context-pilot-engine 0.2.0 → 0.4.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/dist/engine.d.ts +11 -64
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +110 -204
- package/dist/engine.js.map +1 -0
- package/dist/graph/graph.js.map +1 -0
- package/dist/history/backtest.d.ts +127 -0
- package/dist/history/backtest.d.ts.map +1 -0
- package/dist/history/backtest.js +290 -0
- package/dist/history/backtest.js.map +1 -0
- package/dist/history/cochange.d.ts +91 -0
- package/dist/history/cochange.d.ts.map +1 -0
- package/dist/history/cochange.js +149 -0
- package/dist/history/cochange.js.map +1 -0
- package/dist/history/diff.d.ts +21 -0
- package/dist/history/diff.d.ts.map +1 -0
- package/dist/history/diff.js +57 -0
- package/dist/history/diff.js.map +1 -0
- package/dist/history/git.d.ts +34 -0
- package/dist/history/git.d.ts.map +1 -0
- package/dist/history/git.js +92 -0
- package/dist/history/git.js.map +1 -0
- package/dist/history/miner.d.ts +9 -0
- package/dist/history/miner.d.ts.map +1 -0
- package/dist/history/miner.js +70 -0
- package/dist/history/miner.js.map +1 -0
- package/dist/impact/impact.d.ts +55 -0
- package/dist/impact/impact.d.ts.map +1 -0
- package/dist/impact/impact.js +139 -0
- package/dist/impact/impact.js.map +1 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -0
- package/dist/indexer/chunker.d.ts +9 -6
- package/dist/indexer/chunker.d.ts.map +1 -1
- package/dist/indexer/chunker.js +46 -11
- package/dist/indexer/chunker.js.map +1 -0
- package/dist/indexer/imports.d.ts +24 -0
- package/dist/indexer/imports.d.ts.map +1 -0
- package/dist/indexer/imports.js +138 -0
- package/dist/indexer/imports.js.map +1 -0
- package/dist/indexer/indexer.d.ts +15 -0
- package/dist/indexer/indexer.d.ts.map +1 -1
- package/dist/indexer/indexer.js +55 -59
- package/dist/indexer/indexer.js.map +1 -0
- package/dist/indexer/languages.d.ts +2 -2
- package/dist/indexer/languages.d.ts.map +1 -1
- package/dist/indexer/languages.js +10 -0
- package/dist/indexer/languages.js.map +1 -0
- package/dist/storage/schema.js +87 -87
- package/dist/storage/schema.js.map +1 -0
- package/dist/storage/sqlite.d.ts +34 -27
- package/dist/storage/sqlite.d.ts.map +1 -1
- package/dist/storage/sqlite.js +126 -153
- package/dist/storage/sqlite.js.map +1 -0
- package/dist/types.d.ts +86 -97
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -0
- package/package.json +24 -10
- package/dist/embedder/embedder.d.ts +0 -4
- package/dist/embedder/embedder.d.ts.map +0 -1
- package/dist/embedder/embedder.js +0 -37
- package/dist/engine.test.d.ts +0 -2
- package/dist/engine.test.d.ts.map +0 -1
- package/dist/engine.test.js +0 -9
- package/dist/search/search.d.ts +0 -12
- package/dist/search/search.d.ts.map +0 -1
- package/dist/search/search.js +0 -38
- package/src/embedder/embedder.ts +0 -46
- package/src/engine.ts +0 -425
- package/src/graph/graph.ts +0 -136
- package/src/index.ts +0 -15
- package/src/indexer/chunker.ts +0 -115
- package/src/indexer/indexer.ts +0 -297
- package/src/indexer/languages.ts +0 -55
- package/src/search/search.ts +0 -48
- package/src/storage/schema.ts +0 -92
- package/src/storage/sqlite.ts +0 -353
- package/src/types.ts +0 -137
- package/tsconfig.json +0 -19
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { type GitCommit } from "./git.js";
|
|
2
|
+
import { type CombineMethod } from "./cochange.js";
|
|
3
|
+
import type { ImportEdge } from "../indexer/imports.js";
|
|
4
|
+
export declare const DEFAULT_TEST_COMMITS = 200;
|
|
5
|
+
export declare const DEFAULT_TRAIN_COMMITS = 5000;
|
|
6
|
+
export declare const DEFAULT_BACKTEST_KS: number[];
|
|
7
|
+
export interface BacktestOptions {
|
|
8
|
+
/** Newest N commits are the test set; everything older is training (default 200) */
|
|
9
|
+
testCommits?: number;
|
|
10
|
+
/** Cut-offs for precision/recall/hit-rate (default [5, 10]) */
|
|
11
|
+
ks?: number[];
|
|
12
|
+
/**
|
|
13
|
+
* Files per query. 1 (default): every file of a test commit is queried on its own.
|
|
14
|
+
* q > 1: the first q files of the commit (git order) are queried together.
|
|
15
|
+
*/
|
|
16
|
+
queryFiles?: number;
|
|
17
|
+
minSupport?: number;
|
|
18
|
+
minConfidence?: number;
|
|
19
|
+
combine?: CombineMethod;
|
|
20
|
+
shrinkage?: number;
|
|
21
|
+
/** true (default): each test commit is added to the model after being evaluated */
|
|
22
|
+
walkForward?: boolean;
|
|
23
|
+
maxFilesPerCommit?: number;
|
|
24
|
+
ignore?: (path: string) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Import graph to combine with co-changes (impact scoring). It is the graph
|
|
27
|
+
* as of today, not as of each test commit: a mild leak, fine for comparing
|
|
28
|
+
* configurations but slightly optimistic in absolute terms.
|
|
29
|
+
*/
|
|
30
|
+
graph?: {
|
|
31
|
+
edges: ImportEdge[];
|
|
32
|
+
files: string[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Also report how predictions behave per strongest-signal weight, the value
|
|
36
|
+
* `check` thresholds on. Uses the same queries as the metrics.
|
|
37
|
+
*/
|
|
38
|
+
calibrate?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface CalibrationBucket {
|
|
41
|
+
/** Strongest-signal weight range [min, max) (the last bucket includes 1) */
|
|
42
|
+
min: number;
|
|
43
|
+
max: number;
|
|
44
|
+
predictions: number;
|
|
45
|
+
/** Predictions that were really part of the commit */
|
|
46
|
+
hits: number;
|
|
47
|
+
precision: number;
|
|
48
|
+
}
|
|
49
|
+
export interface CalibrationThreshold {
|
|
50
|
+
threshold: number;
|
|
51
|
+
/** Predictions whose strongest signal is >= threshold */
|
|
52
|
+
alerts: number;
|
|
53
|
+
hits: number;
|
|
54
|
+
precision: number;
|
|
55
|
+
/** Share of evaluated commits with at least one alert */
|
|
56
|
+
commitsAlerted: number;
|
|
57
|
+
/** Share of evaluated commits with at least one correct alert */
|
|
58
|
+
commitsWithHit: number;
|
|
59
|
+
}
|
|
60
|
+
export interface CalibrationReport {
|
|
61
|
+
buckets: CalibrationBucket[];
|
|
62
|
+
thresholds: CalibrationThreshold[];
|
|
63
|
+
}
|
|
64
|
+
export interface BacktestMetrics {
|
|
65
|
+
k: number;
|
|
66
|
+
/** Mean of hits / |top k|, over queries that returned at least one prediction */
|
|
67
|
+
precision: number;
|
|
68
|
+
/** Mean of hits / |rest of the commit| */
|
|
69
|
+
recall: number;
|
|
70
|
+
/** Share of queries with at least one hit in the top k */
|
|
71
|
+
hitRate: number;
|
|
72
|
+
}
|
|
73
|
+
export interface BacktestReport {
|
|
74
|
+
options: {
|
|
75
|
+
testCommits: number;
|
|
76
|
+
queryFiles: number;
|
|
77
|
+
minSupport: number;
|
|
78
|
+
minConfidence: number;
|
|
79
|
+
combine: CombineMethod;
|
|
80
|
+
shrinkage: number;
|
|
81
|
+
walkForward: boolean;
|
|
82
|
+
ks: number[];
|
|
83
|
+
withGraph: boolean;
|
|
84
|
+
};
|
|
85
|
+
headSha?: string;
|
|
86
|
+
trainCommits: number;
|
|
87
|
+
testCommits: number;
|
|
88
|
+
/** Test commits with enough eligible files to be evaluated */
|
|
89
|
+
evaluatedCommits: number;
|
|
90
|
+
skipped: {
|
|
91
|
+
bulk: number;
|
|
92
|
+
tooFewFiles: number;
|
|
93
|
+
};
|
|
94
|
+
queries: number;
|
|
95
|
+
/** Evaluated commits where at least one eligible file had history */
|
|
96
|
+
coverage: number;
|
|
97
|
+
/** Queries that returned at least one prediction */
|
|
98
|
+
answered: number;
|
|
99
|
+
/** Metrics are averaged per commit first, then across commits */
|
|
100
|
+
metrics: BacktestMetrics[];
|
|
101
|
+
calibration?: CalibrationReport;
|
|
102
|
+
}
|
|
103
|
+
/** Strongest signal of each prediction, and whether it was really in the commit. */
|
|
104
|
+
type ScoredPrediction = {
|
|
105
|
+
weight: number;
|
|
106
|
+
hit: boolean;
|
|
107
|
+
};
|
|
108
|
+
export declare function calibrationReport(perCommit: ScoredPrediction[][]): CalibrationReport;
|
|
109
|
+
/**
|
|
110
|
+
* Replays history to measure how well co-changes predict the rest of a commit.
|
|
111
|
+
* Pure: `commits` newest-first (git log order). Each test commit is predicted from
|
|
112
|
+
* strictly older commits only, using the paths as they were before that commit.
|
|
113
|
+
* Files added by a test commit can never be predicted from history, so they are
|
|
114
|
+
* excluded from both queries and targets.
|
|
115
|
+
*/
|
|
116
|
+
export declare function backtestCoChanges(commits: GitCommit[], options?: BacktestOptions): BacktestReport;
|
|
117
|
+
/**
|
|
118
|
+
* Backtests a repository's history. Read-only: only runs `git rev-parse` and
|
|
119
|
+
* `git log` (plus reading source files with `withGraph`), and touches neither
|
|
120
|
+
* the working tree nor the context-pilot database.
|
|
121
|
+
*/
|
|
122
|
+
export declare function backtestRepo(projectPath: string, options?: BacktestOptions & {
|
|
123
|
+
maxTrainCommits?: number;
|
|
124
|
+
withGraph?: boolean;
|
|
125
|
+
}): Promise<BacktestReport>;
|
|
126
|
+
export {};
|
|
127
|
+
//# sourceMappingURL=backtest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backtest.d.ts","sourceRoot":"","sources":["../../src/history/backtest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAWL,KAAK,aAAa,EAGnB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C,MAAM,WAAW,eAAe;IAC9B,oFAAoF;IACpF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,EAAE,CAAC,EAAE,MAAM,EA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AO,GAAE,eAAe,GAAG;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAO,GAChF,OAAO,CAAC,cAAc,CAAC,CAYzB"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { headSha, isGitRepo, readGitLog } from "./git.js";
|
|
2
|
+
import { combineCoChanges, commitWeight, defaultIgnore, DEFAULT_MAX_FILES_PER_COMMIT, DEFAULT_MIN_CONFIDENCE, DEFAULT_MIN_SUPPORT, DEFAULT_SHRINKAGE, mineCommits, pairKey, } from "./cochange.js";
|
|
3
|
+
import { computeImpact } from "../impact/impact.js";
|
|
4
|
+
import { scanImportGraph } from "../indexer/indexer.js";
|
|
5
|
+
export const DEFAULT_TEST_COMMITS = 200;
|
|
6
|
+
export const DEFAULT_TRAIN_COMMITS = 5000;
|
|
7
|
+
export const DEFAULT_BACKTEST_KS = [5, 10];
|
|
8
|
+
/** Mutable co-change model used while walking forward through the test commits. */
|
|
9
|
+
class Model {
|
|
10
|
+
files;
|
|
11
|
+
adj = new Map();
|
|
12
|
+
dead = new Set();
|
|
13
|
+
constructor(files, pairs, dead) {
|
|
14
|
+
this.files = files;
|
|
15
|
+
this.dead = dead;
|
|
16
|
+
for (const p of pairs)
|
|
17
|
+
this.link(p);
|
|
18
|
+
}
|
|
19
|
+
link(p) {
|
|
20
|
+
for (const [a, b] of [[p.fileA, p.fileB], [p.fileB, p.fileA]]) {
|
|
21
|
+
let m = this.adj.get(a);
|
|
22
|
+
if (!m)
|
|
23
|
+
this.adj.set(a, (m = new Map()));
|
|
24
|
+
m.set(b, p);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
predict(sources, opts) {
|
|
28
|
+
const known = sources.filter((s) => this.files.has(s));
|
|
29
|
+
const sourceSet = new Set(sources);
|
|
30
|
+
const rows = known.flatMap((source) => [...(this.adj.get(source) ?? [])].map(([candidate, p]) => ({
|
|
31
|
+
source,
|
|
32
|
+
candidate,
|
|
33
|
+
support: p.support,
|
|
34
|
+
wsupport: p.wsupport,
|
|
35
|
+
lastTs: p.lastTs,
|
|
36
|
+
}))).filter((r) => !sourceSet.has(r.candidate) && !this.dead.has(r.candidate));
|
|
37
|
+
return combineCoChanges(rows, this.files, { ...opts, sourceCount: known.length });
|
|
38
|
+
}
|
|
39
|
+
/** Moves all history of `from` to `to`, as the miner does for renames. */
|
|
40
|
+
rename(from, to) {
|
|
41
|
+
const fs = this.files.get(from);
|
|
42
|
+
if (fs) {
|
|
43
|
+
this.files.delete(from);
|
|
44
|
+
const existing = this.files.get(to);
|
|
45
|
+
if (existing) {
|
|
46
|
+
existing.commits += fs.commits;
|
|
47
|
+
existing.wcommits += fs.wcommits;
|
|
48
|
+
existing.lastTs = Math.max(existing.lastTs, fs.lastTs);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.files.set(to, { ...fs, path: to });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const partners = this.adj.get(from);
|
|
55
|
+
if (!partners)
|
|
56
|
+
return;
|
|
57
|
+
this.adj.delete(from);
|
|
58
|
+
for (const [partner, p] of partners) {
|
|
59
|
+
this.adj.get(partner)?.delete(from);
|
|
60
|
+
if (partner === to)
|
|
61
|
+
continue;
|
|
62
|
+
const [a, b] = pairKey(to, partner);
|
|
63
|
+
const existing = this.adj.get(to)?.get(partner);
|
|
64
|
+
if (existing) {
|
|
65
|
+
existing.support += p.support;
|
|
66
|
+
existing.wsupport += p.wsupport;
|
|
67
|
+
existing.lastTs = Math.max(existing.lastTs, p.lastTs);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.link({ ...p, fileA: a, fileB: b });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
add(paths, timestamp) {
|
|
75
|
+
const w = commitWeight(timestamp);
|
|
76
|
+
for (const path of paths) {
|
|
77
|
+
const s = this.files.get(path);
|
|
78
|
+
if (s) {
|
|
79
|
+
s.commits++;
|
|
80
|
+
s.wcommits += w;
|
|
81
|
+
s.lastTs = Math.max(s.lastTs, timestamp);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.files.set(path, { path, commits: 1, wcommits: w, lastTs: timestamp });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (let i = 0; i < paths.length; i++) {
|
|
88
|
+
for (let j = i + 1; j < paths.length; j++) {
|
|
89
|
+
const p = this.adj.get(paths[i])?.get(paths[j]);
|
|
90
|
+
if (p) {
|
|
91
|
+
p.support++;
|
|
92
|
+
p.wsupport += w;
|
|
93
|
+
p.lastTs = Math.max(p.lastTs, timestamp);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const [a, b] = pairKey(paths[i], paths[j]);
|
|
97
|
+
this.link({ fileA: a, fileB: b, support: 1, wsupport: w, lastTs: timestamp });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Files deleted (or renamed away) as of the newest commit of a newest-first list. */
|
|
104
|
+
function deadFiles(commitsNewestFirst) {
|
|
105
|
+
const dead = new Set();
|
|
106
|
+
for (let i = commitsNewestFirst.length - 1; i >= 0; i--)
|
|
107
|
+
applyLifecycle(dead, commitsNewestFirst[i]);
|
|
108
|
+
return dead;
|
|
109
|
+
}
|
|
110
|
+
function applyLifecycle(dead, commit) {
|
|
111
|
+
for (const f of commit.files) {
|
|
112
|
+
if (f.status === "D")
|
|
113
|
+
dead.add(f.path);
|
|
114
|
+
else
|
|
115
|
+
dead.delete(f.path);
|
|
116
|
+
if (f.status === "R" && f.oldPath && f.oldPath !== f.path)
|
|
117
|
+
dead.add(f.oldPath);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const CALIBRATION_STEPS = 10;
|
|
121
|
+
const bucketOf = (w) => Math.min(CALIBRATION_STEPS - 1, Math.max(0, Math.floor(w * CALIBRATION_STEPS + 1e-9)));
|
|
122
|
+
export function calibrationReport(perCommit) {
|
|
123
|
+
const ratio = (a, b) => (b === 0 ? NaN : a / b);
|
|
124
|
+
const buckets = Array.from({ length: CALIBRATION_STEPS }, (_, i) => ({ predictions: 0, hits: 0, i }));
|
|
125
|
+
for (const p of perCommit.flat()) {
|
|
126
|
+
const b = buckets[bucketOf(p.weight)];
|
|
127
|
+
b.predictions++;
|
|
128
|
+
if (p.hit)
|
|
129
|
+
b.hits++;
|
|
130
|
+
}
|
|
131
|
+
const n = perCommit.length;
|
|
132
|
+
return {
|
|
133
|
+
buckets: buckets.map((b) => ({
|
|
134
|
+
min: b.i / CALIBRATION_STEPS,
|
|
135
|
+
max: (b.i + 1) / CALIBRATION_STEPS,
|
|
136
|
+
predictions: b.predictions,
|
|
137
|
+
hits: b.hits,
|
|
138
|
+
precision: ratio(b.hits, b.predictions),
|
|
139
|
+
})),
|
|
140
|
+
thresholds: Array.from({ length: CALIBRATION_STEPS - 1 }, (_, i) => {
|
|
141
|
+
const step = i + 1;
|
|
142
|
+
const t = step / CALIBRATION_STEPS;
|
|
143
|
+
const above = (p) => bucketOf(p.weight) >= step;
|
|
144
|
+
const kept = buckets.slice(step);
|
|
145
|
+
const alerts = kept.reduce((a, b) => a + b.predictions, 0);
|
|
146
|
+
const hits = kept.reduce((a, b) => a + b.hits, 0);
|
|
147
|
+
return {
|
|
148
|
+
threshold: t,
|
|
149
|
+
alerts,
|
|
150
|
+
hits,
|
|
151
|
+
precision: ratio(hits, alerts),
|
|
152
|
+
commitsAlerted: ratio(perCommit.filter((c) => c.some(above)).length, n),
|
|
153
|
+
commitsWithHit: ratio(perCommit.filter((c) => c.some((p) => p.hit && above(p))).length, n),
|
|
154
|
+
};
|
|
155
|
+
}),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const mean = (xs) => (xs.length === 0 ? 0 : xs.reduce((a, b) => a + b, 0) / xs.length);
|
|
159
|
+
/**
|
|
160
|
+
* Replays history to measure how well co-changes predict the rest of a commit.
|
|
161
|
+
* Pure: `commits` newest-first (git log order). Each test commit is predicted from
|
|
162
|
+
* strictly older commits only, using the paths as they were before that commit.
|
|
163
|
+
* Files added by a test commit can never be predicted from history, so they are
|
|
164
|
+
* excluded from both queries and targets.
|
|
165
|
+
*/
|
|
166
|
+
export function backtestCoChanges(commits, options = {}) {
|
|
167
|
+
const testCount = Math.min(options.testCommits ?? DEFAULT_TEST_COMMITS, commits.length);
|
|
168
|
+
const ks = options.ks ?? DEFAULT_BACKTEST_KS;
|
|
169
|
+
const queryFiles = Math.max(1, options.queryFiles ?? 1);
|
|
170
|
+
const scoring = {
|
|
171
|
+
minSupport: options.minSupport ?? DEFAULT_MIN_SUPPORT,
|
|
172
|
+
minConfidence: options.minConfidence ?? DEFAULT_MIN_CONFIDENCE,
|
|
173
|
+
combine: options.combine ?? "noisy-or",
|
|
174
|
+
shrinkage: options.shrinkage ?? DEFAULT_SHRINKAGE,
|
|
175
|
+
};
|
|
176
|
+
const walkForward = options.walkForward ?? true;
|
|
177
|
+
const maxFiles = options.maxFilesPerCommit ?? DEFAULT_MAX_FILES_PER_COMMIT;
|
|
178
|
+
const ignore = options.ignore ?? defaultIgnore;
|
|
179
|
+
const test = commits.slice(0, testCount).reverse();
|
|
180
|
+
const train = commits.slice(testCount);
|
|
181
|
+
const mined = mineCommits(train, { maxFilesPerCommit: maxFiles, ignore });
|
|
182
|
+
const model = new Model(mined.files, mined.pairs.values(), deadFiles(train));
|
|
183
|
+
const skipped = { bulk: 0, tooFewFiles: 0 };
|
|
184
|
+
const calibration = [];
|
|
185
|
+
const perCommit = [];
|
|
186
|
+
for (const commit of test) {
|
|
187
|
+
const touched = commit.files.filter((f) => f.status !== "D" && !ignore(f.path));
|
|
188
|
+
const bulk = touched.length === 0 || touched.length > maxFiles;
|
|
189
|
+
if (bulk) {
|
|
190
|
+
skipped.bulk++;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
// Paths as the model knows them: before this commit's own renames
|
|
194
|
+
const eligible = [
|
|
195
|
+
...new Set(touched.filter((f) => f.status !== "A").map((f) => (f.status === "R" && f.oldPath) || f.path)),
|
|
196
|
+
];
|
|
197
|
+
const queries = queryFiles === 1 ? eligible.map((f) => [f]) : eligible.length > queryFiles ? [eligible.slice(0, queryFiles)] : [];
|
|
198
|
+
if (eligible.length < 2 || queries.length === 0) {
|
|
199
|
+
skipped.tooFewFiles++;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const scored = [];
|
|
203
|
+
const results = queries.map((q) => {
|
|
204
|
+
const targets = new Set(eligible.filter((f) => !q.includes(f)));
|
|
205
|
+
const coChanges = model.predict(q, scoring);
|
|
206
|
+
const impact = options.graph || options.calibrate
|
|
207
|
+
? computeImpact({
|
|
208
|
+
changed: q,
|
|
209
|
+
coChanges,
|
|
210
|
+
imports: options.graph?.edges ?? [],
|
|
211
|
+
files: options.graph?.files ?? [],
|
|
212
|
+
}).filter((r) => !model.dead.has(r.path))
|
|
213
|
+
: undefined;
|
|
214
|
+
const predicted = options.graph ? impact.map((r) => r.path) : coChanges.map((r) => r.path);
|
|
215
|
+
// As `check` does: threshold on the strongest single signal, not the combined score
|
|
216
|
+
if (impact)
|
|
217
|
+
for (const r of impact)
|
|
218
|
+
scored.push({ weight: r.signals[0]?.weight ?? 0, hit: targets.has(r.path) });
|
|
219
|
+
return ks.map((k) => {
|
|
220
|
+
const top = predicted.slice(0, k);
|
|
221
|
+
const hits = top.filter((p) => targets.has(p)).length;
|
|
222
|
+
return { k, answered: top.length > 0, precision: top.length ? hits / top.length : 0, recall: hits / targets.size, hit: hits > 0 };
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
calibration.push(scored);
|
|
226
|
+
perCommit.push({
|
|
227
|
+
covered: eligible.some((f) => model.files.has(f)),
|
|
228
|
+
queries: queries.length,
|
|
229
|
+
answered: results.filter((r) => r[0].answered).length,
|
|
230
|
+
byK: ks.map((k, i) => {
|
|
231
|
+
const rs = results.map((r) => r[i]);
|
|
232
|
+
const answered = rs.filter((r) => r.answered);
|
|
233
|
+
return {
|
|
234
|
+
k,
|
|
235
|
+
precision: answered.length ? mean(answered.map((r) => r.precision)) : NaN,
|
|
236
|
+
recall: mean(rs.map((r) => r.recall)),
|
|
237
|
+
hitRate: mean(rs.map((r) => (r.hit ? 1 : 0))),
|
|
238
|
+
};
|
|
239
|
+
}),
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (walkForward) {
|
|
244
|
+
for (const f of commit.files) {
|
|
245
|
+
if (f.status === "R" && f.oldPath && f.oldPath !== f.path)
|
|
246
|
+
model.rename(f.oldPath, f.path);
|
|
247
|
+
}
|
|
248
|
+
applyLifecycle(model.dead, commit);
|
|
249
|
+
if (!bulk)
|
|
250
|
+
model.add([...new Set(touched.map((f) => f.path))], commit.timestamp);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
options: { testCommits: testCount, queryFiles, ...scoring, walkForward, ks, withGraph: !!options.graph },
|
|
255
|
+
trainCommits: train.length,
|
|
256
|
+
testCommits: test.length,
|
|
257
|
+
evaluatedCommits: perCommit.length,
|
|
258
|
+
skipped,
|
|
259
|
+
queries: perCommit.reduce((a, c) => a + c.queries, 0),
|
|
260
|
+
coverage: mean(perCommit.map((c) => (c.covered ? 1 : 0))),
|
|
261
|
+
answered: perCommit.reduce((a, c) => a + c.answered, 0),
|
|
262
|
+
metrics: ks.map((k, i) => ({
|
|
263
|
+
k,
|
|
264
|
+
precision: mean(perCommit.map((c) => c.byK[i].precision).filter((x) => !Number.isNaN(x))),
|
|
265
|
+
recall: mean(perCommit.map((c) => c.byK[i].recall)),
|
|
266
|
+
hitRate: mean(perCommit.map((c) => c.byK[i].hitRate)),
|
|
267
|
+
})),
|
|
268
|
+
calibration: options.calibrate ? calibrationReport(calibration) : undefined,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Backtests a repository's history. Read-only: only runs `git rev-parse` and
|
|
273
|
+
* `git log` (plus reading source files with `withGraph`), and touches neither
|
|
274
|
+
* the working tree nor the context-pilot database.
|
|
275
|
+
*/
|
|
276
|
+
export async function backtestRepo(projectPath, options = {}) {
|
|
277
|
+
if (!(await isGitRepo(projectPath)))
|
|
278
|
+
throw new Error(`Not a git repository: ${projectPath}`);
|
|
279
|
+
const head = await headSha(projectPath);
|
|
280
|
+
if (!head)
|
|
281
|
+
throw new Error(`Repository has no commits: ${projectPath}`);
|
|
282
|
+
const testCommits = options.testCommits ?? DEFAULT_TEST_COMMITS;
|
|
283
|
+
const commits = await readGitLog(projectPath, {
|
|
284
|
+
range: head,
|
|
285
|
+
maxCommits: testCommits + (options.maxTrainCommits ?? DEFAULT_TRAIN_COMMITS),
|
|
286
|
+
});
|
|
287
|
+
const graph = options.withGraph ? await scanImportGraph(projectPath) : options.graph;
|
|
288
|
+
return { ...backtestCoChanges(commits, { ...options, graph }), headSha: head };
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=backtest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backtest.js","sourceRoot":"","sources":["../../src/history/backtest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAkB,MAAM,UAAU,CAAC;AAC1E,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,4BAA4B,EAC5B,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,OAAO,GAKR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACxC,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAC1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAA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,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACrF,OAAO,EAAE,GAAG,iBAAiB,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACjF,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { GitCommit } from "./git.js";
|
|
2
|
+
/**
|
|
3
|
+
* Recency weighting: a commit's weight doubles every HALF_LIFE seconds, measured
|
|
4
|
+
* from a fixed epoch. Because the reference point is fixed, weights stored today
|
|
5
|
+
* stay comparable with weights added by later incremental runs, and ratios
|
|
6
|
+
* (confidence) never need re-normalizing.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DECAY_EPOCH = 1600000000;
|
|
9
|
+
export declare const HALF_LIFE_SECONDS: number;
|
|
10
|
+
export declare function commitWeight(timestamp: number): number;
|
|
11
|
+
export interface FileStats {
|
|
12
|
+
path: string;
|
|
13
|
+
commits: number;
|
|
14
|
+
wcommits: number;
|
|
15
|
+
lastTs: number;
|
|
16
|
+
}
|
|
17
|
+
export interface PairStats {
|
|
18
|
+
fileA: string;
|
|
19
|
+
fileB: string;
|
|
20
|
+
support: number;
|
|
21
|
+
wsupport: number;
|
|
22
|
+
lastTs: number;
|
|
23
|
+
}
|
|
24
|
+
export interface MineOptions {
|
|
25
|
+
/** Commits touching more files than this (after ignores) are bulk changes: skipped */
|
|
26
|
+
maxFilesPerCommit?: number;
|
|
27
|
+
ignore?: (path: string) => boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface MineResult {
|
|
30
|
+
files: Map<string, FileStats>;
|
|
31
|
+
pairs: Map<string, PairStats>;
|
|
32
|
+
commitsProcessed: number;
|
|
33
|
+
commitsSkipped: number;
|
|
34
|
+
renames: number;
|
|
35
|
+
}
|
|
36
|
+
export declare const DEFAULT_MAX_FILES_PER_COMMIT = 30;
|
|
37
|
+
/** Calibrated with `context-pilot backtest` (see CLAUDE.md) */
|
|
38
|
+
export declare const DEFAULT_MIN_SUPPORT = 1;
|
|
39
|
+
export declare const DEFAULT_MIN_CONFIDENCE = 0.1;
|
|
40
|
+
/**
|
|
41
|
+
* Pseudo-commits added to a source file's history when computing confidence:
|
|
42
|
+
* confidence = raw * n / (n + shrinkage). Keeps "1 of 1 commits" from scoring 100%.
|
|
43
|
+
*/
|
|
44
|
+
export declare const DEFAULT_SHRINKAGE = 1;
|
|
45
|
+
export declare function defaultIgnore(path: string): boolean;
|
|
46
|
+
export declare function pairKey(a: string, b: string): [string, string, string];
|
|
47
|
+
/**
|
|
48
|
+
* Aggregates per-file and per-pair co-change statistics.
|
|
49
|
+
* `commits` must be ordered newest-first (git log order): renames are resolved
|
|
50
|
+
* so that older commits are attributed to the file's current name.
|
|
51
|
+
*/
|
|
52
|
+
export declare function mineCommits(commits: GitCommit[], opts?: MineOptions): MineResult;
|
|
53
|
+
export interface CoChangeSource {
|
|
54
|
+
file: string;
|
|
55
|
+
support: number;
|
|
56
|
+
/** Recency-weighted P(candidate changes | source changes) */
|
|
57
|
+
confidence: number;
|
|
58
|
+
sourceCommits: number;
|
|
59
|
+
}
|
|
60
|
+
export type CombineMethod = "noisy-or" | "max" | "mean";
|
|
61
|
+
export interface CoChangeResult {
|
|
62
|
+
path: string;
|
|
63
|
+
/** Per-source confidences combined (noisy-OR by default), in [0,1] */
|
|
64
|
+
score: number;
|
|
65
|
+
support: number;
|
|
66
|
+
lastChangedTogether: number;
|
|
67
|
+
sources: CoChangeSource[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Combines evidence from several changed files. With noisy-OR (default) a candidate
|
|
71
|
+
* that co-changes with many of them scores higher than one tied to a single file.
|
|
72
|
+
* `mean` averages over `sourceCount` query files (default: distinct sources in `rows`),
|
|
73
|
+
* so sources without a link to the candidate count as 0.
|
|
74
|
+
*/
|
|
75
|
+
export declare function combineCoChanges(rows: Array<{
|
|
76
|
+
source: string;
|
|
77
|
+
candidate: string;
|
|
78
|
+
support: number;
|
|
79
|
+
wsupport: number;
|
|
80
|
+
lastTs: number;
|
|
81
|
+
}>, sourceStats: Map<string, {
|
|
82
|
+
commits: number;
|
|
83
|
+
wcommits: number;
|
|
84
|
+
}>, opts: {
|
|
85
|
+
minSupport: number;
|
|
86
|
+
minConfidence: number;
|
|
87
|
+
combine?: CombineMethod;
|
|
88
|
+
sourceCount?: number;
|
|
89
|
+
shrinkage?: number;
|
|
90
|
+
}): CoChangeResult[];
|
|
91
|
+
//# sourceMappingURL=cochange.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cochange.d.ts","sourceRoot":"","sources":["../../src/history/cochange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;;GAKG;AACH,eAAO,MAAM,WAAW,aAAgB,CAAC;AACzC,eAAO,MAAM,iBAAiB,QAAkB,CAAC;AAEjD,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,sFAAsF;IACtF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,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