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,271 @@
|
|
|
1
|
+
// The CLI's writer for cli.json (odd/tasks/agent-first-ci.md, T2c). In action mode
|
|
2
|
+
// (CRYSK_OUTCOME_DIR set) it leaves the record the publisher reads. Without it,
|
|
3
|
+
// it does nothing and prints nothing, so local and watcher runs stay byte-identical.
|
|
4
|
+
//
|
|
5
|
+
// It never throws: the review's own result is not the record's to block. A write
|
|
6
|
+
// that cannot land prints one line, and the publisher then reads an earlier record
|
|
7
|
+
// or none at all. The write goes through the trigger's atomic writer, so the
|
|
8
|
+
// publisher never reads a half-written file.
|
|
9
|
+
//
|
|
10
|
+
// The record names what was DELIVERED, and the first, most specific writer wins.
|
|
11
|
+
// Before any of them, just before the CLI posts its pending hold, it writes a progress
|
|
12
|
+
// record instead: reviewing, which names the head the lock is on (recordReviewing,
|
|
13
|
+
// called from src/pr/plan.ts). It is progress, not an outcome, so every outcome
|
|
14
|
+
// below overwrites it.
|
|
15
|
+
// - hunters-failed: recordPipelineOutcome (src/pr/review-pr.ts), when the pipeline
|
|
16
|
+
// returns with every hunter failed. Nothing was delivered, so it is a record of its own.
|
|
17
|
+
// - skipped: publishCiSkip (src/pr/admission.ts), once the notice is on the PR (or
|
|
18
|
+
// the log line is printed, when posting is off).
|
|
19
|
+
// - reviewed: recordReviewDelivered, from publishRunOutcome (src/pr/publish-outcome.ts),
|
|
20
|
+
// once the findings post completes, or once the artifacts exist when posting is off.
|
|
21
|
+
// recordUnsettledStatus (src/pr/teardown.ts) may then add the final status a gate run
|
|
22
|
+
// could not write, and it rewrites a reviewed record only.
|
|
23
|
+
// - error: a writer that catches a failure at its own step (a posting, a skip notice),
|
|
24
|
+
// or writeFatalCliRecord for anything else.
|
|
25
|
+
// The pipeline finishing is not the review being delivered, and the commit status does
|
|
26
|
+
// not say delivery: its success phase means the pipeline finished without every hunter
|
|
27
|
+
// failing (its description is "review posted" or "review complete", or in gate mode a blocking count or a partial review). So the status and
|
|
28
|
+
// the record can differ. A posting that throws after a finished pipeline leaves the
|
|
29
|
+
// status success and the record error, and the publisher reports that error. The
|
|
30
|
+
// publisher posts its own status later under the same context ("crysk", and the legacy "pr-hero") when it
|
|
31
|
+
// knows the head, and that later status is the one GitHub shows.
|
|
32
|
+
// A failure after the pipeline returns and before delivery leaves no reviewed record,
|
|
33
|
+
// including a throw in the pipeline closure's finally or in the workflow group close.
|
|
34
|
+
//
|
|
35
|
+
// WHY ONLY BUILTINS (plus this directory's own builtins-only modules): the CLI
|
|
36
|
+
// imports this module, and the rule that keeps src/ci modules free of node_modules
|
|
37
|
+
// applies here too. outcome.ts and trigger.ts import nothing outside builtins.
|
|
38
|
+
|
|
39
|
+
import { readFileSync } from "node:fs";
|
|
40
|
+
import path from "node:path";
|
|
41
|
+
import {
|
|
42
|
+
actionsRunUrl,
|
|
43
|
+
CLI_RECORD_FILE,
|
|
44
|
+
type CliErrorClass,
|
|
45
|
+
type CliRecord,
|
|
46
|
+
type HunterFailureRecord,
|
|
47
|
+
knownFailureCredential,
|
|
48
|
+
knownTransportCause,
|
|
49
|
+
PENDING_AT_FILE,
|
|
50
|
+
parseCliRecord,
|
|
51
|
+
safeFailureDetail,
|
|
52
|
+
safeModelName,
|
|
53
|
+
safeProviderName,
|
|
54
|
+
type UnsettledStatus,
|
|
55
|
+
} from "./outcome";
|
|
56
|
+
import { NODE_FS, writeRecordAtomically } from "./trigger";
|
|
57
|
+
|
|
58
|
+
export function writeCliRecord(
|
|
59
|
+
record: CliRecord,
|
|
60
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
61
|
+
): void {
|
|
62
|
+
const dir = env.CRYSK_OUTCOME_DIR ?? "";
|
|
63
|
+
if (dir === "") return;
|
|
64
|
+
const written = inheritProgressHead(record, dir);
|
|
65
|
+
try {
|
|
66
|
+
writeRecordAtomically(
|
|
67
|
+
dir,
|
|
68
|
+
CLI_RECORD_FILE,
|
|
69
|
+
`${JSON.stringify(written)}\n`,
|
|
70
|
+
NODE_FS,
|
|
71
|
+
);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
process.stderr.write(
|
|
74
|
+
`crysk: could not write the outcome record: ${errnoCode(error)}\n`,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// WHY an outcome inherits the reviewing head (F002 on #330): the pending lock sits on
|
|
80
|
+
// the head the reviewing record names, and an outcome written after the hold may name
|
|
81
|
+
// no head of its own. The publisher would then answer on the trigger's head and leave
|
|
82
|
+
// the real lock pending. The reviewing record is this run's own statement of that head,
|
|
83
|
+
// so an outcome without one takes it. An outcome that names its head keeps its own.
|
|
84
|
+
function inheritProgressHead(record: CliRecord, dir: string): CliRecord {
|
|
85
|
+
if (record.head_sha !== undefined || record.outcome === "reviewing") {
|
|
86
|
+
return record;
|
|
87
|
+
}
|
|
88
|
+
const earlier = readEarlierRecord(dir);
|
|
89
|
+
if (earlier?.outcome !== "reviewing" || earlier.head_sha === undefined) {
|
|
90
|
+
return record;
|
|
91
|
+
}
|
|
92
|
+
return { ...record, head_sha: earlier.head_sha };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// The progress writer: src/pr/plan.ts calls it just before posting the pending hold, with
|
|
96
|
+
// the head that status is about to be posted on. It is written before the post, so no
|
|
97
|
+
// kill can leave a landed lock without a record. It is written whether or not the post
|
|
98
|
+
// lands, because the CLI tried to hold: the publisher must be able to tell this run's
|
|
99
|
+
// lock from a run that took none. A head that is not a 40-character lowercase SHA
|
|
100
|
+
// writes nothing, since the record would not parse, and the publisher reads an
|
|
101
|
+
// unparseable record as none.
|
|
102
|
+
export function recordReviewing(
|
|
103
|
+
headSha: string,
|
|
104
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
105
|
+
): void {
|
|
106
|
+
const head = cliHeadField(headSha);
|
|
107
|
+
if (head.head_sha === undefined) return;
|
|
108
|
+
writeCliRecord({ v: 1, outcome: "reviewing", head_sha: head.head_sha }, env);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// The head field a record may name: 40 lowercase hex, or nothing, so the record still
|
|
112
|
+
// parses when the head is not one. The pipeline record and the delivery record share it.
|
|
113
|
+
export function cliHeadField(headSha: string): { head_sha?: string } {
|
|
114
|
+
return /^[0-9a-f]{40}$/.test(headSha) ? { head_sha: headSha } : {};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// The per-hunter entries of a hunters-failed record. WHY each field is checked here and
|
|
118
|
+
// not left to the reader: a value the reader would refuse makes the whole record
|
|
119
|
+
// unreadable, and the publisher then reports no outcome at all. So a cause outside the
|
|
120
|
+
// vocabulary, or a provider, model or detail that is not a safe short string, is left out
|
|
121
|
+
// of its entry, and the entry still says that its hunter failed.
|
|
122
|
+
export function hunterFailureRecords(
|
|
123
|
+
failures: readonly {
|
|
124
|
+
readonly cause?: string;
|
|
125
|
+
readonly provider?: string;
|
|
126
|
+
readonly model?: string;
|
|
127
|
+
readonly detail?: string;
|
|
128
|
+
readonly credential?: string;
|
|
129
|
+
}[],
|
|
130
|
+
): HunterFailureRecord[] {
|
|
131
|
+
return failures.map((failure) => {
|
|
132
|
+
const entry: HunterFailureRecord = {};
|
|
133
|
+
const cause = knownTransportCause(failure.cause);
|
|
134
|
+
if (cause !== undefined) entry.cause = cause;
|
|
135
|
+
const provider = safeProviderName(failure.provider);
|
|
136
|
+
if (provider !== undefined) entry.provider = provider;
|
|
137
|
+
const model = safeModelName(failure.model);
|
|
138
|
+
if (model !== undefined) entry.model = model;
|
|
139
|
+
const detail = safeFailureDetail(failure.detail);
|
|
140
|
+
if (detail !== undefined) entry.detail = detail;
|
|
141
|
+
const credential = knownFailureCredential(failure.credential);
|
|
142
|
+
if (credential !== undefined) entry.credential = credential;
|
|
143
|
+
return entry;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// SB3: the pending's own identity, written once it landed. The cancel settle compares the
|
|
148
|
+
// head's newest pending with this exact time, so it never overwrites another run's pending.
|
|
149
|
+
// Never throws, and writes nothing outside action mode.
|
|
150
|
+
export function recordPendingCreatedAt(
|
|
151
|
+
createdAt: string,
|
|
152
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
153
|
+
): void {
|
|
154
|
+
const dir = env.CRYSK_OUTCOME_DIR ?? "";
|
|
155
|
+
if (dir === "") return;
|
|
156
|
+
try {
|
|
157
|
+
writeRecordAtomically(dir, PENDING_AT_FILE, `${createdAt}\n`, NODE_FS);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
process.stderr.write(
|
|
160
|
+
`crysk: could not write the pending record: ${errnoCode(error)}\n`,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// The delivery writer: publishRunOutcome calls it once the review is delivered (see the
|
|
166
|
+
// header for which delivery point, and why). A run that did not deliver never calls it.
|
|
167
|
+
export function recordReviewDelivered(
|
|
168
|
+
headSha: string,
|
|
169
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
170
|
+
): void {
|
|
171
|
+
writeCliRecord({ v: 1, outcome: "reviewed", ...cliHeadField(headSha) }, env);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// The unsettled-status writer: src/pr/teardown.ts calls it when a gate run's final status
|
|
175
|
+
// write fails after the review was delivered. The review is delivered, so the record stays
|
|
176
|
+
// reviewed, and it gains the status the CLI could not write, so the publisher step later in
|
|
177
|
+
// the same job can post it. The head is the one that status was written for, since that is
|
|
178
|
+
// the head whose required check is still pending. Only a reviewed record takes it: an error
|
|
179
|
+
// or hunters-failed record keeps its own outcome, and a head that is not a SHA writes nothing.
|
|
180
|
+
// It never throws, like the other writers.
|
|
181
|
+
//
|
|
182
|
+
// The override cutoff rides on the same record (override_cutoff_ms), when the caller has one: the
|
|
183
|
+
// CLI computes it once for the run (overrideCutoffMs, src/ci/override.ts), and the publisher
|
|
184
|
+
// compares an override with it before it reposts, without re-deriving it. A cutoff that is not a
|
|
185
|
+
// positive safe integer is left out, since the reader would refuse the record.
|
|
186
|
+
//
|
|
187
|
+
// WHY the earlier record is read here: the writer must know the outcome it would overwrite,
|
|
188
|
+
// and the write above has no such check of its own.
|
|
189
|
+
export function recordUnsettledStatus(
|
|
190
|
+
headSha: string,
|
|
191
|
+
status: UnsettledStatus,
|
|
192
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
193
|
+
overrideCutoffMs?: number | null,
|
|
194
|
+
): void {
|
|
195
|
+
const dir = env.CRYSK_OUTCOME_DIR ?? "";
|
|
196
|
+
if (dir === "") return;
|
|
197
|
+
const head = cliHeadField(headSha);
|
|
198
|
+
if (head.head_sha === undefined) return;
|
|
199
|
+
if (readEarlierRecord(dir)?.outcome !== "reviewed") return;
|
|
200
|
+
const cutoff =
|
|
201
|
+
overrideCutoffMs !== undefined &&
|
|
202
|
+
overrideCutoffMs !== null &&
|
|
203
|
+
Number.isSafeInteger(overrideCutoffMs) &&
|
|
204
|
+
overrideCutoffMs > 0
|
|
205
|
+
? { override_cutoff_ms: overrideCutoffMs }
|
|
206
|
+
: {};
|
|
207
|
+
writeCliRecord(
|
|
208
|
+
{
|
|
209
|
+
v: 1,
|
|
210
|
+
outcome: "reviewed",
|
|
211
|
+
...head,
|
|
212
|
+
unsettled_status: status,
|
|
213
|
+
...cutoff,
|
|
214
|
+
},
|
|
215
|
+
env,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// The fatal path's writer: the CLI's catches call this, never writeCliRecord. It keeps
|
|
220
|
+
// any terminal or error record this job already wrote, and writes its own error when
|
|
221
|
+
// there is none, when the file does not parse, or when the earlier record is reviewing.
|
|
222
|
+
// One line on stderr says which outcome was kept.
|
|
223
|
+
//
|
|
224
|
+
// WHY keep an error record too: the writer closest to the failure knows more than this
|
|
225
|
+
// top-level catch. A posting or a skip notice that threw has already named its step, and
|
|
226
|
+
// replacing that record with an unclassified error would discard the step.
|
|
227
|
+
//
|
|
228
|
+
// WHY a reviewing record is overwritten (F001 on #330): it is progress, not an outcome.
|
|
229
|
+
// The error replaces it, and writeCliRecord carries its head over, so the publisher
|
|
230
|
+
// answers on the head the lock is on.
|
|
231
|
+
//
|
|
232
|
+
// WHY no check that the record belongs to this job: the trigger clears cli.json at
|
|
233
|
+
// job start (clearStaleMarkers in trigger.ts), so a record present here was written
|
|
234
|
+
// by this job.
|
|
235
|
+
export function writeFatalCliRecord(
|
|
236
|
+
cls: CliErrorClass,
|
|
237
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
238
|
+
): void {
|
|
239
|
+
const dir = env.CRYSK_OUTCOME_DIR ?? "";
|
|
240
|
+
if (dir === "") return;
|
|
241
|
+
const earlier = readEarlierRecord(dir);
|
|
242
|
+
if (earlier !== undefined && earlier.outcome !== "reviewing") {
|
|
243
|
+
process.stderr.write(
|
|
244
|
+
`crysk: kept the recorded ${earlier.outcome} outcome; a later step failed\n`,
|
|
245
|
+
);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
writeCliRecord({ v: 1, outcome: "error", cls }, env);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// The record this job already wrote, or undefined when there is none, it cannot be
|
|
252
|
+
// read, or it does not parse. Never throws: the fatal path must not fail while it
|
|
253
|
+
// reports a failure.
|
|
254
|
+
function readEarlierRecord(dir: string): CliRecord | undefined {
|
|
255
|
+
try {
|
|
256
|
+
const text = readFileSync(path.join(dir, CLI_RECORD_FILE), "utf8");
|
|
257
|
+
return parseCliRecord(text);
|
|
258
|
+
} catch {
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// The errno code only (ENOENT, EACCES, ...). The message names the path, and the
|
|
264
|
+
// path does not belong in a runner log.
|
|
265
|
+
function errnoCode(error: unknown): string {
|
|
266
|
+
if (typeof error !== "object" || error === null || !("code" in error)) {
|
|
267
|
+
return "unknown";
|
|
268
|
+
}
|
|
269
|
+
const code = error.code;
|
|
270
|
+
return typeof code === "string" && code !== "" ? code : "unknown";
|
|
271
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// How a person or a local agent asks GitHub to run a skipped review anyway.
|
|
2
|
+
// The answer is a pull request comment, `/crysk review`: the scaffolded
|
|
3
|
+
// workflow listens for it, the action checks the commenter's write access,
|
|
4
|
+
// and the review runs on the Actions runner with --force. Running
|
|
5
|
+
// `pr-hero review --force` locally is a different path and is not this one.
|
|
6
|
+
//
|
|
7
|
+
// Workflows scaffolded before the comment trigger existed have no
|
|
8
|
+
// issue_comment listener, so a comment there does nothing. They have the
|
|
9
|
+
// dispatch-only `.github/workflows/pr-hero-force.yml` instead, and the action
|
|
10
|
+
// still declares the inputs it sets, so the hint keeps naming it as the
|
|
11
|
+
// fallback rather than leaving those repos with an instruction that silently
|
|
12
|
+
// fails.
|
|
13
|
+
|
|
14
|
+
import { commandHint } from "../brand";
|
|
15
|
+
import { REVIEW_COMMAND, REVIEW_FULL_COMMAND } from "./trigger";
|
|
16
|
+
|
|
17
|
+
// The trigger's own commands, so a hint can never name a spelling the action
|
|
18
|
+
// would not accept.
|
|
19
|
+
export const CI_REVIEW_COMMENT = REVIEW_COMMAND;
|
|
20
|
+
export const CI_REVIEW_FULL_COMMENT = REVIEW_FULL_COMMAND;
|
|
21
|
+
|
|
22
|
+
export const CI_FORCE_WORKFLOW_FILE = "pr-hero-force.yml";
|
|
23
|
+
|
|
24
|
+
export function ciForceReviewDispatch(prNumber: number): string {
|
|
25
|
+
if (!Number.isInteger(prNumber) || prNumber <= 0) {
|
|
26
|
+
throw new Error(`pr number must be a positive integer, got ${prNumber}`);
|
|
27
|
+
}
|
|
28
|
+
return `gh workflow run ${CI_FORCE_WORKFLOW_FILE} -f pr=${prNumber}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function ciForceReviewHintLine(prNumber: number): string {
|
|
32
|
+
return (
|
|
33
|
+
`Comment ${commandHint(CI_REVIEW_COMMENT)} on this pull request to run it ` +
|
|
34
|
+
`on GitHub Actions anyway (${commandHint(CI_REVIEW_FULL_COMMENT)} re-discovers the ` +
|
|
35
|
+
"whole range). On a workflow scaffolded before comment triggers, run " +
|
|
36
|
+
`\`${ciForceReviewDispatch(prNumber)}\` instead, or re-scaffold with ` +
|
|
37
|
+
"`crysk ci init --force`."
|
|
38
|
+
);
|
|
39
|
+
}
|