import{v as e,xt as t}from"./server-lock-BpjJj3OD-DWhr5fHw.mjs";import{F as n,zr as r}from"./dist-tPUaTm_u.mjs";import{cpSync as i,existsSync as a,lstatSync as o,mkdirSync as s,realpathSync as c,rmSync as l}from"node:fs";import{basename as u,dirname as d,isAbsolute as f,join as p,posix as m,relative as h,resolve as g,sep as _,win32 as v}from"node:path";import{homedir as y}from"node:os";const b=e,x=t,S={MCP_DEBUG:`1`,OK_LOG_FILE:`/tmp/ok-mcp.log`},C=`# ok-mcp-v1`;function w(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.command!==`/bin/sh`||!Array.isArray(t.args)||t.args[0]!==`-l`||t.args[1]!==`-c`)return!1;let n=t.args[2];return typeof n==`string`&&n.includes(`# ok-mcp-v1`)}function T(e=process.argv[1]){if(!e)throw Error(`Cannot infer the local CLI entry for --dev-mcp because process.argv[1] is empty.`);let t=g(e);if(u(t)===`cli.mjs`&&u(d(t))===`dist`)return t;let n=t.split(_),r=n.lastIndexOf(`packages`);if(r===-1||n[r+1]!==`cli`)throw Error(`Cannot infer the repo root for --dev-mcp from ${t}. Run the local CLI from this repo so the built dist path can be derived.`);let i=n.slice(0,r);return p(i.length===0?_:i.join(_),`packages`,`cli`,`dist`,`cli.mjs`)}function E(e={}){return e.mode===`dev`?{command:`node`,args:[T(),`mcp`],env:{...S}}:{command:`/bin/sh`,args:[`-l`,`-c`,`# ok-mcp-v1
USER_BUNDLE="$HOME/Applications/Open Knowledge.app/Contents/Resources/cli/bin/ok.sh"
[ -f "$USER_BUNDLE" ] && [ -x "$USER_BUNDLE" ] && exec "$USER_BUNDLE" mcp
BUNDLE="/Applications/Open Knowledge.app/Contents/Resources/cli/bin/ok.sh"
[ -f "$BUNDLE" ] && [ -x "$BUNDLE" ] && exec "$BUNDLE" mcp
command -v npx >/dev/null 2>&1 && exec npx -y @inkeep/open-knowledge@latest mcp
for d in "$HOME/.nvm/versions/node"/*/bin "$HOME/.fnm/node-versions"/*/installation/bin "$HOME/.asdf/installs/nodejs"/*/bin /opt/homebrew/bin /usr/local/bin "$HOME/.local/bin" "$HOME/.volta/bin"; do
  [ -f "$d/npx" ] && [ -x "$d/npx" ] && exec "$d/npx" -y @inkeep/open-knowledge@latest mcp
done
echo "Open Knowledge: install OK Desktop or Node.js 24+, then restart your editor" >&2
exit 127`]}}function D(e){return e===`win32`?v:m}function O(e={}){let t=e.platformName??process.platform,n=e.home??y();return D(t).join(n,`.claude.json`)}function k(e={}){let t=e.platformName??process.platform,n=e.home??y(),r=e.env??process.env;if(t===`darwin`)return m.join(n,`Library`,`Application Support`,`Claude`,`claude_desktop_config.json`);if(t===`win32`){let e=r.APPDATA??v.join(n,`AppData`,`Roaming`);return v.join(e,`Claude`,`claude_desktop_config.json`)}throw Error(`Claude Desktop is not available on ${t}. Supported: macOS, Windows.`)}function A(e={}){let t=e.platformName??process.platform,n=e.home??y();return D(t).join(n,`.cursor`,`mcp.json`)}function j(e={}){let t=e.platformName??process.platform,n=e.home??y();return(e.env??process.env).CODEX_HOME??D(t).join(n,`.codex`)}function M(e={}){return D(e.platformName??process.platform).join(j(e),`config.toml`)}const N={claude:{id:`claude`,label:x.claude,configPath:(e,t)=>O({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>n,buildEntry:(e,t)=>E(t),scope:`global`,detectPath:(e,t)=>p(t??y(),`.claude`),projectConfigPath:e=>p(e,`.mcp.json`),projectSkillPath:e=>p(e,`.claude`,`skills`,`open-knowledge`,`SKILL.md`)},"claude-desktop":{id:`claude-desktop`,label:x[`claude-desktop`],configPath:(e,t)=>k({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>n,buildEntry:(e,t)=>E(t),scope:`global`,detectPath:(e,t)=>d(k({home:t}))},cursor:{id:`cursor`,label:x.cursor,configPath:(e,t)=>A({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>n,buildEntry:(e,t)=>E(t),scope:`global`,detectPath:(e,t)=>d(A({home:t})),projectConfigPath:e=>p(e,`.cursor`,`mcp.json`),projectSkillPath:e=>p(e,`.cursor`,`skills`,`open-knowledge`,`SKILL.md`)},codex:{id:`codex`,label:x.codex,configPath:(e,t)=>M({home:t}),format:`toml`,topLevelKey:`mcp_servers`,serverName:()=>n,buildEntry:(e,t)=>E(t),scope:`global`,detectPath:(e,t)=>d(M({home:t})),projectConfigPath:e=>p(e,`.codex`,`config.toml`),projectSkillPath:e=>p(e,`.agents`,`skills`,`open-knowledge`,`SKILL.md`)}};function P(e){let t=e.filter(e=>!Object.hasOwn(N,e));if(t.length>0)throw Error(`Unknown editor(s): ${t.join(`, `)}. Valid options: ${b.join(`, `)}`);return e.map(e=>N[e])}function F(e,t){let n;try{n=c(t)}catch{n=g(t)}let r;try{r=o(e)}catch(e){if(e.code!==`ENOENT`)throw e}if(r?.isSymbolicLink())throw Error(`Refusing to write through a symbolic link at ${e}. Remove the symlink and re-run project setup.`);let i=d(e);for(;i.length>1&&i!==_;){let t;try{t=c(i)}catch(e){if(e.code===`ENOENT`){i=d(i);continue}throw e}let r=h(n,t);if(r===``||!r.startsWith(`..`)&&!f(r))return;throw Error(`Refusing to write at ${e}: ancestor ${i} resolves to ${t}, which is outside the project directory ${n}. A symbolic link in the path likely escapes the project. Remove the symlink and re-run project setup.`)}}function I(e,t){let n=e.projectSkillPath?.(t);if(!n)return{editorId:e.id,label:e.label,action:`skipped-unsupported`,path:``};try{let o=r(`project`,{checkDesktop:!0}),c=d(n);F(c,t);let u=a(n)?`overwritten`:`written`;return l(c,{recursive:!0,force:!0}),s(d(c),{recursive:!0}),i(o,c,{recursive:!0}),{editorId:e.id,label:e.label,action:u,path:n}}catch(t){return{editorId:e.id,label:e.label,action:`failed`,path:n,error:t instanceof Error?t.message:String(t)}}}export{x as a,w as c,C as i,T as l,I as n,N as o,b as r,E as s,F as t,P as u};
//# sourceMappingURL=write-project-skill-CdqDqhyf.mjs.map