@claudexor/orchestrator 3.0.4 → 3.1.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 (83) hide show
  1. package/dist/attemptFinalize.d.ts +200 -0
  2. package/dist/attemptFinalize.d.ts.map +1 -0
  3. package/dist/attemptFinalize.js +412 -0
  4. package/dist/attemptFinalize.js.map +1 -0
  5. package/dist/attemptTelemetry.d.ts +88 -7
  6. package/dist/attemptTelemetry.d.ts.map +1 -1
  7. package/dist/attemptTelemetry.js +276 -14
  8. package/dist/attemptTelemetry.js.map +1 -1
  9. package/dist/budgetFailure.d.ts +70 -0
  10. package/dist/budgetFailure.d.ts.map +1 -0
  11. package/dist/budgetFailure.js +114 -0
  12. package/dist/budgetFailure.js.map +1 -0
  13. package/dist/candidateEvidence.d.ts +55 -1
  14. package/dist/candidateEvidence.d.ts.map +1 -1
  15. package/dist/candidateEvidence.js +72 -0
  16. package/dist/candidateEvidence.js.map +1 -1
  17. package/dist/continuation.d.ts +77 -0
  18. package/dist/continuation.d.ts.map +1 -0
  19. package/dist/continuation.js +92 -0
  20. package/dist/continuation.js.map +1 -0
  21. package/dist/deepScanReducer.d.ts +148 -0
  22. package/dist/deepScanReducer.d.ts.map +1 -0
  23. package/dist/deepScanReducer.js +348 -0
  24. package/dist/deepScanReducer.js.map +1 -0
  25. package/dist/effortGovernance.d.ts +49 -0
  26. package/dist/effortGovernance.d.ts.map +1 -0
  27. package/dist/effortGovernance.js +35 -0
  28. package/dist/effortGovernance.js.map +1 -0
  29. package/dist/harnessFailure.d.ts +27 -0
  30. package/dist/harnessFailure.d.ts.map +1 -0
  31. package/dist/harnessFailure.js +61 -0
  32. package/dist/harnessFailure.js.map +1 -0
  33. package/dist/index.d.ts +1 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/orchestrator.d.ts +103 -16
  37. package/dist/orchestrator.d.ts.map +1 -1
  38. package/dist/orchestrator.js +1245 -327
  39. package/dist/orchestrator.js.map +1 -1
  40. package/dist/planQuestions.d.ts.map +1 -1
  41. package/dist/planQuestions.js +105 -50
  42. package/dist/planQuestions.js.map +1 -1
  43. package/dist/planRun.d.ts +15 -7
  44. package/dist/planRun.d.ts.map +1 -1
  45. package/dist/planRun.js +88 -42
  46. package/dist/planRun.js.map +1 -1
  47. package/dist/planTerminal.d.ts +36 -0
  48. package/dist/planTerminal.d.ts.map +1 -0
  49. package/dist/planTerminal.js +63 -0
  50. package/dist/planTerminal.js.map +1 -0
  51. package/dist/reviewerPanel.d.ts +4 -0
  52. package/dist/reviewerPanel.d.ts.map +1 -1
  53. package/dist/reviewerPanel.js +54 -9
  54. package/dist/reviewerPanel.js.map +1 -1
  55. package/dist/revisePrompt.d.ts +17 -0
  56. package/dist/revisePrompt.d.ts.map +1 -0
  57. package/dist/revisePrompt.js +15 -0
  58. package/dist/revisePrompt.js.map +1 -0
  59. package/dist/runSupport.d.ts +67 -2
  60. package/dist/runSupport.d.ts.map +1 -1
  61. package/dist/runSupport.js +86 -6
  62. package/dist/runSupport.js.map +1 -1
  63. package/dist/runTelemetryWriter.d.ts +6 -1
  64. package/dist/runTelemetryWriter.d.ts.map +1 -1
  65. package/dist/runTelemetryWriter.js +2 -0
  66. package/dist/runTelemetryWriter.js.map +1 -1
  67. package/dist/runTerminals.d.ts +15 -4
  68. package/dist/runTerminals.d.ts.map +1 -1
  69. package/dist/runTerminals.js +16 -1
  70. package/dist/runTerminals.js.map +1 -1
  71. package/dist/structuredOutput.d.ts +27 -0
  72. package/dist/structuredOutput.d.ts.map +1 -1
  73. package/dist/structuredOutput.js +65 -7
  74. package/dist/structuredOutput.js.map +1 -1
  75. package/dist/transientClassify.d.ts +59 -0
  76. package/dist/transientClassify.d.ts.map +1 -0
  77. package/dist/transientClassify.js +109 -0
  78. package/dist/transientClassify.js.map +1 -0
  79. package/dist/write-isolation.d.ts +11 -0
  80. package/dist/write-isolation.d.ts.map +1 -0
  81. package/dist/write-isolation.js +13 -0
  82. package/dist/write-isolation.js.map +1 -0
  83. package/package.json +17 -17
