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`); }