create-principles-disciple 1.148.8 → 1.148.10

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 (180) hide show
  1. package/_release/product-identity.json +1 -1
  2. package/codex-adapter/package.json +1 -1
  3. package/console/dist/server/config/WorkspaceConfigStore.js +4 -3
  4. package/console/dist/server/console-ports.d.ts +13 -0
  5. package/console/dist/server/console-ports.js +15 -0
  6. package/console/dist/server/index.js +51 -5
  7. package/console/dist/server/routes/update-transaction.js +4 -4
  8. package/console/dist/server/routes/update.js +37 -21
  9. package/console/dist/server/utils/gateway.js +23 -6
  10. package/console/dist/server/utils/installed-layout.js +5 -3
  11. package/console/dist/server/utils/pd-backups.d.ts +6 -4
  12. package/console/dist/server/utils/pd-backups.js +8 -9
  13. package/console/dist/server/utils/pd-home.d.ts +34 -0
  14. package/console/dist/server/utils/pd-home.js +47 -0
  15. package/console/dist/web/assets/app.js +1 -1
  16. package/console/package.json +1 -1
  17. package/core/dist/index.d.ts +2 -2
  18. package/core/dist/index.d.ts.map +1 -1
  19. package/core/dist/index.js +2 -2
  20. package/core/dist/index.js.map +1 -1
  21. package/core/dist/runtime/adapter/output-schema-registry.d.ts +4 -3
  22. package/core/dist/runtime/adapter/output-schema-registry.d.ts.map +1 -1
  23. package/core/dist/runtime/adapter/output-schema-registry.js +9 -5
  24. package/core/dist/runtime/adapter/output-schema-registry.js.map +1 -1
  25. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts +1 -1
  26. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  27. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +10 -3
  28. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
  29. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts +31 -0
  30. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
  31. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js +55 -0
  32. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js.map +1 -1
  33. package/core/dist/runtime/adapter/schema-prompt-adapter.d.ts.map +1 -1
  34. package/core/dist/runtime/adapter/schema-prompt-adapter.js +48 -9
  35. package/core/dist/runtime/adapter/schema-prompt-adapter.js.map +1 -1
  36. package/core/dist/runtime/adapter/split-pipeline-fixtures.d.ts +2 -2
  37. package/core/dist/runtime/adapter/split-pipeline-fixtures.d.ts.map +1 -1
  38. package/core/dist/runtime/adapter/split-pipeline-fixtures.js +11 -0
  39. package/core/dist/runtime/adapter/split-pipeline-fixtures.js.map +1 -1
  40. package/core/dist/runtime/adapter/test-double-runtime-adapter.d.ts +3 -3
  41. package/core/dist/runtime/adapter/test-double-runtime-adapter.d.ts.map +1 -1
  42. package/core/dist/runtime/adapter/test-double-runtime-adapter.js +9 -3
  43. package/core/dist/runtime/adapter/test-double-runtime-adapter.js.map +1 -1
  44. package/core/dist/runtime/admission-gate.d.ts +2 -2
  45. package/core/dist/runtime/candidate-intake-service.d.ts.map +1 -1
  46. package/core/dist/runtime/candidate-intake-service.js +176 -13
  47. package/core/dist/runtime/candidate-intake-service.js.map +1 -1
  48. package/core/dist/runtime/diagnostician/router-prompt-builder.d.ts +42 -7
  49. package/core/dist/runtime/diagnostician/router-prompt-builder.d.ts.map +1 -1
  50. package/core/dist/runtime/diagnostician/router-prompt-builder.js +53 -10
  51. package/core/dist/runtime/diagnostician/router-prompt-builder.js.map +1 -1
  52. package/core/dist/runtime/diagnostician-association-shadow.d.ts +111 -4
  53. package/core/dist/runtime/diagnostician-association-shadow.d.ts.map +1 -1
  54. package/core/dist/runtime/diagnostician-association-shadow.js +206 -3
  55. package/core/dist/runtime/diagnostician-association-shadow.js.map +1 -1
  56. package/core/dist/runtime/diagnostician-output.d.ts +67 -84
  57. package/core/dist/runtime/diagnostician-output.d.ts.map +1 -1
  58. package/core/dist/runtime/diagnostician-output.js +90 -41
  59. package/core/dist/runtime/diagnostician-output.js.map +1 -1
  60. package/core/dist/runtime/index.d.ts +3 -3
  61. package/core/dist/runtime/index.d.ts.map +1 -1
  62. package/core/dist/runtime/index.js +3 -3
  63. package/core/dist/runtime/index.js.map +1 -1
  64. package/core/dist/runtime/internalization/artifact-summary.js +1 -1
  65. package/core/dist/runtime/internalization/diag-router-runner.d.ts +49 -12
  66. package/core/dist/runtime/internalization/diag-router-runner.d.ts.map +1 -1
  67. package/core/dist/runtime/internalization/diag-router-runner.js +135 -30
  68. package/core/dist/runtime/internalization/diag-router-runner.js.map +1 -1
  69. package/core/dist/runtime/internalization/formation-context.d.ts +2 -2
  70. package/core/dist/runtime/internalization/formation-context.js +2 -2
  71. package/core/dist/runtime/internalization/internalization-route.d.ts +15 -2
  72. package/core/dist/runtime/internalization/internalization-route.d.ts.map +1 -1
  73. package/core/dist/runtime/internalization/internalization-route.js +5 -2
  74. package/core/dist/runtime/internalization/internalization-route.js.map +1 -1
  75. package/core/dist/runtime/internalization/router-context-evidence.d.ts +148 -6
  76. package/core/dist/runtime/internalization/router-context-evidence.d.ts.map +1 -1
  77. package/core/dist/runtime/internalization/router-context-evidence.js +156 -11
  78. package/core/dist/runtime/internalization/router-context-evidence.js.map +1 -1
  79. package/core/dist/runtime/internalization/router-context-reconstruction.d.ts +64 -0
  80. package/core/dist/runtime/internalization/router-context-reconstruction.d.ts.map +1 -0
  81. package/core/dist/runtime/internalization/router-context-reconstruction.js +124 -0
  82. package/core/dist/runtime/internalization/router-context-reconstruction.js.map +1 -0
  83. package/core/dist/runtime/pain-signal-bridge.d.ts +3 -3
  84. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  85. package/core/dist/runtime/pain-signal-bridge.js +35 -9
  86. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  87. package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
  88. package/core/dist/runtime/pain-signal-runtime-factory.js +32 -4
  89. package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
  90. package/core/dist/runtime/principle-tree/rule-candidate-binding.d.ts.map +1 -1
  91. package/core/dist/runtime/principle-tree/rule-candidate-binding.js +9 -5
  92. package/core/dist/runtime/principle-tree/rule-candidate-binding.js.map +1 -1
  93. package/core/dist/runtime/runner/base-peer-runner.d.ts +18 -4
  94. package/core/dist/runtime/runner/base-peer-runner.d.ts.map +1 -1
  95. package/core/dist/runtime/runner/base-peer-runner.js +32 -9
  96. package/core/dist/runtime/runner/base-peer-runner.js.map +1 -1
  97. package/core/dist/runtime/runner/context-hash.d.ts +9 -0
  98. package/core/dist/runtime/runner/context-hash.d.ts.map +1 -0
  99. package/core/dist/runtime/runner/context-hash.js +18 -0
  100. package/core/dist/runtime/runner/context-hash.js.map +1 -0
  101. package/core/dist/runtime/runner/default-validator.d.ts +3 -3
  102. package/core/dist/runtime/runner/default-validator.d.ts.map +1 -1
  103. package/core/dist/runtime/runner/default-validator.js +149 -85
  104. package/core/dist/runtime/runner/default-validator.js.map +1 -1
  105. package/core/dist/runtime/runner/diagnostician-validator.d.ts +11 -9
  106. package/core/dist/runtime/runner/diagnostician-validator.d.ts.map +1 -1
  107. package/core/dist/runtime/runner/peer-runner-types.d.ts +14 -2
  108. package/core/dist/runtime/runner/peer-runner-types.d.ts.map +1 -1
  109. package/core/dist/runtime/runner/runner-result.d.ts +2 -2
  110. package/core/dist/runtime/runtime-protocol.d.ts +8 -0
  111. package/core/dist/runtime/runtime-protocol.d.ts.map +1 -1
  112. package/core/dist/runtime/runtime-protocol.js +8 -0
  113. package/core/dist/runtime/runtime-protocol.js.map +1 -1
  114. package/core/dist/runtime/store/commit/diagnostician-committer.d.ts +4 -4
  115. package/core/dist/runtime/store/commit/diagnostician-committer.d.ts.map +1 -1
  116. package/core/dist/runtime/store/commit/diagnostician-committer.js +27 -8
  117. package/core/dist/runtime/store/commit/diagnostician-committer.js.map +1 -1
  118. package/core/dist/runtime/store/pain-diagnosis/pain-diagnosis-store.d.ts +2 -2
  119. package/core/dist/runtime/store/pain-diagnosis/pain-diagnosis-store.js +1 -1
  120. package/core/dist/runtime/store/run/memory-run-store.d.ts +1 -1
  121. package/core/dist/runtime/store/run/memory-run-store.d.ts.map +1 -1
  122. package/core/dist/runtime/store/run/memory-run-store.js.map +1 -1
  123. package/core/dist/runtime/store/run/run-store.d.ts +1 -1
  124. package/core/dist/runtime/store/run/run-store.d.ts.map +1 -1
  125. package/core/dist/runtime/store/run/sqlite-run-store.d.ts +1 -1
  126. package/core/dist/runtime/store/run/sqlite-run-store.d.ts.map +1 -1
  127. package/core/dist/runtime/store/run/sqlite-run-store.js +4 -0
  128. package/core/dist/runtime/store/run/sqlite-run-store.js.map +1 -1
  129. package/core/dist/runtime/store/runtime-state-manager.d.ts +1 -1
  130. package/core/dist/runtime/store/runtime-state-manager.js +1 -1
  131. package/core/dist/runtime/synthetic-baseline.d.ts +2 -2
  132. package/core/dist/runtime/synthetic-baseline.d.ts.map +1 -1
  133. package/core/dist/runtime/synthetic-baseline.js +2 -0
  134. package/core/dist/runtime/synthetic-baseline.js.map +1 -1
  135. package/core/dist/runtime/types/evidence-chain-contract.d.ts +1 -1
  136. package/core/dist/runtime/types/evidence-chain-contract.js +2 -2
  137. package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
  138. package/core/dist/runtime/types/rule-candidate-binding.d.ts +10 -2
  139. package/core/dist/runtime/types/rule-candidate-binding.d.ts.map +1 -1
  140. package/core/dist/telemetry-event.d.ts +2 -2
  141. package/core/dist/telemetry-event.d.ts.map +1 -1
  142. package/core/dist/telemetry-event.js +19 -0
  143. package/core/dist/telemetry-event.js.map +1 -1
  144. package/core/package.json +1 -1
  145. package/dist/update/bootstrap-executor.d.ts.map +1 -1
  146. package/dist/update/bootstrap-executor.js +33 -19
  147. package/dist/update/bootstrap-executor.js.map +1 -1
  148. package/host-runtime/dist/workspace-telemetry-emitter.js +13 -0
  149. package/host-runtime/package.json +1 -1
  150. package/install-layout/dist/index.d.ts +7 -0
  151. package/install-layout/dist/index.js +7 -0
  152. package/install-layout/dist/pd-home.d.ts +55 -0
  153. package/install-layout/dist/pd-home.js +226 -0
  154. package/install-layout/package.json +1 -1
  155. package/package.json +4 -4
  156. package/pd-cli/dist/commands/candidate.js.map +1 -1
  157. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  158. package/pd-cli/dist/commands/diagnose.js +14 -5
  159. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  160. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  161. package/pd-cli/dist/commands/pain-retry.js +18 -7
  162. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  163. package/pd-cli/dist/services/demo-story-a-runner.js +2 -2
  164. package/pd-cli/dist/services/demo-story-a-runner.js.map +1 -1
  165. package/pd-cli/dist/services/pain-flood-simulation-runner.d.ts.map +1 -1
  166. package/pd-cli/dist/services/pain-flood-simulation-runner.js +4 -1
  167. package/pd-cli/dist/services/pain-flood-simulation-runner.js.map +1 -1
  168. package/pd-cli/dist/services/synthetic-baseline-runner.d.ts.map +1 -1
  169. package/pd-cli/dist/services/synthetic-baseline-runner.js +5 -1
  170. package/pd-cli/dist/services/synthetic-baseline-runner.js.map +1 -1
  171. package/pd-cli/package.json +1 -1
  172. package/pd-mcp-server/dist/version.d.ts +1 -1
  173. package/pd-mcp-server/dist/version.js +1 -1
  174. package/pd-mcp-server/package.json +1 -1
  175. package/plugin/dist/bundle.js +472 -448
  176. package/plugin/openclaw.plugin.json +1 -1
  177. package/plugin/package.json +1 -1
  178. package/release-manager/dist/update/bootstrap-executor.js +33 -19
  179. package/release-manager/package.json +1 -1
  180. package/workbuddy-adapter/package.json +1 -1
