codecartographer-pi 0.23.0 → 0.24.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.
@@ -26,7 +26,21 @@ not replace any phase; it tells phases where to look.
26
26
 
27
27
  ## Reading a Broad-Side run
28
28
 
29
- 1. Read `synthesis.md` first. It carries the executive summary, severity counts,
29
+ 0. If `verified.md` exists, read it first. A verification pass
30
+ (`codecarto_broadside {action: "verify"}`, `/codecarto-broadside verify`)
31
+ has read the top defect and security findings against the real source with
32
+ read-only tools and given each a verdict: **confirmed** (a reachable
33
+ failure, with the input or call site that triggers it), **not-a-defect**
34
+ (the claim is literally true of the code but nothing can reach the failure
35
+ it describes), **discarded** (the claim is wrong about the code, with the
36
+ guard or line that shows it), or **unclear**. Start from the confirmed
37
+ ones; treat a discarded one as answered unless the reasoning is thin.
38
+ Measured on this repository, the top twelve findings by severity were two
39
+ real defects and ten that a look at the guard, the caller, or the tsconfig
40
+ dismissed — the pass agreed with a reviewer on all twelve for about a cent
41
+ a finding. A confirmed verdict is still a model's reading: a strong lead for
42
+ a human's next look, not a validated claim.
43
+ 1. Read `synthesis.md`. It carries the executive summary, severity counts,
30
44
  the top cross-lens findings, and per-module risk levels.
31
45
  2. Read `triage.md` for the work order: each lead scored by impact ×
32
46
  difficulty with a P0–P3 priority and an effort estimate. It is a starting
@@ -36,7 +50,11 @@ not replace any phase; it tells phases where to look.
36
50
  - `architecture-*.json` → the architecture phase's seed of prior knowledge
37
51
  - `api-*.json` → endpoints and data types (contracts/protocols phases)
38
52
  - `security-*.json` → auth, trust boundaries (defect-scan-semantic pass 5)
39
- - `defect-*.json` → mechanical defect leads (defect-scan-mechanical)
53
+ - `defect-*.json` → mechanical defect leads (defect-scan-mechanical). The
54
+ scan is asked to name the input, call site, or sequence that reaches
55
+ each failure, and to file a cast, assertion, or style observation that
56
+ every caller satisfies at severity low under the pattern `type-hygiene`
57
+ — read those as notes, not defects.
40
58
  - `conventions-*.json` → naming/idiom candidates for CONVENTIONS.md
41
59
  - `porting-*.json` → platform coupling (porting phase)
42
60
  4. `run-meta.json` records scope: which lenses ran, at what cost, with what
@@ -66,6 +84,7 @@ Broad-Side is an executable-surface feature. On the Pi extension:
66
84
  /codecarto-broadside collect # poll, save, synthesize
67
85
  /codecarto-broadside status # show recorded runs
68
86
  /codecarto-broadside models # compare batch models
87
+ /codecarto-broadside verify --top=10 # read the top findings against the source
69
88
  ```
70
89
 
71
90
  On the MCP server:
@@ -75,6 +94,7 @@ codecarto_broadside {cwd, action: "submit", lenses: [...]} # fire the batches
75
94
  codecarto_broadside {cwd, action: "collect"} # poll, save, synthesize
76
95
  codecarto_broadside {cwd, action: "status"} # show recorded runs
77
96
  codecarto_broadside {cwd, action: "models"} # compare batch models
97
+ codecarto_broadside {cwd, action: "verify", top: 10} # read the top findings against the source
78
98
  ```
79
99
 
80
100
  The `models` action lists every `:batch` variant on OpenRouter — pricing per
@@ -92,19 +112,33 @@ every source file; the **security** and **API** lenses target where the
92
112
  trust boundary usually lives — `server/**`, `**/auth*`, `**/middleware/**`,
93
113
  `SECURITY.md` (security) and `server/**`, `api/**`, `src/server/**`,
