cordisx 0.1.0-beta.37 → 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 (187) hide show
  1. package/dist/assets/claude-bridge/hooks/register.ts +457 -19
  2. package/dist/assets/launcher/native-agent-models-mcp.mjs +69 -8
  3. package/dist/assets/launcher/native-app-server-protocol.mjs +53 -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 -20
  74. package/dist/src/launcher/agent-bridge.d.ts.map +1 -1
  75. package/dist/src/launcher/agent-bridge.js +463 -119
  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 +31 -27
  85. package/dist/src/launcher/claude-host-sessions.d.ts.map +1 -1
  86. package/dist/src/launcher/claude-host-sessions.js +526 -165
  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 -37
  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 -13
  139. package/dist/src/launcher/native-app-resources.js.map +1 -1
  140. package/dist/src/launcher/native-lazy-wire-request.d.ts +2 -0
  141. package/dist/src/launcher/native-lazy-wire-request.d.ts.map +1 -0
  142. package/dist/src/launcher/native-lazy-wire-request.js +3 -0
  143. package/dist/src/launcher/native-lazy-wire-request.js.map +1 -0
  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 -192
  155. package/dist/src/launcher/native-submission-composition.js.map +1 -1
  156. package/dist/src/launcher/native-submission-control-server.d.ts +4 -2
  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 -385
  171. package/dist/src/launcher/native-submission-structure.js.map +1 -1
  172. package/dist/src/native-account-capability.d.ts +1 -0
  173. package/dist/src/native-account-capability.d.ts.map +1 -1
  174. package/dist/src/native-account-capability.js +25 -7
  175. package/dist/src/native-account-capability.js.map +1 -1
  176. package/dist/src/renderer/adapter/native-operation-request-transform.d.ts +1 -57
  177. package/dist/src/renderer/adapter/native-operation-request-transform.d.ts.map +1 -1
  178. package/dist/src/renderer/adapter/native-operation-request-transform.js +1 -185
  179. package/dist/src/renderer/adapter/native-operation-request-transform.js.map +1 -1
  180. package/dist/src/renderer/adapter/native-submit-orchestrator-transform.d.ts +1 -45
  181. package/dist/src/renderer/adapter/native-submit-orchestrator-transform.d.ts.map +1 -1
  182. package/dist/src/renderer/adapter/native-submit-orchestrator-transform.js +1 -171
  183. package/dist/src/renderer/adapter/native-submit-orchestrator-transform.js.map +1 -1
  184. package/dist/src/renderer/adapter/startup-readiness.d.ts.map +1 -1
  185. package/dist/src/renderer/adapter/startup-readiness.js +5 -1
  186. package/dist/src/renderer/adapter/startup-readiness.js.map +1 -1
  187. package/package.json +5 -3
