Repository-Native Agent Orchestration (Task-Card Protocol for Coding Agents)
Role: Solo, end-to-end: protocol design, scripts in two languages, test harness, adapters for two coding tools, and the owner in every owner gate.
Tech Stack: Windows PowerShell 5.1 and stdlib-only Python 3.12+ (every script exists in both), pytest 9.1.1 with pytest-xdist, Git worktrees, GitHub Actions. The case study, spendtrace, is Python 3.12 with no dependencies over one SQLite file.
Repository: Private, both of them (repository-native-agent-orchestration, MIT licensed, and spendtrace). Demo available on request
Overview
The kit is a control protocol that coding agents follow inside a normal repository. An approved plan becomes a graph of task cards, each card is implemented by one agent and accepted by a different one, and every state change is written to files under Git so a new session can pick up where the last one stopped without reading a chat log.
It was a reaction. I wanted to keep pursuing several projects in parallel with many subagents, but I wanted a better handle on what they were doing, and I wanted to be more responsible about token use and efficiency. The spec I wrote later for spendtrace puts numbers on the week that prompted it. From Sep 14 to 20, 2026, I ran several agents at once across three projects, much of it unattended, in the same week a 1M-token context became my default. Daily spend on Sep 17 was about 16 times what it was on Sep 14, it stayed near that level on the 18th, and it was back near the starting level on the 19th. Over the whole export (Feb 12 to Oct 10, 2026), 96% of all tokens were cache reads, and Claude models read about 179 cached tokens for every output token. Cost followed context, not output, and I had no way to say which feature any of it had bought.
So I built two things. The kit is the attempt to run parallel agents with rules that live in the repo. spendtrace is the attempt to measure what agent work costs per feature, and I built it with the kit so the kit would have a real project to prove itself on. What it proved is mostly on this page under âWhat spendtrace foundâ.
The kit is 224 commits between 2026-09-21 and 2026-09-27, ending at v0.4.0 (3951c07), with 1,020 def test_ functions in its harness (grep at 3951c07 on 2026-11-22, not a run). Each script test runs against both the PowerShell and the Python implementation; the changelog records 1,920 passed and 5 skipped in 21 minutes 10 seconds on Windows at 385614d (2026-09-25).
How the Kit Works
graph TD
P[Plan or specification] --> M[Card map, reviewed by the owner]
M --> X[Task index: dependencies, review tiers, verify commands]
X --> O[Orchestrator: selects ready cards, dispatches]
O --> I1[Implementer, one card, allowed files only]
I1 --> R1[Reviewer, fresh session, reruns the gates]
R1 --> N[Integrator: the only Git writer on the integration branch]
N --> V[Focused check, then repository regression]
V --> L[Ledger, receipts, dispatch log]
L --> O
- Cards. A card states one observable outcome, its dependencies, the files it is allowed to edit, its review tier, acceptance criteria, a registered verification command and stop conditions.
Update-TaskIndexchecks card hashes, dependency edges and cycles, and that the Markdown view matches the structured index. - Roles with different authority. The orchestrator selects and dispatches and does not implement or review. The implementer changes only the cardâs allowed files. The reviewer is a separate session that reruns the gates and can block work whose tests pass. The integrator is the only role that writes to the integration branch. I approve the card map, product decisions, destructive or paid actions, and any change to the work graph.
- Two levels of checking. Each card has a focused check, and every acceptance also runs the repository regression gate. A focused test shows the card does what it says; the regression shows accepted cards still work together.
- Typed blockers. A card can end
blocked: implementation,environment,ownerorintegration. The point is that a sandbox failure does not get âfixedâ by weakening a test, and a product defect does not get excused as an environment problem. - Two execution modes. The default is one worktree and branch per card, with accepted commits applied to the integration branch one at a time in card order. A failed gate after integration is reverted with new commits, never by rewriting history.
shared-main serialis the fallback for projects that cannot be isolated. - Limits enforced in scripts. From 0.3.0 the per-epoch card cap is enforced by the dispatch-log script, which refuses the spawn, and not by asking the orchestrator nicely.
The README is direct about one thing Iâd repeat here: agent instructions are guardrails, not a security boundary. Anything that must hold should be enforced by a sandbox, a hook, branch protection or CI.
What Is Proven and What Is Not
The kitâs README at v0.4.0 says the serial mode âhas been exercised in two real projectsâ and the parallel-worktree default âhas no live trial proof yetâ. Both statements still stand in the kit repo.
- Serial mode, two projects. Snapshots dated 2026-09-21 and not refreshed since: an existing multi-component project with 67 cards, 41 ledger entries and 35 accepted; a greenfield application decomposed from a 607-line plan into 19 cards, with 10 instances in the ledger and 8 accepted. In one review a parser stayed blocked despite 13 passing registered tests, because the reviewerâs own malformed-input probe still reproduced partial output. That is the behavior I built the kit for.
- Parallel mode. The harness covers concurrent verification, serialized integration and additive rollback on synthetic repositories. A toy trial on 2026-09-26 and 27 needed six tries to integrate one sample card, each failure fixed in the changelog. spendtrace then ran with per-card worktrees in October and is where most of the defects below came from. None of that is the clean live trial the release checklist asks for.
- Release gates.
docs/PUBLIC_RELEASE_CHECKLIST.mdkeeps the repo private until both case studies finish their first card sets and a sanitized evidence bundle is committed. None of its six hard gates is ticked.
What spendtrace Found
spendtrace is meant to answer one question: what did this feature cost to build, including the branches that never merged? It is a six-stage batch pipeline (collect, normalize, price, attribute, reconcile, report) where every dollar carries an attribution tier from exact to unattributed.
The run also produced a file in the spendtrace repo, docs/owner-actions/kit-issues-from-spendtrace.md, started on 2026-10-10. It has 41 numbered items: defects checked against the kitâs source at 3951c07 and marked confirmed or unconfirmed with the log line that shows each one, plus fixes, deferred findings and a few notes on the patching process itself. Four of them:
1. An Epoch That Did Nothing Reported a Pass
The documented step said to run Set-OrchestratorLock -Acquire. The script requires a -Session argument the document never mentions, so every unattended epoch failed at step 2 before dispatching anything. The epoch runner then compared state before and after, needed two unchanged epochs in a row to call it no progress, and exited with RESULT: pass. The log itself said âNo agents dispatched, cards finished, or commits createdâ. What I took from it: a stage that exits cleanly has to show it did work, and a documented command has to be runnable exactly as written.
2. A Stop Rule Followed Exactly as Written
The orchestration protocol listed âblocked on ownerâ as a stop condition with no scope. So one question about one card ended the whole epoch, five times, the last time with 31 cards ready to run. The orchestrator was not misbehaving; it obeyed the rule. The fix scopes an owner question to the cards it names and ends an epoch only when no unblocked card is left, with a 66-case test file whose core fixture is one open question, 30 other ready cards, and an expected state of ready.
3. The Same Question, Three Times
Every retry of a card opened a new worktree record and left the old one open, and the integrator refused to proceed with more than one open. The orchestrator escalated to me each time. Three owner questions asked the identical mechanical thing (mark the old attempts abandoned, keep the files) and got the identical answer; the first cost about 50 minutes of idle wall clock. A question with only one possible answer is not an owner decision, and the fix lets the integrator close superseded attempts itself when their commits are preserved.
4. The Example the Integrator Rejects
The review protocolâs example approval receipt shows "files_changed":0. The integrator compares that field against the real diff and refuses on a mismatch. Reviewers who copied the example were refused, reviewers who wrote the real count passed, and the working behavior was documented nowhere. An example in a protocol document is an instruction to an agent, so it needs a test like any other code.
A fifth one is about review catching what tests did not. Two storage cards promised append-only tables, and both implementersâ tests passed through the projectâs own connection helper, which turns on recursive triggers. On a plain sqlite3.connect, an INSERT OR REPLACE that reuses a rowid deleted the protected row without firing the guard. The reviewer found it on the first card, and the second card repeated the mistake 22 minutes later, because the lesson existed only in a review file.
Where It Stands
- spendtrace. 233 commits from 2026-10-10 to 2026-10-18 across its branches. The last commit on main (
4fed8e9, 2026-10-13) records epochs 44 to 79 and marks six more cards blocked. The ledger at that commit shows 29 cards done, 23 blocked and 4 pending. Most blocked rows say an amendment to the plan is required, which means the spec left an interface undefined, and the collect and normalize stage cards are among them. So the pipeline has not run end to end, and the first planned result, a per-feature cost backfill of TALON, does not exist yet. It has 450 test functions of its own (grep fordef test_undertests/spendtraceat4fed8e9, 2026-11-22). - The fixes. Seven fixes from the list (scoped stops, a critical-path ready queue, a supervisor that relaunches epochs, worktree cleanup, typed spawns, a disk guard, lighter polling) were written for both PowerShell and Python and live in spendtrace. They have not been carried back to the kit repo, whose last commit is v0.4.0 on 2026-09-27. The receipt example and the lock command are still wrong there.
- Ceremony. The spendtrace spec estimates, from 120-commit samples, that 57% to 63% of commits in two kit-run repos were the kitâs own bookkeeping. A protocol built partly for efficiency has to account for that, and measuring it is one of spendtraceâs stated principles.
- Done is not reachable. One deferred item notes that four of six finished cards at the time were library code not wired to any entry point. Milestone-level reachability checking is designed and not built.
I havenât abandoned the kit. Each of my agent projects led to the next one, and what this one taught (a rule that exists only as prose gets bypassed, the implementer does not accept its own work, repository state outranks chat state) went into what I built afterwards. The same instinct is in my Playwright guides template, where a passing test is necessary but a separate check decides what gets published.
A Smaller Loop Afterwards
In November 2026 I started over at a much smaller size, in a separate private repository called Goal Loop. Its design notes say what it keeps from the kit (task boundaries, deterministic checks, recoverable state) and what it drops for a first version (mandatory card maps and the role hierarchy). What follows describes its main branch at 3a53a82 (2026-11-20).
- The loop. A planner proposes intents, a worker carries out one intent and reports a fact, and the planner reads the reports and decides what to try next or stops. It is about 1,500 lines of standard-library Python in four files.
- State in SQLite. Intents and an append-only event log live in one database file. Claiming an intent is a transaction, so two processes cannot take the same one, and a task whose worker crashed is held for an explicit
retry, never replayed automatically. - Two backends, one interface. The default worker is a native agent: an OpenAI-compatible chat endpoint and three tools (read a file, write a file, run one process without a shell). The alternative hands the same prompt to an existing coding CLI.
- A claim is not a result. A workerâs
ok: trueis recorded as a report. If no verification command is configured, a plannerâs âgoal metâ is stored asunverifieduntil I approve it with what I checked. - Optional modules. One reserves an estimated cost before each model call, inside a transaction, so parallel workers cannot overspend a cap. The other gives each intent its own Git worktree and never deletes one.
The benchmark runs each task four ways: native or CLI worker, with or without the loop. The first live run, on 2026-11-20, used one task (create a file with exact bytes), two local Qwen models and two coding CLIs. 8 of 16 independent checks passed. Four of the failures were mine: a CLI configured with a read-only workspace. Four corrected reruns passed, which the repo reports as a 12 of 16 composite and not a clean rerun. The smaller local model reported success three times without calling a tool, and in one of those the planner accepted the report as evidence. The loop was usually slower on a task this small, since its shortest path is three model sessions against one.
The repoâs own summary is that this shows the loop can detect failed work and does not show that it can recover from it, and that one trivial task is not a measure of anything else. It has 19 test functions under tests/ (grep count, 2026-11-21) that run with no model. Work on recovery sits on an unmerged branch (last commit 2026-11-21, read 2026-11-22) and is not described here.
Tech Stack
- Scripts: 19 commands, each as Windows PowerShell 5.1 and as stdlib-only Python with the same arguments and the same
RESULT:lines. Two implementations, deliberately: I work on Windows, and the CI job runs the Python scripts on Linux. - State: Markdown, JSON and YAML under Git. No dashboard, no hosted control plane, no daemon.
- Testing: pytest 9.1.1 and pytest-xdist 3.8.0 over synthetic repositories, no network or product code needed.
- CI: GitHub Actions harness workflow with read-only permissions and actions pinned to commit hashes.
- Agents: Role definitions rendered for Codex and Claude Code project agents (implementer, reviewer, a stronger tier of each, and integrator).
- spendtrace: Python 3.12+, zero runtime dependencies, SQLite, raw layer append-only.