cordisx 0.1.0-beta.38 → 0.1.0-beta.39

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 (180) hide show
  1. package/dist/assets/claude-bridge/hooks/register.ts +408 -21
  2. package/dist/assets/launcher/native-agent-models-mcp.mjs +69 -8
  3. package/dist/assets/launcher/native-app-server-protocol.mjs +30 -1
  4. package/dist/assets/launcher/native-managed-resume.mjs +31 -0
  5. package/dist/codex-adapter/LICENSE +661 -0
  6. package/dist/codex-adapter/THIRD_PARTY_NOTICES.md +25 -0
  7. package/dist/codex-adapter/adapter.d.mts +13 -0
  8. package/dist/codex-adapter/adapter.mjs +7113 -0
  9. package/dist/codex-adapter/contracts.d.ts +56 -0
  10. package/dist/codex-adapter/contracts.js +1 -0
  11. package/dist/codex-adapter/index.d.ts +13 -0
  12. package/dist/codex-adapter/index.js +82 -0
  13. package/dist/codex-adapter/native-account-structure.d.ts +7 -0
  14. package/dist/codex-adapter/native-account-structure.js +70 -0
  15. package/dist/codex-adapter/native-agent-task-source.d.ts +27 -0
  16. package/dist/codex-adapter/native-agent-task-source.js +76 -0
  17. package/dist/codex-adapter/native-agent-task-transform.d.ts +9 -0
  18. package/dist/codex-adapter/native-agent-task-transform.js +204 -0
  19. package/dist/codex-adapter/native-lazy-wire-request.d.ts +9 -0
  20. package/dist/codex-adapter/native-lazy-wire-request.js +47 -0
  21. package/dist/codex-adapter/native-operation-request-transform.d.ts +57 -0
  22. package/dist/codex-adapter/native-operation-request-transform.js +185 -0
  23. package/dist/codex-adapter/native-source-bindings.d.ts +3 -0
  24. package/dist/codex-adapter/native-source-bindings.js +69 -0
  25. package/dist/codex-adapter/native-source-structure.d.ts +18 -0
  26. package/dist/codex-adapter/native-source-structure.js +50 -0
  27. package/dist/codex-adapter/native-submission-legacy-resources.d.ts +4 -0
  28. package/dist/codex-adapter/native-submission-legacy-resources.js +17 -0
  29. package/dist/codex-adapter/native-submission-structure.d.ts +14 -0
  30. package/dist/codex-adapter/native-submission-structure.js +425 -0
  31. package/dist/codex-adapter/native-submit-orchestrator-transform.d.ts +45 -0
  32. package/dist/codex-adapter/native-submit-orchestrator-transform.js +171 -0
  33. package/dist/codex-adapter/reasoning.d.ts +1 -0
  34. package/dist/codex-adapter/reasoning.js +10 -0
  35. package/dist/native/native-helper-artifact.json +1 -1
  36. package/dist/src/cli/adapter-command.d.ts +3 -0
  37. package/dist/src/cli/adapter-command.d.ts.map +1 -0
  38. package/dist/src/cli/adapter-command.js +39 -0
  39. package/dist/src/cli/adapter-command.js.map +1 -0
  40. package/dist/src/cli/help.d.ts +1 -1
  41. package/dist/src/cli/help.d.ts.map +1 -1
  42. package/dist/src/cli/help.js +1 -0
  43. package/dist/src/cli/help.js.map +1 -1
  44. package/dist/src/cli/model-export-parse.js +1 -1
  45. package/dist/src/cli/model-export-parse.js.map +1 -1
  46. package/dist/src/cli/run-command-dispatch.d.ts.map +1 -1
  47. package/dist/src/cli/run-command-dispatch.js +8 -0
  48. package/dist/src/cli/run-command-dispatch.js.map +1 -1
  49. package/dist/src/launcher/agent-bridge-context.d.ts +95 -0
  50. package/dist/src/launcher/agent-bridge-context.d.ts.map +1 -0
  51. package/dist/src/launcher/agent-bridge-context.js +197 -0
  52. package/dist/src/launcher/agent-bridge-context.js.map +1 -0
  53. package/dist/src/launcher/agent-bridge-contract.d.ts +95 -0
  54. package/dist/src/launcher/agent-bridge-contract.d.ts.map +1 -0
  55. package/dist/src/launcher/agent-bridge-contract.js +256 -0
  56. package/dist/src/launcher/agent-bridge-contract.js.map +1 -0
  57. package/dist/src/launcher/agent-bridge-operations.d.ts +112 -0
  58. package/dist/src/launcher/agent-bridge-operations.d.ts.map +1 -0
  59. package/dist/src/launcher/agent-bridge-operations.js +337 -0
  60. package/dist/src/launcher/agent-bridge-operations.js.map +1 -0
  61. package/dist/src/launcher/agent-bridge-paths.d.ts +11 -0
  62. package/dist/src/launcher/agent-bridge-paths.d.ts.map +1 -0
  63. package/dist/src/launcher/agent-bridge-paths.js +16 -0
  64. package/dist/src/launcher/agent-bridge-paths.js.map +1 -0
  65. package/dist/src/launcher/agent-bridge-transcript.d.ts +43 -0
  66. package/dist/src/launcher/agent-bridge-transcript.d.ts.map +1 -0
  67. package/dist/src/launcher/agent-bridge-transcript.js +76 -0
  68. package/dist/src/launcher/agent-bridge-transcript.js.map +1 -0
  69. package/dist/src/launcher/agent-bridge-validation.d.ts +15 -0
  70. package/dist/src/launcher/agent-bridge-validation.d.ts.map +1 -0
  71. package/dist/src/launcher/agent-bridge-validation.js +73 -0
  72. package/dist/src/launcher/agent-bridge-validation.js.map +1 -0
  73. package/dist/src/launcher/agent-bridge.d.ts +36 -23
  74. package/dist/src/launcher/agent-bridge.d.ts.map +1 -1
  75. package/dist/src/launcher/agent-bridge.js +462 -152
  76. package/dist/src/launcher/agent-bridge.js.map +1 -1
  77. package/dist/src/launcher/cdp-installation-bootstrap.d.ts.map +1 -1
  78. package/dist/src/launcher/cdp-installation-bootstrap.js +10 -0
  79. package/dist/src/launcher/cdp-installation-bootstrap.js.map +1 -1
  80. package/dist/src/launcher/claude-desktop-process.d.ts +2 -0
  81. package/dist/src/launcher/claude-desktop-process.d.ts.map +1 -1
  82. package/dist/src/launcher/claude-desktop-process.js +6 -5
  83. package/dist/src/launcher/claude-desktop-process.js.map +1 -1
  84. package/dist/src/launcher/claude-host-sessions.d.ts +14 -27
  85. package/dist/src/launcher/claude-host-sessions.d.ts.map +1 -1
  86. package/dist/src/launcher/claude-host-sessions.js +337 -199
  87. package/dist/src/launcher/claude-host-sessions.js.map +1 -1
  88. package/dist/src/launcher/claude-session-records.d.ts +38 -0
  89. package/dist/src/launcher/claude-session-records.d.ts.map +1 -0
  90. package/dist/src/launcher/claude-session-records.js +166 -0
  91. package/dist/src/launcher/claude-session-records.js.map +1 -0
  92. package/dist/src/launcher/codex-adapter/files.d.ts +7 -0
  93. package/dist/src/launcher/codex-adapter/files.d.ts.map +1 -0
  94. package/dist/src/launcher/codex-adapter/files.js +66 -0
  95. package/dist/src/launcher/codex-adapter/files.js.map +1 -0
  96. package/dist/src/launcher/codex-adapter/registry.d.ts +25 -0
  97. package/dist/src/launcher/codex-adapter/registry.d.ts.map +1 -0
  98. package/dist/src/launcher/codex-adapter/registry.js +114 -0
  99. package/dist/src/launcher/codex-adapter/registry.js.map +1 -0
  100. package/dist/src/launcher/codex-adapter/runtime.d.ts +16 -0
  101. package/dist/src/launcher/codex-adapter/runtime.d.ts.map +1 -0
  102. package/dist/src/launcher/codex-adapter/runtime.js +122 -0
  103. package/dist/src/launcher/codex-adapter/runtime.js.map +1 -0
  104. package/dist/src/launcher/codex-adapter/selection.d.ts +24 -0
  105. package/dist/src/launcher/codex-adapter/selection.d.ts.map +1 -0
  106. package/dist/src/launcher/codex-adapter/selection.js +148 -0
  107. package/dist/src/launcher/codex-adapter/selection.js.map +1 -0
  108. package/dist/src/launcher/codex-adapter/store.d.ts +40 -0
  109. package/dist/src/launcher/codex-adapter/store.d.ts.map +1 -0
  110. package/dist/src/launcher/codex-adapter/store.js +256 -0
  111. package/dist/src/launcher/codex-adapter/store.js.map +1 -0
  112. package/dist/src/launcher/integration-status.d.ts +105 -0
  113. package/dist/src/launcher/integration-status.d.ts.map +1 -0
  114. package/dist/src/launcher/integration-status.js +327 -0
  115. package/dist/src/launcher/integration-status.js.map +1 -0
  116. package/dist/src/launcher/native-account-structure.d.ts +1 -7
  117. package/dist/src/launcher/native-account-structure.d.ts.map +1 -1
  118. package/dist/src/launcher/native-account-structure.js +2 -70
  119. package/dist/src/launcher/native-account-structure.js.map +1 -1
  120. package/dist/src/launcher/native-adapter-analysis.d.ts +22 -0
  121. package/dist/src/launcher/native-adapter-analysis.d.ts.map +1 -0
  122. package/dist/src/launcher/native-adapter-analysis.js +183 -0
  123. package/dist/src/launcher/native-adapter-analysis.js.map +1 -0
  124. package/dist/src/launcher/native-agent-models.d.ts +4 -2
  125. package/dist/src/launcher/native-agent-models.d.ts.map +1 -1
  126. package/dist/src/launcher/native-agent-models.js +34 -7
  127. package/dist/src/launcher/native-agent-models.js.map +1 -1
  128. package/dist/src/launcher/native-agent-task-source.d.ts +1 -27
  129. package/dist/src/launcher/native-agent-task-source.d.ts.map +1 -1
  130. package/dist/src/launcher/native-agent-task-source.js +2 -76
  131. package/dist/src/launcher/native-agent-task-source.js.map +1 -1
  132. package/dist/src/launcher/native-agent-task-transform.d.ts +1 -9
  133. package/dist/src/launcher/native-agent-task-transform.d.ts.map +1 -1
  134. package/dist/src/launcher/native-agent-task-transform.js +2 -198
  135. package/dist/src/launcher/native-agent-task-transform.js.map +1 -1
  136. package/dist/src/launcher/native-app-resources.d.ts +1 -1
  137. package/dist/src/launcher/native-app-resources.d.ts.map +1 -1
  138. package/dist/src/launcher/native-app-resources.js +5 -14
  139. package/dist/src/launcher/native-app-resources.js.map +1 -1
  140. package/dist/src/launcher/native-lazy-wire-request.d.ts +1 -9
  141. package/dist/src/launcher/native-lazy-wire-request.d.ts.map +1 -1
  142. package/dist/src/launcher/native-lazy-wire-request.js +2 -47
  143. package/dist/src/launcher/native-lazy-wire-request.js.map +1 -1
  144. package/dist/src/launcher/native-source-bindings.d.ts +1 -3
  145. package/dist/src/launcher/native-source-bindings.d.ts.map +1 -1
  146. package/dist/src/launcher/native-source-bindings.js +2 -69
  147. package/dist/src/launcher/native-source-bindings.js.map +1 -1
  148. package/dist/src/launcher/native-source-structure.d.ts +1 -18
  149. package/dist/src/launcher/native-source-structure.d.ts.map +1 -1
  150. package/dist/src/launcher/native-source-structure.js +2 -50
  151. package/dist/src/launcher/native-source-structure.js.map +1 -1
  152. package/dist/src/launcher/native-submission-composition.d.ts +5 -1
  153. package/dist/src/launcher/native-submission-composition.d.ts.map +1 -1
  154. package/dist/src/launcher/native-submission-composition.js +24 -194
  155. package/dist/src/launcher/native-submission-composition.js.map +1 -1
  156. package/dist/src/launcher/native-submission-control-server.d.ts +3 -1
  157. package/dist/src/launcher/native-submission-control-server.d.ts.map +1 -1
  158. package/dist/src/launcher/native-submission-control-server.js +53 -14
  159. package/dist/src/launcher/native-submission-control-server.js.map +1 -1
  160. package/dist/src/launcher/native-submission-controller.d.ts +2 -1
  161. package/dist/src/launcher/native-submission-controller.d.ts.map +1 -1
  162. package/dist/src/launcher/native-submission-controller.js +2 -0
  163. package/dist/src/launcher/native-submission-controller.js.map +1 -1
  164. package/dist/src/launcher/native-submission-legacy-resources.d.ts +1 -4
  165. package/dist/src/launcher/native-submission-legacy-resources.d.ts.map +1 -1
  166. package/dist/src/launcher/native-submission-legacy-resources.js +2 -17
  167. package/dist/src/launcher/native-submission-legacy-resources.js.map +1 -1
  168. package/dist/src/launcher/native-submission-structure.d.ts +1 -14
  169. package/dist/src/launcher/native-submission-structure.d.ts.map +1 -1
  170. package/dist/src/launcher/native-submission-structure.js +2 -418
  171. package/dist/src/launcher/native-submission-structure.js.map +1 -1
  172. package/dist/src/renderer/adapter/native-operation-request-transform.d.ts +1 -57
  173. package/dist/src/renderer/adapter/native-operation-request-transform.d.ts.map +1 -1
  174. package/dist/src/renderer/adapter/native-operation-request-transform.js +1 -185
  175. package/dist/src/renderer/adapter/native-operation-request-transform.js.map +1 -1
  176. package/dist/src/renderer/adapter/native-submit-orchestrator-transform.d.ts +1 -45
  177. package/dist/src/renderer/adapter/native-submit-orchestrator-transform.d.ts.map +1 -1
  178. package/dist/src/renderer/adapter/native-submit-orchestrator-transform.js +1 -171
  179. package/dist/src/renderer/adapter/native-submit-orchestrator-transform.js.map +1 -1
  180. package/package.json +5 -3
