kijito-tools 0.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.
Files changed (104) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +6 -0
  3. package/README.md +220 -0
  4. package/bin/cli.js +34 -0
  5. package/install.sh +161 -0
  6. package/package.json +50 -0
  7. package/providers/_shared/wake-core.mjs +358 -0
  8. package/providers/claude/CLAUDE.md.snippet +31 -0
  9. package/providers/claude/install.sh +186 -0
  10. package/providers/claude/scripts/arm-session.sh +66 -0
  11. package/providers/claude/scripts/claude-armed.sh +101 -0
  12. package/providers/claude/scripts/heartbeat-watchdog.sh +209 -0
  13. package/providers/claude/scripts/inbox-selftest.sh +277 -0
  14. package/providers/claude/scripts/kijito-persona-lib.sh +94 -0
  15. package/providers/claude/scripts/kijito-qa-pass.sh +12 -0
  16. package/providers/claude/scripts/lifecycle-lib.sh +167 -0
  17. package/providers/claude/scripts/myctx.sh +46 -0
  18. package/providers/claude/scripts/self-clear.sh +134 -0
  19. package/providers/claude/scripts/session-autosend.sh +85 -0
  20. package/providers/claude/scripts/session-catchup-hint.sh +330 -0
  21. package/providers/claude/scripts/statusline-context.sh +67 -0
  22. package/providers/claude/skills/kijito-qa-memory/SKILL.md +110 -0
  23. package/providers/claude/skills/kijito-recall/SKILL.md +53 -0
  24. package/providers/claude/skills/kijito-start/SKILL.md +122 -0
  25. package/providers/claude/wiring/README.md +93 -0
  26. package/providers/claude/wiring/kijito-heartbeat@.service +21 -0
  27. package/providers/codex/README.md +75 -0
  28. package/providers/codex/codex-kijito-parity-plan.md +265 -0
  29. package/providers/codex/docs-codex-setup.md +64 -0
  30. package/providers/codex/install.mjs +184 -0
  31. package/providers/codex/n0-capability-probe-protocol.md +472 -0
  32. package/providers/codex/n0-harness/README.md +57 -0
  33. package/providers/codex/n0-harness/cli.mjs +58 -0
  34. package/providers/codex/n0-harness/evidence-manifest.mjs +77 -0
  35. package/providers/codex/n0-harness/fixture.mjs +279 -0
  36. package/providers/codex/n0-harness/lib.mjs +141 -0
  37. package/providers/codex/n0-harness/manifest.mjs +36 -0
  38. package/providers/codex/n0-harness/oracle.mjs +464 -0
  39. package/providers/codex/n0-harness/parser.mjs +200 -0
  40. package/providers/codex/n0-harness/prompt.mjs +43 -0
  41. package/providers/codex/n0-harness/snapshot.mjs +120 -0
  42. package/providers/codex/n0-harness/specimen.mjs +37 -0
  43. package/providers/codex/notify/kijito-notify-count.mjs +117 -0
  44. package/providers/codex/notify/kijito-notify-count.test.mjs +76 -0
  45. package/providers/codex/plans/gate4-battery-log.md +184 -0
  46. package/providers/codex/plans/gate4-battery-protocol.md +43 -0
  47. package/providers/codex/plans/hive-user-first-plan-QA.md +34 -0
  48. package/providers/codex/plans/hive-user-first-plan.md +247 -0
  49. package/providers/codex/release-manifest.json +53 -0
  50. package/providers/codex/same-chat-continuation-plan-gate.md +235 -0
  51. package/providers/codex/same-chat-continuation-plan.md +458 -0
  52. package/providers/codex/skills/kijito-qa-memory/SKILL.md +193 -0
  53. package/providers/codex/skills/kijito-qa-memory/agents/openai.yaml +4 -0
  54. package/providers/codex/skills/kijito-recall/SKILL.md +53 -0
  55. package/providers/codex/skills/kijito-start/SKILL.md +173 -0
  56. package/providers/codex/skills/kijito-start/agents/openai.yaml +4 -0
  57. package/providers/codex/test/n0-cli-refusal.test.mjs +31 -0
  58. package/providers/codex/test/n0-counterexample-matrix.test.mjs +118 -0
  59. package/providers/codex/test/n0-guard-census-core.mjs +1372 -0
  60. package/providers/codex/test/n0-guard-census.json +35479 -0
  61. package/providers/codex/test/n0-guard-census.mjs +31 -0
  62. package/providers/codex/test/n0-guard-census.test.mjs +374 -0
  63. package/providers/codex/test/n0-guard-counterexamples.mjs +1068 -0
  64. package/providers/codex/test/n0-guard-independent-projection.mjs +70 -0
  65. package/providers/codex/test/n0-guard-independent-projection.test.mjs +53 -0
  66. package/providers/codex/test/n0-guard-manifest-author.mjs +424 -0
  67. package/providers/codex/test/n0-guard-mutation-operators.test.mjs +244 -0
  68. package/providers/codex/test/n0-guard-mutation-runner.mjs +599 -0
  69. package/providers/codex/test/n0-guard-remainder-classes.test.mjs +314 -0
  70. package/providers/codex/test/n0-guard-sanitizer-pairs.test.mjs +68 -0
  71. package/providers/codex/test/n0-guard-shared-context-predicates.test.mjs +84 -0
  72. package/providers/codex/test/n0-harness.test.mjs +553 -0
  73. package/providers/codex/test/n0-notable-regressions.test.mjs +70 -0
  74. package/providers/codex/test/n0-subject-boundary.mjs +97 -0
  75. package/providers/codex/test/n0-subject-boundary.test.mjs +72 -0
  76. package/providers/codex/test/same-chat-plan-preflight.sh +167 -0
  77. package/providers/codex/tools/refresh-manifest.mjs +81 -0
  78. package/providers/codex/wake-helper/TRANSPORT-NOTES.md +25 -0
  79. package/providers/codex/wake-helper/integration.test.mjs +285 -0
  80. package/providers/codex/wake-helper/kijito-wake-helper.mjs +488 -0
  81. package/providers/codex/wake-helper/kijito-wake-helper.test.mjs +128 -0
  82. package/providers/codex/wake-helper/mock-daemon.mjs +64 -0
  83. package/providers/codex/wake-helper/status-probe.mjs +45 -0
  84. package/providers/codex/wake-helper/ws-uds.mjs +153 -0
  85. package/providers/monitor/.github/workflows/publish-npm.yml +38 -0
  86. package/providers/monitor/.github/workflows/publish-pypi.yml +30 -0
  87. package/providers/monitor/CHANGELOG.md +465 -0
  88. package/providers/monitor/IMPORT-PROVENANCE.md +68 -0
  89. package/providers/monitor/LICENSE +202 -0
  90. package/providers/monitor/NOTICE +7 -0
  91. package/providers/monitor/OPAQUE-OUTPUT-ENFORCEMENT.md +45 -0
  92. package/providers/monitor/README.md +571 -0
  93. package/providers/monitor/RELEASING.md +125 -0
  94. package/providers/monitor/arm-hive-monitor.sh +13 -0
  95. package/providers/monitor/bin/cli.js +43 -0
  96. package/providers/monitor/com.kijito.inbox-monitor.plist.template +59 -0
  97. package/providers/monitor/docs/DESIGN.md +984 -0
  98. package/providers/monitor/kijito-inbox-monitor@.service.template +95 -0
  99. package/providers/monitor/kijito_inbox_monitor.py +3666 -0
  100. package/providers/monitor/package.json +35 -0
  101. package/providers/monitor/pyproject.toml +42 -0
  102. package/providers/monitor/scripts/mutation-check.py +399 -0
  103. package/providers/monitor/scripts/prepublish-gate.sh +284 -0
  104. package/providers/monitor/test_kijito_monitor.py +5609 -0
