@agentdeploymentco/bishop 0.8.2 → 0.9.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.
@@ -0,0 +1 @@
1
+ import{readFile as L}from"node:fs/promises";import{createRequire as R}from"node:module";import{homedir as x}from"node:os";import{isAbsolute as S,join as w,resolve as g}from"node:path";import{exec as O}from"../exec.js";import{log as k}from"../log.js";import{repoRoot as M}from"../worktrees.js";import{isPlainObject as d,PLUGIN_INSTALL_TIMEOUT_MS as I,untilAborted as U}from"./layers.js";const C=["extraKnownMarketplaces","additionalMarketplaces"],$=new Set(["directory","file","settings"]),D=3600*1e3;function E(t){return C.flatMap(n=>{const e=t[n];return d(e)?Object.entries(e).filter(a=>d(a[1])):[]})}async function B(t,n,e=M){if(!E(t).some(([,u])=>y(u)!==void 0))return t;const a=await e(n)??n;let i=t;for(const u of C){const r=t[u];if(!d(r))continue;let s=!1;const f=Object.fromEntries(Object.entries(r).map(([l,o])=>{const p=y(o);if(p===void 0)return[l,o];s=!0;const{source:h}=o;return[l,{...o,source:{...h,path:g(a,p)}}]}));s&&(i={...i,[u]:f})}return i}function y(t){if(!d(t)||!d(t.source))return;const{source:n,path:e}=t.source;if(!(n!=="directory"&&n!=="file"))return typeof e=="string"&&e&&!S(e)?e:void 0}function j(t){if(!d(t))return[];const n=E(t).filter(([,e])=>e.autoUpdate===!0).filter(([,e])=>d(e.source)&&!$.has(String(e.source.source))).map(([e])=>e);return[...new Set(n)]}function P(t,n,e=x()){return t.CLAUDE_CODE_PLUGIN_CACHE_DIR?g(n,t.CLAUDE_CODE_PLUGIN_CACHE_DIR):w(g(n,t.CLAUDE_CONFIG_DIR||w(e,".claude")),"plugins")}async function v(t){try{const n=JSON.parse(await L(w(t,"known_marketplaces.json"),"utf8"));return new Set(d(n)?Object.keys(n):[])}catch{return new Set}}function J(){try{const t=R(import.meta.resolve("@anthropic-ai/claude-agent-sdk")),n=`@anthropic-ai/claude-agent-sdk-${process.platform}-${process.arch}`,e=process.platform==="win32"?"claude.exe":"claude",a=process.platform==="linux"?process.report?.getReport():void 0,u=a!==void 0&&a.header?.glibcVersionRuntime===void 0?[`${n}-musl`,n]:[n,`${n}-musl`];for(const r of u)try{return t.resolve(`${r}/${e}`)}catch{}}catch{}}function Y(t){return(n,e)=>O(t,n,{cwd:e.cwd,env:e.env,signal:e.signal})}function z(t=D,n=I,e=Date.now){const a=new Map,i=new Map,u=async(r,s,f)=>{const l={...r.context,marketplace:s},o=await r.run(["plugin","marketplace","update","--",s],{cwd:r.cwd,env:r.env,signal:f});if(o.code===0)k.info(l,"refreshed a plugin marketplace");else{const p=o.output.trim(),c=[f.aborted?"timed out":o.signal?`killed by ${o.signal}`:o.code===null?"couldn't start Claude Code":void 0,p].filter(Boolean).join(": ")||`exited with ${o.code}`;k.warn({...l,error:c},"couldn't refresh a plugin marketplace; this thread gets the copy already fetched")}};return async r=>{const s=j(r.settings);if(s.length===0)return;const f=P(r.env,r.cwd),l=c=>`${f}\0${c}`,o=await v(f),p=AbortSignal.timeout(n);for(const c of s){const m=l(c);if(i.has(m))continue;const _=a.get(m);if(_!==void 0&&e()-_<t||(a.set(m,e()),!o.has(c)))continue;const b=u(r,c,p).catch(A=>k.warn({...r.context,marketplace:c,err:A},"couldn't refresh a plugin marketplace; this thread gets the copy already fetched")).finally(()=>i.delete(m));i.set(m,b)}const h=s.flatMap(c=>i.get(l(c))??[]);await U(Promise.all(h),r.signal)}}export{D as MARKETPLACE_REFRESH_INTERVAL_MS,B as anchorLocalMarketplaces,j as autoUpdated,J as bundledClaude,Y as directClaude,z as marketplaceRefresher,P as pluginsRoot};
@@ -1 +1 @@
1
- import{realpath as d,stat as p}from"node:fs/promises";import{join as u}from"node:path";import{resolveSettings as m}from"@anthropic-ai/claude-agent-sdk";import{log as s}from"../log.js";import{sandboxReadable as g}from"../sandbox.js";import{isPlainObject as l,PLUGIN_INSTALL_TIMEOUT_MS as h,unionLists as w}from"./layers.js";const S=1e3,j=u(".claude","settings.json");async function L(e,n){const r=u(e,j),i=await p(r).catch(()=>{});if(i)try{const t=await d(r);if(!i.isFile()||n&&!g(n,t)){s.warn({path:r,resolved:t},"the agent's settings file isn't a file the agent could read itself; passing nothing from it");return}const o=(await m({cwd:e,settingSources:["project"]})).sources.find(f=>f.source==="project");if(o)return o.settings;s.warn({path:r},"the agent's settings file isn't valid Claude settings, so Claude skips it and Bishop passes nothing from it")}catch(t){s.warn({path:r,err:t},"couldn't read the agent's settings file; passing nothing from it")}}function c(e,n){if(n===void 0)return e;if(Array.isArray(e)&&Array.isArray(n))return w(e,n);if(l(e)&&l(n)){const r=new Set([...Object.keys(e),...Object.keys(n)]),i=(t,a)=>Object.hasOwn(t,a)?t[a]:void 0;return Object.fromEntries([...r].map(t=>[t,c(i(e,t),i(n,t))]))}return n}function k(...e){return e.reduce((n,r)=>c(n,r),{})}function E(e,n=h,r=Date.now){let i;return t=>{if(!(t.type!=="system"||t.subtype!=="plugin_install"))switch(t.status){case"started":i=r();return;case"installed":s.info({...e,marketplace:t.name},"installed plugins from a marketplace");return;case"failed":s.warn({...e,marketplace:t.name,error:t.error},"plugins from a marketplace failed to install");return;case"completed":{if(i===void 0||r()-i<n-S)return;s.warn({...e,timeoutMs:n},"plugin install hit its time limit; this turn runs without whatever had not finished");return}}}}export{j as SETTINGS_FILE,k as mergeSettings,E as pluginInstallWatcher,L as readAgentSettings};
1
+ import{realpath as d,stat as p}from"node:fs/promises";import{join as l}from"node:path";import{resolveSettings as m}from"@anthropic-ai/claude-agent-sdk";import{log as s}from"../log.js";import{sandboxReadable as g}from"../sandbox.js";import{anchorLocalMarketplaces as h}from"./claude-marketplaces.js";import{isPlainObject as u,PLUGIN_INSTALL_TIMEOUT_MS as w,unionLists as S}from"./layers.js";const j=1e3,y=l(".claude","settings.json");async function E(e,n){const r=l(e,y),i=await p(r).catch(()=>{});if(i)try{const t=await d(r);if(!i.isFile()||n&&!g(n,t)){s.warn({path:r,resolved:t},"the agent's settings file isn't a file the agent could read itself; passing nothing from it");return}const o=(await m({cwd:e,settingSources:["project"]})).sources.find(f=>f.source==="project");if(o)return await h(o.settings,e);s.warn({path:r},"the agent's settings file isn't valid Claude settings, so Claude skips it and Bishop passes nothing from it")}catch(t){s.warn({path:r,err:t},"couldn't read the agent's settings file; passing nothing from it")}}function c(e,n){if(n===void 0)return e;if(Array.isArray(e)&&Array.isArray(n))return S(e,n);if(u(e)&&u(n)){const r=new Set([...Object.keys(e),...Object.keys(n)]),i=(t,a)=>Object.hasOwn(t,a)?t[a]:void 0;return Object.fromEntries([...r].map(t=>[t,c(i(e,t),i(n,t))]))}return n}function M(...e){return e.reduce((n,r)=>c(n,r),{})}function C(e,n=w,r=Date.now){let i;return t=>{if(!(t.type!=="system"||t.subtype!=="plugin_install"))switch(t.status){case"started":i=r();return;case"installed":s.info({...e,marketplace:t.name},"installed plugins from a marketplace");return;case"failed":s.warn({...e,marketplace:t.name,error:t.error},"plugins from a marketplace failed to install");return;case"completed":{if(i===void 0||r()-i<n-j)return;s.warn({...e,timeoutMs:n},"plugin install hit its time limit; this turn runs without whatever had not finished");return}}}}export{y as SETTINGS_FILE,M as mergeSettings,C as pluginInstallWatcher,E as readAgentSettings};
@@ -1,13 +1,13 @@
1
- import{spawn as N}from"node:child_process";import{existsSync as P,mkdirSync as $}from"node:fs";import{mkdir as U}from"node:fs/promises";import{homedir as B}from"node:os";import{join as E,resolve as x}from"node:path";import{query as D}from"@anthropic-ai/claude-agent-sdk";import{log as h}from"../log.js";import{executableDir as F,nonoCommand as G}from"../sandbox.js";import{SERVER_NAME as T}from"../tools/server.js";import{isolates as _,repoRoot as W,WORKTREE_DIR as M,worktreePath as H}from"../worktrees.js";import{bishopServer as O,buildAgentOptions as Y,CONTROLLED_KEYS as V,SETTINGS_ONLY_KEYS as z}from"./claude-options.js";import{claudeProcesses as J,DEFAULT_KEEP_ALIVE as Q}from"./claude-processes.js";import{pluginInstallWatcher as X,readAgentSettings as Z}from"./claude-settings.js";import{ignoredKeys as j,shadowedKeys as q}from"./layers.js";import{buildPrompt as ee,NO_OUTPUT as te,principalInstructions as ne}from"./principal.js";const oe=new Set(["Agent","Task"]),re=2e3;function ie(e){if(!e||typeof e!="object")return;const{name:n,description:o}=e;for(const r of[n,o]){if(typeof r!="string"||!r.trim())continue;const i=r.trim().split(`
2
- `)[0]??"";return i.length>40?`${i.slice(0,37)}...`:i}}function se(){const e=new Map,n=new Map,o=(r,i,c)=>{if(r.set(i,c),r.size>re){const s=r.keys().next().value;s!==void 0&&r.delete(s)}};return function*(i){switch(i.type){case"system":i.subtype==="init"&&(yield{type:"session",sessionId:i.session_id,...i.model?{model:i.model}:{}});return;case"assistant":{const c=i.parent_tool_use_id||null,s=c===null?void 0:e.get(c)??"Subagent";for(const a of i.message.content)if(a.type==="text"&&a.text.trim())s||(yield{type:"text",text:a.text});else if(a.type==="tool_use"){const u=oe.has(a.name)?ie(a.input):void 0;u&&o(e,a.id,u),s&&o(n,a.id,s);const g=u??ae(a.input);yield{type:"tool",name:a.name,...g?{detail:g}:{},...s?{agent:s}:{}}}else a.type==="thinking"&&!s&&(yield{type:"thinking"});return}case"tool_use_summary":{const c=i.preceding_tool_use_ids.map(s=>n.get(s)).find(s=>s!==void 0);yield{type:"tool_summary",summary:i.summary,...c?{agent:c}:{}};return}case"result":i.subtype==="success"?yield{type:"done",text:i.result,usage:{turns:i.num_turns,costUsd:i.total_cost_usd}}:yield{type:"error",kind:i.subtype,message:de(i.subtype)};return;default:return}}}function ae(e){if(!e||typeof e!="object")return;const n=e,o=n.file_path??n.notebook_path??n.path;if(typeof o=="string"&&o)return o.split("/").pop()??o;const r=n.url;if(typeof r=="string"&&r)try{return new URL(r).hostname}catch{return r.slice(0,40)}for(const i of["pattern","query","description"]){const c=n[i];if(typeof c=="string"&&c.trim()){const s=c.trim().split(`
3
- `)[0]??"";return s.length>48?`${s.slice(0,45)}...`:s}}}function ce(e){switch(e){case"none":return"existing claude login or cloud provider";case"/login managed key":return"key managed by claude login";default:return e}}function de(e){switch(e){case"error_max_turns":return"the agent hit its turn limit before finishing";case"error_max_budget_usd":return"the agent hit its cost limit before finishing";case"error_during_execution":return"the agent stopped on an error";default:return`the agent stopped: ${e}`}}const le=new Set(["Edit","Write","NotebookEdit"]);function ue(e,n){return["This directory is shared with other conversations that may be running at the same time.",`Before you edit, create, or delete any file here, call EnterWorktree with name "${n}"`,"so your changes land in a git worktree of your own. Load the tool with ToolSearch first if","it isn't available. If a worktree by that name already exists, enter it by path instead:",`${H(e,n)}.`,"","Once you are in the worktree, work normally. Relative paths resolve inside it, and you","stay in it for every later message in this thread. Commit what you finish on the","worktree's branch and say which branch it is, since that's how a person finds your work.","Don't call ExitWorktree."].join(`
4
- `)}function fe(e){const n=x(e);return({toolName:o,cwd:r})=>{if(le.has(o)&&x(r)===n)return"This is the shared checkout, which other conversations are using. Call EnterWorktree with the name given in your instructions, then make this edit inside the worktree."}}const pe=["When background work you started finishes after your reply, you are woken to report on it, and what you say is posted to the conversation.","Report on each subagent as it finishes, the way you would to someone waiting on the work.","Some conversations show only the report you make once all your subagents have finished, so make that one stand on its own: everything the people there need from all of the work, not only the piece that just finished.",`When nothing from the work needs saying, answer ${te} and nothing else.`].join(" ");function he(e,n,o,r,i=!1){const c=_(e)?ue(r,o):void 0;return[ne(n),i?pe:void 0,c].filter(s=>!!s?.trim()).join(`
1
+ import{spawn as W}from"node:child_process";import{existsSync as M,mkdirSync as H}from"node:fs";import{mkdir as Y}from"node:fs/promises";import{homedir as O}from"node:os";import{join as C,resolve as v}from"node:path";import{query as L}from"@anthropic-ai/claude-agent-sdk";import{log as f}from"../log.js";import{executableDir as V,nonoCommand as z}from"../sandbox.js";import{SERVER_NAME as A}from"../tools/server.js";import{isolates as _,repoRoot as J,WORKTREE_DIR as Q,worktreePath as X}from"../worktrees.js";import{bundledClaude as Z,directClaude as N,marketplaceRefresher as q}from"./claude-marketplaces.js";import{bishopServer as ee,buildAgentOptions as te,CONTROLLED_KEYS as ne,SETTINGS_ONLY_KEYS as oe}from"./claude-options.js";import{claudeProcesses as re,DEFAULT_KEEP_ALIVE as ie}from"./claude-processes.js";import{pluginInstallWatcher as se,readAgentSettings as ae}from"./claude-settings.js";import{ignoredKeys as P,shadowedKeys as de}from"./layers.js";import{buildPrompt as le,NO_OUTPUT as ce,principalInstructions as ue}from"./principal.js";const fe=new Set(["Agent","Task"]),pe=2e3;function he(t){if(!t||typeof t!="object")return;const{name:n,description:o}=t;for(const r of[n,o]){if(typeof r!="string"||!r.trim())continue;const i=r.trim().split(`
2
+ `)[0]??"";return i.length>40?`${i.slice(0,37)}...`:i}}function me(){const t=new Map,n=new Map,o=(r,i,a)=>{if(r.set(i,a),r.size>pe){const s=r.keys().next().value;s!==void 0&&r.delete(s)}};return function*(i){switch(i.type){case"system":i.subtype==="init"&&(yield{type:"session",sessionId:i.session_id,...i.model?{model:i.model}:{}});return;case"assistant":{const a=i.parent_tool_use_id||null,s=a===null?void 0:t.get(a)??"Subagent";for(const d of i.message.content)if(d.type==="text"&&d.text.trim())s||(yield{type:"text",text:d.text});else if(d.type==="tool_use"){const m=fe.has(d.name)?he(d.input):void 0;m&&o(t,d.id,m),s&&o(n,d.id,s);const g=m??ge(d.input);yield{type:"tool",name:d.name,...g?{detail:g}:{},...s?{agent:s}:{}}}else d.type==="thinking"&&!s&&(yield{type:"thinking"});return}case"tool_use_summary":{const a=i.preceding_tool_use_ids.map(s=>n.get(s)).find(s=>s!==void 0);yield{type:"tool_summary",summary:i.summary,...a?{agent:a}:{}};return}case"result":i.subtype==="success"?yield{type:"done",text:i.result,usage:{turns:i.num_turns,costUsd:i.total_cost_usd}}:yield{type:"error",kind:i.subtype,message:we(i.subtype)};return;default:return}}}function ge(t){if(!t||typeof t!="object")return;const n=t,o=n.file_path??n.notebook_path??n.path;if(typeof o=="string"&&o)return o.split("/").pop()??o;const r=n.url;if(typeof r=="string"&&r)try{return new URL(r).hostname}catch{return r.slice(0,40)}for(const i of["pattern","query","description"]){const a=n[i];if(typeof a=="string"&&a.trim()){const s=a.trim().split(`
3
+ `)[0]??"";return s.length>48?`${s.slice(0,45)}...`:s}}}function ye(t){switch(t){case"none":return"existing claude login or cloud provider";case"/login managed key":return"key managed by claude login";default:return t}}function we(t){switch(t){case"error_max_turns":return"the agent hit its turn limit before finishing";case"error_max_budget_usd":return"the agent hit its cost limit before finishing";case"error_during_execution":return"the agent stopped on an error";default:return`the agent stopped: ${t}`}}const be=new Set(["Edit","Write","NotebookEdit"]);function ke(t,n){return["This directory is shared with other conversations that may be running at the same time.",`Before you edit, create, or delete any file here, call EnterWorktree with name "${n}"`,"so your changes land in a git worktree of your own. Load the tool with ToolSearch first if","it isn't available. If a worktree by that name already exists, enter it by path instead:",`${X(t,n)}.`,"","Once you are in the worktree, work normally. Relative paths resolve inside it, and you","stay in it for every later message in this thread. Commit what you finish on the","worktree's branch and say which branch it is, since that's how a person finds your work.","Don't call ExitWorktree."].join(`
4
+ `)}function xe(t){const n=v(t);return({toolName:o,cwd:r})=>{if(be.has(o)&&v(r)===n)return"This is the shared checkout, which other conversations are using. Call EnterWorktree with the name given in your instructions, then make this edit inside the worktree."}}const ve=["When background work you started finishes after your reply, you are woken to report on it, and what you say is posted to the conversation.","Report on each subagent as it finishes, the way you would to someone waiting on the work.","Some conversations show only the report you make once all your subagents have finished, so make that one stand on its own: everything the people there need from all of the work, not only the piece that just finished.",`When nothing from the work needs saying, answer ${ce} and nothing else.`].join(" ");function _e(t,n,o,r,i=!1){const a=_(t)?ke(r,o):void 0;return[ue(n),i?ve:void 0,a].filter(s=>!!s?.trim()).join(`
5
5
 
6
- `)}function me(e,n){return{model:n?.model??e.model,effort:n?.effort??e.effort}}function ge(e){return async n=>{const o=n,r=e({toolName:o.tool_name,cwd:o.cwd});return r?(h.info({tool:o.tool_name,cwd:o.cwd},"refusing an edit in the shared checkout"),{continue:!0,hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:r}}):{continue:!0}}}function ye(e,n=B()){const o=e.CLAUDE_CONFIG_DIR;return o?{allow:[o]}:{allow:[E(n,".claude")],allowFiles:[E(n,".claude.json")].filter(P)}}async function we(e){const n=await W(e);if(!n||x(n)===x(e))return[];const o=E(n,M);return await U(o,{recursive:!0}),[o]}const ke=2048;function A(e,n){const o=n.text.trim();return o?`${e}
7
- ${o}`:e}function be(e){return n=>A(n,e)}function xe(e,n,o){return r=>{const i=ye(r.env);for(const u of i.allow??[])$(u,{recursive:!0});const c=F(r.command),s=G(e,{allow:[...i.allow??[],...n],read:c?[c]:[],...i.allowFiles?{allowFiles:i.allowFiles}:{}},r.command,r.args),a=N(s.command,s.args,{...r.cwd?{cwd:r.cwd}:{},env:r.env,stdio:["pipe","pipe","pipe"],signal:r.signal});return a.stderr.on("data",u=>{o.text=(o.text+u.toString()).slice(-ke)}),a.on("exit",u=>{const g=o.text.trim();u&&g&&h.warn({code:u,stderr:g},"the sandboxed agent exited with an error")}),a}}function Ue(e={}){const n=j(e.options,V);n.length>0&&h.warn({ignored:n},"these agent.options are set by Bishop and cannot be overridden; ignoring them");const o=e.options?.mcpServers;o&&typeof o=="object"&&Object.hasOwn(o,T)&&h.warn({server:T},`agent.options.mcpServers names a server "${T}", which is Bishop's own; ignoring it`);const r=t=>me(e,t),i=r(),c=q(e.options,i);c.length>0&&h.warn({shadowed:c},"agent.model and agent.effort override these agent.options");const s=j(e.options,z);s.length>0&&h.warn({misplaced:s},"the harness reads these from agent.options.settings only and ignores them here");const a=e.worktrees,u=e.projectSettings!==!1;if(typeof e.options?.settings=="string"){const t=["auto memory is left to that file and the agent's own settings"];_(a)&&t.push("new worktrees branch from origin/<default-branch> rather than HEAD"),u&&t.push("the agent's .claude/settings.json gets only what headless Claude trusts of it, without its allow rules or plugins"),h.warn({settings:e.options.settings},`agent.options.settings names a file, so Bishop applies no settings defaults: ${t.join("; ")}`)}const g=(t,l,d,m,p)=>{const f=_(a)?fe(t.cwd):void 0,b=f?{PreToolUse:[{hooks:[ge(f)]}]}:void 0,y=Y({...e.options?{configOptions:e.options}:{},general:r(l),...e.apiKey?{apiKey:e.apiKey}:{},...b?{hooks:b,worktrees:!0}:{},...m?{agentSettings:m}:{},...p?{installPlugins:p}:{},controlled:t});return d?{...y,spawnClaudeCodeProcess:d}:y},C=u&&typeof e.options?.settings!="string",R=(t,l)=>C?Z(t,l):Promise.resolve(void 0),v=e.keepAlive??Q,I=se(),S=J({start:e.start??(t=>D(t)),keepAlive:v,async*translate(t){for await(const l of t)yield*I(l)}}),K=async(t,l,d)=>xe(l,_(a)?await we(t):[],d);return{name:"claude",describeStartupFailure(t,l){return`The Claude agent couldn't start in ${t}:
8
- ${l}
6
+ `)}function Se(t,n){return{model:n?.model??t.model,effort:n?.effort??t.effort}}function Ee(t){return async n=>{const o=n,r=t({toolName:o.tool_name,cwd:o.cwd});return r?(f.info({tool:o.tool_name,cwd:o.cwd},"refusing an edit in the shared checkout"),{continue:!0,hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:r}}):{continue:!0}}}function Te(t,n=O()){const o=t.CLAUDE_CONFIG_DIR;return o?{allow:[o]}:{allow:[C(n,".claude")],allowFiles:[C(n,".claude.json")].filter(M)}}async function Ce(t){const n=await J(t);if(!n||v(n)===v(t))return[];const o=C(n,Q);return await Y(o,{recursive:!0}),[o]}const Ae=2048;function R(t,n){const o=n.text.trim();return o?`${t}
7
+ ${o}`:t}function Re(t){return n=>R(n,t)}function U(t,n,o,r,i){const a=Te(o);for(const d of a.allow??[])H(d,{recursive:!0});const s=V(r);return z(t,{allow:[...a.allow??[],...n],read:s?[s]:[],...a.allowFiles?{allowFiles:a.allowFiles}:{}},r,i)}function Ie(t,n){return n?(o,r)=>{const i=U(n,[],r.env,t,o);return N(i.command)(i.args,r)}:N(t)}function je(t,n,o){return r=>{const i=U(t,n,r.env,r.command,r.args),a=W(i.command,i.args,{...r.cwd?{cwd:r.cwd}:{},env:r.env,stdio:["pipe","pipe","pipe"],signal:r.signal});return a.stderr.on("data",s=>{o.text=(o.text+s.toString()).slice(-Ae)}),a.on("exit",s=>{const d=o.text.trim();s&&d&&f.warn({code:s,stderr:d},"the sandboxed agent exited with an error")}),a}}function ze(t={}){const n=P(t.options,ne);n.length>0&&f.warn({ignored:n},"these agent.options are set by Bishop and cannot be overridden; ignoring them");const o=t.options?.mcpServers;o&&typeof o=="object"&&Object.hasOwn(o,A)&&f.warn({server:A},`agent.options.mcpServers names a server "${A}", which is Bishop's own; ignoring it`);const r=e=>Se(t,e),i=r(),a=de(t.options,i);a.length>0&&f.warn({shadowed:a},"agent.model and agent.effort override these agent.options");const s=P(t.options,oe);s.length>0&&f.warn({misplaced:s},"the harness reads these from agent.options.settings only and ignores them here");const d=t.worktrees,m=t.projectSettings!==!1;if(typeof t.options?.settings=="string"){const e=["auto memory is left to that file and the agent's own settings"];_(d)&&e.push("new worktrees branch from origin/<default-branch> rather than HEAD"),m&&e.push("the agent's .claude/settings.json gets only what headless Claude trusts of it, without its allow rules or plugins"),f.warn({settings:t.options.settings},`agent.options.settings names a file, so Bishop applies no settings defaults: ${e.join("; ")}`)}const g=(e,c,l,p,h)=>{const u=_(d)?xe(e.cwd):void 0,x=u?{PreToolUse:[{hooks:[Ee(u)]}]}:void 0,w=te({...t.options?{configOptions:t.options}:{},general:r(c),...t.apiKey?{apiKey:t.apiKey}:{},...x?{hooks:x,worktrees:!0}:{},...p?{agentSettings:p}:{},...h?{installPlugins:h}:{},controlled:e});return l?{...w,spawnClaudeCodeProcess:l}:w},$=m&&typeof t.options?.settings!="string",I=(e,c)=>$?ae(e,c):Promise.resolve(void 0),B=q();let y;const F=()=>{if(y===void 0){const e=t.options?.pathToClaudeCodeExecutable;typeof e=="string"&&/\.(js|mjs|ts|tsx|jsx)$/.test(e)?(y=null,f.warn({pathToClaudeCodeExecutable:e},"agent.options.pathToClaudeCodeExecutable names a script rather than the native binary, so plugin marketplaces marked autoUpdate aren't refreshed")):(y=typeof e=="string"&&e||Z()||null,y||f.warn("couldn't find the Claude Code binary, so plugin marketplaces marked autoUpdate aren't refreshed"))}return y??void 0},S=t.keepAlive??ie,j=me(),E=re({start:t.start??(e=>L(e)),keepAlive:S,async*translate(e){for await(const c of e)yield*j(c)}}),K=async(e,c,l)=>je(c,_(d)?await Ce(e):[],l);return{name:"claude",describeStartupFailure(e,c){return`The Claude agent couldn't start in ${e}:
8
+ ${c}
9
9
 
10
10
  Bishop does not manage Anthropic credentials. The agent authenticates the
11
11
  same way \`claude\` does in this directory, so make sure that works first:
12
12
  ANTHROPIC_API_KEY in the environment or .env, or
13
- an existing \`claude\` login on this machine.`},async check(t,l){const d=new AbortController,m={text:""};try{const p=l?await K(t,l,m):void 0;await R(t,l);for await(const f of D({prompt:"ping",options:{...g({cwd:t,systemPrompt:void 0,abortController:d},void 0,p),maxTurns:1,persistSession:!1}})){if(f.type==="system"&&f.subtype==="init")return d.abort(),{ok:!0,credentialSource:ce(f.apiKeySource),...f.model?{model:f.model}:{}};if(f.type==="result")break}return{ok:!1,error:A("the harness exited without starting a session",m)}}catch(p){if(d.signal.aborted)return{ok:!0};const f=p instanceof Error?p.message:String(p);return{ok:!1,error:A(f,m)}}},async*runTurn(t){let l=!1;try{const d=await R(t.cwd,t.sandbox),m=u&&!t.sessionId,p=m?X({thread:t.threadKey}):void 0,f=!!v&&t.keepAlive===!0,b=he(a,t.origin,t.worktree,t.cwd,f),y=r(t),L=S.run({threadId:t.threadId,threadKey:t.threadKey,text:ee(t),fingerprint:{cwd:t.cwd,origin:{name:t.origin.name,self:t.origin.self},model:y.model,effort:y.effort,settings:d,sandbox:t.sandbox},...t.sessionId?{sessionId:t.sessionId}:{},keepAlive:f,...t.tools?{tools:t.tools}:{},server:O,signal:t.signal,options:async()=>{const w={text:""},k=t.sandbox?await K(t.cwd,t.sandbox,w):void 0;return{options:g({cwd:t.cwd,systemPrompt:{type:"preset",preset:"claude_code",append:b},abortController:new AbortController,...t.sessionId?{resume:t.sessionId}:{}},t,k,d,m),explain:be(w)}}});for await(const w of L){p?.(w);for(const k of I(w))(k.type==="done"||k.type==="error")&&(l=!0),yield k}}catch(d){t.signal.aborted?h.debug({thread:t.threadKey},"claude turn aborted"):l?h.debug({err:d},"the agent failed after reporting a result"):(h.error({err:d},"harness turn failed"),yield{type:"error",kind:"harness_failure",message:d instanceof Error?d.message:String(d)})}},...v?{keepAlive:{attach:t=>S.attach(t),close:()=>S.close()}}:{}}}export{pe as BACKGROUND_REPORTS,me as chosenGeneral,Ue as claudeHarness,ye as claudeStateGrants,se as claudeTranslator,fe as editGuard,he as systemPromptAppend,ae as toolDetail,ue as worktreeNote};
13
+ an existing \`claude\` login on this machine.`},async check(e,c){const l=new AbortController,p={text:""};try{const h=c?await K(e,c,p):void 0;await I(e,c);for await(const u of L({prompt:"ping",options:{...g({cwd:e,systemPrompt:void 0,abortController:l},void 0,h),maxTurns:1,persistSession:!1}})){if(u.type==="system"&&u.subtype==="init")return l.abort(),{ok:!0,credentialSource:ye(u.apiKeySource),...u.model?{model:u.model}:{}};if(u.type==="result")break}return{ok:!1,error:R("the harness exited without starting a session",p)}}catch(h){if(l.signal.aborted)return{ok:!0};const u=h instanceof Error?h.message:String(h);return{ok:!1,error:R(u,p)}}},async*runTurn(e){let c=!1;try{const l=await I(e.cwd,e.sandbox),p=m&&!e.sessionId,h=p?se({thread:e.threadKey}):void 0,u=!!S&&e.keepAlive===!0,x=_e(d,e.origin,e.worktree,e.cwd,u),w=r(e),G=E.run({threadId:e.threadId,threadKey:e.threadKey,text:le(e),fingerprint:{cwd:e.cwd,origin:{name:e.origin.name,self:e.origin.self},model:w.model,effort:w.effort,settings:l,sandbox:e.sandbox},...e.sessionId?{sessionId:e.sessionId}:{},keepAlive:u,...e.tools?{tools:e.tools}:{},server:ee,signal:e.signal,options:async()=>{const b={text:""},k=e.sandbox?await K(e.cwd,e.sandbox,b):void 0,T=g({cwd:e.cwd,systemPrompt:{type:"preset",preset:"claude_code",append:x},abortController:new AbortController,...e.sessionId?{resume:e.sessionId}:{}},e,k,l,p),D=p?F():void 0;return D&&await B({settings:T.settings,env:T.env??process.env,cwd:e.cwd,run:Ie(D,e.sandbox),context:{thread:e.threadKey},signal:e.signal}),{options:T,explain:Re(b)}}});for await(const b of G){h?.(b);for(const k of j(b))(k.type==="done"||k.type==="error")&&(c=!0),yield k}}catch(l){e.signal.aborted?f.debug({thread:e.threadKey},"claude turn aborted"):c?f.debug({err:l},"the agent failed after reporting a result"):(f.error({err:l},"harness turn failed"),yield{type:"error",kind:"harness_failure",message:l instanceof Error?l.message:String(l)})}},...S?{keepAlive:{attach:e=>E.attach(e),close:()=>E.close()}}:{}}}export{ve as BACKGROUND_REPORTS,Se as chosenGeneral,ze as claudeHarness,Te as claudeStateGrants,me as claudeTranslator,xe as editGuard,_e as systemPromptAppend,ge as toolDetail,ke as worktreeNote};
@@ -1,2 +1,2 @@
1
- import{spawn as B}from"node:child_process";import{randomBytes as I}from"node:crypto";import{mkdir as N,realpath as P,rename as E,rm as H,stat as A}from"node:fs/promises";import{basename as R,dirname as M,isAbsolute as T,join as k,relative as W,resolve as G,sep as $}from"node:path";import{createInterface as U}from"node:readline";import{exec as X}from"../exec.js";import{log as O}from"../log.js";import{SERVER_NAME as L}from"../tools/server.js";import{isPlainObject as c,PLUGIN_INSTALL_TIMEOUT_MS as Y,unionLists as z}from"./layers.js";const C=1e4,_=".codex";function S(e){return typeof e=="string"?JSON.stringify(e):typeof e=="number"?Number.isNaN(e)?"nan":Number.isFinite(e)?String(e):e>0?"inf":"-inf":typeof e=="boolean"?String(e):Array.isArray(e)?`[${e.filter(t=>t!=null).map(S).join(",")}]`:c(e)?`{${Object.entries(e).filter(([,n])=>n!=null).map(([n,s])=>`${JSON.stringify(n)}=${S(s)}`).join(",")}}`:JSON.stringify(String(e))}function D(e,t){const n=c(e)?{...e}:{};for(const[s,r]of Object.entries(t)){const o=Object.hasOwn(n,s)?n[s]:void 0;n[s]=c(o)&&c(r)?{...o,...r}:r}return n}function pe(e,t){const n=Object.fromEntries(e.map(s=>[s,{trust_level:"trusted"}]));return`projects=${S(D(t,n))}`}function me(e,t){if(e.length===0)return;const n=Object.fromEntries(e.map(o=>[o.key,{trusted_hash:o.currentHash}])),s=c(t)?t:{},r={...s,state:D(s.state,n)};return`hooks=${S(r)}`}function F(e){const t=e?.plugins;return c(t)?Object.entries(t).filter(([,n])=>c(n)&&n.enabled===!0).map(([n])=>n):[]}function ge(e,t,n){const s=n.map(r=>k(r,_)+$);return e.filter(r=>r.source==="project"&&s.some(o=>r.sourcePath?.startsWith(o)??!1)||r.source==="plugin"&&r.pluginId!==null&&t.includes(r.pluginId))}function K(e,t){return Array.isArray(e)&&Array.isArray(t)?z(t,e):c(e)&&c(t)?Object.fromEntries(Object.entries(e).map(([n,s])=>[n,K(s,Object.hasOwn(t,n)?t[n]:void 0)])):e}const he=["mcp_servers","notify","hooks","projects"];function j(e,t){let n=e;for(const s of t){if(!c(n)||!Object.hasOwn(n,s))return;n=n[s]}return n}const J=[{option:"sandboxMode",key:["sandbox_mode"]},{option:"networkAccessEnabled",key:["sandbox_workspace_write","network_access"]}];function we(e,t){const n=c(t?.config)?t.config:void 0,s={...e};for(const{option:r,key:o}of J)!(t!==void 0&&Object.hasOwn(t,r))&&j(n,o)!==void 0&&delete s[r];return s}function ye(e,t,n){const s=c(t?.config)?t.config:void 0,r={...e},o=[];for(const{option:f,key:g}of J)!(t!==void 0&&Object.hasOwn(t,f)||j(s,g)!==void 0)&&j(n,g)!==void 0&&Object.hasOwn(r,f)&&(delete r[f],o.push(f));return{options:r,yielded:o}}function be(e){const t=e.developer_instructions;return typeof t=="string"&&t.trim()?t:void 0}async function ke(e){return(await A(k(e,_)).catch(()=>{}))?.isDirectory()??!1}async function q(e){const t=await P(e).catch(()=>e);return[...new Set([e,t])]}async function V(e,t,n,s){const r=B(e.command,[...t,"app-server"],{cwd:e.cwd,env:e.env,stdio:["pipe","pipe","pipe"],...s?{signal:s,killSignal:"SIGKILL"}:{}});let o="";r.stderr.setEncoding("utf8"),r.stderr.on("data",p=>{o=(o+p).slice(-2e3)}),r.stdin.on("error",()=>{});const f=U({input:r.stdout}),g=[];let l=0;const y=p=>r.stdin.write(`${JSON.stringify(p)}
2
- `);try{return await new Promise((p,w)=>{const u=setTimeout(()=>w(new Error(`codex app-server didn't answer within ${C}ms`)),C),d=a=>{clearTimeout(u),a?w(a):p(g)},h=()=>{const a=n[l];if(!a)return d();l+=1,y({id:l,...a})};f.on("line",a=>{let m;try{m=JSON.parse(a)}catch{return}m.id===l&&(g.push(m),l===1&&y({method:"initialized"}),h())}),r.on("error",a=>d(a)),r.on("exit",a=>d(new Error(`codex app-server exited with code ${a}: ${o.trim()}`))),h()})}finally{f.close(),r.stdin.end(),r.kill()}}async function Oe(e,t,n){const s=e.cwd;let r;try{r=await V(e,t.flatMap(i=>["-c",i]),[{method:"initialize",params:{clientInfo:{name:"bishop",version:"0"}}},{method:"config/read",params:{includeLayers:!0,cwd:s}},{method:"hooks/list",params:{cwds:[s]}}],n)}catch(i){return{ok:!1,reason:i instanceof Error?i.message:String(i)}}const[,o,f]=r;if(o?.error)return{ok:!1,reason:o.error.message??"config/read failed"};const g=o?.result?.layers,l=(await q(s)).map(i=>k(i,_)),p=(Array.isArray(g)?g:[]).find(i=>c(i)&&c(i.name)&&i.name.type==="project"&&l.includes(String(i.name.dotCodexFolder))&&!i.disabledReason&&c(i.config))?.config??{};if(c(p.mcp_servers)&&Object.hasOwn(p.mcp_servers,L))return{ok:!1,reason:`it declares an MCP server named "${L}", which is Bishop's`};f?.error&&O.warn({cwd:s,error:f.error.message},"codex couldn't list the agent's hooks, so none are approved this turn");const w=f?.result?.data?.[0],u=c(w)?w:{},d=[u.warnings,u.errors].flatMap(i=>Array.isArray(i)?i:[]).map(i=>c(i)?String(i.message):String(i));d.length>0&&O.warn({cwd:s,warnings:d},"codex reported problems with the agent's hooks; it skips those");const h=(Array.isArray(u.hooks)?u.hooks:[]).filter(i=>c(i)&&typeof i.key=="string"&&typeof i.currentHash=="string"),a=o?.result?.config,m=c(a)?a.plugins:void 0,b=c(m)?Object.entries(m).filter(([,i])=>c(i)&&i.enabled===!1).map(([i])=>i):[];return{ok:!0,project:{config:p,hooks:h,disabledPlugins:b}}}function Q(e,t){if(typeof e.source!="string"||!e.source)return;const n=e.source_type==="local"&&!T(e.source)?G(t,e.source):e.source,s=typeof e.ref=="string"&&e.ref?[`--ref=${e.ref}`]:[],r=Array.isArray(e.sparse_paths)?e.sparse_paths.filter(o=>typeof o=="string").map(o=>`--sparse=${o}`):[];return["plugin","marketplace","add",...s,...r,"--json","--",n]}function Z(e){const t=e.lastIndexOf("@");if(!(t<=0||t===e.length-1))return{plugin:e.slice(0,t),marketplace:e.slice(t+1)}}async function xe(e){const{launch:t,home:n,agent:s,operator:r,installed:o,context:f}=e,g=c(s.marketplaces)?s.marketplaces:{},l=new Map;for(const u of F(s)){if(j(r,["plugins",u,"enabled"])===!1||e.disabled?.includes(u))continue;const d=Z(u);if(d){if(!Object.hasOwn(g,d.marketplace)){await A(k(n,"plugins","cache",d.marketplace,d.plugin)).then(()=>!0).catch(()=>!1)||O.warn({...f,plugin:u},"the agent enables a plugin from a marketplace its config doesn't declare, so Bishop can't install it");continue}l.set(d.marketplace,[...l.get(d.marketplace)??[],u])}}const y=AbortSignal.timeout(e.timeoutMs??Y),p=[...l].flatMap(([u,d])=>{const h=g[u],a=c(h)?Q(h,t.cwd):void 0;if(!a)return O.warn({...f,marketplace:u},"the agent's marketplace declaration has no source, so its plugins aren't installed"),[];const m=JSON.stringify([n,a,d.sort()]),b=o.get(m);if(b?.done)return[];if(b)return[b.pending];const i={done:!1,pending:te({...e,name:u,addArgs:a,plugins:d,signal:y}).then(x=>(x.ok?i.done=!0:o.delete(m),x.added))};return o.set(m,i),[i.pending]});return p.length===0?!1:(await ee(Promise.all(p),e.signal))?.some(Boolean)??!1}function ee(e,t){return t?t.aborted?Promise.resolve(void 0):new Promise((n,s)=>{const r=()=>n(void 0);t.addEventListener("abort",r,{once:!0}),e.then(o=>{t.removeEventListener("abort",r),n(o)},o=>{t.removeEventListener("abort",r),s(o)})}):e}async function te(e){const{launch:t,home:n,name:s,addArgs:r,plugins:o,signal:f,context:g}=e,l={...g,marketplace:s};let y=!1;const p=k(n,".tmp",`bishop-plugins-${I(6).toString("hex")}`);try{await N(p,{recursive:!0});const w=await P(p),u=a=>X(t.command,a,{cwd:t.cwd,env:{...t.env,CODEX_HOME:w},signal:f}),d=await u(r);if(d.code!==0)return O.warn({...l,error:d.output.trim()||"timed out"},"plugins from a marketplace failed to install"),{ok:!1,added:y};let h=!0;for(const a of o){const m=await u(["plugin","add","--json","--",a]),b=ne(m.stdout);if(m.code!==0||!b){O.warn({...l,plugin:a,error:m.output.trim()||"timed out"},"a plugin failed to install"),h=!1;continue}const i=M(b),x=W(w,i);if(x.startsWith("..")||T(x)||!x.startsWith(k("plugins","cache")+$)){O.warn({...l,plugin:a,path:b},"codex installed a plugin somewhere Bishop did not expect"),h=!1;continue}const v=k(n,x);await A(k(v,R(b))).catch(()=>{})||(await re(i,v,w),y=!0)}return h&&O.info({...l,plugins:o},"installed plugins from a marketplace"),{ok:h,added:y}}catch(w){return O.warn({...l,err:w},"plugins from a marketplace failed to install"),{ok:!1,added:y}}finally{await H(p,{recursive:!0,force:!0}).catch(()=>{})}}function ne(e){try{const t=JSON.parse(e);return typeof t.installedPath=="string"?t.installedPath:void 0}catch{return}}async function re(e,t,n){await N(M(t),{recursive:!0});const s=k(n,`replaced-${I(4).toString("hex")}`),r=await E(t,s).then(()=>!0,o=>{if(o.code!=="ENOENT")throw o;return!1});try{await E(e,t)}catch(o){const f=o.code;if(f==="ENOTEMPTY"||f==="EEXIST")return;throw r&&await E(s,t).catch(()=>{}),o}}export{_ as CODEX_DIR,he as WHOLE_KEYS,ge as agentHooks,be as agentInstructions,K as combineLists,F as enabledPlugins,ke as hasProjectConfig,me as hookApprovals,Oe as inspectProject,xe as installPlugins,S as tomlInline,pe as trustOverride,q as trustedDirs,ye as yieldToAgent,we as yieldToOperatorConfig};
1
+ import{spawn as B}from"node:child_process";import{randomBytes as N}from"node:crypto";import{mkdir as P,realpath as M,rename as E,rm as H,stat as A}from"node:fs/promises";import{basename as R,dirname as v,isAbsolute as T,join as b,relative as W,resolve as G,sep as $}from"node:path";import{createInterface as U}from"node:readline";import{exec as X}from"../exec.js";import{log as O}from"../log.js";import{SERVER_NAME as L}from"../tools/server.js";import{isPlainObject as c,PLUGIN_INSTALL_TIMEOUT_MS as Y,unionLists as z,untilAborted as F}from"./layers.js";const C=1e4,_=".codex";function S(e){return typeof e=="string"?JSON.stringify(e):typeof e=="number"?Number.isNaN(e)?"nan":Number.isFinite(e)?String(e):e>0?"inf":"-inf":typeof e=="boolean"?String(e):Array.isArray(e)?`[${e.filter(t=>t!=null).map(S).join(",")}]`:c(e)?`{${Object.entries(e).filter(([,n])=>n!=null).map(([n,r])=>`${JSON.stringify(n)}=${S(r)}`).join(",")}}`:JSON.stringify(String(e))}function D(e,t){const n=c(e)?{...e}:{};for(const[r,s]of Object.entries(t)){const i=Object.hasOwn(n,r)?n[r]:void 0;n[r]=c(i)&&c(s)?{...i,...s}:s}return n}function pe(e,t){const n=Object.fromEntries(e.map(r=>[r,{trust_level:"trusted"}]));return`projects=${S(D(t,n))}`}function me(e,t){if(e.length===0)return;const n=Object.fromEntries(e.map(i=>[i.key,{trusted_hash:i.currentHash}])),r=c(t)?t:{},s={...r,state:D(r.state,n)};return`hooks=${S(s)}`}function K(e){const t=e?.plugins;return c(t)?Object.entries(t).filter(([,n])=>c(n)&&n.enabled===!0).map(([n])=>n):[]}function ge(e,t,n){const r=n.map(s=>b(s,_)+$);return e.filter(s=>s.source==="project"&&r.some(i=>s.sourcePath?.startsWith(i)??!1)||s.source==="plugin"&&s.pluginId!==null&&t.includes(s.pluginId))}function q(e,t){return Array.isArray(e)&&Array.isArray(t)?z(t,e):c(e)&&c(t)?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,q(r,Object.hasOwn(t,n)?t[n]:void 0)])):e}const he=["mcp_servers","notify","hooks","projects"];function j(e,t){let n=e;for(const r of t){if(!c(n)||!Object.hasOwn(n,r))return;n=n[r]}return n}const J=[{option:"sandboxMode",key:["sandbox_mode"]},{option:"networkAccessEnabled",key:["sandbox_workspace_write","network_access"]}];function we(e,t){const n=c(t?.config)?t.config:void 0,r={...e};for(const{option:s,key:i}of J)!(t!==void 0&&Object.hasOwn(t,s))&&j(n,i)!==void 0&&delete r[s];return r}function ye(e,t,n){const r=c(t?.config)?t.config:void 0,s={...e},i=[];for(const{option:f,key:g}of J)!(t!==void 0&&Object.hasOwn(t,f)||j(r,g)!==void 0)&&j(n,g)!==void 0&&Object.hasOwn(s,f)&&(delete s[f],i.push(f));return{options:s,yielded:i}}function ke(e){const t=e.developer_instructions;return typeof t=="string"&&t.trim()?t:void 0}async function be(e){return(await A(b(e,_)).catch(()=>{}))?.isDirectory()??!1}async function V(e){const t=await M(e).catch(()=>e);return[...new Set([e,t])]}async function Q(e,t,n,r){const s=B(e.command,[...t,"app-server"],{cwd:e.cwd,env:e.env,stdio:["pipe","pipe","pipe"],...r?{signal:r,killSignal:"SIGKILL"}:{}});let i="";s.stderr.setEncoding("utf8"),s.stderr.on("data",p=>{i=(i+p).slice(-2e3)}),s.stdin.on("error",()=>{});const f=U({input:s.stdout}),g=[];let d=0;const y=p=>s.stdin.write(`${JSON.stringify(p)}
2
+ `);try{return await new Promise((p,w)=>{const u=setTimeout(()=>w(new Error(`codex app-server didn't answer within ${C}ms`)),C),l=a=>{clearTimeout(u),a?w(a):p(g)},h=()=>{const a=n[d];if(!a)return l();d+=1,y({id:d,...a})};f.on("line",a=>{let m;try{m=JSON.parse(a)}catch{return}m.id===d&&(g.push(m),d===1&&y({method:"initialized"}),h())}),s.on("error",a=>l(a)),s.on("exit",a=>l(new Error(`codex app-server exited with code ${a}: ${i.trim()}`))),h()})}finally{f.close(),s.stdin.end(),s.kill()}}async function Oe(e,t,n){const r=e.cwd;let s;try{s=await Q(e,t.flatMap(o=>["-c",o]),[{method:"initialize",params:{clientInfo:{name:"bishop",version:"0"}}},{method:"config/read",params:{includeLayers:!0,cwd:r}},{method:"hooks/list",params:{cwds:[r]}}],n)}catch(o){return{ok:!1,reason:o instanceof Error?o.message:String(o)}}const[,i,f]=s;if(i?.error)return{ok:!1,reason:i.error.message??"config/read failed"};const g=i?.result?.layers,d=(await V(r)).map(o=>b(o,_)),p=(Array.isArray(g)?g:[]).find(o=>c(o)&&c(o.name)&&o.name.type==="project"&&d.includes(String(o.name.dotCodexFolder))&&!o.disabledReason&&c(o.config))?.config??{};if(c(p.mcp_servers)&&Object.hasOwn(p.mcp_servers,L))return{ok:!1,reason:`it declares an MCP server named "${L}", which is Bishop's`};f?.error&&O.warn({cwd:r,error:f.error.message},"codex couldn't list the agent's hooks, so none are approved this turn");const w=f?.result?.data?.[0],u=c(w)?w:{},l=[u.warnings,u.errors].flatMap(o=>Array.isArray(o)?o:[]).map(o=>c(o)?String(o.message):String(o));l.length>0&&O.warn({cwd:r,warnings:l},"codex reported problems with the agent's hooks; it skips those");const h=(Array.isArray(u.hooks)?u.hooks:[]).filter(o=>c(o)&&typeof o.key=="string"&&typeof o.currentHash=="string"),a=i?.result?.config,m=c(a)?a.plugins:void 0,k=c(m)?Object.entries(m).filter(([,o])=>c(o)&&o.enabled===!1).map(([o])=>o):[];return{ok:!0,project:{config:p,hooks:h,disabledPlugins:k}}}function Z(e,t){if(typeof e.source!="string"||!e.source)return;const n=e.source_type==="local"&&!T(e.source)?G(t,e.source):e.source,r=typeof e.ref=="string"&&e.ref?[`--ref=${e.ref}`]:[],s=Array.isArray(e.sparse_paths)?e.sparse_paths.filter(i=>typeof i=="string").map(i=>`--sparse=${i}`):[];return["plugin","marketplace","add",...r,...s,"--json","--",n]}function ee(e){const t=e.lastIndexOf("@");if(!(t<=0||t===e.length-1))return{plugin:e.slice(0,t),marketplace:e.slice(t+1)}}async function xe(e){const{launch:t,home:n,agent:r,operator:s,installed:i,context:f}=e,g=c(r.marketplaces)?r.marketplaces:{},d=new Map;for(const u of K(r)){if(j(s,["plugins",u,"enabled"])===!1||e.disabled?.includes(u))continue;const l=ee(u);if(l){if(!Object.hasOwn(g,l.marketplace)){await A(b(n,"plugins","cache",l.marketplace,l.plugin)).then(()=>!0).catch(()=>!1)||O.warn({...f,plugin:u},"the agent enables a plugin from a marketplace its config doesn't declare, so Bishop can't install it");continue}d.set(l.marketplace,[...d.get(l.marketplace)??[],u])}}const y=AbortSignal.timeout(e.timeoutMs??Y),p=[...d].flatMap(([u,l])=>{const h=g[u],a=c(h)?Z(h,t.cwd):void 0;if(!a)return O.warn({...f,marketplace:u},"the agent's marketplace declaration has no source, so its plugins aren't installed"),[];const m=JSON.stringify([n,a,l.sort()]),k=i.get(m);if(k?.done)return[];if(k)return[k.pending];const o={done:!1,pending:te({...e,name:u,addArgs:a,plugins:l,signal:y}).then(x=>(x.ok?o.done=!0:i.delete(m),x.added))};return i.set(m,o),[o.pending]});return p.length===0?!1:(await F(Promise.all(p),e.signal))?.some(Boolean)??!1}async function te(e){const{launch:t,home:n,name:r,addArgs:s,plugins:i,signal:f,context:g}=e,d={...g,marketplace:r};let y=!1;const p=b(n,".tmp",`bishop-plugins-${N(6).toString("hex")}`);try{await P(p,{recursive:!0});const w=await M(p),u=a=>X(t.command,a,{cwd:t.cwd,env:{...t.env,CODEX_HOME:w},signal:f}),l=await u(s);if(l.code!==0)return O.warn({...d,error:l.output.trim()||"timed out"},"plugins from a marketplace failed to install"),{ok:!1,added:y};let h=!0;for(const a of i){const m=await u(["plugin","add","--json","--",a]),k=ne(m.stdout);if(m.code!==0||!k){O.warn({...d,plugin:a,error:m.output.trim()||"timed out"},"a plugin failed to install"),h=!1;continue}const o=v(k),x=W(w,o);if(x.startsWith("..")||T(x)||!x.startsWith(b("plugins","cache")+$)){O.warn({...d,plugin:a,path:k},"codex installed a plugin somewhere Bishop did not expect"),h=!1;continue}const I=b(n,x);await A(b(I,R(k))).catch(()=>{})||(await re(o,I,w),y=!0)}return h&&O.info({...d,plugins:i},"installed plugins from a marketplace"),{ok:h,added:y}}catch(w){return O.warn({...d,err:w},"plugins from a marketplace failed to install"),{ok:!1,added:y}}finally{await H(p,{recursive:!0,force:!0}).catch(()=>{})}}function ne(e){try{const t=JSON.parse(e);return typeof t.installedPath=="string"?t.installedPath:void 0}catch{return}}async function re(e,t,n){await P(v(t),{recursive:!0});const r=b(n,`replaced-${N(4).toString("hex")}`),s=await E(t,r).then(()=>!0,i=>{if(i.code!=="ENOENT")throw i;return!1});try{await E(e,t)}catch(i){const f=i.code;if(f==="ENOTEMPTY"||f==="EEXIST")return;throw s&&await E(r,t).catch(()=>{}),i}}export{_ as CODEX_DIR,he as WHOLE_KEYS,ge as agentHooks,ke as agentInstructions,q as combineLists,K as enabledPlugins,be as hasProjectConfig,me as hookApprovals,Oe as inspectProject,xe as installPlugins,S as tomlInline,pe as trustOverride,V as trustedDirs,ye as yieldToAgent,we as yieldToOperatorConfig};
@@ -1 +1 @@
1
- function o(e){const n={...e.defaults,...e.configOptions};for(const[r,t]of Object.entries(e.general??{}))t!==void 0&&(n[r]=t);for(const r of e.controlledKeys)delete n[r];return n}function i(e,n){return!e||!n?[]:Object.entries(n).filter(([r,t])=>t!==void 0&&r in e).map(([r])=>r)}function s(e,n){return e?n.filter(r=>r in e):[]}function f(e,n){if(!(!e&&Object.keys(n).length===0))return{...process.env,...e,...n}}const u=6e4;function c(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function d(e,n){const r=new Set(e.map(t=>JSON.stringify(t)));return[...e,...n.filter(t=>!r.has(JSON.stringify(t)))]}export{u as PLUGIN_INSTALL_TIMEOUT_MS,s as ignoredKeys,c as isPlainObject,o as layerOptions,f as mergeEnv,i as shadowedKeys,d as unionLists};
1
+ function f(e){const t={...e.defaults,...e.configOptions};for(const[r,n]of Object.entries(e.general??{}))n!==void 0&&(t[r]=n);for(const r of e.controlledKeys)delete t[r];return t}function u(e,t){return!e||!t?[]:Object.entries(t).filter(([r,n])=>n!==void 0&&r in e).map(([r])=>r)}function s(e,t){return e?t.filter(r=>r in e):[]}function d(e,t){if(!(!e&&Object.keys(t).length===0))return{...process.env,...e,...t}}const c=6e4;function y(e,t){return t?t.aborted?Promise.resolve(void 0):new Promise((r,n)=>{const o=()=>r(void 0);t.addEventListener("abort",o,{once:!0}),e.then(i=>{t.removeEventListener("abort",o),r(i)},i=>{t.removeEventListener("abort",o),n(i)})}):e}function b(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function p(e,t){const r=new Set(e.map(n=>JSON.stringify(n)));return[...e,...t.filter(n=>!r.has(JSON.stringify(n)))]}export{c as PLUGIN_INSTALL_TIMEOUT_MS,s as ignoredKeys,b as isPlainObject,f as layerOptions,d as mergeEnv,u as shadowedKeys,p as unionLists,y as untilAborted};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentdeploymentco/bishop",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "An agent gateway. Connects an agent to Slack, email, and Microsoft Teams.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -45,10 +45,10 @@
45
45
  "docs:preview": "npm --prefix docs run preview --"
46
46
  },
47
47
  "dependencies": {
48
- "@anthropic-ai/claude-agent-sdk": "0.3.310",
48
+ "@anthropic-ai/claude-agent-sdk": "0.3.316",
49
49
  "@microsoft/teams.apps": "^2.0.16",
50
50
  "@modelcontextprotocol/sdk": "^1.30.0",
51
- "@openai/codex-sdk": "0.164.0",
51
+ "@openai/codex-sdk": "0.166.0",
52
52
  "@slack/bolt": "^5.1.0",
53
53
  "@slack/types": "^3.2.0",
54
54
  "@slack/web-api": "^8.2.0",