loopwright 0.1.1 → 0.1.2
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 +76 -142
- package/content/hooks/default-config.json +8 -2
- package/content/hooks/guard-locked-tests.mjs +7 -2
- package/content/hooks/lib.mjs +9 -1
- package/content/hooks/lw.mjs +32 -4
- package/content/hooks/reinject-context.mjs +1 -1
- package/content/hooks/stop-gate.mjs +1 -1
- package/content/skills/loopwright-build/SKILL.md +1 -1
- package/content/skills/loopwright-flow/SKILL.md +2 -1
- package/content/skills/loopwright-plan/SKILL.md +3 -1
- package/content/skills/loopwright-review/SKILL.md +6 -6
- package/content/skills/loopwright-test/SKILL.md +1 -1
- package/dist/cli.js +187 -38
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,176 +1,110 @@
|
|
|
1
1
|
# loopwright
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Make your AI coding agent plan, test, build and review like a careful team: a **Plan → Test → Build → Review → Done** workflow (Test is skipped for small tasks, and Review loops back to Build until it passes), installed into your repo as skills, subagents and hooks.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Why
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
| Feature | Claude Code | Codex |
|
|
10
|
-
|---|---|---|
|
|
11
|
-
| Skills install | Supported, tested | WIP: installed, not tested end-to-end |
|
|
12
|
-
| Subagents (scout, tester, implementer, reviewer) | Supported, tested | WIP: installed, not tested end-to-end |
|
|
13
|
-
| Hook enforcement (locked-test guard, stop gate, context reinjection) | Supported, tested | WIP: installed, not tested end-to-end |
|
|
14
|
-
| Structured questions | `AskUserQuestion` | Plain-text fallback (numbered options) |
|
|
15
|
-
| Cross-model review (as the reviewer) | Supported, tested | WIP: untested |
|
|
16
|
-
| Global install | Supported, tested | WIP: installed, not tested end-to-end |
|
|
17
|
-
|
|
18
|
-
**Codex support is work in progress.** Its behavior was derived from Codex source and CLI help; no real Codex session has been run against loopwright yet. Expect rough edges.
|
|
19
|
-
|
|
20
|
-
## Install
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npx loopwright init # into the current git repo (commit the result to share it)
|
|
24
|
-
npx loopwright init --global # into your user directories instead
|
|
25
|
-
npx loopwright update # refresh installed files to this version
|
|
26
|
-
npx loopwright uninstall # remove installed files
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Requires Node >= 22.14. Repo mode needs a git repository; `--global` does not.
|
|
30
|
-
|
|
31
|
-
| Flag | Effect |
|
|
32
|
-
|---|---|
|
|
33
|
-
| `--global` | Install into your home directory instead of the repo. Shows the planned changes and asks before touching user config. |
|
|
34
|
-
| `--no-hook` | Skip hook wiring. Skills still work but nothing is enforced. |
|
|
35
|
-
| `--no-symlink` | Do not create the `.claude/skills` symlink. |
|
|
36
|
-
| `--dry-run` | Show what would change without writing. |
|
|
37
|
-
| `--force` | Overwrite conflicts and skip confirmation prompts. |
|
|
38
|
-
| `-v`, `--version` / `-h`, `--help` | Print version / help. |
|
|
39
|
-
|
|
40
|
-
### What gets written
|
|
41
|
-
|
|
42
|
-
Repo install:
|
|
43
|
-
|
|
44
|
-
- `.agents/skills/loopwright-{flow,plan,test,build,review,done}/SKILL.md`, and `.claude/skills` as a symlink to `../.agents/skills` (existing directories or other symlinks are prompted about unless `--force`)
|
|
45
|
-
- `.claude/agents/loopwright-<role>.md` and `.codex/agents/loopwright-<role>.toml` for `scout`, `tester`, `implementer`, `reviewer`
|
|
46
|
-
- `.agents/loopwright/` with `hooks/`, `prompts/reviewer.md`, `schemas/verdict.json`
|
|
47
|
-
- hook wiring (unless `--no-hook`): entries in `.claude/settings.json`, and a `# BEGIN loopwright` ... `# END loopwright` block in `.codex/config.toml`
|
|
48
|
-
- `.loopwright/` (in the main worktree) with its own `.gitignore` (`*`), `config.json`, `manifest.json`, `tasks/`, `state/`
|
|
49
|
-
|
|
50
|
-
In a repo without `.loopwright/` (a global install, or a fresh clone, since `.loopwright/` ignores itself), the first task start creates it: `.gitignore`, `tasks/`, `state/` and a `config.json` seeded from `~/.config/loopwright/config.json` if that exists, else the defaults.
|
|
51
|
-
|
|
52
|
-
Global install writes the equivalents to `~/.agents/skills`, `~/.claude/skills` (copies, not a symlink), `~/.claude/agents`, `~/.codex/agents`, `~/.claude/settings.json`, `~/.codex/config.toml`, and `~/.config/loopwright/` (hooks, prompts, schemas, `manifest.json`). It does not create `~/.config/loopwright/config.json`; that file is optional (see Configuration).
|
|
53
|
-
|
|
54
|
-
## The loop
|
|
7
|
+
Left alone, coding agents:
|
|
55
8
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
5. **Done** (main thread): proposes `AGENTS.md` / `docs/agents/` additions and prunes (each approved individually), and drafts a commit/PR message with the decisions and rejected options. It does not commit.
|
|
9
|
+
- bake silent assumptions into the plan,
|
|
10
|
+
- write tests that fit their own code,
|
|
11
|
+
- grade their own work,
|
|
12
|
+
- forget agreed decisions after context compaction.
|
|
61
13
|
|
|
62
|
-
|
|
14
|
+
loopwright counters each of these:
|
|
63
15
|
|
|
64
|
-
- **
|
|
65
|
-
- **
|
|
66
|
-
- **
|
|
16
|
+
- **Assumption ledger**: every assumption is stated; high-impact ones are asked one at a time.
|
|
17
|
+
- **Isolated contexts**: the tester never sees the implementation; the reviewer starts blind.
|
|
18
|
+
- **Enforced gates**: hooks block edits to locked tests and block finishing without a passing review.
|
|
19
|
+
- **No document sprawl**: one short task file per task, kept locally. Durable lessons go to your `AGENTS.md` only with your approval.
|
|
67
20
|
|
|
68
|
-
|
|
21
|
+
## Quick start
|
|
69
22
|
|
|
70
|
-
|
|
23
|
+
You need Node >= 22.14 and a git repository.
|
|
71
24
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
| `/loopwright-plan` | `$loopwright-plan` | Plan stage |
|
|
76
|
-
| `/loopwright-test` | `$loopwright-test` | Test stage |
|
|
77
|
-
| `/loopwright-build` | `$loopwright-build` | Build stage |
|
|
78
|
-
| `/loopwright-review` | `$loopwright-review` | Review stage |
|
|
79
|
-
| `/loopwright-done` | `$loopwright-done` | Done stage |
|
|
80
|
-
|
|
81
|
-
Task files live in `.loopwright/tasks/<date>-<title>.md`: goal, decisions (tagged asked / batch-confirmed / overridden), assumptions, acceptance criteria, review log, open questions.
|
|
82
|
-
|
|
83
|
-
## Configuration
|
|
84
|
-
|
|
85
|
-
`.loopwright/config.json` is created with these defaults (by `init`, or by the first task start) and never overwritten. `init`/`update` render the model settings into the generated agent files, so re-run `update` after editing.
|
|
86
|
-
|
|
87
|
-
Global installs read `~/.config/loopwright/config.json` if you create it (it is optional and not written by `init --global`): its model settings go into the global agent files, and it seeds the `config.json` of each repo's new `.loopwright/`.
|
|
88
|
-
|
|
89
|
-
```json
|
|
90
|
-
{
|
|
91
|
-
"maxFixRounds": 3,
|
|
92
|
-
"crossModelReview": "off",
|
|
93
|
-
"docsDir": "docs/agents",
|
|
94
|
-
"models": {
|
|
95
|
-
"claude": { "scout": "opus", "tester": "sonnet", "implementer": "sonnet", "reviewer": "opus" },
|
|
96
|
-
"codex": { "scout": "inherit", "tester": "inherit", "implementer": "inherit", "reviewer": "inherit" },
|
|
97
|
-
"crossModelReviewer": { "claude": "opus", "codex": "inherit" }
|
|
98
|
-
}
|
|
99
|
-
}
|
|
25
|
+
```bash
|
|
26
|
+
cd your-repo
|
|
27
|
+
npx loopwright init
|
|
100
28
|
```
|
|
101
29
|
|
|
102
|
-
|
|
103
|
-
- `crossModelReview`: `"off"`, `"codex"` or `"claude"`. When set, the review also runs the same reviewer prompt headlessly through the other CLI (`codex exec` or `claude -p`) and both verdicts must pass. A missing or failing CLI is skipped with a note in the review log; it never blocks.
|
|
104
|
-
- `docsDir`: where Done puts longer standards docs linked from `AGENTS.md`.
|
|
105
|
-
- `models`: per tool and role; tool-native aliases or full IDs, or `inherit` (the session model). Codex also accepts `models.codex.effort.<role>`. Editing generated agent files directly counts as a user modification and is kept on update.
|
|
106
|
-
- Plan runs in your main thread, so it uses your session's model. Start the session on the model you want for planning.
|
|
107
|
-
|
|
108
|
-
## Enforcement and its limits
|
|
109
|
-
|
|
110
|
-
Three hooks (plain Node scripts, no dependencies) are wired by default:
|
|
30
|
+
Then open Claude Code in the repo and run:
|
|
111
31
|
|
|
112
|
-
|
|
113
|
-
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
Limits, stated plainly:
|
|
117
|
-
|
|
118
|
-
- Shell edits (`sed -i`, redirects) are not intercepted. The review re-hashes locked tests and fails on any mismatch; that is the real backstop.
|
|
119
|
-
- State fields such as `awaitingUser` and the history log are tamper-evident, not tamper-proof. A determined agent can write them; the aim is to catch drift, not adversaries.
|
|
120
|
-
- Hooks fail open: if a hook crashes or state is unreadable it warns and allows, so a loopwright bug never bricks your session. Review checks remain authoritative.
|
|
121
|
-
- With `--no-hook`, none of this is enforced.
|
|
122
|
-
- Setting `LOOPWRIGHT_HOOKS=off` in a session's environment turns every loopwright hook into a silent no-op. The cross-model review sets it on the headless `claude -p` / `codex exec` reviewer so that session is not gated.
|
|
32
|
+
```text
|
|
33
|
+
/loopwright-flow add rate limiting to the login endpoint
|
|
34
|
+
```
|
|
123
35
|
|
|
124
|
-
|
|
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. Nothing is committed for you.
|
|
125
37
|
|
|
126
|
-
|
|
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.
|
|
127
39
|
|
|
128
|
-
##
|
|
40
|
+
## How it works
|
|
129
41
|
|
|
130
|
-
|
|
42
|
+
The stages run in order, but the path depends on the task's size (its *tier*) and a failed review loops back to Build.
|
|
131
43
|
|
|
132
|
-
|
|
44
|
+
```mermaid
|
|
45
|
+
flowchart TD
|
|
46
|
+
goal(["Your goal or spec"]) --> plan["Plan<br/>scout the repo, assumption ledger,<br/>you confirm tier, checks and criteria"]
|
|
47
|
+
plan --> tier{"Tier"}
|
|
48
|
+
tier -- "small" --> build
|
|
49
|
+
tier -- "standard" --> test["Test<br/>tester writes and locks acceptance tests"]
|
|
50
|
+
tier -- "large" --> slices["Split into slices<br/>each runs Test, Build, Review,<br/>then one whole-branch review"]
|
|
51
|
+
test --> build["Build<br/>implementer makes the tests pass"]
|
|
52
|
+
build --> review{"Review<br/>separate reviewer: passes?"}
|
|
53
|
+
review -- "blocking findings, rounds left" --> build
|
|
54
|
+
review -- "fix-round cap reached" --> you{{"You decide"}}
|
|
55
|
+
review -- "pass" --> done["Done<br/>AGENTS.md proposals, commit and PR draft"]
|
|
56
|
+
slices -.-> done
|
|
57
|
+
done --> commit(["You commit"])
|
|
58
|
+
```
|
|
133
59
|
|
|
134
|
-
-
|
|
135
|
-
-
|
|
136
|
-
-
|
|
60
|
+
- **Plan** runs in your session. A read-only scout maps the repo, then you answer the high-impact questions one at a time and confirm the plan. Nothing is built before that.
|
|
61
|
+
- **Test** (standard and large): a tester subagent, which never sees the implementation, writes acceptance tests from your confirmed criteria and locks them.
|
|
62
|
+
- **Build**: an implementer subagent makes the locked tests pass. Small tasks skip Test, so the implementer writes the tests.
|
|
63
|
+
- **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.
|
|
64
|
+
- **Done**: proposes `AGENTS.md` updates and drafts the commit and PR message. You approve each change; loopwright never commits.
|
|
137
65
|
|
|
138
|
-
|
|
66
|
+
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).
|
|
139
67
|
|
|
140
|
-
|
|
141
|
-
- Your `.gitignore`: `.loopwright/` ignores itself.
|
|
142
|
-
- Your commits: the agent drafts messages but does not commit.
|
|
143
|
-
- Anything under `.loopwright/tasks/` on update or uninstall.
|
|
68
|
+
### Commands
|
|
144
69
|
|
|
145
|
-
|
|
70
|
+
Run a single stage, or the whole loop with `flow`. In Codex, use `$` instead of `/`.
|
|
146
71
|
|
|
147
|
-
|
|
72
|
+
| Command | Does |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `/loopwright-flow` | Run or resume the whole loop, stopping wherever you must decide |
|
|
75
|
+
| `/loopwright-plan` | Plan stage |
|
|
76
|
+
| `/loopwright-test` | Test stage |
|
|
77
|
+
| `/loopwright-build` | Build stage |
|
|
78
|
+
| `/loopwright-review` | Review stage |
|
|
79
|
+
| `/loopwright-done` | Done stage |
|
|
148
80
|
|
|
149
|
-
|
|
81
|
+
## Support
|
|
150
82
|
|
|
151
|
-
|
|
152
|
-
|
|
83
|
+
| Feature | Claude Code | Codex | Junie CLI |
|
|
84
|
+
|---|---|---|---|
|
|
85
|
+
| Skills install | Supported, tested | WIP: installed, not tested end-to-end | WIP: reads `.agents/skills` |
|
|
86
|
+
| Subagents (scout, tester, implementer, reviewer) | Supported, tested | WIP: installed, not tested end-to-end | WIP: `.junie/agents` |
|
|
87
|
+
| Hook enforcement (locked-test guard, stop gate, context reinjection) | Supported, tested | WIP: installed, not tested end-to-end | Experimental (`--experimental junie-hooks`, Early Access) |
|
|
88
|
+
| Structured questions | `AskUserQuestion` | Plain-text fallback (numbered options) | Plain-text fallback |
|
|
89
|
+
| Cross-agent review (as the reviewer) | Supported, tested | WIP: untested | Not supported |
|
|
90
|
+
| Global install | Supported, tested | WIP: installed, not tested end-to-end | WIP: `~/.junie/agents` |
|
|
153
91
|
|
|
154
|
-
|
|
92
|
+
Codex and Junie CLI support is work in progress.
|
|
155
93
|
|
|
156
|
-
**
|
|
94
|
+
- **Codex**: behavior was derived from Codex source and CLI help; no real Codex session has been run against loopwright yet. Expect rough edges.
|
|
95
|
+
- **Junie CLI**: its hooks are Early Access. Subagents are installed with per-role models from `models.junie` (default: scout `opus`, tester and implementer `sonnet`, reviewer `gpt`, so the review comes from a different vendor than the code). If your Junie plan cannot use a model, the stage skills retry the subagent without a model (Junie's default).
|
|
157
96
|
|
|
158
|
-
|
|
159
|
-
git switch main && git pull
|
|
160
|
-
git switch -c release-x.y.z
|
|
161
|
-
npm version patch --no-git-tag-version # or minor / major; edits package.json + package-lock.json only
|
|
162
|
-
git commit -am "release x.y.z"
|
|
163
|
-
git push -u origin HEAD
|
|
164
|
-
gh pr create --fill # merge it once CI is green
|
|
165
|
-
```
|
|
97
|
+
## Learn more
|
|
166
98
|
|
|
167
|
-
|
|
99
|
+
- [Installation](docs/installation.md): flags, files written, update, uninstall, worktrees.
|
|
100
|
+
- [Configuration](docs/configuration.md): models, fix rounds, cross-agent review, effort profiles (`lean`, `balanced`, `thorough`, `deep`; set with `--profile`), experimental features.
|
|
101
|
+
- [Workflow in detail](docs/workflow.md): the full flow with charts: slices, the Plan and Review steps, and where it waits for you.
|
|
102
|
+
- [Enforcement and its limits](docs/enforcement.md): what the hooks block, and what they cannot.
|
|
103
|
+
- [Dogfood checklist](docs/dogfood-checklist.md): a manual end-to-end test run.
|
|
168
104
|
|
|
169
|
-
|
|
105
|
+
## Contributing
|
|
170
106
|
|
|
171
|
-
|
|
172
|
-
2. On npmjs.com → `loopwright` → Settings → Trusted publishing → GitHub Actions: repository `xuansontrinh/loopwright`, workflow `publish.yml`, with **Allow `npm publish`** and **Allow `npm dist-tag`** left unchecked (stage-only).
|
|
173
|
-
3. Publishing access: "Require two-factor authentication and disallow tokens".
|
|
107
|
+
See [CLAUDE.md](CLAUDE.md) for the project layout and conventions, [writing documentation guidelines](docs/writing-documentation-guidelines.md) before editing docs, and [Releasing](docs/releasing.md) for maintainers.
|
|
174
108
|
|
|
175
109
|
## License
|
|
176
110
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"maxFixRounds": 3,
|
|
3
|
-
"
|
|
3
|
+
"crossAgentReview": "off",
|
|
4
4
|
"docsDir": "docs/agents",
|
|
5
5
|
"models": {
|
|
6
6
|
"claude": {
|
|
@@ -15,7 +15,13 @@
|
|
|
15
15
|
"implementer": "inherit",
|
|
16
16
|
"reviewer": "inherit"
|
|
17
17
|
},
|
|
18
|
-
"
|
|
18
|
+
"junie": {
|
|
19
|
+
"scout": "opus",
|
|
20
|
+
"tester": "sonnet",
|
|
21
|
+
"implementer": "sonnet",
|
|
22
|
+
"reviewer": "gpt"
|
|
23
|
+
},
|
|
24
|
+
"crossAgentReviewer": {
|
|
19
25
|
"claude": "opus",
|
|
20
26
|
"codex": "inherit"
|
|
21
27
|
}
|
|
@@ -16,14 +16,19 @@ exitIfHooksOff();
|
|
|
16
16
|
|
|
17
17
|
try {
|
|
18
18
|
const input = await readStdinJson();
|
|
19
|
-
|
|
19
|
+
// Junie runs hooks from ~/.junie and reports the repo as project_path.
|
|
20
|
+
const cwd = input.project_path || input.cwd || process.cwd();
|
|
20
21
|
const dir = loopwrightDir(cwd);
|
|
21
22
|
if (!dir) allow();
|
|
22
23
|
const state = readState(dir, worktreeId(cwd));
|
|
23
24
|
if (!state || state.stage !== 'build' || !Array.isArray(state.lockedTests) || state.lockedTests.length === 0) allow();
|
|
24
25
|
|
|
25
26
|
const ti = input.tool_input ?? {};
|
|
26
|
-
const raw = input.tool_name === 'apply_patch'
|
|
27
|
+
const raw = input.tool_name === 'apply_patch'
|
|
28
|
+
? patchPaths(ti.patch ?? ti.command)
|
|
29
|
+
: ti.file_path && input.tool_name !== 'Read' // Junie fires PreToolUse for reads too; only edits are guarded
|
|
30
|
+
? [ti.file_path]
|
|
31
|
+
: [];
|
|
27
32
|
const locked = new Set(state.lockedTests.map((l) => l.path));
|
|
28
33
|
for (const p of raw) {
|
|
29
34
|
const rel = repoRelative(cwd, p);
|
package/content/hooks/lib.mjs
CHANGED
|
@@ -4,6 +4,14 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
import { existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, realpathSync, renameSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
6
6
|
|
|
7
|
+
/** Mirror of PROFILES in src/core/profiles.ts (a test pins them equal). */
|
|
8
|
+
export const PROFILES = {
|
|
9
|
+
lean: { scout: 'low', tester: 'low', implementer: 'low', reviewer: 'medium' },
|
|
10
|
+
balanced: { scout: 'medium', tester: 'medium', implementer: 'medium', reviewer: 'high' },
|
|
11
|
+
thorough: { scout: 'high', tester: 'high', implementer: 'high', reviewer: 'xhigh' },
|
|
12
|
+
deep: { scout: 'xhigh', tester: 'xhigh', implementer: 'xhigh', reviewer: 'xhigh' },
|
|
13
|
+
};
|
|
14
|
+
|
|
7
15
|
const MAX_BUFFER = 1024 * 1024 * 1024;
|
|
8
16
|
|
|
9
17
|
function git(cwd, args) {
|
|
@@ -93,7 +101,7 @@ export function fingerprint(cwd, baseCommit) {
|
|
|
93
101
|
return h.digest('hex');
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
/** Hooks call this first: LOOPWRIGHT_HOOKS=off (e.g. a headless cross-
|
|
104
|
+
/** Hooks call this first: LOOPWRIGHT_HOOKS=off (e.g. a headless cross-agent reviewer) disables them silently. */
|
|
97
105
|
export function exitIfHooksOff() {
|
|
98
106
|
if (process.env.LOOPWRIGHT_HOOKS === 'off') process.exit(0);
|
|
99
107
|
}
|
package/content/hooks/lw.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Loopwright state tool. Usage: node lw.mjs <cmd> [args]
|
|
3
|
-
import { copyFileSync, existsSync, mkdirSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { copyFileSync, existsSync, readFileSync, mkdirSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
6
6
|
import { execFileSync } from 'node:child_process';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
|
-
import { fingerprint, gitTopLevel, loopwrightDir, loopwrightPath, readState, repoRelative, sha256File, statePath, worktreeId, writeState } from './lib.mjs';
|
|
8
|
+
import { PROFILES, fingerprint, gitTopLevel, loopwrightDir, loopwrightPath, readState, repoRelative, sha256File, statePath, worktreeId, writeState } from './lib.mjs';
|
|
9
9
|
|
|
10
10
|
const STAGES = ['plan', 'test', 'build', 'review', 'done'];
|
|
11
11
|
const cwd = process.cwd();
|
|
@@ -48,7 +48,7 @@ function ctx(create = false) {
|
|
|
48
48
|
if (!create) fail('loopwright: no active task (no .loopwright directory yet; lw.mjs start creates it)');
|
|
49
49
|
scaffold(path);
|
|
50
50
|
dir = path;
|
|
51
|
-
}
|
|
51
|
+
} else if (create) scaffold(dir); // idempotent: seeds a config.json missing from an existing .loopwright/
|
|
52
52
|
return { dir, id: worktreeId(cwd) };
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -59,6 +59,31 @@ function requireState() {
|
|
|
59
59
|
return { dir, id, state };
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/** Effort for a role: the task header's `profile:`, else the manifest's recorded profile, else balanced. */
|
|
63
|
+
function effortFor(role) {
|
|
64
|
+
if (!Object.hasOwn(PROFILES.balanced, role)) fail(`loopwright: usage: effort <${Object.keys(PROFILES.balanced).join('|')}>`);
|
|
65
|
+
// Works before `start` (Plan's scout spawn): no task or repo state just means no header.
|
|
66
|
+
let name;
|
|
67
|
+
let dir = null;
|
|
68
|
+
try {
|
|
69
|
+
dir = loopwrightDir(cwd);
|
|
70
|
+
const state = dir && readState(dir, worktreeId(cwd));
|
|
71
|
+
if (state?.task && existsSync(join(dir, state.task))) {
|
|
72
|
+
name = /^profile:\s*(\S+)\s*$/m.exec(readFileSync(join(dir, state.task), 'utf8').split(/^## /m)[0])?.[1];
|
|
73
|
+
}
|
|
74
|
+
} catch {}
|
|
75
|
+
// Repo manifest first, then the global one (global installs record it under ~/.config/loopwright).
|
|
76
|
+
for (const m of [dir && join(dir, 'manifest.json'), join(homedir(), '.config', 'loopwright', 'manifest.json')]) {
|
|
77
|
+
if (name || !m || !existsSync(m)) continue;
|
|
78
|
+
try {
|
|
79
|
+
name = JSON.parse(readFileSync(m, 'utf8')).options?.profile;
|
|
80
|
+
} catch {}
|
|
81
|
+
}
|
|
82
|
+
name ??= 'balanced';
|
|
83
|
+
if (!Object.hasOwn(PROFILES, name)) fail(`loopwright: unknown profile '${name}' (allowed: ${Object.keys(PROFILES).join(', ')})`);
|
|
84
|
+
return PROFILES[name][role];
|
|
85
|
+
}
|
|
86
|
+
|
|
62
87
|
const gitOut = (args) => execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
63
88
|
|
|
64
89
|
const [cmd, ...rest] = process.argv.slice(2);
|
|
@@ -194,6 +219,9 @@ try {
|
|
|
194
219
|
out(state);
|
|
195
220
|
break;
|
|
196
221
|
}
|
|
222
|
+
case 'effort':
|
|
223
|
+
process.stdout.write(effortFor(rest[0]) + '\n');
|
|
224
|
+
break;
|
|
197
225
|
case 'status': {
|
|
198
226
|
out(requireState().state);
|
|
199
227
|
break;
|
|
@@ -208,7 +236,7 @@ try {
|
|
|
208
236
|
break;
|
|
209
237
|
}
|
|
210
238
|
default:
|
|
211
|
-
fail('loopwright: usage: lw.mjs <dir|start|stage|lock|check-locks|fingerprint|verdict|await-user|resume|status|done>');
|
|
239
|
+
fail('loopwright: usage: lw.mjs <dir|start|stage|lock|check-locks|fingerprint|verdict|await-user|resume|status|effort|done>');
|
|
212
240
|
}
|
|
213
241
|
} catch (err) {
|
|
214
242
|
fail(`loopwright: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -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));
|
|
@@ -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.";
|
|
@@ -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` (`
|
|
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-
|
|
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 <
|
|
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 <
|
|
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.
|
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,50 @@ import { execFileSync } from "node:child_process";
|
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { createInterface } from "node:readline";
|
|
10
|
+
// src/core/experimental.ts
|
|
11
|
+
const EXPERIMENTAL_FEATURES = ["junie-hooks"];
|
|
12
|
+
/** Parse a comma-separated `--experimental` value; `all` expands to every feature, in registry order. */
|
|
13
|
+
function parseExperimental(raw) {
|
|
14
|
+
const names = raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
15
|
+
const out = /* @__PURE__ */ new Set();
|
|
16
|
+
for (const n of names) if (n === "all") for (const f of EXPERIMENTAL_FEATURES) out.add(f);
|
|
17
|
+
else if (EXPERIMENTAL_FEATURES.includes(n)) out.add(n);
|
|
18
|
+
else throw new Error(`Unknown experimental feature "${n}". Valid: ${EXPERIMENTAL_FEATURES.join(", ")}, all`);
|
|
19
|
+
return EXPERIMENTAL_FEATURES.filter((f) => out.has(f));
|
|
20
|
+
}
|
|
21
|
+
// src/core/profiles.ts
|
|
22
|
+
/** Effort per role. Mirrored in content/hooks/lib.mjs (a test pins them equal). Efforts only, never models. */
|
|
23
|
+
const PROFILES = {
|
|
24
|
+
lean: {
|
|
25
|
+
scout: "low",
|
|
26
|
+
tester: "low",
|
|
27
|
+
implementer: "low",
|
|
28
|
+
reviewer: "medium"
|
|
29
|
+
},
|
|
30
|
+
balanced: {
|
|
31
|
+
scout: "medium",
|
|
32
|
+
tester: "medium",
|
|
33
|
+
implementer: "medium",
|
|
34
|
+
reviewer: "high"
|
|
35
|
+
},
|
|
36
|
+
thorough: {
|
|
37
|
+
scout: "high",
|
|
38
|
+
tester: "high",
|
|
39
|
+
implementer: "high",
|
|
40
|
+
reviewer: "xhigh"
|
|
41
|
+
},
|
|
42
|
+
deep: {
|
|
43
|
+
scout: "xhigh",
|
|
44
|
+
tester: "xhigh",
|
|
45
|
+
implementer: "xhigh",
|
|
46
|
+
reviewer: "xhigh"
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const PROFILE_NAMES = Object.keys(PROFILES);
|
|
50
|
+
function resolveProfile(name) {
|
|
51
|
+
if (!Object.hasOwn(PROFILES, name)) throw new Error(`Unknown profile ${JSON.stringify(name)} (allowed: ${PROFILE_NAMES.join(", ")})`);
|
|
52
|
+
return PROFILES[name];
|
|
53
|
+
}
|
|
10
54
|
// src/core/git.ts
|
|
11
55
|
function git(cwd, args) {
|
|
12
56
|
return execFileSync("git", args, {
|
|
@@ -50,9 +94,11 @@ function resolveTargets(opts) {
|
|
|
50
94
|
claudeSkillsMode: "copy",
|
|
51
95
|
claudeAgentsDir: join(h, ".claude/agents"),
|
|
52
96
|
codexAgentsDir: join(h, ".codex/agents"),
|
|
97
|
+
junieAgentsDir: join(h, ".junie/agents"),
|
|
53
98
|
lwHome: lw,
|
|
54
99
|
lwHomeRef: lw,
|
|
55
100
|
claudeSettingsPath: join(h, ".claude/settings.json"),
|
|
101
|
+
junieConfigPath: join(h, ".junie/config.json"),
|
|
56
102
|
codexConfigPath: join(h, ".codex/config.toml"),
|
|
57
103
|
manifestPath: join(lw, "manifest.json"),
|
|
58
104
|
configPath: join(lw, "config.json"),
|
|
@@ -76,9 +122,11 @@ function resolveTargets(opts) {
|
|
|
76
122
|
claudeSkillsMode: opts.symlink ? "symlink" : "none",
|
|
77
123
|
claudeAgentsDir: join(root, ".claude/agents"),
|
|
78
124
|
codexAgentsDir: join(root, ".codex/agents"),
|
|
125
|
+
junieAgentsDir: join(root, ".junie/agents"),
|
|
79
126
|
lwHome: join(root, ".agents/loopwright"),
|
|
80
127
|
lwHomeRef: ".agents/loopwright",
|
|
81
128
|
claudeSettingsPath: join(root, ".claude/settings.json"),
|
|
129
|
+
junieConfigPath: join(root, ".junie/config.json"),
|
|
82
130
|
codexConfigPath: join(root, ".codex/config.toml"),
|
|
83
131
|
manifestPath: join(stateDir, "manifest.json"),
|
|
84
132
|
configPath: join(stateDir, "config.json"),
|
|
@@ -88,7 +136,7 @@ function resolveTargets(opts) {
|
|
|
88
136
|
// src/core/config.ts
|
|
89
137
|
const DEFAULT_CONFIG = {
|
|
90
138
|
maxFixRounds: 3,
|
|
91
|
-
|
|
139
|
+
crossAgentReview: "off",
|
|
92
140
|
docsDir: "docs/agents",
|
|
93
141
|
models: {
|
|
94
142
|
claude: {
|
|
@@ -103,7 +151,13 @@ const DEFAULT_CONFIG = {
|
|
|
103
151
|
implementer: "inherit",
|
|
104
152
|
reviewer: "inherit"
|
|
105
153
|
},
|
|
106
|
-
|
|
154
|
+
junie: {
|
|
155
|
+
scout: "opus",
|
|
156
|
+
tester: "sonnet",
|
|
157
|
+
implementer: "sonnet",
|
|
158
|
+
reviewer: "gpt"
|
|
159
|
+
},
|
|
160
|
+
crossAgentReviewer: {
|
|
107
161
|
claude: "opus",
|
|
108
162
|
codex: "inherit"
|
|
109
163
|
}
|
|
@@ -118,15 +172,27 @@ function merge(base, over) {
|
|
|
118
172
|
for (const [k, v] of Object.entries(over)) out[k] = merge(base[k], v);
|
|
119
173
|
return out;
|
|
120
174
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
175
|
+
/** Efforts come only from `profile` (--profile, default balanced); effort keys in the file are ignored. Models are never touched. */
|
|
176
|
+
function readConfig(path, profile) {
|
|
177
|
+
profile ??= "balanced";
|
|
178
|
+
if (!PROFILE_NAMES.includes(profile)) throw new Error(`Invalid profile in ${path}: ${JSON.stringify(profile)} (allowed: ${PROFILE_NAMES.join(", ")})`);
|
|
179
|
+
let config = structuredClone(DEFAULT_CONFIG);
|
|
180
|
+
if (existsSync(path)) {
|
|
181
|
+
let parsed;
|
|
182
|
+
try {
|
|
183
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
184
|
+
} catch (e) {
|
|
185
|
+
throw new Error(`Invalid JSON in ${path}: ${e.message}`);
|
|
186
|
+
}
|
|
187
|
+
config = merge(config, parsed);
|
|
128
188
|
}
|
|
129
|
-
|
|
189
|
+
const efforts = resolveProfile(profile);
|
|
190
|
+
const m = config.models;
|
|
191
|
+
m.claude.effort = { ...efforts };
|
|
192
|
+
m.junie.effort = { ...efforts };
|
|
193
|
+
m.codex.effort = { ...efforts };
|
|
194
|
+
m.crossAgentReviewer.effort = { claude: efforts.reviewer };
|
|
195
|
+
return config;
|
|
130
196
|
}
|
|
131
197
|
// src/core/manifest.ts
|
|
132
198
|
function sha256(text) {
|
|
@@ -194,8 +260,8 @@ var InstallWriter = class {
|
|
|
194
260
|
});
|
|
195
261
|
}
|
|
196
262
|
/** Hooks skipped this run: existing wiring stays in place, so its manifest record must too. */
|
|
197
|
-
carryPriorConfig() {
|
|
198
|
-
for (const c of this.opts.manifest?.config ?? []) this.addConfig(c);
|
|
263
|
+
carryPriorConfig(kinds) {
|
|
264
|
+
for (const c of this.opts.manifest?.config ?? []) if (kinds.includes(c.kind)) this.addConfig(c);
|
|
199
265
|
}
|
|
200
266
|
addConfig(entry) {
|
|
201
267
|
if (!this.config.some((c) => c.file === entry.file && c.kind === entry.kind)) this.config.push({
|
|
@@ -277,7 +343,7 @@ function parseAgentSource(role, md) {
|
|
|
277
343
|
body: m[2].trim()
|
|
278
344
|
};
|
|
279
345
|
}
|
|
280
|
-
function renderClaudeAgent(src, model) {
|
|
346
|
+
function renderClaudeAgent(src, model, effort) {
|
|
281
347
|
const lines = [
|
|
282
348
|
"---",
|
|
283
349
|
`name: ${src.name}`,
|
|
@@ -285,6 +351,7 @@ function renderClaudeAgent(src, model) {
|
|
|
285
351
|
];
|
|
286
352
|
if (src.tools) lines.push(`tools: ${src.tools}`);
|
|
287
353
|
if (model !== "inherit") lines.push(`model: ${model}`);
|
|
354
|
+
if (effort) lines.push(`effort: ${effort}`);
|
|
288
355
|
lines.push("---", "", src.body, "");
|
|
289
356
|
return lines.join("\n");
|
|
290
357
|
}
|
|
@@ -302,6 +369,22 @@ function renderCodexAgent(src, model, effort) {
|
|
|
302
369
|
lines.push(`developer_instructions = ${instructions}`, "");
|
|
303
370
|
return lines.join("\n");
|
|
304
371
|
}
|
|
372
|
+
/** Junie takes the same tool labels as the role source, as a YAML list. */
|
|
373
|
+
function renderJunieAgent(src, model, effort, lwHome = ".agents/loopwright") {
|
|
374
|
+
const lines = [
|
|
375
|
+
"---",
|
|
376
|
+
`name: ${src.name}`,
|
|
377
|
+
`description: ${src.description}`
|
|
378
|
+
];
|
|
379
|
+
if (src.tools) {
|
|
380
|
+
lines.push("tools:");
|
|
381
|
+
for (const t of src.tools.split(",").map((x) => x.trim()).filter(Boolean)) lines.push(` - ${t}`);
|
|
382
|
+
}
|
|
383
|
+
if (model !== "inherit") lines.push(`model: ${model}`);
|
|
384
|
+
if (effort) lines.push(`reasoningLevel: ${effort}`);
|
|
385
|
+
lines.push("---", "", renderTemplate(src.body, { LW_HOME: lwHome }), "");
|
|
386
|
+
return lines.join("\n");
|
|
387
|
+
}
|
|
305
388
|
// src/install/hook-wiring.ts
|
|
306
389
|
/** Substring identifying commands managed by loopwright. */
|
|
307
390
|
const MANAGED_HOOK_HINT = "loopwright/hooks/";
|
|
@@ -324,7 +407,7 @@ function hookSpecs(tool) {
|
|
|
324
407
|
];
|
|
325
408
|
}
|
|
326
409
|
function hookCommand(tool, targets, script) {
|
|
327
|
-
if (targets.mode === "global") return `node "${targets.lwHome}/hooks/${script}" --tool ${tool}`;
|
|
410
|
+
if (targets.mode === "global" || tool === "junie") return `node "${targets.lwHome}/hooks/${script}" --tool ${tool}`;
|
|
328
411
|
return `node "${tool === "claude" ? "$CLAUDE_PROJECT_DIR" : "$(git rev-parse --show-toplevel)"}/.agents/loopwright/hooks/${script}" --tool ${tool}`;
|
|
329
412
|
}
|
|
330
413
|
// src/install/claude-settings.ts
|
|
@@ -399,6 +482,13 @@ function removeClaudeHooks(settingsText, hint, filePath) {
|
|
|
399
482
|
else next["hooks"] = hooks;
|
|
400
483
|
return JSON.stringify(next, null, 2) + "\n";
|
|
401
484
|
}
|
|
485
|
+
// src/install/junie-config.ts
|
|
486
|
+
function upsertJunieHooks(text, specs, commandFor, filePath) {
|
|
487
|
+
return mergeClaudeHooks(text, specs, commandFor, filePath);
|
|
488
|
+
}
|
|
489
|
+
function removeJunieHooks(text, hint = MANAGED_HOOK_HINT, filePath) {
|
|
490
|
+
return removeClaudeHooks(text, hint, filePath);
|
|
491
|
+
}
|
|
402
492
|
// src/install/codex-config.ts
|
|
403
493
|
const CODEX_BEGIN = "# BEGIN loopwright";
|
|
404
494
|
const CODEX_END = "# END loopwright";
|
|
@@ -643,21 +733,41 @@ function mergeIntoAgents(source, dest) {
|
|
|
643
733
|
// src/install/install.ts
|
|
644
734
|
/** Compute hook wiring results without writing. Throws SettingsParseError on malformed files. */
|
|
645
735
|
function planWiring(targets, opts) {
|
|
646
|
-
if (!opts.hook) return [];
|
|
647
736
|
const read = (f) => existsSync(f) ? readFileSync(f, "utf8") : "";
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
737
|
+
const plans = [];
|
|
738
|
+
if (opts.hook) {
|
|
739
|
+
const cs = read(targets.claudeSettingsPath);
|
|
740
|
+
const cc = read(targets.codexConfigPath);
|
|
741
|
+
plans.push({
|
|
742
|
+
file: targets.claudeSettingsPath,
|
|
743
|
+
kind: "claude-hooks",
|
|
744
|
+
managed: true,
|
|
745
|
+
cur: cs,
|
|
746
|
+
out: mergeClaudeHooks(cs, hookSpecs("claude"), (s) => hookCommand("claude", targets, s.script), targets.claudeSettingsPath)
|
|
747
|
+
}, {
|
|
748
|
+
file: targets.codexConfigPath,
|
|
749
|
+
kind: "codex-block",
|
|
750
|
+
managed: true,
|
|
751
|
+
cur: cc,
|
|
752
|
+
out: upsertCodexBlock(cc, renderCodexHookBlock(hookSpecs("codex"), (s) => hookCommand("codex", targets, s.script)))
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
const jc = read(targets.junieConfigPath);
|
|
756
|
+
if (opts.experimental?.includes("junie-hooks")) plans.push({
|
|
757
|
+
file: targets.junieConfigPath,
|
|
758
|
+
kind: "junie-hooks",
|
|
759
|
+
managed: true,
|
|
760
|
+
cur: jc,
|
|
761
|
+
out: upsertJunieHooks(jc, hookSpecs("junie"), (s) => hookCommand("junie", targets, s.script), targets.junieConfigPath)
|
|
762
|
+
});
|
|
763
|
+
else if (jc.includes("loopwright/hooks/")) plans.push({
|
|
764
|
+
file: targets.junieConfigPath,
|
|
765
|
+
kind: "junie-hooks",
|
|
766
|
+
managed: false,
|
|
767
|
+
cur: jc,
|
|
768
|
+
out: removeJunieHooks(jc, MANAGED_HOOK_HINT, targets.junieConfigPath)
|
|
769
|
+
});
|
|
770
|
+
return plans;
|
|
661
771
|
}
|
|
662
772
|
/** Install every file under content/ plus agents and hook wiring. Returns whether anything changed. */
|
|
663
773
|
async function installAll(targets, writer, config, opts, link = "skip") {
|
|
@@ -680,8 +790,9 @@ async function installAll(targets, writer, config, opts, link = "skip") {
|
|
|
680
790
|
if (!f.endsWith(".md")) continue;
|
|
681
791
|
const role = basename(f, ".md");
|
|
682
792
|
const src = parseAgentSource(role, renderTemplate(readContent(`agents/${f}`), vars));
|
|
683
|
-
await put(join(targets.claudeAgentsDir, `${src.name}.md`), renderClaudeAgent(src, config.models.claude[role] ?? "inherit"));
|
|
793
|
+
await put(join(targets.claudeAgentsDir, `${src.name}.md`), renderClaudeAgent(src, config.models.claude[role] ?? "inherit", config.models.claude.effort?.[role]));
|
|
684
794
|
await put(join(targets.codexAgentsDir, `${src.name}.toml`), renderCodexAgent(src, config.models.codex[role] ?? "inherit", config.models.codex.effort?.[role]));
|
|
795
|
+
await put(join(targets.junieAgentsDir, `${src.name}.md`), renderJunieAgent(src, config.models.junie[role] ?? "inherit", config.models.junie.effort?.[role], targets.lwHomeRef));
|
|
685
796
|
}
|
|
686
797
|
for (const sub of [
|
|
687
798
|
"hooks",
|
|
@@ -694,9 +805,9 @@ async function installAll(targets, writer, config, opts, link = "skip") {
|
|
|
694
805
|
if (targets.claudeSkillsMode === "symlink") {
|
|
695
806
|
if (applyLink(targets.root, link, opts.dryRun)) changed = true;
|
|
696
807
|
}
|
|
697
|
-
if (!opts.hook) writer.carryPriorConfig();
|
|
808
|
+
if (!opts.hook) writer.carryPriorConfig(["claude-hooks", "codex-block"]);
|
|
698
809
|
for (const w of wiring) {
|
|
699
|
-
writer.recordConfig({
|
|
810
|
+
if (w.managed) writer.recordConfig({
|
|
700
811
|
file: w.file,
|
|
701
812
|
kind: w.kind
|
|
702
813
|
});
|
|
@@ -740,7 +851,9 @@ function withRecordedOptions(opts, recorded) {
|
|
|
740
851
|
return {
|
|
741
852
|
...opts,
|
|
742
853
|
hook: opts.explicit?.hook ? opts.hook : recorded.hook,
|
|
743
|
-
symlink: opts.explicit?.symlink ? opts.symlink : recorded.symlink
|
|
854
|
+
symlink: opts.explicit?.symlink ? opts.symlink : recorded.symlink,
|
|
855
|
+
experimental: opts.explicit?.experimental ? opts.experimental : recorded.experimental ?? [],
|
|
856
|
+
profile: opts.explicit?.profile ? opts.profile : recorded.profile
|
|
744
857
|
};
|
|
745
858
|
}
|
|
746
859
|
/** Shared install flow for `init` and `update`. */
|
|
@@ -771,7 +884,7 @@ async function runInstall(opts, doneVerb, isInit = false) {
|
|
|
771
884
|
return 1;
|
|
772
885
|
}
|
|
773
886
|
if (targets.mode === "repo" && targets.stateDir) scaffoldLoopwrightDir(targets.stateDir, opts.dryRun);
|
|
774
|
-
const config = readConfig(targets.configPath);
|
|
887
|
+
const config = readConfig(targets.configPath, opts.profile);
|
|
775
888
|
if (targets.mode === "global" && !opts.dryRun && !opts.force) {
|
|
776
889
|
log.info("The following changes would be made to your user configuration:");
|
|
777
890
|
const preview = {
|
|
@@ -790,12 +903,20 @@ async function runInstall(opts, doneVerb, isInit = false) {
|
|
|
790
903
|
...writer.result(),
|
|
791
904
|
options: {
|
|
792
905
|
hook: opts.hook,
|
|
793
|
-
symlink: opts.symlink
|
|
906
|
+
symlink: opts.symlink,
|
|
907
|
+
...opts.experimental?.length ? { experimental: opts.experimental } : {},
|
|
908
|
+
...opts.profile ? { profile: opts.profile } : {}
|
|
794
909
|
}
|
|
795
910
|
});
|
|
796
911
|
if (!changed) log.success("loopwright is already up to date.");
|
|
797
912
|
else if (!opts.dryRun) log.success(`loopwright ${doneVerb}.`);
|
|
798
913
|
if (targets.mode === "repo" && opts.hook) log.info("Codex: trust this project and approve loopwright hooks via /hooks.");
|
|
914
|
+
log.info("Junie (WIP/EAP): subagents installed to .junie/agents; skills are read from .agents/skills.");
|
|
915
|
+
if (opts.profile) log.info(`Effort profile: ${opts.profile}. Claude Code can also set it per task at Plan; run \`npx loopwright update\` after changing it.`);
|
|
916
|
+
for (const f of opts.experimental ?? []) {
|
|
917
|
+
log.warn(`Experimental feature "${f}" is unstable and may change or break.`);
|
|
918
|
+
if (f === "junie-hooks") log.info(`Junie hooks are written to ${targets.junieConfigPath}. Junie ignores project hooks unless started with --config-location (e.g. junie --config-location .junie).`);
|
|
919
|
+
}
|
|
799
920
|
return 0;
|
|
800
921
|
} catch (e) {
|
|
801
922
|
if (e instanceof SettingsParseError) {
|
|
@@ -864,12 +985,15 @@ async function runUninstall(opts) {
|
|
|
864
985
|
for (const c of manifest.config) configs.set(resolve(abs(c.file)), c.kind);
|
|
865
986
|
configs.set(resolve(targets.claudeSettingsPath), "claude-hooks");
|
|
866
987
|
configs.set(resolve(targets.codexConfigPath), "codex-block");
|
|
988
|
+
configs.set(resolve(targets.junieConfigPath), "junie-hooks");
|
|
867
989
|
for (const [file, kind] of configs) {
|
|
868
990
|
if (!existsSync(file)) continue;
|
|
869
991
|
const cur = readFileSync(file, "utf-8");
|
|
870
992
|
let out;
|
|
871
993
|
try {
|
|
872
|
-
|
|
994
|
+
if (kind === "claude-hooks") out = removeClaudeHooks(cur, "loopwright/hooks/", file);
|
|
995
|
+
else if (kind === "junie-hooks") out = removeJunieHooks(cur, "loopwright/hooks/", file);
|
|
996
|
+
else out = removeCodexBlock(cur);
|
|
873
997
|
} catch (e) {
|
|
874
998
|
if (e instanceof SettingsParseError) {
|
|
875
999
|
log.warn(`left ${file} untouched: ${e.message}`);
|
|
@@ -880,7 +1004,7 @@ async function runUninstall(opts) {
|
|
|
880
1004
|
if (out === cur) continue;
|
|
881
1005
|
log.dim(` ${dry ? "Would update" : "Updated"} ${file}`);
|
|
882
1006
|
if (dry) continue;
|
|
883
|
-
writeFileSync(file, kind
|
|
1007
|
+
writeFileSync(file, kind !== "codex-block" && out.trim() === "{}" ? "{}\n" : out, "utf-8");
|
|
884
1008
|
}
|
|
885
1009
|
const link = targets.claudeSkillsDir;
|
|
886
1010
|
if (lstatSync(link, { throwIfNoEntry: false })?.isSymbolicLink() && readlinkSync(link) === "../.agents/skills") {
|
|
@@ -908,7 +1032,7 @@ async function runUninstall(opts) {
|
|
|
908
1032
|
return 0;
|
|
909
1033
|
}
|
|
910
1034
|
// src/cli.ts
|
|
911
|
-
const HELP = `loopwright - agent workflow installer for Claude Code and
|
|
1035
|
+
const HELP = `loopwright - agent workflow installer for Claude Code, Codex and Junie (WIP)
|
|
912
1036
|
|
|
913
1037
|
Usage:
|
|
914
1038
|
loopwright init Install the workflow into the current repo (or globally)
|
|
@@ -920,6 +1044,14 @@ Options:
|
|
|
920
1044
|
--global Install into the user home instead of the current repo
|
|
921
1045
|
--no-hook Skip hook wiring
|
|
922
1046
|
--no-symlink Skip the .claude/skills symlink
|
|
1047
|
+
--experimental <names>
|
|
1048
|
+
Enable unstable features (comma-separated, or 'all'): ${EXPERIMENTAL_FEATURES.join(", ")}.
|
|
1049
|
+
junie-hooks: wire Junie CLI hooks (Early Access; needs --config-location).
|
|
1050
|
+
update keeps the recorded list; --experimental '' turns all off
|
|
1051
|
+
--profile <name>
|
|
1052
|
+
Effort profile for the subagents: ${PROFILE_NAMES.join(", ")} (default balanced).
|
|
1053
|
+
Per-task profiles are chosen at Plan on Claude Code; this is the install-time
|
|
1054
|
+
default (and the only setting for Junie). update keeps the recorded profile
|
|
923
1055
|
--dry-run Show what would change without writing
|
|
924
1056
|
--force Overwrite conflicting files without prompting
|
|
925
1057
|
-v, --version Print version
|
|
@@ -956,6 +1088,8 @@ async function main(argv) {
|
|
|
956
1088
|
type: "boolean",
|
|
957
1089
|
default: false
|
|
958
1090
|
},
|
|
1091
|
+
experimental: { type: "string" },
|
|
1092
|
+
profile: { type: "string" },
|
|
959
1093
|
version: {
|
|
960
1094
|
type: "boolean",
|
|
961
1095
|
short: "v",
|
|
@@ -982,6 +1116,17 @@ async function main(argv) {
|
|
|
982
1116
|
console.log(HELP);
|
|
983
1117
|
return 0;
|
|
984
1118
|
}
|
|
1119
|
+
let experimental = [];
|
|
1120
|
+
try {
|
|
1121
|
+
if (values.experimental !== void 0) experimental = parseExperimental(values.experimental);
|
|
1122
|
+
} catch (err) {
|
|
1123
|
+
console.error(err.message);
|
|
1124
|
+
return 1;
|
|
1125
|
+
}
|
|
1126
|
+
if (values.profile !== void 0 && !PROFILE_NAMES.includes(values.profile)) {
|
|
1127
|
+
console.error(`Invalid --profile ${JSON.stringify(values.profile)} (allowed: ${PROFILE_NAMES.join(", ")})`);
|
|
1128
|
+
return 1;
|
|
1129
|
+
}
|
|
985
1130
|
const opts = {
|
|
986
1131
|
mode: values.global ? "global" : "repo",
|
|
987
1132
|
cwd: process.cwd(),
|
|
@@ -990,9 +1135,13 @@ async function main(argv) {
|
|
|
990
1135
|
force: values.force,
|
|
991
1136
|
hook: !values["no-hook"],
|
|
992
1137
|
symlink: !values["no-symlink"],
|
|
1138
|
+
experimental,
|
|
1139
|
+
profile: values.profile,
|
|
993
1140
|
explicit: {
|
|
994
1141
|
hook: values["no-hook"],
|
|
995
|
-
symlink: values["no-symlink"]
|
|
1142
|
+
symlink: values["no-symlink"],
|
|
1143
|
+
experimental: values.experimental !== void 0,
|
|
1144
|
+
profile: values.profile !== void 0
|
|
996
1145
|
}
|
|
997
1146
|
};
|
|
998
1147
|
switch (command) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loopwright",
|
|
3
3
|
"author": "Xuan Son Trinh",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"description": "Agent workflow installer for Claude Code and
|
|
4
|
+
"version": "0.1.2",
|
|
5
|
+
"description": "Agent workflow installer for Claude Code, Codex and Junie",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
8
|
"loopwright": "./dist/cli.js"
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
],
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@types/node": "^
|
|
37
|
+
"@types/node": "^22.20.5",
|
|
38
38
|
"smol-toml": "^1.9.1",
|
|
39
39
|
"tsdown": "^0.23.7",
|
|
40
|
-
"typescript": "^
|
|
40
|
+
"typescript": "^7.0.2",
|
|
41
41
|
"unrun": "^0.3.1",
|
|
42
|
-
"vitest": "^
|
|
42
|
+
"vitest": "^5.0.5"
|
|
43
43
|
}
|
|
44
44
|
}
|