cc-codeconductor 1.8.0 → 1.9.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/README.md +6 -6
- package/dist/index.js +1574 -569
- package/docs/generated/cli.md +21 -0
- package/package.json +7 -4
package/dist/index.js
CHANGED
|
@@ -72,7 +72,7 @@ var package_default;
|
|
|
72
72
|
var init_package = __esm(() => {
|
|
73
73
|
package_default = {
|
|
74
74
|
name: "cc-codeconductor",
|
|
75
|
-
version: "1.
|
|
75
|
+
version: "1.9.0",
|
|
76
76
|
description: "A multi-agent orchestration framework for AI-assisted software engineering workflows.",
|
|
77
77
|
keywords: [
|
|
78
78
|
"ai",
|
|
@@ -119,8 +119,9 @@ var init_package = __esm(() => {
|
|
|
119
119
|
},
|
|
120
120
|
scripts: {
|
|
121
121
|
dev: "bun run src/cli/main.ts",
|
|
122
|
+
"ab:run": "bun run scripts/ab-run.ts",
|
|
122
123
|
build: "bun run scripts/build.ts",
|
|
123
|
-
"build:cli": "bun build src/cli/main.ts --target=node --outfile=dist/index.js",
|
|
124
|
+
"build:cli": "bun build src/cli/main.ts --target=node --external typescript --outfile=dist/index.js",
|
|
124
125
|
"build:lib": "bun build src/index.ts --target=node --outfile=dist/library.js --packages=external",
|
|
125
126
|
"build:types": "tsc -p tsconfig.lib.json --emitDeclarationOnly",
|
|
126
127
|
"generate:cli-docs": "bun run scripts/generate-cli-docs.ts",
|
|
@@ -128,6 +129,8 @@ var init_package = __esm(() => {
|
|
|
128
129
|
"test:fast": "bun run scripts/test-fast.ts",
|
|
129
130
|
typecheck: "tsc --noEmit",
|
|
130
131
|
lint: "bun run scripts/lint.ts",
|
|
132
|
+
"rework:rate": "bun run scripts/rework-rate.ts",
|
|
133
|
+
"bench:local": "bun run scripts/bench-local.ts",
|
|
131
134
|
"check:council-redirect": "bun run scripts/check-council-redirect.ts",
|
|
132
135
|
"check:coverage": "bun run scripts/check-coverage.ts",
|
|
133
136
|
"check:prompt-changelog": "bun run scripts/check-prompt-changelog.ts",
|
|
@@ -142,12 +145,12 @@ var init_package = __esm(() => {
|
|
|
142
145
|
},
|
|
143
146
|
dependencies: {
|
|
144
147
|
zod: "^3.23.8",
|
|
148
|
+
typescript: "^5.5.3",
|
|
145
149
|
yaml: "^2.4.5",
|
|
146
150
|
"smol-toml": "^1.9.1"
|
|
147
151
|
},
|
|
148
152
|
devDependencies: {
|
|
149
|
-
"@types/bun": "^1.1.8"
|
|
150
|
-
typescript: "^5.5.3"
|
|
153
|
+
"@types/bun": "^1.1.8"
|
|
151
154
|
}
|
|
152
155
|
};
|
|
153
156
|
});
|
|
@@ -21568,6 +21571,144 @@ var init_ask_command = __esm(() => {
|
|
|
21568
21571
|
init_recommend_flow();
|
|
21569
21572
|
});
|
|
21570
21573
|
|
|
21574
|
+
// src/core/ask/recommend-correction.ts
|
|
21575
|
+
function includesAny2(haystack, needles) {
|
|
21576
|
+
return needles.some((n) => haystack.includes(n));
|
|
21577
|
+
}
|
|
21578
|
+
function pick(layer, command, reason, forbidProse = true) {
|
|
21579
|
+
return { layer, command, reason, forbidProse };
|
|
21580
|
+
}
|
|
21581
|
+
function recommendCorrection(signal) {
|
|
21582
|
+
const text = signal.trim().toLowerCase();
|
|
21583
|
+
if (includesAny2(text, [
|
|
21584
|
+
"bun run dev",
|
|
21585
|
+
'script not found "dev"',
|
|
21586
|
+
"script not found 'dev'",
|
|
21587
|
+
"consumer cli",
|
|
21588
|
+
"consumer-facing",
|
|
21589
|
+
"npx cc-codeconductor"
|
|
21590
|
+
])) {
|
|
21591
|
+
return pick("static-analysis", "bun test test/unit/presets/consumer-cli-invocation.test.ts", "Shipped artifacts must not tell consumers to run `bun run dev`. The consumer-cli-invocation test owns this; do not restate it in AGENTS.md.");
|
|
21592
|
+
}
|
|
21593
|
+
if (includesAny2(text, [
|
|
21594
|
+
"council redirect",
|
|
21595
|
+
"council stub",
|
|
21596
|
+
"hand-edit council",
|
|
21597
|
+
"hand edit council",
|
|
21598
|
+
"cc-council",
|
|
21599
|
+
"check:council-redirect"
|
|
21600
|
+
])) {
|
|
21601
|
+
return pick("static-analysis", "bun run check:council-redirect", "Council copies must stay generated redirect stubs. Regenerating scripts own this; never hand-edit the copies or document a workaround.");
|
|
21602
|
+
}
|
|
21603
|
+
if (includesAny2(text, [
|
|
21604
|
+
"check:drift",
|
|
21605
|
+
"hand-edit preset",
|
|
21606
|
+
"hand edit preset",
|
|
21607
|
+
"hand-edit skill",
|
|
21608
|
+
"sync:skills",
|
|
21609
|
+
"presets drifted",
|
|
21610
|
+
"shared-skills"
|
|
21611
|
+
])) {
|
|
21612
|
+
return pick("static-analysis", "bun run check:drift", "Generated presets and synced skills have one source of truth. Fix the generator or canonical skill, then re-run check:drift.");
|
|
21613
|
+
}
|
|
21614
|
+
const doubleCast = ["as un", "known as"].join("");
|
|
21615
|
+
const anyAnnotation = [":", " any"].join("");
|
|
21616
|
+
const anyAssertion = ["as", " any"].join("");
|
|
21617
|
+
if (includesAny2(text, [
|
|
21618
|
+
"no-any",
|
|
21619
|
+
doubleCast,
|
|
21620
|
+
"nested import",
|
|
21621
|
+
"no-nested-import",
|
|
21622
|
+
anyAnnotation,
|
|
21623
|
+
anyAssertion
|
|
21624
|
+
])) {
|
|
21625
|
+
return pick("static-analysis", "bun run lint", "TypeScript agent shortcuts are banned in src/ by scripts/lint.ts. Fix the code; do not add a prose reminder.");
|
|
21626
|
+
}
|
|
21627
|
+
if (includesAny2(text, [
|
|
21628
|
+
"out of scope",
|
|
21629
|
+
"outside scope",
|
|
21630
|
+
"scope guard",
|
|
21631
|
+
"scope violation",
|
|
21632
|
+
"surgical",
|
|
21633
|
+
"adjacent code",
|
|
21634
|
+
"filesaffected",
|
|
21635
|
+
"symbol boundary"
|
|
21636
|
+
])) {
|
|
21637
|
+
return pick("verification", "scope-guard (checkScopeCompliance)", "Diff scope is enforced by checkScopeCompliance (fail-closed when git evidence is missing). Tighten the Technical Plan allowlist or shrink the diff — do not add AGENTS.md surgical-change prose.");
|
|
21638
|
+
}
|
|
21639
|
+
if (includesAny2(text, [
|
|
21640
|
+
"rdd verify",
|
|
21641
|
+
"ev-rdd",
|
|
21642
|
+
"receipt",
|
|
21643
|
+
"rdd receipt",
|
|
21644
|
+
"receipt-driven"
|
|
21645
|
+
])) {
|
|
21646
|
+
return pick("verification", "cc-codeconductor rdd verify --receipt <id>", "RDD receipts are verified by the rdd CLI. Capture or verify the receipt for the current candidate; do not invent a checklist paragraph.");
|
|
21647
|
+
}
|
|
21648
|
+
if (includesAny2(text, [
|
|
21649
|
+
"openspec analyze",
|
|
21650
|
+
"skip analyze",
|
|
21651
|
+
"skipped analyze",
|
|
21652
|
+
"skip openspec",
|
|
21653
|
+
"before openspec analyze"
|
|
21654
|
+
])) {
|
|
21655
|
+
return pick("verification", "cc-codeconductor openspec analyze", "OpenSpec analyze is the gate before implementer work. Run it; do not replace it with a skill reminder.");
|
|
21656
|
+
}
|
|
21657
|
+
if (includesAny2(text, [
|
|
21658
|
+
"document in agents",
|
|
21659
|
+
"document this in agents",
|
|
21660
|
+
"add to agents.md",
|
|
21661
|
+
"update agents.md",
|
|
21662
|
+
"write in agents.md",
|
|
21663
|
+
"add a rule to agents",
|
|
21664
|
+
"documenta esto en agents",
|
|
21665
|
+
"añade a agents.md",
|
|
21666
|
+
"agrega a agents.md"
|
|
21667
|
+
])) {
|
|
21668
|
+
return pick("prose", "(none — refuse until a lower-layer owner is ruled out)", "AGENTS.md is last. First ask whether architecture, lint/CI, or a verification command can own the rule. Only judgment calls that cannot be enforced belong in prose.", false);
|
|
21669
|
+
}
|
|
21670
|
+
return pick("verification", "cc-codeconductor doctor", "No known mistake class matched. Run doctor / the relevant verification CLI before adding prose.", true);
|
|
21671
|
+
}
|
|
21672
|
+
|
|
21673
|
+
// src/commands/correct.command.ts
|
|
21674
|
+
var exports_correct_command = {};
|
|
21675
|
+
__export(exports_correct_command, {
|
|
21676
|
+
correctCommand: () => correctCommand
|
|
21677
|
+
});
|
|
21678
|
+
async function correctCommand(options) {
|
|
21679
|
+
const signal = options.signal.trim();
|
|
21680
|
+
if (!signal) {
|
|
21681
|
+
return {
|
|
21682
|
+
code: 1,
|
|
21683
|
+
data: {
|
|
21684
|
+
success: false,
|
|
21685
|
+
command: "correct",
|
|
21686
|
+
errors: [
|
|
21687
|
+
'Usage: correct "<mistake signal>". Recommends a layer and existing command; does not start a workflow.'
|
|
21688
|
+
]
|
|
21689
|
+
}
|
|
21690
|
+
};
|
|
21691
|
+
}
|
|
21692
|
+
const rec = recommendCorrection(signal);
|
|
21693
|
+
const proseLine = rec.forbidProse ? "Do not add AGENTS.md prose — a lower-layer owner already exists." : "Prose is allowed only if no architecture, lint, or verification owner can enforce the rule.";
|
|
21694
|
+
return {
|
|
21695
|
+
code: 0,
|
|
21696
|
+
data: {
|
|
21697
|
+
success: true,
|
|
21698
|
+
command: "correct",
|
|
21699
|
+
recommended: rec,
|
|
21700
|
+
executed: false,
|
|
21701
|
+
message: `Layer: ${rec.layer}
|
|
21702
|
+
Command: ${rec.command}
|
|
21703
|
+
${rec.reason}
|
|
21704
|
+
|
|
21705
|
+
` + `${proseLine}
|
|
21706
|
+
` + "Do not start a workflow from this recommendation."
|
|
21707
|
+
}
|
|
21708
|
+
};
|
|
21709
|
+
}
|
|
21710
|
+
var init_correct_command = () => {};
|
|
21711
|
+
|
|
21571
21712
|
// src/commands/help.command.ts
|
|
21572
21713
|
var exports_help_command = {};
|
|
21573
21714
|
__export(exports_help_command, {
|
|
@@ -28748,26 +28889,596 @@ var init_tdd_command = __esm(() => {
|
|
|
28748
28889
|
init_schemas();
|
|
28749
28890
|
});
|
|
28750
28891
|
|
|
28892
|
+
// src/core/verification/harness/gatekeeper.ts
|
|
28893
|
+
import { readFile as readFile39 } from "node:fs/promises";
|
|
28894
|
+
import { dirname as dirname13, relative as relative11, resolve as resolve37 } from "node:path";
|
|
28895
|
+
import ts from "typescript";
|
|
28896
|
+
async function parse2(file) {
|
|
28897
|
+
const text = await readFile39(file, "utf-8");
|
|
28898
|
+
return ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
|
|
28899
|
+
}
|
|
28900
|
+
function lineOf(sf, node2) {
|
|
28901
|
+
return sf.getLineAndCharacterOfPosition(node2.getStart(sf)).line + 1;
|
|
28902
|
+
}
|
|
28903
|
+
function isFunctionLike(node2) {
|
|
28904
|
+
return ts.isFunctionDeclaration(node2) || ts.isMethodDeclaration(node2) || ts.isConstructorDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2) || ts.isGetAccessorDeclaration(node2) || ts.isSetAccessorDeclaration(node2);
|
|
28905
|
+
}
|
|
28906
|
+
function isDecision(node2) {
|
|
28907
|
+
if (ts.isBinaryExpression(node2)) {
|
|
28908
|
+
const k = node2.operatorToken.kind;
|
|
28909
|
+
return k === ts.SyntaxKind.AmpersandAmpersandToken || k === ts.SyntaxKind.BarBarToken || k === ts.SyntaxKind.QuestionQuestionToken || k === ts.SyntaxKind.AmpersandAmpersandEqualsToken || k === ts.SyntaxKind.BarBarEqualsToken || k === ts.SyntaxKind.QuestionQuestionEqualsToken;
|
|
28910
|
+
}
|
|
28911
|
+
return ts.isIfStatement(node2) || ts.isForStatement(node2) || ts.isForInStatement(node2) || ts.isForOfStatement(node2) || ts.isWhileStatement(node2) || ts.isDoStatement(node2) || ts.isCaseClause(node2) || ts.isCatchClause(node2) || ts.isConditionalExpression(node2);
|
|
28912
|
+
}
|
|
28913
|
+
function complexityOf(fn) {
|
|
28914
|
+
let total = 1;
|
|
28915
|
+
const visit2 = (node2) => {
|
|
28916
|
+
if (isFunctionLike(node2))
|
|
28917
|
+
return;
|
|
28918
|
+
if (isDecision(node2))
|
|
28919
|
+
total++;
|
|
28920
|
+
ts.forEachChild(node2, visit2);
|
|
28921
|
+
};
|
|
28922
|
+
if (fn.body)
|
|
28923
|
+
ts.forEachChild(fn.body, visit2);
|
|
28924
|
+
for (const p of fn.parameters)
|
|
28925
|
+
if (p.initializer)
|
|
28926
|
+
visit2(p.initializer);
|
|
28927
|
+
return total;
|
|
28928
|
+
}
|
|
28929
|
+
function countParams(fn) {
|
|
28930
|
+
return fn.parameters.filter((p) => !(ts.isIdentifier(p.name) && p.name.text === "this")).length;
|
|
28931
|
+
}
|
|
28932
|
+
function lineCount(text) {
|
|
28933
|
+
const lines = text.split(/\r?\n/);
|
|
28934
|
+
return text.endsWith(`
|
|
28935
|
+
`) ? lines.length - 1 : lines.length;
|
|
28936
|
+
}
|
|
28937
|
+
async function checkProductionFiles(files, limits = {}) {
|
|
28938
|
+
const max = { ...DEFAULT_LIMITS, ...limits };
|
|
28939
|
+
const violations = [];
|
|
28940
|
+
for (const file of files) {
|
|
28941
|
+
const sf = await parse2(file);
|
|
28942
|
+
const lines = lineCount(sf.text);
|
|
28943
|
+
if (lines > max.maxLines) {
|
|
28944
|
+
violations.push({ file, line: 1, rule: "max-lines", message: `${lines} lines (max ${max.maxLines})` });
|
|
28945
|
+
}
|
|
28946
|
+
const visit2 = (node2) => {
|
|
28947
|
+
if (isFunctionLike(node2)) {
|
|
28948
|
+
const params = countParams(node2);
|
|
28949
|
+
if (params > max.maxParams) {
|
|
28950
|
+
violations.push({
|
|
28951
|
+
file,
|
|
28952
|
+
line: lineOf(sf, node2),
|
|
28953
|
+
rule: "max-params",
|
|
28954
|
+
message: `${params} parameters (max ${max.maxParams})`
|
|
28955
|
+
});
|
|
28956
|
+
}
|
|
28957
|
+
const complexity = complexityOf(node2);
|
|
28958
|
+
if (complexity > max.maxComplexity) {
|
|
28959
|
+
violations.push({
|
|
28960
|
+
file,
|
|
28961
|
+
line: lineOf(sf, node2),
|
|
28962
|
+
rule: "max-complexity",
|
|
28963
|
+
message: `cyclomatic complexity ${complexity} (max ${max.maxComplexity})`
|
|
28964
|
+
});
|
|
28965
|
+
}
|
|
28966
|
+
}
|
|
28967
|
+
ts.forEachChild(node2, visit2);
|
|
28968
|
+
};
|
|
28969
|
+
visit2(sf);
|
|
28970
|
+
}
|
|
28971
|
+
return violations;
|
|
28972
|
+
}
|
|
28973
|
+
function globToRegExp(glob) {
|
|
28974
|
+
const body = glob.split("**").map((part) => part.split("*").map((s) => s.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join("[^/]*")).join(".*");
|
|
28975
|
+
return new RegExp(`^${body}$`);
|
|
28976
|
+
}
|
|
28977
|
+
async function checkTestFiles(files, domainGlobs, root) {
|
|
28978
|
+
const matchers = domainGlobs.map(globToRegExp);
|
|
28979
|
+
const isDomain = (file, specifier) => {
|
|
28980
|
+
if (!specifier.startsWith("."))
|
|
28981
|
+
return false;
|
|
28982
|
+
const rel = relative11(root, resolve37(dirname13(file), specifier)).replace(/\\/g, "/");
|
|
28983
|
+
return [rel, `${rel}.ts`, `${rel}/index.ts`].some((c) => matchers.some((m) => m.test(c)));
|
|
28984
|
+
};
|
|
28985
|
+
const violations = [];
|
|
28986
|
+
for (const file of files) {
|
|
28987
|
+
const sf = await parse2(file);
|
|
28988
|
+
const domainNames = new Set;
|
|
28989
|
+
for (const stmt of sf.statements) {
|
|
28990
|
+
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
28991
|
+
continue;
|
|
28992
|
+
if (!isDomain(file, stmt.moduleSpecifier.text))
|
|
28993
|
+
continue;
|
|
28994
|
+
const clause = stmt.importClause;
|
|
28995
|
+
if (clause?.name)
|
|
28996
|
+
domainNames.add(clause.name.text);
|
|
28997
|
+
const bindings = clause?.namedBindings;
|
|
28998
|
+
if (bindings && ts.isNamespaceImport(bindings))
|
|
28999
|
+
domainNames.add(bindings.name.text);
|
|
29000
|
+
if (bindings && ts.isNamedImports(bindings))
|
|
29001
|
+
bindings.elements.forEach((e) => domainNames.add(e.name.text));
|
|
29002
|
+
}
|
|
29003
|
+
const bind = (node2) => {
|
|
29004
|
+
if (ts.isVariableDeclaration(node2) && ts.isIdentifier(node2.name) && node2.initializer && ts.isNewExpression(node2.initializer) && domainNames.has(node2.initializer.expression.getText(sf))) {
|
|
29005
|
+
domainNames.add(node2.name.text);
|
|
29006
|
+
}
|
|
29007
|
+
ts.forEachChild(node2, bind);
|
|
29008
|
+
};
|
|
29009
|
+
bind(sf);
|
|
29010
|
+
const flag = (node2, message) => {
|
|
29011
|
+
violations.push({ file, line: lineOf(sf, node2), rule: "no-internal-mock", message });
|
|
29012
|
+
};
|
|
29013
|
+
const visit2 = (node2) => {
|
|
29014
|
+
if (ts.isCallExpression(node2)) {
|
|
29015
|
+
const callee = node2.expression;
|
|
29016
|
+
const first = node2.arguments[0];
|
|
29017
|
+
if (ts.isPropertyAccessExpression(callee)) {
|
|
29018
|
+
const target = first && ts.isStringLiteralLike(first) ? first.text : undefined;
|
|
29019
|
+
if (MOCK_MODULE_MEMBERS.has(callee.name.text) && target !== undefined && isDomain(file, target)) {
|
|
29020
|
+
flag(node2, `${callee.getText(sf)} on domain module ${target}`);
|
|
29021
|
+
}
|
|
29022
|
+
}
|
|
29023
|
+
const calleeName = ts.isPropertyAccessExpression(callee) ? callee.name.text : callee.getText(sf);
|
|
29024
|
+
const spied = first && ts.isPropertyAccessExpression(first) && first.name.text === "prototype" ? first.expression : first;
|
|
29025
|
+
if (calleeName === "spyOn" && spied && ts.isIdentifier(spied) && domainNames.has(spied.text)) {
|
|
29026
|
+
flag(node2, `spyOn on domain import ${spied.text}`);
|
|
29027
|
+
}
|
|
29028
|
+
}
|
|
29029
|
+
ts.forEachChild(node2, visit2);
|
|
29030
|
+
};
|
|
29031
|
+
visit2(sf);
|
|
29032
|
+
}
|
|
29033
|
+
return violations;
|
|
29034
|
+
}
|
|
29035
|
+
var DEFAULT_LIMITS, MOCK_MODULE_MEMBERS;
|
|
29036
|
+
var init_gatekeeper = __esm(() => {
|
|
29037
|
+
DEFAULT_LIMITS = { maxParams: 4, maxLines: 250, maxComplexity: 10 };
|
|
29038
|
+
MOCK_MODULE_MEMBERS = new Set(["module", "mock", "doMock", "unstable_mockModule"]);
|
|
29039
|
+
});
|
|
29040
|
+
|
|
29041
|
+
// src/core/verification/harness/git.ts
|
|
29042
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
29043
|
+
import { promisify as promisify5 } from "node:util";
|
|
29044
|
+
async function runGit(root, args) {
|
|
29045
|
+
try {
|
|
29046
|
+
const { stdout } = await execFileAsync5("git", ["-c", "core.fsmonitor=false", ...args], {
|
|
29047
|
+
cwd: root,
|
|
29048
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
29049
|
+
env: { ...process.env, GIT_CONFIG_NOSYSTEM: "1" }
|
|
29050
|
+
});
|
|
29051
|
+
return stdout;
|
|
29052
|
+
} catch {
|
|
29053
|
+
return null;
|
|
29054
|
+
}
|
|
29055
|
+
}
|
|
29056
|
+
var execFileAsync5;
|
|
29057
|
+
var init_git = __esm(() => {
|
|
29058
|
+
execFileAsync5 = promisify5(execFile5);
|
|
29059
|
+
});
|
|
29060
|
+
|
|
29061
|
+
// src/core/verification/harness/symbol-map.ts
|
|
29062
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
29063
|
+
import { readdir as readdir12, readFile as readFile40 } from "node:fs/promises";
|
|
29064
|
+
import { join as join27, relative as relative12 } from "node:path";
|
|
29065
|
+
import ts2 from "typescript";
|
|
29066
|
+
function isExported(node2) {
|
|
29067
|
+
return ts2.canHaveModifiers(node2) && (ts2.getModifiers(node2) ?? []).some((m) => m.kind === ts2.SyntaxKind.ExportKeyword);
|
|
29068
|
+
}
|
|
29069
|
+
function callSignature(fn, sf) {
|
|
29070
|
+
const params = fn.parameters.map((p) => p.getText(sf)).join(", ");
|
|
29071
|
+
return `(${params})${fn.type ? `: ${fn.type.getText(sf)}` : ""}`;
|
|
29072
|
+
}
|
|
29073
|
+
function isPrivate(member) {
|
|
29074
|
+
const flags = ts2.getCombinedModifierFlags(member);
|
|
29075
|
+
return (flags & (ts2.ModifierFlags.Private | ts2.ModifierFlags.Protected)) !== 0 || !!member.name && ts2.isPrivateIdentifier(member.name);
|
|
29076
|
+
}
|
|
29077
|
+
function classMembers(node2, sf) {
|
|
29078
|
+
const out = [];
|
|
29079
|
+
for (const m of node2.members) {
|
|
29080
|
+
if (isPrivate(m) || !m.name)
|
|
29081
|
+
continue;
|
|
29082
|
+
if (ts2.isMethodDeclaration(m))
|
|
29083
|
+
out.push(`${m.name.getText(sf)}${callSignature(m, sf)}`);
|
|
29084
|
+
else if (ts2.isPropertyDeclaration(m))
|
|
29085
|
+
out.push(`${m.name.getText(sf)}${m.type ? `: ${m.type.getText(sf)}` : ""}`);
|
|
29086
|
+
}
|
|
29087
|
+
return out;
|
|
29088
|
+
}
|
|
29089
|
+
function interfaceMembers(node2, sf) {
|
|
29090
|
+
return node2.members.map((m) => m.getText(sf).replace(/[;,]\s*$/, ""));
|
|
29091
|
+
}
|
|
29092
|
+
function extractSymbols(sf) {
|
|
29093
|
+
const out = [];
|
|
29094
|
+
for (const node2 of sf.statements) {
|
|
29095
|
+
if (!isExported(node2))
|
|
29096
|
+
continue;
|
|
29097
|
+
if (ts2.isClassDeclaration(node2) && node2.name) {
|
|
29098
|
+
const heritage = node2.heritageClauses?.map((h) => h.getText(sf)).join(" ") ?? "";
|
|
29099
|
+
out.push({
|
|
29100
|
+
name: node2.name.text,
|
|
29101
|
+
kind: "class",
|
|
29102
|
+
signature: `class ${node2.name.text}${heritage ? ` ${heritage}` : ""}`,
|
|
29103
|
+
members: classMembers(node2, sf)
|
|
29104
|
+
});
|
|
29105
|
+
} else if (ts2.isFunctionDeclaration(node2) && node2.name) {
|
|
29106
|
+
out.push({ name: node2.name.text, kind: "function", signature: callSignature(node2, sf) });
|
|
29107
|
+
} else if (ts2.isInterfaceDeclaration(node2)) {
|
|
29108
|
+
out.push({
|
|
29109
|
+
name: node2.name.text,
|
|
29110
|
+
kind: "interface",
|
|
29111
|
+
signature: `interface ${node2.name.text}`,
|
|
29112
|
+
members: interfaceMembers(node2, sf)
|
|
29113
|
+
});
|
|
29114
|
+
} else if (ts2.isTypeAliasDeclaration(node2)) {
|
|
29115
|
+
out.push({ name: node2.name.text, kind: "type", signature: node2.type.getText(sf) });
|
|
29116
|
+
} else if (ts2.isEnumDeclaration(node2)) {
|
|
29117
|
+
out.push({ name: node2.name.text, kind: "enum", signature: `enum ${node2.name.text}` });
|
|
29118
|
+
} else if (ts2.isVariableStatement(node2)) {
|
|
29119
|
+
for (const d of node2.declarationList.declarations) {
|
|
29120
|
+
if (ts2.isIdentifier(d.name)) {
|
|
29121
|
+
out.push({ name: d.name.text, kind: "const", signature: d.type ? d.type.getText(sf) : "" });
|
|
29122
|
+
}
|
|
29123
|
+
}
|
|
29124
|
+
}
|
|
29125
|
+
}
|
|
29126
|
+
return out;
|
|
29127
|
+
}
|
|
29128
|
+
function isSourceFile(name) {
|
|
29129
|
+
return name.endsWith(".ts") && !name.endsWith(".d.ts") && !name.endsWith(".test.ts");
|
|
29130
|
+
}
|
|
29131
|
+
async function listSourceFiles(root) {
|
|
29132
|
+
const files = [];
|
|
29133
|
+
const walk = async (dir) => {
|
|
29134
|
+
for (const entry of await readdir12(dir, { withFileTypes: true })) {
|
|
29135
|
+
if (entry.isDirectory()) {
|
|
29136
|
+
if (!IGNORED_DIRS.has(entry.name))
|
|
29137
|
+
await walk(join27(dir, entry.name));
|
|
29138
|
+
} else if (entry.isFile() && isSourceFile(entry.name)) {
|
|
29139
|
+
files.push(join27(dir, entry.name));
|
|
29140
|
+
}
|
|
29141
|
+
}
|
|
29142
|
+
};
|
|
29143
|
+
await walk(root);
|
|
29144
|
+
return files.sort();
|
|
29145
|
+
}
|
|
29146
|
+
async function readExistingMap(path) {
|
|
29147
|
+
try {
|
|
29148
|
+
return JSON.parse(await readFile40(path, "utf-8"));
|
|
29149
|
+
} catch (e) {
|
|
29150
|
+
if (e.code === "ENOENT")
|
|
29151
|
+
return null;
|
|
29152
|
+
throw e;
|
|
29153
|
+
}
|
|
29154
|
+
}
|
|
29155
|
+
async function headSha(root) {
|
|
29156
|
+
return (await runGit(root, ["rev-parse", "HEAD"]) ?? "untracked").trim();
|
|
29157
|
+
}
|
|
29158
|
+
async function buildSymbolMap(root, outPath) {
|
|
29159
|
+
const cached = (await readExistingMap(outPath))?.modules ?? {};
|
|
29160
|
+
const modules = {};
|
|
29161
|
+
let parsed = 0;
|
|
29162
|
+
let reused = 0;
|
|
29163
|
+
for (const file of await listSourceFiles(root)) {
|
|
29164
|
+
const key = relative12(root, file).replace(/\\/g, "/");
|
|
29165
|
+
const text = await readFile40(file, "utf-8");
|
|
29166
|
+
const sha2563 = createHash8("sha256").update(text).digest("hex");
|
|
29167
|
+
const hit = cached[key];
|
|
29168
|
+
if (hit && hit.sha256 === sha2563) {
|
|
29169
|
+
modules[key] = hit;
|
|
29170
|
+
reused++;
|
|
29171
|
+
continue;
|
|
29172
|
+
}
|
|
29173
|
+
const symbols = extractSymbols(ts2.createSourceFile(file, text, ts2.ScriptTarget.Latest, true));
|
|
29174
|
+
parsed++;
|
|
29175
|
+
if (symbols.length > 0)
|
|
29176
|
+
modules[key] = { sha256: sha2563, symbols };
|
|
29177
|
+
}
|
|
29178
|
+
const map = { baseCommitSha: await headSha(root), modules };
|
|
29179
|
+
await writeContainedFile(root, relative12(root, outPath), JSON.stringify(map, null, 2), { force: true });
|
|
29180
|
+
return { map, parsed, reused };
|
|
29181
|
+
}
|
|
29182
|
+
function isTracked(symbol) {
|
|
29183
|
+
const generic = symbol.kind === "function" || symbol.kind === "const";
|
|
29184
|
+
return !generic || symbol.name.length >= MIN_FUNCTION_NAME_LENGTH;
|
|
29185
|
+
}
|
|
29186
|
+
async function findCollisions(mapPath, stubFiles, root) {
|
|
29187
|
+
const map = await readExistingMap(mapPath);
|
|
29188
|
+
if (!map)
|
|
29189
|
+
return [];
|
|
29190
|
+
const registry = new Map;
|
|
29191
|
+
for (const [file, mod] of Object.entries(map.modules)) {
|
|
29192
|
+
for (const symbol of mod.symbols) {
|
|
29193
|
+
if (isTracked(symbol))
|
|
29194
|
+
registry.set(symbol.name, [...registry.get(symbol.name) ?? [], file]);
|
|
29195
|
+
}
|
|
29196
|
+
}
|
|
29197
|
+
const collisions = [];
|
|
29198
|
+
for (const stub of stubFiles) {
|
|
29199
|
+
const stubFile = relative12(root, stub).replace(/\\/g, "/");
|
|
29200
|
+
const sf = ts2.createSourceFile(stub, await readFile40(stub, "utf-8"), ts2.ScriptTarget.Latest, true);
|
|
29201
|
+
for (const symbol of extractSymbols(sf)) {
|
|
29202
|
+
const existingFile = registry.get(symbol.name)?.find((f) => f !== stubFile);
|
|
29203
|
+
if (isTracked(symbol) && existingFile !== undefined) {
|
|
29204
|
+
collisions.push({ name: symbol.name, stubFile, existingFile });
|
|
29205
|
+
}
|
|
29206
|
+
}
|
|
29207
|
+
}
|
|
29208
|
+
return collisions;
|
|
29209
|
+
}
|
|
29210
|
+
var IGNORED_DIRS, MIN_FUNCTION_NAME_LENGTH = 13;
|
|
29211
|
+
var init_symbol_map = __esm(() => {
|
|
29212
|
+
init_path_containment();
|
|
29213
|
+
init_git();
|
|
29214
|
+
IGNORED_DIRS = new Set(["node_modules", ".git", "dist", "test", "tests", ".worktrees"]);
|
|
29215
|
+
});
|
|
29216
|
+
|
|
29217
|
+
// src/core/verification/test-freeze.ts
|
|
29218
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
29219
|
+
import { constants as constants3 } from "node:fs";
|
|
29220
|
+
import { readdir as readdir13, readFile as readFile41, open as open3, lstat as lstat3 } from "node:fs/promises";
|
|
29221
|
+
import { join as join28, relative as relative13, isAbsolute as isAbsolute6 } from "node:path";
|
|
29222
|
+
async function collectFiles(dirs, basePath) {
|
|
29223
|
+
const allFiles = [];
|
|
29224
|
+
async function walk(currentPath) {
|
|
29225
|
+
try {
|
|
29226
|
+
const s = await lstat3(currentPath);
|
|
29227
|
+
if (s.isSymbolicLink()) {
|
|
29228
|
+
throw new Error(`Symlink in sealed set: ${relative13(basePath, currentPath)}`);
|
|
29229
|
+
}
|
|
29230
|
+
if (s.isDirectory()) {
|
|
29231
|
+
const entries = await readdir13(currentPath, { withFileTypes: true });
|
|
29232
|
+
for (const entry of entries) {
|
|
29233
|
+
await walk(join28(currentPath, entry.name));
|
|
29234
|
+
}
|
|
29235
|
+
} else if (s.isFile()) {
|
|
29236
|
+
allFiles.push(relative13(basePath, currentPath));
|
|
29237
|
+
}
|
|
29238
|
+
} catch (e) {
|
|
29239
|
+
if (e.code !== "ENOENT") {
|
|
29240
|
+
throw e;
|
|
29241
|
+
}
|
|
29242
|
+
}
|
|
29243
|
+
}
|
|
29244
|
+
for (const dir of dirs) {
|
|
29245
|
+
const fullDir = isAbsolute6(dir) ? dir : join28(basePath, dir);
|
|
29246
|
+
await walk(fullDir);
|
|
29247
|
+
}
|
|
29248
|
+
return allFiles.sort();
|
|
29249
|
+
}
|
|
29250
|
+
async function hashFile2(filePath) {
|
|
29251
|
+
const content = await readFile41(filePath);
|
|
29252
|
+
return createHash9("sha256").update(content).digest("hex");
|
|
29253
|
+
}
|
|
29254
|
+
async function freezeTestSuite(dirs, lockDir, basePath = process.cwd()) {
|
|
29255
|
+
const files = await collectFiles(dirs, basePath);
|
|
29256
|
+
const fileInfos = [];
|
|
29257
|
+
for (const file of files) {
|
|
29258
|
+
const hash = await hashFile2(join28(basePath, file));
|
|
29259
|
+
fileInfos.push({ path: file, hash });
|
|
29260
|
+
}
|
|
29261
|
+
const hashContent = fileInfos.map((f) => `${f.path}\x00${f.hash}`).join(`
|
|
29262
|
+
`);
|
|
29263
|
+
const aggregateHash = createHash9("sha256").update(hashContent).digest("hex");
|
|
29264
|
+
const manifest = {
|
|
29265
|
+
hash: aggregateHash,
|
|
29266
|
+
files: fileInfos,
|
|
29267
|
+
frozenAt: new Date().toISOString()
|
|
29268
|
+
};
|
|
29269
|
+
const flags = constants3.O_WRONLY | constants3.O_CREAT | constants3.O_TRUNC | (constants3.O_NOFOLLOW ?? 0);
|
|
29270
|
+
const handle = await open3(join28(lockDir, FREEZE_LOCK_FILE), flags, 420);
|
|
29271
|
+
try {
|
|
29272
|
+
await handle.writeFile(JSON.stringify(manifest, null, 2), "utf-8");
|
|
29273
|
+
} finally {
|
|
29274
|
+
await handle.close();
|
|
29275
|
+
}
|
|
29276
|
+
return manifest;
|
|
29277
|
+
}
|
|
29278
|
+
async function verifyTestFreeze(lockPath, dirs, basePath) {
|
|
29279
|
+
const manifest = await readFreezeLock(lockPath);
|
|
29280
|
+
if (!manifest) {
|
|
29281
|
+
throw new Error("Lock file not found");
|
|
29282
|
+
}
|
|
29283
|
+
const files = await collectFiles(dirs, basePath);
|
|
29284
|
+
const fileInfos = [];
|
|
29285
|
+
for (const file of files) {
|
|
29286
|
+
const hash = await hashFile2(join28(basePath, file));
|
|
29287
|
+
fileInfos.push({ path: file, hash });
|
|
29288
|
+
}
|
|
29289
|
+
const hashContent = fileInfos.map((f) => `${f.path}\x00${f.hash}`).join(`
|
|
29290
|
+
`);
|
|
29291
|
+
const aggregateHash = createHash9("sha256").update(hashContent).digest("hex");
|
|
29292
|
+
const tamperedFiles = [];
|
|
29293
|
+
const manifestFileMap = new Map(manifest.files.map((f) => [f.path, f.hash]));
|
|
29294
|
+
const currentFileMap = new Map(fileInfos.map((f) => [f.path, f.hash]));
|
|
29295
|
+
for (const [path, hash] of currentFileMap.entries()) {
|
|
29296
|
+
if (manifestFileMap.get(path) !== hash) {
|
|
29297
|
+
tamperedFiles.push(path);
|
|
29298
|
+
}
|
|
29299
|
+
}
|
|
29300
|
+
for (const [path] of manifestFileMap.entries()) {
|
|
29301
|
+
if (!currentFileMap.has(path) && !tamperedFiles.includes(path)) {
|
|
29302
|
+
tamperedFiles.push(path);
|
|
29303
|
+
}
|
|
29304
|
+
}
|
|
29305
|
+
tamperedFiles.sort();
|
|
29306
|
+
return {
|
|
29307
|
+
valid: aggregateHash === manifest.hash && tamperedFiles.length === 0,
|
|
29308
|
+
expectedHash: manifest.hash,
|
|
29309
|
+
actualHash: aggregateHash,
|
|
29310
|
+
tamperedFiles
|
|
29311
|
+
};
|
|
29312
|
+
}
|
|
29313
|
+
async function readFreezeLock(lockPath) {
|
|
29314
|
+
try {
|
|
29315
|
+
const content = await readFile41(lockPath, "utf-8");
|
|
29316
|
+
return FreezeManifestSchema.parse(JSON.parse(content));
|
|
29317
|
+
} catch (e) {
|
|
29318
|
+
if (e.code === "ENOENT") {
|
|
29319
|
+
return null;
|
|
29320
|
+
}
|
|
29321
|
+
throw e;
|
|
29322
|
+
}
|
|
29323
|
+
}
|
|
29324
|
+
var FREEZE_LOCK_FILE = "test-freeze.lock", FreezeManifestSchema;
|
|
29325
|
+
var init_test_freeze = __esm(() => {
|
|
29326
|
+
init_zod();
|
|
29327
|
+
FreezeManifestSchema = exports_external.object({
|
|
29328
|
+
hash: exports_external.string(),
|
|
29329
|
+
files: exports_external.array(exports_external.object({ path: exports_external.string(), hash: exports_external.string() })),
|
|
29330
|
+
frozenAt: exports_external.string()
|
|
29331
|
+
});
|
|
29332
|
+
});
|
|
29333
|
+
|
|
29334
|
+
// src/commands/harness.command.ts
|
|
29335
|
+
var exports_harness_command = {};
|
|
29336
|
+
__export(exports_harness_command, {
|
|
29337
|
+
harnessCommand: () => harnessCommand
|
|
29338
|
+
});
|
|
29339
|
+
import { lstat as lstat4, mkdir as mkdir25 } from "node:fs/promises";
|
|
29340
|
+
import { join as join29, relative as relative14, resolve as resolve38 } from "node:path";
|
|
29341
|
+
function fail2(command, errors3) {
|
|
29342
|
+
return { code: 1, data: { success: false, command, errors: errors3 } };
|
|
29343
|
+
}
|
|
29344
|
+
function report(command, ok2, payload, summary) {
|
|
29345
|
+
return { code: ok2 ? 0 : 1, data: { success: ok2, command, ...payload, output: summary } };
|
|
29346
|
+
}
|
|
29347
|
+
async function existingPath(root, rel) {
|
|
29348
|
+
return resolveWithinRoot(root, rel).catch(() => {
|
|
29349
|
+
return;
|
|
29350
|
+
});
|
|
29351
|
+
}
|
|
29352
|
+
async function outputPath(root, rel) {
|
|
29353
|
+
return resolveOutputWithinRoot(root, rel).catch(() => {
|
|
29354
|
+
return;
|
|
29355
|
+
});
|
|
29356
|
+
}
|
|
29357
|
+
async function harnessCommand(options) {
|
|
29358
|
+
const command = `harness ${options.subcommand}`;
|
|
29359
|
+
const root = resolve38(options.projectRoot);
|
|
29360
|
+
const rels = options.paths ?? [];
|
|
29361
|
+
const needsPaths = ["seal", "verify-seal", "check-code", "check-tests", "collisions"];
|
|
29362
|
+
if (needsPaths.includes(options.subcommand) && rels.length === 0)
|
|
29363
|
+
return fail2(command, [`Usage: ${USAGE4}`]);
|
|
29364
|
+
const abs = [];
|
|
29365
|
+
for (const rel of rels) {
|
|
29366
|
+
const real = await existingPath(root, rel);
|
|
29367
|
+
if (!real)
|
|
29368
|
+
return fail2(command, [`Path is missing or escapes the project root: ${rel}`]);
|
|
29369
|
+
abs.push(real);
|
|
29370
|
+
}
|
|
29371
|
+
try {
|
|
29372
|
+
switch (options.subcommand) {
|
|
29373
|
+
case "seal":
|
|
29374
|
+
return await seal(command, root, rels, options);
|
|
29375
|
+
case "verify-seal":
|
|
29376
|
+
return await verifySeal(command, root, rels, options);
|
|
29377
|
+
case "check-code":
|
|
29378
|
+
return await checkCode(command, abs);
|
|
29379
|
+
case "check-tests":
|
|
29380
|
+
return await checkTests(command, root, abs, options);
|
|
29381
|
+
case "index":
|
|
29382
|
+
return await index(command, root, options);
|
|
29383
|
+
case "collisions":
|
|
29384
|
+
return await collisions(command, root, abs, options);
|
|
29385
|
+
default:
|
|
29386
|
+
return fail2(command, [`Usage: ${USAGE4}`]);
|
|
29387
|
+
}
|
|
29388
|
+
} catch (e) {
|
|
29389
|
+
return fail2(command, [e instanceof Error ? e.message : String(e)]);
|
|
29390
|
+
}
|
|
29391
|
+
}
|
|
29392
|
+
async function lockDirOf(root, options) {
|
|
29393
|
+
return outputPath(root, options.lockDir ?? DEFAULT_LOCK_DIR);
|
|
29394
|
+
}
|
|
29395
|
+
async function seal(command, root, rels, options) {
|
|
29396
|
+
const lockDir = await lockDirOf(root, options);
|
|
29397
|
+
if (!lockDir)
|
|
29398
|
+
return fail2(command, ["Lock dir is not an allowed destination"]);
|
|
29399
|
+
const lockPath = join29(lockDir, FREEZE_LOCK_FILE);
|
|
29400
|
+
const existing = await lstat4(lockPath).catch(() => {
|
|
29401
|
+
return;
|
|
29402
|
+
});
|
|
29403
|
+
if (existing?.isSymbolicLink())
|
|
29404
|
+
return fail2(command, ["Lock file is a symlink"]);
|
|
29405
|
+
if (existing && options.force !== true) {
|
|
29406
|
+
return fail2(command, ["A seal already exists; re-sealing replaces it. Pass --force to confirm."]);
|
|
29407
|
+
}
|
|
29408
|
+
await mkdir25(lockDir, { recursive: true });
|
|
29409
|
+
const manifest = await freezeTestSuite([...rels], lockDir, root);
|
|
29410
|
+
return report(command, true, { hash: manifest.hash, files: manifest.files.length }, `Sealed ${manifest.files.length} files (${manifest.hash}). Keep the hash outside the working tree and pass it to verify-seal --expected-hash.`);
|
|
29411
|
+
}
|
|
29412
|
+
async function verifySeal(command, root, rels, options) {
|
|
29413
|
+
const lockDir = await lockDirOf(root, options);
|
|
29414
|
+
if (!lockDir)
|
|
29415
|
+
return fail2(command, ["Lock dir is not an allowed destination"]);
|
|
29416
|
+
const result = await verifyTestFreeze(join29(lockDir, FREEZE_LOCK_FILE), [...rels], root);
|
|
29417
|
+
const anchored = options.expectedHash === undefined || result.actualHash === options.expectedHash;
|
|
29418
|
+
const ok2 = result.valid && anchored;
|
|
29419
|
+
return report(command, ok2, { tamperedFiles: result.tamperedFiles, hash: result.actualHash }, ok2 ? "Seal intact." : `Seal violated: ${result.tamperedFiles.join(", ") || (anchored ? "lock inconsistent" : "hash differs from --expected-hash")}`);
|
|
29420
|
+
}
|
|
29421
|
+
async function checkCode(command, files) {
|
|
29422
|
+
const violations = await checkProductionFiles(files);
|
|
29423
|
+
return report(command, violations.length === 0, { violations }, `${violations.length} violation(s).`);
|
|
29424
|
+
}
|
|
29425
|
+
async function checkTests(command, root, files, options) {
|
|
29426
|
+
const violations = await checkTestFiles(files, options.domain ?? DEFAULT_DOMAIN, root);
|
|
29427
|
+
return report(command, violations.length === 0, { violations }, `${violations.length} violation(s).`);
|
|
29428
|
+
}
|
|
29429
|
+
async function index(command, root, options) {
|
|
29430
|
+
const out = await outputPath(root, options.outFile ?? DEFAULT_MAP);
|
|
29431
|
+
if (!out)
|
|
29432
|
+
return fail2(command, ["Output path is not an allowed destination"]);
|
|
29433
|
+
const { map, parsed, reused } = await buildSymbolMap(root, out);
|
|
29434
|
+
const modules = Object.keys(map.modules).length;
|
|
29435
|
+
return report(command, true, { modules, parsed, reused, path: relative14(root, out) }, `Indexed ${modules} modules (${parsed} parsed, ${reused} reused).`);
|
|
29436
|
+
}
|
|
29437
|
+
async function collisions(command, root, files, options) {
|
|
29438
|
+
const map = await outputPath(root, options.mapFile ?? DEFAULT_MAP);
|
|
29439
|
+
if (!map)
|
|
29440
|
+
return fail2(command, ["Map path is not an allowed destination"]);
|
|
29441
|
+
const found = await findCollisions(map, files, root);
|
|
29442
|
+
return report(command, found.length === 0, { collisions: found }, `${found.length} collision(s).`);
|
|
29443
|
+
}
|
|
29444
|
+
var DEFAULT_DOMAIN, DEFAULT_LOCK_DIR = ".harness", DEFAULT_MAP = "SYMBOL_MAP.json", USAGE4;
|
|
29445
|
+
var init_harness_command = __esm(() => {
|
|
29446
|
+
init_gatekeeper();
|
|
29447
|
+
init_symbol_map();
|
|
29448
|
+
init_test_freeze();
|
|
29449
|
+
init_path_containment();
|
|
29450
|
+
DEFAULT_DOMAIN = ["src/core/**"];
|
|
29451
|
+
USAGE4 = [
|
|
29452
|
+
"harness seal --paths <dirs|files> [--lock-dir <dir>] [--force]",
|
|
29453
|
+
"harness verify-seal --paths <dirs|files> [--lock-dir <dir>] [--expected-hash <sha256>]",
|
|
29454
|
+
"harness check-code --paths <files>",
|
|
29455
|
+
"harness check-tests --paths <files> [--domain <globs>]",
|
|
29456
|
+
"harness index [--out <file>]",
|
|
29457
|
+
"harness collisions --paths <files> [--map <file>]"
|
|
29458
|
+
].join(`
|
|
29459
|
+
`);
|
|
29460
|
+
});
|
|
29461
|
+
|
|
28751
29462
|
// src/commands/rdd.command.ts
|
|
28752
29463
|
var exports_rdd_command = {};
|
|
28753
29464
|
__export(exports_rdd_command, {
|
|
28754
29465
|
rddCommand: () => rddCommand,
|
|
28755
29466
|
rddStatus: () => rddStatus
|
|
28756
29467
|
});
|
|
28757
|
-
import { execFile as
|
|
29468
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
28758
29469
|
import { existsSync as existsSync6 } from "node:fs";
|
|
28759
|
-
import { mkdir as
|
|
28760
|
-
import { dirname as
|
|
28761
|
-
import { promisify as
|
|
29470
|
+
import { mkdir as mkdir26, readFile as readFile42, readdir as readdir14, rename as rename5, writeFile as writeFile25, chmod } from "node:fs/promises";
|
|
29471
|
+
import { dirname as dirname14, resolve as resolve39 } from "node:path";
|
|
29472
|
+
import { promisify as promisify6 } from "node:util";
|
|
28762
29473
|
function receiptPath(projectRoot, id) {
|
|
28763
|
-
const directory =
|
|
28764
|
-
const path =
|
|
28765
|
-
if (
|
|
29474
|
+
const directory = resolve39(evidenceDir(projectRoot));
|
|
29475
|
+
const path = resolve39(directory, `${id.replace(/[^A-Za-z0-9_-]/g, "_")}.json`);
|
|
29476
|
+
if (dirname14(path) !== directory)
|
|
28766
29477
|
throw new Error(`Invalid RDD receipt id: ${id}`);
|
|
28767
29478
|
return path;
|
|
28768
29479
|
}
|
|
28769
29480
|
async function loadReceipt(projectRoot, id) {
|
|
28770
|
-
const raw = await
|
|
29481
|
+
const raw = await readFile42(receiptPath(projectRoot, id), "utf-8");
|
|
28771
29482
|
const evidence = EvidenceSchema.parse(JSON.parse(raw));
|
|
28772
29483
|
if (evidence.type !== "rdd")
|
|
28773
29484
|
throw new Error(`Evidence "${id}" is not an RDD receipt`);
|
|
@@ -28783,7 +29494,7 @@ async function rddStatus(projectRoot, taskId) {
|
|
|
28783
29494
|
if (!existsSync6(directory))
|
|
28784
29495
|
return [];
|
|
28785
29496
|
const receipts = [];
|
|
28786
|
-
for (const file of await
|
|
29497
|
+
for (const file of await readdir14(directory)) {
|
|
28787
29498
|
if (!file.endsWith(".json"))
|
|
28788
29499
|
continue;
|
|
28789
29500
|
try {
|
|
@@ -28805,20 +29516,20 @@ async function rddStatus(projectRoot, taskId) {
|
|
|
28805
29516
|
return receipts.sort((left, right) => right.timestamp.localeCompare(left.timestamp));
|
|
28806
29517
|
}
|
|
28807
29518
|
async function installHooks(projectRoot) {
|
|
28808
|
-
const { stdout } = await
|
|
29519
|
+
const { stdout } = await execFileAsync6("git", ["rev-parse", "--git-path", "hooks"], {
|
|
28809
29520
|
cwd: projectRoot,
|
|
28810
29521
|
encoding: "utf8"
|
|
28811
29522
|
});
|
|
28812
|
-
const hooksDir =
|
|
28813
|
-
await
|
|
29523
|
+
const hooksDir = resolve39(projectRoot, stdout.trim());
|
|
29524
|
+
await mkdir26(hooksDir, { recursive: true });
|
|
28814
29525
|
const installed = [];
|
|
28815
29526
|
const skipped = [];
|
|
28816
29527
|
for (const hook of ["pre-commit", "pre-push"]) {
|
|
28817
|
-
const path =
|
|
28818
|
-
const backup =
|
|
29528
|
+
const path = resolve39(hooksDir, hook);
|
|
29529
|
+
const backup = resolve39(hooksDir, `${hook}.rdd-original`);
|
|
28819
29530
|
const marker = "# codeconductor-rdd-hook";
|
|
28820
29531
|
if (existsSync6(path)) {
|
|
28821
|
-
const existing = await
|
|
29532
|
+
const existing = await readFile42(path, "utf8");
|
|
28822
29533
|
if (existing.includes(marker)) {
|
|
28823
29534
|
skipped.push(hook);
|
|
28824
29535
|
continue;
|
|
@@ -28869,7 +29580,7 @@ async function rddCommand(options) {
|
|
|
28869
29580
|
data: { rddReceipt: receipt }
|
|
28870
29581
|
};
|
|
28871
29582
|
const directory = evidenceDir(options.projectRoot);
|
|
28872
|
-
await
|
|
29583
|
+
await mkdir26(directory, { recursive: true });
|
|
28873
29584
|
await writeFile25(receiptPath(options.projectRoot, id), JSON.stringify(evidence, null, 2), "utf-8");
|
|
28874
29585
|
return { code: 0, data: { success: true, receiptId: id, receipt } };
|
|
28875
29586
|
}
|
|
@@ -28897,12 +29608,12 @@ async function rddCommand(options) {
|
|
|
28897
29608
|
return { code: 1, data: { success: false, errors: [error instanceof Error ? error.message : String(error)] } };
|
|
28898
29609
|
}
|
|
28899
29610
|
}
|
|
28900
|
-
var
|
|
29611
|
+
var execFileAsync6;
|
|
28901
29612
|
var init_rdd_command = __esm(() => {
|
|
28902
29613
|
init_schemas();
|
|
28903
29614
|
init_paths();
|
|
28904
29615
|
init_rdd_receipt();
|
|
28905
|
-
|
|
29616
|
+
execFileAsync6 = promisify6(execFile6);
|
|
28906
29617
|
});
|
|
28907
29618
|
|
|
28908
29619
|
// src/core/ccep/confirmation-gate.ts
|
|
@@ -29296,9 +30007,9 @@ var init_prompt_compiler = __esm(() => {
|
|
|
29296
30007
|
|
|
29297
30008
|
// src/core/ccep/command-parser.ts
|
|
29298
30009
|
import { existsSync as existsSync7, readFileSync as readFileSync5 } from "node:fs";
|
|
29299
|
-
import { basename as basename7, join as
|
|
30010
|
+
import { basename as basename7, join as join30 } from "node:path";
|
|
29300
30011
|
function readProjectId(projectRoot) {
|
|
29301
|
-
const packageJsonPath =
|
|
30012
|
+
const packageJsonPath = join30(projectRoot, "package.json");
|
|
29302
30013
|
if (existsSync7(packageJsonPath)) {
|
|
29303
30014
|
try {
|
|
29304
30015
|
const pkg = JSON.parse(readFileSync5(packageJsonPath, "utf-8"));
|
|
@@ -29328,7 +30039,7 @@ function parseCommand(command, userRequest, projectRoot) {
|
|
|
29328
30039
|
maxVariance: "low"
|
|
29329
30040
|
}
|
|
29330
30041
|
};
|
|
29331
|
-
const packageJsonPath =
|
|
30042
|
+
const packageJsonPath = join30(projectRoot, "package.json");
|
|
29332
30043
|
if (existsSync7(packageJsonPath)) {
|
|
29333
30044
|
try {
|
|
29334
30045
|
const pkg = JSON.parse(readFileSync5(packageJsonPath, "utf-8"));
|
|
@@ -29401,10 +30112,10 @@ var init_workflow_profile_loader = __esm(() => {
|
|
|
29401
30112
|
});
|
|
29402
30113
|
|
|
29403
30114
|
// src/core/evaluation/harness-catalog.ts
|
|
29404
|
-
import { createHash as
|
|
30115
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
29405
30116
|
import { existsSync as existsSync8, readFileSync as readFileSync6 } from "node:fs";
|
|
29406
|
-
import { copyFile as copyFile2, mkdir as
|
|
29407
|
-
import { dirname as
|
|
30117
|
+
import { copyFile as copyFile2, mkdir as mkdir27, readFile as readFile43, readdir as readdir15, rm as rm4, writeFile as writeFile26 } from "node:fs/promises";
|
|
30118
|
+
import { dirname as dirname15, join as join31, resolve as resolve40 } from "node:path";
|
|
29408
30119
|
function catalogIds(catalog = DEFAULT_HARNESS_CATALOG) {
|
|
29409
30120
|
return catalog.components.map((c) => c.id);
|
|
29410
30121
|
}
|
|
@@ -29454,23 +30165,23 @@ function harnessFingerprint(disabled, contractVersion, ccepProfile = "feature",
|
|
|
29454
30165
|
contractVersion,
|
|
29455
30166
|
ccepProfile
|
|
29456
30167
|
};
|
|
29457
|
-
return
|
|
30168
|
+
return createHash10("sha256").update(JSON.stringify(payload)).digest("hex").slice(0, 16);
|
|
29458
30169
|
}
|
|
29459
30170
|
async function loadHarnessCatalog(projectRoot) {
|
|
29460
|
-
const overridePath =
|
|
30171
|
+
const overridePath = resolve40(projectRoot, EVAL_DIR2, CATALOG_FILE);
|
|
29461
30172
|
try {
|
|
29462
|
-
const raw = await
|
|
30173
|
+
const raw = await readFile43(overridePath, "utf-8");
|
|
29463
30174
|
return HarnessCatalogSchema.parse($parse(raw));
|
|
29464
30175
|
} catch {
|
|
29465
30176
|
return DEFAULT_HARNESS_CATALOG;
|
|
29466
30177
|
}
|
|
29467
30178
|
}
|
|
29468
30179
|
function activeOverlayPath(projectRoot) {
|
|
29469
|
-
return
|
|
30180
|
+
return resolve40(projectRoot, EVAL_DIR2, ACTIVE_OVERLAY_FILE);
|
|
29470
30181
|
}
|
|
29471
30182
|
async function readActiveOverlay(projectRoot) {
|
|
29472
30183
|
try {
|
|
29473
|
-
const raw = await
|
|
30184
|
+
const raw = await readFile43(activeOverlayPath(projectRoot), "utf-8");
|
|
29474
30185
|
return HarnessOverlaySchema.parse($parse(raw));
|
|
29475
30186
|
} catch {
|
|
29476
30187
|
return null;
|
|
@@ -29524,25 +30235,25 @@ function applyCatalogToProfile(profile, disabled) {
|
|
|
29524
30235
|
return next;
|
|
29525
30236
|
}
|
|
29526
30237
|
async function restoreOverlayBackup(projectRoot) {
|
|
29527
|
-
const backupRoot =
|
|
30238
|
+
const backupRoot = resolve40(projectRoot, EVAL_DIR2, OVERLAY_BACKUP_DIR);
|
|
29528
30239
|
if (!existsSync8(backupRoot))
|
|
29529
30240
|
return;
|
|
29530
|
-
const configBackup =
|
|
29531
|
-
const configDest =
|
|
30241
|
+
const configBackup = join31(backupRoot, "config.yml");
|
|
30242
|
+
const configDest = resolve40(projectRoot, ".codeconductor", "config.yml");
|
|
29532
30243
|
if (existsSync8(configBackup)) {
|
|
29533
|
-
await
|
|
30244
|
+
await mkdir27(dirname15(configDest), { recursive: true });
|
|
29534
30245
|
await copyFile2(configBackup, configDest);
|
|
29535
30246
|
}
|
|
29536
|
-
const workflowsBackup =
|
|
29537
|
-
const workflowsDest =
|
|
30247
|
+
const workflowsBackup = join31(backupRoot, "workflows");
|
|
30248
|
+
const workflowsDest = resolve40(projectRoot, ".codeconductor", "workflows");
|
|
29538
30249
|
if (existsSync8(workflowsBackup)) {
|
|
29539
|
-
await
|
|
29540
|
-
const files = await
|
|
30250
|
+
await mkdir27(workflowsDest, { recursive: true });
|
|
30251
|
+
const files = await readdir15(workflowsBackup);
|
|
29541
30252
|
for (const file of files) {
|
|
29542
|
-
await copyFile2(
|
|
30253
|
+
await copyFile2(join31(workflowsBackup, file), join31(workflowsDest, file));
|
|
29543
30254
|
}
|
|
29544
30255
|
}
|
|
29545
|
-
const overlayBackup =
|
|
30256
|
+
const overlayBackup = join31(backupRoot, ACTIVE_OVERLAY_FILE);
|
|
29546
30257
|
const overlayDest = activeOverlayPath(projectRoot);
|
|
29547
30258
|
if (existsSync8(overlayBackup)) {
|
|
29548
30259
|
await copyFile2(overlayBackup, overlayDest);
|
|
@@ -29551,28 +30262,28 @@ async function restoreOverlayBackup(projectRoot) {
|
|
|
29551
30262
|
}
|
|
29552
30263
|
}
|
|
29553
30264
|
async function snapshotForBackup(projectRoot) {
|
|
29554
|
-
const backupRoot =
|
|
30265
|
+
const backupRoot = resolve40(projectRoot, EVAL_DIR2, OVERLAY_BACKUP_DIR);
|
|
29555
30266
|
if (existsSync8(backupRoot))
|
|
29556
30267
|
return;
|
|
29557
|
-
await
|
|
29558
|
-
const configPath =
|
|
30268
|
+
await mkdir27(backupRoot, { recursive: true });
|
|
30269
|
+
const configPath = resolve40(projectRoot, ".codeconductor", "config.yml");
|
|
29559
30270
|
if (existsSync8(configPath)) {
|
|
29560
|
-
await copyFile2(configPath,
|
|
30271
|
+
await copyFile2(configPath, join31(backupRoot, "config.yml"));
|
|
29561
30272
|
}
|
|
29562
|
-
const workflowsDir =
|
|
30273
|
+
const workflowsDir = resolve40(projectRoot, ".codeconductor", "workflows");
|
|
29563
30274
|
if (existsSync8(workflowsDir)) {
|
|
29564
|
-
const dest =
|
|
29565
|
-
await
|
|
29566
|
-
const files = await
|
|
30275
|
+
const dest = join31(backupRoot, "workflows");
|
|
30276
|
+
await mkdir27(dest, { recursive: true });
|
|
30277
|
+
const files = await readdir15(workflowsDir);
|
|
29567
30278
|
for (const file of files) {
|
|
29568
30279
|
if (file.endsWith(".yml")) {
|
|
29569
|
-
await copyFile2(
|
|
30280
|
+
await copyFile2(join31(workflowsDir, file), join31(dest, file));
|
|
29570
30281
|
}
|
|
29571
30282
|
}
|
|
29572
30283
|
}
|
|
29573
30284
|
const overlay = activeOverlayPath(projectRoot);
|
|
29574
30285
|
if (existsSync8(overlay)) {
|
|
29575
|
-
await copyFile2(overlay,
|
|
30286
|
+
await copyFile2(overlay, join31(backupRoot, ACTIVE_OVERLAY_FILE));
|
|
29576
30287
|
}
|
|
29577
30288
|
}
|
|
29578
30289
|
async function applyHarnessOverlay(projectRoot, disabled, options = {}) {
|
|
@@ -29581,13 +30292,13 @@ async function applyHarnessOverlay(projectRoot, disabled, options = {}) {
|
|
|
29581
30292
|
await restoreOverlayBackup(projectRoot);
|
|
29582
30293
|
await snapshotForBackup(projectRoot);
|
|
29583
30294
|
}
|
|
29584
|
-
const workflowsDir =
|
|
29585
|
-
await
|
|
29586
|
-
await
|
|
30295
|
+
const workflowsDir = resolve40(projectRoot, ".codeconductor", "workflows");
|
|
30296
|
+
await mkdir27(workflowsDir, { recursive: true });
|
|
30297
|
+
await mkdir27(resolve40(projectRoot, EVAL_DIR2), { recursive: true });
|
|
29587
30298
|
for (const command of WORKFLOW_OVERLAY_COMMANDS) {
|
|
29588
30299
|
const base = loadWorkflowProfile(command);
|
|
29589
30300
|
const next = applyCatalogToProfile(base, disabled);
|
|
29590
|
-
await writeFile26(
|
|
30301
|
+
await writeFile26(join31(workflowsDir, `${command}.yml`), $stringify(next), "utf-8");
|
|
29591
30302
|
}
|
|
29592
30303
|
const needsConfig = disabled.includes("compile_loop") || disabled.includes("council");
|
|
29593
30304
|
if (needsConfig) {
|
|
@@ -29726,9 +30437,9 @@ var init_harness_catalog = __esm(() => {
|
|
|
29726
30437
|
});
|
|
29727
30438
|
|
|
29728
30439
|
// src/core/openspec/openspec-state.ts
|
|
29729
|
-
import { createHash as
|
|
29730
|
-
import { mkdir as
|
|
29731
|
-
import { resolve as
|
|
30440
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
30441
|
+
import { mkdir as mkdir28, readFile as readFile44, rename as rename6, writeFile as writeFile27 } from "node:fs/promises";
|
|
30442
|
+
import { resolve as resolve41 } from "node:path";
|
|
29732
30443
|
function canTransition(from, to) {
|
|
29733
30444
|
return ALLOWED_TRANSITIONS[from]?.includes(to) ?? false;
|
|
29734
30445
|
}
|
|
@@ -29754,8 +30465,8 @@ async function writeFileAtomic(path, content) {
|
|
|
29754
30465
|
}
|
|
29755
30466
|
async function loadOpenspecState(projectRoot) {
|
|
29756
30467
|
try {
|
|
29757
|
-
const filePath =
|
|
29758
|
-
const content = await
|
|
30468
|
+
const filePath = resolve41(projectRoot, STATE_FILE);
|
|
30469
|
+
const content = await readFile44(filePath, "utf-8");
|
|
29759
30470
|
const data = JSON.parse(content);
|
|
29760
30471
|
return ok(OpenspecStateSchema.parse(data));
|
|
29761
30472
|
} catch (e) {
|
|
@@ -29772,10 +30483,10 @@ async function loadOpenspecState(projectRoot) {
|
|
|
29772
30483
|
}
|
|
29773
30484
|
async function writeOpenspecState(projectRoot, state) {
|
|
29774
30485
|
try {
|
|
29775
|
-
const dir =
|
|
29776
|
-
await
|
|
30486
|
+
const dir = resolve41(projectRoot, ".codeconductor");
|
|
30487
|
+
await mkdir28(dir, { recursive: true });
|
|
29777
30488
|
const validated = OpenspecStateSchema.parse(state);
|
|
29778
|
-
await writeFileAtomic(
|
|
30489
|
+
await writeFileAtomic(resolve41(dir, "openspec-state.json"), JSON.stringify(validated, null, 2));
|
|
29779
30490
|
return ok(undefined);
|
|
29780
30491
|
} catch (e) {
|
|
29781
30492
|
return err(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -29797,7 +30508,7 @@ function getNextTaskCard(state) {
|
|
|
29797
30508
|
return null;
|
|
29798
30509
|
}
|
|
29799
30510
|
function hashContent(content) {
|
|
29800
|
-
return
|
|
30511
|
+
return createHash11("sha256").update(content).digest("hex").slice(0, 16);
|
|
29801
30512
|
}
|
|
29802
30513
|
function serializeItemSnapshot(item) {
|
|
29803
30514
|
return JSON.stringify({
|
|
@@ -29951,9 +30662,9 @@ var init_context_assembly = __esm(() => {
|
|
|
29951
30662
|
});
|
|
29952
30663
|
|
|
29953
30664
|
// src/core/ccep/scoped-rules.ts
|
|
29954
|
-
import { createHash as
|
|
29955
|
-
import { readdir as
|
|
29956
|
-
import { join as
|
|
30665
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
30666
|
+
import { readdir as readdir16 } from "node:fs/promises";
|
|
30667
|
+
import { join as join32, posix as posix2 } from "node:path";
|
|
29957
30668
|
async function readContained(projectRoot, relPath) {
|
|
29958
30669
|
try {
|
|
29959
30670
|
return await readFileWithinRoot(projectRoot, relPath);
|
|
@@ -30105,7 +30816,7 @@ function buildContextManifest(input) {
|
|
|
30105
30816
|
async function listRuleFiles(projectRoot, dir) {
|
|
30106
30817
|
let entries;
|
|
30107
30818
|
try {
|
|
30108
|
-
entries = await
|
|
30819
|
+
entries = await readdir16(join32(projectRoot, dir), { withFileTypes: true });
|
|
30109
30820
|
} catch {
|
|
30110
30821
|
return [];
|
|
30111
30822
|
}
|
|
@@ -30204,7 +30915,7 @@ async function resolveScopedContext(projectRoot, input) {
|
|
|
30204
30915
|
diagnostics
|
|
30205
30916
|
};
|
|
30206
30917
|
}
|
|
30207
|
-
var CLASS_RANK, RULES_DIR = ".codeconductor/rules", sha2563 = (value) =>
|
|
30918
|
+
var CLASS_RANK, RULES_DIR = ".codeconductor/rules", sha2563 = (value) => createHash12("sha256").update(value).digest("hex"), byText = (a, b) => a < b ? -1 : a > b ? 1 : 0, normalizeRoot = (root) => root === "." ? "." : posix2.normalize(root).replace(/\/$/, ""), depthOf = (root) => root === "." ? 0 : root.split("/").length, DEFAULT_RULES_BUDGET_BYTES = 16384;
|
|
30208
30919
|
var init_scoped_rules = __esm(() => {
|
|
30209
30920
|
init_dist();
|
|
30210
30921
|
init_path_containment();
|
|
@@ -30270,9 +30981,9 @@ var init_skill_selector = __esm(() => {
|
|
|
30270
30981
|
|
|
30271
30982
|
// src/core/ccep/context-resolver.ts
|
|
30272
30983
|
import { existsSync as existsSync9 } from "node:fs";
|
|
30273
|
-
import { readFile as
|
|
30274
|
-
import { join as
|
|
30275
|
-
import { createHash as
|
|
30984
|
+
import { readFile as readFile45 } from "node:fs/promises";
|
|
30985
|
+
import { join as join33 } from "node:path";
|
|
30986
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
30276
30987
|
async function loadProductKnowledge(projectRoot) {
|
|
30277
30988
|
if (isProductGraphDisabled(projectRoot)) {
|
|
30278
30989
|
return {};
|
|
@@ -30282,7 +30993,7 @@ async function loadProductKnowledge(projectRoot) {
|
|
|
30282
30993
|
return {};
|
|
30283
30994
|
}
|
|
30284
30995
|
try {
|
|
30285
|
-
const raw = await
|
|
30996
|
+
const raw = await readFile45(graphPath, "utf-8");
|
|
30286
30997
|
const graph = ProductGraphSchema.parse(JSON.parse(raw));
|
|
30287
30998
|
return {
|
|
30288
30999
|
productName: graph.productName,
|
|
@@ -30298,7 +31009,7 @@ async function loadProductKnowledge(projectRoot) {
|
|
|
30298
31009
|
}
|
|
30299
31010
|
async function resolveAstSource(projectRoot) {
|
|
30300
31011
|
if (isProductGraphDisabled(projectRoot)) {
|
|
30301
|
-
const graphifyPath2 =
|
|
31012
|
+
const graphifyPath2 = join33(projectRoot, "graphify-out", "graph.json");
|
|
30302
31013
|
if (existsSync9(graphifyPath2)) {
|
|
30303
31014
|
return { source: "graphify", confidence: "medium" };
|
|
30304
31015
|
}
|
|
@@ -30308,7 +31019,7 @@ async function resolveAstSource(projectRoot) {
|
|
|
30308
31019
|
if (existsSync9(graphPath)) {
|
|
30309
31020
|
return { source: "product-graph", confidence: "high" };
|
|
30310
31021
|
}
|
|
30311
|
-
const graphifyPath =
|
|
31022
|
+
const graphifyPath = join33(projectRoot, "graphify-out", "graph.json");
|
|
30312
31023
|
if (existsSync9(graphifyPath)) {
|
|
30313
31024
|
return { source: "graphify", confidence: "medium" };
|
|
30314
31025
|
}
|
|
@@ -30325,8 +31036,8 @@ async function publishedSkills(ids) {
|
|
|
30325
31036
|
const diagnostics = [];
|
|
30326
31037
|
for (const id of ids) {
|
|
30327
31038
|
try {
|
|
30328
|
-
const content = await
|
|
30329
|
-
skills.push({ id, version:
|
|
31039
|
+
const content = await readFile45(join33(ROOT_PRESETS_DIR, "claude", "skills", id, "SKILL.md"));
|
|
31040
|
+
skills.push({ id, version: createHash13("sha256").update(content).digest("hex") });
|
|
30330
31041
|
} catch {
|
|
30331
31042
|
diagnostics.push({ code: "skill_unreadable", severity: "warning", message: `Published SKILL.md for "${id}" is not readable` });
|
|
30332
31043
|
}
|
|
@@ -30937,8 +31648,8 @@ var exports_prompt_structurer = {};
|
|
|
30937
31648
|
__export(exports_prompt_structurer, {
|
|
30938
31649
|
structurePrompt: () => structurePrompt
|
|
30939
31650
|
});
|
|
30940
|
-
import { readFile as
|
|
30941
|
-
import { resolve as
|
|
31651
|
+
import { readFile as readFile46 } from "node:fs/promises";
|
|
31652
|
+
import { resolve as resolve42 } from "node:path";
|
|
30942
31653
|
function escapeXml(value) {
|
|
30943
31654
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
30944
31655
|
}
|
|
@@ -30955,7 +31666,7 @@ async function readPolicyBits(projectRoot) {
|
|
|
30955
31666
|
};
|
|
30956
31667
|
let raw;
|
|
30957
31668
|
try {
|
|
30958
|
-
raw = await
|
|
31669
|
+
raw = await readFile46(resolve42(projectRoot, "policy.yml"), "utf-8");
|
|
30959
31670
|
} catch {
|
|
30960
31671
|
return empty;
|
|
30961
31672
|
}
|
|
@@ -31126,8 +31837,8 @@ __export(exports_ballot_box, {
|
|
|
31126
31837
|
tallyBallots: () => tallyBallots
|
|
31127
31838
|
});
|
|
31128
31839
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
31129
|
-
import { appendFile as appendFile4, mkdir as
|
|
31130
|
-
import { resolve as
|
|
31840
|
+
import { appendFile as appendFile4, mkdir as mkdir29, readFile as readFile47, rename as rename7, unlink as unlink6, writeFile as writeFile28 } from "node:fs/promises";
|
|
31841
|
+
import { resolve as resolve43 } from "node:path";
|
|
31131
31842
|
function boxFileFor(preset) {
|
|
31132
31843
|
if (preset === DEFAULT_PRESET)
|
|
31133
31844
|
return ok(BOX_FILE);
|
|
@@ -31139,7 +31850,7 @@ function boxFileFor(preset) {
|
|
|
31139
31850
|
async function readBox(projectRoot, boxFile) {
|
|
31140
31851
|
let raw;
|
|
31141
31852
|
try {
|
|
31142
|
-
raw = await
|
|
31853
|
+
raw = await readFile47(resolve43(projectRoot, boxFile), "utf-8");
|
|
31143
31854
|
} catch (e) {
|
|
31144
31855
|
if (e.code === "ENOENT")
|
|
31145
31856
|
return ok([]);
|
|
@@ -31155,22 +31866,22 @@ async function readBox(projectRoot, boxFile) {
|
|
|
31155
31866
|
return err(new Error("Ballot box is corrupt: expected a JSON array"));
|
|
31156
31867
|
}
|
|
31157
31868
|
const ballots = [];
|
|
31158
|
-
for (const [
|
|
31869
|
+
for (const [index2, entry] of parsed.entries()) {
|
|
31159
31870
|
const validated = CouncilVerdictInputSchema.safeParse(entry);
|
|
31160
31871
|
if (!validated.success) {
|
|
31161
|
-
return err(new Error(`Ballot box is corrupt at index ${
|
|
31872
|
+
return err(new Error(`Ballot box is corrupt at index ${index2}`));
|
|
31162
31873
|
}
|
|
31163
31874
|
ballots.push(validated.data);
|
|
31164
31875
|
}
|
|
31165
31876
|
return ok(ballots);
|
|
31166
31877
|
}
|
|
31167
31878
|
async function writeBox(projectRoot, boxFile, ballots) {
|
|
31168
|
-
const dir =
|
|
31169
|
-
const temporary =
|
|
31879
|
+
const dir = resolve43(projectRoot, ".codeconductor/council");
|
|
31880
|
+
const temporary = resolve43(dir, `ballots.${process.pid}.${randomUUID4()}.tmp`);
|
|
31170
31881
|
try {
|
|
31171
|
-
await
|
|
31882
|
+
await mkdir29(dir, { recursive: true });
|
|
31172
31883
|
await writeFile28(temporary, JSON.stringify(ballots, null, 2), { encoding: "utf-8", flag: "wx" });
|
|
31173
|
-
await rename7(temporary,
|
|
31884
|
+
await rename7(temporary, resolve43(projectRoot, boxFile));
|
|
31174
31885
|
return ok(undefined);
|
|
31175
31886
|
} catch (e) {
|
|
31176
31887
|
return err(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -31250,9 +31961,9 @@ async function tallyBallots(projectRoot, config, preset = DEFAULT_PRESET) {
|
|
|
31250
31961
|
return effective;
|
|
31251
31962
|
const verdict = councilConsensus(box.data, effective.data);
|
|
31252
31963
|
try {
|
|
31253
|
-
const dir =
|
|
31254
|
-
await
|
|
31255
|
-
await appendFile4(
|
|
31964
|
+
const dir = resolve43(projectRoot, ".codeconductor/council");
|
|
31965
|
+
await mkdir29(dir, { recursive: true });
|
|
31966
|
+
await appendFile4(resolve43(projectRoot, VERDICTS_LOG), `${JSON.stringify({ at: new Date().toISOString(), preset, verdict })}
|
|
31256
31967
|
`, "utf-8");
|
|
31257
31968
|
} catch (e) {
|
|
31258
31969
|
return err(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -32308,11 +33019,11 @@ var init_backlog_scanner = __esm(() => {
|
|
|
32308
33019
|
});
|
|
32309
33020
|
|
|
32310
33021
|
// src/core/openspec/backlog-session.ts
|
|
32311
|
-
import { readFile as
|
|
32312
|
-
import { resolve as
|
|
33022
|
+
import { readFile as readFile48 } from "node:fs/promises";
|
|
33023
|
+
import { resolve as resolve44 } from "node:path";
|
|
32313
33024
|
async function loadBacklogSession(projectRoot) {
|
|
32314
33025
|
try {
|
|
32315
|
-
const raw = await
|
|
33026
|
+
const raw = await readFile48(resolve44(projectRoot, BACKLOG_FILENAME), "utf-8");
|
|
32316
33027
|
const parsed = parseBacklogMarkdown(raw);
|
|
32317
33028
|
if (!parsed.success)
|
|
32318
33029
|
return parsed;
|
|
@@ -32320,16 +33031,16 @@ async function loadBacklogSession(projectRoot) {
|
|
|
32320
33031
|
if (!stateResult.success)
|
|
32321
33032
|
return stateResult;
|
|
32322
33033
|
const state = stateResult.data;
|
|
32323
|
-
const
|
|
32324
|
-
if (!
|
|
32325
|
-
return err(new BacklogSessionError(parsed.data,
|
|
33034
|
+
const report2 = validateBacklog(parsed.data);
|
|
33035
|
+
if (!report2.valid) {
|
|
33036
|
+
return err(new BacklogSessionError(parsed.data, report2, state));
|
|
32326
33037
|
}
|
|
32327
33038
|
return ok({
|
|
32328
33039
|
raw,
|
|
32329
33040
|
doc: parsed.data,
|
|
32330
33041
|
state,
|
|
32331
33042
|
scan: computeScanDiff(raw, parsed.data, state.itemSnapshots ?? {}, checkBacklogFileChanged(projectRoot)),
|
|
32332
|
-
report
|
|
33043
|
+
report: report2
|
|
32333
33044
|
});
|
|
32334
33045
|
} catch (e) {
|
|
32335
33046
|
return err(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -32345,11 +33056,11 @@ var init_backlog_session = __esm(() => {
|
|
|
32345
33056
|
doc;
|
|
32346
33057
|
report;
|
|
32347
33058
|
state;
|
|
32348
|
-
constructor(doc,
|
|
32349
|
-
super(
|
|
33059
|
+
constructor(doc, report2, state) {
|
|
33060
|
+
super(report2.errors.map((e) => e.message).join("; ") || "Invalid BACKLOG.md");
|
|
32350
33061
|
this.name = "BacklogSessionError";
|
|
32351
33062
|
this.doc = doc;
|
|
32352
|
-
this.report =
|
|
33063
|
+
this.report = report2;
|
|
32353
33064
|
this.state = state;
|
|
32354
33065
|
}
|
|
32355
33066
|
};
|
|
@@ -32536,8 +33247,8 @@ var init_backlog_planner = __esm(() => {
|
|
|
32536
33247
|
});
|
|
32537
33248
|
|
|
32538
33249
|
// src/core/openspec/openspec-generator.ts
|
|
32539
|
-
import { access as access7, mkdir as
|
|
32540
|
-
import { basename as basename8, resolve as
|
|
33250
|
+
import { access as access7, mkdir as mkdir30, readFile as readFile49, rename as rename8, writeFile as writeFile29 } from "node:fs/promises";
|
|
33251
|
+
import { basename as basename8, resolve as resolve45 } from "node:path";
|
|
32541
33252
|
function pad3(n) {
|
|
32542
33253
|
return String(n).padStart(3, "0");
|
|
32543
33254
|
}
|
|
@@ -32602,8 +33313,8 @@ ${item.acceptanceCriteria.map((c) => markUntrusted("acceptance-criterion", c)).j
|
|
|
32602
33313
|
}
|
|
32603
33314
|
function specDelta(item) {
|
|
32604
33315
|
const criteria = item.acceptanceCriteria.length > 0 ? item.acceptanceCriteria : [`${item.title} is delivered`];
|
|
32605
|
-
const blocks = criteria.map((criterion,
|
|
32606
|
-
const n = pad3(
|
|
33316
|
+
const blocks = criteria.map((criterion, index2) => {
|
|
33317
|
+
const n = pad3(index2 + 1);
|
|
32607
33318
|
return `### Requirement: FR-${n} ${criterion}
|
|
32608
33319
|
|
|
32609
33320
|
The system MUST ${criterion}.
|
|
@@ -32624,10 +33335,10 @@ ${blocks.join(`
|
|
|
32624
33335
|
`;
|
|
32625
33336
|
}
|
|
32626
33337
|
async function syncTaskCardCheckbox(projectRoot, changePath, cardId, done) {
|
|
32627
|
-
const file =
|
|
33338
|
+
const file = resolve45(projectRoot, changePath, "tasks.md");
|
|
32628
33339
|
let content;
|
|
32629
33340
|
try {
|
|
32630
|
-
content = await
|
|
33341
|
+
content = await readFile49(file, "utf-8");
|
|
32631
33342
|
} catch (e) {
|
|
32632
33343
|
if (e.code === "ENOENT")
|
|
32633
33344
|
return;
|
|
@@ -32663,8 +33374,8 @@ function tasksContent(cards, options = {}) {
|
|
|
32663
33374
|
if (criteria.length === 0) {
|
|
32664
33375
|
lines.push(`- [ ] Implementation tasks (generated after plan)${tag("implement")}`);
|
|
32665
33376
|
} else {
|
|
32666
|
-
for (const [
|
|
32667
|
-
const n = pad3(
|
|
33377
|
+
for (const [index2, criterion] of criteria.entries()) {
|
|
33378
|
+
const n = pad3(index2 + 1);
|
|
32668
33379
|
if (options.tddRequired) {
|
|
32669
33380
|
lines.push(`- [ ] Write failing test for FR-${n} (${criterion})${tag("test")}`);
|
|
32670
33381
|
}
|
|
@@ -32687,19 +33398,19 @@ function tasksContent(cards, options = {}) {
|
|
|
32687
33398
|
}
|
|
32688
33399
|
async function generateOpenspecChange(projectRoot, item, taskCards, options = {}) {
|
|
32689
33400
|
const slug = buildChangeSlug(item);
|
|
32690
|
-
const changeDir =
|
|
32691
|
-
await
|
|
33401
|
+
const changeDir = resolve45(projectRoot, "openspec", "changes", slug);
|
|
33402
|
+
await mkdir30(resolve45(changeDir, "specs"), { recursive: true });
|
|
32692
33403
|
const taskOpts = {
|
|
32693
33404
|
tddRequired: options.tddRequired,
|
|
32694
33405
|
acceptanceCriteria: options.acceptanceCriteria ?? item.acceptanceCriteria
|
|
32695
33406
|
};
|
|
32696
|
-
await writeFile29(
|
|
32697
|
-
await writeFile29(
|
|
32698
|
-
await writeFile29(
|
|
33407
|
+
await writeFile29(resolve45(changeDir, "proposal.md"), proposalContent(item), "utf-8");
|
|
33408
|
+
await writeFile29(resolve45(changeDir, "design.md"), designContent(item), "utf-8");
|
|
33409
|
+
await writeFile29(resolve45(changeDir, "tasks.md"), tasksContent(taskCards, taskOpts), "utf-8");
|
|
32699
33410
|
const capability = capabilitySlug(item.title);
|
|
32700
|
-
await
|
|
32701
|
-
await writeFile29(
|
|
32702
|
-
await writeFile29(
|
|
33411
|
+
await mkdir30(resolve45(changeDir, "specs", capability), { recursive: true });
|
|
33412
|
+
await writeFile29(resolve45(changeDir, "specs", capability, "spec.md"), specDelta(item), "utf-8");
|
|
33413
|
+
await writeFile29(resolve45(changeDir, "change.yaml"), `version: 1
|
|
32703
33414
|
backlogId: ${item.id}
|
|
32704
33415
|
profile: standard
|
|
32705
33416
|
capabilities:
|
|
@@ -32708,11 +33419,11 @@ capabilities:
|
|
|
32708
33419
|
return `openspec/changes/${slug}`;
|
|
32709
33420
|
}
|
|
32710
33421
|
async function archiveChangeFolder(projectRoot, changePath) {
|
|
32711
|
-
const src =
|
|
33422
|
+
const src = resolve45(projectRoot, changePath);
|
|
32712
33423
|
const slug = basename8(changePath);
|
|
32713
|
-
const destDir =
|
|
32714
|
-
await
|
|
32715
|
-
const dest =
|
|
33424
|
+
const destDir = resolve45(projectRoot, "openspec", "changes", "archive");
|
|
33425
|
+
await mkdir30(destDir, { recursive: true });
|
|
33426
|
+
const dest = resolve45(destDir, slug);
|
|
32716
33427
|
try {
|
|
32717
33428
|
await access7(dest);
|
|
32718
33429
|
throw new Error(`Archive destination already exists: openspec/changes/archive/${slug}`);
|
|
@@ -32725,12 +33436,12 @@ async function archiveChangeFolder(projectRoot, changePath) {
|
|
|
32725
33436
|
return `openspec/changes/archive/${slug}`;
|
|
32726
33437
|
}
|
|
32727
33438
|
async function ensureOpenspecConfig(projectRoot) {
|
|
32728
|
-
const configPath =
|
|
33439
|
+
const configPath = resolve45(projectRoot, "openspec", "config.yaml");
|
|
32729
33440
|
try {
|
|
32730
33441
|
const { access: access8 } = await import("node:fs/promises");
|
|
32731
33442
|
await access8(configPath);
|
|
32732
33443
|
} catch {
|
|
32733
|
-
await
|
|
33444
|
+
await mkdir30(resolve45(projectRoot, "openspec"), { recursive: true });
|
|
32734
33445
|
const stub = `# OpenSpec project config (CodeConductor native compatible)
|
|
32735
33446
|
schema: spec-driven
|
|
32736
33447
|
`;
|
|
@@ -32743,8 +33454,8 @@ var init_openspec_generator = __esm(() => {
|
|
|
32743
33454
|
});
|
|
32744
33455
|
|
|
32745
33456
|
// src/core/openspec/spec-files.ts
|
|
32746
|
-
import { readFile as
|
|
32747
|
-
import { basename as basename9, dirname as
|
|
33457
|
+
import { readFile as readFile50, readdir as readdir17 } from "node:fs/promises";
|
|
33458
|
+
import { basename as basename9, dirname as dirname16, join as join34 } from "node:path";
|
|
32748
33459
|
function requirementId(name, capability) {
|
|
32749
33460
|
const frId = name.match(/\bFR-\d{3}\b/)?.[0];
|
|
32750
33461
|
if (frId)
|
|
@@ -32755,14 +33466,14 @@ function specNameSlug(name) {
|
|
|
32755
33466
|
return name.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
32756
33467
|
}
|
|
32757
33468
|
function specCapability(path) {
|
|
32758
|
-
return basename9(path) === "spec.md" ? basename9(
|
|
33469
|
+
return basename9(path) === "spec.md" ? basename9(dirname16(path)) : basename9(path, ".md");
|
|
32759
33470
|
}
|
|
32760
33471
|
function hasMalformedRenames(markdown) {
|
|
32761
33472
|
const sections = [...markdown.matchAll(/^## (ADDED|MODIFIED|REMOVED|RENAMED) Requirements\s*$/gm)];
|
|
32762
|
-
return sections.some((section,
|
|
33473
|
+
return sections.some((section, index2) => {
|
|
32763
33474
|
if (section[1] !== "RENAMED")
|
|
32764
33475
|
return false;
|
|
32765
|
-
const text = markdown.slice((section.index ?? 0) + section[0].length, sections[
|
|
33476
|
+
const text = markdown.slice((section.index ?? 0) + section[0].length, sections[index2 + 1]?.index ?? markdown.length).split(/^## /m, 1)[0] ?? "";
|
|
32766
33477
|
const renamed = requirementBlocks(`## RENAMED Requirements
|
|
32767
33478
|
${text}`).filter((block) => block.renamedFrom);
|
|
32768
33479
|
return renamed.length === 0 || renamed.some((block) => block.id?.endsWith("/") || block.renamedFrom?.endsWith("/")) || (text.match(/^- (?:FROM|TO):/gm)?.length ?? 0) !== renamed.length * 2;
|
|
@@ -32771,13 +33482,13 @@ ${text}`).filter((block) => block.renamedFrom);
|
|
|
32771
33482
|
async function walkMarkdownFiles(dir) {
|
|
32772
33483
|
let entries;
|
|
32773
33484
|
try {
|
|
32774
|
-
entries = await
|
|
33485
|
+
entries = await readdir17(dir, { withFileTypes: true });
|
|
32775
33486
|
} catch {
|
|
32776
33487
|
return [];
|
|
32777
33488
|
}
|
|
32778
33489
|
const files = [];
|
|
32779
33490
|
for (const entry of entries) {
|
|
32780
|
-
const path =
|
|
33491
|
+
const path = join34(dir, entry.name);
|
|
32781
33492
|
if (entry.isDirectory()) {
|
|
32782
33493
|
files.push(...await walkMarkdownFiles(path));
|
|
32783
33494
|
} else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
@@ -32790,7 +33501,7 @@ async function readMarkdownFiles(dir) {
|
|
|
32790
33501
|
const files = await walkMarkdownFiles(dir);
|
|
32791
33502
|
const out = [];
|
|
32792
33503
|
for (const path of files) {
|
|
32793
|
-
out.push({ path, content: await
|
|
33504
|
+
out.push({ path, content: await readFile50(path, "utf-8") });
|
|
32794
33505
|
}
|
|
32795
33506
|
return out;
|
|
32796
33507
|
}
|
|
@@ -32798,12 +33509,12 @@ function requirementBlocks(markdown, capability) {
|
|
|
32798
33509
|
const starts = [...markdown.matchAll(/^### Requirement:.*$/gm)];
|
|
32799
33510
|
const sections = [...markdown.matchAll(/^## (ADDED|MODIFIED|REMOVED|RENAMED) Requirements\s*$/gm)];
|
|
32800
33511
|
const headings = [...markdown.matchAll(/^## (.*)$/gm)];
|
|
32801
|
-
const blocks = starts.map((match,
|
|
33512
|
+
const blocks = starts.map((match, index2) => {
|
|
32802
33513
|
const start = match.index ?? 0;
|
|
32803
33514
|
const heading = [...headings].reverse().find((entry) => (entry.index ?? 0) < start);
|
|
32804
33515
|
const operation = heading?.[1]?.trim().match(/^(ADDED|MODIFIED|REMOVED|RENAMED) Requirements$/)?.[1];
|
|
32805
33516
|
const nextSection = markdown.slice(start).search(/^## /m);
|
|
32806
|
-
const end = Math.min(starts[
|
|
33517
|
+
const end = Math.min(starts[index2 + 1]?.index ?? markdown.length, nextSection < 0 ? markdown.length : start + nextSection);
|
|
32807
33518
|
const block = markdown.slice(start, end).trim();
|
|
32808
33519
|
const name = match[0].replace(/^### Requirement:\s*/, "").trim();
|
|
32809
33520
|
return {
|
|
@@ -32813,10 +33524,10 @@ function requirementBlocks(markdown, capability) {
|
|
|
32813
33524
|
deltaOperation: operation
|
|
32814
33525
|
};
|
|
32815
33526
|
});
|
|
32816
|
-
for (const [
|
|
33527
|
+
for (const [index2, section] of sections.entries()) {
|
|
32817
33528
|
if (section[1] !== "RENAMED")
|
|
32818
33529
|
continue;
|
|
32819
|
-
const text = markdown.slice((section.index ?? 0) + section[0].length, sections[
|
|
33530
|
+
const text = markdown.slice((section.index ?? 0) + section[0].length, sections[index2 + 1]?.index ?? markdown.length).split(/^## /m, 1)[0] ?? "";
|
|
32820
33531
|
const pairs = [...text.matchAll(/^- FROM:\s*`?### Requirement:\s*(.*?)`?\s*\r?\n- TO:\s*`?### Requirement:\s*(.*?)`?\s*$/gm)];
|
|
32821
33532
|
for (const pair of pairs) {
|
|
32822
33533
|
const name = pair[2] ?? "";
|
|
@@ -32837,8 +33548,8 @@ var init_spec_files = __esm(() => {
|
|
|
32837
33548
|
});
|
|
32838
33549
|
|
|
32839
33550
|
// src/core/openspec/spec-quality.ts
|
|
32840
|
-
import { readFile as
|
|
32841
|
-
import { join as
|
|
33551
|
+
import { readFile as readFile51 } from "node:fs/promises";
|
|
33552
|
+
import { join as join35, relative as relative15, resolve as resolve46 } from "node:path";
|
|
32842
33553
|
function uniqueIds(matches) {
|
|
32843
33554
|
return [...new Set(matches ?? [])];
|
|
32844
33555
|
}
|
|
@@ -32908,8 +33619,8 @@ function assessSpecMarkdown(content, path) {
|
|
|
32908
33619
|
}
|
|
32909
33620
|
const scenarios = [...text.matchAll(/^#### Scenario:\s*(.+)$/gm)];
|
|
32910
33621
|
if (!legacyBlock) {
|
|
32911
|
-
for (const [
|
|
32912
|
-
const body = text.slice(scenario.index, scenarios[
|
|
33622
|
+
for (const [index2, scenario] of scenarios.entries()) {
|
|
33623
|
+
const body = text.slice(scenario.index, scenarios[index2 + 1]?.index ?? text.length);
|
|
32913
33624
|
officialScenarios.push({ id: `${block.id}#${specNameSlug(scenario[1] ?? "")}`, text: scenario[1] ?? "" });
|
|
32914
33625
|
if (!/\bWHEN\b[\s\S]*?\bTHEN\b/i.test(body)) {
|
|
32915
33626
|
issues.push({ code: "MISSING_GWT", message: `Scenario "${scenario[1]}" MUST include WHEN/THEN steps`, path, severity: "error" });
|
|
@@ -32976,8 +33687,8 @@ function mergeSpecQualityReports(reports) {
|
|
|
32976
33687
|
};
|
|
32977
33688
|
}
|
|
32978
33689
|
async function assessChangeFolder(projectRoot, changePath) {
|
|
32979
|
-
const root =
|
|
32980
|
-
const changeRoot =
|
|
33690
|
+
const root = resolve46(projectRoot);
|
|
33691
|
+
const changeRoot = resolve46(root, changePath);
|
|
32981
33692
|
if (!changeRoot.startsWith(root)) {
|
|
32982
33693
|
return {
|
|
32983
33694
|
valid: false,
|
|
@@ -32995,22 +33706,22 @@ async function assessChangeFolder(projectRoot, changePath) {
|
|
|
32995
33706
|
successCriteria: []
|
|
32996
33707
|
};
|
|
32997
33708
|
}
|
|
32998
|
-
const specDir =
|
|
33709
|
+
const specDir = join35(changeRoot, "specs");
|
|
32999
33710
|
const specFiles = await walkMarkdownFiles(specDir);
|
|
33000
|
-
const extra = ["proposal.md", "design.md"].map((name) =>
|
|
33711
|
+
const extra = ["proposal.md", "design.md"].map((name) => join35(changeRoot, name));
|
|
33001
33712
|
const reports = [];
|
|
33002
33713
|
for (const file of specFiles) {
|
|
33003
|
-
const content = await
|
|
33004
|
-
reports.push(assessSpecMarkdown(content,
|
|
33714
|
+
const content = await readFile51(file, "utf-8");
|
|
33715
|
+
reports.push(assessSpecMarkdown(content, relative15(root, file).replace(/\\/g, "/")));
|
|
33005
33716
|
}
|
|
33006
33717
|
for (const file of extra) {
|
|
33007
33718
|
let content;
|
|
33008
33719
|
try {
|
|
33009
|
-
content = await
|
|
33720
|
+
content = await readFile51(file, "utf-8");
|
|
33010
33721
|
} catch {
|
|
33011
33722
|
continue;
|
|
33012
33723
|
}
|
|
33013
|
-
const rel =
|
|
33724
|
+
const rel = relative15(root, file).replace(/\\/g, "/");
|
|
33014
33725
|
if (PLACEHOLDER.test(content)) {
|
|
33015
33726
|
reports.push({
|
|
33016
33727
|
valid: false,
|
|
@@ -33061,8 +33772,8 @@ var init_spec_quality = __esm(() => {
|
|
|
33061
33772
|
});
|
|
33062
33773
|
|
|
33063
33774
|
// src/core/openspec/spec-analyzer.ts
|
|
33064
|
-
import { readFile as
|
|
33065
|
-
import { join as
|
|
33775
|
+
import { readFile as readFile52 } from "node:fs/promises";
|
|
33776
|
+
import { join as join36, resolve as resolve47 } from "node:path";
|
|
33066
33777
|
function unique(ids) {
|
|
33067
33778
|
return [...new Set(ids)];
|
|
33068
33779
|
}
|
|
@@ -33160,20 +33871,20 @@ function analyzeSpecArtifacts(input) {
|
|
|
33160
33871
|
};
|
|
33161
33872
|
}
|
|
33162
33873
|
async function analyzeChangeFolder(projectRoot, changePath, options) {
|
|
33163
|
-
const changeRoot =
|
|
33164
|
-
const specFiles = await readMarkdownFiles(
|
|
33874
|
+
const changeRoot = resolve47(projectRoot, changePath);
|
|
33875
|
+
const specFiles = await readMarkdownFiles(join36(changeRoot, "specs"));
|
|
33165
33876
|
const specMarkdown = specFiles.map((file) => file.content).join(`
|
|
33166
33877
|
|
|
33167
33878
|
`);
|
|
33168
33879
|
let tasksMarkdown = "";
|
|
33169
33880
|
try {
|
|
33170
|
-
tasksMarkdown = await
|
|
33881
|
+
tasksMarkdown = await readFile52(join36(changeRoot, "tasks.md"), "utf-8");
|
|
33171
33882
|
} catch {
|
|
33172
33883
|
tasksMarkdown = "";
|
|
33173
33884
|
}
|
|
33174
33885
|
let designMarkdown;
|
|
33175
33886
|
try {
|
|
33176
|
-
designMarkdown = await
|
|
33887
|
+
designMarkdown = await readFile52(join36(changeRoot, "design.md"), "utf-8");
|
|
33177
33888
|
} catch {
|
|
33178
33889
|
designMarkdown = undefined;
|
|
33179
33890
|
}
|
|
@@ -33194,8 +33905,8 @@ var init_spec_analyzer = __esm(() => {
|
|
|
33194
33905
|
});
|
|
33195
33906
|
|
|
33196
33907
|
// src/core/openspec/spec-sync.ts
|
|
33197
|
-
import { mkdir as
|
|
33198
|
-
import { join as
|
|
33908
|
+
import { mkdir as mkdir31, readFile as readFile53 } from "node:fs/promises";
|
|
33909
|
+
import { join as join37, relative as relative16, resolve as resolve48 } from "node:path";
|
|
33199
33910
|
function deltaRequirements(markdown, capability) {
|
|
33200
33911
|
return requirementBlocks(markdown, capability).filter((requirement) => requirement.id !== null && requirement.deltaOperation !== undefined).map((requirement) => ({
|
|
33201
33912
|
id: requirement.id,
|
|
@@ -33260,9 +33971,9 @@ ${delta.markdown}`;
|
|
|
33260
33971
|
` };
|
|
33261
33972
|
}
|
|
33262
33973
|
async function syncChangeSpecs(projectRoot, changePath) {
|
|
33263
|
-
const root =
|
|
33264
|
-
const changeRoot =
|
|
33265
|
-
const changeSpecs =
|
|
33974
|
+
const root = resolve48(projectRoot);
|
|
33975
|
+
const changeRoot = resolve48(root, changePath);
|
|
33976
|
+
const changeSpecs = join37(changeRoot, "specs");
|
|
33266
33977
|
if (changeRoot !== root && !changeRoot.startsWith(`${root}/`)) {
|
|
33267
33978
|
return { success: false, syncedPaths: [], errors: ["Change path escapes project root"] };
|
|
33268
33979
|
}
|
|
@@ -33272,40 +33983,40 @@ async function syncChangeSpecs(projectRoot, changePath) {
|
|
|
33272
33983
|
}
|
|
33273
33984
|
const writes = [];
|
|
33274
33985
|
for (const file of files) {
|
|
33275
|
-
const delta = await
|
|
33986
|
+
const delta = await readFile53(file, "utf-8");
|
|
33276
33987
|
if (hasMalformedRenames(delta)) {
|
|
33277
|
-
return { success: false, syncedPaths: [], errors: [`${
|
|
33988
|
+
return { success: false, syncedPaths: [], errors: [`${relative16(root, file)}: RENAMED requires paired FROM/TO requirement headings`] };
|
|
33278
33989
|
}
|
|
33279
33990
|
const requirements = deltaRequirements(delta, specCapability(file));
|
|
33280
33991
|
if (requirements.some((requirement) => !requirement.name?.trim() || requirement.id.endsWith("/"))) {
|
|
33281
|
-
return { success: false, syncedPaths: [], errors: [`${
|
|
33992
|
+
return { success: false, syncedPaths: [], errors: [`${relative16(root, file)}: requirement names must produce a nonempty stable ID`] };
|
|
33282
33993
|
}
|
|
33283
33994
|
if (requirements.length === 0) {
|
|
33284
33995
|
return {
|
|
33285
33996
|
success: false,
|
|
33286
33997
|
syncedPaths: [],
|
|
33287
|
-
errors: [`${
|
|
33998
|
+
errors: [`${relative16(root, file)}: no delta requirements found`]
|
|
33288
33999
|
};
|
|
33289
34000
|
}
|
|
33290
|
-
const relativeSpec =
|
|
33291
|
-
const target =
|
|
34001
|
+
const relativeSpec = relative16(changeSpecs, file);
|
|
34002
|
+
const target = join37(root, "openspec", "specs", relativeSpec);
|
|
33292
34003
|
let existing = `# ${relativeSpec.replace(/\\/g, "/")}
|
|
33293
34004
|
`;
|
|
33294
34005
|
try {
|
|
33295
|
-
existing = await
|
|
34006
|
+
existing = await readFile53(target, "utf-8");
|
|
33296
34007
|
} catch {}
|
|
33297
|
-
const merged = upsertRequirements(existing, requirements,
|
|
34008
|
+
const merged = upsertRequirements(existing, requirements, relative16(root, file), specCapability(file));
|
|
33298
34009
|
if (!merged.ok)
|
|
33299
34010
|
return { success: false, syncedPaths: [], errors: [merged.error] };
|
|
33300
34011
|
writes.push({ path: target, content: merged.content });
|
|
33301
34012
|
}
|
|
33302
34013
|
for (const write of writes) {
|
|
33303
|
-
await
|
|
34014
|
+
await mkdir31(resolve48(write.path, ".."), { recursive: true });
|
|
33304
34015
|
await writeFileAtomic(write.path, write.content);
|
|
33305
34016
|
}
|
|
33306
34017
|
return {
|
|
33307
34018
|
success: true,
|
|
33308
|
-
syncedPaths: writes.map((write) =>
|
|
34019
|
+
syncedPaths: writes.map((write) => relative16(root, write.path).replace(/\\/g, "/")),
|
|
33309
34020
|
errors: []
|
|
33310
34021
|
};
|
|
33311
34022
|
}
|
|
@@ -33315,8 +34026,8 @@ var init_spec_sync = __esm(() => {
|
|
|
33315
34026
|
});
|
|
33316
34027
|
|
|
33317
34028
|
// src/core/openspec/artifact-progress.ts
|
|
33318
|
-
import { access as access8, readdir as
|
|
33319
|
-
import { join as
|
|
34029
|
+
import { access as access8, readdir as readdir18, readFile as readFile54 } from "node:fs/promises";
|
|
34030
|
+
import { join as join38, resolve as resolve49 } from "node:path";
|
|
33320
34031
|
function countCheckboxes(markdown) {
|
|
33321
34032
|
let total = 0;
|
|
33322
34033
|
let complete = 0;
|
|
@@ -33342,12 +34053,12 @@ async function exists(path) {
|
|
|
33342
34053
|
async function hasMarkdown(dir) {
|
|
33343
34054
|
let entries;
|
|
33344
34055
|
try {
|
|
33345
|
-
entries = await
|
|
34056
|
+
entries = await readdir18(dir, { withFileTypes: true });
|
|
33346
34057
|
} catch {
|
|
33347
34058
|
return false;
|
|
33348
34059
|
}
|
|
33349
34060
|
for (const entry of entries) {
|
|
33350
|
-
const full =
|
|
34061
|
+
const full = join38(dir, entry.name);
|
|
33351
34062
|
if (entry.isFile() && entry.name.endsWith(".md"))
|
|
33352
34063
|
return true;
|
|
33353
34064
|
if (entry.isDirectory() && await hasMarkdown(full))
|
|
@@ -33356,21 +34067,21 @@ async function hasMarkdown(dir) {
|
|
|
33356
34067
|
return false;
|
|
33357
34068
|
}
|
|
33358
34069
|
async function readArtifactProgress(projectRoot, changePath) {
|
|
33359
|
-
const root =
|
|
33360
|
-
const changeRoot =
|
|
34070
|
+
const root = resolve49(projectRoot);
|
|
34071
|
+
const changeRoot = resolve49(root, changePath);
|
|
33361
34072
|
if (changeRoot !== root && !changeRoot.startsWith(`${root}/`)) {
|
|
33362
34073
|
return ABSENT;
|
|
33363
34074
|
}
|
|
33364
34075
|
const [proposal, design, tasks, specs] = await Promise.all([
|
|
33365
|
-
exists(
|
|
33366
|
-
exists(
|
|
33367
|
-
exists(
|
|
33368
|
-
hasMarkdown(
|
|
34076
|
+
exists(join38(changeRoot, "proposal.md")),
|
|
34077
|
+
exists(join38(changeRoot, "design.md")),
|
|
34078
|
+
exists(join38(changeRoot, "tasks.md")),
|
|
34079
|
+
hasMarkdown(join38(changeRoot, "specs"))
|
|
33369
34080
|
]);
|
|
33370
34081
|
let checkboxes = { total: 0, complete: 0, remaining: 0 };
|
|
33371
34082
|
if (tasks) {
|
|
33372
34083
|
try {
|
|
33373
|
-
checkboxes = countCheckboxes(await
|
|
34084
|
+
checkboxes = countCheckboxes(await readFile54(join38(changeRoot, "tasks.md"), "utf-8"));
|
|
33374
34085
|
} catch {
|
|
33375
34086
|
checkboxes = { total: 0, complete: 0, remaining: 0 };
|
|
33376
34087
|
}
|
|
@@ -33403,9 +34114,9 @@ var exports_openspec_command = {};
|
|
|
33403
34114
|
__export(exports_openspec_command, {
|
|
33404
34115
|
openspecCommand: () => openspecCommand
|
|
33405
34116
|
});
|
|
33406
|
-
import { readFile as
|
|
34117
|
+
import { readFile as readFile55 } from "node:fs/promises";
|
|
33407
34118
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
33408
|
-
import { resolve as
|
|
34119
|
+
import { resolve as resolve50 } from "node:path";
|
|
33409
34120
|
async function openspecCommand(options) {
|
|
33410
34121
|
const { subcommand, itemId, projectRoot, output, reason, allowUnchecked } = options;
|
|
33411
34122
|
switch (subcommand) {
|
|
@@ -33448,14 +34159,14 @@ async function openspecCommand(options) {
|
|
|
33448
34159
|
};
|
|
33449
34160
|
}
|
|
33450
34161
|
}
|
|
33451
|
-
function
|
|
34162
|
+
function fail3(command, errors3, extra = {}) {
|
|
33452
34163
|
return {
|
|
33453
34164
|
code: 1,
|
|
33454
34165
|
data: { success: false, command, errors: errors3, ...extra }
|
|
33455
34166
|
};
|
|
33456
34167
|
}
|
|
33457
34168
|
async function persistBacklog(projectRoot, content) {
|
|
33458
|
-
await writeFileAtomic(
|
|
34169
|
+
await writeFileAtomic(resolve50(projectRoot, BACKLOG_FILENAME), content);
|
|
33459
34170
|
}
|
|
33460
34171
|
async function persistState(projectRoot, state) {
|
|
33461
34172
|
const written = await writeOpenspecState(projectRoot, state);
|
|
@@ -33483,12 +34194,12 @@ function resolveActiveChange(state, command, itemId) {
|
|
|
33483
34194
|
if (!targetId) {
|
|
33484
34195
|
return {
|
|
33485
34196
|
ok: false,
|
|
33486
|
-
response:
|
|
34197
|
+
response: fail3(command, ["No active change. Run openspec plan or pass an item id."])
|
|
33487
34198
|
};
|
|
33488
34199
|
}
|
|
33489
34200
|
const changePath = state.changePaths[targetId];
|
|
33490
34201
|
if (!changePath || changePath.includes("/archive/")) {
|
|
33491
|
-
return { ok: false, response:
|
|
34202
|
+
return { ok: false, response: fail3(command, [`No active change folder for ${targetId}`]) };
|
|
33492
34203
|
}
|
|
33493
34204
|
return { ok: true, targetId, changePath };
|
|
33494
34205
|
}
|
|
@@ -33496,7 +34207,7 @@ async function collectAnalyzeReport(projectRoot, session, targetId, changePath)
|
|
|
33496
34207
|
const tddRequired = session.doc.global.tddRequired;
|
|
33497
34208
|
const policyParts = [];
|
|
33498
34209
|
try {
|
|
33499
|
-
policyParts.push(await
|
|
34210
|
+
policyParts.push(await readFile55(resolve50(projectRoot, "AGENTS.md"), "utf-8"));
|
|
33500
34211
|
} catch {}
|
|
33501
34212
|
policyParts.push(session.raw);
|
|
33502
34213
|
const cards = itemCards(session.state, targetId);
|
|
@@ -33512,13 +34223,13 @@ async function collectAnalyzeReport(projectRoot, session, targetId, changePath)
|
|
|
33512
34223
|
}
|
|
33513
34224
|
}
|
|
33514
34225
|
}
|
|
33515
|
-
const
|
|
34226
|
+
const report2 = await analyzeChangeFolder(projectRoot, changePath, {
|
|
33516
34227
|
tddRequired,
|
|
33517
34228
|
policyText: policyParts.join(`
|
|
33518
34229
|
`),
|
|
33519
34230
|
hasTddEvidence
|
|
33520
34231
|
});
|
|
33521
|
-
return { tddRequired, report };
|
|
34232
|
+
return { tddRequired, report: report2 };
|
|
33522
34233
|
}
|
|
33523
34234
|
function buildNextSteps(input) {
|
|
33524
34235
|
const { state, nextItemId, progress } = input;
|
|
@@ -33593,13 +34304,13 @@ async function buildValidationResponse(projectRoot, sessionResult) {
|
|
|
33593
34304
|
}
|
|
33594
34305
|
};
|
|
33595
34306
|
}
|
|
33596
|
-
const { doc, state, report } = sessionParts(sessionResult.success ? sessionResult.data : sessionResult.error);
|
|
33597
|
-
const errors3 =
|
|
33598
|
-
const recommendations = [...
|
|
34307
|
+
const { doc, state, report: report2 } = sessionParts(sessionResult.success ? sessionResult.data : sessionResult.error);
|
|
34308
|
+
const errors3 = report2.errors.map((e) => e.message);
|
|
34309
|
+
const recommendations = [...report2.recommendations];
|
|
33599
34310
|
const spec = await assessActiveChangeSpecs(projectRoot, state);
|
|
33600
34311
|
errors3.push(...spec.errors);
|
|
33601
34312
|
recommendations.push(...spec.recommendations);
|
|
33602
|
-
const valid =
|
|
34313
|
+
const valid = report2.valid && spec.specValid;
|
|
33603
34314
|
return {
|
|
33604
34315
|
code: valid ? 0 : 1,
|
|
33605
34316
|
data: {
|
|
@@ -33638,7 +34349,7 @@ async function handleScan(projectRoot) {
|
|
|
33638
34349
|
};
|
|
33639
34350
|
const written = await persistState(projectRoot, state);
|
|
33640
34351
|
if (!written.ok) {
|
|
33641
|
-
return
|
|
34352
|
+
return fail3("openspec scan", [written.error]);
|
|
33642
34353
|
}
|
|
33643
34354
|
return {
|
|
33644
34355
|
code: 0,
|
|
@@ -33673,7 +34384,7 @@ async function handlePlan(projectRoot, itemId) {
|
|
|
33673
34384
|
}
|
|
33674
34385
|
const existingState = session.state;
|
|
33675
34386
|
if (item.status !== "PLANNED" && !canTransition(item.status, "PLANNED")) {
|
|
33676
|
-
return
|
|
34387
|
+
return fail3("openspec plan", [
|
|
33677
34388
|
`Illegal backlog transition for ${item.id}: ${item.status} → PLANNED.`
|
|
33678
34389
|
]);
|
|
33679
34390
|
}
|
|
@@ -33700,11 +34411,11 @@ async function handlePlan(projectRoot, itemId) {
|
|
|
33700
34411
|
};
|
|
33701
34412
|
const written = await persistState(projectRoot, newState);
|
|
33702
34413
|
if (!written.ok) {
|
|
33703
|
-
return
|
|
34414
|
+
return fail3("openspec plan", [written.error]);
|
|
33704
34415
|
}
|
|
33705
34416
|
const transition = applyBacklogTransition(session.raw, item.id, item.status, "PLANNED", item.progress);
|
|
33706
34417
|
if (!transition.success) {
|
|
33707
|
-
return
|
|
34418
|
+
return fail3("openspec plan", [transition.error.message]);
|
|
33708
34419
|
}
|
|
33709
34420
|
await persistBacklog(projectRoot, transition.data);
|
|
33710
34421
|
return {
|
|
@@ -33725,32 +34436,32 @@ async function handleAnalyze(projectRoot, itemId) {
|
|
|
33725
34436
|
const command = "openspec analyze";
|
|
33726
34437
|
const sessionResult = await loadBacklogSession(projectRoot);
|
|
33727
34438
|
if (!sessionResult.success)
|
|
33728
|
-
return
|
|
34439
|
+
return fail3(command, [sessionResult.error.message]);
|
|
33729
34440
|
const session = sessionResult.data;
|
|
33730
34441
|
const resolved = resolveActiveChange(session.state, command, itemId);
|
|
33731
34442
|
if (!resolved.ok)
|
|
33732
34443
|
return resolved.response;
|
|
33733
|
-
const { report } = await collectAnalyzeReport(projectRoot, session, resolved.targetId, resolved.changePath);
|
|
34444
|
+
const { report: report2 } = await collectAnalyzeReport(projectRoot, session, resolved.targetId, resolved.changePath);
|
|
33734
34445
|
const data = SpecAnalyzeReportSchema.parse({
|
|
33735
|
-
changePath:
|
|
33736
|
-
frIds:
|
|
33737
|
-
scIds:
|
|
33738
|
-
mappedFr:
|
|
33739
|
-
mappedSc:
|
|
33740
|
-
mappedToTests:
|
|
33741
|
-
frCoveragePct:
|
|
33742
|
-
scCoveragePct:
|
|
33743
|
-
testCoveragePct:
|
|
33744
|
-
findings:
|
|
33745
|
-
stop:
|
|
34446
|
+
changePath: report2.changePath,
|
|
34447
|
+
frIds: report2.frIds,
|
|
34448
|
+
scIds: report2.scIds,
|
|
34449
|
+
mappedFr: report2.mappedFr,
|
|
34450
|
+
mappedSc: report2.mappedSc,
|
|
34451
|
+
mappedToTests: report2.mappedToTests,
|
|
34452
|
+
frCoveragePct: report2.frCoveragePct,
|
|
34453
|
+
scCoveragePct: report2.scCoveragePct,
|
|
34454
|
+
testCoveragePct: report2.testCoveragePct,
|
|
34455
|
+
findings: report2.findings,
|
|
34456
|
+
stop: report2.stop
|
|
33746
34457
|
});
|
|
33747
34458
|
return {
|
|
33748
|
-
code:
|
|
34459
|
+
code: report2.stop ? 1 : 0,
|
|
33749
34460
|
data: {
|
|
33750
|
-
success: !
|
|
34461
|
+
success: !report2.stop,
|
|
33751
34462
|
command,
|
|
33752
34463
|
...data,
|
|
33753
|
-
stopForClarify:
|
|
34464
|
+
stopForClarify: report2.quality.stopForClarify
|
|
33754
34465
|
}
|
|
33755
34466
|
};
|
|
33756
34467
|
}
|
|
@@ -33764,7 +34475,7 @@ async function handleSync(projectRoot, itemId) {
|
|
|
33764
34475
|
return resolved.response;
|
|
33765
34476
|
const synced = await syncChangeSpecs(projectRoot, resolved.changePath);
|
|
33766
34477
|
if (!synced.success) {
|
|
33767
|
-
return
|
|
34478
|
+
return fail3(command, [
|
|
33768
34479
|
`Spec sync failed for ${resolved.targetId}: ${synced.errors.join("; ")}`
|
|
33769
34480
|
]);
|
|
33770
34481
|
}
|
|
@@ -33790,7 +34501,7 @@ async function handleVerify(projectRoot, itemId) {
|
|
|
33790
34501
|
const command = "openspec verify";
|
|
33791
34502
|
const sessionResult = await loadBacklogSession(projectRoot);
|
|
33792
34503
|
if (!sessionResult.success)
|
|
33793
|
-
return
|
|
34504
|
+
return fail3(command, [sessionResult.error.message]);
|
|
33794
34505
|
const session = sessionResult.data;
|
|
33795
34506
|
const resolved = resolveActiveChange(session.state, command, itemId);
|
|
33796
34507
|
if (!resolved.ok)
|
|
@@ -33799,12 +34510,12 @@ async function handleVerify(projectRoot, itemId) {
|
|
|
33799
34510
|
const itemLoaded = findItemOrFail(session, targetId, command);
|
|
33800
34511
|
if (!itemLoaded.ok)
|
|
33801
34512
|
return itemLoaded.response;
|
|
33802
|
-
const { report } = await collectAnalyzeReport(projectRoot, session, targetId, changePath);
|
|
34513
|
+
const { report: report2 } = await collectAnalyzeReport(projectRoot, session, targetId, changePath);
|
|
33803
34514
|
const progress = await readArtifactProgress(projectRoot, changePath);
|
|
33804
34515
|
const cards = itemCards(session.state, targetId);
|
|
33805
34516
|
const doneCount = cards.filter((c) => c.status === "done").length;
|
|
33806
34517
|
const issues = [];
|
|
33807
|
-
for (const finding of
|
|
34518
|
+
for (const finding of report2.findings) {
|
|
33808
34519
|
const dimension = finding.code === "POLICY_CONFLICT" || finding.code === "NEEDS_CLARIFICATION" ? "Coherence" : "Correctness";
|
|
33809
34520
|
issues.push({
|
|
33810
34521
|
severity: analyzeSeverityToVerify(finding.severity),
|
|
@@ -33868,9 +34579,9 @@ async function handleVerify(projectRoot, itemId) {
|
|
|
33868
34579
|
checkboxProgress: progress.checkboxes,
|
|
33869
34580
|
cardsTotal: cards.length,
|
|
33870
34581
|
cardsDone: doneCount,
|
|
33871
|
-
frCoveragePct:
|
|
33872
|
-
scCoveragePct:
|
|
33873
|
-
testCoveragePct:
|
|
34582
|
+
frCoveragePct: report2.frCoveragePct,
|
|
34583
|
+
scCoveragePct: report2.scCoveragePct,
|
|
34584
|
+
testCoveragePct: report2.testCoveragePct,
|
|
33874
34585
|
issues
|
|
33875
34586
|
}
|
|
33876
34587
|
};
|
|
@@ -33949,14 +34660,14 @@ async function handleNext2(projectRoot) {
|
|
|
33949
34660
|
async function loadStateOrFail(projectRoot, command) {
|
|
33950
34661
|
const stateResult = await loadOpenspecState(projectRoot);
|
|
33951
34662
|
if (!stateResult.success) {
|
|
33952
|
-
return { ok: false, response:
|
|
34663
|
+
return { ok: false, response: fail3(command, [stateResult.error.message]) };
|
|
33953
34664
|
}
|
|
33954
34665
|
return { ok: true, state: stateResult.data };
|
|
33955
34666
|
}
|
|
33956
34667
|
function findItemOrFail(session, itemId, command) {
|
|
33957
34668
|
const item = session.doc.items.find((i) => i.id === itemId) ?? session.doc.archive.find((i) => i.id === itemId);
|
|
33958
34669
|
if (!item) {
|
|
33959
|
-
return { ok: false, response:
|
|
34670
|
+
return { ok: false, response: fail3(command, [`Backlog item ${itemId} not found`]) };
|
|
33960
34671
|
}
|
|
33961
34672
|
return {
|
|
33962
34673
|
ok: true,
|
|
@@ -33967,18 +34678,18 @@ function findItemOrFail(session, itemId, command) {
|
|
|
33967
34678
|
async function handleStart(projectRoot, cardId) {
|
|
33968
34679
|
const command = "openspec start";
|
|
33969
34680
|
if (!cardId) {
|
|
33970
|
-
return
|
|
34681
|
+
return fail3(command, ["Missing card id. Usage: openspec start <cardId>"]);
|
|
33971
34682
|
}
|
|
33972
34683
|
const sessionResult = await loadBacklogSession(projectRoot);
|
|
33973
34684
|
if (!sessionResult.success)
|
|
33974
|
-
return
|
|
34685
|
+
return fail3(command, [sessionResult.error.message]);
|
|
33975
34686
|
const session = sessionResult.data;
|
|
33976
34687
|
const card = findCard(session.state, cardId);
|
|
33977
34688
|
if (!card) {
|
|
33978
|
-
return
|
|
34689
|
+
return fail3(command, [`Task card ${cardId} not found`]);
|
|
33979
34690
|
}
|
|
33980
34691
|
if (card.status !== "pending" && card.status !== "doing") {
|
|
33981
|
-
return
|
|
34692
|
+
return fail3(command, [`Card ${cardId} cannot start from status ${card.status}`]);
|
|
33982
34693
|
}
|
|
33983
34694
|
const itemLoaded = findItemOrFail(session, card.backlogId, command);
|
|
33984
34695
|
if (!itemLoaded.ok)
|
|
@@ -34001,11 +34712,11 @@ async function handleStart(projectRoot, cardId) {
|
|
|
34001
34712
|
state = setTaskCardStatus(state, cardId, "doing");
|
|
34002
34713
|
const written = await persistState(projectRoot, state);
|
|
34003
34714
|
if (!written.ok)
|
|
34004
|
-
return
|
|
34715
|
+
return fail3(command, [written.error]);
|
|
34005
34716
|
}
|
|
34006
34717
|
const transition = await transitionItem(projectRoot, itemLoaded.item, "IN_PROGRESS", itemLoaded.item.progress, session.raw);
|
|
34007
34718
|
if (!transition.ok)
|
|
34008
|
-
return
|
|
34719
|
+
return fail3(command, [transition.error]);
|
|
34009
34720
|
return {
|
|
34010
34721
|
code: 0,
|
|
34011
34722
|
data: {
|
|
@@ -34022,15 +34733,15 @@ async function handleStart(projectRoot, cardId) {
|
|
|
34022
34733
|
async function handleDone(projectRoot, cardId) {
|
|
34023
34734
|
const command = "openspec done";
|
|
34024
34735
|
if (!cardId) {
|
|
34025
|
-
return
|
|
34736
|
+
return fail3(command, ["Missing card id. Usage: openspec done <cardId>"]);
|
|
34026
34737
|
}
|
|
34027
34738
|
const sessionResult = await loadBacklogSession(projectRoot);
|
|
34028
34739
|
if (!sessionResult.success)
|
|
34029
|
-
return
|
|
34740
|
+
return fail3(command, [sessionResult.error.message]);
|
|
34030
34741
|
const session = sessionResult.data;
|
|
34031
34742
|
const card = findCard(session.state, cardId);
|
|
34032
34743
|
if (!card) {
|
|
34033
|
-
return
|
|
34744
|
+
return fail3(command, [`Task card ${cardId} not found`]);
|
|
34034
34745
|
}
|
|
34035
34746
|
if (card.status === "done") {
|
|
34036
34747
|
return {
|
|
@@ -34039,7 +34750,7 @@ async function handleDone(projectRoot, cardId) {
|
|
|
34039
34750
|
};
|
|
34040
34751
|
}
|
|
34041
34752
|
if (card.status !== "doing") {
|
|
34042
|
-
return
|
|
34753
|
+
return fail3(command, [`Card ${cardId} must be doing before done (got ${card.status})`]);
|
|
34043
34754
|
}
|
|
34044
34755
|
const itemLoaded = findItemOrFail(session, card.backlogId, command);
|
|
34045
34756
|
if (!itemLoaded.ok)
|
|
@@ -34051,9 +34762,9 @@ async function handleDone(projectRoot, cardId) {
|
|
|
34051
34762
|
if (card.phase === "test") {
|
|
34052
34763
|
const recorded = await recordRedValidation(projectRoot, cardId);
|
|
34053
34764
|
if (!recorded.success)
|
|
34054
|
-
return
|
|
34765
|
+
return fail3(command, [`${message} ${recorded.error.message}`]);
|
|
34055
34766
|
} else if (!await hasTddRunnerEvidence(projectRoot, cardId, expectedPhase)) {
|
|
34056
|
-
return
|
|
34767
|
+
return fail3(command, [message]);
|
|
34057
34768
|
}
|
|
34058
34769
|
}
|
|
34059
34770
|
const state = setTaskCardStatus(session.state, cardId, "done");
|
|
@@ -34063,14 +34774,14 @@ async function handleDone(projectRoot, cardId) {
|
|
|
34063
34774
|
const allDone = cards.length > 0 && doneCount === cards.length;
|
|
34064
34775
|
const written = await persistState(projectRoot, state);
|
|
34065
34776
|
if (!written.ok)
|
|
34066
|
-
return
|
|
34777
|
+
return fail3(command, [written.error]);
|
|
34067
34778
|
const changePath = state.changePaths[card.backlogId];
|
|
34068
34779
|
if (changePath)
|
|
34069
34780
|
await syncTaskCardCheckbox(projectRoot, changePath, cardId, true);
|
|
34070
34781
|
const nextStatus = allDone ? "REVIEW" : "IN_PROGRESS";
|
|
34071
34782
|
const transition = await transitionItem(projectRoot, itemLoaded.item, nextStatus, progress, session.raw);
|
|
34072
34783
|
if (!transition.ok)
|
|
34073
|
-
return
|
|
34784
|
+
return fail3(command, [transition.error]);
|
|
34074
34785
|
return {
|
|
34075
34786
|
code: 0,
|
|
34076
34787
|
data: {
|
|
@@ -34088,18 +34799,18 @@ async function handleDone(projectRoot, cardId) {
|
|
|
34088
34799
|
async function handleBlock(projectRoot, cardId, reason) {
|
|
34089
34800
|
const command = "openspec block";
|
|
34090
34801
|
if (!cardId) {
|
|
34091
|
-
return
|
|
34802
|
+
return fail3(command, ["Missing card id. Usage: openspec block <cardId> --reason <text>"]);
|
|
34092
34803
|
}
|
|
34093
34804
|
if (!reason || !reason.trim()) {
|
|
34094
|
-
return
|
|
34805
|
+
return fail3(command, ["--reason is required"]);
|
|
34095
34806
|
}
|
|
34096
34807
|
const sessionResult = await loadBacklogSession(projectRoot);
|
|
34097
34808
|
if (!sessionResult.success)
|
|
34098
|
-
return
|
|
34809
|
+
return fail3(command, [sessionResult.error.message]);
|
|
34099
34810
|
const session = sessionResult.data;
|
|
34100
34811
|
const card = findCard(session.state, cardId);
|
|
34101
34812
|
if (!card) {
|
|
34102
|
-
return
|
|
34813
|
+
return fail3(command, [`Task card ${cardId} not found`]);
|
|
34103
34814
|
}
|
|
34104
34815
|
const itemLoaded = findItemOrFail(session, card.backlogId, command);
|
|
34105
34816
|
if (!itemLoaded.ok)
|
|
@@ -34107,10 +34818,10 @@ async function handleBlock(projectRoot, cardId, reason) {
|
|
|
34107
34818
|
const state = setTaskCardStatus(session.state, cardId, "blocked");
|
|
34108
34819
|
const written = await persistState(projectRoot, state);
|
|
34109
34820
|
if (!written.ok)
|
|
34110
|
-
return
|
|
34821
|
+
return fail3(command, [written.error]);
|
|
34111
34822
|
const transition = await transitionItem(projectRoot, itemLoaded.item, "BLOCKED", undefined, session.raw);
|
|
34112
34823
|
if (!transition.ok)
|
|
34113
|
-
return
|
|
34824
|
+
return fail3(command, [transition.error]);
|
|
34114
34825
|
return {
|
|
34115
34826
|
code: 0,
|
|
34116
34827
|
data: {
|
|
@@ -34127,37 +34838,37 @@ async function handleBlock(projectRoot, cardId, reason) {
|
|
|
34127
34838
|
async function handleUnblock(projectRoot, cardId) {
|
|
34128
34839
|
const command = "openspec unblock";
|
|
34129
34840
|
if (!cardId) {
|
|
34130
|
-
return
|
|
34841
|
+
return fail3(command, ["Missing card id. Usage: openspec unblock <cardId>"]);
|
|
34131
34842
|
}
|
|
34132
34843
|
const sessionResult = await loadBacklogSession(projectRoot);
|
|
34133
34844
|
if (!sessionResult.success)
|
|
34134
|
-
return
|
|
34845
|
+
return fail3(command, [sessionResult.error.message]);
|
|
34135
34846
|
const session = sessionResult.data;
|
|
34136
34847
|
const card = findCard(session.state, cardId);
|
|
34137
34848
|
if (!card) {
|
|
34138
|
-
return
|
|
34849
|
+
return fail3(command, [`Task card ${cardId} not found`]);
|
|
34139
34850
|
}
|
|
34140
34851
|
if (card.status !== "blocked") {
|
|
34141
|
-
return
|
|
34852
|
+
return fail3(command, [`Card ${cardId} must be blocked before unblock (got ${card.status})`]);
|
|
34142
34853
|
}
|
|
34143
34854
|
const itemLoaded = findItemOrFail(session, card.backlogId, command);
|
|
34144
34855
|
if (!itemLoaded.ok)
|
|
34145
34856
|
return itemLoaded.response;
|
|
34146
34857
|
if (itemLoaded.item.status !== "BLOCKED") {
|
|
34147
|
-
return
|
|
34858
|
+
return fail3(command, [
|
|
34148
34859
|
`Backlog item ${itemLoaded.item.id} must be BLOCKED before unblock (got ${itemLoaded.item.status})`
|
|
34149
34860
|
]);
|
|
34150
34861
|
}
|
|
34151
34862
|
const state = setTaskCardStatus(session.state, cardId, "pending");
|
|
34152
34863
|
const written = await persistState(projectRoot, state);
|
|
34153
34864
|
if (!written.ok)
|
|
34154
|
-
return
|
|
34865
|
+
return fail3(command, [written.error]);
|
|
34155
34866
|
const changePath = state.changePaths[card.backlogId];
|
|
34156
34867
|
if (changePath)
|
|
34157
34868
|
await syncTaskCardCheckbox(projectRoot, changePath, cardId, false);
|
|
34158
34869
|
const transition = await transitionItem(projectRoot, itemLoaded.item, "READY", undefined, session.raw);
|
|
34159
34870
|
if (!transition.ok)
|
|
34160
|
-
return
|
|
34871
|
+
return fail3(command, [transition.error]);
|
|
34161
34872
|
return {
|
|
34162
34873
|
code: 0,
|
|
34163
34874
|
data: {
|
|
@@ -34174,35 +34885,35 @@ async function handleUnblock(projectRoot, cardId) {
|
|
|
34174
34885
|
async function handleArchive(projectRoot, itemId, allowUnchecked = false) {
|
|
34175
34886
|
const command = "openspec archive";
|
|
34176
34887
|
if (!itemId) {
|
|
34177
|
-
return
|
|
34888
|
+
return fail3(command, ["Missing item id. Usage: openspec archive <itemId>"]);
|
|
34178
34889
|
}
|
|
34179
34890
|
const sessionResult = await loadBacklogSession(projectRoot);
|
|
34180
34891
|
if (!sessionResult.success)
|
|
34181
|
-
return
|
|
34892
|
+
return fail3(command, [sessionResult.error.message]);
|
|
34182
34893
|
const session = sessionResult.data;
|
|
34183
34894
|
const itemLoaded = findItemOrFail(session, itemId, command);
|
|
34184
34895
|
if (!itemLoaded.ok)
|
|
34185
34896
|
return itemLoaded.response;
|
|
34186
34897
|
const cards = itemCards(session.state, itemId);
|
|
34187
34898
|
if (cards.length === 0) {
|
|
34188
|
-
return
|
|
34899
|
+
return fail3(command, [`No task cards found for ${itemId}. Run openspec plan first.`]);
|
|
34189
34900
|
}
|
|
34190
34901
|
const unfinished = cards.filter((c) => c.status !== "done");
|
|
34191
34902
|
if (unfinished.length > 0) {
|
|
34192
|
-
return
|
|
34903
|
+
return fail3(command, [
|
|
34193
34904
|
`Cannot archive ${itemId}: ${unfinished.length} card(s) are not done (${unfinished.map((c) => c.id).join(", ")})`
|
|
34194
34905
|
]);
|
|
34195
34906
|
}
|
|
34196
34907
|
if (itemLoaded.reviewRequired) {
|
|
34197
34908
|
const reviewCard = cards.find((c) => c.phase === "review");
|
|
34198
34909
|
if (!reviewCard || reviewCard.status !== "done") {
|
|
34199
|
-
return
|
|
34910
|
+
return fail3(command, [
|
|
34200
34911
|
`Cannot archive ${itemId}: global.reviewRequired needs the review phase card done`
|
|
34201
34912
|
]);
|
|
34202
34913
|
}
|
|
34203
34914
|
const passed = await hasPassingScorecard(projectRoot, itemId);
|
|
34204
34915
|
if (!passed) {
|
|
34205
|
-
return
|
|
34916
|
+
return fail3(command, [
|
|
34206
34917
|
`Cannot archive ${itemId}: global.reviewRequired needs a PASS scorecard for this backlog id`
|
|
34207
34918
|
]);
|
|
34208
34919
|
}
|
|
@@ -34214,21 +34925,21 @@ async function handleArchive(projectRoot, itemId, allowUnchecked = false) {
|
|
|
34214
34925
|
const progress = await readArtifactProgress(projectRoot, changePath);
|
|
34215
34926
|
const missing = missingArtifacts(progress.artifacts);
|
|
34216
34927
|
if (missing.length > 0) {
|
|
34217
|
-
return
|
|
34928
|
+
return fail3(command, [
|
|
34218
34929
|
`Cannot archive ${itemId}: change folder is missing ${missing.join(", ")}. Re-run openspec plan ${itemId} or restore them.`
|
|
34219
34930
|
]);
|
|
34220
34931
|
}
|
|
34221
|
-
const { report } = await collectAnalyzeReport(projectRoot, session, itemId, changePath);
|
|
34222
|
-
const critical =
|
|
34932
|
+
const { report: report2 } = await collectAnalyzeReport(projectRoot, session, itemId, changePath);
|
|
34933
|
+
const critical = report2.findings.filter((f) => f.severity === "CRITICAL");
|
|
34223
34934
|
if (critical.length > 0) {
|
|
34224
|
-
return
|
|
34935
|
+
return fail3(command, [
|
|
34225
34936
|
`Cannot archive ${itemId}: analyze reports ${critical.length} CRITICAL finding(s): ${critical.map((f) => f.code).join(", ")}. Resolve them first.`
|
|
34226
34937
|
]);
|
|
34227
34938
|
}
|
|
34228
34939
|
if (progress.checkboxes.remaining > 0) {
|
|
34229
34940
|
const unchecked = `${progress.checkboxes.remaining} of ${progress.checkboxes.total} tasks.md checkboxes are unchecked (only [x]/[X] counts as done)`;
|
|
34230
34941
|
if (!allowUnchecked) {
|
|
34231
|
-
return
|
|
34942
|
+
return fail3(command, [
|
|
34232
34943
|
`Cannot archive ${itemId}: ${unchecked}. Tick them as the work completes, or pass --allow-unchecked to archive anyway.`
|
|
34233
34944
|
]);
|
|
34234
34945
|
}
|
|
@@ -34236,12 +34947,12 @@ async function handleArchive(projectRoot, itemId, allowUnchecked = false) {
|
|
|
34236
34947
|
}
|
|
34237
34948
|
const synced = await syncChangeSpecs(projectRoot, changePath);
|
|
34238
34949
|
if (!synced.success) {
|
|
34239
|
-
return
|
|
34950
|
+
return fail3(command, [`Cannot archive ${itemId}: spec sync failed: ${synced.errors.join("; ")}`]);
|
|
34240
34951
|
}
|
|
34241
34952
|
try {
|
|
34242
34953
|
archivedPath = await archiveChangeFolder(projectRoot, changePath);
|
|
34243
34954
|
} catch (e) {
|
|
34244
|
-
return
|
|
34955
|
+
return fail3(command, [
|
|
34245
34956
|
`Backlog archived but change folder move failed: ${e instanceof Error ? e.message : String(e)}`
|
|
34246
34957
|
]);
|
|
34247
34958
|
}
|
|
@@ -34250,7 +34961,7 @@ async function handleArchive(projectRoot, itemId, allowUnchecked = false) {
|
|
|
34250
34961
|
if (itemLoaded.item.status !== "DONE") {
|
|
34251
34962
|
const toDone = await transitionItem(projectRoot, itemLoaded.item, "DONE", 100, content);
|
|
34252
34963
|
if (!toDone.ok)
|
|
34253
|
-
return
|
|
34964
|
+
return fail3(command, [toDone.error]);
|
|
34254
34965
|
content = toDone.content;
|
|
34255
34966
|
}
|
|
34256
34967
|
const archived = archiveItemInMarkdown(content, itemId);
|
|
@@ -34262,7 +34973,7 @@ async function handleArchive(projectRoot, itemId, allowUnchecked = false) {
|
|
|
34262
34973
|
};
|
|
34263
34974
|
const written = await persistState(projectRoot, nextState);
|
|
34264
34975
|
if (!written.ok)
|
|
34265
|
-
return
|
|
34976
|
+
return fail3(command, [written.error]);
|
|
34266
34977
|
return {
|
|
34267
34978
|
code: 0,
|
|
34268
34979
|
data: {
|
|
@@ -34327,25 +35038,25 @@ var init_handoff_envelope = __esm(() => {
|
|
|
34327
35038
|
});
|
|
34328
35039
|
|
|
34329
35040
|
// src/core/delivery/delivery-ledger.ts
|
|
34330
|
-
import { createHash as
|
|
34331
|
-
import { mkdir as
|
|
34332
|
-
import { resolve as
|
|
35041
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
35042
|
+
import { mkdir as mkdir32, readFile as readFile56, writeFile as writeFile30 } from "node:fs/promises";
|
|
35043
|
+
import { resolve as resolve51, sep as sep10 } from "node:path";
|
|
34333
35044
|
function ledgerPath(projectRoot, id) {
|
|
34334
35045
|
if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(id))
|
|
34335
35046
|
throw new Error("Invalid delivery ledger id");
|
|
34336
|
-
return
|
|
35047
|
+
return resolve51(projectRoot, DELIVERY_DIR, `${id}.md`);
|
|
34337
35048
|
}
|
|
34338
35049
|
async function fingerprintWorkspace(projectRoot, paths) {
|
|
34339
|
-
const root =
|
|
35050
|
+
const root = resolve51(projectRoot);
|
|
34340
35051
|
const fingerprints = {};
|
|
34341
35052
|
for (const path of paths) {
|
|
34342
|
-
const candidate =
|
|
35053
|
+
const candidate = resolve51(root, path);
|
|
34343
35054
|
if (candidate !== root && !candidate.startsWith(`${root}${sep10}`)) {
|
|
34344
35055
|
fingerprints[path] = "outside-root";
|
|
34345
35056
|
continue;
|
|
34346
35057
|
}
|
|
34347
35058
|
try {
|
|
34348
|
-
fingerprints[path] =
|
|
35059
|
+
fingerprints[path] = createHash14("sha256").update(await readFile56(candidate)).digest("hex");
|
|
34349
35060
|
} catch {
|
|
34350
35061
|
fingerprints[path] = "missing";
|
|
34351
35062
|
}
|
|
@@ -34368,7 +35079,7 @@ function parseLedger(content) {
|
|
|
34368
35079
|
return DeliveryLedgerSchema.parse($parse(match[1]));
|
|
34369
35080
|
}
|
|
34370
35081
|
async function loadDeliveryLedger(projectRoot, id) {
|
|
34371
|
-
return parseLedger(await
|
|
35082
|
+
return parseLedger(await readFile56(ledgerPath(projectRoot, id), "utf-8"));
|
|
34372
35083
|
}
|
|
34373
35084
|
async function createDeliveryLedger(projectRoot, input) {
|
|
34374
35085
|
const request = DeliveryLedgerRequestSchema.parse(input);
|
|
@@ -34393,7 +35104,7 @@ async function createDeliveryLedger(projectRoot, input) {
|
|
|
34393
35104
|
createdAt: now,
|
|
34394
35105
|
updatedAt: now
|
|
34395
35106
|
});
|
|
34396
|
-
await
|
|
35107
|
+
await mkdir32(resolve51(projectRoot, DELIVERY_DIR), { recursive: true });
|
|
34397
35108
|
try {
|
|
34398
35109
|
await writeFile30(path, render(ledger), { encoding: "utf-8", flag: "wx" });
|
|
34399
35110
|
return { created: true, ledger };
|
|
@@ -34523,7 +35234,7 @@ __export(exports_hook_command, {
|
|
|
34523
35234
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
34524
35235
|
import { existsSync as existsSync10, readFileSync as readFileSync7 } from "node:fs";
|
|
34525
35236
|
import { createRequire as createRequire2 } from "node:module";
|
|
34526
|
-
import { dirname as
|
|
35237
|
+
import { dirname as dirname17, resolve as resolve52 } from "node:path";
|
|
34527
35238
|
function parseHookFormat(raw) {
|
|
34528
35239
|
return raw === "agy" || raw === "claude" || raw === "muse" ? raw : undefined;
|
|
34529
35240
|
}
|
|
@@ -34556,12 +35267,12 @@ function resolvePreToolInput(options, stdinText, format) {
|
|
|
34556
35267
|
scopeFiles: options.scopeFiles,
|
|
34557
35268
|
dispatchMode: options.dispatchMode,
|
|
34558
35269
|
leaf: options.leaf,
|
|
34559
|
-
exists: options.dispatchMode && filePath ? existsSync10(
|
|
35270
|
+
exists: options.dispatchMode && filePath ? existsSync10(resolve52(options.projectRoot, filePath)) : undefined
|
|
34560
35271
|
};
|
|
34561
35272
|
}
|
|
34562
35273
|
async function sessionLines(projectRoot) {
|
|
34563
|
-
const backlogPath =
|
|
34564
|
-
const profilePath =
|
|
35274
|
+
const backlogPath = resolve52(projectRoot, "BACKLOG.md");
|
|
35275
|
+
const profilePath = resolve52(projectRoot, ".codeconductor", "evaluation", "execution-profile.yml");
|
|
34565
35276
|
return [
|
|
34566
35277
|
"[CodeConductor] Session start",
|
|
34567
35278
|
"Skills: openspec, backlog, evaluation, testing-tdd — invoke via /cc-* then CLI.",
|
|
@@ -34650,21 +35361,21 @@ async function hookCommand(options) {
|
|
|
34650
35361
|
function formatWrittenFile(filePath, projectRoot) {
|
|
34651
35362
|
if (!filePath)
|
|
34652
35363
|
return;
|
|
34653
|
-
filePath =
|
|
35364
|
+
filePath = resolve52(projectRoot, filePath);
|
|
34654
35365
|
if (!existsSync10(filePath))
|
|
34655
35366
|
return;
|
|
34656
35367
|
const prettier = /\.(ts|tsx|js|jsx|mjs|cjs|json|jsonc|md|mdx|css|scss|html|astro|ya?ml)$/i;
|
|
34657
35368
|
const eslint = /\.(ts|tsx|js|jsx|mjs|cjs)$/i;
|
|
34658
35369
|
const python = /\.py$/i;
|
|
34659
35370
|
const opts = { cwd: projectRoot, stdio: "ignore", windowsHide: true, timeout: 5000 };
|
|
34660
|
-
const require2 = createRequire2(
|
|
35371
|
+
const require2 = createRequire2(resolve52(projectRoot, "package.json"));
|
|
34661
35372
|
function runNodeTool(name, args) {
|
|
34662
35373
|
try {
|
|
34663
35374
|
const manifestPath = require2.resolve(`${name}/package.json`);
|
|
34664
35375
|
const manifest = JSON.parse(readFileSync7(manifestPath, "utf8"));
|
|
34665
35376
|
const bin = typeof manifest.bin === "string" ? manifest.bin : manifest.bin?.[name];
|
|
34666
35377
|
if (typeof bin === "string")
|
|
34667
|
-
spawnSync2(process.execPath, [
|
|
35378
|
+
spawnSync2(process.execPath, [resolve52(dirname17(manifestPath), bin), ...args], opts);
|
|
34668
35379
|
} catch {}
|
|
34669
35380
|
}
|
|
34670
35381
|
if (prettier.test(filePath)) {
|
|
@@ -34968,13 +35679,13 @@ var init_complexity_auditor = __esm(() => {
|
|
|
34968
35679
|
});
|
|
34969
35680
|
|
|
34970
35681
|
// src/core/complexity/cc-gain.ts
|
|
34971
|
-
function computeCcGain(
|
|
34972
|
-
const locContribution =
|
|
34973
|
-
const depsAvoided =
|
|
35682
|
+
function computeCcGain(report2) {
|
|
35683
|
+
const locContribution = report2.locRemoved * 0.4;
|
|
35684
|
+
const depsAvoided = report2.depsRemoved.length - report2.depsAdded.length;
|
|
34974
35685
|
const depContribution = depsAvoided * 1.5;
|
|
34975
|
-
const complexityReduced =
|
|
35686
|
+
const complexityReduced = report2.cyclomaticRemoved - report2.cyclomaticAdded;
|
|
34976
35687
|
const complexityContribution = complexityReduced * 2;
|
|
34977
|
-
const abstractionFindings =
|
|
35688
|
+
const abstractionFindings = report2.findings.filter((f) => f.pattern === "excessive-abstraction" || f.pattern === "single-implementation-interface" || f.pattern === "one-method-class" || f.pattern === "trivial-wrapper").length;
|
|
34978
35689
|
const abstractionPenalty = abstractionFindings * 1;
|
|
34979
35690
|
const raw = locContribution + depContribution + complexityContribution - abstractionPenalty;
|
|
34980
35691
|
const MAX_RAW = 50;
|
|
@@ -35178,16 +35889,16 @@ function collectScorecardSignals(projectRoot, scopeFiles, extra) {
|
|
|
35178
35889
|
}
|
|
35179
35890
|
}
|
|
35180
35891
|
try {
|
|
35181
|
-
const
|
|
35182
|
-
const gain = computeCcGain(
|
|
35892
|
+
const report2 = analyzeDiff(diff);
|
|
35893
|
+
const gain = computeCcGain(report2);
|
|
35183
35894
|
const ccScore = ccGainToScorecardImpact(gain);
|
|
35184
35895
|
overrides.cc_gain = {
|
|
35185
35896
|
score: ccScore,
|
|
35186
35897
|
notes: `cc-gain raw=${gain.raw}, verdict=${gain.verdict}`,
|
|
35187
35898
|
autoSuggested: true
|
|
35188
35899
|
};
|
|
35189
|
-
if (
|
|
35190
|
-
findings.push(`Complexity auditor: ${
|
|
35900
|
+
if (report2.findings.length > 0) {
|
|
35901
|
+
findings.push(`Complexity auditor: ${report2.findings.length} finding(s).`);
|
|
35191
35902
|
}
|
|
35192
35903
|
} catch {
|
|
35193
35904
|
findings.push("Complexity audit skipped.");
|
|
@@ -35404,24 +36115,24 @@ var init_telemetry_command = __esm(() => {
|
|
|
35404
36115
|
|
|
35405
36116
|
// src/core/evaluation/harness-experiment.ts
|
|
35406
36117
|
import { existsSync as existsSync11 } from "node:fs";
|
|
35407
|
-
import { cp, mkdir as
|
|
35408
|
-
import { dirname as
|
|
36118
|
+
import { cp, mkdir as mkdir33, readFile as readFile57, readdir as readdir19, writeFile as writeFile31 } from "node:fs/promises";
|
|
36119
|
+
import { dirname as dirname18, join as join39, resolve as resolve53 } from "node:path";
|
|
35409
36120
|
function experimentDir(projectRoot, experimentId) {
|
|
35410
|
-
return
|
|
36121
|
+
return resolve53(projectRoot, EVAL_DIR2, EXPERIMENTS_DIR, experimentId);
|
|
35411
36122
|
}
|
|
35412
36123
|
function experimentYamlPath(projectRoot, experimentId) {
|
|
35413
|
-
return
|
|
36124
|
+
return join39(experimentDir(projectRoot, experimentId), "experiment.yml");
|
|
35414
36125
|
}
|
|
35415
36126
|
async function loadHarnessSuite(projectRoot, suiteId, suitePath) {
|
|
35416
36127
|
const candidates = suitePath ? [suitePath] : [
|
|
35417
|
-
|
|
35418
|
-
|
|
36128
|
+
resolve53(projectRoot, "eval", "suites", suiteId, "suite.yml"),
|
|
36129
|
+
resolve53(projectRoot, EVAL_DIR2, "suites", suiteId, "suite.yml")
|
|
35419
36130
|
];
|
|
35420
36131
|
for (const path of candidates) {
|
|
35421
36132
|
if (!existsSync11(path))
|
|
35422
36133
|
continue;
|
|
35423
36134
|
try {
|
|
35424
|
-
const suite = HarnessSuiteSchema.parse($parse(await
|
|
36135
|
+
const suite = HarnessSuiteSchema.parse($parse(await readFile57(path, "utf-8")));
|
|
35425
36136
|
return ok({ ...suite, path });
|
|
35426
36137
|
} catch (e) {
|
|
35427
36138
|
return err(e instanceof Error ? e : new Error(String(e)));
|
|
@@ -35431,7 +36142,7 @@ async function loadHarnessSuite(projectRoot, suiteId, suitePath) {
|
|
|
35431
36142
|
}
|
|
35432
36143
|
async function loadExperiment(projectRoot, experimentId) {
|
|
35433
36144
|
try {
|
|
35434
|
-
const raw = await
|
|
36145
|
+
const raw = await readFile57(experimentYamlPath(projectRoot, experimentId), "utf-8");
|
|
35435
36146
|
return ok(HarnessExperimentSchema.parse($parse(raw)));
|
|
35436
36147
|
} catch (e) {
|
|
35437
36148
|
if (e.code === "ENOENT") {
|
|
@@ -35441,10 +36152,10 @@ async function loadExperiment(projectRoot, experimentId) {
|
|
|
35441
36152
|
}
|
|
35442
36153
|
}
|
|
35443
36154
|
async function listExperiments(projectRoot) {
|
|
35444
|
-
const root =
|
|
36155
|
+
const root = resolve53(projectRoot, EVAL_DIR2, EXPERIMENTS_DIR);
|
|
35445
36156
|
if (!existsSync11(root))
|
|
35446
36157
|
return [];
|
|
35447
|
-
const ids = await
|
|
36158
|
+
const ids = await readdir19(root);
|
|
35448
36159
|
const experiments = [];
|
|
35449
36160
|
for (const id of ids) {
|
|
35450
36161
|
const loaded = await loadExperiment(projectRoot, id);
|
|
@@ -35520,8 +36231,8 @@ function generateExperimentId(suiteId, now = new Date) {
|
|
|
35520
36231
|
return `abl-${date}-${suiteId}-${rand}`;
|
|
35521
36232
|
}
|
|
35522
36233
|
async function copyFixture(suitePath, fixtureDir, dest) {
|
|
35523
|
-
const source = fixtureDir ?
|
|
35524
|
-
await
|
|
36234
|
+
const source = fixtureDir ? resolve53(dirname18(suitePath), fixtureDir) : join39(dirname18(suitePath), "fixture");
|
|
36235
|
+
await mkdir33(dest, { recursive: true });
|
|
35525
36236
|
if (existsSync11(source)) {
|
|
35526
36237
|
await cp(source, dest, { recursive: true });
|
|
35527
36238
|
}
|
|
@@ -35543,12 +36254,12 @@ async function startHarnessExperiment(projectRoot, options) {
|
|
|
35543
36254
|
suitePath: suite.data.path
|
|
35544
36255
|
};
|
|
35545
36256
|
const root = experimentDir(projectRoot, experimentId);
|
|
35546
|
-
await
|
|
36257
|
+
await mkdir33(root, { recursive: true });
|
|
35547
36258
|
await writeFile31(experimentYamlPath(projectRoot, experimentId), $stringify(experiment), "utf-8");
|
|
35548
|
-
await writeFile31(
|
|
36259
|
+
await writeFile31(join39(root, "EXPERIMENT.md"), formatExperimentMarkdown(experiment), "utf-8");
|
|
35549
36260
|
for (const task of suite.data.tasks) {
|
|
35550
36261
|
for (const variantId of variants) {
|
|
35551
|
-
const runRoot =
|
|
36262
|
+
const runRoot = join39(root, "runs", task.id, variantDirName(variantId));
|
|
35552
36263
|
await copyFixture(suite.data.path, suite.data.fixtureDir, runRoot);
|
|
35553
36264
|
await writeConfig(runRoot, structuredClone(DEFAULT_CONFIG), true);
|
|
35554
36265
|
const disabled = variantId === "baseline" ? [] : options.components.filter((id) => variantIdFor(id) === variantId);
|
|
@@ -35560,7 +36271,7 @@ async function startHarnessExperiment(projectRoot, options) {
|
|
|
35560
36271
|
});
|
|
35561
36272
|
if (!overlay.success)
|
|
35562
36273
|
return overlay;
|
|
35563
|
-
await writeFile31(
|
|
36274
|
+
await writeFile31(join39(runRoot, "TASK.md"), formatTaskCard(task, experimentId, variantId), "utf-8");
|
|
35564
36275
|
}
|
|
35565
36276
|
}
|
|
35566
36277
|
return ok(experiment);
|
|
@@ -35595,7 +36306,7 @@ var init_harness_experiment = __esm(() => {
|
|
|
35595
36306
|
// src/core/evaluation/suite-run.ts
|
|
35596
36307
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
35597
36308
|
import { existsSync as existsSync12 } from "node:fs";
|
|
35598
|
-
import { resolve as
|
|
36309
|
+
import { resolve as resolve54 } from "node:path";
|
|
35599
36310
|
async function runHarnessSuiteTasks(projectRoot, suiteId, suitePath) {
|
|
35600
36311
|
const suite = await loadHarnessSuite(projectRoot, suiteId, suitePath);
|
|
35601
36312
|
if (!suite.success) {
|
|
@@ -35655,7 +36366,7 @@ function runTaskCommand(projectRoot, task) {
|
|
|
35655
36366
|
if (parts.length === 0) {
|
|
35656
36367
|
return { ok: false, detail: "Empty testCommand" };
|
|
35657
36368
|
}
|
|
35658
|
-
const bin = parts[0] === "bun" && existsSync12(
|
|
36369
|
+
const bin = parts[0] === "bun" && existsSync12(resolve54(projectRoot, "src/cli/main.ts")) ? "bun" : parts[0];
|
|
35659
36370
|
const args = parts[0] === "bun" ? parts.slice(1) : parts.slice(1);
|
|
35660
36371
|
const result = spawnSync3(bin, args, {
|
|
35661
36372
|
cwd: projectRoot,
|
|
@@ -35707,11 +36418,11 @@ var init_suite_run = __esm(() => {
|
|
|
35707
36418
|
});
|
|
35708
36419
|
|
|
35709
36420
|
// src/core/evaluation/execution-profile.ts
|
|
35710
|
-
import { readFile as
|
|
35711
|
-
import { resolve as
|
|
36421
|
+
import { readFile as readFile58 } from "node:fs/promises";
|
|
36422
|
+
import { resolve as resolve55 } from "node:path";
|
|
35712
36423
|
async function loadExecutionProfile(projectRoot, defaultTarget = "opencode") {
|
|
35713
36424
|
try {
|
|
35714
|
-
const content = await
|
|
36425
|
+
const content = await readFile58(resolve55(projectRoot, PROFILE_FILE), "utf-8");
|
|
35715
36426
|
const data = $parse(content);
|
|
35716
36427
|
return ExecutionProfileSchema.parse(data);
|
|
35717
36428
|
} catch {
|
|
@@ -35791,12 +36502,12 @@ var init_execution_profile = __esm(() => {
|
|
|
35791
36502
|
});
|
|
35792
36503
|
|
|
35793
36504
|
// src/core/ccep/prompt-metrics.ts
|
|
35794
|
-
import { createHash as
|
|
36505
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
35795
36506
|
function estimateTokens(bytes) {
|
|
35796
36507
|
return Math.ceil(bytes / 4);
|
|
35797
36508
|
}
|
|
35798
36509
|
function sha256Hex(text) {
|
|
35799
|
-
return
|
|
36510
|
+
return createHash15("sha256").update(text, "utf8").digest("hex");
|
|
35800
36511
|
}
|
|
35801
36512
|
function layerBytes(content) {
|
|
35802
36513
|
return Buffer.byteLength(content, "utf8");
|
|
@@ -36027,16 +36738,16 @@ var SHINGLE_LINES = 8;
|
|
|
36027
36738
|
var init_prompt_metrics = () => {};
|
|
36028
36739
|
|
|
36029
36740
|
// src/core/evaluation/prompt-diff.ts
|
|
36030
|
-
import { mkdtemp as mkdtemp2, readFile as
|
|
36741
|
+
import { mkdtemp as mkdtemp2, readFile as readFile59, readdir as readdir20, rm as rm5, symlink, lstat as lstat5, writeFile as writeFile32 } from "node:fs/promises";
|
|
36031
36742
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
36032
|
-
import { join as
|
|
36743
|
+
import { join as join40, resolve as resolve56 } from "node:path";
|
|
36033
36744
|
import { spawn as spawn2 } from "node:child_process";
|
|
36034
36745
|
function normalizeVersion(v) {
|
|
36035
36746
|
return v.startsWith("v") ? v : `v${v}`;
|
|
36036
36747
|
}
|
|
36037
36748
|
async function listPromptFiles(dir) {
|
|
36038
36749
|
try {
|
|
36039
|
-
const entries = await
|
|
36750
|
+
const entries = await readdir20(dir, { withFileTypes: true });
|
|
36040
36751
|
return entries.filter((e) => e.isFile() && e.name.endsWith(".md")).map((e) => e.name);
|
|
36041
36752
|
} catch {
|
|
36042
36753
|
return [];
|
|
@@ -36079,30 +36790,30 @@ async function diffPromptVersions(fromVersion, toVersion, options = {}) {
|
|
|
36079
36790
|
const fromV = normalizeVersion(fromVersion);
|
|
36080
36791
|
const toV = normalizeVersion(toVersion);
|
|
36081
36792
|
const searchRoots = [
|
|
36082
|
-
|
|
36083
|
-
|
|
36084
|
-
|
|
36793
|
+
resolve56(options.projectRoot ?? PACKAGE_ROOT, ".agents", "prompts"),
|
|
36794
|
+
join40(ROOT_PRESETS_DIR, target, "prompts"),
|
|
36795
|
+
join40(ROOT_PRESETS_DIR, "opencode", "prompts")
|
|
36085
36796
|
];
|
|
36086
36797
|
let fromDir = "";
|
|
36087
36798
|
let toDir = "";
|
|
36088
36799
|
for (const root of searchRoots) {
|
|
36089
|
-
const f =
|
|
36090
|
-
const t =
|
|
36800
|
+
const f = join40(root, fromV);
|
|
36801
|
+
const t = join40(root, toV);
|
|
36091
36802
|
try {
|
|
36092
|
-
await
|
|
36803
|
+
await readFile59(join40(f, "orchestrator.md"), "utf-8");
|
|
36093
36804
|
fromDir = f;
|
|
36094
36805
|
toDir = t;
|
|
36095
36806
|
break;
|
|
36096
36807
|
} catch {}
|
|
36097
36808
|
}
|
|
36098
36809
|
if (!fromDir) {
|
|
36099
|
-
fromDir =
|
|
36100
|
-
toDir =
|
|
36810
|
+
fromDir = join40(ROOT_PRESETS_DIR, "opencode", "prompts", fromV);
|
|
36811
|
+
toDir = join40(ROOT_PRESETS_DIR, "opencode", "prompts", toV);
|
|
36101
36812
|
} else {
|
|
36102
36813
|
try {
|
|
36103
|
-
await
|
|
36814
|
+
await readFile59(join40(toDir, "orchestrator.md"), "utf-8");
|
|
36104
36815
|
} catch {
|
|
36105
|
-
toDir =
|
|
36816
|
+
toDir = join40(ROOT_PRESETS_DIR, "opencode", "prompts", toV);
|
|
36106
36817
|
}
|
|
36107
36818
|
}
|
|
36108
36819
|
const fromFiles = await listPromptFiles(fromDir);
|
|
@@ -36120,12 +36831,12 @@ async function diffPromptVersions(fromVersion, toVersion, options = {}) {
|
|
|
36120
36831
|
let oldText = "";
|
|
36121
36832
|
let newText = "";
|
|
36122
36833
|
try {
|
|
36123
|
-
oldText = await
|
|
36834
|
+
oldText = await readFile59(join40(fromDir, name), "utf-8");
|
|
36124
36835
|
} catch {
|
|
36125
36836
|
oldText = "";
|
|
36126
36837
|
}
|
|
36127
36838
|
try {
|
|
36128
|
-
newText = await
|
|
36839
|
+
newText = await readFile59(join40(toDir, name), "utf-8");
|
|
36129
36840
|
} catch {
|
|
36130
36841
|
newText = "";
|
|
36131
36842
|
}
|
|
@@ -36203,7 +36914,7 @@ function buildHarnessV1CompileContext(options = {}) {
|
|
|
36203
36914
|
fixtureId: "eval/suites/harness-v1"
|
|
36204
36915
|
};
|
|
36205
36916
|
}
|
|
36206
|
-
function
|
|
36917
|
+
function runGit2(args, cwd) {
|
|
36207
36918
|
return new Promise((resolvePromise, reject) => {
|
|
36208
36919
|
const child = spawn2("git", args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
36209
36920
|
let stdout = "";
|
|
@@ -36224,29 +36935,29 @@ function runGit(args, cwd) {
|
|
|
36224
36935
|
});
|
|
36225
36936
|
}
|
|
36226
36937
|
async function linkNodeModules(gitRoot, worktreePath) {
|
|
36227
|
-
const src =
|
|
36228
|
-
const dest =
|
|
36938
|
+
const src = join40(gitRoot, "node_modules");
|
|
36939
|
+
const dest = join40(worktreePath, "node_modules");
|
|
36229
36940
|
try {
|
|
36230
|
-
await
|
|
36941
|
+
await lstat5(src);
|
|
36231
36942
|
} catch {
|
|
36232
36943
|
return;
|
|
36233
36944
|
}
|
|
36234
36945
|
try {
|
|
36235
|
-
await
|
|
36946
|
+
await lstat5(dest);
|
|
36236
36947
|
return;
|
|
36237
36948
|
} catch {}
|
|
36238
36949
|
await symlink(src, dest, "dir");
|
|
36239
36950
|
}
|
|
36240
36951
|
async function withGitWorktree(gitRoot, ref, fn) {
|
|
36241
|
-
const base = await mkdtemp2(
|
|
36242
|
-
const worktreePath =
|
|
36952
|
+
const base = await mkdtemp2(join40(tmpdir2(), "cc-prompt-diff-"));
|
|
36953
|
+
const worktreePath = join40(base, ref.replace(/[^A-Za-z0-9._-]/g, "_"));
|
|
36243
36954
|
try {
|
|
36244
|
-
await
|
|
36955
|
+
await runGit2(["worktree", "add", "--detach", worktreePath, ref], gitRoot);
|
|
36245
36956
|
await linkNodeModules(gitRoot, worktreePath);
|
|
36246
36957
|
return await fn(worktreePath);
|
|
36247
36958
|
} finally {
|
|
36248
36959
|
try {
|
|
36249
|
-
await
|
|
36960
|
+
await runGit2(["worktree", "remove", "--force", worktreePath], gitRoot);
|
|
36250
36961
|
} catch {}
|
|
36251
36962
|
await rm5(base, { recursive: true, force: true }).catch(() => {
|
|
36252
36963
|
return;
|
|
@@ -36254,8 +36965,8 @@ async function withGitWorktree(gitRoot, ref, fn) {
|
|
|
36254
36965
|
}
|
|
36255
36966
|
}
|
|
36256
36967
|
async function compileLayersInWorktree(worktreePath, fixed) {
|
|
36257
|
-
const payloadPath =
|
|
36258
|
-
const scriptPath =
|
|
36968
|
+
const payloadPath = join40(worktreePath, ".cc-prompt-diff-input.json");
|
|
36969
|
+
const scriptPath = join40(worktreePath, ".cc-prompt-diff-compile.mjs");
|
|
36259
36970
|
await writeFile32(payloadPath, JSON.stringify({
|
|
36260
36971
|
role: fixed.role,
|
|
36261
36972
|
phase: fixed.phase,
|
|
@@ -36388,12 +37099,12 @@ var init_prompt_diff = __esm(() => {
|
|
|
36388
37099
|
|
|
36389
37100
|
// src/core/evaluation/regression-checklist.ts
|
|
36390
37101
|
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
36391
|
-
import { mkdir as
|
|
36392
|
-
import { dirname as
|
|
37102
|
+
import { mkdir as mkdir34, readFile as readFile60, writeFile as writeFile33 } from "node:fs/promises";
|
|
37103
|
+
import { dirname as dirname19, resolve as resolve57 } from "node:path";
|
|
36393
37104
|
async function loadRegressionChecklist() {
|
|
36394
37105
|
try {
|
|
36395
|
-
const path =
|
|
36396
|
-
const content = await
|
|
37106
|
+
const path = resolve57(ROOT_PRESETS_DIR, "templates", "regression-checklist.yml");
|
|
37107
|
+
const content = await readFile60(path, "utf-8");
|
|
36397
37108
|
const data = $parse(content);
|
|
36398
37109
|
return data.checks ?? [];
|
|
36399
37110
|
} catch {
|
|
@@ -36443,15 +37154,15 @@ async function runRegressionChecklist(projectRoot, options = {}) {
|
|
|
36443
37154
|
...outcome
|
|
36444
37155
|
});
|
|
36445
37156
|
}
|
|
36446
|
-
const
|
|
37157
|
+
const report2 = {
|
|
36447
37158
|
passed: checks.every((c) => !c.required || c.passed),
|
|
36448
37159
|
checks,
|
|
36449
37160
|
timestamp: new Date().toISOString()
|
|
36450
37161
|
};
|
|
36451
|
-
const outPath =
|
|
36452
|
-
await
|
|
36453
|
-
await writeFile33(outPath, JSON.stringify(
|
|
36454
|
-
return ok(
|
|
37162
|
+
const outPath = resolve57(projectRoot, ".codeconductor/evaluation/regression-last.json");
|
|
37163
|
+
await mkdir34(dirname19(outPath), { recursive: true });
|
|
37164
|
+
await writeFile33(outPath, JSON.stringify(report2, null, 2), "utf-8");
|
|
37165
|
+
return ok(report2);
|
|
36455
37166
|
} catch (e) {
|
|
36456
37167
|
return err(e instanceof Error ? e : new Error(String(e)));
|
|
36457
37168
|
}
|
|
@@ -36493,7 +37204,7 @@ var init_model_comparison = __esm(() => {
|
|
|
36493
37204
|
|
|
36494
37205
|
// src/core/evaluation/cost-quality-matrix.ts
|
|
36495
37206
|
import { writeFile as writeFile34 } from "node:fs/promises";
|
|
36496
|
-
import { resolve as
|
|
37207
|
+
import { resolve as resolve58 } from "node:path";
|
|
36497
37208
|
async function buildCostQualityMatrix(projectRoot, outcomes) {
|
|
36498
37209
|
const agg = aggregateOutcomes(outcomes);
|
|
36499
37210
|
const rows = Object.entries(agg.byModel).map(([model, entry]) => {
|
|
@@ -36513,7 +37224,7 @@ async function buildCostQualityMatrix(projectRoot, outcomes) {
|
|
|
36513
37224
|
rows
|
|
36514
37225
|
};
|
|
36515
37226
|
const dir = await ensureEvaluationDir(projectRoot);
|
|
36516
|
-
await writeFile34(
|
|
37227
|
+
await writeFile34(resolve58(dir, "matrix.yml"), $stringify(matrix), "utf-8");
|
|
36517
37228
|
return matrix;
|
|
36518
37229
|
}
|
|
36519
37230
|
function formatMatrixMarkdown(matrix) {
|
|
@@ -36537,8 +37248,8 @@ var init_cost_quality_matrix = __esm(() => {
|
|
|
36537
37248
|
});
|
|
36538
37249
|
|
|
36539
37250
|
// src/core/evaluation/ablation-report.ts
|
|
36540
|
-
import { mkdir as
|
|
36541
|
-
import { resolve as
|
|
37251
|
+
import { mkdir as mkdir35, writeFile as writeFile35 } from "node:fs/promises";
|
|
37252
|
+
import { resolve as resolve59 } from "node:path";
|
|
36542
37253
|
function isPass(o) {
|
|
36543
37254
|
return o.verdict === "PASS" || o.status === "pass";
|
|
36544
37255
|
}
|
|
@@ -36673,26 +37384,26 @@ async function buildAblationReport(projectRoot, outcomes, experimentId) {
|
|
|
36673
37384
|
rows
|
|
36674
37385
|
};
|
|
36675
37386
|
}
|
|
36676
|
-
function formatAblationMarkdown(
|
|
37387
|
+
function formatAblationMarkdown(report2) {
|
|
36677
37388
|
const lines = [
|
|
36678
37389
|
"# Harness Ablation Report",
|
|
36679
37390
|
"",
|
|
36680
|
-
`Generated: ${
|
|
36681
|
-
|
|
36682
|
-
`Outcomes: ${
|
|
37391
|
+
`Generated: ${report2.generatedAt}`,
|
|
37392
|
+
report2.experimentId ? `Experiment: ${report2.experimentId}` : "Experiment: (all tagged outcomes)",
|
|
37393
|
+
`Outcomes: ${report2.outcomeCount}`,
|
|
36683
37394
|
"",
|
|
36684
37395
|
"| Component | Verdict | Δ score | Δ pass | Δ cost | Δ duration | Baseline n | Treatment n |",
|
|
36685
37396
|
"|-----------|---------|---------|--------|--------|------------|------------|-------------|"
|
|
36686
37397
|
];
|
|
36687
|
-
for (const row of
|
|
37398
|
+
for (const row of report2.rows) {
|
|
36688
37399
|
lines.push(`| ${row.component} | ${row.verdict} | ${row.deltaScore.toFixed(2)} | ${(row.deltaPassRate * 100).toFixed(0)}pp | ${row.deltaCost?.toFixed(4) ?? "—"} | ${row.deltaDurationMs ?? "—"} | ${row.baseline.count} | ${row.treatment.count} |`);
|
|
36689
37400
|
}
|
|
36690
|
-
if (
|
|
37401
|
+
if (report2.rows.length === 0) {
|
|
36691
37402
|
lines.push("| — | — | — | — | — | — | — | — |");
|
|
36692
37403
|
lines.push("", "No paired baseline/treatment outcomes yet.");
|
|
36693
37404
|
} else {
|
|
36694
37405
|
lines.push("", "## Criterion deltas", "");
|
|
36695
|
-
for (const row of
|
|
37406
|
+
for (const row of report2.rows) {
|
|
36696
37407
|
const keys = Object.keys(row.deltaCriteria);
|
|
36697
37408
|
if (keys.length === 0)
|
|
36698
37409
|
continue;
|
|
@@ -36712,9 +37423,9 @@ function formatAblationMarkdown(report) {
|
|
|
36712
37423
|
`);
|
|
36713
37424
|
}
|
|
36714
37425
|
async function persistAblationReport(projectRoot, markdown) {
|
|
36715
|
-
const dir =
|
|
36716
|
-
await
|
|
36717
|
-
const path =
|
|
37426
|
+
const dir = resolve59(projectRoot, EVAL_DIR2);
|
|
37427
|
+
await mkdir35(dir, { recursive: true });
|
|
37428
|
+
const path = resolve59(dir, "ablation-last.md");
|
|
36718
37429
|
await writeFile35(path, markdown, "utf-8");
|
|
36719
37430
|
return path;
|
|
36720
37431
|
}
|
|
@@ -36725,12 +37436,13 @@ var init_ablation_report = __esm(() => {
|
|
|
36725
37436
|
});
|
|
36726
37437
|
|
|
36727
37438
|
// src/core/telemetry/openrouter-spend-lock.ts
|
|
36728
|
-
function isOpenRouterFreeModel(modelId) {
|
|
36729
|
-
return modelId.trim().endsWith(":free");
|
|
36730
|
-
}
|
|
36731
37439
|
function isFiniteNumber(value) {
|
|
36732
37440
|
return typeof value === "number" && Number.isFinite(value);
|
|
36733
37441
|
}
|
|
37442
|
+
function resolveMaxSpendUsd(input) {
|
|
37443
|
+
const raw = input.maxSpendUsd ?? input.maxLimitUsd ?? DEFAULT_OPENROUTER_SPEND_CAP_USD;
|
|
37444
|
+
return raw;
|
|
37445
|
+
}
|
|
36734
37446
|
function keySnapshotIsComplete(key) {
|
|
36735
37447
|
const limitOk = key.limit === null || isFiniteNumber(key.limit);
|
|
36736
37448
|
const remOk = key.limitRemaining === null || isFiniteNumber(key.limitRemaining);
|
|
@@ -36741,13 +37453,6 @@ function keySnapshotIsComplete(key) {
|
|
|
36741
37453
|
const creditsOk = key.credits === undefined || key.credits === null || isFiniteNumber(key.credits);
|
|
36742
37454
|
return limitOk && remOk && usageOk && freeOk && labelOk && balanceOk && creditsOk;
|
|
36743
37455
|
}
|
|
36744
|
-
function keyLimitWithinCap(key, maxLimitUsd = DEFAULT_OPENROUTER_LIMIT_CAP_USD) {
|
|
36745
|
-
if (!isFiniteNumber(maxLimitUsd) || maxLimitUsd < 0)
|
|
36746
|
-
return false;
|
|
36747
|
-
if (!isFiniteNumber(key.limit))
|
|
36748
|
-
return false;
|
|
36749
|
-
return key.limit <= maxLimitUsd;
|
|
36750
|
-
}
|
|
36751
37456
|
function readOpenRouterApiKeyFromEnv(env = process.env) {
|
|
36752
37457
|
const key = env.OPENROUTER_API_KEY?.trim();
|
|
36753
37458
|
return key && key.length > 0 ? key : null;
|
|
@@ -36844,15 +37549,27 @@ async function resolveKeySnapshot(input) {
|
|
|
36844
37549
|
return key;
|
|
36845
37550
|
}
|
|
36846
37551
|
async function assertOpenRouterZeroSpend(input) {
|
|
36847
|
-
const
|
|
36848
|
-
if (!
|
|
37552
|
+
const maxSpendUsd = resolveMaxSpendUsd(input);
|
|
37553
|
+
if (!isFiniteNumber(maxSpendUsd) || maxSpendUsd < 0) {
|
|
37554
|
+
return {
|
|
37555
|
+
ok: false,
|
|
37556
|
+
reason: `OpenRouter spend lock: maxSpendUsd must be a finite number ≥ 0 (got ${maxSpendUsd})`,
|
|
37557
|
+
checkedModel: true,
|
|
37558
|
+
checkedKey: false,
|
|
37559
|
+
key: null,
|
|
37560
|
+
usageBefore: null,
|
|
37561
|
+
maxSpendUsd
|
|
37562
|
+
};
|
|
37563
|
+
}
|
|
37564
|
+
if (!input.modelId || !input.modelId.trim()) {
|
|
36849
37565
|
return {
|
|
36850
37566
|
ok: false,
|
|
36851
|
-
reason:
|
|
37567
|
+
reason: "OpenRouter spend lock: modelId is required",
|
|
36852
37568
|
checkedModel: true,
|
|
36853
37569
|
checkedKey: false,
|
|
36854
37570
|
key: null,
|
|
36855
|
-
usageBefore: null
|
|
37571
|
+
usageBefore: null,
|
|
37572
|
+
maxSpendUsd
|
|
36856
37573
|
};
|
|
36857
37574
|
}
|
|
36858
37575
|
if (input.skipKeyCheck) {
|
|
@@ -36862,7 +37579,8 @@ async function assertOpenRouterZeroSpend(input) {
|
|
|
36862
37579
|
checkedModel: true,
|
|
36863
37580
|
checkedKey: false,
|
|
36864
37581
|
key: null,
|
|
36865
|
-
usageBefore: null
|
|
37582
|
+
usageBefore: null,
|
|
37583
|
+
maxSpendUsd
|
|
36866
37584
|
};
|
|
36867
37585
|
}
|
|
36868
37586
|
const key = await resolveKeySnapshot(input);
|
|
@@ -36873,47 +37591,30 @@ async function assertOpenRouterZeroSpend(input) {
|
|
|
36873
37591
|
checkedModel: true,
|
|
36874
37592
|
checkedKey: false,
|
|
36875
37593
|
key: null,
|
|
36876
|
-
usageBefore: null
|
|
37594
|
+
usageBefore: null,
|
|
37595
|
+
maxSpendUsd
|
|
36877
37596
|
};
|
|
36878
37597
|
}
|
|
36879
37598
|
if (!keySnapshotIsComplete(key)) {
|
|
36880
37599
|
return {
|
|
36881
37600
|
ok: false,
|
|
36882
|
-
reason: "OpenRouter
|
|
36883
|
-
checkedModel: true,
|
|
36884
|
-
checkedKey: true,
|
|
36885
|
-
key,
|
|
36886
|
-
usageBefore: null
|
|
36887
|
-
};
|
|
36888
|
-
}
|
|
36889
|
-
if (!isFiniteNumber(key.limit)) {
|
|
36890
|
-
return {
|
|
36891
|
-
ok: false,
|
|
36892
|
-
reason: "OpenRouter zero-spend lock: key limit is null or unlimited (fail-closed; expected finite limit ≤ cap)",
|
|
36893
|
-
checkedModel: true,
|
|
36894
|
-
checkedKey: true,
|
|
36895
|
-
key,
|
|
36896
|
-
usageBefore: null
|
|
36897
|
-
};
|
|
36898
|
-
}
|
|
36899
|
-
if (!keyLimitWithinCap(key, maxLimitUsd)) {
|
|
36900
|
-
return {
|
|
36901
|
-
ok: false,
|
|
36902
|
-
reason: `OpenRouter zero-spend lock: key limit ${key.limit} exceeds cap ${maxLimitUsd} USD`,
|
|
37601
|
+
reason: "OpenRouter spend lock: /api/v1/key response is incomplete or unparseable (fail-closed)",
|
|
36903
37602
|
checkedModel: true,
|
|
36904
37603
|
checkedKey: true,
|
|
36905
37604
|
key,
|
|
36906
|
-
usageBefore: null
|
|
37605
|
+
usageBefore: null,
|
|
37606
|
+
maxSpendUsd
|
|
36907
37607
|
};
|
|
36908
37608
|
}
|
|
36909
37609
|
if (!isFiniteNumber(key.usage)) {
|
|
36910
37610
|
return {
|
|
36911
37611
|
ok: false,
|
|
36912
|
-
reason: "OpenRouter
|
|
37612
|
+
reason: "OpenRouter spend lock: key usage is missing or not a finite number (cannot establish spend baseline)",
|
|
36913
37613
|
checkedModel: true,
|
|
36914
37614
|
checkedKey: true,
|
|
36915
37615
|
key,
|
|
36916
|
-
usageBefore: null
|
|
37616
|
+
usageBefore: null,
|
|
37617
|
+
maxSpendUsd
|
|
36917
37618
|
};
|
|
36918
37619
|
}
|
|
36919
37620
|
return {
|
|
@@ -36922,19 +37623,37 @@ async function assertOpenRouterZeroSpend(input) {
|
|
|
36922
37623
|
checkedModel: true,
|
|
36923
37624
|
checkedKey: true,
|
|
36924
37625
|
key,
|
|
36925
|
-
usageBefore: key.usage
|
|
37626
|
+
usageBefore: key.usage,
|
|
37627
|
+
maxSpendUsd
|
|
36926
37628
|
};
|
|
36927
37629
|
}
|
|
36928
|
-
async function
|
|
37630
|
+
async function assertOpenRouterUsageWithinCap(input) {
|
|
37631
|
+
const maxSpendUsd = input.maxSpendUsd ?? DEFAULT_OPENROUTER_SPEND_CAP_USD;
|
|
37632
|
+
const approachUsd = input.approachUsd ?? maxSpendUsd * DEFAULT_OPENROUTER_SPEND_APPROACH_FRACTION;
|
|
36929
37633
|
if (!isFiniteNumber(input.usageBefore)) {
|
|
36930
37634
|
return {
|
|
36931
37635
|
ok: false,
|
|
36932
|
-
reason: "OpenRouter
|
|
37636
|
+
reason: "OpenRouter spend lock: usageBefore is not a finite number",
|
|
37637
|
+
usageBefore: input.usageBefore,
|
|
37638
|
+
usageAfter: null,
|
|
37639
|
+
deltaUsd: null,
|
|
37640
|
+
runValid: false,
|
|
37641
|
+
keyAfter: null,
|
|
37642
|
+
maxSpendUsd,
|
|
37643
|
+
approachUsd
|
|
37644
|
+
};
|
|
37645
|
+
}
|
|
37646
|
+
if (!isFiniteNumber(maxSpendUsd) || maxSpendUsd < 0) {
|
|
37647
|
+
return {
|
|
37648
|
+
ok: false,
|
|
37649
|
+
reason: `OpenRouter spend lock: maxSpendUsd must be a finite number ≥ 0`,
|
|
36933
37650
|
usageBefore: input.usageBefore,
|
|
36934
37651
|
usageAfter: null,
|
|
36935
37652
|
deltaUsd: null,
|
|
36936
37653
|
runValid: false,
|
|
36937
|
-
keyAfter: null
|
|
37654
|
+
keyAfter: null,
|
|
37655
|
+
maxSpendUsd,
|
|
37656
|
+
approachUsd
|
|
36938
37657
|
};
|
|
36939
37658
|
}
|
|
36940
37659
|
const keyAfter = await resolveKeySnapshot({
|
|
@@ -36944,35 +37663,54 @@ async function assertOpenRouterUsageUnchanged(input) {
|
|
|
36944
37663
|
if (!keyAfter) {
|
|
36945
37664
|
return {
|
|
36946
37665
|
ok: false,
|
|
36947
|
-
reason: "OpenRouter
|
|
37666
|
+
reason: "OpenRouter spend lock: could not re-read /api/v1/key after run (fail-closed)",
|
|
36948
37667
|
usageBefore: input.usageBefore,
|
|
36949
37668
|
usageAfter: null,
|
|
36950
37669
|
deltaUsd: null,
|
|
36951
37670
|
runValid: false,
|
|
36952
|
-
keyAfter: null
|
|
37671
|
+
keyAfter: null,
|
|
37672
|
+
maxSpendUsd,
|
|
37673
|
+
approachUsd
|
|
36953
37674
|
};
|
|
36954
37675
|
}
|
|
36955
37676
|
if (!keySnapshotIsComplete(keyAfter) || !isFiniteNumber(keyAfter.usage)) {
|
|
36956
37677
|
return {
|
|
36957
37678
|
ok: false,
|
|
36958
|
-
reason: "OpenRouter
|
|
37679
|
+
reason: "OpenRouter spend lock: post-run /api/v1/key usage is incomplete or unparseable (fail-closed)",
|
|
36959
37680
|
usageBefore: input.usageBefore,
|
|
36960
37681
|
usageAfter: null,
|
|
36961
37682
|
deltaUsd: null,
|
|
36962
37683
|
runValid: false,
|
|
36963
|
-
keyAfter
|
|
37684
|
+
keyAfter,
|
|
37685
|
+
maxSpendUsd,
|
|
37686
|
+
approachUsd
|
|
36964
37687
|
};
|
|
36965
37688
|
}
|
|
36966
37689
|
const deltaUsd = keyAfter.usage - input.usageBefore;
|
|
36967
|
-
if (deltaUsd >
|
|
37690
|
+
if (deltaUsd > maxSpendUsd) {
|
|
37691
|
+
return {
|
|
37692
|
+
ok: false,
|
|
37693
|
+
reason: `OpenRouter spend lock: usage rose by ${deltaUsd} USD (cap ${maxSpendUsd} USD); run is invalid`,
|
|
37694
|
+
usageBefore: input.usageBefore,
|
|
37695
|
+
usageAfter: keyAfter.usage,
|
|
37696
|
+
deltaUsd,
|
|
37697
|
+
runValid: false,
|
|
37698
|
+
keyAfter,
|
|
37699
|
+
maxSpendUsd,
|
|
37700
|
+
approachUsd
|
|
37701
|
+
};
|
|
37702
|
+
}
|
|
37703
|
+
if (deltaUsd >= approachUsd) {
|
|
36968
37704
|
return {
|
|
36969
37705
|
ok: false,
|
|
36970
|
-
reason: `OpenRouter
|
|
37706
|
+
reason: `OpenRouter spend lock: usage Δ ${deltaUsd} USD approaches cap ${maxSpendUsd} USD (threshold ${approachUsd}); aborting`,
|
|
36971
37707
|
usageBefore: input.usageBefore,
|
|
36972
37708
|
usageAfter: keyAfter.usage,
|
|
36973
37709
|
deltaUsd,
|
|
36974
37710
|
runValid: false,
|
|
36975
|
-
keyAfter
|
|
37711
|
+
keyAfter,
|
|
37712
|
+
maxSpendUsd,
|
|
37713
|
+
approachUsd
|
|
36976
37714
|
};
|
|
36977
37715
|
}
|
|
36978
37716
|
return {
|
|
@@ -36982,10 +37720,12 @@ async function assertOpenRouterUsageUnchanged(input) {
|
|
|
36982
37720
|
usageAfter: keyAfter.usage,
|
|
36983
37721
|
deltaUsd,
|
|
36984
37722
|
runValid: true,
|
|
36985
|
-
keyAfter
|
|
37723
|
+
keyAfter,
|
|
37724
|
+
maxSpendUsd,
|
|
37725
|
+
approachUsd
|
|
36986
37726
|
};
|
|
36987
37727
|
}
|
|
36988
|
-
var
|
|
37728
|
+
var DEFAULT_OPENROUTER_SPEND_CAP_USD = 0.49, DEFAULT_OPENROUTER_SPEND_APPROACH_FRACTION = 0.9, OPENROUTER_KEY_URL = "https://openrouter.ai/api/v1/key", REQUIRED_KEY_FIELDS;
|
|
36989
37729
|
var init_openrouter_spend_lock = __esm(() => {
|
|
36990
37730
|
REQUIRED_KEY_FIELDS = [
|
|
36991
37731
|
"limit",
|
|
@@ -37121,7 +37861,7 @@ function taskNonInferiority(baselineK, baselineN, treatmentK, treatmentN) {
|
|
|
37121
37861
|
}
|
|
37122
37862
|
|
|
37123
37863
|
// src/core/evaluation/bench/report.ts
|
|
37124
|
-
import { createHash as
|
|
37864
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
37125
37865
|
function valuesFor(cells, variant, taskId, metric) {
|
|
37126
37866
|
return cells.filter((c) => c.variant === variant && (taskId === null || c.taskId === taskId)).map((c) => c[metric]).filter((v) => typeof v === "number" && Number.isFinite(v));
|
|
37127
37867
|
}
|
|
@@ -37217,7 +37957,7 @@ function canonicalBenchHash(input) {
|
|
|
37217
37957
|
fingerprints: input.fingerprints,
|
|
37218
37958
|
cells: [...input.cells].sort((a, b) => `${a.variant}:${a.taskId}:${a.repetition}`.localeCompare(`${b.variant}:${b.taskId}:${b.repetition}`))
|
|
37219
37959
|
});
|
|
37220
|
-
return
|
|
37960
|
+
return createHash16("sha256").update(payload).digest("hex");
|
|
37221
37961
|
}
|
|
37222
37962
|
function buildBenchReport(input) {
|
|
37223
37963
|
const metric = input.metric ?? "tokensTotal";
|
|
@@ -37277,44 +38017,44 @@ function buildBenchReport(input) {
|
|
|
37277
38017
|
contentHash
|
|
37278
38018
|
};
|
|
37279
38019
|
}
|
|
37280
|
-
function formatBenchReportMarkdown(
|
|
38020
|
+
function formatBenchReportMarkdown(report2) {
|
|
37281
38021
|
const lines = [
|
|
37282
38022
|
"# Bench Report",
|
|
37283
38023
|
"",
|
|
37284
|
-
`Generated: ${
|
|
37285
|
-
`Suite: \`${
|
|
37286
|
-
`Claim: ${
|
|
37287
|
-
`Verdict: **${
|
|
37288
|
-
`Hash: \`${
|
|
38024
|
+
`Generated: ${report2.generatedAt} (${report2.timezone})`,
|
|
38025
|
+
`Suite: \`${report2.suiteId}\` · N=${report2.n} · cheap=${report2.cheap}`,
|
|
38026
|
+
`Claim: ${report2.claim}`,
|
|
38027
|
+
`Verdict: **${report2.verdict}**`,
|
|
38028
|
+
`Hash: \`${report2.contentHash}\``,
|
|
37289
38029
|
"",
|
|
37290
38030
|
"## Reasons",
|
|
37291
38031
|
"",
|
|
37292
|
-
...
|
|
38032
|
+
...report2.verdictReasons.map((r) => `- ${r}`),
|
|
37293
38033
|
"",
|
|
37294
38034
|
"## Fingerprints",
|
|
37295
38035
|
"",
|
|
37296
|
-
`- harness: \`${
|
|
37297
|
-
`- prompt: \`${
|
|
37298
|
-
`- host: \`${
|
|
37299
|
-
`- model: \`${
|
|
37300
|
-
`- pricing: \`${
|
|
38036
|
+
`- harness: \`${report2.fingerprints.harness ?? "n/a"}\``,
|
|
38037
|
+
`- prompt: \`${report2.fingerprints.prompt ?? "n/a"}\``,
|
|
38038
|
+
`- host: \`${report2.fingerprints.host ?? "n/a"}\``,
|
|
38039
|
+
`- model: \`${report2.fingerprints.model ?? "n/a"}\``,
|
|
38040
|
+
`- pricing: \`${report2.fingerprints.pricingVersion ?? "n/a"}\``,
|
|
37301
38041
|
"",
|
|
37302
|
-
`Total cost (sum of cells): ${
|
|
38042
|
+
`Total cost (sum of cells): ${report2.totalCostUsd ?? "n/a"}`,
|
|
37303
38043
|
"",
|
|
37304
38044
|
"## Per-task tokens (median [IQR])",
|
|
37305
38045
|
"",
|
|
37306
38046
|
"| Task | Baseline | Treatment | Δ median | IC 95% | Success B→T | NI |",
|
|
37307
38047
|
"| --- | --- | --- | ---: | --- | --- | --- |"
|
|
37308
38048
|
];
|
|
37309
|
-
for (const t of
|
|
38049
|
+
for (const t of report2.tasks) {
|
|
37310
38050
|
const b = t.baseline;
|
|
37311
38051
|
const tr = t.treatment;
|
|
37312
38052
|
const fmt = (s) => s.median === null ? "—" : `${s.median.toFixed(1)} [${s.q1?.toFixed(1) ?? "—"}, ${s.q3?.toFixed(1) ?? "—"}]`;
|
|
37313
38053
|
const ci = t.bootstrap.ciLow === null ? "—" : `[${t.bootstrap.ciLow.toFixed(1)}, ${t.bootstrap.ciHigh?.toFixed(1)}]`;
|
|
37314
38054
|
lines.push(`| ${t.taskId} | ${fmt(b)} | ${fmt(tr)} | ${t.deltaMedian?.toFixed(1) ?? "—"} | ${ci} | ${t.baselineSuccess.k}/${t.baselineSuccess.n}→${t.treatmentSuccess.k}/${t.treatmentSuccess.n} | ${t.nonInferiorityOk ? "ok" : "FAIL"} |`);
|
|
37315
38055
|
}
|
|
37316
|
-
const o =
|
|
37317
|
-
lines.push(`| TOTAL | ${o.baseline.median?.toFixed(1) ?? "—"} | ${o.treatment.median?.toFixed(1) ?? "—"} | ${o.deltaMedian?.toFixed(1) ?? "—"} | [${o.bootstrap.ciLow?.toFixed(1) ?? "—"}, ${o.bootstrap.ciHigh?.toFixed(1) ?? "—"}] | ${
|
|
38056
|
+
const o = report2.overall.tokens;
|
|
38057
|
+
lines.push(`| TOTAL | ${o.baseline.median?.toFixed(1) ?? "—"} | ${o.treatment.median?.toFixed(1) ?? "—"} | ${o.deltaMedian?.toFixed(1) ?? "—"} | [${o.bootstrap.ciLow?.toFixed(1) ?? "—"}, ${o.bootstrap.ciHigh?.toFixed(1) ?? "—"}] | ${report2.overall.baselineSuccess.k}/${report2.overall.baselineSuccess.n}→${report2.overall.treatmentSuccess.k}/${report2.overall.treatmentSuccess.n} | — |`);
|
|
37318
38058
|
lines.push("");
|
|
37319
38059
|
return lines.join(`
|
|
37320
38060
|
`);
|
|
@@ -37521,11 +38261,67 @@ var init_claude_json = __esm(() => {
|
|
|
37521
38261
|
init_schema();
|
|
37522
38262
|
});
|
|
37523
38263
|
|
|
38264
|
+
// src/core/evaluation/bench/openrouter-request-proxy.ts
|
|
38265
|
+
function isProxyLocalToken(token) {
|
|
38266
|
+
return typeof token === "string" && token.startsWith(PROXY_LOCAL_TOKEN_PREFIX);
|
|
38267
|
+
}
|
|
38268
|
+
function buildClaudeChildEnv(input) {
|
|
38269
|
+
if (!isProxyLocalToken(input.localAuthToken)) {
|
|
38270
|
+
throw new RequestCounterError("localAuthToken must be a minted cc-proxy-local-* token");
|
|
38271
|
+
}
|
|
38272
|
+
const parent = input.parentEnv ?? process.env;
|
|
38273
|
+
const env = {
|
|
38274
|
+
PATH: parent.PATH,
|
|
38275
|
+
HOME: parent.HOME,
|
|
38276
|
+
USER: parent.USER,
|
|
38277
|
+
LANG: parent.LANG,
|
|
38278
|
+
TMPDIR: parent.TMPDIR,
|
|
38279
|
+
XDG_STATE_HOME: parent.XDG_STATE_HOME,
|
|
38280
|
+
CI: "true",
|
|
38281
|
+
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
|
|
38282
|
+
CLAUDE_CODE_MAX_RETRIES: "0",
|
|
38283
|
+
ANTHROPIC_MAX_RETRIES: "0",
|
|
38284
|
+
CLAUDE_CODE_VERSION: parent.CLAUDE_CODE_VERSION,
|
|
38285
|
+
ANTHROPIC_API_KEY: "",
|
|
38286
|
+
ANTHROPIC_BASE_URL: input.proxyBaseUrl,
|
|
38287
|
+
ANTHROPIC_AUTH_TOKEN: input.localAuthToken,
|
|
38288
|
+
ANTHROPIC_MODEL: input.modelId,
|
|
38289
|
+
ANTHROPIC_SMALL_FAST_MODEL: input.modelId,
|
|
38290
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: input.modelId,
|
|
38291
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: input.modelId,
|
|
38292
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: input.modelId,
|
|
38293
|
+
CLAUDE_CODE_SUBAGENT_MODEL: input.modelId
|
|
38294
|
+
};
|
|
38295
|
+
delete env.OPENROUTER_API_KEY;
|
|
38296
|
+
return env;
|
|
38297
|
+
}
|
|
38298
|
+
var PROXY_LOCAL_TOKEN_PREFIX = "cc-proxy-local-", RequestCounterError, HOP_BY_HOP;
|
|
38299
|
+
var init_openrouter_request_proxy = __esm(() => {
|
|
38300
|
+
RequestCounterError = class RequestCounterError extends Error {
|
|
38301
|
+
constructor(message) {
|
|
38302
|
+
super(message);
|
|
38303
|
+
this.name = "RequestCounterError";
|
|
38304
|
+
}
|
|
38305
|
+
};
|
|
38306
|
+
HOP_BY_HOP = new Set([
|
|
38307
|
+
"connection",
|
|
38308
|
+
"keep-alive",
|
|
38309
|
+
"proxy-authenticate",
|
|
38310
|
+
"proxy-authorization",
|
|
38311
|
+
"te",
|
|
38312
|
+
"trailers",
|
|
38313
|
+
"transfer-encoding",
|
|
38314
|
+
"upgrade",
|
|
38315
|
+
"proxy-connection"
|
|
38316
|
+
]);
|
|
38317
|
+
});
|
|
38318
|
+
|
|
37524
38319
|
// src/core/evaluation/bench/host-claude.ts
|
|
37525
38320
|
import { spawn as spawn3 } from "node:child_process";
|
|
37526
|
-
import {
|
|
37527
|
-
import {
|
|
37528
|
-
import {
|
|
38321
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
38322
|
+
import { cp as cp2, mkdtemp as mkdtemp3, rm as rm6, writeFile as writeFile36, readFile as readFile61, access as access9, realpath as realpath2 } from "node:fs/promises";
|
|
38323
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
38324
|
+
import { join as join41 } from "node:path";
|
|
37529
38325
|
function budgetExhausted(budget) {
|
|
37530
38326
|
if (budget.requests >= budget.maxRequests) {
|
|
37531
38327
|
return `request budget exhausted: ${budget.requests}/${budget.maxRequests}`;
|
|
@@ -37577,19 +38373,30 @@ async function rateLimit(minIntervalMs) {
|
|
|
37577
38373
|
lastCallAt = Date.now();
|
|
37578
38374
|
}
|
|
37579
38375
|
function sanitizeStderr(stderr, maxLen = 500) {
|
|
37580
|
-
let s = stderr.replace(/sk-or-v1-[A-Za-z0-9_-]+/g, "[REDACTED_OR_KEY]").replace(/sk-ant-[A-Za-z0-9_-]+/g, "[REDACTED_ANT_KEY]").replace(
|
|
38376
|
+
let s = stderr.replace(/OPENROUTER_API_KEY=\S+/g, "OPENROUTER_API_KEY=[REDACTED]").replace(/DEEPSEEK_API_KEY=\S+/g, "DEEPSEEK_API_KEY=[REDACTED]").replace(/ANTHROPIC_AUTH_TOKEN=\S+/g, "ANTHROPIC_AUTH_TOKEN=[REDACTED]").replace(/ANTHROPIC_API_KEY=\S+/g, "ANTHROPIC_API_KEY=[REDACTED]").replace(/sk-or-v1-[A-Za-z0-9_-]+/g, "[REDACTED_OR_KEY]").replace(/sk-ant-[A-Za-z0-9_-]+/g, "[REDACTED_ANT_KEY]").replace(/\bsk-[A-Za-z0-9_-]{8,}\b/g, "[REDACTED_SK_TOKEN]").replace(/cc-proxy-local-[A-Za-z0-9_-]+/g, "[REDACTED_PROXY_LOCAL]").replace(/Bearer\s+[A-Za-z0-9._-]+/gi, "Bearer [REDACTED]").replace(/session[_-]?id["\s:=]+[A-Za-z0-9_-]+/gi, "session_id=[REDACTED]").replace(/\/(?:home|Users|tmp|var|opt|workspace|runner)\/[^\s"'\\]+/gi, "[REDACTED_PATH]").replace(/[A-Za-z]:\\[^\s"']+/g, "[REDACTED_PATH]").replace(/~\/[^\s"']+/g, "[REDACTED_PATH]");
|
|
37581
38377
|
if (s.length > maxLen)
|
|
37582
38378
|
s = `${s.slice(0, maxLen)}…`;
|
|
37583
38379
|
return s;
|
|
37584
38380
|
}
|
|
38381
|
+
function extractSanitizedErrorResult(payload, isError, maxLen = 500) {
|
|
38382
|
+
if (isError !== true || !payload || typeof payload !== "object")
|
|
38383
|
+
return null;
|
|
38384
|
+
const rec = payload;
|
|
38385
|
+
const raw = rec.result;
|
|
38386
|
+
if (typeof raw !== "string" || raw.trim().length === 0)
|
|
38387
|
+
return null;
|
|
38388
|
+
return sanitizeStderr(raw, maxLen);
|
|
38389
|
+
}
|
|
37585
38390
|
function emptyDiagnostics(attempt) {
|
|
37586
38391
|
return {
|
|
37587
38392
|
exitCode: null,
|
|
37588
38393
|
stderrTruncated: null,
|
|
38394
|
+
resultTruncated: null,
|
|
37589
38395
|
subtype: null,
|
|
37590
38396
|
isError: null,
|
|
37591
38397
|
timedOut: false,
|
|
37592
38398
|
http429: false,
|
|
38399
|
+
requestBudgetExhausted: false,
|
|
37593
38400
|
attempt
|
|
37594
38401
|
};
|
|
37595
38402
|
}
|
|
@@ -37598,7 +38405,8 @@ function extractMeta(payload) {
|
|
|
37598
38405
|
return { subtype: null, isError: null };
|
|
37599
38406
|
}
|
|
37600
38407
|
const rec = payload;
|
|
37601
|
-
const
|
|
38408
|
+
const nested = rec.result && typeof rec.result === "object" && !Array.isArray(rec.result) ? rec.result : null;
|
|
38409
|
+
const subtype = typeof rec.subtype === "string" ? rec.subtype : typeof nested?.subtype === "string" ? nested.subtype : null;
|
|
37602
38410
|
const isError = typeof rec.is_error === "boolean" ? rec.is_error : typeof rec.isError === "boolean" ? rec.isError : null;
|
|
37603
38411
|
return { subtype, isError };
|
|
37604
38412
|
}
|
|
@@ -37607,8 +38415,18 @@ function looksLike429(stderr, stdout) {
|
|
|
37607
38415
|
${stdout}`.toLowerCase();
|
|
37608
38416
|
return blob.includes("429") || blob.includes("rate limit") || blob.includes("rate_limit") || blob.includes("too many requests");
|
|
37609
38417
|
}
|
|
38418
|
+
function looksLikeRequestBudgetExhausted(stderr, stdout) {
|
|
38419
|
+
const blob = `${stderr}
|
|
38420
|
+
${stdout}`;
|
|
38421
|
+
return blob.includes("request_budget_exhausted") || blob.includes("cc_proxy_budget") || /request budget exhausted/i.test(blob);
|
|
38422
|
+
}
|
|
38423
|
+
function isRequestBudgetAbortReason(reason) {
|
|
38424
|
+
if (!reason)
|
|
38425
|
+
return false;
|
|
38426
|
+
return reason.includes("request_budget_exhausted") || reason.includes("cc_proxy_budget") || /request budget exhausted/i.test(reason) || /token budget exhausted/i.test(reason);
|
|
38427
|
+
}
|
|
37610
38428
|
function runShell(command, cwd, timeoutMs, env) {
|
|
37611
|
-
return new Promise((
|
|
38429
|
+
return new Promise((resolve60) => {
|
|
37612
38430
|
let timedOut = false;
|
|
37613
38431
|
const child = spawn3("bash", ["-lc", command], {
|
|
37614
38432
|
cwd,
|
|
@@ -37629,35 +38447,102 @@ function runShell(command, cwd, timeoutMs, env) {
|
|
|
37629
38447
|
});
|
|
37630
38448
|
child.on("close", (code) => {
|
|
37631
38449
|
clearTimeout(timer);
|
|
37632
|
-
|
|
38450
|
+
resolve60({ code: code ?? 1, stdout, stderr, timedOut });
|
|
37633
38451
|
});
|
|
37634
38452
|
child.on("error", (err3) => {
|
|
37635
38453
|
clearTimeout(timer);
|
|
37636
|
-
|
|
38454
|
+
resolve60({ code: 1, stdout, stderr: String(err3), timedOut });
|
|
37637
38455
|
});
|
|
37638
38456
|
});
|
|
37639
38457
|
}
|
|
37640
|
-
async function
|
|
37641
|
-
const dir =
|
|
37642
|
-
|
|
37643
|
-
const
|
|
37644
|
-
|
|
37645
|
-
|
|
37646
|
-
|
|
37647
|
-
|
|
38458
|
+
async function prepareIsolatedClaudeConfig(cwd) {
|
|
38459
|
+
const dir = await mkdtemp3(join41(tmpdir3(), "cc-bench-claude-config-"));
|
|
38460
|
+
const project = { hasTrustDialogAccepted: true, hasCompletedProjectOnboarding: true };
|
|
38461
|
+
const projects = { [cwd]: project };
|
|
38462
|
+
projects[await realpath2(cwd)] = project;
|
|
38463
|
+
await writeFile36(join41(dir, ".claude.json"), JSON.stringify({ hasCompletedOnboarding: true, projects }, null, 2), "utf-8");
|
|
38464
|
+
await writeFile36(join41(dir, "settings.json"), `{}
|
|
38465
|
+
`, "utf-8");
|
|
38466
|
+
return dir;
|
|
38467
|
+
}
|
|
38468
|
+
async function isClaudeWorkspaceTrusted(cwd, configDir) {
|
|
37648
38469
|
try {
|
|
37649
|
-
await
|
|
38470
|
+
const raw = await readFile61(join41(configDir, ".claude.json"), "utf-8");
|
|
38471
|
+
const parsed = JSON.parse(raw);
|
|
38472
|
+
return parsed.projects?.[await realpath2(cwd)]?.hasTrustDialogAccepted === true;
|
|
37650
38473
|
} catch {
|
|
37651
|
-
|
|
38474
|
+
return false;
|
|
37652
38475
|
}
|
|
37653
38476
|
}
|
|
37654
|
-
function
|
|
37655
|
-
|
|
37656
|
-
|
|
38477
|
+
async function inspectHarnessPresence(cwd, configDir) {
|
|
38478
|
+
const files = [];
|
|
38479
|
+
const missing = [];
|
|
38480
|
+
const chunks = [];
|
|
38481
|
+
for (const rel of HARNESS_MARKER_PATHS) {
|
|
38482
|
+
const full = join41(cwd, rel);
|
|
38483
|
+
try {
|
|
38484
|
+
const body = await readFile61(full, "utf-8");
|
|
38485
|
+
files.push(rel);
|
|
38486
|
+
chunks.push(`${rel}
|
|
38487
|
+
${body}`);
|
|
38488
|
+
} catch {
|
|
38489
|
+
missing.push(rel);
|
|
38490
|
+
}
|
|
38491
|
+
}
|
|
38492
|
+
const workspaceTrusted = await isClaudeWorkspaceTrusted(cwd, configDir);
|
|
38493
|
+
const loaded = missing.length === 0 && workspaceTrusted;
|
|
38494
|
+
const fingerprint2 = chunks.length > 0 ? createHash17("sha256").update(chunks.join(`
|
|
38495
|
+
---
|
|
38496
|
+
`)).digest("hex") : null;
|
|
38497
|
+
return { loaded, files, missing, fingerprint: fingerprint2, workspaceTrusted };
|
|
38498
|
+
}
|
|
38499
|
+
async function installHarnessPreset(cwd, configDir) {
|
|
38500
|
+
const install = await installPresetCommand({
|
|
38501
|
+
target: "claude",
|
|
38502
|
+
dryRun: false,
|
|
38503
|
+
force: true,
|
|
38504
|
+
global: false,
|
|
38505
|
+
output: "json",
|
|
38506
|
+
projectRoot: cwd,
|
|
38507
|
+
locale: "en"
|
|
38508
|
+
});
|
|
38509
|
+
if (install.code !== 0) {
|
|
38510
|
+
throw new Error(`harness install failed (code ${install.code})`);
|
|
38511
|
+
}
|
|
38512
|
+
const presence = await inspectHarnessPresence(cwd, configDir);
|
|
38513
|
+
if (!presence.loaded) {
|
|
38514
|
+
throw new Error(`harness install incomplete: missing=${presence.missing.join(",") || "none"} ` + `trusted=${presence.workspaceTrusted}`);
|
|
38515
|
+
}
|
|
38516
|
+
return presence;
|
|
38517
|
+
}
|
|
38518
|
+
function buildClaudeEnv(modelId, provider = "openrouter") {
|
|
38519
|
+
if (provider === "anthropic")
|
|
38520
|
+
return buildAnthropicEnv(modelId);
|
|
38521
|
+
const localToken = process.env.ANTHROPIC_AUTH_TOKEN;
|
|
38522
|
+
const baseUrl = process.env.ANTHROPIC_BASE_URL?.trim();
|
|
38523
|
+
if (isProxyLocalToken(localToken) && baseUrl) {
|
|
38524
|
+
return buildClaudeChildEnv({
|
|
38525
|
+
modelId,
|
|
38526
|
+
proxyBaseUrl: baseUrl,
|
|
38527
|
+
localAuthToken: localToken,
|
|
38528
|
+
parentEnv: process.env
|
|
38529
|
+
});
|
|
38530
|
+
}
|
|
38531
|
+
const env = {
|
|
38532
|
+
PATH: process.env.PATH,
|
|
38533
|
+
HOME: process.env.HOME,
|
|
38534
|
+
USER: process.env.USER,
|
|
38535
|
+
LANG: process.env.LANG,
|
|
38536
|
+
TMPDIR: process.env.TMPDIR,
|
|
38537
|
+
XDG_STATE_HOME: process.env.XDG_STATE_HOME,
|
|
37657
38538
|
CI: "true",
|
|
37658
38539
|
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
|
|
38540
|
+
CLAUDE_CODE_MAX_RETRIES: "0",
|
|
38541
|
+
ANTHROPIC_MAX_RETRIES: "0",
|
|
38542
|
+
CLAUDE_CODE_VERSION: process.env.CLAUDE_CODE_VERSION,
|
|
37659
38543
|
ANTHROPIC_API_KEY: "",
|
|
37660
|
-
ANTHROPIC_BASE_URL:
|
|
38544
|
+
ANTHROPIC_BASE_URL: baseUrl || "",
|
|
38545
|
+
ANTHROPIC_AUTH_TOKEN: localToken || "",
|
|
37661
38546
|
ANTHROPIC_MODEL: modelId,
|
|
37662
38547
|
ANTHROPIC_SMALL_FAST_MODEL: modelId,
|
|
37663
38548
|
ANTHROPIC_DEFAULT_HAIKU_MODEL: modelId,
|
|
@@ -37665,9 +38550,39 @@ function buildClaudeEnv(modelId) {
|
|
|
37665
38550
|
ANTHROPIC_DEFAULT_OPUS_MODEL: modelId,
|
|
37666
38551
|
CLAUDE_CODE_SUBAGENT_MODEL: modelId
|
|
37667
38552
|
};
|
|
38553
|
+
delete env.OPENROUTER_API_KEY;
|
|
38554
|
+
return env;
|
|
37668
38555
|
}
|
|
37669
|
-
function
|
|
37670
|
-
|
|
38556
|
+
function buildAnthropicEnv(modelId) {
|
|
38557
|
+
const oauthToken = process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim();
|
|
38558
|
+
const apiKey = process.env.ANTHROPIC_API_KEY?.trim();
|
|
38559
|
+
if (!oauthToken && !apiKey) {
|
|
38560
|
+
throw new Error("anthropic provider requires CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY");
|
|
38561
|
+
}
|
|
38562
|
+
const env = {
|
|
38563
|
+
PATH: process.env.PATH,
|
|
38564
|
+
HOME: process.env.HOME,
|
|
38565
|
+
USER: process.env.USER,
|
|
38566
|
+
LANG: process.env.LANG,
|
|
38567
|
+
TMPDIR: process.env.TMPDIR,
|
|
38568
|
+
CI: "true",
|
|
38569
|
+
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
|
|
38570
|
+
CLAUDE_CODE_VERSION: process.env.CLAUDE_CODE_VERSION,
|
|
38571
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: modelId,
|
|
38572
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: modelId,
|
|
38573
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: modelId,
|
|
38574
|
+
CLAUDE_CODE_SUBAGENT_MODEL: modelId
|
|
38575
|
+
};
|
|
38576
|
+
if (oauthToken)
|
|
38577
|
+
env.CLAUDE_CODE_OAUTH_TOKEN = oauthToken;
|
|
38578
|
+
else
|
|
38579
|
+
env.ANTHROPIC_API_KEY = apiKey;
|
|
38580
|
+
return env;
|
|
38581
|
+
}
|
|
38582
|
+
function runClaude(claudeBin, prompt, modelId, maxTurns, cwd, timeoutMs, budget, configDir, provider, maxBudgetUsd) {
|
|
38583
|
+
const env = { ...buildClaudeEnv(modelId, provider), CLAUDE_CONFIG_DIR: configDir };
|
|
38584
|
+
const budgetArgs = provider === "anthropic" && maxBudgetUsd !== undefined ? ["--max-budget-usd", String(maxBudgetUsd)] : [];
|
|
38585
|
+
return new Promise((resolve60) => {
|
|
37671
38586
|
let timedOut = false;
|
|
37672
38587
|
let budgetStop = null;
|
|
37673
38588
|
let payload = null;
|
|
@@ -37685,8 +38600,9 @@ function runClaude(claudeBin, prompt, modelId, maxTurns, cwd, timeoutMs, budget)
|
|
|
37685
38600
|
String(maxTurns),
|
|
37686
38601
|
"--dangerously-skip-permissions",
|
|
37687
38602
|
"--model",
|
|
37688
|
-
modelId
|
|
37689
|
-
|
|
38603
|
+
modelId,
|
|
38604
|
+
...budgetArgs
|
|
38605
|
+
], { cwd, env, stdio: ["ignore", "pipe", "pipe"] });
|
|
37690
38606
|
const timer = setTimeout(() => {
|
|
37691
38607
|
timedOut = true;
|
|
37692
38608
|
child.kill("SIGKILL");
|
|
@@ -37722,7 +38638,7 @@ function runClaude(claudeBin, prompt, modelId, maxTurns, cwd, timeoutMs, budget)
|
|
|
37722
38638
|
budget.requests += 1;
|
|
37723
38639
|
budgetStop = budgetExhausted(budget);
|
|
37724
38640
|
}
|
|
37725
|
-
|
|
38641
|
+
resolve60({
|
|
37726
38642
|
code,
|
|
37727
38643
|
stdout,
|
|
37728
38644
|
stderr,
|
|
@@ -37745,28 +38661,20 @@ async function runClaudeHostCell(slot, options) {
|
|
|
37745
38661
|
const claudeBin = options.claudeBin ?? "claude";
|
|
37746
38662
|
const maxAttempts = options.maxAttempts ?? 2;
|
|
37747
38663
|
const maxTurns = options.maxTurns ?? 5;
|
|
38664
|
+
const provider = options.provider ?? "openrouter";
|
|
37748
38665
|
const started = Date.now();
|
|
37749
|
-
await ensureClaudeCiConfig();
|
|
37750
38666
|
let workDir = null;
|
|
38667
|
+
let configDir = null;
|
|
37751
38668
|
let lastDiag = emptyDiagnostics(0);
|
|
37752
38669
|
let requests = 0;
|
|
38670
|
+
let spentUsd = 0;
|
|
37753
38671
|
try {
|
|
37754
|
-
workDir = await mkdtemp3(
|
|
37755
|
-
await cp2(options.fixtureDir,
|
|
37756
|
-
const cwd =
|
|
38672
|
+
workDir = await mkdtemp3(join41(tmpdir3(), "cc-bench-live-"));
|
|
38673
|
+
await cp2(options.fixtureDir, join41(workDir, "fixture"), { recursive: true });
|
|
38674
|
+
const cwd = join41(workDir, "fixture");
|
|
38675
|
+
configDir = await prepareIsolatedClaudeConfig(cwd);
|
|
37757
38676
|
if (slot.variant === "treatment") {
|
|
37758
|
-
|
|
37759
|
-
target: "claude",
|
|
37760
|
-
dryRun: false,
|
|
37761
|
-
force: true,
|
|
37762
|
-
global: false,
|
|
37763
|
-
output: "json",
|
|
37764
|
-
projectRoot: cwd,
|
|
37765
|
-
locale: "en"
|
|
37766
|
-
});
|
|
37767
|
-
if (install.code !== 0) {
|
|
37768
|
-
throw new Error(`harness install failed (code ${install.code})`);
|
|
37769
|
-
}
|
|
38677
|
+
await installHarnessPreset(cwd, configDir);
|
|
37770
38678
|
}
|
|
37771
38679
|
for (let attempt = 1;attempt <= maxAttempts; attempt++) {
|
|
37772
38680
|
const spent = budgetExhausted(options.budget);
|
|
@@ -37777,14 +38685,16 @@ async function runClaudeHostCell(slot, options) {
|
|
|
37777
38685
|
pendingReason: spent,
|
|
37778
38686
|
durationMs: Date.now() - started,
|
|
37779
38687
|
diagnostics: lastDiag,
|
|
38688
|
+
spentUsd,
|
|
37780
38689
|
totals: null
|
|
37781
38690
|
};
|
|
37782
38691
|
}
|
|
37783
38692
|
await options.beforeCall?.();
|
|
37784
38693
|
await rateLimit(minIntervalMs);
|
|
37785
|
-
const result = await runClaude(claudeBin, slot.prompt, options.modelId, maxTurns, cwd, timeoutMs, options.budget);
|
|
38694
|
+
const result = await runClaude(claudeBin, slot.prompt, options.modelId, maxTurns, cwd, timeoutMs, options.budget, configDir, provider, options.maxBudgetUsd);
|
|
37786
38695
|
requests += result.requests;
|
|
37787
38696
|
const http429 = looksLike429(result.stderr, result.stdout);
|
|
38697
|
+
const requestBudgetExhausted = Boolean(result.budgetStop && isRequestBudgetAbortReason(result.budgetStop)) || looksLikeRequestBudgetExhausted(result.stderr, result.stdout);
|
|
37788
38698
|
const payload = result.payload;
|
|
37789
38699
|
let subtype = null;
|
|
37790
38700
|
let isError = null;
|
|
@@ -37792,23 +38702,40 @@ async function runClaudeHostCell(slot, options) {
|
|
|
37792
38702
|
const meta = extractMeta(payload);
|
|
37793
38703
|
subtype = meta.subtype;
|
|
37794
38704
|
isError = meta.isError;
|
|
38705
|
+
const cost = payload.total_cost_usd;
|
|
38706
|
+
if (typeof cost === "number")
|
|
38707
|
+
spentUsd += cost;
|
|
37795
38708
|
}
|
|
37796
38709
|
lastDiag = {
|
|
37797
38710
|
exitCode: result.code,
|
|
37798
38711
|
stderrTruncated: sanitizeStderr(result.stderr),
|
|
38712
|
+
resultTruncated: extractSanitizedErrorResult(payload, isError),
|
|
37799
38713
|
subtype,
|
|
37800
38714
|
isError,
|
|
37801
38715
|
timedOut: result.timedOut,
|
|
37802
38716
|
http429,
|
|
38717
|
+
requestBudgetExhausted,
|
|
37803
38718
|
attempt
|
|
37804
38719
|
};
|
|
37805
|
-
if (result.budgetStop) {
|
|
38720
|
+
if (result.budgetStop || requestBudgetExhausted) {
|
|
38721
|
+
return {
|
|
38722
|
+
cell: null,
|
|
38723
|
+
pending: true,
|
|
38724
|
+
pendingReason: result.budgetStop ?? "request budget exhausted (proxy 403 cc_proxy_budget)",
|
|
38725
|
+
durationMs: Date.now() - started,
|
|
38726
|
+
diagnostics: lastDiag,
|
|
38727
|
+
spentUsd,
|
|
38728
|
+
totals: null
|
|
38729
|
+
};
|
|
38730
|
+
}
|
|
38731
|
+
if (subtype === "error_max_budget_usd") {
|
|
37806
38732
|
return {
|
|
37807
38733
|
cell: null,
|
|
37808
38734
|
pending: true,
|
|
37809
|
-
pendingReason:
|
|
38735
|
+
pendingReason: "spend budget exhausted (--max-budget-usd)",
|
|
37810
38736
|
durationMs: Date.now() - started,
|
|
37811
38737
|
diagnostics: lastDiag,
|
|
38738
|
+
spentUsd,
|
|
37812
38739
|
totals: null
|
|
37813
38740
|
};
|
|
37814
38741
|
}
|
|
@@ -37827,6 +38754,7 @@ async function runClaudeHostCell(slot, options) {
|
|
|
37827
38754
|
pendingReason: `claude no valid cell: exit=${result.code} subtype=${subtype} is_error=${isError} timedOut=${result.timedOut}`,
|
|
37828
38755
|
durationMs: Date.now() - started,
|
|
37829
38756
|
diagnostics: lastDiag,
|
|
38757
|
+
spentUsd,
|
|
37830
38758
|
totals: null
|
|
37831
38759
|
};
|
|
37832
38760
|
}
|
|
@@ -37842,15 +38770,15 @@ async function runClaudeHostCell(slot, options) {
|
|
|
37842
38770
|
if (promoteMatch) {
|
|
37843
38771
|
const destRel = promoteMatch[1].replace(/^\.\//, "");
|
|
37844
38772
|
const base = destRel.replace(/\.test\.ts$/, "");
|
|
37845
|
-
const example =
|
|
37846
|
-
const dest =
|
|
38773
|
+
const example = join41(cwd, `${base}.test.ts.example`);
|
|
38774
|
+
const dest = join41(cwd, destRel);
|
|
37847
38775
|
try {
|
|
37848
38776
|
await access9(example);
|
|
37849
|
-
const body = await
|
|
38777
|
+
const body = await readFile61(example, "utf-8");
|
|
37850
38778
|
await writeFile36(dest, body, "utf-8");
|
|
37851
38779
|
} catch {}
|
|
37852
38780
|
}
|
|
37853
|
-
const test = await runShell(slot.testCommand, cwd, 60000, buildClaudeEnv(options.modelId));
|
|
38781
|
+
const test = await runShell(slot.testCommand, cwd, 60000, buildClaudeEnv(options.modelId, provider));
|
|
37854
38782
|
success = test.code === 0;
|
|
37855
38783
|
} else {
|
|
37856
38784
|
success = result.code === 0 && isError !== true;
|
|
@@ -37889,6 +38817,7 @@ async function runClaudeHostCell(slot, options) {
|
|
|
37889
38817
|
pendingReason: null,
|
|
37890
38818
|
durationMs: Date.now() - started,
|
|
37891
38819
|
diagnostics: lastDiag,
|
|
38820
|
+
spentUsd,
|
|
37892
38821
|
totals: {
|
|
37893
38822
|
input,
|
|
37894
38823
|
output,
|
|
@@ -37904,6 +38833,7 @@ async function runClaudeHostCell(slot, options) {
|
|
|
37904
38833
|
pendingReason: "exhausted attempts without valid cell",
|
|
37905
38834
|
durationMs: Date.now() - started,
|
|
37906
38835
|
diagnostics: lastDiag,
|
|
38836
|
+
spentUsd,
|
|
37907
38837
|
totals: null
|
|
37908
38838
|
};
|
|
37909
38839
|
} catch (err3) {
|
|
@@ -37916,31 +38846,39 @@ async function runClaudeHostCell(slot, options) {
|
|
|
37916
38846
|
...lastDiag,
|
|
37917
38847
|
stderrTruncated: sanitizeStderr(err3 instanceof Error ? err3.message : String(err3))
|
|
37918
38848
|
},
|
|
38849
|
+
spentUsd,
|
|
37919
38850
|
totals: null
|
|
37920
38851
|
};
|
|
37921
38852
|
} finally {
|
|
37922
|
-
|
|
37923
|
-
|
|
37924
|
-
|
|
37925
|
-
|
|
38853
|
+
for (const dir of [workDir, configDir]) {
|
|
38854
|
+
if (dir)
|
|
38855
|
+
await rm6(dir, { recursive: true, force: true }).catch(() => {
|
|
38856
|
+
return;
|
|
38857
|
+
});
|
|
37926
38858
|
}
|
|
37927
38859
|
}
|
|
37928
38860
|
}
|
|
37929
|
-
var lastCallAt = 0;
|
|
38861
|
+
var HARNESS_MARKER_PATHS, lastCallAt = 0;
|
|
37930
38862
|
var init_host_claude = __esm(() => {
|
|
37931
38863
|
init_claude_json();
|
|
37932
38864
|
init_install_command();
|
|
38865
|
+
init_openrouter_request_proxy();
|
|
38866
|
+
HARNESS_MARKER_PATHS = [
|
|
38867
|
+
".claude/CLAUDE.md",
|
|
38868
|
+
".claude/settings.json",
|
|
38869
|
+
".claude/hooks/invoke-hook.cjs"
|
|
38870
|
+
];
|
|
37933
38871
|
});
|
|
37934
38872
|
|
|
37935
38873
|
// src/core/evaluation/bench/runner.ts
|
|
37936
|
-
import { cp as cp3, mkdtemp as mkdtemp4, readFile as
|
|
38874
|
+
import { cp as cp3, mkdtemp as mkdtemp4, readFile as readFile62, rm as rm7, writeFile as writeFile37, mkdir as mkdir36 } from "node:fs/promises";
|
|
37937
38875
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
37938
|
-
import { join as
|
|
37939
|
-
import { createHash as
|
|
38876
|
+
import { join as join42, resolve as resolve60 } from "node:path";
|
|
38877
|
+
import { createHash as createHash18 } from "node:crypto";
|
|
37940
38878
|
function defaultReportDir(projectRoot) {
|
|
37941
|
-
const hash =
|
|
37942
|
-
const xdg = process.env.XDG_STATE_HOME ??
|
|
37943
|
-
return
|
|
38879
|
+
const hash = createHash18("sha256").update(projectRoot).digest("hex").slice(0, 12);
|
|
38880
|
+
const xdg = process.env.XDG_STATE_HOME ?? join42(tmpdir4(), "cc-state");
|
|
38881
|
+
return join42(xdg, "codeconductor", hash, "bench");
|
|
37944
38882
|
}
|
|
37945
38883
|
function interleaveSchedule(taskIds, n, seed) {
|
|
37946
38884
|
const rng = createLcg(seed);
|
|
@@ -37963,6 +38901,19 @@ function interleaveSchedule(taskIds, n, seed) {
|
|
|
37963
38901
|
}
|
|
37964
38902
|
return pairs.flat();
|
|
37965
38903
|
}
|
|
38904
|
+
function buildTaskPrompt(task) {
|
|
38905
|
+
return [
|
|
38906
|
+
task.prompt.trim(),
|
|
38907
|
+
"",
|
|
38908
|
+
`Files in scope: ${task.scope}`,
|
|
38909
|
+
"",
|
|
38910
|
+
"Acceptance criteria:",
|
|
38911
|
+
...task.acceptanceCriteria.map((c) => `- ${c}`),
|
|
38912
|
+
"",
|
|
38913
|
+
"Apply the change by editing the files."
|
|
38914
|
+
].join(`
|
|
38915
|
+
`);
|
|
38916
|
+
}
|
|
37966
38917
|
function synthesizeDryCells(taskIds, n, seed) {
|
|
37967
38918
|
const schedule = interleaveSchedule(taskIds, n, seed);
|
|
37968
38919
|
const rng = createLcg(seed ^ 2654435769);
|
|
@@ -37997,7 +38948,7 @@ async function loadCells(options) {
|
|
|
37997
38948
|
if (options.cells)
|
|
37998
38949
|
return options.cells;
|
|
37999
38950
|
if (options.cellsPath) {
|
|
38000
|
-
const raw = JSON.parse(await
|
|
38951
|
+
const raw = JSON.parse(await readFile62(options.cellsPath, "utf-8"));
|
|
38001
38952
|
if (!Array.isArray(raw))
|
|
38002
38953
|
throw new Error("cellsPath must be a JSON array");
|
|
38003
38954
|
return raw;
|
|
@@ -38018,25 +38969,37 @@ async function runBench(options) {
|
|
|
38018
38969
|
if (!suite.success) {
|
|
38019
38970
|
throw suite.error;
|
|
38020
38971
|
}
|
|
38021
|
-
const
|
|
38972
|
+
const allTaskIds = suite.data.tasks.map((t) => t.id);
|
|
38022
38973
|
const taskById = new Map(suite.data.tasks.map((t) => [t.id, t]));
|
|
38023
|
-
|
|
38974
|
+
let taskIds = allTaskIds;
|
|
38975
|
+
if (options.taskIds && options.taskIds.length > 0) {
|
|
38976
|
+
const missing = options.taskIds.filter((id) => !taskById.has(id));
|
|
38977
|
+
if (missing.length > 0) {
|
|
38978
|
+
throw new Error(`unknown bench taskIds: ${missing.join(", ")}`);
|
|
38979
|
+
}
|
|
38980
|
+
taskIds = options.taskIds;
|
|
38981
|
+
}
|
|
38982
|
+
const fixtureDir = suite.data.fixtureDir ? resolve60(options.suitePath ? resolve60(options.suitePath, "..") : resolve60(PACKAGE_ROOT, "eval", "suites", suiteId), suite.data.fixtureDir) : null;
|
|
38024
38983
|
if (fixtureDir) {
|
|
38025
|
-
const wt = await mkdtemp4(
|
|
38984
|
+
const wt = await mkdtemp4(join42(tmpdir4(), "cc-bench-"));
|
|
38026
38985
|
workDirs.push(wt);
|
|
38027
|
-
await cp3(fixtureDir,
|
|
38986
|
+
await cp3(fixtureDir, join42(wt, "fixture"), { recursive: true });
|
|
38028
38987
|
}
|
|
38029
38988
|
let usageBefore = null;
|
|
38030
38989
|
let runValid = true;
|
|
38031
38990
|
let aborted = false;
|
|
38032
38991
|
let abortReason = null;
|
|
38033
|
-
const modelId = options.modelId ?? "
|
|
38992
|
+
const modelId = options.modelId ?? "deepseek/deepseek-v4-flash";
|
|
38993
|
+
const maxSpendUsd = options.maxSpendUsd ?? options.maxLimitUsd ?? DEFAULT_OPENROUTER_SPEND_CAP_USD;
|
|
38994
|
+
const variantAllow = options.variants ? new Set(options.variants) : null;
|
|
38995
|
+
const provider = options.provider ?? "openrouter";
|
|
38996
|
+
let spentUsd = 0;
|
|
38034
38997
|
if (cheap) {
|
|
38035
38998
|
const lock = await assertOpenRouterZeroSpend({
|
|
38036
38999
|
modelId,
|
|
38037
39000
|
key: options.keyBefore,
|
|
38038
39001
|
fetchKey: options.fetchKey,
|
|
38039
|
-
|
|
39002
|
+
maxSpendUsd,
|
|
38040
39003
|
skipKeyCheck: options.keyBefore === undefined && !options.fetchKey && !process.env.OPENROUTER_API_KEY && options.live !== true
|
|
38041
39004
|
});
|
|
38042
39005
|
if (!lock.ok) {
|
|
@@ -38050,9 +39013,9 @@ async function runBench(options) {
|
|
|
38050
39013
|
let cells = await loadCells(options);
|
|
38051
39014
|
if (!cells) {
|
|
38052
39015
|
if (options.live === true) {
|
|
38053
|
-
if (!cheap) {
|
|
39016
|
+
if (provider === "openrouter" && !cheap) {
|
|
38054
39017
|
aborted = true;
|
|
38055
|
-
abortReason = "live bench requires --cheap (OpenRouter
|
|
39018
|
+
abortReason = "live bench requires --cheap (OpenRouter $5 spend lock)";
|
|
38056
39019
|
runValid = false;
|
|
38057
39020
|
cells = [];
|
|
38058
39021
|
} else if (!fixtureDir) {
|
|
@@ -38068,7 +39031,7 @@ async function runBench(options) {
|
|
|
38068
39031
|
} else if (aborted) {
|
|
38069
39032
|
cells = [];
|
|
38070
39033
|
} else {
|
|
38071
|
-
const schedule = interleaveSchedule(taskIds, n, seed);
|
|
39034
|
+
const schedule = interleaveSchedule(taskIds, n, seed).filter((s) => variantAllow ? variantAllow.has(s.variant) : true);
|
|
38072
39035
|
const maxLive = options.maxLiveCells ?? schedule.length;
|
|
38073
39036
|
cells = [];
|
|
38074
39037
|
let lastTaskId = null;
|
|
@@ -38095,10 +39058,11 @@ async function runBench(options) {
|
|
|
38095
39058
|
continue;
|
|
38096
39059
|
}
|
|
38097
39060
|
if (lastTaskId !== null && slot.taskId !== lastTaskId && usageBefore !== null) {
|
|
38098
|
-
const mid = await
|
|
39061
|
+
const mid = await assertOpenRouterUsageWithinCap({
|
|
38099
39062
|
usageBefore,
|
|
38100
39063
|
keyAfter: options.keyAfter,
|
|
38101
|
-
fetchKey: options.fetchKey
|
|
39064
|
+
fetchKey: options.fetchKey,
|
|
39065
|
+
maxSpendUsd
|
|
38102
39066
|
});
|
|
38103
39067
|
if (!mid.ok) {
|
|
38104
39068
|
aborted = true;
|
|
@@ -38119,19 +39083,28 @@ async function runBench(options) {
|
|
|
38119
39083
|
taskId: slot.taskId,
|
|
38120
39084
|
variant: slot.variant,
|
|
38121
39085
|
repetition: slot.repetition,
|
|
38122
|
-
prompt: task
|
|
38123
|
-
testCommand: task
|
|
39086
|
+
prompt: buildTaskPrompt(task),
|
|
39087
|
+
testCommand: task.testCommand
|
|
38124
39088
|
}, {
|
|
38125
39089
|
fixtureDir,
|
|
38126
39090
|
modelId,
|
|
38127
39091
|
budget: options.budget,
|
|
38128
39092
|
hostVersion: process.env.CLAUDE_CODE_VERSION ?? null,
|
|
38129
|
-
maxAttempts: 2
|
|
39093
|
+
maxAttempts: 2,
|
|
39094
|
+
maxTurns: options.maxTurns,
|
|
39095
|
+
provider,
|
|
39096
|
+
maxBudgetUsd: provider === "anthropic" ? maxSpendUsd - spentUsd : undefined
|
|
38130
39097
|
});
|
|
39098
|
+
spentUsd += hostResult.spentUsd;
|
|
39099
|
+
if (provider === "anthropic" && spentUsd >= maxSpendUsd) {
|
|
39100
|
+
aborted = true;
|
|
39101
|
+
abortReason = `spend budget exhausted: $${spentUsd.toFixed(4)}/$${maxSpendUsd}`;
|
|
39102
|
+
runValid = false;
|
|
39103
|
+
}
|
|
38131
39104
|
const spent = budgetExhausted(options.budget);
|
|
38132
|
-
if (spent) {
|
|
39105
|
+
if (spent || hostResult.diagnostics.requestBudgetExhausted || isRequestBudgetAbortReason(hostResult.pendingReason) || hostResult.diagnostics.subtype === "error_max_budget_usd") {
|
|
38133
39106
|
aborted = true;
|
|
38134
|
-
abortReason = spent;
|
|
39107
|
+
abortReason = spent ?? hostResult.pendingReason ?? "request budget exhausted";
|
|
38135
39108
|
runValid = false;
|
|
38136
39109
|
}
|
|
38137
39110
|
invocations.push({
|
|
@@ -38163,10 +39136,11 @@ async function runBench(options) {
|
|
|
38163
39136
|
} finally {
|
|
38164
39137
|
if (usageBefore !== null) {
|
|
38165
39138
|
try {
|
|
38166
|
-
const after = await
|
|
39139
|
+
const after = await assertOpenRouterUsageWithinCap({
|
|
38167
39140
|
usageBefore,
|
|
38168
39141
|
keyAfter: options.keyAfter,
|
|
38169
|
-
fetchKey: options.fetchKey
|
|
39142
|
+
fetchKey: options.fetchKey,
|
|
39143
|
+
maxSpendUsd
|
|
38170
39144
|
});
|
|
38171
39145
|
usageAfter = after.usageAfter;
|
|
38172
39146
|
if (!after.ok) {
|
|
@@ -38195,10 +39169,11 @@ async function runBench(options) {
|
|
|
38195
39169
|
}
|
|
38196
39170
|
if (!options.live && cheap && !aborted && usageBefore !== null) {
|
|
38197
39171
|
for (const taskId of taskIds) {
|
|
38198
|
-
const after = await
|
|
39172
|
+
const after = await assertOpenRouterUsageWithinCap({
|
|
38199
39173
|
usageBefore,
|
|
38200
39174
|
keyAfter: options.keyAfter,
|
|
38201
|
-
fetchKey: options.fetchKey
|
|
39175
|
+
fetchKey: options.fetchKey,
|
|
39176
|
+
maxSpendUsd
|
|
38202
39177
|
});
|
|
38203
39178
|
usageAfter = after.usageAfter;
|
|
38204
39179
|
if (!after.ok) {
|
|
@@ -38209,28 +39184,28 @@ async function runBench(options) {
|
|
|
38209
39184
|
}
|
|
38210
39185
|
}
|
|
38211
39186
|
}
|
|
38212
|
-
const
|
|
39187
|
+
const report2 = buildBenchReport({
|
|
38213
39188
|
suiteId,
|
|
38214
39189
|
cells,
|
|
38215
39190
|
fingerprints: options.fingerprints ?? {
|
|
38216
39191
|
harness: null,
|
|
38217
39192
|
prompt: null,
|
|
38218
|
-
host: null,
|
|
38219
|
-
model: options.modelId ?? (cheap ? "openrouter:
|
|
39193
|
+
host: process.env.CLAUDE_CODE_VERSION ?? null,
|
|
39194
|
+
model: options.modelId ?? (cheap ? "openrouter:cheap" : "dry-synthetic"),
|
|
38220
39195
|
pricingVersion: null
|
|
38221
39196
|
},
|
|
38222
39197
|
claim: options.claim ?? "success-only",
|
|
38223
39198
|
cheap,
|
|
38224
39199
|
seed
|
|
38225
39200
|
});
|
|
38226
|
-
const markdown = formatBenchReportMarkdown(
|
|
39201
|
+
const markdown = formatBenchReportMarkdown(report2);
|
|
38227
39202
|
let reportPath = null;
|
|
38228
39203
|
if (options.writeReport !== false) {
|
|
38229
39204
|
const dir = options.reportDir ?? defaultReportDir(projectRoot);
|
|
38230
39205
|
await mkdir36(dir, { recursive: true });
|
|
38231
|
-
reportPath =
|
|
38232
|
-
await writeFile37(reportPath, JSON.stringify(
|
|
38233
|
-
await writeFile37(
|
|
39206
|
+
reportPath = join42(dir, "bench-report.json");
|
|
39207
|
+
await writeFile37(reportPath, JSON.stringify(report2, null, 2), "utf-8");
|
|
39208
|
+
await writeFile37(join42(dir, "bench-report.md"), markdown, "utf-8");
|
|
38234
39209
|
}
|
|
38235
39210
|
for (const d of workDirs) {
|
|
38236
39211
|
await rm7(d, { recursive: true, force: true }).catch(() => {
|
|
@@ -38238,7 +39213,7 @@ async function runBench(options) {
|
|
|
38238
39213
|
});
|
|
38239
39214
|
}
|
|
38240
39215
|
return {
|
|
38241
|
-
report,
|
|
39216
|
+
report: report2,
|
|
38242
39217
|
markdown,
|
|
38243
39218
|
reportPath,
|
|
38244
39219
|
workDirs,
|
|
@@ -38265,8 +39240,8 @@ __export(exports_scorecard_command, {
|
|
|
38265
39240
|
measureCurrentPromptMetrics: () => measureCurrentPromptMetrics,
|
|
38266
39241
|
scorecardCommand: () => scorecardCommand
|
|
38267
39242
|
});
|
|
38268
|
-
import { readFile as
|
|
38269
|
-
import { resolve as
|
|
39243
|
+
import { readFile as readFile63 } from "node:fs/promises";
|
|
39244
|
+
import { resolve as resolve61 } from "node:path";
|
|
38270
39245
|
function contractVersion() {
|
|
38271
39246
|
return package_default.version;
|
|
38272
39247
|
}
|
|
@@ -38651,12 +39626,12 @@ async function handleCompareModels(projectRoot, options) {
|
|
|
38651
39626
|
outcomes = outcomes.filter((o) => options.modelsFilter.includes(o.model));
|
|
38652
39627
|
}
|
|
38653
39628
|
const markdown = generateModelComparisonMarkdown(outcomes, options.modelsFilter);
|
|
38654
|
-
const templatePath =
|
|
39629
|
+
const templatePath = resolve61(projectRoot, ".codeconductor/evaluation/model-comparison-last.md");
|
|
38655
39630
|
try {
|
|
38656
|
-
await
|
|
39631
|
+
await readFile63(templatePath);
|
|
38657
39632
|
} catch {}
|
|
38658
39633
|
const { writeFile: writeFile38, mkdir: mkdir37 } = await import("node:fs/promises");
|
|
38659
|
-
await mkdir37(
|
|
39634
|
+
await mkdir37(resolve61(projectRoot, ".codeconductor/evaluation"), { recursive: true });
|
|
38660
39635
|
await writeFile38(templatePath, markdown, "utf-8");
|
|
38661
39636
|
return {
|
|
38662
39637
|
code: 0,
|
|
@@ -38768,15 +39743,15 @@ async function handleAblation(projectRoot, options) {
|
|
|
38768
39743
|
if (!list.success) {
|
|
38769
39744
|
return { code: 1, data: { success: false, errors: [list.error.message] } };
|
|
38770
39745
|
}
|
|
38771
|
-
const
|
|
38772
|
-
const markdown = formatAblationMarkdown(
|
|
39746
|
+
const report2 = await buildAblationReport(projectRoot, list.data, filter.experimentId);
|
|
39747
|
+
const markdown = formatAblationMarkdown(report2);
|
|
38773
39748
|
const path = await persistAblationReport(projectRoot, markdown);
|
|
38774
39749
|
return {
|
|
38775
39750
|
code: 0,
|
|
38776
39751
|
data: {
|
|
38777
39752
|
success: true,
|
|
38778
39753
|
command: "scorecard ablation",
|
|
38779
|
-
report,
|
|
39754
|
+
report: report2,
|
|
38780
39755
|
markdown,
|
|
38781
39756
|
path
|
|
38782
39757
|
}
|
|
@@ -39841,10 +40816,10 @@ async function mapLimit2(items, limit, fn) {
|
|
|
39841
40816
|
let next = 0;
|
|
39842
40817
|
async function worker() {
|
|
39843
40818
|
while (true) {
|
|
39844
|
-
const
|
|
39845
|
-
if (
|
|
40819
|
+
const index2 = next++;
|
|
40820
|
+
if (index2 >= items.length)
|
|
39846
40821
|
return;
|
|
39847
|
-
out[
|
|
40822
|
+
out[index2] = await fn(items[index2]);
|
|
39848
40823
|
}
|
|
39849
40824
|
}
|
|
39850
40825
|
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
@@ -39979,15 +40954,15 @@ var init_seo_auditor = __esm(() => {
|
|
|
39979
40954
|
});
|
|
39980
40955
|
|
|
39981
40956
|
// src/domain/seo/report-formatter.ts
|
|
39982
|
-
function formatCli(
|
|
40957
|
+
function formatCli(report2) {
|
|
39983
40958
|
const lines = [];
|
|
39984
40959
|
lines.push("");
|
|
39985
40960
|
lines.push(`${BOLD}SEO Audit Report${RESET}`);
|
|
39986
|
-
lines.push(`${DIM}Target: ${
|
|
39987
|
-
lines.push(`${DIM}Time: ${
|
|
39988
|
-
lines.push(`${DIM}Pages: ${
|
|
40961
|
+
lines.push(`${DIM}Target: ${report2.target}${RESET}`);
|
|
40962
|
+
lines.push(`${DIM}Time: ${report2.timestamp}${RESET}`);
|
|
40963
|
+
lines.push(`${DIM}Pages: ${report2.pages.length}${RESET}`);
|
|
39989
40964
|
lines.push("");
|
|
39990
|
-
for (const page of
|
|
40965
|
+
for (const page of report2.pages) {
|
|
39991
40966
|
lines.push(`${BOLD}── ${page.url} (${page.responseTime}ms) ──${RESET}`);
|
|
39992
40967
|
const grouped = groupByCategory(page.checks);
|
|
39993
40968
|
for (const [category, checks] of grouped) {
|
|
@@ -40003,7 +40978,7 @@ function formatCli(report) {
|
|
|
40003
40978
|
}
|
|
40004
40979
|
lines.push("");
|
|
40005
40980
|
}
|
|
40006
|
-
const { summary } =
|
|
40981
|
+
const { summary } = report2;
|
|
40007
40982
|
lines.push(`${BOLD}Summary${RESET}`);
|
|
40008
40983
|
lines.push(` Score: ${summary.score}%`);
|
|
40009
40984
|
lines.push(` ${SEVERITY_COLORS.pass}✓ ${summary.passed} passed${RESET}`);
|
|
@@ -40014,28 +40989,28 @@ function formatCli(report) {
|
|
|
40014
40989
|
return lines.join(`
|
|
40015
40990
|
`);
|
|
40016
40991
|
}
|
|
40017
|
-
function formatJson(
|
|
40018
|
-
return JSON.stringify(
|
|
40992
|
+
function formatJson(report2) {
|
|
40993
|
+
return JSON.stringify(report2, null, 2);
|
|
40019
40994
|
}
|
|
40020
|
-
function formatMarkdown(
|
|
40995
|
+
function formatMarkdown(report2) {
|
|
40021
40996
|
const lines = [];
|
|
40022
40997
|
lines.push("# SEO Audit Report");
|
|
40023
40998
|
lines.push("");
|
|
40024
|
-
lines.push(`- **Target:** ${
|
|
40025
|
-
lines.push(`- **Date:** ${
|
|
40026
|
-
lines.push(`- **Pages audited:** ${
|
|
40999
|
+
lines.push(`- **Target:** ${report2.target}`);
|
|
41000
|
+
lines.push(`- **Date:** ${report2.timestamp}`);
|
|
41001
|
+
lines.push(`- **Pages audited:** ${report2.pages.length}`);
|
|
40027
41002
|
lines.push("");
|
|
40028
41003
|
lines.push("## Summary");
|
|
40029
41004
|
lines.push("");
|
|
40030
41005
|
lines.push(`| Metric | Value |`);
|
|
40031
41006
|
lines.push(`|--------|-------|`);
|
|
40032
|
-
lines.push(`| Score | ${
|
|
40033
|
-
lines.push(`| Passed | ${
|
|
40034
|
-
lines.push(`| Warnings | ${
|
|
40035
|
-
lines.push(`| Errors | ${
|
|
40036
|
-
lines.push(`| Total checks | ${
|
|
41007
|
+
lines.push(`| Score | ${report2.summary.score}% |`);
|
|
41008
|
+
lines.push(`| Passed | ${report2.summary.passed} |`);
|
|
41009
|
+
lines.push(`| Warnings | ${report2.summary.warnings} |`);
|
|
41010
|
+
lines.push(`| Errors | ${report2.summary.errors} |`);
|
|
41011
|
+
lines.push(`| Total checks | ${report2.summary.total} |`);
|
|
40037
41012
|
lines.push("");
|
|
40038
|
-
for (const page of
|
|
41013
|
+
for (const page of report2.pages) {
|
|
40039
41014
|
lines.push(`## ${page.url}`);
|
|
40040
41015
|
lines.push("");
|
|
40041
41016
|
lines.push(`Response time: ${page.responseTime}ms`);
|
|
@@ -40084,7 +41059,7 @@ function formatMarkdown(report) {
|
|
|
40084
41059
|
}
|
|
40085
41060
|
}
|
|
40086
41061
|
lines.push("---");
|
|
40087
|
-
lines.push(`*Generated by CodeConductor SEO Audit on ${
|
|
41062
|
+
lines.push(`*Generated by CodeConductor SEO Audit on ${report2.timestamp.split("T")[0]}*`);
|
|
40088
41063
|
return lines.join(`
|
|
40089
41064
|
`);
|
|
40090
41065
|
}
|
|
@@ -40098,12 +41073,12 @@ function groupByCategory(checks) {
|
|
|
40098
41073
|
}
|
|
40099
41074
|
return groups;
|
|
40100
41075
|
}
|
|
40101
|
-
function computeExitCode(
|
|
40102
|
-
if (
|
|
41076
|
+
function computeExitCode(report2, failOn) {
|
|
41077
|
+
if (report2.summary.errors > 0)
|
|
40103
41078
|
return 1;
|
|
40104
|
-
if (failOn === "warning" &&
|
|
41079
|
+
if (failOn === "warning" && report2.summary.warnings > 0)
|
|
40105
41080
|
return 2;
|
|
40106
|
-
if (
|
|
41081
|
+
if (report2.summary.warnings > 0)
|
|
40107
41082
|
return 0;
|
|
40108
41083
|
return 0;
|
|
40109
41084
|
}
|
|
@@ -40128,7 +41103,7 @@ var exports_seo_audit_command = {};
|
|
|
40128
41103
|
__export(exports_seo_audit_command, {
|
|
40129
41104
|
seoAuditCommand: () => seoAuditCommand
|
|
40130
41105
|
});
|
|
40131
|
-
import { join as
|
|
41106
|
+
import { join as join43 } from "node:path";
|
|
40132
41107
|
async function seoAuditCommand(options) {
|
|
40133
41108
|
const { url, sitemap, format, failOn, delay: delay2, output, followRedirects, force } = options;
|
|
40134
41109
|
if (!url && !sitemap) {
|
|
@@ -40141,7 +41116,7 @@ async function seoAuditCommand(options) {
|
|
|
40141
41116
|
}
|
|
40142
41117
|
};
|
|
40143
41118
|
}
|
|
40144
|
-
const defaultMarkdownPath = output === undefined && format === "markdown" ?
|
|
41119
|
+
const defaultMarkdownPath = output === undefined && format === "markdown" ? join43("seo-reports", `audit-report-${new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19)}.md`) : undefined;
|
|
40145
41120
|
const outputPathToWrite = output ?? defaultMarkdownPath;
|
|
40146
41121
|
if (outputPathToWrite !== undefined) {
|
|
40147
41122
|
const preflightError = await preflightContainedOutput(options.projectRoot, outputPathToWrite, { force });
|
|
@@ -40157,7 +41132,7 @@ async function seoAuditCommand(options) {
|
|
|
40157
41132
|
}
|
|
40158
41133
|
}
|
|
40159
41134
|
try {
|
|
40160
|
-
const
|
|
41135
|
+
const report2 = sitemap ? await auditSitemap(sitemap, {
|
|
40161
41136
|
delay: delay2,
|
|
40162
41137
|
followRedirects,
|
|
40163
41138
|
onProgress: format === "cli" ? (current, total, pageUrl) => {
|
|
@@ -40170,13 +41145,13 @@ async function seoAuditCommand(options) {
|
|
|
40170
41145
|
let formattedOutput;
|
|
40171
41146
|
switch (format) {
|
|
40172
41147
|
case "json":
|
|
40173
|
-
formattedOutput = formatJson(
|
|
41148
|
+
formattedOutput = formatJson(report2);
|
|
40174
41149
|
break;
|
|
40175
41150
|
case "markdown":
|
|
40176
|
-
formattedOutput = formatMarkdown(
|
|
41151
|
+
formattedOutput = formatMarkdown(report2);
|
|
40177
41152
|
break;
|
|
40178
41153
|
default:
|
|
40179
|
-
formattedOutput = formatCli(
|
|
41154
|
+
formattedOutput = formatCli(report2);
|
|
40180
41155
|
}
|
|
40181
41156
|
let outputFile;
|
|
40182
41157
|
if (outputPathToWrite !== undefined) {
|
|
@@ -40186,13 +41161,13 @@ async function seoAuditCommand(options) {
|
|
|
40186
41161
|
`);
|
|
40187
41162
|
}
|
|
40188
41163
|
}
|
|
40189
|
-
const exitCode = computeExitCode(
|
|
41164
|
+
const exitCode = computeExitCode(report2, failOn);
|
|
40190
41165
|
return {
|
|
40191
41166
|
code: exitCode,
|
|
40192
41167
|
data: {
|
|
40193
41168
|
success: true,
|
|
40194
41169
|
command: "seo audit",
|
|
40195
|
-
report,
|
|
41170
|
+
report: report2,
|
|
40196
41171
|
output: formattedOutput,
|
|
40197
41172
|
outputFile
|
|
40198
41173
|
}
|
|
@@ -40375,15 +41350,15 @@ async function seoLlmsCommand(options) {
|
|
|
40375
41350
|
}
|
|
40376
41351
|
}) : await generateLlmsTxtFromUrl(url);
|
|
40377
41352
|
process.stderr.write("\r" + " ".repeat(80) + "\r");
|
|
40378
|
-
const
|
|
40379
|
-
process.stderr.write(`Generated: ${
|
|
41353
|
+
const outputPath2 = await writeContainedFile(options.projectRoot, outputPathToWrite, result.content, { force });
|
|
41354
|
+
process.stderr.write(`Generated: ${outputPath2} (${result.entries.length} entries)
|
|
40380
41355
|
`);
|
|
40381
41356
|
return {
|
|
40382
41357
|
code: 0,
|
|
40383
41358
|
data: {
|
|
40384
41359
|
success: true,
|
|
40385
41360
|
command: "seo llms",
|
|
40386
|
-
outputFile:
|
|
41361
|
+
outputFile: outputPath2,
|
|
40387
41362
|
entries: result.entries.length,
|
|
40388
41363
|
content: result.content
|
|
40389
41364
|
}
|
|
@@ -40523,6 +41498,7 @@ var COMMANDS = [
|
|
|
40523
41498
|
] },
|
|
40524
41499
|
{ name: "cc-help", group: "maintenance", summary: "Show a target preset inventory.", usage: ["cc-codeconductor cc-help --target <target>"] },
|
|
40525
41500
|
{ name: "ask", group: "workflow", summary: "Recommend a slash-command workflow.", usage: ['cc-codeconductor ask "problem"'] },
|
|
41501
|
+
{ name: "correct", group: "workflow", summary: "Recommend a correction layer and existing owner command.", usage: ['cc-codeconductor correct "mistake signal"'] },
|
|
40526
41502
|
{ name: "goal", aliases: ["cc-goal"], group: "workflow", summary: "Plan a goal into dependent tasks.", usage: ['cc-codeconductor goal "objective"'] },
|
|
40527
41503
|
{ name: "ingest", group: "workflow", summary: "Ingest repository knowledge into the product graph.", usage: ["cc-codeconductor ingest"] },
|
|
40528
41504
|
{ name: "product", group: "workflow", summary: "Explore the product graph and memory.", usage: ["cc-codeconductor product <subcommand>"] },
|
|
@@ -40535,6 +41511,7 @@ var COMMANDS = [
|
|
|
40535
41511
|
{ name: "verify", group: "workflow", summary: "Verify task completion with evidence.", usage: ["cc-codeconductor verify --task <id>"] },
|
|
40536
41512
|
{ name: "tdd", group: "workflow", summary: "Capture runner-verified RED/GREEN TDD evidence.", usage: ['cc-codeconductor tdd capture --task <cardId> --phase red|green --command "<test command>"'] },
|
|
40537
41513
|
{ name: "rdd", group: "workflow", summary: "Capture and validate Receipt-Driven Development evidence.", usage: ["cc-codeconductor rdd capture --task <id> [--phase red|green|review]", "cc-codeconductor rdd verify --receipt <id>", "cc-codeconductor rdd status [--task <id>]", "cc-codeconductor rdd git-check", "cc-codeconductor rdd install-hooks"] },
|
|
41514
|
+
{ name: "harness", group: "workflow", summary: "Seal tests and gate code for the SDD/TDD harness.", usage: ["cc-codeconductor harness seal --paths <dirs|files> [--force]", "cc-codeconductor harness verify-seal --paths <dirs|files> [--expected-hash <sha256>]", "cc-codeconductor harness check-code --paths <files>", "cc-codeconductor harness check-tests --paths <files>", "cc-codeconductor harness index [--out <file>]", "cc-codeconductor harness collisions --paths <files>"] },
|
|
40538
41515
|
{ name: "seo", group: "tool", summary: "Audit SEO and generate llms.txt.", usage: ["cc-codeconductor seo audit --url <url>"] },
|
|
40539
41516
|
{ name: "debt-harvest", aliases: ["harvest"], group: "tool", summary: "Scan source files for deferred debt.", usage: ["cc-codeconductor debt-harvest"] }
|
|
40540
41517
|
];
|
|
@@ -41018,6 +41995,14 @@ async function routeCommand(args, projectRoot) {
|
|
|
41018
41995
|
output: flags.output
|
|
41019
41996
|
});
|
|
41020
41997
|
}
|
|
41998
|
+
case "correct": {
|
|
41999
|
+
const { correctCommand: correctCommand2 } = await Promise.resolve().then(() => (init_correct_command(), exports_correct_command));
|
|
42000
|
+
const signal = subcommand && !subcommand.startsWith("-") ? [subcommand, ...args.rest ?? []].join(" ").trim() : (args.rest ?? []).join(" ").trim() || String(options.signal ?? options.problem ?? "");
|
|
42001
|
+
return correctCommand2({
|
|
42002
|
+
signal,
|
|
42003
|
+
output: flags.output
|
|
42004
|
+
});
|
|
42005
|
+
}
|
|
41021
42006
|
case "cc-help": {
|
|
41022
42007
|
const { helpCommand: helpCommand2 } = await Promise.resolve().then(() => (init_help_command(), exports_help_command));
|
|
41023
42008
|
return helpCommand2({
|
|
@@ -41189,6 +42174,26 @@ async function routeCommand(args, projectRoot) {
|
|
|
41189
42174
|
outFile: options.out
|
|
41190
42175
|
});
|
|
41191
42176
|
}
|
|
42177
|
+
case "harness": {
|
|
42178
|
+
const validSubs = ["seal", "verify-seal", "check-code", "check-tests", "index", "collisions"];
|
|
42179
|
+
if (!subcommand || !validSubs.includes(subcommand)) {
|
|
42180
|
+
return unknownSubcommand("harness", subcommand ?? "", [...validSubs]);
|
|
42181
|
+
}
|
|
42182
|
+
const { harnessCommand: harnessCommand2 } = await Promise.resolve().then(() => (init_harness_command(), exports_harness_command));
|
|
42183
|
+
const list = (value) => typeof value === "string" ? value.split(",").map((item) => item.trim()).filter(Boolean) : undefined;
|
|
42184
|
+
return harnessCommand2({
|
|
42185
|
+
subcommand,
|
|
42186
|
+
projectRoot,
|
|
42187
|
+
output: flags.output,
|
|
42188
|
+
paths: list(options.paths),
|
|
42189
|
+
lockDir: options["lock-dir"],
|
|
42190
|
+
domain: list(options.domain),
|
|
42191
|
+
outFile: options.out,
|
|
42192
|
+
mapFile: options.map,
|
|
42193
|
+
force: flags.force === true,
|
|
42194
|
+
expectedHash: options["expected-hash"]
|
|
42195
|
+
});
|
|
42196
|
+
}
|
|
41192
42197
|
case "rdd": {
|
|
41193
42198
|
const validSubs = ["capture", "verify", "status", "git-check", "install-hooks"];
|
|
41194
42199
|
if (!subcommand || !validSubs.includes(subcommand)) {
|