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
@@ -20,6 +20,10 @@
20
20
  // `hostAcceptance.completionSummary` enforce <= 2000 code points on writes (never cut by fitting)
21
21
  // and truncate with markers on loads of older/external documents.
22
22
  //
23
+ // Removal is `deleteMany` only: one atomic, bounded, all-or-nothing write that the
24
+ // execution record view drives. A live record is never removed, a refused batch
25
+ // writes nothing, and a failed write leaves the stored copy visible.
26
+ //
23
27
  // On load, `pending`/`running` records become `interrupted` with
24
28
  // `error.code = JOB_INTERRUPTED_RESTART`. They are never resubmitted, and the
25
29
  // authorization that once covered them is not restored.
@@ -91,8 +95,19 @@ export const HISTORY_CODES = Object.freeze({
91
95
  limitExceeded: 'HISTORY_LIMIT_EXCEEDED',
92
96
  writeFailed: 'HISTORY_WRITE_FAILED',
93
97
  disposed: 'HISTORY_DISPOSED',
98
+ // A batch delete that cannot be honoured as one unit. Nothing is written.
99
+ deleteInvalid: 'HISTORY_DELETE_INVALID',
94
100
  });
95
101
 
102
+ /**
103
+ * Upper bound on how many records one batch delete may remove.
104
+ *
105
+ * It matches the per-entry list bound of the projection, so a batch can never be
106
+ * larger than a document's own record list; the API also caps the number of CHAINS
107
+ * per request, so the composition cannot grow with a caller's list.
108
+ */
109
+ export const HISTORY_DELETE_MAX_TASKS = 500;
110
+
96
111
  /** Windows rename races are transient: retry them briefly before refusing. */
97
112
  const WINDOWS_TRANSIENT_RENAME = new Set(['EACCES', 'EBUSY', 'EPERM']);
98
113
 
@@ -284,6 +299,21 @@ export class HistoryStore {
284
299
  merged = { ...(merged ?? entry), goalDescription: savedGoal };
285
300
  }
286
301
  }
302
+ for (const hierarchyField of ['planNodeId', 'parentNodeId']) {
303
+ const savedRef = draft[index][hierarchyField];
304
+ if (typeof savedRef === 'string' && savedRef !== '') {
305
+ const incomingRef = entry[hierarchyField];
306
+ if (incomingRef !== undefined && incomingRef !== savedRef) {
307
+ throw new HistoryError(HISTORY_CODES.viewInvalid, `a saved ${hierarchyField} cannot be replaced by a different one`, {
308
+ taskId: entry.taskId,
309
+ field: hierarchyField,
310
+ });
311
+ }
312
+ if (incomingRef !== savedRef) {
313
+ merged = { ...(merged ?? entry), [hierarchyField]: savedRef };
314
+ }
315
+ }
316
+ }
287
317
  if (merged !== null) {
288
318
  entry = projectView(merged, this.maxEntryBytes, { rejectOversizeNote: true });
289
319
  }
@@ -349,6 +379,23 @@ export class HistoryStore {
349
379
  });
350
380
  }
351
381
  }
382
+ for (const hierarchyField of ['planNodeId', 'parentNodeId']) {
383
+ const storedRef = base[index][hierarchyField];
384
+ if (typeof storedRef === 'string' && storedRef !== '') {
385
+ if (entry[hierarchyField] === undefined) {
386
+ throw new HistoryError(HISTORY_CODES.viewInvalid, `a history update may not erase ${hierarchyField}`, {
387
+ taskId,
388
+ field: hierarchyField,
389
+ });
390
+ }
391
+ if (entry[hierarchyField] !== storedRef) {
392
+ throw new HistoryError(HISTORY_CODES.viewInvalid, `a history update may not replace ${hierarchyField}`, {
393
+ taskId,
394
+ field: hierarchyField,
395
+ });
396
+ }
397
+ }
398
+ }
352
399
  const storedReview = base[index].hostAcceptance;
353
400
  const storedSummary = storedReview?.completionSummary;