94
114
  `src/api/**`, `**/*routes*`, `**/*router*`, `**/*handler*`, `**/*endpoint*`
95
- (API). A repository whose server is `src/server.js` matches none of those, so
96
- when the targeted patterns find nothing those two lenses **fall back to every
97
- source file** — priced as such, chunked at the lens's slice size rather than
98
- truncated, and said so on the lens line of the estimate, the submit report,
99
- `status`, and the prompt the model receives. A lens whose targeted patterns
100
- and fallback both find nothing (only test files, say) is skipped with a line
101
- naming both. `max_cost` is the guard against a fallback scan on a large
102
- repository being more than you meant to spend.
115
+ (API). A repository whose server is `src/server.js` matches none of those,
116
+ and one whose only match is `SECURITY.md` has given the lens a policy to read
117
+ and no code to check it against; so when the targeted patterns find **no
118
+ source file** those two lenses **fall back to every source file**, on top of
119
+ whatever did match — priced as such, chunked at the lens's slice size rather
120
+ than truncated, and said so on the lens line of the estimate, the submit
121
+ report, `status`, and the prompt the model receives. A lens whose targeted
122
+ patterns and fallback both find nothing (only test files, say) is skipped
123
+ with a line naming both. `max_cost` is the guard against a fallback scan on
124
+ a large repository being more than you meant to spend.
103
125
 
104
126
  Collect runs two cross-lens post-passes by default: **synthesis** (the
105
127
  executive report) and **triage** (the prioritized work order). Pass
106
128
  `include_synthesis: false` or `include_triage: false` on collect to skip one.
107
129
 
130
+ `verify` is the third pass, run separately after collect because it is
131
+ sync-priced rather than batch-priced: for each of the top `top` findings
132
+ (default 10, most severe first) of the defect and security lenses, one chat
133
+ completion on the run's model without its `:batch` suffix (`model` overrides),
134
+ with three read-only tools confined to the repository's source files —
135
+ `read_file` by line range, `grep`, `list_dir` — at most eight tool calls, low
136
+ reasoning effort, then a verdict. It writes `verified.md` and `verified.json`
137
+ beside `triage.md` and records the pass on the run. `max_cost` is a running
138
+ cap here, since a sync call's cost is known only when it returns: the pass
139
+ stops before the next finding once the calls so far have reached it and
140
+ reports `partial`. About a cent a finding on the default model.
141
+
108
142
  Two caveats apply to any model you pick. The `models` action lists every id
109
143
  OpenRouter advertises a `:batch` variant for, and many of those variants do not
110
144
  exist — submitting one returns `does not have a :batch endpoint`, with nothing in
@@ -3,4 +3,4 @@
3
3
  # workspace's framework-owned files (GUIDE.md, templates/, workflow/ pipelines
4
4
  # and VALIDATE.md) predate the running release. Written at release time and
5
5
  # copied verbatim by init — never edit by hand.
