crysk 0.0.0 → 0.3.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 (229) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +609 -3
  3. package/bin/pr-hero.js +166 -0
  4. package/config/models/anthropic.json +5 -0
  5. package/dist/SKILL-7e3725zn.md +496 -0
  6. package/dist/SKILL-7q35wcaz.md +66 -0
  7. package/dist/SKILL-9at22381.md +74 -0
  8. package/dist/SKILL-ex2hxxh3.md +134 -0
  9. package/dist/adjudicator-dtg2axnh.md +86 -0
  10. package/dist/admission-config.example-a9vqmmad.json +9 -0
  11. package/dist/ci-admission-camfbx2b.md +122 -0
  12. package/dist/cli.js +42292 -0
  13. package/dist/consolidate-ac0mnfyj.md +24 -0
  14. package/dist/deep-review-lifecycle-m698ybjp.md +362 -0
  15. package/dist/deep-review-logic-a6b1gczf.md +156 -0
  16. package/dist/deep-review-parity-0ec904db.md +120 -0
  17. package/dist/deep-review-reliability-qyakbjb9.md +125 -0
  18. package/dist/deep-review-resilience-3tz8y26e.md +118 -0
  19. package/dist/index.js +20190 -0
  20. package/dist/opencode-ci-7b0be64p.md +141 -0
  21. package/dist/review-refuter-j4e9gezy.md +71 -0
  22. package/dist/scout-yvp153q7.md +140 -0
  23. package/dist/summarizer-zca44nxa.md +18 -0
  24. package/dist/workflow-w1g9szna.yml +151 -0
  25. package/package.json +81 -4
  26. package/prompts/consolidate.md +24 -0
  27. package/prompts/default/PROVENANCE.md +18 -0
  28. package/prompts/default/deep-review-lifecycle.md +362 -0
  29. package/prompts/default/deep-review-logic.md +156 -0
  30. package/prompts/default/deep-review-parity.md +120 -0
  31. package/prompts/default/deep-review-reliability.md +125 -0
  32. package/prompts/default/deep-review-resilience.md +118 -0
  33. package/prompts/default/review-refuter.md +71 -0
  34. package/prompts/scout.md +140 -0
  35. package/prompts/summarizer.md +18 -0
  36. package/skills/crysk/SKILL.md +74 -0
  37. package/skills/crysk-ci-setup/SKILL.md +134 -0
  38. package/skills/crysk-ci-setup/assets/admission-config.example.json +9 -0
  39. package/skills/crysk-ci-setup/assets/workflow.yml +151 -0
  40. package/skills/crysk-ci-setup/references/ci-admission.md +122 -0
  41. package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
  42. package/skills/crysk-loop/SKILL.md +496 -0
  43. package/skills/crysk-loop/adjudicator.md +86 -0
  44. package/skills/crysk-pr/SKILL.md +66 -0
  45. package/src/agent-env.ts +1084 -0
  46. package/src/asset-manifest.ts +83 -0
  47. package/src/assets.d.ts +6 -0
  48. package/src/assets.ts +183 -0
  49. package/src/brand-paths.ts +155 -0
  50. package/src/brand.ts +255 -0
  51. package/src/ci/admission-ledger.ts +350 -0
  52. package/src/ci/classify-error.ts +73 -0
  53. package/src/ci/cli-record.ts +271 -0
  54. package/src/ci/force-comment.ts +39 -0
  55. package/src/ci/gates.ts +923 -0
  56. package/src/ci/outcome.ts +2181 -0
  57. package/src/ci/override.ts +187 -0
  58. package/src/ci/publish.ts +1639 -0
  59. package/src/ci/reporter.ts +626 -0
  60. package/src/ci/review-admission.ts +901 -0
  61. package/src/ci/review-levels.ts +310 -0
  62. package/src/ci/review-policy.ts +18 -0
  63. package/src/ci/review-risk.ts +184 -0
  64. package/src/ci/setup.ts +844 -0
  65. package/src/ci/trigger.ts +1353 -0
  66. package/src/cli.ts +348 -0
  67. package/src/commands/activity.ts +67 -0
  68. package/src/commands/ci-setup-questions.ts +397 -0
  69. package/src/commands/ci-setup.ts +381 -0
  70. package/src/commands/config.ts +99 -0
  71. package/src/commands/doctor.ts +108 -0
  72. package/src/commands/init.ts +139 -0
  73. package/src/commands/mcp.ts +10 -0
  74. package/src/commands/menu.ts +129 -0
  75. package/src/commands/post.ts +302 -0
  76. package/src/commands/skills.ts +83 -0
  77. package/src/commands/status.ts +173 -0
  78. package/src/commands/triage.ts +342 -0
  79. package/src/commands/uninstall.ts +37 -0
  80. package/src/commands/upgrade.ts +214 -0
  81. package/src/commands/usage.ts +98 -0
  82. package/src/compare/compare.ts +28 -0
  83. package/src/compare/floor-test.ts +471 -0
  84. package/src/compare/martian-adapter.ts +80 -0
  85. package/src/config/config.ts +267 -0
  86. package/src/corpus/corpus.ts +1094 -0
  87. package/src/corpus/preflight.ts +1789 -0
  88. package/src/diversity/accounting.ts +90 -0
  89. package/src/diversity/adjudication.ts +145 -0
  90. package/src/diversity/admission.ts +60 -0
  91. package/src/diversity/benchmark.ts +195 -0
  92. package/src/diversity/clustering.ts +285 -0
  93. package/src/diversity/errors.ts +7 -0
  94. package/src/diversity/identity.ts +285 -0
  95. package/src/diversity/index.ts +11 -0
  96. package/src/diversity/pipeline-integration.ts +448 -0
  97. package/src/diversity/projection.ts +57 -0
  98. package/src/diversity/self-contained.ts +68 -0
  99. package/src/diversity/target-validation.ts +179 -0
  100. package/src/doctor-migration.ts +209 -0
  101. package/src/doctor.ts +723 -0
  102. package/src/errors.ts +83 -0
  103. package/src/execution/admission.ts +75 -0
  104. package/src/execution/atomic-write.ts +35 -0
  105. package/src/execution/attempt-evidence.ts +415 -0
  106. package/src/execution/bucket-id.ts +136 -0
  107. package/src/execution/concurrency-limiter.ts +175 -0
  108. package/src/execution/contracts.ts +443 -0
  109. package/src/execution/failure-classification.ts +42 -0
  110. package/src/execution/failure-policy.ts +240 -0
  111. package/src/execution/harness.ts +2548 -0
  112. package/src/execution/settlement.ts +348 -0
  113. package/src/execution/spawned-process.ts +66 -0
  114. package/src/execution/spend-limiter.ts +424 -0
  115. package/src/execution/step-artifacts.ts +55 -0
  116. package/src/execution/usage-normalized.ts +469 -0
  117. package/src/git/git.ts +396 -0
  118. package/src/git/identity.ts +64 -0
  119. package/src/git/refs.ts +140 -0
  120. package/src/home-preflight.ts +443 -0
  121. package/src/home.ts +243 -0
  122. package/src/ignore-file.ts +336 -0
  123. package/src/ignore-read.ts +118 -0
  124. package/src/index.ts +34 -0
  125. package/src/legacy-launchd.ts +29 -0
  126. package/src/mcp/mcp.ts +150 -0
  127. package/src/mcp/preflight.ts +407 -0
  128. package/src/menu-context.ts +192 -0
  129. package/src/model/catalog.ts +251 -0
  130. package/src/model/exec-snapshots.ts +390 -0
  131. package/src/model/free-discovery.ts +302 -0
  132. package/src/model/provider-capabilities.ts +814 -0
  133. package/src/model/routing.ts +600 -0
  134. package/src/pr/admission.ts +847 -0
  135. package/src/pr/ci-admission-gate.ts +665 -0
  136. package/src/pr/ci-publish.ts +76 -0
  137. package/src/pr/discovery.ts +432 -0
  138. package/src/pr/inline.ts +507 -0
  139. package/src/pr/plan.ts +366 -0
  140. package/src/pr/posting.ts +115 -0
  141. package/src/pr/pr-status.ts +787 -0
  142. package/src/pr/pr.ts +3642 -0
  143. package/src/pr/preflight.ts +1031 -0
  144. package/src/pr/publish-outcome.ts +361 -0
  145. package/src/pr/range.ts +119 -0
  146. package/src/pr/reverts-preflight.ts +606 -0
  147. package/src/pr/reverts.ts +377 -0
  148. package/src/pr/review-pr.ts +927 -0
  149. package/src/pr/status.ts +154 -0
  150. package/src/pr/target.ts +388 -0
  151. package/src/pr/teardown.ts +437 -0
  152. package/src/pr/worktree-setup.ts +60 -0
  153. package/src/production-runtime.ts +1877 -0
  154. package/src/progress.ts +487 -0
  155. package/src/rereview/adjudicate.ts +89 -0
  156. package/src/rereview/classify.ts +362 -0
  157. package/src/rereview/identity.ts +211 -0
  158. package/src/rereview/plan.ts +308 -0
  159. package/src/rereview/prepare.ts +1025 -0
  160. package/src/rereview/state.ts +767 -0
  161. package/src/rereview/verify.ts +241 -0
  162. package/src/review/boundary.ts +105 -0
  163. package/src/review/consolidate.ts +246 -0
  164. package/src/review/dedupe.ts +368 -0
  165. package/src/review/drafts.ts +448 -0
  166. package/src/review/findings-conformance.ts +120 -0
  167. package/src/review/findings.ts +714 -0
  168. package/src/review/pipeline.ts +3977 -0
  169. package/src/review/preflight.ts +3575 -0
  170. package/src/review/prompt-set.ts +177 -0
  171. package/src/review/proof-refs.ts +187 -0
  172. package/src/review/report.ts +1821 -0
  173. package/src/review/review.ts +490 -0
  174. package/src/review/root-cause.ts +120 -0
  175. package/src/review/route-preflight.ts +289 -0
  176. package/src/review/run.ts +601 -0
  177. package/src/review/scout.ts +323 -0
  178. package/src/review/size-gate.ts +595 -0
  179. package/src/review/spec.ts +235 -0
  180. package/src/review/step-runner.ts +233 -0
  181. package/src/runner-authority.ts +596 -0
  182. package/src/security/binding-policy.ts +115 -0
  183. package/src/security/credential-broker.ts +773 -0
  184. package/src/security/evidence-redaction.ts +62 -0
  185. package/src/security/execution-authority.ts +27 -0
  186. package/src/security/redact.ts +71 -0
  187. package/src/security/workspace-read-broker.ts +466 -0
  188. package/src/server/client.ts +190 -0
  189. package/src/server/preflight.ts +217 -0
  190. package/src/server/server.ts +327 -0
  191. package/src/signal-handler.ts +50 -0
  192. package/src/store/activity.ts +413 -0
  193. package/src/store/backfill-preflight.ts +49 -0
  194. package/src/store/backfill.ts +141 -0
  195. package/src/store/gc-preflight.ts +206 -0
  196. package/src/store/gc.ts +424 -0
  197. package/src/store/metrics-preflight.ts +229 -0
  198. package/src/store/metrics.ts +236 -0
  199. package/src/store/preflight.ts +748 -0
  200. package/src/store/store.ts +693 -0
  201. package/src/system-tools.ts +355 -0
  202. package/src/transport-registry.ts +1124 -0
  203. package/src/transports/claude-code-cli.ts +1348 -0
  204. package/src/transports/opencode-admission.ts +515 -0
  205. package/src/transports/opencode-client.ts +3328 -0
  206. package/src/transports/opencode-evidence.ts +557 -0
  207. package/src/transports/opencode-mcp.ts +248 -0
  208. package/src/transports/opencode-sdk.ts +2294 -0
  209. package/src/transports/opencode-server.ts +535 -0
  210. package/src/triage/adjudication.ts +113 -0
  211. package/src/triage/reply.ts +125 -0
  212. package/src/triage/triage.ts +255 -0
  213. package/src/ui/activity.ts +173 -0
  214. package/src/ui/config-edit.ts +816 -0
  215. package/src/ui/config.ts +462 -0
  216. package/src/ui/menu.ts +1325 -0
  217. package/src/ui/plan.ts +1039 -0
  218. package/src/ui/primitives.ts +300 -0
  219. package/src/ui/progress.ts +298 -0
  220. package/src/ui/result.ts +552 -0
  221. package/src/ui/review-menu.ts +312 -0
  222. package/src/ui/select.ts +528 -0
  223. package/src/ui/tree.ts +178 -0
  224. package/src/uninstaller.ts +479 -0
  225. package/src/updater.ts +836 -0
  226. package/src/usage.ts +77 -0
  227. package/src/watch/preflight.ts +1389 -0
  228. package/src/watch/watch.ts +1235 -0
  229. package/src/wizard.ts +877 -0
