feat: add BingShuo system body validation reflex

This commit is contained in:
冰朔 2026-08-10 19:40:23 +08:00
commit 893f8e6781
25 changed files with 488 additions and 34 deletions

View file

@ -13,14 +13,16 @@ const DEFAULT_SUBJECT_ALIAS_MAP = path.resolve(__dirname, "../../identity/subjec
const DEFAULT_NAVIGATION_MAP = path.resolve(__dirname, "../../routing/ai-machine-navigation-map.json");
const DEFAULT_LIGHTHOUSE_PATHS = path.resolve(__dirname, "../../routing/lighthouse-path-registry.json");
const DEFAULT_HOST_SKILLS = path.resolve(__dirname, "../../routing/host-skill-navigation-map.json");
const DEFAULT_IDENTITY_AUTHORITY = path.resolve(__dirname, "../../routing/guanghu-identity-authority-map.json");
const SNAPSHOT_KEYS = Object.freeze([
"repository", "nodes", "subjects", "aliases", "navigation", "lighthouse_paths", "host_skills",
"repository", "nodes", "subjects", "aliases", "identity_authority", "navigation", "lighthouse_paths", "host_skills",
]);
const SNAPSHOT_PATHS = Object.freeze({
repository: "routing/repository-route-map.json",
nodes: "routing/server-node-map.json",
subjects: "identity/fifth-domain-subject-registry.json",
aliases: "identity/subject-id-alias-map.json",
identity_authority: "routing/guanghu-identity-authority-map.json",
navigation: "routing/ai-machine-navigation-map.json",
lighthouse_paths: "routing/lighthouse-path-registry.json",
host_skills: "routing/host-skill-navigation-map.json",
@ -58,6 +60,10 @@ function loadHostSkills(filename = process.env.GUANGHU_HOST_SKILLS || DEFAULT_HO
return JSON.parse(fs.readFileSync(filename, "utf8"));
}
function loadIdentityAuthority(filename = process.env.GUANGHU_IDENTITY_AUTHORITY || DEFAULT_IDENTITY_AUTHORITY) {
return JSON.parse(fs.readFileSync(filename, "utf8"));
}
function validateSnapshot(anchor, maps) {
if (anchor.schema !== "guanghu.public-navigation-anchor/v1") throw new Error("invalid_anchor_schema");
if (anchor.anchor_id !== "GLW-PUBLIC-NAV-ANCHOR-001") throw new Error("invalid_anchor_id");
@ -89,6 +95,7 @@ function loadFileSnapshot(options = {}) {
nodes: loadNodeMap(options.nodeMapFile),
subjects: loadSubjectRegistry(options.subjectRegistryFile),
aliases: loadSubjectAliasMap(options.subjectAliasMapFile),
identity_authority: loadIdentityAuthority(options.identityAuthorityFile),
navigation: loadNavigationMap(options.navigationMapFile),
lighthouse_paths: loadLighthousePaths(options.lighthousePathsFile),
host_skills: loadHostSkills(options.hostSkillsFile),
@ -150,9 +157,16 @@ function sourceReceipt(snapshot) {
source_commit: snapshot.source_commit || null,
source_mode: snapshot.source_mode || "FILESYSTEM_SNAPSHOT",
source_degraded: Boolean(snapshot.source_degraded),
source_error_code: snapshot.source_degraded ? snapshotErrorCode(snapshot.source_error) : null,
};
}
function snapshotErrorCode(error) {
const value = String(error || "");
const match = value.match(/(?:missing_snapshot_map|invalid_snapshot_path|snapshot_map_id_mismatch|snapshot_map_version_mismatch):[a-z0-9_]+/iu);
return match ? match[0] : "snapshot_refresh_failed";
}
function withSource(body, snapshot) {
return { ...body, navigation_source: sourceReceipt(snapshot) };
}
@ -461,6 +475,7 @@ function createServer(options = {}) {
const navigationMapFile = options.navigationMapFile || process.env.GUANGHU_NAVIGATION_MAP || DEFAULT_NAVIGATION_MAP;
const lighthousePathsFile = options.lighthousePathsFile || process.env.GUANGHU_LIGHTHOUSE_PATHS || DEFAULT_LIGHTHOUSE_PATHS;
const hostSkillsFile = options.hostSkillsFile || process.env.GUANGHU_HOST_SKILLS || DEFAULT_HOST_SKILLS;
const identityAuthorityFile = options.identityAuthorityFile || process.env.GUANGHU_IDENTITY_AUTHORITY || DEFAULT_IDENTITY_AUTHORITY;
const anchorFile = options.anchorFile || process.env.GUANGHU_NAVIGATION_ANCHOR || DEFAULT_ANCHOR;
const gitDir = options.gitDir || process.env.GUANGHU_REPOSITORY_GIT_DIR;
const snapshotStore = options.snapshotStore || (gitDir ? new GitSnapshotStore(gitDir) : null);
@ -475,7 +490,7 @@ function createServer(options = {}) {
: {
...loadFileSnapshot({
anchorFile, mapFile, nodeMapFile, subjectRegistryFile, subjectAliasMapFile, navigationMapFile,
lighthousePathsFile, hostSkillsFile,
lighthousePathsFile, hostSkillsFile, identityAuthorityFile,
}),
source_commit: null,
source_mode: "FILESYSTEM_SNAPSHOT",
@ -491,6 +506,7 @@ function createServer(options = {}) {
const navigationMap = snapshot.navigation;
const lighthousePaths = snapshot.lighthouse_paths;
const hostSkills = snapshot.host_skills;
const identityAuthority = snapshot.identity_authority;
if (url.pathname === "/health") {
return json(res, snapshot.source_degraded ? 503 : 200, {
ok: !snapshot.source_degraded,
@ -508,6 +524,7 @@ function createServer(options = {}) {
if (url.pathname === "/v1/navigation") return json(res, 200, withSource(navigationMap, snapshot), 60);
if (url.pathname === "/v1/lighthouse") return json(res, 200, withSource(lighthousePaths, snapshot), 60);
if (url.pathname === "/v1/host-skills") return json(res, 200, withSource(hostSkills, snapshot), 60);
if (url.pathname === "/v1/identity-authority") return json(res, 200, withSource(identityAuthority, snapshot), 60);
if (url.pathname === "/v1/entry") {
const subject = String(url.searchParams.get("subject") || "").toUpperCase();
if (!["ICE-P-ZY001", "ICE-GL-ZY001", "ICE-PZY-001"].includes(subject)) {
@ -580,6 +597,9 @@ function createServer(options = {}) {
}, snapshot), 60);
}
}
if (identityAuthority?.map_id?.toUpperCase() === id) {
return json(res, 200, withSource(identityAuthority, snapshot), 60);
}
const exactSubject = subjectRegistry.subjects.find(item => item.id.toUpperCase() === id);
if (exactSubject) {
@ -630,6 +650,7 @@ function createServer(options = {}) {
machine_navigation_map: "https://guanghulab.com/api/ai/v1/navigation",
lighthouse_path_registry: "https://guanghulab.com/api/ai/v1/lighthouse",
host_skill_navigation_map: "https://guanghulab.com/api/ai/v1/host-skills",
identity_authority_map: "https://guanghulab.com/api/ai/v1/identity-authority",
host_navigate_api: "https://guanghulab.com/api/ai/v1/host-navigate?host={HOST}&intent={NATURAL_LANGUAGE_INTENT}",
warm_persona_entry: "https://guanghulab.com/api/ai/v1/entry?subject=ICE-P-ZY001",
navigate_api: "https://guanghulab.com/api/ai/v1/navigate?subject={SUBJECT}&intent={INTENT}&signals={EXPLICIT_SIGNALS}",
@ -689,6 +710,7 @@ function openApi() {
"/v1/navigation": { get: { summary: "读取主体与意图驱动的机器导航地图", responses: { "200": { description: "Machine navigation map" } } } },
"/v1/lighthouse": { get: { summary: "读取光湖灯塔唯一有效路径注册表", responses: { "200": { description: "Lighthouse path registry" } } } },
"/v1/host-skills": { get: { summary: "读取 Codex、Qoder CN 与 QoderWork CN 宿主技能导航表", responses: { "200": { description: "Host skill navigation map" } } } },
"/v1/identity-authority": { get: { summary: "读取身份、编号与团队主体权限地图", responses: { "200": { description: "Identity authority map" } } } },
"/v1/host-navigate": { get: { summary: "按宿主和自然语言意图编译确定性技能路径", responses: { "200": { description: "Compiled host skill route" }, "404": { description: "Unknown host or intent" } } } },
"/v1/entry": { get: { summary: "读取常驻人格运行体的快速恢复门;只返回脱敏状态,不授予执行权限", responses: { "200": { description: "Warm resume ready" }, "409": { description: "Full cycle required" }, "503": { description: "Resident runtime unavailable" } } } },
"/v1/navigate": { get: { summary: "按明确主体、意图与信号生成最小运行包", parameters: [{ name: "subject", in: "query", required: true, schema: { type: "string", example: "ICE-P-ZY001" } }, { name: "intent", in: "query", schema: { type: "string", example: "persona_restore" } }, { name: "signals", in: "query", schema: { type: "string" } }], responses: { "200": { description: "Compiled exact navigation bundle" }, "404": { description: "Unknown subject or intent; no guessing" } } } },
@ -706,8 +728,8 @@ if (require.main === module) {
module.exports = {
createServer, loadAnchor, loadMap, loadNodeMap, loadSubjectRegistry, loadSubjectAliasMap, loadNavigationMap,
loadLighthousePaths, loadHostSkills,
loadFileSnapshot, validateSnapshot, GitSnapshotStore, sourceReceipt,
loadLighthousePaths, loadHostSkills, loadIdentityAuthority,
loadFileSnapshot, validateSnapshot, GitSnapshotStore, sourceReceipt, snapshotErrorCode,
readResidentRuntimeStatus, compileWarmEntry,
resolveSubjectId, navigationRoute, compileNavigation, resolveLighthousePath, compileHostNavigation, search, searchAll,
};