dsh-coding-enhanced 0.0.0-stage → 0.5.15
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 +247 -0
- package/LICENSE +21 -0
- package/README.md +454 -2
- package/cordis.patch.yml +5 -0
- package/docs/withdraw.md +560 -0
- package/lib/client.js +1727 -0
- package/lib/index.js +1771 -0
- package/package.json +52 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,1727 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-coding-enhanced — browser half.
|
|
3
|
+
*
|
|
4
|
+
* 1. Withdraw: an action in the assistant strip cancels the latest completed
|
|
5
|
+
* turn, greys it, and labels its changed-files line `已撤销`.
|
|
6
|
+
* 2. Review gate: every `write`/`edit` the AI proposes opens a right-sidebar tab
|
|
7
|
+
* (like a file preview) that lists all changes with per-file diffs, Approve /
|
|
8
|
+
* Reject, an instruction box, and manual editing of the proposed content. A
|
|
9
|
+
* floating toolbox holds Approve all / Reject all / Finish.
|
|
10
|
+
*
|
|
11
|
+
* Transport: the authenticated Connection `/api` bridge (`POST
|
|
12
|
+
* /api/coding-enhanced`).
|
|
13
|
+
*/
|
|
14
|
+
window.__ModuleLoader__.load({
|
|
15
|
+
id: 'dsh-coding-enhanced',
|
|
16
|
+
factory: (require) => {
|
|
17
|
+
var module = { exports: {} }
|
|
18
|
+
var exports = module.exports
|
|
19
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
20
|
+
|
|
21
|
+
const React = require('react')
|
|
22
|
+
const ReactDOM = require('react-dom')
|
|
23
|
+
|
|
24
|
+
const NS = 'coding-enhanced'
|
|
25
|
+
const REVIEW_TAB_ID = 'dsh-coding-enhanced/review'
|
|
26
|
+
const REVIEW_KIND = 'coding-enhanced-review'
|
|
27
|
+
const inject = ['slots', 'connection', 'locale', 'sidebarRight', 'sidebarRightTabs']
|
|
28
|
+
const EMPTY_TABS = []
|
|
29
|
+
|
|
30
|
+
const en = {
|
|
31
|
+
action: 'Withdraw this turn',
|
|
32
|
+
confirm:
|
|
33
|
+
'Withdraw turn {turn}?\n\nThe workspace will be restored to its state before this turn, and the AI will no longer see it in its context.',
|
|
34
|
+
failed: 'Withdraw failed: {message}',
|
|
35
|
+
skipped: 'These nested git repositories were left untouched (their contents are not part of the snapshot): {paths}',
|
|
36
|
+
withdrawnTitle: 'This round was withdrawn',
|
|
37
|
+
withdrawnDesc: 'The workspace is back to before this turn.',
|
|
38
|
+
withdrawnFiles: '{count} file(s) restored · the workspace is back to before this turn.',
|
|
39
|
+
fold: 'Fold',
|
|
40
|
+
resizeDiff: 'Drag to resize · double-click to reset',
|
|
41
|
+
reviewTools: 'Review tools',
|
|
42
|
+
autoReview: 'Auto review',
|
|
43
|
+
autoReviewDesc: 'The agent queues every edit with review_write / review_patch and waits via review_wait. Off: normal write/edit.',
|
|
44
|
+
reviewFeatureOff: 'AI Change Review is off in Settings. Enable it first, then use this switch.',
|
|
45
|
+
reviewOn: 'On',
|
|
46
|
+
reviewOff: 'Off',
|
|
47
|
+
unfold: 'Unfold',
|
|
48
|
+
badge: 'Withdrawn',
|
|
49
|
+
files: 'restored {count} file(s)',
|
|
50
|
+
reasonActive: 'The turn is still running',
|
|
51
|
+
reasonIncomplete: 'This turn has not finished yet.',
|
|
52
|
+
reasonNoSnapshot:
|
|
53
|
+
'Available from the next turn: this turn started before the plugin recorded a workspace snapshot',
|
|
54
|
+
|
|
55
|
+
reviewTitle: 'Code review',
|
|
56
|
+
reviewSubtitle: '{count} file(s) · nothing is written until you finish',
|
|
57
|
+
approve: 'Approve',
|
|
58
|
+
reject: 'Reject',
|
|
59
|
+
approved: 'Approved',
|
|
60
|
+
rejected: 'Rejected',
|
|
61
|
+
pending: 'Pending',
|
|
62
|
+
comment: 'Instructions for the AI (sent when you reject this file)',
|
|
63
|
+
finish: 'Finish',
|
|
64
|
+
finishPending: '{count} file(s) still need a decision',
|
|
65
|
+
approveAll: 'Approve all',
|
|
66
|
+
rejectAll: 'Reject all',
|
|
67
|
+
pendingPill: '{count} file(s) to review',
|
|
68
|
+
submitting: 'Applying…',
|
|
69
|
+
reviewFailed: 'Could not apply the review: {message}',
|
|
70
|
+
newFile: 'new',
|
|
71
|
+
truncated: 'Large diff — showing only the first part',
|
|
72
|
+
noDiff: 'No line diff is available for this change.',
|
|
73
|
+
loading: 'Loading review…',
|
|
74
|
+
reviewClosed: 'No pending review.',
|
|
75
|
+
edit: 'Edit',
|
|
76
|
+
editDone: 'Done',
|
|
77
|
+
reset: 'Reset',
|
|
78
|
+
edited: 'Edited',
|
|
79
|
+
editedHint: 'Edited files are applied automatically; no approve or reject needed.',
|
|
80
|
+
editHint: 'Finish writes your edited content, not the AI proposal.',
|
|
81
|
+
rejectAllKeepEdited: 'Reject all files that were not edited by hand? Your edited files will still be written.',
|
|
82
|
+
rejectDiscard: 'This file has your edits. Rejecting discards them. Continue?',
|
|
83
|
+
editedNeedsApprove: 'Some files have your edits but are marked Reject. Approve them or reset the edits before finishing.',
|
|
84
|
+
settingsNav: 'Coding Enhanced',
|
|
85
|
+
settingsTitle: 'Coding Enhanced',
|
|
86
|
+
settingsSubtitle: 'Toggle each sub-feature independently. Changes apply immediately and persist in your DSH home.',
|
|
87
|
+
settingsReview: 'AI Change Review',
|
|
88
|
+
settingsReviewDesc: 'Hold every write/edit in the right-sidebar review tab until you approve, reject, or edit it.',
|
|
89
|
+
settingsWithdraw: 'Turn Withdraw',
|
|
90
|
+
settingsWithdrawDesc: 'Snapshot each turn and restore the workspace when you withdraw the latest turn.',
|
|
91
|
+
settingsLoading: 'Loading settings…',
|
|
92
|
+
settingsFailed: 'Could not update: {message}',
|
|
93
|
+
settingsGroupReview: 'Review',
|
|
94
|
+
settingsGroupWithdraw: 'Turn withdraw',
|
|
95
|
+
settingsKeepTurns: 'Turns kept for withdraw',
|
|
96
|
+
settingsKeepTurnsDesc: 'How many recent turns stay withdrawable. Older snapshots are pruned automatically.',
|
|
97
|
+
settingsKeepTurnsInvalid: 'Enter a whole number from 1 to 50.',
|
|
98
|
+
settingsTurnsUnit: 'turns',
|
|
99
|
+
settingsNested: 'Snapshot nested git repositories',
|
|
100
|
+
settingsNestedDesc: 'Include the working files of nested repositories (excluding .git) so withdraw can restore them. Costs extra time and disk.',
|
|
101
|
+
settingsAutoGc: 'Automatic cleanup',
|
|
102
|
+
settingsAutoGcDesc: 'Run git gc on shadow snapshots after pruning or withdrawing. Manual cleanup always runs it.',
|
|
103
|
+
cleanupNow: 'Clean up now',
|
|
104
|
+
cleanupDone: 'Pruned {pruned} snapshot(s) and compacted {repos} repository(ies).',
|
|
105
|
+
cleanupFailed: 'Cleanup failed: {message}',
|
|
106
|
+
rewindAction: 'Withdraw from here',
|
|
107
|
+
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}.',
|
|
108
|
+
settingsFeatures: 'Features',
|
|
109
|
+
collecting: 'The agent is still proposing changes. Finish unlocks when it calls review_wait.',
|
|
110
|
+
waitingSubmit: 'Waiting for the agent…',
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const zh = {
|
|
114
|
+
action: '撤回本轮',
|
|
115
|
+
confirm:
|
|
116
|
+
'撤回第 {turn} 轮?\n\n工作区将恢复到本轮开始前,AI 的上下文中也不再包含这一轮。',
|
|
117
|
+
failed: '撤回失败:{message}',
|
|
118
|
+
skipped: '以下嵌套 git 仓库未参与快照,内容保持原样:{paths}',
|
|
119
|
+
withdrawnTitle: '本轮已撤销',
|
|
120
|
+
withdrawnDesc: '工作区已恢复到本轮开始前。',
|
|
121
|
+
withdrawnFiles: '恢复 {count} 个文件 · 工作区回到本轮开始前。',
|
|
122
|
+
fold: '折叠',
|
|
123
|
+
resizeDiff: '拖动调整高度 · 双击还原',
|
|
124
|
+
reviewTools: 'Review 工具',
|
|
125
|
+
autoReview: '自动 review',
|
|
126
|
+
autoReviewDesc: 'AI 用 review_write / review_patch 排队所有改动,并通过 review_wait 等你审阅。关闭后走普通的 write/edit。',
|
|
127
|
+
reviewFeatureOff: '设置里的 AI Change Review 处于关闭状态,先启用后再用这个开关。',
|
|
128
|
+
reviewOn: '开',
|
|
129
|
+
reviewOff: '关',
|
|
130
|
+
unfold: '展开',
|
|
131
|
+
badge: '已撤销',
|
|
132
|
+
files: '恢复 {count} 个文件',
|
|
133
|
+
reasonActive: '本轮仍在运行',
|
|
134
|
+
reasonIncomplete: '本轮尚未结束。',
|
|
135
|
+
reasonNoSnapshot: '从下一轮开始可用:本轮开始时插件还没有记录工作区快照',
|
|
136
|
+
|
|
137
|
+
reviewTitle: '代码审查',
|
|
138
|
+
reviewSubtitle: '{count} 个文件 · 全部确认后才会写入',
|
|
139
|
+
approve: '通过',
|
|
140
|
+
reject: '拒绝',
|
|
141
|
+
approved: '已通过',
|
|
142
|
+
rejected: '已拒绝',
|
|
143
|
+
pending: '待确认',
|
|
144
|
+
comment: '给 AI 的具体修改意见(拒绝该文件时发送)',
|
|
145
|
+
finish: '完成',
|
|
146
|
+
finishPending: '还有 {count} 个文件未确认',
|
|
147
|
+
approveAll: '全部通过',
|
|
148
|
+
rejectAll: '全部拒绝',
|
|
149
|
+
pendingPill: '{count} 个文件待审查',
|
|
150
|
+
submitting: '正在应用…',
|
|
151
|
+
reviewFailed: '提交失败:{message}',
|
|
152
|
+
newFile: '新增',
|
|
153
|
+
truncated: '差异过大,仅显示前面部分',
|
|
154
|
+
noDiff: '此改动没有可显示的行级差异。',
|
|
155
|
+
loading: '正在加载审查…',
|
|
156
|
+
reviewClosed: '没有待审查的改动。',
|
|
157
|
+
edit: '编辑',
|
|
158
|
+
editDone: '完成',
|
|
159
|
+
reset: '还原',
|
|
160
|
+
edited: '已修改',
|
|
161
|
+
editedHint: '手动修改过的文件会直接写入,不需要再通过或拒绝。',
|
|
162
|
+
editHint: '点击完成后写入你编辑后的内容,而不是 AI 的原始提案。',
|
|
163
|
+
rejectAllKeepEdited: '拒绝所有未手动修改的文件?你手动修改过的文件仍会写入。',
|
|
164
|
+
rejectDiscard: '这个文件有你的修改。拒绝会丢弃这些修改,继续吗?',
|
|
165
|
+
editedNeedsApprove: '有文件包含你的修改但被标记为拒绝。请通过它们或还原修改后再完成。',
|
|
166
|
+
settingsNav: '编码增强',
|
|
167
|
+
settingsTitle: '编码增强',
|
|
168
|
+
settingsSubtitle: '两个子功能可以独立开关,修改立即生效并保存在 DSH 数据目录。',
|
|
169
|
+
settingsReview: 'AI 改动审查',
|
|
170
|
+
settingsReviewDesc: '每次 write/edit 都先停在右侧审查页,等你通过、拒绝或手动修改后再写入。',
|
|
171
|
+
settingsWithdraw: '撤回本轮',
|
|
172
|
+
settingsWithdrawDesc: '每轮开始时记录工作区快照;撤回最新一轮时恢复工作区。',
|
|
173
|
+
settingsLoading: '正在加载设置…',
|
|
174
|
+
settingsFailed: '更新失败:{message}',
|
|
175
|
+
settingsGroupReview: '审查',
|
|
176
|
+
settingsGroupWithdraw: '撤回',
|
|
177
|
+
settingsKeepTurns: '保留可撤回轮数',
|
|
178
|
+
settingsKeepTurnsDesc: '最近多少轮保持可撤回;更早的快照会自动清理。',
|
|
179
|
+
settingsKeepTurnsInvalid: '请输入 1–50 的整数。',
|
|
180
|
+
settingsTurnsUnit: '轮',
|
|
181
|
+
settingsNested: '包含嵌套 git 仓库',
|
|
182
|
+
settingsNestedDesc: '把嵌套仓库的工作区文件(不含 .git)也纳入快照,撤回时可以恢复它们;会多花一些时间和磁盘。',
|
|
183
|
+
settingsAutoGc: '自动清理',
|
|
184
|
+
settingsAutoGcDesc: '清理或撤回后对影子快照执行 git gc;手动清理始终会执行。',
|
|
185
|
+
cleanupNow: '立即清理',
|
|
186
|
+
cleanupDone: '已清理 {pruned} 个快照,压缩 {repos} 个仓库。',
|
|
187
|
+
cleanupFailed: '清理失败:{message}',
|
|
188
|
+
rewindAction: '从这里撤回',
|
|
189
|
+
rewindConfirm: '撤回第 {turn} 轮?第 {turn} 到第 {latest} 轮都会从模型上下文中撤销,工作区恢复到第 {turn} 轮开始前。',
|
|
190
|
+
settingsFeatures: '功能开关',
|
|
191
|
+
collecting: 'AI 还在提交改动;等它调用 review_wait 后即可完成。',
|
|
192
|
+
waitingSubmit: '等待 AI…',
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const STYLE_ID = 'dsh-coding-enhanced-styles'
|
|
196
|
+
const CSS = `
|
|
197
|
+
[data-withdraw-canceled]{opacity:.6;filter:grayscale(.35);transition:opacity .15s ease,filter .15s ease}
|
|
198
|
+
[data-chat-turn][data-withdraw-canceled]:not([data-step-process]){border-left:2px dashed var(--dsw-alias-state-warn-primary,#9a6700);padding-left:.7em}
|
|
199
|
+
[data-step-process][data-withdraw-canceled]{border:1px dashed color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 45%,transparent);border-radius:.75em;padding:.45em;box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 18%,transparent)}
|
|
200
|
+
[data-withdraw-changes]::after{content:attr(data-withdraw-label);margin-left:.6em;padding:0 .5em;border-radius:.3em;font-size:.78em;line-height:1.5;font-weight:400;color:var(--dsw-alias-label-tertiary);background:var(--dsw-alias-interactive-bg-hover);white-space:nowrap}
|
|
201
|
+
[data-withdraw-button]{display:inline-flex;align-items:center;justify-content:center;width:1.9em;height:1.9em;padding:0;border:0;border-radius:.45em;background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer;transition:background-color .12s,color .12s}
|
|
202
|
+
[data-withdraw-button]:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
203
|
+
[data-withdraw-button]:disabled{opacity:.5;cursor:default}
|
|
204
|
+
[data-withdraw-badge]{display:inline-block;border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-tertiary);padding:0 .5em;font-size:.78em;line-height:1.5;white-space:nowrap}
|
|
205
|
+
.wr-withdrawn{display:flex;align-items:flex-start;gap:.7em;margin:.7em 0;padding:.75em .9em;border:1px dashed color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 40%,transparent);border-radius:.75em;background:color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 7%,transparent);font-size:1em}
|
|
206
|
+
.wr-withdrawn-icon{display:inline-flex;align-items:center;justify-content:center;width:1.7em;height:1.7em;border-radius:50%;background:color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 16%,transparent);color:var(--dsw-alias-state-warn-primary,#9a6700);flex:none}
|
|
207
|
+
.wr-withdrawn-main{flex:1;min-width:0}
|
|
208
|
+
.wr-withdrawn-title{font-size:.92em;font-weight:600;line-height:1.4;color:var(--dsw-alias-label-primary,#1a1a1a)}
|
|
209
|
+
.wr-withdrawn-desc{font-size:.82em;line-height:1.45;color:var(--dsw-alias-label-tertiary,#888);margin-top:.15em}
|
|
210
|
+
.wr-withdrawn-chip{flex:none;align-self:center;padding:.1em .55em;border-radius:.4em;background:color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 14%,transparent);color:var(--dsw-alias-state-warn-primary,#9a6700);font-size:.74em;font-weight:600;line-height:1.6;white-space:nowrap}
|
|
211
|
+
.wr-withdrawn-actions{display:inline-flex;align-items:center;gap:.35em;flex:none}
|
|
212
|
+
.wr-withdrawn-action{display:inline-flex;align-items:center;gap:.35em;padding:.15em .55em;border-radius:.45em;border:1px dashed color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 40%,transparent);background:color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 8%,transparent);color:var(--dsw-alias-state-warn-primary,#9a6700);font-size:.78em;line-height:1.5;white-space:nowrap}
|
|
213
|
+
.wr-withdrawn-action svg{width:1em;height:1em}
|
|
214
|
+
/* Keep the withdrawn chip visible without hovering the turn tail. */
|
|
215
|
+
[data-actions-reveal="hover"]:has(.wr-withdrawn-action) > *{opacity:1!important}
|
|
216
|
+
.wr-withdrawn-fold{flex:none;align-self:center;padding:.15em .55em;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.12));border-radius:.4em;background:transparent;color:var(--dsw-alias-label-secondary,#555);font-size:.74em;line-height:1.6;cursor:pointer;white-space:nowrap}
|
|
217
|
+
.wr-withdrawn-fold:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.06))}
|
|
218
|
+
/* Folded withdrawn turn: hide every row that does not contain the turn-tail banner. */
|
|
219
|
+
[data-withdraw-folded]:not(:has([data-turn-tail])){display:none!important}
|
|
220
|
+
|
|
221
|
+
.wr-pane{position:relative;display:flex;flex-direction:column;height:100%;min-height:0;min-width:0;overflow:hidden;background:var(--dsw-alias-bg-base);font-size:1em;color:var(--dsw-alias-label-primary,#1a1a1a)}
|
|
222
|
+
.wr-pane-head{display:flex;align-items:center;gap:.6em;flex:none;padding:.7em .9em;border-bottom:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08));background:var(--dsw-alias-bg-base)}
|
|
223
|
+
.wr-pane-title{font-size:1.05em;font-weight:600;line-height:1.4}
|
|
224
|
+
.wr-pane-sub{font-size:.8em;line-height:1.4;color:var(--dsw-alias-label-tertiary,#888)}
|
|
225
|
+
.wr-scroll{flex:1 1 auto;min-height:0;overflow-y:auto;overflow-x:hidden;padding:.7em .7em 5em;display:flex;flex-direction:column;gap:.8em}
|
|
226
|
+
.wr-empty{display:flex;align-items:center;justify-content:center;height:100%;min-height:12em;color:var(--dsw-alias-label-tertiary,#888);font-size:.9em}
|
|
227
|
+
.wr-file{flex:0 0 auto;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.12));border-radius:.75em;overflow:hidden;background:var(--dsw-alias-bg-layer-1,#fff)}
|
|
228
|
+
.wr-file.approved{border-color:var(--dsw-alias-state-success-primary,#2da44e)}
|
|
229
|
+
.wr-file.rejected{border-color:var(--dsw-alias-state-error-primary,#cf222e)}
|
|
230
|
+
.wr-file.edited{border-color:var(--dsw-alias-state-warn-primary,#9a6700)}
|
|
231
|
+
.wr-file-head{display:flex;align-items:center;flex-wrap:wrap;gap:.4em;padding:.6em .8em;border-bottom:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08));background:var(--dsw-alias-bg-base,#fafafa)}
|
|
232
|
+
.wr-path{flex:1 1 100%;min-width:0;font-weight:600;font-size:.92em;line-height:1.4;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
233
|
+
.wr-chip{flex:none;border-radius:.3em;padding:0 .5em;font-size:.72em;line-height:1.6;background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.06));color:var(--dsw-alias-label-secondary,#555)}
|
|
234
|
+
.wr-chip.ok{color:var(--dsw-alias-state-success-primary,#2da44e)}
|
|
235
|
+
.wr-chip.no{color:var(--dsw-alias-state-error-primary,#cf222e)}
|
|
236
|
+
.wr-chip.edited{color:var(--dsw-alias-state-warn-primary,#9a6700);background:color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 14%,transparent)}
|
|
237
|
+
.wr-add{flex:none;font-size:.8em;font-weight:600;color:var(--dsw-alias-state-success-primary,#2da44e)}
|
|
238
|
+
.wr-del{flex:none;font-size:.8em;font-weight:600;color:var(--dsw-alias-state-error-primary,#cf222e)}
|
|
239
|
+
.wr-btn{display:inline-flex;align-items:center;justify-content:center;gap:.4em;padding:.35em .8em;border-radius:.5em;border:1px solid var(--dsw-alias-border-l3,rgba(0,0,0,.16));background:transparent;color:var(--dsw-alias-label-primary,#1a1a1a);font:inherit;font-size:.88em;line-height:1.5;cursor:pointer;white-space:nowrap}
|
|
240
|
+
.wr-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.06))}
|
|
241
|
+
.wr-btn:disabled{opacity:.45;cursor:default}
|
|
242
|
+
.wr-btn.sm{padding:.2em .6em;font-size:.8em}
|
|
243
|
+
.wr-btn.ok.active{border-color:var(--dsw-alias-state-success-primary,#2da44e);color:var(--dsw-alias-state-success-primary,#2da44e);background:var(--dsw-alias-file-diff-added-bg,rgba(46,160,67,.12))}
|
|
244
|
+
.wr-btn.no.active{border-color:var(--dsw-alias-state-error-primary,#cf222e);color:var(--dsw-alias-state-error-primary,#cf222e);background:var(--dsw-alias-file-diff-deleted-bg,rgba(248,81,73,.12))}
|
|
245
|
+
.wr-btn.primary{border-color:transparent;background:var(--dsw-alias-state-business-primary,#4d6bfe);color:#fff;font-weight:600}
|
|
246
|
+
.wr-btn.primary:hover:not(:disabled){filter:brightness(1.05)}
|
|
247
|
+
.wr-note{margin:0;padding:.35em .7em;font-size:.82em;line-height:1.5;color:var(--dsw-alias-label-tertiary,#888)}
|
|
248
|
+
.wr-note.warn{color:var(--dsw-alias-state-warn-primary,#9a6700);background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.04))}
|
|
249
|
+
.wr-diff{max-height:var(--wr-diff-height,min(45vh,30em));overflow:auto;font-family:var(--ds-font-family-code,ui-monospace,SFMono-Regular,Menlo,Consolas,monospace);font-size:.92em;line-height:1.6;tab-size:4}
|
|
250
|
+
.wr-line{display:flex;white-space:pre}
|
|
251
|
+
.wr-line.add{background:var(--dsw-alias-file-diff-added-bg,rgba(46,160,67,.12))}
|
|
252
|
+
.wr-line.del{background:var(--dsw-alias-file-diff-deleted-bg,rgba(248,81,73,.12))}
|
|
253
|
+
.wr-line.add .wr-no{background:var(--dsw-alias-file-diff-added-gutter,rgba(46,160,67,.18))}
|
|
254
|
+
.wr-line.del .wr-no{background:var(--dsw-alias-file-diff-deleted-gutter,rgba(248,81,73,.18))}
|
|
255
|
+
.wr-no{flex:none;width:3.2em;padding-right:.4em;text-align:right;color:var(--dsw-alias-label-tertiary,#999);user-select:none}
|
|
256
|
+
.wr-sign{flex:none;width:1.2em;text-align:center;color:var(--dsw-alias-label-tertiary,#999)}
|
|
257
|
+
.wr-text{flex:1;padding-right:.7em;min-width:0}
|
|
258
|
+
.ce-review-trigger{position:relative;display:inline-flex;align-items:center;justify-content:center;width:calc(28px + var(--dsh-content-font-delta,0px));height:calc(28px + var(--dsh-content-font-delta,0px));padding:0;border:0;border-radius:999px;background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer;transition:background-color .12s,color .12s}
|
|
259
|
+
.ce-review-trigger:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
260
|
+
.ce-review-trigger.disabled{opacity:.5}
|
|
261
|
+
.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)}
|
|
262
|
+
.ce-review-dot.on{background:var(--dsw-alias-state-success-primary,#2da44e)}
|
|
263
|
+
.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}
|
|
264
|
+
.ce-review-head{display:flex;align-items:center;justify-content:space-between;gap:8px}
|
|
265
|
+
.ce-review-title{font-size:14px;font-weight:600;line-height:20px}
|
|
266
|
+
.ce-review-state{font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary);padding:0 6px;border-radius:999px;background:var(--dsw-alias-interactive-bg-hover)}
|
|
267
|
+
.ce-review-state.on{color:var(--dsw-alias-state-success-primary,#2da44e);background:color-mix(in srgb,var(--dsw-alias-state-success-primary,#2da44e) 12%,transparent)}
|
|
268
|
+
.ce-review-row{display:flex;align-items:center;gap:12px;margin-top:12px}
|
|
269
|
+
.ce-review-text{flex:1;min-width:0}
|
|
270
|
+
.ce-review-row-title{font-size:13px;font-weight:600;line-height:18px}
|
|
271
|
+
.ce-review-row-desc{font-size:12px;line-height:17px;color:var(--dsw-alias-label-tertiary);margin-top:2px}
|
|
272
|
+
.ce-review-off{font-size:12px;line-height:17px;color:var(--dsw-alias-label-tertiary);margin-top:10px}
|
|
273
|
+
.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}
|
|
274
|
+
.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))}
|
|
275
|
+
.wr-diff-resize:hover{background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4d6bfe) 12%,transparent)}
|
|
276
|
+
.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))}
|
|
277
|
+
.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}
|
|
278
|
+
.wr-comment:focus{outline:2px solid var(--dsw-alias-state-business-primary,#4d6bfe);outline-offset:-1px}
|
|
279
|
+
.wr-editor{display:block;width:calc(100% - 1.4em);margin:.55em .7em;box-sizing:border-box;min-height:16em;resize:vertical;padding:.6em;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-family:var(--ds-font-family-code,ui-monospace,SFMono-Regular,Menlo,Consolas,monospace);font-size:.92em;line-height:1.6;tab-size:4}
|
|
280
|
+
.wr-editor:focus{outline:2px solid var(--dsw-alias-state-business-primary,#4d6bfe);outline-offset:-1px}
|
|
281
|
+
.wr-toolbar{position:absolute;right:.7em;bottom:.7em;z-index:3;flex:0 0 auto;display:flex;align-items:center;flex-wrap:wrap;gap:.4em;width:max-content;max-width:calc(100% - 1.4em);padding:.45em .6em;border-radius:.8em;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.14));background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 .5em 1.5em rgba(0,0,0,.16)}
|
|
282
|
+
.wr-toolbar-info{font-size:.8em;line-height:1.5;color:var(--dsw-alias-label-tertiary,#888);padding:0 .3em}
|
|
283
|
+
.wr-error{color:var(--dsw-alias-state-error-primary,#cf222e);font-size:.8em;line-height:1.5;padding:0 .3em}
|
|
284
|
+
.wr-pill{position:fixed;right:1.5em;bottom:1.5em;z-index:3999;display:inline-flex;align-items:center;gap:.5em;padding:.6em 1em;border-radius:999px;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.14));background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,#1a1a1a);font:inherit;font-size:.9em;line-height:1.4;cursor:pointer;box-shadow:0 .5em 1.8em rgba(0,0,0,.18)}
|
|
285
|
+
.wr-pill:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.06))}
|
|
286
|
+
.wr-collecting{flex:none;padding:.5em .8em;font-size:.8em;line-height:1.5;color:var(--dsw-alias-state-warn-primary,#9a6700);background:color-mix(in srgb,var(--dsw-alias-state-warn-primary,#9a6700) 10%,transparent);border-bottom:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08))}
|
|
287
|
+
|
|
288
|
+
.ce-settings{padding:1.7em;max-width:52em;box-sizing:border-box;font-size:1em}
|
|
289
|
+
.ce-title{font-size:1.3em;line-height:1.35;font-weight:600;margin:0 0 .35em;color:var(--dsw-alias-label-primary)}
|
|
290
|
+
.ce-sub{font-size:.87em;line-height:1.5;color:var(--dsw-alias-label-tertiary);margin:0 0 1.1em}
|
|
291
|
+
.ce-card{border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.12));border-radius:.85em;overflow:hidden;background:var(--dsw-alias-bg-layer-1,#fff)}
|
|
292
|
+
.ce-row{display:flex;align-items:center;gap:1em;padding:.95em 1.1em;border-bottom:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08))}
|
|
293
|
+
.ce-row:last-child{border-bottom:0}
|
|
294
|
+
.ce-row-text{flex:1;min-width:0}
|
|
295
|
+
.ce-row-title{font-size:.95em;line-height:1.4;font-weight:600;color:var(--dsw-alias-label-primary,#1a1a1a)}
|
|
296
|
+
.ce-row-desc{font-size:.84em;line-height:1.45;color:var(--dsw-alias-label-tertiary,#888);margin-top:.15em}
|
|
297
|
+
.ce-switch{position:relative;flex:none;box-sizing:border-box;width:2.6em;height:1.45em;padding:0;border-radius:999px;border:1px solid var(--dsw-alias-border-l3,rgba(0,0,0,.16));background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.06));cursor:pointer;transition:background-color .15s,border-color .15s}
|
|
298
|
+
.ce-switch.on{background:var(--dsw-alias-state-business-primary,#4d6bfe);border-color:transparent}
|
|
299
|
+
.ce-switch:disabled{opacity:.5;cursor:default}
|
|
300
|
+
.ce-switch-thumb{position:absolute;top:.12em;left:.12em;width:1.05em;height:1.05em;border-radius:50%;background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.25);transition:transform .15s}
|
|
301
|
+
.ce-switch.on .ce-switch-thumb{transform:translateX(1.15em)}
|
|
302
|
+
.ce-number-wrap{display:flex;align-items:center;gap:.4em;flex:none}
|
|
303
|
+
.ce-number{width:4.2em;box-sizing:border-box;padding:.35em .5em;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.12));border-radius:.5em;background:var(--dsw-alias-bg-base,#fafafa);color:var(--dsw-alias-label-primary,#1a1a1a);font-size:.9em;line-height:1.4;text-align:center;outline:none}
|
|
304
|
+
.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)}
|
|
305
|
+
.ce-number:disabled{opacity:.5}
|
|
306
|
+
.ce-number-unit{font-size:.78em;color:var(--dsw-alias-label-tertiary,#888)}
|
|
307
|
+
.ce-action{flex:none;padding:.4em .75em;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.12));border-radius:.5em;background:var(--dsw-alias-bg-base,#fafafa);color:var(--dsw-alias-label-primary,#1a1a1a);font-size:.82em;line-height:1.4;cursor:pointer}
|
|
308
|
+
.ce-action:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.06))}
|
|
309
|
+
.ce-action:disabled{opacity:.5;cursor:default}
|
|
310
|
+
.ce-error{font-size:.82em;line-height:1.45;color:var(--dsw-alias-state-error-primary,#cf222e);margin:.7em 0 0}
|
|
311
|
+
.ce-settings.compact{padding:0;max-width:none}
|
|
312
|
+
.ce-compact-title{font-size:.82em;line-height:1.4;font-weight:600;color:var(--dsw-alias-label-secondary,#555);margin:0 0 .45em}
|
|
313
|
+
.ce-group-title{font-size:.76em;line-height:1.4;font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--dsw-alias-label-tertiary,#888);margin:1.1em 0 .45em}
|
|
314
|
+
.ce-group-title:first-of-type{margin-top:0}
|
|
315
|
+
.ce-settings.compact .ce-card{background:var(--dsw-alias-bg-base,#fafafa)}
|
|
316
|
+
|
|
317
|
+
/* Plugin detail page: config switches above the README, README in a scroll box */
|
|
318
|
+
[data-detail-document]{max-height:min(420px,50vh);overflow:auto;box-sizing:border-box;padding:10px 14px;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.12));border-radius:10px;background:var(--dsw-alias-bg-layer-1,#fff)}
|
|
319
|
+
div:has(> [data-detail-document]) > [data-plugin-config]{order:-1}
|
|
320
|
+
`
|
|
321
|
+
|
|
322
|
+
function apply(ctx) {
|
|
323
|
+
// ------------------------------------------------------------- copy ---
|
|
324
|
+
try {
|
|
325
|
+
ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'coding-enhanced: dictionaries')
|
|
326
|
+
} catch {}
|
|
327
|
+
|
|
328
|
+
// ------------------------------------------------------------ styles ---
|
|
329
|
+
ctx.effect(() => {
|
|
330
|
+
const style = document.createElement('style')
|
|
331
|
+
style.id = STYLE_ID
|
|
332
|
+
style.textContent = CSS
|
|
333
|
+
document.head.appendChild(style)
|
|
334
|
+
return () => style.remove()
|
|
335
|
+
}, 'coding-enhanced: styles')
|
|
336
|
+
|
|
337
|
+
// ------------------------------------------------------------- rpc ---
|
|
338
|
+
const call = async (endpoint, payload) => {
|
|
339
|
+
try {
|
|
340
|
+
const response = await fetch('api/coding-enhanced', {
|
|
341
|
+
method: 'POST',
|
|
342
|
+
headers: { 'content-type': 'application/json' },
|
|
343
|
+
body: JSON.stringify({ endpoint, payload }),
|
|
344
|
+
})
|
|
345
|
+
if (!response.ok) {
|
|
346
|
+
return { ok: false, error: { message: `HTTP ${response.status}` } }
|
|
347
|
+
}
|
|
348
|
+
return await response.json()
|
|
349
|
+
} catch (error) {
|
|
350
|
+
return { ok: false, error: { message: String(error) } }
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// -------------------------------------------------- withdraw store ---
|
|
355
|
+
const records = new Map()
|
|
356
|
+
const listeners = new Map()
|
|
357
|
+
const inflight = new Map()
|
|
358
|
+
const fetchedAt = new Map()
|
|
359
|
+
|
|
360
|
+
const notify = (sessionId) => {
|
|
361
|
+
const set = listeners.get(sessionId)
|
|
362
|
+
if (set === undefined) return
|
|
363
|
+
for (const listener of [...set]) listener()
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const setRecord = (sessionId, record) => {
|
|
367
|
+
records.set(sessionId, record)
|
|
368
|
+
notify(sessionId)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const refresh = (sessionId, force = false) => {
|
|
372
|
+
if (typeof sessionId !== 'string' || sessionId === '') return undefined
|
|
373
|
+
if (!force && fetchedAt.has(sessionId) && Date.now() - fetchedAt.get(sessionId) < 250) {
|
|
374
|
+
return inflight.get(sessionId)
|
|
375
|
+
}
|
|
376
|
+
const running = inflight.get(sessionId)
|
|
377
|
+
if (running !== undefined) return running
|
|
378
|
+
const promise = (async () => {
|
|
379
|
+
const result = await call('status', { sessionId })
|
|
380
|
+
if (result.ok === true) {
|
|
381
|
+
records.set(sessionId, { status: 'ready', value: result.value })
|
|
382
|
+
} else {
|
|
383
|
+
records.set(sessionId, {
|
|
384
|
+
status: 'error',
|
|
385
|
+
message: result.error?.message ?? 'status failed',
|
|
386
|
+
})
|
|
387
|
+
}
|
|
388
|
+
fetchedAt.set(sessionId, Date.now())
|
|
389
|
+
notify(sessionId)
|
|
390
|
+
})().finally(() => {
|
|
391
|
+
inflight.delete(sessionId)
|
|
392
|
+
})
|
|
393
|
+
inflight.set(sessionId, promise)
|
|
394
|
+
return promise
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const subscribe = (sessionId, listener) => {
|
|
398
|
+
let set = listeners.get(sessionId)
|
|
399
|
+
if (set === undefined) {
|
|
400
|
+
set = new Set()
|
|
401
|
+
listeners.set(sessionId, set)
|
|
402
|
+
}
|
|
403
|
+
set.add(listener)
|
|
404
|
+
return () => {
|
|
405
|
+
set.delete(listener)
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const pollTimers = new Map()
|
|
410
|
+
const pollCounts = new Map()
|
|
411
|
+
const acquirePoll = (sessionId) => {
|
|
412
|
+
pollCounts.set(sessionId, (pollCounts.get(sessionId) ?? 0) + 1)
|
|
413
|
+
if (!pollTimers.has(sessionId)) {
|
|
414
|
+
pollTimers.set(sessionId, window.setInterval(() => {
|
|
415
|
+
void refresh(sessionId, true)
|
|
416
|
+
}, 1500))
|
|
417
|
+
}
|
|
418
|
+
return () => {
|
|
419
|
+
const next = (pollCounts.get(sessionId) ?? 1) - 1
|
|
420
|
+
if (next > 0) {
|
|
421
|
+
pollCounts.set(sessionId, next)
|
|
422
|
+
return
|
|
423
|
+
}
|
|
424
|
+
pollCounts.delete(sessionId)
|
|
425
|
+
const timer = pollTimers.get(sessionId)
|
|
426
|
+
if (timer !== undefined) {
|
|
427
|
+
window.clearInterval(timer)
|
|
428
|
+
pollTimers.delete(sessionId)
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const useRecord = (sessionId) => {
|
|
434
|
+
const [, bump] = React.useState(0)
|
|
435
|
+
React.useEffect(() => {
|
|
436
|
+
const unsubscribe = subscribe(sessionId, () => bump((value) => value + 1))
|
|
437
|
+
const releasePoll = acquirePoll(sessionId)
|
|
438
|
+
void refresh(sessionId)
|
|
439
|
+
return () => {
|
|
440
|
+
unsubscribe()
|
|
441
|
+
releasePoll()
|
|
442
|
+
}
|
|
443
|
+
}, [sessionId])
|
|
444
|
+
return records.get(sessionId)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// -------------------------------------------------------- decorate ---
|
|
448
|
+
const annotateChangedFiles = (node, label) => {
|
|
449
|
+
const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT)
|
|
450
|
+
let current = walker.nextNode()
|
|
451
|
+
while (current !== null) {
|
|
452
|
+
const text = (current.nodeValue ?? '').trim()
|
|
453
|
+
if (text !== '' && /^(已编辑|Edited|編集しました)/.test(text)) {
|
|
454
|
+
const button = current.parentElement?.closest('button')
|
|
455
|
+
if (button !== null && button !== undefined) {
|
|
456
|
+
button.setAttribute('data-withdraw-changes', '')
|
|
457
|
+
button.setAttribute('data-withdraw-label', label)
|
|
458
|
+
return
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
current = walker.nextNode()
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const markTurn = (turn, label) => {
|
|
466
|
+
const nodes = [...document.querySelectorAll(`[data-chat-turn="${turn}"]`)]
|
|
467
|
+
// Only the outermost containers carry the dim/frame attribute; nested
|
|
468
|
+
// rows inherit it. Applying it to every nested row multiplies opacity.
|
|
469
|
+
const outer = nodes.filter((node) => !nodes.some((other) => other !== node && other.contains(node)))
|
|
470
|
+
for (const node of nodes) annotateChangedFiles(node, label)
|
|
471
|
+
for (const node of outer) node.setAttribute('data-withdraw-canceled', '')
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const clearTurn = (turn) => {
|
|
475
|
+
const nodes = document.querySelectorAll(`[data-chat-turn="${turn}"]`)
|
|
476
|
+
for (const node of nodes) {
|
|
477
|
+
node.removeAttribute('data-withdraw-canceled')
|
|
478
|
+
for (const decorated of node.querySelectorAll('[data-withdraw-changes]')) {
|
|
479
|
+
decorated.removeAttribute('data-withdraw-changes')
|
|
480
|
+
decorated.removeAttribute('data-withdraw-label')
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const foldKey = (sessionId, turn) => `dsh-coding-enhanced:withdraw-fold:${sessionId}:${turn}`
|
|
486
|
+
const readFold = (sessionId, turn) => {
|
|
487
|
+
try {
|
|
488
|
+
return window.localStorage.getItem(foldKey(sessionId, turn)) === '1'
|
|
489
|
+
} catch {
|
|
490
|
+
return false
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const writeFold = (sessionId, turn, folded) => {
|
|
494
|
+
try {
|
|
495
|
+
window.localStorage.setItem(foldKey(sessionId, turn), folded ? '1' : '0')
|
|
496
|
+
} catch {}
|
|
497
|
+
}
|
|
498
|
+
const applyFold = (turn, folded) => {
|
|
499
|
+
for (const node of document.querySelectorAll(`[data-chat-turn="${turn}"]`)) {
|
|
500
|
+
if (folded) node.setAttribute('data-withdraw-folded', '')
|
|
501
|
+
else node.removeAttribute('data-withdraw-folded')
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// ------------------------------------------------------ components ---
|
|
506
|
+
const UndoIcon = () =>
|
|
507
|
+
React.createElement(
|
|
508
|
+
'svg',
|
|
509
|
+
{
|
|
510
|
+
width: 16,
|
|
511
|
+
height: 16,
|
|
512
|
+
viewBox: '0 0 16 16',
|
|
513
|
+
fill: 'none',
|
|
514
|
+
stroke: 'currentColor',
|
|
515
|
+
strokeWidth: 1.4,
|
|
516
|
+
strokeLinecap: 'round',
|
|
517
|
+
strokeLinejoin: 'round',
|
|
518
|
+
'aria-hidden': true,
|
|
519
|
+
},
|
|
520
|
+
React.createElement('path', { d: 'M3.5 6.5h6a3.5 3.5 0 0 1 0 7H6' }),
|
|
521
|
+
React.createElement('path', { d: 'M6 3.5 3 6.5l3 3' }),
|
|
522
|
+
)
|
|
523
|
+
|
|
524
|
+
function WithdrawAction(props) {
|
|
525
|
+
const { messageId, sessionId, t } = props
|
|
526
|
+
const record = useRecord(sessionId)
|
|
527
|
+
const [busy, setBusy] = React.useState(false)
|
|
528
|
+
const value = record?.status === 'ready' ? record.value : undefined
|
|
529
|
+
const turn = value?.anchors?.[messageId]
|
|
530
|
+
const isWithdrawn = turn !== undefined && value?.turns?.[turn] !== undefined
|
|
531
|
+
const [folded, setFolded] = React.useState(() => (turn === undefined ? false : readFold(sessionId, turn)))
|
|
532
|
+
|
|
533
|
+
React.useEffect(() => {
|
|
534
|
+
if (turn === undefined) return
|
|
535
|
+
setFolded(readFold(sessionId, turn))
|
|
536
|
+
}, [sessionId, turn])
|
|
537
|
+
|
|
538
|
+
React.useEffect(() => {
|
|
539
|
+
if (turn === undefined || !isWithdrawn) return
|
|
540
|
+
applyFold(turn, folded)
|
|
541
|
+
}, [turn, isWithdrawn, folded])
|
|
542
|
+
|
|
543
|
+
if (record === undefined || record.status !== 'ready') return null
|
|
544
|
+
if (turn === undefined) return null
|
|
545
|
+
if (isWithdrawn) {
|
|
546
|
+
const toggleFold = () => {
|
|
547
|
+
const next = !folded
|
|
548
|
+
setFolded(next)
|
|
549
|
+
writeFold(sessionId, turn, next)
|
|
550
|
+
applyFold(turn, next)
|
|
551
|
+
}
|
|
552
|
+
return React.createElement(
|
|
553
|
+
'span',
|
|
554
|
+
{ className: 'wr-withdrawn-actions' },
|
|
555
|
+
React.createElement(
|
|
556
|
+
'span',
|
|
557
|
+
{
|
|
558
|
+
className: 'wr-withdrawn-action',
|
|
559
|
+
title: typeof t === 'function' ? t('withdrawnTitle') : 'This round was withdrawn',
|
|
560
|
+
},
|
|
561
|
+
React.createElement(UndoIcon, null),
|
|
562
|
+
React.createElement('span', null, typeof t === 'function' ? t('badge') : 'Withdrawn'),
|
|
563
|
+
),
|
|
564
|
+
React.createElement(
|
|
565
|
+
'button',
|
|
566
|
+
{
|
|
567
|
+
type: 'button',
|
|
568
|
+
className: 'wr-withdrawn-fold',
|
|
569
|
+
'aria-expanded': !folded,
|
|
570
|
+
title: typeof t === 'function' ? (folded ? t('unfold') : t('fold')) : (folded ? 'Unfold' : 'Fold'),
|
|
571
|
+
onClick: toggleFold,
|
|
572
|
+
},
|
|
573
|
+
folded
|
|
574
|
+
? (typeof t === 'function' ? t('unfold') : 'Unfold')
|
|
575
|
+
: (typeof t === 'function' ? t('fold') : 'Fold'),
|
|
576
|
+
),
|
|
577
|
+
)
|
|
578
|
+
}
|
|
579
|
+
const latest = value?.latestTurn
|
|
580
|
+
const enabled = value?.withdrawable?.[turn] === true || (value?.canWithdraw === true && latest === turn)
|
|
581
|
+
const reason = value?.reason
|
|
582
|
+
const unavailable = enabled
|
|
583
|
+
? null
|
|
584
|
+
: latest === turn && reason === 'no-snapshot'
|
|
585
|
+
? (typeof t === 'function' ? t('reasonNoSnapshot') : 'No workspace snapshot for this turn')
|
|
586
|
+
: latest === turn && reason === 'active'
|
|
587
|
+
? (typeof t === 'function' ? t('reasonActive') : 'The turn is still running')
|
|
588
|
+
: latest === turn && reason === 'incomplete'
|
|
589
|
+
? (typeof t === 'function' ? t('reasonIncomplete') : 'This turn has not finished yet.')
|
|
590
|
+
: undefined
|
|
591
|
+
if (unavailable === undefined && !enabled) return null
|
|
592
|
+
const rewind = enabled && typeof latest === 'number' && turn < latest
|
|
593
|
+
const label = rewind
|
|
594
|
+
? (typeof t === 'function' ? t('rewindAction') : 'Withdraw from here')
|
|
595
|
+
: (typeof t === 'function' ? t('action') : 'Withdraw this turn')
|
|
596
|
+
const onClick = async () => {
|
|
597
|
+
if (busy) return
|
|
598
|
+
const question = typeof t === 'function'
|
|
599
|
+
? (rewind ? t('rewindConfirm', { turn: String(turn), latest: String(latest) }) : t('confirm', { turn: String(turn) }))
|
|
600
|
+
: (rewind ? `Withdraw turns ${turn}–${latest}?` : `Withdraw turn ${turn}?`)
|
|
601
|
+
if (typeof window.confirm === 'function' && !window.confirm(question)) return
|
|
602
|
+
setBusy(true)
|
|
603
|
+
const result = await call('withdraw', { sessionId, turn })
|
|
604
|
+
setBusy(false)
|
|
605
|
+
if (result.ok !== true) {
|
|
606
|
+
const message = result.error?.message ?? 'unknown error'
|
|
607
|
+
if (typeof window.alert === 'function') {
|
|
608
|
+
window.alert(typeof t === 'function' ? t('failed', { message }) : `Withdraw failed: ${message}`)
|
|
609
|
+
}
|
|
610
|
+
return
|
|
611
|
+
}
|
|
612
|
+
const previous = records.get(sessionId)
|
|
613
|
+
const previousValue = previous?.status === 'ready' ? previous.value : {}
|
|
614
|
+
const withdrawnTurns = { ...(previousValue.turns ?? {}) }
|
|
615
|
+
const affected = Array.isArray(result.value?.withdrawn) ? result.value.withdrawn : [turn]
|
|
616
|
+
for (const affectedTurn of affected) {
|
|
617
|
+
withdrawnTurns[affectedTurn] = {
|
|
618
|
+
at: Date.now(),
|
|
619
|
+
files: affectedTurn === turn ? (result.value?.files ?? 0) : 0,
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
setRecord(sessionId, {
|
|
623
|
+
status: 'ready',
|
|
624
|
+
value: {
|
|
625
|
+
...previousValue,
|
|
626
|
+
canWithdraw: false,
|
|
627
|
+
withdrawable: {},
|
|
628
|
+
turns: withdrawnTurns,
|
|
629
|
+
},
|
|
630
|
+
})
|
|
631
|
+
if (
|
|
632
|
+
Array.isArray(result.value?.skipped)
|
|
633
|
+
&& result.value.skipped.length > 0
|
|
634
|
+
&& typeof window.alert === 'function'
|
|
635
|
+
) {
|
|
636
|
+
window.alert(typeof t === 'function'
|
|
637
|
+
? t('skipped', { paths: result.value.skipped.join(', ') })
|
|
638
|
+
: `Left untouched: ${result.value.skipped.join(', ')}`)
|
|
639
|
+
}
|
|
640
|
+
void refresh(sessionId, true)
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
return React.createElement(
|
|
644
|
+
'button',
|
|
645
|
+
{
|
|
646
|
+
type: 'button',
|
|
647
|
+
'data-withdraw-button': '',
|
|
648
|
+
'aria-label': unavailable ?? label,
|
|
649
|
+
title: unavailable ?? label,
|
|
650
|
+
disabled: busy || unavailable !== null,
|
|
651
|
+
onClick,
|
|
652
|
+
},
|
|
653
|
+
React.createElement(UndoIcon, null),
|
|
654
|
+
)
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function WithdrawMarker(props) {
|
|
658
|
+
const { turn, sessionId, t } = props
|
|
659
|
+
const record = useRecord(sessionId)
|
|
660
|
+
const withdrawn = record?.status === 'ready' ? record.value?.turns?.[turn] : undefined
|
|
661
|
+
const ref = React.useRef(null)
|
|
662
|
+
const label = typeof t === 'function' ? t('badge') : 'Withdrawn'
|
|
663
|
+
const [folded, setFolded] = React.useState(() => readFold(sessionId, turn))
|
|
664
|
+
|
|
665
|
+
React.useEffect(() => {
|
|
666
|
+
setFolded(readFold(sessionId, turn))
|
|
667
|
+
}, [sessionId, turn])
|
|
668
|
+
|
|
669
|
+
React.useEffect(() => {
|
|
670
|
+
if (withdrawn === undefined) return
|
|
671
|
+
applyFold(turn, folded)
|
|
672
|
+
}, [withdrawn, turn, folded])
|
|
673
|
+
|
|
674
|
+
const toggleFold = () => {
|
|
675
|
+
const next = !folded
|
|
676
|
+
setFolded(next)
|
|
677
|
+
writeFold(sessionId, turn, next)
|
|
678
|
+
applyFold(turn, next)
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
React.useEffect(() => {
|
|
682
|
+
if (withdrawn === undefined) return undefined
|
|
683
|
+
let timer
|
|
684
|
+
let interval
|
|
685
|
+
const paint = () => markTurn(turn, label)
|
|
686
|
+
paint()
|
|
687
|
+
timer = window.setTimeout(paint, 150)
|
|
688
|
+
// Chat rows are virtualized/re-rendered; keep the attribute applied.
|
|
689
|
+
interval = window.setInterval(paint, 500)
|
|
690
|
+
return () => {
|
|
691
|
+
window.clearTimeout(timer)
|
|
692
|
+
window.clearInterval(interval)
|
|
693
|
+
clearTurn(turn)
|
|
694
|
+
}
|
|
695
|
+
}, [withdrawn, turn, label])
|
|
696
|
+
|
|
697
|
+
if (withdrawn === undefined) return null
|
|
698
|
+
const files = typeof withdrawn.files === 'number' && withdrawn.files > 0 ? withdrawn.files : 0
|
|
699
|
+
const description = files > 0
|
|
700
|
+
? (typeof t === 'function' ? t('withdrawnFiles', { count: String(files) }) : `${files} file(s) restored · the workspace is back to before this turn.`)
|
|
701
|
+
: (typeof t === 'function' ? t('withdrawnDesc') : 'The workspace is back to before this turn.')
|
|
702
|
+
return React.createElement(
|
|
703
|
+
'div',
|
|
704
|
+
{ ref, className: 'wr-withdrawn', role: 'status' },
|
|
705
|
+
React.createElement(
|
|
706
|
+
'span',
|
|
707
|
+
{ className: 'wr-withdrawn-icon', 'aria-hidden': true },
|
|
708
|
+
React.createElement(UndoIcon, null),
|
|
709
|
+
),
|
|
710
|
+
React.createElement(
|
|
711
|
+
'div',
|
|
712
|
+
{ className: 'wr-withdrawn-main' },
|
|
713
|
+
React.createElement('div', { className: 'wr-withdrawn-title' }, typeof t === 'function' ? t('withdrawnTitle') : 'This round was withdrawn'),
|
|
714
|
+
React.createElement('div', { className: 'wr-withdrawn-desc' }, description),
|
|
715
|
+
),
|
|
716
|
+
React.createElement('span', { className: 'wr-withdrawn-chip' }, label),
|
|
717
|
+
React.createElement(
|
|
718
|
+
'button',
|
|
719
|
+
{
|
|
720
|
+
type: 'button',
|
|
721
|
+
className: 'wr-withdrawn-fold',
|
|
722
|
+
'aria-expanded': !folded,
|
|
723
|
+
onClick: toggleFold,
|
|
724
|
+
},
|
|
725
|
+
folded
|
|
726
|
+
? (typeof t === 'function' ? t('unfold') : 'Unfold')
|
|
727
|
+
: (typeof t === 'function' ? t('fold') : 'Fold'),
|
|
728
|
+
),
|
|
729
|
+
)
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// ---------------------------------------------------- review feed ---
|
|
733
|
+
const feed = {
|
|
734
|
+
version: -1,
|
|
735
|
+
reviews: [],
|
|
736
|
+
loaded: false,
|
|
737
|
+
error: null,
|
|
738
|
+
listeners: new Set(),
|
|
739
|
+
timer: null,
|
|
740
|
+
running: false,
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
const feedNotify = () => {
|
|
744
|
+
for (const listener of [...feed.listeners]) listener()
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const feedLoad = async (force) => {
|
|
748
|
+
const since = force ? -1 : feed.version
|
|
749
|
+
const result = await call('reviews', { since })
|
|
750
|
+
if (result.ok !== true) {
|
|
751
|
+
feed.error = result.error?.message ?? 'review load failed'
|
|
752
|
+
if (!feed.loaded) {
|
|
753
|
+
feed.loaded = true
|
|
754
|
+
feedNotify()
|
|
755
|
+
}
|
|
756
|
+
return
|
|
757
|
+
}
|
|
758
|
+
if (result.value.unchanged === true) {
|
|
759
|
+
if (!feed.loaded) {
|
|
760
|
+
feed.loaded = true
|
|
761
|
+
feedNotify()
|
|
762
|
+
}
|
|
763
|
+
return
|
|
764
|
+
}
|
|
765
|
+
feed.version = result.value.version
|
|
766
|
+
feed.reviews = result.value.reviews ?? []
|
|
767
|
+
feed.error = null
|
|
768
|
+
feed.loaded = true
|
|
769
|
+
feedNotify()
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
const feedLoop = async () => {
|
|
773
|
+
if (!feed.running) return
|
|
774
|
+
try {
|
|
775
|
+
await feedLoad(false)
|
|
776
|
+
} catch {}
|
|
777
|
+
if (!feed.running) return
|
|
778
|
+
feed.timer = window.setTimeout(feedLoop, 1000)
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
const feedSubscribe = (listener) => {
|
|
782
|
+
feed.listeners.add(listener)
|
|
783
|
+
if (!feed.running) {
|
|
784
|
+
feed.running = true
|
|
785
|
+
feed.timer = window.setTimeout(feedLoop, 0)
|
|
786
|
+
}
|
|
787
|
+
return () => {
|
|
788
|
+
feed.listeners.delete(listener)
|
|
789
|
+
if (feed.listeners.size === 0) {
|
|
790
|
+
feed.running = false
|
|
791
|
+
window.clearTimeout(feed.timer)
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
const feedRefresh = () => {
|
|
797
|
+
void feedLoad(true)
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
const useReviews = () => {
|
|
801
|
+
const [, bump] = React.useState(0)
|
|
802
|
+
React.useEffect(() => {
|
|
803
|
+
const unsubscribe = feedSubscribe(() => bump((value) => value + 1))
|
|
804
|
+
return unsubscribe
|
|
805
|
+
}, [])
|
|
806
|
+
return feed
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const useOpenTabs = () => {
|
|
810
|
+
const service = ctx.get('sidebarRight')
|
|
811
|
+
const subscribeTabs = React.useCallback((callback) => {
|
|
812
|
+
if (service?.openTabs?.subscribe === undefined) return () => {}
|
|
813
|
+
return service.openTabs.subscribe(callback)
|
|
814
|
+
}, [service])
|
|
815
|
+
const getTabs = React.useCallback(() => {
|
|
816
|
+
try {
|
|
817
|
+
return service?.openTabs?.getSnapshot?.() ?? EMPTY_TABS
|
|
818
|
+
} catch {
|
|
819
|
+
return EMPTY_TABS
|
|
820
|
+
}
|
|
821
|
+
}, [service])
|
|
822
|
+
return React.useSyncExternalStore(subscribeTabs, getTabs)
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
const pendingReview = (reviews) =>
|
|
826
|
+
reviews.find((review) => review.finished !== true && review.applying !== true && review.entries.length > 0)
|
|
827
|
+
|
|
828
|
+
const openReviewTab = (reviewId) => {
|
|
829
|
+
try {
|
|
830
|
+
ctx.sidebarRight.openTab(REVIEW_KIND, { params: { reviewId } })
|
|
831
|
+
} catch (error) {
|
|
832
|
+
console.error('coding-enhanced: cannot open the review tab', error)
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
// ------------------------------------------------------ watcher ---
|
|
837
|
+
function ReviewWatcher(props) {
|
|
838
|
+
const { sessionId, t } = props
|
|
839
|
+
const state = useReviews()
|
|
840
|
+
const tabs = useOpenTabs()
|
|
841
|
+
const review = pendingReview(state.reviews)
|
|
842
|
+
const opened = React.useRef(null)
|
|
843
|
+
const tabOpen = tabs.some((tab) => tab.kind === REVIEW_KIND && tab.sessionId === sessionId)
|
|
844
|
+
|
|
845
|
+
React.useEffect(() => {
|
|
846
|
+
if (!state.loaded || review === undefined) return
|
|
847
|
+
if (opened.current === review.id) return
|
|
848
|
+
opened.current = review.id
|
|
849
|
+
openReviewTab(review.id)
|
|
850
|
+
}, [state.loaded, review?.id])
|
|
851
|
+
|
|
852
|
+
React.useEffect(() => {
|
|
853
|
+
if (review === undefined) opened.current = null
|
|
854
|
+
}, [review?.id])
|
|
855
|
+
|
|
856
|
+
if (!state.loaded || review === undefined || tabOpen) return null
|
|
857
|
+
return ReactDOM.createPortal(
|
|
858
|
+
React.createElement(
|
|
859
|
+
'button',
|
|
860
|
+
{
|
|
861
|
+
type: 'button',
|
|
862
|
+
className: 'wr-pill',
|
|
863
|
+
onClick: () => {
|
|
864
|
+
opened.current = review.id
|
|
865
|
+
openReviewTab(review.id)
|
|
866
|
+
},
|
|
867
|
+
},
|
|
868
|
+
typeof t === 'function'
|
|
869
|
+
? t('pendingPill', { count: String(review.entries.length) })
|
|
870
|
+
: `${review.entries.length} files to review`,
|
|
871
|
+
),
|
|
872
|
+
document.body,
|
|
873
|
+
)
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// ------------------------------------------------------ review tab ---
|
|
877
|
+
function ReviewTab(props) {
|
|
878
|
+
const { sessionId, useTabInfo, t } = props
|
|
879
|
+
const { tab } = useTabInfo()
|
|
880
|
+
const state = useReviews()
|
|
881
|
+
const review = pendingReview(state.reviews)
|
|
882
|
+
const [local, setLocal] = React.useState({})
|
|
883
|
+
const [submitting, setSubmitting] = React.useState(false)
|
|
884
|
+
const [error, setError] = React.useState(null)
|
|
885
|
+
const finishedRef = React.useRef(false)
|
|
886
|
+
const currentReviewRef = React.useRef(review)
|
|
887
|
+
currentReviewRef.current = review
|
|
888
|
+
const [diffHeight, setDiffHeight] = React.useState(() => {
|
|
889
|
+
try {
|
|
890
|
+
const raw = Number(window.localStorage.getItem('dsh-coding-enhanced:review-diff-height'))
|
|
891
|
+
return Number.isFinite(raw) && raw >= 120 ? raw : 0
|
|
892
|
+
} catch {
|
|
893
|
+
return 0
|
|
894
|
+
}
|
|
895
|
+
})
|
|
896
|
+
const signaturesRef = React.useRef(new Map())
|
|
897
|
+
|
|
898
|
+
React.useEffect(() => {
|
|
899
|
+
try {
|
|
900
|
+
if (diffHeight > 0) window.localStorage.setItem('dsh-coding-enhanced:review-diff-height', String(diffHeight))
|
|
901
|
+
else window.localStorage.removeItem('dsh-coding-enhanced:review-diff-height')
|
|
902
|
+
} catch {}
|
|
903
|
+
}, [diffHeight])
|
|
904
|
+
|
|
905
|
+
// Decisions made while the agent is still proposing must not survive a
|
|
906
|
+
// new edit to the same file; reset them when the entry content changes.
|
|
907
|
+
React.useEffect(() => {
|
|
908
|
+
if (review === undefined) return
|
|
909
|
+
const next = new Map()
|
|
910
|
+
const resetIds = []
|
|
911
|
+
for (const entry of review.entries) {
|
|
912
|
+
const signature = `${entry.updatedAt ?? 0}:${entry.afterText?.length ?? 0}`
|
|
913
|
+
const previous = signaturesRef.current.get(entry.id)
|
|
914
|
+
next.set(entry.id, signature)
|
|
915
|
+
if (previous !== undefined && previous !== signature) resetIds.push(entry.id)
|
|
916
|
+
}
|
|
917
|
+
signaturesRef.current = next
|
|
918
|
+
if (resetIds.length === 0) return
|
|
919
|
+
setLocal((previous) => {
|
|
920
|
+
let copy = null
|
|
921
|
+
for (const id of resetIds) {
|
|
922
|
+
if (previous[id] === undefined) continue
|
|
923
|
+
if (copy === null) copy = { ...previous }
|
|
924
|
+
delete copy[id]
|
|
925
|
+
}
|
|
926
|
+
return copy ?? previous
|
|
927
|
+
})
|
|
928
|
+
}, [review])
|
|
929
|
+
|
|
930
|
+
const startResize = (event) => {
|
|
931
|
+
event.preventDefault()
|
|
932
|
+
const diff = event.currentTarget.parentElement?.querySelector('.wr-diff')
|
|
933
|
+
const startY = event.clientY
|
|
934
|
+
const startHeight = diff?.getBoundingClientRect().height ?? (diffHeight > 0 ? diffHeight : 360)
|
|
935
|
+
const onMove = (move) => {
|
|
936
|
+
const next = Math.max(120, Math.min(900, Math.round(startHeight + (move.clientY - startY))))
|
|
937
|
+
setDiffHeight(next)
|
|
938
|
+
}
|
|
939
|
+
const stop = () => {
|
|
940
|
+
window.removeEventListener('pointermove', onMove)
|
|
941
|
+
window.removeEventListener('pointerup', stop)
|
|
942
|
+
window.removeEventListener('pointercancel', stop)
|
|
943
|
+
document.body.style.userSelect = ''
|
|
944
|
+
}
|
|
945
|
+
document.body.style.userSelect = 'none'
|
|
946
|
+
window.addEventListener('pointermove', onMove)
|
|
947
|
+
window.addEventListener('pointerup', stop)
|
|
948
|
+
window.addEventListener('pointercancel', stop)
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
React.useEffect(() => {
|
|
952
|
+
setLocal({})
|
|
953
|
+
setError(null)
|
|
954
|
+
finishedRef.current = false
|
|
955
|
+
}, [review?.id])
|
|
956
|
+
|
|
957
|
+
React.useEffect(() => {
|
|
958
|
+
const signal = tab?.signal
|
|
959
|
+
if (signal === undefined) return undefined
|
|
960
|
+
const onAbort = () => {
|
|
961
|
+
if (finishedRef.current) return
|
|
962
|
+
const current = currentReviewRef.current
|
|
963
|
+
if (current === undefined) return
|
|
964
|
+
void call('cancel', { reviewId: current.id })
|
|
965
|
+
}
|
|
966
|
+
signal.addEventListener('abort', onAbort, { once: true })
|
|
967
|
+
return () => signal.removeEventListener('abort', onAbort)
|
|
968
|
+
}, [tab])
|
|
969
|
+
|
|
970
|
+
React.useEffect(() => {
|
|
971
|
+
if (!state.loaded || review !== undefined) return undefined
|
|
972
|
+
const timer = window.setTimeout(() => {
|
|
973
|
+
try {
|
|
974
|
+
tab.actions.close()
|
|
975
|
+
} catch {}
|
|
976
|
+
}, 500)
|
|
977
|
+
return () => window.clearTimeout(timer)
|
|
978
|
+
}, [state.loaded, review?.id, tab])
|
|
979
|
+
|
|
980
|
+
if (!state.loaded) {
|
|
981
|
+
return React.createElement('div', { className: 'wr-empty' }, typeof t === 'function' ? t('loading') : 'Loading review…')
|
|
982
|
+
}
|
|
983
|
+
if (review === undefined) {
|
|
984
|
+
return React.createElement('div', { className: 'wr-empty' }, typeof t === 'function' ? t('reviewClosed') : 'No pending review.')
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
const submitted = review.submitted === true
|
|
988
|
+
const decisionOf = (entryId) => local[entryId] ?? {}
|
|
989
|
+
const patchEntry = (entryId, patch) => {
|
|
990
|
+
setLocal((previous) => ({
|
|
991
|
+
...previous,
|
|
992
|
+
[entryId]: { ...(previous[entryId] ?? {}), ...patch },
|
|
993
|
+
}))
|
|
994
|
+
}
|
|
995
|
+
const decide = (entryId, approved) => patchEntry(entryId, { approved })
|
|
996
|
+
const setAll = (approved) => {
|
|
997
|
+
const edited = review.entries.filter((entry) => isDirty(entry))
|
|
998
|
+
if (
|
|
999
|
+
approved === false
|
|
1000
|
+
&& edited.length > 0
|
|
1001
|
+
&& typeof window.confirm === 'function'
|
|
1002
|
+
&& !window.confirm(t('rejectAllKeepEdited'))
|
|
1003
|
+
) {
|
|
1004
|
+
return
|
|
1005
|
+
}
|
|
1006
|
+
setLocal((previous) => {
|
|
1007
|
+
const next = { ...previous }
|
|
1008
|
+
for (const entry of review.entries) {
|
|
1009
|
+
if (approved === false && isDirty(entry)) continue
|
|
1010
|
+
next[entry.id] = { ...(next[entry.id] ?? {}), approved }
|
|
1011
|
+
}
|
|
1012
|
+
return next
|
|
1013
|
+
})
|
|
1014
|
+
}
|
|
1015
|
+
const isDirty = (entry) => {
|
|
1016
|
+
const localEntry = decisionOf(entry.id)
|
|
1017
|
+
return entry.editable === true
|
|
1018
|
+
&& typeof localEntry.editedAfter === 'string'
|
|
1019
|
+
&& entry.afterText !== null
|
|
1020
|
+
&& localEntry.editedAfter !== entry.afterText
|
|
1021
|
+
}
|
|
1022
|
+
const rejectEntry = (entry) => decide(entry.id, false)
|
|
1023
|
+
const undecided = review.entries.filter((entry) => !isDirty(entry) && typeof decisionOf(entry.id).approved !== 'boolean').length
|
|
1024
|
+
|
|
1025
|
+
const finish = async () => {
|
|
1026
|
+
if (undecided > 0 || submitting || !submitted) return
|
|
1027
|
+
setSubmitting(true)
|
|
1028
|
+
setError(null)
|
|
1029
|
+
const decisions = review.entries.map((entry) => {
|
|
1030
|
+
const localEntry = decisionOf(entry.id)
|
|
1031
|
+
const edited = localEntry.editedAfter
|
|
1032
|
+
const included = entry.editable === true
|
|
1033
|
+
&& typeof edited === 'string'
|
|
1034
|
+
&& edited !== entry.afterText
|
|
1035
|
+
return included
|
|
1036
|
+
? { entryId: entry.id, outcome: 'edited', editedAfter: edited }
|
|
1037
|
+
: {
|
|
1038
|
+
entryId: entry.id,
|
|
1039
|
+
approved: localEntry.approved === true,
|
|
1040
|
+
comment: localEntry.comment ?? '',
|
|
1041
|
+
}
|
|
1042
|
+
})
|
|
1043
|
+
const result = await call('decide', { reviewId: review.id, decisions })
|
|
1044
|
+
setSubmitting(false)
|
|
1045
|
+
if (result.ok !== true) {
|
|
1046
|
+
const message = result.error?.message ?? 'unknown error'
|
|
1047
|
+
setError(typeof t === 'function' ? t('reviewFailed', { message }) : `Review failed: ${message}`)
|
|
1048
|
+
feedRefresh()
|
|
1049
|
+
return
|
|
1050
|
+
}
|
|
1051
|
+
finishedRef.current = true
|
|
1052
|
+
feedRefresh()
|
|
1053
|
+
try {
|
|
1054
|
+
tab.actions.close()
|
|
1055
|
+
} catch {}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
const renderFile = (entry) => {
|
|
1059
|
+
const locked = false
|
|
1060
|
+
const localEntry = decisionOf(entry.id)
|
|
1061
|
+
const dirty = isDirty(entry)
|
|
1062
|
+
const status = dirty ? 'edited' : localEntry.approved === true ? 'approved' : localEntry.approved === false ? 'rejected' : 'pending'
|
|
1063
|
+
const statusLabel = dirty
|
|
1064
|
+
? (typeof t === 'function' ? t('edited') : 'Edited')
|
|
1065
|
+
: status === 'approved'
|
|
1066
|
+
? (typeof t === 'function' ? t('approved') : 'Approved')
|
|
1067
|
+
: status === 'rejected'
|
|
1068
|
+
? (typeof t === 'function' ? t('rejected') : 'Rejected')
|
|
1069
|
+
: (typeof t === 'function' ? t('pending') : 'Pending')
|
|
1070
|
+
const editing = localEntry.editing === true
|
|
1071
|
+
const editedText = localEntry.editedAfter ?? entry.afterText ?? ''
|
|
1072
|
+
|
|
1073
|
+
const diff = entry.hunks.length === 0
|
|
1074
|
+
? React.createElement('div', { className: 'wr-note' }, typeof t === 'function' ? t('noDiff') : 'No diff')
|
|
1075
|
+
: entry.hunks.map((hunk, hunkIndex) =>
|
|
1076
|
+
React.createElement(
|
|
1077
|
+
'div',
|
|
1078
|
+
{ key: `h${hunkIndex}` },
|
|
1079
|
+
React.createElement('div', { className: 'wr-hunk' }, hunk.header),
|
|
1080
|
+
hunk.lines.map((line, lineIndex) =>
|
|
1081
|
+
React.createElement(
|
|
1082
|
+
'div',
|
|
1083
|
+
{ key: lineIndex, className: `wr-line ${line.type}` },
|
|
1084
|
+
React.createElement('span', { className: 'wr-no' }, line.oldNo === null ? '' : line.oldNo),
|
|
1085
|
+
React.createElement('span', { className: 'wr-no' }, line.newNo === null ? '' : line.newNo),
|
|
1086
|
+
React.createElement('span', { className: 'wr-sign' }, line.type === 'add' ? '+' : line.type === 'del' ? '-' : ' '),
|
|
1087
|
+
React.createElement('span', { className: 'wr-text' }, line.text === '' ? ' ' : line.text),
|
|
1088
|
+
),
|
|
1089
|
+
),
|
|
1090
|
+
),
|
|
1091
|
+
)
|
|
1092
|
+
|
|
1093
|
+
return React.createElement(
|
|
1094
|
+
'div',
|
|
1095
|
+
{ key: entry.id, className: `wr-file ${status}` },
|
|
1096
|
+
React.createElement(
|
|
1097
|
+
'div',
|
|
1098
|
+
{ className: 'wr-file-head' },
|
|
1099
|
+
React.createElement('span', { className: 'wr-path', title: entry.path }, entry.display),
|
|
1100
|
+
entry.isNew === true ? React.createElement('span', { className: 'wr-chip' }, typeof t === 'function' ? t('newFile') : 'new') : null,
|
|
1101
|
+
React.createElement('span', { className: 'wr-add' }, `+${entry.added}`),
|
|
1102
|
+
React.createElement('span', { className: 'wr-del' }, `-${entry.removed}`),
|
|
1103
|
+
React.createElement('span', { className: `wr-chip ${status === 'approved' ? 'ok' : status === 'rejected' ? 'no' : status === 'edited' ? 'edited' : ''}` }, statusLabel),
|
|
1104
|
+
dirty
|
|
1105
|
+
? React.createElement(
|
|
1106
|
+
'button',
|
|
1107
|
+
{ type: 'button', className: 'wr-btn sm', disabled: locked, onClick: () => patchEntry(entry.id, { editedAfter: entry.afterText, approved: undefined }) },
|
|
1108
|
+
typeof t === 'function' ? t('reset') : 'Reset',
|
|
1109
|
+
)
|
|
1110
|
+
: React.createElement(
|
|
1111
|
+
'button',
|
|
1112
|
+
{ type: 'button', className: `wr-btn sm ok${status === 'approved' ? ' active' : ''}`, disabled: locked, onClick: () => decide(entry.id, true) },
|
|
1113
|
+
typeof t === 'function' ? t('approve') : 'Approve',
|
|
1114
|
+
),
|
|
1115
|
+
dirty
|
|
1116
|
+
? null
|
|
1117
|
+
: React.createElement(
|
|
1118
|
+
'button',
|
|
1119
|
+
{ type: 'button', className: `wr-btn sm no${status === 'rejected' ? ' active' : ''}`, disabled: locked, onClick: () => rejectEntry(entry) },
|
|
1120
|
+
typeof t === 'function' ? t('reject') : 'Reject',
|
|
1121
|
+
),
|
|
1122
|
+
entry.editable === true
|
|
1123
|
+
? React.createElement(
|
|
1124
|
+
'button',
|
|
1125
|
+
{
|
|
1126
|
+
type: 'button',
|
|
1127
|
+
className: 'wr-btn sm',
|
|
1128
|
+
disabled: locked,
|
|
1129
|
+
onClick: () => patchEntry(entry.id, {
|
|
1130
|
+
editing: !editing,
|
|
1131
|
+
...(!editing && typeof localEntry.editedAfter !== 'string' ? { editedAfter: entry.afterText } : {}),
|
|
1132
|
+
}),
|
|
1133
|
+
},
|
|
1134
|
+
editing
|
|
1135
|
+
? (typeof t === 'function' ? t('editDone') : 'Done')
|
|
1136
|
+
: (typeof t === 'function' ? t('edit') : 'Edit'),
|
|
1137
|
+
)
|
|
1138
|
+
: null,
|
|
1139
|
+
),
|
|
1140
|
+
entry.warning !== null && entry.warning !== undefined
|
|
1141
|
+
? React.createElement('div', { className: 'wr-note warn' }, entry.warning)
|
|
1142
|
+
: null,
|
|
1143
|
+
entry.truncated === true
|
|
1144
|
+
? React.createElement('div', { className: 'wr-note' }, typeof t === 'function' ? t('truncated') : 'Large diff')
|
|
1145
|
+
: null,
|
|
1146
|
+
React.createElement('div', { className: 'wr-diff' }, diff),
|
|
1147
|
+
React.createElement('div', {
|
|
1148
|
+
className: 'wr-diff-resize',
|
|
1149
|
+
title: typeof t === 'function' ? t('resizeDiff') : 'Drag to resize',
|
|
1150
|
+
onPointerDown: startResize,
|
|
1151
|
+
onDoubleClick: () => setDiffHeight(0),
|
|
1152
|
+
}),
|
|
1153
|
+
editing
|
|
1154
|
+
? React.createElement(
|
|
1155
|
+
'div',
|
|
1156
|
+
null,
|
|
1157
|
+
React.createElement('div', { className: 'wr-note' }, typeof t === 'function' ? t('editHint') : 'Finish writes your edited content.'),
|
|
1158
|
+
React.createElement('textarea', {
|
|
1159
|
+
className: 'wr-editor',
|
|
1160
|
+
value: editedText,
|
|
1161
|
+
spellCheck: false,
|
|
1162
|
+
disabled: locked,
|
|
1163
|
+
onChange: (event) => patchEntry(entry.id, { editedAfter: event.target.value, approved: true }),
|
|
1164
|
+
}),
|
|
1165
|
+
React.createElement(
|
|
1166
|
+
'div',
|
|
1167
|
+
{ style: { padding: '0 10px 8px' } },
|
|
1168
|
+
React.createElement(
|
|
1169
|
+
'button',
|
|
1170
|
+
{ type: 'button', className: 'wr-btn sm', disabled: locked, onClick: () => patchEntry(entry.id, { editedAfter: entry.afterText }) },
|
|
1171
|
+
typeof t === 'function' ? t('reset') : 'Reset',
|
|
1172
|
+
),
|
|
1173
|
+
),
|
|
1174
|
+
)
|
|
1175
|
+
: null,
|
|
1176
|
+
dirty
|
|
1177
|
+
? React.createElement('div', { className: 'wr-note' }, typeof t === 'function' ? t('editedHint') : 'Edited files are applied automatically.')
|
|
1178
|
+
: React.createElement('textarea', {
|
|
1179
|
+
className: 'wr-comment',
|
|
1180
|
+
value: localEntry.comment ?? '',
|
|
1181
|
+
placeholder: typeof t === 'function' ? t('comment') : 'Instructions for the AI',
|
|
1182
|
+
disabled: locked,
|
|
1183
|
+
onChange: (event) => patchEntry(entry.id, { comment: event.target.value }),
|
|
1184
|
+
rows: 2,
|
|
1185
|
+
}),
|
|
1186
|
+
)
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
const paneStyle = diffHeight > 0 ? { '--wr-diff-height': `${diffHeight}px` } : undefined
|
|
1190
|
+
|
|
1191
|
+
return React.createElement(
|
|
1192
|
+
'div',
|
|
1193
|
+
{ className: 'wr-pane', style: paneStyle },
|
|
1194
|
+
React.createElement(
|
|
1195
|
+
'div',
|
|
1196
|
+
{ className: 'wr-pane-head' },
|
|
1197
|
+
React.createElement('span', { className: 'wr-pane-title' }, typeof t === 'function' ? t('reviewTitle') : 'Code review'),
|
|
1198
|
+
React.createElement(
|
|
1199
|
+
'span',
|
|
1200
|
+
{ className: 'wr-pane-sub' },
|
|
1201
|
+
typeof t === 'function'
|
|
1202
|
+
? t('reviewSubtitle', { count: String(review.entries.length) })
|
|
1203
|
+
: `${review.entries.length} files`,
|
|
1204
|
+
),
|
|
1205
|
+
),
|
|
1206
|
+
!submitted
|
|
1207
|
+
? React.createElement('div', { className: 'wr-collecting' }, typeof t === 'function' ? t('collecting') : 'Waiting for the agent to submit.')
|
|
1208
|
+
: null,
|
|
1209
|
+
React.createElement(
|
|
1210
|
+
'div',
|
|
1211
|
+
{ className: 'wr-scroll' },
|
|
1212
|
+
review.entries.map(renderFile),
|
|
1213
|
+
React.createElement(
|
|
1214
|
+
'div',
|
|
1215
|
+
{ className: 'wr-toolbar' },
|
|
1216
|
+
React.createElement('button', { type: 'button', className: 'wr-btn', onClick: () => setAll(true) }, typeof t === 'function' ? t('approveAll') : 'Approve all'),
|
|
1217
|
+
React.createElement('button', { type: 'button', className: 'wr-btn', onClick: () => setAll(false) }, typeof t === 'function' ? t('rejectAll') : 'Reject all'),
|
|
1218
|
+
undecided > 0
|
|
1219
|
+
? React.createElement('span', { className: 'wr-toolbar-info' }, typeof t === 'function' ? t('finishPending', { count: String(undecided) }) : `${undecided} pending`)
|
|
1220
|
+
: null,
|
|
1221
|
+
error !== null ? React.createElement('span', { className: 'wr-error' }, error) : null,
|
|
1222
|
+
React.createElement(
|
|
1223
|
+
'button',
|
|
1224
|
+
{
|
|
1225
|
+
type: 'button',
|
|
1226
|
+
className: 'wr-btn primary',
|
|
1227
|
+
disabled: undecided > 0 || submitting || !submitted,
|
|
1228
|
+
onClick: finish,
|
|
1229
|
+
},
|
|
1230
|
+
!submitted
|
|
1231
|
+
? (typeof t === 'function' ? t('waitingSubmit') : 'Waiting for the agent…')
|
|
1232
|
+
: submitting
|
|
1233
|
+
? (typeof t === 'function' ? t('submitting') : 'Applying…')
|
|
1234
|
+
: (typeof t === 'function' ? t('finish') : 'Finish'),
|
|
1235
|
+
),
|
|
1236
|
+
),
|
|
1237
|
+
),
|
|
1238
|
+
)
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
const ReviewIcon = () =>
|
|
1243
|
+
React.createElement(
|
|
1244
|
+
'svg',
|
|
1245
|
+
{ width: 15, height: 15, viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true },
|
|
1246
|
+
React.createElement('path', { d: 'M8 1.8 13 3.5v4.1c0 3-2.1 5.3-5 6.6-2.9-1.3-5-3.6-5-6.6V3.5L8 1.8Z' }),
|
|
1247
|
+
React.createElement('path', { d: 'm5.8 7.9 1.5 1.5 3-3.2' }),
|
|
1248
|
+
)
|
|
1249
|
+
|
|
1250
|
+
function ReviewToggle({ t }) {
|
|
1251
|
+
const [flags, setFlags] = React.useState(null)
|
|
1252
|
+
const [open, setOpen] = React.useState(false)
|
|
1253
|
+
const [busy, setBusy] = React.useState(false)
|
|
1254
|
+
const [rect, setRect] = React.useState(null)
|
|
1255
|
+
const triggerRef = React.useRef(null)
|
|
1256
|
+
|
|
1257
|
+
const load = React.useCallback(() => {
|
|
1258
|
+
void call('settings').then((result) => {
|
|
1259
|
+
if (result.ok === true) setFlags(result.value)
|
|
1260
|
+
})
|
|
1261
|
+
}, [])
|
|
1262
|
+
|
|
1263
|
+
React.useEffect(() => {
|
|
1264
|
+
load()
|
|
1265
|
+
}, [load])
|
|
1266
|
+
|
|
1267
|
+
React.useEffect(() => {
|
|
1268
|
+
if (!open) return undefined
|
|
1269
|
+
const onPointer = (event) => {
|
|
1270
|
+
if (triggerRef.current?.contains(event.target)) return
|
|
1271
|
+
if (event.target?.closest?.('.ce-review-popover') !== null && event.target?.closest?.('.ce-review-popover') !== undefined) return
|
|
1272
|
+
setOpen(false)
|
|
1273
|
+
}
|
|
1274
|
+
const onKey = (event) => {
|
|
1275
|
+
if (event.key === 'Escape') setOpen(false)
|
|
1276
|
+
}
|
|
1277
|
+
document.addEventListener('pointerdown', onPointer)
|
|
1278
|
+
document.addEventListener('keydown', onKey)
|
|
1279
|
+
return () => {
|
|
1280
|
+
document.removeEventListener('pointerdown', onPointer)
|
|
1281
|
+
document.removeEventListener('keydown', onKey)
|
|
1282
|
+
}
|
|
1283
|
+
}, [open])
|
|
1284
|
+
|
|
1285
|
+
const enabled = flags?.review === true
|
|
1286
|
+
const auto = flags?.autoReview === true
|
|
1287
|
+
|
|
1288
|
+
const toggleOpen = () => {
|
|
1289
|
+
if (!open && triggerRef.current !== null) {
|
|
1290
|
+
const box = triggerRef.current.getBoundingClientRect()
|
|
1291
|
+
setRect(box)
|
|
1292
|
+
load()
|
|
1293
|
+
}
|
|
1294
|
+
setOpen((value) => !value)
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
const toggleAuto = async () => {
|
|
1298
|
+
if (busy || flags === null || !enabled) return
|
|
1299
|
+
setBusy(true)
|
|
1300
|
+
const result = await call('setSettings', { autoReview: !auto })
|
|
1301
|
+
setBusy(false)
|
|
1302
|
+
if (result.ok === true) setFlags(result.value)
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
const popover = open && rect !== null
|
|
1306
|
+
? ReactDOM.createPortal(
|
|
1307
|
+
React.createElement(
|
|
1308
|
+
'div',
|
|
1309
|
+
{
|
|
1310
|
+
className: 'ce-review-popover',
|
|
1311
|
+
style: {
|
|
1312
|
+
position: 'fixed',
|
|
1313
|
+
left: `${Math.max(8, Math.min(window.innerWidth - 300, rect.left))}px`,
|
|
1314
|
+
bottom: `${Math.max(8, window.innerHeight - rect.top + 8)}px`,
|
|
1315
|
+
width: '280px',
|
|
1316
|
+
},
|
|
1317
|
+
},
|
|
1318
|
+
React.createElement(
|
|
1319
|
+
'div',
|
|
1320
|
+
{ className: 'ce-review-head' },
|
|
1321
|
+
React.createElement('span', { className: 'ce-review-title' }, typeof t === 'function' ? t('reviewTools') : 'Review tools'),
|
|
1322
|
+
React.createElement(
|
|
1323
|
+
'span',
|
|
1324
|
+
{ className: `ce-review-state${enabled && auto ? ' on' : ''}` },
|
|
1325
|
+
enabled
|
|
1326
|
+
? (auto ? (typeof t === 'function' ? t('reviewOn') : 'On') : (typeof t === 'function' ? t('reviewOff') : 'Off'))
|
|
1327
|
+
: (typeof t === 'function' ? t('reviewOff') : 'Off'),
|
|
1328
|
+
),
|
|
1329
|
+
),
|
|
1330
|
+
enabled
|
|
1331
|
+
? React.createElement(
|
|
1332
|
+
'div',
|
|
1333
|
+
{ className: 'ce-review-row' },
|
|
1334
|
+
React.createElement(
|
|
1335
|
+
'div',
|
|
1336
|
+
{ className: 'ce-review-text' },
|
|
1337
|
+
React.createElement('div', { className: 'ce-review-row-title' }, typeof t === 'function' ? t('autoReview') : 'Auto review'),
|
|
1338
|
+
React.createElement('div', { className: 'ce-review-row-desc' }, typeof t === 'function' ? t('autoReviewDesc') : ''),
|
|
1339
|
+
),
|
|
1340
|
+
React.createElement(
|
|
1341
|
+
'button',
|
|
1342
|
+
{
|
|
1343
|
+
type: 'button',
|
|
1344
|
+
role: 'switch',
|
|
1345
|
+
'aria-checked': auto,
|
|
1346
|
+
'aria-label': typeof t === 'function' ? t('autoReview') : 'Auto review',
|
|
1347
|
+
className: `ce-switch${auto ? ' on' : ''}`,
|
|
1348
|
+
disabled: busy || flags === null,
|
|
1349
|
+
onClick: () => { void toggleAuto() },
|
|
1350
|
+
},
|
|
1351
|
+
React.createElement('span', { className: 'ce-switch-thumb' }),
|
|
1352
|
+
),
|
|
1353
|
+
)
|
|
1354
|
+
: React.createElement('div', { className: 'ce-review-off' }, typeof t === 'function' ? t('reviewFeatureOff') : ''),
|
|
1355
|
+
),
|
|
1356
|
+
document.body,
|
|
1357
|
+
)
|
|
1358
|
+
: null
|
|
1359
|
+
|
|
1360
|
+
return React.createElement(
|
|
1361
|
+
React.Fragment,
|
|
1362
|
+
null,
|
|
1363
|
+
React.createElement(
|
|
1364
|
+
'button',
|
|
1365
|
+
{
|
|
1366
|
+
ref: triggerRef,
|
|
1367
|
+
type: 'button',
|
|
1368
|
+
className: `ce-review-trigger${enabled && auto ? ' on' : ''}${enabled ? '' : ' disabled'}`,
|
|
1369
|
+
title: typeof t === 'function' ? t('reviewTools') : 'Review tools',
|
|
1370
|
+
'aria-label': typeof t === 'function' ? t('reviewTools') : 'Review tools',
|
|
1371
|
+
'aria-expanded': open,
|
|
1372
|
+
onClick: toggleOpen,
|
|
1373
|
+
},
|
|
1374
|
+
React.createElement(ReviewIcon, null),
|
|
1375
|
+
React.createElement('span', { className: `ce-review-dot${enabled && auto ? ' on' : ''}` }),
|
|
1376
|
+
),
|
|
1377
|
+
popover,
|
|
1378
|
+
)
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// ------------------------------------------------- settings section ---
|
|
1382
|
+
function SettingsSection({ t, compact }) {
|
|
1383
|
+
const [flags, setFlags] = React.useState(null)
|
|
1384
|
+
const [busy, setBusy] = React.useState(null)
|
|
1385
|
+
const [error, setError] = React.useState(null)
|
|
1386
|
+
const [turnsDraft, setTurnsDraft] = React.useState(null)
|
|
1387
|
+
const [cleanupBusy, setCleanupBusy] = React.useState(false)
|
|
1388
|
+
const [cleanupText, setCleanupText] = React.useState(null)
|
|
1389
|
+
|
|
1390
|
+
React.useEffect(() => {
|
|
1391
|
+
let alive = true
|
|
1392
|
+
void call('settings').then((result) => {
|
|
1393
|
+
if (!alive) return
|
|
1394
|
+
if (result.ok === true) setFlags(result.value)
|
|
1395
|
+
else setError(typeof t === 'function' ? t('settingsFailed', { message: result.error?.message ?? '' }) : String(result.error?.message ?? ''))
|
|
1396
|
+
})
|
|
1397
|
+
return () => {
|
|
1398
|
+
alive = false
|
|
1399
|
+
}
|
|
1400
|
+
}, [])
|
|
1401
|
+
|
|
1402
|
+
React.useEffect(() => {
|
|
1403
|
+
if (flags === null) return
|
|
1404
|
+
setTurnsDraft((current) => current ?? String(flags.keepTurns ?? 10))
|
|
1405
|
+
}, [flags])
|
|
1406
|
+
|
|
1407
|
+
const commitTurns = async () => {
|
|
1408
|
+
if (busy !== null || flags === null || turnsDraft === null) return
|
|
1409
|
+
const value = Number(turnsDraft)
|
|
1410
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > 50) {
|
|
1411
|
+
setError(typeof t === 'function' ? t('settingsKeepTurnsInvalid') : 'Enter a whole number from 1 to 50.')
|
|
1412
|
+
setTurnsDraft(String(flags.keepTurns ?? 10))
|
|
1413
|
+
return
|
|
1414
|
+
}
|
|
1415
|
+
if (value === flags.keepTurns) return
|
|
1416
|
+
setBusy('keepTurns')
|
|
1417
|
+
setError(null)
|
|
1418
|
+
const result = await call('setSettings', { keepTurns: value })
|
|
1419
|
+
setBusy(null)
|
|
1420
|
+
if (result.ok === true) {
|
|
1421
|
+
setFlags(result.value)
|
|
1422
|
+
setTurnsDraft(String(result.value.keepTurns))
|
|
1423
|
+
} else {
|
|
1424
|
+
setError(typeof t === 'function' ? t('settingsFailed', { message: result.error?.message ?? '' }) : String(result.error?.message ?? ''))
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
const runCleanup = async () => {
|
|
1429
|
+
if (cleanupBusy || flags === null) return
|
|
1430
|
+
setCleanupBusy(true)
|
|
1431
|
+
setCleanupText(null)
|
|
1432
|
+
const result = await call('cleanup')
|
|
1433
|
+
setCleanupBusy(false)
|
|
1434
|
+
if (result.ok === true) {
|
|
1435
|
+
setCleanupText(typeof t === 'function'
|
|
1436
|
+
? t('cleanupDone', { pruned: String(result.value?.pruned ?? 0), repos: String(result.value?.repos ?? 0) })
|
|
1437
|
+
: `Pruned ${result.value?.pruned ?? 0}, compacted ${result.value?.repos ?? 0}.`)
|
|
1438
|
+
} else {
|
|
1439
|
+
setCleanupText(typeof t === 'function'
|
|
1440
|
+
? t('cleanupFailed', { message: result.error?.message ?? '' })
|
|
1441
|
+
: String(result.error?.message ?? 'cleanup failed'))
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
const toggle = async (key) => {
|
|
1446
|
+
if (busy !== null || flags === null) return
|
|
1447
|
+
const next = { ...flags, [key]: flags[key] !== true }
|
|
1448
|
+
setBusy(key)
|
|
1449
|
+
setError(null)
|
|
1450
|
+
const result = await call('setSettings', { [key]: next[key] })
|
|
1451
|
+
setBusy(null)
|
|
1452
|
+
if (result.ok === true) setFlags(result.value)
|
|
1453
|
+
else setError(typeof t === 'function' ? t('settingsFailed', { message: result.error?.message ?? '' }) : String(result.error?.message ?? ''))
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
const row = (key, title, description) =>
|
|
1457
|
+
React.createElement(
|
|
1458
|
+
'div',
|
|
1459
|
+
{ key, className: 'ce-row' },
|
|
1460
|
+
React.createElement(
|
|
1461
|
+
'div',
|
|
1462
|
+
{ className: 'ce-row-text' },
|
|
1463
|
+
React.createElement('div', { className: 'ce-row-title' }, title),
|
|
1464
|
+
React.createElement('div', { className: 'ce-row-desc' }, description),
|
|
1465
|
+
),
|
|
1466
|
+
React.createElement(
|
|
1467
|
+
'button',
|
|
1468
|
+
{
|
|
1469
|
+
type: 'button',
|
|
1470
|
+
role: 'switch',
|
|
1471
|
+
'aria-checked': flags !== null && flags[key] === true,
|
|
1472
|
+
'aria-label': title,
|
|
1473
|
+
className: `ce-switch${flags !== null && flags[key] === true ? ' on' : ''}`,
|
|
1474
|
+
disabled: flags === null || busy !== null,
|
|
1475
|
+
onClick: () => toggle(key),
|
|
1476
|
+
},
|
|
1477
|
+
React.createElement('span', { className: 'ce-switch-thumb' }),
|
|
1478
|
+
),
|
|
1479
|
+
)
|
|
1480
|
+
|
|
1481
|
+
const numberRow = (title, description) =>
|
|
1482
|
+
React.createElement(
|
|
1483
|
+
'div',
|
|
1484
|
+
{ className: 'ce-row' },
|
|
1485
|
+
React.createElement(
|
|
1486
|
+
'div',
|
|
1487
|
+
{ className: 'ce-row-text' },
|
|
1488
|
+
React.createElement('div', { className: 'ce-row-title' }, title),
|
|
1489
|
+
React.createElement('div', { className: 'ce-row-desc' }, description),
|
|
1490
|
+
),
|
|
1491
|
+
React.createElement(
|
|
1492
|
+
'div',
|
|
1493
|
+
{ className: 'ce-number-wrap' },
|
|
1494
|
+
React.createElement('input', {
|
|
1495
|
+
type: 'number',
|
|
1496
|
+
min: 1,
|
|
1497
|
+
max: 50,
|
|
1498
|
+
className: 'ce-number',
|
|
1499
|
+
value: turnsDraft ?? '',
|
|
1500
|
+
disabled: flags === null || busy !== null,
|
|
1501
|
+
'aria-label': title,
|
|
1502
|
+
onChange: (event) => setTurnsDraft(event.target.value),
|
|
1503
|
+
onBlur: () => { void commitTurns() },
|
|
1504
|
+
onKeyDown: (event) => {
|
|
1505
|
+
if (event.key === 'Enter') {
|
|
1506
|
+
event.preventDefault()
|
|
1507
|
+
void commitTurns()
|
|
1508
|
+
}
|
|
1509
|
+
},
|
|
1510
|
+
}),
|
|
1511
|
+
React.createElement('span', { className: 'ce-number-unit' }, typeof t === 'function' ? t('settingsTurnsUnit') : 'turns'),
|
|
1512
|
+
),
|
|
1513
|
+
)
|
|
1514
|
+
|
|
1515
|
+
const title = typeof t === 'function' ? t('settingsTitle') : 'Coding Enhanced'
|
|
1516
|
+
const wrapper = compact === true ? 'ce-settings compact' : 'ce-settings'
|
|
1517
|
+
if (flags === null) {
|
|
1518
|
+
return React.createElement(
|
|
1519
|
+
'div',
|
|
1520
|
+
{ className: wrapper },
|
|
1521
|
+
compact === true ? null : React.createElement('h2', { className: 'ce-title' }, title),
|
|
1522
|
+
React.createElement('p', { className: 'ce-sub' }, typeof t === 'function' ? t('settingsLoading') : 'Loading settings…'),
|
|
1523
|
+
error !== null ? React.createElement('p', { className: 'ce-error' }, error) : null,
|
|
1524
|
+
)
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
const cleanupRow = React.createElement(
|
|
1528
|
+
'div',
|
|
1529
|
+
{ className: 'ce-row' },
|
|
1530
|
+
React.createElement(
|
|
1531
|
+
'div',
|
|
1532
|
+
{ className: 'ce-row-text' },
|
|
1533
|
+
React.createElement('div', { className: 'ce-row-title' }, typeof t === 'function' ? t('cleanupNow') : 'Clean up now'),
|
|
1534
|
+
cleanupText !== null
|
|
1535
|
+
? React.createElement('div', { className: 'ce-row-desc' }, cleanupText)
|
|
1536
|
+
: null,
|
|
1537
|
+
),
|
|
1538
|
+
React.createElement(
|
|
1539
|
+
'button',
|
|
1540
|
+
{
|
|
1541
|
+
type: 'button',
|
|
1542
|
+
className: 'ce-action',
|
|
1543
|
+
disabled: cleanupBusy || flags === null,
|
|
1544
|
+
onClick: () => { void runCleanup() },
|
|
1545
|
+
},
|
|
1546
|
+
cleanupBusy
|
|
1547
|
+
? '…'
|
|
1548
|
+
: (typeof t === 'function' ? t('cleanupNow') : 'Clean up now'),
|
|
1549
|
+
),
|
|
1550
|
+
)
|
|
1551
|
+
|
|
1552
|
+
return React.createElement(
|
|
1553
|
+
'div',
|
|
1554
|
+
{ className: wrapper },
|
|
1555
|
+
compact === true
|
|
1556
|
+
? React.createElement('div', { className: 'ce-compact-title' }, typeof t === 'function' ? t('settingsFeatures') : 'Features')
|
|
1557
|
+
: React.createElement('h2', { className: 'ce-title' }, title),
|
|
1558
|
+
compact === true
|
|
1559
|
+
? null
|
|
1560
|
+
: React.createElement('p', { className: 'ce-sub' }, typeof t === 'function' ? t('settingsSubtitle') : 'Toggle each sub-feature independently.'),
|
|
1561
|
+
React.createElement('div', { className: 'ce-group-title' }, typeof t === 'function' ? t('settingsGroupReview') : 'Review'),
|
|
1562
|
+
React.createElement(
|
|
1563
|
+
'div',
|
|
1564
|
+
{ className: 'ce-card' },
|
|
1565
|
+
row('review', typeof t === 'function' ? t('settingsReview') : 'AI Change Review', typeof t === 'function' ? t('settingsReviewDesc') : ''),
|
|
1566
|
+
),
|
|
1567
|
+
React.createElement('div', { className: 'ce-group-title' }, typeof t === 'function' ? t('settingsGroupWithdraw') : 'Turn withdraw'),
|
|
1568
|
+
React.createElement(
|
|
1569
|
+
'div',
|
|
1570
|
+
{ className: 'ce-card' },
|
|
1571
|
+
row('withdraw', typeof t === 'function' ? t('settingsWithdraw') : 'Turn Withdraw', typeof t === 'function' ? t('settingsWithdrawDesc') : ''),
|
|
1572
|
+
numberRow(
|
|
1573
|
+
typeof t === 'function' ? t('settingsKeepTurns') : 'Turns kept for withdraw',
|
|
1574
|
+
typeof t === 'function' ? t('settingsKeepTurnsDesc') : 'How many recent turns stay withdrawable.',
|
|
1575
|
+
),
|
|
1576
|
+
row(
|
|
1577
|
+
'nestedSnapshots',
|
|
1578
|
+
typeof t === 'function' ? t('settingsNested') : 'Snapshot nested git repositories',
|
|
1579
|
+
typeof t === 'function' ? t('settingsNestedDesc') : 'Include nested repository files in snapshots.',
|
|
1580
|
+
),
|
|
1581
|
+
row(
|
|
1582
|
+
'autoGc',
|
|
1583
|
+
typeof t === 'function' ? t('settingsAutoGc') : 'Automatic cleanup',
|
|
1584
|
+
typeof t === 'function' ? t('settingsAutoGcDesc') : 'Compact shadow snapshots after pruning or withdrawing.',
|
|
1585
|
+
),
|
|
1586
|
+
cleanupRow,
|
|
1587
|
+
),
|
|
1588
|
+
error !== null ? React.createElement('p', { className: 'ce-error' }, error) : null,
|
|
1589
|
+
)
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
// ------------------------------------------------ tab registration ---
|
|
1593
|
+
const bindT = ctx.locale.bind(NS)
|
|
1594
|
+
|
|
1595
|
+
// Withdrawn turns must be marked even when the turn-tail marker is not
|
|
1596
|
+
// mounted (virtualized or collapsed chat). Keep a session-scoped global
|
|
1597
|
+
// painter that only runs while withdraw UI is mounted for that session.
|
|
1598
|
+
ctx.effect(() => {
|
|
1599
|
+
const label = typeof bindT === 'function' ? bindT('badge') : 'Withdrawn'
|
|
1600
|
+
const timer = window.setInterval(() => {
|
|
1601
|
+
for (const sessionId of pollCounts.keys()) {
|
|
1602
|
+
const record = records.get(sessionId)
|
|
1603
|
+
if (record === undefined || record.status !== 'ready') continue
|
|
1604
|
+
const turns = record.value?.turns
|
|
1605
|
+
if (turns === null || turns === undefined || typeof turns !== 'object') continue
|
|
1606
|
+
for (const key of Object.keys(turns)) {
|
|
1607
|
+
const turn = Number(key)
|
|
1608
|
+
if (!Number.isSafeInteger(turn)) continue
|
|
1609
|
+
markTurn(turn, label)
|
|
1610
|
+
applyFold(turn, readFold(sessionId, turn))
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
}, 1000)
|
|
1614
|
+
return () => window.clearInterval(timer)
|
|
1615
|
+
}, 'coding-enhanced: withdrawn turn markers')
|
|
1616
|
+
try {
|
|
1617
|
+
ctx.effect(() => ctx.sidebarRightTabs.register({
|
|
1618
|
+
id: REVIEW_TAB_ID,
|
|
1619
|
+
kind: REVIEW_KIND,
|
|
1620
|
+
title: () => (typeof bindT === 'function' ? bindT('reviewTitle') : 'Code review'),
|
|
1621
|
+
}), 'coding-enhanced: review tab type')
|
|
1622
|
+
} catch (error) {
|
|
1623
|
+
ctx.logger?.warn?.(`coding-enhanced: cannot register the review tab type: ${String(error)}`)
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
// ------------------------------------------------------------ slots ---
|
|
1627
|
+
ctx.slots.inject('plugins.bundle.config', () =>
|
|
1628
|
+
ctx.slots.register(
|
|
1629
|
+
{
|
|
1630
|
+
name: 'plugins.bundle.config',
|
|
1631
|
+
key: 'dsh-coding-enhanced',
|
|
1632
|
+
locale: NS,
|
|
1633
|
+
inject: () => ({ compact: true }),
|
|
1634
|
+
},
|
|
1635
|
+
SettingsSection,
|
|
1636
|
+
),
|
|
1637
|
+
)
|
|
1638
|
+
|
|
1639
|
+
ctx.slots.inject('conversation.input.right', () =>
|
|
1640
|
+
ctx.slots.register(
|
|
1641
|
+
{
|
|
1642
|
+
name: 'conversation.input.right',
|
|
1643
|
+
id: 'coding-enhanced-review-toggle',
|
|
1644
|
+
order: 20,
|
|
1645
|
+
locale: NS,
|
|
1646
|
+
},
|
|
1647
|
+
ReviewToggle,
|
|
1648
|
+
),
|
|
1649
|
+
)
|
|
1650
|
+
|
|
1651
|
+
ctx.slots.inject('settings.section', () =>
|
|
1652
|
+
ctx.slots.register(
|
|
1653
|
+
{
|
|
1654
|
+
name: 'settings.section',
|
|
1655
|
+
id: 'coding-enhanced',
|
|
1656
|
+
order: 60,
|
|
1657
|
+
label: () => (typeof bindT === 'function' ? bindT('settingsNav') : 'Coding Enhanced'),
|
|
1658
|
+
locale: NS,
|
|
1659
|
+
},
|
|
1660
|
+
SettingsSection,
|
|
1661
|
+
),
|
|
1662
|
+
)
|
|
1663
|
+
|
|
1664
|
+
ctx.slots.inject('conversation.chat.assistant-actions', () =>
|
|
1665
|
+
ctx.slots.register(
|
|
1666
|
+
{
|
|
1667
|
+
name: 'conversation.chat.assistant-actions',
|
|
1668
|
+
id: 'coding-enhanced',
|
|
1669
|
+
order: 40,
|
|
1670
|
+
locale: NS,
|
|
1671
|
+
inject: (sessionId) => ({ sessionId }),
|
|
1672
|
+
},
|
|
1673
|
+
WithdrawAction,
|
|
1674
|
+
),
|
|
1675
|
+
)
|
|
1676
|
+
|
|
1677
|
+
ctx.slots.inject('conversation.chat.turnTail', () =>
|
|
1678
|
+
ctx.slots.register(
|
|
1679
|
+
{
|
|
1680
|
+
name: 'conversation.chat.turnTail',
|
|
1681
|
+
id: 'coding-enhanced-marker',
|
|
1682
|
+
order: 200,
|
|
1683
|
+
locale: NS,
|
|
1684
|
+
inject: (sessionId) => ({ sessionId }),
|
|
1685
|
+
},
|
|
1686
|
+
WithdrawMarker,
|
|
1687
|
+
),
|
|
1688
|
+
)
|
|
1689
|
+
|
|
1690
|
+
ctx.slots.inject('conversation.session.header.actions', () =>
|
|
1691
|
+
ctx.slots.register(
|
|
1692
|
+
{
|
|
1693
|
+
name: 'conversation.session.header.actions',
|
|
1694
|
+
id: 'coding-enhanced-review-watcher',
|
|
1695
|
+
order: 60,
|
|
1696
|
+
locale: NS,
|
|
1697
|
+
inject: (sessionId) => ({ sessionId }),
|
|
1698
|
+
},
|
|
1699
|
+
ReviewWatcher,
|
|
1700
|
+
),
|
|
1701
|
+
)
|
|
1702
|
+
|
|
1703
|
+
ctx.slots.inject('sidebar.right.pane.tab', () =>
|
|
1704
|
+
ctx.slots.register(
|
|
1705
|
+
{
|
|
1706
|
+
name: 'sidebar.right.pane.tab',
|
|
1707
|
+
key: REVIEW_TAB_ID,
|
|
1708
|
+
locale: NS,
|
|
1709
|
+
},
|
|
1710
|
+
ReviewTab,
|
|
1711
|
+
),
|
|
1712
|
+
)
|
|
1713
|
+
|
|
1714
|
+
ctx.on('connection/reset', () => {
|
|
1715
|
+
for (const sessionId of records.keys()) {
|
|
1716
|
+
fetchedAt.delete(sessionId)
|
|
1717
|
+
void refresh(sessionId, true)
|
|
1718
|
+
}
|
|
1719
|
+
feedRefresh()
|
|
1720
|
+
})
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
exports.apply = apply
|
|
1724
|
+
exports.inject = inject
|
|
1725
|
+
return module.exports
|
|
1726
|
+
},
|
|
1727
|
+
})
|