opencode-with-claude 1.6.17 → 1.7.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 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 h}from"path";var w=()=>h(U(),".config","meridian"),R=()=>h(w(),"profiles.json"),S=()=>h(w(),"settings.json");function m(e,r){e?.("warn","[opencode-with-claude] ".concat(r))}function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function E(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 i=[];for(let o of e){if(!k(o)||typeof o.id!="string"||!o.id){m(n,"".concat(r,': dropping profile without a string "id" field.'));continue}let t={id:o.id};(o.type==="claude-max"||o.type==="api"||o.type==="oauth-token")&&(t.type=o.type),typeof o.claudeConfigDir=="string"&&(t.claudeConfigDir=o.claudeConfigDir),typeof o.apiKey=="string"&&(t.apiKey=o.apiKey),typeof o.baseUrl=="string"&&(t.baseUrl=o.baseUrl),typeof o.oauthToken=="string"&&(t.oauthToken=o.oauthToken),i.push(t)}return i}function I(e,r){if(_(e))try{return JSON.parse(H(e,"utf8"))}catch(n){let i=n instanceof Error?n.message:String(n);m(r,"failed to parse ".concat(e,": ").concat(i));return}}function j(e){let r=process.env.MERIDIAN_PROFILES;if(r)try{return E(JSON.parse(r),"MERIDIAN_PROFILES",e)}catch(n){let i=n instanceof Error?n.message:String(n);m(e,"failed to parse MERIDIAN_PROFILES env var: ".concat(i));return}}function W(e){let r=I(R(),e);return r===void 0?[]:E(r,R(),e)}function J(e){let r=I(S(),e);if(!k(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 C(e){let r=[],n="none",i=j(e);if(i)r=i,n="env";else{let f=W(e);f.length>0&&(r=f,n="disk")}let o,t="none",g=process.env.MERIDIAN_DEFAULT_PROFILE?.trim();if(g)o=g,t="env";else{let f=J(e);f&&(o=f,t="disk")}return o&&r.length>0&&!r.some(f=>f.id===o)&&(m(e,'default profile "'.concat(o,'" (from ').concat(t,") not found among configured profiles; ignoring.")),o=void 0,t="none"),{profiles:r,defaultProfile:o,sources:{profiles:n,defaultProfile:t}}}function b(e){if(e.profiles.length===0)return;let r=e.profiles.map(t=>t.id).join(", "),n=e.defaultProfile??e.profiles[0]?.id,i=e.sources.profiles,o=e.sources.defaultProfile==="none"?"first":e.sources.defaultProfile;return"loaded ".concat(e.profiles.length," meridian profile(s) from ").concat(i,": ").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 v(){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=v()){return e==="0.0.0.0"?A:e==="::"||e==="[::]"?"::1":e}function D(e,r=v()){return"http://".concat(z(X(r)),":").concat(e)}async function $(e){let{port:r=F,log:n,profiles:i,defaultProfile:o}=e,t=v(),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:t,silent:!0,profiles:i,defaultProfile:o}).then(p=>{let P=O=>{y(O)};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 T(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,i=C(r),o=b(i);o&&r("info",o);let t=process.env.CLAUDE_PROXY_PORT||3456,g=await $({port:t,log:r,profiles:i.profiles,defaultProfile:i.defaultProfile}),f=D(g.port);return r("info","proxy ready at ".concat(f)),T(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};
@@ -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/package.json CHANGED
@@ -1,16 +1,16 @@
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.17",
4
+ "version": "1.7.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.45.0",
9
+ "@rynfar/meridian": "^1.55.1",
10
10
  "@rynfar/meridian-plugin-opencode-scrub": "^0.2.0"
11
11
  },
12
12
  "devDependencies": {
13
- "@opencode-ai/plugin": "^1.17.17",
13
+ "@opencode-ai/plugin": "^1.18.3",
14
14
  "@types/node": "^26.1.1",
15
15
  "tsup": "^8.5.1",
16
16
  "typescript": "^7.0.2"