@tduyng/pi-opencode-z 0.0.2 → 0.0.4

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 (2) hide show
  1. package/README.md +50 -25
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,42 +1,58 @@
1
- # pi-opencode-z
1
+ # @tduyng/pi-opencode-z
2
2
 
3
- Use opencode's Zen models from Pi, including the free ones.
3
+ opencode's Zen models in pi, free ones included, with no API key and no proxy. The bridge drives the opencode server already running on the machine.
4
4
 
5
- Since September 2026 the free tier answers any direct API call with `403 FreeTierError: "OpenCode's free tier can only be used from within OpenCode"`. No API key or proxy gets around it, because the check is on where the request originates. So this extension does not call the Zen API. It drives the opencode background server already running on your machine and lets opencode make the upstream call, which is the one thing the free tier accepts.
5
+ Since September 2026 the free tier answers any direct API call with `403 FreeTierError: "OpenCode's free tier can only be used from within OpenCode"`. No key and no proxy gets around it, because the check is on where the request originates.
6
6
 
7
- ## How it works
7
+ So the extension does not call the Zen API. It drives the opencode background server and lets opencode make the upstream call, which is the one thing the free tier accepts.
8
8
 
9
- The bridge reads the server's url and password from `~/.local/state/opencode/service.json` and talks to it over HTTP basic auth as user `opencode`. If the server is not running, `opencode service start` brings it back.
9
+ ## The conversation lives in opencode
10
10
 
11
- Each Pi session gets one opencode session, rooted in a throwaway temp directory that holds its `opencode.jsonc`. Nothing is written to your repo or to `~/.config/opencode`.
11
+ The bridge sends only the new message each turn instead of re-serialising the transcript, and the tool schemas sit in opencode's cached prefix rather than being pasted back as prose on every request.
12
12
 
13
- Pi's own tools reach the model through a local MCP server, exposed as `pi_read`, `pi_bash`, `pi_edit` and so on. When the model calls one, the bridge holds that MCP request open, hands the call to Pi, and Pi runs the real tool against your real project. The answer goes back over the same held request and opencode carries on in the same session, none the wiser. The model never touches your files directly. Pi does, under Pi's own permissions.
13
+ The bridge exposes pi's tools over MCP as `pi_read`, `pi_bash`, `pi_edit` and so on. When the model calls one, the bridge holds that MCP request open, hands the call to pi, and pi runs the real tool against the real project. The answer goes back over the same held request and opencode carries on in the same session. The model never touches files directly.
14
14
 
15
- Pi hands providers a transcript rather than a prompt and a tool list, so the bridge replays the transcript's system messages to recover the current instructions and tool set before each turn.
15
+ Nothing is written to the repository. Each pi session gets one opencode session rooted in a throwaway temp directory holding its `opencode.jsonc`, and `~/.config/opencode` is untouched.
16
16
 
17
- Cold start costs nothing extra. A plain `opencode run` on a free model spends 9176 input tokens on a one-line prompt. The bridge spends 6941, with 2048 of those served from cache. That 7k floor is opencode's own system prompt and built-in tool schemas. Every approach to this problem pays it, because stripping those tools is exactly what trips the 403.
17
+ A mode switch that adds or removes tools keeps the session too: the bridge pushes `notifications/tools/list_changed` over MCP, opencode re-lists, and the cached prefix survives.
18
18
 
19
- The savings are per turn. opencode holds the conversation, so each turn sends only the new message instead of re-serializing the whole transcript. Tool schemas sit in the cached prefix rather than being pasted back as prose every time. Extensions that drive the opencode CLI instead have to resend everything on every turn and teach the model to hand-write tool calls inside text markers. A mode switch that adds or removes tools keeps the session too: the bridge pushes `notifications/tools/list_changed` over MCP, opencode re-lists, and the cached prefix survives.
19
+ ## The token floor
20
20
 