354
401
  if (storedReview !== null && storedReview !== undefined) {
@@ -379,6 +426,74 @@ export class HistoryStore {
379
426
  return await run;
380
427
  }
381
428
 
429
+ /**
430
+ * Atomically delete ONE batch of TERMINAL stored records.
431
+ *
432
+ * This is the only removal path a caller may use, and it is deliberately narrow:
433
+ *
434
+ * * **All or nothing.** Every id must name a stored record that is terminal in
435
+ * the document as read INSIDE the write queue. A missing id, an id whose stored
436
+ * state is still `pending`/`running`, and a duplicate id refuse the WHOLE batch
437
+ * with `HISTORY_DELETE_INVALID` and write nothing. There is no partial success
438
+ * to report as a success.
439
+ * The write is serialized with saves and updates. The optional check runs on
440
+ * the latest rows in the queue. The store only publishes the new list after
441
+ * the temporary file replaces the old document.
442
+ *
443
+ * Deleting a history record removes the stored evidence only. It does not touch a
444
+ * DSH Workspace, a Session, a worktree, a source file or any other document.
445
+ * @param {string[]} taskIds - exact stored ids to remove.
446
+ * @param {object} [options] - synchronous `beforeWrite(rows)` and `afterWrite(ids)` hooks.
447
+ * @returns {Promise<{ deletedTaskIds: string[], remaining: number }>} outcome.
448
+ * @throws {HistoryError} `HISTORY_DELETE_INVALID` for a refused batch (nothing written),
449
+ * `HISTORY_WRITE_FAILED` when the document could not be written (nothing removed),
450
+ * or the error `beforeWrite` threw.
451
+ */
452
+ async deleteMany(taskIds, options = {}) {
453
+ if (this.disposed) throw this.disposedError();
454
+ if (this.refusal !== null) this.throwIfRefused();
455
+ const ids = requireDeleteIds(taskIds);
456
+ const beforeWrite = typeof options.beforeWrite === 'function' ? options.beforeWrite : null;
457
+ const run = this.enqueue(async () => {
458
+ this.throwIfRefused();
459
+ const base = await this.ensureLoaded();
460
+ // The re-check sees the freshest rows and the caller's own in-flight facts, so a
461
+ // batch that became unsafe while it waited is refused before anything is written.
462
+ if (beforeWrite !== null) beforeWrite(base.slice());
463
+ const byId = new Map();
464
+ for (const job of base) byId.set(job.taskId, job);
465
+ const missing = [];
466
+ const live = [];
467
+ for (const taskId of ids) {
468
+ const row = byId.get(taskId);
469
+ if (row === undefined) missing.push(taskId);
470
+ else if (!isTerminal(row.state) || row.state === 'interrupted') live.push(taskId);
471
+ }
472
+ if (missing.length > 0 || live.length > 0) {
473
+ // The ids are echoed back because the caller sent them; nothing else is.
474
+ // A refusal never rewrites the document, so the caller can re-read and retry.
475
+ throw new HistoryError(
476
+ HISTORY_CODES.deleteInvalid,
477
+ 'a history batch can only remove stored finished records that still exist',
478
+ {
479
+ missing,
480
+ live,
481
+ requested: ids.length,
482
+ limit: HISTORY_DELETE_MAX_TASKS,
483
+ },
484
+ );
485
+ }
486
+ const wanted = new Set(ids);
487
+ const draft = base.filter((job) => !wanted.has(job.taskId)).map((job) => structuredClone(job));
488
+ const now = Date.now();
489
+ await this.writeDocument(draft, now);
490
+ this.jobs = draft;
491
+ options.afterWrite?.(ids);
492
+ return { deletedTaskIds: [...ids], remaining: draft.length };
493
+ });
494
+ return await run;
495
+ }
496
+
382
497
  /**
383
498
  * Wait for the in-flight read and every queued write to settle.
384
499
  * @returns {Promise<void>} resolves when the document is consistent.
@@ -634,6 +749,8 @@ function projectView(view, maxEntryBytes, options = {}) {
634
749
  // Both are omitted when absent, so a load does not rewrite a document to add the new keys.
635
750
  const title = titleText(view.title, ctx);
636
751
  const continueFrom = continuationRef(view.continueFromTaskId, taskId);
752
+ const planNodeId = continuationRef(view.planNodeId, taskId);
753
+ const parentNodeId = continuationRef(view.parentNodeId, taskId);
637
754
  const goalDescription = descriptionText(
638
755
  view.goalDescription, ctx, TASK_DESCRIPTION_FIELDS.goal, { rejectOversize: options.rejectOversizeNote === true },
639
756
  );
@@ -642,6 +759,8 @@ function projectView(view, maxEntryBytes, options = {}) {
642
759
  state: view.state,
643
760
  ...(title === '' ? {} : { title }),
644
761
  ...(continueFrom === null ? {} : { continueFromTaskId: continueFrom }),
762
+ ...(planNodeId === null ? {} : { planNodeId }),
763
+ ...(parentNodeId === null ? {} : { parentNodeId }),
645
764
  // Only present when the commander stated a goal: nothing is derived from the prompt.
646
765
  ...(goalDescription === null ? {} : { goalDescription }),
647
766
  phase: label(view.phase),
@@ -696,6 +815,15 @@ function projectView(view, maxEntryBytes, options = {}) {
696
815
  // dispatcher made no choice, so a restored record can tell "not asked" from "asked",
697
816
  // and "applied" from "asked but unapplied".
698
817
  agentTeams: typeof view.agentTeams === 'boolean' ? view.agentTeams : null,
818
+ // WHERE that decision came from (`request` / `continuation` / `settings-default`), or
819
+ // ABSENT when there is nothing to say. Closed vocabulary, so a restored record can
820
+ // never present the operator's default as something the dispatcher asked for.
821
+ //
822
+ // Omitted rather than written as `null`, for the same reason `title` is: a stored
823
+ // record that predates the field (or never recorded a decision) must reload byte for
824
+ // byte. Writing `null` would make every such load look like a change and rewrite the
825
+ // document just to add a key that means "unknown" anyway.
826
+ ...(teamOriginView(view.agentTeamsOrigin) === null ? {} : { agentTeamsOrigin: teamOriginView(view.agentTeamsOrigin) }),
699
827
  team: teamView(view.team, ctx),
700
828
  // A completed job is not an accepted one. This is fixed, never copied.
701
829
  selfApproved: false,
@@ -760,33 +888,46 @@ function markInterrupted(entry, now) {
760
888
  function effectiveView(value) {
761
889
  if (!isPlainObject(value)) return null;
762
890
  const worker = isPlainObject(value.worker) ? value.worker : {};
763
- const review = isPlainObject(value.review) ? value.review : {};
891
+ const review = isPlainObject(value.review) ? value.review : null;
764
892
  const provenance = isPlainObject(value.provenance) ? value.provenance : {};
765
893
  return {
766
894
  worker: {
767
895
  providerId: label(worker.providerId),
768
896
  model: label(worker.model),
769
897
  reasoningEffort: label(worker.reasoningEffort),
898
+ // The legacy stored value, kept verbatim so a stored record still says what the
899
+ // document it ran under contained. It is NOT what bounded the run.
770
900
  timeoutSeconds: count(worker.timeoutSeconds),
901
+ // What the run's budget actually was: `null` means "no total execution
902
+ // deadline" (the default), a number means an explicit per-job cap. Stored as
903
+ // its own field, because reading the legacy value as the budget would state a
904
+ // limit the engine did not apply.
905
+ executionTimeoutSeconds: Number.isFinite(worker.executionTimeoutSeconds)
906
+ ? count(worker.executionTimeoutSeconds)
907
+ : null,
771
908
  maxParallelism: count(worker.maxParallelism),
772
909
  isolation: knownValue(worker.isolation, ['worktree', 'shared']),
773
910
  },
774
- review: {
775
- enabled: review.enabled === true,
776
- providerId: label(review.providerId),
777
- model: label(review.model),
778
- reasoningEffort: label(review.reasoningEffort),
779
- },
911
+ ...(review === null ? {} : {
912
+ review: {
913
+ enabled: review.enabled === true,
914
+ providerId: label(review.providerId),
915
+ model: label(review.model),
916
+ reasoningEffort: label(review.reasoningEffort),
917
+ },
918
+ }),
780
919
  // The conversation policy the task was frozen with (a rule, not a stored
781
920
  // setting) plus, in `value.conversation` below, what the run actually did. No
782
921
  // session id is stored here, so history is not a way back into a conversation.
783
922
  conversation: isPlainObject(value.conversation)
784
923
  ? { policy: label(value.conversation.policy) }
785
924
  : null,
786
- // The silence thresholds this task froze at admission. Stored because they are
787
- // the only way a stored activity block can be interpreted: "idle for 12 minutes"
788
- // means something different under a 10-minute attention threshold than under a
789
- // two-hour one, and the live settings may have changed since.
925
+ // The no-progress thresholds this task froze at admission. Stored because they are
926
+ // the only way a stored activity block can be interpreted: "no progress for 12
927
+ // minutes" means something different under a 10-minute self-check threshold than
928
+ // under a two-hour one, and the live settings may have changed since. `0` is a
929
+ // stored decision ("this reminder is off") and is preserved as such, never
930
+ // re-defaulted.
790
931
  monitoring: isPlainObject(value.monitoring)
791
932
  ? {
792
933
  selfCheckSeconds: count(value.monitoring.selfCheckSeconds),
@@ -956,7 +1097,7 @@ function usageView(value) {
956
1097
  return Object.keys(out).length === 0 ? null : out;
957
1098
  }
958
1099
 
959
- /** @returns {object | null} bounded additional-review outcome. */
1100
+ /** @returns {object | null} bounded result from a legacy model review. */
960
1101
  function reviewView(value, ctx) {
961
1102
  if (!isPlainObject(value)) return null;
962
1103
  return {
@@ -1180,6 +1321,21 @@ function teamView(value, ctx) {
1180
1321
  };
1181
1322
  }
1182
1323
 
1324
+ /**
1325
+ * Project the ORIGIN of a task's frozen Agent Teams decision for storage.
1326
+ *
1327
+ * A closed vocabulary of three words, or `null`. Anything else stored in a document
1328
+ * (a hand edit, a field written by a later build) reads back as `null` instead of
1329
+ * being echoed, so no reader can be shown a fourth "origin" this build does not
1330
+ * understand. `null` is also what a record written before this field existed
1331
+ * restores as, which is the honest answer.
1332
+ * @param {unknown} value - task `agentTeamsOrigin`.
1333
+ * @returns {'request' | 'continuation' | 'settings-default' | null} the stored origin.
1334
+ */
1335
+ function teamOriginView(value) {
1336
+ return value === 'request' || value === 'continuation' || value === 'settings-default' ? value : null;
1337
+ }
1338
+
1183
1339
  /** @param {object} value - activity summary view. @returns {object|null} bounded activity view. */
1184
1340
  function activityView(value) {
1185
1341
  if (!isPlainObject(value)) return null;
@@ -1807,6 +1963,62 @@ function isTerminal(state) {
1807
1963
  return KNOWN_STATES.has(state) && !LIVE_STATES.has(state);
1808
1964
  }
1809
1965
 
1966
+ /**
1967
+ * Validate the id list of one batch delete, without touching any document.
1968
+ *
1969
+ * The list is a SET of exact ids: a duplicate, a blank id, a non-string, an empty
1970
+ * list or one above the bound is the caller's mistake and is refused whole. Each id
1971
+ * is TRIMMED exactly like `projectView` trims a stored `taskId`, so the comparison in
1972
+ * `deleteMany` is against the same canonical form that was written — nothing else is
1973
+ * coerced, so an id this store could not have minted can never match by accident.
1974
+ * @param {unknown} taskIds - caller-supplied ids.
1975
+ * @returns {string[]} the trimmed ids, in the caller's order.
1976
+ * @throws {HistoryError} `HISTORY_DELETE_INVALID`.
1977
+ */
1978
+ function requireDeleteIds(taskIds) {
1979
+ if (!Array.isArray(taskIds)) {
1980
+ throw new HistoryError(HISTORY_CODES.deleteInvalid, 'a history batch delete needs a list of task ids', {
1981
+ field: 'taskIds',
1982
+ limit: HISTORY_DELETE_MAX_TASKS,
1983
+ });
1984
+ }
1985
+ if (taskIds.length === 0) {
1986
+ throw new HistoryError(HISTORY_CODES.deleteInvalid, 'a history batch delete needs at least one task id', {
1987
+ field: 'taskIds',
1988
+ count: 0,
1989
+ });
1990
+ }
1991
+ if (taskIds.length > HISTORY_DELETE_MAX_TASKS) {
1992
+ throw new HistoryError(HISTORY_CODES.deleteInvalid, 'a history batch delete exceeds the accepted bound', {
1993
+ field: 'taskIds',
1994
+ count: taskIds.length,
1995
+ limit: HISTORY_DELETE_MAX_TASKS,
1996
+ });
1997
+ }
1998
+ const seen = new Set();
1999
+ for (const value of taskIds) {
2000
+ if (typeof value !== 'string') {
2001
+ throw new HistoryError(HISTORY_CODES.deleteInvalid, 'every task id in a batch delete must be a bounded task id', {
2002
+ field: 'taskIds',
2003
+ });
2004
+ }
2005
+ const id = value.trim();
2006
+ if (id === '' || id.length > MAX_LABEL_CHARS) {
2007
+ throw new HistoryError(HISTORY_CODES.deleteInvalid, 'every task id in a batch delete must be a bounded task id', {
2008
+ field: 'taskIds',
2009
+ });
2010
+ }
2011
+ if (seen.has(id)) {
2012
+ throw new HistoryError(HISTORY_CODES.deleteInvalid, 'a batch delete may not repeat a task id', {
2013
+ field: 'taskIds',
2014
+ taskId: id,
2015
+ });
2016
+ }
2017
+ seen.add(id);
2018
+ }
2019
+ return [...seen];
2020
+ }
2021
+
1810
2022
  /**
1811
2023
  * Total order used on disk: creation time, then id, so serialization is stable.
1812
2024
  * @param {object} a - first entry.