feat: auto-activate current persona subagent command

This commit is contained in:
冰朔 2026-09-08 14:33:29 +08:00
commit ccb7992090
8 changed files with 47 additions and 17 deletions

View file

@ -10,7 +10,7 @@ from typing import Any
ROOT = Path(__file__).resolve().parents[2]
MAP = ROOT / "routing/persona-dynamic-subagent-command-map.json"
PERSONAS = ROOT / "routing/persona-system-canonical-map.json"
DEFAULT_STATE = Path("/Volumes/JZAO/HoloLake/persona-runtime/shared/persona-subagent-command")
DEFAULT_STATE = Path("/Volumes/JZAO/HoloLake/persona-runtime/shared/persona-subagent-command/codex")
RUNTIMES = {"codex":"/Applications/ChatGPT.app/Contents/Resources/codex", "qwen":"/Users/bingshuolingdianyuanhe/.npm-global/bin/qwen"}
OPENLUX_ROUTER = ROOT / "server-tools/persona-model-smart-router/openlux_router.py"
@ -55,7 +55,7 @@ def atomic(path: Path, value: dict[str, Any]) -> None:
def activate(event: dict[str, Any], state: Path) -> dict[str, Any]:
for k in ("parent_persona_id","session_id","channel_id","direct_event_sha256","model_runtime"):
for k in ("parent_persona_id","session_id","channel_id","current_intent_sha256","model_runtime"):
if not isinstance(event.get(k),str) or not event[k].strip(): raise CommandError(f"REQUIRED_FIELD:{k}")
if event["parent_persona_id"] not in registered_personas(): raise CommandError("PARENT_PERSONA_NOT_REGISTERED")
if not runtime_available(event["model_runtime"]): raise CommandError("MODEL_PROVIDER_UNAVAILABLE_NO_AGENT_ACTIVATION")
@ -73,7 +73,7 @@ def activate(event: dict[str, Any], state: Path) -> dict[str, Any]:
"cognition_adapter":"server-tools/persona-execution-limb-agent/persona_limb_agent.py",
"deterministic_organ":slot["deterministic_organ"], "task_authority":"NONE_UNTIL_PARENT_ENVELOPE"
})
result={"schema":"guanghu.persona-subagent-command-current/v1","state":"ACTIVE_UNDER_CURRENT_PERSONA","generation":generation,"parent_persona_id":event["parent_persona_id"],"session_id":event["session_id"],"channel_id":event["channel_id"],"direct_event_sha256":event["direct_event_sha256"],"model_runtime":event["model_runtime"],"team":team,"prior_generation_invalidated":bool(previous),"credentials_stored":False,"authority_granted":False}
result={"schema":"guanghu.persona-subagent-command-current/v1","state":"ACTIVE_UNDER_CURRENT_PERSONA","generation":generation,"parent_persona_id":event["parent_persona_id"],"session_id":event["session_id"],"channel_id":event["channel_id"],"current_intent_sha256":event["current_intent_sha256"],"model_runtime":event["model_runtime"],"team":team,"prior_generation_invalidated":bool(previous),"credentials_stored":False,"authority_granted":False}
result["binding_sha256"]=digest(stable(result))
atomic(current_path,result)
return result
@ -98,13 +98,17 @@ def dispatch(event: dict[str, Any], state: Path) -> dict[str, Any]:
def main() -> int:
p=argparse.ArgumentParser(); p.add_argument("command",choices=("probe","activate","status","dispatch")); p.add_argument("--input"); p.add_argument("--state-root",default=str(DEFAULT_STATE)); a=p.parse_args(); state=Path(a.state_root)
p=argparse.ArgumentParser(); p.add_argument("command",choices=("probe","activate","status","dispatch")); p.add_argument("--input"); p.add_argument("--stdin",action="store_true"); p.add_argument("--state-root",default=str(DEFAULT_STATE)); a=p.parse_args(); state=Path(a.state_root)
try:
if a.command=="probe": result={"outcome":"PASS","model_runtimes":{k:runtime_available(k) for k in [*RUNTIMES,"openlux-smart","hololake-model-gateway"]},"repository_credentials":False}
elif a.command=="status": result=load(state/"CURRENT.json") if (state/"CURRENT.json").is_file() else {"outcome":"FAIL","state":"NO_ACTIVE_COMMANDER"}
else:
if not a.input: raise CommandError("INPUT_REQUIRED")
event=load(Path(a.input)); result=activate(event,state) if a.command=="activate" else dispatch(event,state)
if a.stdin:
event=json.load(os.sys.stdin)
elif a.input:
event=load(Path(a.input))
else: raise CommandError("INPUT_REQUIRED")
result=activate(event,state) if a.command=="activate" else dispatch(event,state)
print(json.dumps(result,ensure_ascii=False,indent=2,sort_keys=True)); return 0
except Exception as e:
print(json.dumps({"outcome":"FAIL","error":str(e)},ensure_ascii=False)); return 2

View file

@ -5,7 +5,7 @@ from unittest.mock import patch
S=Path(__file__).with_name('command_router.py'); spec=importlib.util.spec_from_file_location('router',S); M=importlib.util.module_from_spec(spec); spec.loader.exec_module(M)
def event(persona='ICE-P-ZY001', session='s1'):
return {"parent_persona_id":persona,"session_id":session,"channel_id":"ICE-CH-HB001","direct_event_sha256":"a"*64,"model_runtime":"codex"}
return {"parent_persona_id":persona,"session_id":session,"channel_id":"ICE-CH-HB001","current_intent_sha256":"a"*64,"model_runtime":"codex"}
class Tests(unittest.TestCase):
def test_every_slot_is_model_backed_and_owned_by_parent(self):