dsh-taskbridge 1.4.2 → 1.5.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.
- package/CHANGELOG.md +34 -2
- package/README.md +10 -8
- package/bin/dsh-delegate-mcp.d.ts +20 -3
- package/bin/dsh-delegate-mcp.js +15 -0
- package/codex/dsh-taskbridge.toml +180 -16
- package/docs/INTRODUCTION.md +2 -2
- package/docs/INTRODUCTION.zh.md +2 -2
- package/docs/codex-integration.md +11 -13
- package/docs/conversation-placement.md +44 -7
- package/docs/plugin-market.md +1 -1
- package/docs/redaction-contract.md +47 -4
- package/docs/releases/1.5.0-token-benchmark.zh.md +73 -0
- package/docs/releases/1.5.0.zh.md +51 -0
- package/docs/releases/1.5.1.zh.md +70 -0
- package/docs/runtime-compatibility.md +4 -4
- package/docs/silent-wait.md +157 -3
- package/docs/taskbridge-upgrade.md +1 -1
- package/docs/worker-permissions.md +154 -17
- package/lib/client.js +298 -103
- package/package.json +9 -3
- package/src/client/api.js +315 -34
- package/src/client/index.jsx +151 -67
- package/src/codex/installer.js +251 -11
- package/src/config/redact.js +72 -11
- package/src/http/execution-plane.js +124 -10
- package/src/index.d.ts +347 -0
- package/src/index.js +88 -5
- package/src/jobs/activity.js +102 -9
- package/src/jobs/continuation-identity.js +283 -0
- package/src/jobs/engine.js +491 -55
- package/src/jobs/history.js +96 -0
- package/src/mcp/continuation.js +317 -0
- package/src/mcp/metrics.js +366 -0
- package/src/mcp/server.js +1203 -53
- package/src/mcp/wait.js +338 -73
- package/src/review/prompts.js +145 -126
- package/src/runtime/agent-runner.js +330 -0
- package/src/runtime/permissions.js +192 -2
- package/src/runtime/question-call.js +162 -0
- package/src/runtime/questions.js +909 -0
- package/src/runtime/sandbox.js +363 -358
- package/src/runtime/session-placement.js +1207 -1121
- package/src/version.js +121 -0
- package/src/workspace/worktrees.js +70 -4
package/src/index.d.ts
CHANGED
|
@@ -172,6 +172,8 @@ export interface DelegatePendingPermission {
|
|
|
172
172
|
grant: { kind: 'allowed-once'; appliesTo: 'this-call-only'; callId: string; reusable: false } | null;
|
|
173
173
|
/** Always true: a decision never changes the Session's standing mode. */
|
|
174
174
|
standingModeUnchanged: true;
|
|
175
|
+
/** Present after a commander rejection; delivery is independent of the rejection outcome. */
|
|
176
|
+
rejectionFeedback?: { delivered: boolean; reason: string | null; text?: string } | null;
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
/** The per-call permission block every task view carries. */
|
|
@@ -196,6 +198,122 @@ export interface DelegateTaskPermission {
|
|
|
196
198
|
interrupted?: true;
|
|
197
199
|
}
|
|
198
200
|
|
|
201
|
+
/**
|
|
202
|
+
* One option a question offers.
|
|
203
|
+
*/
|
|
204
|
+
export interface DelegateQuestionOption {
|
|
205
|
+
/** The label an answer selects. */
|
|
206
|
+
label: string;
|
|
207
|
+
/** Optional extra context for the option. */
|
|
208
|
+
description: string | null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* One question a delegated worker asked, as the task view publishes it.
|
|
213
|
+
*
|
|
214
|
+
* Nothing here is model output: these are the questions the worker composed with the
|
|
215
|
+
* native `ask_user_question` tool. No reasoning, transcript or tool argument has a field.
|
|
216
|
+
*/
|
|
217
|
+
export interface DelegateQuestion {
|
|
218
|
+
/** Stable caller-provided id, echoed in the answer. */
|
|
219
|
+
id: string;
|
|
220
|
+
/** The question text. */
|
|
221
|
+
question: string;
|
|
222
|
+
/** Optional short heading. */
|
|
223
|
+
header: string | null;
|
|
224
|
+
/** Optional supporting detail, kept out of the option labels. */
|
|
225
|
+
detail: string | null;
|
|
226
|
+
/** Choices the question offered; empty when it expects free text. */
|
|
227
|
+
options: DelegateQuestionOption[];
|
|
228
|
+
/** Whether more than one option may be selected. */
|
|
229
|
+
multiSelect: boolean;
|
|
230
|
+
/**
|
|
231
|
+
* The caller's presentation intent, when it declared one.
|
|
232
|
+
*
|
|
233
|
+
* `'approval'` questions are REFUSED on this channel: a permission decision belongs to
|
|
234
|
+
* `delegate_permission_decide`, which binds one exact tool call. `'plan-review'` is an
|
|
235
|
+
* information answer and grants nothing either.
|
|
236
|
+
*/
|
|
237
|
+
intent: 'plan-review' | 'approval' | null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** One pending ordinary question set. */
|
|
241
|
+
export interface DelegatePendingQuestion {
|
|
242
|
+
requestId: string;
|
|
243
|
+
taskId: string;
|
|
244
|
+
sessionId: string | null;
|
|
245
|
+
/** The native tool call the question is keyed by, when the harness supplied one. */
|
|
246
|
+
callId: string | null;
|
|
247
|
+
state: 'pending' | 'answered' | 'expired' | 'cancelled' | 'refused';
|
|
248
|
+
createdAt: number;
|
|
249
|
+
/** Finite absolute deadline; defaults to ten minutes after the question was published. */
|
|
250
|
+
deadlineAt: number;
|
|
251
|
+
questions: DelegateQuestion[];
|
|
252
|
+
/** An omitted question must never be answered using partial text. */
|
|
253
|
+
questionsOmitted?: boolean;
|
|
254
|
+
questionAnswerable?: boolean;
|
|
255
|
+
questionCount?: number;
|
|
256
|
+
/** Always `false`: answering a question never grants access. */
|
|
257
|
+
grantsAccess: false;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** One answer the commander gave. */
|
|
261
|
+
export interface DelegateQuestionAnswerItem {
|
|
262
|
+
id: string;
|
|
263
|
+
/** Labels this question actually offered. */
|
|
264
|
+
selected: string[];
|
|
265
|
+
/** Optional free text; required when the question offered no options. */
|
|
266
|
+
custom?: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** The ordinary-question block every task view carries. */
|
|
270
|
+
export interface DelegateTaskQuestion {
|
|
271
|
+
/** Whether this run was offered a question bridge at all. */
|
|
272
|
+
bridged: boolean;
|
|
273
|
+
/** Whether a question is outstanding right now. */
|
|
274
|
+
waiting: boolean;
|
|
275
|
+
pending: DelegatePendingQuestion | null;
|
|
276
|
+
/** Bounded settled trail, oldest first. */
|
|
277
|
+
evidence: {
|
|
278
|
+
requestId: string;
|
|
279
|
+
taskId: string;
|
|
280
|
+
callId: string | null;
|
|
281
|
+
state: string;
|
|
282
|
+
questions: { id: string; question: string }[];
|
|
283
|
+
answers: DelegateQuestionAnswerItem[] | null;
|
|
284
|
+
reason: string | null;
|
|
285
|
+
createdAt: number;
|
|
286
|
+
settledAt: number | null;
|
|
287
|
+
answeredAt: number | null;
|
|
288
|
+
}[];
|
|
289
|
+
/** Time the run spent waiting for an answer, NOT charged to the execution budget. */
|
|
290
|
+
pausedExecutionMs: number;
|
|
291
|
+
/** Always `false`, stated so no reader mistakes a question answer for a grant. */
|
|
292
|
+
grantsAccess: false;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* The receipt of ONE question answer.
|
|
297
|
+
*
|
|
298
|
+
* `applied: true` is claimed only when the route confirmed the SAME task and request.
|
|
299
|
+
* `applied: null` with `confirmation: "unknown"` means nothing was established — read the
|
|
300
|
+
* task before answering again, and never resend automatically.
|
|
301
|
+
*/
|
|
302
|
+
export interface DelegateAnswerReceipt {
|
|
303
|
+
receiptId: string;
|
|
304
|
+
taskId: string | null;
|
|
305
|
+
requestId: string | null;
|
|
306
|
+
answers?: DelegateQuestionAnswerItem[];
|
|
307
|
+
answersOmitted?: true;
|
|
308
|
+
answerCount?: number;
|
|
309
|
+
evidenceOmitted?: true;
|
|
310
|
+
applied: boolean | null;
|
|
311
|
+
confirmation: 'confirmed' | 'unknown' | 'refused';
|
|
312
|
+
/** Always `false`: an answer is not an authorization. */
|
|
313
|
+
grantsAccess: false;
|
|
314
|
+
reason?: string | null;
|
|
315
|
+
}
|
|
316
|
+
|
|
199
317
|
/**
|
|
200
318
|
* Bounded activity metadata for one task.
|
|
201
319
|
*
|
|
@@ -263,6 +381,15 @@ export interface DelegateTaskActivity {
|
|
|
263
381
|
export interface DelegateRepeatedFailure {
|
|
264
382
|
/** Fixed discriminator, so a client can tell this apart from a silence report. */
|
|
265
383
|
kind: 'repeated-tool-failure';
|
|
384
|
+
/**
|
|
385
|
+
* The stable identity of THIS notification: 16 hex chars digesting the episode's
|
|
386
|
+
* own hashed identity under a per-monitor 16-byte random nonce — never the raw
|
|
387
|
+
* arguments or error prose. The reminder is redelivered with the SAME eventId
|
|
388
|
+
* until the receiver acknowledges it by this id, so a lost answer is recoverable
|
|
389
|
+
* and one repeated failure is one notification; two tasks failing identically at
|
|
390
|
+
* the same instant never share an identity.
|
|
391
|
+
*/
|
|
392
|
+
eventId: string;
|
|
266
393
|
/** The native tool name. */
|
|
267
394
|
toolName: string;
|
|
268
395
|
/**
|
|
@@ -292,6 +419,13 @@ export type DelegateObserveReason =
|
|
|
292
419
|
| 'heartbeat'
|
|
293
420
|
| 'attention'
|
|
294
421
|
| 'permission'
|
|
422
|
+
/**
|
|
423
|
+
* The worker asked an ordinary question and is paused until it is answered.
|
|
424
|
+
*
|
|
425
|
+
* Reported IMMEDIATELY, not after a silence threshold, and it grants nothing: any
|
|
426
|
+
* widening still needs its own `permission` request.
|
|
427
|
+
*/
|
|
428
|
+
| 'question'
|
|
295
429
|
| 'ready'
|
|
296
430
|
| 'failed'
|
|
297
431
|
| 'cancelled'
|
|
@@ -328,11 +462,41 @@ export interface DelegateObservationSummary {
|
|
|
328
462
|
connectionId: string | null;
|
|
329
463
|
/** Always false: execution completion is not host acceptance. */
|
|
330
464
|
selfApproved: false;
|
|
465
|
+
/**
|
|
466
|
+
* The commander's DSH Agent Teams decision frozen on the task at admission
|
|
467
|
+
* (`true`/`false`), or `null` when they made no choice (the Session keeps its own
|
|
468
|
+
* mode). This is the REQUEST, never the applied state — read `team` for that.
|
|
469
|
+
*/
|
|
470
|
+
agentTeams: boolean | null;
|
|
471
|
+
/** What DSH's own Agent Teams service confirmed for the run, or `null` when unasked. */
|
|
472
|
+
team: DelegateAgentTeamsOutcome | null;
|
|
331
473
|
/** The commander's recorded delivery review, or null while none exists. */
|
|
332
474
|
hostAcceptance: DelegateCompactHostAcceptance | null;
|
|
333
475
|
reviewPersistence: DelegateReviewPersistence;
|
|
334
476
|
}
|
|
335
477
|
|
|
478
|
+
/**
|
|
479
|
+
* The outcome of one run's Agent Teams selection.
|
|
480
|
+
*
|
|
481
|
+
* DSH owns the switch: the run's own root Session stores `team/mode`, the same selection
|
|
482
|
+
* the model menu's「Use Agent Teams」control writes. `requested` is what the dispatcher
|
|
483
|
+
* asked for, `applied` is what the service CONFIRMED by reading the saved selection back,
|
|
484
|
+
* and `reason` explains every non-application (`not-requested`,
|
|
485
|
+
* `agent-teams-unavailable`, `agent-teams-failed: …`, `agent-teams-unconfirmed`,
|
|
486
|
+
* `agent-teams-mismatch: …`, `aborted`) so an operator can tell "asked and on" from
|
|
487
|
+
* "asked and could not be applied".
|
|
488
|
+
*/
|
|
489
|
+
export interface DelegateAgentTeamsOutcome {
|
|
490
|
+
requested: boolean | null;
|
|
491
|
+
/** Whether this harness composed the Agent Teams service at all. */
|
|
492
|
+
supported: boolean;
|
|
493
|
+
/** True only after the service's own read-back agreed with the request. */
|
|
494
|
+
applied: boolean;
|
|
495
|
+
/** The selection the Session reports, or `null` when it could not be read. */
|
|
496
|
+
enabled: boolean | null;
|
|
497
|
+
reason: string | null;
|
|
498
|
+
}
|
|
499
|
+
|
|
336
500
|
/**
|
|
337
501
|
* A replayed (idempotent) review request and its answer.
|
|
338
502
|
*
|
|
@@ -430,6 +594,154 @@ export interface DelegateHostAcceptance {
|
|
|
430
594
|
note: string;
|
|
431
595
|
}
|
|
432
596
|
|
|
597
|
+
/**
|
|
598
|
+
* The receipt of ONE per-call permission decision.
|
|
599
|
+
*
|
|
600
|
+
* `applied` is the only field that answers "did this take effect", and it is deliberately
|
|
601
|
+
* three-valued: `null` with `confirmation: 'unknown'` means the decision could not be
|
|
602
|
+
* confirmed — the call failed before the harness answered, OR the answer lacked the identity
|
|
603
|
+
* and outcome evidence, OR it CONTRADICTED the request that was decided. Such a decision must
|
|
604
|
+
* never be resent without reading the task's real state first.
|
|
605
|
+
*
|
|
606
|
+
* `applied: true` is claimed ONLY from a permission answer that names the SAME task, the SAME
|
|
607
|
+
* request and the SAME operation fingerprint the decision was bound to, reports a settled
|
|
608
|
+
* `state`, and carries the outcome this decision asked for (`allowed-once` for an allow,
|
|
609
|
+
* `rejected` for a reject). An allow additionally needs its `verified` evidence; a reject
|
|
610
|
+
* needs none. The quoted fingerprint is never replaced by a conflicting backend value.
|
|
611
|
+
*/
|
|
612
|
+
export interface DelegateDecisionReceipt {
|
|
613
|
+
taskId: string | null;
|
|
614
|
+
requestId: string | null;
|
|
615
|
+
decision: 'allow-once' | 'reject' | null;
|
|
616
|
+
/** The exact operation the decision was bound to; `null` when none could be proven. */
|
|
617
|
+
fingerprint: string | null;
|
|
618
|
+
/** `true` only for a confirmed decision; `false` for a harness refusal; `null` if unknown. */
|
|
619
|
+
applied: boolean | null;
|
|
620
|
+
confirmation: 'applied' | 'unknown' | 'refused';
|
|
621
|
+
/** The closed native outcome, when the harness reported one. */
|
|
622
|
+
outcome?: DelegatePendingPermission['outcome'];
|
|
623
|
+
/** Which checks an `allowed-once` actually passed. Absent for a reject. */
|
|
624
|
+
verified?: DelegatePendingPermission['verified'];
|
|
625
|
+
decidedAt?: number;
|
|
626
|
+
grant?: DelegatePendingPermission['grant'];
|
|
627
|
+
/** Whether the rejection reason reached the executor; the note itself is not repeated. */
|
|
628
|
+
rejectionFeedback?: { delivered: boolean; reason: string | null } | null;
|
|
629
|
+
/** Why the decision is not confirmed. Present only when `confirmation` is not `applied`. */
|
|
630
|
+
reason?: string;
|
|
631
|
+
/**
|
|
632
|
+
* The contradicting evidence, when the answer disagreed with what was decided. Present only
|
|
633
|
+
* for an `unknown` outcome, and bounded.
|
|
634
|
+
*/
|
|
635
|
+
evidence?: Record<string, unknown>;
|
|
636
|
+
/** Present only when a bound forced the bulky evidence out of a rescued receipt. */
|
|
637
|
+
evidenceOmitted?: true;
|
|
638
|
+
/** Present only for an unconfirmed decision: the failure that prevented confirmation. */
|
|
639
|
+
error?: { code: string; message: string };
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* The answer of `delegate_permission_decide({ waitAfterDecision: true })`.
|
|
644
|
+
*
|
|
645
|
+
* It is the SAME flat shape {@link DelegateObservation} publishes for a wait — a plain
|
|
646
|
+
* `delegate_wait` answer plus `decisionReceipt` — so a host reads one vocabulary for both.
|
|
647
|
+
* There is no nested follow-up block: the top-level `permission` is the live pending
|
|
648
|
+
* operation, and `boundedJson` keeps it (and the receipt) even when the answer must be cut.
|
|
649
|
+
*
|
|
650
|
+
* When the decision WAS applied but the following wait failed, was interrupted or was
|
|
651
|
+
* cancelled, this is still a SUCCESS carrying `decisionReceipt` (`applied: true`) plus
|
|
652
|
+
* `reason: null`, `actionable: false` and a `waitError` block: the decision stands, only the
|
|
653
|
+
* waiting ended, and the execution was not stopped. The receipt is never swallowed.
|
|
654
|
+
*/
|
|
655
|
+
export interface DelegateDecisionWithWait extends DelegateObservation {
|
|
656
|
+
decisionReceipt: DelegateDecisionReceipt;
|
|
657
|
+
/** Present only when the applied decision's follow-up wait ended in a refusal. */
|
|
658
|
+
waitError?: { code: string; message: string; phase: 'follow-up-wait' };
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* The refusal of a decision whose outcome nobody established or confirmed.
|
|
663
|
+
*
|
|
664
|
+
* `applied` is `null`, `confirmation` is `'unknown'`, and the caller must read the task with
|
|
665
|
+
* `delegate_result` before deciding whether to send the decision again. Nothing is retried
|
|
666
|
+
* automatically and no wait is started.
|
|
667
|
+
*/
|
|
668
|
+
export interface DelegateUnconfirmedDecisionFacts {
|
|
669
|
+
decisionReceipt: DelegateDecisionReceipt;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* One bounded accounting census of an MCP process.
|
|
674
|
+
*
|
|
675
|
+
* These are counts of the PROGRAM — the tool calls a host made and the waits it ran — never
|
|
676
|
+
* of the host model. The host's own turns, token usage and cost are not observable from this
|
|
677
|
+
* process and are reported as `'not-integrated'`, never as zero.
|
|
678
|
+
*/
|
|
679
|
+
export interface DelegateMcpMetrics {
|
|
680
|
+
schemaVersion: 1;
|
|
681
|
+
definitions: Record<string, string>;
|
|
682
|
+
hostObservability: {
|
|
683
|
+
hostModelResponses: 'not-integrated';
|
|
684
|
+
hostTokenUsage: 'not-integrated';
|
|
685
|
+
hostCost: 'not-integrated';
|
|
686
|
+
reason: string;
|
|
687
|
+
};
|
|
688
|
+
tools: Record<string, number>;
|
|
689
|
+
returnedText: {
|
|
690
|
+
count: number;
|
|
691
|
+
/** UTF-8 bytes of the final bounded, redacted tool text. Not a delivery receipt. */
|
|
692
|
+
bytes: number;
|
|
693
|
+
/** Returns whose size could not be measured (no text, or unencodable). */
|
|
694
|
+
unmeasured: number;
|
|
695
|
+
unit: 'utf8-bytes-of-serialized-tool-text';
|
|
696
|
+
};
|
|
697
|
+
waits: {
|
|
698
|
+
count: number;
|
|
699
|
+
totalMs: number;
|
|
700
|
+
observations: number;
|
|
701
|
+
reasons: Record<string, number>;
|
|
702
|
+
};
|
|
703
|
+
decisions: {
|
|
704
|
+
count: number;
|
|
705
|
+
applied: number;
|
|
706
|
+
unknown: number;
|
|
707
|
+
refused: number;
|
|
708
|
+
allowed: number;
|
|
709
|
+
rejected: number;
|
|
710
|
+
};
|
|
711
|
+
questionAnswers: { count: number; applied: number; unknown: number; refused: number };
|
|
712
|
+
correlation: {
|
|
713
|
+
waitsAfterDecisions: number;
|
|
714
|
+
waitQuestionsAnswered: number;
|
|
715
|
+
recentWaits: Array<{
|
|
716
|
+
waitId: string | null;
|
|
717
|
+
afterDecisionId: string | null;
|
|
718
|
+
taskId: string | null;
|
|
719
|
+
reason: string;
|
|
720
|
+
durationMs: number;
|
|
721
|
+
observationRequests: number;
|
|
722
|
+
heartbeatsConsumed: number;
|
|
723
|
+
settledRequestObservations: number;
|
|
724
|
+
waitReturns: number;
|
|
725
|
+
at: number;
|
|
726
|
+
}>;
|
|
727
|
+
recentDecisions: Array<{
|
|
728
|
+
receiptId: string | null;
|
|
729
|
+
taskId: string | null;
|
|
730
|
+
requestId: string | null;
|
|
731
|
+
decision: 'allow-once' | 'reject' | 'question-answer' | null;
|
|
732
|
+
fingerprint: string | null;
|
|
733
|
+
/**
|
|
734
|
+
* The same three-valued fact the permission receipt publishes: `true` for `applied`,
|
|
735
|
+
* `false` for `refused`, `null` for `unknown`. An unconfirmed attempt is `null`, never
|
|
736
|
+
* `false`, so a reader cannot mistake it for an established refusal.
|
|
737
|
+
*/
|
|
738
|
+
applied: boolean | null;
|
|
739
|
+
state: 'applied' | 'unknown' | 'refused';
|
|
740
|
+
at: number;
|
|
741
|
+
}>;
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
|
|
433
745
|
/** Result of one bounded observation of a delegated task. */
|
|
434
746
|
export interface DelegateObservation {
|
|
435
747
|
task: DelegateObservationSummary;
|
|
@@ -440,12 +752,47 @@ export interface DelegateObservation {
|
|
|
440
752
|
* never shortened into an undecidable summary.
|
|
441
753
|
*/
|
|
442
754
|
permission: DelegatePendingPermission | null;
|
|
755
|
+
/**
|
|
756
|
+
* The FULL pending question set, present only for `reason: 'question'`.
|
|
757
|
+
*
|
|
758
|
+
* Carries the questions, their options, and the identity an answer is bound to, so one
|
|
759
|
+
* reply is enough to answer — exactly like the permission block. It never carries
|
|
760
|
+
* model text.
|
|
761
|
+
*/
|
|
762
|
+
question: DelegatePendingQuestion | null;
|
|
763
|
+
/** Present only on a `question` answer: derived from the operation as published. */
|
|
764
|
+
questionAnswerable?: boolean;
|
|
765
|
+
/** Present only on a `question` answer: always `false`, restated where it matters. */
|
|
766
|
+
grantsAccess?: false;
|
|
443
767
|
/**
|
|
444
768
|
* Present only when `reason` is `attention` AND the reminder is about repeated
|
|
445
769
|
* failures rather than silence. `null`/absent for an ordinary silence report, which
|
|
446
770
|
* keeps the two distinguishable without a new reason value.
|
|
447
771
|
*/
|
|
448
772
|
failure?: DelegateRepeatedFailure | null;
|
|
773
|
+
/**
|
|
774
|
+
* Present only when the caller asked to acknowledge one delivered reminder by its
|
|
775
|
+
* `eventId` (an `ackFailureEventId` on the observe/wait call). `acknowledged` is
|
|
776
|
+
* `true` when the exact pending event was cleared (or had already been cleared by
|
|
777
|
+
* an idempotent repeat); `false` with a `reason` (`unknown-event`, `superseded`,
|
|
778
|
+
* `no-pending`, `event-id-required`) when nothing was cleared — a wrong ack never
|
|
779
|
+
* silences a live reminder.
|
|
780
|
+
*/
|
|
781
|
+
/**
|
|
782
|
+
* Present only when the caller asked to acknowledge one delivered reminder by its
|
|
783
|
+
* `eventId` (an `ackFailureEventId` on the observe/wait call). `acknowledged` is
|
|
784
|
+
* `true` when the exact pending event was cleared (or had already been cleared by
|
|
785
|
+
* an idempotent repeat); `false` with a `reason` (`unknown-event`, `superseded`,
|
|
786
|
+
* `no-pending`, `event-id-required`) when nothing was cleared — a wrong ack never
|
|
787
|
+
* silences a live reminder, and an empty id is refused, not ignored. The FIRST
|
|
788
|
+
* verdict reported on a wait is frozen for that call: later observations do not
|
|
789
|
+
* overwrite it with an `unknown-event` from a disposed monitor or a settled task.
|
|
790
|
+
*/
|
|
791
|
+
failureAck?: {
|
|
792
|
+
acknowledged: boolean;
|
|
793
|
+
eventId: string | null;
|
|
794
|
+
reason: string | null;
|
|
795
|
+
};
|
|
449
796
|
activity: DelegateTaskActivity | null;
|
|
450
797
|
selfCheck: { episode: number | null; checkedAt: number | null; verdict: string | null } | null;
|
|
451
798
|
/**
|
package/src/index.js
CHANGED
|
@@ -59,7 +59,10 @@ import { resolveCodexActionSeam } from './codex/seam.js';
|
|
|
59
59
|
import { ReviewPreset } from './review/preset.js';
|
|
60
60
|
import { configureDelegatedSession, policyServicesOf } from './runtime/sandbox.js';
|
|
61
61
|
import { PermissionBridge, PERMISSION_DEFAULT_TIMEOUT_MS } from './runtime/permissions.js';
|
|
62
|
+
import { QuestionBridge } from './runtime/questions.js';
|
|
62
63
|
import { redactText, isSecretKey } from './config/redact.js';
|
|
64
|
+
import { approvalFeedbackMessage } from './runtime/agent-runner.js';
|
|
65
|
+
import { reportedVersion } from './version.js';
|
|
63
66
|
|
|
64
67
|
/** Stable Cordis plugin name; also the settings/document namespace. */
|
|
65
68
|
export const name = 'dsh-taskbridge';
|
|
@@ -109,6 +112,15 @@ export const Config = z.object({
|
|
|
109
112
|
export async function apply(ctx, config = {}) {
|
|
110
113
|
const logger = ctx.logger;
|
|
111
114
|
const dataDir = await resolveDataDir(ctx, config);
|
|
115
|
+
// Re-read THIS build's manifest on every activation.
|
|
116
|
+
//
|
|
117
|
+
// A host can replace the installed package on disk while this module stays loaded (a
|
|
118
|
+
// DSH hot update: `package.json` becomes 1.5.1-test.2, the code that is running is the
|
|
119
|
+
// new one). The process-lifetime manifest memo then still answers the PREVIOUS version,
|
|
120
|
+
// and this activation would stamp the Codex integration with it — so the next start,
|
|
121
|
+
// reading the real manifest, sees a freshly written file as operator-customised. One
|
|
122
|
+
// forced read per activation is the whole fix; nothing else bypasses the cache.
|
|
123
|
+
const pluginVersion = reportedVersion({ refresh: true }).version;
|
|
112
124
|
|
|
113
125
|
const settings = new SettingsService(dataDir);
|
|
114
126
|
// Read once at load so an unusable document fails the plugin loudly instead of
|
|
@@ -231,7 +243,7 @@ export async function apply(ctx, config = {}) {
|
|
|
231
243
|
// Startup only refreshes an agent file whose bytes match a shipped template.
|
|
232
244
|
// Agent creation and MCP registration remain explicit settings-page actions.
|
|
233
245
|
codex: resolveCodexActionSeam({
|
|
234
|
-
version:
|
|
246
|
+
version: pluginVersion,
|
|
235
247
|
// The automatic upgrade's protected backup location, inside this activation's own
|
|
236
248
|
// data directory: never the package, never the Codex home, never a user home. The
|
|
237
249
|
// seam supplies it to a caller that does not pass one, so the unattended MCP write
|
|
@@ -256,6 +268,15 @@ export async function apply(ctx, config = {}) {
|
|
|
256
268
|
getApprovalService: () => readOptionalApprovalService(ctx),
|
|
257
269
|
logger,
|
|
258
270
|
}),
|
|
271
|
+
// The ordinary-question bridge factory. It does NOT depend on the approval service:
|
|
272
|
+
// asking a question is not granting anything, so a run keeps its fail-closed `never`
|
|
273
|
+
// approval stance and may still ask. A question is only surfaced when the harness
|
|
274
|
+
// actually composes the native `userQuestions` seam; otherwise the factory returns
|
|
275
|
+
// null and nothing is registered, which is the safe default.
|
|
276
|
+
questionBridge: createQuestionBridgeFactory({
|
|
277
|
+
hasQuestionService: () => hasQuestionService(ctx),
|
|
278
|
+
logger,
|
|
279
|
+
}),
|
|
259
280
|
};
|
|
260
281
|
|
|
261
282
|
try {
|
|
@@ -284,7 +305,7 @@ export async function apply(ctx, config = {}) {
|
|
|
284
305
|
logger?.info?.(`dsh-delegate: Codex integration check skipped (${target.reason})`);
|
|
285
306
|
}
|
|
286
307
|
if (migration?.changed.includes('agent')) {
|
|
287
|
-
logger?.info?.(`dsh-delegate: refreshed a managed Codex agent template to ${
|
|
308
|
+
logger?.info?.(`dsh-delegate: refreshed a managed Codex agent template to ${pluginVersion}`);
|
|
288
309
|
}
|
|
289
310
|
if (migration?.changed.includes('mcp')) {
|
|
290
311
|
logger?.info?.('dsh-delegate: upgraded a stale managed Codex MCP entry in place');
|
|
@@ -409,7 +430,7 @@ export async function apply(ctx, config = {}) {
|
|
|
409
430
|
deps.engine = engine;
|
|
410
431
|
deps.describeRuntime = () => ({
|
|
411
432
|
plugin: name,
|
|
412
|
-
version:
|
|
433
|
+
version: pluginVersion,
|
|
413
434
|
schemaVersion: SCHEMA_VERSION,
|
|
414
435
|
// Facts an operator needs to reason about exposure. Never a secret.
|
|
415
436
|
bind: ctx.webServer?.host ?? null,
|
|
@@ -510,8 +531,18 @@ export async function apply(ctx, config = {}) {
|
|
|
510
531
|
});
|
|
511
532
|
}
|
|
512
533
|
|
|
513
|
-
/**
|
|
514
|
-
|
|
534
|
+
/**
|
|
535
|
+
* Version reported by the runtime facts block and stamped into the Codex integration.
|
|
536
|
+
*
|
|
537
|
+
* Read from the package manifest this build ships in, never written as a literal: two
|
|
538
|
+
* copies of one fact drift, and a host asking a pre-release build which version it is
|
|
539
|
+
* must not be told the last released number.
|
|
540
|
+
*
|
|
541
|
+
* There is deliberately NO module-level constant: a host hot update replaces the manifest
|
|
542
|
+
* under a running instance, so the value is taken per activation
|
|
543
|
+
* (`reportedVersion({ refresh: true })` at the top of {@link apply}) rather than frozen
|
|
544
|
+
* when this module was first loaded.
|
|
545
|
+
*/
|
|
515
546
|
|
|
516
547
|
/**
|
|
517
548
|
* Read the native approval service without turning absence into a throw.
|
|
@@ -570,6 +601,10 @@ function createPermissionBridgeFactory(options) {
|
|
|
570
601
|
// because that secret carries no credential-shaped TEXT at all.
|
|
571
602
|
redact: (text) => redactText(text),
|
|
572
603
|
isSecretKey,
|
|
604
|
+
// The REAL native message factory. Without it the bridge would fall back to a
|
|
605
|
+
// locally built object, and the note reaching the worker would be a look-alike
|
|
606
|
+
// rather than a message the native inbox normalised.
|
|
607
|
+
createUserMessage: approvalFeedbackMessage,
|
|
573
608
|
onPending: request?.onPending,
|
|
574
609
|
onSettled: request?.onSettled,
|
|
575
610
|
logger: options?.logger ?? null,
|
|
@@ -581,6 +616,54 @@ function createPermissionBridgeFactory(options) {
|
|
|
581
616
|
};
|
|
582
617
|
}
|
|
583
618
|
|
|
619
|
+
/**
|
|
620
|
+
* Whether this harness composes the native user-questions seam.
|
|
621
|
+
*
|
|
622
|
+
* Read live, per run, through the non-strict accessor: DSH may compose
|
|
623
|
+
* `ctx.userQuestions` after this plugin activated, and a missing seam is a fact (the
|
|
624
|
+
* worker's tool surface then simply has no `ask_user_question`), not a failure.
|
|
625
|
+
* @param {object} ctx - plugin context.
|
|
626
|
+
* @returns {boolean} true when the native service is present.
|
|
627
|
+
*/
|
|
628
|
+
function hasQuestionService(ctx) {
|
|
629
|
+
if (ctx === null || ctx === undefined || typeof ctx.get !== 'function') return false;
|
|
630
|
+
try {
|
|
631
|
+
return ctx.get('userQuestions', false) !== undefined && ctx.get('userQuestions', false) !== null;
|
|
632
|
+
} catch {
|
|
633
|
+
// A service whose read is refused is treated as absent, never as present.
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Build the ordinary-question bridge factory.
|
|
640
|
+
*
|
|
641
|
+
* A bridge is produced only when the harness composes the native question seam AND the
|
|
642
|
+
* Agent-scoped answerer can be registered, which is decided per run by the runner. The
|
|
643
|
+
* factory itself holds no task state: the observers belong to the engine, which is what
|
|
644
|
+
* records the phase and accounts the paused budget.
|
|
645
|
+
* @param {object} options - `hasQuestionService` (live predicate), `logger`.
|
|
646
|
+
* @returns {(request: object) => object | null} factory.
|
|
647
|
+
*/
|
|
648
|
+
function createQuestionBridgeFactory(options) {
|
|
649
|
+
return function questionBridge(request) {
|
|
650
|
+
const present = typeof options?.hasQuestionService === 'function' ? options.hasQuestionService() : false;
|
|
651
|
+
if (present !== true) return null;
|
|
652
|
+
try {
|
|
653
|
+
return new QuestionBridge({
|
|
654
|
+
taskId: request?.taskId,
|
|
655
|
+
connectionId: request?.connectionId,
|
|
656
|
+
onPending: request?.onPending,
|
|
657
|
+
onSettled: request?.onSettled,
|
|
658
|
+
logger: options?.logger ?? null,
|
|
659
|
+
});
|
|
660
|
+
} catch (error) {
|
|
661
|
+
options?.logger?.warn?.('dsh-delegate: the question bridge could not be constructed', String(error?.code ?? ''));
|
|
662
|
+
return null;
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
|
|
584
667
|
/**
|
|
585
668
|
* Resolve the plugin's own data directory.
|
|
586
669
|
*
|