A Zig re-implementation of the core runtime ideas from pi-mono.
Scope (MVP): a small, auditable plan runner with tool execution + run artifacts. Not a 1:1 rewrite of the entire TypeScript monorepo.
plan.jsoninput (schema,workflow,steps[])- deterministic topo execution (dependsOn)
- built-in tools:
echo,sleep_ms - fail-closed: missing deps / cycles => error
- artifacts:
runs/<runId>/plan.jsonruns/<runId>/run.jsonruns/<runId>/steps/<stepId>.json
zig buildzig build run -- run --plan examples/hello.plan.jsonzig build run -- verify --run <runId>This is a minimal AgentLoop clone (uses a deterministic mock model).
JSONL entries are now structured (not just plain messages):
type: sessiontype: messagetype: tool_calltype: tool_resulttype: leaf(tracks current leaf for branching)
# creates/extends a JSONL session
zig build run -- chat --session /tmp/pi-session.jsonl
# replay the JSONL log
zig build run -- replay --session /tmp/pi-session.jsonlTry:
echo: hellosh: ls(only if you pass--allow-shell)
Branching + labels (session tree MVP):
# list current leaf path (shows entryIds)
zig build run -- list --session /tmp/pi-session.jsonl
# label a node
zig build run -- label --session /tmp/pi-session.jsonl --to <entryId> --label ROOT
# branch leaf to an earlier node
zig build run -- branch --session /tmp/pi-session.jsonl --to <entryId>
# replay follows current leaf (root -> leaf path)
zig build run -- replay --session /tmp/pi-session.jsonl
# show full details for one entry
zig build run -- show --session /tmp/pi-session.jsonl --id <entryId>
# show full session tree ("*" marks current leaf path)
zig build run -- tree --session /tmp/pi-session.jsonl
# compact current leaf path into a summary + keep last N nodes
zig build run -- compact --session /tmp/pi-session.jsonl --keep-last 8
# preview compaction summary without writing
zig build run -- compact --session /tmp/pi-session.jsonl --keep-last 8 --dry-run
# TS-aligned structured summary (markdown)
zig build run -- compact --session /tmp/pi-session.jsonl --keep-last 8 --dry-run --structured md
# Update an existing structured summary (naive merge):
# - ensures Next Steps / In Progress placeholders are actionable
# - appends new snippets into Critical Context
zig build run -- compact --session /tmp/pi-session.jsonl --keep-last 8 --structured md --update
# Keep last N complete turn-groups (TS-like) instead of last N entries
zig build run -- compact --session /tmp/pi-session.jsonl --keep-last-groups 2 --structured md
# Record thresholds in the summary stats (manual compaction)
zig build run -- compact --session /tmp/pi-session.jsonl --keep-last-groups 2 --structured md --max-chars 8000 --max-tokens-est 2000
# structured summary (json)
zig build run -- compact --session /tmp/pi-session.jsonl --keep-last 8 --dry-run --structured json
# auto-compact while chatting (naive char-count threshold)
# (now calls the same compaction logic: summary + keep-last tail clone)
zig build run -- chat --session /tmp/pi-session.jsonl --auto-compact --max-chars 8000 --keep-last 8This currently checks:
runs/<runId>/plan.jsonexists and is validruns/<runId>/run.jsonexistsruns/<runId>/steps/<stepId>.jsonexists for every step in the plan- every step artifact has
ok: trueand matchingrunId
See examples/hello.plan.json.