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/progress.ts
ADDED
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
// The live progress panel's pure half: panel state, its transitions under
|
|
2
|
+
// the pipeline's event stream, and frame-text assembly. Everything here is
|
|
3
|
+
// testable offline; cli.ts owns the I/O half — TTY detection, the tick, and
|
|
4
|
+
// the ANSI cursor positioning that redraws the frame in place.
|
|
5
|
+
//
|
|
6
|
+
// Deliberately NO percentage bar anywhere: step durations are unknowable up
|
|
7
|
+
// front, and a fake number invites exactly the Ctrl-C this slice exists to
|
|
8
|
+
// cure. The honest signals are a spinner, elapsed time, and per-step
|
|
9
|
+
// completions.
|
|
10
|
+
//
|
|
11
|
+
// The panel is a TREE (ui/tree.ts), not a list of lines, for one reason: the
|
|
12
|
+
// refuter runs ONE STEP PER FINDING and those verdicts used to be a counter
|
|
13
|
+
// that overwrote itself (`judging F001 (1 of 2)…`), so a run's most expensive
|
|
14
|
+
// leg reported a number instead of its results. As leaves they ACCUMULATE and
|
|
15
|
+
// can be watched landing. The second level is deliberately not models:
|
|
16
|
+
// spec.agents assigns exactly one model per agent, so a model level would
|
|
17
|
+
// give every node exactly one child — a list with extra glyphs.
|
|
18
|
+
|
|
19
|
+
import type { PipelineProgressEvent } from "#review/pipeline";
|
|
20
|
+
import { formatElapsed } from "#review/report";
|
|
21
|
+
import { renderTree, type TreeNode } from "#ui/tree";
|
|
22
|
+
|
|
23
|
+
export const SPINNER_FRAMES = [
|
|
24
|
+
"⠋",
|
|
25
|
+
"⠙",
|
|
26
|
+
"⠹",
|
|
27
|
+
"⠸",
|
|
28
|
+
"⠼",
|
|
29
|
+
"⠴",
|
|
30
|
+
"⠦",
|
|
31
|
+
"⠧",
|
|
32
|
+
"⠇",
|
|
33
|
+
"⠏",
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
type PanelHunterStatus = "waiting" | "running" | "done" | "failed";
|
|
37
|
+
type PanelSummarizerStatus = "running" | "done" | "failed";
|
|
38
|
+
|
|
39
|
+
interface PanelHunter {
|
|
40
|
+
key: string;
|
|
41
|
+
status: PanelHunterStatus;
|
|
42
|
+
durationMs?: number;
|
|
43
|
+
// Resolved model, when the pipeline named it (hunters-started carries the
|
|
44
|
+
// map). Absent is normal, not an error: only the pipeline knows what
|
|
45
|
+
// resolveModel decided, and the panel may render a frame before it says.
|
|
46
|
+
model?: string;
|
|
47
|
+
drafts?: number;
|
|
48
|
+
// The latest retry this hunter's step announced, as a leaf under its row.
|
|
49
|
+
// Latest only: a step retries at most twice (one transient, one format), and
|
|
50
|
+
// what an operator needs is "it is retrying now", not a history.
|
|
51
|
+
retry?: { attempt: number; maxAttempts: number; reason: string };
|
|
52
|
+
// Why the step failed, as the pipeline's event carried it (#314).
|
|
53
|
+
failureReason?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The scout is the one stage with a real STARTED event, because it is the one
|
|
57
|
+
// that runs alone: it is awaited before the hunters spawn, and M4 measured it
|
|
58
|
+
// at 86-600s. Without a row of its own the panel shows four hunters "waiting"
|
|
59
|
+
// for up to ten minutes and explains nothing — the silence that once cost a
|
|
60
|
+
// paid run to a reasonable Ctrl-C.
|
|
61
|
+
interface PanelScout {
|
|
62
|
+
status: "running" | "done" | "failed";
|
|
63
|
+
durationMs?: number;
|
|
64
|
+
model?: string;
|
|
65
|
+
leads?: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface PanelSummarizer {
|
|
69
|
+
// The summarizer starts with the pipeline, but it has no separate started
|
|
70
|
+
// event. Seeding it as running keeps the first frame truthful.
|
|
71
|
+
status: PanelSummarizerStatus;
|
|
72
|
+
durationMs?: number;
|
|
73
|
+
failureReason?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// One refuter leaf: a finding submitted to the gate. Every leaf is running
|
|
77
|
+
// from the moment the leg starts — the fan-out is parallel, so there is no
|
|
78
|
+
// queue to be pending in.
|
|
79
|
+
interface PanelRefuterLeaf {
|
|
80
|
+
id: string;
|
|
81
|
+
location?: string;
|
|
82
|
+
status: "running" | "done";
|
|
83
|
+
verdict?: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface PanelState {
|
|
87
|
+
// What the header says is under review: "PR #1682", or "dev..HEAD".
|
|
88
|
+
subject: string;
|
|
89
|
+
startedAtMs: number;
|
|
90
|
+
// Whether the spec wires a refuter at all ("at most one" is spec-legal, and
|
|
91
|
+
// a header promising one that never runs is a lie about the plan).
|
|
92
|
+
hasRefuter: boolean;
|
|
93
|
+
// Stamped by the hunters-started event so running rows show the fan-out's
|
|
94
|
+
// own elapsed, not the panel's.
|
|
95
|
+
huntersStartedAtMs?: number;
|
|
96
|
+
hunters: PanelHunter[];
|
|
97
|
+
// Absent until the scout-started event arrives — unlike the summarizer,
|
|
98
|
+
// which is seeded, because a run with no scout must show no scout row and
|
|
99
|
+
// the caller's flag is not the panel's business.
|
|
100
|
+
scout?: PanelScout;
|
|
101
|
+
// Cosmetic only: the pipeline owns summary semantics and run status.
|
|
102
|
+
// Absent means the summary step was disabled for this run.
|
|
103
|
+
summarizer?: PanelSummarizer;
|
|
104
|
+
dedupe?: { drafts: number; findings: number };
|
|
105
|
+
refuter?: {
|
|
106
|
+
total: number;
|
|
107
|
+
judged: number;
|
|
108
|
+
done: boolean;
|
|
109
|
+
findings: PanelRefuterLeaf[];
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Rows are seeded "waiting" from the keys the caller already resolved, so
|
|
114
|
+
// the panel has its full shape from the first frame; the hunters-started
|
|
115
|
+
// event is authoritative and reconciles the set (a key it names that the
|
|
116
|
+
// seed missed is added, never dropped).
|
|
117
|
+
export function createPanelState(
|
|
118
|
+
subject: string,
|
|
119
|
+
startedAtMs: number,
|
|
120
|
+
hunterKeys: string[],
|
|
121
|
+
opts: { refuter?: boolean; summarizer?: boolean } = {},
|
|
122
|
+
): PanelState {
|
|
123
|
+
return {
|
|
124
|
+
subject,
|
|
125
|
+
startedAtMs,
|
|
126
|
+
hasRefuter: opts.refuter ?? true,
|
|
127
|
+
hunters: hunterKeys.map((key) => ({ key, status: "waiting" as const })),
|
|
128
|
+
...(opts.summarizer === true
|
|
129
|
+
? { summarizer: { status: "running" as const } }
|
|
130
|
+
: {}),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function applyProgressEvent(
|
|
135
|
+
state: PanelState,
|
|
136
|
+
event: PipelineProgressEvent,
|
|
137
|
+
nowMs: number,
|
|
138
|
+
): void {
|
|
139
|
+
switch (event.kind) {
|
|
140
|
+
case "hunters-started": {
|
|
141
|
+
state.huntersStartedAtMs = nowMs;
|
|
142
|
+
for (const key of event.hunters) {
|
|
143
|
+
const row = state.hunters.find((h) => h.key === key);
|
|
144
|
+
const model = event.models?.[key];
|
|
145
|
+
if (row) {
|
|
146
|
+
row.status = "running";
|
|
147
|
+
if (model !== undefined) row.model = model;
|
|
148
|
+
} else {
|
|
149
|
+
state.hunters.push({
|
|
150
|
+
key,
|
|
151
|
+
status: "running",
|
|
152
|
+
...(model === undefined ? {} : { model }),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
case "hunter-finished": {
|
|
159
|
+
const row = state.hunters.find((h) => h.key === event.hunter);
|
|
160
|
+
if (!row) return;
|
|
161
|
+
row.status = event.ok ? "done" : "failed";
|
|
162
|
+
row.durationMs = event.durationMs;
|
|
163
|
+
if (event.drafts !== undefined) row.drafts = event.drafts;
|
|
164
|
+
if (!event.ok && event.reason !== undefined) {
|
|
165
|
+
row.failureReason = event.reason;
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
case "dedupe-finished":
|
|
170
|
+
state.dedupe = { drafts: event.drafts, findings: event.findings };
|
|
171
|
+
return;
|
|
172
|
+
case "refuter-started":
|
|
173
|
+
// The submitted ids, when the pipeline named them, become the leaves up
|
|
174
|
+
// front: the leg's whole shape is then visible from its first frame
|
|
175
|
+
// instead of growing out of nothing. Without them the leaves appear as
|
|
176
|
+
// they settle, which is the same information one step later.
|
|
177
|
+
state.refuter = {
|
|
178
|
+
total: event.severeFindings,
|
|
179
|
+
judged: 0,
|
|
180
|
+
done: false,
|
|
181
|
+
findings: (event.findings ?? []).map((f) => ({
|
|
182
|
+
id: f.id,
|
|
183
|
+
...(f.location === undefined ? {} : { location: f.location }),
|
|
184
|
+
status: "running" as const,
|
|
185
|
+
})),
|
|
186
|
+
};
|
|
187
|
+
return;
|
|
188
|
+
case "refuter-step-finished": {
|
|
189
|
+
if (!state.refuter) return;
|
|
190
|
+
state.refuter.judged += 1;
|
|
191
|
+
const leaf = state.refuter.findings.find((f) => f.id === event.findingId);
|
|
192
|
+
if (leaf) {
|
|
193
|
+
leaf.status = "done";
|
|
194
|
+
leaf.verdict = event.verdict;
|
|
195
|
+
} else {
|
|
196
|
+
state.refuter.findings.push({
|
|
197
|
+
id: event.findingId,
|
|
198
|
+
status: "done",
|
|
199
|
+
verdict: event.verdict,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (state.refuter.judged >= state.refuter.total) {
|
|
203
|
+
state.refuter.done = true;
|
|
204
|
+
}
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
case "verify-started":
|
|
208
|
+
case "verify-step-finished":
|
|
209
|
+
return;
|
|
210
|
+
case "scout-started": {
|
|
211
|
+
state.scout = { status: "running", model: event.model };
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
case "scout-finished": {
|
|
215
|
+
// Tolerant of a finish with no start: the construction-failure path
|
|
216
|
+
// emits only the finish, and a panel that threw there would take the
|
|
217
|
+
// run down with it.
|
|
218
|
+
state.scout ??= { status: "running" };
|
|
219
|
+
state.scout.status = event.ok ? "done" : "failed";
|
|
220
|
+
state.scout.durationMs = event.durationMs;
|
|
221
|
+
if (event.leads !== undefined) state.scout.leads = event.leads;
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
case "summarizer-finished": {
|
|
225
|
+
if (!state.summarizer) return;
|
|
226
|
+
state.summarizer.status = event.ok ? "done" : "failed";
|
|
227
|
+
state.summarizer.durationMs = event.durationMs;
|
|
228
|
+
if (!event.ok && event.reason !== undefined) {
|
|
229
|
+
state.summarizer.failureReason = event.reason;
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
case "step-retry": {
|
|
234
|
+
// Hunter steps only, by design: their rows are the ones an operator
|
|
235
|
+
// watches for minutes at a time. A refuter step's retry is reported on
|
|
236
|
+
// the non-TTY line renderer, where nothing competes for the space, and
|
|
237
|
+
// a leaf under a leaf would bury the verdict the row exists to show.
|
|
238
|
+
const key = event.step.startsWith("hunter-")
|
|
239
|
+
? event.step.slice("hunter-".length)
|
|
240
|
+
: undefined;
|
|
241
|
+
if (key === undefined) return;
|
|
242
|
+
const row = state.hunters.find((h) => h.key === key);
|
|
243
|
+
if (!row) return;
|
|
244
|
+
row.retry = {
|
|
245
|
+
attempt: event.attempt,
|
|
246
|
+
maxAttempts: event.maxAttempts,
|
|
247
|
+
reason: event.reason,
|
|
248
|
+
};
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// The failure-reason leaf under a failed row (#314). Capped well below the
|
|
255
|
+
// pipeline's own 160: this panel is not width-aware, and its redraw walks the
|
|
256
|
+
// cursor up by the number of LINES it returned — a leaf that wraps in the
|
|
257
|
+
// terminal occupies two rows the arithmetic never counted, and every redraw
|
|
258
|
+
// after that leaves an orphaned copy behind. The full reason is in the
|
|
259
|
+
// non-TTY log line and the step's artifacts.
|
|
260
|
+
const PANEL_REASON_MAX_CHARS = 64;
|
|
261
|
+
|
|
262
|
+
function failureReasonChildren(reason: string | undefined): TreeNode[] {
|
|
263
|
+
if (reason === undefined) return [];
|
|
264
|
+
return [
|
|
265
|
+
{
|
|
266
|
+
label:
|
|
267
|
+
reason.length <= PANEL_REASON_MAX_CHARS
|
|
268
|
+
? reason
|
|
269
|
+
: `${reason.slice(0, PANEL_REASON_MAX_CHARS - 1)}…`,
|
|
270
|
+
},
|
|
271
|
+
];
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function pad(text: string, width: number): string {
|
|
275
|
+
return text.length >= width ? text : text + " ".repeat(width - text.length);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// The retry leaf. "attempt N of M" only for a transient retry: the format
|
|
279
|
+
// retry is capped at exactly one on its OWN budget (see FORMAT_RETRY_REMINDER),
|
|
280
|
+
// so printing it against maxAttempts would fabricate a number the runner's WHY
|
|
281
|
+
// comments contradict.
|
|
282
|
+
function retryChildren(hunter: PanelHunter): TreeNode[] {
|
|
283
|
+
const retry = hunter.retry;
|
|
284
|
+
if (retry === undefined) return [];
|
|
285
|
+
return [
|
|
286
|
+
{
|
|
287
|
+
label:
|
|
288
|
+
retry.reason === "format"
|
|
289
|
+
? "↻ format retry"
|
|
290
|
+
: `↻ attempt ${retry.attempt} of ${retry.maxAttempts}`,
|
|
291
|
+
...(retry.reason === "format" ? {} : { detail: retry.reason }),
|
|
292
|
+
},
|
|
293
|
+
];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Sub-columns are aligned by padding here, in the caller, exactly as
|
|
297
|
+
// ui/tree.ts's `detail` contract asks: the tree owns nesting, not layout.
|
|
298
|
+
function hunterNode(
|
|
299
|
+
hunter: PanelHunter,
|
|
300
|
+
state: PanelState,
|
|
301
|
+
nowMs: number,
|
|
302
|
+
labelWidth: number,
|
|
303
|
+
modelWidth: number,
|
|
304
|
+
): TreeNode {
|
|
305
|
+
const label = pad(hunter.key, labelWidth);
|
|
306
|
+
// The retry leaf outlives the retry: a finished row that says "attempt 2"
|
|
307
|
+
// explains a duration that would otherwise look like a slow model.
|
|
308
|
+
const children = [
|
|
309
|
+
...retryChildren(hunter),
|
|
310
|
+
...(hunter.status === "failed"
|
|
311
|
+
? failureReasonChildren(hunter.failureReason)
|
|
312
|
+
: []),
|
|
313
|
+
];
|
|
314
|
+
const model = modelWidth === 0 ? "" : pad(hunter.model ?? "", modelWidth);
|
|
315
|
+
const parts: string[] = [];
|
|
316
|
+
if (model.length > 0) parts.push(model);
|
|
317
|
+
const node = (status: TreeNode["status"]): TreeNode => ({
|
|
318
|
+
label,
|
|
319
|
+
status,
|
|
320
|
+
detail: parts.join(" "),
|
|
321
|
+
...(children.length === 0 ? {} : { children }),
|
|
322
|
+
});
|
|
323
|
+
switch (hunter.status) {
|
|
324
|
+
case "waiting":
|
|
325
|
+
parts.push("waiting");
|
|
326
|
+
return node("pending");
|
|
327
|
+
case "running":
|
|
328
|
+
parts.push(
|
|
329
|
+
formatElapsed(nowMs - (state.huntersStartedAtMs ?? state.startedAtMs)),
|
|
330
|
+
);
|
|
331
|
+
return node("running");
|
|
332
|
+
case "done":
|
|
333
|
+
parts.push(formatElapsed(hunter.durationMs ?? 0));
|
|
334
|
+
if (hunter.drafts !== undefined) {
|
|
335
|
+
parts.push(`${hunter.drafts} draft${hunter.drafts === 1 ? "" : "s"}`);
|
|
336
|
+
}
|
|
337
|
+
return node("done");
|
|
338
|
+
case "failed":
|
|
339
|
+
// A dead hunter is a partial run, never an abort — the row says so
|
|
340
|
+
// rather than leaving the operator to guess from a red mark.
|
|
341
|
+
parts.push("failed — the run continues");
|
|
342
|
+
return node("failed");
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function refuterNode(
|
|
347
|
+
refuter: NonNullable<PanelState["refuter"]>,
|
|
348
|
+
labelWidth: number,
|
|
349
|
+
): TreeNode {
|
|
350
|
+
const idWidth = Math.max(
|
|
351
|
+
...refuter.findings.map((f) => f.id.length),
|
|
352
|
+
"F000".length,
|
|
353
|
+
);
|
|
354
|
+
const children: TreeNode[] = refuter.findings.map((leaf) => {
|
|
355
|
+
const detail = [
|
|
356
|
+
leaf.location === undefined ? "" : leaf.location,
|
|
357
|
+
leaf.verdict === undefined ? "" : leaf.verdict,
|
|
358
|
+
]
|
|
359
|
+
.filter((part) => part.length > 0)
|
|
360
|
+
.join(" ");
|
|
361
|
+
return {
|
|
362
|
+
label: pad(leaf.id, idWidth),
|
|
363
|
+
status: leaf.status === "done" ? ("done" as const) : ("running" as const),
|
|
364
|
+
...(detail.length === 0 ? {} : { detail }),
|
|
365
|
+
};
|
|
366
|
+
});
|
|
367
|
+
return {
|
|
368
|
+
label: pad("refuter", labelWidth),
|
|
369
|
+
status: refuter.done ? "done" : "running",
|
|
370
|
+
detail: refuter.done
|
|
371
|
+
? `${refuter.total} judged`
|
|
372
|
+
: `judging ${refuter.judged} of ${refuter.total}`,
|
|
373
|
+
children,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function scoutNode(
|
|
378
|
+
scout: PanelScout,
|
|
379
|
+
state: PanelState,
|
|
380
|
+
nowMs: number,
|
|
381
|
+
labelWidth: number,
|
|
382
|
+
): TreeNode {
|
|
383
|
+
const detail =
|
|
384
|
+
scout.status === "running"
|
|
385
|
+
? `reading the diff — ${formatElapsed(nowMs - state.startedAtMs)}`
|
|
386
|
+
: scout.status === "done"
|
|
387
|
+
? `${scout.leads ?? 0} lead${scout.leads === 1 ? "" : "s"} — ` +
|
|
388
|
+
formatElapsed(scout.durationMs ?? 0)
|
|
389
|
+
: "failed — the hunters run unled";
|
|
390
|
+
return {
|
|
391
|
+
label: pad("scout", labelWidth),
|
|
392
|
+
status: scout.status,
|
|
393
|
+
detail,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function summarizerNode(
|
|
398
|
+
summarizer: PanelSummarizer,
|
|
399
|
+
state: PanelState,
|
|
400
|
+
nowMs: number,
|
|
401
|
+
labelWidth: number,
|
|
402
|
+
): TreeNode {
|
|
403
|
+
const detail =
|
|
404
|
+
summarizer.status === "running"
|
|
405
|
+
? formatElapsed(nowMs - state.startedAtMs)
|
|
406
|
+
: summarizer.status === "done"
|
|
407
|
+
? formatElapsed(summarizer.durationMs ?? 0)
|
|
408
|
+
: "failed — the run continues";
|
|
409
|
+
const children =
|
|
410
|
+
summarizer.status === "failed"
|
|
411
|
+
? failureReasonChildren(summarizer.failureReason)
|
|
412
|
+
: [];
|
|
413
|
+
return {
|
|
414
|
+
label: pad("summarizer", labelWidth),
|
|
415
|
+
status:
|
|
416
|
+
summarizer.status === "running"
|
|
417
|
+
? "running"
|
|
418
|
+
: summarizer.status === "done"
|
|
419
|
+
? "done"
|
|
420
|
+
: "failed",
|
|
421
|
+
detail,
|
|
422
|
+
...(children.length === 0 ? {} : { children }),
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// One frame of the panel as plain lines — no cursor movement, no clearing;
|
|
427
|
+
// the shell owns positioning. `frame` indexes SPINNER_FRAMES (the shell's
|
|
428
|
+
// tick advances it). `maxLines` bounds the WHOLE panel, header included,
|
|
429
|
+
// because the shell's redraw arithmetic is against the count returned here.
|
|
430
|
+
export function renderPanelLines(
|
|
431
|
+
state: PanelState,
|
|
432
|
+
nowMs: number,
|
|
433
|
+
frame: number,
|
|
434
|
+
colors: boolean,
|
|
435
|
+
maxLines?: number,
|
|
436
|
+
): string[] {
|
|
437
|
+
const spinner = SPINNER_FRAMES[frame % SPINNER_FRAMES.length] ?? "";
|
|
438
|
+
const count = state.hunters.length;
|
|
439
|
+
const header =
|
|
440
|
+
`${spinner} reviewing ${state.subject} · ` +
|
|
441
|
+
`${count} hunter${count === 1 ? "" : "s"}` +
|
|
442
|
+
`${state.hasRefuter ? " + refuter" : ""} — ` +
|
|
443
|
+
formatElapsed(nowMs - state.startedAtMs);
|
|
444
|
+
if (maxLines !== undefined && maxLines <= 1) return [header];
|
|
445
|
+
const labelWidth = Math.max(
|
|
446
|
+
...state.hunters.map((h) => h.key.length),
|
|
447
|
+
"dedupe".length,
|
|
448
|
+
"refuter".length,
|
|
449
|
+
state.summarizer === undefined ? 0 : "summarizer".length,
|
|
450
|
+
state.scout === undefined ? 0 : "scout".length,
|
|
451
|
+
);
|
|
452
|
+
const modelWidth = Math.max(
|
|
453
|
+
0,
|
|
454
|
+
...state.hunters.map((h) => h.model?.length ?? 0),
|
|
455
|
+
);
|
|
456
|
+
// FIRST, above the hunters: it ran before them, and a row below rows that
|
|
457
|
+
// are waiting on it reads as the wrong order.
|
|
458
|
+
const nodes: TreeNode[] = [];
|
|
459
|
+
if (state.scout) nodes.push(scoutNode(state.scout, state, nowMs, labelWidth));
|
|
460
|
+
nodes.push(
|
|
461
|
+
...state.hunters.map((hunter) =>
|
|
462
|
+
hunterNode(hunter, state, nowMs, labelWidth, modelWidth),
|
|
463
|
+
),
|
|
464
|
+
);
|
|
465
|
+
if (state.summarizer) {
|
|
466
|
+
nodes.push(summarizerNode(state.summarizer, state, nowMs, labelWidth));
|
|
467
|
+
}
|
|
468
|
+
if (state.dedupe) {
|
|
469
|
+
nodes.push({
|
|
470
|
+
label: pad("dedupe", labelWidth),
|
|
471
|
+
status: "done",
|
|
472
|
+
detail:
|
|
473
|
+
`${state.dedupe.drafts} draft${state.dedupe.drafts === 1 ? "" : "s"}` +
|
|
474
|
+
` → ${state.dedupe.findings} ` +
|
|
475
|
+
`finding${state.dedupe.findings === 1 ? "" : "s"}`,
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
if (state.refuter) nodes.push(refuterNode(state.refuter, labelWidth));
|
|
479
|
+
return [
|
|
480
|
+
header,
|
|
481
|
+
...renderTree(nodes, {
|
|
482
|
+
styles: colors,
|
|
483
|
+
frame: spinner,
|
|
484
|
+
...(maxLines === undefined ? {} : { maxLines: maxLines - 1 }),
|
|
485
|
+
}),
|
|
486
|
+
];
|
|
487
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// T5b adjudication leg, pure half (src/triage/adjudication.ts holds the record).
|
|
2
|
+
// The CI adjudicator rules on one author dismissal per step. This module owns
|
|
3
|
+
// the prompt it is given and the one JSON object it must answer with; the
|
|
4
|
+
// pipeline owns the step itself. Clones the verify leg's nonce-wrapped block
|
|
5
|
+
// pattern (src/rereview/verify.ts composeVerifyPrompt), so the same forgery
|
|
6
|
+
// guard applies to the author's argument.
|
|
7
|
+
|
|
8
|
+
import { blockForgesNonce, wrapBlock } from "#review/boundary";
|
|
9
|
+
import { extractJsonObject } from "#review/drafts";
|
|
10
|
+
import type {
|
|
11
|
+
AdjudicationSubject,
|
|
12
|
+
AdjudicationVerdict,
|
|
13
|
+
} from "#triage/adjudication";
|
|
14
|
+
|
|
15
|
+
// Verbatim: the adjudicator's output contract is this sentence, nothing else.
|
|
16
|
+
const ADJUDICATION_INSTRUCTION =
|
|
17
|
+
'Rule on the author\'s argument that this finding should be dismissed. Read the repository at the current head yourself. Answer with exactly one JSON object and nothing else: {"verdict": "upheld" | "rejected" | "inconclusive", "evidence": ["path:line", ...]}. "upheld" only if you verified in the repository, yourself, that the finding is not a defect.';
|
|
18
|
+
|
|
19
|
+
const ADJUDICATION_VERDICT_WORDS: ReadonlySet<string> = new Set<string>([
|
|
20
|
+
"upheld",
|
|
21
|
+
"rejected",
|
|
22
|
+
"inconclusive",
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
// The most path:line citations kept from one ruling. A ruling that cites more
|
|
26
|
+
// is not made less true by the excess; the cap keeps the posted reply bounded.
|
|
27
|
+
const MAX_EVIDENCE = 20;
|
|
28
|
+
|
|
29
|
+
export function composeAdjudicationPrompt(
|
|
30
|
+
subject: AdjudicationSubject,
|
|
31
|
+
nonce: string,
|
|
32
|
+
): string | null {
|
|
33
|
+
const finding = JSON.stringify(
|
|
34
|
+
{
|
|
35
|
+
prior_id: subject.priorId,
|
|
36
|
+
severity: subject.sev,
|
|
37
|
+
locs: subject.locs,
|
|
38
|
+
claim: subject.claim,
|
|
39
|
+
},
|
|
40
|
+
null,
|
|
41
|
+
2,
|
|
42
|
+
);
|
|
43
|
+
const blocks = [finding, subject.argument];
|
|
44
|
+
if (blocks.some((block) => blockForgesNonce(block, nonce))) return null;
|
|
45
|
+
return [
|
|
46
|
+
wrapBlock("finding", nonce, finding),
|
|
47
|
+
wrapBlock("author_reply", nonce, subject.argument),
|
|
48
|
+
"",
|
|
49
|
+
ADJUDICATION_INSTRUCTION,
|
|
50
|
+
]
|
|
51
|
+
.filter((line) => line !== "")
|
|
52
|
+
.join("\n");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function parseAdjudicationResult(finalText: string): {
|
|
56
|
+
verdict: AdjudicationVerdict;
|
|
57
|
+
evidence: string[];
|
|
58
|
+
} {
|
|
59
|
+
const extracted = extractJsonObject(finalText);
|
|
60
|
+
if (
|
|
61
|
+
typeof extracted !== "object" ||
|
|
62
|
+
extracted === null ||
|
|
63
|
+
Array.isArray(extracted)
|
|
64
|
+
) {
|
|
65
|
+
throw new Error("adjudicator final message has no JSON object");
|
|
66
|
+
}
|
|
67
|
+
const record = extracted as Record<string, unknown>;
|
|
68
|
+
const verdict = record.verdict;
|
|
69
|
+
if (typeof verdict !== "string" || !ADJUDICATION_VERDICT_WORDS.has(verdict)) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"adjudicator verdict is not upheld, rejected or inconclusive",
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const rawEvidence = record.evidence;
|
|
75
|
+
let evidence: string[] = [];
|
|
76
|
+
if (rawEvidence !== undefined) {
|
|
77
|
+
if (
|
|
78
|
+
!Array.isArray(rawEvidence) ||
|
|
79
|
+
!rawEvidence.every((item) => typeof item === "string")
|
|
80
|
+
) {
|
|
81
|
+
throw new Error("adjudicator evidence is not an array of strings");
|
|
82
|
+
}
|
|
83
|
+
evidence = (rawEvidence as string[])
|
|
84
|
+
.map((item) => item.trim())
|
|
85
|
+
.filter((item) => item.length > 0)
|
|
86
|
+
.slice(0, MAX_EVIDENCE);
|
|
87
|
+
}
|
|
88
|
+
return { verdict: verdict as AdjudicationVerdict, evidence };
|
|
89
|
+
}
|