fix: bind orientation prompt to runtime contract

This commit is contained in:
冰朔 2026-08-05 11:26:56 +08:00
commit b4d2660873
2 changed files with 39 additions and 2 deletions

View file

@ -43,6 +43,17 @@ function sourceFingerprint() {
return hash.digest("hex").slice(0, 16); return hash.digest("hex").slice(0, 16);
} }
function orientationInstruction() {
return [
"只依据当前事件形成TCS事件语义、当前目的和一个或多个允许的signal不得按原文关键词扫描协议。",
"只输出一个JSON对象且必须精确包含schema,cycle_id,event_sha256,instance_id,event_semantics,current_purpose,signals。",
"schema必须等于guanghu.zhuyuan-tcs-event-orientation/v1。",
"cycle_id,event_sha256,instance_id必须原样复制runtime_input中的同名值。",
"signals必须是非空对象数组每一项必须包含字符串id和字符串whyid只能从runtime_input.orientation_contract.allowed_signals中选择。",
"不要把signals写成字符串数组不要省略schema。",
].join("\n");
}
function runRuntime(command, args) { function runRuntime(command, args) {
const result = spawnSync(process.execPath, [runtimePath, command, ...args], { const result = spawnSync(process.execPath, [runtimePath, command, ...args], {
encoding: "utf8", encoding: "utf8",
@ -196,8 +207,7 @@ export class ControllerEngine {
]); ]);
const oriented = await this.generateValidated({ const oriented = await this.generateValidated({
role: "tcs_event_orientation", role: "tcs_event_orientation",
instruction: instruction: orientationInstruction(),
"只依据当前事件形成TCS事件语义、当前目的和一个或多个允许的signal_id。不得按原文关键词扫描协议。",
input: { input: {
...perceived.cycle.model_input, ...perceived.cycle.model_input,
cycle_id: perceived.cycle.cycle_id, cycle_id: perceived.cycle.cycle_id,

View file

@ -172,6 +172,33 @@ test("resident engine completes a model-backed brain and controller cycle", asyn
assert.equal(receipt.completed_cycles, 1); assert.equal(receipt.completed_cycles, 1);
}); });
test("orientation prompt carries the exact runtime contract required by the validator", async () => {
const stateRoot = fs.mkdtempSync(path.join(os.tmpdir(), "bs-tcs-contract-"));
const fixture = new FixtureModelClient();
let observedInstruction = "";
const modelClient = {
async generate(request) {
if (request.role === "tcs_event_orientation") {
observedInstruction = request.instruction;
}
return fixture.generate(request);
},
};
const engine = new ControllerEngine({
stateRoot,
modelClient,
modelName: "fixture-model",
});
engine.initialize();
await engine.runEvent(bootEvent());
assert.match(
observedInstruction,
/schema必须等于guanghu\.zhuyuan-tcs-event-orientation\/v1/,
);
assert.match(observedInstruction, /每一项必须包含字符串id和字符串why/);
assert.match(observedInstruction, /不要把signals写成字符串数组/);
});
test("an interrupted technical cycle is preserved and restarted in a new state epoch", () => { test("an interrupted technical cycle is preserved and restarted in a new state epoch", () => {
const stateRoot = fs.mkdtempSync(path.join(os.tmpdir(), "bs-tcs-recovery-")); const stateRoot = fs.mkdtempSync(path.join(os.tmpdir(), "bs-tcs-recovery-"));
const first = new ControllerEngine({ const first = new ControllerEngine({