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.
Files changed (44) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/README.md +10 -8
  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 +180 -16
  6. package/docs/INTRODUCTION.md +2 -2
  7. package/docs/INTRODUCTION.zh.md +2 -2
  8. package/docs/codex-integration.md +11 -13
  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/releases/1.5.1.zh.md +70 -0
  15. package/docs/runtime-compatibility.md +4 -4
  16. package/docs/silent-wait.md +157 -3
  17. package/docs/taskbridge-upgrade.md +1 -1
  18. package/docs/worker-permissions.md +154 -17
  19. package/lib/client.js +298 -103
  20. package/package.json +9 -3
  21. package/src/client/api.js +315 -34
  22. package/src/client/index.jsx +151 -67
  23. package/src/codex/installer.js +251 -11
  24. package/src/config/redact.js +72 -11
  25. package/src/http/execution-plane.js +124 -10
  26. package/src/index.d.ts +347 -0
  27. package/src/index.js +88 -5
  28. package/src/jobs/activity.js +102 -9
  29. package/src/jobs/continuation-identity.js +283 -0
  30. package/src/jobs/engine.js +491 -55
  31. package/src/jobs/history.js +96 -0
  32. package/src/mcp/continuation.js +317 -0
  33. package/src/mcp/metrics.js +366 -0
  34. package/src/mcp/server.js +1203 -53
  35. package/src/mcp/wait.js +338 -73
  36. package/src/review/prompts.js +145 -126
  37. package/src/runtime/agent-runner.js +330 -0
  38. package/src/runtime/permissions.js +192 -2
  39. package/src/runtime/question-call.js +162 -0
  40. package/src/runtime/questions.js +909 -0
  41. package/src/runtime/sandbox.js +363 -358
  42. package/src/runtime/session-placement.js +1207 -1121
  43. package/src/version.js +121 -0
  44. package/src/workspace/worktrees.js +70 -4
@@ -573,6 +573,14 @@ function projectView(view, maxEntryBytes, options = {}) {
573
573
  sourcePath: path(view.sourcePath, ctx, 'sourcePath'),
574
574
  workspacePath: path(view.workspacePath, ctx, 'workspacePath'),
575
575
  executionWorkspacePath: path(view.executionWorkspacePath, ctx, 'executionWorkspacePath'),
576
+ // The verifiable continuation identity stored beside those paths. A digest is
577
+ // opaque to redaction, so a row whose path a projection shortened can still prove
578
+ // which directory it named; a row without one proves nothing and is refused by a
579
+ // follow-up. Nothing here is executable material or conversation content.
580
+ sourcePathDigest: digest(view.sourcePathDigest),
581
+ executionPathDigest: digest(view.executionPathDigest),
582
+ workspaceId: label(view.workspaceId),
583
+ sessionId: label(view.sessionId),
576
584
  isolation: knownValue(view.isolation, ['worktree', 'shared']),
577
585
  interruptedFrom: knownValue(view.interruptedFrom, ['pending', 'running']),
578
586
  // The connection identity is provenance: which external connection asked for
@@ -605,6 +613,12 @@ function projectView(view, maxEntryBytes, options = {}) {
605
613
  error: errorView(view.error, ctx),
606
614
  cancelledBy: label(view.cancelledBy),
607
615
  hostAcceptance: acceptance,
616
+ // The per-task Agent Teams decision (frozen at admission) and what DSH's own service
617
+ // confirmed for the run. Booleans and a bounded reason string only: `null` means the
618
+ // dispatcher made no choice, so a restored record can tell "not asked" from "asked",
619
+ // and "applied" from "asked but unapplied".
620
+ agentTeams: typeof view.agentTeams === 'boolean' ? view.agentTeams : null,
621
+ team: teamView(view.team, ctx),
608
622
  // A completed job is not an accepted one. This is fixed, never copied.
609
623
  selfApproved: false,
610
624
  };
@@ -947,6 +961,37 @@ function permissionEntryView(value, ctx, field) {
947
961
  reusable: grant.reusable === true,
948
962
  },
949
963
  standingModeUnchanged: value.standingModeUnchanged === true,
964
+ // Whether the commander's rejection reason actually reached the worker, and — only when
965
+ // it did — the exact text. Stored because "the worker was told why" is a claim that must
966
+ // be checkable after a restart, and bounded so one long note cannot grow the record.
967
+ rejectionFeedback: rejectionFeedbackView(value.rejectionFeedback, ctx, `${field}.rejectionFeedback`),
968
+ };
969
+ }
970
+
971
+ /**
972
+ * Bounded projection of one rejection-feedback outcome.
973
+ *
974
+ * `delivered` and `reason` are kept VERBATIM (they are a closed vocabulary and the fact the
975
+ * record exists to state). `text` is kept only when delivery succeeded — a failed note has
976
+ * nothing to quote — and is bounded, because it is prose.
977
+ * @param {unknown} value - the delivered/not-delivered outcome.
978
+ * @param {object} ctx - cut context.
979
+ * @param {string} field - field label for a cut.
980
+ * @returns {object | null} bounded copy.
981
+ */
982
+ function rejectionFeedbackView(value, ctx, field) {
983
+ if (!isPlainObject(value)) return null;
984
+ const delivered = value.delivered === true;
985
+ const quoted = delivered && typeof value.text === 'string' && value.text !== ''
986
+ ? text(value.text, ctx, field, MAX_MESSAGE_CHARS)
987
+ : null;
988
+ return {
989
+ delivered,
990
+ reason: label(value.reason),
991
+ requestId: label(value.requestId),
992
+ callId: label(value.callId),
993
+ messageId: label(value.messageId),
994
+ text: quoted,
950
995
  };
951
996
  }
