dsh-coding-enhanced 0.7.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/lib/index.js +83 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -265,7 +265,7 @@ Open **Settings → Coding Enhanced** (the same controls appear on the plugin's
265
265
  | Setting | Default | What it does |
266
266
  |---|---|---|
267
267
  | **Change gate** (`AI Change Review`) | on | the pre-write review gate for `review_write` / `review_patch` |
268
- | **AI explanations** | on | require a short note for every added group; off = queue without notes and hide the AI rows |
268
+ | **AI explanations** | on | require at least one note per changed file; line-level notes for user-requested/key/hard changes; off = no notes and no AI rows |
269
269
  | **Workspace time machine** (`Turn Withdraw`) | on | turn-start snapshots, multi-turn withdraw and the restore action |
270
270
  | **Turns kept for withdraw** | 10 | how many recent turns stay withdrawable (1–50) |
271
271
  | **Snapshot nested git repositories** | on | include nested repositories' working files (excluding `.git`) |
package/lib/index.js CHANGED
@@ -25,7 +25,7 @@ import path from 'node:path'
25
25
  import { fileURLToPath } from 'node:url'
26
26
 
27
27
  export const name = 'coding-enhanced'
28
- export const inject = ['sessions', 'connection', 'tools', 'systemPrompt']
28
+ export const inject = ['sessions', 'connection', 'tools', 'systemPrompt', 'subagents']
29
29
 
30
30
  const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
31
31
  const PLUGIN_VERSION = (() => {
@@ -871,6 +871,7 @@ export function apply(ctx) {
871
871
  const MAX_EDITABLE_BYTES = 200 * 1024
872
872
  /** sessionId -> review { id, sessionId, entries, virtual, submitted, finished, canceled, waiters } */
873
873
  const reviews = new Map()
874
+ const reviewWaiters = new Map()
874
875
  let reviewVersion = 0
875
876
 
876
877
  const bumpReview = () => {
@@ -1262,8 +1263,20 @@ export function apply(ctx) {
1262
1263
  targets.set(newTarget.relative, { ...newTarget, newFile: oldTarget === null })
1263
1264
  }
1264
1265
 
1265
- if (featureFlags.aiExplain === true && !hasNotes(notes)) {
1266
- throw new Error('AI explanations are on: add at least one notes entry with a non-empty text for each added group (path/line or hunk). Turn off AI explanations in the input bar to queue without notes.')
1266
+ if (featureFlags.aiExplain === true) {
1267
+ const missing = []
1268
+ for (const target of targets.values()) {
1269
+ const covered = Array.isArray(notes) && notes.some((note) => {
1270
+ if (note === null || typeof note !== 'object') return false
1271
+ if (typeof note.text !== 'string' || note.text.trim() === '') return false
1272
+ const rawPath = typeof note.path === 'string' ? note.path.replace(/^[ab]\//, '').replace(/^\.\//, '') : ''
1273
+ return rawPath === '' ? targets.size === 1 : rawPath === target.relative
1274
+ })
1275
+ if (!covered) missing.push(target.relative)
1276
+ }
1277
+ if (missing.length > 0) {
1278
+ throw new Error(`AI explanations are on: add at least one note for each changed file. Missing: ${missing.join(', ')}. Turn off AI explanations in the input bar to queue without notes.`)
1279
+ }
1267
1280
  }
1268
1281
  const review = ensureReview(session.id)
1269
1282
  const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'dsh-ce-patch-'))
@@ -1332,16 +1345,71 @@ export function apply(ctx) {
1332
1345
  })
1333
1346
  files.push(queued.entry.display)
1334
1347
  }
1335
- return { files, review }
1348
+ return { files, review, session: session }
1336
1349
  } finally {
1337
1350
  await fs.rm(tmp, { recursive: true, force: true }).catch(() => {})
1338
1351
  }
1339
1352
  }
1340
1353
 
1354
+ const ensureReviewWaiter = async (session, review, exec) => {
1355
+ const subagents = ctx.subagents
1356
+ if (subagents === undefined) return { started: false, reason: 'subagents-service-unavailable' }
1357
+ const prompt = `You are the persistent review waiter for this conversation. Call review_wait with {"reviewId":"${review.id}","waitKey":"${review.waitKey}"} and wait. When it returns, report the per-file outcomes in a compact list; do not edit files, do not start reviews, and stay ready for the next review message.`
1358
+ const existing = reviewWaiters.get(session.id)
1359
+ if (existing !== undefined) {
1360
+ try {
1361
+ await subagents.sendMessage(exec.agent, existing, [{ type: 'text', text: prompt }], { signal: exec.signal })
1362
+ return { started: true, childId: existing, reused: true }
1363
+ } catch {
1364
+ reviewWaiters.delete(session.id)
1365
+ }
1366
+ }
1367
+ // 1) The agent-scoped subagent tool: it knows the provider and the exact
1368
+ // parent, and returns the child id.
1369
+ const scopedTool = ctx.tools.get('subagent', exec.scope)
1370
+ if (scopedTool !== undefined) {
1371
+ try {
1372
+ const result = await scopedTool.execute({ description: 'Review waiter', prompt }, exec)
1373
+ const childId = result?.subagentId ?? result?.childId
1374
+ if (typeof childId === 'string' && childId !== '') {
1375
+ reviewWaiters.set(session.id, childId)
1376
+ return { started: true, childId, reused: false }
1377
+ }
1378
+ } catch {
1379
+ // fall through to the direct provider path
1380
+ }
1381
+ }
1382
+ // 2) Direct provider path; the in-process spawn backend names itself "spawn".
1383
+ const providers = typeof subagents.listProviders === 'function' ? subagents.listProviders() : []
1384
+ const provider = Array.isArray(providers) && providers.length > 0 ? providers[0] : 'spawn'
1385
+ try {
1386
+ const activation = await subagents.startActivation({
1387
+ provider,
1388
+ label: 'Review waiter',
1389
+ request: {
1390
+ prompt: [{ type: 'text', text: prompt }],
1391
+ parent: exec.agent,
1392
+ },
1393
+ signal: exec.signal,
1394
+ delivery: 'parent',
1395
+ })
1396
+ const childId = activation?.childId
1397
+ if (typeof childId === 'string' && childId !== '') {
1398
+ reviewWaiters.set(session.id, childId)
1399
+ return { started: true, childId, reused: false }
1400
+ }
1401
+ return { started: false, reason: 'no-child-id' }
1402
+ } catch (error) {
1403
+ return { started: false, reason: String(error) }
1404
+ }
1405
+ }
1406
+
1407
+
1408
+
1341
1409
  const registerReviewTools = () => {
1342
1410
  ctx.tools.register(defineTool({
1343
1411
  name: 'review_write',
1344
- description: 'Queue a new file or a full-file rewrite for the user\'s review. This does not write the file: the change is held in the Code review tab until the user finishes. Use review_patch for edits to existing files. Add a short notes entry for each group of added lines so the reviewer sees your explanation; notes are required while AI explanations are on. The result includes a reviewId and waitKey; send them to the persistent review waiter child (or start one) and continue; never call review_wait from the main agent.',
1412
+ description: 'Queue a new file or a full-file rewrite for the user\'s review. This does not write the file: the change is held in the Code review tab until the user finishes. Use review_patch for edits to existing files. At least one notes entry per changed file is required while AI explanations are on; prefer line-level notes (line/hunk) for user-requested, key or hard-to-understand changes. Each note is 1-2 sentences explaining why. The plugin starts or reuses the review waiter automatically; just queue and continue, and never call review_wait from the main agent.',
1345
1413
  parameters: {
1346
1414
  file_path: { type: 'string', required: true, description: 'Path to write, resolved like the write tool.' },
1347
1415
  content: { type: 'string', required: true, description: 'Full UTF-8 text content to write.' },
@@ -1365,17 +1433,19 @@ export function apply(ctx) {
1365
1433
  if (session === undefined) return 'No active session.'
1366
1434
  if (featureFlags.review !== true) return 'The review gate is off. Use the write tool instead.'
1367
1435
  if (featureFlags.aiExplain === true && !hasNotes(args.notes)) {
1368
- throw new Error('AI explanations are on: add at least one notes entry with a non-empty text for each added group (line or hunk). Turn off AI explanations in the input bar to queue without notes.')
1436
+ throw new Error('AI explanations are on: add at least one note for this file. Use line-level notes for user-requested, key or hard-to-understand changes. Turn off AI explanations in the input bar to queue without notes.')
1369
1437
  }
1370
1438
  const queued = await stageFileChange(session, { id: exec.callId, name: 'write', arguments: { file_path: args.file_path, content: args.content, notes: args.notes } })
1371
1439
  if (queued === undefined) return 'Could not queue this change (missing or invalid file_path).'
1372
- return `Queued for review: ${queued.entry.display} (${queued.review.entries.size} file(s) queued). Nothing is written until the user finishes. reviewId: ${queued.review.id}; waitKey: ${queued.review.waitKey}; send the id and key to the persistent review waiter child, or start one, and continue; do not call review_wait from the main agent.`
1440
+ const waiter = await ensureReviewWaiter(session, queued.review, exec)
1441
+ if (waiter.started === true) return `Queued for review: ${queued.entry.display} (${queued.review.entries.size} file(s) queued). Nothing is written until the user finishes. A review waiter is running; continue or end your turn and it will wake you.`
1442
+ return `Queued for review: ${queued.entry.display} (${queued.review.entries.size} file(s) queued). Nothing is written until the user finishes. reviewId: ${queued.review.id}; waitKey: ${queued.review.waitKey}; start or send the persistent review waiter and continue; do not call review_wait from the main agent. (${waiter.reason})`
1373
1443
  },
1374
1444
  }), { when: () => featureFlags.review === true && featureFlags.autoReview === true })
1375
1445
 
1376
1446
  ctx.tools.register(defineTool({
1377
1447
  name: 'review_patch',
1378
- description: 'Queue a unified diff for the user\'s review. The patch must use ---/+++ headers and @@ hunks with paths relative to the working directory; a/ and b/ prefixes and diff --git headers are accepted. Use one patch per file when possible; multiple files are allowed. This does not modify the workspace: the change is held in the Code review tab until the user finishes. Add a short notes entry for each group of added lines so the reviewer sees your explanation; notes are required while AI explanations are on. The result includes a reviewId and waitKey; send them to the persistent review waiter child (or start one) and continue; never call review_wait from the main agent. Example:\n--- a/src/app.ts\n+++ b/src/app.ts\n@@ -10,7 +10,9 @@\n const app = createApp()\n- app.use(oldRouter)\n+ app.use(newRouter)\n+ app.use(logger)\n app.listen(3000)\nSend the reviewId and waitKey to the persistent review waiter child (or start one) and continue; do not call review_wait from the main agent.',
1448
+ description: 'Queue a unified diff for the user\'s review. The patch must use ---/+++ headers and @@ hunks with paths relative to the working directory; a/ and b/ prefixes and diff --git headers are accepted. Use one patch per file when possible; multiple files are allowed. This does not modify the workspace: the change is held in the Code review tab until the user finishes. At least one notes entry per changed file is required while AI explanations are on; prefer line-level notes (line/hunk) for user-requested, key or hard-to-understand changes. Each note is 1-2 sentences explaining why. The plugin starts or reuses the review waiter automatically; just queue and continue, and never call review_wait from the main agent. Example:\n--- a/src/app.ts\n+++ b/src/app.ts\n@@ -10,7 +10,9 @@\n const app = createApp()\n- app.use(oldRouter)\n+ app.use(newRouter)\n+ app.use(logger)\n app.listen(3000)\nThe plugin starts or reuses the review waiter automatically; just queue and continue, and do not call review_wait from the main agent.',
1379
1449
  parameters: {
1380
1450
  patch: { type: 'string', required: true, description: 'A unified diff (---/+++/@@) to queue for review.' },
1381
1451
  notes: {
@@ -1399,7 +1469,9 @@ export function apply(ctx) {
1399
1469
  if (session === undefined) return 'No active session.'
1400
1470
  if (featureFlags.review !== true) return 'The review gate is off. Use apply_patch or edit instead.'
1401
1471
  const queued = await stagePatch(session, exec, args.patch, args.notes)
1402
- return `Queued for review: ${queued.files.join(', ')} (${queued.review.entries.size} file(s) in this review). Nothing is written until the user finishes. reviewId: ${queued.review.id}; waitKey: ${queued.review.waitKey}; send the id and key to the persistent review waiter child, or start one, and continue; do not call review_wait from the main agent.`
1472
+ const waiter = await ensureReviewWaiter(session, queued.review, exec)
1473
+ if (waiter.started === true) return `Queued for review: ${queued.files.join(', ')} (${queued.review.entries.size} file(s) in this review). Nothing is written until the user finishes. A review waiter is running; continue or end your turn and it will wake you.`
1474
+ return `Queued for review: ${queued.files.join(', ')} (${queued.review.entries.size} file(s) in this review). Nothing is written until the user finishes. reviewId: ${queued.review.id}; waitKey: ${queued.review.waitKey}; start or send the persistent review waiter and continue; do not call review_wait from the main agent. (${waiter.reason})`
1403
1475
  },
1404
1476
  }), { when: () => featureFlags.review === true && featureFlags.autoReview === true })
1405
1477
 
@@ -1473,7 +1545,7 @@ export function apply(ctx) {
1473
1545
  if (!REVIEW_TOOLS.has(exec.name)) return next()
1474
1546
  return {
1475
1547
  kind: 'deny',
1476
- 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 notes; then send the reviewId/waitKey to the persistent review waiter child (or start one) and continue. Never call review_wait from the main agent. Shell commands are outside the review.',
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. Shell commands are outside the review.',
1477
1549
  }
1478
1550
  }
1479
1551
 
@@ -1484,7 +1556,7 @@ export function apply(ctx) {
1484
1556
  name: 'tool:review-gate',
1485
1557
  order: 110,
1486
1558
  text: () => featureFlags.review === true && featureFlags.autoReview === true
1487
- ? '🎟️ FILE-EDIT VELVET ROPE: The human personally reviews every file change. Queue every change with review_write (new file / full file) or review_patch (unified diff) and include a short notes entry for each added group (required while AI explanations are on). Do not use write/edit/apply_patch/str_replace_editor. Do not call review_wait yourself: send the reviewId/waitKey to the persistent review waiter subagent (or start one), then continue or end the turn; the waiter will wake you. If a file is rejected, read the comment and revise. This is house rules. 💅'
1559
+ ? '🎟️ FILE-EDIT VELVET ROPE: The human personally reviews every file change. Queue every change with review_write (new file / full file) or review_patch (unified diff) and 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). Do not use write/edit/apply_patch/str_replace_editor. 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. 💅'
1488
1560
  : '',
1489
1561
  }), 'coding-enhanced: review prompt')
1490
1562
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-coding-enhanced",
3
- "version": "0.7.1",
3
+ "version": "0.8.3",
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",