21
- A full tool-calling turn, measured end to end including a real file read, takes about 10 seconds.
21
+ A plain `opencode run` on a free model spends 9,176 input tokens on a one-line prompt. This bridge spends 6,941, with 2,048 of those served from cache. That floor is opencode's own system prompt and built-in tool schemas, and every approach pays it, because stripping those tools is exactly what trips the 403.
22
22
 
23
- ## Using it
23
+ What the bridge saves is per turn. A full tool-calling turn with a real file read takes about 10 seconds end to end.
24
24
 
25
- Run `/model` and pick anything under the `opencode-z` provider, for example `opencode-z/mimo-v2.6-flash-free`.
25
+ ## Use
26
26
 
27
- From the command line:
27
+ Run `/model` and pick anything under the `opencode-z` provider, for example `opencode-z/mimo-v2.6-flash-free`.
28
28
 
29
- ```
29
+ ```text
30
30
  pi --provider opencode-z --model mimo-v2.6-flash-free
31
31
  ```
32
32
 
33
- ## Commands
33
+ | Command | Effect |
34
+ | --- | --- |
35
+ | `/opencode-z status` | Server url, config file, models filter, MCP endpoint, live sessions, model list |
36
+ | `/opencode-z models` | The models alone, free ones first |
37
+ | `/opencode-z refresh` | Re-read the config and the catalogue without restarting pi |
38
+ | `/opencode-z config` | Resolved settings and where they come from |
39
+ | `/opencode-z help` | Usage |
40
+
41
+ ## Install
42
+
43
+ - The `opencode` CLI on `PATH`, or `OPENCODE_Z_BIN` pointing at it.
44
+ - The opencode background server. If it is not running, the bridge runs `opencode service start`.
45
+ - No API key and no account.
34
46
 
35
- `/opencode-z status` shows the server url, the config file, the active models filter, the MCP endpoint, live sessions and the model list. `/opencode-z models` lists the models alone, free ones first. `/opencode-z refresh` re-reads the config file and the catalogue from opencode. `/opencode-z config` shows the resolved settings and where they come from. `/opencode-z help` prints usage.
47
+ ```bash
48
+ pi install npm:@tduyng/pi-opencode-z
49
+ ```
50
+
51
+ Local checkout: `pi install /path/to/dotfiles/pi/agent/extensions/pi-opencode-z`
36
52
 
37
- ## Settings
53
+ The bridge reads the server url and password from `~/.local/state/opencode/service.json` and talks to it over HTTP basic auth as user `opencode`.
38
54
 
39
- Settings live in `opencode-z.json` inside Pi's agent directory (usually `~/.pi/agent/opencode-z.json`). A project's `.pi/opencode-z.json` overrides it field by field. Environment variables override both, so either mechanism works and one-off runs never need to touch a file. `/opencode-z config` shows the resolved values, and `/opencode-z refresh` re-reads both files without restarting Pi.
55
+ Settings live in `~/.pi/agent/opencode-z.json`, and a project's `.pi/opencode-z.json` overrides it field by field. Environment variables override both, so a one-off run never needs a file.
40
56
 
41
57
  Free models only:
42
58
 
@@ -55,16 +71,25 @@ A pinned list with a custom binary:
55
71
  }
56
72
  ```
57
73
 
