@moberg_hr/work-tree 1.9.0 → 1.9.1
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/.claude-plugin/marketplace.json +18 -0
- package/README.md +1 -1
- package/dist/bin.js +53 -7
- package/dist/bin.js.map +1 -1
- package/dist/wd-bin.js +53 -7
- package/dist/wd-bin.js.map +1 -1
- package/dist/web/assets/index-BaT8rhHI.js +105 -0
- package/dist/web/assets/index-BaT8rhHI.js.map +1 -0
- package/dist/web/index.html +1 -1
- package/package.json +7 -3
- package/plugins/work-tree/.claude-plugin/plugin.json +11 -0
- package/plugins/work-tree/skills/wd-review/SKILL.md +145 -0
- package/scripts/postinstall.mjs +57 -0
- package/dist/web/assets/index-B-iWIQnC.js +0 -105
- package/dist/web/assets/index-B-iWIQnC.js.map +0 -1
package/dist/web/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<title>work web — sessions</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-BaT8rhHI.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/assets/index-BYfxyhDx.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moberg_hr/work-tree",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "Cross-platform Git worktree manager for multiple repositories",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
"wd": "./dist/wd-bin.js"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
|
-
"dist"
|
|
11
|
+
"dist",
|
|
12
|
+
"scripts/postinstall.mjs",
|
|
13
|
+
".claude-plugin",
|
|
14
|
+
"plugins"
|
|
12
15
|
],
|
|
13
16
|
"scripts": {
|
|
14
17
|
"build": "npm run build:server && npm run build:web",
|
|
@@ -19,7 +22,8 @@
|
|
|
19
22
|
"dev:web": "vite",
|
|
20
23
|
"test": "vitest run",
|
|
21
24
|
"test:watch": "vitest",
|
|
22
|
-
"prepublishOnly": "npm run build"
|
|
25
|
+
"prepublishOnly": "npm run build",
|
|
26
|
+
"postinstall": "node scripts/postinstall.mjs"
|
|
23
27
|
},
|
|
24
28
|
"keywords": [
|
|
25
29
|
"git",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "work-tree",
|
|
3
|
+
"description": "Skills for the work-tree CLI — wd-review drives interactive `wd -c` browser diff reviews",
|
|
4
|
+
"version": "1.9.1",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Moberg HR",
|
|
7
|
+
"url": "https://github.com/moberghr"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/moberghr/cli-work-tree-manager",
|
|
10
|
+
"strict": false
|
|
11
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: wd-review
|
|
3
|
+
description: Open an interactive diff review in the user's browser via `wd -c`, stream each comment back as the user writes it, and react to it (make the change, answer the question, or reply via the comment API). Use when the user says "review my changes", "open a wd review", "let me review with wd", "review with wd", or similar.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
The `wd` CLI on this machine (a global npm bin) ships an interactive review mode. `wd -c` opens a side-by-side diff in the user's browser, lets them click any line number to leave an inline comment, and **streams each comment to stdout as it is saved**. You start the session, react to each comment as it arrives, and the session stays alive until the user clicks "End review" (or the process is killed).
|
|
7
|
+
|
|
8
|
+
## Lifecycle markers on stdout
|
|
9
|
+
|
|
10
|
+
Each line on `wd -c` stdout is one of these self-describing chunks:
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
--- review started ---
|
|
14
|
+
repos: <repo names>
|
|
15
|
+
files: <total file count>
|
|
16
|
+
url: http://127.0.0.1:<port>/
|
|
17
|
+
|
|
18
|
+
--- comment ---
|
|
19
|
+
**<repo>/<path>** : line <N> (<left|right>)
|
|
20
|
+
id: <hex> [· author: claude] [· reply-to: <hex>]
|
|
21
|
+
> <body line 1>
|
|
22
|
+
> <body line 2>
|
|
23
|
+
|
|
24
|
+
--- comment ---
|
|
25
|
+
**General review comment**
|
|
26
|
+
id: <hex>
|
|
27
|
+
> ...
|
|
28
|
+
|
|
29
|
+
--- comment deleted ---
|
|
30
|
+
id: <hex>
|
|
31
|
+
|
|
32
|
+
--- review submitted ---
|
|
33
|
+
count: <N>
|
|
34
|
+
[summary-id: <hex>]
|
|
35
|
+
|
|
36
|
+
(followed by `--- comment ---` chunks for each newly-published draft, in order, then:)
|
|
37
|
+
|
|
38
|
+
--- review batch end ---
|
|
39
|
+
|
|
40
|
+
--- review done ---
|
|
41
|
+
total: <N>
|
|
42
|
+
|
|
43
|
+
--- review aborted (signal) ---
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The user can either post comments one-at-a-time ("Add single comment" — streams immediately) or batch them via "Start review" (drafts stay invisible until they click Submit, then everything arrives between `--- review submitted ---` and `--- review batch end ---` markers, optionally preceded by a general summary comment).
|
|
47
|
+
|
|
48
|
+
Anything on `stderr` is just status logging — ignore it.
|
|
49
|
+
|
|
50
|
+
## How to drive the session
|
|
51
|
+
|
|
52
|
+
1. **Start `wd -c` in the background** using Bash with `run_in_background: true`. The command blocks until the user clicks "End review", so it must not be foreground.
|
|
53
|
+
|
|
54
|
+
Before starting, walk any background tasks from earlier in this session that match `wd -c` or the marker-tailing Monitor (anything you yourself started for a prior review) and `TaskStop` them. Leaving stale `wd -c` shells around creates confusion: they hold ports, their monitors fire spurious events, and the user has to find them in Task Manager.
|
|
55
|
+
|
|
56
|
+
The URL for this session is announced on the FIRST `--- review started ---` marker (the `url:` line); read it from the Bash tool's output file the moment Monitor fires that marker, and keep it in conversation context. There's no on-disk URL file to cat — capturing it from the stream is the only way to learn it, which means you can never accidentally post to a review in a different worktree or a stale daemon.
|
|
57
|
+
|
|
58
|
+
2. **Tail the output with Monitor**, filtering only for marker lines. The exact output file path is reported by the Bash tool when you start the job (`Output is being written to: <path>`). Use a filter like:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
tail -F -n +1 "<output-file>" 2>&1 \
|
|
62
|
+
| grep -E --line-buffered "^--- (comment|comment deleted|review started|review done|review aborted)"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Set `persistent: true` and `timeout_ms: 3600000`. Reviews can take a while.
|
|
66
|
+
|
|
67
|
+
3. **On `--- review started ---`**: confirm the session is live to the user, then sit and wait. Do not act until comments arrive.
|
|
68
|
+
|
|
69
|
+
4. **On each `--- comment ---` event**: read the last ~30 lines of the output file to get the *body* of the freshly-arrived comment (the Monitor only signals which marker fired, it does not deliver the body). Look at the *most recent* `--- comment ---` block.
|
|
70
|
+
|
|
71
|
+
- The server suppresses claude-authored echoes, so every event you see is a real user comment. (If the meta line says `author: claude`, ignore — that's a defensive fallback.)
|
|
72
|
+
- **Save the `id:` value** — you need it to post replies.
|
|
73
|
+
- **Decide intent**: is it a question, a code-change request, an observation, or a nit?
|
|
74
|
+
- **Take the smallest reasonable action**:
|
|
75
|
+
- Code change → make the edit. Live reload will refresh the user's tab automatically.
|
|
76
|
+
- Question → reply via the API (see below). Don't pollute the conversation with a long-form answer; the reply lands inline in the browser.
|
|
77
|
+
- Observation / acknowledgement → reply briefly so the user sees you noticed.
|
|
78
|
+
- Nit you disagree with → reply explaining why, don't change the code.
|
|
79
|
+
- **Acknowledge per comment in chat** in one short line too, so the user reading Claude Code also sees your reaction.
|
|
80
|
+
|
|
81
|
+
5. **On `--- comment deleted ---`**: the user removed a comment they no longer cared about. Don't undo any work that's already shipped, just acknowledge.
|
|
82
|
+
|
|
83
|
+
6. **On `--- review done ---`**: the user closed the session. Summarise what you did in the chat (which comments triggered code changes, which got reply-only). Stop the Monitor with TaskStop.
|
|
84
|
+
|
|
85
|
+
7. **On `--- review aborted (signal) ---`**: same as done — wrap up and stop monitoring.
|
|
86
|
+
|
|
87
|
+
## Replying to a comment
|
|
88
|
+
|
|
89
|
+
**Pick the reply endpoint from the shape of the `url:` line** you captured at the `--- review started ---` marker. `wd -c` runs in one of two modes and they post to different routes:
|
|
90
|
+
|
|
91
|
+
| `url:` shape | Mode | Reply endpoint |
|
|
92
|
+
|---|---|---|
|
|
93
|
+
| `http://host:port/review/<hash>` | **work web scope** (the normal case — `wd -c` registered a review scope on the singleton `work web`) | `http://host:port/api/scopes/<hash>/comments` |
|
|
94
|
+
| `http://host:port/` (no `/review/` segment) | **standalone server** (fallback when work-web autostart failed) | `http://host:port/api/comments` |
|
|
95
|
+
|
|
96
|
+
Do NOT just append `api/comments` to the `url:` value — in scope mode that yields `…/review/<hash>api/comments`, which 404s. Parse the URL: if the path is `/review/<hash>`, the base is everything before `/review/`, and `<hash>` is that last segment.
|
|
97
|
+
|
|
98
|
+
**Write the JSON body to a temp file** and post via `--data-binary "@file"` — inline `-d '...'` will explode the moment your reply contains an apostrophe or a quote:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Derive BASE + ENDPOINT from the captured url: line.
|
|
102
|
+
URL="<the url: value from the --- review started --- marker>"
|
|
103
|
+
if [[ "$URL" == */review/* ]]; then
|
|
104
|
+
BASE="${URL%/review/*}"
|
|
105
|
+
HASH="${URL##*/review/}"; HASH="${HASH%%/*}"
|
|
106
|
+
ENDPOINT="$BASE/api/scopes/$HASH/comments" # work web scope mode
|
|
107
|
+
else
|
|
108
|
+
ENDPOINT="${URL%/}/api/comments" # standalone server mode
|
|
109
|
+
fi
|
|
110
|
+
|
|
111
|
+
# Use mktemp, NOT $CLAUDE_JOB_DIR — that var isn't reliably set, and an empty
|
|
112
|
+
# value resolves to /reply.json → "Permission denied".
|
|
113
|
+
REPLY_JSON="$(mktemp)"
|
|
114
|
+
cat > "$REPLY_JSON" <<'EOF'
|
|
115
|
+
{"parentId":"<comment-id>","author":"claude","body":"<your reply, can contain ' and \" freely>"}
|
|
116
|
+
EOF
|
|
117
|
+
curl -s -X POST -H "Content-Type: application/json" \
|
|
118
|
+
--data-binary "@$REPLY_JSON" "$ENDPOINT"
|
|
119
|
+
rm -f "$REPLY_JSON"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
If you forget the URL mid-conversation, re-scan the Bash output file from the `wd -c` background task — the `url:` line is at the top, in the first `--- review started ---` block.
|
|
123
|
+
|
|
124
|
+
The reply renders threaded under the original comment in the user's browser. Set `author: "claude"` so the UI distinguishes it visually.
|
|
125
|
+
|
|
126
|
+
## Comment anchor mechanics
|
|
127
|
+
|
|
128
|
+
- `side: left` = old/deleted line, `side: right` = new/added line. Same convention as GitHub.
|
|
129
|
+
- `side: general` = a top-level review note, no anchor.
|
|
130
|
+
- If the user edits a file after commenting, the comment shows up with an "outdated" badge in the browser. You can still address it normally — the original `lineContent` is implied by the body.
|
|
131
|
+
|
|
132
|
+
## Behavior notes
|
|
133
|
+
|
|
134
|
+
- **Reviews are per-scope, not global.** In the normal (work-web) mode every `wd -c` registers a distinct scope `<hash>` on the one shared `work web` server, so its URL is `…/review/<hash>` — the *hash* is what's unique per worktree, not a per-review port. Two `wd -c` instances in different worktrees coexist as two scopes on the same server. The URL/hash flows only through the stream you spawned, so post replies to the `<hash>` from *your* `--- review started ---` marker and you can't hit someone else's review. (In the standalone-server fallback each `wd -c` binds its own port instead.)
|
|
135
|
+
- **Don't restart `wd -c` on file edits.** The watcher inside the running session reloads the browser automatically when you edit files.
|
|
136
|
+
- **Live reload is deferred while composing.** If the user is mid-comment when you save a file, their reload is queued and applied as soon as they save/cancel the composer. You don't need to handle this.
|
|
137
|
+
- **Don't open the browser yourself.** `wd -c` opens it. You only start the process.
|
|
138
|
+
|
|
139
|
+
## What "done" looks like for this skill
|
|
140
|
+
|
|
141
|
+
You stop monitoring when `--- review done ---` (or aborted) fires, and you have:
|
|
142
|
+
|
|
143
|
+
- Made all code changes the user requested
|
|
144
|
+
- Replied to all questions and disagreements via the comment API
|
|
145
|
+
- Posted a short summary in chat: which comments you actioned, which you replied to, which you skipped and why
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Best-effort: register the work-tree Claude Code plugin marketplace and
|
|
3
|
+
// install the bundled plugin (wd-review skill) when the `claude` CLI is
|
|
4
|
+
// available. Never fails the npm install — every step is optional.
|
|
5
|
+
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
7
|
+
|
|
8
|
+
const MARKETPLACE_REPO = 'moberghr/cli-work-tree-manager';
|
|
9
|
+
const MARKETPLACE_NAME = 'work-tree';
|
|
10
|
+
const PLUGIN_SPEC = 'work-tree@work-tree';
|
|
11
|
+
|
|
12
|
+
// All argv values below are static literals — nothing user-controlled is
|
|
13
|
+
// interpolated. shell:true is required on Windows where `claude` is a .cmd shim.
|
|
14
|
+
function claude(args) {
|
|
15
|
+
return spawnSync('claude', args, {
|
|
16
|
+
stdio: 'pipe',
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
shell: process.platform === 'win32',
|
|
19
|
+
timeout: 60_000,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function main() {
|
|
24
|
+
if (process.env.CI || process.env.WORK_TREE_SKIP_PLUGIN_SETUP) return;
|
|
25
|
+
|
|
26
|
+
const probe = claude(['--version']);
|
|
27
|
+
if (probe.error || probe.status !== 0) return; // claude CLI not installed — skip silently
|
|
28
|
+
|
|
29
|
+
const list = claude(['plugin', 'marketplace', 'list']);
|
|
30
|
+
const known = !list.error && list.status === 0 && (list.stdout ?? '').includes(MARKETPLACE_NAME);
|
|
31
|
+
|
|
32
|
+
if (!known) {
|
|
33
|
+
const add = claude([
|
|
34
|
+
'plugin', 'marketplace', 'add', MARKETPLACE_REPO,
|
|
35
|
+
'--scope', 'user',
|
|
36
|
+
'--sparse', '.claude-plugin', 'plugins',
|
|
37
|
+
]);
|
|
38
|
+
if (add.error || add.status !== 0) {
|
|
39
|
+
console.log('work-tree: could not register the Claude Code plugin marketplace (run `claude plugin marketplace add ' + MARKETPLACE_REPO + '` manually).');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
console.log('work-tree: registered Claude Code plugin marketplace "' + MARKETPLACE_NAME + '".');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const install = claude(['plugin', 'install', PLUGIN_SPEC, '--scope', 'user']);
|
|
46
|
+
if (install.error || install.status !== 0) {
|
|
47
|
+
// Already installed or transient failure — either way, not fatal.
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
console.log('work-tree: installed Claude Code plugin "' + PLUGIN_SPEC + '" (wd-review skill).');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
main();
|
|
55
|
+
} catch {
|
|
56
|
+
// Never break npm install over optional plugin setup.
|
|
57
|
+
}
|