loopwright 0.1.12 → 0.1.13
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 +4 -4
- package/content/hooks/default-config.json +1 -0
- package/content/hooks/lib.mjs +25 -23
- package/content/hooks/lw.mjs +131 -20
- package/content/prompts/blocked-branch.md +9 -0
- package/content/prompts/commit-and-pr.md +55 -0
- package/content/prompts/user-messages.md +1 -1
- package/content/skills/loopwright-done/SKILL.md +19 -11
- package/content/skills/loopwright-flow/SKILL.md +5 -3
- package/content/skills/loopwright-plan/SKILL.md +4 -4
- package/content/skills/loopwright-review/SKILL.md +7 -1
- package/dist/cli.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Then open Claude Code in the repo and run:
|
|
|
33
33
|
/loopwright-flow add rate limiting to the login endpoint
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
The agent scouts your repo, asks you about its high-impact assumptions, and then walks the task through Test, Build, Review and Done, stopping wherever you need to decide.
|
|
36
|
+
The agent scouts your repo, asks you about its high-impact assumptions, and then walks the task through Test, Build, Review and Done, stopping wherever you need to decide. loopwright commits only after you approve, only on a [working branch](docs/configuration.md#where-commits-are-made), and never pushes.
|
|
37
37
|
|
|
38
38
|
`init` writes skills, subagents, hooks and a local `.loopwright/` folder. Commit the result to share it with your team, or use `npx loopwright init --global` to install into your home directory instead. See [Installation](docs/installation.md) for flags and the exact files written.
|
|
39
39
|
|
|
@@ -57,7 +57,7 @@ flowchart TD
|
|
|
57
57
|
review -- "fix-round cap reached" --> you{{"You decide"}}
|
|
58
58
|
review -- "pass" --> done["Done<br/>AGENTS.md proposals, commit and PR draft"]
|
|
59
59
|
slices -.-> done
|
|
60
|
-
done --> commit(["You commit"])
|
|
60
|
+
done --> commit(["You approve the commit"])
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
- **Plan** runs in your session. Plan first restates your goal for you to confirm or correct. A read-only scout then maps the repo, then you answer the high-impact questions one at a time and confirm the plan. Nothing is built before that.
|
|
@@ -65,9 +65,9 @@ flowchart TD
|
|
|
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
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
|
-
- **Done**: proposes `AGENTS.md` updates and drafts the commit and PR message. You approve each change; loopwright never
|
|
68
|
+
- **Done**: proposes `AGENTS.md` updates and drafts the commit and PR message. You approve each change, and then the local commit (also after each slice of a large task); loopwright never pushes.
|
|
69
69
|
|
|
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).
|
|
70
|
+
Each task's goal, decisions, criteria and review log live in `.loopwright/tasks/<date>-<HH-MM>-<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).
|
|
71
71
|
|
|
72
72
|
### Commands
|
|
73
73
|
|
package/content/hooks/lib.mjs
CHANGED
|
@@ -176,29 +176,31 @@ export function sha256File(path) {
|
|
|
176
176
|
export function fingerprint(cwd, baseCommit) {
|
|
177
177
|
const h = createHash('sha256');
|
|
178
178
|
const top = gitTopLevel(cwd);
|
|
179
|
-
const
|
|
180
|
-
'-c',
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const
|
|
179
|
+
const run = (args) =>
|
|
180
|
+
execFileSync('git', ['-c', 'core.quotePath=false', ...args], {
|
|
181
|
+
cwd: top,
|
|
182
|
+
maxBuffer: MAX_BUFFER,
|
|
183
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
184
|
+
});
|
|
185
|
+
const diff = (...extra) =>
|
|
186
|
+
run([
|
|
187
|
+
'diff',
|
|
188
|
+
...extra,
|
|
189
|
+
'--no-color',
|
|
190
|
+
'--no-ext-diff',
|
|
191
|
+
'--no-textconv',
|
|
192
|
+
'--no-renames',
|
|
193
|
+
'--no-relative',
|
|
194
|
+
'--src-prefix=a/',
|
|
195
|
+
'--dst-prefix=b/',
|
|
196
|
+
baseCommit,
|
|
197
|
+
]);
|
|
198
|
+
// Files new since the base are hashed by content like untracked ones, so adding them to the index or committing
|
|
199
|
+
// them never changes the fingerprint.
|
|
200
|
+
h.update(diff('--binary', '--full-index', '--diff-filter=a'));
|
|
201
|
+
const added = diff('--name-only', '-z', '--diff-filter=A').toString().split('\0');
|
|
202
|
+
const others = run(['ls-files', '--others', '--exclude-standard', '-z']).toString().split('\0');
|
|
203
|
+
const files = [...new Set([...added, ...others])].filter(Boolean).sort();
|
|
202
204
|
for (const f of files) {
|
|
203
205
|
h.update(f + '\0');
|
|
204
206
|
try {
|
package/content/hooks/lw.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { copyFileSync, existsSync, readFileSync, readdirSync, mkdirSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
6
|
-
import { execFileSync } from 'node:child_process';
|
|
6
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
7
7
|
import { isatty } from 'node:tty';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
9
|
import {
|
|
@@ -402,14 +402,18 @@ function markMoved(file, to) {
|
|
|
402
402
|
);
|
|
403
403
|
}
|
|
404
404
|
|
|
405
|
+
const p2 = (n) => String(n).padStart(2, '0');
|
|
406
|
+
|
|
405
407
|
const today = () => {
|
|
406
408
|
const d = new Date();
|
|
407
|
-
const p2 = (n) => String(n).padStart(2, '0');
|
|
408
409
|
return `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())}`;
|
|
409
410
|
};
|
|
410
411
|
|
|
411
|
-
/** File name (no extension) for a stub: date
|
|
412
|
-
const stubBase = (title) =>
|
|
412
|
+
/** File name (no extension) for a new task file or stub: local date and time, then the title with spaces and path characters dashed. */
|
|
413
|
+
const stubBase = (title) => {
|
|
414
|
+
const d = new Date();
|
|
415
|
+
return `${today()}-${p2(d.getHours())}-${p2(d.getMinutes())}-${title.replace(/\s+/g, '-').replace(/[\\/:*?"<>|]/g, '-')}`;
|
|
416
|
+
};
|
|
413
417
|
|
|
414
418
|
/** Write `tasks/<base>.md`, adding `-2`, `-3`... on a name collision; returns the path relative to `dir`. */
|
|
415
419
|
function writeUnique(dir, base, text) {
|
|
@@ -433,6 +437,13 @@ function stubText(title, kind, goal = '', links = {}) {
|
|
|
433
437
|
return `# ${title}\n\n\`\`\`yaml\n${lines.join('\n')}\n\`\`\`\n\n## ${headings.Goal} Goal\n\n${goal ? `${goal}\n\n` : ''}## ${headings.Evidence} Evidence\n`;
|
|
434
438
|
}
|
|
435
439
|
|
|
440
|
+
/** The branch name a title suggests: lower-case words joined by dashes. */
|
|
441
|
+
const titleSlug = (title) =>
|
|
442
|
+
title
|
|
443
|
+
.toLowerCase()
|
|
444
|
+
.replace(/[^\p{L}\p{N}]+/gu, '-')
|
|
445
|
+
.replace(/^-+|-+$/g, '') || 'task';
|
|
446
|
+
|
|
436
447
|
const refExists = (ref) => {
|
|
437
448
|
try {
|
|
438
449
|
gitOut(['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]);
|
|
@@ -442,6 +453,71 @@ const refExists = (ref) => {
|
|
|
442
453
|
}
|
|
443
454
|
};
|
|
444
455
|
|
|
456
|
+
/** Run gh with a time limit; null when it is missing, fails or times out, so GitHub never blocks a commit. */
|
|
457
|
+
function ghJson(path) {
|
|
458
|
+
const r = spawnSync('gh', ['api', path], { cwd, encoding: 'utf8', timeout: 10_000 });
|
|
459
|
+
if (r.status !== 0) return null;
|
|
460
|
+
try {
|
|
461
|
+
return JSON.parse(r.stdout);
|
|
462
|
+
} catch {
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// https://docs.github.com/en/rest/repos/rules#get-rules-for-a-branch: rule types that stop direct changes to a branch.
|
|
468
|
+
const PUSH_RESTRICTING_RULES = [
|
|
469
|
+
'pull_request',
|
|
470
|
+
'update',
|
|
471
|
+
'required_status_checks',
|
|
472
|
+
'required_deployments',
|
|
473
|
+
'merge_queue',
|
|
474
|
+
];
|
|
475
|
+
|
|
476
|
+
/** Why committing on the current branch is refused, or null when it is a working branch. */
|
|
477
|
+
function blockedBranchReason(branch) {
|
|
478
|
+
if (branch === 'HEAD') return 'a detached HEAD is not a working branch';
|
|
479
|
+
if (branch === 'main' || branch === 'master') return `loopwright never commits on ${branch}`;
|
|
480
|
+
let remoteDefault = null;
|
|
481
|
+
try {
|
|
482
|
+
remoteDefault = gitOut(['symbolic-ref', '--short', 'refs/remotes/origin/HEAD']).replace(/^origin\//, '');
|
|
483
|
+
} catch {
|
|
484
|
+
// No remote or no origin/HEAD: only the built-in names and the config list apply.
|
|
485
|
+
}
|
|
486
|
+
if (branch === remoteDefault) return `${branch} is the default branch`;
|
|
487
|
+
if ((readConfig().protectedBranches ?? []).includes(branch))
|
|
488
|
+
return `${branch} is in protectedBranches in config.json`;
|
|
489
|
+
let url = '';
|
|
490
|
+
try {
|
|
491
|
+
url = gitOut(['remote', 'get-url', 'origin']);
|
|
492
|
+
} catch {
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
const repo = /github\.com[:/]([^/]+\/[^/]+?)(?:\.git)?\/?$/.exec(url)?.[1];
|
|
496
|
+
if (!repo) return null;
|
|
497
|
+
const ref = encodeURIComponent(branch);
|
|
498
|
+
// `protected` is also true for a ruleset of any rule type; `protection.enabled` is false when only rulesets protect it.
|
|
499
|
+
const info = ghJson(`repos/${repo}/branches/${ref}`);
|
|
500
|
+
if (
|
|
501
|
+
(info?.protected === true && info.protection?.enabled !== false) ||
|
|
502
|
+
ghJson(`repos/${repo}/rules/branches/${ref}`)?.some((rule) => PUSH_RESTRICTING_RULES.includes(rule.type))
|
|
503
|
+
)
|
|
504
|
+
return `${branch} is protected on GitHub`;
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** Fails with the reason when the current branch is blocked for commits; call before anything touches git's index. */
|
|
509
|
+
function requireWorkingBranch() {
|
|
510
|
+
const branch = gitOut(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
511
|
+
const reason = blockedBranchReason(branch);
|
|
512
|
+
if (!reason) return;
|
|
513
|
+
const dir = loopwrightDir(cwd);
|
|
514
|
+
const state = dir && readState(dir, worktreeId(cwd));
|
|
515
|
+
const title = state?.task ? readTask(dir, state.task).title : null;
|
|
516
|
+
fail(
|
|
517
|
+
`loopwright: commit refused: ${reason}. Create a working branch with lw.mjs branch (suggested name: ${titleSlug(title ?? '')}), or skip the commit.`,
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
|
|
445
521
|
/**
|
|
446
522
|
* Re-locks and restarts that the history flags for the user's attention, and the ones an `accept-locks` took out.
|
|
447
523
|
* Re-locking an existing lock after a build could launder an implementer's edit; first-time locks in later slices are legitimate.
|
|
@@ -626,17 +702,17 @@ try {
|
|
|
626
702
|
if (force) rest.splice(rest.indexOf('--force'), 1);
|
|
627
703
|
const kind = flag(rest, '--kind') ?? 'feature';
|
|
628
704
|
const profile = flag(rest, '--profile');
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
);
|
|
705
|
+
let task = rest[0];
|
|
706
|
+
// Without a path the title comes on stdin and the state tool names the file.
|
|
707
|
+
const titled = task ? '' : readInput().split('\n')[0].trim();
|
|
708
|
+
if (!task && !titled) fail('loopwright: start: give a task path, or a title on stdin');
|
|
634
709
|
if (kind !== 'feature' && kind !== 'fix') fail(`loopwright: start: kind must be feature or fix, not '${kind}'`);
|
|
635
710
|
if (profile !== undefined && !Object.hasOwn(PROFILES, profile))
|
|
636
711
|
fail(`loopwright: unknown profile '${profile}' (allowed: ${Object.keys(PROFILES).join(', ')})`);
|
|
637
712
|
// A task file belongs to the worktree its header names; starting it elsewhere would split its state.
|
|
638
713
|
const own = loopwrightPath(cwd);
|
|
639
|
-
const header =
|
|
714
|
+
const header =
|
|
715
|
+
own && task && existsSync(join(own, task)) ? readFileSync(join(own, task), 'utf8').split(/^## /m)[0] : '';
|
|
640
716
|
const named = namedWorktree(header)?.path;
|
|
641
717
|
if (named && realpathLoose(named) !== realpathLoose(gitTopLevel(cwd)))
|
|
642
718
|
fail(`loopwright: ${task} belongs to the worktree ${named}; start it there`);
|
|
@@ -644,6 +720,10 @@ try {
|
|
|
644
720
|
const prior = readState(dir, id);
|
|
645
721
|
if (!force && prior) fail('loopwright: task already active (run lw.mjs done first, or start --force)');
|
|
646
722
|
const baseCommit = gitOut(['rev-parse', base]);
|
|
723
|
+
const worktree = gitTopLevel(cwd);
|
|
724
|
+
const branch = gitOut(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
725
|
+
const fill = { profile, worktree: `${worktree} (branch ${branch})`, base: baseCommit };
|
|
726
|
+
if (!task) task = writeUnique(dir, stubBase(titled), fillTask(skeleton(titled, kind), fill));
|
|
647
727
|
const baseMoved = prior?.baseCommit !== baseCommit;
|
|
648
728
|
// Locked tests out of step with their lock now that the base moves, that the commits it moves over touched:
|
|
649
729
|
// the pull's files, fixed here so a later edit of a test that matched its lock is never taken for a pull.
|
|
@@ -660,8 +740,8 @@ try {
|
|
|
660
740
|
pulledSnapshot: pulledSnapshot?.length ? pulledSnapshot : undefined,
|
|
661
741
|
baseMovedAt: baseMoved ? (prior?.history?.length ?? 0) : prior.baseMovedAt,
|
|
662
742
|
answeredHead: prior?.answeredHead,
|
|
663
|
-
worktree
|
|
664
|
-
branch
|
|
743
|
+
worktree,
|
|
744
|
+
branch,
|
|
665
745
|
// A forced restart keeps the audit trail and the lock records, so a locked test edited
|
|
666
746
|
// during Build cannot be re-baselined unnoticed.
|
|
667
747
|
lockedTests: Array.isArray(prior?.lockedTests) ? prior.lockedTests : [],
|
|
@@ -673,14 +753,13 @@ try {
|
|
|
673
753
|
// A file that is missing (the title comes on stdin) or a proposed stub becomes a task file at Plan; any other
|
|
674
754
|
// file is left alone except for the base commit line of a forced restart.
|
|
675
755
|
const file = join(dir, task);
|
|
676
|
-
const fill = { profile, worktree: `${state.worktree} (branch ${state.branch})`, base: baseCommit };
|
|
677
756
|
const title = existsSync(file) ? '' : readInput().split('\n')[0].trim();
|
|
678
757
|
const proposed = settingValue(header, 'status') === 'proposed';
|
|
679
758
|
if (title) writeFileAtomic(file, fillTask(skeleton(title, kind), fill));
|
|
680
759
|
else if (proposed) rewriteTask(file, (t) => fillTask(t, fill));
|
|
681
760
|
else if (force) setHeader(file, 'base commit', baseCommit);
|
|
682
761
|
writeState(dir, id, state);
|
|
683
|
-
if (title || proposed) refreshTaskFile(file, state);
|
|
762
|
+
if (title || proposed || titled) refreshTaskFile(file, state);
|
|
684
763
|
out(state);
|
|
685
764
|
break;
|
|
686
765
|
}
|
|
@@ -861,6 +940,42 @@ try {
|
|
|
861
940
|
out({ fingerprint: fingerprint(cwd, state.baseCommit) });
|
|
862
941
|
break;
|
|
863
942
|
}
|
|
943
|
+
case 'commit': {
|
|
944
|
+
requireWorkingBranch();
|
|
945
|
+
const names = (...args) => gitOut(['-c', 'core.quotePath=false', 'diff', '--name-only', ...args]);
|
|
946
|
+
if (rest.includes('--prepare')) {
|
|
947
|
+
gitOut(['add', '-A']);
|
|
948
|
+
process.stdout.write(names('--cached') + '\n');
|
|
949
|
+
break;
|
|
950
|
+
}
|
|
951
|
+
const message = readInput().trim();
|
|
952
|
+
if (!message) fail('loopwright: commit requires the message on stdin');
|
|
953
|
+
if (!names('--cached')) fail('loopwright: commit has nothing in the index to commit; run commit --prepare first');
|
|
954
|
+
const { dir, id, state } = requireState();
|
|
955
|
+
const before = workingTree(cwd);
|
|
956
|
+
const r = spawnSync('git', ['commit', '-F', '-'], { cwd, encoding: 'utf8', input: message });
|
|
957
|
+
if (r.status !== 0) fail(`loopwright: git commit failed\n${r.stdout}${r.stderr}`.trimEnd());
|
|
958
|
+
// A hook that rewrote a file changed content after the review, so the files it touched are named.
|
|
959
|
+
const rewritten = names(before, workingTree(cwd));
|
|
960
|
+
const commit = gitOut(['rev-parse', 'HEAD']).slice(0, 7);
|
|
961
|
+
note(state, 'commit', commit);
|
|
962
|
+
writeState(dir, id, state);
|
|
963
|
+
process.stdout.write(`committed ${commit}\n`);
|
|
964
|
+
if (rewritten) process.stdout.write(`hooks rewrote files after the review:\n${rewritten}\n`);
|
|
965
|
+
break;
|
|
966
|
+
}
|
|
967
|
+
case 'branch': {
|
|
968
|
+
const { dir, id, state } = requireState();
|
|
969
|
+
const name = rest[0] ?? titleSlug(readTask(dir, state.task).title ?? '');
|
|
970
|
+
if (refExists(`refs/heads/${name}`)) fail(`loopwright: branch: ${name} already exists; give another name`);
|
|
971
|
+
gitOut(['switch', '-c', name]);
|
|
972
|
+
state.branch = name;
|
|
973
|
+
note(state, 'branch', name);
|
|
974
|
+
writeState(dir, id, state);
|
|
975
|
+
headerResult([setHeader(join(dir, state.task), 'worktree', `${gitTopLevel(cwd)} (branch ${name})`)]);
|
|
976
|
+
process.stdout.write(`switched to ${name}\n`);
|
|
977
|
+
break;
|
|
978
|
+
}
|
|
864
979
|
case 'verdict': {
|
|
865
980
|
const result = rest.shift();
|
|
866
981
|
if (result !== 'pass' && result !== 'fail') fail('loopwright: usage: verdict <pass|fail> --round <n>');
|
|
@@ -1069,11 +1184,7 @@ try {
|
|
|
1069
1184
|
base = ['origin/HEAD', 'main', 'master'].find(refExists) ?? 'HEAD';
|
|
1070
1185
|
}
|
|
1071
1186
|
const main = mainWorktreeRoot(cwd);
|
|
1072
|
-
const slug =
|
|
1073
|
-
title
|
|
1074
|
-
.toLowerCase()
|
|
1075
|
-
.replace(/[^\p{L}\p{N}]+/gu, '-')
|
|
1076
|
-
.replace(/^-+|-+$/g, '') || 'task';
|
|
1187
|
+
const slug = titleSlug(title);
|
|
1077
1188
|
let name;
|
|
1078
1189
|
let folder;
|
|
1079
1190
|
for (let n = 1; ; n++) {
|
|
@@ -1344,7 +1455,7 @@ try {
|
|
|
1344
1455
|
}
|
|
1345
1456
|
default:
|
|
1346
1457
|
fail(
|
|
1347
|
-
'loopwright: usage: lw.mjs <dir|start|set|add|mark|edit|section|stage|reopen|lock|check-locks|accept-locks|keep-base|fingerprint|verdict|review-diff|await-user|resume|park|explore|status|config|brief|tasks|adopt|worktree|carry|effort|done>',
|
|
1458
|
+
'loopwright: usage: lw.mjs <dir|start|set|add|mark|edit|section|stage|reopen|lock|check-locks|accept-locks|keep-base|fingerprint|commit|branch|verdict|review-diff|await-user|resume|park|explore|status|config|brief|tasks|adopt|worktree|carry|effort|done>',
|
|
1348
1459
|
);
|
|
1349
1460
|
}
|
|
1350
1461
|
} catch (err) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Blocked branch
|
|
2
|
+
|
|
3
|
+
`lw.mjs commit --prepare` or `commit` refused because the current branch is not a working branch. The message names the branch, the reason and a suggested branch name. Never commit on that branch, and never try to get around the refusal.
|
|
4
|
+
|
|
5
|
+
1. Run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "new branch"`.
|
|
6
|
+
2. Tell the user in plain words following `{{LW_HOME}}/prompts/user-messages.md` why the branch is refused (the reason from the message), and ask one question: create a working branch here and commit there (offer the suggested name; the user may change it), or skip the commit.
|
|
7
|
+
3. After the answer run `node "{{LW_HOME}}/hooks/lw.mjs" resume`.
|
|
8
|
+
- New branch → run `node "{{LW_HOME}}/hooks/lw.mjs" branch <name>`. It switches in place and keeps the changes. A name that is taken fails with its own message: show it and ask for another name, or skip. Then go on with the commit step from `commit --prepare`.
|
|
9
|
+
- Skip → nothing is committed and the changes stay in the working tree. The task goes on: the slice is still marked passed and Done still closes.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# loopwright commit and PR rules
|
|
2
|
+
|
|
3
|
+
How to write a commit message, a PR description and issue (ticket) text, for the main thread at Done and Review. People read them later to review, trace and maintain the change, and long or jargon-heavy text defeats that. The rules for the messages that present these drafts to the user are in `user-messages.md`.
|
|
4
|
+
|
|
5
|
+
## Rules
|
|
6
|
+
|
|
7
|
+
1. **Commit message: imperative subject of 72 characters or less, then a body of about 5 lines.** The body says why the change was made and what it changes. Add a rejected option only when a future reader would otherwise try it again; leave out lists of decisions and rejected options. Why: a reader of `git blame` needs the reason, and a long body hides it.
|
|
8
|
+
2. **PR description: a summary of 1–3 sentences on what changed and why, one or two lines on how it was checked, and the decisions a reviewer would question, one line each.** A section built from task records (tests changed after going back, follow-ups, a fix's root cause and repro test) appears only when it has content; add no assumptions section. Why: a reviewer reads the summary first, and an empty or low-value section makes the PR longer without helping.
|
|
9
|
+
3. **Plain words.** Use none of the terms of the loopwright process that made the change: stage names, review rounds, locked tests and task ids never appear. A change to loopwright itself still names the feature it changes. Name a file, function or command only where a reader needs it to find the change, in backticks. Why: the reader never saw the process, and a name they cannot place is noise.
|
|
10
|
+
4. **Issue text: a title, then what and why in a few lines, with `path:line` evidence.** The same plain words apply, and it names no task file. Why: an issue is picked up by someone who has not seen this work.
|
|
11
|
+
5. **The length targets are soft.** Split or cut a sentence rather than cut meaning. Why: a hard cap makes text choppy, but long text is the problem this file exists to prevent.
|
|
12
|
+
|
|
13
|
+
## Examples
|
|
14
|
+
|
|
15
|
+
**Before (commit message):**
|
|
16
|
+
Add slice commit
|
|
17
|
+
|
|
18
|
+
Implements D2 and D3 after review round 2. Decisions: commit via lw.mjs, never push. Rejected: auto-commit without approval, because the user wants to approve; rejected squashing slices, because history is lost. Locked tests: test/commit.test.ts. AC1-AC4 pass.
|
|
19
|
+
|
|
20
|
+
**After:**
|
|
21
|
+
Commit locally after each slice with the user's approval
|
|
22
|
+
|
|
23
|
+
A large change was left uncommitted until the end, so a failed later slice put earlier work at risk. The new `commit` command commits what is staged and never pushes.
|
|
24
|
+
|
|
25
|
+
**Before (PR description):**
|
|
26
|
+
## Summary
|
|
27
|
+
Implements the commit flow.
|
|
28
|
+
## Key decisions
|
|
29
|
+
D1, D2, D3, D4 (see task file)
|
|
30
|
+
## Rejected options
|
|
31
|
+
Auto-commit; squash.
|
|
32
|
+
## Notable assumptions
|
|
33
|
+
Git is installed.
|
|
34
|
+
## Verification
|
|
35
|
+
Round 1 failed, round 2 passed, locked tests unchanged.
|
|
36
|
+
## Follow-ups
|
|
37
|
+
None.
|
|
38
|
+
|
|
39
|
+
**After:**
|
|
40
|
+
## Summary
|
|
41
|
+
Commit locally after each slice and at the end, with the user's approval. A failed later slice no longer puts earlier work at risk.
|
|
42
|
+
|
|
43
|
+
## Checked
|
|
44
|
+
`npm test` passes, including new tests for the `commit` command.
|
|
45
|
+
|
|
46
|
+
## Decisions
|
|
47
|
+
- The command never pushes; the user pushes after reading the commit.
|
|
48
|
+
|
|
49
|
+
**Before (issue text):**
|
|
50
|
+
Follow-up from task 2026-11-02 AC3: the thing is slow, see task file.
|
|
51
|
+
|
|
52
|
+
**After:**
|
|
53
|
+
Title: Full-repo scan runs on every hook call
|
|
54
|
+
|
|
55
|
+
`content/hooks/lib.mjs:120` lists every tracked file on each call, so a hook takes seconds in a large repo. Cache the list for the length of one hook run.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
How to write every message the main thread shows the user during loopwright work: stage updates, questions, the assumption list, the plan, review findings, deviations, Simplify cuts, Done questions. Read it once per conversation, before the first message to the user.
|
|
4
4
|
|
|
5
|
-
The reader knows neither loopwright nor this code, and every "what do you mean?" costs a full extra turn. Commit messages, PR descriptions and `AGENTS.md` text
|
|
5
|
+
The reader knows neither loopwright nor this code, and every "what do you mean?" costs a full extra turn. Commit messages, PR descriptions and issue text follow `commit-and-pr.md`, and `AGENTS.md` text keeps its own rules; these rules cover the messages that present them. Subagent reports keep their formats; rewrite what you relay from them.
|
|
6
6
|
|
|
7
7
|
## Rules
|
|
8
8
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: loopwright-done
|
|
3
|
-
description: Use after a loopwright task passes review, to propose AGENTS.md knowledge updates, draft the commit message and PR description, and close the task
|
|
3
|
+
description: Use after a loopwright task passes review, to propose AGENTS.md knowledge updates, draft the commit message and PR description, make a local commit the user approves, and close the task.
|
|
4
4
|
---
|
|
5
5
|
# loopwright done
|
|
6
6
|
|
|
7
|
-
Done runs in this main thread; do not spawn the subagents here. You propose; the user approves each change
|
|
7
|
+
Done runs in this main thread; do not spawn the subagents here. You propose; the user approves each change and the commit.
|
|
8
8
|
|
|
9
9
|
## Setup
|
|
10
10
|
|
|
@@ -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 -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.
|
|
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, written by `{{LW_HOME}}/prompts/commit-and-pr.md`. 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
|
|
|
@@ -37,11 +37,10 @@ In a linked worktree, its `status: proposed` stubs are deleted along with the wo
|
|
|
37
37
|
|
|
38
38
|
Never write task ids (AC, D, S shorthands) into tests, code, comments, commit messages or PR drafts. Describe decisions in words.
|
|
39
39
|
|
|
40
|
-
Draft both and show them to the user:
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
- Fix tasks (`kind: fix`): the PR also states the root cause in one line (from `## Root cause`), the repro test name(s) with "failed before, passes after", and the follow-ups from `## Follow-ups`.
|
|
40
|
+
Draft both by `{{LW_HOME}}/prompts/commit-and-pr.md` and show them to the user. Do not list the diff file by file. Run `node "{{LW_HOME}}/hooks/lw.mjs" check-locks`. Sections built from the task record appear only when it has content:
|
|
41
|
+
- Locked tests changed after a reopen: when `relockedAfterReopen` is non-empty, list each with its reason; when `accepted` is non-empty, list each accepted re-lock or restart with its reason there too.
|
|
42
|
+
- `## Follow-ups`: the parked stubs by title and any follow-ups in the task file (still no task paths or ids).
|
|
43
|
+
- Fix tasks (`kind: fix`): the root cause in one line (from `## Root cause`) and the repro test name(s) with "failed before, passes after", and the follow-ups from `## Follow-ups`.
|
|
45
44
|
|
|
46
45
|
## Going back
|
|
47
46
|
|
|
@@ -51,10 +50,19 @@ When the user says at any question above that something needs fixing, and before
|
|
|
51
50
|
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`.
|
|
52
51
|
- Applied AGENTS.md/docs edits and carried stubs are kept, not reverted; tell the user they enter the next review's diff.
|
|
53
52
|
|
|
54
|
-
## 4.
|
|
53
|
+
## 4. Commit
|
|
54
|
+
|
|
55
|
+
Offer a local commit with the message drafted in step 3, in every tier. In a large task it also holds the fixes of the whole-branch review. Run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "commit the work"`, then `node "{{LW_HOME}}/hooks/lw.mjs" commit --prepare` (it runs `git add` for the task's changes and lists the files). Tell the user in plain words following the rules file which files are added to the commit and that `git restore --staged <file>` leaves one out, show the message, and ask one question: commit these files with this message, or not. After the answer run `node "{{LW_HOME}}/hooks/lw.mjs" resume`.
|
|
56
|
+
- Approved → run `node "{{LW_HOME}}/hooks/lw.mjs" commit <<'LW_COMMIT'` with the message on the next lines, then `LW_COMMIT`. It commits exactly what is in git's index and never pushes; tell the user the commit id it prints.
|
|
57
|
+
- Declined → nothing is committed; the files stay in git's index.
|
|
58
|
+
- `commit --prepare` or `commit` refuses because the branch is blocked → follow `{{LW_HOME}}/prompts/blocked-branch.md`.
|
|
59
|
+
- It fails (a git hook or signing rejected the commit) → show git's error and run `await-user "commit failed"`, then ask: retry, skip (the changes stay added and the task goes on) or commit it yourself; run `resume` after the answer. Never skip hooks.
|
|
60
|
+
- The output names files a hook rewrote → tell the user which; their content changed after the review, so Review runs again (run `/loopwright-review`) before Close, then come back here.
|
|
61
|
+
|
|
62
|
+
## 5. Close
|
|
55
63
|
|
|
56
64
|
1. `node "{{LW_HOME}}/hooks/lw.mjs" set status done`.
|
|
57
65
|
2. `node "{{LW_HOME}}/hooks/lw.mjs" done` (removes this worktree's machine state; the task file stays).
|
|
58
|
-
3. Tell the user the
|
|
66
|
+
3. Tell the user what was committed, or that nothing was and the changes wait in git's index, including any approved AGENTS.md/docs changes.
|
|
59
67
|
|
|
60
|
-
|
|
68
|
+
Never push, and never create the PR: the PR description stays a draft for the user. Never delete the task file.
|
|
@@ -64,12 +64,14 @@ When a stage says to spawn the `loopwright-<role>` subagent, spawn the subagent
|
|
|
64
64
|
## Gates: stop and wait for the user
|
|
65
65
|
|
|
66
66
|
- the goal restatement and the effort profile (one prompt) before the scout, each high-impact question, the "run this as a fix?" question for a bug-like goal, the low-impact batch, the tier/settings proposal, and the final plan confirmation;
|
|
67
|
-
- the slice
|
|
67
|
+
- the slice commit question after a large-tier slice review passes (commit the files added to git's index with the shown message, or not), and then the slice-boundary question while a `[todo]` slice remains (continue here or in a fresh context);
|
|
68
|
+
- the new-branch question, when a commit is refused on a blocked branch (create a working branch and commit there, or skip the commit);
|
|
69
|
+
- the commit-failed question, at a slice or at Done, when a commit fails (retry, skip, or commit it yourself);
|
|
68
70
|
- tester `Uncovered`/`Needs` items and implementer `Deviations`;
|
|
69
71
|
- the moved-branch question at the start of Build and Review, when the branch has new commits that are already on the upstream branch (pulled commits, or this task's own);
|
|
70
72
|
- fixes: the no-repro gate (no locked repro test: provide evidence, find the faulty unit, or stop; never continue without one) and, after the final passing review (whole-branch for large), the sibling gate (include siblings in this fix or list them as follow-ups);
|
|
71
73
|
- the Simplify question at the start of Review (which proposed cuts to apply; not asked when there is nothing to cut), each undecided review finding, and the fix-round cap being reached;
|
|
72
74
|
- going back from Done: when the user says at a Done question that something needs fixing, the question back to Plan, back to Test, or stay in Done;
|
|
73
|
-
- each AGENTS.md / docs change,
|
|
75
|
+
- each AGENTS.md / docs change, the commit message and PR draft, and the commit question at Done (commit with that message, or not).
|
|
74
76
|
|
|
75
|
-
In Test (no-repro gate), Build, Review and Done (going back), run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "<reason>"` before asking and `resume` after the answer, as those skills say; otherwise the stop gate pushes you past the gate. Never answer a gate yourself or treat silence as approval.
|
|
77
|
+
In Test (no-repro gate), Build, Review and Done (the commit questions, going back), run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "<reason>"` before asking and `resume` after the answer, as those skills say; otherwise the stop gate pushes you past the gate. Never answer a gate yourself or treat silence as approval. Commit only through the commit steps in Review and Done, after the user approves; never push.
|
|
@@ -15,7 +15,7 @@ Before your first message to the user, read `{{LW_HOME}}/prompts/user-messages.m
|
|
|
15
15
|
3. `node "{{LW_HOME}}/hooks/lw.mjs" status`. "no active task" → this worktree is free; a new goal still goes through "Goal intake" below first (a related task in another worktree is not started again here), then continue with a new task. If it prints a task, read `<lw>/<task>`:
|
|
16
16
|
- `stage: plan` and reopened (`status` `history` has a `reopen` event after the last `stage build` event; that event's `reason` says why) → this is the same task returning to Plan for added scope, not a second task: keep its decisions, ACs and tests, run sections 2–6 only for what the reason adds or changes (a new slice starts `[todo]`), then section 7. Do not ask whether the plan is abandoned.
|
|
17
17
|
- `stage: plan`, and the user gave a new goal unrelated to this plan → the worktree is occupied: follow "Goal intake" below, do not resume.
|
|
18
|
-
- `stage: plan` → resume this plan: the first `— pending` item under `## Open questions`, else the proposal (step 6), else the confirmation (step 7). If the user says this plan is abandoned, offer to start the new one with `start
|
|
18
|
+
- `stage: plan` → resume this plan: the first `— pending` item under `## Open questions`, else the proposal (step 6), else the confirmation (step 7). If the user says this plan is abandoned, offer to start the new one with `start --force` and the new goal's title on stdin through a quoted heredoc, no path (the old task file stays).
|
|
19
19
|
- past `plan` → the task is in progress; tell the user to continue it with `/loopwright-flow`. Do not start a second here; a new goal follows "Goal intake".
|
|
20
20
|
4. `node "{{LW_HOME}}/hooks/lw.mjs" config` prints the main checkout's config; read `maxFixRounds` from it (missing key → 3).
|
|
21
21
|
5. `git status --porcelain` not empty → uncommitted changes will be part of the reviewed diff. Ask the user whether to commit/stash them first or include them; record the answer once the task file exists, with `node "{{LW_HOME}}/hooks/lw.mjs" add decision --tag asked <<'LW_TEXT'`, the decision on the next line, then `LW_TEXT`.
|
|
@@ -62,9 +62,9 @@ List every assumption you would otherwise make silently, one line each: `A<n> [h
|
|
|
62
62
|
- **low-impact**: everything else (internal naming, file placement following an existing pattern, minor edge-case choices).
|
|
63
63
|
- Cover: scope in/out, behavior and edge cases, interfaces and paths, error handling, compatibility, how it is tested (no test runner in the repo → high-impact), docs to update, extending an existing mechanism (the scout's `Mechanisms` line) vs adding something new. Behavior that differs by environment, deployment or tenant is high-impact unless it extends a mechanism the scout found.
|
|
64
64
|
|
|
65
|
-
Show the user the whole ledger in one compact message, as a numbered list in plain words following the rules file: each item says what is assumed and what a wrong guess would change, with its label (`A<n>`, a path) in brackets after. The same goes for the decisions whenever you show them: a plain numbered list. The task file keeps its `A<n>`, `D<n>` and `AC<n>` line shapes unchanged, because hooks read them. Then create the task file with `start`, the title on stdin through a quoted heredoc (path
|
|
65
|
+
Show the user the whole ledger in one compact message, as a numbered list in plain words following the rules file: each item says what is assumed and what a wrong guess would change, with its label (`A<n>`, a path) in brackets after. The same goes for the decisions whenever you show them: a plain numbered list. The task file keeps its `A<n>`, `D<n>` and `AC<n>` line shapes unchanged, because hooks read them. Then create the task file with `start`, the title on stdin through a quoted heredoc (no path: the state tool names the file and prints it as `task`; if `dir` printed `null`, this creates `.loopwright/`, so run `dir` again for `<lw>`; a fix adds `--kind fix`):
|
|
66
66
|
```bash
|
|
67
|
-
node "{{LW_HOME}}/hooks/lw.mjs" start
|
|
67
|
+
node "{{LW_HOME}}/hooks/lw.mjs" start --profile <chosen profile> <<'LW_TEXT'
|
|
68
68
|
<title>
|
|
69
69
|
LW_TEXT
|
|
70
70
|
```
|
|
@@ -119,7 +119,7 @@ On "confirm and continue in a fresh context", after the `plan: confirmed` step a
|
|
|
119
119
|
|
|
120
120
|
## Task file
|
|
121
121
|
|
|
122
|
-
Path: `<lw>/tasks/<YYYY-MM-DD>-<readable-title>.md` — today's date and a short title from the goal. Keep meaningful casing (`2026-11-08-add-CLAUDE-to-project.md`); spaces become `-`; replace only filesystem-unsafe characters (`/ \ : * ? " < > |`). If the name exists, append `-2`, `-3`, … before `.md`.
|
|
122
|
+
Path: `<lw>/tasks/<YYYY-MM-DD>-<HH-MM>-<readable-title>.md` — today's date, the local time and a short title from the goal; `start` picks it. Keep meaningful casing (`2026-11-08-14-30-add-CLAUDE-to-project.md`); spaces become `-`; replace only filesystem-unsafe characters (`/ \ : * ? " < > |`). If the name exists, append `-2`, `-3`, … before `.md`.
|
|
123
123
|
One line per entry (a decision's rejected options, a criterion's interface and test go on indented sub-lines); target ≤ ~250 lines. Template:
|
|
124
124
|
|
|
125
125
|
````markdown
|
|
@@ -86,7 +86,13 @@ Large tier: add `--scope S<k>` for a slice and `--scope whole` for the whole-bra
|
|
|
86
86
|
## After a pass
|
|
87
87
|
|
|
88
88
|
- small/standard → `/loopwright-done`.
|
|
89
|
-
- large → run `node "{{LW_HOME}}/hooks/lw.mjs" mark S<n> passed`; a `[todo]` slice remains → ask the question below, then `/loopwright-test` (or the fresh-context steps). When the last slice passes, run this skill again with scope `whole` (the diff against the base commit, all ACs); its fixes go through Build without new tests. Whole-branch pass → `/loopwright-done`.
|
|
89
|
+
- large → after a slice review, offer the slice commit below, then run `node "{{LW_HOME}}/hooks/lw.mjs" mark S<n> passed`; a `[todo]` slice remains → ask the question below, then `/loopwright-test` (or the fresh-context steps). When the last slice passes, run this skill again with scope `whole` (the diff against the base commit, all ACs); its fixes go through Build without new tests. Whole-branch pass → `/loopwright-done`.
|
|
90
|
+
- Large, after a slice review passes (every slice, the last one too; never after the whole-branch review, whose fixes Done commits), before marking the slice `[passed]` and before the question below: offer a local commit. Draft the message by `{{LW_HOME}}/prompts/commit-and-pr.md`. Run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "commit the slice"`, then `node "{{LW_HOME}}/hooks/lw.mjs" commit --prepare` (it runs `git add` for the task's changes and lists the files). Tell the user in plain words following the rules file which files are added to the commit and that `git restore --staged <file>` leaves one out, show the message, and ask one question: commit these files with this message, or not. After the answer run `node "{{LW_HOME}}/hooks/lw.mjs" resume`.
|
|
91
|
+
- Approved → run `node "{{LW_HOME}}/hooks/lw.mjs" commit <<'LW_COMMIT'` with the message on the next lines, then `LW_COMMIT`. It commits exactly what is in git's index and never pushes; tell the user the commit id it prints.
|
|
92
|
+
- Declined → nothing is committed; the files stay in git's index and the next commit includes them.
|
|
93
|
+
- `commit --prepare` or `commit` refuses because the branch is blocked → follow `{{LW_HOME}}/prompts/blocked-branch.md`.
|
|
94
|
+
- It fails (a git hook or signing rejected the commit) → show git's error and run `await-user "commit failed"`, then ask: retry, skip (the changes stay added and the task goes on) or commit it yourself; run `resume` after the answer. Never skip hooks.
|
|
95
|
+
- The output names files a hook rewrote → tell the user which, and since their content changed after the review, Review runs again for this slice (the verdict is stale) before the slice is marked `[passed]`.
|
|
90
96
|
- Large, after marking the slice `[passed]`, and a [todo] slice remains: ask one question, continue here or continue in a fresh context, with the reason in one sentence, stated as a tradeoff: later turns re-read the whole conversation, so a fresh context saves tokens when much of the task remains (several slices left), but the new session rewrites the cache, which can cost more than it saves when little remains; nothing is lost either way because the task file holds the plan. Not asked after the last slice, after a whole-branch review, or on a small or standard task. Run `node "{{LW_HOME}}/hooks/lw.mjs" await-user "<reason>"` before asking and `resume` after the answer. On "continue in a fresh context", in this order:
|
|
91
97
|
1. Write up to five lines of things learned so far that Done may propose for `AGENTS.md`: `node "{{LW_HOME}}/hooks/lw.mjs" section "Notes for Done" --append`, the lines on stdin through a quoted heredoc.
|
|
92
98
|
2. Re-read the task file and add any decision made in this conversation that it is missing, with `add decision`.
|
package/dist/cli.js
CHANGED