dsh-coding-enhanced 0.8.4 → 0.9.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/CHANGELOG.md +42 -0
- package/README.md +49 -3
- package/docs/review-prompts-and-chain.md +33 -2
- package/lib/client.js +275 -26
- package/lib/detect-writes.js +136 -0
- package/lib/index.js +208 -6
- package/lib/web-bridge.js +173 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.2
|
|
4
|
+
|
|
5
|
+
- Three-way **Review channel** switch in the Review tools popover: **Web** (standalone
|
|
6
|
+
review server only), **Both** (default), or **DSH** (sidebar tab only).
|
|
7
|
+
- Host `reviewChannel` setting: `builtin` keeps the outbound WSS stopped and
|
|
8
|
+
skips snapshot publishing; switching modes starts or stops the bridge live.
|
|
9
|
+
- Client gates the review tab type and the `sidebar.right.pane.tab` body:
|
|
10
|
+
Web mode removes the DSH tab and closes open review tabs; DSH/Both register
|
|
11
|
+
them again without a reload.
|
|
12
|
+
- Web review UI: AI explanation rows anchored to their code lines, soft-wrapped
|
|
13
|
+
diffs with page scrolling, an auto-growing AI message box, a collapsible
|
|
14
|
+
app sidebar, a topbar back button, and light-theme syntax highlighting.
|
|
15
|
+
|
|
16
|
+
## 0.9.1
|
|
17
|
+
|
|
18
|
+
- Web review decisions: per-file Approve/Reject and Finish in the browser;
|
|
19
|
+
decision reaches the plugin, applies via `decideReview`, and the finished
|
|
20
|
+
snapshot returns to the Web UI.
|
|
21
|
+
- Standalone web UI moves to a pure white theme.
|
|
22
|
+
- Forward `review.result.error` so failed decisions surface in the browser.
|
|
23
|
+
|
|
24
|
+
## 0.9.0
|
|
25
|
+
|
|
26
|
+
- Standalone web review server (`web/`): passkey login, one-time pairing,
|
|
27
|
+
device/browser WSS, review snapshot cache, React UI.
|
|
28
|
+
- Plugin Web review settings: URL + pairing code, outbound WSS, review.snapshot
|
|
29
|
+
sync, online/offline status.
|
|
30
|
+
- File-target shell gate (`lib/detect-writes.js`): installs, builds and tests
|
|
31
|
+
pass; protected workspace writes block; artifacts pass; turn/end audit stays
|
|
32
|
+
the backstop.
|
|
33
|
+
- Remove the 120s `review_bash` timeout; maxBuffer stays at 8 MiB.
|
|
34
|
+
|
|
35
|
+
## 0.8.5
|
|
36
|
+
|
|
37
|
+
- Native `bash` is denied while Pre-review is on; shell commands go through
|
|
38
|
+
`review_bash`, which detects writes and asks for a second confirmation.
|
|
39
|
+
- Build/test artifacts (`dist`, `build`, `node_modules`, ...) are allowed;
|
|
40
|
+
writes to source are blocked.
|
|
41
|
+
- Audit changes at `turn/end` against the turn-start snapshot and warn about
|
|
42
|
+
files changed outside review.
|
|
43
|
+
- Update the review prompt to read / review tools / review_bash.
|
|
44
|
+
|
|
3
45
|
## 0.5.15
|
|
4
46
|
|
|
5
47
|
- Restore the native tool gate: while AI Change Review and the input-bar Auto
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Queue every AI edit · rewind whole turns · hand review to a non-blocking waite
|
|
|
20
20
|
- **Pre-write change gate** — native `write` / `edit` / `apply_patch` are refused while Pre-review is on; the agent queues `review_write` / `review_patch`; nothing lands until you Finish.
|
|
21
21
|
- **Workspace time machine** — per-turn shadow-git snapshots, multi-turn withdraw, a pre-withdraw backup, and a gap warning when a rewind crosses turns without snapshots.
|
|
22
22
|
- **Non-blocking review handoff** — one persistent review waiter subagent holds the wait; the main agent can keep chatting or end the turn; the waiter wakes it with the per-file results.
|
|
23
|
-
- **Remote + cross-AI (next)** —
|
|
23
|
+
- **Remote + cross-AI (next)** — username+key web review, line-level AI comments (B), and an adversarial AI cross-review API.
|
|
24
24
|
|
|
25
25
|
> **What this is not.** Not an AI PR reviewer (CodeRabbit / Qodo / Copilot), not a hosted SaaS, and not a claim to be first. The diff UI is table stakes; the gate, the time machine, and the handoff are the product. See the [prior-art survey](docs/prior-art.md) for the direct comparison with [`dsh-diff-approval`](https://github.com/9087/dsh-diff-approval).
|
|
26
26
|
|
|
@@ -29,7 +29,7 @@ Queue every AI edit · rewind whole turns · hand review to a non-blocking waite
|
|
|
29
29
|
| 🛡️ | **Change gate** (the `AI Change Review` switch) | The agent queues every edit with `review_write` / `review_patch`; they accumulate in one review tab; nothing lands until you approve, reject, edit or Finish. |
|
|
30
30
|
| ↩️ | **Workspace time machine** (the `Turn Withdraw` switch) | Restore the workspace to before a turn and cancel that round in the model's context; multi-turn rewind, backup and gap warnings. |
|
|
31
31
|
| ⏳ | **Review handoff** | One persistent review waiter subagent holds the wait; the main agent keeps working and is woken when you Finish. |
|
|
32
|
-
| 🌐 | **Remote + cross-AI** | Planned:
|
|
32
|
+
| 🌐 | **Remote + cross-AI** | Planned: username+key web review, line-level AI comments, adversarial external-AI cross-review. |
|
|
33
33
|
|
|
34
34
|
All in one bundle — install once, use the gate and the time machine independently.
|
|
35
35
|
|
|
@@ -272,6 +272,7 @@ Open **Settings → Coding Enhanced** (the same controls appear on the plugin's
|
|
|
272
272
|
| **Automatic cleanup** | on | run `git gc` on shadow snapshots after pruning or withdrawing |
|
|
273
273
|
| **Clean up now** | — | prune extra snapshots and compact every shadow repository |
|
|
274
274
|
| **Updates** | — | check npm for the latest release and install it from the settings card; restart DSH after updating |
|
|
275
|
+
| **Review shell** | on | native `bash` is denied while Pre-review is on; commands go through `review_bash` (write detection + confirmation) |
|
|
275
276
|
|
|
276
277
|
Settings apply immediately and persist in `$DSH_HOME/coding-enhanced/settings.json`.
|
|
277
278
|
|
|
@@ -289,6 +290,11 @@ This is a convenience switch, separate from **Settings → Coding Enhanced → A
|
|
|
289
290
|
Change Review** (which enables the review tab and withdraw surfaces). More
|
|
290
291
|
review switches will be added to the same popover.
|
|
291
292
|
|
|
293
|
+
A separate **Web / Both / DSH** switch sits next to the shield and selects where
|
|
294
|
+
reviews are decided. **Web** uses only the standalone review server; **DSH**
|
|
295
|
+
uses only the sidebar review tab and keeps the outbound WSS stopped; **Both**
|
|
296
|
+
mirrors to both. Switching the channel is immediate and survives a restart.
|
|
297
|
+
|
|
292
298
|
### 4. Use the change gate
|
|
293
299
|
|
|
294
300
|
Ask the agent to change files → it queues them with `review_write` / `review_patch` → the **Code review** tab opens → decide per file
|
|
@@ -309,6 +315,46 @@ confirmation lists those turns.
|
|
|
309
315
|
|
|
310
316
|
---
|
|
311
317
|
|
|
318
|
+
## 🌐 Standalone web review
|
|
319
|
+
|
|
320
|
+
The standalone Web review app is **not part of the plugin tarball**. The npm
|
|
321
|
+
package ships only `lib/`, `docs/`, `README.md`, `CHANGELOG.md` and the bundle
|
|
322
|
+
patch; the React review UI and its Node server live in [`web/`](web/) in this
|
|
323
|
+
repository. Install the plugin normally if you only want the DSH sidebar review.
|
|
324
|
+
|
|
325
|
+
### Run the web app
|
|
326
|
+
|
|
327
|
+
Requires Node **>= 22.5**.
|
|
328
|
+
|
|
329
|
+
```sh
|
|
330
|
+
cd web
|
|
331
|
+
npm install
|
|
332
|
+
npm run build
|
|
333
|
+
node server/index.js --port 4317 --data ~/.dsh-coding-enhanced-web
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Open <http://localhost:4317>, register a username + user key (the key is shown
|
|
337
|
+
once), then generate a pairing code under **Devices**. In DSH open
|
|
338
|
+
**Settings → Coding Enhanced → Web review**, enter `http://localhost:4317` and
|
|
339
|
+
the code, and pair. Choose **Web** or **Both** in the input-bar **Review tools**
|
|
340
|
+
popover.
|
|
341
|
+
|
|
342
|
+
For Vite HMR during development, run the server with
|
|
343
|
+
`ORIGIN=http://localhost:5173` and use `npm run dev:web` (port 5173) instead of
|
|
344
|
+
the built page.
|
|
345
|
+
|
|
346
|
+
### Distribution
|
|
347
|
+
|
|
348
|
+
- **Plugin-only users**: install the tarball from Releases; no web assets are
|
|
349
|
+
downloaded.
|
|
350
|
+
- **Web review users**: clone the repository (or copy `web/`), then run the
|
|
351
|
+
build and server steps above. Ship `web/` source, or `web/dist` + `server/`
|
|
352
|
+
together; the server serves the built page and assets when `dist/index.html`
|
|
353
|
+
exists.
|
|
354
|
+
- Put the server behind HTTPS/reverse proxy and set `ORIGIN` for remote use.
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
312
358
|
<a id="how-it-works"></a>
|
|
313
359
|
|
|
314
360
|
## 🧠 How it works
|
|
@@ -398,7 +444,7 @@ The gate, the time machine, and the handoff are the product. The local diff UI
|
|
|
398
444
|
is deliberately simple; [`dsh-diff-approval`](https://github.com/9087/dsh-diff-approval)
|
|
399
445
|
already covers the “beautiful diff panel” case. Next:
|
|
400
446
|
|
|
401
|
-
- **P1 — standalone web review**:
|
|
447
|
+
- **P1 — standalone web review**: username+key pairing, always-on standby, outbound
|
|
402
448
|
WSS bridge, review display and decisions.
|
|
403
449
|
- **P2 — line-level AI comments (B)**: a dedicated comment subagent; line
|
|
404
450
|
selection; suggestions.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Review contract: prompts & chain
|
|
2
2
|
|
|
3
|
-
> Version: **0.8.
|
|
3
|
+
> Version: **0.8.5** · Date: 2026-11-22 · Source: `dsh-coding-enhanced`
|
|
4
4
|
>
|
|
5
5
|
> This document records the exact prompts, tool contracts and execution chain
|
|
6
6
|
> of the AI change-review workflow. It is intended as a reference for
|
|
@@ -304,10 +304,40 @@ dropped:
|
|
|
304
304
|
- npm publishing uses Trusted Publishing (OIDC); the registry CDN may lag a few
|
|
305
305
|
minutes after the workflow succeeds.
|
|
306
306
|
- The review contract is versioned with the plugin; this document describes
|
|
307
|
-
0.8.
|
|
307
|
+
0.8.5.
|
|
308
308
|
|
|
309
309
|
---
|
|
310
310
|
|
|
311
|
+
## 7.1 Shell gate (0.8.5)
|
|
312
|
+
|
|
313
|
+
Native `bash` is denied while Pre-review is on. All commands go through the
|
|
314
|
+
plugin tool `review_bash`:
|
|
315
|
+
|
|
316
|
+
```text
|
|
317
|
+
review_bash({ command, confirmed?, cwd? })
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
- First call: write detection only, no execution. Returns the reasons and a
|
|
321
|
+
self-check prompt.
|
|
322
|
+
- The agent self-checks whether the command creates/modifies/deletes files.
|
|
323
|
+
- If it writes source: use `review_write` / `review_patch`.
|
|
324
|
+
- If it writes nothing: call again with `confirmed: true`.
|
|
325
|
+
- Second call: re-detect, then run `/bin/sh -c` with the session cwd.
|
|
326
|
+
|
|
327
|
+
Write detection covers shell redirection, `tee`, `sed -i`, `perl -i`,
|
|
328
|
+
`cp/mv/rm/rmdir/mkdir/touch/ln/chmod`, `git apply`, `patch`, dependency
|
|
329
|
+
installs, and inline Python/Node writes. Writes under `dist`, `build`, `out`,
|
|
330
|
+
`target`, `node_modules`, `.next`, `.cache`, `coverage`, `.vitest`,
|
|
331
|
+
`__pycache__`, `.pytest_cache`, `.turbo` are build/test artifacts and pass.
|
|
332
|
+
|
|
333
|
+
### Post-turn audit
|
|
334
|
+
|
|
335
|
+
At `turn/end` the host diffs the turn-start snapshot against the current
|
|
336
|
+
workspace, subtracts reviewed paths and artifact paths, and stores the
|
|
337
|
+
remaining files as `audits[sessionId].outside`. The review tab shows a warning
|
|
338
|
+
listing them; the user can withdraw the turn or accept. The audit is a
|
|
339
|
+
backstop for writes the shell detection missed; it does not auto-revert.
|
|
340
|
+
|
|
311
341
|
## 8. Version history (review workflow)
|
|
312
342
|
|
|
313
343
|
| Version | Change |
|
|
@@ -317,3 +347,4 @@ dropped:
|
|
|
317
347
|
| 0.8.0–0.8.2 | Plugin-owned persistent waiter via `ctx.subagents` (agent-scoped tool, `spawn`) |
|
|
318
348
|
| 0.8.3 | Parent-written explanations; per-file notes validation; comment subagent dropped |
|
|
319
349
|
| 0.8.4 | Copy fixes; this document |
|
|
350
|
+
| 0.8.5 | Native bash denied; `review_bash` with two-step confirmation and write detection; post-turn audit; read/edit/run prompt |
|
package/lib/client.js
CHANGED
|
@@ -42,6 +42,21 @@ window.__ModuleLoader__.load({
|
|
|
42
42
|
autoReview: 'Pre-review',
|
|
43
43
|
aiExplain: 'AI explanations',
|
|
44
44
|
aiExplainDesc: 'Require at least one note per changed file. Off: queue changes without notes.',
|
|
45
|
+
channelLabel: 'Review channel',
|
|
46
|
+
channelHint: 'Where reviews are decided: the standalone web server, both surfaces, or the DSH sidebar only.',
|
|
47
|
+
channelWeb: 'Web',
|
|
48
|
+
channelBoth: 'Both',
|
|
49
|
+
channelBuiltin: 'DSH',
|
|
50
|
+
webTitle: 'Web review',
|
|
51
|
+
webDesc: 'Pair a standalone review server. DSH stays authoritative; the web UI only mirrors reviews.',
|
|
52
|
+
webUrlPlaceholder: 'http://localhost:4317',
|
|
53
|
+
webCodePlaceholder: 'Pairing code',
|
|
54
|
+
webPair: 'Pair',
|
|
55
|
+
webDisconnect: 'Disconnect',
|
|
56
|
+
webOnline: 'online',
|
|
57
|
+
webOffline: 'offline',
|
|
58
|
+
webUnpaired: 'not paired',
|
|
59
|
+
settingsGroupWeb: 'Web review',
|
|
45
60
|
autoReviewDesc: 'The agent must queue every edit with review_write / review_patch before it lands. Off: native write/edit.',
|
|
46
61
|
reviewFeatureOff: 'AI Change Review is off in Settings. Enable it first, then use this switch.',
|
|
47
62
|
reviewOn: 'On',
|
|
@@ -95,7 +110,7 @@ window.__ModuleLoader__.load({
|
|
|
95
110
|
pillarGate: 'Pre-write gate',
|
|
96
111
|
pillarRewind: 'Multi-turn rewind',
|
|
97
112
|
pillarWaiter: 'Non-blocking waiter',
|
|
98
|
-
pillarRemote: '
|
|
113
|
+
pillarRemote: 'Web review + cross-AI · next',
|
|
99
114
|
settingsReview: 'AI Change Review',
|
|
100
115
|
settingsReviewDesc: 'Queue every write/edit in the review tab; nothing lands until you finish. The main agent keeps working while the review waits.',
|
|
101
116
|
settingsWithdraw: 'Turn Withdraw',
|
|
@@ -123,6 +138,8 @@ window.__ModuleLoader__.load({
|
|
|
123
138
|
settingsAboutTitle: 'Coding Enhanced',
|
|
124
139
|
settingsAboutDesc: 'The DSH change gate: pre-write review, multi-turn withdraw, and a non-blocking review handoff. The full README lives on the plugin page and in the repository.',
|
|
125
140
|
settingsReadme: 'Open the full README',
|
|
141
|
+
auditTitle: 'Changed outside review',
|
|
142
|
+
auditDesc: 'Files changed outside review: {files}. Withdraw the turn or accept the change.',
|
|
126
143
|
settingsUpdates: 'Plugin updates',
|
|
127
144
|
settingsUpdatesDesc: 'Check npm for the latest release and install it from here.',
|
|
128
145
|
settingsCurrentVersion: 'Current version',
|
|
@@ -154,6 +171,21 @@ window.__ModuleLoader__.load({
|
|
|
154
171
|
autoReview: 'AI 改动预审查',
|
|
155
172
|
aiExplain: 'AI 解释',
|
|
156
173
|
aiExplainDesc: '每个改动文件至少一条说明。关闭后排队不再要求解释。',
|
|
174
|
+
channelLabel: 'Review 通道',
|
|
175
|
+
channelHint: '在哪里处理 review:独立 Web 服务、两者,或仅 DSH 侧栏。',
|
|
176
|
+
channelWeb: 'Web',
|
|
177
|
+
channelBoth: '两者',
|
|
178
|
+
channelBuiltin: 'DSH',
|
|
179
|
+
webTitle: '网页 review',
|
|
180
|
+
webDesc: '配对独立 review 服务;DSH 仍是权威,网页只镜像 review。',
|
|
181
|
+
webUrlPlaceholder: 'http://localhost:4317',
|
|
182
|
+
webCodePlaceholder: '配对码',
|
|
183
|
+
webPair: '配对',
|
|
184
|
+
webDisconnect: '断开',
|
|
185
|
+
webOnline: '在线',
|
|
186
|
+
webOffline: '离线',
|
|
187
|
+
webUnpaired: '未配对',
|
|
188
|
+
settingsGroupWeb: '网页 review',
|
|
157
189
|
autoReviewDesc: 'AI 的每次改动都必须先进入 review(review_write / review_patch)才能落盘。关闭后走原生 write/edit。',
|
|
158
190
|
reviewFeatureOff: '设置里的 AI Change Review 处于关闭状态,先启用后再用这个开关。',
|
|
159
191
|
reviewOn: '开',
|
|
@@ -206,7 +238,7 @@ window.__ModuleLoader__.load({
|
|
|
206
238
|
pillarGate: '写入前闸门',
|
|
207
239
|
pillarRewind: '多轮回退',
|
|
208
240
|
pillarWaiter: '非阻塞 waiter',
|
|
209
|
-
pillarRemote: '
|
|
241
|
+
pillarRemote: 'Web review + 跨 AI · 下一步',
|
|
210
242
|
settingsReview: 'AI 改动审查',
|
|
211
243
|
settingsReviewDesc: '每次 write/edit 先进入审查页,Finish 前不落盘;review 等待期间主 agent 可以继续工作。',
|
|
212
244
|
settingsWithdraw: '撤回本轮',
|
|
@@ -234,6 +266,8 @@ window.__ModuleLoader__.load({
|
|
|
234
266
|
settingsAboutTitle: 'Coding Enhanced',
|
|
235
267
|
settingsAboutDesc: 'DSH 变更闸门:写入前审查、多轮回退、非阻塞 review 交接。完整 README 在插件页和仓库里。',
|
|
236
268
|
settingsReadme: '打开完整 README',
|
|
269
|
+
auditTitle: 'review 外改动',
|
|
270
|
+
auditDesc: '以下文件在 review 外被修改:{files}。可撤回这一轮或接受改动。',
|
|
237
271
|
settingsUpdates: '插件更新',
|
|
238
272
|
settingsUpdatesDesc: '检查 npm 最新版本,并在这里安装。',
|
|
239
273
|
settingsCurrentVersion: '当前版本',
|
|
@@ -321,6 +355,13 @@ window.__ModuleLoader__.load({
|
|
|
321
355
|
.ce-review-trigger.disabled{opacity:.5}
|
|
322
356
|
.ce-review-dot{position:absolute;right:3px;bottom:3px;width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-label-tertiary,#bbb);box-shadow:0 0 0 2px var(--dsw-alias-bg-base,#fff)}
|
|
323
357
|
.ce-review-dot.on{background:var(--dsw-alias-state-success-primary,#2da44e)}
|
|
358
|
+
.ce-channel-switch{display:inline-flex;align-items:center;gap:1px;padding:2px;border-radius:999px;background:var(--dsw-alias-interactive-bg-hover);border:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08))}
|
|
359
|
+
.ce-channel-option{height:calc(22px + var(--dsh-content-font-delta,0px));padding:0 .5em;border:0;border-radius:999px;background:transparent;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:calc(11px + var(--dsh-content-font-delta,0px));line-height:1;cursor:pointer;white-space:nowrap}
|
|
360
|
+
.ce-channel-option:hover:not(:disabled){color:var(--dsw-alias-label-primary)}
|
|
361
|
+
.ce-channel-option.on{background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary);box-shadow:0 1px 2px rgba(0,0,0,.12)}
|
|
362
|
+
.ce-channel-option:disabled{cursor:default;opacity:.6}
|
|
363
|
+
.ce-review-row.ce-channel-row{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:start;gap:12px}
|
|
364
|
+
.ce-review-row.ce-channel-row .ce-channel-switch{margin-left:0;justify-self:end}
|
|
324
365
|
.ce-review-popover{z-index:10000;box-sizing:border-box;padding:14px;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.12));border-radius:14px;background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 12px 36px rgba(0,0,0,.18);color:var(--dsw-alias-label-primary,#1a1a1a);font-size:14px}
|
|
325
366
|
.ce-review-head{display:flex;align-items:center;justify-content:space-between;gap:8px}
|
|
326
367
|
.ce-review-title{font-size:14px;font-weight:600;line-height:20px}
|
|
@@ -334,6 +375,9 @@ window.__ModuleLoader__.load({
|
|
|
334
375
|
.wr-diff-resize{flex:none;height:.75em;min-height:10px;cursor:ns-resize;background:linear-gradient(to bottom,transparent,color-mix(in srgb,var(--dsw-alias-border-l1,rgba(0,0,0,.08)) 60%,transparent));position:relative}
|
|
335
376
|
.wr-diff-resize::after{content:'';position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:2.4em;height:.25em;border-radius:999px;background:var(--dsw-alias-border-l3,rgba(0,0,0,.18))}
|
|
336
377
|
.wr-diff-resize:hover{background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4d6bfe) 12%,transparent)}
|
|
378
|
+
.wr-audit{margin:.55em .7em .2em;padding:.55em .7em;border-radius:.5em;border:1px solid color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 35%,transparent);background:color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 8%,transparent);font-size:.82em;line-height:1.5}
|
|
379
|
+
.wr-audit-title{font-weight:600;color:var(--dsw-alias-state-warn-primary,#9a6700)}
|
|
380
|
+
.wr-audit-desc{margin-top:.2em;color:var(--dsw-alias-label-secondary,#555);white-space:pre-wrap;overflow-wrap:anywhere}
|
|
337
381
|
.wr-ai-line{background:linear-gradient(90deg,rgba(124,58,237,.10),rgba(217,70,239,.07) 55%,rgba(34,211,238,.05));box-shadow:inset 2px 0 0 #a855f7;cursor:help}
|
|
338
382
|
.wr-ai-line:hover{background:linear-gradient(90deg,rgba(124,58,237,.15),rgba(217,70,239,.10) 55%,rgba(34,211,238,.07))}
|
|
339
383
|
.wr-ai-line .wr-no{background:rgba(168,85,247,.10);color:transparent}
|
|
@@ -432,6 +476,25 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
432
476
|
}
|
|
433
477
|
}
|
|
434
478
|
|
|
479
|
+
// -------------------------------------------------- review channel ---
|
|
480
|
+
// Which review surface is live: 'web' (standalone server only),
|
|
481
|
+
// 'builtin' (DSH sidebar only), or 'both'. The host mirrors settings.
|
|
482
|
+
const REVIEW_CHANNELS = new Set(['web', 'both', 'builtin'])
|
|
483
|
+
let reviewChannel = 'both'
|
|
484
|
+
const channelListeners = new Set()
|
|
485
|
+
const getReviewChannel = () => reviewChannel
|
|
486
|
+
const subscribeReviewChannel = (listener) => {
|
|
487
|
+
channelListeners.add(listener)
|
|
488
|
+
return () => {
|
|
489
|
+
channelListeners.delete(listener)
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
const setReviewChannel = (value) => {
|
|
493
|
+
if (!REVIEW_CHANNELS.has(value) || value === reviewChannel) return
|
|
494
|
+
reviewChannel = value
|
|
495
|
+
for (const listener of [...channelListeners]) listener()
|
|
496
|
+
}
|
|
497
|
+
|
|
435
498
|
// -------------------------------------------------- withdraw store ---
|
|
436
499
|
const records = new Map()
|
|
437
500
|
const listeners = new Map()
|
|
@@ -858,6 +921,7 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
858
921
|
const feed = {
|
|
859
922
|
version: -1,
|
|
860
923
|
reviews: [],
|
|
924
|
+
audits: {},
|
|
861
925
|
loaded: false,
|
|
862
926
|
error: null,
|
|
863
927
|
listeners: new Set(),
|
|
@@ -889,6 +953,7 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
889
953
|
}
|
|
890
954
|
feed.version = result.value.version
|
|
891
955
|
feed.reviews = result.value.reviews ?? []
|
|
956
|
+
feed.audits = result.value.audits ?? {}
|
|
892
957
|
feed.error = null
|
|
893
958
|
feed.loaded = true
|
|
894
959
|
feedNotify()
|
|
@@ -963,22 +1028,25 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
963
1028
|
const { sessionId, t } = props
|
|
964
1029
|
const state = useReviews()
|
|
965
1030
|
const tabs = useOpenTabs()
|
|
1031
|
+
const channel = React.useSyncExternalStore(subscribeReviewChannel, getReviewChannel)
|
|
966
1032
|
const review = pendingReview(state.reviews)
|
|
1033
|
+
const audit = state.audits?.[sessionId]
|
|
1034
|
+
const auditOutside = Array.isArray(audit?.outside) ? audit.outside : []
|
|
967
1035
|
const opened = React.useRef(null)
|
|
968
1036
|
const tabOpen = tabs.some((tab) => tab.kind === REVIEW_KIND && tab.sessionId === sessionId)
|
|
969
1037
|
|
|
970
1038
|
React.useEffect(() => {
|
|
971
|
-
if (!state.loaded || review === undefined) return
|
|
1039
|
+
if (channel === 'web' || !state.loaded || review === undefined) return
|
|
972
1040
|
if (opened.current === review.id) return
|
|
973
1041
|
opened.current = review.id
|
|
974
1042
|
openReviewTab(review.id)
|
|
975
|
-
}, [state.loaded, review?.id])
|
|
1043
|
+
}, [state.loaded, review?.id, channel])
|
|
976
1044
|
|
|
977
1045
|
React.useEffect(() => {
|
|
978
1046
|
if (review === undefined) opened.current = null
|
|
979
1047
|
}, [review?.id])
|
|
980
1048
|
|
|
981
|
-
if (!state.loaded || review === undefined || tabOpen) return null
|
|
1049
|
+
if (channel === 'web' || !state.loaded || review === undefined || tabOpen) return null
|
|
982
1050
|
return ReactDOM.createPortal(
|
|
983
1051
|
React.createElement(
|
|
984
1052
|
'button',
|
|
@@ -1004,6 +1072,8 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1004
1072
|
const { tab } = useTabInfo()
|
|
1005
1073
|
const state = useReviews()
|
|
1006
1074
|
const review = pendingReview(state.reviews)
|
|
1075
|
+
const audit = state.audits?.[sessionId]
|
|
1076
|
+
const auditOutside = Array.isArray(audit?.outside) ? audit.outside : []
|
|
1007
1077
|
const [local, setLocal] = React.useState({})
|
|
1008
1078
|
const [submitting, setSubmitting] = React.useState(false)
|
|
1009
1079
|
const [error, setError] = React.useState(null)
|
|
@@ -1377,6 +1447,14 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1377
1447
|
: `${review.entries.length} files`,
|
|
1378
1448
|
),
|
|
1379
1449
|
),
|
|
1450
|
+
auditOutside.length > 0
|
|
1451
|
+
? React.createElement(
|
|
1452
|
+
'div',
|
|
1453
|
+
{ className: 'wr-audit' },
|
|
1454
|
+
React.createElement('div', { className: 'wr-audit-title' }, typeof t === 'function' ? t('auditTitle') : 'Changed outside review'),
|
|
1455
|
+
React.createElement('div', { className: 'wr-audit-desc' }, typeof t === 'function' ? t('auditDesc', { files: auditOutside.join(', ') }) : `Files changed outside review: ${auditOutside.join(', ')}`),
|
|
1456
|
+
)
|
|
1457
|
+
: null,
|
|
1380
1458
|
!submitted
|
|
1381
1459
|
? React.createElement('div', { className: 'wr-collecting' }, typeof t === 'function' ? t('collecting') : 'Waiting for the agent to submit.')
|
|
1382
1460
|
: null,
|
|
@@ -1493,9 +1571,9 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1493
1571
|
className: 'ce-review-popover',
|
|
1494
1572
|
style: {
|
|
1495
1573
|
position: 'fixed',
|
|
1496
|
-
left: `${Math.max(8, Math.min(window.innerWidth -
|
|
1574
|
+
left: `${Math.max(8, Math.min(window.innerWidth - 368, rect.left))}px`,
|
|
1497
1575
|
bottom: `${Math.max(8, window.innerHeight - rect.top + 8)}px`,
|
|
1498
|
-
width: '
|
|
1576
|
+
width: 'min(360px, calc(100vw - 16px))',
|
|
1499
1577
|
},
|
|
1500
1578
|
},
|
|
1501
1579
|
React.createElement(
|
|
@@ -1537,6 +1615,17 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1537
1615
|
React.createElement('span', { className: 'ce-switch-thumb' }),
|
|
1538
1616
|
),
|
|
1539
1617
|
),
|
|
1618
|
+
React.createElement(
|
|
1619
|
+
'div',
|
|
1620
|
+
{ className: 'ce-review-row ce-channel-row' },
|
|
1621
|
+
React.createElement(
|
|
1622
|
+
'div',
|
|
1623
|
+
{ className: 'ce-review-text' },
|
|
1624
|
+
React.createElement('div', { className: 'ce-review-row-title' }, typeof t === 'function' ? t('channelLabel') : 'Review channel'),
|
|
1625
|
+
React.createElement('div', { className: 'ce-review-row-desc' }, typeof t === 'function' ? t('channelHint') : ''),
|
|
1626
|
+
),
|
|
1627
|
+
React.createElement(ReviewModeSwitch, { t }),
|
|
1628
|
+
),
|
|
1540
1629
|
React.createElement(
|
|
1541
1630
|
'div',
|
|
1542
1631
|
{ className: 'ce-review-row' },
|
|
@@ -1588,7 +1677,118 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1588
1677
|
)
|
|
1589
1678
|
}
|
|
1590
1679
|
|
|
1680
|
+
function ReviewModeSwitch({ t }) {
|
|
1681
|
+
const channel = React.useSyncExternalStore(subscribeReviewChannel, getReviewChannel)
|
|
1682
|
+
const [busy, setBusy] = React.useState(false)
|
|
1683
|
+
const label = (key, fallback) => (typeof t === 'function' ? t(key) : fallback)
|
|
1684
|
+
const options = [
|
|
1685
|
+
{ value: 'web', text: label('channelWeb', 'Web') },
|
|
1686
|
+
{ value: 'both', text: label('channelBoth', 'Both') },
|
|
1687
|
+
{ value: 'builtin', text: label('channelBuiltin', 'DSH') },
|
|
1688
|
+
]
|
|
1689
|
+
const choose = async (value) => {
|
|
1690
|
+
if (busy || value === channel) return
|
|
1691
|
+
setBusy(true)
|
|
1692
|
+
const result = await call('setSettings', { reviewChannel: value })
|
|
1693
|
+
setBusy(false)
|
|
1694
|
+
if (result.ok === true) setReviewChannel(result.value.reviewChannel)
|
|
1695
|
+
}
|
|
1696
|
+
return React.createElement(
|
|
1697
|
+
'div',
|
|
1698
|
+
{
|
|
1699
|
+
className: 'ce-channel-switch',
|
|
1700
|
+
role: 'group',
|
|
1701
|
+
'aria-label': label('channelLabel', 'Review channel'),
|
|
1702
|
+
title: label('channelHint', 'Where reviews are decided'),
|
|
1703
|
+
},
|
|
1704
|
+
options.map((option) =>
|
|
1705
|
+
React.createElement(
|
|
1706
|
+
'button',
|
|
1707
|
+
{
|
|
1708
|
+
key: option.value,
|
|
1709
|
+
type: 'button',
|
|
1710
|
+
className: `ce-channel-option${channel === option.value ? ' on' : ''}`,
|
|
1711
|
+
'aria-pressed': channel === option.value,
|
|
1712
|
+
disabled: busy,
|
|
1713
|
+
onClick: () => { void choose(option.value) },
|
|
1714
|
+
},
|
|
1715
|
+
option.text,
|
|
1716
|
+
),
|
|
1717
|
+
),
|
|
1718
|
+
)
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1591
1721
|
// ------------------------------------------------- settings section ---
|
|
1722
|
+
function WebReviewCard({ t }) {
|
|
1723
|
+
const [status, setStatus] = React.useState(null)
|
|
1724
|
+
const [url, setUrl] = React.useState('')
|
|
1725
|
+
const [code, setCode] = React.useState('')
|
|
1726
|
+
const [busy, setBusy] = React.useState(false)
|
|
1727
|
+
const [message, setMessage] = React.useState(null)
|
|
1728
|
+
const label = (key, fallback) => (typeof t === 'function' ? t(key) : fallback)
|
|
1729
|
+
const refresh = async () => {
|
|
1730
|
+
const result = await call('webStatus')
|
|
1731
|
+
if (result.ok === true) setStatus(result.value)
|
|
1732
|
+
}
|
|
1733
|
+
React.useEffect(() => { void refresh() }, [])
|
|
1734
|
+
const pair = async () => {
|
|
1735
|
+
setBusy(true)
|
|
1736
|
+
setMessage(null)
|
|
1737
|
+
try {
|
|
1738
|
+
const result = await call('webPair', { url, code })
|
|
1739
|
+
if (result.ok === true) {
|
|
1740
|
+
const value = result.value ?? {}
|
|
1741
|
+
if (value.ok === false) setMessage(value.error ?? 'pair failed')
|
|
1742
|
+
else {
|
|
1743
|
+
setCode('')
|
|
1744
|
+
setStatus(value.status ?? null)
|
|
1745
|
+
await refresh()
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
} catch (error) {
|
|
1749
|
+
setMessage(String(error))
|
|
1750
|
+
} finally {
|
|
1751
|
+
setBusy(false)
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
const disconnect = async () => {
|
|
1755
|
+
setBusy(true)
|
|
1756
|
+
try {
|
|
1757
|
+
const result = await call('webDisconnect')
|
|
1758
|
+
if (result.ok === true) setStatus(result.value)
|
|
1759
|
+
} catch (error) {
|
|
1760
|
+
setMessage(String(error))
|
|
1761
|
+
} finally {
|
|
1762
|
+
setBusy(false)
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
const paired = status?.paired === true
|
|
1766
|
+
const connected = status?.connected === true
|
|
1767
|
+
return React.createElement(
|
|
1768
|
+
'div',
|
|
1769
|
+
{ className: 'ce-card' },
|
|
1770
|
+
React.createElement(
|
|
1771
|
+
'div',
|
|
1772
|
+
{ className: 'ce-row' },
|
|
1773
|
+
React.createElement(
|
|
1774
|
+
'div',
|
|
1775
|
+
{ className: 'ce-row-text' },
|
|
1776
|
+
React.createElement('div', { className: 'ce-row-title' }, label('webTitle', 'Web review')),
|
|
1777
|
+
React.createElement('div', { className: 'ce-row-desc' }, label('webDesc', 'Pair a standalone review server. DSH stays authoritative; the web UI only mirrors reviews.')),
|
|
1778
|
+
),
|
|
1779
|
+
React.createElement('span', { className: 'ce-row-desc' }, paired ? (connected ? label('webOnline', 'online') : label('webOffline', 'offline')) : label('webUnpaired', 'not paired')),
|
|
1780
|
+
),
|
|
1781
|
+
React.createElement(
|
|
1782
|
+
'div',
|
|
1783
|
+
{ style: { display: 'flex', gap: '8px', flexWrap: 'wrap', padding: '0 1em 1em' } },
|
|
1784
|
+
React.createElement('input', { className: 'ce-number', style: { flex: '1 1 220px' }, placeholder: label('webUrlPlaceholder', 'http://localhost:4317'), value: url, disabled: busy, onChange: (event) => setUrl(event.target.value) }),
|
|
1785
|
+
React.createElement('input', { className: 'ce-number', style: { width: '120px' }, placeholder: label('webCodePlaceholder', 'Pairing code'), value: code, disabled: busy, onChange: (event) => setCode(event.target.value.toUpperCase()) }),
|
|
1786
|
+
React.createElement('button', { type: 'button', className: 'ce-action primary', disabled: busy || url.trim() === '' || code.trim() === '', onClick: () => { void pair() } }, busy ? '…' : label('webPair', 'Pair')),
|
|
1787
|
+
paired ? React.createElement('button', { type: 'button', className: 'ce-action', disabled: busy, onClick: () => { void disconnect() } }, label('webDisconnect', 'Disconnect')) : null,
|
|
1788
|
+
),
|
|
1789
|
+
message !== null ? React.createElement('div', { className: 'ce-row-desc', style: { padding: '0 1em 1em' } }, message) : null,
|
|
1790
|
+
)
|
|
1791
|
+
}
|
|
1592
1792
|
function SettingsSection({ t, compact }) {
|
|
1593
1793
|
const [flags, setFlags] = React.useState(null)
|
|
1594
1794
|
const [busy, setBusy] = React.useState(null)
|
|
@@ -1824,6 +2024,8 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1824
2024
|
row('review', typeof t === 'function' ? t('settingsReview') : 'AI Change Review', typeof t === 'function' ? t('settingsReviewDesc') : ''),
|
|
1825
2025
|
row('aiExplain', typeof t === 'function' ? t('aiExplain') : 'AI explanations', typeof t === 'function' ? t('aiExplainDesc') : 'Require a short note for every added group. Off: queue changes without notes.'),
|
|
1826
2026
|
),
|
|
2027
|
+
React.createElement('div', { className: 'ce-group-title' }, typeof t === 'function' ? t('settingsGroupWeb') : 'Web review'),
|
|
2028
|
+
React.createElement(WebReviewCard, { t }),
|
|
1827
2029
|
React.createElement('div', { className: 'ce-group-title' }, typeof t === 'function' ? t('settingsGroupWithdraw') : 'Turn withdraw'),
|
|
1828
2030
|
React.createElement(
|
|
1829
2031
|
'div',
|
|
@@ -1933,16 +2135,74 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1933
2135
|
}, 1000)
|
|
1934
2136
|
return () => window.clearInterval(timer)
|
|
1935
2137
|
}, 'coding-enhanced: withdrawn turn markers')
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
2138
|
+
|
|
2139
|
+
// The channel is imperative rather than a one-shot ctx.effect: switching
|
|
2140
|
+
// to 'web' removes the DSH tab (and closes open ones) without a reload;
|
|
2141
|
+
// switching back registers it again.
|
|
2142
|
+
let sidebarTypeDispose = null
|
|
2143
|
+
let sidebarPaneDispose = null
|
|
2144
|
+
let sidebarRegistered = false
|
|
2145
|
+
|
|
2146
|
+
const closeReviewTabs = () => {
|
|
2147
|
+
try {
|
|
2148
|
+
const open = ctx.sidebarRight?.openTabs?.getSnapshot?.() ?? []
|
|
2149
|
+
for (const tab of open) {
|
|
2150
|
+
if (tab.kind !== REVIEW_KIND) continue
|
|
2151
|
+
ctx.sidebarRight.closeIn(tab.sessionId, tab.tabId)
|
|
2152
|
+
}
|
|
2153
|
+
} catch (error) {
|
|
2154
|
+
ctx.logger?.warn?.(`coding-enhanced: cannot close the review tabs: ${String(error)}`)
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
const teardownReviewSidebar = () => {
|
|
2159
|
+
if (!sidebarRegistered) return
|
|
2160
|
+
sidebarRegistered = false
|
|
2161
|
+
closeReviewTabs()
|
|
2162
|
+
try { sidebarPaneDispose?.() } catch {}
|
|
2163
|
+
sidebarPaneDispose = null
|
|
2164
|
+
try { sidebarTypeDispose?.() } catch {}
|
|
2165
|
+
sidebarTypeDispose = null
|
|
1944
2166
|
}
|
|
1945
2167
|
|
|
2168
|
+
const ensureReviewSidebar = () => {
|
|
2169
|
+
if (reviewChannel === 'web') {
|
|
2170
|
+
teardownReviewSidebar()
|
|
2171
|
+
return
|
|
2172
|
+
}
|
|
2173
|
+
if (sidebarRegistered) return
|
|
2174
|
+
sidebarRegistered = true
|
|
2175
|
+
try {
|
|
2176
|
+
sidebarTypeDispose = ctx.sidebarRightTabs.register({
|
|
2177
|
+
id: REVIEW_TAB_ID,
|
|
2178
|
+
kind: REVIEW_KIND,
|
|
2179
|
+
title: () => (typeof bindT === 'function' ? bindT('reviewTitle') : 'Code review'),
|
|
2180
|
+
})
|
|
2181
|
+
sidebarPaneDispose = ctx.slots.inject('sidebar.right.pane.tab', () =>
|
|
2182
|
+
ctx.slots.register(
|
|
2183
|
+
{
|
|
2184
|
+
name: 'sidebar.right.pane.tab',
|
|
2185
|
+
key: REVIEW_TAB_ID,
|
|
2186
|
+
locale: NS,
|
|
2187
|
+
},
|
|
2188
|
+
ReviewTab,
|
|
2189
|
+
),
|
|
2190
|
+
)
|
|
2191
|
+
} catch (error) {
|
|
2192
|
+
sidebarRegistered = false
|
|
2193
|
+
ctx.logger?.warn?.(`coding-enhanced: cannot register the review tab: ${String(error)}`)
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
ctx.effect(() => {
|
|
2198
|
+
ensureReviewSidebar()
|
|
2199
|
+
return () => teardownReviewSidebar()
|
|
2200
|
+
}, 'coding-enhanced: review channel surfaces')
|
|
2201
|
+
subscribeReviewChannel(ensureReviewSidebar)
|
|
2202
|
+
void call('settings').then((result) => {
|
|
2203
|
+
if (result.ok === true) setReviewChannel(result.value.reviewChannel)
|
|
2204
|
+
})
|
|
2205
|
+
|
|
1946
2206
|
// ------------------------------------------------------------ slots ---
|
|
1947
2207
|
ctx.slots.inject('plugins.bundle.config', () =>
|
|
1948
2208
|
ctx.slots.register(
|
|
@@ -2020,17 +2280,6 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
2020
2280
|
),
|
|
2021
2281
|
)
|
|
2022
2282
|
|
|
2023
|
-
ctx.slots.inject('sidebar.right.pane.tab', () =>
|
|
2024
|
-
ctx.slots.register(
|
|
2025
|
-
{
|
|
2026
|
-
name: 'sidebar.right.pane.tab',
|
|
2027
|
-
key: REVIEW_TAB_ID,
|
|
2028
|
-
locale: NS,
|
|
2029
|
-
},
|
|
2030
|
-
ReviewTab,
|
|
2031
|
-
),
|
|
2032
|
-
)
|
|
2033
|
-
|
|
2034
2283
|
ctx.on('connection/reset', () => {
|
|
2035
2284
|
for (const sessionId of records.keys()) {
|
|
2036
2285
|
fetchedAt.delete(sessionId)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
const ARTIFACT_DIRS = ['dist', 'build', 'out', 'target', 'node_modules', '.next', '.cache', 'coverage', '.vitest', '__pycache__', '.pytest_cache', '.turbo', '.parcel-cache']
|
|
4
|
+
|
|
5
|
+
const cleanTarget = (value) => String(value).replace(/^['"]|['"]$/g, '').replace(/^\.\//, '')
|
|
6
|
+
|
|
7
|
+
const isArtifactPath = (value) => {
|
|
8
|
+
const cleaned = cleanTarget(value)
|
|
9
|
+
if (cleaned === '/dev/null' || cleaned.startsWith('/tmp/') || cleaned === '/tmp') return true
|
|
10
|
+
return ARTIFACT_DIRS.some((dir) => cleaned === dir || cleaned.startsWith(`${dir}/`) || cleaned.includes(`/${dir}/`))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const isInsideQuotes = (value, index) => {
|
|
14
|
+
let quote = null
|
|
15
|
+
for (let i = 0; i < index; i += 1) {
|
|
16
|
+
const ch = value[i]
|
|
17
|
+
if (quote !== null) {
|
|
18
|
+
if (ch === quote && value[i - 1] !== '\\') quote = null
|
|
19
|
+
} else if (ch === '"' || ch === "'") {
|
|
20
|
+
quote = ch
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return quote !== null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const isProtectedTarget = (target, cwd) => {
|
|
27
|
+
const cleaned = cleanTarget(target)
|
|
28
|
+
if (cleaned === '' || cleaned.startsWith('&') || /^\d+$/.test(cleaned)) return false
|
|
29
|
+
if (isArtifactPath(cleaned)) return false
|
|
30
|
+
const root = path.resolve(cwd)
|
|
31
|
+
const resolved = path.resolve(root, cleaned)
|
|
32
|
+
return resolved === root || resolved.startsWith(`${root}${path.sep}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const splitArgs = (value) => value.split(/\s+/).filter((part) => part !== '')
|
|
36
|
+
const optionless = (args) => args.filter((part) => !part.startsWith('-') && !part.includes('='))
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Detect shell commands that write protected workspace files.
|
|
40
|
+
*
|
|
41
|
+
* The unit of protection is a file target, not a command. Installs, builds,
|
|
42
|
+
* tests and environment commands pass; only targets inside the workspace that
|
|
43
|
+
* are not artifacts block. Ambiguous writes (patch/apply, git worktree,
|
|
44
|
+
* archives, wrapped commands, inline interpreters) require a second
|
|
45
|
+
* confirmation; the turn/end audit remains the backstop.
|
|
46
|
+
*/
|
|
47
|
+
export const detectShellWrites = (command, cwd) => {
|
|
48
|
+
const reasons = []
|
|
49
|
+
const targets = []
|
|
50
|
+
const add = (reason, target) => {
|
|
51
|
+
reasons.push(reason)
|
|
52
|
+
if (typeof target === 'string' && target !== '') targets.push(target)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (const match of command.matchAll(/(?:^|[^>=-])>{1,2}\s*([^\s;&|]+)/g)) {
|
|
56
|
+
const index = match.index + match[1].length
|
|
57
|
+
if (isInsideQuotes(command, index)) continue
|
|
58
|
+
const target = cleanTarget(match[2])
|
|
59
|
+
if (target.startsWith('&') || /^\d+$/.test(target)) continue
|
|
60
|
+
add('shell redirection', target)
|
|
61
|
+
}
|
|
62
|
+
for (const match of command.matchAll(/(?:^|[^>=-])>\|\s*([^\s;&|]+)/g)) {
|
|
63
|
+
const index = match.index + match[1].length
|
|
64
|
+
if (isInsideQuotes(command, index)) continue
|
|
65
|
+
add('shell redirection', cleanTarget(match[2]))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const tee = /\btee\s+(?:-[A-Za-z]+\s+)*([^\s;&|]+)/.exec(command)
|
|
69
|
+
if (tee !== null && !isInsideQuotes(command, tee.index + tee[0].lastIndexOf(tee[1]))) add('tee', tee[1])
|
|
70
|
+
const sed = /\bsed\s+(?:[^;&|]*\s)?-i(?:\.\w+)?\s+([^\s;&|]+)/.exec(command)
|
|
71
|
+
if (sed !== null) add('in-place edit', sed[1])
|
|
72
|
+
const perl = /\bperl\s+-i\s+([^\s;&|]+)/.exec(command)
|
|
73
|
+
if (perl !== null) add('in-place edit', perl[1])
|
|
74
|
+
const ruby = /\bruby\s+-i(?:\.\w+)?\s+([^\s;&|]+)/.exec(command)
|
|
75
|
+
if (ruby !== null) add('in-place edit', ruby[1])
|
|
76
|
+
const dd = /\bdd\b[^;&|]*\bof=([^\s;&|]+)/.exec(command)
|
|
77
|
+
if (dd !== null) add('dd', dd[1])
|
|
78
|
+
const curl = /\bcurl\b[^;&|]*\s-o\s*([^\s;&|]+)/.exec(command)
|
|
79
|
+
if (curl !== null) add('curl -o', curl[1])
|
|
80
|
+
const wget = /\bwget\b[^;&|]*\s-O\s*([^\s;&|]+)/.exec(command)
|
|
81
|
+
if (wget !== null) add('wget -O', wget[1])
|
|
82
|
+
|
|
83
|
+
const cp = /\bcp\b([^;&|]*)/.exec(command)
|
|
84
|
+
if (cp !== null) {
|
|
85
|
+
const args = optionless(splitArgs(cp[1]))
|
|
86
|
+
if (args.length > 0) add('cp', args[args.length - 1])
|
|
87
|
+
}
|
|
88
|
+
const mv = /\bmv\b([^;&|]*)/.exec(command)
|
|
89
|
+
if (mv !== null) {
|
|
90
|
+
for (const arg of optionless(splitArgs(mv[1]))) add('mv', arg)
|
|
91
|
+
}
|
|
92
|
+
const rm = /\brm\b([^;&|]*)/.exec(command)
|
|
93
|
+
if (rm !== null) {
|
|
94
|
+
for (const arg of optionless(splitArgs(rm[1]))) add('rm', arg)
|
|
95
|
+
}
|
|
96
|
+
const touch = /\btouch\b([^;&|]*)/.exec(command)
|
|
97
|
+
if (touch !== null) {
|
|
98
|
+
for (const arg of optionless(splitArgs(touch[1]))) add('touch', arg)
|
|
99
|
+
}
|
|
100
|
+
const ln = /\bln\b([^;&|]*)/.exec(command)
|
|
101
|
+
if (ln !== null) {
|
|
102
|
+
const args = optionless(splitArgs(ln[1]))
|
|
103
|
+
if (args.length > 0) add('ln', args[args.length - 1])
|
|
104
|
+
}
|
|
105
|
+
const rsync = /\brsync\b([^;&|]*)/.exec(command)
|
|
106
|
+
if (rsync !== null) {
|
|
107
|
+
const args = optionless(splitArgs(rsync[1]))
|
|
108
|
+
if (args.length > 0) add('rsync', args[args.length - 1])
|
|
109
|
+
}
|
|
110
|
+
const scp = /\bscp\b([^;&|]*)/.exec(command)
|
|
111
|
+
if (scp !== null) {
|
|
112
|
+
const args = optionless(splitArgs(scp[1]))
|
|
113
|
+
if (args.length > 0) add('scp', args[args.length - 1])
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const op of ['truncate', 'shred', 'unlink']) {
|
|
117
|
+
const match = new RegExp(`\\b${op}\\b([^;&|]*)`).exec(command)
|
|
118
|
+
if (match !== null) {
|
|
119
|
+
for (const arg of optionless(splitArgs(match[1]))) add(op, arg)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (/\bgit\s+apply\b/.test(command)) add('git apply')
|
|
124
|
+
if (/\bpatch\b/.test(command)) add('patch')
|
|
125
|
+
if (/\bgit\s+(?:restore|checkout\s+--|reset\s+--hard|clean\s+-[A-Za-z]*f[A-Za-z]*|stash)\b/.test(command)) add('git worktree write')
|
|
126
|
+
if (/\btar\b[^;&|]*\s-[A-Za-z]*x[A-Za-z]*/.test(command)) add('archive extract')
|
|
127
|
+
if (/\bunzip\b/.test(command)) add('archive extract')
|
|
128
|
+
if (/\bgit\s+clone\b/.test(command)) add('git clone')
|
|
129
|
+
if (/\b(?:bash|sh|zsh)\s+-c\b|\beval\b|\bsource\b|\bfind\b[^;&|]*\s-exec\b|\bxargs\b/.test(command)) add('wrapped command')
|
|
130
|
+
if (/\b(?:python3?|node|ruby|perl)\b/.test(command) && /\b(?:open|writeFileSync|writeFile|write_text|to_csv|savefig|fs\.write|shutil\.(?:copy|move|rmtree)|os\.(?:rename|remove|unlink))\b/.test(command)) add('inline write')
|
|
131
|
+
|
|
132
|
+
const protectedTargets = targets.filter((target) => isProtectedTarget(target, cwd))
|
|
133
|
+
const blocked = protectedTargets.length > 0
|
|
134
|
+
const needsConfirm = !blocked && reasons.length > 0
|
|
135
|
+
return { blocked, needsConfirm, reasons, targets, protectedTargets }
|
|
136
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -22,6 +22,8 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync } from '
|
|
|
22
22
|
import fs from 'node:fs/promises'
|
|
23
23
|
import os from 'node:os'
|
|
24
24
|
import path from 'node:path'
|
|
25
|
+
import { detectShellWrites } from './detect-writes.js'
|
|
26
|
+
import { createWebBridge } from './web-bridge.js'
|
|
25
27
|
import { fileURLToPath } from 'node:url'
|
|
26
28
|
|
|
27
29
|
export const name = 'coding-enhanced'
|
|
@@ -416,7 +418,8 @@ export function apply(ctx) {
|
|
|
416
418
|
const settingsPath = path.join(root, 'settings.json')
|
|
417
419
|
mkdirSync(root, { recursive: true })
|
|
418
420
|
|
|
419
|
-
const
|
|
421
|
+
const REVIEW_CHANNELS = new Set(['web', 'both', 'builtin'])
|
|
422
|
+
const featureFlags = { review: true, withdraw: true, autoReview: true, aiExplain: true, allowBlockingReviewWait: false, keepTurns: 10, nestedSnapshots: true, autoGc: true, reviewChannel: 'both', webUrl: '', webDeviceToken: '', webDeviceId: '' }
|
|
420
423
|
try {
|
|
421
424
|
const parsed = JSON.parse(readFileSync(settingsPath, 'utf8'))
|
|
422
425
|
if (typeof parsed.review === 'boolean') featureFlags.review = parsed.review
|
|
@@ -429,6 +432,10 @@ export function apply(ctx) {
|
|
|
429
432
|
}
|
|
430
433
|
if (typeof parsed.nestedSnapshots === 'boolean') featureFlags.nestedSnapshots = parsed.nestedSnapshots
|
|
431
434
|
if (typeof parsed.autoGc === 'boolean') featureFlags.autoGc = parsed.autoGc
|
|
435
|
+
if (REVIEW_CHANNELS.has(parsed.reviewChannel)) featureFlags.reviewChannel = parsed.reviewChannel
|
|
436
|
+
if (typeof parsed.webUrl === 'string') featureFlags.webUrl = parsed.webUrl
|
|
437
|
+
if (typeof parsed.webDeviceToken === 'string') featureFlags.webDeviceToken = parsed.webDeviceToken
|
|
438
|
+
if (typeof parsed.webDeviceId === 'string') featureFlags.webDeviceId = parsed.webDeviceId
|
|
432
439
|
} catch {}
|
|
433
440
|
|
|
434
441
|
const saveFeatureFlags = () => {
|
|
@@ -867,15 +874,55 @@ export function apply(ctx) {
|
|
|
867
874
|
|
|
868
875
|
// ------------------------------------------------------- review gate ---
|
|
869
876
|
const REVIEW_TOOLS = new Set(['write', 'edit', 'apply_patch', 'str_replace_editor', 'multi_edit', 'notebook_edit'])
|
|
877
|
+
const ARTIFACT_DIRS = ['dist', 'build', 'out', 'target', 'node_modules', '.next', '.cache', 'coverage', '.vitest', '__pycache__', '.pytest_cache', '.turbo', '.parcel-cache']
|
|
878
|
+
const isArtifactPath = (value) => {
|
|
879
|
+
const cleaned = String(value).replace(/^['"]|['"]$/g, '').replace(/^\.\//, '')
|
|
880
|
+
if (cleaned === '/dev/null' || cleaned.startsWith('/tmp/') || cleaned === '/tmp') return true
|
|
881
|
+
return ARTIFACT_DIRS.some((dir) => cleaned === dir || cleaned.startsWith(`${dir}/`) || cleaned.includes(`/${dir}/`))
|
|
882
|
+
}
|
|
883
|
+
const detectShellWritesLegacy = (command) => {
|
|
884
|
+
const reasons = []
|
|
885
|
+
const targets = []
|
|
886
|
+
const add = (reason, target) => {
|
|
887
|
+
reasons.push(reason)
|
|
888
|
+
if (typeof target === 'string' && target !== '') targets.push(target)
|
|
889
|
+
}
|
|
890
|
+
for (const match of command.matchAll(/(?:^|[^>])>{1,2}\s*([^\s;&|]+)/g)) add('shell redirection', match[1])
|
|
891
|
+
const tee = /\btee\s+(?:-[A-Za-z]+\s+)*([^\s;&|]+)/.exec(command)
|
|
892
|
+
if (tee !== null) add('tee', tee[1])
|
|
893
|
+
const sed = /\bsed\s+(?:[^;&|]*\s)?-i(?:\.\w+)?\s+([^\s;&|]+)/.exec(command)
|
|
894
|
+
if (sed !== null) add('in-place edit', sed[1])
|
|
895
|
+
const perl = /\bperl\s+-i\s+([^\s;&|]+)/.exec(command)
|
|
896
|
+
if (perl !== null) add('in-place edit', perl[1])
|
|
897
|
+
for (const op of ['cp', 'mv', 'rm', 'rmdir', 'mkdir', 'touch', 'ln', 'chmod']) {
|
|
898
|
+
const match = new RegExp(`\\b${op}\\b([^;&|]*)`).exec(command)
|
|
899
|
+
if (match === null) continue
|
|
900
|
+
const args = match[1].split(/\s+/).filter((part) => part !== '' && !part.startsWith('-') && !part.includes('='))
|
|
901
|
+
add(op, args.length > 0 ? args[args.length - 1] : undefined)
|
|
902
|
+
}
|
|
903
|
+
if (/\bgit\s+apply\b/.test(command)) add('git apply')
|
|
904
|
+
if (/\bpatch\b/.test(command)) add('patch')
|
|
905
|
+
if (/\b(npm\s+(install|ci)|pnpm\s+add|yarn\s+add)\b/.test(command)) add('dependency install')
|
|
906
|
+
if (/\b(python3?|node)\b/.test(command) && /\b(open|writeFileSync|writeFile|write_text|to_csv|savefig|fs\.write)/.test(command)) add('inline write')
|
|
907
|
+
const sourceTargets = targets.filter((target) => !isArtifactPath(target))
|
|
908
|
+
const blocked = reasons.length > 0 && (sourceTargets.length > 0 || targets.length < reasons.length)
|
|
909
|
+
return { blocked, reasons, targets }
|
|
910
|
+
}
|
|
911
|
+
|
|
870
912
|
const MAX_REVIEW_FILE_BYTES = 2 * 1024 * 1024
|
|
871
913
|
const MAX_EDITABLE_BYTES = 200 * 1024
|
|
872
914
|
/** sessionId -> review { id, sessionId, entries, virtual, submitted, finished, canceled, waiters } */
|
|
873
915
|
const reviews = new Map()
|
|
874
916
|
const reviewWaiters = new Map()
|
|
917
|
+
const audits = new Map()
|
|
875
918
|
let reviewVersion = 0
|
|
919
|
+
let webBridge = null
|
|
876
920
|
|
|
877
921
|
const bumpReview = () => {
|
|
878
922
|
reviewVersion += 1
|
|
923
|
+
// The built-in channel has no web consumer; keep the bridge silent so the
|
|
924
|
+
// DSH sidebar stays the only review surface in that mode.
|
|
925
|
+
if (featureFlags.reviewChannel !== 'builtin') webBridge?.publishAll()
|
|
879
926
|
}
|
|
880
927
|
|
|
881
928
|
const ensureReview = (sessionId) => {
|
|
@@ -1112,6 +1159,29 @@ export function apply(ctx) {
|
|
|
1112
1159
|
})),
|
|
1113
1160
|
})
|
|
1114
1161
|
|
|
1162
|
+
webBridge = createWebBridge({
|
|
1163
|
+
getConfig: () => ({ url: featureFlags.webUrl, token: featureFlags.webDeviceToken, deviceId: featureFlags.webDeviceId }),
|
|
1164
|
+
saveConfig: (config) => {
|
|
1165
|
+
if (typeof config.url === 'string') featureFlags.webUrl = config.url
|
|
1166
|
+
if (typeof config.token === 'string') featureFlags.webDeviceToken = config.token
|
|
1167
|
+
if (typeof config.deviceId === 'string') featureFlags.webDeviceId = config.deviceId
|
|
1168
|
+
saveFeatureFlags()
|
|
1169
|
+
},
|
|
1170
|
+
isEnabled: () => featureFlags.reviewChannel !== 'builtin',
|
|
1171
|
+
serializeReview,
|
|
1172
|
+
getReviews: () => [...reviews.values()],
|
|
1173
|
+
getVersion: () => reviewVersion,
|
|
1174
|
+
pluginVersion: PLUGIN_VERSION,
|
|
1175
|
+
onDecision: (message) => {
|
|
1176
|
+
const result = decideReview(message.reviewId, message.decisions)
|
|
1177
|
+
if (result.ok !== true) {
|
|
1178
|
+
webBridge.send({ type: 'review.result', reviewId: message.reviewId, results: [], error: result.error ?? result.message ?? 'decision failed' })
|
|
1179
|
+
}
|
|
1180
|
+
},
|
|
1181
|
+
})
|
|
1182
|
+
// 'builtin' means DSH's own review UI only; do not open the outbound WSS.
|
|
1183
|
+
if (featureFlags.reviewChannel !== 'builtin') webBridge.start()
|
|
1184
|
+
|
|
1115
1185
|
const decideReview = (id, decisions) => {
|
|
1116
1186
|
const review = [...reviews.values()].find((candidate) => candidate.id === id)
|
|
1117
1187
|
if (review === undefined) return fail('review-not-found', 'This review is no longer open')
|
|
@@ -1126,9 +1196,14 @@ export function apply(ctx) {
|
|
|
1126
1196
|
const entries = [...review.entries.values()]
|
|
1127
1197
|
const missing = []
|
|
1128
1198
|
const tooLarge = []
|
|
1199
|
+
const stale = []
|
|
1129
1200
|
const normalized = new Map()
|
|
1130
1201
|
for (const entry of entries) {
|
|
1131
1202
|
const decision = byEntry.get(entry.id)
|
|
1203
|
+
if (decision !== undefined && decision !== null && typeof decision.baseAfterText === 'string' && entry.editable === true && entry.after !== decision.baseAfterText) {
|
|
1204
|
+
stale.push(entry.display)
|
|
1205
|
+
continue
|
|
1206
|
+
}
|
|
1132
1207
|
if (decision !== undefined && decision.outcome === 'edited') {
|
|
1133
1208
|
const text = decision.editedAfter
|
|
1134
1209
|
if (entry.editable !== true || typeof text !== 'string' || text === entry.after) {
|
|
@@ -1139,7 +1214,7 @@ export function apply(ctx) {
|
|
|
1139
1214
|
tooLarge.push(entry.display)
|
|
1140
1215
|
continue
|
|
1141
1216
|
}
|
|
1142
|
-
normalized.set(entry.id, { outcome: 'edited', editedAfter: text, comment: '' })
|
|
1217
|
+
normalized.set(entry.id, { outcome: 'edited', editedAfter: text, comment: typeof decision.comment === 'string' ? decision.comment.slice(0, 4000) : '' })
|
|
1143
1218
|
continue
|
|
1144
1219
|
}
|
|
1145
1220
|
if (decision === undefined || typeof decision.approved !== 'boolean') {
|
|
@@ -1153,6 +1228,7 @@ export function apply(ctx) {
|
|
|
1153
1228
|
}
|
|
1154
1229
|
if (missing.length > 0) return fail('incomplete', `No decision for: ${missing.join(', ')}`)
|
|
1155
1230
|
if (tooLarge.length > 0) return fail('edit-too-large', `The edited content is too large for: ${tooLarge.join(', ')}`)
|
|
1231
|
+
if (stale.length > 0) return fail('stale', `The file changed while you were reviewing: ${stale.join(', ')}. Reopen the review and decide again.`)
|
|
1156
1232
|
|
|
1157
1233
|
for (const entry of entries) {
|
|
1158
1234
|
const decision = normalized.get(entry.id)
|
|
@@ -1537,15 +1613,95 @@ export function apply(ctx) {
|
|
|
1537
1613
|
}), { when: () => featureFlags.review === true && featureFlags.autoReview === true })
|
|
1538
1614
|
}
|
|
1539
1615
|
|
|
1616
|
+
const execShell = (command, cwd) => new Promise((resolve) => {
|
|
1617
|
+
execFile('/bin/sh', ['-c', command], { cwd, maxBuffer: 8 * 1024 * 1024, env: process.env }, (error, stdout, stderr) => {
|
|
1618
|
+
resolve({ code: error === null ? 0 : (typeof error.code === 'number' ? error.code : 1), stdout: String(stdout ?? ''), stderr: String(stderr ?? '') })
|
|
1619
|
+
})
|
|
1620
|
+
})
|
|
1621
|
+
|
|
1622
|
+
const registerBashTool = () => {
|
|
1623
|
+
ctx.tools.register(defineTool({
|
|
1624
|
+
name: 'review_bash',
|
|
1625
|
+
description: 'Run a shell command for inspection or tests. The first call does not execute: it returns the write-detection result and asks you to self-check whether the command creates, modifies or deletes files. If it does, use review_write / review_patch instead. If it does not, call again with confirmed:true. The second call re-checks, then runs /bin/sh -c. Build/test artifacts under dist, build, node_modules and similar directories are allowed; writes to source are blocked.',
|
|
1626
|
+
parameters: {
|
|
1627
|
+
command: { type: 'string', required: true, description: 'Shell command to run.' },
|
|
1628
|
+
confirmed: { type: 'boolean', description: 'Set true only after you have checked that the command does not create, modify or delete source files.' },
|
|
1629
|
+
cwd: { type: 'string', description: 'Optional working directory; defaults to the session workspace.' },
|
|
1630
|
+
},
|
|
1631
|
+
output: {
|
|
1632
|
+
schema: {
|
|
1633
|
+
type: 'object',
|
|
1634
|
+
additionalProperties: false,
|
|
1635
|
+
properties: {
|
|
1636
|
+
status: { type: 'string' },
|
|
1637
|
+
command: { type: 'string' },
|
|
1638
|
+
writes: { type: 'boolean' },
|
|
1639
|
+
reasons: { type: 'array', items: { type: 'string' } },
|
|
1640
|
+
exitCode: { type: 'integer' },
|
|
1641
|
+
stdout: { type: 'string' },
|
|
1642
|
+
stderr: { type: 'string' },
|
|
1643
|
+
message: { type: 'string' },
|
|
1644
|
+
},
|
|
1645
|
+
},
|
|
1646
|
+
render: (_args, value) => [{ type: 'text', text: JSON.stringify(value, null, 2) }],
|
|
1647
|
+
},
|
|
1648
|
+
async execute(args, exec) {
|
|
1649
|
+
const session = exec.agent?.session
|
|
1650
|
+
if (session === undefined) return { status: 'error', command: '', writes: false, message: 'No active session.' }
|
|
1651
|
+
const command = typeof args?.command === 'string' ? args.command : ''
|
|
1652
|
+
if (command.trim() === '') return { status: 'error', command, writes: false, message: 'command is required.' }
|
|
1653
|
+
const base = typeof session.header?.cwd === 'string' && session.header.cwd !== '' ? session.header.cwd : process.cwd()
|
|
1654
|
+
const cwd = typeof args?.cwd === 'string' && args.cwd !== '' ? path.resolve(base, args.cwd) : base
|
|
1655
|
+
const detection = detectShellWrites(command, cwd)
|
|
1656
|
+
if (args?.confirmed !== true) {
|
|
1657
|
+
return {
|
|
1658
|
+
status: 'confirm',
|
|
1659
|
+
command,
|
|
1660
|
+
writes: detection.blocked,
|
|
1661
|
+
reasons: detection.reasons,
|
|
1662
|
+
message: detection.blocked
|
|
1663
|
+
? 'This command appears to write source files. Use review_write / review_patch for file changes.'
|
|
1664
|
+
: 'Self-check: does this command create, modify or delete files? If yes, use review_write / review_patch. If no, call review_bash again with confirmed:true.',
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
if (detection.blocked === true) {
|
|
1668
|
+
return {
|
|
1669
|
+
status: 'blocked',
|
|
1670
|
+
command,
|
|
1671
|
+
writes: true,
|
|
1672
|
+
reasons: detection.reasons,
|
|
1673
|
+
message: 'Write detection blocked this command. Use review_write / review_patch for file changes.',
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
const result = await execShell(command, cwd)
|
|
1677
|
+
return {
|
|
1678
|
+
status: result.code === 0 ? 'ok' : 'error',
|
|
1679
|
+
command,
|
|
1680
|
+
writes: false,
|
|
1681
|
+
reasons: detection.reasons,
|
|
1682
|
+
exitCode: result.code,
|
|
1683
|
+
stdout: result.stdout,
|
|
1684
|
+
stderr: result.stderr,
|
|
1685
|
+
}
|
|
1686
|
+
},
|
|
1687
|
+
}), { when: () => featureFlags.review === true && featureFlags.autoReview === true })
|
|
1688
|
+
}
|
|
1540
1689
|
|
|
1541
1690
|
registerReviewTools()
|
|
1691
|
+
registerBashTool()
|
|
1542
1692
|
|
|
1543
1693
|
const nativeGate = async (exec, next) => {
|
|
1544
1694
|
if (featureFlags.review !== true || featureFlags.autoReview !== true) return next()
|
|
1695
|
+
if (exec.name === 'bash') {
|
|
1696
|
+
return {
|
|
1697
|
+
kind: 'deny',
|
|
1698
|
+
reason: 'Use review_bash for shell commands while Pre-review is on. It self-checks writes and asks for a second confirmation; file changes must use review_write / review_patch. Do not use bash to write files.',
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1545
1701
|
if (!REVIEW_TOOLS.has(exec.name)) return next()
|
|
1546
1702
|
return {
|
|
1547
1703
|
kind: 'deny',
|
|
1548
|
-
reason: 'File changes must go through the review gate while Pre-review is on. Use review_write (new file / full file) or review_patch (unified diff) with at least one note per changed file; the plugin starts or reuses the review waiter automatically; just continue. Never call review_wait from the main agent.
|
|
1704
|
+
reason: 'File changes must go through the review gate while Pre-review is on. Use review_write (new file / full file) or review_patch (unified diff) with at least one note per changed file; the plugin starts or reuses the review waiter automatically; just continue. Never call review_wait from the main agent. Run shell commands with review_bash.',
|
|
1549
1705
|
}
|
|
1550
1706
|
}
|
|
1551
1707
|
|
|
@@ -1556,17 +1712,46 @@ export function apply(ctx) {
|
|
|
1556
1712
|
name: 'tool:review-gate',
|
|
1557
1713
|
order: 110,
|
|
1558
1714
|
text: () => featureFlags.review === true && featureFlags.autoReview === true
|
|
1559
|
-
? '🎟️ FILE-EDIT VELVET ROPE: The human personally reviews every file change.
|
|
1715
|
+
? '🎟️ FILE-EDIT VELVET ROPE: The human personally reviews every file change. Read with read; change files with review_write (new file / full file) or review_patch (unified diff); run commands with review_bash. Do not use write/edit/apply_patch/str_replace_editor. Never use bash to write files: review_bash first returns the write-detection result, you self-check whether the command creates/modifies/deletes files, and only a second call with confirmed:true runs it when it writes no source files. Include at least one note per changed file while AI explanations are on; add line-level notes for user-requested, key or hard-to-understand changes (no upper limit). The plugin starts or reuses the review waiter automatically: after queueing, just continue or end the turn; never call review_wait and do not manage a subagent. If a file is rejected, read the comment and revise. This is house rules. 💅'
|
|
1560
1716
|
: '',
|
|
1561
1717
|
}), 'coding-enhanced: review prompt')
|
|
1562
1718
|
})
|
|
1563
1719
|
|
|
1720
|
+
const runAudit = async (session, turn) => {
|
|
1721
|
+
try {
|
|
1722
|
+
const snapshot = snapshotOf(session.id, turn)
|
|
1723
|
+
if (snapshot === undefined) return
|
|
1724
|
+
const cwd = typeof session.header?.cwd === 'string' && session.header.cwd !== '' ? session.header.cwd : process.cwd()
|
|
1725
|
+
const review = reviews.get(session.id)
|
|
1726
|
+
const reviewed = review === undefined ? [] : [...review.entries.values()].map((entry) => entry.display)
|
|
1727
|
+
const base = await captureWorkspace(session.id, cwd)
|
|
1728
|
+
if (base === undefined) return
|
|
1729
|
+
const diff = await runGit(['diff', '--name-status', snapshot.tree, base.tree], { gitDir: snapshot.gitDir, workTree: cwd })
|
|
1730
|
+
const changed = diff.split('\n').map((line) => line.trim()).filter((line) => line !== '').map((line) => {
|
|
1731
|
+
const parts = line.split('\t')
|
|
1732
|
+
return parts.length >= 2 ? parts[parts.length - 1] : ''
|
|
1733
|
+
}).filter((value) => value !== '')
|
|
1734
|
+
const outside = changed.filter((file) => !reviewed.includes(file) && !isArtifactPath(file))
|
|
1735
|
+
audits.set(session.id, {
|
|
1736
|
+
turn,
|
|
1737
|
+
outside,
|
|
1738
|
+
reviewed,
|
|
1739
|
+
artifacts: changed.filter((file) => isArtifactPath(file)),
|
|
1740
|
+
at: Date.now(),
|
|
1741
|
+
})
|
|
1742
|
+
bumpReview()
|
|
1743
|
+
} catch (error) {
|
|
1744
|
+
ctx.logger?.warn?.(`coding-enhanced: audit failed: ${String(error)}`)
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1564
1748
|
ctx.on('session/event', (session, event) => {
|
|
1565
1749
|
if (event.type === 'turn/start') {
|
|
1566
1750
|
const cwd = session.header?.cwd
|
|
1567
1751
|
if (typeof cwd !== 'string' || cwd === '' || isSubagent(session)) return
|
|
1568
1752
|
const turn = event.data?.turn
|
|
1569
1753
|
activeTurns.set(session.id, turn)
|
|
1754
|
+
audits.delete(session.id)
|
|
1570
1755
|
if (featureFlags.withdraw === true) {
|
|
1571
1756
|
const promise = captureSnapshot(session.id, cwd, turn).catch((error) => {
|
|
1572
1757
|
ctx.logger?.warn?.(`coding-enhanced: cannot snapshot ${cwd}: ${String(error)}`)
|
|
@@ -1580,6 +1765,7 @@ export function apply(ctx) {
|
|
|
1580
1765
|
}
|
|
1581
1766
|
if (event.type === 'turn/end') {
|
|
1582
1767
|
const turn = event.data?.turn
|
|
1768
|
+
void runAudit(session, turn)
|
|
1583
1769
|
activeTurns.delete(session.id)
|
|
1584
1770
|
const review = reviews.get(session.id)
|
|
1585
1771
|
if (review !== undefined) {
|
|
@@ -2038,6 +2224,18 @@ export function apply(ctx) {
|
|
|
2038
2224
|
return fail('bad-request', 'settings patch must be an object')
|
|
2039
2225
|
}
|
|
2040
2226
|
let changed = false
|
|
2227
|
+
if (typeof patch.reviewChannel === 'string' && REVIEW_CHANNELS.has(patch.reviewChannel) && patch.reviewChannel !== featureFlags.reviewChannel) {
|
|
2228
|
+
const previous = featureFlags.reviewChannel
|
|
2229
|
+
featureFlags.reviewChannel = patch.reviewChannel
|
|
2230
|
+
changed = true
|
|
2231
|
+
// Start only on a transition away from 'builtin'; stop only when entering
|
|
2232
|
+
// it, so web <-> both never reconnects an already-live bridge.
|
|
2233
|
+
if (previous === 'builtin' && patch.reviewChannel !== 'builtin') {
|
|
2234
|
+
webBridge.start()
|
|
2235
|
+
} else if (previous !== 'builtin' && patch.reviewChannel === 'builtin') {
|
|
2236
|
+
webBridge.stop()
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2041
2239
|
if (typeof patch.review === 'boolean' && patch.review !== featureFlags.review) {
|
|
2042
2240
|
featureFlags.review = patch.review
|
|
2043
2241
|
changed = true
|
|
@@ -2081,7 +2279,7 @@ export function apply(ctx) {
|
|
|
2081
2279
|
cancelReview(review.id, (entry) => `The review gate was turned off in Settings. Nothing was written for "${entry.display}". Do not retry immediately; wait for the user.`)
|
|
2082
2280
|
}
|
|
2083
2281
|
}
|
|
2084
|
-
return ok({ review: featureFlags.review, withdraw: featureFlags.withdraw, autoReview: featureFlags.autoReview, aiExplain: featureFlags.aiExplain, allowBlockingReviewWait: featureFlags.allowBlockingReviewWait, keepTurns: featureFlags.keepTurns, nestedSnapshots: featureFlags.nestedSnapshots, autoGc: featureFlags.autoGc, version: PLUGIN_VERSION })
|
|
2282
|
+
return ok({ review: featureFlags.review, withdraw: featureFlags.withdraw, autoReview: featureFlags.autoReview, aiExplain: featureFlags.aiExplain, allowBlockingReviewWait: featureFlags.allowBlockingReviewWait, keepTurns: featureFlags.keepTurns, nestedSnapshots: featureFlags.nestedSnapshots, autoGc: featureFlags.autoGc, reviewChannel: featureFlags.reviewChannel, version: PLUGIN_VERSION })
|
|
2085
2283
|
}
|
|
2086
2284
|
|
|
2087
2285
|
const handleUpdateCheck = async () => {
|
|
@@ -2146,7 +2344,10 @@ export function apply(ctx) {
|
|
|
2146
2344
|
const dispatch = async (endpoint, payload) => {
|
|
2147
2345
|
try {
|
|
2148
2346
|
if (endpoint === 'status') return handleStatus(payload?.sessionId)
|
|
2149
|
-
if (endpoint === '
|
|
2347
|
+
if (endpoint === 'webStatus') return ok(webBridge.status())
|
|
2348
|
+
if (endpoint === 'webPair') return ok(await webBridge.pair(payload))
|
|
2349
|
+
if (endpoint === 'webDisconnect') return ok(webBridge.disconnect())
|
|
2350
|
+
if (endpoint === 'settings') return ok({ review: featureFlags.review, withdraw: featureFlags.withdraw, autoReview: featureFlags.autoReview, aiExplain: featureFlags.aiExplain, allowBlockingReviewWait: featureFlags.allowBlockingReviewWait, keepTurns: featureFlags.keepTurns, nestedSnapshots: featureFlags.nestedSnapshots, autoGc: featureFlags.autoGc, reviewChannel: featureFlags.reviewChannel, version: PLUGIN_VERSION })
|
|
2150
2351
|
if (endpoint === 'setSettings') return updateSettings(payload)
|
|
2151
2352
|
if (endpoint === 'cleanup') return ok(await cleanupSnapshots())
|
|
2152
2353
|
if (endpoint === 'withdraw') return await handleWithdraw(payload)
|
|
@@ -2162,6 +2363,7 @@ export function apply(ctx) {
|
|
|
2162
2363
|
version: reviewVersion,
|
|
2163
2364
|
unchanged: false,
|
|
2164
2365
|
reviews: [...reviews.values()].map(serializeReview),
|
|
2366
|
+
audits: Object.fromEntries(audits),
|
|
2165
2367
|
})
|
|
2166
2368
|
}
|
|
2167
2369
|
if (endpoint === 'decide') return decideReview(payload?.reviewId, payload?.decisions)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import os from 'node:os'
|
|
2
|
+
|
|
3
|
+
const RECONNECT_MS = [1000, 2000, 5000, 10000]
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Outbound bridge from the DSH plugin host to the standalone web review server.
|
|
7
|
+
*
|
|
8
|
+
* The plugin is the authority; this module only mirrors review snapshots and
|
|
9
|
+
* carries decisions back. It never opens an inbound port: the plugin connects
|
|
10
|
+
* to /ws/device with a device token obtained through the web pairing code.
|
|
11
|
+
*/
|
|
12
|
+
export const createWebBridge = (options) => {
|
|
13
|
+
const { getConfig, saveConfig, serializeReview, getReviews, getVersion, pluginVersion, isEnabled } = options
|
|
14
|
+
let socket = null
|
|
15
|
+
let timer = null
|
|
16
|
+
let attempt = 0
|
|
17
|
+
let connected = false
|
|
18
|
+
let stopped = true
|
|
19
|
+
let lastError = null
|
|
20
|
+
|
|
21
|
+
const status = () => {
|
|
22
|
+
const config = getConfig()
|
|
23
|
+
return {
|
|
24
|
+
url: config.url ?? '',
|
|
25
|
+
deviceId: config.deviceId ?? '',
|
|
26
|
+
paired: Boolean(config.token && config.deviceId),
|
|
27
|
+
connected,
|
|
28
|
+
lastError,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const send = (value) => {
|
|
33
|
+
if (socket !== null && socket.readyState === 1) socket.send(JSON.stringify(value))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const envelope = (review) => ({
|
|
37
|
+
...serializeReview(review),
|
|
38
|
+
version: getVersion(),
|
|
39
|
+
status: review.finished ? 'finished' : review.canceled ? 'canceled' : review.submitted ? 'submitted' : 'open',
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const publish = (review) => {
|
|
43
|
+
send({ type: 'review.snapshot', review: envelope(review) })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const publishAll = () => {
|
|
47
|
+
for (const review of getReviews()) publish(review)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const schedule = () => {
|
|
51
|
+
if (stopped) return
|
|
52
|
+
const delay = RECONNECT_MS[Math.min(attempt, RECONNECT_MS.length - 1)]
|
|
53
|
+
attempt += 1
|
|
54
|
+
timer = setTimeout(connect, delay)
|
|
55
|
+
if (typeof timer.unref === 'function') timer.unref()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const connect = () => {
|
|
59
|
+
const config = getConfig()
|
|
60
|
+
if (!config.url || !config.token) return
|
|
61
|
+
if (typeof WebSocket === 'undefined') {
|
|
62
|
+
lastError = 'WebSocket is not available in this Node runtime'
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const base = String(config.url).replace(/^http/, 'ws').replace(/\/+$/, '')
|
|
67
|
+
const ws = new WebSocket(`${base}/ws/device?token=${encodeURIComponent(config.token)}`)
|
|
68
|
+
socket = ws
|
|
69
|
+
ws.addEventListener('open', () => {
|
|
70
|
+
connected = true
|
|
71
|
+
attempt = 0
|
|
72
|
+
lastError = null
|
|
73
|
+
send({ type: 'hello', deviceId: config.deviceId, pluginVersion: pluginVersion ?? '', capabilities: {} })
|
|
74
|
+
publishAll()
|
|
75
|
+
})
|
|
76
|
+
ws.addEventListener('message', (event) => {
|
|
77
|
+
let message
|
|
78
|
+
try {
|
|
79
|
+
message = JSON.parse(String(event.data))
|
|
80
|
+
} catch {
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
if (message === null || typeof message !== 'object') return
|
|
84
|
+
if (message.type === 'ping') {
|
|
85
|
+
send({ type: 'pong' })
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
if (message.type === 'decision' && typeof options.onDecision === 'function') {
|
|
89
|
+
options.onDecision(message)
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
ws.addEventListener('close', () => {
|
|
93
|
+
connected = false
|
|
94
|
+
if (socket === ws) socket = null
|
|
95
|
+
schedule()
|
|
96
|
+
})
|
|
97
|
+
ws.addEventListener('error', () => {
|
|
98
|
+
lastError = 'WebSocket error'
|
|
99
|
+
})
|
|
100
|
+
} catch (error) {
|
|
101
|
+
lastError = String(error)
|
|
102
|
+
schedule()
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const start = () => {
|
|
107
|
+
stopped = false
|
|
108
|
+
// 'builtin' keeps the web channel off even when pairing saves a token.
|
|
109
|
+
if (typeof isEnabled === 'function' && isEnabled() === false) return
|
|
110
|
+
const config = getConfig()
|
|
111
|
+
if (config.url && config.token) connect()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const stop = () => {
|
|
115
|
+
stopped = true
|
|
116
|
+
// A disabled channel must not leave a reconnect timer or socket behind.
|
|
117
|
+
if (typeof isEnabled === 'function' && isEnabled() === false) {
|
|
118
|
+
if (timer !== null) clearTimeout(timer)
|
|
119
|
+
timer = null
|
|
120
|
+
}
|
|
121
|
+
if (timer !== null) {
|
|
122
|
+
clearTimeout(timer)
|
|
123
|
+
timer = null
|
|
124
|
+
}
|
|
125
|
+
if (socket !== null) {
|
|
126
|
+
try {
|
|
127
|
+
socket.close()
|
|
128
|
+
} catch {
|
|
129
|
+
// Ignore close errors; the bridge is best-effort.
|
|
130
|
+
}
|
|
131
|
+
socket = null
|
|
132
|
+
}
|
|
133
|
+
connected = false
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const pair = async (payload) => {
|
|
137
|
+
const base = String(payload?.url ?? '').trim().replace(/\/+$/, '')
|
|
138
|
+
const code = String(payload?.code ?? '').trim().toUpperCase()
|
|
139
|
+
if (!/^https?:\/\//.test(base)) return { ok: false, error: 'Web URL must start with http:// or https://' }
|
|
140
|
+
if (code === '') return { ok: false, error: 'Pairing code is required' }
|
|
141
|
+
try {
|
|
142
|
+
const response = await fetch(`${base}/api/pair`, {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: { 'content-type': 'application/json' },
|
|
145
|
+
body: JSON.stringify({
|
|
146
|
+
code,
|
|
147
|
+
deviceName: String(payload?.deviceName ?? os.hostname()).slice(0, 64),
|
|
148
|
+
instanceId: os.hostname(),
|
|
149
|
+
}),
|
|
150
|
+
signal: AbortSignal.timeout(10_000),
|
|
151
|
+
})
|
|
152
|
+
const data = await response.json().catch(() => ({}))
|
|
153
|
+
if (!response.ok) return { ok: false, error: data.error ?? `pair failed (${response.status})` }
|
|
154
|
+
if (typeof data.token !== 'string' || data.token === '' || typeof data.deviceId !== 'string') {
|
|
155
|
+
return { ok: false, error: 'pair response did not include a device token' }
|
|
156
|
+
}
|
|
157
|
+
saveConfig({ url: base, token: data.token, deviceId: data.deviceId })
|
|
158
|
+
stop()
|
|
159
|
+
start()
|
|
160
|
+
return { ok: true, status: status() }
|
|
161
|
+
} catch (error) {
|
|
162
|
+
return { ok: false, error: String(error) }
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const disconnect = () => {
|
|
167
|
+
stop()
|
|
168
|
+
saveConfig({ token: '', deviceId: '' })
|
|
169
|
+
return { ok: true, status: status() }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return { start, stop, pair, disconnect, status, publish, publishAll, connect, send }
|
|
173
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-coding-enhanced",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "The DSH change gate: queue AI edits before write, rewind turns with shadow-git snapshots, and hand review to a non-blocking waiter subagent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -41,6 +41,9 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"author": "dsh-coding-enhanced contributors",
|
|
43
43
|
"scripts": {
|
|
44
|
+
"check": "node --check lib/index.js && node --check lib/client.js && node --check lib/web-bridge.js",
|
|
45
|
+
"test": "node scripts/smoke-host.mjs",
|
|
46
|
+
"web:build": "npm --prefix web run build",
|
|
44
47
|
"pack": "node -e \"require('node:fs').mkdirSync('dist',{recursive:true})\" && npm pack --pack-destination dist"
|
|
45
48
|
},
|
|
46
49
|
"repository": {
|