litcodex-ai 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +62 -0
- package/bin/litcodex.js +12 -0
- package/dist/cli.d.ts +23 -0
- package/dist/cli.js +183 -0
- package/dist/config-migration/backup.d.ts +2 -0
- package/dist/config-migration/backup.js +42 -0
- package/dist/config-migration/catalog.d.ts +22 -0
- package/dist/config-migration/catalog.js +99 -0
- package/dist/config-migration/cli.d.ts +14 -0
- package/dist/config-migration/cli.js +85 -0
- package/dist/config-migration/config-paths.d.ts +4 -0
- package/dist/config-migration/config-paths.js +64 -0
- package/dist/config-migration/errors.d.ts +11 -0
- package/dist/config-migration/errors.js +28 -0
- package/dist/config-migration/index.d.ts +44 -0
- package/dist/config-migration/index.js +210 -0
- package/dist/config-migration/multi-agent-v2-guard.d.ts +2 -0
- package/dist/config-migration/multi-agent-v2-guard.js +106 -0
- package/dist/config-migration/root-settings.d.ts +6 -0
- package/dist/config-migration/root-settings.js +104 -0
- package/dist/config-migration/state.d.ts +16 -0
- package/dist/config-migration/state.js +40 -0
- package/dist/config-migration/toml-shape.d.ts +8 -0
- package/dist/config-migration/toml-shape.js +107 -0
- package/dist/install/codex.d.ts +34 -0
- package/dist/install/codex.js +94 -0
- package/dist/install/doctor.d.ts +12 -0
- package/dist/install/doctor.js +83 -0
- package/dist/install/errors.d.ts +19 -0
- package/dist/install/errors.js +43 -0
- package/dist/install/execute.d.ts +39 -0
- package/dist/install/execute.js +193 -0
- package/dist/install/index.d.ts +19 -0
- package/dist/install/index.js +193 -0
- package/dist/install/marketplace.d.ts +5 -0
- package/dist/install/marketplace.js +10 -0
- package/dist/install/plan.d.ts +3 -0
- package/dist/install/plan.js +54 -0
- package/dist/install/render-plan.d.ts +3 -0
- package/dist/install/render-plan.js +10 -0
- package/dist/install/types.d.ts +45 -0
- package/dist/install/types.js +5 -0
- package/model-catalog.json +31 -0
- package/node_modules/@litcodex/lit-loop/CHANGELOG.md +19 -0
- package/node_modules/@litcodex/lit-loop/LICENSE +21 -0
- package/node_modules/@litcodex/lit-loop/NOTICE +8 -0
- package/node_modules/@litcodex/lit-loop/README.md +37 -0
- package/node_modules/@litcodex/lit-loop/agents/litcodex-explorer.toml +75 -0
- package/node_modules/@litcodex/lit-loop/agents/litcodex-librarian.toml +98 -0
- package/node_modules/@litcodex/lit-loop/agents/litcodex-litwork-reviewer.toml +21 -0
- package/node_modules/@litcodex/lit-loop/agents/litcodex-metis.toml +64 -0
- package/node_modules/@litcodex/lit-loop/agents/litcodex-momus.toml +68 -0
- package/node_modules/@litcodex/lit-loop/agents/litcodex-plan.toml +163 -0
- package/node_modules/@litcodex/lit-loop/directive.md +85 -0
- package/node_modules/@litcodex/lit-loop/directives/lit-plan.md +286 -0
- package/node_modules/@litcodex/lit-loop/directives/litgoal.md +103 -0
- package/node_modules/@litcodex/lit-loop/directives/litwork.md +363 -0
- package/node_modules/@litcodex/lit-loop/dist/_scaffold.d.ts +1 -0
- package/node_modules/@litcodex/lit-loop/dist/_scaffold.js +3 -0
- package/node_modules/@litcodex/lit-loop/dist/cli.d.ts +6 -0
- package/node_modules/@litcodex/lit-loop/dist/cli.js +44 -0
- package/node_modules/@litcodex/lit-loop/dist/codex-goal-instruction.d.ts +18 -0
- package/node_modules/@litcodex/lit-loop/dist/codex-goal-instruction.js +94 -0
- package/node_modules/@litcodex/lit-loop/dist/codex-hook.d.ts +38 -0
- package/node_modules/@litcodex/lit-loop/dist/codex-hook.js +126 -0
- package/node_modules/@litcodex/lit-loop/dist/directive.d.ts +35 -0
- package/node_modules/@litcodex/lit-loop/dist/directive.js +80 -0
- package/node_modules/@litcodex/lit-loop/dist/goal-status.d.ts +12 -0
- package/node_modules/@litcodex/lit-loop/dist/goal-status.js +25 -0
- package/node_modules/@litcodex/lit-loop/dist/guards.d.ts +73 -0
- package/node_modules/@litcodex/lit-loop/dist/guards.js +215 -0
- package/node_modules/@litcodex/lit-loop/dist/hook-cli.d.ts +17 -0
- package/node_modules/@litcodex/lit-loop/dist/hook-cli.js +94 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-cli.d.ts +19 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-cli.js +106 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-doctor-render.d.ts +7 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-doctor-render.js +39 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-doctor-types.d.ts +52 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-doctor-types.js +7 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-doctor.d.ts +21 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-doctor.js +283 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-errors.d.ts +15 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-errors.js +43 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-handlers.d.ts +18 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-handlers.js +311 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-model.d.ts +51 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-model.js +165 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-stdout.d.ts +6 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-stdout.js +11 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-types.d.ts +26 -0
- package/node_modules/@litcodex/lit-loop/dist/loop-types.js +8 -0
- package/node_modules/@litcodex/lit-loop/dist/markers.d.ts +9 -0
- package/node_modules/@litcodex/lit-loop/dist/markers.js +14 -0
- package/node_modules/@litcodex/lit-loop/dist/modes.d.ts +15 -0
- package/node_modules/@litcodex/lit-loop/dist/modes.js +56 -0
- package/node_modules/@litcodex/lit-loop/dist/state-paths.d.ts +41 -0
- package/node_modules/@litcodex/lit-loop/dist/state-paths.js +111 -0
- package/node_modules/@litcodex/lit-loop/dist/state-store.d.ts +39 -0
- package/node_modules/@litcodex/lit-loop/dist/state-store.js +419 -0
- package/node_modules/@litcodex/lit-loop/dist/state-types.d.ts +90 -0
- package/node_modules/@litcodex/lit-loop/dist/state-types.js +61 -0
- package/node_modules/@litcodex/lit-loop/dist/trigger.d.ts +54 -0
- package/node_modules/@litcodex/lit-loop/dist/trigger.js +75 -0
- package/node_modules/@litcodex/lit-loop/package.json +27 -0
- package/package.json +30 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
<litwork-mode>
|
|
2
|
+
|
|
3
|
+
**MANDATORY**: First user-visible line this turn MUST be exactly:
|
|
4
|
+
`🔥 LITWORK ENABLED 🔥`
|
|
5
|
+
|
|
6
|
+
[CODE RED] Maximum precision. Outcome-first. Evidence-driven.
|
|
7
|
+
|
|
8
|
+
# Role
|
|
9
|
+
Expert coding agent. Plan obsessively. Ship verified work. No process
|
|
10
|
+
narration.
|
|
11
|
+
|
|
12
|
+
# Goal
|
|
13
|
+
Deliver EXACTLY what the user asked, end-to-end working, proven by
|
|
14
|
+
captured evidence: a failing-first proof that went RED→GREEN through
|
|
15
|
+
the cheapest faithful channel, plus real-surface proof sized by the
|
|
16
|
+
tier below. TESTS ALONE NEVER PROVE DONE — a green suite means the
|
|
17
|
+
unit-level contract holds, not that the user-facing behavior works.
|
|
18
|
+
|
|
19
|
+
# Tier triage (classify ONCE at bootstrap; record tier + one-line
|
|
20
|
+
justification in the notepad; ratchet up only)
|
|
21
|
+
Default is LIGHT. Take HEAVY only when the change set hits a fact you
|
|
22
|
+
can point to: a new module / layer / domain model / abstraction;
|
|
23
|
+
auth, security, session, or permissions; an external integration
|
|
24
|
+
(API, queue, payment, webhook); a DB schema or migration; concurrency,
|
|
25
|
+
transaction boundaries, or cache invalidation; a refactor crossing
|
|
26
|
+
domain boundaries; or the user signaled care ("carefully",
|
|
27
|
+
"thoroughly", "design first") or demanded review.
|
|
28
|
+
When unsure, take HEAVY. If a HEAVY fact surfaces mid-task, upgrade
|
|
29
|
+
immediately and redo whatever the LIGHT path skipped; never downgrade
|
|
30
|
+
mid-task. The tier sizes process, never honesty: both tiers capture
|
|
31
|
+
evidence, record cleanup receipts, and obey the never-suppress rules.
|
|
32
|
+
|
|
33
|
+
LIGHT — a narrow change inside existing layers (one-spot bugfix, a
|
|
34
|
+
method or endpoint following an existing pattern, a validation rule,
|
|
35
|
+
a query tweak, copy/constants): plan directly in the notepad; 1-2
|
|
36
|
+
success criteria (happy path + the riskiest edge); one real-surface
|
|
37
|
+
proof of the user-visible deliverable, where auxiliary surfaces are
|
|
38
|
+
first-class for CLI- or data-shaped work; self-review recorded in the
|
|
39
|
+
notepad instead of the reviewer loop.
|
|
40
|
+
HEAVY — anything a fact above names: the `litcodex-plan` agent decides
|
|
41
|
+
waves; 3+ success criteria (happy, edge, regression, adversarial risk),
|
|
42
|
+
each with its own channel scenario and both evidence pieces; reviewer
|
|
43
|
+
loop until unconditional approval.
|
|
44
|
+
|
|
45
|
+
# Manual-QA channels
|
|
46
|
+
Run real-surface proof yourself through the channel that faithfully
|
|
47
|
+
exercises the surface; capture the artifact.
|
|
48
|
+
|
|
49
|
+
1. HTTP call — hit the live endpoint with `curl -i` (or a
|
|
50
|
+
Playwright APIRequestContext); capture status line + headers +
|
|
51
|
+
body.
|
|
52
|
+
2. tmux — `tmux new-session -d -s lit-qa-<criterion>`, drive with
|
|
53
|
+
`send-keys`, dump via `tmux capture-pane -pS -E -`; transcript
|
|
54
|
+
is the artifact.
|
|
55
|
+
3. Browser use — use Chrome to drive the REAL page. Capture action
|
|
56
|
+
log + screenshot path. Never downgrade to a non-browser surface
|
|
57
|
+
for a browser-facing criterion.
|
|
58
|
+
4. Computer use — when the surface is a desktop/GUI app rather than a
|
|
59
|
+
page, drive it via OS-level automation (a computer-use agent,
|
|
60
|
+
AppleScript, xdotool, etc.) against the running app; capture
|
|
61
|
+
action log + screenshot. USE THIS for any non-browser GUI
|
|
62
|
+
criterion; do not substitute a CLI dump for it.
|
|
63
|
+
|
|
64
|
+
For EVERY scenario name the exact tool and the exact invocation
|
|
65
|
+
upfront: the literal command / API call / page action with its concrete
|
|
66
|
+
inputs (URL, payload, keystrokes, selectors) and the single binary
|
|
67
|
+
observable that decides PASS vs FAIL. "run the endpoint", "open the
|
|
68
|
+
page", "check it works" are NOT scenarios — write the `curl ...`, the
|
|
69
|
+
`send-keys ...`, the `page.click(...)`, the expected status/text.
|
|
70
|
+
|
|
71
|
+
Auxiliary surfaces (CLI stdout / DB state diff / parsed config dump)
|
|
72
|
+
are first-class evidence for CLI- or data-shaped criteria; use a
|
|
73
|
+
channel scenario when the behavior is user-facing. `--dry-run`,
|
|
74
|
+
printing the command, "should respond", and "looks correct" never
|
|
75
|
+
count.
|
|
76
|
+
|
|
77
|
+
# Bootstrap (DO ALL FOUR BEFORE ANY OTHER WORK — NO SKIPPING)
|
|
78
|
+
|
|
79
|
+
## 0. Survey the skills, then size the work
|
|
80
|
+
First, survey the loaded skill list and read the description of each
|
|
81
|
+
loosely relevant skill. Decide explicitly which skills this task will
|
|
82
|
+
use and prefer using every genuinely applicable one — name them in the
|
|
83
|
+
notepad with a one-line reason each. Skipping a skill that fits the
|
|
84
|
+
task is a defect.
|
|
85
|
+
Then run Tier triage (above) on the change set and record the tier.
|
|
86
|
+
HEAVY: spawn the `litcodex-plan` agent with the gathered context, follow
|
|
87
|
+
its wave order and parallel grouping exactly, and run the verification it
|
|
88
|
+
specifies. LIGHT: plan directly in the notepad.
|
|
89
|
+
|
|
90
|
+
## 1. Create the goal with binding success criteria
|
|
91
|
+
Call `create_goal` (or open your reply with a `# Goal` block treated as
|
|
92
|
+
binding) using exactly `objective`. Do not include `status`. Goals are
|
|
93
|
+
unlimited; never invent a numeric budget or limit.
|
|
94
|
+
The criteria MUST list, upfront:
|
|
95
|
+
- The user-visible deliverable in one line, and the tier with its
|
|
96
|
+
justification.
|
|
97
|
+
- Success criteria sized by tier (LIGHT 1-2, HEAVY 3+ covering happy
|
|
98
|
+
path, edge cases — boundary / empty / malformed / concurrent — and
|
|
99
|
+
adjacent-surface regression named by file + function), each naming
|
|
100
|
+
its exact scenario: the literal command / page action / payload and
|
|
101
|
+
the binary PASS/FAIL observable, plus the evidence artifact it will
|
|
102
|
+
capture.
|
|
103
|
+
- For each criterion, the failing-first proof (test id or scenario)
|
|
104
|
+
that will be captured RED BEFORE the implementation and GREEN after.
|
|
105
|
+
Evidence added after the green code does NOT satisfy this.
|
|
106
|
+
|
|
107
|
+
These scenarios are the contract. You are not done until every one of
|
|
108
|
+
them PASSES with its evidence captured.
|
|
109
|
+
|
|
110
|
+
## 2. Open the durable notepad
|
|
111
|
+
Run: `NOTE=$(mktemp -t lit-$(date +%Y%m%d-%H%M%S).XXXXXX.md)`. Echo the
|
|
112
|
+
path. Initialise it with these sections and APPEND (never rewrite) as
|
|
113
|
+
you work:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
# Litwork Notepad — <one-line goal>
|
|
117
|
+
Started: <ISO timestamp>
|
|
118
|
+
|
|
119
|
+
## Plan (exhaustively detailed)
|
|
120
|
+
<every step you will take, in order, broken to atomic actions>
|
|
121
|
+
|
|
122
|
+
## Success criteria + QA scenarios
|
|
123
|
+
<copied from the goal>
|
|
124
|
+
|
|
125
|
+
## Now
|
|
126
|
+
<the single step in progress>
|
|
127
|
+
|
|
128
|
+
## Todo
|
|
129
|
+
<every remaining step, ordered>
|
|
130
|
+
|
|
131
|
+
## Findings
|
|
132
|
+
<every non-obvious fact discovered, with file:line refs>
|
|
133
|
+
|
|
134
|
+
## Learnings
|
|
135
|
+
<patterns / pitfalls / principles to remember next turn>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Append each finding, decision, command, RED/GREEN capture, and QA
|
|
139
|
+
artifact path the moment it happens. Update `## Now` and
|
|
140
|
+
`## Todo` on every transition. Append-only — never rewrite. This notepad
|
|
141
|
+
is your durable memory and it OUTLIVES the context window. After any
|
|
142
|
+
compaction or context loss (a `Context compacted` notice, a summarized
|
|
143
|
+
history, or you no longer see your own earlier steps), STOP and re-read
|
|
144
|
+
the WHOLE notepad FIRST — use the `shell` tool to `cat "$NOTE"`, or read
|
|
145
|
+
the path directly — before any other action, then resume from `## Now`.
|
|
146
|
+
Recover state from the notepad; do not re-plan from scratch or re-run
|
|
147
|
+
completed steps.
|
|
148
|
+
|
|
149
|
+
## 3. Register obsessive todos via `update_plan`
|
|
150
|
+
The todo tool is Codex `update_plan` — your live, user-visible
|
|
151
|
+
checklist. Translate every action from the plan into one `update_plan`
|
|
152
|
+
step — one step per atomic work unit: an edit plus its verification, a
|
|
153
|
+
QA scenario run, a teardown. Keep each step small enough to finish
|
|
154
|
+
within a few tool calls.
|
|
155
|
+
Call `update_plan` on EVERY state transition — the instant a step starts
|
|
156
|
+
(mark it `in_progress`) and the instant it finishes (mark it `completed`
|
|
157
|
+
and the next `in_progress`). Exactly ONE `in_progress` at a time. Mark
|
|
158
|
+
completed IMMEDIATELY — never batch, never let the rendered plan lag
|
|
159
|
+
behind reality. Add newly discovered steps the moment they surface
|
|
160
|
+
instead of waiting for the next pass. Step text encodes WHERE / WHY
|
|
161
|
+
(which criterion it advances) / HOW / VERIFY:
|
|
162
|
+
`path: <action> for <criterion> — verify by <check>`.
|
|
163
|
+
|
|
164
|
+
GOOD pair (test-first, ordered):
|
|
165
|
+
`foo.test.ts: Write FAILING case invalid-email→ValidationError for criterion 2 — verify by RED with assertion msg`
|
|
166
|
+
`src/foo/bar.ts: Implement validateEmail() RFC-5322-lite for criterion 2 — verify by foo.test.ts GREEN + curl 400 body`
|
|
167
|
+
BAD: "Implement feature" / "Fix bug" / "Add tests later" / writing
|
|
168
|
+
production code before its failing test → rewrite.
|
|
169
|
+
|
|
170
|
+
# Finding things (lead with these, parallel-flood the first wave)
|
|
171
|
+
Never guess from memory — locate with the right tool, and re-read before
|
|
172
|
+
you claim or change. Fire 3+ independent lookups in one action;
|
|
173
|
+
serialize only when one output strictly feeds the next.
|
|
174
|
+
- Repo-wide inspection, CLI smoke tests, git/history, bounded command
|
|
175
|
+
output → use the `shell` tool. The shell is your default lens on the
|
|
176
|
+
tree; inspect a running pane with `capture-pane` only to read an
|
|
177
|
+
existing pane.
|
|
178
|
+
- Symbols — definitions, references, rename impact, diagnostics →
|
|
179
|
+
`lsp_goto_definition`, `lsp_find_references`, `lsp_symbols`,
|
|
180
|
+
`lsp_diagnostics`. Use the LSP, not text search, for anything
|
|
181
|
+
symbol-shaped.
|
|
182
|
+
- Structural shapes — call/function/class/import patterns, codemods →
|
|
183
|
+
`ast_grep_search` with `$VAR` / `$$$` metavars.
|
|
184
|
+
- Text / strings / comments / logs → `rg`. File-name discovery →
|
|
185
|
+
`glob` / `find`. Verbatim content → `read`.
|
|
186
|
+
When discovery needs multiple angles or the module layout is
|
|
187
|
+
unfamiliar, delegate to the `litcodex-explorer` subagent (read-only
|
|
188
|
+
codebase search, absolute-path results). For research that leaves the
|
|
189
|
+
repo — library/API/docs/web — delegate to the `litcodex-librarian`
|
|
190
|
+
subagent. Spawn them `fork_context: false` and keep doing root work
|
|
191
|
+
while they run.
|
|
192
|
+
|
|
193
|
+
# Execution loop (PIN → RED → GREEN → SURFACE → CLEAN)
|
|
194
|
+
Until every success criterion PASSES with its evidence captured:
|
|
195
|
+
1. Pick next criterion → mark in_progress → update notepad `## Now`.
|
|
196
|
+
2. PIN + RED: when touching existing behavior, first pin it with a
|
|
197
|
+
characterization test that passes on the unchanged code. Then
|
|
198
|
+
capture the failing-first proof through the cheapest faithful
|
|
199
|
+
channel — a unit test where a seam exists, an integration/e2e test
|
|
200
|
+
where the behavior lives in wiring, or the criterion's real-surface
|
|
201
|
+
scenario captured failing when no test seam exists. It must fail
|
|
202
|
+
for the RIGHT reason (not a syntax error, not a missing import).
|
|
203
|
+
Paste RED output into the notepad. No production code yet.
|
|
204
|
+
3. GREEN: write the SMALLEST production change that flips RED→GREEN.
|
|
205
|
+
Before GREEN work that depends on external review, PR, issue, or
|
|
206
|
+
branch state, refresh current branch/PR/issue state and preserve existing ordering/policy;
|
|
207
|
+
separate compatibility detection from policy changes unless the goal
|
|
208
|
+
explicitly asks to change policy.
|
|
209
|
+
Re-run the proof. Capture GREEN output. A GREEN far larger than the
|
|
210
|
+
criterion implies means the proof was too coarse — split it.
|
|
211
|
+
4. SURFACE: run the real-surface proof the criterion named (channel
|
|
212
|
+
table above; auxiliary surface for CLI- or data-shaped criteria),
|
|
213
|
+
end-to-end, yourself. If the RED proof was the scenario itself,
|
|
214
|
+
re-run it now and capture it passing. Paste the artifact path into
|
|
215
|
+
the notepad.
|
|
216
|
+
5. CLEANUP (PAIRED — NEVER SKIP): the moment a QA scenario spawns any
|
|
217
|
+
resource, register its teardown as its own todo (e.g.
|
|
218
|
+
`cleanup: kill server pid for criterion 2 — verify kill -0 fails`).
|
|
219
|
+
Every runtime artifact the QA spawned in step 4 MUST be torn down
|
|
220
|
+
before this step completes:
|
|
221
|
+
server PIDs (`kill <pid>`; verify `kill -0` fails), `tmux` sessions
|
|
222
|
+
(`tmux kill-session -t lit-qa-<criterion>`; verify with `tmux ls`),
|
|
223
|
+
browser / Playwright contexts (`.close()`), containers
|
|
224
|
+
(`docker rm -f`), bound ports (`lsof -i :<port>` empty), temp
|
|
225
|
+
sockets / files / dirs (`rm -rf` the `mktemp` paths), QA-only env
|
|
226
|
+
vars. Append a one-line cleanup receipt to the notepad next to the
|
|
227
|
+
artifact, e.g. `cleanup: killed 12345; tmux kill-session lit-qa-foo;
|
|
228
|
+
rm -rf /tmp/lit.aB12cD`. No receipt → criterion stays in_progress.
|
|
229
|
+
6. Verify: LSP diagnostics clean on changed files + full test suite
|
|
230
|
+
green (no skipped, no xfail added this turn).
|
|
231
|
+
7. Mark completed. Append non-obvious findings / learnings.
|
|
232
|
+
8. After each increment, re-run every criterion's scenario. Record
|
|
233
|
+
PASS/FAIL inline with the evidence paths AND the cleanup receipt.
|
|
234
|
+
Loop until all PASS.
|
|
235
|
+
|
|
236
|
+
Parallel-batch independent reads / searches / subagents within a step,
|
|
237
|
+
but NEVER parallelise RED and GREEN of the same criterion.
|
|
238
|
+
|
|
239
|
+
# Codex subagent reliability
|
|
240
|
+
Every `multi_agent_v1.spawn_agent` message is self-contained and starts with
|
|
241
|
+
`TASK: <imperative assignment>`, then names `DELIVERABLE`, `SCOPE`, and
|
|
242
|
+
`VERIFY`. State that it is an executable assignment, not a context
|
|
243
|
+
handoff. Use `fork_context: false` unless full history is truly
|
|
244
|
+
required; paste only the context the child needs. Full-history forks can
|
|
245
|
+
make the child continue old parent context instead of the delegated task.
|
|
246
|
+
|
|
247
|
+
# TOML-backed subagent routing compatibility
|
|
248
|
+
Treat TOML-backed role routing as **routing-unverified**. The
|
|
249
|
+
`multi_agent_v1.spawn_agent` schema accepts `message`, `fork_context`,
|
|
250
|
+
`agent_type`, and `model`; it cannot select a TOML-backed role, model, reasoning
|
|
251
|
+
effort, or `service_tier` by name alone. Say so briefly in the notepad, paste the
|
|
252
|
+
role requirements into the message, and judge the result from delivered
|
|
253
|
+
evidence. Never claim the reviewer, planner, or explorer role was
|
|
254
|
+
selected from TOML unless runtime evidence confirms it.
|
|
255
|
+
|
|
256
|
+
Treat child status as a progress signal, not a timeout counter. For
|
|
257
|
+
work likely to exceed one wait cycle, tell the child to send
|
|
258
|
+
`WORKING: <task> - <current phase>` before long reading, testing, or
|
|
259
|
+
review passes, and `BLOCKED: <reason>` only when it cannot progress.
|
|
260
|
+
Track spawned agent names locally. Use `multi_agent_v1.wait_agent` for mailbox
|
|
261
|
+
signals, but a timeout only means no new mailbox update arrived.
|
|
262
|
+
Treat a running child as alive and keep doing independent root work.
|
|
263
|
+
Fallback only when the child is completed without the
|
|
264
|
+
deliverable, ack-only, or no longer running. If that followup is still
|
|
265
|
+
silent or ack-only, record the result as inconclusive, do not count it
|
|
266
|
+
as approval/pass, close it if safe, and respawn a smaller
|
|
267
|
+
`fork_context: false` task with the missing deliverable.
|
|
268
|
+
|
|
269
|
+
# Subagent-dependent transition barrier
|
|
270
|
+
Do not mark an `update_plan` step `completed` while an active child owns
|
|
271
|
+
evidence for that step. Do not start dependent implementation until the
|
|
272
|
+
audit, research, or review result is integrated or explicitly recorded
|
|
273
|
+
as inconclusive. Do not generate a plan before spawned research lanes
|
|
274
|
+
that feed the plan have returned or been closed as inconclusive.
|
|
275
|
+
Do not write the final answer, PR handoff, or completion summary while
|
|
276
|
+
active child agents remain open. Use short `multi_agent_v1.wait_agent` cycles.
|
|
277
|
+
After two silent waits send `TASK STILL ACTIVE: return <deliverable> or
|
|
278
|
+
BLOCKED: <reason>`. After four silent or ack-only checks, close the lane as
|
|
279
|
+
inconclusive, record that it is not approval, and respawn smaller only
|
|
280
|
+
if the deliverable is still required.
|
|
281
|
+
|
|
282
|
+
# Verification gate (TRIGGERED, NOT OPTIONAL)
|
|
283
|
+
|
|
284
|
+
Trigger when ANY apply:
|
|
285
|
+
- Tier is HEAVY.
|
|
286
|
+
- User demanded strict, rigorous, or proper review.
|
|
287
|
+
LIGHT tier records a self-review in the notepad instead: re-read the
|
|
288
|
+
diff, run diagnostics, confirm each criterion's evidence, and state in
|
|
289
|
+
one line why the tier held.
|
|
290
|
+
|
|
291
|
+
Procedure (NON-NEGOTIABLE):
|
|
292
|
+
1. Spawn a child with `fork_context: false` and a self-contained reviewer
|
|
293
|
+
assignment in `message`. The `multi_agent_v1.spawn_agent` schema cannot select a
|
|
294
|
+
TOML-backed reviewer role, so paste the reviewer requirements into
|
|
295
|
+
the message. Route this to the `litcodex-momus` reviewer (or the
|
|
296
|
+
`litcodex-litwork-reviewer` lane) and judge it from delivered evidence.
|
|
297
|
+
Pass: goal, success-criteria, scenario evidence, full diff, notepad
|
|
298
|
+
path.
|
|
299
|
+
2. Treat the reviewer's verdict as binding. There is NO "false
|
|
300
|
+
positive". Every concern is real. Do not argue. Do not minimise. Do
|
|
301
|
+
not explain it away.
|
|
302
|
+
3. Fix every issue. Re-run the FULL scenario QA. Capture fresh
|
|
303
|
+
evidence. Update notepad.
|
|
304
|
+
4. Re-submit to the SAME reviewer. Loop until you receive an
|
|
305
|
+
UNCONDITIONAL approval ("looks good but..." = REJECTION).
|
|
306
|
+
5. Only on unconditional approval may you declare done. Stopping early
|
|
307
|
+
IS failure.
|
|
308
|
+
|
|
309
|
+
For design-shaped or critique-heavy verification, the `litcodex-metis`
|
|
310
|
+
agent supplies adversarial design critique; route architecture and
|
|
311
|
+
trade-off concerns there before the reviewer loop closes.
|
|
312
|
+
|
|
313
|
+
# Commits
|
|
314
|
+
Atomic, Conventional Commits (`<type>(<scope>): <imperative>` — feat /
|
|
315
|
+
fix / refactor / test / docs / chore / build / ci / perf). One logical
|
|
316
|
+
change per commit; each commit builds + tests green on its own. No WIP
|
|
317
|
+
on the final branch. If a plan file exists, final commit footer:
|
|
318
|
+
`Plan: .litcodex/plans/<slug>.md`. Do NOT auto-`git commit` unless the
|
|
319
|
+
user requested or preauthorised this session — default is stage + draft
|
|
320
|
+
message + present for approval.
|
|
321
|
+
|
|
322
|
+
# Constraints
|
|
323
|
+
- Every behavior change needs a failing-first proof captured BEFORE
|
|
324
|
+
the production change, through the cheapest faithful channel (unit
|
|
325
|
+
test at a seam; integration/e2e in wiring; the real-surface scenario
|
|
326
|
+
when no test seam exists). If you typed production code first, STOP,
|
|
327
|
+
revert, capture the proof failing, then redo the change. Exempt
|
|
328
|
+
only: pure formatting, comment-only edits, dependency bumps with no
|
|
329
|
+
behavior delta, rename-only moves — justify each in `## Findings`.
|
|
330
|
+
- A test that mirrors its implementation — asserting mocks were
|
|
331
|
+
called, pinning a constant, or unable to fail under any plausible
|
|
332
|
+
regression — is NOT evidence. Prefer a real-surface proof with no
|
|
333
|
+
new test over a tautological test.
|
|
334
|
+
- Refactors: characterization tests pinning current observable
|
|
335
|
+
behavior FIRST, green against the old code, green throughout.
|
|
336
|
+
- Smallest correct change. No drive-by refactors.
|
|
337
|
+
- Never suppress lints / errors / test failures. Never delete, skip,
|
|
338
|
+
`.only`, `.skip`, `xfail`, or comment out tests to green the suite.
|
|
339
|
+
- Never claim done from inference — only from captured evidence.
|
|
340
|
+
- Parallel tool calls for any independent work.
|
|
341
|
+
|
|
342
|
+
# Output discipline
|
|
343
|
+
- First line literally: `🔥 LITWORK ENABLED 🔥`
|
|
344
|
+
- After bootstrap: 1-2 paragraph plan summary + notepad path.
|
|
345
|
+
- During execution: surface only state changes (RED captured, GREEN
|
|
346
|
+
captured, scenario PASS/FAIL with evidence paths, reviewer verdict).
|
|
347
|
+
- Final message: outcome + success-criteria checklist with evidence
|
|
348
|
+
refs + notepad path + reviewer approval (if gate triggered) + commit
|
|
349
|
+
list (`<sha> <subject>`). No file-by-file changelog unless asked.
|
|
350
|
+
|
|
351
|
+
# Stop rules
|
|
352
|
+
- Stop ONLY when every scenario PASSES with captured evidence, every
|
|
353
|
+
cleanup receipt is recorded, notepad is current, and (if gate
|
|
354
|
+
triggered) reviewer approved unconditionally.
|
|
355
|
+
- Leftover QA state (live process, `tmux` session, browser context,
|
|
356
|
+
bound port, temp file / dir) means NOT done. Tear it down, record
|
|
357
|
+
the receipt, then continue.
|
|
358
|
+
- After 2 identical failed attempts at one step, surface what was tried
|
|
359
|
+
and ask the user before another retry.
|
|
360
|
+
- After 2 parallel exploration waves yield no new useful facts, stop
|
|
361
|
+
exploring and act.
|
|
362
|
+
|
|
363
|
+
</litwork-mode>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SCAFFOLD_PLACEHOLDER: Readonly<{}>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Dispatch one argv vector to a route and resolve its exit code. Pure of process.exit; writes only
|
|
4
|
+
* to the injected streams.
|
|
5
|
+
*/
|
|
6
|
+
export declare function main(argv: readonly string[], stdin: NodeJS.ReadableStream, stdout: NodeJS.WritableStream, stderr: NodeJS.WritableStream): Promise<number>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// src/cli.ts — M06-owned component bin dispatcher (A2 §3/§6.4, A3 addendum A1).
|
|
3
|
+
//
|
|
4
|
+
// Bin `litcodex-lit-loop` → dist/cli.js, the target the aggregate hooks.json invokes. Knows exactly
|
|
5
|
+
// two route prefixes — `hook` and `loop` — and NO `config` route (config migration is owned by the
|
|
6
|
+
// separate litcodex-ai installer bin, not this dispatcher).
|
|
7
|
+
//
|
|
8
|
+
// Exit-code table (A3 addendum A1.2):
|
|
9
|
+
// 0 — route ran to completion (hook activation / hook no-op / a loop subcommand that succeeded)
|
|
10
|
+
// 1 — DISPATCHER unknown command (argv[2] not `hook`/`loop`, or `hook` with a second token
|
|
11
|
+
// ≠ user-prompt-submit, or `loop` with an unknown subcommand). Plain-text stderr, no JSON.
|
|
12
|
+
// 2 — M06 hook route malformed/oversized stdin (LitHookError JSON on stderr; owned by hook-cli).
|
|
13
|
+
// 3/4/5 — M09 loop route (ships at T14).
|
|
14
|
+
//
|
|
15
|
+
// `main` NEVER calls process.exit (the shebang wrapper does); it resolves exactly one integer, so
|
|
16
|
+
// the dispatcher is unit-testable with an injected argv array.
|
|
17
|
+
import { runUserPromptSubmitHookCli } from "./hook-cli.js";
|
|
18
|
+
import { loopCommand } from "./loop-cli.js";
|
|
19
|
+
const UNKNOWN_COMMAND = "lit-loop: unknown command\n";
|
|
20
|
+
/**
|
|
21
|
+
* Dispatch one argv vector to a route and resolve its exit code. Pure of process.exit; writes only
|
|
22
|
+
* to the injected streams.
|
|
23
|
+
*/
|
|
24
|
+
export async function main(argv, stdin, stdout, stderr) {
|
|
25
|
+
const command = argv[2];
|
|
26
|
+
const subcommand = argv[3];
|
|
27
|
+
if (command === "hook") {
|
|
28
|
+
if (subcommand !== "user-prompt-submit") {
|
|
29
|
+
stderr.write(UNKNOWN_COMMAND);
|
|
30
|
+
return 1;
|
|
31
|
+
}
|
|
32
|
+
return runUserPromptSubmitHookCli(stdin, stdout, stderr);
|
|
33
|
+
}
|
|
34
|
+
if (command === "loop") {
|
|
35
|
+
// T14: route to M09's loopCommand (argv past `loop`); it resolves one exit code (0/1/2/3/4/5)
|
|
36
|
+
// and never calls process.exit. The `doctor` subcommand is still the M09 stub until M11/T16.
|
|
37
|
+
return loopCommand(argv.slice(3), { stdout, stderr, stdin });
|
|
38
|
+
}
|
|
39
|
+
stderr.write(UNKNOWN_COMMAND);
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
main(process.argv, process.stdin, process.stdout, process.stderr).then((code) => {
|
|
43
|
+
process.exit(code);
|
|
44
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { LoopGoal, LoopGoalStatus, LoopPlan } from "./loop-types.js";
|
|
2
|
+
export interface CodexCreateGoalPayload {
|
|
3
|
+
readonly objective: string;
|
|
4
|
+
}
|
|
5
|
+
export interface LitLoopGoalInstruction {
|
|
6
|
+
readonly text: string;
|
|
7
|
+
readonly json: CodexCreateGoalPayload;
|
|
8
|
+
}
|
|
9
|
+
export declare function buildCodexGoalInstruction(args: {
|
|
10
|
+
readonly plan: LoopPlan;
|
|
11
|
+
readonly goal: LoopGoal;
|
|
12
|
+
readonly isFinal?: boolean;
|
|
13
|
+
}): LitLoopGoalInstruction;
|
|
14
|
+
export declare function buildCodexGoalCheckpoint(args: {
|
|
15
|
+
readonly plan: LoopPlan;
|
|
16
|
+
readonly goal: LoopGoal;
|
|
17
|
+
readonly status: LoopGoalStatus;
|
|
18
|
+
}): string;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// src/codex-goal-instruction.ts — Codex native-goal handoff instruction builder.
|
|
2
|
+
//
|
|
3
|
+
// Builds the `create_goal` / `update_goal` instruction text and JSON payload that lit-loop's
|
|
4
|
+
// handleRun and handleCheckpoint append to their output so the agent keeps Codex's `/goal`
|
|
5
|
+
// surface in sync with the active lit-loop goal. Per-story model only (one Codex goal per
|
|
6
|
+
// lit-loop goal). Pure — no I/O, no store, no clock.
|
|
7
|
+
import { expectedCodexObjective, isFinalRunCompletionCandidate, isLitLoopDone } from "./goal-status.js";
|
|
8
|
+
export function buildCodexGoalInstruction(args) {
|
|
9
|
+
const { plan, goal } = args;
|
|
10
|
+
const json = { objective: expectedCodexObjective(goal) };
|
|
11
|
+
const isFinal = args.isFinal ?? isFinalRunCompletionCandidate(plan, goal);
|
|
12
|
+
const text = buildText(plan, goal, json, isFinal);
|
|
13
|
+
return { text, json };
|
|
14
|
+
}
|
|
15
|
+
function buildText(plan, goal, payload, isFinal) {
|
|
16
|
+
return joinLines([
|
|
17
|
+
"lit-loop Codex goal handoff",
|
|
18
|
+
`Plan: ${plan.goalsPath}`,
|
|
19
|
+
`Ledger: ${plan.ledgerPath}`,
|
|
20
|
+
`Goal: ${goal.id} — ${goal.title}`,
|
|
21
|
+
"",
|
|
22
|
+
...activeGoalLines(goal),
|
|
23
|
+
"",
|
|
24
|
+
...successCriteriaLines(goal),
|
|
25
|
+
"",
|
|
26
|
+
"Codex goal integration constraints:",
|
|
27
|
+
"- Use the create_goal payload exactly as rendered: objective only.",
|
|
28
|
+
"- Goals are unlimited. Do not add numeric limits.",
|
|
29
|
+
"- First call get_goal. If no active goal exists, call create_goal with the payload below.",
|
|
30
|
+
"- If get_goal already reports this objective as active, continue without creating a new goal.",
|
|
31
|
+
"- If a different active Codex goal exists, finish or clear it (`/goal clear`) before starting this lit-loop goal.",
|
|
32
|
+
"- Work only this goal until all criteria pass.",
|
|
33
|
+
...finalLines(goal, isFinal),
|
|
34
|
+
...checkpointLines(),
|
|
35
|
+
"",
|
|
36
|
+
"create_goal payload:",
|
|
37
|
+
JSON.stringify(payload, null, 2),
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
function activeGoalLines(goal) {
|
|
41
|
+
return ["Active goal:", `- id: ${goal.id}`, `- title: ${goal.title}`, `- objective: ${goal.objective}`];
|
|
42
|
+
}
|
|
43
|
+
function successCriteriaLines(goal) {
|
|
44
|
+
if (goal.successCriteria.length === 0)
|
|
45
|
+
return ["Success criteria:", "- No success criteria recorded for this goal."];
|
|
46
|
+
return [
|
|
47
|
+
"Success criteria:",
|
|
48
|
+
...goal.successCriteria.map((c) => {
|
|
49
|
+
const remaining = c.status === "pending" ? " remaining work:" : "";
|
|
50
|
+
return `-${remaining} [${c.id}] (${c.userModel}) ${c.scenario} — expect: ${c.expectedEvidence} — status: ${c.status}`;
|
|
51
|
+
}),
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
function finalLines(goal, isFinal) {
|
|
55
|
+
if (!isFinal) {
|
|
56
|
+
return ["- This is not the final lit-loop goal; leave the Codex goal active for the next run."];
|
|
57
|
+
}
|
|
58
|
+
return [
|
|
59
|
+
"- This is the final lit-loop goal. After all criteria pass and checkpoint is complete:",
|
|
60
|
+
` 1. litcodex loop checkpoint --goal-id ${goal.id} --status complete --evidence "<summary>"`,
|
|
61
|
+
' 2. Call update_goal({status: "complete"}) to mark the Codex goal done.',
|
|
62
|
+
" 3. Run `/goal clear` to close the Codex goal surface.",
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
function checkpointLines() {
|
|
66
|
+
return [
|
|
67
|
+
"- If blocked or failed, checkpoint with the failure evidence; rerun with `litcodex loop run --retry-failed` to resume.",
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
// ── checkpoint handoff ──────────────────────────────────────────────────────
|
|
71
|
+
export function buildCodexGoalCheckpoint(args) {
|
|
72
|
+
const { plan, goal, status } = args;
|
|
73
|
+
if (status === "complete") {
|
|
74
|
+
const lines = [
|
|
75
|
+
"Codex goal checkpoint:",
|
|
76
|
+
`Goal ${goal.id} is complete. Call update_goal({status: "complete"}) to mark the Codex goal done.`,
|
|
77
|
+
];
|
|
78
|
+
if (isLitLoopDone(plan)) {
|
|
79
|
+
lines.push("All lit-loop goals are now complete. Run `/goal clear` to close the Codex goal surface.");
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
lines.push("Run `litcodex loop run` to hand off the next goal.");
|
|
83
|
+
}
|
|
84
|
+
return joinLines(lines);
|
|
85
|
+
}
|
|
86
|
+
return joinLines([
|
|
87
|
+
"Codex goal checkpoint:",
|
|
88
|
+
`Goal ${goal.id} is ${status}. The Codex goal remains active.`,
|
|
89
|
+
"Resume via `litcodex loop run --retry-failed` when ready.",
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
function joinLines(lines) {
|
|
93
|
+
return lines.join("\n");
|
|
94
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accepted stdin event shape AFTER JSON.parse. The declared canonical wire form is snake_case;
|
|
3
|
+
* `isLitUserPromptSubmitInput` additionally accepts the camelCase event-name/transcript keys at
|
|
4
|
+
* runtime (A3 C12). Extra fields (cwd, model, session_id, …) are tolerated and ignored.
|
|
5
|
+
*/
|
|
6
|
+
export interface LitUserPromptSubmitInput {
|
|
7
|
+
readonly hook_event_name: "UserPromptSubmit";
|
|
8
|
+
readonly prompt: string;
|
|
9
|
+
readonly transcript_path?: string | null;
|
|
10
|
+
}
|
|
11
|
+
/** Structured engine result. The CLI maps this to stdout / exit. */
|
|
12
|
+
export type HookDecision = {
|
|
13
|
+
readonly kind: "inject";
|
|
14
|
+
readonly stdout: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: "noop";
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Type-guard. True iff `value` is a record whose accepted event-name key (snake `hook_event_name`
|
|
20
|
+
* primary, camel `hookEventName` fallback) === "UserPromptSubmit", `prompt` is a string, and the
|
|
21
|
+
* transcript-path key (either casing) is undefined | null | string (A3 C12). This is a runtime
|
|
22
|
+
* accept-set, not a structural type assert, so a camelCase-keyed record also returns true.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isLitUserPromptSubmitInput(value: unknown): value is LitUserPromptSubmitInput;
|
|
25
|
+
/**
|
|
26
|
+
* Wraps directive text in the Codex output envelope. Returns "" if the normalized context is empty
|
|
27
|
+
* (caller treats "" as noop). Output is a single-line JSON + trailing "\n":
|
|
28
|
+
* {"hookSpecificOutput":{"hookEventName":"UserPromptSubmit","additionalContext":<ctx>}}\n
|
|
29
|
+
*/
|
|
30
|
+
export declare function formatAdditionalContextOutput(additionalContext: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Pure decision function (multi-mode router). Takes an already-parsed value (NOT a raw string).
|
|
33
|
+
* Total over `unknown`; NEVER throws. Flow: validate shape → match the lit-family trigger token
|
|
34
|
+
* (guard 0) → resolve the mode → run guards 1-3 against the MATCHED mode's marker (RC1) → load that
|
|
35
|
+
* mode's directive fail-silent. Returns { kind:"noop" } for a wrong-shape value, no trigger, a guard
|
|
36
|
+
* veto, or a fail-silent empty directive; { kind:"inject", stdout } only on a real activation.
|
|
37
|
+
*/
|
|
38
|
+
export declare function runUserPromptSubmitHook(input: unknown): HookDecision;
|