dsh-taskbridge 1.5.4 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/CHANGELOG.md +80 -59
  2. package/README.md +51 -50
  3. package/THIRD_PARTY_NOTICES.txt +23 -0
  4. package/bin/dsh-delegate-mcp.d.ts +1 -0
  5. package/bin/dsh-delegate-mcp.js +1 -0
  6. package/codex/dsh-taskbridge.toml +148 -71
  7. package/docs/INTRODUCTION.md +44 -22
  8. package/docs/INTRODUCTION.zh.md +32 -26
  9. package/docs/codex-integration.md +99 -19
  10. package/docs/contracts-stage-b.md +4 -4
  11. package/docs/conversation-placement.md +25 -7
  12. package/docs/plugin-market.md +1 -1
  13. package/docs/releases/1.6.0.zh.md +11 -0
  14. package/docs/releases/1.7.0.zh.md +11 -0
  15. package/docs/runtime-compatibility.md +10 -11
  16. package/docs/silent-wait.md +69 -31
  17. package/docs/taskbridge-upgrade.md +1 -1
  18. package/docs/worker-permissions.md +11 -21
  19. package/docs/workspace-grouping.md +126 -0
  20. package/lib/client.d.ts +581 -0
  21. package/lib/client.js +332 -3461
  22. package/locale/en.json +1 -1
  23. package/locale/zh.json +1 -1
  24. package/package.json +7 -19
  25. package/src/client/api.js +895 -90
  26. package/src/client/index.jsx +1363 -296
  27. package/src/client/sidebar.jsx +862 -0
  28. package/src/client/styles.js +340 -0
  29. package/src/client/task-cleanup.js +304 -0
  30. package/src/client/task-records-table.jsx +217 -0
  31. package/src/client/task-view.js +307 -0
  32. package/src/client/workspace-groups.js +482 -0
  33. package/src/client/workspaces-browser.jsx +770 -0
  34. package/src/codex/agent-ownership.js +270 -0
  35. package/src/codex/installer.js +528 -35
  36. package/src/codex/seam.js +5 -0
  37. package/src/config/defaults.js +63 -17
  38. package/src/config/settings.js +60 -62
  39. package/src/config/validate.js +126 -71
  40. package/src/http/execution-plane.js +200 -1
  41. package/src/http/respond.js +26 -2
  42. package/src/http/user-plane.js +566 -2
  43. package/src/index.d.ts +55 -0
  44. package/src/index.js +58 -42
  45. package/src/jobs/activity.js +968 -78
  46. package/src/jobs/engine.js +1010 -230
  47. package/src/jobs/history.js +224 -12
  48. package/src/jobs/plan-store.js +1020 -0
  49. package/src/jobs/record-cleanup.js +196 -0
  50. package/src/jobs/task-display.js +73 -0
  51. package/src/jobs/task-tree.js +786 -0
  52. package/src/jobs/title.js +129 -12
  53. package/src/mcp/server.js +206 -10
  54. package/src/mcp/wait.js +64 -5
  55. package/src/runtime/agent-runner.js +101 -15
  56. package/src/runtime/worker-prompt.js +53 -0
  57. package/src/workspace/locks.js +288 -167
  58. package/docs/assets/taskbridge-workflow.en.png +0 -0
  59. package/docs/assets/taskbridge-workflow.zh.png +0 -0
  60. package/docs/releases/1.4.0-token-benchmark.zh.md +0 -40
  61. package/docs/releases/1.4.0.zh.md +0 -54
  62. package/docs/releases/1.4.1.zh.md +0 -59
  63. package/docs/releases/1.4.2.zh.md +0 -23
  64. package/docs/releases/1.5.0-token-benchmark.zh.md +0 -73
  65. package/docs/releases/1.5.0.zh.md +0 -51
  66. package/docs/releases/1.5.1.zh.md +0 -70
  67. package/docs/releases/1.5.2.zh.md +0 -30
  68. package/docs/releases/1.5.3-test.1.zh.md +0 -28
  69. package/docs/releases/1.5.3-test.2.zh.md +0 -24
  70. package/docs/releases/1.5.3.zh.md +0 -33
  71. package/docs/releases/1.5.4.zh.md +0 -25
  72. package/src/review/preset.js +0 -868
  73. package/src/review/prompts.js +0 -145
  74. package/src/review/reviewer.js +0 -933
