dsh-taskbridge 0.0.0-stage → 1.3.2

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 (75) hide show
  1. package/CHANGELOG.md +763 -0
  2. package/LICENSE +21 -0
  3. package/README.md +622 -3
  4. package/bin/dsh-delegate-codex-agent.js +115 -0
  5. package/bin/dsh-delegate-control.d.ts +90 -0
  6. package/bin/dsh-delegate-control.js +450 -0
  7. package/bin/dsh-delegate-mcp.d.ts +121 -0
  8. package/bin/dsh-delegate-mcp.js +273 -0
  9. package/codex/dsh-taskbridge.toml +247 -0
  10. package/cordis.patch.yml +6 -0
  11. package/docs/INTRODUCTION.md +15 -0
  12. package/docs/INTRODUCTION.zh.md +34 -0
  13. package/docs/auth-contract.md +138 -0
  14. package/docs/claude-code.md +31 -0
  15. package/docs/codex-integration.md +937 -0
  16. package/docs/contracts-stage-b.md +443 -0
  17. package/docs/conversation-placement.md +304 -0
  18. package/docs/plugin-market.md +30 -0
  19. package/docs/redaction-contract.md +127 -0
  20. package/docs/runtime-compatibility.md +223 -0
  21. package/docs/silent-wait.md +191 -0
  22. package/docs/taskbridge-upgrade.md +28 -0
  23. package/docs/taskdispatch-upgrade.md +25 -0
  24. package/docs/worker-permissions.md +347 -0
  25. package/docs/workspace-contract.md +538 -0
  26. package/icon.svg +1 -0
  27. package/lib/client.d.ts +118 -0
  28. package/lib/client.js +3232 -0
  29. package/locale/en.json +7 -0
  30. package/locale/zh.json +7 -0
  31. package/package.json +138 -4
  32. package/src/auth/fence.js +361 -0
  33. package/src/auth/grants.js +789 -0
  34. package/src/client/api.js +2322 -0
  35. package/src/client/index.jsx +2333 -0
  36. package/src/client/styles.js +251 -0
  37. package/src/codex/installer.js +3299 -0
  38. package/src/codex/seam.js +429 -0
  39. package/src/codex/toml.js +784 -0
  40. package/src/config/defaults.js +164 -0
  41. package/src/config/redact.js +184 -0
  42. package/src/config/settings.js +629 -0
  43. package/src/config/store.js +186 -0
  44. package/src/config/validate.js +763 -0
  45. package/src/credentials/seam.js +202 -0
  46. package/src/http/execution-plane.js +456 -0
  47. package/src/http/respond.js +175 -0
  48. package/src/http/user-plane.js +1122 -0
  49. package/src/index.d.ts +332 -0
  50. package/src/index.js +657 -0
  51. package/src/jobs/activity.js +1008 -0
  52. package/src/jobs/engine.js +3614 -0
  53. package/src/jobs/history.js +1467 -0
  54. package/src/jobs/title.js +17 -0
  55. package/src/mcp/server.js +1821 -0
  56. package/src/mcp/wait.js +536 -0
  57. package/src/model/connectivity.js +371 -0
  58. package/src/model/discovery.js +582 -0
  59. package/src/model/native-catalog.js +68 -0
  60. package/src/model/openai-adapter.js +671 -0
  61. package/src/model/probe.js +264 -0
  62. package/src/model/providers.js +756 -0
  63. package/src/model/routing.js +321 -0
  64. package/src/review/preset.js +868 -0
  65. package/src/review/prompts.js +126 -0
  66. package/src/review/reviewer.js +933 -0
  67. package/src/runtime/agent-runner.js +1740 -0
  68. package/src/runtime/endpoint-discovery.js +118 -0
  69. package/src/runtime/permissions.js +1429 -0
  70. package/src/runtime/sandbox.js +358 -0
  71. package/src/runtime/session-placement.js +1121 -0
  72. package/src/workspace/audit.js +775 -0
  73. package/src/workspace/locks.js +167 -0
  74. package/src/workspace/preflight.js +424 -0
  75. package/src/workspace/worktrees.js +613 -0
