@quolu/lattice 0.43.0 → 0.44.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/package.json +4 -2
- package/sensor/dist/bin/lattice-sensor.js +14 -0
- package/sensor/dist/db/index.d.ts +114 -0
- package/sensor/dist/db/index.d.ts.map +1 -1
- package/sensor/dist/db/index.js +235 -7
- package/sensor/dist/db/index.js.map +1 -1
- package/sensor/dist/db/queries.d.ts +26 -4
- package/sensor/dist/db/queries.d.ts.map +1 -1
- package/sensor/dist/db/queries.js +72 -10
- package/sensor/dist/db/queries.js.map +1 -1
- package/sensor/dist/db/wal-valve.d.ts +15 -2
- package/sensor/dist/db/wal-valve.d.ts.map +1 -1
- package/sensor/dist/db/wal-valve.js +88 -6
- package/sensor/dist/db/wal-valve.js.map +1 -1
- package/sensor/dist/extraction/extraction-version.d.ts +1 -1
- package/sensor/dist/extraction/extraction-version.d.ts.map +1 -1
- package/sensor/dist/extraction/extraction-version.js +5 -1
- package/sensor/dist/extraction/extraction-version.js.map +1 -1
- package/sensor/dist/extraction/function-ref.d.ts.map +1 -1
- package/sensor/dist/extraction/function-ref.js +6 -0
- package/sensor/dist/extraction/function-ref.js.map +1 -1
- package/sensor/dist/extraction/grammars.d.ts.map +1 -1
- package/sensor/dist/extraction/grammars.js +46 -0
- package/sensor/dist/extraction/grammars.js.map +1 -1
- package/sensor/dist/extraction/index.d.ts +11 -1
- package/sensor/dist/extraction/index.d.ts.map +1 -1
- package/sensor/dist/extraction/index.js +50 -11
- package/sensor/dist/extraction/index.js.map +1 -1
- package/sensor/dist/extraction/kernel/decode.d.ts.map +1 -1
- package/sensor/dist/extraction/kernel/decode.js +9 -3
- package/sensor/dist/extraction/kernel/decode.js.map +1 -1
- package/sensor/dist/extraction/kernel/index.d.ts +2 -0
- package/sensor/dist/extraction/kernel/index.d.ts.map +1 -1
- package/sensor/dist/extraction/kernel/index.js +122 -8
- package/sensor/dist/extraction/kernel/index.js.map +1 -1
- package/sensor/dist/extraction/kernel/layout.d.ts +10 -1
- package/sensor/dist/extraction/kernel/layout.d.ts.map +1 -1
- package/sensor/dist/extraction/kernel/layout.js +11 -2
- package/sensor/dist/extraction/kernel/layout.js.map +1 -1
- package/sensor/dist/extraction/kernel/loader.d.ts +42 -0
- package/sensor/dist/extraction/kernel/loader.d.ts.map +1 -1
- package/sensor/dist/extraction/kernel/loader.js.map +1 -1
- package/sensor/dist/extraction/languages/c-cpp.d.ts +13 -0
- package/sensor/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/sensor/dist/extraction/languages/c-cpp.js +809 -13
- package/sensor/dist/extraction/languages/c-cpp.js.map +1 -1
- package/sensor/dist/extraction/store-worker.js +29 -0
- package/sensor/dist/extraction/store-worker.js.map +1 -1
- package/sensor/dist/extraction/tree-sitter.d.ts +4 -1
- package/sensor/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/sensor/dist/extraction/tree-sitter.js +20 -4
- package/sensor/dist/extraction/tree-sitter.js.map +1 -1
- package/sensor/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
- package/sensor/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
- package/sensor/dist/index.d.ts +3 -1
- package/sensor/dist/index.d.ts.map +1 -1
- package/sensor/dist/index.js +31 -7
- package/sensor/dist/index.js.map +1 -1
- package/sensor/dist/mcp/index.d.ts +24 -0
- package/sensor/dist/mcp/index.d.ts.map +1 -1
- package/sensor/dist/mcp/index.js +51 -2
- package/sensor/dist/mcp/index.js.map +1 -1
- package/sensor/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/sensor/dist/mcp/liveness-watchdog.js +3 -1
- package/sensor/dist/mcp/liveness-watchdog.js.map +1 -1
- package/sensor/dist/mcp/server-instructions.d.ts +1 -1
- package/sensor/dist/mcp/server-instructions.d.ts.map +1 -1
- package/sensor/dist/mcp/server-instructions.js +1 -0
- package/sensor/dist/mcp/server-instructions.js.map +1 -1
- package/sensor/dist/mcp/tools.d.ts +48 -0
- package/sensor/dist/mcp/tools.d.ts.map +1 -1
- package/sensor/dist/mcp/tools.js +231 -4
- package/sensor/dist/mcp/tools.js.map +1 -1
- package/sensor/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/sensor/dist/resolution/c-fnptr-synthesizer.js +561 -127
- package/sensor/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/sensor/dist/resolution/callback-synthesizer.d.ts +1 -1
- package/sensor/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/sensor/dist/resolution/callback-synthesizer.js +80 -11
- package/sensor/dist/resolution/callback-synthesizer.js.map +1 -1
- package/sensor/dist/resolution/import-resolver.d.ts.map +1 -1
- package/sensor/dist/resolution/import-resolver.js +34 -2
- package/sensor/dist/resolution/import-resolver.js.map +1 -1
- package/sensor/dist/resolution/index.d.ts +34 -0
- package/sensor/dist/resolution/index.d.ts.map +1 -1
- package/sensor/dist/resolution/index.js +393 -51
- package/sensor/dist/resolution/index.js.map +1 -1
- package/sensor/dist/resolution/memory-budget.d.ts +48 -0
- package/sensor/dist/resolution/memory-budget.d.ts.map +1 -0
- package/sensor/dist/resolution/memory-budget.js +162 -0
- package/sensor/dist/resolution/memory-budget.js.map +1 -0
- package/sensor/dist/resolution/name-matcher.d.ts +4 -7
- package/sensor/dist/resolution/name-matcher.d.ts.map +1 -1
- package/sensor/dist/resolution/name-matcher.js +256 -91
- package/sensor/dist/resolution/name-matcher.js.map +1 -1
- package/sensor/dist/resolution/resolver-pool.d.ts +41 -1
- package/sensor/dist/resolution/resolver-pool.d.ts.map +1 -1
- package/sensor/dist/resolution/resolver-pool.js +103 -3
- package/sensor/dist/resolution/resolver-pool.js.map +1 -1
- package/sensor/dist/resolution/resolver-worker.js +27 -0
- package/sensor/dist/resolution/resolver-worker.js.map +1 -1
- package/sensor/dist/sync/watcher.d.ts +8 -1
- package/sensor/dist/sync/watcher.d.ts.map +1 -1
- package/sensor/dist/sync/watcher.js +44 -2
- package/sensor/dist/sync/watcher.js.map +1 -1
- package/sensor/dist/types.d.ts +3 -0
- package/sensor/dist/types.d.ts.map +1 -1
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* burn tokens. ADR 0049 / 0059 require the eight compatibility tools to remain
|
|
16
16
|
* visible by default; provider identity is Lattice regardless of their names.
|
|
17
17
|
*/
|
|
18
|
-
export declare const SERVER_INSTRUCTIONS = "# Lattice sensor \u2014 code intelligence over an indexed knowledge graph\n\nProvider identity: lattice. The lattice_sensor_* names below are compatibility tool names served by Lattice's own bundled sensor; they do not call or require the independent Lattice sensor product.\n\nLattice sensor is a SQLite knowledge graph of every symbol, edge, and file in\nthe workspace \u2014 pre-computed structure you would otherwise re-derive by\nreading files (cached intelligence: thousands of parse/trace decisions you\ndon't pay to re-reason each run). Reads are sub-millisecond; the index lags\nwrites by ~1s through the file watcher. Reach for it BEFORE *and* while\nwriting or editing code \u2014 not just for questions: one call returns the\nverbatim source PLUS who calls it and what it affects, so you edit with the\nblast radius in view. More accurate context, in far fewer tokens and\nround-trips than reading files yourself.\n\n## One tool: lattice_sensor_explore \u2014 use it instead of reading files\n\nThere is a single tool, `lattice_sensor_explore`, and it is Read-equivalent. It\ntakes either a natural-language question or a bag of symbol/file names and\nreturns the **verbatim, line-numbered source** of the relevant symbols\ngrouped by file \u2014 the same `<n>\\t<line>` shape `Read` gives you, safe to\n`Edit` from \u2014 PLUS the call path among them (including dynamic-dispatch hops\nlike callbacks, React re-render, and JSX children that grep can't follow) and\na blast-radius summary of what depends on them.\n\nWhether you're answering \"how does X work\" or implementing a change (fixing a\nbug, adding a feature), call `lattice_sensor_explore` before you Read. ONE call\nusually answers the whole question. Lattice sensor IS the pre-built search index \u2014\nso running your own grep + read loop, or delegating the lookup to a separate\nfile-reading sub-task/agent, repeats work lattice sensor already did and costs more\nfor the same answer. A direct lattice sensor answer is typically one to a few\ncalls; a grep/read exploration is dozens.\n\n## How to query\n\n- **Almost any question \u2014 \"how does X work\", architecture, a bug, \"what/where is X\", or surveying an area** \u2192 `lattice_sensor_explore` with a natural-language question or the relevant names. ONE capped call returns the verbatim source grouped by file; most often the ONLY call you need.\n- **\"How does X reach/become Y? / the flow / the path from X to Y\"** \u2192 `lattice_sensor_explore`, naming the symbols that span the flow (e.g. `mutateElement renderScene`) \u2014 it surfaces the call path among them, riding dynamic-dispatch hops, and returns their source.\n- **Reading or editing a file/symbol you can name** \u2192 put its name or file path in the `lattice_sensor_explore` query \u2014 it returns that current line-numbered source (safe to `Edit` from) with the call path and blast radius attached, so you don't Read it separately. For an overloaded name it returns every matching definition's body in one call.\n- **Need more?** Call `lattice_sensor_explore` again with more specific names \u2014 treat the source it returns as already Read.\n\n## Anti-patterns\n\n- **Trust lattice sensor's results \u2014 don't re-verify them with grep.** They come from a full AST parse; re-checking with grep is slower, less accurate, and wastes context.\n- **Don't grep or Read first** to find or understand indexed code \u2014 ONE `lattice_sensor_explore` returns the relevant symbols' source together in a single round-trip. Reach for raw `Read`/`Grep` only to confirm a specific detail lattice sensor didn't cover, or for what lattice sensor doesn't index (configs, docs).\n- **Don't reconstruct a flow by hand** \u2014 name the endpoints in one `lattice_sensor_explore` and it surfaces the path between them, dynamic-dispatch hops included.\n- **After editing, check the staleness banner.** When a tool response starts with \"\u26A0\uFE0F Some files referenced below were edited since the last index sync\u2026\", the listed files are pending re-index \u2014 Read those specific files for accurate content. Every file NOT in that banner is fresh, so still trust lattice sensor. A different, rarer banner \u2014 \"\u26A0\uFE0F LatticeSensor auto-sync is DISABLED\u2026\" \u2014 means live watching stopped entirely (the whole index is frozen, not just a few files); until it's resolved, Read files directly to confirm anything that may have changed.\n\n## Limitations\n\n- If a project isn't indexed (no `.lattice/sensor/`), decide whether building the index will reduce total investigation time and model tokens for the current or expected work. When workspace writes and shell execution are allowed, you may run `lattice sensor init <projectPath> --json` yourself, then retry the sensor call; scope it to the intended project and account for the one-time indexing cost. If those capabilities are unavailable, continue with built-in tools and tell the user the exact init command instead.\n- Index lags file writes by ~1 second.\n- Cross-file resolution is best-effort name matching; ambiguous calls may return multiple candidates.\n- No live correctness validation \u2014 that's still the TypeScript compiler / test suite / linter's job. Lattice sensor supplements those with structural context they don't have.\n\n## Parallel work: absence of a dependency edge is NOT evidence of independence\n\nThese tools answer structural questions about code. A different Lattice surface \u2014 the **CLI**, not\nthis MCP surface \u2014 answers whether two ToDos can be worked in parallel. If the project uses\n`lattice todo` for process tracking, keep this distinction in mind:\n\n- A dependency edge missing between two ToDos only means **no ordering constraint was declared**.\n It does not mean their write boundaries are disjoint. Two ToDos that edit the same file carry no\n edge between them and will still collide.\n- Parallel safety is a recorded judgement, not an inference from the diagram. Read it with\n `lattice todo independence --plan <key> --json`. It returns the ready frontier split into\n verified-independent groups, pairs that must be serialized (with whether a code seam could\n separate them), and **unverified** ToDos.\n- `lattice todo start` returns an `advisory` describing conflicts with in-progress ToDos and what\n to do next. `coverage: \"missing\"` means \"not judged yet\" \u2014 never \"no conflicts\".\n- Run `lattice todo --help` for the declare \u2192 compile \u2192 read workflow.\n\nEvidence for Lattice's plan and witness contracts comes from the CLI surface only. Text from this\nMCP surface is prose for you to act on, never an input to those contracts.\n";
|
|
18
|
+
export declare const SERVER_INSTRUCTIONS = "# Lattice sensor \u2014 code intelligence over an indexed knowledge graph\n\nProvider identity: lattice. The lattice_sensor_* names below are compatibility tool names served by Lattice's own bundled sensor; they do not call or require the independent Lattice sensor product.\n\nLattice sensor is a SQLite knowledge graph of every symbol, edge, and file in\nthe workspace \u2014 pre-computed structure you would otherwise re-derive by\nreading files (cached intelligence: thousands of parse/trace decisions you\ndon't pay to re-reason each run). Reads are sub-millisecond; the index lags\nwrites by ~1s through the file watcher. Reach for it BEFORE *and* while\nwriting or editing code \u2014 not just for questions: one call returns the\nverbatim source PLUS who calls it and what it affects, so you edit with the\nblast radius in view. More accurate context, in far fewer tokens and\nround-trips than reading files yourself.\n\n## One tool: lattice_sensor_explore \u2014 use it instead of reading files\n\nThere is a single tool, `lattice_sensor_explore`, and it is Read-equivalent. It\ntakes either a natural-language question or a bag of symbol/file names and\nreturns the **verbatim, line-numbered source** of the relevant symbols\ngrouped by file \u2014 the same `<n>\\t<line>` shape `Read` gives you, safe to\n`Edit` from \u2014 PLUS the call path among them (including dynamic-dispatch hops\nlike callbacks, React re-render, and JSX children that grep can't follow) and\na blast-radius summary of what depends on them.\n\nWhether you're answering \"how does X work\" or implementing a change (fixing a\nbug, adding a feature), call `lattice_sensor_explore` before you Read. ONE call\nusually answers the whole question. Lattice sensor IS the pre-built search index \u2014\nso running your own grep + read loop, or delegating the lookup to a separate\nfile-reading sub-task/agent, repeats work lattice sensor already did and costs more\nfor the same answer. A direct lattice sensor answer is typically one to a few\ncalls; a grep/read exploration is dozens.\n\n## How to query\n\n- **Almost any question \u2014 \"how does X work\", architecture, a bug, \"what/where is X\", or surveying an area** \u2192 `lattice_sensor_explore` with a natural-language question or the relevant names. ONE capped call returns the verbatim source grouped by file; most often the ONLY call you need.\n- **\"How does X reach/become Y? / the flow / the path from X to Y\"** \u2192 `lattice_sensor_explore`, naming the symbols that span the flow (e.g. `mutateElement renderScene`) \u2014 it surfaces the call path among them, riding dynamic-dispatch hops, and returns their source.\n- **Reading or editing a file/symbol you can name** \u2192 put its name or file path in the `lattice_sensor_explore` query \u2014 it returns that current line-numbered source (safe to `Edit` from) with the call path and blast radius attached, so you don't Read it separately. For an overloaded name it returns every matching definition's body in one call.\n- **Need more?** Call `lattice_sensor_explore` again with more specific names \u2014 treat the source it returns as already Read.\n\n## Anti-patterns\n\n- **Trust lattice sensor's results \u2014 don't re-verify them with grep.** They come from a full AST parse; re-checking with grep is slower, less accurate, and wastes context.\n- **Don't grep or Read first** to find or understand indexed code \u2014 ONE `lattice_sensor_explore` returns the relevant symbols' source together in a single round-trip. Reach for raw `Read`/`Grep` only to confirm a specific detail lattice sensor didn't cover, or for what lattice sensor doesn't index (configs, docs).\n- **Don't reconstruct a flow by hand** \u2014 name the endpoints in one `lattice_sensor_explore` and it surfaces the path between them, dynamic-dispatch hops included.\n- **After editing, check the staleness banner.** When a tool response starts with \"\u26A0\uFE0F Some files referenced below were edited since the last index sync\u2026\", the listed files are pending re-index \u2014 Read those specific files for accurate content. Every file NOT in that banner is fresh, so still trust lattice sensor. A different, rarer banner \u2014 \"\u26A0\uFE0F LatticeSensor auto-sync is DISABLED\u2026\" \u2014 means live watching stopped entirely (the whole index is frozen, not just a few files); until it's resolved, Read files directly to confirm anything that may have changed.\n- **A file flagged \"\u26A0 changed on disk after the last index sync\" drifted from its index** (most common on projects queried via `projectPath`, which have no live watcher). LatticeSensor never serves a possibly-mis-sliced body from such a file \u2014 it either shows the file's full CURRENT source (trust it as a Read) or omits the source with this flag. When the source was omitted, Read that specific file; line numbers referencing it elsewhere in the response may be shifted until that project's next sync. All unflagged files remain trustworthy.\n\n## Limitations\n\n- If a project isn't indexed (no `.lattice/sensor/`), decide whether building the index will reduce total investigation time and model tokens for the current or expected work. When workspace writes and shell execution are allowed, you may run `lattice sensor init <projectPath> --json` yourself, then retry the sensor call; scope it to the intended project and account for the one-time indexing cost. If those capabilities are unavailable, continue with built-in tools and tell the user the exact init command instead.\n- Index lags file writes by ~1 second.\n- Cross-file resolution is best-effort name matching; ambiguous calls may return multiple candidates.\n- No live correctness validation \u2014 that's still the TypeScript compiler / test suite / linter's job. Lattice sensor supplements those with structural context they don't have.\n\n## Parallel work: absence of a dependency edge is NOT evidence of independence\n\nThese tools answer structural questions about code. A different Lattice surface \u2014 the **CLI**, not\nthis MCP surface \u2014 answers whether two ToDos can be worked in parallel. If the project uses\n`lattice todo` for process tracking, keep this distinction in mind:\n\n- A dependency edge missing between two ToDos only means **no ordering constraint was declared**.\n It does not mean their write boundaries are disjoint. Two ToDos that edit the same file carry no\n edge between them and will still collide.\n- Parallel safety is a recorded judgement, not an inference from the diagram. Read it with\n `lattice todo independence --plan <key> --json`. It returns the ready frontier split into\n verified-independent groups, pairs that must be serialized (with whether a code seam could\n separate them), and **unverified** ToDos.\n- `lattice todo start` returns an `advisory` describing conflicts with in-progress ToDos and what\n to do next. `coverage: \"missing\"` means \"not judged yet\" \u2014 never \"no conflicts\".\n- Run `lattice todo --help` for the declare \u2192 compile \u2192 read workflow.\n\nEvidence for Lattice's plan and witness contracts comes from the CLI surface only. Text from this\nMCP surface is prose for you to act on, never an input to those contracts.\n";
|
|
19
19
|
/**
|
|
20
20
|
* Instructions variant sent when the server's own root has NO lattice sensor index.
|
|
21
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-instructions.d.ts","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"server-instructions.d.ts","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,0lOAyE/B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iCAAiC,yhDAsB7C,CAAC"}
|
|
@@ -63,6 +63,7 @@ calls; a grep/read exploration is dozens.
|
|
|
63
63
|
- **Don't grep or Read first** to find or understand indexed code — ONE \`lattice_sensor_explore\` returns the relevant symbols' source together in a single round-trip. Reach for raw \`Read\`/\`Grep\` only to confirm a specific detail lattice sensor didn't cover, or for what lattice sensor doesn't index (configs, docs).
|
|
64
64
|
- **Don't reconstruct a flow by hand** — name the endpoints in one \`lattice_sensor_explore\` and it surfaces the path between them, dynamic-dispatch hops included.
|
|
65
65
|
- **After editing, check the staleness banner.** When a tool response starts with "⚠️ Some files referenced below were edited since the last index sync…", the listed files are pending re-index — Read those specific files for accurate content. Every file NOT in that banner is fresh, so still trust lattice sensor. A different, rarer banner — "⚠️ LatticeSensor auto-sync is DISABLED…" — means live watching stopped entirely (the whole index is frozen, not just a few files); until it's resolved, Read files directly to confirm anything that may have changed.
|
|
66
|
+
- **A file flagged "⚠ changed on disk after the last index sync" drifted from its index** (most common on projects queried via \`projectPath\`, which have no live watcher). LatticeSensor never serves a possibly-mis-sliced body from such a file — it either shows the file's full CURRENT source (trust it as a Read) or omits the source with this flag. When the source was omitted, Read that specific file; line numbers referencing it elsewhere in the response may be shifted until that project's next sync. All unflagged files remain trustworthy.
|
|
66
67
|
|
|
67
68
|
## Limitations
|
|
68
69
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-instructions.js","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,mBAAmB,GAAG
|
|
1
|
+
{"version":3,"file":"server-instructions.js","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyElC,CAAC;AAEF;;;;;;;;;;;GAWG;AACU,QAAA,iCAAiC,GAAG;;;;;;;;;;;;;;;;;;;;;;CAsBhD,CAAC"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type LatticeSensor from '../index';
|
|
7
7
|
import type { QueryPool } from './query-pool';
|
|
8
|
+
export declare function __setLoadLatticeSensorForTests(cls: typeof import('../index').default | null): void;
|
|
8
9
|
import type { PendingFile } from '../sync';
|
|
9
10
|
/**
|
|
10
11
|
* An expected, recoverable "lattice sensor can't serve this" condition — most
|
|
@@ -377,6 +378,32 @@ export declare class ToolHandler {
|
|
|
377
378
|
* Cost when nothing is pending — the common case — is one boolean check.
|
|
378
379
|
* No I/O, no parsing of markdown beyond a per-pending-file substring scan.
|
|
379
380
|
*/
|
|
381
|
+
private driftCache;
|
|
382
|
+
private static readonly DRIFT_TTL_MS;
|
|
383
|
+
/**
|
|
384
|
+
* On-disk drift check for a single indexed file (issue #1474). The code
|
|
385
|
+
* renderers slice CURRENT bytes at INDEXED line ranges; when the file
|
|
386
|
+
* changed after its last index sync those ranges can point at a DIFFERENT
|
|
387
|
+
* symbol's code — served under the requested name with `isError: false`.
|
|
388
|
+
* The watcher-based pending/degraded banners can't cover this for a
|
|
389
|
+
* project reached via `projectPath` (cross-project instances have no
|
|
390
|
+
* watcher, by construction), so freshness is verified here, at the point
|
|
391
|
+
* of emission, from data the index already stores.
|
|
392
|
+
*
|
|
393
|
+
* Cheap and precise: one stat() per file (size + mtime, the same
|
|
394
|
+
* comparison the sync fast path uses); only on a stat mismatch is the
|
|
395
|
+
* content hashed (sha256, matching extraction's `hashContent`) so a
|
|
396
|
+
* touch/checkout that rewrote identical bytes never false-positives.
|
|
397
|
+
* Results are memoized briefly so one response rendering the same file in
|
|
398
|
+
* several sections pays for the check once.
|
|
399
|
+
*
|
|
400
|
+
* Returns true when the on-disk file differs from what was indexed —
|
|
401
|
+
* i.e. indexed line ranges for it are NOT trustworthy. Any failure
|
|
402
|
+
* (missing files-table row, stat/read error) reports false: those cases
|
|
403
|
+
* are handled by the existing not-found paths, and a wrong "stale" flag
|
|
404
|
+
* would needlessly push the agent back to Read.
|
|
405
|
+
*/
|
|
406
|
+
private isFileStaleOnDisk;
|
|
380
407
|
private withStalenessNotice;
|
|
381
408
|
/**
|
|
382
409
|
* Execute a tool by name
|
|
@@ -501,6 +528,14 @@ export declare class ToolHandler {
|
|
|
501
528
|
* qualify so a leaf-only exploration stays clean.
|
|
502
529
|
*/
|
|
503
530
|
private buildBlastRadiusSection;
|
|
531
|
+
/**
|
|
532
|
+
* Test-coverage note for a blast-radius entry whose DIRECT callers include no
|
|
533
|
+
* test file. A helper called only by production code can still be exercised
|
|
534
|
+
* by tests further up the caller chain (#1475: 40% of directly-unflagged
|
|
535
|
+
* symbols had a test within 2-3 hops), so walk up to 2 more hops before
|
|
536
|
+
* claiming anything — and even then claim only what was measured.
|
|
537
|
+
*/
|
|
538
|
+
private indirectTestNote;
|
|
504
539
|
/**
|
|
505
540
|
* Graph-connectivity relevance via Random-Walk-with-Restart (personalized
|
|
506
541
|
* PageRank) from the query's matched SEED nodes over the call/reference graph.
|
|
@@ -550,6 +585,19 @@ export declare class ToolHandler {
|
|
|
550
585
|
private handleFileView;
|
|
551
586
|
/** Render one symbol: details + (optional) body/outline + its caller/callee trail. */
|
|
552
587
|
private renderNodeSection;
|
|
588
|
+
private static readonly STALE_WHOLE_FILE_MAX_LINES;
|
|
589
|
+
private static readonly STALE_WHOLE_FILE_MAX_CHARS;
|
|
590
|
+
/**
|
|
591
|
+
* lattice_sensor_node render for a symbol whose file changed on disk after the
|
|
592
|
+
* last index sync (issue #1474). The indexed line range is no longer
|
|
593
|
+
* trustworthy, so no slice is emitted: a small file gets its full CURRENT
|
|
594
|
+
* source (Read-parity — sufficiency preserved, the agent still doesn't need
|
|
595
|
+
* Read); a large one gets an explicit notice steering to the tool's own
|
|
596
|
+
* file-read mode (or Read) — honest absence instead of confident wrongness.
|
|
597
|
+
* Location/signature stay (they're the index's answer) but are flagged as
|
|
598
|
+
* possibly shifted.
|
|
599
|
+
*/
|
|
600
|
+
private renderStaleNodeSection;
|
|
553
601
|
/**
|
|
554
602
|
* Build the "trail" for a symbol: its direct callees (what it calls) and
|
|
555
603
|
* callers (what calls it), each with file:line — so lattice_sensor_node doubles as
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,aA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IACH,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,cAAc;IAgBtB;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,YAAY;IA4BpB;;;;;;OAMG;IACH,OAAO,CAAC,qBAAqB;IAe7B,OAAO,CAAC,iBAAiB;IA8BzB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,WAAW;CAMpB"}
|
package/sensor/dist/mcp/tools.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.ToolHandler = exports.tools = exports.IndexOpenError = exports.PathRefusalError = exports.NotIndexedError = void 0;
|
|
9
|
+
exports.__setLoadLatticeSensorForTests = __setLoadLatticeSensorForTests;
|
|
9
10
|
exports.normalizeQuerySpelling = normalizeQuerySpelling;
|
|
10
11
|
exports.getExploreBudget = getExploreBudget;
|
|
11
12
|
exports.getExploreOutputBudget = getExploreOutputBudget;
|
|
@@ -20,10 +21,20 @@ const version_1 = require("./version");
|
|
|
20
21
|
// schemas), but it must NOT drag in sqlite/query layers before the daemon binds;
|
|
21
22
|
// LatticeSensor is pulled in only when a tool actually opens a project. require() is
|
|
22
23
|
// sync + cached (CommonJS build).
|
|
23
|
-
const loadLatticeSensor = () => require('../index').default;
|
|
24
|
+
const loadLatticeSensor = () => loadLatticeSensorForTests ?? require('../index').default;
|
|
25
|
+
// Test seam (same pattern as the watcher's `__setFsWatchForTests`): vitest's
|
|
26
|
+
// module transform can't service the lazy `require('../index')` above, so
|
|
27
|
+
// in-process tests that exercise a genuine cross-project open (an explicit
|
|
28
|
+
// `projectPath` to a different project — issue #1474's repro shape) inject the
|
|
29
|
+
// already-imported class here. Never set outside tests.
|
|
30
|
+
let loadLatticeSensorForTests = null;
|
|
31
|
+
function __setLoadLatticeSensorForTests(cls) {
|
|
32
|
+
loadLatticeSensorForTests = cls;
|
|
33
|
+
}
|
|
24
34
|
const worktree_1 = require("../sync/worktree");
|
|
25
35
|
const query_utils_1 = require("../search/query-utils");
|
|
26
36
|
const fs_1 = require("fs");
|
|
37
|
+
const crypto_1 = require("crypto");
|
|
27
38
|
const utils_1 = require("../utils");
|
|
28
39
|
const generated_detection_1 = require("../extraction/generated-detection");
|
|
29
40
|
const dynamic_boundaries_1 = require("./dynamic-boundaries");
|
|
@@ -1124,6 +1135,68 @@ class ToolHandler {
|
|
|
1124
1135
|
* Cost when nothing is pending — the common case — is one boolean check.
|
|
1125
1136
|
* No I/O, no parsing of markdown beyond a per-pending-file substring scan.
|
|
1126
1137
|
*/
|
|
1138
|
+
driftCache = new Map();
|
|
1139
|
+
static DRIFT_TTL_MS = 2000;
|
|
1140
|
+
/**
|
|
1141
|
+
* On-disk drift check for a single indexed file (issue #1474). The code
|
|
1142
|
+
* renderers slice CURRENT bytes at INDEXED line ranges; when the file
|
|
1143
|
+
* changed after its last index sync those ranges can point at a DIFFERENT
|
|
1144
|
+
* symbol's code — served under the requested name with `isError: false`.
|
|
1145
|
+
* The watcher-based pending/degraded banners can't cover this for a
|
|
1146
|
+
* project reached via `projectPath` (cross-project instances have no
|
|
1147
|
+
* watcher, by construction), so freshness is verified here, at the point
|
|
1148
|
+
* of emission, from data the index already stores.
|
|
1149
|
+
*
|
|
1150
|
+
* Cheap and precise: one stat() per file (size + mtime, the same
|
|
1151
|
+
* comparison the sync fast path uses); only on a stat mismatch is the
|
|
1152
|
+
* content hashed (sha256, matching extraction's `hashContent`) so a
|
|
1153
|
+
* touch/checkout that rewrote identical bytes never false-positives.
|
|
1154
|
+
* Results are memoized briefly so one response rendering the same file in
|
|
1155
|
+
* several sections pays for the check once.
|
|
1156
|
+
*
|
|
1157
|
+
* Returns true when the on-disk file differs from what was indexed —
|
|
1158
|
+
* i.e. indexed line ranges for it are NOT trustworthy. Any failure
|
|
1159
|
+
* (missing files-table row, stat/read error) reports false: those cases
|
|
1160
|
+
* are handled by the existing not-found paths, and a wrong "stale" flag
|
|
1161
|
+
* would needlessly push the agent back to Read.
|
|
1162
|
+
*/
|
|
1163
|
+
isFileStaleOnDisk(cg, relPath, content) {
|
|
1164
|
+
let root;
|
|
1165
|
+
try {
|
|
1166
|
+
root = cg.getProjectRoot();
|
|
1167
|
+
}
|
|
1168
|
+
catch {
|
|
1169
|
+
return false;
|
|
1170
|
+
}
|
|
1171
|
+
const key = `${root}\0${relPath}`;
|
|
1172
|
+
const now = Date.now();
|
|
1173
|
+
const hit = this.driftCache.get(key);
|
|
1174
|
+
if (hit && now - hit.at < ToolHandler.DRIFT_TTL_MS)
|
|
1175
|
+
return hit.stale;
|
|
1176
|
+
let stale = false;
|
|
1177
|
+
try {
|
|
1178
|
+
const rec = cg.getFile(relPath);
|
|
1179
|
+
const absPath = rec ? (0, utils_1.validatePathWithinRoot)(root, relPath) : null;
|
|
1180
|
+
if (rec && absPath && (0, fs_1.existsSync)(absPath)) {
|
|
1181
|
+
const st = (0, fs_1.statSync)(absPath);
|
|
1182
|
+
// Same freshness test as the sync fast path (extraction/index.ts):
|
|
1183
|
+
// equal size + equal floored mtime ⇒ unchanged, no read needed.
|
|
1184
|
+
if (st.size !== rec.size || Math.floor(st.mtimeMs) !== Math.floor(rec.modifiedAt)) {
|
|
1185
|
+
const data = content ?? (0, fs_1.readFileSync)(absPath, 'utf-8');
|
|
1186
|
+
// Must stay byte-identical to extraction's `hashContent` (sha256 over
|
|
1187
|
+
// the utf-8 string) — the identical-rewrite test in
|
|
1188
|
+
// mcp-stale-slice.test.ts pins the parity. Inlined (not imported)
|
|
1189
|
+
// to keep the extraction module off the MCP startup path.
|
|
1190
|
+
stale = (0, crypto_1.createHash)('sha256').update(data).digest('hex') !== rec.contentHash;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
catch {
|
|
1195
|
+
stale = false;
|
|
1196
|
+
}
|
|
1197
|
+
this.driftCache.set(key, { at: now, stale });
|
|
1198
|
+
return stale;
|
|
1199
|
+
}
|
|
1127
1200
|
withStalenessNotice(result, projectPath) {
|
|
1128
1201
|
if (result.isError)
|
|
1129
1202
|
return result;
|
|
@@ -2326,7 +2399,7 @@ class ToolHandler {
|
|
|
2326
2399
|
const where = nonTest.length > 0 ? ` in ${shown}${more}` : '';
|
|
2327
2400
|
const tests = testFiles.length > 0
|
|
2328
2401
|
? `; tests: ${testFiles.slice(0, FILE_CAP).map((f) => `\`${f}\``).join(', ')}${testFiles.length > FILE_CAP ? ` +${testFiles.length - FILE_CAP}` : ''}`
|
|
2329
|
-
:
|
|
2402
|
+
: this.indirectTestNote(cg, uniq, rel);
|
|
2330
2403
|
entries.push(`- \`${root.name}\` (${rel(root.filePath)}:${root.startLine}) — ${uniq.length} caller${uniq.length === 1 ? '' : 's'}${where}${tests}`);
|
|
2331
2404
|
}
|
|
2332
2405
|
if (entries.length === 0)
|
|
@@ -2338,6 +2411,59 @@ class ToolHandler {
|
|
|
2338
2411
|
'',
|
|
2339
2412
|
].join('\n');
|
|
2340
2413
|
}
|
|
2414
|
+
/**
|
|
2415
|
+
* Test-coverage note for a blast-radius entry whose DIRECT callers include no
|
|
2416
|
+
* test file. A helper called only by production code can still be exercised
|
|
2417
|
+
* by tests further up the caller chain (#1475: 40% of directly-unflagged
|
|
2418
|
+
* symbols had a test within 2-3 hops), so walk up to 2 more hops before
|
|
2419
|
+
* claiming anything — and even then claim only what was measured.
|
|
2420
|
+
*/
|
|
2421
|
+
indirectTestNote(cg, directCallers, rel) {
|
|
2422
|
+
const MAX_HOPS = 3; // direct callers are hop 1
|
|
2423
|
+
const BUDGET = 64; // getCallers lookups per entry — bounds god-fan-in symbols
|
|
2424
|
+
const FILE_CAP = 2;
|
|
2425
|
+
let budget = BUDGET;
|
|
2426
|
+
const visited = new Set(directCallers.map((n) => n.id));
|
|
2427
|
+
let frontier = directCallers;
|
|
2428
|
+
for (let hop = 2; hop <= MAX_HOPS && frontier.length > 0 && budget > 0; hop++) {
|
|
2429
|
+
const next = [];
|
|
2430
|
+
const found = new Set();
|
|
2431
|
+
for (const node of frontier) {
|
|
2432
|
+
if (budget-- <= 0)
|
|
2433
|
+
break;
|
|
2434
|
+
let callers = [];
|
|
2435
|
+
try {
|
|
2436
|
+
callers = cg.getCallers(node.id);
|
|
2437
|
+
}
|
|
2438
|
+
catch {
|
|
2439
|
+
continue;
|
|
2440
|
+
}
|
|
2441
|
+
for (const c of callers) {
|
|
2442
|
+
const n = c?.node;
|
|
2443
|
+
if (!n || visited.has(n.id))
|
|
2444
|
+
continue;
|
|
2445
|
+
visited.add(n.id);
|
|
2446
|
+
const f = rel(n.filePath);
|
|
2447
|
+
if ((0, query_utils_1.isTestFile)(f))
|
|
2448
|
+
found.add(f);
|
|
2449
|
+
else
|
|
2450
|
+
next.push(n);
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
if (found.size > 0) {
|
|
2454
|
+
const files = [...found];
|
|
2455
|
+
const shown = files.slice(0, FILE_CAP).map((f) => `\`${f}\``).join(', ');
|
|
2456
|
+
const more = files.length > FILE_CAP ? ` +${files.length - FILE_CAP}` : '';
|
|
2457
|
+
return `; tested via callers: ${shown}${more}`;
|
|
2458
|
+
}
|
|
2459
|
+
frontier = next;
|
|
2460
|
+
}
|
|
2461
|
+
// Budget exhaustion means hops 2-3 weren't fully searched — fall back to
|
|
2462
|
+
// the weaker claim that IS established by the direct-caller check.
|
|
2463
|
+
return budget > 0
|
|
2464
|
+
? `; no tests found within ${MAX_HOPS} caller hops`
|
|
2465
|
+
: '; no test calls this directly';
|
|
2466
|
+
}
|
|
2341
2467
|
/**
|
|
2342
2468
|
* Graph-connectivity relevance via Random-Walk-with-Restart (personalized
|
|
2343
2469
|
* PageRank) from the query's matched SEED nodes over the call/reference graph.
|
|
@@ -3075,6 +3201,9 @@ class ToolHandler {
|
|
|
3075
3201
|
};
|
|
3076
3202
|
lines.push('**Source Code**');
|
|
3077
3203
|
lines.push('');
|
|
3204
|
+
// Recorded so the drift pass below (#1474) can append a per-file exception
|
|
3205
|
+
// to this guarantee after the render loop knows which files drifted.
|
|
3206
|
+
const verbatimHeaderIdx = lines.length;
|
|
3078
3207
|
lines.push('> The code below is the **verbatim, current on-disk source** of these files — re-read from disk on this call and line-numbered, byte-for-byte identical to what the Read tool returns. It is NOT a summary, outline, or stale cache. Treat each block as a Read you have already performed: do not Read a file shown here.');
|
|
3079
3208
|
lines.push('');
|
|
3080
3209
|
let totalChars = lines.join('\n').length;
|
|
@@ -3083,6 +3212,14 @@ class ToolHandler {
|
|
|
3083
3212
|
// (#1046) — it must reflect what we show, not the raw candidate gather.
|
|
3084
3213
|
const renderedFilePaths = [];
|
|
3085
3214
|
let anyFileTrimmed = false;
|
|
3215
|
+
// Files that changed on disk after their last index sync (#1474). Their
|
|
3216
|
+
// indexed line ranges are untrustworthy, so sliced renders (adaptive /
|
|
3217
|
+
// skeleton / clusters) are OFF for them: a small drifted file still ships
|
|
3218
|
+
// whole (current bytes, correct by construction → staleRendered), a big one
|
|
3219
|
+
// is omitted with an explicit notice (→ staleOmitted) — honest absence
|
|
3220
|
+
// instead of a different symbol's code under the requested name.
|
|
3221
|
+
const staleRendered = [];
|
|
3222
|
+
const staleOmitted = [];
|
|
3086
3223
|
for (const [filePath, group] of sortedFiles) {
|
|
3087
3224
|
if (filesIncluded >= maxFiles)
|
|
3088
3225
|
break;
|
|
@@ -3107,6 +3244,10 @@ class ToolHandler {
|
|
|
3107
3244
|
}
|
|
3108
3245
|
const fileLines = fileContent.split('\n');
|
|
3109
3246
|
const lang = group.nodes[0]?.language || '';
|
|
3247
|
+
// Disk-drift gate (#1474): every render branch below except whole-file
|
|
3248
|
+
// slices fileContent (CURRENT bytes) at INDEXED line ranges. Content is
|
|
3249
|
+
// already in hand, so the check costs one stat (hash only on mismatch).
|
|
3250
|
+
const fileStale = this.isFileStaleOnDisk(cg, filePath, fileContent);
|
|
3110
3251
|
// Adaptive sizing (LATTICE_SENSOR_ADAPTIVE_EXPLORE, default on): collapse a file
|
|
3111
3252
|
// to a per-symbol view when it's a redundant member of a polymorphic family.
|
|
3112
3253
|
// Engages iff ALL hold:
|
|
@@ -3145,7 +3286,7 @@ class ToolHandler {
|
|
|
3145
3286
|
const onSpineGodFile = hasSpineNode
|
|
3146
3287
|
&& namedBodyChars > budget.maxCharsPerFile
|
|
3147
3288
|
&& group.nodes.some(n => CALLABLE_BODY.has(n.kind) && flow.uniqueNamedNodeIds.has(n.id) && !flow.pathNodeIds.has(n.id));
|
|
3148
|
-
if (adaptiveExploreEnabled() && flow.pathNodeIds.size > 0
|
|
3289
|
+
if (!fileStale && adaptiveExploreEnabled() && flow.pathNodeIds.size > 0
|
|
3149
3290
|
&& (onSpineGodFile || (!hasSpineNode && isPolymorphicSibling(group.nodes) && !spared))) {
|
|
3150
3291
|
const syms = group.nodes
|
|
3151
3292
|
.filter(n => n.kind !== 'import' && n.kind !== 'export' && n.startLine > 0)
|
|
@@ -3270,7 +3411,11 @@ class ToolHandler {
|
|
|
3270
3411
|
.map(n => `${n.name}(${n.kind})`))];
|
|
3271
3412
|
const headerNames = uniqSymbols.slice(0, budget.maxSymbolsInFileHeader);
|
|
3272
3413
|
const omitted = uniqSymbols.length - headerNames.length;
|
|
3273
|
-
|
|
3414
|
+
// A drifted file rendered WHOLE is still correct (current bytes,
|
|
3415
|
+
// numbered from 1) — only the index-derived symbol list / line refs to
|
|
3416
|
+
// it elsewhere in this response may be shifted (#1474). Flag that.
|
|
3417
|
+
const staleSuffix = fileStale ? ' · ⚠ changed since last index sync — source below is current; the symbol list may be outdated' : '';
|
|
3418
|
+
const wholeHeader = fileSectionHeader(filePath, (omitted > 0 ? `${headerNames.join(', ')}, +${omitted} more` : headerNames.join(', ')) + staleSuffix);
|
|
3274
3419
|
if (!fileNecessary && totalChars + wholeSection.length + 200 > budget.maxOutputChars) {
|
|
3275
3420
|
// Don't slice a whole file mid-method: an incidental file that doesn't
|
|
3276
3421
|
// fit is skipped; a necessary one (below) renders in full. Half a file
|
|
@@ -3282,6 +3427,19 @@ class ToolHandler {
|
|
|
3282
3427
|
totalChars += wholeSection.length + 200;
|
|
3283
3428
|
renderedFilePaths.push(filePath);
|
|
3284
3429
|
filesIncluded++;
|
|
3430
|
+
if (fileStale)
|
|
3431
|
+
staleRendered.push(filePath);
|
|
3432
|
+
continue;
|
|
3433
|
+
}
|
|
3434
|
+
// Drifted file too big for the whole-file window (#1474): the cluster /
|
|
3435
|
+
// skeleton renders below would slice current bytes at indexed ranges —
|
|
3436
|
+
// on a shifted file that serves a DIFFERENT symbol's code under the
|
|
3437
|
+
// requested name. Omit the source with an explicit notice instead;
|
|
3438
|
+
// never render a possibly-wrong slice.
|
|
3439
|
+
if (fileStale) {
|
|
3440
|
+
staleOmitted.push(filePath);
|
|
3441
|
+
lines.push(fileSectionHeader(filePath, '⚠ changed on disk after the last index sync — source omitted (indexed line ranges no longer match, so a slice could show the wrong code). Read this file directly for current content; the change is picked up on that project\'s next index sync.'), '');
|
|
3442
|
+
totalChars += 260;
|
|
3285
3443
|
continue;
|
|
3286
3444
|
}
|
|
3287
3445
|
// Cluster nearby symbols to avoid reading huge gaps between distant symbols.
|
|
@@ -3572,6 +3730,18 @@ class ToolHandler {
|
|
|
3572
3730
|
renderedFilePaths.push(filePath);
|
|
3573
3731
|
filesIncluded++;
|
|
3574
3732
|
}
|
|
3733
|
+
// Drift epilogue (#1474). The "verbatim / do not Read" guarantee above
|
|
3734
|
+
// stays TRUE for everything actually rendered (drifted files ship whole or
|
|
3735
|
+
// not at all — never as a possibly-wrong slice), but two caveats must be
|
|
3736
|
+
// explicit: omitted files need Reading, and index-derived LINE REFERENCES
|
|
3737
|
+
// to any drifted file (flow steps, blast radius, trail) may be shifted.
|
|
3738
|
+
if (staleOmitted.length > 0) {
|
|
3739
|
+
lines[verbatimHeaderIdx] += ' (Exception: files flagged "⚠ changed on disk" below drifted from the index after their last sync — their source is omitted rather than risk a mis-sliced block; Read those specific files.)';
|
|
3740
|
+
}
|
|
3741
|
+
const staleAll = [...new Set([...staleOmitted, ...staleRendered])];
|
|
3742
|
+
if (staleAll.length > 0) {
|
|
3743
|
+
lines.push('', `> ⚠ Changed on disk after the last index sync: ${staleAll.join(', ')}. Line numbers referencing ${staleAll.length === 1 ? 'this file' : 'these files'} elsewhere in this response (flow steps, blast radius, symbol lists) may be shifted until that project's next sync re-indexes ${staleAll.length === 1 ? 'it' : 'them'}.`);
|
|
3744
|
+
}
|
|
3575
3745
|
// The curated header count is computed from the files that SURVIVE the final
|
|
3576
3746
|
// truncation (see end of method) — `filesIncluded` can over-count when the
|
|
3577
3747
|
// hard ceiling drops trailing sections — so leave a sentinel here and fill it
|
|
@@ -3914,6 +4084,14 @@ class ToolHandler {
|
|
|
3914
4084
|
}
|
|
3915
4085
|
/** Render one symbol: details + (optional) body/outline + its caller/callee trail. */
|
|
3916
4086
|
async renderNodeSection(cg, node, includeCode) {
|
|
4087
|
+
// Disk-drift gate (issue #1474): the body below is CURRENT bytes sliced at
|
|
4088
|
+
// INDEXED line ranges. If the file changed since its last index sync, that
|
|
4089
|
+
// slice can be a DIFFERENT symbol's code served under this node's name —
|
|
4090
|
+
// confidently wrong, with no watcher banner to catch it on a `projectPath`
|
|
4091
|
+
// (cross-project) target. Never emit a slice from a drifted file.
|
|
4092
|
+
if (this.isFileStaleOnDisk(cg, node.filePath)) {
|
|
4093
|
+
return this.renderStaleNodeSection(cg, node, includeCode);
|
|
4094
|
+
}
|
|
3917
4095
|
let code = null;
|
|
3918
4096
|
let outline = null;
|
|
3919
4097
|
if (includeCode) {
|
|
@@ -3930,6 +4108,55 @@ class ToolHandler {
|
|
|
3930
4108
|
}
|
|
3931
4109
|
return this.formatNodeDetails(node, code, outline) + this.formatTrail(cg, node);
|
|
3932
4110
|
}
|
|
4111
|
+
// Whole-file fallback caps for a drifted file (#1474): small enough to fit
|
|
4112
|
+
// lattice_sensor_node's output cap (MAX_OUTPUT_LENGTH) with headroom for the
|
|
4113
|
+
// header + trail. A file within these bounds is served WHOLE and CURRENT
|
|
4114
|
+
// (Read-parity, correct by construction) instead of a possibly-wrong slice.
|
|
4115
|
+
static STALE_WHOLE_FILE_MAX_LINES = 300;
|
|
4116
|
+
static STALE_WHOLE_FILE_MAX_CHARS = 12000;
|
|
4117
|
+
/**
|
|
4118
|
+
* lattice_sensor_node render for a symbol whose file changed on disk after the
|
|
4119
|
+
* last index sync (issue #1474). The indexed line range is no longer
|
|
4120
|
+
* trustworthy, so no slice is emitted: a small file gets its full CURRENT
|
|
4121
|
+
* source (Read-parity — sufficiency preserved, the agent still doesn't need
|
|
4122
|
+
* Read); a large one gets an explicit notice steering to the tool's own
|
|
4123
|
+
* file-read mode (or Read) — honest absence instead of confident wrongness.
|
|
4124
|
+
* Location/signature stay (they're the index's answer) but are flagged as
|
|
4125
|
+
* possibly shifted.
|
|
4126
|
+
*/
|
|
4127
|
+
renderStaleNodeSection(cg, node, includeCode) {
|
|
4128
|
+
const lines = [
|
|
4129
|
+
`**${node.name}** (${node.kind})`,
|
|
4130
|
+
'',
|
|
4131
|
+
`**Location:** ${node.filePath}${node.startLine ? `:${node.startLine}` : ''} — ⚠ as of the last index sync; the file has changed on disk since, so this line may be shifted`,
|
|
4132
|
+
];
|
|
4133
|
+
if (node.signature) {
|
|
4134
|
+
lines.push(`**Signature:** \`${node.signature}\``);
|
|
4135
|
+
}
|
|
4136
|
+
lines.push('');
|
|
4137
|
+
let embedded = false;
|
|
4138
|
+
if (includeCode) {
|
|
4139
|
+
try {
|
|
4140
|
+
const absPath = (0, utils_1.validatePathWithinRoot)(cg.getProjectRoot(), node.filePath);
|
|
4141
|
+
if (absPath && (0, fs_1.existsSync)(absPath) && !(0, utils_1.isConfigLeafNode)(node)) {
|
|
4142
|
+
const content = (0, fs_1.readFileSync)(absPath, 'utf-8');
|
|
4143
|
+
const body = content.replace(/\n+$/, '');
|
|
4144
|
+
if (body.length <= ToolHandler.STALE_WHOLE_FILE_MAX_CHARS &&
|
|
4145
|
+
body.split('\n').length <= ToolHandler.STALE_WHOLE_FILE_MAX_LINES) {
|
|
4146
|
+
lines.push(`> ⚠ \`${node.filePath}\` changed on disk after it was last indexed, so the indexed line range for this symbol may no longer match. Showing the file's full CURRENT source instead (Read-parity — treat it as already Read):`, '', '```' + (node.language || ''), numberSourceLines(body, 1), '```');
|
|
4147
|
+
embedded = true;
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
4150
|
+
}
|
|
4151
|
+
catch {
|
|
4152
|
+
/* fall through to the notice */
|
|
4153
|
+
}
|
|
4154
|
+
}
|
|
4155
|
+
if (!embedded) {
|
|
4156
|
+
lines.push(`> ⚠ \`${node.filePath}\` changed on disk after it was last indexed — the indexed line range for this symbol no longer reliably matches, so its body is omitted rather than risk showing a different symbol's code. For current content, call lattice_sensor_node with \`file: "${node.filePath}"\` (no symbol; \`offset\`/\`limit\` narrow it like Read), or Read the file. The change is picked up automatically on that project's next index sync.`);
|
|
4157
|
+
}
|
|
4158
|
+
return lines.join('\n') + this.formatTrail(cg, node);
|
|
4159
|
+
}
|
|
3933
4160
|
/**
|
|
3934
4161
|
* Build the "trail" for a symbol: its direct callees (what it calls) and
|
|
3935
4162
|
* callers (what calls it), each with file:line — so lattice_sensor_node doubles as
|