Common patterns for skill harnesses
Source: an audit of 2026-10 session records (about 770 sessions, including the first and second pro-launch audits). Issue #950.
Purpose
To build better skill harnesses, this page collects the general lessons, independent of any one skill, that the session audit confirmed again and again. Use it as the reference document for open-source sharing and for applying these ideas to other harnesses. Individual bugs are handled in their linked issues; this page covers only the patterns.
What works (keep it and generalize it)
- A uniform JSON envelope (
ok,code,summary,next): of about 3,360 calls, about 90 returnedok:false, and every one of them was machine-readable. The agent branches oncode, not on the wording, and followsnext. bad_argsas JSON: the agent corrects itself in one turn.available_subcommandsgets used.- Domain-aware warnings:
label_warning,assignee_warning, Korean/English status label equivalence (#776). - Passing secrets through environment variables (
SECRET_VALUE),sanitize-message, staging with explicit paths, redirect-safe log downloads. - pro-launch's fixed entry point +
newer_installed,known_fixandkb,learn_hint, the device claim display. - Dry-run
before/plannedfor actions that change a remote repository + approval per repo.
General lessons
- Agents guess arguments, regular expressions and key names. Accept the most commonly guessed forms, or fail with a hint. When the same guess repeats across independent sessions, it is a product signal (
--issue Nin about 12 sessions). - Put usage inside the structured error.
usage, one example, the closest subcommand. Agents read only the stdout JSON. - A fixed entry point beats path searching. 18% of calls were
find | sort -V | tail -1. - Provide a field selector and an output schema.
--field a.bremoves inline Python and the KeyError family. - Keep a verified raw API escape hatch. When a feature is missing, the agent reads the token from a config file and uses curl. An
apipass-through command that injects auth centrally is safer. Grepping sessions forapi.github.comgives you a map of missing features. - Put polling inside the tool. One
--wait --timeoutbeatssleep(blocked by the harness), scheduled wake-ups and watch loops. Return a final verdict andnext. - Waiting states need an age and a way out. A
waitingwith no time limit turns a dead pipeline into an endless wait (4.5 hours). Includeage_secondsand reportstuckat a threshold. - Turn any ritual the agent types by hand more than 3 times into a subcommand. Base sync, worktree create + copy + record, comment + label + close.
- Separate transient errors from permanent ones. Retry only 5xx and mark
retryable. For non-idempotent calls, detect duplicates with a marker. - Check cheap preconditions inside the tool first. Checking that the branch exists on origin names the cause, instead of GitHub's vague 422.
- Do not take secrets through argv. When the permission classifier blocks it, the agent gives up instead of changing its approach. Provide a store, environment variables and a human prompt. Docs that tell the agent to read a secret also leak into session records.
- Silent correction is a bug. Image resizing, accepting empty input,
Path('.').parents. Surface it as a structured warning. - Tell transport success apart from remote command failure. Map known exit codes such as ssh 255 and sshpass 5 to named codes, take remote output as bytes and decode it in the order utf-8 > legacy code page > replace.
- QA steps that change the environment keep a ledger. Record the before/after values and verify the restore. Before filing a defect, rule out leftover state and tool errors through a different input path.
- Document a platform symmetry table. A table that covers only one side makes the agent build the other side by hand (22 Maestro YAML files). If it cannot be built, do not skip it silently; report
blockedwith a reason. - Give large payloads a file-based happy path. For tools with large MCP results, without an
ingestthat takes the result file the harness saved, the agent spends the tokens again or skips the tool. - Subagent contract: the worker writes and verifies its own output file, and the parent only checks that it exists. Put the resolved script path into the prompt template.
- Separate approval gates. "Write a report" can be automatic; "change a remote repository" is always manual and shows the values before and after the change.
- Provide deterministic choices as scripts. If "the 3 weakest" is left as prose, the answer differs on every run.
- Find dead features with usage metering. Record only the subcommand and code (no arguments) locally, and on each release look at "never called", "most common error code", the number of
--helpcalls, raw API hosts and the amount of exploration boilerplate. These four numbers alone produced most of this audit. - Tie docs and code together with tests that run the docs as written on both OSes. A recipe verified only on Windows breaks silently on macOS. Block forbidden idioms, such as git porcelain that truncates text, with a lint.
- Model/effort fit as data. A frontmatter field instead of a prose banner (
⚠️ model recommendation). Parallel workers record the model they used in their output and warn on degenerate output (for example, 0 citations). - Put a fix id in the failure response. Show the fix verified in sessions on the first failure, not after 3 failures.
- Fact memory also keeps failures and explorations of unsupported platforms. Otherwise every session learns
chcpandschtasksall over again.
What this repo implements
| Pattern | Implementation |
|---|---|
| Fixed entry point + old version warning | scripts/projectops_cli.py, scripts/common/stable_entry.py (#942) |
4 leading response keys, --brief/--field, usage in bad_args | scripts/common/emit.py, cli_parser.py (#940) |
Polling inside the tool, stuck verdict | actions wait, deploy-status --wait (#939, #945) |
| Transient error retry, idempotent reconciliation | scripts/common/github_rest/transport.py, issues.py (#941) |
| Environment change ledger | device appearance/locale/text-size --restore (#929, #947) |
| Precondition pre-check | create-pr head check (#938) |