dsh-taskbridge 1.7.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -21
- package/README.md +149 -290
- package/THIRD_PARTY_NOTICES.txt +23 -23
- package/antigravity/agents/dsh-taskbridge.md +31 -0
- package/antigravity/skills/dsh-taskbridge/SKILL.md +51 -0
- package/codex/dsh-taskbridge.toml +170 -631
- package/cordis.patch.yml +6 -6
- package/docs/INTRODUCTION.md +119 -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/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/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 +733 -699
- package/lib/client.js +7 -7
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +149 -144
- package/src/antigravity/installer.js +1046 -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 +143 -0
- package/src/client/index.jsx +113 -3
- package/src/client/sidebar.jsx +862 -862
- package/src/client/styles.js +624 -624
- package/src/client/task-cleanup.js +304 -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 +3 -0
- package/src/codex/toml.js +784 -784
- 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 +72 -0
- package/src/index.js +25 -0
- package/src/jobs/diagnostics.js +15 -15
- package/src/jobs/plan-store.js +1020 -1020
- 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 +4 -1
- 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/permissions.js +1619 -1619
- package/src/runtime/question-call.js +162 -162
- package/src/runtime/questions.js +909 -909
- package/src/runtime/worker-prompt.js +60 -55
- package/src/workspace/audit.js +775 -775
- package/src/workspace/preflight.js +424 -424
- package/src/workspace/worktrees.js +679 -679
|
@@ -1,304 +1,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
|
-
selectable,
|
|
99
|
-
blockers,
|
|
100
|
-
reason: selectable
|
|
101
|
-
? null
|
|
102
|
-
: (blockers.length > 0
|
|
103
|
-
? blockers.map(cleanupBlockerLabel).join(';')
|
|
104
|
-
: cleanupBlockerLabel('unknown')),
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
for (const child of Array.isArray(node?.children) ? node.children : []) walk(child);
|
|
108
|
-
};
|
|
109
|
-
for (const root of Array.isArray(view?.roots) ? view.roots : []) walk(root);
|
|
110
|
-
return out;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* The cleanup state of one candidate after a refresh.
|
|
115
|
-
*
|
|
116
|
-
* `selection-stale` is the one blocker this module adds: the operator selected a
|
|
117
|
-
* chain, a background refresh replaced the tree, and the chain's rounds are no
|
|
118
|
-
* longer exactly what was selected. Sending it anyway would delete a round the
|
|
119
|
-
* operator never saw, so it is made unselectable instead.
|
|
120
|
-
* @param {object} candidate - entry from {@link cleanupCandidates}.
|
|
121
|
-
* @param {string[]} selectedTaskIds - the ids that were selected for this chain.
|
|
122
|
-
* @returns {object} the candidate, possibly with an added `selection-stale` blocker.
|
|
123
|
-
*/
|
|
124
|
-
export function withSelectionState(candidate, selectedTaskIds) {
|
|
125
|
-
if (!Array.isArray(selectedTaskIds) || !candidate.selectable) return candidate;
|
|
126
|
-
const same = selectedTaskIds.length === candidate.taskIds.length
|
|
127
|
-
&& selectedTaskIds.every((id, index) => id === candidate.taskIds[index]);
|
|
128
|
-
if (same) return candidate;
|
|
129
|
-
const blockers = [...candidate.blockers, 'selection-stale'];
|
|
130
|
-
return {
|
|
131
|
-
...candidate,
|
|
132
|
-
selectable: false,
|
|
133
|
-
blockers,
|
|
134
|
-
reason: blockers.map(cleanupBlockerLabel).join(';'),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Drop selections that no longer name a selectable chain of the current tree.
|
|
140
|
-
*
|
|
141
|
-
* Kept as a pure function so the page can run it on every render: a selection is
|
|
142
|
-
* `{ [chainId]: taskIds }`, and anything this returns is safe to send.
|
|
143
|
-
* @param {object} selection - chain id -> selected task ids.
|
|
144
|
-
* @param {object[]} candidates - current candidates.
|
|
145
|
-
* @returns {{ selection: object, dropped: string[] }} the surviving selection and the ids dropped.
|
|
146
|
-
*/
|
|
147
|
-
export function pruneCleanupSelection(selection, candidates) {
|
|
148
|
-
const byId = new Map(candidates.map((candidate) => [candidate.chainId, candidate]));
|
|
149
|
-
const next = {};
|
|
150
|
-
const dropped = [];
|
|
151
|
-
for (const [chainId, ids] of Object.entries(selection ?? {})) {
|
|
152
|
-
const candidate = byId.get(chainId);
|
|
153
|
-
if (candidate === undefined || !candidate.selectable) {
|
|
154
|
-
dropped.push(chainId);
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
const checked = withSelectionState(candidate, ids);
|
|
158
|
-
if (!checked.selectable) {
|
|
159
|
-
dropped.push(chainId);
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
next[chainId] = candidate.taskIds.slice();
|
|
163
|
-
}
|
|
164
|
-
return { selection: next, dropped };
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Toggle one chain in a selection.
|
|
169
|
-
* @param {object} selection - chain id -> selected task ids.
|
|
170
|
-
* @param {object} candidate - the chain to toggle.
|
|
171
|
-
* @returns {object} the new selection (a new object; the input is not mutated).
|
|
172
|
-
*/
|
|
173
|
-
export function toggleCleanupSelection(selection, candidate) {
|
|
174
|
-
const next = { ...(selection ?? {}) };
|
|
175
|
-
if (candidate === null || typeof candidate !== 'object' || candidate.selectable !== true) return next;
|
|
176
|
-
if (Array.isArray(next[candidate.chainId])) delete next[candidate.chainId];
|
|
177
|
-
else next[candidate.chainId] = candidate.taskIds.slice();
|
|
178
|
-
return next;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* What the confirmation says BEFORE anything is sent.
|
|
183
|
-
*
|
|
184
|
-
* The numbers are computed from the selection and the current tree, so the text can
|
|
185
|
-
* never claim more (or fewer) chains and rounds than the request will name.
|
|
186
|
-
* @param {object} selection - chain id -> selected task ids.
|
|
187
|
-
* @param {object[]} candidates - current candidates.
|
|
188
|
-
* @returns {{ chains: number, rounds: number, empty: boolean, executable: boolean, problems: string[] }} summary.
|
|
189
|
-
*/
|
|
190
|
-
export function cleanupSelectionSummary(selection, candidates) {
|
|
191
|
-
const byId = new Map(candidates.map((candidate) => [candidate.chainId, candidate]));
|
|
192
|
-
let chains = 0;
|
|
193
|
-
let rounds = 0;
|
|
194
|
-
const problems = [];
|
|
195
|
-
for (const [chainId, ids] of Object.entries(selection ?? {})) {
|
|
196
|
-
const candidate = byId.get(chainId);
|
|
197
|
-
if (candidate === undefined) {
|
|
198
|
-
problems.push('所选执行链已不在当前任务树中,请重新选择');
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
if (!candidate.selectable || !withSelectionState(candidate, ids).selectable) {
|
|
202
|
-
problems.push(`执行链「${candidate.title}」已不能清理:${candidate.reason ?? cleanupBlockerLabel('unknown')}`);
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
chains += 1;
|
|
206
|
-
rounds += candidate.taskIds.length;
|
|
207
|
-
}
|
|
208
|
-
if (chains > MAX_CLEANUP_CHAINS) {
|
|
209
|
-
problems.push(`一次最多清理 ${MAX_CLEANUP_CHAINS} 条执行链,请分批处理`);
|
|
210
|
-
}
|
|
211
|
-
if (chains === 0 && problems.length === 0) problems.push('请先勾选要清理的执行链');
|
|
212
|
-
return { chains, rounds, empty: chains === 0, executable: problems.length === 0, problems };
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Project a selection onto the exact request body the host accepts.
|
|
217
|
-
*
|
|
218
|
-
* One entry per selected chain: its id and that chain's exact task ids, in tree
|
|
219
|
-
* order. Anything that is not a selectable chain of the CURRENT tree is refused
|
|
220
|
-
* here instead of being sent and refused by the host.
|
|
221
|
-
* @param {object} selection - chain id -> selected task ids.
|
|
222
|
-
* @param {object[]} candidates - current candidates.
|
|
223
|
-
* @returns {{ body: { chains: Array<{ chainId: string, taskIds: string[] }> }, problems: string[] }} request.
|
|
224
|
-
*/
|
|
225
|
-
export function cleanupRequest(selection, candidates) {
|
|
226
|
-
const byId = new Map(candidates.map((candidate) => [candidate.chainId, candidate]));
|
|
227
|
-
const summary = cleanupSelectionSummary(selection, candidates);
|
|
228
|
-
if (!summary.executable) return { body: { chains: [] }, problems: summary.problems };
|
|
229
|
-
const chains = [];
|
|
230
|
-
for (const [chainId, ids] of Object.entries(selection)) {
|
|
231
|
-
const candidate = byId.get(chainId);
|
|
232
|
-
chains.push({ chainId: candidate.chainId, taskIds: candidate.taskIds.slice() });
|
|
233
|
-
}
|
|
234
|
-
return { body: { chains }, problems: [] };
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Stable key so a selection survives a refresh: `chainId` -> the ids selected.
|
|
239
|
-
* @param {object[]} candidates - current candidates.
|
|
240
|
-
* @param {object} selection - chain id -> selected task ids.
|
|
241
|
-
* @returns {string} a comparable fingerprint of the selection.
|
|
242
|
-
*/
|
|
243
|
-
export function cleanupSelectionKey(candidates, selection) {
|
|
244
|
-
const parts = [];
|
|
245
|
-
for (const candidate of candidates) {
|
|
246
|
-
if (Array.isArray(selection?.[candidate.chainId])) parts.push(`${candidate.chainId}:${candidate.taskIds.join(',')}`);
|
|
247
|
-
}
|
|
248
|
-
return parts.join('|');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* The task ids a completed deletion removed, as the host reported them.
|
|
253
|
-
*
|
|
254
|
-
* Read defensively: a host that answers `deleted: []` removed nothing and must not
|
|
255
|
-
* be shown as a success, so the caller decides from `chains`/`tasks` counts.
|
|
256
|
-
* @param {object | null} outcome - `{ chains, tasks, deletedTaskIds }`.
|
|
257
|
-
* @returns {{ chains: number, rounds: number, deletedTaskIds: string[] }} normalized counts.
|
|
258
|
-
*/
|
|
259
|
-
export function cleanupOutcome(outcome) {
|
|
260
|
-
const deleted = Array.isArray(outcome?.deletedTaskIds)
|
|
261
|
-
? outcome.deletedTaskIds.filter((id) => typeof id === 'string' && id !== '')
|
|
262
|
-
: [];
|
|
263
|
-
const chains = Number.isFinite(outcome?.chains) ? outcome.chains : 0;
|
|
264
|
-
return { chains, rounds: deleted.length, deletedTaskIds: deleted };
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Plain-Chinese description of one completed cleanup.
|
|
269
|
-
* @param {object | null} outcome - the host's success body.
|
|
270
|
-
* @returns {string} one sentence; empty when nothing was removed.
|
|
271
|
-
*/
|
|
272
|
-
export function describeCleanupOutcome(outcome) {
|
|
273
|
-
const summary = cleanupOutcome(outcome);
|
|
274
|
-
if (summary.chains === 0 && summary.rounds === 0) return '';
|
|
275
|
-
return `已永久删除 ${summary.chains} 条执行链、共 ${summary.rounds} 轮的任务记录与审查意见;`
|
|
276
|
-
+ 'DSH 会话、工作区与源文件均未删除。';
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* The standing warning shown next to the confirm button.
|
|
281
|
-
* @returns {string} Chinese text.
|
|
282
|
-
*/
|
|
283
|
-
export function cleanupWarningText() {
|
|
284
|
-
return '删除任务记录后不可恢复,也无法按这些任务编号查询或续接。';
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* A detached copy of the projection, for one caller that must not see bindings change.
|
|
289
|
-
* @returns {object} the seven functions plus the bound.
|
|
290
|
-
*/
|
|
291
|
-
export function cleanupProjection() {
|
|
292
|
-
return {
|
|
293
|
-
candidates: cleanupCandidates,
|
|
294
|
-
request: cleanupRequest,
|
|
295
|
-
outcome: cleanupOutcome,
|
|
296
|
-
describe: describeCleanupOutcome,
|
|
297
|
-
selectionSummary: cleanupSelectionSummary,
|
|
298
|
-
prune: pruneCleanupSelection,
|
|
299
|
-
toggle: toggleCleanupSelection,
|
|
300
|
-
blockerLabel: cleanupBlockerLabel,
|
|
301
|
-
warning: cleanupWarningText,
|
|
302
|
-
MAX_CHAINS: MAX_CLEANUP_CHAINS,
|
|
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
|
+
selectable,
|
|
99
|
+
blockers,
|
|
100
|
+
reason: selectable
|
|
101
|
+
? null
|
|
102
|
+
: (blockers.length > 0
|
|
103
|
+
? blockers.map(cleanupBlockerLabel).join(';')
|
|
104
|
+
: cleanupBlockerLabel('unknown')),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
for (const child of Array.isArray(node?.children) ? node.children : []) walk(child);
|
|
108
|
+
};
|
|
109
|
+
for (const root of Array.isArray(view?.roots) ? view.roots : []) walk(root);
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The cleanup state of one candidate after a refresh.
|
|
115
|
+
*
|
|
116
|
+
* `selection-stale` is the one blocker this module adds: the operator selected a
|
|
117
|
+
* chain, a background refresh replaced the tree, and the chain's rounds are no
|
|
118
|
+
* longer exactly what was selected. Sending it anyway would delete a round the
|
|
119
|
+
* operator never saw, so it is made unselectable instead.
|
|
120
|
+
* @param {object} candidate - entry from {@link cleanupCandidates}.
|
|
121
|
+
* @param {string[]} selectedTaskIds - the ids that were selected for this chain.
|
|
122
|
+
* @returns {object} the candidate, possibly with an added `selection-stale` blocker.
|
|
123
|
+
*/
|
|
124
|
+
export function withSelectionState(candidate, selectedTaskIds) {
|
|
125
|
+
if (!Array.isArray(selectedTaskIds) || !candidate.selectable) return candidate;
|
|
126
|
+
const same = selectedTaskIds.length === candidate.taskIds.length
|
|
127
|
+
&& selectedTaskIds.every((id, index) => id === candidate.taskIds[index]);
|
|
128
|
+
if (same) return candidate;
|
|
129
|
+
const blockers = [...candidate.blockers, 'selection-stale'];
|
|
130
|
+
return {
|
|
131
|
+
...candidate,
|
|
132
|
+
selectable: false,
|
|
133
|
+
blockers,
|
|
134
|
+
reason: blockers.map(cleanupBlockerLabel).join(';'),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Drop selections that no longer name a selectable chain of the current tree.
|
|
140
|
+
*
|
|
141
|
+
* Kept as a pure function so the page can run it on every render: a selection is
|
|
142
|
+
* `{ [chainId]: taskIds }`, and anything this returns is safe to send.
|
|
143
|
+
* @param {object} selection - chain id -> selected task ids.
|
|
144
|
+
* @param {object[]} candidates - current candidates.
|
|
145
|
+
* @returns {{ selection: object, dropped: string[] }} the surviving selection and the ids dropped.
|
|
146
|
+
*/
|
|
147
|
+
export function pruneCleanupSelection(selection, candidates) {
|
|
148
|
+
const byId = new Map(candidates.map((candidate) => [candidate.chainId, candidate]));
|
|
149
|
+
const next = {};
|
|
150
|
+
const dropped = [];
|
|
151
|
+
for (const [chainId, ids] of Object.entries(selection ?? {})) {
|
|
152
|
+
const candidate = byId.get(chainId);
|
|
153
|
+
if (candidate === undefined || !candidate.selectable) {
|
|
154
|
+
dropped.push(chainId);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const checked = withSelectionState(candidate, ids);
|
|
158
|
+
if (!checked.selectable) {
|
|
159
|
+
dropped.push(chainId);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
next[chainId] = candidate.taskIds.slice();
|
|
163
|
+
}
|
|
164
|
+
return { selection: next, dropped };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Toggle one chain in a selection.
|
|
169
|
+
* @param {object} selection - chain id -> selected task ids.
|
|
170
|
+
* @param {object} candidate - the chain to toggle.
|
|
171
|
+
* @returns {object} the new selection (a new object; the input is not mutated).
|
|
172
|
+
*/
|
|
173
|
+
export function toggleCleanupSelection(selection, candidate) {
|
|
174
|
+
const next = { ...(selection ?? {}) };
|
|
175
|
+
if (candidate === null || typeof candidate !== 'object' || candidate.selectable !== true) return next;
|
|
176
|
+
if (Array.isArray(next[candidate.chainId])) delete next[candidate.chainId];
|
|
177
|
+
else next[candidate.chainId] = candidate.taskIds.slice();
|
|
178
|
+
return next;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* What the confirmation says BEFORE anything is sent.
|
|
183
|
+
*
|
|
184
|
+
* The numbers are computed from the selection and the current tree, so the text can
|
|
185
|
+
* never claim more (or fewer) chains and rounds than the request will name.
|
|
186
|
+
* @param {object} selection - chain id -> selected task ids.
|
|
187
|
+
* @param {object[]} candidates - current candidates.
|
|
188
|
+
* @returns {{ chains: number, rounds: number, empty: boolean, executable: boolean, problems: string[] }} summary.
|
|
189
|
+
*/
|
|
190
|
+
export function cleanupSelectionSummary(selection, candidates) {
|
|
191
|
+
const byId = new Map(candidates.map((candidate) => [candidate.chainId, candidate]));
|
|
192
|
+
let chains = 0;
|
|
193
|
+
let rounds = 0;
|
|
194
|
+
const problems = [];
|
|
195
|
+
for (const [chainId, ids] of Object.entries(selection ?? {})) {
|
|
196
|
+
const candidate = byId.get(chainId);
|
|
197
|
+
if (candidate === undefined) {
|
|
198
|
+
problems.push('所选执行链已不在当前任务树中,请重新选择');
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (!candidate.selectable || !withSelectionState(candidate, ids).selectable) {
|
|
202
|
+
problems.push(`执行链「${candidate.title}」已不能清理:${candidate.reason ?? cleanupBlockerLabel('unknown')}`);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
chains += 1;
|
|
206
|
+
rounds += candidate.taskIds.length;
|
|
207
|
+
}
|
|
208
|
+
if (chains > MAX_CLEANUP_CHAINS) {
|
|
209
|
+
problems.push(`一次最多清理 ${MAX_CLEANUP_CHAINS} 条执行链,请分批处理`);
|
|
210
|
+
}
|
|
211
|
+
if (chains === 0 && problems.length === 0) problems.push('请先勾选要清理的执行链');
|
|
212
|
+
return { chains, rounds, empty: chains === 0, executable: problems.length === 0, problems };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Project a selection onto the exact request body the host accepts.
|
|
217
|
+
*
|
|
218
|
+
* One entry per selected chain: its id and that chain's exact task ids, in tree
|
|
219
|
+
* order. Anything that is not a selectable chain of the CURRENT tree is refused
|
|
220
|
+
* here instead of being sent and refused by the host.
|
|
221
|
+
* @param {object} selection - chain id -> selected task ids.
|
|
222
|
+
* @param {object[]} candidates - current candidates.
|
|
223
|
+
* @returns {{ body: { chains: Array<{ chainId: string, taskIds: string[] }> }, problems: string[] }} request.
|
|
224
|
+
*/
|
|
225
|
+
export function cleanupRequest(selection, candidates) {
|
|
226
|
+
const byId = new Map(candidates.map((candidate) => [candidate.chainId, candidate]));
|
|
227
|
+
const summary = cleanupSelectionSummary(selection, candidates);
|
|
228
|
+
if (!summary.executable) return { body: { chains: [] }, problems: summary.problems };
|
|
229
|
+
const chains = [];
|
|
230
|
+
for (const [chainId, ids] of Object.entries(selection)) {
|
|
231
|
+
const candidate = byId.get(chainId);
|
|
232
|
+
chains.push({ chainId: candidate.chainId, taskIds: candidate.taskIds.slice() });
|
|
233
|
+
}
|
|
234
|
+
return { body: { chains }, problems: [] };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Stable key so a selection survives a refresh: `chainId` -> the ids selected.
|
|
239
|
+
* @param {object[]} candidates - current candidates.
|
|
240
|
+
* @param {object} selection - chain id -> selected task ids.
|
|
241
|
+
* @returns {string} a comparable fingerprint of the selection.
|
|
242
|
+
*/
|
|
243
|
+
export function cleanupSelectionKey(candidates, selection) {
|
|
244
|
+
const parts = [];
|
|
245
|
+
for (const candidate of candidates) {
|
|
246
|
+
if (Array.isArray(selection?.[candidate.chainId])) parts.push(`${candidate.chainId}:${candidate.taskIds.join(',')}`);
|
|
247
|
+
}
|
|
248
|
+
return parts.join('|');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The task ids a completed deletion removed, as the host reported them.
|
|
253
|
+
*
|
|
254
|
+
* Read defensively: a host that answers `deleted: []` removed nothing and must not
|
|
255
|
+
* be shown as a success, so the caller decides from `chains`/`tasks` counts.
|
|
256
|
+
* @param {object | null} outcome - `{ chains, tasks, deletedTaskIds }`.
|
|
257
|
+
* @returns {{ chains: number, rounds: number, deletedTaskIds: string[] }} normalized counts.
|
|
258
|
+
*/
|
|
259
|
+
export function cleanupOutcome(outcome) {
|
|
260
|
+
const deleted = Array.isArray(outcome?.deletedTaskIds)
|
|
261
|
+
? outcome.deletedTaskIds.filter((id) => typeof id === 'string' && id !== '')
|
|
262
|
+
: [];
|
|
263
|
+
const chains = Number.isFinite(outcome?.chains) ? outcome.chains : 0;
|
|
264
|
+
return { chains, rounds: deleted.length, deletedTaskIds: deleted };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Plain-Chinese description of one completed cleanup.
|
|
269
|
+
* @param {object | null} outcome - the host's success body.
|
|
270
|
+
* @returns {string} one sentence; empty when nothing was removed.
|
|
271
|
+
*/
|
|
272
|
+
export function describeCleanupOutcome(outcome) {
|
|
273
|
+
const summary = cleanupOutcome(outcome);
|
|
274
|
+
if (summary.chains === 0 && summary.rounds === 0) return '';
|
|
275
|
+
return `已永久删除 ${summary.chains} 条执行链、共 ${summary.rounds} 轮的任务记录与审查意见;`
|
|
276
|
+
+ 'DSH 会话、工作区与源文件均未删除。';
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* The standing warning shown next to the confirm button.
|
|
281
|
+
* @returns {string} Chinese text.
|
|
282
|
+
*/
|
|
283
|
+
export function cleanupWarningText() {
|
|
284
|
+
return '删除任务记录后不可恢复,也无法按这些任务编号查询或续接。';
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* A detached copy of the projection, for one caller that must not see bindings change.
|
|
289
|
+
* @returns {object} the seven functions plus the bound.
|
|
290
|
+
*/
|
|
291
|
+
export function cleanupProjection() {
|
|
292
|
+
return {
|
|
293
|
+
candidates: cleanupCandidates,
|
|
294
|
+
request: cleanupRequest,
|
|
295
|
+
outcome: cleanupOutcome,
|
|
296
|
+
describe: describeCleanupOutcome,
|
|
297
|
+
selectionSummary: cleanupSelectionSummary,
|
|
298
|
+
prune: pruneCleanupSelection,
|
|
299
|
+
toggle: toggleCleanupSelection,
|
|
300
|
+
blockerLabel: cleanupBlockerLabel,
|
|
301
|
+
warning: cleanupWarningText,
|
|
302
|
+
MAX_CHAINS: MAX_CLEANUP_CHAINS,
|
|
303
|
+
};
|
|
304
|
+
}
|