buddy-agent-harness 0.13.0 → 0.14.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.
Files changed (36) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.codex-plugin/plugin.json +1 -1
  3. package/.cursor-plugin/plugin.json +1 -1
  4. package/dist/cli.mjs +1 -1
  5. package/dist/index.d.mts +1 -1
  6. package/dist/index.mjs +1 -1
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/skill-scripts/doctor.mjs +2 -2
  9. package/dist/skill-scripts/init.mjs +2 -2
  10. package/dist/skill-scripts/mcp.mjs +2 -2
  11. package/dist/skill-scripts/reference.mjs +2 -2
  12. package/package.json +1 -1
  13. package/plugin.json +1 -1
  14. package/skills/doctor-buddy-agent-harness/SKILL.md +1 -1
  15. package/skills/doctor-buddy-agent-harness/references/harnesses/copilot-cli.md +2 -2
  16. package/skills/doctor-buddy-agent-harness/references/harnesses/cursor.md +1 -1
  17. package/skills/doctor-buddy-agent-harness/references/harnesses/gemini-cli.md +1 -1
  18. package/skills/doctor-buddy-agent-harness/references/harnesses/windsurf.md +1 -1
  19. package/skills/doctor-buddy-agent-harness/scripts/doctor.mjs +2 -2
  20. package/skills/init-buddy-agent-harness/SKILL.md +5 -3
  21. package/skills/init-buddy-agent-harness/references/harnesses/cursor.md +14 -8
  22. package/skills/init-buddy-agent-harness/scripts/doctor.mjs +2 -2
  23. package/skills/init-buddy-agent-harness/scripts/init.mjs +2 -2
  24. package/skills/reference/README.md +53 -0
  25. package/skills/reference/SKILL.md +77 -0
  26. package/skills/reference/references/create.md +56 -0
  27. package/skills/{load-reference/SKILL.md → reference/references/load.md} +2 -7
  28. package/skills/{load-reference → reference}/scripts/reference.mjs +2 -2
  29. package/skills/repair/SKILL.md +1 -1
  30. package/skills/repair/scripts/doctor.mjs +2 -2
  31. package/skills/repair/scripts/mcp.mjs +2 -2
  32. package/src/diagnose-bridges/doctor-guidance.ts +2 -2
  33. package/src/references/{load-reference-invocation.ts → reference-invocation.ts} +3 -3
  34. package/src/references/reference.command.ts +1 -1
  35. package/src/skill-scripts/launchers.ts +1 -1
  36. package/skills/load-reference/README.md +0 -33