6
- scaffold_version: 0.23.0
6
+ scaffold_version: 0.24.1
package/README.md CHANGED
@@ -383,7 +383,7 @@ Each workflow tool accepts an absolute `cwd` for the target repository. `codecar
383
383
 
384
384
  ## Broad-Side (batch reconnaissance)
385
385
 
386
- Broad-Side is the cheap sweep you run *before* the expensive interactive run. It fires six analysis lenses — architecture, API surface, security, mechanical defect scan, convention extraction, porting — at a repository as single-turn prompts over the [OpenRouter Batch API](https://openrouter.ai/docs), then cross-references them into one executive report (`synthesis.md`) and a prioritized P0–P3 work order (`triage.md`). The security and API lenses target the paths where a trust boundary usually lives (`server/`, `auth*`, `middleware/`, routers and handlers) and fall back to every source file when a repository has none of them — priced as such, and said so on the estimate — so a service whose server is `src/server.js` still gets its security review.
386
+ Broad-Side is the cheap sweep you run *before* the expensive interactive run. It fires six analysis lenses — architecture, API surface, security, mechanical defect scan, convention extraction, porting — at a repository as single-turn prompts over the [OpenRouter Batch API](https://openrouter.ai/docs), then cross-references them into one executive report (`synthesis.md`) and a prioritized P0–P3 work order (`triage.md`). The security and API lenses target the paths where a trust boundary usually lives (`server/`, `auth*`, `middleware/`, routers and handlers) and fall back to every source file when a repository has no code under them — priced as such, and said so on the estimate — so a service whose server is `src/server.js`, or one whose only match is its `SECURITY.md`, still gets its security review.
387
387
 
388
388
  **Broad-Side findings are unverified scouting leads, not evidence.** Each lens is one shot: no cross-file traversal, no runtime verification, no builds, no tests. Every finding is a `file:line` pointer that the interactive pipeline — or you — must confirm before it is a fact. That division of labor is the point: a sub-dollar unattended sweep that tells the expensive run where to look. Nothing downstream may cite a Broad-Side report as a source.
389
389
 
@@ -394,13 +394,16 @@ codecarto_broadside {cwd, action: "models"} # compare batch mo
394
394
  codecarto_broadside {cwd, action: "submit", lenses: [...]} # fire the batches, priced first
395
395
  codecarto_broadside {cwd, action: "status"} # what is in flight
396
396
  codecarto_broadside {cwd, action: "collect"} # poll, save, synthesize, triage
397
+ codecarto_broadside {cwd, action: "verify", top: 10} # read the top findings against the source
397
398
  ```
398
399
 
400
+ A third action, `verify`, reads the top defect and security findings of a collected run against the real source — one sync-priced call each with read-only tools (`read_file`, `grep`, `list_dir`) confined to the repository — and writes `verified.md` with a verdict per finding: **confirmed** (a reachable failure, with the trigger), **not-a-defect**, **discarded**, or **unclear**. Measured on this repository, the top twelve findings by severity were two real defects and ten claims a look at the guard or the caller dismissed; the pass agreed with a reviewer on all twelve for a cent a finding. Read `verified.md` before `triage.md`.
401
+
399
402
  Submit and collect are separate because batch jobs routinely take tens of minutes; collect is resumable and picks up whatever is still in flight (`wait_seconds: 0`, the default, polls once and returns), and two collects on one run — a retried tool call, a second session — never pay for the synthesis, triage, or truncation retry twice: each is claimed in the run's state before it is submitted, and a collect whose client has gone away stops polling and submits nothing further. Submit prices the run from the collected file sizes against the model's live per-token pricing (cached 24h) and refuses when the estimate exceeds `max_cost` — $1.00 unless the config or the call sets another value, `0` for no limit — unless `force: true` is passed — a pre-flight estimate, not a runtime stop. Actual spend lands in each run's `run-meta.json`.
400
403
 
401
404
  Repository defaults live in `.codecarto/broadside/config.yaml` (`model`, `api_key`, `default_lenses`, `max_cost`, `pricing` overrides, `lens_models`, `incremental`, `retry_truncated`, `include_synthesis`, `include_triage`, `wait_seconds`); an explicit tool parameter always wins. `lens_models` routes individual lenses to their own batch model — a stronger model changes security and defect findings far more than it changes an architecture map — and each override is priced, capability-checked, and clamped exactly like the default, with the estimate broken out per lens so a mixed-model run cannot be approved without seeing which lens costs what. CodeCartographer ships no stronger default: which model earns its price depends on your repository and budget, so compare candidates with the `models` action and choose — for one run with the `model` and `lens_models` parameters (Pi: `--model=ID`, `--lens-model=LENS:ID`), or for the repository in `config.yaml`. The `models` listing is advisory: OpenRouter's catalog returns a `:batch` id for some models its Batch API then refuses (`does not have a :batch endpoint`), at no cost, and nothing in the catalog tells them apart — so the listing tags the ids this repository's own submits have seen accepted or refused, and a refused lens says why in the submit report. `codecarto_skill {cwd, name: "broadside"}` returns the reading guide for a completed run, and unlike post-pipeline skills it is not gated on a finished pipeline.
