@finalai/acp-adapter-codex 0.0.0-stage → 0.1.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.
package/HOSTING.md ADDED
@@ -0,0 +1,363 @@
1
+ # Hosting agents: requirements, provide documents and local hosts
2
+
3
+ An agent is a document (data) that states what it requires: a harness within a
4
+ permission ceiling, compute by capability, and named integration slots. Whoever
5
+ starts work provides implementations in a plain `provide` object. This guide is
6
+ for hosts that implement the agent platform API these packages call: what the
7
+ SDK sends, what it expects back, and the connection a client dials to lend its
8
+ own process to an agent.
9
+
10
+ ## Selecting a deployment
11
+
12
+ ```sh
13
+ export FINAL_API_HOST=https://<agents-api-host>
14
+ export FINAL_API_KEY=<api-key>
15
+ export FINAL_PROJECT_ID=<project-id>
16
+ pnpm exec final-agents print ./agent.ts # the document, as JSON; calls nothing
17
+ pnpm exec final-agents publish ./agent.ts --name release-scout
18
+ ```
19
+
20
+ `--host` overrides `FINAL_API_HOST`; `--project` overrides `FINAL_PROJECT_ID`.
21
+ `createClient({ host })` selects a deployment the same way. Nothing in an agent
22
+ names a deployment, a server URL or a credential, so the same document runs
23
+ against any host.
24
+
25
+ ## Agents are documents
26
+
27
+ An agent value (`defineAgent`) becomes its document with `documentOf(agent)`:
28
+ identity, instructions, skills, `require`, workspace seed files, each tool's
29
+ name and schema, hooks, tool policy, secret names and schedules. The agent's
30
+ identity is the content hash of the canonical document with defaults applied
31
+ (`agentDocumentHash` from `@finalai/agent-provider/document`, `sha256:<hex>`).
32
+ Hosts must hash with that function; any other canonicalization yields other
33
+ hashes.
34
+
35
+ Each tool and hook says where it runs:
36
+
37
+ - **Serverless** code carries one self-contained ES module (`source`, `export`).
38
+ It runs on the host's serverless runtime from the document alone, whether or
39
+ not any client is connected. Hosts re-check that the source imports nothing.
40
+ - **In-process** code carries only its interface. Its body never leaves the
41
+ process that created the session; the host calls it over that process's
42
+ local host connection (below). With no such connection the tool reports
43
+ itself unavailable and the session carries on.
44
+
45
+ `@finalai/agent-provider/code-host` routes each call by placement
46
+ (`createCodeHost`); the serverless runtime contract is `ServerlessRuntimeIface`.
47
+ A serverless tool gives the model a projection apart from its structured output
48
+ by returning `{ [Symbol.for(SERVERLESS_TOOL_RESULT)]: true, output, modelOutput }`;
49
+ the runtime reads every tool return with `serverlessToolResultOf` and sends
50
+ `modelOutput` on the result line. The model sees `modelOutput` when present,
51
+ and `output` stays the structured result.
52
+
53
+ Routes, under `/api/v1/projects/:projectId/agents`:
54
+
55
+ | Route | Body / query | Response |
56
+ | ---------------- | ----------------------------------- | -------------------------------------- |
57
+ | `PUT /documents` | `{ document, hash? }` | `{ hash }`; refuse a hash that differs |
58
+ | `POST /publish` | `{ name, hash }` | `{ id, name, hash, publishedAt }` |
59
+ | `GET /lookup` | exactly one of `name`, `id`, `hash` | `agentInfoSchema` |
60
+ | `GET /history` | `name`, `cursor?`, `limit?` | `agentHistorySchema` |
61
+
62
+ An agent is always passed as an object, `{ hash, document? }`, never a name. A
63
+ request whose document is absent names a hash the host already stores.
64
+
65
+ ## Provide documents
66
+
67
+ ```json
68
+ {
69
+ "harness": {
70
+ "harness": "pi",
71
+ "configuration": {
72
+ "model": "gpt-6.1-sol",
73
+ "inference": [{ "source": "final", "billTo": "project" }]
74
+ }
75
+ },
76
+ "compute": { "files": "asbx_01J…", "shell": "asbx_01J…" },
77
+ "integrations": { "issues": "intg_01H…" }
78
+ }
79
+ ```
80
+
81
+ `provideDocumentSchema` (`@finalai/agent-protocol/agent-platform`) is the one
82
+ shape on every call that can start work: `sessions.create`, `conversations.create`
83
+ (per participant, plus a shared document for the conversation), direct and Home
84
+ conversations, `addParticipant`, `PUT …/participants/:pid/provide`, channel
85
+ installs (`agents.provide`) and schedules. It names only things that exist: a
86
+ sandbox or integration by id, harness settings inline. Hosts store it as given
87
+ and resolve participant, then conversation, then the install or schedule that
88
+ created the conversation, taking each top-level key whole from the nearest scope
89
+ that sets it. A conversation returns its shared document as `provide`, so a
90
+ client can run the same check before adding a participant. Nothing has a
91
+ default on the host.
92
+
93
+ `files` and `shell` must name the same sandbox. A sandbox or integration id
94
+ must belong to the session's project.
95
+
96
+ ## The requirements check
97
+
98
+ Every call that can start work runs `unmetRequirements` from
99
+ `@finalai/agent-provider/requirements-check` with what the host knows (each
100
+ sandbox's capabilities, which integrations exist, the composed harness via
101
+ `harnessCheckInputOf`, whether a client holding the in-process code is
102
+ connected). If anything is unmet, nothing is created and the response is:
103
+
104
+ ```json
105
+ {
106
+ "error": {
107
+ "code": "requirements_unmet",
108
+ "message": "…",
109
+ "details": {
110
+ "agent": "sha256:…",
111
+ "requirements": [
112
+ {
113
+ "kind": "integration",
114
+ "name": "issues",
115
+ "description": "Issue tracker",
116
+ "problem": "not_provided",
117
+ "detail": null
118
+ }
119
+ ]
120
+ }
121
+ }
122
+ }
123
+ ```
124
+
125
+ `harness_unsuitable` has the same body for a harness change refused on its own.
126
+ The SDK runs the same function before sending, so a caller sees the same list
127
+ either way; the SDK error carries `code` and `requirements`
128
+ (`isRequirementsUnmetError`).
129
+
130
+ A running agent therefore always has what it requires: the host adds nothing to
131
+ its context about requirements. An optional requirement that was not provided is
132
+ simply absent.
133
+
134
+ ## Harnesses, ACP adapters and environments
135
+
136
+ Three independent pieces reach a model loop, and the host speaks only ACP v2:
137
+
138
+ - a **harness** definition: the agent program (it need not speak ACP);
139
+ - an **ACP adapter** definition: maps one harness interface to ACP v2, reusable
140
+ across harnesses; a harness that speaks ACP v2 needs none;
141
+ - an **environment**: a sandbox that runs them, or an ACP v2 endpoint already
142
+ running at a URL.
143
+
144
+ Harness settings name them:
145
+ `{ harness, adapter?, configuration, environment? }`. `adapter` defaults to the
146
+ harness definition's. `environment` is a sandbox id (the pair is started
147
+ there), `{ url, hop? }` (nothing is started), or absent: a harness that uses
148
+ `files` or `shell` natively then runs in the sandbox provided for `shell`; any
149
+ other harness is refused.
150
+
151
+ Definitions are data (`harnessDefinitionSchema`, `acpAdapterDefinitionSchema`
152
+ in `@finalai/agent-provider/harness-definition`), published by name and stored
153
+ by content hash. A harness definition carries its configuration's JSON Schema,
154
+ supported features, `lowestPermission`, accepted inference sources, what it uses
155
+ natively from where it runs (`native.files`, `native.shell`), its interface and
156
+ default adapter, ACP behaviour (`promptWhileRunning`, `sessionSurvivesDisconnect`,
157
+ `supports`, `mcp`, `consumes`), and `run` entries per runtime kind:
158
+
159
+ - `process`: a command, with arguments and environment derived from the
160
+ configuration by templates (`{{configuration.model}}`, groups included
161
+ `when` a value is set). An adapter's process entry wraps the harness's
162
+ (`{{harness.command}}`, `{ spread: 'harness.args' }`).
163
+ - `worker`: a program built for a worker runtime, by name.
164
+
165
+ An environment runs what its sandbox provider declares
166
+ (`SandboxEnvironmentImplementationIface.runtimes`: `process`, `worker`; absent
167
+ means `process` when it offers `shell`). A worker runtime is not a machine: it
168
+ offers the model no files or shell, so a harness running there reaches the
169
+ sandboxes provided for them over the handle RPC. `composeHarness` picks a
170
+ runtime kind the environment, the harness and the adapter all have, and
171
+ `harnessCheckInputOf` turns the result into the requirements check's input: a
172
+ harness's native capabilities are its environment's, so only that sandbox may
173
+ be provided for them. `harnessStartFor` renders what to start.
174
+
175
+ A harness provider (`HarnessProviderIface`, `@finalai/agent-provider/harness-provider`)
176
+ reaches a harness: `open` and `resume` return an ACP endpoint (`ws`, `http`, or
177
+ `sandbox`: a process or worker program the session service starts in the
178
+ environment sandbox over the handle RPC, ACP on its stdio or stream, with no
179
+ port exposed), and `park`, `close` and `health` follow its lifecycle. The
180
+ general provider starts adapter(harness) from the definitions; a definition
181
+ whose harness is reached some other way carries its own provider code
182
+ (`defineHarnessProvider`), one self-contained module run on the serverless
183
+ runtime.
184
+
185
+ Routes, under `/api/v1/projects/:projectId`:
186
+
187
+ | Route | Body or query | Response |
188
+ | ------------------------------------------ | ------------------------------------ | --------------------------------- |
189
+ | `POST /harnesses/check` | `{ agent: hash, harness, compute? }` | `harnessCheckResponseSchema` |
190
+ | `POST /harnesses/publish` | `{ name, definition, hash? }` | `definitionPublicationSchema` |
191
+ | `GET /harnesses/lookup` | `name` or `hash` | `harnessDefinitionInfoSchema` |
192
+ | `GET /harnesses` | | `harnessDefinitionListSchema` |
193
+ | `POST /acp-adapters/publish` | `{ name, definition, hash? }` | `definitionPublicationSchema` |
194
+ | `GET /acp-adapters/lookup` | `name` or `hash` | `acpAdapterDefinitionInfoSchema` |
195
+ | `GET /acp-adapters` | | `acpAdapterDefinitionListSchema` |
196
+ | `GET /subscription-allowances` | | `subscriptionAllowanceListSchema` |
197
+ | `PUT /subscription-allowances/:harness` | `{}` | `subscriptionAllowanceSchema` |
198
+ | `DELETE /subscription-allowances/:harness` | | `{ ok }` |
199
+
200
+ The check answers `{ suitable, problems, compute, environment, adapter,
201
+ runtime }`, where `compute[capability].status` is `harness` (its environment
202
+ serves it natively), `sandbox` (a provided sandbox must) or `unavailable`. A
203
+ project can name its own definitions, its ancestors' and the public catalog's.
204
+ A subscription inference source reaches a harness only when the project allows
205
+ that harness, or the public catalog does for its own definitions. The model is
206
+ a string the harness validates; the host never substitutes a default model.
207
+
208
+ ## Sandboxes and setups
209
+
210
+ Under `/api/v1/projects/:projectId`: `POST /sandboxes` (`{ provider, environment,
211
+ setup?, ownedBy?, idempotencyKey? }`; creating boots nothing), `GET` and
212
+ `DELETE /sandboxes/:id`, `GET /sandboxes/:id/description`, and
213
+ `POST /sandboxes/:id/run` (`{ command, cwd?, env?, timeoutMs? }` →
214
+ `{ exitCode, stdout, stderr }`, booting the sandbox if needed). A sandbox owned
215
+ by a conversation or session is deleted with its owner. A retried create with
216
+ the same `idempotencyKey` returns the first sandbox. Sandbox setups are
217
+ published with `POST /sandbox-setups` (`{ name, setup }`); `latest` resolves once,
218
+ when a sandbox is created.
219
+
220
+ ## Integrations and sign-in
221
+
222
+ Integrations are project resources: an MCP server and how calls to it
223
+ authenticate (`oauth` personal or shared, `secret` by project secret name,
224
+ `platform-identity`, `none`). A person's own sign-in is runtime state: on the
225
+ first call that needs it, the host raises a `sign_in` decision for that person,
226
+ holds the call, and continues it when `POST /api/v1/sign-ins/complete` succeeds.
227
+ `platform-identity` sends a short-lived signed assertion of the calling session
228
+ that any server can verify against the host's published keys; Final's gateway is
229
+ an ordinary integration with this auth.
230
+
231
+ ### Integration tool policy
232
+
233
+ A slot's `tools` (`allow`, `deny`, `load`, `allowAnnotations`,
234
+ `denyAnnotations`) and `approvals` are a ceiling over whatever integration fills
235
+ it. Keys are tool names or `*` patterns: `*` matches any run of characters,
236
+ `deny` wins over `allow`, and the most specific key governs (an exact name, else
237
+ the pattern with the most literal characters, ties toward `ask`). Hosts enforce
238
+ this with `isToolExposed`, `isToolLoaded`, `toolApprovalOf` and
239
+ `resolveToolApprovalKey` from `@finalai/agent-provider`.
240
+
241
+ An annotation selector matches when every hint it sets equals the tool's hint,
242
+ reading omitted hints as the MCP spec's defaults (not read-only, destructive, not
243
+ idempotent, open world). Annotations come from the integration's server, so
244
+ select on them only for servers trusted to classify their own tools.
245
+
246
+ With `load`, the host lists only the loaded tools and keeps every other exposed
247
+ tool reachable through a search over the integration's remaining tools and a
248
+ call that runs a found tool by its real name, with the same exposure and
249
+ approval checks as a direct call. Without `load`, the host lists every exposed
250
+ tool except tools a server labels with a connector in `_meta`
251
+ (`{ "ai.final/connector": { "namespace": "…", "name": "…" } }`) and tools past
252
+ the host's listing limit, which it searches instead. A harness that declares
253
+ `supports.deferredToolSearch` searches tools itself, so the host lists every
254
+ exposed tool to it.
255
+
256
+ ## Local hosts
257
+
258
+ A client that starts an agent can lend its own process to it: it serves the
259
+ agent's `files` and `shell` (any it was not given a sandbox for, unless created
260
+ with `localCompute: false`) and answers calls to the agent's in-process tools,
261
+ hooks and approval predicates. It does so over one WebSocket per agent it
262
+ started:
263
+
264
+ ```
265
+ GET /api/v1/projects/:projectId/local-hosts (WebSocket upgrade)
266
+ Sec-WebSocket-Protocol: final.local-host.v1
267
+ Authorization: Bearer <the client's credential>
268
+ ```
269
+
270
+ The socket carries two protocols. Binary frames are always the sandbox handle
271
+ RPC's stream chunks. A text frame belongs to the **host protocol** when it is a
272
+ JSON-RPC request or notification whose method starts with `host/` or `code/`, or
273
+ a response (or `$/cancel_request`) whose id is a string starting with `host:`.
274
+ Every other text frame is the **sandbox handle RPC**
275
+ (`@finalai/agent-provider/sandbox/wire`), in which the host is the RPC client and
276
+ the client process serves the sandbox: the host sends `initialize`,
277
+ `sandbox/readFile`, `sandbox/run` and the rest, with numeric ids, gated by a grant
278
+ of the access the agent requires on the capabilities it serves.
279
+ `splitLocalHostChannel` and `createHostPeer` from `@finalai/agents/client/local-host`
280
+ implement both sides of the split.
281
+
282
+ **`host/hello`** (client → host, first): the client's id is `host:1`.
283
+
284
+ ```json
285
+ {
286
+ "jsonrpc": "2.0",
287
+ "id": "host:1",
288
+ "method": "host/hello",
289
+ "params": {
290
+ "protocolVersion": 1,
291
+ "owner": { "kind": "session", "id": "ases_…" },
292
+ "agent": "sha256:…",
293
+ "capabilities": ["files", "shell"],
294
+ "tools": ["find_order"],
295
+ "hooks": [],
296
+ "approvals": [],
297
+ "resume": "lhost_…"
298
+ }
299
+ }
300
+ ```
301
+
302
+ `owner.kind` is `session` or `conversation`; `owner.id` is absent when the
303
+ caller chose no id, and the host reserves one the client then creates with.
304
+ `resume` is a host id from an earlier connection. The result:
305
+
306
+ ```json
307
+ {
308
+ "jsonrpc": "2.0",
309
+ "id": "host:1",
310
+ "result": {
311
+ "hostId": "lhost_…",
312
+ "owner": { "kind": "session", "id": "ases_…" },
313
+ "sandboxId": "asbx_…"
314
+ }
315
+ }
316
+ ```
317
+
318
+ `sandboxId` names this connection's compute in `provide.compute` (one sandbox for
319
+ both capabilities, as the requirements check demands); it is null when the
320
+ client serves no capability. The sandbox belongs to the owner and is deleted
321
+ with it.
322
+
323
+ **`code/run`** (host → client): params are one code invocation
324
+ (`codeInvocationSchema` from `@finalai/agent-provider/code-host`: `kind` tool,
325
+ hook or approval, the `name` in the document, `input` or `event` and `payload`,
326
+ and a `context` with `sessionId`, `callId`, `actingUserId` and the session's
327
+ compute endpoints for `ctx.sandbox(capability)`). A hook's payload is
328
+ `{ data, meta: { id, at, seq } }`. The result is the final line:
329
+ `{ "type": "result", "output": …, "modelOutput"?: … }` or
330
+ `{ "type": "error", "message": "…" }`; an approval answers `output: true` to
331
+ ask first. While it runs the client sends **`code/progress`** notifications
332
+ `{ "requestId": "host:7", "data": …, "label"?: "…" }`. The host cancels with
333
+ `$/cancel_request { "requestId": "host:7" }`.
334
+
335
+ **`code/secret`** (client → host): in-process code reading `ctx.secrets.get(name)`
336
+ asks with `{ "requestId": "host:7", "name": "BILLING_TOKEN" }`, where
337
+ `requestId` is the `code/run` it runs for. The host answers
338
+ `{ "value": "…" | null }` (null when the secret is not set). It refuses a name
339
+ the agent's document does not list in `secrets`, a `requestId` that is not a
340
+ `code/run` in flight on this connection, and resolves the name in the project
341
+ of the session or conversation the host serves. The client refuses unlisted
342
+ names itself before asking.
343
+
344
+ When the socket closes the session carries on. Until a connection resumes it,
345
+ the host reports this process's in-process tools as unavailable
346
+ (`CodeErrorCode.Unavailable`) and its sandbox as unreachable. The SDK's socket
347
+ does not keep a Node process alive, so a script that is done exits and its tools
348
+ become unavailable.
349
+
350
+ ## Host integration
351
+
352
+ These packages define contracts and client behaviour, not a platform. A host
353
+ implementing them must:
354
+
355
+ 1. Store documents by `agentDocumentHash`, re-check self-contained serverless
356
+ source, and point names at hashes only when someone publishes.
357
+ 2. Run `unmetRequirements` on every call that starts work and at every session
358
+ open, and create nothing when it fails.
359
+ 3. Store each `provide` as given; never fill a requirement on a caller's behalf.
360
+ 4. Route each tool and hook by its placement: serverless code to its runtime with
361
+ the source from the document, in-process code to the local host that holds it.
362
+ 5. Resolve integration auth per call for the acting person, raising sign-in as
363
+ that integration's auth step.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Final TypeScript packages
2
+ Copyright 2026 Final, Inc.
3
+
4
+ Licensed under the Apache License, Version 2.0. See LICENSE for details.
package/README.md CHANGED
@@ -1,3 +1,58 @@
1
- # Temporary Holding Version
1
+ # @finalai/acp-adapter-codex
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Codex as an [ACP](https://agentclientprotocol.com) v2 agent on stdio, with Final's ACP
4
+ extensions. It drives the Codex app-server (`codex app-server`, from the `@openai/codex`
5
+ package it depends on) and is built on `@finalai/acp-session`.
6
+
7
+ ```sh
8
+ npx @finalai/acp-adapter-codex --permission-mode ask -- codex app-server -c model=gpt-6
9
+ ```
10
+
11
+ With `OPENAI_API_KEY` in the environment the adapter is started with, Codex uses that key and
12
+ `OPENAI_BASE_URL` (default `https://api.openai.com/v1`). Without it, Codex uses its own login
13
+ in `CODEX_HOME`. Your Codex `config.toml`, `AGENTS.md` and skills stay in effect.
14
+
15
+ ## Options
16
+
17
+ - `--state-dir <dir>`: where sessions are kept so that `session/resume` works in a new
18
+ process (default `$ACP_ADAPTER_STATE_DIR`, then `~/.acp-adapter-codex`).
19
+ - `--permission-mode <mode>`: the approval policy sessions start with: `untrusted`,
20
+ `on-request` or `never`, or a permission level (`ask`, `review`, `auto`, in that order).
21
+ - `-- <command> [args...]`: the app-server command line to run (`app-server` is added when
22
+ missing). Without it the adapter runs the Codex its `@openai/codex` dependency installs.
23
+
24
+ ## Session config options
25
+
26
+ Set with `session/set_config_option`:
27
+
28
+ | Config id | Values |
29
+ | --------- | -------------------------------------------------------------- |
30
+ | `model` | `default` (Codex's configured model) or any model id |
31
+ | `effort` | `default`, `none`, `minimal`, `low`, `medium`, `high`, `xhigh` |
32
+ | `mode` | approval policy: `untrusted` (default), `on-request`, `never` |
33
+ | `sandbox` | `read-only`, `workspace-write` (default), `danger-full-access` |
34
+
35
+ Model, effort and approval policy apply from the next turn; a sandbox change restarts the
36
+ app-server on the same thread.
37
+
38
+ ## ACP and extensions
39
+
40
+ - `initialize` advertises `_meta["final.ai"]`: `supports` `observe`, `authorMeta`,
41
+ `resumeReplay`, `afterSeqReplay` and `fork`; `program` `codex`; `runtime` this package.
42
+ - `session/new`, `session/resume` (replay from `start` or `_final/after_seq`), `session/fork`
43
+ (a Codex thread fork), `session/prompt`, `session/cancel`, `session/close`,
44
+ `session/set_config_option`.
45
+ - `_final/session/observe`: observed content is held and given to Codex ahead of the next
46
+ prompt. `_final/live_text` accompanies streamed text, which carries `emittedAtMs`.
47
+ - `_meta["final.ai"].author` on prompt content reaches the model as an author line.
48
+ - Error stops carry `_meta["final.ai"].providerError`.
49
+ - Command, file change and permission approvals become `session/request_permission`; MCP
50
+ elicitations and Codex's questions become `elicitation/create`.
51
+ - MCP servers: `http`, `stdio` and `acp` (served by the client over `mcp/message`). Codex's
52
+ own MCP client reaches every one through a loopback MCP proxy the adapter runs, which keeps
53
+ each tool call's full result: Codex shortens large results for the model, while the tool
54
+ call's ACP content is the whole result. Content over the ACP frame limits is written to the
55
+ state directory and linked as a `resource_link`.
56
+ - A prompt sent while a turn runs is steered into it (`turn/steer`), and the turn ends once
57
+ both are answered (one idle).
58
+ - Prompts take text, images and embedded resources.
@@ -0,0 +1,11 @@
1
+ import type { CodexTransportIface } from "./json-rpc.mjs";
2
+ export interface SpawnAppServerArgsIface {
3
+ command: string;
4
+ args: string[];
5
+ cwd: string;
6
+ env: Record<string, string>;
7
+ log: (line: string) => void;
8
+ closeGraceMs?: number;
9
+ }
10
+ export type SpawnAppServer = (args: SpawnAppServerArgsIface) => CodexTransportIface;
11
+ export declare const spawnCodexAppServer: SpawnAppServer;