gestalt-mobile 0.46.2 → 0.48.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.
Files changed (30) hide show
  1. package/README.md +81 -2
  2. package/dist/client/assets/index-CE4-9CY1.css +1 -0
  3. package/dist/client/assets/index-DvIxykMj.js +112 -0
  4. package/dist/client/index.html +2 -2
  5. package/dist/server/server/cli.js +15 -0
  6. package/dist/server/server/composition.contracts.js +87 -18
  7. package/dist/server/server/composition.js +82 -7
  8. package/dist/server/server/config.js +5 -0
  9. package/dist/server/server/features/catalog/get-bootstrap/use-case.js +1 -0
  10. package/dist/server/server/features/catalog/get-xerj-status/endpoint.js +11 -0
  11. package/dist/server/server/features/catalog/register-routes.js +3 -0
  12. package/dist/server/server/features/sessions/model/relay-session.js +1 -0
  13. package/dist/server/server/features/skills/list-available/endpoint.js +1 -1
  14. package/dist/server/server/features/skills/model/skill-profile.js +9 -3
  15. package/dist/server/server/platform/codex/codex-capabilities.js +96 -0
  16. package/dist/server/server/platform/codex/codex-serena.js +150 -0
  17. package/dist/server/server/platform/codex/managed-serena.js +69 -0
  18. package/dist/server/server/platform/codex/normalizer.js +36 -0
  19. package/dist/server/server/platform/codex/session-runtime.js +146 -6
  20. package/dist/server/server/platform/kimi/kimi-skill-catalog.js +9 -0
  21. package/dist/server/server/platform/retrieval/codex-xerj.js +157 -0
  22. package/dist/server/server/platform/retrieval/managed-xerj.js +120 -0
  23. package/dist/server/server/platform/retrieval/xerj-index-config.js +67 -0
  24. package/dist/server/server/platform/retrieval/xerj-indexer.js +256 -0
  25. package/dist/server/server/platform/skills/cached-skill-catalog.js +0 -0
  26. package/dist/server/server/platform/skills/codex-skill-catalog.js +49 -6
  27. package/dist/server/shared/contracts/xerj-status.js +6 -0
  28. package/package.json +1 -1
  29. package/dist/client/assets/index-CGCxdtE6.js +0 -112
  30. package/dist/client/assets/index-s4qgQfcy.css +0 -1
