gestalt-mobile 0.62.4 → 0.64.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 (25) hide show
  1. package/README.md +9 -2
  2. package/dist/client/assets/index-Cj7IlGeB.js +128 -0
  3. package/dist/client/assets/index-DS139o-V.css +1 -0
  4. package/dist/client/index.html +2 -2
  5. package/dist/server/client/features/chat/activity-summary.js +8 -0
  6. package/dist/server/client/features/chat/chat-projection.js +1 -1
  7. package/dist/server/server/composition.contracts.js +6 -0
  8. package/dist/server/server/composition.js +2 -0
  9. package/dist/server/server/features/files/create-directory/endpoint.js +35 -0
  10. package/dist/server/server/features/files/register-routes.js +2 -0
  11. package/dist/server/server/features/files/upload-file/endpoint.js +2 -1
  12. package/dist/server/server/platform/codex/codex-capabilities.js +3 -0
  13. package/dist/server/server/platform/codex/mcp-startup-failure.js +25 -0
  14. package/dist/server/server/platform/codex/session-runtime.js +17 -1
  15. package/dist/server/server/platform/filesystem/filesystem-workspace-files.js +31 -0
  16. package/dist/server/server/platform/retrieval/codex-xerj.js +9 -1
  17. package/dist/server/server/platform/retrieval/managed-xerj.js +89 -14
  18. package/dist/server/server/platform/retrieval/xerj-index-diagnostic.js +8 -1
  19. package/dist/server/server/platform/retrieval/xerj-indexer.js +31 -5
  20. package/dist/server/shared/contracts/file-upload.js +6 -0
  21. package/dist/server/shared/contracts/mcp-startup-failure.js +16 -2
  22. package/dist/server/shared/contracts/xerj-startup.js +76 -0
  23. package/package.json +1 -1
  24. package/dist/client/assets/index-CRnoGk06.css +0 -1
  25. package/dist/client/assets/index-DehRk2EQ.js +0 -127
@@ -7,58 +7,118 @@ import { spawn } from 'node:child_process';
7
7
  import { access } from 'node:fs/promises';
8
8
  import { constants } from 'node:fs';
9
9
  import { isAbsolute, join } from 'node:path';
10
+ import { parseXerjStartupReason } from '../../../shared/contracts/xerj-startup.js';
10
11
  /** The manager alone owns backend identity, authentication and shared lifetime. */
