gestalt-mobile 0.56.0 → 0.58.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/README.md +2 -1
- package/dist/client/assets/index-Cp-JfcNd.css +1 -0
- package/dist/client/assets/index-DeNYHfGR.js +123 -0
- package/dist/client/index.html +2 -2
- package/dist/server/client/features/chat/chat-projection.js +11 -0
- package/dist/server/server/cli.js +1 -1
- package/dist/server/server/composition.contracts.js +219 -1
- package/dist/server/server/composition.js +26 -1
- package/dist/server/server/config.js +1 -1
- package/dist/server/server/features/agent-activity/tool-efficiency-projection.js +179 -0
- package/dist/server/server/features/agent-activity/tool-efficiency.js +13 -0
- package/dist/server/server/features/catalog/get-xerj-status/endpoint.js +3 -1
- package/dist/server/server/features/control-plane-trace/export-trace.js +18 -3
- package/dist/server/server/features/sessions/get-history/endpoint.js +3 -0
- package/dist/server/server/features/sessions/get-retrieval-readiness/endpoint.js +19 -0
- package/dist/server/server/features/sessions/get-session/endpoint.js +3 -1
- package/dist/server/server/features/sessions/register-routes.js +7 -1
- package/dist/server/server/platform/codex/activity-facts.js +2 -0
- package/dist/server/server/platform/codex/codex-capabilities.js +4 -0
- package/dist/server/server/platform/codex/codex-serena.js +16 -3
- package/dist/server/server/platform/codex/mcp-startup-failure.js +96 -0
- package/dist/server/server/platform/codex/normalizer.js +69 -0
- package/dist/server/server/platform/codex/session-runtime.js +101 -4
- package/dist/server/server/platform/codex/tool-efficiency-facts.js +178 -0
- package/dist/server/server/platform/persistence/migrate.js +1 -0
- package/dist/server/server/platform/persistence/sqlite-event-journal.js +16 -0
- package/dist/server/server/platform/persistence/sqlite-tool-efficiency-store.js +23 -0
- package/dist/server/server/platform/retrieval/codex-xerj.js +17 -3
- package/dist/server/server/platform/retrieval/read-authority.js +55 -0
- package/dist/server/server/platform/retrieval/readiness-evidence.js +92 -0
- package/dist/server/server/platform/retrieval/repository-readiness.js +464 -0
- package/dist/server/server/platform/retrieval/xerj-indexer.js +19 -1
- package/dist/server/shared/contracts/mcp-startup-failure.js +158 -0
- package/dist/server/shared/contracts/retrieval-readiness.js +47 -0
- package/dist/server/shared/contracts/tool-efficiency.js +125 -0
- package/dist/server/shared/contracts/tool-efficiency.test-fixture.js +77 -0
- package/package.json +1 -1
- package/dist/client/assets/index-BIDTmI1d.css +0 -1
- package/dist/client/assets/index-UlRqhCZk.js +0 -116
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import { execFile } from 'node:child_process';
|
|
7
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
8
|
+
import { readFile, realpath, stat } from 'node:fs/promises';
|
|
9
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
10
|
+
import { promisify } from 'node:util';
|
|
11
|
+
import { beforeDeadline } from './codex-xerj.js';
|
|
12
|
+
import { ReadinessEvidence } from './readiness-evidence.js';
|
|
13
|
+
import { hasUnrestrictedReadAuthority } from './read-authority.js';
|
|
14
|
+
const execute = promisify(execFile);
|
|
15
|
+
const hash = (value) => createHash('sha256').update(value).digest('hex');
|
|
16
|
+
const record = (value) => value && typeof value === 'object' && !Array.isArray(value)
|
|
17
|
+
? value
|
|
18
|
+
: undefined;
|
|
19
|
+
const small = (value) => typeof value === 'string' && value.trim().length > 0 && value.length <= 4096;
|
|
20
|
+
const contained = (root, path) => {
|
|
21
|
+
const rel = relative(root, path);
|
|
22
|
+
return rel === '' || (!isAbsolute(rel) && rel !== '..' && !rel.startsWith('../'));
|
|
23
|
+
};
|
|
24
|
+
async function bytes(path, root, authorize, optional = false, limit = 4_194_304) {
|
|
25
|
+
try {
|
|
26
|
+
authorize();
|
|
27
|
+
const canonical = await realpath(path);
|
|
28
|
+
if (!contained(root, canonical))
|
|
29
|
+
throw new Error('READINESS_PATH_OUTSIDE_WORKSPACE');
|
|
30
|
+
authorize();
|
|
31
|
+
const info = await stat(canonical);
|
|
32
|
+
if (!info.isFile() || info.size > limit)
|
|
33
|
+
throw new Error('READINESS_INPUT_TOO_LARGE');
|
|
34
|
+
authorize();
|
|
35
|
+
const content = await readFile(canonical);
|
|
36
|
+
if (content.length > limit)
|
|
37
|
+
throw new Error('READINESS_INPUT_TOO_LARGE');
|
|
38
|
+
return content;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (optional && error.code === 'ENOENT')
|
|
42
|
+
return null;
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function git(cwd, args) {
|
|
47
|
+
return (await execute('git', ['--no-optional-locks', ...args], {
|
|
48
|
+
cwd,
|
|
49
|
+
timeout: 2000,
|
|
50
|
+
maxBuffer: 262144,
|
|
51
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: '0' },
|
|
52
|
+
})).stdout;
|
|
53
|
+
}
|
|
54
|
+
/** Read only the requested source, known metadata and bounded dirty tracked inputs, on demand. */
|
|
55
|
+
async function capture(workspace, cwd, path, configuration, authorize) {
|
|
56
|
+
const canonical = (value) => {
|
|
57
|
+
authorize();
|
|
58
|
+
return realpath(value);
|
|
59
|
+
};
|
|
60
|
+
const runGit = (directory, args) => {
|
|
61
|
+
authorize();
|
|
62
|
+
return git(directory, args);
|
|
63
|
+
};
|
|
64
|
+
const root = await canonical(workspace);
|
|
65
|
+
const read = (value, optional = false, limit) => bytes(value, root, authorize, optional, limit);
|
|
66
|
+
const working = await canonical(cwd);
|
|
67
|
+
if (!contained(root, working))
|
|
68
|
+
throw new Error('READINESS_CWD_OUTSIDE_WORKSPACE');
|
|
69
|
+
// Serena paths remain relative to its prepared project, even for a narrowed child cwd.
|
|
70
|
+
const source = await canonical(resolve(root, path));
|
|
71
|
+
if (!contained(working, source))
|
|
72
|
+
throw new Error('READINESS_SOURCE_OUTSIDE_CHILD');
|
|
73
|
+
const repository = await canonical((await runGit(dirname(source), ['rev-parse', '--show-toplevel'])).trim());
|
|
74
|
+
if (!contained(root, repository) || !contained(repository, source))
|
|
75
|
+
throw new Error('READINESS_REPOSITORY_OUTSIDE_WORKSPACE');
|
|
76
|
+
const sourceBytes = await read(source);
|
|
77
|
+
const head = (await runGit(repository, ['rev-parse', 'HEAD'])).trim();
|
|
78
|
+
const dirty = (await runGit(repository, [
|
|
79
|
+
'diff',
|
|
80
|
+
'--no-ext-diff',
|
|
81
|
+
'--no-textconv',
|
|
82
|
+
'--name-only',
|
|
83
|
+
'-z',
|
|
84
|
+
'HEAD',
|
|
85
|
+
]))
|
|
86
|
+
.split('\0')
|
|
87
|
+
.filter(Boolean)
|
|
88
|
+
.sort();
|
|
89
|
+
const untracked = (await runGit(repository, ['ls-files', '--others', '--exclude-standard', '-z']))
|
|
90
|
+
.split('\0')
|
|
91
|
+
.filter(Boolean);
|
|
92
|
+
const changed = [...new Set([...dirty, ...untracked])].sort();
|
|
93
|
+
if (changed.length > 128)
|
|
94
|
+
throw new Error('READINESS_DIRTY_SCOPE_TOO_LARGE');
|
|
95
|
+
let inputBytes = 0;
|
|
96
|
+
const dirtyInputs = [];
|
|
97
|
+
for (const name of changed) {
|
|
98
|
+
const content = await read(join(repository, name), true, 4_194_304 - inputBytes);
|
|
99
|
+
inputBytes += content?.length ?? 0;
|
|
100
|
+
if (inputBytes > 4_194_304)
|
|
101
|
+
throw new Error('READINESS_DIRTY_SCOPE_TOO_LARGE');
|
|
102
|
+
dirtyInputs.push([name, hash(content ?? 'deleted')]);
|
|
103
|
+
}
|
|
104
|
+
const metadata = [];
|
|
105
|
+
const builds = [];
|
|
106
|
+
for (const name of [
|
|
107
|
+
...new Set([
|
|
108
|
+
join(repository, 'compile_commands.json'),
|
|
109
|
+
join(repository, 'build/compile_commands.json'),
|
|
110
|
+
join(working, 'compile_commands.json'),
|
|
111
|
+
]),
|
|
112
|
+
]) {
|
|
113
|
+
const content = await read(name, true);
|
|
114
|
+
metadata.push([name, content ? hash(content) : null]);
|
|
115
|
+
if (!content)
|
|
116
|
+
continue;
|
|
117
|
+
const entries = JSON.parse(content.toString());
|
|
118
|
+
if (!Array.isArray(entries) || entries.length > 20000)
|
|
119
|
+
throw new Error('READINESS_BUILD_METADATA_INVALID');
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
const item = record(entry);
|
|
122
|
+
if (!small(item?.file) || !small(item?.directory) || !isAbsolute(item.directory))
|
|
123
|
+
continue;
|
|
124
|
+
if (!small(item.command) &&
|
|
125
|
+
!(Array.isArray(item.arguments) && item.arguments.length > 0 && item.arguments.every(small)))
|
|
126
|
+
continue;
|
|
127
|
+
const compiled = resolve(item.directory, item.file);
|
|
128
|
+
if (basename(compiled) !== basename(source) || !contained(root, compiled))
|
|
129
|
+
continue;
|
|
130
|
+
if ((await canonical(compiled)) !== source)
|
|
131
|
+
continue;
|
|
132
|
+
const build = await canonical(item.directory);
|
|
133
|
+
if (!contained(repository, build))
|
|
134
|
+
throw new Error('READINESS_BUILD_OUTSIDE_REPOSITORY');
|
|
135
|
+
// Keep every matching compile-command alias in the fingerprint; never rewrite selection.
|
|
136
|
+
builds.push(hash(JSON.stringify([build, item])));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
for (const name of [
|
|
140
|
+
'.serena/project.yml',
|
|
141
|
+
'.xerjignore',
|
|
142
|
+
'CMakePresets.json',
|
|
143
|
+
'CMakeUserPresets.json',
|
|
144
|
+
]) {
|
|
145
|
+
const content = await read(join(repository, name), true);
|
|
146
|
+
metadata.push([name, content ? hash(content) : null]);
|
|
147
|
+
}
|
|
148
|
+
const id = hash(repository);
|
|
149
|
+
return {
|
|
150
|
+
source,
|
|
151
|
+
root: repository,
|
|
152
|
+
project: root,
|
|
153
|
+
cwd: working,
|
|
154
|
+
hasBuild: builds.length > 0,
|
|
155
|
+
authorize,
|
|
156
|
+
repository: {
|
|
157
|
+
id,
|
|
158
|
+
label: basename(repository)
|
|
159
|
+
.replace(/[\u0000-\u001f\u007f]/g, '')
|
|
160
|
+
.slice(0, 96),
|
|
161
|
+
buildIds: builds.sort(),
|
|
162
|
+
},
|
|
163
|
+
key: hash(JSON.stringify([
|
|
164
|
+
id,
|
|
165
|
+
working,
|
|
166
|
+
head,
|
|
167
|
+
hash(sourceBytes),
|
|
168
|
+
dirtyInputs,
|
|
169
|
+
metadata,
|
|
170
|
+
builds,
|
|
171
|
+
configuration,
|
|
172
|
+
])),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function payloads(result) {
|
|
176
|
+
const value = record(result);
|
|
177
|
+
if (!value)
|
|
178
|
+
return [];
|
|
179
|
+
const output = value.structuredContent === undefined ? [] : [value.structuredContent];
|
|
180
|
+
if (Array.isArray(value.content) && value.content.length <= 32) {
|
|
181
|
+
for (const part of value.content) {
|
|
182
|
+
const item = record(part);
|
|
183
|
+
if (item?.type !== 'text' || typeof item.text !== 'string' || item.text.length > 65536)
|
|
184
|
+
continue;
|
|
185
|
+
try {
|
|
186
|
+
output.push(JSON.parse(item.text));
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
/* Unsupported output stays unknown. */
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return output;
|
|
194
|
+
}
|
|
195
|
+
function symbolKind(kind) {
|
|
196
|
+
return ((typeof kind === 'number' && Number.isInteger(kind) && kind >= 1 && kind <= 26) ||
|
|
197
|
+
(small(kind) &&
|
|
198
|
+
/^(?:file|module|namespace|package|class|method|property|field|constructor|enum|interface|function|variable|constant|string|number|boolean|array|object|key|null|enummember|struct|event|operator|typeparameter)$/i.test(kind)));
|
|
199
|
+
}
|
|
200
|
+
function symbols(value) {
|
|
201
|
+
if (!Array.isArray(value) || value.length > 1000)
|
|
202
|
+
return [];
|
|
203
|
+
return value.flatMap((item) => {
|
|
204
|
+
const symbol = record(item);
|
|
205
|
+
return symbol && (small(symbol.name_path) || small(symbol.name)) && symbolKind(symbol.kind)
|
|
206
|
+
? [symbol]
|
|
207
|
+
: [];
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
// Installed Serena 1.7 groups overviews by kind and references by path then kind.
|
|
211
|
+
// Counts, shortened prose and unknown shapes are deliberately not capability evidence.
|
|
212
|
+
function groupedSymbols(value, overview, path) {
|
|
213
|
+
const groups = record(value);
|
|
214
|
+
if (!groups || Object.keys(groups).length > 32)
|
|
215
|
+
return [];
|
|
216
|
+
const result = [];
|
|
217
|
+
for (const [kind, members] of Object.entries(groups)) {
|
|
218
|
+
if (!symbolKind(kind) || !Array.isArray(members) || members.length > 1000)
|
|
219
|
+
continue;
|
|
220
|
+
for (const member of members) {
|
|
221
|
+
if (overview && small(member))
|
|
222
|
+
result.push({ name: member, kind });
|
|
223
|
+
else {
|
|
224
|
+
const symbol = record(member);
|
|
225
|
+
if (symbol && (small(symbol.name_path) || small(symbol.name)))
|
|
226
|
+
result.push({ ...symbol, kind, ...(path ? { relative_path: path } : {}) });
|
|
227
|
+
else if (overview && symbol && Object.keys(symbol).length === 1) {
|
|
228
|
+
const name = Object.keys(symbol)[0];
|
|
229
|
+
const children = record(symbol[name]);
|
|
230
|
+
if (small(name) && children && Object.keys(children).every(symbolKind))
|
|
231
|
+
result.push({ name, kind });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (result.length >= 1000)
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
function decodedSymbols(tool, payload) {
|
|
241
|
+
const flat = symbols(payload);
|
|
242
|
+
if (flat.length)
|
|
243
|
+
return flat;
|
|
244
|
+
if (tool === 'get_symbols_overview')
|
|
245
|
+
return groupedSymbols(payload, true);
|
|
246
|
+
if (tool !== 'find_referencing_symbols')
|
|
247
|
+
return [];
|
|
248
|
+
const paths = record(payload);
|
|
249
|
+
if (!paths || Object.keys(paths).length > 128)
|
|
250
|
+
return [];
|
|
251
|
+
return Object.entries(paths)
|
|
252
|
+
.flatMap(([path, groups]) => groupedSymbols(groups, false, path))
|
|
253
|
+
.slice(0, 1000);
|
|
254
|
+
}
|
|
255
|
+
async function usable(tool, result, bound) {
|
|
256
|
+
bound.authorize();
|
|
257
|
+
for (const payload of payloads(result)) {
|
|
258
|
+
const candidates = decodedSymbols(tool, payload);
|
|
259
|
+
if (tool !== 'find_referencing_symbols') {
|
|
260
|
+
for (const candidate of candidates) {
|
|
261
|
+
if (!candidate.relative_path)
|
|
262
|
+
return true;
|
|
263
|
+
if (small(candidate.relative_path)) {
|
|
264
|
+
bound.authorize();
|
|
265
|
+
if ((await realpath(resolve(bound.project, candidate.relative_path))) === bound.source)
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (tool === 'find_referencing_symbols' && candidates.length) {
|
|
271
|
+
if (/\.(?:c|cc|cpp|cxx|h|hh|hpp|hxx)$/i.test(bound.source) && !bound.hasBuild)
|
|
272
|
+
return false;
|
|
273
|
+
for (const candidate of candidates) {
|
|
274
|
+
if (!small(candidate.relative_path))
|
|
275
|
+
continue;
|
|
276
|
+
bound.authorize();
|
|
277
|
+
const target = await realpath(resolve(bound.project, candidate.relative_path));
|
|
278
|
+
if (contained(bound.root, target) && contained(bound.cwd, target))
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
/** One observer per prepared runtime. It never changes projects, permissions or index ownership. */
|
|
286
|
+
export class RepositoryReadiness {
|
|
287
|
+
workspace;
|
|
288
|
+
runtimeId = randomUUID();
|
|
289
|
+
settings = new Map();
|
|
290
|
+
entries = new Map();
|
|
291
|
+
pending = new Map();
|
|
292
|
+
epoch = 0;
|
|
293
|
+
projectChanged = false;
|
|
294
|
+
constructor(workspace) {
|
|
295
|
+
this.workspace = workspace;
|
|
296
|
+
}
|
|
297
|
+
/** Already observed state for activity publication; no filesystem or tool work. */
|
|
298
|
+
peek() {
|
|
299
|
+
return [...this.entries.values()].map((entry) => ({
|
|
300
|
+
threadId: entry.threadId,
|
|
301
|
+
readiness: entry.evidence.snapshot(),
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
async binding(rpc, rootThreadId, threadId, path, current) {
|
|
305
|
+
const deadline = Date.now() + 2500;
|
|
306
|
+
const result = record(await beforeDeadline(rpc.request('thread/read', { threadId, includeTurns: false }), deadline));
|
|
307
|
+
const thread = record(result?.thread);
|
|
308
|
+
if (thread?.id !== threadId ||
|
|
309
|
+
!small(thread.cwd) ||
|
|
310
|
+
(threadId !== rootThreadId && thread.parentThreadId !== rootThreadId) ||
|
|
311
|
+
!['active', 'idle'].includes(String(record(thread.status)?.type)))
|
|
312
|
+
throw new Error('READINESS_THREAD_UNVERIFIED');
|
|
313
|
+
const config = await beforeDeadline(rpc.request('config/read', { includeLayers: false, cwd: thread.cwd }), deadline);
|
|
314
|
+
if (!record(record(config)?.config))
|
|
315
|
+
throw new Error('READINESS_CONFIG_UNVERIFIED');
|
|
316
|
+
const settings = this.settings.get(threadId);
|
|
317
|
+
const authorize = () => {
|
|
318
|
+
if (!current() ||
|
|
319
|
+
this.settings.get(threadId) !== settings ||
|
|
320
|
+
!hasUnrestrictedReadAuthority(settings, record(config)?.config, String(thread.cwd)))
|
|
321
|
+
throw new Error('READINESS_READ_AUTHORITY_UNKNOWN');
|
|
322
|
+
};
|
|
323
|
+
authorize();
|
|
324
|
+
const status = record(await beforeDeadline(rpc.request('mcpServerStatus/list', {
|
|
325
|
+
threadId,
|
|
326
|
+
serverName: 'gestalt-serena',
|
|
327
|
+
detail: 'full',
|
|
328
|
+
}), deadline));
|
|
329
|
+
const server = Array.isArray(status?.data)
|
|
330
|
+
? status.data.map(record).find((item) => item?.name === 'gestalt-serena')
|
|
331
|
+
: undefined;
|
|
332
|
+
if (server?.runtimeStatus !== 'connected' || server.toolsError || !record(server.tools))
|
|
333
|
+
throw new Error('READINESS_CONNECTION_UNVERIFIED');
|
|
334
|
+
return capture(this.workspace, thread.cwd, path, hash(JSON.stringify([config, server.tools, settings])), authorize);
|
|
335
|
+
}
|
|
336
|
+
async observe(rpc, rootThreadId, notification, current) {
|
|
337
|
+
const params = record(notification.params);
|
|
338
|
+
const threadId = params?.threadId;
|
|
339
|
+
if (notification.method === 'thread/settings/updated' &&
|
|
340
|
+
small(threadId) &&
|
|
341
|
+
(this.settings.has(threadId) || this.settings.size < 64))
|
|
342
|
+
this.settings.set(threadId, params?.threadSettings);
|
|
343
|
+
if ((notification.method === 'mcpServer/statusUpdated' && params?.name === 'gestalt-serena') ||
|
|
344
|
+
notification.method === 'thread/settings/updated' ||
|
|
345
|
+
(notification.method === 'item/completed' && record(params?.item)?.type === 'fileChange')) {
|
|
346
|
+
this.epoch += 1;
|
|
347
|
+
for (const entry of this.entries.values()) {
|
|
348
|
+
if (!small(threadId) ||
|
|
349
|
+
threadId === rootThreadId ||
|
|
350
|
+
entry.threadId === threadId ||
|
|
351
|
+
notification.method === 'item/completed') {
|
|
352
|
+
entry.evidence.invalidate();
|
|
353
|
+
if (notification.method === 'mcpServer/statusUpdated' &&
|
|
354
|
+
['failed', 'cancelled'].includes(String(params?.status)))
|
|
355
|
+
entry.evidence.connection('unavailable');
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const item = record(params?.item);
|
|
361
|
+
if (item?.type === 'mcpToolCall' &&
|
|
362
|
+
item.server === 'gestalt-serena' &&
|
|
363
|
+
notification.method === 'item/started' &&
|
|
364
|
+
![
|
|
365
|
+
'get_symbols_overview',
|
|
366
|
+
'find_symbol',
|
|
367
|
+
'find_referencing_symbols',
|
|
368
|
+
'initial_instructions',
|
|
369
|
+
].includes(String(item.tool))) {
|
|
370
|
+
this.epoch += 1;
|
|
371
|
+
if (['activate_project', 'switch_modes'].includes(String(item.tool)))
|
|
372
|
+
this.projectChanged = true;
|
|
373
|
+
for (const entry of this.entries.values())
|
|
374
|
+
entry.evidence.invalidate();
|
|
375
|
+
}
|
|
376
|
+
if (!current() ||
|
|
377
|
+
this.projectChanged ||
|
|
378
|
+
!small(threadId) ||
|
|
379
|
+
item?.type !== 'mcpToolCall' ||
|
|
380
|
+
item.server !== 'gestalt-serena' ||
|
|
381
|
+
!small(item.id) ||
|
|
382
|
+
!['get_symbols_overview', 'find_symbol', 'find_referencing_symbols'].includes(String(item.tool)))
|
|
383
|
+
return;
|
|
384
|
+
const key = `${threadId}:${item.id}`;
|
|
385
|
+
if (notification.method === 'item/started') {
|
|
386
|
+
const path = record(item.arguments)?.relative_path;
|
|
387
|
+
if (!small(path) || this.pending.size >= 128)
|
|
388
|
+
return;
|
|
389
|
+
const epoch = this.epoch;
|
|
390
|
+
const slot = {
|
|
391
|
+
capture: Promise.resolve(null),
|
|
392
|
+
ready: false,
|
|
393
|
+
};
|
|
394
|
+
slot.capture = this.binding(rpc, rootThreadId, threadId, path, current)
|
|
395
|
+
.then((bound) => {
|
|
396
|
+
if (!current() || epoch !== this.epoch)
|
|
397
|
+
return null;
|
|
398
|
+
const entryKey = `${threadId}:${bound.repository.id}`;
|
|
399
|
+
let entry = this.entries.get(entryKey);
|
|
400
|
+
if (!entry) {
|
|
401
|
+
if (this.entries.size >= 64)
|
|
402
|
+
return null;
|
|
403
|
+
entry = { evidence: new ReadinessEvidence(), capture: bound, threadId };
|
|
404
|
+
this.entries.set(entryKey, entry);
|
|
405
|
+
}
|
|
406
|
+
entry.capture = bound;
|
|
407
|
+
const generation = entry.evidence.bind(bound.key, bound.repository);
|
|
408
|
+
entry.evidence.connection('ready');
|
|
409
|
+
slot.ready = true;
|
|
410
|
+
return { capture: bound, entry, generation, tool: String(item.tool), path, epoch };
|
|
411
|
+
})
|
|
412
|
+
.catch(() => null);
|
|
413
|
+
this.pending.set(key, slot);
|
|
414
|
+
await slot.capture;
|
|
415
|
+
}
|
|
416
|
+
else if (notification.method === 'item/completed') {
|
|
417
|
+
const pending = this.pending.get(key);
|
|
418
|
+
this.pending.delete(key);
|
|
419
|
+
if (!pending?.ready)
|
|
420
|
+
return;
|
|
421
|
+
const before = await pending.capture;
|
|
422
|
+
if (!before || !current())
|
|
423
|
+
return;
|
|
424
|
+
try {
|
|
425
|
+
const after = await this.binding(rpc, rootThreadId, threadId, before.path, current);
|
|
426
|
+
if (!current() || before.epoch !== this.epoch || before.capture.key !== after.key) {
|
|
427
|
+
before.entry.evidence.invalidate();
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
const failed = item.status === 'failed' || item.error != null || record(item.result)?.isError === true;
|
|
431
|
+
if (failed)
|
|
432
|
+
before.entry.evidence.semantic(before.generation, before.tool, false, hash(before.capture.source));
|
|
433
|
+
else if (item.status === 'completed' &&
|
|
434
|
+
(await usable(before.tool, item.result, after)) &&
|
|
435
|
+
current() &&
|
|
436
|
+
before.epoch === this.epoch)
|
|
437
|
+
before.entry.evidence.semantic(before.generation, before.tool, true, hash(before.capture.source));
|
|
438
|
+
}
|
|
439
|
+
catch {
|
|
440
|
+
before.entry.evidence.invalidate();
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
async snapshot(rpc, rootThreadId, current) {
|
|
445
|
+
const output = [];
|
|
446
|
+
const deadline = Date.now() + 5000;
|
|
447
|
+
for (const entry of this.entries.values()) {
|
|
448
|
+
try {
|
|
449
|
+
if (Date.now() >= deadline)
|
|
450
|
+
throw new Error('READINESS_REFRESH_TIMEOUT');
|
|
451
|
+
const fresh = await beforeDeadline(this.binding(rpc, rootThreadId, entry.threadId, entry.capture.source, () => current() && Date.now() < deadline), deadline);
|
|
452
|
+
if (fresh.key !== entry.capture.key)
|
|
453
|
+
entry.evidence.invalidate();
|
|
454
|
+
}
|
|
455
|
+
catch {
|
|
456
|
+
entry.evidence.invalidate();
|
|
457
|
+
}
|
|
458
|
+
if (!current())
|
|
459
|
+
return [];
|
|
460
|
+
output.push({ threadId: entry.threadId, readiness: entry.evidence.snapshot() });
|
|
461
|
+
}
|
|
462
|
+
return output;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
@@ -10,6 +10,7 @@ import { join } from 'node:path';
|
|
|
10
10
|
import { homedir } from 'node:os';
|
|
11
11
|
import { checkXerjIndexConfig, saveXerjIndexConfig, xerjContentArguments, xerjIndexConfig, } from './xerj-index-config.js';
|
|
12
12
|
import { xerjDeadline } from './managed-xerj.js';
|
|
13
|
+
import { ReadinessEvidence } from './readiness-evidence.js';
|
|
13
14
|
// Native gitignore syntax, editable by the host operator. Hidden directories and
|
|
14
15
|
// symlinks are already skipped by XERJ. Never replace an existing root policy.
|
|
15
16
|
export const xerjDefaultIgnores = `# Gestalt source discovery. Edit these native XERJ rules to change scope.
|
|
@@ -58,6 +59,7 @@ export class XerjIndexer {
|
|
|
58
59
|
environment;
|
|
59
60
|
report;
|
|
60
61
|
value;
|
|
62
|
+
evidence = new ReadinessEvidence();
|
|
61
63
|
child;
|
|
62
64
|
task;
|
|
63
65
|
closed = false;
|
|
@@ -70,7 +72,7 @@ export class XerjIndexer {
|
|
|
70
72
|
this.value = { root, mode, state: mode === 'off' ? 'disabled' : 'starting' };
|
|
71
73
|
}
|
|
72
74
|
status() {
|
|
73
|
-
return { ...this.value };
|
|
75
|
+
return { ...this.value, readiness: this.evidence.snapshot() };
|
|
74
76
|
}
|
|
75
77
|
start() {
|
|
76
78
|
if (this.task || this.closed || this.value.mode === 'off')
|
|
@@ -81,6 +83,7 @@ export class XerjIndexer {
|
|
|
81
83
|
});
|
|
82
84
|
}
|
|
83
85
|
fail(message) {
|
|
86
|
+
this.evidence.coverage(this.value.lastUpdate ? 'stale' : 'unavailable');
|
|
84
87
|
this.value = { ...this.value, state: 'error', message };
|
|
85
88
|
this.report(message);
|
|
86
89
|
}
|
|
@@ -96,6 +99,8 @@ export class XerjIndexer {
|
|
|
96
99
|
if (this.closed)
|
|
97
100
|
return;
|
|
98
101
|
if (ready.status === 'absent') {
|
|
102
|
+
this.evidence.connection('unavailable');
|
|
103
|
+
this.evidence.coverage('unavailable');
|
|
99
104
|
this.value = {
|
|
100
105
|
...this.value,
|
|
101
106
|
state: 'absent',
|
|
@@ -103,9 +108,11 @@ export class XerjIndexer {
|
|
|
103
108
|
return;
|
|
104
109
|
}
|
|
105
110
|
if (ready.status !== 'ready') {
|
|
111
|
+
this.evidence.connection('unavailable');
|
|
106
112
|
this.fail('XERJ backend unavailable. Run gestalt doctor; check the managed data directory and local port.');
|
|
107
113
|
return;
|
|
108
114
|
}
|
|
115
|
+
this.evidence.connection('ready');
|
|
109
116
|
if (this.value.mode === 'manual') {
|
|
110
117
|
this.value = { ...this.value, state: 'ready', message: 'Automatic indexing is disabled.' };
|
|
111
118
|
return;
|
|
@@ -117,6 +124,7 @@ export class XerjIndexer {
|
|
|
117
124
|
return;
|
|
118
125
|
if (compatibility === 'incompatible') {
|
|
119
126
|
this.fail('XERJ index settings differ from the saved fingerprint. Restore the previous settings or explicitly rebuild this root index; indexing was not started.');
|
|
127
|
+
this.evidence.coverage('stale');
|
|
120
128
|
return;
|
|
121
129
|
}
|
|
122
130
|
if (compatibility === 'missing')
|
|
@@ -175,6 +183,7 @@ export class XerjIndexer {
|
|
|
175
183
|
if (this.closed)
|
|
176
184
|
return;
|
|
177
185
|
if (code === 75) {
|
|
186
|
+
this.evidence.coverage('unknown');
|
|
178
187
|
this.value = {
|
|
179
188
|
...this.value,
|
|
180
189
|
state: 'shared',
|
|
@@ -192,6 +201,9 @@ export class XerjIndexer {
|
|
|
192
201
|
try {
|
|
193
202
|
const event = JSON.parse(line);
|
|
194
203
|
if (event.event === 'progress') {
|
|
204
|
+
this.evidence.invalidate();
|
|
205
|
+
this.evidence.connection('ready');
|
|
206
|
+
this.evidence.coverage(this.value.lastUpdate ? 'stale' : 'unknown');
|
|
195
207
|
const phase = typeof event.phase === 'string' && /^[a-z-]{1,32}$/.test(event.phase)
|
|
196
208
|
? event.phase
|
|
197
209
|
: undefined;
|
|
@@ -220,6 +232,11 @@ export class XerjIndexer {
|
|
|
220
232
|
...(count(event.files) !== undefined ? { files: count(event.files) } : {}),
|
|
221
233
|
...(count(event.records) !== undefined ? { records: count(event.records) } : {}),
|
|
222
234
|
};
|
|
235
|
+
const records = count(event.records);
|
|
236
|
+
this.evidence.coverage(records === undefined ? 'unknown' : records === 0 ? 'unavailable' : 'ready', {
|
|
237
|
+
files: count(event.files),
|
|
238
|
+
records,
|
|
239
|
+
});
|
|
223
240
|
}
|
|
224
241
|
else if (event.event === 'warning') {
|
|
225
242
|
if (typeof event.message === 'string' &&
|
|
@@ -248,6 +265,7 @@ export class XerjIndexer {
|
|
|
248
265
|
});
|
|
249
266
|
}
|
|
250
267
|
this.value = { ...this.value, state: this.value.mode === 'off' ? 'disabled' : 'stopped' };
|
|
268
|
+
this.evidence.connection('unavailable');
|
|
251
269
|
}
|
|
252
270
|
}
|
|
253
271
|
function count(value) {
|