@@ -0,0 +1,240 @@
1
+ // §7 (docs/multi-runtime-model-diversity-design.md lines 370-422): cause
2
+ // answers WHAT happened; disposition answers WHAT the harness may do. They
3
+ // are separate types and this pure module is the only place that maps one
4
+ // onto the other — LLMs judge, code governs.
5
+
6
+ import type { TransportFailureCause, TransportOutcome } from "./contracts";
7
+ import {
8
+ classifyFailure as classifyLegacyFailure,
9
+ type FailureClass,
10
+ } from "./failure-classification";
11
+
12
+ export type { TransportFailureCause };
13
+
14
+ // §7 lines 390-395, verbatim.
15
+ export type HarnessFailureCause =
16
+ | "format_violation"
17
+ | "watchdog_timeout"
18
+ | "pipeline_cancelled"
19
+ | "user_cancelled"
20
+ | "settlement_unconfirmed";
21
+
22
+ // §7 line 397, verbatim.
23
+ export type FailureCause = TransportFailureCause | HarnessFailureCause;
24
+
25
+ // §7 lines 399-402, verbatim.
26
+ export interface RetryState {
27
+ readonly transientAttemptsUsed: number;
28
+ readonly formatRetriesUsed: number;
29
+ }
30
+
31
+ // §7 lines 404-408, verbatim.
32
+ export type RetryDisposition =
33
+ | { action: "retry_now"; budget: "transient" }
34
+ | { action: "retry_after"; budget: "transient"; delayMs: number }
35
+ | { action: "retry_format_reminder"; budget: "format" }
36
+ | { action: "terminal" };
37
+
38
+ // One failed outcome reduced to policy input. The `legacy_terminal` arm
39
+ // carries a stop ruling that has no §7 cause behind it — see the bridge
40
+ // comment below for WHY it must stay cause-less.
41
+ export type CauseResolution =
42
+ | { readonly kind: "cause"; readonly cause: FailureCause }
43
+ | { readonly kind: "legacy_terminal" };
44
+
45
+ const DEFAULT_MAX_TRANSIENT_ATTEMPTS = 3;
46
+ const DEFAULT_MAX_RETRY_AFTER_DELAY_MS = 60_000;
47
+ const DEFAULT_MAX_FORMAT_RETRIES = 1;
48
+ // Base of the §7 line 416 capped exponential backoff: doubles per
49
+ // transientAttemptsUsed, hard-capped at maxRetryAfterDelayMs.
50
+ const RATE_LIMIT_BACKOFF_BASE_MS = 1_000;
51
+
52
+ export function decideRetryDisposition(
53
+ cause: FailureCause,
54
+ state: RetryState,
55
+ options: {
56
+ readonly maxTransientAttempts?: number;
57
+ readonly maxRetryAfterDelayMs?: number;
58
+ readonly maxFormatRetries?: number;
59
+ // §7 line 416: a VALIDATED Retry-After hint (positive, finite, ≤
60
+ // maxRetryAfterDelayMs) is honored verbatim; an absent or invalid one
61
+ // falls back to the capped exponential. Optional because
62
+ // TransportOutcome carries no Retry-After fact yet — the harness wires
63
+ // the hint through here when a transport ships one.
64
+ readonly retryAfterMs?: number;
65
+ } = {},
66
+ ): RetryDisposition {
67
+ const maxTransientAttempts =
68
+ options.maxTransientAttempts ?? DEFAULT_MAX_TRANSIENT_ATTEMPTS;
69
+ const maxRetryAfterDelayMs =
70
+ options.maxRetryAfterDelayMs ?? DEFAULT_MAX_RETRY_AFTER_DELAY_MS;
71
+ const maxFormatRetries =
72
+ options.maxFormatRetries ?? DEFAULT_MAX_FORMAT_RETRIES;
73
+
74
+ // §7 line 417: the format reminder answers to its OWN budget alone, so it
75
+ // is decided before any transient arithmetic can touch it (§13 line 759).
76
+ if (cause === "format_violation") {
77
+ return state.formatRetriesUsed < maxFormatRetries
78
+ ? { action: "retry_format_reminder", budget: "format" }
79
+ : { action: "terminal" };
80
+ }
81
+
82
+ const transientBudgetLeft =
83
+ state.transientAttemptsUsed < maxTransientAttempts;
84
+
85
+ switch (cause) {
86
+ case "network_transient":
87
+ case "protocol_truncation":
88
+ case "watchdog_timeout":
89
+ return transientBudgetLeft
90
+ ? { action: "retry_now", budget: "transient" }
91
+ : { action: "terminal" };
92
+ case "rate_limit": {
93
+ if (!transientBudgetLeft) return { action: "terminal" };
94
+ const hint = options.retryAfterMs;
95
+ const delayMs =
96
+ hint !== undefined &&
97
+ Number.isFinite(hint) &&
98
+ hint > 0 &&
99
+ hint <= maxRetryAfterDelayMs
100
+ ? hint
101
+ : Math.min(
102
+ RATE_LIMIT_BACKOFF_BASE_MS * 2 ** state.transientAttemptsUsed,
103
+ maxRetryAfterDelayMs,
104
+ );
105
+ return { action: "retry_after", budget: "transient", delayMs };
106
+ }
107
+ default:
108
+ // §7 lines 418-420: every remaining cause — auth/quota/context/output/
109
+ // safety/config/runtime, protocol conformance failures, cancellations
110
+ // and unconfirmed settlements/aborts — is terminal.
111
+ return { action: "terminal" };
112
+ }
113
+ }
114
+
115
+ // WHY legacy "terminal" becomes a disposition, not a cause: §7 lines 375-397
116
+ // freeze the cause vocabulary verbatim, and "the transport said stop" carries
117
+ // stop authority without causal content — inventing a union member would
118
+ // drift the frozen schema, so the bridge hands the harness a direct terminal
119
+ // ruling instead. The transient/format budget separation (§13 line 759) is
120
+ // untouched either way.
121
+ //
122
+ // WHY the raw `timedOut` fact is a parameter and not read off the class:
123
+ // step-runner's classifyFailure collapses a watchdog kill into the generic
124
+ // "transient" class before anything downstream sees it
125
+ // (`src/review/step-runner.ts:111`), so the class ALONE can never distinguish a
126
+ // timeout from a network error. §7 declares `watchdog_timeout` a first-class
127
+ // cause; a bridge that only accepted the collapsed class would attribute
128
+ // every timeout to the network in the per-attempt log the harness persists
129
+ // for incident triage. Both causes share a disposition today, so that lie
130
+ // would never have failed loudly — it would just have been wrong.
131
+ export function causeFromLegacyFailureClass(
132
+ legacy: FailureClass,
133
+ outcome: { readonly timedOut?: boolean } = {},
134
+ ): CauseResolution {
135
+ switch (legacy) {
136
+ case "transient":
137
+ return {
138
+ kind: "cause",
139
+ // Consulted for this class only: a terminal ruling keeps its stop
140
+ // authority and a format violation keeps its own budget even when the
141
+ // same outcome also timed out.
142
+ cause:
143
+ outcome.timedOut === true ? "watchdog_timeout" : "network_transient",
144
+ };
145
+ case "format":
146
+ return { kind: "cause", cause: "format_violation" };
147
+ case "terminal":
148
+ return { kind: "legacy_terminal" };
149
+ }
150
+ }
151
+
152
+ // D1-08 PR0 (D1-07 wiring): the harness's ONE place to decide "what failed
153
+ // and why" — a pure function so the harness itself never touches the legacy
154
+ // step-runner classifier or re-implements a transport's own witness
155
+ // matching. Ordered per design decision D1:
156
+ // 1. timedOut -> watchdog_timeout (distinct from a plain network
157
+ // failure — step-runner's classifyFailure collapses
158
+ // both into "transient" before anything downstream
159
+ // sees it, which is the pr-hero F002 defect).
160
+ // 2. transport-native -> the SECOND unwired mechanism this slice closes:
161
+ // classifyFailure() every transport implements classifyFailure with
162
+ // its own paid-for witness ordering (e.g. checking
163
+ // rate-limit backpressure before a generic network
164
+ // witness), and nothing in the live path called it.
165
+ // 3. parseThrew -> format_violation: the model's own JSON was bad,
166
+ // not a provider/infra problem.
167
+ // 4. legacy fallback -> causeFromLegacyFailureClass(classifyFailure(...))
168
+ // (D2): retains stop authority for the legacy
169
+ // terminal ruling and the legacy transient/format
170
+ // split for any outcome the transport's own
171
+ // classifier and the parse check both miss.
172
+ export interface ResolveFailureCauseInput {
173
+ readonly outcome: TransportOutcome;
174
+ // Not the whole `ProviderTransport` — just the one method, passed as a
175
+ // plain function reference (never bound or wrapped in a lambda): the D1-08
176
+ // spec tripwire greps harness.ts for exactly `this.transport.classifyFailure`
177
+ // and nothing else naming "classifyFailure".
178
+ readonly classifyFailure: (
179
+ outcome: TransportOutcome,
180
+ ) => TransportFailureCause | undefined;
181
+ readonly parseThrew: boolean;
182
+ }
183
+
184
+ export function resolveFailureCause(
185
+ input: ResolveFailureCauseInput,
186
+ ): CauseResolution {
187
+ const { outcome, classifyFailure, parseThrew } = input;
188
+
189
+ if (outcome.timedOut === true) {
190
+ return { kind: "cause", cause: "watchdog_timeout" };
191
+ }
192
+
193
+ // A cause the transport holds as a typed fact beats its witness patterns: the
194
+ // witness can only spell it, and a generic witness would lose it.
195
+ if (outcome.failureCause !== undefined) {
196
+ return { kind: "cause", cause: outcome.failureCause };
197
+ }
198
+
199
+ const transportCause = classifyFailure(outcome);
200
+ if (transportCause !== undefined) {
201
+ return { kind: "cause", cause: transportCause };
202
+ }
203
+
204
+ if (parseThrew) {
205
+ return { kind: "cause", cause: "format_violation" };
206
+ }
207
+
208
+ return causeFromLegacyFailureClass(
209
+ classifyLegacyFailure({
210
+ stderrTail: outcome.stderrTail,
211
+ resultText: outcome.finalText,
212
+ timedOut: Boolean(outcome.timedOut),
213
+ }),
214
+ { timedOut: outcome.timedOut },
215
+ );
216
+ }
217
+
218
+ // Legacy attempt logs record `classification: ok|transient|terminal|format`
219
+ // (test/step-runner.test.ts pins this literal vocabulary — it must not
220
+ // change). The §7 cause is richer than that three-way split — e.g.
221
+ // watchdog_timeout and network_transient both legacy-classify as
222
+ // "transient" — so this is a lossy PROJECTION back onto the old field for
223
+ // backward compatibility; the caller additionally logs the real
224
+ // `CauseResolution` in a new, additive line (D1-08 design row 13).
225
+ const TRANSIENT_FAMILY_CAUSES: ReadonlySet<FailureCause> = new Set([
226
+ "network_transient",
227
+ "protocol_truncation",
228
+ "rate_limit",
229
+ "watchdog_timeout",
230
+ ]);
231
+
232
+ export function legacyClassificationFromCause(
233
+ resolution: CauseResolution,
234
+ ): FailureClass {
235
+ if (resolution.kind === "legacy_terminal") return "terminal";
236
+ if (resolution.cause === "format_violation") return "format";
237
+ return TRANSIENT_FAMILY_CAUSES.has(resolution.cause)
238
+ ? "transient"
239
+ : "terminal";
240
+ }