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.
- package/LICENSE +176 -0
- package/README.md +609 -3
- package/bin/pr-hero.js +166 -0
- package/config/models/anthropic.json +5 -0
- package/dist/SKILL-7e3725zn.md +496 -0
- package/dist/SKILL-7q35wcaz.md +66 -0
- package/dist/SKILL-9at22381.md +74 -0
- package/dist/SKILL-ex2hxxh3.md +134 -0
- package/dist/adjudicator-dtg2axnh.md +86 -0
- package/dist/admission-config.example-a9vqmmad.json +9 -0
- package/dist/ci-admission-camfbx2b.md +122 -0
- package/dist/cli.js +42292 -0
- package/dist/consolidate-ac0mnfyj.md +24 -0
- package/dist/deep-review-lifecycle-m698ybjp.md +362 -0
- package/dist/deep-review-logic-a6b1gczf.md +156 -0
- package/dist/deep-review-parity-0ec904db.md +120 -0
- package/dist/deep-review-reliability-qyakbjb9.md +125 -0
- package/dist/deep-review-resilience-3tz8y26e.md +118 -0
- package/dist/index.js +20190 -0
- package/dist/opencode-ci-7b0be64p.md +141 -0
- package/dist/review-refuter-j4e9gezy.md +71 -0
- package/dist/scout-yvp153q7.md +140 -0
- package/dist/summarizer-zca44nxa.md +18 -0
- package/dist/workflow-w1g9szna.yml +151 -0
- package/package.json +81 -4
- package/prompts/consolidate.md +24 -0
- package/prompts/default/PROVENANCE.md +18 -0
- package/prompts/default/deep-review-lifecycle.md +362 -0
- package/prompts/default/deep-review-logic.md +156 -0
- package/prompts/default/deep-review-parity.md +120 -0
- package/prompts/default/deep-review-reliability.md +125 -0
- package/prompts/default/deep-review-resilience.md +118 -0
- package/prompts/default/review-refuter.md +71 -0
- package/prompts/scout.md +140 -0
- package/prompts/summarizer.md +18 -0
- package/skills/crysk/SKILL.md +74 -0
- package/skills/crysk-ci-setup/SKILL.md +134 -0
- package/skills/crysk-ci-setup/assets/admission-config.example.json +9 -0
- package/skills/crysk-ci-setup/assets/workflow.yml +151 -0
- package/skills/crysk-ci-setup/references/ci-admission.md +122 -0
- package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
- package/skills/crysk-loop/SKILL.md +496 -0
- package/skills/crysk-loop/adjudicator.md +86 -0
- package/skills/crysk-pr/SKILL.md +66 -0
- package/src/agent-env.ts +1084 -0
- package/src/asset-manifest.ts +83 -0
- package/src/assets.d.ts +6 -0
- package/src/assets.ts +183 -0
- package/src/brand-paths.ts +155 -0
- package/src/brand.ts +255 -0
- package/src/ci/admission-ledger.ts +350 -0
- package/src/ci/classify-error.ts +73 -0
- package/src/ci/cli-record.ts +271 -0
- package/src/ci/force-comment.ts +39 -0
- package/src/ci/gates.ts +923 -0
- package/src/ci/outcome.ts +2181 -0
- package/src/ci/override.ts +187 -0
- package/src/ci/publish.ts +1639 -0
- package/src/ci/reporter.ts +626 -0
- package/src/ci/review-admission.ts +901 -0
- package/src/ci/review-levels.ts +310 -0
- package/src/ci/review-policy.ts +18 -0
- package/src/ci/review-risk.ts +184 -0
- package/src/ci/setup.ts +844 -0
- package/src/ci/trigger.ts +1353 -0
- package/src/cli.ts +348 -0
- package/src/commands/activity.ts +67 -0
- package/src/commands/ci-setup-questions.ts +397 -0
- package/src/commands/ci-setup.ts +381 -0
- package/src/commands/config.ts +99 -0
- package/src/commands/doctor.ts +108 -0
- package/src/commands/init.ts +139 -0
- package/src/commands/mcp.ts +10 -0
- package/src/commands/menu.ts +129 -0
- package/src/commands/post.ts +302 -0
- package/src/commands/skills.ts +83 -0
- package/src/commands/status.ts +173 -0
- package/src/commands/triage.ts +342 -0
- package/src/commands/uninstall.ts +37 -0
- package/src/commands/upgrade.ts +214 -0
- package/src/commands/usage.ts +98 -0
- package/src/compare/compare.ts +28 -0
- package/src/compare/floor-test.ts +471 -0
- package/src/compare/martian-adapter.ts +80 -0
- package/src/config/config.ts +267 -0
- package/src/corpus/corpus.ts +1094 -0
- package/src/corpus/preflight.ts +1789 -0
- package/src/diversity/accounting.ts +90 -0
- package/src/diversity/adjudication.ts +145 -0
- package/src/diversity/admission.ts +60 -0
- package/src/diversity/benchmark.ts +195 -0
- package/src/diversity/clustering.ts +285 -0
- package/src/diversity/errors.ts +7 -0
- package/src/diversity/identity.ts +285 -0
- package/src/diversity/index.ts +11 -0
- package/src/diversity/pipeline-integration.ts +448 -0
- package/src/diversity/projection.ts +57 -0
- package/src/diversity/self-contained.ts +68 -0
- package/src/diversity/target-validation.ts +179 -0
- package/src/doctor-migration.ts +209 -0
- package/src/doctor.ts +723 -0
- package/src/errors.ts +83 -0
- package/src/execution/admission.ts +75 -0
- package/src/execution/atomic-write.ts +35 -0
- package/src/execution/attempt-evidence.ts +415 -0
- package/src/execution/bucket-id.ts +136 -0
- package/src/execution/concurrency-limiter.ts +175 -0
- package/src/execution/contracts.ts +443 -0
- package/src/execution/failure-classification.ts +42 -0
- package/src/execution/failure-policy.ts +240 -0
- package/src/execution/harness.ts +2548 -0
- package/src/execution/settlement.ts +348 -0
- package/src/execution/spawned-process.ts +66 -0
- package/src/execution/spend-limiter.ts +424 -0
- package/src/execution/step-artifacts.ts +55 -0
- package/src/execution/usage-normalized.ts +469 -0
- package/src/git/git.ts +396 -0
- package/src/git/identity.ts +64 -0
- package/src/git/refs.ts +140 -0
- package/src/home-preflight.ts +443 -0
- package/src/home.ts +243 -0
- package/src/ignore-file.ts +336 -0
- package/src/ignore-read.ts +118 -0
- package/src/index.ts +34 -0
- package/src/legacy-launchd.ts +29 -0
- package/src/mcp/mcp.ts +150 -0
- package/src/mcp/preflight.ts +407 -0
- package/src/menu-context.ts +192 -0
- package/src/model/catalog.ts +251 -0
- package/src/model/exec-snapshots.ts +390 -0
- package/src/model/free-discovery.ts +302 -0
- package/src/model/provider-capabilities.ts +814 -0
- package/src/model/routing.ts +600 -0
- package/src/pr/admission.ts +847 -0
- package/src/pr/ci-admission-gate.ts +665 -0
- package/src/pr/ci-publish.ts +76 -0
- package/src/pr/discovery.ts +432 -0
- package/src/pr/inline.ts +507 -0
- package/src/pr/plan.ts +366 -0
- package/src/pr/posting.ts +115 -0
- package/src/pr/pr-status.ts +787 -0
- package/src/pr/pr.ts +3642 -0
- package/src/pr/preflight.ts +1031 -0
- package/src/pr/publish-outcome.ts +361 -0
- package/src/pr/range.ts +119 -0
- package/src/pr/reverts-preflight.ts +606 -0
- package/src/pr/reverts.ts +377 -0
- package/src/pr/review-pr.ts +927 -0
- package/src/pr/status.ts +154 -0
- package/src/pr/target.ts +388 -0
- package/src/pr/teardown.ts +437 -0
- package/src/pr/worktree-setup.ts +60 -0
- package/src/production-runtime.ts +1877 -0
- package/src/progress.ts +487 -0
- package/src/rereview/adjudicate.ts +89 -0
- package/src/rereview/classify.ts +362 -0
- package/src/rereview/identity.ts +211 -0
- package/src/rereview/plan.ts +308 -0
- package/src/rereview/prepare.ts +1025 -0
- package/src/rereview/state.ts +767 -0
- package/src/rereview/verify.ts +241 -0
- package/src/review/boundary.ts +105 -0
- package/src/review/consolidate.ts +246 -0
- package/src/review/dedupe.ts +368 -0
- package/src/review/drafts.ts +448 -0
- package/src/review/findings-conformance.ts +120 -0
- package/src/review/findings.ts +714 -0
- package/src/review/pipeline.ts +3977 -0
- package/src/review/preflight.ts +3575 -0
- package/src/review/prompt-set.ts +177 -0
- package/src/review/proof-refs.ts +187 -0
- package/src/review/report.ts +1821 -0
- package/src/review/review.ts +490 -0
- package/src/review/root-cause.ts +120 -0
- package/src/review/route-preflight.ts +289 -0
- package/src/review/run.ts +601 -0
- package/src/review/scout.ts +323 -0
- package/src/review/size-gate.ts +595 -0
- package/src/review/spec.ts +235 -0
- package/src/review/step-runner.ts +233 -0
- package/src/runner-authority.ts +596 -0
- package/src/security/binding-policy.ts +115 -0
- package/src/security/credential-broker.ts +773 -0
- package/src/security/evidence-redaction.ts +62 -0
- package/src/security/execution-authority.ts +27 -0
- package/src/security/redact.ts +71 -0
- package/src/security/workspace-read-broker.ts +466 -0
- package/src/server/client.ts +190 -0
- package/src/server/preflight.ts +217 -0
- package/src/server/server.ts +327 -0
- package/src/signal-handler.ts +50 -0
- package/src/store/activity.ts +413 -0
- package/src/store/backfill-preflight.ts +49 -0
- package/src/store/backfill.ts +141 -0
- package/src/store/gc-preflight.ts +206 -0
- package/src/store/gc.ts +424 -0
- package/src/store/metrics-preflight.ts +229 -0
- package/src/store/metrics.ts +236 -0
- package/src/store/preflight.ts +748 -0
- package/src/store/store.ts +693 -0
- package/src/system-tools.ts +355 -0
- package/src/transport-registry.ts +1124 -0
- package/src/transports/claude-code-cli.ts +1348 -0
- package/src/transports/opencode-admission.ts +515 -0
- package/src/transports/opencode-client.ts +3328 -0
- package/src/transports/opencode-evidence.ts +557 -0
- package/src/transports/opencode-mcp.ts +248 -0
- package/src/transports/opencode-sdk.ts +2294 -0
- package/src/transports/opencode-server.ts +535 -0
- package/src/triage/adjudication.ts +113 -0
- package/src/triage/reply.ts +125 -0
- package/src/triage/triage.ts +255 -0
- package/src/ui/activity.ts +173 -0
- package/src/ui/config-edit.ts +816 -0
- package/src/ui/config.ts +462 -0
- package/src/ui/menu.ts +1325 -0
- package/src/ui/plan.ts +1039 -0
- package/src/ui/primitives.ts +300 -0
- package/src/ui/progress.ts +298 -0
- package/src/ui/result.ts +552 -0
- package/src/ui/review-menu.ts +312 -0
- package/src/ui/select.ts +528 -0
- package/src/ui/tree.ts +178 -0
- package/src/uninstaller.ts +479 -0
- package/src/updater.ts +836 -0
- package/src/usage.ts +77 -0
- package/src/watch/preflight.ts +1389 -0
- package/src/watch/watch.ts +1235 -0
- package/src/wizard.ts +877 -0
|
@@ -0,0 +1,816 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
mergeConfig,
|
|
6
|
+
parseGlobalConfig,
|
|
7
|
+
parseLocalConfig,
|
|
8
|
+
} from "#review/preflight";
|
|
9
|
+
import { resolveHomeDir, resolveRepoDir } from "../brand-paths";
|
|
10
|
+
import { bold, box, cyan, dim, sanitizeText, yellow } from "./primitives";
|
|
11
|
+
import type { KeyReader } from "./select";
|
|
12
|
+
|
|
13
|
+
export interface ConfigEntry {
|
|
14
|
+
key: string;
|
|
15
|
+
value: string;
|
|
16
|
+
desc: string;
|
|
17
|
+
type?: "string" | "number" | "boolean";
|
|
18
|
+
currentRaw?: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getEditableLayerEntries(
|
|
22
|
+
layer: "team" | "person" | "watch",
|
|
23
|
+
rawData: Record<string, unknown>,
|
|
24
|
+
): ConfigEntry[] {
|
|
25
|
+
if (layer === "team") {
|
|
26
|
+
const base =
|
|
27
|
+
typeof rawData.default_base === "string"
|
|
28
|
+
? rawData.default_base
|
|
29
|
+
: "(not set)";
|
|
30
|
+
const lines =
|
|
31
|
+
typeof rawData.max_changed_lines === "number"
|
|
32
|
+
? rawData.max_changed_lines.toString()
|
|
33
|
+
: "(not set)";
|
|
34
|
+
const files =
|
|
35
|
+
typeof rawData.max_changed_files === "number"
|
|
36
|
+
? rawData.max_changed_files.toString()
|
|
37
|
+
: "(not set)";
|
|
38
|
+
const steps =
|
|
39
|
+
typeof rawData.max_verification_steps === "number"
|
|
40
|
+
? rawData.max_verification_steps.toString()
|
|
41
|
+
: "(not set)";
|
|
42
|
+
const summaryObj =
|
|
43
|
+
typeof rawData.summary === "object" && rawData.summary !== null
|
|
44
|
+
? (rawData.summary as Record<string, unknown>)
|
|
45
|
+
: {};
|
|
46
|
+
const summaryEnabled =
|
|
47
|
+
typeof summaryObj.enabled === "boolean"
|
|
48
|
+
? summaryObj.enabled
|
|
49
|
+
? "[✓] true"
|
|
50
|
+
: "[ ] false"
|
|
51
|
+
: "(not set)";
|
|
52
|
+
const scoutVal =
|
|
53
|
+
typeof rawData.scout === "boolean"
|
|
54
|
+
? rawData.scout
|
|
55
|
+
? "[✓] true"
|
|
56
|
+
: "[ ] false"
|
|
57
|
+
: "(not set)";
|
|
58
|
+
const postVal =
|
|
59
|
+
typeof rawData.post === "boolean"
|
|
60
|
+
? rawData.post
|
|
61
|
+
? "[✓] true"
|
|
62
|
+
: "[ ] false"
|
|
63
|
+
: "(not set)";
|
|
64
|
+
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
key: "default_base",
|
|
68
|
+
value: base,
|
|
69
|
+
desc: "Default base branch",
|
|
70
|
+
type: "string",
|
|
71
|
+
currentRaw: rawData.default_base,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
key: "max_changed_lines",
|
|
75
|
+
value: lines,
|
|
76
|
+
desc: "Line budget threshold (0 disables)",
|
|
77
|
+
type: "number",
|
|
78
|
+
currentRaw: rawData.max_changed_lines,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
key: "max_changed_files",
|
|
82
|
+
value: files,
|
|
83
|
+
desc: "File budget threshold (0 disables)",
|
|
84
|
+
type: "number",
|
|
85
|
+
currentRaw: rawData.max_changed_files,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
key: "max_verification_steps",
|
|
89
|
+
value: steps,
|
|
90
|
+
desc: "Max refuter verification steps",
|
|
91
|
+
type: "number",
|
|
92
|
+
currentRaw: rawData.max_verification_steps,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
key: "summary.enabled",
|
|
96
|
+
value: summaryEnabled,
|
|
97
|
+
desc: "Generate AI summary overview",
|
|
98
|
+
type: "boolean",
|
|
99
|
+
currentRaw: summaryObj.enabled,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
key: "scout",
|
|
103
|
+
value: scoutVal,
|
|
104
|
+
desc: "Run scout reconnaissance stage",
|
|
105
|
+
type: "boolean",
|
|
106
|
+
currentRaw: rawData.scout,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
key: "post",
|
|
110
|
+
value: postVal,
|
|
111
|
+
desc: "Publish review as PR comment",
|
|
112
|
+
type: "boolean",
|
|
113
|
+
currentRaw: rawData.post,
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (layer === "person") {
|
|
119
|
+
const lines =
|
|
120
|
+
typeof rawData.max_changed_lines === "number"
|
|
121
|
+
? rawData.max_changed_lines.toString()
|
|
122
|
+
: "(not set)";
|
|
123
|
+
const files =
|
|
124
|
+
typeof rawData.max_changed_files === "number"
|
|
125
|
+
? rawData.max_changed_files.toString()
|
|
126
|
+
: "(not set)";
|
|
127
|
+
const steps =
|
|
128
|
+
typeof rawData.max_verification_steps === "number"
|
|
129
|
+
? rawData.max_verification_steps.toString()
|
|
130
|
+
: "(not set)";
|
|
131
|
+
const summaryObj =
|
|
132
|
+
typeof rawData.summary === "object" && rawData.summary !== null
|
|
133
|
+
? (rawData.summary as Record<string, unknown>)
|
|
134
|
+
: {};
|
|
135
|
+
const summaryEnabled =
|
|
136
|
+
typeof summaryObj.enabled === "boolean"
|
|
137
|
+
? summaryObj.enabled
|
|
138
|
+
? "[✓] true"
|
|
139
|
+
: "[ ] false"
|
|
140
|
+
: "(not set)";
|
|
141
|
+
const scoutVal =
|
|
142
|
+
typeof rawData.scout === "boolean"
|
|
143
|
+
? rawData.scout
|
|
144
|
+
? "[✓] true"
|
|
145
|
+
: "[ ] false"
|
|
146
|
+
: "(not set)";
|
|
147
|
+
const postVal =
|
|
148
|
+
typeof rawData.post === "boolean"
|
|
149
|
+
? rawData.post
|
|
150
|
+
? "[✓] true"
|
|
151
|
+
: "[ ] false"
|
|
152
|
+
: "(not set)";
|
|
153
|
+
|
|
154
|
+
return [
|
|
155
|
+
{
|
|
156
|
+
key: "max_changed_lines",
|
|
157
|
+
value: lines,
|
|
158
|
+
desc: "Personal line budget ceiling (0 disables)",
|
|
159
|
+
type: "number",
|
|
160
|
+
currentRaw: rawData.max_changed_lines,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
key: "max_changed_files",
|
|
164
|
+
value: files,
|
|
165
|
+
desc: "Personal file budget ceiling (0 disables)",
|
|
166
|
+
type: "number",
|
|
167
|
+
currentRaw: rawData.max_changed_files,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
key: "max_verification_steps",
|
|
171
|
+
value: steps,
|
|
172
|
+
desc: "Personal max refuter ceiling",
|
|
173
|
+
type: "number",
|
|
174
|
+
currentRaw: rawData.max_verification_steps,
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
key: "summary.enabled",
|
|
178
|
+
value: summaryEnabled,
|
|
179
|
+
desc: "Generate AI summary overview",
|
|
180
|
+
type: "boolean",
|
|
181
|
+
currentRaw: summaryObj.enabled,
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
key: "scout",
|
|
185
|
+
value: scoutVal,
|
|
186
|
+
desc: "Personal scout reconnaissance ceiling",
|
|
187
|
+
type: "boolean",
|
|
188
|
+
currentRaw: rawData.scout,
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
key: "post",
|
|
192
|
+
value: postVal,
|
|
193
|
+
desc: "Personal PR posting ceiling",
|
|
194
|
+
type: "boolean",
|
|
195
|
+
currentRaw: rawData.post,
|
|
196
|
+
},
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (layer === "watch") {
|
|
201
|
+
const cap =
|
|
202
|
+
typeof rawData.daily_cap === "number"
|
|
203
|
+
? rawData.daily_cap.toString()
|
|
204
|
+
: "(not set)";
|
|
205
|
+
let windowStr = "(not set)";
|
|
206
|
+
if (typeof rawData.window === "object" && rawData.window !== null) {
|
|
207
|
+
const w = rawData.window as { start?: string; end?: string };
|
|
208
|
+
if (w.start && w.end) {
|
|
209
|
+
windowStr = `${w.start}-${w.end}`;
|
|
210
|
+
}
|
|
211
|
+
} else if (typeof rawData.window === "string") {
|
|
212
|
+
windowStr = rawData.window;
|
|
213
|
+
}
|
|
214
|
+
return [
|
|
215
|
+
{
|
|
216
|
+
key: "daily_cap",
|
|
217
|
+
value: cap,
|
|
218
|
+
desc: "Daily automatic review limit",
|
|
219
|
+
type: "number",
|
|
220
|
+
currentRaw: rawData.daily_cap,
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
key: "window",
|
|
224
|
+
value: windowStr,
|
|
225
|
+
desc: "Active hours window (e.g. 09:00-18:00)",
|
|
226
|
+
type: "string",
|
|
227
|
+
currentRaw: rawData.window,
|
|
228
|
+
},
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function stepNumericValue(
|
|
236
|
+
current: number,
|
|
237
|
+
delta: number,
|
|
238
|
+
min = 0,
|
|
239
|
+
max?: number,
|
|
240
|
+
): number {
|
|
241
|
+
const next = current + delta;
|
|
242
|
+
const clampedMin = Math.max(min, next);
|
|
243
|
+
return max !== undefined ? Math.min(max, clampedMin) : clampedMin;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function toggleBooleanValue(current: boolean): boolean {
|
|
247
|
+
return !current;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function cycleStringPreset(
|
|
251
|
+
current: string,
|
|
252
|
+
presets: readonly string[],
|
|
253
|
+
): string {
|
|
254
|
+
if (presets.length === 0) return current;
|
|
255
|
+
const idx = presets.indexOf(current);
|
|
256
|
+
if (idx === -1) return presets[0];
|
|
257
|
+
return presets[(idx + 1) % presets.length];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function renderConfigLayerSelection(
|
|
261
|
+
layers: string[],
|
|
262
|
+
cursor: number,
|
|
263
|
+
width: number,
|
|
264
|
+
styles: boolean,
|
|
265
|
+
): string[] {
|
|
266
|
+
const lines = layers.map((layer, idx) => {
|
|
267
|
+
const isSelected = idx === cursor;
|
|
268
|
+
const prefix = isSelected ? "▸ " : " ";
|
|
269
|
+
const line = sanitizeText(`${prefix}${idx + 1}. ${layer}`);
|
|
270
|
+
return isSelected ? bold(cyan(line, styles), styles) : line;
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
return box("Select Configuration Layer", lines, {
|
|
274
|
+
width,
|
|
275
|
+
styles,
|
|
276
|
+
borderStyle: "double",
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export const DEFAULT_CARD_ACTIONS = [
|
|
281
|
+
"[ Save changes ]",
|
|
282
|
+
"[ Discard & back ]",
|
|
283
|
+
"[ Clear all (unset) ]",
|
|
284
|
+
] as const;
|
|
285
|
+
|
|
286
|
+
export function renderConfigEditCard(
|
|
287
|
+
title: string,
|
|
288
|
+
entries: ConfigEntry[],
|
|
289
|
+
cursor: number,
|
|
290
|
+
width: number,
|
|
291
|
+
styles: boolean,
|
|
292
|
+
annotation?: string,
|
|
293
|
+
actions: readonly string[] = DEFAULT_CARD_ACTIONS,
|
|
294
|
+
): string[] {
|
|
295
|
+
const lines: string[] = [];
|
|
296
|
+
|
|
297
|
+
for (let idx = 0; idx < entries.length; idx++) {
|
|
298
|
+
const entry = entries[idx];
|
|
299
|
+
const isSelected = idx === cursor;
|
|
300
|
+
const prefix = isSelected ? "▸ " : " ";
|
|
301
|
+
const rawLine = `${prefix}${entry.key}: ${entry.value} — ${entry.desc}`;
|
|
302
|
+
const sanitized = sanitizeText(rawLine);
|
|
303
|
+
lines.push(isSelected ? bold(cyan(sanitized, styles), styles) : sanitized);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (actions.length > 0) {
|
|
307
|
+
lines.push("");
|
|
308
|
+
const innerWidth = Math.max(10, width - 4);
|
|
309
|
+
lines.push(dim("─".repeat(innerWidth), styles));
|
|
310
|
+
for (let i = 0; i < actions.length; i++) {
|
|
311
|
+
const actionIdx = entries.length + i;
|
|
312
|
+
const isSelected = actionIdx === cursor;
|
|
313
|
+
const prefix = isSelected ? "▸ " : " ";
|
|
314
|
+
const line = `${prefix}${actions[i]}`;
|
|
315
|
+
lines.push(
|
|
316
|
+
isSelected ? bold(cyan(line, styles), styles) : sanitizeText(line),
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (annotation) {
|
|
322
|
+
lines.push("");
|
|
323
|
+
lines.push(sanitizeText(` ${yellow("Note:", styles)} ${annotation}`));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return box(title, lines, {
|
|
327
|
+
width,
|
|
328
|
+
styles,
|
|
329
|
+
borderStyle: "double",
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export async function saveLayerConfig(input: {
|
|
334
|
+
layer: "team" | "person" | "watch";
|
|
335
|
+
draft: Record<string, unknown>;
|
|
336
|
+
home?: string;
|
|
337
|
+
repoRoot?: string;
|
|
338
|
+
}): Promise<{ status: "ok"; annotation?: string }> {
|
|
339
|
+
const home = input.home ?? os.homedir();
|
|
340
|
+
let targetFile: string;
|
|
341
|
+
|
|
342
|
+
if (input.layer === "team") {
|
|
343
|
+
if (!input.repoRoot) {
|
|
344
|
+
throw new Error(
|
|
345
|
+
"cannot edit team configuration outside a git repository",
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
targetFile = path.join(resolveRepoDir(input.repoRoot), "config.json");
|
|
349
|
+
} else if (input.layer === "person") {
|
|
350
|
+
targetFile = path.join(resolveHomeDir(home), "config.json");
|
|
351
|
+
} else {
|
|
352
|
+
targetFile = path.join(resolveHomeDir(home), "watch.json");
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const dir = path.dirname(targetFile);
|
|
356
|
+
if (!existsSync(dir)) {
|
|
357
|
+
mkdirSync(dir, { recursive: true });
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
writeFileSync(targetFile, `${JSON.stringify(input.draft, null, 2)}\n`);
|
|
361
|
+
|
|
362
|
+
let annotation: string | undefined;
|
|
363
|
+
if (input.layer === "team") {
|
|
364
|
+
const personFile = path.join(resolveHomeDir(home), "config.json");
|
|
365
|
+
if (existsSync(personFile)) {
|
|
366
|
+
try {
|
|
367
|
+
const personData = JSON.parse(readFileSync(personFile, "utf-8"));
|
|
368
|
+
if (
|
|
369
|
+
typeof input.draft.max_verification_steps === "number" &&
|
|
370
|
+
typeof personData.max_verification_steps === "number" &&
|
|
371
|
+
input.draft.max_verification_steps > personData.max_verification_steps
|
|
372
|
+
) {
|
|
373
|
+
annotation = `effective max_verification_steps remains ${personData.max_verification_steps} (capped by person config)`;
|
|
374
|
+
} else if (
|
|
375
|
+
typeof input.draft.max_changed_lines === "number" &&
|
|
376
|
+
typeof personData.max_changed_lines === "number" &&
|
|
377
|
+
input.draft.max_changed_lines > personData.max_changed_lines
|
|
378
|
+
) {
|
|
379
|
+
annotation = `effective max_changed_lines remains ${personData.max_changed_lines} (capped by person config)`;
|
|
380
|
+
} else if (
|
|
381
|
+
typeof input.draft.max_changed_files === "number" &&
|
|
382
|
+
typeof personData.max_changed_files === "number" &&
|
|
383
|
+
input.draft.max_changed_files > personData.max_changed_files
|
|
384
|
+
) {
|
|
385
|
+
annotation = `effective max_changed_files remains ${personData.max_changed_files} (capped by person config)`;
|
|
386
|
+
}
|
|
387
|
+
} catch {
|
|
388
|
+
// ignore
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const saveAnnotation = annotation
|
|
394
|
+
? `✓ Saved ${targetFile} (${annotation})`
|
|
395
|
+
: `✓ Saved ${targetFile}`;
|
|
396
|
+
|
|
397
|
+
return { status: "ok", annotation: saveAnnotation };
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const TIME_WINDOW_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
401
|
+
|
|
402
|
+
export async function setConfigValue(input: {
|
|
403
|
+
layer: "person" | "team" | "watch";
|
|
404
|
+
key: string;
|
|
405
|
+
value: string;
|
|
406
|
+
home?: string;
|
|
407
|
+
repoRoot?: string;
|
|
408
|
+
}): Promise<{ status: "ok"; annotation?: string }> {
|
|
409
|
+
const home = input.home ?? os.homedir();
|
|
410
|
+
|
|
411
|
+
if (input.layer === "team") {
|
|
412
|
+
if (!input.repoRoot) {
|
|
413
|
+
throw new Error(
|
|
414
|
+
"cannot edit team configuration outside a git repository",
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
const repoConfigPath = path.join(
|
|
418
|
+
resolveRepoDir(input.repoRoot),
|
|
419
|
+
"config.json",
|
|
420
|
+
);
|
|
421
|
+
let currentRepo: Record<string, unknown> = {};
|
|
422
|
+
if (existsSync(repoConfigPath)) {
|
|
423
|
+
try {
|
|
424
|
+
currentRepo = JSON.parse(readFileSync(repoConfigPath, "utf-8"));
|
|
425
|
+
} catch {
|
|
426
|
+
currentRepo = {};
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
let parsedVal: unknown = input.value;
|
|
431
|
+
if (input.key === "max_verification_steps") {
|
|
432
|
+
const num = Number.parseInt(input.value, 10);
|
|
433
|
+
if (Number.isNaN(num) || num < 0) {
|
|
434
|
+
throw new Error(
|
|
435
|
+
"max_verification_steps must be a non-negative integer",
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
parsedVal = num;
|
|
439
|
+
currentRepo.max_verification_steps = num;
|
|
440
|
+
} else if (input.key === "max_changed_lines") {
|
|
441
|
+
const num = Number.parseInt(input.value, 10);
|
|
442
|
+
if (Number.isNaN(num) || num < 0) {
|
|
443
|
+
throw new Error("max_changed_lines must be a non-negative integer");
|
|
444
|
+
}
|
|
445
|
+
parsedVal = num;
|
|
446
|
+
currentRepo.max_changed_lines = num;
|
|
447
|
+
} else if (input.key === "max_changed_files") {
|
|
448
|
+
const num = Number.parseInt(input.value, 10);
|
|
449
|
+
if (Number.isNaN(num) || num < 0) {
|
|
450
|
+
throw new Error("max_changed_files must be a non-negative integer");
|
|
451
|
+
}
|
|
452
|
+
parsedVal = num;
|
|
453
|
+
currentRepo.max_changed_files = num;
|
|
454
|
+
} else if (input.key === "summary.enabled") {
|
|
455
|
+
const b = input.value.toLowerCase() === "true";
|
|
456
|
+
parsedVal = b;
|
|
457
|
+
currentRepo.summary = {
|
|
458
|
+
...(typeof currentRepo.summary === "object" &&
|
|
459
|
+
currentRepo.summary !== null
|
|
460
|
+
? (currentRepo.summary as Record<string, unknown>)
|
|
461
|
+
: {}),
|
|
462
|
+
enabled: b,
|
|
463
|
+
};
|
|
464
|
+
} else if (input.key === "summary.model") {
|
|
465
|
+
if (typeof input.value !== "string" || input.value.trim().length === 0) {
|
|
466
|
+
throw new Error("summary.model must be a non-empty string");
|
|
467
|
+
}
|
|
468
|
+
currentRepo.summary = {
|
|
469
|
+
...(typeof currentRepo.summary === "object" &&
|
|
470
|
+
currentRepo.summary !== null
|
|
471
|
+
? (currentRepo.summary as Record<string, unknown>)
|
|
472
|
+
: {}),
|
|
473
|
+
model: input.value.trim(),
|
|
474
|
+
};
|
|
475
|
+
} else if (input.key === "default_base") {
|
|
476
|
+
if (typeof input.value !== "string" || input.value.trim().length === 0) {
|
|
477
|
+
throw new Error("default_base must be a non-empty string");
|
|
478
|
+
}
|
|
479
|
+
currentRepo.default_base = input.value.trim();
|
|
480
|
+
} else if (input.key === "parity_trigger_paths") {
|
|
481
|
+
let paths: string[];
|
|
482
|
+
if (input.value.startsWith("[")) {
|
|
483
|
+
try {
|
|
484
|
+
paths = JSON.parse(input.value);
|
|
485
|
+
} catch {
|
|
486
|
+
throw new Error(
|
|
487
|
+
"parity_trigger_paths must be an array of non-empty strings",
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
} else {
|
|
491
|
+
paths = input.value
|
|
492
|
+
.split(",")
|
|
493
|
+
.map((s) => s.trim())
|
|
494
|
+
.filter(Boolean);
|
|
495
|
+
}
|
|
496
|
+
if (
|
|
497
|
+
!Array.isArray(paths) ||
|
|
498
|
+
paths.length === 0 ||
|
|
499
|
+
paths.some((p) => typeof p !== "string" || p.trim().length === 0)
|
|
500
|
+
) {
|
|
501
|
+
throw new Error(
|
|
502
|
+
"parity_trigger_paths must be an array of non-empty strings",
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
currentRepo.parity_trigger_paths = paths;
|
|
506
|
+
} else if (input.key === "agents_dir") {
|
|
507
|
+
currentRepo.agents_dir = input.value.trim();
|
|
508
|
+
} else if (input.key === "scout") {
|
|
509
|
+
const b = input.value.toLowerCase() === "true";
|
|
510
|
+
parsedVal = b;
|
|
511
|
+
currentRepo.scout = b;
|
|
512
|
+
} else if (input.key === "post") {
|
|
513
|
+
const b = input.value.toLowerCase() === "true";
|
|
514
|
+
parsedVal = b;
|
|
515
|
+
currentRepo.post = b;
|
|
516
|
+
} else {
|
|
517
|
+
throw new Error(
|
|
518
|
+
`unknown or unsupported key for team configuration: ${input.key}`,
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
writeFileSync(repoConfigPath, `${JSON.stringify(currentRepo, null, 2)}\n`);
|
|
523
|
+
|
|
524
|
+
// Check annotation from mergeConfig
|
|
525
|
+
let annotation: string | undefined;
|
|
526
|
+
const personConfigPath = path.join(resolveHomeDir(home), "config.json");
|
|
527
|
+
if (existsSync(personConfigPath)) {
|
|
528
|
+
try {
|
|
529
|
+
const globalLayer = parseGlobalConfig(
|
|
530
|
+
readFileSync(personConfigPath, "utf-8"),
|
|
531
|
+
);
|
|
532
|
+
const repoLayer = parseLocalConfig(
|
|
533
|
+
readFileSync(repoConfigPath, "utf-8"),
|
|
534
|
+
);
|
|
535
|
+
const merged = mergeConfig(globalLayer, repoLayer);
|
|
536
|
+
if (
|
|
537
|
+
input.key === "max_verification_steps" &&
|
|
538
|
+
globalLayer.max_verification_steps !== undefined &&
|
|
539
|
+
parsedVal !== merged.effective.max_verification_steps
|
|
540
|
+
) {
|
|
541
|
+
annotation = `written: ${parsedVal} — your effective value remains ${merged.effective.max_verification_steps}, capped by your Person layer`;
|
|
542
|
+
} else if (
|
|
543
|
+
input.key === "max_changed_lines" &&
|
|
544
|
+
globalLayer.max_changed_lines !== undefined &&
|
|
545
|
+
parsedVal !== merged.effective.max_changed_lines
|
|
546
|
+
) {
|
|
547
|
+
annotation = `written: ${parsedVal} — your effective value remains ${merged.effective.max_changed_lines}, capped by your Person layer`;
|
|
548
|
+
} else if (
|
|
549
|
+
input.key === "max_changed_files" &&
|
|
550
|
+
globalLayer.max_changed_files !== undefined &&
|
|
551
|
+
parsedVal !== merged.effective.max_changed_files
|
|
552
|
+
) {
|
|
553
|
+
annotation = `written: ${parsedVal} — your effective value remains ${merged.effective.max_changed_files}, capped by your Person layer`;
|
|
554
|
+
} else if (
|
|
555
|
+
input.key === "summary.enabled" &&
|
|
556
|
+
globalLayer.summary?.enabled !== undefined &&
|
|
557
|
+
merged.effective.summary?.enabled !== parsedVal
|
|
558
|
+
) {
|
|
559
|
+
annotation = `written: ${parsedVal} — your effective value remains ${merged.effective.summary?.enabled}, capped by your Person layer`;
|
|
560
|
+
} else if (
|
|
561
|
+
input.key === "scout" &&
|
|
562
|
+
globalLayer.scout !== undefined &&
|
|
563
|
+
merged.effective.scout !== parsedVal
|
|
564
|
+
) {
|
|
565
|
+
annotation = `written: ${parsedVal} — your effective value remains ${merged.effective.scout}, capped by your Person layer`;
|
|
566
|
+
} else if (
|
|
567
|
+
input.key === "post" &&
|
|
568
|
+
globalLayer.post !== undefined &&
|
|
569
|
+
merged.effective.post !== parsedVal
|
|
570
|
+
) {
|
|
571
|
+
annotation = `written: ${parsedVal} — your effective value remains ${merged.effective.post}, capped by your Person layer`;
|
|
572
|
+
}
|
|
573
|
+
} catch {
|
|
574
|
+
// Ignore
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return { status: "ok", annotation };
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
if (input.layer === "person") {
|
|
582
|
+
if (
|
|
583
|
+
input.key === "default_base" ||
|
|
584
|
+
input.key === "parity_trigger_paths" ||
|
|
585
|
+
input.key === "suspicion_priors"
|
|
586
|
+
) {
|
|
587
|
+
throw new Error(
|
|
588
|
+
`${input.key} is a per-repo key; use --team to configure it.`,
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
const personConfigPath = path.join(resolveHomeDir(home), "config.json");
|
|
593
|
+
let currentPerson: Record<string, unknown> = {};
|
|
594
|
+
if (existsSync(personConfigPath)) {
|
|
595
|
+
try {
|
|
596
|
+
currentPerson = JSON.parse(readFileSync(personConfigPath, "utf-8"));
|
|
597
|
+
} catch {
|
|
598
|
+
currentPerson = {};
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (input.key === "max_verification_steps") {
|
|
603
|
+
const num = Number.parseInt(input.value, 10);
|
|
604
|
+
if (Number.isNaN(num) || num < 0) {
|
|
605
|
+
throw new Error(
|
|
606
|
+
"max_verification_steps must be a non-negative integer",
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
currentPerson.max_verification_steps = num;
|
|
610
|
+
} else if (input.key === "max_changed_lines") {
|
|
611
|
+
const num = Number.parseInt(input.value, 10);
|
|
612
|
+
if (Number.isNaN(num) || num < 0) {
|
|
613
|
+
throw new Error("max_changed_lines must be a non-negative integer");
|
|
614
|
+
}
|
|
615
|
+
currentPerson.max_changed_lines = num;
|
|
616
|
+
} else if (input.key === "max_changed_files") {
|
|
617
|
+
const num = Number.parseInt(input.value, 10);
|
|
618
|
+
if (Number.isNaN(num) || num < 0) {
|
|
619
|
+
throw new Error("max_changed_files must be a non-negative integer");
|
|
620
|
+
}
|
|
621
|
+
currentPerson.max_changed_files = num;
|
|
622
|
+
} else if (input.key === "summary.enabled") {
|
|
623
|
+
const b = input.value.toLowerCase() === "true";
|
|
624
|
+
currentPerson.summary = {
|
|
625
|
+
...(typeof currentPerson.summary === "object" &&
|
|
626
|
+
currentPerson.summary !== null
|
|
627
|
+
? (currentPerson.summary as Record<string, unknown>)
|
|
628
|
+
: {}),
|
|
629
|
+
enabled: b,
|
|
630
|
+
};
|
|
631
|
+
} else if (input.key === "summary.model") {
|
|
632
|
+
if (typeof input.value !== "string" || input.value.trim().length === 0) {
|
|
633
|
+
throw new Error("summary.model must be a non-empty string");
|
|
634
|
+
}
|
|
635
|
+
currentPerson.summary = {
|
|
636
|
+
...(typeof currentPerson.summary === "object" &&
|
|
637
|
+
currentPerson.summary !== null
|
|
638
|
+
? (currentPerson.summary as Record<string, unknown>)
|
|
639
|
+
: {}),
|
|
640
|
+
model: input.value.trim(),
|
|
641
|
+
};
|
|
642
|
+
} else if (input.key === "agents_dir") {
|
|
643
|
+
currentPerson.agents_dir = input.value.trim();
|
|
644
|
+
} else if (input.key === "scout") {
|
|
645
|
+
const b = input.value.toLowerCase() === "true";
|
|
646
|
+
currentPerson.scout = b;
|
|
647
|
+
} else if (input.key === "post") {
|
|
648
|
+
const b = input.value.toLowerCase() === "true";
|
|
649
|
+
currentPerson.post = b;
|
|
650
|
+
} else {
|
|
651
|
+
throw new Error(
|
|
652
|
+
`unknown or unsupported key for person configuration: ${input.key}`,
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
writeFileSync(
|
|
657
|
+
personConfigPath,
|
|
658
|
+
`${JSON.stringify(currentPerson, null, 2)}\n`,
|
|
659
|
+
);
|
|
660
|
+
return { status: "ok" };
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
if (input.layer === "watch") {
|
|
664
|
+
const watchConfigPath = path.join(resolveHomeDir(home), "watch.json");
|
|
665
|
+
let currentWatch: Record<string, unknown> = {};
|
|
666
|
+
if (existsSync(watchConfigPath)) {
|
|
667
|
+
try {
|
|
668
|
+
currentWatch = JSON.parse(readFileSync(watchConfigPath, "utf-8"));
|
|
669
|
+
} catch {
|
|
670
|
+
currentWatch = {};
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if (input.key === "daily_cap") {
|
|
675
|
+
const num = Number.parseInt(input.value, 10);
|
|
676
|
+
if (Number.isNaN(num) || num <= 0) {
|
|
677
|
+
throw new Error("daily_cap must be a positive integer");
|
|
678
|
+
}
|
|
679
|
+
currentWatch.daily_cap = num;
|
|
680
|
+
} else if (input.key === "window") {
|
|
681
|
+
const parts = input.value.split("-");
|
|
682
|
+
if (
|
|
683
|
+
parts.length !== 2 ||
|
|
684
|
+
!parts[0] ||
|
|
685
|
+
!parts[1] ||
|
|
686
|
+
!TIME_WINDOW_RE.test(parts[0]) ||
|
|
687
|
+
!TIME_WINDOW_RE.test(parts[1]) ||
|
|
688
|
+
parts[0] === parts[1]
|
|
689
|
+
) {
|
|
690
|
+
throw new Error(
|
|
691
|
+
"window must be in format 'HH:MM-HH:MM' with valid 24h times where start != end",
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
currentWatch.window = { start: parts[0], end: parts[1] };
|
|
695
|
+
} else {
|
|
696
|
+
throw new Error(
|
|
697
|
+
`unknown or unsupported key for watch configuration: ${input.key}`,
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
writeFileSync(
|
|
702
|
+
watchConfigPath,
|
|
703
|
+
`${JSON.stringify(currentWatch, null, 2)}\n`,
|
|
704
|
+
);
|
|
705
|
+
return { status: "ok" };
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
return { status: "ok" };
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
export async function unsetConfigValue(input: {
|
|
712
|
+
layer: "person" | "team" | "watch";
|
|
713
|
+
key: string;
|
|
714
|
+
home?: string;
|
|
715
|
+
repoRoot?: string;
|
|
716
|
+
}): Promise<{ status: "ok" }> {
|
|
717
|
+
const home = input.home ?? os.homedir();
|
|
718
|
+
|
|
719
|
+
const removeKey = (obj: Record<string, unknown>, key: string) => {
|
|
720
|
+
if (key.startsWith("summary.")) {
|
|
721
|
+
const sub = key.slice("summary.".length);
|
|
722
|
+
if (obj.summary && typeof obj.summary === "object") {
|
|
723
|
+
delete (obj.summary as Record<string, unknown>)[sub];
|
|
724
|
+
}
|
|
725
|
+
} else {
|
|
726
|
+
delete obj[key];
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
if (input.layer === "team") {
|
|
731
|
+
if (!input.repoRoot) {
|
|
732
|
+
throw new Error(
|
|
733
|
+
"cannot edit team configuration outside a git repository",
|
|
734
|
+
);
|
|
735
|
+
}
|
|
736
|
+
const repoConfigPath = path.join(
|
|
737
|
+
resolveRepoDir(input.repoRoot),
|
|
738
|
+
"config.json",
|
|
739
|
+
);
|
|
740
|
+
if (existsSync(repoConfigPath)) {
|
|
741
|
+
const current = JSON.parse(readFileSync(repoConfigPath, "utf-8"));
|
|
742
|
+
removeKey(current, input.key);
|
|
743
|
+
writeFileSync(repoConfigPath, `${JSON.stringify(current, null, 2)}\n`);
|
|
744
|
+
}
|
|
745
|
+
return { status: "ok" };
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
if (input.layer === "person") {
|
|
749
|
+
const personConfigPath = path.join(resolveHomeDir(home), "config.json");
|
|
750
|
+
if (existsSync(personConfigPath)) {
|
|
751
|
+
const current = JSON.parse(readFileSync(personConfigPath, "utf-8"));
|
|
752
|
+
removeKey(current, input.key);
|
|
753
|
+
writeFileSync(personConfigPath, `${JSON.stringify(current, null, 2)}\n`);
|
|
754
|
+
}
|
|
755
|
+
return { status: "ok" };
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
if (input.layer === "watch") {
|
|
759
|
+
const watchConfigPath = path.join(resolveHomeDir(home), "watch.json");
|
|
760
|
+
if (existsSync(watchConfigPath)) {
|
|
761
|
+
const current = JSON.parse(readFileSync(watchConfigPath, "utf-8"));
|
|
762
|
+
removeKey(current, input.key);
|
|
763
|
+
writeFileSync(watchConfigPath, `${JSON.stringify(current, null, 2)}\n`);
|
|
764
|
+
}
|
|
765
|
+
return { status: "ok" };
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
return { status: "ok" };
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
export async function runConfigEditor(
|
|
772
|
+
deps: {
|
|
773
|
+
home?: string;
|
|
774
|
+
repoRoot?: string;
|
|
775
|
+
width?: number;
|
|
776
|
+
styles?: boolean;
|
|
777
|
+
createReader?: () => KeyReader;
|
|
778
|
+
io?: { write: (t: string) => void; line: (t?: string) => void };
|
|
779
|
+
} = {},
|
|
780
|
+
): Promise<number> {
|
|
781
|
+
const styles = deps.styles ?? false;
|
|
782
|
+
const io = deps.io ?? {
|
|
783
|
+
write: (t) => process.stderr.write(t),
|
|
784
|
+
line: (t = "") => process.stderr.write(`${t}\n`),
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
io.line();
|
|
788
|
+
io.line(bold("Interactive Configuration Editor", styles));
|
|
789
|
+
io.line(
|
|
790
|
+
dim(
|
|
791
|
+
"Person layer: ~/.crysk/config.json (~/.prhero/config.json on a pre-rename install)",
|
|
792
|
+
styles,
|
|
793
|
+
),
|
|
794
|
+
);
|
|
795
|
+
if (deps.repoRoot) {
|
|
796
|
+
io.line(
|
|
797
|
+
dim(
|
|
798
|
+
`Team layer: ${path.join(resolveRepoDir(deps.repoRoot), "config.json")}`,
|
|
799
|
+
styles,
|
|
800
|
+
),
|
|
801
|
+
);
|
|
802
|
+
} else {
|
|
803
|
+
io.line(dim("Team layer: (disabled outside git repository)", styles));
|
|
804
|
+
}
|
|
805
|
+
io.line(
|
|
806
|
+
dim(
|
|
807
|
+
"Watcher layer: ~/.crysk/watch.json (~/.prhero/watch.json on a pre-rename install)",
|
|
808
|
+
styles,
|
|
809
|
+
),
|
|
810
|
+
);
|
|
811
|
+
io.line();
|
|
812
|
+
io.line(
|
|
813
|
+
"Use 'crysk config set <key> <value> [--person|--team|--watch]' to modify configuration.",
|
|
814
|
+
);
|
|
815
|
+
return 0;
|
|
816
|
+
}
|