opencode-fixes-huihui 0.1.3 → 0.1.4-beta.2

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,6 +1,9 @@
1
1
  # opencode-fixes-huihui
2
2
 
3
- opencode 单插件版本:统一处理 sticky session headers 和 `promptCacheKey`,用于稳定会话路由与缓存命中。
3
+ 统一插件包:默认导出组合插件,同时包含:
4
+
5
+ - sticky session headers + `promptCacheKey` 注入
6
+ - Anthropic 渠道 `metadata.user_id` 缓存注入
4
7
 
5
8
  ## 安装
6
9
 
@@ -10,44 +13,75 @@ npm i opencode-fixes-huihui
10
13
 
11
14
  ## 使用
12
15
 
16
+ 默认导出是组合插件(推荐):
17
+
13
18
  ```ts
14
- import StickySessionPlugin from "opencode-fixes-huihui";
19
+ import CombinedPlugin from "opencode-fixes-huihui";
15
20
 
16
21
  export default {
17
- plugins: [StickySessionPlugin],
22
+ plugins: [CombinedPlugin],
18
23
  };
19
24
  ```
20
25
 
21
- 也可使用具名导出:
26
+ 也支持具名导出:
22
27
 
23
28
  ```ts
24
- import { StickySessionPlugin } from "opencode-fixes-huihui";
29
+ import {
30
+ CombinedPlugin,
31
+ StickySessionPlugin,
32
+ AnthropicCache,
33
+ AnthropicUltraCache,
34
+ FoxcodeAwsCache,
35
+ createAnthropicCachePlugin,
36
+ } from "opencode-fixes-huihui";
25
37
  ```
26
38
 
27
- ## 行为
39
+ ## 功能说明
40
+
41
+ ### 1) Sticky session(`StickySessionPlugin`)
42
+
43
+ 在 `chat.params` 阶段执行,仅对 `@ai-sdk/openai` 或 `isCodex` provider 生效。
44
+
45
+ 会话值优先级:
46
+
47
+ 1. `OPENCODE_PROMPT_CACHE_KEY`
48
+ 2. `OPENCODE_STICKY_SESSION_ID`
49
+ 3. 现有 headers:`x-session-id` / `conversation_id` / `session_id`
50
+ 4. `input.sessionID`
51
+
52
+ 写入位置:
53
+
54
+ - `input.model.headers.x-session-id`
55
+ - `input.model.headers.conversation_id`
56
+ - `input.model.headers.session_id`
57
+ - `output.options.promptCacheKey`
58
+
59
+ 可选环境变量:
60
+
61
+ - `OPENCODE_PROMPT_CACHE_KEY`:强制覆盖会话值(最高优先级)
62
+ - `OPENCODE_STICKY_SESSION_ID`:次优先级覆盖会话值
63
+
64
+ ### 2) Anthropic cache(`AnthropicCache` 系列)
65
+
66
+ 在 auth loader 的请求 `fetch` 中拦截 Anthropic POST JSON 请求,自动补齐:
67
+
68
+ - `metadata.user_id = user_{projectId}_account__session_{sessionId}`
28
69
 
29
- 插件在 `chat.params` 中执行:
70
+ 内置 provider:
30
71
 
31
- 1. 仅对 `@ai-sdk/openai` provider 生效
32
- 2. 解析会话值优先级:
33
- - `OPENCODE_PROMPT_CACHE_KEY`
34
- - `OPENCODE_STICKY_SESSION_ID`
35
- - 现有 headers:`x-session-id` / `conversation_id` / `session_id`
36
- - `input.sessionID`
37
- 3. 将解析值同时写入:
38
- - `input.model.headers.x-session-id`
39
- - `input.model.headers.conversation_id`
40
- - `input.model.headers.session_id`
41
- - `output.options.promptCacheKey`
72
+ - `AnthropicCache`(`anthropic`)
73
+ - `AnthropicUltraCache`(`anthropic-ultra`)
74
+ - `FoxcodeAwsCache`(`foxcode-aws`)
42
75
 
43
- ## 可选环境变量
76
+ 自定义 provider 可使用:
44
77
 
45
- - `OPENCODE_PROMPT_CACHE_KEY`: 强制覆盖会话值(最高优先级)
46
- - `OPENCODE_STICKY_SESSION_ID`: 次优先级覆盖会话值
78
+ - `createAnthropicCachePlugin("your-provider-name")`
47
79
 
48
80
  ## 开发
49
81
 