@@ -90,7 +90,7 @@ ${toPrettyType(e.config)}`:``}function toPrettyType(e){return tersify(toTypeObje
90
90
  `)?e:`${e}\n`)}function encodeResult(e,t){return t===`json`?JSON.stringify(e):t===`text`?renderText(e):encode(e)}function cell(e){return e===void 0?``:String(e)}function table(e){let t=[...new Set(e.flatMap(e=>Object.keys(e)))],n=t.map(t=>Math.max(t.length,...e.map(e=>cell(e[t]).length))),line=e=>` ${e.map((e,t)=>e.padEnd(n[t])).join(` `)}`.trimEnd();return[line(t),...e.map(e=>line(t.map(t=>cell(e[t]))))]}function renderText(e){let t=Object.entries(e).map(([e,t])=>{if(!Array.isArray(t))return[`${e}: ${isRecord$1(t)?JSON.stringify(t):String(t)}`];if(!t.length)return[`${e}: (none)`];let n=t.every(isRecord$1)?table(t):t.map(e=>` - ${String(e)}`);return[`${e}:`,...n]});return t.flatMap((e,n)=>{let r=t[n-1];return r&&(r.length>1||e.length>1)?[``,...e]:e}).join(`
91
91
  `)}function collapseHome(e,t){return e&&t.startsWith(e+C)?`~${t.slice(e.length)}`:t}function displayBinPath(e,t){return t?collapseHome(e,t):`buddy-agent-harness`}const ua=new Set([`deps`,`dependencies`,`local`,`plugins`,`marketplace`,`plugin`,`default`]);function isGenericName(e){return ua.has(e.toLowerCase())}function marketplaceName$1(e){return e.replace(/^@/,``).replace(/\//g,`-`).replace(/[^a-zA-Z0-9-_.]/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``)||`agent-plugins`}__name(marketplaceName$1,`marketplaceName`);function declaredDependencies(e){if(!e||typeof e!=`object`)return[];let t=e,n=new Set;for(let e of[`dependencies`,`devDependencies`]){let r=t[e];if(r&&typeof r==`object`)for(let e of Object.keys(r))n.add(e)}return[...n].sort()}function buildCatalog({name:e,owner:t,plugins:n}){let r=[...n].sort((e,t)=>e.plugin.localeCompare(t.plugin)).map(({plugin:e,package:t,version:n,description:r})=>{let i={source:`npm`,package:t,version:n};return r?{name:e,source:i,description:r}:{name:e,source:i}});return{name:e,owner:{name:t},description:`Plugins provided by this repository’s dependencies. Generated — do not edit.`,plugins:r}}function serializeCatalog(e){return`${JSON.stringify(e,null,` `)}\n`}function readJson$2(e){try{return JSON.parse(o(e,`utf8`))}catch{return}}__name(readJson$2,`readJson`);function ancestorCandidates(e,t){let n=t.split(`/`),r=[],i=e;for(;;){r.push(v(i,`node_modules`,...n));let e=g(i);if(e===i)break;i=e}return r}function packageDir(t,n){try{let r=e(n);return g(r.resolve(`${t}/package.json`))}catch{}for(let e of ancestorCandidates(g(n),t))if(r(v(e,`package.json`)))return e}function readDepPlugin(e,t){let n=packageDir(e,t);if(!n)return{ok:!1,package:e,reason:`unresolved`};let r=readJson$2(v(n,`plugin.json`));if(!r||typeof r!=`object`)return{ok:!1,package:e,reason:`no-manifest`};let i=r,a=typeof i.name==`string`?i.name:void 0;if(!a)return{ok:!1,package:e,reason:`unnamed`};let o=readJson$2(v(n,`package.json`)),s=typeof o?.version==`string`?o.version:void 0;if(!s)return{ok:!1,package:e,reason:`no-manifest`};let c=typeof i.description==`string`?i.description:void 0;return{ok:!0,plugin:c?{package:e,plugin:a,version:s,description:c}:{package:e,plugin:a,version:s}}}function isPnp(){return!!process.versions.pnp}const da=v(`.agents`,`buddy-agent-harness`),fa=v(da,`.claude-plugin`,`marketplace.json`);function readManifest(e){return JSON.parse(o(e,`utf8`))}function deriveCatalog(e){let t=v(e,`package.json`),n=readManifest(t),r=[],i=[];for(let e of declaredDependencies(n)){let n=readDepPlugin(e,t);n.ok?r.push(n.plugin):n.reason===`unresolved`&&i.push({package:e,reason:n.reason})}let a=typeof n.name==`string`?n.name:`unknown`,o=marketplaceName$1(a);return{catalog:buildCatalog({name:o,owner:a,plugins:r}),plugins:r,unresolved:i,genericName:isGenericName(o),pnp:isPnp()}}function catalogStatus(e,t){let n;try{n=o(v(e,fa),`utf8`)}catch{n=void 0}return n===serializeCatalog(t)?`unchanged`:n===void 0?`created`:`updated`}function writeCatalog(e,t){let n=catalogStatus(e,t);if(n===`unchanged`)return n;let r=v(e,fa);return a(g(r),{recursive:!0}),m(r,serializeCatalog(t)),n}function readJson$1(e){try{return JSON.parse(o(e,`utf8`))}catch{return}}__name(readJson$1,`readJson`);function directories$1(e){try{return s(e,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}__name(directories$1,`directories`);function claudeConfigDir(e,t=process.env){return t.CLAUDE_CONFIG_DIR||v(e,`.claude`)}function readClaudeState(e){let t=readJson$1(v(e,`plugins`,`installed_plugins.json`)),n=[];for(let[e,r]of Object.entries(t?.plugins??{}))if(Array.isArray(r))for(let t of r){if(!t||typeof t!=`object`)continue;let r=t,i=typeof r.version==`string`?r.version:void 0,a=typeof r.scope==`string`?r.scope:void 0;if(!i||!a)continue;let o=typeof r.projectPath==`string`?r.projectPath:void 0;n.push(o?{id:e,version:i,scope:a,projectPath:o}:{id:e,version:i,scope:a})}let r=readJson$1(v(e,`plugins`,`known_marketplaces.json`)),i=[];for(let[e,t]of Object.entries(r??{}))i.push({name:e,path:typeof t?.source?.path==`string`?t.source.path:``});return{installed:n,marketplaces:i}}const pa={name:`claude-code`,scoped:!0,installedOnMachine:(e,t=process.env)=>r(claudeConfigDir(e,t)),state:(e,t=process.env)=>readClaudeState(claudeConfigDir(e,t)),register:e=>`claude plugin marketplace add ./${e} --scope project`,install:e=>`claude plugin install ${e} --scope project`,update:e=>`claude plugin update ${e} --scope project`,uninstall:e=>`claude plugin uninstall ${e} --scope project`,refreshMarketplace:e=>`claude plugin marketplace update ${e}`};function codexHome(e,t=process.env){return t.CODEX_HOME||v(e,`.codex`)}function readCodexState(e){let t=v(e,`plugins`,`cache`),n=[];for(let e of directories$1(t))for(let r of directories$1(v(t,e)))for(let i of directories$1(v(t,e,r)))n.push({id:`${r}@${e}`,version:i,scope:`user`});let r=[],i=``;try{i=o(v(e,`config.toml`),`utf8`)}catch{i=``}let a;for(let e of i.split(`
92
92
  `)){let t=/^\s*\[marketplaces\.(?:"([^"]+)"|([^\]]+))\]\s*$/.exec(e);if(t){a={name:t[1]??t[2],path:``},r.push(a);continue}if(/^\s*\[/.test(e)){a=void 0;continue}let n=a?/^\s*source\s*=\s*"([^"]*)"\s*$/.exec(e):void 0;n?.[1]&&a&&(a.path=n[1])}return{installed:n,marketplaces:r}}const ma=[pa,{name:`codex`,scoped:!1,installedOnMachine:(e,t=process.env)=>r(codexHome(e,t)),state:(e,t=process.env)=>readCodexState(codexHome(e,t)),register:e=>`codex plugin marketplace add ./${e}`,install:e=>`codex plugin add ${e}`,update:e=>`codex plugin add ${e}`,uninstall:e=>`codex plugin remove ${e}`,refreshMarketplace:()=>``}];function ours(e,t,n,r){let i=`@${t}`;return e.filter(e=>e.id.endsWith(i)&&(!r||e.projectPath===n))}function reconcile({catalog:e,catalogDir:t,root:n,installed:r,marketplaces:i,scoped:a=!0}){let o=i.find(t=>t.name===e.name),s=[],c=t.split(/[\\/]/).filter(Boolean),l=o?c.every(e=>o.path.includes(e)):!1,u=o&&!l?o.path:void 0;o||s.push({kind:`register`,subject:e.name,detail:`marketplace is not registered with this harness`});let d=ours(r,e.name,n,a),p=new Map(d.map(e=>[e.id,e]));for(let t of e.plugins){let n=`${t.name}@${e.name}`,r=p.get(n);if(!r){s.push({kind:`install`,subject:n,detail:`not installed; catalog pins ${t.source.version}`});continue}r.version!==t.source.version&&s.push({kind:`update`,subject:n,detail:`installed ${r.version}, catalog pins ${t.source.version}`})}let m=new Set(e.plugins.map(t=>`${t.name}@${e.name}`));for(let e of d)m.has(e.id)||s.push({kind:`uninstall`,subject:e.id,detail:`installed but no longer in the catalog; it will report a load failure until removed`});return{actions:s,...u?{collision:u}:{},unregistered:!o}}function commandFor(e,t,n){switch(t.kind){case`register`:return e.register(da);case`install`:return e.install(t.subject);case`update`:{let r=e.refreshMarketplace(n),i=e.update(t.subject);return r?`${r} && ${i}`:i}case`uninstall`:return e.uninstall(t.subject)}}function notesFor(e){let t=[];e.pnp&&t.push(`Yarn Plug’n’Play is active: dependencies live inside zip archives, so no harness can install from them. Set nodeLinker: node-modules, or unplug the plugin dependencies.`),e.genericName&&t.push(`Marketplace name "${e.catalog.name}" is generic. Registering a second marketplace under a name already in use replaces the first silently, and the install that follows reports "already installed" — the repository then runs the other one's versions.`);for(let{package:n}of e.unresolved)t.push(`Declared dependency "${n}" is not installed; install dependencies before generating.`);return t}const ha=command({name:`dep-plugins`,description:`Derive the marketplace catalog for plugins shipped by this repository’s dependencies, so a harness can install them. Writes the catalog; installing is the harness’s own job.`,options:{root:{description:`Repository directory. Defaults to the current directory.`,type:q(K())},check:{description:`Report whether the catalog is current without writing it. For CI and postinstall.`,type:q(Fn())},format:{description:`Output format: toon (default), json, or text for a human-readable report.`,type:q(K()),default:`toon`}},run(e){try{let t=parseFormat(e.format),n=e.root??process.cwd(),r=deriveCatalog(n),i=e.check?catalogStatus(n,r.catalog)===`unchanged`?`current`:`would-change`:writeCatalog(n,r.catalog),a=E(),o=notesFor(r),s=ma.filter(e=>e.installedOnMachine(a)),c=[],l=[];for(let e of s){let t=e.state(a),i=reconcile({catalog:r.catalog,catalogDir:da,root:S(n),installed:t.installed,marketplaces:t.marketplaces,scoped:e.scoped});i.collision&&o.push(`${e.name}: marketplace "${r.catalog.name}" is already registered against ${i.collision}. Registering over it replaces the other repository's silently, and the install that follows reports "already installed" — rename this repository's marketplace instead.`),c.push({runtime:e.name,status:i.actions.length?`${i.actions.length} to apply`:`in sync`});for(let t of i.actions)l.push({runtime:e.name,do:commandFor(e,t,r.catalog.name),subject:t.subject,why:t.detail})}return r.plugins.length&&o.push(`Copilot CLI rejects an npm marketplace source, so it cannot install from this catalog. It needs a path-sourced catalog, which cannot reach node_modules from a subdirectory.`),writeResult({catalog:fa,marketplace:r.catalog.name,outcome:i,plugins:r.plugins.length?r.plugins.map(({plugin:e,package:t,version:n})=>({name:e,package:t,version:n})):`0 dependencies ship a plugin — nothing to install`,harness:c.length?c:`no supported harness detected on this machine`,actions:l.length?l:`0 actions — every detected harness matches the catalog`,...o.length?{notes:o}:{}},t),i===`would-change`?O.error:O.success}catch(e){return process.stderr.write(`error: ${e instanceof Error?e.message:`Catalog generation failed.`}\n`),O.error}}});function filesUnder(e){try{return s(e,{recursive:!0,withFileTypes:!0}).filter(e=>e.isFile()).map(t=>x(e,v(t.parentPath,t.name)).split(C).join(b.sep)).sort()}catch{return[]}}const isOne=e=>e===`1`,isSet=e=>e!==``,ga={name:`CLAUDECODE`,matches:isOne,description:`Claude Code sets CLAUDECODE=1 in subprocesses it spawns; IDE extensions also set it in integrated terminals`,research:`E-CC-D1`},_a=[{harness:`claude-code`,all:[ga,{name:`CLAUDE_CODE_CHILD_SESSION`,matches:isOne,description:`Claude Code sets CLAUDE_CODE_CHILD_SESSION=1 for tool, hook, and status line subprocesses`,research:`E-CC-D3`}]},{harness:`claude-code`,all:[ga,{name:`CLAUDE_CODE_SESSION_ID`,matches:isSet,description:`Claude Code sets CLAUDE_CODE_SESSION_ID in tool, hook, and stdio MCP server subprocesses`,research:`E-CC-D6`}]},{harness:`cursor`,all:[{name:`CURSOR_AGENT`,matches:isOne,description:`Cursor sets CURSOR_AGENT=1 on terminal commands its agent runs`,research:`E-CUR-D1`}]},{harness:`cursor`,all:[{name:`CURSOR_VERSION`,matches:isSet,description:`Cursor sets CURSOR_VERSION for hook commands`,research:`E-CUR-D10`},{name:`CURSOR_PROJECT_DIR`,matches:isSet,description:`Cursor sets CURSOR_PROJECT_DIR for hook commands`,research:`E-CUR-D10`}]},{harness:`codex`,all:[{name:`CODEX_THREAD_ID`,matches:isSet,description:`Codex injects CODEX_THREAD_ID into shell tool commands, even under a restrictive shell env policy`,research:`E-CODEX-D2`}]},{harness:`copilot-cli`,all:[{name:`COPILOT_CLI`,matches:isOne,description:`Copilot CLI sets COPILOT_CLI=1 in its subprocesses`,research:`E-COPILOT-D1`}]},{harness:`copilot-cli`,all:[{name:`COPILOT_AGENT_SESSION_ID`,matches:isSet,description:`Copilot CLI passes COPILOT_AGENT_SESSION_ID to shell commands and MCP servers`,research:`E-COPILOT-D2`}]},{harness:`copilot-cli`,all:[{name:`COPILOT_PLUGIN_ROOT`,matches:isSet,description:`Copilot CLI passes COPILOT_PLUGIN_ROOT to plugin hooks`,research:`E-COPILOT-D6`}]},{harness:`opencode`,all:[{name:`OPENCODE`,matches:isOne,description:`OpenCode sets OPENCODE=1 for shell tool commands and MCP servers; Kilo Code, its fork, sets it too`,research:`E-OC-D1`},{name:`OPENCODE_PID`,matches:isSet,description:`OpenCode sets OPENCODE_PID for shell tool commands and MCP servers; Kilo Code sets KILO_PID instead`,research:`E-OC-D2`}]},{harness:`kilo`,all:[{name:`KILO`,matches:isOne,description:`Kilo Code sets KILO=1 for shell tool commands and MCP servers`,research:`E-KILO-D2`},{name:`KILO_PID`,matches:isSet,description:`Kilo Code sets KILO_PID for shell tool commands and MCP servers`,research:`E-KILO-D1`}]},{harness:`gemini-cli`,all:[{name:`GEMINI_CLI`,matches:isOne,description:`Gemini CLI sets GEMINI_CLI=1 for shell tool commands and MCP stdio servers`,research:`E-GEM-D1`}]},{harness:`qwen-code`,all:[{name:`QWEN_CODE`,matches:isOne,description:`Qwen Code sets QWEN_CODE=1 for shell tool commands, not for MCP servers or hooks`,research:`E-QWEN-D1`}]},{harness:`vscode-copilot`,all:[{name:`COPILOT_AGENT`,matches:isOne,description:`VS Code 1.121+ sets COPILOT_AGENT=1 on terminals its Copilot agent runs commands in`,research:`E-VSC-D1`}]},{harness:`cline`,all:[{name:`CLINE_ACTIVE`,matches:e=>e===`true`,description:`Cline's VS Code extension sets CLINE_ACTIVE=true on the terminals it creates; the Cline CLI does not`,research:`E-CLINE-D1`}]},{harness:`crush`,all:[{name:`CRUSH`,matches:isOne,description:`Crush sets CRUSH=1 for bash tool and hook commands, not for MCP servers`,research:`E-CRUSH-D1`}]},{harness:`openhands`,all:[{name:`AI_AGENT`,matches:e=>e===`openhands`,description:`OpenHands sets AI_AGENT=openhands for terminal tool and hook commands when AI_AGENT is unset; other vendors use the name with other values`,research:`E-OH-D1`}]},{harness:`openhands`,all:[{name:`OPENHANDS_EVENT_TYPE`,matches:isSet,description:`OpenHands sets OPENHANDS_EVENT_TYPE for hook commands`,research:`E-OH-D4`},{name:`OPENHANDS_PROJECT_DIR`,matches:isSet,description:`OpenHands sets OPENHANDS_PROJECT_DIR for hook commands`,research:`E-OH-D4`}]},{harness:`augment`,all:[{name:`AUGMENT_HOOK_EVENT`,matches:isSet,description:`The Auggie CLI sets AUGMENT_HOOK_EVENT for hook commands; its shell commands carry no marker`,research:`E-AUG-D3`},{name:`AUGMENT_PROJECT_DIR`,matches:isSet,description:`The Auggie CLI sets AUGMENT_PROJECT_DIR for hook commands`,research:`E-AUG-D3`}]}];function detectHarness(e={}){let t=e.env??process.env,n=[],r=[];for(let e of _a){let i=e.all.filter(e=>{let n=t[e.name];return n!==void 0&&e.matches(n)});for(let t of i)n.some(n=>n.harness===e.harness&&n.signal===t.name)||n.push({harness:e.harness,signal:t.name,description:t.description,research:t.research});i.length===e.all.length&&!r.includes(e.harness)&&r.push(e.harness)}return{harness:r.length===1?r[0]:`unknown`,evidence:n,candidates:r}}function managedPolicyLocations(e,t={}){let n=t.platform??process.platform,r=t.env??process.env;return va[e](n,r)}const joinFor=e=>e===`win32`?w.join:b.join,dirnameFor=e=>e===`win32`?w.dirname:b.dirname;function opencodeFamily(e,t,n,r){let i={darwin:`/Library/Application Support/${n}`,linux:`/etc/${n}`,win32:w.join(t.ProgramData??`C:\\ProgramData`,n)}[e];return[...when(e===`darwin`,{kind:`macos-managed-preferences`,location:`ai.opencode.managed`,description:`MDM configuration profile; outranks the managed config folder`,research:r.preferences}),...when(i!==void 0,{kind:`directory`,location:i??``,description:`Managed config files; outrank user and project config`,research:r.directory})]}function geminiFamily(e,t,n){let r=e===`darwin`||e===`win32`?n.dirs[e]:n.dirs.linux,i=t[n.settingsVariable]||joinFor(e)(r,`settings.json`),a=t[n.defaultsVariable]||joinFor(e)(dirnameFor(e)(i),`system-defaults.json`);return[{kind:`file`,location:i,description:`System settings; outrank user and workspace settings. ${n.settingsVariable} overrides the path`,research:n.research},{kind:`file`,location:a,description:`System defaults; user and workspace settings override them. ${n.defaultsVariable} overrides the path`,research:n.research}]}const when=(e,...t)=>e?t:[],va={"claude-code":e=>{let t={darwin:`/Library/Application Support/ClaudeCode`,linux:`/etc/claude-code`,win32:`C:\\Program Files\\ClaudeCode`}[e],n=joinFor(e);return[{kind:`server`,location:`claude.ai admin console or a self-hosted Claude apps gateway`,description:`Server-managed settings; the highest-ranked managed source`,research:`E-CC-M6`},...when(e===`darwin`,{kind:`macos-managed-preferences`,location:`com.anthropic.claudecode`,description:`MDM configuration profile with the same top-level keys as managed-settings.json`,research:`E-CC-M6`}),...when(e===`win32`,{kind:`windows-registry`,location:`HKLM\\SOFTWARE\\Policies\\ClaudeCode`,description:`MDM or Group Policy; the Settings value holds managed-settings JSON`,research:`E-CC-M6`}),...when(t!==void 0,{kind:`file`,location:n(t??``,`managed-settings.json`),description:`Managed settings, same shape as settings.json`,research:`E-CC-M1`},{kind:`directory`,location:n(t??``,`managed-settings.d`),description:`Drop-in managed settings files, merged with managed-settings.json`,research:`E-CC-M1`},{kind:`file`,location:n(t??``,`managed-mcp.json`),description:`Managed MCP servers`,research:`E-CC-M1`}),...when(e===`win32`,{kind:`windows-registry`,location:`HKCU\\SOFTWARE\\Policies\\ClaudeCode`,description:`User-writable; used only when no other managed source delivers a policy key`,research:`E-CC-M6`})]},cursor:e=>{let t={darwin:`/Library/Application Support/Cursor/hooks.json`,linux:`/etc/cursor/hooks.json`,win32:`C:\\ProgramData\\Cursor\\hooks.json`}[e];return[...when(t!==void 0,{kind:`file`,location:t??``,description:`Enterprise hooks deployed by MDM; hooks only, not other enterprise settings`,research:`E-CUR-M1`}),{kind:`server`,location:`Cursor dashboard`,description:`Team hooks and other enterprise settings, synced from the dashboard`,research:`E-CUR-M1`}]},codex:(e,t)=>{let n={kind:`server`,location:`ChatGPT workspace admin settings`,description:`Cloud-managed requirements; outrank every local source`,research:`E-CODEX-M8`};return e===`win32`?[n,{kind:`file`,location:w.join(t.ProgramData??`C:\\ProgramData`,`OpenAI`,`Codex`,`requirements.toml`),description:`Admin-enforced requirements users cannot override`,research:`E-CODEX-M4`}]:[n,...when(e===`darwin`,{kind:`macos-managed-preferences`,location:`com.openai.codex`,description:`MDM keys requirements_toml_base64 (enforced) and config_toml_base64 (managed defaults)`,research:`E-CODEX-M6`}),{kind:`file`,location:`/etc/codex/requirements.toml`,description:`Admin-enforced requirements users cannot override`,research:`E-CODEX-M3`},{kind:`file`,location:`/etc/codex/managed_config.toml`,description:`Managed defaults; a user can override them within a session`,research:`E-CODEX-M2`},{kind:`file`,location:`/etc/codex/config.toml`,description:`System-wide config`,research:`E-CODEX-M1`}]},"copilot-cli":(e,t)=>{let n={darwin:`/Library/Application Support/GitHubCopilot/managed-settings.json`,linux:`/etc/github-copilot/managed-settings.json`,win32:w.join(t.ProgramFiles??`C:\\Program Files`,`GitHubCopilot`,`managed-settings.json`)}[e];return[...when(e===`darwin`,{kind:`macos-managed-preferences`,location:`com.github.copilot`,description:`MDM-managed settings; the highest-ranked source`,research:`E-COPILOT-M2`}),...when(e===`win32`,{kind:`windows-registry`,location:`HKLM\\SOFTWARE\\Policies\\GitHubCopilot`,description:`MDM-managed settings as REG_SZ values; the highest-ranked source`,research:`E-COPILOT-M2`}),{kind:`server`,location:`copilot/managed-settings.json in the enterprise's .github-private repository`,description:`Server-managed settings, fetched for the signed-in account`,research:`E-COPILOT-M3`},...when(n!==void 0,{kind:`file`,location:n??``,description:`File-based managed settings; on macOS and Linux it must be a root-owned regular file`,research:`E-COPILOT-M1`})]},opencode:(e,t)=>[...opencodeFamily(e,t,`opencode`,{directory:`E-OC-M1`,preferences:`E-OC-M1`}),{kind:`server`,location:`Remote config at the organization domain /.well-known/opencode`,description:`Organization defaults; the lowest-ranked config source, so user config overrides them`,research:`E-OC-M2`}],kilo:(e,t)=>opencodeFamily(e,t,`kilo`,{directory:`E-KILO-M1`,preferences:`E-KILO-M2`}),"gemini-cli":(e,t)=>geminiFamily(e,t,{settingsVariable:`GEMINI_CLI_SYSTEM_SETTINGS_PATH`,defaultsVariable:`GEMINI_CLI_SYSTEM_DEFAULTS_PATH`,dirs:{darwin:`/Library/Application Support/GeminiCli`,linux:`/etc/gemini-cli`,win32:`C:\\ProgramData\\gemini-cli`},research:`E-GEM-M1`}),"qwen-code":(e,t)=>geminiFamily(e,t,{settingsVariable:`QWEN_CODE_SYSTEM_SETTINGS_PATH`,defaultsVariable:`QWEN_CODE_SYSTEM_DEFAULTS_PATH`,dirs:{darwin:`/Library/Application Support/QwenCode`,linux:`/etc/qwen-code`,win32:`C:\\ProgramData\\qwen-code`},research:`E-QWEN-M1`}),"vscode-copilot":e=>[...when(e===`win32`,{kind:`windows-registry`,location:`Software\\Policies\\Microsoft\\VSCode`,description:`VS Code policies set by Group Policy (ADMX templates ship with VS Code)`,research:`E-VSC-M1`}),...when(e===`linux`,{kind:`file`,location:`/etc/vscode/policy.json`,description:`VS Code policies as JSON, read by VS Code 1.106 and later`,research:`E-VSC-M3`})],cline:()=>[{kind:`server`,location:`Cline Enterprise admin console`,description:`Provider, model, and tool policy pushed to clients; no local policy file is documented`,research:`E-CLINE-M1`}],crush:e=>when(e!==`win32`,{kind:`file`,location:`/etc/crush/crush.json`,description:`System config; the lowest-ranked source, so user and project config override it`,research:`E-CRUSH-M1`}),openhands:()=>[{kind:`server`,location:`OpenHands Cloud or Enterprise deployment`,description:`Organization controls held server-side; no local policy file is known`,research:`E-OH-D8`}],augment:(e,t)=>[{kind:`file`,location:e===`win32`?w.join(t.ProgramData||`C:\\ProgramData`,`augment`,`settings.json`):`/etc/augment/settings.json`,description:`System settings, read from the Auggie CLI bundle; its rank against user settings is not documented`,research:`E-AUG-M1`}]};function resolveHarnessEnvironment(e={}){return{env:e.env??process.env,homedir:e.homedir??E(),cwd:e.cwd??process.cwd(),platform:e.platform??process.platform}}async function readText(e){try{return await ne(e,`utf8`)}catch(e){if(e.code===`ENOENT`)return;throw e}}function stripJsonComments$1(e){let t=``,n=0;for(;n<e.length;){let r=e[n];if(r===`"`){let r=n+1;for(;r<e.length&&e[r]!==`"`;)r+=e[r]===`\\`?2:1;t+=e.slice(n,r+1),n=r+1}else if(r===`/`&&e[n+1]===`/`)for(;n<e.length&&e[n]!==`
93
- `;)n++;else if(r===`/`&&e[n+1]===`*`){let t=e.indexOf(`*/`,n+2);n=t===-1?e.length:t+2}else t+=r,n++}return t.replace(/,(\s*[}\]])/g,`$1`)}__name(stripJsonComments$1,`stripJsonComments`);function isRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function pluginStorage(e,t={}){return ya[e](resolveHarnessEnvironment(t))}const xdgConfig=({env:e,homedir:t})=>e.XDG_CONFIG_HOME||v(t,`.config`);function vscodeAgentPlugins({env:e,homedir:t,platform:n}){if(n===`win32`){let n=w.join(e.APPDATA||w.join(t,`AppData`,`Roaming`),`Code`);return{configDir:n,path:w.join(n,`agentPlugins`)}}let r=n===`darwin`?v(t,`Library`,`Application Support`,`Code`):v(t,`.config`,`Code`);return{configDir:r,path:v(r,`agentPlugins`)}}const ya={"claude-code":({env:e,homedir:t})=>{let n=e.CLAUDE_CONFIG_DIR||v(t,`.claude`),r=v(n,`plugins`);return{harness:`claude-code`,configDir:n,locations:[{kind:`plugin-cache`,path:v(r,`cache`),description:`Installed plugins as <marketplace>/<plugin>/<version>/`,research:`E-CC-P1`},{kind:`marketplaces`,path:v(r,`marketplaces`),description:`Marketplace checkouts`,research:`E-CC-P1`},{kind:`install-record`,path:v(r,`installed_plugins.json`),description:`Installs keyed by plugin@marketplace, each with scope, installPath, and version`,research:`E-CC-P2`},{kind:`enabled-record`,path:v(n,`settings.json`),description:`User settings; enabledPlugins maps plugin@marketplace to a boolean`,research:`E-CC-P3`}]}},cursor:({homedir:e})=>{let t=v(e,`.cursor`);return{harness:`cursor`,configDir:t,locations:[{kind:`local-plugins`,path:v(t,`plugins`,`local`),description:`Plugins under development, one folder each`,research:`E-CUR-P2`},{kind:`marketplaces`,path:v(t,`plugins`,`marketplaces`),description:`Marketplace checkouts`,research:`E-CUR-P3`}]}},codex:({env:e,homedir:t})=>{let n=e.CODEX_HOME||v(t,`.codex`);return{harness:`codex`,configDir:n,locations:[{kind:`plugin-cache`,path:v(n,`plugins`,`cache`),description:`Installed plugins as <marketplace>/<plugin>/<version>/`,research:`E-CODEX-P3`},{kind:`enabled-record`,path:v(n,`config.toml`),description:`User config; [plugins."<plugin>@<marketplace>"] tables carry enabled = <bool>`,research:`E-CODEX-P2`}]}},"copilot-cli":({env:e,homedir:t})=>{let n=e.COPILOT_HOME||v(t,`.copilot`);return{harness:`copilot-cli`,configDir:n,locations:[{kind:`installed-plugins`,path:v(n,`installed-plugins`),description:`Installed plugins as <marketplace>/<plugin>/, or _direct/<source-id>/ for direct installs`,research:`E-COPILOT-P9`},{kind:`install-record`,path:v(n,`config.json`),description:`Application state, including installedPlugins`,research:`E-COPILOT-P9`},{kind:`enabled-record`,path:v(n,`settings.json`),description:`User settings (JSON with comments); enabledPlugins maps plugin specs to a boolean`,research:`E-COPILOT-P4`}]}},opencode:e=>{let t=v(xdgConfig(e),`opencode`);return{harness:`opencode`,configDir:t,locations:[{kind:`local-plugins`,path:v(t,`plugins`),description:`JS/TS plugin modules loaded at startup; npm plugins are named in the plugin config array`,research:`E-OC-P2`}]}},kilo:e=>{let t=v(xdgConfig(e),`kilo`);return{harness:`kilo`,configDir:t,locations:[{kind:`local-plugins`,path:v(t,`plugin`),description:`JS/TS plugin modules loaded at startup; npm plugins are named in the plugin config array`,research:`E-KILO-P2`}]}},"gemini-cli":({env:e,homedir:t})=>{let n=v(e.GEMINI_CLI_HOME||t,`.gemini`),r=v(n,`extensions`);return{harness:`gemini-cli`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed extensions, one folder each with a gemini-extension.json manifest`,research:`E-GEM-P1`},{kind:`enabled-record`,path:v(r,`extension-enablement.json`),description:`Per-extension path-glob overrides that enable or disable it by folder, not a boolean`,research:`E-GEM-P3`}]}},"qwen-code":({env:e,homedir:t})=>{let n=e.QWEN_HOME||v(t,`.qwen`),r=v(n,`extensions`);return{harness:`qwen-code`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed extensions, one folder each with a qwen-extension.json manifest`,research:`E-QWEN-P1`},{kind:`enabled-record`,path:v(r,`extension-enablement.json`),description:`Extension enable/disable state, inherited from Gemini CLI's format`,research:`E-QWEN-P2`}]}},"vscode-copilot":e=>{let{configDir:t,path:n}=vscodeAgentPlugins(e);return{harness:`vscode-copilot`,configDir:t,locations:[{kind:`installed-plugins`,path:n,description:`Installed agent plugins as <host>/<org>/<repo>/`,research:`E-VSC-P3`}]}},cline:({homedir:e})=>{let t=v(e,`.cline`);return{harness:`cline`,configDir:t,locations:[{kind:`installed-plugins`,path:v(t,`plugins`,`_installed`),description:`Installed plugins, grouped by source: npm, git, remote, or local`,research:`E-CLINE-P3`}]}},crush:({env:e,homedir:t})=>({harness:`crush`,configDir:e.CRUSH_GLOBAL_CONFIG||v(e.XDG_CONFIG_HOME||v(t,`.config`),`crush`),locations:[]}),openhands:({env:e,homedir:t})=>{let n=e.OH_PERSISTENCE_DIR||e.OPENHANDS_PERSISTENCE_DIR||v(t,`.openhands`),r=v(n,`plugins`,`installed`);return{harness:`openhands`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed plugins, one folder each`,research:`E-OH-P3`},{kind:`enabled-record`,path:v(r,`.installed.json`),description:`Install metadata keyed by plugin name, each with enabled: <bool>`,research:`E-OH-P4`}]}},augment:({homedir:e})=>{let t=v(e,`.augment`);return{harness:`augment`,configDir:t,locations:[{kind:`marketplaces`,path:v(t,`plugins`,`marketplaces`),description:`Marketplace checkouts`,research:`E-AUG-P2`},{kind:`enabled-record`,path:v(t,`settings.json`),description:`User settings; enabledPlugins maps plugin@marketplace to a boolean`,research:`E-AUG-P4`}]}}};async function enabledPlugins(e,t={}){let n=Ca[e](resolveHarnessEnvironment(t),t.managedSettingsPath),r=new Map,i=[];for(let e of n.sources){let t;try{let n=await readText(e.path);if(n===void 0){i.push({scope:e.scope,path:e.path,found:!1});continue}t=e.parse(n)}catch(t){i.push({scope:e.scope,path:e.path,found:!0,error:String(t)});continue}i.push({scope:e.scope,path:e.path,found:!0});for(let[n,i]of Object.entries(t))r.has(n)||r.set(n,{id:n,enabled:i,scope:e.scope,source:e.path})}return{harness:e,supported:n.supported,plugins:[...r.values()],sources:i,unread:n.unread,research:n.research}}function jsonEnabledPlugins(e){let t=JSON.parse(e),n=isRecord(t)?t.enabledPlugins:void 0;return isRecord(n)?Object.fromEntries(Object.entries(n).filter(e=>typeof e[1]==`boolean`)):{}}const ba=/^\[\s*plugins\s*\.\s*(?:"([^"]*)"|'([^']*)'|([A-Za-z0-9_-]+))\s*\]\s*(?:#.*)?$/,xa=/^enabled\s*=\s*(true|false)\s*(?:#.*)?$/;function tomlEnabledPlugins(e){let t={},n;for(let r of e.split(/\r?\n/)){let e=r.trim();if(e.startsWith(`[`)){let t=ba.exec(e);n=t?t[1]??t[2]??t[3]:void 0;continue}let i=n===void 0?null:xa.exec(e);n!==void 0&&i&&(t[n]=i[1]===`true`)}return t}const Sa={server:`server-managed settings`,"macos-managed-preferences":`MDM managed preferences`,"windows-registry":`Windows registry policy`,directory:`drop-in managed settings`,file:`managed file`};function unreadPolicy(e,t,n=[]){return e.filter(e=>e.location!==t&&!n.some(t=>e.location.endsWith(t))).map(e=>`${Sa[e.kind]} (${e.location})`)}function managedFile(e,t){return e.find(e=>e.kind===`file`&&e.location.endsWith(t))?.location}function jsoncEnabledPlugins(e){return jsonEnabledPlugins(stripJsonComments$1(e))}const unsupported$1=(...e)=>({supported:!1,sources:[],unread:[],research:e}),Ca={"claude-code":(e,t)=>{let{configDir:n}=pluginStorage(`claude-code`,e),r=managedPolicyLocations(`claude-code`,e),i=managedFile(r,`managed-settings.json`),a=t??i,o=v(e.cwd,`.claude`);return{supported:!0,sources:[...a===void 0?[]:[{scope:`managed`,path:a,parse:jsonEnabledPlugins}],{scope:`local`,path:v(o,`settings.local.json`),parse:jsonEnabledPlugins},{scope:`project`,path:v(o,`settings.json`),parse:jsonEnabledPlugins},{scope:`user`,path:v(n,`settings.json`),parse:jsonEnabledPlugins}],unread:unreadPolicy(r,i,[`managed-mcp.json`]),research:[`E-CC-P3`,`E-CC-P7`,`E-CC-M1`,`E-CC-M6`]}},cursor:()=>unsupported$1(),opencode:()=>unsupported$1(`E-OC-P3`),kilo:()=>unsupported$1(`E-KILO-P3`),"gemini-cli":()=>unsupported$1(`E-GEM-P3`),"qwen-code":()=>unsupported$1(`E-QWEN-P2`),"vscode-copilot":()=>unsupported$1(`E-VSC-P4`),cline:()=>unsupported$1(`E-CLINE-P4`),crush:()=>unsupported$1(`E-CRUSH-P2`),openhands:()=>unsupported$1(`E-OH-P4`),augment:()=>unsupported$1(`E-AUG-P4`),codex:e=>{let t=pluginStorage(`codex`,e);return{supported:!0,sources:[{scope:`user`,path:v(t.configDir,`config.toml`),parse:tomlEnabledPlugins}],unread:unreadPolicy(managedPolicyLocations(`codex`,e),void 0),research:[`E-CODEX-P2`,`E-CODEX-M7`]}},"copilot-cli":(e,t)=>{let n=pluginStorage(`copilot-cli`,e),r=managedPolicyLocations(`copilot-cli`,e),i=managedFile(r,`managed-settings.json`),a=t??i,o=v(e.cwd,`.github`,`copilot`),s=v(e.cwd,`.claude`);return{supported:!0,sources:[...a===void 0?[]:[{scope:`managed`,path:a,parse:jsoncEnabledPlugins}],{scope:`local`,path:v(o,`settings.local.json`),parse:jsoncEnabledPlugins},{scope:`project`,path:v(o,`settings.json`),parse:jsoncEnabledPlugins},{scope:`user`,path:v(n.configDir,`settings.json`),parse:jsoncEnabledPlugins}],unread:[...unreadPolicy(r,i),`Claude Code project settings (${v(s,`settings.json`)})`,`Claude Code local settings (${v(s,`settings.local.json`)})`],research:[`E-COPILOT-P4`,`E-COPILOT-M1`,`E-COPILOT-M2`,`E-COPILOT-M4`]}}};async function installedPlugins(e,t={}){let n=Ma[e](resolveHarnessEnvironment(t)),r={harness:e,supported:n.supported,unread:n.unread,research:n.research};if(n.source===void 0)return{...r,plugins:[],unresolved:[],sources:[]};let i=n.source;try{let e=await n.read(i);return e===void 0?{...r,plugins:[],unresolved:[],sources:[{path:i,found:!1}]}:{...r,plugins:e.plugins,unresolved:e.unresolved??[],sources:[{path:i,found:!0}]}}catch(e){return{...r,plugins:[],unresolved:[],sources:[{path:i,found:!0,error:String(e)}]}}}const wa=[`managed`,`local`,`project`,`user`],optionalString=e=>typeof e==`string`&&e!==``?e:void 0;async function readClaudeInstalls(e){let t=await readText(e);if(t===void 0)return;let n=JSON.parse(t),r=isRecord(n)?n.plugins:void 0;if(!isRecord(r))return{plugins:[]};let i=[];for(let[e,t]of Object.entries(r))if(Array.isArray(t))for(let n of t){let t=isRecord(n)?optionalString(n.installPath):void 0;if(!isRecord(n)||t===void 0)continue;let r=optionalString(n.version),a=typeof n.scope==`string`&&wa.includes(n.scope)?n.scope:void 0,o=optionalString(n.projectPath);i.push({id:e,path:t,...r===void 0?{}:{version:r},...a===void 0?{}:{scope:a},...o===void 0?{}:{projectPath:o},research:[`E-CC-P2`]})}return{plugins:i}}async function readCopilotInstalls(e){let t=await readText(e);if(t===void 0)return;let n=JSON.parse(stripJsonComments$1(t)),r=isRecord(n)?n.installedPlugins:void 0;if(!Array.isArray(r))return{plugins:[]};let i=[];for(let e of r){if(!isRecord(e))continue;let t=optionalString(e.name),n=optionalString(e.cache_path);if(t===void 0||n===void 0)continue;let r=optionalString(e.marketplace),a=optionalString(e.version);i.push({id:r===void 0?t:`${t}@${r}`,path:n,...a===void 0?{}:{version:a},research:r===void 0?[`E-COPILOT-P10`,`E-COPILOT-P11`]:[`E-COPILOT-P10`]})}return{plugins:i}}const Ta=`local`,Ea=/^[A-Za-z0-9_-]+$/,Da=/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/,Oa=/^[A-Za-z0-9._+-]+$/;async function readCodexInstalls(e){let t=await directories(e);if(t===void 0)return;let n=[],r=[];for(let i of t.filter(e=>Ea.test(e)))for(let t of await directories(v(e,i))??[]){if(!Da.test(t))continue;let a=`${t}@${i}`,o=(await directories(v(e,i,t))??[]).filter(e=>Oa.test(e)&&e!==`.`&&e!==`..`);if(o.length===0)continue;let s=activeCodexVersion(o);if(s===void 0){r.push(a);continue}n.push({id:a,path:v(e,i,t,s),version:s,research:[`E-CODEX-P3`,`E-CODEX-P8`]})}return{plugins:n,unresolved:r}}function activeCodexVersion(e){if(e.includes(Ta))return Ta;let t=e.filter(e=>parseSemver(e)!==void 0).length;if(!(e.length>2&&t!==0&&t!==e.length))return[...e].sort(compareCodexVersions).at(-1)}async function directories(e){try{return(await re(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name)}catch(e){if(e.code===`ENOENT`)return;throw e}}const ka=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;function parseSemver(e){let t=ka.exec(e);if(t)return{core:[t[1],t[2],t[3]],pre:t[4]===void 0?[]:t[4].split(`.`),build:t[5]===void 0?[]:t[5].split(`.`)}}function compareCodexVersions(e,t){let n=parseSemver(e),r=parseSemver(t);if(n===void 0||r===void 0)return compareStrings(e,t);for(let e=0;e<3;e++){let t=compareNumeric(n.core[e],r.core[e]);if(t!==0)return t}let i=n.pre.length===0||r.pre.length===0?r.pre.length-n.pre.length:compareIdentifiers(n.pre,r.pre);return i===0?compareIdentifiers(n.build,r.build):Math.sign(i)}const Aa=/^\d+$/;function compareIdentifiers(e,t){for(let n=0;n<Math.min(e.length,t.length);n++){let r=e[n],i=t[n],a=Aa.test(r),o=Aa.test(i),s=a&&o?compareNumeric(r,i):a===o?compareStrings(r,i):a?-1:1;if(s!==0)return s}return e.length-t.length}function compareNumeric(e,t){let n=e.replace(/^0+(?=\d)/,``),r=t.replace(/^0+(?=\d)/,``);return n.length-r.length||compareStrings(n,r)||e.length-t.length}const compareStrings=(e,t)=>e<t?-1:+(e>t),ja={supported:!1,read:async()=>void 0,unread:[],research:[]},Ma={"claude-code":e=>({supported:!0,source:v(pluginStorage(`claude-code`,e).configDir,`plugins`,`installed_plugins.json`),read:readClaudeInstalls,unread:[],research:[`E-CC-P2`]}),codex:e=>({supported:!0,source:v(pluginStorage(`codex`,e).configDir,`plugins`,`cache`),read:readCodexInstalls,unread:[],research:[`E-CODEX-P3`,`E-CODEX-P8`]}),"copilot-cli":e=>{let{configDir:t}=pluginStorage(`copilot-cli`,e);return{supported:!0,source:v(t,`config.json`),read:readCopilotInstalls,unread:[`plugins from marketplaces added by local path (extraKnownMarketplaces in ${v(t,`settings.json`)})`],research:[`E-COPILOT-P10`,`E-COPILOT-P11`,`E-COPILOT-P12`,`E-COPILOT-P13`]}},cursor:()=>ja,opencode:()=>ja,kilo:()=>ja,"gemini-cli":()=>ja,"qwen-code":()=>ja,"vscode-copilot":()=>ja,cline:()=>ja,crush:()=>ja,openhands:()=>ja,augment:()=>ja};function skillsDirectories(e){switch(e){case`claude-code`:return{project:[`.claude/skills`],user:[`.claude/skills`],research:[`E-CC-L1`]};case`cursor`:return{project:[`.agents/skills`,`.cursor/skills`,`.claude/skills`,`.codex/skills`],user:[`.agents/skills`,`.cursor/skills`,`.claude/skills`,`.codex/skills`],research:[`E-CUR-L1`]};case`codex`:return{project:[`.agents/skills`],user:[`.agents/skills`],research:[`E-CODEX-L1`]};case`copilot-cli`:return{project:[`.github/skills`,`.agents/skills`,`.claude/skills`],user:[`.copilot/skills`,`.agents/skills`],research:[`E-COPILOT-S5`]};case`vscode-copilot`:return{project:[`.github/skills`,`.claude/skills`,`.agents/skills`],user:[`.copilot/skills`,`.claude/skills`,`.agents/skills`],research:[`E-VSC-P1`]};case`opencode`:return{project:[`.opencode/skills`,`.claude/skills`,`.agents/skills`],user:[`.config/opencode/skills`,`.claude/skills`,`.agents/skills`],research:[`E-OC-S1`]};case`gemini-cli`:return{project:[`.agents/skills`,`.gemini/skills`],user:[`.agents/skills`,`.gemini/skills`],research:[`E-GEM-L1`]};case`cline`:return{project:[`.cline/skills`,`.clinerules/skills`,`.claude/skills`],user:[`.cline/skills`],research:[`E-CLINE-S1`]};case`augment`:return{project:[`.augment/skills`],user:[`.augment/skills`],research:[`E-AUG-S1`]};case`kilo`:case`qwen-code`:case`crush`:case`openhands`:return}}function skillsProjection(e,t,n=skillsDirectories(e)?.[t]){let r=n??[],[i]=r;if(i===void 0)throw Error(`@cyberuni/agent-harness records no ${t} skills directories for ${e}.`);return r.includes(`.agents/skills`)?{}:{skillsDirectory:i}}const Na=[{name:`claude-code`,project:{detect:`.claude`,...skillsProjection(`claude-code`,`project`),shadowedBy:[`CLAUDE.md`,`.claude/CLAUDE.md`,`CLAUDE.local.md`],mcpConfig:{path:`.mcp.json`,key:`mcpServers`,format:`json`,dialect:`claude-code`},nonstandard:[{path:`.claude/commands`,shape:`directory`,kind:`command`},{path:`.claude/rules`,shape:`directory`,kind:`rule`},{path:`.claude/agents`,shape:`directory`,kind:`subagent`}]},user:{detect:`.claude`,...skillsProjection(`claude-code`,`user`)}},{name:`cursor`,project:{detect:`.cursor`,...skillsProjection(`cursor`,`project`),mcpConfig:{path:`.cursor/mcp.json`,key:`mcpServers`,format:`json`,dialect:`cursor`},nonstandard:[{path:`.cursorrules`,shape:`file`,kind:`instructions`},{path:`.cursor/rules`,shape:`directory`,kind:`rule`},{path:`.cursor/commands`,shape:`directory`,kind:`command`},{path:`.cursor/skills`,shape:`directory`,kind:`skill`}]},user:{detect:`.cursor`,...skillsProjection(`cursor`,`user`)}},{name:`codex`,project:{detect:`.codex`,...skillsProjection(`codex`,`project`),mcpConfig:{path:`.codex/config.toml`,key:`mcp_servers`,format:`toml`,dialect:`codex`,shared:!0},nonstandard:[{path:`.codex/skills`,shape:`directory`,kind:`skill`}]},user:{detect:`.codex`,...skillsProjection(`codex`,`user`)}},{name:`copilot-cli`,project:{detect:`.github/skills`,...skillsProjection(`copilot-cli`,`project`),nonstandard:[{path:`.github/copilot-instructions.md`,shape:`file`,kind:`instructions`},{path:`.github/instructions`,shape:`directory`,kind:`instructions`},{path:`.github/skills`,shape:`directory`,kind:`skill`}]},user:{detect:`.copilot`,...skillsProjection(`copilot-cli`,`user`)}},{name:`gemini-cli`,project:{detect:`.gemini`,...skillsProjection(`gemini-cli`,`project`),instructionBridge:{kind:`settings-entry`,path:`.gemini/settings.json`,key:`context.fileName`},mcpConfig:{path:`.gemini/settings.json`,key:`mcpServers`,format:`json`,dialect:`gemini-cli`,shared:!0},nonstandard:[{path:`GEMINI.md`,shape:`file`,kind:`instructions`},{path:`.gemini/skills`,shape:`directory`,kind:`skill`}]},user:{detect:`.gemini`,...skillsProjection(`gemini-cli`,`user`)}},{name:`devin-desktop`,project:{detect:`.devin`}},{name:`windsurf`,project:{detect:`.windsurf`,skillsDirectory:`.windsurf/skills`,nonstandard:[{path:`.windsurfrules`,shape:`file`,kind:`instructions`},{path:`.windsurf/rules`,shape:`directory`,kind:`rule`}]},deprecated:`devin-desktop`}],Pa=new Set(Na.map(e=>e.name));function isHarnessName(e){return Pa.has(e)}function parseHarnesses(e){let t=(e??``).split(`,`).map(e=>e.trim()).filter(Boolean),n=t.filter(e=>!isHarnessName(e));if(n.length)throw Error(`Unsupported harness: ${n.join(`, `)}. Supported: ${Na.map(e=>e.name).join(`, `)}.`);return t.filter(isHarnessName)}const Fa=[`claude-code`,`cursor`];function directoryExists(e){try{return i(e).isDirectory()}catch{return!1}}function selectHarnesses(e,t){let n=new Set([...Fa,...t]);return Na.filter(t=>n.has(t.name)||directoryExists(v(e,t.project.detect)))}function locatorText({file:e,server:t,field:n,position:r}){return r?`${e}#L${r.line}:${r.column}`:t===void 0?e:`${e}#servers.${t}${n===void 0?``:`.${n}`}`}function repairsOf(e){return Object.entries(e).map(([e,t])=>({problem:e,...t}))}const Ia=`buddy-agent-harness`,La=`/buddy-agent-harness:repair`,X=`/buddy-agent-harness:init-buddy-agent-harness`,Ra=`.agents/buddy-agent-harness/mcp.toml`,za={"no-canonical":{detail:`the canonical skill directory does not exist, so no bridge can resolve`,repair:(e,t)=>({command:`${t} init`,instruction:`run \`${t} init\` to create .agents/skills and the bridges into it`}),skillRepair:()=>`run \`${X}\`, which creates \`.agents/skills\` and the bridges`},missing:{detail:`no bridge at this path — the harness sees zero project skills`,repair:({file:e},t)=>({command:`${t} init`,instruction:`run \`${t} init\` to create the bridge at ${e}`}),skillRepair:()=>`run \`${X}\``},degraded:{detail:`expected a directory but found a regular file — checkout without core.symlinks`,repair:({file:e},t)=>({command:`${t} init --copy --force ${e}`,instruction:`run \`${t} init --copy --force ${e}\` to rebuild ${e} as a real directory`}),skillRepair:({file:e})=>`run \`${X} --copy --force ${e}\``},stale:{detail:`symlink does not resolve to .agents/skills`,repair:({file:e},t)=>({command:`${t} init --force ${e}`,instruction:`run \`${t} init --force ${e}\` to repoint ${e} at .agents/skills`}),skillRepair:({file:e})=>`run \`${X} --force ${e}\``},"diverged-bridge":{detail:`only the bridge changed since the two last agreed — an agent wrote through the copy`,repair:({file:e},t)=>({command:``,instruction:`replace .agents/skills with ${e} to keep the newer edit, then run \`${t} init --force ${e}\``}),skillRepair:({file:e})=>`replace .agents/skills with ${e} to keep the newer edit, then run \`${X} --force ${e}\``},"diverged-canonical":{detail:`only .agents/skills changed since the two last agreed — the copy is stale`,repair:({file:e},t)=>({command:`${t} init --copy --force ${e}`,instruction:`run \`${t} init --copy --force ${e}\` to rebuild ${e} from the newer .agents/skills`}),skillRepair:({file:e})=>`run \`${X} --copy --force ${e}\``},"diverged-both":{detail:`both sides changed since they last agreed — rebuilding would discard one of them`,repair:({file:e})=>({command:``,instruction:`reconcile .agents/skills with ${e} by hand — rebuilding would discard one of them; \`git diff --no-index .agents/skills ${e}\` shows what differs`}),skillRepair:({file:e})=>`run \`git diff --no-index .agents/skills ${e}\` and reconcile by hand`},"diverged-unknown":{detail:`contents differ and no commit where they agreed was found — which side moved is unknown`,repair:({file:e})=>({command:``,instruction:`reconcile .agents/skills with ${e} by hand — which side moved is unknown; \`git diff --no-index .agents/skills ${e}\` shows what differs`}),skillRepair:({file:e})=>`run \`git diff --no-index .agents/skills ${e}\` and reconcile by hand`},"unpinned-copy":{detail:`tracked copy without the skip-worktree bit — the tree is dirty with content that must not be committed`,repair:({file:e})=>({command:`git ls-files -z ${e} | xargs -0 git update-index --skip-worktree`,instruction:`run \`git ls-files -z ${e} | xargs -0 git update-index --skip-worktree\` to restore the skip-worktree bit`}),skillRepair:({file:e})=>`run \`git ls-files -z ${e} | xargs -0 git update-index --skip-worktree\``}};repairsOf(za);const Ba={"no-instructions":{detail:`no AGENTS.md at the repository root, so the instructions this repository has reach one harness at most`,repair:()=>({command:``,instruction:`hand this to \`${X}\`, which consolidates what the repository has into AGENTS.md, or derives it`}),skillRepair:()=>`run \`${X}\`, which consolidates or derives AGENTS.md`},"instructions-missing":{detail:`no instruction bridge at this path — the harness reads none of AGENTS.md`,repair:({file:e})=>({command:``,instruction:`hand ${e} to \`${X}\`, which writes the bridge into it`}),skillRepair:()=>`run \`${X}\``},"instructions-unbridged":{detail:`the file is present but names AGENTS.md nowhere — the harness reads none of it`,repair:({file:e})=>({command:``,instruction:`hand ${e} to \`${X}\`, which adds the bridge without discarding what the file already says`}),skillRepair:()=>`run \`${X}\`, which adds the bridge without discarding what the file already says`},"instructions-shadowing":{detail:`this file suppresses the AGENTS.md beside it — the harness reads this instead, and none of AGENTS.md`,repair:({file:e})=>({command:``,instruction:`hand ${e} to \`${X}\`, which consolidates what it says into AGENTS.md, or adds an @AGENTS.md import above it where the file has to stay`}),skillRepair:()=>`run \`${X}\`, which consolidates the file into AGENTS.md or imports AGENTS.md from it`},"instructions-superseded":{detail:`a bridge from before the harness read AGENTS.md itself — it still works, and nothing needs it`,repair:({file:e})=>({command:``,instruction:`remove ${e}, or keep it for sessions that cannot read AGENTS.md directly — \`${X}\` offers the choice`}),skillRepair:()=>`run \`${X}\`, which offers to remove it`},"instructions-unreadable":{detail:`the settings file does not parse, so the harness reads none of it`,repair:({file:e})=>({command:``,instruction:`fix the JSON in ${e} by hand, then hand it to \`${X}\``}),skillRepair:()=>`fix the JSON by hand, then run \`${X}\``}};repairsOf(Ba);const Va={"deprecated-harness":{detail:`a projection under a harness name that has been superseded — the replacement reads .agents/skills natively and needs no projection at all`,repair:({file:e})=>({command:``,instruction:`remove ${e} and enable the harness that replaced it — \`${La}\` offers the correction`}),skillRepair:()=>`run \`${La}\``},"ignored-bridge":{detail:`a .gitignore rule matches this bridge — an untracked bridge swallows a real edit silently`,repair:({file:e})=>({command:``,instruction:`narrow or remove the .gitignore rule matching ${e} — \`${La}\` offers the correction`}),skillRepair:()=>`run \`${La}\``},"unread-local-override":{detail:`no harness reads this filename, so everything in it is invisible to every agent`,repair:({file:e})=>({command:``,instruction:`move ${e} to CLAUDE.local.md, or consolidate it into AGENTS.md — \`${La}\` offers the correction`}),skillRepair:()=>`run \`${La}\``},"unloadable-skill":{detail:`frontmatter that does not parse, or no description — either one makes a harness skip the skill outright`,repair:({file:e})=>({command:``,instruction:`quote the description in ${e}, or add one — \`${La}\` offers the correction`}),skillRepair:()=>`run \`${La}\``}};repairsOf(Va);const Ha={"mcp-golden-unreadable":{detail:`the golden MCP set does not parse — the locator gives the line and column, and nothing else can be said about it`,repair:e=>({command:``,instruction:`fix the TOML at ${locatorText(e)}`}),skillRepair:e=>`fix the TOML at ${locatorText(e)} by hand — the reported line and column are all that can be quoted, because the parser's own message repeats the offending line and that line is the one holding the credential`},"mcp-target-unreadable":{detail:`this harness config does not parse, so the harness starts none of its servers and nothing in it can be compared`,repair:e=>({command:``,instruction:`fix the syntax of ${locatorText(e)}`}),skillRepair:e=>`fix the syntax of ${locatorText(e)} by hand`},"mcp-unprojected":{detail:`the golden set declares this server and the harness config does not carry it`,repair:({file:e,server:t})=>({command:``,instruction:`add the server ${t} to ${e}, or drop it from the golden set — \`${La}\` offers the correction`}),skillRepair:e=>`hand ${locatorText(e)} to \`${La}\`, which projects it from its golden entry with \`mcp project\` — or drop it from the golden set`},"mcp-undeclared":{detail:`the harness config carries this server and the golden set does not declare it`,repair:({file:e,server:t})=>({command:``,instruction:`add the server ${t} to ${Ra}, or drop it from ${e} — \`${La}\` offers the import`}),skillRepair:e=>`hand ${locatorText(e)} to \`${La}\`, which imports it field by field with \`mcp reconcile\`, refusing any literal credential — or drop it from ${e.file}`},"mcp-diverged-target":{detail:`only the harness config changed since the two last agreed — the edit was made through the copy`,repair:e=>({command:``,instruction:`reconcile the value at ${locatorText(e)} back into ${Ra} — \`${La}\` offers the import`}),skillRepair:e=>`hand ${locatorText(e)} to \`${La}\`, which imports the field into ${Ra} with \`mcp reconcile\` once approved`},"mcp-diverged-golden":{detail:`only the golden set changed since the two last agreed — the harness copy is stale`,repair:e=>({command:``,instruction:`update ${locatorText(e)} from the golden entry — \`${La}\` offers the correction`}),skillRepair:e=>`hand ${locatorText(e)} to \`${La}\`, which updates it from the golden entry with \`mcp project\``},"mcp-diverged-both":{detail:`both sides changed since they last agreed — merging either way would discard the other`,repair:e=>({command:``,instruction:`reconcile ${locatorText(e)} against ${Ra} by hand`}),skillRepair:e=>`reconcile ${locatorText(e)} against ${Ra} by hand — never merge a three-way conflict automatically`},"mcp-diverged-unknown":{detail:`the two disagree and no baseline says which side moved — neither history nor a last-projected record covers this server`,repair:e=>({command:``,instruction:`compare ${locatorText(e)} against ${Ra} by hand`}),skillRepair:e=>`compare ${locatorText(e)} against ${Ra} by hand`},"mcp-literal-secret":{detail:`a credential-bearing field holds a literal rather than a reference to an environment variable`,repair:e=>({command:``,instruction:`move the value at ${locatorText(e)} into an environment variable and reference it`}),skillRepair:e=>`move the value at ${locatorText(e)} into an environment variable and reference it — read the value from the file, never from this report, and never repeat it back`},"mcp-committed-secret":{detail:`a credential-bearing field holds a literal in a git-tracked file — the credential is committed, and moving it does not un-commit it`,repair:e=>({command:``,instruction:`rotate the credential behind ${locatorText(e)}, then reference it from an environment variable`}),skillRepair:e=>`rotate the credential behind ${locatorText(e)} at its issuer, then reference it from an environment variable — it is in the repository's history, so moving it is not enough`}};repairsOf(Ha);const Ua={"nonstandard-instructions":{detail:`instruction content only one harness reads — AGENTS.md carries the same prose to all of them`,repair:({file:e})=>({command:``,instruction:`consolidate ${e} into AGENTS.md and leave a generated bridge in its place — \`${X}\` offers the consolidation`}),skillRepair:({file:e})=>`hand ${e} to \`${X}\`, which consolidates it into AGENTS.md`},"nonstandard-rule":{detail:`a path-scoped rule only one harness reads — a skill reaches every harness where the scoping is incidental`,repair:({file:e})=>({command:``,instruction:`convert ${e} into a skill under .agents/skills where its guidance is not tied to the paths it names — \`${X}\` offers the conversion; keep it where the path scoping is the point`}),skillRepair:({file:e})=>`hand ${e} to \`${X}\` to convert into a skill, unless the path scoping is load-bearing`},"nonstandard-command":{detail:`a harness command file — a skill is the portable form, and this harness reads skills too`,repair:({file:e})=>({command:``,instruction:`move ${e} to .agents/skills/<name>/SKILL.md — \`${X}\` offers the move`}),skillRepair:({file:e})=>`hand ${e} to \`${X}\`, which moves it to .agents/skills`},"nonstandard-skill":{detail:`a skill under a harness directory rather than the canonical one, where only that harness finds it`,repair:({file:e})=>({command:``,instruction:`move ${e} to .agents/skills and project it back where the harness needs one — \`${X}\` offers the move`}),skillRepair:({file:e})=>`hand ${e} to \`${X}\`, which moves it to .agents/skills`},"nonstandard-subagent":{detail:`a subagent definition with no cross-harness form — nothing outside this harness can read it, and no canonical form exists yet`,repair:({file:e})=>({command:``,instruction:`leave ${e} where it is and record that it reaches one harness only — no portable form exists to convert it to`}),skillRepair:({file:e})=>`leave ${e} in place — no portable form exists yet, so this is work for a person rather than a skill`}};repairsOf(Ua);const Wa={...za,...Ba,...Va,...Ha,...Ua};repairsOf(Wa);function repairFor(e){return{problem:e,...Wa[e]}}const Ga=`.agents/skills`,Ka=`AGENTS.local.md`;function frontmatterFault(e){let t=/^---\n([\s\S]*?)\n---/.exec(e);if(!t)return`unparseable`;let n=/^description:[ \t]*(.*)$/m.exec(t[1])?.[1]?.trim();if(!n)return`no-description`;if(!/^(['"]).*\1$/.test(n)&&/:\s/.test(n))return`unparseable`}function diagnoseConfiguration({root:e,git:t,cli:n}){let i=[],add=(e,t)=>{let{detail:r,repair:a}=repairFor(t);i.push({path:e,problem:t,detail:r,repair:a({file:e},n)})},a=selectHarnesses(e,[]);for(let t of a){let n=t.project.skillsDirectory;t.deprecated&&n&&r(v(e,n))&&add(n,`deprecated-harness`)}for(let n of a){let i=n.project.skillsDirectory;i&&r(v(e,i))&&t.isIgnored(i)&&add(i,`ignored-bridge`)}r(v(e,Ka))&&add(Ka,`unread-local-override`);for(let t of filesUnder(v(e,Ga)).filter(e=>e.endsWith(`SKILL.md`)))frontmatterFault(o(v(e,Ga,t),`utf8`))&&add(`${Ga}/${t}`,`unloadable-skill`);return i}const qa=[`transport`,`command`,`args`,`env`,`url`,`headers`,`description`,`enabled`,`timeout`,`source`],Ja=new Set([`env`,`headers`]);function sameValue(e,t,n){if(Ja.has(e)&&isRecord$1(t)&&isRecord$1(n)){let e=Object.keys(t);return e.length===Object.keys(n).length&&e.every(e=>t[e]===n[e])}return JSON.stringify(t)===JSON.stringify(n)}function divergingFields(e,t,n=new Set(qa)){return qa.filter(r=>{if(!n.has(r))return!1;let i=e[r];if(i===void 0)return!1;if(Ja.has(r)&&isRecord$1(i)&&isRecord$1(t[r])){let e=t[r];return Object.keys(i).some(t=>i[t]!==e[t])}return!sameValue(r,i,t[r])})}function sameField(e,t,n){return sameValue(e,t?.[e],n?.[e])}function stringMap(e){if(!isRecord$1(e))return;let t=Object.entries(e).filter(([,e])=>typeof e==`string`);return t.length?Object.fromEntries(t):void 0}const Ya=new Set([`stdio`,`http`,`sse`]);function transportOf(e){let t=e.type??e.transport;if(typeof t==`string`&&Ya.has(t))return t;if(typeof e.url==`string`)return`http`;if(typeof e.command==`string`)return`stdio`}function serverFrom(e){let t=Array.isArray(e.args)&&e.args.every(e=>typeof e==`string`),n=transportOf(e),r=stringMap(e.env),i=stringMap(e.headers);return{...n?{transport:n}:{},...typeof e.command==`string`?{command:e.command}:{},...t?{args:e.args}:{},...r?{env:r}:{},...typeof e.url==`string`?{url:e.url}:{},...i?{headers:i}:{},...typeof e.description==`string`?{description:e.description}:{},...typeof e.enabled==`boolean`?{enabled:e.enabled}:{},...typeof e.timeout==`number`?{timeout:e.timeout}:{},...typeof e.source==`string`?{source:e.source}:{}}}const Xa=/^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/,Za=/\$\{[^}]*\}|\$[A-Za-z_]/;var Refusal=class extends Error{field;reason;constructor(e,t){super(t),this.field=e,this.reason=t}};function refuse(e,t){throw new Refusal(e,t)}function rendering(e){try{return{kind:`entry`,entry:e()}}catch(e){if(!(e instanceof Refusal))throw e;return{kind:`refused`,field:e.field,reason:e.reason}}}function assertRunnable(e){(e.transport===`stdio`?!e.command:!e.url)&&refuse(e.transport===`stdio`?`command`:`url`,`the golden set leaves it unset and the target requires it`)}function defined(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function mapValues(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t(n)]))}function noReferenceIn(e,t,n){for(let r of t){let t=e[r];(Array.isArray(t)?t:[t]).some(e=>typeof e==`string`&&Za.test(e))&&refuse(r,`${n} documents no reference expansion here`)}}const Qa={fields:new Set([`transport`,`command`,`args`,`env`,`url`,`headers`,`description`,`timeout`]),read:serverFrom,write:e=>rendering(()=>(assertRunnable(e),defined({type:e.transport,command:e.command,args:e.args,env:e.env,url:e.url,headers:e.headers,description:e.description,timeout:e.timeout})))};function toCursor(e,t){return e.replace(/\$\{([^}]*)\}|\$[A-Za-z_]/g,(e,n)=>((n===void 0||!Xa.test(e))&&refuse(t,`Cursor expands only a plain variable reference, with no default`),`\${env:${n}}`))}function fromCursor(e){return e.replace(/\$\{env:([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,t)=>`\${${t}}`)}function fromCursorEntry(e){let strings=e=>typeof e==`string`?fromCursor(e):e,map=e=>isRecord$1(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,strings(t)])):e;return{...e,command:strings(e.command),args:Array.isArray(e.args)?e.args.map(strings):e.args,env:map(e.env),url:strings(e.url),headers:map(e.headers)}}const $a={fields:new Set([`command`,`args`,`env`,`url`,`headers`]),read:e=>serverFrom(fromCursorEntry(e)),write:e=>rendering(()=>(assertRunnable(e),defined({type:e.transport===`stdio`?`stdio`:void 0,command:e.command&&toCursor(e.command,`command`),args:e.args?.map(e=>toCursor(e,`args`)),env:mapValues(e.env,e=>toCursor(e,`env`)),url:e.url&&toCursor(e.url,`url`),headers:mapValues(e.headers,e=>toCursor(e,`headers`))})))},eo=/^Bearer \$\{([A-Za-z_][A-Za-z0-9_]*)\}$/;function codexEnv(e){let t={},n=[];for(let[r,i]of Object.entries(e??{}))Xa.exec(i)?.[1]===r?n.push(r):Za.test(i)?refuse(`env`,`Codex passes a variable through only under its own name`):t[r]=i;return defined({env:Object.keys(t).length?t:void 0,env_vars:n.length?n:void 0})}function codexHeaders(e){let t={},n={},r;for(let[i,a]of Object.entries(e??{})){let e=Xa.exec(a)?.[1],o=eo.exec(a)?.[1];o&&i===`Authorization`?r=o:e?n[i]=e:Za.test(a)?refuse(`headers`,`Codex fills a header only from a whole variable reference, or Bearer and one`):t[i]=a}return defined({http_headers:Object.keys(t).length?t:void 0,env_http_headers:Object.keys(n).length?n:void 0,bearer_token_env_var:r})}function stringRecord(e){return isRecord$1(e)?Object.fromEntries(Object.entries(e).filter(([,e])=>typeof e==`string`)):{}}function fromCodex(e){let t=Array.isArray(e.env_vars)?e.env_vars.filter(e=>typeof e==`string`):[],n={...stringRecord(e.env),...Object.fromEntries(t.map(e=>[e,`\${${e}}`]))},r=e.bearer_token_env_var,i={...stringRecord(e.http_headers),...Object.fromEntries(Object.entries(stringRecord(e.env_http_headers)).map(([e,t])=>[e,`\${${t}}`])),...typeof r==`string`?{Authorization:`Bearer \${${r}}`}:{}},a=e.tool_timeout_sec;return{command:e.command,args:e.args,env:n,url:e.url,headers:i,enabled:e.enabled,timeout:typeof a==`number`?Math.round(a*1e3):void 0}}const to={fields:new Set([`transport`,`command`,`args`,`env`,`url`,`headers`,`enabled`,`timeout`]),defaults:{timeout:6e4},read:e=>serverFrom(fromCodex(e)),write:e=>rendering(()=>(e.transport===`sse`&&refuse(`transport`,`Codex supports no SSE transport`),assertRunnable(e),noReferenceIn(e,[`command`,`args`,`url`],`Codex`),defined({command:e.command,args:e.args,...codexEnv(e.env),url:e.url,...codexHeaders(e.headers),enabled:e.enabled,tool_timeout_sec:e.timeout===void 0?void 0:e.timeout/1e3})))};function fromGemini(e){let{httpUrl:t,url:n,...r}=e;return typeof t==`string`?{...r,type:`http`,url:t}:typeof n==`string`?{...r,type:`sse`,url:n}:r}const no={"claude-code":Qa,cursor:$a,codex:to,"gemini-cli":{fields:new Set([`transport`,`command`,`args`,`env`,`url`,`headers`,`timeout`]),defaults:{timeout:6e5},read:e=>serverFrom(fromGemini(e)),write:e=>rendering(()=>(assertRunnable(e),defined({command:e.command,args:e.args,env:e.env,url:e.transport===`sse`?e.url:void 0,httpUrl:e.transport===`http`?e.url:void 0,headers:e.headers,timeout:e.timeout})))}};function stripJsonComments(e){let t=``,n=0,r=!1,i=!1;for(;n<e.length;){let a=e[n];if(r){t+=a,i?i=!1:a===`\\`?i=!0:a===`"`&&(r=!1),n+=1;continue}if(a===`"`){r=!0,t+=a,n+=1;continue}if(a===`/`&&e[n+1]===`/`){for(;n<e.length&&e[n]!==`
93
+ `;)n++;else if(r===`/`&&e[n+1]===`*`){let t=e.indexOf(`*/`,n+2);n=t===-1?e.length:t+2}else t+=r,n++}return t.replace(/,(\s*[}\]])/g,`$1`)}__name(stripJsonComments$1,`stripJsonComments`);function isRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function pluginStorage(e,t={}){return ya[e](resolveHarnessEnvironment(t))}const xdgConfig=({env:e,homedir:t})=>e.XDG_CONFIG_HOME||v(t,`.config`);function vscodeAgentPlugins({env:e,homedir:t,platform:n}){if(n===`win32`){let n=w.join(e.APPDATA||w.join(t,`AppData`,`Roaming`),`Code`);return{configDir:n,path:w.join(n,`agentPlugins`)}}let r=n===`darwin`?v(t,`Library`,`Application Support`,`Code`):v(t,`.config`,`Code`);return{configDir:r,path:v(r,`agentPlugins`)}}const ya={"claude-code":({env:e,homedir:t})=>{let n=e.CLAUDE_CONFIG_DIR||v(t,`.claude`),r=v(n,`plugins`);return{harness:`claude-code`,configDir:n,locations:[{kind:`plugin-cache`,path:v(r,`cache`),description:`Installed plugins as <marketplace>/<plugin>/<version>/`,research:`E-CC-P1`},{kind:`marketplaces`,path:v(r,`marketplaces`),description:`Marketplace checkouts`,research:`E-CC-P1`},{kind:`install-record`,path:v(r,`installed_plugins.json`),description:`Installs keyed by plugin@marketplace, each with scope, installPath, and version`,research:`E-CC-P2`},{kind:`enabled-record`,path:v(n,`settings.json`),description:`User settings; enabledPlugins maps plugin@marketplace to a boolean`,research:`E-CC-P3`}]}},cursor:({homedir:e})=>{let t=v(e,`.cursor`);return{harness:`cursor`,configDir:t,locations:[{kind:`local-plugins`,path:v(t,`plugins`,`local`),description:`Plugins under development, one folder each`,research:`E-CUR-P2`},{kind:`marketplaces`,path:v(t,`plugins`,`marketplaces`),description:`Marketplace checkouts`,research:`E-CUR-P3`}]}},codex:({env:e,homedir:t})=>{let n=e.CODEX_HOME||v(t,`.codex`);return{harness:`codex`,configDir:n,locations:[{kind:`plugin-cache`,path:v(n,`plugins`,`cache`),description:`Installed plugins as <marketplace>/<plugin>/<version>/`,research:`E-CODEX-P3`},{kind:`enabled-record`,path:v(n,`config.toml`),description:`User config; [plugins."<plugin>@<marketplace>"] tables carry enabled = <bool>`,research:`E-CODEX-P2`}]}},"copilot-cli":({env:e,homedir:t})=>{let n=e.COPILOT_HOME||v(t,`.copilot`);return{harness:`copilot-cli`,configDir:n,locations:[{kind:`installed-plugins`,path:v(n,`installed-plugins`),description:`Installed plugins as <marketplace>/<plugin>/, or _direct/<source-id>/ for direct installs`,research:`E-COPILOT-P9`},{kind:`install-record`,path:v(n,`config.json`),description:`Application state, including installedPlugins`,research:`E-COPILOT-P9`},{kind:`enabled-record`,path:v(n,`settings.json`),description:`User settings (JSON with comments); enabledPlugins maps plugin specs to a boolean`,research:`E-COPILOT-P4`}]}},opencode:e=>{let t=v(xdgConfig(e),`opencode`);return{harness:`opencode`,configDir:t,locations:[{kind:`local-plugins`,path:v(t,`plugins`),description:`JS/TS plugin modules loaded at startup; npm plugins are named in the plugin config array`,research:`E-OC-P2`}]}},kilo:e=>{let t=v(xdgConfig(e),`kilo`);return{harness:`kilo`,configDir:t,locations:[{kind:`local-plugins`,path:v(t,`plugin`),description:`JS/TS plugin modules loaded at startup; npm plugins are named in the plugin config array`,research:`E-KILO-P2`}]}},"gemini-cli":({env:e,homedir:t})=>{let n=v(e.GEMINI_CLI_HOME||t,`.gemini`),r=v(n,`extensions`);return{harness:`gemini-cli`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed extensions, one folder each with a gemini-extension.json manifest`,research:`E-GEM-P1`},{kind:`enabled-record`,path:v(r,`extension-enablement.json`),description:`Per-extension path-glob overrides that enable or disable it by folder, not a boolean`,research:`E-GEM-P3`}]}},"qwen-code":({env:e,homedir:t})=>{let n=e.QWEN_HOME||v(t,`.qwen`),r=v(n,`extensions`);return{harness:`qwen-code`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed extensions, one folder each with a qwen-extension.json manifest`,research:`E-QWEN-P1`},{kind:`enabled-record`,path:v(r,`extension-enablement.json`),description:`Extension enable/disable state, inherited from Gemini CLI's format`,research:`E-QWEN-P2`}]}},"vscode-copilot":e=>{let{configDir:t,path:n}=vscodeAgentPlugins(e);return{harness:`vscode-copilot`,configDir:t,locations:[{kind:`installed-plugins`,path:n,description:`Installed agent plugins as <host>/<org>/<repo>/`,research:`E-VSC-P3`}]}},cline:({homedir:e})=>{let t=v(e,`.cline`);return{harness:`cline`,configDir:t,locations:[{kind:`installed-plugins`,path:v(t,`plugins`,`_installed`),description:`Installed plugins, grouped by source: npm, git, remote, or local`,research:`E-CLINE-P3`}]}},crush:({env:e,homedir:t})=>({harness:`crush`,configDir:e.CRUSH_GLOBAL_CONFIG||v(e.XDG_CONFIG_HOME||v(t,`.config`),`crush`),locations:[]}),openhands:({env:e,homedir:t})=>{let n=e.OH_PERSISTENCE_DIR||e.OPENHANDS_PERSISTENCE_DIR||v(t,`.openhands`),r=v(n,`plugins`,`installed`);return{harness:`openhands`,configDir:n,locations:[{kind:`installed-plugins`,path:r,description:`Installed plugins, one folder each`,research:`E-OH-P3`},{kind:`enabled-record`,path:v(r,`.installed.json`),description:`Install metadata keyed by plugin name, each with enabled: <bool>`,research:`E-OH-P4`}]}},augment:({homedir:e})=>{let t=v(e,`.augment`);return{harness:`augment`,configDir:t,locations:[{kind:`marketplaces`,path:v(t,`plugins`,`marketplaces`),description:`Marketplace checkouts`,research:`E-AUG-P2`},{kind:`enabled-record`,path:v(t,`settings.json`),description:`User settings; enabledPlugins maps plugin@marketplace to a boolean`,research:`E-AUG-P4`}]}}};async function enabledPlugins(e,t={}){let n=Ca[e](resolveHarnessEnvironment(t),t.managedSettingsPath),r=new Map,i=[];for(let e of n.sources){let t;try{let n=await readText(e.path);if(n===void 0){i.push({scope:e.scope,path:e.path,found:!1});continue}t=e.parse(n)}catch(t){i.push({scope:e.scope,path:e.path,found:!0,error:String(t)});continue}i.push({scope:e.scope,path:e.path,found:!0});for(let[n,i]of Object.entries(t))r.has(n)||r.set(n,{id:n,enabled:i,scope:e.scope,source:e.path})}return{harness:e,supported:n.supported,plugins:[...r.values()],sources:i,unread:n.unread,research:n.research}}function jsonEnabledPlugins(e){let t=JSON.parse(e),n=isRecord(t)?t.enabledPlugins:void 0;return isRecord(n)?Object.fromEntries(Object.entries(n).filter(e=>typeof e[1]==`boolean`)):{}}const ba=/^\[\s*plugins\s*\.\s*(?:"([^"]*)"|'([^']*)'|([A-Za-z0-9_-]+))\s*\]\s*(?:#.*)?$/,xa=/^enabled\s*=\s*(true|false)\s*(?:#.*)?$/;function tomlEnabledPlugins(e){let t={},n;for(let r of e.split(/\r?\n/)){let e=r.trim();if(e.startsWith(`[`)){let t=ba.exec(e);n=t?t[1]??t[2]??t[3]:void 0;continue}let i=n===void 0?null:xa.exec(e);n!==void 0&&i&&(t[n]=i[1]===`true`)}return t}const Sa={server:`server-managed settings`,"macos-managed-preferences":`MDM managed preferences`,"windows-registry":`Windows registry policy`,directory:`drop-in managed settings`,file:`managed file`};function unreadPolicy(e,t,n=[]){return e.filter(e=>e.location!==t&&!n.some(t=>e.location.endsWith(t))).map(e=>`${Sa[e.kind]} (${e.location})`)}function managedFile(e,t){return e.find(e=>e.kind===`file`&&e.location.endsWith(t))?.location}function jsoncEnabledPlugins(e){return jsonEnabledPlugins(stripJsonComments$1(e))}const unsupported$1=(...e)=>({supported:!1,sources:[],unread:[],research:e}),Ca={"claude-code":(e,t)=>{let{configDir:n}=pluginStorage(`claude-code`,e),r=managedPolicyLocations(`claude-code`,e),i=managedFile(r,`managed-settings.json`),a=t??i,o=v(e.cwd,`.claude`);return{supported:!0,sources:[...a===void 0?[]:[{scope:`managed`,path:a,parse:jsonEnabledPlugins}],{scope:`local`,path:v(o,`settings.local.json`),parse:jsonEnabledPlugins},{scope:`project`,path:v(o,`settings.json`),parse:jsonEnabledPlugins},{scope:`user`,path:v(n,`settings.json`),parse:jsonEnabledPlugins}],unread:unreadPolicy(r,i,[`managed-mcp.json`]),research:[`E-CC-P3`,`E-CC-P7`,`E-CC-M1`,`E-CC-M6`]}},cursor:()=>unsupported$1(),opencode:()=>unsupported$1(`E-OC-P3`),kilo:()=>unsupported$1(`E-KILO-P3`),"gemini-cli":()=>unsupported$1(`E-GEM-P3`),"qwen-code":()=>unsupported$1(`E-QWEN-P2`),"vscode-copilot":()=>unsupported$1(`E-VSC-P4`),cline:()=>unsupported$1(`E-CLINE-P4`),crush:()=>unsupported$1(`E-CRUSH-P2`),openhands:()=>unsupported$1(`E-OH-P4`),augment:()=>unsupported$1(`E-AUG-P4`),codex:e=>{let t=pluginStorage(`codex`,e);return{supported:!0,sources:[{scope:`user`,path:v(t.configDir,`config.toml`),parse:tomlEnabledPlugins}],unread:unreadPolicy(managedPolicyLocations(`codex`,e),void 0),research:[`E-CODEX-P2`,`E-CODEX-M7`]}},"copilot-cli":(e,t)=>{let n=pluginStorage(`copilot-cli`,e),r=managedPolicyLocations(`copilot-cli`,e),i=managedFile(r,`managed-settings.json`),a=t??i,o=v(e.cwd,`.github`,`copilot`),s=v(e.cwd,`.claude`);return{supported:!0,sources:[...a===void 0?[]:[{scope:`managed`,path:a,parse:jsoncEnabledPlugins}],{scope:`local`,path:v(o,`settings.local.json`),parse:jsoncEnabledPlugins},{scope:`project`,path:v(o,`settings.json`),parse:jsoncEnabledPlugins},{scope:`user`,path:v(n.configDir,`settings.json`),parse:jsoncEnabledPlugins}],unread:[...unreadPolicy(r,i),`Claude Code project settings (${v(s,`settings.json`)})`,`Claude Code local settings (${v(s,`settings.local.json`)})`],research:[`E-COPILOT-P4`,`E-COPILOT-M1`,`E-COPILOT-M2`,`E-COPILOT-M4`]}}};async function installedPlugins(e,t={}){let n=Ma[e](resolveHarnessEnvironment(t)),r={harness:e,supported:n.supported,unread:n.unread,research:n.research};if(n.source===void 0)return{...r,plugins:[],unresolved:[],sources:[]};let i=n.source;try{let e=await n.read(i);return e===void 0?{...r,plugins:[],unresolved:[],sources:[{path:i,found:!1}]}:{...r,plugins:e.plugins,unresolved:e.unresolved??[],sources:[{path:i,found:!0}]}}catch(e){return{...r,plugins:[],unresolved:[],sources:[{path:i,found:!0,error:String(e)}]}}}const wa=[`managed`,`local`,`project`,`user`],optionalString=e=>typeof e==`string`&&e!==``?e:void 0;async function readClaudeInstalls(e){let t=await readText(e);if(t===void 0)return;let n=JSON.parse(t),r=isRecord(n)?n.plugins:void 0;if(!isRecord(r))return{plugins:[]};let i=[];for(let[e,t]of Object.entries(r))if(Array.isArray(t))for(let n of t){let t=isRecord(n)?optionalString(n.installPath):void 0;if(!isRecord(n)||t===void 0)continue;let r=optionalString(n.version),a=typeof n.scope==`string`&&wa.includes(n.scope)?n.scope:void 0,o=optionalString(n.projectPath);i.push({id:e,path:t,...r===void 0?{}:{version:r},...a===void 0?{}:{scope:a},...o===void 0?{}:{projectPath:o},research:[`E-CC-P2`]})}return{plugins:i}}async function readCopilotInstalls(e){let t=await readText(e);if(t===void 0)return;let n=JSON.parse(stripJsonComments$1(t)),r=isRecord(n)?n.installedPlugins:void 0;if(!Array.isArray(r))return{plugins:[]};let i=[];for(let e of r){if(!isRecord(e))continue;let t=optionalString(e.name),n=optionalString(e.cache_path);if(t===void 0||n===void 0)continue;let r=optionalString(e.marketplace),a=optionalString(e.version);i.push({id:r===void 0?t:`${t}@${r}`,path:n,...a===void 0?{}:{version:a},research:r===void 0?[`E-COPILOT-P10`,`E-COPILOT-P11`]:[`E-COPILOT-P10`]})}return{plugins:i}}const Ta=`local`,Ea=/^[A-Za-z0-9_-]+$/,Da=/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/,Oa=/^[A-Za-z0-9._+-]+$/;async function readCodexInstalls(e){let t=await directories(e);if(t===void 0)return;let n=[],r=[];for(let i of t.filter(e=>Ea.test(e)))for(let t of await directories(v(e,i))??[]){if(!Da.test(t))continue;let a=`${t}@${i}`,o=(await directories(v(e,i,t))??[]).filter(e=>Oa.test(e)&&e!==`.`&&e!==`..`);if(o.length===0)continue;let s=activeCodexVersion(o);if(s===void 0){r.push(a);continue}n.push({id:a,path:v(e,i,t,s),version:s,research:[`E-CODEX-P3`,`E-CODEX-P8`]})}return{plugins:n,unresolved:r}}function activeCodexVersion(e){if(e.includes(Ta))return Ta;let t=e.filter(e=>parseSemver(e)!==void 0).length;if(!(e.length>2&&t!==0&&t!==e.length))return[...e].sort(compareCodexVersions).at(-1)}async function directories(e){try{return(await re(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name)}catch(e){if(e.code===`ENOENT`)return;throw e}}const ka=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;function parseSemver(e){let t=ka.exec(e);if(t)return{core:[t[1],t[2],t[3]],pre:t[4]===void 0?[]:t[4].split(`.`),build:t[5]===void 0?[]:t[5].split(`.`)}}function compareCodexVersions(e,t){let n=parseSemver(e),r=parseSemver(t);if(n===void 0||r===void 0)return compareStrings(e,t);for(let e=0;e<3;e++){let t=compareNumeric(n.core[e],r.core[e]);if(t!==0)return t}let i=n.pre.length===0||r.pre.length===0?r.pre.length-n.pre.length:compareIdentifiers(n.pre,r.pre);return i===0?compareIdentifiers(n.build,r.build):Math.sign(i)}const Aa=/^\d+$/;function compareIdentifiers(e,t){for(let n=0;n<Math.min(e.length,t.length);n++){let r=e[n],i=t[n],a=Aa.test(r),o=Aa.test(i),s=a&&o?compareNumeric(r,i):a===o?compareStrings(r,i):a?-1:1;if(s!==0)return s}return e.length-t.length}function compareNumeric(e,t){let n=e.replace(/^0+(?=\d)/,``),r=t.replace(/^0+(?=\d)/,``);return n.length-r.length||compareStrings(n,r)||e.length-t.length}const compareStrings=(e,t)=>e<t?-1:+(e>t),ja={supported:!1,read:async()=>void 0,unread:[],research:[]},Ma={"claude-code":e=>({supported:!0,source:v(pluginStorage(`claude-code`,e).configDir,`plugins`,`installed_plugins.json`),read:readClaudeInstalls,unread:[],research:[`E-CC-P2`]}),codex:e=>({supported:!0,source:v(pluginStorage(`codex`,e).configDir,`plugins`,`cache`),read:readCodexInstalls,unread:[],research:[`E-CODEX-P3`,`E-CODEX-P8`]}),"copilot-cli":e=>{let{configDir:t}=pluginStorage(`copilot-cli`,e);return{supported:!0,source:v(t,`config.json`),read:readCopilotInstalls,unread:[`plugins from marketplaces added by local path (extraKnownMarketplaces in ${v(t,`settings.json`)})`],research:[`E-COPILOT-P10`,`E-COPILOT-P11`,`E-COPILOT-P12`,`E-COPILOT-P13`]}},cursor:()=>ja,opencode:()=>ja,kilo:()=>ja,"gemini-cli":()=>ja,"qwen-code":()=>ja,"vscode-copilot":()=>ja,cline:()=>ja,crush:()=>ja,openhands:()=>ja,augment:()=>ja};function skillsDirectories(e){switch(e){case`claude-code`:return{project:[`.claude/skills`],user:[`.claude/skills`],research:[`E-CC-L1`]};case`cursor`:return{project:[`.agents/skills`,`.cursor/skills`,`.claude/skills`,`.codex/skills`],user:[`.agents/skills`,`.cursor/skills`,`.claude/skills`,`.codex/skills`],research:[`E-CUR-L1`]};case`codex`:return{project:[`.agents/skills`],user:[`.agents/skills`],research:[`E-CODEX-L1`]};case`copilot-cli`:return{project:[`.github/skills`,`.agents/skills`,`.claude/skills`],user:[`.copilot/skills`,`.agents/skills`],research:[`E-COPILOT-S5`]};case`vscode-copilot`:return{project:[`.github/skills`,`.claude/skills`,`.agents/skills`],user:[`.copilot/skills`,`.claude/skills`,`.agents/skills`],research:[`E-VSC-P1`]};case`opencode`:return{project:[`.opencode/skills`,`.claude/skills`,`.agents/skills`],user:[`.config/opencode/skills`,`.claude/skills`,`.agents/skills`],research:[`E-OC-S1`]};case`gemini-cli`:return{project:[`.agents/skills`,`.gemini/skills`],user:[`.agents/skills`,`.gemini/skills`],research:[`E-GEM-L1`]};case`cline`:return{project:[`.cline/skills`,`.clinerules/skills`,`.claude/skills`],user:[`.cline/skills`],research:[`E-CLINE-S1`]};case`augment`:return{project:[`.augment/skills`],user:[`.augment/skills`],research:[`E-AUG-S1`]};case`kilo`:case`qwen-code`:case`crush`:case`openhands`:return}}function skillsProjection(e,t,n=skillsDirectories(e)?.[t]){let r=n??[],[i]=r;if(i===void 0)throw Error(`@cyberuni/agent-harness records no ${t} skills directories for ${e}.`);return r.includes(`.agents/skills`)?{}:{skillsDirectory:i}}const Na=[{name:`claude-code`,project:{detect:`.claude`,...skillsProjection(`claude-code`,`project`),shadowedBy:[`CLAUDE.md`,`.claude/CLAUDE.md`,`CLAUDE.local.md`],mcpConfig:{path:`.mcp.json`,key:`mcpServers`,format:`json`,dialect:`claude-code`},nonstandard:[{path:`.claude/commands`,shape:`directory`,kind:`command`},{path:`.claude/rules`,shape:`directory`,kind:`rule`},{path:`.claude/agents`,shape:`directory`,kind:`subagent`}]},user:{detect:`.claude`,...skillsProjection(`claude-code`,`user`)}},{name:`cursor`,project:{detect:`.cursor`,...skillsProjection(`cursor`,`project`),mcpConfig:{path:`.cursor/mcp.json`,key:`mcpServers`,format:`json`,dialect:`cursor`},nonstandard:[{path:`.cursorrules`,shape:`file`,kind:`instructions`},{path:`.cursor/rules`,shape:`directory`,kind:`rule`},{path:`.cursor/commands`,shape:`directory`,kind:`command`},{path:`.cursor/skills`,shape:`directory`,kind:`skill`}]},user:{detect:`.cursor`,...skillsProjection(`cursor`,`user`)}},{name:`codex`,project:{detect:`.codex`,...skillsProjection(`codex`,`project`),mcpConfig:{path:`.codex/config.toml`,key:`mcp_servers`,format:`toml`,dialect:`codex`,shared:!0},nonstandard:[{path:`.codex/skills`,shape:`directory`,kind:`skill`}]},user:{detect:`.codex`,...skillsProjection(`codex`,`user`)}},{name:`copilot-cli`,project:{detect:`.github/skills`,...skillsProjection(`copilot-cli`,`project`),nonstandard:[{path:`.github/copilot-instructions.md`,shape:`file`,kind:`instructions`},{path:`.github/instructions`,shape:`directory`,kind:`instructions`},{path:`.github/skills`,shape:`directory`,kind:`skill`}]},user:{detect:`.copilot`,...skillsProjection(`copilot-cli`,`user`)}},{name:`gemini-cli`,project:{detect:`.gemini`,...skillsProjection(`gemini-cli`,`project`),instructionBridge:{kind:`settings-entry`,path:`.gemini/settings.json`,key:`context.fileName`},mcpConfig:{path:`.gemini/settings.json`,key:`mcpServers`,format:`json`,dialect:`gemini-cli`,shared:!0},nonstandard:[{path:`GEMINI.md`,shape:`file`,kind:`instructions`},{path:`.gemini/skills`,shape:`directory`,kind:`skill`}]},user:{detect:`.gemini`,...skillsProjection(`gemini-cli`,`user`)}},{name:`devin-desktop`,project:{detect:`.devin`}},{name:`windsurf`,project:{detect:`.windsurf`,skillsDirectory:`.windsurf/skills`,nonstandard:[{path:`.windsurfrules`,shape:`file`,kind:`instructions`},{path:`.windsurf/rules`,shape:`directory`,kind:`rule`}]},deprecated:`devin-desktop`}],Pa=new Set(Na.map(e=>e.name));function isHarnessName(e){return Pa.has(e)}function parseHarnesses(e){let t=(e??``).split(`,`).map(e=>e.trim()).filter(Boolean),n=t.filter(e=>!isHarnessName(e));if(n.length)throw Error(`Unsupported harness: ${n.join(`, `)}. Supported: ${Na.map(e=>e.name).join(`, `)}.`);return t.filter(isHarnessName)}const Fa=[`claude-code`,`cursor`];function directoryExists(e){try{return i(e).isDirectory()}catch{return!1}}function selectHarnesses(e,t){let n=new Set([...Fa,...t]);return Na.filter(t=>n.has(t.name)||directoryExists(v(e,t.project.detect)))}function locatorText({file:e,server:t,field:n,position:r}){return r?`${e}#L${r.line}:${r.column}`:t===void 0?e:`${e}#servers.${t}${n===void 0?``:`.${n}`}`}function repairsOf(e){return Object.entries(e).map(([e,t])=>({problem:e,...t}))}const Ia=`buddy-agent-harness`,La=`/buddy-agent-harness:repair`,X=`/buddy-agent-harness:init-buddy-agent-harness`,Ra=`.agents/buddy-agent-harness/mcp.toml`,za={"no-canonical":{detail:`the canonical skill directory does not exist, so no bridge can resolve`,repair:(e,t)=>({command:`${t} init`,instruction:`run \`${t} init\` to create .agents/skills and the bridges into it`}),skillRepair:()=>`run \`${X}\`, which creates \`.agents/skills\` and the bridges`},missing:{detail:`no bridge at this path — the harness sees zero project skills`,repair:({file:e},t)=>({command:`${t} init`,instruction:`run \`${t} init\` to create the bridge at ${e}`}),skillRepair:()=>`run \`${X}\``},degraded:{detail:`expected a directory but found a regular file — checkout without core.symlinks`,repair:({file:e},t)=>({command:`${t} init --copy --force ${e}`,instruction:`run \`${t} init --copy --force ${e}\` to rebuild ${e} as a real directory`}),skillRepair:({file:e})=>`run \`${X} --copy --force ${e}\``},stale:{detail:`symlink does not resolve to .agents/skills`,repair:({file:e},t)=>({command:`${t} init --force ${e}`,instruction:`run \`${t} init --force ${e}\` to repoint ${e} at .agents/skills`}),skillRepair:({file:e})=>`run \`${X} --force ${e}\``},"diverged-bridge":{detail:`only the bridge changed since the two last agreed — an agent wrote through the copy`,repair:({file:e},t)=>({command:``,instruction:`replace .agents/skills with ${e} to keep the newer edit, then run \`${t} init --force ${e}\``}),skillRepair:({file:e})=>`replace .agents/skills with ${e} to keep the newer edit, then run \`${X} --force ${e}\``},"diverged-canonical":{detail:`only .agents/skills changed since the two last agreed — the copy is stale`,repair:({file:e},t)=>({command:`${t} init --copy --force ${e}`,instruction:`run \`${t} init --copy --force ${e}\` to rebuild ${e} from the newer .agents/skills`}),skillRepair:({file:e})=>`run \`${X} --copy --force ${e}\``},"diverged-both":{detail:`both sides changed since they last agreed — rebuilding would discard one of them`,repair:({file:e})=>({command:``,instruction:`reconcile .agents/skills with ${e} by hand — rebuilding would discard one of them; \`git diff --no-index .agents/skills ${e}\` shows what differs`}),skillRepair:({file:e})=>`run \`git diff --no-index .agents/skills ${e}\` and reconcile by hand`},"diverged-unknown":{detail:`contents differ and no commit where they agreed was found — which side moved is unknown`,repair:({file:e})=>({command:``,instruction:`reconcile .agents/skills with ${e} by hand — which side moved is unknown; \`git diff --no-index .agents/skills ${e}\` shows what differs`}),skillRepair:({file:e})=>`run \`git diff --no-index .agents/skills ${e}\` and reconcile by hand`},"unpinned-copy":{detail:`tracked copy without the skip-worktree bit — the tree is dirty with content that must not be committed`,repair:({file:e})=>({command:`git ls-files -z ${e} | xargs -0 git update-index --skip-worktree`,instruction:`run \`git ls-files -z ${e} | xargs -0 git update-index --skip-worktree\` to restore the skip-worktree bit`}),skillRepair:({file:e})=>`run \`git ls-files -z ${e} | xargs -0 git update-index --skip-worktree\``}};repairsOf(za);const Ba={"no-instructions":{detail:`no AGENTS.md at the repository root, so the instructions this repository has reach one harness at most`,repair:()=>({command:``,instruction:`hand this to \`${X}\`, which consolidates what the repository has into AGENTS.md, or derives it`}),skillRepair:()=>`run \`${X}\`, which consolidates or derives AGENTS.md`},"instructions-missing":{detail:`no instruction bridge at this path — the harness reads none of AGENTS.md`,repair:({file:e})=>({command:``,instruction:`hand ${e} to \`${X}\`, which writes the bridge into it`}),skillRepair:()=>`run \`${X}\``},"instructions-unbridged":{detail:`the file is present but names AGENTS.md nowhere — the harness reads none of it`,repair:({file:e})=>({command:``,instruction:`hand ${e} to \`${X}\`, which adds the bridge without discarding what the file already says`}),skillRepair:()=>`run \`${X}\`, which adds the bridge without discarding what the file already says`},"instructions-shadowing":{detail:`this file suppresses the AGENTS.md beside it — the harness reads this instead, and none of AGENTS.md`,repair:({file:e})=>({command:``,instruction:`hand ${e} to \`${X}\`, which consolidates what it says into AGENTS.md, or adds an @AGENTS.md import above it where the file has to stay`}),skillRepair:()=>`run \`${X}\`, which consolidates the file into AGENTS.md or imports AGENTS.md from it`},"instructions-superseded":{detail:`a bridge from before the harness read AGENTS.md itself — it still works, and nothing needs it`,repair:({file:e})=>({command:``,instruction:`remove ${e}, or keep it for sessions that cannot read AGENTS.md directly — \`${X}\` offers the choice`}),skillRepair:()=>`run \`${X}\`, which offers to remove it`},"instructions-unreadable":{detail:`the settings file does not parse, so the harness reads none of it`,repair:({file:e})=>({command:``,instruction:`fix the JSON in ${e} by hand, then hand it to \`${X}\``}),skillRepair:()=>`fix the JSON by hand, then run \`${X}\``}};repairsOf(Ba);const Va={"deprecated-harness":{detail:`a projection under a harness name that has been superseded — the replacement reads .agents/skills natively and needs no projection at all`,repair:({file:e})=>({command:``,instruction:`remove ${e} and enable the harness that replaced it — \`${La}\` offers the correction`}),skillRepair:()=>`run \`${La}\``},"ignored-bridge":{detail:`a .gitignore rule matches this bridge — an untracked bridge swallows a real edit silently`,repair:({file:e})=>({command:``,instruction:`narrow or remove the .gitignore rule matching ${e} — \`${La}\` offers the correction`}),skillRepair:()=>`run \`${La}\``},"unread-local-override":{detail:`no harness reads this filename, so everything in it is invisible to every agent`,repair:({file:e})=>({command:``,instruction:`move ${e} to CLAUDE.local.md, or consolidate it into AGENTS.md — \`${La}\` offers the correction`}),skillRepair:()=>`run \`${La}\``},"unloadable-skill":{detail:`frontmatter that does not parse, or no description — either one makes a harness skip the skill outright`,repair:({file:e})=>({command:``,instruction:`quote the description in ${e}, or add one — \`${La}\` offers the correction`}),skillRepair:()=>`run \`${La}\``}};repairsOf(Va);const Ha={"mcp-golden-unreadable":{detail:`the golden MCP set does not parse — the locator gives the line and column, and nothing else can be said about it`,repair:e=>({command:``,instruction:`fix the TOML at ${locatorText(e)}`}),skillRepair:e=>`fix the TOML at ${locatorText(e)} by hand — the reported line and column are all that can be quoted, because the parser's own message repeats the offending line and that line is the one holding the credential`},"mcp-target-unreadable":{detail:`this harness config does not parse, so the harness starts none of its servers and nothing in it can be compared`,repair:e=>({command:``,instruction:`fix the syntax of ${locatorText(e)}`}),skillRepair:e=>`fix the syntax of ${locatorText(e)} by hand`},"mcp-unprojected":{detail:`the golden set declares this server and the harness config does not carry it`,repair:({file:e,server:t})=>({command:``,instruction:`add the server ${t} to ${e}, or drop it from the golden set — \`${La}\` offers the correction`}),skillRepair:e=>`hand ${locatorText(e)} to \`${La}\`, which projects it from its golden entry with \`mcp project\` — or drop it from the golden set`},"mcp-undeclared":{detail:`the harness config carries this server and the golden set does not declare it`,repair:({file:e,server:t})=>({command:``,instruction:`add the server ${t} to ${Ra}, or drop it from ${e} — \`${La}\` offers the import`}),skillRepair:e=>`hand ${locatorText(e)} to \`${La}\`, which imports it field by field with \`mcp reconcile\`, refusing any literal credential — or drop it from ${e.file}`},"mcp-diverged-target":{detail:`only the harness config changed since the two last agreed — the edit was made through the copy`,repair:e=>({command:``,instruction:`reconcile the value at ${locatorText(e)} back into ${Ra} — \`${La}\` offers the import`}),skillRepair:e=>`hand ${locatorText(e)} to \`${La}\`, which imports the field into ${Ra} with \`mcp reconcile\` once approved`},"mcp-diverged-golden":{detail:`only the golden set changed since the two last agreed — the harness copy is stale`,repair:e=>({command:``,instruction:`update ${locatorText(e)} from the golden entry — \`${La}\` offers the correction`}),skillRepair:e=>`hand ${locatorText(e)} to \`${La}\`, which updates it from the golden entry with \`mcp project\``},"mcp-diverged-both":{detail:`both sides changed since they last agreed — merging either way would discard the other`,repair:e=>({command:``,instruction:`reconcile ${locatorText(e)} against ${Ra} by hand`}),skillRepair:e=>`reconcile ${locatorText(e)} against ${Ra} by hand — never merge a three-way conflict automatically`},"mcp-diverged-unknown":{detail:`the two disagree and no baseline says which side moved — neither history nor a last-projected record covers this server`,repair:e=>({command:``,instruction:`compare ${locatorText(e)} against ${Ra} by hand`}),skillRepair:e=>`compare ${locatorText(e)} against ${Ra} by hand`},"mcp-literal-secret":{detail:`a credential-bearing field holds a literal rather than a reference to an environment variable`,repair:e=>({command:``,instruction:`move the value at ${locatorText(e)} into an environment variable and reference it`}),skillRepair:e=>`move the value at ${locatorText(e)} into an environment variable and reference it — read the value from the file, never from this report, and never repeat it back`},"mcp-committed-secret":{detail:`a credential-bearing field holds a literal in a git-tracked file — the credential is committed, and moving it does not un-commit it`,repair:e=>({command:``,instruction:`rotate the credential behind ${locatorText(e)}, then reference it from an environment variable`}),skillRepair:e=>`rotate the credential behind ${locatorText(e)} at its issuer, then reference it from an environment variable — it is in the repository's history, so moving it is not enough`}};repairsOf(Ha);const Ua={"nonstandard-instructions":{detail:`instruction content only one harness reads — AGENTS.md carries the same prose to all of them`,repair:({file:e})=>({command:``,instruction:`consolidate ${e} into AGENTS.md — \`${X}\` offers the consolidation, and keeps the content reachable where this harness needs it`}),skillRepair:({file:e})=>`hand ${e} to \`${X}\`, which consolidates it into AGENTS.md`},"nonstandard-rule":{detail:`a path-scoped rule only one harness reads — a skill reaches every harness where the scoping is incidental`,repair:({file:e})=>({command:``,instruction:`convert ${e} into a skill under .agents/skills where its guidance is not tied to the paths it names — \`${X}\` offers the conversion; keep it where the path scoping is the point`}),skillRepair:({file:e})=>`hand ${e} to \`${X}\` to convert into a skill, unless the path scoping is load-bearing`},"nonstandard-command":{detail:`a harness command file — a skill is the portable form, and this harness reads skills too`,repair:({file:e})=>({command:``,instruction:`move ${e} to .agents/skills/<name>/SKILL.md — \`${X}\` offers the move`}),skillRepair:({file:e})=>`hand ${e} to \`${X}\`, which moves it to .agents/skills`},"nonstandard-skill":{detail:`a skill under a harness directory rather than the canonical one, where only that harness finds it`,repair:({file:e})=>({command:``,instruction:`move ${e} to .agents/skills and project it back where the harness needs one — \`${X}\` offers the move`}),skillRepair:({file:e})=>`hand ${e} to \`${X}\`, which moves it to .agents/skills`},"nonstandard-subagent":{detail:`a subagent definition with no cross-harness form — nothing outside this harness can read it, and no canonical form exists yet`,repair:({file:e})=>({command:``,instruction:`leave ${e} where it is and record that it reaches one harness only — no portable form exists to convert it to`}),skillRepair:({file:e})=>`leave ${e} in place — no portable form exists yet, so this is work for a person rather than a skill`}};repairsOf(Ua);const Wa={...za,...Ba,...Va,...Ha,...Ua};repairsOf(Wa);function repairFor(e){return{problem:e,...Wa[e]}}const Ga=`.agents/skills`,Ka=`AGENTS.local.md`;function frontmatterFault(e){let t=/^---\n([\s\S]*?)\n---/.exec(e);if(!t)return`unparseable`;let n=/^description:[ \t]*(.*)$/m.exec(t[1])?.[1]?.trim();if(!n)return`no-description`;if(!/^(['"]).*\1$/.test(n)&&/:\s/.test(n))return`unparseable`}function diagnoseConfiguration({root:e,git:t,cli:n}){let i=[],add=(e,t)=>{let{detail:r,repair:a}=repairFor(t);i.push({path:e,problem:t,detail:r,repair:a({file:e},n)})},a=selectHarnesses(e,[]);for(let t of a){let n=t.project.skillsDirectory;t.deprecated&&n&&r(v(e,n))&&add(n,`deprecated-harness`)}for(let n of a){let i=n.project.skillsDirectory;i&&r(v(e,i))&&t.isIgnored(i)&&add(i,`ignored-bridge`)}r(v(e,Ka))&&add(Ka,`unread-local-override`);for(let t of filesUnder(v(e,Ga)).filter(e=>e.endsWith(`SKILL.md`)))frontmatterFault(o(v(e,Ga,t),`utf8`))&&add(`${Ga}/${t}`,`unloadable-skill`);return i}const qa=[`transport`,`command`,`args`,`env`,`url`,`headers`,`description`,`enabled`,`timeout`,`source`],Ja=new Set([`env`,`headers`]);function sameValue(e,t,n){if(Ja.has(e)&&isRecord$1(t)&&isRecord$1(n)){let e=Object.keys(t);return e.length===Object.keys(n).length&&e.every(e=>t[e]===n[e])}return JSON.stringify(t)===JSON.stringify(n)}function divergingFields(e,t,n=new Set(qa)){return qa.filter(r=>{if(!n.has(r))return!1;let i=e[r];if(i===void 0)return!1;if(Ja.has(r)&&isRecord$1(i)&&isRecord$1(t[r])){let e=t[r];return Object.keys(i).some(t=>i[t]!==e[t])}return!sameValue(r,i,t[r])})}function sameField(e,t,n){return sameValue(e,t?.[e],n?.[e])}function stringMap(e){if(!isRecord$1(e))return;let t=Object.entries(e).filter(([,e])=>typeof e==`string`);return t.length?Object.fromEntries(t):void 0}const Ya=new Set([`stdio`,`http`,`sse`]);function transportOf(e){let t=e.type??e.transport;if(typeof t==`string`&&Ya.has(t))return t;if(typeof e.url==`string`)return`http`;if(typeof e.command==`string`)return`stdio`}function serverFrom(e){let t=Array.isArray(e.args)&&e.args.every(e=>typeof e==`string`),n=transportOf(e),r=stringMap(e.env),i=stringMap(e.headers);return{...n?{transport:n}:{},...typeof e.command==`string`?{command:e.command}:{},...t?{args:e.args}:{},...r?{env:r}:{},...typeof e.url==`string`?{url:e.url}:{},...i?{headers:i}:{},...typeof e.description==`string`?{description:e.description}:{},...typeof e.enabled==`boolean`?{enabled:e.enabled}:{},...typeof e.timeout==`number`?{timeout:e.timeout}:{},...typeof e.source==`string`?{source:e.source}:{}}}const Xa=/^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/,Za=/\$\{[^}]*\}|\$[A-Za-z_]/;var Refusal=class extends Error{field;reason;constructor(e,t){super(t),this.field=e,this.reason=t}};function refuse(e,t){throw new Refusal(e,t)}function rendering(e){try{return{kind:`entry`,entry:e()}}catch(e){if(!(e instanceof Refusal))throw e;return{kind:`refused`,field:e.field,reason:e.reason}}}function assertRunnable(e){(e.transport===`stdio`?!e.command:!e.url)&&refuse(e.transport===`stdio`?`command`:`url`,`the golden set leaves it unset and the target requires it`)}function defined(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function mapValues(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t(n)]))}function noReferenceIn(e,t,n){for(let r of t){let t=e[r];(Array.isArray(t)?t:[t]).some(e=>typeof e==`string`&&Za.test(e))&&refuse(r,`${n} documents no reference expansion here`)}}const Qa={fields:new Set([`transport`,`command`,`args`,`env`,`url`,`headers`,`description`,`timeout`]),read:serverFrom,write:e=>rendering(()=>(assertRunnable(e),defined({type:e.transport,command:e.command,args:e.args,env:e.env,url:e.url,headers:e.headers,description:e.description,timeout:e.timeout})))};function toCursor(e,t){return e.replace(/\$\{([^}]*)\}|\$[A-Za-z_]/g,(e,n)=>((n===void 0||!Xa.test(e))&&refuse(t,`Cursor expands only a plain variable reference, with no default`),`\${env:${n}}`))}function fromCursor(e){return e.replace(/\$\{env:([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,t)=>`\${${t}}`)}function fromCursorEntry(e){let strings=e=>typeof e==`string`?fromCursor(e):e,map=e=>isRecord$1(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,strings(t)])):e;return{...e,command:strings(e.command),args:Array.isArray(e.args)?e.args.map(strings):e.args,env:map(e.env),url:strings(e.url),headers:map(e.headers)}}const $a={fields:new Set([`command`,`args`,`env`,`url`,`headers`]),read:e=>serverFrom(fromCursorEntry(e)),write:e=>rendering(()=>(assertRunnable(e),defined({type:e.transport===`stdio`?`stdio`:void 0,command:e.command&&toCursor(e.command,`command`),args:e.args?.map(e=>toCursor(e,`args`)),env:mapValues(e.env,e=>toCursor(e,`env`)),url:e.url&&toCursor(e.url,`url`),headers:mapValues(e.headers,e=>toCursor(e,`headers`))})))},eo=/^Bearer \$\{([A-Za-z_][A-Za-z0-9_]*)\}$/;function codexEnv(e){let t={},n=[];for(let[r,i]of Object.entries(e??{}))Xa.exec(i)?.[1]===r?n.push(r):Za.test(i)?refuse(`env`,`Codex passes a variable through only under its own name`):t[r]=i;return defined({env:Object.keys(t).length?t:void 0,env_vars:n.length?n:void 0})}function codexHeaders(e){let t={},n={},r;for(let[i,a]of Object.entries(e??{})){let e=Xa.exec(a)?.[1],o=eo.exec(a)?.[1];o&&i===`Authorization`?r=o:e?n[i]=e:Za.test(a)?refuse(`headers`,`Codex fills a header only from a whole variable reference, or Bearer and one`):t[i]=a}return defined({http_headers:Object.keys(t).length?t:void 0,env_http_headers:Object.keys(n).length?n:void 0,bearer_token_env_var:r})}function stringRecord(e){return isRecord$1(e)?Object.fromEntries(Object.entries(e).filter(([,e])=>typeof e==`string`)):{}}function fromCodex(e){let t=Array.isArray(e.env_vars)?e.env_vars.filter(e=>typeof e==`string`):[],n={...stringRecord(e.env),...Object.fromEntries(t.map(e=>[e,`\${${e}}`]))},r=e.bearer_token_env_var,i={...stringRecord(e.http_headers),...Object.fromEntries(Object.entries(stringRecord(e.env_http_headers)).map(([e,t])=>[e,`\${${t}}`])),...typeof r==`string`?{Authorization:`Bearer \${${r}}`}:{}},a=e.tool_timeout_sec;return{command:e.command,args:e.args,env:n,url:e.url,headers:i,enabled:e.enabled,timeout:typeof a==`number`?Math.round(a*1e3):void 0}}const to={fields:new Set([`transport`,`command`,`args`,`env`,`url`,`headers`,`enabled`,`timeout`]),defaults:{timeout:6e4},read:e=>serverFrom(fromCodex(e)),write:e=>rendering(()=>(e.transport===`sse`&&refuse(`transport`,`Codex supports no SSE transport`),assertRunnable(e),noReferenceIn(e,[`command`,`args`,`url`],`Codex`),defined({command:e.command,args:e.args,...codexEnv(e.env),url:e.url,...codexHeaders(e.headers),enabled:e.enabled,tool_timeout_sec:e.timeout===void 0?void 0:e.timeout/1e3})))};function fromGemini(e){let{httpUrl:t,url:n,...r}=e;return typeof t==`string`?{...r,type:`http`,url:t}:typeof n==`string`?{...r,type:`sse`,url:n}:r}const no={"claude-code":Qa,cursor:$a,codex:to,"gemini-cli":{fields:new Set([`transport`,`command`,`args`,`env`,`url`,`headers`,`timeout`]),defaults:{timeout:6e5},read:e=>serverFrom(fromGemini(e)),write:e=>rendering(()=>(assertRunnable(e),defined({command:e.command,args:e.args,env:e.env,url:e.transport===`sse`?e.url:void 0,httpUrl:e.transport===`http`?e.url:void 0,headers:e.headers,timeout:e.timeout})))}};function stripJsonComments(e){let t=``,n=0,r=!1,i=!1;for(;n<e.length;){let a=e[n];if(r){t+=a,i?i=!1:a===`\\`?i=!0:a===`"`&&(r=!1),n+=1;continue}if(a===`"`){r=!0,t+=a,n+=1;continue}if(a===`/`&&e[n+1]===`/`){for(;n<e.length&&e[n]!==`
94
94
  `;)n+=1;continue}if(a===`/`&&e[n+1]===`*`){for(n+=2;n<e.length&&(e[n]!==`*`||e[n+1]!==`/`);)n+=1;n+=2;continue}t+=a,n+=1}return t}function parseJsonWithComments(e){try{return JSON.parse(stripJsonComments(e))}catch{return}}
95
95
  /*!
96
96
  * Copyright (c) Squirrel Chat et al., All rights reserved.
@@ -470,4 +470,4 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
470
470
  `,i=Object.entries(n).map(([e,t])=>`${tomlKey(e)} = ${renderTomlInline(t)}\n`);return`${e}${r}\n[${t.map(tomlKey).join(`.`)}]\n${i.join(``)}`}function lineEndAt(e,t){let n=e.indexOf(`
471
471
  `,t);return n===-1?e.length:n}function setTomlKey(e,t,n,r){let i;try{i=parseTOML(e)}catch{return{kind:`refused`,reason:`unreadable`}}let a=i.body[0].body.filter(e=>e.type===`TOMLTable`),o=a.find(e=>e.kind===`standard`&&e.resolvedKey.length===t.length&&startsWith(e.resolvedKey,t));if(!o)return{kind:`refused`,reason:`absent`};let s=o.body;if(a.some(e=>startsWith(e.resolvedKey,[...t,n]))||s.some(e=>keyNames(e.key)[0]===n&&e.key.keys.length>1))return{kind:`refused`,reason:`shape`};let c=s.find(e=>e.key.keys.length===1&&keyNames(e.key)[0]===n);if(c&&r!==void 0)return{kind:`edited`,text:`${e.slice(0,c.value.range[0])}${renderTomlInline(r)}${e.slice(c.value.range[1])}`};if(c){let t=e.lastIndexOf(`
472
472
  `,c.range[0]-1)+1,n=lineEndAt(e,c.range[1]);return{kind:`edited`,text:`${e.slice(0,t)}${e.slice(Math.min(n+1,e.length))}`}}if(r===void 0)return{kind:`edited`,text:e};let l=lineEndAt(e,s.at(-1)?.range[1]??o.range[0]);return{kind:`edited`,text:`${e.slice(0,l)}\n${tomlKey(n)} = ${renderTomlInline(r)}${e.slice(l)}`}}function read$1(e,t){let n=v(e,t);return r(n)?o(n,`utf8`):void 0}__name(read$1,`read`);const wc={both:`both sides changed since the last projection — a three-way conflict for a person to settle, never imported`,unknown:`no baseline says which side changed — compare the two by hand; never imported`};function inferredTransport(e){return e.url===void 0?`stdio`:`http`}function mapValue(e,t){let n=Object.entries(e).flatMap(([e])=>{let n=isRecord$1(t)?t[e]:void 0;return typeof n==`string`?[[e,n]]:[]});return n.length?Object.fromEntries(n):void 0}function reconcileMcp({root:e,git:t,accept:n}){let r=read$1(e,uo),i=parseGoldenSet(r);if(i.kind!==`servers`)return i;let a=parseProjectionRecord(read$1(e,fo)),o=new McpBaseline({git:t,record:a}),s=[],c=[];for(let t of mcpTargets(e)){let n=parseTarget(t,read$1(e,t.path));if(n.kind===`unreadable`){s.push({path:t.path,action:`refuse`,detail:`the target does not parse`});continue}if(n.kind===`absent`)continue;let r=no[t.dialect];for(let[e,a]of n.servers){let n=i.servers.get(e),at=n=>locatorText({file:t.path,server:e,field:n}),offer=(i,o)=>{let l=literalsIn(i,o);for(let e of l)s.push({path:at(e),action:`refuse`,detail:`${e} holds a literal credential, which never enters the golden set — set it in the environment and reference it as \${VAR}`});let u=withoutLiterals(i,o,l,n);if(l.length&&(u===void 0||sameField(i,{[i]:u},n)))return;let d=r.defaults?.[i];if(d!==void 0&&sameField(i,{[i]:u},{[i]:d})){s.push({path:at(i),action:`skip`,detail:`${t.dialect} fills this in by default, so it may not be the user's — set it in the golden set by hand if it is`});return}let p={path:at(i),action:`import`,detail:n?`only the harness changed it — approve to take it into the golden set`:`the golden set does not declare this server — approve each field to add it`,value:u===void 0?`(unset)`:`${i} = ${renderTomlInline(u)}`};s.push(p),c.push({row:p,config:t,server:e,field:i,value:u,carried:a,adds:!n})};if(!n){for(let e of qa)r.fields.has(e)&&a[e]!==void 0&&(e!==`transport`||a.transport!==inferredTransport(a))&&offer(e,a[e]);continue}for(let i of divergingFields(n,a,r.fields)){let r=o.directionOf(t,e,i,n,a);r!==`golden`&&(r===`target`?offer(i,i===`env`||i===`headers`?mapValue(n[i],a[i]):a[i]):s.push({path:at(i),action:`skip`,detail:wc[r]}))}}}if(!n.length)return{kind:`planned`,rows:s,written:!1};let l=approve(c,s,n);if(l.kind===`rejected`)return l;let u=r,d=[];for(let[e,t]of groupByServer(l.offers)){if(t[0]?.adds){let n=Object.fromEntries(qa.flatMap(e=>{let n=t.find(t=>t.field===e);return n?[[e,n.value]]:[]}));u=land(u,appendInlineTomlTable(u,[`servers`,e],n),e,n,t,d);continue}for(let n of t){let t={...parseGoldenSet(u).servers.get(e),[n.field]:n.value};n.value===void 0&&delete t[n.field];let r=setTomlKey(u,[`servers`,e],n.field,n.value);u=land(u,r.kind===`edited`?r.text:void 0,e,t,[n],d)}}return u!==r&&(m(v(e,uo),u),writeRecord$1(e,a,o,d,parseGoldenSet(u))),{kind:`planned`,rows:s,written:!0}}function literalsIn(e,t){return t===void 0?[]:e===`args`?nonSecretArgs(t).length===t.length?[]:[`args`]:e!==`env`&&e!==`headers`&&e!==`url`?[]:credentialFields({[e]:t})}function withoutLiterals(e,t,n,r){if(!n.length)return t;if(e!==`env`&&e!==`headers`)return;let i={...t};for(let t of n){let n=t.slice(e.length+1),a=r?.[e]?.[n];a===void 0?delete i[n]:i[n]=a}return Object.keys(i).length?i:void 0}function approve(e,t,n){let r=[],i=[];for(let a of new Set(n)){let n=e.find(e=>e.row.path===a);if(n)i.push(n);else{let e=t.find(e=>e.path===a);r.push(e?`${a} is ${e.action}, not importable: ${e.detail}`:`${a} names no importable field`)}}for(let[e,t]of groupByServer(i)){for(let n of new Set(t.map(e=>e.field))){let i=t.filter(e=>e.field===n);i.some(e=>!sameField(n,{[n]:e.value},{[n]:i[0]?.value}))&&r.push(`servers.${e}.${n} is approved from more than one target with different values — approve one`)}t[0]?.adds&&!t.some(e=>e.field===`command`||e.field===`url`)&&r.push(`servers.${e} would be added with nothing to run — approve its command or url too`)}return r.length?{kind:`rejected`,reasons:r}:{kind:`approved`,offers:i}}function groupByServer(e){let t=new Map;for(let n of e)t.set(n.server,[...t.get(n.server)??[],n]);return t}function land(e,t,n,r,i,a){let o=parseGoldenSet(e),s=t===void 0?void 0:parseGoldenSet(t),c=s?.kind===`servers`&&qa.every(e=>e===`transport`&&r.transport===void 0||sameField(e,s.servers.get(n),r))&&[...o.servers].every(([e,t])=>e===n||JSON.stringify(s.servers.get(e))===JSON.stringify(t));for(let e of i)e.row.action=c?`imported`:`edit`,e.row.detail=c?`written into the golden set`:`the golden set writes this server in a shape that cannot be edited byte-safely — apply the value by hand`;return c?(a.push(...i),t):e}function writeRecord$1(e,t,n,r,i){for(let e of r){let r=t.get(e.config.path)??new Map,a=r.get(e.server),o=a?{...a,[e.field]:e.value}:baseEntry(e,n,i.servers.get(e.server));o&&(e.value===void 0&&delete o[e.field],r.set(e.server,o),t.set(e.config.path,r))}let o=v(e,fo);a(g(o),{recursive:!0}),m(o,formatProjectionRecord(t))}__name(writeRecord$1,`writeRecord`);function baseEntry(e,t,n){if(e.adds)return{...n};let r={};for(let i of no[e.config.dialect].fields){if(n[i]===void 0)continue;if(sameField(i,n,e.carried)){r[i]=n[i];continue}let a=t.baseFor(e.config,e.server,i);if(!a)return;r[i]=a[i]}return r}const Tc=command({name:`reconcile`,description:`Import a harness-side MCP change into the golden set, one approved field at a time. A dry run unless --accept names a field.`,options:{root:{description:`Repository or package directory. Defaults to the current directory.`,type:q(K())},accept:{description:`Approve one field by the path a dry run lists for it; repeat for each field. There is no approve-all.`,type:q(In(K()))},format:{description:`Output format: toon (default), json, or text for a human-readable report.`,type:q(K()),default:`toon`}},run(e){try{let t=parseFormat(e.format),n=e.root??process.cwd(),r=e.accept??[],i=reconcileMcp({root:n,git:new GitBridgeState(n),accept:r});if(i.kind===`unreadable`){let e=i.position?` at line ${i.position.line}, column ${i.position.column}`:``;return process.stderr.write(`error: ${uo} does not parse${e}.\n`),O.error}return i.kind===`rejected`?(process.stderr.write(`error: nothing written.\n${i.reasons.map(e=>`- ${e}\n`).join(``)}`),O.error):i.kind===`absent`?(writeResult({golden:`0 servers — no golden set at ${uo}`,mode:`nothing to reconcile into`,fields:`0 fields`,record:`not written`},t),O.success):(writeResult({golden:uo,mode:i.written?`written — only the fields named by --accept`:`dry run — nothing written; re-run with --accept <path> for each approved field`,fields:i.rows.length?i.rows:`0 fields — no harness holds a change the golden set lacks`,record:i.written?fo:`not written — dry run`},t),O.success)}catch(e){return process.stderr.write(`error: ${e instanceof Error?e.message:`MCP reconcile failed.`}\n`),O.error}}});function indentUnit(e){let t=/\n([ \t]+)\S/.exec(e);return t?t[1]:` `}function jsonAt(e,t,n){return JSON.stringify(e,null,t).replaceAll(`
473
- `,`\n${t.repeat(n)}`)}function objectAt(e,t){let n=e&&(t.length?zi(e,t):e);return n?.type===`object`?n:void 0}function insertJsonProperty(e,t,n,r){let i=objectAt(Ri(e),t);if(!i||zi(i,[n]))return;let a=t.length+1,o=indentUnit(e),s=`${o.repeat(a)}${JSON.stringify(n)}: ${jsonAt(r,o,a)}`,c=i.children?.at(-1);if(c){let t=c.offset+c.length;return`${e.slice(0,t)},\n${s}${e.slice(t)}`}let l=i.offset+1,u=i.offset+i.length-1;return`${e.slice(0,l)}\n${s}\n${o.repeat(a-1)}${e.slice(u)}`}function replaceJsonValue(e,t,n){let r=Ri(e),i=r&&zi(r,t);if(!i)return{kind:`refused`,reason:`absent`};let a=i.offset+i.length,o=e.slice(i.offset,a);return stripJsonComments(o)===o?{kind:`edited`,text:`${e.slice(0,i.offset)}${jsonAt(n,indentUnit(e),t.length)}${e.slice(a)}`}:{kind:`refused`,reason:`comment`}}function createFile(e,t,n){return e.format===`toml`?renderTomlTable([e.key,t],n):`${JSON.stringify({[e.key]:{[t]:n}},null,2)}\n`}function appendServer(e,t,n,r){return e.format===`toml`?appendTomlTable(t,[e.key,n],r):insertJsonProperty(t,[e.key],n,r)??insertJsonProperty(t,[],e.key,{[n]:r})}function replaceServer(e,t,n,r){let i=e.format===`toml`?replaceTomlTable(t,[e.key,n],r):replaceJsonValue(t,[e.key,n],r);return i.kind===`edited`?i.text:void 0}function renderEntry(e,t,n){return e.format===`toml`?renderTomlTable([e.key,t],n):JSON.stringify({[t]:n},null,2)}function read(e,t){let n=v(e,t);return r(n)?o(n,`utf8`):void 0}const Ec={target:`the target changed since the last projection — reconcile it into the golden set first`,both:`both sides changed since the last projection — a three-way conflict for a person to settle`,unknown:`no baseline says which side changed — compare the two by hand`};function heldBack(e){return[`both`,`unknown`,`target`].find(t=>e.includes(t))}function projectMcp({root:e,git:t,write:n}){let r=parseGoldenSet(read(e,uo));if(r.kind!==`servers`)return r;let i=parseProjectionRecord(read(e,fo)),a=new McpBaseline({git:t,record:i}),o=[],s=[],c=[];for(let t of mcpTargets(e)){let n=read(e,t.path),i=parseTarget(t,n);if(i.kind===`unreadable`){o.push({target:t.path,server:``,action:`refuse`,detail:`the target does not parse`});continue}let l={config:t,source:n,created:n===void 0,servers:i.kind===`servers`?i.servers:new Map,agreed:new Map};c.push(l);let u=no[t.dialect];for(let[e,n]of r.servers){let row=(n,r)=>o.push({target:t.path,server:e,action:n,detail:r}),r=credentialFields(n)[0];if(r){row(`refuse`,`the golden set holds a literal credential at ${r} — reference it as \${VAR} first`);continue}let i=u.write(n);if(i.kind===`refused`){row(`refuse`,`${i.field}: ${i.reason}`);continue}let c=l.servers.get(e);if(!c){let r=l.source===void 0?createFile(t,e,i.entry):appendServer(t,l.source,e,i.entry);apply(l,e,n,i.entry,r,l.created?`creates the file`:`appends the server`,row,s);continue}let d=divergingFields(n,c,u.fields);if(!d.length){l.agreed.set(e,n);continue}let p=heldBack(d.map(r=>a.directionOf(t,e,r,n,c)));if(p){row(`skip`,Ec[p]);continue}let m=replaceServer(t,l.source,e,i.entry);apply(l,e,n,i.entry,m,`replaces ${d.join(`, `)}`,row,s)}}if(n){for(let t of c)t.source!==void 0&&t.source!==read(e,t.config.path)&&writeTarget(e,t);writeRecord(e,i,c)}return{kind:`planned`,rows:o,entries:s,written:n}}function apply(e,t,n,r,i,a,o,s){let c=!e.servers.has(t),l=i!==void 0&&readsBack(e,t,n,i),u=l?c?`add`:`update`:`edit`;if(s.push({target:e.config.path,server:t,action:u,entry:renderEntry(e.config,t,r)}),!l){o(`edit`,c?`the file has no safe place to add it — apply the entry by hand`:`an in-place change here is applied by hand`);return}e.source=i,e.servers=parseTarget(e.config,i).servers,e.agreed.set(t,n),o(u,a)}function readsBack(e,t,n,r){let i=parseTarget(e.config,r);if(i.kind!==`servers`)return!1;let a=i.servers.get(t),o=no[e.config.dialect].fields;return!a||divergingFields(n,a,o).length?!1:[...e.servers].every(([e,n])=>{if(e===t)return!0;let r=i.servers.get(e);return r!==void 0&&JSON.stringify(r)===JSON.stringify(n)})}function writeTarget(e,t){let n=v(e,t.config.path);a(g(n),{recursive:!0}),m(n,t.source)}function writeRecord(e,t,n){for(let e of n){let n=t.get(e.config.path)??new Map;for(let[t,r]of e.agreed)n.set(t,r);n.size&&t.set(e.config.path,n)}let r=v(e,fo);a(g(r),{recursive:!0}),m(r,formatProjectionRecord(t))}const Dc=command({name:`mcp`,description:`Work with the golden MCP server set at .agents/buddy-agent-harness/mcp.toml.`,commands:[command({name:`project`,description:`Project the golden MCP server set into each enabled harness. A dry run unless --write; never overwrites a change made on the harness side.`,options:{root:{description:`Repository or package directory. Defaults to the current directory.`,type:q(K())},write:{description:`Apply the plan and record what was projected. Without it nothing on disk changes.`,type:q(Fn())},format:{description:`Output format: toon (default), json, or text for a human-readable report.`,type:q(K()),default:`toon`}},run(e){try{let t=parseFormat(e.format),n=e.root??process.cwd(),r=e.write===!0,i=projectMcp({root:n,git:new GitBridgeState(n),write:r});if(i.kind===`unreadable`){let e=i.position?` at line ${i.position.line}, column ${i.position.column}`:``;return process.stderr.write(`error: ${uo} does not parse${e}.\n`),O.error}return i.kind===`absent`?(writeResult({golden:`0 servers — no golden set at ${uo}`,mode:`nothing to project`,actions:`0 changes`,record:`not written`},t),O.success):(writeResult({golden:uo,mode:r?`written`:`dry run — nothing written; re-run with --write to apply`,actions:i.rows.length?i.rows:`0 changes — every enabled harness already carries the golden set`,...i.entries.length?{entries:i.entries}:{},record:r?fo:`not written — dry run`},t),O.success)}catch(e){return process.stderr.write(`error: ${e instanceof Error?e.message:`MCP projection failed.`}\n`),O.error}}}),Tc]});function app(){return cli({name:`buddy-agent-harness`,version:`0.13.0`,description:`Initialize agent harness skill compatibility in consumer repositories.`}).command(ic).command(Ys).command(Dc).command(ha).command(rc).command($s)}async function run(e){try{let t=await app().parse(e);return typeof t==`number`?t:O.success}catch(e){return process.stderr.write(`error: ${e instanceof Error?e.message:`Invalid command.`}\n`),O.usage}}process.exitCode=await run([...process.argv.slice(0,2),`init`,...process.argv.slice(2)]);export{};
473
+ `,`\n${t.repeat(n)}`)}function objectAt(e,t){let n=e&&(t.length?zi(e,t):e);return n?.type===`object`?n:void 0}function insertJsonProperty(e,t,n,r){let i=objectAt(Ri(e),t);if(!i||zi(i,[n]))return;let a=t.length+1,o=indentUnit(e),s=`${o.repeat(a)}${JSON.stringify(n)}: ${jsonAt(r,o,a)}`,c=i.children?.at(-1);if(c){let t=c.offset+c.length;return`${e.slice(0,t)},\n${s}${e.slice(t)}`}let l=i.offset+1,u=i.offset+i.length-1;return`${e.slice(0,l)}\n${s}\n${o.repeat(a-1)}${e.slice(u)}`}function replaceJsonValue(e,t,n){let r=Ri(e),i=r&&zi(r,t);if(!i)return{kind:`refused`,reason:`absent`};let a=i.offset+i.length,o=e.slice(i.offset,a);return stripJsonComments(o)===o?{kind:`edited`,text:`${e.slice(0,i.offset)}${jsonAt(n,indentUnit(e),t.length)}${e.slice(a)}`}:{kind:`refused`,reason:`comment`}}function createFile(e,t,n){return e.format===`toml`?renderTomlTable([e.key,t],n):`${JSON.stringify({[e.key]:{[t]:n}},null,2)}\n`}function appendServer(e,t,n,r){return e.format===`toml`?appendTomlTable(t,[e.key,n],r):insertJsonProperty(t,[e.key],n,r)??insertJsonProperty(t,[],e.key,{[n]:r})}function replaceServer(e,t,n,r){let i=e.format===`toml`?replaceTomlTable(t,[e.key,n],r):replaceJsonValue(t,[e.key,n],r);return i.kind===`edited`?i.text:void 0}function renderEntry(e,t,n){return e.format===`toml`?renderTomlTable([e.key,t],n):JSON.stringify({[t]:n},null,2)}function read(e,t){let n=v(e,t);return r(n)?o(n,`utf8`):void 0}const Ec={target:`the target changed since the last projection — reconcile it into the golden set first`,both:`both sides changed since the last projection — a three-way conflict for a person to settle`,unknown:`no baseline says which side changed — compare the two by hand`};function heldBack(e){return[`both`,`unknown`,`target`].find(t=>e.includes(t))}function projectMcp({root:e,git:t,write:n}){let r=parseGoldenSet(read(e,uo));if(r.kind!==`servers`)return r;let i=parseProjectionRecord(read(e,fo)),a=new McpBaseline({git:t,record:i}),o=[],s=[],c=[];for(let t of mcpTargets(e)){let n=read(e,t.path),i=parseTarget(t,n);if(i.kind===`unreadable`){o.push({target:t.path,server:``,action:`refuse`,detail:`the target does not parse`});continue}let l={config:t,source:n,created:n===void 0,servers:i.kind===`servers`?i.servers:new Map,agreed:new Map};c.push(l);let u=no[t.dialect];for(let[e,n]of r.servers){let row=(n,r)=>o.push({target:t.path,server:e,action:n,detail:r}),r=credentialFields(n)[0];if(r){row(`refuse`,`the golden set holds a literal credential at ${r} — reference it as \${VAR} first`);continue}let i=u.write(n);if(i.kind===`refused`){row(`refuse`,`${i.field}: ${i.reason}`);continue}let c=l.servers.get(e);if(!c){let r=l.source===void 0?createFile(t,e,i.entry):appendServer(t,l.source,e,i.entry);apply(l,e,n,i.entry,r,l.created?`creates the file`:`appends the server`,row,s);continue}let d=divergingFields(n,c,u.fields);if(!d.length){l.agreed.set(e,n);continue}let p=heldBack(d.map(r=>a.directionOf(t,e,r,n,c)));if(p){row(`skip`,Ec[p]);continue}let m=replaceServer(t,l.source,e,i.entry);apply(l,e,n,i.entry,m,`replaces ${d.join(`, `)}`,row,s)}}if(n){for(let t of c)t.source!==void 0&&t.source!==read(e,t.config.path)&&writeTarget(e,t);writeRecord(e,i,c)}return{kind:`planned`,rows:o,entries:s,written:n}}function apply(e,t,n,r,i,a,o,s){let c=!e.servers.has(t),l=i!==void 0&&readsBack(e,t,n,i),u=l?c?`add`:`update`:`edit`;if(s.push({target:e.config.path,server:t,action:u,entry:renderEntry(e.config,t,r)}),!l){o(`edit`,c?`the file has no safe place to add it — apply the entry by hand`:`an in-place change here is applied by hand`);return}e.source=i,e.servers=parseTarget(e.config,i).servers,e.agreed.set(t,n),o(u,a)}function readsBack(e,t,n,r){let i=parseTarget(e.config,r);if(i.kind!==`servers`)return!1;let a=i.servers.get(t),o=no[e.config.dialect].fields;return!a||divergingFields(n,a,o).length?!1:[...e.servers].every(([e,n])=>{if(e===t)return!0;let r=i.servers.get(e);return r!==void 0&&JSON.stringify(r)===JSON.stringify(n)})}function writeTarget(e,t){let n=v(e,t.config.path);a(g(n),{recursive:!0}),m(n,t.source)}function writeRecord(e,t,n){for(let e of n){let n=t.get(e.config.path)??new Map;for(let[t,r]of e.agreed)n.set(t,r);n.size&&t.set(e.config.path,n)}let r=v(e,fo);a(g(r),{recursive:!0}),m(r,formatProjectionRecord(t))}const Dc=command({name:`mcp`,description:`Work with the golden MCP server set at .agents/buddy-agent-harness/mcp.toml.`,commands:[command({name:`project`,description:`Project the golden MCP server set into each enabled harness. A dry run unless --write; never overwrites a change made on the harness side.`,options:{root:{description:`Repository or package directory. Defaults to the current directory.`,type:q(K())},write:{description:`Apply the plan and record what was projected. Without it nothing on disk changes.`,type:q(Fn())},format:{description:`Output format: toon (default), json, or text for a human-readable report.`,type:q(K()),default:`toon`}},run(e){try{let t=parseFormat(e.format),n=e.root??process.cwd(),r=e.write===!0,i=projectMcp({root:n,git:new GitBridgeState(n),write:r});if(i.kind===`unreadable`){let e=i.position?` at line ${i.position.line}, column ${i.position.column}`:``;return process.stderr.write(`error: ${uo} does not parse${e}.\n`),O.error}return i.kind===`absent`?(writeResult({golden:`0 servers — no golden set at ${uo}`,mode:`nothing to project`,actions:`0 changes`,record:`not written`},t),O.success):(writeResult({golden:uo,mode:r?`written`:`dry run — nothing written; re-run with --write to apply`,actions:i.rows.length?i.rows:`0 changes — every enabled harness already carries the golden set`,...i.entries.length?{entries:i.entries}:{},record:r?fo:`not written — dry run`},t),O.success)}catch(e){return process.stderr.write(`error: ${e instanceof Error?e.message:`MCP projection failed.`}\n`),O.error}}}),Tc]});function app(){return cli({name:`buddy-agent-harness`,version:`0.14.0`,description:`Initialize agent harness skill compatibility in consumer repositories.`}).command(ic).command(Ys).command(Dc).command(ha).command(rc).command($s)}async function run(e){try{let t=await app().parse(e);return typeof t==`number`?t:O.success}catch(e){return process.stderr.write(`error: ${e instanceof Error?e.message:`Invalid command.`}\n`),O.usage}}process.exitCode=await run([...process.argv.slice(0,2),`init`,...process.argv.slice(2)]);export{};