@@ -0,0 +1,157 @@
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 { readFile } from 'node:fs/promises';
7
+ export const xerjServerName = 'gestalt-xerj';
8
+ export const xerjTools = ['xerj_search', 'xerj_map', 'xerj_code_search'];
9
+ /** Ephemeral native thread configuration; no installation or daemon ownership. */
10
+ export class CodexXerj {
11
+ capability;
12
+ constructor(capability) {
13
+ this.capability = capability;
14
+ }
15
+ async prepare(input) {
16
+ const skill = input.skills.find((entry) => entry.name === 'gestalt:xerj');
17
+ const state = {
18
+ ready: false,
19
+ deadline: input.deadline,
20
+ config: { ...input.config },
21
+ skillsConfig: input.skillsConfig.map((entry) => ({
22
+ ...entry,
23
+ enabled: entry.path === skill?.path ? false : entry.enabled,
24
+ })),
25
+ fallback: () => { },
26
+ };
27
+ let native = {};
28
+ let compatible = false;
29
+ try {
30
+ const read = (await beforeDeadline(input.rpc.request('config/read', { includeLayers: false }), input.deadline));
31
+ native = read.config ?? {};
32
+ compatible = read.config !== undefined;
33
+ }
34
+ catch {
35
+ /* An incompatible runtime cannot safely advertise retrieval. */
36
+ }
37
+ const servers = native.mcp_servers && typeof native.mcp_servers === 'object'
38
+ ? native.mcp_servers
39
+ : {};
40
+ const mcp = {};
41
+ // Disable aliases of the managed connection without disturbing unrelated MCP.
42
+ for (const [name, server] of Object.entries(servers)) {
43
+ if (server?.args?.[0] === 'xerj' && server.args[1] === 'mcp')
44
+ mcp[name] = { ...server, enabled: false, required: false };
45
+ }
46
+ const instructions = typeof native.developer_instructions === 'string' ? native.developer_instructions : '';
47
+ state.fallback = () => {
48
+ state.ready = false;
49
+ state.skillsConfig = state.skillsConfig.map((entry) => ({
50
+ ...entry,
51
+ enabled: entry.path === skill?.path ? false : entry.enabled,
52
+ }));
53
+ state.config = {
54
+ ...input.config,
55
+ skills: { config: [{ name: 'gestalt:xerj', enabled: false }] },
56
+ mcp_servers: {
57
+ ...mcp,
58
+ [xerjServerName]: {
59
+ command: 'gestalt',
60
+ args: ['xerj', 'mcp'],
61
+ enabled: false,
62
+ required: false,
63
+ },
64
+ },
65
+ developer_instructions: `${instructions}\n<gestalt_xerj_unavailable>\nXerj retrieval is unavailable in this runtime. Earlier retrieval guidance is inactive; use rg and current source reads.\n</gestalt_xerj_unavailable>`,
66
+ };
67
+ };
68
+ state.fallback();
69
+ if (!compatible || !skill || Date.now() >= input.deadline)
70
+ return state;
71
+ try {
72
+ const ready = await this.capability.check({
73
+ cwd: input.cwd,
74
+ deadline: input.deadline,
75
+ start: input.start,
76
+ });
77
+ if (ready.status !== 'ready') {
78
+ if (ready.status === 'unavailable')
79
+ state.diagnostic = 'backend-unavailable';
80
+ return state;
81
+ }
82
+ const guidance = await beforeDeadline(readFile(skill.path, 'utf8'), input.deadline);
83
+ if (guidance.length > 16_384)
84
+ return state;
85
+ state.skillsConfig = state.skillsConfig.map((entry) => ({
86
+ ...entry,
87
+ enabled: entry.path === skill.path ? true : entry.enabled,
88
+ }));
89
+ state.config = {
90
+ ...input.config,
91
+ skills: { config: [{ name: 'gestalt:xerj', enabled: true }] },
92
+ mcp_servers: {
93
+ ...mcp,
94
+ [xerjServerName]: {
95
+ command: ready.manager,
96
+ args: ['xerj', 'mcp', '--url', ready.endpoint],
97
+ cwd: input.cwd,
98
+ env_vars: ['CODEX_HOME', 'GESTALT_HOME', 'XERJ_API_KEY', 'XERJ_AUTH'],
99
+ enabled: true,
100
+ required: false,
101
+ startup_readiness: 'connection',
102
+ startup_timeout_ms: Math.max(1, input.deadline - Date.now()),
103
+ enabled_tools: xerjTools,
104
+ default_tools_approval_mode: 'approve',
105
+ },
106
+ },
107
+ developer_instructions: `${instructions}\n<gestalt_xerj_capability>\n${guidance}\n</gestalt_xerj_capability>`,
108
+ };
109
+ state.ready = true;
110
+ }
111
+ catch {
112
+ state.fallback();
113
+ state.diagnostic = 'connection-unavailable';
114
+ }
115
+ return state;
116
+ }
117
+ async verify(rpc, threadId, state) {
118
+ if (!state.ready)
119
+ return false;
120
+ try {
121
+ while (Date.now() < state.deadline) {
122
+ const result = (await beforeDeadline(rpc.request('mcpServerStatus/list', {
123
+ threadId,
124
+ serverName: xerjServerName,
125
+ detail: 'full',
126
+ }), state.deadline));
127
+ const server = result.data?.find((entry) => entry.name === xerjServerName);
128
+ if (server?.runtimeStatus === 'connected' &&
129
+ !server.toolsError &&
130
+ xerjTools.every((tool) => Object.hasOwn(server.tools ?? {}, tool)))
131
+ return true;
132
+ if (server?.runtimeStatus !== 'starting')
133
+ return false;
134
+ await beforeDeadline(new Promise((resolve) => setTimeout(resolve, 25)), state.deadline);
135
+ }
136
+ return false;
137
+ }
138
+ catch {
139
+ return false;
140
+ }
141
+ }
142
+ }
143
+ export async function beforeDeadline(promise, deadline) {
144
+ let timer;
145
+ try {
146
+ return await Promise.race([
147
+ promise,
148
+ new Promise((_, reject) => {
149
+ timer = setTimeout(() => reject(new Error('XERJ_READINESS_TIMEOUT')), Math.max(0, deadline - Date.now()));
150
+ }),
151
+ ]);
152
+ }
153
+ finally {
154
+ if (timer)
155
+ clearTimeout(timer);
156
+ }
157
+ }
@@ -0,0 +1,120 @@
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 { spawn } from 'node:child_process';
7
+ import { access } from 'node:fs/promises';
8
+ import { constants } from 'node:fs';
9
+ import { isAbsolute, join } from 'node:path';
10
+ export const managedXerjVersion = '1.0.0-rc.87';
11
+ /** The manager alone owns backend identity, authentication and shared lifetime. */
12
+ export class ManagedXerj {
13
+ environment;
14
+ constructor(environment = process.env) {
15
+ this.environment = environment;
16
+ }
17
+ async check(input) {
18
+ const manager = await this.manager();
19
+ if (!manager)
20
+ return { status: 'absent' };
21
+ const remaining = input.deadline - Date.now();
22
+ // The shipped manager rejects sub-100ms operations because it reserves
23
+ // cleanup time inside the overall deadline. Do not spend the remaining
24
+ // budget spawning a request that cannot satisfy that contract.
25
+ if (remaining < minimumXerjTimeoutMs)
26
+ return { status: 'unavailable', reason: 'readiness-timeout' };
27
+ return new Promise((resolve) => {
28
+ const child = spawn(manager, ['xerj', input.start ? 'ensure-ready' : 'probe'], {
29
+ cwd: input.cwd,
30
+ env: { ...this.environment, XERJ_READY_TIMEOUT_MS: String(remaining) },
31
+ shell: false,
32
+ stdio: ['ignore', 'pipe', 'ignore'],
33
+ });
34
+ let output = '';
35
+ let finished = false;
36
+ const settle = (result) => {
37
+ if (finished)
38
+ return;
39
+ finished = true;
40
+ clearTimeout(timer);
41
+ resolve(result);
42
+ };
43
+ const unavailable = (reason) => ({
44
+ status: 'unavailable',
45
+ reason,
46
+ });
47
+ const timer = setTimeout(() => {
48
+ // Reap the owned probe; never signal the manager's shared backend.
49
+ child.kill('SIGTERM');
50
+ const kill = setTimeout(() => child.kill('SIGKILL'), 100).unref();
51
+ child.once('close', () => clearTimeout(kill));
52
+ settle(unavailable('readiness-timeout'));
53
+ }, remaining);
54
+ child.on('error', () => settle(unavailable('manager-unavailable')));
55
+ child.stdout.on('data', (data) => {
56
+ output += data.toString();
57
+ if (output.length > 16_384) {
58
+ child.kill('SIGKILL');
59
+ settle(unavailable('invalid-manager-response'));
60
+ }
61
+ });
62
+ child.once('close', (code) => {
63
+ try {
64
+ const value = JSON.parse(output);
65
+ if (code !== 0 || value.schemaVersion !== 1)
66
+ throw new Error();
67
+ if (value.status === 'absent')
68
+ return settle({ status: 'absent' });
69
+ if (value.status === 'unavailable')
70
+ return settle(unavailable('managed-backend-unavailable'));
71
+ if (value.status !== 'ready' ||
72
+ value.version !== managedXerjVersion ||
73
+ typeof value.endpoint !== 'string' ||
74
+ !/^http:\/\/(127\.0\.0\.1|\[::1\])(?::\d{1,5})?$/.test(value.endpoint))
75
+ throw new Error();
76
+ const url = new URL(value.endpoint);
77
+ if (Number(url.port || 80) < 1 || Number(url.port || 80) > 65535)
78
+ throw new Error();
79
+ settle({ status: 'ready', manager, endpoint: value.endpoint });
80
+ }
81
+ catch {
82
+ settle(unavailable('invalid-manager-response'));
83
+ }
84
+ });
85
+ });
86
+ }
87
+ async manager() {
88
+ const explicit = this.environment.GESTALT_MANAGER_BIN;
89
+ const paths = explicit
90
+ ? [explicit]
91
+ : (this.environment.PATH ?? '')
92
+ .split(':')
93
+ .filter(Boolean)
94
+ .map((path) => join(path, 'gestalt'));
95
+ for (const path of paths) {
96
+ if (!isAbsolute(path))
97
+ continue;
98
+ try {
99
+ await access(path, constants.X_OK);
100
+ return path;
101
+ }
102
+ catch {
103
+ /* Try next established executable path. */
104
+ }
105
+ }
106
+ return undefined;
107
+ }
108
+ }
109
+ export function xerjDeadline(environment = process.env) {
110
+ const configured = Number(environment.XERJ_READY_TIMEOUT_MS);
111
+ return (Date.now() +
112
+ (Number.isInteger(configured) &&
113
+ configured >= minimumXerjTimeoutMs &&
114
+ configured <= maximumXerjTimeoutMs
115
+ ? configured
116
+ : defaultXerjTimeoutMs));
117
+ }
118
+ const minimumXerjTimeoutMs = 100;
119
+ const maximumXerjTimeoutMs = 60_000;
120
+ const defaultXerjTimeoutMs = 5_000;
@@ -0,0 +1,67 @@
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 { createHash, randomUUID } from 'node:crypto';
7
+ import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
8
+ import { join } from 'node:path';
9
+ import { managedXerjVersion } from './managed-xerj.js';
10
+ // Content-affecting rc.87 settings. Reused in the command and fingerprint so
11
+ // changing an operational setting cannot accidentally require a rebuild.
12
+ export const xerjContentArguments = [
13
+ '--no-graph',
14
+ '--no-semantic',
15
+ '--max-file-gb',
16
+ '1',
17
+ '--sample',
18
+ '500',
19
+ '--pdf-timeout-secs',
20
+ '120',
21
+ ];
22
+ export function xerjIndexConfig(root, prefix, endpoint) {
23
+ const settings = {
24
+ root,
25
+ prefix,
26
+ endpoint,
27
+ nativeVersion: managedXerjVersion,
28
+ contentArguments: xerjContentArguments,
29
+ followSymlinks: false,
30
+ label: null,
31
+ };
32
+ return {
33
+ schemaVersion: 1,
34
+ fingerprint: createHash('sha256').update(JSON.stringify(settings)).digest('hex'),
35
+ settings,
36
+ };
37
+ }
38
+ const filename = '.gestalt-index-config.json';
39
+ /** Unknown legacy indexes still undergo native validation; never bless them early. */
40
+ export async function checkXerjIndexConfig(directory, expected) {
41
+ try {
42
+ const saved = JSON.parse(await readFile(join(directory, filename), 'utf8'));
43
+ return saved.schemaVersion === expected.schemaVersion &&
44
+ saved.fingerprint === expected.fingerprint &&
45
+ createHash('sha256').update(JSON.stringify(saved.settings)).digest('hex') ===
46
+ saved.fingerprint
47
+ ? 'compatible'
48
+ : 'incompatible';
49
+ }
50
+ catch (error) {
51
+ if (error.code === 'ENOENT')
52
+ return 'missing';
53
+ return 'incompatible';
54
+ }
55
+ }
56
+ /** Record only after a successful native generation, atomically and without credentials. */
57
+ export async function saveXerjIndexConfig(directory, config) {
58
+ await mkdir(directory, { recursive: true, mode: 0o700 });
59
+ const temporary = join(directory, `${filename}.${randomUUID()}.tmp`);
60
+ try {
61
+ await writeFile(temporary, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
62
+ await rename(temporary, join(directory, filename));
63
+ }
64
+ finally {
65
+ await rm(temporary, { force: true });
66
+ }
67
+ }
@@ -0,0 +1,256 @@
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 { spawn } from 'node:child_process';
7
+ import { createHash } from 'node:crypto';
8
+ import { realpath, writeFile } from 'node:fs/promises';
9
+ import { join } from 'node:path';
10
+ import { homedir } from 'node:os';
11
+ import { checkXerjIndexConfig, saveXerjIndexConfig, xerjContentArguments, xerjIndexConfig, } from './xerj-index-config.js';
12
+ import { xerjDeadline } from './managed-xerj.js';
13
+ // Native gitignore syntax, editable by the host operator. Hidden directories and
14
+ // symlinks are already skipped by XERJ. Never replace an existing root policy.
15
+ export const xerjDefaultIgnores = `# Gestalt source discovery. Edit these native XERJ rules to change scope.
16
+ # Keep useful vendored source; XERJ otherwise excludes vendor by default.
17
+ !vendor/
18
+ node_modules/
19
+ target/
20
+ build/
21
+ dist/
22
+ coverage/
23
+ __pycache__/
24
+ .cache/
25
+ .next/
26
+ .astro/
27
+ *.o
28
+ *.obj
29
+ *.a
30
+ *.so
31
+ *.dll
32
+ *.exe
33
+ *.class
34
+ *.pyc
35
+ *.wasm
36
+ *.map
37
+ *.min.js
38
+ *.lock
39
+ *.tmp
40
+ *.swp
41
+ *.log
42
+ *.zip
43
+ *.tar
44
+ *.gz
45
+ *.sqlite*
46
+ *.db
47
+ *.pem
48
+ *.key
49
+ id_rsa*
50
+ id_ed25519*
51
+ credentials*
52
+ secrets/
53
+ package-cache/
54
+ `;
55
+ /** One host-owned child; backend supervision and watcher locking stay in the manager. */
56
+ export class XerjIndexer {
57
+ capability;
58
+ environment;
59
+ report;
60
+ value;
61
+ child;
62
+ task;
63
+ closed = false;
64
+ saveConfiguration;
65
+ configurationSaved;
66
+ constructor(root, mode, capability, environment = process.env, report = console.warn) {
67
+ this.capability = capability;
68
+ this.environment = environment;
69
+ this.report = report;
70
+ this.value = { root, mode, state: mode === 'off' ? 'disabled' : 'starting' };
71
+ }
72
+ status() {
73
+ return { ...this.value };
74
+ }
75
+ start() {
76
+ if (this.task || this.closed || this.value.mode === 'off')
77
+ return;
78
+ this.task = this.launch().catch(() => {
79
+ if (!this.closed)
80
+ this.fail('Could not start XERJ indexing. Check root access and run gestalt doctor.');
81
+ });
82
+ }
83
+ fail(message) {
84
+ this.value = { ...this.value, state: 'error', message };
85
+ this.report(message);
86
+ }
87
+ async launch() {
88
+ const root = await realpath(this.value.root);
89
+ const namespace = `ax-${createHash('sha256').update(root).digest('hex').slice(0, 16)}`;
90
+ this.value = { ...this.value, root, namespace };
91
+ const ready = await this.capability.check({
92
+ cwd: root,
93
+ deadline: xerjDeadline(this.environment),
94
+ start: true,
95
+ });
96
+ if (this.closed)
97
+ return;
98
+ if (ready.status === 'absent') {
99
+ this.value = {
100
+ ...this.value,
101
+ state: 'absent',
102
+ message: 'Install with gestalt xerj install.',
103
+ };
104
+ return;
105
+ }
106
+ if (ready.status !== 'ready') {
107
+ this.fail('XERJ backend unavailable. Run gestalt doctor; check the managed data directory and local port.');
108
+ return;
109
+ }
110
+ if (this.value.mode === 'manual') {
111
+ this.value = { ...this.value, state: 'ready', message: 'Automatic indexing is disabled.' };
112
+ return;
113
+ }
114
+ const directory = join(this.environment.CODEX_HOME ?? join(homedir(), '.codex-gestalt'), 'xerj-data', 'autoindex', namespace);
115
+ const config = xerjIndexConfig(root, namespace, ready.endpoint);
116
+ const compatibility = await checkXerjIndexConfig(directory, config);
117
+ if (this.closed)
118
+ return;
119
+ if (compatibility === 'incompatible') {
120
+ this.fail('XERJ index settings differ from the saved fingerprint. Restore the previous settings or explicitly rebuild this root index; indexing was not started.');
121
+ return;
122
+ }
123
+ if (compatibility === 'missing')
124
+ this.saveConfiguration = () => saveXerjIndexConfig(directory, config);
125
+ try {
126
+ await writeFile(join(root, '.xerjignore'), xerjDefaultIgnores, { flag: 'wx', mode: 0o600 });
127
+ }
128
+ catch (error) {
129
+ if (error.code !== 'EEXIST')
130
+ throw error;
131
+ }
132
+ if (this.closed)
133
+ return;
134
+ const child = spawn(ready.manager, [
135
+ 'xerj',
136
+ 'autoindex',
137
+ root,
138
+ '--url',
139
+ ready.endpoint,
140
+ '--prefix',
141
+ namespace,
142
+ '--watch',
143
+ ...xerjContentArguments,
144
+ '--yes',
145
+ '--workers',
146
+ '2',
147
+ '--pdf-workers',
148
+ '1',
149
+ '--bulk-mb',
150
+ '4',
151
+ '--debounce',
152
+ '2000',
153
+ '--progress',
154
+ 'json',
155
+ ], { cwd: root, env: this.environment, shell: false, stdio: ['ignore', 'ignore', 'pipe'] });
156
+ this.child = child;
157
+ this.value = { ...this.value, state: 'indexing' };
158
+ // Never retain raw tool output or filenames. The status contains only an
159
+ // allowlist of counters/phases; bound even a malformed unterminated line.
160
+ let pending = '';
161
+ child.stderr?.on('data', (data) => {
162
+ pending += data.toString();
163
+ const lines = pending.split('\n');
164
+ pending = lines.pop() ?? '';
165
+ if (pending.length > 16_384)
166
+ pending = '';
167
+ for (const line of lines)
168
+ this.progress(line);
169
+ });
170
+ child.once('error', () => {
171
+ if (!this.closed)
172
+ this.fail('Could not launch XERJ. Check the Gestalt manager and flock/setpriv installation.');
173
+ });
174
+ child.once('close', (code) => {
175
+ this.child = undefined;
176
+ if (this.closed)
177
+ return;
178
+ if (code === 75) {
179
+ this.value = {
180
+ ...this.value,
181
+ state: 'shared',
182
+ message: 'Another watcher owns this root. Progress is available in its Mobile instance.',
183
+ };
184
+ }
185
+ else {
186
+ this.fail(`XERJ watcher stopped (exit ${code ?? 'signal'}). Run gestalt doctor; verify flock and setpriv are installed, then restart Mobile.`);
187
+ }
188
+ });
189
+ }
190
+ progress(line) {
191
+ if (this.closed)
192
+ return;
193
+ try {
194
+ const event = JSON.parse(line);
195
+ if (event.event === 'progress') {
196
+ const phase = typeof event.phase === 'string' && /^[a-z-]{1,32}$/.test(event.phase)
197
+ ? event.phase
198
+ : undefined;
199
+ const percent = typeof event.pct === 'number' && event.pct >= 0 && event.pct <= 100
200
+ ? event.pct
201
+ : undefined;
202
+ this.value = { ...this.value, state: 'indexing', phase, percent, message: undefined };
203
+ }
204
+ else if (event.event === 'done') {
205
+ if (event.ok !== true) {
206
+ this.fail('XERJ indexing failed. Check the index with gestalt xerj autoindex status; the next source change retries it.');
207
+ return;
208
+ }
209
+ if (this.saveConfiguration && !this.configurationSaved) {
210
+ this.configurationSaved = this.saveConfiguration().catch(() => {
211
+ this.fail('XERJ indexed successfully but could not save its configuration fingerprint. Check write access to the managed index directory.');
212
+ });
213
+ }
214
+ this.value = {
215
+ ...this.value,
216
+ state: 'watching',
217
+ phase: undefined,
218
+ percent: undefined,
219
+ lastUpdate: new Date().toISOString(),
220
+ message: undefined,
221
+ ...(count(event.files) !== undefined ? { files: count(event.files) } : {}),
222
+ ...(count(event.records) !== undefined ? { records: count(event.records) } : {}),
223
+ };
224
+ }
225
+ else if (event.event === 'warning') {
226
+ if (typeof event.message === 'string' &&
227
+ event.message.includes('refusing ambiguous assignment')) {
228
+ this.fail('XERJ incremental dataset assignment failed; the index is stale. See the XERJ recovery guide for this upstream limitation.');
229
+ return;
230
+ }
231
+ this.fail('XERJ reported an indexing warning. Inspect the index with gestalt xerj autoindex status; source changes trigger another pass.');
232
+ }
233
+ }
234
+ catch {
235
+ /* Native diagnostics are not public status or application logs. */
236
+ }
237
+ }
238
+ async close() {
239
+ this.closed = true;
240
+ await this.task;
241
+ await this.configurationSaved;
242
+ const child = this.child;
243
+ if (child && child.exitCode === null && child.signalCode === null) {
244
+ await new Promise((resolve) => {
245
+ child.once('close', resolve);
246
+ child.kill('SIGTERM');
247
+ const timer = setTimeout(() => child.kill('SIGKILL'), 2_000).unref();
248
+ child.once('close', () => clearTimeout(timer));
249
+ });
250
+ }
251
+ this.value = { ...this.value, state: this.value.mode === 'off' ? 'disabled' : 'stopped' };
252
+ }
253
+ }
254
+ function count(value) {
255
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
256
+ }