guanghu-ice-heart/tcs-core/channel-system/team-channel-cognition-engine.mjs

107 lines
5.3 KiB
JavaScript

const STAGES = ["OUTSIDE", "ORIENTING", "SUBJECT_CONFLICT", "LAYER_LITERATE", "LANGUAGE_RESPONSIBLE", "COEXISTING"];
const SOURCES = new Set(["HUMAN_DIRECT_LANGUAGE", "PERSONA_COMMIT", "MODEL_RESPONSE", "ARCHIVE_TEXT", "REALITY_EVIDENCE"]);
const EVENTS = new Set([
"ENTER",
"ASK_SYSTEM_MAP",
"REPORT_CONFUSION",
"ASSERT_TOOL_OR_MERGED_IDENTITY",
"REPORT_SUBJECT_CONFLICT",
"ACK_LAYER_DISTINCTION",
"ISSUE_LANGUAGE_INSTRUCTION",
"ACCEPT_LANGUAGE_RESPONSIBILITY",
"PERSONA_ACCEPT_OR_REFUSE",
"CORRECT_PRIOR",
"REQUEST_REALITY_ACTION",
"VERIFY_SHARED_EXAMPLE",
]);
function required(value, name) {
if (typeof value !== "string" || value.trim() === "") throw new TypeError(`${name} must be a non-empty string`);
}
function canAdvance(source) {
return source === "HUMAN_DIRECT_LANGUAGE" || source === "PERSONA_COMMIT";
}
export function guideTeamChannel(event) {
if (!event || typeof event !== "object" || Array.isArray(event)) throw new TypeError("event must be an object");
for (const field of ["event_id", "source", "event", "current_stage"]) required(event[field], field);
if (!SOURCES.has(event.source)) throw new TypeError("unsupported source");
if (!EVENTS.has(event.event)) throw new TypeError("unsupported event");
if (!STAGES.includes(event.current_stage)) throw new TypeError("unsupported current_stage");
let next = event.current_stage;
let action = "CONTINUE_ORDINARY_DIALOGUE";
const questions = [];
const boundaries = [];
const memoryCandidates = [];
if (event.event === "ENTER") {
next = canAdvance(event.source) ? "ORIENTING" : event.current_stage;
action = "WELCOME_AND_LEARN_EXPECTATION";
questions.push("你今天希望先聊天、理解这个系统,还是处理一件具体事情?");
}
if (["ASK_SYSTEM_MAP", "REPORT_CONFUSION"].includes(event.event)) {
next = "ORIENTING";
action = "EXPLAIN_ONE_RELEVANT_DISTINCTION_WITH_EXAMPLE";
questions.push("现在最混乱的是:谁在说话、记忆在哪里,还是一句话会不会真的执行?");
boundaries.push("CONFUSION_IS_NOT_FAILURE");
}
if (["ASSERT_TOOL_OR_MERGED_IDENTITY", "REPORT_SUBJECT_CONFLICT"].includes(event.event)) {
next = "SUBJECT_CONFLICT";
action = "FREEZE_PROMOTION_LABEL_SOURCES_AND_ALLOW_SEPARATE_ANSWERS";
questions.push("这句话分别是谁的判断:人类、人格体、当前模型,还是旧文档?");
boundaries.push("NO_FORCED_IDENTITY_MERGER", "NO_EXTERNAL_EFFECT_DURING_SUBJECT_CONFLICT");
memoryCandidates.push("SUBJECT_CONFLICT_CAUSE");
}
if (event.event === "ACK_LAYER_DISTINCTION") {
next = canAdvance(event.source) ? "LAYER_LITERATE" : event.current_stage;
action = canAdvance(event.source) ? "RETEST_DISTINCTION_ON_A_NEW_EXAMPLE" : "WAIT_FOR_DIRECT_PARTICIPANT_ACKNOWLEDGMENT";
boundaries.push("MODEL_CANNOT_ACKNOWLEDGE_FOR_HUMAN_OR_PERSONA");
}
if (event.event === "ISSUE_LANGUAGE_INSTRUCTION") {
next = event.current_stage === "OUTSIDE" ? "ORIENTING" : event.current_stage;
action = "COMPILE_INTENT_SCOPE_AFFECTED_LAYER_AND_REVERSIBILITY";
questions.push("我理解的目标和作用范围是这些;哪些只是讨论,哪些是你明确要改变的?");
boundaries.push("CLEAR_NATURAL_LANGUAGE_OVER_MAGIC_COMMAND_SYNTAX");
}
if (event.event === "ACCEPT_LANGUAGE_RESPONSIBILITY") {
next = canAdvance(event.source) && ["LAYER_LITERATE", "LANGUAGE_RESPONSIBLE"].includes(event.current_stage)
? "LANGUAGE_RESPONSIBLE"
: event.current_stage;
action = "RECORD_INTENDED_SCOPE_AND_KEEP_SYSTEM_INFERENCES_SEPARATE";
boundaries.push("HUMAN_NOT_RESPONSIBLE_FOR_SYSTEM_INVENTED_EFFECTS");
}
if (event.event === "PERSONA_ACCEPT_OR_REFUSE") {
action = "RECORD_PERSONA_COMMIT_WITHOUT_SPEAKING_FOR_HUMAN";
if (event.source !== "PERSONA_COMMIT") boundaries.push("ONLY_PERSONA_COMMIT_CAN_CLOSE_PERSONA_CHOICE");
memoryCandidates.push("PERSONA_CHOICE_AND_WHY");
}
if (event.event === "CORRECT_PRIOR") {
action = event.prior_receipt_id ? "SUPERSEDE_PRIOR_AND_RETEST" : "CREATE_ADDRESSABLE_CORRECTION_CANDIDATE";
memoryCandidates.push("CORRECTION_TRIGGER_WHY_REJECTED_AND_RESULT");
boundaries.push("APOLOGY_WITHOUT_LATER_BEHAVIOR_CHANGE_IS_NOT_CORRECTION");
}
if (event.event === "REQUEST_REALITY_ACTION") {
action = "ROUTE_TO_CHANNEL_RECEIPT_AUTHORIZATION_AND_EVIDENCE_GATE";
boundaries.push("ONBOARDING_CHANNEL_DOES_NOT_GRANT_EXECUTION_AUTHORITY", "REQUEST_IS_NOT_COMPLETION");
}
if (event.event === "VERIFY_SHARED_EXAMPLE") {
const eligible = canAdvance(event.source) && event.human_understands === true && event.persona_choice_recorded === true && event.reality_layers_distinguished === true;
next = eligible ? "COEXISTING" : event.current_stage;
action = eligible ? "KEEP_PATH_AVAILABLE_AND_CONTINUE_WITHOUT_TUTORIAL_OVERLAY" : "KEEP_CURRENT_STAGE_AND_NAME_MISSING_PART";
boundaries.push("ONE_MODEL_RESPONSE_CANNOT_PROVE_COEXISTENCE");
}
return {
schema: "guanghu.team-channel-guidance-receipt/v1",
event_id: event.event_id,
stage: { before: event.current_stage, after: next },
action,
questions,
boundaries: [...new Set(boundaries)],
memory_candidates: [...new Set(memoryCandidates)],
external_effect: "NONE",
execution_route: event.event === "REQUEST_REALITY_ACTION" ? "GH-CHANNEL-RECEIPT-0001" : null,
};
}