crysk 0.0.0 → 0.3.1

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 (233) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +611 -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/SKILL-y8rv8msh.md +134 -0
  10. package/dist/SKILL-ygka1bs0.md +515 -0
  11. package/dist/adjudicator-dtg2axnh.md +86 -0
  12. package/dist/admission-config.example-a9vqmmad.json +9 -0
  13. package/dist/ci-admission-camfbx2b.md +122 -0
  14. package/dist/ci-admission-qk9r9taq.md +124 -0
  15. package/dist/cli.js +42501 -0
  16. package/dist/consolidate-ac0mnfyj.md +24 -0
  17. package/dist/deep-review-lifecycle-m698ybjp.md +362 -0
  18. package/dist/deep-review-logic-a6b1gczf.md +156 -0
  19. package/dist/deep-review-parity-0ec904db.md +120 -0
  20. package/dist/deep-review-reliability-qyakbjb9.md +125 -0
  21. package/dist/deep-review-resilience-3tz8y26e.md +118 -0
  22. package/dist/index.js +20190 -0
  23. package/dist/opencode-ci-7b0be64p.md +141 -0
  24. package/dist/review-refuter-j4e9gezy.md +71 -0
  25. package/dist/scout-yvp153q7.md +140 -0
  26. package/dist/summarizer-zca44nxa.md +18 -0
  27. package/dist/workflow-w1g9szna.yml +151 -0
  28. package/package.json +81 -4
  29. package/prompts/consolidate.md +24 -0
  30. package/prompts/default/PROVENANCE.md +18 -0
  31. package/prompts/default/deep-review-lifecycle.md +362 -0
  32. package/prompts/default/deep-review-logic.md +156 -0
  33. package/prompts/default/deep-review-parity.md +120 -0
  34. package/prompts/default/deep-review-reliability.md +125 -0
  35. package/prompts/default/deep-review-resilience.md +118 -0
  36. package/prompts/default/review-refuter.md +71 -0
  37. package/prompts/scout.md +140 -0
  38. package/prompts/summarizer.md +18 -0
  39. package/skills/crysk/SKILL.md +74 -0
  40. package/skills/crysk-ci-setup/SKILL.md +134 -0
  41. package/skills/crysk-ci-setup/assets/admission-config.example.json +9 -0
  42. package/skills/crysk-ci-setup/assets/workflow.yml +151 -0
  43. package/skills/crysk-ci-setup/references/ci-admission.md +124 -0
  44. package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
  45. package/skills/crysk-loop/SKILL.md +515 -0
  46. package/skills/crysk-loop/adjudicator.md +86 -0
  47. package/skills/crysk-pr/SKILL.md +66 -0
  48. package/src/agent-env.ts +1084 -0
  49. package/src/asset-manifest.ts +83 -0
  50. package/src/assets.d.ts +6 -0
  51. package/src/assets.ts +183 -0
  52. package/src/brand-paths.ts +155 -0
  53. package/src/brand.ts +255 -0
  54. package/src/ci/admission-ledger.ts +350 -0
  55. package/src/ci/classify-error.ts +73 -0
  56. package/src/ci/cli-record.ts +271 -0
  57. package/src/ci/force-comment.ts +39 -0
  58. package/src/ci/gates.ts +945 -0
  59. package/src/ci/outcome.ts +2181 -0
  60. package/src/ci/override.ts +187 -0
  61. package/src/ci/publish.ts +1639 -0
  62. package/src/ci/reporter.ts +626 -0
  63. package/src/ci/review-admission.ts +910 -0
  64. package/src/ci/review-levels.ts +310 -0
  65. package/src/ci/review-policy.ts +18 -0
  66. package/src/ci/review-risk.ts +184 -0
  67. package/src/ci/setup.ts +844 -0
  68. package/src/ci/trigger.ts +1353 -0
  69. package/src/cli.ts +348 -0
  70. package/src/commands/activity.ts +67 -0
  71. package/src/commands/ci-setup-questions.ts +397 -0
  72. package/src/commands/ci-setup.ts +381 -0
  73. package/src/commands/config.ts +99 -0
  74. package/src/commands/doctor.ts +108 -0
  75. package/src/commands/init.ts +139 -0
  76. package/src/commands/mcp.ts +10 -0
  77. package/src/commands/menu.ts +129 -0
  78. package/src/commands/post.ts +302 -0
  79. package/src/commands/skills.ts +83 -0
  80. package/src/commands/status.ts +173 -0
  81. package/src/commands/triage.ts +342 -0
  82. package/src/commands/uninstall.ts +37 -0
  83. package/src/commands/upgrade.ts +214 -0
  84. package/src/commands/usage.ts +98 -0
  85. package/src/compare/compare.ts +28 -0
  86. package/src/compare/floor-test.ts +471 -0
  87. package/src/compare/martian-adapter.ts +80 -0
  88. package/src/config/config.ts +267 -0
  89. package/src/corpus/corpus.ts +1094 -0
  90. package/src/corpus/preflight.ts +1789 -0
  91. package/src/diversity/accounting.ts +90 -0
  92. package/src/diversity/adjudication.ts +145 -0
  93. package/src/diversity/admission.ts +60 -0
  94. package/src/diversity/benchmark.ts +195 -0
  95. package/src/diversity/clustering.ts +285 -0
  96. package/src/diversity/errors.ts +7 -0
  97. package/src/diversity/identity.ts +285 -0
  98. package/src/diversity/index.ts +11 -0
  99. package/src/diversity/pipeline-integration.ts +448 -0
  100. package/src/diversity/projection.ts +57 -0
  101. package/src/diversity/self-contained.ts +68 -0
  102. package/src/diversity/target-validation.ts +179 -0
  103. package/src/doctor-migration.ts +209 -0
  104. package/src/doctor.ts +723 -0
  105. package/src/errors.ts +83 -0
  106. package/src/execution/admission.ts +75 -0
  107. package/src/execution/atomic-write.ts +35 -0
  108. package/src/execution/attempt-evidence.ts +415 -0
  109. package/src/execution/bucket-id.ts +136 -0
  110. package/src/execution/concurrency-limiter.ts +175 -0
  111. package/src/execution/contracts.ts +443 -0
  112. package/src/execution/failure-classification.ts +42 -0
  113. package/src/execution/failure-policy.ts +240 -0
  114. package/src/execution/harness.ts +2548 -0
  115. package/src/execution/settlement.ts +348 -0
  116. package/src/execution/spawned-process.ts +66 -0
  117. package/src/execution/spend-limiter.ts +424 -0
  118. package/src/execution/step-artifacts.ts +55 -0
  119. package/src/execution/usage-normalized.ts +469 -0
  120. package/src/git/git.ts +396 -0
  121. package/src/git/identity.ts +64 -0
  122. package/src/git/refs.ts +140 -0
  123. package/src/home-preflight.ts +443 -0
  124. package/src/home.ts +243 -0
  125. package/src/ignore-file.ts +336 -0
  126. package/src/ignore-read.ts +118 -0
  127. package/src/index.ts +34 -0
  128. package/src/legacy-launchd.ts +29 -0
  129. package/src/mcp/mcp.ts +150 -0
  130. package/src/mcp/preflight.ts +407 -0
  131. package/src/menu-context.ts +192 -0
  132. package/src/model/catalog.ts +251 -0
  133. package/src/model/exec-snapshots.ts +390 -0
  134. package/src/model/free-discovery.ts +302 -0
  135. package/src/model/provider-capabilities.ts +814 -0
  136. package/src/model/routing.ts +600 -0
  137. package/src/pr/admission.ts +984 -0
  138. package/src/pr/answered-findings.ts +169 -0
  139. package/src/pr/ci-admission-gate.ts +743 -0
  140. package/src/pr/ci-publish.ts +76 -0
  141. package/src/pr/discovery.ts +432 -0
  142. package/src/pr/inline.ts +507 -0
  143. package/src/pr/plan.ts +366 -0
  144. package/src/pr/posting.ts +115 -0
  145. package/src/pr/pr-status.ts +845 -0
  146. package/src/pr/pr.ts +3642 -0
  147. package/src/pr/preflight.ts +1031 -0
  148. package/src/pr/publish-outcome.ts +361 -0
  149. package/src/pr/range.ts +119 -0
  150. package/src/pr/reverts-preflight.ts +606 -0
  151. package/src/pr/reverts.ts +377 -0
  152. package/src/pr/review-pr.ts +927 -0
  153. package/src/pr/status.ts +154 -0
  154. package/src/pr/target.ts +388 -0
  155. package/src/pr/teardown.ts +437 -0
  156. package/src/pr/worktree-setup.ts +60 -0
  157. package/src/production-runtime.ts +1877 -0
  158. package/src/progress.ts +487 -0
  159. package/src/rereview/adjudicate.ts +89 -0
  160. package/src/rereview/classify.ts +362 -0
  161. package/src/rereview/identity.ts +211 -0
  162. package/src/rereview/plan.ts +308 -0
  163. package/src/rereview/prepare.ts +1025 -0
  164. package/src/rereview/state.ts +767 -0
  165. package/src/rereview/verify.ts +241 -0
  166. package/src/review/boundary.ts +105 -0
  167. package/src/review/consolidate.ts +246 -0
  168. package/src/review/dedupe.ts +368 -0
  169. package/src/review/drafts.ts +448 -0
  170. package/src/review/findings-conformance.ts +120 -0
  171. package/src/review/findings.ts +714 -0
  172. package/src/review/pipeline.ts +3977 -0
  173. package/src/review/preflight.ts +3575 -0
  174. package/src/review/prompt-set.ts +177 -0
  175. package/src/review/proof-refs.ts +187 -0
  176. package/src/review/report.ts +1821 -0
  177. package/src/review/review.ts +490 -0
  178. package/src/review/root-cause.ts +120 -0
  179. package/src/review/route-preflight.ts +289 -0
  180. package/src/review/run.ts +601 -0
  181. package/src/review/scout.ts +323 -0
  182. package/src/review/size-gate.ts +595 -0
  183. package/src/review/spec.ts +235 -0
  184. package/src/review/step-runner.ts +233 -0
  185. package/src/runner-authority.ts +596 -0
  186. package/src/security/binding-policy.ts +115 -0
  187. package/src/security/credential-broker.ts +773 -0
  188. package/src/security/evidence-redaction.ts +62 -0
  189. package/src/security/execution-authority.ts +27 -0
  190. package/src/security/redact.ts +71 -0
  191. package/src/security/workspace-read-broker.ts +466 -0
  192. package/src/server/client.ts +190 -0
  193. package/src/server/preflight.ts +217 -0
  194. package/src/server/server.ts +327 -0
  195. package/src/signal-handler.ts +50 -0
  196. package/src/store/activity.ts +413 -0
  197. package/src/store/backfill-preflight.ts +49 -0
  198. package/src/store/backfill.ts +141 -0
  199. package/src/store/gc-preflight.ts +206 -0
  200. package/src/store/gc.ts +424 -0
  201. package/src/store/metrics-preflight.ts +229 -0
  202. package/src/store/metrics.ts +236 -0
  203. package/src/store/preflight.ts +748 -0
  204. package/src/store/store.ts +693 -0
  205. package/src/system-tools.ts +355 -0
  206. package/src/transport-registry.ts +1124 -0
  207. package/src/transports/claude-code-cli.ts +1348 -0
  208. package/src/transports/opencode-admission.ts +515 -0
  209. package/src/transports/opencode-client.ts +3328 -0
  210. package/src/transports/opencode-evidence.ts +557 -0
  211. package/src/transports/opencode-mcp.ts +248 -0
  212. package/src/transports/opencode-sdk.ts +2294 -0
  213. package/src/transports/opencode-server.ts +535 -0
  214. package/src/triage/adjudication.ts +113 -0
  215. package/src/triage/reply.ts +125 -0
  216. package/src/triage/triage.ts +255 -0
  217. package/src/ui/activity.ts +173 -0
  218. package/src/ui/config-edit.ts +816 -0
  219. package/src/ui/config.ts +462 -0
  220. package/src/ui/menu.ts +1325 -0
  221. package/src/ui/plan.ts +1039 -0
  222. package/src/ui/primitives.ts +300 -0
  223. package/src/ui/progress.ts +298 -0
  224. package/src/ui/result.ts +552 -0
  225. package/src/ui/review-menu.ts +312 -0
  226. package/src/ui/select.ts +528 -0
  227. package/src/ui/tree.ts +178 -0
  228. package/src/uninstaller.ts +479 -0
  229. package/src/updater.ts +836 -0
  230. package/src/usage.ts +77 -0
  231. package/src/watch/preflight.ts +1389 -0
  232. package/src/watch/watch.ts +1235 -0
  233. package/src/wizard.ts +877 -0
