opencode-with-claude 1.6.18 → 1.8.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
@@ -74,8 +74,9 @@ without leaving OpenCode.
74
74
 
75
75
  ### Profiles (`~/.config/meridian/profiles.json`)
76
76
 
77
- Define one or more named profiles (for example, a personal Claude Max account
78
- and a work account). The plugin forwards them to Meridian at startup.
77
+ Define one or more named profiles (for example, a personal Claude Max account,
78
+ a work account, or an OAuth-token profile). The plugin forwards them to Meridian
79
+ at startup.
79
80
 
80
81
  ```json
81
82
  [
@@ -86,6 +87,11 @@ and a work account). The plugin forwards them to Meridian at startup.
86
87
  {
87
88
  "id": "work",
88
89
  "claudeConfigDir": "/Users/me/.config/meridian/profiles/work"
90
+ },
91
+ {
92
+ "id": "headless",
93
+ "type": "oauth-token",
94
+ "oauthToken": "<token from claude setup-token>"
89
95
  }
90
96
  ]
91
97
  ```
package/dist/index.js CHANGED
@@ -1 +1 @@
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};
1
+ import{scrubOpencodeFingerprints as ie}from"@rynfar/meridian-plugin-opencode-scrub";var H=/authenticat|credentials|expired|not logged in|exit(?:ed)? with code|crash|unhealthy|401|402|billing|subscription/i,j=/rate.limit|429|overloaded|503|stale.session|timeout|timed out/i;function x(e){return(n,r)=>e.app.log({body:{service:"opencode-with-claude",level:n,message:r}})}function S(e){return H.test(e)?"error":j.test(e)?"warn":"debug"}import{existsSync as q,readFileSync as W}from"fs";import{homedir as J}from"os";import{join as v}from"path";var b=()=>v(J(),".config","meridian"),k=()=>v(b(),"profiles.json"),L=()=>v(b(),"settings.json");function m(e,n){e?.("warn","[opencode-with-claude] ".concat(n))}function E(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function I(e,n,r){if(!Array.isArray(e))return m(r,"".concat(n," 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(r,"".concat(n,': dropping profile without a string "id" field.'));continue}let i={id:o.id};(o.type==="claude-max"||o.type==="api"||o.type==="oauth-token")&&(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),typeof o.oauthToken=="string"&&(i.oauthToken=o.oauthToken),t.push(i)}return t}function C(e,n){if(q(e))try{return JSON.parse(W(e,"utf8"))}catch(r){let t=r instanceof Error?r.message:String(r);m(n,"failed to parse ".concat(e,": ").concat(t));return}}function G(e){let n=process.env.MERIDIAN_PROFILES;if(n)try{return I(JSON.parse(n),"MERIDIAN_PROFILES",e)}catch(r){let t=r instanceof Error?r.message:String(r);m(e,"failed to parse MERIDIAN_PROFILES env var: ".concat(t));return}}function K(e){let n=C(k(),e);return n===void 0?[]:I(n,k(),e)}function z(e){let n=C(L(),e);if(!E(n))return;let r=n.activeProfile;if(r!==void 0){if(typeof r!="string"||!r){m(e,"".concat(L(),': "activeProfile" must be a non-empty string; ignoring.'));return}return r}}function F(e){let n=[],r="none",t=G(e);if(t)n=t,r="env";else{let s=K(e);s.length>0&&(n=s,r="disk")}let o,i="none",d=process.env.MERIDIAN_DEFAULT_PROFILE?.trim();if(d)o=d,i="env";else{let s=z(e);s&&(o=s,i="disk")}return o&&n.length>0&&!n.some(s=>s.id===o)&&(m(e,'default profile "'.concat(o,'" (from ').concat(i,") not found among configured profiles; ignoring.")),o=void 0,i="none"),{profiles:n,defaultProfile:o,sources:{profiles:r,defaultProfile:i}}}function A(e){if(e.profiles.length===0)return;let n=e.profiles.map(i=>i.id).join(", "),r=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(n," (active: ").concat(r," [").concat(o,"])")}import{existsSync as X,readFileSync as Y}from"fs";import{createRequire as B}from"module";import{dirname as $,join as V}from"path";import{startProxyServer as Q}from"@rynfar/meridian";process.env.MERIDIAN_PASSTHROUGH??="true";var Z=process.platform==="win32",D=3456,T="127.0.0.1",O="@rynfar/meridian";function ee(){try{let e=$(B(import.meta.url).resolve(O));for(let n=0;n<5;n++){let r=V(e,"package.json");if(X(r)){let o=JSON.parse(Y(r,"utf8"));if(o.name===O&&typeof o.version=="string")return o.version}let t=$(e);if(t===e)break;e=t}return}catch{return}}function ne(e){return e.includes(":")&&!e.startsWith("[")?"[".concat(e,"]"):e}function h(){let e=process.env.MERIDIAN_HOST?.trim()||process.env.CLAUDE_PROXY_HOST?.trim()||T;return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e}function re(e=h()){return e==="0.0.0.0"?T:e==="::"||e==="[::]"?"::1":e}function R(e,n=h()){return"http://".concat(ne(re(n)),":").concat(e)}async function N(e){let{port:n=D,log:r,profiles:t,defaultProfile:o}=e,i=h(),d=ee(),s=console.error;console.error=(...c)=>{let u=c.map(String).join(" ");if(u.startsWith("[PROXY]")){r?.(S(u),u);return}s.apply(console,c)};let f=c=>new Promise((u,w)=>{Q({port:c,host:i,silent:!0,profiles:t,defaultProfile:o,version:d}).then(g=>{let P=_=>{w(_)};g.server.once("error",P),g.server.listening?(g.server.removeListener("error",P),u(g)):g.server.once("listening",()=>{g.server.removeListener("error",P),u(g)})},w)}),l=async c=>{try{return await f(c)}catch(u){if(c!==0&&u instanceof Error&&"code"in u&&u.code==="EADDRINUSE")return r?.("info","Port ".concat(c," in use, starting on a random port instead...")),f(0);throw u}},a;try{a=await l(typeof n=="string"?parseInt(n,10):n)}catch(c){throw console.error=s,c}let y=a.server.address()?.port??a.config?.port??D;return r?.("info","Claude Max proxy running on port ".concat(y)),{port:y,close:async()=>{console.error=s,await a.close()}}}function oe(e){if(typeof e!="object"||e===null)return{};let n=e,r={};return typeof n.daysUntilRenewal=="number"&&Number.isFinite(n.daysUntilRenewal)&&(r.daysUntilRenewal=n.daysUntilRenewal),typeof n.renewalRequiredSoon=="boolean"&&(r.renewalRequiredSoon=n.renewalRequiredSoon),r}function te(e){return e===void 0?"soon":e<=0?"today":e===1?"in 1 day":"in ".concat(e," days")}async function U(e,n){try{let r=await fetch(R(e)+"/health",{signal:AbortSignal.timeout(5e3)}),t=await r.json(),o=t.version,i=typeof o=="string"&&o!=="unknown"?o:void 0,d=oe(t.auth);if(i&&n?.("info","[claude-max] meridian ".concat(i)),d.renewalRequiredSoon&&n?.("warn","[claude-max] Claude login expires ".concat(te(d.daysUntilRenewal),". Run 'claude login' to renew \u2014 the proxy cannot refresh it for you.")),t.status==="healthy")return{ok:!0,version:i,...d};if(t.status==="degraded"){let f=typeof t.error=="string"?t.error:"Could not verify auth status";return n?.("warn","[claude-max] ".concat(f,". Requests may still work \u2014 if they hang, try running 'claude login' in your terminal.")),{ok:!0,message:f,version:i,...d}}let s=typeof t.error=="string"?t.error:"Proxy health check returned status: ".concat(t.status??r.status);return n?.("error","[claude-max] ".concat(s)),{ok:!1,message:s,version:i,...d}}catch(r){let t=r instanceof Error?r.message:String(r);return n?.("error","[claude-max] Health check failed: ".concat(t)),{ok:!1,message:"Health check failed: ".concat(t)}}}function M(e){let n=!1,r=()=>{n||(n=!0,e.close())};process.on("exit",r),process.on("SIGINT",r),Z||process.on("SIGTERM",r)}var we=async({client:e})=>{let n=x(e),r=new Map,t=F(n),o=A(t);o&&n("info",o);let i=process.env.CLAUDE_PROXY_PORT||3456,d=await N({port:i,log:n,profiles:t.profiles,defaultProfile:t.defaultProfile}),s=R(d.port);return n("info","proxy ready at ".concat(s)),M(d),U(d.port,n),{async config(f){for(let[a,p]of Object.entries(f.agent??{}))p?.mode&&r.set(a.toLowerCase(),p.mode);let l=f.provider?.anthropic;l&&((l.options??={}).baseURL=s)},async"experimental.chat.system.transform"(f,l){if(f.model.providerID!=="anthropic")return;let a=l.system.join("\n\n"),p=ie(a);p!==a&&l.system.splice(0,l.system.length,p)},async"chat.headers"(f,l){if(f.model.providerID!=="anthropic")return;delete l.headers["anthropic-beta"];let a=f.agent,p=typeof a=="object"&&a!==null,y=p?a.name:a,c=String(y??"unknown").replace(/[^\x20-\x7E]/g,"").trim()||"unknown",u=p&&typeof a.mode=="string"?a.mode:r.get(c.toLowerCase())??"primary";l.headers["x-opencode-session"]=f.sessionID,l.headers["x-opencode-request"]=f.message.id,l.headers["x-opencode-agent-mode"]=u,l.headers["x-opencode-agent-name"]=c}}};export{we as ClaudeMaxPlugin};
@@ -16,11 +16,14 @@
16
16
  * This is a leaf module — no imports from proxy.ts or index.ts.
17
17
  */
18
18
  import type { LogFn } from "./logger.ts";
19
- export type ProfileType = "claude-max" | "api";
19
+ export type ProfileType = "claude-max" | "api" | "oauth-token";
20
20
  export interface ProfileConfig {
21
21
  /** Unique profile identifier (e.g. "personal", "work") */
22
22
  id: string;
23
- /** Auth type — "claude-max" uses CLAUDE_CONFIG_DIR, "api" uses ANTHROPIC_API_KEY */
23
+ /**
24
+ * Auth type — "claude-max" uses CLAUDE_CONFIG_DIR, "api" uses ANTHROPIC_API_KEY,
25
+ * "oauth-token" uses a long-lived OAuth token from `claude setup-token`.
26
+ */
24
27
  type?: ProfileType;
25
28
  /** Path to .claude config directory (claude-max profiles) */
26
29
  claudeConfigDir?: string;
@@ -28,6 +31,8 @@ export interface ProfileConfig {
28
31
  apiKey?: string;
29
32
  /** Anthropic base URL override (api profiles) */
30
33
  baseUrl?: string;
34
+ /** Long-lived OAuth token from `claude setup-token` (oauth-token profiles) */
35
+ oauthToken?: string;
31
36
  }
32
37
  export interface MeridianConfigResult {
33
38
  profiles: ProfileConfig[];
package/dist/proxy.d.ts CHANGED
@@ -12,6 +12,22 @@ export interface ProxyHandle {
12
12
  port: string | number;
13
13
  close(): Promise<void>;
14
14
  }
15
+ /**
16
+ * Read the installed Meridian version so it can be handed to
17
+ * `startProxyServer({ version })`.
18
+ *
19
+ * Meridian falls back to the literal string `"unknown"` on /health unless the
20
+ * host passes this in: its CLI reads its own package.json, but a library
21
+ * consumer such as this plugin has to do the same. Without it, /health, the
22
+ * dashboard, and any external monitor all report `"unknown"`.
23
+ *
24
+ * The manifest cannot be resolved as a subpath — Meridian's `exports` map only
25
+ * declares `"."`, so `require.resolve("@rynfar/meridian/package.json")` throws
26
+ * ERR_PACKAGE_PATH_NOT_EXPORTED. Resolve the entry point instead and walk up to
27
+ * the owning package root. Returns undefined if anything is unexpected, which
28
+ * simply leaves Meridian's own fallback in place.
29
+ */
30
+ export declare function resolveMeridianVersion(): string | undefined;
15
31
  export declare function getProxyHost(): string;
16
32
  export declare function getProxyConnectHost(host?: string): string;
17
33
  export declare function getProxyBaseURL(port: string | number, host?: string): string;
@@ -19,6 +35,12 @@ export declare function startProxy(opts: StartProxyOptions): Promise<ProxyHandle
19
35
  export interface HealthResult {
20
36
  ok: boolean;
21
37
  message?: string;
38
+ /** Meridian version behind the proxy. Absent on releases that omit it. */
39
+ version?: string;
40
+ /** Days until the Claude login itself expires, when Meridian reports it. */
41
+ daysUntilRenewal?: number;
42
+ /** True when Meridian flags the login as needing renewal soon. */
43
+ renewalRequiredSoon?: boolean;
22
44
  }
23
45
  export declare function checkProxyHealth(port: string | number, log: LogFn | undefined): Promise<HealthResult>;
24
46
  export declare function registerCleanup(proxy: ProxyHandle): void;
package/package.json CHANGED
@@ -1,12 +1,12 @@
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.18",
4
+ "version": "1.8.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "dependencies": {
9
- "@rynfar/meridian": "^1.50.0",
9
+ "@rynfar/meridian": "^1.60.0",
10
10
  "@rynfar/meridian-plugin-opencode-scrub": "^0.2.0"
11
11
  },
12
12
  "devDependencies": {