@sdsrs/code-graph 0.178.0 → 0.179.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.
|
@@ -28,6 +28,7 @@ const { formatCoveringTests } = require('./covering-tests');
|
|
|
28
28
|
const { emitPreToolContext } = require('./hook-emit');
|
|
29
29
|
const { hidden } = require('./proc-opts');
|
|
30
30
|
const { remainingMs } = require('./hook-fail-open');
|
|
31
|
+
const { definitionHeaders } = require('./stop-impact');
|
|
31
32
|
|
|
32
33
|
// v0.49 — walk up from the shell cwd (subdir-cwd fix). The per-cwd index.db
|
|
33
34
|
// gate kept this hook dark for entire sessions after `cd backend/` — daagu
|
|
@@ -135,19 +136,21 @@ const scanned = oldStr.length > 8192 ? oldStr.slice(0, 8192) : oldStr;
|
|
|
135
136
|
// matches — 0.163.0's rule. Three replacements (the earliest match, then an
|
|
136
137
|
// allow-list of what may precede a method name, then keyword-anchored arms
|
|
137
138
|
// first) each fixed shapes and broke others, and three review rounds found a
|
|
138
|
-
// regression in each (pre-tag review 2026-09-29), so
|
|
139
|
-
//
|
|
139
|
+
// regression in each (pre-tag review 2026-09-29), so this rule still names the
|
|
140
|
+
// pick; the Stop check's per-language reader decides below, where it reads the
|
|
141
|
+
// language, which definition the edit changed.
|
|
140
142
|
//
|
|
141
143
|
// Where the definition starts is its name's line: `// TODO: make this
|
|
142
144
|
// async\nfn f(` matches from the comment line, and the same-file pick below
|
|
143
145
|
// counts lines from here. That moves no name, only the line.
|
|
144
146
|
let symbol = null;
|
|
145
147
|
let symbolAt = -1;
|
|
148
|
+
let nameAt = -1;
|
|
146
149
|
for (const pat of fnPatterns) {
|
|
147
150
|
const m = scanned.match(new RegExp(pat.source, `${pat.flags}d`));
|
|
148
151
|
if (m) {
|
|
149
152
|
symbol = m[1] || m[2];
|
|
150
|
-
|
|
153
|
+
nameAt = (m.indices[1] || m.indices[2])[0];
|
|
151
154
|
symbolAt = Math.max(m.index, scanned.lastIndexOf('\n', nameAt - 1) + 1);
|
|
152
155
|
break;
|
|
153
156
|
}
|
|
@@ -179,7 +182,107 @@ function headerAt(text, at) {
|
|
|
179
182
|
.filter((i) => i >= 0);
|
|
180
183
|
return ends.length ? rest.slice(0, Math.min(...ends)) : rest.split('\n', 1)[0];
|
|
181
184
|
}
|
|
182
|
-
|
|
185
|
+
const bodyOnly = newStr.includes(headerAt(scanned, symbolAt));
|
|
186
|
+
|
|
187
|
+
// Which definition the edit changed, where the Stop check's per-language reader
|
|
188
|
+
// (stop-impact.js LANGS) reads this file: a definition of the hunk whose
|
|
189
|
+
// signature key the new text no longer has. The pick above sent 35 of its 103
|
|
190
|
+
// impact queries for names that are no definition there (a Rust `match f(…)
|
|
191
|
+
// {`, a comment's "function already", a string) and missed 24 changed headers
|
|
192
|
+
// (a later definition, a `{` inside the parameters, an old header still inside
|
|
193
|
+
// the new one), measured on every Edit hunk in this machine's transcripts
|
|
194
|
+
// (tasks/specs/pre-edit-pick-by-reader.md).
|
|
195
|
+
// - a changed definition of the picked name → it, placed where it starts;
|
|
196
|
+
// - the pick's header changed as the first-match rule reads it, and the pick
|
|
197
|
+
// is not proven no definition → the pick, as before. The reader may not
|
|
198
|
+
// see it (a method whose parameters span lines, `#[inline] fn` on one
|
|
199
|
+
// line); where it reads it unchanged, the old reading can have run into
|
|
200
|
+
// the next definition, which 0.178.0 did too;
|
|
201
|
+
// - else the first changed definition, logged for the Stop check too;
|
|
202
|
+
// - else none.
|
|
203
|
+
// The pick is no definition when its line opens a comment that has not closed
|
|
204
|
+
// before it, or, in Rust and Python, when its name does not follow `fn` /
|
|
205
|
+
// `def`. A comment here is not stop-impact.js's COMMENT_LINE, which takes any
|
|
206
|
+
// line opening with `*` or `#`: `*entries(prefix) {` is a JS generator method,
|
|
207
|
+
// `#[inline] pub fn` a Rust definition; a doc comment's `*` is followed by a
|
|
208
|
+
// space, a `/` or the line's end.
|
|
209
|
+
//
|
|
210
|
+
// Only in the extensions of the reader's languages that corpus had hunks in
|
|
211
|
+
// (not C: 2 hunks). Elsewhere the reader misread shapes no hunk there had
|
|
212
|
+
// (pre-tag review of 0.179.0: Kotlin's `fun Config.validate(` reads as
|
|
213
|
+
// `Config`, PHP's `function &name(` has no keyword before the name, a C++
|
|
214
|
+
// statement `Type name(args);` reads as a definition), so the pick keeps its
|
|
215
|
+
// own verdict, as in 0.178.0; so does a hunk the reader has no reading of (a
|
|
216
|
+
// header past its cap).
|
|
217
|
+
const READER_MEASURED = new Set(['.rs', '.py', '.js', '.mjs', '.cjs', '.ts']);
|
|
218
|
+
const OPENS_A_COMMENT = /^\s*(?:\/\/|\/\*|\*(?=\s|\/|$)|#(?!\[)|--|;)/;
|
|
219
|
+
function onComment(line, nameCol) {
|
|
220
|
+
const closed = /^\s*(?:\/\*.*?\*\/\s*)+/.exec(line.slice(0, nameCol));
|
|
221
|
+
return OPENS_A_COMMENT.test(closed ? line.slice(closed[0].length) : line);
|
|
222
|
+
}
|
|
223
|
+
function changedDefinition() {
|
|
224
|
+
const ext = path.extname(editedAbs).toLowerCase();
|
|
225
|
+
const before = READER_MEASURED.has(ext) ? definitionHeaders(oldStr, ext) : null;
|
|
226
|
+
const after = before && definitionHeaders(newStr, ext);
|
|
227
|
+
if (!before || !after) return bodyOnly ? null : { name: symbol, at: symbolAt };
|
|
228
|
+
const count = (defs) => {
|
|
229
|
+
const m = new Map();
|
|
230
|
+
for (const d of defs) m.set(`${d.name}\0${d.key}`, (m.get(`${d.name}\0${d.key}`) || 0) + 1);
|
|
231
|
+
return m;
|
|
232
|
+
};
|
|
233
|
+
const has = count(after.defs);
|
|
234
|
+
const left = new Map(has);
|
|
235
|
+
let changed = [];
|
|
236
|
+
for (const d of before.defs) {
|
|
237
|
+
const k = `${d.name}\0${d.key}`;
|
|
238
|
+
if (left.get(k) > 0) left.set(k, left.get(k) - 1);
|
|
239
|
+
else changed.push(d);
|
|
240
|
+
}
|
|
241
|
+
// The count matches headers, not definitions: of two definitions of one name
|
|
242
|
+
// with one old header, one kept, it marks the later, whichever the edit
|
|
243
|
+
// changed. Such a name's definitions pair in order when the hunk keeps their
|
|
244
|
+
// number and pairing finds as many changed as the count; otherwise which one
|
|
245
|
+
// changed is not in the text (one went or came, or the hunk moved them), and
|
|
246
|
+
// the reader names none of that name (the rule below can still keep the
|
|
247
|
+
// pick).
|
|
248
|
+
const twinned = new Set(changed
|
|
249
|
+
.filter((c) => (has.get(`${c.name}\0${c.key}`) || 0) > 0)
|
|
250
|
+
.map((c) => c.name));
|
|
251
|
+
if (twinned.size) {
|
|
252
|
+
const counted = new Map();
|
|
253
|
+
for (const d of changed) if (twinned.has(d.name)) counted.set(d.name, (counted.get(d.name) || 0) + 1);
|
|
254
|
+
const byName = (defs) => {
|
|
255
|
+
const m = new Map();
|
|
256
|
+
for (const d of defs) if (twinned.has(d.name)) (m.get(d.name) || m.set(d.name, []).get(d.name)).push(d);
|
|
257
|
+
return m;
|
|
258
|
+
};
|
|
259
|
+
const olds = byName(before.defs);
|
|
260
|
+
const news = byName(after.defs);
|
|
261
|
+
changed = changed.filter((d) => !twinned.has(d.name));
|
|
262
|
+
for (const [name, o] of olds) {
|
|
263
|
+
const n = news.get(name) || [];
|
|
264
|
+
const paired = o.length === n.length ? o.filter((d, i) => d.key !== n[i].key) : [];
|
|
265
|
+
if (paired.length === counted.get(name)) changed.push(...paired);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
changed.sort((x, y) => x.at - y.at);
|
|
269
|
+
const same = changed.find((d) => d.name === symbol);
|
|
270
|
+
if (same) return { name: symbol, at: same.at };
|
|
271
|
+
const lineStart = scanned.lastIndexOf('\n', nameAt - 1) + 1;
|
|
272
|
+
const lineEnd = scanned.indexOf('\n', nameAt);
|
|
273
|
+
const pickLine = scanned.slice(lineStart, lineEnd === -1 ? scanned.length : lineEnd);
|
|
274
|
+
const notADefinition = onComment(pickLine, nameAt - lineStart)
|
|
275
|
+
|| (before.keywordOnly && !before.keywordLeads(scanned.slice(lineStart, nameAt)));
|
|
276
|
+
if (!bodyOnly && !notADefinition) return { name: symbol, at: symbolAt };
|
|
277
|
+
return changed.length ? { name: changed[0].name, at: changed[0].at } : null;
|
|
278
|
+
}
|
|
279
|
+
const edited = changedDefinition();
|
|
280
|
+
if (!edited) process.exit(0);
|
|
281
|
+
if (edited.name !== symbol) {
|
|
282
|
+
symbol = edited.name;
|
|
283
|
+
logEdit(symbol);
|
|
284
|
+
}
|
|
285
|
+
symbolAt = edited.at;
|
|
183
286
|
|
|
184
287
|
if (process.env.CODE_GRAPH_QUIET_HOOKS === '1') process.exit(0);
|
|
185
288
|
|
|
@@ -89,12 +89,17 @@ const NOT_A_TYPE = new Set([
|
|
|
89
89
|
// initializers, C# `: base(…)` — body, not signature)
|
|
90
90
|
// closeParen the parameter list's `)` ends it (Ruby, Lua: no return types,
|
|
91
91
|
// and a one-line body may follow on the same line)
|
|
92
|
+
// keywordOnly every function definition's name follows `keyword`, so a
|
|
93
|
+
// name without it is none (pre-edit-guide reads that; Rust and
|
|
94
|
+
// Python only, the languages it was measured on. These rules do not
|
|
95
|
+
// find every such definition: a line opening with `#[` or `/* … */`,
|
|
96
|
+
// a second one on a line)
|
|
92
97
|
const LANGS = new Map();
|
|
93
98
|
function defineLang(exts, profile) {
|
|
94
99
|
for (const e of exts) LANGS.set(e, profile);
|
|
95
100
|
}
|
|
96
|
-
defineLang(['.rs'], { keyword: 'fn', ends: '{;' });
|
|
97
|
-
defineLang(['.py', '.pyi'], { keyword: 'def', ends: ':' });
|
|
101
|
+
defineLang(['.rs'], { keyword: 'fn', ends: '{;', keywordOnly: true });
|
|
102
|
+
defineLang(['.py', '.pyi'], { keyword: 'def', ends: ':', keywordOnly: true });
|
|
98
103
|
defineLang(['.go'], { keyword: 'func', receiver: true, ends: '{;\n' });
|
|
99
104
|
defineLang(['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'],
|
|
100
105
|
{ keyword: 'function\\*?', jsForms: true, ends: '{;', arrowEnds: true, angles: true });
|
|
@@ -110,12 +115,18 @@ function escapeRe(s) {
|
|
|
110
115
|
return String(s).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
111
116
|
}
|
|
112
117
|
|
|
118
|
+
// What comes before a definition's name: the keyword, Go's receiver, Kotlin's
|
|
119
|
+
// type parameters.
|
|
120
|
+
function keywordLead(lang) {
|
|
121
|
+
const receiver = lang.receiver ? '(?:\\([^)\\n]*\\)\\s*)?' : '';
|
|
122
|
+
const typeParams = lang.typeParams ? '(?:<[^>\\n]*>\\s*)?' : '';
|
|
123
|
+
return `\\b(?:${lang.keyword})\\s+${receiver}${typeParams}`;
|
|
124
|
+
}
|
|
125
|
+
|
|
113
126
|
function definitionPatterns(S, lang) {
|
|
114
127
|
const out = [];
|
|
115
128
|
if (lang.keyword) {
|
|
116
|
-
|
|
117
|
-
const typeParams = lang.typeParams ? '(?:<[^>\\n]*>\\s*)?' : '';
|
|
118
|
-
out.push({ re: new RegExp(`\\b(?:${lang.keyword})\\s+${receiver}${typeParams}${S}\\b`, 'g') });
|
|
129
|
+
out.push({ re: new RegExp(`${keywordLead(lang)}${S}\\b`, 'g') });
|
|
119
130
|
}
|
|
120
131
|
if (lang.jsForms) {
|
|
121
132
|
out.push({ re: new RegExp(`\\b(?:const|let|var)\\s+${S}\\s*=\\s*(?:async\\s+)?(?:function\\b|\\([^)\\n]*\\)\\s*=>|[A-Za-z_$][\\w$]*\\s*=>)`, 'g') });
|
|
@@ -183,6 +194,40 @@ function allSignatures(text, ext = '') {
|
|
|
183
194
|
return out;
|
|
184
195
|
}
|
|
185
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Every definition in `text`, in text order, with the line it starts on and
|
|
199
|
+
* its signature key (as allSignatures reads it) — for pre-edit-guide, which
|
|
200
|
+
* must tell which of a hunk's definitions an edit changed and where it sits.
|
|
201
|
+
* `keywordOnly` (LANGS) with `keywordLeads`, which tests the text before a
|
|
202
|
+
* name on its line: where both hold, a name it is false for is no definition.
|
|
203
|
+
* null when there is no exact reading of the whole text: the language is not
|
|
204
|
+
* in LANGS, a definition sits on an over-long line, or any header has no
|
|
205
|
+
* reading.
|
|
206
|
+
* @returns {{ defs: {name:string, at:number, key:string}[], keywordOnly: boolean,
|
|
207
|
+
* keywordLeads: (before: string) => boolean }|null}
|
|
208
|
+
*/
|
|
209
|
+
function definitionHeaders(text, ext = '') {
|
|
210
|
+
const lang = LANGS.get(String(ext).toLowerCase());
|
|
211
|
+
if (!lang || typeof text !== 'string') return null;
|
|
212
|
+
const starts = definitionStarts(text, lang, ANY_NAME, null);
|
|
213
|
+
if (starts === null) return null;
|
|
214
|
+
const defs = [];
|
|
215
|
+
for (const [name, lineStarts] of starts) {
|
|
216
|
+
for (const at of lineStarts) {
|
|
217
|
+
const header = readHeader(text, at, lang);
|
|
218
|
+
if (header === null) return null;
|
|
219
|
+
defs.push({ name, at, key: signatureKey(header) });
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
defs.sort((x, y) => x.at - y.at);
|
|
223
|
+
const lead = lang.keyword ? new RegExp(`${keywordLead(lang)}$`) : null;
|
|
224
|
+
return {
|
|
225
|
+
defs,
|
|
226
|
+
keywordOnly: lang.keywordOnly === true,
|
|
227
|
+
keywordLeads: (before) => lead !== null && lead.test(before),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
186
231
|
/**
|
|
187
232
|
* Where definitions start: Map name → Set of line-start offsets. With `symbol`
|
|
188
233
|
* the patterns carry it escaped in `S`; without, `S` is ANY_NAME and the name
|
|
@@ -670,6 +715,6 @@ function runMain() {
|
|
|
670
715
|
if (require.main === module) runMain();
|
|
671
716
|
|
|
672
717
|
module.exports = {
|
|
673
|
-
extractSignatures, allSignatures, signatureChanged, findCallSiteLine, computeStopReport, formatStopContext,
|
|
718
|
+
extractSignatures, allSignatures, definitionHeaders, signatureChanged, findCallSiteLine, computeStopReport, formatStopContext,
|
|
674
719
|
followUpOf, reportRecords, MAX_SYMBOLS_CHECKED, MAX_CALLERS_LISTED, MAX_FOLLOWUP_FILES,
|
|
675
720
|
};
|
|
@@ -41,7 +41,7 @@ jobs:
|
|
|
41
41
|
# refuses a snapshot that has no checksum sidecar.
|
|
42
42
|
- name: Build snapshot
|
|
43
43
|
run: |
|
|
44
|
-
npx -y -p @sdsrs/code-graph@0.
|
|
44
|
+
npx -y -p @sdsrs/code-graph@0.179.0 code-graph-mcp snapshot create --out "code-graph-snapshot-${GITHUB_SHA:0:7}.db.zst"
|
|
45
45
|
- name: Upload to release
|
|
46
46
|
env:
|
|
47
47
|
GH_TOKEN: ${{ github.token }}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdsrs/code-graph",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.179.0",
|
|
4
4
|
"description": "MCP server that indexes codebases into an AST knowledge graph with semantic search, call graph traversal, and HTTP route tracing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"node": ">=16"
|
|
36
36
|
},
|
|
37
37
|
"optionalDependencies": {
|
|
38
|
-
"@sdsrs/code-graph-linux-x64": "0.
|
|
39
|
-
"@sdsrs/code-graph-linux-arm64": "0.
|
|
40
|
-
"@sdsrs/code-graph-darwin-x64": "0.
|
|
41
|
-
"@sdsrs/code-graph-darwin-arm64": "0.
|
|
42
|
-
"@sdsrs/code-graph-win32-x64": "0.
|
|
38
|
+
"@sdsrs/code-graph-linux-x64": "0.179.0",
|
|
39
|
+
"@sdsrs/code-graph-linux-arm64": "0.179.0",
|
|
40
|
+
"@sdsrs/code-graph-darwin-x64": "0.179.0",
|
|
41
|
+
"@sdsrs/code-graph-darwin-arm64": "0.179.0",
|
|
42
|
+
"@sdsrs/code-graph-win32-x64": "0.179.0"
|
|
43
43
|
}
|
|
44
44
|
}
|