402
405
 
403
- On the Pi extension the same run is `/codecarto-broadside [submit|collect|status|models] [lenses…] [--model=ID] [--lens-model=LENS:ID]`, with tab-completion for actions, lens names, and flags and live per-lens progress while batches poll. The two surfaces differ in one deliberate place: MCP cannot ask a human, so it refuses a run over `max_cost` until you pass `force`; Pi shows the per-lens breakdown and asks, and your approval *is* the force flag. Neither surface takes an API key as a command argument — a key typed into a slash command lands in the session transcript.
406
+ On the Pi extension the same run is `/codecarto-broadside [submit|collect|status|models|verify] [lenses…] [--model=ID] [--lens-model=LENS:ID] [--top=N]`, with tab-completion for actions, lens names, and flags and live per-lens progress while batches poll. The two surfaces differ in one deliberate place: MCP cannot ask a human, so it refuses a run over `max_cost` until you pass `force`; Pi shows the per-lens breakdown and asks, and your approval *is* the force flag. Neither surface takes an API key as a command argument — a key typed into a slash command lands in the session transcript.
404
407
 
405
408
  Broad-Side needs runtime code, so firing a run is an executable-surface feature: Pi and MCP have it, the pure drop-in template does not (it carries only the reading guide).
406
409
 
@@ -95,7 +95,11 @@ Two more economies worth knowing:
95
95
 
96
96
  ## Reading a run
97
97
 
98
- Results land in `.codecarto/broadside/<run>/`. Read them in this order:
98
+ Results land in `.codecarto/broadside/<run>/`. If `verified.md` is there, read
99
+ it before anything else: `action: "verify"` has read the top defect and
100
+ security findings against the source with read-only tools and given each a
101
+ verdict (confirmed with its trigger, not-a-defect, discarded with the guard
102
+ that shows it, unclear). Then, in this order:
99
103
 
100
104
  1. `synthesis.md` — executive summary, severity counts, top cross-lens
101
105
  findings, per-module risk.
@@ -39,8 +39,11 @@ export declare function listAmendmentNames(workspaceDir: string): Promise<string
39
39
  export declare function loadAmendmentFile(name: string, workspaceDir: string): Promise<Amendment>;
40
40
  /**
41
41
  * Apply one amendment to canonical state under the completion lock. Refuses
42
- * while the pipeline is incomplete — mid-pipeline resolutions belong in the
43
- * phase handoff, and allowing both channels at once would race them.
44
- * Idempotent: ids that no longer match anything are reported, not fatal.
42
+ * while the pipeline is incomplete, judged on the state read under the lock:
43
+ * the check used to run on a read taken before the lock, so a status change
44
+ * that landed in between — a pipeline switch, a re-init, a rolled-back
45
+ * completion — was amended over as if the pipeline were still complete
46
+ * (Broad-Side verify, 2026-09-13 run). Idempotent: ids that no longer match
47
+ * anything are reported, not fatal.
45
48
  */
46
49
  export declare function applyAmendment(cwd: string, name: string): Promise<AmendmentResult>;
@@ -91,17 +91,12 @@ function renderAmendmentCloseout(amendment, applied, timestamp) {
91
91
  return lines.join("\n");
92
92
  }
93
93
  /**
94
- * Apply one amendment to canonical state under the completion lock. Refuses
95
- * while the pipeline is incomplete — mid-pipeline resolutions belong in the
96
- * phase handoff, and allowing both channels at once would race them.
97
- * Idempotent: ids that no longer match anything are reported, not fatal.
94
+ * The refusal an amendment gets while the pipeline is incomplete —
95
+ * mid-pipeline resolutions belong in the phase handoff, and allowing both
96
+ * channels at once would race them.
98
97
  */
