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,248 @@
1
+ // #141: the MCP half of the OpenCode transport. PURE — the impure halves are
2
+ // the launcher (which carries the config into the child's environment) and the
3
+ // client (which reads the file and verifies the readback).
4
+ //
5
+ // pr-hero writes ONE mcp registry per run, in Claude Code's shape
6
+ // (src/cli.ts's CODEGRAPH_ONLY_MCP_CONFIG), and `binding-policy.ts` gates that
7
+ // exact file: not a symlink, `mcpServers` empty or exactly ["codegraph"], and
8
+ // an optional sha256 pin. This module TRANSLATES that file rather than letting
9
+ // the OpenCode route write its own. A second config would be a registry the
10
+ // integrity gate never sees — which is the same thing as no gate at all, since
11
+ // the agent cannot tell which registry granted it a tool.
12
+ //
13
+ // The two shapes are not compatible and never were:
14
+ //
15
+ // Claude { "mcpServers": { codegraph: { type: "stdio",
16
+ // command: "codegraph",
17
+ // args: ["serve", "--mcp"] } } }
18
+ // OpenCode { "mcp": { codegraph: { type: "local",
19
+ // command: ["<abs>", "serve", …] } } }
20
+ //
21
+ // (McpLocalConfig, @opencode-ai/sdk types.gen.d.ts:946-969.)
22
+
23
+ // What `OPENCODE_CONFIG_CONTENT` carries under `mcp`. Narrow on purpose: the
24
+ // SDK's own `McpLocalConfig` also admits `environment` and `timeout`, and this
25
+ // transport delivers neither — an environment map here would be a second,
26
+ // ungated channel into a child that already inherits the projected one.
27
+ interface OpenCodeMcpLocalConfig {
28
+ readonly type: "local";
29
+ readonly command: readonly string[];
30
+ readonly enabled: true;
31
+ }
32
+
33
+ export type OpenCodeMcpConfig = Readonly<
34
+ Record<string, OpenCodeMcpLocalConfig>
35
+ >;
36
+
37
+ // The ONE server pr-hero can express, and the same name binding-policy.ts
38
+ // admits. Anything else reaching the translation is a registry this route
39
+ // cannot honour, not a server to drop quietly.
40
+ const CODEGRAPH_SERVER = "codegraph";
41
+
42
+ // OpenCode normalises an MCP tool to `<server>_<tool>`, and
43
+ // `codegraph serve --mcp` exposes exactly one tool, `codegraph_explore` — so
44
+ // the id is the doubled-looking `codegraph_codegraph_explore`. MEASURED live
45
+ // (#141 fact 4), not derived from the docs: with an empty tools map the model
46
+ // called it and named it back; with this key written false alongside every
47
+ // built-in, the model answered REFUSED and no tool call appeared in the event
48
+ // stream. The map key genuinely gates it.
49
+ const MCP_SERVER_TOOL_IDS: Readonly<Record<string, readonly string[]>> = {
50
+ [CODEGRAPH_SERVER]: ["codegraph_codegraph_explore"],
51
+ };
52
+
53
+ interface ClaudeMcpServer {
54
+ readonly type?: unknown;
55
+ readonly command?: unknown;
56
+ readonly args?: unknown;
57
+ }
58
+
59
+ function asRecord(value: unknown): Record<string, unknown> | undefined {
60
+ return typeof value === "object" && value !== null && !Array.isArray(value)
61
+ ? (value as Record<string, unknown>)
62
+ : undefined;
63
+ }
64
+
65
+ interface TranslateMcpConfigInput {
66
+ // The mcp.json bytes, already read by the caller. Read BEFORE the server is
67
+ // spawned (the F005 ordering rule): a config that cannot be translated must
68
+ // cost nothing to unwind.
69
+ readonly json: string;
70
+ // Carried only so a failure names the file the operator has to look at.
71
+ readonly configPath: string;
72
+ // The REVIEW TARGET, which is not the launcher's cwd.
73
+ readonly cwd: string;
74
+ // Absolute, resolved by the caller (transport-registry.ts), never looked up
75
+ // here: a PATH lookup inside a pure translation would be unreachable from a
76
+ // test and invisible in an artifact.
77
+ readonly codegraphBinaryPath?: string;
78
+ }
79
+
80
+ export function translateMcpConfig(
81
+ input: TranslateMcpConfigInput,
82
+ ): OpenCodeMcpConfig {
83
+ let parsed: unknown;
84
+ try {
85
+ parsed = JSON.parse(input.json);
86
+ } catch (error) {
87
+ throw new Error(
88
+ `mcp registry at ${input.configPath} is not valid JSON: ${(error as Error).message}`,
89
+ );
90
+ }
91
+
92
+ const servers = asRecord(asRecord(parsed)?.mcpServers) ?? {};
93
+ const out: Record<string, OpenCodeMcpLocalConfig> = {};
94
+
95
+ for (const [name, raw] of Object.entries(servers)) {
96
+ // Not a filter — a REFUSAL. This translation knows how to build exactly
97
+ // one command, and a server it silently dropped would be a tool the
98
+ // prompt was promised and the model never receives: the absent-key hazard
99
+ // resolveToolMap was written to kill, re-entering through the config.
100
+ // binding-policy.ts already refuses such a registry; this is the same
101
+ // ruling at the point where the command is actually built.
102
+ if (name !== CODEGRAPH_SERVER) {
103
+ throw new Error(
104
+ `mcp registry at ${input.configPath} registers "${name}", which the ` +
105
+ "opencode route cannot express; only the codegraph server is supported",
106
+ );
107
+ }
108
+ const server = (asRecord(raw) ?? {}) as ClaudeMcpServer;
109
+ // A remote transport has no command to translate at all, and inventing
110
+ // one would produce a server that connects to nothing.
111
+ if (server.type !== undefined && server.type !== "stdio") {
112
+ throw new Error(
113
+ `mcp registry at ${input.configPath} declares "${name}" as ` +
114
+ `"${String(server.type)}"; only stdio servers can be translated`,
115
+ );
116
+ }
117
+ if (typeof server.command !== "string" || server.command.length === 0) {
118
+ throw new Error(
119
+ `mcp registry at ${input.configPath} declares "${name}" with no command`,
120
+ );
121
+ }
122
+ const args = server.args ?? [];
123
+ if (!Array.isArray(args) || args.some((arg) => typeof arg !== "string")) {
124
+ throw new Error(
125
+ `mcp registry at ${input.configPath} declares non-string args for "${name}"`,
126
+ );
127
+ }
128
+
129
+ out[name] = {
130
+ type: "local",
131
+ command: [
132
+ resolveCommand(server.command, input),
133
+ ...(args as string[]),
134
+ // REQUIRED, not decorative. The OpenCode server process inherits
135
+ // pr-hero's process cwd, NOT the review target — in PR mode the
136
+ // target is a worktree — so a codegraph left to resolve its project
137
+ // from cwd would index the operator's checkout and answer every
138
+ // hunter about the wrong tree. It would ANSWER, which is what makes
139
+ // this the expensive kind of wrong.
140
+ "-p",
141
+ input.cwd,
142
+ ],
143
+ enabled: true,
144
+ };
145
+ }
146
+
147
+ return out;
148
+ }
149
+
150
+ // The Claude-side file carries a bare "codegraph" because the claude CLI child
151
+ // inherits a real PATH. The OpenCode child does not: the production env
152
+ // projection is EXACTLY {HOME, TMPDIR, XDG_DATA_HOME, XDG_CONFIG_HOME}
153
+ // (credential-broker.ts:449-457), so a bare name resolves to nothing. Fail
154
+ // loud rather than degrade: a command that cannot resolve produces a server
155
+ // that never connects, and the readback would then abort the attempt with a
156
+ // diagnosis pointing at the wrong thing.
157
+ function resolveCommand(
158
+ declared: string,
159
+ input: TranslateMcpConfigInput,
160
+ ): string {
161
+ if (declared.startsWith("/")) return declared;
162
+ const override = input.codegraphBinaryPath;
163
+ if (override === undefined) {
164
+ throw new Error(
165
+ `mcp registry at ${input.configPath} names the codegraph binary as ` +
166
+ `"${declared}", and no absolute codegraph path could be resolved; ` +
167
+ "the opencode child is spawned with no PATH, so a bare name cannot " +
168
+ "start. Install codegraph or pass an absolute override.",
169
+ );
170
+ }
171
+ if (!override.startsWith("/")) {
172
+ throw new Error(`codegraph binary must be an absolute path: ${override}`);
173
+ }
174
+ return override;
175
+ }
176
+
177
+ export function mcpConfigIsEmpty(config: OpenCodeMcpConfig): boolean {
178
+ return Object.keys(config).length === 0;
179
+ }
180
+
181
+ // Every tool id any deliverable MCP server contributes. Written into the allow
182
+ // map unconditionally — true only for a server actually delivered — because an
183
+ // absent key asks for the provider's default and the provider's default is not
184
+ // ours to inherit.
185
+ export const ALL_MCP_TOOL_IDS: readonly string[] =
186
+ Object.values(MCP_SERVER_TOOL_IDS).flat();
187
+
188
+ export function mcpToolIdsFor(config: OpenCodeMcpConfig): ReadonlySet<string> {
189
+ const ids = new Set<string>();
190
+ for (const name of Object.keys(config)) {
191
+ for (const id of MCP_SERVER_TOOL_IDS[name] ?? []) ids.add(id);
192
+ }
193
+ return ids;
194
+ }
195
+
196
+ // §E: the readback, and the reason it exists rather than a declaration.
197
+ // claude-code gets `--strict-mcp-config` — a FLAG, believed. Here the
198
+ // connected set is read back from the provider and compared, which is strictly
199
+ // stronger: it is verified, not declared.
200
+ //
201
+ // The concrete threat it closes is measured (#141 fact 7): `--pure` suppresses
202
+ // neither config-delivered nor config-FILE MCP servers. A server launched with
203
+ // the operator's real HOME loads ~/.config/opencode/opencode.jsonc and
204
+ // connects whatever the operator configured, and production is shielded only
205
+ // INCIDENTALLY — by the synthetic XDG_CONFIG_HOME the credential projection
206
+ // happens to set. An extra server is an undeclared tool channel inside a
207
+ // process holding a projected credential, and nothing else in this transport
208
+ // would ever notice it: a connected MCP server contributes nothing to
209
+ // `tool.ids()`, so the allow-map enumeration cannot see it either.
210
+ export function assertMcpConnected(
211
+ status: unknown,
212
+ expected: readonly string[],
213
+ ): void {
214
+ const record = asRecord(status);
215
+ // An unreadable response proves nothing, and "nothing extra is connected" is
216
+ // precisely the claim that cannot be made from it.
217
+ if (record === undefined) {
218
+ throw new Error(
219
+ "opencode reported an unreadable MCP status, so the connected server " +
220
+ "set cannot be verified; refusing to prompt a session whose tool " +
221
+ "channels are unknown",
222
+ );
223
+ }
224
+
225
+ const declared = new Set(expected);
226
+ const connected = Object.keys(record).sort();
227
+ const extra = connected.filter((name) => !declared.has(name));
228
+ if (extra.length > 0) {
229
+ throw new Error(
230
+ `opencode connected MCP servers Crysk did not declare: ${extra.join(", ")}` +
231
+ ` (declared: ${expected.length === 0 ? "none" : [...declared].sort().join(", ")})`,
232
+ );
233
+ }
234
+
235
+ for (const name of [...declared].sort()) {
236
+ const entry = asRecord(record[name]);
237
+ if (entry === undefined) {
238
+ throw new Error(
239
+ `opencode did not connect the declared MCP server "${name}"`,
240
+ );
241
+ }
242
+ if (entry.status !== "connected") {
243
+ throw new Error(
244
+ `opencode MCP server "${name}" is ${String(entry.status)}, not connected`,
245
+ );
246
+ }
247
+ }
248
+ }