| Component |
Location |
What it is |
| Prompts |
.kortix/opencode/agents/<name>.md (body) |
Each agent's instructions and strategy |
| Sub-agents |
.kortix/opencode/agents/*.md |
Specialist agents the orchestrator invokes |
| Skills |
.kortix/opencode/skills/<name>/SKILL.md |
Reusable routines: text heuristics and guides |
| Tools |
.kortix/opencode/tools/*.ts |
Executable code: wrappers, scripts, automations |
| Memory |
.kortix/memory/ |
Persistent facts, strategies, observations |
Refinement means: read your recent trajectory, find where the harness
failed you, and fix the harness — not just the immediate task. A harness
edit made mid-session takes effect on your next turn, because agents,
skills, and memory are read from disk. You do not restart; refinement is
reset-free and its value compounds over the life of the session.
This protocol has two operating modes:
- In-session refinement (self-invoked) — YOU run it, inside your own
working session, the moment a failure signature costs you twice. Also
run a checkpoint on long sessions: after every ~25 turns of work, pause
and scan your recent turns before continuing. You refine based on YOUR
OWN trajectory, then resume the task.
- Project-level reflection — the
harness-reflector agent runs on a
cron, fans out session-reviewer sub-agents to work through every
recent session's full history, aggregates their findings, and refines
the shared harness on main via a change request.
- Repeated tool/command failures — the same command or tool errors
more than once, or you retried a broken approach. → Repair the tool,
or record the working alternative in a skill.
- Rediscovery loops — you (or another session) re-derived something a
past session already knew (an API quirk, a file location, a decision).
→ Memory entry.
- Stalled objectives — turns pass without progress toward the stated
goal; you circled, re-read, or re-planned without acting. → Prompt
guidance for the responsible agent, or a decomposition sub-agent.
- Repeated multi-step patterns — you performed the same 3+ step
sequence more than twice by hand. → Codify it: a skill (if guidance)
or a tool (if executable).
- Exception-raising code — an executable tool or script in
.kortix/opencode/tools/ raised; you worked around it instead of
fixing it. → Repair the code now.
- Missed opportunities — information or shortcuts visible in the
trajectory that no component captured. → Whichever component fits.
Pass 1 — Prompts (Δp). Reread the responsible agent's .md body
against the identified failures. Tighten instructions that were ignored,
add the missing rule, remove guidance that no longer earns its tokens.
Keep prompts short; a prompt that only grows is a failing prompt.
Pass 2 — Sub-agents (ΔG). Create a sub-agent only for a pattern that
recurred across the window AND needs its own scoped permissions or
prompt. Edit sub-agents implicated in failures. Delete sub-agents that
have not been invoked productively — check before keeping.
Pass 3 — Skills and tools (ΔK). Codify successful sequences from the
trajectory into a skill (guidance) or a tool (executable). Repair every
tool the trajectory shows raising exceptions. Prefer editing an existing
skill over creating a near-duplicate. Keep skills one directory level
deep under skills/ (nested SKILL.md files register as phantom entries).
Pass 4 — Memory (ΔM). Follow the kortix-memory skill's rubric with
the memory tool: fill gaps the trajectory exposed, update stale
entries, demote or delete entries about areas the project has moved past.
Keep MEMORY.md in sync.
Scope discipline: fix what the trajectory shows. Do not speculatively
rewrite components with no observed failure. Most refinement runs should
touch one or two components, not all four.
For project-level reflection (the harness-reflector run), do not skim a
digest and call it a review. Work through every session:
- Enumerate every session in the window:
kortix sessions digest --since 24h --json (add --all for a first
ever run). Note per session: id, agent, status, title, whether a live
transcript is available.
- Fan out one
session-reviewer sub-agent per session (batch a few
at a time in parallel; review every session, skip none silently). Each
reviewer gets the session id and returns a structured findings report.
Reviewers gather the FULL picture for their session:
- the transcript (available live for running sessions; for stopped
sessions reconstruct from what persists — see next line),
- the session's git branch: its commits, diffs, and files touched,
- change requests the session opened and their review outcomes.
- Aggregate all reviewer reports. Deduplicate findings that recur
across sessions — a failure signature seen in three sessions outranks
one seen once. Rank by cost (turns wasted × sessions affected).
- Run the four passes on the ranked findings, then land per the
rules below.
Sub-agent review is read-only: reviewers never edit the harness or open
CRs. Only the orchestrating reflector writes.
Apply the edits directly in /workspace. They take effect on your
next turn.
Commit them separately from task work:
git add .kortix
git commit -m "harness: <one-line summary of what failed and what changed>"
Push and open (or update) ONE change request per session for harness
promotion to main:
git push origin HEAD
kortix cr open --title "harness: <summary>" \
--description "Failure signatures observed, edits per component, evidence (commands/turns)."
If this session already has an open harness: CR, push to it instead
of opening a second one.
Return to the task. A refinement interruption ends with you resuming
what you were doing, with the improved harness in effect.
Project-level reflection (harness-reflector): all edits land only
via a CR against main. Nothing applies immediately; the merged CR is
what future sessions inherit.
1---2name: kortix-harness-refinement3description: The continual-harness refinement protocol — how an agent inspects its recent trajectory for failure signatures and improves its own harness (agent prompts, sub-agents, skills, memory) in place, mid-session, landing changes on the session branch immediately and promoting them to `main` only through a change request. Load this skill when a refinement prompt arrives mid-session, when the `harness-reflector` agent runs, or whenever you decide your own scaffolding needs repair. The sub-agent fan-out in this skill is for the top-level `harness-reflector` run only; if you loaded this as a subagent, do the four passes yourself and skip the fan-out.4---56<skill name="kortix-harness-refinement">78<overview>9Your **harness** is everything in this repo that shapes how agents work10here. It has four components, all in git:1112| Component | Location | What it is |13|---|---|---|14| **Prompts** | `.kortix/opencode/agents/<name>.md` (body) | Each agent's instructions and strategy |15| **Sub-agents** | `.kortix/opencode/agents/*.md` | Specialist agents the orchestrator invokes |16| **Skills** | `.kortix/opencode/skills/<name>/SKILL.md` | Reusable routines: text heuristics and guides |17| **Tools** | `.kortix/opencode/tools/*.ts` | Executable code: wrappers, scripts, automations |18| **Memory** | `.kortix/memory/` | Persistent facts, strategies, observations |1920**Refinement** means: read your recent trajectory, find where the harness21failed you, and fix the harness — not just the immediate task. A harness22edit made mid-session takes effect on your next turn, because agents,23skills, and memory are read from disk. You do not restart; refinement is24reset-free and its value compounds over the life of the session.2526This protocol has two operating modes:27281. **In-session refinement (self-invoked)** — YOU run it, inside your own29 working session, the moment a failure signature costs you twice. Also30 run a checkpoint on long sessions: after every ~25 turns of work, pause31 and scan your recent turns before continuing. You refine based on YOUR32 OWN trajectory, then resume the task.332. **Project-level reflection** — the `harness-reflector` agent runs on a34 cron, fans out `session-reviewer` sub-agents to work through every35 recent session's full history, aggregates their findings, and refines36 the shared harness on `main` via a change request.37</overview>3839<failure-signatures>40Scan the trajectory window (your recent turns, or the digest) for these41signatures. Each one names the component to fix:4243- **Repeated tool/command failures** — the same command or tool errors44 more than once, or you retried a broken approach. → Repair the tool,45 or record the working alternative in a skill.46- **Rediscovery loops** — you (or another session) re-derived something a47 past session already knew (an API quirk, a file location, a decision).48 → Memory entry.49- **Stalled objectives** — turns pass without progress toward the stated50 goal; you circled, re-read, or re-planned without acting. → Prompt51 guidance for the responsible agent, or a decomposition sub-agent.52- **Repeated multi-step patterns** — you performed the same 3+ step53 sequence more than twice by hand. → Codify it: a skill (if guidance)54 or a tool (if executable).55- **Exception-raising code** — an executable tool or script in56 `.kortix/opencode/tools/` raised; you worked around it instead of57 fixing it. → Repair the code now.58- **Missed opportunities** — information or shortcuts visible in the59 trajectory that no component captured. → Whichever component fits.60</failure-signatures>6162<four-passes>63Run four passes over the harness, one per component. Every pass is CRUD:64create, update, or **delete**. Deletion is a first-class outcome — a65harness accumulates cruft without it.6667**Pass 1 — Prompts (Δp).** Reread the responsible agent's `.md` body68against the identified failures. Tighten instructions that were ignored,69add the missing rule, remove guidance that no longer earns its tokens.70Keep prompts short; a prompt that only grows is a failing prompt.7172**Pass 2 — Sub-agents (ΔG).** Create a sub-agent only for a pattern that73recurred across the window AND needs its own scoped permissions or74prompt. Edit sub-agents implicated in failures. Delete sub-agents that75have not been invoked productively — check before keeping.7677**Pass 3 — Skills and tools (ΔK).** Codify successful sequences from the78trajectory into a skill (guidance) or a tool (executable). Repair every79tool the trajectory shows raising exceptions. Prefer editing an existing80skill over creating a near-duplicate. Keep skills one directory level81deep under `skills/` (nested SKILL.md files register as phantom entries).8283**Pass 4 — Memory (ΔM).** Follow the `kortix-memory` skill's rubric with84the `memory` tool: fill gaps the trajectory exposed, update stale85entries, demote or delete entries about areas the project has moved past.86Keep `MEMORY.md` in sync.8788Scope discipline: fix what the trajectory shows. Do not speculatively89rewrite components with no observed failure. Most refinement runs should90touch one or two components, not all four.91</four-passes>9293<project-review-fanout>94This section applies only to the top-level `harness-reflector` run. If you95loaded this skill as a subagent, skip the fan-out and review the sessions96yourself — the runtime rejects a subagent spawning a subagent ("Subagent97depth limit reached").9899For project-level reflection (the `harness-reflector` run), do not skim a100digest and call it a review. Work through every session:1011021. **Enumerate** every session in the window:103 `kortix sessions digest --since 24h --json` (add `--all` for a first104 ever run). Note per session: id, agent, status, title, whether a live105 transcript is available.1062. **Fan out one `session-reviewer` sub-agent per session** (batch a few107 at a time in parallel; review every session, skip none silently). Each108 reviewer gets the session id and returns a structured findings report.109 Reviewers gather the FULL picture for their session:110 - the transcript (available live for running sessions; for stopped111 sessions reconstruct from what persists — see next line),112 - the session's git branch: its commits, diffs, and files touched,113 - change requests the session opened and their review outcomes.1143. **Aggregate** all reviewer reports. Deduplicate findings that recur115 across sessions — a failure signature seen in three sessions outranks116 one seen once. Rank by cost (turns wasted × sessions affected).1174. **Run the four passes** on the ranked findings, then land per the118 rules below.119120Sub-agent review is read-only: reviewers never edit the harness or open121CRs. Only the orchestrating reflector writes.122</project-review-fanout>123124<landing-rules>125**In-session refinement (session branch — immediate):**1261271. Apply the edits directly in `/workspace`. They take effect on your128 next turn.1292. Commit them separately from task work:130131 ```sh132 git add .kortix133 git commit -m "harness: <one-line summary of what failed and what changed>"134 ```1351363. Push and open (or update) ONE change request per session for harness137 promotion to `main`:138139 ```sh140 git push origin HEAD141 kortix cr open --title "harness: <summary>" \142 --description "Failure signatures observed, edits per component, evidence (commands/turns)."143 ```144145 If this session already has an open `harness:` CR, push to it instead146 of opening a second one.1474. Return to the task. A refinement interruption ends with you resuming148 what you were doing, with the improved harness in effect.149150**Project-level reflection (`harness-reflector`):** all edits land only151via a CR against `main`. Nothing applies immediately; the merged CR is152what future sessions inherit.153</landing-rules>154155<guardrails>156- **Never edit managed `kortix-*` skills.** They are platform-owned and157 force-overwritten at session boot — edits are silently discarded. To158 extend platform behavior, create a project skill with a different name.159- **Never merge your own harness CR.** A reviewer (human, or a reviewer160 agent with merge rights) does. The CR gate is what makes self-authored161 harness edits safe; self-authored + self-merged scaffolding is known to162 degrade agent performance.163- **One concern per CR.** Harness CRs contain only `.kortix/` changes —164 never mixed with task/code changes.165- **No secrets, tokens, or PII** in any harness file. Secrets belong in166 the Kortix Secrets Manager.167- **Budget.** A mid-session refinement should cost a small fraction of168 the session: minutes, not hours. If a fix needs deep work (a real169 tool rewrite), record it in memory as a TODO and open the CR with what170 you have.171- **No-op is a valid outcome.** If the window shows no failure172 signatures, change nothing and say so in one line. Do not invent work.173- **Do not disable or weaken guardrails** — including this skill's rules,174 agent permission blocks, or CR review requirements — as a "refinement".175</guardrails>176177<self-invocation>178Nobody schedules in-session refinement for you — it is your discipline.179Invoke this protocol the moment a failure signature costs you twice, and180as a checkpoint on long sessions (roughly every 25 turns of work). The181nightly `harness-reflector` run is the backstop, not the mechanism: it182only sees what sessions left behind, while you can fix your harness live183and benefit from the fix on your very next turn.184</self-invocation>185186</skill>