dsh-taskbridge 0.0.0-stage → 1.3.1

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 +754 -0
  2. package/LICENSE +21 -0
  3. package/README.md +624 -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-delegate.toml +245 -0
  10. package/cordis.patch.yml +6 -0
  11. package/docs/INTRODUCTION.md +15 -0
  12. package/docs/INTRODUCTION.zh.md +32 -0
  13. package/docs/auth-contract.md +138 -0
  14. package/docs/claude-code.md +31 -0
  15. package/docs/codex-integration.md +922 -0
  16. package/docs/contracts-stage-b.md +443 -0
  17. package/docs/conversation-placement.md +293 -0
  18. package/docs/plugin-market.md +30 -0
  19. package/docs/redaction-contract.md +127 -0
  20. package/docs/runtime-compatibility.md +220 -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 +135 -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 +3260 -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 +454 -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 +3609 -0
  53. package/src/jobs/history.js +1467 -0
  54. package/src/mcp/server.js +1820 -0
  55. package/src/mcp/wait.js +536 -0
  56. package/src/model/connectivity.js +371 -0
  57. package/src/model/discovery.js +582 -0
  58. package/src/model/native-catalog.js +68 -0
  59. package/src/model/openai-adapter.js +671 -0
  60. package/src/model/probe.js +264 -0
  61. package/src/model/providers.js +756 -0
  62. package/src/model/routing.js +321 -0
  63. package/src/review/preset.js +868 -0
  64. package/src/review/prompts.js +126 -0
  65. package/src/review/reviewer.js +933 -0
  66. package/src/runtime/agent-runner.js +1738 -0
  67. package/src/runtime/endpoint-discovery.js +118 -0
  68. package/src/runtime/permissions.js +1429 -0
  69. package/src/runtime/sandbox.js +358 -0
  70. package/src/runtime/session-placement.js +1103 -0
  71. package/src/workspace/audit.js +775 -0
  72. package/src/workspace/locks.js +167 -0
  73. package/src/workspace/preflight.js +424 -0
  74. package/src/workspace/worktrees.js +613 -0
