dsh-taskbridge 1.4.2 → 1.5.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 (40) hide show
  1. package/CHANGELOG.md +16 -2
  2. package/README.md +8 -7
  3. package/bin/dsh-delegate-mcp.d.ts +20 -3
  4. package/bin/dsh-delegate-mcp.js +15 -0
  5. package/codex/dsh-taskbridge.toml +74 -5
  6. package/docs/INTRODUCTION.md +2 -2
  7. package/docs/INTRODUCTION.zh.md +2 -2
  8. package/docs/codex-integration.md +4 -2
  9. package/docs/conversation-placement.md +44 -7
  10. package/docs/plugin-market.md +1 -1
  11. package/docs/redaction-contract.md +47 -4
  12. package/docs/releases/1.5.0-token-benchmark.zh.md +73 -0
  13. package/docs/releases/1.5.0.zh.md +51 -0
  14. package/docs/runtime-compatibility.md +4 -4
  15. package/docs/silent-wait.md +84 -0
  16. package/docs/taskbridge-upgrade.md +1 -1
  17. package/docs/worker-permissions.md +154 -17
  18. package/lib/client.js +3 -0
  19. package/package.json +4 -2
  20. package/src/client/api.js +26 -0
  21. package/src/codex/installer.js +15 -0
  22. package/src/config/redact.js +72 -11
  23. package/src/http/execution-plane.js +76 -5
  24. package/src/index.d.ts +285 -0
  25. package/src/index.js +72 -2
  26. package/src/jobs/activity.js +10 -0
  27. package/src/jobs/continuation-identity.js +278 -0
  28. package/src/jobs/engine.js +326 -36
  29. package/src/jobs/history.js +53 -0
  30. package/src/mcp/continuation.js +317 -0
  31. package/src/mcp/metrics.js +343 -0
  32. package/src/mcp/server.js +1079 -47
  33. package/src/mcp/wait.js +266 -74
  34. package/src/review/prompts.js +145 -126
  35. package/src/runtime/agent-runner.js +165 -0
  36. package/src/runtime/permissions.js +192 -2
  37. package/src/runtime/question-call.js +162 -0
  38. package/src/runtime/questions.js +909 -0
  39. package/src/runtime/session-placement.js +78 -5
  40. package/src/version.js +99 -0
@@ -50,6 +50,7 @@ import { dirname, join } from 'node:path';
50
50
 
51
51
  import { ISOLATION_MODES, SESSIONS_FILE } from '../config/defaults.js';
52
52
  import { diagnostic } from '../config/redact.js';
53
+ import { continuationIdentityOf, pathDigest, isPathDigest, sameRecordedDirectory } from '../jobs/continuation-identity.js';
53
54
 
54
55
  /** Stable ids of a managed worktree life cycle, mirrored as a plain string set here. */
55
56
  const WORKTREE_STATE_DISPOSED = 'disposed';
