@devflow-tools/benchmark 0.17.7 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2 -2
- package/dist/accuracy-command-options.d.ts +3 -0
- package/dist/accuracy-command-options.d.ts.map +1 -0
- package/dist/accuracy-command-options.js +17 -0
- package/dist/accuracy-command-options.js.map +1 -0
- package/dist/context-symbol-quality-command.d.ts +59 -0
- package/dist/context-symbol-quality-command.d.ts.map +1 -0
- package/dist/context-symbol-quality-command.js +482 -0
- package/dist/context-symbol-quality-command.js.map +1 -0
- package/dist/evaluation-bundle-builder.d.ts +48 -0
- package/dist/evaluation-bundle-builder.d.ts.map +1 -0
- package/dist/evaluation-bundle-builder.js +496 -0
- package/dist/evaluation-bundle-builder.js.map +1 -0
- package/dist/evaluation-bundle-command.d.ts +2 -0
- package/dist/evaluation-bundle-command.d.ts.map +1 -0
- package/dist/evaluation-bundle-command.js +15 -0
- package/dist/evaluation-bundle-command.js.map +1 -0
- package/dist/evaluation-bundle.d.ts +55 -0
- package/dist/evaluation-bundle.d.ts.map +1 -0
- package/dist/evaluation-bundle.js +272 -0
- package/dist/evaluation-bundle.js.map +1 -0
- package/dist/evaluation-run-state.d.ts +23 -0
- package/dist/evaluation-run-state.d.ts.map +1 -0
- package/dist/evaluation-run-state.js +115 -0
- package/dist/evaluation-run-state.js.map +1 -0
- package/dist/evidence-quality-metrics.d.ts +15 -0
- package/dist/evidence-quality-metrics.d.ts.map +1 -1
- package/dist/evidence-quality-metrics.js +51 -1
- package/dist/evidence-quality-metrics.js.map +1 -1
- package/dist/graders/deterministic.d.ts.map +1 -1
- package/dist/graders/deterministic.js +5 -3
- package/dist/graders/deterministic.js.map +1 -1
- package/dist/index.d.ts +15 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/release-quality-bundle-command.d.ts +3 -0
- package/dist/release-quality-bundle-command.d.ts.map +1 -0
- package/dist/release-quality-bundle-command.js +72 -0
- package/dist/release-quality-bundle-command.js.map +1 -0
- package/dist/release-quality-bundle-evaluator.d.ts +61 -0
- package/dist/release-quality-bundle-evaluator.d.ts.map +1 -0
- package/dist/release-quality-bundle-evaluator.js +321 -0
- package/dist/release-quality-bundle-evaluator.js.map +1 -0
- package/dist/release-quality-bundle-materializer.d.ts +79 -0
- package/dist/release-quality-bundle-materializer.d.ts.map +1 -0
- package/dist/release-quality-bundle-materializer.js +395 -0
- package/dist/release-quality-bundle-materializer.js.map +1 -0
- package/dist/release-quality-comparison.d.ts +34 -0
- package/dist/release-quality-comparison.d.ts.map +1 -0
- package/dist/release-quality-comparison.js +60 -0
- package/dist/release-quality-comparison.js.map +1 -0
- package/dist/release-quality-evaluation-command.d.ts +42 -0
- package/dist/release-quality-evaluation-command.d.ts.map +1 -0
- package/dist/release-quality-evaluation-command.js +91 -0
- package/dist/release-quality-evaluation-command.js.map +1 -0
- package/dist/release-quality-host-proof.d.ts +30 -0
- package/dist/release-quality-host-proof.d.ts.map +1 -0
- package/dist/release-quality-host-proof.js +109 -0
- package/dist/release-quality-host-proof.js.map +1 -0
- package/dist/release-quality-output-cleanup.d.ts +2 -0
- package/dist/release-quality-output-cleanup.d.ts.map +1 -0
- package/dist/release-quality-output-cleanup.js +18 -0
- package/dist/release-quality-output-cleanup.js.map +1 -0
- package/dist/release-quality-policy.d.ts +87 -0
- package/dist/release-quality-policy.d.ts.map +1 -0
- package/dist/release-quality-policy.js +179 -0
- package/dist/release-quality-policy.js.map +1 -0
- package/dist/release-quality-query-sampling.d.ts +36 -0
- package/dist/release-quality-query-sampling.d.ts.map +1 -0
- package/dist/release-quality-query-sampling.js +87 -0
- package/dist/release-quality-query-sampling.js.map +1 -0
- package/dist/release-quality-source-snapshot.d.ts +18 -0
- package/dist/release-quality-source-snapshot.d.ts.map +1 -0
- package/dist/release-quality-source-snapshot.js +46 -0
- package/dist/release-quality-source-snapshot.js.map +1 -0
- package/dist/retrieval-quality-corpus.d.ts +0 -1
- package/dist/retrieval-quality-corpus.d.ts.map +1 -1
- package/dist/retrieval-quality-corpus.js +1 -1
- package/dist/retrieval-quality-corpus.js.map +1 -1
- package/dist/retrieval-quality.d.ts.map +1 -1
- package/dist/retrieval-quality.js +29 -26
- package/dist/retrieval-quality.js.map +1 -1
- package/dist/run-accuracy-tests.js +82 -2
- package/dist/run-accuracy-tests.js.map +1 -1
- package/dist/suite-runner.js +1 -1
- package/dist/suite-runner.js.map +1 -1
- package/dist/unified-runtime-corpus.d.ts +64 -0
- package/dist/unified-runtime-corpus.d.ts.map +1 -0
- package/dist/unified-runtime-corpus.js +161 -0
- package/dist/unified-runtime-corpus.js.map +1 -0
- package/dist/unified-runtime-evaluation.d.ts +133 -0
- package/dist/unified-runtime-evaluation.d.ts.map +1 -0
- package/dist/unified-runtime-evaluation.js +388 -0
- package/dist/unified-runtime-evaluation.js.map +1 -0
- package/dist/unified-runtime-observation.d.ts +101 -0
- package/dist/unified-runtime-observation.d.ts.map +1 -0
- package/dist/unified-runtime-observation.js +2 -0
- package/dist/unified-runtime-observation.js.map +1 -0
- package/dist/unified-runtime-runner.d.ts +73 -0
- package/dist/unified-runtime-runner.d.ts.map +1 -0
- package/dist/unified-runtime-runner.js +620 -0
- package/dist/unified-runtime-runner.js.map +1 -0
- package/fixtures/evidence-runtime-corpus.json +0 -100
- package/fixtures/release-quality/bundles.json +1 -0
- package/fixtures/release-quality/calibration.json +602 -0
- package/fixtures/release-quality/ecc/corpus.json +257 -0
- package/fixtures/release-quality/ecc/input.json +62 -0
- package/fixtures/release-quality/llm-wiki/corpus.json +263 -0
- package/fixtures/release-quality/llm-wiki/input.json +72 -0
- package/fixtures/release-quality/mem0/corpus.json +288 -0
- package/fixtures/release-quality/mem0/input.json +68 -0
- package/fixtures/release-quality/projects.json +29 -0
- package/fixtures/release-quality/release-quality-policy.json +232 -0
- package/fixtures/release-quality/rsbuild-react/corpus.json +263 -0
- package/fixtures/release-quality/rsbuild-react/input.json +62 -0
- package/fixtures/retrieval-quality-corpus.json +7 -7
- package/fixtures/semantic-regex-inventory.json +3 -10
- package/fixtures/unified-runtime/baselines/2026-08-08.json +37 -0
- package/fixtures/unified-runtime/context.json +206 -0
- package/fixtures/unified-runtime/knowledge.json +224 -0
- package/fixtures/unified-runtime/memory.json +224 -0
- package/fixtures/unified-runtime/real-projects/rsbuild-react-2026-08-07/context.json +32 -0
- package/fixtures/unified-runtime/real-projects/rsbuild-react-2026-08-07/knowledge.json +32 -0
- package/fixtures/unified-runtime/real-projects/rsbuild-react-2026-08-07/memory.json +32 -0
- package/fixtures/unified-runtime/real-projects/rsbuild-react-2026-08-07/semantic.json +409 -0
- package/fixtures/unified-runtime/runs/rsbuild-react-2026-08-05.json +54 -0
- package/fixtures/unified-runtime/semantic.json +409 -0
- package/package.json +24 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 shilongfeicool
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @devflow-tools/benchmark
|
|
2
2
|
|
|
3
|
-
> 用于比较 baseline 与 DevFlow Agent 结果的评测和检索质量基准库。(v0.17.
|
|
3
|
+
> 用于比较 baseline 与 DevFlow Agent 结果的评测和检索质量基准库。(v0.17.8)
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@devflow-tools/benchmark)
|
|
6
6
|
|
|
@@ -30,7 +30,7 @@ console.log(report.summary);
|
|
|
30
30
|
|
|
31
31
|
## 版本与兼容性
|
|
32
32
|
|
|
33
|
-
- 当前包版本:`0.17.
|
|
33
|
+
- 当前包版本:`0.17.8`
|
|
34
34
|
- Node.js:未在 package manifest 声明更高版本时,使用 Node.js 18+;原生 SQLite/Playwright 能力请按对应依赖安装
|
|
35
35
|
- workspace 内部包应使用同一 DevFlow minor/patch 版本,避免类型和数据库 schema 不一致
|
|
36
36
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accuracy-command-options.d.ts","sourceRoot":"","sources":["../src/accuracy-command-options.ts"],"names":[],"mappings":"AAEA,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEnF;AAED,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAElF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
export function resolveAccuracyProjectRoot(args, fallback) {
|
|
3
|
+
return resolve(optionalPathOption(args, '--project-root') ?? fallback);
|
|
4
|
+
}
|
|
5
|
+
export function resolveAccuracyFixtureDirectory(args) {
|
|
6
|
+
return optionalPathOption(args, '--fixture-directory');
|
|
7
|
+
}
|
|
8
|
+
function optionalPathOption(args, name) {
|
|
9
|
+
const index = args.indexOf(name);
|
|
10
|
+
if (index < 0)
|
|
11
|
+
return undefined;
|
|
12
|
+
const value = args[index + 1];
|
|
13
|
+
if (!value || value.startsWith('--'))
|
|
14
|
+
throw new Error(`${name} requires a path`);
|
|
15
|
+
return resolve(value);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=accuracy-command-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accuracy-command-options.js","sourceRoot":"","sources":["../src/accuracy-command-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,UAAU,0BAA0B,CAAC,IAAc,EAAE,QAAgB;IACzE,OAAO,OAAO,CAAC,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,CAAC,IAAI,QAAQ,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,IAAc;IAC5D,OAAO,kBAAkB,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAc,EAAE,IAAY;IACtD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,kBAAkB,CAAC,CAAC;IACjF,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type ProviderExecutionStatus } from '@devflow-tools/sdk';
|
|
2
|
+
import { type EvidenceQualityMetric } from './evidence-quality-metrics.js';
|
|
3
|
+
import { type RetrievalQuerySamplingAdapter } from '@devflow-tools/semantic-engine';
|
|
4
|
+
interface ContextExperimentCaseInput {
|
|
5
|
+
caseId: string;
|
|
6
|
+
candidateRefs: string[];
|
|
7
|
+
selectedRefs: string[];
|
|
8
|
+
goldRefs: string[];
|
|
9
|
+
forbiddenRefs: string[];
|
|
10
|
+
querySampling: ContextQuerySamplingEvidence;
|
|
11
|
+
}
|
|
12
|
+
interface ContextQuerySamplingEvidence {
|
|
13
|
+
status: ProviderExecutionStatus;
|
|
14
|
+
receiptHash: string;
|
|
15
|
+
reasonCodes: string[];
|
|
16
|
+
proposalCount: number;
|
|
17
|
+
acceptedCount: number;
|
|
18
|
+
rejectedCount: number;
|
|
19
|
+
proposals: Array<{
|
|
20
|
+
proposalId: string;
|
|
21
|
+
kind: 'rewrite' | 'expansion';
|
|
22
|
+
query: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export interface ContextSymbolExperimentReportV1 {
|
|
26
|
+
schemaVersion: 'devflow.context-symbol-experiment.v1';
|
|
27
|
+
profile: {
|
|
28
|
+
profileHash: string;
|
|
29
|
+
generation: 3;
|
|
30
|
+
modelId: string;
|
|
31
|
+
};
|
|
32
|
+
cases: Array<{
|
|
33
|
+
caseId: string;
|
|
34
|
+
candidateRefs: string[];
|
|
35
|
+
selectedRefs: string[];
|
|
36
|
+
goldRefs: string[];
|
|
37
|
+
candidateHit: boolean;
|
|
38
|
+
recallAt5: EvidenceQualityMetric;
|
|
39
|
+
forbiddenRefsAt5: string[];
|
|
40
|
+
querySampling: ContextQuerySamplingEvidence;
|
|
41
|
+
}>;
|
|
42
|
+
hits: number;
|
|
43
|
+
denominator: number;
|
|
44
|
+
status: 'passed' | 'failed';
|
|
45
|
+
}
|
|
46
|
+
export declare function evaluateContextExperiment(input: {
|
|
47
|
+
profile: ContextSymbolExperimentReportV1['profile'];
|
|
48
|
+
cases: ContextExperimentCaseInput[];
|
|
49
|
+
}): ContextSymbolExperimentReportV1;
|
|
50
|
+
export declare function runContextSymbolQualityExperiment(input: {
|
|
51
|
+
manifestPath: string;
|
|
52
|
+
sourcesRoot: string;
|
|
53
|
+
caseIds: string[];
|
|
54
|
+
samplingAdapter: RetrievalQuerySamplingAdapter;
|
|
55
|
+
observer?: (event: Record<string, unknown>) => void;
|
|
56
|
+
}): Promise<ContextSymbolExperimentReportV1>;
|
|
57
|
+
export declare function createDeepSeekSamplingAdapter(model: string): RetrievalQuerySamplingAdapter;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=context-symbol-quality-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-symbol-quality-command.d.ts","sourceRoot":"","sources":["../src/context-symbol-quality-command.ts"],"names":[],"mappings":"AAWA,OAAO,EAQL,KAAK,uBAAuB,EAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAyB,KAAK,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAMlG,OAAO,EAEL,KAAK,6BAA6B,EACnC,MAAM,gCAAgC,CAAC;AAgDxC,UAAU,0BAA0B;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE,4BAA4B,CAAC;CAC7C;AAED,UAAU,4BAA4B;IACpC,MAAM,EAAE,uBAAuB,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,KAAK,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,SAAS,GAAG,WAAW,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACxF;AAED,MAAM,WAAW,+BAA+B;IAC9C,aAAa,EAAE,sCAAsC,CAAC;IACtD,OAAO,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,CAAC,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACjE,KAAK,EAAE,KAAK,CAAC;QACX,MAAM,EAAE,MAAM,CAAC;QACf,aAAa,EAAE,MAAM,EAAE,CAAC;QACxB,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,YAAY,EAAE,OAAO,CAAC;QACtB,SAAS,EAAE,qBAAqB,CAAC;QACjC,gBAAgB,EAAE,MAAM,EAAE,CAAC;QAC3B,aAAa,EAAE,4BAA4B,CAAC;KAC7C,CAAC,CAAC;IACH,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAC7B;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAC/C,OAAO,EAAE,+BAA+B,CAAC,SAAS,CAAC,CAAC;IACpD,KAAK,EAAE,0BAA0B,EAAE,CAAC;CACrC,GAAG,+BAA+B,CAqClC;AAED,wBAAsB,iCAAiC,CAAC,KAAK,EAAE;IAC7D,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,eAAe,EAAE,6BAA6B,CAAC;IAC/C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACrD,GAAG,OAAO,CAAC,+BAA+B,CAAC,CA6B3C;AA2RD,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,MAAM,GAAG,6BAA6B,CAkD1F"}
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import CGModule from '@colbymchenry/codegraph';
|
|
7
|
+
import { createEngines } from '@devflow-tools/mcp-server/composition';
|
|
8
|
+
import { createSamplingEvidenceReranker } from '@devflow-tools/mcp-server/retrieval';
|
|
9
|
+
import { DevFlowDatabase } from '@devflow-tools/database';
|
|
10
|
+
import { RetrievalCoordinator, RetrievalSessionRepository } from '@devflow-tools/retrieval-engine';
|
|
11
|
+
import { resolveTaskSemanticContext } from '@devflow-tools/semantic-engine';
|
|
12
|
+
import { createRuntimeActivationSnapshotV1, evaluationContextStableRef, projectSnapshotId, stableRuntimeJson, } from '@devflow-tools/sdk';
|
|
13
|
+
import { evidenceQualityMetric } from './evidence-quality-metrics.js';
|
|
14
|
+
import { readProjectSnapshotIdentity } from './evaluation-bundle.js';
|
|
15
|
+
import { loadReleaseQualityMaterializationTargets, } from './release-quality-bundle-materializer.js';
|
|
16
|
+
import { createRetrievalQuerySamplingResolver, } from '@devflow-tools/semantic-engine';
|
|
17
|
+
import { captureProducer, identityFor, noOpTaskRuntime, rankedEvidenceRefs, stageCapture, } from './unified-runtime-runner.js';
|
|
18
|
+
const CodeGraph = CGModule.default ?? CGModule;
|
|
19
|
+
const REQUIRED_CASES = new Set([
|
|
20
|
+
'llm-wiki/context/explicit-files',
|
|
21
|
+
'ecc/context/path-safety',
|
|
22
|
+
]);
|
|
23
|
+
const RETRIEVAL_QUERY_TOOL_NAME = 'submit_retrieval_queries';
|
|
24
|
+
const RETRIEVAL_QUERY_TOOL = {
|
|
25
|
+
name: RETRIEVAL_QUERY_TOOL_NAME,
|
|
26
|
+
description: 'Submit evidence-bound retrieval query proposals.',
|
|
27
|
+
input_schema: {
|
|
28
|
+
type: 'object',
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
properties: {
|
|
31
|
+
proposals: {
|
|
32
|
+
type: 'array',
|
|
33
|
+
maxItems: 9,
|
|
34
|
+
items: {
|
|
35
|
+
type: 'object',
|
|
36
|
+
additionalProperties: false,
|
|
37
|
+
properties: {
|
|
38
|
+
channel: { type: 'string', enum: ['code', 'memory', 'knowledge'] },
|
|
39
|
+
kind: { type: 'string', enum: ['rewrite', 'expansion'] },
|
|
40
|
+
query: { type: 'string', maxLength: 2_000 },
|
|
41
|
+
sourceClaimIds: {
|
|
42
|
+
type: 'array',
|
|
43
|
+
maxItems: 32,
|
|
44
|
+
items: { type: 'string' },
|
|
45
|
+
},
|
|
46
|
+
confidence: { type: 'number', minimum: 0, maximum: 1 },
|
|
47
|
+
},
|
|
48
|
+
required: ['channel', 'kind', 'query', 'sourceClaimIds', 'confidence'],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
required: ['proposals'],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const EVIDENCE_RERANK_TOOL_NAME = 'rank_evidence';
|
|
56
|
+
export function evaluateContextExperiment(input) {
|
|
57
|
+
if (input.profile.generation !== 3 || !/^[a-f0-9]{64}$/u.test(input.profile.profileHash)) {
|
|
58
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_PROFILE_INVALID');
|
|
59
|
+
}
|
|
60
|
+
const caseIds = new Set(input.cases.map(item => item.caseId));
|
|
61
|
+
if (caseIds.size !== REQUIRED_CASES.size
|
|
62
|
+
|| [...REQUIRED_CASES].some(caseId => !caseIds.has(caseId))) {
|
|
63
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_CASE_SET_INVALID');
|
|
64
|
+
}
|
|
65
|
+
const cases = input.cases.map(item => {
|
|
66
|
+
const candidates = unique(item.candidateRefs).slice(0, 20);
|
|
67
|
+
const selected = unique(item.selectedRefs).slice(0, 5);
|
|
68
|
+
const gold = unique(item.goldRefs);
|
|
69
|
+
if (gold.length === 0)
|
|
70
|
+
throw new Error(`CONTEXT_SYMBOL_EXPERIMENT_GOLD_MISSING:${item.caseId}`);
|
|
71
|
+
const candidateSet = new Set(candidates);
|
|
72
|
+
const selectedSet = new Set(selected);
|
|
73
|
+
const forbidden = new Set(item.forbiddenRefs);
|
|
74
|
+
return {
|
|
75
|
+
caseId: item.caseId,
|
|
76
|
+
candidateRefs: candidates,
|
|
77
|
+
selectedRefs: selected,
|
|
78
|
+
goldRefs: gold,
|
|
79
|
+
candidateHit: gold.every(ref => candidateSet.has(ref)),
|
|
80
|
+
recallAt5: evidenceQualityMetric(gold.filter(ref => selectedSet.has(ref)).length, gold.length),
|
|
81
|
+
forbiddenRefsAt5: selected.filter(ref => forbidden.has(ref)),
|
|
82
|
+
querySampling: item.querySampling,
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
const hits = cases.filter(item => item.candidateHit && item.forbiddenRefsAt5.length === 0).length;
|
|
86
|
+
return {
|
|
87
|
+
schemaVersion: 'devflow.context-symbol-experiment.v1',
|
|
88
|
+
profile: input.profile,
|
|
89
|
+
cases,
|
|
90
|
+
hits,
|
|
91
|
+
denominator: cases.length,
|
|
92
|
+
status: hits === cases.length ? 'passed' : 'failed',
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export async function runContextSymbolQualityExperiment(input) {
|
|
96
|
+
const requested = new Set(input.caseIds);
|
|
97
|
+
if (requested.size !== REQUIRED_CASES.size
|
|
98
|
+
|| [...REQUIRED_CASES].some(caseId => !requested.has(caseId))) {
|
|
99
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_CASE_SET_INVALID');
|
|
100
|
+
}
|
|
101
|
+
const targets = loadReleaseQualityMaterializationTargets({
|
|
102
|
+
manifestPath: input.manifestPath,
|
|
103
|
+
sourcesRoot: input.sourcesRoot,
|
|
104
|
+
outputRoot: join(tmpdir(), 'devflow-context-symbol-unused'),
|
|
105
|
+
}).filter(target => target.input.requiredSlices.some(slice => slice.channel === 'context' && slice.caseIds.some(caseId => requested.has(caseId))));
|
|
106
|
+
if (targets.length !== 2)
|
|
107
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_TARGETS_INVALID');
|
|
108
|
+
let profile;
|
|
109
|
+
const cases = [];
|
|
110
|
+
for (const target of targets) {
|
|
111
|
+
assertPinnedCheckout(target);
|
|
112
|
+
const result = await runTarget(target, requested, input.samplingAdapter, input.observer);
|
|
113
|
+
profile ??= result.profile;
|
|
114
|
+
if (result.profile.profileHash !== profile.profileHash
|
|
115
|
+
|| result.profile.generation !== profile.generation
|
|
116
|
+
|| result.profile.modelId !== profile.modelId) {
|
|
117
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_PROFILE_MISMATCH');
|
|
118
|
+
}
|
|
119
|
+
cases.push(...result.cases);
|
|
120
|
+
}
|
|
121
|
+
if (!profile)
|
|
122
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_PROFILE_MISSING');
|
|
123
|
+
return evaluateContextExperiment({ profile, cases });
|
|
124
|
+
}
|
|
125
|
+
async function runTarget(target, requested, samplingAdapter, observer) {
|
|
126
|
+
const container = mkdtempSync(join(tmpdir(), 'devflow-context-symbol-'));
|
|
127
|
+
const runtimeRoot = join(container, 'project');
|
|
128
|
+
let engines;
|
|
129
|
+
let operationalDatabase;
|
|
130
|
+
try {
|
|
131
|
+
execFileSync('git', ['clone', '--quiet', '--no-hardlinks', '--no-checkout', target.checkoutPath, runtimeRoot]);
|
|
132
|
+
execFileSync('git', ['-C', runtimeRoot, 'checkout', '--quiet', '--detach', target.input.project.commit]);
|
|
133
|
+
mkdirSync(join(runtimeRoot, '.devflow'), { recursive: true });
|
|
134
|
+
writeFileSync(join(runtimeRoot, '.devflow/config.json'), `${stableRuntimeJson({
|
|
135
|
+
projectId: target.input.project.projectId,
|
|
136
|
+
memoryNamespace: `memory:${target.input.project.projectId}`,
|
|
137
|
+
})}\n`);
|
|
138
|
+
const graph = await CodeGraph.init(runtimeRoot);
|
|
139
|
+
try {
|
|
140
|
+
const indexed = await graph.indexAll();
|
|
141
|
+
if (!indexed.success || graph.getIndexState() !== 'complete') {
|
|
142
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_CODEGRAPH_FAILED');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
graph.close();
|
|
147
|
+
}
|
|
148
|
+
engines = await createEngines(runtimeRoot, { warmSymbolVectors: false });
|
|
149
|
+
if (!engines.symbolEmbedder || !engines.symbolStore) {
|
|
150
|
+
throw new Error('CONTEXT_SYMBOL_VECTOR_RUNTIME_UNAVAILABLE');
|
|
151
|
+
}
|
|
152
|
+
const buildStartedAt = performance.now();
|
|
153
|
+
await engines.symbolEmbedder.buildAll();
|
|
154
|
+
if (!engines.symbolEmbedder.isBuilt())
|
|
155
|
+
throw new Error('CONTEXT_SYMBOL_VECTOR_BUILD_INCOMPLETE');
|
|
156
|
+
const buildDurationMs = Math.round((performance.now() - buildStartedAt) * 1000) / 1000;
|
|
157
|
+
const embeddingProfile = engines.symbolStore.getProfile();
|
|
158
|
+
const profile = experimentProfile(embeddingProfile);
|
|
159
|
+
observer?.({
|
|
160
|
+
stage: 'vector-build',
|
|
161
|
+
projectId: target.input.project.projectId,
|
|
162
|
+
commit: target.input.project.commit,
|
|
163
|
+
tree: target.input.project.tree,
|
|
164
|
+
vectorCount: engines.symbolStore.count(),
|
|
165
|
+
buildDurationMs,
|
|
166
|
+
profile,
|
|
167
|
+
});
|
|
168
|
+
const snapshotId = projectSnapshotId(readProjectSnapshotIdentity(target.checkoutPath));
|
|
169
|
+
const corpus = readJson(target.corpusPath);
|
|
170
|
+
operationalDatabase = new DevFlowDatabase(runtimeRoot, {
|
|
171
|
+
dbPath: join(container, 'operational/devflow.db'),
|
|
172
|
+
});
|
|
173
|
+
const cases = [];
|
|
174
|
+
const retrievalQuerySampling = createRetrievalQuerySamplingResolver(samplingAdapter);
|
|
175
|
+
for (const item of corpus.cases.filter(item => requested.has(item.caseId))) {
|
|
176
|
+
const goldRefs = target.input.context.evidence.map(evidence => {
|
|
177
|
+
const node = engines.codegraph.getNodesInFile(evidence.path)
|
|
178
|
+
.find(candidate => candidate.name === evidence.symbol && candidate.startLine === evidence.startLine);
|
|
179
|
+
if (!node)
|
|
180
|
+
throw new Error(`CONTEXT_SYMBOL_EXPERIMENT_GOLD_NODE_MISSING:${item.caseId}`);
|
|
181
|
+
return evaluationContextStableRef({
|
|
182
|
+
projectSnapshotId: snapshotId,
|
|
183
|
+
normalizedPath: node.filePath,
|
|
184
|
+
symbolId: node.id,
|
|
185
|
+
range: [node.startLine, node.endLine],
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
const identity = identityFor(item.caseId, 'benchmark:context-symbol-experiment', runtimeRoot, target.input.project.projectId);
|
|
189
|
+
const semantic = await resolveTaskSemanticContext({
|
|
190
|
+
normalizedPrompt: item.prompt,
|
|
191
|
+
identity,
|
|
192
|
+
revision: 1,
|
|
193
|
+
activation: createRuntimeActivationSnapshotV1({
|
|
194
|
+
semantic: 'authoritative',
|
|
195
|
+
retrieval: 'authoritative',
|
|
196
|
+
memoryExtraction: 'deferred',
|
|
197
|
+
knowledgeCompilation: 'deferred',
|
|
198
|
+
embeddingProfiles: { code_retrieval: profile.profileHash },
|
|
199
|
+
rolloutPolicyVersion: 'context-symbol-experiment.v1',
|
|
200
|
+
createdAt: 1,
|
|
201
|
+
}),
|
|
202
|
+
router: engines.semanticRouter,
|
|
203
|
+
retrievalQuerySampling: { sample: retrievalQuerySampling },
|
|
204
|
+
policy: {
|
|
205
|
+
policyHash: 'context-symbol-experiment.v1',
|
|
206
|
+
budgets: {
|
|
207
|
+
hookDeadlineMs: 3_000,
|
|
208
|
+
contextTokens: 8_000,
|
|
209
|
+
responseReserveTokens: 2_000,
|
|
210
|
+
perChannelMs: { code: 1_500, memory: 800, knowledge: 1_500 },
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
now: 1,
|
|
214
|
+
});
|
|
215
|
+
const context = semantic.context;
|
|
216
|
+
const queryReceipt = semantic.resolution.providerReceipts
|
|
217
|
+
.find(receipt => receipt.capability === 'retrieval_query');
|
|
218
|
+
if (!queryReceipt)
|
|
219
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_QUERY_RECEIPT_MISSING');
|
|
220
|
+
if (context.plan.code.requirement === 'prohibited') {
|
|
221
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_CODE_PLAN_PROHIBITED');
|
|
222
|
+
}
|
|
223
|
+
const querySampling = {
|
|
224
|
+
status: queryReceipt.status,
|
|
225
|
+
receiptHash: queryReceipt.receiptHash,
|
|
226
|
+
reasonCodes: queryReceipt.reasonCodes,
|
|
227
|
+
proposalCount: queryReceipt.proposalCount,
|
|
228
|
+
acceptedCount: queryReceipt.acceptedCount,
|
|
229
|
+
rejectedCount: queryReceipt.rejectedCount,
|
|
230
|
+
proposals: context.plan.code.additions.map(proposal => ({
|
|
231
|
+
proposalId: proposal.proposalId,
|
|
232
|
+
kind: proposal.kind,
|
|
233
|
+
query: proposal.query,
|
|
234
|
+
})),
|
|
235
|
+
};
|
|
236
|
+
const stage = stageCapture();
|
|
237
|
+
const result = await new RetrievalCoordinator({
|
|
238
|
+
code: captureProducer(engines.codeEvidence, stage),
|
|
239
|
+
memory: captureProducer(engines.memoryQuery, stage),
|
|
240
|
+
knowledge: captureProducer(engines.knowledgeQuery, stage),
|
|
241
|
+
sessions: new RetrievalSessionRepository(operationalDatabase),
|
|
242
|
+
reranker: createSamplingEvidenceReranker(samplingAdapter),
|
|
243
|
+
taskRuntime: noOpTaskRuntime(),
|
|
244
|
+
}).retrieve({ context, taskRevision: 1, tokenBudget: 8_000, now: 1 });
|
|
245
|
+
const candidates = stage.candidates.filter(candidate => candidate.channel === 'code');
|
|
246
|
+
assertVectorCandidateProfiles(candidates, embeddingProfile);
|
|
247
|
+
const producerOutput = stage.outputs.find(output => output.result.receipt.channel === 'code');
|
|
248
|
+
if (!producerOutput)
|
|
249
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_PRODUCER_RECEIPT_MISSING');
|
|
250
|
+
const refByProducerRef = new Map(candidates.map(candidate => [
|
|
251
|
+
candidate.stableRef,
|
|
252
|
+
evaluationRef(snapshotId, candidate),
|
|
253
|
+
]));
|
|
254
|
+
const rankedCandidates = rankedEvidenceRefs(result.receipt, 'context')
|
|
255
|
+
.map(stableRef => candidates.find(candidate => candidate.stableRef === stableRef))
|
|
256
|
+
.filter((candidate) => Boolean(candidate));
|
|
257
|
+
const candidateRefs = unique(rankedCandidates.map(candidate => refByProducerRef.get(candidate.stableRef)));
|
|
258
|
+
const selectedRefs = unique((result.receipt.selectedEvidence ?? [])
|
|
259
|
+
.filter(candidate => candidate.channel === 'code')
|
|
260
|
+
.map(candidate => refByProducerRef.get(candidate.stableRef))
|
|
261
|
+
.filter((ref) => Boolean(ref)));
|
|
262
|
+
observer?.({
|
|
263
|
+
stage: 'retrieval',
|
|
264
|
+
caseId: item.caseId,
|
|
265
|
+
goldRanks: goldRefs.map(ref => candidateRefs.indexOf(ref) + 1 || null),
|
|
266
|
+
vectorGoldRanks: vectorGoldRanks(producerOutput.vectorCandidateRefs ?? [], candidates, snapshotId, goldRefs),
|
|
267
|
+
producerGoldRanks: goldRefs.map(ref => candidateRefs.indexOf(ref) + 1 || null),
|
|
268
|
+
selectedGoldRanks: selectedRefs.map(ref => goldRefs.indexOf(ref) + 1 || null),
|
|
269
|
+
querySampling,
|
|
270
|
+
topCandidates: rankedCandidates.slice(0, 20).map(candidate => ({
|
|
271
|
+
ref: refByProducerRef.get(candidate.stableRef),
|
|
272
|
+
path: candidate.payload.path,
|
|
273
|
+
symbol: candidate.payload.symbol,
|
|
274
|
+
symbolId: candidate.payload.symbolId,
|
|
275
|
+
contributingLegs: candidate.contributingLegs,
|
|
276
|
+
})),
|
|
277
|
+
});
|
|
278
|
+
cases.push({
|
|
279
|
+
caseId: item.caseId,
|
|
280
|
+
candidateRefs,
|
|
281
|
+
selectedRefs,
|
|
282
|
+
goldRefs,
|
|
283
|
+
forbiddenRefs: [],
|
|
284
|
+
querySampling,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
return { profile, cases };
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
operationalDatabase?.close();
|
|
291
|
+
if (engines)
|
|
292
|
+
closeEngines(engines);
|
|
293
|
+
rmSync(container, { recursive: true, force: true });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function vectorGoldRanks(vectorRefs, candidates, snapshotId, goldRefs) {
|
|
297
|
+
const evaluationByProducerRef = new Map(candidates.map(candidate => [
|
|
298
|
+
candidate.stableRef,
|
|
299
|
+
evaluationRef(snapshotId, candidate),
|
|
300
|
+
]));
|
|
301
|
+
return goldRefs.map(gold => {
|
|
302
|
+
const match = vectorRefs.find(item => evaluationByProducerRef.get(item.ref) === gold);
|
|
303
|
+
return match?.rank ?? null;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
function experimentProfile(profile) {
|
|
307
|
+
if (profile.purpose !== 'code_retrieval' || profile.generation !== 3) {
|
|
308
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_PROFILE_INVALID');
|
|
309
|
+
}
|
|
310
|
+
return { profileHash: profile.profileHash, generation: 3, modelId: profile.modelId };
|
|
311
|
+
}
|
|
312
|
+
function assertVectorCandidateProfiles(candidates, profile) {
|
|
313
|
+
for (const candidate of candidates.filter(item => item.contributingLegs.some(leg => /vector|embedding/iu.test(leg.leg)))) {
|
|
314
|
+
if (candidate.retrievalProfile !== profile.profileHash || candidate.generation !== profile.generation) {
|
|
315
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_CANDIDATE_PROFILE_MISMATCH');
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function evaluationRef(snapshotId, candidate) {
|
|
320
|
+
const path = candidate.payload.path;
|
|
321
|
+
const symbolId = candidate.payload.symbolId;
|
|
322
|
+
const startLine = candidate.payload.startLine;
|
|
323
|
+
const endLine = candidate.payload.endLine;
|
|
324
|
+
if (typeof path !== 'string' || typeof symbolId !== 'string'
|
|
325
|
+
|| !Number.isSafeInteger(startLine) || !Number.isSafeInteger(endLine)) {
|
|
326
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_CANDIDATE_IDENTITY_INVALID');
|
|
327
|
+
}
|
|
328
|
+
return evaluationContextStableRef({
|
|
329
|
+
projectSnapshotId: snapshotId,
|
|
330
|
+
normalizedPath: path,
|
|
331
|
+
symbolId,
|
|
332
|
+
range: [startLine, endLine],
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function assertPinnedCheckout(target) {
|
|
336
|
+
if (git(target.checkoutPath, ['rev-parse', 'HEAD']) !== target.input.project.commit
|
|
337
|
+
|| git(target.checkoutPath, ['rev-parse', 'HEAD^{tree}']) !== target.input.project.tree
|
|
338
|
+
|| git(target.checkoutPath, ['status', '--porcelain', '--untracked-files=all']) !== '') {
|
|
339
|
+
throw new Error('CONTEXT_SYMBOL_EXPERIMENT_CHECKOUT_IDENTITY_MISMATCH');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function git(root, args) {
|
|
343
|
+
return execFileSync('git', ['-C', root, ...args], { encoding: 'utf8' }).trim();
|
|
344
|
+
}
|
|
345
|
+
function readJson(path) {
|
|
346
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
347
|
+
}
|
|
348
|
+
function unique(refs) {
|
|
349
|
+
return [...new Set(refs)];
|
|
350
|
+
}
|
|
351
|
+
function closeEngines(engines) {
|
|
352
|
+
engines.context.close();
|
|
353
|
+
engines.memory.close();
|
|
354
|
+
engines.knowledge.close();
|
|
355
|
+
engines.telemetry.close();
|
|
356
|
+
engines.codegraph.close();
|
|
357
|
+
engines.data.close?.();
|
|
358
|
+
}
|
|
359
|
+
function requiredOption(argv, name) {
|
|
360
|
+
const index = argv.indexOf(name);
|
|
361
|
+
const value = index >= 0 ? argv[index + 1] : undefined;
|
|
362
|
+
if (!value)
|
|
363
|
+
throw new Error(`${name} requires a value`);
|
|
364
|
+
return value;
|
|
365
|
+
}
|
|
366
|
+
async function main(argv) {
|
|
367
|
+
const output = resolve(requiredOption(argv, '--output'));
|
|
368
|
+
const report = await runContextSymbolQualityExperiment({
|
|
369
|
+
manifestPath: resolveInputPath(requiredOption(argv, '--manifest')),
|
|
370
|
+
sourcesRoot: resolveInputPath(requiredOption(argv, '--sources')),
|
|
371
|
+
caseIds: requiredOption(argv, '--cases').split(',').filter(Boolean),
|
|
372
|
+
samplingAdapter: createDeepSeekSamplingAdapter(requiredOption(argv, '--sampling-model')),
|
|
373
|
+
observer: event => process.stderr.write(`${stableRuntimeJson(event)}\n`),
|
|
374
|
+
});
|
|
375
|
+
mkdirSync(dirname(output), { recursive: true });
|
|
376
|
+
writeFileSync(output, `${stableRuntimeJson(report)}\n`);
|
|
377
|
+
process.stdout.write(`${stableRuntimeJson(report)}\n`);
|
|
378
|
+
if (report.status !== 'passed')
|
|
379
|
+
process.exitCode = 1;
|
|
380
|
+
}
|
|
381
|
+
export function createDeepSeekSamplingAdapter(model) {
|
|
382
|
+
if (!model.trim())
|
|
383
|
+
throw new Error('--sampling-model requires a value');
|
|
384
|
+
const baseUrl = process.env.DEEPSEEK_BASE_URL?.replace(/\/$/u, '');
|
|
385
|
+
const apiKey = process.env.DEEPSEEK_API_KEY;
|
|
386
|
+
return {
|
|
387
|
+
isSupported: () => Boolean(baseUrl && apiKey),
|
|
388
|
+
createMessage: async (request) => {
|
|
389
|
+
if (!baseUrl || !apiKey)
|
|
390
|
+
throw new Error('DEEPSEEK_SAMPLING_ENV_UNAVAILABLE');
|
|
391
|
+
const reranking = request.systemPrompt.startsWith('You rank retrieved evidence');
|
|
392
|
+
const tool = reranking ? evidenceRerankTool(request.prompt) : RETRIEVAL_QUERY_TOOL;
|
|
393
|
+
const response = await fetch(`${baseUrl}/v1/messages`, {
|
|
394
|
+
method: 'POST',
|
|
395
|
+
headers: {
|
|
396
|
+
'content-type': 'application/json',
|
|
397
|
+
'anthropic-version': '2023-06-01',
|
|
398
|
+
'x-api-key': apiKey,
|
|
399
|
+
},
|
|
400
|
+
body: JSON.stringify({
|
|
401
|
+
model,
|
|
402
|
+
max_tokens: request.maxTokens,
|
|
403
|
+
temperature: 0,
|
|
404
|
+
thinking: { type: 'disabled' },
|
|
405
|
+
system: request.systemPrompt,
|
|
406
|
+
messages: [{ role: 'user', content: request.prompt }],
|
|
407
|
+
tools: [tool],
|
|
408
|
+
tool_choice: { type: 'tool', name: tool.name },
|
|
409
|
+
}),
|
|
410
|
+
signal: AbortSignal.timeout(request.timeoutMs),
|
|
411
|
+
});
|
|
412
|
+
const body = await response.json();
|
|
413
|
+
if (!response.ok) {
|
|
414
|
+
throw new Error(`DEEPSEEK_SAMPLING_HTTP_${response.status}:${String(body.error?.message ?? '')}`);
|
|
415
|
+
}
|
|
416
|
+
const toolOutputs = body.content?.filter(item => item.type === 'tool_use'
|
|
417
|
+
&& item.name === tool.name) ?? [];
|
|
418
|
+
const input = toolOutputs.length === 1 ? toolOutputs[0]?.input : undefined;
|
|
419
|
+
const outputKey = reranking ? 'rankedRefs' : 'proposals';
|
|
420
|
+
if (!isRecord(input) || Object.keys(input).length !== 1 || !Array.isArray(input[outputKey])) {
|
|
421
|
+
throw new Error('DEEPSEEK_SAMPLING_TOOL_OUTPUT_INVALID');
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
text: reranking ? JSON.stringify(input) : JSON.stringify(input.proposals),
|
|
425
|
+
model: typeof body.model === 'string' ? body.model : model,
|
|
426
|
+
};
|
|
427
|
+
},
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
function evidenceRerankTool(prompt) {
|
|
431
|
+
let value;
|
|
432
|
+
try {
|
|
433
|
+
value = JSON.parse(prompt);
|
|
434
|
+
}
|
|
435
|
+
catch {
|
|
436
|
+
throw new Error('DEEPSEEK_RERANK_REQUEST_INVALID');
|
|
437
|
+
}
|
|
438
|
+
if (!isRecord(value) || !Array.isArray(value.candidates)) {
|
|
439
|
+
throw new Error('DEEPSEEK_RERANK_REQUEST_INVALID');
|
|
440
|
+
}
|
|
441
|
+
const rankedRefs = value.candidates.map(candidate => isRecord(candidate) && typeof candidate.stableRef === 'string'
|
|
442
|
+
? candidate.stableRef
|
|
443
|
+
: undefined);
|
|
444
|
+
if (rankedRefs.length === 0 || rankedRefs.length > 20
|
|
445
|
+
|| rankedRefs.some((ref) => ref === undefined)
|
|
446
|
+
|| new Set(rankedRefs).size !== rankedRefs.length) {
|
|
447
|
+
throw new Error('DEEPSEEK_RERANK_REQUEST_INVALID');
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
name: EVIDENCE_RERANK_TOOL_NAME,
|
|
451
|
+
description: 'Rank every supplied evidence ref by direct relevance.',
|
|
452
|
+
input_schema: {
|
|
453
|
+
type: 'object',
|
|
454
|
+
additionalProperties: false,
|
|
455
|
+
properties: {
|
|
456
|
+
rankedRefs: {
|
|
457
|
+
type: 'array',
|
|
458
|
+
minItems: rankedRefs.length,
|
|
459
|
+
maxItems: rankedRefs.length,
|
|
460
|
+
uniqueItems: true,
|
|
461
|
+
items: { type: 'string', enum: rankedRefs },
|
|
462
|
+
},
|
|
463
|
+
},
|
|
464
|
+
required: ['rankedRefs'],
|
|
465
|
+
},
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function isRecord(value) {
|
|
469
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
470
|
+
}
|
|
471
|
+
function resolveInputPath(value) {
|
|
472
|
+
if (value.startsWith('/') || /^[A-Za-z]:[\\/]/u.test(value))
|
|
473
|
+
return resolve(value);
|
|
474
|
+
const fromCwd = resolve(value);
|
|
475
|
+
if (existsSync(fromCwd))
|
|
476
|
+
return fromCwd;
|
|
477
|
+
return resolve(import.meta.dirname, '../../..', value);
|
|
478
|
+
}
|
|
479
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) {
|
|
480
|
+
await main(process.argv.slice(2));
|
|
481
|
+
}
|
|
482
|
+
//# sourceMappingURL=context-symbol-quality-command.js.map
|