11
12
  export class ManagedXerj {
12
13
  environment;
14
+ startup;
15
+ probes = new Set();
16
+ closed = false;
13
17
  constructor(environment = process.env) {
14
18
  this.environment = environment;
15
19
  }
16
20
  async check(input) {
21
+ if (this.closed)
22
+ return { status: 'unavailable', reason: 'cancelled' };
17
23
  const manager = await this.manager();
24
+ if (this.closed)
25
+ return { status: 'unavailable', reason: 'cancelled' };
18
26
  if (!manager)
19
27
  return { status: 'absent' };
20
28
  const remaining = input.deadline - Date.now();
29
+ if (this.startup?.manager === manager)
30
+ return this.wait(this.startup.result, Math.max(0, remaining));
21
31
  // The shipped manager rejects sub-100ms operations because it reserves
22
32
  // cleanup time inside the overall deadline. Do not spend the remaining
23
33
  // budget spawning a request that cannot satisfy that contract.
24
34
  if (remaining < minimumXerjTimeoutMs)
25
35
  return { status: 'unavailable', reason: 'readiness-timeout' };
36
+ // A short-lived session waiter never owns the shared startup process.
37
+ // Read-only discovery can observe an existing startup but cannot initiate one.
38
+ if (!input.start)
39
+ return this.run(manager, input.cwd, 'probe', Math.min(remaining, maximumXerjTimeoutMs));
40
+ const startup = {
41
+ manager,
42
+ result: this.run(manager, input.cwd, 'ensure-ready', xerjStartupTimeout(this.environment)),
43
+ };
44
+ this.startup = startup;
45
+ void startup.result.then(() => {
46
+ if (this.startup === startup)
47
+ this.startup = undefined;
48
+ });
49
+ return this.wait(startup.result, remaining);
50
+ }
51
+ async wait(result, timeout) {
52
+ let timer;
53
+ try {
54
+ return await Promise.race([
55
+ result,
56
+ new Promise((resolve) => {
57
+ timer = setTimeout(() => resolve({ status: 'starting' }), timeout);
58
+ }),
59
+ ]);
60
+ }
61
+ finally {
62
+ clearTimeout(timer);
63
+ }
64
+ }
65
+ run(manager, cwd, operation, timeout) {
26
66
  return new Promise((resolve) => {
27
- const child = spawn(manager, ['xerj', input.start ? 'ensure-ready' : 'probe'], {
28
- cwd: input.cwd,
29
- env: { ...this.environment, XERJ_READY_TIMEOUT_MS: String(remaining) },
67
+ const child = spawn(manager, ['xerj', operation], {
68
+ cwd,
69
+ env: { ...this.environment, XERJ_READY_TIMEOUT_MS: String(timeout) },
30
70
  shell: false,
31
71
  stdio: ['ignore', 'pipe', 'ignore'],
32
72
  });
33
73
  let output = '';
34
74
  let finished = false;
75
+ let failure;
76
+ let escalation;
77
+ let closed;
78
+ const probe = {
79
+ stop: () => stop('cancelled'),
80
+ closed: new Promise((resolve) => {
81
+ closed = resolve;
82
+ }),
83
+ };
84
+ this.probes.add(probe);
35
85
  const settle = (result) => {
36
86
  if (finished)
37
87
  return;
38
88
  finished = true;
39
89
  clearTimeout(timer);
90
+ clearTimeout(escalation);
91
+ this.probes.delete(probe);
92
+ closed();
40
93
  resolve(result);
41
94
  };
42
95
  const unavailable = (reason) => ({
43
96
  status: 'unavailable',
44
97
  reason,
45
98
  });
46
- const timer = setTimeout(() => {
47
- // Reap the owned probe; never signal the manager's shared backend.
99
+ const stop = (reason) => {
100
+ if (finished || failure)
101
+ return;
102
+ failure = unavailable(reason);
103
+ // Reap only our manager client; its lifecycle contract owns launch cleanup.
48
104
  child.kill('SIGTERM');
49
- const kill = setTimeout(() => child.kill('SIGKILL'), 100).unref();
50
- child.once('close', () => clearTimeout(kill));
51
- settle(unavailable('readiness-timeout'));
52
- }, remaining);
53
- child.on('error', () => settle(unavailable('manager-unavailable')));
105
+ escalation = setTimeout(() => child.kill('SIGKILL'), 100).unref();
106
+ };
107
+ const timer = setTimeout(() => stop('readiness-timeout'), timeout);
108
+ child.on('error', () => {
109
+ failure = unavailable('manager-unavailable');
110
+ });
54
111
  child.stdout.on('data', (data) => {
112
+ if (failure)
113
+ return;
55
114
  output += data.toString();
56
115
  if (output.length > 16_384) {
57
- child.kill('SIGKILL');
58
- settle(unavailable('invalid-manager-response'));
116
+ stop('invalid-manager-response');
59
117
  }
60
118
  });
61
119
  child.once('close', (code) => {
120
+ if (failure)
121
+ return settle(failure);
62
122
  try {
63
123
  const value = JSON.parse(output);
64
124
  if (code !== 0 || value.schemaVersion !== 1)
@@ -66,7 +126,7 @@ export class ManagedXerj {
66
126
  if (value.status === 'absent')
67
127
  return settle({ status: 'absent' });
68
128
  if (value.status === 'unavailable')
69
- return settle(unavailable('managed-backend-unavailable'));
129
+ return settle(unavailable(parseXerjStartupReason(value.reason)));
70
130
  if (value.status !== 'ready' ||
71
131
  typeof value.version !== 'string' ||
72
132
  !/^[0-9]+\.[0-9]+\.[0-9]+(?:[-+][A-Za-z0-9.-]+)?$/.test(value.version) ||
@@ -82,7 +142,14 @@ export class ManagedXerj {
82
142
  settle(unavailable('invalid-manager-response'));
83
143
  }
84
144
  });
85
- });
145
+ }).catch(() => ({ status: 'unavailable', reason: 'manager-unavailable' }));
146
+ }
147
+ async close() {
148
+ this.closed = true;
149
+ const probes = [...this.probes];
150
+ for (const probe of probes)
151
+ probe.stop();
152
+ await Promise.all(probes.map((probe) => probe.closed));
86
153
  }
87
154
  async manager() {
88
155
  const explicit = this.environment.GESTALT_MANAGER_BIN;
@@ -118,3 +185,11 @@ export function xerjDeadline(environment = process.env) {
118
185
  const minimumXerjTimeoutMs = 100;
119
186
  const maximumXerjTimeoutMs = 60_000;
120
187
  const defaultXerjTimeoutMs = 5_000;
188
+ export function xerjStartupTimeout(environment = process.env) {
189
+ const configured = Number(environment.XERJ_STARTUP_TIMEOUT_MS);
190
+ return Number.isInteger(configured) &&
191
+ configured >= minimumXerjTimeoutMs &&
192
+ configured <= maximumXerjTimeoutMs
193
+ ? configured
194
+ : 30_000;
195
+ }
@@ -19,7 +19,14 @@ export function xerjIndexDiagnostic(message) {
19
19
  ? 'connection'
20
20
  : /\b(out of memory|no space left|disk full)\b/i.test(text)
21
21
  ? 'capacity'
22
- : 'unknown-warning';
22
+ : text.includes('rebuild with a new --state-dir and a new --prefix')
23
+ ? 'rebuild-required'
24
+ : /^watch: pass \d+ FAILED after [\d.]+s:/.test(text)
25
+ ? 'watch-pass-failed'
26
+ : text ===
27
+ 'watch: the platform reported dropped events (watch queue overflow); re-hashing the whole tree for this pass'
28
+ ? 'watch-rescan'
29
+ : 'unknown-warning';
23
30
  return {
24
31
  id: randomUUID(),
25
32
  occurredAt: new Date().toISOString(),
@@ -9,9 +9,10 @@ import { realpath, writeFile } from 'node:fs/promises';
9
9
  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
- import { xerjDeadline } from './managed-xerj.js';
12
+ import { xerjStartupTimeout } from './managed-xerj.js';
13
13
  import { ReadinessEvidence } from './readiness-evidence.js';
14
14
  import { saveXerjIndexDiagnostic, xerjIndexDiagnostic } from './xerj-index-diagnostic.js';
15
+ import { parseXerjStartupReason, xerjStartupMessage, } from '../../../shared/contracts/xerj-startup.js';
15
16
  // Native gitignore syntax, editable by the host operator. Hidden directories and
16
17
  // symlinks are already skipped by XERJ. Never replace an existing root policy.
17
18
  export const xerjDefaultIgnores = `# Gestalt source discovery. Edit these native XERJ rules to change scope.
@@ -88,7 +89,7 @@ export class XerjIndexer {
88
89
  }
89
90
  fail(message) {
90
91
  this.evidence.coverage(this.value.lastUpdate ? 'stale' : 'unavailable');
91
- this.value = { ...this.value, state: 'error', message };
92
+ this.value = { ...this.value, state: 'error', phase: undefined, percent: undefined, message };
92
93
  this.report(message);
93
94
  }
94
95
  async launch() {
@@ -97,7 +98,9 @@ export class XerjIndexer {
97
98
  this.value = { ...this.value, root, namespace };
98
99
  const ready = await this.capability.check({
99
100
  cwd: root,
100
- deadline: xerjDeadline(this.environment),
101
+ // This background task waits for backend startup, not the chat allowance.
102
+ // Leave room for the owned manager client's bounded shutdown.
103
+ deadline: Date.now() + xerjStartupTimeout(this.environment) + 1_000,
101
104
  start: true,
102
105
  });
103
106
  if (this.closed)
@@ -113,7 +116,7 @@ export class XerjIndexer {
113
116
  }
114
117
  if (ready.status !== 'ready') {
115
118
  this.evidence.connection('unavailable');
116
- this.fail('XERJ backend unavailable. Run gestalt doctor; check the managed data directory and local port.');
119
+ this.fail(`${xerjStartupMessage(parseXerjStartupReason(ready.status === 'unavailable' ? ready.reason : 'unknown'))} Inspect gestalt xerj status.`);
117
120
  return;
118
121
  }
119
122
  this.evidence.connection('ready');
@@ -249,12 +252,35 @@ export class XerjIndexer {
249
252
  this.pendingDiagnostic = diagnostic;
250
253
  this.diagnosticSaved ??= this.saveDiagnostics();
251
254
  const reference = ` Diagnostic: ${diagnostic.id} (${diagnostic.code}).`;
255
+ if (diagnostic.code === 'watch-rescan') {
256
+ // Native XERJ already schedules a full pass after dropped watch events.
257
+ // This invalidates coverage, but is not a failed pass or lost connection.
258
+ this.evidence.coverage(this.value.lastUpdate ? 'stale' : 'unknown');
259
+ this.value = {
260
+ ...this.value,
261
+ state: 'indexing',
262
+ phase: undefined,
263
+ percent: undefined,
264
+ message: 'XERJ is rescanning the workspace after filesystem events were dropped.',
265
+ };
266
+ return;
267
+ }
268
+ if (diagnostic.code === 'rebuild-required') {
269
+ this.fail('XERJ cannot update the saved index with the current indexing configuration. A new index generation is required; source changes alone cannot repair it. See the XERJ recovery guide.' +
270
+ reference);
271
+ return;
272
+ }
273
+ if (diagnostic.code === 'watch-pass-failed') {
274
+ this.fail('XERJ index update failed. The watcher is still running and will retry after a source change; existing index coverage is unverified until an update succeeds.' +
275
+ reference);
276
+ return;
277
+ }
252
278
  if (diagnostic.code === 'ambiguous-assignment') {
253
279
  this.fail('XERJ incremental dataset assignment failed; the index is stale. See the XERJ recovery guide for this upstream limitation.' +
254
280
  reference);
255
281
  return;
256
282
  }
257
- this.fail('XERJ reported an indexing warning. Inspect the index with gestalt xerj autoindex status; source changes trigger another pass.' +
283
+ this.fail('XERJ reported an unclassified indexing warning. Inspect the index with gestalt xerj autoindex status.' +
258
284
  reference);
259
285
  }
260
286
  }
@@ -0,0 +1,6 @@
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
+ export const MAX_UPLOAD_BYTES = 100 * 1024 * 1024;
@@ -3,13 +3,14 @@
3
3
  * Designed by Denis Roio <jaromil@dyne.org>
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
+ import { parseXerjStartupReason } from './xerj-startup.js';
6
7
  export const startupServers = [
7
8
  'context-mode',
8
9
  'gestalt-context-mode',
9
10
  'gestalt-serena',
10
11
  'gestalt-xerj',
11
12
  ];
12
- export const startupPhases = ['artifact', 'spawn', 'initialize', 'startup'];
13
+ export const startupPhases = ['artifact', 'spawn', 'initialize', 'startup', 'readiness'];
13
14
  export const startupFailureCodes = [
14
15
  'artifact-unavailable',
15
16
  'process-exited',
@@ -18,6 +19,7 @@ export const startupFailureCodes = [
18
19
  'reauthentication-required',
19
20
  'startup-failed',
20
21
  'cancelled',
22
+ 'readiness-failed',
21
23
  ];
22
24
  const signals = [
23
25
  'SIGHUP',
@@ -60,6 +62,9 @@ export function parseMcpStartupFailure(value) {
60
62
  !member(startupPhases, r.phase) ||
61
63
  !member(startupFailureCodes, r.code))
62
64
  return undefined;
65
+ if ((r.phase === 'readiness' || r.code === 'readiness-failed') &&
66
+ !(r.phase === 'readiness' && r.code === 'readiness-failed' && r.serverName === 'gestalt-xerj'))
67
+ return undefined;
63
68
  return {
64
69
  schemaVersion: 1,
65
70
  failureId,
@@ -80,6 +85,9 @@ export function parseMcpStartupFailure(value) {
80
85
  ? r.exitCode
81
86
  : null,
82
87
  signal: member(signals, r.signal) ? r.signal : null,
88
+ ...(r.phase === 'readiness' && r.code === 'readiness-failed' && r.serverName === 'gestalt-xerj'
89
+ ? { readinessReason: parseXerjStartupReason(r.readinessReason) }
90
+ : {}),
83
91
  };
84
92
  }
85
93
  export function parseMcpStartupStatus(value) {
@@ -118,6 +126,9 @@ export function parseMcpStartupStatus(value) {
118
126
  observedAt,
119
127
  status: r.status,
120
128
  failure: failure ?? null,
129
+ ...(r.phase === 'readiness' && r.serverName === 'gestalt-xerj'
130
+ ? { phase: 'readiness' }
131
+ : {}),
121
132
  };
122
133
  }
123
134
  /** One current row per physical thread/tool; unattributed lifetimes stay separate. */
@@ -126,7 +137,9 @@ export function mcpStartupActivity(status) {
126
137
  id: `mcp-startup:${status.threadId ?? `unattributed:${status.runtimeId}`}:${status.serverName}`,
127
138
  label: `${status.serverName} · ${status.status}`,
128
139
  detail: status.failure
129
- ? `Startup observation: ${status.failure.code}. Child exit diagnostics are unavailable.`
140
+ ? status.failure.phase === 'readiness'
141
+ ? `Backend readiness: ${status.failure.readinessReason ?? 'unknown'}.`
142
+ : `Startup observation: ${status.failure.code}. Child exit diagnostics are unavailable.`
130
143
  : `Startup observation: ${status.status}.`,
131
144
  mcpStartup: status,
132
145
  };
@@ -147,6 +160,7 @@ export function startupFailureReason(code) {
147
160
  'reauthentication-required': 'Codex reported that authentication is required again.',
148
161
  'startup-failed': 'Codex reported a startup failure without a more specific reason.',
149
162
  cancelled: 'Startup was cancelled.',
163
+ 'readiness-failed': 'Gestalt could not prepare the XERJ backend.',
150
164
  }[code];
151
165
  }
152
166
  export function startupRecoveryGuidance(server) {
@@ -0,0 +1,76 @@
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
+ /** Manager reason codes only; never propagate subprocess prose or environment values. */
7
+ const reasons = [
8
+ 'cancelled',
9
+ 'timeout',
10
+ 'readiness-timeout',
11
+ 'unsafe-path',
12
+ 'unsupported-installation',
13
+ 'unsupported-version',
14
+ 'unsupported-binary',
15
+ 'unsafe-endpoint',
16
+ 'credentials-unavailable',
17
+ 'authentication-failed',
18
+ 'backend-unavailable',
19
+ 'invalid-backend',
20
+ 'invalid-mcp',
21
+ 'incompatible-mcp',
22
+ 'invalid-deadline',
23
+ 'invalid-lifecycle-record',
24
+ 'lifecycle-busy',
25
+ 'endpoint-in-use',
26
+ 'launch-failed',
27
+ 'probe-failed',
28
+ 'manager-unavailable',
29
+ 'invalid-manager-response',
30
+ 'unknown',
31
+ ];
32
+ export function parseXerjStartupReason(value) {
33
+ return typeof value === 'string' && reasons.includes(value)
34
+ ? value
35
+ : 'unknown';
36
+ }
37
+ export function xerjStartupMessage(reason) {
38
+ switch (reason) {
39
+ case 'timeout':
40
+ case 'readiness-timeout':
41
+ return 'XERJ backend preparation exceeded its time budget.';
42
+ case 'credentials-unavailable':
43
+ case 'authentication-failed':
44
+ return 'XERJ backend authentication is unavailable or was rejected.';
45
+ case 'endpoint-in-use':
46
+ return 'The selected XERJ endpoint is already occupied.';
47
+ case 'unsafe-path':
48
+ case 'unsafe-endpoint':
49
+ case 'unsupported-installation':
50
+ case 'invalid-lifecycle-record':
51
+ case 'invalid-deadline':
52
+ return 'XERJ manager configuration or managed state failed validation.';
53
+ case 'unsupported-version':
54
+ case 'unsupported-binary':
55
+ case 'incompatible-mcp':
56
+ return 'The installed XERJ runtime is incompatible or unavailable.';
57
+ case 'manager-unavailable':
58
+ return 'The Gestalt manager could not be executed.';
59
+ case 'backend-unavailable':
60
+ return 'The XERJ backend could not be reached.';
61
+ case 'launch-failed':
62
+ return 'The managed XERJ backend could not be started.';
63
+ case 'probe-failed':
64
+ return 'The Gestalt manager could not complete its readiness check.';
65
+ case 'invalid-backend':
66
+ case 'invalid-mcp':
67
+ case 'invalid-manager-response':
68
+ return 'XERJ readiness returned an invalid response.';
69
+ case 'lifecycle-busy':
70
+ return 'Another XERJ lifecycle operation is still in progress.';
71
+ case 'cancelled':
72
+ return 'XERJ backend preparation was cancelled.';
73
+ default:
74
+ return 'XERJ backend preparation failed; no more specific cause is available.';
75
+ }
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.62.4",
3
+ "version": "0.64.0",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",