gestalt-mobile 0.47.0 → 0.48.1

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 (27) hide show
  1. package/README.md +47 -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 +9 -3
  7. package/dist/server/server/composition.js +37 -18
  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/model/skill-profile.js +4 -2
  14. package/dist/server/server/platform/codex/codex-capabilities.js +96 -0
  15. package/dist/server/server/platform/codex/codex-serena.js +159 -0
  16. package/dist/server/server/platform/codex/managed-serena.js +69 -0
  17. package/dist/server/server/platform/codex/normalizer.js +19 -0
  18. package/dist/server/server/platform/codex/session-runtime.js +52 -3
  19. package/dist/server/server/platform/retrieval/codex-xerj.js +2 -1
  20. package/dist/server/server/platform/retrieval/managed-xerj.js +2 -1
  21. package/dist/server/server/platform/retrieval/xerj-index-config.js +67 -0
  22. package/dist/server/server/platform/retrieval/xerj-indexer.js +256 -0
  23. package/dist/server/server/platform/skills/codex-skill-catalog.js +12 -4
  24. package/dist/server/shared/contracts/xerj-status.js +6 -0
  25. package/package.json +1 -1
  26. package/dist/client/assets/index-CGCxdtE6.js +0 -112
  27. package/dist/client/assets/index-s4qgQfcy.css +0 -1
@@ -68,6 +68,7 @@ class SessionResource {
68
68
  }
69
69
  retrieval;
70
70
  retrievalFailureReported = false;
71
+ capabilityFailuresReported = new Set();
71
72
  readinessDeadline = xerjDeadline();
