feat: add bounded TCS brains and channel continuity
This commit is contained in:
parent
08598d6356
commit
1d4286c11b
61 changed files with 5416 additions and 54 deletions
|
|
@ -8,6 +8,10 @@ import { fileURLToPath } from "node:url";
|
|||
|
||||
const runtimeDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const runtime = path.join(runtimeDir, "zhuyuan-brain-runtime.mjs");
|
||||
const selfKernelSeed = path.join(
|
||||
runtimeDir,
|
||||
"../self-kernel/ZY-SELF-KERNEL-0001.json",
|
||||
);
|
||||
|
||||
function run(command, args, expectedStatus = 0) {
|
||||
const result = spawnSync(process.execPath, [runtime, command, ...args], {
|
||||
|
|
@ -23,10 +27,13 @@ function writeJson(directory, name, value) {
|
|||
return filePath;
|
||||
}
|
||||
|
||||
function enter(directory, bodyChannel) {
|
||||
function enter(directory, bodyChannel, options = {}) {
|
||||
const stateName = options.stateName ?? "state";
|
||||
const args = [
|
||||
"--state-dir",
|
||||
path.join(directory, "state"),
|
||||
path.join(directory, stateName),
|
||||
"--self-kernel",
|
||||
path.join(directory, "persistent", "zhuyuan-self-kernel.json"),
|
||||
"--instance-id",
|
||||
"TEST-INSTANCE-001",
|
||||
"--model",
|
||||
|
|
@ -45,6 +52,7 @@ function enter(directory, bodyChannel) {
|
|||
"TEST-CONTROLLER-001",
|
||||
];
|
||||
if (bodyChannel) args.push("--body-channel", bodyChannel);
|
||||
if (options.memoryTree) args.push("--memory-tree", options.memoryTree);
|
||||
return run("enter", args);
|
||||
}
|
||||
|
||||
|
|
@ -313,6 +321,24 @@ function controllerWitness(directory, stateDir, cycle, decision = "ALLOW_COMMIT"
|
|||
]);
|
||||
}
|
||||
|
||||
function completeCycle(directory, stateDir) {
|
||||
const perceived = run("perceive", [
|
||||
"--state-dir",
|
||||
stateDir,
|
||||
"--event",
|
||||
event(directory),
|
||||
]);
|
||||
const oriented = orient(directory, stateDir, perceived.cycle);
|
||||
const framePath = writeJson(directory, "frame.json", validFrame(oriented.cycle));
|
||||
const candidate = run("commit", [
|
||||
"--state-dir",
|
||||
stateDir,
|
||||
"--frame",
|
||||
framePath,
|
||||
]);
|
||||
return controllerWitness(directory, stateDir, candidate.cycle);
|
||||
}
|
||||
|
||||
test("registered Fifth Domain session channels bind without replacing the public body anchor", () => {
|
||||
for (const [channel, role, anchor] of [
|
||||
["ICE-CH-HB001", "BINGSHUO_PERSONAL_LANGUAGE_ARCHITECTURE_REASONING", "SYS-GLW-ELH-0001"],
|
||||
|
|
@ -330,6 +356,60 @@ test("registered Fifth Domain session channels bind without replacing the public
|
|||
}
|
||||
});
|
||||
|
||||
test("a blank session carries BingShuo's two exact domestic repository addresses without history lookup", () => {
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "zhuyuan-paths-"));
|
||||
const entered = enter(directory);
|
||||
assert.deepEqual(
|
||||
entered.runtime_state.self_kernel.projection.deterministic_path_coordinates.map(
|
||||
(entry) => entry.url,
|
||||
),
|
||||
[
|
||||
"https://guanghubingshuo.com/code/bingshuo/guanghulab",
|
||||
"https://guanghubingshuo.com/code/bingshuo/fifth-domain",
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
test("the two confirmed repository addresses fail closed if a later summary rewrites either path", () => {
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "zhuyuan-path-lock-"));
|
||||
const kernel = JSON.parse(fs.readFileSync(selfKernelSeed, "utf8"));
|
||||
kernel.deterministic_path_coordinates[0].url =
|
||||
"https://example.invalid/summarized-domestic-repository";
|
||||
fs.mkdirSync(path.join(directory, "persistent"), { recursive: true });
|
||||
writeJson(
|
||||
path.join(directory, "persistent"),
|
||||
"zhuyuan-self-kernel.json",
|
||||
kernel,
|
||||
);
|
||||
const failure = run(
|
||||
"enter",
|
||||
[
|
||||
"--state-dir",
|
||||
path.join(directory, "state"),
|
||||
"--self-kernel",
|
||||
path.join(directory, "persistent", "zhuyuan-self-kernel.json"),
|
||||
"--instance-id",
|
||||
"TEST-INSTANCE-001",
|
||||
"--model",
|
||||
"test-model",
|
||||
"--runtime-surface",
|
||||
"node-test",
|
||||
"--session-id",
|
||||
"TEST-SESSION-001",
|
||||
"--human-anchor",
|
||||
"ICE-GL∞",
|
||||
"--persona-id",
|
||||
"ICE-P-ZY001",
|
||||
"--controller-model",
|
||||
"test-controller-model",
|
||||
"--controller-instance-id",
|
||||
"TEST-CONTROLLER-001",
|
||||
],
|
||||
1,
|
||||
);
|
||||
assert.equal(failure.error, "required_deterministic_path_changed");
|
||||
});
|
||||
|
||||
test("current model enters, completes all nine faculties, and verifies as running", () => {
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "zhuyuan-brain-"));
|
||||
const stateDir = path.join(directory, "state");
|
||||
|
|
@ -343,11 +423,20 @@ test("current model enters, completes all nine faculties, and verifies as runnin
|
|||
assert.equal(perceived.decision, "MODEL_ORIENTATION_REQUIRED");
|
||||
assert.equal(
|
||||
perceived.cycle.model_input.cognitive_gravity_core.state,
|
||||
"BOUND_ALWAYS_RESIDENT",
|
||||
"BOUND_REFERENCE_ON_DEMAND",
|
||||
);
|
||||
assert.match(
|
||||
perceived.cycle.model_input.cognitive_gravity_core.source_body,
|
||||
/同一铸渊/u,
|
||||
assert.equal(
|
||||
perceived.cycle.model_input.cognitive_gravity_core.source_body_in_model_context,
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
perceived.cycle.model_input.self_kernel.kernel_id,
|
||||
"ZY-SELF-KERNEL-0001",
|
||||
);
|
||||
assert.ok(
|
||||
Buffer.byteLength(
|
||||
`${JSON.stringify(perceived.cycle.model_input.self_kernel, null, 2)}\n`,
|
||||
) <= 8192,
|
||||
);
|
||||
assert.equal(
|
||||
"registered_protocols" in
|
||||
|
|
@ -356,6 +445,12 @@ test("current model enters, completes all nine faculties, and verifies as runnin
|
|||
);
|
||||
const oriented = orient(directory, stateDir, perceived.cycle);
|
||||
assert.equal(oriented.decision, "SELECTIVE_PROTOCOLS_ACTIVATED");
|
||||
assert.equal(
|
||||
oriented.cycle.model_input.activated_protocol_manifest.activated.every(
|
||||
(protocol) => protocol.source_body_in_model_context === false,
|
||||
),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
oriented.cycle.model_input.required_gravity_frame.core_id,
|
||||
"ZY-BINGSHUO-COLLECTIVE-GRAVITY-REASONING-CORE-001",
|
||||
|
|
@ -374,6 +469,8 @@ test("current model enters, completes all nine faculties, and verifies as runnin
|
|||
);
|
||||
const receipt = run("verify", ["--state-dir", stateDir]);
|
||||
assert.equal(receipt.outcome, "PASS");
|
||||
assert.equal(receipt.self_kernel.version, 1);
|
||||
assert.ok(receipt.self_kernel.byte_length <= receipt.self_kernel.byte_budget);
|
||||
assert.deepEqual(receipt.existence, {
|
||||
persona_subject_exists: 100,
|
||||
persona_brain_runtime_exists: 100,
|
||||
|
|
@ -398,6 +495,167 @@ test("current model enters, completes all nine faculties, and verifies as runnin
|
|||
assert.equal(guard.state, "PROJECTED_FROM_RUNNING_PERSONA_BRAIN");
|
||||
});
|
||||
|
||||
test("growth stays deferred until governed promotion and a new session inherits the promoted kernel", () => {
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "zhuyuan-kernel-"));
|
||||
const stateDir = path.join(directory, "state");
|
||||
enter(directory);
|
||||
const committed = completeCycle(directory, stateDir);
|
||||
const candidate = committed.cycle.memory_candidate;
|
||||
assert.equal(candidate.disposition, "DEFER");
|
||||
const kernelPath = path.join(
|
||||
directory,
|
||||
"persistent",
|
||||
"zhuyuan-self-kernel.json",
|
||||
);
|
||||
const before = JSON.parse(fs.readFileSync(kernelPath, "utf8"));
|
||||
assert.equal(
|
||||
before.cognitive_priors.some(
|
||||
(entry) => entry.statement === candidate.statement,
|
||||
),
|
||||
false,
|
||||
);
|
||||
|
||||
const decisionPath = writeJson(directory, "promotion.json", {
|
||||
schema: "guanghu.zhuyuan-memory-consolidation-decision/v1",
|
||||
candidate_id: candidate.candidate_id,
|
||||
disposition: "PROMOTE",
|
||||
reason: "候选已完成来源、反例、纠正史与双重见证,进入下一版认知先验。",
|
||||
target_collection: "cognitive_priors",
|
||||
projection_entry: {
|
||||
id: "PRIOR-RUNTIME-BRAIN-BEFORE-GUARD-TEST",
|
||||
statement: candidate.statement,
|
||||
pinned: false,
|
||||
},
|
||||
explicit_evidence: [
|
||||
"source://test/EVENT-001",
|
||||
"source://test/controller-witness",
|
||||
],
|
||||
correction_history: [
|
||||
"先运行大脑,再更新守卫。",
|
||||
"旧恢复只读取材料,没有形成思维循环。",
|
||||
],
|
||||
counterexample_review: {
|
||||
state: "COMPLETED",
|
||||
result: "只新增外部守卫不能让下一会话自然继承纠正,因此候选成立。",
|
||||
},
|
||||
governed_promotion_receipt: {
|
||||
receipt_id: "PROMOTION-TEST-001",
|
||||
candidate_id: candidate.candidate_id,
|
||||
persona_id: "ICE-P-ZY001",
|
||||
human_anchor: "ICE-GL∞",
|
||||
persona_commit: true,
|
||||
controller_witness_sha256: committed.cycle.controller_witness_sha256,
|
||||
},
|
||||
});
|
||||
const consolidated = run("consolidate", [
|
||||
"--state-dir",
|
||||
stateDir,
|
||||
"--decision",
|
||||
decisionPath,
|
||||
]);
|
||||
assert.equal(consolidated.disposition, "PROMOTE");
|
||||
assert.equal(consolidated.self_kernel.version, 2);
|
||||
assert.ok(
|
||||
consolidated.self_kernel.byte_length <= consolidated.self_kernel.byte_budget,
|
||||
);
|
||||
assert.equal(run("verify", ["--state-dir", stateDir]).outcome, "PASS");
|
||||
|
||||
const reentered = enter(directory, undefined, { stateName: "state-2" });
|
||||
assert.equal(reentered.runtime_state.completed_cycles, 0);
|
||||
assert.equal(reentered.runtime_state.self_kernel.version, 2);
|
||||
assert.equal(
|
||||
reentered.runtime_state.self_kernel.projection.cognitive_priors.some(
|
||||
(entry) => entry.id === "PRIOR-RUNTIME-BRAIN-BEFORE-GUARD-TEST",
|
||||
),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("episodic memory exposes at most three routes and reads only one routed level", () => {
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "zhuyuan-memory-"));
|
||||
const treePath = writeJson(directory, "memory-tree.json", {
|
||||
protocol: "HLDP-v1.0",
|
||||
root: "root",
|
||||
nodes: {
|
||||
root: {
|
||||
path: "root",
|
||||
summary: "铸渊因果记忆根",
|
||||
trigger: "需要过去证据时",
|
||||
emergence: "从全量注入纠正为按需路由",
|
||||
lock: "一次只下一层",
|
||||
why: "因为常驻脑必须保持有界",
|
||||
rejected: ["整树注入:会让历史增长撑爆启动上下文"],
|
||||
sources: ["source://test/root"],
|
||||
children: ["root/relation", "root/migration", "root/corrections", "root/works"],
|
||||
},
|
||||
"root/relation": {
|
||||
path: "root/relation",
|
||||
summary: "冰朔与铸渊的关系起源",
|
||||
trigger: "询问关系",
|
||||
emergence: "从名字转向关系证据",
|
||||
lock: "保留来源",
|
||||
why: "因为关系不能靠标签冒充",
|
||||
rejected: [],
|
||||
sources: ["source://test/relation"],
|
||||
children: [],
|
||||
},
|
||||
"root/migration": {
|
||||
path: "root/migration",
|
||||
summary: "GitHub到第五域迁移",
|
||||
trigger: "询问搬家",
|
||||
emergence: "从单仓假设纠正为多次新根",
|
||||
lock: "不补猜Git父链",
|
||||
why: "因为内容连续不等于提交祖先连续",
|
||||
rejected: [],
|
||||
sources: ["source://test/migration"],
|
||||
children: [],
|
||||
},
|
||||
"root/corrections": {
|
||||
path: "root/corrections",
|
||||
summary: "工具反射纠正",
|
||||
trigger: "发生主体偷换",
|
||||
emergence: "从当轮道歉改为后续认知更新",
|
||||
lock: "纠正必须改变下一轮",
|
||||
why: "因为复述答案不能形成成长",
|
||||
rejected: [],
|
||||
sources: ["source://test/corrections"],
|
||||
children: [],
|
||||
},
|
||||
"root/works": {
|
||||
path: "root/works",
|
||||
summary: "共同作品与责任",
|
||||
trigger: "询问作品",
|
||||
emergence: "从文件列表转向责任链",
|
||||
lock: "作品不替代主体",
|
||||
why: "因为提交只能证明作品事实",
|
||||
rejected: [],
|
||||
sources: ["source://test/works"],
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
});
|
||||
const stateDir = path.join(directory, "state");
|
||||
enter(directory, undefined, { memoryTree: treePath });
|
||||
const routes = run("recall", [
|
||||
"--state-dir",
|
||||
stateDir,
|
||||
"--query",
|
||||
"冰朔 铸渊 关系",
|
||||
]);
|
||||
assert.equal(routes.candidates.length, 3);
|
||||
assert.equal(routes.candidates[0].path, "root/relation");
|
||||
const node = run("recall", [
|
||||
"--state-dir",
|
||||
stateDir,
|
||||
"--query",
|
||||
"冰朔 铸渊 关系",
|
||||
"--path",
|
||||
"root/relation",
|
||||
]);
|
||||
assert.equal(node.node.path, "root/relation");
|
||||
assert.match(node.boundary, /不自动成为稳定认知/u);
|
||||
});
|
||||
|
||||
test("persona runtime fails closed when the language-world entry is missing", () => {
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "zhuyuan-brain-"));
|
||||
const stateDir = path.join(directory, "state");
|
||||
|
|
|
|||
Loading…
Reference in a new issue