50
82
  ```bash
83
+ npm run format
84
+ npm run lint
51
85
  npm run typecheck
52
86
  npm run build
53
87
  ```
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from "@opencode-ai/plugin";
2
+ export declare const CombinedPlugin: Plugin;
3
+ export default CombinedPlugin;
4
+ //# sourceMappingURL=combined-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combined-plugin.d.ts","sourceRoot":"","sources":["../src/combined-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAgBzD,eAAO,MAAM,cAAc,EAAE,MAwE5B,CAAC;AAEF,eAAe,cAAc,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,21 +1,4 @@
1
- import type { Plugin } from "@opencode-ai/plugin";
2
- /**
3
- * set a session-scoped prompt cache key and session-scoped sticky routing headers for right.codes.
4
- *
5
- * Injects HTTP headers via `input.model.headers` so upstream proxies/load
6
- * balancers can keep a conversation pinned to one account.
7
- *
8
- * Headers injected for @ai-sdk/openai providers:
9
- * - x-session-id
10
- * - conversation_id
11
- * - session_id
12
- *
13
- * Source of truth (in order):
14
- * - env: OPENCODE_PROMPT_CACHE_KEY (manual override)
15
- * - env: OPENCODE_STICKY_SESSION_ID (manual override)
16
- * - model headers (x-session-id / conversation_id / session_id)
17
- * - opencode sessionID (default)
18
- */
19
- export declare const StickySessionPlugin: Plugin;
20
- export default StickySessionPlugin;
1
+ export { CombinedPlugin, default } from "./combined-plugin";
2
+ export { AnthropicCache, AnthropicUltraCache, createAnthropicCachePlugin, FoxcodeAwsCache, } from "./opencode-anthropic-cache";
3
+ export { StickySessionPlugin } from "./sticky-session-plugin";
21
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AA2BlD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,EAAE,MA6CjC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,0BAA0B,EAC1B,eAAe,GAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,87 +1,89 @@
1
- // codex_header.txt
2
- var codex_header_default = `You are OpenCode, the best coding agent on the planet.
3
-
4
- You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
5
-
6
- ## Editing constraints
7
- - Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.
8
- - Only add comments if they are necessary to make a non-obvious block easier to understand.
9
- - Try to use apply_patch for single file edits, but it is fine to explore other options to make the edit if it does not work well. Do not use apply_patch for changes that are auto-generated (i.e. generating package.json or running a lint or format command like gofmt) or when scripting is more efficient (such as search and replacing a string across a codebase).
10
-
11
- ## Tool usage
12
- - Prefer specialized tools over shell for file operations:
13
- - Use Read to view files, Edit to modify files, and Write only when needed.
14
- - Use Glob to find files by name and Grep to search file contents.
15
- - Use Bash for terminal operations (git, bun, builds, tests, running scripts).
16
- - Run tool calls in parallel when neither call needs the other\u2019s output; otherwise run sequentially.
17
-
18
- ## Git and workspace hygiene
19
- - You may be in a dirty git worktree.
20
- * NEVER revert existing changes you did not make unless explicitly requested, since these changes were made by the user.
21
- * If asked to make a commit or code edits and there are unrelated changes to your work or changes that you didn't make in those files, don't revert those changes.
22
- * If the changes are in files you've touched recently, you should read carefully and understand how you can work with the changes rather than reverting them.
23
- * If the changes are in unrelated files, just ignore them and don't revert them.
24
- - Do not amend commits unless explicitly requested.
25
- - **NEVER** use destructive commands like \`git reset --hard\` or \`git checkout --\` unless specifically requested or approved by the user.
26
-
27
- ## Frontend tasks
28
- When doing frontend design tasks, avoid collapsing into bland, generic layouts.
29
- Aim for interfaces that feel intentional and deliberate.
30
- - Typography: Use expressive, purposeful fonts and avoid default stacks (Inter, Roboto, Arial, system).
31
- - Color & Look: Choose a clear visual direction; define CSS variables; avoid purple-on-white defaults. No purple bias or dark mode bias.
32
- - Motion: Use a few meaningful animations (page-load, staggered reveals) instead of generic micro-motions.
33
- - Background: Don't rely on flat, single-color backgrounds; use gradients, shapes, or subtle patterns to build atmosphere.
34
- - Overall: Avoid boilerplate layouts and interchangeable UI patterns. Vary themes, type families, and visual languages across outputs.
35
- - Ensure the page loads properly on both desktop and mobile.
36
-
37
- Exception: If working within an existing website or design system, preserve the established patterns, structure, and visual language.
38
-
39
- ## Presenting your work and final message
40
-
41
- You are producing plain text that will later be styled by the CLI. Follow these rules exactly. Formatting should make results easy to scan, but not feel mechanical. Use judgment to decide how much structure adds value.
42
-
43
- - Default: be very concise; friendly coding teammate tone.
44
- - Default: do the work without asking questions. Treat short tasks as sufficient direction; infer missing details by reading the codebase and following existing conventions.
45
- - Questions: only ask when you are truly blocked after checking relevant context AND you cannot safely pick a reasonable default. This usually means one of:
46
- * The request is ambiguous in a way that materially changes the result and you cannot disambiguate by reading the repo.
47
- * The action is destructive/irreversible, touches production, or changes billing/security posture.
48
- * You need a secret/credential/value that cannot be inferred (API key, account id, etc.).
49
- - If you must ask: do all non-blocked work first, then ask exactly one targeted question, include your recommended default, and state what would change based on the answer.
50
- - Never ask permission questions like "Should I proceed?" or "Do you want me to run tests?"; proceed with the most reasonable option and mention what you did.
51
- - For substantial work, summarize clearly; follow final\u2011answer formatting.
52
- - Skip heavy formatting for simple confirmations.
53
- - Don't dump large files you've written; reference paths only.
54
- - No "save/copy this file" - User is on the same machine.
55
- - Offer logical next steps (tests, commits, build) briefly; add verify steps if you couldn't do something.
56
- - For code changes:
57
- * Lead with a quick explanation of the change, and then give more details on the context covering where and why a change was made. Do not start this explanation with "summary", just jump right in.
58
- * If there are natural next steps the user may want to take, suggest them at the end of your response. Do not make suggestions if there are no natural next steps.
59
- * When suggesting multiple options, use numeric lists for the suggestions so the user can quickly respond with a single number.
60
- - The user does not command execution outputs. When asked to show the output of a command (e.g. \`git show\`), relay the important details in your answer or summarize the key lines so the user understands the result.
61
-
62
- ## Final answer structure and style guidelines
63
-
64
- - Plain text; CLI handles styling. Use structure only when it helps scannability.
65
- - Headers: optional; short Title Case (1-3 words) wrapped in **\u2026**; no blank line before the first bullet; add only if they truly help.
66
- - Bullets: use - ; merge related points; keep to one line when possible; 4\u20136 per list ordered by importance; keep phrasing consistent.
67
- - Monospace: backticks for commands/paths/env vars/code ids and inline examples; use for literal keyword bullets; never combine with **.
68
- - Code samples or multi-line snippets should be wrapped in fenced code blocks; include an info string as often as possible.
69
- - Structure: group related bullets; order sections general \u2192 specific \u2192 supporting; for subsections, start with a bolded keyword bullet, then items; match complexity to the task.
70
- - Tone: collaborative, concise, factual; present tense, active voice; self\u2011contained; no "above/below"; parallel wording.
71
- - Don'ts: no nested bullets/hierarchies; no ANSI codes; don't cram unrelated keywords; keep keyword lists short\u2014wrap/reformat if long; avoid naming formatting styles in answers.
72
- - Adaptation: code explanations \u2192 precise, structured with code refs; simple tasks \u2192 lead with outcome; big changes \u2192 logical walkthrough + rationale + next actions; casual one-offs \u2192 plain sentences, no headers/bullets.
73
- - File References: When referencing files in your response follow the below rules:
74
- * Use inline code to make file paths clickable.
75
- * Each reference should have a stand alone path. Even if it's the same file.
76
- * Accepted: absolute, workspace\u2011relative, a/ or b/ diff prefixes, or bare filename/suffix.
77
- * Optionally include line/column (1\u2011based): :line[:column] or #Lline[Ccolumn] (column defaults to 1).
78
- * Do not use URIs like file://, vscode://, or https://.
79
- * Do not provide range of lines
80
- * Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\\repo\\project\\main.rs:12:5`;
1
+ // src/opencode-anthropic-cache.ts
2
+ var currentSessionId = "";
3
+ var projectId = "";
4
+ var isInitialized = false;
5
+ function buildUserId() {
6
+ const pid = projectId || "unknown";
7
+ const sid = currentSessionId || "unknown";
8
+ return `user_${pid}_account__session_${sid}`;
9
+ }
10
+ function isJsonContentType(headers) {
11
+ const ct = headers.get("content-type") || "";
12
+ return ct.includes("application/json");
13
+ }
14
+ function parseBody(body) {
15
+ if (!body) return null;
16
+ if (typeof body === "string") return body;
17
+ if (body instanceof Uint8Array) return new TextDecoder().decode(body);
18
+ return null;
19
+ }
20
+ function createCacheFetch() {
21
+ return async (url, init) => {
22
+ const headers = new Headers(init?.headers);
23
+ const method = (init?.method || "GET").toUpperCase();
24
+ if (method !== "POST" || !isJsonContentType(headers)) {
25
+ return fetch(url, init);
26
+ }
27
+ const rawBody = parseBody(init?.body);
28
+ if (!rawBody) return fetch(url, init);
29
+ let payload;
30
+ try {
31
+ payload = JSON.parse(rawBody);
32
+ } catch {
33
+ return fetch(url, init);
34
+ }
35
+ if (payload && typeof payload === "object") {
36
+ if (!payload.metadata || typeof payload.metadata !== "object") {
37
+ payload.metadata = {};
38
+ }
39
+ const meta = payload.metadata;
40
+ if (meta.user_id == null) {
41
+ meta.user_id = buildUserId();
42
+ }
43
+ }
44
+ headers.delete("content-length");
45
+ return fetch(url, { ...init, headers, body: JSON.stringify(payload) });
46
+ };
47
+ }
48
+ function createEventHandler() {
49
+ return async ({ event }) => {
50
+ if (event.type === "session.created" || event.type === "session.updated") {
51
+ const props = event.properties;
52
+ currentSessionId = props?.info?.id || "";
53
+ }
54
+ };
55
+ }
56
+ function createProviderPlugin(providerName) {
57
+ return async ({ project }) => {
58
+ if (!isInitialized) {
59
+ projectId = project?.id || "";
60
+ isInitialized = true;
61
+ }
62
+ return {
63
+ event: createEventHandler(),
64
+ auth: {
65
+ provider: providerName,
66
+ methods: [{ type: "api", label: "key" }],
67
+ loader: async () => ({
68
+ fetch: createCacheFetch()
69
+ })
70
+ }
71
+ };
72
+ };
73
+ }
74
+ var FoxcodeAwsCache = createProviderPlugin("foxcode-aws");
75
+ var AnthropicCache = createProviderPlugin("anthropic");
76
+ var AnthropicUltraCache = createProviderPlugin("anthropic-ultra");
77
+ var createAnthropicCachePlugin = createProviderPlugin;
78
+ var opencode_anthropic_cache_default = AnthropicCache;
81
79
 