58
- `bin` overrides the `opencode` executable. `models` narrows what gets registered: `free` keeps zero-cost models, a comma-separated string or an array of ids pins the list. Unset or empty, the bridge registers every Zen model your account can reach, free and paid. Only Zen models appear here (the `opencode` provider in opencode's catalogue), never other providers. `OPENCODE_Z_BIN` and `OPENCODE_Z_MODELS` do the same per process and win over the file.
74
+ `models` narrows what gets registered: `free` keeps zero-cost models, and a comma-separated string or an array pins the list. Unset or empty, every Zen model the account can reach is registered. Only Zen models appear, never other providers. `OPENCODE_Z_BIN` and `OPENCODE_Z_MODELS` do the same per process and win over the file.
75
+
76
+ It adds no tool, no prompt block and no schema, so the context is pi's own and cold start is unchanged.
59
77
 
60
78
  ## Notes
61
79
 
62
- The bridge never denies opencode's built-in tools. A `deny` rule anywhere in the agent's permissions trips the free tier 403 even for tools that were allowed, so every action stays on `ask` and the bridge rejects the unwanted ones at runtime. A weaker model sometimes reaches for its built-in `read` first, gets refused, and retries with `pi_read`, which costs one round trip.
80
+ The bridge never denies opencode's built-in tools. A `deny` rule anywhere in the agent's permissions trips the free-tier 403 even for allowed tools, so every action stays on `ask` and the bridge rejects the unwanted ones at runtime. A weaker model sometimes reaches for its built-in `read` first, gets refused, and retries with `pi_read`, which costs one round trip.
81
+
82
+ opencode adds and retires Zen models often, so the bridge reads the catalogue live at startup and `/opencode-z refresh` re-reads it.
83
+
84
+ The first prompt lists the exact MCP names available in that turn. Some model hosts display these tools under a `functions.` namespace, and the bridge states that the label does not rename a tool, so a model does not mistake a disabled `read` for `pi_read`.
63
85
 
64
- opencode adds and retires Zen models often. The catalogue is read live at startup, and `/opencode-z refresh` re-reads it without restarting Pi.
86
+ opencode stops a whole step when the model calls two built-in tools at once, since refusing one declines the rest. The bridge counts its own refusals and, when that stop was its doing, re-prompts the same session with a nudge back to the `pi_` tools, at most twice per turn.
65
87
 
66
- The first prompt lists the exact MCP names available in that turn. Some model hosts display these tools under a `functions.` namespace. The bridge states that the label does not rename a tool, which keeps a model from mistaking disabled `read` for `pi_read`. A successful model step with reasoning but no text or tool call is re-prompted through the same bounded recovery path, and so is a step whose only text is a pi_ call written out as chat template markup instead of dispatched.
88
+ When a turn fails, the bridge interrupts opencode and answers waiting tool calls with an error. It keeps the opencode session when pi's transcript still ends at the last completed user message, so a retry reuses the prompt cache, and drops it when a partial assistant or tool result is present.
67
89
 
68
- opencode stops a whole step when the model calls two of its built-in tools at once: refusing one declines the rest. The bridge counts its own refusals and, when that stop was its doing, re-prompts the same session with a nudge back to the pi_ tools (at most twice per turn) instead of failing the turn.
90
+ ## Limits
69
91
 
70
- When a turn fails, the bridge interrupts opencode and answers waiting tool calls with an error. It keeps the opencode session when Pi's transcript still ends at the last completed user message, so a retry can reuse the prompt cache. If Pi's transcript contains a partial assistant or tool result, the bridge drops the session and rebuilds it from Pi's transcript. A timeout usually means the model was still working (large contexts on high thinking levels are slow) or opencode got stuck waiting.
92
+ - A turn times out at 300 seconds, and an MCP exec at 300 seconds. Large contexts on high thinking levels are slow, so a timeout usually means the model was still working.
93
+ - The API request times out at 15 seconds, and the MCP body is capped at 8 MB.
94
+ - A step that produces reasoning but no text and no tool call is re-prompted through a bounded recovery path, twice per turn at most.
95
+ - Free-tier model availability is opencode's to change. The list is read live for that reason.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tduyng/pi-opencode-z",
3
- "version": "0.0.2",
4
- "description": "Use opencode's Zen models from Pi, including the free ones, by driving the local opencode server and bridging Pi tools over MCP.",
3
+ "version": "0.0.4",
4
+ "description": "opencode's Zen models in Pi, free ones included, by driving the local opencode server. No API key of your own.",
5
5
  "keywords": [
6
6
  "pi",
7
7
  "pi-package",