@@ -59,6 +60,12 @@ const RECORD_FIELDS = Object.freeze([
59
60
  'taskId',
60
61
  'sourcePath',
61
62
  'executionPath',
63
+ // Digests of the two canonical paths. They are the identity a follow-up can
64
+ // compare even when a projection shortened the path string itself, and they are
65
+ // opaque to redaction, so a readable path and its digest normally agree and the
66
+ // path remains what an operator recognises.
67
+ 'sourcePathDigest',
68
+ 'executionPathDigest',
62
69
  'workspaceId',
63
70
  'sessionId',
64
71
  'isolation',
@@ -167,6 +174,28 @@ export function sameSessionPath(a, b) {
167
174
  return left !== null && right !== null && left === right;
168
175
  }
169
176
 
177
+ /**
178
+ * Whether a recorded path PROVES it is one directory, from either kind of evidence.
179
+ *
180
+ * This is a thin adapter over {@link sameRecordedDirectory}, NOT a rule of its own:
181
+ * the identity module is the single definition of what a stored path proves. An
182
+ * earlier version of this function compared the readable path first and returned
183
+ * `true` on that alone, so a record whose digest named a DIFFERENT directory was
184
+ * admitted — its two proofs contradicted each other and one of them was believed.
185
+ * Delegating removes that second rule entirely: a contradictory record proves
186
+ * nothing, a masked record needs its digest, and a record with neither is refused.
187
+ * @param {unknown} recordedPath - the stored path.
188
+ * @param {unknown} recordedDigest - the stored digest, if the row has one.
189
+ * @param {unknown} currentPath - the directory this run resolved.
190
+ * @returns {boolean} true only when the record proves it is that directory.
191
+ */
192
+ export function recordedSessionPathIs(recordedPath, recordedDigest, currentPath) {
193
+ return sameRecordedDirectory(
194
+ { path: recordedPath, digest: recordedDigest },
195
+ { path: currentPath, digest: pathDigest(currentPath) },
196
+ );
197
+ }
198
+
170
199
  /**
171
200
  * Narrow a dependency object to the two native controllers.
172
201
  *
@@ -557,7 +586,7 @@ async function continueTaskThread({ deps, sessions, workspace, parent, execPath,
557
586
  );
558
587
  }
559
588
  const recordedExec = parent.executionPath ?? parent.path ?? null;
560
- if (!sameSessionPath(recordedExec, execPath)) {
589
+ if (!recordedSessionPathIs(recordedExec, parent.executionPathDigest, execPath)) {
561
590
  throw new SessionPlacementError(
562
591
  SESSION_CODES.continuationPathMismatch,
563
592
  'the named task ran in another execution directory, so its conversation was not continued',
@@ -578,7 +607,7 @@ async function continueTaskThread({ deps, sessions, workspace, parent, execPath,
578
607
  const recordedSource = parent.sourcePath ?? null;
579
608
  const currentSource = deps?.sourcePath ?? null;
580
609
  if (typeof recordedSource === 'string' && recordedSource !== '' && typeof currentSource === 'string' && currentSource !== ''
581
- && !sameSessionPath(recordedSource, currentSource)) {
610
+ && !recordedSessionPathIs(recordedSource, parent.sourcePathDigest, currentSource)) {
582
611
  throw new SessionPlacementError(
583
612
  SESSION_CODES.continuationWorkspaceMismatch,
584
613
  'the named task was authorized for another source repository, so its conversation was not continued',
@@ -1058,6 +1087,17 @@ function projectSessionRecord(value) {
1058
1087
  taskId,
1059
1088
  sourcePath,
1060
1089
  executionPath,
1090
+ // A digest is carried through verbatim when the row has one, so a stored
1091
+ // identity read back from disk keeps the proof a shortened path lost. When it
1092
+ // has none (a row written by this build always does) it is derived from the
1093
+ // path it belongs to, which yields the same value for a readable path and
1094
+ // nothing at all for a masked one.
1095
+ sourcePathDigest: isPathDigest(value.sourcePathDigest)
1096
+ ? value.sourcePathDigest
1097
+ : (sourcePath === null ? null : pathDigest(sourcePath)),
1098
+ executionPathDigest: isPathDigest(value.executionPathDigest)
1099
+ ? value.executionPathDigest
1100
+ : (executionPath === null ? null : pathDigest(executionPath)),
1061
1101
  workspaceId: typeof value.workspaceId === 'string' ? value.workspaceId.trim() : '',
1062
1102
  sessionId,
1063
1103
  isolation,
@@ -1103,12 +1143,36 @@ export async function rememberSession(store, placement, entry) {
1103
1143
  // A row without a task and an execution path names nothing a continuation could
1104
1144
  // validate, so it is not written at all rather than half-written.
1105
1145
  if (taskId === '' || executionPath === '') return false;
1146
+ const identity = continuationIdentityOf(target, placement, target.isolation ?? null);
1147
+ return identity === null ? false : rememberIdentity(store, placement, target, identity);
1148
+ }
1149
+
1150
+ /**
1151
+ * Write one already-computed identity row.
1152
+ * @param {object} store - the identity store.
1153
+ * @param {object} placement - the run's placement.
1154
+ * @param {object} target - the caller's identity target.
1155
+ * @param {object} identity - {@link continuationIdentityOf} result.
1156
+ * @returns {Promise<boolean>} whether a record was written.
1157
+ */
1158
+ async function rememberIdentity(store, placement, target, identity) {
1159
+ const sessionId = typeof placement.sessionId === 'string' ? placement.sessionId : '';
1160
+ if (sessionId === '') return false;
1161
+ const taskId = identity.taskId;
1162
+ const executionPath = identity.executionPath ?? trimmedPath(target.executionPath);
1163
+ if (executionPath === '') return false;
1164
+ const sourcePath = identity.sourcePath ?? (trimmedPath(target.sourcePath) !== ''
1165
+ ? trimmedPath(target.sourcePath)
1166
+ : executionPath);
1106
1167
  await store.put({
1107
1168
  taskId,
1108
1169
  executionPath,
1109
- sourcePath: typeof target.sourcePath === 'string' && target.sourcePath.trim() !== ''
1110
- ? target.sourcePath.trim()
1111
- : executionPath,
1170
+ sourcePath,
1171
+ // Recorded canonically, with the digest of the canonical form, so a later
1172
+ // follow-up can prove the directory even if redaction shortens the display
1173
+ // path. `continuationIdentityOf` is the one definition of this identity.
1174
+ sourcePathDigest: identity.sourcePathDigest ?? (sourcePath === '' ? null : pathDigest(sourcePath)),
1175
+ executionPathDigest: identity.executionPathDigest ?? pathDigest(executionPath),
1112
1176
  workspaceId: typeof placement.workspaceId === 'string' ? placement.workspaceId : '',
1113
1177
  sessionId,
1114
1178
  isolation: typeof target.isolation === 'string' ? target.isolation : null,
@@ -1118,4 +1182,13 @@ export async function rememberSession(store, placement, entry) {
1118
1182
  return true;
1119
1183
  }
1120
1184
 
1185
+ /**
1186
+ * The trimmed spelling of a caller-supplied path, or an empty string.
1187
+ * @param {unknown} value - candidate path.
1188
+ * @returns {string} trimmed path or ''.
1189
+ */
1190
+ function trimmedPath(value) {
1191
+ return typeof value === 'string' ? value.trim() : '';
1192
+ }
1193
+
1121
1194
  export { RECORD_FIELDS };
package/src/version.js ADDED
@@ -0,0 +1,99 @@
1
+ // The version this build actually is, read from its own package manifest.
2
+ //
3
+ // A literal version in the source is a second copy of a fact that already lives in
4
+ // `package.json`, and the two drift: the MCP handshake reported `1.4.2` while a
5
+ // pre-release tarball of the same source answered `initialize` with that shipped
6
+ // number, so a host could not tell which build it was talking to.
7
+ //
8
+ // The manifest is the ONE source. It is read from disk on demand and is the fixed
9
+ // relative location `<package root>/package.json`, where `<package root>` is the
10
+ // directory above this module's own `src/`. That is the only layout this build
11
+ // supports: a checkout, an installed tarball and the published `files` allowlist all
12
+ // keep `src/`, so no other lookup is attempted. A build that cannot read the manifest
13
+ // says so instead of inventing a number.
14
+
15
+ import { readFileSync } from 'node:fs';
16
+ import { dirname, join, resolve } from 'node:path';
17
+ import { fileURLToPath } from 'node:url';
18
+
19
+ /** This module's directory (`<package root>/src`). */
20
+ const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
21
+
22
+ /**
23
+ * The package root this module is loaded from: one directory above `src/`.
24
+ *
25
+ * Derived from the module's own location rather than `process.cwd()`, which a host may
26
+ * have set to anything.
27
+ */
28
+ export const PACKAGE_ROOT = resolve(MODULE_DIR, '..');
29
+
30
+ /** Absolute path of the manifest this module reads. The only location it reads. */
31
+ export const MANIFEST_PATH = join(PACKAGE_ROOT, 'package.json');
32
+
33
+ /** The package name reported when the manifest cannot supply one. */
34
+ const FALLBACK_NAME = 'dsh-taskbridge';
35
+
36
+ /** The memoised manifest answer, or null before the first read. */
37
+ let cached = null;
38
+
39
+ /**
40
+ * Read the manifest this build belongs to.
41
+ *
42
+ * Memoised: the answer cannot change while the process runs, and the handshake may be
43
+ * asked for it repeatedly by an MCP host that reconnects.
44
+ * @returns {{ ok: true, name: string, version: string, path: string }
45
+ * | { ok: false, reason: string, path: string }} the manifest facts, or why not.
46
+ */
47
+ export function readPackageManifest() {
48
+ if (cached !== null) return cached;
49
+ cached = loadPackageManifest();
50
+ return cached;
51
+ }
52
+
53
+ /**
54
+ * Read and parse the manifest without memoising.
55
+ * @returns {{ ok: true, name: string, version: string, path: string }
56
+ * | { ok: false, reason: string, path: string }} the manifest facts, or why not.
57
+ */
58
+ function loadPackageManifest() {
59
+ let text;
60
+ try {
61
+ text = readFileSync(MANIFEST_PATH, 'utf8');
62
+ } catch (error) {
63
+ return { ok: false, path: MANIFEST_PATH, reason: error?.code === 'ENOENT' ? 'manifest-missing' : 'manifest-unreadable' };
64
+ }
65
+ let parsed;
66
+ try {
67
+ parsed = JSON.parse(text);
68
+ } catch {
69
+ return { ok: false, path: MANIFEST_PATH, reason: 'manifest-invalid' };
70
+ }
71
+ const version = typeof parsed?.version === 'string' ? parsed.version.trim() : '';
72
+ const name = typeof parsed?.name === 'string' ? parsed.name.trim() : '';
73
+ if (version === '') return { ok: false, path: MANIFEST_PATH, reason: 'manifest-version-missing' };
74
+ return {
75
+ ok: true,
76
+ name: name === '' ? FALLBACK_NAME : name,
77
+ version,
78
+ path: MANIFEST_PATH,
79
+ };
80
+ }
81
+
82
+ /**
83
+ * The version to report, with an explicit fallback when the manifest cannot be read.
84
+ *
85
+ * The fallback version is `'0.0.0-unknown'` rather than a plausible-looking release
86
+ * number: an MCP host that reads it learns the build could not describe itself, which
87
+ * is the true fact, instead of being told a version that belongs to a different build.
88
+ * The fallback NAME is this package's own name, so an unreadable manifest still reports
89
+ * the right package rather than a historical alias.
90
+ * @returns {{ name: string, version: string, source: string }} reported identity.
91
+ * `source` is `package.json` when the manifest was read, `fallback` otherwise.
92
+ */
93
+ export function reportedVersion() {
94
+ const manifest = readPackageManifest();
95
+ if (manifest.ok) {
96
+ return { name: manifest.name, version: manifest.version, source: 'package.json' };
97
+ }
98
+ return { name: FALLBACK_NAME, version: '0.0.0-unknown', source: 'fallback' };
99
+ }