crysk 0.0.0-stage → 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 +610 -2
- 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 +82 -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,300 @@
|
|
|
1
|
+
// The terminal surface's pure half: styling, key/value rows, cards and the
|
|
2
|
+
// path/sha shorteners every human-readable printer in this CLI shares. Same
|
|
3
|
+
// split as progress.ts — everything here is a total function of its inputs
|
|
4
|
+
// (the style flag and the width arrive as PARAMETERS, never sniffed inside),
|
|
5
|
+
// so the whole layout is testable offline without a TTY. The shells (cli.ts,
|
|
6
|
+
// watch/watch.ts) own the one impure decision, `styleEnabled()`, and hand the
|
|
7
|
+
// answer down.
|
|
8
|
+
//
|
|
9
|
+
// Deliberately independent of progress.ts: the two render different things at
|
|
10
|
+
// different times and neither should be able to break the other by editing a
|
|
11
|
+
// shared constant. The ANSI convention is copied on purpose, not imported.
|
|
12
|
+
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import type { Severity, Tier } from "#review/findings";
|
|
16
|
+
|
|
17
|
+
// The one shared writer. stderr, ALWAYS: stdout is reserved for the `ledger`
|
|
18
|
+
// command's markdown, so every human-readable line in this CLI — plans,
|
|
19
|
+
// progress, errors — goes to the other stream or the reserve is worthless.
|
|
20
|
+
// Lived in duplicate in cli.ts and watch/watch.ts before this module existed.
|
|
21
|
+
export function log(line = ""): void {
|
|
22
|
+
process.stderr.write(`${line}\n`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// NO_COLOR convention, matching progress.ts: style only when the stream we
|
|
26
|
+
// write to is a TTY *and* NO_COLOR is unset. ANY value counts, including the
|
|
27
|
+
// empty string — `NO_COLOR=` on the command line is still an operator saying
|
|
28
|
+
// no, and `=== undefined` is the only test that honours that.
|
|
29
|
+
export function styleEnabled(
|
|
30
|
+
stream: { isTTY?: boolean } = process.stderr,
|
|
31
|
+
env: Record<string, string | undefined> = process.env,
|
|
32
|
+
): boolean {
|
|
33
|
+
return Boolean(stream.isTTY) && env.NO_COLOR === undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Width from stdout first (that is the terminal the human sized), stderr as
|
|
37
|
+
// the fallback for a piped-stdout run, 80 when neither knows.
|
|
38
|
+
//
|
|
39
|
+
// The ONE sniff, and it belongs to the SHELLS (cli.ts, watch/watch.ts) and to a
|
|
40
|
+
// renderer's own entry point (renderResult). Nothing inside row()/box() calls
|
|
41
|
+
// it any more: an optional width with a sniffing fallback is exactly how
|
|
42
|
+
// renderPlan/renderPrPlan violated this module's contract undetected for two
|
|
43
|
+
// work units — every row they drew measured the terminal that happened to be
|
|
44
|
+
// running the tests, so `bun test` in a ~40-column pane failed on wrap points
|
|
45
|
+
// nobody could stub. Required width makes the contract a tsc fact.
|
|
46
|
+
export function terminalWidth(): number {
|
|
47
|
+
return process.stdout.columns ?? process.stderr.columns ?? 80;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const RESET = "\x1b[0m";
|
|
51
|
+
|
|
52
|
+
function paint(text: string, code: string, styles: boolean): string {
|
|
53
|
+
return styles ? `\x1b[${code}m${text}${RESET}` : text;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function bold(text: string, styles: boolean): string {
|
|
57
|
+
return paint(text, "1", styles);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function dim(text: string, styles: boolean): string {
|
|
61
|
+
return paint(text, "2", styles);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function red(text: string, styles: boolean): string {
|
|
65
|
+
return paint(text, "31", styles);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function green(text: string, styles: boolean): string {
|
|
69
|
+
return paint(text, "32", styles);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function yellow(text: string, styles: boolean): string {
|
|
73
|
+
return paint(text, "33", styles);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function cyan(text: string, styles: boolean): string {
|
|
77
|
+
return paint(text, "36", styles);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// A group heading. Bold, unindented, and never coloured: the rows under it
|
|
81
|
+
// carry the colour, and a heading that competes with them costs the eye the
|
|
82
|
+
// scan it exists to enable.
|
|
83
|
+
export function section(title: string, styles: boolean): string {
|
|
84
|
+
return bold(title, styles);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function truncate(text: string, max: number): string {
|
|
88
|
+
if (max <= 0) return "";
|
|
89
|
+
if (text.length <= max) return text;
|
|
90
|
+
if (max === 1) return "…";
|
|
91
|
+
return `${text.slice(0, max - 1)}…`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Word wrap. A single word longer than the width is never split — it goes on
|
|
95
|
+
// its own overlong line, because a hard-split sha or path is unusable and a
|
|
96
|
+
// wrapped one is merely ugly.
|
|
97
|
+
export function wrapText(text: string, width: number): string[] {
|
|
98
|
+
const words = text.split(/\s+/).filter((w) => w.length > 0);
|
|
99
|
+
if (words.length === 0) return [""];
|
|
100
|
+
const lines: string[] = [];
|
|
101
|
+
let current = "";
|
|
102
|
+
for (const word of words) {
|
|
103
|
+
if (current.length === 0) {
|
|
104
|
+
current = word;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (current.length + 1 + word.length <= width) {
|
|
108
|
+
current += ` ${word}`;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
lines.push(current);
|
|
112
|
+
current = word;
|
|
113
|
+
}
|
|
114
|
+
lines.push(current);
|
|
115
|
+
return lines;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// `width` is REQUIRED, unlike everything else here: it is the one option whose
|
|
119
|
+
// absence used to be filled by sniffing the real terminal (see
|
|
120
|
+
// terminalWidth()'s note), and a required field is the only version of this
|
|
121
|
+
// contract a compiler can hold.
|
|
122
|
+
interface RowOptions {
|
|
123
|
+
width: number;
|
|
124
|
+
styles?: boolean;
|
|
125
|
+
indent?: number;
|
|
126
|
+
labelWidth?: number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// The indent of the value column: two spaces of margin plus the label field.
|
|
130
|
+
const DEFAULT_INDENT = 2;
|
|
131
|
+
const DEFAULT_LABEL_WIDTH = 11;
|
|
132
|
+
// The gap a label is entitled to keep between itself and its value. One space
|
|
133
|
+
// is the minimum that still reads as two columns.
|
|
134
|
+
const LABEL_GAP = 1;
|
|
135
|
+
// Below this the value column would leave nothing to wrap into, so a very
|
|
136
|
+
// narrow terminal gets an overlong line instead of a one-word-per-line
|
|
137
|
+
// column.
|
|
138
|
+
const MIN_VALUE_WIDTH = 20;
|
|
139
|
+
|
|
140
|
+
// One key/value row as its lines. The point of this function — the whole
|
|
141
|
+
// reason it exists rather than a `padEnd` template — is that a long value
|
|
142
|
+
// wraps to the VALUE COLUMN, not to column 0: base refs, cost bases and
|
|
143
|
+
// paths used to fall back to the left margin mid-word and destroy the grid
|
|
144
|
+
// that makes a plan scannable.
|
|
145
|
+
//
|
|
146
|
+
// A value that already fits is emitted VERBATIM, never re-joined: rows that
|
|
147
|
+
// align sub-columns with runs of spaces (the agent list) depend on those runs
|
|
148
|
+
// surviving, and the wrapper collapses whitespace by construction.
|
|
149
|
+
export function row(label: string, value: string, opts: RowOptions): string[] {
|
|
150
|
+
const indent = opts.indent ?? DEFAULT_INDENT;
|
|
151
|
+
const labelWidth = opts.labelWidth ?? DEFAULT_LABEL_WIDTH;
|
|
152
|
+
const width = opts.width;
|
|
153
|
+
const styles = opts.styles ?? false;
|
|
154
|
+
const valueCol = indent + labelWidth;
|
|
155
|
+
const available = Math.max(width - valueCol, MIN_VALUE_WIDTH);
|
|
156
|
+
const head = " ".repeat(indent) + dim(label.padEnd(labelWidth), styles);
|
|
157
|
+
const pad = " ".repeat(valueCol);
|
|
158
|
+
const chunks =
|
|
159
|
+
value.length <= available ? [value] : wrapText(value, available);
|
|
160
|
+
return chunks.map((chunk, i) => (i === 0 ? head + chunk : pad + chunk));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// The decision block deliberately breaks the grid above it: a one-character
|
|
164
|
+
// marker instead of a label column, so the two lines that decide "spend or
|
|
165
|
+
// not" do not read as two more rows of setup.
|
|
166
|
+
const MARKER_ROW = { indent: 2, labelWidth: 2 } as const;
|
|
167
|
+
|
|
168
|
+
// Built UNSTYLED and painted whole afterwards: row() measures the value to
|
|
169
|
+
// place the wrap, and an escape sequence inside that value would be counted
|
|
170
|
+
// as visible width.
|
|
171
|
+
export function markerRowLines(
|
|
172
|
+
marker: string,
|
|
173
|
+
value: string,
|
|
174
|
+
paint: (text: string, styles: boolean) => string,
|
|
175
|
+
styles: boolean,
|
|
176
|
+
width: number,
|
|
177
|
+
): string[] {
|
|
178
|
+
return row(marker, value, { ...MARKER_ROW, styles: false, width }).map(
|
|
179
|
+
(line) => paint(line, styles),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// A label column DERIVED from the labels it has to hold, for callers whose
|
|
184
|
+
// label set is not fixed at design time.
|
|
185
|
+
//
|
|
186
|
+
// WHY it exists: `row()`'s DEFAULT_LABEL_WIDTH is 11 and the details views
|
|
187
|
+
// carry an 11-character label ("permissions"). padEnd(11) pads an 11-character
|
|
188
|
+
// string by nothing at all, so the row printed
|
|
189
|
+
// `permissionssteps run with --permission-mode…` — the label and the value
|
|
190
|
+
// welded together — and every shorter label in the same view was fine, which is
|
|
191
|
+
// why it survived review. A caller that asks for the width its own labels need
|
|
192
|
+
// cannot regress that when a longer label is added later.
|
|
193
|
+
export function labelColumnWidth(labels: readonly string[]): number {
|
|
194
|
+
return Math.max(0, ...labels.map((label) => label.length)) + LABEL_GAP;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
interface BoxOptions {
|
|
198
|
+
// Required for the reason RowOptions.width is.
|
|
199
|
+
width: number;
|
|
200
|
+
styles?: boolean;
|
|
201
|
+
borderStyle?: "round" | "double";
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const MIN_BOX_WIDTH = 24;
|
|
205
|
+
const MAX_BOX_WIDTH = 96;
|
|
206
|
+
|
|
207
|
+
// A unicode card: `╭─ title ───╮` or `╔═ title ═══╗` over a body. Both the title
|
|
208
|
+
// and the body lines are truncated to fit rather than wrapped — a card whose border
|
|
209
|
+
// does not close reads as corruption.
|
|
210
|
+
export function box(title: string, body: string[], opts: BoxOptions): string[] {
|
|
211
|
+
const width = Math.max(Math.min(opts.width, MAX_BOX_WIDTH), MIN_BOX_WIDTH);
|
|
212
|
+
const styles = opts.styles ?? false;
|
|
213
|
+
const isDouble = opts.borderStyle === "double";
|
|
214
|
+
const tl = isDouble ? "╔" : "╭";
|
|
215
|
+
const tr = isDouble ? "╗" : "╮";
|
|
216
|
+
const bl = isDouble ? "╚" : "╰";
|
|
217
|
+
const br = isDouble ? "╝" : "╯";
|
|
218
|
+
const h = isDouble ? "═" : "─";
|
|
219
|
+
const v = isDouble ? "║" : "│";
|
|
220
|
+
|
|
221
|
+
const inner = width - 4;
|
|
222
|
+
const shownTitle = truncate(title, width - 6);
|
|
223
|
+
const fill = Math.max(width - 5 - shownTitle.length, 1);
|
|
224
|
+
const lines = [
|
|
225
|
+
dim(`${tl}${h} `, styles) +
|
|
226
|
+
bold(shownTitle, styles) +
|
|
227
|
+
dim(` ${h.repeat(fill)}${tr}`, styles),
|
|
228
|
+
];
|
|
229
|
+
for (const line of body) {
|
|
230
|
+
lines.push(
|
|
231
|
+
`${dim(v, styles)} ${truncate(line, inner).padEnd(inner)} ` +
|
|
232
|
+
dim(v, styles),
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
lines.push(dim(`${bl}${h.repeat(width - 2)}${br}`, styles));
|
|
236
|
+
return lines;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const ANSI_ESCAPE_REGEX = new RegExp(
|
|
240
|
+
`${String.fromCharCode(27)}\\[[0-9;]*[a-zA-Z]`,
|
|
241
|
+
"g",
|
|
242
|
+
);
|
|
243
|
+
const CONTROL_CHAR_REGEX = new RegExp(
|
|
244
|
+
`[${String.fromCharCode(0)}-${String.fromCharCode(31)}${String.fromCharCode(127)}]`,
|
|
245
|
+
"g",
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
export function sanitizeText(text: string): string {
|
|
249
|
+
return text.replace(ANSI_ESCAPE_REGEX, "").replace(CONTROL_CHAR_REGEX, "");
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const SHORT_SHA_LENGTH = 10;
|
|
253
|
+
|
|
254
|
+
export function shortSha(sha: string, len: number = SHORT_SHA_LENGTH): string {
|
|
255
|
+
return sha.slice(0, len);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// A path a human can read at a glance. Relative to `root` when it lives
|
|
259
|
+
// under it, `~`-collapsed otherwise: three absolute paths sharing a 60-char
|
|
260
|
+
// prefix carry one bit of information each and cost a whole line apiece.
|
|
261
|
+
// The FULL path still goes to pipeline.json — this is a display projection.
|
|
262
|
+
export function shortPath(
|
|
263
|
+
p: string,
|
|
264
|
+
root?: string,
|
|
265
|
+
home: string = homedir(),
|
|
266
|
+
): string {
|
|
267
|
+
if (root !== undefined && root.length > 0) {
|
|
268
|
+
if (p === root) return path.basename(p) || p;
|
|
269
|
+
const prefix = root.endsWith(path.sep) ? root : root + path.sep;
|
|
270
|
+
if (p.startsWith(prefix)) return p.slice(prefix.length);
|
|
271
|
+
}
|
|
272
|
+
if (home.length > 0) {
|
|
273
|
+
if (p === home) return "~";
|
|
274
|
+
const prefix = home.endsWith(path.sep) ? home : home + path.sep;
|
|
275
|
+
if (p.startsWith(prefix)) return `~${path.sep}${p.slice(prefix.length)}`;
|
|
276
|
+
}
|
|
277
|
+
return p;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Severity carries the colour, tier carries the weight: an advisory finding
|
|
281
|
+
// is dimmed whatever its severity, because the tier is what decides whether
|
|
282
|
+
// a human must act and the severity only says how bad it would be.
|
|
283
|
+
export function severityLabel(
|
|
284
|
+
severity: Severity,
|
|
285
|
+
tier: Tier,
|
|
286
|
+
styles: boolean,
|
|
287
|
+
): string {
|
|
288
|
+
if (!styles) return severity;
|
|
289
|
+
if (tier === "advisory") return dim(severity, true);
|
|
290
|
+
switch (severity) {
|
|
291
|
+
case "BLOCKER":
|
|
292
|
+
return paint(severity, "1;31", true);
|
|
293
|
+
case "CRITICAL":
|
|
294
|
+
return red(severity, true);
|
|
295
|
+
case "WARNING":
|
|
296
|
+
return yellow(severity, true);
|
|
297
|
+
default:
|
|
298
|
+
return cyan(severity, true);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
// Live progress for the paid leg, born from a real incident: the CLI went
|
|
2
|
+
// silent for ~10 minutes between `codegraph init` and `run complete`, and a
|
|
3
|
+
// paid run died to a Ctrl-C from a user who reasonably believed it hung.
|
|
4
|
+
// On a TTY: a multi-line panel redrawn in place (state and frame text are
|
|
5
|
+
// pure in progress.ts). Non-TTY (piped, backgrounded): one plain stderr
|
|
6
|
+
// line per event. I/O by nature, untested by construction — formatElapsed
|
|
7
|
+
// and the progress.ts halves are the pure, tested pieces.
|
|
8
|
+
|
|
9
|
+
import type { FreeRouteBilling } from "#model/free-discovery";
|
|
10
|
+
import type { PipelineProgressEvent } from "#review/pipeline";
|
|
11
|
+
import type { CliOptions } from "#review/preflight";
|
|
12
|
+
import { formatElapsed } from "#review/report";
|
|
13
|
+
import { type SizeGateVerdict, sizeGateDisposition } from "#review/size-gate";
|
|
14
|
+
import { log, styleEnabled } from "#ui/primitives";
|
|
15
|
+
import {
|
|
16
|
+
type ConfirmResult,
|
|
17
|
+
type ConfirmSpec,
|
|
18
|
+
confirmReview,
|
|
19
|
+
confirmSizeGate,
|
|
20
|
+
freeBillingMode,
|
|
21
|
+
} from "#ui/select";
|
|
22
|
+
import { CliError } from "../errors";
|
|
23
|
+
import {
|
|
24
|
+
applyProgressEvent,
|
|
25
|
+
createPanelState,
|
|
26
|
+
renderPanelLines,
|
|
27
|
+
} from "../progress";
|
|
28
|
+
|
|
29
|
+
export type { ConfirmResult };
|
|
30
|
+
|
|
31
|
+
export interface ProgressRenderer {
|
|
32
|
+
onProgress: (event: PipelineProgressEvent) => void;
|
|
33
|
+
stop: () => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Height the panel assumes when the stream will not say (a TTY without rows),
|
|
37
|
+
// and the rows it leaves free below itself.
|
|
38
|
+
const PANEL_FALLBACK_ROWS = 24;
|
|
39
|
+
const PANEL_HEADROOM = 3;
|
|
40
|
+
|
|
41
|
+
export function startProgressRenderer(
|
|
42
|
+
startedAtMs: number,
|
|
43
|
+
subject: string,
|
|
44
|
+
hunterKeys: string[],
|
|
45
|
+
hasRefuter = true,
|
|
46
|
+
hasSummarizer = false,
|
|
47
|
+
): ProgressRenderer {
|
|
48
|
+
return process.stderr.isTTY
|
|
49
|
+
? startPanelRenderer(
|
|
50
|
+
startedAtMs,
|
|
51
|
+
subject,
|
|
52
|
+
hunterKeys,
|
|
53
|
+
hasRefuter,
|
|
54
|
+
hasSummarizer,
|
|
55
|
+
)
|
|
56
|
+
: startLineRenderer(startedAtMs);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The TTY panel: header + a TREE of agent rows (the refuter's per-finding
|
|
60
|
+
// leaves under it), redrawn in place with cursor-up (\x1b[<n>A) + per-line
|
|
61
|
+
// clear (\x1b[2K) on every event and on a 250ms tick that advances the
|
|
62
|
+
// spinner and the elapsed clocks. The cursor is deliberately NOT hidden:
|
|
63
|
+
// \x1b[?25l would need a restore on every exit path, and a leaked hidden
|
|
64
|
+
// cursor wrecks the user's terminal — a visible cursor over a redrawing
|
|
65
|
+
// panel is fine.
|
|
66
|
+
//
|
|
67
|
+
// Two things the tree made load-bearing that a fixed-height list did not:
|
|
68
|
+
// - the height budget, recomputed EVERY draw (a mid-run resize must tighten
|
|
69
|
+
// it on the next tick, not walk the cursor off the top of the screen);
|
|
70
|
+
// - \x1b[0J after the frame. The old panel could only grow, so leftover
|
|
71
|
+
// lines were impossible; a tree that collapses a finished branch shrinks,
|
|
72
|
+
// and without the erase-to-end the previous frame's tail stays on screen
|
|
73
|
+
// as orphaned rows.
|
|
74
|
+
// Exported for its test, which is the only consumer outside this module: the
|
|
75
|
+
// post-stop silence below is a CRITICAL invariant and an untested one regresses.
|
|
76
|
+
export function startPanelRenderer(
|
|
77
|
+
startedAtMs: number,
|
|
78
|
+
subject: string,
|
|
79
|
+
hunterKeys: string[],
|
|
80
|
+
hasRefuter = true,
|
|
81
|
+
hasSummarizer = false,
|
|
82
|
+
): ProgressRenderer {
|
|
83
|
+
// The NO_COLOR convention: any value disables color; a TTY alone is not
|
|
84
|
+
// consent.
|
|
85
|
+
const colors = process.env.NO_COLOR === undefined;
|
|
86
|
+
const state = createPanelState(subject, startedAtMs, hunterKeys, {
|
|
87
|
+
refuter: hasRefuter,
|
|
88
|
+
summarizer: hasSummarizer,
|
|
89
|
+
});
|
|
90
|
+
let frame = 0;
|
|
91
|
+
let drawnLines = 0;
|
|
92
|
+
// Headroom, not the whole window: the summary block prints below the final
|
|
93
|
+
// frame, and a panel that fills the terminal exactly would scroll it away
|
|
94
|
+
// the moment anything else is written. 24 is the classic default for a
|
|
95
|
+
// stream that will not say how tall it is.
|
|
96
|
+
const budget = (): number =>
|
|
97
|
+
Math.max((process.stderr.rows ?? PANEL_FALLBACK_ROWS) - PANEL_HEADROOM, 3);
|
|
98
|
+
const draw = (): void => {
|
|
99
|
+
const lines = renderPanelLines(
|
|
100
|
+
state,
|
|
101
|
+
performance.now(),
|
|
102
|
+
frame,
|
|
103
|
+
colors,
|
|
104
|
+
budget(),
|
|
105
|
+
);
|
|
106
|
+
if (drawnLines > 0) process.stderr.write(`\x1b[${drawnLines}A`);
|
|
107
|
+
for (const line of lines) {
|
|
108
|
+
process.stderr.write(`\x1b[2K${line}\n`);
|
|
109
|
+
}
|
|
110
|
+
// See the header: the frame can shrink, so anything below it must go.
|
|
111
|
+
process.stderr.write("\x1b[0J");
|
|
112
|
+
drawnLines = lines.length;
|
|
113
|
+
};
|
|
114
|
+
const ticker = setInterval(() => {
|
|
115
|
+
frame += 1;
|
|
116
|
+
draw();
|
|
117
|
+
}, 250);
|
|
118
|
+
draw();
|
|
119
|
+
// STOPPED IS LOAD-BEARING, and it is what makes \x1b[0J safe. The pipeline
|
|
120
|
+
// ceiling resolves the run while in-flight step promises are ABANDONED, not
|
|
121
|
+
// awaited (pipeline.ts: "abandoned, not awaited"), and their settle handlers
|
|
122
|
+
// emit unconditionally. So an event can arrive after stop() — after the
|
|
123
|
+
// result block has already printed below the final frame. Without this flag
|
|
124
|
+
// that late event redraws: the cursor walks back UP over the summary and
|
|
125
|
+
// \x1b[0J erases everything below it, deleting the findings of a paid run.
|
|
126
|
+
// Found live by pr-hero reviewing its own PR #7 (F002, CRITICAL,
|
|
127
|
+
// corroborated) — the erase-to-end-of-screen that fixed the shrinking-frame
|
|
128
|
+
// bug created this one.
|
|
129
|
+
let stopped = false;
|
|
130
|
+
return {
|
|
131
|
+
onProgress: (event: PipelineProgressEvent): void => {
|
|
132
|
+
if (stopped) return;
|
|
133
|
+
applyProgressEvent(state, event, performance.now());
|
|
134
|
+
draw();
|
|
135
|
+
},
|
|
136
|
+
stop: (): void => {
|
|
137
|
+
if (stopped) return;
|
|
138
|
+
clearInterval(ticker);
|
|
139
|
+
// One last draw so the completed states land; the frame then stays as
|
|
140
|
+
// the static record, and the summary prints below it.
|
|
141
|
+
draw();
|
|
142
|
+
// AFTER the final draw, so stop() itself is not a no-op.
|
|
143
|
+
stopped = true;
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// "done", or the honest failure with its reason when the pipeline had one
|
|
149
|
+
// (#314: a CI log that said only "failed" for every hunter hid an E2BIG). A
|
|
150
|
+
// failed hunter or summarizer is a partial run, never an abort.
|
|
151
|
+
function finishedText(event: { ok: boolean; reason?: string }): string {
|
|
152
|
+
if (event.ok) return "done";
|
|
153
|
+
return event.reason === undefined
|
|
154
|
+
? "failed (the run continues)"
|
|
155
|
+
: `failed — ${event.reason} (the run continues)`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Non-TTY: no redraw art, one plain line per event, elapsed prefix.
|
|
159
|
+
export function startLineRenderer(startedAtMs: number): ProgressRenderer {
|
|
160
|
+
const line = (text: string): void => {
|
|
161
|
+
log(` [${formatElapsed(performance.now() - startedAtMs)}] ${text}`);
|
|
162
|
+
};
|
|
163
|
+
return {
|
|
164
|
+
onProgress: (event: PipelineProgressEvent): void => {
|
|
165
|
+
switch (event.kind) {
|
|
166
|
+
case "hunters-started":
|
|
167
|
+
// The expectation line printed right before runPipeline already
|
|
168
|
+
// announced the fan-out; restating it here would be its echo.
|
|
169
|
+
return;
|
|
170
|
+
case "hunter-finished":
|
|
171
|
+
// A failed hunter is honest, not alarming: one dead hunter is a
|
|
172
|
+
// partial run, never an abort.
|
|
173
|
+
line(`hunter ${event.hunter}: ${finishedText(event)}`);
|
|
174
|
+
return;
|
|
175
|
+
case "dedupe-finished":
|
|
176
|
+
line(
|
|
177
|
+
`dedupe: ${event.drafts} draft${event.drafts === 1 ? "" : "s"} ` +
|
|
178
|
+
`-> ${event.findings} finding${event.findings === 1 ? "" : "s"}`,
|
|
179
|
+
);
|
|
180
|
+
return;
|
|
181
|
+
case "refuter-started":
|
|
182
|
+
line(
|
|
183
|
+
`refuter: ${event.severeFindings} severe finding` +
|
|
184
|
+
`${event.severeFindings === 1 ? "" : "s"} to judge`,
|
|
185
|
+
);
|
|
186
|
+
return;
|
|
187
|
+
case "refuter-step-finished":
|
|
188
|
+
line(`refuter ${event.findingId}: ${event.verdict}`);
|
|
189
|
+
return;
|
|
190
|
+
case "verify-started":
|
|
191
|
+
line(
|
|
192
|
+
`verify: ${event.queued} prior finding` +
|
|
193
|
+
`${event.queued === 1 ? "" : "s"} to check`,
|
|
194
|
+
);
|
|
195
|
+
return;
|
|
196
|
+
case "verify-step-finished":
|
|
197
|
+
line(`verify ${event.findingId}: ${event.verdict}`);
|
|
198
|
+
return;
|
|
199
|
+
case "summarizer-finished":
|
|
200
|
+
line(`summarizer: ${finishedText(event)}`);
|
|
201
|
+
return;
|
|
202
|
+
case "scout-started":
|
|
203
|
+
line(`scout: reading the diff (${event.model})`);
|
|
204
|
+
return;
|
|
205
|
+
case "scout-finished":
|
|
206
|
+
// "unled", never "the run continues": a scout failure is not a
|
|
207
|
+
// partial review, it is the control pipeline. Naming it as a
|
|
208
|
+
// degradation would teach an operator to distrust a complete run.
|
|
209
|
+
line(
|
|
210
|
+
event.ok
|
|
211
|
+
? `scout: ${event.leads ?? 0} lead(s)`
|
|
212
|
+
: "scout: failed (the hunters run unled)",
|
|
213
|
+
);
|
|
214
|
+
return;
|
|
215
|
+
case "step-retry":
|
|
216
|
+
// EVERY step, hunters and refuter alike — this is the launchd log,
|
|
217
|
+
// where a retry that explains a long wall time has to be readable
|
|
218
|
+
// after the fact and nothing competes for the line.
|
|
219
|
+
line(
|
|
220
|
+
`retry ${event.step}: ` +
|
|
221
|
+
(event.reason === "format"
|
|
222
|
+
? "format retry"
|
|
223
|
+
: `attempt ${event.attempt} of ${event.maxAttempts} ` +
|
|
224
|
+
"(transient)"),
|
|
225
|
+
);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
stop: (): void => {
|
|
230
|
+
// Nothing ticking to stop — kept so both renderers share one shape.
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// The cost band's gate. `details` is a thunk so the details view — which
|
|
236
|
+
// probes the filesystem — is built only if the human asks for it, and
|
|
237
|
+
// `canSkipPost` is what decides whether "Review, but don't post" exists at
|
|
238
|
+
// all: offering it to a run that was never going to post is a no-op dressed
|
|
239
|
+
// as a choice.
|
|
240
|
+
// The spec without its styles: a pure function of the run, so the billing
|
|
241
|
+
// wording it carries is testable offline. The free-route count is the same one
|
|
242
|
+
// the plan card was printed with (callers pass the same object to both).
|
|
243
|
+
export function confirmSpecFor(
|
|
244
|
+
low: number,
|
|
245
|
+
high: number,
|
|
246
|
+
canSkipPost: boolean,
|
|
247
|
+
details: () => string[],
|
|
248
|
+
freeRoute: FreeRouteBilling | undefined,
|
|
249
|
+
): Omit<ConfirmSpec, "styles"> {
|
|
250
|
+
const billing = freeBillingMode(freeRoute);
|
|
251
|
+
return {
|
|
252
|
+
low,
|
|
253
|
+
high,
|
|
254
|
+
canSkipPost,
|
|
255
|
+
details,
|
|
256
|
+
...(billing === undefined ? {} : { billing }),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function confirm(
|
|
261
|
+
low: number,
|
|
262
|
+
high: number,
|
|
263
|
+
canSkipPost: boolean,
|
|
264
|
+
details: () => string[],
|
|
265
|
+
freeRoute?: FreeRouteBilling,
|
|
266
|
+
): Promise<ConfirmResult> {
|
|
267
|
+
return confirmReview({
|
|
268
|
+
...confirmSpecFor(low, high, canSkipPost, details, freeRoute),
|
|
269
|
+
styles: styleEnabled(),
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// The size-gate override. `onBlock` runs for both the hard skip and the
|
|
274
|
+
// interactive prompt (PR mode prints the SKIP line here, because that path
|
|
275
|
+
// never reaches the plan). Local mode passes nothing: the plan already
|
|
276
|
+
// printed the verdict.
|
|
277
|
+
export async function applySizeGate(
|
|
278
|
+
verdict: SizeGateVerdict,
|
|
279
|
+
options: Pick<CliOptions, "force" | "yes">,
|
|
280
|
+
onBlock?: () => void,
|
|
281
|
+
): Promise<"proceed" | "abort"> {
|
|
282
|
+
const disposition = sizeGateDisposition(verdict, {
|
|
283
|
+
force: options.force,
|
|
284
|
+
yes: options.yes,
|
|
285
|
+
interactive: Boolean(process.stdin.isTTY),
|
|
286
|
+
});
|
|
287
|
+
if (disposition.action === "proceed") return "proceed";
|
|
288
|
+
onBlock?.();
|
|
289
|
+
if (disposition.action === "skip") {
|
|
290
|
+
throw new CliError(disposition.message);
|
|
291
|
+
}
|
|
292
|
+
const choice = await confirmSizeGate(styleEnabled());
|
|
293
|
+
if (choice.kind === "cancel") {
|
|
294
|
+
log("aborted; nothing was spent.");
|
|
295
|
+
return "abort";
|
|
296
|
+
}
|
|
297
|
+
return "proceed";
|
|
298
|
+
}
|