dsh-taskbridge 1.7.1 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/LICENSE +21 -21
- package/README.md +733 -877
- package/THIRD_PARTY_NOTICES.txt +23 -23
- package/antigravity/agents/dsh-taskbridge.md +32 -0
- package/antigravity/skills/dsh-taskbridge/SKILL.md +51 -0
- package/codex/dsh-taskbridge.toml +181 -631
- package/cordis.patch.yml +6 -6
- package/docs/INTRODUCTION.md +122 -295
- package/docs/INTRODUCTION.zh.md +134 -279
- package/docs/antigravity-integration.md +42 -0
- package/docs/auth-contract.md +138 -138
- package/docs/claude-code.md +6 -11
- package/docs/codex-integration.md +2 -2
- package/docs/contracts-stage-b.md +443 -443
- package/docs/conversation-placement.md +7 -6
- package/docs/plugin-market.md +30 -30
- package/docs/redaction-contract.md +170 -170
- package/docs/releases/1.7.0.zh.md +11 -11
- package/docs/releases/1.8.0.zh.md +16 -0
- package/docs/releases/1.8.1.zh.md +24 -0
- package/docs/runtime-compatibility.md +1 -1
- package/docs/taskbridge-upgrade.md +28 -28
- package/docs/taskdispatch-upgrade.md +25 -25
- package/docs/workspace-contract.md +538 -538
- package/docs/workspace-grouping.md +126 -126
- package/icon.svg +1 -1
- package/lib/client.d.ts +804 -699
- package/lib/client.js +7 -7
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +150 -144
- package/src/antigravity/installer.js +1068 -0
- package/src/antigravity/seam.js +142 -0
- package/src/auth/fence.js +361 -361
- package/src/auth/grants.js +789 -789
- package/src/client/api.js +266 -3
- package/src/client/index.jsx +224 -11
- package/src/client/sidebar.jsx +862 -862
- package/src/client/styles.js +624 -624
- package/src/client/task-cleanup.js +429 -304
- package/src/client/task-records-table.jsx +217 -217
- package/src/client/task-view.js +307 -307
- package/src/client/workspace-groups.js +482 -482
- package/src/client/workspaces-browser.jsx +770 -770
- package/src/codex/agent-ownership.js +270 -270
- package/src/codex/installer.js +6 -0
- package/src/codex/toml.js +784 -784
- package/src/config/defaults.js +11 -15
- package/src/config/redact.js +245 -245
- package/src/config/store.js +186 -186
- package/src/credentials/seam.js +202 -202
- package/src/http/respond.js +6 -5
- package/src/http/user-plane.js +83 -1
- package/src/index.js +25 -0
- package/src/jobs/diagnostics.js +15 -15
- package/src/jobs/engine.js +1 -0
- package/src/jobs/history.js +1 -1
- package/src/jobs/plan-store.js +1103 -1020
- package/src/jobs/record-cleanup.js +452 -7
- package/src/jobs/review-note.js +63 -63
- package/src/jobs/task-descriptions.js +82 -82
- package/src/jobs/task-display.js +73 -73
- package/src/jobs/task-tree.js +786 -786
- package/src/jobs/title.js +134 -134
- package/src/mcp/continuation.js +317 -317
- package/src/mcp/server.js +34 -27
- package/src/mcp/wait.js +34 -15
- package/src/model/connectivity.js +371 -371
- package/src/model/discovery.js +582 -582
- package/src/model/native-catalog.js +68 -68
- package/src/model/openai-adapter.js +671 -671
- package/src/model/probe.js +264 -264
- package/src/model/providers.js +756 -756
- package/src/model/routing.js +321 -321
- package/src/runtime/agent-runner.js +1 -0
- package/src/runtime/permissions.js +1619 -1619
- package/src/runtime/question-call.js +162 -162
- package/src/runtime/questions.js +909 -909
- package/src/runtime/session-placement.js +36 -1
- package/src/runtime/worker-prompt.js +61 -55
- package/src/workspace/audit.js +775 -775
- package/src/workspace/preflight.js +424 -424
- package/src/workspace/worktrees.js +833 -679
|
@@ -1,304 +1,429 @@
|
|
|
1
|
-
// Task-record cleanup: which execution chains may be selected for deletion, what a
|
|
2
|
-
// deletion batch carries, and what the operator is shown before it is sent.
|
|
3
|
-
//
|
|
4
|
-
// Zero Node-only imports and no React: this is the part of "清理记录" that can be
|
|
5
|
-
// reasoned about and tested on its own, while the page (`index.jsx`) only renders
|
|
6
|
-
// the answers computed here. Three rules shape everything:
|
|
7
|
-
//
|
|
8
|
-
// 1. **Identity comes from the host's own tree.** A selectable unit is ONE
|
|
9
|
-
// execution chain (`chainId`, `taskIds`) taken from the projection's
|
|
10
|
-
// `executions` — including a chain attached to a planning node — and the
|
|
11
|
-
// selection carries exactly that chain's ids. Nothing is inferred from a
|
|
12
|
-
// title, a time or a position, and the tree is never re-derived here.
|
|
13
|
-
// 2. **Eligibility is stated, not guessed.** A chain the host marked as still
|
|
14
|
-
// active/undurable, as depended on by another chain, or as holding planning
|
|
15
|
-
// children is listed with `selectable: false` and a reason. A selection only
|
|
16
|
-
// ever contains selectable chains, so a disabled row cannot be sent by accident.
|
|
17
|
-
// The server re-checks every rule; this side only decides what to draw.
|
|
18
|
-
// 3. **The batch is closed.** The request body carries `{ chainId, taskIds }`
|
|
19
|
-
// pairs and nothing else: no time range, no path, and no "delete everything".
|
|
20
|
-
|
|
21
|
-
/** Refusal/notice codes the cleanup surface may produce locally. */
|
|
22
|
-
export const CLEANUP_BLOCKER_LABELS = Object.freeze({
|
|
23
|
-
CLEANUP_CHAIN_LIVE: '仍在执行或未正常结束,不能清理',
|
|
24
|
-
CLEANUP_NOT_DURABLE: '记录尚未写入,不能清理',
|
|
25
|
-
CLEANUP_NEXT_ROUND: '还有续接记录,不能清理',
|
|
26
|
-
CLEANUP_PLAN_CHILDREN: '有规划子节点引用此记录,不能清理',
|
|
27
|
-
CLEANUP_HIERARCHY_CHILDREN: '有子任务引用此记录,不能清理',
|
|
28
|
-
CLEANUP_REVIEW_WRITE: '审查意见正在写入,请稍后重试',
|
|
29
|
-
CLEANUP_UNAVAILABLE: '清理暂不可用',
|
|
30
|
-
CLEANUP_STALE: '任务记录已变化,请重新选择',
|
|
31
|
-
unknown: '暂时无法确认这条记录可以清理',
|
|
32
|
-
'selection-stale': '任务记录已变化,请重新选择',
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
/** Chinese label for one blocker code, falling back to the raw code. */
|
|
36
|
-
export function cleanupBlockerLabel(code) {
|
|
37
|
-
if (typeof code !== 'string' || code === '') return CLEANUP_BLOCKER_LABELS.unknown;
|
|
38
|
-
return CLEANUP_BLOCKER_LABELS[code] ?? String(code);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* How many chains one request may name. Mirrors `MAX_CLEANUP_CHAINS` in
|
|
43
|
-
* `src/jobs/record-cleanup.js`; the host refuses a larger batch rather than
|
|
44
|
-
* silently dropping the rest, and the page refuses it before sending.
|
|
45
|
-
*/
|
|
46
|
-
export const MAX_CLEANUP_CHAINS = 100;
|
|
47
|
-
|
|
48
|
-
/** Chains of one node: a plan node carries `executions`, a task node its own `chain`. */
|
|
49
|
-
function chainsOf(node) {
|
|
50
|
-
if (node === null || typeof node !== 'object') return [];
|
|
51
|
-
if (Array.isArray(node.executions)) return node.executions;
|
|
52
|
-
return node.chain !== null && typeof node.chain === 'object' ? [node.chain] : [];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** One chain whose identity the page can key, or `null`. */
|
|
56
|
-
function selectableChain(chain) {
|
|
57
|
-
if (chain === null || typeof chain !== 'object') return null;
|
|
58
|
-
const chainId = typeof chain.chainId === 'string' && chain.chainId !== '' ? chain.chainId : null;
|
|
59
|
-
const taskIds = Array.isArray(chain.taskIds) ? chain.taskIds.filter((id) => typeof id === 'string' && id !== '') : [];
|
|
60
|
-
if (chainId === null || taskIds.length === 0) return null;
|
|
61
|
-
return { chainId, taskIds };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Every execution chain of one rendered tree, in pre-order, with its eligibility.
|
|
66
|
-
*
|
|
67
|
-
* A chain that appears twice (it cannot in one projection, but a host could answer a
|
|
68
|
-
* duplicated node) is listed once, by `chainId`: the selection is a set of chains,
|
|
69
|
-
* and a duplicate row would let one chain be counted twice in the confirmation.
|
|
70
|
-
* @param {object | null} view - `taskTreeView(...)` result.
|
|
71
|
-
* @returns {object[]} `{ chainId, taskIds, roundCount, title, planNodeId, parentNodeId,
|
|
72
|
-
* selectable, blockers, reason, nodeId }` entries.
|
|
73
|
-
*/
|
|
74
|
-
export function cleanupCandidates(view) {
|
|
75
|
-
const out = [];
|
|
76
|
-
const seen = new Set();
|
|
77
|
-
const walk = (node) => {
|
|
78
|
-
for (const chain of chainsOf(node)) {
|
|
79
|
-
const identity = selectableChain(chain);
|
|
80
|
-
if (identity === null || seen.has(identity.chainId)) continue;
|
|
81
|
-
seen.add(identity.chainId);
|
|
82
|
-
const blockers = Array.isArray(chain.cleanup?.blockers)
|
|
83
|
-
? chain.cleanup.blockers.filter((code) => typeof code === 'string' && code !== '')
|
|
84
|
-
: [];
|
|
85
|
-
const eligible = chain.cleanup?.eligible === true;
|
|
86
|
-
const selectable = eligible && blockers.length === 0;
|
|
87
|
-
out.push({
|
|
88
|
-
chainId: identity.chainId,
|
|
89
|
-
taskIds: identity.taskIds,
|
|
90
|
-
roundCount: Number.isFinite(chain.roundCount) ? chain.roundCount : identity.taskIds.length,
|
|
91
|
-
title: typeof chain.displayTitle === 'string' && chain.displayTitle !== ''
|
|
92
|
-
? chain.displayTitle
|
|
93
|
-
: (typeof chain.title === 'string' && chain.title !== '' ? chain.title : '未记录标题'),
|
|
94
|
-
planNodeId: typeof chain.planNodeId === 'string' ? chain.planNodeId : null,
|
|
95
|
-
parentNodeId: typeof chain.parentNodeId === 'string' ? chain.parentNodeId : null,
|
|
96
|
-
nodeId: typeof node?.nodeId === 'string' ? node.nodeId : null,
|
|
97
|
-
nodeKind: typeof node?.kind === 'string' ? node.kind : 'unknown',
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
*
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
*
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* @
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
1
|
+
// Task-record cleanup: which execution chains may be selected for deletion, what a
|
|
2
|
+
// deletion batch carries, and what the operator is shown before it is sent.
|
|
3
|
+
//
|
|
4
|
+
// Zero Node-only imports and no React: this is the part of "清理记录" that can be
|
|
5
|
+
// reasoned about and tested on its own, while the page (`index.jsx`) only renders
|
|
6
|
+
// the answers computed here. Three rules shape everything:
|
|
7
|
+
//
|
|
8
|
+
// 1. **Identity comes from the host's own tree.** A selectable unit is ONE
|
|
9
|
+
// execution chain (`chainId`, `taskIds`) taken from the projection's
|
|
10
|
+
// `executions` — including a chain attached to a planning node — and the
|
|
11
|
+
// selection carries exactly that chain's ids. Nothing is inferred from a
|
|
12
|
+
// title, a time or a position, and the tree is never re-derived here.
|
|
13
|
+
// 2. **Eligibility is stated, not guessed.** A chain the host marked as still
|
|
14
|
+
// active/undurable, as depended on by another chain, or as holding planning
|
|
15
|
+
// children is listed with `selectable: false` and a reason. A selection only
|
|
16
|
+
// ever contains selectable chains, so a disabled row cannot be sent by accident.
|
|
17
|
+
// The server re-checks every rule; this side only decides what to draw.
|
|
18
|
+
// 3. **The batch is closed.** The request body carries `{ chainId, taskIds }`
|
|
19
|
+
// pairs and nothing else: no time range, no path, and no "delete everything".
|
|
20
|
+
|
|
21
|
+
/** Refusal/notice codes the cleanup surface may produce locally. */
|
|
22
|
+
export const CLEANUP_BLOCKER_LABELS = Object.freeze({
|
|
23
|
+
CLEANUP_CHAIN_LIVE: '仍在执行或未正常结束,不能清理',
|
|
24
|
+
CLEANUP_NOT_DURABLE: '记录尚未写入,不能清理',
|
|
25
|
+
CLEANUP_NEXT_ROUND: '还有续接记录,不能清理',
|
|
26
|
+
CLEANUP_PLAN_CHILDREN: '有规划子节点引用此记录,不能清理',
|
|
27
|
+
CLEANUP_HIERARCHY_CHILDREN: '有子任务引用此记录,不能清理',
|
|
28
|
+
CLEANUP_REVIEW_WRITE: '审查意见正在写入,请稍后重试',
|
|
29
|
+
CLEANUP_UNAVAILABLE: '清理暂不可用',
|
|
30
|
+
CLEANUP_STALE: '任务记录已变化,请重新选择',
|
|
31
|
+
unknown: '暂时无法确认这条记录可以清理',
|
|
32
|
+
'selection-stale': '任务记录已变化,请重新选择',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/** Chinese label for one blocker code, falling back to the raw code. */
|
|
36
|
+
export function cleanupBlockerLabel(code) {
|
|
37
|
+
if (typeof code !== 'string' || code === '') return CLEANUP_BLOCKER_LABELS.unknown;
|
|
38
|
+
return CLEANUP_BLOCKER_LABELS[code] ?? String(code);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* How many chains one request may name. Mirrors `MAX_CLEANUP_CHAINS` in
|
|
43
|
+
* `src/jobs/record-cleanup.js`; the host refuses a larger batch rather than
|
|
44
|
+
* silently dropping the rest, and the page refuses it before sending.
|
|
45
|
+
*/
|
|
46
|
+
export const MAX_CLEANUP_CHAINS = 100;
|
|
47
|
+
|
|
48
|
+
/** Chains of one node: a plan node carries `executions`, a task node its own `chain`. */
|
|
49
|
+
function chainsOf(node) {
|
|
50
|
+
if (node === null || typeof node !== 'object') return [];
|
|
51
|
+
if (Array.isArray(node.executions)) return node.executions;
|
|
52
|
+
return node.chain !== null && typeof node.chain === 'object' ? [node.chain] : [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** One chain whose identity the page can key, or `null`. */
|
|
56
|
+
function selectableChain(chain) {
|
|
57
|
+
if (chain === null || typeof chain !== 'object') return null;
|
|
58
|
+
const chainId = typeof chain.chainId === 'string' && chain.chainId !== '' ? chain.chainId : null;
|
|
59
|
+
const taskIds = Array.isArray(chain.taskIds) ? chain.taskIds.filter((id) => typeof id === 'string' && id !== '') : [];
|
|
60
|
+
if (chainId === null || taskIds.length === 0) return null;
|
|
61
|
+
return { chainId, taskIds };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Every execution chain of one rendered tree, in pre-order, with its eligibility.
|
|
66
|
+
*
|
|
67
|
+
* A chain that appears twice (it cannot in one projection, but a host could answer a
|
|
68
|
+
* duplicated node) is listed once, by `chainId`: the selection is a set of chains,
|
|
69
|
+
* and a duplicate row would let one chain be counted twice in the confirmation.
|
|
70
|
+
* @param {object | null} view - `taskTreeView(...)` result.
|
|
71
|
+
* @returns {object[]} `{ chainId, taskIds, roundCount, title, planNodeId, parentNodeId,
|
|
72
|
+
* selectable, blockers, reason, nodeId }` entries.
|
|
73
|
+
*/
|
|
74
|
+
export function cleanupCandidates(view) {
|
|
75
|
+
const out = [];
|
|
76
|
+
const seen = new Set();
|
|
77
|
+
const walk = (node) => {
|
|
78
|
+
for (const chain of chainsOf(node)) {
|
|
79
|
+
const identity = selectableChain(chain);
|
|
80
|
+
if (identity === null || seen.has(identity.chainId)) continue;
|
|
81
|
+
seen.add(identity.chainId);
|
|
82
|
+
const blockers = Array.isArray(chain.cleanup?.blockers)
|
|
83
|
+
? chain.cleanup.blockers.filter((code) => typeof code === 'string' && code !== '')
|
|
84
|
+
: [];
|
|
85
|
+
const eligible = chain.cleanup?.eligible === true;
|
|
86
|
+
const selectable = eligible && blockers.length === 0;
|
|
87
|
+
out.push({
|
|
88
|
+
chainId: identity.chainId,
|
|
89
|
+
taskIds: identity.taskIds,
|
|
90
|
+
roundCount: Number.isFinite(chain.roundCount) ? chain.roundCount : identity.taskIds.length,
|
|
91
|
+
title: typeof chain.displayTitle === 'string' && chain.displayTitle !== ''
|
|
92
|
+
? chain.displayTitle
|
|
93
|
+
: (typeof chain.title === 'string' && chain.title !== '' ? chain.title : '未记录标题'),
|
|
94
|
+
planNodeId: typeof chain.planNodeId === 'string' ? chain.planNodeId : null,
|
|
95
|
+
parentNodeId: typeof chain.parentNodeId === 'string' ? chain.parentNodeId : null,
|
|
96
|
+
nodeId: typeof node?.nodeId === 'string' ? node.nodeId : null,
|
|
97
|
+
nodeKind: typeof node?.kind === 'string' ? node.kind : 'unknown',
|
|
98
|
+
nodeStatus: typeof chain.nodeStatus === 'string'
|
|
99
|
+
? chain.nodeStatus
|
|
100
|
+
: (typeof node?.nodeStatus === 'string' ? node.nodeStatus : null),
|
|
101
|
+
isolation: typeof chain.isolation === 'string'
|
|
102
|
+
? chain.isolation
|
|
103
|
+
: (Array.isArray(chain.rounds) && typeof chain.rounds[0]?.isolation === 'string' ? chain.rounds[0].isolation : null),
|
|
104
|
+
selectable,
|
|
105
|
+
blockers,
|
|
106
|
+
reason: selectable
|
|
107
|
+
? null
|
|
108
|
+
: (blockers.length > 0
|
|
109
|
+
? blockers.map(cleanupBlockerLabel).join(';')
|
|
110
|
+
: cleanupBlockerLabel('unknown')),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
for (const child of Array.isArray(node?.children) ? node.children : []) walk(child);
|
|
114
|
+
};
|
|
115
|
+
for (const root of Array.isArray(view?.roots) ? view.roots : []) walk(root);
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The cleanup state of one candidate after a refresh.
|
|
121
|
+
*
|
|
122
|
+
* `selection-stale` is the one blocker this module adds: the operator selected a
|
|
123
|
+
* chain, a background refresh replaced the tree, and the chain's rounds are no
|
|
124
|
+
* longer exactly what was selected. Sending it anyway would delete a round the
|
|
125
|
+
* operator never saw, so it is made unselectable instead.
|
|
126
|
+
* @param {object} candidate - entry from {@link cleanupCandidates}.
|
|
127
|
+
* @param {string[]} selectedTaskIds - the ids that were selected for this chain.
|
|
128
|
+
* @returns {object} the candidate, possibly with an added `selection-stale` blocker.
|
|
129
|
+
*/
|
|
130
|
+
export function withSelectionState(candidate, selectedTaskIds) {
|
|
131
|
+
if (!Array.isArray(selectedTaskIds) || !candidate.selectable) return candidate;
|
|
132
|
+
const same = selectedTaskIds.length === candidate.taskIds.length
|
|
133
|
+
&& selectedTaskIds.every((id, index) => id === candidate.taskIds[index]);
|
|
134
|
+
if (same) return candidate;
|
|
135
|
+
const blockers = [...candidate.blockers, 'selection-stale'];
|
|
136
|
+
return {
|
|
137
|
+
...candidate,
|
|
138
|
+
selectable: false,
|
|
139
|
+
blockers,
|
|
140
|
+
reason: blockers.map(cleanupBlockerLabel).join(';'),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Drop selections that no longer name a selectable chain of the current tree.
|
|
146
|
+
*
|
|
147
|
+
* Kept as a pure function so the page can run it on every render: a selection is
|
|
148
|
+
* `{ [chainId]: taskIds }`, and anything this returns is safe to send.
|
|
149
|
+
* @param {object} selection - chain id -> selected task ids.
|
|
150
|
+
* @param {object[]} candidates - current candidates.
|
|
151
|
+
* @returns {{ selection: object, dropped: string[] }} the surviving selection and the ids dropped.
|
|
152
|
+
*/
|
|
153
|
+
export function pruneCleanupSelection(selection, candidates) {
|
|
154
|
+
const byId = new Map(candidates.map((candidate) => [candidate.chainId, candidate]));
|
|
155
|
+
const next = {};
|
|
156
|
+
const dropped = [];
|
|
157
|
+
for (const [chainId, ids] of Object.entries(selection ?? {})) {
|
|
158
|
+
const candidate = byId.get(chainId);
|
|
159
|
+
if (candidate === undefined || !candidate.selectable) {
|
|
160
|
+
dropped.push(chainId);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const checked = withSelectionState(candidate, ids);
|
|
164
|
+
if (!checked.selectable) {
|
|
165
|
+
dropped.push(chainId);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
next[chainId] = candidate.taskIds.slice();
|
|
169
|
+
}
|
|
170
|
+
return { selection: next, dropped };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Toggle one chain in a selection.
|
|
175
|
+
* @param {object} selection - chain id -> selected task ids.
|
|
176
|
+
* @param {object} candidate - the chain to toggle.
|
|
177
|
+
* @returns {object} the new selection (a new object; the input is not mutated).
|
|
178
|
+
*/
|
|
179
|
+
export function toggleCleanupSelection(selection, candidate) {
|
|
180
|
+
const next = { ...(selection ?? {}) };
|
|
181
|
+
if (candidate === null || typeof candidate !== 'object' || candidate.selectable !== true) return next;
|
|
182
|
+
if (Array.isArray(next[candidate.chainId])) delete next[candidate.chainId];
|
|
183
|
+
else next[candidate.chainId] = candidate.taskIds.slice();
|
|
184
|
+
return next;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Which status group one preset shortcut selects.
|
|
189
|
+
*
|
|
190
|
+
* `all` takes every selectable chain of the current view, `accepted` only the chains
|
|
191
|
+
* the host marked `accepted`, and `failed-cancelled` the chains that ended badly:
|
|
192
|
+
* `failed`, `cancelled`, and `interrupted` (a chain a host restart left in a terminal
|
|
193
|
+
* state no round can resume).
|
|
194
|
+
*/
|
|
195
|
+
export const CLEANUP_PRESETS = Object.freeze(['all', 'accepted', 'failed-cancelled']);
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Batch-select up to {@link MAX_CLEANUP_CHAINS} selectable candidates matching a preset,
|
|
199
|
+
* optionally restricted to the chains currently visible under the active UI filters.
|
|
200
|
+
* @param {object[]} candidates - entries from {@link cleanupCandidates}.
|
|
201
|
+
* @param {'all'|'accepted'|'failed-cancelled'} [preset] - which status group to select.
|
|
202
|
+
* @param {Set<string>|string[]|null} [visibleChainIds] - optional visible chain id filter.
|
|
203
|
+
* @returns {object} `{ [chainId]: taskIds }` selection map.
|
|
204
|
+
*/
|
|
205
|
+
export function selectCleanupCandidatesByPreset(candidates, preset = 'all', visibleChainIds = null) {
|
|
206
|
+
const visibleSet = visibleChainIds instanceof Set
|
|
207
|
+
? visibleChainIds
|
|
208
|
+
: (Array.isArray(visibleChainIds) ? new Set(visibleChainIds) : null);
|
|
209
|
+
const next = {};
|
|
210
|
+
let count = 0;
|
|
211
|
+
for (const candidate of Array.isArray(candidates) ? candidates : []) {
|
|
212
|
+
if (count >= MAX_CLEANUP_CHAINS) break;
|
|
213
|
+
if (candidate === null || typeof candidate !== 'object' || candidate.selectable !== true) continue;
|
|
214
|
+
if (visibleSet !== null && !visibleSet.has(candidate.chainId)) continue;
|
|
215
|
+
if (preset === 'accepted' && candidate.nodeStatus !== 'accepted') continue;
|
|
216
|
+
if (
|
|
217
|
+
preset === 'failed-cancelled'
|
|
218
|
+
&& candidate.nodeStatus !== 'failed'
|
|
219
|
+
&& candidate.nodeStatus !== 'cancelled'
|
|
220
|
+
&& candidate.nodeStatus !== 'interrupted'
|
|
221
|
+
) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
next[candidate.chainId] = candidate.taskIds.slice();
|
|
225
|
+
count += 1;
|
|
226
|
+
}
|
|
227
|
+
return next;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* What the confirmation says BEFORE anything is sent.
|
|
232
|
+
*
|
|
233
|
+
* The numbers are computed from the selection and the current tree, so the text can
|
|
234
|
+
* never claim more (or fewer) chains and rounds than the request will name.
|
|
235
|
+
* @param {object} selection - chain id -> selected task ids.
|
|
236
|
+
* @param {object[]} candidates - current candidates.
|
|
237
|
+
* @returns {{ chains: number, rounds: number, empty: boolean, executable: boolean, problems: string[] }} summary.
|
|
238
|
+
*/
|
|
239
|
+
export function cleanupSelectionSummary(selection, candidates) {
|
|
240
|
+
const byId = new Map(candidates.map((candidate) => [candidate.chainId, candidate]));
|
|
241
|
+
let chains = 0;
|
|
242
|
+
let rounds = 0;
|
|
243
|
+
const problems = [];
|
|
244
|
+
for (const [chainId, ids] of Object.entries(selection ?? {})) {
|
|
245
|
+
const candidate = byId.get(chainId);
|
|
246
|
+
if (candidate === undefined) {
|
|
247
|
+
problems.push('所选执行链已不在当前任务树中,请重新选择');
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (!candidate.selectable || !withSelectionState(candidate, ids).selectable) {
|
|
251
|
+
problems.push(`执行链「${candidate.title}」已不能清理:${candidate.reason ?? cleanupBlockerLabel('unknown')}`);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
chains += 1;
|
|
255
|
+
rounds += candidate.taskIds.length;
|
|
256
|
+
}
|
|
257
|
+
if (chains > MAX_CLEANUP_CHAINS) {
|
|
258
|
+
problems.push(`一次最多清理 ${MAX_CLEANUP_CHAINS} 条执行链,请分批处理`);
|
|
259
|
+
}
|
|
260
|
+
if (chains === 0 && problems.length === 0) problems.push('请先勾选要清理的执行链');
|
|
261
|
+
return { chains, rounds, empty: chains === 0, executable: problems.length === 0, problems };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Project a selection onto the exact request body the host accepts.
|
|
266
|
+
*
|
|
267
|
+
* One entry per selected chain: its id and that chain's exact task ids, in tree
|
|
268
|
+
* order. Anything that is not a selectable chain of the CURRENT tree is refused
|
|
269
|
+
* here instead of being sent and refused by the host.
|
|
270
|
+
* @param {object} selection - chain id -> selected task ids.
|
|
271
|
+
* @param {object[]} candidates - current candidates.
|
|
272
|
+
* @returns {{ body: { chains: Array<{ chainId: string, taskIds: string[] }> }, problems: string[] }} request.
|
|
273
|
+
*/
|
|
274
|
+
export function cleanupRequest(selection, candidates, options = {}) {
|
|
275
|
+
const byId = new Map(candidates.map((candidate) => [candidate.chainId, candidate]));
|
|
276
|
+
const summary = cleanupSelectionSummary(selection, candidates);
|
|
277
|
+
if (!summary.executable) return { body: { chains: [] }, problems: summary.problems };
|
|
278
|
+
const chains = [];
|
|
279
|
+
for (const [chainId] of Object.entries(selection)) {
|
|
280
|
+
const candidate = byId.get(chainId);
|
|
281
|
+
chains.push({ chainId: candidate.chainId, taskIds: candidate.taskIds.slice() });
|
|
282
|
+
}
|
|
283
|
+
const body = { chains };
|
|
284
|
+
if (options?.archiveSessions === true) body.archiveSessions = true;
|
|
285
|
+
if (options?.removeWorktrees === true) body.removeWorktrees = true;
|
|
286
|
+
if (options?.cleanPlans === true) body.cleanPlans = true;
|
|
287
|
+
return { body, problems: [] };
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Stable key so a selection survives a refresh: `chainId` -> the ids selected.
|
|
292
|
+
* @param {object[]} candidates - current candidates.
|
|
293
|
+
* @param {object} selection - chain id -> selected task ids.
|
|
294
|
+
* @returns {string} a comparable fingerprint of the selection.
|
|
295
|
+
*/
|
|
296
|
+
export function cleanupSelectionKey(candidates, selection) {
|
|
297
|
+
const parts = [];
|
|
298
|
+
for (const candidate of candidates) {
|
|
299
|
+
if (Array.isArray(selection?.[candidate.chainId])) parts.push(`${candidate.chainId}:${candidate.taskIds.join(',')}`);
|
|
300
|
+
}
|
|
301
|
+
return parts.join('|');
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* The task ids a completed deletion removed, as the host reported them.
|
|
306
|
+
*
|
|
307
|
+
* Read defensively: a host that answers `deleted: []` removed nothing and must not
|
|
308
|
+
* be shown as a success, so the caller decides from `chains`/`tasks` counts.
|
|
309
|
+
* @param {object | null} outcome - `{ chains, tasks, deletedTaskIds }`.
|
|
310
|
+
* @returns {{ chains: number, rounds: number, deletedTaskIds: string[] }} normalized counts.
|
|
311
|
+
*/
|
|
312
|
+
export function cleanupOutcome(outcome) {
|
|
313
|
+
const deleted = Array.isArray(outcome?.deletedTaskIds)
|
|
314
|
+
? outcome.deletedTaskIds.filter((id) => typeof id === 'string' && id !== '')
|
|
315
|
+
: [];
|
|
316
|
+
const chains = Number.isFinite(outcome?.chains) ? outcome.chains : 0;
|
|
317
|
+
return { chains, rounds: deleted.length, deletedTaskIds: deleted };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Plain-Chinese description of one completed cleanup.
|
|
322
|
+
* @param {object | null} outcome - the host's success body.
|
|
323
|
+
* @returns {string} one sentence; empty when nothing was removed.
|
|
324
|
+
*/
|
|
325
|
+
export function describeCleanupOutcome(outcome) {
|
|
326
|
+
const summary = cleanupOutcome(outcome);
|
|
327
|
+
if (summary.chains === 0 && summary.rounds === 0) return '';
|
|
328
|
+
const cleaned = outcome?.cleaned ?? null;
|
|
329
|
+
const retained = outcome?.retained ?? null;
|
|
330
|
+
const hasLinkedOption = cleaned !== null
|
|
331
|
+
|| (retained !== null && (
|
|
332
|
+
retained.sessions === false
|
|
333
|
+
|| retained.worktrees === false
|
|
334
|
+
|| retained.workspaces === false
|
|
335
|
+
|| retained.plans === false
|
|
336
|
+
));
|
|
337
|
+
if (!hasLinkedOption) {
|
|
338
|
+
return `已永久删除 ${summary.chains} 条执行链、共 ${summary.rounds} 轮的任务记录与审查意见;`
|
|
339
|
+
+ 'DSH 会话、工作区与源文件均未删除。';
|
|
340
|
+
}
|
|
341
|
+
const archivedCount = Array.isArray(cleaned?.archivedSessionIds) ? cleaned.archivedSessionIds.length : 0;
|
|
342
|
+
const worktreeCount = Array.isArray(cleaned?.removedWorktreePaths) ? cleaned.removedWorktreePaths.length : 0;
|
|
343
|
+
const workspaceCount = Array.isArray(cleaned?.removedWorkspaceIds) ? cleaned.removedWorkspaceIds.length : 0;
|
|
344
|
+
const planCount = Array.isArray(cleaned?.removedPlanNodeIds) ? cleaned.removedPlanNodeIds.length : 0;
|
|
345
|
+
const extras = [];
|
|
346
|
+
if (archivedCount > 0) extras.push(`归档 ${archivedCount} 个派工对话`);
|
|
347
|
+
if (worktreeCount > 0) extras.push(`清理 ${worktreeCount} 个隔离工作树`);
|
|
348
|
+
if (workspaceCount > 0) extras.push(`移除 ${workspaceCount} 个临时工作区`);
|
|
349
|
+
if (planCount > 0) extras.push(`清理 ${planCount} 个空规划节点`);
|
|
350
|
+
const linkedClause = extras.length > 0
|
|
351
|
+
? `同步${extras.join('、')};`
|
|
352
|
+
: '无额外需归档的派工对话或隔离工作树;';
|
|
353
|
+
return `已永久删除 ${summary.chains} 条执行链、共 ${summary.rounds} 轮的任务记录与审查意见;`
|
|
354
|
+
+ `${linkedClause}主项目源文件与共享工作区均未删除。`;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Plain-Chinese description of one completed orphan worktree/session sweep.
|
|
359
|
+
* @param {object | null} outcome - the host's orphan cleanup body.
|
|
360
|
+
* @returns {string} summary sentence.
|
|
361
|
+
*/
|
|
362
|
+
export function describeOrphanCleanupOutcome(outcome) {
|
|
363
|
+
if (outcome === null || typeof outcome !== 'object') return '';
|
|
364
|
+
const cleaned = outcome.cleaned ?? {};
|
|
365
|
+
const archivedCount = Array.isArray(cleaned.archivedSessionIds) ? cleaned.archivedSessionIds.length : 0;
|
|
366
|
+
const worktreeCount = Array.isArray(cleaned.removedWorktreePaths) ? cleaned.removedWorktreePaths.length : 0;
|
|
367
|
+
const workspaceCount = Array.isArray(cleaned.removedWorkspaceIds) ? cleaned.removedWorkspaceIds.length : 0;
|
|
368
|
+
const forgottenCount = Number.isFinite(outcome.orphanSessionsForgotten) ? outcome.orphanSessionsForgotten : 0;
|
|
369
|
+
if (archivedCount === 0 && worktreeCount === 0 && workspaceCount === 0 && forgottenCount === 0) {
|
|
370
|
+
return '未发现残留的隔离工作树或已删记录的派工对话;主项目源文件与共享工作区均未改动。';
|
|
371
|
+
}
|
|
372
|
+
const parts = [];
|
|
373
|
+
if (archivedCount > 0) parts.push(`归档 ${archivedCount} 个已删记录的派工对话`);
|
|
374
|
+
else if (forgottenCount > 0) parts.push(`清理 ${forgottenCount} 条残留会话映射`);
|
|
375
|
+
if (worktreeCount > 0) parts.push(`清理 ${worktreeCount} 个残留隔离工作树`);
|
|
376
|
+
if (workspaceCount > 0) parts.push(`移除 ${workspaceCount} 个临时工作区`);
|
|
377
|
+
return `已完成残留清理:${parts.join('、')};主项目源文件与共享工作区均未删除。`;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Build the confirmation dialog text before deletion is executed.
|
|
382
|
+
* @param {{ chains: number, rounds: number }} summary - selection counts.
|
|
383
|
+
* @param {{ archiveSessions?: boolean, removeWorktrees?: boolean, cleanPlans?: boolean }} [options] - linked cleanup choices.
|
|
384
|
+
* @returns {string} confirmation sentence.
|
|
385
|
+
*/
|
|
386
|
+
export function cleanupConfirmText(summary, options = {}) {
|
|
387
|
+
const archiveSessions = options?.archiveSessions === true;
|
|
388
|
+
const removeWorktrees = options?.removeWorktrees === true;
|
|
389
|
+
const cleanPlans = options?.cleanPlans === true;
|
|
390
|
+
if (!archiveSessions && !removeWorktrees && !cleanPlans) {
|
|
391
|
+
return `确认永久删除 ${summary.chains} 条执行链、共 ${summary.rounds} 轮的任务记录及审查意见?删除后无法按任务编号查询或续接。DSH 会话、工作区与源文件不会被删除。`;
|
|
392
|
+
}
|
|
393
|
+
const linked = [];
|
|
394
|
+
if (archiveSessions) linked.push('归档对应的 DSH 派工对话(不影响你自己的普通对话)');
|
|
395
|
+
if (removeWorktrees) linked.push('删除隔离任务的工作树目录与临时工作区(共享工作区绝不删除)');
|
|
396
|
+
if (cleanPlans) linked.push('清理已无关联任务的空规划节点');
|
|
397
|
+
return `确认永久删除 ${summary.chains} 条执行链、共 ${summary.rounds} 轮的任务记录及审查意见,并同时${linked.join('、')}?删除后无法按任务编号查询或续接;主项目源文件与共享工作区不会被删除。`;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* The standing warning shown next to the confirm button.
|
|
402
|
+
* @returns {string} Chinese text.
|
|
403
|
+
*/
|
|
404
|
+
export function cleanupWarningText() {
|
|
405
|
+
return '删除任务记录后不可恢复,也无法按这些任务编号查询或续接。';
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* A detached copy of the projection, for one caller that must not see bindings change.
|
|
410
|
+
* @returns {object} the projection functions plus the bound.
|
|
411
|
+
*/
|
|
412
|
+
export function cleanupProjection() {
|
|
413
|
+
return {
|
|
414
|
+
candidates: cleanupCandidates,
|
|
415
|
+
request: cleanupRequest,
|
|
416
|
+
outcome: cleanupOutcome,
|
|
417
|
+
describe: describeCleanupOutcome,
|
|
418
|
+
describeOrphans: describeOrphanCleanupOutcome,
|
|
419
|
+
confirmText: cleanupConfirmText,
|
|
420
|
+
selectByPreset: selectCleanupCandidatesByPreset,
|
|
421
|
+
selectionSummary: cleanupSelectionSummary,
|
|
422
|
+
prune: pruneCleanupSelection,
|
|
423
|
+
toggle: toggleCleanupSelection,
|
|
424
|
+
blockerLabel: cleanupBlockerLabel,
|
|
425
|
+
warning: cleanupWarningText,
|
|
426
|
+
MAX_CHAINS: MAX_CLEANUP_CHAINS,
|
|
427
|
+
PRESETS: CLEANUP_PRESETS,
|
|
428
|
+
};
|
|
429
|
+
}
|