@tiphys/kernel 0.0.0 → 0.1.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 (181) hide show
  1. package/AGENTS.md +611 -0
  2. package/LICENSE +202 -0
  3. package/assurance-modes.yaml +278 -0
  4. package/checklists/clean-room.yaml +325 -0
  5. package/checklists/env-failure-diagnosis.yaml +68 -0
  6. package/checklists/flake-playbook.yaml +68 -0
  7. package/checklists/hazard-review.yaml +144 -0
  8. package/checklists/plan-review.yaml +103 -0
  9. package/dist/bin/tiphys.d.ts +2 -0
  10. package/dist/bin/tiphys.js +14 -0
  11. package/dist/src/brief.d.ts +32 -0
  12. package/dist/src/brief.js +59 -0
  13. package/dist/src/checklists.d.ts +169 -0
  14. package/dist/src/checklists.js +310 -0
  15. package/dist/src/checks.d.ts +828 -0
  16. package/dist/src/checks.js +3314 -0
  17. package/dist/src/cli.d.ts +9 -0
  18. package/dist/src/cli.js +57 -0
  19. package/dist/src/commands/brief.d.ts +92 -0
  20. package/dist/src/commands/brief.js +320 -0
  21. package/dist/src/commands/checklist.d.ts +42 -0
  22. package/dist/src/commands/checklist.js +168 -0
  23. package/dist/src/commands/doctor.d.ts +35 -0
  24. package/dist/src/commands/doctor.js +605 -0
  25. package/dist/src/commands/gates.d.ts +9 -0
  26. package/dist/src/commands/gates.js +360 -0
  27. package/dist/src/commands/init.d.ts +30 -0
  28. package/dist/src/commands/init.js +128 -0
  29. package/dist/src/commands/lock.d.ts +1 -0
  30. package/dist/src/commands/lock.js +229 -0
  31. package/dist/src/commands/mode.d.ts +40 -0
  32. package/dist/src/commands/mode.js +134 -0
  33. package/dist/src/commands/plan.d.ts +20 -0
  34. package/dist/src/commands/plan.js +105 -0
  35. package/dist/src/commands/pool.d.ts +1 -0
  36. package/dist/src/commands/pool.js +128 -0
  37. package/dist/src/commands/spawn.d.ts +1 -0
  38. package/dist/src/commands/spawn.js +146 -0
  39. package/dist/src/commands/status.d.ts +19 -0
  40. package/dist/src/commands/status.js +120 -0
  41. package/dist/src/commands/teardown.d.ts +1 -0
  42. package/dist/src/commands/teardown.js +79 -0
  43. package/dist/src/commands/tuition.d.ts +21 -0
  44. package/dist/src/commands/tuition.js +218 -0
  45. package/dist/src/commands/validate.d.ts +78 -0
  46. package/dist/src/commands/validate.js +360 -0
  47. package/dist/src/commands/watch.d.ts +1 -0
  48. package/dist/src/commands/watch.js +172 -0
  49. package/dist/src/exec/env.d.ts +128 -0
  50. package/dist/src/exec/env.js +190 -0
  51. package/dist/src/fleet.d.ts +51 -0
  52. package/dist/src/fleet.js +80 -0
  53. package/dist/src/gates/adapters/http-json.d.ts +5 -0
  54. package/dist/src/gates/adapters/http-json.js +283 -0
  55. package/dist/src/gates/adapters/migrations-command.d.ts +1 -0
  56. package/dist/src/gates/adapters/migrations-command.js +373 -0
  57. package/dist/src/gates/citations.d.ts +408 -0
  58. package/dist/src/gates/citations.js +1163 -0
  59. package/dist/src/gates/coverage.d.ts +284 -0
  60. package/dist/src/gates/coverage.js +701 -0
  61. package/dist/src/gates/credentials.d.ts +74 -0
  62. package/dist/src/gates/credentials.js +533 -0
  63. package/dist/src/gates/deploy.d.ts +1 -0
  64. package/dist/src/gates/deploy.js +33 -0
  65. package/dist/src/gates/manifest.d.ts +99 -0
  66. package/dist/src/gates/manifest.js +208 -0
  67. package/dist/src/gates/migrations.d.ts +1 -0
  68. package/dist/src/gates/migrations.js +36 -0
  69. package/dist/src/gates/pin.d.ts +114 -0
  70. package/dist/src/gates/pin.js +154 -0
  71. package/dist/src/gates/red-witness.d.ts +22 -0
  72. package/dist/src/gates/red-witness.js +390 -0
  73. package/dist/src/gates/release.d.ts +283 -0
  74. package/dist/src/gates/release.js +820 -0
  75. package/dist/src/gates/result.d.ts +116 -0
  76. package/dist/src/gates/result.js +91 -0
  77. package/dist/src/gates/run.d.ts +566 -0
  78. package/dist/src/gates/run.js +1536 -0
  79. package/dist/src/gates/schemas/citation-config.schema.json +59 -0
  80. package/dist/src/gates/schemas/coverage-config.schema.json +77 -0
  81. package/dist/src/gates/schemas/gate-manifest.schema.json +125 -0
  82. package/dist/src/gates/schemas/gate-result.schema.json +160 -0
  83. package/dist/src/gates/schemas/phase-declaration.schema.json +42 -0
  84. package/dist/src/gates/schemas/release-record.schema.json +119 -0
  85. package/dist/src/gates/schemas/verifier-config.schema.json +101 -0
  86. package/dist/src/gates/schemas/witness-spec.schema.json +110 -0
  87. package/dist/src/gates/scope.d.ts +131 -0
  88. package/dist/src/gates/scope.js +1018 -0
  89. package/dist/src/gates/suite.d.ts +217 -0
  90. package/dist/src/gates/suite.js +927 -0
  91. package/dist/src/gates/validate.d.ts +121 -0
  92. package/dist/src/gates/validate.js +414 -0
  93. package/dist/src/hooks.d.ts +32 -0
  94. package/dist/src/hooks.js +62 -0
  95. package/dist/src/liveness.d.ts +321 -0
  96. package/dist/src/liveness.js +396 -0
  97. package/dist/src/lock.d.ts +178 -0
  98. package/dist/src/lock.js +500 -0
  99. package/dist/src/modes.d.ts +149 -0
  100. package/dist/src/modes.js +258 -0
  101. package/dist/src/path-identity.d.ts +2 -0
  102. package/dist/src/path-identity.js +10 -0
  103. package/dist/src/plan.d.ts +73 -0
  104. package/dist/src/plan.js +153 -0
  105. package/dist/src/pool.d.ts +130 -0
  106. package/dist/src/pool.js +721 -0
  107. package/dist/src/roles.d.ts +430 -0
  108. package/dist/src/roles.js +734 -0
  109. package/dist/src/spawn.d.ts +177 -0
  110. package/dist/src/spawn.js +332 -0
  111. package/dist/src/status.d.ts +91 -0
  112. package/dist/src/status.js +119 -0
  113. package/dist/src/task.d.ts +264 -0
  114. package/dist/src/task.js +305 -0
  115. package/dist/src/teardown.d.ts +32 -0
  116. package/dist/src/teardown.js +314 -0
  117. package/dist/src/tuition.d.ts +159 -0
  118. package/dist/src/tuition.js +311 -0
  119. package/dist/src/validate.d.ts +230 -0
  120. package/dist/src/validate.js +732 -0
  121. package/dist/src/version.d.ts +3 -0
  122. package/dist/src/version.js +38 -0
  123. package/dist/src/watcher.d.ts +275 -0
  124. package/dist/src/watcher.js +859 -0
  125. package/dist/src/witness/run.d.ts +274 -0
  126. package/dist/src/witness/run.js +1327 -0
  127. package/dist/src/witness/spec.d.ts +102 -0
  128. package/dist/src/witness/spec.js +253 -0
  129. package/dist/tsconfig.src.tsbuildinfo +1 -0
  130. package/gate-registry.yaml +390 -0
  131. package/gates.manifest.json +195 -0
  132. package/package.json +57 -3
  133. package/role-model-config.yaml +88 -0
  134. package/roles/README.md +128 -0
  135. package/roles/_shared-dispatch-contract.md +87 -0
  136. package/roles/adversarial-plan-reviewer.md +80 -0
  137. package/roles/clean-room-reviewer.md +140 -0
  138. package/roles/implementer.md +460 -0
  139. package/roles/investigator.md +138 -0
  140. package/roles/plan-writer.md +95 -0
  141. package/schemas/README.md +81 -0
  142. package/schemas/assurance-modes.schema.json +264 -0
  143. package/schemas/charter.schema.json +166 -0
  144. package/schemas/checklist.schema.json +114 -0
  145. package/schemas/decision-record.schema.json +88 -0
  146. package/schemas/final-report.schema.json +90 -0
  147. package/schemas/finding.schema.json +106 -0
  148. package/schemas/gate-registry.schema.json +260 -0
  149. package/schemas/mechanism-index.schema.json +94 -0
  150. package/schemas/plan.schema.json +300 -0
  151. package/schemas/report.schema.json +579 -0
  152. package/schemas/role-brief.schema.json +105 -0
  153. package/schemas/role-model-config.schema.json +90 -0
  154. package/schemas/status-line.schema.json +40 -0
  155. package/schemas/tuition.schema.json +191 -0
  156. package/schemas/verdict.schema.json +289 -0
  157. package/schemas/work-history.schema.json +183 -0
  158. package/templates/charter.example.yaml +54 -0
  159. package/templates/decision-record.example.yaml +27 -0
  160. package/templates/final-report.example.yaml +80 -0
  161. package/templates/plan.example.yaml +87 -0
  162. package/templates/report.example.yaml +236 -0
  163. package/templates/warnings.md +74 -0
  164. package/templates/work-history.example.yaml +185 -0
  165. package/tuition/README.md +76 -0
  166. package/tuition/T-001.yaml +48 -0
  167. package/tuition/T-002.yaml +51 -0
  168. package/tuition/T-003.yaml +100 -0
  169. package/tuition/T-004.yaml +52 -0
  170. package/tuition/T-005.yaml +72 -0
  171. package/tuition/T-006.yaml +81 -0
  172. package/tuition/T-007.yaml +56 -0
  173. package/tuition/T-008.yaml +111 -0
  174. package/tuition/T-009.yaml +50 -0
  175. package/tuition/T-015.yaml +36 -0
  176. package/tuition/T-016.yaml +36 -0
  177. package/tuition/T-017.yaml +46 -0
  178. package/tuition/T-018.yaml +84 -0
  179. package/tuition/T-021.yaml +40 -0
  180. package/tuition/T-022.yaml +36 -0
  181. package/tuition/mechanism-index.yaml +256 -0
