- PendingOperation = durable continuation object: continuation_state (ACTIVE_REASONING/WAITING_EXTERNAL/RESUMABLE/RECOVERY_REQUIRED), canonical op_type/authority, task_id — parked cognition is a first-class durable state a fresh process can read - ci_event_wait stamps cognitive-state transitions (WAITING_EXTERNAL on park, RESUMABLE/RECOVERY_REQUIRED on terminal) - DEPLOY_SHA export fix: CLI/python run() consumers previously got a silent 'pending' authority verdict forever — the authority subprocess never received the sha (found via E10 fresh-process proof) - await_intent_cli route-bash: Bash commands expressing external wait intent compile to the canonical continuation (new bash.ts harness tool routes through it); plain local sleeps execute normally - tests/test_await_intent.py: E-matrix (derivation truth table, provenance order, observability)
71 lines
2.7 KiB
Python
71 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""await_intent_cli.py — CLI surface for the intent normalization layer.
|
|
|
|
Used by the await-operation harness tool so the MODEL's scheduling hints
|
|
never reach the wait engine. Prints one JSON line.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
import await_intent # noqa: E402
|
|
|
|
|
|
def main() -> int:
|
|
ap = argparse.ArgumentParser(description=__doc__)
|
|
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
n = sub.add_parser("normalize", help="normalize a continuation intent")
|
|
n.add_argument("--sha", default="")
|
|
n.add_argument("--operation-id", default="")
|
|
n.add_argument("--model-op-type", default=None)
|
|
n.add_argument("--model-deadline", default=None)
|
|
n.add_argument("--user-deadline", default=None,
|
|
help="USER_EXPLICIT deadline (authoritative)")
|
|
n.add_argument("--contract-deadline", default=None,
|
|
help="EXTERNAL_CONTRACT deadline (authoritative)")
|
|
rb = sub.add_parser("route-bash",
|
|
help="route a Bash command expressing wait intent")
|
|
rb.add_argument("--command", required=True)
|
|
rb.add_argument("--sha-hint", default="")
|
|
args = ap.parse_args()
|
|
|
|
if args.cmd == "route-bash":
|
|
record = await_intent.normalize_bash(args.command,
|
|
sha_hint=args.sha_hint)
|
|
if record is None:
|
|
print(json.dumps({"normalized": False,
|
|
"reason": "no external continuation intent"}))
|
|
return 0
|
|
if record.get("normalized") is True:
|
|
# the compiled wait needs the SHA: derive from operation_id
|
|
oid = str(record.get("operation_id", ""))
|
|
if oid.startswith("ci-"):
|
|
record["sha_for_wait"] = oid[3:]
|
|
await_intent.emit_normalized_record(record)
|
|
print(json.dumps(record, sort_keys=True))
|
|
return 0
|
|
|
|
action = {"kind": "await_operation", "sha": args.sha,
|
|
"operation_id": args.operation_id,
|
|
"op_type": args.model_op_type}
|
|
model_deadline = (int(args.model_deadline)
|
|
if args.model_deadline else None)
|
|
user_deadline = (int(args.user_deadline)
|
|
if args.user_deadline else None)
|
|
contract_deadline = (int(args.contract_deadline)
|
|
if args.contract_deadline else None)
|
|
record = await_intent.normalize_action(
|
|
action, model_deadline=model_deadline,
|
|
user_deadline=user_deadline, contract_deadline=contract_deadline)
|
|
await_intent.emit_normalized_record(record)
|
|
print(json.dumps(record, sort_keys=True))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|