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
package/src/pr/plan.ts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
// PR mode's plan-and-confirm stage (ROADMAP B1): the real (non-dry-run) plan
|
|
2
|
+
// card, its two possible early exits (the CI budget gate, a declined
|
|
3
|
+
// interactive confirm), and the "committed to spending" commit-status hold
|
|
4
|
+
// that follows a successful confirm. Relocated out of reviewPr()
|
|
5
|
+
// (src/pr/review-pr.ts): identifiers moved onto explicit parameters, control
|
|
6
|
+
// flow and WHY comments unchanged.
|
|
7
|
+
//
|
|
8
|
+
// `parityFires` / `activeHunters` / `hunterCount` stay computed in
|
|
9
|
+
// reviewPr() itself: `activeHunters` is derived via `discoveryHunters`
|
|
10
|
+
// (src/pr/discovery.ts, invariant 1 — behavior-tested in
|
|
11
|
+
// test/pr/discovery.test.ts, not pinned as literal source) and is read only
|
|
12
|
+
// by reviewPr()'s own progress renderer, never by this stage. Only
|
|
13
|
+
// `hunterCount` (and `parityFires`, for the plan card's `resolved` field)
|
|
14
|
+
// actually cross into this function.
|
|
15
|
+
//
|
|
16
|
+
// A discriminated union, not a flat result-plus-sentinel: the two early-exit
|
|
17
|
+
// branches (`exitCode: number`) genuinely have no route plan, runner
|
|
18
|
+
// authority, or status url to report — the caller returns immediately and
|
|
19
|
+
// never reads them — so giving that branch real fields to fill would mean
|
|
20
|
+
// fabricating values nothing produced. Same intent as
|
|
21
|
+
// CiAdmissionGateResult's `exitCode: number | undefined` sentinel
|
|
22
|
+
// (src/pr/ci-admission-gate.ts), expressed so the type checker enforces it.
|
|
23
|
+
import { recordPendingCreatedAt, recordReviewing } from "#ci/cli-record";
|
|
24
|
+
import { planCiBudgetSkip } from "#ci/gates";
|
|
25
|
+
import { actionsRunUrl } from "#ci/outcome";
|
|
26
|
+
import {
|
|
27
|
+
countFreeRouteSteps,
|
|
28
|
+
type FreeRouteBilling,
|
|
29
|
+
} from "#model/free-discovery";
|
|
30
|
+
import type { ResolvedRoutePlan } from "#model/routing";
|
|
31
|
+
import {
|
|
32
|
+
type CiAdmissionLedgerState,
|
|
33
|
+
publishCiSkip,
|
|
34
|
+
settleCiGateSkip,
|
|
35
|
+
} from "#pr/admission";
|
|
36
|
+
import { ghRepoWebUrl } from "#pr/pr";
|
|
37
|
+
import {
|
|
38
|
+
type CiMode,
|
|
39
|
+
type CommitStatusContext,
|
|
40
|
+
commitStatusRequest,
|
|
41
|
+
type PrTarget,
|
|
42
|
+
prHtmlUrl,
|
|
43
|
+
} from "#pr/preflight";
|
|
44
|
+
import { holdCommitStatusLock, tryPublishCommitStatus } from "#pr/status";
|
|
45
|
+
import type { buildPhaseBQueue, PreparedDiscovery } from "#rereview/prepare";
|
|
46
|
+
import {
|
|
47
|
+
type AgentsDirSource,
|
|
48
|
+
type CliOptions,
|
|
49
|
+
resolveMaxVerificationSteps,
|
|
50
|
+
} from "#review/preflight";
|
|
51
|
+
import type { ParsedAgent } from "#review/prompt-set";
|
|
52
|
+
import { type DiffStat, estimateCost } from "#review/report";
|
|
53
|
+
import {
|
|
54
|
+
enforceCapabilityGate,
|
|
55
|
+
type LoadedRunConfig,
|
|
56
|
+
resolvePipelineRoute,
|
|
57
|
+
} from "#review/run";
|
|
58
|
+
import type { SizeGateVerdict } from "#review/size-gate";
|
|
59
|
+
import type { ReviewSpec } from "#review/spec";
|
|
60
|
+
import {
|
|
61
|
+
configProvenanceOf,
|
|
62
|
+
type PrPlanContext,
|
|
63
|
+
prPlanDetails,
|
|
64
|
+
renderPrPlan,
|
|
65
|
+
} from "#ui/plan";
|
|
66
|
+
import { log, styleEnabled } from "#ui/primitives";
|
|
67
|
+
import { confirm } from "#ui/progress";
|
|
68
|
+
import type { ProductionAdmissionContext } from "../production-runtime";
|
|
69
|
+
import {
|
|
70
|
+
type RunnerAuthorityResolution,
|
|
71
|
+
resolveRunnerAuthority,
|
|
72
|
+
} from "../runner-authority";
|
|
73
|
+
|
|
74
|
+
export type PrPlanAndConfirmResult =
|
|
75
|
+
| { exitCode: number }
|
|
76
|
+
| {
|
|
77
|
+
exitCode: undefined;
|
|
78
|
+
postEnabled: boolean;
|
|
79
|
+
routePlan: ResolvedRoutePlan | undefined;
|
|
80
|
+
productionAdmission: ProductionAdmissionContext | undefined;
|
|
81
|
+
runnerAuthority: RunnerAuthorityResolution;
|
|
82
|
+
maxVerificationSteps: number;
|
|
83
|
+
estimate: ReturnType<typeof estimateCost>;
|
|
84
|
+
statusTargetUrl: string | undefined;
|
|
85
|
+
// W3-FOOTER: the count the plan card priced by, handed on so the end-of-run
|
|
86
|
+
// footer names a free route the same way the card did.
|
|
87
|
+
freeRoute: FreeRouteBilling | undefined;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// The pending's target_url (SB3 follow-up): in GitHub Actions it is this run's attempt, so the
|
|
91
|
+
// cancel settle can tell this run's pending from another run's (decideCancelSettle, src/ci/publish.ts).
|
|
92
|
+
// Outside Actions it stays the PR page. The lock hold keeps the PR page either way.
|
|
93
|
+
export function pendingStatusTargetUrl(
|
|
94
|
+
prTargetUrl: string | undefined,
|
|
95
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
96
|
+
): string | undefined {
|
|
97
|
+
return actionsRunUrl(env) ?? prTargetUrl;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function resolvePrPlanAndConfirm(params: {
|
|
101
|
+
options: CliOptions;
|
|
102
|
+
operatorRoot: string;
|
|
103
|
+
prNumber: number;
|
|
104
|
+
target: PrTarget;
|
|
105
|
+
worktreePath: string;
|
|
106
|
+
runDir: string;
|
|
107
|
+
headSha: string;
|
|
108
|
+
baseSha: string;
|
|
109
|
+
diffFromSha: string;
|
|
110
|
+
diffPath: string;
|
|
111
|
+
diffStat: DiffStat;
|
|
112
|
+
droppedPaths: string[];
|
|
113
|
+
sizeGate: SizeGateVerdict;
|
|
114
|
+
sizeGateConfirmed: boolean;
|
|
115
|
+
agentsDir: string;
|
|
116
|
+
agentsDirSource: AgentsDirSource;
|
|
117
|
+
agentFiles: Map<string, ParsedAgent>;
|
|
118
|
+
spec: ReviewSpec;
|
|
119
|
+
config: LoadedRunConfig["config"];
|
|
120
|
+
summary: LoadedRunConfig["summary"];
|
|
121
|
+
loaded: LoadedRunConfig["loaded"];
|
|
122
|
+
isCi: boolean;
|
|
123
|
+
// The one resolution of the run's CI mode (resolveCiPosture, reviewPr). Passed
|
|
124
|
+
// down, never re-resolved here.
|
|
125
|
+
ciMode: CiMode;
|
|
126
|
+
// The context this run's statuses post on: pr-hero only for an explicit --ci
|
|
127
|
+
// run, pr-hero/local otherwise (resolveCiPosture). Passed down, never re-derived.
|
|
128
|
+
statusContext: CommitStatusContext;
|
|
129
|
+
ciBudgetCeiling: { budgetUsd: number | undefined };
|
|
130
|
+
ciAdmissionLedger: CiAdmissionLedgerState | null;
|
|
131
|
+
skipDiscovery: boolean;
|
|
132
|
+
hunterCount: number;
|
|
133
|
+
parityFires: boolean;
|
|
134
|
+
verifyQueue: ReturnType<typeof buildPhaseBQueue>["queued"];
|
|
135
|
+
prepared: PreparedDiscovery;
|
|
136
|
+
}): Promise<PrPlanAndConfirmResult> {
|
|
137
|
+
const maxVerificationSteps = resolveMaxVerificationSteps(params.config);
|
|
138
|
+
const queuedVerification = Math.min(
|
|
139
|
+
params.verifyQueue.length,
|
|
140
|
+
maxVerificationSteps,
|
|
141
|
+
);
|
|
142
|
+
const estimate = estimateCost(
|
|
143
|
+
params.diffStat,
|
|
144
|
+
params.hunterCount,
|
|
145
|
+
params.summary.enabled && !params.skipDiscovery,
|
|
146
|
+
params.options.scout && !params.skipDiscovery,
|
|
147
|
+
queuedVerification,
|
|
148
|
+
!params.skipDiscovery,
|
|
149
|
+
);
|
|
150
|
+
// 7b(CI) — the budget gate, immediately after the estimate it reads and
|
|
151
|
+
// BEFORE the plan card/confirm/"committed to spending" commit-status
|
|
152
|
+
// block below: spec 3.1 ("Review MUST halt before agent spawning") is
|
|
153
|
+
// satisfied at any point before runPipeline, and this is the earliest
|
|
154
|
+
// point the REAL (parity-narrowed) estimate exists — the same one the
|
|
155
|
+
// plan card is about to show, so the skip comment's number and the
|
|
156
|
+
// (unrendered) plan's number can never have disagreed. `estimate.high`,
|
|
157
|
+
// not `.low`: report.ts's own doctrine (~97-98) is that every recorded
|
|
158
|
+
// overrun was an UNDER-estimate, so the generous side is the cheap one
|
|
159
|
+
// to be wrong on. `force` is passed through: a `/pr-hero review` comment
|
|
160
|
+
// sets `--force`, and that one run clears this ceiling the same way it
|
|
161
|
+
// clears the size gate and admission. The interactive cost-band prompt
|
|
162
|
+
// is a different question and still requires `--yes` on its own.
|
|
163
|
+
// Unlike the size gate, this runs AFTER
|
|
164
|
+
// createPrRunDir (step 6), so a budget skip can leave a near-empty run
|
|
165
|
+
// dir behind — the tidiness rationale that placement protects against
|
|
166
|
+
// (the watcher's attempt counter) does not apply to an ephemeral CI
|
|
167
|
+
// runner, and restructuring the cost estimate earlier is out of Phase
|
|
168
|
+
// 3's scope.
|
|
169
|
+
// `ciBudgetCeiling.budgetUsd`, not `options.budgetUsd`: since issue #156
|
|
170
|
+
// an unset `--budget-usd` is a POLICY, not an absent number. It resolves
|
|
171
|
+
// to no ceiling on a subscription route (where `estimate.high` is a token
|
|
172
|
+
// figure and the cash cost is $0.00, so gating on it refused work over an
|
|
173
|
+
// overrun that cannot happen) and to the default ceiling on a metered one.
|
|
174
|
+
// `undefined` here still means the gate does not run — the announcement
|
|
175
|
+
// for that already fired at the resolution site above.
|
|
176
|
+
if (params.isCi && params.ciBudgetCeiling.budgetUsd !== undefined) {
|
|
177
|
+
const budgetPlan = planCiBudgetSkip({
|
|
178
|
+
isCi: params.isCi,
|
|
179
|
+
estimatedCostUsd: estimate.high,
|
|
180
|
+
budgetUsd: params.ciBudgetCeiling.budgetUsd,
|
|
181
|
+
prNumber: params.prNumber,
|
|
182
|
+
force: params.options.force,
|
|
183
|
+
ciMode: params.ciMode,
|
|
184
|
+
});
|
|
185
|
+
if (budgetPlan !== null) {
|
|
186
|
+
await settleCiGateSkip(
|
|
187
|
+
params.ciAdmissionLedger,
|
|
188
|
+
"estimated cost exceeds the configured CI budget ceiling",
|
|
189
|
+
);
|
|
190
|
+
const exitCode = await publishCiSkip({
|
|
191
|
+
operatorRoot: params.operatorRoot,
|
|
192
|
+
prNumber: params.prNumber,
|
|
193
|
+
post: params.options.post === true,
|
|
194
|
+
isCi: params.isCi,
|
|
195
|
+
stepSummaryFlag: params.options.stepSummary,
|
|
196
|
+
plan: budgetPlan,
|
|
197
|
+
noticeMessage:
|
|
198
|
+
"crysk review skipped — estimated cost exceeds the configured CI budget ceiling",
|
|
199
|
+
ciMode: params.ciMode,
|
|
200
|
+
headSha: params.headSha,
|
|
201
|
+
});
|
|
202
|
+
return { exitCode };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const productionRoute = await resolvePipelineRoute({
|
|
206
|
+
routingConfigured: params.config.routing !== undefined,
|
|
207
|
+
workspaceRoot: params.worktreePath,
|
|
208
|
+
spec: params.spec,
|
|
209
|
+
options: params.options,
|
|
210
|
+
agentFiles: params.agentFiles,
|
|
211
|
+
routingConfig: params.config.routing,
|
|
212
|
+
summary: params.summary,
|
|
213
|
+
summarizerEnabled: params.summary.enabled && !params.skipDiscovery,
|
|
214
|
+
scoutEnabled: params.options.scout && !params.skipDiscovery,
|
|
215
|
+
consolidateEnabled: !params.skipDiscovery,
|
|
216
|
+
});
|
|
217
|
+
const routePlan = productionRoute?.routePlan;
|
|
218
|
+
const productionAdmission = productionRoute?.productionAdmission;
|
|
219
|
+
// Read off the admission above, which already decided every free verdict:
|
|
220
|
+
// this adds no probe. Absent without routing, so the band stays.
|
|
221
|
+
const freeRoute =
|
|
222
|
+
routePlan === undefined || productionAdmission === undefined
|
|
223
|
+
? undefined
|
|
224
|
+
: await countFreeRouteSteps({
|
|
225
|
+
steps: routePlan.steps,
|
|
226
|
+
probe: productionAdmission.freeModelProbe,
|
|
227
|
+
});
|
|
228
|
+
const runnerAuthority = await resolveRunnerAuthority({
|
|
229
|
+
workspaceRoot: params.worktreePath,
|
|
230
|
+
});
|
|
231
|
+
await enforceCapabilityGate({
|
|
232
|
+
routePlan,
|
|
233
|
+
workspaceRoot: params.worktreePath,
|
|
234
|
+
runnerAuthority,
|
|
235
|
+
productionAdmission,
|
|
236
|
+
});
|
|
237
|
+
// Same reason as local mode's planContext: the card and the confirm menu's
|
|
238
|
+
// details view must describe one and the same planned run.
|
|
239
|
+
const planContext: PrPlanContext = {
|
|
240
|
+
options: params.options,
|
|
241
|
+
operatorRoot: params.operatorRoot,
|
|
242
|
+
target: params.target,
|
|
243
|
+
worktreePath: params.worktreePath,
|
|
244
|
+
runDir: params.runDir,
|
|
245
|
+
diffStat: params.diffStat,
|
|
246
|
+
agentsDir: params.agentsDir,
|
|
247
|
+
agentFiles: params.agentFiles,
|
|
248
|
+
spec: params.spec,
|
|
249
|
+
config: params.config,
|
|
250
|
+
summary: params.summary,
|
|
251
|
+
estimate,
|
|
252
|
+
hunterCount: params.hunterCount,
|
|
253
|
+
sizeGate: params.sizeGate,
|
|
254
|
+
droppedPaths: params.droppedPaths,
|
|
255
|
+
configProvenance: configProvenanceOf(params.loaded, params.agentsDirSource),
|
|
256
|
+
resolved: {
|
|
257
|
+
baseSha: params.baseSha,
|
|
258
|
+
diffFromSha: params.diffFromSha,
|
|
259
|
+
diffPath: params.diffPath,
|
|
260
|
+
parityFires: params.parityFires,
|
|
261
|
+
},
|
|
262
|
+
...(params.sizeGateConfirmed ? { sizeGateConfirmed: true } : {}),
|
|
263
|
+
...(queuedVerification > 0
|
|
264
|
+
? { verificationSteps: queuedVerification }
|
|
265
|
+
: {}),
|
|
266
|
+
...(params.prepared.case === "A"
|
|
267
|
+
? {}
|
|
268
|
+
: {
|
|
269
|
+
rereview: {
|
|
270
|
+
case: params.prepared.case,
|
|
271
|
+
lastHead: params.prepared.last.L,
|
|
272
|
+
discoveryRestricted: params.prepared.plan.discoveryRestricted,
|
|
273
|
+
skipDiscovery: params.skipDiscovery,
|
|
274
|
+
},
|
|
275
|
+
}),
|
|
276
|
+
...(routePlan === undefined ? {} : { routePlan }),
|
|
277
|
+
...(freeRoute === undefined ? {} : { freeRoute }),
|
|
278
|
+
};
|
|
279
|
+
for (const line of renderPrPlan(planContext, styleEnabled())) log(line);
|
|
280
|
+
// What this run will actually publish. `options` is never mutated: the plan
|
|
281
|
+
// card and the details view print what was ASKED FOR, and only the run
|
|
282
|
+
// itself follows the answer given here.
|
|
283
|
+
let postEnabled = params.options.post ?? false;
|
|
284
|
+
if (!params.options.yes) {
|
|
285
|
+
const choice = await confirm(
|
|
286
|
+
estimate.low,
|
|
287
|
+
estimate.high,
|
|
288
|
+
params.options.post ?? false,
|
|
289
|
+
() => prPlanDetails(planContext, styleEnabled()),
|
|
290
|
+
freeRoute,
|
|
291
|
+
);
|
|
292
|
+
if (choice.kind === "cancel") {
|
|
293
|
+
log("aborted; nothing was spent.");
|
|
294
|
+
return { exitCode: 1 };
|
|
295
|
+
}
|
|
296
|
+
postEnabled = choice.post;
|
|
297
|
+
if (params.options.post && !postEnabled) {
|
|
298
|
+
log("posting disabled for this run; the review still runs.");
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Committed to spending: a pending commit status is the GitHub-visible
|
|
303
|
+
// in-flight signal. Check Runs need a GitHub App; this CLI posts as the
|
|
304
|
+
// operator via `gh`, so the write path is the Statuses API. Size-gate
|
|
305
|
+
// abort and a declined confirm never reach here.
|
|
306
|
+
const statusTargetUrl = prHtmlUrl(
|
|
307
|
+
await ghRepoWebUrl(params.operatorRoot),
|
|
308
|
+
params.prNumber,
|
|
309
|
+
);
|
|
310
|
+
// WHY the progress record comes BEFORE the pending post (F001 and F002 on #330): the
|
|
311
|
+
// publisher gives a run with no record no status on any head, so the record is what
|
|
312
|
+
// says the lock is this run's and on which head. The CLI records that it is about to
|
|
313
|
+
// hold the lock before it posts the lock, so no kill can leave a landed pending with
|
|
314
|
+
// no record; such a pending would stay until the admission gate's 90-minute TTL
|
|
315
|
+
// expires. If the post never lands and the CLI then dies, the publisher reads no
|
|
316
|
+
// pending status on that head and posts the error status (unless the head's newest
|
|
317
|
+
// pr-hero status already settled), which is right, because the run died. If the CLI
|
|
318
|
+
// completes, its terminal record overwrites `reviewing`.
|
|
319
|
+
// WHY the start is read here, before the record and the POST: the POST can take two
|
|
320
|
+
// attempts of 15 s, and an override posted while it is in flight was posted during this
|
|
321
|
+
// run. Stamping after the POST would class that override as before the run and overwrite
|
|
322
|
+
// it (the override rule, src/ci/override.ts).
|
|
323
|
+
const runStartedMs = Date.now();
|
|
324
|
+
recordReviewing(params.headSha);
|
|
325
|
+
const pendingLanded = await tryPublishCommitStatus(
|
|
326
|
+
params.operatorRoot,
|
|
327
|
+
params.headSha,
|
|
328
|
+
commitStatusRequest({
|
|
329
|
+
phase: "pending",
|
|
330
|
+
posted: false,
|
|
331
|
+
targetUrl: pendingStatusTargetUrl(statusTargetUrl),
|
|
332
|
+
context: params.statusContext,
|
|
333
|
+
}),
|
|
334
|
+
undefined,
|
|
335
|
+
(createdAt) => recordPendingCreatedAt(createdAt),
|
|
336
|
+
);
|
|
337
|
+
// From here the lock is HELD, and the only two ways out both clear it:
|
|
338
|
+
// the finally below on the normal path, and the signal handlers in runCli
|
|
339
|
+
// on the cancelled one. Held even if the publish above failed — a settle
|
|
340
|
+
// for a status that was never posted is a harmless no-op write, whereas
|
|
341
|
+
// skipping the hold on a publish that actually landed is the #162 bug. Whether the
|
|
342
|
+
// pending landed is passed too: only a landed pending vouches for runStartedMs in the
|
|
343
|
+
// override check (teardown.ts).
|
|
344
|
+
holdCommitStatusLock(
|
|
345
|
+
{
|
|
346
|
+
operatorRoot: params.operatorRoot,
|
|
347
|
+
sha: params.headSha,
|
|
348
|
+
targetUrl: statusTargetUrl,
|
|
349
|
+
context: params.statusContext,
|
|
350
|
+
},
|
|
351
|
+
runStartedMs,
|
|
352
|
+
pendingLanded,
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
return {
|
|
356
|
+
exitCode: undefined,
|
|
357
|
+
postEnabled,
|
|
358
|
+
routePlan,
|
|
359
|
+
productionAdmission,
|
|
360
|
+
runnerAuthority,
|
|
361
|
+
maxVerificationSteps,
|
|
362
|
+
estimate,
|
|
363
|
+
statusTargetUrl,
|
|
364
|
+
freeRoute,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// PR mode's inline-posting stage: publish the review as PR comments, only
|
|
2
|
+
// when asked. Relocated out of reviewPr() (src/pr/review-pr.ts): the
|
|
3
|
+
// `postEnabled` branch became an early return and identifiers moved onto
|
|
4
|
+
// explicit parameters, control flow otherwise unchanged. The WHY comments
|
|
5
|
+
// below move with the code they explain.
|
|
6
|
+
//
|
|
7
|
+
// Runs AFTER the Greptile comparison on purpose: a posting failure must
|
|
8
|
+
// never cost the comparison artifact. And unlike the comparison, posting
|
|
9
|
+
// does NOT degrade to a warning — it was explicitly requested. Goes through
|
|
10
|
+
// the inline surface — anchorability, cross-run matching, the one review
|
|
11
|
+
// submission (with its 422 recovery into the summary Outside Diff bucket).
|
|
12
|
+
// `postInlineIfEligible` carries the `sessionFailed` guard (design D6,
|
|
13
|
+
// spec "sessionFailed suppresses all posting"): a clean-bill comment set
|
|
14
|
+
// from a review that never ran would be a public lie, same reasoning as the
|
|
15
|
+
// comparison guard in comparison.ts.
|
|
16
|
+
|
|
17
|
+
import type { InlinePostOutcome } from "#pr/inline";
|
|
18
|
+
import { ghRepoWebUrl, postInlineIfEligible, writePostReceipt } from "#pr/pr";
|
|
19
|
+
import type { CiMode } from "#pr/preflight";
|
|
20
|
+
import type { RereviewProvenance } from "#rereview/prepare";
|
|
21
|
+
import type { FindingsDocument } from "#review/findings";
|
|
22
|
+
import { log } from "#ui/primitives";
|
|
23
|
+
|
|
24
|
+
export interface PostingStageResult {
|
|
25
|
+
posted: InlinePostOutcome | null;
|
|
26
|
+
postedWebUrl: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function postFindingsIfEnabled(input: {
|
|
30
|
+
postEnabled: boolean;
|
|
31
|
+
sessionFailed: boolean;
|
|
32
|
+
operatorRoot: string;
|
|
33
|
+
pr: number;
|
|
34
|
+
headSha: string;
|
|
35
|
+
doc: FindingsDocument;
|
|
36
|
+
diffPatch: string;
|
|
37
|
+
runDir: string;
|
|
38
|
+
rereview?: RereviewProvenance;
|
|
39
|
+
rereviewPriors?: readonly {
|
|
40
|
+
id: string;
|
|
41
|
+
claim: string;
|
|
42
|
+
locs: readonly string[];
|
|
43
|
+
}[];
|
|
44
|
+
// Test-only seam (default: the real Bun.spawn). ghRepoWebUrl and
|
|
45
|
+
// postInlineIfEligible already accept an invisible-to-production spawnFn
|
|
46
|
+
// of their own (pr.ts's established seam); this stage just never exposed
|
|
47
|
+
// the option, so offline tests could not reach either without hitting gh.
|
|
48
|
+
spawnFn?: typeof Bun.spawn;
|
|
49
|
+
// The delivery point (F002 on #330): fired once the findings POST resolves with
|
|
50
|
+
// an outcome, before the local receipt is written. The caller records the review
|
|
51
|
+
// as delivered here, so a receipt write that fails afterwards is a failure after
|
|
52
|
+
// delivery, never a failed delivery. Never fired when posting is off, or when the
|
|
53
|
+
// session failed and nothing was posted.
|
|
54
|
+
onDelivered?: () => void;
|
|
55
|
+
// S4: the mode this run resolved. It reaches the summary comment's footer.
|
|
56
|
+
ciMode: CiMode;
|
|
57
|
+
// A comment-triggered run. Forwarded so the summary counter stays put (see
|
|
58
|
+
// nextStateReviewCount in ci/review-admission.ts).
|
|
59
|
+
force?: boolean;
|
|
60
|
+
}): Promise<PostingStageResult> {
|
|
61
|
+
if (!input.postEnabled) {
|
|
62
|
+
return { posted: null, postedWebUrl: undefined };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const postedWebUrl = await ghRepoWebUrl(input.operatorRoot, {
|
|
66
|
+
spawnFn: input.spawnFn,
|
|
67
|
+
});
|
|
68
|
+
if (postedWebUrl === undefined) {
|
|
69
|
+
log("repo web url unavailable: posting plain locations");
|
|
70
|
+
}
|
|
71
|
+
const posted = await postInlineIfEligible({
|
|
72
|
+
sessionFailed: input.sessionFailed,
|
|
73
|
+
skippedReason:
|
|
74
|
+
"post skipped: every hunter failed, so there is no review to publish",
|
|
75
|
+
operatorRoot: input.operatorRoot,
|
|
76
|
+
pr: input.pr,
|
|
77
|
+
headSha: input.headSha,
|
|
78
|
+
doc: input.doc,
|
|
79
|
+
diffPatch: input.diffPatch,
|
|
80
|
+
webUrl: postedWebUrl,
|
|
81
|
+
spawnFn: input.spawnFn,
|
|
82
|
+
rereview: input.rereview,
|
|
83
|
+
rereviewPriors: input.rereviewPriors,
|
|
84
|
+
ciMode: input.ciMode,
|
|
85
|
+
force: input.force,
|
|
86
|
+
});
|
|
87
|
+
if (posted) {
|
|
88
|
+
input.onDelivered?.();
|
|
89
|
+
await writePostReceipt(input.runDir, input.pr, input.headSha, posted);
|
|
90
|
+
log(
|
|
91
|
+
`posted: review ${posted.reviewOutcome} (${posted.reviewFindingCount} ` +
|
|
92
|
+
`finding(s)), ${posted.outsideDiffCount} outside diff, ` +
|
|
93
|
+
`summary ${posted.summary.action} comment ${posted.summary.commentId}`,
|
|
94
|
+
);
|
|
95
|
+
// GitHub #39: said at the MOMENT it happened, not only in the result
|
|
96
|
+
// block minutes of scrollback later — the same reason the 422 demotion
|
|
97
|
+
// below gets its own line here. The two can co-occur: a force-push both
|
|
98
|
+
// moves the head and 422s the pinned submission.
|
|
99
|
+
if (posted.movedHeadSha) {
|
|
100
|
+
log(
|
|
101
|
+
`warning: the PR head moved while the review ran — reviewed ` +
|
|
102
|
+
`${input.headSha}, head is now ${posted.movedHeadSha}; the ` +
|
|
103
|
+
"comments are pinned to the reviewed commit",
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (posted.reviewOutcome === "demoted") {
|
|
107
|
+
log(
|
|
108
|
+
"warning: the review submission was rejected (422) and recovered " +
|
|
109
|
+
"into the summary Outside Diff bucket — see the run's post.json " +
|
|
110
|
+
"for detail",
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return { posted, postedWebUrl };
|
|
115
|
+
}
|