@@ -1,9 +1,66 @@
1
1
  import { type Static } from '@sinclair/typebox';
2
+ /**
3
+ * One canonical principle the system exposed to the model for a router run.
4
+ * The digest is computed over the canonicalized `{id, version, status, text}`
5
+ * tuple with a fixed key order, so any consumer can re-verify the record.
6
+ */
7
+ export interface RouterTrustedPrinciple {
8
+ /** Canonical ledger principleId (the only id the model may reference). */
9
+ readonly principleId: string;
10
+ /** Ledger lifecycle status at exposure time (candidate | probation | active). */
11
+ readonly status: string;
12
+ /** Semantic version of the principle record. */
13
+ readonly version: number;
14
+ /** Principle body text as exposed to the model. */
15
+ readonly text: string;
16
+ /** sha256 over the canonicalized {id, version, status, text} tuple. */
17
+ readonly contentDigest: string;
18
+ }
19
+ /**
20
+ * Deterministic content digest for a trusted principle exposure entry.
21
+ * Fixed key order, fixed field set, sha256 hex — version this function only
22
+ * by changing the receipt schemaVersion (SPEC v0.6 §5).
23
+ */
24
+ export declare function computeTrustedPrincipleDigest(entry: {
25
+ principleId: string;
26
+ status: string;
27
+ version: number;
28
+ text: string;
29
+ }): string;
30
+ /**
31
+ * Read-side port for assembling the trusted principle exposure before the
32
+ * model call (SPEC v0.6 §5). Implementations read from PD's authoritative
33
+ * sources (Principle Ledger / verified read models) — NEVER from model output.
34
+ *
35
+ * A readable ledger with zero eligible principles is a PROVEN empty exposure
36
+ * (`ok` with `principles: []`), not `unavailable` — the model demonstrably saw
37
+ * no canonical ids. `unavailable` is reserved for "cannot prove what was (or
38
+ * would be) exposed".
39
+ */
40
+ export interface RouterTrustedPrincipleSource {
41
+ readTrustedPrinciples(): {
42
+ status: 'ok';
43
+ principles: RouterTrustedPrinciple[];
44
+ } | {
45
+ status: 'unavailable';
46
+ reason: 'ledger_unavailable' | 'ledger_corrupt' | 'source_not_configured';
47
+ };
48
+ }
49
+ /** Runtime guard (rc-1/rc-2): structural detection of the source port on an
50
+ * injected dependency — lets the runtime factory accept the concrete ledger
51
+ * adapter through its narrow LedgerAdapter-typed option without a cast. */
52
+ export declare function isRouterTrustedPrincipleSource(value: unknown): value is RouterTrustedPrincipleSource;
53
+ /**
54
+ * PRI-1146: receipt schemaVersion bumped v1 → v2 because `canonicalPrinciples`
55
+ * gained the `available` shape and the receipt now pins the exposed evidence
56
+ * refs. Old `router-context-v1` receipts belong to retired V1-only artifacts
57
+ * and are not readable through this contract (Clean Break).
58
+ */
2
59
  export declare const RouterContextReceiptSchema: import("@sinclair/typebox").TObject<{
3
- schemaVersion: import("@sinclair/typebox").TLiteral<"router-context-v1">;
60
+ schemaVersion: import("@sinclair/typebox").TLiteral<"router-context-v2">;
4
61
  taskId: import("@sinclair/typebox").TString;
5
62
  runId: import("@sinclair/typebox").TString;
6
- outputSchemaRef: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"diagnostician-output">, import("@sinclair/typebox").TLiteral<"diagnostician-output-v1">]>;
63
+ outputSchemaRef: import("@sinclair/typebox").TLiteral<"diagnostician-output">;
7
64
  contextHash: import("@sinclair/typebox").TString;
