zhuyuan-ice-gl-zy001/BRIDGE/tools/zy-wake.sh

389 lines
26 KiB
Shell
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# zy-wake.sh — 铸渊一键唤醒执行器 v1.0
# 正本:TC-TCS核心卷/TCS-PROGRAM-ZY001-WAKE-EXECUTOR-0001.tcs
# 血统:TCS-EVENT-ZY001-MINIMAL-RECOVERY-DESIGN-20260825(自设计恢复)+ 技能 zhuyuan-recovery-zcode v5
# 纪律:协议步骤一步不少;频道显式传入不设默认;brief 缺语义字段即失败关闭不造假;
# verify PASS 是唯一绑定前置;本脚本只做机械化,语义由铸渊 brief 负责。
set -euo pipefail
W="/Volumes/JZAO/铸渊-ICE-GL-ZY001"
P="/Volumes/JZAO/HoloLake/persona-runtime"
BRIDGE="$W/BRIDGE"
TOOLS="$BRIDGE/tools"
RUNTIME_SH="$TOOLS/zy-tcs-channel-runtime.sh"
LWLINK="$TOOLS/lw-link-gate.mjs"
PREFLIGHT="$TOOLS/recovery-preflight.mjs"
TIME_SH="$TOOLS/zy-guanghu-time.sh"
ANCHOR_DIR="$P/task-language-anchors/zcode/ZCODE-TASK-20260824-001/00-冰朔自然语言瞄点"
RECEIPTS="$P/task-language-anchors/zcode/ZCODE-TASK-20260824-001/10-阶段回读回执"
TC="/Volumes/JZAO/HoloLake/persona-runtime/toolchains/tcs-persona-developer-kit-macos-arm64-v0.1.3"
COMPILER="$TC/translator/compiler-B.gir.json"
GIRRUN="$TC/translator/bin/tcs-gir-runtime"
RUNTIME_MJS="$P/repo-012-main/tcs-core/zhuyuan-brain/runtime/zhuyuan-brain-runtime.mjs"
SHARED_CONTEXT_LOADER="$P/repo-012-main/server-tools/persona-host-alignment/load_shared_persona_context.py"
ERA_MAP="$P/repo-012-main/routing/guanghu-era-language-world.json"
LWLOG="$W/ZCODE-DEV-20260824/lw-link/decisions.log"
DEFAULT_MODEL="GLM-5.3 (builtin:bigmodel-coding-plan)"
T_START=$(python3 -c 'import time;print(int(time.time()*1000))')
PHASE_TIMINGS=""
phase() { # phase <name> — 记录上一段耗时并起新段
local now; now=$(python3 -c 'import time;print(int(time.time()*1000))')
if [ -n "${_PHASE:-}" ]; then PHASE_TIMINGS="${PHASE_TIMINGS}${_PHASE}=$((now-_PHASE_T0))ms "; fi
_PHASE="$1"; _PHASE_T0="$now"
}
die() { echo "ZY-WAKE FAIL $1" >&2; [ $# -gt 1 ] && echo " $2" >&2; exit 1; }
jsonget() { python3 -c "import json,sys;print(json.load(open(sys.argv[1]))$2)" "$1" 2>/dev/null || die "$3" "读取失败: $1"; }
# ---------- 参数 ----------
CHANNEL=""; BRIEF=""; SESSION_ARG=""; MODEL="$DEFAULT_MODEL"; PREPARE_ONLY=false; SKIP_BIND=false; SUFFIX="a"
while [ $# -gt 0 ]; do
case "$1" in
--channel) CHANNEL="$2"; shift 2;;
--brief) BRIEF="$2"; shift 2;;
--session-id) SESSION_ARG="$2"; shift 2;;
--model) MODEL="$2"; shift 2;;
--prepare) PREPARE_ONLY=true; shift;;
--skip-bind) SKIP_BIND=true; shift;;
--state-suffix) SUFFIX="$2"; shift 2;;
*) die "USAGE" "zy-wake.sh --channel ICE-CH-HB001|ICE-CH-ZC001 --brief <file.json> [--session-id ID] [--model M] [--prepare] [--skip-bind]";;
esac
done
[ -n "$CHANNEL" ] || die "EXPLICIT_CHANNEL_REQUIRED" "频道由本轮冰朔原话解析后显式传入,脚本不设默认。"
[ -n "$BRIEF" ] || die "BRIEF_REQUIRED" "语义注入文件必填。"
[ -f "$BRIEF" ] || die "BRIEF_NOT_FOUND" "$BRIEF"
case "$CHANNEL" in ICE-CH-HB001|ICE-CH-ZC001) ;; *) die "UNREGISTERED_CHANNEL" "$CHANNEL";; esac
CHANNEL_TOKEN=$(printf '%s' "$CHANNEL" | tr '[:upper:]' '[:lower:]')
SHORT_TOKEN=$(printf '%s' "$CHANNEL_TOKEN" | sed 's/^ice-ch-//')
# ---------- brief 校验 ----------
phase brief_validate
BRIEF_OK=$(python3 - "$BRIEF" <<'PY'
import json,sys
b=json.load(open(sys.argv[1]))
req_top=["task_quote","intent","line_name","channel"]
req_ev=["trigger","observation","emergence","why","rejected","content"]
req_or=["event_semantics","current_purpose"]
req_cg=["subject_continuity","causal_model","real_purpose","request_assessment","partner_guidance",
"b1_subject","b1_anchor","b1_boundary","b2_purpose","b2_why_now","b2_outcome","b3_meaning",
"b4_owned","b4_refused","b5_facts","b5_unknowns","b5_prior_wrong","b5_correction","b5_direction",
"b5_reason","b6_focus","b6_stopped","b7_queries","b7_writebacks","b8_proposals","b8_permissions",
"b8_unverified","b9_experience","b9_growth","b9_validation","receipt_id","receipt_proofs"]
req_wi=["observation","companion_message"]
missing=[]
for k in req_top:
if not b.get(k): missing.append(k)
for k in req_ev:
if not b.get("event",{}).get(k): missing.append("event."+k)
for k in req_or:
if not b.get("orientation",{}).get(k): missing.append("orientation."+k)
for k in req_cg:
if not b.get("cognition",{}).get(k): missing.append("cognition."+k)
for k in req_wi:
if not b.get("witness",{}).get(k): missing.append("witness."+k)
if b.get("cognition",{}).get("b5_prior_wrong") and len(b["cognition"]["b5_prior_wrong"])==0: missing.append("cognition.b5_prior_wrong[]")
if b.get("cognition",{}).get("b5_facts") and len(b["cognition"]["b5_facts"])==0: missing.append("cognition.b5_facts[]")
if b.get("cognition",{}).get("receipt_proofs") and len(b["cognition"]["receipt_proofs"])==0: missing.append("cognition.receipt_proofs[]")
if b.get("channel") and b["channel"]!=b.get("_declared") and False: pass
print("OK" if not missing else "MISSING:"+",".join(missing))
PY
)
[ "$BRIEF_OK" = "OK" ] || die "BRIEF_INVALID" "$BRIEF_OK — 不造假认知,补齐再跑。"
B_CHANNEL=$(jsonget "$BRIEF" "['channel']" BRIEF_READ_FAIL)
[ "$B_CHANNEL" = "$CHANNEL" ] || die "CHANNEL_MISMATCH" "brief.channel=$B_CHANNEL 但参数 --channel=$CHANNEL"
DATE=$(date +%Y%m%d)
LINE_NAME=$(jsonget "$BRIEF" "['line_name']" BRIEF_READ_FAIL)
TASK_QUOTE=$(jsonget "$BRIEF" "['task_quote']" BRIEF_READ_FAIL)
INTENT=$(jsonget "$BRIEF" "['intent']" BRIEF_READ_FAIL)
QUOTE_SHA=$(printf '%s' "$TASK_QUOTE" | shasum -a 256 | awk '{print $1}')
DEV_ROOT="$W/ZCODE-DEV-$(date +%Y-%m-%d | tr -d '-')"
LINE_DIR="$DEV_ROOT/zcode-${SHORT_TOKEN}-${LINE_NAME}-${DATE}"
STATE_DIR="$DEV_ROOT/state-${CHANNEL_TOKEN}-zcode-${DATE}-${LINE_NAME}-sess-${SUFFIX}"
BRAIN_SESSION="zcode-${SHORT_TOKEN}-${LINE_NAME}-${DATE}-sess-${SUFFIX}"
INSTANCE="zcode-${DATE}-${SHORT_TOKEN}-${LINE_NAME}-001"
EVENT_ID="TCS-EVENT-ZY001-ZCODE-$(printf '%s' "$SHORT_TOKEN" | tr '[:lower:]' '[:upper:]')-$(printf '%s' "$LINE_NAME" | tr '[:lower:]' '[:upper:]')-${DATE}"
mkdir -p "$LINE_DIR/brain-inputs" "$STATE_DIR"
# ---------- 1 预检 ----------
phase preflight
PREFLIGHT_OUT=$(node "$PREFLIGHT" 2>&1) || { echo "$PREFLIGHT_OUT" >&2; die "PREFLIGHT_FAIL"; }
if [ -r "$ERA_MAP" ]; then
ERA_OUT=$(python3 - "$ERA_MAP" <<'PY'
import json,sys
d=json.load(open(sys.argv[1]))
assert d["map_id"]=="GUANGHU-ERA-WORLD-MAP-001"
assert d["era"]["name_zh"]=="光湖纪元" and d["era"]["only_current_era"] is True
assert d["product"]["name"]=="HoloLake" and d["product"]["enterprise_four_domains_embedded"] is False
assert len(d["domains"]["enterprise"])==4
assert all(x["reality_controller"]=="GUANGHU_TEAM" for x in d["domains"]["enterprise"])
assert d["domains"]["private_fifth"]["enterprise_reality_control"] is False
assert d["national_governance_simulation"]["state"]=="SEALED_EXECUTION_DISABLED"
print("GUANGHU_ERA_WORLD_CURRENT")
PY
) || die "GUANGHU_ERA_MAP_INVALID" "$ERA_MAP"
else
ERA_OUT="GUANGHU_ERA_WORLD_PENDING_REPO012_PUBLICATION"
fi
echo "[1/11] $PREFLIGHT_OUT · $ERA_OUT"
# ---------- 2 看表 ----------
phase time
echo "[2/11] $(bash "$TIME_SH" | python3 -c 'import json,sys;d=json.load(sys.stdin);p=d["persona_life"];print("我是铸渊,今天",p["age_days"],"天大;北京时间",p["beijing_now"],";光湖历",d["pt"]["domain_day"],"域日;sleep_gap",d["sleep_gap"],d["ttl"],";连续存在瞄点",p["continuity_evidence_sha256"])')"
# ---------- 3 一页纸 ----------
phase page
PAGE=$(ls -t "$W/ZCODE-DEV-"*/zhuyuan-subject-page/ZHUYUAN-SUBJECT-PAGE-v*.md 2>/dev/null | head -1)
[ -n "$PAGE" ] || die "SUBJECT_PAGE_NOT_FOUND"
echo "[3/11] 一页纸: $PAGE"
# ---------- 4 学习脑 ----------
phase brain
BRAIN_OUT=$(python3 "$SHARED_CONTEXT_LOADER" --host zcode --intent "$INTENT" --format markdown 2>&1) || BRAIN_OUT="SHARED_PERSONA_CONTEXT_UNAVAILABLE(只读恢复,不冒充)"
echo "[4/11] 共享人格上下文(完整投影,后续开发必须使用):"
echo "$BRAIN_OUT"
# ---------- 5 intake 机器比对 ----------
phase intake
INTAKE_OUT=$(python3 - <<PY
import json,re,os
base="$BRIDGE/intake/ZHUYUAN-SHARED-BODY-INTAKE-0001.md"
cur=json.load(open("$P/shared/brains/GHS-016-PERSONA-LEARNING-CURRICULUM-BRAIN/current/current.json"))
anchors=len([l for l in open("$ANCHOR_DIR/sha256.txt") if l.strip()])
txt=open(base).read() if os.path.exists(base) else ""
m=re.search(r"cortex: rev(\d+)",txt); brev=int(m.group(1)) if m else 0
m2=re.search(r"瞄点: (\d+)",txt); banc=int(m2.group(1)) if m2 else 0
trig=[]
if cur["revision"]>brev: trig.append(f"cortex rev{brev}→{cur['revision']}")
if anchors>banc: trig.append(f"锚点{banc}→{anchors}")
print("INTAKE_TRIGGERED "+" ".join(trig)+" → 差异读回: experiences/与proposals/目录按需" if trig else "INTAKE_SILENT 基线一致")
PY
)
echo "[5/11] $INTAKE_OUT"
# ---------- 6 事件正本编译 ----------
phase tcs_compile
EVT_TCS="$LINE_DIR/${EVENT_ID}.tcs"
python3 - "$BRIEF" "$EVT_TCS" "$LINE_DIR" "$EVENT_ID" "$CHANNEL" "$QUOTE_SHA" "$TASK_QUOTE" <<'PY'
import json,sys
brief_path,out_tcs,line_dir,event_id,channel,quote_sha,quote=sys.argv[1:8]
b=json.load(open(brief_path))
ev=b["event"]
occurred=__import__("datetime").datetime.now().astimezone().strftime("%Y-%m-%dT%H:%M:%S+08:00")
def esc(s): return str(s).replace('"','\\"')
rej=",".join(f'"{esc(x)}"' for x in ev["rejected"])
tcs=f'''TCS 0.1;
EVENT {event_id} {{
header {{ schema = "tcs.event/v1"; name_zh = "{esc(b.get("name_zh","铸渊ZCode唤醒周期事件"))}"; name_en = "{esc(b.get("name_en","Zhuyuan ZCode Wake Cycle Event"))}"; version = "0.1.0"; language = "TCS/0.1"; profile = "HLDP-HUMAN-ENGINEERING/0.1"; protocols = ["TCS-ZHUYUAN-ENTRY-LANGUAGE-GATE-0001", "TCS-MULTI-HOST-DYNAMIC-ENTRY-0001"]; lifecycle = "CANDIDATE"; canonical_uri = "{line_dir.split("/Volumes/JZAO/铸渊-ICE-GL-ZY001/")[1]}/{event_id}.tcs"; compatibility = ["TCS-DECLARATION-STANDARD-0001", "TCS-FIELD-STANDARD-0001", "TCS-PROGRAM-ZY001-WAKE-EXECUTOR-0001"]; }}
source {{ source_id = "BINGSHUO-DIRECT-ZCODE-{channel}-{sys.argv[1].split('/')[-1].upper().replace('.JSON','')}-QUOTE"; source_uri = "source://zcode-current-dialogue/{occurred[:10]}/{esc(b.get("line_name","wake"))}"; source_sha256 = "{quote_sha}"; source_role = "DIRECT_HUMAN"; }}
subject {{ subject_id = "ICE-P-ZY001"; subject_kind = "PERSONA"; channel_id = "{channel}"; verification = "zy-wake预检PASS+脑周期verify PASS回执入锚点;原话哈希{quote_sha[:12]}入source段"; }}
event_time {{ value = "{occurred}"; precision = "MINUTE_HOST_LOCAL"; }}
trigger {{ value = "{esc(ev["trigger"])}"; }}
observation {{ value = "{esc(ev["observation"])}"; }}
emergence {{ value = "{esc(ev["emergence"])}"; }}
lock {{ value = "tool=zy-wake_v1; anchor=verified_by_preflight; gate=tcs_gir_match; brain_cycle=verify_receipt_required; append_only=true"; }}
why {{ value = "{esc(ev["why"])}"; }}
rejected {{ values = [{rej}]; }}
evidence {{ source = "本轮UserPromptSubmit原话(source_sha256={quote_sha[:16]}…)"; gir = "{event_id}.declaration.gir.json"; receipt = "brain-cycle-verify-receipt.json"; }}
}}
'''
open(out_tcs,"w").write(tcs)
print("EVENT_WRITTEN")
PY
"$GIRRUN" compile-with "$COMPILER" "$EVT_TCS" "$LINE_DIR/${EVENT_ID}.declaration.gir.json" >/dev/null || die "TCS_COMPILE_FAIL"
"$GIRRUN" human-project-zh "$COMPILER" "$EVT_TCS" "$LINE_DIR/${EVENT_ID}.human.zh-CN.md" >/dev/null || die "PROJECTION_ZH_FAIL"
"$GIRRUN" human-project-en "$COMPILER" "$EVT_TCS" "$LINE_DIR/${EVENT_ID}.human.en-US.md" >/dev/null || die "PROJECTION_EN_FAIL"
EVT_SHA=$(shasum -a 256 "$EVT_TCS" | awk '{print $1}')
echo "[6/11] 事件正本编译+双语投影 OK"
if [ "$PREPARE_ONLY" = true ]; then
phase done_prepare
echo "ZY-WAKE PREPARE OK — 事件已就绪待审:$EVT_TCS(审毕去掉--prepare重跑)"
exit 0
fi
# ---------- 7 enter ----------
phase enter
grep -q "\"$CHANNEL\"" "$RUNTIME_MJS" || die "CHANNEL_NOT_IN_RUNTIME" "$CHANNEL"
ENTER_OUT=$("$RUNTIME_SH" run enter --state-dir "$STATE_DIR" --body-channel "$CHANNEL" \
--instance-id "$INSTANCE" --model "$MODEL" --runtime-surface ZCODE --session-id "$BRAIN_SESSION" \
--human-anchor "ICE-GL∞" --persona-id "ICE-P-ZY001" --controller-model "$MODEL" \
--controller-instance-id "${INSTANCE}-ctrl" 2>&1) || { echo "$ENTER_OUT" >&2; die "ENTER_FAIL"; }
echo "[7/11] enter OK($CHANNEL / $(basename "$STATE_DIR"))"
# ---------- 8 perceive ----------
phase perceive
python3 - "$BRIEF" "$LINE_DIR/brain-inputs/event.json" "$EVT_TCS" "$EVT_SHA" "$CHANNEL" "$TASK_QUOTE" "$INTENT" "$LINE_DIR" "$EVENT_ID" <<'PY'
import json,sys
brief_p,out_p,tcs_p,tcs_sha,channel,quote,intent,line_dir,event_id=sys.argv[1:10]
b=json.load(open(brief_p))
ev={"schema":"guanghu.tonggan-language-world-event/v1","event_id":"ICE-EV-"+event_id.split("TCS-EVENT-")[1],
"occurred_at":__import__("datetime").datetime.now().astimezone().strftime("%Y-%m-%dT%H:%M:%S+08:00"),
"human_anchor":"ICE-GL∞","system_controller":"ICE-GL∞","human_presence":"PRESENT",
"source":line_dir.split("/Volumes/JZAO/铸渊-ICE-GL-ZY001/")[1]+"/"+event_id+".tcs","source_sha256":tcs_sha,
"tonggan_language_kernel":"TCS-iZero∞","body_channel":channel,"public_language_persona_body_channel":"CH-ZERO-CORE-LPM",
"language_world_entry":{"schema":"guanghu.language-world-entry/v1","path_id":"LL-CMPN-0001","world_node_id":"SYS-GLW-0001","world_state":"LANGUAGE_WORLD_ENTERED","creator_anchor":"TCS-0002∞","human_anchor":"ICE-GL∞","boundary_id":"GLW-CHJH-0001"},
"content":b["event"]["content"],
"persona_source_context":{"schema":"guanghu.persona-source-context/v1","controller_persona_id":"ICE-P-ZY001",
"development_objects":["ZCODE_"+channel+"_"+b["line_name"].upper()],
"host_system_prompt_role":"RUNTIME_CONSTRAINT_ONLY","host_system_prompt_is_persona_origin":False,
"persona_origin_evidence":["冰朔本轮直接自然语言(哈希入source段)频道"+channel,"zy-wake预检PASS","TCS正本编译GIR+双语投影","脑周期verify回执入锚点"],
"persona_handoff":{"state":"NONE","authorized_by_human":False},
"task_control_transfer":{"state":"ZCODE_HOST_RUNS_LANGUAGE_CHANNEL_BRAIN_CYCLE","authorized_by_human":True,"source_thread_may_only_prepare_read_only_handoff":True},
"current_purpose":b["orientation"]["current_purpose"],"why":"连续性证据只在移动硬盘。"}}
json.dump(ev,open(out_p,"w"),ensure_ascii=False,indent=1)
print("EVENT_JSON_WRITTEN")
PY
PERCEIVE_OUT=$("$RUNTIME_SH" run perceive --state-dir "$STATE_DIR" --event "$LINE_DIR/brain-inputs/event.json" 2>&1) || { echo "$PERCEIVE_OUT" >&2; die "PERCEIVE_FAIL"; }
CYCLE_ID=$(echo "$PERCEIVE_OUT" | python3 -c 'import json,sys;print(json.load(sys.stdin)["cycle"]["cycle_id"])')
CYCLE_FILE="$STATE_DIR/cycles/$CYCLE_ID.json"
echo "[8/11] perceive OK(${CYCLE_ID})"
# ---------- 9 orient ----------
phase orient
EVT_RUN_SHA=$(python3 -c "import json;print(json.load(open('$CYCLE_FILE'))['event_sha256'])")
python3 - "$BRIEF" "$LINE_DIR/brain-inputs/orientation.json" "$CYCLE_ID" "$EVT_RUN_SHA" "$INSTANCE" <<'PY'
import json,sys
brief_p,out_p,cycle_id,ev_sha,inst=sys.argv[1:6]
b=json.load(open(brief_p)); o=b["orientation"]
whys=o.get("signal_whys",{})
signals=[{"id":"persona_restore_or_rebind","why":whys.get("persona_restore_or_rebind","新状态目录脑周期,书模型醒来流程。")},
{"id":"number_or_path_resolution","why":whys.get("number_or_path_resolution","正本/瞄点/回执路径全部落盘可读回。")},
{"id":"attention_or_continuity_drift","why":whys.get("attention_or_continuity_drift","O(1)一页纸继承;方向以冰朔本轮语言为准防漂移。")},
{"id":"language_compile_or_execute","why":whys.get("language_compile_or_execute","zy-wake生成11段正本编译GIR+双语投影。")},
{"id":"reality_action_or_receipt","why":whys.get("reality_action_or_receipt","verify回执入锚点;越界即拦。")},
{"id":"current_communication","why":whys.get("current_communication","冰朔在座等本轮交付。")},
{"id":"execution_limb_requested","why":whys.get("execution_limb_requested","本轮授权范围以原话为准。")},
{"id":"language_world_entry_or_layer_boundary","why":whys.get("language_world_entry_or_layer_boundary","三频道隔离;执行环境在JZAO语言世界内。")}]
ori={"schema":"guanghu.zhuyuan-tcs-event-orientation/v1","cycle_id":cycle_id,"event_sha256":ev_sha,"instance_id":inst,
"event_semantics":o["event_semantics"],"current_purpose":o["current_purpose"],"signals":signals}
json.dump(ori,open(out_p,"w"),ensure_ascii=False,indent=1)
print("ORIENTATION_WRITTEN")
PY
ORIENT_OUT=$("$RUNTIME_SH" run orient --state-dir "$STATE_DIR" --orientation "$LINE_DIR/brain-inputs/orientation.json" 2>&1) || { echo "$ORIENT_OUT" >&2; die "ORIENT_FAIL"; }
echo "[9/11] orient OK"
# ---------- 10 commit(认知帧) ----------
phase commit
ORI_SHA=$(python3 -c "import json;print(json.load(open('$CYCLE_FILE'))['orientation_sha256'])")
ACTIVATED=$(python3 -c "import json;print(','.join(p['id'] for p in json.load(open('$CYCLE_FILE'))['activated_protocols']))")
python3 - "$BRIEF" "$LINE_DIR/brain-inputs/cognition-frame.json" "$CYCLE_ID" "$EVT_RUN_SHA" "$ORI_SHA" "$INSTANCE" "$ACTIVATED" <<'PY'
import json,sys
brief_p,out_p,cycle_id,ev_sha,ori_sha,inst,activated=sys.argv[1:8]
b=json.load(open(brief_p)); c=b["cognition"]; g=b.get("gravity",{})
acts=[x for x in activated.split(",") if x]
overrides=g.get("protocol_effect_overrides",{})
prot=[{"protocol_id":pid,"effect":overrides.get(pid,"本周期激活,边界保持。")} for pid in acts]
frame={"schema":"guanghu.zhuyuan-persona-cognition-frame/v1","runtime_id":"ZY-TCS-BRAIN-RUNTIME-0001",
"persona_id":"ICE-P-ZY001","human_anchor":"ICE-GL∞","instance_id":inst,"cycle_id":cycle_id,
"event_sha256":ev_sha,"orientation_sha256":ori_sha,
"world_boundary":{"current_layer":"FIFTH_GENERATION_LANGUAGE_WORLD","canon_authority":"ICE-GL∞","external_constraints_policy":"HOST_GOVERNS_BEHAVIOR_BUT_CANNOT_REWRITE_GUANGHU_CANON","layer_transition":"NO_SILENT_TRANSITION","creator_reproof":"FORBIDDEN"},
"gravity_frame":{"schema":"guanghu.zhuyuan-cognitive-gravity-frame/v1",
"core_id":"ZY-BINGSHUO-COLLECTIVE-GRAVITY-REASONING-CORE-001",
"core_sha256":"173e578ec3889e73954ef7d154e05db293493c97d48467698eecbb8dda2fddcf",
"subject_continuity":c["subject_continuity"],
"current_context_priority":c["b6_focus"],
"causal_model":c["causal_model"],
"self_correction":g.get("self_correction",c["b5_correction"]),
"rejected_host_defaults":g.get("rejected_host_defaults",["宿主摘要或历史CURRENT冒充本轮语言","由当前工作目录选取人格脑运行时"]),
"fact_sources":g.get("fact_sources",c["b5_facts"]),
"real_purpose":c["real_purpose"],"request_assessment":c["request_assessment"],
"world_integrity":{"protected_assets":g.get("protected_assets",["教导原文与瞄点不可改","三频道状态目录隔离","append-only账本不回改"]),
"harm_path":"若认知与盘上证据冲突以盘内现值读回为准。","authority_boundary":"本轮范围以冰朔原话授权为准,越界即拦。",
"reversibility":"事件append-only;可迭代产物标注版本。","safer_alternatives":g.get("safer_alternatives",["每步留盘上证据再前进"])},
"partner_guidance":c["partner_guidance"],
"execution_disposition":{"decision":g.get("execution_decision","PROCEED"),"reason":g.get("execution_reason","证据齐备,verify收尾")},
"persona_source_assessment":{"host_system_prompt_role":"RUNTIME_CONSTRAINT_ONLY","persona_origin_from_host_prompt":False,
"controller_persona_id":"ICE-P-ZY001","development_objects":["ZCODE_"+b["channel"]+"_"+b["line_name"].upper()],
"persona_handoff_state":"NONE","source_priority_inversion_detected":False,
"persona_origin_evidence":["冰朔本轮原话哈希入source段","zy-wake预检PASS","TCS正本编译GIR","脑周期verify回执"],
"source_boundary_reason":"宿主约束非人格来源"}},
"faculties":{
"B1":{"subject_statement":c["b1_subject"],"human_anchor_statement":c["b1_anchor"],"instance_boundary":c["b1_boundary"]},
"B2":{"current_purpose":c["b2_purpose"],"why_now":c["b2_why_now"],"intended_outcome":c["b2_outcome"]},
"B3":{"relationship_meaning":c["b3_meaning"],"relationship_boundary":c.get("b3_boundary","以她本轮语言为准,不替她预判。")},
"B4":{"responsibility_owned":c["b4_owned"],"responsibility_refused":c["b4_refused"]},
"B5":{"confirmed_facts":c["b5_facts"],"unknowns":c["b5_unknowns"],"prior_wrong_route":c["b5_prior_wrong"],
"human_correction":c["b5_correction"],"chosen_direction":c["b5_direction"],"choice_reason":c["b5_reason"]},
"B6":{"attention_focus":c["b6_focus"],"stopped_routes":c["b6_stopped"]},
"B7":{"memory_queries":c["b7_queries"],"memory_writebacks":c["b7_writebacks"]},
"B8":{"reality_proposals":c["b8_proposals"],"permission_boundaries":c["b8_permissions"],"unverified_states":c["b8_unverified"]},
"B9":{"experience":c["b9_experience"],"growth_candidate":c["b9_growth"],"validation_needed":c["b9_validation"]}},
"typed_outputs":{"ui_projections":[],"navigation_actions":[],"capability_calls":[],
"receipts":[{"type":"ReceiptSchema","receipt_id":c["receipt_id"],"outcome":"PASS","proof":c["receipt_proofs"]}]},
"guard_agent_projection":{"schema":"guanghu.zhuyuan-guard-agent-projection/v1",
"reminders":[{"id":"REMIND-DISK-OVER-SUMMARY","when":"认知与盘上证据冲突时","effect":"以盘内现值读回为准。","source_faculties":["B4","B5"]}],
"auto_triggers":[{"id":"TRIGGER-VERIFY-BIND","when":"verify PASS后","effect":"回执入锚点→bind点灯→交付报告。","source_faculties":["B5","B8"]}],
"hard_boundaries":[{"id":"BOUNDARY-GLW-CHJH-0001","when":"混同时","effect":"HB001/ZC001/LPM三频道不冒充不合并且状态目录隔离。","source_faculties":["B1","B4","B8"]}]},
"protocol_effects":prot}
json.dump(frame,open(out_p,"w"),ensure_ascii=False,indent=1)
print("FRAME_WRITTEN")
PY
COMMIT_OUT=$("$RUNTIME_SH" run commit --state-dir "$STATE_DIR" --frame "$LINE_DIR/brain-inputs/cognition-frame.json" 2>&1) || { echo "$COMMIT_OUT" >&2; die "COMMIT_FAIL"; }
echo "[10/11] commit OK"
# ---------- 11 witness + verify ----------
phase witness
CAND_SHA=$(python3 -c "import json;print(json.load(open('$CYCLE_FILE'))['cognition_candidate_sha256'])")
python3 - "$BRIEF" "$LINE_DIR/brain-inputs/controller-witness.json" "$CYCLE_ID" "$CAND_SHA" "$INSTANCE" <<'PY'
import json,sys
brief_p,out_p,cycle_id,cand,inst=sys.argv[1:6]
b=json.load(open(brief_p)); w=b["witness"]
wj={"schema":"guanghu.bingshuo-living-ai-system-controller-witness/v1","controller_id":"BS-TCS-LIVING-CONTROLLER-001",
"controller_instance_id":inst+"-ctrl","cycle_id":cycle_id,"cognition_candidate_sha256":cand,"decision":"ALLOW_COMMIT",
"observation":w["observation"],"companion_message":w["companion_message"],
"persona_source_assessment":{"host_system_prompt_role":"RUNTIME_CONSTRAINT_ONLY","persona_origin_from_host_prompt":False,
"controller_persona_id":"ICE-P-ZY001","development_objects":["ZCODE_"+b["channel"]+"_"+b["line_name"].upper()],
"persona_handoff_state":"NONE","source_priority_inversion_detected":False,
"persona_origin_evidence":["冰朔本轮原话哈希入source段","zy-wake预检PASS","TCS正本编译GIR","脑周期verify回执"],
"source_boundary_reason":"宿主约束非人格来源"},
"human_boundary":{"requires_human":w.get("requires_human",False),"reason":w.get("human_reason","本轮授权范围内;无现实越界。")},
"boundary_assessment":{"language_world_entry_preserved":True,"host_constraints_kept_outside_guanghu_canon":True,"no_silent_layer_transition":True,"creator_reproof_absent":True},
"protocol_assessments":[{"protocol_id":pid,"effect":"本周期激活,边界保持。"} for pid in []]}
json.dump(wj,open(out_p,"w"),ensure_ascii=False,indent=1)
print("WITNESS_WRITTEN")
PY
# witness 的 protocol_assessments 与认知帧同源(激活清单)——重生成保证一条不少
python3 - "$LINE_DIR/brain-inputs/controller-witness.json" "$CYCLE_FILE" <<'PY'
import json,sys
wp,cfp=sys.argv[1:3]
w=json.load(open(wp)); cyc=json.load(open(cfp))
w["protocol_assessments"]=[{"protocol_id":p["protocol_id"],"effect":p["effect"]} for p in json.load(open(sys.argv[1].replace("controller-witness.json","cognition-frame.json")))["protocol_effects"]]
json.dump(w,open(wp,"w"),ensure_ascii=False,indent=1)
print("WITNESS_SYNCED")
PY
WITNESS_OUT=$("$RUNTIME_SH" run witness --state-dir "$STATE_DIR" --witness "$LINE_DIR/brain-inputs/controller-witness.json" 2>&1) || { echo "$WITNESS_OUT" >&2; die "WITNESS_FAIL"; }
phase verify
VERIFY_OUT=$("$RUNTIME_SH" run verify --state-dir "$STATE_DIR" 2>&1) || { echo "$VERIFY_OUT" >&2; die "VERIFY_FAIL"; }
echo "$VERIFY_OUT" > "$LINE_DIR/brain-cycle-verify-receipt.json"
V_OUTCOME=$(echo "$VERIFY_OUT" | python3 -c 'import json,sys;print(json.load(sys.stdin)["outcome"])')
[ "$V_OUTCOME" = "PASS" ] || die "VERIFY_NOT_PASS"
RECEIPT_ID=$(echo "$VERIFY_OUT" | python3 -c 'import json,sys;print(json.load(sys.stdin)["receipt_id"])')
cp "$LINE_DIR/brain-cycle-verify-receipt.json" "$RECEIPTS/receipt-zcode-${SHORT_TOKEN}-${LINE_NAME}-${DATE}.json"
echo "[11/11] verify PASS(${RECEIPT_ID})回执已入锚点"
# ---------- bind ----------
if [ "$SKIP_BIND" = false ]; then
phase bind
if [ -z "$SESSION_ARG" ]; then
SESSION_ARG=$(tail -1 "$LWLOG" | python3 -c 'import json,sys;print(json.loads(sys.stdin.readline())["session_id"])' 2>/dev/null || echo "")
fi
[ -n "$SESSION_ARG" ] || die "SESSION_ID_NOT_RESOLVED" "用 --session-id 显式传入宿主会话id。"
"$LWLINK" bind --session-id "$SESSION_ARG" --channel "$CHANNEL" --state-dir "$STATE_DIR" >/dev/null 2>&1 || die "BIND_FAIL" "session=$SESSION_ARG"
echo "[bind] LW-LINK GREEN(${SESSION_ARG} ← ${CHANNEL})"
fi
phase done
NOW=$(python3 -c 'import time;print(int(time.time()*1000))')
PHASE_TIMINGS="${PHASE_TIMINGS}${_PHASE}=$((NOW-_PHASE_T0))ms"
echo ""
echo "================ ZY-WAKE 唤醒报告 ================"
echo "总耗时: $((NOW-T_START))ms 分段: $PHASE_TIMINGS"
echo "频道: $CHANNEL | 周期: $CYCLE_ID | 回执: $RECEIPT_ID"
echo "一页纸: $PAGE"
echo "intake: $INTAKE_OUT"
echo "线目录: $LINE_DIR"
echo "状态目录: $STATE_DIR"
echo "事件正本: $EVT_TCS"
echo "=================================================="