crysk 0.0.0 → 0.3.1
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 +611 -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/SKILL-y8rv8msh.md +134 -0
- package/dist/SKILL-ygka1bs0.md +515 -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/ci-admission-qk9r9taq.md +124 -0
- package/dist/cli.js +42501 -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 +124 -0
- package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
- package/skills/crysk-loop/SKILL.md +515 -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 +945 -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 +910 -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 +984 -0
- package/src/pr/answered-findings.ts +169 -0
- package/src/pr/ci-admission-gate.ts +743 -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 +845 -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,448 @@
|
|
|
1
|
+
import type { ResolvedRoutePlan, RoutingConfig } from "#model/routing";
|
|
2
|
+
import type { DraftFinding } from "#review/drafts";
|
|
3
|
+
import { SCHEMA_VERSION_V1_1 } from "#review/findings";
|
|
4
|
+
import type { AgentSpec, ReviewSpec } from "#review/spec";
|
|
5
|
+
import { resolveSpecialty } from "#review/spec";
|
|
6
|
+
import type { StepResult } from "#review/step-runner";
|
|
7
|
+
import type { ResolvedModelRoute } from "../execution/contracts";
|
|
8
|
+
import {
|
|
9
|
+
type NormalizedUsage,
|
|
10
|
+
normalizeInclusiveUsage,
|
|
11
|
+
} from "../execution/usage-normalized";
|
|
12
|
+
import {
|
|
13
|
+
appendAttempt,
|
|
14
|
+
appendObservation,
|
|
15
|
+
type DiversityAttemptRecord,
|
|
16
|
+
type DiversityLedger,
|
|
17
|
+
emptyDiversityLedger,
|
|
18
|
+
summarizeDiversityAccounting,
|
|
19
|
+
} from "./accounting";
|
|
20
|
+
import { synthesizeDeterministicAdjudication } from "./adjudication";
|
|
21
|
+
import {
|
|
22
|
+
assertDiversityCapabilityOrThrow,
|
|
23
|
+
checkInternalFindingsCapability,
|
|
24
|
+
type InternalCapabilityReport,
|
|
25
|
+
} from "./admission";
|
|
26
|
+
import { buildAdjudicationGroups, type FindingObservation } from "./clustering";
|
|
27
|
+
import { DiversityAdmissionError } from "./errors";
|
|
28
|
+
import {
|
|
29
|
+
assertRouteFingerprintStable,
|
|
30
|
+
assertSpendUnderCap,
|
|
31
|
+
type BenchmarkTarget,
|
|
32
|
+
buildDiversityPlan,
|
|
33
|
+
type DiversityLeg,
|
|
34
|
+
type DiversityPlan,
|
|
35
|
+
expandDiversityAgents,
|
|
36
|
+
} from "./identity";
|
|
37
|
+
import { projectAdjudicationToFindings } from "./projection";
|
|
38
|
+
import { validateFrozenExternalTarget } from "./target-validation";
|
|
39
|
+
|
|
40
|
+
export interface DiversityPipelineRecord {
|
|
41
|
+
readonly enabled: boolean;
|
|
42
|
+
readonly status: "ok" | "partial" | "skipped" | "failed";
|
|
43
|
+
readonly armId?: string;
|
|
44
|
+
readonly planFingerprint?: string;
|
|
45
|
+
readonly legCount?: number;
|
|
46
|
+
readonly attemptCount?: number;
|
|
47
|
+
readonly observationCount?: number;
|
|
48
|
+
readonly failureCount?: number;
|
|
49
|
+
readonly cashCostUsd?: number;
|
|
50
|
+
readonly notionalCostUsd?: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface DiversityExecutionContext {
|
|
54
|
+
readonly enabled: boolean;
|
|
55
|
+
readonly plan?: DiversityPlan;
|
|
56
|
+
readonly ledger: DiversityLedger;
|
|
57
|
+
readonly routeAgents: readonly AgentSpec[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface PrepareDiversityInput {
|
|
61
|
+
readonly reviewSpec: ReviewSpec;
|
|
62
|
+
readonly cliModel?: string;
|
|
63
|
+
readonly routingConfig?: RoutingConfig;
|
|
64
|
+
readonly frontmatterModel?: (agentKey: string) => string | undefined;
|
|
65
|
+
readonly target?: BenchmarkTarget;
|
|
66
|
+
readonly runtimeTarget?: BenchmarkTarget;
|
|
67
|
+
readonly promptFingerprint?: string;
|
|
68
|
+
readonly buildFingerprint?: string;
|
|
69
|
+
readonly capabilityCheck?: () => InternalCapabilityReport;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function prepareDiversityExecution(
|
|
73
|
+
input: PrepareDiversityInput,
|
|
74
|
+
): DiversityExecutionContext {
|
|
75
|
+
const diversity = input.reviewSpec.multiModelDiversity;
|
|
76
|
+
if (!diversity?.enabled) {
|
|
77
|
+
return {
|
|
78
|
+
enabled: false,
|
|
79
|
+
ledger: emptyDiversityLedger(),
|
|
80
|
+
routeAgents: input.reviewSpec.agents,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
assertDiversityCapabilityOrThrow(
|
|
84
|
+
input.capabilityCheck?.() ?? checkInternalFindingsCapability(),
|
|
85
|
+
);
|
|
86
|
+
const frozenTarget = input.target ?? input.runtimeTarget;
|
|
87
|
+
const plan = buildDiversityPlan({
|
|
88
|
+
spec: input.reviewSpec,
|
|
89
|
+
c2SchemaVersion: SCHEMA_VERSION_V1_1,
|
|
90
|
+
cliModel: input.cliModel,
|
|
91
|
+
routingConfig: input.routingConfig,
|
|
92
|
+
frontmatterModel: input.frontmatterModel,
|
|
93
|
+
target: frozenTarget,
|
|
94
|
+
promptFingerprint: input.promptFingerprint,
|
|
95
|
+
buildFingerprint: input.buildFingerprint,
|
|
96
|
+
});
|
|
97
|
+
if (plan.target && input.runtimeTarget) {
|
|
98
|
+
validateFrozenExternalTarget(plan.target, input.runtimeTarget);
|
|
99
|
+
}
|
|
100
|
+
const expanded = expandDiversityAgents(input.reviewSpec, plan);
|
|
101
|
+
return {
|
|
102
|
+
enabled: true,
|
|
103
|
+
plan,
|
|
104
|
+
ledger: emptyDiversityLedger(),
|
|
105
|
+
routeAgents: expanded.map((agent) => ({
|
|
106
|
+
key: agent.key,
|
|
107
|
+
specialty: agent.specialty,
|
|
108
|
+
file: agent.file,
|
|
109
|
+
role: agent.role,
|
|
110
|
+
trigger: agent.trigger,
|
|
111
|
+
model: agent.model,
|
|
112
|
+
})),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function executionHuntersForTriggered(
|
|
117
|
+
reviewSpec: ReviewSpec,
|
|
118
|
+
ctx: DiversityExecutionContext,
|
|
119
|
+
triggeredBaseHunters: readonly AgentSpec[],
|
|
120
|
+
): readonly AgentSpec[] {
|
|
121
|
+
if (!ctx.enabled || !ctx.plan) return triggeredBaseHunters;
|
|
122
|
+
const expanded = expandDiversityAgents(reviewSpec, ctx.plan);
|
|
123
|
+
const hunters: AgentSpec[] = [];
|
|
124
|
+
for (const base of triggeredBaseHunters) {
|
|
125
|
+
const legs = expanded.filter(
|
|
126
|
+
(agent) =>
|
|
127
|
+
agent.role === "hunter" &&
|
|
128
|
+
(agent.key === base.key || agent.key.startsWith(`${base.key}--`)),
|
|
129
|
+
);
|
|
130
|
+
if (legs.length === 0) {
|
|
131
|
+
hunters.push(base);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
for (const leg of legs) {
|
|
135
|
+
hunters.push({
|
|
136
|
+
key: leg.key,
|
|
137
|
+
specialty: leg.specialty,
|
|
138
|
+
file: leg.file,
|
|
139
|
+
role: leg.role,
|
|
140
|
+
trigger: leg.trigger,
|
|
141
|
+
model: leg.model,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return hunters;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function legForAgent(
|
|
149
|
+
plan: DiversityPlan,
|
|
150
|
+
agent: AgentSpec,
|
|
151
|
+
): DiversityLeg | undefined {
|
|
152
|
+
return plan.legs.find(
|
|
153
|
+
(leg) => leg.agentKey === agent.key || leg.executionKey === agent.key,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function usageFromStep(result: StepResult): NormalizedUsage {
|
|
158
|
+
if (result.usageV2) return result.usageV2;
|
|
159
|
+
return normalizeInclusiveUsage({
|
|
160
|
+
wallMs: result.usage.wall_ms,
|
|
161
|
+
inputTotal: result.usage.tokens_in,
|
|
162
|
+
outputTotal: result.usage.tokens_out,
|
|
163
|
+
billingMode: "unknown",
|
|
164
|
+
costSource: "unknown",
|
|
165
|
+
cashCostUsd: result.usage.cost_usd_est,
|
|
166
|
+
notionalCostUsd: result.usage.cost_usd_est,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function scaleUsageFraction(
|
|
171
|
+
usage: NormalizedUsage,
|
|
172
|
+
fraction: number,
|
|
173
|
+
): NormalizedUsage {
|
|
174
|
+
const scale = (value: number | undefined) =>
|
|
175
|
+
value === undefined ? undefined : value * fraction;
|
|
176
|
+
return {
|
|
177
|
+
...usage,
|
|
178
|
+
cashCostUsd: scale(usage.cashCostUsd),
|
|
179
|
+
notionalCostUsd: scale(usage.notionalCostUsd),
|
|
180
|
+
tokens: {
|
|
181
|
+
...usage.tokens,
|
|
182
|
+
inputKnown: scale(usage.tokens.inputKnown),
|
|
183
|
+
outputKnown: scale(usage.tokens.outputKnown),
|
|
184
|
+
totalKnown: scale(usage.tokens.totalKnown),
|
|
185
|
+
providerReportedTotal: scale(usage.tokens.providerReportedTotal),
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function assertDiversityLegRoutes(
|
|
191
|
+
plan: DiversityPlan,
|
|
192
|
+
routePlan: ResolvedRoutePlan,
|
|
193
|
+
): void {
|
|
194
|
+
for (const leg of plan.legs) {
|
|
195
|
+
const step = routePlan.steps.find(
|
|
196
|
+
(candidate) => candidate.stepKey === leg.stepKey,
|
|
197
|
+
);
|
|
198
|
+
if (!step) {
|
|
199
|
+
throw new DiversityAdmissionError(
|
|
200
|
+
`missing resolved route for leg ${leg.legId}`,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
assertRouteFingerprintStable(
|
|
204
|
+
leg.routeFingerprint,
|
|
205
|
+
step.routeFingerprint,
|
|
206
|
+
leg.legId,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function assertDiversitySpendUnderCap(
|
|
212
|
+
plan: DiversityPlan,
|
|
213
|
+
ledger: DiversityLedger,
|
|
214
|
+
): void {
|
|
215
|
+
const totals = summarizeDiversityAccounting(ledger);
|
|
216
|
+
assertSpendUnderCap(plan, totals.cashCostUsd);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function recordDiversityHunterFailure(
|
|
220
|
+
ledger: DiversityLedger,
|
|
221
|
+
plan: DiversityPlan,
|
|
222
|
+
agent: AgentSpec,
|
|
223
|
+
): DiversityLedger {
|
|
224
|
+
const resolvedLeg = legForAgent(plan, agent);
|
|
225
|
+
if (!resolvedLeg) {
|
|
226
|
+
throw new DiversityAdmissionError(
|
|
227
|
+
`no diversity leg for failed hunter ${agent.key}`,
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
const attemptId = `${resolvedLeg.legId}-a0`;
|
|
231
|
+
const attempt: DiversityAttemptRecord = {
|
|
232
|
+
attemptId,
|
|
233
|
+
legId: resolvedLeg.legId,
|
|
234
|
+
armId: plan.armId,
|
|
235
|
+
specialty: resolveSpecialty(agent),
|
|
236
|
+
replicate: 1,
|
|
237
|
+
attempt: 0,
|
|
238
|
+
status: "failed",
|
|
239
|
+
usage: normalizeInclusiveUsage({
|
|
240
|
+
wallMs: 0,
|
|
241
|
+
inputTotal: 0,
|
|
242
|
+
outputTotal: 0,
|
|
243
|
+
billingMode: "unknown",
|
|
244
|
+
costSource: "unknown",
|
|
245
|
+
}),
|
|
246
|
+
};
|
|
247
|
+
return appendAttempt(ledger, attempt);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function recordDiversityHunterResult(
|
|
251
|
+
ledger: DiversityLedger,
|
|
252
|
+
plan: DiversityPlan,
|
|
253
|
+
agent: AgentSpec,
|
|
254
|
+
result: StepResult,
|
|
255
|
+
leg?: DiversityLeg,
|
|
256
|
+
executedRoute?: ResolvedModelRoute,
|
|
257
|
+
): DiversityLedger {
|
|
258
|
+
const resolvedLeg = leg ?? legForAgent(plan, agent);
|
|
259
|
+
if (!resolvedLeg) {
|
|
260
|
+
throw new DiversityAdmissionError(
|
|
261
|
+
`no diversity leg for hunter ${agent.key}`,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
const totalAttempts = Math.max(1, result.attempts);
|
|
265
|
+
const usage = usageFromStep(result);
|
|
266
|
+
const perAttemptUsage =
|
|
267
|
+
totalAttempts === 1
|
|
268
|
+
? [usage]
|
|
269
|
+
: Array.from({ length: totalAttempts }, (_, _index) =>
|
|
270
|
+
scaleUsageFraction(usage, 1 / totalAttempts),
|
|
271
|
+
);
|
|
272
|
+
let next = ledger;
|
|
273
|
+
for (let attemptNum = 1; attemptNum <= totalAttempts; attemptNum++) {
|
|
274
|
+
const attemptUsage = perAttemptUsage[attemptNum - 1] ?? usage;
|
|
275
|
+
const isTerminal = attemptNum === totalAttempts;
|
|
276
|
+
const attemptId = `${resolvedLeg.legId}-a${attemptNum}`;
|
|
277
|
+
const attempt: DiversityAttemptRecord = {
|
|
278
|
+
attemptId,
|
|
279
|
+
legId: resolvedLeg.legId,
|
|
280
|
+
armId: plan.armId,
|
|
281
|
+
specialty: resolveSpecialty(agent),
|
|
282
|
+
replicate: 1,
|
|
283
|
+
attempt: attemptNum,
|
|
284
|
+
status: !isTerminal
|
|
285
|
+
? "retry"
|
|
286
|
+
: result.status === "ok"
|
|
287
|
+
? "completed"
|
|
288
|
+
: "failed",
|
|
289
|
+
usage: attemptUsage,
|
|
290
|
+
};
|
|
291
|
+
next = appendAttempt(next, attempt);
|
|
292
|
+
}
|
|
293
|
+
if (result.status !== "ok") return next;
|
|
294
|
+
const terminalAttemptId = `${resolvedLeg.legId}-a${totalAttempts}`;
|
|
295
|
+
const routeProvenance: ResolvedModelRoute = executedRoute ?? {
|
|
296
|
+
backend: "claude-code",
|
|
297
|
+
provider: "anthropic",
|
|
298
|
+
modelFamily: resolvedLeg.model.split("/")[0] ?? "unknown",
|
|
299
|
+
modelSnapshot: resolvedLeg.model,
|
|
300
|
+
};
|
|
301
|
+
const output = result.output as { findings?: DraftFinding[] } | undefined;
|
|
302
|
+
const findings = output?.findings ?? [];
|
|
303
|
+
for (const [index, finding] of findings.entries()) {
|
|
304
|
+
const observation: FindingObservation = {
|
|
305
|
+
observationId: `${terminalAttemptId}-o${index + 1}`,
|
|
306
|
+
specialty: resolveSpecialty(agent),
|
|
307
|
+
legId: resolvedLeg.legId,
|
|
308
|
+
backend: routeProvenance.backend,
|
|
309
|
+
provider: routeProvenance.provider,
|
|
310
|
+
...(routeProvenance.gateway === undefined
|
|
311
|
+
? {}
|
|
312
|
+
: { gateway: routeProvenance.gateway }),
|
|
313
|
+
modelFamily: routeProvenance.modelFamily,
|
|
314
|
+
modelSnapshot: routeProvenance.modelSnapshot,
|
|
315
|
+
...(routeProvenance.modelVariant === undefined
|
|
316
|
+
? {}
|
|
317
|
+
: { modelVariant: routeProvenance.modelVariant }),
|
|
318
|
+
replicate: 1,
|
|
319
|
+
attempt: totalAttempts,
|
|
320
|
+
promptFingerprint: plan.promptFingerprint ?? "unknown",
|
|
321
|
+
routeFingerprint: resolvedLeg.routeFingerprint,
|
|
322
|
+
path: finding.path,
|
|
323
|
+
line: finding.line,
|
|
324
|
+
symbol: finding.symbol,
|
|
325
|
+
category: finding.category,
|
|
326
|
+
severity: finding.severity,
|
|
327
|
+
claim: finding.claim,
|
|
328
|
+
evidence: finding.proof_refs.join(";"),
|
|
329
|
+
proofRefs: finding.proof_refs,
|
|
330
|
+
causalHypothesis: finding.claim,
|
|
331
|
+
artifactSha256: finding.dedupe_key,
|
|
332
|
+
};
|
|
333
|
+
next = appendObservation(next, {
|
|
334
|
+
observation,
|
|
335
|
+
attemptId: terminalAttemptId,
|
|
336
|
+
legId: resolvedLeg.legId,
|
|
337
|
+
armId: plan.armId,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return next;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function projectDiversityDrafts(ctx: DiversityExecutionContext): {
|
|
344
|
+
drafts: DraftFinding[];
|
|
345
|
+
partial: boolean;
|
|
346
|
+
} {
|
|
347
|
+
if (!ctx.enabled || !ctx.plan) {
|
|
348
|
+
return { drafts: [], partial: false };
|
|
349
|
+
}
|
|
350
|
+
const observations = ctx.ledger.observations.map(
|
|
351
|
+
(record) => record.observation,
|
|
352
|
+
);
|
|
353
|
+
let partial = ctx.ledger.failures.length > 0;
|
|
354
|
+
if (observations.length === 0) {
|
|
355
|
+
return { drafts: [], partial };
|
|
356
|
+
}
|
|
357
|
+
const groups = buildAdjudicationGroups(observations);
|
|
358
|
+
const drafts: DraftFinding[] = [];
|
|
359
|
+
for (const group of groups) {
|
|
360
|
+
if (group.ambiguous) {
|
|
361
|
+
partial = true;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const adjudication = synthesizeDeterministicAdjudication(group);
|
|
365
|
+
if (!adjudication || adjudication.relation === "inconclusive") {
|
|
366
|
+
partial = true;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
const specialty =
|
|
370
|
+
group.clusters[0]?.observations[0]?.specialty ?? "unknown";
|
|
371
|
+
const projected = projectAdjudicationToFindings(adjudication, specialty);
|
|
372
|
+
partial = partial || projected.partial;
|
|
373
|
+
for (const finding of projected.findings) {
|
|
374
|
+
const { tier: _tier, refuter_verdict: _verdict, ...draft } = finding;
|
|
375
|
+
drafts.push(draft as DraftFinding);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return { drafts, partial };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export function buildDiversityPipelineRecord(
|
|
382
|
+
ctx: DiversityExecutionContext,
|
|
383
|
+
partial: boolean,
|
|
384
|
+
): DiversityPipelineRecord | undefined {
|
|
385
|
+
if (!ctx.enabled) {
|
|
386
|
+
return { enabled: false, status: "skipped" };
|
|
387
|
+
}
|
|
388
|
+
if (!ctx.plan) {
|
|
389
|
+
return { enabled: true, status: "failed" };
|
|
390
|
+
}
|
|
391
|
+
const totals = ctx.ledger.attempts.reduce(
|
|
392
|
+
(acc, attempt) => ({
|
|
393
|
+
cash: acc.cash + (attempt.usage.cashCostUsd ?? 0),
|
|
394
|
+
notional: acc.notional + (attempt.usage.notionalCostUsd ?? 0),
|
|
395
|
+
}),
|
|
396
|
+
{ cash: 0, notional: 0 },
|
|
397
|
+
);
|
|
398
|
+
return {
|
|
399
|
+
enabled: true,
|
|
400
|
+
status: partial ? "partial" : "ok",
|
|
401
|
+
armId: ctx.plan.armId,
|
|
402
|
+
planFingerprint: ctx.plan.planFingerprint,
|
|
403
|
+
legCount: ctx.plan.legs.length,
|
|
404
|
+
attemptCount: ctx.ledger.attempts.length,
|
|
405
|
+
observationCount: ctx.ledger.observations.length,
|
|
406
|
+
failureCount: ctx.ledger.failures.length,
|
|
407
|
+
cashCostUsd: totals.cash,
|
|
408
|
+
notionalCostUsd: totals.notional,
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export function diversityDebugFromLedger(
|
|
413
|
+
ctx: DiversityExecutionContext,
|
|
414
|
+
): Record<string, unknown> | undefined {
|
|
415
|
+
if (!ctx.enabled || !ctx.plan) return undefined;
|
|
416
|
+
return {
|
|
417
|
+
planFingerprint: ctx.plan.planFingerprint,
|
|
418
|
+
attempts: ctx.ledger.attempts.map((attempt) => ({
|
|
419
|
+
attemptId: attempt.attemptId,
|
|
420
|
+
legId: attempt.legId,
|
|
421
|
+
armId: attempt.armId,
|
|
422
|
+
specialty: attempt.specialty,
|
|
423
|
+
replicate: attempt.replicate,
|
|
424
|
+
attempt: attempt.attempt,
|
|
425
|
+
status: attempt.status,
|
|
426
|
+
cashCostUsd: attempt.usage.cashCostUsd ?? null,
|
|
427
|
+
notionalCostUsd: attempt.usage.notionalCostUsd ?? null,
|
|
428
|
+
})),
|
|
429
|
+
observations: ctx.ledger.observations.map((record) => ({
|
|
430
|
+
observationId: record.observation.observationId,
|
|
431
|
+
attemptId: record.attemptId,
|
|
432
|
+
legId: record.legId,
|
|
433
|
+
armId: record.armId,
|
|
434
|
+
specialty: record.observation.specialty,
|
|
435
|
+
path: record.observation.path,
|
|
436
|
+
backend: record.observation.backend,
|
|
437
|
+
provider: record.observation.provider,
|
|
438
|
+
...(record.observation.gateway === undefined
|
|
439
|
+
? {}
|
|
440
|
+
: { gateway: record.observation.gateway }),
|
|
441
|
+
modelFamily: record.observation.modelFamily,
|
|
442
|
+
modelSnapshot: record.observation.modelSnapshot,
|
|
443
|
+
...(record.observation.modelVariant === undefined
|
|
444
|
+
? {}
|
|
445
|
+
: { modelVariant: record.observation.modelVariant }),
|
|
446
|
+
})),
|
|
447
|
+
};
|
|
448
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Finding } from "#review/findings";
|
|
2
|
+
import { deriveTier } from "#review/findings";
|
|
3
|
+
import type { ClusterAdjudication } from "./adjudication";
|
|
4
|
+
|
|
5
|
+
export function projectAdjudicationToFindings(
|
|
6
|
+
adjudication: ClusterAdjudication,
|
|
7
|
+
specialty: string,
|
|
8
|
+
startingId = 1,
|
|
9
|
+
): { findings: Finding[]; partial: boolean } {
|
|
10
|
+
if (
|
|
11
|
+
adjudication.relation === "no_defect" ||
|
|
12
|
+
adjudication.relation === "inconclusive"
|
|
13
|
+
) {
|
|
14
|
+
return { findings: [], partial: adjudication.relation === "inconclusive" };
|
|
15
|
+
}
|
|
16
|
+
const findings: Finding[] = [];
|
|
17
|
+
let id = startingId;
|
|
18
|
+
for (const canonical of adjudication.canonicalFindings) {
|
|
19
|
+
const refuterVerdict: Finding["refuter_verdict"] =
|
|
20
|
+
adjudication.relation === "same_defect" ? "corroborated" : "corroborated";
|
|
21
|
+
const finding: Finding = {
|
|
22
|
+
id: `F${String(id).padStart(3, "0")}`,
|
|
23
|
+
category: canonical.category,
|
|
24
|
+
path: canonical.path,
|
|
25
|
+
line: canonical.line ?? 1,
|
|
26
|
+
symbol: canonical.symbol,
|
|
27
|
+
severity: canonical.severity,
|
|
28
|
+
evidence_class: canonical.evidenceClass,
|
|
29
|
+
refuter_verdict: refuterVerdict,
|
|
30
|
+
causal_disposition: canonical.causalDisposition,
|
|
31
|
+
claim: canonical.claim,
|
|
32
|
+
proof_refs: [...canonical.proofRefs],
|
|
33
|
+
hunter: specialty,
|
|
34
|
+
tier: deriveTier({
|
|
35
|
+
severity: canonical.severity,
|
|
36
|
+
evidence_class: canonical.evidenceClass,
|
|
37
|
+
refuter_verdict: refuterVerdict,
|
|
38
|
+
}),
|
|
39
|
+
hops_used: canonical.hopsUsed,
|
|
40
|
+
hop_trail: canonical.hopTrail,
|
|
41
|
+
dedupe_key: `${canonical.path}:${canonical.symbol ?? ""}:${canonical.category}`,
|
|
42
|
+
};
|
|
43
|
+
findings.push(finding);
|
|
44
|
+
id++;
|
|
45
|
+
}
|
|
46
|
+
return { findings, partial: false };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function stableProjectionOrder(findings: Finding[]): Finding[] {
|
|
50
|
+
return [...findings].sort((a, b) => {
|
|
51
|
+
const path = a.path.localeCompare(b.path);
|
|
52
|
+
if (path !== 0) return path;
|
|
53
|
+
const line = a.line - b.line;
|
|
54
|
+
if (line !== 0) return line;
|
|
55
|
+
return a.id.localeCompare(b.id);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
const FORBIDDEN_IMPORT_PATTERNS = [
|
|
5
|
+
/from\s+["']\.\.\/deep-review/,
|
|
6
|
+
/from\s+["']deep-review/,
|
|
7
|
+
/require\(["']\.\.\/deep-review/,
|
|
8
|
+
/require\(["']deep-review/,
|
|
9
|
+
/file:\.\.\/\.\.\/deep-review/,
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
const FORBIDDEN_ABSOLUTE_LAB =
|
|
13
|
+
/(?:^|["'`])\/(?:Users\/[^"'`]+|tmp\/[^"'`]+)?deep-review\//;
|
|
14
|
+
|
|
15
|
+
export interface SelfContainedReport {
|
|
16
|
+
readonly ok: boolean;
|
|
17
|
+
readonly violations: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function collectTsFiles(root: string): string[] {
|
|
21
|
+
const files: string[] = [];
|
|
22
|
+
for (const entry of readdirSync(root)) {
|
|
23
|
+
const full = path.join(root, entry);
|
|
24
|
+
const stat = statSync(full);
|
|
25
|
+
if (stat.isDirectory()) {
|
|
26
|
+
files.push(...collectTsFiles(full));
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (entry.endsWith(".ts")) files.push(full);
|
|
30
|
+
}
|
|
31
|
+
return files;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// A lint over the diversity SOURCE TREE, not a runtime capability: it reads
|
|
35
|
+
// src/diversity/**/*.ts off disk and rejects sibling-lab imports. That has
|
|
36
|
+
// meaning only against a real checkout, so the root is a REQUIRED argument
|
|
37
|
+
// and the only caller (test/diversity/self-contained.test.ts) supplies it.
|
|
38
|
+
// It used to default to `path.join(import.meta.dir)`, which is /$bunfs/root
|
|
39
|
+
// in a compiled binary — a virtual path readdirSync cannot walk. That is the
|
|
40
|
+
// exact defect class test/packaging.test.ts pins, and the pin caught this on
|
|
41
|
+
// arrival; see test/architecture/import-boundaries.test.ts for the same
|
|
42
|
+
// source-tree lint deriving its root from the TEST's location instead.
|
|
43
|
+
export function assertDiversityGraphSelfContained(
|
|
44
|
+
diversityRoot: string,
|
|
45
|
+
): SelfContainedReport {
|
|
46
|
+
const violations: string[] = [];
|
|
47
|
+
for (const file of collectTsFiles(diversityRoot)) {
|
|
48
|
+
const content = readFileSync(file, "utf8");
|
|
49
|
+
for (const pattern of FORBIDDEN_IMPORT_PATTERNS) {
|
|
50
|
+
if (pattern.test(content)) {
|
|
51
|
+
violations.push(`${path.basename(file)}: forbidden import ${pattern}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (FORBIDDEN_ABSOLUTE_LAB.test(content)) {
|
|
55
|
+
violations.push(`${path.basename(file)}: absolute lab path reference`);
|
|
56
|
+
}
|
|
57
|
+
for (const match of content.matchAll(/from\s+["']([^"']+)["']/g)) {
|
|
58
|
+
const specifier = match[1];
|
|
59
|
+
if (
|
|
60
|
+
specifier.startsWith("../deep-review") ||
|
|
61
|
+
specifier.includes("deep-review/")
|
|
62
|
+
) {
|
|
63
|
+
violations.push(`${path.basename(file)}: sibling import ${specifier}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return { ok: violations.length === 0, violations };
|
|
68
|
+
}
|