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 +3 -4
- package/dist/index.js +1 -1
- package/package.json +1 -1
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
|
|
112
|
-
OpenCode
|
|
113
|
-
|
|
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
|
|
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