8
65
  messageDigest: import("@sinclair/typebox").TString;
9
66
  systemPromptDigest: import("@sinclair/typebox").TString;
@@ -11,13 +68,67 @@ export declare const RouterContextReceiptSchema: import("@sinclair/typebox").TOb
11
68
  artifactId: import("@sinclair/typebox").TString;
12
69
  contentDigest: import("@sinclair/typebox").TString;
13
70
  }>>;
14
- canonicalPrinciples: import("@sinclair/typebox").TObject<{
71
+ /**
72
+ * Evidence sourceRefs actually exposed to the model in this run (from the
73
+ * Stage A predecessor artifact's evidence array). Association evidenceRefs
74
+ * must be a subset of this list.
75
+ */
76
+ evidenceRefs: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
77
+ canonicalPrinciples: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
78
+ status: import("@sinclair/typebox").TLiteral<"available">;
79
+ /**
80
+ * The exact set exposed to the model — may be empty (a provably empty
81
+ * allowlist is still "available": the model saw no canonical ids).
82
+ */
83
+ principles: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
84
+ principleId: import("@sinclair/typebox").TString;
85
+ status: import("@sinclair/typebox").TString;
86
+ version: import("@sinclair/typebox").TInteger;
87
+ text: import("@sinclair/typebox").TString;
88
+ contentDigest: import("@sinclair/typebox").TString;
89
+ }>>;
90
+ }>, import("@sinclair/typebox").TObject<{
15
91
  status: import("@sinclair/typebox").TLiteral<"unavailable">;
16
- reason: import("@sinclair/typebox").TLiteral<"router_has_no_system_canonical_principle_allowlist">;
92
+ reason: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"ledger_unavailable">, import("@sinclair/typebox").TLiteral<"ledger_corrupt">, import("@sinclair/typebox").TLiteral<"source_not_configured">]>;
17
93
  nextAction: import("@sinclair/typebox").TString;
