loopwright 0.1.1 → 0.1.3

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.
@@ -13,7 +13,7 @@ const NEXT = {
13
13
  };
14
14
 
15
15
  function goalParagraph(text) {
16
- const lines = text.split('\n');
16
+ const lines = text.split(/\r?\n/);
17
17
  const i = lines.findIndex((l) => /^#{1,6}\s*goal\b/i.test(l.trim()));
18
18
  if (i === -1) return [];
19
19
  const out = [];
@@ -33,7 +33,7 @@ exitIfHooksOff();
33
33
  try {
34
34
  const tool = process.argv.includes('--tool') ? process.argv[process.argv.indexOf('--tool') + 1] : 'claude';
35
35
  const input = await readStdinJson();
36
- const cwd = input.cwd || process.cwd();
36
+ const cwd = input.project_path || input.cwd || process.cwd();
37
37
  const dir = loopwrightDir(cwd);
38
38
  if (!dir) allow();
39
39
  const state = readState(dir, worktreeId(cwd));
@@ -45,18 +45,23 @@ try {
45
45
  const text = readFileSync(file, 'utf8');
46
46
  lines.push(...goalParagraph(text));
47
47
  lines.push(`Stage: ${state.stage}`);
48
- lines.push(...text.split('\n').filter((l) => l.startsWith('- D')));
48
+ lines.push(...text.split(/\r?\n/).filter((l) => l.startsWith('- D')));
49
49
  } else {
50
50
  lines.push(`Stage: ${state.stage}`);
51
51
  }
52
- if (state.awaitingUser) lines.push(`Waiting on the user: ${state.awaitingUser} — do not proceed until they answer; then run lw.mjs resume.`);
52
+ if (state.awaitingUser)
53
+ lines.push(
54
+ `Waiting on the user: ${state.awaitingUser} — do not proceed until they answer; then run lw.mjs resume.`,
55
+ );
53
56
  else lines.push(NEXT[state.stage] ?? NEXT.plan);
54
57
  const body = lines.slice(0, 40);
55
58
  if (lines.length > 40) body[39] = lines[lines.length - 1];
56
59
  const out = body.join('\n');
57
60
 
58
61
  if (tool === 'codex') {
59
- process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName: 'SessionStart', additionalContext: out } }) + '\n');
62
+ process.stdout.write(
63
+ JSON.stringify({ hookSpecificOutput: { hookEventName: 'SessionStart', additionalContext: out } }) + '\n',
64
+ );
60
65
  } else {
61
66
  process.stdout.write(out + '\n');
62
67
  }
@@ -1,6 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  // Stop hook: block stopping in build/review without a passing review for the current code.
3
- import { allow, exitIfHooksOff, deny, failOpen, fingerprint, loopwrightDir, readState, readStdinJson, worktreeId, writeState } from './lib.mjs';
3
+ import {
4
+ allow,
5
+ exitIfHooksOff,
6
+ deny,
7
+ failOpen,
8
+ fingerprint,
9
+ loopwrightDir,
10
+ readState,
11
+ readStdinJson,
12
+ worktreeId,
13
+ writeState,
14
+ } from './lib.mjs';
4
15
 
5
16
  const CAP = 3;
6
17
 
@@ -8,7 +19,7 @@ exitIfHooksOff();
8
19
 
9
20
  try {
10
21
  const input = await readStdinJson();
11
- const cwd = input.cwd || process.cwd();
22
+ const cwd = input.project_path || input.cwd || process.cwd();
12
23
  const dir = loopwrightDir(cwd);
13
24
  if (!dir) allow();
14
25
  const id = worktreeId(cwd);
@@ -29,9 +40,17 @@ try {
29
40
  allow();
30
41
  }
31
42
  state.stopBlocks = blocks + 1;
32
- (state.history ??= []).push({ event: 'stop-blocked', detail: String(state.stopBlocks), at: new Date().toISOString() });
43
+ (state.history ??= []).push({
44
+ event: 'stop-blocked',
45
+ detail: String(state.stopBlocks),
46
+ at: new Date().toISOString(),
47
+ });
33
48
  writeState(dir, id, state);
34
- deny('', '', 'loopwright: no passing review for the current code. Run /loopwright-review (or finish the fix loop) before stopping.');
49
+ deny(
50
+ '',
51
+ '',
52
+ 'loopwright: no passing review for the current code. Run /loopwright-review (or finish the fix loop) before stopping.',
53
+ );
35
54
  } catch (err) {
36
55
  failOpen(err);
37
56
  }
