iterate-kernel 0.1.0-draft.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +56 -0
  2. package/dist/canonical-json.d.ts +21 -0
  3. package/dist/canonical-json.d.ts.map +1 -0
  4. package/dist/canonical-json.js +31 -0
  5. package/dist/canonical-json.js.map +1 -0
  6. package/dist/decision-log-entry.d.ts +34 -0
  7. package/dist/decision-log-entry.d.ts.map +1 -0
  8. package/dist/decision-log-entry.js +17 -0
  9. package/dist/decision-log-entry.js.map +1 -0
  10. package/dist/decision-log.d.ts +142 -0
  11. package/dist/decision-log.d.ts.map +1 -0
  12. package/dist/decision-log.js +288 -0
  13. package/dist/decision-log.js.map +1 -0
  14. package/dist/dimension-context.d.ts +402 -0
  15. package/dist/dimension-context.d.ts.map +1 -0
  16. package/dist/dimension-context.js +226 -0
  17. package/dist/dimension-context.js.map +1 -0
  18. package/dist/errors.d.ts +15 -0
  19. package/dist/errors.d.ts.map +1 -0
  20. package/dist/errors.js +18 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/evidence-decision.d.ts +44 -0
  23. package/dist/evidence-decision.d.ts.map +1 -0
  24. package/dist/evidence-decision.js +88 -0
  25. package/dist/evidence-decision.js.map +1 -0
  26. package/dist/evidence-pack.d.ts +1884 -0
  27. package/dist/evidence-pack.d.ts.map +1 -0
  28. package/dist/evidence-pack.js +243 -0
  29. package/dist/evidence-pack.js.map +1 -0
  30. package/dist/index.d.ts +19 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +19 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/parse.d.ts +22 -0
  35. package/dist/parse.d.ts.map +1 -0
  36. package/dist/parse.js +53 -0
  37. package/dist/parse.js.map +1 -0
  38. package/dist/recipe-config.d.ts +48 -0
  39. package/dist/recipe-config.d.ts.map +1 -0
  40. package/dist/recipe-config.js +20 -0
  41. package/dist/recipe-config.js.map +1 -0
  42. package/dist/schemas.d.ts +11 -0
  43. package/dist/schemas.d.ts.map +1 -0
  44. package/dist/schemas.js +19 -0
  45. package/dist/schemas.js.map +1 -0
  46. package/package.json +84 -0
  47. package/schemas/decision-log-entry.schema.json +45 -0
  48. package/schemas/evidence-pack.schema.json +359 -0
  49. package/schemas/recipe-config.schema.json +36 -0