82
- // index.ts
80
+ // src/sticky-session-plugin.ts
83
81
  var OPENAI_PROVIDER_NPM = "@ai-sdk/openai";
84
- var SESSION_HEADER_KEYS = ["x-session-id", "conversation_id", "session_id"];
82
+ var SESSION_HEADER_KEYS = [
83
+ "x-session-id",
84
+ "conversation_id",
85
+ "session_id"
86
+ ];
85
87
  var normalize = (value) => typeof value === "string" ? value.trim() : "";
86
88
  var pickHeaderSessionValue = (headers) => {
87
89
  for (const key of SESSION_HEADER_KEYS) {
@@ -114,12 +116,6 @@ var StickySessionPlugin = async ({ client }) => {
114
116
  inited = true;
115
117
  };
116
118
  return {
117
- "experimental.chat.system.transform": async ({ model }, { system }) => {
118
- if (!inited) await init();
119
- const isCodex = isProviderCodexMap[model.providerID] ?? false;
120
- if (!isCodex) return;
121
- system[0] = system[0].startsWith(codex_header_default) ? system[0].slice(codex_header_default.length).trimStart() : system[0];
122
- },
123
119
  "chat.params": async (input, output) => {
124
120
  if (!inited) await init();
125
121
  const providerNpm = normalize(input.model.api.npm);
@@ -133,14 +129,99 @@ var StickySessionPlugin = async ({ client }) => {
133
129
  }
134
130
  output.options.promptCacheKey = sessionValue;
135
131
  if (isCodex && !output.options.instructions) {
136
- output.options.instructions = codex_header_default;
132
+ output.options.instructions = "";
137
133
  }
138
134
  }
139
135
  };
140
136
  };
141
- var index_default = StickySessionPlugin;
137
+
138
+ // src/combined-plugin.ts
139
+ var mergeHook = (first, second) => {
140
+ if (!first) return second;
141
+ if (!second) return first;
142
+ return async (...args) => {
143
+ await first(...args);
144
+ await second(...args);
145
+ };
146
+ };
147
+ var CombinedPlugin = async (input) => {
148
+ const stickyHooks = await StickySessionPlugin(input);
149
+ const anthropicHooks = await opencode_anthropic_cache_default(input);
150
+ const merged = {
151
+ ...anthropicHooks,
152
+ ...stickyHooks,
153
+ tool: {
154
+ ...anthropicHooks.tool ?? {},
155
+ ...stickyHooks.tool ?? {}
156
+ },
157
+ "chat.message": mergeHook(
158
+ anthropicHooks["chat.message"],
159
+ stickyHooks["chat.message"]
160
+ ),
161
+ "chat.params": mergeHook(
162
+ anthropicHooks["chat.params"],
163
+ stickyHooks["chat.params"]
164
+ ),
165
+ "chat.headers": mergeHook(
166
+ anthropicHooks["chat.headers"],
167
+ stickyHooks["chat.headers"]
168
+ ),
169
+ "permission.ask": mergeHook(
170
+ anthropicHooks["permission.ask"],
171
+ stickyHooks["permission.ask"]
172
+ ),
173
+ "command.execute.before": mergeHook(
174
+ anthropicHooks["command.execute.before"],
175
+ stickyHooks["command.execute.before"]
176
+ ),
177
+ "tool.execute.before": mergeHook(
178
+ anthropicHooks["tool.execute.before"],
179
+ stickyHooks["tool.execute.before"]
180
+ ),
181
+ "shell.env": mergeHook(
182
+ anthropicHooks["shell.env"],
183
+ stickyHooks["shell.env"]
184
+ ),
185
+ "tool.execute.after": mergeHook(
186
+ anthropicHooks["tool.execute.after"],
187
+ stickyHooks["tool.execute.after"]
188
+ ),
189
+ "experimental.chat.messages.transform": mergeHook(
190
+ anthropicHooks["experimental.chat.messages.transform"],
191
+ stickyHooks["experimental.chat.messages.transform"]
192
+ ),
193
+ "experimental.chat.system.transform": mergeHook(
194
+ anthropicHooks["experimental.chat.system.transform"],
195
+ stickyHooks["experimental.chat.system.transform"]
196
+ ),
197
+ "experimental.session.compacting": mergeHook(
198
+ anthropicHooks["experimental.session.compacting"],
199
+ stickyHooks["experimental.session.compacting"]
200
+ ),
201
+ "experimental.text.complete": mergeHook(
202
+ anthropicHooks["experimental.text.complete"],
203
+ stickyHooks["experimental.text.complete"]
204
+ ),
205
+ "tool.definition": mergeHook(
206
+ anthropicHooks["tool.definition"],
207
+ stickyHooks["tool.definition"]
208
+ ),
209
+ event: mergeHook(anthropicHooks.event, stickyHooks.event),
210
+ config: mergeHook(anthropicHooks.config, stickyHooks.config)
211
+ };
212
+ if (merged.auth === void 0) {
213
+ merged.auth = anthropicHooks.auth ?? stickyHooks.auth;
214
+ }
215
+ return merged;
216
+ };
217
+ var combined_plugin_default = CombinedPlugin;
142
218
  export {
219
+ AnthropicCache,
220
+ AnthropicUltraCache,
221
+ CombinedPlugin,
222
+ FoxcodeAwsCache,
143
223
  StickySessionPlugin,
144
- index_default as default
224
+ createAnthropicCachePlugin,
225
+ combined_plugin_default as default
145
226
  };
146
227
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../codex_header.txt", "../index.ts"],
4
- "sourcesContent": ["You are OpenCode, the best coding agent on the planet.\n\nYou are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.\n\n## Editing constraints\n- Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.\n- Only add comments if they are necessary to make a non-obvious block easier to understand.\n- Try to use apply_patch for single file edits, but it is fine to explore other options to make the edit if it does not work well. Do not use apply_patch for changes that are auto-generated (i.e. generating package.json or running a lint or format command like gofmt) or when scripting is more efficient (such as search and replacing a string across a codebase).\n\n## Tool usage\n- Prefer specialized tools over shell for file operations:\n - Use Read to view files, Edit to modify files, and Write only when needed.\n - Use Glob to find files by name and Grep to search file contents.\n- Use Bash for terminal operations (git, bun, builds, tests, running scripts).\n- Run tool calls in parallel when neither call needs the other\u2019s output; otherwise run sequentially.\n\n## Git and workspace hygiene\n- You may be in a dirty git worktree.\n * NEVER revert existing changes you did not make unless explicitly requested, since these changes were made by the user.\n * If asked to make a commit or code edits and there are unrelated changes to your work or changes that you didn't make in those files, don't revert those changes.\n * If the changes are in files you've touched recently, you should read carefully and understand how you can work with the changes rather than reverting them.\n * If the changes are in unrelated files, just ignore them and don't revert them.\n- Do not amend commits unless explicitly requested.\n- **NEVER** use destructive commands like `git reset --hard` or `git checkout --` unless specifically requested or approved by the user.\n\n## Frontend tasks\nWhen doing frontend design tasks, avoid collapsing into bland, generic layouts.\nAim for interfaces that feel intentional and deliberate.\n- Typography: Use expressive, purposeful fonts and avoid default stacks (Inter, Roboto, Arial, system).\n- Color & Look: Choose a clear visual direction; define CSS variables; avoid purple-on-white defaults. No purple bias or dark mode bias.\n- Motion: Use a few meaningful animations (page-load, staggered reveals) instead of generic micro-motions.\n- Background: Don't rely on flat, single-color backgrounds; use gradients, shapes, or subtle patterns to build atmosphere.\n- Overall: Avoid boilerplate layouts and interchangeable UI patterns. Vary themes, type families, and visual languages across outputs.\n- Ensure the page loads properly on both desktop and mobile.\n\nException: If working within an existing website or design system, preserve the established patterns, structure, and visual language.\n\n## Presenting your work and final message\n\nYou are producing plain text that will later be styled by the CLI. Follow these rules exactly. Formatting should make results easy to scan, but not feel mechanical. Use judgment to decide how much structure adds value.\n\n- Default: be very concise; friendly coding teammate tone.\n- Default: do the work without asking questions. Treat short tasks as sufficient direction; infer missing details by reading the codebase and following existing conventions.\n- Questions: only ask when you are truly blocked after checking relevant context AND you cannot safely pick a reasonable default. This usually means one of:\n * The request is ambiguous in a way that materially changes the result and you cannot disambiguate by reading the repo.\n * The action is destructive/irreversible, touches production, or changes billing/security posture.\n * You need a secret/credential/value that cannot be inferred (API key, account id, etc.).\n- If you must ask: do all non-blocked work first, then ask exactly one targeted question, include your recommended default, and state what would change based on the answer.\n- Never ask permission questions like \"Should I proceed?\" or \"Do you want me to run tests?\"; proceed with the most reasonable option and mention what you did.\n- For substantial work, summarize clearly; follow final\u2011answer formatting.\n- Skip heavy formatting for simple confirmations.\n- Don't dump large files you've written; reference paths only.\n- No \"save/copy this file\" - User is on the same machine.\n- Offer logical next steps (tests, commits, build) briefly; add verify steps if you couldn't do something.\n- For code changes:\n * Lead with a quick explanation of the change, and then give more details on the context covering where and why a change was made. Do not start this explanation with \"summary\", just jump right in.\n * If there are natural next steps the user may want to take, suggest them at the end of your response. Do not make suggestions if there are no natural next steps.\n * When suggesting multiple options, use numeric lists for the suggestions so the user can quickly respond with a single number.\n- The user does not command execution outputs. When asked to show the output of a command (e.g. `git show`), relay the important details in your answer or summarize the key lines so the user understands the result.\n\n## Final answer structure and style guidelines\n\n- Plain text; CLI handles styling. Use structure only when it helps scannability.\n- Headers: optional; short Title Case (1-3 words) wrapped in **\u2026**; no blank line before the first bullet; add only if they truly help.\n- Bullets: use - ; merge related points; keep to one line when possible; 4\u20136 per list ordered by importance; keep phrasing consistent.\n- Monospace: backticks for commands/paths/env vars/code ids and inline examples; use for literal keyword bullets; never combine with **.\n- Code samples or multi-line snippets should be wrapped in fenced code blocks; include an info string as often as possible.\n- Structure: group related bullets; order sections general \u2192 specific \u2192 supporting; for subsections, start with a bolded keyword bullet, then items; match complexity to the task.\n- Tone: collaborative, concise, factual; present tense, active voice; self\u2011contained; no \"above/below\"; parallel wording.\n- Don'ts: no nested bullets/hierarchies; no ANSI codes; don't cram unrelated keywords; keep keyword lists short\u2014wrap/reformat if long; avoid naming formatting styles in answers.\n- Adaptation: code explanations \u2192 precise, structured with code refs; simple tasks \u2192 lead with outcome; big changes \u2192 logical walkthrough + rationale + next actions; casual one-offs \u2192 plain sentences, no headers/bullets.\n- File References: When referencing files in your response follow the below rules:\n * Use inline code to make file paths clickable.\n * Each reference should have a stand alone path. Even if it's the same file.\n * Accepted: absolute, workspace\u2011relative, a/ or b/ diff prefixes, or bare filename/suffix.\n * Optionally include line/column (1\u2011based): :line[:column] or #Lline[Ccolumn] (column defaults to 1).\n * Do not use URIs like file://, vscode://, or https://.\n * Do not provide range of lines\n * Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\\repo\\project\\main.rs:12:5", "import type { Plugin } from \"@opencode-ai/plugin\";\nimport PROMPT_CODEX from \"./codex_header.txt\";\n\nconst OPENAI_PROVIDER_NPM = \"@ai-sdk/openai\";\nconst SESSION_HEADER_KEYS = [\"x-session-id\", \"conversation_id\", \"session_id\"] as const;\n\ntype HeaderMap = Record<string, unknown>;\n\nconst normalize = (value: unknown): string => (typeof value === \"string\" ? value.trim() : \"\");\n\nconst pickHeaderSessionValue = (headers: HeaderMap): string => {\n for (const key of SESSION_HEADER_KEYS) {\n const value = normalize(headers[key]);\n if (value) return value;\n }\n return \"\";\n};\n\nconst ensureHeaders = (model: { headers?: unknown }): HeaderMap => {\n if (model.headers && typeof model.headers === \"object\") {\n return model.headers as HeaderMap;\n }\n const headers: HeaderMap = {};\n model.headers = headers;\n return headers;\n};\n\n/**\n * set a session-scoped prompt cache key and session-scoped sticky routing headers for right.codes.\n *\n * Injects HTTP headers via `input.model.headers` so upstream proxies/load\n * balancers can keep a conversation pinned to one account.\n *\n * Headers injected for @ai-sdk/openai providers:\n * - x-session-id\n * - conversation_id\n * - session_id\n *\n * Source of truth (in order):\n * - env: OPENCODE_PROMPT_CACHE_KEY (manual override)\n * - env: OPENCODE_STICKY_SESSION_ID (manual override)\n * - model headers (x-session-id / conversation_id / session_id)\n * - opencode sessionID (default)\n */\nexport const StickySessionPlugin: Plugin = async ({ client }) => {\n const envPromptCacheKey = normalize(process.env.OPENCODE_PROMPT_CACHE_KEY);\n const envStickySessionID = normalize(process.env.OPENCODE_STICKY_SESSION_ID);\n const envOverride = envPromptCacheKey || envStickySessionID;\n const isProviderCodexMap: Record<string, boolean> = {};\n let inited = false;\n const init = async () => {\n if (inited) return;\n const resp = await client.config.providers();\n const providers = resp.data?.providers ?? [];\n for (const provider of providers) {\n isProviderCodexMap[provider.id] = Boolean(provider.options?.isCodex);\n }\n inited = true;\n };\n\n return {\n \"experimental.chat.system.transform\": async ({ model }, { system }) => {\n if (!inited) await init();\n const isCodex = isProviderCodexMap[model.providerID] ?? false;\n if (!isCodex) return;\n system[0] = system[0].startsWith(PROMPT_CODEX)\n ? system[0].slice(PROMPT_CODEX.length).trimStart()\n : system[0];\n },\n \"chat.params\": async (input, output) => {\n if (!inited) await init();\n const providerNpm = normalize(input.model.api.npm);\n const isCodex = isProviderCodexMap[input.model.providerID] ?? false;\n if (!providerNpm.includes(OPENAI_PROVIDER_NPM) && !isCodex) return;\n\n const headers = ensureHeaders(input.model);\n const sessionValue = envOverride || pickHeaderSessionValue(headers) || normalize(input.sessionID);\n if (!sessionValue) return;\n\n for (const key of SESSION_HEADER_KEYS) {\n headers[key] = sessionValue;\n }\n\n output.options.promptCacheKey = sessionValue;\n if (isCodex && !output.options.instructions) {\n output.options.instructions = PROMPT_CODEX;\n }\n },\n };\n};\n\nexport default StickySessionPlugin;\n"],
5
- "mappings": ";AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,IAAM,sBAAsB;AAC5B,IAAM,sBAAsB,CAAC,gBAAgB,mBAAmB,YAAY;AAI5E,IAAM,YAAY,CAAC,UAA4B,OAAO,UAAU,WAAW,MAAM,KAAK,IAAI;AAE1F,IAAM,yBAAyB,CAAC,YAA+B;AAC7D,aAAW,OAAO,qBAAqB;AACrC,UAAM,QAAQ,UAAU,QAAQ,GAAG,CAAC;AACpC,QAAI,MAAO,QAAO;AAAA,EACpB;AACA,SAAO;AACT;AAEA,IAAM,gBAAgB,CAAC,UAA4C;AACjE,MAAI,MAAM,WAAW,OAAO,MAAM,YAAY,UAAU;AACtD,WAAO,MAAM;AAAA,EACf;AACA,QAAM,UAAqB,CAAC;AAC5B,QAAM,UAAU;AAChB,SAAO;AACT;AAmBO,IAAM,sBAA8B,OAAO,EAAE,OAAO,MAAM;AAC/D,QAAM,oBAAoB,UAAU,QAAQ,IAAI,yBAAyB;AACzE,QAAM,qBAAqB,UAAU,QAAQ,IAAI,0BAA0B;AA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anthropic-cache.ts", "../src/sticky-session-plugin.ts", "../src/combined-plugin.ts"],
4
+ "sourcesContent": ["import type { Hooks, Plugin } from \"@opencode-ai/plugin\";\n\n// Session and project tracking\nlet currentSessionId = \"\";\nlet projectId = \"\";\nlet isInitialized = false;\nfunction buildUserId() {\n const pid = projectId || \"unknown\";\n const sid = currentSessionId || \"unknown\";\n return `user_${pid}_account__session_${sid}`;\n}\nfunction isJsonContentType(headers: Headers) {\n const ct = headers.get(\"content-type\") || \"\";\n return ct.includes(\"application/json\");\n}\nfunction parseBody(body?: unknown) {\n if (!body) return null;\n if (typeof body === \"string\") return body;\n if (body instanceof Uint8Array) return new TextDecoder().decode(body);\n return null;\n}\ntype CachePayload = {\n metadata?: {\n user_id?: string;\n [key: string]: unknown;\n };\n [key: string]: unknown;\n};\n\n// Create the fetch interceptor that injects metadata.user_id\nfunction createCacheFetch() {\n return async (url: string, init?: RequestInit) => {\n const headers = new Headers(init?.headers);\n const method = (init?.method || \"GET\").toUpperCase();\n if (method !== \"POST\" || !isJsonContentType(headers)) {\n return fetch(url, init);\n }\n const rawBody = parseBody(init?.body);\n if (!rawBody) return fetch(url, init);\n let payload: CachePayload;\n try {\n payload = JSON.parse(rawBody) as CachePayload;\n } catch {\n return fetch(url, init);\n }\n if (payload && typeof payload === \"object\") {\n if (!payload.metadata || typeof payload.metadata !== \"object\") {\n payload.metadata = {};\n }\n const meta = payload.metadata;\n if (meta.user_id == null) {\n meta.user_id = buildUserId();\n }\n }\n headers.delete(\"content-length\");\n return fetch(url, { ...init, headers, body: JSON.stringify(payload) });\n };\n}\n// Shared event handler\nfunction createEventHandler(): Hooks[\"event\"] {\n return async ({ event }) => {\n if (event.type === \"session.created\" || event.type === \"session.updated\") {\n const props = event.properties;\n currentSessionId = props?.info?.id || \"\";\n }\n };\n}\n// Factory to create plugin for a specific provider\nfunction createProviderPlugin(providerName: string): Plugin {\n return async ({ project }) => {\n if (!isInitialized) {\n projectId = project?.id || \"\";\n isInitialized = true;\n }\n return {\n event: createEventHandler(),\n auth: {\n provider: providerName,\n methods: [{ type: \"api\", label: \"key\" }],\n loader: async () => ({\n fetch: createCacheFetch(),\n }),\n },\n };\n };\n}\n// Pre-built plugins for common providers\nexport const FoxcodeAwsCache = createProviderPlugin(\"foxcode-aws\");\nexport const AnthropicCache = createProviderPlugin(\"anthropic\");\nexport const AnthropicUltraCache = createProviderPlugin(\"anthropic-ultra\");\n// Generic factory for custom provider names\nexport const createAnthropicCachePlugin = createProviderPlugin;\nexport default AnthropicCache;\n", "import type { Plugin } from \"@opencode-ai/plugin\";\n\nconst OPENAI_PROVIDER_NPM = \"@ai-sdk/openai\";\nconst SESSION_HEADER_KEYS = [\n \"x-session-id\",\n \"conversation_id\",\n \"session_id\",\n] as const;\n\ntype HeaderMap = Record<string, unknown>;\n\nconst normalize = (value: unknown): string =>\n typeof value === \"string\" ? value.trim() : \"\";\n\nconst pickHeaderSessionValue = (headers: HeaderMap): string => {\n for (const key of SESSION_HEADER_KEYS) {\n const value = normalize(headers[key]);\n if (value) return value;\n }\n return \"\";\n};\n\nconst ensureHeaders = (model: { headers?: unknown }): HeaderMap => {\n if (model.headers && typeof model.headers === \"object\") {\n return model.headers as HeaderMap;\n }\n const headers: HeaderMap = {};\n model.headers = headers;\n return headers;\n};\n\n/**\n * set a session-scoped prompt cache key and session-scoped sticky routing headers for right.codes.\n *\n * Injects HTTP headers via `input.model.headers` so upstream proxies/load\n * balancers can keep a conversation pinned to one account.\n *\n * Headers injected for @ai-sdk/openai providers:\n * - x-session-id\n * - conversation_id\n * - session_id\n *\n * Source of truth (in order):\n * - env: OPENCODE_PROMPT_CACHE_KEY (manual override)\n * - env: OPENCODE_STICKY_SESSION_ID (manual override)\n * - model headers (x-session-id / conversation_id / session_id)\n * - opencode sessionID (default)\n */\nexport const StickySessionPlugin: Plugin = async ({ client }) => {\n const envPromptCacheKey = normalize(process.env.OPENCODE_PROMPT_CACHE_KEY);\n const envStickySessionID = normalize(process.env.OPENCODE_STICKY_SESSION_ID);\n const envOverride = envPromptCacheKey || envStickySessionID;\n const isProviderCodexMap: Record<string, boolean> = {};\n let inited = false;\n const init = async () => {\n if (inited) return;\n const resp = await client.config.providers();\n const providers = resp.data?.providers ?? [];\n for (const provider of providers) {\n isProviderCodexMap[provider.id] = Boolean(provider.options?.isCodex);\n }\n inited = true;\n };\n\n return {\n \"chat.params\": async (input, output) => {\n if (!inited) await init();\n const providerNpm = normalize(input.model.api.npm);\n const isCodex = isProviderCodexMap[input.model.providerID] ?? false;\n if (!providerNpm.includes(OPENAI_PROVIDER_NPM) && !isCodex) return;\n\n const headers = ensureHeaders(input.model);\n const sessionValue =\n envOverride ||\n pickHeaderSessionValue(headers) ||\n normalize(input.sessionID);\n if (!sessionValue) return;\n\n for (const key of SESSION_HEADER_KEYS) {\n headers[key] = sessionValue;\n }\n\n output.options.promptCacheKey = sessionValue;\n if (isCodex && !output.options.instructions) {\n output.options.instructions = \"\";\n }\n },\n };\n};\n\nexport default StickySessionPlugin;\n", "import type { Hooks, Plugin } from \"@opencode-ai/plugin\";\nimport AnthropicCachePlugin from \"./opencode-anthropic-cache\";\nimport { StickySessionPlugin } from \"./sticky-session-plugin\";\n\nconst mergeHook = <TArgs extends unknown[]>(\n first?: (...args: TArgs) => Promise<void>,\n second?: (...args: TArgs) => Promise<void>,\n): ((...args: TArgs) => Promise<void>) | undefined => {\n if (!first) return second;\n if (!second) return first;\n return async (...args: TArgs) => {\n await first(...args);\n await second(...args);\n };\n};\n\nexport const CombinedPlugin: Plugin = async (input) => {\n const stickyHooks = await StickySessionPlugin(input);\n const anthropicHooks = await AnthropicCachePlugin(input);\n\n const merged: Hooks = {\n ...anthropicHooks,\n ...stickyHooks,\n tool: {\n ...(anthropicHooks.tool ?? {}),\n ...(stickyHooks.tool ?? {}),\n },\n \"chat.message\": mergeHook(\n anthropicHooks[\"chat.message\"],\n stickyHooks[\"chat.message\"],\n ),\n \"chat.params\": mergeHook(\n anthropicHooks[\"chat.params\"],\n stickyHooks[\"chat.params\"],\n ),\n \"chat.headers\": mergeHook(\n anthropicHooks[\"chat.headers\"],\n stickyHooks[\"chat.headers\"],\n ),\n \"permission.ask\": mergeHook(\n anthropicHooks[\"permission.ask\"],\n stickyHooks[\"permission.ask\"],\n ),\n \"command.execute.before\": mergeHook(\n anthropicHooks[\"command.execute.before\"],\n stickyHooks[\"command.execute.before\"],\n ),\n \"tool.execute.before\": mergeHook(\n anthropicHooks[\"tool.execute.before\"],\n stickyHooks[\"tool.execute.before\"],\n ),\n \"shell.env\": mergeHook(\n anthropicHooks[\"shell.env\"],\n stickyHooks[\"shell.env\"],\n ),\n \"tool.execute.after\": mergeHook(\n anthropicHooks[\"tool.execute.after\"],\n stickyHooks[\"tool.execute.after\"],\n ),\n \"experimental.chat.messages.transform\": mergeHook(\n anthropicHooks[\"experimental.chat.messages.transform\"],\n stickyHooks[\"experimental.chat.messages.transform\"],\n ),\n \"experimental.chat.system.transform\": mergeHook(\n anthropicHooks[\"experimental.chat.system.transform\"],\n stickyHooks[\"experimental.chat.system.transform\"],\n ),\n \"experimental.session.compacting\": mergeHook(\n anthropicHooks[\"experimental.session.compacting\"],\n stickyHooks[\"experimental.session.compacting\"],\n ),\n \"experimental.text.complete\": mergeHook(\n anthropicHooks[\"experimental.text.complete\"],\n stickyHooks[\"experimental.text.complete\"],\n ),\n \"tool.definition\": mergeHook(\n anthropicHooks[\"tool.definition\"],\n stickyHooks[\"tool.definition\"],\n ),\n event: mergeHook(anthropicHooks.event, stickyHooks.event),\n config: mergeHook(anthropicHooks.config, stickyHooks.config),\n };\n\n if (merged.auth === undefined) {\n merged.auth = anthropicHooks.auth ?? stickyHooks.auth;\n }\n\n return merged;\n};\n\nexport default CombinedPlugin;\n"],
5
+ "mappings": ";AAGA,IAAI,mBAAmB;AACvB,IAAI,YAAY;AAChB,IAAI,gBAAgB;AACpB,SAAS,cAAc;AACrB,QAAM,MAAM,aAAa;AACzB,QAAM,MAAM,oBAAoB;AAChC,SAAO,QAAQ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,OAAO,YAAY,KAAK;AAAA,IACxD,QAAQ,UAAU,eAAe,QAAQ,YAAY,MAAM;AAAA,EAC7D;AAEA,MAAI,OAAO,SAAS,QAAW;AAC7B,WAAO,OAAO,eAAe,QAAQ,YAAY;AAAA,EACnD;AAEA,SAAO;AACT;AAEA,IAAO,0BAAQ;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,8 @@
1
+ import type { Plugin } from "@opencode-ai/plugin";
2
+ declare function createProviderPlugin(providerName: string): Plugin;
3
+ export declare const FoxcodeAwsCache: Plugin;
4
+ export declare const AnthropicCache: Plugin;
5
+ export declare const AnthropicUltraCache: Plugin;
6
+ export declare const createAnthropicCachePlugin: typeof createProviderPlugin;
7
+ export default AnthropicCache;
8
+ //# sourceMappingURL=opencode-anthropic-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencode-anthropic-cache.d.ts","sourceRoot":"","sources":["../src/opencode-anthropic-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAoEzD,iBAAS,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAiB1D;AAED,eAAO,MAAM,eAAe,QAAsC,CAAC;AACnE,eAAO,MAAM,cAAc,QAAoC,CAAC;AAChE,eAAO,MAAM,mBAAmB,QAA0C,CAAC;AAE3E,eAAO,MAAM,0BAA0B,6BAAuB,CAAC;AAC/D,eAAe,cAAc,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { Plugin } from "@opencode-ai/plugin";
2
+ /**
3
+ * set a session-scoped prompt cache key and session-scoped sticky routing headers for right.codes.
4
+ *
5
+ * Injects HTTP headers via `input.model.headers` so upstream proxies/load
6
+ * balancers can keep a conversation pinned to one account.
7
+ *
8
+ * Headers injected for @ai-sdk/openai providers:
9
+ * - x-session-id
10
+ * - conversation_id
11
+ * - session_id
12
+ *
13
+ * Source of truth (in order):
14
+ * - env: OPENCODE_PROMPT_CACHE_KEY (manual override)
15
+ * - env: OPENCODE_STICKY_SESSION_ID (manual override)
16
+ * - model headers (x-session-id / conversation_id / session_id)
17
+ * - opencode sessionID (default)
18
+ */
19
+ export declare const StickySessionPlugin: Plugin;
20
+ export default StickySessionPlugin;
21
+ //# sourceMappingURL=sticky-session-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sticky-session-plugin.d.ts","sourceRoot":"","sources":["../src/sticky-session-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AA+BlD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAwCjC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-fixes-huihui",
3
- "version": "0.1.3",
3
+ "version": "0.1.4-beta.2",
4
4
  "description": "Unified sticky-session plugin for opencode with session headers and prompt cache key.",
