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
package/src/ui/config.ts
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
// `pr-hero config`'s output, as LINES. Fourth member of the terminal
|
|
2
|
+
// surface's pure half (ui/primitives.ts formats, ui/select.ts asks, ui/result.ts
|
|
3
|
+
// reports, this one explains): same contract as all three — everything is a
|
|
4
|
+
// total function of its inputs, the style flag and the width arrive as
|
|
5
|
+
// PARAMETERS, and the I/O shell in cli.ts owns the printing and the exit code.
|
|
6
|
+
//
|
|
7
|
+
// WHY the command exists at all (C5 D10): two layers that cannot be inspected
|
|
8
|
+
// are worse DX than one layer that can. The first question a teammate asks is
|
|
9
|
+
// "why is this value what it is", and before this the answer was "read two
|
|
10
|
+
// files and know the rules". The data was already there — D7 makes
|
|
11
|
+
// pipeline.json carry the same per-key source record — so this is a renderer,
|
|
12
|
+
// not a mechanism.
|
|
13
|
+
//
|
|
14
|
+
// WHY it lists DEFAULTS too, unlike the plan card: the card tags only the
|
|
15
|
+
// surprising values (global, capped) because it sits between the operator and
|
|
16
|
+
// a spend decision and is already dense; cli.ts's configTag says so and names
|
|
17
|
+
// this file as where the exhaustive list belongs (judgment ledger JD-21).
|
|
18
|
+
// Here the exhaustive list IS the product — a key missing from the listing
|
|
19
|
+
// would read as "pr-hero has no such setting".
|
|
20
|
+
|
|
21
|
+
import type {
|
|
22
|
+
ConfigSource,
|
|
23
|
+
ConfigSources,
|
|
24
|
+
LocalConfig,
|
|
25
|
+
SummaryConfig,
|
|
26
|
+
} from "#review/preflight";
|
|
27
|
+
import type { SuspicionPrior } from "#review/prompt-set";
|
|
28
|
+
import {
|
|
29
|
+
bold,
|
|
30
|
+
cyan,
|
|
31
|
+
dim,
|
|
32
|
+
labelColumnWidth,
|
|
33
|
+
row,
|
|
34
|
+
terminalWidth,
|
|
35
|
+
wrapText,
|
|
36
|
+
yellow,
|
|
37
|
+
} from "./primitives";
|
|
38
|
+
|
|
39
|
+
export interface ConfigViewInput {
|
|
40
|
+
// The MERGED config and its provenance, exactly as a review resolved them —
|
|
41
|
+
// loadEffectiveConfig's own output, never a re-derivation. §3.10's "what it
|
|
42
|
+
// prints cannot drift from what actually runs" is only true while this stays
|
|
43
|
+
// the same fold the engine path takes.
|
|
44
|
+
effective: LocalConfig;
|
|
45
|
+
sources: ConfigSources;
|
|
46
|
+
// Both paths, named whether or not the file is there: "where do I even
|
|
47
|
+
// write this" is the other half of the question a teammate is asking, and a
|
|
48
|
+
// path that only appears once the file exists answers it for exactly the
|
|
49
|
+
// people who did not need the answer. Printed verbatim rather than
|
|
50
|
+
// home-collapsed, because a path you can copy beats a path that is short —
|
|
51
|
+
// and shortPath()'s homedir() default would be a sniff inside a renderer.
|
|
52
|
+
repoConfigPath: string;
|
|
53
|
+
repoPresent: boolean;
|
|
54
|
+
globalConfigPath: string;
|
|
55
|
+
globalPresent: boolean;
|
|
56
|
+
styles: boolean;
|
|
57
|
+
// Optional for the reason PlanContext.width is: the shell may leave the one
|
|
58
|
+
// sniff to this entry point, and the tests ALWAYS pin it.
|
|
59
|
+
width?: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface ConfigCell {
|
|
63
|
+
value: string;
|
|
64
|
+
source: ConfigSource;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface ConfigRow extends ConfigCell {
|
|
68
|
+
key: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The keys that get one row each. `summary` is excluded and expanded into its
|
|
72
|
+
// two fields below, exactly as ConfigSources splits it — its fields have
|
|
73
|
+
// different directions and one row could not name two layers.
|
|
74
|
+
type ConfigRowKey = Exclude<keyof LocalConfig, "summary">;
|
|
75
|
+
|
|
76
|
+
// Nothing named the key, so there is no value to print. NOT a rendered
|
|
77
|
+
// default: the built-in fallbacks are not uniform and two of them are not even
|
|
78
|
+
// values — `default_base` falls through to remote-head autodetection at run
|
|
79
|
+
// time, and `agents_dir` has no default at all (resolveAgentsDirSetting hard-
|
|
80
|
+
// errors). Printing an invented one would be this command's own version of
|
|
81
|
+
// "a wrong answer with a plausible face".
|
|
82
|
+
const UNSET = "(unset)";
|
|
83
|
+
// A layer DID name the key and named it empty. Distinct from UNSET on
|
|
84
|
+
// purpose: `"parity_trigger_paths": []` is a repo deliberately disarming the
|
|
85
|
+
// parity hunter, and it is the fact §3.2's parser change exists to keep
|
|
86
|
+
// distinguishable from silence.
|
|
87
|
+
const EMPTY = "(empty)";
|
|
88
|
+
|
|
89
|
+
function cell(value: string | undefined, source: ConfigSource): ConfigCell {
|
|
90
|
+
return { value: value ?? UNSET, source };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function listCell(values: readonly string[], source: ConfigSource): ConfigCell {
|
|
94
|
+
if (source === "default") return { value: UNSET, source };
|
|
95
|
+
return { value: values.length === 0 ? EMPTY : values.join(", "), source };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Path plus weight, never the reason: the reason is prose written for a
|
|
99
|
+
// hunter's prompt and would swamp the row. The path is what identifies the
|
|
100
|
+
// prior, and the file it came from is one row above.
|
|
101
|
+
function priorsCell(
|
|
102
|
+
priors: readonly SuspicionPrior[],
|
|
103
|
+
source: ConfigSource,
|
|
104
|
+
): ConfigCell {
|
|
105
|
+
return listCell(
|
|
106
|
+
priors.map((prior) => `${prior.path} (${prior.weight})`),
|
|
107
|
+
source,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function routingCell(
|
|
112
|
+
routing: LocalConfig["routing"],
|
|
113
|
+
source: ConfigSource,
|
|
114
|
+
): ConfigCell {
|
|
115
|
+
if (source === "default" || routing === undefined) {
|
|
116
|
+
return { value: UNSET, source };
|
|
117
|
+
}
|
|
118
|
+
const mappingsCount = routing.mappings
|
|
119
|
+
? Array.isArray(routing.mappings)
|
|
120
|
+
? routing.mappings.length
|
|
121
|
+
: Object.keys(routing.mappings).length
|
|
122
|
+
: 0;
|
|
123
|
+
if (mappingsCount === 0 && routing.default) {
|
|
124
|
+
return {
|
|
125
|
+
value: "default route",
|
|
126
|
+
source,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (mappingsCount > 0 && routing.default) {
|
|
130
|
+
return {
|
|
131
|
+
value: `${mappingsCount} mapping${mappingsCount === 1 ? "" : "s"} (+ default)`,
|
|
132
|
+
source,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
value: `${mappingsCount} mapping${mappingsCount === 1 ? "" : "s"}`,
|
|
137
|
+
source,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// One row per key, and the two Records below are what stops a key from
|
|
142
|
+
// silently going missing: both are exhaustive over their key union, so adding
|
|
143
|
+
// a member to LocalConfig or SummaryConfig fails tsc until it has a cell here.
|
|
144
|
+
// The plan card's configTags makes the same promise in a comment ("a direction
|
|
145
|
+
// change must not silently drop a key off the card") with a hand-written
|
|
146
|
+
// array behind it; a Record is the version a compiler holds. (Judgment ledger
|
|
147
|
+
// JD-12 is about the parser's key set, which this does not close — it closes
|
|
148
|
+
// the same class for this surface.)
|
|
149
|
+
export function configRows(
|
|
150
|
+
effective: LocalConfig,
|
|
151
|
+
sources: ConfigSources,
|
|
152
|
+
): ConfigRow[] {
|
|
153
|
+
const cells: Record<ConfigRowKey, ConfigCell> = {
|
|
154
|
+
agents_dir: cell(effective.agents_dir, sources.agents_dir),
|
|
155
|
+
default_base: cell(effective.default_base, sources.default_base),
|
|
156
|
+
parity_trigger_paths: listCell(
|
|
157
|
+
effective.parity_trigger_paths,
|
|
158
|
+
sources.parity_trigger_paths,
|
|
159
|
+
),
|
|
160
|
+
suspicion_priors: priorsCell(
|
|
161
|
+
effective.suspicion_priors,
|
|
162
|
+
sources.suspicion_priors,
|
|
163
|
+
),
|
|
164
|
+
routing: routingCell(effective.routing, sources.routing),
|
|
165
|
+
max_verification_steps: cell(
|
|
166
|
+
effective.max_verification_steps?.toString(),
|
|
167
|
+
sources.max_verification_steps,
|
|
168
|
+
),
|
|
169
|
+
max_concurrent_steps: cell(
|
|
170
|
+
effective.max_concurrent_steps?.toString(),
|
|
171
|
+
sources.max_concurrent_steps,
|
|
172
|
+
),
|
|
173
|
+
max_changed_lines: cell(
|
|
174
|
+
effective.max_changed_lines?.toString(),
|
|
175
|
+
sources.max_changed_lines,
|
|
176
|
+
),
|
|
177
|
+
max_changed_files: cell(
|
|
178
|
+
effective.max_changed_files?.toString(),
|
|
179
|
+
sources.max_changed_files,
|
|
180
|
+
),
|
|
181
|
+
scout: cell(effective.scout?.toString(), sources.scout),
|
|
182
|
+
post: cell(effective.post?.toString(), sources.post),
|
|
183
|
+
ci_review_policy: cell(
|
|
184
|
+
effective.ci_review_policy,
|
|
185
|
+
sources.ci_review_policy,
|
|
186
|
+
),
|
|
187
|
+
ci_max_attempts: cell(
|
|
188
|
+
effective.ci_max_attempts?.toString(),
|
|
189
|
+
sources.ci_max_attempts,
|
|
190
|
+
),
|
|
191
|
+
ci_max_reviews: cell(
|
|
192
|
+
effective.ci_max_reviews?.toString(),
|
|
193
|
+
sources.ci_max_reviews,
|
|
194
|
+
),
|
|
195
|
+
ci_rereview_min_score: cell(
|
|
196
|
+
effective.ci_rereview_min_score?.toString(),
|
|
197
|
+
sources.ci_rereview_min_score,
|
|
198
|
+
),
|
|
199
|
+
ci_blocking_weight: cell(
|
|
200
|
+
effective.ci_blocking_weight?.toString(),
|
|
201
|
+
sources.ci_blocking_weight,
|
|
202
|
+
),
|
|
203
|
+
ci_advisory_weight: cell(
|
|
204
|
+
effective.ci_advisory_weight?.toString(),
|
|
205
|
+
sources.ci_advisory_weight,
|
|
206
|
+
),
|
|
207
|
+
ci_trusted_actors: listCell(
|
|
208
|
+
effective.ci_trusted_actors ?? [],
|
|
209
|
+
sources.ci_trusted_actors,
|
|
210
|
+
),
|
|
211
|
+
ci_admission_observe_only: cell(
|
|
212
|
+
effective.ci_admission_observe_only?.toString(),
|
|
213
|
+
sources.ci_admission_observe_only,
|
|
214
|
+
),
|
|
215
|
+
};
|
|
216
|
+
const summaryCells: Record<keyof SummaryConfig, ConfigCell> = {
|
|
217
|
+
enabled: cell(
|
|
218
|
+
effective.summary?.enabled?.toString(),
|
|
219
|
+
sources.summary.enabled,
|
|
220
|
+
),
|
|
221
|
+
model: cell(effective.summary?.model, sources.summary.model),
|
|
222
|
+
};
|
|
223
|
+
// Object.entries over an object literal keeps declaration order, which is
|
|
224
|
+
// the same guarantee CONFIG_DIRECTION already leans on for its derived key
|
|
225
|
+
// sets. The summary pair lands last rather than in `summary`'s declared
|
|
226
|
+
// slot: an ordering constant that a new key could fall outside of would
|
|
227
|
+
// reintroduce exactly the silent-drop this Record is here to prevent.
|
|
228
|
+
return [
|
|
229
|
+
...Object.entries(cells).map(([key, value]) => ({ key, ...value })),
|
|
230
|
+
...Object.entries(summaryCells).map(([key, value]) => ({
|
|
231
|
+
key: `summary.${key}`,
|
|
232
|
+
...value,
|
|
233
|
+
})),
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// The four layer names, padded to one column so the eye can scan them. Derived
|
|
238
|
+
// from the ConfigSource union's own members, so a fifth source cannot leave
|
|
239
|
+
// the column too narrow to hold it.
|
|
240
|
+
const SOURCE_NAMES: readonly ConfigSource[] = [
|
|
241
|
+
"global",
|
|
242
|
+
"repo",
|
|
243
|
+
"capped",
|
|
244
|
+
"default",
|
|
245
|
+
];
|
|
246
|
+
const SOURCE_WIDTH = labelColumnWidth(SOURCE_NAMES);
|
|
247
|
+
|
|
248
|
+
// The marker D10 asks for by name ("marks any value a cap narrowed"). The
|
|
249
|
+
// `capped` source already says it; this says what it MEANS, because `capped`
|
|
250
|
+
// is the one layer name that describes an event rather than a file — the team
|
|
251
|
+
// asked for something wider and the global ceiling took it away.
|
|
252
|
+
const CAPPED_MARKER = "← narrowed by the global ceiling";
|
|
253
|
+
|
|
254
|
+
type Painter = (text: string, styles: boolean) => string;
|
|
255
|
+
|
|
256
|
+
function sourcePainter(source: ConfigSource): Painter {
|
|
257
|
+
switch (source) {
|
|
258
|
+
case "capped":
|
|
259
|
+
return yellow;
|
|
260
|
+
case "global":
|
|
261
|
+
return cyan;
|
|
262
|
+
default:
|
|
263
|
+
// `repo` and `default` are the unsurprising layers, and colouring them
|
|
264
|
+
// would cost the two above the contrast they exist for.
|
|
265
|
+
return dim;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const INDENT = 2;
|
|
270
|
+
|
|
271
|
+
// A value column assembled from spans that are coloured INDEPENDENTLY, so
|
|
272
|
+
// that row() never receives a string containing an escape byte.
|
|
273
|
+
//
|
|
274
|
+
// WHY that invariant, spelled out because breaking it is silent: row() places
|
|
275
|
+
// the wrap with raw `value.length`, so escape bytes are counted as visible
|
|
276
|
+
// width and a painted row wraps EARLIER than the same row unpainted; then
|
|
277
|
+
// wrapText splits on whitespace, which can leave a colour's opening escape on
|
|
278
|
+
// one line and its reset on the next — and that colour bleeds into whatever
|
|
279
|
+
// the terminal prints after the block. This module shipped with exactly that
|
|
280
|
+
// bug: `paintSource(...) + value + yellow(marker)` handed straight to row().
|
|
281
|
+
//
|
|
282
|
+
// WHY not the established fix — cli.ts's markerRowLines builds the row
|
|
283
|
+
// unstyled and paints the whole LINE afterwards (`row(..., { styles: false })
|
|
284
|
+
// .map(line => paint(line))`) — a config row has TWO spans coloured
|
|
285
|
+
// differently, the layer tag and the cap marker, with an uncoloured value
|
|
286
|
+
// between them, and one whole-line painter cannot express that. So the same
|
|
287
|
+
// discipline is applied one level down: row() lays out the plain
|
|
288
|
+
// concatenation, and the colours go back onto the chunks it hands back.
|
|
289
|
+
//
|
|
290
|
+
// WHY not fold the layer tag into row()'s label column instead, which would
|
|
291
|
+
// dodge the wrap entirely: it moves the layout. A long `agents_dir` already
|
|
292
|
+
// wraps at 80 columns today (its value lands on the continuation line), and
|
|
293
|
+
// widening the label column would pull it back up onto the first line.
|
|
294
|
+
interface Span {
|
|
295
|
+
text: string;
|
|
296
|
+
paint?: Painter;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const WHITESPACE = /\s/;
|
|
300
|
+
|
|
301
|
+
interface SpanRowOptions {
|
|
302
|
+
width: number;
|
|
303
|
+
styles: boolean;
|
|
304
|
+
indent: number;
|
|
305
|
+
labelWidth: number;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function spanRow(
|
|
309
|
+
label: string,
|
|
310
|
+
spans: readonly Span[],
|
|
311
|
+
opts: SpanRowOptions,
|
|
312
|
+
): string[] {
|
|
313
|
+
const plain = spans.map((span) => span.text).join("");
|
|
314
|
+
// The span each non-whitespace character belongs to, in order. wrapText
|
|
315
|
+
// collapses whitespace, but it never reorders or drops a non-whitespace
|
|
316
|
+
// character — so this sequence is enough to walk any chunk row() returns
|
|
317
|
+
// back to the spans it came from, wrapped or verbatim.
|
|
318
|
+
const anchors: number[] = [];
|
|
319
|
+
spans.forEach((span, index) => {
|
|
320
|
+
for (let i = 0; i < span.text.length; i += 1) {
|
|
321
|
+
if (!WHITESPACE.test(span.text[i])) anchors.push(index);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// row() is handed styles:false so its head is exactly `indent + labelWidth`
|
|
326
|
+
// characters wide and every chunk is recoverable by slicing there. The
|
|
327
|
+
// label is dimmed below instead, with the same dim() row() would have used.
|
|
328
|
+
const head = " ".repeat(opts.indent) + label.padEnd(opts.labelWidth);
|
|
329
|
+
const valueCol = opts.indent + opts.labelWidth;
|
|
330
|
+
const lines = row(label, plain, {
|
|
331
|
+
width: opts.width,
|
|
332
|
+
styles: false,
|
|
333
|
+
indent: opts.indent,
|
|
334
|
+
labelWidth: opts.labelWidth,
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// The anchor cursor is shared across chunks — each one resumes where the
|
|
338
|
+
// previous stopped — so the chunks MUST be painted in order.
|
|
339
|
+
let cursor = 0;
|
|
340
|
+
const paintChunk = (chunk: string): string => {
|
|
341
|
+
if (chunk.length === 0) return "";
|
|
342
|
+
const ids: number[] = [];
|
|
343
|
+
// Whitespace inherits the span of the character BEFORE it, which is what
|
|
344
|
+
// keeps a padded tag's trailing spaces inside its own colour. Leading
|
|
345
|
+
// whitespace has no such character, so it takes the span the chunk is
|
|
346
|
+
// about to resolve.
|
|
347
|
+
let owner = anchors[cursor] ?? 0;
|
|
348
|
+
for (let i = 0; i < chunk.length; i += 1) {
|
|
349
|
+
if (!WHITESPACE.test(chunk[i])) {
|
|
350
|
+
owner = anchors[cursor] ?? owner;
|
|
351
|
+
cursor += 1;
|
|
352
|
+
}
|
|
353
|
+
ids.push(owner);
|
|
354
|
+
}
|
|
355
|
+
let painted = "";
|
|
356
|
+
let start = 0;
|
|
357
|
+
for (let i = 1; i <= chunk.length; i += 1) {
|
|
358
|
+
if (i < chunk.length && ids[i] === ids[start]) continue;
|
|
359
|
+
const span = spans[ids[start]];
|
|
360
|
+
const text = chunk.slice(start, i);
|
|
361
|
+
painted +=
|
|
362
|
+
span.paint === undefined ? text : span.paint(text, opts.styles);
|
|
363
|
+
start = i;
|
|
364
|
+
}
|
|
365
|
+
return painted;
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
return lines.map((line, index) => {
|
|
369
|
+
const first = index === 0;
|
|
370
|
+
const prefix = first
|
|
371
|
+
? " ".repeat(opts.indent) +
|
|
372
|
+
dim(label.padEnd(opts.labelWidth), opts.styles)
|
|
373
|
+
: " ".repeat(valueCol);
|
|
374
|
+
return prefix + paintChunk(line.slice(first ? head.length : valueCol));
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function noteLines(text: string, width: number, styles: boolean): string[] {
|
|
379
|
+
return wrapText(text, Math.max(width - INDENT, 20)).map(
|
|
380
|
+
(line) => " ".repeat(INDENT) + dim(line, styles),
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export function renderConfig(input: ConfigViewInput): string[] {
|
|
385
|
+
const width = input.width ?? terminalWidth();
|
|
386
|
+
const styles = input.styles;
|
|
387
|
+
const rows = configRows(input.effective, input.sources);
|
|
388
|
+
const keyWidth = labelColumnWidth(rows.map((r) => r.key));
|
|
389
|
+
const fileWidth = labelColumnWidth(["global"]);
|
|
390
|
+
const lines: string[] = [bold("crysk config", styles), ""];
|
|
391
|
+
|
|
392
|
+
for (const [label, filePath, present] of [
|
|
393
|
+
["repo", input.repoConfigPath, input.repoPresent],
|
|
394
|
+
["global", input.globalConfigPath, input.globalPresent],
|
|
395
|
+
] as const) {
|
|
396
|
+
lines.push(
|
|
397
|
+
...row(label, `${filePath} (${present ? "present" : "absent"})`, {
|
|
398
|
+
width,
|
|
399
|
+
styles,
|
|
400
|
+
indent: INDENT,
|
|
401
|
+
labelWidth: fileWidth,
|
|
402
|
+
}),
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
lines.push("");
|
|
406
|
+
|
|
407
|
+
for (const entry of rows) {
|
|
408
|
+
// The marker's two leading spaces are their own span so they stay OUTSIDE
|
|
409
|
+
// the yellow, exactly as `value + " " + yellow(marker)` used to put them.
|
|
410
|
+
const spans: Span[] = [
|
|
411
|
+
{
|
|
412
|
+
text: entry.source.padEnd(SOURCE_WIDTH),
|
|
413
|
+
paint: sourcePainter(entry.source),
|
|
414
|
+
},
|
|
415
|
+
{ text: entry.value },
|
|
416
|
+
...(entry.source === "capped"
|
|
417
|
+
? [{ text: " " }, { text: CAPPED_MARKER, paint: yellow }]
|
|
418
|
+
: []),
|
|
419
|
+
];
|
|
420
|
+
lines.push(
|
|
421
|
+
...spanRow(entry.key, spans, {
|
|
422
|
+
width,
|
|
423
|
+
styles,
|
|
424
|
+
indent: INDENT,
|
|
425
|
+
labelWidth: keyWidth,
|
|
426
|
+
}),
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
lines.push("");
|
|
430
|
+
|
|
431
|
+
// The vocabulary, always printed: this command's whole product is the layer
|
|
432
|
+
// column, and a column of words nobody can define is not an answer.
|
|
433
|
+
lines.push(
|
|
434
|
+
...noteLines(
|
|
435
|
+
"repo beats global, except on a capped key — there the NARROWER value " +
|
|
436
|
+
"wins, so a committed file can spend less of your money but never " +
|
|
437
|
+
"more. capped means the repo asked for the wider value and the " +
|
|
438
|
+
"global ceiling took it away; default means neither file named the " +
|
|
439
|
+
"key, and the resolver's own fallback decides at run time.",
|
|
440
|
+
width,
|
|
441
|
+
styles,
|
|
442
|
+
),
|
|
443
|
+
);
|
|
444
|
+
lines.push("");
|
|
445
|
+
// The honest limit of "what it prints cannot drift from what actually runs"
|
|
446
|
+
// (judgment ledger JD-10). ConfigSource has no `flag` member and cannot
|
|
447
|
+
// grow one here: flags never enter mergeConfig at all — they are applied
|
|
448
|
+
// AFTER it, by the resolvers — so no row above can ever read `flag`, and a
|
|
449
|
+
// row that named a layer for a flag-decided value would be naming the file
|
|
450
|
+
// that lost. Saying so is the only way the sentence above stays true.
|
|
451
|
+
lines.push(
|
|
452
|
+
...noteLines(
|
|
453
|
+
"Flags (--base, --model, --agents, --no-summary) and PRHERO_AGENTS_DIR " +
|
|
454
|
+
"are applied after this merge, by the resolvers, so no row above can " +
|
|
455
|
+
"say flag. A review passing one of them uses the flag's value, not " +
|
|
456
|
+
"the layer named here.",
|
|
457
|
+
width,
|
|
458
|
+
styles,
|
|
459
|
+
),
|
|
460
|
+
);
|
|
461
|
+
return lines;
|
|
462
|
+
}
|