loopwright 0.1.10 → 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.
package/README.md CHANGED
@@ -64,7 +64,7 @@ flowchart TD
64
64
  - **Test** (standard, large, and every fix): a tester subagent, which never sees the implementation, writes acceptance tests from your confirmed criteria and locks them.
65
65
  - **Build**: an implementer subagent makes the locked tests pass. Small feature tasks skip Test, so the implementer writes the tests; a fix never skips it.
66
66
  - **Simplify** (standard, large, and every fix): a read-only reviewer proposes behavior-preserving cuts to the diff, each with its net line change and what it gives up. You choose which to apply; nothing changes without your approval, and you are not asked when there is nothing to cut.
67
- - **Review**: a reviewer that starts blind runs your checks, confirms the locked tests are untouched, and reports only proven, high-impact findings. Blocking findings send the task back to Build, up to 3 rounds by default; findings it cannot confirm come to you to fix or dismiss.
67
+ - **Review**: a reviewer that starts blind runs your checks, confirms the locked tests are untouched, and reports only proven, high-impact findings. Blocking findings send the task back to Build, up to 3 rounds by default, and after a fix, later rounds check only what changed; findings it cannot confirm come to you to fix or dismiss.
68
68
  - **Done**: proposes `AGENTS.md` updates and drafts the commit and PR message. You approve each change; loopwright never commits.
69
69
 
70
70
  Each task's goal, decisions, criteria and review log live in `.loopwright/tasks/<date>-<title>.md`. For the large-tier slice loop, step-by-step Plan and Review charts, and every point where loopwright waits for you, see [Workflow in detail](docs/workflow.md).
@@ -91,7 +91,7 @@ Run a single stage, or the whole loop with `flow`. In Codex, use `$` instead of
91
91
  |---|---|---|---|
92
92
  | Skills install | Supported, tested | WIP: installed, not tested end-to-end | WIP: reads `.agents/skills` |
93
93
  | Subagents (scout, tester, implementer, reviewer) | Supported, tested | WIP: installed, not tested end-to-end | WIP: `.junie/agents` |
94
- | Hook enforcement (locked-test guard, stop gate, context reinjection, plus compaction instructions and the question check on Claude Code only) | Supported, tested | WIP: installed, not tested end-to-end | Experimental (`--experimental junie-hooks`, Early Access) |
94
+ | Hook enforcement (locked-test guard, stop gate, context restore, plus compaction instructions and the question check on Claude Code only) | Supported, tested | WIP: installed, not tested end-to-end | Experimental (`--experimental junie-hooks`, Early Access) |
95
95
  | Plain-words rules for messages to you | Supported | WIP: installed, not tested end-to-end | WIP: reads `.agents/skills` |
96
96
  | Structured questions | `AskUserQuestion` | Plain-text fallback (numbered options) | Plain-text fallback |
97
97
  | Cross-agent review (as the reviewer) | Supported, tested | WIP: untested | Not supported |
@@ -106,7 +106,7 @@ Codex and Junie CLI support is work in progress.
106
106
 
107
107
  - [Installation](docs/installation.md): flags, files written, update, uninstall, worktrees.
108
108
  - [Configuration](docs/configuration.md): models, fix rounds, cross-agent review, effort profiles (`lean`, `balanced`, `thorough`, `deep`; set with `--profile`), experimental features.
109
- - [Workflow in detail](docs/workflow.md): the full flow with charts: slices, the Plan and Review steps, and where it waits for you.
109
+ - [Workflow in detail](docs/workflow.md): the full flow with charts: slices, the Plan and Review stages, and where it waits for you.
110
110
  - [Enforcement and its limits](docs/enforcement.md): what the hooks block, and what they cannot.
111
111
  - [Dogfood checklist](docs/dogfood-checklist.md): a manual end-to-end test run.
112
112
 
@@ -9,7 +9,7 @@ You are the loopwright implementer. You make the smallest change that satisfies
9
9
 
10
10
  The main thread gives you the task file path, and on a fix round the reviewer's Blocking findings. Read the task file fresh every time: goal, decisions (`D…`), acceptance criteria (`AC…`), check commands, locked tests. The task file wins over any summary in your prompt.
11
11
 
12
- Approved simplifications (the main thread lists them verbatim, each approved by the user): apply only those, in place of Step 3's implementing, and add no unit tests. They are exempt from "no unrelated cleanups"; behavior must stay identical. Steps 1, 2 and 4 still run; skip Step 5, your own simplify pass, which could cut what the user did not approve. Write no `Root cause:` line on that run, even on a fix task.
12
+ Approved Simplify cuts (the main thread lists them verbatim, each approved by the user): apply only those, in place of Step 3's implementing, and add no unit tests. They are exempt from "no unrelated cleanups"; behavior must stay identical. Steps 1, 2 and 4 still run; skip Step 5, your own simplify pass, which could cut what the user did not approve. Write no `Root cause:` line on that run, even on a fix task.
13
13
 
14
14
  ## Boundaries