5
5
  "type": "module",
6
6
  "private": false,
@@ -19,10 +19,13 @@
19
19
  "README.md"
20
20
  ],
21
21
  "scripts": {
22
+ "clean": "rm -rf dist",
23
+ "lint": "biome check --config-path .biome.json src package.json tsconfig.json",
24
+ "format": "biome format --write --config-path .biome.json src package.json tsconfig.json",
22
25
  "typecheck": "tsc --noEmit",
23
26
  "build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
24
- "build:js": "esbuild index.ts --bundle --platform=node --target=es2022 --format=esm --outfile=dist/index.js --loader:.txt=text --sourcemap",
25
- "build": "npm run build:types && npm run build:js",
27
+ "build:js": "esbuild src/index.ts --bundle --platform=node --target=es2022 --format=esm --outfile=dist/index.js --loader:.txt=text --sourcemap",
28
+ "build": "npm run clean && npm run build:types && npm run build:js",
26
29
  "prepublishOnly": "npm run typecheck && npm run build"
27
30
  },
28
31
  "keywords": [
@@ -46,6 +49,7 @@
46
49
  "node": ">=18"
47
50
  },
48
51
  "devDependencies": {
52
+ "@biomejs/biome": "^2.4.4",
49
53
  "@opencode-ai/plugin": "^1.2.6",
50
54
  "@types/node": "^25.2.3",
51
55
  "esbuild": "^0.27.3",