99
- export async function applyAmendment(cwd, name) {
100
- const initialState = await getWorkspaceState(cwd);
101
- if (!initialState)
102
- throw new Error("CodeCartographer workspace not found. Run /codecarto-init first.");
103
- const amendment = await loadAmendmentFile(name, initialState.workspaceDir);
104
- const outcome = resolvePipelineOutcome(initialState);
98
+ function refuseUnlessComplete(state) {
99
+ const outcome = resolvePipelineOutcome(state);
105
100
  if (outcome.kind === "eligible") {
106
101
  throw new Error(`Cannot amend: the pipeline is not complete (next phase: ${outcome.phase.id}). `
107
102
  + `Resolve open questions and routed items through that phase's handoff (open_question_closures / carry_forward_closures) instead.`);
@@ -111,10 +106,26 @@ export async function applyAmendment(cwd, name) {
111
106
  // finish is not there yet (#228).
112
107
  throw new Error(`Cannot amend: the pipeline is not complete. ${describeStuckPipeline(outcome.blocked)}`);
113
108
  }
109
+ }
110
+ /**
111
+ * Apply one amendment to canonical state under the completion lock. Refuses
112
+ * while the pipeline is incomplete, judged on the state read under the lock:
113
+ * the check used to run on a read taken before the lock, so a status change
114
+ * that landed in between — a pipeline switch, a re-init, a rolled-back
115
+ * completion — was amended over as if the pipeline were still complete
116
+ * (Broad-Side verify, 2026-09-13 run). Idempotent: ids that no longer match
117
+ * anything are reported, not fatal.
118
+ */
119
+ export async function applyAmendment(cwd, name) {
120
+ const initialState = await getWorkspaceState(cwd);
121
+ if (!initialState)
122
+ throw new Error("CodeCartographer workspace not found. Run /codecarto-init first.");
123
+ const amendment = await loadAmendmentFile(name, initialState.workspaceDir);
114
124
  const timestamp = new Date().toISOString();
115
125
  const applied = { openQuestionsClosed: [], postPipelineClosed: [], unknownIds: [] };
116
126
  let closeoutNotice = "";
117
127
  const updatedState = await updateStatusAtomically(cwd, async (lockedState) => {
128
+ refuseUnlessComplete(lockedState);
118
129
  const nextStatus = normalizeStatus(lockedState.status, lockedState.pipeline, lockedState.status.pipeline, lockedState.cwd);
119
130
  for (const closureId of amendment.open_question_closures) {
120
131
  if (!closureId)
@@ -0,0 +1,95 @@
1
+ import { type BroadsideLensId, type BroadsideVerifyEntry, type FetchLike, type StoredLensResult } from "./broadside.ts";
2
+ export declare const BROADSIDE_CHAT_URL = "https://openrouter.ai/api/v1/chat/completions";
3
+ /** How many findings `verify` reads by default, most severe first. */
4
+ export declare const BROADSIDE_VERIFY_DEFAULT_TOP = 10;
5
+ /** Tool calls one finding may spend before it must answer. */
6
+ export declare const BROADSIDE_VERIFY_MAX_TOOL_CALLS = 8;
7
+ /** The lenses whose findings carry a file:line and a claim to check. */
8
+ export declare const BROADSIDE_VERIFIABLE_LENSES: readonly BroadsideLensId[];
9
+ export type VerifyVerdict = "confirmed" | "not-a-defect" | "discarded" | "unclear";
10
+ export type VerifiedFinding = {
11
+ index: number;
12
+ lensId: BroadsideLensId;
13
+ customId: string;
14
+ severity: string;
15
+ title: string;
16
+ location: string;
17
+ verdict: VerifyVerdict | "error";
18
+ confidence: string;
19
+ evidence: Array<{
20
+ file: string;
21
+ lines: string;
22
+ note: string;
23
+ }>;
24
+ reasoning: string;
25
+ toolCalls: number;
26
+ cost: number;
27
+ };
28
+ export type BroadsideVerifyResult = {
29
+ runId: string;
30
+ outputDir: string;
31
+ model: string;
32
+ status: BroadsideVerifyEntry["status"];
33
+ /** How many findings the run had in the verifiable lenses. */
34
+ candidates: number;
35
+ findings: VerifiedFinding[];
36
+ totalCost: number;
37
+ /** Set when the cost cap stopped the pass before every selected finding was read. */
38
+ stoppedByCost?: boolean;
39
+ };
40
+ type CandidateFinding = {
41
+ lensId: BroadsideLensId;
42
+ customId: string;
43
+ severity: string;
44
+ title: string;
45
+ location: string;
46
+ description: string;
47
+ pattern: string;
48
+ };
49
+ /** The sync-priced id behind a `:batch` model id (`vendor/name:batch` → `vendor/name`). */
50
+ export declare function syncModelFor(batchModel: string): string;
51
+ /** The findings a run's saved lens results carry, most severe first. */
52
+ export declare function rankVerifiableFindings(stored: StoredLensResult[]): CandidateFinding[];
53
+ export type RepoReader = {
54
+ readFile(path: string, startLine?: number, endLine?: number): Promise<string>;
55
+ grep(pattern: string, pathPrefix?: string): Promise<string>;
56
+ listDir(path: string): Promise<string>;
57
+ };
58
+ /**
59
+ * Three read-only tools over the repository's own file list — the same
60
+ * listing the lenses scan (tracked and untracked, ignore rules applied) minus
61
+ * everything {@link isSlurpable} keeps out of a lens: credential stores, build
62
+ * output, binaries. A path outside the repository, or one the listing does
63
+ * not contain, is an error the model sees, not a read.
64
+ */
65
+ export declare function createRepoReader(cwd: string): Promise<RepoReader>;
66
+ /**
67
+ * The rubric. The order is deliberate — it is the order a reviewer settles a
68
+ * claim in — and `not-a-defect` is the verdict that separates "the code does
69
+ * what the claim says" from "and that is a bug": without it, a cast every
70
+ * caller satisfies gets confirmed because it is literally there.
71
+ */
72
+ export declare const BROADSIDE_VERIFY_SYSTEM_PROMPT: string;
73
+ /** Verify one finding: up to the tool budget, then a verdict. */
74
+ export declare function verifyFinding(finding: CandidateFinding, index: number, reader: RepoReader, apiKey: string, model: string, fetcher: FetchLike): Promise<Omit<VerifiedFinding, "index" | "lensId" | "customId" | "severity" | "title" | "location">>;
75
+ /**
76
+ * Verify the top findings of a collected run against the repository.
77
+ *
78
+ * `maxCost` is a running cap, not a pre-flight estimate: a sync call's cost
79
+ * is only known when it returns, so the pass stops *before* starting the next
80
+ * finding once the cap is reached and reports `partial`. On the default
81
+ * model a finding costs about a cent.
82
+ */
83
+ export declare function runBroadsideVerify(cwd: string, apiKey: string, opts?: {
84
+ runId?: string;
85
+ top?: number;
86
+ model?: string;
87
+ /** USD; 0 means no limit. */
88
+ maxCost?: number;
89
+ fetcher?: FetchLike;
90
+ signal?: AbortSignal;
91
+ onProgress?: (finding: VerifiedFinding) => void;
92
+ }): Promise<BroadsideVerifyResult>;
93
+ export declare function renderVerifiedMarkdown(result: BroadsideVerifyResult): string;
94
+ export declare function verifyResultText(result: BroadsideVerifyResult): string;
95
+ export {};