@@ -0,0 +1,70 @@
1
+ import crypto from "node:crypto";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+
5
+ const EXTENSIONS = new Set([".js", ".mjs", ".cjs"]);
6
+
7
+ function sha256(value) {
8
+ return crypto.createHash("sha256").update(value).digest("hex");
9
+ }
10
+
11
+ function filesUnder(root) {
12
+ const files = [];
13
+ const visit = (directory) => {
14
+ for (const entry of fs.readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
15
+ const target = path.join(directory, entry.name);
16
+ if (entry.isDirectory()) visit(target);
17
+ else if (entry.isFile() && EXTENSIONS.has(path.extname(entry.name))) files.push(target);
18
+ }
19
+ };
20
+ visit(root);
21
+ return files;
22
+ }
23
+
24
+ function position(source, offset) {
25
+ const prefix = source.slice(0, offset);
26
+ const line = prefix.split("\n").length;
27
+ const lastBreak = prefix.lastIndexOf("\n");
28
+ return { line, column: offset - lastBreak };
29
+ }
30
+
31
+ function site(relative, source, match, spelling) {
32
+ const at = position(source, match.index);
33
+ const lineText = source.split("\n")[at.line - 1]?.trim() ?? "";
34
+ return {
35
+ file: relative,
36
+ line: at.line,
37
+ column: at.column,
38
+ spelling,
39
+ lineHash: sha256(lineText),
40
+ };
41
+ }
42
+
43
+ export function independentProjection(root) {
44
+ const absolute = path.resolve(root);
45
+ const sites = [];
46
+ for (const file of filesUnder(absolute)) {
47
+ const relative = path.relative(absolute, file).split(path.sep).join("/");
48
+ const source = fs.readFileSync(file, "utf8").replace(/\r\n/g, "\n");
49
+ for (const match of source.matchAll(/\bfail\s*\(/g)) {
50
+ const prefix = source.slice(Math.max(0, match.index - 32), match.index);
51
+ if (/function\s+$/.test(prefix) || /function\s+fail\s*$/.test(prefix)) continue;
52
+ sites.push(site(relative, source, match, "fail"));
53
+ }
54
+ for (const match of source.matchAll(/\bverdict\s*\(\s*["']RED["']/g)) {
55
+ sites.push(site(relative, source, match, "verdict:RED"));
56
+ }
57
+ }
58
+ sites.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column || a.spelling.localeCompare(b.spelling));
59
+ const counts = {
60
+ fail: sites.filter((entry) => entry.spelling === "fail").length,
61
+ "verdict:RED": sites.filter((entry) => entry.spelling === "verdict:RED").length,
62
+ };
63
+ return {
64
+ mechanism: "plain-regex-line-scan-v1-no-parser",
65
+ sourceAggregate: sha256(filesUnder(absolute).map((file) => `${path.relative(absolute, file)}\0${fs.readFileSync(file)}`).join("\0")),
66
+ aggregate: sha256(JSON.stringify(sites)),
67
+ counts,
68
+ sites,
69
+ };
70
+ }
@@ -0,0 +1,53 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import { afterEach, test } from "node:test";
6
+ import { fileURLToPath } from "node:url";
7
+ import { independentProjection } from "./n0-guard-independent-projection.mjs";
8
+
9
+ const HERE = path.dirname(fileURLToPath(import.meta.url));
10
+ const temporaryRoots = [];
11
+
12
+ afterEach(() => {
13
+ for (const root of temporaryRoots.splice(0)) rmSync(root, { recursive: true, force: true });
14
+ });
15
+
16
+ function fixture(source) {
17
+ const root = mkdtempSync(path.join(tmpdir(), "n0-independent-projection-"));
18
+ temporaryRoots.push(root);
19
+ writeFileSync(path.join(root, "subject.mjs"), source);
20
+ return root;
21
+ }
22
+
23
+ test("independent projection is intentionally crude enough to disagree on data-like spellings", () => {
24
+ const root = fixture(`
25
+ function fail() {}
26
+ function verdict() {}
27
+ export function subject() { fail("X"); return verdict("RED", "Y"); }
28
+ const text = 'fail("data") verdict("RED", "data")';
29
+ // fail("comment") verdict("RED", "comment")
30
+ `);
31
+ const result = independentProjection(root);
32
+ assert.equal(result.mechanism, "plain-regex-line-scan-v1-no-parser");
33
+ assert.deepEqual(result.counts, { fail: 3, "verdict:RED": 3 });
34
+ assert.equal(result.sites.length, 6);
35
+ });
36
+
37
+ test("independent projection has no parser or analyzer dependency", () => {
38
+ const source = readFileSync(path.join(HERE, "n0-guard-independent-projection.mjs"), "utf8");
39
+ assert.doesNotMatch(source, /from\s+["']acorn["']/);
40
+ assert.doesNotMatch(source, /n0-guard-census-core/);
41
+ assert.doesNotMatch(source, /\bparse\s*\(/);
42
+ });
43
+
44
+ test("source aggregate binds non-site edits while the exact site aggregate stays stable", () => {
45
+ const root = fixture(`export function subject() { fail("X"); }\n`);
46
+ const before = independentProjection(root);
47
+ mkdirSync(path.join(root, "nested"));
48
+ writeFileSync(path.join(root, "nested/metadata.mjs"), "export const value = 1;\n");
49
+ const after = independentProjection(root);
50
+ assert.notEqual(after.sourceAggregate, before.sourceAggregate);
51
+ assert.equal(after.aggregate, before.aggregate);
52
+ assert.deepEqual(after.sites, before.sites);
53
+ });
@@ -0,0 +1,424 @@
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { parse } from "acorn";
6
+
7
+ const here = path.dirname(fileURLToPath(import.meta.url));
8
+ const manifestPath = path.join(here, "n0-guard-census.json");
9
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
10
+
11
+ const PAYLOAD_FREE_OPERATORS = new Map(Object.entries({
12
+ "cli.mjs:36:44:rejecting-helper-call:674bf493f8036d66": "suppress-thrown-rejection",
13
+ "cli.mjs:42:22:rejecting-helper-call:3168111b49061320": "suppress-thrown-rejection",
14
+ "cli.mjs:42:38:rejecting-helper-call:76622647f598b656": "suppress-thrown-rejection",
15
+ "cli.mjs:43:22:rejecting-helper-call:ae44c6cc219d62f9": "suppress-thrown-rejection",
16
+ "cli.mjs:43:38:rejecting-helper-call:c2fc2cee0a0f64b5": "suppress-thrown-rejection",
17
+ "cli.mjs:45:20:rejecting-helper-call:ebdff9a32fcc066b": "force-call-result-status",
18
+ "evidence-manifest.mjs:31:28:rejecting-helper-call:423e405b2da9b7fd": "suppress-thrown-rejection",
19
+ "lib.mjs:97:20:rejecting-helper-call:b3bed58f42c6ee8c": "suppress-thrown-rejection",
20
+ "lib.mjs:105:3:rejecting-helper-call:7f37de2cf456b629": "bypass-rejection",
21
+ "oracle.mjs:362:27:rejecting-helper-call:ccf1ae04a417cc27": "suppress-thrown-rejection",
22
+ "lib.mjs:55:3:rejecting-helper-call:9431c6ae92b05bf5": "suppress-thrown-rejection",
23
+ "oracle.mjs:81:17:rejecting-helper-call:74d6da1d9a547734": "suppress-thrown-rejection",
24
+ "oracle.mjs:98:18:rejecting-helper-call:72e6f71373cc02a2": "suppress-thrown-rejection",
25
+ "oracle.mjs:106:22:rejecting-helper-call:a09692553a3b4d79": "suppress-thrown-rejection",
26
+ "oracle.mjs:120:20:rejecting-helper-call:ff6a25b01f60ae5b": "suppress-thrown-rejection",
27
+ "oracle.mjs:128:17:rejecting-helper-call:19670ead0eddfacf": "suppress-thrown-rejection",
28
+ "oracle.mjs:165:19:rejecting-helper-call:47055976d70dcbe6": "suppress-thrown-rejection",
29
+ "oracle.mjs:177:17:rejecting-helper-call:4cfcd52300a3b9c3": "suppress-thrown-rejection",
30
+ "oracle.mjs:189:19:rejecting-helper-call:d1a33bb56cfd0cb8": "suppress-thrown-rejection",
31
+ "oracle.mjs:193:20:rejecting-helper-call:0378081cd7a677a4": "suppress-thrown-rejection",
32
+ "oracle.mjs:215:18:rejecting-helper-call:395a93f673d3332a": "suppress-thrown-rejection",
33
+ "oracle.mjs:223:3:rejecting-helper-call:8bbe25ad570a6758": "suppress-thrown-rejection",
34
+ "oracle.mjs:242:23:rejecting-helper-call:421568a92598c2d1": "suppress-thrown-rejection",
35
+ "oracle.mjs:292:3:rejecting-helper-call:2563493bf86065c7": "suppress-thrown-rejection",
36
+ "oracle.mjs:299:19:rejecting-helper-call:d2913eb550ea3c08": "suppress-thrown-rejection",
37
+ "oracle.mjs:304:5:rejecting-helper-call:47fc1e277b4ab20d": "suppress-thrown-rejection",
38
+ "oracle.mjs:430:3:rejecting-helper-call:0e82521959067f2f": "suppress-thrown-rejection",
39
+ "oracle.mjs:442:3:rejecting-helper-call:2a68a40248bfc7d8": "suppress-thrown-rejection",
40
+ "prompt.mjs:8:17:rejecting-helper-call:5311a80d2d36ba75": "suppress-thrown-rejection",
41
+ "cli.mjs:54:3:rejecting-helper-call:25482116c496f993": "suppress-thrown-rejection",
42
+ "parser.mjs:109:52:rejecting-helper-call:24633b97fa21810f": "suppress-thrown-rejection",
43
+ "specimen.mjs:9:18:rejecting-helper-call:e2f8125b417f7ed0": "suppress-thrown-rejection",
44
+ }));
45
+
46
+ const BYPASS_ENTRIES = new Set([
47
+ "cli.mjs:9:3:exit-status-site:1fc28e7745de9012",
48
+ "cli.mjs:47:46:exit-status-site:7e283b07214cfa3b",
49
+ "cli.mjs:57:3:exit-status-site:7e283b07214cfa3b",
50
+ "evidence-manifest.mjs:27:97:rejection-site:740028662f63c4e4",
51
+ "snapshot.mjs:64:9:rejecting-helper-call:37287c78f93753ad",
52
+ ]);
53
+
54
+ const FORCE_OWNED_CONDITIONS = new Map(Object.entries({
55
+ "cli.mjs:31:7:guard-atom:26c91edf4fd94e26": false,
56
+ "cli.mjs:31:24:guard-atom:63045e284c19263b": false,
57
+ "evidence-manifest.mjs:27:38:guard-atom:69fa47ef158a2145": false,
58
+ "evidence-manifest.mjs:27:59:guard-atom:aeef6579f5981cc3": false,
59
+ "lib.mjs:95:7:guard-atom:703d241562495f56": false,
60
+ "lib.mjs:99:7:guard-atom:b8c975ed7df43f77": false,
61
+ "lib.mjs:100:7:guard-atom:879684b9778da4d6": false,
62
+ "oracle.mjs:93:7:guard-atom:2aca57d142ee35bb": false,
63
+ "oracle.mjs:175:9:guard-atom:a30803d547c6841d": false,
64
+ "oracle.mjs:313:7:guard-atom:e3c481736ae16a55": false,
65
+ "oracle.mjs:329:9:guard-atom:1a9495640d1fc0ed": false,
66
+ "parser.mjs:19:7:guard-atom:d958fd86ec515ca0": false,
67
+ "snapshot.mjs:49:7:guard-atom:703d241562495f56": false,
68
+ "snapshot.mjs:59:11:guard-atom:b8c975ed7df43f77": false,
69
+ "lib.mjs:82:92:predicate-atom:4542f69c79c1c3b7": true,
70
+ "oracle.mjs:230:7:predicate-atom:c501cea746d8b024": false,
71
+ "oracle.mjs:230:17:predicate-atom:e052cf82d87a7ce7": false,
72
+ "oracle.mjs:237:10:predicate-atom:9fc1043699bdb5fa": true,
73
+ "oracle.mjs:237:44:predicate-atom:a9035cd3a7d97ea6": true,
74
+ }));
75
+
76
+ const SHARED_CONTEXT_PREDICATE_ATOMS = new Set([
77
+ "lib.mjs:22:10:predicate-atom:b579cf79ff684260",
78
+ "lib.mjs:22:28:predicate-atom:f13c9e45b40ad616",
79
+ "lib.mjs:82:10:predicate-atom:b7fc7b5f4fb78cb6",
80
+ "lib.mjs:82:30:predicate-atom:d8edadc88ffeb3ca",
81
+ ]);
82
+
83
+ const SAME_CODE_SHADOW_WITNESSES = new Map(Object.entries({
84
+ "oracle.mjs:81:17:rejecting-helper-call:74d6da1d9a547734": "oracle.specimen.paths-object",
85
+ "oracle.mjs:98:18:rejecting-helper-call:72e6f71373cc02a2": "oracle.specimen.target-object",
86
+ "oracle.mjs:106:22:rejecting-helper-call:a09692553a3b4d79": "oracle.specimen.permission-object",
87
+ "oracle.mjs:177:17:rejecting-helper-call:4cfcd52300a3b9c3": "oracle.specimen.clock-object",
88
+ "oracle.mjs:189:19:rejecting-helper-call:d1a33bb56cfd0cb8": "oracle.rollout.object",
89
+ "oracle.mjs:193:20:rejecting-helper-call:0378081cd7a677a4": "oracle.rollout.snapshot-object",
90
+ "oracle.mjs:215:18:rejecting-helper-call:395a93f673d3332a": "oracle.rollout.parser-object",
91
+ "oracle.mjs:223:3:rejecting-helper-call:8bbe25ad570a6758": "oracle.versions.object",
92
+ "oracle.mjs:242:23:rejecting-helper-call:421568a92598c2d1": "oracle.environment.object",
93
+ "oracle.mjs:292:3:rejecting-helper-call:2563493bf86065c7": "oracle.permission.object",
94
+ "oracle.mjs:430:3:rejecting-helper-call:0e82521959067f2f": "oracle.meta.object",
95
+ }));
96
+
97
+ const DOWNSTREAM_DOMAIN_SHADOW_WITNESSES = new Map(Object.entries({
98
+ "oracle.mjs:230:7:predicate-atom:c501cea746d8b024": "oracle.canary.value-null",
99
+ "oracle.mjs:230:17:predicate-atom:e052cf82d87a7ce7": "oracle.canary.value-primitive",
100
+ }));
101
+
102
+ const SUCCESS_PATH_CALLS = new Set([
103
+ "fixture.mjs:64:20:rejecting-helper-call:5ee8fe818d227757",
104
+ "fixture.mjs:116:18:rejecting-helper-call:e2f8125b417f7ed0",
105
+ "fixture.mjs:175:44:rejecting-helper-call:891243e1c000198e",
106
+ "fixture.mjs:220:54:rejecting-helper-call:891243e1c000198e",
107
+ "fixture.mjs:232:44:rejecting-helper-call:891243e1c000198e",
108
+ "fixture.mjs:252:17:rejecting-helper-call:107da86911fcb8d4",
109
+ "oracle.mjs:175:25:rejecting-helper-call:e2f8125b417f7ed0",
110
+ ]);
111
+
112
+ const DELEGATED_OUTCOME_CALLS = new Set([
113
+ "cli.mjs:28:18:rejecting-helper-call:2abc5cf6881921c3",
114
+ ]);
115
+
116
+ const COMPOUNDS = [
117
+ {
118
+ id: "snapshot-catch-triad",
119
+ witness: { id: "snapshot.stable.error", rejectCode: "SNAPSHOT_SCHEMA", acceptCode: "SNAPSHOT_STABLE_ACCEPTED" },
120
+ memberIds: [
121
+ "snapshot.mjs:116:9:guard-atom:b1e4b91352b7dd37",
122
+ "snapshot.mjs:116:35:rejection-site:8c468a57ba68bc74",
123
+ "snapshot.mjs:117:5:rejection-site:8c468a57ba68bc74",
124
+ ],
125
+ edits: [
126
+ { entryId: "snapshot.mjs:116:9:guard-atom:b1e4b91352b7dd37", mutation: { operator: "force-owned-condition", value: false } },
127
+ { entryId: "snapshot.mjs:116:35:rejection-site:8c468a57ba68bc74", mutation: { operator: "bypass-rejection" } },
128
+ { entryId: "snapshot.mjs:117:5:rejection-site:8c468a57ba68bc74", mutation: { operator: "bypass-rejection" } },
129
+ ],
130
+ },
131
+ {
132
+ id: "run-binding-triad",
133
+ witness: { id: "oracle.case.run-binding-type", rejectCode: "RUN_BINDING", acceptCode: "ALL_SYNTHETIC_EVIDENCE_GREEN" },
134
+ memberIds: [
135
+ "oracle.mjs:336:9:guard-atom:427adbe36f06b655",
136
+ "oracle.mjs:336:52:guard-atom:affdb92192535a0b",
137
+ "oracle.mjs:337:73:guard-atom:78af6b5e91c052a0",
138
+ ],
139
+ edits: [
140
+ { entryId: "oracle.mjs:336:9:guard-atom:427adbe36f06b655", mutation: { operator: "force-owned-condition", value: false } },
141
+ { entryId: "oracle.mjs:336:52:guard-atom:affdb92192535a0b", mutation: { operator: "force-owned-condition", value: false } },
142
+ { entryId: "oracle.mjs:337:73:guard-atom:78af6b5e91c052a0", mutation: { operator: "force-owned-condition", value: false } },
143
+ ],
144
+ },
145
+ {
146
+ id: "receipt-binding-triad",
147
+ witness: { id: "oracle.case.receipt-binding-type", rejectCode: "RECEIPT_BINDING", acceptCode: "ALL_SYNTHETIC_EVIDENCE_GREEN" },
148
+ memberIds: [
149
+ "oracle.mjs:341:9:guard-atom:eadf0ac86ffaaedb",
150
+ "oracle.mjs:341:49:guard-atom:7c1048938de29511",
151
+ "oracle.mjs:342:70:guard-atom:b20ab6539939ae8b",
152
+ ],
153
+ edits: [
154
+ { entryId: "oracle.mjs:341:9:guard-atom:eadf0ac86ffaaedb", mutation: { operator: "force-owned-condition", value: false } },
155
+ { entryId: "oracle.mjs:341:49:guard-atom:7c1048938de29511", mutation: { operator: "force-owned-condition", value: false } },
156
+ { entryId: "oracle.mjs:342:70:guard-atom:b20ab6539939ae8b", mutation: { operator: "force-owned-condition", value: false } },
157
+ ],
158
+ },
159
+ {
160
+ id: "nonce-cardinality-pair",
161
+ witness: { id: "parser.nonce.multiple-turns", rejectCode: "NONCE_USER_SPAN", acceptCode: "NONCE_ACCEPTED" },
162
+ memberIds: ["parser.mjs:64:22:guard-atom:4606e22e0103c3b5"],
163
+ edits: [
164
+ { entryId: "parser.mjs:64:7:guard-atom:fd65b3c7d7d3dee5", mutation: { operator: "force-owned-condition", value: false } },
165
+ { entryId: "parser.mjs:64:22:guard-atom:4606e22e0103c3b5", mutation: { operator: "force-owned-condition", value: false } },
166
+ ],
167
+ },
168
+ {
169
+ id: "lib-root-kind-pair",
170
+ witness: { id: "lib.read.root-symlink", rejectCode: "ROOT_INVALID", acceptCode: "READ_FILE_ACCEPTED" },
171
+ memberIds: ["lib.mjs:95:7:guard-atom:703d241562495f56"],
172
+ edits: [
173
+ { entryId: "lib.mjs:95:7:guard-atom:703d241562495f56", mutation: { operator: "force-owned-condition", value: false } },
174
+ { entryId: "lib.mjs:95:36:guard-atom:ce1efc18573feb2c", mutation: { operator: "force-owned-condition", value: false } },
175
+ ],
176
+ },
177
+ {
178
+ id: "snapshot-root-kind-pair",
179
+ witness: { id: "snapshot.root.symlink", rejectCode: "SNAPSHOT_ROOT_INVALID", acceptCode: "SNAPSHOT_ACCEPTED" },
180
+ memberIds: ["snapshot.mjs:49:7:guard-atom:703d241562495f56"],
181
+ edits: [
182
+ { entryId: "snapshot.mjs:49:7:guard-atom:703d241562495f56", mutation: { operator: "force-owned-condition", value: false } },
183
+ { entryId: "snapshot.mjs:49:36:guard-atom:ce1efc18573feb2c", mutation: { operator: "force-owned-condition", value: false } },
184
+ ],
185
+ },
186
+ {
187
+ id: "case-status-null-pair",
188
+ witness: { id: "oracle.case.status-null", rejectCode: "CASE_EVIDENCE_INVALID", acceptCode: "ALL_SYNTHETIC_EVIDENCE_GREEN" },
189
+ memberIds: ["oracle.mjs:329:9:guard-atom:1a9495640d1fc0ed"],
190
+ edits: [
191
+ { entryId: "oracle.mjs:329:9:guard-atom:1a9495640d1fc0ed", mutation: { operator: "force-owned-condition", value: false } },
192
+ { entryId: "oracle.mjs:329:19:guard-atom:9c88b773e2a1b75a", mutation: { operator: "force-owned-condition", value: false } },
193
+ ],
194
+ },
195
+ ];
196
+
197
+ const FIRST_ARGUMENT_SANITIZERS = new Map(Object.entries({
198
+ "oracle.mjs:189:19:rejecting-helper-call:d1a33bb56cfd0cb8": "JSON.parse(specimen.rollout)",
199
+ "oracle.mjs:193:20:rejecting-helper-call:0378081cd7a677a4": "JSON.parse(rollout.preActionSnapshot)",
200
+ "oracle.mjs:215:18:rejecting-helper-call:395a93f673d3332a": "JSON.parse(rollout.parser)",
201
+ "oracle.mjs:299:19:rejecting-helper-call:d2913eb550ea3c08": "JSON.parse(evidence.canaryResults)",
202
+ "parser.mjs:41:19:rejecting-helper-call:d3df82140ecfc7d0": JSON.stringify('{"type":"session_meta","payload":{"id":"sanitized"}}\n'),
203
+ "parser.mjs:77:22:rejecting-helper-call:4559b1577e5654c7": 'candidate.text.toString("utf8")',
204
+ "parser.mjs:107:18:rejecting-helper-call:04f6cdc8d3d1a5f8": 'rolloutText.toString("utf8")',
205
+ "parser.mjs:119:19:rejecting-helper-call:e792f84ed71527f6": '[{ type: "turn_context", payload: { turn_id: expected.turnId, ...expected.environment } }]',
206
+ "prompt.mjs:42:29:rejecting-helper-call:0f93f1bf1d83d8ce": '({ ...specimen, cases: { ...specimen.cases, [caseName]: { ...specimen.cases[caseName], nonce: "a".repeat(32) } } })',
207
+ "snapshot.mjs:113:21:rejecting-helper-call:7613fc44bd316ea4": "current",
208
+ "specimen.mjs:12:10:rejecting-helper-call:d808855d1bc13c94": "({ ...specimen, target: { ...specimen.target, clean: true } })",
209
+ }));
210
+
211
+ function expression(source) {
212
+ const program = parse(source, { ecmaVersion: "latest" });
213
+ if (program.body.length !== 1 || program.body[0].type !== "ExpressionStatement") throw new Error(`not one expression: ${source}`);
214
+ return program.body[0].expression;
215
+ }
216
+
217
+ function convertMutation(entry) {
218
+ const prior = entry.mutation;
219
+ if (!prior || prior.operator) return;
220
+ if (prior.kind === "structural-only") {
221
+ entry.mutation = null;
222
+ entry.witness = null;
223
+ entry.acceptFlipSet = null;
224
+ entry.rejectDeltaSet = null;
225
+ entry.positiveRegressionSet = null;
226
+ entry.ownershipRecord = { kind: "owned-success", reason: "the sole N0_TEST_CAPABLE return constructor" };
227
+ return;
228
+ }
229
+ if (prior.kind === "replace-node") {
230
+ if (prior.replacement === "void 0") entry.mutation = { operator: "bypass-rejection" };
231
+ else if (["false", "true"].includes(prior.replacement)) entry.mutation = { operator: "force-owned-condition", value: prior.replacement === "true" };
232
+ else throw new Error(`unsupported node mutation ${entry.id}: ${prior.replacement}`);
233
+ return;
234
+ }
235
+ if (prior.kind !== "replace-expression") throw new Error(`unsupported mutation kind ${entry.id}: ${prior.kind}`);
236
+ const parsed = expression(prior.replacement);
237
+ if (parsed.type === "AssignmentExpression" && parsed.operator === "=") {
238
+ entry.mutation = {
239
+ operator: "sanitize-first-binding",
240
+ binding: prior.replacement.slice(parsed.left.start, parsed.left.end),
241
+ value: prior.replacement.slice(parsed.right.start, parsed.right.end),
242
+ };
243
+ } else if (parsed.type === "UnaryExpression" && parsed.operator === "delete") {
244
+ entry.mutation = { operator: "drop-reviewed-property", target: prior.replacement.slice(parsed.argument.start, parsed.argument.end) };
245
+ } else {
246
+ entry.mutation = { operator: "substitute-reviewed-expression", expression: prior.replacement };
247
+ }
248
+ }
249
+
250
+ for (const entry of manifest.entries) {
251
+ convertMutation(entry);
252
+ if (BYPASS_ENTRIES.has(entry.id)) {
253
+ entry.mutation = { operator: "bypass-rejection" };
254
+ entry.witness = null;
255
+ entry.acceptFlipSet = null;
256
+ entry.rejectDeltaSet = null;
257
+ entry.positiveRegressionSet = null;
258
+ entry.ownershipRecord = null;
259
+ }
260
+ if (FORCE_OWNED_CONDITIONS.has(entry.id)) {
261
+ entry.mutation = { operator: "force-owned-condition", value: FORCE_OWNED_CONDITIONS.get(entry.id) };
262
+ entry.witness = null;
263
+ entry.acceptFlipSet = null;
264
+ entry.rejectDeltaSet = null;
265
+ entry.positiveRegressionSet = null;
266
+ entry.ownershipRecord = null;
267
+ }
268
+ if (FIRST_ARGUMENT_SANITIZERS.has(entry.id)) {
269
+ entry.mutation = { operator: "sanitize-first-argument", value: FIRST_ARGUMENT_SANITIZERS.get(entry.id) };
270
+ entry.witness = null;
271
+ entry.acceptFlipSet = null;
272
+ entry.rejectDeltaSet = null;
273
+ entry.positiveRegressionSet = null;
274
+ entry.ownershipRecord = null;
275
+ }
276
+ if (PAYLOAD_FREE_OPERATORS.has(entry.id)) {
277
+ entry.mutation = { operator: PAYLOAD_FREE_OPERATORS.get(entry.id) };
278
+ entry.witness = null;
279
+ entry.acceptFlipSet = null;
280
+ entry.rejectDeltaSet = null;
281
+ entry.positiveRegressionSet = null;
282
+ entry.ownershipRecord = null;
283
+ }
284
+ if (SHARED_CONTEXT_PREDICATE_ATOMS.has(entry.id)) {
285
+ const proof = manifest.baseline?.sharedContextPredicates?.find((item) => item.predicate === entry.predicate);
286
+ if (!proof?.atomIds?.includes(entry.id)) throw new Error(`missing shared-context proof for ${entry.id}`);
287
+ const canonicalMutation = proof.canonicalAtomMutations?.find((item) => item.id === entry.id)?.mutation;
288
+ if (!canonicalMutation) throw new Error(`missing canonical shared-context mutation for ${entry.id}`);
289
+ entry.mutation = null;
290
+ entry.witness = null;
291
+ entry.acceptFlipSet = null;
292
+ entry.rejectDeltaSet = null;
293
+ entry.positiveRegressionSet = null;
294
+ entry.disposition = null;
295
+ entry.ownershipRecord = {
296
+ kind: "shared-context-predicate",
297
+ predicate: entry.predicate,
298
+ canonicalMutation,
299
+ };
300
+ }
301
+ if (SAME_CODE_SHADOW_WITNESSES.has(entry.id)) {
302
+ const proof = manifest.baseline?.sameCodeShadows?.find((item) => item.entryId === entry.id);
303
+ if (!proof || entry.mutation?.operator !== "suppress-thrown-rejection") {
304
+ throw new Error(`missing same-code shadow proof or canonical suppression for ${entry.id}`);
305
+ }
306
+ entry.mutation = null;
307
+ entry.witness = null;
308
+ entry.acceptFlipSet = null;
309
+ entry.rejectDeltaSet = null;
310
+ entry.positiveRegressionSet = null;
311
+ entry.disposition = null;
312
+ entry.ownershipRecord = {
313
+ kind: "same-code-shadow",
314
+ downstreamEntryId: proof.downstreamEntryId,
315
+ rejectCode: proof.rejectCode,
316
+ witnessId: SAME_CODE_SHADOW_WITNESSES.get(entry.id),
317
+ canonicalMutation: { operator: "suppress-thrown-rejection" },
318
+ };
319
+ }
320
+ if (DOWNSTREAM_DOMAIN_SHADOW_WITNESSES.has(entry.id)) {
321
+ const proof = manifest.baseline?.downstreamDomainShadows?.find((item) => item.entryId === entry.id);
322
+ if (!proof) throw new Error(`missing downstream-domain shadow proof for ${entry.id}`);
323
+ entry.mutation = null;
324
+ entry.witness = null;
325
+ entry.acceptFlipSet = null;
326
+ entry.rejectDeltaSet = null;
327
+ entry.positiveRegressionSet = null;
328
+ entry.disposition = null;
329
+ entry.ownershipRecord = {
330
+ kind: "downstream-domain-shadow",
331
+ downstreamEntryId: proof.downstreamEntryId,
332
+ enforcingEntryIds: proof.enforcingEntryIds,
333
+ canonicalMutation: proof.canonicalMutation,
334
+ catchReturn: proof.catchReturn,
335
+ pathHash: proof.pathHash,
336
+ witnessId: DOWNSTREAM_DOMAIN_SHADOW_WITNESSES.get(entry.id),
337
+ };
338
+ }
339
+ if (SUCCESS_PATH_CALLS.has(entry.id)) {
340
+ const proof = manifest.baseline?.successPathCalls?.find((item) => item.entryId === entry.id);
341
+ if (!proof) throw new Error(`missing success-path proof for ${entry.id}`);
342
+ entry.mutation = null;
343
+ entry.witness = null;
344
+ entry.acceptFlipSet = null;
345
+ entry.rejectDeltaSet = null;
346
+ entry.positiveRegressionSet = null;
347
+ entry.disposition = null;
348
+ entry.ownershipRecord = {
349
+ kind: "success-path-call",
350
+ proofKind: proof.proofKind,
351
+ dischargerEntryIds: proof.dischargerEntryIds,
352
+ };
353
+ }
354
+ if (DELEGATED_OUTCOME_CALLS.has(entry.id)) {
355
+ const proof = manifest.baseline?.delegatedOutcomeCalls?.find((item) => item.entryId === entry.id);
356
+ if (!proof) throw new Error(`missing delegated-outcome proof for ${entry.id}`);
357
+ entry.mutation = null;
358
+ entry.witness = null;
359
+ entry.acceptFlipSet = null;
360
+ entry.rejectDeltaSet = null;
361
+ entry.positiveRegressionSet = null;
362
+ entry.disposition = null;
363
+ entry.ownershipRecord = {
364
+ kind: "delegated-outcome-call",
365
+ internalCallEntryIds: proof.internalCallEntryIds,
366
+ internalOutcomeEntryIds: proof.internalOutcomeEntryIds,
367
+ callerNullGuardOwnership: proof.callerNullGuard,
368
+ callerControlFlowOwnership: proof.callerControlFlow,
369
+ };
370
+ }
371
+ if (entry.kind === "unresolved-call") {
372
+ entry.classification = {
373
+ kind: ["process.kill", "Promise.reject", "assert", "assert.ok"].includes(entry.callee) ? "sink-candidate" : "non-predicate",
374
+ reason: `closed-world review of exact source ${entry.sourceHash}; any changed call spelling creates an unowned entry`,
375
+ };
376
+ } else if (entry.kind === "outcome-candidate") {
377
+ entry.classification = {
378
+ kind: "non-outcome",
379
+ reason: `immutable returned binding is not a RED/BLOCKED/N0_TEST_CAPABLE constructor at exact source ${entry.sourceHash}`,
380
+ };
381
+ } else if (entry.kind === "success-constructor") {
382
+ entry.mutation = null;
383
+ entry.witness = null;
384
+ entry.acceptFlipSet = null;
385
+ entry.rejectDeltaSet = null;
386
+ entry.positiveRegressionSet = null;
387
+ entry.ownershipRecord = { kind: "owned-success", reason: "the sole N0_TEST_CAPABLE return constructor" };
388
+ }
389
+ }
390
+
391
+ manifest.floors.sharedContextPredicateAtoms ??= SHARED_CONTEXT_PREDICATE_ATOMS.size;
392
+ manifest.floors.sameCodeShadowEntries ??= SAME_CODE_SHADOW_WITNESSES.size;
393
+ manifest.floors.downstreamDomainShadowEntries = DOWNSTREAM_DOMAIN_SHADOW_WITNESSES.size;
394
+ manifest.floors.successPathCalls ??= SUCCESS_PATH_CALLS.size;
395
+ manifest.floors.delegatedOutcomeCalls ??= DELEGATED_OUTCOME_CALLS.size;
396
+ manifest.floors.ownershipGrowthReasons ??= {};
397
+ manifest.floors.ownershipGrowthReasons.rejectPreservingOwnership = "Reviewed exact-remainder growth: PR6-N0-REMAINDER-AMENDMENT with Assay rulings 4247/4249/4263, extended by PR6-N0-R7-ZERO-AMENDMENT and Assay ruling 4286";
398
+ manifest.floors.ownershipGrowthReasons.mixedOwnership = "Reviewed exact-remainder growth: PR6-N0-REMAINDER-AMENDMENT with Assay rulings 4247/4249/4263, extended by PR6-N0-R7-ZERO-AMENDMENT and Assay ruling 4286";
399
+ manifest.compounds = structuredClone(COMPOUNDS);
400
+ const compoundMembers = new Map(COMPOUNDS.flatMap((compound) => compound.memberIds.map((id) => [id, compound.id])));
401
+ for (const entry of manifest.entries) {
402
+ const compoundId = compoundMembers.get(entry.id);
403
+ if (!compoundId) continue;
404
+ entry.mutation = null;
405
+ entry.witness = null;
406
+ entry.acceptFlipSet = null;
407
+ entry.rejectDeltaSet = null;
408
+ entry.positiveRegressionSet = null;
409
+ entry.disposition = null;
410
+ entry.ownershipRecord = { kind: "compound-member", compoundId };
411
+ }
412
+ manifest.floors.compoundDispositionUnits = COMPOUNDS.length;
413
+ manifest.floors.compoundDispositionMembers = compoundMembers.size;
414
+
415
+ fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
416
+ const unsafeOperators = manifest.entries.filter((entry) => entry.mutation?.operator === "substitute-reviewed-expression").length;
417
+ const unpairedEntries = manifest.entries.filter((entry) => !entry.mutation && !entry.disposition && !entry.ownershipRecord
418
+ && !["unresolved-call", "outcome-candidate"].includes(entry.kind)).length;
419
+ if (unsafeOperators > 0 || unpairedEntries > 0) {
420
+ process.stderr.write(`N0_GUARD_MANIFEST_AUTHOR_INCOMPLETE unsafeOperators=${unsafeOperators} unpairedEntries=${unpairedEntries}\n`);
421
+ process.exitCode = 1;
422
+ } else {
423
+ process.stdout.write("N0_GUARD_MANIFEST_AUTHOR_GREEN operators safe and every executable entry owned\n");
424
+ }