952
997
 
@@ -1028,6 +1073,28 @@ function markPermissionInterrupted(entry) {
1028
1073
  * @param {unknown} value - task `activity` block.
1029
1074
  * @returns {object | null} bounded copy, or null when the task never ran.
1030
1075
  */
1076
+ /**
1077
+ * Project one run's Agent Teams outcome for storage.
1078
+ *
1079
+ * Allow-list only: three booleans (or null) and one bounded reason. The selection itself
1080
+ * belongs to the DSH Session, not to this record, so nothing here can turn a global
1081
+ * switch on when a record is read back.
1082
+ * @param {unknown} value - run `team` fact.
1083
+ * @param {object} ctx - cut context.
1084
+ * @returns {{ requested: boolean|null, supported: boolean, applied: boolean, enabled: boolean|null, reason: string|null } | null} bounded fact.
1085
+ */
1086
+ function teamView(value, ctx) {
1087
+ if (!isPlainObject(value)) return null;
1088
+ return {
1089
+ requested: typeof value.requested === 'boolean' ? value.requested : null,
1090
+ supported: value.supported === true,
1091
+ applied: value.applied === true,
1092
+ enabled: typeof value.enabled === 'boolean' ? value.enabled : null,
1093
+ reason: boundedReason(value.reason, ctx, 'team.reason'),
1094
+ };
1095
+ }
1096
+
1097
+ /** @param {object} value - activity summary view. @returns {object|null} bounded activity view. */
1031
1098
  function activityView(value) {
1032
1099
  if (!isPlainObject(value)) return null;
1033
1100
  const tool = isPlainObject(value.currentTool) ? value.currentTool : null;
@@ -1473,6 +1540,21 @@ function label(value) {
1473
1540
  return value.slice(0, MAX_LABEL_CHARS);
1474
1541
  }
1475
1542
 
1543
+ /**
1544
+ * A short, bounded reason string (a code or a one-line diagnostic), cut once and
1545
+ * the cut stated.
1546
+ * @param {unknown} value - reason.
1547
+ * @param {object} ctx - cut context.
1548
+ * @param {string} field - field label used when the value had to be cut.
1549
+ * @returns {string | null} bounded reason, or null when absent.
1550
+ */
1551
+ function boundedReason(value, ctx, field) {
1552
+ if (typeof value !== 'string' || value === '') return null;
1553
+ if (value.length <= MAX_LABEL_CHARS) return value;
1554
+ if (ctx !== null && ctx !== undefined) ctx.fields.add(field);
1555
+ return value.slice(0, MAX_LABEL_CHARS);
1556
+ }
1557
+
1476
1558
  /**
1477
1559
  * @param {unknown} value - path.
1478
1560
  * @param {object} [ctx] - cut context; omitted for project-owned paths.
@@ -1486,6 +1568,20 @@ function path(value, ctx = null, field = '') {
1486
1568
  return value.slice(0, MAX_PATH_CHARS);
1487
1569
  }
1488
1570
 
1571
+ /**
1572
+ * A stored continuation digest, kept verbatim when well formed.
1573
+ *
1574
+ * A digest is fixed-length and opaque, so it is never shortened: a cut digest would
1575
+ * compare unequal to every real directory and turn "provable" into "refused" without
1576
+ * saying so. A value that is not a well-formed digest is dropped, which is the same
1577
+ * as the row having none — the follow-up then refuses rather than guesses.
1578
+ * @param {unknown} value - candidate digest.
1579
+ * @returns {string | null} the digest, or null.
1580
+ */
1581
+ function digest(value) {
1582
+ return typeof value === 'string' && /^sha256:[0-9a-f]{64}$/u.test(value) ? value : null;
1583
+ }
1584
+
1489
1585
  /**
1490
1586
  * @param {unknown} value - value to read.
1491
1587
  * @param {string} field - field label for truncation reporting.
@@ -0,0 +1,317 @@
1
+ // The two predicates the post-decision continuation needs — and nothing else.
2
+ //
3
+ // `delegate_permission_decide({ waitAfterDecision: true })` answers in the SAME shape a
4
+ // `delegate_wait` answers in, because the commander's next decision is the same decision
5
+ // either way. That means the continuation must be THE wait loop (`./wait.js`): the same
6
+ // 25-second internal observation, the same default deadline, the same heartbeat handling,
7
+ // the same `interrupted` classification and the same bounded deadline semantics. This
8
+ // module therefore contains no loop, no timeout and no reason vocabulary of its own; it
9
+ // supplies only the two facts the shared loop cannot know:
10
+ //
11
+ // 1. **Rollover.** After a decision the engine may still publish the settled request in
12
+ // `task.permission.pending` until the paused native call actually resumes (the
13
+ // bridge's `onSettled` fires when the call continues, not when the decision is made).
14
+ // A loop that answered that would present the commander's own decision back as a new
15
+ // question. {@link decidedRequestMatcher} is the predicate the shared loop uses to
16
+ // keep waiting, and it matches on the FULL identity — `requestId` AND `fingerprint` —
17
+ // so a new request id, or the same id with a changed operation, is never inherited.
18
+ //
19
+ // 2. **Receipt evidence.** {@link decisionReceipt} reads the harness's answer to the
20
+ // decision and states exactly what can be proven about it, including the case where
21
+ // the transport failed and nobody can know whether it was applied.
22
+
23
+ /**
24
+ * The pending operation a wait-shaped answer carries, if any.
25
+ * @param {object | null | undefined} observation - an observation.
26
+ * @returns {object | null} the pending operation.
27
+ */
28
+ export function pendingOperationOf(observation) {
29
+ const block = observation?.permission;
30
+ if (block === null || typeof block !== 'object') return null;
31
+ const operation = block.pending !== undefined ? block.pending : block;
32
+ if (operation === null || typeof operation !== 'object' || Array.isArray(operation)) return null;
33
+ return operation;
34
+ }
35
+
36
+ /**
37
+ * Build the predicate that decides whether an observation describes the request this call
38
+ * already decided.
39
+ *
40
+ * The match requires BOTH the request id and the fingerprint. That is the whole rule:
41
+ *
42
+ * * same id, same fingerprint → the settled request still in its slot → keep waiting;
43
+ * * a different request id → a NEW question → answered immediately;
44
+ * * same id, different fingerprint → the operation changed → a NEW question, because a
45
+ * decision is bound to one exact operation and inheriting it would grant an operation
46
+ * the commander never reviewed.
47
+ *
48
+ * Cost asymmetry: wrongly treating a settled request as new costs one host turn; wrongly
49
+ * treating a new request as settled would leave a worker paused with nothing reported. So
50
+ * every field is required to match, and nothing is assumed.
51
+ * @param {{ requestId?: string | null, fingerprint?: string | null }} receipt - the decision.
52
+ * @returns {(observation: object) => boolean} predicate for the shared wait loop.
53
+ */
54
+ export function decidedRequestMatcher(receipt) {
55
+ const requestId = typeof receipt?.requestId === 'string' && receipt.requestId !== '' ? receipt.requestId : null;
56
+ const fingerprint = typeof receipt?.fingerprint === 'string' && receipt.fingerprint !== ''
57
+ ? receipt.fingerprint
58
+ : null;
59
+ if (requestId === null || fingerprint === null) {
60
+ // Without BOTH halves of the identity nothing can be proven to be the decided request,
61
+ // so nothing is skipped: a request already settled is refused by the engine as
62
+ // `PERMISSION_REQUEST_NOT_PENDING`, which is a refusal the host can act on.
63
+ return () => false;
64
+ }
65
+ return (observation) => {
66
+ const operation = pendingOperationOf(observation);
67
+ if (operation === null) return false;
68
+ return operation.requestId === requestId && operation.fingerprint === fingerprint;
69
+ };
70
+ }
71
+
72
+ /**
73
+ * The ONE settled state that means "this request was decided".
74
+ *
75
+ * `expired`, `cancelled` and `unavailable` are settled records too, but none of them is a
76
+ * decision this call applied — an `expired` request carrying a stale `allowed-once` outcome
77
+ * is exactly the shape that must never read as confirmed.
78
+ */
79
+ const CONFIRMED_STATE = 'decided';
80
+
81
+ /** The closed native outcomes a settled allow/reject record can carry. */
82
+ const SETTLED_OUTCOMES = Object.freeze(['allowed-once', 'rejected', 'cancelled', 'unavailable']);
83
+
84
+ /**
85
+ * The verification checks an `allowed-once` must report as TRUE to confirm the allow.
86
+ *
87
+ * These are the four claims the harness makes when it grants one call: the caller quoted the
88
+ * fingerprint, the arguments were complete, the operation was re-read from the Session log,
89
+ * and the turn was still open. A record that reports any of them false is not evidence for an
90
+ * allow, whatever its `outcome` says. A `reject` needs none of them.
91
+ */
92
+ const VERIFIED_REQUIRED = Object.freeze(['fingerprintQuoted', 'argumentsComplete', 'callReread', 'turnOpen']);
93
+
94
+ const asString = (value) => (typeof value === 'string' && value !== '' ? value : null);
95
+
96
+ /**
97
+ * What can honestly be said about one decision, from the harness's own answer.
98
+ *
99
+ * The ONLY thing that makes a decision `applied` is a permission answer whose own fields
100
+ * confirm it, and the check is deliberately strict because a false `applied: true` is the
101
+ * worst outcome this tool can produce: it tells a commander an authorization is in force
102
+ * when it is not (or one operation when another was settled). The real permission route
103
+ * answers:
104
+ *
105
+ * ```js
106
+ * { ok: true,
107
+ * task: { taskId, ... },
108
+ * permission: { taskId, requestId, fingerprint, state: 'decided',
109
+ * outcome: 'allowed-once' | 'rejected', verified?, grant?, decision? } }
110
+ * ```
111
+ *
112
+ * `decision` is sometimes `null` in the real bridge, so it is NOT required; the settled
113
+ * `outcome` is. `verified`/`grant` exist only for an `allowed-once`, so a `reject` is never
114
+ * required to have them.
115
+ *
116
+ * Two outcomes, and the difference between them is the point:
117
+ *
118
+ * * **applied** — the answer is `ok: true`, names the SAME task (both task ids, when both
119
+ * appear, must agree), the SAME request and the SAME operation fingerprint the decision
120
+ * was bound to, is in state `decided`, and its `outcome` matches the decision
121
+ * (`allowed-once` for allow-once, `rejected` for reject). An allow additionally needs
122
+ * every {@link VERIFIED_REQUIRED} check to be true. Only then is the decision in force.
123
+ * * **unknown** — the call failed before an answer existed (transport, timeout, malformed
124
+ * body), or the answer is `ok: false`, or it lacks the evidence above, or its identity
125
+ * CONTRADICTS the request that was decided. Nobody can say whether the decision applied,
126
+ * so it is never claimed, never continued and never resent automatically.
127
+ * * **refused** — the harness's own refusal code: the decision was definitely not applied.
128
+ *
129
+ * A QUOTED fingerprint must be matched by evidence. The caller's value is never silently
130
+ * replaced by a conflicting backend one, and an answer that omits it cannot confirm that
131
+ * operation. A `reject` that quoted no fingerprint is not required to produce one.
132
+ * @param {object} options - `taskId`, `requestId`, `decision`, `fingerprint` (the quoted one,
133
+ * or null), `answer` (the harness answer, or null), `error` (the thrown failure, or null).
134
+ * @returns {{ applied: boolean | null, confirmation: 'applied' | 'unknown' | 'refused',
135
+ * taskId: string | null, requestId: string | null, decision: 'allow-once' | 'reject' | null,
136
+ * fingerprint: string | null, outcome?: string, verified?: object, grant?: object,
137
+ * decidedAt?: number, reason?: string, error?: object, evidence?: object }} the receipt fields.
138
+ */
139
+ export function decisionReceipt(options) {
140
+ const error = options.error ?? null;
141
+ const answer = options.answer ?? null;
142
+ const settled = answer?.permission ?? null;
143
+ const answerTask = answer?.task ?? null;
144
+ const requestedTaskId = asString(options.taskId);
145
+ const requestedRequestId = asString(options.requestId);
146
+ const quotedFingerprint = asString(options.fingerprint);
147
+ const decision = options.decision === 'allow-once' || options.decision === 'reject'
148
+ ? options.decision
149
+ : null;
150
+
151
+ /** The identity the receipt may safely publish: only values the caller itself supplied. */
152
+ const identity = {
153
+ taskId: requestedTaskId,
154
+ requestId: requestedRequestId,
155
+ decision,
156
+ fingerprint: quotedFingerprint,
157
+ };
158
+
159
+ /** Build an UNCONFIRMED receipt that keeps the caller's own identity and says why. */
160
+ const unconfirmed = (reason, extra = {}) => ({
161
+ ...identity,
162
+ // Never `false`: "not applied" would be a fact nobody established.
163
+ applied: null,
164
+ confirmation: 'unknown',
165
+ reason,
166
+ ...extra,
167
+ });
168
+
169
+ if (error !== null) {
170
+ const code = typeof error.code === 'string' ? error.code : 'MCP_CALL_FAILED';
171
+ // A refusal the harness produced is a fact about the decision; every other failure
172
+ // happened before an answer existed, so the outcome is genuinely unknown.
173
+ if (options.refusedByHarness === true) {
174
+ return {
175
+ ...identity,
176
+ applied: false,
177
+ confirmation: 'refused',
178
+ error: { code, message: 'the harness refused this decision' },
179
+ };
180
+ }
181
+ return unconfirmed(
182
+ 'the decision call did not produce a harness answer, so whether it was applied is unknown; '
183
+ + 'read the task\'s real state with delegate_result before deciding whether to send it again',
184
+ { error: { code, message: 'the decision could not be confirmed' } },
185
+ );
186
+ }
187
+
188
+ // ---- What the answer itself proves -------------------------------------------------
189
+ if (answer === null || typeof answer !== 'object' || answer.ok !== true) {
190
+ return unconfirmed('the harness answer was not ok, so the decision cannot be confirmed as applied');
191
+ }
192
+ if (settled === null || typeof settled !== 'object' || Array.isArray(settled)) {
193
+ return unconfirmed('the harness answer carried no settled permission record to confirm the decision');
194
+ }
195
+ const settledTaskId = asString(settled.taskId);
196
+ const outerTaskId = asString(answerTask?.taskId);
197
+ const answerRequestId = asString(settled.requestId);
198
+ const answerFingerprint = asString(settled.fingerprint);
199
+ const answerState = asString(settled.state);
200
+ const answerOutcome = asString(settled.outcome);
201
+ if (answerRequestId === null || answerState === null || answerOutcome === null) {
202
+ return unconfirmed('the harness answer did not carry the identity and outcome needed to confirm the decision', {
203
+ evidence: { taskId: settledTaskId ?? outerTaskId, requestId: answerRequestId, state: answerState, outcome: answerOutcome },
204
+ });
205
+ }
206
+ // Identity must MATCH what was decided. A different task, request or operation is a
207
+ // CONTRADICTION: the answer describes something this call did not decide.
208
+ //
209
+ // BOTH task ids are checked when both appear, and they must ALSO agree with each other. A
210
+ // matching outer `task.taskId` cannot vouch for a settled record that names another task:
211
+ // the settled record is the thing being confirmed, so an internal disagreement means the
212
+ // answer is not one coherent settlement of this task.
213
+ if (settledTaskId !== null && outerTaskId !== null && settledTaskId !== outerTaskId) {
214
+ return unconfirmed('the harness answer contradicted itself: its task and its settled record name different tasks', {
215
+ evidence: { answeredTaskId: settledTaskId, surroundingTaskId: outerTaskId },
216
+ });
217
+ }
218
+ const answerTaskId = settledTaskId ?? outerTaskId;
219
+ if (answerTaskId === null) {
220
+ return unconfirmed('the harness answer did not name the task it settled', {
221
+ evidence: { taskId: null },
222
+ });
223
+ }
224
+ if (requestedTaskId !== null && answerTaskId !== requestedTaskId) {
225
+ return unconfirmed('the harness confirmed a DIFFERENT task than the one this decision named', {
226
+ evidence: { answeredTaskId: answerTaskId },
227
+ });
228
+ }
229
+ if (requestedRequestId !== null && answerRequestId !== requestedRequestId) {
230
+ return unconfirmed('the harness confirmed a DIFFERENT request than the one this decision named', {
231
+ evidence: { answeredRequestId: answerRequestId },
232
+ });
233
+ }
234
+ // The operation is part of the identity. A QUOTED fingerprint must be matched by evidence:
235
+ // an answer that omits it cannot confirm that THIS operation was settled, and a conflicting
236
+ // backend value is never allowed to replace the quoted one.
237
+ if (quotedFingerprint !== null) {
238
+ if (answerFingerprint === null) {
239
+ return unconfirmed('the harness settled without reporting the operation fingerprint this decision quoted', {
240
+ evidence: { answeredFingerprint: null },
241
+ });
242
+ }
243
+ if (answerFingerprint !== quotedFingerprint) {
244
+ return unconfirmed('the harness settled a DIFFERENT operation than the fingerprint this decision quoted', {
245
+ evidence: { answeredFingerprint: answerFingerprint },
246
+ });
247
+ }
248
+ }
249
+ // Only `decided` is a settled DECISION. `expired`, `cancelled` and `unavailable` are also
250
+ // settled records, but none of them means "this decision was applied".
251
+ if (answerState !== CONFIRMED_STATE) {
252
+ return unconfirmed(`the harness reported state ${JSON.stringify(answerState)}, which is not a decided request`, {
253
+ evidence: { state: answerState },
254
+ });
255
+ }
256
+ if (!SETTLED_OUTCOMES.includes(answerOutcome)) {
257
+ return unconfirmed(`the harness reported outcome ${JSON.stringify(answerOutcome)}, which is not a settled decision`, {
258
+ evidence: { outcome: answerOutcome },
259
+ });
260
+ }
261
+ // The outcome must be the one this decision asked for. `allowed-once` is the only grant,
262
+ // and a reject must read `rejected`; anything else is not this decision's confirmation.
263
+ const expectedOutcome = decision === 'allow-once' ? 'allowed-once' : decision === 'reject' ? 'rejected' : null;
264
+ if (expectedOutcome === null) {
265
+ return unconfirmed('the decision argument was not a recognized decision');
266
+ }
267
+ if (answerOutcome !== expectedOutcome) {
268
+ return unconfirmed(
269
+ `the harness settled ${JSON.stringify(answerOutcome)}, not the ${JSON.stringify(expectedOutcome)} this decision asked for`,
270
+ { evidence: { outcome: answerOutcome } },
271
+ );
272
+ }
273
+ // An allow must be backed by the checks it claims, and every required one must be TRUE: a
274
+ // record whose own verification says the fingerprint was not quoted, the arguments were not
275
+ // complete, the call was not re-read or the turn was not open is not evidence for an allow.
276
+ // A reject needs none of them.
277
+ if (decision === 'allow-once') {
278
+ const verified = settled.verified;
279
+ if (verified === null || typeof verified !== 'object' || Array.isArray(verified)) {
280
+ return unconfirmed('an allowed-once was reported without the verification evidence an allow requires');
281
+ }
282
+ const failed = VERIFIED_REQUIRED.filter((key) => verified[key] !== true);
283
+ if (failed.length > 0) {
284
+ return unconfirmed(
285
+ `an allowed-once reported verification that does not hold (${failed.join(', ')}), so it cannot confirm the allow`,
286
+ { evidence: { unverified: failed } },
287
+ );
288
+ }
289
+ }
290
+ return {
291
+ taskId: answerTaskId,
292
+ requestId: answerRequestId,
293
+ decision,
294
+ // The confirmed operation. It equals the quoted fingerprint here — a mismatch returned
295
+ // above — so publishing the harness's own value is a restatement, not a substitution.
296
+ fingerprint: answerFingerprint ?? quotedFingerprint,
297
+ applied: true,
298
+ confirmation: 'applied',
299
+ outcome: answerOutcome,
300
+ ...(settled.verified !== undefined ? { verified: settled.verified } : {}),
301
+ ...(settled.decidedAt !== undefined ? { decidedAt: settled.decidedAt } : {}),
302
+ ...(settled.grant !== undefined ? { grant: settled.grant } : {}),
303
+ // Whether the rejection reason reached the worker, stated as the SHORT fact only. The
304
+ // note text is the worker's own message and is stored in history; repeating it here
305
+ // would multiply the receipt for no gain, so only delivery and its reason travel.
306
+ ...(settled.rejectionFeedback !== undefined && settled.rejectionFeedback !== null
307
+ ? {
308
+ rejectionFeedback: {
309
+ delivered: settled.rejectionFeedback.delivered === true,
310
+ reason: typeof settled.rejectionFeedback.reason === 'string'
311
+ ? settled.rejectionFeedback.reason
312
+ : null,
313
+ },
314
+ }
315
+ : {}),
316
+ };
317
+ }