@qmediat.io/gemini-code-context-mcp 1.12.2 → 1.14.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/CHANGELOG.md +174 -0
- package/dist/cache/cache-manager.d.ts +20 -0
- package/dist/cache/cache-manager.d.ts.map +1 -1
- package/dist/cache/cache-manager.js +120 -19
- package/dist/cache/cache-manager.js.map +1 -1
- package/dist/cache/files-uploader.d.ts.map +1 -1
- package/dist/cache/files-uploader.js +57 -30
- package/dist/cache/files-uploader.js.map +1 -1
- package/dist/config.d.ts +31 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +42 -0
- package/dist/config.js.map +1 -1
- package/dist/indexer/workspace-scanner.d.ts +63 -0
- package/dist/indexer/workspace-scanner.d.ts.map +1 -1
- package/dist/indexer/workspace-scanner.js +66 -7
- package/dist/indexer/workspace-scanner.js.map +1 -1
- package/dist/manifest/db.d.ts +101 -0
- package/dist/manifest/db.d.ts.map +1 -1
- package/dist/manifest/db.js +231 -10
- package/dist/manifest/db.js.map +1 -1
- package/dist/tools/ask.tool.d.ts +10 -0
- package/dist/tools/ask.tool.d.ts.map +1 -1
- package/dist/tools/ask.tool.js +42 -1
- package/dist/tools/ask.tool.js.map +1 -1
- package/dist/tools/code.tool.d.ts +10 -0
- package/dist/tools/code.tool.d.ts.map +1 -1
- package/dist/tools/code.tool.js +40 -1
- package/dist/tools/code.tool.js.map +1 -1
- package/dist/tools/reindex.tool.d.ts.map +1 -1
- package/dist/tools/reindex.tool.js +4 -0
- package/dist/tools/reindex.tool.js.map +1 -1
- package/dist/tools/status.tool.d.ts.map +1 -1
- package/dist/tools/status.tool.js +46 -0
- package/dist/tools/status.tool.js.map +1 -1
- package/dist/types.d.ts +36 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/logger.js +0 -0
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/run-pool.d.ts +15 -0
- package/dist/utils/run-pool.d.ts.map +1 -0
- package/dist/utils/run-pool.js +36 -0
- package/dist/utils/run-pool.js.map +1 -0
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { basename } from 'node:path';
|
|
17
17
|
import { logger, safeForLog } from '../utils/logger.js';
|
|
18
|
+
import { runPool } from '../utils/run-pool.js';
|
|
18
19
|
const FILES_API_TTL_MS = 47 * 3600 * 1000; // 1 h safety margin before 48 h auto-delete
|
|
19
20
|
/**
|
|
20
21
|
* Files are unsafe to reuse when Google is about to delete them. A cache build
|
|
@@ -38,33 +39,6 @@ const DEFAULT_UPLOAD_CONCURRENCY = 10;
|
|
|
38
39
|
function uploadMimeType(_relpath) {
|
|
39
40
|
return 'text/plain';
|
|
40
41
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Run `task` over `items` with up to `concurrency` in flight. Order of
|
|
43
|
-
* results matches order of items. Never throws — every failure is captured
|
|
44
|
-
* as a rejected `PromiseSettledResult` in the returned array.
|
|
45
|
-
*/
|
|
46
|
-
async function runPool(items, concurrency, task) {
|
|
47
|
-
const results = new Array(items.length);
|
|
48
|
-
let next = 0;
|
|
49
|
-
const workers = Array.from({ length: Math.max(1, Math.min(concurrency, items.length || 1)) }, async () => {
|
|
50
|
-
while (next < items.length) {
|
|
51
|
-
const i = next;
|
|
52
|
-
next += 1;
|
|
53
|
-
const item = items[i];
|
|
54
|
-
if (item === undefined)
|
|
55
|
-
continue;
|
|
56
|
-
try {
|
|
57
|
-
const value = await task(item, i);
|
|
58
|
-
results[i] = { status: 'fulfilled', value };
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
results[i] = { status: 'rejected', reason: err };
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
await Promise.all(workers);
|
|
66
|
-
return results;
|
|
67
|
-
}
|
|
68
42
|
export async function uploadWorkspaceFiles(args) {
|
|
69
43
|
const { client, manifest, workspaceRoot, files, emitter } = args;
|
|
70
44
|
const concurrency = args.concurrency ?? DEFAULT_UPLOAD_CONCURRENCY;
|
|
@@ -75,6 +49,28 @@ export async function uploadWorkspaceFiles(args) {
|
|
|
75
49
|
let reusedCount = 0;
|
|
76
50
|
let completed = 0;
|
|
77
51
|
const failures = [];
|
|
52
|
+
// v1.13.0 progress-emit throttle. On a 500-file workspace, the previous
|
|
53
|
+
// per-file emit dispatched 500 MCP notifications inside ~3 s — most of
|
|
54
|
+
// them serialised over stdio for the same effective UI state ("X/500
|
|
55
|
+
// indexed"). Cap the emit cadence at ≥250 ms apart OR ≥25 files of
|
|
56
|
+
// progress, whichever comes first; ALWAYS emit the final completion so
|
|
57
|
+
// the progress UI doesn't hang at e.g. 475/500. Only the index
|
|
58
|
+
// notifications are throttled — abort/error events stay immediate.
|
|
59
|
+
const PROGRESS_EMIT_INTERVAL_MS = 250;
|
|
60
|
+
const PROGRESS_EMIT_FILE_STEP = 25;
|
|
61
|
+
let lastEmitTimeMs = 0;
|
|
62
|
+
let lastEmitCompleted = 0;
|
|
63
|
+
const emitProgress = (relpath) => {
|
|
64
|
+
const isFinal = completed === files.length;
|
|
65
|
+
const tNow = Date.now();
|
|
66
|
+
const stepReached = completed - lastEmitCompleted >= PROGRESS_EMIT_FILE_STEP;
|
|
67
|
+
const intervalReached = tNow - lastEmitTimeMs >= PROGRESS_EMIT_INTERVAL_MS;
|
|
68
|
+
if (!(isFinal || stepReached || intervalReached))
|
|
69
|
+
return;
|
|
70
|
+
lastEmitTimeMs = tNow;
|
|
71
|
+
lastEmitCompleted = completed;
|
|
72
|
+
emitter.emit(`indexed ${completed}/${files.length}: ${relpath}`, completed, files.length);
|
|
73
|
+
};
|
|
78
74
|
// Pre-flight: don't start the pool at all if abort already fired.
|
|
79
75
|
if (signal?.aborted) {
|
|
80
76
|
throw signal.reason instanceof Error
|
|
@@ -114,11 +110,13 @@ export async function uploadWorkspaceFiles(args) {
|
|
|
114
110
|
fileId: entry.existing.fileId,
|
|
115
111
|
uploadedAt: entry.existing.uploadedAt,
|
|
116
112
|
expiresAt: entry.existing.expiresAt,
|
|
113
|
+
mtimeMs: entry.file.mtimeMs,
|
|
114
|
+
size: entry.file.size,
|
|
117
115
|
};
|
|
118
116
|
manifest.upsertFile(row);
|
|
119
117
|
out[i] = row;
|
|
120
118
|
completed += 1;
|
|
121
|
-
|
|
119
|
+
emitProgress(entry.file.relpath);
|
|
122
120
|
return;
|
|
123
121
|
}
|
|
124
122
|
// Same-batch dedup: if another worker is already uploading this content hash,
|
|
@@ -158,25 +156,54 @@ export async function uploadWorkspaceFiles(args) {
|
|
|
158
156
|
fileId,
|
|
159
157
|
uploadedAt: now,
|
|
160
158
|
expiresAt: now + FILES_API_TTL_MS,
|
|
159
|
+
mtimeMs: entry.file.mtimeMs,
|
|
160
|
+
size: entry.file.size,
|
|
161
161
|
};
|
|
162
162
|
manifest.upsertFile(row);
|
|
163
163
|
out[i] = row;
|
|
164
164
|
if (isDuplicate)
|
|
165
165
|
reusedCount += 1;
|
|
166
166
|
completed += 1;
|
|
167
|
-
|
|
167
|
+
emitProgress(entry.file.relpath);
|
|
168
168
|
}).then((settled) => {
|
|
169
169
|
// Collect failures after the pool finishes — don't lose the mapping to files.
|
|
170
|
+
//
|
|
171
|
+
// v1.13.0 post-review (FN3, gemini P1): abort-induced rejections are NOT
|
|
172
|
+
// genuine upload failures — they're cooperative bail-outs from the per-task
|
|
173
|
+
// abort guard at the top of the worker. Treating them as "failed" pollutes
|
|
174
|
+
// stderr with N-completed warns AND inflates `failures`, both of which
|
|
175
|
+
// mislead the user before the post-pool re-throw at line ~246 surfaces the
|
|
176
|
+
// real `signal.reason` (typically a TimeoutError that maps to
|
|
177
|
+
// `errorCode: 'TIMEOUT'`). On a 400-file repo with concurrency 10 and an
|
|
178
|
+
// abort fired at completed=12, this could spew ~388 warn lines.
|
|
179
|
+
const aborted = signal?.aborted === true;
|
|
170
180
|
for (let i = 0; i < settled.length; i += 1) {
|
|
171
181
|
const r = settled[i];
|
|
172
182
|
const file = files[i];
|
|
173
183
|
if (r?.status === 'rejected' && file) {
|
|
174
|
-
const
|
|
184
|
+
const reason = r.reason;
|
|
185
|
+
if (aborted &&
|
|
186
|
+
(reason === signal?.reason || (reason instanceof Error && reason.name === 'AbortError'))) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const message = reason instanceof Error ? reason.message : String(reason);
|
|
175
190
|
logger.warn(`upload failed for ${safeForLog(file.relpath)}: ${safeForLog(message)}`);
|
|
176
191
|
failures.push({ relpath: file.relpath, error: message });
|
|
177
192
|
}
|
|
178
193
|
}
|
|
179
194
|
});
|
|
195
|
+
// v1.13.0 round-3 fix (Copilot finding): `emitProgress` only force-emits
|
|
196
|
+
// when `completed === files.length`, but `completed` only increments on
|
|
197
|
+
// task SUCCESS — a tail of failed uploads (rejections) leaves `completed
|
|
198
|
+
// < files.length`, the throttle's `isFinal` predicate never trips, and
|
|
199
|
+
// the last successful indexed-file message can stay buffered behind the
|
|
200
|
+
// 250 ms / 25-file gates indefinitely. UI hangs at e.g. 490/500 even
|
|
201
|
+
// though the operation is fully finished. Trailing flush guarantees the
|
|
202
|
+
// emitter sees the final true `completed` value.
|
|
203
|
+
if (completed > lastEmitCompleted) {
|
|
204
|
+
emitter.emit(`indexed ${completed}/${files.length}`, completed, files.length);
|
|
205
|
+
lastEmitCompleted = completed;
|
|
206
|
+
}
|
|
180
207
|
// Post-pool abort propagation (v1.12.1). `runPool` catches per-task
|
|
181
208
|
// errors and returns a settled-results array, so the in-task abort
|
|
182
209
|
// throw above just becomes "Upload failed for X" in `failures`. To
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files-uploader.js","sourceRoot":"","sources":["../../src/cache/files-uploader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAKrC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":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IAC7E,MAAM,SAAS,GAAc,EAAE,CAAC;IAChC,KAAK,MAAM,GAAG,IAAI,GAAG;QAAE,IAAI,GAAG;YAAE,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEpD,OAAO;QACL,KAAK,EAAE,SAAS;QAChB,aAAa;QACb,WAAW;QACX,WAAW,EAAE,QAAQ,CAAC,MAAM;QAC5B,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -32,6 +32,37 @@ export interface Config {
|
|
|
32
32
|
* Controlled by `GEMINI_CODE_CONTEXT_FORCE_MAX_OUTPUT` env var.
|
|
33
33
|
*/
|
|
34
34
|
forceMaxOutputTokens: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* v1.13.0+: when `true`, every `ask` / `code` call bypasses the scan memo
|
|
37
|
+
* and re-hashes every file in the workspace. The scan memo (default
|
|
38
|
+
* behaviour) skips per-file SHA256 when `mtime_ms` and `size` match the
|
|
39
|
+
* previously-stored values — typically ~95% of files on a warm rescan.
|
|
40
|
+
* Per-call `input.forceRescan` is ORed with this flag; either one being
|
|
41
|
+
* `true` forces a fresh hash. Default `false`. Controlled by env var
|
|
42
|
+
* `GEMINI_CODE_CONTEXT_FORCE_RESCAN`. Use this if you've observed scan
|
|
43
|
+
* results going stale after filesystem mutations outside the dev workflow.
|
|
44
|
+
*/
|
|
45
|
+
forceRescan: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* v1.14.0+: default caching mode for `ask` / `code` when the per-call
|
|
48
|
+
* `cachingMode` field is unset.
|
|
49
|
+
*
|
|
50
|
+
* - `'implicit'` (v1.14.0 default): skip `caches.create`; rely on Gemini
|
|
51
|
+
* 2.5+/3 Pro's automatic implicit caching for repeated workspace
|
|
52
|
+
* prefixes. Eliminates the 60–180 s rebuild wait on the
|
|
53
|
+
* review→edit→review path. Probabilistic rather than guaranteed savings
|
|
54
|
+
* (Gemini's docs note "no cost saving guarantee"); hit rate observable
|
|
55
|
+
* via `status.structuredContent.caching.implicitHitRate`.
|
|
56
|
+
* - `'explicit'`: build a Gemini Context Cache via `caches.create`;
|
|
57
|
+
* guaranteed ~75 % discount on cached input tokens but pays the rebuild
|
|
58
|
+
* cost on every file change. Set this when you need predictable
|
|
59
|
+
* per-call billing more than warm-path latency.
|
|
60
|
+
*
|
|
61
|
+
* Per-call `input.cachingMode` always wins. Controlled by env var
|
|
62
|
+
* `GEMINI_CODE_CONTEXT_CACHING_MODE`. Invalid values fall back to the
|
|
63
|
+
* `'implicit'` default with a startup warning.
|
|
64
|
+
*/
|
|
65
|
+
cachingMode: 'explicit' | 'implicit';
|
|
35
66
|
/**
|
|
36
67
|
* Client-side TPM (tokens-per-minute) throttle ceiling, per resolved model.
|
|
37
68
|
* `0` disables the throttle entirely; positive integer caps how many input
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAe,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAe,MAAM,0BAA0B,CAAC;AAG1E,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,YAAY,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,oBAAoB,EAAE,MAAM,CAAC;IAC7B,2CAA2C;IAC3C,gBAAgB,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,gBAAgB,EAAE,OAAO,CAAC;IAC1B;;;;;;;;;;OAUG;IACH,oBAAoB,EAAE,OAAO,CAAC;IAC9B;;;;;;;;;OASG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,EAAE,UAAU,GAAG,UAAU,CAAC;IACrC;;;;;;;;;;OAUG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAoED,wBAAgB,UAAU,IAAI,MAAM,CA+CnC"}
|
package/dist/config.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Runtime config — environment variables + resolved auth profile.
|
|
3
3
|
*/
|
|
4
4
|
import { resolveAuth } from './auth/profile-loader.js';
|
|
5
|
+
import { safeForLog } from './utils/logger.js';
|
|
5
6
|
function readIntEnv(name, fallback) {
|
|
6
7
|
const raw = process.env[name];
|
|
7
8
|
if (!raw || raw.length === 0)
|
|
@@ -29,6 +30,45 @@ function readBoolEnv(name) {
|
|
|
29
30
|
const v = raw.trim().toLowerCase();
|
|
30
31
|
return v === 'true' || v === '1' || v === 'yes' || v === 'on';
|
|
31
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* v1.14.0 — read `GEMINI_CODE_CONTEXT_CACHING_MODE` env var with strict
|
|
35
|
+
* validation. Returns `'implicit'` (the v1.14.0 default) when unset; returns
|
|
36
|
+
* the parsed value when set to `'explicit'` or `'implicit'`. Anything else
|
|
37
|
+
* emits a startup warning and falls back to the default — operators get a
|
|
38
|
+
* clear signal that their override didn't take effect, instead of a silent
|
|
39
|
+
* mistype shipping the wrong cache strategy to production.
|
|
40
|
+
*/
|
|
41
|
+
function readCachingModeEnv() {
|
|
42
|
+
const raw = process.env.GEMINI_CODE_CONTEXT_CACHING_MODE;
|
|
43
|
+
if (raw === undefined)
|
|
44
|
+
return 'implicit';
|
|
45
|
+
// v1.14.0 round-1 fix (F9, Grok P1): trim BEFORE the empty-check so
|
|
46
|
+
// whitespace-only values (`' '`, `'\t'`) short-circuit to default
|
|
47
|
+
// silently instead of falling into the warn path. Whitespace-only is
|
|
48
|
+
// morally equivalent to "unset" — operators shouldn't get a misleading
|
|
49
|
+
// "not a recognised value" warning when they paste a value containing
|
|
50
|
+
// only whitespace (a common shell-quoting mistake).
|
|
51
|
+
const v = raw.trim().toLowerCase();
|
|
52
|
+
if (v === '')
|
|
53
|
+
return 'implicit';
|
|
54
|
+
if (v === 'explicit' || v === 'implicit')
|
|
55
|
+
return v;
|
|
56
|
+
// Stderr-only warning so MCP host log pipelines surface the mistype.
|
|
57
|
+
// Falling back to 'implicit' (the v1.14.0 default) keeps behaviour safe.
|
|
58
|
+
//
|
|
59
|
+
// v1.14.0 round-1 fix (F3+F4, Copilot + GPT P1): wrap `raw` in
|
|
60
|
+
// `safeForLog` so a malicious or accidental env value containing
|
|
61
|
+
// newlines / control chars / ANSI escapes can't forge a separate log
|
|
62
|
+
// record (record-splitting / log injection). `safeForLog` escapes C0
|
|
63
|
+
// control chars (LF/CR/TAB/ESC) into printable form (`\\n`/`\\r`/...)
|
|
64
|
+
// and caps length at 2000 chars — preserves the printable prefix so
|
|
65
|
+
// operators still see what they typed (`EXPLICITT`-style typos remain
|
|
66
|
+
// diagnosable), but multi-line forgery attempts collapse to a single
|
|
67
|
+
// safe log line.
|
|
68
|
+
// eslint-disable-next-line no-console
|
|
69
|
+
console.error(`[gemini-code-context-mcp] warning: GEMINI_CODE_CONTEXT_CACHING_MODE="${safeForLog(raw)}" is not a recognised value (expected 'explicit' or 'implicit'); falling back to 'implicit'.`);
|
|
70
|
+
return 'implicit';
|
|
71
|
+
}
|
|
32
72
|
export function loadConfig() {
|
|
33
73
|
const auth = resolveAuth();
|
|
34
74
|
// Default alias resolves to the newest Pro-class model that advertises
|
|
@@ -64,6 +104,8 @@ export function loadConfig() {
|
|
|
64
104
|
tpmThrottleLimit,
|
|
65
105
|
workspaceGuardRatio,
|
|
66
106
|
forceMaxOutputTokens: readBoolEnv('GEMINI_CODE_CONTEXT_FORCE_MAX_OUTPUT'),
|
|
107
|
+
forceRescan: readBoolEnv('GEMINI_CODE_CONTEXT_FORCE_RESCAN'),
|
|
108
|
+
cachingMode: readCachingModeEnv(),
|
|
67
109
|
};
|
|
68
110
|
}
|
|
69
111
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAqB,WAAW,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAqB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAoG/C,SAAS,UAAU,CAAC,IAAY,EAAE,QAAgB;IAChD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC9C,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACnC,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC3C,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,QAAgB;IAClD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC9C,MAAM,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,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AAW,CAAC,kCAAkC,CAAC;QAC5D,WAAW,EAAE,kBAAkB,EAAE;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -3,18 +3,73 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Respects default include extensions + exclude directories, plus user overrides
|
|
5
5
|
* passed via `MatchConfig`. Enforces a soft file-count cap and a per-file size cap.
|
|
6
|
+
*
|
|
7
|
+
* v1.13.0+: when `manifestMemo` is supplied, files whose `(mtime_ms, size)`
|
|
8
|
+
* match the previously-stored values reuse the stored content hash and skip
|
|
9
|
+
* re-hashing — typically ~95% of files on a warm rescan, cutting scan
|
|
10
|
+
* wall-clock by ≥10× on large workspaces.
|
|
11
|
+
*/
|
|
12
|
+
import type { FileRow } from '../types.js';
|
|
13
|
+
/**
|
|
14
|
+
* v1.13.0+: build the per-file fingerprint map the scanner consults to skip
|
|
15
|
+
* re-hashing. Rows lacking `mtimeMs` or `size` (pre-1.13 manifests, or rows
|
|
16
|
+
* the uploader hasn't refreshed yet) are dropped — those files always
|
|
17
|
+
* re-hash on the next scan.
|
|
6
18
|
*/
|
|
19
|
+
export declare function buildScanMemo(rows: readonly FileRow[]): Map<string, ScanMemoEntry>;
|
|
20
|
+
/**
|
|
21
|
+
* v1.13.0+: per-file fingerprint stored on the previous scan, used by the
|
|
22
|
+
* scan memo to skip re-hashing when nothing material has changed.
|
|
23
|
+
*
|
|
24
|
+
* `contentHash` is the SHA256 we'd have computed; `mtimeMs` is the file's
|
|
25
|
+
* mtime in ms; `size` is the byte count. ALL THREE must match for the memo
|
|
26
|
+
* to fire — `mtime` alone would mis-cache the (rare) case where two writes
|
|
27
|
+
* within a 1-second resolution window leave the same `mtime` but different
|
|
28
|
+
* content. Size adds a second gate that catches that.
|
|
29
|
+
*/
|
|
30
|
+
export interface ScanMemoEntry {
|
|
31
|
+
contentHash: string;
|
|
32
|
+
mtimeMs: number;
|
|
33
|
+
size: number;
|
|
34
|
+
}
|
|
7
35
|
export interface ScanOptions {
|
|
8
36
|
includeGlobs?: readonly string[];
|
|
9
37
|
excludeGlobs?: readonly string[];
|
|
10
38
|
maxFiles: number;
|
|
11
39
|
maxFileSizeBytes: number;
|
|
40
|
+
/**
|
|
41
|
+
* Concurrency for the per-file `stat` + `hashFile` loop. v1.13.0 default
|
|
42
|
+
* (20) measured ~6× faster than the serial loop on a 670k-token workspace.
|
|
43
|
+
* Capped low enough that small workspaces don't pay setup overhead.
|
|
44
|
+
*/
|
|
45
|
+
hashConcurrency?: number;
|
|
46
|
+
/**
|
|
47
|
+
* v1.13.0+: scan-memo lookup. Map keyed by relpath (POSIX-style, matches
|
|
48
|
+
* what the scanner produces). When `mtimeMs` and `size` from `stat()`
|
|
49
|
+
* match the entry, the scanner reuses `contentHash` and skips reading the
|
|
50
|
+
* file from disk. Pass empty (or `undefined`) to force a fresh hash for
|
|
51
|
+
* every file — equivalent to `forceRescan`.
|
|
52
|
+
*/
|
|
53
|
+
manifestMemo?: ReadonlyMap<string, ScanMemoEntry>;
|
|
54
|
+
/**
|
|
55
|
+
* v1.13.0+: bypass the scan memo and re-hash every file. Useful when the
|
|
56
|
+
* caller suspects the manifest is stale (e.g. after a manual filesystem
|
|
57
|
+
* mutation outside the dev workflow) and wants a forced verification scan.
|
|
58
|
+
*/
|
|
59
|
+
forceRescan?: boolean;
|
|
12
60
|
}
|
|
13
61
|
export interface ScannedFile {
|
|
14
62
|
relpath: string;
|
|
15
63
|
absolutePath: string;
|
|
16
64
|
size: number;
|
|
17
65
|
contentHash: string;
|
|
66
|
+
/** v1.13.0+: file mtime in ms, used by the scan memo on subsequent scans. */
|
|
67
|
+
mtimeMs: number;
|
|
68
|
+
/**
|
|
69
|
+
* v1.13.0+: did the scan memo fire for this file? Operators can sum these
|
|
70
|
+
* to see how often the warm path is exercised.
|
|
71
|
+
*/
|
|
72
|
+
memoHit: boolean;
|
|
18
73
|
}
|
|
19
74
|
export interface ScanResult {
|
|
20
75
|
workspaceRoot: string;
|
|
@@ -22,6 +77,14 @@ export interface ScanResult {
|
|
|
22
77
|
filesHash: string;
|
|
23
78
|
skippedTooLarge: number;
|
|
24
79
|
truncated: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* v1.13.0+: count of files that hit the scan memo (mtime+size unchanged
|
|
82
|
+
* since last scan, content hash reused without reading the file). Useful
|
|
83
|
+
* for status/observability — when this is near zero on what should be a
|
|
84
|
+
* warm scan, something is invalidating the memo (e.g. a build step
|
|
85
|
+
* touching every file).
|
|
86
|
+
*/
|
|
87
|
+
memoHitCount: number;
|
|
25
88
|
}
|
|
26
89
|
export declare function scanWorkspace(workspaceRoot: string, options: ScanOptions): Promise<ScanResult>;
|
|
27
90
|
//# sourceMappingURL=workspace-scanner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-scanner.d.ts","sourceRoot":"","sources":["../../src/indexer/workspace-scanner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"workspace-scanner.d.ts","sourceRoot":"","sources":["../../src/indexer/workspace-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAK3C;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAWlF;AAcD;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAClD;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB;AA6BD,wBAAsB,aAAa,CACjC,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC,CA8ErB"}
|
|
@@ -3,11 +3,36 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Respects default include extensions + exclude directories, plus user overrides
|
|
5
5
|
* passed via `MatchConfig`. Enforces a soft file-count cap and a per-file size cap.
|
|
6
|
+
*
|
|
7
|
+
* v1.13.0+: when `manifestMemo` is supplied, files whose `(mtime_ms, size)`
|
|
8
|
+
* match the previously-stored values reuse the stored content hash and skip
|
|
9
|
+
* re-hashing — typically ~95% of files on a warm rescan, cutting scan
|
|
10
|
+
* wall-clock by ≥10× on large workspaces.
|
|
6
11
|
*/
|
|
7
12
|
import { readdir, stat } from 'node:fs/promises';
|
|
8
13
|
import { join, sep as pathSep, relative } from 'node:path';
|
|
14
|
+
import { runPool } from '../utils/run-pool.js';
|
|
9
15
|
import { defaultMatchConfig, isFileIncluded, isPathExcluded } from './globs.js';
|
|
10
16
|
import { hashFile, mergeHashes } from './hasher.js';
|
|
17
|
+
/**
|
|
18
|
+
* v1.13.0+: build the per-file fingerprint map the scanner consults to skip
|
|
19
|
+
* re-hashing. Rows lacking `mtimeMs` or `size` (pre-1.13 manifests, or rows
|
|
20
|
+
* the uploader hasn't refreshed yet) are dropped — those files always
|
|
21
|
+
* re-hash on the next scan.
|
|
22
|
+
*/
|
|
23
|
+
export function buildScanMemo(rows) {
|
|
24
|
+
const memo = new Map();
|
|
25
|
+
for (const row of rows) {
|
|
26
|
+
if (typeof row.mtimeMs !== 'number' || typeof row.size !== 'number')
|
|
27
|
+
continue;
|
|
28
|
+
memo.set(row.relpath, {
|
|
29
|
+
contentHash: row.contentHash,
|
|
30
|
+
mtimeMs: row.mtimeMs,
|
|
31
|
+
size: row.size,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return memo;
|
|
35
|
+
}
|
|
11
36
|
/**
|
|
12
37
|
* Normalise a path separator to POSIX-style `/`.
|
|
13
38
|
*
|
|
@@ -52,18 +77,51 @@ export async function scanWorkspace(workspaceRoot, options) {
|
|
|
52
77
|
absolutes.sort();
|
|
53
78
|
const truncated = absolutes.length > options.maxFiles;
|
|
54
79
|
const picked = truncated ? absolutes.slice(0, options.maxFiles) : absolutes;
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
80
|
+
const memo = options.forceRescan ? undefined : options.manifestMemo;
|
|
81
|
+
const concurrency = Math.max(1, options.hashConcurrency ?? 20);
|
|
82
|
+
const settled = await runPool(picked, concurrency, async (absolutePath) => {
|
|
58
83
|
const stats = await stat(absolutePath);
|
|
59
84
|
if (stats.size > options.maxFileSizeBytes) {
|
|
85
|
+
return { skipped: true };
|
|
86
|
+
}
|
|
87
|
+
const rel = toPosix(relative(workspaceRoot, absolutePath));
|
|
88
|
+
const memoEntry = memo?.get(rel);
|
|
89
|
+
const memoHit = memoEntry !== undefined &&
|
|
90
|
+
memoEntry.mtimeMs === stats.mtimeMs &&
|
|
91
|
+
memoEntry.size === stats.size;
|
|
92
|
+
const hash = memoHit
|
|
93
|
+
? memoEntry.contentHash
|
|
94
|
+
: await hashFile(absolutePath, stats);
|
|
95
|
+
return {
|
|
96
|
+
file: {
|
|
97
|
+
relpath: rel,
|
|
98
|
+
absolutePath,
|
|
99
|
+
size: stats.size,
|
|
100
|
+
contentHash: hash,
|
|
101
|
+
mtimeMs: stats.mtimeMs,
|
|
102
|
+
memoHit,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
// Drain the settled array preserving input order so `filesHash` stays
|
|
107
|
+
// deterministic. Any rejection (a `stat`/`hashFile` throw) bubbles —
|
|
108
|
+
// workspace scanning has no per-file recovery story; an unreadable file
|
|
109
|
+
// means the rescan is broken and the caller needs to surface that.
|
|
110
|
+
const files = [];
|
|
111
|
+
let skippedTooLarge = 0;
|
|
112
|
+
let memoHitCount = 0;
|
|
113
|
+
for (const result of settled) {
|
|
114
|
+
if (result.status === 'rejected') {
|
|
115
|
+
throw result.reason instanceof Error ? result.reason : new Error(String(result.reason));
|
|
116
|
+
}
|
|
117
|
+
const entry = result.value;
|
|
118
|
+
if ('skipped' in entry) {
|
|
60
119
|
skippedTooLarge += 1;
|
|
61
120
|
continue;
|
|
62
121
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
files.push({ relpath: rel, absolutePath, size: stats.size, contentHash: hash });
|
|
122
|
+
files.push(entry.file);
|
|
123
|
+
if (entry.file.memoHit)
|
|
124
|
+
memoHitCount += 1;
|
|
67
125
|
}
|
|
68
126
|
const filesHash = mergeHashes(files.map((f) => ({ relpath: f.relpath, hash: f.contentHash })));
|
|
69
127
|
return {
|
|
@@ -72,6 +130,7 @@ export async function scanWorkspace(workspaceRoot, options) {
|
|
|
72
130
|
filesHash,
|
|
73
131
|
skippedTooLarge,
|
|
74
132
|
truncated,
|
|
133
|
+
memoHitCount,
|
|
75
134
|
};
|
|
76
135
|
}
|
|
77
136
|
//# sourceMappingURL=workspace-scanner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-scanner.js","sourceRoot":"","sources":["../../src/indexer/workspace-scanner.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"workspace-scanner.js","sourceRoot":"","sources":["../../src/indexer/workspace-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAoB,kBAAkB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAClG,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAwB;IACpD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC9C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ;YAAE,SAAS;QAC9E,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE;YACpB,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,IAAI,EAAE,GAAG,CAAC,IAAI;SACf,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,OAAO,CAAC,CAAS;IACxB,OAAO,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CA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AE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;IAE/F,OAAO;QACL,aAAa;QACb,KAAK;QACL,SAAS;QACT,eAAe;QACf,SAAS;QACT,YAAY;KACb,CAAC;AACJ,CAAC"}
|
package/dist/manifest/db.d.ts
CHANGED
|
@@ -13,6 +13,46 @@ export declare class ManifestDb {
|
|
|
13
13
|
upsertWorkspace(ws: WorkspaceRow): void;
|
|
14
14
|
deleteWorkspace(workspaceRoot: string): void;
|
|
15
15
|
getFiles(workspaceRoot: string): FileRow[];
|
|
16
|
+
/**
|
|
17
|
+
* v1.13.0+ memo-seeder. Used by `prepareContext`'s inline / implicit /
|
|
18
|
+
* small-workspace branches — those paths skip the uploader entirely (which
|
|
19
|
+
* is the only writer of `upsertFile`), so without this the scan memo would
|
|
20
|
+
* silently degrade to cold every call (every file re-hashes — defeating
|
|
21
|
+
* the v1.13.0 perf headline).
|
|
22
|
+
*
|
|
23
|
+
* Conditional preservation of `file_id` / `uploaded_at` / `expires_at`
|
|
24
|
+
* (round-3 fix for the v1.13.0 silent-corruption HIGH found by Gemini /
|
|
25
|
+
* GPT / Copilot in the round-2 review):
|
|
26
|
+
*
|
|
27
|
+
* - **content_hash UNCHANGED** → preserve the upload metadata. A prior
|
|
28
|
+
* explicit-cache run uploaded these bytes to Files API; a switch back
|
|
29
|
+
* to `cachingMode: 'explicit'` should hit dedup and skip re-upload.
|
|
30
|
+
* - **content_hash CHANGED** → null out `file_id` / `uploaded_at` /
|
|
31
|
+
* `expires_at`. The previous fileId points to an upload of OLD bytes
|
|
32
|
+
* on Google's servers; preserving it would let `findFileRowByHash`
|
|
33
|
+
* return that stale fileId for the NEW content — silently feeding
|
|
34
|
+
* OLD bytes into Gemini under the file's NEW relpath.
|
|
35
|
+
*
|
|
36
|
+
* The pre-fix version preserved unconditionally, locking in a stale-fileId
|
|
37
|
+
* row whenever an edit landed between an explicit run and an implicit run.
|
|
38
|
+
* Two corruption scenarios were reachable:
|
|
39
|
+
* (A) same-relpath self-corruption: file edited mid-session, subsequent
|
|
40
|
+
* explicit run reuses the stale fileId for the changed file.
|
|
41
|
+
* (B) cross-file leak: a different file with the same NEW content_hash
|
|
42
|
+
* hits the dedup query and gets routed through the stale fileId.
|
|
43
|
+
*
|
|
44
|
+
* The CASE-based clear closes both. Confirmed by /6step round-3 analysis:
|
|
45
|
+
* `findFileRowByHash` returns rows where `content_hash = ?` and `file_id IS
|
|
46
|
+
* NOT NULL` — the conditional null-out ensures any stale fileId is gone
|
|
47
|
+
* BEFORE the dedup query could return it.
|
|
48
|
+
*/
|
|
49
|
+
refreshFileFingerprints(rows: ReadonlyArray<{
|
|
50
|
+
workspaceRoot: string;
|
|
51
|
+
relpath: string;
|
|
52
|
+
contentHash: string;
|
|
53
|
+
mtimeMs: number;
|
|
54
|
+
size: number;
|
|
55
|
+
}>): void;
|
|
16
56
|
upsertFile(file: FileRow): void;
|
|
17
57
|
deleteFile(workspaceRoot: string, relpath: string): void;
|
|
18
58
|
/** Find a file ID for a content hash already uploaded (dedupe helper). */
|
|
@@ -68,6 +108,16 @@ export declare class ManifestDb {
|
|
|
68
108
|
uncachedTokens: number;
|
|
69
109
|
costUsdMicro: number;
|
|
70
110
|
durationMs: number;
|
|
111
|
+
/**
|
|
112
|
+
* v1.13.0+: caching mode used for the call. `'inline'` is the
|
|
113
|
+
* forced-inline outcome (e.g. `code({ codeExecution: true })`), added in
|
|
114
|
+
* the v1.13.0 round-2 review fix (FN2) so telemetry distinguishes
|
|
115
|
+
* "user asked for explicit and got it" from "user asked for explicit but
|
|
116
|
+
* the runtime forced inline".
|
|
117
|
+
*/
|
|
118
|
+
cachingMode?: 'explicit' | 'implicit' | 'inline' | null;
|
|
119
|
+
/** v1.13.0+: `usage_metadata.cachedContentTokenCount` from the Gemini response. */
|
|
120
|
+
cachedContentTokenCount?: number | null;
|
|
71
121
|
}): void;
|
|
72
122
|
/**
|
|
73
123
|
* Drop a reservation row when the tool call failed before producing any
|
|
@@ -108,5 +158,56 @@ export declare class ManifestDb {
|
|
|
108
158
|
inFlightReservedMicros: number;
|
|
109
159
|
last24hCostMicros: number;
|
|
110
160
|
};
|
|
161
|
+
/**
|
|
162
|
+
* v1.13.0+: caching telemetry aggregation for the `status` tool.
|
|
163
|
+
*
|
|
164
|
+
* Surfaces caching mode adoption, implicit-cache hit rate (when applicable),
|
|
165
|
+
* and explicit-cache rebuild count over the last 24 h. Hit rate is computed
|
|
166
|
+
* as `sum(cached_content_token_count) / (sum(cached_content_token_count) +
|
|
167
|
+
* sum(uncached_tokens))` across implicit-mode calls — the ratio of input
|
|
168
|
+
* tokens that Gemini's automatic implicit cache served vs the ones we paid
|
|
169
|
+
* full input rate for. Settled rows only (`duration_ms > 0`) so in-flight
|
|
170
|
+
* reservations don't skew the hit rate downward.
|
|
171
|
+
*
|
|
172
|
+
* `mode` is the dominant caching mode in the window:
|
|
173
|
+
* - `'explicit'` if all metric rows used explicit (or no caching mode set)
|
|
174
|
+
* - `'implicit'` if all metric rows used implicit
|
|
175
|
+
* - `'inline'` if all metric rows used the forced-inline path (e.g.
|
|
176
|
+
* `code({ codeExecution: true })` — the user requested
|
|
177
|
+
* explicit but the runtime forbade `cachedContent` + tools
|
|
178
|
+
* simultaneously). Distinguished from `'explicit'` so the
|
|
179
|
+
* v1.14.0 default-flip telemetry isn't biased toward
|
|
180
|
+
* "explicit adoption" by codeExecution traffic.
|
|
181
|
+
* - `'mixed'` if 2+ of the above modes appear (operator changed
|
|
182
|
+
* defaults mid-day, codeExecution + non-codeExecution
|
|
183
|
+
* traffic, etc.)
|
|
184
|
+
* - `null` if no calls in the window
|
|
185
|
+
*
|
|
186
|
+
* Rows older than v1.13.0 lack `caching_mode` (NULL) and are treated as
|
|
187
|
+
* `'explicit'` for the dominant-mode tally.
|
|
188
|
+
*
|
|
189
|
+
* Upgrade-day note (v1.12.x → v1.13.0): if pre-upgrade calls landed inside
|
|
190
|
+
* the 24h window AND post-upgrade traffic is exclusively forced-inline
|
|
191
|
+
* (e.g. `code({ codeExecution: true })`), `mode` returns `'mixed'` because
|
|
192
|
+
* the legacy NULL rows COALESCE into the explicit tally. This self-corrects
|
|
193
|
+
* once the legacy rows fall out of the 24h window. Operators surprised by
|
|
194
|
+
* `'mixed'` post-upgrade should look at `inlineCallCount` and
|
|
195
|
+
* `explicitRebuildCount` to confirm the actual post-upgrade traffic shape.
|
|
196
|
+
*/
|
|
197
|
+
cacheStatsLast24h(nowMs: number): {
|
|
198
|
+
mode: 'explicit' | 'implicit' | 'inline' | 'mixed' | null;
|
|
199
|
+
callCount: number;
|
|
200
|
+
implicitCallsTotal: number;
|
|
201
|
+
implicitCallsWithHit: number;
|
|
202
|
+
implicitCachedTokens: number;
|
|
203
|
+
implicitUncachedTokens: number;
|
|
204
|
+
implicitHitRate: number;
|
|
205
|
+
explicitRebuildCount: number;
|
|
206
|
+
/** v1.13.0 round-2 (FN2 fix): forced-inline call count. Useful for
|
|
207
|
+
* understanding why explicit-rebuild count differs from explicit-call
|
|
208
|
+
* count (codeExecution calls request explicit, get inline, never trigger
|
|
209
|
+
* caches.create). */
|
|
210
|
+
inlineCallCount: number;
|
|
211
|
+
};
|
|
111
212
|
}
|
|
112
213
|
//# sourceMappingURL=db.d.ts.map
|