omk-adaptorch-wpl 0.91.0

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 (90) hide show
  1. package/README.md +49 -0
  2. package/dist/adaptorch-client.d.ts +184 -0
  3. package/dist/adaptorch-client.d.ts.map +1 -0
  4. package/dist/adaptorch-client.js +109 -0
  5. package/dist/adaptorch-client.js.map +1 -0
  6. package/dist/adjudicator-registry.d.ts +93 -0
  7. package/dist/adjudicator-registry.d.ts.map +1 -0
  8. package/dist/adjudicator-registry.js +89 -0
  9. package/dist/adjudicator-registry.js.map +1 -0
  10. package/dist/adjudicator.d.ts +73 -0
  11. package/dist/adjudicator.d.ts.map +1 -0
  12. package/dist/adjudicator.js +356 -0
  13. package/dist/adjudicator.js.map +1 -0
  14. package/dist/b2c-mapper.d.ts +25 -0
  15. package/dist/b2c-mapper.d.ts.map +1 -0
  16. package/dist/b2c-mapper.js +186 -0
  17. package/dist/b2c-mapper.js.map +1 -0
  18. package/dist/b2c-verdict.d.ts +66 -0
  19. package/dist/b2c-verdict.d.ts.map +1 -0
  20. package/dist/b2c-verdict.js +5 -0
  21. package/dist/b2c-verdict.js.map +1 -0
  22. package/dist/deep-wall.d.ts +80 -0
  23. package/dist/deep-wall.d.ts.map +1 -0
  24. package/dist/deep-wall.js +97 -0
  25. package/dist/deep-wall.js.map +1 -0
  26. package/dist/evaluate-correctness-wall.d.ts +35 -0
  27. package/dist/evaluate-correctness-wall.d.ts.map +1 -0
  28. package/dist/evaluate-correctness-wall.js +128 -0
  29. package/dist/evaluate-correctness-wall.js.map +1 -0
  30. package/dist/in-memory-adaptorch.d.ts +12 -0
  31. package/dist/in-memory-adaptorch.d.ts.map +1 -0
  32. package/dist/in-memory-adaptorch.js +26 -0
  33. package/dist/in-memory-adaptorch.js.map +1 -0
  34. package/dist/index.d.ts +46 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +28 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/live-adaptorch-transport.d.ts +14 -0
  39. package/dist/live-adaptorch-transport.d.ts.map +1 -0
  40. package/dist/live-adaptorch-transport.js +19 -0
  41. package/dist/live-adaptorch-transport.js.map +1 -0
  42. package/dist/loop.d.ts +149 -0
  43. package/dist/loop.d.ts.map +1 -0
  44. package/dist/loop.js +219 -0
  45. package/dist/loop.js.map +1 -0
  46. package/dist/mcp-introspection-transport.d.ts +18 -0
  47. package/dist/mcp-introspection-transport.d.ts.map +1 -0
  48. package/dist/mcp-introspection-transport.js +29 -0
  49. package/dist/mcp-introspection-transport.js.map +1 -0
  50. package/dist/policy-wall.d.ts +34 -0
  51. package/dist/policy-wall.d.ts.map +1 -0
  52. package/dist/policy-wall.js +125 -0
  53. package/dist/policy-wall.js.map +1 -0
  54. package/dist/receipt-signature.d.ts +28 -0
  55. package/dist/receipt-signature.d.ts.map +1 -0
  56. package/dist/receipt-signature.js +30 -0
  57. package/dist/receipt-signature.js.map +1 -0
  58. package/dist/regenerate-packet.d.ts +25 -0
  59. package/dist/regenerate-packet.d.ts.map +1 -0
  60. package/dist/regenerate-packet.js +29 -0
  61. package/dist/regenerate-packet.js.map +1 -0
  62. package/dist/repair-budget.d.ts +24 -0
  63. package/dist/repair-budget.d.ts.map +1 -0
  64. package/dist/repair-budget.js +44 -0
  65. package/dist/repair-budget.js.map +1 -0
  66. package/dist/repair-loop.d.ts +18 -0
  67. package/dist/repair-loop.d.ts.map +1 -0
  68. package/dist/repair-loop.js +54 -0
  69. package/dist/repair-loop.js.map +1 -0
  70. package/dist/retry-backoff.d.ts +56 -0
  71. package/dist/retry-backoff.d.ts.map +1 -0
  72. package/dist/retry-backoff.js +75 -0
  73. package/dist/retry-backoff.js.map +1 -0
  74. package/dist/signed-receipt.d.ts +29 -0
  75. package/dist/signed-receipt.d.ts.map +1 -0
  76. package/dist/signed-receipt.js +25 -0
  77. package/dist/signed-receipt.js.map +1 -0
  78. package/dist/state-machine.d.ts +40 -0
  79. package/dist/state-machine.d.ts.map +1 -0
  80. package/dist/state-machine.js +88 -0
  81. package/dist/state-machine.js.map +1 -0
  82. package/dist/types.d.ts +149 -0
  83. package/dist/types.d.ts.map +1 -0
  84. package/dist/types.js +16 -0
  85. package/dist/types.js.map +1 -0
  86. package/dist/wall-meta.d.ts +3 -0
  87. package/dist/wall-meta.d.ts.map +1 -0
  88. package/dist/wall-meta.js +3 -0
  89. package/dist/wall-meta.js.map +1 -0
  90. package/package.json +46 -0
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Maps OA adjudication + policy flags to B2C {@link VerdictCard} and apply/submit gates.
3
+ */
4
+ import { B2C_VERDICT_SCHEMA_VERSION, } from "./b2c-verdict.js";
5
+ import { POLICY_FLAG } from "./policy-wall.js";
6
+ const USER_VERDICT_SEVERITY = ["BLOCKED", "INCONCLUSIVE", "ADVISORY", "PASS"];
7
+ function worstUserVerdict(current, next) {
8
+ const cur = USER_VERDICT_SEVERITY.indexOf(current);
9
+ const nxt = USER_VERDICT_SEVERITY.indexOf(next);
10
+ return cur <= nxt ? current : next;
11
+ }
12
+ function verdictFromOa(verdict) {
13
+ switch (verdict) {
14
+ case "CONFIRMED":
15
+ return "PASS";
16
+ case "CORROBORATED-FAILURE":
17
+ return "ADVISORY";
18
+ case "CONTRADICTED":
19
+ return "BLOCKED";
20
+ case "INDETERMINATE":
21
+ return "INCONCLUSIVE";
22
+ case "VERIFIER-ERROR":
23
+ return "INCONCLUSIVE";
24
+ }
25
+ }
26
+ function riskFromUserVerdict(verdict, flags) {
27
+ if (verdict === "BLOCKED" || flags.includes(POLICY_FLAG.NON_NEGOTIABLE_BLOCKING)) {
28
+ return "critical";
29
+ }
30
+ if (verdict === "INCONCLUSIVE")
31
+ return "high";
32
+ if (verdict === "ADVISORY")
33
+ return "medium";
34
+ return "low";
35
+ }
36
+ const REASON_CODE_USER = {
37
+ SCOPE_VIOLATION: { blocked: "Write scope violation detected by outcome adjudication." },
38
+ SCHEMA_DRIFT: { blocked: "Output schema does not match the expected contract." },
39
+ CONTENT_CHECK_FAILED: { blocked: "Content verification failed for one or more artifacts." },
40
+ NO_EVIDENCE_ON_SUCCESS: { blocked: "Run reported success but left no usable evidence." },
41
+ EMPTY_ARTIFACT_CONTENT: { blocked: "An artifact was present but contained no substantive content." },
42
+ TRACE_CHECK_FAILED: { blocked: "Trace verification failed for this run." },
43
+ TRACE_ERROR_SPAN: { blocked: "Error-level spans were found under a reported success." },
44
+ MIN_ACTIONS_UNMET: { blocked: "Fewer actions were recorded than required for this kind." },
45
+ RUN_STATUS_UNPARSEABLE: { blocked: "Run status could not be interpreted." },
46
+ RUN_FETCH_FAILED: { blocked: "Evidence could not be fetched for this run." },
47
+ MALFORMED_REQUEST: { blocked: "Adjudication request was malformed." },
48
+ RUN_NOT_TERMINAL: { blocked: "Run has not reached a terminal status yet." },
49
+ EVIDENCE_EMPTY: { blocked: "Evidence was too thin to reach a confident verdict." },
50
+ FAILURE_REPORTED: { blocked: "The run reported failure and evidence agrees." },
51
+ ALL_CHECKS_PASSED: { passed: "All outcome adjudication checks passed." },
52
+ };
53
+ function userStringsForReasonCode(code) {
54
+ const entry = REASON_CODE_USER[code];
55
+ const passed = [];
56
+ const blocked = [];
57
+ if (entry.passed)
58
+ passed.push(entry.passed);
59
+ if (entry.blocked)
60
+ blocked.push(entry.blocked);
61
+ return { passed, blocked };
62
+ }
63
+ function userVerdictFromPolicyFlags(flags, previewOnly) {
64
+ let v = "PASS";
65
+ if (flags.includes(POLICY_FLAG.NON_NEGOTIABLE_BLOCKING) ||
66
+ flags.includes(POLICY_FLAG.CANDIDATE_LEAK_SUSPECT) ||
67
+ flags.includes(POLICY_FLAG.SECRET_SUSPECT)) {
68
+ v = worstUserVerdict(v, "BLOCKED");
69
+ }
70
+ if (flags.includes(POLICY_FLAG.EVIDENCE_DAG_INCOMPLETE)) {
71
+ v = worstUserVerdict(v, "INCONCLUSIVE");
72
+ }
73
+ if (previewOnly &&
74
+ (flags.includes(POLICY_FLAG.REPRO_OVERFIT_SUSPECT) || flags.includes(POLICY_FLAG.LOW_DISCRIMINATION))) {
75
+ v = worstUserVerdict(v, "ADVISORY");
76
+ }
77
+ return v === "PASS" && flags.length === 0 ? null : v;
78
+ }
79
+ export const BATCH1_NO_DOCKER_RUNNER = "BATCH1_NO_DOCKER_RUNNER";
80
+ function buildNextActions(verdict, previewOnly, canApply) {
81
+ if (verdict === "BLOCKED") {
82
+ return ["Regenerate"];
83
+ }
84
+ if (verdict === "INCONCLUSIVE") {
85
+ return previewOnly ? ["Deep Check", "Regenerate"] : ["Deep Check"];
86
+ }
87
+ if (verdict === "ADVISORY") {
88
+ return previewOnly ? ["Deep Check", "Apply"] : ["Apply"];
89
+ }
90
+ if (canApply) {
91
+ return ["Apply"];
92
+ }
93
+ return ["Deep Check"];
94
+ }
95
+ function buildLimitsCode(previewOnly) {
96
+ return previewOnly ? BATCH1_NO_DOCKER_RUNNER : undefined;
97
+ }
98
+ function buildDisclaimer(previewOnly, limitsCode) {
99
+ if (!previewOnly) {
100
+ return undefined;
101
+ }
102
+ const code = limitsCode ?? BATCH1_NO_DOCKER_RUNNER;
103
+ return `Preview-only evaluation (${code}): no docker runner; apply and submit gates are conservative.`;
104
+ }
105
+ export function mapToB2C(input) {
106
+ const evaluatedAt = input.evaluatedAt ?? new Date().toISOString();
107
+ let userVerdict = "INCONCLUSIVE";
108
+ const passed_checks = [];
109
+ const blocked_reasons = [];
110
+ if (input.diffPaths.length === 0 && input.adjudication === undefined) {
111
+ userVerdict = "INCONCLUSIVE";
112
+ blocked_reasons.push("No changed paths were found in the diff; cannot assess write scope.");
113
+ }
114
+ else {
115
+ userVerdict = "PASS";
116
+ }
117
+ const policyVerdict = userVerdictFromPolicyFlags(input.policyFlags, input.previewOnly);
118
+ if (policyVerdict !== null) {
119
+ userVerdict = worstUserVerdict(userVerdict, policyVerdict);
120
+ }
121
+ if (input.policyFlags.includes(POLICY_FLAG.SECRET_SUSPECT)) {
122
+ blocked_reasons.push("Diff lines may contain secrets or credentials; remove before proceeding.");
123
+ }
124
+ if (input.policyFlags.includes(POLICY_FLAG.CANDIDATE_LEAK_SUSPECT)) {
125
+ blocked_reasons.push("One or more changed paths fall outside the approved write scope.");
126
+ }
127
+ if (input.policyFlags.includes(POLICY_FLAG.EVIDENCE_DAG_INCOMPLETE)) {
128
+ blocked_reasons.push("Run evidence is required but was not evaluated in this receipt.");
129
+ }
130
+ if (input.previewOnly && input.policyFlags.includes(POLICY_FLAG.LOW_DISCRIMINATION)) {
131
+ blocked_reasons.push("Preview-only mode: discrimination against production evidence is limited.");
132
+ }
133
+ if (input.adjudication !== undefined) {
134
+ const fromOa = verdictFromOa(input.adjudication.verdict);
135
+ userVerdict = worstUserVerdict(userVerdict, fromOa);
136
+ const strings = userStringsForReasonCode(input.adjudication.reason_code);
137
+ passed_checks.push(...strings.passed);
138
+ blocked_reasons.push(...strings.blocked);
139
+ }
140
+ else if (userVerdict === "PASS" && input.diffPaths.length > 0) {
141
+ passed_checks.push("Changed paths are within approved write scope (fast wall).");
142
+ }
143
+ const limitsCode = buildLimitsCode(input.previewOnly);
144
+ const limits = {
145
+ requiresHumanReview: userVerdict === "BLOCKED" || userVerdict === "INCONCLUSIVE",
146
+ previewOnly: input.previewOnly,
147
+ code: limitsCode,
148
+ };
149
+ const canApply = userVerdict === "PASS" &&
150
+ !input.policyFlags.includes(POLICY_FLAG.NON_NEGOTIABLE_BLOCKING) &&
151
+ !input.policyFlags.includes(POLICY_FLAG.CANDIDATE_LEAK_SUSPECT) &&
152
+ !input.policyFlags.includes(POLICY_FLAG.SECRET_SUSPECT) &&
153
+ (input.adjudication === undefined || input.adjudication.verdict === "CONFIRMED");
154
+ const shouldSubmit = userVerdict !== "BLOCKED" && !input.policyFlags.includes(POLICY_FLAG.NON_NEGOTIABLE_BLOCKING);
155
+ const disclaimer = buildDisclaimer(input.previewOnly, limitsCode);
156
+ const verdictCard = {
157
+ schemaVersion: B2C_VERDICT_SCHEMA_VERSION,
158
+ verdict: userVerdict,
159
+ risk: riskFromUserVerdict(userVerdict, input.policyFlags),
160
+ limits,
161
+ passed_checks,
162
+ blocked_reasons: [...new Set(blocked_reasons)],
163
+ next_actions: buildNextActions(userVerdict, input.previewOnly, canApply),
164
+ repairHints: input.repairHints !== undefined && input.repairHints.length > 0 ? input.repairHints : undefined,
165
+ packetId: input.packetId,
166
+ kind: input.kind,
167
+ };
168
+ const receipt = {
169
+ schemaVersion: B2C_VERDICT_SCHEMA_VERSION,
170
+ evaluatedAt,
171
+ kind: input.kind,
172
+ packetId: input.packetId,
173
+ dispatchRecordId: input.dispatchRecordId,
174
+ runIds: input.runIds,
175
+ previewOnly: input.previewOnly,
176
+ canApply,
177
+ shouldSubmit,
178
+ policyFlags: [...input.policyFlags],
179
+ adjudicationVerdict: input.adjudication?.verdict,
180
+ adjudicationReasonCode: input.adjudication?.reason_code,
181
+ diffPaths: input.diffPaths,
182
+ disclaimer,
183
+ };
184
+ return { verdictCard, receipt };
185
+ }
186
+ //# sourceMappingURL=b2c-mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"b2c-mapper.js","sourceRoot":"","sources":["../src/b2c-mapper.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EACN,0BAA0B,GAO1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAmB,MAAM,kBAAkB,CAAC;AAEhE,MAAM,qBAAqB,GAAkB,CAAC,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AAE7F,SAAS,gBAAgB,CAAC,OAAoB,EAAE,IAAiB,EAAe;IAC/E,MAAM,GAAG,GAAG,qBAAqB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,qBAAqB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;AAAA,CACnC;AAED,SAAS,aA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;QAChD,sBAAsB,EAAE,KAAK,CAAC,YAAY,EAAE,WAAW;QACvD,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,UAAU;KACV,CAAC;IAEF,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;AAAA,CAChC","sourcesContent":["/**\n * Maps OA adjudication + policy flags to B2C {@link VerdictCard} and apply/submit gates.\n */\n\nimport type { AdjudicationResult } from \"./adjudicator.ts\";\nimport type { AdjudicationReasonCode, VerdictState } from \"./adjudicator-registry.ts\";\nimport {\n\tB2C_VERDICT_SCHEMA_VERSION,\n\ttype UserRiskLevel,\n\ttype UserVerdict,\n\ttype VerdictCard,\n\ttype VerdictLimits,\n\ttype VerdictNextAction,\n\ttype VerificationReceipt,\n} from \"./b2c-verdict.ts\";\nimport { POLICY_FLAG, type PolicyFlag } from \"./policy-wall.ts\";\n\nconst USER_VERDICT_SEVERITY: UserVerdict[] = [\"BLOCKED\", \"INCONCLUSIVE\", \"ADVISORY\", \"PASS\"];\n\nfunction worstUserVerdict(current: UserVerdict, next: UserVerdict): UserVerdict {\n\tconst cur = USER_VERDICT_SEVERITY.indexOf(current);\n\tconst nxt = USER_VERDICT_SEVERITY.indexOf(next);\n\treturn cur <= nxt ? current : next;\n}\n\nfunction verdictFromOa(verdict: VerdictState): UserVerdict {\n\tswitch (verdict) {\n\t\tcase \"CONFIRMED\":\n\t\t\treturn \"PASS\";\n\t\tcase \"CORROBORATED-FAILURE\":\n\t\t\treturn \"ADVISORY\";\n\t\tcase \"CONTRADICTED\":\n\t\t\treturn \"BLOCKED\";\n\t\tcase \"INDETERMINATE\":\n\t\t\treturn \"INCONCLUSIVE\";\n\t\tcase \"VERIFIER-ERROR\":\n\t\t\treturn \"INCONCLUSIVE\";\n\t}\n}\n\nfunction riskFromUserVerdict(verdict: UserVerdict, flags: PolicyFlag[]): UserRiskLevel {\n\tif (verdict === \"BLOCKED\" || flags.includes(POLICY_FLAG.NON_NEGOTIABLE_BLOCKING)) {\n\t\treturn \"critical\";\n\t}\n\tif (verdict === \"INCONCLUSIVE\") return \"high\";\n\tif (verdict === \"ADVISORY\") return \"medium\";\n\treturn \"low\";\n}\n\nconst REASON_CODE_USER: Record<AdjudicationReasonCode, { passed?: string; blocked?: string }> = {\n\tSCOPE_VIOLATION: { blocked: \"Write scope violation detected by outcome adjudication.\" },\n\tSCHEMA_DRIFT: { blocked: \"Output schema does not match the expected contract.\" },\n\tCONTENT_CHECK_FAILED: { blocked: \"Content verification failed for one or more artifacts.\" },\n\tNO_EVIDENCE_ON_SUCCESS: { blocked: \"Run reported success but left no usable evidence.\" },\n\tEMPTY_ARTIFACT_CONTENT: { blocked: \"An artifact was present but contained no substantive content.\" },\n\tTRACE_CHECK_FAILED: { blocked: \"Trace verification failed for this run.\" },\n\tTRACE_ERROR_SPAN: { blocked: \"Error-level spans were found under a reported success.\" },\n\tMIN_ACTIONS_UNMET: { blocked: \"Fewer actions were recorded than required for this kind.\" },\n\tRUN_STATUS_UNPARSEABLE: { blocked: \"Run status could not be interpreted.\" },\n\tRUN_FETCH_FAILED: { blocked: \"Evidence could not be fetched for this run.\" },\n\tMALFORMED_REQUEST: { blocked: \"Adjudication request was malformed.\" },\n\tRUN_NOT_TERMINAL: { blocked: \"Run has not reached a terminal status yet.\" },\n\tEVIDENCE_EMPTY: { blocked: \"Evidence was too thin to reach a confident verdict.\" },\n\tFAILURE_REPORTED: { blocked: \"The run reported failure and evidence agrees.\" },\n\tALL_CHECKS_PASSED: { passed: \"All outcome adjudication checks passed.\" },\n};\n\nfunction userStringsForReasonCode(code: AdjudicationReasonCode): { passed: string[]; blocked: string[] } {\n\tconst entry = REASON_CODE_USER[code];\n\tconst passed: string[] = [];\n\tconst blocked: string[] = [];\n\tif (entry.passed) passed.push(entry.passed);\n\tif (entry.blocked) blocked.push(entry.blocked);\n\treturn { passed, blocked };\n}\n\nfunction userVerdictFromPolicyFlags(flags: PolicyFlag[], previewOnly: boolean): UserVerdict | null {\n\tlet v: UserVerdict = \"PASS\";\n\tif (\n\t\tflags.includes(POLICY_FLAG.NON_NEGOTIABLE_BLOCKING) ||\n\t\tflags.includes(POLICY_FLAG.CANDIDATE_LEAK_SUSPECT) ||\n\t\tflags.includes(POLICY_FLAG.SECRET_SUSPECT)\n\t) {\n\t\tv = worstUserVerdict(v, \"BLOCKED\");\n\t}\n\tif (flags.includes(POLICY_FLAG.EVIDENCE_DAG_INCOMPLETE)) {\n\t\tv = worstUserVerdict(v, \"INCONCLUSIVE\");\n\t}\n\tif (\n\t\tpreviewOnly &&\n\t\t(flags.includes(POLICY_FLAG.REPRO_OVERFIT_SUSPECT) || flags.includes(POLICY_FLAG.LOW_DISCRIMINATION))\n\t) {\n\t\tv = worstUserVerdict(v, \"ADVISORY\");\n\t}\n\treturn v === \"PASS\" && flags.length === 0 ? null : v;\n}\n\nexport interface MapToB2CInput {\n\tkind: string;\n\tpacketId?: string;\n\tdispatchRecordId?: string;\n\trunIds: string[];\n\tpreviewOnly: boolean;\n\tpolicyFlags: PolicyFlag[];\n\tdiffPaths: string[];\n\tadjudication?: AdjudicationResult;\n\tevaluatedAt?: string;\n\trepairHints?: string[];\n}\n\nexport interface MapToB2COutput {\n\tverdictCard: VerdictCard;\n\treceipt: VerificationReceipt;\n}\n\nexport const BATCH1_NO_DOCKER_RUNNER = \"BATCH1_NO_DOCKER_RUNNER\" as const;\n\nfunction buildNextActions(verdict: UserVerdict, previewOnly: boolean, canApply: boolean): VerdictNextAction[] {\n\tif (verdict === \"BLOCKED\") {\n\t\treturn [\"Regenerate\"];\n\t}\n\tif (verdict === \"INCONCLUSIVE\") {\n\t\treturn previewOnly ? [\"Deep Check\", \"Regenerate\"] : [\"Deep Check\"];\n\t}\n\tif (verdict === \"ADVISORY\") {\n\t\treturn previewOnly ? [\"Deep Check\", \"Apply\"] : [\"Apply\"];\n\t}\n\tif (canApply) {\n\t\treturn [\"Apply\"];\n\t}\n\treturn [\"Deep Check\"];\n}\n\nfunction buildLimitsCode(previewOnly: boolean): string | undefined {\n\treturn previewOnly ? BATCH1_NO_DOCKER_RUNNER : undefined;\n}\n\nfunction buildDisclaimer(previewOnly: boolean, limitsCode: string | undefined): string | undefined {\n\tif (!previewOnly) {\n\t\treturn undefined;\n\t}\n\tconst code = limitsCode ?? BATCH1_NO_DOCKER_RUNNER;\n\treturn `Preview-only evaluation (${code}): no docker runner; apply and submit gates are conservative.`;\n}\n\nexport function mapToB2C(input: MapToB2CInput): MapToB2COutput {\n\tconst evaluatedAt = input.evaluatedAt ?? new Date().toISOString();\n\tlet userVerdict: UserVerdict = \"INCONCLUSIVE\";\n\tconst passed_checks: string[] = [];\n\tconst blocked_reasons: string[] = [];\n\n\tif (input.diffPaths.length === 0 && input.adjudication === undefined) {\n\t\tuserVerdict = \"INCONCLUSIVE\";\n\t\tblocked_reasons.push(\"No changed paths were found in the diff; cannot assess write scope.\");\n\t} else {\n\t\tuserVerdict = \"PASS\";\n\t}\n\n\tconst policyVerdict = userVerdictFromPolicyFlags(input.policyFlags, input.previewOnly);\n\tif (policyVerdict !== null) {\n\t\tuserVerdict = worstUserVerdict(userVerdict, policyVerdict);\n\t}\n\n\tif (input.policyFlags.includes(POLICY_FLAG.SECRET_SUSPECT)) {\n\t\tblocked_reasons.push(\"Diff lines may contain secrets or credentials; remove before proceeding.\");\n\t}\n\tif (input.policyFlags.includes(POLICY_FLAG.CANDIDATE_LEAK_SUSPECT)) {\n\t\tblocked_reasons.push(\"One or more changed paths fall outside the approved write scope.\");\n\t}\n\tif (input.policyFlags.includes(POLICY_FLAG.EVIDENCE_DAG_INCOMPLETE)) {\n\t\tblocked_reasons.push(\"Run evidence is required but was not evaluated in this receipt.\");\n\t}\n\tif (input.previewOnly && input.policyFlags.includes(POLICY_FLAG.LOW_DISCRIMINATION)) {\n\t\tblocked_reasons.push(\"Preview-only mode: discrimination against production evidence is limited.\");\n\t}\n\n\tif (input.adjudication !== undefined) {\n\t\tconst fromOa = verdictFromOa(input.adjudication.verdict);\n\t\tuserVerdict = worstUserVerdict(userVerdict, fromOa);\n\t\tconst strings = userStringsForReasonCode(input.adjudication.reason_code);\n\t\tpassed_checks.push(...strings.passed);\n\t\tblocked_reasons.push(...strings.blocked);\n\t} else if (userVerdict === \"PASS\" && input.diffPaths.length > 0) {\n\t\tpassed_checks.push(\"Changed paths are within approved write scope (fast wall).\");\n\t}\n\n\tconst limitsCode = buildLimitsCode(input.previewOnly);\n\tconst limits: VerdictLimits = {\n\t\trequiresHumanReview: userVerdict === \"BLOCKED\" || userVerdict === \"INCONCLUSIVE\",\n\t\tpreviewOnly: input.previewOnly,\n\t\tcode: limitsCode,\n\t};\n\n\tconst canApply =\n\t\tuserVerdict === \"PASS\" &&\n\t\t!input.policyFlags.includes(POLICY_FLAG.NON_NEGOTIABLE_BLOCKING) &&\n\t\t!input.policyFlags.includes(POLICY_FLAG.CANDIDATE_LEAK_SUSPECT) &&\n\t\t!input.policyFlags.includes(POLICY_FLAG.SECRET_SUSPECT) &&\n\t\t(input.adjudication === undefined || input.adjudication.verdict === \"CONFIRMED\");\n\n\tconst shouldSubmit = userVerdict !== \"BLOCKED\" && !input.policyFlags.includes(POLICY_FLAG.NON_NEGOTIABLE_BLOCKING);\n\n\tconst disclaimer = buildDisclaimer(input.previewOnly, limitsCode);\n\n\tconst verdictCard: VerdictCard = {\n\t\tschemaVersion: B2C_VERDICT_SCHEMA_VERSION,\n\t\tverdict: userVerdict,\n\t\trisk: riskFromUserVerdict(userVerdict, input.policyFlags),\n\t\tlimits,\n\t\tpassed_checks,\n\t\tblocked_reasons: [...new Set(blocked_reasons)],\n\t\tnext_actions: buildNextActions(userVerdict, input.previewOnly, canApply),\n\t\trepairHints: input.repairHints !== undefined && input.repairHints.length > 0 ? input.repairHints : undefined,\n\t\tpacketId: input.packetId,\n\t\tkind: input.kind,\n\t};\n\n\tconst receipt: VerificationReceipt = {\n\t\tschemaVersion: B2C_VERDICT_SCHEMA_VERSION,\n\t\tevaluatedAt,\n\t\tkind: input.kind,\n\t\tpacketId: input.packetId,\n\t\tdispatchRecordId: input.dispatchRecordId,\n\t\trunIds: input.runIds,\n\t\tpreviewOnly: input.previewOnly,\n\t\tcanApply,\n\t\tshouldSubmit,\n\t\tpolicyFlags: [...input.policyFlags],\n\t\tadjudicationVerdict: input.adjudication?.verdict,\n\t\tadjudicationReasonCode: input.adjudication?.reason_code,\n\t\tdiffPaths: input.diffPaths,\n\t\tdisclaimer,\n\t};\n\n\treturn { verdictCard, receipt };\n}\n"]}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * B2C Correctness Wall — user-facing verdict vocabulary (schemaVersion 1).
3
+ */
4
+ import type { DeepWallRunnerEvidence, DeepWallStatus } from "./deep-wall.ts";
5
+ import type { SignedWallReceipt } from "./receipt-signature.ts";
6
+ import type { VerificationDigest } from "./signed-receipt.ts";
7
+ export declare const B2C_VERDICT_SCHEMA_VERSION: 1;
8
+ /** End-user verdict (distinct from OA {@link VerdictState}). */
9
+ export type UserVerdict = "PASS" | "ADVISORY" | "INCONCLUSIVE" | "BLOCKED";
10
+ export type UserRiskLevel = "low" | "medium" | "high" | "critical";
11
+ /** Structured next-step for B2C verdict cards. */
12
+ export type VerdictNextAction = "Apply" | "Deep Check" | "Regenerate";
13
+ export interface VerdictLimits {
14
+ /** When true, automated apply/submit must not proceed without human override. */
15
+ requiresHumanReview: boolean;
16
+ /** Preview-only evaluation; no side effects implied. */
17
+ previewOnly: boolean;
18
+ /** Machine-readable limit code (e.g. batch-1 no docker runner). */
19
+ code?: string;
20
+ }
21
+ export interface VerdictCard {
22
+ schemaVersion: typeof B2C_VERDICT_SCHEMA_VERSION;
23
+ verdict: UserVerdict;
24
+ risk: UserRiskLevel;
25
+ limits: VerdictLimits;
26
+ /** Checks that passed (human-readable). */
27
+ passed_checks: string[];
28
+ /** Reasons submission or apply is blocked (human-readable). */
29
+ blocked_reasons: string[];
30
+ /** Suggested follow-ups for the user or operator. */
31
+ next_actions: VerdictNextAction[];
32
+ /** Optional operator-facing repair guidance. */
33
+ repairHints?: string[];
34
+ packetId?: string;
35
+ kind: string;
36
+ }
37
+ export interface VerificationReceipt {
38
+ schemaVersion: typeof B2C_VERDICT_SCHEMA_VERSION;
39
+ evaluatedAt: string;
40
+ kind: string;
41
+ packetId?: string;
42
+ dispatchRecordId?: string;
43
+ runIds: string[];
44
+ previewOnly: boolean;
45
+ /** Machine may apply the proposed change (distinct from shouldSubmit). */
46
+ canApply: boolean;
47
+ /** Packet may be submitted to downstream workflow. */
48
+ shouldSubmit: boolean;
49
+ policyFlags: string[];
50
+ adjudicationVerdict?: string;
51
+ adjudicationReasonCode?: string;
52
+ diffPaths: string[];
53
+ /** Human-readable limits / preview disclaimer. */
54
+ disclaimer?: string;
55
+ /** Patch/evidence fingerprints (no secret payload). */
56
+ verificationDigest?: VerificationDigest;
57
+ /** Correctness wall batch id for this evaluation receipt. */
58
+ wallVersion?: string;
59
+ /** Deep wall phase when {@link EvaluateCorrectnessWallParams.deepWall} was requested. */
60
+ deepWallStatus?: DeepWallStatus;
61
+ /** Structured evidence when deep wall reached `completed` (Wave 4-C3b). */
62
+ deepWallEvidence?: DeepWallRunnerEvidence;
63
+ /** Optional HMAC attestation when signing secret configured (Wave 3). */
64
+ signedReceipt?: SignedWallReceipt;
65
+ }
66
+ //# sourceMappingURL=b2c-verdict.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"b2c-verdict.d.ts","sourceRoot":"","sources":["../src/b2c-verdict.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,eAAO,MAAM,0BAA0B,GAAa,CAAC;AAErD,gEAAgE;AAChE,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,UAAU,GAAG,cAAc,GAAG,SAAS,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CAAC,EAAE,MAAM,CAAC;IAChC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yFAAyF;IACzF,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;IAC1C,yEAAyE;IACzE,aAAa,CAAC,EAAE,iBAAiB,CAAC;CAClC","sourcesContent":["/**\n * B2C Correctness Wall — user-facing verdict vocabulary (schemaVersion 1).\n */\n\nimport type { DeepWallRunnerEvidence, DeepWallStatus } from \"./deep-wall.ts\";\nimport type { SignedWallReceipt } from \"./receipt-signature.ts\";\nimport type { VerificationDigest } from \"./signed-receipt.ts\";\n\nexport const B2C_VERDICT_SCHEMA_VERSION = 1 as const;\n\n/** End-user verdict (distinct from OA {@link VerdictState}). */\nexport type UserVerdict = \"PASS\" | \"ADVISORY\" | \"INCONCLUSIVE\" | \"BLOCKED\";\n\nexport type UserRiskLevel = \"low\" | \"medium\" | \"high\" | \"critical\";\n\n/** Structured next-step for B2C verdict cards. */\nexport type VerdictNextAction = \"Apply\" | \"Deep Check\" | \"Regenerate\";\n\nexport interface VerdictLimits {\n\t/** When true, automated apply/submit must not proceed without human override. */\n\trequiresHumanReview: boolean;\n\t/** Preview-only evaluation; no side effects implied. */\n\tpreviewOnly: boolean;\n\t/** Machine-readable limit code (e.g. batch-1 no docker runner). */\n\tcode?: string;\n}\n\nexport interface VerdictCard {\n\tschemaVersion: typeof B2C_VERDICT_SCHEMA_VERSION;\n\tverdict: UserVerdict;\n\trisk: UserRiskLevel;\n\tlimits: VerdictLimits;\n\t/** Checks that passed (human-readable). */\n\tpassed_checks: string[];\n\t/** Reasons submission or apply is blocked (human-readable). */\n\tblocked_reasons: string[];\n\t/** Suggested follow-ups for the user or operator. */\n\tnext_actions: VerdictNextAction[];\n\t/** Optional operator-facing repair guidance. */\n\trepairHints?: string[];\n\tpacketId?: string;\n\tkind: string;\n}\n\nexport interface VerificationReceipt {\n\tschemaVersion: typeof B2C_VERDICT_SCHEMA_VERSION;\n\tevaluatedAt: string;\n\tkind: string;\n\tpacketId?: string;\n\tdispatchRecordId?: string;\n\trunIds: string[];\n\tpreviewOnly: boolean;\n\t/** Machine may apply the proposed change (distinct from shouldSubmit). */\n\tcanApply: boolean;\n\t/** Packet may be submitted to downstream workflow. */\n\tshouldSubmit: boolean;\n\tpolicyFlags: string[];\n\tadjudicationVerdict?: string;\n\tadjudicationReasonCode?: string;\n\tdiffPaths: string[];\n\t/** Human-readable limits / preview disclaimer. */\n\tdisclaimer?: string;\n\t/** Patch/evidence fingerprints (no secret payload). */\n\tverificationDigest?: VerificationDigest;\n\t/** Correctness wall batch id for this evaluation receipt. */\n\twallVersion?: string;\n\t/** Deep wall phase when {@link EvaluateCorrectnessWallParams.deepWall} was requested. */\n\tdeepWallStatus?: DeepWallStatus;\n\t/** Structured evidence when deep wall reached `completed` (Wave 4-C3b). */\n\tdeepWallEvidence?: DeepWallRunnerEvidence;\n\t/** Optional HMAC attestation when signing secret configured (Wave 3). */\n\tsignedReceipt?: SignedWallReceipt;\n}\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * B2C Correctness Wall — user-facing verdict vocabulary (schemaVersion 1).
3
+ */
4
+ export const B2C_VERDICT_SCHEMA_VERSION = 1;
5
+ //# sourceMappingURL=b2c-verdict.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"b2c-verdict.js","sourceRoot":"","sources":["../src/b2c-verdict.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAU,CAAC","sourcesContent":["/**\n * B2C Correctness Wall — user-facing verdict vocabulary (schemaVersion 1).\n */\n\nimport type { DeepWallRunnerEvidence, DeepWallStatus } from \"./deep-wall.ts\";\nimport type { SignedWallReceipt } from \"./receipt-signature.ts\";\nimport type { VerificationDigest } from \"./signed-receipt.ts\";\n\nexport const B2C_VERDICT_SCHEMA_VERSION = 1 as const;\n\n/** End-user verdict (distinct from OA {@link VerdictState}). */\nexport type UserVerdict = \"PASS\" | \"ADVISORY\" | \"INCONCLUSIVE\" | \"BLOCKED\";\n\nexport type UserRiskLevel = \"low\" | \"medium\" | \"high\" | \"critical\";\n\n/** Structured next-step for B2C verdict cards. */\nexport type VerdictNextAction = \"Apply\" | \"Deep Check\" | \"Regenerate\";\n\nexport interface VerdictLimits {\n\t/** When true, automated apply/submit must not proceed without human override. */\n\trequiresHumanReview: boolean;\n\t/** Preview-only evaluation; no side effects implied. */\n\tpreviewOnly: boolean;\n\t/** Machine-readable limit code (e.g. batch-1 no docker runner). */\n\tcode?: string;\n}\n\nexport interface VerdictCard {\n\tschemaVersion: typeof B2C_VERDICT_SCHEMA_VERSION;\n\tverdict: UserVerdict;\n\trisk: UserRiskLevel;\n\tlimits: VerdictLimits;\n\t/** Checks that passed (human-readable). */\n\tpassed_checks: string[];\n\t/** Reasons submission or apply is blocked (human-readable). */\n\tblocked_reasons: string[];\n\t/** Suggested follow-ups for the user or operator. */\n\tnext_actions: VerdictNextAction[];\n\t/** Optional operator-facing repair guidance. */\n\trepairHints?: string[];\n\tpacketId?: string;\n\tkind: string;\n}\n\nexport interface VerificationReceipt {\n\tschemaVersion: typeof B2C_VERDICT_SCHEMA_VERSION;\n\tevaluatedAt: string;\n\tkind: string;\n\tpacketId?: string;\n\tdispatchRecordId?: string;\n\trunIds: string[];\n\tpreviewOnly: boolean;\n\t/** Machine may apply the proposed change (distinct from shouldSubmit). */\n\tcanApply: boolean;\n\t/** Packet may be submitted to downstream workflow. */\n\tshouldSubmit: boolean;\n\tpolicyFlags: string[];\n\tadjudicationVerdict?: string;\n\tadjudicationReasonCode?: string;\n\tdiffPaths: string[];\n\t/** Human-readable limits / preview disclaimer. */\n\tdisclaimer?: string;\n\t/** Patch/evidence fingerprints (no secret payload). */\n\tverificationDigest?: VerificationDigest;\n\t/** Correctness wall batch id for this evaluation receipt. */\n\twallVersion?: string;\n\t/** Deep wall phase when {@link EvaluateCorrectnessWallParams.deepWall} was requested. */\n\tdeepWallStatus?: DeepWallStatus;\n\t/** Structured evidence when deep wall reached `completed` (Wave 4-C3b). */\n\tdeepWallEvidence?: DeepWallRunnerEvidence;\n\t/** Optional HMAC attestation when signing secret configured (Wave 3). */\n\tsignedReceipt?: SignedWallReceipt;\n}\n"]}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Deep Correctness Wall — stub default, plus evidence-gated runner injection (Wave 4-C3b).
3
+ *
4
+ * `completed` is NEVER emitted unless a caller injects a `runner`, sets
5
+ * `allowCompletion`, AND the runner returns structured evidence. Without all
6
+ * three, the result is downgraded to `unavailable`. This is a candidate-patch-leak
7
+ * guard: deep completion must be evidence-backed, never asserted.
8
+ */
9
+ import { BATCH1_NO_DOCKER_RUNNER } from "./b2c-mapper.ts";
10
+ export type DeepWallStatus = "not_requested" | "unavailable" | "completed";
11
+ export type DeepWallPhase = "stub" | "docker";
12
+ export declare const DEEP_WALL_UNAVAILABLE: "DEEP_WALL_UNAVAILABLE";
13
+ /** Policy flag when deep wall would report completed without a wired runner (Wave 4 gate). */
14
+ export declare const DEEP_RUNNER_NOT_WIRED: "DEEP_RUNNER_NOT_WIRED";
15
+ /** Policy flag when an injected runner returned `completed` without valid evidence (downgraded). */
16
+ export declare const DEEP_RUNNER_EVIDENCE_MISSING: "DEEP_RUNNER_EVIDENCE_MISSING";
17
+ /** Policy flag when an injected runner threw (caught, treated as unavailable). */
18
+ export declare const DEEP_RUNNER_ERROR: "DEEP_RUNNER_ERROR";
19
+ /** Structured evidence a runner MUST attach to a `completed` result. */
20
+ export interface DeepWallRunnerEvidence {
21
+ /** Content digest of what was checked (e.g. sha256 of replayed patch + base). */
22
+ digest: string;
23
+ /** The exact command/provenance the runner executed. */
24
+ command: string;
25
+ /** Runner exit code; `completed` requires `0` by runner contract. */
26
+ exitCode: number;
27
+ }
28
+ export interface DeepWallRunnerResult {
29
+ status: "completed" | "unavailable";
30
+ evidence?: DeepWallRunnerEvidence;
31
+ message: string;
32
+ }
33
+ export type DeepWallRunnerFn = (params: RunDeepWallStubParams) => Promise<DeepWallRunnerResult>;
34
+ export interface RunDeepWallStubParams {
35
+ kind: string;
36
+ runIds?: string[];
37
+ packetId?: string;
38
+ /** Wave 3: `docker` records intent; runner still unavailable until hermetic exec ships. */
39
+ phase?: DeepWallPhase;
40
+ /** Wave 4-C3b: injected hermetic runner. Completion is gated by `allowCompletion` + evidence. */
41
+ runner?: DeepWallRunnerFn;
42
+ /** Must be `true` for a runner to report `completed`; default `false` (stub path). */
43
+ allowCompletion?: boolean;
44
+ }
45
+ export interface DeepWallStubResult {
46
+ status: Extract<DeepWallStatus, "unavailable">;
47
+ limits: readonly [typeof BATCH1_NO_DOCKER_RUNNER];
48
+ message: string;
49
+ }
50
+ export interface DeepWallResult {
51
+ status: DeepWallStatus;
52
+ message: string;
53
+ evidence?: DeepWallRunnerEvidence;
54
+ limits?: readonly string[];
55
+ /** Additional policy flags surfaced by the runner path (e.g. evidence-missing, runner-error). */
56
+ runnerFlags?: readonly string[];
57
+ }
58
+ /** Resolve deep-wall phase from env `OMK_WALL_DEEP_PHASE` (stub | docker). */
59
+ export declare function resolveDeepWallPhaseFromEnv(): DeepWallPhase;
60
+ /**
61
+ * Hermetic deep runner is not shipped by default; `completed` is only reachable
62
+ * via an injected runner through {@link runDeepWall}, and even then requires evidence.
63
+ */
64
+ export declare function isDeepRunnerCompletionAllowed(): boolean;
65
+ /**
66
+ * Stub deep wall: always reports unavailable with batch-1 limit code (no docker exec).
67
+ */
68
+ export declare function runDeepWallStub(params: RunDeepWallStubParams): DeepWallStubResult;
69
+ /**
70
+ * Evidence-gated deep wall entry point.
71
+ *
72
+ * - No runner, or `allowCompletion !== true` → stub unavailable path.
73
+ * - Runner present + `allowCompletion` → runner is called in a try/catch.
74
+ * - `completed` + valid evidence → `completed` (evidence attached).
75
+ * - `completed` without valid evidence → downgraded to `unavailable`
76
+ * with `DEEP_RUNNER_EVIDENCE_MISSING` (candidate-patch-leak guard).
77
+ * - runner throws → `unavailable` with `DEEP_RUNNER_ERROR`.
78
+ */
79
+ export declare function runDeepWall(params: RunDeepWallStubParams): Promise<DeepWallResult>;
80
+ //# sourceMappingURL=deep-wall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-wall.d.ts","sourceRoot":"","sources":["../src/deep-wall.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,aAAa,GAAG,WAAW,CAAC;AAE3E,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE9C,eAAO,MAAM,qBAAqB,yBAAmC,CAAC;AAEtE,8FAA8F;AAC9F,eAAO,MAAM,qBAAqB,yBAAmC,CAAC;AAEtE,oGAAoG;AACpG,eAAO,MAAM,4BAA4B,gCAA0C,CAAC;AAEpF,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,qBAA+B,CAAC;AAE9D,wEAAwE;AACxE,MAAM,WAAW,sBAAsB;IACtC,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC;IACpC,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,qBAAqB,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEhG,MAAM,WAAW,qBAAqB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2FAA2F;IAC3F,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,iGAAiG;IACjG,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,sFAAsF;IACtF,eAAe,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,kBAAkB;IAClC,MAAM,EAAE,OAAO,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;IAC/C,MAAM,EAAE,SAAS,CAAC,OAAO,uBAAuB,CAAC,CAAC;IAClD,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC9B,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,iGAAiG;IACjG,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC;AAqBD,8EAA8E;AAC9E,wBAAgB,2BAA2B,IAAI,aAAa,CAI3D;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,IAAI,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,kBAAkB,CAQjF;AAED;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CA6BxF","sourcesContent":["/**\n * Deep Correctness Wall — stub default, plus evidence-gated runner injection (Wave 4-C3b).\n *\n * `completed` is NEVER emitted unless a caller injects a `runner`, sets\n * `allowCompletion`, AND the runner returns structured evidence. Without all\n * three, the result is downgraded to `unavailable`. This is a candidate-patch-leak\n * guard: deep completion must be evidence-backed, never asserted.\n */\n\nimport { BATCH1_NO_DOCKER_RUNNER } from \"./b2c-mapper.ts\";\n\nexport type DeepWallStatus = \"not_requested\" | \"unavailable\" | \"completed\";\n\nexport type DeepWallPhase = \"stub\" | \"docker\";\n\nexport const DEEP_WALL_UNAVAILABLE = \"DEEP_WALL_UNAVAILABLE\" as const;\n\n/** Policy flag when deep wall would report completed without a wired runner (Wave 4 gate). */\nexport const DEEP_RUNNER_NOT_WIRED = \"DEEP_RUNNER_NOT_WIRED\" as const;\n\n/** Policy flag when an injected runner returned `completed` without valid evidence (downgraded). */\nexport const DEEP_RUNNER_EVIDENCE_MISSING = \"DEEP_RUNNER_EVIDENCE_MISSING\" as const;\n\n/** Policy flag when an injected runner threw (caught, treated as unavailable). */\nexport const DEEP_RUNNER_ERROR = \"DEEP_RUNNER_ERROR\" as const;\n\n/** Structured evidence a runner MUST attach to a `completed` result. */\nexport interface DeepWallRunnerEvidence {\n\t/** Content digest of what was checked (e.g. sha256 of replayed patch + base). */\n\tdigest: string;\n\t/** The exact command/provenance the runner executed. */\n\tcommand: string;\n\t/** Runner exit code; `completed` requires `0` by runner contract. */\n\texitCode: number;\n}\n\nexport interface DeepWallRunnerResult {\n\tstatus: \"completed\" | \"unavailable\";\n\tevidence?: DeepWallRunnerEvidence;\n\tmessage: string;\n}\n\nexport type DeepWallRunnerFn = (params: RunDeepWallStubParams) => Promise<DeepWallRunnerResult>;\n\nexport interface RunDeepWallStubParams {\n\tkind: string;\n\trunIds?: string[];\n\tpacketId?: string;\n\t/** Wave 3: `docker` records intent; runner still unavailable until hermetic exec ships. */\n\tphase?: DeepWallPhase;\n\t/** Wave 4-C3b: injected hermetic runner. Completion is gated by `allowCompletion` + evidence. */\n\trunner?: DeepWallRunnerFn;\n\t/** Must be `true` for a runner to report `completed`; default `false` (stub path). */\n\tallowCompletion?: boolean;\n}\n\nexport interface DeepWallStubResult {\n\tstatus: Extract<DeepWallStatus, \"unavailable\">;\n\tlimits: readonly [typeof BATCH1_NO_DOCKER_RUNNER];\n\tmessage: string;\n}\n\nexport interface DeepWallResult {\n\tstatus: DeepWallStatus;\n\tmessage: string;\n\tevidence?: DeepWallRunnerEvidence;\n\tlimits?: readonly string[];\n\t/** Additional policy flags surfaced by the runner path (e.g. evidence-missing, runner-error). */\n\trunnerFlags?: readonly string[];\n}\n\nconst DEFAULT_DEEP_WALL_MESSAGE =\n\t\"Deep correctness check is not available in this environment (no docker runner). Use preview fast wall or run checks locally.\";\n\nconst DOCKER_PHASE_MESSAGE =\n\t\"Deep wall docker phase requested but hermetic runner is not wired yet; fast wall and local CI remain authoritative.\";\n\nfunction hasValidEvidence(e: unknown): e is DeepWallRunnerEvidence {\n\tif (typeof e !== \"object\" || e === null) return false;\n\tconst v = e as DeepWallRunnerEvidence;\n\treturn (\n\t\ttypeof v.digest === \"string\" &&\n\t\tv.digest.length > 0 &&\n\t\ttypeof v.command === \"string\" &&\n\t\tv.command.length > 0 &&\n\t\ttypeof v.exitCode === \"number\" &&\n\t\tNumber.isFinite(v.exitCode)\n\t);\n}\n\n/** Resolve deep-wall phase from env `OMK_WALL_DEEP_PHASE` (stub | docker). */\nexport function resolveDeepWallPhaseFromEnv(): DeepWallPhase {\n\tconst raw = process.env.OMK_WALL_DEEP_PHASE?.trim().toLowerCase();\n\tif (raw === \"docker\") return \"docker\";\n\treturn \"stub\";\n}\n\n/**\n * Hermetic deep runner is not shipped by default; `completed` is only reachable\n * via an injected runner through {@link runDeepWall}, and even then requires evidence.\n */\nexport function isDeepRunnerCompletionAllowed(): boolean {\n\treturn false;\n}\n\n/**\n * Stub deep wall: always reports unavailable with batch-1 limit code (no docker exec).\n */\nexport function runDeepWallStub(params: RunDeepWallStubParams): DeepWallStubResult {\n\tconst phase = params.phase ?? resolveDeepWallPhaseFromEnv();\n\tconst message = phase === \"docker\" ? DOCKER_PHASE_MESSAGE : DEFAULT_DEEP_WALL_MESSAGE;\n\treturn {\n\t\tstatus: \"unavailable\",\n\t\tlimits: [BATCH1_NO_DOCKER_RUNNER],\n\t\tmessage,\n\t};\n}\n\n/**\n * Evidence-gated deep wall entry point.\n *\n * - No runner, or `allowCompletion !== true` → stub unavailable path.\n * - Runner present + `allowCompletion` → runner is called in a try/catch.\n * - `completed` + valid evidence → `completed` (evidence attached).\n * - `completed` without valid evidence → downgraded to `unavailable`\n * with `DEEP_RUNNER_EVIDENCE_MISSING` (candidate-patch-leak guard).\n * - runner throws → `unavailable` with `DEEP_RUNNER_ERROR`.\n */\nexport async function runDeepWall(params: RunDeepWallStubParams): Promise<DeepWallResult> {\n\tif (params.runner !== undefined && params.allowCompletion === true) {\n\t\ttry {\n\t\t\tconst result = await params.runner(params);\n\t\t\tif (result.status === \"completed\") {\n\t\t\t\tif (hasValidEvidence(result.evidence)) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\tevidence: result.evidence,\n\t\t\t\t\t\tmessage: result.message,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"unavailable\",\n\t\t\t\t\tmessage: \"Deep runner reported completed without valid evidence; downgraded to unavailable.\",\n\t\t\t\t\trunnerFlags: [DEEP_RUNNER_EVIDENCE_MISSING],\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { status: \"unavailable\", message: result.message };\n\t\t} catch (err) {\n\t\t\treturn {\n\t\t\t\tstatus: \"unavailable\",\n\t\t\t\tmessage: `Deep runner threw: ${err instanceof Error ? err.message : String(err)}`,\n\t\t\t\trunnerFlags: [DEEP_RUNNER_ERROR],\n\t\t\t};\n\t\t}\n\t}\n\tconst stub = runDeepWallStub(params);\n\treturn { status: stub.status, message: stub.message, limits: stub.limits };\n}\n"]}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Deep Correctness Wall — stub default, plus evidence-gated runner injection (Wave 4-C3b).
3
+ *
4
+ * `completed` is NEVER emitted unless a caller injects a `runner`, sets
5
+ * `allowCompletion`, AND the runner returns structured evidence. Without all
6
+ * three, the result is downgraded to `unavailable`. This is a candidate-patch-leak
7
+ * guard: deep completion must be evidence-backed, never asserted.
8
+ */
9
+ import { BATCH1_NO_DOCKER_RUNNER } from "./b2c-mapper.js";
10
+ export const DEEP_WALL_UNAVAILABLE = "DEEP_WALL_UNAVAILABLE";
11
+ /** Policy flag when deep wall would report completed without a wired runner (Wave 4 gate). */
12
+ export const DEEP_RUNNER_NOT_WIRED = "DEEP_RUNNER_NOT_WIRED";
13
+ /** Policy flag when an injected runner returned `completed` without valid evidence (downgraded). */
14
+ export const DEEP_RUNNER_EVIDENCE_MISSING = "DEEP_RUNNER_EVIDENCE_MISSING";
15
+ /** Policy flag when an injected runner threw (caught, treated as unavailable). */
16
+ export const DEEP_RUNNER_ERROR = "DEEP_RUNNER_ERROR";
17
+ const DEFAULT_DEEP_WALL_MESSAGE = "Deep correctness check is not available in this environment (no docker runner). Use preview fast wall or run checks locally.";
18
+ const DOCKER_PHASE_MESSAGE = "Deep wall docker phase requested but hermetic runner is not wired yet; fast wall and local CI remain authoritative.";
19
+ function hasValidEvidence(e) {
20
+ if (typeof e !== "object" || e === null)
21
+ return false;
22
+ const v = e;
23
+ return (typeof v.digest === "string" &&
24
+ v.digest.length > 0 &&
25
+ typeof v.command === "string" &&
26
+ v.command.length > 0 &&
27
+ typeof v.exitCode === "number" &&
28
+ Number.isFinite(v.exitCode));
29
+ }
30
+ /** Resolve deep-wall phase from env `OMK_WALL_DEEP_PHASE` (stub | docker). */
31
+ export function resolveDeepWallPhaseFromEnv() {
32
+ const raw = process.env.OMK_WALL_DEEP_PHASE?.trim().toLowerCase();
33
+ if (raw === "docker")
34
+ return "docker";
35
+ return "stub";
36
+ }
37
+ /**
38
+ * Hermetic deep runner is not shipped by default; `completed` is only reachable
39
+ * via an injected runner through {@link runDeepWall}, and even then requires evidence.
40
+ */
41
+ export function isDeepRunnerCompletionAllowed() {
42
+ return false;
43
+ }
44
+ /**
45
+ * Stub deep wall: always reports unavailable with batch-1 limit code (no docker exec).
46
+ */
47
+ export function runDeepWallStub(params) {
48
+ const phase = params.phase ?? resolveDeepWallPhaseFromEnv();
49
+ const message = phase === "docker" ? DOCKER_PHASE_MESSAGE : DEFAULT_DEEP_WALL_MESSAGE;
50
+ return {
51
+ status: "unavailable",
52
+ limits: [BATCH1_NO_DOCKER_RUNNER],
53
+ message,
54
+ };
55
+ }
56
+ /**
57
+ * Evidence-gated deep wall entry point.
58
+ *
59
+ * - No runner, or `allowCompletion !== true` → stub unavailable path.
60
+ * - Runner present + `allowCompletion` → runner is called in a try/catch.
61
+ * - `completed` + valid evidence → `completed` (evidence attached).
62
+ * - `completed` without valid evidence → downgraded to `unavailable`
63
+ * with `DEEP_RUNNER_EVIDENCE_MISSING` (candidate-patch-leak guard).
64
+ * - runner throws → `unavailable` with `DEEP_RUNNER_ERROR`.
65
+ */
66
+ export async function runDeepWall(params) {
67
+ if (params.runner !== undefined && params.allowCompletion === true) {
68
+ try {
69
+ const result = await params.runner(params);
70
+ if (result.status === "completed") {
71
+ if (hasValidEvidence(result.evidence)) {
72
+ return {
73
+ status: "completed",
74
+ evidence: result.evidence,
75
+ message: result.message,
76
+ };
77
+ }
78
+ return {
79
+ status: "unavailable",
80
+ message: "Deep runner reported completed without valid evidence; downgraded to unavailable.",
81
+ runnerFlags: [DEEP_RUNNER_EVIDENCE_MISSING],
82
+ };
83
+ }
84
+ return { status: "unavailable", message: result.message };
85
+ }
86
+ catch (err) {
87
+ return {
88
+ status: "unavailable",
89
+ message: `Deep runner threw: ${err instanceof Error ? err.message : String(err)}`,
90
+ runnerFlags: [DEEP_RUNNER_ERROR],
91
+ };
92
+ }
93
+ }
94
+ const stub = runDeepWallStub(params);
95
+ return { status: stub.status, message: stub.message, limits: stub.limits };
96
+ }
97
+ //# sourceMappingURL=deep-wall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-wall.js","sourceRoot":"","sources":["../src/deep-wall.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAM1D,MAAM,C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,CAAC;IACF,CAAC;IACD,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACrC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AAAA,CAC3E","sourcesContent":["/**\n * Deep Correctness Wall — stub default, plus evidence-gated runner injection (Wave 4-C3b).\n *\n * `completed` is NEVER emitted unless a caller injects a `runner`, sets\n * `allowCompletion`, AND the runner returns structured evidence. Without all\n * three, the result is downgraded to `unavailable`. This is a candidate-patch-leak\n * guard: deep completion must be evidence-backed, never asserted.\n */\n\nimport { BATCH1_NO_DOCKER_RUNNER } from \"./b2c-mapper.ts\";\n\nexport type DeepWallStatus = \"not_requested\" | \"unavailable\" | \"completed\";\n\nexport type DeepWallPhase = \"stub\" | \"docker\";\n\nexport const DEEP_WALL_UNAVAILABLE = \"DEEP_WALL_UNAVAILABLE\" as const;\n\n/** Policy flag when deep wall would report completed without a wired runner (Wave 4 gate). */\nexport const DEEP_RUNNER_NOT_WIRED = \"DEEP_RUNNER_NOT_WIRED\" as const;\n\n/** Policy flag when an injected runner returned `completed` without valid evidence (downgraded). */\nexport const DEEP_RUNNER_EVIDENCE_MISSING = \"DEEP_RUNNER_EVIDENCE_MISSING\" as const;\n\n/** Policy flag when an injected runner threw (caught, treated as unavailable). */\nexport const DEEP_RUNNER_ERROR = \"DEEP_RUNNER_ERROR\" as const;\n\n/** Structured evidence a runner MUST attach to a `completed` result. */\nexport interface DeepWallRunnerEvidence {\n\t/** Content digest of what was checked (e.g. sha256 of replayed patch + base). */\n\tdigest: string;\n\t/** The exact command/provenance the runner executed. */\n\tcommand: string;\n\t/** Runner exit code; `completed` requires `0` by runner contract. */\n\texitCode: number;\n}\n\nexport interface DeepWallRunnerResult {\n\tstatus: \"completed\" | \"unavailable\";\n\tevidence?: DeepWallRunnerEvidence;\n\tmessage: string;\n}\n\nexport type DeepWallRunnerFn = (params: RunDeepWallStubParams) => Promise<DeepWallRunnerResult>;\n\nexport interface RunDeepWallStubParams {\n\tkind: string;\n\trunIds?: string[];\n\tpacketId?: string;\n\t/** Wave 3: `docker` records intent; runner still unavailable until hermetic exec ships. */\n\tphase?: DeepWallPhase;\n\t/** Wave 4-C3b: injected hermetic runner. Completion is gated by `allowCompletion` + evidence. */\n\trunner?: DeepWallRunnerFn;\n\t/** Must be `true` for a runner to report `completed`; default `false` (stub path). */\n\tallowCompletion?: boolean;\n}\n\nexport interface DeepWallStubResult {\n\tstatus: Extract<DeepWallStatus, \"unavailable\">;\n\tlimits: readonly [typeof BATCH1_NO_DOCKER_RUNNER];\n\tmessage: string;\n}\n\nexport interface DeepWallResult {\n\tstatus: DeepWallStatus;\n\tmessage: string;\n\tevidence?: DeepWallRunnerEvidence;\n\tlimits?: readonly string[];\n\t/** Additional policy flags surfaced by the runner path (e.g. evidence-missing, runner-error). */\n\trunnerFlags?: readonly string[];\n}\n\nconst DEFAULT_DEEP_WALL_MESSAGE =\n\t\"Deep correctness check is not available in this environment (no docker runner). Use preview fast wall or run checks locally.\";\n\nconst DOCKER_PHASE_MESSAGE =\n\t\"Deep wall docker phase requested but hermetic runner is not wired yet; fast wall and local CI remain authoritative.\";\n\nfunction hasValidEvidence(e: unknown): e is DeepWallRunnerEvidence {\n\tif (typeof e !== \"object\" || e === null) return false;\n\tconst v = e as DeepWallRunnerEvidence;\n\treturn (\n\t\ttypeof v.digest === \"string\" &&\n\t\tv.digest.length > 0 &&\n\t\ttypeof v.command === \"string\" &&\n\t\tv.command.length > 0 &&\n\t\ttypeof v.exitCode === \"number\" &&\n\t\tNumber.isFinite(v.exitCode)\n\t);\n}\n\n/** Resolve deep-wall phase from env `OMK_WALL_DEEP_PHASE` (stub | docker). */\nexport function resolveDeepWallPhaseFromEnv(): DeepWallPhase {\n\tconst raw = process.env.OMK_WALL_DEEP_PHASE?.trim().toLowerCase();\n\tif (raw === \"docker\") return \"docker\";\n\treturn \"stub\";\n}\n\n/**\n * Hermetic deep runner is not shipped by default; `completed` is only reachable\n * via an injected runner through {@link runDeepWall}, and even then requires evidence.\n */\nexport function isDeepRunnerCompletionAllowed(): boolean {\n\treturn false;\n}\n\n/**\n * Stub deep wall: always reports unavailable with batch-1 limit code (no docker exec).\n */\nexport function runDeepWallStub(params: RunDeepWallStubParams): DeepWallStubResult {\n\tconst phase = params.phase ?? resolveDeepWallPhaseFromEnv();\n\tconst message = phase === \"docker\" ? DOCKER_PHASE_MESSAGE : DEFAULT_DEEP_WALL_MESSAGE;\n\treturn {\n\t\tstatus: \"unavailable\",\n\t\tlimits: [BATCH1_NO_DOCKER_RUNNER],\n\t\tmessage,\n\t};\n}\n\n/**\n * Evidence-gated deep wall entry point.\n *\n * - No runner, or `allowCompletion !== true` → stub unavailable path.\n * - Runner present + `allowCompletion` → runner is called in a try/catch.\n * - `completed` + valid evidence → `completed` (evidence attached).\n * - `completed` without valid evidence → downgraded to `unavailable`\n * with `DEEP_RUNNER_EVIDENCE_MISSING` (candidate-patch-leak guard).\n * - runner throws → `unavailable` with `DEEP_RUNNER_ERROR`.\n */\nexport async function runDeepWall(params: RunDeepWallStubParams): Promise<DeepWallResult> {\n\tif (params.runner !== undefined && params.allowCompletion === true) {\n\t\ttry {\n\t\t\tconst result = await params.runner(params);\n\t\t\tif (result.status === \"completed\") {\n\t\t\t\tif (hasValidEvidence(result.evidence)) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\tevidence: result.evidence,\n\t\t\t\t\t\tmessage: result.message,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"unavailable\",\n\t\t\t\t\tmessage: \"Deep runner reported completed without valid evidence; downgraded to unavailable.\",\n\t\t\t\t\trunnerFlags: [DEEP_RUNNER_EVIDENCE_MISSING],\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { status: \"unavailable\", message: result.message };\n\t\t} catch (err) {\n\t\t\treturn {\n\t\t\t\tstatus: \"unavailable\",\n\t\t\t\tmessage: `Deep runner threw: ${err instanceof Error ? err.message : String(err)}`,\n\t\t\t\trunnerFlags: [DEEP_RUNNER_ERROR],\n\t\t\t};\n\t\t}\n\t}\n\tconst stub = runDeepWallStub(params);\n\treturn { status: stub.status, message: stub.message, limits: stub.limits };\n}\n"]}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * B2C Correctness Wall orchestration — fast wall + optional OA adjudication.
3
+ */
4
+ import type { AdaptOrchClient } from "./adaptorch-client.ts";
5
+ import { type VerifierRegistryEntry } from "./adjudicator-registry.ts";
6
+ import type { VerdictCard, VerificationReceipt } from "./b2c-verdict.ts";
7
+ import { type DeepWallRunnerFn } from "./deep-wall.ts";
8
+ export interface EvaluateCorrectnessWallParams {
9
+ kind: string;
10
+ runIds?: string[];
11
+ dispatchRecordId?: string;
12
+ approvedWriteScope?: string[];
13
+ previewOnly?: boolean;
14
+ diffText?: string;
15
+ packetId?: string;
16
+ /** When set with non-empty runIds and previewOnly false, OA adjudication is invoked. */
17
+ client?: AdaptOrchClient;
18
+ registry?: {
19
+ get(kind: string): VerifierRegistryEntry;
20
+ };
21
+ /** When true, merge deep-wall result into limits / policy flags. */
22
+ deepWall?: boolean;
23
+ /** Wave 4-C3b: injected hermetic runner. Completion gated by `deepWallAllowCompletion` + evidence. */
24
+ deepWallRunner?: DeepWallRunnerFn;
25
+ /** Must be true for a runner to emit `completed`. */
26
+ deepWallAllowCompletion?: boolean;
27
+ /** When set, attach HMAC signed receipt attestation (never log secret). */
28
+ receiptSigningSecret?: string;
29
+ }
30
+ export interface EvaluateCorrectnessWallResult {
31
+ verdictCard: VerdictCard;
32
+ receipt: VerificationReceipt;
33
+ }
34
+ export declare function evaluateCorrectnessWall(params: EvaluateCorrectnessWallParams): Promise<EvaluateCorrectnessWallResult>;
35
+ //# sourceMappingURL=evaluate-correctness-wall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate-correctness-wall.d.ts","sourceRoot":"","sources":["../src/evaluate-correctness-wall.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAA0B,KAAK,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAE/F,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAGN,KAAK,gBAAgB,EAIrB,MAAM,gBAAgB,CAAC;AAOxB,MAAM,WAAW,6BAA6B;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,QAAQ,CAAC,EAAE;QAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,CAAA;KAAE,CAAC;IACxD,oEAAoE;IACpE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sGAAsG;IACtG,cAAc,CAAC,EAAE,gBAAgB,CAAC;IAClC,qDAAqD;IACrD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,2EAA2E;IAC3E,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,6BAA6B;IAC7C,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,EAAE,mBAAmB,CAAC;CAC7B;AAED,wBAAsB,uBAAuB,CAC5C,MAAM,EAAE,6BAA6B,GACnC,OAAO,CAAC,6BAA6B,CAAC,CA4HxC","sourcesContent":["/**\n * B2C Correctness Wall orchestration — fast wall + optional OA adjudication.\n */\n\nimport type { AdaptOrchClient } from \"./adaptorch-client.ts\";\nimport { type AdjudicationRequest, adjudicate } from \"./adjudicator.ts\";\nimport { createVerifierRegistry, type VerifierRegistryEntry } from \"./adjudicator-registry.ts\";\nimport { mapToB2C } from \"./b2c-mapper.ts\";\nimport type { VerdictCard, VerificationReceipt } from \"./b2c-verdict.ts\";\nimport {\n\tDEEP_RUNNER_NOT_WIRED,\n\tDEEP_WALL_UNAVAILABLE,\n\ttype DeepWallRunnerFn,\n\tisDeepRunnerCompletionAllowed,\n\tresolveDeepWallPhaseFromEnv,\n\trunDeepWall,\n} from \"./deep-wall.ts\";\nimport { runFastWall } from \"./policy-wall.ts\";\nimport { signWallReceipt } from \"./receipt-signature.ts\";\nimport { deriveRepairHints } from \"./repair-loop.ts\";\nimport { buildVerificationDigest } from \"./signed-receipt.ts\";\nimport { CORRECTNESS_WALL_VERSION } from \"./wall-meta.ts\";\n\nexport interface EvaluateCorrectnessWallParams {\n\tkind: string;\n\trunIds?: string[];\n\tdispatchRecordId?: string;\n\tapprovedWriteScope?: string[];\n\tpreviewOnly?: boolean;\n\tdiffText?: string;\n\tpacketId?: string;\n\t/** When set with non-empty runIds and previewOnly false, OA adjudication is invoked. */\n\tclient?: AdaptOrchClient;\n\tregistry?: { get(kind: string): VerifierRegistryEntry };\n\t/** When true, merge deep-wall result into limits / policy flags. */\n\tdeepWall?: boolean;\n\t/** Wave 4-C3b: injected hermetic runner. Completion gated by `deepWallAllowCompletion` + evidence. */\n\tdeepWallRunner?: DeepWallRunnerFn;\n\t/** Must be true for a runner to emit `completed`. */\n\tdeepWallAllowCompletion?: boolean;\n\t/** When set, attach HMAC signed receipt attestation (never log secret). */\n\treceiptSigningSecret?: string;\n}\n\nexport interface EvaluateCorrectnessWallResult {\n\tverdictCard: VerdictCard;\n\treceipt: VerificationReceipt;\n}\n\nexport async function evaluateCorrectnessWall(\n\tparams: EvaluateCorrectnessWallParams,\n): Promise<EvaluateCorrectnessWallResult> {\n\tconst runIds = params.runIds ?? [];\n\tconst previewOnly = params.previewOnly === true;\n\tconst registry = params.registry ?? createVerifierRegistry([]);\n\n\tconst wall = runFastWall({\n\t\tdiffText: params.diffText,\n\t\tapprovedWriteScope: params.approvedWriteScope,\n\t\trunIds,\n\t\tpreviewOnly,\n\t});\n\n\tlet adjudication: Awaited<ReturnType<typeof adjudicate>> | undefined;\n\tconst useOa = runIds.length > 0 && !previewOnly && params.client !== undefined;\n\tif (useOa && params.client !== undefined) {\n\t\tconst request: AdjudicationRequest = {\n\t\t\tdispatch_record_id: params.dispatchRecordId ?? \"b2c-wall\",\n\t\t\tkind: params.kind,\n\t\t\trun_ids: runIds,\n\t\t};\n\t\tadjudication = await adjudicate(request, params.client, registry);\n\t}\n\n\tlet policyFlags = wall.flags;\n\tif (adjudication !== undefined) {\n\t\tpolicyFlags = wall.flags.filter((f) => f !== \"EVIDENCE_DAG_INCOMPLETE\");\n\t}\n\n\tconst provisional = mapToB2C({\n\t\tkind: params.kind,\n\t\tpacketId: params.packetId,\n\t\tdispatchRecordId: params.dispatchRecordId,\n\t\trunIds,\n\t\tpreviewOnly,\n\t\tpolicyFlags,\n\t\tdiffPaths: wall.diffPaths,\n\t\tadjudication,\n\t});\n\n\tconst repairHints = deriveRepairHints({\n\t\tuserVerdict: provisional.verdictCard.verdict,\n\t\tpolicyFlags,\n\t\tadjudicationReasonCode: adjudication?.reason_code,\n\t\tpreviewOnly,\n\t\tdiffPaths: wall.diffPaths,\n\t});\n\n\tconst mapped = mapToB2C({\n\t\tkind: params.kind,\n\t\tpacketId: params.packetId,\n\t\tdispatchRecordId: params.dispatchRecordId,\n\t\trunIds,\n\t\tpreviewOnly,\n\t\tpolicyFlags,\n\t\tdiffPaths: wall.diffPaths,\n\t\tadjudication,\n\t\trepairHints,\n\t});\n\n\tconst verificationDigest = buildVerificationDigest({\n\t\tpatchText: params.diffText,\n\t\tevidenceChunks: runIds.length > 0 ? runIds : undefined,\n\t\twallVersion: CORRECTNESS_WALL_VERSION,\n\t});\n\n\tlet verdictCard = mapped.verdictCard;\n\tlet receipt: VerificationReceipt = {\n\t\t...mapped.receipt,\n\t\tverificationDigest,\n\t\twallVersion: CORRECTNESS_WALL_VERSION,\n\t};\n\n\tconst signingSecret = params.receiptSigningSecret?.trim();\n\tif (signingSecret !== undefined && signingSecret.length > 0 && verificationDigest !== undefined) {\n\t\treceipt = {\n\t\t\t...receipt,\n\t\t\tsignedReceipt: signWallReceipt({\n\t\t\t\tdigest: verificationDigest,\n\t\t\t\twallVersion: CORRECTNESS_WALL_VERSION,\n\t\t\t\tsecret: signingSecret,\n\t\t\t}),\n\t\t};\n\t}\n\n\tif (params.deepWall === true) {\n\t\tconst deep = await runDeepWall({\n\t\t\tkind: params.kind,\n\t\t\trunIds,\n\t\t\tpacketId: params.packetId,\n\t\t\tphase: resolveDeepWallPhaseFromEnv(),\n\t\t\trunner: params.deepWallRunner,\n\t\t\tallowCompletion: params.deepWallAllowCompletion,\n\t\t});\n\t\tconst policyFlags = [...receipt.policyFlags];\n\t\tif (deep.status !== \"completed\") {\n\t\t\tif (!policyFlags.includes(DEEP_WALL_UNAVAILABLE)) {\n\t\t\t\tpolicyFlags.push(DEEP_WALL_UNAVAILABLE);\n\t\t\t}\n\t\t\tif (!isDeepRunnerCompletionAllowed() && !policyFlags.includes(DEEP_RUNNER_NOT_WIRED)) {\n\t\t\t\tpolicyFlags.push(DEEP_RUNNER_NOT_WIRED);\n\t\t\t}\n\t\t}\n\t\tfor (const f of deep.runnerFlags ?? []) {\n\t\t\tif (!policyFlags.includes(f as never)) policyFlags.push(f as never);\n\t\t}\n\t\tconst limitsCode = deep.limits?.[0] ?? verdictCard.limits.code;\n\t\tverdictCard = {\n\t\t\t...verdictCard,\n\t\t\tlimits: {\n\t\t\t\t...verdictCard.limits,\n\t\t\t\trequiresHumanReview: deep.status !== \"completed\",\n\t\t\t\tcode: limitsCode ?? verdictCard.limits.code,\n\t\t\t},\n\t\t\tblocked_reasons: [...new Set([...verdictCard.blocked_reasons, deep.message])],\n\t\t};\n\t\treceipt = {\n\t\t\t...receipt,\n\t\t\tpolicyFlags,\n\t\t\tdeepWallStatus: deep.status,\n\t\t\tdeepWallEvidence: deep.evidence,\n\t\t};\n\t}\n\n\treturn { verdictCard, receipt };\n}\n"]}