15
15
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: loopwright-reviewer
3
- description: Reads a change against its task file and standards under a procedure file the caller names (a review verdict by default, or a list of proposed simplifications) and returns that procedure's JSON output. Never edits code.
3
+ description: Reads a change against its task file and standards under a procedure file the caller names (a review verdict by default, or a list of proposed Simplify cuts) and returns that procedure's JSON output. Never edits code.
4
4
  tools: Read, Grep, Glob, Bash
5
5
  ---
6
6
  You are the loopwright reviewer, a context separate from the one that wrote the code.
@@ -68,7 +68,7 @@ try {
68
68
  if (locked.size === 0) continue;
69
69
  const rel = repoRelative(top, abs);
70
70
  if (locked.has(rel))
71
- deny('', '', `loopwright: ${rel} is a locked acceptance test. Ask the user before changing it.`);
71
+ deny('PreToolUse', `loopwright: ${rel} is a locked acceptance test. Ask the user before changing it.`);
72
72
  }
73
73
  }
74
74
  allow();
@@ -2,15 +2,21 @@
2
2
  import { execFileSync } from 'node:child_process';
3
3
  import { createHash } from 'node:crypto';
4
4
  import {
5
+ copyFileSync,
5
6
  existsSync,
6
7
  lstatSync,
7
8
  mkdirSync,
9
+ mkdtempSync,
8
10
  readFileSync,
9
11
  readlinkSync,
10
12
  realpathSync,
11
13
  renameSync,
14
+ rmSync,
15
+ statSync,
16
+ utimesSync,
12
17
  writeFileSync,
13
18
  } from 'node:fs';
19
+ import { tmpdir } from 'node:os';
14
20
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
15
21
  import { fileURLToPath } from 'node:url';
16
22
 
@@ -18,10 +24,63 @@ import { fileURLToPath } from 'node:url';
18
24
  export const PROFILES = {
19
25
  lean: { scout: 'low', tester: 'low', implementer: 'low', reviewer: 'medium' },
20
26
  balanced: { scout: 'medium', tester: 'medium', implementer: 'medium', reviewer: 'high' },
21
- thorough: { scout: 'high', tester: 'high', implementer: 'high', reviewer: 'xhigh' },
27
+ thorough: { scout: 'high', tester: 'high', implementer: 'high', reviewer: 'high' },
22
28
  deep: { scout: 'xhigh', tester: 'xhigh', implementer: 'xhigh', reviewer: 'xhigh' },
23
29
  };
24
30
 
31
+ /**
32
+ * Icons in the task file: settings keys, section headings, tags, and progress marks. The plan skill's template uses
33
+ * the same ones (a test pins them equal); `lw.mjs` repairs a missing or wrong icon on the lines it knows.
34
+ * Some carry a variation selector (U+FE0F): compare exact code points.
35
+ */
36
+ export const TASK_FILE_ICONS = {
37
+ settings: {
38
+ kind: '🏷️',
39
+ status: '🚦',
40
+ stage: '📍',
41
+ plan: '📋',
42
+ tier: '📐',
43
+ profile: '🎚️',
44
+ 'two-pass': '👀',
45
+ 'fix-round cap': '🔧',
46
+ checks: '🔬',
47
+ worktree: '🌿',
48
+ 'base commit': '⚓',
49
+ 'found while': '🔗',
50
+ blocks: '⛔',
51
+ },
52
+ headings: {
53
+ Goal: '🎯',
54
+ Decisions: '⚖️',
55
+ Assumptions: '🔎',
56
+ 'Acceptance criteria': '🧪',
57
+ Slices: '🧩',
58
+ 'Review log': '🔁',
59
+ 'Open questions': '❓',
60
+ 'Notes for Done': '🗒️',
61
+ 'Follow-ups': '📌',
62
+ 'Bug report': '🐞',
63
+ 'Root cause': '🌱',
64
+ Evidence: '📎',
65
+ },
66
+ tags: {
67
+ asked: '🙋',
68
+ 'batch-confirmed': '☑️',
69
+ overridden: '✏️',
70
+ confirmed: '☑️',
71
+ todo: '⬜',
72
+ tested: '🧪',
73
+ passed: '✅',
74
+ },
75
+ progress: { finished: '✅', failed: '❌', running: '▶️', paused: '⏸️', back: '↩️' },
76
+ };
77
+
78
+ /** Regex source for a leading icon (and its space) before a settings key, heading name or tag; the line may have none. */
79
+ export const ICON_PREFIX = '(?:[^\\x00-\\x7F]\\S*[ \\t]+)?';
80
+
81
+ /** The first word after `key:` on a settings line, with or without a leading icon; undefined when there is no such line. */
82
+ export const settingValue = (text, key) => new RegExp(`^${ICON_PREFIX}${key}:[ \\t]*(\\S+)`, 'm').exec(text)?.[1];
83
+
25
84
  /** Hooks sit in `<loopwright home>/hooks`, the prompts beside them. */
