opencode-with-claude 1.6.14 → 1.6.17
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 +3 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.js +1 -1
- package/dist/logger.d.ts +11 -0
- package/dist/meridian-config.d.ts +49 -0
- package/dist/proxy.d.ts +24 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ npm install -g opencode-with-claude
|
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
40
|
npm install -g @anthropic-ai/claude-code
|
|
41
|
-
claude login
|
|
41
|
+
claude auth login
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
**3. Add to your `opencode.json`**
|
|
@@ -151,6 +151,8 @@ npm install -g @anthropic-ai/claude-code
|
|
|
151
151
|
### "Claude not authenticated"
|
|
152
152
|
|
|
153
153
|
```bash
|
|
154
|
+
claude auth login
|
|
155
|
+
# or (depends of your version)
|
|
154
156
|
claude login
|
|
155
157
|
```
|
|
156
158
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{scrubOpencodeFingerprints as
|
|
1
|
+
import{scrubOpencodeFingerprints as Y}from"@rynfar/meridian-plugin-opencode-scrub";var M=/authenticat|credentials|expired|not logged in|exit(?:ed)? with code|crash|unhealthy|401|402|billing|subscription/i,N=/rate.limit|429|overloaded|503|stale.session|timeout|timed out/i;function x(e){return(r,n)=>e.app.log({body:{service:"opencode-with-claude",level:r,message:n}})}function L(e){return M.test(e)?"error":N.test(e)?"warn":"debug"}import{existsSync as _,readFileSync as H}from"fs";import{homedir as U}from"os";import{join as v}from"path";var w=()=>v(U(),".config","meridian"),R=()=>v(w(),"profiles.json"),S=()=>v(w(),"settings.json");function m(e,r){e?.("warn","[opencode-with-claude] ".concat(r))}function E(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function I(e,r,n){if(!Array.isArray(e))return m(n,"".concat(r," must be a JSON array of profile objects; got ").concat(typeof e,". Ignoring.")),[];let t=[];for(let o of e){if(!E(o)||typeof o.id!="string"||!o.id){m(n,"".concat(r,': dropping profile without a string "id" field.'));continue}let i={id:o.id};(o.type==="claude-max"||o.type==="api")&&(i.type=o.type),typeof o.claudeConfigDir=="string"&&(i.claudeConfigDir=o.claudeConfigDir),typeof o.apiKey=="string"&&(i.apiKey=o.apiKey),typeof o.baseUrl=="string"&&(i.baseUrl=o.baseUrl),t.push(i)}return t}function C(e,r){if(_(e))try{return JSON.parse(H(e,"utf8"))}catch(n){let t=n instanceof Error?n.message:String(n);m(r,"failed to parse ".concat(e,": ").concat(t));return}}function j(e){let r=process.env.MERIDIAN_PROFILES;if(r)try{return I(JSON.parse(r),"MERIDIAN_PROFILES",e)}catch(n){let t=n instanceof Error?n.message:String(n);m(e,"failed to parse MERIDIAN_PROFILES env var: ".concat(t));return}}function W(e){let r=C(R(),e);return r===void 0?[]:I(r,R(),e)}function J(e){let r=C(S(),e);if(!E(r))return;let n=r.activeProfile;if(n!==void 0){if(typeof n!="string"||!n){m(e,"".concat(S(),': "activeProfile" must be a non-empty string; ignoring.'));return}return n}}function b(e){let r=[],n="none",t=j(e);if(t)r=t,n="env";else{let f=W(e);f.length>0&&(r=f,n="disk")}let o,i="none",g=process.env.MERIDIAN_DEFAULT_PROFILE?.trim();if(g)o=g,i="env";else{let f=J(e);f&&(o=f,i="disk")}return o&&r.length>0&&!r.some(f=>f.id===o)&&(m(e,'default profile "'.concat(o,'" (from ').concat(i,") not found among configured profiles; ignoring.")),o=void 0,i="none"),{profiles:r,defaultProfile:o,sources:{profiles:n,defaultProfile:i}}}function k(e){if(e.profiles.length===0)return;let r=e.profiles.map(i=>i.id).join(", "),n=e.defaultProfile??e.profiles[0]?.id,t=e.sources.profiles,o=e.sources.defaultProfile==="none"?"first":e.sources.defaultProfile;return"loaded ".concat(e.profiles.length," meridian profile(s) from ").concat(t,": ").concat(r," (active: ").concat(n," [").concat(o,"])")}import{startProxyServer as G}from"@rynfar/meridian";process.env.MERIDIAN_PASSTHROUGH??="true";var K=process.platform==="win32",F=3456,A="127.0.0.1";function z(e){return e.includes(":")&&!e.startsWith("[")?"[".concat(e,"]"):e}function h(){let e=process.env.MERIDIAN_HOST?.trim()||process.env.CLAUDE_PROXY_HOST?.trim()||A;return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e}function X(e=h()){return e==="0.0.0.0"?A:e==="::"||e==="[::]"?"::1":e}function D(e,r=h()){return"http://".concat(z(X(r)),":").concat(e)}async function $(e){let{port:r=F,log:n,profiles:t,defaultProfile:o}=e,i=h(),g=console.error;console.error=(...c)=>{let a=c.map(String).join(" ");if(a.startsWith("[PROXY]")){n?.(L(a),a);return}g.apply(console,c)};let f=c=>new Promise((a,y)=>{G({port:c,host:i,silent:!0,profiles:t,defaultProfile:o}).then(p=>{let P=T=>{y(T)};p.server.once("error",P),p.server.listening?(p.server.removeListener("error",P),a(p)):p.server.once("listening",()=>{p.server.removeListener("error",P),a(p)})},y)}),l=async c=>{try{return await f(c)}catch(a){if(c!==0&&a instanceof Error&&"code"in a&&a.code==="EADDRINUSE")return n?.("info","Port ".concat(c," in use, starting on a random port instead...")),f(0);throw a}},s;try{s=await l(typeof r=="string"?parseInt(r,10):r)}catch(c){throw console.error=g,c}let u=s.server.address()?.port??s.config?.port??F;return n?.("info","Claude Max proxy running on port ".concat(u)),{port:u,close:async()=>{console.error=g,await s.close()}}}function O(e){let r=!1,n=()=>{r||(r=!0,e.close())};process.on("exit",n),process.on("SIGINT",n),K||process.on("SIGTERM",n)}var ae=async({client:e})=>{let r=x(e),n=new Map,t=b(r),o=k(t);o&&r("info",o);let i=process.env.CLAUDE_PROXY_PORT||3456,g=await $({port:i,log:r,profiles:t.profiles,defaultProfile:t.defaultProfile}),f=D(g.port);return r("info","proxy ready at ".concat(f)),O(g),{async config(l){for(let[d,u]of Object.entries(l.agent??{}))u?.mode&&n.set(d.toLowerCase(),u.mode);let s=l.provider?.anthropic;s&&((s.options??={}).baseURL=f)},async"experimental.chat.system.transform"(l,s){if(l.model.providerID!=="anthropic")return;let d=s.system.join("\n\n"),u=Y(d);u!==d&&s.system.splice(0,s.system.length,u)},async"chat.headers"(l,s){if(l.model.providerID!=="anthropic")return;delete s.headers["anthropic-beta"];let d=l.agent,u=typeof d=="object"&&d!==null,c=u?d.name:d,a=String(c??"unknown").replace(/[^\x20-\x7E]/g,"").trim()||"unknown",y=u&&typeof d.mode=="string"?d.mode:n.get(a.toLowerCase())??"primary";s.headers["x-opencode-session"]=l.sessionID,s.headers["x-opencode-request"]=l.message.id,s.headers["x-opencode-agent-mode"]=y,s.headers["x-opencode-agent-name"]=a}}};export{ae as ClaudeMaxPlugin};
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin } from "@opencode-ai/plugin";
|
|
2
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
3
|
+
export type LogFn = (level: LogLevel, message: string) => Promise<unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* Create a logger bound to the plugin's client.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createLogger(client: Parameters<Plugin>[0]["client"]): LogFn;
|
|
8
|
+
/**
|
|
9
|
+
* Classify a proxy log message into a log level.
|
|
10
|
+
*/
|
|
11
|
+
export declare function classifyProxyLog(msg: string): LogLevel;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load Meridian proxy configuration from disk so the plugin can forward
|
|
3
|
+
* it to `startProxyServer({ profiles, defaultProfile })`.
|
|
4
|
+
*
|
|
5
|
+
* Meridian's own CLI calls `enableDiskProfileDiscovery()` before starting
|
|
6
|
+
* the server, but that function is not re-exported from `@rynfar/meridian`'s
|
|
7
|
+
* public entry point and its private module has a hash-suffixed filename
|
|
8
|
+
* that drifts between releases. Instead we read the same files Meridian's
|
|
9
|
+
* CLI reads (`~/.config/meridian/profiles.json` and `settings.json`) and
|
|
10
|
+
* pass them through the supported `ProxyConfig` API.
|
|
11
|
+
*
|
|
12
|
+
* Precedence matches Meridian's CLI:
|
|
13
|
+
* profiles: MERIDIAN_PROFILES env var > profiles.json > []
|
|
14
|
+
* defaultProfile: MERIDIAN_DEFAULT_PROFILE > settings.activeProfile > undefined
|
|
15
|
+
*
|
|
16
|
+
* This is a leaf module — no imports from proxy.ts or index.ts.
|
|
17
|
+
*/
|
|
18
|
+
import type { LogFn } from "./logger.ts";
|
|
19
|
+
export type ProfileType = "claude-max" | "api";
|
|
20
|
+
export interface ProfileConfig {
|
|
21
|
+
/** Unique profile identifier (e.g. "personal", "work") */
|
|
22
|
+
id: string;
|
|
23
|
+
/** Auth type — "claude-max" uses CLAUDE_CONFIG_DIR, "api" uses ANTHROPIC_API_KEY */
|
|
24
|
+
type?: ProfileType;
|
|
25
|
+
/** Path to .claude config directory (claude-max profiles) */
|
|
26
|
+
claudeConfigDir?: string;
|
|
27
|
+
/** Anthropic API key (api profiles) */
|
|
28
|
+
apiKey?: string;
|
|
29
|
+
/** Anthropic base URL override (api profiles) */
|
|
30
|
+
baseUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface MeridianConfigResult {
|
|
33
|
+
profiles: ProfileConfig[];
|
|
34
|
+
defaultProfile?: string;
|
|
35
|
+
sources: {
|
|
36
|
+
profiles: "env" | "disk" | "none";
|
|
37
|
+
defaultProfile: "env" | "disk" | "none";
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Load profiles + default profile from disk/env with CLI-parity precedence.
|
|
42
|
+
* Never throws; all I/O and parse errors funnel through `log`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function loadMeridianConfig(log?: LogFn): MeridianConfigResult;
|
|
45
|
+
/**
|
|
46
|
+
* Build a short, human-readable summary of the loaded config for logging.
|
|
47
|
+
* Returns `undefined` when nothing was loaded (so callers can skip the log).
|
|
48
|
+
*/
|
|
49
|
+
export declare function summarizeMeridianConfig(cfg: MeridianConfigResult): string | undefined;
|
package/dist/proxy.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type LogFn } from "./logger.ts";
|
|
2
|
+
import type { ProfileConfig } from "./meridian-config.ts";
|
|
3
|
+
export interface StartProxyOptions {
|
|
4
|
+
port?: string | number;
|
|
5
|
+
log: LogFn | undefined;
|
|
6
|
+
/** Named auth profiles forwarded to Meridian's ProxyConfig. */
|
|
7
|
+
profiles?: ProfileConfig[];
|
|
8
|
+
/** Default profile id when no x-meridian-profile header is sent. */
|
|
9
|
+
defaultProfile?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ProxyHandle {
|
|
12
|
+
port: string | number;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare function getProxyHost(): string;
|
|
16
|
+
export declare function getProxyConnectHost(host?: string): string;
|
|
17
|
+
export declare function getProxyBaseURL(port: string | number, host?: string): string;
|
|
18
|
+
export declare function startProxy(opts: StartProxyOptions): Promise<ProxyHandle>;
|
|
19
|
+
export interface HealthResult {
|
|
20
|
+
ok: boolean;
|
|
21
|
+
message?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function checkProxyHealth(port: string | number, log: LogFn | undefined): Promise<HealthResult>;
|
|
24
|
+
export declare function registerCleanup(proxy: ProxyHandle): void;
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-with-claude",
|
|
3
3
|
"description": "OpenCode plugin to use your Claude Max subscription via Meridian proxy",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.17",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@rynfar/meridian": "^1.
|
|
9
|
+
"@rynfar/meridian": "^1.45.0",
|
|
10
10
|
"@rynfar/meridian-plugin-opencode-scrub": "^0.2.0"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@opencode-ai/plugin": "^1.17.
|
|
14
|
-
"@types/node": "^26.
|
|
13
|
+
"@opencode-ai/plugin": "^1.17.17",
|
|
14
|
+
"@types/node": "^26.1.1",
|
|
15
15
|
"tsup": "^8.5.1",
|
|
16
|
-
"typescript": "^
|
|
16
|
+
"typescript": "^7.0.2"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "tsup",
|
|
19
|
+
"build": "tsup && tsc",
|
|
20
20
|
"test": "./test/run.sh",
|
|
21
21
|
"test:unit": "npm run build && node --experimental-strip-types --test test/unit/*.test.mjs",
|
|
22
22
|
"test:clean": "./test/run.sh --clean",
|