@@ -0,0 +1,267 @@
1
+ // The config domain: the two-layer read (repo `.prhero/config.json` +
2
+ // global `~/.prhero/config.json`), the pipeline-input adapters that turn an
3
+ // `EffectiveConfig`/`PipelineResult` into the JSON `pipeline.json` actually
4
+ // publishes, the review()/reviewPr() caller-seam wrappers around fail-soft
5
+ // metrics ingest and canonical-store persistence, and the repo-root
6
+ // resolver `configCommand` shares with `main`'s `setup` dispatch. Extracted
7
+ // from cli.ts (cli-decomp S2, Cluster A): every WHY comment below is carried
8
+ // over verbatim, unchanged in meaning or behavior.
9
+
10
+ import { existsSync } from "node:fs";
11
+ import os from "node:os";
12
+ import path from "node:path";
13
+ import { resolveRepoRoot } from "#git/git";
14
+ import type { FindingsDocument } from "#review/findings";
15
+ import type { PerAgentUsage, PipelineResult } from "#review/pipeline";
16
+ import {
17
+ type CliOptions,
18
+ type ConfigLayer,
19
+ type ConfigSources,
20
+ type LocalConfig,
21
+ mergeConfig,
22
+ parseGlobalConfig,
23
+ parseLocalConfig,
24
+ } from "#review/preflight";
25
+ import { type FailSoftIngestInput, failSoftIngest } from "#store/metrics";
26
+ import { projectCompleteRun } from "#store/preflight";
27
+ import { openProductStore, saveRunTransaction } from "#store/store";
28
+ import { resolveHomeDir, resolveRepoDir } from "../brand-paths";
29
+ import { CliError } from "../errors";
30
+ import { prheroLayout } from "../home-preflight";
31
+
32
+ // C5 O-6's half of the pipeline input. Unconditional, unlike its two
33
+ // neighbours above: the summarizer and the scout are stages that may not run,
34
+ // while a config ALWAYS resolved to something — and D7's whole point is that
35
+ // the artifact must discriminate the builds. `global_present` is carried
36
+ // separately because `sources` cannot express it: a global file that exists
37
+ // and says `{}` leaves every source at `repo` or `default`, exactly like no
38
+ // file at all.
39
+ // #173 (§8: "Artifacts and reports show cash and notional totals
40
+ // separately"). The shell's one decision on the cash/notional split, extracted
41
+ // into a pure function for the same reason `pipelineScoutInput` above is one:
42
+ // `review()` and `reviewPr()` are I/O shells nothing can call offline, so a
43
+ // decision left inline in them is a decision no test can reach. That matters
44
+ // more here than usual — `notionalCostUsd` spent three slices fully built and
45
+ // entirely unpopulated, and the step that goes missing in that pattern is
46
+ // always the last wiring one. Deleting the four call sites below must fail a
47
+ // test; without this function it flipped nothing.
48
+ //
49
+ // Absence, never zero: a run whose steps reported no normalized usage, or
50
+ // reported usage carrying no provider figure, yields NO key at all, and both
51
+ // renderers omit their notional line on `undefined`. A `0` default would print
52
+ // "$0.00 at list price" for a run that never produced a list price — the same
53
+ // fabrication `normalizeUnavailableUsage` exists to refuse, relocated to the
54
+ // terminal.
55
+ export function notionalCostInput(
56
+ result: Pick<PipelineResult, "usageV2">,
57
+ ): { notionalUsd: number } | Record<string, never> {
58
+ const notionalUsd = result.usageV2?.notionalCostUsd;
59
+ return notionalUsd === undefined ? {} : { notionalUsd };
60
+ }
61
+
62
+ export function pipelineConfigInput(loaded: EffectiveConfig): {
63
+ config: {
64
+ effective: LocalConfig;
65
+ sources: ConfigSources;
66
+ global_present: boolean;
67
+ };
68
+ } {
69
+ return {
70
+ config: {
71
+ effective: loaded.effective,
72
+ sources: loaded.sources,
73
+ global_present: loaded.globalPresent,
74
+ },
75
+ };
76
+ }
77
+
78
+ // The ONE caller-layer seam review() and reviewPr() both call after writing
79
+ // their artifact (W4 Phase 6 remediation, GitHub #23 option D — spec
80
+ // "Fail-Soft Ingest": "WHEN a review finishes THEN the review still exits
81
+ // successfully"). A thin wrapper around failSoftIngest is deliberate: the
82
+ // verify report flagged that the fail-soft proof lived one layer BELOW this
83
+ // call (failSoftIngest's own unit tests), never at the layer review()/
84
+ // reviewPr() actually invoke — this function IS that layer, so a test
85
+ // against it proves the same seam the two real callers use, not a sibling
86
+ // one.
87
+ export function ingestReviewMetrics(input: FailSoftIngestInput): void {
88
+ failSoftIngest(input);
89
+ }
90
+
91
+ export interface PersistCanonicalReviewInput {
92
+ dbPath?: string;
93
+ home?: string;
94
+ repoId: string | null;
95
+ runDir: string;
96
+ checkoutPath: string | null;
97
+ doc: FindingsDocument;
98
+ perAgent?: Record<string, PerAgentUsage>;
99
+ // The PR's diff base. Local runs pass none; the store keeps the value it has.
100
+ diffFromSha?: string | null;
101
+ generatedAt?: string;
102
+ log?: (line: string) => void;
103
+ // Test seam
104
+ persist?: (input: PersistCanonicalReviewInput) => number;
105
+ }
106
+
107
+ // Canonical Product Store (Fundamentals #6 / observability-canonical-store.md).
108
+ // Persists the complete run result into ~/.prhero/prhero.db transactionally.
109
+ export function persistCanonicalReview(
110
+ input: PersistCanonicalReviewInput,
111
+ ): number {
112
+ if (input.persist) {
113
+ return input.persist(input);
114
+ }
115
+ if (input.repoId === null) {
116
+ input.log?.(
117
+ "warning: no repo_id resolved for this run; skipping canonical store persistence",
118
+ );
119
+ return 0;
120
+ }
121
+ try {
122
+ const dbPath =
123
+ input.dbPath ?? prheroLayout(input.home ?? os.homedir()).prheroDbPath;
124
+ const db = openProductStore(dbPath);
125
+ try {
126
+ const projected = projectCompleteRun({
127
+ doc: input.doc,
128
+ perAgent: input.perAgent,
129
+ diffFromSha: input.diffFromSha,
130
+ repoId: input.repoId,
131
+ runDir: input.runDir,
132
+ checkoutPath: input.checkoutPath,
133
+ generatedAt: input.generatedAt,
134
+ });
135
+ return saveRunTransaction(db, projected);
136
+ } finally {
137
+ db.close();
138
+ }
139
+ } catch (err) {
140
+ input.log?.(
141
+ `warning: canonical store persistence failed — the review itself is intact: ${(err as Error).message}`,
142
+ );
143
+ return 0;
144
+ }
145
+ }
146
+
147
+ export interface EffectiveConfig {
148
+ // The ONE shape every resolver downstream receives, exactly as before C5.
149
+ // They cannot tell how it was built, which is the whole of D9's promise.
150
+ effective: LocalConfig;
151
+ sources: ConfigSources;
152
+ repoConfigPath: string;
153
+ globalConfigPath: string;
154
+ // Additive beyond design §3.4's four fields, and O-6 needs it: pipeline.json
155
+ // has to record whether a global layer EXISTED, and that is not derivable
156
+ // from `sources` — a global file that exists and says `{}` leaves every
157
+ // source at `repo` or `default`, indistinguishable from no file at all.
158
+ // Returned from the same stat the read used, so the artifact cannot
159
+ // disagree with what was actually loaded.
160
+ globalPresent: boolean;
161
+ }
162
+
163
+ // C5 §3.4 — the two-layer read, and the ONLY place either config file is
164
+ // opened on the review path. Replaces the duplicated
165
+ // existsSync/parseLocalConfig/EMPTY_LOCAL_CONFIG block that used to sit in
166
+ // both review() and reviewPr().
167
+ //
168
+ // `root` is the OPERATOR root in both modes and NEVER the review worktree
169
+ // (O-8): a reviewed PR's tree must not influence engine config, and the
170
+ // global file is read from os.homedir(), which is one step further from a PR
171
+ // author's reach than the operator checkout already was. C5 cannot weaken
172
+ // that boundary; it only adds a source the author has strictly less access to.
173
+ //
174
+ // WHY a missing file yields an ABSENT layer instead of EMPTY_LOCAL_CONFIG:
175
+ // the constant materialises `parity_trigger_paths: []` and
176
+ // `suspicion_priors: []`, so handing it to the merge would make "no file at
177
+ // all" indistinguishable from "a file that said []", and provenance would
178
+ // report `repo` for a layer that does not exist. mergeConfig decides what an
179
+ // all-silent run resolves to; EMPTY_LOCAL_CONFIG is now the shape that comes
180
+ // OUT of that, not the input that goes in.
181
+ //
182
+ // `--config` overrides the repo path only. A flag that repointed the global
183
+ // layer is a footgun with no use case. Its missing-file CliError is
184
+ // unchanged: an explicitly named file that is not there stays an error,
185
+ // because silently falling back to "no parity triggers" would disable a
186
+ // hunter the caller just asked for, and a hunter that never fires looks
187
+ // exactly like a hunter that found nothing.
188
+ // The global layer on its own, and the ONE place `~/.prhero/config.json` is
189
+ // opened. Two callers need it for different reasons and must not read it two
190
+ // ways: loadEffectiveConfig folds it under the repo file, while `pr-hero init`
191
+ // needs it WITHOUT the repo file, because init is writing that file and asking
192
+ // what the global already supplies is the whole of O-9. A second read site
193
+ // would be a second chance for the two to disagree about what "the global
194
+ // layer" is — the same reason §3.4 collapsed review()/reviewPr()'s duplicated
195
+ // block into one function.
196
+ //
197
+ // A malformed global file throws here, so it fails init exactly as loudly as
198
+ // it fails a review. That is deliberate: a scaffold silently written against
199
+ // "no global file" when there IS one, broken, would hardcode into the repo
200
+ // file precisely the keys the operator was about to fix.
201
+ export async function loadGlobalConfigLayer(home: string): Promise<{
202
+ filePath: string;
203
+ layer: ConfigLayer | undefined;
204
+ }> {
205
+ const filePath = prheroLayout(home).reviewConfigPath;
206
+ if (!existsSync(filePath)) return { filePath, layer: undefined };
207
+ return {
208
+ filePath,
209
+ layer: parseGlobalConfig(
210
+ await Bun.file(filePath).text(),
211
+ `~/${path.basename(path.dirname(filePath))}/config.json`,
212
+ ),
213
+ };
214
+ }
215
+
216
+ export async function loadEffectiveConfig(input: {
217
+ root?: string | undefined;
218
+ home: string;
219
+ configFlag?: string | undefined;
220
+ }): Promise<EffectiveConfig> {
221
+ const repoConfigPath = input.configFlag
222
+ ? path.resolve(input.configFlag)
223
+ : input.root
224
+ ? path.join(resolveRepoDir(input.root), "config.json")
225
+ : path.join(resolveHomeDir(input.home), "config.json");
226
+ if (input.configFlag && !existsSync(repoConfigPath)) {
227
+ throw new CliError(`config file not found: ${repoConfigPath}`);
228
+ }
229
+ const { filePath: globalConfigPath, layer: global } =
230
+ await loadGlobalConfigLayer(input.home);
231
+ // `global !== undefined` and not a second stat: the helper returns a layer
232
+ // exactly when the file was there and read, so the artifact's
233
+ // `global_present` cannot disagree with what was actually loaded — which is
234
+ // the property the field was added for.
235
+ const globalPresent = global !== undefined;
236
+ const repo =
237
+ (input.configFlag || input.root) && existsSync(repoConfigPath)
238
+ ? parseLocalConfig(
239
+ await Bun.file(repoConfigPath).text(),
240
+ input.configFlag
241
+ ? undefined
242
+ : `${path.basename(path.dirname(repoConfigPath))}/config.json`,
243
+ )
244
+ : {};
245
+ return {
246
+ ...mergeConfig(global, repo),
247
+ repoConfigPath,
248
+ globalConfigPath,
249
+ globalPresent,
250
+ };
251
+ }
252
+
253
+ // `pr-hero config`'s and `setup`'s shared repo-root resolver: unlike the
254
+ // review path (a missing/invalid repo is a hard CliError), both commands
255
+ // treat "not inside a repo" as a valid state — `config` renders the global
256
+ // layer alone, `setup` runs the wizard against `process.cwd()` outright.
257
+ // `options.repoExplicit` still enforces the same failure the review path
258
+ // does when the operator NAMED a --repo: an explicit flag that does not
259
+ // resolve should not silently degrade to "no repo".
260
+ export async function resolveOptionalRepoRoot(
261
+ options: CliOptions,
262
+ ): Promise<string | undefined> {
263
+ if (options.repoExplicit) {
264
+ return await resolveRepoRoot(options.repo);
265
+ }
266
+ return await resolveRepoRoot(process.cwd()).catch(() => undefined);
267
+ }