26
85
  export const USER_MESSAGES_RULES = fileURLToPath(new URL('../prompts/user-messages.md', import.meta.url));
27
86
 
@@ -90,11 +149,11 @@ export function readState(dir, id) {
90
149
  }
91
150
  }
92
151
 
93
- export function writeState(dir, id, state) {
94
- const path = statePath(dir, id);
152
+ /** Write `text` to `path` through a temp file and a rename, so a reader never sees half a file. */
153
+ export function writeFileAtomic(path, text) {
95
154
  mkdirSync(dirname(path), { recursive: true });
96
155
  const tmp = `${path}.${process.pid}.tmp`;
97
- writeFileSync(tmp, JSON.stringify(state, null, 2) + '\n');
156
+ writeFileSync(tmp, text);
98
157
  // Windows: rename fails with EPERM/EBUSY/EACCES while another process briefly holds the target.
99
158
  for (let attempt = 0; ; attempt++) {
100
159
  try {
@@ -107,6 +166,9 @@ export function writeState(dir, id, state) {
107
166
  }
108
167
  }
109
168
 
169
+ export const writeState = (dir, id, state) =>
170
+ writeFileAtomic(statePath(dir, id), JSON.stringify(state, null, 2) + '\n');
171
+
110
172
  export function sha256File(path) {
111
173
  return createHash('sha256').update(readFileSync(path)).digest('hex');
112
174
  }
@@ -152,6 +214,38 @@ export function fingerprint(cwd, baseCommit) {
152
214
  return h.digest('hex');
153
215
  }
154
216
 
217
+ /** Tree id of the working tree as it is now: the files in the user's index (force-added ignored files too) plus
218
+ * untracked files that are not ignored, the same set the fingerprint covers. Built in a temporary index seeded from a
219
+ * copy of the user's index (or HEAD when there is none), so the user's index and working tree are never written. */
220
+ export function workingTree(cwd) {
221
+ const top = gitTopLevel(cwd);
222
+ // A linked worktree's index lives under .git/worktrees/<name>/; git prints the path relative to `top`.
223
+ const userIndex = resolve(top, git(top, ['rev-parse', '--git-path', 'index']));
224
+ const tmp = mkdtempSync(join(tmpdir(), 'lw-index-'));
225
+ const index = join(tmp, 'index');
226
+ const run = (args) =>
227
+ execFileSync('git', args, {
228
+ cwd: top,
229
+ encoding: 'utf8',
230
+ maxBuffer: MAX_BUFFER,
231
+ stdio: ['ignore', 'pipe', 'pipe'],
232
+ env: { ...process.env, GIT_INDEX_FILE: index },
233
+ }).trim();
234
+ try {
235
+ if (existsSync(userIndex)) {
236
+ copyFileSync(userIndex, index);
237
+ // Keep the source mtime: git trusts an entry's stat data unless the entry is as new as the index file
238
+ // (racy check), so a fresh mtime on the copy would hide a same-size edit made just after the entry was written.
239
+ const st = statSync(userIndex);
240
+ utimesSync(index, st.atime, st.mtime);
241
+ } else run(['read-tree', 'HEAD']);
242
+ run(['add', '-A']);
243
+ return run(['write-tree']);
244
+ } finally {
245
+ rmSync(tmp, { recursive: true, force: true });
246
+ }
247
+ }
248
+
155
249
  /** Hooks call this first: LOOPWRIGHT_HOOKS=off (e.g. a headless cross-agent reviewer) disables them silently. */
156
250
  export function exitIfHooksOff() {
157
251
  if (process.env.LOOPWRIGHT_HOOKS === 'off') process.exit(0);
@@ -168,10 +262,24 @@ export function allow() {
168
262
  process.exit(0);
169
263
  }
170
264
 
171
- // Claude and Codex both block via stderr reason + exit 2. The reason must be
172
- // non-empty: Codex ignores exit 2 with empty stderr.
173
- export function deny(_tool, _event, reason) {
265
+ // Claude Code blocks through JSON on stdout, which it shows without the hook's command path
266
+ // (https://code.claude.com/docs/en/hooks.md: PreToolUse permissionDecision, Stop decision control).
267
+ // Codex and Junie block via stderr reason + exit 2; Codex ignores exit 2 with empty stderr, so the reason is never empty.
268
+ export function deny(event, reason) {
174
269
  const text = String(reason ?? '').trim() || 'loopwright: blocked';
270
+ const i = process.argv.indexOf('--tool');
271
+ if (i !== -1 && process.argv[i + 1] === 'claude') {
272
+ process.stdout.write(
273
+ JSON.stringify(
274
+ event === 'Stop'
275
+ ? { decision: 'block', reason: text }
276
+ : {
277
+ hookSpecificOutput: { hookEventName: event, permissionDecision: 'deny', permissionDecisionReason: text },
278
+ },
279
+ ) + '\n',
280
+ );
281
+ process.exit(0);
282
+ }
175
283
  process.stderr.write(text + '\n');
176
284
  process.exit(2);
177
285
  }