@@ -0,0 +1,371 @@
1
+ // Layered connectivity check for one provider profile.
2
+ //
3
+ // The four layers exist because they fail for different reasons and an operator
4
+ // who sees one red row must be able to tell "the endpoint is unreachable" from
5
+ // "the key is wrong" from "the model answered nothing". Collapsing them into one
6
+ // boolean produces the classic false negative this project was told not to
7
+ // repeat: a reasoning model asked for one token spends its whole budget thinking,
8
+ // returns no visible text, and looks broken while it is working perfectly.
9
+ //
10
+ // Layer order and what each one actually proves:
11
+ //
12
+ // 1. `transport` — the configured base URL answers at the HTTP level. This
13
+ // is a real request with **no credential attached**, so a
14
+ // 401/403 is a pass: it proves the endpoint is there.
15
+ // 2. `authentication`— the profile's credential reference is configured in the
16
+ // native seam. Presence only; the value is never read.
17
+ // 3. `catalog` — the native routing layer can resolve this exact
18
+ // provider/model/effort triple and reports its declared
19
+ // efforts. This is the layer that refuses an unsupported
20
+ // effort instead of silently ignoring it.
21
+ // 4. `modelResponse` — a real, short completion with a practical token budget,
22
+ // classified by `probeModel` (reasoning-only counts).
23
+ //
24
+ // Only the last layer requires the first three to have any chance of passing, but
25
+ // every layer is still evaluated: an operator fixing a key should not also have to
26
+ // re-run to discover the address is wrong.
27
+
28
+ import { resolveRoute, ROUTING_CODES, CONNECTIVITY_LAYERS } from './routing.js';
29
+
30
+ /** Stable codes for connectivity-layer outcomes that are not routing refusals. */
31
+ export const CONNECTIVITY_CODES = Object.freeze({
32
+ providerUnknown: 'CONNECTIVITY_PROVIDER_UNKNOWN',
33
+ urlInvalid: 'CONNECTIVITY_URL_INVALID',
34
+ transportOk: 'CONNECTIVITY_TRANSPORT_OK',
35
+ transportUnreachable: 'CONNECTIVITY_TRANSPORT_UNREACHABLE',
36
+ noCredentialRef: 'CONNECTIVITY_NO_CREDENTIAL_REF',
37
+ credentialConfigured: 'CONNECTIVITY_CREDENTIAL_CONFIGURED',
38
+ credentialMissing: 'CONNECTIVITY_CREDENTIAL_MISSING',
39
+ seamUnavailable: 'CONNECTIVITY_CREDENTIAL_SEAM_UNAVAILABLE',
40
+ catalogOk: 'CONNECTIVITY_CATALOG_OK',
41
+ });
42
+
43
+ /** Bound on the transport probe. A dead socket must not hold the request open. */
44
+ export const TRANSPORT_TIMEOUT_MS = 10_000;
45
+
46
+ /**
47
+ * Probe one base URL at the HTTP level without sending a credential.
48
+ *
49
+ * `redirect: 'manual'` is deliberate: following a redirect would send this request
50
+ * to a host the operator did not configure, and the status of *that* host would
51
+ * then be reported as if it were theirs.
52
+ * @param {string} baseUrl - validated base URL from the provider profile.
53
+ * @param {object} [options] - `fetchImpl` (tests), `timeoutMs`, `signal`.
54
+ * @returns {Promise<{ ok: boolean, detail: object }>} layer result.
55
+ */
56
+ export async function probeTransport(baseUrl, options = {}) {
57
+ let url;
58
+ try {
59
+ url = new URL(baseUrl);
60
+ } catch {
61
+ return {
62
+ ok: false,
63
+ detail: { code: CONNECTIVITY_CODES.urlInvalid, message: 'the provider base URL is not an absolute URL' },
64
+ };
65
+ }
66
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
67
+ return {
68
+ ok: false,
69
+ detail: { code: CONNECTIVITY_CODES.urlInvalid, message: 'the provider base URL is not http or https' },
70
+ };
71
+ }
72
+ const fetchImpl = options.fetchImpl ?? ((target, init) => globalThis.fetch(target, init));
73
+ const timeoutMs = Number.isInteger(options.timeoutMs) ? options.timeoutMs : TRANSPORT_TIMEOUT_MS;
74
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
75
+ // A caller's cancellation and the layer's own budget are both honoured; either
76
+ // one aborts the request.
77
+ const signal = options.signal === undefined || options.signal === null
78
+ ? timeoutSignal
79
+ : AbortSignal.any([timeoutSignal, options.signal]);
80
+ try {
81
+ const response = await fetchImpl(url, {
82
+ method: 'GET',
83
+ redirect: 'manual',
84
+ // No `authorization` header and no cookie jar: this layer answers "is
85
+ // something listening and speaking HTTP here", nothing about the key.
86
+ headers: { accept: 'application/json, text/plain;q=0.5' },
87
+ signal,
88
+ });
89
+ const status = typeof response?.status === 'number' ? response.status : 0;
90
+ // Drain the body so the socket is released; the content is not inspected.
91
+ await response?.body?.cancel?.().catch?.(() => undefined);
92
+ if (status >= 100 && status < 500) {
93
+ // A 401/403/404 is reachability evidence, not a failure of this layer.
94
+ return {
95
+ ok: true,
96
+ detail: { code: CONNECTIVITY_CODES.transportOk, status, authenticated: false },
97
+ };
98
+ }
99
+ return {
100
+ ok: false,
101
+ detail: {
102
+ code: CONNECTIVITY_CODES.transportUnreachable,
103
+ message: `the endpoint answered HTTP ${status}`,
104
+ status,
105
+ },
106
+ };
107
+ } catch (error) {
108
+ return {
109
+ ok: false,
110
+ detail: {
111
+ code: CONNECTIVITY_CODES.transportUnreachable,
112
+ message: 'the endpoint could not be reached',
113
+ cause: typeof error?.code === 'string' ? error.code : (error?.name ?? null),
114
+ },
115
+ };
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Build the empty report skeleton, in the documented layer order.
121
+ * @returns {object} report with every layer present and unproven.
122
+ */
123
+ function emptyReport() {
124
+ const report = {};
125
+ for (const layer of CONNECTIVITY_LAYERS) {
126
+ report[layer] = { ok: null, detail: null };
127
+ }
128
+ return report;
129
+ }
130
+
131
+ /**
132
+ * Resolve the provider profile and the model/effort triple a check should use.
133
+ *
134
+ * The requested triple wins over the stored worker selection so an operator can
135
+ * test a candidate before saving it, but a request that names nothing falls back
136
+ * to the stored selection — never to a different provider, model or effort.
137
+ * @param {object} settings - validated settings document.
138
+ * @param {object} request - `{ providerId, model?, reasoningEffort? }`.
139
+ * @returns {object} resolution facts.
140
+ */
141
+ function resolveTarget(settings, request) {
142
+ const providerId = typeof request?.providerId === 'string' ? request.providerId.trim() : '';
143
+ const provider = settings.providers.find((entry) => entry.id === providerId) ?? null;
144
+ const worker = settings.worker;
145
+ const sameProvider = provider !== null && worker.providerId === provider.id;
146
+ const model = typeof request?.model === 'string' && request.model !== ''
147
+ ? request.model
148
+ : (sameProvider ? worker.model : null);
149
+ const reasoningEffort = typeof request?.reasoningEffort === 'string' && request.reasoningEffort !== ''
150
+ ? request.reasoningEffort
151
+ : (sameProvider ? worker.reasoningEffort : null);
152
+ return {
153
+ providerId,
154
+ provider,
155
+ model: typeof model === 'string' && model !== '' ? model : null,
156
+ reasoningEffort: typeof reasoningEffort === 'string' && reasoningEffort !== '' ? reasoningEffort : null,
157
+ };
158
+ }
159
+
160
+ /**
161
+ * Run the four-layer check for one provider profile.
162
+ *
163
+ * Every layer runs even when an earlier one failed, so the report is a complete
164
+ * picture rather than "the first thing that broke".
165
+ * @param {object} deps - `settings`, `credentials` (gateway), `llm`, `probeModel`,
166
+ * `ensureRoutes`, and optional `fetchImpl`.
167
+ * @param {object} request - `{ providerId, model?, reasoningEffort? }`.
168
+ * @param {object} [options] - `signal`, `timeoutMs` for the transport layer.
169
+ * @returns {Promise<object>} the layered report.
170
+ */
171
+ export async function checkProviderConnectivity(deps, request, options = {}) {
172
+ const report = emptyReport();
173
+ const settings = await deps.settings.read();
174
+ const target = resolveTarget(settings, request);
175
+ report.providerId = target.providerId;
176
+ report.providerName = target.provider?.name ?? null;
177
+ report.selection = { model: target.model, reasoningEffort: target.reasoningEffort };
178
+
179
+ if (target.provider === null) {
180
+ const detail = { code: CONNECTIVITY_CODES.providerUnknown, message: `no provider profile named ${target.providerId}` };
181
+ report.transport = { ok: false, detail };
182
+ report.authentication = { ok: null, detail };
183
+ report.catalog = { ok: false, detail };
184
+ report.modelResponse = { ok: null, detail, response: null };
185
+ return report;
186
+ }
187
+
188
+ // ---- 1. transport -------------------------------------------------------
189
+ try {
190
+ report.transport = await probeTransport(target.provider.baseUrl, {
191
+ ...(deps.fetchImpl === undefined ? {} : { fetchImpl: deps.fetchImpl }),
192
+ ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
193
+ ...(options.signal === undefined ? {} : { signal: options.signal }),
194
+ });
195
+ } catch (error) {
196
+ report.transport = {
197
+ ok: false,
198
+ detail: {
199
+ code: CONNECTIVITY_CODES.transportUnreachable,
200
+ message: 'the endpoint check could not be completed',
201
+ cause: typeof error?.code === 'string' ? error.code : null,
202
+ },
203
+ };
204
+ }
205
+
206
+ // ---- 2. authentication --------------------------------------------------
207
+ const reference = target.provider.credentialRef;
208
+ if (reference === null || reference === undefined) {
209
+ report.authentication = {
210
+ ok: false,
211
+ detail: {
212
+ code: CONNECTIVITY_CODES.noCredentialRef,
213
+ message: 'this profile names no credential reference, so a request would be refused',
214
+ },
215
+ };
216
+ } else if (deps.credentials === undefined || deps.credentials === null) {
217
+ report.authentication = {
218
+ ok: null,
219
+ detail: { code: CONNECTIVITY_CODES.seamUnavailable, message: 'this harness exposes no credential service' },
220
+ };
221
+ } else {
222
+ try {
223
+ const info = await deps.credentials.describe(reference);
224
+ report.authentication = {
225
+ ok: info.configured === true,
226
+ detail: {
227
+ code: info.configured === true
228
+ ? CONNECTIVITY_CODES.credentialConfigured
229
+ : CONNECTIVITY_CODES.credentialMissing,
230
+ reference,
231
+ ...(info.source === undefined ? {} : { source: info.source }),
232
+ // A shadowed, non-writable reference is a distinct operator fact: the
233
+ // value resolves, but this plugin cannot change it.
234
+ writable: info.writable === true,
235
+ },
236
+ };
237
+ } catch (error) {
238
+ report.authentication = {
239
+ ok: false,
240
+ detail: {
241
+ code: typeof error?.code === 'string' ? error.code : CONNECTIVITY_CODES.seamUnavailable,
242
+ message: 'the credential reference could not be described',
243
+ reference,
244
+ },
245
+ };
246
+ }
247
+ }
248
+
249
+ // ---- 3. catalog + 4. model response ------------------------------------
250
+ // Both need a registered native route for this provider. `ensureRoutes` is the
251
+ // same call the job engine makes, so a route that works here is the route a
252
+ // task would use.
253
+ if (target.model === null) {
254
+ const detail = {
255
+ code: ROUTING_CODES.modelUnresolved,
256
+ message: 'no model is selected for this provider, so no model request was made',
257
+ };
258
+ report.catalog = { ok: false, detail };
259
+ report.modelResponse = { ok: null, detail, response: null };
260
+ return report;
261
+ }
262
+
263
+ let routes = null;
264
+ try {
265
+ routes = await deps.ensureRoutes?.(settings) ?? null;
266
+ } catch (error) {
267
+ const detail = {
268
+ code: typeof error?.code === 'string' ? error.code : ROUTING_CODES.providerNotRegistered,
269
+ message: 'the native provider route could not be registered',
270
+ };
271
+ report.catalog = { ok: false, detail };
272
+ report.modelResponse = { ok: null, detail, response: null };
273
+ return report;
274
+ }
275
+
276
+ const selection = {
277
+ providerId: target.providerId,
278
+ model: target.model,
279
+ reasoningEffort: target.reasoningEffort,
280
+ };
281
+
282
+ let route;
283
+ try {
284
+ route = await resolveRoute(deps, selection, { routes, signal: options.signal });
285
+ report.catalog = {
286
+ ok: true,
287
+ detail: {
288
+ code: CONNECTIVITY_CODES.catalogOk,
289
+ route: route.providerRoute,
290
+ model: route.model,
291
+ declaredEfforts: [...route.declaredEfforts],
292
+ defaultEffort: route.defaultEffort,
293
+ },
294
+ providers: [{ providerId: target.providerId, route: route.providerRoute }],
295
+ };
296
+ } catch (error) {
297
+ const detail = {
298
+ code: typeof error?.code === 'string' ? error.code : ROUTING_CODES.modelUnresolved,
299
+ message: typeof error?.message === 'string' ? error.message.slice(0, 300) : 'the selection could not be routed',
300
+ ...(error?.details === undefined ? {} : { details: error.details }),
301
+ };
302
+ report.catalog = { ok: false, detail, providers: [] };
303
+ // A refused selection is not a model failure: nothing was asked of the model,
304
+ // so this layer stays unproven rather than red.
305
+ report.modelResponse = { ok: null, detail, response: null };
306
+ return report;
307
+ }
308
+
309
+ if (typeof deps.probeModel !== 'function') {
310
+ report.modelResponse = {
311
+ ok: null,
312
+ detail: { code: 'PROBE_UNAVAILABLE', message: 'no model probe is installed in this harness' },
313
+ response: null,
314
+ };
315
+ return report;
316
+ }
317
+
318
+ // The probe is a native service call, so it can throw as well as answer: a
319
+ // harness whose `llm` seam is registered but not yet usable, or a probe
320
+ // implementation that rejects, must leave this layer *unproven* rather than
321
+ // failing the whole report. The other three layers have already been decided
322
+ // and stay in the report either way.
323
+ let result;
324
+ try {
325
+ result = await deps.probeModel(route, { signal: options.signal });
326
+ } catch (error) {
327
+ report.modelResponse = {
328
+ ok: null,
329
+ detail: {
330
+ code: 'PROBE_UNAVAILABLE',
331
+ message: 'the model probe could not complete',
332
+ cause: typeof error?.code === 'string' ? error.code : null,
333
+ },
334
+ response: null,
335
+ };
336
+ return report;
337
+ }
338
+
339
+ const detail = result?.detail ?? null;
340
+ const finishReason = typeof detail?.finishReason === 'string' ? detail.finishReason : null;
341
+ // A budget ending is a budget fact, not a model failure; the probe is the one
342
+ // classifier that decides it (`budgetExhausted`), and it also counts a
343
+ // reasoning-only answer as an answer. Nothing is re-classified here, so the
344
+ // report cannot disagree with the probe that produced it.
345
+ const budgetExhausted = detail?.budgetExhausted === true;
346
+ const reasoningOnly = result?.reasoningOnly === true;
347
+ const text = typeof result?.text === 'string' ? result.text : '';
348
+ const answered = text.trim() !== '' || reasoningOnly;
349
+ report.modelResponse = {
350
+ // A reasoning-only answer is a working model: the model answered, it simply
351
+ // did not answer in visible text.
352
+ ok: answered ? true : result?.ok === true,
353
+ detail,
354
+ response: {
355
+ text,
356
+ reasoningOnly,
357
+ reasoningChars: Number.isInteger(result?.reasoningChars) ? result.reasoningChars : null,
358
+ finishReason,
359
+ budgetExhausted,
360
+ ...(budgetExhausted && answered
361
+ ? {
362
+ note: reasoningOnly
363
+ ? 'the model answered in reasoning only and stopped at its token budget; raise the budget for visible text'
364
+ : 'the model answered and stopped at its token budget; raise the budget for a complete answer',
365
+ }
366
+ : {}),
367
+ tokens: result?.tokens ?? null,
368
+ },
369
+ };
370
+ return report;
371
+ }