headroom-opencode 0.36.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 ADDED
@@ -0,0 +1,107 @@
1
+ # headroom-opencode
2
+
3
+ OpenCode integration helpers for Headroom. The package supports two integration paths:
4
+
5
+ 1. Provider config helpers used by `headroom wrap opencode` and persistent installs.
6
+ 2. A native OpenCode plugin that installs Headroom transport interception and exposes the retrieve tool.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install headroom-opencode
12
+ ```
13
+
14
+ ## Provider Config Helpers
15
+
16
+ Use these helpers when you need to generate OpenCode config that routes a `headroom` provider through a running Headroom proxy.
17
+
18
+ ```ts
19
+ import {
20
+ buildOpencodeConfigContent,
21
+ createHeadroomProvider,
22
+ } from "headroom-opencode";
23
+
24
+ const provider = createHeadroomProvider({ proxyPort: 8787 });
25
+ const config = buildOpencodeConfigContent({
26
+ proxyPort: 8787,
27
+ defaultModel: "claude-sonnet-4-6",
28
+ });
29
+
30
+ console.log(provider.provider.headroom.npm);
31
+ console.log(config.model);
32
+ ```
33
+
34
+ The generated provider uses `@ai-sdk/openai-compatible` and points model requests at `http://127.0.0.1:<port>/v1`.
35
+
36
+ ## Native OpenCode Plugin
37
+
38
+ Use `HeadroomPlugin` when OpenCode should intercept provider traffic in-process and expose Headroom tooling from a plugin.
39
+
40
+ ```ts
41
+ import { HeadroomPlugin } from "headroom-opencode";
42
+
43
+ export default async function plugin(input) {
44
+ return HeadroomPlugin(input, {
45
+ proxyUrl: process.env.HEADROOM_PROXY_URL ?? "http://127.0.0.1:8787",
46
+ });
47
+ }
48
+ ```
49
+
50
+ `HeadroomPlugin`:
51
+
52
+ - installs Headroom transport interception for OpenCode provider traffic.
53
+ - exposes the `headroom_retrieve` tool.
54
+ - publishes `HEADROOM_PROXY_URL` in the plugin output env.
55
+ - defaults to `http://127.0.0.1:8787` when no proxy URL is supplied.
56
+
57
+ ## Retrieve Tool
58
+
59
+ ```ts
60
+ import { createHeadroomRetrieveTool } from "headroom-opencode";
61
+
62
+ const retrieve = createHeadroomRetrieveTool({
63
+ proxyBaseUrl: "http://127.0.0.1:8787",
64
+ });
65
+
66
+ const result = await retrieve.execute({
67
+ hash: "0123456789abcdef01234567",
68
+ });
69
+ ```
70
+
71
+ The tool calls `/v1/retrieve/<hash>` on the Headroom proxy.
72
+
73
+ ## Compression Helper
74
+
75
+ ```ts
76
+ import { compressWithHeadroom } from "headroom-opencode";
77
+
78
+ const result = await compressWithHeadroom(
79
+ [{ role: "user", content: "Summarize this file" }],
80
+ { model: "gpt-4o", proxyUrl: "http://127.0.0.1:8787" },
81
+ );
82
+
83
+ console.log(`Saved ${result.tokensSaved} tokens`);
84
+ ```
85
+
86
+ ## Models
87
+
88
+ | Model | Context | Output |
89
+ |---|---:|---:|
90
+ | `claude-sonnet-4-6` | 200K | 16K |
91
+ | `claude-opus-4-6` | 200K | 16K |
92
+ | `claude-haiku-4-5-20251001` | 200K | 8K |
93
+ | `gpt-4o` | 128K | 16K |
94
+ | `gpt-4.1` | 1M | 32K |
95
+
96
+ The provider config exposes these as `headroom/<model>` and defaults to `headroom/claude-sonnet-4-6`.
97
+
98
+ ## Environment
99
+
100
+ | Variable | Used by | Description |
101
+ |---|---|---|
102
+ | `HEADROOM_PROXY_URL` | Native plugin | Proxy URL used by `HeadroomPlugin` |
103
+ | `OPENCODE_CONFIG_CONTENT` | OpenCode wrapper | Generated OpenCode provider, model, and MCP config |
104
+
105
+ ## License
106
+
107
+ Apache-2.0