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
@@ -16,8 +16,8 @@ SPDX-License-Identifier: AGPL-3.0-or-later
16
16
  <link rel="icon" href="/icons/gestalt-mobile-192.png" />
17
17
  <link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
18
18
  <title>Gestalt Mobile</title>
19
- <script type="module" crossorigin src="/assets/index-CGCxdtE6.js"></script>
20
- <link rel="stylesheet" crossorigin href="/assets/index-s4qgQfcy.css">
19
+ <script type="module" crossorigin src="/assets/index-DvIxykMj.js"></script>
20
+ <link rel="stylesheet" crossorigin href="/assets/index-CE4-9CY1.css">
21
21
  </head>
22
22
  <body>
23
23
  <div id="app"></div>
@@ -29,6 +29,7 @@ Options:
29
29
  --disable-passkey-auth Disable passkey access control (unsafe on shared or network hosts)
30
30
  --data-dir <path> Directory for persistent application data
31
31
  --icon <path> SVG or PNG used as the installed PWA application icon
32
+ --xerj <mode> Source discovery: manual (default, no indexing), auto, off
32
33
  --skills <profile> Use a global skill profile for every session
33
34
  --skills list List saved global skill profiles without starting the server
34
35
  --help Show this help
@@ -36,6 +37,9 @@ Options:
36
37
  function managedVersion(value) {
37
38
  return value && /^[A-Za-z0-9][A-Za-z0-9.+_-]{0,99}$/.test(value) ? value : null;
38
39
  }
40
+ function semanticVersion(value) {
41
+ return value && /^\d+\.\d+\.\d+$/.test(value) ? value : null;
42
+ }
39
43
  export function componentVersions(mobileVersion, codexVersion, environment = process.env) {
40
44
  return [
41
45
  {
@@ -55,6 +59,16 @@ export function componentVersions(mobileVersion, codexVersion, environment = pro
55
59
  version: managedVersion(environment.GESTALT_CONTEXT_MODE_VERSION),
56
60
  },
57
61
  { id: 'codex', label: 'Codex CLI', version: codexVersion },
62
+ { id: 'xerj', label: 'xerj', version: managedVersion(environment.GESTALT_XERJ_VERSION) },
63
+ { id: 'serena', label: 'Serena', version: semanticVersion(environment.GESTALT_SERENA_VERSION) },
64
+ { id: 'uv', label: 'uv', version: semanticVersion(environment.GESTALT_UV_VERSION) },
65
+ {
66
+ id: 'serena-python',
67
+ label: 'Serena Python',
68
+ version: /^3\.13\.\d+$/.test(environment.GESTALT_SERENA_PYTHON_VERSION ?? '')
69
+ ? environment.GESTALT_SERENA_PYTHON_VERSION
70
+ : null,
71
+ },
58
72
  ];
59
73
  }
60
74
  export async function runStartupDoctor(cwd) {
@@ -272,6 +286,7 @@ export async function runCli(dependencies = {}) {
272
286
  const mobileVersion = await packageVersion(moduleUrl);
273
287
  const app = await (dependencies.compose ?? composeRelayApp)({
274
288
  root: config.root,
289
+ xerj: config.xerj,
275
290
  dataDir: config.dataDir,
276
291
  relyingParty: config.relyingParty,
277
292
  passkeyAuthEnabled: config.passkeyAuthEnabled,
@@ -3259,9 +3259,13 @@ describe('production composition', () => {
3259
3259
  ],
3260
3260
  });
3261
3261
  await expect.poll(() => handles.length).toBeGreaterThan(handlesBeforeRecovery);
3262
- const replacement = handles.find((candidate) => candidate !== first &&
3263
- candidate.requests.some((request) => request.method === 'thread/resume'));
3264
- expect(replacement?.requests).toContainEqual({
3262
+ // Launching the replacement precedes its asynchronous thread resume.
3263
+ // Wait for the recovery operation, not merely the new process handle.
3264
+ await expect
3265
+ .poll(() => handles
3266
+ .filter((candidate) => candidate !== first)
3267
+ .flatMap((candidate) => candidate.requests))
3268
+ .toContainEqual({
3265
3269
  method: 'thread/resume',
3266
3270
  params: expect.objectContaining({ threadId, cwd: join(root, 'workspace') }),
3267
3271
  });
@@ -3275,6 +3279,77 @@ describe('production composition', () => {
3275
3279
  });
3276
3280
  await app.close();
3277
3281
  });
3282
+ it('drains an in-flight capacity recovery before closing its session database', async () => {
3283
+ const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
3284
+ const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-mobile-state-'));
3285
+ ownTemporaryPaths(root, dataDir);
3286
+ await mkdir(join(root, 'workspace'));
3287
+ const handles = [];
3288
+ const launch = liveAppServer(handles);
3289
+ let blockResume = false;
3290
+ let resumeStarted;
3291
+ let releaseResume;
3292
+ const resumeStarting = new Promise((resolve) => (resumeStarted = resolve));
3293
+ const resumeGate = new Promise((resolve) => (releaseResume = resolve));
3294
+ const app = await composeAuthorizedApp({
3295
+ root,
3296
+ dataDir,
3297
+ relyingParty,
3298
+ installedCodexVersion: 'codex-cli 0.144.3',
3299
+ startAppServers: true,
3300
+ launchAppServer: () => {
3301
+ const server = launch();
3302
+ const handle = handles.at(-1);
3303
+ handle.respond = async (method, params) => {
3304
+ if (!blockResume || method !== 'thread/resume')
3305
+ return undefined;
3306
+ resumeStarted();
3307
+ await resumeGate;
3308
+ return { thread: { id: params.threadId } };
3309
+ };
3310
+ return server;
3311
+ },
3312
+ profiles: {
3313
+ list: async () => [],
3314
+ require: async () => ({
3315
+ name: 'default',
3316
+ state: 'ok',
3317
+ status: 'ready',
3318
+ }),
3319
+ },
3320
+ });
3321
+ const sessionId = await createComposedSession(app);
3322
+ const first = handles.find((candidate) => candidate.calls.includes('thread/start'));
3323
+ const started = await app.inject({
3324
+ method: 'POST',
3325
+ url: `/api/sessions/${sessionId}/turns`,
3326
+ payload: { text: 'continue supervised work' },
3327
+ });
3328
+ const turnId = started.json().activeTurnId;
3329
+ const threadId = (await app.inject(`/api/sessions/${sessionId}`)).json().threadId;
3330
+ first.notify?.({ method: 'turn/started', params: { threadId, turn: { id: turnId } } });
3331
+ blockResume = true;
3332
+ await expect(first.request({
3333
+ id: 92,
3334
+ method: 'item/tool/call',
3335
+ params: {
3336
+ threadId,
3337
+ turnId,
3338
+ tool: 'gestalt_agent_capacity_recovery',
3339
+ arguments: { version: 1, reason: 'agentThreadLimit' },
3340
+ },
3341
+ })).resolves.toMatchObject({ success: true });
3342
+ await resumeStarting;
3343
+ let closed = false;
3344
+ const close = app.close().then(() => {
3345
+ closed = true;
3346
+ });
3347
+ await new Promise((resolve) => setTimeout(resolve, 25));
3348
+ const closedBeforeRecoverySettled = closed;
3349
+ releaseResume();
3350
+ await close;
3351
+ expect(closedBeforeRecoverySettled).toBe(false);
3352
+ });
3278
3353
  it('publishes an idle websocket status after saving a completed turn', async () => {
3279
3354
  const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
3280
3355
  const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-mobile-state-'));
@@ -3542,6 +3617,8 @@ describe('production composition', () => {
3542
3617
  ['DELETE', '/api/auth/devices/:deviceId', '/api/auth/devices/device-1', 'protected'],
3543
3618
  ['GET', '/api/bootstrap', '/api/bootstrap', 'protected'],
3544
3619
  ['HEAD', '/api/bootstrap', '/api/bootstrap', 'protected'],
3620
+ ['GET', '/api/xerj', '/api/xerj', 'protected'],
3621
+ ['HEAD', '/api/xerj', '/api/xerj', 'protected'],
3545
3622
  ['GET', '/api/session-defaults', '/api/session-defaults', 'protected'],
3546
3623
  ['HEAD', '/api/session-defaults', '/api/session-defaults', 'protected'],
3547
3624
  ['PUT', '/api/session-defaults', '/api/session-defaults', 'protected'],
@@ -4434,19 +4511,10 @@ describe('production composition', () => {
4434
4511
  payload: { workspaceId: workspace.id, profile: 'default', provider: 'codex' },
4435
4512
  });
4436
4513
  expect(created.statusCode).toBe(202);
4437
- expect(firstCalls).toEqual([
4438
- 'initialize',
4439
- 'model/list',
4440
- 'initialize',
4441
- 'model/list',
4442
- 'initialize',
4443
- 'skills/list',
4444
- 'initialize',
4445
- 'skills/list',
4446
- 'initialize',
4447
- 'thread/start',
4448
- 'thread/read',
4449
- ]);
4514
+ expect(firstCalls.filter((method) => method === 'thread/start')).toHaveLength(1);
4515
+ expect(firstCalls).not.toContain('thread/resume');
4516
+ expect(firstCalls.indexOf('skills/list')).toBeLessThan(firstCalls.indexOf('thread/start'));
4517
+ expect(firstCalls.indexOf('config/read')).toBeLessThan(firstCalls.indexOf('thread/start'));
4450
4518
  await first.close();
4451
4519
  const secondCalls = [];
4452
4520
  const second = await composeAuthorizedApp({
@@ -4463,8 +4531,9 @@ describe('production composition', () => {
4463
4531
  await expect
4464
4532
  .poll(() => secondCalls, { timeout: 1_000 })
4465
4533
  .toEqual(['initialize', 'skills/list']);
4466
- const restored = await second.inject(`/api/sessions/${created.json().id}`);
4467
- expect(restored.json()).toMatchObject({
4534
+ await expect
4535
+ .poll(async () => (await second.inject(`/api/sessions/${created.json().id}`)).json())
4536
+ .toMatchObject({
4468
4537
  threadId: 'thread-1',
4469
4538
  state: 'stopped',
4470
4539
  agentActivity: { confidence: 'stale', root: { state: 'disconnected' } },
@@ -60,6 +60,12 @@ import { promoteRecentThread } from './features/sessions/promote-recent-thread/u
60
60
  import { FilesystemSkillProfileStore } from './platform/skills/filesystem-skill-profile-store.js';
61
61
  import { CodexSkillCatalog } from './platform/skills/codex-skill-catalog.js';
62
62
  import { CachedSkillCatalog } from './platform/skills/cached-skill-catalog.js';
63
+ import { XerjIndexer } from './platform/retrieval/xerj-indexer.js';
64
+ import { ManagedXerj, xerjDeadline } from './platform/retrieval/managed-xerj.js';
65
+ import { CodexXerj } from './platform/retrieval/codex-xerj.js';
66
+ import { CodexSerena } from './platform/codex/codex-serena.js';
67
+ import { ManagedSerena } from './platform/codex/managed-serena.js';
68
+ import { CodexCapabilities } from './platform/codex/codex-capabilities.js';
63
69
  import { compileSkillOverride } from './features/skills/model/skill-profile.js';
64
70
  import { SupervisedPlanRegistry } from './features/plans/application/supervised-plan-registry.js';
65
71
  import { FilesystemPlanStatusSource } from './platform/plans/filesystem-plan-status-source.js';
@@ -412,10 +418,37 @@ export async function composeRelayApp(options) {
412
418
  // kimi discovery is workspace-scoped, not profile-scoped: the profile only
413
419
  // decides which discovered skills a session's server materializes.
414
420
  const kimiSkillCatalog = new KimiSkillCatalog(kimiManager ?? null, kimiManager != null);
421
+ const retrievalCapability = options.xerj === 'off'
422
+ ? { check: async () => ({ status: 'absent' }) }
423
+ : (options.retrievalCapability ?? new ManagedXerj());
424
+ const xerjIndexer = new XerjIndexer(root, options.xerj ?? 'manual', retrievalCapability);
425
+ const xerj = new CodexXerj(retrievalCapability);
426
+ const serenaInstallation = new ManagedSerena();
427
+ const capabilities = new CodexCapabilities(xerj, new CodexSerena(serenaInstallation));
415
428
  const skillCatalog = (provider, profile) => provider === 'kimi'
416
429
  ? kimiSkillCatalog
417
430
  : new CodexSkillCatalog(profile, options.launchAppServer ?? launchCodexAppServer);
418
- const editorSkillCatalog = new CachedSkillCatalog((provider, profile, workspace) => skillCatalog(provider, profile).list(workspace));
431
+ const editorSkillCatalog = new CachedSkillCatalog((provider, profile, workspace) => provider === 'codex'
432
+ ? new CodexSkillCatalog(profile, options.launchAppServer ?? launchCodexAppServer, 5_000, capabilities).list(workspace)
433
+ : kimiSkillCatalog.list(workspace), async (provider, _profile, workspace, result) => {
434
+ if (provider !== 'codex')
435
+ return result;
436
+ const [xerjStatus, serenaStatus] = await Promise.all([
437
+ result.skills.some((skill) => skill.name === 'gestalt:xerj' && skill.enabled)
438
+ ? retrievalCapability.check({ cwd: workspace, deadline: xerjDeadline(), start: false })
439
+ : undefined,
440
+ result.skills.some((skill) => skill.name === 'gestalt:serena' && skill.enabled)
441
+ ? serenaInstallation.check()
442
+ : undefined,
443
+ ]);
444
+ return {
445
+ ...result,
446
+ skills: result.skills.map((skill) => (skill.name === 'gestalt:xerj' && xerjStatus && xerjStatus.status !== 'ready') ||
447
+ (skill.name === 'gestalt:serena' && serenaStatus && serenaStatus.status !== 'installed')
448
+ ? { ...skill, enabled: false }
449
+ : skill),
450
+ };
451
+ });
419
452
  const workspacePlanCatalog = new FilesystemWorkspacePlanCatalog();
420
453
  const planArchiver = new FilesystemPlanArchiver();
421
454
  const resolveSkills = async (session) => {
@@ -472,6 +505,9 @@ export async function composeRelayApp(options) {
472
505
  let recoverExitedSession = () => { };
473
506
  let recoverExitedKimiSession = () => { };
474
507
  let scheduleAgentCapacityRecovery = () => false;
508
+ const capacityRecoveries = new Set();
509
+ const capacityRecoveryTimers = new Map();
510
+ const capacityRecoveryTasks = new Map();
475
511
  let planMeasurementRefresh;
476
512
  const publishInteractionResolved = (sessionId, requestId, occurredAt, outcome) => {
477
513
  const interaction = interactions
@@ -963,7 +999,30 @@ export async function composeRelayApp(options) {
963
999
  failPendingCheckpointHandoffs(sessionId, false);
964
1000
  dismissPendingInteractions(sessionId, new Date().toISOString(), 'failed');
965
1001
  recoverExitedSession(sessionId);
966
- }, resolveSkills, planStatusSource, acceptPlanUpdate, options.planMeasurementBaseUrl, 30_000, 64, root, (session) => sessionModelConfig.resolve(session))
1002
+ }, undefined, planStatusSource, acceptPlanUpdate, options.planMeasurementBaseUrl, 30_000, 64, root, (session) => sessionModelConfig.resolve(session), {
1003
+ prepare: async (session, rpc, config, deadline) => {
1004
+ const catalog = await new CodexSkillCatalog(session.profile, options.launchAppServer ?? launchCodexAppServer, Math.max(1, deadline - Date.now())).list(session.workspacePath);
1005
+ const project = await skillProfiles.readWorkspaceDefault(session.workspacePath);
1006
+ const selected = compileSkillOverride({
1007
+ discovered: catalog.skills,
1008
+ explicit: session.effectiveSkillSelection?.skills.map((skill) => skill.name === 'gestalt:serena' &&
1009
+ session.effectiveSkillSelection?.serenaSelected !== undefined
1010
+ ? { ...skill, enabled: session.effectiveSkillSelection.serenaSelected }
1011
+ : skill) ?? options.explicitSkillProfile?.skills,
1012
+ project: project?.skills,
1013
+ });
1014
+ return capabilities.prepare({
1015
+ cwd: session.workspacePath,
1016
+ rpc,
1017
+ config,
1018
+ deadline,
1019
+ skills: catalog.skills,
1020
+ skillsConfig: selected.skillsConfig,
1021
+ start: true,
1022
+ });
1023
+ },
1024
+ verify: (rpc, threadId, state) => capabilities.verify(rpc, threadId, state),
1025
+ })
967
1026
  : null;
968
1027
  const handleKimiNotification = (sessionId, event) => {
969
1028
  const occurredAt = new Date().toISOString();
@@ -1084,13 +1143,13 @@ export async function composeRelayApp(options) {
1084
1143
  /** Routes a session to the runtime owning its provider's llm service. */
1085
1144
  const ownerRuntime = (session) => session.provider === 'kimi' ? kimiRuntime : runtime;
1086
1145
  if (runtime) {
1087
- const capacityRecoveries = new Set();
1088
1146
  scheduleAgentCapacityRecovery = (sessionId, acknowledge) => {
1089
- if (capacityRecoveries.has(sessionId) || !acknowledge())
1147
+ if (closing || capacityRecoveries.has(sessionId) || !acknowledge())
1090
1148
  return false;
1091
1149
  capacityRecoveries.add(sessionId);
1092
- setTimeout(() => {
1093
- void (async () => {
1150
+ const timer = setTimeout(() => {
1151
+ capacityRecoveryTimers.delete(sessionId);
1152
+ const task = Promise.resolve().then(async () => {
1094
1153
  try {
1095
1154
  if (closing)
1096
1155
  return;
@@ -1112,9 +1171,12 @@ export async function composeRelayApp(options) {
1112
1171
  }
1113
1172
  finally {
1114
1173
  capacityRecoveries.delete(sessionId);
1174
+ capacityRecoveryTasks.delete(sessionId);
1115
1175
  }
1116
- })();
1176
+ });
1177
+ capacityRecoveryTasks.set(sessionId, task);
1117
1178
  }, 500);
1179
+ capacityRecoveryTimers.set(sessionId, timer);
1118
1180
  return true;
1119
1181
  };
1120
1182
  const supervisor = new SessionSupervisor(async (sessionId) => {
@@ -1213,6 +1275,7 @@ export async function composeRelayApp(options) {
1213
1275
  recentThreads: recentThreadsForRelay,
1214
1276
  sessionDefaults,
1215
1277
  bootstrap: {
1278
+ xerj: () => xerjIndexer.status(),
1216
1279
  sessionDefaults,
1217
1280
  workspaces,
1218
1281
  profiles: options.profiles,
@@ -1789,6 +1852,8 @@ export async function composeRelayApp(options) {
1789
1852
  });
1790
1853
  };
1791
1854
  app.addHook('onListen', async () => {
1855
+ if (options.xerj)
1856
+ xerjIndexer.start();
1792
1857
  const profile = (await options.profiles.list()).find((item) => item.state === 'ok')?.name;
1793
1858
  if (profile)
1794
1859
  await editorSkillCatalog.refresh('codex', profile, root);
@@ -1817,6 +1882,16 @@ export async function composeRelayApp(options) {
1817
1882
  });
1818
1883
  app.addHook('onClose', async () => {
1819
1884
  closing = true;
1885
+ await xerjIndexer.close();
1886
+ for (const [sessionId, timer] of capacityRecoveryTimers) {
1887
+ clearTimeout(timer);
1888
+ capacityRecoveries.delete(sessionId);
1889
+ }
1890
+ capacityRecoveryTimers.clear();
1891
+ // Capacity recovery owns an app-server recycle that can still persist its
1892
+ // result after an await. Drain accepted operations before stopping runtimes
1893
+ // or closing the session database they use.
1894
+ await Promise.allSettled([...capacityRecoveryTasks.values()]);
1820
1895
  planMeasurementRefresh?.stopAll();
1821
1896
  for (const session of sessions.list()) {
1822
1897
  autopilot.dispose(session.id);
@@ -16,6 +16,7 @@ const optionNames = new Set([
16
16
  '--public-origin',
17
17
  '--skills',
18
18
  '--icon',
19
+ '--xerj',
19
20
  ]);
20
21
  const flagNames = new Set(['--disable-passkey-auth']);
21
22
  export function parseConfig(args, cwd = process.cwd()) {
@@ -41,6 +42,9 @@ export function parseConfig(args, cwd = process.cwd()) {
41
42
  values.set(option, value);
42
43
  index += 1;
43
44
  }
45
+ const xerj = values.get('--xerj') ?? 'manual';
46
+ if (xerj !== 'auto' && xerj !== 'manual' && xerj !== 'off')
47
+ throw new CliUsageError('--xerj must be auto, manual, or off');
44
48
  const portValue = values.get('--port') ?? '3000';
45
49
  const port = Number(portValue);
46
50
  if (!Number.isInteger(port) || port < 1 || port > 65535)
@@ -53,6 +57,7 @@ export function parseConfig(args, cwd = process.cwd()) {
53
57
  return {
54
58
  host,
55
59
  port,
60
+ xerj,
56
61
  passkeyAuthEnabled,
57
62
  relyingParty: createRelyingPartyConfig(publicOrigin),
58
63
  root: resolve(cwd, values.get('--cwd') ?? '.'),
@@ -22,6 +22,7 @@ export async function getBootstrap(deps) {
22
22
  }
23
23
  return {
24
24
  ...(deps.sessionDefaults ? { sessionDefaults, sessionDefaultsError } : {}),
25
+ ...(deps.xerj ? { xerj: deps.xerj() } : {}),
25
26
  workspaces,
26
27
  profiles,
27
28
  models: { codex: codexModels, kimi: kimiModels },
@@ -0,0 +1,11 @@
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 function registerXerjStatus(app, status) {
7
+ app.get('/api/xerj', async (_request, reply) => {
8
+ reply.header('Cache-Control', 'no-store');
9
+ return status();
10
+ });
11
+ }
@@ -3,11 +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 { registerXerjStatus } from './get-xerj-status/endpoint.js';
6
7
  import { registerGetBootstrap } from './get-bootstrap/endpoint.js';
7
8
  import { registerSessionDefaults } from './session-defaults/endpoint.js';
8
9
  export function registerCatalogRoutes(app, deps) {
9
10
  if (deps.bootstrap)
10
11
  registerGetBootstrap(app, deps.bootstrap);
12
+ if (deps.bootstrap?.xerj)
13
+ registerXerjStatus(app, deps.bootstrap.xerj);
11
14
  if (deps.sessionDefaults)
12
15
  registerSessionDefaults(app, deps.sessionDefaults);
13
16
  }
@@ -40,6 +40,7 @@ export function createEffectiveSkillSelection(input) {
40
40
  ...(input.selectedProfileName === undefined
41
41
  ? {}
42
42
  : { selectedProfileName: normalizeSkillProfileName(input.selectedProfileName) }),
43
+ ...(typeof input.serenaSelected === 'boolean' ? { serenaSelected: input.serenaSelected } : {}),
43
44
  skills: createSkillSelection(input.skills),
44
45
  ...(warnings.length > 0 ? { warnings: warnings.slice(0, 50) } : {}),
45
46
  };
@@ -41,7 +41,7 @@ export function registerListAvailableSkills(app, deps) {
41
41
  source: project ? 'project' : 'native',
42
42
  errors: discovered.errors.map(({ message }) => ({ message })),
43
43
  skills: skills
44
- .filter((skill) => !isAlwaysAdvertisedSkill(skill))
44
+ .filter((skill) => !isAlwaysAdvertisedSkill(skill) && skill.name !== 'gestalt:xerj')
45
45
  .sort((left, right) => left.path.localeCompare(right.path))
46
46
  .map((skill) => ({
47
47
  name: skill.name,
@@ -56,7 +56,9 @@ export const availableSkillSchema = z
56
56
  .strict();
57
57
  /** Gestalt workflow skills are session infrastructure, not optional profile entries. */
58
58
  export function isAlwaysAdvertisedSkill(skill) {
59
- return isGestaltSkillName(skill.name);
59
+ return (skill.name !== 'gestalt:serena' &&
60
+ isGestaltSkillName(skill.name) &&
61
+ (skill.name !== 'gestalt:xerj' || skill.enabled));
60
62
  }
61
63
  export function isGestaltSkillName(name) {
62
64
  return name.startsWith('gestalt:');
@@ -159,7 +161,11 @@ export function applySkillSelectionSnapshot(discovered, selection) {
159
161
  const enabledByPath = new Map(createSkillSelection(selection).map((entry) => [entry.path, entry.enabled]));
160
162
  return catalog.map((skill) => ({
161
163
  ...skill,
162
- enabled: isAlwaysAdvertisedSkill(skill) ? true : (enabledByPath.get(skill.path) ?? false),
164
+ enabled: skill.name === 'gestalt:xerj'
165
+ ? skill.enabled
166
+ : isAlwaysAdvertisedSkill(skill)
167
+ ? true
168
+ : (enabledByPath.get(skill.path) ?? false),
163
169
  }));
164
170
  }
165
171
  /** Explicit session selection takes precedence over a workspace default. */
@@ -215,7 +221,7 @@ export function createSkillProfile(input) {
215
221
  // Gestalt skills are mandatory thread infrastructure. Legacy profiles are
216
222
  // normalized on read so they cannot pin a stale plugin-cache version or
217
223
  // expose a meaningless enable/disable control in the editor.
218
- skills: createSkillSelection(input.skills.filter((skill) => !isGestaltSkillName(skill.name))),
224
+ skills: createSkillSelection(input.skills.filter((skill) => skill.name === 'gestalt:serena' || !isGestaltSkillName(skill.name))),
219
225
  };
220
226
  }
221
227
  /** Parse the version-1 YAML document without performing filesystem access. */
@@ -0,0 +1,96 @@
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 { CodexXerj } from '../retrieval/codex-xerj.js';
7
+ import { CodexSerena } from './codex-serena.js';
8
+ /** The two managed capabilities share lifecycle, but never share availability or approvals. */
9
+ export class CodexCapabilities {
10
+ xerj;
11
+ serena;
12
+ states = new WeakMap();
13
+ constructor(xerj, serena) {
14
+ this.xerj = xerj;
15
+ this.serena = serena;
16
+ }
17
+ async prepare(input) {
18
+ // Connection verification is a separate bounded phase for Serena. A slow
19
+ // optional XERJ probe must not spend Serena's entire connection allowance.
20
+ const serenaVerificationMs = Math.max(1, Math.min(5_000, input.deadline - Date.now()));
21
+ const [xerj, serena] = await Promise.all([
22
+ this.xerj.prepare(input),
23
+ this.serena.prepare(input),
24
+ ]);
25
+ if (serena.ready)
26
+ serena.deadline = Date.now() + serenaVerificationMs;
27
+ const serenaPath = input.skills.find((skill) => skill.name === 'gestalt:serena')?.path;
28
+ const state = {
29
+ deadline: Math.max(input.deadline, serena.ready ? serena.deadline : input.deadline),
30
+ get ready() {
31
+ return xerj.ready || serena.ready;
32
+ },
33
+ get capabilities() {
34
+ return [
35
+ {
36
+ skillName: 'gestalt:xerj',
37
+ serverName: 'gestalt-xerj',
38
+ ready: xerj.ready,
39
+ diagnostic: xerj.diagnostic,
40
+ },
41
+ {
42
+ skillName: 'gestalt:serena',
43
+ serverName: 'gestalt-serena',
44
+ ready: serena.ready,
45
+ diagnostic: serena.diagnostic,
46
+ },
47
+ ];
48
+ },
49
+ get skillsConfig() {
50
+ return xerj.skillsConfig.map((entry) => entry.path === serenaPath
51
+ ? (serena.skillsConfig.find((candidate) => candidate.path === serenaPath) ?? entry)
52
+ : entry);
53
+ },
54
+ get config() {
55
+ const xerjInstructions = String(xerj.config.developer_instructions ?? '');
56
+ const serenaInstructions = String(serena.config.developer_instructions ?? '');
57
+ return {
58
+ ...input.config,
59
+ mcp_servers: {
60
+ ...xerj.config.mcp_servers,
61
+ ...serena.config.mcp_servers,
62
+ },
63
+ skills: {
64
+ config: [
65
+ ...(xerj.config.skills?.config ?? []),
66
+ ...(serena.config.skills?.config ?? []),
67
+ ],
68
+ },
69
+ developer_instructions: `${xerjInstructions}\n${serenaInstructions.slice(serenaInstructions.indexOf('<gestalt_serena_'))}`,
70
+ };
71
+ },
72
+ // verify already disables only the failed connection; runtime rebinds the composed config.
73
+ fallback() { },
74
+ };
75
+ this.states.set(state, { xerj, serena });
76
+ return state;
77
+ }
78
+ async verify(rpc, threadId, state) {
79
+ const pair = this.states.get(state);
80
+ if (!pair)
81
+ return false;
82
+ const [xerj, serena] = await Promise.all([
83
+ pair.xerj.ready ? this.xerj.verify(rpc, threadId, pair.xerj) : true,
84
+ pair.serena.ready ? this.serena.verify(rpc, threadId, pair.serena) : true,
85
+ ]);
86
+ if (!xerj) {
87
+ pair.xerj.fallback();
88
+ pair.xerj.diagnostic = 'connection-unavailable';
89
+ }
90
+ if (!serena) {
91
+ pair.serena.fallback();
92
+ pair.serena.diagnostic = 'connection-unavailable';
93
+ }
94
+ return xerj && serena;
95
+ }
96
+ }