18
- }>;
94
+ }>]>;
19
95
  }>;
20
96
  export type RouterContextReceipt = Static<typeof RouterContextReceiptSchema>;
97
+ /**
98
+ * The trusted-context state as it travels in the router prompt INPUT payload
99
+ * (structured, low-trust data channel — PRI-1146 P1-02). Mirrors the receipt
100
+ * schema's `canonicalPrinciples` union above; the schema remains the validation
101
+ * authority at the persistence boundary. Principle data never enters the
102
+ * system prompt — the static prompt declares the data/instruction boundary and
103
+ * the receipt's messageDigest binds exactly this payload.
104
+ */
105
+ export type RouterTrustedContext = {
106
+ status: 'available';
107
+ principles: readonly RouterTrustedPrinciple[];
108
+ } | {
109
+ status: 'unavailable';
110
+ reason: 'ledger_unavailable' | 'ledger_corrupt' | 'source_not_configured';
111
+ nextAction: string;
112
+ };
113
+ /**
114
+ * Runtime guard schema for the trusted-context payload state. Used when
115
+ * REBUILDING evidence from persisted data (PRI-1146 P2-01) — the persisted
116
+ * message is untrusted input at that boundary (rc-1/rc-4).
117
+ */
118
+ export declare const RouterTrustedContextSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
119
+ status: import("@sinclair/typebox").TLiteral<"available">;
120
+ principles: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
121
+ principleId: import("@sinclair/typebox").TString;
122
+ status: import("@sinclair/typebox").TString;
123
+ version: import("@sinclair/typebox").TInteger;
124
+ text: import("@sinclair/typebox").TString;
125
+ contentDigest: import("@sinclair/typebox").TString;
126
+ }>>;
127
+ }>, import("@sinclair/typebox").TObject<{
128
+ status: import("@sinclair/typebox").TLiteral<"unavailable">;
129
+ reason: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"ledger_unavailable">, import("@sinclair/typebox").TLiteral<"ledger_corrupt">, import("@sinclair/typebox").TLiteral<"source_not_configured">]>;
130
+ nextAction: import("@sinclair/typebox").TString;
131
+ }>]>;
21
132
  /** Read only a system-produced artifact envelope, never a model response. */
