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,150 @@
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
+ import { beforeDeadline, } from '../retrieval/codex-xerj.js';
8
+ import { ManagedSerena, serenaTools } from './managed-serena.js';
9
+ export const serenaServerName = 'gestalt-serena';
10
+ // config/read includes unset defaults as null. Thread overrides cannot encode
11
+ // those as TOML values; retain explicit settings, including tool approvals.
12
+ function omitUnsetConfig(value) {
13
+ if (Array.isArray(value))
14
+ return value.map(omitUnsetConfig);
15
+ if (value !== null && typeof value === 'object')
16
+ return Object.fromEntries(Object.entries(value)
17
+ .filter(([, entry]) => entry !== null && entry !== undefined)
18
+ .map(([key, entry]) => [key, omitUnsetConfig(entry)]));
19
+ return value;
20
+ }
21
+ /** Connection availability only. Native model calls establish effective sandbox authority. */
22
+ export class CodexSerena {
23
+ installation;
24
+ constructor(installation = new ManagedSerena()) {
25
+ this.installation = installation;
26
+ }
27
+ async prepare(input) {
28
+ const skill = input.skills.find((entry) => entry.name === 'gestalt:serena');
29
+ let native = {};
30
+ let compatible = false;
31
+ try {
32
+ const read = (await beforeDeadline(input.rpc.request('config/read', { includeLayers: false }), input.deadline));
33
+ native = read.config ?? {};
34
+ compatible = read.config !== undefined;
35
+ }
36
+ catch {
37
+ /* Fail closed on an incompatible runtime. */
38
+ }
39
+ const servers = omitUnsetConfig(native.mcp_servers ?? {});
40
+ const reserved = servers[serenaServerName] ?? {};
41
+ const mcp = {};
42
+ for (const [name, server] of Object.entries(servers)) {
43
+ const args = server?.args;
44
+ if (args?.[0] === 'serena' && args[1] === 'mcp')
45
+ mcp[name] = { ...server, enabled: false, required: false };
46
+ }
47
+ const instructions = typeof native.developer_instructions === 'string' ? native.developer_instructions : '';
48
+ const state = {
49
+ ready: false,
50
+ deadline: input.deadline,
51
+ config: {},
52
+ skillsConfig: input.skillsConfig,
53
+ fallback: () => {
54
+ state.ready = false;
55
+ state.skillsConfig = input.skillsConfig.map((entry) => ({
56
+ ...entry,
57
+ enabled: entry.path === skill?.path ? false : entry.enabled,
58
+ }));
59
+ state.config = {
60
+ ...input.config,
61
+ skills: { config: [{ name: 'gestalt:serena', enabled: false }] },
62
+ mcp_servers: {
63
+ ...mcp,
64
+ [serenaServerName]: { ...reserved, enabled: false, required: false },
65
+ },
66
+ developer_instructions: `${instructions}\n<gestalt_serena_unavailable>\nSerena is unavailable in this runtime. Earlier Serena guidance is inactive; use native code tools.\n</gestalt_serena_unavailable>`,
67
+ };
68
+ },
69
+ };
70
+ state.fallback();
71
+ const rules = native.skills;
72
+ const selected = input.skillsConfig.find((entry) => entry.path === skill?.path);
73
+ const conflict = reserved.enabled === false ||
74
+ (reserved.env && Object.keys(reserved.env).length) ||
75
+ reserved.enabled_tools ||
76
+ reserved.disabled_tools?.length ||
77
+ Object.values((reserved.tools ?? {})).some((tool) => tool.enabled !== undefined);
78
+ if (!compatible ||
79
+ !skill ||
80
+ !selected?.enabled ||
81
+ rules?.include_instructions === false ||
82
+ native.features?.hooks !== true ||
83
+ rules?.config?.filter((rule) => rule.name === skill.name || rule.path === skill.path).at(-1)
84
+ ?.enabled === false ||
85
+ conflict ||
86
+ Date.now() >= input.deadline)
87
+ return state;
88
+ try {
89
+ const install = await beforeDeadline(this.installation.check(), input.deadline);
90
+ if (install.status !== 'installed') {
91
+ state.diagnostic = 'installation-unavailable';
92
+ return state;
93
+ }
94
+ const guidance = await beforeDeadline(readFile(skill.path, 'utf8'), input.deadline);
95
+ if (guidance.length > 16_384)
96
+ return state;
97
+ state.config = {
98
+ ...input.config,
99
+ skills: { config: [{ name: 'gestalt:serena', enabled: true }] },
100
+ mcp_servers: {
101
+ ...mcp,
102
+ [serenaServerName]: {
103
+ ...reserved,
104
+ command: install.manager,
105
+ args: ['serena', 'mcp', '--cwd', input.cwd],
106
+ cwd: input.cwd,
107
+ env_vars: ['CODEX_HOME', 'GESTALT_HOME'],
108
+ enabled: true,
109
+ required: false,
110
+ startup_readiness: 'connection',
111
+ startup_timeout_ms: Math.max(1, input.deadline - Date.now()),
112
+ },
113
+ },
114
+ developer_instructions: `${instructions}\n<gestalt_serena_capability>\nSerena is bound to this workspace. Connection and listed tools do not prove language readiness. First call get_symbols_overview on a current project source file and verify success before semantic editing; on failure use native code tools. Native session and child permissions and approvals apply. Plan mode prohibits edits. Do not switch projects or modes.\n${guidance}\n</gestalt_serena_capability>`,
115
+ };
116
+ state.skillsConfig = input.skillsConfig;
117
+ state.ready = true;
118
+ }
119
+ catch {
120
+ state.fallback();
121
+ state.diagnostic = 'connection-unavailable';
122
+ }
123
+ return state;
124
+ }
125
+ async verify(rpc, threadId, state) {
126
+ if (!state.ready)
127
+ return false;
128
+ try {
129
+ while (Date.now() < state.deadline) {
130
+ const result = (await beforeDeadline(rpc.request('mcpServerStatus/list', {
131
+ threadId,
132
+ serverName: serenaServerName,
133
+ detail: 'full',
134
+ }), state.deadline));
135
+ const server = result.data?.find((entry) => entry.name === serenaServerName);
136
+ if (server?.runtimeStatus === 'connected' &&
137
+ !server.toolsError &&
138
+ serenaTools.every((tool) => Object.hasOwn(server.tools ?? {}, tool)))
139
+ return true;
140
+ if (server?.runtimeStatus !== 'starting')
141
+ return false;
142
+ await beforeDeadline(new Promise((resolve) => setTimeout(resolve, 25)), state.deadline);
143
+ }
144
+ }
145
+ catch {
146
+ /* Optional connection failure must not prevent a session. */
147
+ }
148
+ return false;
149
+ }
150
+ }
@@ -0,0 +1,69 @@
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 { constants } from 'node:fs';
7
+ import { access, readFile, stat } from 'node:fs/promises';
8
+ import { homedir } from 'node:os';
9
+ import { isAbsolute, join } from 'node:path';
10
+ export const serenaTools = [
11
+ 'get_symbols_overview',
12
+ 'find_symbol',
13
+ 'initial_instructions',
14
+ 'replace_symbol_body',
15
+ ];
16
+ /** Read shared executable metadata only; never prepare a project with operator authority. */
17
+ export class ManagedSerena {
18
+ environment;
19
+ constructor(environment = process.env) {
20
+ this.environment = environment;
21
+ }
22
+ async check() {
23
+ const home = this.environment.GESTALT_HOME ?? join(this.environment.HOME ?? homedir(), '.gestalt');
24
+ try {
25
+ const path = join(home, 'serena', 'active.json');
26
+ if ((await stat(path)).size > 262_144)
27
+ return { status: 'unavailable' };
28
+ const install = JSON.parse(await readFile(path, 'utf8'));
29
+ if (install.schemaVersion !== 1 ||
30
+ install.contractVersion !== 1 ||
31
+ !/^\d+\.\d+\.\d+$/.test(install.version) ||
32
+ !Array.isArray(install.tools) ||
33
+ !serenaTools.every((name) => install.tools.some((tool) => tool.name === name && tool.inputSchema?.type === 'object')))
34
+ return { status: 'unavailable' };
35
+ for (const executable of [install.executable, install.python, install.uv]) {
36
+ if (typeof executable !== 'string' || !isAbsolute(executable))
37
+ return { status: 'unavailable' };
38
+ await access(executable, constants.X_OK);
39
+ }
40
+ if (typeof install.pythonInstallDir !== 'string' ||
41
+ !isAbsolute(install.pythonInstallDir) ||
42
+ !(await stat(install.pythonInstallDir)).isDirectory())
43
+ return { status: 'unavailable' };
44
+ const candidates = this.environment.GESTALT_MANAGER_BIN
45
+ ? [this.environment.GESTALT_MANAGER_BIN]
46
+ : (this.environment.PATH ?? '')
47
+ .split(':')
48
+ .filter(Boolean)
49
+ .map((path) => join(path, 'gestalt'));
50
+ for (const manager of candidates) {
51
+ if (!isAbsolute(manager))
52
+ continue;
53
+ try {
54
+ await access(manager, constants.X_OK);
55
+ return { status: 'installed', manager, version: install.version };
56
+ }
57
+ catch {
58
+ /* Try the next established manager path. */
59
+ }
60
+ }
61
+ return { status: 'unavailable' };
62
+ }
63
+ catch (error) {
64
+ return {
65
+ status: error.code === 'ENOENT' ? 'absent' : 'unavailable',
66
+ };
67
+ }
68
+ }
69
+ }
@@ -6,6 +6,42 @@
6
6
  import { countDiffLines } from '../../../shared/contracts/file-change.js';
