feat(scanners): a redundancy claim that belongs to one model is scoped to it
Anthropic documents that Claude Opus 5 verifies its own work, and that telling it to double-check or to delegate verification to a subagent causes over-verification -- token cost with no quality gain. The general subtraction detector (BP-SUB-001) already surfaces those blocks for every user, with no model-awareness at all. `optimize --subtract --for-model <name>` adds the missing half. It ANNOTATES a subset of the candidates --subtract already produced; it is not a second detector and can never widen the candidate set. A second SUBTRACT_DETECTORS entry would have collided with BP-SUB-001 on de-dup, and a prose-only signal in the agent prompt would have been untestable. There is no auto-detection, by measurement rather than omission: a CLAUDE.md has no frontmatter and no resolvable target model, and this operator's own `route` skill deliberately runs a different model per session -- the same file is read by whichever model comes next. So the model is named, and the citation is reported as conditional everywhere a human sees it (agent report copy, and the Step 7a listing that is the last surface before an approval file). Precision comes from the TARGET, not the verb list. Measured across the 409-file corpus: 392 BP-SUB-001 candidates, 31 (7.9%) carry a verify verb, and 0 also carry a reflexive or delegated target. Two independent raw-text greps found 0 as well, so the zero is the corpus rather than an over-narrow regex. Those 31 verb-only blocks -- "sjekk relevante config-filer", "Type-sjekk: pyright", "To verify plugin functionality" -- are exactly the false positives a verb-only version would have produced, which is BP-JUDG-001's 7/7 failure arriving one lens over. The numbers live in the register entry's note and are pinned by a test, because a session that cannot see the measurement reads the zero as a broken detector and loosens it. `recognized` is reported separately from `matchedCount`: a typo'd model name and a genuinely clean config both yield zero, and without the distinction the CLI would report a silent no-op as good news. Dogfooded on the real machine -- `opus-5` gives recognized:true/matchedCount:0, `oppus5` gives recognized:false. source.published is absent because the guide carries no visible publish date; its absence is asserted so a later session does not invent one to match the other entries' shape. Both quoted sentences were verified verbatim 2026-08-12. The payload stays additive -- forModel and per-candidate modelScope appear only under the flag, so a plain --subtract run is byte-identical to before (asserted on the serialized bytes, since a key set to undefined passes a shallow check). Suite 1724 -> 1752 (+28). The one remaining failure is the pre-existing drift-cli --output-file crash, untouched by this work. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BRuXt6tZyowi8QYNKLSHQm
This commit is contained in:
parent
05b4e9d797
commit
7df8e0d65b
11 changed files with 650 additions and 10 deletions
|
|
@ -20,6 +20,12 @@
|
|||
*
|
||||
* Usage:
|
||||
* node optimize-lens-cli.mjs [path] [--output-file <path>] [--global]
|
||||
* [--subtract [--for-model <name>]]
|
||||
*
|
||||
* `--for-model <name>` annotates the subtraction candidates a named model
|
||||
* documents as redundant (BP-PROMPT-001). It never widens the candidate set,
|
||||
* and there is deliberately no auto-detection: a CLAUDE.md has no frontmatter
|
||||
* and no statically-resolvable target model, so the model must be named.
|
||||
*
|
||||
* Exit codes: 0=ok, 3=unrecoverable error. Zero external dependencies.
|
||||
*/
|
||||
|
|
@ -32,11 +38,18 @@ import { parseFrontmatter } from './lib/yaml-parser.mjs';
|
|||
import { loadRegister, getEntry } from './lib/best-practices-register.mjs';
|
||||
import { prefilterClaudeMd, LENS_DETECTORS } from './lib/lens-prefilter.mjs';
|
||||
import { subtractionCandidates, SUBTRACT_DETECTORS } from './lib/subtraction-prefilter.mjs';
|
||||
import { matchModelScope, normalizeModel } from './lib/prompting-model-scope.mjs';
|
||||
import { scan as optScan } from './optimization-lens-scanner.mjs';
|
||||
import { requireValidArgs } from './lib/cli-args.mjs';
|
||||
|
||||
/** Flag surface, measured 2026-08-09. Anything else is exit 3. */
|
||||
const ARG_SPEC = { boolean: ['--global', '--subtract'], value: ['--output-file'] };
|
||||
const ARG_SPEC = {
|
||||
boolean: ['--global', '--subtract'],
|
||||
// `--for-model` is a VALUE flag, so a bare `--for-model` is reported as
|
||||
// "needs a value" rather than "unknown flag" — the two are different failures
|
||||
// and reporting the wrong one hides which mistake the caller made.
|
||||
value: ['--output-file', '--for-model'],
|
||||
};
|
||||
|
||||
// Files under `.claude/plugins/` are shipped by an installed plugin — vendored
|
||||
// CLAUDE.md plus its bundled tests/fixtures and examples. They are not the user's
|
||||
|
|
@ -60,11 +73,13 @@ async function main() {
|
|||
let outputFile = null;
|
||||
let includeGlobal = false;
|
||||
let subtract = false;
|
||||
let targetModel = null;
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (args[i] === '--global') includeGlobal = true;
|
||||
else if (args[i] === '--subtract') subtract = true;
|
||||
else if (args[i] === '--output-file' && args[i + 1]) outputFile = args[++i];
|
||||
else if (args[i] === '--for-model' && args[i + 1]) targetModel = args[++i];
|
||||
else if (!args[i].startsWith('-')) targetPath = args[i];
|
||||
}
|
||||
|
||||
|
|
@ -108,6 +123,23 @@ async function main() {
|
|||
// fire on a plain `/config-audit optimize` run (brief §7 q3).
|
||||
const subtractCands = [];
|
||||
const subtractEntry = subtract && register ? confirmedEntry(register, 'BP-SUB-001') : null;
|
||||
// Model-scoped annotation entries (BP-PROMPT-001 and any later sibling). These
|
||||
// never produce candidates of their own — they only tag candidates the
|
||||
// BP-SUB-001 detector above already surfaced.
|
||||
const promptEntries =
|
||||
subtract && register
|
||||
? (register.entries || []).filter(
|
||||
(e) => e.category === 'prompting-fit' && e.confidence === 'confirmed',
|
||||
)
|
||||
: [];
|
||||
// `recognized` is reported separately from the match count so a typo'd model
|
||||
// name is distinguishable from a config that genuinely carries nothing.
|
||||
const modelRecognized =
|
||||
!!targetModel &&
|
||||
promptEntries.some((e) =>
|
||||
(e.modelScope || []).some((m) => normalizeModel(m) === normalizeModel(targetModel)),
|
||||
);
|
||||
let modelMatchedCount = 0;
|
||||
|
||||
for (const file of claudeMdFiles) {
|
||||
let content;
|
||||
|
|
@ -122,6 +154,8 @@ async function main() {
|
|||
|
||||
if (subtractEntry) {
|
||||
for (const cand of subtractionCandidates(body)) {
|
||||
const modelScope = matchModelScope(cand.text, targetModel, promptEntries);
|
||||
if (modelScope) modelMatchedCount++;
|
||||
subtractCands.push({
|
||||
file: file.absPath,
|
||||
line: bodyStartLine - 1 + cand.startLine,
|
||||
|
|
@ -137,6 +171,9 @@ async function main() {
|
|||
severity: subtractEntry.severity || 'low',
|
||||
source: subtractEntry.source,
|
||||
},
|
||||
// Spread only when matched: a run without --for-model must not grow
|
||||
// even a key set to undefined.
|
||||
...(modelScope ? { modelScope } : {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -217,6 +254,15 @@ async function main() {
|
|||
: [],
|
||||
detectors: SUBTRACT_DETECTORS.map((d) => ({ ...d })),
|
||||
};
|
||||
// Present ONLY when a model was named — a plain --subtract run stays
|
||||
// byte-identical to the pre-flag payload.
|
||||
if (targetModel) {
|
||||
payload.subtract.forModel = {
|
||||
requested: targetModel,
|
||||
recognized: modelRecognized,
|
||||
matchedCount: modelMatchedCount,
|
||||
};
|
||||
}
|
||||
payload.counts.subtractCandidates = subtractCands.length;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue