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
@@ -8,9 +8,8 @@
8
8
  // acquired afterwards is disposed instead of driven;
9
9
  // 2. the agent-preset mount, because an Agent that joins no preset has no tools
10
10
  // at all and would report a model it cannot exercise. The identity is the
11
- // caller's choice: omitted means "the registry's configured default" (every
12
- // worker run), and an explicit `presetId` names a composition the caller
13
- // owns and has already verified (the additional review);
11
+ // caller's choice: omitted uses the registry's configured default. An
12
+ // explicit `presetId` names a composition the caller owns and has verified;
14
13
  // 3. bounded prompt sizes, so a huge request cannot be smuggled into a turn;
15
14
  // 4. an explicit, bounded request budget for the model call (never
16
15
  // `maxTokens: 1`, which makes a working provider look broken, and never an
@@ -460,8 +459,7 @@ export class ExecutionDeadline {
460
459
  * was created in.
461
460
  * * no placement: the historical path, which creates a Session (and Agent) through
462
461
  * `agents.create` under a caller-supplied or generated identity. Retained for a
463
- * caller that owns its own conversation identity — the additional review, which
464
- * composes its own preset and must not join the operator's history.
462
+ * caller that owns its own conversation identity.
465
463
  *
466
464
  * The runner never disposes an agent it resolved. Disposal would end a conversation
467
465
  * a later follow-up must be able to continue, so {@link driveAgent} accepts an
@@ -750,6 +748,8 @@ export async function driveAgent(deps, request) {
750
748
  request.onEvent?.(event);
751
749
  };
752
750
 
751
+ let selectionContext = null;
752
+ let releaseEffort = null;
753
753
  try {
754
754
  // A cancellation that arrived before the factory was ever called must not
755
755
  // create an agent at all — creating one only to dispose it would still run
@@ -801,6 +801,7 @@ export async function driveAgent(deps, request) {
801
801
  // legacy harness it travels through `installModelSelection`. Nothing is
802
802
  // reported as applied that was not read back.
803
803
  state.selection = applySelection(agentCtx, agent, selection);
804
+ selectionContext = agentCtx;
804
805
  agentCtx.on('session/event', onEvent);
805
806
  agentCtx.on('agent/error', (payload) => {
806
807
  state.error = errorText(payload?.error);
@@ -869,9 +870,12 @@ export async function driveAgent(deps, request) {
869
870
  // keyword heuristics) and never opens the global default.
870
871
  //
871
872
  // A REQUESTED team mode that cannot be applied STOPS the run here, before the prompt:
872
- // continuing with the Session's old mode would silently do the opposite of what the
873
- // commander asked. Only an ABSENT choice (`null`) keeps the Session as it is.
874
- state.team = await applyTeamSelection(deps, handle.agent, request?.agentTeams ?? null, state, { aborted });
873
+ // continuing with the Session's old mode would silently do the opposite of what was
874
+ // asked. Only an ABSENT choice (`null`) keeps the Session as it is — and an absent
875
+ // choice is what a continuation with no provable chain decision now arrives as.
876
+ state.team = await applyTeamSelection(
877
+ deps, handle.agent, request?.agentTeams ?? null, state, { aborted }, request?.agentTeamsImplicit === true,
878
+ );
875
879
  if (state.team !== null && typeof state.team.refuseReason === 'string') {
876
880
  // A requested mode that could not be applied is a REFUSAL, not a downgrade: the
877
881
  // worker is released without ever receiving the prompt, so nothing runs under the
@@ -892,6 +896,11 @@ export async function driveAgent(deps, request) {
892
896
  return finish(state, RUN_OUTCOMES.failed);
893
897
  }
894
898
 
899
+ const selected = state.selection;
900
+ if (request.delegated === true && selected?.applied === true
901
+ && selected.reasoningEffort !== null && selected.reasoningEffort !== 'auto') {
902
+ releaseEffort = preserveWorkerEffort(selectionContext, handle.agent, selected);
903
+ }
895
904
  handle.agent.followup(userMessage(prompt));
896
905
  await Promise.race([handle.agent.whenIdle(), aborted]);
897
906
 
@@ -917,6 +926,7 @@ export async function driveAgent(deps, request) {
917
926
  cause: diagnostic(error?.message ?? error),
918
927
  });
919
928
  } finally {
929
+ releaseEffort?.();
920
930
  // The deadline is disarmed on every exit path, which also clears a paused span
921
931
  // so a run that ends during a wait leaves no armed timer behind.
922
932
  if (state.deadline !== null) state.deadline.dispose();
@@ -988,6 +998,7 @@ export async function driveAgent(deps, request) {
988
998
  // task's name. `maxTokens` is not part of the selection: the native selection
989
999
  // carries only the provider route, model and effort.
990
1000
  state.selection = applySelection(agentCtx, agent, runSelection);
1001
+ selectionContext = agentCtx;
991
1002
  agentCtx.on('session/event', onEvent);
992
1003
  agentCtx.on('agent/error', (payload) => {
993
1004
  state.error = errorText(payload?.error);
@@ -1153,9 +1164,7 @@ export async function driveAgent(deps, request) {
1153
1164
  * `this.ctx.waterfall(scopeTarget(req.agent, req.agent), 'approval/request', req, …)`,
1154
1165
  * and `approveEscalation` is the one caller that raises it for a widened sandbox
1155
1166
  * request). A listener registered on the AGENT's own context therefore sees only
1156
- * that Agent's requests — an ordinary session, another task's worker and the
1157
- * optional read-only reviewer are all outside this scope and are never answered
1158
- * by this bridge.
1167
+ * that Agent's requests. Other sessions and tasks use their own answerers.
1159
1168
  *
1160
1169
  * The listener answers with the bridge's closed outcome. It never throws: the
1161
1170
  * seam already contains a thrown answerer into `'unavailable'`, and a bridge that
@@ -1459,6 +1468,8 @@ export async function driveAgent(deps, request) {
1459
1468
  ? null
1460
1469
  : {
1461
1470
  requested: state.team.requested,
1471
+ // Strictly boolean: was the operator's SETTING behind the request, or a person?
1472
+ implicit: state.team.implicit === true,
1462
1473
  supported: state.team.supported,
1463
1474
  applied: state.team.applied,
1464
1475
  enabled: state.team.enabled,
@@ -1480,20 +1491,33 @@ export async function driveAgent(deps, request) {
1480
1491
  * other conversation and no future task inherits it;
1481
1492
  * * a REQUESTED mode that cannot be applied stops the run BEFORE the prompt (the
1482
1493
  * caller treats `refuseReason` as terminal); an ABSENT choice never does;
1494
+ * * what is requested is the outcome that will be APPLIED — an explicit per-task
1495
+ * choice, an inherited chain choice, or the operator's new-task default — not only
1496
+ * the dispatcher's own field. An older host with no agent-teams service refuses both
1497
+ * an explicit and an inherited choice (somebody asked for exactly that mode), and
1498
+ * proceeds only for the operator's implicit OFF default, which it reports as NOT
1499
+ * APPLIED rather than claiming the Session is off;
1483
1500
  * * the wait is BOUNDED by the run itself: it races the caller's own `aborted` latch
1484
1501
  * (internal deadline or cancellation), so a service that never resolves cannot hold
1485
1502
  * the run past its budget, and a late settle never reaches the prompt.
1486
1503
  * @param {object} deps - run dependencies (`policyServices`).
1487
1504
  * @param {object} agent - the live root Agent this run drives.
1488
- * @param {boolean | null} requested - the commander's choice, or null.
1505
+ * @param {boolean | null} requested - the decision to apply, or null for none.
1489
1506
  * @param {object} state - the run state carrying the abort latch.
1490
1507
  * @param {{ aborted: Promise<string> }} hooks - the run's own abort latch promise.
1491
- * @returns {Promise<object>} `{ requested, supported, applied, enabled, reason, refuseReason }`
1508
+ * @param {boolean} [implicit] - whether `requested` is the operator's DEFAULT filling an
1509
+ * absent choice rather than something a person decided. Only an implicit OFF may
1510
+ * proceed on a host with no agent-teams service, and even then it is reported as not
1511
+ * applied rather than claimed as "off".
1512
+ * @returns {Promise<object>} `{ requested, implicit, supported, applied, enabled, reason, refuseReason }`
1492
1513
  * where `refuseReason` is non-null exactly when the run must NOT proceed.
1493
1514
  */
1494
- async function applyTeamSelection(deps, agent, requested, state, hooks = {}) {
1515
+ async function applyTeamSelection(deps, agent, requested, state, hooks = {}, implicit = false) {
1495
1516
  const base = {
1496
1517
  requested: requested === true ? true : requested === false ? false : null,
1518
+ // A strictly-boolean view of the same fact, so a reader never has to interpret a
1519
+ // tri-state to know whether the setting or a person was behind the value.
1520
+ implicit: implicit === true,
1497
1521
  supported: false,
1498
1522
  applied: false,
1499
1523
  enabled: null,
@@ -1520,6 +1544,21 @@ export async function driveAgent(deps, request) {
1520
1544
  service = null;
1521
1545
  }
1522
1546
  if (service === null || typeof service.setEnabled !== 'function') {
1547
+ // No agent-teams service on this host.
1548
+ //
1549
+ // An EXPLICIT `true` or `false`, and an INHERITED chain decision, are both REFUSED:
1550
+ // somebody asked for that exact mode, and proceeding would run under whatever the
1551
+ // Session happens to hold while the record implies otherwise. That is a refusal, not
1552
+ // a downgrade, so the prompt is never delivered.
1553
+ //
1554
+ // The one exception is the operator's DEFAULT filling an absent choice, and only its
1555
+ // OFF direction: that is exactly what a host without the service already does, so an
1556
+ // ordinary older-version dispatch keeps working. It is still reported as NOT
1557
+ // APPLIED — `applied: false`, `enabled: null` — because nothing confirmed it, and
1558
+ // claiming "off" would be asserting a fact this run never observed.
1559
+ if (base.requested === false && base.implicit) {
1560
+ return { ...base, supported: false, applied: false, enabled: null, reason: 'service-absent-default-off' };
1561
+ }
1523
1562
  return refuse('agent-teams-unavailable');
1524
1563
  }
1525
1564
  if (state.abortRequested === true) return refuse('agent-teams-aborted');
@@ -1563,9 +1602,18 @@ export async function driveAgent(deps, request) {
1563
1602
  if (state.abortRequested === true) return refuse('agent-teams-aborted');
1564
1603
  // Read back from the SERVICE, not from what we just asked for: `isEnabled` resolves
1565
1604
  // the runtime root and returns the saved projection, so this is the applied fact.
1605
+ //
1606
+ // STRICT: only a real boolean is a confirmed reading. `isEnabled(agent) === true`
1607
+ // would turn `undefined` (no runtime root, no saved selection, a service that answers
1608
+ // nothing) into `false` and then "confirm" an OFF request nobody observed — the same
1609
+ // class of false evidence this plugin refuses everywhere else. Anything that is not
1610
+ // `true` or `false` reads as UNCONFIRMED instead.
1566
1611
  let enabled = null;
1567
1612
  try {
1568
- enabled = typeof service.isEnabled === 'function' ? service.isEnabled(agent) === true : null;
1613
+ if (typeof service.isEnabled === 'function') {
1614
+ const reported = service.isEnabled(agent);
1615
+ enabled = reported === true ? true : reported === false ? false : null;
1616
+ }
1569
1617
  } catch {
1570
1618
  enabled = null;
1571
1619
  }
@@ -1857,6 +1905,44 @@ function selectThroughAgentModel(agent, wanted) {
1857
1905
  };
1858
1906
  }
1859
1907
 
1908
+ /** Keep the delegated worker's concrete effort after step schedulers run. */
1909
+ function preserveWorkerEffort(agentCtx, agent, { provider, model, reasoningEffort }) {
1910
+ const removers = [];
1911
+ let active = true;
1912
+ const sameRoute = (selection) => selection?.provider === provider && selection?.model === model;
1913
+ const shouldKeep = (payload, selection) => active && payload.agent === agent
1914
+ && payload.signal?.aborted !== true && sameRoute(selection) && selection.reasoningEffort !== reasoningEffort;
1915
+ const release = () => {
1916
+ active = false;
1917
+ for (const remove of removers) {
1918
+ if (typeof remove !== 'function') continue;
1919
+ try { remove(); } catch { /* Agent disposal can remove the listener first. */ }
1920
+ }
1921
+ };
1922
+ try {
1923
+ // DSH 0.2.2 binds the model from this step selection before it validates
1924
+ // agent/request. Prepending makes this listener unwind after the scheduler.
1925
+ removers.push(agentCtx.on('agent/pre-step', async (payload, next) => {
1926
+ const decision = await next();
1927
+ const selection = payload.modelSelection;
1928
+ if (decision?.kind !== 'reject' && shouldKeep(payload, selection)) {
1929
+ selection.reasoningEffort = reasoningEffort;
1930
+ }
1931
+ return decision;
1932
+ }, { prepend: true }));
1933
+ // Earlier hosts let the scheduler rewrite the request directly. On 0.2.2
1934
+ // the step already carries the selected effort, so the request passes through.
1935
+ removers.push(agentCtx.on('agent/request', async (payload, next) => {
1936
+ const request = await next();
1937
+ return shouldKeep(payload, request) ? { ...request, reasoningEffort } : request;
1938
+ }, { prepend: true }));
1939
+ } catch (error) {
1940
+ release();
1941
+ throw error;
1942
+ }
1943
+ return release;
1944
+ }
1945
+
1860
1946
  function numeric(value) {
1861
1947
  return typeof value === 'number' && Number.isFinite(value) ? value : null;
1862
1948
  }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Build the delegation prompt for one task.
3
+ * @param {object} input - `taskId`, `prompt`, `workspacePath`, `isolation`, `diff`, `baseline`.
4
+ * @returns {string} assembled prompt.
5
+ */
6
+ export function buildWorkerPrompt(input) {
7
+ const lines = [];
8
+ lines.push('You are a delegated implementation worker. Your work will be reviewed by the host.');
9
+ lines.push('');
10
+ lines.push(`Task id: ${input.taskId}`);
11
+ if (typeof input.workspacePath === 'string' && input.workspacePath !== '') {
12
+ lines.push(`Workspace: ${input.workspacePath}`);
13
+ }
14
+ lines.push(`Isolation: ${input.isolation ?? 'shared'}`);
15
+ lines.push('');
16
+ lines.push('## Task');
17
+ lines.push(String(input.prompt ?? '').trim());
18
+ lines.push('');
19
+ lines.push('## Working rules');
20
+ lines.push('- You may modify files only inside the workspace above.');
21
+ lines.push('- Do not commit, push, tag, or rewrite git history.');
22
+ lines.push('- Do not read or print credentials, tokens, or .env contents.');
23
+ lines.push('- Do not install packages from the network unless the task explicitly requires it.');
24
+ lines.push('- Report what you changed and what you could not do. Do not claim checks you did not run.');
25
+ lines.push('');
26
+ lines.push('## Checks and extra permissions');
27
+ lines.push('- Read ordinary files and logs with the normal file tools and the ordinary workspace permission. '
28
+ + 'Do not ask for elevated access merely to read a log, and do not use a sandbox escape as a substitute for '
29
+ + 'a file tool.');
30
+ lines.push('- Run tests under the ordinary permission first. If a test fails for a CONCRETE environment reason '
31
+ + '(a missing module, a denied pipe, an absent binary), keep that error text and report it rather than retrying '
32
+ + 'the same command with more access.');
33
+ lines.push('- Ask for extra permission only for the one complete, bounded command that genuinely needs it, and say '
34
+ + 'which error it resolves. A permission granted for one call never covers a later call, and it never widens '
35
+ + 'the sandbox permanently.');
36
+ lines.push('- Run one combined test command, save its FULL stdout/stderr, its real exit code and a short summary '
37
+ + '(for example into `.cache/`), and read that saved log afterwards with the file tools. Do not re-run a test '
38
+ + 'merely to change a filter, a `Select-String` pattern or a `Select-Object -First N`: read the log instead.');
39
+ lines.push('- A missing dependency is a fact to verify, not a reason to re-run the suite: check whether the module '
40
+ + 'exists before concluding the test failed, and never use extra permission to paper over a module-not-found '
41
+ + 'error.');
42
+ lines.push('- Fix a failing test before running the suite again. Report the tests you actually ran, their exit '
43
+ + 'codes and their counts; if the worktree cannot provide a dependency, say so plainly instead of retrying.');
44
+ lines.push('');
45
+ lines.push('## Completion');
46
+ lines.push('When the task is complete, reply with a short summary, the files you changed, and any checks you actually ran with their results.');
47
+ lines.push('You cannot approve your own work; the host decides acceptance.');
48
+ if (input.baseline !== undefined && input.baseline !== null) {
49
+ lines.push('');
50
+ lines.push(`## Starting state: ${input.baseline.dirtyBaseline === true ? 'the workspace already had uncommitted changes' : 'the workspace was clean'}`);
51
+ }
52
+ return lines.join('\n');
53
+ }