@@ -48,6 +48,8 @@ Second pass: only when the caller hands you the implementer's report. Verify eac
48
48
 
49
49
  ## Findings
50
50
 
51
+ Never write task ids (AC, D, S shorthands) into tests, code, comments, commit messages or PR drafts. A task id in the diff is a finding; your own findings may cite them.
52
+
51
53
  Every reported finding has:
52
54
  - `location` — `path:line` (or `path` when file-level, or the command run);
53
55
  - `expectation` — the violated expectation, citing its source (`D3`, `AC2`, `AGENTS.md`, the comment rule, an existing pattern at `path:line`);
@@ -19,7 +19,7 @@ The implementer subagent writes the code. This thread dispatches it and hands th
19
19
  ## Steps
20
20
 
21
21
  1. `node "{{LW_HOME}}/hooks/lw.mjs" stage build`, and set `stage: build` in the task file header.
22
- 2. Now spawn the `loopwright-implementer` subagent and wait for its result. The prompt contains only:
22
+ 2. Now spawn the `loopwright-implementer` subagent and wait for its result. On Claude Code pass `effort` = the output of `node "{{LW_HOME}}/hooks/lw.mjs" effort implementer` on the spawn; if the spawn rejects `effort`, fall back to spawning without it (the agent file's effort applies). The prompt contains only:
23
23
  - the absolute task file path (`<lw>/<task>`);
24
24
  - large tier: "Implement slice S<n> only.";
25
25
  - small tier (no locked tests): "This task has no locked acceptance tests. Write tests covering each acceptance criterion (AC…) as part of your change.";
@@ -31,5 +31,6 @@ The implementer subagent writes the code. This thread dispatches it and hands th
31
31
 
32
32
  ## Rules
33
33
 
34
+ - Never write task ids (AC, D, S shorthands) into tests, code, comments, commit messages or PR drafts.
34
35
  - Never edit locked tests or ask the implementer to. A locked test that looks wrong goes to the user.
35
36
  - Do not run `lw.mjs verdict` here; only Review records verdicts.
@@ -27,9 +27,11 @@ If `CLAUDE.md` exists and has no line `@AGENTS.md`, propose adding that import l
27
27
 
28
28
  ## 2. Commit message and PR description
29
29
 
30
+ Never write task ids (AC, D, S shorthands) into tests, code, comments, commit messages or PR drafts. Describe decisions in words.
31
+
30
32
  Draft both and show them to the user:
31
33
  - Commit: imperative subject ≤ 72 chars; body says why, the key decisions, and the rejected options with the reason.
32
- - PR: summary of intent; decisions and rejected options (`D…`); notable assumptions the reviewer should know; how it was verified (check commands, acceptance tests, review rounds from the log). Do not list the diff file by file.
34
+ - PR: summary of intent; decisions and rejected options; notable assumptions the reviewer should know; how it was verified (check commands, acceptance tests, review rounds from the log). Do not list the diff file by file.
33
35
 
34
36
  ## 3. Close
35
37
 
@@ -10,7 +10,8 @@ Runs the stage skills in order for the confirmed tier and resumes where a task l
10
10
 
11
11
  1. Run every loopwright command from the worktree root: `cd "$(git rev-parse --show-toplevel)"`.
12
12
  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.
13
- 3. Hooks check: `grep -l "loopwright/hooks/" .claude/settings.json .codex/config.toml ~/.claude/settings.json ~/.codex/config.toml 2>/dev/null`. No match → warn the user once: "loopwright hooks are not installed, so locked tests, the stop gate and context restore are not enforced; run `npx loopwright init` to install them." Continue unless the user objects. In Codex, hooks also need approval via `/hooks`.
13
+ 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 locked tests, the stop gate and context restore are not enforced; run `npx loopwright init` to install them." Continue unless the user objects. In Codex, hooks also need approval via `/hooks`.
14
+ 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.
14
15
 
15
16
  ## Resume
16
17
 
@@ -23,7 +23,7 @@ Plan runs in this main thread. You state assumptions; the user decides. Do not e
23
23
 
24
24
  ## 2. Scout
25
25
 
26
- Before writing any assumption, spawn the `loopwright-scout` subagent and wait for its result. Give it only the goal text or the spec path.
26
+ Before writing any assumption, spawn the `loopwright-scout` subagent and wait for its result. Give it only the goal text or the spec path. On Claude Code pass `effort` = the output of `node "{{LW_HOME}}/hooks/lw.mjs" effort scout` on the spawn; if the spawn rejects `effort`, fall back to spawning without it (the agent file's effort applies).
27
27
  Never ask the user a question the repo can answer. If the scout report leaves a repo fact open, look it up yourself or spawn the `loopwright-scout` subagent and wait for its result again with that one question.
28
28
 
29
29
  ## 3. Assumption ledger
@@ -51,6 +51,7 @@ Write the result immediately: accepted → `[batch-confirmed]`, changed by the u
51
51
 
52
52
  In one message, propose and explain each in one line:
53
53
  - **tier**: `small` (one area, few files, low risk; no acceptance-test stage, the implementer writes tests for every AC), `standard` (default; tests first, then build), `large` (several separable parts; split into ordered slices, each run Test → Build → Review, then one whole-branch review).
54
+ - **profile**: `lean` (trivial or mechanical), `balanced` (default; most tasks), `thorough` (cross-module work, risky changes), `deep` (major refactors, complex redesigns). It sets subagent effort for the task; the user confirms. Written as `profile: <name>` in the header; Test, Build and Review read it via `lw.mjs effort <role>`.
54
55
  - **two-pass** review on/off: on when the implementer's claims matter beyond what tests show (performance, migrations, concurrency, external APIs); otherwise off.
55
56
  - **fix-round cap**: default `maxFixRounds` from config; may be lower for small tasks.
56
57
  - **check commands**: exact lint / typecheck / test commands from the scout report.
@@ -74,6 +75,7 @@ status: active
74
75
  stage: plan
75
76
  plan: draft
76
77
  tier: <small|standard|large>
78
+ profile: <lean|balanced|thorough|deep>
77
79
  two-pass: <on|off>
78
80
  fix-round cap: <n>
79
81
  checks: `<lint>` · `<typecheck>` · `<test>`
@@ -11,20 +11,20 @@ Reviewers judge in their own context. This thread dispatches them, merges their
11
11
  1. Run every loopwright command from the worktree root: `cd "$(git rev-parse --show-toplevel)"`.
12
12
  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 and the next step reports "no active task". Not a git repo → tell the user loopwright must run inside a git repo, stop).
13
13
  3. `node "{{LW_HOME}}/hooks/lw.mjs" status` → `task` (relative to `<lw>`) and `baseCommit`. "no active task" → point the user to `/loopwright-flow`, stop.
14
- 4. Read the task file header (`tier`, `two-pass`, `fix-round cap`) and `<lw>/config.json` (`crossModelReview`, `models.crossModelReviewer`; missing → `off`).
14
+ 4. Read the task file header (`tier`, `two-pass`, `fix-round cap`) and `<lw>/config.json` (`crossAgentReview`, `models.crossAgentReviewer`; missing → `off`).
15
15
  5. Scope: small/standard → the task. Large → the first `S<n> [tested]` slice, or `whole` once every slice is `[passed]`.
16
16
  6. Round `n` = number of `- R` lines in `## Review log` for this scope + 1.
17
17
 
18
18
  ## Passes
19
19
 
20
20
  1. `node "{{LW_HOME}}/hooks/lw.mjs" stage review`, and set `stage: review` in the header.
21
- 2. **Blind pass.** Now spawn the `loopwright-reviewer` subagent and wait for its result. Give it only: the absolute task file path, the base commit, and "Follow `{{LW_HOME}}/prompts/reviewer.md`. Blind pass." Large tier: add "Scope: slice S<n> (its ACs; earlier slices passed)" or "Scope: whole-branch review of all slices". Never include the implementer report, chat history or your opinion.
21
+ 2. **Blind pass.** Now spawn the `loopwright-reviewer` subagent and wait for its result. Give it only: the absolute task file path, the base commit, and "Follow `{{LW_HOME}}/prompts/reviewer.md`. Blind pass." Large tier: add "Scope: slice S<n> (its ACs; earlier slices passed)" or "Scope: whole-branch review of all slices". Never include the implementer report, chat history or your opinion. On Claude Code pass `effort` = the output of `node "{{LW_HOME}}/hooks/lw.mjs" effort reviewer` on the spawn; if the spawn rejects `effort`, fall back to spawning without it (the agent file's effort applies). Use the same effort for the second pass.
22
22
  3. **Second pass** (only if `two-pass: on`). Now spawn the `loopwright-reviewer` subagent and wait for its result, with the task file path, the base commit, "Follow `{{LW_HOME}}/prompts/reviewer.md`. Second pass.", and then "Verify the claims in this implementer report:" with the report verbatim. Report no longer available → skip and note it in the log line.
23
- 4. **Cross-model pass** (only if `crossModelReview` is not `off`). `command -v <claude|codex>` fails → skip, note it. Otherwise, from the worktree root, set `PROMPT="Follow {{LW_HOME}}/prompts/reviewer.md. Task file: <abs path>. Base commit: <sha>. Blind pass."` and run (`LOOPWRIGHT_HOOKS=off` keeps loopwright's own hooks, such as the stop gate, out of the headless reviewer session):
24
- - claude (omit `--model` when the model is `inherit`; add one `"Bash(<cmd>:*)"` per check command in the task header; the `lw.mjs` entries allow only the read-only `status`, `check-locks` and `fingerprint`, in the quoted form the reviewer prompt uses and unquoted; the prompt must come after `--` because the tool flags take several values):
25
- `LOOPWRIGHT_HOOKS=off claude -p --model <crossModelReviewer.claude> --output-format json --json-schema "$(cat "{{LW_HOME}}/schemas/verdict.json")" --allowedTools "Read" "Grep" "Glob" "Bash(git diff:*)" "Bash(git status:*)" "Bash(git log:*)" 'Bash(node "{{LW_HOME}}/hooks/lw.mjs" status)' 'Bash(node "{{LW_HOME}}/hooks/lw.mjs" check-locks)' 'Bash(node "{{LW_HOME}}/hooks/lw.mjs" fingerprint)' "Bash(node {{LW_HOME}}/hooks/lw.mjs status)" "Bash(node {{LW_HOME}}/hooks/lw.mjs check-locks)" "Bash(node {{LW_HOME}}/hooks/lw.mjs fingerprint)" "Bash(<check command>:*)" --disallowedTools "Edit" "Write" "MultiEdit" "NotebookEdit" -- "$PROMPT"`
23
+ 4. **Cross-agent pass** (only if `crossAgentReview` is not `off`). `command -v <claude|codex>` fails → skip, note it. Otherwise, from the worktree root, set `PROMPT="Follow {{LW_HOME}}/prompts/reviewer.md. Task file: <abs path>. Base commit: <sha>. Blind pass."` and run (`LOOPWRIGHT_HOOKS=off` keeps loopwright's own hooks, such as the stop gate, out of the headless reviewer session):
24
+ - claude (omit `--model` when the model is `inherit`; add one `"Bash(<cmd>:*)"` per check command in the task header; the `lw.mjs` entries allow only the read-only `status`, `check-locks` and `fingerprint`, in the quoted form the reviewer prompt uses and unquoted; the prompt must come after `--` because the tool flags take several values; `<effort>` is the output of `lw.mjs effort reviewer`; omit `--effort` if that command fails):
25
+ `LOOPWRIGHT_HOOKS=off claude -p --model <crossAgentReviewer.claude> --effort <effort> --output-format json --json-schema "$(cat "{{LW_HOME}}/schemas/verdict.json")" --allowedTools "Read" "Grep" "Glob" "Bash(git diff:*)" "Bash(git status:*)" "Bash(git log:*)" 'Bash(node "{{LW_HOME}}/hooks/lw.mjs" status)' 'Bash(node "{{LW_HOME}}/hooks/lw.mjs" check-locks)' 'Bash(node "{{LW_HOME}}/hooks/lw.mjs" fingerprint)' "Bash(node {{LW_HOME}}/hooks/lw.mjs status)" "Bash(node {{LW_HOME}}/hooks/lw.mjs check-locks)" "Bash(node {{LW_HOME}}/hooks/lw.mjs fingerprint)" "Bash(<check command>:*)" --disallowedTools "Edit" "Write" "MultiEdit" "NotebookEdit" -- "$PROMPT"`
26
26
  The verdict is the top-level `structured_output` field.
27
- - codex (best effort, untested; omit `-m` when the model is `inherit`): `OUT="$(mktemp)"; LOOPWRIGHT_HOOKS=off codex exec --sandbox read-only --output-schema "{{LW_HOME}}/schemas/verdict.json" -o "$OUT" -m <crossModelReviewer.codex> "$PROMPT"`, then read the verdict from `$OUT`.
27
+ - codex (best effort, untested; omit `-m` when the model is `inherit`): `OUT="$(mktemp)"; LOOPWRIGHT_HOOKS=off codex exec --sandbox read-only --output-schema "{{LW_HOME}}/schemas/verdict.json" -o "$OUT" -m <crossAgentReviewer.codex> "$PROMPT"`, then read the verdict from `$OUT`.
28
28
  Any error, timeout or unparseable output → skip and note it. This pass never blocks on its own failure. A check-command failure reported only by this pass that looks sandbox-caused (permission denied, read-only filesystem) is noted in the log, not counted as blocking.
29
29
  5. A subagent reply that is not one JSON verdict → dispatch it once more asking for only the JSON; still invalid → stop and show the user.
30
30
 
@@ -19,7 +19,7 @@ The tester writes acceptance tests from the confirmed ACs and locks them. This t
19
19
  ## Steps
20
20
 
21
21
  1. `node "{{LW_HOME}}/hooks/lw.mjs" stage test`, and set `stage: test` in the task file header.
22
- 2. Now spawn the `loopwright-tester` subagent and wait for its result. Give it only the absolute task file path (`<lw>/<task>`) and, for large tier, "Write tests only for slice S<n>: AC…". No chat history, no implementation hints.
22
+ 2. Now spawn the `loopwright-tester` subagent and wait for its result. Give it only the absolute task file path (`<lw>/<task>`) and, for large tier, "Write tests only for slice S<n>: AC…". No chat history, no implementation hints. On Claude Code pass `effort` = the output of `node "{{LW_HOME}}/hooks/lw.mjs" effort tester` on the spawn; if the spawn rejects `effort`, fall back to spawning without it (the agent file's effort applies).
23
23
  3. Verify the report:
24
24
  - `node "{{LW_HOME}}/hooks/lw.mjs" status` → `lockedTests` must contain every test file and fixture the report lists. A reported file missing from the locks → run `node "{{LW_HOME}}/hooks/lw.mjs" lock <file>` yourself.
25
25
  - Every in-scope AC has a test, and each failure excerpt shows the expected reason (missing behavior, missing module/export at the named path), not a syntax or setup error. Otherwise spawn the `loopwright-tester` subagent and wait for its result again, naming the problem.
@@ -29,5 +29,6 @@ The tester writes acceptance tests from the confirmed ACs and locks them. This t
29
29
 
30
30
  ## Rules
31
31
 
32
+ - Never write task ids (AC, D, S shorthands) into tests, code, comments, commit messages or PR drafts.
32
33
  - Lock only in this stage, and only the tests for this stage's scope (the task, or the current slice). Never re-lock an existing locked test; if one is wrong, tell the user and let them decide.
33
34
  - Do not read the implementation to judge the tests; the ACs are the contract.