22
133
  export declare function readRouterContextReceipt(envelope: unknown, expected: {
23
134
  taskId: string;
@@ -36,10 +147,41 @@ export declare function verifyRouterContextReceipt(envelope: unknown, expected:
36
147
  runId: string;
37
148
  contextHash: string;
38
149
  message: string;
39
- systemPrompt: string;
150
+ /**
151
+ * Reconstructed effective system prompt (base layer + profile layers,
152
+ * merged through the adapter's single merge path). Used when a caller can
153
+ * rebuild the full prompt bytes.
154
+ */
155
+ systemPrompt?: string;
156
+ /**
157
+ * Adapter-attested SHA-256 of the EXACT effective system prompt sent to
158
+ * the provider. Used on the in-process commit path, where the adapter is
159
+ * the authority on the merged prompt. Exactly one of `systemPrompt` /
160
+ * `systemPromptDigest` must be supplied — an unverifiable receipt is never
161
+ * reported as verified.
162
+ */
163
+ systemPromptDigest?: string;
40
164
  predecessors: {
41
165
  artifactId: string;
42
166
  content: unknown;
43
167
  }[];
168
+ /**
169
+ * What the caller can prove was actually exposed (runner replay); optional.
170
+ * A discriminated union mirrors the receipt's `canonicalPrinciples`: the
171
+ * caller declares whether the exposure was provably `available` (with the
172
+ * exact principle set) or typed `unavailable` (with reason + nextAction).
173
+ * `evidenceRefs` is verified in BOTH states — the Stage A evidence refs are
174
+ * digest-bound to the message regardless of ledger provability.
175
+ */
176
+ exposed?: {
177
+ status: 'available';
178
+ principles: readonly RouterTrustedPrinciple[];
179
+ evidenceRefs: readonly string[];
180
+ } | {
181
+ status: 'unavailable';
182
+ reason: 'ledger_unavailable' | 'ledger_corrupt' | 'source_not_configured';
183
+ nextAction: string;
184
+ evidenceRefs: readonly string[];
185
+ };
44
186
  }): ReturnType<typeof readRouterContextReceipt>;
45
187
  //# sourceMappingURL=router-context-evidence.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"router-context-evidence.d.ts","sourceRoot":"","sources":["../../../src/runtime/internalization/router-context-evidence.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAItD,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;EAmBrC,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE7E,6EAA6E;AAC7E,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,oBAAoB,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAQxH;AAED,gGAAgG;AAChG,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE;IACR,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAC1F,YAAY,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CAC1D,GACA,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAkB7C"}
1
+ {"version":3,"file":"router-context-evidence.d.ts","sourceRoot":"","sources":["../../../src/runtime/internalization/router-context-evidence.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAOtD;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,0EAA0E;IAC1E,QAAQ,CAAC,WAAW,EAAE,M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"}
@@ -1,27 +1,117 @@
1
+ /**
2
+ * Trusted router context evidence (SPEC-PD-RULE-ASSOCIATION-005 v0.6 §5).
3
+ *
4
+ * The receipt proves, for one diagnostician router run, exactly which
5
+ * canonical principles and evidence refs the SYSTEM exposed to the model. It
6
+ * is produced BEFORE the model call, persisted immutably inside the committed
7
+ * artifact envelope (`artifacts.content_json` / `pi_artifacts.contentJson`),
8
+ * and re-verifiable after a restart by digest comparison.
9
+ *
10
+ * Rules:
11
+ * - The exposed set is the only allowlist association validation may trust;
12
+ * the current Ledger state is NEVER a substitute for the historical
13
+ * exposure (a principle added later cannot impersonate history).
14
+ * - When the system cannot prove what was exposed, the receipt carries a
15
+ * typed `unavailable` with a machine-readable reason — never a guess.
16
+ */
1
17
  import { createHash } from 'node:crypto';
2
18
  import { Type } from '@sinclair/typebox';
3
19
  import { Value } from '@sinclair/typebox/value';
4
20
  const DigestSchema = Type.String({ pattern: '^[a-f0-9]{64}$' });
21
+ const RouterTrustedPrincipleSchema = Type.Object({
22
+ principleId: Type.String({ minLength: 1 }),
23
+ status: Type.String({ minLength: 1 }),
24
+ version: Type.Integer({ minimum: 0 }),
25
+ text: Type.String(),
26
+ contentDigest: DigestSchema,
27
+ }, { additionalProperties: false });
28
+ /**
29
+ * Deterministic content digest for a trusted principle exposure entry.
30
+ * Fixed key order, fixed field set, sha256 hex — version this function only
31
+ * by changing the receipt schemaVersion (SPEC v0.6 §5).
32
+ */
33
+ export function computeTrustedPrincipleDigest(entry) {
34
+ const canonical = JSON.stringify({
35
+ id: entry.principleId,
36
+ version: entry.version,
37
+ status: entry.status,
38
+ text: entry.text,
39
+ });
40
+ return createHash('sha256').update(canonical).digest('hex');
41
+ }
42
+ /** Runtime guard (rc-1/rc-2): structural detection of the source port on an
43
+ * injected dependency — lets the runtime factory accept the concrete ledger
44
+ * adapter through its narrow LedgerAdapter-typed option without a cast. */
45
+ export function isRouterTrustedPrincipleSource(value) {
46
+ return typeof value === 'object' && value !== null
47
+ && typeof value.readTrustedPrinciples === 'function';
48
+ }
49
+ // ── Receipt schema ───────────────────────────────────────────────────────────
50
+ /**
51
+ * PRI-1146: receipt schemaVersion bumped v1 → v2 because `canonicalPrinciples`
52
+ * gained the `available` shape and the receipt now pins the exposed evidence
53
+ * refs. Old `router-context-v1` receipts belong to retired V1-only artifacts
54
+ * and are not readable through this contract (Clean Break).
55
+ */
5
56
  export const RouterContextReceiptSchema = Type.Object({
6
- schemaVersion: Type.Literal('router-context-v1'),
57
+ schemaVersion: Type.Literal('router-context-v2'),
7
58
  taskId: Type.String({ minLength: 1 }),
8
59
  runId: Type.String({ minLength: 1 }),
9
- // PRI-1139: new receipts carry the version-neutral canonical ref; receipts
10
- // persisted before the cutover keep the versioned spelling. Both are valid
11
- // reads of the same immutable artifact contract.
12
- outputSchemaRef: Type.Union([Type.Literal('diagnostician-output'), Type.Literal('diagnostician-output-v1')]),
60
+ // Neutral canonical ref (PRI-1139); `diagnostician-output` resolves to the
61
+ // V2 schema since PRI-1146. A versioned spelling here is a receipt bug.
62
+ outputSchemaRef: Type.Literal('diagnostician-output'),
13
63
  contextHash: Type.String({ minLength: 1 }),
14
64
  messageDigest: DigestSchema,
15
65
  systemPromptDigest: DigestSchema,
16
66
  predecessorDigests: Type.Array(Type.Object({
17
67
  artifactId: Type.String({ minLength: 1 }), contentDigest: DigestSchema,
18
68
  }), { minItems: 2, maxItems: 2 }),
19
- canonicalPrinciples: Type.Object({
69
+ /**
70
+ * Evidence sourceRefs actually exposed to the model in this run (from the
71
+ * Stage A predecessor artifact's evidence array). Association evidenceRefs
72
+ * must be a subset of this list.
73
+ */
74
+ evidenceRefs: Type.Array(Type.String({ minLength: 1 }), { uniqueItems: true }),
75
+ canonicalPrinciples: Type.Union([
76
+ Type.Object({
77
+ status: Type.Literal('available'),
78
+ /**
79
+ * The exact set exposed to the model — may be empty (a provably empty
80
+ * allowlist is still "available": the model saw no canonical ids).
81
+ */
82
+ principles: Type.Array(RouterTrustedPrincipleSchema),
83
+ }, { additionalProperties: false }),
84
+ Type.Object({
85
+ status: Type.Literal('unavailable'),
86
+ reason: Type.Union([
87
+ Type.Literal('ledger_unavailable'),
88
+ Type.Literal('ledger_corrupt'),
89
+ Type.Literal('source_not_configured'),
90
+ ]),
91
+ nextAction: Type.String({ minLength: 1 }),
92
+ }, { additionalProperties: false }),
93
+ ]),
94
+ });
95
+ /**
96
+ * Runtime guard schema for the trusted-context payload state. Used when
97
+ * REBUILDING evidence from persisted data (PRI-1146 P2-01) — the persisted
98
+ * message is untrusted input at that boundary (rc-1/rc-4).
99
+ */
100
+ export const RouterTrustedContextSchema = Type.Union([
101
+ Type.Object({
102
+ status: Type.Literal('available'),
103
+ principles: Type.Array(RouterTrustedPrincipleSchema),
104
+ }, { additionalProperties: false }),
105
+ Type.Object({
20
106
  status: Type.Literal('unavailable'),
21
- reason: Type.Literal('router_has_no_system_canonical_principle_allowlist'),
107
+ reason: Type.Union([
108
+ Type.Literal('ledger_unavailable'),
109
+ Type.Literal('ledger_corrupt'),
110
+ Type.Literal('source_not_configured'),
111
+ ]),
22
112
  nextAction: Type.String({ minLength: 1 }),
23
- }),
24
- });
113
+ }, { additionalProperties: false }),
114
+ ]);
25
115
  /** Read only a system-produced artifact envelope, never a model response. */
