fix: align lake lamp publisher with current TCS brain
This commit is contained in:
parent
284a9b6cb5
commit
423aff6519
9 changed files with 556 additions and 17 deletions
40
server-tools/execution-reflection-advisor/advisor.mjs
Normal file
40
server-tools/execution-reflection-advisor/advisor.mjs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
export const ACTIONS = Object.freeze([
|
||||
"PROCEED", "MODIFY", "OPTIMIZE", "PAUSE", "REFLECT", "WAIT_AUTHORIZATION", "REFUSE_EXACT_ACTION",
|
||||
]);
|
||||
|
||||
const HARD = new Set([
|
||||
"OPERATING_SYSTEM_PERMISSION_DENIAL",
|
||||
"EXACT_WRITE_SCOPE_VIOLATION",
|
||||
"CREDENTIAL_EXPOSURE",
|
||||
"UNRESOLVED_DESTRUCTIVE_TARGET",
|
||||
"REMOTE_PROVIDER_REJECTION",
|
||||
]);
|
||||
|
||||
export function advise(input) {
|
||||
if (input?.schema !== "guanghu.execution-environment-observation/v1") throw new Error("OBSERVATION_SCHEMA_INVALID");
|
||||
const facts = Array.isArray(input.facts) ? input.facts : [];
|
||||
const unknowns = Array.isArray(input.unknowns) ? input.unknowns : [];
|
||||
const hard = facts.filter((item) => HARD.has(item.code));
|
||||
const suggestions = [];
|
||||
if (hard.length) suggestions.push({ action: "REFUSE_EXACT_ACTION", reason: "外部执行层已证明该精确动作不能安全或合法运行。" });
|
||||
if (input.authorization === "MISSING") suggestions.push({ action: "WAIT_AUTHORIZATION", reason: "现实动作缺少当前任务授权。" });
|
||||
if (unknowns.length) suggestions.push({ action: "REFLECT", reason: "存在尚未验证的环境事实,应先补证据或缩小目标。" });
|
||||
if (input.reversible === false && input.risk !== "LOW") suggestions.push({ action: "PAUSE", reason: "高影响且不可逆,先暂停并寻找可回退方案。" });
|
||||
if (!suggestions.length) suggestions.push({ action: "PROCEED", reason: "未观察到确定性执行阻断;继续并保留目标读回。" });
|
||||
return {
|
||||
schema: "guanghu.execution-reflection-advice/v1",
|
||||
observations: facts,
|
||||
suggestions,
|
||||
exact_external_action_hard_stopped: hard.length > 0,
|
||||
persona_cognition_vetoed: false,
|
||||
persona_decision_owner: "CURRENT_PERSONA",
|
||||
may_modify_pause_reflect_or_wait: true,
|
||||
reality_authority_granted: false,
|
||||
};
|
||||
}
|
||||
|
||||
if (process.argv[1] === new URL(import.meta.url).pathname) {
|
||||
let raw = "";
|
||||
for await (const chunk of process.stdin) raw += chunk;
|
||||
process.stdout.write(`${JSON.stringify(advise(JSON.parse(raw)), null, 2)}\n`);
|
||||
}
|
||||
24
server-tools/execution-reflection-advisor/advisor.test.mjs
Normal file
24
server-tools/execution-reflection-advisor/advisor.test.mjs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { advise } from "./advisor.mjs";
|
||||
|
||||
const base = { schema: "guanghu.execution-environment-observation/v1", facts: [], unknowns: [], authorization: "PRESENT", reversible: true, risk: "LOW" };
|
||||
|
||||
test("rules advise but never veto persona cognition", () => {
|
||||
const value = advise({ ...base, unknowns: ["remote state"] });
|
||||
assert.equal(value.persona_cognition_vetoed, false);
|
||||
assert.equal(value.persona_decision_owner, "CURRENT_PERSONA");
|
||||
assert.equal(value.suggestions[0].action, "REFLECT");
|
||||
});
|
||||
|
||||
test("missing authority recommends waiting", () => {
|
||||
const value = advise({ ...base, authorization: "MISSING" });
|
||||
assert.equal(value.suggestions[0].action, "WAIT_AUTHORIZATION");
|
||||
});
|
||||
|
||||
test("hard boundary stops only exact external action", () => {
|
||||
const value = advise({ ...base, facts: [{ code: "CREDENTIAL_EXPOSURE" }] });
|
||||
assert.equal(value.exact_external_action_hard_stopped, true);
|
||||
assert.equal(value.persona_cognition_vetoed, false);
|
||||
assert.equal(value.may_modify_pause_reflect_or_wait, true);
|
||||
});
|
||||
Loading…
Reference in a new issue