package/dist/errors.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Thrown by every parse* function in this package when the input does not
3
+ * conform to the schema. `code` is stable and machine-readable; `issues`
4
+ * carries one entry per violation with a JSON-path-like location.
5
+ */
6
+ export class KernelSchemaError extends Error {
7
+ code = "KERNEL_E_SCHEMA";
8
+ issues;
9
+ constructor(label, issues) {
10
+ const detail = issues
11
+ .map((issue) => `${issue.path.length > 0 ? issue.path : "<root>"}: ${issue.message}`)
12
+ .join("; ");
13
+ super(`invalid ${label}: ${detail}`);
14
+ this.name = "KernelSchemaError";
15
+ this.issues = issues;
16
+ }
17
+ }
18
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,IAAI,GAAG,iBAAiB,CAAC;IACzB,MAAM,CAA+B;IAE9C,YAAY,KAAa,EAAE,MAAoC;QAC7D,MAAM,MAAM,GAAG,MAAM;aAClB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;aACpF,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,KAAK,CAAC,WAAW,KAAK,KAAK,MAAM,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,44 @@
1
+ import type { EvidencePack } from "./evidence-pack.js";
2
+ import type { DecisionOutcome } from "./decision-log-entry.js";
3
+ /**
4
+ * Transcribing an evidence pack into the decision log's vocabulary.
5
+ *
6
+ * This function deliberately contains **no verification logic of its own**. The
7
+ * three architecture iron laws put "did this change happen because of this
8
+ * operation" inside the Swift engine; the engine already answered that question
9
+ * and wrote it into the pack (`attribution`, `assertion.passed`,
10
+ * `diagnosis.class`, `circuitBreaker.level`). What lives here is only the
11
+ * mapping from those verdicts to the four `DecisionOutcome` values, so that both
12
+ * TypeScript shells log the same words for the same evidence — one of the
13
+ * reasons the mapping is in the kernel instead of in each shell.
14
+ *
15
+ * Order matters, and it is the order of "what actually decides the run":
16
+ *
17
+ * 1. `circuitBreaker.level >= 3` → `blocked`
18
+ * The loop was stopped by policy. Whether the interface is fine is not
19
+ * what this entry is about, and saying `fail` would blame the app for a
20
+ * harness limit.
21
+ * 2. an assertion present → `pass` / `fail` from `assertion.passed`
22
+ * This is the engine's own verdict on the property that was checked.
23
+ * 3. a diagnosis present → `NO_ANOMALY` = pass, `INCONCLUSIVE` =
24
+ * inconclusive, any `T*` class = fail
25
+ * 4. neither → `inconclusive`
26
+ * Nothing was asserted and nothing diagnosed: there is no basis to record
27
+ * a verdict, and an audit log full of unfounded `pass` entries is worse
28
+ * than an empty one.
29
+ *
30
+ * Then, and only as a downgrade, the pack's own contamination fields are
31
+ * honoured: a `pass` whose attribution is `weak`, or which the engine flagged
32
+ * `contaminated`, is recorded as `inconclusive`. A "pass" the engine itself
33
+ * refuses to attribute to this operation must not be logged as if it had been
34
+ * attributed — that is the failure mode the audit chain exists to catch.
35
+ * Nothing here can upgrade a verdict.
36
+ */
37
+ export declare function decisionOutcomeFromEvidence(evidence: EvidencePack): DecisionOutcome;
38
+ /**
39
+ * Human-readable reason for the entry's `summary`, built from the same fields
40
+ * only. Producers use it so that two shells do not invent two phrasings of the
41
+ * same state; it is a *rendering* of the pack, never a new judgement.
42
+ */
43
+ export declare function decisionSummaryFromEvidence(evidence: EvidencePack): string;
44
+ //# sourceMappingURL=evidence-decision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence-decision.d.ts","sourceRoot":"","sources":["../src/evidence-decision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,YAAY,GAAG,eAAe,CAMnF;AAoBD;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM,CAoB1E"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Transcribing an evidence pack into the decision log's vocabulary.
3
+ *
4
+ * This function deliberately contains **no verification logic of its own**. The
5
+ * three architecture iron laws put "did this change happen because of this
6
+ * operation" inside the Swift engine; the engine already answered that question
7
+ * and wrote it into the pack (`attribution`, `assertion.passed`,
8
+ * `diagnosis.class`, `circuitBreaker.level`). What lives here is only the
9
+ * mapping from those verdicts to the four `DecisionOutcome` values, so that both
10
+ * TypeScript shells log the same words for the same evidence — one of the
11
+ * reasons the mapping is in the kernel instead of in each shell.
12
+ *
13
+ * Order matters, and it is the order of "what actually decides the run":
14
+ *
15
+ * 1. `circuitBreaker.level >= 3` → `blocked`
16
+ * The loop was stopped by policy. Whether the interface is fine is not
17
+ * what this entry is about, and saying `fail` would blame the app for a
18
+ * harness limit.
19
+ * 2. an assertion present → `pass` / `fail` from `assertion.passed`
20
+ * This is the engine's own verdict on the property that was checked.
21
+ * 3. a diagnosis present → `NO_ANOMALY` = pass, `INCONCLUSIVE` =
22
+ * inconclusive, any `T*` class = fail
23
+ * 4. neither → `inconclusive`
24
+ * Nothing was asserted and nothing diagnosed: there is no basis to record
25
+ * a verdict, and an audit log full of unfounded `pass` entries is worse
26
+ * than an empty one.
27
+ *
28
+ * Then, and only as a downgrade, the pack's own contamination fields are
29
+ * honoured: a `pass` whose attribution is `weak`, or which the engine flagged
30
+ * `contaminated`, is recorded as `inconclusive`. A "pass" the engine itself
31
+ * refuses to attribute to this operation must not be logged as if it had been
32
+ * attributed — that is the failure mode the audit chain exists to catch.
33
+ * Nothing here can upgrade a verdict.
34
+ */
35
+ export function decisionOutcomeFromEvidence(evidence) {
36
+ const base = baseOutcome(evidence);
37
+ if (base !== "pass")
38
+ return base;
39
+ if (evidence.attribution.contaminated)
40
+ return "inconclusive";
41
+ if (evidence.attribution.level === "weak")
42
+ return "inconclusive";
43
+ return "pass";
44
+ }
45
+ function baseOutcome(evidence) {
46
+ if (evidence.circuitBreaker.level >= 3)
47
+ return "blocked";
48
+ // `assertion` and `diagnosis` are **both** `optional()` and `union([X, null])`:
49
+ // absent and explicit-null are two different shapes the engine really emits
50
+ // (the frozen fixture carries `"diagnosis": null`). A `!== null` test alone
51
+ // would treat an absent key as a present object and throw, so presence is
52
+ // tested with `?? null` instead.
53
+ const assertion = evidence.assertion ?? null;
54
+ if (assertion !== null)
55
+ return assertion.passed ? "pass" : "fail";
56
+ const diagnosis = evidence.diagnosis ?? null;
57
+ if (diagnosis !== null) {
58
+ if (diagnosis.class === "NO_ANOMALY")
59
+ return "pass";
60
+ if (diagnosis.class === "INCONCLUSIVE")
61
+ return "inconclusive";
62
+ return "fail";
63
+ }
64
+ return "inconclusive";
65
+ }
66
+ /**
67
+ * Human-readable reason for the entry's `summary`, built from the same fields
68
+ * only. Producers use it so that two shells do not invent two phrasings of the
69
+ * same state; it is a *rendering* of the pack, never a new judgement.
70
+ */
71
+ export function decisionSummaryFromEvidence(evidence) {
72
+ const parts = [];
73
+ const assertion = evidence.assertion ?? null;
74
+ if (assertion !== null) {
75
+ parts.push(`assertion ${assertion.property} ${assertion.passed ? "passed" : "failed"}: expected ${JSON.stringify(assertion.expected)}, actual ${JSON.stringify(assertion.actual)}`);
76
+ }
77
+ const diagnosis = evidence.diagnosis ?? null;
78
+ if (diagnosis !== null) {
79
+ parts.push(`diagnosis ${diagnosis.class}: ${diagnosis.report.anomaly}`);
80
+ }
81
+ if (evidence.circuitBreaker.level > 0) {
82
+ parts.push(`circuitBreaker level ${evidence.circuitBreaker.level}${evidence.circuitBreaker.reason ? ` (${evidence.circuitBreaker.reason})` : ""}`);
83
+ }
84
+ parts.push(`attribution ${evidence.attribution.level}${evidence.attribution.contaminated ? ", contaminated" : ""}`);
85
+ const summary = parts.join("; ");
86
+ return summary.length > 2048 ? `${summary.slice(0, 2045)}...` : summary;
87
+ }
88
+ //# sourceMappingURL=evidence-decision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence-decision.js","sourceRoot":"","sources":["../src/evidence-decision.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,2BAA2B,CAAC,QAAsB;IAChE,MAAM,IAAI,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IACjC,IAAI,QAAQ,CAAC,WAAW,CAAC,YAAY;QAAE,OAAO,cAAc,CAAC;IAC7D,IAAI,QAAQ,CAAC,WAAW,CAAC,KAAK,KAAK,MAAM;QAAE,OAAO,cAAc,CAAC;IACjE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,QAAsB;IACzC,IAAI,QAAQ,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IACzD,gFAAgF;IAChF,4EAA4E;IAC5E,4EAA4E;IAC5E,0EAA0E;IAC1E,iCAAiC;IACjC,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,IAAI,IAAI,CAAC;IAC7C,IAAI,SAAS,KAAK,IAAI;QAAE,OA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