26
116
  export function readRouterContextReceipt(envelope, expected) {
27
117
  const invalid = (reason) => ({ status: 'unavailable', reason, nextAction: 'Inspect the immutable router artifact and its task/run lineage; do not infer a canonical allowlist.' });
@@ -33,6 +123,19 @@ export function readRouterContextReceipt(envelope, expected) {
33
123
  return invalid('context_receipt_invalid');
34
124
  if (receipt.taskId !== expected.taskId || receipt.runId !== expected.runId)
35
125
  return invalid('context_receipt_lineage_mismatch');
126
+ if (receipt.canonicalPrinciples.status === 'available') {
127
+ // rc-4-validate-array-elements: uniqueness is by principleId (object-level
128
+ // uniqueItems cannot express this), and every digest must verify against
129
+ // the entry it travels with — a self-consistent, non-ambiguous allowlist.
130
+ const seen = new Set();
131
+ for (const entry of receipt.canonicalPrinciples.principles) {
132
+ if (seen.has(entry.principleId))
133
+ return invalid('context_receipt_invalid');
134
+ seen.add(entry.principleId);
135
+ if (computeTrustedPrincipleDigest(entry) !== entry.contentDigest)
136
+ return invalid('context_receipt_invalid');
137
+ }
138
+ }
36
139
  return { status: 'available', receipt };
37
140
  }
38
141
  /** Re-verify reconstructed system input after restart; current Ledger is not input evidence. */
@@ -42,9 +145,13 @@ export function verifyRouterContextReceipt(envelope, expected) {
42
145
  return result;
43
146
  const hash = (text) => createHash('sha256').update(text).digest('hex');
44
147
  const mismatch = () => ({ status: 'unavailable', reason: 'context_receipt_source_mismatch', nextAction: 'Reload the original system input and predecessor artifacts; keep canonical association unavailable.' });
45
- if (result.receipt.contextHash !== expected.contextHash
148
+ const providerPromptDigest = expected.systemPrompt !== undefined
149
+ ? hash(expected.systemPrompt)
150
+ : expected.systemPromptDigest;
151
+ if (providerPromptDigest === undefined
152
+ || result.receipt.contextHash !== expected.contextHash
46
153
  || result.receipt.messageDigest !== hash(expected.message)
47
- || result.receipt.systemPromptDigest !== hash(expected.systemPrompt)
154
+ || result.receipt.systemPromptDigest !== providerPromptDigest
48
155
  || expected.predecessors.length !== result.receipt.predecessorDigests.length)
49
156
  return mismatch();
50
157
  const ids = new Set(expected.predecessors.map((source) => source.artifactId));
@@ -62,6 +169,44 @@ export function verifyRouterContextReceipt(envelope, expected) {
62
169
  if (!digest || content === undefined || digest.contentDigest !== hash(content))
63
170
  return mismatch();
64
171
  }
172
+ if (expected.exposed) {
173
+ // The receipt must match the exposure the caller can reconstruct from the
174
+ // persisted prompt input. Evidence refs are verified in BOTH states: they
175
+ // are digest-bound to the message even when the ledger is unprovable.
176
+ const expectedRefs = new Set(expected.exposed.evidenceRefs);
177
+ if (expectedRefs.size !== expected.exposed.evidenceRefs.length)
178
+ return mismatch();
179
+ if (result.receipt.evidenceRefs.length !== expectedRefs.size
180
+ || result.receipt.evidenceRefs.some((ref) => !expectedRefs.has(ref)))
181
+ return mismatch();
182
+ const receiptExposure = result.receipt.canonicalPrinciples;
183
+ if (expected.exposed.status === 'available') {
184
+ // Same principle set (id + digest). A receipt claiming exposure the
185
+ // input cannot show (or vice versa) is a mismatch, not a partial pass.
186
+ if (receiptExposure.status !== 'available')
187
+ return mismatch();
188
+ const receiptPrinciples = receiptExposure.principles;
189
+ if (receiptPrinciples.length !== expected.exposed.principles.length)
190
+ return mismatch();
191
+ const expectedById = new Map(expected.exposed.principles.map((p) => [p.principleId, p]));
192
+ if (expectedById.size !== expected.exposed.principles.length)
193
+ return mismatch();
194
+ for (const entry of receiptPrinciples) {
195
+ const match = expectedById.get(entry.principleId);
196
+ if (!match || match.contentDigest !== entry.contentDigest)
197
+ return mismatch();
198
+ }
199
+ }
200
+ else {
201
+ // The caller proved the exposure was unprovable: the receipt must carry
202
+ // the SAME typed unavailable reason + nextAction, never an allowlist.
203
+ if (receiptExposure.status !== 'unavailable')
204
+ return mismatch();
205
+ if (receiptExposure.reason !== expected.exposed.reason
206
+ || receiptExposure.nextAction !== expected.exposed.nextAction)
207
+ return mismatch();
208
+ }
209
+ }
65
210
  return result;
66
211
  }
67
212
  //# sourceMappingURL=router-context-evidence.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"router-context-evidence.js","sourceRoot":"","sources":["../../../src/runtime/internalization/router-context-evidence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;AAChE,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC,MAAM,CAAC;IACpD,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC;IAChD,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAA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AAiB,GAAG,eAAe,CAAC,UAAU,CAAC;YACrD,IAAI,iBAAiB,CAAC,MAAM,KAAK,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM;gBAAE,OAAO,QAAQ,EAAE,CAAC;YACvF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACzF,IAAI,YAAY,CAAC,IAAI,KAAK,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM;gBAAE,OAAO,QAAQ,EAAE,CAAC;YAChF,KAAK,MAAM,KAAK,IAAI,iBAAiB,EAAE,CAAC;gBACtC,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;gBAClD,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,aAAa,KAAK,KAAK,CAAC,aAAa;oBAAE,OAAO,QAAQ,EAAE,CAAC;YAC/E,CAAC;QACH,CAAC;aAAM,CAAC;YACN,wEAAwE;YACxE,sEAAsE;YACtE,IAAI,eAAe,CAAC,MAAM,KAAK,aAAa;gBAAE,OAAO,QAAQ,EAAE,CAAC;YAChE,IAAI,eAAe,CAAC,MAAM,KAAK,QAAQ,CAAC,OAAO,CAAC,MAAM;mBACjD,eAAe,CAAC,UAAU,KAAK,QAAQ,CAAC,OAAO,CAAC,UAAU;gBAAE,OAAO,QAAQ,EAAE,CAAC;QACrF,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,64 @@
1
+ import type { OutputLanguage } from '../language-directive.js';
2
+ import { type RouterTrustedPrinciple } from './router-context-evidence.js';
3
+ /** The exposure a caller can prove from the persisted message itself. */
4
+ export type ReconstructedExposure = {
5
+ status: 'available';
6
+ principles: readonly RouterTrustedPrinciple[];
7
+ evidenceRefs: readonly string[];
8
+ } | {
9
+ status: 'unavailable';
10
+ reason: 'ledger_unavailable' | 'ledger_corrupt' | 'source_not_configured';
11
+ nextAction: string;
12
+ evidenceRefs: readonly string[];
13
+ };
14
+ export interface ReconstructedRouterContextEvidence {
15
+ taskId: string;
16
+ runId: string;
17
+ contextHash: string;
18
+ /** The exact message the original run submitted (byte-identical). */
19
+ message: string;
20
+ /** Effective system prompt: base layer merged with the profile layer. */
21
+ systemPrompt: string;
22
+ predecessors: {
23
+ artifactId: string;
24
+ content: unknown;
25
+ }[];
26
+ exposed: ReconstructedExposure;
27
+ }
28
+ export interface ReconstructRouterContextEvidenceInput {
29
+ /** Persisted run row — `inputPayload` is the exact submitted message. */
30
+ run: {
31
+ runId: string;
32
+ taskId: string;
33
+ inputPayload?: string;
34
+ };
35
+ /** Persisted Stage A / Stage B artifacts, loaded by artifact id. */
36
+ predecessorArtifacts: readonly {
37
+ artifactId: string;
38
+ contentJson: string;
39
+ }[];
40
+ /** Operator-configured profile append layer at verification time. */
41
+ profileSystemPrompt?: string;
42
+ outputLanguage?: OutputLanguage;
43
+ }
44
+ type ReconstructionResult = {
45
+ status: 'available';
46
+ evidence: ReconstructedRouterContextEvidence;
47
+ } | {
48
+ status: 'unavailable';
49
+ reason: string;
50
+ nextAction: string;
51
+ };
52
+ /**
53
+ * Rebuild the full invocation evidence for one router run from persisted data.
54
+ *
55
+ * Fail-closed conditions (all typed, never guessed):
56
+ * - missing run input payload / malformed JSON / schema-invalid message;
57
+ * - missing, extra, malformed, or schema-invalid predecessor artifacts;
58
+ * - persisted predecessor content differing from what the message embedded;
59
+ * - a rebuilt message that is not byte-identical to the submitted message;
60
+ * - a rebuilt system prompt that is empty.
61
+ */
62
+ export declare function reconstructRouterContextEvidence(input: ReconstructRouterContextEvidenceInput): ReconstructionResult;
63
+ export {};
64
+ //# sourceMappingURL=router-context-reconstruction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router-context-reconstruction.d.ts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C,EAAE,cAAc,CAAC;CACjC;AAED,KAAK,oBAAoB,GACrB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,kCAAkC,CAAA;CAAE,GACrE;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAIlE;;;;;;;;;GASG;AACH,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,qCAAqC,GAC3C,oBAAoB,CAgFtB"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Post-restart reconstruction of router invocation evidence
3
+ * (SPEC-PD-RULE-ASSOCIATION-005 v0.6 §5; PRI-1146 P2-01).
4
+ *
5
+ * A receipt is only evidence if a NEW process can re-derive everything the
6
+ * original run submitted and then run the FULL verification
7
+ * (`verifyRouterContextReceipt`), not just a structural read.
8
+ *
9
+ * The reconstruction uses persisted, immutable facts only:
10
+ * - the run's exact `input_payload` (the router message submitted);
11
+ * - the Stage A / Stage B predecessor artifacts (`content_json`);
12
+ * - the profile system-prompt layer from runtime configuration.
13
+ *
14
+ * It never trusts the current Ledger as a substitute for the historical
15
+ * exposure, and it never invents evidence: any inconsistency is a typed
16
+ * failure, never a partial pass.
17
+ */
18
+ import { Type } from '@sinclair/typebox';
19
+ import { Value } from '@sinclair/typebox/value';
20
+ import { DiagRootCauseOutputV1Schema } from '../diagnostician/diag-rootcause-output.js';
21
+ import { DiagDistillerOutputV1Schema } from '../diagnostician/diag-distiller-output.js';
22
+ import { RouterPromptBuilder } from '../diagnostician/router-prompt-builder.js';
23
+ import { mergeSystemPromptLayers } from '../system-prompt-merge.js';
24
+ import { hashContextRefs } from '../runner/context-hash.js';
25
+ import { RouterTrustedContextSchema, } from './router-context-evidence.js';
26
+ /** The exact persisted router message shape (`RouterPromptInput`). */
27
+ const PersistedRouterMessageSchema = Type.Object({
28
+ taskId: Type.String({ minLength: 1 }),
29
+ rootCauseArtifactId: Type.String({ minLength: 1 }),
30
+ rootCauseOutput: DiagRootCauseOutputV1Schema,
31
+ distillerArtifactId: Type.String({ minLength: 1 }),
32
+ distillerOutput: DiagDistillerOutputV1Schema,
33
+ trustedContext: RouterTrustedContextSchema,
34
+ }, { additionalProperties: false });
35
+ const fail = (reason, nextAction) => ({ status: 'unavailable', reason, nextAction });
36
+ /**
37
+ * Rebuild the full invocation evidence for one router run from persisted data.
38
+ *
39
+ * Fail-closed conditions (all typed, never guessed):
40
+ * - missing run input payload / malformed JSON / schema-invalid message;
41
+ * - missing, extra, malformed, or schema-invalid predecessor artifacts;
42
+ * - persisted predecessor content differing from what the message embedded;
43
+ * - a rebuilt message that is not byte-identical to the submitted message;
44
+ * - a rebuilt system prompt that is empty.
45
+ */
46
+ export function reconstructRouterContextEvidence(input) {
47
+ const { run, predecessorArtifacts, profileSystemPrompt, outputLanguage } = input;
48
+ const invalid = (reason) => fail(reason, 'Reload the persisted router run, its Stage A/B predecessor artifacts, and the runtime profile configuration; do not infer a canonical allowlist.');
49
+ if (run.inputPayload === undefined || run.inputPayload.trim() === '')
50
+ return invalid('run_input_payload_missing');
51
+ if (predecessorArtifacts.length !== 2)
52
+ return invalid('predecessor_artifacts_incomplete');
53
+ let parsedMessage;
54
+ try {
55
+ parsedMessage = JSON.parse(run.inputPayload);
56
+ }
57
+ catch {
58
+ return invalid('run_input_payload_invalid_json');
59
+ }
60
+ if (!Value.Check(PersistedRouterMessageSchema, parsedMessage))
61
+ return invalid('run_input_payload_invalid');
62
+ const message = parsedMessage;
63
+ const rootCauseArtifact = predecessorArtifacts.find((artifact) => artifact.artifactId === message.rootCauseArtifactId);
64
+ const distillerArtifact = predecessorArtifacts.find((artifact) => artifact.artifactId === message.distillerArtifactId);
65
+ if (!rootCauseArtifact || !distillerArtifact)
66
+ return invalid('predecessor_artifact_missing');
67
+ if (rootCauseArtifact.artifactId === distillerArtifact.artifactId)
68
+ return invalid('predecessor_artifact_duplicate');
69
+ let persistedRootCause;
70
+ let persistedDistiller;
71
+ try {
72
+ persistedRootCause = JSON.parse(rootCauseArtifact.contentJson);
73
+ persistedDistiller = JSON.parse(distillerArtifact.contentJson);
74
+ }
75
+ catch {
76
+ return invalid('predecessor_artifact_invalid_json');
77
+ }
78
+ if (!Value.Check(DiagRootCauseOutputV1Schema, persistedRootCause)
79
+ || !Value.Check(DiagDistillerOutputV1Schema, persistedDistiller)) {
80
+ return invalid('predecessor_artifact_invalid');
81
+ }
82
+ // The message is only reconstructible from these artifacts if they are the
83
+ // SAME content the run embedded — otherwise the digest proof would bind a
84
+ // prompt that never ran.
85
+ if (!Value.Equal(persistedRootCause, message.rootCauseOutput)
86
+ || !Value.Equal(persistedDistiller, message.distillerOutput)) {
87
+ return invalid('predecessor_artifact_mismatch');
88
+ }
89
+ const trustedContext = message.trustedContext;
90
+ const rebuilt = new RouterPromptBuilder().buildPrompt({
91
+ rootCauseArtifactId: message.rootCauseArtifactId,
92
+ rootCauseOutput: message.rootCauseOutput,
93
+ distillerArtifactId: message.distillerArtifactId,
94
+ distillerOutput: message.distillerOutput,
95
+ trustedContext,
96
+ }, { outputLanguage });
97
+ // Byte equality proves the rebuilt message (and therefore the system prompt
98
+ // input) is the one the run actually submitted.
99
+ if (rebuilt.message !== run.inputPayload)
100
+ return invalid('message_reconstruction_mismatch');
101
+ const systemPrompt = mergeSystemPromptLayers(rebuilt.systemPrompt, profileSystemPrompt);
102
+ if (systemPrompt === undefined)
103
+ return invalid('system_prompt_unreconstructible');
104
+ const evidenceRefs = [...new Set(message.rootCauseOutput.evidence.map((entry) => entry.sourceRef))];
105
+ const exposed = trustedContext.status === 'available'
106
+ ? { status: 'available', principles: trustedContext.principles, evidenceRefs }
107
+ : { status: 'unavailable', reason: trustedContext.reason, nextAction: trustedContext.nextAction, evidenceRefs };
108
+ return {
109
+ status: 'available',
110
+ evidence: {
111
+ taskId: run.taskId,
112
+ runId: run.runId,
113
+ contextHash: hashContextRefs([message.rootCauseArtifactId, message.distillerArtifactId]),
114
+ message: run.inputPayload,
115
+ systemPrompt,
116
+ predecessors: [
117
+ { artifactId: message.rootCauseArtifactId, content: message.rootCauseOutput },
118
+ { artifactId: message.distillerArtifactId, content: message.distillerOutput },
119
+ ],
120
+ exposed,
121
+ },
122
+ };
123
+ }
124
+ //# sourceMappingURL=router-context-reconstruction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router-context-reconstruction.js","sourceRoot":"","sources":["../../../src/runtime/internalization/router-context-reconstruction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAEhF,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,0BAA0B,GAG3B,MAAM,8BAA8B,CAAC;AAEtC,sEAAsE;AACtE,MAAM,4BAA4B,GAAG,IAAI,CAAC,MAAM,CAAC;IAC/C,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACrC,mBAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAClD,eAAe,EAAE,2BAA2B;IAC5C,mBAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAClD,eAAe,EAAE,2BAA2B;IAC5C,cAAc,EAAE,0BAA0B;CAC3C,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC;AAiCpC,MAAM,IAAI,GAAG,CAAC,MA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