loopwright 0.1.11 → 0.1.12

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.
@@ -47,8 +47,7 @@ try {
47
47
  });
48
48
  writeState(dir, id, state);
49
49
  deny(
50
- '',
51
- '',
50
+ 'Stop',
52
51
  'loopwright: no passing review for the current code. Run /loopwright-review (or finish the fix loop) before stopping.',
53
52
  );
54
53
  } catch (err) {
@@ -0,0 +1,243 @@
1
+ // Task-file edits behind the writer commands of lw.mjs. Every function maps the file's text (LF line endings) to its
2
+ // next text, or throws a message for the user; icons are written only in a file that has the yaml settings fence.
3
+ import { ICON_PREFIX, TASK_FILE_ICONS, settingValue } from './lib.mjs';
4
+
5
+ const { settings: SETTING_ICONS, headings: HEADING_ICONS, tags: TAG_ICONS } = TASK_FILE_ICONS;
6
+
7
+ export const SETTING_KEYS = Object.keys(SETTING_ICONS);
8
+ /** Section names in the order a new heading is placed. */
9
+ export const SECTION_NAMES = [
10
+ 'Goal',
11
+ 'Bug report',
12
+ 'Root cause',
13
+ 'Evidence',
14
+ 'Decisions',
15
+ 'Assumptions',
16
+ 'Acceptance criteria',
17
+ 'Slices',
18
+ 'Review log',
19
+ 'Open questions',
20
+ 'Notes for Done',
21
+ 'Follow-ups',
22
+ ];
23
+
24
+ export const header = (t) => t.split(/^## /m)[0];
25
+ export const fenced = (t) => /^```yaml[ \t]*$/m.test(header(t));
26
+ const icon = (t, table, name) => (fenced(t) ? `${table[name]} ` : '');
27
+ const tagged = (t, tag) => `${icon(t, TAG_ICONS, tag)}[${tag}]`;
28
+ const nextNumber = (text, re) => 1 + Math.max(0, ...Array.from(text.matchAll(re), (m) => Number(m[1])));
29
+
30
+ /** Set `key: value` in the settings (added when missing), or drop the line when `value` is null. */
31
+ export function setSetting(t, key, value) {
32
+ const head = header(t);
33
+ const rest = t.slice(head.length);
34
+ const line = new RegExp(`^(${ICON_PREFIX})${key}:[^\\n]*(\\n?)`, 'm');
35
+ if (line.test(head))
36
+ return head.replace(line, (_, ic, nl) => (value === null ? '' : `${ic}${key}: ${value}${nl}`)) + rest;
37
+ if (value === null) return t;
38
+ const added = `${icon(t, SETTING_ICONS, key)}${key}: ${value}\n`;
39
+ if (fenced(t)) {
40
+ const open = /^```yaml[ \t]*\n/m.exec(head);
41
+ const from = open.index + open[0].length;
42
+ const close = from + head.slice(from).search(/^```[ \t]*$/m);
43
+ return head.slice(0, close) + added + head.slice(close) + rest;
44
+ }
45
+ const last = [...head.matchAll(new RegExp(`^${ICON_PREFIX}(?:${SETTING_KEYS.join('|')}):[^\\n]*\\n`, 'gm'))].at(-1);
46
+ const at = last ? last.index + last[0].length : head.length;
47
+ return head.slice(0, at) + added + head.slice(at) + rest;
48
+ }
49
+
50
+ const headingRe = (name) => new RegExp(`^## ${ICON_PREFIX}${name}[ \\t]*$`, 'm');
51
+
52
+ /** Add the section's heading when missing, before the first later section of the template order (else last). */
53
+ export function ensureSection(t, name) {
54
+ if (headingRe(name).test(t)) return t;
55
+ const heading = `## ${icon(t, HEADING_ICONS, name)}${name}`;
56
+ const later = SECTION_NAMES.slice(SECTION_NAMES.indexOf(name) + 1)
57
+ .map((n) => headingRe(n).exec(t))
58
+ .filter(Boolean);
59
+ const at = Math.min(...later.map((m) => m.index));
60
+ return later.length ? `${t.slice(0, at)}${heading}\n\n${t.slice(at)}` : `${t.replace(/\n*$/, '\n')}\n${heading}\n`;
61
+ }
62
+
63
+ function sectionSpan(t, name) {
64
+ const m = headingRe(name).exec(t);
65
+ const from = m.index + m[0].length;
66
+ const next = t.slice(from).search(/^## /m);
67
+ return { from, to: next === -1 ? t.length : from + next };
68
+ }
69
+
70
+ const sectionBody = (t, name) => {
71
+ const { from, to } = sectionSpan(t, name);
72
+ return t.slice(from, to).trim();
73
+ };
74
+
75
+ /** Replace the section's body with the lines `change` returns for the current ones; creates a missing section. */
76
+ function changeLines(t, name, change) {
77
+ const text = ensureSection(t, name);
78
+ const body = sectionBody(text, name);
79
+ const lines = change(body ? body.split('\n') : []).join('\n');
80
+ const { from, to } = sectionSpan(text, name);
81
+ return `${text.slice(0, from)}${lines ? `\n\n${lines}\n` : '\n'}${to < text.length ? '\n' : ''}${text.slice(to)}`;
82
+ }
83
+
84
+ export const writeSection = (t, name, body, append) =>
85
+ changeLines(t, name, (lines) => [...(append ? lines : []), ...(body ? body.split('\n') : [])]);
86
+
87
+ const DECISION_TAGS = ['asked', 'batch-confirmed', 'overridden'];
88
+ const ASSUMPTION_TAGS = ['confirmed', 'batch-confirmed', 'overridden'];
89
+
90
+ /** `flags`: the options an entry type takes; `tags`: its allowed `--tag` values; `section`: where it is appended. */
91
+ const ENTRY_TYPES = {
92
+ decision: { section: 'Decisions', flags: ['tag', 'resolves'], tags: DECISION_TAGS, tagRequired: true },
93
+ assumption: { section: 'Assumptions', flags: ['tag', 'resolves'], tags: ASSUMPTION_TAGS, tagRequired: true },
94
+ question: { section: 'Open questions', flags: [], prefix: '- ', suffix: ' — pending' },
95
+ ac: { section: 'Acceptance criteria', flags: ['tag', 'interface', 'test'], tags: ['repro', 'regression'] },
96
+ slice: { section: 'Slices', flags: [] },
97
+ round: { section: 'Review log', flags: ['scope'] },
98
+ finding: { section: 'Review log', flags: [], nested: true },
99
+ sibling: { section: 'Review log', flags: [], nested: true },
100
+ 'scope-change': { section: 'Review log', flags: [], prefix: '- Scope change: ' },
101
+ simplify: { section: 'Review log', flags: [], prefix: '- Simplify: ' },
102
+ followup: { section: 'Follow-ups', flags: [], prefix: '- ' },
103
+ };
104
+ export const ENTRY_NAMES = Object.keys(ENTRY_TYPES);
105
+
106
+ /**
107
+ * Append the next-numbered entry of `type`. `opts` holds the flags given, `input` the stdin lines: the first is the
108
+ * entry's text, the rest become sub-lines. Returns the new text and the entry's id, when it has one.
109
+ */
110
+ export function addEntry(t, type, opts, input) {
111
+ const spec = ENTRY_TYPES[type];
112
+ const extra = Object.keys(opts).find((k) => !spec.flags.includes(k));
113
+ if (extra) throw new Error(`add ${type} does not take --${extra}`);
114
+ if (opts.tag === undefined ? spec.tagRequired : !spec.tags.includes(opts.tag))
115
+ throw new Error(`add ${type} needs --tag, one of ${spec.tags.join(', ')}`);
116
+ if (!input.length) throw new Error(`add ${type} needs its text on stdin`);
117
+ if (spec.nested && input.length > 1) throw new Error(`add ${type} takes one line of text`);
118
+ const [text, ...more] = input;
119
+ const subs = [
120
+ ...(opts.interface === undefined ? [] : [`interface: ${opts.interface}`]),
121
+ ...(opts.test === undefined ? [] : [`test: ${opts.test}`]),
122
+ ...more,
123
+ ].map((l) => ` - ${l}`);
124
+ let id;
125
+ const number = (letters) => `${letters}${nextNumber(t, new RegExp(`^- ${letters}(\\d+) `, 'gm'))}`;
126
+ const entry = (lines) => (log) => [...log, ...lines];
127
+ let change;
128
+ if (type === 'decision' || type === 'assumption') {
129
+ id = number(type === 'decision' ? 'D' : 'A');
130
+ change = entry([`- ${id} ${tagged(t, opts.tag)} ${text}`, ...subs]);
131
+ } else if (type === 'ac') {
132
+ id = number('AC');
133
+ change = entry([`- ${id}${opts.tag ? ` [${opts.tag}]` : ''} ${text}`, ...subs]);
134
+ } else if (type === 'slice') {
135
+ id = number('S');
136
+ change = entry([`- ${id} ${tagged(t, 'todo')} ${text}`, ...subs]);
137
+ } else if (type === 'round') {
138
+ change = (log) => {
139
+ const rounds = log
140
+ .slice(log.findLastIndex((l) => l.startsWith('- Scope change:')) + 1)
141
+ .map((l) => /^- R(\d+)(?: (\S+))?:/.exec(l))
142
+ .filter((m) => m && m[2] === opts.scope);
143
+ id = `R${1 + Math.max(0, ...rounds.map((m) => Number(m[1])))}`;
144
+ return [...log, `- ${id}${opts.scope ? ` ${opts.scope}` : ''}: ${text}`, ...subs];
145
+ };
146
+ } else if (spec.nested) {
147
+ change = (log) => {
148
+ const round = log.findLastIndex((l) => /^- R\d+/.test(l));
149
+ if (round === -1) throw new Error(`add ${type}: no review round to attach it to`);
150
+ let end = round + 1;
151
+ while (log[end]?.startsWith(' ')) end++;
152
+ const n = nextNumber(log.slice(round, end).join('\n'), /^ {2}- U(\d+) /gm);
153
+ id = type === 'finding' ? `U${n}` : undefined;
154
+ return log.toSpliced(end, 0, type === 'finding' ? ` - ${id} ${text}` : ` - Sibling ${text}`);
155
+ };
156
+ } else change = entry([`${spec.prefix}${text}${spec.suffix ?? ''}`, ...subs]);
157
+ let next = t;
158
+ if (opts.resolves !== undefined) {
159
+ const pending = `- ${opts.resolves} — pending`;
160
+ if (!headingRe('Open questions').test(t) || !sectionBody(t, 'Open questions').split('\n').includes(pending))
161
+ throw new Error(`add ${type}: no open question '${opts.resolves}'`);
162
+ next = changeLines(t, 'Open questions', (lines) => lines.filter((l) => l !== pending));
163
+ }
164
+ return { text: changeLines(next, spec.section, change), id };
165
+ }
166
+
167
+ /** Set a slice to todo, tested or passed (with its icon), or drop the `— apply pending` ending of the Simplify line. */
168
+ export function markEntry(t, id, state) {
169
+ if (id === 'simplify') {
170
+ if (state !== 'applied') throw new Error('mark simplify takes the state applied');
171
+ const lines = t.split('\n');
172
+ const at = lines.findLastIndex((l) => /^- Simplify: .* — apply pending$/.test(l));
173
+ if (at === -1) throw new Error('mark: no Simplify line is waiting to be applied');
174
+ lines[at] = lines[at].replace(/ — apply pending$/, '');
175
+ return lines.join('\n');
176
+ }
177
+ if (!/^S\d+$/.test(id ?? '')) throw new Error('mark: expected a slice id (S<n>) or simplify');
178
+ if (!['todo', 'tested', 'passed'].includes(state)) throw new Error('mark: the state is todo, tested or passed');
179
+ const line = new RegExp(`^- ${id} ${ICON_PREFIX}\\[(?:todo|tested|passed)\\]`, 'm');
180
+ if (!line.test(t)) throw new Error(`mark: ${id} not found`);
181
+ return t.replace(line, () => `- ${id} ${tagged(t, state)}`);
182
+ }
183
+
184
+ /** Replace the text of a decision, assumption, criterion or slice, and/or its `interface:` and `test:` sub-lines. */
185
+ export function editEntry(t, id, { text, interface: iface, test }) {
186
+ if (!/^(?:D|A|AC|S)\d+$/.test(id ?? '')) throw new Error('edit: expected an id such as D1, A1, AC1 or S1');
187
+ const lines = t.split('\n');
188
+ const at = lines.findIndex((l) => l.startsWith(`- ${id} `));
189
+ if (at === -1) throw new Error(`edit: ${id} not found`);
190
+ if (text !== undefined)
191
+ lines[at] = new RegExp(`^- ${id} (?:${ICON_PREFIX}\\[[a-z-]+\\] )?`).exec(lines[at])[0] + text;
192
+ for (const [key, value] of [
193
+ ['interface', iface],
194
+ ['test', test],
195
+ ]) {
196
+ if (value === undefined) continue;
197
+ let end = at + 1;
198
+ while (lines[end]?.startsWith(' ')) end++;
199
+ const subs = lines.slice(at + 1, end);
200
+ const own = subs.findIndex((l) => l.startsWith(` - ${key}:`));
201
+ const after = key === 'test' ? subs.findIndex((l) => l.startsWith(' - interface:')) : -1;
202
+ if (own === -1) lines.splice(at + 1 + (after + 1), 0, ` - ${key}: ${value}`);
203
+ else lines[at + 1 + own] = ` - ${key}: ${value}`;
204
+ }
205
+ return lines.join('\n');
206
+ }
207
+
208
+ /** A new task file: the title and the kind; `fillTask` adds the rest. */
209
+ export const skeleton = (title, kind) => `# ${title}\n\n\`\`\`yaml\n${SETTING_ICONS.kind} kind: ${kind}\n\`\`\`\n`;
210
+
211
+ /**
212
+ * Bring a new file or a proposed stub to a task file at Plan: active, the settings the plan fills in later set to
213
+ * pending, and every empty section. What the stub already has (kind, plan, links, goal, evidence) is kept.
214
+ */
215
+ export function fillTask(t, { profile, worktree, base }) {
216
+ const settings = [
217
+ ['status', 'active', true],
218
+ ['stage', 'plan', true],
219
+ ['plan', 'draft'],
220
+ ['tier', 'pending'],
221
+ ['profile', profile ?? 'pending', profile !== undefined],
222
+ ['two-pass', 'pending'],
223
+ ['fix-round cap', 'pending'],
224
+ ['checks', 'pending'],
225
+ ['worktree', worktree, true],
226
+ ['base commit', base, true],
227
+ ];
228
+ const withSettings = settings.reduce(
229
+ (text, [key, value, force]) =>
230
+ force || settingValue(header(text), key) === undefined ? setSetting(text, key, value) : text,
231
+ t,
232
+ );
233
+ const fix = settingValue(header(t), 'kind') === 'fix';
234
+ return [
235
+ 'Goal',
236
+ 'Decisions',
237
+ 'Assumptions',
238
+ 'Acceptance criteria',
239
+ 'Review log',
240
+ 'Open questions',
241
+ ...(fix ? ['Bug report', 'Root cause', 'Follow-ups', 'Evidence'] : []),
242
+ ].reduce((text, name) => ensureSection(text, name), withSettings);
243
+ }
@@ -0,0 +1,37 @@
1
+ # loopwright glossary
2
+
3
+ Use one term for each idea, in every skill, agent file, prompt, doc and message to the user. A second word for the same thing reads as a second thing. Each entry gives the term, a one-line definition, and the phrases not to use for it; a test fails when a `Not:` phrase appears in the shipped files or docs. A new term goes into both copies of this file (`GLOSSARY.md` and `content/prompts/glossary.md`).
4
+
5
+ - **task id** (AC3, D2, A1, S2, R1, U1): a short label in the task file for one acceptance criterion, decision, assumption, slice, review round or undecided finding; say what the item is, never the label alone.
6
+ - **acceptance criterion** (AC): one thing the finished work must do that you can see, such as "an expired link shows a clear message".
7
+ - **acceptance test**: an automated test, written before the code, that checks one acceptance criterion; when it passes, that behavior works.
8
+ - **locked test**: a test file fixed with a fingerprint so the implementer cannot change it to make it pass.
9
+ Not: frozen, frozen test, frozen tests
10
+ - **re-lock**: locking a test file again after it was edited, which is allowed only after you chose to go back or approved a pull.
11
+ - **tier**: how big the task is (small, standard or large); it sets how much process the task gets.
12
+ - **profile**: how much effort the helper agents spend (lean, balanced, thorough or deep); more effort costs more time and tokens.
13
+ - **slice**: one separately built and checked piece of a large task.
14
+ - **stop gate**: a check that keeps the agent from ending its turn while a build or review is unfinished.
15
+ - **fix round**: one pass of fixing what a review found, followed by another review; each task has a limit.
16
+ Not: repair round, repair rounds, repair attempt, repair attempts
17
+ - **review round**: one run of the reviewer over the change, counted from 1 in the review log.
18
+ - **two-pass review**: the reviewer checks the change twice, once without hints and once against the implementer's own report of what it did.
19
+ - **undecided finding**: a review concern the reviewer cannot settle alone, so you decide whether to fix it or dismiss it.
20
+ Not: open finding, open findings
21
+ - **deviation**: something the implementer did differently from the plan or could not do as planned; you accept it, ask for a fix, or go back.
22
+ - **simplify cut**: a proposed removal of code, tests or docs that the change added and does not need; you choose which to apply.
23
+ Not: simplification, simplifications
24
+ - **worktree**: a separate working folder of the same repository, on its own branch, so two tasks do not mix.
25
+ - **base commit**: the saved point in git history where the task began; the review compares the work against it.
26
+ - **implementer**: the agent that writes the code in Build; the tester writes the tests.
27
+ Not: code writer
28
+ - **stage**: one of Plan, Test, Build, Review and Done; "step" is kept for the numbered steps inside a stage.
29
+ Not: Plan step, Test step, Review step, Done step, Build step
30
+ - **context restore**: what runs after compaction to print the goal, stage, decisions and next step again from the task file.
31
+ Not: context reinjection
32
+ - **go back**: return to an earlier stage after Build began, by `reopen`, only on your choice.
33
+ - **state tool**: the script (`lw.mjs`) that records the stage, history and locked tests and edits the task file; name the file only in brackets or in commands.
34
+ - **stub**: a short task file saved for later by Park, with a goal and nothing decided.
35
+ Not: proposed task, proposed tasks
36
+ - **park**: save a stub for later instead of working on it now.
37
+ - **follow-up**: a change found while working that belongs in its own later task, not in this one.
@@ -16,4 +16,5 @@ Shared by the tester, implementer and reviewer. The repo's own docs on architect
16
16
  - **Comments.** Comments explain why, briefly. State each rationale in exactly one place. Never restate what the code does. Why: a comment that repeats the code or another comment goes stale first.
17
17
  - **No change-log comments.** Do not write "added", "changed from" or "now uses"; history lives in git. Why: the comment is wrong once the next change lands.
18
18
  - **Leave existing docs alone.** Edit docs and comments you did not need to change only when your change makes them false. Why: unrelated rewrites bury the real diff.
19
+ - **One term per idea.** Use the terms in `glossary.md` (next to this file) in code comments, test names and reports; never a second word for a glossary term. Why: a second word for a thing reads as a second thing.
19
20
  - **The test name carries the behavior.** Name a test for what it checks and skip doc blocks or comments that restate the name or the criterion. Why: a restated criterion is a second copy to keep in sync.
@@ -8,11 +8,11 @@ The reader knows neither loopwright nor this code, and every "what do you mean?"
8
8
 
9
9
  1. **Outcome or decision first.** Open with what happened or what you need decided, then the reason. Why: a reader who stops after one sentence still has the point.
10
10
  2. **Write for a reader who has not seen the code, the tool output or the task file.** Say what a thing is before you use it, and never lean on something only you read. Why: you have seen files the user never opened, so your shorthand feels obvious to you and is a puzzle to them.
11
- 3. **Plain description first, the name in brackets after.** Say what it is in everyday words, then give the file, function or loopwright term in brackets as a lookup pointer; a name or id never stands alone. Why: the plain words make the point, and the name still lets the user find it.
11
+ 3. **Plain description first, the name in brackets after.** Say what it is in everyday words, then give the file, function or task id in brackets as a lookup pointer; brackets carry names only (files, functions, task ids), and a name or id never stands alone. A glossary term is not a name: use it as an ordinary word, and explain it in plain words the first time it comes up. Why: the plain words make the point, and the name still lets the user find it.
12
12
  4. **Say what each finding or trade-off means for the user.** State the effect on what they will see or do, not only the technical fact. Why: a fact without its effect leaves the user to work out why they should care.
13
13
  5. **One idea per sentence.** Aim for 15–20 words; the target is soft, so split a long sentence rather than cut meaning. Why: short sentences are read once, long ones twice, and hard caps make prose choppy.
14
14
  6. **Use active voice and say who acts.** "The tester locks the tests", not "the tests are locked". Why: the user needs to know who did a thing, and who they need to answer.
15
- 7. **Use the same word for the same thing.** Do not coin labels during the work; if a term needs a name, introduce it with its plain description. Why: a second word for a thing reads as a second thing.
15
+ 7. **Use the same word for the same thing.** Use the terms in `glossary.md`, and do not coin labels during the work; if a term needs a name, introduce it with its plain description. Why: a second word for a thing reads as a second thing.
16
16
  8. **Decision questions say what is decided and why, each option says what happens if chosen, and one recommendation comes with a reason.** Never a bare yes/no. Why: the user can pick without asking what an option does.
17
17
  9. **Give one concrete example for a trade-off.** Show what it looks like for this change. Why: a trade-off in the abstract is hard to weigh, and one real case is quick to judge.
18
18
  10. **Give the short answer first and details on request.** Explain only what this message needs, and offer the rest. Why: extra detail costs the user reading time now, while an offer costs nothing.
@@ -22,29 +22,10 @@ The reader knows neither loopwright nor this code, and every "what do you mean?"
22
22
  ## Examples
23
23
 
24
24
  **Before:** AC1 and AC2 covered; locked: test/login.test.ts. D3 accepted.
25
- **After:** Tests now check the two sign-in behaviors you asked for (a wrong password shows an error; a right one opens the dashboard). They are frozen, so the code writer cannot change them (test/login.test.ts). Next, the implementer writes the code.
25
+ **After:** Tests now check the two sign-in behaviors you asked for (a wrong password shows an error; a right one opens the dashboard). They are locked, so the implementer cannot change them (test/login.test.ts). Next, the implementer writes the code.
26
26
 
27
27
  **Before:** Deviation: D4 conflicts with locked test/login.test.ts ("Invalid password" vs "Wrong password"); implemented to the test, test untouched.
28
- **After:** Your choice of error text and a frozen test disagree. You chose "Wrong password" for a failed sign-in, but the test expects "Invalid password" (test/login.test.ts). The implementer cannot change the test, so it wrote the code to show "Invalid password". Do you want to keep "Invalid password", or go back to the test step so the test is corrected and the code then shows "Wrong password"? I recommend going back: the test, not your choice, is what looks wrong.
28
+ **After:** Your choice of error text and a locked test disagree. You chose "Wrong password" for a failed sign-in, but the test expects "Invalid password" (test/login.test.ts). The implementer cannot change the test, so it wrote the code to show "Invalid password". Do you want to keep "Invalid password", or go back to the Test stage so the test is corrected and the code then shows "Wrong password"? I recommend going back: the test, not your choice, is what looks wrong.
29
29
 
30
30
  **Before:** Tier: large, two slices, two-pass review on, fix-round cap 3.
31
- **After:** This is a big change, so I will build it in two parts and review each part, then the whole. The reviewer checks twice because the speed claim cannot be shown by tests. A review that finds problems gets up to 3 repair attempts. Is that right?
32
-
33
- ## Glossary
34
-
35
- - **Task id** (AC3, D2, A1, S2, R1, U1): a short label in the task file for one acceptance criterion, decision, assumption, slice, review round or undecided finding; say what the item is, never the label alone.
36
- - **Acceptance criterion** (AC): one thing the finished work must do that you can see, such as "an expired link shows a clear message".
37
- - **Acceptance test**: an automated test, written before the code, that checks one acceptance criterion; when it passes, that behavior works.
38
- - **Lock** (locked test): a test file frozen with a fingerprint so the code writer cannot change it to make it pass.
39
- - **Re-lock**: freezing a test file again after it was edited, which is allowed only after you chose to go back or approved a pull.
40
- - **Tier**: how big the task is (small, standard or large); it sets how much process the task gets.
41
- - **Profile**: how much effort the helper agents spend (lean, balanced, thorough or deep); more effort costs more time and tokens.
42
- - **Slice**: one separately built and checked part of a large task.
43
- - **Stop gate**: a check that keeps the agent from ending its turn while a build or review is unfinished.
44
- - **Fix round**: one pass of repairing what a review found, followed by another review; each task has a limit.
45
- - **Two-pass review**: the reviewer checks the change twice, once without hints and once against the implementer's own report of what it did.
46
- - **Undecided finding**: a review concern the reviewer cannot settle alone, so you decide whether to fix it or dismiss it.
47
- - **Deviation**: something the implementer did differently from the plan or could not do as planned; you accept it, ask for a fix, or go back.
48
- - **Simplify cut**: a proposed removal of code, tests or docs that the change added and does not need; you choose which to apply.
49
- - **Worktree**: a separate working folder of the same repository, on its own branch, so two tasks do not mix.
50
- - **Base commit**: the saved point in git history where the task began; the review compares the work against it.
31
+ **After:** This is a big change, so I will build it in two slices and review each slice, then the whole. The reviewer checks twice because the speed claim cannot be shown by tests. A review that finds problems gets up to 3 fix rounds. Is that right?
@@ -8,7 +8,7 @@ The implementer subagent writes the code. This thread dispatches it and hands th
8
8
 
9
9
  ## Setup
10
10
 
11
- Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` unless you already read it in this conversation, and write every message to the user by it.
11
+ Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` and `{{LW_HOME}}/prompts/glossary.md` unless you already read them in this conversation, and write every message to the user by them, using one term for each idea.
12
12
 
13
13
  1. Run every loopwright command from the worktree root: `cd "$(git rev-parse --show-toplevel)"`.
14
14
  2. `node "{{LW_HOME}}/hooks/lw.mjs" brief implementer` → `dir` (`<lw>`), `task` (relative to `<lw>`), `stage`, `lockedTests`, `effort`. `dir` `null` inside a git repo → no task has started here yet; `lw.mjs start` creates `.loopwright/` with the first task, so continue and `task: null` reports "no active task". Not a git repo → tell the user loopwright must run inside a git repo, stop.
@@ -19,17 +19,17 @@ Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.m
19
19
  - `kind: fix` with no `lockedTests`, at any tier including small → run `/loopwright-test` first; a fix is never built without a locked repro test.
20
20
  - `large` → the current slice is the first `S<n> [tested]` line; build only that slice. Every slice `[passed]` → this is a whole-branch fix round; no slice limit.
21
21
  - `## Review log` has a `- Simplify:` line ending in `— apply pending` (an approved Simplify apply was interrupted) → run `/loopwright-review` to finish it, and stop here: skip steps 5–7 and the Steps below.
22
- 5. Moved branch. Skip this on a fix round (called with Review findings). `headMoved` in `brief` (new commits since the base commit, at least one already on the upstream branch, and not answered yet for this HEAD) → run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "branch moved"`, list the commits to the user and ask one question: are they pulled commits (leave them out of the review) or this task's own commits (keep them in)? After the answer run `node "{{LW_HOME}}/hooks/lw.mjs" resume` and record it as a decision `D<n> [asked]`.
22
+ 5. Moved branch. Skip this on a fix round (called with Review findings). `headMoved` in `brief` (new commits since the base commit, at least one already on the upstream branch, and not answered yet for this HEAD) → run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "branch moved"`, list the commits to the user and ask one question: are they pulled commits (leave them out of the review) or this task's own commits (keep them in)? After the answer run `node "{{LW_HOME}}/hooks/lw.mjs" resume` and record it with `node "{{LW_HOME}}/hooks/lw.mjs" add decision --tag asked <<'LW_TEXT'`, the decision on the next line, then `LW_TEXT`.
23
23
  - `headMoved.keptEarlier` → an earlier answer kept commits in the review, so the branch holds both kinds whatever the answer: list only the new commits, and a 'pulled' answer takes the keep-base path below, with the both-kinds notice.
24
24
  - `headMoved.localOnly` → the listed short shas exist only locally, so they are the task's own work and the branch holds both kinds whatever the answer: a 'pulled' answer takes the keep-base path below, with the both-kinds notice. Never judge this from the commit subjects.
25
- - Pulled → run `node "{{LW_HOME}}/hooks/lw.mjs" start <task> --force --base HEAD && node "{{LW_HOME}}/hooks/lw.mjs" stage build` as one call, update `base commit` in the task file header to the new HEAD, then run `node "{{LW_HOME}}/hooks/lw.mjs" accept-locks --restart --reason "<the decision in words>"`.
25
+ - Pulled → run `node "{{LW_HOME}}/hooks/lw.mjs" start <task> --force --base HEAD && node "{{LW_HOME}}/hooks/lw.mjs" stage build` as one call, then run `node "{{LW_HOME}}/hooks/lw.mjs" accept-locks --restart --reason "<the decision in words>"`.
26
26
  - This task's own commits, or a branch holding both kinds → run `node "{{LW_HOME}}/hooks/lw.mjs" keep-base --reason "<the decision in words>"`; the base stays. Both kinds: add `--pulled` to that command, so the locked tests the new commits changed show in `pulledLocks` (step 7), and tell the user the pulled commits stay in the review, because the base cannot move past the task's own commits.
27
- 6. Upstream check. Skip this check on a fix round (called with Review findings). Otherwise run `GIT_TERMINAL_PROMPT=0 git fetch --quiet` (never prompts for credentials; failure, e.g. offline or no auth → skip). List `git log --oneline HEAD..@{u}`; with no upstream, use `HEAD..origin/HEAD`; with neither, skip. For `large`, check before each slice's first Build. If the new commits touch the task's files or feature, or a sibling repo the task touches, run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "upstream changed"`, show them to the user and ask whether to pull first or stop (someone may already have done this work) before spawning the implementer. Before asking, run `brief` and note whether `ownCommits` is present (the task already has commits since its base, answered as its own or only local). After the answer, run `node "{{LW_HOME}}/hooks/lw.mjs" resume` and record it as a decision `D<n> [asked]`. If the user pulled and `ownCommits` was present, the base stays: run `node "{{LW_HOME}}/hooks/lw.mjs" keep-base --pulled --reason "<the pull decision in words>"` instead of the restart below, tell the user the pulled commits stay in the review (the base cannot move past the task's own commits), and go to step 7. If it pulled and `ownCommits` was absent, rebase the review scope so pulled commits are not judged as this task's change: run `node "{{LW_HOME}}/hooks/lw.mjs" start <task> --force --base HEAD && node "{{LW_HOME}}/hooks/lw.mjs" stage build` as one call (`start` keeps locks and history and resets the stage to plan; `stage build` sets it back), and update `base commit` in the task file header to the new HEAD, then run `node "{{LW_HOME}}/hooks/lw.mjs" accept-locks --restart --reason "<the pull decision in words>"` (the pull is the approved restart, so it is not raised again in Review). Otherwise continue.
27
+ 6. Upstream check. Skip this check on a fix round (called with Review findings). Otherwise run `GIT_TERMINAL_PROMPT=0 git fetch --quiet` (never prompts for credentials; failure, e.g. offline or no auth → skip). List `git log --oneline HEAD..@{u}`; with no upstream, use `HEAD..origin/HEAD`; with neither, skip. For `large`, check before each slice's first Build. If the new commits touch the task's files or feature, or a sibling repo the task touches, run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "upstream changed"`, show them to the user and ask whether to pull first or stop (someone may already have done this work) before spawning the implementer. Before asking, run `brief` and note whether `ownCommits` is present (the task already has commits since its base, answered as its own or only local). After the answer, run `node "{{LW_HOME}}/hooks/lw.mjs" resume` and record it the way step 5 does. If the user pulled and `ownCommits` was present, the base stays: run `node "{{LW_HOME}}/hooks/lw.mjs" keep-base --pulled --reason "<the pull decision in words>"` instead of the restart below, tell the user the pulled commits stay in the review (the base cannot move past the task's own commits), and go to step 7. If it pulled and `ownCommits` was absent, rebase the review scope so pulled commits are not judged as this task's change: run `node "{{LW_HOME}}/hooks/lw.mjs" start <task> --force --base HEAD && node "{{LW_HOME}}/hooks/lw.mjs" stage build` as one call (`start` keeps locks and history, updates the base commit line and resets the stage to plan; `stage build` sets it back), then run `node "{{LW_HOME}}/hooks/lw.mjs" accept-locks --restart --reason "<the pull decision in words>"` (the pull is the approved restart, so it is not raised again in Review). Otherwise continue.
28
28
  7. After a pull (step 5 or 6), run `brief` again, as in step 2. `pulledLocks` present (a pulled commit changed those locked tests) → before the implementer runs, send only the listed files to Test: `node "{{LW_HOME}}/hooks/lw.mjs" reopen test "<the pull decision in words>"` when Build has begun, `node "{{LW_HOME}}/hooks/lw.mjs" stage test` otherwise, then run `/loopwright-test` for those files. After the tester re-locked them, run `node "{{LW_HOME}}/hooks/lw.mjs" accept-locks --reason "<the pull decision in words>" <path>…` with the `pulledLocks` paths, so the re-locks are accepted under the pull decision, and continue with Steps.
29
29
 
30
30
  ## Steps
31
31
 
32
- 1. `node "{{LW_HOME}}/hooks/lw.mjs" stage build` (it updates the task file header `stage:` line; if it prints `"header": false`, set that line by hand).
32
+ 1. `node "{{LW_HOME}}/hooks/lw.mjs" stage build` (it updates the task file header `stage:` line; if it prints `"header": false`, run `node "{{LW_HOME}}/hooks/lw.mjs" set stage build`).
33
33
  2. Now spawn the `loopwright-implementer` subagent and wait for its result. On Claude Code pass `effort` = the `effort` from `brief` on the spawn; if `brief` has no `effort` (it warns on stderr) or the spawn rejects `effort`, spawn without it (the agent file's effort applies). The prompt contains only:
34
34
  - the absolute task file path (`<lw>/<task>`);
35
35
  - large tier: "Implement slice S<n> only.";
@@ -37,8 +37,8 @@ Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.m
37
37
  - fix round: the findings to fix, verbatim from Review (location, expectation, proof).
38
38
  Never paste chat history, your own summary of the decisions, or design ideas; the task file is the source.
39
39
  3. Keep the implementer report verbatim in this conversation; a two-pass review needs it.
40
- Fix task: write the report's `Root cause:` line to `## Root cause` in the task file. A root cause that differs from the plan's hypothesis is a `Deviation`, handled in step 4.
41
- 4. `Deviations` not "none" → run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "deviations in build"` (so the stop gate lets you end the turn), then show each to the user before Review, one at a time, in plain words following the rules file (what the implementer did differently from the plan, and why; never the raw report text), and ask (Claude: `AskUserQuestion`; Codex: numbered text, then end the turn). After the answers, run `node "{{LW_HOME}}/hooks/lw.mjs" resume`. The user either accepts it (write a new decision `D<n> [asked]` to the task file), wants it fixed (run `node "{{LW_HOME}}/hooks/lw.mjs" stage build` first, so a `reopen` the implementer runs on its own does not directly follow the `resume` and is not counted as the user's choice; then spawn the `loopwright-implementer` subagent and wait for its result again, with the deviation as the finding), or wants to go back: offer that when the deviation needs a changed decision or locked test. Going back: directly after `resume`, run `node "{{LW_HOME}}/hooks/lw.mjs" reopen <plan|test> "<reason>"` (it sets the header `stage:` line, and `plan: draft` for plan; if it prints `"header": false`, set those lines by hand), record the decision, and continue with `/loopwright-plan` or `/loopwright-test` as the target says.
40
+ Fix task: write the report's `Root cause:` line to `## Root cause` (`node "{{LW_HOME}}/hooks/lw.mjs" section "Root cause" --set`, the text on stdin through a quoted heredoc). A root cause that differs from the plan's hypothesis is a `Deviation`, handled in step 4.
41
+ 4. `Deviations` not "none" → run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "deviations in build"` (so the stop gate lets you end the turn), then show each to the user before Review, one at a time, in plain words following the rules file (what the implementer did differently from the plan, and why; never the raw report text), and ask (Claude: `AskUserQuestion`; Codex: numbered text, then end the turn). After the answers, run `node "{{LW_HOME}}/hooks/lw.mjs" resume`. The user either accepts it (record it as a decision the way Going back does, below), wants it fixed (run `node "{{LW_HOME}}/hooks/lw.mjs" stage build` first, so a `reopen` the implementer runs on its own does not directly follow the `resume` and is not counted as the user's choice; then spawn the `loopwright-implementer` subagent and wait for its result again, with the deviation as the finding), or wants to go back: offer that when the deviation needs a changed decision or locked test. Going back: directly after `resume`, run `node "{{LW_HOME}}/hooks/lw.mjs" reopen <plan|test> "<reason>"` (it sets the header `stage:` line, and `plan: draft` for plan; if it prints `"header": false`, run `set stage <plan|test>` and, for plan, `set plan draft`), record the decision with `node "{{LW_HOME}}/hooks/lw.mjs" add decision --tag asked <<'LW_TEXT'`, the decision on the next line, then `LW_TEXT`, and continue with `/loopwright-plan` or `/loopwright-test` as the target says.
42
42
  5. Go straight to `/loopwright-review`, which runs Simplify before its passes. The stop gate blocks ending the turn in Build without a passing review.
43
43
 
44
44
  ## Rules
@@ -8,13 +8,13 @@ Done runs in this main thread; do not spawn the subagents here. You propose; the
8
8
 
9
9
  ## Setup
10
10
 
11
- Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` unless you already read it in this conversation, and write every message to the user by it.
11
+ Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` and `{{LW_HOME}}/prompts/glossary.md` unless you already read them in this conversation, and write every message to the user by them, using one term for each idea.
12
12
 
13
13
  1. Run every loopwright command from the worktree root: `cd "$(git rev-parse --show-toplevel)"`.
14
14
  2. `node "{{LW_HOME}}/hooks/lw.mjs" brief` → `dir` (`<lw>`), `task`, `verdict`, `config.docsDir` (the main checkout's config; default `docs/agents`). `dir` `null` inside a git repo → no task has started here yet; `lw.mjs start` creates `.loopwright/` with the first task, so continue and `task: null` reports "no active task". Not a git repo → tell the user loopwright must run inside a git repo, stop.
15
15
  3. `task: null` → "no active task": stop. Then `node "{{LW_HOME}}/hooks/lw.mjs" fingerprint`.
16
- - No `verdict.pass: true`, or its `fingerprint` differs from the current one → the code changed since review or never passed: run `/loopwright-review` first. Continue only if the user explicitly says so, and note it in the review log.
17
- 4. `node "{{LW_HOME}}/hooks/lw.mjs" stage done` (it updates the task file header `stage:` line; if it prints `"header": false`, set that line by hand).
16
+ - No `verdict.pass: true`, or its `fingerprint` differs from the current one → the code changed since review or never passed: run `/loopwright-review` first. Continue only if the user explicitly says so, and record that as a decision (`node "{{LW_HOME}}/hooks/lw.mjs" add decision --tag asked <<'LW_TEXT'`, the text on the next line, then `LW_TEXT`).
17
+ 4. `node "{{LW_HOME}}/hooks/lw.mjs" stage done` (it updates the task file header `stage:` line; if it prints `"header": false`, run `node "{{LW_HOME}}/hooks/lw.mjs" set stage done`).
18
18
 
19
19
  ## 1. Knowledge (AGENTS.md)
20
20
 
@@ -29,7 +29,7 @@ If `CLAUDE.md` exists and has no line `@AGENTS.md`, propose adding that import l
29
29
 
30
30
  ## 2. Parked follow-ups
31
31
 
32
- `grep -l "^found while: <this task path>" <lw>/tasks/*.md` lists the stubs parked while this task ran (`status: proposed` ones are still open). For each, draft issue text (title, what and why, `path:line` evidence from its `## Evidence`) and show it to the user. It is shown only: never file it, and write no task paths or ids into it. A stub with `blocks: <this task path>` that is still `proposed` → ask one question: clear the flag (the stub no longer blocks) or note it in the PR.
32
+ `grep -lE "^([^ ]+ )?found while: <this task path>" <lw>/tasks/*.md` lists the stubs parked while this task ran (`status: proposed` ones are still open). For each, draft issue text (title, what and why, `path:line` evidence from its `## Evidence`) and show it to the user. It is shown only: never file it, and write no task paths or ids into it. A stub with `blocks: <this task path>` that is still `proposed` → ask one question: clear the flag (the stub no longer blocks; `node "{{LW_HOME}}/hooks/lw.mjs" set blocks --unset --file tasks/<stub>.md`) or note it in the PR.
33
33
 
34
34
  In a linked worktree, its `status: proposed` stubs are deleted along with the worktree. List them and offer one question: move them to the main checkout with `node "{{LW_HOME}}/hooks/lw.mjs" carry` (it copies each into the main checkout's `tasks/` and marks the source `status: moved`; it fails in the main checkout, where the stubs already are). Run it only on yes; a stub the user keeps here is lost when the worktree is removed, so say so.
35
35
 
@@ -47,12 +47,13 @@ Draft both and show them to the user:
47
47
 
48
48
  When the user says at any question above that something needs fixing, and before Close, offer to go back; do not ask it on every run. Run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "go back from done"` before asking one question, in plain words following the rules file: back to Test, back to Plan, or stay in Done. Recommend Test when only a test or the code changes, Plan when a decision, acceptance criterion or the scope changes.
49
49
  - Stay in Done → run `node "{{LW_HOME}}/hooks/lw.mjs" resume` and continue.
50
- - Plan or Test → run `node "{{LW_HOME}}/hooks/lw.mjs" resume`, append `- Scope change: <reason>` to the review log (the next review starts at round 1 and Simplify runs again), and record the go-back as `D<n> [asked]` with the user's reason. Then run `node "{{LW_HOME}}/hooks/lw.mjs" reopen <plan|test> "<reason>"` (it sets the header `stage:` line, and `plan: draft` for plan; if it prints `"header": false`, set those lines by hand), directly after `resume` with no other `lw.mjs` call between, and only after the user chooses it. Then continue with `/loopwright-plan` or `/loopwright-test`.
50
+ - Plan or Test → run `node "{{LW_HOME}}/hooks/lw.mjs" resume`, run `node "{{LW_HOME}}/hooks/lw.mjs" add scope-change` with the reason on stdin (the next review starts at round 1 and Simplify runs again), and record the go-back with `add decision --tag asked` and the user's reason.
51
+ Then run `node "{{LW_HOME}}/hooks/lw.mjs" reopen <plan|test> "<reason>"` (it sets the header `stage:` line, and `plan: draft` for plan; if it prints `"header": false`, run `set stage <plan|test>` and, for plan, `set plan draft`), directly after `resume` with no other state-changing `lw.mjs` call between (the writer calls above only edit the task file), and only after the user chooses it. Then continue with `/loopwright-plan` or `/loopwright-test`.
51
52
  - Applied AGENTS.md/docs edits and carried stubs are kept, not reverted; tell the user they enter the next review's diff.
52
53
 
53
54
  ## 4. Close
54
55
 
55
- 1. Set `status: done` in the task file header.
56
+ 1. `node "{{LW_HOME}}/hooks/lw.mjs" set status done`.
56
57
  2. `node "{{LW_HOME}}/hooks/lw.mjs" done` (removes this worktree's machine state; the task file stays).
57
58
  3. Tell the user the work is ready to commit, including any approved AGENTS.md/docs changes.
58
59
 
@@ -8,7 +8,7 @@ Writes a walkthrough of a codebase (or one folder, `/loopwright-explore services
8
8
 
9
9
  ## Setup
10
10
 
11
- Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` unless you already read it in this conversation, and write every message to the user by it.
11
+ Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` and `{{LW_HOME}}/prompts/glossary.md` unless you already read them in this conversation, and write every message to the user by them, using one term for each idea.
12
12
 
13
13
  1. Run every loopwright command from the worktree root: `cd "$(git rev-parse --show-toplevel)"`.
14
14
  2. `node "{{LW_HOME}}/hooks/lw.mjs" dir` → `<lw>`. `null` inside a git repo → no task has started here yet; `lw.mjs explore` creates `.loopwright/`, so continue. Not a git repo → tell the user loopwright must run inside a git repo, stop.
@@ -8,12 +8,12 @@ Entry for bug fixes. It reuses Plan, Test, Build, Review and Done with `kind: fi
8
8
 
9
9
  ## Setup
10
10
 
11
- Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` unless you already read it in this conversation, and write every message to the user by it.
11
+ Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` and `{{LW_HOME}}/prompts/glossary.md` unless you already read them in this conversation, and write every message to the user by them, using one term for each idea.
12
12
 
13
13
  1. Run every loopwright command from the worktree root: `cd "$(git rev-parse --show-toplevel)"`.
14
14
  2. `node "{{LW_HOME}}/hooks/lw.mjs" dir` prints the `.loopwright` directory (`<lw>` below). `null` inside a git repo → no task has started here yet; `lw.mjs start` creates `.loopwright/`, so continue with a new task. Not a git repo → tell the user loopwright must run inside a git repo, stop.
15
15
  3. `node "{{LW_HOME}}/hooks/lw.mjs" status`. "no active task" → this worktree is free; the bug is a new goal, so run "Goal intake" below before Steps (a related task in another worktree is not started again here). It prints a task → this worktree is occupied; follow "Goal intake" below instead of starting a second task here.
16
- 4. Hooks check: `grep -l "loopwright/hooks/" .claude/settings.json .codex/config.toml .junie/config.json ~/.claude/settings.json ~/.codex/config.toml ~/.junie/config.json 2>/dev/null`. No match → warn the user once: "loopwright hooks are not installed, so nothing stops the code writer from editing the frozen tests (locked tests), nothing keeps the agent from stopping with work unfinished (stop gate), and a shortened conversation loses track of the task (context restore); run `npx loopwright init` to install them." Continue unless the user objects.
16
+ 4. Hooks check: `grep -l "loopwright/hooks/" .claude/settings.json .codex/config.toml .junie/config.json ~/.claude/settings.json ~/.codex/config.toml ~/.junie/config.json 2>/dev/null`. No match → warn the user once: "loopwright hooks are not installed, so nothing stops the implementer from editing the locked tests, nothing keeps the agent from stopping with work unfinished (stop gate), and a shortened conversation loses track of the task (context restore); run `npx loopwright init` to install them." Continue unless the user objects.
17
17
 
18
18
  ## Goal intake
19
19
 
@@ -8,21 +8,21 @@ Runs the stage skills in order for the confirmed tier and resumes where a task l
8
8
 
9
9
  ## Setup
10
10
 
11
- Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` unless you already read it in this conversation, and write every message to the user by it.
11
+ Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` and `{{LW_HOME}}/prompts/glossary.md` unless you already read them in this conversation, and write every message to the user by them, using one term for each idea.
12
12
 
13
13
  1. Run every loopwright command from the worktree root: `cd "$(git rev-parse --show-toplevel)"`.
14
14
  2. `node "{{LW_HOME}}/hooks/lw.mjs" dir` → `<lw>`. `null` inside a git repo → no task has started here yet; `lw.mjs start` creates `.loopwright/` with the first task, so continue. Not a git repo → tell the user loopwright must run inside a git repo, stop.
15
- 3. Hooks check: `grep -l "loopwright/hooks/" .claude/settings.json .codex/config.toml .junie/config.json ~/.claude/settings.json ~/.codex/config.toml ~/.junie/config.json 2>/dev/null`. No match → warn the user once: "loopwright hooks are not installed, so nothing stops the code writer from editing the frozen tests (locked tests), nothing keeps the agent from stopping with work unfinished (stop gate), and a shortened conversation loses track of the task (context restore); run `npx loopwright init` to install them." Continue unless the user objects. In Codex, hooks also need approval via `/hooks`.
15
+ 3. Hooks check: `grep -l "loopwright/hooks/" .claude/settings.json .codex/config.toml .junie/config.json ~/.claude/settings.json ~/.codex/config.toml ~/.junie/config.json 2>/dev/null`. No match → warn the user once: "loopwright hooks are not installed, so nothing stops the implementer from editing the locked tests, nothing keeps the agent from stopping with work unfinished (stop gate), and a shortened conversation loses track of the task (context restore); run `npx loopwright init` to install them." Continue unless the user objects. In Codex, hooks also need approval via `/hooks`.
16
16
  4. Junie: if a `loopwright-<role>` subagent fails because its configured model is not available to the user, spawn it again without `model` and `reasoningLevel` (Junie's default); this is not an error to report.
17
17
 
18
18
  ## Resume
19
19
 
20
20
  `node "{{LW_HOME}}/hooks/lw.mjs" status`:
21
21
  - Prints a task, and the user gave a new goal → the worktree is occupied: follow "Goal intake" below, never continue the task unasked. Prints a task, and no goal or the goal is that task → read `<lw>/<task>` and continue at its `stage` (plan: run `loopwright-plan`, which resumes the open plan; review: count rounds from the review log).
22
- - "no active task" → `grep -l "^status: active" <lw>/tasks/*.md`.
22
+ - "no active task" → `grep -lE "^([^ ]+ )?status: active" <lw>/tasks/*.md`.
23
23
  - One or more files → ask the user which one (or a new task). For the chosen file, offer to rebuild state from it: `node "{{LW_HOME}}/hooks/lw.mjs" start tasks/<file>.md --base <base commit from its header>`, then `node "{{LW_HOME}}/hooks/lw.mjs" stage <stage from its header>`. Locked-test hashes are lost with the state: if the task already has acceptance tests and is past Test, tell the user; re-lock the test files named in its AC lines (`stage test`, `lock <files>`, then `stage <stage>`) only if the user confirms they are unchanged.
24
24
  - None, or the user wants a new task → continue below.
25
- - Also list stubs parked by `/loopwright-park` (`status: proposed` in `lw.mjs tasks`, from any worktree; `grep -l "^status: proposed" <lw>/tasks/*.md` lists this worktree's). Offer each as start, drop, or a new task instead. Start → run `loopwright-plan` on it as in that skill ("Parked stubs"); a stub that sits in another worktree starts in a new worktree instead (`lw.mjs worktree "<title>" --stub <absolute path>`, then print the start command). Drop → set `status: dropped` in the stub; never delete it.
25
+ - Also list stubs parked by `/loopwright-park` (`status: proposed` in `lw.mjs tasks`, from any worktree; `grep -lE "^([^ ]+ )?status: proposed" <lw>/tasks/*.md` lists this worktree's). Offer each as start, drop, or a new task instead. Start → run `loopwright-plan` on it as in that skill ("Parked stubs"); a stub that sits in another worktree starts in a new worktree instead (`lw.mjs worktree "<title>" --stub <absolute path>`, then print the start command). Drop → run `node "{{LW_HOME}}/hooks/lw.mjs" set status dropped --file <stub path>`, where the path is the stub's worktree from `lw.mjs tasks` + `/.loopwright/` + its task (`--file tasks/<stub>.md` only finds this worktree's stubs); never delete it.
26
26
  - An `olderLayout` entry listed under this worktree is a task from before tasks were kept per worktree: offer `node "{{LW_HOME}}/hooks/lw.mjs" adopt <task>` to copy it and its state (with locks) in. Nothing moves or is deleted unasked.
27
27
  - No stubs and no task, or the user wants a new task → run "Goal intake" below for the user's goal, then start at Plan with the goal or spec path.
28
28
 
@@ -50,7 +50,7 @@ Follow each stage skill in turn (Claude Code `/loopwright-<stage>`, Codex `$loop
50
50
  - standard (and any fix): `loopwright-plan` → `loopwright-test` → `loopwright-build` → `loopwright-review` → `loopwright-done`
51
51
  - large: `loopwright-plan` → for each slice in order: `loopwright-test` → `loopwright-build` → `loopwright-review` → then one whole-branch `loopwright-review` → `loopwright-done`
52
52
  - A fix (`kind: fix` in the task file header; set by `/loopwright-fix`, or by Plan after the user agrees to run a bug-like goal as a fix) runs `loopwright-test` at every tier: a small fix is never built without a locked repro test. Large keeps its slice loop.
53
- - Going back is the user's choice only: at a deviation, an undecided review finding, or a fix the user raises at Done, run `node "{{LW_HOME}}/hooks/lw.mjs" reopen <plan|test> "<reason>"` (plan or test; accepted only after Build began; it sets the header `stage:` line, and `plan: draft` for plan; if it prints `"header": false`, set those lines by hand), then follow the stage skill it names. Locked tests may then be edited by the tester in Test and are re-locked.
53
+ - Going back is the user's choice only: at a deviation, an undecided review finding, or a fix the user raises at Done, run `node "{{LW_HOME}}/hooks/lw.mjs" reopen <plan|test> "<reason>"` (plan or test; accepted only after Build began; it sets the header `stage:` line, and `plan: draft` for plan; if it prints `"header": false`, run `set stage <plan|test>` and, for plan, `set plan draft`), then follow the stage skill it names. Locked tests may then be edited by the tester in Test and are re-locked.
54
54
  - A failed review returns to `loopwright-build` and then `loopwright-review`, up to the task's fix-round cap.
55
55
 
56
56
  A "fresh context" answer (at the plan confirmation, or at a slice boundary) ends the turn after the stage is advanced; the next session resumes from `status` and the task file, as in Resume.
@@ -8,7 +8,7 @@ Captures work found mid-task (call it B) as a stub, so the current task (A) keep
8
8
 
9
9
  ## Setup
10
10
 
11
- Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` unless you already read it in this conversation, and write every message to the user by it.
11
+ Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.md` and `{{LW_HOME}}/prompts/glossary.md` unless you already read them in this conversation, and write every message to the user by them, using one term for each idea.
12
12
 
13
13
  1. Run every loopwright command from the worktree root: `cd "$(git rev-parse --show-toplevel)"`.
14
14
  2. `node "{{LW_HOME}}/hooks/lw.mjs" dir` → `<lw>`. `null` inside a git repo → no task has started here yet; `lw.mjs park` creates `.loopwright/`, so continue. Not a git repo → tell the user loopwright must run inside a git repo, stop.
@@ -19,7 +19,15 @@ Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.m
19
19
  1. Restate B for the user to edit: a title, a one-paragraph goal, and evidence as `path:line` leads from what you already saw. No scouting: do not read more code to fill this in.
20
20
  2. Ask one question, "Does this block the current task?", recommendation "no" (Claude: `AskUserQuestion`; Codex: numbered text). It needs an active task; with none, skip it.
21
21
  3. Run `node "{{LW_HOME}}/hooks/lw.mjs" park "<title>"`, adding `--blocks` when the answer is yes and `--kind fix` when B is a bug. It prints `{stub, foundWhile, blocks}`.
22
- 4. Write the agreed goal under `## Goal` and the evidence under `## Evidence` of `<lw>/<stub>`.
22
+ 4. Write the agreed goal and the evidence into the stub, the text on stdin through a quoted heredoc (pick a delimiter that does not appear alone on a line in the text):
23
+ ```bash
24
+ node "{{LW_HOME}}/hooks/lw.mjs" section Goal --set --file <stub> <<'LW_TEXT'
25
+ <goal>
26
+ LW_TEXT
27
+ node "{{LW_HOME}}/hooks/lw.mjs" section Evidence --set --file <stub> <<'LW_TEXT'
28
+ <evidence>
29
+ LW_TEXT
30
+ ```
23
31
  5. Blocking → suggest running B first in a new worktree (`node "{{LW_HOME}}/hooks/lw.mjs" worktree "<title>" --stub <stub>` moves the stub there; print the start command as `loopwright-flow` describes under "Goal intake"), and leave A as it is.
24
32
  6. Tell the user the stub path (it lives in this worktree's `.loopwright/`) and that it is listed under A's `## Follow-ups`. Resume A where it was.
25
33