opencode-with-claude 1.6.5 → 1.6.7

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
@@ -108,6 +108,10 @@ without restarting the proxy. The plugin does not need to do anything special
108
108
  for it to work — just edit the file and the next request picks it up. See
109
109
  Meridian's documentation for the full list of adapter keys.
110
110
 
111
+ This plugin keeps Meridian's client prompt pass-through enabled, but strips
112
+ OpenCode's built-in system prompt before forwarding. OpenCode-assembled context
113
+ such as cwd, `AGENTS.md`, and configured instructions is preserved.
114
+
111
115
  ```json
112
116
  {
113
117
  "opencode": {
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var _=/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 h(e){return(r,n)=>e.app.log({body:{service:"opencode-with-claude",level:r,message:n}})}function R(e){return _.test(e)?"error":N.test(e)?"warn":"debug"}import{existsSync as M,readFileSync as H}from"fs";import{homedir as U}from"os";import{join as P}from"path";var E=()=>P(U(),".config","meridian"),L=()=>P(E(),"profiles.json"),S=()=>P(E(),"settings.json");function p(e,r){e?.("warn","[opencode-with-claude] ".concat(r))}function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function w(e,r,n){if(!Array.isArray(e))return p(n,"".concat(r," must be a JSON array of profile objects; got ").concat(typeof e,". Ignoring.")),[];let s=[];for(let o of e){if(!I(o)||typeof o.id!="string"||!o.id){p(n,"".concat(r,': dropping profile without a string "id" field.'));continue}let t={id:o.id};(o.type==="claude-max"||o.type==="api")&&(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),s.push(t)}return s}function C(e,r){if(M(e))try{return JSON.parse(H(e,"utf8"))}catch(n){let s=n instanceof Error?n.message:String(n);p(r,"failed to parse ".concat(e,": ").concat(s));return}}function j(e){let r=process.env.MERIDIAN_PROFILES;if(r)try{return w(JSON.parse(r),"MERIDIAN_PROFILES",e)}catch(n){let s=n instanceof Error?n.message:String(n);p(e,"failed to parse MERIDIAN_PROFILES env var: ".concat(s));return}}function W(e){let r=C(L(),e);return r===void 0?[]:w(r,L(),e)}function J(e){let r=C(S(),e);if(!I(r))return;let n=r.activeProfile;if(n!==void 0){if(typeof n!="string"||!n){p(e,"".concat(S(),': "activeProfile" must be a non-empty string; ignoring.'));return}return n}}function k(e){let r=[],n="none",s=j(e);if(s)r=s,n="env";else{let i=W(e);i.length>0&&(r=i,n="disk")}let o,t="none",c=process.env.MERIDIAN_DEFAULT_PROFILE?.trim();if(c)o=c,t="env";else{let i=J(e);i&&(o=i,t="disk")}return o&&r.length>0&&!r.some(i=>i.id===o)&&(p(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 F(e){if(e.profiles.length===0)return;let r=e.profiles.map(t=>t.id).join(", "),n=e.defaultProfile??e.profiles[0]?.id,s=e.sources.profiles,o=e.sources.defaultProfile==="none"?"first":e.sources.defaultProfile;return"loaded ".concat(e.profiles.length," meridian profile(s) from ").concat(s,": ").concat(r," (active: ").concat(n," [").concat(o,"])")}import{startProxyServer as G}from"@rynfar/meridian";process.env.MERIDIAN_PASSTHROUGH??="true";var K=process.platform==="win32",A=3456,D="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()||D;return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e}function X(e=v()){return e==="0.0.0.0"?D:e==="::"||e==="[::]"?"::1":e}function b(e,r=v()){return"http://".concat(z(X(r)),":").concat(e)}async function $(e){let{port:r=A,log:n,profiles:s,defaultProfile:o}=e,t=v(),c=console.error;console.error=(...a)=>{let f=a.map(String).join(" ");if(f.startsWith("[PROXY]")){n?.(R(f),f);return}c.apply(console,a)};let i=a=>new Promise((f,x)=>{G({port:a,host:t,silent:!0,profiles:s,defaultProfile:o}).then(u=>{let y=T=>{x(T)};u.server.once("error",y),u.server.listening?(u.server.removeListener("error",y),f(u)):u.server.once("listening",()=>{u.server.removeListener("error",y),f(u)})},x)}),d=async a=>{try{return await i(a)}catch(f){if(a!==0&&f instanceof Error&&"code"in f&&f.code==="EADDRINUSE")return n?.("info","Port ".concat(a," in use, starting on a random port instead...")),i(0);throw f}},l;try{l=await d(typeof r=="string"?parseInt(r,10):r)}catch(a){throw console.error=c,a}let g=l.server.address()?.port??l.config?.port??A;return n?.("info","Claude Max proxy running on port ".concat(g)),{port:g,close:async()=>{console.error=c,await l.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 ie=async({client:e})=>{let r=h(e),n=k(r),s=F(n);s&&r("info",s);let o=process.env.CLAUDE_PROXY_PORT||3456,t=await $({port:o,log:r,profiles:n.profiles,defaultProfile:n.defaultProfile}),c=b(t.port);return r("info","proxy ready at ".concat(c)),O(t),{async config(i){let d=i.provider?.anthropic;d&&((d.options??={}).baseURL=c)},async"chat.headers"(i,d){if(i.model.providerID!=="anthropic")return;delete d.headers["anthropic-beta"];let l=i.agent,m=typeof l=="object"&&l!==null?l:void 0,g=m?.name??String(l??"unknown"),a=m?.mode??"primary";d.headers["x-opencode-session"]=i.sessionID,d.headers["x-opencode-request"]=i.message.id,d.headers["x-opencode-agent-mode"]=a,d.headers["x-opencode-agent-name"]=g.replace(/[^\x20-\x7E]/g,"").trim()||"unknown"}}};export{ie as ClaudeMaxPlugin};
1
+ var M=/authenticat|credentials|expired|not logged in|exit(?:ed)? with code|crash|unhealthy|401|402|billing|subscription/i,U=/rate.limit|429|overloaded|503|stale.session|timeout|timed out/i;function R(e){return(r,n)=>e.app.log({body:{service:"opencode-with-claude",level:r,message:n}})}function E(e){return M.test(e)?"error":U.test(e)?"warn":"debug"}import{existsSync as w,readFileSync as H,renameSync as j,writeFileSync as J}from"fs";import{homedir as W}from"os";import{join as y}from"path";var v=()=>y(W(),".config","meridian"),I=()=>y(v(),"profiles.json"),C=()=>y(v(),"settings.json"),K=()=>y(v(),"sdk-features.json");function l(e,r){e?.("warn","[opencode-with-claude] ".concat(r))}function m(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function F(e,r,n){if(!Array.isArray(e))return l(n,"".concat(r," must be a JSON array of profile objects; got ").concat(typeof e,". Ignoring.")),[];let s=[];for(let t of e){if(!m(t)||typeof t.id!="string"||!t.id){l(n,"".concat(r,': dropping profile without a string "id" field.'));continue}let i={id:t.id};(t.type==="claude-max"||t.type==="api")&&(i.type=t.type),typeof t.claudeConfigDir=="string"&&(i.claudeConfigDir=t.claudeConfigDir),typeof t.apiKey=="string"&&(i.apiKey=t.apiKey),typeof t.baseUrl=="string"&&(i.baseUrl=t.baseUrl),s.push(i)}return s}function x(e,r){if(w(e))try{return JSON.parse(H(e,"utf8"))}catch(n){let s=n instanceof Error?n.message:String(n);l(r,"failed to parse ".concat(e,": ").concat(s));return}}function G(e){let r=process.env.MERIDIAN_PROFILES;if(r)try{return F(JSON.parse(r),"MERIDIAN_PROFILES",e)}catch(n){let s=n instanceof Error?n.message:String(n);l(e,"failed to parse MERIDIAN_PROFILES env var: ".concat(s));return}}function Y(e){let r=x(I(),e);return r===void 0?[]:F(r,I(),e)}function z(e){let r=x(C(),e);if(!m(r))return;let n=r.activeProfile;if(n!==void 0){if(typeof n!="string"||!n){l(e,"".concat(C(),': "activeProfile" must be a non-empty string; ignoring.'));return}return n}}function b(e){let r=[],n="none",s=G(e);if(s)r=s,n="env";else{let o=Y(e);o.length>0&&(r=o,n="disk")}let t,i="none",f=process.env.MERIDIAN_DEFAULT_PROFILE?.trim();if(f)t=f,i="env";else{let o=z(e);o&&(t=o,i="disk")}return t&&r.length>0&&!r.some(o=>o.id===t)&&(l(e,'default profile "'.concat(t,'" (from ').concat(i,") not found among configured profiles; ignoring.")),t=void 0,i="none"),{profiles:r,defaultProfile:t,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,s=e.sources.profiles,t=e.sources.defaultProfile==="none"?"first":e.sources.defaultProfile;return"loaded ".concat(e.profiles.length," meridian profile(s) from ").concat(s,": ").concat(r," (active: ").concat(n," [").concat(t,"])")}function $(e){let r=K();if(!w(r))return;let n=x(r,e);if(n===void 0)return;if(!m(n)){l(e,"".concat(r," must be a JSON object; leaving client prompt passthrough unchanged."));return}let s=n,t=s.opencode;if(t!==void 0&&!m(t)){l(e,"".concat(r,': "opencode" must be a JSON object; leaving client prompt passthrough unchanged.'));return}if(!t||t.clientSystemPrompt!==!1)return;let i={...t};delete i.clientSystemPrompt;let f={...s};Object.keys(i).length>0?f.opencode=i:delete f.opencode;try{let o="".concat(r,".tmp");J(o,JSON.stringify(f,null,2)),j(o,r)}catch(o){let a=o instanceof Error?o.message:String(o);l(e,"failed to update ".concat(r,": ").concat(a))}}import{startProxyServer as X}from"@rynfar/meridian";process.env.MERIDIAN_PASSTHROUGH??="true";var q=process.platform==="win32",A=3456,D="127.0.0.1";function B(e){return e.includes(":")&&!e.startsWith("[")?"[".concat(e,"]"):e}function S(){let e=process.env.MERIDIAN_HOST?.trim()||process.env.CLAUDE_PROXY_HOST?.trim()||D;return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e}function Q(e=S()){return e==="0.0.0.0"?D:e==="::"||e==="[::]"?"::1":e}function O(e,r=S()){return"http://".concat(B(Q(r)),":").concat(e)}async function N(e){let{port:r=A,log:n,profiles:s,defaultProfile:t}=e,i=S(),f=console.error;console.error=(...d)=>{let c=d.map(String).join(" ");if(c.startsWith("[PROXY]")){n?.(E(c),c);return}f.apply(console,d)};let o=d=>new Promise((c,L)=>{X({port:d,host:i,silent:!0,profiles:s,defaultProfile:t}).then(p=>{let h=_=>{L(_)};p.server.once("error",h),p.server.listening?(p.server.removeListener("error",h),c(p)):p.server.once("listening",()=>{p.server.removeListener("error",h),c(p)})},L)}),a=async d=>{try{return await o(d)}catch(c){if(d!==0&&c instanceof Error&&"code"in c&&c.code==="EADDRINUSE")return n?.("info","Port ".concat(d," in use, starting on a random port instead...")),o(0);throw c}},u;try{u=await a(typeof r=="string"?parseInt(r,10):r)}catch(d){throw console.error=f,d}let g=u.server.address()?.port??u.config?.port??A;return n?.("info","Claude Max proxy running on port ".concat(g)),{port:g,close:async()=>{console.error=f,await u.close()}}}function T(e){let r=!1,n=()=>{r||(r=!0,e.close())};process.on("exit",n),process.on("SIGINT",n),q||process.on("SIGTERM",n)}var de=async({client:e})=>{let r=R(e),n=b(r),s=k(n);s&&r("info",s),$(r);let t=process.env.CLAUDE_PROXY_PORT||3456,i=await N({port:t,log:r,profiles:n.profiles,defaultProfile:n.defaultProfile}),f=O(i.port);return r("info","proxy ready at ".concat(f)),T(i),{async config(o){let a=o.provider?.anthropic;a&&((a.options??={}).baseURL=f)},async"experimental.chat.system.transform"(o,a){o.model.providerID==="anthropic"&&/^\s*You are OpenCode\b/i.test(a.system[0]??"")&&a.system.shift()},async"chat.headers"(o,a){if(o.model.providerID!=="anthropic")return;delete a.headers["anthropic-beta"];let u=o.agent,P=typeof u=="object"&&u!==null?u:void 0,g=P?.name??String(u??"unknown"),d=P?.mode??"primary";a.headers["x-opencode-session"]=o.sessionID,a.headers["x-opencode-request"]=o.message.id,a.headers["x-opencode-agent-mode"]=d,a.headers["x-opencode-agent-name"]=g.replace(/[^\x20-\x7E]/g,"").trim()||"unknown"}}};export{de as ClaudeMaxPlugin};
package/package.json CHANGED
@@ -1,7 +1,7 @@
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.5",
4
+ "version": "1.6.7",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",