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,177 @@
|
|
|
1
|
+
// Prompt-set loading, ported from deep-review runner/session.ts. In v1 these
|
|
2
|
+
// files were assembled into an inline `--agents` registry for the orchestrator
|
|
3
|
+
// session's Task tool; in v2 each agent body IS a step's system prompt, so the
|
|
4
|
+
// frontmatter parsing survives while the JSON registry assembly is gone — and
|
|
5
|
+
// the {{PRIORS}}/{{GOTCHAS}} templating the orchestrator prose used to do at
|
|
6
|
+
// spawn time moves into the driver (renderAgentBody).
|
|
7
|
+
|
|
8
|
+
import { EFFORT_LEVELS, type Effort, isEffort } from "#model/catalog";
|
|
9
|
+
import { wrapBlock } from "./boundary";
|
|
10
|
+
|
|
11
|
+
// Fixed order — the lab's promptSetFingerprint hashes the concatenated files
|
|
12
|
+
// in exactly this sequence, so reordering here would silently move every
|
|
13
|
+
// recorded fingerprint. The names are the file basenames inside a prompt-set
|
|
14
|
+
// directory (`agents/<set>/<name>.md`).
|
|
15
|
+
export const AGENT_NAMES = [
|
|
16
|
+
"deep-review-reliability",
|
|
17
|
+
"deep-review-resilience",
|
|
18
|
+
"deep-review-parity",
|
|
19
|
+
"review-refuter",
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
export interface ParsedAgent {
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
tools: string[];
|
|
26
|
+
model?: string;
|
|
27
|
+
// Optional `effort:` key. Absent means "use the engine's per-role default"
|
|
28
|
+
// (defaultEffortForRole), never "use the CLI's implicit one".
|
|
29
|
+
effort?: Effort;
|
|
30
|
+
// Everything below the frontmatter block — the step's system prompt.
|
|
31
|
+
body: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Same minimal frontmatter grammar as v1: a leading `---` block with
|
|
35
|
+
// single-line `key: value` fields. Deliberately not a YAML parser — the agent
|
|
36
|
+
// files are ours, and a stricter grammar keeps a malformed set failing loudly
|
|
37
|
+
// instead of half-parsing.
|
|
38
|
+
export function parseAgentSource(raw: string): ParsedAgent {
|
|
39
|
+
const match = raw.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
40
|
+
if (!match?.[1] || match[2] === undefined) {
|
|
41
|
+
throw new Error("agent file has no frontmatter block");
|
|
42
|
+
}
|
|
43
|
+
const [, frontmatter, body] = match;
|
|
44
|
+
const field = (key: string): string | undefined => {
|
|
45
|
+
const line = frontmatter.split("\n").find((l) => l.startsWith(`${key}:`));
|
|
46
|
+
return line
|
|
47
|
+
?.slice(key.length + 1)
|
|
48
|
+
.trim()
|
|
49
|
+
.replace(/^"|"$/g, "");
|
|
50
|
+
};
|
|
51
|
+
const name = field("name");
|
|
52
|
+
if (!name) throw new Error("agent file has no name field");
|
|
53
|
+
const tools = field("tools");
|
|
54
|
+
const model = field("model");
|
|
55
|
+
const effort = field("effort");
|
|
56
|
+
// Present-but-empty is malformed, not an omission (unlike `model:`): an
|
|
57
|
+
// `effort:` line is someone choosing a level, and silently dropping it would
|
|
58
|
+
// put the step on the engine default while the file reads as overridden.
|
|
59
|
+
if (effort !== undefined && !isEffort(effort)) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`agent file declares effort "${effort}"; expected one of ${EFFORT_LEVELS.join(", ")}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
name,
|
|
66
|
+
description: field("description") ?? name,
|
|
67
|
+
tools: tools ? tools.split(",").map((t) => t.trim()) : [],
|
|
68
|
+
...(model ? { model } : {}),
|
|
69
|
+
...(effort === undefined ? {} : { effort }),
|
|
70
|
+
body: body.trim(),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function parseAgentFile(filePath: string): Promise<ParsedAgent> {
|
|
75
|
+
const raw = await Bun.file(filePath).text();
|
|
76
|
+
try {
|
|
77
|
+
return parseAgentSource(raw);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
// parseAgentSource sees bytes, not a path, so the file is named here: a
|
|
80
|
+
// preflight failure that does not say WHICH of six prompt files is wrong
|
|
81
|
+
// sends the reader grepping.
|
|
82
|
+
throw new Error(
|
|
83
|
+
`${filePath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface SuspicionPrior {
|
|
89
|
+
path: string;
|
|
90
|
+
// The live config carries prose weights ("maximum", "high"), not numbers;
|
|
91
|
+
// rendering only interpolates, so both pass through untouched.
|
|
92
|
+
weight: number | string;
|
|
93
|
+
reason: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Exported because the driver needs the SAME bytes twice: once here, to fill
|
|
97
|
+
// the {{PRIORS}} anchor, and once at nonce-selection time, to prove the run's
|
|
98
|
+
// boundary nonce does not already occur inside the block it is about to wrap
|
|
99
|
+
// (C4 O-3.3). Rendering priors twice with two spellings would let the check
|
|
100
|
+
// pass on a string the prompt never carries.
|
|
101
|
+
export function renderPriorsBlock(priors: SuspicionPrior[]): string {
|
|
102
|
+
return priors
|
|
103
|
+
.map((p) => `- ${p.path} (weight ${p.weight}): ${p.reason}`)
|
|
104
|
+
.join("\n");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Prose Step 4's two dynamic sections, now driver-side: {{PRIORS}} becomes a
|
|
108
|
+
// bullet list of the config's suspicion_priors, {{GOTCHAS}} the verbatim
|
|
109
|
+
// gotchas content — placed wherever the agent body anchors them (the baseline
|
|
110
|
+
// bodies put gotchas ahead of the diff, per the spec's injection requirement).
|
|
111
|
+
//
|
|
112
|
+
// Both land inside C4 boundary tags. Not because the operator is a threat —
|
|
113
|
+
// they are not — but because a uniform rule is enforceable and a rule with
|
|
114
|
+
// exceptions is a rule someone forgets (§3.4). `nonce` is REQUIRED, so a future
|
|
115
|
+
// caller cannot reach this substitution without one.
|
|
116
|
+
export function renderAgentBody(
|
|
117
|
+
body: string,
|
|
118
|
+
context: { priors: SuspicionPrior[]; gotchas: string; nonce: string },
|
|
119
|
+
): string {
|
|
120
|
+
return body
|
|
121
|
+
.replaceAll(
|
|
122
|
+
"{{PRIORS}}",
|
|
123
|
+
wrapBlock("priors", context.nonce, renderPriorsBlock(context.priors)),
|
|
124
|
+
)
|
|
125
|
+
.replaceAll(
|
|
126
|
+
"{{GOTCHAS}}",
|
|
127
|
+
wrapBlock("gotchas", context.nonce, context.gotchas),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// The prompt set's identity, and the reason it exists is M6's central claim:
|
|
132
|
+
// "both arms ran the same prompt set" must be RECORDED, not believed. Ported
|
|
133
|
+
// byte-for-byte from the lab's `promptSetFingerprint` (deep-review
|
|
134
|
+
// runner/session.ts) — sha256 over the concatenated file TEXTS in the order
|
|
135
|
+
// given, truncated to 16 hex — so a fingerprint computed here and one computed
|
|
136
|
+
// there are the same string for the same bytes. Changing the algorithm, the
|
|
137
|
+
// truncation length, or the file order silently moves every fingerprint ever
|
|
138
|
+
// recorded on either side, which is why neither is a free choice.
|
|
139
|
+
//
|
|
140
|
+
// Order comes from the caller (the ReviewSpec's declaration order), never from
|
|
141
|
+
// a directory listing: same files, different order = different concatenation =
|
|
142
|
+
// different hash.
|
|
143
|
+
export async function promptSetFingerprint(files: string[]): Promise<string> {
|
|
144
|
+
const hasher = new Bun.CryptoHasher("sha256");
|
|
145
|
+
for (const file of files) {
|
|
146
|
+
hasher.update(await Bun.file(file).text());
|
|
147
|
+
}
|
|
148
|
+
return hasher.digest("hex").slice(0, 16);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface PromptSetIdentity {
|
|
152
|
+
name: string;
|
|
153
|
+
sha256: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// `name` is the agents DIRECTORY basename, which is what the lab's `arm-a` /
|
|
157
|
+
// `baseline` set names have always meant — two runs can share a fingerprint
|
|
158
|
+
// and differ in nothing else, so the name is a label and the sha is the fact.
|
|
159
|
+
//
|
|
160
|
+
// `name` overrides that derivation, and the compiled binary is why: its
|
|
161
|
+
// bundled set has no directory at all (the prompts are embedded at hashed,
|
|
162
|
+
// flattened paths, and `agentsDir` is a display label there). It must still
|
|
163
|
+
// report "default" — byte-identical to what dev and npm derive from
|
|
164
|
+
// `prompts/default` — or one prompt set would name itself three ways and every
|
|
165
|
+
// cross-run comparison of `prompt_set` would split into three rows. Passed
|
|
166
|
+
// explicitly rather than string-munged out of the label, because a label is
|
|
167
|
+
// prose and prose gets edited.
|
|
168
|
+
export async function promptSetIdentity(
|
|
169
|
+
agentsDir: string,
|
|
170
|
+
files: string[],
|
|
171
|
+
name?: string,
|
|
172
|
+
): Promise<PromptSetIdentity> {
|
|
173
|
+
return {
|
|
174
|
+
name: name ?? agentsDir.replace(/\/+$/, "").split("/").pop() ?? agentsDir,
|
|
175
|
+
sha256: await promptSetFingerprint(files),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Resolvability of a finding's evidence, as a pure decision.
|
|
2
|
+
//
|
|
3
|
+
// `proof_refs` is what makes a verdict auditable, and until #152 nothing
|
|
4
|
+
// checked that the paths it names exist. A refuter returned
|
|
5
|
+
// `["src/index.ts:7-20", "package.json:15-20"]` against a three-file repo
|
|
6
|
+
// containing neither — with `read/grep/glob` all available, so not a tool
|
|
7
|
+
// failure — and that citation sailed through schema validation, dedupe, tier
|
|
8
|
+
// derivation and the renderer to reach a human looking exactly like a verified
|
|
9
|
+
// one. Evidence that cannot be resolved is not weaker evidence; it is NO
|
|
10
|
+
// evidence wearing the shape of some.
|
|
11
|
+
//
|
|
12
|
+
// THE RULE, and the reason it is narrower than "every ref must resolve":
|
|
13
|
+
//
|
|
14
|
+
// Only accuse what can be checked. A ref is judged ONLY when it asserts a
|
|
15
|
+
// repo path; anything else is unverifiable, and unverifiable is not the same
|
|
16
|
+
// as false.
|
|
17
|
+
//
|
|
18
|
+
// That distinction was bought with a failed fixture eval, not reasoned into
|
|
19
|
+
// existence. On the first live run under the strict rule a hunter found the
|
|
20
|
+
// planted defect perfectly, cited four real `path:line` refs — and added a
|
|
21
|
+
// fifth quoting the gotcha it had been handed:
|
|
22
|
+
//
|
|
23
|
+
// "gotcha: Volume values are 0-1 gain fractions everywhere in this codebase"
|
|
24
|
+
//
|
|
25
|
+
// The strict rule called that fabrication, rejected the draft, burned the
|
|
26
|
+
// retry and lost BOTH hunters: a correct finding destroyed over a citation
|
|
27
|
+
// style the prompts never forbade. Prose, gotcha quotes and hunk labels are
|
|
28
|
+
// now out of scope; `src/index.ts:7-20` — #152's own case — still is not.
|
|
29
|
+
//
|
|
30
|
+
// This module is the pure half on purpose: it never touches the filesystem.
|
|
31
|
+
// The reviewed tree arrives as an injected predicate, which keeps review/drafts.ts
|
|
32
|
+
// pure, keeps the offline suite offline, and makes every rule below testable
|
|
33
|
+
// without a repo.
|
|
34
|
+
|
|
35
|
+
const ESCAPING_SEGMENT = "..";
|
|
36
|
+
|
|
37
|
+
// The path spellings a ref could mean, or `undefined` when the ref asserts no
|
|
38
|
+
// checkable repo path at all. `undefined` is the ABSTENTION, and it is load
|
|
39
|
+
// bearing: it is what separates "the tree says this is false" from "there is
|
|
40
|
+
// nothing here to check", and only the former may fail a step.
|
|
41
|
+
export function proofRefPathClaim(ref: string): string[] | undefined {
|
|
42
|
+
const trimmed = ref.trim();
|
|
43
|
+
if (trimmed.length === 0) return undefined;
|
|
44
|
+
// Everything before the FIRST colon. `src/a.ts:12-20` and
|
|
45
|
+
// `src/a.ts:12 (the guard)` both reduce to the same path, and a line range
|
|
46
|
+
// is deliberately not checked here — path existence is the cheap,
|
|
47
|
+
// high-value first cut (#152); a range past EOF is the harder half.
|
|
48
|
+
const colon = trimmed.indexOf(":");
|
|
49
|
+
const raw = (colon === -1 ? trimmed : trimmed.slice(0, colon)).trim();
|
|
50
|
+
const normalized = raw.replace(/^\.\//, "");
|
|
51
|
+
if (normalized.length === 0) return undefined;
|
|
52
|
+
// Whitespace inside the path part means the ref is a sentence, not a
|
|
53
|
+
// citation — "the guard in src/player.ts is missing" names a file without
|
|
54
|
+
// claiming to BE one, and a reviewer accusing it of fabrication is wrong.
|
|
55
|
+
if (/\s/.test(normalized)) return undefined;
|
|
56
|
+
// Absolute, home-relative and escaping refs are abstentions rather than
|
|
57
|
+
// failures: "does the reviewed tree contain this" has no answer for a path
|
|
58
|
+
// outside it, and the resolver must never be handed one. An absolute path
|
|
59
|
+
// to a file that really does exist is a spelling problem, not a lie, and
|
|
60
|
+
// burning a whole draft over spelling is what the fixture eval punished.
|
|
61
|
+
if (normalized.startsWith("/") || normalized.startsWith("~"))
|
|
62
|
+
return undefined;
|
|
63
|
+
if (normalized.split("/").includes(ESCAPING_SEGMENT)) return undefined;
|
|
64
|
+
// What makes this a PATH claim rather than prose: a directory separator or
|
|
65
|
+
// a file extension. `gotcha` and `diff-hunk#1` have neither and are left
|
|
66
|
+
// alone.
|
|
67
|
+
//
|
|
68
|
+
// A `:<digits>` suffix is deliberately NOT a third trigger, though the
|
|
69
|
+
// `path:line` form the prompts mandate has one. It was, and it made
|
|
70
|
+
// `Makefile:12` checkable at the cost of also claiming `line:42`,
|
|
71
|
+
// `confidence:80` and `hunk:3` — plausible things for a model to write
|
|
72
|
+
// beside a real citation, each one enough to reject the whole draft. The two
|
|
73
|
+
// shapes are SYNTACTICALLY INDISTINGUISHABLE, so no sharper regex separates
|
|
74
|
+
// them; for a bareword, "the tree does not have it" is ambiguous between
|
|
75
|
+
// "invented file" and "not a file at all", and a rule that cannot tell those
|
|
76
|
+
// apart has no business accusing either. Abstaining loses the ability to
|
|
77
|
+
// catch a fabricated `Makefile:12`, which is the cheaper half of the trade.
|
|
78
|
+
const looksLikePath = normalized.includes("/") || normalized.includes(".");
|
|
79
|
+
if (!looksLikePath) return undefined;
|
|
80
|
+
const candidates = [normalized];
|
|
81
|
+
// `a/` and `b/` are git diff notation a model copies out of the patch — and
|
|
82
|
+
// `a/` is also a perfectly legal directory name. Offering BOTH spellings
|
|
83
|
+
// lets the tree decide instead of this parser guessing, so a repo with a
|
|
84
|
+
// real top-level `a/` is never rejected for a spelling it owns.
|
|
85
|
+
const stripped = normalized.replace(/^[ab]\//, "");
|
|
86
|
+
if (stripped !== normalized && stripped.length > 0) candidates.push(stripped);
|
|
87
|
+
return candidates;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Every path the patch names, both sides. A file the PR deletes is gone from
|
|
91
|
+
// the worktree yet fully readable in the diff, so a hunter can cite it
|
|
92
|
+
// honestly; the same holds for the `rename from` side. Treating those as
|
|
93
|
+
// fabrication would be a false accusation, so the reviewed target is the
|
|
94
|
+
// worktree AND the patch.
|
|
95
|
+
//
|
|
96
|
+
// Deliberately NOT `changedPathsFromDiff` (review/pipeline.ts), which skips
|
|
97
|
+
// deletions on purpose: that function answers "what changed, for trigger
|
|
98
|
+
// evaluation", and a deleted file cannot trigger a parity hunter. This one
|
|
99
|
+
// answers "what was citable", which is a different question with a different
|
|
100
|
+
// right answer.
|
|
101
|
+
export function pathsNamedInDiff(patch: string): Set<string> {
|
|
102
|
+
const named = new Set<string>();
|
|
103
|
+
for (const line of patch.split("\n")) {
|
|
104
|
+
// The `diff --git` header is the ONLY line every file gets. A binary file
|
|
105
|
+
// has no `---`/`+++` pair at all — git writes
|
|
106
|
+
// `Binary files a/logo.png and /dev/null differ` instead — so without this
|
|
107
|
+
// a deleted binary is absent from the set AND gone from disk, and citing
|
|
108
|
+
// it is called fabrication. Verified against real `git diff` output, not
|
|
109
|
+
// assumed.
|
|
110
|
+
if (line.startsWith(DIFF_HEADER)) {
|
|
111
|
+
addHeaderPaths(line.slice(DIFF_HEADER.length), named);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
let candidate: string | undefined;
|
|
115
|
+
// The quote is optional because git wraps any path containing a space:
|
|
116
|
+
// `--- "a/we ird.ts"`. Matching only the bare spelling left every such
|
|
117
|
+
// file out of an ALLOWLIST, which is the direction that costs findings.
|
|
118
|
+
for (const [prefix, strip] of SIDE_PREFIXES) {
|
|
119
|
+
if (!line.startsWith(prefix)) continue;
|
|
120
|
+
candidate = unwrapPath(line.slice(prefix.length), strip);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
if (candidate === undefined) continue;
|
|
124
|
+
if (candidate.length === 0 || candidate === "/dev/null") continue;
|
|
125
|
+
named.add(candidate);
|
|
126
|
+
}
|
|
127
|
+
return named;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const DIFF_HEADER = "diff --git ";
|
|
131
|
+
|
|
132
|
+
// Prefix → whether an `a/`/`b/` side marker follows it. `rename to`/`from`
|
|
133
|
+
// carry the bare path; the `---`/`+++` pair carries the side marker, either
|
|
134
|
+
// spelling of it.
|
|
135
|
+
const SIDE_PREFIXES: ReadonlyArray<readonly [string, boolean]> = [
|
|
136
|
+
["+++ ", true],
|
|
137
|
+
["--- ", true],
|
|
138
|
+
["rename to ", false],
|
|
139
|
+
["rename from ", false],
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
function unwrapPath(raw: string, stripSideMarker: boolean): string {
|
|
143
|
+
const trimmed = raw.trim().replace(/^"/, "").replace(/"$/, "");
|
|
144
|
+
return stripSideMarker ? trimmed.replace(/^[ab]\//, "") : trimmed;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// `a/<old> b/<new>`, unpicked leniently ON PURPOSE. A path containing " b/"
|
|
148
|
+
// makes the split ambiguous and git quotes any path with spaces, so rather
|
|
149
|
+
// than parse git's quoting rules this adds EVERY plausible split: `named` is
|
|
150
|
+
// an ALLOWLIST, so an extra entry can only make the rule abstain more, while a
|
|
151
|
+
// missing one is what produces a false accusation. The asymmetry is the whole
|
|
152
|
+
// design — over-inclusion costs a citation nobody checks, under-inclusion
|
|
153
|
+
// costs a correct finding and its whole draft.
|
|
154
|
+
function addHeaderPaths(rest: string, named: Set<string>): void {
|
|
155
|
+
// Both spellings of the right-hand side marker: ` b/` bare, ` "b/` quoted.
|
|
156
|
+
for (const marker of [' "b/', " b/"]) {
|
|
157
|
+
for (
|
|
158
|
+
let i = rest.indexOf(marker);
|
|
159
|
+
i !== -1;
|
|
160
|
+
i = rest.indexOf(marker, i + 1)
|
|
161
|
+
) {
|
|
162
|
+
for (const half of [rest.slice(0, i), rest.slice(i + 1)]) {
|
|
163
|
+
const unwrapped = unwrapPath(half, true);
|
|
164
|
+
if (unwrapped.length > 0 && unwrapped !== "/dev/null") {
|
|
165
|
+
named.add(unwrapped);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// The refs that assert a repo path the tree does not have, returned as the
|
|
173
|
+
// model's ORIGINAL text — a reader has to see which citation was the invented
|
|
174
|
+
// one, and the parsed path is not what the model wrote. A ref that asserts no
|
|
175
|
+
// path is absent from this list: it was never judged.
|
|
176
|
+
export function unresolvedProofRefs(
|
|
177
|
+
refs: readonly string[],
|
|
178
|
+
resolves: (path: string) => boolean,
|
|
179
|
+
): string[] {
|
|
180
|
+
const unresolved: string[] = [];
|
|
181
|
+
for (const ref of refs) {
|
|
182
|
+
const claim = proofRefPathClaim(ref);
|
|
183
|
+
if (claim === undefined) continue;
|
|
184
|
+
if (!claim.some((candidate) => resolves(candidate))) unresolved.push(ref);
|
|
185
|
+
}
|
|
186
|
+
return unresolved;
|
|
187
|
+
}
|