@@ -41,12 +41,20 @@ const LAUNCH = {
41
41
  /** How long a started Codex gets to bring its agent bridge up. */
42
42
  const CODEX_START_MS = 90_000
43
43
 
44
+ /** One set of tool names for every app CordisX connects; `app` names the target. */
45
+ const MODEL_PROVIDER_TOOL = {
46
+ name: 'list_model_providers',
47
+ description:
48
+ 'List the CordisX model services declared for Claude in this CordisX home (`<CORDISX_HOME>/config.json`) merged with the services this Claude profile already holds, with their exact model ids. Read-only: never returns endpoints or credentials, and changes no default. The same shape the Codex app returns. `start_session` with `app: "claude"` takes a `providerId` and `model` from here; one it does not list is refused.',
49
+ inputSchema: { type: 'object', additionalProperties: false, properties: {} },
50
+ } as const
51
+
44
52
  /** One set of tool names for every app CordisX connects; `app` names the target. */
45
53
  const SESSION_TOOLS = [
46
54
  {
47
55
  name: 'list_sessions',
48
56
  description:
49
- '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.',
50
58
  inputSchema: {
51
59
  type: 'object',
52
60
  additionalProperties: false,
@@ -62,7 +70,7 @@ const SESSION_TOOLS = [
62
70
  {
63
71
  name: 'read_session',
64
72
  description:
65
- 'Read the recent transcript of one conversation by its sessionId (from list_sessions) in the named app, plus its link. Read-only.',
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.',
66
74
  inputSchema: {
67
75
  type: 'object',
68
76
  additionalProperties: false,
@@ -70,6 +78,11 @@ const SESSION_TOOLS = [
70
78
  app: APP,
71
79
  sessionId: { type: 'string', minLength: 1, maxLength: 512 },
72
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
+ },
73
86
  launch: LAUNCH,
74
87
  },
75
88
  required: ['app', 'sessionId'],
@@ -78,17 +91,32 @@ const SESSION_TOOLS = [
78
91
  {
79
92
  name: 'start_session',
80
93
  description:
81
- '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. For Codex, providerId and model pick one of the model services CordisX configured. 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.',
82
95
  inputSchema: {
83
96
  type: 'object',
84
97
  additionalProperties: false,
85
98
  properties: {
86
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
+ },
87
110
  prompt: { type: 'string', minLength: 1, maxLength: 100000 },
88
111
  title: { type: 'string', minLength: 1, maxLength: 120 },
89
112
  cwd: { type: 'string', minLength: 1, maxLength: 4096 },
90
113
  providerId: { type: 'string', minLength: 1, maxLength: 128 },
91
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
+ },
92
120
  launch: LAUNCH,
93
121
  },
94
122
  required: ['app', 'prompt'],
@@ -97,12 +125,18 @@ const SESSION_TOOLS = [
97
125
  {
98
126
  name: 'send_message',
99
127
  description:
100
- '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.',
101
129
  inputSchema: {
102
130
  type: 'object',
103
131
  additionalProperties: false,
104
132
  properties: {
105
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
+ },
106
140
  sessionId: { type: 'string', minLength: 1, maxLength: 512 },
107
141
  prompt: { type: 'string', minLength: 1, maxLength: 100000 },
108
142
  launch: LAUNCH,
@@ -110,8 +144,46 @@ const SESSION_TOOLS = [
110
144
  required: ['app', 'sessionId', 'prompt'],
111
145
  },
112
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
+ },
113
158
  ] as const
114
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
+
115
187
  let polling = false
116
188
 
117
189
  async function readBinding($: EngineInterface): Promise<Binding | undefined> {
@@ -132,18 +204,43 @@ async function post($: EngineInterface, route: string, body: unknown): Promise<B
132
204
  return { ok: false, unreachable: true, error: 'CordisX is not running Codex (no agent bridge found)' }
133
205
  }
134
206
  try {
135
- const response = await $.http.fetch(`http://cordisx${route}`, {
207
+ let timer: ReturnType<typeof setTimeout> | undefined
208
+ const fetch = $.http.fetch(`http://cordisx${route}`, {
136
209
  method: 'POST',
137
210
  socketPath: binding.socketPath,
138
211
  headers: { 'content-type': 'application/json', 'x-cordisx-bridge-token': binding.token },
139
212
  body: JSON.stringify(body),
140
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
+ }
141
227
  return JSON.parse(response.text) as BridgeReply
142
228
  } catch {
143
229
  return { ok: false, unreachable: true, error: 'The CordisX agent bridge is not reachable' }
144
230
  }
145
231
  }
146
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
+
147
244
  function textOf(value: unknown): string {
148
245
  const text = (value as { text?: unknown } | undefined)?.text
149
246
  return typeof text === 'string' ? text : JSON.stringify(value)
@@ -153,6 +250,39 @@ function limitOf(args: Record<string, unknown>, fallback: number): number {
153
250
  return typeof args.limit === 'number' ? args.limit : fallback
154
251
  }
155
252
 
253
+ /**
254
+ * The model services a Claude start may name, in the shape the Codex tool
255
+ * returns: provider id, title, exact model ids and labels. The CordisX side
256
+ * merges the home config's declarations with this profile's own library, so
257
+ * the two apps answer the same list; without a bridge, the declarations alone
258
+ * are read from `<CORDISX_HOME>/config.json`.
259
+ */
260
+ async function modelProviders($: EngineInterface): Promise<unknown> {
261
+ const bridged = await post($, '/sessions', { app: 'claude', operation: 'list_model_providers', args: {} })
262
+ if (bridged.ok) return bridged.value
263
+ const home = await cordisxHome($)
264
+ let providers: Record<string, unknown>[] = []
265
+ try {
266
+ const config = JSON.parse(await $.fs.read(`${home}/config.json`)) as { providers?: unknown }
267
+ const declared = Array.isArray(config.providers) ? config.providers : []
268
+ providers = declared.flatMap(entry => {
269
+ const provider = entry as Record<string, unknown>
270
+ if (provider?.kind !== 'model-service' || provider.enabled === false) return []
271
+ const protocols = Array.isArray(provider.protocols) ? provider.protocols : []
272
+ const appliesTo = Array.isArray(provider.appliesTo) ? provider.appliesTo : undefined
273
+ if (!protocols.includes('anthropic-messages')) return []
274
+ if (appliesTo !== undefined && !appliesTo.includes('claude')) return []
275
+ const models = (provider.models as Record<string, unknown> | undefined)?.claude
276
+ return [{
277
+ providerId: String(provider.id ?? ''),
278
+ title: String(provider.displayName ?? provider.id ?? ''),
279
+ models: (Array.isArray(models) ? models : []).map(id => ({ id: String(id), label: String(id) })),
280
+ }]
281
+ })
282
+ } catch { /* no config yet: nothing is declared */ }
283
+ return { providers }
284
+ }
285
+
156
286
  /** Runs one Codex -> Claude request with Claude Desktop's own session tools. */
157
287
  async function answer($: EngineInterface, operation: string, args: Record<string, unknown>): Promise<unknown> {
158
288
  if (operation === 'list_sessions') {
@@ -188,7 +318,9 @@ async function answer($: EngineInterface, operation: string, args: Record<string
188
318
  ...(typeof args.cwd === 'string' ? { cwd: args.cwd } : {}),
189
319
  })
190
320
  const sessionId = SESSION_ID.exec(textOf(started))?.[0]
191
- 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
+ }
192
324
  // A session this one starts nests under it; the user should see it as their own.
193
325
  try {
194
326
  await $.tool.call({ tool: 'mcp__ccd_session_mgmt__detach_session', session_id: sessionId })
@@ -197,6 +329,14 @@ async function answer($: EngineInterface, operation: string, args: Record<string
197
329
  const link = CLAUDE_LINK.exec(textOf(details))?.[0]
198
330
  return { status: 'started', sessionId, ...(link === undefined ? {} : { link }) }
199
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
+ }
200
340
  if (operation === 'send_message') {
201
341
  const prompt = String(args.prompt ?? args.message ?? '')
202
342
  // Claude refuses a session's message to itself; a prompt this session submits is its next turn.
@@ -248,32 +388,297 @@ async function hostsClaudeSessions($: EngineInterface): Promise<boolean> {
248
388
  )
249
389
  }
250
390
 
251
- /** 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
+ */
252
463
  async function runSessionTool($: EngineInterface, operation: string, input: Record<string, unknown>): Promise<string> {
253
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
+ }
254
469
  if (app === 'claude') {
255
470
  // The bridge drives Claude from outside the app, so a new session needs no
256
471
  // "start the session?" prompt; without a bridge, Claude's own tools answer.
257
472
  const { launch: _launch, ...request } = args
258
473
  const bridged = await post($, '/sessions', { app, operation, args: request })
259
- 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
+ }
260
487
  try {
261
- return JSON.stringify(await answer($, operation, args), null, 2)
488
+ return compact(await answer($, operation, args))
262
489
  } catch (error) {
263
- 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
+ )
264
493
  }
265
494
  }
266
- 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
+ }
267
504
  const { launch, ...request } = args
268
505
  let answered = await post($, '/sessions', { app, operation, args: request })
269
- 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.
270
509
  const started = await startCodex($, launch)
271
- if (started !== true) return JSON.stringify(started, null, 2)
510
+ if (started !== true) return compact(started)
272
511
  answered = await post($, '/sessions', { app, operation, args: request })
273
512
  }
274
- return answered.ok
275
- ? JSON.stringify(answered.value, null, 2)
276
- : `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
+ }
277
682
  }
278
683
 
279
684
  async function cordisxHome($: EngineInterface): Promise<string> {
@@ -301,6 +706,7 @@ async function startCodex($: EngineInterface, launch: unknown): Promise<true | R
301
706
  return {
302
707
  status: 'needs-confirmation',
303
708
  reason: 'codex-not-running',
709
+ retryable: false,
304
710
  question: 'Codex Desktop is not running. Start it?',
305
711
  howToContinue:
306
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.',
@@ -319,28 +725,60 @@ async function startCodex($: EngineInterface, launch: unknown): Promise<true | R
319
725
  : ['cordisx', 'start', 'codex', target.profileId]
320
726
  const started = await $.process.run(argv, { env: { CORDISX_HOME: target.homeDir }, timeoutMs: CODEX_START_MS })
321
727
  if (started.exitCode !== 0) {
322
- 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
+ }
323
736
  }
324
737
  for (const deadline = Date.now() + CODEX_START_MS; Date.now() < deadline;) {
325
738
  if ((await post($, '/sessions', { app: 'codex', operation: 'list_sessions', args: { limit: 1 } })).ok) return true
326
739
  await new Promise(resolve => setTimeout(resolve, 1000))
327
740
  }
328
- 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
+ }
329
748
  }
330
749
 
331
750
  export const register: Register = on => {
332
751
  on('session.start', async ($, e, next) => {
333
- for (const tool of SESSION_TOOLS) {
752
+ for (const tool of [...SESSION_TOOLS, MODEL_PROVIDER_TOOL, STATUS_TOOL]) {
334
753
  await $.tool.register({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema })
335
754
  }
336
755
  $.clock.every(POLL_MS, () => void poll($))
337
756
  return next(e)
338
757
  })
339
758
 
759
+ on('tool.call', { tool: `mcp__cordisx__${MODEL_PROVIDER_TOOL.name}` }, async $ => {
760
+ try {
761
+ return { result: compact(await modelProviders($)) }
762
+ } catch (error) {
763
+ return {
764
+ result: compact(
765
+ failure('agent-bridge-unavailable', error instanceof Error ? error.message : String(error), true),
766
+ ),
767
+ }
768
+ }
769
+ })
770
+
340
771
  for (const tool of SESSION_TOOLS) {
341
772
  on('tool.call', { tool: `mcp__cordisx__${tool.name}` }, async ($, e) => {
342
773
  const { tool: _tool, tool_use_id: _id, ...args } = e as Record<string, unknown>
343
774
  return { result: await runSessionTool($, tool.name, args) }
344
775
  })
345
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
+ })
346
784
  }