@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,116 @@
1
+ import type { Pin } from "./pin.ts";
2
+ /**
3
+ * THE GATE RESULT RECORD (kernel plan M2, M2-P1 step 2).
4
+ *
5
+ * Every gate this milestone ships emits exactly one of these, and the exit
6
+ * test counts them. Nine phases build against this shape, so it is written
7
+ * once here and never re-derived: a gate that invents its own record is a
8
+ * review finding.
9
+ *
10
+ * THE STATUS VOCABULARY IS FOUR WORDS AND THEY ARE NOT INTERCHANGEABLE.
11
+ *
12
+ * green the gate did its work and the property holds
13
+ * red the gate did its work and the property does not hold
14
+ * not-applicable the gate's precondition WAS EVALUATED and found unmet
15
+ * error the gate could not reach a verdict
16
+ *
17
+ * `not-applicable` is the one most easily abused, and SC-011 is why it is
18
+ * spelled out: it ASSERTS that a precondition was evaluated. A gate that
19
+ * could not evaluate its precondition, could not find its input, or was
20
+ * invoked without a parameter it needs is `error` and never
21
+ * `not-applicable` and never green (M2-C-3, fail closed). "Never green by
22
+ * omission" is the whole point of the vocabulary.
23
+ *
24
+ * M2-C-2, ENFORCED HERE RATHER THAN REMEMBERED. A record with status
25
+ * `green` and `units` 0 claims a property holds while having examined
26
+ * nothing. `makeGateResult` rewrites it to `error` naming M2-C-2 and marks
27
+ * it `vacuous`, and there is no other constructor, so a gate built on this
28
+ * module cannot emit one. The runner applies the SAME rule again when it
29
+ * ingests a record, because a gate written in another language or by hand
30
+ * does not go through this constructor and must not be able to smuggle a
31
+ * vacuous green past the runner (see `ingestRecord` in run.ts).
32
+ *
33
+ * WHY `vacuous` IS A FIELD AND NOT A STRING TO GREP FOR. Step 8 requires
34
+ * the summary to count `vacuous` as a strict subset of `error`. Once the
35
+ * rewrite has happened, a vacuous error and an ordinary error are the same
36
+ * status, so the runner would have to recover the distinction by
37
+ * pattern-matching the detail text of a record another program wrote.
38
+ * MECHANISMS.md's row "Deciding what another program will do by
39
+ * pattern-matching the text of a file it consumes" is exactly that
40
+ * mechanism and it cost this project four rounds. So the distinction is
41
+ * carried structurally. This is an addition to the plan's field list and is
42
+ * declared as such in the work history.
43
+ */
44
+ /** The four words. Nothing else is a status. */
45
+ export type GateStatus = "green" | "red" | "not-applicable" | "error";
46
+ export declare const GATE_STATUSES: readonly GateStatus[];
47
+ /**
48
+ * The gate subprocess exit-code table, and the runner's own aggregate exit
49
+ * codes. One table, used by both ends of the pipe, so a gate and the runner
50
+ * can never disagree about what 20 means.
51
+ *
52
+ * 64 is EX_USAGE and is the CLI's, not a gate status: a gate that exits 64
53
+ * was invoked wrongly, which means it measured nothing, which the runner
54
+ * records as `error`.
55
+ */
56
+ export declare const EXIT_GREEN = 0;
57
+ export declare const EXIT_RED = 1;
58
+ export declare const EXIT_NOT_APPLICABLE = 20;
59
+ export declare const EXIT_GATE_ERROR = 21;
60
+ export declare function exitCodeForStatus(status: GateStatus): number;
61
+ export declare function statusForExitCode(code: number): GateStatus | undefined;
62
+ /**
63
+ * What a precondition evaluation concluded. `met` false means EVALUATED AND
64
+ * UNMET; an evaluation that could not conclude produces no PreconditionRecord
65
+ * at all, because the gate is `error` and the reason says so.
66
+ */
67
+ export interface PreconditionRecord {
68
+ id: string;
69
+ met: boolean;
70
+ reason: string;
71
+ evidence?: string[];
72
+ }
73
+ /** Start and end pins for the gates M2-C-5 binds. */
74
+ export interface PinPair {
75
+ start: Pin;
76
+ end: Pin;
77
+ }
78
+ export interface GateResult {
79
+ gate: string;
80
+ status: GateStatus;
81
+ units: number;
82
+ unitLabel: string;
83
+ startedAt: string;
84
+ endedAt: string;
85
+ /** Set only when the M2-C-2 rewrite fired. See the module comment. */
86
+ vacuous?: boolean;
87
+ precondition?: PreconditionRecord;
88
+ pin?: PinPair;
89
+ detail: string;
90
+ /** Paths relative to the evidence directory. */
91
+ evidence: string[];
92
+ }
93
+ /** The fields a caller supplies; the constructor owns `vacuous`. */
94
+ export interface GateResultFields {
95
+ gate: string;
96
+ status: GateStatus;
97
+ units: number;
98
+ unitLabel: string;
99
+ startedAt: string;
100
+ endedAt: string;
101
+ precondition?: PreconditionRecord;
102
+ pin?: PinPair;
103
+ detail: string;
104
+ evidence?: string[];
105
+ }
106
+ export declare const M2_C_2_DETAIL: string;
107
+ /**
108
+ * THE ONLY CONSTRUCTOR. Applies the M2-C-2 rewrite, so a green record with
109
+ * zero units cannot be constructed. `units` is coerced to a non-negative
110
+ * integer: a negative or fractional unit count is not a smaller measurement,
111
+ * it is an unusable one, so it is treated as zero and therefore triggers the
112
+ * same rewrite when the status was green.
113
+ */
114
+ export declare function makeGateResult(fields: GateResultFields): GateResult;
115
+ /** Serialize a record the way every kernel JSON state file is written. */
116
+ export declare function renderGateResult(result: GateResult): string;
@@ -0,0 +1,91 @@
1
+ export const GATE_STATUSES = [
2
+ "green",
3
+ "red",
4
+ "not-applicable",
5
+ "error",
6
+ ];
7
+ /**
8
+ * The gate subprocess exit-code table, and the runner's own aggregate exit
9
+ * codes. One table, used by both ends of the pipe, so a gate and the runner
10
+ * can never disagree about what 20 means.
11
+ *
12
+ * 64 is EX_USAGE and is the CLI's, not a gate status: a gate that exits 64
13
+ * was invoked wrongly, which means it measured nothing, which the runner
14
+ * records as `error`.
15
+ */
16
+ export const EXIT_GREEN = 0;
17
+ export const EXIT_RED = 1;
18
+ export const EXIT_NOT_APPLICABLE = 20;
19
+ export const EXIT_GATE_ERROR = 21;
20
+ export function exitCodeForStatus(status) {
21
+ if (status === "green") {
22
+ return EXIT_GREEN;
23
+ }
24
+ if (status === "red") {
25
+ return EXIT_RED;
26
+ }
27
+ if (status === "not-applicable") {
28
+ return EXIT_NOT_APPLICABLE;
29
+ }
30
+ return EXIT_GATE_ERROR;
31
+ }
32
+ export function statusForExitCode(code) {
33
+ if (code === EXIT_GREEN) {
34
+ return "green";
35
+ }
36
+ if (code === EXIT_RED) {
37
+ return "red";
38
+ }
39
+ if (code === EXIT_NOT_APPLICABLE) {
40
+ return "not-applicable";
41
+ }
42
+ if (code === EXIT_GATE_ERROR) {
43
+ return "error";
44
+ }
45
+ return undefined;
46
+ }
47
+ export const M2_C_2_DETAIL = "M2-C-2 (never green by omission): a gate reporting green with units 0 " +
48
+ "examined nothing, so this record is error";
49
+ /**
50
+ * THE ONLY CONSTRUCTOR. Applies the M2-C-2 rewrite, so a green record with
51
+ * zero units cannot be constructed. `units` is coerced to a non-negative
52
+ * integer: a negative or fractional unit count is not a smaller measurement,
53
+ * it is an unusable one, so it is treated as zero and therefore triggers the
54
+ * same rewrite when the status was green.
55
+ */
56
+ export function makeGateResult(fields) {
57
+ const units = Number.isFinite(fields.units) && Number.isInteger(fields.units) && fields.units > 0
58
+ ? fields.units
59
+ : 0;
60
+ const base = {
61
+ gate: fields.gate,
62
+ status: fields.status,
63
+ units,
64
+ unitLabel: fields.unitLabel,
65
+ startedAt: fields.startedAt,
66
+ endedAt: fields.endedAt,
67
+ detail: fields.detail,
68
+ evidence: fields.evidence === undefined ? [] : [...fields.evidence],
69
+ };
70
+ if (fields.precondition !== undefined) {
71
+ base.precondition = fields.precondition;
72
+ }
73
+ if (fields.pin !== undefined) {
74
+ base.pin = fields.pin;
75
+ }
76
+ if (base.status === "green" && base.units === 0) {
77
+ return {
78
+ ...base,
79
+ status: "error",
80
+ vacuous: true,
81
+ detail: base.detail === ""
82
+ ? M2_C_2_DETAIL
83
+ : `${M2_C_2_DETAIL}; the gate reported: ${base.detail}`,
84
+ };
85
+ }
86
+ return base;
87
+ }
88
+ /** Serialize a record the way every kernel JSON state file is written. */
89
+ export function renderGateResult(result) {
90
+ return `${JSON.stringify(result, null, 2)}\n`;
91
+ }