@@ -0,0 +1,196 @@
1
+ import { buildTaskTree } from './task-tree.js';
2
+ import { HISTORY_CODES, HISTORY_DELETE_MAX_TASKS } from './history.js';
3
+
4
+ export const MAX_CLEANUP_CHAINS = 100;
5
+ const FINISHED = new Set(['awaiting-host-review', 'failed', 'cancelled']);
6
+
7
+ export const CLEANUP_CODES = Object.freeze({
8
+ invalid: 'CLEANUP_INVALID',
9
+ notFound: 'CLEANUP_CHAIN_NOT_FOUND',
10
+ stale: 'CLEANUP_STALE',
11
+ live: 'CLEANUP_CHAIN_LIVE',
12
+ notDurable: 'CLEANUP_NOT_DURABLE',
13
+ nextRound: 'CLEANUP_NEXT_ROUND',
14
+ planChildren: 'CLEANUP_PLAN_CHILDREN',
15
+ hierarchyChildren: 'CLEANUP_HIERARCHY_CHILDREN',
16
+ reviewWrite: 'CLEANUP_REVIEW_WRITE',
17
+ unavailable: 'CLEANUP_UNAVAILABLE',
18
+ failed: 'CLEANUP_FAILED',
19
+ });
20
+
21
+ class CleanupError extends Error {
22
+ constructor(code, message, details = {}) {
23
+ super(message);
24
+ this.name = 'CleanupError';
25
+ this.code = code;
26
+ this.details = details;
27
+ }
28
+ }
29
+
30
+ function invalid(message, details) {
31
+ throw new CleanupError(CLEANUP_CODES.invalid, message, details);
32
+ }
33
+
34
+ function isObject(value) {
35
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
36
+ }
37
+
38
+ function isId(value) {
39
+ return typeof value === 'string' && value.length > 0 && value.length <= 256 && value.trim() === value;
40
+ }
41
+
42
+ export function validateCleanupRequest(body) {
43
+ if (!isObject(body) || Object.keys(body).some((key) => key !== 'chains' && key !== 'confirm')) {
44
+ invalid('expected only chains and explicit confirmation');
45
+ }
46
+ if (body.confirm !== true) invalid('cleanup requires explicit confirmation', { field: 'confirm' });
47
+ if (!Array.isArray(body.chains) || body.chains.length === 0 || body.chains.length > MAX_CLEANUP_CHAINS) {
48
+ invalid('select a bounded list of execution chains', { field: 'chains', limit: MAX_CLEANUP_CHAINS });
49
+ }
50
+ const chainIds = new Set();
51
+ const taskIds = new Set();
52
+ const chains = body.chains.map((chain, index) => {
53
+ if (!isObject(chain) || Object.keys(chain).some((key) => key !== 'chainId' && key !== 'taskIds') || !isId(chain.chainId)) {
54
+ invalid('expected a chain id and its exact rounds', { index });
55
+ }
56
+ if (chainIds.has(chain.chainId)) invalid('duplicate chain id', { index });
57
+ chainIds.add(chain.chainId);
58
+ if (!Array.isArray(chain.taskIds) || chain.taskIds.length === 0) invalid('select the complete chain', { index });
59
+ for (const id of chain.taskIds) {
60
+ if (!isId(id) || taskIds.has(id)) invalid('expected unique task ids', { index });
61
+ taskIds.add(id);
62
+ if (taskIds.size > HISTORY_DELETE_MAX_TASKS) invalid('too many rounds for one batch', { limit: HISTORY_DELETE_MAX_TASKS });
63
+ }
64
+ return { chainId: chain.chainId, taskIds: [...chain.taskIds] };
65
+ });
66
+ return { chains };
67
+ }
68
+
69
+ function planStore(deps) {
70
+ return deps.plans ?? deps.engine?.plans ?? null;
71
+ }
72
+
73
+ function collectChains(node, byChain) {
74
+ for (const chain of node.chain ? [node.chain] : node.executions ?? []) byChain.set(chain.chainId, chain);
75
+ for (const child of node.children) collectChains(child, byChain);
76
+ }
77
+
78
+ function cleanupContext(engine, archived, plans) {
79
+ const live = engine?.list?.() ?? [];
80
+ const liveById = new Map(live.map((row) => [row.taskId, row]));
81
+ const archivedById = new Map(archived.map((row) => [row.taskId, row]));
82
+ const tasks = new Map([...archivedById, ...liveById]);
83
+ const continuations = new Map();
84
+ const taskChildren = new Map();
85
+ const planParents = new Set(plans.map((node) => node.parentNodeId));
86
+ const remember = (map, parent, child) => {
87
+ if (typeof parent !== 'string' || parent === '' || parent === child) return;
88
+ if (!map.has(parent)) map.set(parent, new Set());
89
+ map.get(parent).add(child);
90
+ };
91
+ for (const row of [...archived, ...live]) {
92
+ remember(continuations, row.continueFromTaskId, row.taskId);
93
+ remember(taskChildren, row.parentNodeId, row.taskId);
94
+ remember(taskChildren, row.planNodeId, row.taskId);
95
+ }
96
+ const tree = buildTaskTree({ planNodes: plans, tasks: [...tasks.values()] });
97
+ const byChain = new Map();
98
+ for (const root of tree.roots) collectChains(root, byChain);
99
+ return { byChain, liveById, archivedById, continuations, taskChildren, planParents, engine };
100
+ }
101
+
102
+ function blockersFor(chain, context) {
103
+ const blockers = new Set();
104
+ const members = new Set(chain.taskIds);
105
+ for (const taskId of members) {
106
+ const live = context.liveById.get(taskId);
107
+ const archived = context.archivedById.get(taskId);
108
+ if ((live && !FINISHED.has(live.state)) || (archived && !FINISHED.has(archived.state))) {
109
+ blockers.add(CLEANUP_CODES.live);
110
+ } else if (!archived || (live && !context.engine.isTaskSettledForCleanup?.(taskId))) {
111
+ blockers.add(CLEANUP_CODES.notDurable);
112
+ }
113
+ if (context.engine?.reviewWriteDone?.(taskId)) blockers.add(CLEANUP_CODES.reviewWrite);
114
+ for (const child of context.continuations.get(taskId) ?? []) {
115
+ if (!members.has(child)) blockers.add(CLEANUP_CODES.nextRound);
116
+ }
117
+ for (const child of context.taskChildren.get(taskId) ?? []) {
118
+ if (!members.has(child)) blockers.add(CLEANUP_CODES.hierarchyChildren);
119
+ }
120
+ if (context.planParents.has(taskId)) blockers.add(CLEANUP_CODES.planChildren);
121
+ }
122
+ return [...blockers];
123
+ }
124
+
125
+ export async function cleanupOverview(deps) {
126
+ const archived = await deps.history.load();
127
+ const plans = await planStore(deps)?.load() ?? [];
128
+ const context = cleanupContext(deps.engine, archived, plans);
129
+ const chains = [...context.byChain.values()].map((chain) => {
130
+ const blockers = blockersFor(chain, context);
131
+ return { chainId: chain.chainId, taskIds: [...chain.taskIds], eligible: blockers.length === 0, blockers };
132
+ });
133
+ return { chains };
134
+ }
135
+
136
+ function checkBatch(chains, context) {
137
+ const refused = [];
138
+ for (const { chainId, taskIds } of chains) {
139
+ const chain = context.byChain.get(chainId);
140
+ let blockers;
141
+ if (!chain) blockers = [CLEANUP_CODES.notFound];
142
+ else if (chain.taskIds.length !== taskIds.length || chain.taskIds.some((id, i) => id !== taskIds[i])) {
143
+ blockers = [CLEANUP_CODES.stale];
144
+ } else blockers = blockersFor(chain, context);
145
+ if (blockers.length) refused.push({ chainId, code: blockers[0], blockers });
146
+ }
147
+ if (refused.length) {
148
+ throw new CleanupError(refused[0].code, 'the selected chains cannot be removed as one batch', {
149
+ chains: refused, reason: refused[0].code, deleted: 0,
150
+ });
151
+ }
152
+ }
153
+
154
+ export async function runCleanup(deps, body) {
155
+ const { chains } = validateCleanupRequest(body);
156
+ const store = deps.history;
157
+ const plans = planStore(deps);
158
+ const engine = deps.engine;
159
+ if (typeof store?.deleteMany !== 'function' || (plans && typeof plans.withStableNodes !== 'function')) {
160
+ throw new CleanupError(CLEANUP_CODES.unavailable, 'task record cleanup is unavailable');
161
+ }
162
+ const ids = chains.flatMap((chain) => chain.taskIds);
163
+ const deleteRecords = async (planNodes) => {
164
+ let release;
165
+ try {
166
+ return await store.deleteMany(ids, {
167
+ beforeWrite(archived) {
168
+ // Read the latest engine state inside the history queue. No asynchronous
169
+ // work may run between checking relationships and reserving these ids.
170
+ checkBatch(chains, cleanupContext(engine, archived, planNodes));
171
+ release = engine?.reserveCleanupIds(ids);
172
+ },
173
+ afterWrite(deletedIds) {
174
+ engine?.forgetCleanedRecords(deletedIds);
175
+ },
176
+ });
177
+ } finally {
178
+ release?.();
179
+ }
180
+ };
181
+ let result;
182
+ try {
183
+ result = plans ? await plans.withStableNodes(deleteRecords) : await deleteRecords([]);
184
+ } catch (error) {
185
+ if (error instanceof CleanupError) throw error;
186
+ const code = error?.code === HISTORY_CODES.deleteInvalid ? CLEANUP_CODES.stale
187
+ : error?.code === HISTORY_CODES.writeFailed ? CLEANUP_CODES.failed : CLEANUP_CODES.unavailable;
188
+ throw new CleanupError(code, 'the task records could not be removed', { deleted: 0 });
189
+ }
190
+ return {
191
+ chains: chains.length,
192
+ tasks: result.deletedTaskIds.length,
193
+ ...result,
194
+ retained: { sessions: true, workspaces: true, worktrees: true, sourceFiles: true, plans: true },
195
+ };
196
+ }
@@ -0,0 +1,73 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { JsonDocument } from '../config/store.js';
3
+
4
+ const MAX_ARCHIVES = 2048;
5
+ const ARCHIVABLE = 'accepted';
6
+
7
+ function chainsOf(node) {
8
+ return node.kind === 'plan' ? node.executions : [node.chain];
9
+ }
10
+
11
+ // Hash only the facts that made this subtree eligible. A continuation, a changed
12
+ // review or a missing history entry brings the subtree back into the active view.
13
+ function activityStamp(node) {
14
+ const evidence = [node.nodeId, node.nodeStatus, node.hostAcceptance?.acceptedAt ?? null];
15
+ for (const chain of chainsOf(node)) {
16
+ evidence.push(chain.rounds.map((round) => [round.taskId, round.state, round.hostAcceptance?.acceptedAt ?? null]));
17
+ }
18
+ evidence.push(node.children.map(activityStamp));
19
+ return createHash('sha256').update(JSON.stringify(evidence)).digest('hex');
20
+ }
21
+
22
+ export function findDisplayNode(roots, nodeId) {
23
+ const remaining = [...roots];
24
+ while (remaining.length > 0) {
25
+ const node = remaining.pop();
26
+ if (node.nodeId === nodeId) return node;
27
+ remaining.push(...node.children);
28
+ }
29
+ return null;
30
+ }
31
+
32
+ export class TaskDisplayStore extends JsonDocument {
33
+ constructor(dataDir) {
34
+ super(dataDir, 'task-display.json', {
35
+ schemaVersion: 1,
36
+ initial: () => ({ schemaVersion: 1, archives: {} }),
37
+ });
38
+ }
39
+
40
+ async project(tree) {
41
+ const { archives } = await this.load();
42
+ if (!archives || typeof archives !== 'object' || Array.isArray(archives)) throw new Error('invalid display archive');
43
+ const hidden = new Set();
44
+ const visit = (node) => {
45
+ node.displayArchived = node.nodeStatus === ARCHIVABLE
46
+ && Object.hasOwn(archives, node.nodeId)
47
+ && archives[node.nodeId] === activityStamp(node);
48
+ if (node.displayArchived) hidden.add(node.nodeId);
49
+ for (const child of node.children) visit(child);
50
+ };
51
+ for (const root of tree.roots) visit(root);
52
+ for (const node of tree.flatNodes) node.displayArchived = hidden.has(node.nodeId);
53
+ }
54
+
55
+ async setArchived(node, archived, knownIds) {
56
+ if (archived && node.nodeStatus !== ARCHIVABLE) return { conflict: 'TASK_DISPLAY_NOT_ACCEPTED' };
57
+ let limitReached = false;
58
+ await this.commit((draft) => {
59
+ if (!draft.archives || typeof draft.archives !== 'object' || Array.isArray(draft.archives)) throw new Error('invalid display archive');
60
+ for (const id of Object.keys(draft.archives)) {
61
+ if (!knownIds.has(id)) delete draft.archives[id];
62
+ }
63
+ if (!archived) {
64
+ delete draft.archives[node.nodeId];
65
+ } else if (Object.hasOwn(draft.archives, node.nodeId) || Object.keys(draft.archives).length < MAX_ARCHIVES) {
66
+ Object.defineProperty(draft.archives, node.nodeId, { value: activityStamp(node), enumerable: true, configurable: true, writable: true });
67
+ } else {
68
+ limitReached = true;
69
+ }
70
+ });
71
+ return limitReached ? { conflict: 'TASK_DISPLAY_LIMIT' } : { archived };
72
+ }
73
+ }