feat(persona): add reflex arc and embedded time system
This commit is contained in:
parent
4423b4bc2f
commit
28a60b4e80
19 changed files with 1382 additions and 81 deletions
|
|
@ -16,6 +16,7 @@ RUNTIMES = {
|
|||
"qwen": "/Users/bingshuolingdianyuanhe/.npm-global/bin/qwen",
|
||||
"opencode": "/Users/bingshuolingdianyuanhe/.npm-global/bin/opencode",
|
||||
"codex": "/Applications/ChatGPT.app/Contents/Resources/codex",
|
||||
"zcode": "/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs",
|
||||
}
|
||||
QWEN_AUTH_TYPE = "openai"
|
||||
QWEN_MODELS = ["qwen3.8-max", "qwen3.7-plus", "deepseek-v4-pro", "deepseek-v4-flash-0731", "glm-5.2"]
|
||||
|
|
@ -53,7 +54,7 @@ def probe() -> dict:
|
|||
}
|
||||
|
||||
|
||||
def envelope(persona_id: str, task_id: str, task: str, runtime: str) -> dict:
|
||||
def envelope(persona_id: str, task_id: str, task: str, runtime: str, access: str = "read-only") -> dict:
|
||||
tools = probe()["runtimes"]
|
||||
if runtime not in tools or not tools[runtime]["available"]:
|
||||
raise ValueError("HOST_TOOL_UNAVAILABLE_REPORT_NOT_INVENT")
|
||||
|
|
@ -64,6 +65,7 @@ def envelope(persona_id: str, task_id: str, task: str, runtime: str) -> dict:
|
|||
"parent_persona_id": persona_id,
|
||||
"limb_profile_id": p["profile_id"],
|
||||
"runtime": runtime,
|
||||
"access": access,
|
||||
"task": task,
|
||||
"working_defaults": p["working_defaults"],
|
||||
"authority": "CURRENT_TASK_ENVELOPE_ONLY",
|
||||
|
|
@ -83,6 +85,13 @@ def prompt(value: dict) -> str:
|
|||
)
|
||||
|
||||
|
||||
def zcode_succeeded(completed: subprocess.CompletedProcess[str]) -> bool:
|
||||
if completed.returncode != 0:
|
||||
return False
|
||||
text = completed.stdout.strip()
|
||||
return bool(text) and "[API Error" not in text
|
||||
|
||||
|
||||
def qwen_succeeded(completed: subprocess.CompletedProcess[str]) -> bool:
|
||||
if completed.returncode != 0 or "[API Error:" in completed.stdout:
|
||||
return False
|
||||
|
|
@ -121,18 +130,20 @@ def main() -> int:
|
|||
p.add_argument("--task-id", required=True)
|
||||
p.add_argument("--task", required=True)
|
||||
p.add_argument("--runtime", required=True, choices=tuple(RUNTIMES))
|
||||
p.add_argument("--access", choices=("read-only", "workspace-write"), default="read-only")
|
||||
run = sub.add_parser("run")
|
||||
run.add_argument("--persona", required=True)
|
||||
run.add_argument("--task-id", required=True)
|
||||
run.add_argument("--task", required=True)
|
||||
run.add_argument("--runtime", required=True, choices=("qwen", "codex"))
|
||||
run.add_argument("--runtime", required=True, choices=("qwen", "codex", "zcode"))
|
||||
run.add_argument("--cwd", required=True)
|
||||
run.add_argument("--access", choices=("read-only", "workspace-write"), default="read-only")
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
if args.command == "probe":
|
||||
result = probe()
|
||||
else:
|
||||
value = envelope(args.persona, args.task_id, args.task, args.runtime)
|
||||
value = envelope(args.persona, args.task_id, args.task, args.runtime, args.access)
|
||||
if args.command == "prepare":
|
||||
result = value
|
||||
else:
|
||||
|
|
@ -160,7 +171,7 @@ def main() -> int:
|
|||
if ok:
|
||||
selected_model = model
|
||||
break
|
||||
else:
|
||||
elif args.runtime == "codex":
|
||||
candidate = subprocess.run(
|
||||
[
|
||||
RUNTIMES["codex"],
|
||||
|
|
@ -168,18 +179,33 @@ def main() -> int:
|
|||
"exec",
|
||||
"--ephemeral",
|
||||
"--ignore-rules",
|
||||
"--sandbox", "read-only",
|
||||
"--sandbox", args.access,
|
||||
"--cd", str(cwd),
|
||||
"--json",
|
||||
prompt(value),
|
||||
],
|
||||
cwd=cwd, capture_output=True, text=True, timeout=180, check=False,
|
||||
cwd=cwd, capture_output=True, text=True, timeout=420, check=False,
|
||||
)
|
||||
ok = codex_succeeded(candidate)
|
||||
attempts.append({"model": "codex-configured-default", "exit_code": candidate.returncode, "semantic_success": ok})
|
||||
completed = candidate
|
||||
if ok:
|
||||
selected_model = "codex-configured-default"
|
||||
else:
|
||||
candidate = subprocess.run(
|
||||
[
|
||||
"node",
|
||||
RUNTIMES["zcode"],
|
||||
"--prompt", prompt(value),
|
||||
"--surface", "terminal",
|
||||
],
|
||||
cwd=cwd, capture_output=True, text=True, timeout=180, check=False,
|
||||
)
|
||||
ok = zcode_succeeded(candidate)
|
||||
attempts.append({"model": "zcode-configured-default", "exit_code": candidate.returncode, "semantic_success": ok})
|
||||
completed = candidate
|
||||
if ok:
|
||||
selected_model = "zcode-configured-default"
|
||||
assert completed is not None
|
||||
success = selected_model is not None
|
||||
result = {
|
||||
|
|
@ -187,6 +213,7 @@ def main() -> int:
|
|||
"task_id": value["task_id"],
|
||||
"parent_persona_id": value["parent_persona_id"],
|
||||
"runtime": args.runtime,
|
||||
"access": args.access,
|
||||
"selected_model": selected_model,
|
||||
"attempts": attempts,
|
||||
"exit_code": completed.returncode,
|
||||
|
|
|
|||
Loading…
Reference in a new issue