@@ -0,0 +1,168 @@
1
+ /**
2
+ * `tiphys checklist resolve --checklist <id> [--extra <file>] [--framing <id>]`
3
+ * (kernel plan M3, M3-P7 step 5; R-054, T-001).
4
+ *
5
+ * PROBE INJECTION AS DATA. The orchestrator writes a per-phase probe file and
6
+ * this command merges it into the canonical checklist, so a per-phase probe
7
+ * set is reviewable and reusable instead of living in a dispatch prompt
8
+ * nobody can diff. The AGENTS.md duty to WRITE them is M3-P9's; this is the
9
+ * mechanism they plug into.
10
+ *
11
+ * IT VALIDATES BEFORE IT SERVES. Both documents go through exactly what
12
+ * `tiphys validate --type checklist` runs, schema first and derived checks
13
+ * second, and a document that fails is REFUSED rather than partly printed.
14
+ * That is the M3-P3 `mode show` fix round applied at the site that would
15
+ * otherwise repeat it: as first shipped, that command read a document and
16
+ * printed it, invoking neither the schema nor any registered check, so every
17
+ * guard its phase built was bypassed on the one path built for humans. A
18
+ * partial answer from an invalid checklist is worse than an error, because
19
+ * the reviewer cannot tell.
20
+ *
21
+ * THE CONTEXT FOR THE DERIVED CHECKS IS THE PACKAGE ROOT, which is where
22
+ * `gate-registry.yaml` sits, so `gate-probes-resolve` RUNS here rather than
23
+ * SKIPPING. A skip fails the run, and a command that always failed would be a
24
+ * command nobody uses.
25
+ *
26
+ * Exit codes:
27
+ * 0 both documents are valid, the framing resolved, and the list printed
28
+ * 1 a document could not be read or is invalid, an extra probe collided
29
+ * or required no evidence, or the named framing is not declared
30
+ * 64 usage error (BSD sysexits EX_USAGE)
31
+ *
32
+ * A FRAMING ID THAT IS NOT DECLARED IS 1, NOT 64, for the reason
33
+ * `tiphys mode show` records for an undeclared mode: 64 means the caller used
34
+ * the command wrongly, 1 means the command worked and the answer is no.
35
+ * `--framing fix-round` against a checklist that declares only
36
+ * `criteria-contract` is a well formed question with a negative answer.
37
+ */
38
+ import { runChecks } from "../checks.js";
39
+ import { formatDiagnostics, validateInstance } from "../validate.js";
40
+ import { loadTypeSchema } from "./validate.js";
41
+ import { packageRoot } from "../modes.js";
42
+ import { readChecklistFile, readShippedChecklist, renderResolution, resolveChecklist, shippedChecklistIds, } from "../checklists.js";
43
+ /** The artifact type this command reads, and the type its checks are registered for. */
44
+ const CHECKLIST_TYPE = "checklist";
45
+ /** Exit code for usage errors, per BSD sysexits EX_USAGE. */
46
+ export const EX_USAGE = 64;
47
+ function usage() {
48
+ return "usage: tiphys checklist resolve --checklist <id> [--extra <file>] [--framing <id>]";
49
+ }
50
+ function parseArgs(argv) {
51
+ const options = {};
52
+ const known = new Map([
53
+ ["--checklist", "checklist"],
54
+ ["--extra", "extra"],
55
+ ["--framing", "framing"],
56
+ ]);
57
+ for (let index = 0; index < argv.length; index += 1) {
58
+ const argument = argv[index];
59
+ const field = known.get(argument);
60
+ if (field === undefined) {
61
+ return { usageError: `unknown argument ${argument}` };
62
+ }
63
+ const value = argv[index + 1];
64
+ if (value === undefined || value.startsWith("--")) {
65
+ return { usageError: `${argument} requires a value` };
66
+ }
67
+ options[field] = value;
68
+ index += 1;
69
+ }
70
+ if (options.checklist === undefined) {
71
+ return { usageError: "--checklist is required" };
72
+ }
73
+ return { options };
74
+ }
75
+ function fail(reason, code) {
76
+ process.stderr.write(`tiphys checklist: ${reason}\n`);
77
+ if (code === EX_USAGE) {
78
+ process.stderr.write(`${usage()}\n`);
79
+ }
80
+ return code;
81
+ }
82
+ /**
83
+ * Schema, then derived checks, on ONE document. Returns the lines to print
84
+ * when it is invalid, empty when it is not.
85
+ *
86
+ * The same two calls `tiphys validate` makes, in the same order, so the two
87
+ * commands cannot drift into disagreeing about what a valid checklist is.
88
+ */
89
+ function invalidityLines(checklist, context) {
90
+ const schemaLines = formatDiagnostics(validateInstance(loadTypeSchema(CHECKLIST_TYPE), checklist.raw));
91
+ const checks = runChecks(CHECKLIST_TYPE, checklist.raw, context);
92
+ return schemaLines.length > 0 || checks.failed ? [...schemaLines, ...checks.lines] : [];
93
+ }
94
+ export function cmdChecklist(argv) {
95
+ const [subcommand, ...rest] = argv;
96
+ if (subcommand !== "resolve") {
97
+ return fail(subcommand === undefined
98
+ ? "a subcommand is required"
99
+ : `unknown subcommand ${subcommand}`, EX_USAGE);
100
+ }
101
+ const parsed = parseArgs(rest);
102
+ if (parsed.options === undefined) {
103
+ return fail(parsed.usageError ?? "usage error", EX_USAGE);
104
+ }
105
+ const { checklist: checklistId, extra: extraPath, framing } = parsed.options;
106
+ const canonical = readShippedChecklist(checklistId);
107
+ if (!canonical.ok) {
108
+ return fail(canonical.reason, 1);
109
+ }
110
+ /* The package root holds `gate-registry.yaml`, so the cross-document check
111
+ resolves rather than skipping. `packageRoot()` throws when the shipped
112
+ layout is not above this module, which is an incomplete installation and
113
+ not a caller error: one line, never a stack trace. */
114
+ let context;
115
+ try {
116
+ context = packageRoot();
117
+ }
118
+ catch (error) {
119
+ return fail(String(error instanceof Error ? error.message : error), 1);
120
+ }
121
+ const canonicalProblems = invalidityLines(canonical.value, context);
122
+ if (canonicalProblems.length > 0) {
123
+ process.stderr.write(`tiphys checklist: ${canonical.value.path} is not a valid ${CHECKLIST_TYPE} document, so it is not served\n`);
124
+ for (const line of canonicalProblems) {
125
+ process.stderr.write(`${line}\n`);
126
+ }
127
+ return 1;
128
+ }
129
+ let extra;
130
+ if (extraPath !== undefined) {
131
+ const read = readChecklistFile(extraPath, extraPath);
132
+ if (!read.ok) {
133
+ return fail(read.reason, 1);
134
+ }
135
+ /* THE EXTRA FILE IS A CHECKLIST DOCUMENT AND IS HELD TO THE SAME
136
+ CONTRACT. Making it a bespoke fragment shape would give the extension
137
+ mechanism a second, weaker schema, and R-054's whole point is that a
138
+ per-phase probe set is data a reviewer can validate on its own. */
139
+ const extraProblems = invalidityLines(read.value, context);
140
+ if (extraProblems.length > 0) {
141
+ process.stderr.write(`tiphys checklist: ${read.value.path} is not a valid ${CHECKLIST_TYPE} document, so it is not merged\n`);
142
+ for (const line of extraProblems) {
143
+ process.stderr.write(`${line}\n`);
144
+ }
145
+ return 1;
146
+ }
147
+ extra = read.value;
148
+ }
149
+ const resolved = resolveChecklist({
150
+ checklist: canonical.value,
151
+ extra,
152
+ framingId: framing,
153
+ });
154
+ if (!resolved.ok) {
155
+ for (const reason of resolved.reasons) {
156
+ process.stderr.write(`tiphys checklist: ${reason}\n`);
157
+ }
158
+ return 1;
159
+ }
160
+ for (const line of renderResolution(canonical.value, resolved.value)) {
161
+ process.stdout.write(`${line}\n`);
162
+ }
163
+ return 0;
164
+ }
165
+ /** The shipped ids, for the usage line and for tests that must not hand-list them. */
166
+ export function declaredChecklistIds() {
167
+ return shippedChecklistIds();
168
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * tiphys doctor: deterministic health checks over the current directory as
3
+ * a fleet home (kernel plan v1, M1-P2 step 3). One line per check, format
4
+ * "CHECK <name> PASS|WARN|FAIL <detail>", exit 0 only if no check FAILs.
5
+ * Every check is file-based (substrate-neutral, DR-0007): no process is
6
+ * ever probed (plan constraint C-2), and no currency is ever read off a
7
+ * log tail (plan constraint C-1; this phase's checks read no task state,
8
+ * and any later task-currency check must read tasks/<id>/meta.json and the
9
+ * turn-end file only).
10
+ */
11
+ export type CheckStatus = "PASS" | "WARN" | "FAIL";
12
+ export interface CheckResult {
13
+ name: string;
14
+ status: CheckStatus;
15
+ detail: string;
16
+ /** Names the WARN condition a profile may promote to FAIL (EXT-F-08). */
17
+ condition?: string;
18
+ }
19
+ /**
20
+ * Readiness profiles (EXT-F-08): a profile promotes its required WARN
21
+ * conditions to FAIL, so exit 0 under a profile means ready for that mode
22
+ * (SC-011: never green by omission). The M1 table is deliberately small
23
+ * and grows at M2/M3 with the gate registry.
24
+ */
25
+ export declare const PROFILES: Record<string, readonly string[]>;
26
+ /**
27
+ * Evaluate a running node version against the kernel's engines.node range.
28
+ * Fails closed (CR-102): only the exact ">=<major>[.<minor>[.<patch>]]"
29
+ * form is interpreted, compared over the full version tuple; any other
30
+ * range shape, and any unparseable version, is FAIL with a reason line,
31
+ * never a silent truncation.
32
+ */
33
+ export declare function nodeCheckFor(range: string, version: string): CheckResult;
34
+ export declare function runChecks(root: string): CheckResult[];
35
+ export declare function cmdDoctor(args: string[]): number;