@@ -0,0 +1,200 @@
1
+ /**
2
+ * D-16 unified attempt finalizer.
3
+ *
4
+ * ONE owner for the "did this attempt deliver, and in what work_state?" decision
5
+ * — replacing the three divergent deliverable predicates (candidate diff||answer;
6
+ * planner no-error⇒delivered; read-only nonempty-report). It folds the raw
7
+ * intent-specific deliverable evidence with the model-authored WorkReport, the
8
+ * typed context signals, the harness error state, and the gates into:
9
+ * - a final `deliverablePresent`,
10
+ * - a `work_state` axis (orthogonal to lifecycle, INV-116),
11
+ * - a typed reason,
12
+ * - and the class of outcome (clean / veto / contract-failure / interrupted).
13
+ *
14
+ * The module is PURE (no I/O, no clock). The envelope compile/unwrap helpers
15
+ * live here too so the spec-build decision and the finalizer read one contract.
16
+ */
17
+ import { WorkReport, type HarnessCapabilities, type RunReason, type WorkReportSource, type WorkState } from "@claudexor/schema";
18
+ import type { ToolErrorRecord, WebEvidenceState } from "./attemptTelemetry.js";
19
+ /**
20
+ * How the WorkReport rides the wire for an active envelope (D-16c):
21
+ * - `constrained_json`: the whole final answer IS the `{work_report, output}`
22
+ * JSON (codex `--output-schema`; claude `--json-schema` WITH a caller schema).
23
+ * - `side_tool`: a `{work_report}`-only schema arms claude's StructuredOutput
24
+ * TOOL; the markdown final message stays the deliverable and the report rides
25
+ * the tool payload (surfaced on the final message's `work_report_side_tool`).
26
+ * - `instructed_fence`: no native constraint — the model is INSTRUCTED to end
27
+ * its answer with a fenced `{work_report, output}` JSON block, validated off
28
+ * the last fenced JSON (cursor).
29
+ */
30
+ export type WorkReportChannel = "constrained_json" | "side_tool" | "instructed_fence";
31
+ /** The per-attempt envelope decision made at spec build and consumed by the
32
+ * unwrap. `active` means the orchestrator actually armed a WorkReport transport
33
+ * for this route, so a missing/malformed report is a typed contract failure. */
34
+ export interface WorkReportEnvelopeMode {
35
+ active: boolean;
36
+ source: WorkReportSource;
37
+ hasCallerSchema: boolean;
38
+ channel: WorkReportChannel;
39
+ /** Instruction to APPEND to the spec (instructed_fence only); null otherwise. */
40
+ instruction: string | null;
41
+ }
42
+ /**
43
+ * The instruction appended to an `instructed_fence` (cursor) route so the model
44
+ * emits the WorkReport envelope the finalizer validates. No native schema
45
+ * constrains cursor, so the contract is instructed and validated off the last
46
+ * fenced JSON block (D-16c). The `output` string carries the deliverable prose.
47
+ */
48
+ export declare const WORK_REPORT_FENCE_INSTRUCTION: string;
49
+ /** Result of the spec-build envelope decision. */
50
+ export interface ResolvedWorkReportEnvelope {
51
+ /** What rides HarnessRunSpec.output_schema (undefined = leave unset). */
52
+ outputSchema: Record<string, unknown> | undefined;
53
+ mode: WorkReportEnvelopeMode;
54
+ }
55
+ /**
56
+ * Decide the transport envelope for one route at spec build (D-16 §2). The
57
+ * caller's ORIGINAL schema stays the conformance authority for `output` (it is
58
+ * NOT passed here strictified for validation — only the transport copy is).
59
+ *
60
+ * Activated HERE directly for `constrained` routes that natively constrain
61
+ * output and are not interactive-gated (the WorkReport rides the
62
+ * `{work_report, output}` envelope; claude's no-caller `side_tool` case instead
63
+ * arms a `{work_report}`-only schema on the StructuredOutput tool so the markdown
64
+ * final stays the deliverable — the D-16c seam), and for `validated` routes
65
+ * (cursor), where the report rides an INSTRUCTED fenced envelope. Only
66
+ * interactive-gated and schema-incapable routes stay inactive here (disclosed
67
+ * `absent` work_state).
68
+ */
69
+ export declare function resolveWorkReportEnvelope(opts: {
70
+ transport: HarnessCapabilities["work_report_transport"];
71
+ channel: HarnessCapabilities["structured_output_channel"];
72
+ supportsJsonSchemaOutput: boolean;
73
+ interactive: boolean;
74
+ callerSchema: Record<string, unknown> | null;
75
+ }): ResolvedWorkReportEnvelope;
76
+ /** The unwrapped attempt answer plus the extracted WorkReport (or a typed
77
+ * contract violation). `deliverable` is what answer.md / the caller-schema
78
+ * validator must see — never the envelope. */
79
+ export interface UnwrappedAnswer {
80
+ deliverable: string;
81
+ workReport: WorkReport | null;
82
+ source: WorkReportSource;
83
+ /** Non-null when an active route failed to carry a valid WorkReport. */
84
+ contractViolation: string | null;
85
+ }
86
+ /**
87
+ * Un-nest the WorkReport envelope from an active route's answer (D-16 §2). The
88
+ * behavior forks on `mode.channel`:
89
+ * - `constrained_json`: the whole answer IS `{work_report, output}` JSON.
90
+ * - `instructed_fence`: the envelope is the LAST fenced JSON block; prose
91
+ * before it is discarded (the `output` string is the deliverable).
92
+ * - `side_tool`: the answer text IS the markdown deliverable; the report rides
93
+ * `opts.sideToolReport` (the tool payload the adapter surfaced).
94
+ * A non-active mode passes the answer through untouched. The WorkReport
95
+ * cross-field rules (completed ⇒ no required_inputs; needs_input ⇒ ≥1) are
96
+ * enforced HERE so a broken report is a typed contract violation.
97
+ *
98
+ * For a `constrained_json` route `answerText` is the raw `{work_report, output}`
99
+ * envelope (codex #19816 / QA-009: the orchestrator passes `answer.machineText()`,
100
+ * which yields the raw envelope even when the codex adapter pre-unwrapped the
101
+ * DISPLAY copy of the final message — the visible stream sees the output, the
102
+ * un-nest here still sees the envelope).
103
+ */
104
+ export declare function unwrapWorkReportEnvelope(answerText: string, mode: WorkReportEnvelopeMode, opts?: {
105
+ sideToolReport?: unknown;
106
+ }): UnwrappedAnswer;
107
+ /**
108
+ * QA-036: the terminal outcome facts for a read-only (ask) run that produced NO
109
+ * successful attempt. The D8 legacy mapping treated ANY web-blocked run as a
110
+ * succeeded/review_blocked terminal (exit 0, "Needs review"); a blocked Ask that
111
+ * delivered nothing then read as done. This re-checks the DELIVERABLE: only a
112
+ * blocked attempt that actually produced a partial answer is a review-blocked
113
+ * SUCCESS; an empty blocked (or plain failed) run is a failure (exit 1).
114
+ */
115
+ export declare function readOnlyNoSuccessTerminal(opts: {
116
+ webBlocked: boolean;
117
+ hasDeliverable: boolean;
118
+ budgetStopped: boolean;
119
+ attemptsCount: number;
120
+ }): {
121
+ lifecycle: "succeeded" | "failed";
122
+ review?: "blocked";
123
+ reason: RunReason;
124
+ };
125
+ /** Everything the finalizer folds for one attempt. The gate/web/belt axes are
126
+ * NOT folded here — the finalizer decides deliverable+work_state, and
127
+ * `setAttemptOutcome` runs the status math over gates/web/belt on top (so a
128
+ * `completed` claim with a failed gate still yields a failed status there). */
129
+ export interface FinalizeAttemptInput {
130
+ /** Raw intent-specific deliverable evidence (diff/answer/report present). */
131
+ deliverableEvidence: boolean;
132
+ harnessErrored: boolean;
133
+ workReport: WorkReport | null;
134
+ workReportSource: WorkReportSource;
135
+ /** Non-null when an active route failed its WorkReport contract. */
136
+ workReportViolation: string | null;
137
+ /** A terminal capacity_exhausted context signal was observed this attempt. */
138
+ contextTerminalExhausted: boolean;
139
+ }
140
+ /** Outcome class the run-level terminal maps onto lifecycle/facts. */
141
+ export type AttemptOutcomeClass = "clean" | "veto" | "contract_failure" | "interrupted";
142
+ export interface FinalizeAttemptResult {
143
+ /** Final deliverable presence (a completed claim never invents evidence). */
144
+ deliverablePresent: boolean;
145
+ /** Final harness-error state (a contract failure elevates it). */
146
+ harnessErrored: boolean;
147
+ workState: WorkState;
148
+ /** Typed reason for the veto/failure; null on a clean outcome. */
149
+ reason: RunReason | null;
150
+ outcomeClass: AttemptOutcomeClass;
151
+ }
152
+ /**
153
+ * The unified finalizer. Precedence (hardest signal wins):
154
+ * 1. terminal context exhaustion with no completed report ⇒ interrupted;
155
+ * 2. a broken WorkReport contract on a constrained route ⇒ hard failure
156
+ * (never prose-success);
157
+ * 3. a valid needs_input/incomplete report ⇒ veto (lifecycle stays, run is
158
+ * non-applyable, exit non-zero) — a `completed` claim NEVER overrides a
159
+ * harness error / failed gate / missing evidence;
160
+ * 4. otherwise the disclosed work_state (completed or unverified).
161
+ */
162
+ export declare function finalizeAttempt(input: FinalizeAttemptInput): FinalizeAttemptResult;
163
+ /**
164
+ * The deliverable exception for tool hygiene (INV-043/INV-044), shared by every
165
+ * read-only intent so planner and explorer cannot drift apart again.
166
+ *
167
+ * An unrecovered tool error is tool hygiene, not a terminal state: on an attempt
168
+ * that DELIVERED its contracted deliverable it stays disclosed warning evidence
169
+ * (`toolWarnings` counts it and `setAttemptOutcome` lands `success_with_warnings`)
170
+ * instead of discarding a produced answer or plan. Only a deliverable-LESS
171
+ * attempt escalates the FIRST unrecovered error into a hard harness error.
172
+ *
173
+ * `deliverableEvidence` MUST be the same raw evidence boolean `finalizeAttempt`
174
+ * folds — the unwrapped D-16 deliverable, never the pre-envelope answer text —
175
+ * so the WorkReport contract stays the one owner of what "delivered" means.
176
+ * This decides ONLY the tool-error axis: required-but-unsatisfied web evidence
177
+ * keeps its own hard gate, and the finalizer's contract-failure and interrupted
178
+ * classes still outrank whatever this returns.
179
+ *
180
+ * Returns the harness-error message to escalate, or null to leave the errors as
181
+ * warning evidence.
182
+ */
183
+ export declare function unrecoveredToolErrorFailure(unrecovered: readonly ToolErrorRecord[], deliverableEvidence: boolean): string | null;
184
+ /**
185
+ * The harness-error message for required-but-unsatisfied web evidence, shared by
186
+ * every lane that reports it so the web axis has the SAME single owner as the
187
+ * tool-error axis above and the two cannot drift apart.
188
+ *
189
+ * This is a message builder only — it neither decides that the evidence is
190
+ * unsatisfied (`webUnsatisfied` owns that) nor changes the axis precedence: web
191
+ * stays a HARD gate that an attempt cannot buy off with a deliverable, unlike
192
+ * the tool-error exception, and the finalizer's contract-failure and interrupted
193
+ * classes still outrank it at the call site.
194
+ *
195
+ * The reason falls back through the telemetry the same way in every lane: the
196
+ * recorded `errorSummary` when there is one, else an unrecovered-web-tool reason
197
+ * when web was attempted at all, else a never-attempted reason.
198
+ */
199
+ export declare function webEvidenceFailure(web: Pick<WebEvidenceState, "attempted" | "errorSummary">): string;
200
+ //# sourceMappingURL=attemptFinalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attemptFinalize.d.ts","sourceRoot":"","sources":["../src/attemptFinalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAGL,UAAU,EACV,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,S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;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,SAAS,eAAe,EAAE,EACvC,mBAAmB,EAAE,OAAO,GAC3B,MAAM,GAAG,IAAI,CAIf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,cAAc,CAAC,GACxD,MAAM,CAER"}
@@ -0,0 +1,412 @@
1
+ /**
2
+ * D-16 unified attempt finalizer.
3
+ *
4
+ * ONE owner for the "did this attempt deliver, and in what work_state?" decision
5
+ * — replacing the three divergent deliverable predicates (candidate diff||answer;
6
+ * planner no-error⇒delivered; read-only nonempty-report). It folds the raw
7
+ * intent-specific deliverable evidence with the model-authored WorkReport, the
8
+ * typed context signals, the harness error state, and the gates into:
9
+ * - a final `deliverablePresent`,
10
+ * - a `work_state` axis (orthogonal to lifecycle, INV-116),
11
+ * - a typed reason,
12
+ * - and the class of outcome (clean / veto / contract-failure / interrupted).
13
+ *
14
+ * The module is PURE (no I/O, no clock). The envelope compile/unwrap helpers
15
+ * live here too so the spec-build decision and the finalizer read one contract.
16
+ */
17
+ import { buildWorkReportEnvelope, strictifyOutputSchema, WorkReport, } from "@claudexor/schema";
18
+ import { redactSecrets } from "@claudexor/util";
19
+ /**
20
+ * The instruction appended to an `instructed_fence` (cursor) route so the model
21
+ * emits the WorkReport envelope the finalizer validates. No native schema
22
+ * constrains cursor, so the contract is instructed and validated off the last
23
+ * fenced JSON block (D-16c). The `output` string carries the deliverable prose.
24
+ */
25
+ export const WORK_REPORT_FENCE_INSTRUCTION = [
26
+ "When you have finished, end your reply with a single fenced ```json code block",
27
+ "containing exactly this object and nothing after it:",
28
+ '{"work_report": {"state": "completed" | "needs_input" | "incomplete",',
29
+ '"required_inputs": [{"kind": "file"|"context"|"credential"|"permission"|"decision"|"external_dependency",',
30
+ '"locator": string|null, "description": string}]}, "output": "<your final answer as a string>"}.',
31
+ 'Use state "completed" only when the task is fully done with an empty required_inputs list;',
32
+ 'use "needs_input" (with at least one required_inputs entry) when you are blocked on a missing input;',
33
+ 'use "incomplete" when partial work remains. This block is mandatory.',
34
+ ].join(" ");
35
+ /**
36
+ * Decide the transport envelope for one route at spec build (D-16 §2). The
37
+ * caller's ORIGINAL schema stays the conformance authority for `output` (it is
38
+ * NOT passed here strictified for validation — only the transport copy is).
39
+ *
40
+ * Activated HERE directly for `constrained` routes that natively constrain
41
+ * output and are not interactive-gated (the WorkReport rides the
42
+ * `{work_report, output}` envelope; claude's no-caller `side_tool` case instead
43
+ * arms a `{work_report}`-only schema on the StructuredOutput tool so the markdown
44
+ * final stays the deliverable — the D-16c seam), and for `validated` routes
45
+ * (cursor), where the report rides an INSTRUCTED fenced envelope. Only
46
+ * interactive-gated and schema-incapable routes stay inactive here (disclosed
47
+ * `absent` work_state).
48
+ */
49
+ export function resolveWorkReportEnvelope(opts) {
50
+ const hasCallerSchema = opts.callerSchema !== null;
51
+ const callerStrict = hasCallerSchema
52
+ ? strictifyOutputSchema(opts.callerSchema)
53
+ : null;
54
+ // claude's `--json-schema` × interactive stream-json is an unverified combo:
55
+ // disclose the WorkReport transport as unsupported for that lane (§1).
56
+ const interactiveGated = opts.channel === "side_tool" && opts.interactive;
57
+ // `validated` transport (cursor): no native schema constrains the output —
58
+ // the WorkReport rides an INSTRUCTED fenced envelope validated off the last
59
+ // fenced JSON (D-16c). Caller schemas on such routes were already refused by
60
+ // the mandatory-schema gate upstream, so this is the WorkReport-only case.
61
+ if (opts.transport === "validated" && !interactiveGated) {
62
+ return {
63
+ outputSchema: callerStrict ?? undefined,
64
+ mode: {
65
+ active: true,
66
+ source: "validated",
67
+ hasCallerSchema,
68
+ channel: "instructed_fence",
69
+ instruction: WORK_REPORT_FENCE_INSTRUCTION,
70
+ },
71
+ };
72
+ }
73
+ const active = opts.transport === "constrained" && opts.supportsJsonSchemaOutput && !interactiveGated;
74
+ if (active) {
75
+ // claude side_tool WITHOUT a caller schema (D-16c): arm a {work_report}-only
76
+ // schema on the StructuredOutput tool; the markdown final message stays the
77
+ // deliverable and the report rides the tool payload. Every other constrained
78
+ // case carries the output INSIDE the `{work_report, output}` envelope
79
+ // (caller schema → the strict S; no-caller final_message → output:string).
80
+ if (opts.channel === "side_tool" && !hasCallerSchema) {
81
+ return {
82
+ outputSchema: buildWorkReportEnvelope(null),
83
+ mode: {
84
+ active: true,
85
+ source: "constrained",
86
+ hasCallerSchema,
87
+ channel: "side_tool",
88
+ instruction: null,
89
+ },
90
+ };
91
+ }
92
+ const output = hasCallerSchema
93
+ ? callerStrict
94
+ : "string";
95
+ return {
96
+ outputSchema: buildWorkReportEnvelope(output),
97
+ mode: {
98
+ active: true,
99
+ source: "constrained",
100
+ hasCallerSchema,
101
+ channel: "constrained_json",
102
+ instruction: null,
103
+ },
104
+ };
105
+ }
106
+ return {
107
+ // Legacy path preserved: a caller schema still rides (strictified) on a
108
+ // non-activated route (the mandatory-schema gate already refused
109
+ // schema-incapable routes upstream).
110
+ outputSchema: callerStrict ?? undefined,
111
+ mode: {
112
+ active: false,
113
+ source: "absent",
114
+ hasCallerSchema,
115
+ channel: "constrained_json",
116
+ instruction: null,
117
+ },
118
+ };
119
+ }
120
+ function extractOutput(obj, mode) {
121
+ const output = obj["output"];
122
+ if (mode.hasCallerSchema) {
123
+ // Re-serialize the S-conformant object so finalizeStructuredOutput can
124
+ // JSON.parse + validate it against the caller schema (the caller schema is
125
+ // the conformance authority for `output`, so any shape rides through here).
126
+ return { deliverable: output === undefined ? "" : JSON.stringify(output) };
127
+ }
128
+ // No caller schema: `output` MUST be a string deliverable. A non-string
129
+ // (object/array/null/number/bool) or missing `output` is a BROKEN envelope —
130
+ // coercing it (String({...}) => "[object Object]") would let a bogus payload
131
+ // like {"work_report":{"state":"completed"},"output":{}} finalize CLEAN
132
+ // instead of failing the WorkReport contract. Fail it here (D-16 §2).
133
+ if (typeof output !== "string") {
134
+ return { violation: "work_report envelope output must be a string" };
135
+ }
136
+ return { deliverable: output };
137
+ }
138
+ /** Extract the LAST fenced ```…``` block's body (its optional language tag
139
+ * stripped), or null when the text has no closed fence. No-regex, mechanical
140
+ * transport parsing (INV-049 governs the typed WorkReport, not this seam). */
141
+ function lastFencedBlock(text) {
142
+ const FENCE = "```";
143
+ const end = text.lastIndexOf(FENCE);
144
+ if (end <= 0)
145
+ return null;
146
+ const start = text.lastIndexOf(FENCE, end - 1);
147
+ if (start < 0)
148
+ return null;
149
+ let inner = text.slice(start + FENCE.length, end);
150
+ const nl = inner.indexOf("\n");
151
+ if (nl >= 0) {
152
+ const firstLine = inner.slice(0, nl).trim();
153
+ // A bare language tag (letters/digits/±_-, no whitespace) on the opening
154
+ // line is dropped; a first line that is already JSON content is kept.
155
+ const isLangTag = firstLine.length > 0 &&
156
+ firstLine.length <= 20 &&
157
+ ![...firstLine].some((ch) => ch === " " || ch === "{" || ch === "[" || ch === '"');
158
+ if (firstLine === "" || isLangTag)
159
+ inner = inner.slice(nl + 1);
160
+ }
161
+ return inner.trim();
162
+ }
163
+ /**
164
+ * Un-nest the WorkReport envelope from an active route's answer (D-16 §2). The
165
+ * behavior forks on `mode.channel`:
166
+ * - `constrained_json`: the whole answer IS `{work_report, output}` JSON.
167
+ * - `instructed_fence`: the envelope is the LAST fenced JSON block; prose
168
+ * before it is discarded (the `output` string is the deliverable).
169
+ * - `side_tool`: the answer text IS the markdown deliverable; the report rides
170
+ * `opts.sideToolReport` (the tool payload the adapter surfaced).
171
+ * A non-active mode passes the answer through untouched. The WorkReport
172
+ * cross-field rules (completed ⇒ no required_inputs; needs_input ⇒ ≥1) are
173
+ * enforced HERE so a broken report is a typed contract violation.
174
+ *
175
+ * For a `constrained_json` route `answerText` is the raw `{work_report, output}`
176
+ * envelope (codex #19816 / QA-009: the orchestrator passes `answer.machineText()`,
177
+ * which yields the raw envelope even when the codex adapter pre-unwrapped the
178
+ * DISPLAY copy of the final message — the visible stream sees the output, the
179
+ * un-nest here still sees the envelope).
180
+ */
181
+ export function unwrapWorkReportEnvelope(answerText, mode, opts = {}) {
182
+ if (!mode.active) {
183
+ return {
184
+ deliverable: answerText,
185
+ workReport: null,
186
+ source: mode.source,
187
+ contractViolation: null,
188
+ };
189
+ }
190
+ // side_tool: the markdown answer stays the deliverable; the report is the tool
191
+ // payload. A missing/malformed tool report is a typed contract failure.
192
+ if (mode.channel === "side_tool") {
193
+ if (opts.sideToolReport === undefined) {
194
+ return {
195
+ deliverable: answerText,
196
+ workReport: null,
197
+ source: mode.source,
198
+ contractViolation: "the StructuredOutput tool did not carry a work_report",
199
+ };
200
+ }
201
+ return validateWorkReport(answerText, opts.sideToolReport, mode.source);
202
+ }
203
+ let text = answerText.trim();
204
+ if (mode.channel === "instructed_fence") {
205
+ const fenced = lastFencedBlock(answerText);
206
+ if (fenced === null) {
207
+ return {
208
+ deliverable: answerText,
209
+ workReport: null,
210
+ source: mode.source,
211
+ contractViolation: "final answer has no fenced work_report envelope",
212
+ };
213
+ }
214
+ text = fenced;
215
+ }
216
+ let parsed;
217
+ try {
218
+ parsed = JSON.parse(text);
219
+ }
220
+ catch {
221
+ return {
222
+ deliverable: answerText,
223
+ workReport: null,
224
+ source: mode.source,
225
+ contractViolation: "final answer is not the JSON work_report envelope",
226
+ };
227
+ }
228
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
229
+ return {
230
+ deliverable: answerText,
231
+ workReport: null,
232
+ source: mode.source,
233
+ contractViolation: "work_report envelope is not a JSON object",
234
+ };
235
+ }
236
+ const obj = parsed;
237
+ const extracted = extractOutput(obj, mode);
238
+ if ("violation" in extracted) {
239
+ return {
240
+ deliverable: answerText,
241
+ workReport: null,
242
+ source: mode.source,
243
+ contractViolation: extracted.violation,
244
+ };
245
+ }
246
+ return validateWorkReport(extracted.deliverable, obj["work_report"], mode.source);
247
+ }
248
+ /** Parse + cross-field-validate a raw work_report value against a resolved
249
+ * deliverable. The cross-field rules (completed ⇒ no required_inputs;
250
+ * needs_input ⇒ ≥1) live HERE, not on the permissive Zod wire type. */
251
+ function validateWorkReport(deliverable, rawReport, source) {
252
+ const wr = WorkReport.safeParse(rawReport);
253
+ if (!wr.success) {
254
+ return {
255
+ deliverable,
256
+ workReport: null,
257
+ source,
258
+ contractViolation: `work_report missing or malformed: ${wr.error.issues[0]?.message ?? "invalid"}`,
259
+ };
260
+ }
261
+ // ONE redaction owner for every WorkReport transport: the model-authored
262
+ // locator/description strings flow VERBATIM into telemetry yaml, decision
263
+ // facts, and the CLI needsInputLabel — the last reads the local artifact and
264
+ // bypasses serve-time redaction — so a token pasted into a required_input
265
+ // would otherwise persist unredacted at rest. Redact here, before the report
266
+ // is handed to any of them. (The cross-field checks below read only state and
267
+ // list length, so redaction order does not affect them.)
268
+ const report = {
269
+ ...wr.data,
270
+ required_inputs: wr.data.required_inputs.map((ri) => ({
271
+ ...ri,
272
+ locator: ri.locator === null ? null : redactSecrets(ri.locator),
273
+ description: redactSecrets(ri.description),
274
+ })),
275
+ };
276
+ if (report.state === "completed" && report.required_inputs.length > 0) {
277
+ return {
278
+ deliverable,
279
+ workReport: null,
280
+ source,
281
+ contractViolation: "a completed work_report must not list required_inputs",
282
+ };
283
+ }
284
+ if (report.state === "needs_input" && report.required_inputs.length === 0) {
285
+ return {
286
+ deliverable,
287
+ workReport: null,
288
+ source,
289
+ contractViolation: "a needs_input work_report must list at least one required_input",
290
+ };
291
+ }
292
+ return { deliverable, workReport: report, source, contractViolation: null };
293
+ }
294
+ /**
295
+ * QA-036: the terminal outcome facts for a read-only (ask) run that produced NO
296
+ * successful attempt. The D8 legacy mapping treated ANY web-blocked run as a
297
+ * succeeded/review_blocked terminal (exit 0, "Needs review"); a blocked Ask that
298
+ * delivered nothing then read as done. This re-checks the DELIVERABLE: only a
299
+ * blocked attempt that actually produced a partial answer is a review-blocked
300
+ * SUCCESS; an empty blocked (or plain failed) run is a failure (exit 1).
301
+ */
302
+ export function readOnlyNoSuccessTerminal(opts) {
303
+ if (opts.webBlocked && opts.hasDeliverable) {
304
+ return { lifecycle: "succeeded", review: "blocked", reason: "review_blocked" };
305
+ }
306
+ if (opts.budgetStopped && opts.attemptsCount === 0) {
307
+ return { lifecycle: "failed", reason: "budget_exhausted" };
308
+ }
309
+ return { lifecycle: "failed", reason: "harness_failed" };
310
+ }
311
+ /**
312
+ * The unified finalizer. Precedence (hardest signal wins):
313
+ * 1. terminal context exhaustion with no completed report ⇒ interrupted;
314
+ * 2. a broken WorkReport contract on a constrained route ⇒ hard failure
315
+ * (never prose-success);
316
+ * 3. a valid needs_input/incomplete report ⇒ veto (lifecycle stays, run is
317
+ * non-applyable, exit non-zero) — a `completed` claim NEVER overrides a
318
+ * harness error / failed gate / missing evidence;
319
+ * 4. otherwise the disclosed work_state (completed or unverified).
320
+ */
321
+ export function finalizeAttempt(input) {
322
+ const completed = input.workReport?.state === "completed";
323
+ if (input.contextTerminalExhausted && !completed) {
324
+ return {
325
+ deliverablePresent: input.deliverableEvidence,
326
+ harnessErrored: input.harnessErrored,
327
+ workState: { state: "unverified", source: input.workReportSource },
328
+ reason: "context_capacity_exhausted",
329
+ outcomeClass: "interrupted",
330
+ };
331
+ }
332
+ if (input.workReportViolation) {
333
+ return {
334
+ deliverablePresent: false,
335
+ // A constrained route that promised a WorkReport and broke the contract
336
+ // failed the attempt — it must never terminalize as a prose success.
337
+ harnessErrored: true,
338
+ workState: { state: "unverified", source: input.workReportSource },
339
+ reason: "work_report_contract",
340
+ outcomeClass: "contract_failure",
341
+ };
342
+ }
343
+ const report = input.workReport;
344
+ if (report && (report.state === "needs_input" || report.state === "incomplete")) {
345
+ return {
346
+ deliverablePresent: input.deliverableEvidence,
347
+ harnessErrored: input.harnessErrored,
348
+ workState: {
349
+ state: report.state,
350
+ source: input.workReportSource,
351
+ ...(report.required_inputs.length > 0 ? { required_inputs: report.required_inputs } : {}),
352
+ },
353
+ reason: report.state === "needs_input" ? "input_required" : "work_incomplete",
354
+ outcomeClass: "veto",
355
+ };
356
+ }
357
+ return {
358
+ deliverablePresent: input.deliverableEvidence,
359
+ harnessErrored: input.harnessErrored,
360
+ workState: {
361
+ state: report?.state === "completed" ? "completed" : "unverified",
362
+ source: report ? input.workReportSource : "absent",
363
+ },
364
+ reason: null,
365
+ outcomeClass: "clean",
366
+ };
367
+ }
368
+ /**
369
+ * The deliverable exception for tool hygiene (INV-043/INV-044), shared by every
370
+ * read-only intent so planner and explorer cannot drift apart again.
371
+ *
372
+ * An unrecovered tool error is tool hygiene, not a terminal state: on an attempt
373
+ * that DELIVERED its contracted deliverable it stays disclosed warning evidence
374
+ * (`toolWarnings` counts it and `setAttemptOutcome` lands `success_with_warnings`)
375
+ * instead of discarding a produced answer or plan. Only a deliverable-LESS
376
+ * attempt escalates the FIRST unrecovered error into a hard harness error.
377
+ *
378
+ * `deliverableEvidence` MUST be the same raw evidence boolean `finalizeAttempt`
379
+ * folds — the unwrapped D-16 deliverable, never the pre-envelope answer text —
380
+ * so the WorkReport contract stays the one owner of what "delivered" means.
381
+ * This decides ONLY the tool-error axis: required-but-unsatisfied web evidence
382
+ * keeps its own hard gate, and the finalizer's contract-failure and interrupted
383
+ * classes still outrank whatever this returns.
384
+ *
385
+ * Returns the harness-error message to escalate, or null to leave the errors as
386
+ * warning evidence.
387
+ */
388
+ export function unrecoveredToolErrorFailure(unrecovered, deliverableEvidence) {
389
+ if (deliverableEvidence)
390
+ return null;
391
+ const first = unrecovered[0];
392
+ return first ? `${first.tool} failed without recovery: ${first.summary}` : null;
393
+ }
394
+ /**
395
+ * The harness-error message for required-but-unsatisfied web evidence, shared by
396
+ * every lane that reports it so the web axis has the SAME single owner as the
397
+ * tool-error axis above and the two cannot drift apart.
398
+ *
399
+ * This is a message builder only — it neither decides that the evidence is
400
+ * unsatisfied (`webUnsatisfied` owns that) nor changes the axis precedence: web
401
+ * stays a HARD gate that an attempt cannot buy off with a deliverable, unlike
402
+ * the tool-error exception, and the finalizer's contract-failure and interrupted
403
+ * classes still outrank it at the call site.
404
+ *
405
+ * The reason falls back through the telemetry the same way in every lane: the
406
+ * recorded `errorSummary` when there is one, else an unrecovered-web-tool reason
407
+ * when web was attempted at all, else a never-attempted reason.
408
+ */
409
+ export function webEvidenceFailure(web) {
410
+ return `web evidence unsatisfied: ${web.errorSummary ?? (web.attempted ? "web tool failed without verified recovery" : "web evidence required but never attempted")}`;
411
+ }
412
+ //# sourceMappingURL=attemptFinalize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attemptFinalize.js","sourceRoot":"","sources":["../src/attemptFinalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,UAAU,GAKX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA4BhD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,gFAAgF;IAChF,sDAAsD;IACtD,uEAAuE;IACvE,2GAA2G;IAC3G,iGAAiG;IACjG,4FAA4F;IAC5F,sGAAsG;IACtG,sEAAsE;CACvE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AASZ;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,yBAAyB,CAAC,IAMzC;IACC,MAAM,eAAe,GAAG,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC;IACnD,MAAM,YAAY,GAAG,eAAe;QAClC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,YAAuC,CAAC;QACrE,CAAC,CAAC,IAAI,CAAC;IACT,6EAA6E;IAC7E,uEAAuE;IACvE,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,KAAK,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC;IAE1E,2EAA2E;IAC3E,4EAA4E;IAC5E,6EAA6E;IAC7E,2EAA2E;IAC3E,IAAI,IAAI,CAAC,SAAS,KAAK,WAAW,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxD,OAAO;YACL,YAAY,EAAE,YAAY,I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