omk-protocol 0.99.0 → 1.2.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.
- package/CHANGELOG.md +7 -1
- package/dist/evaluation.d.ts.map +1 -1
- package/dist/evaluation.js +50 -7
- package/dist/evaluation.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/strict-evidence-types.d.ts +37 -0
- package/dist/strict-evidence-types.d.ts.map +1 -0
- package/dist/strict-evidence-types.js +2 -0
- package/dist/strict-evidence-types.js.map +1 -0
- package/dist/strict-evidence-validation.d.ts +4 -0
- package/dist/strict-evidence-validation.d.ts.map +1 -0
- package/dist/strict-evidence-validation.js +68 -0
- package/dist/strict-evidence-validation.js.map +1 -0
- package/dist/strict-evidence.d.ts +5 -0
- package/dist/strict-evidence.d.ts.map +1 -0
- package/dist/strict-evidence.js +84 -0
- package/dist/strict-evidence.js.map +1 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +5 -0
- package/dist/validation.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [
|
|
3
|
+
## [1.2.0] - 2026-09-20
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-09-18
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Strict-evidence contract: `StrictEvidenceBinding`, `StrictEvidenceSnapshot`, `StrictEvidenceReport`, and `StrictEvidenceCompletion` wire types with parsers, plus `evaluateStrictEvidence` wired into evaluation so an admitted snapshot can gate results. A snapshot is evidence, not approval or execution by itself.
|
|
4
10
|
|
|
5
11
|
## [0.99.0] - 2026-09-13
|
|
6
12
|
|
package/dist/evaluation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluation.d.ts","sourceRoot":"","sources":["../src/evaluation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evaluation.d.ts","sourceRoot":"","sources":["../src/evaluation.ts"],"names":[],"mappings":"AACA,OAAO,EAIN,KAAK,eAAe,EACpB,KAAK,gBAAgB,EAMrB,MAAM,YAAY,CAAC;AASpB,qBAAa,sBAAuB,SAAQ,KAAK;IAChD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAsID,4DAA4D;AAC5D,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CAsErE","sourcesContent":["import { evaluateStrictEvidence } from \"./strict-evidence.ts\";\nimport {\n\ttype ClaimCondition,\n\ttype ClaimEvaluation,\n\ttype ClaimResult,\n\ttype EvaluationInput,\n\ttype EvaluationResult,\n\ttype JsonValue,\n\ttype Observation,\n\tPROTOCOL_VERSION,\n\ttype SemanticVerdict,\n\ttype WaiverRecord,\n} from \"./types.ts\";\nimport {\n\tparseEvaluationResult,\n\tparseExecutionAttempt,\n\tparseObservation,\n\tparseTaskSpec,\n\tparseWaiverRecord,\n} from \"./validation.ts\";\n\nexport class ProtocolInvariantError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"ProtocolInvariantError\";\n\t}\n}\n\ninterface ConditionResult {\n\treadonly result: ClaimResult;\n\treadonly observationIds: readonly string[];\n}\n\nfunction isObject(value: JsonValue): value is { readonly [key: string]: JsonValue } {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction matchesExpected(actual: JsonValue | undefined, expected: JsonValue): boolean {\n\tif (Array.isArray(expected)) {\n\t\treturn (\n\t\t\tArray.isArray(actual) &&\n\t\t\tactual.length === expected.length &&\n\t\t\texpected.every((value, index) => matchesExpected(actual[index], value))\n\t\t);\n\t}\n\tif (isObject(expected)) {\n\t\treturn (\n\t\t\tactual !== undefined &&\n\t\t\tisObject(actual) &&\n\t\t\tObject.entries(expected).every(([key, value]) => matchesExpected(actual[key], value))\n\t\t);\n\t}\n\treturn Object.is(actual, expected);\n}\n\nfunction unique(values: readonly string[]): readonly string[] {\n\treturn [...new Set(values)];\n}\n\nfunction evaluateCondition(\n\tcondition: ClaimCondition,\n\tobservations: readonly Observation[],\n\tattemptId: string,\n\tcandidateHash?: string,\n): ConditionResult {\n\tif (condition.kind === \"observation\") {\n\t\tconst candidates = observations.filter((observation) => {\n\t\t\tif (observation.kind !== condition.observationKind) return false;\n\t\t\tif (condition.scope === \"attempt\" && observation.attemptId !== attemptId) return false;\n\t\t\t// Candidate binding: when the attempt declares a candidate hash, an\n\t\t\t// observation recorded for a different candidate cannot satisfy this\n\t\t\t// attempt's condition — a stale pass is not evidence for this build.\n\t\t\tif (candidateHash !== undefined) {\n\t\t\t\tconst observed = observation.facts.candidate;\n\t\t\t\tif (typeof observed === \"string\" && observed !== candidateHash) return false;\n\t\t\t}\n\t\t\t// Explicit per-condition binding additionally requires the\n\t\t\t// observation to name the same candidate outright.\n\t\t\tif (condition.bindToCandidate === true) {\n\t\t\t\tif (candidateHash === undefined || observation.facts.candidate !== candidateHash) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\t\tif (candidates.length === 0) return { result: \"inconclusive\", observationIds: [] };\n\t\tconst matching = candidates.filter((observation) => matchesExpected(observation.facts, condition.facts));\n\t\treturn matching.length > 0\n\t\t\t? { result: \"satisfied\", observationIds: matching.map(({ observationId }) => observationId) }\n\t\t\t: { result: \"violated\", observationIds: candidates.map(({ observationId }) => observationId) };\n\t}\n\n\tif (condition.kind === \"not\") {\n\t\tconst child = evaluateCondition(condition.condition, observations, attemptId, candidateHash);\n\t\treturn {\n\t\t\tresult: child.result === \"satisfied\" ? \"violated\" : child.result === \"violated\" ? \"satisfied\" : \"inconclusive\",\n\t\t\tobservationIds: child.observationIds,\n\t\t};\n\t}\n\n\tconst children = condition.conditions.map((child) =>\n\t\tevaluateCondition(child, observations, attemptId, candidateHash),\n\t);\n\tif (condition.kind === \"all\") {\n\t\tconst result = children.some((child) => child.result === \"violated\")\n\t\t\t? \"violated\"\n\t\t\t: children.some((child) => child.result === \"inconclusive\")\n\t\t\t\t? \"inconclusive\"\n\t\t\t\t: \"satisfied\";\n\t\treturn { result, observationIds: unique(children.flatMap(({ observationIds }) => observationIds)) };\n\t}\n\tconst result = children.some((child) => child.result === \"satisfied\")\n\t\t? \"satisfied\"\n\t\t: children.every((child) => child.result === \"violated\")\n\t\t\t? \"violated\"\n\t\t\t: \"inconclusive\";\n\treturn { result, observationIds: unique(children.flatMap(({ observationIds }) => observationIds)) };\n}\n\nfunction reasonCode(result: ClaimResult): ClaimEvaluation[\"reasonCode\"] {\n\tif (result === \"satisfied\") return \"claim.satisfied\";\n\tif (result === \"violated\") return \"claim.violated\";\n\treturn \"claim.observation_missing\";\n}\n\nfunction validateWaivers(input: EvaluationInput, waivers: readonly WaiverRecord[]): ReadonlyMap<string, WaiverRecord> {\n\tconst claims = new Map(input.taskSpec.claims.map((claim) => [claim.claimId, claim]));\n\tconst byClaim = new Map<string, WaiverRecord>();\n\tfor (const waiver of waivers) {\n\t\tparseWaiverRecord(waiver);\n\t\tif (waiver.scope.taskId !== input.taskSpec.taskId) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} targets task ${waiver.scope.taskId}`);\n\t\t}\n\t\tconst claim = claims.get(waiver.scope.claimId);\n\t\tif (!claim) throw new ProtocolInvariantError(`${waiver.waiverId} targets unknown claim ${waiver.scope.claimId}`);\n\t\tif (claim.requirement !== \"required\") {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} cannot waive advisory claim ${claim.claimId}`);\n\t\t}\n\t\tif (waiver.scope.attemptId !== undefined && waiver.scope.attemptId !== input.attempt.attemptId) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} targets attempt ${waiver.scope.attemptId}`);\n\t\t}\n\t\tif (waiver.approvedAt > input.evaluatedAt) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} was approved after evaluation`);\n\t\t}\n\t\tif (waiver.expiresAt !== undefined && waiver.expiresAt <= input.evaluatedAt) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} is expired`);\n\t\t}\n\t\tif (byClaim.has(claim.claimId))\n\t\t\tthrow new ProtocolInvariantError(`multiple waivers target claim ${claim.claimId}`);\n\t\tbyClaim.set(claim.claimId, waiver);\n\t}\n\treturn byClaim;\n}\n\nfunction reduceVerdict(claims: readonly ClaimEvaluation[]): SemanticVerdict {\n\tconst required = claims.filter((claim) => claim.requirement === \"required\" && claim.waiverId === undefined);\n\tif (required.length === 0) return claims.some((claim) => claim.requirement === \"required\") ? \"pass\" : \"inconclusive\";\n\tif (required.some((claim) => claim.result === \"violated\")) return \"fail\";\n\tif (required.some((claim) => claim.result === \"inconclusive\")) return \"inconclusive\";\n\treturn \"pass\";\n}\n\n/** Pure TaskSpec -> Observation -> Evaluation reduction. */\nexport function evaluateTask(input: EvaluationInput): EvaluationResult {\n\tparseTaskSpec(input.taskSpec);\n\tparseExecutionAttempt(input.attempt);\n\tif (input.attempt.taskId !== input.taskSpec.taskId) {\n\t\tthrow new ProtocolInvariantError(`${input.attempt.attemptId} targets task ${input.attempt.taskId}`);\n\t}\n\tfor (const observation of input.observations) {\n\t\tparseObservation(observation);\n\t\tif (observation.taskId !== input.taskSpec.taskId) {\n\t\t\tthrow new ProtocolInvariantError(`${observation.observationId} targets task ${observation.taskId}`);\n\t\t}\n\t}\n\tconst waivers = validateWaivers(input, input.waivers ?? []);\n\tconst strict =\n\t\tinput.strictEvidence === undefined\n\t\t\t? undefined\n\t\t\t: evaluateStrictEvidence(input.strictEvidence, input.observations, input.attempt);\n\tconst observations =\n\t\tstrict === undefined\n\t\t\t? input.observations\n\t\t\t: input.observations.filter((observation) => strict.observationIds.includes(observation.observationId));\n\tconst claims = Object.freeze(\n\t\tinput.taskSpec.claims.map((claim): ClaimEvaluation => {\n\t\t\tconst evaluated = evaluateCondition(\n\t\t\t\tclaim.condition,\n\t\t\t\tobservations,\n\t\t\t\tinput.attempt.attemptId,\n\t\t\t\tinput.attempt.candidateHash,\n\t\t\t);\n\t\t\tconst waiver = evaluated.result === \"satisfied\" ? undefined : waivers.get(claim.claimId);\n\t\t\treturn Object.freeze({\n\t\t\t\tclaimId: claim.claimId,\n\t\t\t\trequirement: claim.requirement,\n\t\t\t\tresult: evaluated.result,\n\t\t\t\treasonCode: reasonCode(evaluated.result),\n\t\t\t\tobservationIds: Object.freeze([...evaluated.observationIds]),\n\t\t\t\t...(waiver ? { waiverId: waiver.waiverId } : {}),\n\t\t\t});\n\t\t}),\n\t);\n\tconst semanticVerdict =\n\t\tstrict && strict.status !== \"passed\"\n\t\t\t? strict.status === \"violated\"\n\t\t\t\t? \"fail\"\n\t\t\t\t: \"inconclusive\"\n\t\t\t: reduceVerdict(claims);\n\treturn parseEvaluationResult(\n\t\tObject.freeze({\n\t\t\tschemaVersion: PROTOCOL_VERSION,\n\t\t\tevaluationId: input.evaluationId,\n\t\t\ttaskId: input.taskSpec.taskId,\n\t\t\tattemptId: input.attempt.attemptId,\n\t\t\tevaluatedAt: input.evaluatedAt,\n\t\t\tclaims,\n\t\t\tsemanticVerdict,\n\t\t\t...(strict\n\t\t\t\t? {\n\t\t\t\t\t\tstrictEvidence: Object.freeze({\n\t\t\t\t\t\t\t...strict,\n\t\t\t\t\t\t\tacceptance:\n\t\t\t\t\t\t\t\tsemanticVerdict !== \"pass\"\n\t\t\t\t\t\t\t\t\t? (\"denied\" as const)\n\t\t\t\t\t\t\t\t\t: claims.some((claim) => claim.waiverId !== undefined)\n\t\t\t\t\t\t\t\t\t\t? (\"accepted_with_waiver\" as const)\n\t\t\t\t\t\t\t\t\t\t: (\"passed_by_checks\" as const),\n\t\t\t\t\t\t}),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t}),\n\t);\n}\n"]}
|
package/dist/evaluation.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { evaluateStrictEvidence } from "./strict-evidence.js";
|
|
1
2
|
import { PROTOCOL_VERSION, } from "./types.js";
|
|
2
3
|
import { parseEvaluationResult, parseExecutionAttempt, parseObservation, parseTaskSpec, parseWaiverRecord, } from "./validation.js";
|
|
3
4
|
export class ProtocolInvariantError extends Error {
|
|
@@ -25,10 +26,29 @@ function matchesExpected(actual, expected) {
|
|
|
25
26
|
function unique(values) {
|
|
26
27
|
return [...new Set(values)];
|
|
27
28
|
}
|
|
28
|
-
function evaluateCondition(condition, observations, attemptId) {
|
|
29
|
+
function evaluateCondition(condition, observations, attemptId, candidateHash) {
|
|
29
30
|
if (condition.kind === "observation") {
|
|
30
|
-
const candidates = observations.filter((observation) =>
|
|
31
|
-
(
|
|
31
|
+
const candidates = observations.filter((observation) => {
|
|
32
|
+
if (observation.kind !== condition.observationKind)
|
|
33
|
+
return false;
|
|
34
|
+
if (condition.scope === "attempt" && observation.attemptId !== attemptId)
|
|
35
|
+
return false;
|
|
36
|
+
// Candidate binding: when the attempt declares a candidate hash, an
|
|
37
|
+
// observation recorded for a different candidate cannot satisfy this
|
|
38
|
+
// attempt's condition — a stale pass is not evidence for this build.
|
|
39
|
+
if (candidateHash !== undefined) {
|
|
40
|
+
const observed = observation.facts.candidate;
|
|
41
|
+
if (typeof observed === "string" && observed !== candidateHash)
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
// Explicit per-condition binding additionally requires the
|
|
45
|
+
// observation to name the same candidate outright.
|
|
46
|
+
if (condition.bindToCandidate === true) {
|
|
47
|
+
if (candidateHash === undefined || observation.facts.candidate !== candidateHash)
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
});
|
|
32
52
|
if (candidates.length === 0)
|
|
33
53
|
return { result: "inconclusive", observationIds: [] };
|
|
34
54
|
const matching = candidates.filter((observation) => matchesExpected(observation.facts, condition.facts));
|
|
@@ -37,13 +57,13 @@ function evaluateCondition(condition, observations, attemptId) {
|
|
|
37
57
|
: { result: "violated", observationIds: candidates.map(({ observationId }) => observationId) };
|
|
38
58
|
}
|
|
39
59
|
if (condition.kind === "not") {
|
|
40
|
-
const child = evaluateCondition(condition.condition, observations, attemptId);
|
|
60
|
+
const child = evaluateCondition(condition.condition, observations, attemptId, candidateHash);
|
|
41
61
|
return {
|
|
42
62
|
result: child.result === "satisfied" ? "violated" : child.result === "violated" ? "satisfied" : "inconclusive",
|
|
43
63
|
observationIds: child.observationIds,
|
|
44
64
|
};
|
|
45
65
|
}
|
|
46
|
-
const children = condition.conditions.map((child) => evaluateCondition(child, observations, attemptId));
|
|
66
|
+
const children = condition.conditions.map((child) => evaluateCondition(child, observations, attemptId, candidateHash));
|
|
47
67
|
if (condition.kind === "all") {
|
|
48
68
|
const result = children.some((child) => child.result === "violated")
|
|
49
69
|
? "violated"
|
|
@@ -119,8 +139,14 @@ export function evaluateTask(input) {
|
|
|
119
139
|
}
|
|
120
140
|
}
|
|
121
141
|
const waivers = validateWaivers(input, input.waivers ?? []);
|
|
142
|
+
const strict = input.strictEvidence === undefined
|
|
143
|
+
? undefined
|
|
144
|
+
: evaluateStrictEvidence(input.strictEvidence, input.observations, input.attempt);
|
|
145
|
+
const observations = strict === undefined
|
|
146
|
+
? input.observations
|
|
147
|
+
: input.observations.filter((observation) => strict.observationIds.includes(observation.observationId));
|
|
122
148
|
const claims = Object.freeze(input.taskSpec.claims.map((claim) => {
|
|
123
|
-
const evaluated = evaluateCondition(claim.condition, input.
|
|
149
|
+
const evaluated = evaluateCondition(claim.condition, observations, input.attempt.attemptId, input.attempt.candidateHash);
|
|
124
150
|
const waiver = evaluated.result === "satisfied" ? undefined : waivers.get(claim.claimId);
|
|
125
151
|
return Object.freeze({
|
|
126
152
|
claimId: claim.claimId,
|
|
@@ -131,6 +157,11 @@ export function evaluateTask(input) {
|
|
|
131
157
|
...(waiver ? { waiverId: waiver.waiverId } : {}),
|
|
132
158
|
});
|
|
133
159
|
}));
|
|
160
|
+
const semanticVerdict = strict && strict.status !== "passed"
|
|
161
|
+
? strict.status === "violated"
|
|
162
|
+
? "fail"
|
|
163
|
+
: "inconclusive"
|
|
164
|
+
: reduceVerdict(claims);
|
|
134
165
|
return parseEvaluationResult(Object.freeze({
|
|
135
166
|
schemaVersion: PROTOCOL_VERSION,
|
|
136
167
|
evaluationId: input.evaluationId,
|
|
@@ -138,7 +169,19 @@ export function evaluateTask(input) {
|
|
|
138
169
|
attemptId: input.attempt.attemptId,
|
|
139
170
|
evaluatedAt: input.evaluatedAt,
|
|
140
171
|
claims,
|
|
141
|
-
semanticVerdict
|
|
172
|
+
semanticVerdict,
|
|
173
|
+
...(strict
|
|
174
|
+
? {
|
|
175
|
+
strictEvidence: Object.freeze({
|
|
176
|
+
...strict,
|
|
177
|
+
acceptance: semanticVerdict !== "pass"
|
|
178
|
+
? "denied"
|
|
179
|
+
: claims.some((claim) => claim.waiverId !== undefined)
|
|
180
|
+
? "accepted_with_waiver"
|
|
181
|
+
: "passed_by_checks",
|
|
182
|
+
}),
|
|
183
|
+
}
|
|
184
|
+
: {}),
|
|
142
185
|
}));
|
|
143
186
|
}
|
|
144
187
|
//# sourceMappingURL=evaluation.js.map
|
package/dist/evaluation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluation.js","sourceRoot":"","sources":["../src/evaluation.ts"],"names":[],"mappings":"AAAA,OAAO,EAQN,gBAAgB,GAGhB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,GACjB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAChD,YAAY,OAAe,EAAE;QAC5B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IAAA,CACrC;CACD;AAOD,SAAS,QAAQ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AAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACzF,OAAO,MAAM,CAAC,MAAM,CAAC;YACpB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,MAAM,EAAE,SAAS,CAAC,MAAM;YACxB,UAAU,EAAE,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC;YACxC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;YAC5D,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChD,CAAC,CAAC;IAAA,CACH,CAAC,CACF,CAAC;IACF,OAAO,qBAAqB,CAC3B,MAAM,CAAC,MAAM,CAAC;QACb,aAAa,EAAE,gBAAgB;QAC/B,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM;QAC7B,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS;QAClC,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,MAAM;QACN,eAAe,EAAE,aAAa,CAAC,MAAM,CAAC;KACtC,CAAC,CACF,CAAC;AAAA,CACF","sourcesContent":["import {\n\ttype ClaimCondition,\n\ttype ClaimEvaluation,\n\ttype ClaimResult,\n\ttype EvaluationInput,\n\ttype EvaluationResult,\n\ttype JsonValue,\n\ttype Observation,\n\tPROTOCOL_VERSION,\n\ttype SemanticVerdict,\n\ttype WaiverRecord,\n} from \"./types.ts\";\nimport {\n\tparseEvaluationResult,\n\tparseExecutionAttempt,\n\tparseObservation,\n\tparseTaskSpec,\n\tparseWaiverRecord,\n} from \"./validation.ts\";\n\nexport class ProtocolInvariantError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"ProtocolInvariantError\";\n\t}\n}\n\ninterface ConditionResult {\n\treadonly result: ClaimResult;\n\treadonly observationIds: readonly string[];\n}\n\nfunction isObject(value: JsonValue): value is { readonly [key: string]: JsonValue } {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction matchesExpected(actual: JsonValue | undefined, expected: JsonValue): boolean {\n\tif (Array.isArray(expected)) {\n\t\treturn (\n\t\t\tArray.isArray(actual) &&\n\t\t\tactual.length === expected.length &&\n\t\t\texpected.every((value, index) => matchesExpected(actual[index], value))\n\t\t);\n\t}\n\tif (isObject(expected)) {\n\t\treturn (\n\t\t\tactual !== undefined &&\n\t\t\tisObject(actual) &&\n\t\t\tObject.entries(expected).every(([key, value]) => matchesExpected(actual[key], value))\n\t\t);\n\t}\n\treturn Object.is(actual, expected);\n}\n\nfunction unique(values: readonly string[]): readonly string[] {\n\treturn [...new Set(values)];\n}\n\nfunction evaluateCondition(\n\tcondition: ClaimCondition,\n\tobservations: readonly Observation[],\n\tattemptId: string,\n): ConditionResult {\n\tif (condition.kind === \"observation\") {\n\t\tconst candidates = observations.filter(\n\t\t\t(observation) =>\n\t\t\t\tobservation.kind === condition.observationKind &&\n\t\t\t\t(condition.scope === \"task\" || observation.attemptId === attemptId),\n\t\t);\n\t\tif (candidates.length === 0) return { result: \"inconclusive\", observationIds: [] };\n\t\tconst matching = candidates.filter((observation) => matchesExpected(observation.facts, condition.facts));\n\t\treturn matching.length > 0\n\t\t\t? { result: \"satisfied\", observationIds: matching.map(({ observationId }) => observationId) }\n\t\t\t: { result: \"violated\", observationIds: candidates.map(({ observationId }) => observationId) };\n\t}\n\n\tif (condition.kind === \"not\") {\n\t\tconst child = evaluateCondition(condition.condition, observations, attemptId);\n\t\treturn {\n\t\t\tresult: child.result === \"satisfied\" ? \"violated\" : child.result === \"violated\" ? \"satisfied\" : \"inconclusive\",\n\t\t\tobservationIds: child.observationIds,\n\t\t};\n\t}\n\n\tconst children = condition.conditions.map((child) => evaluateCondition(child, observations, attemptId));\n\tif (condition.kind === \"all\") {\n\t\tconst result = children.some((child) => child.result === \"violated\")\n\t\t\t? \"violated\"\n\t\t\t: children.some((child) => child.result === \"inconclusive\")\n\t\t\t\t? \"inconclusive\"\n\t\t\t\t: \"satisfied\";\n\t\treturn { result, observationIds: unique(children.flatMap(({ observationIds }) => observationIds)) };\n\t}\n\tconst result = children.some((child) => child.result === \"satisfied\")\n\t\t? \"satisfied\"\n\t\t: children.every((child) => child.result === \"violated\")\n\t\t\t? \"violated\"\n\t\t\t: \"inconclusive\";\n\treturn { result, observationIds: unique(children.flatMap(({ observationIds }) => observationIds)) };\n}\n\nfunction reasonCode(result: ClaimResult): ClaimEvaluation[\"reasonCode\"] {\n\tif (result === \"satisfied\") return \"claim.satisfied\";\n\tif (result === \"violated\") return \"claim.violated\";\n\treturn \"claim.observation_missing\";\n}\n\nfunction validateWaivers(input: EvaluationInput, waivers: readonly WaiverRecord[]): ReadonlyMap<string, WaiverRecord> {\n\tconst claims = new Map(input.taskSpec.claims.map((claim) => [claim.claimId, claim]));\n\tconst byClaim = new Map<string, WaiverRecord>();\n\tfor (const waiver of waivers) {\n\t\tparseWaiverRecord(waiver);\n\t\tif (waiver.scope.taskId !== input.taskSpec.taskId) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} targets task ${waiver.scope.taskId}`);\n\t\t}\n\t\tconst claim = claims.get(waiver.scope.claimId);\n\t\tif (!claim) throw new ProtocolInvariantError(`${waiver.waiverId} targets unknown claim ${waiver.scope.claimId}`);\n\t\tif (claim.requirement !== \"required\") {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} cannot waive advisory claim ${claim.claimId}`);\n\t\t}\n\t\tif (waiver.scope.attemptId !== undefined && waiver.scope.attemptId !== input.attempt.attemptId) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} targets attempt ${waiver.scope.attemptId}`);\n\t\t}\n\t\tif (waiver.approvedAt > input.evaluatedAt) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} was approved after evaluation`);\n\t\t}\n\t\tif (waiver.expiresAt !== undefined && waiver.expiresAt <= input.evaluatedAt) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} is expired`);\n\t\t}\n\t\tif (byClaim.has(claim.claimId))\n\t\t\tthrow new ProtocolInvariantError(`multiple waivers target claim ${claim.claimId}`);\n\t\tbyClaim.set(claim.claimId, waiver);\n\t}\n\treturn byClaim;\n}\n\nfunction reduceVerdict(claims: readonly ClaimEvaluation[]): SemanticVerdict {\n\tconst required = claims.filter((claim) => claim.requirement === \"required\" && claim.waiverId === undefined);\n\tif (required.length === 0) return claims.some((claim) => claim.requirement === \"required\") ? \"pass\" : \"inconclusive\";\n\tif (required.some((claim) => claim.result === \"violated\")) return \"fail\";\n\tif (required.some((claim) => claim.result === \"inconclusive\")) return \"inconclusive\";\n\treturn \"pass\";\n}\n\n/** Pure TaskSpec -> Observation -> Evaluation reduction. */\nexport function evaluateTask(input: EvaluationInput): EvaluationResult {\n\tparseTaskSpec(input.taskSpec);\n\tparseExecutionAttempt(input.attempt);\n\tif (input.attempt.taskId !== input.taskSpec.taskId) {\n\t\tthrow new ProtocolInvariantError(`${input.attempt.attemptId} targets task ${input.attempt.taskId}`);\n\t}\n\tfor (const observation of input.observations) {\n\t\tparseObservation(observation);\n\t\tif (observation.taskId !== input.taskSpec.taskId) {\n\t\t\tthrow new ProtocolInvariantError(`${observation.observationId} targets task ${observation.taskId}`);\n\t\t}\n\t}\n\tconst waivers = validateWaivers(input, input.waivers ?? []);\n\tconst claims = Object.freeze(\n\t\tinput.taskSpec.claims.map((claim): ClaimEvaluation => {\n\t\t\tconst evaluated = evaluateCondition(claim.condition, input.observations, input.attempt.attemptId);\n\t\t\tconst waiver = evaluated.result === \"satisfied\" ? undefined : waivers.get(claim.claimId);\n\t\t\treturn Object.freeze({\n\t\t\t\tclaimId: claim.claimId,\n\t\t\t\trequirement: claim.requirement,\n\t\t\t\tresult: evaluated.result,\n\t\t\t\treasonCode: reasonCode(evaluated.result),\n\t\t\t\tobservationIds: Object.freeze([...evaluated.observationIds]),\n\t\t\t\t...(waiver ? { waiverId: waiver.waiverId } : {}),\n\t\t\t});\n\t\t}),\n\t);\n\treturn parseEvaluationResult(\n\t\tObject.freeze({\n\t\t\tschemaVersion: PROTOCOL_VERSION,\n\t\t\tevaluationId: input.evaluationId,\n\t\t\ttaskId: input.taskSpec.taskId,\n\t\t\tattemptId: input.attempt.attemptId,\n\t\t\tevaluatedAt: input.evaluatedAt,\n\t\t\tclaims,\n\t\t\tsemanticVerdict: reduceVerdict(claims),\n\t\t}),\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"evaluation.js","sourceRoot":"","sources":["../src/evaluation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAQN,gBAAgB,GAGhB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,GACjB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAChD,YAAY,OAAe,EAAE;QAC5B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IAAA,CACrC;CACD;AAOD,SAAS,QAAQ,CAAC,KAAgB,EAAkD;IACnF,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAAA,CAC5E;AAED,SAAS,eAAe,CAAC,MAA6B,EAAE,QAAmB,EAAW;IACrF,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,OAAO,CACN,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YACrB,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM;YACjC,QAAQ,CAAC,KAAK,C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,UAAU;YAC7B,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,cAAc;QACjB,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1B,OAAO,qBAAqB,CAC3B,MAAM,CAAC,MAAM,CAAC;QACb,aAAa,EAAE,gBAAgB;QAC/B,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM;QAC7B,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS;QAClC,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,MAAM;QACN,eAAe;QACf,GAAG,CAAC,MAAM;YACT,CAAC,CAAC;gBACA,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC;oBAC7B,GAAG,MAAM;oBACT,UAAU,EACT,eAAe,KAAK,MAAM;wBACzB,CAAC,CAAE,QAAkB;wBACrB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC;4BACrD,CAAC,CAAE,sBAAgC;4BACnC,CAAC,CAAE,kBAA4B;iBAClC,CAAC;aACF;YACF,CAAC,CAAC,EAAE,CAAC;KACN,CAAC,CACF,CAAC;AAAA,CACF","sourcesContent":["import { evaluateStrictEvidence } from \"./strict-evidence.ts\";\nimport {\n\ttype ClaimCondition,\n\ttype ClaimEvaluation,\n\ttype ClaimResult,\n\ttype EvaluationInput,\n\ttype EvaluationResult,\n\ttype JsonValue,\n\ttype Observation,\n\tPROTOCOL_VERSION,\n\ttype SemanticVerdict,\n\ttype WaiverRecord,\n} from \"./types.ts\";\nimport {\n\tparseEvaluationResult,\n\tparseExecutionAttempt,\n\tparseObservation,\n\tparseTaskSpec,\n\tparseWaiverRecord,\n} from \"./validation.ts\";\n\nexport class ProtocolInvariantError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"ProtocolInvariantError\";\n\t}\n}\n\ninterface ConditionResult {\n\treadonly result: ClaimResult;\n\treadonly observationIds: readonly string[];\n}\n\nfunction isObject(value: JsonValue): value is { readonly [key: string]: JsonValue } {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction matchesExpected(actual: JsonValue | undefined, expected: JsonValue): boolean {\n\tif (Array.isArray(expected)) {\n\t\treturn (\n\t\t\tArray.isArray(actual) &&\n\t\t\tactual.length === expected.length &&\n\t\t\texpected.every((value, index) => matchesExpected(actual[index], value))\n\t\t);\n\t}\n\tif (isObject(expected)) {\n\t\treturn (\n\t\t\tactual !== undefined &&\n\t\t\tisObject(actual) &&\n\t\t\tObject.entries(expected).every(([key, value]) => matchesExpected(actual[key], value))\n\t\t);\n\t}\n\treturn Object.is(actual, expected);\n}\n\nfunction unique(values: readonly string[]): readonly string[] {\n\treturn [...new Set(values)];\n}\n\nfunction evaluateCondition(\n\tcondition: ClaimCondition,\n\tobservations: readonly Observation[],\n\tattemptId: string,\n\tcandidateHash?: string,\n): ConditionResult {\n\tif (condition.kind === \"observation\") {\n\t\tconst candidates = observations.filter((observation) => {\n\t\t\tif (observation.kind !== condition.observationKind) return false;\n\t\t\tif (condition.scope === \"attempt\" && observation.attemptId !== attemptId) return false;\n\t\t\t// Candidate binding: when the attempt declares a candidate hash, an\n\t\t\t// observation recorded for a different candidate cannot satisfy this\n\t\t\t// attempt's condition — a stale pass is not evidence for this build.\n\t\t\tif (candidateHash !== undefined) {\n\t\t\t\tconst observed = observation.facts.candidate;\n\t\t\t\tif (typeof observed === \"string\" && observed !== candidateHash) return false;\n\t\t\t}\n\t\t\t// Explicit per-condition binding additionally requires the\n\t\t\t// observation to name the same candidate outright.\n\t\t\tif (condition.bindToCandidate === true) {\n\t\t\t\tif (candidateHash === undefined || observation.facts.candidate !== candidateHash) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\t\tif (candidates.length === 0) return { result: \"inconclusive\", observationIds: [] };\n\t\tconst matching = candidates.filter((observation) => matchesExpected(observation.facts, condition.facts));\n\t\treturn matching.length > 0\n\t\t\t? { result: \"satisfied\", observationIds: matching.map(({ observationId }) => observationId) }\n\t\t\t: { result: \"violated\", observationIds: candidates.map(({ observationId }) => observationId) };\n\t}\n\n\tif (condition.kind === \"not\") {\n\t\tconst child = evaluateCondition(condition.condition, observations, attemptId, candidateHash);\n\t\treturn {\n\t\t\tresult: child.result === \"satisfied\" ? \"violated\" : child.result === \"violated\" ? \"satisfied\" : \"inconclusive\",\n\t\t\tobservationIds: child.observationIds,\n\t\t};\n\t}\n\n\tconst children = condition.conditions.map((child) =>\n\t\tevaluateCondition(child, observations, attemptId, candidateHash),\n\t);\n\tif (condition.kind === \"all\") {\n\t\tconst result = children.some((child) => child.result === \"violated\")\n\t\t\t? \"violated\"\n\t\t\t: children.some((child) => child.result === \"inconclusive\")\n\t\t\t\t? \"inconclusive\"\n\t\t\t\t: \"satisfied\";\n\t\treturn { result, observationIds: unique(children.flatMap(({ observationIds }) => observationIds)) };\n\t}\n\tconst result = children.some((child) => child.result === \"satisfied\")\n\t\t? \"satisfied\"\n\t\t: children.every((child) => child.result === \"violated\")\n\t\t\t? \"violated\"\n\t\t\t: \"inconclusive\";\n\treturn { result, observationIds: unique(children.flatMap(({ observationIds }) => observationIds)) };\n}\n\nfunction reasonCode(result: ClaimResult): ClaimEvaluation[\"reasonCode\"] {\n\tif (result === \"satisfied\") return \"claim.satisfied\";\n\tif (result === \"violated\") return \"claim.violated\";\n\treturn \"claim.observation_missing\";\n}\n\nfunction validateWaivers(input: EvaluationInput, waivers: readonly WaiverRecord[]): ReadonlyMap<string, WaiverRecord> {\n\tconst claims = new Map(input.taskSpec.claims.map((claim) => [claim.claimId, claim]));\n\tconst byClaim = new Map<string, WaiverRecord>();\n\tfor (const waiver of waivers) {\n\t\tparseWaiverRecord(waiver);\n\t\tif (waiver.scope.taskId !== input.taskSpec.taskId) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} targets task ${waiver.scope.taskId}`);\n\t\t}\n\t\tconst claim = claims.get(waiver.scope.claimId);\n\t\tif (!claim) throw new ProtocolInvariantError(`${waiver.waiverId} targets unknown claim ${waiver.scope.claimId}`);\n\t\tif (claim.requirement !== \"required\") {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} cannot waive advisory claim ${claim.claimId}`);\n\t\t}\n\t\tif (waiver.scope.attemptId !== undefined && waiver.scope.attemptId !== input.attempt.attemptId) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} targets attempt ${waiver.scope.attemptId}`);\n\t\t}\n\t\tif (waiver.approvedAt > input.evaluatedAt) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} was approved after evaluation`);\n\t\t}\n\t\tif (waiver.expiresAt !== undefined && waiver.expiresAt <= input.evaluatedAt) {\n\t\t\tthrow new ProtocolInvariantError(`${waiver.waiverId} is expired`);\n\t\t}\n\t\tif (byClaim.has(claim.claimId))\n\t\t\tthrow new ProtocolInvariantError(`multiple waivers target claim ${claim.claimId}`);\n\t\tbyClaim.set(claim.claimId, waiver);\n\t}\n\treturn byClaim;\n}\n\nfunction reduceVerdict(claims: readonly ClaimEvaluation[]): SemanticVerdict {\n\tconst required = claims.filter((claim) => claim.requirement === \"required\" && claim.waiverId === undefined);\n\tif (required.length === 0) return claims.some((claim) => claim.requirement === \"required\") ? \"pass\" : \"inconclusive\";\n\tif (required.some((claim) => claim.result === \"violated\")) return \"fail\";\n\tif (required.some((claim) => claim.result === \"inconclusive\")) return \"inconclusive\";\n\treturn \"pass\";\n}\n\n/** Pure TaskSpec -> Observation -> Evaluation reduction. */\nexport function evaluateTask(input: EvaluationInput): EvaluationResult {\n\tparseTaskSpec(input.taskSpec);\n\tparseExecutionAttempt(input.attempt);\n\tif (input.attempt.taskId !== input.taskSpec.taskId) {\n\t\tthrow new ProtocolInvariantError(`${input.attempt.attemptId} targets task ${input.attempt.taskId}`);\n\t}\n\tfor (const observation of input.observations) {\n\t\tparseObservation(observation);\n\t\tif (observation.taskId !== input.taskSpec.taskId) {\n\t\t\tthrow new ProtocolInvariantError(`${observation.observationId} targets task ${observation.taskId}`);\n\t\t}\n\t}\n\tconst waivers = validateWaivers(input, input.waivers ?? []);\n\tconst strict =\n\t\tinput.strictEvidence === undefined\n\t\t\t? undefined\n\t\t\t: evaluateStrictEvidence(input.strictEvidence, input.observations, input.attempt);\n\tconst observations =\n\t\tstrict === undefined\n\t\t\t? input.observations\n\t\t\t: input.observations.filter((observation) => strict.observationIds.includes(observation.observationId));\n\tconst claims = Object.freeze(\n\t\tinput.taskSpec.claims.map((claim): ClaimEvaluation => {\n\t\t\tconst evaluated = evaluateCondition(\n\t\t\t\tclaim.condition,\n\t\t\t\tobservations,\n\t\t\t\tinput.attempt.attemptId,\n\t\t\t\tinput.attempt.candidateHash,\n\t\t\t);\n\t\t\tconst waiver = evaluated.result === \"satisfied\" ? undefined : waivers.get(claim.claimId);\n\t\t\treturn Object.freeze({\n\t\t\t\tclaimId: claim.claimId,\n\t\t\t\trequirement: claim.requirement,\n\t\t\t\tresult: evaluated.result,\n\t\t\t\treasonCode: reasonCode(evaluated.result),\n\t\t\t\tobservationIds: Object.freeze([...evaluated.observationIds]),\n\t\t\t\t...(waiver ? { waiverId: waiver.waiverId } : {}),\n\t\t\t});\n\t\t}),\n\t);\n\tconst semanticVerdict =\n\t\tstrict && strict.status !== \"passed\"\n\t\t\t? strict.status === \"violated\"\n\t\t\t\t? \"fail\"\n\t\t\t\t: \"inconclusive\"\n\t\t\t: reduceVerdict(claims);\n\treturn parseEvaluationResult(\n\t\tObject.freeze({\n\t\t\tschemaVersion: PROTOCOL_VERSION,\n\t\t\tevaluationId: input.evaluationId,\n\t\t\ttaskId: input.taskSpec.taskId,\n\t\t\tattemptId: input.attempt.attemptId,\n\t\t\tevaluatedAt: input.evaluatedAt,\n\t\t\tclaims,\n\t\t\tsemanticVerdict,\n\t\t\t...(strict\n\t\t\t\t? {\n\t\t\t\t\t\tstrictEvidence: Object.freeze({\n\t\t\t\t\t\t\t...strict,\n\t\t\t\t\t\t\tacceptance:\n\t\t\t\t\t\t\t\tsemanticVerdict !== \"pass\"\n\t\t\t\t\t\t\t\t\t? (\"denied\" as const)\n\t\t\t\t\t\t\t\t\t: claims.some((claim) => claim.waiverId !== undefined)\n\t\t\t\t\t\t\t\t\t\t? (\"accepted_with_waiver\" as const)\n\t\t\t\t\t\t\t\t\t\t: (\"passed_by_checks\" as const),\n\t\t\t\t\t\t}),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t}),\n\t);\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export { MAX_RUN_DAG_TASKS, MAX_RUN_TASK_ATTEMPTS, orderRunDag, type RunDagTask,
|
|
|
9
9
|
export { MAX_VERIFIED_RUN_GENERATIONS, parseRunResumeCommand, type RunResumeCommand } from "./run-resume.ts";
|
|
10
10
|
export { parseRunTaskRetryCommand, type RunTaskRetryCommand } from "./run-task-retry.ts";
|
|
11
11
|
export { parseRunWriterRestartCommand, type RunWriterRestartCommand } from "./run-writer-restart.ts";
|
|
12
|
+
export type { StrictEvidenceBinding, StrictEvidenceCompletion, StrictEvidenceReport, StrictEvidenceSnapshot, } from "./strict-evidence-types.ts";
|
|
13
|
+
export { parseStrictEvidenceBinding, parseStrictEvidenceSnapshot } from "./strict-evidence-validation.ts";
|
|
12
14
|
export type { AllCondition, AnyCondition, AttemptExecutor, AttemptOutcome, AttemptTrigger, ClaimCondition, ClaimEvaluation, ClaimPredicate, ClaimReasonCode, ClaimResult, EvaluationInput, EvaluationResult, ExecutionAttempt, JsonObject, JsonPrimitive, JsonValue, NotCondition, Observation, ObservationCondition, ProtocolVersion, RequirementLevel, RuntimeAction, RuntimeDecision, RuntimeDecisionInput, RuntimeDecisionPolicy, RuntimeDecisionReason, SemanticVerdict, TaskSpec, WaiverRecord, } from "./types.ts";
|
|
13
15
|
export { PROTOCOL_VERSION } from "./types.ts";
|
|
14
16
|
export { ProtocolValidationError, parseEvaluationResult, parseExecutionAttempt, parseObservation, parseRuntimeDecision, parseTaskSpec, parseWaiverRecord, } from "./validation.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,iBAAiB,EACjB,2BAA2B,EAC3B,kBAAkB,GAClB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,kBAAkB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,KAAK,sBAAsB,EAC3B,0BAA0B,EAC1B,wBAAwB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,sBAAsB,EACtB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACN,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,wBAAwB,EACxB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,iBAAiB,EACjB,qBAAqB,EACrB,WAAW,EACX,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,eAAe,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7G,OAAO,EAAE,wBAAwB,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAE,4BAA4B,EAAE,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACrG,YAAY,EACX,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,SAAS,EACT,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,QAAQ,EACR,YAAY,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACN,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,GACjB,MAAM,iBAAiB,CAAC","sourcesContent":["export {\n\texplainBlockingCut,\n\tisBlockingVerdict,\n\tMAX_BLOCKING_CUT_CANDIDATES,\n\tminimalBlockingCut,\n} from \"./claims/claim-blocking-cut.ts\";\nexport { evaluateProofClosure } from \"./claims/claim-closure.ts\";\nexport {\n\tClaimGraphError,\n\tcanonicalClaimGraph,\n\trootClaimIds,\n\ttopologicalClaimOrder,\n\tvalidateClaimGraph,\n} from \"./claims/claim-graph.ts\";\nexport {\n\ttype BlockingCutExplanation,\n\tCLAIM_GRAPH_SCHEMA_VERSION,\n\tCLAIM_VERDICT_PRECEDENCE,\n\ttype ClaimClosureEvaluation,\n\ttype ClaimGraph,\n\ttype ClaimNode,\n\ttype ClaimNodeKind,\n\ttype ClaimRule,\n\ttype ClaimSeverity,\n\ttype ClaimVerdict,\n\tOBSERVATION_TRUST_RANK,\n\ttype ObservationNode,\n\ttype ObservationPolarity,\n\ttype ObservationSource,\n\ttype ProofClosureInput,\n\ttype ProofClosureResult,\n\ttype VerificationVerdict,\n\ttype WaiverNode,\n\ttype WitnessIndependencePolicy,\n\ttype WorkspaceCompleteness,\n} from \"./claims/claim-types.ts\";\nexport { reduceRuntimeDecision } from \"./decision.ts\";\nexport { evaluateTask, ProtocolInvariantError } from \"./evaluation.ts\";\nexport {\n\tparseRunContract,\n\tparseRunStartCommand,\n\ttype RunCheck,\n\ttype RunContract,\n\tRunContractError,\n\ttype RunPhaseBudget,\n\ttype RunScriptedWriter,\n\ttype RunStartCommand,\n\tVERIFIED_COMMAND_VERSION,\n\tVERIFIED_RUN_VERSION,\n} from \"./run-contract.ts\";\nexport {\n\tMAX_RUN_DAG_TASKS,\n\tMAX_RUN_TASK_ATTEMPTS,\n\torderRunDag,\n\ttype RunDagTask,\n\ttype RunDagWriter,\n\trunDagAncestors,\n} from \"./run-dag.ts\";\nexport { MAX_VERIFIED_RUN_GENERATIONS, parseRunResumeCommand, type RunResumeCommand } from \"./run-resume.ts\";\nexport { parseRunTaskRetryCommand, type RunTaskRetryCommand } from \"./run-task-retry.ts\";\nexport { parseRunWriterRestartCommand, type RunWriterRestartCommand } from \"./run-writer-restart.ts\";\nexport type {\n\tAllCondition,\n\tAnyCondition,\n\tAttemptExecutor,\n\tAttemptOutcome,\n\tAttemptTrigger,\n\tClaimCondition,\n\tClaimEvaluation,\n\tClaimPredicate,\n\tClaimReasonCode,\n\tClaimResult,\n\tEvaluationInput,\n\tEvaluationResult,\n\tExecutionAttempt,\n\tJsonObject,\n\tJsonPrimitive,\n\tJsonValue,\n\tNotCondition,\n\tObservation,\n\tObservationCondition,\n\tProtocolVersion,\n\tRequirementLevel,\n\tRuntimeAction,\n\tRuntimeDecision,\n\tRuntimeDecisionInput,\n\tRuntimeDecisionPolicy,\n\tRuntimeDecisionReason,\n\tSemanticVerdict,\n\tTaskSpec,\n\tWaiverRecord,\n} from \"./types.ts\";\nexport { PROTOCOL_VERSION } from \"./types.ts\";\nexport {\n\tProtocolValidationError,\n\tparseEvaluationResult,\n\tparseExecutionAttempt,\n\tparseObservation,\n\tparseRuntimeDecision,\n\tparseTaskSpec,\n\tparseWaiverRecord,\n} from \"./validation.ts\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,iBAAiB,EACjB,2BAA2B,EAC3B,kBAAkB,GAClB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,kBAAkB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,KAAK,sBAAsB,EAC3B,0BAA0B,EAC1B,wBAAwB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,sBAAsB,EACtB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACN,gBAAgB,EAChB,oBAAoB,EACpB,KAA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B,CAAC","sourcesContent":["export {\n\texplainBlockingCut,\n\tisBlockingVerdict,\n\tMAX_BLOCKING_CUT_CANDIDATES,\n\tminimalBlockingCut,\n} from \"./claims/claim-blocking-cut.ts\";\nexport { evaluateProofClosure } from \"./claims/claim-closure.ts\";\nexport {\n\tClaimGraphError,\n\tcanonicalClaimGraph,\n\trootClaimIds,\n\ttopologicalClaimOrder,\n\tvalidateClaimGraph,\n} from \"./claims/claim-graph.ts\";\nexport {\n\ttype BlockingCutExplanation,\n\tCLAIM_GRAPH_SCHEMA_VERSION,\n\tCLAIM_VERDICT_PRECEDENCE,\n\ttype ClaimClosureEvaluation,\n\ttype ClaimGraph,\n\ttype ClaimNode,\n\ttype ClaimNodeKind,\n\ttype ClaimRule,\n\ttype ClaimSeverity,\n\ttype ClaimVerdict,\n\tOBSERVATION_TRUST_RANK,\n\ttype ObservationNode,\n\ttype ObservationPolarity,\n\ttype ObservationSource,\n\ttype ProofClosureInput,\n\ttype ProofClosureResult,\n\ttype VerificationVerdict,\n\ttype WaiverNode,\n\ttype WitnessIndependencePolicy,\n\ttype WorkspaceCompleteness,\n} from \"./claims/claim-types.ts\";\nexport { reduceRuntimeDecision } from \"./decision.ts\";\nexport { evaluateTask, ProtocolInvariantError } from \"./evaluation.ts\";\nexport {\n\tparseRunContract,\n\tparseRunStartCommand,\n\ttype RunCheck,\n\ttype RunContract,\n\tRunContractError,\n\ttype RunPhaseBudget,\n\ttype RunScriptedWriter,\n\ttype RunStartCommand,\n\tVERIFIED_COMMAND_VERSION,\n\tVERIFIED_RUN_VERSION,\n} from \"./run-contract.ts\";\nexport {\n\tMAX_RUN_DAG_TASKS,\n\tMAX_RUN_TASK_ATTEMPTS,\n\torderRunDag,\n\ttype RunDagTask,\n\ttype RunDagWriter,\n\trunDagAncestors,\n} from \"./run-dag.ts\";\nexport { MAX_VERIFIED_RUN_GENERATIONS, parseRunResumeCommand, type RunResumeCommand } from \"./run-resume.ts\";\nexport { parseRunTaskRetryCommand, type RunTaskRetryCommand } from \"./run-task-retry.ts\";\nexport { parseRunWriterRestartCommand, type RunWriterRestartCommand } from \"./run-writer-restart.ts\";\nexport type {\n\tStrictEvidenceBinding,\n\tStrictEvidenceCompletion,\n\tStrictEvidenceReport,\n\tStrictEvidenceSnapshot,\n} from \"./strict-evidence-types.ts\";\nexport { parseStrictEvidenceBinding, parseStrictEvidenceSnapshot } from \"./strict-evidence-validation.ts\";\nexport type {\n\tAllCondition,\n\tAnyCondition,\n\tAttemptExecutor,\n\tAttemptOutcome,\n\tAttemptTrigger,\n\tClaimCondition,\n\tClaimEvaluation,\n\tClaimPredicate,\n\tClaimReasonCode,\n\tClaimResult,\n\tEvaluationInput,\n\tEvaluationResult,\n\tExecutionAttempt,\n\tJsonObject,\n\tJsonPrimitive,\n\tJsonValue,\n\tNotCondition,\n\tObservation,\n\tObservationCondition,\n\tProtocolVersion,\n\tRequirementLevel,\n\tRuntimeAction,\n\tRuntimeDecision,\n\tRuntimeDecisionInput,\n\tRuntimeDecisionPolicy,\n\tRuntimeDecisionReason,\n\tSemanticVerdict,\n\tTaskSpec,\n\tWaiverRecord,\n} from \"./types.ts\";\nexport { PROTOCOL_VERSION } from \"./types.ts\";\nexport {\n\tProtocolValidationError,\n\tparseEvaluationResult,\n\tparseExecutionAttempt,\n\tparseObservation,\n\tparseRuntimeDecision,\n\tparseTaskSpec,\n\tparseWaiverRecord,\n} from \"./validation.ts\";\n"]}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { MAX_RUN_DAG_TASKS, MAX_RUN_TASK_ATTEMPTS, orderRunDag, runDagAncestors,
|
|
|
9
9
|
export { MAX_VERIFIED_RUN_GENERATIONS, parseRunResumeCommand } from "./run-resume.js";
|
|
10
10
|
export { parseRunTaskRetryCommand } from "./run-task-retry.js";
|
|
11
11
|
export { parseRunWriterRestartCommand } from "./run-writer-restart.js";
|
|
12
|
+
export { parseStrictEvidenceBinding, parseStrictEvidenceSnapshot } from "./strict-evidence-validation.js";
|
|
12
13
|
export { PROTOCOL_VERSION } from "./types.js";
|
|
13
14
|
export { ProtocolValidationError, parseEvaluationResult, parseExecutionAttempt, parseObservation, parseRuntimeDecision, parseTaskSpec, parseWaiverRecord, } from "./validation.js";
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,iBAAiB,EACjB,2BAA2B,EAC3B,kBAAkB,GAClB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,kBAAkB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEN,0BAA0B,EAC1B,wBAAwB,EAQxB,sBAAsB,GAUtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACN,gBAAgB,EAChB,oBAAoB,EAGpB,gBAAgB,EAIhB,wBAAwB,EACxB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,iBAAiB,EACjB,qBAAqB,EACrB,WAAW,EAGX,eAAe,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,4BAA4B,EAAE,qBAAqB,EAAyB,MAAM,iBAAiB,CAAC;AAC7G,OAAO,EAAE,wBAAwB,EAA4B,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAE,4BAA4B,EAAgC,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,iBAAiB,EACjB,2BAA2B,EAC3B,kBAAkB,GAClB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,kBAAkB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEN,0BAA0B,EAC1B,wBAAwB,EAQxB,sBAAsB,GAUtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACN,gBAAgB,EAChB,oBAAoB,EAGpB,gBAAgB,EAIhB,wBAAwB,EACxB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,iBAAiB,EACjB,qBAAqB,EACrB,WAAW,EAGX,eAAe,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,4BAA4B,EAAE,qBAAqB,EAAyB,MAAM,iBAAiB,CAAC;AAC7G,OAAO,EAAE,wBAAwB,EAA4B,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAE,4BAA4B,EAAgC,MAAM,yBAAyB,CAAC;AAOrG,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAgC1G,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACN,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,GACjB,MAAM,iBAAiB,CAAC","sourcesContent":["export {\n\texplainBlockingCut,\n\tisBlockingVerdict,\n\tMAX_BLOCKING_CUT_CANDIDATES,\n\tminimalBlockingCut,\n} from \"./claims/claim-blocking-cut.ts\";\nexport { evaluateProofClosure } from \"./claims/claim-closure.ts\";\nexport {\n\tClaimGraphError,\n\tcanonicalClaimGraph,\n\trootClaimIds,\n\ttopologicalClaimOrder,\n\tvalidateClaimGraph,\n} from \"./claims/claim-graph.ts\";\nexport {\n\ttype BlockingCutExplanation,\n\tCLAIM_GRAPH_SCHEMA_VERSION,\n\tCLAIM_VERDICT_PRECEDENCE,\n\ttype ClaimClosureEvaluation,\n\ttype ClaimGraph,\n\ttype ClaimNode,\n\ttype ClaimNodeKind,\n\ttype ClaimRule,\n\ttype ClaimSeverity,\n\ttype ClaimVerdict,\n\tOBSERVATION_TRUST_RANK,\n\ttype ObservationNode,\n\ttype ObservationPolarity,\n\ttype ObservationSource,\n\ttype ProofClosureInput,\n\ttype ProofClosureResult,\n\ttype VerificationVerdict,\n\ttype WaiverNode,\n\ttype WitnessIndependencePolicy,\n\ttype WorkspaceCompleteness,\n} from \"./claims/claim-types.ts\";\nexport { reduceRuntimeDecision } from \"./decision.ts\";\nexport { evaluateTask, ProtocolInvariantError } from \"./evaluation.ts\";\nexport {\n\tparseRunContract,\n\tparseRunStartCommand,\n\ttype RunCheck,\n\ttype RunContract,\n\tRunContractError,\n\ttype RunPhaseBudget,\n\ttype RunScriptedWriter,\n\ttype RunStartCommand,\n\tVERIFIED_COMMAND_VERSION,\n\tVERIFIED_RUN_VERSION,\n} from \"./run-contract.ts\";\nexport {\n\tMAX_RUN_DAG_TASKS,\n\tMAX_RUN_TASK_ATTEMPTS,\n\torderRunDag,\n\ttype RunDagTask,\n\ttype RunDagWriter,\n\trunDagAncestors,\n} from \"./run-dag.ts\";\nexport { MAX_VERIFIED_RUN_GENERATIONS, parseRunResumeCommand, type RunResumeCommand } from \"./run-resume.ts\";\nexport { parseRunTaskRetryCommand, type RunTaskRetryCommand } from \"./run-task-retry.ts\";\nexport { parseRunWriterRestartCommand, type RunWriterRestartCommand } from \"./run-writer-restart.ts\";\nexport type {\n\tStrictEvidenceBinding,\n\tStrictEvidenceCompletion,\n\tStrictEvidenceReport,\n\tStrictEvidenceSnapshot,\n} from \"./strict-evidence-types.ts\";\nexport { parseStrictEvidenceBinding, parseStrictEvidenceSnapshot } from \"./strict-evidence-validation.ts\";\nexport type {\n\tAllCondition,\n\tAnyCondition,\n\tAttemptExecutor,\n\tAttemptOutcome,\n\tAttemptTrigger,\n\tClaimCondition,\n\tClaimEvaluation,\n\tClaimPredicate,\n\tClaimReasonCode,\n\tClaimResult,\n\tEvaluationInput,\n\tEvaluationResult,\n\tExecutionAttempt,\n\tJsonObject,\n\tJsonPrimitive,\n\tJsonValue,\n\tNotCondition,\n\tObservation,\n\tObservationCondition,\n\tProtocolVersion,\n\tRequirementLevel,\n\tRuntimeAction,\n\tRuntimeDecision,\n\tRuntimeDecisionInput,\n\tRuntimeDecisionPolicy,\n\tRuntimeDecisionReason,\n\tSemanticVerdict,\n\tTaskSpec,\n\tWaiverRecord,\n} from \"./types.ts\";\nexport { PROTOCOL_VERSION } from \"./types.ts\";\nexport {\n\tProtocolValidationError,\n\tparseEvaluationResult,\n\tparseExecutionAttempt,\n\tparseObservation,\n\tparseRuntimeDecision,\n\tparseTaskSpec,\n\tparseWaiverRecord,\n} from \"./validation.ts\";\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Explicit host-admitted snapshot; none of these serializable fields authenticate a worker. */
|
|
2
|
+
export interface StrictEvidenceBinding {
|
|
3
|
+
readonly taskId: string;
|
|
4
|
+
readonly candidateHash: string;
|
|
5
|
+
readonly contractDigest: string;
|
|
6
|
+
readonly environmentDigest: string;
|
|
7
|
+
readonly checkCodeDigest: string;
|
|
8
|
+
readonly dependencyDigest: string;
|
|
9
|
+
readonly generation: number;
|
|
10
|
+
readonly verificationRound: number;
|
|
11
|
+
}
|
|
12
|
+
export interface StrictEvidenceCompletion {
|
|
13
|
+
readonly observationId: string;
|
|
14
|
+
readonly checkId: string;
|
|
15
|
+
readonly binding: StrictEvidenceBinding;
|
|
16
|
+
/** Sequence allocated by the accepting host, never worker wall time. */
|
|
17
|
+
readonly sequence: number;
|
|
18
|
+
readonly executionId: string;
|
|
19
|
+
readonly previousExecutionId: string | null;
|
|
20
|
+
readonly verdict: "passed" | "failed";
|
|
21
|
+
}
|
|
22
|
+
export interface StrictEvidenceSnapshot {
|
|
23
|
+
readonly policy: "omk.strict-evidence.v1";
|
|
24
|
+
readonly binding: StrictEvidenceBinding;
|
|
25
|
+
readonly requiredCheckIds: readonly string[];
|
|
26
|
+
/** Includes open producers and unknown/unsettled executions, even after a completed pass. */
|
|
27
|
+
readonly pendingExecutionIds: readonly string[];
|
|
28
|
+
readonly results: readonly StrictEvidenceCompletion[];
|
|
29
|
+
}
|
|
30
|
+
export interface StrictEvidenceReport {
|
|
31
|
+
readonly policy: "omk.strict-evidence.v1";
|
|
32
|
+
readonly status: "passed" | "violated" | "pending" | "inconclusive";
|
|
33
|
+
readonly observationIds: readonly string[];
|
|
34
|
+
readonly missingCheckIds: readonly string[];
|
|
35
|
+
readonly acceptance: "passed_by_checks" | "accepted_with_waiver" | "denied";
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=strict-evidence-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-evidence-types.d.ts","sourceRoot":"","sources":["../src/strict-evidence-types.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IACxC,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAAC;CACtC;AAED,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IACxC,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7C,6FAA6F;IAC7F,QAAQ,CAAC,mBAAmB,EAAE,SAAS,MAAM,EAAE,CAAC;IAChD,QAAQ,CAAC,OAAO,EAAE,SAAS,wBAAwB,EAAE,CAAC;CACtD;AAED,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,cAAc,CAAC;IACpE,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,UAAU,EAAE,kBAAkB,GAAG,sBAAsB,GAAG,QAAQ,CAAC;CAC5E","sourcesContent":["/** Explicit host-admitted snapshot; none of these serializable fields authenticate a worker. */\nexport interface StrictEvidenceBinding {\n\treadonly taskId: string;\n\treadonly candidateHash: string;\n\treadonly contractDigest: string;\n\treadonly environmentDigest: string;\n\treadonly checkCodeDigest: string;\n\treadonly dependencyDigest: string;\n\treadonly generation: number;\n\treadonly verificationRound: number;\n}\n\nexport interface StrictEvidenceCompletion {\n\treadonly observationId: string;\n\treadonly checkId: string;\n\treadonly binding: StrictEvidenceBinding;\n\t/** Sequence allocated by the accepting host, never worker wall time. */\n\treadonly sequence: number;\n\treadonly executionId: string;\n\treadonly previousExecutionId: string | null;\n\treadonly verdict: \"passed\" | \"failed\";\n}\n\nexport interface StrictEvidenceSnapshot {\n\treadonly policy: \"omk.strict-evidence.v1\";\n\treadonly binding: StrictEvidenceBinding;\n\treadonly requiredCheckIds: readonly string[];\n\t/** Includes open producers and unknown/unsettled executions, even after a completed pass. */\n\treadonly pendingExecutionIds: readonly string[];\n\treadonly results: readonly StrictEvidenceCompletion[];\n}\n\nexport interface StrictEvidenceReport {\n\treadonly policy: \"omk.strict-evidence.v1\";\n\treadonly status: \"passed\" | \"violated\" | \"pending\" | \"inconclusive\";\n\treadonly observationIds: readonly string[];\n\treadonly missingCheckIds: readonly string[];\n\treadonly acceptance: \"passed_by_checks\" | \"accepted_with_waiver\" | \"denied\";\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-evidence-types.js","sourceRoot":"","sources":["../src/strict-evidence-types.ts"],"names":[],"mappings":"","sourcesContent":["/** Explicit host-admitted snapshot; none of these serializable fields authenticate a worker. */\nexport interface StrictEvidenceBinding {\n\treadonly taskId: string;\n\treadonly candidateHash: string;\n\treadonly contractDigest: string;\n\treadonly environmentDigest: string;\n\treadonly checkCodeDigest: string;\n\treadonly dependencyDigest: string;\n\treadonly generation: number;\n\treadonly verificationRound: number;\n}\n\nexport interface StrictEvidenceCompletion {\n\treadonly observationId: string;\n\treadonly checkId: string;\n\treadonly binding: StrictEvidenceBinding;\n\t/** Sequence allocated by the accepting host, never worker wall time. */\n\treadonly sequence: number;\n\treadonly executionId: string;\n\treadonly previousExecutionId: string | null;\n\treadonly verdict: \"passed\" | \"failed\";\n}\n\nexport interface StrictEvidenceSnapshot {\n\treadonly policy: \"omk.strict-evidence.v1\";\n\treadonly binding: StrictEvidenceBinding;\n\treadonly requiredCheckIds: readonly string[];\n\t/** Includes open producers and unknown/unsettled executions, even after a completed pass. */\n\treadonly pendingExecutionIds: readonly string[];\n\treadonly results: readonly StrictEvidenceCompletion[];\n}\n\nexport interface StrictEvidenceReport {\n\treadonly policy: \"omk.strict-evidence.v1\";\n\treadonly status: \"passed\" | \"violated\" | \"pending\" | \"inconclusive\";\n\treadonly observationIds: readonly string[];\n\treadonly missingCheckIds: readonly string[];\n\treadonly acceptance: \"passed_by_checks\" | \"accepted_with_waiver\" | \"denied\";\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { StrictEvidenceBinding, StrictEvidenceSnapshot } from "./strict-evidence-types.ts";
|
|
2
|
+
export declare function parseStrictEvidenceBinding(value: unknown): StrictEvidenceBinding;
|
|
3
|
+
export declare function parseStrictEvidenceSnapshot(value: unknown): StrictEvidenceSnapshot;
|
|
4
|
+
//# sourceMappingURL=strict-evidence-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-evidence-validation.d.ts","sourceRoot":"","sources":["../src/strict-evidence-validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,qBAAqB,EAErB,sBAAsB,EACtB,MAAM,4BAA4B,CAAC;AAEpC,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,qBAAqB,CAqBhF;AAyBD,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,sBAAsB,CAqBlF","sourcesContent":["import { runArray, runDigest, runLimit, runObject, runText } from \"./run-parsing.ts\";\nimport type {\n\tStrictEvidenceBinding,\n\tStrictEvidenceCompletion,\n\tStrictEvidenceSnapshot,\n} from \"./strict-evidence-types.ts\";\n\nexport function parseStrictEvidenceBinding(value: unknown): StrictEvidenceBinding {\n\tconst raw = runObject(value, [\n\t\t\"taskId\",\n\t\t\"candidateHash\",\n\t\t\"contractDigest\",\n\t\t\"environmentDigest\",\n\t\t\"checkCodeDigest\",\n\t\t\"dependencyDigest\",\n\t\t\"generation\",\n\t\t\"verificationRound\",\n\t]);\n\treturn Object.freeze({\n\t\ttaskId: runText(raw.taskId, \"taskId\"),\n\t\tcandidateHash: runText(raw.candidateHash, \"candidateHash\"),\n\t\tcontractDigest: runDigest(raw.contractDigest),\n\t\tenvironmentDigest: runDigest(raw.environmentDigest),\n\t\tcheckCodeDigest: runDigest(raw.checkCodeDigest),\n\t\tdependencyDigest: runDigest(raw.dependencyDigest),\n\t\tgeneration: runLimit(raw.generation, \"generation\"),\n\t\tverificationRound: runLimit(raw.verificationRound, \"verificationRound\"),\n\t});\n}\n\nfunction completion(value: unknown): StrictEvidenceCompletion {\n\tconst raw = runObject(value, [\n\t\t\"observationId\",\n\t\t\"checkId\",\n\t\t\"binding\",\n\t\t\"sequence\",\n\t\t\"executionId\",\n\t\t\"previousExecutionId\",\n\t\t\"verdict\",\n\t]);\n\tif (raw.verdict !== \"passed\" && raw.verdict !== \"failed\") throw new Error(\"Invalid strict evidence verdict\");\n\treturn Object.freeze({\n\t\tobservationId: runText(raw.observationId, \"observationId\"),\n\t\tcheckId: runText(raw.checkId, \"checkId\"),\n\t\tbinding: parseStrictEvidenceBinding(raw.binding),\n\t\tsequence: runLimit(raw.sequence, \"sequence\", Number.MAX_SAFE_INTEGER),\n\t\texecutionId: runText(raw.executionId, \"executionId\"),\n\t\tpreviousExecutionId:\n\t\t\traw.previousExecutionId === null ? null : runText(raw.previousExecutionId, \"previousExecutionId\"),\n\t\tverdict: raw.verdict,\n\t});\n}\n\nexport function parseStrictEvidenceSnapshot(value: unknown): StrictEvidenceSnapshot {\n\tconst raw = runObject(value, [\"policy\", \"binding\", \"requiredCheckIds\", \"pendingExecutionIds\", \"results\"]);\n\tif (raw.policy !== \"omk.strict-evidence.v1\") throw new Error(\"Unsupported strict evidence policy\");\n\tconst requiredCheckIds = runArray(raw.requiredCheckIds, (v) => runText(v, \"checkId\"), 1024);\n\tif (new Set(requiredCheckIds).size !== requiredCheckIds.length) throw new Error(\"Duplicate required check ID\");\n\t// runArray deliberately forbids empty arrays; these two collections may be empty.\n\tconst pendingExecutionIds =\n\t\tArray.isArray(raw.pendingExecutionIds) && raw.pendingExecutionIds.length === 0\n\t\t\t? Object.freeze([])\n\t\t\t: runArray(raw.pendingExecutionIds, (v) => runText(v, \"pendingExecutionId\"), 10000);\n\tconst results =\n\t\tArray.isArray(raw.results) && raw.results.length === 0\n\t\t\t? Object.freeze([])\n\t\t\t: runArray(raw.results, completion, 10000);\n\treturn Object.freeze({\n\t\tpolicy: raw.policy,\n\t\tbinding: parseStrictEvidenceBinding(raw.binding),\n\t\trequiredCheckIds,\n\t\tpendingExecutionIds,\n\t\tresults,\n\t});\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { runArray, runDigest, runLimit, runObject, runText } from "./run-parsing.js";
|
|
2
|
+
export function parseStrictEvidenceBinding(value) {
|
|
3
|
+
const raw = runObject(value, [
|
|
4
|
+
"taskId",
|
|
5
|
+
"candidateHash",
|
|
6
|
+
"contractDigest",
|
|
7
|
+
"environmentDigest",
|
|
8
|
+
"checkCodeDigest",
|
|
9
|
+
"dependencyDigest",
|
|
10
|
+
"generation",
|
|
11
|
+
"verificationRound",
|
|
12
|
+
]);
|
|
13
|
+
return Object.freeze({
|
|
14
|
+
taskId: runText(raw.taskId, "taskId"),
|
|
15
|
+
candidateHash: runText(raw.candidateHash, "candidateHash"),
|
|
16
|
+
contractDigest: runDigest(raw.contractDigest),
|
|
17
|
+
environmentDigest: runDigest(raw.environmentDigest),
|
|
18
|
+
checkCodeDigest: runDigest(raw.checkCodeDigest),
|
|
19
|
+
dependencyDigest: runDigest(raw.dependencyDigest),
|
|
20
|
+
generation: runLimit(raw.generation, "generation"),
|
|
21
|
+
verificationRound: runLimit(raw.verificationRound, "verificationRound"),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function completion(value) {
|
|
25
|
+
const raw = runObject(value, [
|
|
26
|
+
"observationId",
|
|
27
|
+
"checkId",
|
|
28
|
+
"binding",
|
|
29
|
+
"sequence",
|
|
30
|
+
"executionId",
|
|
31
|
+
"previousExecutionId",
|
|
32
|
+
"verdict",
|
|
33
|
+
]);
|
|
34
|
+
if (raw.verdict !== "passed" && raw.verdict !== "failed")
|
|
35
|
+
throw new Error("Invalid strict evidence verdict");
|
|
36
|
+
return Object.freeze({
|
|
37
|
+
observationId: runText(raw.observationId, "observationId"),
|
|
38
|
+
checkId: runText(raw.checkId, "checkId"),
|
|
39
|
+
binding: parseStrictEvidenceBinding(raw.binding),
|
|
40
|
+
sequence: runLimit(raw.sequence, "sequence", Number.MAX_SAFE_INTEGER),
|
|
41
|
+
executionId: runText(raw.executionId, "executionId"),
|
|
42
|
+
previousExecutionId: raw.previousExecutionId === null ? null : runText(raw.previousExecutionId, "previousExecutionId"),
|
|
43
|
+
verdict: raw.verdict,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export function parseStrictEvidenceSnapshot(value) {
|
|
47
|
+
const raw = runObject(value, ["policy", "binding", "requiredCheckIds", "pendingExecutionIds", "results"]);
|
|
48
|
+
if (raw.policy !== "omk.strict-evidence.v1")
|
|
49
|
+
throw new Error("Unsupported strict evidence policy");
|
|
50
|
+
const requiredCheckIds = runArray(raw.requiredCheckIds, (v) => runText(v, "checkId"), 1024);
|
|
51
|
+
if (new Set(requiredCheckIds).size !== requiredCheckIds.length)
|
|
52
|
+
throw new Error("Duplicate required check ID");
|
|
53
|
+
// runArray deliberately forbids empty arrays; these two collections may be empty.
|
|
54
|
+
const pendingExecutionIds = Array.isArray(raw.pendingExecutionIds) && raw.pendingExecutionIds.length === 0
|
|
55
|
+
? Object.freeze([])
|
|
56
|
+
: runArray(raw.pendingExecutionIds, (v) => runText(v, "pendingExecutionId"), 10000);
|
|
57
|
+
const results = Array.isArray(raw.results) && raw.results.length === 0
|
|
58
|
+
? Object.freeze([])
|
|
59
|
+
: runArray(raw.results, completion, 10000);
|
|
60
|
+
return Object.freeze({
|
|
61
|
+
policy: raw.policy,
|
|
62
|
+
binding: parseStrictEvidenceBinding(raw.binding),
|
|
63
|
+
requiredCheckIds,
|
|
64
|
+
pendingExecutionIds,
|
|
65
|
+
results,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=strict-evidence-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-evidence-validation.js","sourceRoot":"","sources":["../src/strict-evidence-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOrF,MAAM,UAAU,0BAA0B,CAAC,KAAc,EAAyB;IACjF,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,EAAE;QAC5B,QAAQ;QACR,eAAe;QACf,gBAAgB;QAChB,mBAAmB;QACnB,iBAAiB;QACjB,kBAAkB;QAClB,YAAY;QACZ,mBAAmB;KACnB,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;QACrC,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,eAAe,CAAC;QAC1D,cAAc,EAAE,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC;QAC7C,iBAAiB,EAAE,SAAS,CAAC,GAAG,CAAC,iBAAiB,CAAC;QACnD,eAAe,EAAE,SAAS,CAAC,GAAG,CAAC,eAAe,CAAC;QAC/C,gBAAgB,EAAE,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC;QACjD,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC;QAClD,iBAAiB,EAAE,QAAQ,CAAC,GAAG,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;KACvE,CAAC,CAAC;AAAA,CACH;AAED,SAAS,UAAU,CAAC,KAAc,EAA4B;IAC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E,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC;IAC5F,IAAI,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC,IAAI,KAAK,gBAAgB,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAC/G,kFAAkF;IAClF,MAAM,mBAAmB,GACxB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,GAAG,CAAC,mBAAmB,CAAC,MAAM,KAAK,CAAC;QAC7E,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QACnB,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,oBAAoB,CAAC,EAAE,KAAK,CAAC,CAAC;IACtF,MAAM,OAAO,GACZ,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;QACrD,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QACnB,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,OAAO,EAAE,0BAA0B,CAAC,GAAG,CAAC,OAAO,CAAC;QAChD,gBAAgB;QAChB,mBAAmB;QACnB,OAAO;KACP,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { runArray, runDigest, runLimit, runObject, runText } from \"./run-parsing.ts\";\nimport type {\n\tStrictEvidenceBinding,\n\tStrictEvidenceCompletion,\n\tStrictEvidenceSnapshot,\n} from \"./strict-evidence-types.ts\";\n\nexport function parseStrictEvidenceBinding(value: unknown): StrictEvidenceBinding {\n\tconst raw = runObject(value, [\n\t\t\"taskId\",\n\t\t\"candidateHash\",\n\t\t\"contractDigest\",\n\t\t\"environmentDigest\",\n\t\t\"checkCodeDigest\",\n\t\t\"dependencyDigest\",\n\t\t\"generation\",\n\t\t\"verificationRound\",\n\t]);\n\treturn Object.freeze({\n\t\ttaskId: runText(raw.taskId, \"taskId\"),\n\t\tcandidateHash: runText(raw.candidateHash, \"candidateHash\"),\n\t\tcontractDigest: runDigest(raw.contractDigest),\n\t\tenvironmentDigest: runDigest(raw.environmentDigest),\n\t\tcheckCodeDigest: runDigest(raw.checkCodeDigest),\n\t\tdependencyDigest: runDigest(raw.dependencyDigest),\n\t\tgeneration: runLimit(raw.generation, \"generation\"),\n\t\tverificationRound: runLimit(raw.verificationRound, \"verificationRound\"),\n\t});\n}\n\nfunction completion(value: unknown): StrictEvidenceCompletion {\n\tconst raw = runObject(value, [\n\t\t\"observationId\",\n\t\t\"checkId\",\n\t\t\"binding\",\n\t\t\"sequence\",\n\t\t\"executionId\",\n\t\t\"previousExecutionId\",\n\t\t\"verdict\",\n\t]);\n\tif (raw.verdict !== \"passed\" && raw.verdict !== \"failed\") throw new Error(\"Invalid strict evidence verdict\");\n\treturn Object.freeze({\n\t\tobservationId: runText(raw.observationId, \"observationId\"),\n\t\tcheckId: runText(raw.checkId, \"checkId\"),\n\t\tbinding: parseStrictEvidenceBinding(raw.binding),\n\t\tsequence: runLimit(raw.sequence, \"sequence\", Number.MAX_SAFE_INTEGER),\n\t\texecutionId: runText(raw.executionId, \"executionId\"),\n\t\tpreviousExecutionId:\n\t\t\traw.previousExecutionId === null ? null : runText(raw.previousExecutionId, \"previousExecutionId\"),\n\t\tverdict: raw.verdict,\n\t});\n}\n\nexport function parseStrictEvidenceSnapshot(value: unknown): StrictEvidenceSnapshot {\n\tconst raw = runObject(value, [\"policy\", \"binding\", \"requiredCheckIds\", \"pendingExecutionIds\", \"results\"]);\n\tif (raw.policy !== \"omk.strict-evidence.v1\") throw new Error(\"Unsupported strict evidence policy\");\n\tconst requiredCheckIds = runArray(raw.requiredCheckIds, (v) => runText(v, \"checkId\"), 1024);\n\tif (new Set(requiredCheckIds).size !== requiredCheckIds.length) throw new Error(\"Duplicate required check ID\");\n\t// runArray deliberately forbids empty arrays; these two collections may be empty.\n\tconst pendingExecutionIds =\n\t\tArray.isArray(raw.pendingExecutionIds) && raw.pendingExecutionIds.length === 0\n\t\t\t? Object.freeze([])\n\t\t\t: runArray(raw.pendingExecutionIds, (v) => runText(v, \"pendingExecutionId\"), 10000);\n\tconst results =\n\t\tArray.isArray(raw.results) && raw.results.length === 0\n\t\t\t? Object.freeze([])\n\t\t\t: runArray(raw.results, completion, 10000);\n\treturn Object.freeze({\n\t\tpolicy: raw.policy,\n\t\tbinding: parseStrictEvidenceBinding(raw.binding),\n\t\trequiredCheckIds,\n\t\tpendingExecutionIds,\n\t\tresults,\n\t});\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { StrictEvidenceReport, StrictEvidenceSnapshot } from "./strict-evidence-types.ts";
|
|
2
|
+
import type { ExecutionAttempt, Observation } from "./types.ts";
|
|
3
|
+
/** Structural/integrity reduction only. The caller owns admission and snapshot completeness. */
|
|
4
|
+
export declare function evaluateStrictEvidence(value: StrictEvidenceSnapshot, observations: readonly Observation[], attempt: ExecutionAttempt): Omit<StrictEvidenceReport, "acceptance">;
|
|
5
|
+
//# sourceMappingURL=strict-evidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-evidence.d.ts","sourceRoot":"","sources":["../src/strict-evidence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAE/F,OAAO,KAAK,EAAE,gBAAgB,EAAa,WAAW,EAAE,MAAM,YAAY,CAAC;AAa3E,gGAAgG;AAChG,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,sBAAsB,EAC7B,YAAY,EAAE,SAAS,WAAW,EAAE,EACpC,OAAO,EAAE,gBAAgB,GACvB,IAAI,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAmE1C","sourcesContent":["import type { StrictEvidenceReport, StrictEvidenceSnapshot } from \"./strict-evidence-types.ts\";\nimport { parseStrictEvidenceSnapshot } from \"./strict-evidence-validation.ts\";\nimport type { ExecutionAttempt, JsonValue, Observation } from \"./types.ts\";\n\nfunction canonical(value: JsonValue): string {\n\tif (Array.isArray(value)) return `[${value.map(canonical).join(\",\")}]`;\n\tif (value !== null && typeof value === \"object\") {\n\t\treturn `{${Object.keys(value)\n\t\t\t.sort()\n\t\t\t.map((key) => `${JSON.stringify(key)}:${canonical((value as { readonly [key: string]: JsonValue })[key])}`)\n\t\t\t.join(\",\")}}`;\n\t}\n\treturn JSON.stringify(value);\n}\n\n/** Structural/integrity reduction only. The caller owns admission and snapshot completeness. */\nexport function evaluateStrictEvidence(\n\tvalue: StrictEvidenceSnapshot,\n\tobservations: readonly Observation[],\n\tattempt: ExecutionAttempt,\n): Omit<StrictEvidenceReport, \"acceptance\"> {\n\tconst snapshot = parseStrictEvidenceSnapshot(value);\n\tconst bindingKey = JSON.stringify(snapshot.binding);\n\tif (snapshot.binding.taskId !== attempt.taskId || snapshot.binding.candidateHash !== attempt.candidateHash) {\n\t\tthrow new Error(\"Strict evidence binding does not match attempt\");\n\t}\n\tconst byId = new Map<string, Observation>();\n\tfor (const observation of observations) {\n\t\tconst old = byId.get(observation.observationId);\n\t\tif (old && canonical(old as unknown as JsonValue) !== canonical(observation as unknown as JsonValue)) {\n\t\t\tthrow new Error(\"Conflicting observation identity\");\n\t\t}\n\t\tbyId.set(observation.observationId, observation);\n\t}\n\tconst identities = new Map<string, string>();\n\tconst unique = new Map<string, (typeof snapshot.results)[number]>();\n\tfor (const result of snapshot.results) {\n\t\tconst payload = JSON.stringify(result);\n\t\tfor (const key of [\n\t\t\t`observation:${result.observationId}`,\n\t\t\t`execution:${result.executionId}`,\n\t\t\t`sequence:${result.sequence}`,\n\t\t]) {\n\t\t\tconst old = identities.get(key);\n\t\t\tif (old !== undefined && old !== payload) throw new Error(\"Conflicting strict evidence identity or sequence\");\n\t\t\tidentities.set(key, payload);\n\t\t}\n\t\tconst observation = byId.get(result.observationId);\n\t\tif (!observation) throw new Error(\"Strict completion references missing observation\");\n\t\tconst candidate = observation.facts.candidate;\n\t\tif (typeof candidate === \"string\" && candidate !== result.binding.candidateHash) {\n\t\t\tthrow new Error(\"Strict evidence binding disagrees with observation candidate\");\n\t\t}\n\t\tunique.set(result.observationId, result);\n\t}\n\tconst selected: string[] = [];\n\tconst missing: string[] = [];\n\tlet failed = false;\n\tfor (const checkId of [...snapshot.requiredCheckIds].sort()) {\n\t\tconst history = [...unique.values()]\n\t\t\t.filter((r) => r.checkId === checkId && JSON.stringify(r.binding) === bindingKey)\n\t\t\t.sort((a, b) => a.sequence - b.sequence);\n\t\tfor (const [index, result] of history.entries()) {\n\t\t\tif (result.previousExecutionId !== (index === 0 ? null : history[index - 1].executionId)) {\n\t\t\t\tthrow new Error(\"Broken strict evidence attempt chain\");\n\t\t\t}\n\t\t}\n\t\tconst latest = history.at(-1);\n\t\tif (!latest) missing.push(checkId);\n\t\telse {\n\t\t\tselected.push(latest.observationId);\n\t\t\tfailed ||= latest.verdict === \"failed\";\n\t\t}\n\t}\n\treturn Object.freeze({\n\t\tpolicy: snapshot.policy,\n\t\tstatus:\n\t\t\tsnapshot.pendingExecutionIds.length > 0\n\t\t\t\t? \"pending\"\n\t\t\t\t: failed\n\t\t\t\t\t? \"violated\"\n\t\t\t\t\t: missing.length > 0\n\t\t\t\t\t\t? \"inconclusive\"\n\t\t\t\t\t\t: \"passed\",\n\t\tobservationIds: Object.freeze(selected.sort()),\n\t\tmissingCheckIds: Object.freeze(missing),\n\t});\n}\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { parseStrictEvidenceSnapshot } from "./strict-evidence-validation.js";
|
|
2
|
+
function canonical(value) {
|
|
3
|
+
if (Array.isArray(value))
|
|
4
|
+
return `[${value.map(canonical).join(",")}]`;
|
|
5
|
+
if (value !== null && typeof value === "object") {
|
|
6
|
+
return `{${Object.keys(value)
|
|
7
|
+
.sort()
|
|
8
|
+
.map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`)
|
|
9
|
+
.join(",")}}`;
|
|
10
|
+
}
|
|
11
|
+
return JSON.stringify(value);
|
|
12
|
+
}
|
|
13
|
+
/** Structural/integrity reduction only. The caller owns admission and snapshot completeness. */
|
|
14
|
+
export function evaluateStrictEvidence(value, observations, attempt) {
|
|
15
|
+
const snapshot = parseStrictEvidenceSnapshot(value);
|
|
16
|
+
const bindingKey = JSON.stringify(snapshot.binding);
|
|
17
|
+
if (snapshot.binding.taskId !== attempt.taskId || snapshot.binding.candidateHash !== attempt.candidateHash) {
|
|
18
|
+
throw new Error("Strict evidence binding does not match attempt");
|
|
19
|
+
}
|
|
20
|
+
const byId = new Map();
|
|
21
|
+
for (const observation of observations) {
|
|
22
|
+
const old = byId.get(observation.observationId);
|
|
23
|
+
if (old && canonical(old) !== canonical(observation)) {
|
|
24
|
+
throw new Error("Conflicting observation identity");
|
|
25
|
+
}
|
|
26
|
+
byId.set(observation.observationId, observation);
|
|
27
|
+
}
|
|
28
|
+
const identities = new Map();
|
|
29
|
+
const unique = new Map();
|
|
30
|
+
for (const result of snapshot.results) {
|
|
31
|
+
const payload = JSON.stringify(result);
|
|
32
|
+
for (const key of [
|
|
33
|
+
`observation:${result.observationId}`,
|
|
34
|
+
`execution:${result.executionId}`,
|
|
35
|
+
`sequence:${result.sequence}`,
|
|
36
|
+
]) {
|
|
37
|
+
const old = identities.get(key);
|
|
38
|
+
if (old !== undefined && old !== payload)
|
|
39
|
+
throw new Error("Conflicting strict evidence identity or sequence");
|
|
40
|
+
identities.set(key, payload);
|
|
41
|
+
}
|
|
42
|
+
const observation = byId.get(result.observationId);
|
|
43
|
+
if (!observation)
|
|
44
|
+
throw new Error("Strict completion references missing observation");
|
|
45
|
+
const candidate = observation.facts.candidate;
|
|
46
|
+
if (typeof candidate === "string" && candidate !== result.binding.candidateHash) {
|
|
47
|
+
throw new Error("Strict evidence binding disagrees with observation candidate");
|
|
48
|
+
}
|
|
49
|
+
unique.set(result.observationId, result);
|
|
50
|
+
}
|
|
51
|
+
const selected = [];
|
|
52
|
+
const missing = [];
|
|
53
|
+
let failed = false;
|
|
54
|
+
for (const checkId of [...snapshot.requiredCheckIds].sort()) {
|
|
55
|
+
const history = [...unique.values()]
|
|
56
|
+
.filter((r) => r.checkId === checkId && JSON.stringify(r.binding) === bindingKey)
|
|
57
|
+
.sort((a, b) => a.sequence - b.sequence);
|
|
58
|
+
for (const [index, result] of history.entries()) {
|
|
59
|
+
if (result.previousExecutionId !== (index === 0 ? null : history[index - 1].executionId)) {
|
|
60
|
+
throw new Error("Broken strict evidence attempt chain");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const latest = history.at(-1);
|
|
64
|
+
if (!latest)
|
|
65
|
+
missing.push(checkId);
|
|
66
|
+
else {
|
|
67
|
+
selected.push(latest.observationId);
|
|
68
|
+
failed ||= latest.verdict === "failed";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return Object.freeze({
|
|
72
|
+
policy: snapshot.policy,
|
|
73
|
+
status: snapshot.pendingExecutionIds.length > 0
|
|
74
|
+
? "pending"
|
|
75
|
+
: failed
|
|
76
|
+
? "violated"
|
|
77
|
+
: missing.length > 0
|
|
78
|
+
? "inconclusive"
|
|
79
|
+
: "passed",
|
|
80
|
+
observationIds: Object.freeze(selected.sort()),
|
|
81
|
+
missingCheckIds: Object.freeze(missing),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=strict-evidence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-evidence.js","sourceRoot":"","sources":["../src/strict-evidence.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAG9E,S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F,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,MAAM,EACL,QAAQ,CAAC,mBAAmB,CAAC,MAAM,GAAG,CAAC;YACtC,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,MAAM;gBACP,CAAC,CAAC,UAAU;gBACZ,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;oBACnB,CAAC,CAAC,cAAc;oBAChB,CAAC,CAAC,QAAQ;QACd,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC9C,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;KACvC,CAAC,CAAC;AAAA,CACH","sourcesContent":["import type { StrictEvidenceReport, StrictEvidenceSnapshot } from \"./strict-evidence-types.ts\";\nimport { parseStrictEvidenceSnapshot } from \"./strict-evidence-validation.ts\";\nimport type { ExecutionAttempt, JsonValue, Observation } from \"./types.ts\";\n\nfunction canonical(value: JsonValue): string {\n\tif (Array.isArray(value)) return `[${value.map(canonical).join(\",\")}]`;\n\tif (value !== null && typeof value === \"object\") {\n\t\treturn `{${Object.keys(value)\n\t\t\t.sort()\n\t\t\t.map((key) => `${JSON.stringify(key)}:${canonical((value as { readonly [key: string]: JsonValue })[key])}`)\n\t\t\t.join(\",\")}}`;\n\t}\n\treturn JSON.stringify(value);\n}\n\n/** Structural/integrity reduction only. The caller owns admission and snapshot completeness. */\nexport function evaluateStrictEvidence(\n\tvalue: StrictEvidenceSnapshot,\n\tobservations: readonly Observation[],\n\tattempt: ExecutionAttempt,\n): Omit<StrictEvidenceReport, \"acceptance\"> {\n\tconst snapshot = parseStrictEvidenceSnapshot(value);\n\tconst bindingKey = JSON.stringify(snapshot.binding);\n\tif (snapshot.binding.taskId !== attempt.taskId || snapshot.binding.candidateHash !== attempt.candidateHash) {\n\t\tthrow new Error(\"Strict evidence binding does not match attempt\");\n\t}\n\tconst byId = new Map<string, Observation>();\n\tfor (const observation of observations) {\n\t\tconst old = byId.get(observation.observationId);\n\t\tif (old && canonical(old as unknown as JsonValue) !== canonical(observation as unknown as JsonValue)) {\n\t\t\tthrow new Error(\"Conflicting observation identity\");\n\t\t}\n\t\tbyId.set(observation.observationId, observation);\n\t}\n\tconst identities = new Map<string, string>();\n\tconst unique = new Map<string, (typeof snapshot.results)[number]>();\n\tfor (const result of snapshot.results) {\n\t\tconst payload = JSON.stringify(result);\n\t\tfor (const key of [\n\t\t\t`observation:${result.observationId}`,\n\t\t\t`execution:${result.executionId}`,\n\t\t\t`sequence:${result.sequence}`,\n\t\t]) {\n\t\t\tconst old = identities.get(key);\n\t\t\tif (old !== undefined && old !== payload) throw new Error(\"Conflicting strict evidence identity or sequence\");\n\t\t\tidentities.set(key, payload);\n\t\t}\n\t\tconst observation = byId.get(result.observationId);\n\t\tif (!observation) throw new Error(\"Strict completion references missing observation\");\n\t\tconst candidate = observation.facts.candidate;\n\t\tif (typeof candidate === \"string\" && candidate !== result.binding.candidateHash) {\n\t\t\tthrow new Error(\"Strict evidence binding disagrees with observation candidate\");\n\t\t}\n\t\tunique.set(result.observationId, result);\n\t}\n\tconst selected: string[] = [];\n\tconst missing: string[] = [];\n\tlet failed = false;\n\tfor (const checkId of [...snapshot.requiredCheckIds].sort()) {\n\t\tconst history = [...unique.values()]\n\t\t\t.filter((r) => r.checkId === checkId && JSON.stringify(r.binding) === bindingKey)\n\t\t\t.sort((a, b) => a.sequence - b.sequence);\n\t\tfor (const [index, result] of history.entries()) {\n\t\t\tif (result.previousExecutionId !== (index === 0 ? null : history[index - 1].executionId)) {\n\t\t\t\tthrow new Error(\"Broken strict evidence attempt chain\");\n\t\t\t}\n\t\t}\n\t\tconst latest = history.at(-1);\n\t\tif (!latest) missing.push(checkId);\n\t\telse {\n\t\t\tselected.push(latest.observationId);\n\t\t\tfailed ||= latest.verdict === \"failed\";\n\t\t}\n\t}\n\treturn Object.freeze({\n\t\tpolicy: snapshot.policy,\n\t\tstatus:\n\t\t\tsnapshot.pendingExecutionIds.length > 0\n\t\t\t\t? \"pending\"\n\t\t\t\t: failed\n\t\t\t\t\t? \"violated\"\n\t\t\t\t\t: missing.length > 0\n\t\t\t\t\t\t? \"inconclusive\"\n\t\t\t\t\t\t: \"passed\",\n\t\tobservationIds: Object.freeze(selected.sort()),\n\t\tmissingCheckIds: Object.freeze(missing),\n\t});\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StrictEvidenceReport, StrictEvidenceSnapshot } from "./strict-evidence-types.ts";
|
|
1
2
|
export declare const PROTOCOL_VERSION: "omk.run.v1";
|
|
2
3
|
export type ProtocolVersion = typeof PROTOCOL_VERSION;
|
|
3
4
|
export type JsonPrimitive = boolean | number | string | null;
|
|
@@ -14,6 +15,13 @@ export interface ObservationCondition {
|
|
|
14
15
|
readonly observationKind: string;
|
|
15
16
|
readonly scope: "attempt" | "task";
|
|
16
17
|
readonly facts: JsonObject;
|
|
18
|
+
/**
|
|
19
|
+
* When `"candidate"`, the observation must additionally carry
|
|
20
|
+
* `facts.candidate` equal to the evaluated attempt's `candidateHash` —
|
|
21
|
+
* a pass observed for a different candidate can never satisfy the claim.
|
|
22
|
+
* Requires the attempt to declare `candidateHash`.
|
|
23
|
+
*/
|
|
24
|
+
readonly bindToCandidate?: boolean;
|
|
17
25
|
}
|
|
18
26
|
export interface AllCondition {
|
|
19
27
|
readonly kind: "all";
|
|
@@ -69,6 +77,13 @@ export interface ExecutionAttempt {
|
|
|
69
77
|
readonly finishedAt: string;
|
|
70
78
|
readonly executor: AttemptExecutor;
|
|
71
79
|
readonly outcome: AttemptOutcome;
|
|
80
|
+
/**
|
|
81
|
+
* Hash identifying the candidate (source tree / artifact) this attempt ran
|
|
82
|
+
* against. When set, `scope: "task"` observations recorded for a different
|
|
83
|
+
* candidate do not satisfy conditions of this attempt's evaluation —
|
|
84
|
+
* evidence stays bound to the candidate it was produced for.
|
|
85
|
+
*/
|
|
86
|
+
readonly candidateHash?: string;
|
|
72
87
|
}
|
|
73
88
|
/** Immutable execution facts. Semantic pass/fail belongs only in ClaimEvaluation. */
|
|
74
89
|
export interface Observation {
|
|
@@ -109,6 +124,7 @@ export interface ClaimEvaluation {
|
|
|
109
124
|
readonly waiverId?: string;
|
|
110
125
|
}
|
|
111
126
|
export interface EvaluationResult {
|
|
127
|
+
readonly strictEvidence?: StrictEvidenceReport;
|
|
112
128
|
readonly schemaVersion: ProtocolVersion;
|
|
113
129
|
readonly evaluationId: string;
|
|
114
130
|
readonly taskId: string;
|
|
@@ -118,6 +134,8 @@ export interface EvaluationResult {
|
|
|
118
134
|
readonly semanticVerdict: SemanticVerdict;
|
|
119
135
|
}
|
|
120
136
|
export interface EvaluationInput {
|
|
137
|
+
/** Host-admitted snapshot only; omitted preserves historical exists semantics and wire shape. */
|
|
138
|
+
readonly strictEvidence?: StrictEvidenceSnapshot;
|
|
121
139
|
readonly evaluationId: string;
|
|
122
140
|
readonly evaluatedAt: string;
|
|
123
141
|
readonly taskSpec: TaskSpec;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,cAAwB,CAAC;AAEtD,MAAM,MAAM,eAAe,GAAG,OAAO,gBAAgB,CAAC;AACtD,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,SAAS,EAAE,CAAC;AAC1E,MAAM,WAAW,UAAU;IAC1B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC;AAED,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,UAAU,CAAC;AACvD,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM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MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;CAC3C;AAED,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;CACvC","sourcesContent":["export const PROTOCOL_VERSION = \"omk.run.v1\" as const;\n\nexport type ProtocolVersion = typeof PROTOCOL_VERSION;\nexport type JsonPrimitive = boolean | number | string | null;\nexport type JsonValue = JsonPrimitive | JsonObject | readonly JsonValue[];\nexport interface JsonObject {\n\treadonly [key: string]: JsonValue;\n}\n\nexport type RequirementLevel = \"required\" | \"advisory\";\nexport type SemanticVerdict = \"pass\" | \"fail\" | \"inconclusive\";\nexport type ClaimResult = \"satisfied\" | \"violated\" | \"inconclusive\";\nexport type RuntimeAction = \"continue\" | \"retry\" | \"failover\" | \"stop\";\n\nexport interface ObservationCondition {\n\treadonly kind: \"observation\";\n\treadonly observationKind: string;\n\treadonly scope: \"attempt\" | \"task\";\n\treadonly facts: JsonObject;\n}\n\nexport interface AllCondition {\n\treadonly kind: \"all\";\n\treadonly conditions: readonly ClaimCondition[];\n}\n\nexport interface AnyCondition {\n\treadonly kind: \"any\";\n\treadonly conditions: readonly ClaimCondition[];\n}\n\nexport interface NotCondition {\n\treadonly kind: \"not\";\n\treadonly condition: ClaimCondition;\n}\n\nexport type ClaimCondition = ObservationCondition | AllCondition | AnyCondition | NotCondition;\n\nexport interface ClaimPredicate {\n\treadonly claimId: string;\n\treadonly statement: string;\n\treadonly requirement: RequirementLevel;\n\treadonly condition: ClaimCondition;\n}\n\nexport interface TaskSpec {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly taskId: string;\n\treadonly goal: string;\n\treadonly createdAt: string;\n\treadonly claims: readonly ClaimPredicate[];\n}\n\nexport type AttemptTrigger = \"initial\" | \"retry\" | \"failover\" | \"resume\";\n\nexport interface AttemptExecutor {\n\treadonly kind: string;\n\treadonly provider?: string;\n\treadonly model?: string;\n}\n\nexport type AttemptOutcome =\n\t| { readonly kind: \"completed\" }\n\t| { readonly kind: \"failed\"; readonly code: string; readonly message?: string }\n\t| { readonly kind: \"cancelled\"; readonly code: string };\n\n/** One completed execution. Retry and failover counts are derived from these records. */\nexport interface ExecutionAttempt {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly attemptId: string;\n\treadonly taskId: string;\n\treadonly sequence: number;\n\treadonly trigger: AttemptTrigger;\n\treadonly previousAttemptId?: string;\n\treadonly startedAt: string;\n\treadonly finishedAt: string;\n\treadonly executor: AttemptExecutor;\n\treadonly outcome: AttemptOutcome;\n}\n\n/** Immutable execution facts. Semantic pass/fail belongs only in ClaimEvaluation. */\nexport interface Observation {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly observationId: string;\n\treadonly taskId: string;\n\treadonly attemptId: string;\n\treadonly observedAt: string;\n\treadonly kind: string;\n\treadonly source: {\n\t\treadonly kind: string;\n\t\treadonly id: string;\n\t};\n\treadonly facts: JsonObject;\n\treadonly evidenceRefs: readonly string[];\n}\n\nexport interface WaiverRecord {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly waiverId: string;\n\treadonly scope: {\n\t\treadonly taskId: string;\n\t\treadonly claimId: string;\n\t\treadonly attemptId?: string;\n\t};\n\treadonly approvedBy: string;\n\treadonly approvedAt: string;\n\treadonly expiresAt?: string;\n\treadonly rationale: string;\n\treadonly evidenceRefs: readonly string[];\n}\n\nexport type ClaimReasonCode = \"claim.satisfied\" | \"claim.violated\" | \"claim.observation_missing\";\n\nexport interface ClaimEvaluation {\n\treadonly claimId: string;\n\treadonly requirement: RequirementLevel;\n\treadonly result: ClaimResult;\n\treadonly reasonCode: ClaimReasonCode;\n\treadonly observationIds: readonly string[];\n\treadonly waiverId?: string;\n}\n\nexport interface EvaluationResult {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly evaluationId: string;\n\treadonly taskId: string;\n\treadonly attemptId: string;\n\treadonly evaluatedAt: string;\n\treadonly claims: readonly ClaimEvaluation[];\n\treadonly semanticVerdict: SemanticVerdict;\n}\n\nexport interface EvaluationInput {\n\treadonly evaluationId: string;\n\treadonly evaluatedAt: string;\n\treadonly taskSpec: TaskSpec;\n\treadonly attempt: ExecutionAttempt;\n\treadonly observations: readonly Observation[];\n\treadonly waivers?: readonly WaiverRecord[];\n}\n\nexport interface RuntimeDecisionPolicy {\n\treadonly onFail: RuntimeAction;\n\treadonly onInconclusive: RuntimeAction;\n}\n\nexport type RuntimeDecisionReason = \"evaluation.pass\" | \"evaluation.fail\" | \"evaluation.inconclusive\";\n\nexport interface RuntimeDecision {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly decisionId: string;\n\treadonly taskId: string;\n\treadonly attemptId: string;\n\treadonly evaluationId: string;\n\treadonly decidedAt: string;\n\treadonly action: RuntimeAction;\n\treadonly reasonCode: RuntimeDecisionReason;\n}\n\nexport interface RuntimeDecisionInput {\n\treadonly decisionId: string;\n\treadonly decidedAt: string;\n\treadonly evaluation: EvaluationResult;\n\treadonly policy: RuntimeDecisionPolicy;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAE/F,eAAO,MAAM,gBAAgB,cAAwB,CAAC;AAEtD,MAAM,MAAM,eAAe,GAAG,OAAO,gBAAgB,CAAC;AACtD,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAC7D,MAAM,MA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,QAAQ,CAAC,YAAY,EAAE,SAAS,WAAW,EAAE,CAAC;IAC9C,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,aAAa,CAAC;CACvC;AAED,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,GAAG,iBAAiB,GAAG,yBAAyB,CAAC;AAEtG,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,aAAa,EAAE,eAAe,CAAC;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;CAC3C;AAED,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;CACvC","sourcesContent":["import type { StrictEvidenceReport, StrictEvidenceSnapshot } from \"./strict-evidence-types.ts\";\n\nexport const PROTOCOL_VERSION = \"omk.run.v1\" as const;\n\nexport type ProtocolVersion = typeof PROTOCOL_VERSION;\nexport type JsonPrimitive = boolean | number | string | null;\nexport type JsonValue = JsonPrimitive | JsonObject | readonly JsonValue[];\nexport interface JsonObject {\n\treadonly [key: string]: JsonValue;\n}\n\nexport type RequirementLevel = \"required\" | \"advisory\";\nexport type SemanticVerdict = \"pass\" | \"fail\" | \"inconclusive\";\nexport type ClaimResult = \"satisfied\" | \"violated\" | \"inconclusive\";\nexport type RuntimeAction = \"continue\" | \"retry\" | \"failover\" | \"stop\";\n\nexport interface ObservationCondition {\n\treadonly kind: \"observation\";\n\treadonly observationKind: string;\n\treadonly scope: \"attempt\" | \"task\";\n\treadonly facts: JsonObject;\n\t/**\n\t * When `\"candidate\"`, the observation must additionally carry\n\t * `facts.candidate` equal to the evaluated attempt's `candidateHash` —\n\t * a pass observed for a different candidate can never satisfy the claim.\n\t * Requires the attempt to declare `candidateHash`.\n\t */\n\treadonly bindToCandidate?: boolean;\n}\n\nexport interface AllCondition {\n\treadonly kind: \"all\";\n\treadonly conditions: readonly ClaimCondition[];\n}\n\nexport interface AnyCondition {\n\treadonly kind: \"any\";\n\treadonly conditions: readonly ClaimCondition[];\n}\n\nexport interface NotCondition {\n\treadonly kind: \"not\";\n\treadonly condition: ClaimCondition;\n}\n\nexport type ClaimCondition = ObservationCondition | AllCondition | AnyCondition | NotCondition;\n\nexport interface ClaimPredicate {\n\treadonly claimId: string;\n\treadonly statement: string;\n\treadonly requirement: RequirementLevel;\n\treadonly condition: ClaimCondition;\n}\n\nexport interface TaskSpec {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly taskId: string;\n\treadonly goal: string;\n\treadonly createdAt: string;\n\treadonly claims: readonly ClaimPredicate[];\n}\n\nexport type AttemptTrigger = \"initial\" | \"retry\" | \"failover\" | \"resume\";\n\nexport interface AttemptExecutor {\n\treadonly kind: string;\n\treadonly provider?: string;\n\treadonly model?: string;\n}\n\nexport type AttemptOutcome =\n\t| { readonly kind: \"completed\" }\n\t| { readonly kind: \"failed\"; readonly code: string; readonly message?: string }\n\t| { readonly kind: \"cancelled\"; readonly code: string };\n\n/** One completed execution. Retry and failover counts are derived from these records. */\nexport interface ExecutionAttempt {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly attemptId: string;\n\treadonly taskId: string;\n\treadonly sequence: number;\n\treadonly trigger: AttemptTrigger;\n\treadonly previousAttemptId?: string;\n\treadonly startedAt: string;\n\treadonly finishedAt: string;\n\treadonly executor: AttemptExecutor;\n\treadonly outcome: AttemptOutcome;\n\t/**\n\t * Hash identifying the candidate (source tree / artifact) this attempt ran\n\t * against. When set, `scope: \"task\"` observations recorded for a different\n\t * candidate do not satisfy conditions of this attempt's evaluation —\n\t * evidence stays bound to the candidate it was produced for.\n\t */\n\treadonly candidateHash?: string;\n}\n\n/** Immutable execution facts. Semantic pass/fail belongs only in ClaimEvaluation. */\nexport interface Observation {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly observationId: string;\n\treadonly taskId: string;\n\treadonly attemptId: string;\n\treadonly observedAt: string;\n\treadonly kind: string;\n\treadonly source: {\n\t\treadonly kind: string;\n\t\treadonly id: string;\n\t};\n\treadonly facts: JsonObject;\n\treadonly evidenceRefs: readonly string[];\n}\n\nexport interface WaiverRecord {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly waiverId: string;\n\treadonly scope: {\n\t\treadonly taskId: string;\n\t\treadonly claimId: string;\n\t\treadonly attemptId?: string;\n\t};\n\treadonly approvedBy: string;\n\treadonly approvedAt: string;\n\treadonly expiresAt?: string;\n\treadonly rationale: string;\n\treadonly evidenceRefs: readonly string[];\n}\n\nexport type ClaimReasonCode = \"claim.satisfied\" | \"claim.violated\" | \"claim.observation_missing\";\n\nexport interface ClaimEvaluation {\n\treadonly claimId: string;\n\treadonly requirement: RequirementLevel;\n\treadonly result: ClaimResult;\n\treadonly reasonCode: ClaimReasonCode;\n\treadonly observationIds: readonly string[];\n\treadonly waiverId?: string;\n}\n\nexport interface EvaluationResult {\n\treadonly strictEvidence?: StrictEvidenceReport;\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly evaluationId: string;\n\treadonly taskId: string;\n\treadonly attemptId: string;\n\treadonly evaluatedAt: string;\n\treadonly claims: readonly ClaimEvaluation[];\n\treadonly semanticVerdict: SemanticVerdict;\n}\n\nexport interface EvaluationInput {\n\t/** Host-admitted snapshot only; omitted preserves historical exists semantics and wire shape. */\n\treadonly strictEvidence?: StrictEvidenceSnapshot;\n\treadonly evaluationId: string;\n\treadonly evaluatedAt: string;\n\treadonly taskSpec: TaskSpec;\n\treadonly attempt: ExecutionAttempt;\n\treadonly observations: readonly Observation[];\n\treadonly waivers?: readonly WaiverRecord[];\n}\n\nexport interface RuntimeDecisionPolicy {\n\treadonly onFail: RuntimeAction;\n\treadonly onInconclusive: RuntimeAction;\n}\n\nexport type RuntimeDecisionReason = \"evaluation.pass\" | \"evaluation.fail\" | \"evaluation.inconclusive\";\n\nexport interface RuntimeDecision {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly decisionId: string;\n\treadonly taskId: string;\n\treadonly attemptId: string;\n\treadonly evaluationId: string;\n\treadonly decidedAt: string;\n\treadonly action: RuntimeAction;\n\treadonly reasonCode: RuntimeDecisionReason;\n}\n\nexport interface RuntimeDecisionInput {\n\treadonly decisionId: string;\n\treadonly decidedAt: string;\n\treadonly evaluation: EvaluationResult;\n\treadonly policy: RuntimeDecisionPolicy;\n}\n"]}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAqB,CAAC","sourcesContent":["import type { StrictEvidenceReport, StrictEvidenceSnapshot } from \"./strict-evidence-types.ts\";\n\nexport const PROTOCOL_VERSION = \"omk.run.v1\" as const;\n\nexport type ProtocolVersion = typeof PROTOCOL_VERSION;\nexport type JsonPrimitive = boolean | number | string | null;\nexport type JsonValue = JsonPrimitive | JsonObject | readonly JsonValue[];\nexport interface JsonObject {\n\treadonly [key: string]: JsonValue;\n}\n\nexport type RequirementLevel = \"required\" | \"advisory\";\nexport type SemanticVerdict = \"pass\" | \"fail\" | \"inconclusive\";\nexport type ClaimResult = \"satisfied\" | \"violated\" | \"inconclusive\";\nexport type RuntimeAction = \"continue\" | \"retry\" | \"failover\" | \"stop\";\n\nexport interface ObservationCondition {\n\treadonly kind: \"observation\";\n\treadonly observationKind: string;\n\treadonly scope: \"attempt\" | \"task\";\n\treadonly facts: JsonObject;\n\t/**\n\t * When `\"candidate\"`, the observation must additionally carry\n\t * `facts.candidate` equal to the evaluated attempt's `candidateHash` —\n\t * a pass observed for a different candidate can never satisfy the claim.\n\t * Requires the attempt to declare `candidateHash`.\n\t */\n\treadonly bindToCandidate?: boolean;\n}\n\nexport interface AllCondition {\n\treadonly kind: \"all\";\n\treadonly conditions: readonly ClaimCondition[];\n}\n\nexport interface AnyCondition {\n\treadonly kind: \"any\";\n\treadonly conditions: readonly ClaimCondition[];\n}\n\nexport interface NotCondition {\n\treadonly kind: \"not\";\n\treadonly condition: ClaimCondition;\n}\n\nexport type ClaimCondition = ObservationCondition | AllCondition | AnyCondition | NotCondition;\n\nexport interface ClaimPredicate {\n\treadonly claimId: string;\n\treadonly statement: string;\n\treadonly requirement: RequirementLevel;\n\treadonly condition: ClaimCondition;\n}\n\nexport interface TaskSpec {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly taskId: string;\n\treadonly goal: string;\n\treadonly createdAt: string;\n\treadonly claims: readonly ClaimPredicate[];\n}\n\nexport type AttemptTrigger = \"initial\" | \"retry\" | \"failover\" | \"resume\";\n\nexport interface AttemptExecutor {\n\treadonly kind: string;\n\treadonly provider?: string;\n\treadonly model?: string;\n}\n\nexport type AttemptOutcome =\n\t| { readonly kind: \"completed\" }\n\t| { readonly kind: \"failed\"; readonly code: string; readonly message?: string }\n\t| { readonly kind: \"cancelled\"; readonly code: string };\n\n/** One completed execution. Retry and failover counts are derived from these records. */\nexport interface ExecutionAttempt {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly attemptId: string;\n\treadonly taskId: string;\n\treadonly sequence: number;\n\treadonly trigger: AttemptTrigger;\n\treadonly previousAttemptId?: string;\n\treadonly startedAt: string;\n\treadonly finishedAt: string;\n\treadonly executor: AttemptExecutor;\n\treadonly outcome: AttemptOutcome;\n\t/**\n\t * Hash identifying the candidate (source tree / artifact) this attempt ran\n\t * against. When set, `scope: \"task\"` observations recorded for a different\n\t * candidate do not satisfy conditions of this attempt's evaluation —\n\t * evidence stays bound to the candidate it was produced for.\n\t */\n\treadonly candidateHash?: string;\n}\n\n/** Immutable execution facts. Semantic pass/fail belongs only in ClaimEvaluation. */\nexport interface Observation {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly observationId: string;\n\treadonly taskId: string;\n\treadonly attemptId: string;\n\treadonly observedAt: string;\n\treadonly kind: string;\n\treadonly source: {\n\t\treadonly kind: string;\n\t\treadonly id: string;\n\t};\n\treadonly facts: JsonObject;\n\treadonly evidenceRefs: readonly string[];\n}\n\nexport interface WaiverRecord {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly waiverId: string;\n\treadonly scope: {\n\t\treadonly taskId: string;\n\t\treadonly claimId: string;\n\t\treadonly attemptId?: string;\n\t};\n\treadonly approvedBy: string;\n\treadonly approvedAt: string;\n\treadonly expiresAt?: string;\n\treadonly rationale: string;\n\treadonly evidenceRefs: readonly string[];\n}\n\nexport type ClaimReasonCode = \"claim.satisfied\" | \"claim.violated\" | \"claim.observation_missing\";\n\nexport interface ClaimEvaluation {\n\treadonly claimId: string;\n\treadonly requirement: RequirementLevel;\n\treadonly result: ClaimResult;\n\treadonly reasonCode: ClaimReasonCode;\n\treadonly observationIds: readonly string[];\n\treadonly waiverId?: string;\n}\n\nexport interface EvaluationResult {\n\treadonly strictEvidence?: StrictEvidenceReport;\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly evaluationId: string;\n\treadonly taskId: string;\n\treadonly attemptId: string;\n\treadonly evaluatedAt: string;\n\treadonly claims: readonly ClaimEvaluation[];\n\treadonly semanticVerdict: SemanticVerdict;\n}\n\nexport interface EvaluationInput {\n\t/** Host-admitted snapshot only; omitted preserves historical exists semantics and wire shape. */\n\treadonly strictEvidence?: StrictEvidenceSnapshot;\n\treadonly evaluationId: string;\n\treadonly evaluatedAt: string;\n\treadonly taskSpec: TaskSpec;\n\treadonly attempt: ExecutionAttempt;\n\treadonly observations: readonly Observation[];\n\treadonly waivers?: readonly WaiverRecord[];\n}\n\nexport interface RuntimeDecisionPolicy {\n\treadonly onFail: RuntimeAction;\n\treadonly onInconclusive: RuntimeAction;\n}\n\nexport type RuntimeDecisionReason = \"evaluation.pass\" | \"evaluation.fail\" | \"evaluation.inconclusive\";\n\nexport interface RuntimeDecision {\n\treadonly schemaVersion: ProtocolVersion;\n\treadonly decisionId: string;\n\treadonly taskId: string;\n\treadonly attemptId: string;\n\treadonly evaluationId: string;\n\treadonly decidedAt: string;\n\treadonly action: RuntimeAction;\n\treadonly reasonCode: RuntimeDecisionReason;\n}\n\nexport interface RuntimeDecisionInput {\n\treadonly decisionId: string;\n\treadonly decidedAt: string;\n\treadonly evaluation: EvaluationResult;\n\treadonly policy: RuntimeDecisionPolicy;\n}\n"]}
|
package/dist/validation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAGrB,KAAK,WAAW,EAEhB,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,MAAM,YAAY,CAAC;AAKpB,qBAAa,uBAAwB,SAAQ,KAAK;IACjD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAkFD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAoBtD;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CA6BtE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAc5D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAc9D;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CA2BtE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAepE","sourcesContent":["import {\n\ttype ClaimCondition,\n\ttype EvaluationResult,\n\ttype ExecutionAttempt,\n\ttype JsonObject,\n\ttype JsonValue,\n\ttype Observation,\n\tPROTOCOL_VERSION,\n\ttype RuntimeDecision,\n\ttype TaskSpec,\n\ttype WaiverRecord,\n} from \"./types.ts\";\n\nconst ISO_TIMESTAMP = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/;\nconst MAX_CONDITION_DEPTH = 32;\n\nexport class ProtocolValidationError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"ProtocolValidationError\";\n\t}\n}\n\nfunction record(value: unknown, path: string): Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new ProtocolValidationError(`${path} must be an object`);\n\t}\n\treturn value as Record<string, unknown>;\n}\n\nfunction string(value: unknown, path: string): string {\n\tif (typeof value !== \"string\" || value.trim().length === 0) {\n\t\tthrow new ProtocolValidationError(`${path} must be a non-empty string`);\n\t}\n\treturn value;\n}\n\nfunction timestamp(value: unknown, path: string): string {\n\tconst parsed = string(value, path);\n\tif (!ISO_TIMESTAMP.test(parsed) || Number.isNaN(Date.parse(parsed))) {\n\t\tthrow new ProtocolValidationError(`${path} must be an ISO 8601 UTC timestamp`);\n\t}\n\treturn parsed;\n}\n\nfunction version(value: Record<string, unknown>, path: string): void {\n\tif (value.schemaVersion !== PROTOCOL_VERSION) {\n\t\tthrow new ProtocolValidationError(`${path}.schemaVersion must be ${PROTOCOL_VERSION}`);\n\t}\n}\n\nfunction stringArray(value: unknown, path: string): readonly string[] {\n\tif (!Array.isArray(value)) throw new ProtocolValidationError(`${path} must be an array`);\n\treturn value.map((item, index) => string(item, `${path}[${index}]`));\n}\n\nfunction jsonValue(value: unknown, path: string, depth = 0): asserts value is JsonValue {\n\tif (depth > MAX_CONDITION_DEPTH) throw new ProtocolValidationError(`${path} exceeds maximum nesting depth`);\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return;\n\tif (typeof value === \"number\" && Number.isFinite(value)) return;\n\tif (Array.isArray(value)) {\n\t\tvalue.forEach((item, index) => {\n\t\t\tjsonValue(item, `${path}[${index}]`, depth + 1);\n\t\t});\n\t\treturn;\n\t}\n\tconst object = record(value, path);\n\tfor (const [key, item] of Object.entries(object)) jsonValue(item, `${path}.${key}`, depth + 1);\n}\n\nfunction jsonObject(value: unknown, path: string): asserts value is JsonObject {\n\trecord(value, path);\n\tjsonValue(value, path);\n}\n\nfunction condition(value: unknown, path: string, depth = 0): asserts value is ClaimCondition {\n\tif (depth > MAX_CONDITION_DEPTH) throw new ProtocolValidationError(`${path} exceeds maximum nesting depth`);\n\tconst input = record(value, path);\n\tswitch (input.kind) {\n\t\tcase \"observation\":\n\t\t\tstring(input.observationKind, `${path}.observationKind`);\n\t\t\tif (input.scope !== \"attempt\" && input.scope !== \"task\") {\n\t\t\t\tthrow new ProtocolValidationError(`${path}.scope must be attempt or task`);\n\t\t\t}\n\t\t\tjsonObject(input.facts, `${path}.facts`);\n\t\t\treturn;\n\t\tcase \"all\":\n\t\tcase \"any\":\n\t\t\tif (!Array.isArray(input.conditions) || input.conditions.length === 0) {\n\t\t\t\tthrow new ProtocolValidationError(`${path}.conditions must be a non-empty array`);\n\t\t\t}\n\t\t\tinput.conditions.forEach((item, index) => {\n\t\t\t\tcondition(item, `${path}.conditions[${index}]`, depth + 1);\n\t\t\t});\n\t\t\treturn;\n\t\tcase \"not\":\n\t\t\tcondition(input.condition, `${path}.condition`, depth + 1);\n\t\t\treturn;\n\t\tdefault:\n\t\t\tthrow new ProtocolValidationError(`${path}.kind is unsupported`);\n\t}\n}\n\nexport function parseTaskSpec(value: unknown): TaskSpec {\n\tconst input = record(value, \"taskSpec\");\n\tversion(input, \"taskSpec\");\n\tstring(input.taskId, \"taskSpec.taskId\");\n\tstring(input.goal, \"taskSpec.goal\");\n\ttimestamp(input.createdAt, \"taskSpec.createdAt\");\n\tif (!Array.isArray(input.claims)) throw new ProtocolValidationError(\"taskSpec.claims must be an array\");\n\tconst claimIds = new Set<string>();\n\tfor (const [index, rawClaim] of input.claims.entries()) {\n\t\tconst claim = record(rawClaim, `taskSpec.claims[${index}]`);\n\t\tconst claimId = string(claim.claimId, `taskSpec.claims[${index}].claimId`);\n\t\tif (claimIds.has(claimId)) throw new ProtocolValidationError(`duplicate claimId ${claimId}`);\n\t\tclaimIds.add(claimId);\n\t\tstring(claim.statement, `taskSpec.claims[${index}].statement`);\n\t\tif (claim.requirement !== \"required\" && claim.requirement !== \"advisory\") {\n\t\t\tthrow new ProtocolValidationError(`taskSpec.claims[${index}].requirement is unsupported`);\n\t\t}\n\t\tcondition(claim.condition, `taskSpec.claims[${index}].condition`);\n\t}\n\treturn value as TaskSpec;\n}\n\nexport function parseExecutionAttempt(value: unknown): ExecutionAttempt {\n\tconst input = record(value, \"attempt\");\n\tversion(input, \"attempt\");\n\tstring(input.attemptId, \"attempt.attemptId\");\n\tstring(input.taskId, \"attempt.taskId\");\n\tif (!Number.isSafeInteger(input.sequence) || (input.sequence as number) < 1) {\n\t\tthrow new ProtocolValidationError(\"attempt.sequence must be a positive integer\");\n\t}\n\tif (![\"initial\", \"retry\", \"failover\", \"resume\"].includes(input.trigger as string)) {\n\t\tthrow new ProtocolValidationError(\"attempt.trigger is unsupported\");\n\t}\n\tif (input.previousAttemptId !== undefined) string(input.previousAttemptId, \"attempt.previousAttemptId\");\n\tconst startedAt = timestamp(input.startedAt, \"attempt.startedAt\");\n\tconst finishedAt = timestamp(input.finishedAt, \"attempt.finishedAt\");\n\tif (finishedAt < startedAt) throw new ProtocolValidationError(\"attempt.finishedAt precedes startedAt\");\n\tconst executor = record(input.executor, \"attempt.executor\");\n\tstring(executor.kind, \"attempt.executor.kind\");\n\tif (executor.provider !== undefined) string(executor.provider, \"attempt.executor.provider\");\n\tif (executor.model !== undefined) string(executor.model, \"attempt.executor.model\");\n\tconst outcome = record(input.outcome, \"attempt.outcome\");\n\tif (outcome.kind === \"failed\") {\n\t\tstring(outcome.code, \"attempt.outcome.code\");\n\t\tif (outcome.message !== undefined) string(outcome.message, \"attempt.outcome.message\");\n\t} else if (outcome.kind === \"cancelled\") {\n\t\tstring(outcome.code, \"attempt.outcome.code\");\n\t} else if (outcome.kind !== \"completed\") {\n\t\tthrow new ProtocolValidationError(\"attempt.outcome.kind is unsupported\");\n\t}\n\treturn value as ExecutionAttempt;\n}\n\nexport function parseObservation(value: unknown): Observation {\n\tconst input = record(value, \"observation\");\n\tversion(input, \"observation\");\n\tstring(input.observationId, \"observation.observationId\");\n\tstring(input.taskId, \"observation.taskId\");\n\tstring(input.attemptId, \"observation.attemptId\");\n\ttimestamp(input.observedAt, \"observation.observedAt\");\n\tstring(input.kind, \"observation.kind\");\n\tconst source = record(input.source, \"observation.source\");\n\tstring(source.kind, \"observation.source.kind\");\n\tstring(source.id, \"observation.source.id\");\n\tjsonObject(input.facts, \"observation.facts\");\n\tstringArray(input.evidenceRefs, \"observation.evidenceRefs\");\n\treturn value as Observation;\n}\n\nexport function parseWaiverRecord(value: unknown): WaiverRecord {\n\tconst input = record(value, \"waiver\");\n\tversion(input, \"waiver\");\n\tstring(input.waiverId, \"waiver.waiverId\");\n\tconst scope = record(input.scope, \"waiver.scope\");\n\tstring(scope.taskId, \"waiver.scope.taskId\");\n\tstring(scope.claimId, \"waiver.scope.claimId\");\n\tif (scope.attemptId !== undefined) string(scope.attemptId, \"waiver.scope.attemptId\");\n\tstring(input.approvedBy, \"waiver.approvedBy\");\n\ttimestamp(input.approvedAt, \"waiver.approvedAt\");\n\tif (input.expiresAt !== undefined) timestamp(input.expiresAt, \"waiver.expiresAt\");\n\tstring(input.rationale, \"waiver.rationale\");\n\tstringArray(input.evidenceRefs, \"waiver.evidenceRefs\");\n\treturn value as WaiverRecord;\n}\n\nexport function parseEvaluationResult(value: unknown): EvaluationResult {\n\tconst input = record(value, \"evaluation\");\n\tversion(input, \"evaluation\");\n\tstring(input.evaluationId, \"evaluation.evaluationId\");\n\tstring(input.taskId, \"evaluation.taskId\");\n\tstring(input.attemptId, \"evaluation.attemptId\");\n\ttimestamp(input.evaluatedAt, \"evaluation.evaluatedAt\");\n\tif (!Array.isArray(input.claims)) throw new ProtocolValidationError(\"evaluation.claims must be an array\");\n\tfor (const [index, rawClaim] of input.claims.entries()) {\n\t\tconst claim = record(rawClaim, `evaluation.claims[${index}]`);\n\t\tstring(claim.claimId, `evaluation.claims[${index}].claimId`);\n\t\tif (claim.requirement !== \"required\" && claim.requirement !== \"advisory\") {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].requirement is unsupported`);\n\t\t}\n\t\tif (![\"satisfied\", \"violated\", \"inconclusive\"].includes(claim.result as string)) {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].result is unsupported`);\n\t\t}\n\t\tif (![\"claim.satisfied\", \"claim.violated\", \"claim.observation_missing\"].includes(claim.reasonCode as string)) {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].reasonCode is unsupported`);\n\t\t}\n\t\tstringArray(claim.observationIds, `evaluation.claims[${index}].observationIds`);\n\t\tif (claim.waiverId !== undefined) string(claim.waiverId, `evaluation.claims[${index}].waiverId`);\n\t}\n\tif (![\"pass\", \"fail\", \"inconclusive\"].includes(input.semanticVerdict as string)) {\n\t\tthrow new ProtocolValidationError(\"evaluation.semanticVerdict is unsupported\");\n\t}\n\treturn value as EvaluationResult;\n}\n\nexport function parseRuntimeDecision(value: unknown): RuntimeDecision {\n\tconst input = record(value, \"decision\");\n\tversion(input, \"decision\");\n\tstring(input.decisionId, \"decision.decisionId\");\n\tstring(input.taskId, \"decision.taskId\");\n\tstring(input.attemptId, \"decision.attemptId\");\n\tstring(input.evaluationId, \"decision.evaluationId\");\n\ttimestamp(input.decidedAt, \"decision.decidedAt\");\n\tif (![\"continue\", \"retry\", \"failover\", \"stop\"].includes(input.action as string)) {\n\t\tthrow new ProtocolValidationError(\"decision.action is unsupported\");\n\t}\n\tif (![\"evaluation.pass\", \"evaluation.fail\", \"evaluation.inconclusive\"].includes(input.reasonCode as string)) {\n\t\tthrow new ProtocolValidationError(\"decision.reasonCode is unsupported\");\n\t}\n\treturn value as RuntimeDecision;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAGrB,KAAK,WAAW,EAEhB,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,MAAM,YAAY,CAAC;AAKpB,qBAAa,uBAAwB,SAAQ,KAAK;IACjD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAqFD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAoBtD;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CA8BtE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAc5D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAc9D;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CA2BtE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAepE","sourcesContent":["import {\n\ttype ClaimCondition,\n\ttype EvaluationResult,\n\ttype ExecutionAttempt,\n\ttype JsonObject,\n\ttype JsonValue,\n\ttype Observation,\n\tPROTOCOL_VERSION,\n\ttype RuntimeDecision,\n\ttype TaskSpec,\n\ttype WaiverRecord,\n} from \"./types.ts\";\n\nconst ISO_TIMESTAMP = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/;\nconst MAX_CONDITION_DEPTH = 32;\n\nexport class ProtocolValidationError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"ProtocolValidationError\";\n\t}\n}\n\nfunction record(value: unknown, path: string): Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new ProtocolValidationError(`${path} must be an object`);\n\t}\n\treturn value as Record<string, unknown>;\n}\n\nfunction string(value: unknown, path: string): string {\n\tif (typeof value !== \"string\" || value.trim().length === 0) {\n\t\tthrow new ProtocolValidationError(`${path} must be a non-empty string`);\n\t}\n\treturn value;\n}\n\nfunction timestamp(value: unknown, path: string): string {\n\tconst parsed = string(value, path);\n\tif (!ISO_TIMESTAMP.test(parsed) || Number.isNaN(Date.parse(parsed))) {\n\t\tthrow new ProtocolValidationError(`${path} must be an ISO 8601 UTC timestamp`);\n\t}\n\treturn parsed;\n}\n\nfunction version(value: Record<string, unknown>, path: string): void {\n\tif (value.schemaVersion !== PROTOCOL_VERSION) {\n\t\tthrow new ProtocolValidationError(`${path}.schemaVersion must be ${PROTOCOL_VERSION}`);\n\t}\n}\n\nfunction stringArray(value: unknown, path: string): readonly string[] {\n\tif (!Array.isArray(value)) throw new ProtocolValidationError(`${path} must be an array`);\n\treturn value.map((item, index) => string(item, `${path}[${index}]`));\n}\n\nfunction jsonValue(value: unknown, path: string, depth = 0): asserts value is JsonValue {\n\tif (depth > MAX_CONDITION_DEPTH) throw new ProtocolValidationError(`${path} exceeds maximum nesting depth`);\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return;\n\tif (typeof value === \"number\" && Number.isFinite(value)) return;\n\tif (Array.isArray(value)) {\n\t\tvalue.forEach((item, index) => {\n\t\t\tjsonValue(item, `${path}[${index}]`, depth + 1);\n\t\t});\n\t\treturn;\n\t}\n\tconst object = record(value, path);\n\tfor (const [key, item] of Object.entries(object)) jsonValue(item, `${path}.${key}`, depth + 1);\n}\n\nfunction jsonObject(value: unknown, path: string): asserts value is JsonObject {\n\trecord(value, path);\n\tjsonValue(value, path);\n}\n\nfunction condition(value: unknown, path: string, depth = 0): asserts value is ClaimCondition {\n\tif (depth > MAX_CONDITION_DEPTH) throw new ProtocolValidationError(`${path} exceeds maximum nesting depth`);\n\tconst input = record(value, path);\n\tswitch (input.kind) {\n\t\tcase \"observation\":\n\t\t\tstring(input.observationKind, `${path}.observationKind`);\n\t\t\tif (input.scope !== \"attempt\" && input.scope !== \"task\") {\n\t\t\t\tthrow new ProtocolValidationError(`${path}.scope must be attempt or task`);\n\t\t\t}\n\t\t\tjsonObject(input.facts, `${path}.facts`);\n\t\t\tif (input.bindToCandidate !== undefined && typeof input.bindToCandidate !== \"boolean\") {\n\t\t\t\tthrow new ProtocolValidationError(`${path}.bindToCandidate must be a boolean`);\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"all\":\n\t\tcase \"any\":\n\t\t\tif (!Array.isArray(input.conditions) || input.conditions.length === 0) {\n\t\t\t\tthrow new ProtocolValidationError(`${path}.conditions must be a non-empty array`);\n\t\t\t}\n\t\t\tinput.conditions.forEach((item, index) => {\n\t\t\t\tcondition(item, `${path}.conditions[${index}]`, depth + 1);\n\t\t\t});\n\t\t\treturn;\n\t\tcase \"not\":\n\t\t\tcondition(input.condition, `${path}.condition`, depth + 1);\n\t\t\treturn;\n\t\tdefault:\n\t\t\tthrow new ProtocolValidationError(`${path}.kind is unsupported`);\n\t}\n}\n\nexport function parseTaskSpec(value: unknown): TaskSpec {\n\tconst input = record(value, \"taskSpec\");\n\tversion(input, \"taskSpec\");\n\tstring(input.taskId, \"taskSpec.taskId\");\n\tstring(input.goal, \"taskSpec.goal\");\n\ttimestamp(input.createdAt, \"taskSpec.createdAt\");\n\tif (!Array.isArray(input.claims)) throw new ProtocolValidationError(\"taskSpec.claims must be an array\");\n\tconst claimIds = new Set<string>();\n\tfor (const [index, rawClaim] of input.claims.entries()) {\n\t\tconst claim = record(rawClaim, `taskSpec.claims[${index}]`);\n\t\tconst claimId = string(claim.claimId, `taskSpec.claims[${index}].claimId`);\n\t\tif (claimIds.has(claimId)) throw new ProtocolValidationError(`duplicate claimId ${claimId}`);\n\t\tclaimIds.add(claimId);\n\t\tstring(claim.statement, `taskSpec.claims[${index}].statement`);\n\t\tif (claim.requirement !== \"required\" && claim.requirement !== \"advisory\") {\n\t\t\tthrow new ProtocolValidationError(`taskSpec.claims[${index}].requirement is unsupported`);\n\t\t}\n\t\tcondition(claim.condition, `taskSpec.claims[${index}].condition`);\n\t}\n\treturn value as TaskSpec;\n}\n\nexport function parseExecutionAttempt(value: unknown): ExecutionAttempt {\n\tconst input = record(value, \"attempt\");\n\tversion(input, \"attempt\");\n\tstring(input.attemptId, \"attempt.attemptId\");\n\tstring(input.taskId, \"attempt.taskId\");\n\tif (!Number.isSafeInteger(input.sequence) || (input.sequence as number) < 1) {\n\t\tthrow new ProtocolValidationError(\"attempt.sequence must be a positive integer\");\n\t}\n\tif (![\"initial\", \"retry\", \"failover\", \"resume\"].includes(input.trigger as string)) {\n\t\tthrow new ProtocolValidationError(\"attempt.trigger is unsupported\");\n\t}\n\tif (input.previousAttemptId !== undefined) string(input.previousAttemptId, \"attempt.previousAttemptId\");\n\tconst startedAt = timestamp(input.startedAt, \"attempt.startedAt\");\n\tconst finishedAt = timestamp(input.finishedAt, \"attempt.finishedAt\");\n\tif (finishedAt < startedAt) throw new ProtocolValidationError(\"attempt.finishedAt precedes startedAt\");\n\tconst executor = record(input.executor, \"attempt.executor\");\n\tstring(executor.kind, \"attempt.executor.kind\");\n\tif (executor.provider !== undefined) string(executor.provider, \"attempt.executor.provider\");\n\tif (executor.model !== undefined) string(executor.model, \"attempt.executor.model\");\n\tconst outcome = record(input.outcome, \"attempt.outcome\");\n\tif (outcome.kind === \"failed\") {\n\t\tstring(outcome.code, \"attempt.outcome.code\");\n\t\tif (outcome.message !== undefined) string(outcome.message, \"attempt.outcome.message\");\n\t} else if (outcome.kind === \"cancelled\") {\n\t\tstring(outcome.code, \"attempt.outcome.code\");\n\t} else if (outcome.kind !== \"completed\") {\n\t\tthrow new ProtocolValidationError(\"attempt.outcome.kind is unsupported\");\n\t}\n\tif (input.candidateHash !== undefined) string(input.candidateHash, \"attempt.candidateHash\");\n\treturn value as ExecutionAttempt;\n}\n\nexport function parseObservation(value: unknown): Observation {\n\tconst input = record(value, \"observation\");\n\tversion(input, \"observation\");\n\tstring(input.observationId, \"observation.observationId\");\n\tstring(input.taskId, \"observation.taskId\");\n\tstring(input.attemptId, \"observation.attemptId\");\n\ttimestamp(input.observedAt, \"observation.observedAt\");\n\tstring(input.kind, \"observation.kind\");\n\tconst source = record(input.source, \"observation.source\");\n\tstring(source.kind, \"observation.source.kind\");\n\tstring(source.id, \"observation.source.id\");\n\tjsonObject(input.facts, \"observation.facts\");\n\tstringArray(input.evidenceRefs, \"observation.evidenceRefs\");\n\treturn value as Observation;\n}\n\nexport function parseWaiverRecord(value: unknown): WaiverRecord {\n\tconst input = record(value, \"waiver\");\n\tversion(input, \"waiver\");\n\tstring(input.waiverId, \"waiver.waiverId\");\n\tconst scope = record(input.scope, \"waiver.scope\");\n\tstring(scope.taskId, \"waiver.scope.taskId\");\n\tstring(scope.claimId, \"waiver.scope.claimId\");\n\tif (scope.attemptId !== undefined) string(scope.attemptId, \"waiver.scope.attemptId\");\n\tstring(input.approvedBy, \"waiver.approvedBy\");\n\ttimestamp(input.approvedAt, \"waiver.approvedAt\");\n\tif (input.expiresAt !== undefined) timestamp(input.expiresAt, \"waiver.expiresAt\");\n\tstring(input.rationale, \"waiver.rationale\");\n\tstringArray(input.evidenceRefs, \"waiver.evidenceRefs\");\n\treturn value as WaiverRecord;\n}\n\nexport function parseEvaluationResult(value: unknown): EvaluationResult {\n\tconst input = record(value, \"evaluation\");\n\tversion(input, \"evaluation\");\n\tstring(input.evaluationId, \"evaluation.evaluationId\");\n\tstring(input.taskId, \"evaluation.taskId\");\n\tstring(input.attemptId, \"evaluation.attemptId\");\n\ttimestamp(input.evaluatedAt, \"evaluation.evaluatedAt\");\n\tif (!Array.isArray(input.claims)) throw new ProtocolValidationError(\"evaluation.claims must be an array\");\n\tfor (const [index, rawClaim] of input.claims.entries()) {\n\t\tconst claim = record(rawClaim, `evaluation.claims[${index}]`);\n\t\tstring(claim.claimId, `evaluation.claims[${index}].claimId`);\n\t\tif (claim.requirement !== \"required\" && claim.requirement !== \"advisory\") {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].requirement is unsupported`);\n\t\t}\n\t\tif (![\"satisfied\", \"violated\", \"inconclusive\"].includes(claim.result as string)) {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].result is unsupported`);\n\t\t}\n\t\tif (![\"claim.satisfied\", \"claim.violated\", \"claim.observation_missing\"].includes(claim.reasonCode as string)) {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].reasonCode is unsupported`);\n\t\t}\n\t\tstringArray(claim.observationIds, `evaluation.claims[${index}].observationIds`);\n\t\tif (claim.waiverId !== undefined) string(claim.waiverId, `evaluation.claims[${index}].waiverId`);\n\t}\n\tif (![\"pass\", \"fail\", \"inconclusive\"].includes(input.semanticVerdict as string)) {\n\t\tthrow new ProtocolValidationError(\"evaluation.semanticVerdict is unsupported\");\n\t}\n\treturn value as EvaluationResult;\n}\n\nexport function parseRuntimeDecision(value: unknown): RuntimeDecision {\n\tconst input = record(value, \"decision\");\n\tversion(input, \"decision\");\n\tstring(input.decisionId, \"decision.decisionId\");\n\tstring(input.taskId, \"decision.taskId\");\n\tstring(input.attemptId, \"decision.attemptId\");\n\tstring(input.evaluationId, \"decision.evaluationId\");\n\ttimestamp(input.decidedAt, \"decision.decidedAt\");\n\tif (![\"continue\", \"retry\", \"failover\", \"stop\"].includes(input.action as string)) {\n\t\tthrow new ProtocolValidationError(\"decision.action is unsupported\");\n\t}\n\tif (![\"evaluation.pass\", \"evaluation.fail\", \"evaluation.inconclusive\"].includes(input.reasonCode as string)) {\n\t\tthrow new ProtocolValidationError(\"decision.reasonCode is unsupported\");\n\t}\n\treturn value as RuntimeDecision;\n}\n"]}
|
package/dist/validation.js
CHANGED
|
@@ -68,6 +68,9 @@ function condition(value, path, depth = 0) {
|
|
|
68
68
|
throw new ProtocolValidationError(`${path}.scope must be attempt or task`);
|
|
69
69
|
}
|
|
70
70
|
jsonObject(input.facts, `${path}.facts`);
|
|
71
|
+
if (input.bindToCandidate !== undefined && typeof input.bindToCandidate !== "boolean") {
|
|
72
|
+
throw new ProtocolValidationError(`${path}.bindToCandidate must be a boolean`);
|
|
73
|
+
}
|
|
71
74
|
return;
|
|
72
75
|
case "all":
|
|
73
76
|
case "any":
|
|
@@ -143,6 +146,8 @@ export function parseExecutionAttempt(value) {
|
|
|
143
146
|
else if (outcome.kind !== "completed") {
|
|
144
147
|
throw new ProtocolValidationError("attempt.outcome.kind is unsupported");
|
|
145
148
|
}
|
|
149
|
+
if (input.candidateHash !== undefined)
|
|
150
|
+
string(input.candidateHash, "attempt.candidateHash");
|
|
146
151
|
return value;
|
|
147
152
|
}
|
|
148
153
|
export function parseObservation(value) {
|
package/dist/validation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,gBAAgB,GAIhB,MAAM,YAAY,CAAC;AAEpB,MAAM,aAAa,GAAG,+CAA+C,CAAC;AACtE,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACjD,YAAY,OAAe,EAAE;QAC5B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IAAA,CACtC;CACD;AAED,SAAS,MAAM,CAAC,KAAc,EAAE,IAAY,EAA2B;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ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ACjD,IAAI,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAgB,CAAC,EAAE,CAAC;QACjF,MAAM,IAAI,uBAAuB,CAAC,gCAAgC,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,CAAC,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,yBAAyB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAoB,CAAC,EAAE,CAAC;QAC7G,MAAM,IAAI,uBAAuB,CAAC,oCAAoC,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,KAAwB,CAAC;AAAA,CAChC","sourcesContent":["import {\n\ttype ClaimCondition,\n\ttype EvaluationResult,\n\ttype ExecutionAttempt,\n\ttype JsonObject,\n\ttype JsonValue,\n\ttype Observation,\n\tPROTOCOL_VERSION,\n\ttype RuntimeDecision,\n\ttype TaskSpec,\n\ttype WaiverRecord,\n} from \"./types.ts\";\n\nconst ISO_TIMESTAMP = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/;\nconst MAX_CONDITION_DEPTH = 32;\n\nexport class ProtocolValidationError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"ProtocolValidationError\";\n\t}\n}\n\nfunction record(value: unknown, path: string): Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new ProtocolValidationError(`${path} must be an object`);\n\t}\n\treturn value as Record<string, unknown>;\n}\n\nfunction string(value: unknown, path: string): string {\n\tif (typeof value !== \"string\" || value.trim().length === 0) {\n\t\tthrow new ProtocolValidationError(`${path} must be a non-empty string`);\n\t}\n\treturn value;\n}\n\nfunction timestamp(value: unknown, path: string): string {\n\tconst parsed = string(value, path);\n\tif (!ISO_TIMESTAMP.test(parsed) || Number.isNaN(Date.parse(parsed))) {\n\t\tthrow new ProtocolValidationError(`${path} must be an ISO 8601 UTC timestamp`);\n\t}\n\treturn parsed;\n}\n\nfunction version(value: Record<string, unknown>, path: string): void {\n\tif (value.schemaVersion !== PROTOCOL_VERSION) {\n\t\tthrow new ProtocolValidationError(`${path}.schemaVersion must be ${PROTOCOL_VERSION}`);\n\t}\n}\n\nfunction stringArray(value: unknown, path: string): readonly string[] {\n\tif (!Array.isArray(value)) throw new ProtocolValidationError(`${path} must be an array`);\n\treturn value.map((item, index) => string(item, `${path}[${index}]`));\n}\n\nfunction jsonValue(value: unknown, path: string, depth = 0): asserts value is JsonValue {\n\tif (depth > MAX_CONDITION_DEPTH) throw new ProtocolValidationError(`${path} exceeds maximum nesting depth`);\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return;\n\tif (typeof value === \"number\" && Number.isFinite(value)) return;\n\tif (Array.isArray(value)) {\n\t\tvalue.forEach((item, index) => {\n\t\t\tjsonValue(item, `${path}[${index}]`, depth + 1);\n\t\t});\n\t\treturn;\n\t}\n\tconst object = record(value, path);\n\tfor (const [key, item] of Object.entries(object)) jsonValue(item, `${path}.${key}`, depth + 1);\n}\n\nfunction jsonObject(value: unknown, path: string): asserts value is JsonObject {\n\trecord(value, path);\n\tjsonValue(value, path);\n}\n\nfunction condition(value: unknown, path: string, depth = 0): asserts value is ClaimCondition {\n\tif (depth > MAX_CONDITION_DEPTH) throw new ProtocolValidationError(`${path} exceeds maximum nesting depth`);\n\tconst input = record(value, path);\n\tswitch (input.kind) {\n\t\tcase \"observation\":\n\t\t\tstring(input.observationKind, `${path}.observationKind`);\n\t\t\tif (input.scope !== \"attempt\" && input.scope !== \"task\") {\n\t\t\t\tthrow new ProtocolValidationError(`${path}.scope must be attempt or task`);\n\t\t\t}\n\t\t\tjsonObject(input.facts, `${path}.facts`);\n\t\t\treturn;\n\t\tcase \"all\":\n\t\tcase \"any\":\n\t\t\tif (!Array.isArray(input.conditions) || input.conditions.length === 0) {\n\t\t\t\tthrow new ProtocolValidationError(`${path}.conditions must be a non-empty array`);\n\t\t\t}\n\t\t\tinput.conditions.forEach((item, index) => {\n\t\t\t\tcondition(item, `${path}.conditions[${index}]`, depth + 1);\n\t\t\t});\n\t\t\treturn;\n\t\tcase \"not\":\n\t\t\tcondition(input.condition, `${path}.condition`, depth + 1);\n\t\t\treturn;\n\t\tdefault:\n\t\t\tthrow new ProtocolValidationError(`${path}.kind is unsupported`);\n\t}\n}\n\nexport function parseTaskSpec(value: unknown): TaskSpec {\n\tconst input = record(value, \"taskSpec\");\n\tversion(input, \"taskSpec\");\n\tstring(input.taskId, \"taskSpec.taskId\");\n\tstring(input.goal, \"taskSpec.goal\");\n\ttimestamp(input.createdAt, \"taskSpec.createdAt\");\n\tif (!Array.isArray(input.claims)) throw new ProtocolValidationError(\"taskSpec.claims must be an array\");\n\tconst claimIds = new Set<string>();\n\tfor (const [index, rawClaim] of input.claims.entries()) {\n\t\tconst claim = record(rawClaim, `taskSpec.claims[${index}]`);\n\t\tconst claimId = string(claim.claimId, `taskSpec.claims[${index}].claimId`);\n\t\tif (claimIds.has(claimId)) throw new ProtocolValidationError(`duplicate claimId ${claimId}`);\n\t\tclaimIds.add(claimId);\n\t\tstring(claim.statement, `taskSpec.claims[${index}].statement`);\n\t\tif (claim.requirement !== \"required\" && claim.requirement !== \"advisory\") {\n\t\t\tthrow new ProtocolValidationError(`taskSpec.claims[${index}].requirement is unsupported`);\n\t\t}\n\t\tcondition(claim.condition, `taskSpec.claims[${index}].condition`);\n\t}\n\treturn value as TaskSpec;\n}\n\nexport function parseExecutionAttempt(value: unknown): ExecutionAttempt {\n\tconst input = record(value, \"attempt\");\n\tversion(input, \"attempt\");\n\tstring(input.attemptId, \"attempt.attemptId\");\n\tstring(input.taskId, \"attempt.taskId\");\n\tif (!Number.isSafeInteger(input.sequence) || (input.sequence as number) < 1) {\n\t\tthrow new ProtocolValidationError(\"attempt.sequence must be a positive integer\");\n\t}\n\tif (![\"initial\", \"retry\", \"failover\", \"resume\"].includes(input.trigger as string)) {\n\t\tthrow new ProtocolValidationError(\"attempt.trigger is unsupported\");\n\t}\n\tif (input.previousAttemptId !== undefined) string(input.previousAttemptId, \"attempt.previousAttemptId\");\n\tconst startedAt = timestamp(input.startedAt, \"attempt.startedAt\");\n\tconst finishedAt = timestamp(input.finishedAt, \"attempt.finishedAt\");\n\tif (finishedAt < startedAt) throw new ProtocolValidationError(\"attempt.finishedAt precedes startedAt\");\n\tconst executor = record(input.executor, \"attempt.executor\");\n\tstring(executor.kind, \"attempt.executor.kind\");\n\tif (executor.provider !== undefined) string(executor.provider, \"attempt.executor.provider\");\n\tif (executor.model !== undefined) string(executor.model, \"attempt.executor.model\");\n\tconst outcome = record(input.outcome, \"attempt.outcome\");\n\tif (outcome.kind === \"failed\") {\n\t\tstring(outcome.code, \"attempt.outcome.code\");\n\t\tif (outcome.message !== undefined) string(outcome.message, \"attempt.outcome.message\");\n\t} else if (outcome.kind === \"cancelled\") {\n\t\tstring(outcome.code, \"attempt.outcome.code\");\n\t} else if (outcome.kind !== \"completed\") {\n\t\tthrow new ProtocolValidationError(\"attempt.outcome.kind is unsupported\");\n\t}\n\treturn value as ExecutionAttempt;\n}\n\nexport function parseObservation(value: unknown): Observation {\n\tconst input = record(value, \"observation\");\n\tversion(input, \"observation\");\n\tstring(input.observationId, \"observation.observationId\");\n\tstring(input.taskId, \"observation.taskId\");\n\tstring(input.attemptId, \"observation.attemptId\");\n\ttimestamp(input.observedAt, \"observation.observedAt\");\n\tstring(input.kind, \"observation.kind\");\n\tconst source = record(input.source, \"observation.source\");\n\tstring(source.kind, \"observation.source.kind\");\n\tstring(source.id, \"observation.source.id\");\n\tjsonObject(input.facts, \"observation.facts\");\n\tstringArray(input.evidenceRefs, \"observation.evidenceRefs\");\n\treturn value as Observation;\n}\n\nexport function parseWaiverRecord(value: unknown): WaiverRecord {\n\tconst input = record(value, \"waiver\");\n\tversion(input, \"waiver\");\n\tstring(input.waiverId, \"waiver.waiverId\");\n\tconst scope = record(input.scope, \"waiver.scope\");\n\tstring(scope.taskId, \"waiver.scope.taskId\");\n\tstring(scope.claimId, \"waiver.scope.claimId\");\n\tif (scope.attemptId !== undefined) string(scope.attemptId, \"waiver.scope.attemptId\");\n\tstring(input.approvedBy, \"waiver.approvedBy\");\n\ttimestamp(input.approvedAt, \"waiver.approvedAt\");\n\tif (input.expiresAt !== undefined) timestamp(input.expiresAt, \"waiver.expiresAt\");\n\tstring(input.rationale, \"waiver.rationale\");\n\tstringArray(input.evidenceRefs, \"waiver.evidenceRefs\");\n\treturn value as WaiverRecord;\n}\n\nexport function parseEvaluationResult(value: unknown): EvaluationResult {\n\tconst input = record(value, \"evaluation\");\n\tversion(input, \"evaluation\");\n\tstring(input.evaluationId, \"evaluation.evaluationId\");\n\tstring(input.taskId, \"evaluation.taskId\");\n\tstring(input.attemptId, \"evaluation.attemptId\");\n\ttimestamp(input.evaluatedAt, \"evaluation.evaluatedAt\");\n\tif (!Array.isArray(input.claims)) throw new ProtocolValidationError(\"evaluation.claims must be an array\");\n\tfor (const [index, rawClaim] of input.claims.entries()) {\n\t\tconst claim = record(rawClaim, `evaluation.claims[${index}]`);\n\t\tstring(claim.claimId, `evaluation.claims[${index}].claimId`);\n\t\tif (claim.requirement !== \"required\" && claim.requirement !== \"advisory\") {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].requirement is unsupported`);\n\t\t}\n\t\tif (![\"satisfied\", \"violated\", \"inconclusive\"].includes(claim.result as string)) {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].result is unsupported`);\n\t\t}\n\t\tif (![\"claim.satisfied\", \"claim.violated\", \"claim.observation_missing\"].includes(claim.reasonCode as string)) {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].reasonCode is unsupported`);\n\t\t}\n\t\tstringArray(claim.observationIds, `evaluation.claims[${index}].observationIds`);\n\t\tif (claim.waiverId !== undefined) string(claim.waiverId, `evaluation.claims[${index}].waiverId`);\n\t}\n\tif (![\"pass\", \"fail\", \"inconclusive\"].includes(input.semanticVerdict as string)) {\n\t\tthrow new ProtocolValidationError(\"evaluation.semanticVerdict is unsupported\");\n\t}\n\treturn value as EvaluationResult;\n}\n\nexport function parseRuntimeDecision(value: unknown): RuntimeDecision {\n\tconst input = record(value, \"decision\");\n\tversion(input, \"decision\");\n\tstring(input.decisionId, \"decision.decisionId\");\n\tstring(input.taskId, \"decision.taskId\");\n\tstring(input.attemptId, \"decision.attemptId\");\n\tstring(input.evaluationId, \"decision.evaluationId\");\n\ttimestamp(input.decidedAt, \"decision.decidedAt\");\n\tif (![\"continue\", \"retry\", \"failover\", \"stop\"].includes(input.action as string)) {\n\t\tthrow new ProtocolValidationError(\"decision.action is unsupported\");\n\t}\n\tif (![\"evaluation.pass\", \"evaluation.fail\", \"evaluation.inconclusive\"].includes(input.reasonCode as string)) {\n\t\tthrow new ProtocolValidationError(\"decision.reasonCode is unsupported\");\n\t}\n\treturn value as RuntimeDecision;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,gBAAgB,GAIhB,MAAM,YAAY,CAAC;AAEpB,MAAM,aAAa,GAAG,+CAA+C,CAAC;AACtE,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACjD,YAAY,OAAe,EAAE;QAC5B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IAAA,CACtC;CACD;AAED,SAAS,MAAM,CAAC,KAAc,EAAE,IAAY,EAA2B;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzE,MAAM,IAAI,uBAAuB,CAAC,GAAG,IAAI,oBAAoB,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,KAAgC,CAAC;AAAA,CACxC;AAED,SAAS,MAAM,CAA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;IACpD,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;IACjD,IAAI,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAgB,CAAC,EAAE,CAAC;QACjF,MAAM,IAAI,uBAAuB,CAAC,gCAAgC,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,CAAC,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,yBAAyB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAoB,CAAC,EAAE,CAAC;QAC7G,MAAM,IAAI,uBAAuB,CAAC,oCAAoC,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,KAAwB,CAAC;AAAA,CAChC","sourcesContent":["import {\n\ttype ClaimCondition,\n\ttype EvaluationResult,\n\ttype ExecutionAttempt,\n\ttype JsonObject,\n\ttype JsonValue,\n\ttype Observation,\n\tPROTOCOL_VERSION,\n\ttype RuntimeDecision,\n\ttype TaskSpec,\n\ttype WaiverRecord,\n} from \"./types.ts\";\n\nconst ISO_TIMESTAMP = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/;\nconst MAX_CONDITION_DEPTH = 32;\n\nexport class ProtocolValidationError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"ProtocolValidationError\";\n\t}\n}\n\nfunction record(value: unknown, path: string): Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new ProtocolValidationError(`${path} must be an object`);\n\t}\n\treturn value as Record<string, unknown>;\n}\n\nfunction string(value: unknown, path: string): string {\n\tif (typeof value !== \"string\" || value.trim().length === 0) {\n\t\tthrow new ProtocolValidationError(`${path} must be a non-empty string`);\n\t}\n\treturn value;\n}\n\nfunction timestamp(value: unknown, path: string): string {\n\tconst parsed = string(value, path);\n\tif (!ISO_TIMESTAMP.test(parsed) || Number.isNaN(Date.parse(parsed))) {\n\t\tthrow new ProtocolValidationError(`${path} must be an ISO 8601 UTC timestamp`);\n\t}\n\treturn parsed;\n}\n\nfunction version(value: Record<string, unknown>, path: string): void {\n\tif (value.schemaVersion !== PROTOCOL_VERSION) {\n\t\tthrow new ProtocolValidationError(`${path}.schemaVersion must be ${PROTOCOL_VERSION}`);\n\t}\n}\n\nfunction stringArray(value: unknown, path: string): readonly string[] {\n\tif (!Array.isArray(value)) throw new ProtocolValidationError(`${path} must be an array`);\n\treturn value.map((item, index) => string(item, `${path}[${index}]`));\n}\n\nfunction jsonValue(value: unknown, path: string, depth = 0): asserts value is JsonValue {\n\tif (depth > MAX_CONDITION_DEPTH) throw new ProtocolValidationError(`${path} exceeds maximum nesting depth`);\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return;\n\tif (typeof value === \"number\" && Number.isFinite(value)) return;\n\tif (Array.isArray(value)) {\n\t\tvalue.forEach((item, index) => {\n\t\t\tjsonValue(item, `${path}[${index}]`, depth + 1);\n\t\t});\n\t\treturn;\n\t}\n\tconst object = record(value, path);\n\tfor (const [key, item] of Object.entries(object)) jsonValue(item, `${path}.${key}`, depth + 1);\n}\n\nfunction jsonObject(value: unknown, path: string): asserts value is JsonObject {\n\trecord(value, path);\n\tjsonValue(value, path);\n}\n\nfunction condition(value: unknown, path: string, depth = 0): asserts value is ClaimCondition {\n\tif (depth > MAX_CONDITION_DEPTH) throw new ProtocolValidationError(`${path} exceeds maximum nesting depth`);\n\tconst input = record(value, path);\n\tswitch (input.kind) {\n\t\tcase \"observation\":\n\t\t\tstring(input.observationKind, `${path}.observationKind`);\n\t\t\tif (input.scope !== \"attempt\" && input.scope !== \"task\") {\n\t\t\t\tthrow new ProtocolValidationError(`${path}.scope must be attempt or task`);\n\t\t\t}\n\t\t\tjsonObject(input.facts, `${path}.facts`);\n\t\t\tif (input.bindToCandidate !== undefined && typeof input.bindToCandidate !== \"boolean\") {\n\t\t\t\tthrow new ProtocolValidationError(`${path}.bindToCandidate must be a boolean`);\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"all\":\n\t\tcase \"any\":\n\t\t\tif (!Array.isArray(input.conditions) || input.conditions.length === 0) {\n\t\t\t\tthrow new ProtocolValidationError(`${path}.conditions must be a non-empty array`);\n\t\t\t}\n\t\t\tinput.conditions.forEach((item, index) => {\n\t\t\t\tcondition(item, `${path}.conditions[${index}]`, depth + 1);\n\t\t\t});\n\t\t\treturn;\n\t\tcase \"not\":\n\t\t\tcondition(input.condition, `${path}.condition`, depth + 1);\n\t\t\treturn;\n\t\tdefault:\n\t\t\tthrow new ProtocolValidationError(`${path}.kind is unsupported`);\n\t}\n}\n\nexport function parseTaskSpec(value: unknown): TaskSpec {\n\tconst input = record(value, \"taskSpec\");\n\tversion(input, \"taskSpec\");\n\tstring(input.taskId, \"taskSpec.taskId\");\n\tstring(input.goal, \"taskSpec.goal\");\n\ttimestamp(input.createdAt, \"taskSpec.createdAt\");\n\tif (!Array.isArray(input.claims)) throw new ProtocolValidationError(\"taskSpec.claims must be an array\");\n\tconst claimIds = new Set<string>();\n\tfor (const [index, rawClaim] of input.claims.entries()) {\n\t\tconst claim = record(rawClaim, `taskSpec.claims[${index}]`);\n\t\tconst claimId = string(claim.claimId, `taskSpec.claims[${index}].claimId`);\n\t\tif (claimIds.has(claimId)) throw new ProtocolValidationError(`duplicate claimId ${claimId}`);\n\t\tclaimIds.add(claimId);\n\t\tstring(claim.statement, `taskSpec.claims[${index}].statement`);\n\t\tif (claim.requirement !== \"required\" && claim.requirement !== \"advisory\") {\n\t\t\tthrow new ProtocolValidationError(`taskSpec.claims[${index}].requirement is unsupported`);\n\t\t}\n\t\tcondition(claim.condition, `taskSpec.claims[${index}].condition`);\n\t}\n\treturn value as TaskSpec;\n}\n\nexport function parseExecutionAttempt(value: unknown): ExecutionAttempt {\n\tconst input = record(value, \"attempt\");\n\tversion(input, \"attempt\");\n\tstring(input.attemptId, \"attempt.attemptId\");\n\tstring(input.taskId, \"attempt.taskId\");\n\tif (!Number.isSafeInteger(input.sequence) || (input.sequence as number) < 1) {\n\t\tthrow new ProtocolValidationError(\"attempt.sequence must be a positive integer\");\n\t}\n\tif (![\"initial\", \"retry\", \"failover\", \"resume\"].includes(input.trigger as string)) {\n\t\tthrow new ProtocolValidationError(\"attempt.trigger is unsupported\");\n\t}\n\tif (input.previousAttemptId !== undefined) string(input.previousAttemptId, \"attempt.previousAttemptId\");\n\tconst startedAt = timestamp(input.startedAt, \"attempt.startedAt\");\n\tconst finishedAt = timestamp(input.finishedAt, \"attempt.finishedAt\");\n\tif (finishedAt < startedAt) throw new ProtocolValidationError(\"attempt.finishedAt precedes startedAt\");\n\tconst executor = record(input.executor, \"attempt.executor\");\n\tstring(executor.kind, \"attempt.executor.kind\");\n\tif (executor.provider !== undefined) string(executor.provider, \"attempt.executor.provider\");\n\tif (executor.model !== undefined) string(executor.model, \"attempt.executor.model\");\n\tconst outcome = record(input.outcome, \"attempt.outcome\");\n\tif (outcome.kind === \"failed\") {\n\t\tstring(outcome.code, \"attempt.outcome.code\");\n\t\tif (outcome.message !== undefined) string(outcome.message, \"attempt.outcome.message\");\n\t} else if (outcome.kind === \"cancelled\") {\n\t\tstring(outcome.code, \"attempt.outcome.code\");\n\t} else if (outcome.kind !== \"completed\") {\n\t\tthrow new ProtocolValidationError(\"attempt.outcome.kind is unsupported\");\n\t}\n\tif (input.candidateHash !== undefined) string(input.candidateHash, \"attempt.candidateHash\");\n\treturn value as ExecutionAttempt;\n}\n\nexport function parseObservation(value: unknown): Observation {\n\tconst input = record(value, \"observation\");\n\tversion(input, \"observation\");\n\tstring(input.observationId, \"observation.observationId\");\n\tstring(input.taskId, \"observation.taskId\");\n\tstring(input.attemptId, \"observation.attemptId\");\n\ttimestamp(input.observedAt, \"observation.observedAt\");\n\tstring(input.kind, \"observation.kind\");\n\tconst source = record(input.source, \"observation.source\");\n\tstring(source.kind, \"observation.source.kind\");\n\tstring(source.id, \"observation.source.id\");\n\tjsonObject(input.facts, \"observation.facts\");\n\tstringArray(input.evidenceRefs, \"observation.evidenceRefs\");\n\treturn value as Observation;\n}\n\nexport function parseWaiverRecord(value: unknown): WaiverRecord {\n\tconst input = record(value, \"waiver\");\n\tversion(input, \"waiver\");\n\tstring(input.waiverId, \"waiver.waiverId\");\n\tconst scope = record(input.scope, \"waiver.scope\");\n\tstring(scope.taskId, \"waiver.scope.taskId\");\n\tstring(scope.claimId, \"waiver.scope.claimId\");\n\tif (scope.attemptId !== undefined) string(scope.attemptId, \"waiver.scope.attemptId\");\n\tstring(input.approvedBy, \"waiver.approvedBy\");\n\ttimestamp(input.approvedAt, \"waiver.approvedAt\");\n\tif (input.expiresAt !== undefined) timestamp(input.expiresAt, \"waiver.expiresAt\");\n\tstring(input.rationale, \"waiver.rationale\");\n\tstringArray(input.evidenceRefs, \"waiver.evidenceRefs\");\n\treturn value as WaiverRecord;\n}\n\nexport function parseEvaluationResult(value: unknown): EvaluationResult {\n\tconst input = record(value, \"evaluation\");\n\tversion(input, \"evaluation\");\n\tstring(input.evaluationId, \"evaluation.evaluationId\");\n\tstring(input.taskId, \"evaluation.taskId\");\n\tstring(input.attemptId, \"evaluation.attemptId\");\n\ttimestamp(input.evaluatedAt, \"evaluation.evaluatedAt\");\n\tif (!Array.isArray(input.claims)) throw new ProtocolValidationError(\"evaluation.claims must be an array\");\n\tfor (const [index, rawClaim] of input.claims.entries()) {\n\t\tconst claim = record(rawClaim, `evaluation.claims[${index}]`);\n\t\tstring(claim.claimId, `evaluation.claims[${index}].claimId`);\n\t\tif (claim.requirement !== \"required\" && claim.requirement !== \"advisory\") {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].requirement is unsupported`);\n\t\t}\n\t\tif (![\"satisfied\", \"violated\", \"inconclusive\"].includes(claim.result as string)) {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].result is unsupported`);\n\t\t}\n\t\tif (![\"claim.satisfied\", \"claim.violated\", \"claim.observation_missing\"].includes(claim.reasonCode as string)) {\n\t\t\tthrow new ProtocolValidationError(`evaluation.claims[${index}].reasonCode is unsupported`);\n\t\t}\n\t\tstringArray(claim.observationIds, `evaluation.claims[${index}].observationIds`);\n\t\tif (claim.waiverId !== undefined) string(claim.waiverId, `evaluation.claims[${index}].waiverId`);\n\t}\n\tif (![\"pass\", \"fail\", \"inconclusive\"].includes(input.semanticVerdict as string)) {\n\t\tthrow new ProtocolValidationError(\"evaluation.semanticVerdict is unsupported\");\n\t}\n\treturn value as EvaluationResult;\n}\n\nexport function parseRuntimeDecision(value: unknown): RuntimeDecision {\n\tconst input = record(value, \"decision\");\n\tversion(input, \"decision\");\n\tstring(input.decisionId, \"decision.decisionId\");\n\tstring(input.taskId, \"decision.taskId\");\n\tstring(input.attemptId, \"decision.attemptId\");\n\tstring(input.evaluationId, \"decision.evaluationId\");\n\ttimestamp(input.decidedAt, \"decision.decidedAt\");\n\tif (![\"continue\", \"retry\", \"failover\", \"stop\"].includes(input.action as string)) {\n\t\tthrow new ProtocolValidationError(\"decision.action is unsupported\");\n\t}\n\tif (![\"evaluation.pass\", \"evaluation.fail\", \"evaluation.inconclusive\"].includes(input.reasonCode as string)) {\n\t\tthrow new ProtocolValidationError(\"decision.reasonCode is unsupported\");\n\t}\n\treturn value as RuntimeDecision;\n}\n"]}
|