72
73
  dispose() {
73
74
  if (this.disposed)
@@ -949,6 +950,12 @@ export class CodexSessionRuntime {
949
950
  return;
950
951
  if (notification.method === 'mcpServer/statusUpdated') {
951
952
  const status = notification.params;
953
+ if (status?.name === 'gestalt-serena' &&
954
+ ['failed', 'cancelled'].includes(status.status ?? '')) {
955
+ if (resource.capabilityFailuresReported.has(status.name))
956
+ return;
957
+ resource.capabilityFailuresReported.add(status.name);
958
+ }
952
959
  if (status?.name === 'gestalt-xerj' &&
953
960
  ['failed', 'cancelled'].includes(status.status ?? '')) {
954
961
  if (resource.retrievalFailureReported)
@@ -1002,11 +1009,34 @@ export class CodexSessionRuntime {
1002
1009
  withEffectiveRetrieval(session, resource) {
1003
1010
  if (!resource.retrieval || !session.effectiveSkillSelection)
1004
1011
  return session;
1012
+ const serena = resource.retrieval.capabilities?.find((capability) => capability.skillName === 'gestalt:serena');
1013
+ const warning = 'Serena is unavailable in this session. Use native code tools. Connection availability will be checked when the runtime resumes.';
1014
+ const warnings = session.effectiveSkillSelection.warnings?.filter((message) => message !== warning) ?? [];
1015
+ if (serena?.diagnostic)
1016
+ warnings.push(warning);
1005
1017
  return {
1006
1018
  ...session,
1007
1019
  effectiveSkillSelection: {
1008
1020
  ...session.effectiveSkillSelection,
1009
- skills: session.effectiveSkillSelection.skills.map((skill) => skill.name === 'gestalt:xerj' ? { ...skill, enabled: resource.retrieval.ready } : skill),
1021
+ ...(serena &&
1022
+ (serena.diagnostic || session.effectiveSkillSelection.warnings?.includes(warning))
1023
+ ? { warnings }
1024
+ : {}),
1025
+ ...(resource.retrieval.capabilities &&
1026
+ session.effectiveSkillSelection.skills.some((skill) => skill.name === 'gestalt:serena')
1027
+ ? {
1028
+ serenaSelected: session.effectiveSkillSelection.serenaSelected ??
1029
+ Boolean(session.effectiveSkillSelection.skills.find((skill) => skill.name === 'gestalt:serena')?.enabled),
1030
+ }
1031
+ : {}),
1032
+ skills: session.effectiveSkillSelection.skills.map((skill) => resource.retrieval.capabilities?.some((capability) => capability.skillName === skill.name)
1033
+ ? {
1034
+ ...skill,
1035
+ enabled: Boolean(resource.retrieval.capabilities.find((capability) => capability.skillName === skill.name)?.ready),
1036
+ }
1037
+ : skill.name === 'gestalt:xerj'
1038
+ ? { ...skill, enabled: resource.retrieval.ready }
1039
+ : skill),
1010
1040
  },
1011
1041
  };
1012
1042
  }
@@ -1017,6 +1047,7 @@ export class CodexSessionRuntime {
1017
1047
  resource.retrieval = state;
1018
1048
  resource.skillsConfig = state.skillsConfig;
1019
1049
  resource.modelConfig = state.config;
1050
+ this.reportCapabilityFailures(resource, session);
1020
1051
  if (state.diagnostic && !resource.retrievalFailureReported) {
1021
1052
  resource.retrievalFailureReported = true;
1022
1053
  this.onNotification?.(session.id, {
@@ -1025,14 +1056,32 @@ export class CodexSessionRuntime {
1025
1056
  }, { kind: 'root' });
1026
1057
  }
1027
1058
  }
1059
+ reportCapabilityFailures(resource, session) {
1060
+ for (const capability of resource.retrieval?.capabilities ?? []) {
1061
+ if (!capability.diagnostic || resource.capabilityFailuresReported.has(capability.serverName))
1062
+ continue;
1063
+ resource.capabilityFailuresReported.add(capability.serverName);
1064
+ this.onNotification?.(session.id, {
1065
+ method: 'mcpServer/statusUpdated',
1066
+ params: { name: capability.serverName, status: 'failed' },
1067
+ }, { kind: 'root' });
1068
+ }
1069
+ }
1028
1070
  async verifyRetrieval(resource, session, fresh = false) {
1029
1071
  const state = resource.retrieval;
1030
1072
  if (!state?.ready || !resource.threadId || !this.retrieval)
1031
1073
  return;
1032
- if (await this.retrieval.verify(resource.process.rpc, resource.threadId, state))
1074
+ if (await this.retrieval.verify(resource.process.rpc, resource.threadId, state)) {
1075
+ if (state.capabilities?.some((capability) => capability.serverName === 'gestalt-serena' && capability.ready))
1076
+ this.onNotification?.(session.id, {
1077
+ method: 'mcpServer/statusUpdated',
1078
+ params: { name: 'gestalt-serena', status: 'connected' },
1079
+ }, { kind: 'root' });
1033
1080
  return;
1081
+ }
1034
1082
  state.fallback();
1035
- if (!resource.retrievalFailureReported) {
1083
+ this.reportCapabilityFailures(resource, session);
1084
+ if (!state.capabilities && !resource.retrievalFailureReported) {
1036
1085
  resource.retrievalFailureReported = true;
1037
1086
  this.onNotification?.(session.id, {
1038
1087
  method: 'mcpServer/statusUpdated',
@@ -94,7 +94,8 @@ export class CodexXerj {
94
94
  [xerjServerName]: {
95
95
  command: ready.manager,
96
96
  args: ['xerj', 'mcp', '--url', ready.endpoint],
97
- env_vars: ['GESTALT_HOME', 'XERJ_API_KEY', 'XERJ_AUTH'],
97
+ cwd: input.cwd,
98
+ env_vars: ['CODEX_HOME', 'GESTALT_HOME', 'XERJ_API_KEY', 'XERJ_AUTH'],
98
99
  enabled: true,
99
100
  required: false,
100
101
  startup_readiness: 'connection',
@@ -7,6 +7,7 @@ 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
+ export const managedXerjVersion = '1.0.0-rc.87';
10
11
  /** The manager alone owns backend identity, authentication and shared lifetime. */
11
12
  export class ManagedXerj {
12
13
  environment;
@@ -68,7 +69,7 @@ export class ManagedXerj {
68
69
  if (value.status === 'unavailable')
69
70
  return settle(unavailable('managed-backend-unavailable'));
70
71
  if (value.status !== 'ready' ||
71
- value.version !== '1.0.0-rc.87' ||
72
+ value.version !== managedXerjVersion ||
72
73
  typeof value.endpoint !== 'string' ||
73
74
  !/^http:\/\/(127\.0\.0\.1|\[::1\])(?::\d{1,5})?$/.test(value.endpoint))
74
75
  throw new Error();
@@ -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
+ }
@@ -76,7 +76,8 @@ export class CodexSkillCatalog {
76
76
  ? { ...stable.data, enabled: false }
77
77
  : stable.data;
78
78
  });
79
- if (this.retrieval && skills.some((skill) => skill.name === 'gestalt:xerj')) {
79
+ if (this.retrieval &&
80
+ skills.some((skill) => ['gestalt:xerj', 'gestalt:serena'].includes(skill.name))) {
80
81
  const state = await this.retrieval.prepare({
81
82
  cwd: canonicalWorkspace,
82
83
  deadline,
@@ -86,18 +87,25 @@ export class CodexSkillCatalog {
86
87
  config: {},
87
88
  start: false,
88
89
  });
90
+ const requestedSerena = skills.find((skill) => skill.name === 'gestalt:serena');
91
+ if (requestedSerena)
92
+ requestedSerena.enabled = false;
89
93
  if (state.ready) {
90
94
  try {
91
95
  const result = (await this.withTimeout(server.rpc.request('thread/start', {
92
96
  cwd: canonicalWorkspace,
93
97
  ...threadSkillConfig(state.skillsConfig, state.config),
94
98
  ephemeral: true,
95
- }), deadline));
99
+ }), state.deadline));
96
100
  const ready = result.thread?.id &&
97
101
  (await this.retrieval.verify(server.rpc, result.thread.id, state));
98
102
  for (const skill of skills)
99
- if (skill.name === 'gestalt:xerj')
100
- skill.enabled = Boolean(ready);
103
+ if (['gestalt:xerj', 'gestalt:serena'].includes(skill.name))
104
+ skill.enabled = state.capabilities
105
+ ? Boolean(result.thread?.id) &&
106
+ Boolean(state.capabilities.find((capability) => capability.skillName === skill.name)
107
+ ?.ready)
108
+ : Boolean(ready);
101
109
  }
102
110
  catch {
103
111
  /* Discovery remains usable without optional retrieval. */
@@ -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 {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.47.0",
3
+ "version": "0.48.1",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",