@@ -0,0 +1,321 @@
1
+ // Model routing against the native LLM seam.
2
+ //
3
+ // The rule this module exists to enforce: the model that runs a job is the
4
+ // model the operator selected. No branch here substitutes a provider, a model
5
+ // or a reasoning effort. When the native registry cannot confirm the requested
6
+ // triple, routing refuses with a machine code and the job does not start.
7
+ //
8
+ // Validation has two independent sources and both must agree:
9
+ // 1. the plugin's own settings document (operator intent), and
10
+ // 2. the native `llm` service (what this harness can actually reach right now).
11
+ // A configuration can be internally consistent and still unroutable; a settings
12
+ // edit can also make a previously routable route vanish.
13
+
14
+ import { redactText } from '../config/redact.js';
15
+
16
+ /** Refusal codes surfaced by routing. */
17
+ export const ROUTING_CODES = Object.freeze({
18
+ serviceUnavailable: 'ROUTING_SERVICE_UNAVAILABLE',
19
+ providerNotRegistered: 'ROUTING_PROVIDER_NOT_REGISTERED',
20
+ providerListFailed: 'ROUTING_PROVIDER_LIST_FAILED',
21
+ modelUnresolved: 'ROUTING_MODEL_UNRESOLVED',
22
+ effortUnsupported: 'ROUTING_EFFORT_UNSUPPORTED',
23
+ credentialMissing: 'ROUTING_CREDENTIAL_MISSING',
24
+ });
25
+
26
+ /**
27
+ * The four connectivity layers, in report order.
28
+ *
29
+ * They are separate because they fail for different reasons and an operator who
30
+ * sees one red row must be able to tell "the endpoint is unreachable" from "the
31
+ * key is wrong" from "the model answered nothing".
32
+ */
33
+ export const CONNECTIVITY_LAYERS = Object.freeze(['transport', 'authentication', 'catalog', 'modelResponse']);
34
+
35
+ /** A routing refusal with a stable machine code. */
36
+ export class RoutingError extends Error {
37
+ /**
38
+ * @param {string} code - stable machine code.
39
+ * @param {string} message - human-readable explanation.
40
+ * @param {object} [details] - bounded, non-secret details.
41
+ */
42
+ constructor(code, message, details = {}) {
43
+ super(message);
44
+ this.name = 'RoutingError';
45
+ this.code = code;
46
+ this.details = details;
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Read a native value that may be a plain array or a promise-returning accessor.
52
+ * The native seam differs between harness versions; both shapes are handled so a
53
+ * signature change degrades to an explicit refusal instead of an exception.
54
+ * @param {unknown} value - candidate value.
55
+ * @returns {Promise<unknown>} resolved value.
56
+ */
57
+ async function settle(value) {
58
+ return await value;
59
+ }
60
+
61
+ /**
62
+ * Normalize the native effort list for one resolved model.
63
+ *
64
+ * The native seam validates this shape before returning it
65
+ * (`LlmRuntime.normalizeModelInfo` throws `INVALID_MODEL_REASONING` on malformed
66
+ * metadata), so this reads a trusted structure and only flattens it.
67
+ * @param {object | null | undefined} resolved - resolved model info.
68
+ * @returns {{ efforts: string[], defaultEffort: string | null }} declared efforts.
69
+ */
70
+ export function declaredEfforts(resolved) {
71
+ const reasoning = resolved?.reasoning ?? null;
72
+ const raw = Array.isArray(reasoning?.efforts) ? reasoning.efforts : [];
73
+ const efforts = [];
74
+ for (const entry of raw) {
75
+ const id = typeof entry === 'string' ? entry : entry?.id;
76
+ if (typeof id === 'string' && id !== '' && !efforts.includes(id)) efforts.push(id);
77
+ }
78
+ const defaultEffort = typeof reasoning?.defaultEffort === 'string' ? reasoning.defaultEffort : null;
79
+ return { efforts, defaultEffort };
80
+ }
81
+
82
+ /**
83
+ * Call the native exact-model lookup.
84
+ *
85
+ * The runtime service exposes `resolveModelInfo(provider, model, signal)`; the
86
+ * adapter base class exposes `resolveModel(...)`. Both are tried because a test
87
+ * double or an older harness may provide either, but a service that offers
88
+ * neither is a refusal, not a silent "assume it works".
89
+ * @param {object} llm - native LLM service.
90
+ * @param {string} providerRoute - provider route id.
91
+ * @param {string} model - model id.
92
+ * @param {AbortSignal | undefined} signal - cancellation.
93
+ * @returns {Promise<object | null>} resolved info, or null when unsupported.
94
+ */
95
+ async function resolveModelInfo(llm, providerRoute, model, signal) {
96
+ if (typeof llm.resolveModelInfo === 'function') {
97
+ return await settle(llm.resolveModelInfo(providerRoute, model, signal));
98
+ }
99
+ if (typeof llm.resolveModel === 'function') {
100
+ return await settle(llm.resolveModel(providerRoute, model, signal));
101
+ }
102
+ return null;
103
+ }
104
+
105
+ /**
106
+ * Decide which native provider route one selection actually addresses.
107
+ *
108
+ * Two sources exist and only one may win. When the provider registry has
109
+ * produced a mapping for the operator's configured provider id, that mapping is
110
+ * authoritative: it is the route the plugin just registered with the harness,
111
+ * and a profile id is not a native route (`relay` in settings is not
112
+ * necessarily the route id the adapter was registered under). When no mapping
113
+ * is supplied — a caller that already froze a route, or a snapshot taken before
114
+ * the first sync — the explicit route, then the profile id, is used as before.
115
+ * There is no substitution: a provider absent from a supplied mapping is
116
+ * refused rather than rerouted through its profile id, because that id may
117
+ * collide with an unrelated native route.
118
+ * @param {Map<string, string> | null | undefined} routes - public provider id -> native route.
119
+ * @param {string | null | undefined} providerId - operator-facing profile id.
120
+ * @param {string | null | undefined} explicitRoute - route already resolved by a caller.
121
+ * @returns {string} native route id.
122
+ */
123
+ function requireMappedRoute(routes, providerId, explicitRoute) {
124
+ if (routes === undefined || routes === null) return explicitRoute ?? providerId;
125
+ const mapped = routes instanceof Map ? routes.get(providerId) : undefined;
126
+ if (typeof mapped !== 'string' || mapped === '') {
127
+ throw new RoutingError(ROUTING_CODES.providerNotRegistered, `provider ${providerId} has no registered native route`, {
128
+ providerId: typeof providerId === 'string' ? providerId : null,
129
+ registered: routes instanceof Map ? [...routes.keys()].slice(0, 32) : [],
130
+ });
131
+ }
132
+ return mapped;
133
+ }
134
+
135
+ /**
136
+ * Resolve one configured selection into a routable native request descriptor.
137
+ *
138
+ * @param {object} deps - `llm` is the native LLM service (may be undefined while
139
+ * the plugin loads before that service exists).
140
+ * @param {object} selection - validated `{ providerId, providerRoute, model, reasoningEffort, provider }`.
141
+ * @param {object} [options] - `signal` for cancellation, `requireEffort` to demand
142
+ * an explicit effort on models that declare efforts, `routes` as the plugin's
143
+ * public-provider-id -> native-route mapping.
144
+ * @returns {Promise<object>} routable descriptor.
145
+ */
146
+ export async function resolveRoute(deps, selection, options = {}) {
147
+ const llm = deps?.llm;
148
+ if (llm === undefined || llm === null
149
+ || (typeof llm.resolveModelInfo !== 'function' && typeof llm.resolveModel !== 'function')) {
150
+ throw new RoutingError(ROUTING_CODES.serviceUnavailable, 'the native llm service is not available', {});
151
+ }
152
+ const providerRoute = requireMappedRoute(options.routes, selection.providerId, selection.providerRoute);
153
+ const model = selection.model;
154
+ if (typeof providerRoute !== 'string' || providerRoute === '') {
155
+ throw new RoutingError(ROUTING_CODES.providerNotRegistered, 'no provider route was selected', {});
156
+ }
157
+ if (typeof model !== 'string' || model === '') {
158
+ throw new RoutingError(ROUTING_CODES.modelUnresolved, 'no model was selected', { providerRoute });
159
+ }
160
+
161
+ let registered;
162
+ try {
163
+ registered = await settle(typeof llm.listProviders === 'function' ? llm.listProviders() : []);
164
+ } catch (error) {
165
+ throw new RoutingError(ROUTING_CODES.providerListFailed, 'the native llm provider list could not be read', {
166
+ cause: error?.code ?? null,
167
+ });
168
+ }
169
+ const routeIds = Array.isArray(registered)
170
+ ? registered.map((entry) => (typeof entry === 'string' ? entry : entry?.id ?? entry?.provider)).filter((id) => typeof id === 'string')
171
+ : [];
172
+ if (routeIds.length > 0 && !routeIds.includes(providerRoute)) {
173
+ throw new RoutingError(ROUTING_CODES.providerNotRegistered, `provider route ${providerRoute} is not registered with the harness`, {
174
+ providerRoute,
175
+ available: routeIds.slice(0, 32),
176
+ });
177
+ }
178
+
179
+ let resolved;
180
+ try {
181
+ resolved = await resolveModelInfo(llm, providerRoute, model, options.signal);
182
+ } catch (error) {
183
+ throw new RoutingError(ROUTING_CODES.modelUnresolved, `model ${model} could not be resolved on route ${providerRoute}`, {
184
+ providerRoute,
185
+ model,
186
+ cause: error?.code ?? null,
187
+ // Bounded and redacted: adapters may surface transport errors verbatim.
188
+ detail: typeof error?.message === 'string' ? error.message.slice(0, 300) : null,
189
+ });
190
+ }
191
+ if (resolved === null || typeof resolved !== 'object') {
192
+ throw new RoutingError(ROUTING_CODES.serviceUnavailable, 'the native llm service cannot resolve exact model metadata', {
193
+ providerRoute,
194
+ model,
195
+ });
196
+ }
197
+
198
+ const { efforts, defaultEffort } = declaredEfforts(resolved);
199
+ const requested = selection.reasoningEffort ?? null;
200
+ if (requested !== null) {
201
+ if (efforts.length === 0) {
202
+ // The adapter declares no effort axis. Sending an effort would be a guess
203
+ // that a provider may ignore or reject; refuse instead.
204
+ throw new RoutingError(ROUTING_CODES.effortUnsupported, `model ${model} declares no reasoning efforts`, {
205
+ providerRoute,
206
+ model,
207
+ requested,
208
+ });
209
+ }
210
+ if (!efforts.includes(requested)) {
211
+ throw new RoutingError(ROUTING_CODES.effortUnsupported, `model ${model} does not support reasoning effort ${requested}`, {
212
+ providerRoute,
213
+ model,
214
+ requested,
215
+ supported: [...efforts],
216
+ });
217
+ }
218
+ } else if (options.requireEffort === true && efforts.length > 0 && defaultEffort === null) {
219
+ // Explicit routing means an effort is a decision, not an omission. If the
220
+ // model has an effort axis and no adapter default, an unset effort is
221
+ // ambiguous and is refused rather than resolved silently.
222
+ throw new RoutingError(ROUTING_CODES.effortUnsupported, `model ${model} requires an explicit reasoning effort`, {
223
+ providerRoute,
224
+ model,
225
+ supported: [...efforts],
226
+ });
227
+ }
228
+
229
+ return {
230
+ providerRoute,
231
+ model,
232
+ // Only a validated value leaves this function; an unset effort stays unset.
233
+ reasoningEffort: requested,
234
+ declaredEfforts: efforts,
235
+ defaultEffort,
236
+ hasEffortAxis: efforts.length > 0,
237
+ };
238
+ }
239
+
240
+ /**
241
+ * Collect the operator-facing catalog of routable models: for every configured
242
+ * provider, the models the native seam can resolve and which efforts each
243
+ * declares. Unreachable providers are reported with a reason instead of being
244
+ * hidden, so an operator sees why their configured model cannot be picked.
245
+ *
246
+ * The `routes` map is authoritative whenever the caller has one, and a caller
247
+ * that is *reporting* routes must always supply one. There is deliberately no
248
+ * "no mapping supplied, so use the profile id" branch: a profile id is not a
249
+ * native route, and reporting it produced the observed `/models` and `/catalog`
250
+ * answers of `route: "workbuddy"` with an empty model list — a row that named an
251
+ * ambient route the plugin does not own. A caller with no mapping (`routes`
252
+ * `null`/absent) gets a `providerNotRegistered` refusal instead. Only the
253
+ * internal routing decision keeps the profile-id fallback, through
254
+ * `requireMappedRoute`, for callers that froze a route before the first sync.
255
+ * @param {object} deps - `llm` native service.
256
+ * @param {object[]} providers - validated provider profiles.
257
+ * @param {object} [options] - `signal`, `routes` as the public-id -> native-route map.
258
+ * @returns {Promise<object[]>} per-provider catalog with explicit status.
259
+ */
260
+ export async function describeCatalog(deps, providers, options = {}) {
261
+ const llm = deps?.llm;
262
+ const routes = options.routes instanceof Map ? options.routes : null;
263
+ const out = [];
264
+ for (const provider of providers) {
265
+ const mapped = routes === null ? undefined : routes.get(provider.id);
266
+ // `route` is null unless a native route was actually registered for this
267
+ // provider: never the profile id, which may collide with an ambient route.
268
+ const entry = {
269
+ providerId: provider.id,
270
+ route: typeof mapped === 'string' && mapped !== '' ? mapped : null,
271
+ models: [],
272
+ error: null,
273
+ };
274
+ if (entry.route === null) {
275
+ entry.error = {
276
+ code: ROUTING_CODES.providerNotRegistered,
277
+ message: routes === null
278
+ ? 'no native route mapping was supplied, so no route is reported'
279
+ : 'this provider has no registered native route',
280
+ };
281
+ out.push(entry);
282
+ continue;
283
+ }
284
+ const route = entry.route;
285
+ const resolveAvailable = llm !== undefined && llm !== null
286
+ && (typeof llm.resolveModelInfo === 'function' || typeof llm.resolveModel === 'function');
287
+ if (!resolveAvailable) {
288
+ entry.error = { code: ROUTING_CODES.serviceUnavailable, message: 'the native llm service is not available' };
289
+ out.push(entry);
290
+ continue;
291
+ }
292
+ const declared = Array.isArray(provider.models) ? provider.models : [];
293
+ const candidates = declared.length > 0
294
+ ? declared.map((model) => model.id)
295
+ : await listNativeModels(llm, route).catch(() => []);
296
+ for (const modelId of candidates) {
297
+ try {
298
+ const resolved = await resolveModelInfo(llm, route, modelId, options.signal);
299
+ const { efforts, defaultEffort } = declaredEfforts(resolved);
300
+ entry.models.push({ id: modelId, efforts, defaultEffort });
301
+ } catch (error) {
302
+ entry.error = entry.error ?? {
303
+ code: ROUTING_CODES.modelUnresolved,
304
+ message: `model ${modelId} could not be resolved`,
305
+ detail: typeof error?.message === 'string' ? error.message.slice(0, 300) : null,
306
+ };
307
+ }
308
+ }
309
+ out.push(entry);
310
+ }
311
+ return out;
312
+ }
313
+
314
+ async function listNativeModels(llm, providerId) {
315
+ if (typeof llm?.listModels !== 'function') return [];
316
+ const listed = await settle(llm.listModels(providerId));
317
+ if (!Array.isArray(listed)) return [];
318
+ return listed
319
+ .map((model) => (typeof model === 'string' ? model : model?.id))
320
+ .filter((id) => typeof id === 'string' && id !== '');
321
+ }