@nones/agentflow-opencode 0.0.0-stage → 0.6.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AgentFlow contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,195 @@
1
- # Temporary Holding Version
1
+ # `@nones/agentflow-opencode`
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
+ Local OpenCode V2 HTTP provider adapter for AgentFlow. It connects to a loopback
4
+ OpenCode service, opens native sessions, submits turns and maps completion,
5
+ rate-limit and interruption signals into AgentFlow contracts.
6
+
7
+ The adapter uses the shared contracts from `@nones/agentflow-core` through
8
+ type-only imports, so importing it never loads core or its
9
+ server.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ bun add @nones/agentflow-opencode
15
+ ```
16
+
17
+ Bun 1.4.5 or newer is required.
18
+
19
+ ## Direct use
20
+
21
+ ```ts
22
+ import { createOpenCodeAdapter } from "@nones/agentflow-opencode";
23
+
24
+ const adapter = createOpenCodeAdapter({
25
+ resolveCredential: (ref) => {
26
+ // Trusted host code resolves the reference. The adapter never reads token
27
+ // files, credential stores or environment variables on its own.
28
+ if (ref === "env:OPENCODE_TOKEN") return process.env.OPENCODE_TOKEN;
29
+ return undefined;
30
+ },
31
+ });
32
+
33
+ const profile = {
34
+ id: "local",
35
+ adapter: "opencode",
36
+ model: "provider/model",
37
+ settings: {
38
+ endpoint: "http://127.0.0.1:4096",
39
+ auth: { type: "bearer", ref: "env:OPENCODE_TOKEN" },
40
+ },
41
+ };
42
+
43
+ const agent = {
44
+ id: "reviewer",
45
+ prompt: "Review the current diff.",
46
+ cwd: process.cwd(),
47
+ };
48
+
49
+ const sessionId = await adapter.open(agent, profile);
50
+
51
+ const result = await adapter.turn({
52
+ sessionId,
53
+ turnId: crypto.randomUUID(),
54
+ agent,
55
+ profile,
56
+ prompt: agent.prompt,
57
+ onReceipt: (id) => {
58
+ // Persist the receipt so an ambiguous transport can be reconciled later.
59
+ console.error(`receipt: ${id}`);
60
+ },
61
+ });
62
+
63
+ console.log(result.status);
64
+ ```
65
+
66
+ With `@nones/agentflow-core`, pass the adapter in `serve({ adapters })`. With
67
+ the CLI package, `agentflow serve` composes it automatically for profiles whose
68
+ `adapter` is `"opencode"`. See
69
+ [`examples/server.ts`](https://github.com/nones-tools/agentflow/blob/main/examples/server.ts).
70
+
71
+ ## Profile settings
72
+
73
+ ```ts
74
+ {
75
+ endpoint: "http://127.0.0.1:4096", // or endpointName + resolveEndpoint
76
+ auth: { type: "bearer", ref: "env:OPENCODE_TOKEN" },
77
+ model: "provider/model", // profile.model also works
78
+ directory: "/path/to/worktree", // or settings.cwd
79
+ turnDelivery: "queue", // or "steer"
80
+ timeouts: {
81
+ requestMs: 15_000,
82
+ sessionReadyMs: 5_000,
83
+ turnMs: 120_000,
84
+ waitMs: 10_000
85
+ },
86
+ eventStream: true,
87
+ headers: { "x-extra": "value" }
88
+ }
89
+ ```
90
+
91
+ `directory` / `cwd` is used for profile-level operations such as `doctor`, where
92
+ it is sent as the `location[directory]` query. `createOpenCodeAdapter` may also
93
+ receive an explicit `defaultCwd` fallback; the adapter never invents a cwd.
94
+
95
+ Endpoints must be loopback (`localhost`, `127.0.0.0/8` or `::1`) unless
96
+ `allowNonLoopback: true` is explicitly set on the adapter. Port discovery is not
97
+ automatic; a named endpoint must be registered deliberately through
98
+ `endpoints` or `resolveEndpoint`.
99
+
100
+ The adapter requests a concrete `provider/model` when creating a session and
101
+ polls `GET /api/session/{id}` until the native session exposes that model.
102
+
103
+ ## Authentication references
104
+
105
+ Authentication is configured as a reference in local profile settings. The
106
+ adapter passes the reference to your `resolveCredential` callback and never
107
+ reads credentials itself. AgentFlow's CLI accepts only environment references;
108
+ trusted host code may resolve them from whatever local source it already owns.
109
+
110
+ Bearer:
111
+
112
+ ```ts
113
+ auth: { type: "bearer", ref: "env:OPENCODE_TOKEN" }
114
+ ```
115
+
116
+ Custom header:
117
+
118
+ ```ts
119
+ auth: {
120
+ type: "header",
121
+ name: "Authorization",
122
+ ref: "env:OPENCODE_AUTHORIZATION",
123
+ }
124
+ ```
125
+
126
+ A bare string is treated as a bearer reference. The CLI resolves only explicit
127
+ `env:NAME`, `$NAME` or bare environment-variable references and never prints or
128
+ inventories the value. Credential files and provider auth stores are never read
129
+ by either package.
130
+
131
+ ## Native endpoints used
132
+
133
+ - `POST /api/session`
134
+ - `GET /api/session/{sessionID}`
135
+ - `PUT /api/experimental/session/{sessionID}/instructions/entries/agentflow_modules`
136
+ (only when session instructions are supplied)
137
+ - `POST /api/session/{sessionID}/prompt`
138
+ - `POST /api/experimental/session/{sessionID}/wait` (completion hint)
139
+ - `GET /api/session/{sessionID}/message`
140
+ - `GET /api/event` (SSE)
141
+ - `POST /api/session/{sessionID}/interrupt`
142
+ - `GET /api/model` (doctor only)
143
+
144
+ Both bare responses and `{ data: ... }` wrappers are accepted.
145
+
146
+ ## Admission and observation semantics
147
+
148
+ - An explicit HTTP 429 before admission produces `status: "rate_limited"` with
149
+ `safeToRetry: true`, the classified reason and `Retry-After` when present.
150
+ - A transport failure after prompt submission is ambiguous and maps to
151
+ `status: "interrupted"`. The adapter never resubmits automatically.
152
+ - Receipts scope observation. Assistant messages are grouped only when they can
153
+ be attributed to the current receipt or turn. Baseline message IDs and event
154
+ timestamps prevent older terminal events from completing a new turn.
155
+ - A completed intermediate step whose finish reason is tool calls is not
156
+ terminal. The turn continues until an explicit session idle/error or
157
+ `session.execution.*` completion.
158
+ - A confirmed native `retry.scheduled` event with an HTTP 429 signal is emitted
159
+ to `onEvent` as `{ type: "provider.rate_limit", data: { reason, retryAfterMs } }`.
160
+ It is an observation only and never submits a duplicate turn.
161
+ - SSE and experimental-wait cancellation are awaited at turn close. Reader and
162
+ observer tasks carry rejection handlers, so an open stream cannot surface an
163
+ unhandled `AbortError`.
164
+ - `reconcile` requires a receipt and returns a result only for a terminal
165
+ assistant message attributed to that receipt. Otherwise it returns
166
+ `undefined` rather than guessing.
167
+ - `doctor` checks endpoint reachability and, when `/api/model` is available,
168
+ whether the configured model is listed. HTTP 401/403 is reported with
169
+ `ok: false`. An empty, unavailable or unknown catalogue is never treated as
170
+ successful model verification.
171
+
172
+ ## Tests
173
+
174
+ From a repository checkout:
175
+
176
+ ```sh
177
+ bun test providers/opencode
178
+ ```
179
+
180
+ Tests use an injected fetch and synthetic fixtures only. They do not contact a
181
+ server, read credentials, inspect environment variables or touch token files.
182
+ Auth coverage uses `resolveCredential`; the adapter has no literal-token or
183
+ environment-variable default.
184
+
185
+ ## Documentation
186
+
187
+ - [Core contracts](https://github.com/nones-tools/agentflow/blob/main/docs/contracts.md)
188
+ - [Server bootstrap example](https://github.com/nones-tools/agentflow/blob/main/examples/server.ts)
189
+ - [CLI package](https://github.com/nones-tools/agentflow/tree/main/apps/cli)
190
+ - [Repository README](https://github.com/nones-tools/agentflow/blob/main/README.md)
191
+ - [Issues](https://github.com/nones-tools/agentflow/issues)
192
+
193
+ ## License
194
+
195
+ MIT. See [LICENSE](https://github.com/nones-tools/agentflow/blob/main/LICENSE).
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@nones/agentflow-opencode",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.6.0",
4
+ "description": "Local OpenCode V2 HTTP provider adapter for AgentFlow",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "./src/index.ts",
8
+ "module": "./src/index.ts",
9
+ "types": "./src/index.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./src/index.ts",
13
+ "import": "./src/index.ts",
14
+ "default": "./src/index.ts"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "files": [
19
+ "src",
20
+ "README.md"
21
+ ],
22
+ "engines": {
23
+ "bun": ">=1.4.5"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "registry": "https://registry.npmjs.org/"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/nones-tools/agentflow.git",
32
+ "directory": "providers/opencode"
33
+ },
34
+ "scripts": {
35
+ "build": "bun build ./src/index.ts --target=bun --outdir=.tmp/build --packages external",
36
+ "test": "bun test"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/nones-tools/agentflow/issues"
40
+ },
41
+ "license": "MIT",
42
+ "dependencies": {
43
+ "@nones/agentflow-core": "0.6.0"
44
+ }
45
+ }