@nones/agentflow-opencode 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/README.md CHANGED
@@ -1,3 +1,115 @@
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 is deliberately
4
+ local-only and has no runtime dependencies.
5
+
6
+ ## Usage
7
+
8
+ ```ts
9
+ import { createOpenCodeAdapter } from "@nones/agentflow-opencode";
10
+
11
+ const adapter = createOpenCodeAdapter({
12
+ resolveCredential: async (ref) => {
13
+ // Trusted host code resolves a credential reference. The adapter never
14
+ // reads token files or environment variables itself.
15
+ return await myCredentialSource(ref);
16
+ },
17
+ });
18
+
19
+ const sessionId = await adapter.open(agent, profile, {
20
+ // Passed only by trusted opt-in module composition.
21
+ instructions: "Session-only module instructions.",
22
+ permissions: [{ action: "shell", resource: "bd *", effect: "deny" }],
23
+ });
24
+ const result = await adapter.turn({
25
+ sessionId,
26
+ turnId,
27
+ agent,
28
+ profile,
29
+ prompt: "Do the work",
30
+ onReceipt: (id) => saveReceipt(id),
31
+ });
32
+ ```
33
+
34
+ ## Profile settings
35
+
36
+ ```ts
37
+ {
38
+ endpoint: "http://127.0.0.1:4096", // or endpointName + resolveEndpoint
39
+ auth: { type: "bearer", ref: "opencode-local" },
40
+ model: "openai/gpt-4.1", // profile.model also works
41
+ directory: "/path/to/worktree", // or settings.cwd
42
+ turnDelivery: "queue", // or "steer"
43
+ timeouts: {
44
+ requestMs: 15_000,
45
+ sessionReadyMs: 5_000,
46
+ turnMs: 120_000,
47
+ waitMs: 10_000
48
+ },
49
+ eventStream: true,
50
+ headers: { "x-extra": "value" }
51
+ }
52
+ ```
53
+
54
+ `directory` / `cwd` is used for profile-level operations such as `doctor`,
55
+ where it is sent as the `location[directory]` query. `createOpenCodeAdapter`
56
+ may also receive an explicit `defaultCwd` fallback; the adapter never invents a
57
+ cwd.
58
+
59
+ Endpoints must be loopback (`localhost`, `127.0.0.0/8`, or `::1`) unless
60
+ `allowNonLoopback` is explicitly set on the adapter. Port discovery is not
61
+ automatic; a named endpoint must be registered deliberately.
62
+
63
+ The adapter requests a concrete `provider/model` when creating a session and
64
+ polls `GET /api/session/{id}` until the native session exposes that model.
65
+
66
+ ## Native endpoints used
67
+
68
+ - `POST /api/session`
69
+ - `GET /api/session/{sessionID}`
70
+ - `PUT /api/experimental/session/{sessionID}/instructions/entries/agentflow_modules` (only when session instructions are supplied)
71
+ - `POST /api/session/{sessionID}/prompt`
72
+ - `POST /api/experimental/session/{sessionID}/wait` (completion hint)
73
+ - `GET /api/session/{sessionID}/message`
74
+ - `GET /api/event` (SSE)
75
+ - `POST /api/session/{sessionID}/interrupt`
76
+ - `GET /api/model` (doctor only)
77
+
78
+ Both bare responses and `{ data: ... }` wrappers are accepted.
79
+
80
+ ## Admission and observation semantics
81
+
82
+ - An explicit HTTP 429 before admission produces `status: "rate_limited"` with
83
+ `safeToRetry: true`, the classified reason, and `Retry-After` when present.
84
+ - A transport failure after a prompt submission is treated as ambiguous and
85
+ maps to `status: "interrupted"`. The adapter never resubmits automatically.
86
+ - Receipts scope observation. Assistant messages are grouped only when they can
87
+ be attributed to the current receipt or turn; baseline message ids and event
88
+ timestamps prevent older terminal events from completing a new turn. A
89
+ completed intermediate step whose finish reason is tool-calls/tool-use is not
90
+ terminal; the turn continues until an explicit session idle/error or
91
+ `session.execution.*` completion.
92
+ - A confirmed native `retry.scheduled` event with an HTTP 429 signal is emitted
93
+ to `onEvent` as `{ type: "provider.rate_limit", data: { reason, retryAfterMs } }`.
94
+ It is an observation only and never submits a duplicate turn.
95
+ - SSE and experimental-wait cancellation are awaited at turn close. Reader
96
+ cancellation and observer tasks always carry rejection handlers, so an open
97
+ stream cannot surface an unhandled `AbortError`.
98
+ - `reconcile` requires a receipt and returns a result only for a terminal
99
+ assistant message attributed to that receipt. Otherwise it returns
100
+ `undefined` rather than guessing.
101
+ - `doctor` checks endpoint reachability and, when `/api/model` is available,
102
+ whether the configured model is listed. HTTP 401/403 is reported with
103
+ `ok: false`. An empty catalogue, an unavailable catalogue, or an unknown
104
+ catalogue shape is never treated as model verification.
105
+
106
+ ## Tests
107
+
108
+ ```sh
109
+ bun test providers/opencode
110
+ ```
111
+
112
+ Tests use an injected fetch and synthetic fixtures only. They do not contact a
113
+ server, read credentials, inspect environment variables, or touch token files.
114
+ Auth coverage uses `resolveCredential`; the adapter has no literal-token or
115
+ environment-variable default.
package/package.json CHANGED
@@ -1,6 +1,38 @@
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.1.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
+ }