@@ -54,7 +54,7 @@ const SESSION_TOOLS = [
54
54
  {
55
55
  name: 'list_sessions',
56
56
  description:
57
- 'List conversations in an app CordisX connects (`app`: "codex" for Codex Desktop threads, "claude" for Claude Desktop Code sessions), most recent first, each with a link the user can click to open it. Read-only.',
57
+ 'List conversations in an app CordisX connects (`app`: "codex" for Codex Desktop threads, "claude" for Claude Desktop Code sessions), most recent first, each with a link the user can click to open it. Read-only. searchTerm matches messages as well as titles; matches include matchedIn and a short match excerpt. scan.capped reports bounded-search omissions.',
58
58
  inputSchema: {
59
59
  type: 'object',
60
60
  additionalProperties: false,
@@ -70,7 +70,7 @@ const SESSION_TOOLS = [
70
70
  {
71
71
  name: 'read_session',
72
72
  description:
73
- 'Read the recent transcript of one conversation by its sessionId (from list_sessions) in the named app, plus its link. Read-only. `limit` caps the number of returned message entries (the newest ones); the transcript is also capped at about 60k characters.',
73
+ 'Read one page of a conversation transcript by its sessionId (from list_sessions), newest messages kept, plus the link and `transcriptTotal`. Read-only, but one page may be large (~60k characters). Page older text with `cursor` from `nextCursor`; `truncated: true` means something was left out, and `clippedCharacters` says how much of the oldest returned message was cut.',
74
74
  inputSchema: {
75
75
  type: 'object',
76
76
  additionalProperties: false,
@@ -78,6 +78,11 @@ const SESSION_TOOLS = [
78
78
  app: APP,
79
79
  sessionId: { type: 'string', minLength: 1, maxLength: 512 },
80
80
  limit: { type: 'integer', minimum: 1, maximum: 200 },
81
+ cursor: {
82
+ type: 'string',
83
+ maxLength: 128,
84
+ description: 'nextCursor from an earlier read_session, unchanged, to read the next older page.',
85
+ },
81
86
  launch: LAUNCH,
82
87
  },
83
88
  required: ['app', 'sessionId'],
@@ -86,17 +91,32 @@ const SESSION_TOOLS = [
86
91
  {
87
92
  name: 'start_session',
88
93
  description:
89
- 'Start a new conversation in the named app for a task the user asked to hand over, and return its sessionId and link. The prompt is the full brief. `title` names the conversation where the app supports it. `providerId` and `model` pick one of the model services `list_model_providers` returns for that app; a value it does not list is refused. For Claude the turn runs in the background, and the result says whether it failed within a short wait; a turn still running is reported as started. Only when the user explicitly asks.',
94
+ 'Start a new conversation in the named app for a task the user asked to hand over. context summary appends a bounded summary of this conversation as background. Costs a model call and may take minutes. Returns `operationId`, `sessionId` and a link; keep the operationId. A repeat with the same operationId returns that same session instead of starting a second one. `title` names the conversation where the app supports it. `providerId` and `model` pick one of the model services `list_model_providers` returns; a value it does not list is refused. `dryRun: true` validates provider, model, cwd and key and starts nothing. Only when the user explicitly asks.',
90
95
  inputSchema: {
91
96
  type: 'object',
92
97
  additionalProperties: false,
93
98
  properties: {
94
99
  app: APP,
100
+ operationId: {
101
+ type: 'string',
102
+ minLength: 1,
103
+ maxLength: 128,
104
+ description: 'Unique per intended start. Reuse it only to repeat this exact call.',
105
+ },
106
+ dryRun: {
107
+ type: 'boolean',
108
+ description: 'Validate the provider, model, cwd and key without starting anything. Never required.',
109
+ },
95
110
  prompt: { type: 'string', minLength: 1, maxLength: 100000 },
96
111
  title: { type: 'string', minLength: 1, maxLength: 120 },
97
112
  cwd: { type: 'string', minLength: 1, maxLength: 4096 },
98
113
  providerId: { type: 'string', minLength: 1, maxLength: 128 },
99
114
  model: { type: 'string', minLength: 1, maxLength: 512 },
115
+ context: {
116
+ enum: ['none', 'summary'],
117
+ description:
118
+ 'summary appends a bounded summary of the calling conversation, marked as background; none sends only the prompt.',
119
+ },
100
120
  launch: LAUNCH,
101
121
  },
102
122
  required: ['app', 'prompt'],
@@ -105,12 +125,18 @@ const SESSION_TOOLS = [
105
125
  {
106
126
  name: 'send_message',
107
127
  description:
108
- 'Send a message to an existing conversation by its sessionId in the named app; it runs there as the next turn. Only when the user explicitly asks.',
128
+ 'Send a message to an existing conversation by its sessionId in the named app; it runs there as the next turn. Costs a model call and may take minutes. Returns `operationId`; a repeat with the same operationId does not send twice. Only when the user explicitly asks.',
109
129
  inputSchema: {
110
130
  type: 'object',
111
131
  additionalProperties: false,
112
132
  properties: {
113
133
  app: APP,
134
+ operationId: {
135
+ type: 'string',
136
+ minLength: 1,
137
+ maxLength: 128,
138
+ description: 'Unique per intended send. Reuse it only to repeat this exact call.',
139
+ },
114
140
  sessionId: { type: 'string', minLength: 1, maxLength: 512 },
115
141
  prompt: { type: 'string', minLength: 1, maxLength: 100000 },
116
142
  launch: LAUNCH,
@@ -118,8 +144,46 @@ const SESSION_TOOLS = [
118
144
  required: ['app', 'sessionId', 'prompt'],
119
145
  },
120
146
  },
147
+ {
148
+ name: 'check_operation',
149
+ description:
150
+ 'Report what a start_session or send_message operation became: `running`, `done` or `failed`, with the sessionId and link, or the failure reason. Read-only, side-effect free and cheap: call it instead of guessing how long a background turn takes, and poll it a few seconds apart rather than in a tight loop.',
151
+ inputSchema: {
152
+ type: 'object',
153
+ additionalProperties: false,
154
+ properties: { app: APP, operationId: { type: 'string', minLength: 1, maxLength: 128 } },
155
+ required: ['app', 'operationId'],
156
+ },
157
+ },
121
158
  ] as const
122
159
 
160
+ /**
161
+ * The status tool has its own result shape, not a session operation: it reports
162
+ * the bridge, both apps, the declared model services, and plugin health.
163
+ */
164
+ const STATUS_TOOL = {
165
+ name: 'integration_status',
166
+ description:
167
+ "Report whether the CordisX integrations work right now, and what to fix when they do not, before you guess or retry: this app's bridge socket and token, the CordisX home and running profile; the other app (Codex Desktop or Claude Desktop) whether its process is still alive, its profile, the model service it was launched with, and whether its side of the bridge answers; the model services declared in the CordisX config with the models each app can use and whether their key variable is set (never its value); and cheap bridge-plugin health. Read-only and fast: no app is started, no turn runs, nothing is written. `problems` already carries a reason and a remedy for everything that is not working.",
168
+ inputSchema: {
169
+ type: 'object',
170
+ additionalProperties: false,
171
+ properties: {
172
+ app: {
173
+ enum: ['claude', 'codex'],
174
+ description: 'Whose side to report as "self". Defaults to this app (Claude).',
175
+ },
176
+ },
177
+ },
178
+ } as const
179
+
180
+ /** One judged fact, in the shape both apps report. */
181
+ interface Check {
182
+ status: string
183
+ reason?: string
184
+ remedy?: string
185
+ }
186
+
123
187
  let polling = false
124
188
 
125
189
  async function readBinding($: EngineInterface): Promise<Binding | undefined> {
@@ -140,18 +204,43 @@ async function post($: EngineInterface, route: string, body: unknown): Promise<B
140
204
  return { ok: false, unreachable: true, error: 'CordisX is not running Codex (no agent bridge found)' }
141
205
  }
142
206
  try {
143
- const response = await $.http.fetch(`http://cordisx${route}`, {
207
+ let timer: ReturnType<typeof setTimeout> | undefined
208
+ const fetch = $.http.fetch(`http://cordisx${route}`, {
144
209
  method: 'POST',
145
210
  socketPath: binding.socketPath,
146
211
  headers: { 'content-type': 'application/json', 'x-cordisx-bridge-token': binding.token },
147
212
  body: JSON.stringify(body),
148
213
  })
214
+ let response: Awaited<typeof fetch>
215
+ try {
216
+ response = route === '/status'
217
+ ? await Promise.race([
218
+ fetch,
219
+ new Promise<never>((_, reject) => {
220
+ timer = setTimeout(() => reject(new Error('Status probe timed out')), 3500)
221
+ }),
222
+ ])
223
+ : await fetch
224
+ } finally {
225
+ if (timer !== undefined) clearTimeout(timer)
226
+ }
149
227
  return JSON.parse(response.text) as BridgeReply
150
228
  } catch {
151
229
  return { ok: false, unreachable: true, error: 'The CordisX agent bridge is not reachable' }
152
230
  }
153
231
  }
154
232
 
233
+ /** One sentence an agent can follow, so a failure from the fallback path reads like one from the bridge. */
234
+ function failure(reason: string, message: string, retryable = false): Record<string, unknown> {
235
+ return {
236
+ status: 'failed',
237
+ reason,
238
+ retryable,
239
+ howToContinue: 'Read message; if the bridge is not what failed, call this tool again.',
240
+ message,
241
+ }
242
+ }
243
+
155
244
  function textOf(value: unknown): string {
156
245
  const text = (value as { text?: unknown } | undefined)?.text
157
246
  return typeof text === 'string' ? text : JSON.stringify(value)
@@ -229,7 +318,9 @@ async function answer($: EngineInterface, operation: string, args: Record<string
229
318
  ...(typeof args.cwd === 'string' ? { cwd: args.cwd } : {}),
230
319
  })
231
320
  const sessionId = SESSION_ID.exec(textOf(started))?.[0]
232
- if (sessionId === undefined) return { status: 'unknown', result: textOf(started) }
321
+ if (sessionId === undefined) {
322
+ return failure('session-not-started', `Claude did not report a session: ${textOf(started)}`)
323
+ }
233
324
  // A session this one starts nests under it; the user should see it as their own.
234
325
  try {
235
326
  await $.tool.call({ tool: 'mcp__ccd_session_mgmt__detach_session', session_id: sessionId })
@@ -238,6 +329,14 @@ async function answer($: EngineInterface, operation: string, args: Record<string
238
329
  const link = CLAUDE_LINK.exec(textOf(details))?.[0]
239
330
  return { status: 'started', sessionId, ...(link === undefined ? {} : { link }) }
240
331
  }
332
+ if (operation === 'check_operation') {
333
+ // The fallback path starts Claude's own sessions, which report synchronously:
334
+ // there is nothing to poll, and pretending otherwise would mislead the agent.
335
+ return failure(
336
+ 'operation-not-found',
337
+ 'This Claude session answers through the CordisX bridge, which is not running, so it has no background operations to check.',
338
+ )
339
+ }
241
340
  if (operation === 'send_message') {
242
341
  const prompt = String(args.prompt ?? args.message ?? '')
243
342
  // Claude refuses a session's message to itself; a prompt this session submits is its next turn.
@@ -289,32 +388,297 @@ async function hostsClaudeSessions($: EngineInterface): Promise<boolean> {
289
388
  )
290
389
  }
291
390
 
292
- /** Runs one session tool: Codex through the agent bridge, Claude with this app's own session tools. */
391
+ const SUMMARY_CHARS = 4000
392
+ const FILE_MENTIONED = /[\w.@+-]+(?:\/[\w.@+-]+)*\.[A-Za-z][A-Za-z0-9]{1,7}\b/gu
393
+
394
+ const flatten = (value: string): string => value.replace(/\s+/gu, ' ').trim()
395
+
396
+ function clip(value: string, max: number): string {
397
+ const text = flatten(value)
398
+ return text.length > max ? `${text.slice(0, max - 1)}…` : text
399
+ }
400
+
401
+ function textOfMessage(message: unknown): string | undefined {
402
+ if (typeof message === 'string') return message
403
+ const value = message as { content?: unknown } | undefined
404
+ if (typeof value?.content === 'string') return value.content
405
+ const parts = Array.isArray(value?.content) ? value.content : Array.isArray(message) ? message : []
406
+ const said = parts.flatMap(part => {
407
+ const text = (part as { text?: unknown } | undefined)?.text
408
+ return typeof text === 'string' ? [text] : []
409
+ })
410
+ return said.length === 0 ? undefined : said.join('\n')
411
+ }
412
+
413
+ /**
414
+ * What this conversation has been about, for a Codex task handed over from it:
415
+ * the first and latest requests, the latest answer, and the files named. It is
416
+ * the same shape the CordisX host builds, and it is capped before it is sent.
417
+ */
418
+ async function conversationSummary($: EngineInterface, sessionId: string): Promise<string | undefined> {
419
+ let messages: unknown[] = []
420
+ try {
421
+ messages = (await $.session.messages()) as unknown[]
422
+ } catch {
423
+ return undefined
424
+ }
425
+ const entries: { role: string; text: string }[] = []
426
+ for (const message of messages) {
427
+ const value = message as { role?: unknown; type?: unknown } | undefined
428
+ const role = typeof value?.role === 'string' ? value.role : value?.type
429
+ const said = textOfMessage(message)
430
+ if (typeof role !== 'string' || said === undefined || said.trim().length === 0) continue
431
+ entries.push({ role, text: said })
432
+ }
433
+ const users = entries.filter(entry => entry.role === 'user')
434
+ if (users.length === 0) return undefined
435
+ const answers = entries.filter(entry => entry.role === 'assistant')
436
+ const lines = [`Conversation in Claude (${sessionId}).`, `Asked: ${clip(users[0]!.text, 700)}`]
437
+ for (const entry of users.slice(1).slice(-3)) lines.push(`Then asked: ${clip(entry.text, 300)}`)
438
+ const latest = answers[answers.length - 1]
439
+ if (latest !== undefined) lines.push(`Latest answer: ${clip(latest.text, 700)}`)
440
+ const files: string[] = []
441
+ for (const entry of entries) {
442
+ if (files.length >= 12) break
443
+ for (const match of entry.text.matchAll(FILE_MENTIONED)) {
444
+ const found = match[0].replace(/^[./]+/u, '')
445
+ if (found.length > 120 || files.includes(found)) continue
446
+ files.push(found)
447
+ if (files.length >= 12) break
448
+ }
449
+ }
450
+ if (files.length > 0) lines.push(`Files mentioned: ${files.join(', ')}`)
451
+ return clip(lines.join('\n'), SUMMARY_CHARS)
452
+ }
453
+
454
+ /** Tool results are read by an agent, not a person: compact JSON, never pretty-printed. */
455
+ const compact = (value: unknown): string => JSON.stringify(value)
456
+
457
+ /**
458
+ * Runs one session tool: Codex through the agent bridge, Claude with this
459
+ * app's own session tools. Whatever happens, the result is one JSON object
460
+ * with the bridge's fields — `status`, and for a failure `reason`,
461
+ * `retryable` and `howToContinue` — so an agent branches on them either way.
462
+ */
293
463
  async function runSessionTool($: EngineInterface, operation: string, input: Record<string, unknown>): Promise<string> {
294
464
  const { app, ...args } = input
465
+ if (operation === 'start_session' && args.context === 'summary') {
466
+ const summary = await conversationSummary($, await $.session.id())
467
+ if (summary !== undefined) args.callerSummary = summary
468
+ }
295
469
  if (app === 'claude') {
296
470
  // The bridge drives Claude from outside the app, so a new session needs no
297
471
  // "start the session?" prompt; without a bridge, Claude's own tools answer.
298
472
  const { launch: _launch, ...request } = args
299
473
  const bridged = await post($, '/sessions', { app, operation, args: request })
300
- if (bridged.ok) return JSON.stringify(bridged.value, null, 2)
474
+ // A bridge answer is final, failure included: it knows the app state better
475
+ // than this session's own tools do.
476
+ if (bridged.ok) return compact(bridged.value)
477
+ if (
478
+ args.dryRun === true || args.context === 'summary' || args.operationId !== undefined || args.cursor !== undefined
479
+ ) {
480
+ return compact(
481
+ failure(
482
+ 'agent-bridge-unavailable',
483
+ 'Start Codex with CordisX to use recoverable operations, dryRun, context handoff, or transcript paging.',
484
+ ),
485
+ )
486
+ }
301
487
  try {
302
- return JSON.stringify(await answer($, operation, args), null, 2)
488
+ return compact(await answer($, operation, args))
303
489
  } catch (error) {
304
- return `Claude could not do it: ${error instanceof Error ? error.message : String(error)}`
490
+ return compact(
491
+ failure('claude-unavailable', error instanceof Error ? error.message : String(error), true),
492
+ )
305
493
  }
306
494
  }
307
- if (app !== 'codex') return `app must be one of ${APPS.join(', ')}`
495
+ if (app !== 'codex') {
496
+ return compact({
497
+ status: 'rejected',
498
+ reason: 'unknown-app',
499
+ retryable: false,
500
+ howToContinue: `Pass app ${APPS.map(name => `"${name}"`).join(' or ')}.`,
501
+ message: `app must be one of ${APPS.join(', ')}`,
502
+ })
503
+ }
308
504
  const { launch, ...request } = args
309
505
  let answered = await post($, '/sessions', { app, operation, args: request })
310
- if (!answered.ok && answered.unreachable === true) {
506
+ if (!answered.ok && answered.unreachable === true && args.dryRun !== true && operation !== 'check_operation') {
507
+ // An operationId only means something to one bridge process; a restarted
508
+ // bridge reports it as not found, which is what the agent needs to know.
311
509
  const started = await startCodex($, launch)
312
- if (started !== true) return JSON.stringify(started, null, 2)
510
+ if (started !== true) return compact(started)
313
511
  answered = await post($, '/sessions', { app, operation, args: request })
314
512
  }
315
- return answered.ok
316
- ? JSON.stringify(answered.value, null, 2)
317
- : `Codex is unavailable: ${answered.error ?? 'unknown error'}`
513
+ if (answered.ok) return compact(answered.value)
514
+ return compact({
515
+ status: 'failed',
516
+ reason: 'agent-bridge-unavailable',
517
+ retryable: true,
518
+ howToContinue: 'CordisX is not running the Codex bridge; start it with `cordisx start codex`, then call again.',
519
+ message: answered.error ?? 'Codex is unavailable',
520
+ })
521
+ }
522
+
523
+ /**
524
+ * The report when no CordisX Codex launch answers: the same shape, assembled
525
+ * from the profile files this session can read. It can speak for Claude (this
526
+ * plugin runs inside the app) but not for Codex, whose process it cannot probe.
527
+ */
528
+ async function localStatus($: EngineInterface, args: Record<string, unknown>): Promise<unknown> {
529
+ const home = await cordisxHome($)
530
+ const requested: 'claude' | 'codex' = args.app === 'codex' ? 'codex' : 'claude'
531
+ const read = async (file: string): Promise<Record<string, unknown> | undefined> => {
532
+ try {
533
+ return JSON.parse(await $.fs.read(file)) as Record<string, unknown>
534
+ } catch {
535
+ return undefined
536
+ }
537
+ }
538
+ const string = (value: unknown): string | undefined =>
539
+ typeof value === 'string' && value.length > 0 ? value : undefined
540
+ const record = (value: unknown): Record<string, unknown> =>
541
+ value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : {}
542
+
543
+ const config = await read(`${home}/config.json`)
544
+ const binding = await read(`${home}/run/agent-bridge.json`)
545
+ const claudeProfile = await read(`${home}/run/claude-desktop.json`)
546
+ const codexLaunch = await read(`${home}/run/codex-launch.json`)
547
+ const token = string(binding?.token)
548
+ const socketPath = string(binding?.socketPath)
549
+
550
+ const configuredVariables = Array.isArray(config?.environmentVariables) ? config.environmentVariables : []
551
+ const keySet = async (name: string): Promise<boolean> =>
552
+ (await $.env.get(name) ?? '').length > 0
553
+ || configuredVariables.some(entry =>
554
+ string(record(entry).name) === name && record(entry).enabled === true
555
+ && (string(record(entry).value) ?? '').length > 0
556
+ )
557
+
558
+ const use = (provider: Record<string, unknown>, app: 'claude' | 'codex') => {
559
+ const models = record(provider.models)[app]
560
+ const list = Array.isArray(models) ? models.filter((model): model is string => typeof model === 'string') : []
561
+ if (provider.enabled === false) return { usable: false, models: list, reason: 'disabled' }
562
+ const appliesTo = Array.isArray(provider.appliesTo) ? provider.appliesTo : undefined
563
+ if (appliesTo !== undefined && !appliesTo.includes(app)) {
564
+ return { usable: false, models: list, reason: 'app-not-declared' }
565
+ }
566
+ const protocols = Array.isArray(provider.protocols) ? provider.protocols : []
567
+ if (!protocols.includes(app === 'claude' ? 'anthropic-messages' : 'openai-responses')) {
568
+ return { usable: false, models: list, reason: 'protocol-unsupported' }
569
+ }
570
+ return list.length === 0
571
+ ? { usable: false, models: list, reason: 'no-models' }
572
+ : { usable: true, models: list }
573
+ }
574
+ const declared = Array.isArray(config?.providers) ? (config!.providers as unknown[]).map(record) : []
575
+ const services = await Promise.all(
576
+ declared
577
+ .filter(provider => provider.kind === 'model-service')
578
+ .map(async provider => ({
579
+ id: string(provider.id),
580
+ displayName: string(provider.displayName),
581
+ keyVariable: string(provider.apiKeyEnv),
582
+ keySet: await keySet(string(provider.apiKeyEnv) ?? ''),
583
+ apps: { claude: use(provider, 'claude'), codex: use(provider, 'codex') },
584
+ })),
585
+ )
586
+ const declares = (id: string | undefined): boolean => id !== undefined && services.some(service => service.id === id)
587
+
588
+ const bridge = (answers: boolean, status?: Check) => ({
589
+ ...(status ?? { status: token !== undefined && answers ? 'ok' : 'unreachable' }),
590
+ token: token === undefined ? 'missing' : 'present',
591
+ ...(socketPath === undefined ? {} : { socketPath }),
592
+ })
593
+
594
+ const claudeProfileId = string(claudeProfile?.profileId)
595
+ const claudeProviderId = string(record(claudeProfile?.provider).id)
596
+ const sessionToolsConnected = await hostsClaudeSessions($)
597
+ // The plugin proves this Claude process is alive; it does not prove the shared bridge answers.
598
+ const claude: Record<string, unknown> = {
599
+ app: 'claude',
600
+ ...(claudeProfileId === undefined ? {} : { profileId: claudeProfileId }),
601
+ ...(claudeProviderId === undefined
602
+ ? {}
603
+ : { modelService: { id: claudeProviderId, declared: declares(claudeProviderId) } }),
604
+ status: 'ok',
605
+ bridge: bridge(false, { status: 'unreachable', reason: 'bridge-not-answering' }),
606
+ }
607
+ const codexProfileId = string(codexLaunch?.profileId)
608
+ const codexServiceId = string(codexLaunch?.modelServiceId)
609
+ const codexRemedy = token === undefined
610
+ ? 'Start Codex with `cordisx start codex <profile>`; its launch creates the bridge.'
611
+ : `Ask the person before starting Codex: \`cordisx start codex ${codexProfileId ?? '<profile>'}\`.`
612
+ const codex: Record<string, unknown> = {
613
+ app: 'codex',
614
+ ...(codexProfileId === undefined ? {} : { profileId: codexProfileId }),
615
+ ...(codexServiceId === undefined
616
+ ? {}
617
+ : { modelService: { id: codexServiceId, declared: declares(codexServiceId) } }),
618
+ status: 'unknown',
619
+ reason: 'codex-process-not-probed',
620
+ remedy: codexRemedy,
621
+ bridge: bridge(false, {
622
+ status: 'unreachable',
623
+ reason: token === undefined ? 'bridge-binding-missing' : 'bridge-not-answering',
624
+ remedy: codexRemedy,
625
+ }),
626
+ }
627
+
628
+ const problems = [
629
+ ...services.flatMap(service => {
630
+ const usable = service.apps.claude.usable || service.apps.codex.usable
631
+ if (!usable) {
632
+ return [{
633
+ area: `model-service:${service.id}`,
634
+ status: 'not-configured',
635
+ reason: 'no-app-can-use-it',
636
+ remedy:
637
+ `Neither app can use ${service.id}: give it an "anthropic-messages" protocol with models.claude (Claude) or "openai-responses" with models.codex (Codex).`,
638
+ }]
639
+ }
640
+ return service.keySet ? [] : [{
641
+ area: `model-service:${service.id}`,
642
+ status: 'not-configured',
643
+ reason: 'key-not-set',
644
+ remedy: `Set ${service.keyVariable} in the CordisX environment variables, or export it before launching.`,
645
+ }]
646
+ }),
647
+ { area: requested === 'codex' ? 'self' : 'other', status: codex.status, reason: codex.reason, remedy: codexRemedy },
648
+ { area: requested === 'codex' ? 'self.bridge' : 'other.bridge', ...(codex.bridge as Check) },
649
+ { area: requested === 'claude' ? 'self.bridge' : 'other.bridge', ...(claude.bridge as Check) },
650
+ ...(config === undefined
651
+ ? [{
652
+ area: 'config',
653
+ status: 'missing',
654
+ reason: 'home-config-unreadable',
655
+ remedy: 'Check the CordisX home config.',
656
+ }]
657
+ : []),
658
+ ...(!sessionToolsConnected
659
+ ? [{ area: 'plugins.claudeSessionTools', status: 'not-connected', reason: 'claude-session-tools-missing' }]
660
+ : []),
661
+ ]
662
+
663
+ return {
664
+ version: 1,
665
+ status: 'unavailable',
666
+ app: requested,
667
+ cordisxHome: home,
668
+ self: requested === 'claude' ? claude : codex,
669
+ other: requested === 'claude' ? codex : claude,
670
+ modelServices: services,
671
+ plugins: {
672
+ claudePluginDirectory: { status: 'ok' },
673
+ claudeSessionTools: sessionToolsConnected
674
+ ? { status: 'ok' }
675
+ : { status: 'not-connected', reason: 'claude-session-tools-missing' },
676
+ codexAppServer: { status: 'unknown', reason: 'codex-app-server-not-probed' },
677
+ },
678
+ problems,
679
+ note:
680
+ 'Assembled inside Claude without a CordisX Codex launch answering; start Codex for the bridge, app-server, and Codex process checks.',
681
+ }
318
682
  }
319
683
 
320
684
  async function cordisxHome($: EngineInterface): Promise<string> {
@@ -342,6 +706,7 @@ async function startCodex($: EngineInterface, launch: unknown): Promise<true | R
342
706
  return {
343
707
  status: 'needs-confirmation',
344
708
  reason: 'codex-not-running',
709
+ retryable: false,
345
710
  question: 'Codex Desktop is not running. Start it?',
346
711
  howToContinue:
347
712
  'Ask the user, in their language, whether to start Codex Desktop. If they agree, call this tool again with the same arguments plus launch "once" (start it this time) or "always" (start it automatically from now on, without asking). Do not retry without their answer.',
@@ -360,18 +725,31 @@ async function startCodex($: EngineInterface, launch: unknown): Promise<true | R
360
725
  : ['cordisx', 'start', 'codex', target.profileId]
361
726
  const started = await $.process.run(argv, { env: { CORDISX_HOME: target.homeDir }, timeoutMs: CODEX_START_MS })
362
727
  if (started.exitCode !== 0) {
363
- return { status: 'failed', reason: 'codex-start-failed', detail: started.stderr.slice(-2000) }
728
+ return {
729
+ status: 'failed',
730
+ reason: 'codex-start-failed',
731
+ retryable: true,
732
+ howToContinue: 'Codex Desktop did not start; start it with `cordisx start codex`, then call again.',
733
+ message: 'Codex Desktop did not start',
734
+ detail: started.stderr.slice(-2000),
735
+ }
364
736
  }
365
737
  for (const deadline = Date.now() + CODEX_START_MS; Date.now() < deadline;) {
366
738
  if ((await post($, '/sessions', { app: 'codex', operation: 'list_sessions', args: { limit: 1 } })).ok) return true
367
739
  await new Promise(resolve => setTimeout(resolve, 1000))
368
740
  }
369
- return { status: 'failed', reason: 'codex-bridge-not-ready' }
741
+ return {
742
+ status: 'failed',
743
+ reason: 'agent-bridge-unavailable',
744
+ retryable: true,
745
+ howToContinue: 'Codex Desktop started but its bridge did not answer in time; call this tool again.',
746
+ message: 'Codex Desktop started but its agent bridge did not come up',
747
+ }
370
748
  }
371
749
 
372
750
  export const register: Register = on => {
373
751
  on('session.start', async ($, e, next) => {
374
- for (const tool of [...SESSION_TOOLS, MODEL_PROVIDER_TOOL]) {
752
+ for (const tool of [...SESSION_TOOLS, MODEL_PROVIDER_TOOL, STATUS_TOOL]) {
375
753
  await $.tool.register({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema })
376
754
  }
377
755
  $.clock.every(POLL_MS, () => void poll($))
@@ -380,10 +758,12 @@ export const register: Register = on => {
380
758
 
381
759
  on('tool.call', { tool: `mcp__cordisx__${MODEL_PROVIDER_TOOL.name}` }, async $ => {
382
760
  try {
383
- return { result: JSON.stringify(await modelProviders($), null, 2) }
761
+ return { result: compact(await modelProviders($)) }
384
762
  } catch (error) {
385
763
  return {
386
- result: `The model services could not be read: ${error instanceof Error ? error.message : String(error)}`,
764
+ result: compact(
765
+ failure('agent-bridge-unavailable', error instanceof Error ? error.message : String(error), true),
766
+ ),
387
767
  }
388
768
  }
389
769
  })
@@ -394,4 +774,11 @@ export const register: Register = on => {
394
774
  return { result: await runSessionTool($, tool.name, args) }
395
775
  })
396
776
  }
777
+
778
+ on('tool.call', { tool: `mcp__cordisx__${STATUS_TOOL.name}` }, async ($, e) => {
779
+ const { tool: _tool, tool_use_id: _id, ...args } = e as Record<string, unknown>
780
+ // The bridge holds both apps' state; without it, report what this side can see.
781
+ const answered = await post($, '/status', { caller: 'claude', ...args })
782
+ return { result: JSON.stringify(answered.ok ? answered.value : await localStatus($, args)) }
783
+ })
397
784
  }