dsh-coding-enhanced 0.6.5 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/client.js +84 -19
- package/lib/index.js +129 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -265,6 +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
269
|
| **Workspace time machine** (`Turn Withdraw`) | on | turn-start snapshots, multi-turn withdraw and the restore action |
|
|
269
270
|
| **Turns kept for withdraw** | 10 | how many recent turns stay withdrawable (1–50) |
|
|
270
271
|
| **Snapshot nested git repositories** | on | include nested repositories' working files (excluding `.git`) |
|
package/lib/client.js
CHANGED
|
@@ -40,6 +40,8 @@ window.__ModuleLoader__.load({
|
|
|
40
40
|
resizeDiff: 'Drag to resize · double-click to reset',
|
|
41
41
|
reviewTools: 'Review tools',
|
|
42
42
|
autoReview: 'Pre-review',
|
|
43
|
+
aiExplain: 'AI explanations',
|
|
44
|
+
aiExplainDesc: 'Require a short note for every added group. Off: queue changes without notes.',
|
|
43
45
|
autoReviewDesc: 'The agent must queue every edit with review_write / review_patch before it lands. Off: native write/edit.',
|
|
44
46
|
reviewFeatureOff: 'AI Change Review is off in Settings. Enable it first, then use this switch.',
|
|
45
47
|
reviewOn: 'On',
|
|
@@ -117,6 +119,10 @@ window.__ModuleLoader__.load({
|
|
|
117
119
|
rewindConfirm: 'Withdraw turn {turn}? Turns {turn} through {latest} will be canceled in the model context, and the workspace will be restored to before turn {turn}.',
|
|
118
120
|
settingsFeatures: 'Change gate · time machine · handoff',
|
|
119
121
|
settingsGroupUpdates: 'Updates',
|
|
122
|
+
settingsAbout: 'About',
|
|
123
|
+
settingsAboutTitle: 'Coding Enhanced',
|
|
124
|
+
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
|
+
settingsReadme: 'Open the full README',
|
|
120
126
|
settingsUpdates: 'Plugin updates',
|
|
121
127
|
settingsUpdatesDesc: 'Check npm for the latest release and install it from here.',
|
|
122
128
|
settingsCurrentVersion: 'Current version',
|
|
@@ -146,6 +152,8 @@ window.__ModuleLoader__.load({
|
|
|
146
152
|
resizeDiff: '拖动调整高度 · 双击还原',
|
|
147
153
|
reviewTools: 'Review 工具',
|
|
148
154
|
autoReview: 'AI 改动预审查',
|
|
155
|
+
aiExplain: 'AI 解释',
|
|
156
|
+
aiExplainDesc: '每个新增块都要求一条说明。关闭后排队不再要求解释。',
|
|
149
157
|
autoReviewDesc: 'AI 的每次改动都必须先进入 review(review_write / review_patch)才能落盘。关闭后走原生 write/edit。',
|
|
150
158
|
reviewFeatureOff: '设置里的 AI Change Review 处于关闭状态,先启用后再用这个开关。',
|
|
151
159
|
reviewOn: '开',
|
|
@@ -222,6 +230,10 @@ window.__ModuleLoader__.load({
|
|
|
222
230
|
rewindConfirm: '撤回第 {turn} 轮?第 {turn} 到第 {latest} 轮都会从模型上下文中撤销,工作区恢复到第 {turn} 轮开始前。',
|
|
223
231
|
settingsFeatures: '闸门 · 时间机器 · 交接',
|
|
224
232
|
settingsGroupUpdates: '更新',
|
|
233
|
+
settingsAbout: '关于',
|
|
234
|
+
settingsAboutTitle: 'Coding Enhanced',
|
|
235
|
+
settingsAboutDesc: 'DSH 变更闸门:写入前审查、多轮回退、非阻塞 review 交接。完整 README 在插件页和仓库里。',
|
|
236
|
+
settingsReadme: '打开完整 README',
|
|
225
237
|
settingsUpdates: '插件更新',
|
|
226
238
|
settingsUpdatesDesc: '检查 npm 最新版本,并在这里安装。',
|
|
227
239
|
settingsCurrentVersion: '当前版本',
|
|
@@ -326,8 +338,8 @@ window.__ModuleLoader__.load({
|
|
|
326
338
|
.wr-ai-line:hover{background:linear-gradient(90deg,rgba(124,58,237,.15),rgba(217,70,239,.10) 55%,rgba(34,211,238,.07))}
|
|
327
339
|
.wr-ai-line .wr-no{background:rgba(168,85,247,.10);color:transparent}
|
|
328
340
|
.wr-ai-line .wr-ai-sign{color:#7c3aed;font-size:.6em;font-weight:800;letter-spacing:.02em;text-shadow:0 0 8px rgba(168,85,247,.35)}
|
|
329
|
-
.wr-ai-line .wr-ai-text{display:flex;align-items:
|
|
330
|
-
.wr-ai-line .wr-ai-text > span:last-child{min-width:0;overflow:
|
|
341
|
+
.wr-ai-line .wr-ai-text{display:flex;align-items:flex-start;gap:.5em;white-space:normal;overflow:visible;color:var(--dsw-alias-label-secondary,#555)}
|
|
342
|
+
.wr-ai-line .wr-ai-text > span:last-child{min-width:0;white-space:pre-wrap;overflow-wrap:anywhere;overflow:visible;text-overflow:clip}
|
|
331
343
|
.wr-hunk{padding:.15em .5em;font-size:.78em;line-height:1.5;color:var(--dsw-alias-label-tertiary,#999);background:var(--dsw-alias-bg-base,#fafafa);border-top:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.06));border-bottom:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.06))}
|
|
332
344
|
.wr-comment{display:block;width:calc(100% - 1.4em);margin:.55em .7em .7em;box-sizing:border-box;min-height:2.8em;resize:vertical;padding:.4em .55em;border-radius:.5em;border:1px solid var(--dsw-alias-border-l3,rgba(0,0,0,.16));background:var(--dsw-alias-bg-base,#fafafa);color:inherit;font:inherit;font-size:.88em;line-height:1.5}
|
|
333
345
|
.wr-comment:focus{outline:2px solid var(--dsw-alias-state-business-primary,#4d6bfe);outline-offset:-1px}
|
|
@@ -359,6 +371,9 @@ window.__ModuleLoader__.load({
|
|
|
359
371
|
.ce-number:focus{border-color:var(--dsw-alias-state-business-primary,#4d6bfe);box-shadow:0 0 0 2px color-mix(in srgb,var(--dsw-alias-state-business-primary,#4d6bfe) 18%,transparent)}
|
|
360
372
|
.ce-number:disabled{opacity:.5}
|
|
361
373
|
.ce-number-unit{font-size:.78em;color:var(--dsw-alias-label-tertiary,#888)}
|
|
374
|
+
.ce-about .ce-row-desc{margin-top:.3em}
|
|
375
|
+
.ce-about-link{display:inline-flex;margin-top:.6em;font-size:.85em;font-weight:500;color:var(--dsw-alias-state-business-primary,#4d6bfe);text-decoration:none}
|
|
376
|
+
.ce-about-link:hover{text-decoration:underline}
|
|
362
377
|
.ce-update .ce-row{align-items:flex-start;gap:.8em}
|
|
363
378
|
.ce-update-actions{display:flex;gap:.4em;flex-wrap:wrap;justify-content:flex-end}
|
|
364
379
|
.ce-update-meta{margin-top:.35em;font-size:.76em;color:var(--dsw-alias-label-tertiary)}
|
|
@@ -992,6 +1007,7 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
992
1007
|
const [local, setLocal] = React.useState({})
|
|
993
1008
|
const [submitting, setSubmitting] = React.useState(false)
|
|
994
1009
|
const [error, setError] = React.useState(null)
|
|
1010
|
+
const [explain, setExplain] = React.useState(true)
|
|
995
1011
|
const finishedRef = React.useRef(false)
|
|
996
1012
|
const currentReviewRef = React.useRef(review)
|
|
997
1013
|
currentReviewRef.current = review
|
|
@@ -1210,7 +1226,7 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1210
1226
|
return anchors
|
|
1211
1227
|
}
|
|
1212
1228
|
const aiNote = (items, key) =>
|
|
1213
|
-
items.map((note, index) =>
|
|
1229
|
+
explain !== true ? [] : items.map((note, index) =>
|
|
1214
1230
|
React.createElement(
|
|
1215
1231
|
'div',
|
|
1216
1232
|
{ className: 'wr-line wr-ai-line', key: `${key}-${index}`, title: note.text },
|
|
@@ -1442,6 +1458,7 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1442
1458
|
|
|
1443
1459
|
const enabled = flags?.review === true
|
|
1444
1460
|
const auto = flags?.autoReview === true
|
|
1461
|
+
const explain = flags?.aiExplain !== false
|
|
1445
1462
|
|
|
1446
1463
|
const toggleOpen = () => {
|
|
1447
1464
|
if (!open && triggerRef.current !== null) {
|
|
@@ -1460,6 +1477,14 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1460
1477
|
if (result.ok === true) setFlags(result.value)
|
|
1461
1478
|
}
|
|
1462
1479
|
|
|
1480
|
+
const toggleExplain = async () => {
|
|
1481
|
+
if (busy || flags === null || !enabled) return
|
|
1482
|
+
setBusy(true)
|
|
1483
|
+
const result = await call('setSettings', { aiExplain: !explain })
|
|
1484
|
+
setBusy(false)
|
|
1485
|
+
if (result.ok === true) setFlags(result.value)
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1463
1488
|
const popover = open && rect !== null
|
|
1464
1489
|
? ReactDOM.createPortal(
|
|
1465
1490
|
React.createElement(
|
|
@@ -1487,26 +1512,53 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1487
1512
|
),
|
|
1488
1513
|
enabled
|
|
1489
1514
|
? React.createElement(
|
|
1490
|
-
|
|
1491
|
-
|
|
1515
|
+
React.Fragment,
|
|
1516
|
+
null,
|
|
1492
1517
|
React.createElement(
|
|
1493
1518
|
'div',
|
|
1494
|
-
{ className: 'ce-review-
|
|
1495
|
-
React.createElement(
|
|
1496
|
-
|
|
1519
|
+
{ className: 'ce-review-row' },
|
|
1520
|
+
React.createElement(
|
|
1521
|
+
'div',
|
|
1522
|
+
{ className: 'ce-review-text' },
|
|
1523
|
+
React.createElement('div', { className: 'ce-review-row-title' }, typeof t === 'function' ? t('autoReview') : 'Pre-review'),
|
|
1524
|
+
React.createElement('div', { className: 'ce-review-row-desc' }, typeof t === 'function' ? t('autoReviewDesc') : ''),
|
|
1525
|
+
),
|
|
1526
|
+
React.createElement(
|
|
1527
|
+
'button',
|
|
1528
|
+
{
|
|
1529
|
+
type: 'button',
|
|
1530
|
+
role: 'switch',
|
|
1531
|
+
'aria-checked': auto,
|
|
1532
|
+
'aria-label': typeof t === 'function' ? t('autoReview') : 'Pre-review',
|
|
1533
|
+
className: `ce-switch${auto ? ' on' : ''}`,
|
|
1534
|
+
disabled: busy || flags === null,
|
|
1535
|
+
onClick: () => { void toggleAuto() },
|
|
1536
|
+
},
|
|
1537
|
+
React.createElement('span', { className: 'ce-switch-thumb' }),
|
|
1538
|
+
),
|
|
1497
1539
|
),
|
|
1498
1540
|
React.createElement(
|
|
1499
|
-
'
|
|
1500
|
-
{
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
'
|
|
1504
|
-
'
|
|
1505
|
-
className:
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1541
|
+
'div',
|
|
1542
|
+
{ className: 'ce-review-row' },
|
|
1543
|
+
React.createElement(
|
|
1544
|
+
'div',
|
|
1545
|
+
{ className: 'ce-review-text' },
|
|
1546
|
+
React.createElement('div', { className: 'ce-review-row-title' }, typeof t === 'function' ? t('aiExplain') : 'AI explanations'),
|
|
1547
|
+
React.createElement('div', { className: 'ce-review-row-desc' }, typeof t === 'function' ? t('aiExplainDesc') : ''),
|
|
1548
|
+
),
|
|
1549
|
+
React.createElement(
|
|
1550
|
+
'button',
|
|
1551
|
+
{
|
|
1552
|
+
type: 'button',
|
|
1553
|
+
role: 'switch',
|
|
1554
|
+
'aria-checked': explain,
|
|
1555
|
+
'aria-label': typeof t === 'function' ? t('aiExplain') : 'AI explanations',
|
|
1556
|
+
className: `ce-switch${explain ? ' on' : ''}`,
|
|
1557
|
+
disabled: busy || flags === null,
|
|
1558
|
+
onClick: () => { void toggleExplain() },
|
|
1559
|
+
},
|
|
1560
|
+
React.createElement('span', { className: 'ce-switch-thumb' }),
|
|
1561
|
+
),
|
|
1510
1562
|
),
|
|
1511
1563
|
)
|
|
1512
1564
|
: React.createElement('div', { className: 'ce-review-off' }, typeof t === 'function' ? t('reviewFeatureOff') : ''),
|
|
@@ -1770,6 +1822,7 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1770
1822
|
'div',
|
|
1771
1823
|
{ className: 'ce-card' },
|
|
1772
1824
|
row('review', typeof t === 'function' ? t('settingsReview') : 'AI Change Review', typeof t === 'function' ? t('settingsReviewDesc') : ''),
|
|
1825
|
+
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.'),
|
|
1773
1826
|
),
|
|
1774
1827
|
React.createElement('div', { className: 'ce-group-title' }, typeof t === 'function' ? t('settingsGroupWithdraw') : 'Turn withdraw'),
|
|
1775
1828
|
React.createElement(
|
|
@@ -1840,6 +1893,18 @@ div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
|
1840
1893
|
),
|
|
1841
1894
|
),
|
|
1842
1895
|
),
|
|
1896
|
+
React.createElement('div', { className: 'ce-group-title' }, typeof t === 'function' ? t('settingsAbout') : 'About'),
|
|
1897
|
+
React.createElement(
|
|
1898
|
+
'div',
|
|
1899
|
+
{ className: 'ce-card ce-about' },
|
|
1900
|
+
React.createElement('div', { className: 'ce-row-title' }, typeof t === 'function' ? t('settingsAboutTitle') : 'Coding Enhanced'),
|
|
1901
|
+
React.createElement('div', { className: 'ce-row-desc' }, typeof t === 'function' ? t('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.'),
|
|
1902
|
+
React.createElement(
|
|
1903
|
+
'a',
|
|
1904
|
+
{ className: 'ce-about-link', href: 'https://github.com/hello-2021/dsh-coding-enhanced#readme', target: '_blank', rel: 'noreferrer' },
|
|
1905
|
+
typeof t === 'function' ? t('settingsReadme') : 'Open the full README',
|
|
1906
|
+
),
|
|
1907
|
+
),
|
|
1843
1908
|
error !== null ? React.createElement('p', { className: 'ce-error' }, error) : null,
|
|
1844
1909
|
)
|
|
1845
1910
|
}
|
package/lib/index.js
CHANGED
|
@@ -58,15 +58,90 @@ const execOnce = (command, args, options) => new Promise((resolve, reject) => {
|
|
|
58
58
|
})
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
+
const readConfiguredRegistry = () => {
|
|
62
|
+
const files = [
|
|
63
|
+
path.join(os.homedir(), '.npmrc'),
|
|
64
|
+
path.join(path.dirname(path.dirname(PACKAGE_ROOT)), '.npmrc'),
|
|
65
|
+
]
|
|
66
|
+
for (const file of files) {
|
|
67
|
+
try {
|
|
68
|
+
for (const line of readFileSync(file, 'utf8').split(/\r?\n/)) {
|
|
69
|
+
const match = line.match(/^\s*registry\s*=\s*(\S+)\s*$/)
|
|
70
|
+
if (match !== null) return match[1]
|
|
71
|
+
}
|
|
72
|
+
} catch {
|
|
73
|
+
// ignore missing/unreadable npmrc
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return process.env.npm_config_registry
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const registryBases = () => {
|
|
80
|
+
const configured = readConfiguredRegistry()
|
|
81
|
+
return [...new Set([
|
|
82
|
+
configured,
|
|
83
|
+
'https://registry.npmjs.org',
|
|
84
|
+
'https://registry.npmmirror.com',
|
|
85
|
+
].filter((value) => typeof value === 'string' && value.length > 0))]
|
|
86
|
+
}
|
|
87
|
+
|
|
61
88
|
const latestNpmVersion = async () => {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
89
|
+
const failures = []
|
|
90
|
+
for (const base of registryBases()) {
|
|
91
|
+
const url = `${base.replace(/\/+$/, '')}/dsh-coding-enhanced/latest`
|
|
92
|
+
try {
|
|
93
|
+
const response = await fetch(url, {
|
|
94
|
+
headers: { accept: 'application/vnd.npm.install-v1+json, application/json' },
|
|
95
|
+
signal: AbortSignal.timeout(12000),
|
|
96
|
+
})
|
|
97
|
+
if (response.ok !== true) throw new Error(`HTTP ${response.status}`)
|
|
98
|
+
const data = await response.json()
|
|
99
|
+
if (typeof data.version !== 'string' || data.version === '') throw new Error('no version in response')
|
|
100
|
+
return { version: data.version, registry: base }
|
|
101
|
+
} catch (error) {
|
|
102
|
+
failures.push(`${base} (${String(error)})`)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
throw new Error(`No npm registry reachable. Tried: ${failures.join('; ')}`)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const findBundledPnpm = () => {
|
|
109
|
+
const candidates = []
|
|
110
|
+
if (typeof process.resourcesPath === 'string' && process.resourcesPath !== '') {
|
|
111
|
+
candidates.push(path.join(process.resourcesPath, 'app.asar', 'runtime', 'pnpm', 'bin', 'pnpm.cjs'))
|
|
112
|
+
candidates.push(path.join(process.resourcesPath, 'runtime', 'pnpm', 'bin', 'pnpm.cjs'))
|
|
113
|
+
}
|
|
114
|
+
candidates.push(path.join(path.dirname(process.execPath), '..', 'Resources', 'app.asar', 'runtime', 'pnpm', 'bin', 'pnpm.cjs'))
|
|
115
|
+
return candidates.find((candidate) => existsSync(candidate))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const installPackage = async (spec, profileDir) => {
|
|
119
|
+
const failures = []
|
|
120
|
+
try {
|
|
121
|
+
await execOnce('pnpm', ['add', spec], { cwd: profileDir })
|
|
122
|
+
return 'pnpm'
|
|
123
|
+
} catch (error) {
|
|
124
|
+
failures.push(String(error))
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
await execOnce('npm', ['install', spec, '--no-audit', '--no-fund'], { cwd: profileDir })
|
|
128
|
+
return 'npm'
|
|
129
|
+
} catch (error) {
|
|
130
|
+
failures.push(String(error))
|
|
131
|
+
}
|
|
132
|
+
const bundled = findBundledPnpm()
|
|
133
|
+
if (bundled !== undefined) {
|
|
134
|
+
try {
|
|
135
|
+
await execOnce(process.execPath, [bundled, 'add', spec], {
|
|
136
|
+
cwd: profileDir,
|
|
137
|
+
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' },
|
|
138
|
+
})
|
|
139
|
+
return 'dsh-bundled-pnpm'
|
|
140
|
+
} catch (error) {
|
|
141
|
+
failures.push(String(error))
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
throw new Error(failures.join(' | '))
|
|
70
145
|
}
|
|
71
146
|
|
|
72
147
|
const SURFACE_TYPES = new Set([
|
|
@@ -341,12 +416,14 @@ export function apply(ctx) {
|
|
|
341
416
|
const settingsPath = path.join(root, 'settings.json')
|
|
342
417
|
mkdirSync(root, { recursive: true })
|
|
343
418
|
|
|
344
|
-
const featureFlags = { review: true, withdraw: true, autoReview: true, keepTurns: 10, nestedSnapshots: true, autoGc: true }
|
|
419
|
+
const featureFlags = { review: true, withdraw: true, autoReview: true, aiExplain: true, allowBlockingReviewWait: false, keepTurns: 10, nestedSnapshots: true, autoGc: true }
|
|
345
420
|
try {
|
|
346
421
|
const parsed = JSON.parse(readFileSync(settingsPath, 'utf8'))
|
|
347
422
|
if (typeof parsed.review === 'boolean') featureFlags.review = parsed.review
|
|
348
423
|
if (typeof parsed.withdraw === 'boolean') featureFlags.withdraw = parsed.withdraw
|
|
349
424
|
if (typeof parsed.autoReview === 'boolean') featureFlags.autoReview = parsed.autoReview
|
|
425
|
+
if (typeof parsed.aiExplain === 'boolean') featureFlags.aiExplain = parsed.aiExplain
|
|
426
|
+
if (typeof parsed.allowBlockingReviewWait === 'boolean') featureFlags.allowBlockingReviewWait = parsed.allowBlockingReviewWait
|
|
350
427
|
if (Number.isSafeInteger(parsed.keepTurns)) {
|
|
351
428
|
featureFlags.keepTurns = Math.min(50, Math.max(1, parsed.keepTurns))
|
|
352
429
|
}
|
|
@@ -789,7 +866,7 @@ export function apply(ctx) {
|
|
|
789
866
|
})
|
|
790
867
|
|
|
791
868
|
// ------------------------------------------------------- review gate ---
|
|
792
|
-
const REVIEW_TOOLS = new Set(['write', 'edit', 'apply_patch'])
|
|
869
|
+
const REVIEW_TOOLS = new Set(['write', 'edit', 'apply_patch', 'str_replace_editor', 'multi_edit', 'notebook_edit'])
|
|
793
870
|
const MAX_REVIEW_FILE_BYTES = 2 * 1024 * 1024
|
|
794
871
|
const MAX_EDITABLE_BYTES = 200 * 1024
|
|
795
872
|
/** sessionId -> review { id, sessionId, entries, virtual, submitted, finished, canceled, waiters } */
|
|
@@ -820,6 +897,8 @@ export function apply(ctx) {
|
|
|
820
897
|
return review
|
|
821
898
|
}
|
|
822
899
|
|
|
900
|
+
const hasNotes = (notes) => Array.isArray(notes) && notes.some((note) => note !== null && typeof note === 'object' && typeof note.text === 'string' && note.text.trim() !== '')
|
|
901
|
+
|
|
823
902
|
const cleanupReview = (sessionId) => {
|
|
824
903
|
const review = reviews.get(sessionId)
|
|
825
904
|
if (review === undefined) return
|
|
@@ -1183,6 +1262,9 @@ export function apply(ctx) {
|
|
|
1183
1262
|
targets.set(newTarget.relative, { ...newTarget, newFile: oldTarget === null })
|
|
1184
1263
|
}
|
|
1185
1264
|
|
|
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.')
|
|
1267
|
+
}
|
|
1186
1268
|
const review = ensureReview(session.id)
|
|
1187
1269
|
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'dsh-ce-patch-'))
|
|
1188
1270
|
try {
|
|
@@ -1259,7 +1341,7 @@ export function apply(ctx) {
|
|
|
1259
1341
|
const registerReviewTools = () => {
|
|
1260
1342
|
ctx.tools.register(defineTool({
|
|
1261
1343
|
name: 'review_write',
|
|
1262
|
-
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. The result includes a reviewId and waitKey;
|
|
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.',
|
|
1263
1345
|
parameters: {
|
|
1264
1346
|
file_path: { type: 'string', required: true, description: 'Path to write, resolved like the write tool.' },
|
|
1265
1347
|
content: { type: 'string', required: true, description: 'Full UTF-8 text content to write.' },
|
|
@@ -1282,15 +1364,18 @@ export function apply(ctx) {
|
|
|
1282
1364
|
const session = exec.agent?.session
|
|
1283
1365
|
if (session === undefined) return 'No active session.'
|
|
1284
1366
|
if (featureFlags.review !== true) return 'The review gate is off. Use the write tool instead.'
|
|
1367
|
+
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.')
|
|
1369
|
+
}
|
|
1285
1370
|
const queued = await stageFileChange(session, { id: exec.callId, name: 'write', arguments: { file_path: args.file_path, content: args.content, notes: args.notes } })
|
|
1286
1371
|
if (queued === undefined) return 'Could not queue this change (missing or invalid file_path).'
|
|
1287
|
-
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};
|
|
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.`
|
|
1288
1373
|
},
|
|
1289
1374
|
}), { when: () => featureFlags.review === true && featureFlags.autoReview === true })
|
|
1290
1375
|
|
|
1291
1376
|
ctx.tools.register(defineTool({
|
|
1292
1377
|
name: 'review_patch',
|
|
1293
|
-
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. The result includes a reviewId and waitKey;
|
|
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.',
|
|
1294
1379
|
parameters: {
|
|
1295
1380
|
patch: { type: 'string', required: true, description: 'A unified diff (---/+++/@@) to queue for review.' },
|
|
1296
1381
|
notes: {
|
|
@@ -1314,13 +1399,13 @@ export function apply(ctx) {
|
|
|
1314
1399
|
if (session === undefined) return 'No active session.'
|
|
1315
1400
|
if (featureFlags.review !== true) return 'The review gate is off. Use apply_patch or edit instead.'
|
|
1316
1401
|
const queued = await stagePatch(session, exec, args.patch, args.notes)
|
|
1317
|
-
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};
|
|
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.`
|
|
1318
1403
|
},
|
|
1319
1404
|
}), { when: () => featureFlags.review === true && featureFlags.autoReview === true })
|
|
1320
1405
|
|
|
1321
1406
|
ctx.tools.register(defineTool({
|
|
1322
1407
|
name: 'review_wait',
|
|
1323
|
-
description: 'Wait for a review.
|
|
1408
|
+
description: 'Wait for a review. Only a review waiter subagent should call this: pass the reviewId and waitKey from review_write/review_patch. The main agent must not call it; if it does, the call is refused so the turn never blocks. Returns one structured result per file: applied, rejected (with the user\'s comment), edited, or failed.',
|
|
1324
1409
|
parameters: {
|
|
1325
1410
|
reviewId: { type: 'string', description: 'Review id returned by review_write/review_patch.' },
|
|
1326
1411
|
waitKey: { type: 'string', description: 'Wait key returned by the same tool result.' },
|
|
@@ -1331,6 +1416,7 @@ export function apply(ctx) {
|
|
|
1331
1416
|
additionalProperties: false,
|
|
1332
1417
|
properties: {
|
|
1333
1418
|
status: { type: 'string' },
|
|
1419
|
+
message: { type: 'string' },
|
|
1334
1420
|
files: {
|
|
1335
1421
|
type: 'array',
|
|
1336
1422
|
items: {
|
|
@@ -1362,6 +1448,13 @@ export function apply(ctx) {
|
|
|
1362
1448
|
review = reviews.get(session.id)
|
|
1363
1449
|
if (review === undefined || review.entries.size === 0) return { status: 'empty', files: [] }
|
|
1364
1450
|
}
|
|
1451
|
+
if (review.sessionId === session.id && featureFlags.allowBlockingReviewWait !== true) {
|
|
1452
|
+
return {
|
|
1453
|
+
status: 'blocked',
|
|
1454
|
+
files: [],
|
|
1455
|
+
message: 'The main agent must not call review_wait: start a review waiter subagent with the reviewId and waitKey (or send them to the existing persistent waiter) and continue; only the child may wait. If delegation is unavailable, the user can enable allowBlockingReviewWait in settings.',
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1365
1458
|
if (review.submitted !== true) {
|
|
1366
1459
|
review.submitted = true
|
|
1367
1460
|
bumpReview()
|
|
@@ -1380,7 +1473,7 @@ export function apply(ctx) {
|
|
|
1380
1473
|
if (!REVIEW_TOOLS.has(exec.name)) return next()
|
|
1381
1474
|
return {
|
|
1382
1475
|
kind: 'deny',
|
|
1383
|
-
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);
|
|
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.',
|
|
1384
1477
|
}
|
|
1385
1478
|
}
|
|
1386
1479
|
|
|
@@ -1391,7 +1484,7 @@ export function apply(ctx) {
|
|
|
1391
1484
|
name: 'tool:review-gate',
|
|
1392
1485
|
order: 110,
|
|
1393
1486
|
text: () => featureFlags.review === true && featureFlags.autoReview === true
|
|
1394
|
-
? '🎟️ FILE-EDIT VELVET ROPE: The human personally reviews every file change
|
|
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. 💅'
|
|
1395
1488
|
: '',
|
|
1396
1489
|
}), 'coding-enhanced: review prompt')
|
|
1397
1490
|
})
|
|
@@ -1885,6 +1978,14 @@ export function apply(ctx) {
|
|
|
1885
1978
|
featureFlags.autoReview = patch.autoReview
|
|
1886
1979
|
changed = true
|
|
1887
1980
|
}
|
|
1981
|
+
if (typeof patch.aiExplain === 'boolean' && patch.aiExplain !== featureFlags.aiExplain) {
|
|
1982
|
+
featureFlags.aiExplain = patch.aiExplain
|
|
1983
|
+
changed = true
|
|
1984
|
+
}
|
|
1985
|
+
if (typeof patch.allowBlockingReviewWait === 'boolean' && patch.allowBlockingReviewWait !== featureFlags.allowBlockingReviewWait) {
|
|
1986
|
+
featureFlags.allowBlockingReviewWait = patch.allowBlockingReviewWait
|
|
1987
|
+
changed = true
|
|
1988
|
+
}
|
|
1888
1989
|
if (Number.isSafeInteger(patch.keepTurns)) {
|
|
1889
1990
|
const next = Math.min(50, Math.max(1, patch.keepTurns))
|
|
1890
1991
|
if (next !== featureFlags.keepTurns) {
|
|
@@ -1908,13 +2009,13 @@ export function apply(ctx) {
|
|
|
1908
2009
|
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.`)
|
|
1909
2010
|
}
|
|
1910
2011
|
}
|
|
1911
|
-
return ok({ review: featureFlags.review, withdraw: featureFlags.withdraw, autoReview: featureFlags.autoReview, keepTurns: featureFlags.keepTurns, nestedSnapshots: featureFlags.nestedSnapshots, autoGc: featureFlags.autoGc, version: PLUGIN_VERSION })
|
|
2012
|
+
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 })
|
|
1912
2013
|
}
|
|
1913
2014
|
|
|
1914
2015
|
const handleUpdateCheck = async () => {
|
|
1915
2016
|
try {
|
|
1916
|
-
const
|
|
1917
|
-
return ok({ current: PLUGIN_VERSION, latest, available: compareVersions(
|
|
2017
|
+
const check = await latestNpmVersion()
|
|
2018
|
+
return ok({ current: PLUGIN_VERSION, latest: check.version, registry: check.registry, available: compareVersions(check.version, PLUGIN_VERSION) > 0 })
|
|
1918
2019
|
} catch (error) {
|
|
1919
2020
|
return fail('update-check-failed', String(error))
|
|
1920
2021
|
}
|
|
@@ -1923,7 +2024,7 @@ export function apply(ctx) {
|
|
|
1923
2024
|
const handleUpdateInstall = async () => {
|
|
1924
2025
|
let latest
|
|
1925
2026
|
try {
|
|
1926
|
-
latest = await latestNpmVersion()
|
|
2027
|
+
latest = (await latestNpmVersion()).version
|
|
1927
2028
|
} catch (error) {
|
|
1928
2029
|
return fail('update-check-failed', String(error))
|
|
1929
2030
|
}
|
|
@@ -1936,14 +2037,11 @@ export function apply(ctx) {
|
|
|
1936
2037
|
}
|
|
1937
2038
|
const spec = `dsh-coding-enhanced@${latest}`
|
|
1938
2039
|
const profileName = path.basename(profileDir)
|
|
2040
|
+
let manager
|
|
1939
2041
|
try {
|
|
1940
|
-
await
|
|
1941
|
-
} catch (
|
|
1942
|
-
|
|
1943
|
-
await execOnce('npm', ['install', spec, '--no-audit', '--no-fund'], { cwd: profileDir })
|
|
1944
|
-
} catch (npmError) {
|
|
1945
|
-
return fail('update-failed', `Could not install ${spec}. Run \`pnpm add ${spec}\` in ${profileDir} and restart DSH. ${String(npmError)}`)
|
|
1946
|
-
}
|
|
2042
|
+
manager = await installPackage(spec, profileDir)
|
|
2043
|
+
} catch (error) {
|
|
2044
|
+
return fail('update-failed', `Could not install ${spec}. Run \`dsh plugin --profile ${profileName} add ${spec}\` and restart DSH. ${String(error)}`)
|
|
1947
2045
|
}
|
|
1948
2046
|
return ok({
|
|
1949
2047
|
updated: true,
|
|
@@ -1951,7 +2049,8 @@ export function apply(ctx) {
|
|
|
1951
2049
|
to: latest,
|
|
1952
2050
|
restart: true,
|
|
1953
2051
|
profile: profileName,
|
|
1954
|
-
|
|
2052
|
+
manager,
|
|
2053
|
+
command: manager === 'dsh-bundled-pnpm' ? `dsh-bundled pnpm add ${spec}` : `${manager} add ${spec}`,
|
|
1955
2054
|
})
|
|
1956
2055
|
}
|
|
1957
2056
|
|
|
@@ -1975,7 +2074,7 @@ export function apply(ctx) {
|
|
|
1975
2074
|
const dispatch = async (endpoint, payload) => {
|
|
1976
2075
|
try {
|
|
1977
2076
|
if (endpoint === 'status') return handleStatus(payload?.sessionId)
|
|
1978
|
-
if (endpoint === 'settings') return ok({ review: featureFlags.review, withdraw: featureFlags.withdraw, autoReview: featureFlags.autoReview, keepTurns: featureFlags.keepTurns, nestedSnapshots: featureFlags.nestedSnapshots, autoGc: featureFlags.autoGc, version: PLUGIN_VERSION })
|
|
2077
|
+
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, version: PLUGIN_VERSION })
|
|
1979
2078
|
if (endpoint === 'setSettings') return updateSettings(payload)
|
|
1980
2079
|
if (endpoint === 'cleanup') return ok(await cleanupSnapshots())
|
|
1981
2080
|
if (endpoint === 'withdraw') return await handleWithdraw(payload)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-coding-enhanced",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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",
|