7
7
  import { relative } from 'node:path';
8
8
  export function normalizeCodexNotification(sessionId, sequence, occurredAt, notification, workspacePath, activeTurnId, origin = { kind: 'root' }) {
9
+ const connection = record(notification.params);
10
+ if (notification.method === 'mcpServer/statusUpdated' &&
11
+ connection?.name === 'gestalt-xerj' &&
12
+ ['failed', 'cancelled'].includes(String(connection.status))) {
13
+ return {
14
+ sessionId,
15
+ sequence,
16
+ occurredAt,
17
+ type: 'activity.updated',
18
+ payload: {
19
+ id: 'gestalt-xerj-availability',
20
+ label: 'Xerj unavailable',
21
+ detail: 'Retrieval is unavailable. Check gestalt xerj status. Use rg and current source reads; readiness will be checked when the runtime resumes.',
22
+ ...(activeTurnId ? { turnId: activeTurnId } : {}),
23
+ },
24
+ };
25
+ }
26
+ if (notification.method === 'mcpServer/statusUpdated' &&
27
+ connection?.name === 'gestalt-serena' &&
28
+ ['connected', 'failed', 'cancelled'].includes(String(connection.status))) {
29
+ const connected = connection.status === 'connected';
30
+ return {
31
+ sessionId,
32
+ sequence,
33
+ occurredAt,
34
+ type: 'activity.updated',
35
+ payload: {
36
+ id: 'gestalt-serena-availability',
37
+ label: connected ? 'Serena connected' : 'Serena unavailable',
38
+ detail: connected
39
+ ? 'Connection verified. Before semantic editing, call get_symbols_overview on a current source file and verify success; language readiness is still unverified.'
40
+ : 'Serena is unavailable in this session. Use native code tools; connection availability will be checked when the runtime resumes. Operators can inspect installation with gestalt serena doctor.',
41
+ ...(activeTurnId ? { turnId: activeTurnId } : {}),
42
+ },
43
+ };
44
+ }
9
45
  const decoded = decodeNotification(notification);
10
46
  if (!decoded)
11
47
  return null;
@@ -18,13 +18,17 @@ import { threadPlanName } from './thread-plan-name.js';
18
18
  import { WriterAcquisitionError, } from '../../features/sessions/application/writer-acquisition.js';
19
19
  import { CodexJsonRpcError, isCodexThreadWriterBusy, isMissingCodexThreadRollout, } from './json-rpc-client.js';
20
20
  import { resolvedServerRequestId } from './server-request.js';
21
+ import { xerjDeadline } from '../retrieval/managed-xerj.js';
21
22
  /** Sticky thread config keeps skill paths out of the app-server process argv. */
22
23
  export function threadSkillConfig(skillsConfig, modelConfig = {}) {
24
+ const conditional = modelConfig.skills?.config ?? [];
23
25
  return {
24
26
  config: {
25
27
  ...modelConfig,
26
28
  'tools.update_plan.enabled': true,
27
- ...(skillsConfig === undefined ? {} : { skills: { config: skillsConfig } }),
29
+ ...(skillsConfig === undefined
30
+ ? {}
31
+ : { skills: { config: [...skillsConfig, ...conditional] } }),
28
32
  },
29
33
  };
30
34
  }
@@ -62,6 +66,10 @@ class SessionResource {
62
66
  this.unregister = unregister;
63
67
  this.onDisposed = onDisposed;
64
68
  }
69
+ retrieval;
70
+ retrievalFailureReported = false;
71
+ capabilityFailuresReported = new Set();
72
+ readinessDeadline = xerjDeadline();
65
73
  dispose() {
66
74
  if (this.disposed)
67
75
  return false;
@@ -102,13 +110,14 @@ export class CodexSessionRuntime {
102
110
  maxPendingRequests;
103
111
  readerCwd;
104
112
  resolveModelConfig;
113
+ retrieval;
105
114
  serverResponseListeners = new Set();
106
115
  constructor(launch,
107
116
  // Kept as an ignored compatibility slot while callers migrate from the old
108
117
  // correlated-map constructor shape. Live ownership is `sessions` only.
109
118
  _legacyProcesses = undefined, onNotification, onServerRequest, onProcessExit, resolveSkills, planStatusSource, onPlanStatus, planMeasurementBaseUrl,
110
119
  // Compatibility slot: blocking app-server requests wait for explicit input.
111
- _legacyRequestTimeoutMs = undefined, maxPendingRequests = 64, readerCwd, resolveModelConfig) {
120
+ _legacyRequestTimeoutMs = undefined, maxPendingRequests = 64, readerCwd, resolveModelConfig, retrieval) {
112
121
  this.launch = launch;
113
122
  this.onNotification = onNotification;
114
123
  this.onServerRequest = onServerRequest;
@@ -120,6 +129,7 @@ export class CodexSessionRuntime {
120
129
  this.maxPendingRequests = maxPendingRequests;
121
130
  this.readerCwd = readerCwd;
122
131
  this.resolveModelConfig = resolveModelConfig;
132
+ this.retrieval = retrieval;
123
133
  void _legacyProcesses;
124
134
  void _legacyRequestTimeoutMs;
125
135
  }
@@ -134,13 +144,15 @@ export class CodexSessionRuntime {
134
144
  clientInfo: { name: 'gestalt-mobile', version: '0.1.0' },
135
145
  capabilities: { experimentalApi: true },
136
146
  });
147
+ await this.prepareRetrieval(resource, session);
137
148
  const startedThreadId = await this.startThread(resource.process, session, resource.skillsConfig, resource.modelConfig);
138
149
  resource.threadId = startedThreadId;
150
+ await this.verifyRetrieval(resource, session, true);
139
151
  this.sessions.set(session.id, resource);
140
152
  await this.writePendingThreadName(session.id);
141
- return RelaySession.rehydrate(session)
142
- .bindThread(startedThreadId, now)
143
- .supportsAttentionTool(now).snapshot;
153
+ return this.withEffectiveRetrieval(RelaySession.rehydrate(session)
154
+ .bindThread(resource.threadId, now)
155
+ .supportsAttentionTool(now).snapshot, resource);
144
156
  }
145
157
  catch (error) {
146
158
  resource.dispose();
@@ -754,7 +766,9 @@ export class CodexSessionRuntime {
754
766
  clientInfo: { name: 'gestalt-mobile', version: '0.1.0' },
755
767
  capabilities: { experimentalApi: true },
756
768
  });
769
+ await this.prepareRetrieval(resource, session);
757
770
  let result;
771
+ let missingRollout;
758
772
  try {
759
773
  await resource.process.rpc.request('thread/resume', {
760
774
  threadId: session.threadId,
@@ -782,14 +796,18 @@ export class CodexSessionRuntime {
782
796
  catch (error) {
783
797
  if (!canRebindMissingRollout(session, error))
784
798
  throw error;
799
+ missingRollout = error;
785
800
  const replacementThreadId = await this.startThread(resource.process, session, resource.skillsConfig, resource.modelConfig);
786
801
  result = rebindMissingRollout(session, error, replacementThreadId, now);
787
802
  }
788
803
  resource.threadId = result.session.threadId;
804
+ await this.verifyRetrieval(resource, session, result.replacementCreated);
805
+ if (result.replacementCreated && resource.threadId !== result.session.threadId)
806
+ result = rebindMissingRollout(session, missingRollout, resource.threadId, now);
789
807
  this.sessions.get(session.id)?.dispose();
790
808
  this.sessions.set(session.id, resource);
791
809
  await this.writePendingThreadName(session.id);
792
- return result;
810
+ return { ...result, session: this.withEffectiveRetrieval(result.session, resource) };
793
811
  }
794
812
  catch (error) {
795
813
  resource.dispose();
@@ -884,6 +902,7 @@ export class CodexSessionRuntime {
884
902
  : { sandbox: selection };
885
903
  }
886
904
  async createResource(session) {
905
+ const deadline = xerjDeadline();
887
906
  const lease = this.planStatusSource
888
907
  ? await this.planStatusSource.open({ id: session.id, workspacePath: session.workspacePath }, (update) => this.onPlanStatus?.(session.id, update))
889
908
  : undefined;
@@ -914,6 +933,7 @@ export class CodexSessionRuntime {
914
933
  if (this.sessions.get(session.id) === resource)
915
934
  this.sessions.delete(session.id);
916
935
  });
936
+ resource.readinessDeadline = deadline;
917
937
  // Own process exit before resume/initialization can make this resource appear healthy.
918
938
  // A short-lived child could otherwise leave a durable ready session without a writer.
919
939
  const exitUnsubscribe = process.onExit?.(() => {
@@ -928,6 +948,21 @@ export class CodexSessionRuntime {
928
948
  const notificationUnsubscribe = process.rpc.onNotification((notification) => {
929
949
  if (!resource.active)
930
950
  return;
951
+ if (notification.method === 'mcpServer/statusUpdated') {
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
+ }
959
+ if (status?.name === 'gestalt-xerj' &&
960
+ ['failed', 'cancelled'].includes(status.status ?? '')) {
961
+ if (resource.retrievalFailureReported)
962
+ return;
963
+ resource.retrievalFailureReported = true;
964
+ }
965
+ }
931
966
  const childModel = decodeThreadSettingsModel(notification);
932
967
  if (childModel &&
933
968
  (resource.spawnedAgentModels.has(childModel.threadId) ||
@@ -971,6 +1006,111 @@ export class CodexSessionRuntime {
971
1006
  throw error;
972
1007
  }
973
1008
  }
1009
+ withEffectiveRetrieval(session, resource) {
1010
+ if (!resource.retrieval || !session.effectiveSkillSelection)
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);
1017
+ return {
1018
+ ...session,
1019
+ effectiveSkillSelection: {
1020
+ ...session.effectiveSkillSelection,
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),
1040
+ },
1041
+ };
1042
+ }
1043
+ async prepareRetrieval(resource, session) {
1044
+ if (!this.retrieval)
1045
+ return;
1046
+ const state = await this.retrieval.prepare(session, resource.process.rpc, resource.modelConfig, resource.readinessDeadline);
1047
+ resource.retrieval = state;
1048
+ resource.skillsConfig = state.skillsConfig;
1049
+ resource.modelConfig = state.config;
1050
+ this.reportCapabilityFailures(resource, session);
1051
+ if (state.diagnostic && !resource.retrievalFailureReported) {
1052
+ resource.retrievalFailureReported = true;
1053
+ this.onNotification?.(session.id, {
1054
+ method: 'mcpServer/statusUpdated',
1055
+ params: { name: 'gestalt-xerj', status: 'failed' },
1056
+ }, { kind: 'root' });
1057
+ }
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
+ }
1070
+ async verifyRetrieval(resource, session, fresh = false) {
1071
+ const state = resource.retrieval;
1072
+ if (!state?.ready || !resource.threadId || !this.retrieval)
1073
+ return;
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' });
1080
+ return;
1081
+ }
1082
+ state.fallback();
1083
+ this.reportCapabilityFailures(resource, session);
1084
+ if (!state.capabilities && !resource.retrievalFailureReported) {
1085
+ resource.retrievalFailureReported = true;
1086
+ this.onNotification?.(session.id, {
1087
+ method: 'mcpServer/statusUpdated',
1088
+ params: {
1089
+ name: 'gestalt-xerj',
1090
+ status: 'failed',
1091
+ },
1092
+ }, { kind: 'root' });
1093
+ }
1094
+ resource.skillsConfig = state.skillsConfig;
1095
+ resource.modelConfig = state.config;
1096
+ // A fresh Codex thread has no durable rollout until its first turn, so it
1097
+ // cannot be resumed. Release its connection and create the fallback root
1098
+ // before publishing a thread ID. Persisted resumes retain their identity.
1099
+ if (fresh) {
1100
+ await resource.process.rpc.request('thread/unsubscribe', { threadId: resource.threadId });
1101
+ resource.threadId = await this.startThread(resource.process, session, resource.skillsConfig, resource.modelConfig);
1102
+ return;
1103
+ }
1104
+ await resource.process.rpc.request('thread/resume', {
1105
+ threadId: resource.threadId,
1106
+ cwd: session.workspacePath,
1107
+ ...threadSkillConfig(resource.skillsConfig, resource.modelConfig),
1108
+ ...(session.executionPolicy?.approvalPolicy
1109
+ ? { approvalPolicy: session.executionPolicy.approvalPolicy }
1110
+ : {}),
1111
+ ...this.permissionParams(session),
1112
+ });
1113
+ }
974
1114
  resolveNotificationOrigin(resource, notification) {
975
1115
  const params = asRecord(notification.params);
976
1116
  if (!params)
@@ -45,6 +45,15 @@ export class KimiSkillCatalog {
45
45
  const skill = wire;
46
46
  if (!skill || typeof skill !== 'object' || typeof skill.name !== 'string')
47
47
  continue;
48
+ // kimi web workers accept only global MCP configuration and expose no
49
+ // per-session native connection readiness gate. Never materialize
50
+ // conditional retrieval guidance without that verified connection.
51
+ if (skill.name === 'gestalt:xerj') {
52
+ errors.push({
53
+ message: 'Xerj retrieval is unavailable for Kimi web: native session readiness is unsupported.',
54
+ });
55
+ continue;
56
+ }
48
57
  // The shared catalog contract canonicalizes skill paths as absolute
49
58
  // filesystem paths (profile snapshots and overrides resolve against
50
59
  // them). kimi built-ins report no path and cannot be materialized per