opencode-with-claude 1.6.6 → 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,14 +108,13 @@ 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 defaults OpenCode's client prompt off because forwarding the
112
- OpenCode prompt can cause Claude Max requests to be classified as third-party
113
- usage. You can re-enable it by setting `clientSystemPrompt` to `true`.
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
114
 
115
115
  ```json
116
116
  {
117
117
  "opencode": {
118
- "clientSystemPrompt": false,
119
118
  "memory": true,
120
119
  "thinking": "enabled",
121
120
  "maxBudgetUsd": 0.5
package/dist/index.js CHANGED
@@ -1 +1 @@
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 L(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 C,mkdirSync as H,readFileSync as j,renameSync as J,writeFileSync as W}from"fs";import{homedir as K}from"os";import{join as y}from"path";var P=()=>y(K(),".config","meridian"),w=()=>y(P(),"profiles.json"),I=()=>y(P(),"settings.json"),G=()=>y(P(),"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 o=[];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),o.push(i)}return o}function x(e,r){if(C(e))try{return JSON.parse(j(e,"utf8"))}catch(n){let o=n instanceof Error?n.message:String(n);l(r,"failed to parse ".concat(e,": ").concat(o));return}}function z(e){let r=process.env.MERIDIAN_PROFILES;if(r)try{return F(JSON.parse(r),"MERIDIAN_PROFILES",e)}catch(n){let o=n instanceof Error?n.message:String(n);l(e,"failed to parse MERIDIAN_PROFILES env var: ".concat(o));return}}function X(e){let r=x(w(),e);return r===void 0?[]:F(r,w(),e)}function Y(e){let r=x(I(),e);if(!m(r))return;let n=r.activeProfile;if(n!==void 0){if(typeof n!="string"||!n){l(e,"".concat(I(),': "activeProfile" must be a non-empty string; ignoring.'));return}return n}}function k(e){let r=[],n="none",o=z(e);if(o)r=o,n="env";else{let a=X(e);a.length>0&&(r=a,n="disk")}let t,i="none",s=process.env.MERIDIAN_DEFAULT_PROFILE?.trim();if(s)t=s,i="env";else{let a=Y(e);a&&(t=a,i="disk")}return t&&r.length>0&&!r.some(a=>a.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 b(e){if(e.profiles.length===0)return;let r=e.profiles.map(i=>i.id).join(", "),n=e.defaultProfile??e.profiles[0]?.id,o=e.sources.profiles,t=e.sources.defaultProfile==="none"?"first":e.sources.defaultProfile;return"loaded ".concat(e.profiles.length," meridian profile(s) from ").concat(o,": ").concat(r," (active: ").concat(n," [").concat(t,"])")}function $(e){let r=G(),n={};if(C(r)){let s=x(r,e);if(s===void 0)return;if(!m(s)){l(e,"".concat(r," must be a JSON object; leaving client prompt default unchanged."));return}n=s}let o=n.opencode;if(o!==void 0&&!m(o)){l(e,"".concat(r,': "opencode" must be a JSON object; leaving client prompt default unchanged.'));return}let t=o??{};if(Object.hasOwn(t,"clientSystemPrompt"))return;let i={...n,opencode:{...t,clientSystemPrompt:!1}};try{H(P(),{recursive:!0});let s="".concat(r,".tmp");W(s,JSON.stringify(i,null,2)),J(s,r)}catch(s){let a=s instanceof Error?s.message:String(s);l(e,"failed to update ".concat(r,": ").concat(a))}}import{startProxyServer as q}from"@rynfar/meridian";process.env.MERIDIAN_PASSTHROUGH??="true";var B=process.platform==="win32",D=3456,A="127.0.0.1";function Q(e){return e.includes(":")&&!e.startsWith("[")?"[".concat(e,"]"):e}function S(){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 V(e=S()){return e==="0.0.0.0"?A:e==="::"||e==="[::]"?"::1":e}function O(e,r=S()){return"http://".concat(Q(V(r)),":").concat(e)}async function N(e){let{port:r=D,log:n,profiles:o,defaultProfile:t}=e,i=S(),s=console.error;console.error=(...f)=>{let d=f.map(String).join(" ");if(d.startsWith("[PROXY]")){n?.(E(d),d);return}s.apply(console,f)};let a=f=>new Promise((d,R)=>{q({port:f,host:i,silent:!0,profiles:o,defaultProfile:t}).then(p=>{let h=_=>{R(_)};p.server.once("error",h),p.server.listening?(p.server.removeListener("error",h),d(p)):p.server.once("listening",()=>{p.server.removeListener("error",h),d(p)})},R)}),c=async f=>{try{return await a(f)}catch(d){if(f!==0&&d instanceof Error&&"code"in d&&d.code==="EADDRINUSE")return n?.("info","Port ".concat(f," in use, starting on a random port instead...")),a(0);throw d}},u;try{u=await c(typeof r=="string"?parseInt(r,10):r)}catch(f){throw console.error=s,f}let g=u.server.address()?.port??u.config?.port??D;return n?.("info","Claude Max proxy running on port ".concat(g)),{port:g,close:async()=>{console.error=s,await u.close()}}}function T(e){let r=!1,n=()=>{r||(r=!0,e.close())};process.on("exit",n),process.on("SIGINT",n),B||process.on("SIGTERM",n)}var ce=async({client:e})=>{let r=L(e),n=k(r),o=b(n);o&&r("info",o),$(r);let t=process.env.CLAUDE_PROXY_PORT||3456,i=await N({port:t,log:r,profiles:n.profiles,defaultProfile:n.defaultProfile}),s=O(i.port);return r("info","proxy ready at ".concat(s)),T(i),{async config(a){let c=a.provider?.anthropic;c&&((c.options??={}).baseURL=s)},async"chat.headers"(a,c){if(a.model.providerID!=="anthropic")return;delete c.headers["anthropic-beta"];let u=a.agent,v=typeof u=="object"&&u!==null?u:void 0,g=v?.name??String(u??"unknown"),f=v?.mode??"primary";c.headers["x-opencode-session"]=a.sessionID,c.headers["x-opencode-request"]=a.message.id,c.headers["x-opencode-agent-mode"]=f,c.headers["x-opencode-agent-name"]=g.replace(/[^\x20-\x7E]/g,"").trim()||"unknown"}}};export{ce 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.6",
4
+ "version": "1.6.7",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",