@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,274 @@
1
+ import type { Pin } from "../gates/pin.ts";
2
+ import type { DangerousStateMember, WitnessSpec } from "./spec.ts";
3
+ /**
4
+ * THE RED-WITNESS HARNESS (kernel plan M2, M2-P2 step 3, step 4, step 5).
5
+ *
6
+ * A test guards a behavior only when it has been demonstrated RED against a
7
+ * dangerous state that intersects the phase diff and GREEN at head, in a
8
+ * pinned isolated run. This module evaluates one witness spec: refusal
9
+ * rules (a) to (g) first, each producing `red` with a reason naming its
10
+ * source, then per-member execution in a scratch clone the harness owns.
11
+ *
12
+ * ISOLATION (M2-C-4). Every member is evaluated in its own scratch clone
13
+ * under a directory this run created with mkdtemp. The caller's repository
14
+ * is only ever READ (git read commands and file reads through the delivered
15
+ * probes); after any run its HEAD and working tree are untouched.
16
+ *
17
+ * PINS (M2-C-5, and work-history decision D-P2-1). The delivered pin is
18
+ * five fields including ctimeMs, which userspace cannot restore, so pins
19
+ * bracket EACH TEST EXECUTION rather than the mutate-restore cycle: the red
20
+ * runs are bracketed by a pin pair over the dangerous tree they actually
21
+ * execute, and the green head run by a pair over the head tree. A
22
+ * difference inside either pair is `error` naming the path and the fields.
23
+ *
24
+ * REPORTER PIN (MECHANISMS.md, "Parsing another program's reporter
25
+ * output"). The child is always invoked with an explicit
26
+ * `--test-reporter tap`; a stream that does not open with `TAP version` is
27
+ * an error naming the expected and observed formats, never a widened parse.
28
+ *
29
+ * C-2 and C-3: children run in the foreground via spawnSync with a
30
+ * timeout; nothing here probes a process, detaches, or touches /proc.
31
+ */
32
+ export interface WitnessHooks {
33
+ /**
34
+ * DOCUMENTED IN-HARNESS TEST HOOK (M2-P2 criterion 7, M2R-009). Called
35
+ * once per member, between the green run's start and end pins, with the
36
+ * clone's absolute path. Exists so a pin witness can rewrite a file
37
+ * byte-identically inside the pinned window and prove the five-field pin
38
+ * catches it. Never set outside tests.
39
+ */
40
+ betweenPins?: (cloneDir: string) => void;
41
+ }
42
+ export interface DiffFile {
43
+ path: string;
44
+ /** git name-status letter (A, M, D, R...). */
45
+ status: string;
46
+ /** New-side [start, end] line ranges of changed hunks, 1-based inclusive. */
47
+ hunks: Array<[number, number]>;
48
+ }
49
+ export interface PhaseDiff {
50
+ baseSha: string;
51
+ headSha: string;
52
+ files: Map<string, DiffFile>;
53
+ }
54
+ export interface EvaluationInputs {
55
+ repoRoot: string;
56
+ headSha: string;
57
+ /**
58
+ * The ref or sha resolved per clone against the FETCHED remote (M2-P2
59
+ * step 7: merge-time re-verification is the `--baseline` parameter).
60
+ */
61
+ baselineRef: string;
62
+ diff: PhaseDiff;
63
+ destructiveCommands: string[];
64
+ behaviors: Set<string>;
65
+ /** Repo-relative test file path -> source at the audited head. */
66
+ testFiles: Map<string, string>;
67
+ /** Changed files the spawn grep matched (rule (f) derivation). */
68
+ spawningChangedFiles: string[];
69
+ scratchRoot: string;
70
+ /** True for the phase's own witnesses; rule (d) applies only to them. */
71
+ phaseOwn: boolean;
72
+ hooks?: WitnessHooks;
73
+ }
74
+ export interface MemberRun {
75
+ exitCode: number;
76
+ red: boolean;
77
+ failedNamedTests: string[];
78
+ passedNamedTests: string[];
79
+ missingNamedTests: string[];
80
+ }
81
+ export interface PinPairRecord {
82
+ start: Pin;
83
+ end: Pin;
84
+ equal: boolean;
85
+ }
86
+ export interface MemberRecord {
87
+ index: number;
88
+ member: DangerousStateMember;
89
+ description: string;
90
+ baselineSha?: string;
91
+ /** The applied dangerous-state diff, verbatim (git diff output). */
92
+ appliedDiff?: string;
93
+ mutatedLines?: {
94
+ file: string;
95
+ lines: number[];
96
+ };
97
+ preservesAssertedText?: boolean;
98
+ rate?: {
99
+ red: number;
100
+ total: number;
101
+ };
102
+ runs: MemberRun[];
103
+ redPins?: PinPairRecord;
104
+ greenPins?: PinPairRecord;
105
+ headGreen?: boolean;
106
+ unreachedArm?: {
107
+ file: string;
108
+ lines: number[];
109
+ greenTests: string[];
110
+ };
111
+ problem?: string;
112
+ }
113
+ export type WitnessStatus = "green" | "red" | "error";
114
+ export interface WitnessEvaluation {
115
+ witness: string;
116
+ specPath: string;
117
+ behavior: string;
118
+ status: WitnessStatus;
119
+ reasons: string[];
120
+ textAsserting: boolean;
121
+ assertedPatterns: string[];
122
+ testFiles: string[];
123
+ captures?: Array<{
124
+ path: string;
125
+ sha256: string;
126
+ provenance: string;
127
+ }>;
128
+ members: MemberRecord[];
129
+ }
130
+ interface GitResult {
131
+ ok: boolean;
132
+ status: number | null;
133
+ stdout: string;
134
+ stderr: string;
135
+ reason: string;
136
+ }
137
+ /**
138
+ * Run git with a pinned C locale (verification-m1-p3-fix-round.md U-8: a
139
+ * message-text classification with no locale pin silently stops matching in
140
+ * a localized environment).
141
+ */
142
+ export declare function gitIn(cwd: string, args: string[]): GitResult;
143
+ /**
144
+ * Compute the phase diff base...head: changed files with status and the
145
+ * new-side line ranges of every changed hunk.
146
+ */
147
+ export declare function computePhaseDiff(repoRoot: string, base: string, head: string): {
148
+ ok: true;
149
+ diff: PhaseDiff;
150
+ } | {
151
+ ok: false;
152
+ reason: string;
153
+ };
154
+ /**
155
+ * The spawn grep of rule (f), over the changed files' head-state contents.
156
+ * Exactly the plan's four tokens (M2-P2 step 4 rule (f)): a wider pattern
157
+ * (for example a bare `exec(`) false-positives on `RegExp.exec` calls and
158
+ * would derive a capture obligation from a file that spawns nothing.
159
+ */
160
+ export declare const SPAWN_GREP: RegExp;
161
+ /**
162
+ * The shell form of rule (f)'s derivation (CR-H2). A POSIX shell script that
163
+ * spawns another program and PARSES its output contains none of the four JS
164
+ * tokens, so `SPAWN_GREP` is blind to exactly where M1's V-2 lived
165
+ * (`bin/fm-*.sh` classifying git contention output). A shell spawn-and-parse
166
+ * is derived as the conjunction of two signals over the script text:
167
+ * - SPAWN: another program's output is captured (a pipeline `|`, a command
168
+ * substitution `$(...)` or backticks, or stdin consumed by `read`/`while
169
+ * read`);
170
+ * - PARSE: that output is classified or transformed (`grep`, `awk`, `sed`,
171
+ * `cut`, `tr`, a `case` branch, or a `[[ ... =~ ... ]]` regex test).
172
+ * The conjunction is deliberately narrow: a script that only runs a command
173
+ * for its exit status, with no capture and no classifier, is not "in that
174
+ * state" and is not burdened with a capture obligation. What this does NOT
175
+ * cover is stated in the work history (rule (f), shell residue).
176
+ */
177
+ export declare const SHELL_SPAWN: RegExp;
178
+ export declare const SHELL_PARSE: RegExp;
179
+ /** True when the shell script text both spawns a program and parses its output. */
180
+ export declare function shellSpawnsAndParses(text: string): boolean;
181
+ export interface TapTestPoint {
182
+ name: string;
183
+ ok: boolean;
184
+ skipped: boolean;
185
+ }
186
+ export type TapParse = {
187
+ ok: true;
188
+ tests: TapTestPoint[];
189
+ } | {
190
+ ok: false;
191
+ reason: string;
192
+ };
193
+ /**
194
+ * Parse a PINNED tap stream. The format is a controlled input: the child
195
+ * was invoked with `--test-reporter tap`, so a stream that does not open
196
+ * with `TAP version` is a reporter-pin failure naming both formats, never
197
+ * something to parse anyway.
198
+ */
199
+ export declare function parseTapStream(text: string): TapParse;
200
+ export interface TextAssertionDerivation {
201
+ textAsserting: boolean;
202
+ /** Document paths (repo-relative) the named tests' sources read. */
203
+ documents: string[];
204
+ /** Regex sources and literals the assertions apply to those contents. */
205
+ patterns: string[];
206
+ }
207
+ /**
208
+ * Rule (g)'s text-assertion detection, DERIVED from the named tests'
209
+ * sources rather than declared: a source that reads a document from a path
210
+ * outside `src/` and `test/` (a workflow, a manifest, a configuration
211
+ * document) and ASSERTS THAT DOCUMENT'S TEXT is text-asserting. The
212
+ * assertion is tied to the read result (a variable binding or an inline
213
+ * read), never a free-floating assert form, so a read consumed by a project
214
+ * function stays behaviour. Detection is syntactic and fails CONSERVATIVELY:
215
+ * a recognised assert form whose pattern is not statically extractable still
216
+ * marks the witness text-asserting (subject to rule (g)) rather than
217
+ * returning false. The derivation's limits are stated in the work history.
218
+ */
219
+ export declare function deriveTextAssertions(sources: string[]): TextAssertionDerivation;
220
+ /**
221
+ * Resolve named tests to the repo-relative test files whose head-state
222
+ * source contains the name literally. A name found nowhere is a spec
223
+ * defect the caller turns into a red reason.
224
+ */
225
+ export declare function resolveNamedTests(tests: string[], testFiles: Map<string, string>): {
226
+ files: string[];
227
+ missing: string[];
228
+ };
229
+ /**
230
+ * The 1-based line numbers a find text occupies, across every occurrence,
231
+ * multi-line finds included (a single-line scan misses those, and rule (d)
232
+ * plus the unreached-arm report both need the true span).
233
+ */
234
+ export declare function findOccurrenceLines(body: string, find: string): number[];
235
+ interface CloneOutcome {
236
+ dir?: string;
237
+ reason?: string;
238
+ }
239
+ /**
240
+ * Create a scratch clone of the audited repository at the audited head,
241
+ * with `origin` pointing at the audited repository's own origin when it
242
+ * has one (so baselines resolve against the real remote after a fetch,
243
+ * never a stale local ref), else at the audited repository itself.
244
+ */
245
+ export declare function makeClone(repoRoot: string, headSha: string, scratchRoot: string, label: string): CloneOutcome;
246
+ /**
247
+ * Evaluate one witness spec end to end. Refusal rules first; then, per
248
+ * declared dangerous-state member, a scratch clone, the member applied, the
249
+ * named tests run red `repeats` times, head restored, the named tests run
250
+ * green, everything pinned and recorded.
251
+ */
252
+ export declare function evaluateWitness(spec: WitnessSpec, specPath: string, inputs: EvaluationInputs): WitnessEvaluation;
253
+ /** Create the scratch root this harness owns; the caller removes it. */
254
+ export declare function makeScratchRoot(): string;
255
+ /** Remove a scratch root created by makeScratchRoot. */
256
+ export declare function removeScratchRoot(root: string): void;
257
+ /**
258
+ * Read the head-state sources of every test file under `test/`, from git
259
+ * rather than the working tree, because on pull_request events the checkout
260
+ * is a synthetic merge commit and the audited head is `--head`.
261
+ */
262
+ export declare function readTestFilesAtHead(repoRoot: string, headSha: string): {
263
+ ok: true;
264
+ files: Map<string, string>;
265
+ } | {
266
+ ok: false;
267
+ reason: string;
268
+ };
269
+ /** Resolve the absolute path of a repository root, refusing a non-directory. */
270
+ export declare function resolveRepoRoot(path: string): {
271
+ root?: string;
272
+ reason?: string;
273
+ };
274
+ export {};