@inkeep/open-knowledge 0.9.2-beta.8 → 0.9.2-beta.9

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.
@@ -3,7 +3,7 @@ name: open-knowledge-discovery
3
3
  description: "Read when the user asks what Open Knowledge is, wants to install it on a repository, wants to share an Open Knowledge project with collaborators, or asks how `ok init` / `ok install-skill` / OK Desktop set up a project. Do NOT load to perform Open Knowledge reads/writes — the runtime guidance for editing markdown inside an initialized OK project ships as a separate project-local skill at `.claude/skills/open-knowledge/` whenever `ok init` runs. If the user appears to be editing markdown inside a `.ok/` project and this is the only OK skill loaded, advise them to re-run `ok init` to install the project-local skill."
4
4
  compatibility: "Any agent host — no MCP server required. Pure discovery + install guidance."
5
5
  metadata:
6
- version: "0.9.2-beta.8"
6
+ version: "0.9.2-beta.9"
7
7
  author: "Inkeep"
8
8
  repository: "https://github.com/inkeep/open-knowledge"
9
9
  ---
@@ -3,7 +3,7 @@ name: open-knowledge
3
3
  description: "MUST invoke before reading or editing any `.md` / `.mdx` file, and before any `mcp__open-knowledge__*` tool call (`exec`, `search`, `write_document`, `edit_document`, and the rest). This skill is installed into the repository by `ok init`, so its presence alone means this is an Open Knowledge project — its runtime contract governs every markdown file here, with no need to probe for a `.ok/` directory. Authoritative agent-runtime contract; supersedes the overlapping MCP server `instructions` echo."
4
4
  compatibility: "Claude Code, Claude Desktop, Claude Cowork, Claude.ai web. Requires Open Knowledge MCP server + code execution."
5
5
  metadata:
6
- version: "0.9.2-beta.8"
6
+ version: "0.9.2-beta.9"
7
7
  author: "Inkeep"
8
8
  repository: "https://github.com/inkeep/open-knowledge"
9
9
  ---
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{o as e}from"./chunk-FK9Q3tQk.mjs";import{t}from"./esm-CEs3LWY3.mjs";import{Br as n,Gi as r,Hi as i,Ii as a,Li as o,Mi as s,Qi as c,Ri as l,Ui as u,Wi as d,Yi as f,bi as p,bn as m,f as h,ga as g,ha as _,n as v,s as y,ta as b,vr as x,wi as S,yi as ee}from"./server-lock-BpjJj3OD-2pOoEhSP.mjs";import{a as te,n as C,r as ne,t as re}from"./gh-detect-BveVRAue.mjs";import{n as ie,r as ae,t as w}from"./dist-bundle-BK4P1EQn.mjs";import{B as oe,C as se,E as ce,F as le,H as ue,I as de,L as fe,M as pe,N as me,P as he,R as ge,S as _e,T as ve,V as ye,b as be,u as xe,v as Se,w as Ce,z as we}from"./init-BjjtQpJ4.mjs";import{r as Te}from"./git-handle-BSAUg1L_-CUJRlGhd.mjs";import{A as Ee,Ai as De,Ci as Oe,Di as ke,Ei as Ae,Ii as je,In as Me,J as Ne,Mi as Pe,Ni as Fe,Pi as Ie,Qt as Le,Rr as Re,Rt as ze,Si as Be,Sn as Ve,Sr as He,Ti as Ue,Tn as We,Tr as Ge,Z as Ke,Zt as qe,_t as Je,b as Ye,dn as Xe,er as Ze,h as Qe,j as $e,mt as et,pr as tt,q as nt,st as rt,ut as it,wi as at,x as ot,yr as st}from"./dist-sld-_d9T.mjs";import{t as ct}from"./yazl-DjRp4wSy.mjs";import{a as lt,c as ut,f as dt,i as ft,o as pt,p as mt,s as ht}from"./src-B1QW6YWQ.mjs";import{n as gt,t as _t}from"./constants-Dz5iTLUD.mjs";import{n as vt,t as yt}from"./loader-BSyhsuGY.mjs";import{_ as bt,b as xt,f as St,h as Ct,v as wt,y as Tt}from"./start-7bpluiOA.mjs";import{c as Et,i as T,n as E,o as D,r as Dt,s as O,t as k}from"./colors-BtKMHmBX.mjs";import{n as Ot}from"./repair-skills-BP58ginR.mjs";import{execSync as kt,spawn as A,spawnSync as j}from"node:child_process";import At,{basename as M,dirname as jt,join as N,relative as Mt,resolve as P,sep as Nt}from"node:path";import{accessSync as Pt,closeSync as Ft,constants as It,cpSync as Lt,createWriteStream as Rt,existsSync as F,mkdirSync as I,mkdtempSync as zt,openSync as Bt,readFileSync as L,readdirSync as Vt,realpathSync as Ht,rmSync as Ut,statSync as Wt,unlinkSync as Gt,writeFileSync as R}from"node:fs";import Kt from"node:process";import{arch as qt,freemem as Jt,homedir as Yt,platform as Xt,release as Zt,tmpdir as Qt,totalmem as $t,type as en,uptime as tn}from"node:os";import{fileURLToPath as nn}from"node:url";import{AsyncLocalStorage as rn,AsyncResource as an}from"node:async_hooks";import{stripVTControlCharacters as on,styleText as z}from"node:util";import*as sn from"node:readline";import{createHash as cn,randomUUID as ln}from"node:crypto";import{setTimeout as un}from"node:timers/promises";import{createInterface as dn}from"node:readline/promises";async function fn(e,t,n){let r=pn(await mn(e)).host??``;if(!r)return 1;let i=await n.get(r);if(i==null)return 1;let a=e=>e.replace(/[\r\n]/g,``);return t.write(`username=${a(i.login)}\npassword=${a(i.token)}\n`),0}function pn(e){let t={};for(let n of e.split(`
2
+ import{o as e}from"./chunk-FK9Q3tQk.mjs";import{t}from"./esm-CEs3LWY3.mjs";import{Br as n,Gi as r,Hi as i,Ii as a,Li as o,Mi as s,Qi as c,Ri as l,Ui as u,Wi as d,Yi as f,bi as p,bn as m,f as h,ga as g,ha as _,n as v,s as y,ta as b,vr as x,wi as S,yi as ee}from"./server-lock-BpjJj3OD-2pOoEhSP.mjs";import{a as te,n as C,r as ne,t as re}from"./gh-detect-BveVRAue.mjs";import{n as ie,r as ae,t as w}from"./dist-bundle-BK4P1EQn.mjs";import{B as oe,C as se,E as ce,F as le,H as ue,I as de,L as fe,M as pe,N as me,P as he,R as ge,S as _e,T as ve,V as ye,b as be,u as xe,v as Se,w as Ce,z as we}from"./init-Ctu92Awt.mjs";import{r as Te}from"./git-handle-BSAUg1L_-CUJRlGhd.mjs";import{A as Ee,Ai as De,Ci as Oe,Di as ke,Ei as Ae,Ii as je,In as Me,J as Ne,Mi as Pe,Ni as Fe,Pi as Ie,Qt as Le,Rr as Re,Rt as ze,Si as Be,Sn as Ve,Sr as He,Ti as Ue,Tn as We,Tr as Ge,Z as Ke,Zt as qe,_t as Je,b as Ye,dn as Xe,er as Ze,h as Qe,j as $e,mt as et,pr as tt,q as nt,st as rt,ut as it,wi as at,x as ot,yr as st}from"./dist-sld-_d9T.mjs";import{t as ct}from"./yazl-DjRp4wSy.mjs";import{a as lt,c as ut,f as dt,i as ft,o as pt,p as mt,s as ht}from"./src-jN1tBoyd.mjs";import{n as gt,t as _t}from"./constants-DU4TbLA_.mjs";import{n as vt,t as yt}from"./loader-DLF6I7F7.mjs";import{_ as bt,b as xt,f as St,h as Ct,v as wt,y as Tt}from"./start-D474Z7JL.mjs";import{c as Et,i as T,n as E,o as D,r as Dt,s as O,t as k}from"./colors-BtKMHmBX.mjs";import{n as Ot}from"./repair-skills-BP58ginR.mjs";import{execSync as kt,spawn as A,spawnSync as j}from"node:child_process";import At,{basename as M,dirname as jt,join as N,relative as Mt,resolve as P,sep as Nt}from"node:path";import{accessSync as Pt,closeSync as Ft,constants as It,cpSync as Lt,createWriteStream as Rt,existsSync as F,mkdirSync as I,mkdtempSync as zt,openSync as Bt,readFileSync as L,readdirSync as Vt,realpathSync as Ht,rmSync as Ut,statSync as Wt,unlinkSync as Gt,writeFileSync as R}from"node:fs";import Kt from"node:process";import{arch as qt,freemem as Jt,homedir as Yt,platform as Xt,release as Zt,tmpdir as Qt,totalmem as $t,type as en,uptime as tn}from"node:os";import{fileURLToPath as nn}from"node:url";import{AsyncLocalStorage as rn,AsyncResource as an}from"node:async_hooks";import{stripVTControlCharacters as on,styleText as z}from"node:util";import*as sn from"node:readline";import{createHash as cn,randomUUID as ln}from"node:crypto";import{setTimeout as un}from"node:timers/promises";import{createInterface as dn}from"node:readline/promises";async function fn(e,t,n){let r=pn(await mn(e)).host??``;if(!r)return 1;let i=await n.get(r);if(i==null)return 1;let a=e=>e.replace(/[\r\n]/g,``);return t.write(`username=${a(i.login)}\npassword=${a(i.token)}\n`),0}function pn(e){let t={};for(let n of e.split(`
3
3
  `)){let e=n.trim();if(e===``)continue;let r=e.indexOf(`=`);r!==-1&&(t[e.slice(0,r)]=e.slice(r+1))}return t}function mn(e){return new Promise((t,n)=>{let r=[];e.on(`data`,e=>r.push(e)),e.on(`end`,()=>t(Buffer.concat(r).toString(`utf-8`))),e.on(`error`,n)})}function hn(e){let n=new t(`git-credential`);return n.description(`Git credential helper (git credential-helper protocol)`),n.command(`get`).description(`Lookup credentials from TokenStore (called by git)`).action(async()=>{let t=await e(),n=await fn(process.stdin,process.stdout,t);process.exit(n)}),n}function gn(e){let t=e.endpoint.DEFAULTS;return/^https:\/\/(api\.)?github\.com$/.test(t.baseUrl)?`https://github.com`:t.baseUrl.replace(`/api/v3`,``)}async function _n(e,t,n){let r={baseUrl:gn(e),headers:{accept:`application/json`},...n},i=await e(t,r);if(`error`in i.data){let n=new ie(`${i.data.error_description} (${i.data.error}, ${i.data.error_uri})`,400,{request:e.endpoint.merge(t,r)});throw n.response=i,n}return i}async function vn(e){let t=e.request||w,n={client_id:e.clientId};return`scopes`in e&&Array.isArray(e.scopes)&&(n.scope=e.scopes.join(` `)),_n(t,`POST /login/device/code`,n)}async function yn(e){let t=await _n(e.request||w,`POST /login/oauth/access_token`,{client_id:e.clientId,device_code:e.code,grant_type:`urn:ietf:params:oauth:grant-type:device_code`}),n={clientType:e.clientType,clientId:e.clientId,token:t.data.access_token,scopes:t.data.scope.split(/\s+/).filter(Boolean)};if(`clientSecret`in e&&(n.clientSecret=e.clientSecret),e.clientType===`github-app`){if(`refresh_token`in t.data){let e=new Date(t.headers.date).getTime();n.refreshToken=t.data.refresh_token,n.expiresAt=bn(e,t.data.expires_in),n.refreshTokenExpiresAt=bn(e,t.data.refresh_token_expires_in)}delete n.scopes}return{...t,authentication:n}}function bn(e,t){return new Date(e+t*1e3).toISOString()}async function xn(e,t){let n=Sn(e,t.auth);if(n)return n;let{data:r}=await vn({clientType:e.clientType,clientId:e.clientId,request:t.request||e.request,scopes:t.auth.scopes||e.scopes});await e.onVerification(r);let i=await wn(t.request||e.request,e.clientId,e.clientType,r);return e.authentication=i,i}function Sn(e,t){if(t.refresh===!0||!e.authentication)return!1;if(e.clientType===`github-app`)return e.authentication;let n=e.authentication;return(`scopes`in t&&t.scopes||e.scopes).join(` `)===n.scopes.join(` `)?n:!1}async function Cn(e){await new Promise(t=>setTimeout(t,e*1e3))}async function wn(e,t,n,r){try{let i={clientId:t,request:e,code:r.device_code},{authentication:a}=n===`oauth-app`?await yn({...i,clientType:`oauth-app`}):await yn({...i,clientType:`github-app`});return{type:`token`,tokenType:`oauth`,...a}}catch(i){if(!i.response)throw i;let a=i.response.data.error;if(a===`authorization_pending`)return await Cn(r.interval),wn(e,t,n,r);if(a===`slow_down`)return await Cn(r.interval+7),wn(e,t,n,r);throw i}}async function Tn(e,t){return xn(e,{auth:t})}async function En(e,t,n,r){let i=t.endpoint.merge(n,r);if(/\/login\/(oauth\/access_token|device\/code)$/.test(i.url))return t(i);let{token:a}=await xn(e,{request:t,auth:{type:`oauth`}});return i.headers.authorization=`token ${a}`,t(i)}var Dn=`0.0.0-development`;function On(e){let t=e.request||w.defaults({headers:{"user-agent":`octokit-auth-oauth-device.js/${Dn} ${ae()}`}}),{request:n=t,...r}=e,i=e.clientType===`github-app`?{...r,clientType:`github-app`,request:n}:{...r,clientType:`oauth-app`,request:n,scopes:e.scopes||[]};if(!e.clientId)throw Error(`[@octokit/auth-oauth-device] "clientId" option must be set (https://github.com/octokit/auth-oauth-device.js#usage)`);if(!e.onVerification)throw Error(`[@octokit/auth-oauth-device] "onVerification" option must be a function (https://github.com/octokit/auth-oauth-device.js#usage)`);return Object.assign(Tn.bind(null,i),{hook:En.bind(null,i)})}async function kn(e){let{clientId:t,scopes:n=[`repo`,`read:user`,`user:email`],onVerification:r,host:i}=e,a=i&&i!==`github.com`?`https://${i}/api/v3`:`https://api.github.com`,o=On({clientType:`oauth-app`,clientId:t,scopes:n,onVerification:async e=>{await r({verificationUri:e.verification_uri,userCode:e.user_code,expiresIn:e.expires_in,interval:e.interval})},request:a===`https://api.github.com`?void 0:(await import(`./dist-bundle-CjV1Pdeo.mjs`)).request.defaults({baseUrl:a})}),s;try{s=await o({type:`oauth`})}catch(e){if(e instanceof Error){let t=e.message.toLowerCase();throw t.includes(`access_denied`)?Error(`Device-flow authorization was denied.`):t.includes(`expired_token`)||t.includes(`timeout`)||t.includes(`timed out`)?Error(`Device-flow code expired before authorization — please try again.`):Error(`GitHub sign-in failed: ${e.message}`)}throw e}return{token:s.token,tokenType:s.tokenType,scopes:s.scopes??[]}}const An={invalid_type:`invalid_type`,too_big:`too_big`,too_small:`too_small`,invalid_format:`invalid_format`,not_multiple_of:`not_multiple_of`,unrecognized_keys:`unrecognized_keys`,invalid_union:`invalid_union`,invalid_key:`invalid_key`,invalid_element:`invalid_element`,invalid_value:`invalid_value`,custom:`custom`};var jn;(function(e){})(jn||={});function Mn(e){return b(s,e)}function Nn(){return process.env.OPEN_KNOWLEDGE_GITHUB_CLIENT_ID??`Ov23liqlSd0V1MwR6rhI`}const Pn=new Set([`gitlab.com`,`bitbucket.org`,`codeberg.org`,`gitea.com`,`sr.ht`,`sourcehut.org`]);function B(e){let t=e.toLowerCase().replace(/:\d+$/,``);Pn.has(t)&&(process.stderr.write(`Error: ${e} is not a GitHub host. Only GitHub and GitHub Enterprise Server are supported.\n`),process.exit(1))}function Fn(e,t){e&&process.stdout.write(`${JSON.stringify(t)}\n`)}async function In(e,t,n=kn){let r=Nn(),{host:i,json:a}=e;B(i),a||process.stderr.write(`Logging in to ${i}\n`);let o=await n({clientId:r,host:i===`github.com`?void 0:i,onVerification:e=>{e.userCode,e.verificationUri,a?Fn(!0,{type:`verification`,user_code:e.userCode,verification_uri:e.verificationUri,expires_in:e.expiresIn}):process.stderr.write(`Open: ${e.verificationUri}\nEnter code: ${e.userCode}\n`)}}),s=`unknown`,c,l;try{let e=i===`github.com`?`https://api.github.com`:`https://${i}/api/v3`,t=await fetch(`${e}/user`,{headers:{Authorization:`Bearer ${o.token}`,"User-Agent":`open-knowledge-cli`,Accept:`application/vnd.github+json`}});if(t.ok){let e=await t.json();s=e.login??s,c=e.name??void 0,l=e.email??void 0}}catch{}await t.set(i,s,o.token,{gitProtocol:`https`,name:c,email:l}),a?Fn(!0,{type:`complete`,host:i,login:s}):process.stderr.write(`✓ Logged in as ${s} on ${i}\n`)}function Ln(e){return new t(`login`).description(`Authenticate with GitHub via Device Flow`).option(`--host <host>`,`GitHub or GitHub Enterprise hostname`,`github.com`).option(`--json`,`Output JSONL progress events`,!1).action(async t=>{await In(t,await e())})}const Rn=e=>e.name===`enter`||e.name===`return`;var zn=class extends Error{name=`AbortPromptError`;message=`Prompt was aborted`;constructor(e){super(),this.cause=e?.cause}},Bn=class extends Error{name=`CancelPromptError`;message=`Prompt was canceled`},Vn=class extends Error{name=`ExitPromptError`},Hn=class extends Error{name=`HookError`},Un=class extends Error{name=`ValidationError`};const Wn=new rn;function Gn(e){return{rl:e,hooks:[],hooksCleanup:[],hooksEffect:[],index:0,handleChange(){}}}function Kn(e,t){let n=Gn(e);return Wn.run(n,()=>{function e(e){n.handleChange=()=>{n.index=0,e()},n.handleChange()}return t(e)})}function V(){let e=Wn.getStore();if(!e)throw new Hn(`[Inquirer] Hook functions can only be called from within a prompt`);return e}function qn(){return V().rl}function Jn(e){return an.bind((...t)=>{let n=V(),r=!1,i=n.handleChange;n.handleChange=()=>{r=!0};let a=e(...t);return r&&i(),n.handleChange=i,a})}function Yn(e){let t=V(),{index:n}=t,r=e({get(){return t.hooks[n]},set(e){t.hooks[n]=e},initialized:n in t.hooks});return t.index++,r}function Xn(){V().handleChange()}const Zn={queue(e){let t=V(),{index:n}=t;t.hooksEffect.push(()=>{t.hooksCleanup[n]?.();let r=e(qn());if(r!=null&&typeof r!=`function`)throw new Un(`useEffect return value must be a cleanup function or nothing.`);t.hooksCleanup[n]=r})},run(){let e=V();Jn(()=>{e.hooksEffect.forEach(e=>{e()}),e.hooksEffect.length=0})()},clearAll(){let e=V();e.hooksCleanup.forEach(e=>{e?.()}),e.hooksEffect.length=0,e.hooksCleanup.length=0}};function Qn(e){return typeof e==`function`}function H(e){return Yn(t=>{let n=an.bind(function(e){t.get()!==e&&(t.set(e),Xn())});if(t.initialized)return[t.get(),n];let r=Qn(e)?e():e;return t.set(r),[r,n]})}function $n(e,t){Yn(n=>{let r=n.get();(!Array.isArray(r)||t.some((e,t)=>!Object.is(e,r[t])))&&Zn.queue(e),n.set(t)})}const er={prefix:{idle:z(`blue`,`?`),done:z(`green`,ue.tick)},spinner:{interval:80,frames:[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`].map(e=>z(`yellow`,e))},style:{answer:e=>z(`cyan`,e),message:e=>z(`bold`,e),error:e=>z(`red`,`> ${e}`),defaultAnswer:e=>z(`dim`,`(${e})`),help:e=>z(`dim`,e),highlight:e=>z(`cyan`,e),key:e=>z(`cyan`,z(`bold`,`<${e}>`))}};function tr(e){if(typeof e!=`object`||!e)return!1;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function nr(...e){let t={};for(let n of e)for(let[e,r]of Object.entries(n)){let n=t[e];t[e]=tr(n)&&tr(r)?nr(n,r):r}return t}function rr(...e){return nr(er,...e.filter(e=>e!=null))}function ir({status:e=`idle`,theme:t}){let[n,r]=H(!1),[i,a]=H(0),{prefix:o,spinner:s}=rr(t);return $n(()=>{if(e===`loading`){let e,t=-1,n=setTimeout(()=>{r(!0),e=setInterval(()=>{t+=1,a(t%s.frames.length)},s.interval)},300);return()=>{clearTimeout(n),clearInterval(e)}}else r(!1)},[e]),n?s.frames[i]:typeof o==`string`?o:o[e===`loading`?`idle`:e]??o.idle}function ar(e){return H({current:e})[0]}function or(e){let t=ar(e);t.current=e,$n(e=>{let n=!1,r=Jn((r,i)=>{n||t.current(i,e)});return e.input.on(`keypress`,r),()=>{n=!0,e.input.removeListener(`keypress`,r)}},[])}var sr=e(ye(),1);function cr(e,t){return e.split(`
4
4
  `).flatMap(e=>oe(e,t,{trim:!1,hard:!0}).split(`
5
5
  `).map(e=>e.trimEnd())).join(`
@@ -20,7 +20,7 @@ import{o as e}from"./chunk-FK9Q3tQk.mjs";import{t}from"./esm-CEs3LWY3.mjs";impor
20
20
  `),patterns:[...t],lineCount:n}}const Di=N(Yt(),`.ok`,`logs`),Oi=N(Yt(),`.ok`,`bug-reports`);function ki(e){let t=N(e,`.ok`,`config.yml`);if(F(t))try{let e=L(t,`utf8`).match(/^\s*name:\s*['"]?(.+?)['"]?\s*$/m);if(e?.[1])return e[1]}catch{}return F(N(e,`.ok`))?cn(`sha256`).update(P(e)).digest(`hex`).slice(0,12):null}function Ai(){let e={timestamp:new Date().toISOString(),platform:Xt(),osType:en(),osRelease:Zt(),hostname:`[redacted]`,uptime:tn(),freeMem:Jt(),totalMem:$t(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=kt(`sw_vers -productVersion 2>/dev/null`,{encoding:`utf8`}).trim()}catch{}try{let t=N(__dirname,`..`,`..`,`package.json`);F(t)&&(e.okVersion=JSON.parse(L(t,`utf8`)).version)}catch{}return e}function ji(e){if(!F(Di))return{files:[],dir:Di};let t=Vt(Di).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>N(Di,e));if(e&&t.length>0){let n=t.filter(t=>{try{return L(t,`utf8`).includes(`"project":"${e}"`)}catch{return!0}});n.length>0&&(t=n)}return{files:t,dir:Di}}function Mi(e){let t=N(e,`.ok`,`local`);return F(t)?{files:[`server.lock`,`last-spawn-error.log`].map(e=>N(t,e)).filter(e=>F(e)),dir:t}:{files:[],dir:null}}function Ni(e){let t=N(e,`.ok`,`local`,`logs`);return F(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>N(t,e)).filter(e=>F(e)),dir:t}:{files:[],dir:null}}async function Pi(t){let n=Rl();I(Oi,{recursive:!0});let r=N(Oi,`${new Date().toISOString().replace(/[:.]/g,`-`)}-bugreport.zip`);n?.info({projectSlug:t.projectSlug},`gathering diagnostic data`);let i=Ai(),{files:a}=ji(t.projectSlug),{files:o}=Mi(t.cwd),{files:s}=Ni(t.cwd);n?.info({logFileCount:a.length,lockFileCount:o.length,localSinkFileCount:s.length},`files collected`);let c=[],l=[],{ZipFile:u}=await import(`./yazl-CJayzk0b.mjs`).then(t=>e(t.default,1)),d=new u;for(let e of a)try{let{redacted:t,patterns:n,lineCount:r}=Ei(L(e,`utf8`)),i=`logs/${M(e)}`;d.addBuffer(Buffer.from(t,`utf8`),i),l.push(i),n.length>0&&c.push({file:i,lineCount:r,patterns:n})}catch{}for(let e of o)try{let{redacted:t,patterns:n,lineCount:r}=Ei(L(e,`utf8`)),i=`lockdir/${M(e)}`;d.addBuffer(Buffer.from(t,`utf8`),i),l.push(i),n.length>0&&c.push({file:i,lineCount:r,patterns:n})}catch{}for(let e of s)try{let{redacted:t,patterns:n,lineCount:r}=Ei(L(e,`utf8`)),i=`local-logs/${M(e)}`;d.addBuffer(Buffer.from(t,`utf8`),i),l.push(i),n.length>0&&c.push({file:i,lineCount:r,patterns:n})}catch{}let f=JSON.stringify(i,null,2);d.addBuffer(Buffer.from(f,`utf8`),`sysinfo.json`),l.push(`sysinfo.json`);let p={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:t.projectSlug,files:l,redactions:c,sysinfo:i};d.addBuffer(Buffer.from(JSON.stringify(p,null,2),`utf8`),`MANIFEST.json`);let m=c.reduce((e,t)=>e+t.lineCount,0),h=[`# Bug Report Bundle`,``,`Generated: ${p.generatedAt}`,`Project: ${t.projectSlug??`(unscoped)`}`,`Discipline version: ${p.disciplineVersion}`,``,`## Contents`,``,...l.map(e=>`- ${e}`),``,`## Privacy`,``,`This bundle was auto-redacted before packaging.`,`Patterns checked: ${Ti.join(`, `)}`,m>0?`${m} line(s) were scrubbed across ${c.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,``,`This bundle is safe to attach to a GitHub issue.`].join(`
21
21
  `);d.addBuffer(Buffer.from(h,`utf8`),`README.md`),d.end();let g=Rt(r);if(d.outputStream.pipe(g),await new Promise((e,t)=>{g.on(`close`,e),g.on(`error`,t)}),n?.info({bundlePath:r,fileCount:l.length,redactionCount:m},`bundle written`),process.stdout.write(`${r}\n`),m>0&&process.stderr.write(`ok bug-report: ${m} line(s) auto-redacted across ${c.length} file(s)\n`),!t.noReveal&&Xt()===`darwin`)try{A(`/usr/bin/open`,[`-R`,r],{detached:!0,stdio:`ignore`}).unref()}catch{}return r}function Fi(){return new t(`bug-report`).description(`Generate a diagnostic bundle for bug reporting`).option(`--reveal`,`Reveal the bundle in Finder (default: true)`,!0).option(`--no-reveal`,`Do not reveal the bundle in Finder`).action(async e=>{let t=process.cwd(),n=ki(t);try{await Pi({projectSlug:n,cwd:t,noReveal:!e.reveal})}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`ok bug-report: failed — ${t}\n`),process.exitCode=1}})}function Ii(e,t){let n=[];for(let[r,i]of[[`server`,e],[`ui`,t]])(i.status===`dead-pid`||i.status===`corrupt`)&&n.push({name:r,lockPath:i.lockPath,reason:i.status});return{prune:n}}function Li(e){let t=e.inspect??(t=>mt(e.lockDir,t)),n=e.unlink??(e=>Gt(e)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=Ii(t(`server`),t(`ui`));if(a.prune.length===0)return r(`No stale locks.`),{pruned:[],failed:[]};let o=[],s=[];for(let e of a.prune)try{n(e.lockPath),o.push(e)}catch(t){s.push({target:e,error:t instanceof Error?t.message:String(t)})}if(o.length>0){let e=o.map(e=>`${e.name} (${e.reason})`).join(`, `);r(`Pruned ${o.length} stale lock${o.length===1?``:`s`}: ${e}`)}return s.length>0&&i(`Failed to prune: ${s.map(({target:e,error:t})=>`${e.name} (${e.lockPath}): ${t}`).join(`; `)}`),{pruned:o,failed:s}}function Ri(e){return new t(`clean`).description(`Prune stale / corrupt open-knowledge lock files (never touches live locks)`).action(()=>{e(),Li({lockDir:He(process.cwd())}).failed.length>0&&(process.exitCode=1)})}async function zi(e,t,n={},r=re){if(!n.skipGhDetect&&r().available)return{tier:`A`,credentialArgs:[`-c`,`credential.helper=!gh auth git-credential`]};let i=await t.get(e);return i==null?{tier:`none`,credentialArgs:[]}:{tier:i.gitProtocol===`ssh`?`C`:`B`,credentialArgs:[`-c`,`credential.helper=!open-knowledge auth git-credential`]}}async function Bi(e,t,n=fetch){let r=new AbortController,i=setTimeout(()=>r.abort(),5e3);try{return(await n(`https://api.github.com/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{signal:r.signal,headers:{"User-Agent":`open-knowledge-cli`,Accept:`application/vnd.github+json`}})).status===200}catch{return!1}finally{clearTimeout(i)}}const Vi=[[`count`,0,10],[`compress`,10,20],[`receiv`,20,60],[`resolv`,60,100]];function Hi(e){let t=/^([\w ]+):\s+(\d+)%/.exec(e.trim());if(!t)return null;let n=t[1].toLowerCase(),r=Number(t[2]);for(let[e,i,a]of Vi)if(n.includes(e))return{stage:t[1],pct:Math.round(i+r/100*(a-i))};return null}function G(e,t){e&&process.stdout.write(`${JSON.stringify(t)}\n`)}function Ui(e){return typeof e!=`string`||e.length===0?[`--progress`]:[`--progress`,`-b`,e]}const Wi=n;async function Gi(e){try{return await e.clone(Ui(e.branch)),{fellBack:!1}}catch(t){if(e.branch!==null&&Wi(t))return e.onFallback(e.branch),await e.clone(Ui(null)),{fellBack:!0};throw t}}function Ki(e,t,n){return e===`https`&&t===`github.com`&&n}async function qi(e,t,n,r=process.cwd()){let i=dt(e);if(!i)throw Error(`Invalid git URL: ${e}`);let a=t.dir?P(r,t.dir):P(r,i.name);if(F(a)&&Vt(a).length>0)throw Error(`Target directory is not empty: ${a}`);let o=te(),s=i.protocol===`https`&&i.hostname===`github.com`?await Bi(i.owner,i.name):!1,c=Ki(i.protocol,i.hostname,s)?{tier:`none`,credentialArgs:[]}:await zi(i.hostname,o,{}),l=Te({baseDir:r,config:c.credentialArgs.length>=2?[c.credentialArgs[1]]:[],unsafe:{allowUnsafeCredentialHelper:!0}}).env({GIT_TERMINAL_PROMPT:`0`}),u=-1;l.outputHandler((e,n,r)=>{r.on(`data`,e=>{let n=e.toString(`utf-8`);for(let e of n.split(`
22
22
  `)){let n=Hi(e);n&&n.pct!==u&&(u=n.pct,G(t.json,{type:`progress`,pct:n.pct,stage:n.stage}),t.json||process.stderr.write(`\r Cloning ${n.pct}%`))}})}),await Gi({branch:typeof t.branch==`string`&&t.branch.length>0?t.branch:null,clone:t=>l.clone(e,a,t),onFallback:e=>{G(t.json,{type:`branch-fallback`,branch:e}),t.json||process.stderr.write(`\n Branch '${e}' not found upstream — cloning default branch instead.\n`)}}),t.json||process.stderr.write(`
23
- `);try{let{runInit:e}=await import(`./init-CxAAKK9q.mjs`),n=await e({cwd:a,mcp:!1});if(n.contentUpdated.length>0){let e=`auto-init: updated ${n.contentUpdated.join(`, `)}`;t.json?G(!0,{type:`warning`,message:e}):process.stderr.write(` ${e}\n`)}}catch(e){let n=e instanceof Error?e.message:String(e);t.json?G(!0,{type:`warning`,message:`auto-init: ${n}`}):process.stderr.write(` auto-init: ${n}\n`)}try{Ji(a)}catch(e){let n=e instanceof Error?e.message:String(e);t.json?G(!0,{type:`warning`,message:`git-exclude: ${n}`}):process.stderr.write(` git-exclude: ${n}\n`)}return a}function Ji(e){let t=be(e,[`.ok/`]);return t.kind===`no-exclude`?`no-exclude`:t.kind===`refused-tracked`?`already-present`:t.appended.length>0?`appended`:`already-present`}function Yi(e){return new t(`clone`).description(`Clone a git repository and open it`).argument(`<url>`,`Repository URL or owner/repo shorthand`).argument(`[dir]`,`Target directory (default: ./<repo-name>)`).option(`--json`,`Output JSONL progress events`,!1).option(`-b, --branch <branch>`,`Branch to check out (falls back to default if missing)`).action(async(t,n,r)=>{let i=e();try{let a=await qi(t,{json:r.json,dir:n,branch:r.branch??null},i);if(r.json)G(!0,{type:`complete`,dir:a});else{process.stderr.write(`✓ Cloned to ${a}\n`),process.chdir(a);let{startCommand:t}=await import(`./start-BjSIXm8g.mjs`);await t(e).parseAsync([],{from:`user`})}}catch(e){let t=e instanceof Error?e.message:String(e);r.json?G(!0,{type:`error`,message:t}):process.stderr.write(`✗ ${t}\n`),process.exitCode=1}})}var Xi=g();const Zi=[[`sync`],[`persistence`,`debounceMs`],[`persistence`,`maxDebounceMs`],[`server`,`port`],...p.map(e=>e.path)];function Qi(e={}){let t=e.log??(e=>console.error(e)),n=e.error??(e=>console.error(e)),r=e.loadConfigFn??vt;try{let{sources:n}=r(e.cwd);return t(`✓ Configuration valid (sources: ${n.length===0?`defaults only`:n.join(`, `)})`),{ok:!0}}catch(e){return n(e instanceof Error?e.message:String(e)),{ok:!1}}}function $i(e){let t=(0,Xi.parseDocument)(L(e,`utf-8`));if(t.errors.length>0)throw Error(`Could not parse ${e}: ${t.errors.map(e=>e.message).join(`; `)}`);let n=[];for(let e of Zi)t.hasIn(e)&&n.push(e.join(`.`));return n}function ea(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ta(e){let t={};for(let n of e){let e=t;for(let t=0;t<n.length-1;t++){let r=n[t],i=e[r],a=ea(i)?i:{};e[r]=a,e=a}e[n[n.length-1]]=null}return t}async function na(e={}){let t=e.log??(e=>console.log(e)),n=e.error??(e=>console.error(e)),r=e.scope??`both`,i=e.dryRun??!1,a=e.cwd??process.cwd(),o=e.writeConfigPatchFn??Pe,s=[];(r===`project`||r===`both`)&&s.push({scope:`project`,absPath:De(`project`,a,e.homedirOverride)}),(r===`user`||r===`both`)&&s.push({scope:`user`,absPath:De(`user`,a,e.homedirOverride)});let c=[],l=!0;for(let{scope:t,absPath:n}of s){if(!F(n)){c.push({path:n,scope:t,found:[],removed:[]});continue}let r;try{r=$i(n)}catch(e){let r=e instanceof Error?e.message:String(e);c.push({path:n,scope:t,found:[],removed:[],error:r}),l=!1;continue}if(r.length===0||i){c.push({path:n,scope:t,found:r,removed:[]});continue}let s=await o({cwd:a,scope:t,patch:ta(Zi.filter(e=>r.includes(e.join(`.`)))),homedirOverride:e.homedirOverride});if(!s.ok){c.push({path:n,scope:t,found:r,removed:[],error:S(s.error)}),l=!1;continue}c.push({path:n,scope:t,found:r,removed:r})}for(let e of c)e.error&&n(`✗ ${e.path}: ${e.error}`);let u=c.some(e=>e.error!==void 0),d=c.reduce((e,t)=>e+t.found.length,0);if(d===0&&!u)t(`No deprecated fields found.`);else if(d>0)for(let e of c)e.error||(e.found.length===0?t(` ${e.path}: no deprecated fields`):t(i?`[dry-run] ${e.path}: would remove ${e.found.length} field(s): ${e.found.join(`, `)}`:`✓ ${e.path}: removed ${e.removed.length} field(s): ${e.removed.join(`, `)}`));return{outcomes:c,ok:l}}function ra(){let e=new t(`config`).description(`Inspect and maintain Open Knowledge configuration files`);return e.command(`validate`).description(`Validate the merged config (defaults → user → project)`).action(()=>{Qi({}).ok||(process.exitCode=1)}),e.command(`migrate`).description(`Remove deprecated config fields from config.yml idempotently (every removed key in the registry — content.*, folders, appearance.editorModeDefault, server.host, etc. — plus the silently-dropped sync.*, persistence.*, server.port)`).option(`--scope <scope>`,`Which scope to migrate: project | user | both`,`both`).option(`--dry-run`,`Preview without writing`,!1).action(async e=>{let t=e.scope;if(t!==`project`&&t!==`user`&&t!==`both`){console.error(`Invalid --scope: ${t}. Expected: project | user | both`),process.exitCode=2;return}(await na({scope:t,dryRun:e.dryRun})).ok||(process.exitCode=1)}),e}var ia=e(ct(),1),K=e(Et(),1);const aa=new Set([`doc.name`]);function oa(e){return`doc:${cn(`blake2b512`,{outputLength:32}).update(e).digest(`hex`).slice(0,8)}`}function sa(e,t,n){let r=e.docNameMap[n];if(r===void 0){e.docNameMap[n]=t;return}if(r===t)return;let i=e.docNameCollisions[n];i?i.includes(t)||i.push(t):e.docNameCollisions[n]=[t]}function ca(e,t){let n=t.originalToHashed.get(e);if(n!==void 0)return n;let r=oa(e);return t.originalToHashed.set(e,r),sa(t,e,r),r}function la(e,t){return t.length===0||!e.includes(t)?e:e.split(t).join(`<CONTENT_DIR>`)}function ua(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function da(e,t){if(typeof e==`string`)return la(e,t.contentDir);if(Array.isArray(e))return e.map(e=>da(e,t));if(!ua(e))return e;let n=typeof e.key==`string`&&aa.has(e.key)&&ua(e.value)&&typeof e.value.stringValue==`string`?e.value.stringValue:null,r={};for(let[i,a]of Object.entries(e))if(n!==null&&i===`value`&&ua(a)){let e=ca(n,t);r[i]={...a,stringValue:e}}else aa.has(i)&&typeof a==`string`?r[i]=ca(a,t):r[i]=da(a,t);return r}function fa(e,t){if(t.originalToHashed.size===0)return e;let n=Array.from(t.originalToHashed.entries()).sort(([e],[t])=>t.length-e.length),r=e;for(let[e,t]of n)e.length!==0&&r.includes(e)&&(r=r.split(e).join(t));return r}function pa(e,t){let n=L(e,`utf-8`);if(n.length===0)return;let r=n.endsWith(`
23
+ `);try{let{runInit:e}=await import(`./init-BjabhwWj.mjs`),n=await e({cwd:a,mcp:!1});if(n.contentUpdated.length>0){let e=`auto-init: updated ${n.contentUpdated.join(`, `)}`;t.json?G(!0,{type:`warning`,message:e}):process.stderr.write(` ${e}\n`)}}catch(e){let n=e instanceof Error?e.message:String(e);t.json?G(!0,{type:`warning`,message:`auto-init: ${n}`}):process.stderr.write(` auto-init: ${n}\n`)}try{Ji(a)}catch(e){let n=e instanceof Error?e.message:String(e);t.json?G(!0,{type:`warning`,message:`git-exclude: ${n}`}):process.stderr.write(` git-exclude: ${n}\n`)}return a}function Ji(e){let t=be(e,[`.ok/`]);return t.kind===`no-exclude`?`no-exclude`:t.kind===`refused-tracked`?`already-present`:t.appended.length>0?`appended`:`already-present`}function Yi(e){return new t(`clone`).description(`Clone a git repository and open it`).argument(`<url>`,`Repository URL or owner/repo shorthand`).argument(`[dir]`,`Target directory (default: ./<repo-name>)`).option(`--json`,`Output JSONL progress events`,!1).option(`-b, --branch <branch>`,`Branch to check out (falls back to default if missing)`).action(async(t,n,r)=>{let i=e();try{let a=await qi(t,{json:r.json,dir:n,branch:r.branch??null},i);if(r.json)G(!0,{type:`complete`,dir:a});else{process.stderr.write(`✓ Cloned to ${a}\n`),process.chdir(a);let{startCommand:t}=await import(`./start-BQLkhCCa.mjs`);await t(e).parseAsync([],{from:`user`})}}catch(e){let t=e instanceof Error?e.message:String(e);r.json?G(!0,{type:`error`,message:t}):process.stderr.write(`✗ ${t}\n`),process.exitCode=1}})}var Xi=g();const Zi=[[`sync`],[`persistence`,`debounceMs`],[`persistence`,`maxDebounceMs`],[`server`,`port`],...p.map(e=>e.path)];function Qi(e={}){let t=e.log??(e=>console.error(e)),n=e.error??(e=>console.error(e)),r=e.loadConfigFn??vt;try{let{sources:n}=r(e.cwd);return t(`✓ Configuration valid (sources: ${n.length===0?`defaults only`:n.join(`, `)})`),{ok:!0}}catch(e){return n(e instanceof Error?e.message:String(e)),{ok:!1}}}function $i(e){let t=(0,Xi.parseDocument)(L(e,`utf-8`));if(t.errors.length>0)throw Error(`Could not parse ${e}: ${t.errors.map(e=>e.message).join(`; `)}`);let n=[];for(let e of Zi)t.hasIn(e)&&n.push(e.join(`.`));return n}function ea(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ta(e){let t={};for(let n of e){let e=t;for(let t=0;t<n.length-1;t++){let r=n[t],i=e[r],a=ea(i)?i:{};e[r]=a,e=a}e[n[n.length-1]]=null}return t}async function na(e={}){let t=e.log??(e=>console.log(e)),n=e.error??(e=>console.error(e)),r=e.scope??`both`,i=e.dryRun??!1,a=e.cwd??process.cwd(),o=e.writeConfigPatchFn??Pe,s=[];(r===`project`||r===`both`)&&s.push({scope:`project`,absPath:De(`project`,a,e.homedirOverride)}),(r===`user`||r===`both`)&&s.push({scope:`user`,absPath:De(`user`,a,e.homedirOverride)});let c=[],l=!0;for(let{scope:t,absPath:n}of s){if(!F(n)){c.push({path:n,scope:t,found:[],removed:[]});continue}let r;try{r=$i(n)}catch(e){let r=e instanceof Error?e.message:String(e);c.push({path:n,scope:t,found:[],removed:[],error:r}),l=!1;continue}if(r.length===0||i){c.push({path:n,scope:t,found:r,removed:[]});continue}let s=await o({cwd:a,scope:t,patch:ta(Zi.filter(e=>r.includes(e.join(`.`)))),homedirOverride:e.homedirOverride});if(!s.ok){c.push({path:n,scope:t,found:r,removed:[],error:S(s.error)}),l=!1;continue}c.push({path:n,scope:t,found:r,removed:r})}for(let e of c)e.error&&n(`✗ ${e.path}: ${e.error}`);let u=c.some(e=>e.error!==void 0),d=c.reduce((e,t)=>e+t.found.length,0);if(d===0&&!u)t(`No deprecated fields found.`);else if(d>0)for(let e of c)e.error||(e.found.length===0?t(` ${e.path}: no deprecated fields`):t(i?`[dry-run] ${e.path}: would remove ${e.found.length} field(s): ${e.found.join(`, `)}`:`✓ ${e.path}: removed ${e.removed.length} field(s): ${e.removed.join(`, `)}`));return{outcomes:c,ok:l}}function ra(){let e=new t(`config`).description(`Inspect and maintain Open Knowledge configuration files`);return e.command(`validate`).description(`Validate the merged config (defaults → user → project)`).action(()=>{Qi({}).ok||(process.exitCode=1)}),e.command(`migrate`).description(`Remove deprecated config fields from config.yml idempotently (every removed key in the registry — content.*, folders, appearance.editorModeDefault, server.host, etc. — plus the silently-dropped sync.*, persistence.*, server.port)`).option(`--scope <scope>`,`Which scope to migrate: project | user | both`,`both`).option(`--dry-run`,`Preview without writing`,!1).action(async e=>{let t=e.scope;if(t!==`project`&&t!==`user`&&t!==`both`){console.error(`Invalid --scope: ${t}. Expected: project | user | both`),process.exitCode=2;return}(await na({scope:t,dryRun:e.dryRun})).ok||(process.exitCode=1)}),e}var ia=e(ct(),1),K=e(Et(),1);const aa=new Set([`doc.name`]);function oa(e){return`doc:${cn(`blake2b512`,{outputLength:32}).update(e).digest(`hex`).slice(0,8)}`}function sa(e,t,n){let r=e.docNameMap[n];if(r===void 0){e.docNameMap[n]=t;return}if(r===t)return;let i=e.docNameCollisions[n];i?i.includes(t)||i.push(t):e.docNameCollisions[n]=[t]}function ca(e,t){let n=t.originalToHashed.get(e);if(n!==void 0)return n;let r=oa(e);return t.originalToHashed.set(e,r),sa(t,e,r),r}function la(e,t){return t.length===0||!e.includes(t)?e:e.split(t).join(`<CONTENT_DIR>`)}function ua(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function da(e,t){if(typeof e==`string`)return la(e,t.contentDir);if(Array.isArray(e))return e.map(e=>da(e,t));if(!ua(e))return e;let n=typeof e.key==`string`&&aa.has(e.key)&&ua(e.value)&&typeof e.value.stringValue==`string`?e.value.stringValue:null,r={};for(let[i,a]of Object.entries(e))if(n!==null&&i===`value`&&ua(a)){let e=ca(n,t);r[i]={...a,stringValue:e}}else aa.has(i)&&typeof a==`string`?r[i]=ca(a,t):r[i]=da(a,t);return r}function fa(e,t){if(t.originalToHashed.size===0)return e;let n=Array.from(t.originalToHashed.entries()).sort(([e],[t])=>t.length-e.length),r=e;for(let[e,t]of n)e.length!==0&&r.includes(e)&&(r=r.split(e).join(t));return r}function pa(e,t){let n=L(e,`utf-8`);if(n.length===0)return;let r=n.endsWith(`
24
24
  `),i=n.split(`
25
25
  `),a=[];for(let e=0;e<i.length;e++){let n=i[e]??``;if(!(e===i.length-1&&n===``)){if(n.length===0){a.push(``);continue}try{let e=da(JSON.parse(n),t);a.push(JSON.stringify(e))}catch{a.push(n)}}}R(e,r?`${a.join(`
26
26
  `)}\n`:a.join(`
@@ -50,7 +50,7 @@ ws.addEventListener('error', () => process.exit(1));
50
50
  setTimeout(() => process.exit(2), ${t+1e4});
51
51
  `),r}async function xo(e,t,n,r,i){let a=bo(e,t,N(r,`cpu.cpuprofile`)),o=!1,s=A(process.execPath,[a],{stdio:`ignore`}),c=setInterval(()=>{let e=go(n);e&&i(e)},1e3);await new Promise(e=>{s.once(`close`,t=>{o=t===0,e()}),setTimeout(()=>{s.kill(),e()},t+12e3)}),clearInterval(c);try{Ut(N(a,`..`),{recursive:!0,force:!0})}catch{}return o}function So(e){let t;try{t=JSON.parse(e)}catch{return`(could not parse profile)`}let n=new Map(t.nodes.map(e=>[e.id,e])),r=new Map;for(let e of t.nodes)for(let t of e.children??[])r.set(t,e.id);let i=new Map;for(let e of t.samples??[])i.set(e,(i.get(e)??0)+1);let a=t.samples?.length??0,o=t.endTime!=null&&t.startTime!=null?((t.endTime-t.startTime)/1e3).toFixed(2):`?`,s=[...i.entries()].sort((e,t)=>t[1]-e[1]).slice(0,10),c=[`samples ${a} duration_ms ${o}`,``,`Top leaf nodes`];for(let[e,t]of s){let r=n.get(e);if(!r)continue;let i=a>0?(t/a*100).toFixed(1):`0.0`,{functionName:o,url:s,lineNumber:l,columnNumber:u}=r.callFrame;c.push(` ${t} ${i}% id=${e} ${o||`(anonymous)`} ${s}:${l}:${u} hit=${r.hitCount??0}`)}c.push(``,`Top stacks`);let l=e=>{let t=[],i=e;for(;i!=null;){let e=n.get(i);if(!e)break;let{functionName:a,url:o,lineNumber:s,columnNumber:c}=e.callFrame;t.unshift(` ${a||`(anonymous)`} ${o} ${s} ${c}`),i=r.get(i)}return t};for(let[e,t]of s.slice(0,5)){let n=a>0?(t/a*100).toFixed(1):`0.0`;c.push(``,`--- ${t} ${n}%`,...l(e))}return c.join(`
52
52
  `)}async function Co(e,t={}){let{pid:n,cpuProfileSecs:r=15,noInspector:i=!1}=e,a=t.log??(e=>console.log(e)),o=t.discover??pt,s=t.inspect??mt,c=t.resolveCommand??ht,l=t.resolveUsage??ut,u=t.collectLsofFn??_o,d=t.getEndpoints??yo,f=t.profiler??xo,p=t.isAlive??(e=>{try{return process.kill(e,0),!0}catch(e){return e.code===`EPERM`}}),m=t.sendSignal??((e,t)=>{process.kill(e,t)}),h=t.sleep??(e=>new Promise(t=>setTimeout(t,e))),g=r*1e3;if(!p(n)){a(K.default.red(`No process with pid ${n} found.`));return}let _=await o(),v=null,y=null;for(let e of _){let t=s(e,`server`);if(t.status!==`missing`&&t.status!==`corrupt`&&t.lock.pid===n){v=t.lock.worktreeRoot,y={lockDir:e,state:t.status,lockPath:t.lockPath,lock:t.lock};break}}let b=new Date().toISOString().replace(/[:.]/g,`-`),x=e.output?e.output:v?N(v,`.ok`,`local`,`diagnostics`,`process-${n}-${b}`):N(process.cwd(),`ok-diagnose-${n}-${b}`);try{I(x,{recursive:!0})}catch(e){a(K.default.red(`Cannot create output directory ${x}: ${e.message}`));return}a(K.default.bold(`Diagnosing pid ${n}`)),a(`Output: ${x}`),a(``);let S=(e,t)=>{R(N(x,e),t),a(` wrote ${e}`)},ee=c(n),te=l(n);S(`metadata.json`,JSON.stringify({capturedAt:new Date().toISOString(),pid:n,command:ee,usage:te,lockInfo:y},null,2)),a(` sampling lsof`);let C=u(n);if(C&&S(`lsof.txt`,C),!i){let e=C?vo(C).find(e=>e>=9229&&e<=9299)??9229:9229,t=d(e);if(!t||t.length===0){a(` no inspector on :${e}, sending SIGUSR1 to pid ${n}`);try{m(n,`SIGUSR1`),await h(2e3),t=d(e)}catch(e){a(K.default.yellow(` SIGUSR1 delivery failed: ${e.message}`))}}if(t&&t.length>0){S(`inspector-endpoints.json`,JSON.stringify(t,null,2));let e=t[0].webSocketDebuggerUrl;if(e){a(` capturing ${r}s CPU profile`);let t=[];await f(e,g,n,x,e=>t.push(e))?a(` wrote cpu.cpuprofile`):a(K.default.yellow(` CPU profile capture failed`)),t.length>0&&S(`process-stats.jsonl`,`${t.map(e=>JSON.stringify(e)).join(`
53
- `)}\n`);try{S(`stacks.txt`,So(L(N(x,`cpu.cpuprofile`),`utf-8`)))}catch(e){a(K.default.yellow(` stacks.txt skipped: ${e.message}`))}}}else a(K.default.yellow(` Node inspector unavailable — skipping CPU profile`))}a(``),a(K.default.yellow(`⚠ Before sharing, review what each file contains:`)),a(` metadata.json — content directory paths, lock file locations, CPU/MEM at capture time`),a(` lsof.txt — all open files, network connections, and private paths for this process`),a(` inspector-endpoints.json — Node debugger metadata (titles, URLs)`),a(` cpu.cpuprofile — function names and source file paths from your Node process`),a(` stacks.txt — call stacks derived from cpu.cpuprofile; includes source paths`),a(` process-stats.jsonl — CPU/MEM/RSS numbers only; safe to share`),a(``),a(`Bundle: ${K.default.bold(x)}`)}async function wo(e){let t=dn({input:process.stdin,output:process.stdout});try{return(await t.question(e)).trim()}finally{t.close()}}async function To(e){let t=zt(N(Qt(),`ok-bundle-process-`));return await Co({pid:e,output:t}),t}function Eo(e){if(e<1024)return`${e} B`;let t=e/1024;if(t<1024)return`${t.toFixed(1)} KB`;let n=t/1024;return n<1024?`${n.toFixed(1)} MB`:`${(n/1024).toFixed(1)} GB`}function Do(e){let t=e.trim().toLowerCase();return t===`y`||t===`yes`}function Oo(e,t,n){let{summary:r,manifest:i}=t;e(``),e(K.default.bold(`ok diagnose bundle — content summary`)),e(``),e(` Files: ${r.fileCount}`),e(` Total size: ${Eo(r.totalBytes)} uncompressed`),e(` doc.name attributes: ${r.docNameCount} occurrence(s) in telemetry${r.redacted?` (values hashed)`:``}`),e(` Content-dir path: ${r.contentDirVisible?`visible (${i.contentDir.absolutePath})`:`not visible`}`),e(` Redacted: ${r.redacted?`yes`:`no`}`),e(` Server status: ${i.serverStatus}`),e(` Output: ${n}`),e(``)}async function ko(e,t={}){let n=t.log??(e=>console.log(e)),r=t.prompt??wo,i=t.runProcessDiagnose??To,a=t.now??(()=>new Date),o;if(e.out!==void 0){o=e.out;let t=jt(o);if(!F(t))throw Error(`ok diagnose bundle: --out parent directory does not exist: ${t}. Create it first.`)}else{let t=a().toISOString().replace(/[:.]/g,`-`),n=N(e.contentDir,`.ok`,`local`,`diagnostics`);I(n,{recursive:!0}),o=N(n,`bundle-${t}.zip`)}let s;e.pid!==void 0&&(n(K.default.dim(`Running ok diagnose process ${e.pid} into a temp dir`)),s=await i(e.pid));let c=await qa({contentDir:e.contentDir,projectDir:e.projectDir,processDir:s,redact:e.redact===!0,deps:t.collectDeps});try{return c.manifest.serverStatus===`not-running`&&n(K.default.yellow(` server not running — live state unavailable`)),Oo(n,c,o),e.yes!==!0&&!Do(await r(`Write bundle? [y/N]: `))?(n(K.default.dim(`Aborted; no bundle written.`)),{outputPath:null,declined:!0}):(await Ja({collected:c,outputPath:o}),n(K.default.bold(`Bundle: ${o}`)),{outputPath:o,declined:!1})}finally{if(c.cleanup(),s!==void 0)try{Ut(s,{recursive:!0,force:!0})}catch{}}}function Ao(){let e=new t(`diagnose`).description(`Diagnostic utilities for open-knowledge processes`);return e.command(`process`).description(`Capture a diagnostic bundle (metadata, lsof, CPU profile) for a running process`).argument(`<pid>`,`Process ID to diagnose`).option(`--cpu-profile <seconds>`,`CPU profile duration (default: 15)`,`15`).option(`--output <dir>`,`Output directory`).option(`--no-inspector`,`Collect metadata only; skip Node inspector and CPU profile`).action(async(e,t)=>{let n=Number.parseInt(e,10);(Number.isNaN(n)||n<=0)&&(console.error(K.default.red(`Invalid pid '${e}': must be a positive integer`)),process.exit(1));let r=Number.parseInt(t.cpuProfile,10);(Number.isNaN(r)||r<=0)&&(console.error(K.default.red(`--cpu-profile must be a positive integer`)),process.exit(1)),await Co({pid:n,cpuProfileSecs:r,output:t.output,noInspector:!t.inspector})}),e.addCommand(ho()),e.command(`bundle`).description(`Capture a support bundle (telemetry + logs + server state) into a zip suitable for bug reports`).option(`--pid <pid>`,"Include `ok diagnose process <pid>` output under process/ in the bundle").option(`--out <path>`,`Write the zip to this path instead of the default location`).option(`--yes`,`Skip the y/N prompt`).option(`--redact`,`Hash doc names and strip the content-dir prefix from the staged bundle`).action(async e=>{let t;e.pid!==void 0&&(t=Number.parseInt(e.pid,10),(Number.isNaN(t)||t<=0)&&(console.error(K.default.red(`Invalid --pid '${e.pid}': must be a positive integer`)),process.exit(1)));try{let{loadConfig:n}=await import(`./loader-D6ZQW0bM.mjs`),{resolveContentDir:r}=await import(`./dist-Bj_IaFF5.mjs`),i=process.cwd(),{config:a}=n(i);await ko({contentDir:r(a,i),projectDir:i,pid:t,out:e.out,yes:e.yes===!0,redact:e.redact===!0})}catch(e){let t=e instanceof Error?e.message:String(e);console.error(K.default.red(t)),process.exit(1)}}),e}const jo=[` 1. ${k(`Customize`)} (sidebar) → ${k(`Skills`)}`,` 2. Click the ${k(`+`)} button`,` 3. Click ${k(`Create skill`)}`,` 4. Click ${k(`Upload skill`)}`,` 5. Pick ${k(`openknowledge.skill`)} from Downloads`],Mo=T(` Open the Claude Desktop App, then: ${k(`Customize → Skills → + → Create skill → Upload skill`)} → pick the file.`);function No(e){let t=[D(`Built ${e.outputPath}`),E(` ${e.size} bytes • sha256 ${e.sha256?.slice(0,12)}…`)];return e.handoffError&&t.push(O(` Handoff failed: ${e.handoffError.message}`)),t.push(Mo),t.join(`
53
+ `)}\n`);try{S(`stacks.txt`,So(L(N(x,`cpu.cpuprofile`),`utf-8`)))}catch(e){a(K.default.yellow(` stacks.txt skipped: ${e.message}`))}}}else a(K.default.yellow(` Node inspector unavailable — skipping CPU profile`))}a(``),a(K.default.yellow(`⚠ Before sharing, review what each file contains:`)),a(` metadata.json — content directory paths, lock file locations, CPU/MEM at capture time`),a(` lsof.txt — all open files, network connections, and private paths for this process`),a(` inspector-endpoints.json — Node debugger metadata (titles, URLs)`),a(` cpu.cpuprofile — function names and source file paths from your Node process`),a(` stacks.txt — call stacks derived from cpu.cpuprofile; includes source paths`),a(` process-stats.jsonl — CPU/MEM/RSS numbers only; safe to share`),a(``),a(`Bundle: ${K.default.bold(x)}`)}async function wo(e){let t=dn({input:process.stdin,output:process.stdout});try{return(await t.question(e)).trim()}finally{t.close()}}async function To(e){let t=zt(N(Qt(),`ok-bundle-process-`));return await Co({pid:e,output:t}),t}function Eo(e){if(e<1024)return`${e} B`;let t=e/1024;if(t<1024)return`${t.toFixed(1)} KB`;let n=t/1024;return n<1024?`${n.toFixed(1)} MB`:`${(n/1024).toFixed(1)} GB`}function Do(e){let t=e.trim().toLowerCase();return t===`y`||t===`yes`}function Oo(e,t,n){let{summary:r,manifest:i}=t;e(``),e(K.default.bold(`ok diagnose bundle — content summary`)),e(``),e(` Files: ${r.fileCount}`),e(` Total size: ${Eo(r.totalBytes)} uncompressed`),e(` doc.name attributes: ${r.docNameCount} occurrence(s) in telemetry${r.redacted?` (values hashed)`:``}`),e(` Content-dir path: ${r.contentDirVisible?`visible (${i.contentDir.absolutePath})`:`not visible`}`),e(` Redacted: ${r.redacted?`yes`:`no`}`),e(` Server status: ${i.serverStatus}`),e(` Output: ${n}`),e(``)}async function ko(e,t={}){let n=t.log??(e=>console.log(e)),r=t.prompt??wo,i=t.runProcessDiagnose??To,a=t.now??(()=>new Date),o;if(e.out!==void 0){o=e.out;let t=jt(o);if(!F(t))throw Error(`ok diagnose bundle: --out parent directory does not exist: ${t}. Create it first.`)}else{let t=a().toISOString().replace(/[:.]/g,`-`),n=N(e.contentDir,`.ok`,`local`,`diagnostics`);I(n,{recursive:!0}),o=N(n,`bundle-${t}.zip`)}let s;e.pid!==void 0&&(n(K.default.dim(`Running ok diagnose process ${e.pid} into a temp dir`)),s=await i(e.pid));let c=await qa({contentDir:e.contentDir,projectDir:e.projectDir,processDir:s,redact:e.redact===!0,deps:t.collectDeps});try{return c.manifest.serverStatus===`not-running`&&n(K.default.yellow(` server not running — live state unavailable`)),Oo(n,c,o),e.yes!==!0&&!Do(await r(`Write bundle? [y/N]: `))?(n(K.default.dim(`Aborted; no bundle written.`)),{outputPath:null,declined:!0}):(await Ja({collected:c,outputPath:o}),n(K.default.bold(`Bundle: ${o}`)),{outputPath:o,declined:!1})}finally{if(c.cleanup(),s!==void 0)try{Ut(s,{recursive:!0,force:!0})}catch{}}}function Ao(){let e=new t(`diagnose`).description(`Diagnostic utilities for open-knowledge processes`);return e.command(`process`).description(`Capture a diagnostic bundle (metadata, lsof, CPU profile) for a running process`).argument(`<pid>`,`Process ID to diagnose`).option(`--cpu-profile <seconds>`,`CPU profile duration (default: 15)`,`15`).option(`--output <dir>`,`Output directory`).option(`--no-inspector`,`Collect metadata only; skip Node inspector and CPU profile`).action(async(e,t)=>{let n=Number.parseInt(e,10);(Number.isNaN(n)||n<=0)&&(console.error(K.default.red(`Invalid pid '${e}': must be a positive integer`)),process.exit(1));let r=Number.parseInt(t.cpuProfile,10);(Number.isNaN(r)||r<=0)&&(console.error(K.default.red(`--cpu-profile must be a positive integer`)),process.exit(1)),await Co({pid:n,cpuProfileSecs:r,output:t.output,noInspector:!t.inspector})}),e.addCommand(ho()),e.command(`bundle`).description(`Capture a support bundle (telemetry + logs + server state) into a zip suitable for bug reports`).option(`--pid <pid>`,"Include `ok diagnose process <pid>` output under process/ in the bundle").option(`--out <path>`,`Write the zip to this path instead of the default location`).option(`--yes`,`Skip the y/N prompt`).option(`--redact`,`Hash doc names and strip the content-dir prefix from the staged bundle`).action(async e=>{let t;e.pid!==void 0&&(t=Number.parseInt(e.pid,10),(Number.isNaN(t)||t<=0)&&(console.error(K.default.red(`Invalid --pid '${e.pid}': must be a positive integer`)),process.exit(1)));try{let{loadConfig:n}=await import(`./loader-Bytb4s2w.mjs`),{resolveContentDir:r}=await import(`./dist-Bj_IaFF5.mjs`),i=process.cwd(),{config:a}=n(i);await ko({contentDir:r(a,i),projectDir:i,pid:t,out:e.out,yes:e.yes===!0,redact:e.redact===!0})}catch(e){let t=e instanceof Error?e.message:String(e);console.error(K.default.red(t)),process.exit(1)}}),e}const jo=[` 1. ${k(`Customize`)} (sidebar) → ${k(`Skills`)}`,` 2. Click the ${k(`+`)} button`,` 3. Click ${k(`Create skill`)}`,` 4. Click ${k(`Upload skill`)}`,` 5. Pick ${k(`openknowledge.skill`)} from Downloads`],Mo=T(` Open the Claude Desktop App, then: ${k(`Customize → Skills → + → Create skill → Upload skill`)} → pick the file.`);function No(e){let t=[D(`Built ${e.outputPath}`),E(` ${e.size} bytes • sha256 ${e.sha256?.slice(0,12)}…`)];return e.handoffError&&t.push(O(` Handoff failed: ${e.handoffError.message}`)),t.push(Mo),t.join(`
54
54
  `)}function Po(e){let t=e.skillVersion??`unknown`,n=e.recordedAt??`unknown`;return[T(`Open Knowledge skill ${k(`v${t}`)} already delivered to Claude Desktop.`),E(` Recorded at ${n} in ~/.ok/skill-state.yml`),E(` Use ${k(`--force`)} to rebuild and re-open the install dialog.`)].join(`
55
55
  `)}function Fo(e){let t=e.skillVersion?` • Skill v${e.skillVersion}`:``;return[D(`Built ${e.outputPath}`),E(` ${e.size} bytes • sha256 ${e.sha256?.slice(0,12)}…${t}`),T(` Claude Desktop App opened. Now upload the file manually:`),...jo,E(` If Claude Desktop didn't open, open it and start at step 1. The file is at ${e.outputPath}`)].join(`
56
56
  `)}function Io(e){return`${Dt(`Error:`)} ${e.buildError??`unknown build failure`}`}async function Lo(e={}){let t=await et(e);return t.status===`failed`?{...t,message:Io(t),exitCode:1}:t.status===`skip-current`?{...t,message:Po(t),exitCode:0}:t.status===`installed`?{...t,message:Fo(t),exitCode:0}:{...t,message:No(t),exitCode:0}}function Ro(){return new t(`install-skill`).description("Build openknowledge.skill and open the Claude Desktop App so you can upload it for Claude Chat & Cowork. Not needed for Claude — `ok init` covers that separately.").option(`--out <path>`,`Custom output path (default: ~/Downloads/openknowledge.skill)`).option(`--no-open`,`Build the file but skip the OS file-association handoff`).option(`--force`,`Bypass the install-state gate and rebuild unconditionally`).action(async e=>{let t=await Lo({out:e.out,noOpen:!e.open,force:e.force??!1});process.stdout.write(`${t.message}\n`),t.exitCode!==0&&process.exit(t.exitCode)})}const zo=N(`Contents`,`Resources`,`cli`,`bin`,`ok.sh`),Bo=/Contents\/Resources\/cli\/dist\/cli\.mjs$/;function Vo(e,t,n){return e===`darwin`?[N(t,`Applications`,`Open Knowledge.app`,zo),N(`/Applications`,`Open Knowledge.app`,zo)].find(e=>n.existsSync(e))??null:null}function Ho(e,t,n){if(n!==`darwin`)return{proxy:!1,suppressedBy:`platform`};let r=e.OK_BUNDLE_PROXY?.toLowerCase();return r===`0`||r===`false`?{proxy:!1,suppressedBy:`env`}:t.includes(`--no-bundle-proxy`)?{proxy:!1,suppressedBy:`flag`}:typeof t[1]==`string`&&Bo.test(t[1])?{proxy:!1,suppressedBy:`self`}:{proxy:!0,suppressedBy:null}}function Uo(e){e.stderr.write(`${JSON.stringify({event:`mcp-bundle-proxy`,mode:e.mode,bundlePath:e.bundlePath,reason:e.reason,hint:`Suppress with --no-bundle-proxy or OK_BUNDLE_PROXY=0.`})}\n`)}function Wo(e){Uo({stderr:e.stderr,mode:`bundled`,bundlePath:e.bundlePath,reason:null});let t=e.spawnImpl??A,n=e.exitProcess??(e=>process.exit(e)),r=e.now??(()=>Date.now()),i=r(),a=e.startupFailureWindowMs??1e3;return new Promise((o,s)=>{let c=t(e.bundlePath,e.argv.filter(e=>e!==`--no-bundle-proxy`),{env:{...e.env,OK_BUNDLE_PROXY:`0`},stdio:`inherit`}),l=e=>{c.kill(e)},u=()=>{process.off(`SIGTERM`,l),process.off(`SIGINT`,l)};process.on(`SIGTERM`,l),process.on(`SIGINT`,l),c.once(`error`,e=>{u(),s(e)}),c.once(`exit`,(e,t)=>{if(u(),t){s(Error(`bundle process exited by signal ${t}`));return}let o=e??0,c=r()-i;if(o!==0&&c<=a){s(Error(`bundle process exited during startup with code ${o}`));return}n(o)})})}function Go(e){let t=e.scheduler??{setTimeout:(e,t)=>globalThis.setTimeout(e,t),clearTimeout:e=>globalThis.clearTimeout(e)},n=e.initialBackoffMs??1e3,r=e.maxBackoffMs??3e4,i=e.rng??Math.random,a=e.createWebSocket??(e=>new WebSocket(e)),o=e.logger??null,s=e.log,c=null,l=null,u=!1,d=n;function f(e,t,n){try{o?o[e](t,n):s?.(t)}catch{}}function p(){if(u)return;l!==null&&t.clearTimeout(l);let e=d;d=Math.min(d*2,r);let n=i(),a=Math.max(1,Math.floor(e*(1-n/2)));f(`debug`,`scheduling reconnect`,{backoffMs:a,ceilMs:e}),l=t.setTimeout(()=>{l=null,m().catch(e=>f(`warn`,`reconnect failed`,{error:String(e)}))},a)}async function m(){if(u)return;let t;try{t=await e.resolveWsUrl()}catch(e){f(`warn`,`resolveWsUrl threw`,{error:String(e)}),p();return}if(!t){p();return}let r=e.connectionId?`&connectionId=${encodeURIComponent(e.connectionId)}`:``,i=e.connectionId&&e.displayName!==void 0&&e.clientName!==void 0&&e.colorSeed!==void 0?`&displayName=${encodeURIComponent(e.displayName)}&clientName=${encodeURIComponent(e.clientName)}&colorSeed=${encodeURIComponent(e.colorSeed)}`:``,o=`${t}/collab/keepalive?pid=${process.pid}${r}${i}`;try{c=a(o)}catch(e){f(`warn`,`WebSocket constructor failed`,{url:o,error:String(e)}),c=null,p();return}c.addEventListener(`open`,()=>{f(`info`,`connected`,{url:t}),d=n}),c.addEventListener(`close`,()=>{u||(f(`info`,`disconnected`,{url:t}),c=null,p())}),c.addEventListener(`error`,()=>{f(`debug`,`websocket error observed`,{url:t,readyState:c?.readyState,reason:`error-event`})})}return queueMicrotask(()=>{m().catch(e=>f(`warn`,`initial connect failed`,{error:String(e)}))}),{close:()=>{if(!u&&(u=!0,l!==null&&(t.clearTimeout(l),l=null),c)){try{c.close()}catch{}c=null}},isConnected:()=>c!==null&&c.readyState===1}}var Ko=class{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;let e=this._buffer.indexOf(`
@@ -62,7 +62,7 @@ setTimeout(() => process.exit(2), ${t+1e4});
62
62
  `&&r++}}return[t,n]}var _c=class extends TransformStream{constructor({onError:e,onRetry:t,onComment:n}={}){let r;super({start(i){r=hc({onEvent:e=>{i.enqueue(e)},onError(t){e===`terminate`?i.error(t):typeof e==`function`&&e(t)},onRetry:t,onComment:n})},transform(e){r.feed(e)}})}};const vc={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2};var yc=class extends Error{constructor(e,t){super(`Streamable HTTP error: ${t}`),this.code=e}},bc=class{constructor(e,t){this._hasCompletedAuthFlow=!1,this._url=e,this._resourceMetadataUrl=void 0,this._scope=void 0,this._requestInit=t?.requestInit,this._authProvider=t?.authProvider,this._fetch=t?.fetch,this._fetchWithInit=ns(t?.fetch,t?.requestInit),this._sessionId=t?.sessionId,this._reconnectionOptions=t?.reconnectionOptions??vc}async _authThenStart(){if(!this._authProvider)throw new Z(`No auth provider`);let e;try{e=await Ks(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})}catch(e){throw this.onerror?.(e),e}if(e!==`AUTHORIZED`)throw new Z;return await this._startOrAuthSse({resumptionToken:void 0})}async _commonHeaders(){let e={};if(this._authProvider){let t=await this._authProvider.tokens();t&&(e.Authorization=`Bearer ${t.access_token}`)}this._sessionId&&(e[`mcp-session-id`]=this._sessionId),this._protocolVersion&&(e[`mcp-protocol-version`]=this._protocolVersion);let t=ts(this._requestInit?.headers);return new Headers({...e,...t})}async _startOrAuthSse(e){let{resumptionToken:t}=e;try{let n=await this._commonHeaders();n.set(`Accept`,`text/event-stream`),t&&n.set(`last-event-id`,t);let r=await(this._fetch??fetch)(this._url,{method:`GET`,headers:n,signal:this._abortController?.signal});if(!r.ok){if(await r.body?.cancel(),r.status===401&&this._authProvider)return await this._authThenStart();if(r.status===405)return;throw new yc(r.status,`Failed to open SSE stream: ${r.statusText}`)}this._handleSseStream(r.body,e,!0)}catch(e){throw this.onerror?.(e),e}}_getNextReconnectionDelay(e){if(this._serverRetryMs!==void 0)return this._serverRetryMs;let t=this._reconnectionOptions.initialReconnectionDelay,n=this._reconnectionOptions.reconnectionDelayGrowFactor,r=this._reconnectionOptions.maxReconnectionDelay;return Math.min(t*n**+e,r)}_scheduleReconnection(e,t=0){let n=this._reconnectionOptions.maxRetries;if(t>=n){this.onerror?.(Error(`Maximum reconnection attempts (${n}) exceeded.`));return}let r=this._getNextReconnectionDelay(t);this._reconnectionTimeout=setTimeout(()=>{this._startOrAuthSse(e).catch(n=>{this.onerror?.(Error(`Failed to reconnect SSE stream: ${n instanceof Error?n.message:String(n)}`)),this._scheduleReconnection(e,t+1)})},r)}_handleSseStream(e,t,n){if(!e)return;let{onresumptiontoken:r,replayMessageId:i}=t,a,o=!1,s=!1;(async()=>{try{let t=e.pipeThrough(new TextDecoderStream).pipeThrough(new _c({onRetry:e=>{this._serverRetryMs=e}})).getReader();for(;;){let{value:e,done:n}=await t.read();if(n)break;if(e.id&&(a=e.id,o=!0,r?.(e.id)),e.data&&(!e.event||e.event===`message`))try{let t=Oe.parse(JSON.parse(e.data));ke(t)&&(s=!0,i!==void 0&&(t.id=i)),this.onmessage?.(t)}catch(e){this.onerror?.(e)}}(n||o)&&!s&&this._abortController&&!this._abortController.signal.aborted&&this._scheduleReconnection({resumptionToken:a,onresumptiontoken:r,replayMessageId:i},0)}catch(e){if(this.onerror?.(Error(`SSE stream disconnected: ${e}`)),(n||o)&&!s&&this._abortController&&!this._abortController.signal.aborted)try{this._scheduleReconnection({resumptionToken:a,onresumptiontoken:r,replayMessageId:i},0)}catch(e){this.onerror?.(Error(`Failed to reconnect: ${e instanceof Error?e.message:String(e)}`))}}})()}async start(){if(this._abortController)throw Error(`StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.`);this._abortController=new AbortController}async finishAuth(e){if(!this._authProvider)throw new Z(`No auth provider`);if(await Ks(this._authProvider,{serverUrl:this._url,authorizationCode:e,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})!==`AUTHORIZED`)throw new Z(`Failed to authorize`)}async close(){this._reconnectionTimeout&&=(clearTimeout(this._reconnectionTimeout),void 0),this._abortController?.abort(),this.onclose?.()}async send(e,t){try{let{resumptionToken:n,onresumptiontoken:r}=t||{};if(n){this._startOrAuthSse({resumptionToken:n,replayMessageId:Ae(e)?e.id:void 0}).catch(e=>this.onerror?.(e));return}let i=await this._commonHeaders();i.set(`content-type`,`application/json`),i.set(`accept`,`application/json, text/event-stream`);let a={...this._requestInit,method:`POST`,headers:i,body:JSON.stringify(e),signal:this._abortController?.signal},o=await(this._fetch??fetch)(this._url,a),s=o.headers.get(`mcp-session-id`);if(s&&(this._sessionId=s),!o.ok){let t=await o.text().catch(()=>null);if(o.status===401&&this._authProvider){if(this._hasCompletedAuthFlow)throw new yc(401,`Server returned 401 after successful authentication`);let{resourceMetadataUrl:t,scope:n}=Xs(o);if(this._resourceMetadataUrl=t,this._scope=n,await Ks(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})!==`AUTHORIZED`)throw new Z;return this._hasCompletedAuthFlow=!0,this.send(e)}if(o.status===403&&this._authProvider){let{resourceMetadataUrl:t,scope:n,error:r}=Xs(o);if(r===`insufficient_scope`){let r=o.headers.get(`WWW-Authenticate`);if(this._lastUpscopingHeader===r)throw new yc(403,`Server returned 403 after trying upscoping`);if(n&&(this._scope=n),t&&(this._resourceMetadataUrl=t),this._lastUpscopingHeader=r??void 0,await Ks(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetch})!==`AUTHORIZED`)throw new Z;return this.send(e)}}throw new yc(o.status,`Error POSTing to endpoint: ${t}`)}if(this._hasCompletedAuthFlow=!1,this._lastUpscopingHeader=void 0,o.status===202){await o.body?.cancel(),Ue(e)&&this._startOrAuthSse({resumptionToken:void 0}).catch(e=>this.onerror?.(e));return}let c=(Array.isArray(e)?e:[e]).filter(e=>`method`in e&&`id`in e&&e.id!==void 0).length>0,l=o.headers.get(`content-type`);if(c)if(l?.includes(`text/event-stream`))this._handleSseStream(o.body,{onresumptiontoken:r},!1);else if(l?.includes(`application/json`)){let e=await o.json(),t=Array.isArray(e)?e.map(e=>Oe.parse(e)):[Oe.parse(e)];for(let e of t)this.onmessage?.(e)}else throw await o.body?.cancel(),new yc(-1,`Unexpected content type: ${l}`);else await o.body?.cancel()}catch(e){throw this.onerror?.(e),e}}get sessionId(){return this._sessionId}async terminateSession(){if(this._sessionId)try{let e=await this._commonHeaders(),t={...this._requestInit,method:`DELETE`,headers:e,signal:this._abortController?.signal},n=await(this._fetch??fetch)(this._url,t);if(await n.body?.cancel(),!n.ok&&n.status!==405)throw new yc(n.status,`Failed to terminate session: ${n.statusText}`);this._sessionId=void 0}catch(e){throw this.onerror?.(e),e}}setProtocolVersion(e){this._protocolVersion=e}get protocolVersion(){return this._protocolVersion}async resumeStream(e,t){await this._startOrAuthSse({resumptionToken:e,onresumptiontoken:t?.onresumptiontoken})}};function xc(e){return(t,n)=>{if((n?.method??`GET`).toUpperCase()===`GET`)return globalThis.fetch(t,n);let r=new AbortController,i=setTimeout(()=>r.abort(Error(`MCP request timed out after ${e}ms`)),e),a=n?.signal instanceof AbortSignal?AbortSignal.any([n.signal,r.signal]):r.signal;return globalThis.fetch(t,{...n,signal:a}).finally(()=>clearTimeout(i))}}function Sc(e){if(e===void 0||e===``)return;let t=Number.parseInt(e,10);if(!(Number.isNaN(t)||t<=0))return t}function Cc(e){return e===`0.0.0.0`||e===`::`?`localhost`:e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}function wc(e,t){return`http://${Cc(e)}:${t}/mcp`}function Tc(e,t){return`ws://${Cc(e)}:${t}`}function Ec(e){let t=new URL(e);return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.pathname=``,t.search=``,t.hash=``,t.toString().replace(/\/$/,``)}function Dc(e,t){if(!(!e||e.port<=0)&&t(e.pid))return e.port}function Oc(e){return F(e)?L(e,`utf-8`).trim():``}function kc(e,t){return`server did not start within ${e}ms${t?` stderr:\n${t}`:``}`}function Ac(e){if(e&&typeof e==`object`&&`method`in e&&`id`in e)return e.id}function jc(e){if(!e||typeof e!=`object`||!(`result`in e))return;let t=e.result;if(!t||typeof t!=`object`||!(`protocolVersion`in t))return;let n=t.protocolVersion;return typeof n==`string`?n:void 0}function Mc(e,t){return{jsonrpc:`2.0`,id:e,error:{code:-32e3,message:t instanceof Error?t.message:String(t)}}}async function Nc(e){let t=e.readLock??(()=>h(e.lockDir)),n=e.isAlive??y,r=e.sleep??(e=>un(e)),i=e.spawn??A,a=e.readErrorLog??Oc,o=e.openErrorLog??(e=>Bt(e,`w`)),s=e.closeFd??Ft,c=e.timeoutMs??5e3,l=e.pollIntervalMs??100;if(e.portOverride!==void 0){let t=Number.parseInt(e.portOverride,10);if(Number.isNaN(t)||t<=0)throw Error(`invalid --port value '${e.portOverride}' — HTTP MCP shim requires a positive port`);return wc(`localhost`,t)}let u=Dc(t(),n);if(u!==void 0)return wc(`localhost`,u);if(e.envAutoStart===`0`)throw Error(`Open Knowledge server is not running and OK_MCP_AUTOSTART=0 disables auto-start.`);F(e.lockDir)||I(e.lockDir,{recursive:!0});let d=N(e.lockDir,m),f=o(d),p,g,_=bt();try{try{p=i(_.command,[..._.prefixArgs,`start`],{detached:!0,stdio:[`ignore`,`ignore`,f],cwd:e.contentDir,env:{...process.env,OK_LOCK_KIND:`mcp-spawned`,ELECTRON_RUN_AS_NODE:`1`}}),p.on(`error`,e=>{g=e instanceof Error?e.message:String(e)}),p.unref()}catch(e){g=e instanceof Error?e.message:String(e)}}finally{try{s(f)}catch{}}let v=Date.now()+c;for(;Date.now()<v;){if(g){let e=a(d),t=e?` stderr:\n${e}`:``;throw Error(`spawn failed: ${g}${t}`)}await r(l);let e=Dc(t(),n);if(e!==void 0)return wc(`localhost`,e)}if(g){let e=a(d),t=e?` stderr:\n${e}`:``;throw Error(`spawn failed: ${g}${t}`)}throw Error(kc(c,a(d)))}function Pc(e,t){if(e.portOverride!==void 0)return Ec(t);let n=e.readLock??(()=>h(e.lockDir)),r=e.isAlive??y,i=Dc(n(),r);if(i!==void 0)return Tc(`localhost`,i)}async function Fc(e,t={}){let n=t.stderr??process.stderr,r=t.requestTimeoutMs??12e4,i=t.createStdioTransport?t.createStdioTransport(t.stdin,t.stdout):new Yo(t.stdin,t.stdout),a=t.createHttpTransport?t.createHttpTransport(new URL(e)):new bc(new URL(e),{fetch:xc(r),requestInit:{headers:{...x({kind:`mcp`,runtimeVersion:v}),...t.connectionId===void 0?{}:{[Ee]:t.connectionId}}}}),o=!1,s=async()=>{o||(o=!0,t.onclose?.(),await Promise.allSettled([i.close(),a.close()]))};i.onerror=e=>{n.write(`[mcp-shim] stdio error: ${e.message}\n`)},a.onerror=e=>{n.write(`[mcp-shim] HTTP transport error: ${e.message}\n`)},i.onclose=()=>{s()},a.onclose=()=>{s()};let c=Promise.resolve();i.onmessage=e=>{c=c.then(async()=>{try{await a.send(e)}catch(t){let r=Ac(e);if(r===void 0){n.write(`[mcp-shim] failed to forward stdio notification: ${t instanceof Error?t.message:String(t)}\n`);return}await i.send(Mc(r,t)).catch(e=>{n.write(`[mcp-shim] failed to write stdio error response: ${e instanceof Error?e.message:String(e)}\n`)})}}).catch(e=>{n.write(`[mcp-shim] unexpected stdio forwarding failure: ${e instanceof Error?e.message:String(e)}\n`)})},a.onmessage=e=>{let t=jc(e);t&&a.setProtocolVersion?.(t),i.send(e).catch(e=>{n.write(`[mcp-shim] failed to write stdio response: ${e instanceof Error?e.message:String(e)}\n`)})};try{await a.start(),await i.start()}catch(e){throw await s(),e}return{close:s}}async function Ic(e){let t=e.stderr??process.stderr,n=e.bridgeFn??Fc,r=await Nc(e),i=e.createConnectionId?.()??ln(),a=!1,o=(e.startKeepalive??Go)({connectionId:i,resolveWsUrl:async()=>Pc(e,r),log:e=>t.write(`[mcp-shim] keepalive: ${e}\n`)});t.write(`[mcp-shim] proxying stdio to ${r}\n`);let s;try{s=await n(r,{stderr:t,connectionId:i,onclose:()=>{a||(o.close(),process.exit(0))}})}catch(e){throw o.close(),e}let c=()=>{a=!0,o.close(),s.close().finally(()=>{process.exit(0)})};process.once(`SIGINT`,c),process.once(`SIGTERM`,c)}const Lc=nn(import.meta.url);function Rc(e){let t=P(e);for(;;){if(Me(t))return t;let n=jt(t);if(n===t)throw Error(`No Open Knowledge project found at or above ${e}. Pass an explicit \`cwd\` argument that points inside an OK project (a directory with a \`${ee}\`).`);t=n}}function zc(e){try{let t=new URL(e);return t.protocol===`file:`?nn(t):void 0}catch{return}}async function Bc(e){if(!e.getClientCapabilities()?.roots)return;let t;try{t=await e.listRoots()}catch(t){e.log?.(`listRoots fallback failed: ${t instanceof Error?t.message:String(t)}`);return}let n=t.roots??[];if(n.length!==1)return;let r=zc(n[0].uri);return r===void 0&&e.log?.(`single root URI not usable as fs path: ${n[0].uri}`),r}async function Vc(e,t){if(e!==void 0)return Rc(e);let n=await t();if(n!==void 0)return Rc(n);throw Error("`cwd` is required for tool calls against the global MCP server. Pass an absolute path inside an Open Knowledge project, or have the MCP client advertise a single root.")}async function Hc(e){let t=process.stderr,n=e.spawnTimeoutMs??Sc(process.env.OK_MCP_SPAWN_TIMEOUT_MS),r=e.envAutoStart??process.env.OK_MCP_AUTOSTART,i=yt({startupCwd:e.startupCwd,startupConfig:e.startupConfig}),a=new Be({name:$e,version:v},{instructions:Je({dir:`.`})});We(a);let o=ln(),s={current:{connectionId:o,displayName:o,colorSeed:o}},c=new Map,l=e=>{if(c.has(e))return;let n=Xe(e),r=s.current,i=Go({connectionId:o,displayName:r.displayName,clientName:r.clientInfo?.name??r.displayName,colorSeed:r.colorSeed,resolveWsUrl:async()=>Pc({lockDir:n,contentDir:e},``),log:n=>t.write(`[mcp] keepalive[${e}]: ${n}\n`)});c.set(e,i)},u=()=>Bc({getClientCapabilities:()=>a.server.getClientCapabilities(),listRoots:()=>a.server.listRoots(),log:e=>t.write(`[mcp] ${e}\n`)}),d=e=>Vc(e,u),f=async e=>{let t;if(e===void 0){let e=await u();if(e===void 0)return;t=Rc(e)}else t=Rc(e);let a=await i(t),o=await Nc({lockDir:Xe(t),contentDir:st(a,t),envAutoStart:r,...n===void 0?{}:{timeoutMs:n}});return l(t),o.replace(/\/mcp$/,``)};a.server.oninitialized=()=>{let e=a.server.getClientVersion(),t=Re(e?.name,o);s.current={connectionId:o,clientInfo:e?{name:t,version:e.version}:void 0,displayName:t,colorSeed:t}},tt(a,{serverUrl:f,resolveCwd:d,config:i,identityRef:s});let p=new Yo,m=!1,h,g,_=async()=>{if(m)return;m=!0,h?.stop(),g?.stop();for(let e of c.values())try{e.close()}catch(e){t.write(`[mcp] keepalive close error: ${e instanceof Error?e.message:String(e)}\n`)}c.clear();let e=await Promise.allSettled([a.close(),p.close()]);for(let n of e)if(n.status===`rejected`){let e=n.reason;t.write(`[mcp] shutdown close error: ${e instanceof Error?e.message:String(e)}\n`)}};await a.connect(p),t.write(`[mcp] global stdio server ready (per-call project routing)
63
63
  `);let y=!1,b=()=>{y||(y=!0,setTimeout(()=>{t.write(`[mcp] shutdown deadline (5s) reached — forcing exit(1)
64
64
  `),process.exit(1)},5e3).unref(),_().finally(()=>{process.exit(0)}))};if(process.once(`SIGINT`,b),process.once(`SIGTERM`,b),process.stdin.on(`end`,()=>{t.write(`[mcp] stdin end — host disconnected, shutting down
65
- `),b()}),process.stdin.on(`error`,e=>{t.write(`[mcp] stdin error (${e instanceof Error?e.message:String(e)}) — host disconnected, shutting down\n`),b()}),g=$o({getPpid:()=>process.ppid,onHostGone:e=>{t.write(`[mcp] ${e} — shutting down\n`),b()}}),es({log:e=>t.write(`${e}\n`),transport:p,process,stdin:process.stdin}),process.platform===`darwin`){let e=Qo(Lc,{realpathSync:Ht,statInoSync:e=>Wt(e).ino,log:e=>t.write(`${e}\n`)});if(e!==void 0){t.write(`[mcp] bundle identity anchor=${e.resolvedPath} inode=${e.inode} version=${v}\n`);let{resolvedPath:n,inode:r}=e;h=Zo({detect:()=>Xo({bundleAnchorPath:Lc,currentInode:r,platform:process.platform,realpath:Ht,statInode:e=>Wt(e).ino}),onReplaced:e=>{t.write(`[mcp] bundle replaced anchor=${n} bootInode=${e.currentInode} onDiskInode=${e.onDiskInode} version=${v} — exiting for host respawn\n`),b()},log:e=>t.write(`[mcp] ${e}\n`)})}}return{close:_}}function Uc(e){return new t(`mcp`).description(`Start MCP stdio server for project knowledge base`).option(`-p, --port <port>`,`Override per-call routing and proxy stdio to this HTTP MCP port (skips bundle proxy)`,void 0).option(`--no-bundle-proxy`,`Run the npm-fetched MCP server in-process instead of proxying to the macOS Desktop bundle (equivalent: OK_BUNDLE_PROXY=0)`).action(async t=>{try{let n=e(),r=process.cwd();if(t.port!==void 0){let e=Sc(process.env.OK_MCP_SPAWN_TIMEOUT_MS);await Ic({lockDir:``,contentDir:``,portOverride:t.port,envAutoStart:process.env.OK_MCP_AUTOSTART,timeoutMs:e});return}let i=t.bundleProxy===!1?[...process.argv,`--no-bundle-proxy`]:process.argv,a=Ho(process.env,i,process.platform);if(a.proxy){let e=Vo(process.platform,Yt(),{existsSync:F});if(e===null)Uo({stderr:process.stderr,mode:`fallback-absent`,bundlePath:null,reason:`no installed Open Knowledge.app bundle found`});else try{await Wo({bundlePath:e,argv:process.argv.slice(2),env:process.env,stderr:process.stderr});return}catch(t){Uo({stderr:process.stderr,mode:`fallback-exec-failed`,bundlePath:e,reason:t instanceof Error?t.message:String(t)})}}else{let e=a.suppressedBy===`env`?`suppressed-env`:a.suppressedBy===`flag`?`suppressed-flag`:a.suppressedBy===`self`?`suppressed-self`:`suppressed-platform`;Uo({stderr:process.stderr,mode:e,bundlePath:null,reason:null})}await Hc({startupCwd:r,startupConfig:n})}catch(e){process.stderr.write(`MCP server failed to start: ${e instanceof Error?e.message:String(e)}\n`),process.exitCode=1}})}function Wc(e){let t={...e};return delete t.ELECTRON_RUN_AS_NODE,t}function Gc(e=()=>Tt(wt())){return{detectBundlePath:()=>e().bundlePath??null,resolveBaseUrl:e=>Ge({lockDir:He(e)}).baseUrl,openTarget:e=>{A(`open`,[e],{detached:!0,stdio:`ignore`,env:Wc(process.env)}).unref()},log:e=>process.stdout.write(`${e}\n`),error:e=>process.stderr.write(`${e}\n`)}}function Kc(e,t,n){let r=P(t.project??process.cwd()),i=t.folder===!0||/\/+$/.test(e),a=e.replace(/\/+$/,``);if(!a)return n.error("Nothing to open: pass a doc path (e.g. `ok open specs/foo/SPEC`)."),1;if(a.startsWith(`/`)||a.includes(`\\`)||a.split(`/`).includes(`..`))return n.error(`Invalid name "${a}": must be a relative path with no '..' segments, leading '/', or backslashes.`),1;if(i){let e=n.resolveBaseUrl(r);if(!e)return n.error(`No Open Knowledge UI is running for ${r}. Folder preview requires a running UI — start one with \`ok ui\`, then retry.`),1;let t=`${e}/#/${Le(a)}`;return n.openTarget(t),n.log(`Opening folder ${a} in your browser: ${t}`),0}if(n.detectBundlePath()){let e=`openknowledge://open?project=${encodeURIComponent(r)}&doc=${encodeURIComponent(a)}`;return n.openTarget(e),n.log(`Opening ${a} in the Open Knowledge desktop app.`),0}let o=n.resolveBaseUrl(r);if(o){let e=`${o}/#/${qe(a)}`;return n.openTarget(e),n.log(`Opening ${a} in your browser: ${e}`),0}return n.error("No Open Knowledge desktop app found and no UI is running. Install OK Desktop, or start a UI with `ok ui`, then retry."),1}function qc(){return new t(`open`).description(`Open a doc in the OK Desktop app (folders open in the browser)`).argument(`<doc>`,`Extension-less doc path (e.g. specs/foo/SPEC), or a folder path with --folder`).option(`--folder`,`Treat <doc> as a folder and open the folder route in the browser`).option(`--project <dir>`,`Project root (defaults to the current directory)`).action((e,t)=>{process.exitCode=Kc(e,t,Gc())})}function Jc(e){return new t(`preview`).description(`Show what content the watcher will track (read-only)`).action(async()=>{let{previewContent:t,formatPreviewBlock:n}=await import(`./preview-DRATXrPN.mjs`),r=e(),i=process.cwd(),a=st(r,i),o;try{o=t({projectDir:i,contentDir:a})}catch(e){console.error(`Content preview failed: ${e instanceof Error?e.message:String(e)}`),process.exitCode=1;return}process.stdout.write(`${n(o,i)}\n`),o.totalCount===0&&o.warnings.length>0&&(process.exitCode=1)})}function Yc(e,t){e&&process.stdout.write(`${JSON.stringify(t)}\n`)}async function Xc(e,t,n=process.cwd()){let r=e.op??`sync`,i=h(He(n));if(i&&i.port>0){let t=`http://127.0.0.1:${i.port}/api/sync/trigger`;e.json||process.stderr.write(`Triggering ${r} via running server (port ${i.port})\n`);try{let n=await fetch(t,{method:`POST`,headers:{"Content-Type":`application/json`,...x({kind:`cli`,runtimeVersion:v})},body:JSON.stringify({op:r})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.title??e.error??e.message??`Server responded with ${n.status}`)}Yc(e.json,{type:`triggered`,op:r,port:i.port}),e.json||process.stderr.write(`✓ ${r} triggered\n`);return}catch(t){let n=t instanceof Error?t.message:String(t);e.json||process.stderr.write(`Server trigger failed (${n}), running directly\n`)}}e.json||process.stderr.write(`Running ${r} directly (no live server)\n`);let a=Te({baseDir:n});if(r===`sync`||r===`pull`){Yc(e.json,{type:`step`,step:`pull`});let t=await a.pull();Yc(e.json,{type:`pull`,summary:t.summary}),e.json||process.stderr.write(` pull: ${t.summary.changes} changes\n`)}(r===`sync`||r===`push`)&&(Yc(e.json,{type:`step`,step:`push`}),await a.push(),Yc(e.json,{type:`push`,ok:!0}),e.json||process.stderr.write(` push: ok
65
+ `),b()}),process.stdin.on(`error`,e=>{t.write(`[mcp] stdin error (${e instanceof Error?e.message:String(e)}) — host disconnected, shutting down\n`),b()}),g=$o({getPpid:()=>process.ppid,onHostGone:e=>{t.write(`[mcp] ${e} — shutting down\n`),b()}}),es({log:e=>t.write(`${e}\n`),transport:p,process,stdin:process.stdin}),process.platform===`darwin`){let e=Qo(Lc,{realpathSync:Ht,statInoSync:e=>Wt(e).ino,log:e=>t.write(`${e}\n`)});if(e!==void 0){t.write(`[mcp] bundle identity anchor=${e.resolvedPath} inode=${e.inode} version=${v}\n`);let{resolvedPath:n,inode:r}=e;h=Zo({detect:()=>Xo({bundleAnchorPath:Lc,currentInode:r,platform:process.platform,realpath:Ht,statInode:e=>Wt(e).ino}),onReplaced:e=>{t.write(`[mcp] bundle replaced anchor=${n} bootInode=${e.currentInode} onDiskInode=${e.onDiskInode} version=${v} — exiting for host respawn\n`),b()},log:e=>t.write(`[mcp] ${e}\n`)})}}return{close:_}}function Uc(e){return new t(`mcp`).description(`Start MCP stdio server for project knowledge base`).option(`-p, --port <port>`,`Override per-call routing and proxy stdio to this HTTP MCP port (skips bundle proxy)`,void 0).option(`--no-bundle-proxy`,`Run the npm-fetched MCP server in-process instead of proxying to the macOS Desktop bundle (equivalent: OK_BUNDLE_PROXY=0)`).action(async t=>{try{let n=e(),r=process.cwd();if(t.port!==void 0){let e=Sc(process.env.OK_MCP_SPAWN_TIMEOUT_MS);await Ic({lockDir:``,contentDir:``,portOverride:t.port,envAutoStart:process.env.OK_MCP_AUTOSTART,timeoutMs:e});return}let i=t.bundleProxy===!1?[...process.argv,`--no-bundle-proxy`]:process.argv,a=Ho(process.env,i,process.platform);if(a.proxy){let e=Vo(process.platform,Yt(),{existsSync:F});if(e===null)Uo({stderr:process.stderr,mode:`fallback-absent`,bundlePath:null,reason:`no installed Open Knowledge.app bundle found`});else try{await Wo({bundlePath:e,argv:process.argv.slice(2),env:process.env,stderr:process.stderr});return}catch(t){Uo({stderr:process.stderr,mode:`fallback-exec-failed`,bundlePath:e,reason:t instanceof Error?t.message:String(t)})}}else{let e=a.suppressedBy===`env`?`suppressed-env`:a.suppressedBy===`flag`?`suppressed-flag`:a.suppressedBy===`self`?`suppressed-self`:`suppressed-platform`;Uo({stderr:process.stderr,mode:e,bundlePath:null,reason:null})}await Hc({startupCwd:r,startupConfig:n})}catch(e){process.stderr.write(`MCP server failed to start: ${e instanceof Error?e.message:String(e)}\n`),process.exitCode=1}})}function Wc(e){let t={...e};return delete t.ELECTRON_RUN_AS_NODE,t}function Gc(e=()=>Tt(wt())){return{detectBundlePath:()=>e().bundlePath??null,resolveBaseUrl:e=>Ge({lockDir:He(e)}).baseUrl,openTarget:e=>{A(`open`,[e],{detached:!0,stdio:`ignore`,env:Wc(process.env)}).unref()},log:e=>process.stdout.write(`${e}\n`),error:e=>process.stderr.write(`${e}\n`)}}function Kc(e,t,n){let r=P(t.project??process.cwd()),i=t.folder===!0||/\/+$/.test(e),a=e.replace(/\/+$/,``);if(!a)return n.error("Nothing to open: pass a doc path (e.g. `ok open specs/foo/SPEC`)."),1;if(a.startsWith(`/`)||a.includes(`\\`)||a.split(`/`).includes(`..`))return n.error(`Invalid name "${a}": must be a relative path with no '..' segments, leading '/', or backslashes.`),1;if(i){let e=n.resolveBaseUrl(r);if(!e)return n.error(`No Open Knowledge UI is running for ${r}. Folder preview requires a running UI — start one with \`ok ui\`, then retry.`),1;let t=`${e}/#/${Le(a)}`;return n.openTarget(t),n.log(`Opening folder ${a} in your browser: ${t}`),0}if(n.detectBundlePath()){let e=`openknowledge://open?project=${encodeURIComponent(r)}&doc=${encodeURIComponent(a)}`;return n.openTarget(e),n.log(`Opening ${a} in the Open Knowledge desktop app.`),0}let o=n.resolveBaseUrl(r);if(o){let e=`${o}/#/${qe(a)}`;return n.openTarget(e),n.log(`Opening ${a} in your browser: ${e}`),0}return n.error("No Open Knowledge desktop app found and no UI is running. Install OK Desktop, or start a UI with `ok ui`, then retry."),1}function qc(){return new t(`open`).description(`Open a doc in the OK Desktop app (folders open in the browser)`).argument(`<doc>`,`Extension-less doc path (e.g. specs/foo/SPEC), or a folder path with --folder`).option(`--folder`,`Treat <doc> as a folder and open the folder route in the browser`).option(`--project <dir>`,`Project root (defaults to the current directory)`).action((e,t)=>{process.exitCode=Kc(e,t,Gc())})}function Jc(e){return new t(`preview`).description(`Show what content the watcher will track (read-only)`).action(async()=>{let{previewContent:t,formatPreviewBlock:n}=await import(`./preview-xUWmx13Q.mjs`),r=e(),i=process.cwd(),a=st(r,i),o;try{o=t({projectDir:i,contentDir:a})}catch(e){console.error(`Content preview failed: ${e instanceof Error?e.message:String(e)}`),process.exitCode=1;return}process.stdout.write(`${n(o,i)}\n`),o.totalCount===0&&o.warnings.length>0&&(process.exitCode=1)})}function Yc(e,t){e&&process.stdout.write(`${JSON.stringify(t)}\n`)}async function Xc(e,t,n=process.cwd()){let r=e.op??`sync`,i=h(He(n));if(i&&i.port>0){let t=`http://127.0.0.1:${i.port}/api/sync/trigger`;e.json||process.stderr.write(`Triggering ${r} via running server (port ${i.port})\n`);try{let n=await fetch(t,{method:`POST`,headers:{"Content-Type":`application/json`,...x({kind:`cli`,runtimeVersion:v})},body:JSON.stringify({op:r})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.title??e.error??e.message??`Server responded with ${n.status}`)}Yc(e.json,{type:`triggered`,op:r,port:i.port}),e.json||process.stderr.write(`✓ ${r} triggered\n`);return}catch(t){let n=t instanceof Error?t.message:String(t);e.json||process.stderr.write(`Server trigger failed (${n}), running directly\n`)}}e.json||process.stderr.write(`Running ${r} directly (no live server)\n`);let a=Te({baseDir:n});if(r===`sync`||r===`pull`){Yc(e.json,{type:`step`,step:`pull`});let t=await a.pull();Yc(e.json,{type:`pull`,summary:t.summary}),e.json||process.stderr.write(` pull: ${t.summary.changes} changes\n`)}(r===`sync`||r===`push`)&&(Yc(e.json,{type:`step`,step:`push`}),await a.push(),Yc(e.json,{type:`push`,ok:!0}),e.json||process.stderr.write(` push: ok
66
66
  `)),Yc(e.json,{type:`complete`,op:r}),e.json||process.stderr.write(`✓ ${r} complete\n`)}function Zc(e){return new t(`sync`).description(`Commit, pull, and push to the remote`).option(`--json`,`Output JSONL progress events`,!1).action(async t=>{try{await Xc({json:t.json,op:`sync`},e())}catch(e){let n=e instanceof Error?e.message:String(e);t.json?process.stdout.write(`${JSON.stringify({type:`error`,message:n})}\n`):process.stderr.write(`✗ sync failed: ${n}\n`),process.exit(1)}})}function Qc(e){return new t(`pull`).description(`Pull changes from the remote`).option(`--json`,`Output JSONL progress events`,!1).action(async t=>{try{await Xc({json:t.json,op:`pull`},e())}catch(e){let n=e instanceof Error?e.message:String(e);t.json?process.stdout.write(`${JSON.stringify({type:`error`,message:n})}\n`):process.stderr.write(`✗ pull failed: ${n}\n`),process.exit(1)}})}function $c(e){return new t(`push`).description(`Push commits to the remote`).option(`--json`,`Output JSONL progress events`,!1).action(async t=>{try{await Xc({json:t.json,op:`push`},e())}catch(e){let n=e instanceof Error?e.message:String(e);t.json?process.stdout.write(`${JSON.stringify({type:`error`,message:n})}\n`):process.stderr.write(`✗ push failed: ${n}\n`),process.exit(1)}})}function el(e){return typeof e==`string`&&Ne.includes(e)}async function tl(e={}){let t=P(e.cwd??process.cwd()),n=e.pack??`knowledge-base`;if(!nt[n])return{status:`failed`,message:`${Dt(`Error:`)} Unknown pack "${n}". Available: ${Ne.join(`, `)}`,exitCode:1};let r;try{r=await Ze({projectDir:t,rootDir:e.root,packId:n})}catch(e){return e instanceof Ke?{status:`prerequisite-missing`,message:`${Dt(`Error:`)} ${e.message}`,exitCode:1}:{status:`failed`,message:`${Dt(`Error:`)} ${e instanceof Error?e.message:String(e)}`,exitCode:1}}if(r.created.length===0){let e=nt[n].name;return{status:`no-op`,message:`${D(`Your ${e} pack is already seeded.`)}\n${E(`Nothing to do.`)}`,plan:r,exitCode:0}}if(e.dryRun)return{status:`dry-run`,message:`${k(`Plan (dry-run — no changes made):`)}\n\n${rl(r,t)}`,plan:r,exitCode:0};if(!e.yes&&!await il(`${k(`Plan:`)}\n\n${rl(r,t)}\n\n${k(`Apply?`)} ${E(`[Y/n] `)}`,e.confirmStream))return{status:`cancelled`,message:E(`Cancelled.`),plan:r,exitCode:0};let i=await rt(r,{projectDir:t,packId:n});if(i.errors.length>0){let e=i.errors.map(e=>` ${Dt(`✗`)} ${e.path}: ${e.error}`);return{status:`failed`,message:[`${O(`Applied`)} ${i.applied} entries, ${O(String(i.errors.length))} error(s):`,...e].join(`
67
67
  `),plan:r,exitCode:1}}let a=nt[n].name,o=i.packSkillsInstalled.length>0?`\n${E(`Installed the ${a} skill for: ${i.packSkillsInstalled.join(`, `)}`)}`:``;return{status:`applied`,message:`${D(`✓ Seeded ${a}`)} ${E(`(${i.applied} entries, ${i.durationMs}ms)`)}${o}`,plan:r,exitCode:0}}function nl(){let e=[k(`Available packs:`)];for(let t of Ne){let n=nt[t];e.push(` ${D(t)} ${E(`—`)} ${n.name}: ${n.description}`)}return e.join(`
68
68
  `)}function rl(e,t){let n=[],r=e.created.filter(e=>e.kind===`folder`),i=e.created.filter(e=>e.kind===`file`);if(r.length>0){n.push(k(`Folders to create:`));for(let e of r)n.push(` ${D(`+`)} ${T(Mt(t,P(t,e.path))||e.path)}${E(`/`)}`)}if(i.length>0){n.length>0&&n.push(``),n.push(k(`Files to create:`));for(let e of i)n.push(` ${D(`+`)} ${T(Mt(t,P(t,e.path))||e.path)}`)}if(e.skipped.length>0){n.length>0&&n.push(``),n.push(E(`Already present (skipped):`));for(let t of e.skipped)n.push(` ${E(`· ${t.path} (${t.reason})`)}`)}if(e.warnings.length>0){n.length>0&&n.push(``),n.push(O(`Warnings:`));for(let t of e.warnings)n.push(` ${O(`!`)} ${t}`)}return n.join(`
@@ -0,0 +1,2 @@
1
+ import"./server-lock-BpjJj3OD-2pOoEhSP.mjs";var e=`0.9.2-beta.9`;const t=`config.yml`,n=e;export{n,t};
2
+ //# sourceMappingURL=constants-DU4TbLA_.mjs.map
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{i as e,r as t,t as n}from"./gh-detect-BveVRAue.mjs";import{A as r,C as i,D as a,E as o,O as s,S as c,T as l,_ as u,b as d,d as f,g as p,h as m,i as h,j as g,k as _,o as v,r as y,s as b,t as x,w as S,x as C,y as w}from"./init-BjjtQpJ4.mjs";import{d as T,f as E,l as D,n as O,r as k,t as A,u as j}from"./src-B1QW6YWQ.mjs";import{n as M}from"./loader-BSyhsuGY.mjs";import{n as N}from"./preview-C6kOnHJr.mjs";import{n as P,t as F}from"./mcp-migrate-event-BF8ILHwp.mjs";export{a as ALL_EDITOR_IDS,s as EDITOR_LABELS,_ as EDITOR_TARGETS,x as LAUNCH_CONFIG_NAME,y as LAUNCH_UI_CHAIN_SENTINEL,h as LAUNCH_UI_CHAIN_V1,d as addOkPathsToGitExclude,r as buildManagedServerEntry,F as buildMcpConfigMigrateEvent,v as classifyExistingMcpEntry,t as createTokenStore,n as detectGh,b as detectInstalledEditors,C as formatTrackedRemediation,c as getExcludedOkPaths,i as getOkArtifactPaths,g as isEntryUpToDate,M as loadConfig,e as makeLazyProbeTokenStore,D as parseGitHubBlobUrl,j as parseGitHubShareUrl,T as parseGitHubTreeUrl,E as parseGitUrl,N as previewContent,S as probeTrackedOkPaths,f as readExistingMcpEntry,l as readSharingMode,o as removeOkPathsFromGitExclude,w as resolveProjectRoot,k as runStop,m as scaffoldLaunchJson,P as truncatePriorEntry,O as validateLocalFolderForShare,p as writeEditorMcpConfig,A as writeProjectAiIntegrations,u as writeUserMcpConfigs};
1
+ import{i as e,r as t,t as n}from"./gh-detect-BveVRAue.mjs";import{A as r,C as i,D as a,E as o,O as s,S as c,T as l,_ as u,b as d,d as f,g as p,h as m,i as h,j as g,k as _,o as v,r as y,s as b,t as x,w as S,x as C,y as w}from"./init-Ctu92Awt.mjs";import{d as T,f as E,l as D,n as O,r as k,t as A,u as j}from"./src-jN1tBoyd.mjs";import{n as M}from"./loader-DLF6I7F7.mjs";import{n as N}from"./preview-BiAC5DG4.mjs";import{n as P,t as F}from"./mcp-migrate-event-BF8ILHwp.mjs";export{a as ALL_EDITOR_IDS,s as EDITOR_LABELS,_ as EDITOR_TARGETS,x as LAUNCH_CONFIG_NAME,y as LAUNCH_UI_CHAIN_SENTINEL,h as LAUNCH_UI_CHAIN_V1,d as addOkPathsToGitExclude,r as buildManagedServerEntry,F as buildMcpConfigMigrateEvent,v as classifyExistingMcpEntry,t as createTokenStore,n as detectGh,b as detectInstalledEditors,C as formatTrackedRemediation,c as getExcludedOkPaths,i as getOkArtifactPaths,g as isEntryUpToDate,M as loadConfig,e as makeLazyProbeTokenStore,D as parseGitHubBlobUrl,j as parseGitHubShareUrl,T as parseGitHubTreeUrl,E as parseGitUrl,N as previewContent,S as probeTrackedOkPaths,f as readExistingMcpEntry,l as readSharingMode,o as removeOkPathsFromGitExclude,w as resolveProjectRoot,k as runStop,m as scaffoldLaunchJson,P as truncatePriorEntry,O as validateLocalFolderForShare,p as writeEditorMcpConfig,A as writeProjectAiIntegrations,u as writeUserMcpConfigs};
@@ -0,0 +1 @@
1
+ import{m as e}from"./init-Ctu92Awt.mjs";export{e as runInit};
@@ -1,4 +1,4 @@
1
- import{i as e,o as t,t as n}from"./chunk-FK9Q3tQk.mjs";import{r,t as i}from"./esm-CEs3LWY3.mjs";import{Ct as a,It as o,Tr as s,dn as c,v as l,wt as u,y as d}from"./server-lock-BpjJj3OD-2pOoEhSP.mjs";import{$t as f,B as p,Dn as m,Fi as h,In as g,Nn as _,Oi as v,On as y,Sn as b,j as x,ji as S,kn as C,qt as w,vi as ee}from"./dist-sld-_d9T.mjs";import"./constants-Dz5iTLUD.mjs";import{t as T}from"./is-object-C-4FJ0rP.mjs";import{i as E,o as D,r as O,s as k,t as A}from"./colors-BtKMHmBX.mjs";import{t as te}from"./preview-C6kOnHJr.mjs";import{n as ne,t as re}from"./write-project-skill-ppRYJ9T2.mjs";import{execFileSync as ie}from"node:child_process";import ae,{basename as oe,dirname as j,isAbsolute as se,join as M,posix as N,relative as P,resolve as F,sep as I,win32 as ce}from"node:path";import{existsSync as L,mkdirSync as le,readFileSync as R,realpathSync as ue,writeFileSync as de}from"node:fs";import z from"node:process";import{homedir as B}from"node:os";import{AsyncLocalStorage as fe,AsyncResource as pe}from"node:async_hooks";import{stripVTControlCharacters as me,styleText as V}from"node:util";import*as he from"node:readline";import{randomUUID as ge}from"node:crypto";import{createServer as _e,request as ve}from"node:http";import{connect as ye}from"node:net";function be(){return z.platform.startsWith(`win`)?!!z.env.CI||!!z.env.WT_SESSION||!!z.env.TERMINUS_SUBLIME||z.env.ConEmuTask===`{cmd::Cmder}`||z.env.TERM_PROGRAM===`Terminus-Sublime`||z.env.TERM_PROGRAM===`vscode`||z.env.TERM===`xterm-256color`||z.env.TERM===`alacritty`||z.env.TERMINAL_EMULATOR===`JetBrains-JediTerm`:z.env.TERM!==`linux`}const xe={circleQuestionMark:`(?)`,questionMarkPrefix:`(?)`,square:`█`,squareDarkShade:`▓`,squareMediumShade:`▒`,squareLightShade:`░`,squareTop:`▀`,squareBottom:`▄`,squareLeft:`▌`,squareRight:`▐`,squareCenter:`■`,bullet:`●`,dot:`․`,ellipsis:`…`,pointerSmall:`›`,triangleUp:`▲`,triangleUpSmall:`▴`,triangleDown:`▼`,triangleDownSmall:`▾`,triangleLeftSmall:`◂`,triangleRightSmall:`▸`,home:`⌂`,heart:`♥`,musicNote:`♪`,musicNoteBeamed:`♫`,arrowUp:`↑`,arrowDown:`↓`,arrowLeft:`←`,arrowRight:`→`,arrowLeftRight:`↔`,arrowUpDown:`↕`,almostEqual:`≈`,notEqual:`≠`,lessOrEqual:`≤`,greaterOrEqual:`≥`,identical:`≡`,infinity:`∞`,subscriptZero:`₀`,subscriptOne:`₁`,subscriptTwo:`₂`,subscriptThree:`₃`,subscriptFour:`₄`,subscriptFive:`₅`,subscriptSix:`₆`,subscriptSeven:`₇`,subscriptEight:`₈`,subscriptNine:`₉`,oneHalf:`½`,oneThird:`⅓`,oneQuarter:`¼`,oneFifth:`⅕`,oneSixth:`⅙`,oneEighth:`⅛`,twoThirds:`⅔`,twoFifths:`⅖`,threeQuarters:`¾`,threeFifths:`⅗`,threeEighths:`⅜`,fourFifths:`⅘`,fiveSixths:`⅚`,fiveEighths:`⅝`,sevenEighths:`⅞`,line:`─`,lineBold:`━`,lineDouble:`═`,lineDashed0:`┄`,lineDashed1:`┅`,lineDashed2:`┈`,lineDashed3:`┉`,lineDashed4:`╌`,lineDashed5:`╍`,lineDashed6:`╴`,lineDashed7:`╶`,lineDashed8:`╸`,lineDashed9:`╺`,lineDashed10:`╼`,lineDashed11:`╾`,lineDashed12:`−`,lineDashed13:`–`,lineDashed14:`‐`,lineDashed15:`⁃`,lineVertical:`│`,lineVerticalBold:`┃`,lineVerticalDouble:`║`,lineVerticalDashed0:`┆`,lineVerticalDashed1:`┇`,lineVerticalDashed2:`┊`,lineVerticalDashed3:`┋`,lineVerticalDashed4:`╎`,lineVerticalDashed5:`╏`,lineVerticalDashed6:`╵`,lineVerticalDashed7:`╷`,lineVerticalDashed8:`╹`,lineVerticalDashed9:`╻`,lineVerticalDashed10:`╽`,lineVerticalDashed11:`╿`,lineDownLeft:`┐`,lineDownLeftArc:`╮`,lineDownBoldLeftBold:`┓`,lineDownBoldLeft:`┒`,lineDownLeftBold:`┑`,lineDownDoubleLeftDouble:`╗`,lineDownDoubleLeft:`╖`,lineDownLeftDouble:`╕`,lineDownRight:`┌`,lineDownRightArc:`╭`,lineDownBoldRightBold:`┏`,lineDownBoldRight:`┎`,lineDownRightBold:`┍`,lineDownDoubleRightDouble:`╔`,lineDownDoubleRight:`╓`,lineDownRightDouble:`╒`,lineUpLeft:`┘`,lineUpLeftArc:`╯`,lineUpBoldLeftBold:`┛`,lineUpBoldLeft:`┚`,lineUpLeftBold:`┙`,lineUpDoubleLeftDouble:`╝`,lineUpDoubleLeft:`╜`,lineUpLeftDouble:`╛`,lineUpRight:`└`,lineUpRightArc:`╰`,lineUpBoldRightBold:`┗`,lineUpBoldRight:`┖`,lineUpRightBold:`┕`,lineUpDoubleRightDouble:`╚`,lineUpDoubleRight:`╙`,lineUpRightDouble:`╘`,lineUpDownLeft:`┤`,lineUpBoldDownBoldLeftBold:`┫`,lineUpBoldDownBoldLeft:`┨`,lineUpDownLeftBold:`┥`,lineUpBoldDownLeftBold:`┩`,lineUpDownBoldLeftBold:`┪`,lineUpDownBoldLeft:`┧`,lineUpBoldDownLeft:`┦`,lineUpDoubleDownDoubleLeftDouble:`╣`,lineUpDoubleDownDoubleLeft:`╢`,lineUpDownLeftDouble:`╡`,lineUpDownRight:`├`,lineUpBoldDownBoldRightBold:`┣`,lineUpBoldDownBoldRight:`┠`,lineUpDownRightBold:`┝`,lineUpBoldDownRightBold:`┡`,lineUpDownBoldRightBold:`┢`,lineUpDownBoldRight:`┟`,lineUpBoldDownRight:`┞`,lineUpDoubleDownDoubleRightDouble:`╠`,lineUpDoubleDownDoubleRight:`╟`,lineUpDownRightDouble:`╞`,lineDownLeftRight:`┬`,lineDownBoldLeftBoldRightBold:`┳`,lineDownLeftBoldRightBold:`┯`,lineDownBoldLeftRight:`┰`,lineDownBoldLeftBoldRight:`┱`,lineDownBoldLeftRightBold:`┲`,lineDownLeftRightBold:`┮`,lineDownLeftBoldRight:`┭`,lineDownDoubleLeftDoubleRightDouble:`╦`,lineDownDoubleLeftRight:`╥`,lineDownLeftDoubleRightDouble:`╤`,lineUpLeftRight:`┴`,lineUpBoldLeftBoldRightBold:`┻`,lineUpLeftBoldRightBold:`┷`,lineUpBoldLeftRight:`┸`,lineUpBoldLeftBoldRight:`┹`,lineUpBoldLeftRightBold:`┺`,lineUpLeftRightBold:`┶`,lineUpLeftBoldRight:`┵`,lineUpDoubleLeftDoubleRightDouble:`╩`,lineUpDoubleLeftRight:`╨`,lineUpLeftDoubleRightDouble:`╧`,lineUpDownLeftRight:`┼`,lineUpBoldDownBoldLeftBoldRightBold:`╋`,lineUpDownBoldLeftBoldRightBold:`╈`,lineUpBoldDownLeftBoldRightBold:`╇`,lineUpBoldDownBoldLeftRightBold:`╊`,lineUpBoldDownBoldLeftBoldRight:`╉`,lineUpBoldDownLeftRight:`╀`,lineUpDownBoldLeftRight:`╁`,lineUpDownLeftBoldRight:`┽`,lineUpDownLeftRightBold:`┾`,lineUpBoldDownBoldLeftRight:`╂`,lineUpDownLeftBoldRightBold:`┿`,lineUpBoldDownLeftBoldRight:`╃`,lineUpBoldDownLeftRightBold:`╄`,lineUpDownBoldLeftBoldRight:`╅`,lineUpDownBoldLeftRightBold:`╆`,lineUpDoubleDownDoubleLeftDoubleRightDouble:`╬`,lineUpDoubleDownDoubleLeftRight:`╫`,lineUpDownLeftDoubleRightDouble:`╪`,lineCross:`╳`,lineBackslash:`╲`,lineSlash:`╱`},Se={tick:`✔`,info:`ℹ`,warning:`⚠`,cross:`✘`,squareSmall:`◻`,squareSmallFilled:`◼`,circle:`◯`,circleFilled:`◉`,circleDotted:`◌`,circleDouble:`◎`,circleCircle:`ⓞ`,circleCross:`ⓧ`,circlePipe:`Ⓘ`,radioOn:`◉`,radioOff:`◯`,checkboxOn:`☒`,checkboxOff:`☐`,checkboxCircleOn:`ⓧ`,checkboxCircleOff:`Ⓘ`,pointer:`❯`,triangleUpOutline:`△`,triangleLeft:`◀`,triangleRight:`▶`,lozenge:`◆`,lozengeOutline:`◇`,hamburger:`☰`,smiley:`㋡`,mustache:`෴`,star:`★`,play:`▶`,nodejs:`⬢`,oneSeventh:`⅐`,oneNinth:`⅑`,oneTenth:`⅒`},Ce={tick:`√`,info:`i`,warning:`‼`,cross:`×`,squareSmall:`□`,squareSmallFilled:`■`,circle:`( )`,circleFilled:`(*)`,circleDotted:`( )`,circleDouble:`( )`,circleCircle:`(○)`,circleCross:`(×)`,circlePipe:`(│)`,radioOn:`(*)`,radioOff:`( )`,checkboxOn:`[×]`,checkboxOff:`[ ]`,checkboxCircleOn:`(×)`,checkboxCircleOff:`( )`,pointer:`>`,triangleUpOutline:`∆`,triangleLeft:`◄`,triangleRight:`►`,lozenge:`♦`,lozengeOutline:`◊`,hamburger:`≡`,smiley:`☺`,mustache:`┌─┐`,star:`✶`,play:`►`,nodejs:`♦`,oneSeventh:`1/7`,oneNinth:`1/9`,oneTenth:`1/10`},we={...xe,...Se},Te={...xe,...Ce},H=be()?we:Te;Object.entries(Se);var Ee=n(((t,n)=>{n.exports=i;function r(t){let n={defaultWidth:0,output:process.stdout,tty:e(`tty`)};return t?(Object.keys(n).forEach(function(e){t[e]||(t[e]=n[e])}),t):n}function i(e){let t=r(e);if(t.output.getWindowSize)return t.output.getWindowSize()[0]||t.defaultWidth;if(t.tty.getWindowSize)return t.tty.getWindowSize()[1]||t.defaultWidth;if(t.output.columns)return t.output.columns;if(process.env.CLI_WIDTH){let e=parseInt(process.env.CLI_WIDTH,10);if(!isNaN(e)&&e!==0)return e}return t.defaultWidth}}));const De=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return t=>{let n=0;for(e.lastIndex=0;e.test(t);)n+=1;return t.length-n}})(),Oe=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,ke=e=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141,Ae=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,je=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Me=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,Ne=/\t{1,1000}/y,Pe=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy,Fe=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Ie=/\p{M}+/gu,Le={limit:1/0,ellipsis:``},Re=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?Re(i,Le,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[Fe,l],[Ae,0],[je,o],[Ne,s],[Pe,c],[Me,u]],f=0,p=0,m=e.length,h=0,g=!1,_=m,v=Math.max(0,r-a),y=0,b=0,x=0,S=0;outer:for(;;){if(b>y||p>=m&&p>f){let t=e.slice(y,b)||e.slice(f,p);h=0;for(let e of t.replaceAll(Ie,``)){let t=e.codePointAt(0)||0;if(S=Oe(t)?2:ke(t)?u:l,x+S>v&&(_=Math.min(_,Math.max(y,f)+h)),x+S>r){g=!0;break outer}h+=e.length,x+=S}y=b=0}if(p>=m)break outer;for(let t=0,n=d.length;t<n;t++){let[n,i]=d[t];if(n.lastIndex=p,n.test(e)){if(h=n===Me?De(e.slice(p,n.lastIndex)):n===Pe?1:n.lastIndex-p,S=h*i,x+S>v&&(_=Math.min(_,p+Math.floor((v-x)/i))),x+S>r){g=!0;break outer}x+=S,y=f,b=p,p=f=n.lastIndex;continue outer}}p+=1}return{width:g?v:x,index:g?_:m,truncated:g,ellipsed:g&&r>=a}},ze={limit:1/0,ellipsis:``,ellipsisWidth:0},U=(e,t={})=>Re(e,ze,t).width,Be=`]8;;`,Ve=RegExp(`(?:\\[(?<code>\\d+)m|\\${Be}(?<uri>.*))`,`y`),He=e=>{if(e>=30&&e<=37||e>=90&&e<=97)return 39;if(e>=40&&e<=47||e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0},Ue=e=>`[${e}m`,We=e=>`${Be}${e}`,Ge=(e,t,n)=>{let r=t[Symbol.iterator](),i=!1,a=!1,o=e.at(-1),s=o===void 0?0:U(o),c=r.next(),l=r.next(),u=0;for(;!c.done;){let o=c.value,d=U(o);s+d<=n?e[e.length-1]+=o:(e.push(o),s=0),(o===`\x1B`||o===`›`)&&(i=!0,a=t.startsWith(Be,u+1)),i?a?o===`\x07`&&(i=!1,a=!1):o===`m`&&(i=!1):(s+=d,s===n&&!l.done&&(e.push(``),s=0)),c=l,l=r.next(),u+=o.length}o=e.at(-1),!s&&o!==void 0&&o.length&&e.length>1&&(e[e.length-2]+=e.pop())},Ke=e=>{let t=e.split(` `),n=t.length;for(;n&&!U(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},qe=(e,t,n={})=>{if(n.trim!==!1&&e.trim()===``)return``;let r=``,i,a,o=e.split(` `),s=[``],c=0;for(let e=0;e<o.length;e++){let r=o[e];if(n.trim!==!1){let e=s.at(-1)??``,t=e.trimStart();e.length!==t.length&&(s[s.length-1]=t,c=U(t))}e!==0&&(c>=t&&(n.wordWrap===!1||n.trim===!1)&&(s.push(``),c=0),(c||n.trim===!1)&&(s[s.length-1]+=` `,c++));let i=U(r);if(n.hard&&i>t){let e=t-c,n=1+Math.floor((i-e-1)/t);Math.floor((i-1)/t)<n&&s.push(``),Ge(s,r,t),c=U(s.at(-1)??``);continue}if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){Ge(s,r,t),c=U(s.at(-1)??``);continue}s.push(``),c=0}if(c+i>t&&n.wordWrap===!1){Ge(s,r,t),c=U(s.at(-1)??``);continue}s[s.length-1]+=r,c+=i}n.trim!==!1&&(s=s.map(e=>Ke(e)));let l=s.join(`
1
+ import{i as e,o as t,t as n}from"./chunk-FK9Q3tQk.mjs";import{r,t as i}from"./esm-CEs3LWY3.mjs";import{Ct as a,It as o,Tr as s,dn as c,v as l,wt as u,y as d}from"./server-lock-BpjJj3OD-2pOoEhSP.mjs";import{$t as f,B as p,Dn as m,Fi as h,In as g,Nn as _,Oi as v,On as y,Sn as b,j as x,ji as S,kn as C,qt as w,vi as ee}from"./dist-sld-_d9T.mjs";import"./constants-DU4TbLA_.mjs";import{t as T}from"./is-object-C-4FJ0rP.mjs";import{i as E,o as D,r as O,s as k,t as A}from"./colors-BtKMHmBX.mjs";import{t as te}from"./preview-BiAC5DG4.mjs";import{n as ne,t as re}from"./write-project-skill-ppRYJ9T2.mjs";import{execFileSync as ie}from"node:child_process";import ae,{basename as oe,dirname as j,isAbsolute as se,join as M,posix as N,relative as P,resolve as F,sep as I,win32 as ce}from"node:path";import{existsSync as L,mkdirSync as le,readFileSync as R,realpathSync as ue,writeFileSync as de}from"node:fs";import z from"node:process";import{homedir as B}from"node:os";import{AsyncLocalStorage as fe,AsyncResource as pe}from"node:async_hooks";import{stripVTControlCharacters as me,styleText as V}from"node:util";import*as he from"node:readline";import{randomUUID as ge}from"node:crypto";import{createServer as _e,request as ve}from"node:http";import{connect as ye}from"node:net";function be(){return z.platform.startsWith(`win`)?!!z.env.CI||!!z.env.WT_SESSION||!!z.env.TERMINUS_SUBLIME||z.env.ConEmuTask===`{cmd::Cmder}`||z.env.TERM_PROGRAM===`Terminus-Sublime`||z.env.TERM_PROGRAM===`vscode`||z.env.TERM===`xterm-256color`||z.env.TERM===`alacritty`||z.env.TERMINAL_EMULATOR===`JetBrains-JediTerm`:z.env.TERM!==`linux`}const xe={circleQuestionMark:`(?)`,questionMarkPrefix:`(?)`,square:`█`,squareDarkShade:`▓`,squareMediumShade:`▒`,squareLightShade:`░`,squareTop:`▀`,squareBottom:`▄`,squareLeft:`▌`,squareRight:`▐`,squareCenter:`■`,bullet:`●`,dot:`․`,ellipsis:`…`,pointerSmall:`›`,triangleUp:`▲`,triangleUpSmall:`▴`,triangleDown:`▼`,triangleDownSmall:`▾`,triangleLeftSmall:`◂`,triangleRightSmall:`▸`,home:`⌂`,heart:`♥`,musicNote:`♪`,musicNoteBeamed:`♫`,arrowUp:`↑`,arrowDown:`↓`,arrowLeft:`←`,arrowRight:`→`,arrowLeftRight:`↔`,arrowUpDown:`↕`,almostEqual:`≈`,notEqual:`≠`,lessOrEqual:`≤`,greaterOrEqual:`≥`,identical:`≡`,infinity:`∞`,subscriptZero:`₀`,subscriptOne:`₁`,subscriptTwo:`₂`,subscriptThree:`₃`,subscriptFour:`₄`,subscriptFive:`₅`,subscriptSix:`₆`,subscriptSeven:`₇`,subscriptEight:`₈`,subscriptNine:`₉`,oneHalf:`½`,oneThird:`⅓`,oneQuarter:`¼`,oneFifth:`⅕`,oneSixth:`⅙`,oneEighth:`⅛`,twoThirds:`⅔`,twoFifths:`⅖`,threeQuarters:`¾`,threeFifths:`⅗`,threeEighths:`⅜`,fourFifths:`⅘`,fiveSixths:`⅚`,fiveEighths:`⅝`,sevenEighths:`⅞`,line:`─`,lineBold:`━`,lineDouble:`═`,lineDashed0:`┄`,lineDashed1:`┅`,lineDashed2:`┈`,lineDashed3:`┉`,lineDashed4:`╌`,lineDashed5:`╍`,lineDashed6:`╴`,lineDashed7:`╶`,lineDashed8:`╸`,lineDashed9:`╺`,lineDashed10:`╼`,lineDashed11:`╾`,lineDashed12:`−`,lineDashed13:`–`,lineDashed14:`‐`,lineDashed15:`⁃`,lineVertical:`│`,lineVerticalBold:`┃`,lineVerticalDouble:`║`,lineVerticalDashed0:`┆`,lineVerticalDashed1:`┇`,lineVerticalDashed2:`┊`,lineVerticalDashed3:`┋`,lineVerticalDashed4:`╎`,lineVerticalDashed5:`╏`,lineVerticalDashed6:`╵`,lineVerticalDashed7:`╷`,lineVerticalDashed8:`╹`,lineVerticalDashed9:`╻`,lineVerticalDashed10:`╽`,lineVerticalDashed11:`╿`,lineDownLeft:`┐`,lineDownLeftArc:`╮`,lineDownBoldLeftBold:`┓`,lineDownBoldLeft:`┒`,lineDownLeftBold:`┑`,lineDownDoubleLeftDouble:`╗`,lineDownDoubleLeft:`╖`,lineDownLeftDouble:`╕`,lineDownRight:`┌`,lineDownRightArc:`╭`,lineDownBoldRightBold:`┏`,lineDownBoldRight:`┎`,lineDownRightBold:`┍`,lineDownDoubleRightDouble:`╔`,lineDownDoubleRight:`╓`,lineDownRightDouble:`╒`,lineUpLeft:`┘`,lineUpLeftArc:`╯`,lineUpBoldLeftBold:`┛`,lineUpBoldLeft:`┚`,lineUpLeftBold:`┙`,lineUpDoubleLeftDouble:`╝`,lineUpDoubleLeft:`╜`,lineUpLeftDouble:`╛`,lineUpRight:`└`,lineUpRightArc:`╰`,lineUpBoldRightBold:`┗`,lineUpBoldRight:`┖`,lineUpRightBold:`┕`,lineUpDoubleRightDouble:`╚`,lineUpDoubleRight:`╙`,lineUpRightDouble:`╘`,lineUpDownLeft:`┤`,lineUpBoldDownBoldLeftBold:`┫`,lineUpBoldDownBoldLeft:`┨`,lineUpDownLeftBold:`┥`,lineUpBoldDownLeftBold:`┩`,lineUpDownBoldLeftBold:`┪`,lineUpDownBoldLeft:`┧`,lineUpBoldDownLeft:`┦`,lineUpDoubleDownDoubleLeftDouble:`╣`,lineUpDoubleDownDoubleLeft:`╢`,lineUpDownLeftDouble:`╡`,lineUpDownRight:`├`,lineUpBoldDownBoldRightBold:`┣`,lineUpBoldDownBoldRight:`┠`,lineUpDownRightBold:`┝`,lineUpBoldDownRightBold:`┡`,lineUpDownBoldRightBold:`┢`,lineUpDownBoldRight:`┟`,lineUpBoldDownRight:`┞`,lineUpDoubleDownDoubleRightDouble:`╠`,lineUpDoubleDownDoubleRight:`╟`,lineUpDownRightDouble:`╞`,lineDownLeftRight:`┬`,lineDownBoldLeftBoldRightBold:`┳`,lineDownLeftBoldRightBold:`┯`,lineDownBoldLeftRight:`┰`,lineDownBoldLeftBoldRight:`┱`,lineDownBoldLeftRightBold:`┲`,lineDownLeftRightBold:`┮`,lineDownLeftBoldRight:`┭`,lineDownDoubleLeftDoubleRightDouble:`╦`,lineDownDoubleLeftRight:`╥`,lineDownLeftDoubleRightDouble:`╤`,lineUpLeftRight:`┴`,lineUpBoldLeftBoldRightBold:`┻`,lineUpLeftBoldRightBold:`┷`,lineUpBoldLeftRight:`┸`,lineUpBoldLeftBoldRight:`┹`,lineUpBoldLeftRightBold:`┺`,lineUpLeftRightBold:`┶`,lineUpLeftBoldRight:`┵`,lineUpDoubleLeftDoubleRightDouble:`╩`,lineUpDoubleLeftRight:`╨`,lineUpLeftDoubleRightDouble:`╧`,lineUpDownLeftRight:`┼`,lineUpBoldDownBoldLeftBoldRightBold:`╋`,lineUpDownBoldLeftBoldRightBold:`╈`,lineUpBoldDownLeftBoldRightBold:`╇`,lineUpBoldDownBoldLeftRightBold:`╊`,lineUpBoldDownBoldLeftBoldRight:`╉`,lineUpBoldDownLeftRight:`╀`,lineUpDownBoldLeftRight:`╁`,lineUpDownLeftBoldRight:`┽`,lineUpDownLeftRightBold:`┾`,lineUpBoldDownBoldLeftRight:`╂`,lineUpDownLeftBoldRightBold:`┿`,lineUpBoldDownLeftBoldRight:`╃`,lineUpBoldDownLeftRightBold:`╄`,lineUpDownBoldLeftBoldRight:`╅`,lineUpDownBoldLeftRightBold:`╆`,lineUpDoubleDownDoubleLeftDoubleRightDouble:`╬`,lineUpDoubleDownDoubleLeftRight:`╫`,lineUpDownLeftDoubleRightDouble:`╪`,lineCross:`╳`,lineBackslash:`╲`,lineSlash:`╱`},Se={tick:`✔`,info:`ℹ`,warning:`⚠`,cross:`✘`,squareSmall:`◻`,squareSmallFilled:`◼`,circle:`◯`,circleFilled:`◉`,circleDotted:`◌`,circleDouble:`◎`,circleCircle:`ⓞ`,circleCross:`ⓧ`,circlePipe:`Ⓘ`,radioOn:`◉`,radioOff:`◯`,checkboxOn:`☒`,checkboxOff:`☐`,checkboxCircleOn:`ⓧ`,checkboxCircleOff:`Ⓘ`,pointer:`❯`,triangleUpOutline:`△`,triangleLeft:`◀`,triangleRight:`▶`,lozenge:`◆`,lozengeOutline:`◇`,hamburger:`☰`,smiley:`㋡`,mustache:`෴`,star:`★`,play:`▶`,nodejs:`⬢`,oneSeventh:`⅐`,oneNinth:`⅑`,oneTenth:`⅒`},Ce={tick:`√`,info:`i`,warning:`‼`,cross:`×`,squareSmall:`□`,squareSmallFilled:`■`,circle:`( )`,circleFilled:`(*)`,circleDotted:`( )`,circleDouble:`( )`,circleCircle:`(○)`,circleCross:`(×)`,circlePipe:`(│)`,radioOn:`(*)`,radioOff:`( )`,checkboxOn:`[×]`,checkboxOff:`[ ]`,checkboxCircleOn:`(×)`,checkboxCircleOff:`( )`,pointer:`>`,triangleUpOutline:`∆`,triangleLeft:`◄`,triangleRight:`►`,lozenge:`♦`,lozengeOutline:`◊`,hamburger:`≡`,smiley:`☺`,mustache:`┌─┐`,star:`✶`,play:`►`,nodejs:`♦`,oneSeventh:`1/7`,oneNinth:`1/9`,oneTenth:`1/10`},we={...xe,...Se},Te={...xe,...Ce},H=be()?we:Te;Object.entries(Se);var Ee=n(((t,n)=>{n.exports=i;function r(t){let n={defaultWidth:0,output:process.stdout,tty:e(`tty`)};return t?(Object.keys(n).forEach(function(e){t[e]||(t[e]=n[e])}),t):n}function i(e){let t=r(e);if(t.output.getWindowSize)return t.output.getWindowSize()[0]||t.defaultWidth;if(t.tty.getWindowSize)return t.tty.getWindowSize()[1]||t.defaultWidth;if(t.output.columns)return t.output.columns;if(process.env.CLI_WIDTH){let e=parseInt(process.env.CLI_WIDTH,10);if(!isNaN(e)&&e!==0)return e}return t.defaultWidth}}));const De=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return t=>{let n=0;for(e.lastIndex=0;e.test(t);)n+=1;return t.length-n}})(),Oe=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,ke=e=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141,Ae=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,je=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Me=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,Ne=/\t{1,1000}/y,Pe=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy,Fe=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Ie=/\p{M}+/gu,Le={limit:1/0,ellipsis:``},Re=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?Re(i,Le,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[Fe,l],[Ae,0],[je,o],[Ne,s],[Pe,c],[Me,u]],f=0,p=0,m=e.length,h=0,g=!1,_=m,v=Math.max(0,r-a),y=0,b=0,x=0,S=0;outer:for(;;){if(b>y||p>=m&&p>f){let t=e.slice(y,b)||e.slice(f,p);h=0;for(let e of t.replaceAll(Ie,``)){let t=e.codePointAt(0)||0;if(S=Oe(t)?2:ke(t)?u:l,x+S>v&&(_=Math.min(_,Math.max(y,f)+h)),x+S>r){g=!0;break outer}h+=e.length,x+=S}y=b=0}if(p>=m)break outer;for(let t=0,n=d.length;t<n;t++){let[n,i]=d[t];if(n.lastIndex=p,n.test(e)){if(h=n===Me?De(e.slice(p,n.lastIndex)):n===Pe?1:n.lastIndex-p,S=h*i,x+S>v&&(_=Math.min(_,p+Math.floor((v-x)/i))),x+S>r){g=!0;break outer}x+=S,y=f,b=p,p=f=n.lastIndex;continue outer}}p+=1}return{width:g?v:x,index:g?_:m,truncated:g,ellipsed:g&&r>=a}},ze={limit:1/0,ellipsis:``,ellipsisWidth:0},U=(e,t={})=>Re(e,ze,t).width,Be=`]8;;`,Ve=RegExp(`(?:\\[(?<code>\\d+)m|\\${Be}(?<uri>.*))`,`y`),He=e=>{if(e>=30&&e<=37||e>=90&&e<=97)return 39;if(e>=40&&e<=47||e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0},Ue=e=>`[${e}m`,We=e=>`${Be}${e}`,Ge=(e,t,n)=>{let r=t[Symbol.iterator](),i=!1,a=!1,o=e.at(-1),s=o===void 0?0:U(o),c=r.next(),l=r.next(),u=0;for(;!c.done;){let o=c.value,d=U(o);s+d<=n?e[e.length-1]+=o:(e.push(o),s=0),(o===`\x1B`||o===`›`)&&(i=!0,a=t.startsWith(Be,u+1)),i?a?o===`\x07`&&(i=!1,a=!1):o===`m`&&(i=!1):(s+=d,s===n&&!l.done&&(e.push(``),s=0)),c=l,l=r.next(),u+=o.length}o=e.at(-1),!s&&o!==void 0&&o.length&&e.length>1&&(e[e.length-2]+=e.pop())},Ke=e=>{let t=e.split(` `),n=t.length;for(;n&&!U(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},qe=(e,t,n={})=>{if(n.trim!==!1&&e.trim()===``)return``;let r=``,i,a,o=e.split(` `),s=[``],c=0;for(let e=0;e<o.length;e++){let r=o[e];if(n.trim!==!1){let e=s.at(-1)??``,t=e.trimStart();e.length!==t.length&&(s[s.length-1]=t,c=U(t))}e!==0&&(c>=t&&(n.wordWrap===!1||n.trim===!1)&&(s.push(``),c=0),(c||n.trim===!1)&&(s[s.length-1]+=` `,c++));let i=U(r);if(n.hard&&i>t){let e=t-c,n=1+Math.floor((i-e-1)/t);Math.floor((i-1)/t)<n&&s.push(``),Ge(s,r,t),c=U(s.at(-1)??``);continue}if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){Ge(s,r,t),c=U(s.at(-1)??``);continue}s.push(``),c=0}if(c+i>t&&n.wordWrap===!1){Ge(s,r,t),c=U(s.at(-1)??``);continue}s[s.length-1]+=r,c+=i}n.trim!==!1&&(s=s.map(e=>Ke(e)));let l=s.join(`
2
2
  `),u=!1;for(let e=0;e<l.length;e++){let t=l[e];if(r+=t,u)u=!1;else if(u=t>=`\ud800`&&t<=`\udbff`,u)continue;if(t===`\x1B`||t===`›`){Ve.lastIndex=e+1;let t=Ve.exec(l)?.groups;if(t?.code!==void 0){let e=Number.parseFloat(t.code);i=e===39?void 0:e}else t?.uri!==void 0&&(a=t.uri.length===0?void 0:t.uri)}if(l[e+1]===`
3
3
  `){a&&(r+=We(``));let e=i?He(i):void 0;i&&e&&(r+=Ue(e))}else t===`
4
4
  `&&(i&&He(i)&&(r+=Ue(i)),a&&(r+=We(a)))}return r},Je=/\r?\n/;function Ye(e,t,n){return String(e).normalize().split(Je).map(e=>qe(e,t,n)).join(`
@@ -310,6 +310,6 @@ UIPORT="\${PORT:-${Ui}}"
310
310
  unset PORT
311
311
  exec node "${xt()}" start --ui-port "$UIPORT"`],port:Ui,autoPort:!0}:{name:ca,runtimeExecutable:`/bin/sh`,runtimeArgs:[`-l`,`-c`,da],port:Ui,autoPort:!0};try{if(re(n,e),!L(n))return le(j(n),{recursive:!0}),de(n,`${JSON.stringify({version:sa,configurations:[r]},null,2)}\n`,`utf-8`),{action:`created`,configPath:n};let t=R(n,`utf-8`).trim(),i=t?JSON.parse(t):{};if(!T(i))return{action:`failed`,configPath:n,error:`launch.json root is not an object`};let a=Array.isArray(i.configurations)?i.configurations:[],o=a.findIndex(e=>T(e)&&e.name===`open-knowledge-ui`);o>=0?a[o]=r:a.push(r);let s={...i,version:i.version??sa,configurations:a};return de(n,`${JSON.stringify(s,null,2)}\n`,`utf-8`),{action:o>=0?`merged`:`created`,configPath:n}}catch(e){return{action:`failed`,configPath:n,error:e instanceof Error?e.message:String(e)}}}function pa(e,t,n){try{return L(e.detectPath?.(t,n)??j(e.configPath(t,n)))}catch{return!1}}function ma(e,t,n,r,i){let a=e.serverName(t),o;try{o=i??e.configPath(t,r)}catch(t){return{editorId:e.id,label:e.label,action:`failed`,configPath:``,serverName:a,error:t instanceof Error?t.message:String(t)}}if(!i&&!n.skipAvailabilityCheck&&!pa(e,t,r))return{editorId:e.id,label:e.label,action:`skipped-missing`,configPath:o,serverName:a};if(i!==void 0)try{re(o,t)}catch(t){return{editorId:e.id,label:e.label,action:`failed`,configPath:o,serverName:a,error:t instanceof Error?t.message:String(t),configScope:`project`}}let s;try{s=e.buildEntry(t,n)}catch(t){return{editorId:e.id,label:e.label,action:`failed`,configPath:o,serverName:a,error:t instanceof Error?t.message:String(t),...i===void 0?{}:{configScope:`project`}}}try{le(j(o),{recursive:!0})}catch(t){return{editorId:e.id,label:e.label,action:`failed`,configPath:o,serverName:a,error:t instanceof Error?t.message:String(t),...i===void 0?{}:{configScope:`project`}}}let c,l;try{S(`${o}.lock`,()=>{let t=e.format===`toml`?Qi(o):Zi(o),n=t[e.topLevelKey]??{};c=n[a];let r={...t,[e.topLevelKey]:{...n,[a]:s}};e.format===`toml`?ea(o,r):$i(o,r)},{onWarn:(e,t)=>process.stderr.write(`[ok] ${e} ${JSON.stringify(t)}\n`)})}catch(e){l=e instanceof Error?e:Error(String(e))}return l?{editorId:e.id,label:e.label,action:`failed`,configPath:o,serverName:a,error:l.message,...i===void 0?{}:{configScope:`project`}}:{editorId:e.id,label:e.label,action:c===void 0?`written`:`overwritten`,configPath:o,serverName:a,...i===void 0?{}:{configScope:`project`}}}function ha(e,t){let n=e.projectConfigPath?.(t);if(!(!n||!L(n)))return{editorId:e.id,label:e.label,path:n}}async function ga(e){let t=kt(e.editors),n={mode:`published`,skipAvailabilityCheck:!0};return t.map(t=>ma(t,``,n,e.home))}function _a(e,t,n,r){let i=va(e,t,n,r);return i.kind===`present`?i.entry:null}function va(e,t,n,r){let i;try{i=r??e.configPath(t,n)}catch{return{kind:`absent`}}if(!L(i))return{kind:`absent`};let a;try{a=R(i,`utf-8`)}catch(e){return{kind:`corrupt`,error:e instanceof Error?e.message:String(e)}}if(a.trim()===``)return{kind:`corrupt`,error:`file is empty`};let o;try{o=e.format===`toml`?Qi(i):Zi(i)}catch(e){return{kind:`corrupt`,error:e instanceof Error?e.message:String(e)}}let s=o[e.topLevelKey];if(!T(s))return{kind:`no-entry`};let c=s[e.serverName(t)];return T(c)?{kind:`present`,entry:c}:{kind:`no-entry`}}async function ya(e={}){let t=F(e.cwd??process.cwd()),n=Mi(t,{homeDir:e.home}),r=n.projectRoot,i=!L(M(r,`.ok`));n.ancestorPromoted?console.log(`[ok] Opened existing project at ${r}`):n.gitRootPromoted&&i&&console.log(`[ok] Initialized OK at ${r} — opened parent of ${P(r,t)} because it contains a .git folder`);let a={mode:e.devMcp?`dev`:`published`},o=await f(r),s;try{s=b(r,{contentDir:n.defaultContentDir})}catch(t){let n=G.claude.configPath(r,e.home);return{projectRoot:r,contentCreated:[],contentUpdated:[],contentSkipped:[],editors:[],projectSkills:[],legacyProjectConfigs:[],didGitInit:o.didInit,rootGitignoreCreated:!1,claudeDesktopDetected:!1,mcpAction:`failed`,mcpPath:n,mcpError:`Content scaffolding failed: ${t instanceof Error?t.message:String(t)}`,sharing:{kind:`no-exclude`,reason:`no-git`,localOnlyRequested:!1}}}let c=!1;if(o.didInit)try{c=ee(r)===`created`}catch(e){console.warn(`[ok] Skipping .gitignore seed at ${r}: ${e instanceof Error?e.message:String(e)}`)}let l=await ia({scope:e.scope,mcp:e.mcp,isTTY:e.isTTY,promptFn:e.promptFn}),u=e.editors??Ca(r,e.home),d=e.editors??_t.filter(e=>G[e].projectConfigPath!==void 0),p=kt(u),h=kt(d),g=e.mcp===!1||l===null,_=Array.from(new Map([...p,...g?[]:h].map(e=>[e.id,e])).values()),v=p.filter(t=>pa(t,r,e.home)),y=[],x=[],S=new Set;for(let t of _){if(g){let n=``;try{n=t.configPath(r,e.home)}catch{}y.push({editorId:t.id,label:t.label,action:`skipped-flag`,configPath:n,serverName:t.serverName(r)});continue}if(ta(l)&&p.includes(t)&&y.push(ma(t,r,a,e.home)),na(l)&&h.includes(t)&&t.projectConfigPath){let n=t.projectConfigPath(r),i=ma(t,r,a,e.home,n);y.push(i),(i.action===`written`||i.action===`overwritten`)&&S.add(n)}}for(let e of h)e.projectSkillPath&&x.push(ne(e,r));let C=!g&&l!==null&&na(l)?h.filter(e=>!e.projectConfigPath).map(e=>e.label):void 0,T=g?[]:v.map(e=>ha(e,r)).filter(e=>e!==void 0).filter(e=>!S.has(e.path)),E=v.some(e=>e.id===`claude`)&&!g?fa(r,a):void 0,D=await(e.installUserSkill??m)({home:e.home}),O=w({home:e.home}),k=g?`skipped-flag`:`skipped-missing`,A=y.find(e=>e.editorId===`claude`)??y[0]??{action:k,configPath:G.claude.configPath(r,e.home)},te=await ba({projectRoot:r,desiredMode:await oa({sharing:e.sharing,projectRoot:r,isTTY:e.isTTY,promptFn:e.sharingPromptFn}),explicitFlag:e.sharing});return{projectRoot:r,contentCreated:s.created,contentUpdated:s.updated,contentSkipped:s.skipped,editors:y,projectSkills:x,legacyProjectConfigs:T,launchJson:E,skillInstall:D,didGitInit:o.didInit,rootGitignoreCreated:c,claudeDesktopDetected:O,mcpAction:A.action,mcpPath:A.configPath,mcpError:`error`in A?A.error:void 0,projectScopeUnsupportedLabels:C,sharing:te}}async function ba(e){let{projectRoot:t,desiredMode:n,explicitFlag:r}=e,i=Nt(t);if(i===`no-git`)return{kind:`no-exclude`,reason:`no-git`,localOnlyRequested:r===`local-only`};let a=At(t);if(n===`local-only`){let e=jt(t,a);if(e.kind===`refused-tracked`){let t=e;return{kind:`refused-tracked`,tracked:t.tracked,remediation:t.remediation}}return e.kind===`no-exclude`?{kind:`no-exclude`,reason:e.reason,localOnlyRequested:r===`local-only`}:xa(t,e,`add`)}if(i===`shared`)return{kind:`applied`,mode:`shared`,action:`noop`,appended:[],alreadyPresent:[],removed:[]};let o=Mt(t,a);return o.kind===`no-exclude`?{kind:`no-exclude`,reason:o.reason,localOnlyRequested:!1}:xa(t,o,`remove`)}function xa(e,t,n){let r=Nt(e);return n===`add`?{kind:`applied`,mode:r,action:t.appended.length>0?`added`:`noop`,appended:t.appended,alreadyPresent:t.alreadyPresent,removed:[]}:{kind:`applied`,mode:r,action:`removed`,appended:[],alreadyPresent:[],removed:t.removed}}function Sa(e,t){let n=[],r=e.editors.some(e=>e.action===`written`||e.action===`overwritten`),i=e.editors.some(e=>e.action===`failed`)||e.projectSkills.some(e=>e.action===`failed`),a=e.editors.length>0&&e.editors.every(e=>e.action===`skipped-flag`),o=e.editors.length>0&&e.editors.every(e=>e.action===`skipped-missing`),s=e=>{let n=e.configPath.startsWith(t)?P(t,e.configPath):e.configPath;switch(e.action){case`created`:return` app preview server ${n} configured for Claude Code Desktop embedded browser`;case`merged`:return` app preview server ${n} updated for Claude Code Desktop embedded browser`;case`failed`:return` app preview server ${n} FAILED: ${e.error}`}};e.didGitInit&&n.push(`Initialized git repo at ${t}/.git/ (default branch: main)`),e.rootGitignoreCreated&&n.push(`Seeded .gitignore at ${t}/.gitignore (.DS_Store)`);let c=M(t,`.ok`);if(e.contentCreated.length>0||e.contentUpdated.length>0?(n.push(A(`Content scaffolded at ${c}/`)),e.contentCreated.length>0&&n.push(` Created: ${e.contentCreated.join(`, `)}`),e.contentUpdated.length>0&&n.push(` Updated: ${e.contentUpdated.join(`, `)}`)):n.push(A(`Content already present at ${c}/`)),e.contentSkipped.length>0&&n.push(` Skipped (already exist): ${e.contentSkipped.join(`, `)}`),n.push(``),e.mcpError&&e.editors.length===0)n.push(`Warning: ${e.mcpError}`);else if(e.editors.length===0)if(n.push(A(`MCP server configuration:`)),e.mcpAction===`skipped-flag`)n.push(` MCP config not written — use without --no-mcp to configure editors`);else if(e.projectScopeUnsupportedLabels&&e.projectScopeUnsupportedLabels.length>0){let t=e.projectScopeUnsupportedLabels.join(`, `),r=e.projectScopeUnsupportedLabels.length===1?`does`:`do`;n.push(` ${t} ${r} not support project-level config; skipped`)}else n.push(` No supported editor config directories detected; skipped MCP registration`);else if(a)n.push(`MCP config not written — use without --no-mcp to configure editors`);else if(o)n.push(A(`MCP server configuration:`)),n.push(` No supported editor config directories detected; skipped MCP registration`);else{n.push(A(`MCP server configuration:`));for(let r of e.editors){let i=r.configPath.startsWith(t)?P(t,r.configPath):r.configPath.replace(/^\/Users\/[^/]+/,`~`),a=r.serverName===`open-knowledge`?``:` (${r.serverName})`,o=r.configScope===`project`?` (project)`:``,c=`${r.label}${o}`,l=` `.repeat(Math.max(1,20-c.length)),u=r.editorId===`claude-desktop`&&(r.action===`written`||r.action===`overwritten`)?` — quit and relaunch Claude Desktop to activate`:``;switch(r.action){case`written`:n.push(` ${c}${l}${i} ${D(`registered`)}${a}${u}`);break;case`overwritten`:n.push(` ${c}${l}${i} ${D(`updated`)}${a}${u}`);break;case`skipped-missing`:n.push(` ${c}${l}${i} config root missing; skipped`);break;case`failed`:n.push(` ${c}${l}${i} ${O(`FAILED`)}: ${r.error}`);break;case`skipped-flag`:break}r.editorId===`claude`&&e.launchJson&&n.push(s(e.launchJson))}if(e.projectScopeUnsupportedLabels&&e.projectScopeUnsupportedLabels.length>0){let t=e.projectScopeUnsupportedLabels.join(`, `),r=e.projectScopeUnsupportedLabels.length===1?`does`:`do`;n.push(` ${t} ${r} not support project-level config; skipped`)}}if(e.projectSkills.length>0){n.push(``),n.push(A(`Project-local skills:`));for(let r of e.projectSkills){let e=`${r.label} (project)`,i=` `.repeat(Math.max(1,20-e.length)),a=r.path?P(t,r.path):``;switch(r.action){case`written`:n.push(` ${e}${i}${a} ${D(`installed`)}`);break;case`overwritten`:n.push(` ${e}${i}${a} ${D(`updated`)}`);break;case`skipped-unsupported`:n.push(` ${e}${i}no known project skill surface; skipped`);break;case`failed`:n.push(` ${e}${i}${a} ${O(`FAILED`)}: ${r.error}`);break}}}if(i&&(n.push(``),n.push(`For failed editors, add the MCP server entry or project skill manually. See:`),n.push(` https://github.com/inkeep/open-knowledge#mcp-setup`)),e.legacyProjectConfigs.length>0){n.push(``),n.push(`Project MCP configs found:`);for(let r of e.legacyProjectConfigs)n.push(` ${r.label} ${P(t,r.path)}`);n.push(` These project-local files may override the global config. Remove them if you want fully user-scoped MCP setup in this project.`)}if(e.skillInstall)switch(n.push(``),n.push(A(`User-global skill:`)),e.skillInstall){case`installed`:n.push(` open-knowledge ${D(`installed to detected agent hosts`)} via \`npx skills\``);break;case`skip-current`:n.push(` open-knowledge ${D(`already installed at current version`)}`);break;case`failed`:n.push(` ${k(`open-knowledge install failed — MCP still configured; run manually:`)}`),n.push(` ${k(` npx skills@~1.5.0 add <bundled-path> --agent '*' -g -y --copy`)}`);break}if(e.claudeDesktopDetected&&(n.push(``),n.push(`Claude Desktop App detected. To enable in Claude Chat & Cowork, run: ${A(`ok install-skill`)}`)),e.preview?(n.push(``),n.push(te(e.preview,t))):e.previewWarning&&(n.push(``),n.push(`Content preview unavailable: ${e.previewWarning}`)),n.push(``),n.push(...Ta(e.sharing,t)),r){let t=new Set,r=e.editors.filter(e=>e.action===`written`||e.action===`overwritten`).filter(e=>!t.has(e.editorId)&&t.add(e.editorId)).map(e=>e.label);n.push(``),n.push(`${D(`✓`)} ${A(`Next steps:`)}`),n.push(` 1. Open your editor (${E(r.join(` / `))})`),n.push(` 2. Approve the MCP server when prompted`),n.push(` 3. (Optional) scaffold the starter knowledge-base structure:`),n.push(` - ${E(`ok seed`)} — empty repo, Karpathy 3-layer`),n.push(` - ${E(`mcp__open-knowledge__discover`)} — existing repo, extract conventions`),n.push(` 4. Use the MCP workflow tools as you build the wiki:`),n.push(` - ${E(`mcp__open-knowledge__ingest`)} — capture an external source`),n.push(` - ${E(`mcp__open-knowledge__research`)} — gather sources and write findings`),n.push(` - ${E(`mcp__open-knowledge__consolidate`)} — promote research to canonical articles`)}return n.join(`
312
312
  `)}function Ca(e,t){let n=[];for(let r of _t)pa(G[r],e,t)&&n.push(r);return n}function wa(){return new i(`init`).description(`Scaffold .ok/ in the current directory and register the MCP server for your editor(s)`).option(`--mcp`,`Register the MCP server for selected editors (default: true)`,!0).option(`--no-mcp`,`Scaffold the .ok/ directory but do not touch MCP config`).option(`--dev-mcp`,`Register a local dev MCP entry using node + packages/cli/dist/cli.mjs with debug logging`).addOption(new r(`--scope <scope>`,`Write MCP config at user level, project level, or both`).choices([`user`,`project`,`both`])).addOption(new r(`--shared`,`Commit OK config alongside content (the default for fresh repos)`).conflicts(`localOnly`)).addOption(new r(`--local-only`,`Keep OK config out of git via .git/info/exclude (per-clone, not committed)`).conflicts(`shared`)).action(async e=>{let t=process.cwd(),n=e.shared?`shared`:e.localOnly?`local-only`:void 0,r;try{r=await ya({cwd:t,mcp:e.mcp,devMcp:e.devMcp,scope:e.scope,sharing:n})}catch(e){if(e instanceof p){process.stderr.write(`open-knowledge requires git to initialize a parent repo. Install git or run 'git init' yourself, then re-run.
313
- `),e.stderr&&process.stderr.write(`${e.stderr.trim()}\n`),process.exitCode=1;return}throw e}try{let{previewContent:e}=await import(`./preview-DRATXrPN.mjs`),{loadConfig:t}=await import(`./loader-D6ZQW0bM.mjs`),{resolveContentDir:n}=await import(`./dist-Bj_IaFF5.mjs`),{config:i}=t(r.projectRoot),a=n(i,r.projectRoot);r.preview=e({projectDir:r.projectRoot,contentDir:a})}catch(e){r.previewWarning=e instanceof Error?e.message:String(e)}process.stdout.write(`${Sa(r,r.projectRoot)}\n`),(r.editors.some(e=>e.action===`failed`)||r.mcpAction===`failed`)&&(process.exitCode=1)})}function Ta(e,t){let n=[];switch(e.kind){case`applied`:return n.push(A(`Sharing mode:`)),e.mode===`local-only`?e.action===`added`?n.push(` ${D(`local-only`)} — appended ${e.appended.length} path(s) to ${A(`${t}/.git/info/exclude`)} (per-clone, not committed).`):e.action===`noop`&&e.alreadyPresent.length>0?n.push(` ${D(`local-only`)} — already excluded; nothing to do.`):n.push(` ${D(`local-only`)}`):e.action===`removed`?n.push(` ${D(`shared`)} — removed OK paths from ${A(`${t}/.git/info/exclude`)}; commit the files to share with teammates.`):n.push(` ${D(`shared`)} — OK config will be committed alongside content.`),n;case`refused-tracked`:n.push(k(`Sharing mode: switch to local-only deferred`));for(let t of e.remediation.split(`
313
+ `),e.stderr&&process.stderr.write(`${e.stderr.trim()}\n`),process.exitCode=1;return}throw e}try{let{previewContent:e}=await import(`./preview-xUWmx13Q.mjs`),{loadConfig:t}=await import(`./loader-Bytb4s2w.mjs`),{resolveContentDir:n}=await import(`./dist-Bj_IaFF5.mjs`),{config:i}=t(r.projectRoot),a=n(i,r.projectRoot);r.preview=e({projectDir:r.projectRoot,contentDir:a})}catch(e){r.previewWarning=e instanceof Error?e.message:String(e)}process.stdout.write(`${Sa(r,r.projectRoot)}\n`),(r.editors.some(e=>e.action===`failed`)||r.mcpAction===`failed`)&&(process.exitCode=1)})}function Ta(e,t){let n=[];switch(e.kind){case`applied`:return n.push(A(`Sharing mode:`)),e.mode===`local-only`?e.action===`added`?n.push(` ${D(`local-only`)} — appended ${e.appended.length} path(s) to ${A(`${t}/.git/info/exclude`)} (per-clone, not committed).`):e.action===`noop`&&e.alreadyPresent.length>0?n.push(` ${D(`local-only`)} — already excluded; nothing to do.`):n.push(` ${D(`local-only`)}`):e.action===`removed`?n.push(` ${D(`shared`)} — removed OK paths from ${A(`${t}/.git/info/exclude`)}; commit the files to share with teammates.`):n.push(` ${D(`shared`)} — OK config will be committed alongside content.`),n;case`refused-tracked`:n.push(k(`Sharing mode: switch to local-only deferred`));for(let t of e.remediation.split(`
314
314
  `))n.push(t.length>0?` ${t}`:``);return n.push(` Re-run ${E(`ok config-sharing unshare`)} after resolving to complete the switch.`),n;case`no-exclude`:if(e.localOnlyRequested)n.push(k(`Sharing mode: --local-only requested but no git repo found — option ignored`)),n.push(` Run ${E(`git init`)} (or open this folder via OK Desktop, which can scaffold a repo) and then ${E(`ok config-sharing unshare`)}.`);else if(e.reason===`no-git`)return[];else n.push(k(`Sharing mode unavailable: ${e.reason}.`));return n}}export{St as A,Ye as B,At as C,_t as D,Mt as E,mt as F,H,ft as I,gt as L,pt as M,ut as N,vt as O,dt as P,st as R,Pt as S,Nt as T,Ee as V,ga as _,ba as a,jt as b,Sa as c,_a as d,ia as f,ma as g,fa as h,da as i,bt as j,G as k,Ta as l,ya as m,la as n,va as o,oa as p,ua as r,Ca as s,ca as t,wa as u,Yi as v,Ft as w,It as x,Mi as y,Xe as z};
315
- //# sourceMappingURL=init-BjjtQpJ4.mjs.map
315
+ //# sourceMappingURL=init-Ctu92Awt.mjs.map
@@ -0,0 +1 @@
1
+ import{n as e}from"./loader-DLF6I7F7.mjs";export{e as loadConfig};
@@ -1,4 +1,4 @@
1
- import{Ci as e,Di as t,ga as n,wi as r}from"./server-lock-BpjJj3OD-2pOoEhSP.mjs";import{Ai as i,ki as a,p as o}from"./dist-sld-_d9T.mjs";import{t as s}from"./constants-Dz5iTLUD.mjs";import{t as c}from"./is-object-C-4FJ0rP.mjs";import{resolve as l}from"node:path";import{existsSync as u,readFileSync as d}from"node:fs";import{realpath as f}from"node:fs/promises";async function p(e){let t=l(e);try{return await f(t)}catch(e){if(e.code!==`ENOENT`){let n=e instanceof Error?e.message:String(e);console.warn(`[normalize-cwd] realpath failed for ${t}: ${n}`)}return t}}var m=n();function h(e,t){let n={...e};for(let r of Object.keys(t)){let i=e[r],a=t[r];c(a)&&c(i)?n[r]=h(i,a):a!==void 0&&(n[r]=a)}return n}function g(e){if(!u(e))return{value:null,path:e,source:null,doc:null};let t;try{t=d(e,`utf-8`)}catch(t){return console.warn(`[config] Failed to read ${e}: ${t instanceof Error?t.message:t}`),{value:null,path:e,source:null,doc:null}}let n=(0,m.parseDocument)(t);if(n.errors.length>0)return console.warn(`[config] Failed to parse ${e}: ${n.errors.map(e=>e.message).join(`; `)}`),{value:null,path:e,source:t,doc:null};let r=n.toJSON();return c(r)?{value:r,path:e,source:t,doc:n}:{value:null,path:e,source:t,doc:n}}function _(e,n){return e.map(e=>{let r=e.path.map(e=>typeof e==`symbol`?String(e):e),i={path:r,message:e.message,issueCode:e.code};if(n.doc!==null&&n.source!==null){let e=t({file:n.path,source:n.source,doc:n.doc,path:r});if(e!==void 0)return{...i,source:e}}return i})}function v(t){let n=t??process.cwd(),c=[],u=i(`user`,n),d=a({absPath:u}),f={};d.valid&&d.source!==void 0?(f=h(f,d.value),c.push(u)):d.valid;let p=l(n,`.ok`,s),m=g(p);if(m.value!==null){let t=e({value:m.value,file:m.path,source:m.source,doc:m.doc});if(t.length>0)throw Error(t.map(r).join(`
1
+ import{Ci as e,Di as t,ga as n,wi as r}from"./server-lock-BpjJj3OD-2pOoEhSP.mjs";import{Ai as i,ki as a,p as o}from"./dist-sld-_d9T.mjs";import{t as s}from"./constants-DU4TbLA_.mjs";import{t as c}from"./is-object-C-4FJ0rP.mjs";import{resolve as l}from"node:path";import{existsSync as u,readFileSync as d}from"node:fs";import{realpath as f}from"node:fs/promises";async function p(e){let t=l(e);try{return await f(t)}catch(e){if(e.code!==`ENOENT`){let n=e instanceof Error?e.message:String(e);console.warn(`[normalize-cwd] realpath failed for ${t}: ${n}`)}return t}}var m=n();function h(e,t){let n={...e};for(let r of Object.keys(t)){let i=e[r],a=t[r];c(a)&&c(i)?n[r]=h(i,a):a!==void 0&&(n[r]=a)}return n}function g(e){if(!u(e))return{value:null,path:e,source:null,doc:null};let t;try{t=d(e,`utf-8`)}catch(t){return console.warn(`[config] Failed to read ${e}: ${t instanceof Error?t.message:t}`),{value:null,path:e,source:null,doc:null}}let n=(0,m.parseDocument)(t);if(n.errors.length>0)return console.warn(`[config] Failed to parse ${e}: ${n.errors.map(e=>e.message).join(`; `)}`),{value:null,path:e,source:t,doc:null};let r=n.toJSON();return c(r)?{value:r,path:e,source:t,doc:n}:{value:null,path:e,source:t,doc:n}}function _(e,n){return e.map(e=>{let r=e.path.map(e=>typeof e==`symbol`?String(e):e),i={path:r,message:e.message,issueCode:e.code};if(n.doc!==null&&n.source!==null){let e=t({file:n.path,source:n.source,doc:n.doc,path:r});if(e!==void 0)return{...i,source:e}}return i})}function v(t){let n=t??process.cwd(),c=[],u=i(`user`,n),d=a({absPath:u}),f={};d.valid&&d.source!==void 0?(f=h(f,d.value),c.push(u)):d.valid;let p=l(n,`.ok`,s),m=g(p);if(m.value!==null){let t=e({value:m.value,file:m.path,source:m.source,doc:m.doc});if(t.length>0)throw Error(t.map(r).join(`
2
2
 
3
3
  `));f=h(f,m.value),c.push(p)}let v=o.safeParse(f);if(!v.success){let e={code:`SCHEMA_INVALID`,issues:_(v.error.issues,m)};throw Error(r(e))}return{config:v.data,sources:c}}function y(e){let t=e.cacheMs??1e3,n=e.loadConfigFn??v,r=new Map,i=new Map,a=p(e.startupCwd);return async o=>{let s=await p(o??e.startupCwd),c=Date.now(),l=r.get(s);if(l&&l.expiresAt>c)return l.config;let u=i.get(s);if(u)return await u;let d=(async()=>{if(s===await a)return r.set(s,{config:e.startupConfig,expiresAt:Date.now()+t}),e.startupConfig;let i=n(s).config;return r.set(s,{config:i,expiresAt:Date.now()+t}),i})();i.set(s,d);try{return await d}finally{i.delete(s)}}}export{v as n,y as t};
4
- //# sourceMappingURL=loader-BSyhsuGY.mjs.map
4
+ //# sourceMappingURL=loader-DLF6I7F7.mjs.map
@@ -1,3 +1,3 @@
1
- import{Ft as e}from"./dist-sld-_d9T.mjs";import"./constants-Dz5iTLUD.mjs";import{join as t,relative as n}from"node:path";import{existsSync as r,lstatSync as i,readdirSync as a,realpathSync as o,statSync as s}from"node:fs";function c(r){let{projectDir:c,contentDir:l,sampleCap:u=5}=r,d=[],f=[];try{i(l)}catch(e){return{totalCount:0,sample:[],contentDir:l,warnings:[`cannot access content directory ${l}: ${e instanceof Error?e.message:String(e)}`]}}let p;try{p=e({projectDir:c,contentDir:l})}catch(e){return{totalCount:0,sample:[],contentDir:l,warnings:[e instanceof Error?e.message:String(e)]}}function m(e){let r;try{r=a(e,{withFileTypes:!0})}catch(t){let r=t instanceof Error?t.message:String(t);d.push(`could not read directory ${n(l,e)||`.`}: ${r}`);return}for(let i of r){let r=t(e,i.name);if(i.isSymbolicLink()){let e;try{e=o(r)}catch(e){let t=e.code;t===`ENOENT`||t===`ELOOP`?d.push(`broken or cyclic symlink: ${n(l,r)}`):d.push(`cannot resolve symlink ${n(l,r)}: ${t??`unknown error`}`);continue}let t;try{t=s(e)}catch{continue}if(t.isDirectory()){let e=n(l,r);if(p.isDirExcluded(e))continue;m(r)}else if(t.isFile()){let e=n(l,r);if(p.isExcluded(e))continue;f.push(e)}}else if(i.isDirectory()){let e=n(l,r);if(p.isDirExcluded(e))continue;m(r)}else if(i.isFile()){let e=n(l,r);if(p.isExcluded(e))continue;f.push(e)}}}return m(l),{totalCount:f.length,sample:f.slice(0,u),contentDir:l,warnings:d}}function l(e,i){let a=[],o=n(i,e.contentDir),s=o===``?`./`:`./${o}`;if(a.push(`Content:`),a.push(` Found ${e.totalCount} markdown files in ${s}`),e.sample.length>0){let t=e.sample.join(`, `),n=e.totalCount>e.sample.length?`, …`:``;a.push(` Sample: ${t}${n}`)}if(e.warnings.length>0)for(let t of e.warnings)a.push(` Warning: ${t}`);return a.push(``),r(t(i,`.ok`,`config.yml`))?(a.push(` To adjust scope, add patterns to .okignore at the project root.`),a.push(` To change the content root, edit .ok/config.yml → content.dir.`)):a.push(" Run `open-knowledge init` to scaffold config + .okignore."),a.push(``),a.push(` Re-check anytime: open-knowledge preview`),a.join(`
1
+ import{Ft as e}from"./dist-sld-_d9T.mjs";import"./constants-DU4TbLA_.mjs";import{join as t,relative as n}from"node:path";import{existsSync as r,lstatSync as i,readdirSync as a,realpathSync as o,statSync as s}from"node:fs";function c(r){let{projectDir:c,contentDir:l,sampleCap:u=5}=r,d=[],f=[];try{i(l)}catch(e){return{totalCount:0,sample:[],contentDir:l,warnings:[`cannot access content directory ${l}: ${e instanceof Error?e.message:String(e)}`]}}let p;try{p=e({projectDir:c,contentDir:l})}catch(e){return{totalCount:0,sample:[],contentDir:l,warnings:[e instanceof Error?e.message:String(e)]}}function m(e){let r;try{r=a(e,{withFileTypes:!0})}catch(t){let r=t instanceof Error?t.message:String(t);d.push(`could not read directory ${n(l,e)||`.`}: ${r}`);return}for(let i of r){let r=t(e,i.name);if(i.isSymbolicLink()){let e;try{e=o(r)}catch(e){let t=e.code;t===`ENOENT`||t===`ELOOP`?d.push(`broken or cyclic symlink: ${n(l,r)}`):d.push(`cannot resolve symlink ${n(l,r)}: ${t??`unknown error`}`);continue}let t;try{t=s(e)}catch{continue}if(t.isDirectory()){let e=n(l,r);if(p.isDirExcluded(e))continue;m(r)}else if(t.isFile()){let e=n(l,r);if(p.isExcluded(e))continue;f.push(e)}}else if(i.isDirectory()){let e=n(l,r);if(p.isDirExcluded(e))continue;m(r)}else if(i.isFile()){let e=n(l,r);if(p.isExcluded(e))continue;f.push(e)}}}return m(l),{totalCount:f.length,sample:f.slice(0,u),contentDir:l,warnings:d}}function l(e,i){let a=[],o=n(i,e.contentDir),s=o===``?`./`:`./${o}`;if(a.push(`Content:`),a.push(` Found ${e.totalCount} markdown files in ${s}`),e.sample.length>0){let t=e.sample.join(`, `),n=e.totalCount>e.sample.length?`, …`:``;a.push(` Sample: ${t}${n}`)}if(e.warnings.length>0)for(let t of e.warnings)a.push(` Warning: ${t}`);return a.push(``),r(t(i,`.ok`,`config.yml`))?(a.push(` To adjust scope, add patterns to .okignore at the project root.`),a.push(` To change the content root, edit .ok/config.yml → content.dir.`)):a.push(" Run `open-knowledge init` to scaffold config + .okignore."),a.push(``),a.push(` Re-check anytime: open-knowledge preview`),a.join(`
2
2
  `)}export{c as n,l as t};
3
- //# sourceMappingURL=preview-C6kOnHJr.mjs.map
3
+ //# sourceMappingURL=preview-BiAC5DG4.mjs.map
@@ -0,0 +1 @@
1
+ import{n as e,t}from"./preview-BiAC5DG4.mjs";export{t as formatPreviewBlock,e as previewContent};
@@ -1912,4 +1912,4 @@ Error generating stack: `+e.message+`
1912
1912
  ${SH(gH,ee)}
1913
1913
  ${SH(_H,Ic)}
1914
1914
  ${bH}
1915
- </svg>`,wH=`${GB}\n${aV}`;function TH(e){return{...nM({type:e===`dark`?`dark`:`light`,colors:{"sideBar.background":`var(--sidebar)`,"sideBar.foreground":`var(--sidebar-foreground)`,"sideBar.border":`var(--sidebar-border)`,"list.activeSelectionBackground":`var(--sidebar-accent)`,"list.activeSelectionForeground":`var(--sidebar-accent-foreground)`,"list.hoverBackground":`var(--sidebar-hover)`,focusBorder:`var(--color-primary)`,"input.background":`var(--input)`,"input.border":`var(--border)`}}),"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`0.875rem`,"--trees-item-padding-x-override":`0.5rem`,"--trees-padding-inline-override":`0.5rem`,"--trees-border-radius-override":`0.375rem`,"--trees-selected-fg":`var(--color-primary)`,"--truncate-marker-fade-in-duration":`0s`,"--trees-file-icon-color-markdown":`light-dark(var(--color-gray-400), var(--color-gray-500))`,"--trees-file-icon-color-image":`light-dark(var(--color-gray-400), var(--color-gray-500))`,"--trees-fg-muted":`light-dark(var(--color-gray-400), var(--color-gray-500))`}}function EH(e){let t=e.split(`/`).pop()?.replace(/\.md$/i,``).toLowerCase();return!!t&&hH.has(t)}function DH(e){return e===`darwin`?lr._({id:`LtSYdi`}):e===`win32`?lr._({id:`qi1F96`}):lr._({id:`hz7n6T`})}function OH(e){let t=(0,$.c)(18),{item:n,workspace:r,onClose:a}=e,{_:o}=i(),s=typeof window<`u`?window.okDesktop:void 0;if(!s)return null;let c=s.platform,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=DH(c),t[0]=l):l=t[0];let u=l,d,f;t[1]!==o||t[2]!==r?(d=r?null:o({id:`wTcjov`}),f=o(c===`darwin`?d?{id:`FvpFSZ`,values:{hint:d}}:{id:`LtSYdi`}:c===`win32`?d?{id:`o4dcAf`,values:{hint:d}}:{id:`qi1F96`}:d?{id:`ScUTHW`,values:{hint:d}}:{id:`hz7n6T`}),t[1]=o,t[2]=r,t[3]=d,t[4]=f):(d=t[3],f=t[4]);let p=f,m=!r,h;t[5]!==n||t[6]!==a||t[7]!==r?(h=()=>{if(!r)return;a();let e=Lh(r.contentDir,pk(n),r.pathSeparator);s.shell.showItemInFolder(e)},t[5]=n,t[6]=a,t[7]=r,t[8]=h):h=t[8];let g,_;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Z.jsx)(yt,{"aria-hidden":`true`}),_=(0,Z.jsx)(`span`,{className:`flex-1`,children:u}),t[9]=g,t[10]=_):(g=t[9],_=t[10]);let v;t[11]===d?v=t[12]:(v=d?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:d}):null,t[11]=d,t[12]=v);let y;return t[13]!==p||t[14]!==m||t[15]!==h||t[16]!==v?(y=(0,Z.jsxs)(Wo,{disabled:m,onSelect:h,"aria-label":p,children:[g,_,v]}),t[13]=p,t[14]=m,t[15]=h,t[16]=v,t[17]=y):y=t[17],y}function kH(e){let t=(0,$.c)(21),{dirAbsPath:n,onClose:r}=e,{_:a}=i(),o=typeof window<`u`?window.okDesktop:void 0;if(!o)return null;let c,l,u,d,f;t[0]!==a||t[1]!==n||t[2]!==r?(l=n===null?a({id:`wTcjov`}):null,c=Wo,u=n===null,t[8]!==n||t[9]!==r?(d=()=>{n!==null&&(r(),MV(o,n))},t[8]=n,t[9]=r,t[10]=d):d=t[10],f=a(l?{id:`ehLu5O`,values:{hint:l}}:{id:`BJpGCq`}),t[0]=a,t[1]=n,t[2]=r,t[3]=c,t[4]=l,t[5]=u,t[6]=d,t[7]=f):(c=t[3],l=t[4],u=t[5],d=t[6],f=t[7]);let p;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Z.jsx)(Rl,{"aria-hidden":`true`}),t[11]=p):p=t[11];let m;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Z.jsx)(`span`,{className:`flex-1`,children:(0,Z.jsx)(s,{id:`BJpGCq`})}),t[12]=m):m=t[12];let h;t[13]===l?h=t[14]:(h=l?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:l}):null,t[13]=l,t[14]=h);let g;return t[15]!==c||t[16]!==u||t[17]!==d||t[18]!==f||t[19]!==h?(g=(0,Z.jsxs)(c,{disabled:u,onSelect:d,"aria-label":f,children:[p,m,h]}),t[15]=c,t[16]=u,t[17]=d,t[18]=f,t[19]=h,t[20]=g):g=t[20],g}function AH(e,t){return fk({kind:e.endsWith(`/`)?`directory`:`file`,name:e,path:e},t)}function jH(e,t){return e!==t&&e.startsWith(t)}function MH(e,t){let n=[...new Set(e)],r=n.filter(e=>e.endsWith(`/`));return n.filter(e=>!r.some(t=>jH(e,t))).map(e=>AH(e,t))}function NH(e,t){return e===t||e.startsWith(`${t}/`)}function PH(e){if(!(e instanceof HTMLElement))return!1;let t=e.tagName;return t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable||e.closest(`[contenteditable="true"]`)!==null}function FH(e,t,n){let r=new Set,i=new Set,a=new Set;for(let o of e){if(o.kind===`file`){r.add(o.path);continue}if(o.kind===`asset`){a.add(o.path);continue}i.add(o.path);for(let e of t)zn(e)&&e.docName.startsWith(`${o.path}/`)?r.add(e.docName):kr(e)&&e.path.startsWith(`${o.path}/`)&&a.add(e.path);for(let e of n){let t=tk(e);NH(t,o.path)&&i.add(t)}}return{docNames:r,folderPaths:i,assetPaths:a}}function IH(e,t){return e.kind===`file`?t.kind===`file`&&e.path===t.createdPath:e.kind===`asset`?!1:NH(t.createdPath,e.path)}function LH(e){let t=(0,$.c)(84),{item:n,context:r,anyActionBusy:a,workspace:o,handoff:c,model:l,okignoreBinding:u,projectLocalBinding:d,mergedConfig:f,onStartCreating:p,onCreateFromTemplate:m,onDuplicate:h,onDelete:g,onExpandSubtree:_,onCollapseSubtree:v,folderTreePaths:y,isAsset:b,documents:x}=e,{_:S}=i(),C,w,E,D,O,k,A,j,M,N;if(t[0]!==S||t[1]!==x||t[2]!==n||t[3]!==f?.appearance?.sidebar?.showAllFiles||t[4]!==f?.appearance?.sidebar?.showHiddenFiles||t[5]!==l||t[6]!==u||t[7]!==d){N=fk(n,x),O=n.kind===`directory`,k=N.kind===`asset`?null:N,C=k!==null&&u!==null;let e;t[18]!==S||t[19]!==O?(e=S(O?{id:`5D3Ior`}:{id:`dbhUX1`}),t[18]=S,t[19]=O,t[20]=e):e=t[20],D=e,j=f?.appearance?.sidebar?.showHiddenFiles??!1,A=f?.appearance?.sidebar?.showAllFiles??!1,w=d!==null;let r=l.getSelectedPaths(),i=r.includes(N.treePath)?MH(r,x):[];E=i.length>1?i:[N];let a=E.length;M=lr._({id:`44_vJP`,values:{deleteCount:a}}),t[0]=S,t[1]=x,t[2]=n,t[3]=f?.appearance?.sidebar?.showAllFiles,t[4]=f?.appearance?.sidebar?.showHiddenFiles,t[5]=l,t[6]=u,t[7]=d,t[8]=C,t[9]=w,t[10]=E,t[11]=D,t[12]=O,t[13]=k,t[14]=A,t[15]=j,t[16]=M,t[17]=N}else C=t[8],w=t[9],E=t[10],D=t[11],O=t[12],k=t[13],A=t[14],j=t[15],M=t[16],N=t[17];let P=M,F;t[21]!==O||t[22]!==n||t[23]!==o?(F=O&&o?Lh(o.contentDir,pk(n),o.pathSeparator):null,t[21]=O,t[22]=n,t[23]=o,t[24]=F):F=t[24];let I=F,L;if(t[25]!==O||t[26]!==n||t[27]!==o){bb0:{if(!o||O){L=null;break bb0}let e=pk(n),t=e.lastIndexOf(`/`);if(t===-1){L=o.contentDir;break bb0}L=Lh(o.contentDir,e.slice(0,t),o.pathSeparator)}t[25]=O,t[26]=n,t[27]=o,t[28]=L}else L=t[28];let R=L,z;t[29]!==b||t[30]!==O||t[31]!==n||t[32]!==o?(z=b?null:O?Vh({folderRelativePath:pk(n),workspace:o}):zh({docName:QO(n.path),workspace:o}),t[29]=b,t[30]=O,t[31]=n,t[32]=o,t[33]=z):z=t[33];let B=z,V;t[34]===r?V=t[35]:(V=()=>r.close({restoreFocus:!1}),t[34]=r,t[35]=V);let H=V,U;t[36]===r?U=t[37]:(U=()=>r.close(),t[36]=r,t[37]=U);let W=U,G;t[38]!==S||t[39]!==d?(G=e=>{if(d===null)return;let t=d.patch({appearance:{sidebar:{showHiddenFiles:e}}});t.ok||(console.warn(`[FileTree] showHiddenFiles toggle rejected:`,Er(t.error)),gs.error(S({id:`P47EWZ`}),{description:Er(t.error)}))},t[38]=S,t[39]=d,t[40]=G):G=t[40];let K=G,q;t[41]!==S||t[42]!==d?(q=e=>{if(d===null)return;let t=d.patch({appearance:{sidebar:{showAllFiles:e}}});t.ok||(console.warn(`[FileTree] showAllFiles toggle rejected:`,Er(t.error)),gs.error(S({id:`P47EWZ`}),{description:Er(t.error)}))},t[41]=S,t[42]=d,t[43]=q):q=t[43];let J=q,Y=0,ee=0;if(O){let e=nk(n.path);for(let t of y)(t===e||t.startsWith(e))&&(Y++,kV(l.getItem(t))?.isExpanded()&&ee++)}let te=O&&ee<Y,ne=O&&ee>0,ie;t[44]===W?ie=t[45]:(ie=e=>{e||W()},t[44]=W,t[45]=ie);let ae;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(0,Z.jsx)(Ho,{asChild:!0,children:(0,Z.jsx)(`span`,{"aria-hidden":`true`,"data-file-tree-context-menu-root":`true`,className:`block size-px`})}),t[46]=ae):ae=t[46];let oe;t[47]!==S||t[48]!==a||t[49]!==C||t[50]!==w||t[51]!==W||t[52]!==H||t[53]!==P||t[54]!==E||t[55]!==I||t[56]!==J||t[57]!==K||t[58]!==c||t[59]!==B||t[60]!==D||t[61]!==b||t[62]!==O||t[63]!==n||t[64]!==l||t[65]!==u||t[66]!==k||t[67]!==v||t[68]!==m||t[69]!==g||t[70]!==h||t[71]!==_||t[72]!==p||t[73]!==R||t[74]!==A||t[75]!==j||t[76]!==ne||t[77]!==te||t[78]!==N||t[79]!==o?(oe=(0,Z.jsx)(xo,{sideOffset:0,align:`start`,"data-file-tree-context-menu-root":`true`,className:`min-w-52`,children:O?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{H(),p(`file`,tk(n.path))},children:[(0,Z.jsx)(Nl,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`MW64zN`})]}),(0,Z.jsxs)(To,{children:[(0,Z.jsxs)(Fo,{disabled:a,children:[(0,Z.jsx)(mo,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`Uuj_R4`})]}),(0,Z.jsx)(go,{children:(0,Z.jsx)(OV,{parentDir:tk(n.path),onSelectTemplate:e=>{H(),m(tk(n.path),e)},ItemComponent:Wo})})]}),(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{H(),p(`folder`,tk(n.path))},children:[(0,Z.jsx)(el,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`tX5yOZ`})]}),(0,Z.jsx)(Vo,{}),(0,Z.jsx)(OH,{item:n,workspace:o,onClose:W}),(0,Z.jsx)(XV,{input:B,installStates:c.installStates,isElectronHost:c.isElectronHost,dispatch:c.dispatch,webFallbackVisible:!1}),(0,Z.jsx)(kH,{dirAbsPath:I,onClose:W}),(0,Z.jsxs)(To,{children:[(0,Z.jsxs)(Fo,{children:[(0,Z.jsx)(Be,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`zd00pH`})]}),(0,Z.jsxs)(go,{children:[(0,Z.jsx)(Wo,{disabled:!o,onSelect:()=>{o&&(W(),mH(Lh(o.contentDir,pk(n),o.pathSeparator),`full`))},children:(0,Z.jsx)(s,{id:`z2funE`})}),(0,Z.jsx)(Wo,{onSelect:()=>{W(),mH(pk(n),`relative`)},children:(0,Z.jsx)(s,{id:`xloBjn`})})]})]}),(0,Z.jsx)(Vo,{}),(0,Z.jsx)(ha,{checked:j,onCheckedChange:K,disabled:!w,"data-testid":`file-tree-menu-show-hidden-files`,children:(0,Z.jsx)(s,{id:`K_wz1u`})}),(0,Z.jsx)(ha,{checked:A,onCheckedChange:J,disabled:!w,"data-testid":`file-tree-menu-show-all-files`,children:(0,Z.jsx)(s,{id:`i8dKs-`})}),te||ne?(0,Z.jsx)(Vo,{}):null,te?(0,Z.jsxs)(Wo,{onSelect:()=>{W(),_(n.path)},children:[(0,Z.jsx)(Vl,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`b392Dr`})]}):null,ne?(0,Z.jsxs)(Wo,{onSelect:()=>{W(),v(n.path)},children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`BBtVak`})]}):null,(0,Z.jsx)(Vo,{}),(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{N.kind!==`asset`&&(W(),h(N))},children:[(0,Z.jsx)(Ke,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`euc6Ns`})]}),(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{H(),l.startRenaming(n.path)},children:[(0,Z.jsx)(T,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`2wxgft`})]}),(0,Z.jsxs)(Wo,{"data-testid":`file-tree-menu-hide`,disabled:!C,onSelect:()=>{if(!u||!k)return;W();let e=QB(k),t=Go(u.current()),n=Po(t,e);if(n===t)return;u.patch(Io(n));let r=k.path.split(`/`).pop()||k.path;gs.success(S({id:`4xtLTl`,values:{basename:r}}),{description:S({id:`nWv1ja`}),duration:5e3})},children:[(0,Z.jsx)(lt,{"aria-hidden":`true`}),D]}),(0,Z.jsxs)(Wo,{variant:`destructive`,disabled:a,onSelect:()=>{W(),g(E)},children:[(0,Z.jsx)(re,{"aria-hidden":`true`}),P]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(OH,{item:n,workspace:o,onClose:W}),!b&&(0,Z.jsx)(XV,{input:B,installStates:c.installStates,isElectronHost:c.isElectronHost,dispatch:c.dispatch,webFallbackVisible:!0}),(0,Z.jsx)(kH,{dirAbsPath:R,onClose:W}),(0,Z.jsxs)(To,{children:[(0,Z.jsxs)(Fo,{children:[(0,Z.jsx)(Be,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`zd00pH`})]}),(0,Z.jsxs)(go,{children:[(0,Z.jsx)(Wo,{disabled:!o,onSelect:()=>{o&&(W(),mH(Lh(o.contentDir,pk(n),o.pathSeparator),`full`))},children:(0,Z.jsx)(s,{id:`z2funE`})}),(0,Z.jsx)(Wo,{onSelect:()=>{W(),mH(pk(n),`relative`)},children:(0,Z.jsx)(s,{id:`xloBjn`})})]})]}),(0,Z.jsx)(Vo,{}),b?null:(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{W(),h(N)},children:[(0,Z.jsx)(Ke,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`euc6Ns`})]}),(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{H(),l.startRenaming(n.path)},children:[(0,Z.jsx)(T,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`2wxgft`})]}),k?(0,Z.jsxs)(Wo,{"data-testid":`file-tree-menu-hide`,disabled:!C,onSelect:()=>{if(!u)return;W();let e=QB(k),t=Go(u.current()),n=Po(t,e);if(n===t)return;u.patch(Io(n));let r=k.path.split(`/`).pop()||k.path;gs.success(S({id:`OD0FCX`,values:{basename:r}}),{description:S({id:`nWv1ja`}),duration:5e3})},children:[(0,Z.jsx)(lt,{"aria-hidden":`true`}),D]}):null,(0,Z.jsxs)(Wo,{variant:`destructive`,disabled:a,onSelect:()=>{W(),g(E)},children:[(0,Z.jsx)(re,{"aria-hidden":`true`}),P]})]})}),t[47]=S,t[48]=a,t[49]=C,t[50]=w,t[51]=W,t[52]=H,t[53]=P,t[54]=E,t[55]=I,t[56]=J,t[57]=K,t[58]=c,t[59]=B,t[60]=D,t[61]=b,t[62]=O,t[63]=n,t[64]=l,t[65]=u,t[66]=k,t[67]=v,t[68]=m,t[69]=g,t[70]=h,t[71]=_,t[72]=p,t[73]=R,t[74]=A,t[75]=j,t[76]=ne,t[77]=te,t[78]=N,t[79]=o,t[80]=oe):oe=t[80];let se;return t[81]!==oe||t[82]!==ie?(se=(0,Z.jsxs)(Ya,{open:!0,modal:!1,onOpenChange:ie,children:[ae,oe]}),t[81]=oe,t[82]=ie,t[83]=se):se=t[83],se}function RH(e){let t=(0,$.c)(280),{ref:n}=e,{_:r}=i(),{activeDocName:a,activeTarget:o,closeTabs:c,closeDocument:l,closeAndClearForRename:u,getPoolActiveDocName:d,poolHas:f,isNewTabActive:p,openTarget:m,prewarm:h,remapTabsForRename:g}=pt(),{notifySidebarFileSelected:_}=ID(),{resolvedTheme:v}=Wr(),{addPage:y,pageMeta:b}=ki(),x;t[0]===b?x=t[1]:(x=function(e,t){return Ci(e,t??b.get(e)?.size)??{kind:`doc`,target:e,docName:e}},t[0]=b,t[1]=x);let S=x,C;t[2]!==S||t[3]!==_||t[4]!==m?(C=function(e,t){m(S(e,t),{tabBehavior:`replace-active`}),dH(gr(e)),_()},t[2]=S,t[3]=_,t[4]=m,t[5]=C):C=t[5];let w=C,T;t[6]!==_||t[7]!==m?(T=function(e){let t=_r(e);m({kind:`folder`,target:e,folderPath:e},{tabBehavior:`replace-active`}),dH(t),_()},t[6]=_,t[7]=m,t[8]=T):T=t[8];let E=T,D;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(D=[],t[9]=D):D=t[9];let[O,k]=(0,Q.useState)(D),[A,j]=(0,Q.useState)(!0),[M,N]=(0,Q.useState)(null),[P,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),[z,B]=(0,Q.useState)(null),[V,H]=(0,Q.useState)(null),{conflicts:U}=to(),[W,G]=(0,Q.useState)(null),[K,q]=(0,Q.useState)(null),J=(0,Q.useRef)(O),Y;t[10]!==O||t[11]!==E||t[12]!==w||t[13]!==_||t[14]!==m?(Y=function(e,t){let n=t===void 0?O:t,r=gV(e,n);if(r.kind===`none`){console.debug(`[FileTree] Dropped selection for unknown docName:`,rk(e));return}if(r.kind===`asset`){m({kind:`asset`,target:r.path,assetPath:r.path,mediaKind:r.mediaKind},{tabBehavior:`replace-active`}),dH(r.hash),_();return}if(r.kind===`folder`){E(r.path);return}let i=n.find(e=>zn(e)&&e.docName===r.path);w(r.path,i?.size)},t[10]=O,t[11]=E,t[12]=w,t[13]=_,t[14]=m,t[15]=Y):Y=t[15];let ee=Y,te;t[16]!==_||t[17]!==m?(te=function(e){m({kind:`asset`,target:e,assetPath:e,mediaKind:J.current.find(t=>kr(t)&&t.path===e)?.mediaKind??null},{tabBehavior:`replace-active`}),dH(fi(e)),_()},t[16]=_,t[17]=m,t[18]=te):te=t[18];let ne=te,re=(0,Q.useRef)(a),ie;t[19]===O?ie=t[20]:(ie=new Set(O.filter(kr).map(cU)),t[19]=O,t[20]=ie);let ae=ie,oe=(0,Q.useRef)(ae),se;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(se=[],t[21]=se):se=t[21];let ce=(0,Q.useRef)(se),le=(0,Q.useRef)(null),ue=(0,Q.useRef)(sU),de=(0,Q.useRef)(null),fe=(0,Q.useRef)(null),pe=(0,Q.useRef)(!1),me=(0,Q.useRef)(null),he;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(he=new Map,t[22]=he):he=t[22];let ge=(0,Q.useRef)(he),_e=(0,Q.useRef)(!1),ve=(0,Q.useRef)(!1),ye=(0,Q.useRef)(null),be=(0,Q.useRef)(null),xe=(0,Q.useRef)(oU),Se=(0,Q.useRef)(aU),Ce=(0,Q.useRef)(iU),we=(0,Q.useRef)(rU),Te=(0,Q.useRef)(o),{selectedFilePath:Ee,selectedFolderPath:De,navigationPath:Oe}=hV(o,p?null:a),ke=Ee?ZO(Ee,O.find(e=>zn(e)&&e.docName===Ee)?.docExt):De?nk(De):o?.kind===`asset`?o.assetPath:null,Ae=ug().states,{dispatch:je}=$h(),Me;t[23]!==je||t[24]!==Ae?(Me={installStates:Ae,isElectronHost:typeof window<`u`&&window.okDesktop!=null,dispatch:je},t[23]=je,t[24]=Ae,t[25]=Me):Me=t[25];let Ne=Me,{okignoreBinding:Pe,projectLocalBinding:Fe,merged:Ie}=gt(),Le=Ie?.appearance?.sidebar?.showHiddenFiles??!1,Re=Ie?.appearance?.sidebar?.showAllFiles??!1,ze;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(ze=()=>me.current===null,t[26]=ze):ze=t[26];let Be=ze,Ve;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(Ve=[],t[27]=Ve):Ve=t[27];let He;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(He={set:`complete`,spriteSheet:CH,byFileExtension:{md:{name:vH,viewBox:yH},mdx:{name:vH,viewBox:yH}}},t[28]=He):He=t[28];let Ue;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(Ue={contextMenu:{enabled:!0,triggerMode:`both`,buttonVisibility:`when-needed`}},t[29]=Ue):Ue=t[29];let We;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(We={canDrag:Be,canDrop:Be,onDropComplete:e=>we.current(e),onDropError:nU},t[30]=We):We=t[30];let Ge,Ke;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(Ge={canRename:Be,onRename:e=>Se.current(e),onError:e=>Ce.current(e)},Ke=e=>xe.current(e),t[31]=Ge,t[32]=Ke):(Ge=t[31],Ke=t[32]);let qe;t[33]===r?qe=t[34]:(qe={paths:Ve,flattenEmptyDirectories:!1,initialExpansion:`closed`,fileTreeSearchMode:`hide-non-matches`,initialVisibleRowCount:18,stickyFolders:!0,icons:He,unsafeCSS:wH,composition:Ue,dragAndDrop:We,renaming:Ge,onSelectionChange:Ke,renderRowDecoration:e=>{let{item:t}=e;if(t.kind!==`file`)return null;let n=J.current.find(e=>zn(e)&&ZO(e.docName,e.docExt)===t.path);if(n?.isSymlink){let e=n.targetPath;return{icon:gH,title:r(e?{id:`JE21eh`,values:{targetPath:e}}:{id:`BQu9Pg`})}}return EH(t.path)?{icon:_H,title:r({id:`i9toLO`})}:null}},t[33]=r,t[34]=qe);let{model:X}=zB(qe),Je;t[35]===X?Je=t[36]:(Je=function(e){let t=X.getItem(e)??X.getItem(nk(e));return t?.isDirectory()?nk(tk(t.getPath())):e},t[35]=X,t[36]=Je);let Ye=Je,Xe,Ze;t[37]===O?(Xe=t[38],Ze=t[39]):(Ze=ik(O),Xe=ak(Ze),t[37]=O,t[38]=Xe,t[39]=Ze);let Qe=Xe,$e=(0,Q.useRef)(Ze),et;t[40]===O?et=t[41]:(et=sk(O),t[40]=O,t[41]=et);let tt=et,nt=(0,Q.useRef)(tt),rt=De?ck(nk(De)).slice(0,-1):ck(ke??Oe),it=rt.join(`\0`),at;if(t[42]!==X){let e=()=>{let e=new Set;for(let t of nt.current)kV(X.getItem(t))?.isExpanded()&&e.add(t);return e};at=t=>{let n=new Set(sk(t??J.current)),r=e();for(let e of ce.current)r.add(e);return[...r].filter(e=>n.has(e))},t[42]=X,t[43]=at}else at=t[43];let ot=at,st;t[44]!==ot||t[45]!==X?(st=e=>{let t=ik(e??J.current);X.resetPaths(t,{initialExpandedPaths:ot(e)})},t[44]=ot,t[45]=X,t[46]=st):st=t[46];let ct=st,lt;t[47]!==X||t[48]!==ct?(lt=(e,t,n,r)=>{let i=r===void 0?[]:r,a=0,o=null;for(let{fromDocName:t,toDocName:r}of n){let n=e.find(e=>zn(e)&&e.docName===t);if(n==null||X.getItem(r)==null)continue;let i=ZO(r,n.docExt);X.move(r,i),o=i,a+=1}for(let{toPath:e}of i){let t=BB(e);if(t===``)continue;let n=e.slice(0,-t.length);X.getItem(n)!=null&&(X.getItem(e)??X.move(n,e),o=e,a+=1)}a!==0&&(ct(t),o!=null&&X.focusPath(o))},t[47]=X,t[48]=ct,t[49]=lt):lt=t[49];let ut=lt,dt;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(dt=e=>{de.current=ok(e)},t[50]=dt):dt=t[50];let ft=dt,mt;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(mt=e=>oe.current.has(e),t[51]=mt):mt=t[51];let ht=mt,_t;t[52]!==r||t[53]!==y||t[54]!==E||t[55]!==w||t[56]!==ct?(_t=async function(e){if(e.kind===`asset`||me.current!==null)return;let t=()=>{R(null),me.current=null};me.current=e.path,R(e.path),N(null);try{let n=await Tt(await fetch(`/api/duplicate-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:e.kind,path:e.path})}),r({id:`dw_dUJ`}));if(!n.ok){gs.error(n.title),ct(),t();return}let i=F(Fn,n.body,`duplicate-path`,null);if(i===null){let e=r({id:`67f-3g`});gs.error(e),N(e),Ti([`files`,`backlinks`,`graph`]),ct(),t();return}for(let e of i.duplicatedDocNames)y(e);k(t=>{let n=Ek(t,e,i);return ct(n),ft(n),n}),Ti([`files`,`backlinks`,`graph`]),i.path!==e.path&&(i.kind===`folder`?E(i.path):w(i.path)),gs.success(i.kind===`folder`?r({id:`iilQXA`}):r({id:`A6h5b-`}),{description:i.path}),t()}catch(e){let n=e,i=n instanceof Error?n.message:String(n);console.warn(`[FileTree] duplicate failed:`,n),gs.error(r({id:`EBVbtP`}),{description:i}),ct(),t()}},t[52]=r,t[53]=y,t[54]=E,t[55]=w,t[56]=ct,t[57]=_t):_t=t[57];let vt=_t,yt=(0,Q.useRef)(vt),bt;t[58]===vt?bt=t[59]:(bt=()=>{yt.current=vt},t[58]=vt,t[59]=bt),(0,Q.useEffect)(bt);let xt=function(e){let t=fH(e);if(!t||pH(t))return!1;let n=X.getFocusedPath()??X.getSelectedPaths()[0]??null;if(!n||n.endsWith(`/`)||ht(n))return!1;let r=pH(n);if(!r)return!1;let i=nk(t);if(!nt.current.includes(i))return!1;let a=`${t}${r}`;return $e.current.includes(a)?!1:(Qt({sourcePath:n,destinationPath:a,isFolder:!1}),X.move(n,a),!0)},St;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(St=e=>{let t=e??le.current;!t||le.current!==t||(t.disposeCommitListener(),le.current=null)},t[60]=St):St=t[60];let Ct=St,wt;t[61]!==r||t[62]!==Ct||t[63]!==l||t[64]!==c||t[65]!==ct?(wt=async function(e,t){let n=t===void 0?{}:t,i=n.updateUi??!0,a=n.restoreLocation??i;Ct(e),i&&R(e.renamePath);try{let t=await fetch(`/api/delete-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:e.kind,path:e.createdPath})});if(!t.ok&&t.status!==404){let n=e.kind,a=e.createdPath,o=await Tt(t,r({id:`EcM3k7`,values:{kind:n}}));if(o.ok)return;let s=o.title,c=r({id:`YPFBfr`,values:{detail:s,kind:n,createdPath:a}});i?gs.error(c):console.warn(`[FileTree] cleanup pending create failed: ${c}`),i&&(R(null),ct());return}}catch(t){if(console.warn(`[FileTree] cleanup pending create failed:`,t),i){let t=e.kind,n=e.createdPath;gs.error(r({id:`_TDESN`,values:{kind:t,createdPath:n}}))}i&&(R(null),ct());return}i&&(e.kind===`file`?l(e.createdPath):c([Zt(e.createdPath)],{force:!0})),i&&k(t=>{let n=wk(t,e.kind===`file`?[e.createdPath]:[],e.kind===`folder`?e.createdPath:void 0);return ft(n),n}),Ti([`files`,`backlinks`,`graph`]),a&&(window.location.hash=e.previousHash),i&&R(null)},t[61]=r,t[62]=Ct,t[63]=l,t[64]=c,t[65]=ct,t[66]=wt):wt=t[66];let Et=wt,Dt,Ot;t[67]===Symbol.for(`react.memo_cache_sentinel`)?(Dt=()=>()=>{let e=le.current;e&&ue.current(e,{restoreLocation:!1,updateUi:!1}).catch(tU)},Ot=[],t[67]=Dt,t[68]=Ot):(Dt=t[67],Ot=t[68]),(0,Q.useEffect)(Dt,Ot);let kt,At;t[69]===r?(kt=t[70],At=t[71]):(kt=()=>{let e=!0,t=null,n=HV(async function(){t?.abort();let n=new AbortController;t=n;try{let t=ve.current,i=await fetch(t?`/api/documents?showAll=true`:`/api/documents`,{signal:n.signal,headers:t?UV:void 0});if(t&&WV(i)){let{entries:n,truncated:r}=await qV(i);if(!e)return;k(JV(Bi(n,_e.current||t),J.current,ge.current)),N(null),I(r?n.length:null)}else{let n=await Tt(i,r({id:`8RtNI0`}));if(!e)return;if(!n.ok)N(n.title),I(null);else{let e=vi.safeParse(n.body);if(!e.success)N(r({id:`HlmZBk`})),I(null);else{let n=_e.current||t;k(JV(Bi(e.data.documents,n),J.current,ge.current)),N(null),I(t&&e.data.truncated===!0?e.data.documents.length:null)}}}}catch(t){let i=t;if(n.signal.aborted)return;e&&N(r({id:`34qyH5`})),console.warn(`[FileTree] fetch failed:`,i)}e&&j(!1)},()=>t?.abort());ye.current=()=>n.request(),n.request();let i=()=>{document.visibilityState===`visible`&&n.request()};window.addEventListener(`focus`,i),window.addEventListener(`visibilitychange`,i);let a=ni(e=>{e.includes(`files`)&&n.request()});return()=>{e=!1,ye.current=null,n.dispose(),window.removeEventListener(`focus`,i),window.removeEventListener(`visibilitychange`,i),a()}},At=[r],t[69]=r,t[70]=kt,t[71]=At),(0,Q.useEffect)(kt,At);let jt=(0,Q.useRef)(!0),Mt;t[72]===Symbol.for(`react.memo_cache_sentinel`)?(Mt=()=>{if(jt.current){jt.current=!1;return}ye.current?.()},t[72]=Mt):Mt=t[72];let Nt;t[73]===Le?Nt=t[74]:(Nt=[Le],t[73]=Le,t[74]=Nt),(0,Q.useEffect)(Mt,Nt);let Pt=(0,Q.useRef)(!0),Ft;t[75]===Symbol.for(`react.memo_cache_sentinel`)?(Ft=()=>{if(Pt.current){Pt.current=!1;return}ye.current?.()},t[75]=Ft):Ft=t[75];let It;t[76]===Re?It=t[77]:(It=[Re],t[76]=Re,t[77]=It),(0,Q.useEffect)(Ft,It);let Lt,Rt;t[78]===Symbol.for(`react.memo_cache_sentinel`)?(Lt=()=>{let e=!0;return fetch(`/api/workspace`).then(async t=>{let n=await t.json();if(!e||!t.ok)return;let r=F(Vi,n,`workspace`,null);r&&q({contentDir:r.contentDir,pathSeparator:r.pathSeparator})}).catch(eU),()=>{e=!1}},Rt=[],t[78]=Lt,t[79]=Rt):(Lt=t[78],Rt=t[79]),(0,Q.useEffect)(Lt,Rt);let zt;t[80]!==ot||t[81]!==X||t[82]!==Qe?(zt=()=>{if(de.current===Qe){de.current=null;return}X.resetPaths($e.current,{initialExpandedPaths:ot()})},t[80]=ot,t[81]=X,t[82]=Qe,t[83]=zt):zt=t[83];let Bt;t[84]!==X||t[85]!==Qe?(Bt=[X,Qe],t[84]=X,t[85]=Qe,t[86]=Bt):Bt=t[86],(0,Q.useEffect)(zt,Bt),jV(X,ke,it,pe,Qe);let Vt;t[87]!==ke||t[88]!==A||t[89]!==X?(Vt=()=>{A||!ke||pV(be.current,X)},t[87]=ke,t[88]=A,t[89]=X,t[90]=Vt):Vt=t[90];let Ht;t[91]!==it||t[92]!==ke||t[93]!==A||t[94]!==X||t[95]!==Qe?(Ht=[ke,it,Qe,A,X],t[91]=it,t[92]=ke,t[93]=A,t[94]=X,t[95]=Qe,t[96]=Ht):Ht=t[96],(0,Q.useEffect)(Vt,Ht);let Ut,Wt;t[97]===X?(Ut=t[98],Wt=t[99]):(Ut=()=>X.subscribe(()=>{if(!X.isSearchOpen())for(let e of ce.current){let t=kV(X.getItem(e));t&&!t.isExpanded()&&t.expand()}}),Wt=[X],t[97]=X,t[98]=Ut,t[99]=Wt),(0,Q.useEffect)(Ut,Wt);let Gt,qt;t[100]===X?(Gt=t[101],qt=t[102]):(Gt=()=>X.onMutation(`remove`,e=>{let t=le.current;!t||e.path!==t.renamePath||ue.current(t)}),qt=[X],t[100]=X,t[101]=Gt,t[102]=qt),(0,Q.useEffect)(Gt,qt);let Yt;t[103]!==y||t[104]!==u||t[105]!==d||t[106]!==ne||t[107]!==E||t[108]!==f||t[109]!==ut||t[110]!==g?(Yt=async(e,t,n,r)=>{let i=t===void 0?[]:t,a=n===void 0?[]:n,o=r?.docName??re.current,s=Dk(o,e),c=r?.folderPath??(Te.current?.kind===`folder`?Te.current.folderPath:null),l=c?Jt(c,i):null,p=r?.assetPath??(Te.current?.kind===`asset`?Te.current.assetPath:null),m=p?a.find(e=>e.fromPath===p)?.toPath??Jt(p,i):null;Kt(e);let h=Ok(e,d(),f);await Promise.all(h.map(e=>u(e)));for(let t of e)y(t.toDocName);g(e,i,a),k(t=>{let n=Ck(t,e,i,a);return ut(t,n,e,a),ft(n),n}),c&&l&&l!==c?E(l):s&&s!==o?window.location.hash=gr(s):p&&m&&m!==p&&ne(m),Ti([`files`,`backlinks`,`graph`])},t[103]=y,t[104]=u,t[105]=d,t[106]=ne,t[107]=E,t[108]=f,t[109]=ut,t[110]=g,t[111]=Yt):Yt=t[111];let Xt=Yt;async function Qt(e){let t=!e.isFolder&&ht(e.sourcePath),n=t?e.sourcePath:mk(e.sourcePath,e.isFolder);R(n),N(null);try{let i=HB(e.sourcePath,e.destinationPath,e.isFolder,t);if(i.kind===`block`){gs.error(r({id:`FaBZwp`})),queueMicrotask(()=>{ct()}),Ct(),R(null);return}let a=t?i.destinationPath:mk(i.destinationPath,e.isFolder),o=e.isFolder?{kind:`folder`,fromPath:tk(n),toPath:tk(a)}:t?{kind:`asset`,fromPath:n,toPath:a}:{kind:`file`,fromPath:QO(n),toPath:QO(a)},s={docName:re.current,folderPath:Te.current?.kind===`folder`?Te.current.folderPath:null,assetPath:Te.current?.kind===`asset`?Te.current.assetPath:null},c=await Tt(await fetch(`/api/rename-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(o)}),r({id:`gijbne`}));if(!c.ok){gs.error(c.title),ct();let e=le.current;e&&e.renamePath===n?await Et(e):Ct(),R(null);return}let l=F(li,c.body,`rename-path`,{renamed:[],renamedAssets:[]});try{await Xt(l.renamed,e.isFolder?[{fromPath:tk(n),toPath:tk(a)}]:[],l.renamedAssets,s)}catch(e){console.warn(`[FileTree] post-rename reconciliation failed`,{err:e,sourceTreePath:n,destinationTreePath:a,renamedCount:l.renamed.length,renamedAssetCount:l.renamedAssets.length}),gs.error(r({id:`dDpCOp`}))}Ct(),R(null)}catch(e){console.warn(`[FileTree] rename failed:`,e);let t=r({id:`HIb0vl`});gs.error(t),N(t),ct();let i=le.current;i&&i.renamePath===n?await Et(i):Ct(),R(null)}}let $t;t[112]!==r||t[113]!==Xt||t[114]!==ct?($t=async function(e){let t=e.draggedPaths.map(t=>{let n=_k(t,e.target);return t===n?null:{sourcePath:t,destinationTreePath:n}}).filter($H);if(t.length!==0){R(t[0]?.sourcePath??null),N(null);try{let e=[],n=[],i=[],a={docName:re.current,folderPath:Te.current?.kind===`folder`?Te.current.folderPath:null,assetPath:Te.current?.kind===`asset`?Te.current.assetPath:null};for(let a of t){let t=a.sourcePath.endsWith(`/`),o=!t&&ht(a.sourcePath),s=t?{kind:`folder`,fromPath:tk(a.sourcePath),toPath:tk(a.destinationTreePath)}:o?{kind:`asset`,fromPath:a.sourcePath,toPath:a.destinationTreePath}:{kind:`file`,fromPath:QO(a.sourcePath),toPath:QO(a.destinationTreePath)},c=await Tt(await fetch(`/api/rename-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(s)}),r({id:`dOHMA0`}));if(!c.ok){gs.error(c.title),ct(),R(null);return}let l=F(li,c.body,`rename-path:drop`,{renamed:[],renamedAssets:[]});e=e.concat(l.renamed),n=n.concat(l.renamedAssets),t&&i.push({fromPath:tk(a.sourcePath),toPath:tk(a.destinationTreePath)})}try{await Xt(e,i,n,a)}catch(i){console.warn(`[FileTree] post-move reconciliation failed`,{err:i,operationCount:t.length,renamedCount:e.length,renamedAssetCount:n.length}),gs.error(r({id:`8OxKZy`}))}R(null)}catch(e){console.warn(`[FileTree] move failed:`,e),gs.error(r({id:`HIb0vl`})),ct(),R(null)}}},t[112]=r,t[113]=Xt,t[114]=ct,t[115]=$t):$t=t[115];let en=$t,tn;t[116]===Symbol.for(`react.memo_cache_sentinel`)?(tn=function(e){G({parentDir:e})},t[116]=tn):tn=t[116];let nn=tn,rn;t[117]!==r||t[118]!==y||t[119]!==Et||t[120]!==Ct||t[121]!==X||t[122]!==E||t[123]!==w||t[124]!==ct||t[125]!==Ze?(rn=async function(e,t,n){if(me.current)return;let i=le.current;i&&Ct(i);try{let i=hk(e,t,[...Ze,...nt.current]);R(i.renamePath),me.current=i.renamePath;let a=window.location.hash,o;if(e===`file`){let e=gk(`file`,i.addPath),t={path:e};n?.template&&(t.template=n.template);let a=await Tt(await fetch(`/api/create-page`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}),r({id:`fJgQHX`}));if(!a.ok){gs.error(a.title),R(null),me.current=null;return}let s=QO(e),c=F(zi,a.body,`create-page`,{docName:s}).docName;o=c;let l={kind:`document`,docName:c,docExt:e.toLowerCase().endsWith(`.mdx`)?`.mdx`:`.md`,modified:new Date().toISOString(),size:0};y(c),k(e=>{if(e.some(e=>zn(e)&&e.docName===c))return e;let t=[...e,l];return ft(t),ge.current.set($O(l),Date.now()),t}),Ti([`files`,`backlinks`,`graph`]),w(c)}else{let e=tk(i.addPath),t=await Tt(await fetch(`/api/create-folder`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:e})}),r({id:`K1ckLX`}));if(!t.ok){gs.error(t.title),R(null),me.current=null;return}o=F(Vn,t.body,`create-folder`,{path:e}).path;let n={kind:`folder`,path:o,modified:new Date().toISOString(),size:0};k(e=>{if(e.some(e=>Li(e)&&e.path===o))return e;let t=[...e,n];return ft(t),ge.current.set($O(n),Date.now()),t}),Ti([`files`]),E(o)}let s=!1,c=e=>{if(e.key!==`Enter`)return;let t=le.current;!t||t.renamePath!==i.renamePath||queueMicrotask(()=>Ct(t))};document.addEventListener(`keydown`,c,!0),le.current={kind:e,renamePath:i.renamePath,createdPath:o,previousHash:a,disposeCommitListener:()=>{s||(s=!0,document.removeEventListener(`keydown`,c,!0))}},R(null),me.current=null,X.add(i.addPath),X.startRenaming(i.renamePath,{removeIfCanceled:!0})}catch(e){console.warn(`[FileTree] create placeholder failed:`,e),gs.error(r({id:`S6l5dv`}));let t=le.current;t?await Et(t):Ct(),R(null),me.current=null,ct()}},t[117]=r,t[118]=y,t[119]=Et,t[120]=Ct,t[121]=X,t[122]=E,t[123]=w,t[124]=ct,t[125]=Ze,t[126]=rn):rn=t[126];let an=rn,on;t[127]===X?on=t[128]:(on=function(e){let t=nk(e);(0,Q.startTransition)(()=>{for(let e of nt.current)if(e===t||e.startsWith(t)){let t=kV(X.getItem(e));t&&t.expand()}})},t[127]=X,t[128]=on);let sn=on,cn;t[129]===X?cn=t[130]:(cn=function(e){let t=nk(e),n=new Set(ce.current);(0,Q.startTransition)(()=>{for(let e of[...nt.current].reverse())if((e===t||e.startsWith(t))&&!n.has(e)){let t=kV(X.getItem(e));t&&t.collapse()}})},t[129]=X,t[130]=cn);let ln=cn,un;t[131]!==ee||t[132]!==rt||t[133]!==a||t[134]!==o||t[135]!==ae||t[136]!==L||t[137]!==Et||t[138]!==O||t[139]!==tt||t[140]!==en||t[141]!==Qt||t[142]!==Ye||t[143]!==xt||t[144]!==Re||t[145]!==Le||t[146]!==Ze?(un=()=>{J.current=O,re.current=a,Te.current=o,oe.current=ae,me.current=L,_e.current=Le,ve.current=Re,$e.current=Ze,nt.current=tt,ce.current=rt,ue.current=Et,xe.current=e=>{if(pe.current||e.length!==1)return;let t=e[0];t&&ee(Ye(t),O)},Ce.current=e=>{xt(e)||gs.error(e)},Se.current=Qt,we.current=en},t[131]=ee,t[132]=rt,t[133]=a,t[134]=o,t[135]=ae,t[136]=L,t[137]=Et,t[138]=O,t[139]=tt,t[140]=en,t[141]=Qt,t[142]=Ye,t[143]=xt,t[144]=Re,t[145]=Le,t[146]=Ze,t[147]=un):un=t[147],(0,Q.useLayoutEffect)(un);let dn,fn;t[148]===X?(dn=t[149],fn=t[150]):(dn=()=>{let e=e=>{let t=(e.metaKey||e.ctrlKey)&&!e.altKey,n=e.key.toLowerCase(),r=t&&n===`a`,i=t&&!e.shiftKey&&n===`d`;if(!r&&!i||PH(e.target))return;let a=be.current,o=e.target,s=document.activeElement,c=o instanceof Node&&a?.contains(o),l=s instanceof Node&&a?.contains(s);if(!c&&!l)return;if(i){let t=X.getFocusedPath()??X.getSelectedPaths()[0]??null;if(!t)return;let n=X.getItem(t)??X.getItem(nk(t)),r=n?.isDirectory()?nk(tk(n.getPath())):t;if(oe.current.has(r))return;yt.current(AH(r,J.current)),e.preventDefault(),e.stopPropagation();return}let u=new Set([...nt.current,...$e.current]);pe.current=!0;for(let e of u)e&&X.getItem(e)?.select();queueMicrotask(()=>{pe.current=!1}),e.preventDefault(),e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},fn=[X],t[148]=X,t[149]=dn,t[150]=fn),(0,Q.useEffect)(dn,fn);let pn,mn;t[151]!==O.length||t[152]!==A?(pn=()=>{if(A||O.length===0)return;let e=be.current?.querySelector(Fj)?.shadowRoot;if(!e)return;let t=QH,n=()=>{for(let n of e.querySelectorAll(`[data-item-path]`)){let e=n.dataset.itemPath;if(!e)continue;let r=t(e);n.title!==r&&(n.title=r)}let n=e.querySelector(`[data-type="context-menu-anchor"]`);if(n){let r=e.querySelector(`[data-item-context-hover="true"][data-item-path]`)?.dataset.itemPath,i=r?t(r):``;n.title!==i&&(n.title=i)}};n();let r=new MutationObserver(n);return r.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`data-item-path`,`data-item-context-hover`]}),()=>r.disconnect()},mn=[A,O.length],t[151]=O.length,t[152]=A,t[153]=pn,t[154]=mn):(pn=t[153],mn=t[154]),(0,Q.useEffect)(pn,mn);let hn,gn;t[155]!==O.length||t[156]!==A?(hn=()=>{if(A||O.length===0)return;let e=be.current?.querySelector(Fj)?.shadowRoot;if(!e)return;let t=()=>KB(e);t();let n=new MutationObserver(t);return n.observe(e,{subtree:!0,childList:!0,characterData:!0,attributes:!0,attributeFilter:[`data-item-path`]}),()=>n.disconnect()},gn=[A,O.length],t[155]=O.length,t[156]=A,t[157]=hn,t[158]=gn):(hn=t[157],gn=t[158]),(0,Q.useEffect)(hn,gn);let _n,vn;t[159]!==O.length||t[160]!==A?(_n=()=>{if(A||O.length===0)return;let e=be.current?.querySelector(Fj)?.shadowRoot;if(!e)return;let t=()=>oV(e);t();let n=new MutationObserver(t);return n.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`data-item-path`]}),()=>n.disconnect()},vn=[A,O.length],t[159]=O.length,t[160]=A,t[161]=_n,t[162]=vn):(_n=t[161],vn=t[162]),(0,Q.useEffect)(_n,vn);let yn;t[163]===Symbol.for(`react.memo_cache_sentinel`)?(yn={folderCount:0,expandedCount:0},t[163]=yn):yn=t[163];let bn=(0,Q.useRef)(yn),xn=(0,Q.useRef)(an),Sn=(0,Q.useRef)(nn),Cn;t[164]===an?Cn=t[165]:(Cn=()=>{xn.current=an,Sn.current=nn},t[164]=an,t[165]=Cn),(0,Q.useEffect)(Cn);let wn,Tn;t[166]===X?(wn=t[167],Tn=t[168]):(wn=()=>({startCreating(e,t){xn.current(e,t)},startCreatingFromTemplate(e){Sn.current(e)},createFromTemplate(e,t){xn.current(`file`,e,{template:t})},expandAll(){(0,Q.startTransition)(()=>{for(let e of nt.current){let t=kV(X.getItem(e));t&&t.expand()}})},collapseAll(){let e=new Set(ce.current);(0,Q.startTransition)(()=>{for(let t of[...nt.current].reverse()){if(e.has(t))continue;let n=kV(X.getItem(t));n&&n.collapse()}})},getFolderState(){let e=nt.current,t=0;for(let n of e)kV(X.getItem(n))?.isExpanded()&&t++;let n=e.length,r=bn.current;if(r.folderCount===n&&r.expandedCount===t)return r;let i={folderCount:n,expandedCount:t};return bn.current=i,i},subscribe(e){return X.subscribe(e)}}),Tn=[X],t[166]=X,t[167]=wn,t[168]=Tn),(0,Q.useImperativeHandle)(n,wn,Tn);let En;t[169]!==Ct||t[170]!==u||t[171]!==c||t[172]!==X?(En=async function(e,t,n){let r=FH(e,J.current,nt.current),i=le.current;i&&e.some(e=>IH(e,i))&&(i.kind===`file`?r.docNames.add(i.createdPath):r.folderPaths.add(i.createdPath),Ct(i));let a=new Set([...r.docNames,...t]),o=new Set([...r.folderPaths,...n]),s=new Set([...r.assetPaths,...e.filter(ZH).map(XH)]);c([...[...a].map(YH),...[...o].map(JH),...[...s].map(qH)],{force:!0}),await Promise.all([...a].map(e=>u(e)));for(let t of e){let e=t.kind===`folder`?nk(t.path):t.kind===`asset`?t.path:ZO(t.path,t.docExt);X.getItem(e)&&X.remove(e,t.kind===`folder`?{recursive:!0}:void 0)}k(e=>{let t=wk(e,[...a],void 0,[...s]);for(let e of o)t=wk(t,[],e);return ft(t),t}),Ti([`files`,`backlinks`,`graph`])},t[169]=Ct,t[170]=u,t[171]=c,t[172]=X,t[173]=En):En=t[173];let Dn=En,On;t[174]!==r||t[175]!==Dn?(On=async function(e){let t=[],n=[],i=[];for(let a of e){let e=a.kind;R(a.path);let o=await Tt(await fetch(`/api/delete-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:e,path:a.path})}),r({id:`7JtSLi`}));if(!o.ok)return i.length>0&&await Dn(i,t,n),gs.error(o.title),!1;let s=F(Gn,o.body,`delete-path`,{deletedDocNames:[]});t.push(...s.deletedDocNames),e===`folder`&&n.push(a.path),i.push(a)}return await Dn(i,t,n),!0},t[174]=r,t[175]=Dn,t[176]=On):On=t[176];let kn=On,An;t[177]===Symbol.for(`react.memo_cache_sentinel`)?(An=async function(e,t,n){let r=[],i=[];for(let a of e){R(a.path);let e=kk(a,n),o=await t.shell.trashItem(e);o.ok?r.push(a):i.push({kind:a.kind,path:a.path,name:a.name,reason:SV(o.reason),detail:o.detail})}return{trashed:r,failed:i}},t[177]=An):An=t[177];let jn=An,Mn;t[178]===r?Mn=t[179]:(Mn=async function(e){let t=[],n=[],i=[];for(let a of e){let e=a.kind;try{let o=await Tt(await fetch(`/api/trash/cleanup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:e,path:a.path})}),r({id:`DVh_Tb`}));if(!o.ok){console.warn(`[FileTree] trash-cleanup failed`,{target:`${a.kind}:${a.path}`,reason:o.title}),i.push({target:a,reason:o.title});continue}let s=F(oi,o.body,`trash-cleanup`,{deletedDocNames:[]});t.push(...s.deletedDocNames),e===`folder`&&n.push(a.path)}catch(e){let t=e;console.warn(`[FileTree] trash-cleanup threw`,{target:`${a.kind}:${a.path}`,err:t}),i.push({target:a,reason:r({id:`r4R7AZ`})})}}if(i.length>0){let e=i.length;gs.error(r({id:`IrB5AK`,values:{failedCount:e}}),{description:r({id:`vEJDlt`})})}return i.length===e.length&&e.length>0?null:{deletedDocNames:t,deletedFolderPaths:n}},t[178]=r,t[179]=Mn);let Nn=Mn,Pn;t[180]!==r||t[181]!==U||t[182]!==Dn||t[183]!==kn||t[184]!==Nn||t[185]!==ct||t[186]!==K?(Pn=async function(e){let t=e.map(e=>Tk(e,J.current)),n=t[0];if(!n)return;let i=U.filter(e=>t.some(t=>{if(t.kind===`file`){let n=`${t.path}${t.docExt??`.md`}`;return e.file===n}return t.kind===`folder`?e.file.startsWith(`${t.path}/`):!1}));if(i.length>0){let e=i.slice(0,3).map(KH),t=i.length>e.length?`, +${i.length-e.length} more`:``;gs.error(`Cannot delete files with unresolved conflicts`,{description:`Resolve the conflict on ${e.join(`, `)}${t} before deleting.`});return}R(n.path),B(null);let a=typeof window<`u`?window.okDesktop:void 0;try{if(a&&K){let{trashed:e,failed:n}=await jn(t,a,K);if(e.length>0){let t=await Nn(e);t?await Dn(e,t.deletedDocNames,t.deletedFolderPaths):await Dn(e,e.filter(GH).map(WH),e.filter(UH).map(HH))}n.length>0&&H({failed:n,originalTargets:[...t]}),R(null)}else{let e=await kn(t);R(null),e||ct()}}catch(e){let t=e,n=t instanceof Error?t.message:String(t);console.warn(`[FileTree] delete failed:`,t),gs.error(r({id:`0eHrMb`}),{description:n}),R(null),ct()}},t[180]=r,t[181]=U,t[182]=Dn,t[183]=kn,t[184]=Nn,t[185]=ct,t[186]=K,t[187]=Pn):Pn=t[187];let In=Pn,Ln;t[188]!==r||t[189]!==kn||t[190]!==ct||t[191]!==V?(Ln=async function(){if(!V)return;let e=new Set(V.failed.map(VH)),t=V.originalTargets.filter(t=>e.has(`${t.kind}:${t.path}`));if(H(null),t.length!==0){R(t[0]?.path??null);try{let e=await kn(t);R(null),e||ct()}catch(e){let t=e,n=t instanceof Error?t.message:String(t);console.warn(`[FileTree] hard-delete fallback failed:`,t),gs.error(r({id:`0eHrMb`}),{description:n}),R(null),ct()}}},t[188]=r,t[189]=kn,t[190]=ct,t[191]=V,t[192]=Ln):Ln=t[192];let Rn=Ln,Bn;t[193]!==In||t[194]!==V?(Bn=async function(){if(!V)return;let e=new Set(V.failed.map(BH)),t=V.originalTargets.filter(t=>e.has(`${t.kind}:${t.path}`));H(null),await In(t)},t[193]=In,t[194]=V,t[195]=Bn):Bn=t[195];let Hn=Bn,Un=(0,Q.useRef)(In),Wn;t[196]===In?Wn=t[197]:(Wn=()=>{Un.current=In},t[196]=In,t[197]=Wn),(0,Q.useEffect)(Wn);let Kn,qn;t[198]===Symbol.for(`react.memo_cache_sentinel`)?(Kn=()=>LV(e=>{if(e.kind===`doc`||e.kind===`folder-index`){let t=e.docName,n=J.current.find(e=>zn(e)&&e.docName===t);Un.current([{kind:`file`,path:t,name:t.split(`/`).pop()??t,docExt:n?.docExt}]);return}if(e.kind===`folder`){Un.current([{kind:`folder`,path:e.folderPath,name:e.folderPath.split(`/`).pop()??e.folderPath}]);return}if(e.kind===`asset`){Un.current([{kind:`asset`,path:e.assetPath,name:e.assetPath.split(`/`).pop()??e.assetPath}]);return}console.warn(JSON.stringify({event:`file-tree-menu-action-delete-unsupported-kind`,kind:e.kind}))}),qn=[],t[198]=Kn,t[199]=qn):(Kn=t[198],qn=t[199]),(0,Q.useEffect)(Kn,qn);let Jn,Yn;t[200]===Symbol.for(`react.memo_cache_sentinel`)?(Jn=()=>VV(e=>{if(e.kind===`doc`||e.kind===`folder-index`){let t=e.docName,n=J.current.find(e=>zn(e)&&e.docName===t);yt.current({kind:`file`,path:t,name:t.split(`/`).pop()??t,docExt:n?.docExt});return}if(e.kind===`folder`){yt.current({kind:`folder`,path:e.folderPath,name:e.folderPath.split(`/`).pop()??e.folderPath});return}console.warn(JSON.stringify({event:`file-tree-menu-action-duplicate-unsupported-kind`,kind:e.kind}))}),Yn=[],t[200]=Jn,t[201]=Yn):(Jn=t[200],Yn=t[201]),(0,Q.useEffect)(Jn,Yn);let Xn,Zn;t[202]===X?(Xn=t[203],Zn=t[204]):(Xn=()=>zV(e=>{if(e.kind===`doc`||e.kind===`folder-index`){let t=e.docName,n=ZO(t,J.current.find(e=>zn(e)&&e.docName===t)?.docExt);X.startRenaming(n);return}if(e.kind===`folder`){X.startRenaming(e.folderPath);return}if(e.kind===`asset`){X.startRenaming(e.assetPath);return}console.warn(JSON.stringify({event:`file-tree-menu-action-rename-unsupported-kind`,kind:e.kind}))}),Zn=[X],t[202]=X,t[203]=Xn,t[204]=Zn),(0,Q.useEffect)(Xn,Zn);let Qn;t[205]===Symbol.for(`react.memo_cache_sentinel`)?(Qn=function(){let e=fe.current;e&&lH(e),fe.current=null},t[205]=Qn):Qn=t[205];let $n=Qn,er;t[206]===h?er=t[207]:(er=function(e){let t=lU(e.nativeEvent);if(!t||t.endsWith(`/`)){$n();return}let n=QO(t),r=J.current.find(e=>$O(e)===t);if(r&&kr(r)){$n();return}if(r&&zn(r)&&Ii(r.size)){$n();return}fe.current!==n&&($n(),fe.current=n,cH(n,e=>h(e)))},t[206]=h,t[207]=er);let tr=er,nr;t[208]!==ee||t[209]!==X||t[210]!==E?(nr=function(e){if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=uU(e.nativeEvent);if(!t||t.getAttribute(`aria-selected`)!==`true`)return;let n=t.dataset.itemPath;if(!n)return;let r=t.dataset.itemType===`folder`?nk(n):n;if(X.getSelectedPaths().length!==1)return;if(t.dataset.itemType===`folder`){let e=tk(r);if(window.location.hash===_r(e))return;queueMicrotask(()=>E(e));return}let i=QO(r);window.location.hash!==gr(i)&&queueMicrotask(()=>ee(r))},t[208]=ee,t[209]=X,t[210]=E,t[211]=nr):nr=t[211];let rr=nr;if(A){let e;return t[212]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(fU,{}),t[212]=e):e=t[212],e}if(O.length===0){if(M){let e;return t[213]===M?e=t[214]:(e=(0,Z.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-8`,children:(0,Z.jsx)(`span`,{className:`select-none text-sidebar-foreground/50 text-sm`,children:M})}),t[213]=M,t[214]=e),e}let e;t[215]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(`span`,{className:`select-none text-sidebar-foreground/30 text-sm`,children:(0,Z.jsx)(s,{id:`xiv-dW`})}),t[215]=e):e=t[215];let n;t[216]===an?n=t[217]:(n=()=>an(`file`,``),t[216]=an,t[217]=n);let r;t[218]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,Z.jsx)(s,{id:`6ibbCg`}),t[218]=r):r=t[218];let i;return t[219]===n?i=t[220]:(i=(0,Z.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 py-8`,children:[e,(0,Z.jsx)(Qi,{variant:`link`,size:`sm`,className:`font-mono uppercase`,onClick:n,children:r})]}),t[219]=n,t[220]=i),i}let ir=L!==null,ar=z?.targets[0]??null,or;t[221]!==M||t[222]!==P?(or=(M||P!==null)&&(0,Z.jsxs)(Z.Fragment,{children:[M&&(0,Z.jsx)(`span`,{role:`alert`,className:`px-3 pb-1 text-destructive text-xs`,children:M}),P!==null&&(0,Z.jsx)(`span`,{role:`status`,className:`px-3 pb-1 text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`_HekAK`,values:{truncatedShownCount:P}})})]}),t[221]=M,t[222]=P,t[223]=or):or=t[223];let sr;t[224]===v?sr=t[225]:(sr=TH(v),t[224]=v,t[225]=sr);let cr;t[226]!==ir||t[227]!==ae||t[228]!==ln||t[229]!==O||t[230]!==sn||t[231]!==tt||t[232]!==vt||t[233]!==Ne||t[234]!==Ie||t[235]!==X||t[236]!==Pe||t[237]!==Fe||t[238]!==an||t[239]!==K?(cr=(e,t)=>(0,Z.jsx)(LH,{item:e,context:t,anyActionBusy:ir,workspace:K,handoff:Ne,model:X,okignoreBinding:Pe,projectLocalBinding:Fe,mergedConfig:Ie,onStartCreating:an,onCreateFromTemplate:(e,t)=>an(`file`,e,{template:t}),onDuplicate:vt,onDelete:e=>B({targets:e}),onExpandSubtree:sn,onCollapseSubtree:ln,folderTreePaths:tt,isAsset:ae.has(e.path),documents:O}),t[226]=ir,t[227]=ae,t[228]=ln,t[229]=O,t[230]=sn,t[231]=tt,t[232]=vt,t[233]=Ne,t[234]=Ie,t[235]=X,t[236]=Pe,t[237]=Fe,t[238]=an,t[239]=K,t[240]=cr):cr=t[240];let lr;t[241]!==rr||t[242]!==tr||t[243]!==X||t[244]!==or||t[245]!==sr||t[246]!==cr?(lr=(0,Z.jsx)(`div`,{ref:be,className:`flex min-h-0 flex-1 flex-col`,children:(0,Z.jsx)(RB,{header:or,model:X,style:sr,onClickCapture:rr,onMouseMove:tr,onMouseLeave:$n,renderContextMenu:cr})}),t[241]=rr,t[242]=tr,t[243]=X,t[244]=or,t[245]=sr,t[246]=cr,t[247]=lr):lr=t[247];let ur=!!z,dr;t[248]===L?dr=t[249]:(dr=e=>{!e&&!L&&B(null)},t[248]=L,t[249]=dr);let fr;t[250]!==r||t[251]!==L||t[252]!==z||t[253]!==In||t[254]!==ar?(fr=z&&ar&&(0,Z.jsx)(_a,{...(()=>{let e=yV(typeof window<`u`&&window.okDesktop!=null?`electron`:`web`,z.targets);if(e)return{customTitle:e.title,customDescription:``,customDetail:e.detail,customConfirmLabel:e.confirmLabel,customConfirmLabelBusy:e.confirmLabelBusy,children:e.listedTargets?(0,Z.jsx)(`ul`,{className:`flex flex-col gap-1 font-mono text-foreground text-xs`,children:e.listedTargets.map(zH)}):null};let t=z.targets.length,n=ar.name;return{itemName:t===1?ar.kind===`folder`?`${ar.name}/`:ar.kind===`file`?`${ar.name}${ar.docExt??`.md`}`:ar.name:void 0,customTitle:t>1?r({id:`abiHje`}):void 0,customDescription:t>1?r({id:`WMIKXK`,values:{targetCount:t}}):ar.kind===`folder`?r({id:`a5W0q0`,values:{folderName:n}}):void 0}})(),isSubmitting:L!==null,onDelete:()=>In(z.targets)}),t[250]=r,t[251]=L,t[252]=z,t[253]=In,t[254]=ar,t[255]=fr):fr=t[255];let pr;t[256]!==ur||t[257]!==dr||t[258]!==fr?(pr=(0,Z.jsx)(ps,{open:ur,onOpenChange:dr,children:fr}),t[256]=ur,t[257]=dr,t[258]=fr,t[259]=pr):pr=t[259];let mr=!!V,hr;t[260]===L?hr=t[261]:(hr=e=>{!e&&!L&&H(null)},t[260]=L,t[261]=hr);let vr;t[262]!==L||t[263]!==Rn||t[264]!==Hn||t[265]!==V?(vr=V&&(0,Z.jsx)(EV,{failedTargets:V.failed,isSubmitting:L!==null,onDeletePermanently:Rn,onRetry:Hn,onCancel:()=>H(null)}),t[262]=L,t[263]=Rn,t[264]=Hn,t[265]=V,t[266]=vr):vr=t[266];let yr;t[267]!==mr||t[268]!==hr||t[269]!==vr?(yr=(0,Z.jsx)(ps,{open:mr,onOpenChange:hr,children:vr}),t[267]=mr,t[268]=hr,t[269]=vr,t[270]=yr):yr=t[270];let br=W!==null,xr;t[271]===Symbol.for(`react.memo_cache_sentinel`)?(xr=e=>{e||G(null)},t[271]=xr):xr=t[271];let Sr=W?.parentDir??``,Cr;t[272]!==Sr||t[273]!==br?(Cr=(0,Z.jsx)(km,{open:br,onOpenChange:xr,kind:`file`,initialDir:Sr,defaultToTemplate:!0}),t[272]=Sr,t[273]=br,t[274]=Cr):Cr=t[274];let wr;return t[275]!==Cr||t[276]!==lr||t[277]!==pr||t[278]!==yr?(wr=(0,Z.jsxs)(Z.Fragment,{children:[lr,pr,yr,Cr]}),t[275]=Cr,t[276]=lr,t[277]=pr,t[278]=yr,t[279]=wr):wr=t[279],wr}function zH(e){return(0,Z.jsx)(`li`,{"data-testid":`delete-target-row`,children:bV(e)},`${e.kind}:${e.path}`)}function BH(e){return`${e.kind}:${e.path}`}function VH(e){return`${e.kind}:${e.path}`}function HH(e){return e.path}function UH(e){return e.kind===`folder`}function WH(e){return e.path}function GH(e){return e.kind===`file`}function KH(e){return e.file}function qH(e){return Je(e)}function JH(e){return Zt(e)}function YH(e){return De(e)}function XH(e){return e.path}function ZH(e){return e.kind===`asset`}function QH(e){return e.endsWith(`/`)?e.slice(0,-1):e}function $H(e){return!!e}function eU(e){console.warn(`[FileTree] /api/workspace fetch failed:`,e)}function tU(e){console.warn(`[FileTree] unmount cleanup failed:`,e)}function nU(e){gs.error(e)}function rU(){}function iU(e){return gs.error(e)}function aU(){}function oU(){}async function sU(){}function cU(e){return $O(e)}function lU(e){return uU(e)?.dataset.itemPath??null}function uU(e){for(let t of e.composedPath())if(t instanceof HTMLElement&&t.dataset.itemPath)return t;return null}var dU=[`w-3/4`,`w-2/3`,`w-4/5`,`w-1/2`,`w-3/5`,`w-2/3`];function fU(){let e=(0,$.c)(5),{_:t}=i(),n;e[0]===t?n=e[1]:(n=t({id:`5Tk8Fb`}),e[0]=t,e[1]=n);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=dU.map(pU),e[2]=r):r=e[2];let a;return e[3]===n?a=e[4]:(a=(0,Z.jsx)(`div`,{className:`flex flex-1 flex-col gap-1 px-2 py-2`,role:`status`,"aria-busy":`true`,"aria-label":n,children:r}),e[3]=n,e[4]=a),a}function pU(e,t){return(0,Z.jsxs)(`div`,{className:`flex h-6 items-center gap-2`,children:[(0,Z.jsx)(Sa,{className:`h-3 w-3 shrink-0 rounded-sm`}),(0,Z.jsx)(Sa,{className:`h-3 ${e}`})]},t)}function mU(e){return e?lr._({id:`wTcjov`}):null}function hU(e){let t=(0,$.c)(37),{_:n}=i(),r=ih(),{merged:a}=gt(),o=a?.appearance?.preview?.autoOpen??!0;if(r)return null;let{input:c,installStates:l,dispatch:u,webFallbackVisible:d}=e,f=d===void 0?!0:d,p=c===null,m,h,g,_,v,y,b;if(t[0]!==n||t[1]!==o||t[2]!==u||t[3]!==c||t[4]!==p||t[5]!==l||t[6]!==f){b=Symbol.for(`react.early_return_sentinel`);bb0:{let e=mU(p),r;t[14]===l?r=t[15]:(r=e=>l[e.id]?.installed===!0,t[14]=l,t[15]=r);let i=sh.filter(r);g=l[`claude-code`]?.installed===!0;let a;t[16]!==o||t[17]!==c?(a=c!==null&&c.docContext!==null?Ui(c.docContext.relativePath,o):``,t[16]=o,t[17]=c,t[18]=a):a=t[18];let d=a,x;t[19]!==c||t[20]!==d?(x=()=>{c!==null&&Db(d)},t[19]=c,t[20]=d,t[21]=x):x=t[21],_=x;let S=f&&!g;if(i.length===0&&!S){b=null;break bb0}h=Lk,t[22]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Z.jsxs)(Bk,{children:[(0,Z.jsx)(ua,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`O7_W_a`})]}),t[22]=y):y=t[22],m=Vk,v=i.map(t=>{let r=!p,{displayName:i}=t,a=n(e?{id:`1ZpfyB`,values:{displayName:i,hint:e}}:{id:`WqLq6M`,values:{displayName:i}});return(0,Z.jsxs)(zk,{disabled:!r,onSelect:()=>{c&&u(t.id,c)},"data-testid":`empty-space-open-in-${t.id}`,"aria-label":a,children:[(0,Z.jsx)(xb,{id:t.id,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:t.displayName}),e?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:e}):null]},t.id)})}t[0]=n,t[1]=o,t[2]=u,t[3]=c,t[4]=p,t[5]=l,t[6]=f,t[7]=m,t[8]=h,t[9]=g,t[10]=_,t[11]=v,t[12]=y,t[13]=b}else m=t[7],h=t[8],g=t[9],_=t[10],v=t[11],y=t[12],b=t[13];if(b!==Symbol.for(`react.early_return_sentinel`))return b;let x;t[23]!==n||t[24]!==g||t[25]!==_||t[26]!==p||t[27]!==f?(x=f&&!g?(0,Z.jsxs)(zk,{onSelect:_,disabled:p,"data-testid":`empty-space-open-in-claude-web-fallback`,"aria-label":n({id:`aA51jP`}),children:[(0,Z.jsx)(Bt,{className:`size-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:(0,Z.jsx)(s,{id:`0S9PW_`})}),(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`pcfY8r`})})]}):null,t[23]=n,t[24]=g,t[25]=_,t[26]=p,t[27]=f,t[28]=x):x=t[28];let S;t[29]!==m||t[30]!==v||t[31]!==x?(S=(0,Z.jsxs)(m,{children:[v,x]}),t[29]=m,t[30]=v,t[31]=x,t[32]=S):S=t[32];let C;return t[33]!==h||t[34]!==y||t[35]!==S?(C=(0,Z.jsxs)(h,{children:[y,S]}),t[33]=h,t[34]=y,t[35]=S,t[36]=C):C=t[36],C}var gU=(e,t,n)=>Kl(e,t,n,`ProjectSwitcher`);function _U(e){let t=(0,$.c)(94),{bridge:n}=e,{_:r}=i(),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=[],t[0]=a):a=t[0];let[o,c]=(0,Q.useState)(a),[l,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(!1),g=nO(),_;t[1]!==r||t[2]!==n.project||t[3]!==l?(_=()=>{if(!l)return;let e=!1;return gU(async()=>{let t=await n.project.listRecent();e||c(t)},r({id:`fYKgzG`})),()=>{e=!0}},t[1]=r,t[2]=n.project,t[3]=l,t[4]=_):_=t[4];let v;t[5]!==r||t[6]!==n||t[7]!==l?(v=[l,n,r],t[5]=r,t[6]=n,t[7]=l,t[8]=v):v=t[8],(0,Q.useEffect)(_,v);let y;t[9]!==r||t[10]!==n.project?(y=e=>{d(!1),gU(()=>n.project.open({path:e,target:`new-window`,entryPoint:`recents`}),r({id:`SUOoXn`}))},t[9]=r,t[10]=n.project,t[11]=y):y=t[11];let b=y,x;t[12]!==r||t[13]!==n.dialog||t[14]!==n.project?(x=()=>{d(!1),gU(async()=>{let e=await n.dialog.openFolder();e&&await n.project.open({path:e,target:`new-window`,entryPoint:`pick-existing`})},r({id:`gmJ0An`}))},t[12]=r,t[13]=n.dialog,t[14]=n.project,t[15]=x):x=t[15];let S=x,C;t[16]!==r||t[17]!==n.navigator?(C=()=>{d(!1),gU(()=>n.navigator.open(),r({id:`jol95m`}))},t[16]=r,t[17]=n.navigator,t[18]=C):C=t[18];let w=C,T;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(T=()=>{d(!1),h(!0)},t[19]=T):T=t[19];let E=T,D=n.config.projectPath,k,A,j,M,N,P,F,I,L,R;if(t[20]!==r||t[21]!==g||t[22]!==n.config.projectName||t[23]!==n.config.projectPath||t[24]!==D||t[25]!==l||t[26]!==b||t[27]!==o||t[28]!==f){let e;t[39]===D?e=t[40]:(e=e=>e.path!==D,t[39]=D,t[40]=e);let i=o.filter(e),a=f.trim().toLowerCase(),c=a?i.filter(e=>e.name.toLowerCase().includes(a)||e.path.toLowerCase().includes(a)):i;A=Ya,P=l,t[41]===Symbol.for(`react.memo_cache_sentinel`)?(F=e=>{d(e),e||p(``)},t[41]=F):F=t[41];let u=g!==null&&`h-auto py-1.5`,m;t[42]===u?m=t[43]:(m=Gi(`justify-between text-sidebar-foreground/70 hover:text-sidebar-foreground! data-open:hover:text-sidebar-foreground!`,u),t[42]=u,t[43]=m);let h;t[44]===r?h=t[45]:(h=r({id:`zZ_I5K`}),t[44]=r,t[45]=h);let _;t[46]===n.config.projectName?_=t[47]:(_=(0,Z.jsx)(`span`,{className:`truncate`,children:n.config.projectName}),t[46]=n.config.projectName,t[47]=_);let v;t[48]===g?v=t[49]:(v=g===null?null:(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1 text-xs text-sidebar-foreground/50 group-hover/menu-button:text-sidebar-foreground`,"data-testid":`project-switcher-branch`,children:[(0,Z.jsx)(Ae,{"aria-hidden":`true`,className:`size-3! shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:g})]}),t[48]=g,t[49]=v);let y;t[50]!==_||t[51]!==v?(y=(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[_,v]}),t[50]=_,t[51]=v,t[52]=y):y=t[52];let x;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,Z.jsx)(zc,{"aria-hidden":`true`,className:`opacity-60`}),t[53]=x):x=t[53];let S;t[54]!==m||t[55]!==h||t[56]!==y?(S=(0,Z.jsx)(Tr,{asChild:!0,children:(0,Z.jsx)(Ho,{asChild:!0,children:(0,Z.jsxs)(XD,{className:m,"data-testid":`project-switcher-trigger`,"aria-label":h,children:[y,x]})})}),t[54]=m,t[55]=h,t[56]=y,t[57]=S):S=t[57];let C;t[58]===n.config.projectPath?C=t[59]:(C=(0,Z.jsx)(nr,{side:`right`,className:`max-w-xs break-all`,children:n.config.projectPath}),t[58]=n.config.projectPath,t[59]=C),t[60]!==S||t[61]!==C?(I=(0,Z.jsxs)(Yn,{children:[S,C]}),t[60]=S,t[61]=C,t[62]=I):I=t[62],k=xo,L=`start`,R=`top`,j=`min-w-[260px]`,M=`project-switcher-menu`,N=i.length===0?(0,Z.jsx)(No,{className:`font-normal text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`HNnVG1`})}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(yS,{className:`mb-1 h-8 border-0 shadow-none has-[[data-slot=input-group-control]:focus-visible]:ring-0`,children:[(0,Z.jsx)(wS,{"aria-label":r({id:`H8Ng4Z`}),placeholder:r({id:`8S1E33`}),value:f,onChange:e=>p(e.target.value),onKeyDown:vU,"data-testid":`project-switcher-search`}),(0,Z.jsx)(xS,{children:(0,Z.jsx)(O,{"aria-hidden":`true`})})]}),(0,Z.jsx)(Vo,{}),c.length===0?(0,Z.jsx)(No,{className:`font-normal text-muted-foreground text-xs`,role:`status`,"aria-live":`polite`,children:(0,Z.jsx)(s,{id:`pEQFsW`})}):(0,Z.jsx)(`div`,{className:`max-h-64 overflow-y-auto overscroll-contain subtle-scrollbar scroll-fade-mask`,children:c.slice(0,10).map(e=>(0,Z.jsxs)(Wo,{disabled:e.missing,onSelect:()=>b(e.path),className:`flex flex-col items-start gap-0.5`,"data-testid":`project-switcher-recent-${e.path}`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,Z.jsxs)(`span`,{className:`max-w-[240px] truncate text-muted-foreground text-xs`,children:[e.path,e.missing?r({id:`2Znqb1`}):``]})]},e.path))})]}),t[20]=r,t[21]=g,t[22]=n.config.projectName,t[23]=n.config.projectPath,t[24]=D,t[25]=l,t[26]=b,t[27]=o,t[28]=f,t[29]=k,t[30]=A,t[31]=j,t[32]=M,t[33]=N,t[34]=P,t[35]=F,t[36]=I,t[37]=L,t[38]=R}else k=t[29],A=t[30],j=t[31],M=t[32],N=t[33],P=t[34],F=t[35],I=t[36],L=t[37],R=t[38];let z;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,Z.jsx)(Vo,{}),t[63]=z):z=t[63];let B,V;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,Z.jsx)(yt,{"aria-hidden":`true`,className:`text-muted-foreground`}),V=(0,Z.jsx)(s,{id:`PVUn_c`}),t[64]=B,t[65]=V):(B=t[64],V=t[65]);let H;t[66]===S?H=t[67]:(H=(0,Z.jsxs)(Wo,{onSelect:S,"data-testid":`project-switcher-open-folder`,children:[B,V]}),t[66]=S,t[67]=H);let U,W;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(U=(0,Z.jsx)(u,{"aria-hidden":`true`,className:`text-muted-foreground`}),W=(0,Z.jsx)(s,{id:`2Xs2jo`}),t[68]=U,t[69]=W):(U=t[68],W=t[69]);let G;t[70]===w?G=t[71]:(G=(0,Z.jsxs)(Wo,{onSelect:w,"data-testid":`project-switcher-switch-project`,children:[U,W]}),t[70]=w,t[71]=G);let K;t[72]===Symbol.for(`react.memo_cache_sentinel`)?(K=(0,Z.jsxs)(Wo,{onSelect:E,"data-testid":`project-switcher-new-project`,children:[(0,Z.jsx)(ge,{"aria-hidden":`true`,className:`text-muted-foreground`}),(0,Z.jsx)(s,{id:`gKi-a_`})]}),t[72]=K):K=t[72];let q;t[73]!==k||t[74]!==j||t[75]!==M||t[76]!==N||t[77]!==H||t[78]!==G||t[79]!==L||t[80]!==R?(q=(0,Z.jsxs)(k,{align:L,side:R,className:j,"data-testid":M,children:[N,z,H,G,K]}),t[73]=k,t[74]=j,t[75]=M,t[76]=N,t[77]=H,t[78]=G,t[79]=L,t[80]=R,t[81]=q):q=t[81];let J;t[82]!==A||t[83]!==P||t[84]!==F||t[85]!==I||t[86]!==q?(J=(0,Z.jsxs)(A,{open:P,onOpenChange:F,children:[I,q]}),t[82]=A,t[83]=P,t[84]=F,t[85]=I,t[86]=q,t[87]=J):J=t[87];let Y;t[88]!==n||t[89]!==m?(Y=(0,Z.jsx)(bd,{open:m,onOpenChange:h,bridge:n}),t[88]=n,t[89]=m,t[90]=Y):Y=t[90];let ee;return t[91]!==J||t[92]!==Y?(ee=(0,Z.jsxs)(Z.Fragment,{children:[J,Y]}),t[91]=J,t[92]=Y,t[93]=ee):ee=t[93],ee}function vU(e){return e.stopPropagation()}function yU(e,t){let n=e instanceof Error?e:Error(String(e));console.warn(JSON.stringify({event:`jsx-render-failure`,component:`sidebarSearchPill`,rawComponentName:`sidebarSearchPill`,error:String(n),stack:t.componentStack})),si(`sidebarSearchPill`)}function bU(e){let t=(0,$.c)(8),{onClick:n,className:r}=e,i;t[0]===r?i=t[1]:(i=Gi(`rounded-lg h-9 w-full justify-start gap-2 px-3 font-normal text-muted-foreground`,r),t[0]=r,t[1]=i);let a;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(O,{"aria-hidden":`true`}),t[2]=a):a=t[2];let o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(`span`,{className:`flex-1 text-left text-sm`,children:(0,Z.jsx)(s,{id:`A1taO8`})}),t[3]=o):o=t[3];let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Z.jsx)(D,{className:`text-foreground/70`,children:Ms(`command-palette`)}),t[4]=c):c=t[4];let l;return t[5]!==n||t[6]!==i?(l=(0,Z.jsxs)(Qi,{variant:`outline`,onClick:n,"data-telemetry-event":`ok.sidebar.search_pill.click`,className:i,children:[a,o,c]}),t[5]=n,t[6]=i,t[7]=l):l=t[7],l}function xU(e){let t=(0,$.c)(36),{notice:n,onDismiss:r}=e,{_:a}=i(),o=n.variant===`error`?`border-destructive/60`:`border-sidebar-border`,s;t[0]===a?s=t[1]:(s=a({id:`GUYwCr`}),t[0]=a,t[1]=s);let c;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Z.jsx)(ss,{"aria-hidden":`true`,className:`size-3`}),t[2]=c):c=t[2];let l;t[3]!==r||t[4]!==s?(l=(0,Z.jsx)(Qi,{variant:`ghost`,size:`icon`,className:`size-5 shrink-0 text-muted-foreground hover:text-sidebar-foreground`,"aria-label":s,onClick:r,children:c}),t[3]=r,t[4]=s,t[5]=l):l=t[5];let u=l;if(n.secondaryAction){let e=`update-notice-${n.id}`,r=`flex flex-col gap-2 rounded-md border bg-sidebar-accent/30 px-2 py-2 text-xs text-muted-foreground ${o}`,i;t[6]===n.body?i=t[7]:(i=(0,Z.jsx)(`span`,{className:`flex-1 leading-snug`,children:n.body}),t[6]=n.body,t[7]=i);let a;t[8]!==u||t[9]!==i?(a=(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[i,u]}),t[8]=u,t[9]=i,t[10]=a):a=t[10];let s;t[11]===n.action?s=t[12]:(s=n.action?(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-xs font-medium underline underline-offset-2 decoration-muted-foreground/40 hover:text-sidebar-foreground hover:decoration-sidebar-foreground`,onClick:()=>{n.action?.onClick()},children:n.action.label}):null,t[11]=n.action,t[12]=s);let c;t[13]===n.secondaryAction?c=t[14]:(c=()=>{n.secondaryAction?.onClick()},t[13]=n.secondaryAction,t[14]=c);let l;t[15]!==n.secondaryAction.label||t[16]!==c?(l=(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-xs font-medium underline underline-offset-2 decoration-muted-foreground/40 hover:text-sidebar-foreground hover:decoration-sidebar-foreground`,onClick:c,children:n.secondaryAction.label}),t[15]=n.secondaryAction.label,t[16]=c,t[17]=l):l=t[17];let d;t[18]!==l||t[19]!==s?(d=(0,Z.jsxs)(`div`,{className:`flex gap-3 pl-1`,children:[s,l]}),t[18]=l,t[19]=s,t[20]=d):d=t[20];let f;return t[21]!==d||t[22]!==e||t[23]!==r||t[24]!==a?(f=(0,Z.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":e,className:r,children:[a,d]}),t[21]=d,t[22]=e,t[23]=r,t[24]=a,t[25]=f):f=t[25],f}let d=`update-notice-${n.id}`,f=`flex items-center gap-2 rounded-md border bg-sidebar-accent/30 px-2 py-1.5 text-xs text-muted-foreground ${o}`,p;t[26]===n.body?p=t[27]:(p=(0,Z.jsx)(`span`,{className:`flex-1 leading-snug`,children:n.body}),t[26]=n.body,t[27]=p);let m;t[28]===n.action?m=t[29]:(m=n.action?(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-xs font-medium underline underline-offset-2 decoration-muted-foreground/40 hover:text-sidebar-foreground hover:decoration-sidebar-foreground`,onClick:()=>{n.action?.onClick()},children:n.action.label}):null,t[28]=n.action,t[29]=m);let h;return t[30]!==u||t[31]!==d||t[32]!==f||t[33]!==p||t[34]!==m?(h=(0,Z.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":d,className:f,children:[p,m,u]}),t[30]=u,t[31]=d,t[32]=f,t[33]=p,t[34]=m,t[35]=h):h=t[35],h}function SU(e){if(e.length===0)return null;let t=e[0];if(!t)return null;for(let n=1;n<e.length;n++){let r=e[n];r&&r.priority<t.priority&&(t=r)}return t}function CU(){let e=(0,$.c)(7),t=(0,Q.useSyncExternalStore)(Pp,Np,Np),n;e[0]===t?n=e[1]:(n=SU(t),e[0]=t,e[1]=n);let r=n;if(!r)return null;let i;e[2]===r?i=e[3]:(i=()=>{r.onDismiss?.(),Mp(r.id)},e[2]=r,e[3]=i);let a;return e[4]!==r||e[5]!==i?(a=(0,Z.jsx)(`div`,{"data-testid":`update-notices-list`,children:(0,Z.jsx)(xU,{notice:r,onDismiss:i})}),e[4]=r,e[5]=i,e[6]=a):a=e[6],a}function wU(e,t,n){return e?.kind===`doc`&&t||e?.kind===`folder-index`&&t?Lh(n.contentDir,Rh(t),n.pathSeparator):e?.kind===`folder`?Lh(n.contentDir,e.folderPath,n.pathSeparator):e?.kind===`asset`?Lh(n.contentDir,e.assetPath,n.pathSeparator):n.contentDir}function TU(e,t,n){if((e?.kind===`doc`||e?.kind===`folder-index`)&&t){let e=t.lastIndexOf(`/`);return e<0?n.contentDir:Lh(n.contentDir,t.slice(0,e),n.pathSeparator)}if(e?.kind===`folder`)return Lh(n.contentDir,e.folderPath,n.pathSeparator);if(e?.kind===`asset`){let t=e.assetPath.lastIndexOf(`/`);return t<0?n.contentDir:Lh(n.contentDir,e.assetPath.slice(0,t),n.pathSeparator)}return n.contentDir}function EU(e,t){return(e?.kind===`doc`||e?.kind===`folder-index`)&&t?Rh(t):e?.kind===`folder`?e.folderPath:e?.kind===`asset`?e.assetPath:``}function DU(e,t,n){return e===null?Bh({workspace:n}):e.kind===`folder`?n?Vh({folderRelativePath:e.folderPath,workspace:n}):null:e.kind===`doc`||e.kind===`folder-index`?zh({docName:t,workspace:n}):null}var OU={folderCount:0,expandedCount:0},kU=`button, [role="button"], [role="menuitem"], input, textarea, select, a[href]`;function AU(e){return typeof Element>`u`||!(e instanceof Element)?!1:e.closest(kU)!==null}function jU(e){let t=(0,$.c)(2),{onOpenSearch:n}=e,r;return t[0]===n?r=t[1]:(r=(0,Z.jsx)(x,{name:`file-sidebar`,children:(0,Z.jsx)(NU,{onOpenSearch:n})}),t[0]=n,t[1]=r),r}var MU=e=>{let t=(0,$.c)(15),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({icon:n,label:r,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===n?a=t[5]:(a=(0,Z.jsx)(n,{"aria-hidden":`true`}),t[4]=n,t[5]=a);let o;t[6]!==r||t[7]!==i||t[8]!==a?(o=(0,Z.jsx)(Tr,{asChild:!0,children:(0,Z.jsx)(Qi,{variant:`ghost`,size:`icon-sm`,"aria-label":r,...i,children:a})}),t[6]=r,t[7]=i,t[8]=a,t[9]=o):o=t[9];let s;t[10]===r?s=t[11]:(s=(0,Z.jsx)(nr,{children:r}),t[10]=r,t[11]=s);let c;return t[12]!==o||t[13]!==s?(c=(0,Z.jsxs)(Yn,{children:[o,s]}),t[12]=o,t[13]=s,t[14]=c):c=t[14],c};function NU(e){let t=(0,$.c)(200),{onOpenSearch:n}=e,{_:r}=i(),[a,o]=(0,Q.useState)(null),{activeDocName:c,activeTarget:l}=pt(),u;t[0]!==c||t[1]!==l?(u=l?.kind===`folder`||l?.kind===`folder-index`?l.folderPath:qr(c),t[0]=c,t[1]=l,t[2]=u):u=t[2];let d=u,f=typeof window<`u`&&window.okDesktop!=null,{state:p,toggleSidebar:m}=ID(),h=ih(),g=p===`expanded`,_=f&&p===`collapsed`,[v,y]=(0,Q.useState)(OU),b,x;t[3]===a?(b=t[4],x=t[5]):(b=()=>{if(a!==null)return y(a.getFolderState()),a.subscribe(()=>{y(a.getFolderState())})},x=[a],t[3]=a,t[4]=b,t[5]=x),(0,Q.useEffect)(b,x);let S,C;t[6]===a?(S=t[7],C=t[8]):(S=()=>{if(a!==null)return dx(e=>{let t=e.initialDir??``;if(e.template){a.createFromTemplate(e.template.folder,e.template.name);return}a.startCreating(`file`,t)})},C=[a],t[6]=a,t[7]=S,t[8]=C),(0,Q.useEffect)(S,C);let w=v.folderCount>0,T=w&&v.expandedCount===v.folderCount,E=v.expandedCount===0,D=eo(``),O=eo(d===``?null:d),k=d===``?D:O,A=D.state.status===`ready`?(D.state.data.folder.templates_available?.length??0)>0:!0,j=k.state.status===`ready`?(k.state.data.folder.templates_available?.length??0)>0:!0,M=typeof window<`u`?window.okDesktop:void 0,N=Mo(),P=ug().states,{dispatch:F}=$h(),I;t[9]===N?I=t[10]:(I=Bh({workspace:N}),t[9]=N,t[10]=I);let L=I,{projectLocalBinding:R,merged:z}=gt(),B=z?.appearance?.sidebar?.showHiddenFiles??!1,V=z?.appearance?.sidebar?.showAllFiles??!1,H=w&&!T,U=w&&!E,G=H||U,K=FU,q;t[11]!==a||t[12]!==N?(q=()=>{N&&a?.startCreating(`file`,``)},t[11]=a,t[12]=N,t[13]=q):q=t[13];let J=q,Y;t[14]!==a||t[15]!==N?(Y=e=>{N&&a?.createFromTemplate(``,e)},t[14]=a,t[15]=N,t[16]=Y):Y=t[16];let ee=Y,te;t[17]!==a||t[18]!==N?(te=()=>{N&&a?.startCreating(`folder`,``)},t[17]=a,t[18]=N,t[19]=te):te=t[19];let ne=te,re;t[20]===N?re=t[21]:(re=()=>{!N||!M||M.shell.showItemInFolder(N.contentDir)},t[20]=N,t[21]=re);let ie=re,ae;t[22]===N?ae=t[23]:(ae=()=>{!N||!M||MV(M,N.contentDir)},t[22]=N,t[23]=ae);let oe=ae,se;t[24]!==r||t[25]!==N?(se=async()=>{if(N)try{await navigator.clipboard.writeText(N.contentDir),gs.success(r({id:`6_ZOw4`}),{description:N.contentDir})}catch(e){console.warn(`[FileSidebar] clipboard write failed:`,e),gs.error(r({id:`vfRlCI`}))}},t[24]=r,t[25]=N,t[26]=se):se=t[26];let ce=se,le;t[27]!==r||t[28]!==R?(le=e=>{if(R===null)return;let t=R.patch({appearance:{sidebar:{showHiddenFiles:e}}});t.ok||(console.warn(`[FileSidebar] showHiddenFiles toggle rejected:`,Er(t.error)),gs.error(r({id:`P47EWZ`}),{description:Er(t.error)}))},t[27]=r,t[28]=R,t[29]=le):le=t[29];let ue=le,de;t[30]!==r||t[31]!==R?(de=e=>{if(R===null)return;let t=R.patch({appearance:{sidebar:{showAllFiles:e}}});t.ok||(console.warn(`[FileSidebar] showAllFiles toggle rejected:`,Er(t.error)),gs.error(r({id:`P47EWZ`}),{description:Er(t.error)}))},t[30]=r,t[31]=R,t[32]=de):de=t[32];let fe=de,pe;t[33]===a?pe=t[34]:(pe=()=>{a?.expandAll()},t[33]=a,t[34]=pe);let me=pe,he;t[35]===a?he=t[36]:(he=()=>{a?.collapseAll()},t[35]=a,t[36]=he);let ge=he,_e,ve;t[37]!==V||t[38]!==U||t[39]!==H||t[40]!==B||t[41]!==p?(_e=()=>{M&&M.editor.notifyViewMenuStateChanged({showHiddenFiles:B,showAllFiles:V,canExpandAll:H,canCollapseAll:U,sidebarVisible:p===`expanded`})},ve=[M,B,V,H,U,p],t[37]=V,t[38]=U,t[39]=H,t[40]=B,t[41]=p,t[42]=_e,t[43]=ve):(_e=t[42],ve=t[43]),(0,Q.useEffect)(_e,ve);let ye,be;t[44]!==r||t[45]!==c||t[46]!==l||t[47]!==F||t[48]!==P||t[49]!==d||t[50]!==R||t[51]!==V||t[52]!==B||t[53]!==m||t[54]!==a||t[55]!==N?(ye=()=>{if(M)return M.onMenuAction(e=>{switch(e){case`new-doc`:if(!N||!a)return;a.startCreating(`file`,d);return;case`new-folder`:if(!N||!a)return;a.startCreating(`folder`,d);return;case`new-from-template`:if(!N||!a)return;a.startCreatingFromTemplate(d);return;case`rename`:if(!l)return;RV(l);return;case`duplicate`:if(!l)return;BV(l);return;case`move-to-trash`:if(!l)return;IV(l);return;case`reveal-in-finder`:{if(!M||!N)return;let e=wU(l,c,N);M.shell.showItemInFolder(e);return}case`open-in-terminal`:if(!M||!N)return;MV(M,TU(l,c,N));return;case`send-to-ai`:{let e=sh.filter(e=>P[e.id]?.installed===!0);if(e.length===0){gs.error(r({id:`LKOLNn`}));return}let t=DU(l,c,N);if(!t)return;let[n]=e;if(!n)return;F(n.id,t);return}case`copy-full-path`:{if(!N)return;let e=wU(l,c,N);navigator.clipboard.writeText(e).then(()=>gs.success(r({id:`6_ZOw4`}),{description:e})).catch(e=>{console.warn(`[FileSidebar] clipboard write failed:`,e),gs.error(r({id:`vfRlCI`}))});return}case`copy-relative-path`:{let e=EU(l,c);if(e===``){gs.error(r({id:`74eHt-`}));return}navigator.clipboard.writeText(e).then(()=>gs.success(r({id:`haHgQj`}),{description:e})).catch(e=>{console.warn(`[FileSidebar] clipboard write failed:`,e),gs.error(r({id:`5QGTaA`}))});return}case`toggle-show-hidden-files`:{if(R===null)return;let e=R.patch({appearance:{sidebar:{showHiddenFiles:!B}}});e.ok||(console.warn(`[FileSidebar] toggle-show-hidden-files rejected:`,Er(e.error)),gs.error(r({id:`P47EWZ`}),{description:Er(e.error)}));return}case`toggle-show-all-files`:{if(R===null)return;let e=R.patch({appearance:{sidebar:{showAllFiles:!V}}});e.ok||(console.warn(`[FileSidebar] toggle-show-all-files rejected:`,Er(e.error)),gs.error(r({id:`P47EWZ`}),{description:Er(e.error)}));return}case`expand-all-tree`:a?.expandAll();return;case`collapse-all-tree`:a?.collapseAll();return;case`toggle-sidebar`:m();return;case`delete`:case`toggle-source`:case`save-version`:case`version-history`:case`focus-search`:case`focus-command-palette`:case`toggle-doc-panel`:return}})},be=[M,a,N,l,c,d,R,B,V,P,F,m,r],t[44]=r,t[45]=c,t[46]=l,t[47]=F,t[48]=P,t[49]=d,t[50]=R,t[51]=V,t[52]=B,t[53]=m,t[54]=a,t[55]=N,t[56]=ye,t[57]=be):(ye=t[56],be=t[57]),(0,Q.useEffect)(ye,be);let xe=f&&g&&`motion-safe:delay-100`,Se=_&&`opacity-0`,Ce;t[58]!==xe||t[59]!==Se?(Ce=Gi(`flex-row h-12 items-center py-0 px-3`,f?`justify-end`:`justify-between`,f&&`motion-safe:transition-opacity motion-safe:duration-100 motion-safe:ease-out`,xe,Se,f&&`[-webkit-app-region:drag]`),t[58]=xe,t[59]=Se,t[60]=Ce):Ce=t[60];let we;t[61]===g?we=t[62]:(we=g&&!f?(0,Z.jsx)(`span`,{className:`shrink-0 font-mono text-sm uppercase tracking-wider text-sidebar-foreground/50`,children:(0,Z.jsx)(s,{id:`sER-bs`})}):null,t[61]=g,t[62]=we);let Te;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(Te=Gi(`flex items-center gap-1`,f&&`[&>*]:[-webkit-app-region:no-drag]`),t[63]=Te):Te=t[63];let Ee;t[64]!==r||t[65]!==T||t[66]!==w||t[67]!==E||t[68]!==a?(Ee=w?(0,Z.jsxs)(Ya,{children:[(0,Z.jsx)(Ho,{asChild:!0,children:(0,Z.jsx)(MU,{icon:cl,label:r({id:`Lu_dOh`})})}),(0,Z.jsxs)(xo,{align:`end`,children:[T?null:(0,Z.jsxs)(Wo,{onSelect:()=>a?.expandAll(),children:[(0,Z.jsx)(Vl,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`b392Dr`})]}),E?null:(0,Z.jsxs)(Wo,{onSelect:()=>a?.collapseAll(),children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`BBtVak`})]})]})]}):null,t[64]=r,t[65]=T,t[66]=w,t[67]=E,t[68]=a,t[69]=Ee):Ee=t[69];let De;t[70]===r?De=t[71]:(De=r({id:`MW64zN`}),t[70]=r,t[71]=De);let Oe;t[72]!==d||t[73]!==a?(Oe=()=>a?.startCreating(`file`,d),t[72]=d,t[73]=a,t[74]=Oe):Oe=t[74];let ke;t[75]!==De||t[76]!==Oe?(ke=(0,Z.jsx)(MU,{icon:Nl,label:De,onClick:Oe}),t[75]=De,t[76]=Oe,t[77]=ke):ke=t[77];let Ae;t[78]!==r||t[79]!==j||t[80]!==d||t[81]!==a?(Ae=j?(0,Z.jsxs)(Ya,{children:[(0,Z.jsx)(Ho,{asChild:!0,children:(0,Z.jsx)(MU,{icon:mo,label:r({id:`Uuj_R4`})})}),(0,Z.jsx)(xo,{align:`end`,children:(0,Z.jsx)(OV,{parentDir:d,onSelectTemplate:e=>a?.createFromTemplate(d,e),ItemComponent:Wo})})]}):null,t[78]=r,t[79]=j,t[80]=d,t[81]=a,t[82]=Ae):Ae=t[82];let je;t[83]===r?je=t[84]:(je=r({id:`tX5yOZ`}),t[83]=r,t[84]=je);let Me;t[85]!==d||t[86]!==a?(Me=()=>a?.startCreating(`folder`,d),t[85]=d,t[86]=a,t[87]=Me):Me=t[87];let Ne;t[88]!==je||t[89]!==Me?(Ne=(0,Z.jsx)(MU,{icon:el,label:je,onClick:Me}),t[88]=je,t[89]=Me,t[90]=Ne):Ne=t[90];let Pe;t[91]!==Ee||t[92]!==ke||t[93]!==Ae||t[94]!==Ne?(Pe=(0,Z.jsxs)(`div`,{className:Te,children:[Ee,ke,Ae,Ne]}),t[91]=Ee,t[92]=ke,t[93]=Ae,t[94]=Ne,t[95]=Pe):Pe=t[95];let Fe;t[96]!==Ce||t[97]!==we||t[98]!==Pe?(Fe=(0,Z.jsxs)(WD,{"data-electron-drag":f?``:void 0,className:Ce,children:[we,Pe]}),t[96]=Ce,t[97]=we,t[98]=Pe,t[99]=Fe):Fe=t[99];let Ie=f&&g&&`motion-safe:delay-100`,Le=_&&`opacity-0`,Re;t[100]!==Ie||t[101]!==Le?(Re=Gi(`px-2 pb-2`,f&&`[-webkit-app-region:no-drag]`,f&&`motion-safe:transition-opacity motion-safe:duration-100 motion-safe:ease-out`,Ie,Le),t[100]=Ie,t[101]=Le,t[102]=Re):Re=t[102];let ze;t[103]===p?ze=t[104]:(ze=[p],t[103]=p,t[104]=ze);let Ve;t[105]===n?Ve=t[106]:(Ve=(0,Z.jsx)(bU,{onClick:n}),t[105]=n,t[106]=Ve);let He;t[107]!==ze||t[108]!==Ve?(He=(0,Z.jsx)(W,{fallbackRender:PU,onError:yU,resetKeys:ze,children:Ve}),t[107]=ze,t[108]=Ve,t[109]=He):He=t[109];let Ue;t[110]!==Re||t[111]!==He?(Ue=(0,Z.jsx)(`div`,{className:Re,children:He}),t[110]=Re,t[111]=He,t[112]=Ue):Ue=t[112];let We;t[113]===Symbol.for(`react.memo_cache_sentinel`)?(We=(0,Z.jsxs)(KD,{children:[(0,Z.jsx)(SA,{}),(0,Z.jsx)(RH,{ref:o})]}),t[113]=We):We=t[113];let Ge;t[114]===Symbol.for(`react.memo_cache_sentinel`)?(Ge=(0,Z.jsxs)(GD,{className:`px-0`,children:[(0,Z.jsx)(CU,{}),typeof window<`u`&&window.okDesktop?(0,Z.jsx)(qD,{children:(0,Z.jsx)(JD,{children:(0,Z.jsx)(_U,{bridge:window.okDesktop})})}):null]}),t[114]=Ge):Ge=t[114];let Ke=!(h&&p===`collapsed`),qe;t[115]===Ke?qe=t[116]:(qe=(0,Z.jsx)(HD,{enableToggle:!1,enableDrag:Ke}),t[115]=Ke,t[116]=qe);let X;t[117]!==Fe||t[118]!==Ue||t[119]!==qe?(X=(0,Z.jsx)(Ik,{asChild:!0,children:(0,Z.jsxs)(`div`,{className:`contents`,onContextMenu:K,children:[Fe,Ue,We,Ge,qe]})}),t[117]=Fe,t[118]=Ue,t[119]=qe,t[120]=X):X=t[120];let Je=!N,Ye,Xe;t[121]===Symbol.for(`react.memo_cache_sentinel`)?(Ye=(0,Z.jsx)(Nl,{"aria-hidden":`true`}),Xe=(0,Z.jsx)(s,{id:`MW64zN`}),t[121]=Ye,t[122]=Xe):(Ye=t[121],Xe=t[122]);let Ze;t[123]!==J||t[124]!==Je?(Ze=(0,Z.jsxs)(zk,{disabled:Je,onSelect:J,"data-testid":`empty-space-menu-new-file`,children:[Ye,Xe]}),t[123]=J,t[124]=Je,t[125]=Ze):Ze=t[125];let Qe=!N||!A,$e,et;t[126]===Symbol.for(`react.memo_cache_sentinel`)?($e=(0,Z.jsx)(mo,{"aria-hidden":`true`}),et=(0,Z.jsx)(s,{id:`Uuj_R4`}),t[126]=$e,t[127]=et):($e=t[126],et=t[127]);let tt;t[128]===Qe?tt=t[129]:(tt=(0,Z.jsxs)(Bk,{disabled:Qe,"data-testid":`empty-space-menu-new-from-template`,children:[$e,et]}),t[128]=Qe,t[129]=tt);let nt;t[130]===ee?nt=t[131]:(nt=(0,Z.jsx)(Vk,{children:(0,Z.jsx)(OV,{parentDir:``,onSelectTemplate:ee,ItemComponent:zk})}),t[130]=ee,t[131]=nt);let rt;t[132]!==tt||t[133]!==nt?(rt=(0,Z.jsxs)(Lk,{children:[tt,nt]}),t[132]=tt,t[133]=nt,t[134]=rt):rt=t[134];let it=!N,at,ot;t[135]===Symbol.for(`react.memo_cache_sentinel`)?(at=(0,Z.jsx)(el,{"aria-hidden":`true`}),ot=(0,Z.jsx)(s,{id:`tX5yOZ`}),t[135]=at,t[136]=ot):(at=t[135],ot=t[136]);let st;t[137]!==ne||t[138]!==it?(st=(0,Z.jsxs)(zk,{disabled:it,onSelect:ne,"data-testid":`empty-space-menu-new-folder`,children:[at,ot]}),t[137]=ne,t[138]=it,t[139]=st):st=t[139];let ct;t[140]===Symbol.for(`react.memo_cache_sentinel`)?(ct=(0,Z.jsx)(Uk,{}),t[140]=ct):ct=t[140];let lt;t[141]!==r||t[142]!==ie||t[143]!==N?(lt=M?(0,Z.jsxs)(zk,{disabled:!N,onSelect:ie,"data-testid":`empty-space-menu-reveal-in-finder`,"aria-label":r(N?{id:`LtSYdi`}:{id:`o2yoFu`}),children:[(0,Z.jsx)(yt,{"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:(0,Z.jsx)(s,{id:`LtSYdi`})}),N?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`wTcjov`})})]}):null,t[141]=r,t[142]=ie,t[143]=N,t[144]=lt):lt=t[144];let ut;t[145]!==F||t[146]!==L||t[147]!==P?(ut=(0,Z.jsx)(hU,{input:L,installStates:P,dispatch:F,webFallbackVisible:!1}),t[145]=F,t[146]=L,t[147]=P,t[148]=ut):ut=t[148];let dt;t[149]!==r||t[150]!==oe||t[151]!==N?(dt=M?(0,Z.jsxs)(zk,{disabled:!N,onSelect:oe,"data-testid":`empty-space-menu-open-in-terminal`,"aria-label":r(N?{id:`BJpGCq`}:{id:`_6IEmc`}),children:[(0,Z.jsx)(Rl,{"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:(0,Z.jsx)(s,{id:`BJpGCq`})}),N?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`wTcjov`})})]}):null,t[149]=r,t[150]=oe,t[151]=N,t[152]=dt):dt=t[152];let ft=!N,mt;t[153]!==r||t[154]!==N?(mt=r(N?{id:`Up2_7p`}:{id:`U8CD-l`}),t[153]=r,t[154]=N,t[155]=mt):mt=t[155];let ht;t[156]===Symbol.for(`react.memo_cache_sentinel`)?(ht=(0,Z.jsx)(Be,{"aria-hidden":`true`}),t[156]=ht):ht=t[156];let _t;t[157]===Symbol.for(`react.memo_cache_sentinel`)?(_t=(0,Z.jsx)(`span`,{className:`flex-1`,children:(0,Z.jsx)(s,{id:`Up2_7p`})}),t[157]=_t):_t=t[157];let vt;t[158]===N?vt=t[159]:(vt=N?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`wTcjov`})}),t[158]=N,t[159]=vt);let bt;t[160]!==ce||t[161]!==ft||t[162]!==mt||t[163]!==vt?(bt=(0,Z.jsxs)(zk,{disabled:ft,onSelect:ce,"data-testid":`empty-space-menu-copy-full-path`,"aria-label":mt,children:[ht,_t,vt]}),t[160]=ce,t[161]=ft,t[162]=mt,t[163]=vt,t[164]=bt):bt=t[164];let xt;t[165]===Symbol.for(`react.memo_cache_sentinel`)?(xt=(0,Z.jsx)(Uk,{}),t[165]=xt):xt=t[165];let St=R===null,Ct;t[166]===Symbol.for(`react.memo_cache_sentinel`)?(Ct=(0,Z.jsx)(s,{id:`K_wz1u`}),t[166]=Ct):Ct=t[166];let wt;t[167]!==ue||t[168]!==B||t[169]!==St?(wt=(0,Z.jsx)(Hk,{checked:B,onCheckedChange:ue,disabled:St,"data-testid":`empty-space-menu-show-hidden-files`,children:Ct}),t[167]=ue,t[168]=B,t[169]=St,t[170]=wt):wt=t[170];let Tt=R===null,Et;t[171]===Symbol.for(`react.memo_cache_sentinel`)?(Et=(0,Z.jsx)(s,{id:`i8dKs-`}),t[171]=Et):Et=t[171];let Dt;t[172]!==fe||t[173]!==V||t[174]!==Tt?(Dt=(0,Z.jsx)(Hk,{checked:V,onCheckedChange:fe,disabled:Tt,"data-testid":`empty-space-menu-show-all-files`,children:Et}),t[172]=fe,t[173]=V,t[174]=Tt,t[175]=Dt):Dt=t[175];let Ot;t[176]===G?Ot=t[177]:(Ot=G?(0,Z.jsx)(Uk,{}):null,t[176]=G,t[177]=Ot);let kt;t[178]!==me||t[179]!==H?(kt=H?(0,Z.jsxs)(zk,{onSelect:me,"data-testid":`empty-space-menu-expand-all`,children:[(0,Z.jsx)(Vl,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`OlAl5i`})]}):null,t[178]=me,t[179]=H,t[180]=kt):kt=t[180];let At;t[181]!==ge||t[182]!==U?(At=U?(0,Z.jsxs)(zk,{onSelect:ge,"data-testid":`empty-space-menu-collapse-all`,children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`qvWGzP`})]}):null,t[181]=ge,t[182]=U,t[183]=At):At=t[183];let jt;t[184]!==Ze||t[185]!==rt||t[186]!==st||t[187]!==lt||t[188]!==ut||t[189]!==dt||t[190]!==bt||t[191]!==wt||t[192]!==Dt||t[193]!==Ot||t[194]!==kt||t[195]!==At?(jt=(0,Z.jsxs)(Rk,{children:[Ze,rt,st,ct,lt,ut,dt,bt,xt,wt,Dt,Ot,kt,At]}),t[184]=Ze,t[185]=rt,t[186]=st,t[187]=lt,t[188]=ut,t[189]=dt,t[190]=bt,t[191]=wt,t[192]=Dt,t[193]=Ot,t[194]=kt,t[195]=At,t[196]=jt):jt=t[196];let Mt;return t[197]!==X||t[198]!==jt?(Mt=(0,Z.jsx)(BD,{variant:`inset`,children:(0,Z.jsxs)(Fk,{children:[X,jt]})}),t[197]=X,t[198]=jt,t[199]=Mt):Mt=t[199],Mt}function PU(){return null}function FU(e){AU(e.target)&&(e.preventDefault(),e.stopPropagation())}function IU(e){let t=e.shareTargetExists,n=e.dirtyConflicts.conflicts,r=e.dirtyConflicts.files;return t&&!n?{kind:`A`,openCurrentEnabled:!0,switchEnabled:!0,conflictingFiles:r}:!t&&!n?{kind:`B`,openCurrentEnabled:!1,switchEnabled:!0,conflictingFiles:r}:t&&n?{kind:`C`,openCurrentEnabled:!0,switchEnabled:!1,conflictingFiles:r}:{kind:`D`,openCurrentEnabled:!1,switchEnabled:!1,conflictingFiles:r}}function LU(e){return e.detached?e.currentHeadSha:e.currentBranch??`HEAD`}function RU(e){if(e.ok)return{action:`await-cc1`};switch(e.reason){case`dirty-conflict`:return{action:`rerender-conflict`,files:e.files??[]};case`branch-not-found`:return{action:`dismiss-with-toast`,reason:`branch-not-found`};case`fetch-failed`:case`checkout-failed`:return{action:`stay-with-toast`,reason:e.reason};case`branch-in-other-worktree`:{let t=e.otherWorktreePath;return t===void 0||t.length===0?{action:`stay-with-toast`,reason:`checkout-failed`}:{action:`pivot-to-other-worktree`,otherWorktreePath:t}}default:{let t=e.reason;throw Error(`Unhandled CheckoutFailureReason: ${String(t)}`)}}}var zU={phase:`loading`};function BU(e,t){return e.phase===`loading`?t===null?{phase:`error`}:{phase:`ready`,info:t}:e}function VU(e,t){return e.phase===`ready`?{phase:`switching`,info:e.info,pendingDoc:t}:e}function HU(e,t){if(e.phase!==`switching`)return{state:e};if(t===null)return{state:{phase:`ready`,info:e.info},sideEffect:{kind:`toast`,reason:`proxy-null`}};let n=RU(t);return n.action===`await-cc1`?{state:{phase:`awaiting-cc1-recycle`,pendingDoc:e.pendingDoc}}:n.action===`rerender-conflict`?{state:{phase:`ready`,info:{...e.info,dirtyConflicts:{conflicts:!0,files:n.files.slice()}}}}:n.action===`pivot-to-other-worktree`?{state:{phase:`branch-in-other-worktree`,info:e.info,otherWorktreePath:n.otherWorktreePath,pendingDoc:e.pendingDoc}}:n.action===`dismiss-with-toast`?{state:{phase:`dismissed`,reason:n.reason},sideEffect:{kind:`toast`,reason:n.reason}}:{state:{phase:`ready`,info:e.info},sideEffect:{kind:`toast`,reason:n.reason}}}function UU(e){return e!==null&&e.kind===`project-branch-switch`}function WU(e){let t=(0,$.c)(146),{bridge:n,store:r}=e,a=r===void 0?Wd:r,{_:o}=i(),c=(0,Q.useSyncExternalStore)(a.subscribe,a.getSnapshot,XU),[l,u]=(0,Q.useState)(zU),d=(0,Q.useRef)(!1),f=(0,Q.useRef)(!1),p;t[0]===c?p=t[1]:(p=UU(c)?c:null,t[0]=c,t[1]=p);let m=p,h;t[2]!==o||t[3]!==m?.share.target.kind?(h=m?.share.target.kind===`folder`?o({id:`ugoTXs`}):o({id:`XH30C4`}),t[2]=o,t[3]=m?.share.target.kind,t[4]=h):h=t[4];let g=h,_;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{u(zU),d.current=!1,f.current=!1},t[5]=_):_=t[5];let v;t[6]===c?v=t[7]:(v=[c],t[6]=c,t[7]=v),(0,Q.useEffect)(_,v);let y;t[8]!==m||t[9]!==n?(y=()=>{m&&(d.current||(d.current=!0,n.project.fetchBranchInfo({projectPath:m.projectPath,branch:m.share.branch,kind:m.share.target.kind,path:C(m.share.target)}).then(e=>{u(t=>BU(t,e))}).catch(e=>{console.warn(`[receive] branch-info-fetch-failed`,e instanceof Error?e.message:e),u(YU)})))},t[8]=m,t[9]=n,t[10]=y):y=t[10];let b;t[11]===m?b=t[12]:(b=[m],t[11]=m,t[12]=b),(0,Q.useEffect)(y,b);let x;t[13]!==o||t[14]!==m||t[15]!==l.phase||t[16]!==n||t[17]!==a||t[18]!==g?(x=()=>{if(l.phase!==`awaiting-cc1-recycle`||!m)return;let e=m.share.branch;if(!e){a.dismiss();return}if(f.current)return;f.current=!0;let t=!1;return n.project.awaitBranchSwitched({projectPath:m.projectPath,branch:e,timeoutMs:3e4}).then(r=>{if(!t){if(r.ok){console.log(Xl({branch_dialog_action:`branch-switch-complete`,branch:e})),n.project.open({path:m.projectPath,target:`new-window`,entryPoint:`share-receive`,pendingDeepLinkTarget:{kind:m.share.target.kind,path:C(m.share.target)},pendingBranch:e}).catch(e=>{console.warn(`[receive] warm-focus-dispatch-failed branch_action=switch`,e instanceof Error?e.message:e),gs.error(o({id:`gQV-9w`,values:{targetNoun:g}}))}),a.dismiss();return}console.log(Xl({branch_dialog_action:`branch-switch-timeout`,branch:e})),gs.error(o({id:`LBwUR6`,values:{targetNoun:g}})),a.dismiss()}}).catch(e=>{t||(console.warn(`[receive] awaitBranchSwitched rejected`,e instanceof Error?e.message:e),gs.error(o({id:`Jw6EC4`,values:{targetNoun:g}})),a.dismiss())}),()=>{t=!0}},t[13]=o,t[14]=m,t[15]=l.phase,t[16]=n,t[17]=a,t[18]=g,t[19]=x):x=t[19];let S;if(t[20]!==m||t[21]!==l.phase?(S=[l.phase,m],t[20]=m,t[21]=l.phase,t[22]=S):S=t[22],(0,Q.useEffect)(x,S),!m)return null;let{share:w,projectPath:T,currentBranch:E}=m,D=w.branch,O;t[23]!==o||t[24]!==l.info||t[25]!==l.phase||t[26]!==n.project||t[27]!==T||t[28]!==w.target||t[29]!==D||t[30]!==a?(O=function(){l.phase===`ready`&&IU(l.info).switchEnabled&&(console.log(Xl({branch_dialog_action:`switch`,branch_action:`switch`,branch:D})),u(e=>VU(e,C(w.target))),n.project.runCheckout({projectPath:T,branch:D}).then(e=>{let t=null,n=!1;u(r=>{let{state:i,sideEffect:a}=HU(r,e);return a&&(t=a.reason,n=i.phase===`dismissed`),i}),t===`branch-not-found`?gs.error(o({id:`NJyQi_`,values:{shareBranch:D}})):t===`fetch-failed`?gs.error(o({id:`bWLmRK`})):(t===`checkout-failed`||t===`proxy-null`)&&gs.error(o({id:`c863eW`,values:{shareBranch:D}})),n&&a.dismiss()}).catch(e=>{console.warn(`[receive] runCheckout rejected branch_action=switch`,e instanceof Error?e.message:e),u(JU),gs.error(o({id:`c863eW`,values:{shareBranch:D}}))}))},t[23]=o,t[24]=l.info,t[25]=l.phase,t[26]=n.project,t[27]=T,t[28]=w.target,t[29]=D,t[30]=a,t[31]=O):O=t[31];let k=O,A;t[32]!==o||t[33]!==n.project||t[34]!==T||t[35]!==w.target||t[36]!==D||t[37]!==a||t[38]!==g?(A=function(){console.log(Xl({branch_dialog_action:`open-current`,branch:D})),n.project.open({path:T,target:`new-window`,entryPoint:`share-receive`,pendingDeepLinkTarget:{kind:w.target.kind,path:C(w.target)}}).catch(e=>{console.warn(`[receive] warm-focus-dispatch-failed branch_action=open-current`,e instanceof Error?e.message:e),gs.error(o({id:`b5aNbi`,values:{targetNoun:g}}))}),a.dismiss()},t[32]=o,t[33]=n.project,t[34]=T,t[35]=w.target,t[36]=D,t[37]=a,t[38]=g,t[39]=A):A=t[39];let j=A,M;t[40]!==o||t[41]!==l.otherWorktreePath||t[42]!==l.phase||t[43]!==n.project||t[44]!==w.target||t[45]!==D||t[46]!==a?(M=function(){if(l.phase!==`branch-in-other-worktree`)return;let e=l.otherWorktreePath;console.log(Xl({branch_dialog_action:`pivot-to-other-worktree`,branch:D})),n.project.open({path:e,target:`new-window`,entryPoint:`share-receive`,pendingDeepLinkTarget:{kind:w.target.kind,path:C(w.target)},pendingBranch:D}).catch(t=>{console.warn(`[receive] pivot-open-failed branch_action=pivot-to-other-worktree`,t instanceof Error?t.message:t),gs.error(o({id:`LdABLa`,values:{target:e}}))}),a.dismiss()},t[40]=o,t[41]=l.otherWorktreePath,t[42]=l.phase,t[43]=n.project,t[44]=w.target,t[45]=D,t[46]=a,t[47]=M):M=t[47];let N=M,P;t[48]===a?P=t[49]:(P=function(){console.log(Xl({branch_dialog_action:`cancel`})),a.dismiss()},t[48]=a,t[49]=P);let F=P,I,L,R,z,B,V,H,U,W,G,K,q,J,Y,ee,te,ne;if(t[50]!==o||t[51]!==l.info||t[52]!==l.otherWorktreePath||t[53]!==l.phase||t[54]!==F||t[55]!==E||t[56]!==w.branch||t[57]!==w.owner||t[58]!==w.repo||t[59]!==w.target||t[60]!==D||t[61]!==g){ne=l.phase===`ready`||l.phase===`switching`?IU(l.info):null;let e;t[79]!==l.info||t[80]!==l.phase||t[81]!==E?(e=l.phase===`ready`||l.phase===`switching`?LU(l.info):E??`HEAD`,t[79]=l.info,t[80]=l.phase,t[81]=E,t[82]=e):e=t[82];let n=e;V=l.phase===`switching`||l.phase===`awaiting-cc1-recycle`;let r;t[83]===o?r=t[84]:(r=o({id:`OuY8t9`}),t[83]=o,t[84]=r),z=r;let i;t[85]!==o||t[86]!==D?(i=o({id:`_BthEY`,values:{shareBranch:D}}),t[85]=o,t[86]=D,t[87]=i):i=t[87],B=i;let a=l.phase===`loading`,c=l.phase===`error`;R=ps,ee=!0,t[88]===F?te=t[89]:(te=e=>{e||F()},t[88]=F,t[89]=te),L=ls,G=`sm:max-w-xl`,K=`share-branch-switch-dialog`,q=qU,J=KU;let u;t[90]===g?u=t[91]:(u=(0,Z.jsx)(cs,{children:(0,Z.jsx)(s,{id:`RY6Bq1`,values:{targetNoun:g}})}),t[90]=g,t[91]=u);let d=w.owner,f=w.repo,p;t[92]===w.target?p=t[93]:(p=C(w.target),t[92]=w.target,t[93]=p);let m;t[94]!==w.owner||t[95]!==w.repo||t[96]!==p?(m=(0,Z.jsx)(os,{className:`sr-only`,children:(0,Z.jsx)(s,{id:`f8jU-L`,values:{0:d,1:f,2:p}})}),t[94]=w.owner,t[95]=w.repo,t[96]=p,t[97]=m):m=t[97],t[98]!==u||t[99]!==m?(Y=(0,Z.jsxs)(fs,{children:[u,m]}),t[98]=u,t[99]=m,t[100]=Y):Y=t[100],I=us;let h=w.owner,_=w.repo,v;t[101]===w.target?v=t[102]:(v=C(w.target),t[101]=w.target,t[102]=v),t[103]!==w.branch||t[104]!==w.owner||t[105]!==w.repo||t[106]!==w.target.kind||t[107]!==v?(H=(0,Z.jsx)(`div`,{className:`mb-4`,children:(0,Z.jsx)(Id,{owner:h,repo:_,path:v,kind:w.target.kind,branch:w.branch,testId:`share-branch-switch-metadata`,branchTestId:`share-branch-switch-metadata-branch`})}),t[103]=w.branch,t[104]=w.owner,t[105]=w.repo,t[106]=w.target.kind,t[107]=v,t[108]=H):H=t[108],U=l.phase===`branch-in-other-worktree`?(0,Z.jsxs)(`div`,{className:`text-sm text-muted-foreground`,"data-testid":`share-branch-switch-in-other-worktree`,children:[(0,Z.jsx)(`p`,{className:`leading-6`,children:(0,Z.jsx)(s,{id:`yjExfe`,values:{shareBranch:D},components:{0:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`})}})}),(0,Z.jsx)(`p`,{className:`mt-2 break-all rounded bg-muted px-2 py-1 font-mono text-xs text-foreground/80`,"data-testid":`share-branch-switch-in-other-worktree-path`,children:l.otherWorktreePath})]}):a?(0,Z.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`share-branch-switch-loading`,role:`status`,"aria-live":`polite`,children:[(0,Z.jsx)(wt,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`jerqF0`})]}):c?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:(0,Z.jsx)(s,{id:`w4hMYl`})}):ne?.kind===`D`?(0,Z.jsx)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:(0,Z.jsx)(s,{id:`XnoA1k`,values:{targetNoun:g,shareBranch:D},components:{0:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`})}})}):ne?.kind===`B`?(0,Z.jsx)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:(0,Z.jsx)(s,{id:`sZ2IOu`,values:{targetNoun:g,shareBranch:D,currentLabel:n},components:{0:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`}),1:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`})}})}):(0,Z.jsx)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:(0,Z.jsx)(s,{id:`_902BE`,values:{targetNoun:g,shareBranch:D,currentLabel:n},components:{0:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`}),1:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`})}})}),W=ne&&!ne.switchEnabled&&ne.conflictingFiles.length>0?(0,Z.jsxs)(`div`,{className:`mt-3 rounded-md border border-border bg-muted/30 p-3 text-1sm`,"data-testid":`share-branch-switch-conflict`,children:[(0,Z.jsx)(`p`,{className:`font-medium text-foreground/90`,children:(0,Z.jsx)(s,{id:`n2lRue`})}),(0,Z.jsx)(`ul`,{id:`share-receive-branch-conflict-files`,className:`mt-1 list-disc space-y-0.5 pl-5 text-muted-foreground`,children:ne.conflictingFiles.map(GU)})]}):null,t[50]=o,t[51]=l.info,t[52]=l.otherWorktreePath,t[53]=l.phase,t[54]=F,t[55]=E,t[56]=w.branch,t[57]=w.owner,t[58]=w.repo,t[59]=w.target,t[60]=D,t[61]=g,t[62]=I,t[63]=L,t[64]=R,t[65]=z,t[66]=B,t[67]=V,t[68]=H,t[69]=U,t[70]=W,t[71]=G,t[72]=K,t[73]=q,t[74]=J,t[75]=Y,t[76]=ee,t[77]=te,t[78]=ne}else I=t[62],L=t[63],R=t[64],z=t[65],B=t[66],V=t[67],H=t[68],U=t[69],W=t[70],G=t[71],K=t[72],q=t[73],J=t[74],Y=t[75],ee=t[76],te=t[77],ne=t[78];let re;t[109]===V?re=t[110]:(re=V?(0,Z.jsxs)(`p`,{className:`mt-3 flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`share-branch-switch-switching`,role:`status`,"aria-live":`polite`,children:[(0,Z.jsx)(wt,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`CU3AiE`})]}):null,t[109]=V,t[110]=re);let ie;t[111]!==I||t[112]!==H||t[113]!==U||t[114]!==W||t[115]!==re?(ie=(0,Z.jsxs)(I,{children:[H,U,W,re]}),t[111]=I,t[112]=H,t[113]=U,t[114]=W,t[115]=re,t[116]=ie):ie=t[116];let ae;t[117]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(0,Z.jsx)(s,{id:`dEgA5A`}),t[117]=ae):ae=t[117];let oe;t[118]===F?oe=t[119]:(oe=(0,Z.jsx)(Qi,{variant:`ghost`,className:`font-mono uppercase`,onClick:F,"data-testid":`share-branch-switch-cancel`,children:ae}),t[118]=F,t[119]=oe);let se;t[120]!==l.phase||t[121]!==j||t[122]!==N||t[123]!==k||t[124]!==z||t[125]!==B||t[126]!==V||t[127]!==ne?(se=l.phase===`branch-in-other-worktree`?(0,Z.jsx)(Qi,{onClick:N,"data-testid":`share-branch-switch-in-other-worktree-pivot`,children:(0,Z.jsx)(s,{id:`hyCxJY`})}):(0,Z.jsxs)(`div`,{className:`flex flex-col-reverse gap-2 sm:flex-row sm:gap-2`,children:[ne?.openCurrentEnabled?(0,Z.jsxs)(Qi,{variant:`outline`,className:`font-mono uppercase`,onClick:j,disabled:V,"data-testid":`share-branch-switch-open-current`,children:[(0,Z.jsx)(fl,{className:`size-3.5`,"aria-hidden":!0}),z]}):null,(0,Z.jsx)(Qi,{onClick:k,disabled:!ne?.switchEnabled||V,"aria-disabled":!ne?.switchEnabled||V,"aria-describedby":ne&&!ne.switchEnabled&&ne.conflictingFiles.length>0?`share-receive-branch-conflict-files`:void 0,"data-testid":`share-branch-switch-switch`,children:V?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(wt,{className:`size-3.5 animate-spin`,"aria-hidden":`true`}),B]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ae,{className:`size-3.5`,"aria-hidden":!0}),B]})})]}),t[120]=l.phase,t[121]=j,t[122]=N,t[123]=k,t[124]=z,t[125]=B,t[126]=V,t[127]=ne,t[128]=se):se=t[128];let ce;t[129]!==oe||t[130]!==se?(ce=(0,Z.jsxs)(ds,{className:`sm:justify-between`,children:[oe,se]}),t[129]=oe,t[130]=se,t[131]=ce):ce=t[131];let le;t[132]!==L||t[133]!==G||t[134]!==K||t[135]!==q||t[136]!==J||t[137]!==Y||t[138]!==ie||t[139]!==ce?(le=(0,Z.jsxs)(L,{className:G,"data-testid":K,onInteractOutside:q,onPointerDownOutside:J,children:[Y,ie,ce]}),t[132]=L,t[133]=G,t[134]=K,t[135]=q,t[136]=J,t[137]=Y,t[138]=ie,t[139]=ce,t[140]=le):le=t[140];let ue;return t[141]!==R||t[142]!==ee||t[143]!==te||t[144]!==le?(ue=(0,Z.jsx)(R,{open:ee,onOpenChange:te,children:le}),t[141]=R,t[142]=ee,t[143]=te,t[144]=le,t[145]=ue):ue=t[145],ue}function GU(e){return(0,Z.jsx)(`li`,{children:(0,Z.jsx)(`code`,{className:`text-foreground/80`,children:e})},e)}function KU(e){e.preventDefault()}function qU(e){e.preventDefault()}function JU(e){return HU(e,null).state}function YU(e){return BU(e,null)}function XU(){return null}function ZU(){let e=(0,$.c)(17),t=Dn(),{collabUrl:n,setSystemProvider:r,updateServerInstanceId:i,onBranchSwitched:a,observeBranch:o,observeDiskAck:s,refreshServerInfo:c}=pt(),l;e[0]!==o||e[1]!==s||e[2]!==a||e[3]!==c||e[4]!==i?(l={updateServerInstanceId:i,onBranchSwitched:a,observeBranch:o,observeDiskAck:s,refreshServerInfo:c},e[0]=o,e[1]=s,e[2]=a,e[3]=c,e[4]=i,e[5]=l):l=e[5];let u=(0,Q.useRef)(l),d;e[6]!==o||e[7]!==s||e[8]!==a||e[9]!==c||e[10]!==i?(d=()=>{u.current={updateServerInstanceId:i,onBranchSwitched:a,observeBranch:o,observeDiskAck:s,refreshServerInfo:c}},e[6]=o,e[7]=s,e[8]=a,e[9]=c,e[10]=i,e[11]=d):d=e[11],(0,Q.useEffect)(d);let f,p;return e[12]!==n||e[13]!==t||e[14]!==r?(f=()=>{if(n===null)return;let e=new zt,i=new Ze({url:n,name:Mi,document:e,onStateless:e=>{let{payload:t}=e;fe(t,{onServerInfo:e=>{u.current.updateServerInstanceId(e.serverInstanceId),e.currentBranch!==void 0&&u.current.observeBranch(e.currentBranch)},onBranchSwitched:e=>{u.current.onBranchSwitched(e.branch)},onDiskAck:e=>{u.current.observeDiskAck(e.docName,e.sv)},onDerivedView:rW,onConfigValidationRejected:nW,onConfigIgnoreNestedError:tW,onUnknown:eW})},onClose:$U,onDisconnect:QU}),a=ni(e=>{(e.includes(`files`)||e.includes(`backlinks`))&&(t.invalidateQueries({queryKey:[`backlinks`]}),t.invalidateQueries({queryKey:[`forward-links`]})),(e.includes(`files`)||e.includes(`graph`))&&(t.invalidateQueries({queryKey:[`orphans`]}),t.invalidateQueries({queryKey:[`hubs`]}))}),o=E(()=>{u.current.refreshServerInfo()});i.on(`synced`,()=>{Ti([`files`,`backlinks`,`graph`]),o()});let s=new Set,c=()=>{if(i.awareness)for(let[e,t]of i.awareness.getStates().entries())s.has(e)||t.user?.type===`agent`&&(s.add(e),console.warn(`[agent-presence] observed stale AwarenessUser.type === 'agent' from clientID ${e} — probably a stale bundled client`))};return i.awareness?.on(`change`,c),r(i),()=>{a(),i.awareness?.off(`change`,c),r(null),i.destroy(),e.destroy()}},p=[t,n,r],e[12]=n,e[13]=t,e[14]=r,e[15]=f,e[16]=p):(f=e[15],p=e[16]),(0,Q.useEffect)(f,p),null}function QU(){console.warn(`[CC1] __system__ disconnected - derived views may be stale`)}function $U(e){let{event:t}=e;console.warn(`[CC1] __system__ connection closed:`,t.code,t.reason)}function eW(e){console.warn(`[CC1] Unparseable stateless payload, skipping:`,e.slice(0,100))}function tW(e){Bo(e)}function nW(e){Uo(e)}function rW(e){Ti([e.ch])}var iW=`#install-claude-desktop`;function aW(e){return e===`#settings`||e===iW}function oW(e,t,n){return[e,t,n].map(e=>[...e].sort().join(`\0`)).join(``)}function sW(){let e=(0,$.c)(23),{clearTarget:t,syncOpenTabsWithKnownTargets:n,tabSessionLoaded:r}=pt(),{openTargetTransition:i}=Et(),{assetPaths:a,folderPaths:o,loading:s,pageMeta:c,pages:l,pagesBySlug:u,pagesByBasename:d}=ki(),f=(0,Q.useRef)(null),p;e[0]!==a||e[1]!==o||e[2]!==l?(p=oW(l,o,a),e[0]=a,e[1]=o,e[2]=l,e[3]=p):p=e[3];let m=p,h,g;e[4]!==a||e[5]!==o||e[6]!==s||e[7]!==l||e[8]!==n||e[9]!==r||e[10]!==m?(h=()=>{s||!r||f.current===m||(f.current=m,n({pages:l,folderPaths:o,assetPaths:a}))},g=[a,o,s,l,n,r,m],e[4]=a,e[5]=o,e[6]=s,e[7]=l,e[8]=n,e[9]=r,e[10]=m,e[11]=h,e[12]=g):(h=e[11],g=e[12]),(0,Q.useEffect)(h,g);let _,v;return e[13]!==t||e[14]!==o||e[15]!==s||e[16]!==i||e[17]!==c||e[18]!==l||e[19]!==d||e[20]!==u?(_=()=>{e();function e(){if(aW(window.location.hash))return;let e=Hn(window.location.hash);if(e){let t=_i(e.split(`.`).pop()??``);b(`ok/nav/hash-change`,{docName:null,kind:`asset`}),i({kind:`asset`,target:e,assetPath:e,mediaKind:t});return}if(Sr(window.location.hash)){b(`ok/nav/hash-change`,{docName:null,kind:`folder`}),i({kind:`folder`,target:``,folderPath:``});return}let n=yr(window.location.hash);if(!n){b(`ok/nav/hash-change`,{docName:null,kind:`clear`}),t();return}if(s){b(`ok/nav/hash-change`,{docName:n,kind:`deferred-loading`});return}let r=ji(n,{pages:l,folderPaths:o,pagesBySlug:u,pagesByBasename:d});if(r.kind===`missing`&&/\/+$/.test(n.trim())){b(`ok/nav/hash-change`,{docName:n,kind:`deferred-missing-folder`});return}let a=Yr(Kr(r),c);b(`ok/nav/hash-change`,{docName:n,kind:a.kind}),i(a)}return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},v=[t,o,s,i,c,l,u,d],e[13]=t,e[14]=o,e[15]=s,e[16]=i,e[17]=c,e[18]=l,e[19]=d,e[20]=u,e[21]=_,e[22]=v):(_=e[21],v=e[22]),(0,Q.useEffect)(_,v),null}function cW(){let e=(0,$.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],(0,Q.useEffect)(lW,t),null}function lW(){let e=fW;if(!e(window.location.hash))return;let t=new AbortController;return _e(t.signal).then(n=>{if(t.signal.aborted||n.status!==`ok`)return;let r=n.config.paneTarget;r?.startsWith(`#/`)&&e(window.location.hash)&&(window.location.hash=r,fetch(`/api/config`,{method:`DELETE`}).catch(dW))}).catch(uW),()=>t.abort()}function uW(){}function dW(){}function fW(e){return!aW(e)&&!Hn(e)&&!yr(e)&&(e===``||e===`#`||e===`#/`)}function pW(){let e=(0,$.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],(0,Q.useEffect)(mW,t),null}function mW(){let e=function(e){let t=e.target;lh({target:t,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,key:e.key})&&(e.preventDefault(),window.location.hash!==`#settings`&&(window.location.hash=ch))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}function hW(){let e=(0,$.c)(4),{activeTarget:t}=pt(),n=typeof window<`u`?window.okDesktop??null:null,r=t?.kind===`doc`||t?.kind===`folder`||t?.kind===`asset`?t.kind:null,i=t?.kind===`doc`?t.docName:t?.kind===`folder`?t.folderPath:t?.kind===`asset`?t.assetPath:null,a,o;return e[0]!==i||e[1]!==r?(a=()=>{if(n){if(r===null){n.editor.notifyActiveTargetChanged({kind:null});return}i!==null&&n.editor.notifyActiveTargetChanged({kind:r,identifier:i})}},o=[n,r,i],e[0]=i,e[1]=r,e[2]=a,e[3]=o):(a=e[2],o=e[3]),(0,Q.useEffect)(a,o),null}function gW(){let e=(0,$.c)(8),{activeDocName:t,activeTarget:n}=pt(),[r,i]=(0,Q.useState)(!1),a;e[0]!==t||e[1]!==n?(a=n?.kind===`folder`?n.folderPath:qr(t),e[0]=t,e[1]=n,e[2]=a):a=e[2];let o=a,s,c;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>{let e=function(e){let t=e.target;Dm({target:t,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,key:e.key})&&(e.preventDefault(),i(!0))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},c=[],e[3]=s,e[4]=c):(s=e[3],c=e[4]),(0,Q.useEffect)(s,c);let l;return e[5]!==r||e[6]!==o?(l=(0,Z.jsx)(km,{open:r,onOpenChange:i,kind:`file`,initialDir:o}),e[5]=r,e[6]=o,e[7]=l):l=e[7],l}function _W(){let e=(0,$.c)(18),t=typeof window<`u`?window.okDesktop??null:null,n=typeof window<`u`&&window.okDesktop!=null,[r,i]=(0,Q.useState)(!1),a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(Og,{}),e[0]=a):a=e[0];let o,s,c,l,u,d,f,p,m,h;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(ZU,{}),c=(0,Z.jsx)(sW,{}),l=(0,Z.jsx)(cW,{}),u=(0,Z.jsx)(hW,{}),d=(0,Z.jsx)(gW,{}),f=(0,Z.jsx)(pW,{}),p=!1,m=t?(0,Z.jsx)(kg,{bridge:t}):null,h=(0,Z.jsx)(Md,{}),s=t?(0,Z.jsx)(WU,{bridge:t}):null,e[1]=o,e[2]=s,e[3]=c,e[4]=l,e[5]=u,e[6]=d,e[7]=f,e[8]=p,e[9]=m,e[10]=h):(o=e[1],s=e[2],c=e[3],l=e[4],u=e[5],d=e[6],f=e[7],p=e[8],m=e[9],h=e[10]);let g;e[11]===r?g=e[12]:(g=(0,Z.jsx)(bg,{bridge:t,open:r,onOpenChange:i}),e[11]=r,e[12]=g);let _;e[13]===Symbol.for(`react.memo_cache_sentinel`)?(_=n&&(0,Z.jsx)(`div`,{"aria-hidden":`true`,"data-testid":`editor-window-chrome-drag-strip`,"data-electron-drag":``,className:`pointer-events-none fixed inset-x-0 top-0 z-50 h-2 [-webkit-app-region:drag]`}),e[13]=_):_=e[13];let v;e[14]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Z.jsx)(jU,{onOpenSearch:()=>i(!0)}),e[14]=v):v=e[14];let y;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Z.jsxs)(LD,{className:`h-screen overflow-hidden`,children:[v,(0,Z.jsx)(UD,{className:`overflow-hidden h-[calc(100vh-var(--layout-inset-offset))]`,children:(0,Z.jsx)(bA,{onOpenSearch:()=>i(!0)})})]}),e[15]=y):y=e[15];let b;return e[16]===g?b=e[17]:(b=(0,Z.jsx)(x,{name:`app`,children:(0,Z.jsx)(Pt,{children:(0,Z.jsxs)(Lt,{children:[a,(0,Z.jsxs)(yi,{children:[o,c,l,u,d,f,p,m,h,s,g,_,y]})]})})}),e[16]=g,e[17]=b),b}gc(),pf({apiOrigin:typeof window<`u`?window.okDesktop?.config.apiOrigin:void 0}),Ef(),ep()&&op(),Fp(),typeof window<`u`&&Of({bridge:window.okDesktop}),typeof window<`u`&&Vf({bridge:window.okDesktop}),typeof window<`u`&&As({bridge:window.okDesktop}),typeof window<`u`&&Es({bridge:window.okDesktop}),typeof window<`u`&&jf({bridge:window.okDesktop}),typeof window<`u`&&Gd({bridge:window.okDesktop});var vW=new Tc({defaultOptions:{queries:{retry:1,staleTime:1e4}}}),yW=document.getElementById(`root`);if(!yW)throw Error(`Root element not found`);var bW=typeof window<`u`&&window.okDesktop?.config.mode===`navigator`;(0,Fc.createRoot)(yW).render((0,Z.jsx)(Q.StrictMode,{children:(0,Z.jsx)(a,{i18n:lr,children:(0,Z.jsx)(yn,{client:vW,children:(0,Z.jsxs)(Rr,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,disableTransitionOnChange:!0,storageKey:`ok-theme-v1`,children:[(0,Z.jsx)(fr,{children:bW&&window.okDesktop?(0,Z.jsx)(of,{bridge:window.okDesktop}):(0,Z.jsx)(_W,{})}),(0,Z.jsx)(df,{richColors:!0,closeButton:!0})]})})})}));
1915
+ </svg>`,wH=`${GB}\n${aV}`;function TH(e){return{...nM({type:e===`dark`?`dark`:`light`,colors:{"sideBar.background":`var(--sidebar)`,"sideBar.foreground":`var(--sidebar-foreground)`,"sideBar.border":`var(--sidebar-border)`,"list.activeSelectionBackground":`var(--sidebar-accent)`,"list.activeSelectionForeground":`var(--sidebar-accent-foreground)`,"list.hoverBackground":`var(--sidebar-hover)`,focusBorder:`var(--color-primary)`,"input.background":`var(--input)`,"input.border":`var(--border)`}}),"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`0.875rem`,"--trees-item-padding-x-override":`0.5rem`,"--trees-padding-inline-override":`0.5rem`,"--trees-border-radius-override":`0.375rem`,"--trees-selected-fg":`var(--color-primary)`,"--truncate-marker-fade-in-duration":`0s`,"--trees-file-icon-color-markdown":`light-dark(var(--color-gray-400), var(--color-gray-500))`,"--trees-file-icon-color-image":`light-dark(var(--color-gray-400), var(--color-gray-500))`,"--trees-fg-muted":`light-dark(var(--color-gray-400), var(--color-gray-500))`}}function EH(e){let t=e.split(`/`).pop()?.replace(/\.md$/i,``).toLowerCase();return!!t&&hH.has(t)}function DH(e){return e===`darwin`?lr._({id:`LtSYdi`}):e===`win32`?lr._({id:`qi1F96`}):lr._({id:`hz7n6T`})}function OH(e){let t=(0,$.c)(18),{item:n,workspace:r,onClose:a}=e,{_:o}=i(),s=typeof window<`u`?window.okDesktop:void 0;if(!s)return null;let c=s.platform,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=DH(c),t[0]=l):l=t[0];let u=l,d,f;t[1]!==o||t[2]!==r?(d=r?null:o({id:`wTcjov`}),f=o(c===`darwin`?d?{id:`FvpFSZ`,values:{hint:d}}:{id:`LtSYdi`}:c===`win32`?d?{id:`o4dcAf`,values:{hint:d}}:{id:`qi1F96`}:d?{id:`ScUTHW`,values:{hint:d}}:{id:`hz7n6T`}),t[1]=o,t[2]=r,t[3]=d,t[4]=f):(d=t[3],f=t[4]);let p=f,m=!r,h;t[5]!==n||t[6]!==a||t[7]!==r?(h=()=>{if(!r)return;a();let e=Lh(r.contentDir,pk(n),r.pathSeparator);s.shell.showItemInFolder(e)},t[5]=n,t[6]=a,t[7]=r,t[8]=h):h=t[8];let g,_;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Z.jsx)(yt,{"aria-hidden":`true`}),_=(0,Z.jsx)(`span`,{className:`flex-1`,children:u}),t[9]=g,t[10]=_):(g=t[9],_=t[10]);let v;t[11]===d?v=t[12]:(v=d?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:d}):null,t[11]=d,t[12]=v);let y;return t[13]!==p||t[14]!==m||t[15]!==h||t[16]!==v?(y=(0,Z.jsxs)(Wo,{disabled:m,onSelect:h,"aria-label":p,children:[g,_,v]}),t[13]=p,t[14]=m,t[15]=h,t[16]=v,t[17]=y):y=t[17],y}function kH(e){let t=(0,$.c)(21),{dirAbsPath:n,onClose:r}=e,{_:a}=i(),o=typeof window<`u`?window.okDesktop:void 0;if(!o)return null;let c,l,u,d,f;t[0]!==a||t[1]!==n||t[2]!==r?(l=n===null?a({id:`wTcjov`}):null,c=Wo,u=n===null,t[8]!==n||t[9]!==r?(d=()=>{n!==null&&(r(),MV(o,n))},t[8]=n,t[9]=r,t[10]=d):d=t[10],f=a(l?{id:`ehLu5O`,values:{hint:l}}:{id:`BJpGCq`}),t[0]=a,t[1]=n,t[2]=r,t[3]=c,t[4]=l,t[5]=u,t[6]=d,t[7]=f):(c=t[3],l=t[4],u=t[5],d=t[6],f=t[7]);let p;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Z.jsx)(Rl,{"aria-hidden":`true`}),t[11]=p):p=t[11];let m;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Z.jsx)(`span`,{className:`flex-1`,children:(0,Z.jsx)(s,{id:`BJpGCq`})}),t[12]=m):m=t[12];let h;t[13]===l?h=t[14]:(h=l?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:l}):null,t[13]=l,t[14]=h);let g;return t[15]!==c||t[16]!==u||t[17]!==d||t[18]!==f||t[19]!==h?(g=(0,Z.jsxs)(c,{disabled:u,onSelect:d,"aria-label":f,children:[p,m,h]}),t[15]=c,t[16]=u,t[17]=d,t[18]=f,t[19]=h,t[20]=g):g=t[20],g}function AH(e,t){return fk({kind:e.endsWith(`/`)?`directory`:`file`,name:e,path:e},t)}function jH(e,t){return e!==t&&e.startsWith(t)}function MH(e,t){let n=[...new Set(e)],r=n.filter(e=>e.endsWith(`/`));return n.filter(e=>!r.some(t=>jH(e,t))).map(e=>AH(e,t))}function NH(e,t){return e===t||e.startsWith(`${t}/`)}function PH(e){if(!(e instanceof HTMLElement))return!1;let t=e.tagName;return t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable||e.closest(`[contenteditable="true"]`)!==null}function FH(e,t,n){let r=new Set,i=new Set,a=new Set;for(let o of e){if(o.kind===`file`){r.add(o.path);continue}if(o.kind===`asset`){a.add(o.path);continue}i.add(o.path);for(let e of t)zn(e)&&e.docName.startsWith(`${o.path}/`)?r.add(e.docName):kr(e)&&e.path.startsWith(`${o.path}/`)&&a.add(e.path);for(let e of n){let t=tk(e);NH(t,o.path)&&i.add(t)}}return{docNames:r,folderPaths:i,assetPaths:a}}function IH(e,t){return e.kind===`file`?t.kind===`file`&&e.path===t.createdPath:e.kind===`asset`?!1:NH(t.createdPath,e.path)}function LH(e){let t=(0,$.c)(84),{item:n,context:r,anyActionBusy:a,workspace:o,handoff:c,model:l,okignoreBinding:u,projectLocalBinding:d,mergedConfig:f,onStartCreating:p,onCreateFromTemplate:m,onDuplicate:h,onDelete:g,onExpandSubtree:_,onCollapseSubtree:v,folderTreePaths:y,isAsset:b,documents:x}=e,{_:S}=i(),C,w,E,D,O,k,A,j,M,N;if(t[0]!==S||t[1]!==x||t[2]!==n||t[3]!==f?.appearance?.sidebar?.showAllFiles||t[4]!==f?.appearance?.sidebar?.showHiddenFiles||t[5]!==l||t[6]!==u||t[7]!==d){N=fk(n,x),O=n.kind===`directory`,k=N.kind===`asset`?null:N,C=k!==null&&u!==null;let e;t[18]!==S||t[19]!==O?(e=S(O?{id:`5D3Ior`}:{id:`dbhUX1`}),t[18]=S,t[19]=O,t[20]=e):e=t[20],D=e,j=f?.appearance?.sidebar?.showHiddenFiles??!1,A=f?.appearance?.sidebar?.showAllFiles??!1,w=d!==null;let r=l.getSelectedPaths(),i=r.includes(N.treePath)?MH(r,x):[];E=i.length>1?i:[N];let a=E.length;M=lr._({id:`44_vJP`,values:{deleteCount:a}}),t[0]=S,t[1]=x,t[2]=n,t[3]=f?.appearance?.sidebar?.showAllFiles,t[4]=f?.appearance?.sidebar?.showHiddenFiles,t[5]=l,t[6]=u,t[7]=d,t[8]=C,t[9]=w,t[10]=E,t[11]=D,t[12]=O,t[13]=k,t[14]=A,t[15]=j,t[16]=M,t[17]=N}else C=t[8],w=t[9],E=t[10],D=t[11],O=t[12],k=t[13],A=t[14],j=t[15],M=t[16],N=t[17];let P=M,F;t[21]!==O||t[22]!==n||t[23]!==o?(F=O&&o?Lh(o.contentDir,pk(n),o.pathSeparator):null,t[21]=O,t[22]=n,t[23]=o,t[24]=F):F=t[24];let I=F,L;if(t[25]!==O||t[26]!==n||t[27]!==o){bb0:{if(!o||O){L=null;break bb0}let e=pk(n),t=e.lastIndexOf(`/`);if(t===-1){L=o.contentDir;break bb0}L=Lh(o.contentDir,e.slice(0,t),o.pathSeparator)}t[25]=O,t[26]=n,t[27]=o,t[28]=L}else L=t[28];let R=L,z;t[29]!==b||t[30]!==O||t[31]!==n||t[32]!==o?(z=b?null:O?Vh({folderRelativePath:pk(n),workspace:o}):zh({docName:QO(n.path),workspace:o}),t[29]=b,t[30]=O,t[31]=n,t[32]=o,t[33]=z):z=t[33];let B=z,V;t[34]===r?V=t[35]:(V=()=>r.close({restoreFocus:!1}),t[34]=r,t[35]=V);let H=V,U;t[36]===r?U=t[37]:(U=()=>r.close(),t[36]=r,t[37]=U);let W=U,G;t[38]!==S||t[39]!==d?(G=e=>{if(d===null)return;let t=d.patch({appearance:{sidebar:{showHiddenFiles:e}}});t.ok||(console.warn(`[FileTree] showHiddenFiles toggle rejected:`,Er(t.error)),gs.error(S({id:`P47EWZ`}),{description:Er(t.error)}))},t[38]=S,t[39]=d,t[40]=G):G=t[40];let K=G,q;t[41]!==S||t[42]!==d?(q=e=>{if(d===null)return;let t=d.patch({appearance:{sidebar:{showAllFiles:e}}});t.ok||(console.warn(`[FileTree] showAllFiles toggle rejected:`,Er(t.error)),gs.error(S({id:`P47EWZ`}),{description:Er(t.error)}))},t[41]=S,t[42]=d,t[43]=q):q=t[43];let J=q,Y=0,ee=0;if(O){let e=nk(n.path);for(let t of y)(t===e||t.startsWith(e))&&(Y++,kV(l.getItem(t))?.isExpanded()&&ee++)}let te=O&&ee<Y,ne=O&&ee>0,ie;t[44]===W?ie=t[45]:(ie=e=>{e||W()},t[44]=W,t[45]=ie);let ae;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(0,Z.jsx)(Ho,{asChild:!0,children:(0,Z.jsx)(`span`,{"aria-hidden":`true`,"data-file-tree-context-menu-root":`true`,className:`block size-px`})}),t[46]=ae):ae=t[46];let oe;t[47]!==S||t[48]!==a||t[49]!==C||t[50]!==w||t[51]!==W||t[52]!==H||t[53]!==P||t[54]!==E||t[55]!==I||t[56]!==J||t[57]!==K||t[58]!==c||t[59]!==B||t[60]!==D||t[61]!==b||t[62]!==O||t[63]!==n||t[64]!==l||t[65]!==u||t[66]!==k||t[67]!==v||t[68]!==m||t[69]!==g||t[70]!==h||t[71]!==_||t[72]!==p||t[73]!==R||t[74]!==A||t[75]!==j||t[76]!==ne||t[77]!==te||t[78]!==N||t[79]!==o?(oe=(0,Z.jsx)(xo,{sideOffset:0,align:`start`,"data-file-tree-context-menu-root":`true`,className:`min-w-52`,children:O?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{H(),p(`file`,tk(n.path))},children:[(0,Z.jsx)(Nl,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`MW64zN`})]}),(0,Z.jsxs)(To,{children:[(0,Z.jsxs)(Fo,{disabled:a,children:[(0,Z.jsx)(mo,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`Uuj_R4`})]}),(0,Z.jsx)(go,{children:(0,Z.jsx)(OV,{parentDir:tk(n.path),onSelectTemplate:e=>{H(),m(tk(n.path),e)},ItemComponent:Wo})})]}),(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{H(),p(`folder`,tk(n.path))},children:[(0,Z.jsx)(el,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`tX5yOZ`})]}),(0,Z.jsx)(Vo,{}),(0,Z.jsx)(OH,{item:n,workspace:o,onClose:W}),(0,Z.jsx)(XV,{input:B,installStates:c.installStates,isElectronHost:c.isElectronHost,dispatch:c.dispatch,webFallbackVisible:!1}),(0,Z.jsx)(kH,{dirAbsPath:I,onClose:W}),(0,Z.jsxs)(To,{children:[(0,Z.jsxs)(Fo,{children:[(0,Z.jsx)(Be,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`zd00pH`})]}),(0,Z.jsxs)(go,{children:[(0,Z.jsx)(Wo,{disabled:!o,onSelect:()=>{o&&(W(),mH(Lh(o.contentDir,pk(n),o.pathSeparator),`full`))},children:(0,Z.jsx)(s,{id:`z2funE`})}),(0,Z.jsx)(Wo,{onSelect:()=>{W(),mH(pk(n),`relative`)},children:(0,Z.jsx)(s,{id:`xloBjn`})})]})]}),(0,Z.jsx)(Vo,{}),(0,Z.jsx)(ha,{checked:j,onCheckedChange:K,disabled:!w,"data-testid":`file-tree-menu-show-hidden-files`,children:(0,Z.jsx)(s,{id:`K_wz1u`})}),(0,Z.jsx)(ha,{checked:A,onCheckedChange:J,disabled:!w,"data-testid":`file-tree-menu-show-all-files`,children:(0,Z.jsx)(s,{id:`i8dKs-`})}),te||ne?(0,Z.jsx)(Vo,{}):null,te?(0,Z.jsxs)(Wo,{onSelect:()=>{W(),_(n.path)},children:[(0,Z.jsx)(Vl,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`b392Dr`})]}):null,ne?(0,Z.jsxs)(Wo,{onSelect:()=>{W(),v(n.path)},children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`BBtVak`})]}):null,(0,Z.jsx)(Vo,{}),(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{N.kind!==`asset`&&(W(),h(N))},children:[(0,Z.jsx)(Ke,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`euc6Ns`})]}),(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{H(),l.startRenaming(n.path)},children:[(0,Z.jsx)(T,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`2wxgft`})]}),(0,Z.jsxs)(Wo,{"data-testid":`file-tree-menu-hide`,disabled:!C,onSelect:()=>{if(!u||!k)return;W();let e=QB(k),t=Go(u.current()),n=Po(t,e);if(n===t)return;u.patch(Io(n));let r=k.path.split(`/`).pop()||k.path;gs.success(S({id:`4xtLTl`,values:{basename:r}}),{description:S({id:`nWv1ja`}),duration:5e3})},children:[(0,Z.jsx)(lt,{"aria-hidden":`true`}),D]}),(0,Z.jsxs)(Wo,{variant:`destructive`,disabled:a,onSelect:()=>{W(),g(E)},children:[(0,Z.jsx)(re,{"aria-hidden":`true`}),P]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(OH,{item:n,workspace:o,onClose:W}),!b&&(0,Z.jsx)(XV,{input:B,installStates:c.installStates,isElectronHost:c.isElectronHost,dispatch:c.dispatch,webFallbackVisible:!0}),(0,Z.jsx)(kH,{dirAbsPath:R,onClose:W}),(0,Z.jsxs)(To,{children:[(0,Z.jsxs)(Fo,{children:[(0,Z.jsx)(Be,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`zd00pH`})]}),(0,Z.jsxs)(go,{children:[(0,Z.jsx)(Wo,{disabled:!o,onSelect:()=>{o&&(W(),mH(Lh(o.contentDir,pk(n),o.pathSeparator),`full`))},children:(0,Z.jsx)(s,{id:`z2funE`})}),(0,Z.jsx)(Wo,{onSelect:()=>{W(),mH(pk(n),`relative`)},children:(0,Z.jsx)(s,{id:`xloBjn`})})]})]}),(0,Z.jsx)(Vo,{}),b?null:(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{W(),h(N)},children:[(0,Z.jsx)(Ke,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`euc6Ns`})]}),(0,Z.jsxs)(Wo,{disabled:a,onSelect:()=>{H(),l.startRenaming(n.path)},children:[(0,Z.jsx)(T,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`2wxgft`})]}),k?(0,Z.jsxs)(Wo,{"data-testid":`file-tree-menu-hide`,disabled:!C,onSelect:()=>{if(!u)return;W();let e=QB(k),t=Go(u.current()),n=Po(t,e);if(n===t)return;u.patch(Io(n));let r=k.path.split(`/`).pop()||k.path;gs.success(S({id:`OD0FCX`,values:{basename:r}}),{description:S({id:`nWv1ja`}),duration:5e3})},children:[(0,Z.jsx)(lt,{"aria-hidden":`true`}),D]}):null,(0,Z.jsxs)(Wo,{variant:`destructive`,disabled:a,onSelect:()=>{W(),g(E)},children:[(0,Z.jsx)(re,{"aria-hidden":`true`}),P]})]})}),t[47]=S,t[48]=a,t[49]=C,t[50]=w,t[51]=W,t[52]=H,t[53]=P,t[54]=E,t[55]=I,t[56]=J,t[57]=K,t[58]=c,t[59]=B,t[60]=D,t[61]=b,t[62]=O,t[63]=n,t[64]=l,t[65]=u,t[66]=k,t[67]=v,t[68]=m,t[69]=g,t[70]=h,t[71]=_,t[72]=p,t[73]=R,t[74]=A,t[75]=j,t[76]=ne,t[77]=te,t[78]=N,t[79]=o,t[80]=oe):oe=t[80];let se;return t[81]!==oe||t[82]!==ie?(se=(0,Z.jsxs)(Ya,{open:!0,modal:!1,onOpenChange:ie,children:[ae,oe]}),t[81]=oe,t[82]=ie,t[83]=se):se=t[83],se}function RH(e){let t=(0,$.c)(280),{ref:n}=e,{_:r}=i(),{activeDocName:a,activeTarget:o,closeTabs:c,closeDocument:l,closeAndClearForRename:u,getPoolActiveDocName:d,poolHas:f,isNewTabActive:p,openTarget:m,prewarm:h,remapTabsForRename:g}=pt(),{notifySidebarFileSelected:_}=ID(),{resolvedTheme:v}=Wr(),{addPage:y,pageMeta:b}=ki(),x;t[0]===b?x=t[1]:(x=function(e,t){return Ci(e,t??b.get(e)?.size)??{kind:`doc`,target:e,docName:e}},t[0]=b,t[1]=x);let S=x,C;t[2]!==S||t[3]!==_||t[4]!==m?(C=function(e,t){m(S(e,t),{tabBehavior:`replace-active`}),dH(gr(e)),_()},t[2]=S,t[3]=_,t[4]=m,t[5]=C):C=t[5];let w=C,T;t[6]!==_||t[7]!==m?(T=function(e){let t=_r(e);m({kind:`folder`,target:e,folderPath:e},{tabBehavior:`replace-active`}),dH(t),_()},t[6]=_,t[7]=m,t[8]=T):T=t[8];let E=T,D;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(D=[],t[9]=D):D=t[9];let[O,k]=(0,Q.useState)(D),[A,j]=(0,Q.useState)(!0),[M,N]=(0,Q.useState)(null),[P,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),[z,B]=(0,Q.useState)(null),[V,H]=(0,Q.useState)(null),{conflicts:U}=to(),[W,G]=(0,Q.useState)(null),[K,q]=(0,Q.useState)(null),J=(0,Q.useRef)(O),Y;t[10]!==O||t[11]!==E||t[12]!==w||t[13]!==_||t[14]!==m?(Y=function(e,t){let n=t===void 0?O:t,r=gV(e,n);if(r.kind===`none`){console.debug(`[FileTree] Dropped selection for unknown docName:`,rk(e));return}if(r.kind===`asset`){m({kind:`asset`,target:r.path,assetPath:r.path,mediaKind:r.mediaKind},{tabBehavior:`replace-active`}),dH(r.hash),_();return}if(r.kind===`folder`){E(r.path);return}let i=n.find(e=>zn(e)&&e.docName===r.path);w(r.path,i?.size)},t[10]=O,t[11]=E,t[12]=w,t[13]=_,t[14]=m,t[15]=Y):Y=t[15];let ee=Y,te;t[16]!==_||t[17]!==m?(te=function(e){m({kind:`asset`,target:e,assetPath:e,mediaKind:J.current.find(t=>kr(t)&&t.path===e)?.mediaKind??null},{tabBehavior:`replace-active`}),dH(fi(e)),_()},t[16]=_,t[17]=m,t[18]=te):te=t[18];let ne=te,re=(0,Q.useRef)(a),ie;t[19]===O?ie=t[20]:(ie=new Set(O.filter(kr).map(cU)),t[19]=O,t[20]=ie);let ae=ie,oe=(0,Q.useRef)(ae),se;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(se=[],t[21]=se):se=t[21];let ce=(0,Q.useRef)(se),le=(0,Q.useRef)(null),ue=(0,Q.useRef)(sU),de=(0,Q.useRef)(null),fe=(0,Q.useRef)(null),pe=(0,Q.useRef)(!1),me=(0,Q.useRef)(null),he;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(he=new Map,t[22]=he):he=t[22];let ge=(0,Q.useRef)(he),_e=(0,Q.useRef)(!1),ve=(0,Q.useRef)(!1),ye=(0,Q.useRef)(null),be=(0,Q.useRef)(null),xe=(0,Q.useRef)(oU),Se=(0,Q.useRef)(aU),Ce=(0,Q.useRef)(iU),we=(0,Q.useRef)(rU),Te=(0,Q.useRef)(o),{selectedFilePath:Ee,selectedFolderPath:De,navigationPath:Oe}=hV(o,p?null:a),ke=Ee?ZO(Ee,O.find(e=>zn(e)&&e.docName===Ee)?.docExt):De?nk(De):o?.kind===`asset`?o.assetPath:null,Ae=ug().states,{dispatch:je}=$h(),Me;t[23]!==je||t[24]!==Ae?(Me={installStates:Ae,isElectronHost:typeof window<`u`&&window.okDesktop!=null,dispatch:je},t[23]=je,t[24]=Ae,t[25]=Me):Me=t[25];let Ne=Me,{okignoreBinding:Pe,projectLocalBinding:Fe,merged:Ie}=gt(),Le=Ie?.appearance?.sidebar?.showHiddenFiles??!1,Re=Ie?.appearance?.sidebar?.showAllFiles??!1,ze;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(ze=()=>me.current===null,t[26]=ze):ze=t[26];let Be=ze,Ve;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(Ve=[],t[27]=Ve):Ve=t[27];let He;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(He={set:`complete`,spriteSheet:CH,byFileExtension:{md:{name:vH,viewBox:yH},mdx:{name:vH,viewBox:yH}}},t[28]=He):He=t[28];let Ue;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(Ue={contextMenu:{enabled:!0,triggerMode:`both`,buttonVisibility:`when-needed`}},t[29]=Ue):Ue=t[29];let We;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(We={canDrag:Be,canDrop:Be,onDropComplete:e=>we.current(e),onDropError:nU},t[30]=We):We=t[30];let Ge,Ke;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(Ge={canRename:Be,onRename:e=>Se.current(e),onError:e=>Ce.current(e)},Ke=e=>xe.current(e),t[31]=Ge,t[32]=Ke):(Ge=t[31],Ke=t[32]);let qe;t[33]===r?qe=t[34]:(qe={paths:Ve,flattenEmptyDirectories:!1,initialExpansion:`closed`,fileTreeSearchMode:`hide-non-matches`,initialVisibleRowCount:18,stickyFolders:!0,icons:He,unsafeCSS:wH,composition:Ue,dragAndDrop:We,renaming:Ge,onSelectionChange:Ke,renderRowDecoration:e=>{let{item:t}=e;if(t.kind!==`file`)return null;let n=J.current.find(e=>zn(e)&&ZO(e.docName,e.docExt)===t.path);if(n?.isSymlink){let e=n.targetPath;return{icon:gH,title:r(e?{id:`JE21eh`,values:{targetPath:e}}:{id:`BQu9Pg`})}}return EH(t.path)?{icon:_H,title:r({id:`i9toLO`})}:null}},t[33]=r,t[34]=qe);let{model:X}=zB(qe),Je;t[35]===X?Je=t[36]:(Je=function(e){let t=X.getItem(e)??X.getItem(nk(e));return t?.isDirectory()?nk(tk(t.getPath())):e},t[35]=X,t[36]=Je);let Ye=Je,Xe,Ze;t[37]===O?(Xe=t[38],Ze=t[39]):(Ze=ik(O),Xe=ak(Ze),t[37]=O,t[38]=Xe,t[39]=Ze);let Qe=Xe,$e=(0,Q.useRef)(Ze),et;t[40]===O?et=t[41]:(et=sk(O),t[40]=O,t[41]=et);let tt=et,nt=(0,Q.useRef)(tt),rt=De?ck(nk(De)).slice(0,-1):ck(ke??Oe),it=rt.join(`\0`),at;if(t[42]!==X){let e=()=>{let e=new Set;for(let t of nt.current)kV(X.getItem(t))?.isExpanded()&&e.add(t);return e};at=t=>{let n=new Set(sk(t??J.current)),r=e();for(let e of ce.current)r.add(e);return[...r].filter(e=>n.has(e))},t[42]=X,t[43]=at}else at=t[43];let ot=at,st;t[44]!==ot||t[45]!==X?(st=e=>{let t=ik(e??J.current);X.resetPaths(t,{initialExpandedPaths:ot(e)})},t[44]=ot,t[45]=X,t[46]=st):st=t[46];let ct=st,lt;t[47]!==X||t[48]!==ct?(lt=(e,t,n,r)=>{let i=r===void 0?[]:r,a=0,o=null;for(let{fromDocName:t,toDocName:r}of n){let n=e.find(e=>zn(e)&&e.docName===t);if(n==null||X.getItem(r)==null)continue;let i=ZO(r,n.docExt);X.move(r,i),o=i,a+=1}for(let{toPath:e}of i){let t=BB(e);if(t===``)continue;let n=e.slice(0,-t.length);X.getItem(n)!=null&&(X.getItem(e)??X.move(n,e),o=e,a+=1)}a!==0&&(ct(t),o!=null&&X.focusPath(o))},t[47]=X,t[48]=ct,t[49]=lt):lt=t[49];let ut=lt,dt;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(dt=e=>{de.current=ok(e)},t[50]=dt):dt=t[50];let ft=dt,mt;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(mt=e=>oe.current.has(e),t[51]=mt):mt=t[51];let ht=mt,_t;t[52]!==r||t[53]!==y||t[54]!==E||t[55]!==w||t[56]!==ct?(_t=async function(e){if(e.kind===`asset`||me.current!==null)return;let t=()=>{R(null),me.current=null};me.current=e.path,R(e.path),N(null);try{let n=await Tt(await fetch(`/api/duplicate-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:e.kind,path:e.path})}),r({id:`dw_dUJ`}));if(!n.ok){gs.error(n.title),ct(),t();return}let i=F(Fn,n.body,`duplicate-path`,null);if(i===null){let e=r({id:`67f-3g`});gs.error(e),N(e),Ti([`files`,`backlinks`,`graph`]),ct(),t();return}for(let e of i.duplicatedDocNames)y(e);k(t=>{let n=Ek(t,e,i);return ct(n),ft(n),n}),Ti([`files`,`backlinks`,`graph`]),i.path!==e.path&&(i.kind===`folder`?E(i.path):w(i.path)),gs.success(i.kind===`folder`?r({id:`iilQXA`}):r({id:`A6h5b-`}),{description:i.path}),t()}catch(e){let n=e,i=n instanceof Error?n.message:String(n);console.warn(`[FileTree] duplicate failed:`,n),gs.error(r({id:`EBVbtP`}),{description:i}),ct(),t()}},t[52]=r,t[53]=y,t[54]=E,t[55]=w,t[56]=ct,t[57]=_t):_t=t[57];let vt=_t,yt=(0,Q.useRef)(vt),bt;t[58]===vt?bt=t[59]:(bt=()=>{yt.current=vt},t[58]=vt,t[59]=bt),(0,Q.useEffect)(bt);let xt=function(e){let t=fH(e);if(!t||pH(t))return!1;let n=X.getFocusedPath()??X.getSelectedPaths()[0]??null;if(!n||n.endsWith(`/`)||ht(n))return!1;let r=pH(n);if(!r)return!1;let i=nk(t);if(!nt.current.includes(i))return!1;let a=`${t}${r}`;return $e.current.includes(a)?!1:(Qt({sourcePath:n,destinationPath:a,isFolder:!1}),X.move(n,a),!0)},St;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(St=e=>{let t=e??le.current;!t||le.current!==t||(t.disposeCommitListener(),le.current=null)},t[60]=St):St=t[60];let Ct=St,wt;t[61]!==r||t[62]!==Ct||t[63]!==l||t[64]!==c||t[65]!==ct?(wt=async function(e,t){let n=t===void 0?{}:t,i=n.updateUi??!0,a=n.restoreLocation??i;Ct(e),i&&R(e.renamePath);try{let t=await fetch(`/api/delete-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:e.kind,path:e.createdPath})});if(!t.ok&&t.status!==404){let n=e.kind,a=e.createdPath,o=await Tt(t,r({id:`EcM3k7`,values:{kind:n}}));if(o.ok)return;let s=o.title,c=r({id:`YPFBfr`,values:{detail:s,kind:n,createdPath:a}});i?gs.error(c):console.warn(`[FileTree] cleanup pending create failed: ${c}`),i&&(R(null),ct());return}}catch(t){if(console.warn(`[FileTree] cleanup pending create failed:`,t),i){let t=e.kind,n=e.createdPath;gs.error(r({id:`_TDESN`,values:{kind:t,createdPath:n}}))}i&&(R(null),ct());return}i&&(e.kind===`file`?l(e.createdPath):c([Zt(e.createdPath)],{force:!0})),i&&k(t=>{let n=wk(t,e.kind===`file`?[e.createdPath]:[],e.kind===`folder`?e.createdPath:void 0);return ft(n),n}),Ti([`files`,`backlinks`,`graph`]),a&&(window.location.hash=e.previousHash),i&&R(null)},t[61]=r,t[62]=Ct,t[63]=l,t[64]=c,t[65]=ct,t[66]=wt):wt=t[66];let Et=wt,Dt,Ot;t[67]===Symbol.for(`react.memo_cache_sentinel`)?(Dt=()=>()=>{let e=le.current;e&&ue.current(e,{restoreLocation:!1,updateUi:!1}).catch(tU)},Ot=[],t[67]=Dt,t[68]=Ot):(Dt=t[67],Ot=t[68]),(0,Q.useEffect)(Dt,Ot);let kt,At;t[69]===r?(kt=t[70],At=t[71]):(kt=()=>{let e=!0,t=null,n=HV(async function(){t?.abort();let n=new AbortController;t=n;try{let t=ve.current,i=await fetch(t?`/api/documents?showAll=true`:`/api/documents`,{signal:n.signal,headers:t?UV:void 0});if(t&&WV(i)){let{entries:n,truncated:r}=await qV(i);if(!e)return;k(JV(Bi(n,_e.current||t),J.current,ge.current)),N(null),I(r?n.length:null)}else{let n=await Tt(i,r({id:`8RtNI0`}));if(!e)return;if(!n.ok)N(n.title),I(null);else{let e=vi.safeParse(n.body);if(!e.success)N(r({id:`HlmZBk`})),I(null);else{let n=_e.current||t;k(JV(Bi(e.data.documents,n),J.current,ge.current)),N(null),I(t&&e.data.truncated===!0?e.data.documents.length:null)}}}}catch(t){let i=t;if(n.signal.aborted)return;e&&N(r({id:`34qyH5`})),console.warn(`[FileTree] fetch failed:`,i)}e&&j(!1)},()=>t?.abort());ye.current=()=>n.request(),n.request();let i=()=>{document.visibilityState===`visible`&&n.request()};window.addEventListener(`focus`,i),window.addEventListener(`visibilitychange`,i);let a=ni(e=>{e.includes(`files`)&&n.request()});return()=>{e=!1,ye.current=null,n.dispose(),window.removeEventListener(`focus`,i),window.removeEventListener(`visibilitychange`,i),a()}},At=[r],t[69]=r,t[70]=kt,t[71]=At),(0,Q.useEffect)(kt,At);let jt=(0,Q.useRef)(!0),Mt;t[72]===Symbol.for(`react.memo_cache_sentinel`)?(Mt=()=>{if(jt.current){jt.current=!1;return}ye.current?.()},t[72]=Mt):Mt=t[72];let Nt;t[73]===Le?Nt=t[74]:(Nt=[Le],t[73]=Le,t[74]=Nt),(0,Q.useEffect)(Mt,Nt);let Pt=(0,Q.useRef)(!0),Ft;t[75]===Symbol.for(`react.memo_cache_sentinel`)?(Ft=()=>{if(Pt.current){Pt.current=!1;return}ye.current?.()},t[75]=Ft):Ft=t[75];let It;t[76]===Re?It=t[77]:(It=[Re],t[76]=Re,t[77]=It),(0,Q.useEffect)(Ft,It);let Lt,Rt;t[78]===Symbol.for(`react.memo_cache_sentinel`)?(Lt=()=>{let e=!0;return fetch(`/api/workspace`).then(async t=>{let n=await t.json();if(!e||!t.ok)return;let r=F(Vi,n,`workspace`,null);r&&q({contentDir:r.contentDir,pathSeparator:r.pathSeparator})}).catch(eU),()=>{e=!1}},Rt=[],t[78]=Lt,t[79]=Rt):(Lt=t[78],Rt=t[79]),(0,Q.useEffect)(Lt,Rt);let zt;t[80]!==ot||t[81]!==X||t[82]!==Qe?(zt=()=>{if(de.current===Qe){de.current=null;return}X.resetPaths($e.current,{initialExpandedPaths:ot()})},t[80]=ot,t[81]=X,t[82]=Qe,t[83]=zt):zt=t[83];let Bt;t[84]!==X||t[85]!==Qe?(Bt=[X,Qe],t[84]=X,t[85]=Qe,t[86]=Bt):Bt=t[86],(0,Q.useEffect)(zt,Bt),jV(X,ke,it,pe,Qe);let Vt;t[87]!==ke||t[88]!==A||t[89]!==X?(Vt=()=>{A||!ke||pV(be.current,X)},t[87]=ke,t[88]=A,t[89]=X,t[90]=Vt):Vt=t[90];let Ht;t[91]!==it||t[92]!==ke||t[93]!==A||t[94]!==X||t[95]!==Qe?(Ht=[ke,it,Qe,A,X],t[91]=it,t[92]=ke,t[93]=A,t[94]=X,t[95]=Qe,t[96]=Ht):Ht=t[96],(0,Q.useEffect)(Vt,Ht);let Ut,Wt;t[97]===X?(Ut=t[98],Wt=t[99]):(Ut=()=>X.subscribe(()=>{if(!X.isSearchOpen())for(let e of ce.current){let t=kV(X.getItem(e));t&&!t.isExpanded()&&t.expand()}}),Wt=[X],t[97]=X,t[98]=Ut,t[99]=Wt),(0,Q.useEffect)(Ut,Wt);let Gt,qt;t[100]===X?(Gt=t[101],qt=t[102]):(Gt=()=>X.onMutation(`remove`,e=>{let t=le.current;!t||e.path!==t.renamePath||ue.current(t)}),qt=[X],t[100]=X,t[101]=Gt,t[102]=qt),(0,Q.useEffect)(Gt,qt);let Yt;t[103]!==y||t[104]!==u||t[105]!==d||t[106]!==ne||t[107]!==E||t[108]!==f||t[109]!==ut||t[110]!==g?(Yt=async(e,t,n,r)=>{let i=t===void 0?[]:t,a=n===void 0?[]:n,o=r?.docName??re.current,s=Dk(o,e),c=r?.folderPath??(Te.current?.kind===`folder`?Te.current.folderPath:null),l=c?Jt(c,i):null,p=r?.assetPath??(Te.current?.kind===`asset`?Te.current.assetPath:null),m=p?a.find(e=>e.fromPath===p)?.toPath??Jt(p,i):null;Kt(e);let h=Ok(e,d(),f);await Promise.all(h.map(e=>u(e)));for(let t of e)y(t.toDocName);g(e,i,a),k(t=>{let n=Ck(t,e,i,a);return ut(t,n,e,a),ft(n),n}),c&&l&&l!==c?E(l):s&&s!==o?window.location.hash=gr(s):p&&m&&m!==p&&ne(m),Ti([`files`,`backlinks`,`graph`])},t[103]=y,t[104]=u,t[105]=d,t[106]=ne,t[107]=E,t[108]=f,t[109]=ut,t[110]=g,t[111]=Yt):Yt=t[111];let Xt=Yt;async function Qt(e){let t=!e.isFolder&&ht(e.sourcePath),n=t?e.sourcePath:mk(e.sourcePath,e.isFolder);R(n),N(null);try{let i=HB(e.sourcePath,e.destinationPath,e.isFolder,t);if(i.kind===`block`){gs.error(r({id:`FaBZwp`})),queueMicrotask(()=>{ct()}),Ct(),R(null);return}let a=t?i.destinationPath:mk(i.destinationPath,e.isFolder),o=e.isFolder?{kind:`folder`,fromPath:tk(n),toPath:tk(a)}:t?{kind:`asset`,fromPath:n,toPath:a}:{kind:`file`,fromPath:QO(n),toPath:QO(a)},s={docName:re.current,folderPath:Te.current?.kind===`folder`?Te.current.folderPath:null,assetPath:Te.current?.kind===`asset`?Te.current.assetPath:null},c=await Tt(await fetch(`/api/rename-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(o)}),r({id:`gijbne`}));if(!c.ok){gs.error(c.title),ct();let e=le.current;e&&e.renamePath===n?await Et(e):Ct(),R(null);return}let l=F(li,c.body,`rename-path`,{renamed:[],renamedAssets:[]});try{await Xt(l.renamed,e.isFolder?[{fromPath:tk(n),toPath:tk(a)}]:[],l.renamedAssets,s)}catch(e){console.warn(`[FileTree] post-rename reconciliation failed`,{err:e,sourceTreePath:n,destinationTreePath:a,renamedCount:l.renamed.length,renamedAssetCount:l.renamedAssets.length}),gs.error(r({id:`dDpCOp`}))}Ct(),R(null)}catch(e){console.warn(`[FileTree] rename failed:`,e);let t=r({id:`HIb0vl`});gs.error(t),N(t),ct();let i=le.current;i&&i.renamePath===n?await Et(i):Ct(),R(null)}}let $t;t[112]!==r||t[113]!==Xt||t[114]!==ct?($t=async function(e){let t=e.draggedPaths.map(t=>{let n=_k(t,e.target);return t===n?null:{sourcePath:t,destinationTreePath:n}}).filter($H);if(t.length!==0){R(t[0]?.sourcePath??null),N(null);try{let e=[],n=[],i=[],a={docName:re.current,folderPath:Te.current?.kind===`folder`?Te.current.folderPath:null,assetPath:Te.current?.kind===`asset`?Te.current.assetPath:null};for(let a of t){let t=a.sourcePath.endsWith(`/`),o=!t&&ht(a.sourcePath),s=t?{kind:`folder`,fromPath:tk(a.sourcePath),toPath:tk(a.destinationTreePath)}:o?{kind:`asset`,fromPath:a.sourcePath,toPath:a.destinationTreePath}:{kind:`file`,fromPath:QO(a.sourcePath),toPath:QO(a.destinationTreePath)},c=await Tt(await fetch(`/api/rename-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(s)}),r({id:`dOHMA0`}));if(!c.ok){gs.error(c.title),ct(),R(null);return}let l=F(li,c.body,`rename-path:drop`,{renamed:[],renamedAssets:[]});e=e.concat(l.renamed),n=n.concat(l.renamedAssets),t&&i.push({fromPath:tk(a.sourcePath),toPath:tk(a.destinationTreePath)})}try{await Xt(e,i,n,a)}catch(i){console.warn(`[FileTree] post-move reconciliation failed`,{err:i,operationCount:t.length,renamedCount:e.length,renamedAssetCount:n.length}),gs.error(r({id:`8OxKZy`}))}R(null)}catch(e){console.warn(`[FileTree] move failed:`,e),gs.error(r({id:`HIb0vl`})),ct(),R(null)}}},t[112]=r,t[113]=Xt,t[114]=ct,t[115]=$t):$t=t[115];let en=$t,tn;t[116]===Symbol.for(`react.memo_cache_sentinel`)?(tn=function(e){G({parentDir:e})},t[116]=tn):tn=t[116];let nn=tn,rn;t[117]!==r||t[118]!==y||t[119]!==Et||t[120]!==Ct||t[121]!==X||t[122]!==E||t[123]!==w||t[124]!==ct||t[125]!==Ze?(rn=async function(e,t,n){if(me.current)return;let i=le.current;i&&Ct(i);try{let i=hk(e,t,[...Ze,...nt.current]);R(i.renamePath),me.current=i.renamePath;let a=window.location.hash,o;if(e===`file`){let e=gk(`file`,i.addPath),t={path:e};n?.template&&(t.template=n.template);let a=await Tt(await fetch(`/api/create-page`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}),r({id:`fJgQHX`}));if(!a.ok){gs.error(a.title),R(null),me.current=null;return}let s=QO(e),c=F(zi,a.body,`create-page`,{docName:s}).docName;o=c;let l={kind:`document`,docName:c,docExt:e.toLowerCase().endsWith(`.mdx`)?`.mdx`:`.md`,modified:new Date().toISOString(),size:0};y(c),k(e=>{if(e.some(e=>zn(e)&&e.docName===c))return e;let t=[...e,l];return ft(t),ge.current.set($O(l),Date.now()),t}),Ti([`files`,`backlinks`,`graph`]),w(c)}else{let e=tk(i.addPath),t=await Tt(await fetch(`/api/create-folder`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:e})}),r({id:`K1ckLX`}));if(!t.ok){gs.error(t.title),R(null),me.current=null;return}o=F(Vn,t.body,`create-folder`,{path:e}).path;let n={kind:`folder`,path:o,modified:new Date().toISOString(),size:0};k(e=>{if(e.some(e=>Li(e)&&e.path===o))return e;let t=[...e,n];return ft(t),ge.current.set($O(n),Date.now()),t}),Ti([`files`]),E(o)}let s=!1,c=e=>{if(e.key!==`Enter`)return;let t=le.current;!t||t.renamePath!==i.renamePath||queueMicrotask(()=>Ct(t))};document.addEventListener(`keydown`,c,!0),le.current={kind:e,renamePath:i.renamePath,createdPath:o,previousHash:a,disposeCommitListener:()=>{s||(s=!0,document.removeEventListener(`keydown`,c,!0))}},R(null),me.current=null,X.add(i.addPath),X.startRenaming(i.renamePath,{removeIfCanceled:!0})}catch(e){console.warn(`[FileTree] create placeholder failed:`,e),gs.error(r({id:`S6l5dv`}));let t=le.current;t?await Et(t):Ct(),R(null),me.current=null,ct()}},t[117]=r,t[118]=y,t[119]=Et,t[120]=Ct,t[121]=X,t[122]=E,t[123]=w,t[124]=ct,t[125]=Ze,t[126]=rn):rn=t[126];let an=rn,on;t[127]===X?on=t[128]:(on=function(e){let t=nk(e);(0,Q.startTransition)(()=>{for(let e of nt.current)if(e===t||e.startsWith(t)){let t=kV(X.getItem(e));t&&t.expand()}})},t[127]=X,t[128]=on);let sn=on,cn;t[129]===X?cn=t[130]:(cn=function(e){let t=nk(e),n=new Set(ce.current);(0,Q.startTransition)(()=>{for(let e of[...nt.current].reverse())if((e===t||e.startsWith(t))&&!n.has(e)){let t=kV(X.getItem(e));t&&t.collapse()}})},t[129]=X,t[130]=cn);let ln=cn,un;t[131]!==ee||t[132]!==rt||t[133]!==a||t[134]!==o||t[135]!==ae||t[136]!==L||t[137]!==Et||t[138]!==O||t[139]!==tt||t[140]!==en||t[141]!==Qt||t[142]!==Ye||t[143]!==xt||t[144]!==Re||t[145]!==Le||t[146]!==Ze?(un=()=>{J.current=O,re.current=a,Te.current=o,oe.current=ae,me.current=L,_e.current=Le,ve.current=Re,$e.current=Ze,nt.current=tt,ce.current=rt,ue.current=Et,xe.current=e=>{if(pe.current||e.length!==1)return;let t=e[0];t&&ee(Ye(t),O)},Ce.current=e=>{xt(e)||gs.error(e)},Se.current=Qt,we.current=en},t[131]=ee,t[132]=rt,t[133]=a,t[134]=o,t[135]=ae,t[136]=L,t[137]=Et,t[138]=O,t[139]=tt,t[140]=en,t[141]=Qt,t[142]=Ye,t[143]=xt,t[144]=Re,t[145]=Le,t[146]=Ze,t[147]=un):un=t[147],(0,Q.useLayoutEffect)(un);let dn,fn;t[148]===X?(dn=t[149],fn=t[150]):(dn=()=>{let e=e=>{let t=(e.metaKey||e.ctrlKey)&&!e.altKey,n=e.key.toLowerCase(),r=t&&n===`a`,i=t&&!e.shiftKey&&n===`d`;if(!r&&!i||PH(e.target))return;let a=be.current,o=e.target,s=document.activeElement,c=o instanceof Node&&a?.contains(o),l=s instanceof Node&&a?.contains(s);if(!c&&!l)return;if(i){let t=X.getFocusedPath()??X.getSelectedPaths()[0]??null;if(!t)return;let n=X.getItem(t)??X.getItem(nk(t)),r=n?.isDirectory()?nk(tk(n.getPath())):t;if(oe.current.has(r))return;yt.current(AH(r,J.current)),e.preventDefault(),e.stopPropagation();return}let u=new Set([...nt.current,...$e.current]);pe.current=!0;for(let e of u)e&&X.getItem(e)?.select();queueMicrotask(()=>{pe.current=!1}),e.preventDefault(),e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},fn=[X],t[148]=X,t[149]=dn,t[150]=fn),(0,Q.useEffect)(dn,fn);let pn,mn;t[151]!==O.length||t[152]!==A?(pn=()=>{if(A||O.length===0)return;let e=be.current?.querySelector(Fj)?.shadowRoot;if(!e)return;let t=QH,n=()=>{for(let n of e.querySelectorAll(`[data-item-path]`)){let e=n.dataset.itemPath;if(!e)continue;let r=t(e);n.title!==r&&(n.title=r)}let n=e.querySelector(`[data-type="context-menu-anchor"]`);if(n){let r=e.querySelector(`[data-item-context-hover="true"][data-item-path]`)?.dataset.itemPath,i=r?t(r):``;n.title!==i&&(n.title=i)}};n();let r=new MutationObserver(n);return r.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`data-item-path`,`data-item-context-hover`]}),()=>r.disconnect()},mn=[A,O.length],t[151]=O.length,t[152]=A,t[153]=pn,t[154]=mn):(pn=t[153],mn=t[154]),(0,Q.useEffect)(pn,mn);let hn,gn;t[155]!==O.length||t[156]!==A?(hn=()=>{if(A||O.length===0)return;let e=be.current?.querySelector(Fj)?.shadowRoot;if(!e)return;let t=()=>KB(e);t();let n=new MutationObserver(t);return n.observe(e,{subtree:!0,childList:!0,characterData:!0,attributes:!0,attributeFilter:[`data-item-path`]}),()=>n.disconnect()},gn=[A,O.length],t[155]=O.length,t[156]=A,t[157]=hn,t[158]=gn):(hn=t[157],gn=t[158]),(0,Q.useEffect)(hn,gn);let _n,vn;t[159]!==O.length||t[160]!==A?(_n=()=>{if(A||O.length===0)return;let e=be.current?.querySelector(Fj)?.shadowRoot;if(!e)return;let t=()=>oV(e);t();let n=new MutationObserver(t);return n.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`data-item-path`]}),()=>n.disconnect()},vn=[A,O.length],t[159]=O.length,t[160]=A,t[161]=_n,t[162]=vn):(_n=t[161],vn=t[162]),(0,Q.useEffect)(_n,vn);let yn;t[163]===Symbol.for(`react.memo_cache_sentinel`)?(yn={folderCount:0,expandedCount:0},t[163]=yn):yn=t[163];let bn=(0,Q.useRef)(yn),xn=(0,Q.useRef)(an),Sn=(0,Q.useRef)(nn),Cn;t[164]===an?Cn=t[165]:(Cn=()=>{xn.current=an,Sn.current=nn},t[164]=an,t[165]=Cn),(0,Q.useEffect)(Cn);let wn,Tn;t[166]===X?(wn=t[167],Tn=t[168]):(wn=()=>({startCreating(e,t){xn.current(e,t)},startCreatingFromTemplate(e){Sn.current(e)},createFromTemplate(e,t){xn.current(`file`,e,{template:t})},expandAll(){(0,Q.startTransition)(()=>{for(let e of nt.current){let t=kV(X.getItem(e));t&&t.expand()}})},collapseAll(){let e=new Set(ce.current);(0,Q.startTransition)(()=>{for(let t of[...nt.current].reverse()){if(e.has(t))continue;let n=kV(X.getItem(t));n&&n.collapse()}})},getFolderState(){let e=nt.current,t=0;for(let n of e)kV(X.getItem(n))?.isExpanded()&&t++;let n=e.length,r=bn.current;if(r.folderCount===n&&r.expandedCount===t)return r;let i={folderCount:n,expandedCount:t};return bn.current=i,i},subscribe(e){return X.subscribe(e)}}),Tn=[X],t[166]=X,t[167]=wn,t[168]=Tn),(0,Q.useImperativeHandle)(n,wn,Tn);let En;t[169]!==Ct||t[170]!==u||t[171]!==c||t[172]!==X?(En=async function(e,t,n){let r=FH(e,J.current,nt.current),i=le.current;i&&e.some(e=>IH(e,i))&&(i.kind===`file`?r.docNames.add(i.createdPath):r.folderPaths.add(i.createdPath),Ct(i));let a=new Set([...r.docNames,...t]),o=new Set([...r.folderPaths,...n]),s=new Set([...r.assetPaths,...e.filter(ZH).map(XH)]);c([...[...a].map(YH),...[...o].map(JH),...[...s].map(qH)],{force:!0}),await Promise.all([...a].map(e=>u(e)));for(let t of e){let e=t.kind===`folder`?nk(t.path):t.kind===`asset`?t.path:ZO(t.path,t.docExt);X.getItem(e)&&X.remove(e,t.kind===`folder`?{recursive:!0}:void 0)}k(e=>{let t=wk(e,[...a],void 0,[...s]);for(let e of o)t=wk(t,[],e);return ft(t),t}),Ti([`files`,`backlinks`,`graph`])},t[169]=Ct,t[170]=u,t[171]=c,t[172]=X,t[173]=En):En=t[173];let Dn=En,On;t[174]!==r||t[175]!==Dn?(On=async function(e){let t=[],n=[],i=[];for(let a of e){let e=a.kind;R(a.path);let o=await Tt(await fetch(`/api/delete-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:e,path:a.path})}),r({id:`7JtSLi`}));if(!o.ok)return i.length>0&&await Dn(i,t,n),gs.error(o.title),!1;let s=F(Gn,o.body,`delete-path`,{deletedDocNames:[]});t.push(...s.deletedDocNames),e===`folder`&&n.push(a.path),i.push(a)}return await Dn(i,t,n),!0},t[174]=r,t[175]=Dn,t[176]=On):On=t[176];let kn=On,An;t[177]===Symbol.for(`react.memo_cache_sentinel`)?(An=async function(e,t,n){let r=[],i=[];for(let a of e){R(a.path);let e=kk(a,n),o=await t.shell.trashItem(e);o.ok?r.push(a):i.push({kind:a.kind,path:a.path,name:a.name,reason:SV(o.reason),detail:o.detail})}return{trashed:r,failed:i}},t[177]=An):An=t[177];let jn=An,Mn;t[178]===r?Mn=t[179]:(Mn=async function(e){let t=[],n=[],i=[];for(let a of e){let e=a.kind;try{let o=await Tt(await fetch(`/api/trash/cleanup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:e,path:a.path})}),r({id:`DVh_Tb`}));if(!o.ok){console.warn(`[FileTree] trash-cleanup failed`,{target:`${a.kind}:${a.path}`,reason:o.title}),i.push({target:a,reason:o.title});continue}let s=F(oi,o.body,`trash-cleanup`,{deletedDocNames:[]});t.push(...s.deletedDocNames),e===`folder`&&n.push(a.path)}catch(e){let t=e;console.warn(`[FileTree] trash-cleanup threw`,{target:`${a.kind}:${a.path}`,err:t}),i.push({target:a,reason:r({id:`r4R7AZ`})})}}if(i.length>0){let e=i.length;gs.error(r({id:`IrB5AK`,values:{failedCount:e}}),{description:r({id:`vEJDlt`})})}return i.length===e.length&&e.length>0?null:{deletedDocNames:t,deletedFolderPaths:n}},t[178]=r,t[179]=Mn);let Nn=Mn,Pn;t[180]!==r||t[181]!==U||t[182]!==Dn||t[183]!==kn||t[184]!==Nn||t[185]!==ct||t[186]!==K?(Pn=async function(e){let t=e.map(e=>Tk(e,J.current)),n=t[0];if(!n)return;let i=U.filter(e=>t.some(t=>{if(t.kind===`file`){let n=`${t.path}${t.docExt??`.md`}`;return e.file===n}return t.kind===`folder`?e.file.startsWith(`${t.path}/`):!1}));if(i.length>0){let e=i.slice(0,3).map(KH),t=i.length>e.length?`, +${i.length-e.length} more`:``;gs.error(`Cannot delete files with unresolved conflicts`,{description:`Resolve the conflict on ${e.join(`, `)}${t} before deleting.`});return}R(n.path),B(null);let a=typeof window<`u`?window.okDesktop:void 0;try{if(a&&K){let{trashed:e,failed:n}=await jn(t,a,K);if(e.length>0){let t=await Nn(e);t?await Dn(e,t.deletedDocNames,t.deletedFolderPaths):await Dn(e,e.filter(GH).map(WH),e.filter(UH).map(HH))}n.length>0&&H({failed:n,originalTargets:[...t]}),R(null)}else{let e=await kn(t);R(null),e||ct()}}catch(e){let t=e,n=t instanceof Error?t.message:String(t);console.warn(`[FileTree] delete failed:`,t),gs.error(r({id:`0eHrMb`}),{description:n}),R(null),ct()}},t[180]=r,t[181]=U,t[182]=Dn,t[183]=kn,t[184]=Nn,t[185]=ct,t[186]=K,t[187]=Pn):Pn=t[187];let In=Pn,Ln;t[188]!==r||t[189]!==kn||t[190]!==ct||t[191]!==V?(Ln=async function(){if(!V)return;let e=new Set(V.failed.map(VH)),t=V.originalTargets.filter(t=>e.has(`${t.kind}:${t.path}`));if(H(null),t.length!==0){R(t[0]?.path??null);try{let e=await kn(t);R(null),e||ct()}catch(e){let t=e,n=t instanceof Error?t.message:String(t);console.warn(`[FileTree] hard-delete fallback failed:`,t),gs.error(r({id:`0eHrMb`}),{description:n}),R(null),ct()}}},t[188]=r,t[189]=kn,t[190]=ct,t[191]=V,t[192]=Ln):Ln=t[192];let Rn=Ln,Bn;t[193]!==In||t[194]!==V?(Bn=async function(){if(!V)return;let e=new Set(V.failed.map(BH)),t=V.originalTargets.filter(t=>e.has(`${t.kind}:${t.path}`));H(null),await In(t)},t[193]=In,t[194]=V,t[195]=Bn):Bn=t[195];let Hn=Bn,Un=(0,Q.useRef)(In),Wn;t[196]===In?Wn=t[197]:(Wn=()=>{Un.current=In},t[196]=In,t[197]=Wn),(0,Q.useEffect)(Wn);let Kn,qn;t[198]===Symbol.for(`react.memo_cache_sentinel`)?(Kn=()=>LV(e=>{if(e.kind===`doc`||e.kind===`folder-index`){let t=e.docName,n=J.current.find(e=>zn(e)&&e.docName===t);Un.current([{kind:`file`,path:t,name:t.split(`/`).pop()??t,docExt:n?.docExt}]);return}if(e.kind===`folder`){Un.current([{kind:`folder`,path:e.folderPath,name:e.folderPath.split(`/`).pop()??e.folderPath}]);return}if(e.kind===`asset`){Un.current([{kind:`asset`,path:e.assetPath,name:e.assetPath.split(`/`).pop()??e.assetPath}]);return}console.warn(JSON.stringify({event:`file-tree-menu-action-delete-unsupported-kind`,kind:e.kind}))}),qn=[],t[198]=Kn,t[199]=qn):(Kn=t[198],qn=t[199]),(0,Q.useEffect)(Kn,qn);let Jn,Yn;t[200]===Symbol.for(`react.memo_cache_sentinel`)?(Jn=()=>VV(e=>{if(e.kind===`doc`||e.kind===`folder-index`){let t=e.docName,n=J.current.find(e=>zn(e)&&e.docName===t);yt.current({kind:`file`,path:t,name:t.split(`/`).pop()??t,docExt:n?.docExt});return}if(e.kind===`folder`){yt.current({kind:`folder`,path:e.folderPath,name:e.folderPath.split(`/`).pop()??e.folderPath});return}console.warn(JSON.stringify({event:`file-tree-menu-action-duplicate-unsupported-kind`,kind:e.kind}))}),Yn=[],t[200]=Jn,t[201]=Yn):(Jn=t[200],Yn=t[201]),(0,Q.useEffect)(Jn,Yn);let Xn,Zn;t[202]===X?(Xn=t[203],Zn=t[204]):(Xn=()=>zV(e=>{if(e.kind===`doc`||e.kind===`folder-index`){let t=e.docName,n=ZO(t,J.current.find(e=>zn(e)&&e.docName===t)?.docExt);X.startRenaming(n);return}if(e.kind===`folder`){X.startRenaming(e.folderPath);return}if(e.kind===`asset`){X.startRenaming(e.assetPath);return}console.warn(JSON.stringify({event:`file-tree-menu-action-rename-unsupported-kind`,kind:e.kind}))}),Zn=[X],t[202]=X,t[203]=Xn,t[204]=Zn),(0,Q.useEffect)(Xn,Zn);let Qn;t[205]===Symbol.for(`react.memo_cache_sentinel`)?(Qn=function(){let e=fe.current;e&&lH(e),fe.current=null},t[205]=Qn):Qn=t[205];let $n=Qn,er;t[206]===h?er=t[207]:(er=function(e){let t=lU(e.nativeEvent);if(!t||t.endsWith(`/`)){$n();return}let n=QO(t),r=J.current.find(e=>$O(e)===t);if(r&&kr(r)){$n();return}if(r&&zn(r)&&Ii(r.size)){$n();return}fe.current!==n&&($n(),fe.current=n,cH(n,e=>h(e)))},t[206]=h,t[207]=er);let tr=er,nr;t[208]!==ee||t[209]!==X||t[210]!==E?(nr=function(e){if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=uU(e.nativeEvent);if(!t||t.getAttribute(`aria-selected`)!==`true`)return;let n=t.dataset.itemPath;if(!n)return;let r=t.dataset.itemType===`folder`?nk(n):n;if(X.getSelectedPaths().length!==1)return;if(t.dataset.itemType===`folder`){let e=tk(r);if(window.location.hash===_r(e))return;queueMicrotask(()=>E(e));return}let i=QO(r);window.location.hash!==gr(i)&&queueMicrotask(()=>ee(r))},t[208]=ee,t[209]=X,t[210]=E,t[211]=nr):nr=t[211];let rr=nr;if(A){let e;return t[212]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(fU,{}),t[212]=e):e=t[212],e}if(O.length===0){if(M){let e;return t[213]===M?e=t[214]:(e=(0,Z.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-8`,children:(0,Z.jsx)(`span`,{className:`select-none text-sidebar-foreground/50 text-sm`,children:M})}),t[213]=M,t[214]=e),e}let e;t[215]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(`span`,{className:`select-none text-sidebar-foreground/30 text-sm`,children:(0,Z.jsx)(s,{id:`xiv-dW`})}),t[215]=e):e=t[215];let n;t[216]===an?n=t[217]:(n=()=>an(`file`,``),t[216]=an,t[217]=n);let r;t[218]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,Z.jsx)(s,{id:`6ibbCg`}),t[218]=r):r=t[218];let i;return t[219]===n?i=t[220]:(i=(0,Z.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 py-8`,children:[e,(0,Z.jsx)(Qi,{variant:`link`,size:`sm`,className:`font-mono uppercase`,onClick:n,children:r})]}),t[219]=n,t[220]=i),i}let ir=L!==null,ar=z?.targets[0]??null,or;t[221]!==M||t[222]!==P?(or=(M||P!==null)&&(0,Z.jsxs)(Z.Fragment,{children:[M&&(0,Z.jsx)(`span`,{role:`alert`,className:`px-3 pb-1 text-destructive text-xs`,children:M}),P!==null&&(0,Z.jsx)(`span`,{role:`status`,className:`px-3 pb-1 text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`_HekAK`,values:{truncatedShownCount:P}})})]}),t[221]=M,t[222]=P,t[223]=or):or=t[223];let sr;t[224]===v?sr=t[225]:(sr=TH(v),t[224]=v,t[225]=sr);let cr;t[226]!==ir||t[227]!==ae||t[228]!==ln||t[229]!==O||t[230]!==sn||t[231]!==tt||t[232]!==vt||t[233]!==Ne||t[234]!==Ie||t[235]!==X||t[236]!==Pe||t[237]!==Fe||t[238]!==an||t[239]!==K?(cr=(e,t)=>(0,Z.jsx)(LH,{item:e,context:t,anyActionBusy:ir,workspace:K,handoff:Ne,model:X,okignoreBinding:Pe,projectLocalBinding:Fe,mergedConfig:Ie,onStartCreating:an,onCreateFromTemplate:(e,t)=>an(`file`,e,{template:t}),onDuplicate:vt,onDelete:e=>B({targets:e}),onExpandSubtree:sn,onCollapseSubtree:ln,folderTreePaths:tt,isAsset:ae.has(e.path),documents:O}),t[226]=ir,t[227]=ae,t[228]=ln,t[229]=O,t[230]=sn,t[231]=tt,t[232]=vt,t[233]=Ne,t[234]=Ie,t[235]=X,t[236]=Pe,t[237]=Fe,t[238]=an,t[239]=K,t[240]=cr):cr=t[240];let lr;t[241]!==rr||t[242]!==tr||t[243]!==X||t[244]!==or||t[245]!==sr||t[246]!==cr?(lr=(0,Z.jsx)(`div`,{ref:be,className:`flex min-h-0 flex-1 flex-col`,children:(0,Z.jsx)(RB,{header:or,model:X,style:sr,onClickCapture:rr,onMouseMove:tr,onMouseLeave:$n,renderContextMenu:cr})}),t[241]=rr,t[242]=tr,t[243]=X,t[244]=or,t[245]=sr,t[246]=cr,t[247]=lr):lr=t[247];let ur=!!z,dr;t[248]===L?dr=t[249]:(dr=e=>{!e&&!L&&B(null)},t[248]=L,t[249]=dr);let fr;t[250]!==r||t[251]!==L||t[252]!==z||t[253]!==In||t[254]!==ar?(fr=z&&ar&&(0,Z.jsx)(_a,{...(()=>{let e=yV(typeof window<`u`&&window.okDesktop!=null?`electron`:`web`,z.targets);if(e)return{customTitle:e.title,customDescription:``,customDetail:e.detail,customConfirmLabel:e.confirmLabel,customConfirmLabelBusy:e.confirmLabelBusy,children:e.listedTargets?(0,Z.jsx)(`ul`,{className:`flex flex-col gap-1 font-mono text-foreground text-xs`,children:e.listedTargets.map(zH)}):null};let t=z.targets.length,n=ar.name;return{itemName:t===1?ar.kind===`folder`?`${ar.name}/`:ar.kind===`file`?`${ar.name}${ar.docExt??`.md`}`:ar.name:void 0,customTitle:t>1?r({id:`abiHje`}):void 0,customDescription:t>1?r({id:`WMIKXK`,values:{targetCount:t}}):ar.kind===`folder`?r({id:`a5W0q0`,values:{folderName:n}}):void 0}})(),isSubmitting:L!==null,onDelete:()=>In(z.targets)}),t[250]=r,t[251]=L,t[252]=z,t[253]=In,t[254]=ar,t[255]=fr):fr=t[255];let pr;t[256]!==ur||t[257]!==dr||t[258]!==fr?(pr=(0,Z.jsx)(ps,{open:ur,onOpenChange:dr,children:fr}),t[256]=ur,t[257]=dr,t[258]=fr,t[259]=pr):pr=t[259];let mr=!!V,hr;t[260]===L?hr=t[261]:(hr=e=>{!e&&!L&&H(null)},t[260]=L,t[261]=hr);let vr;t[262]!==L||t[263]!==Rn||t[264]!==Hn||t[265]!==V?(vr=V&&(0,Z.jsx)(EV,{failedTargets:V.failed,isSubmitting:L!==null,onDeletePermanently:Rn,onRetry:Hn,onCancel:()=>H(null)}),t[262]=L,t[263]=Rn,t[264]=Hn,t[265]=V,t[266]=vr):vr=t[266];let yr;t[267]!==mr||t[268]!==hr||t[269]!==vr?(yr=(0,Z.jsx)(ps,{open:mr,onOpenChange:hr,children:vr}),t[267]=mr,t[268]=hr,t[269]=vr,t[270]=yr):yr=t[270];let br=W!==null,xr;t[271]===Symbol.for(`react.memo_cache_sentinel`)?(xr=e=>{e||G(null)},t[271]=xr):xr=t[271];let Sr=W?.parentDir??``,Cr;t[272]!==Sr||t[273]!==br?(Cr=(0,Z.jsx)(km,{open:br,onOpenChange:xr,kind:`file`,initialDir:Sr,defaultToTemplate:!0}),t[272]=Sr,t[273]=br,t[274]=Cr):Cr=t[274];let wr;return t[275]!==Cr||t[276]!==lr||t[277]!==pr||t[278]!==yr?(wr=(0,Z.jsxs)(Z.Fragment,{children:[lr,pr,yr,Cr]}),t[275]=Cr,t[276]=lr,t[277]=pr,t[278]=yr,t[279]=wr):wr=t[279],wr}function zH(e){return(0,Z.jsx)(`li`,{"data-testid":`delete-target-row`,children:bV(e)},`${e.kind}:${e.path}`)}function BH(e){return`${e.kind}:${e.path}`}function VH(e){return`${e.kind}:${e.path}`}function HH(e){return e.path}function UH(e){return e.kind===`folder`}function WH(e){return e.path}function GH(e){return e.kind===`file`}function KH(e){return e.file}function qH(e){return Je(e)}function JH(e){return Zt(e)}function YH(e){return De(e)}function XH(e){return e.path}function ZH(e){return e.kind===`asset`}function QH(e){return e.endsWith(`/`)?e.slice(0,-1):e}function $H(e){return!!e}function eU(e){console.warn(`[FileTree] /api/workspace fetch failed:`,e)}function tU(e){console.warn(`[FileTree] unmount cleanup failed:`,e)}function nU(e){gs.error(e)}function rU(){}function iU(e){return gs.error(e)}function aU(){}function oU(){}async function sU(){}function cU(e){return $O(e)}function lU(e){return uU(e)?.dataset.itemPath??null}function uU(e){for(let t of e.composedPath())if(t instanceof HTMLElement&&t.dataset.itemPath)return t;return null}var dU=[`w-3/4`,`w-2/3`,`w-4/5`,`w-1/2`,`w-3/5`,`w-2/3`];function fU(){let e=(0,$.c)(5),{_:t}=i(),n;e[0]===t?n=e[1]:(n=t({id:`5Tk8Fb`}),e[0]=t,e[1]=n);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=dU.map(pU),e[2]=r):r=e[2];let a;return e[3]===n?a=e[4]:(a=(0,Z.jsx)(`div`,{className:`flex flex-1 flex-col gap-1 px-2 py-2`,role:`status`,"aria-busy":`true`,"aria-label":n,children:r}),e[3]=n,e[4]=a),a}function pU(e,t){return(0,Z.jsxs)(`div`,{className:`flex h-6 items-center gap-2`,children:[(0,Z.jsx)(Sa,{className:`h-3 w-3 shrink-0 rounded-sm`}),(0,Z.jsx)(Sa,{className:`h-3 ${e}`})]},t)}function mU(e){return e?lr._({id:`wTcjov`}):null}function hU(e){let t=(0,$.c)(37),{_:n}=i(),r=ih(),{merged:a}=gt(),o=a?.appearance?.preview?.autoOpen??!0;if(r)return null;let{input:c,installStates:l,dispatch:u,webFallbackVisible:d}=e,f=d===void 0?!0:d,p=c===null,m,h,g,_,v,y,b;if(t[0]!==n||t[1]!==o||t[2]!==u||t[3]!==c||t[4]!==p||t[5]!==l||t[6]!==f){b=Symbol.for(`react.early_return_sentinel`);bb0:{let e=mU(p),r;t[14]===l?r=t[15]:(r=e=>l[e.id]?.installed===!0,t[14]=l,t[15]=r);let i=sh.filter(r);g=l[`claude-code`]?.installed===!0;let a;t[16]!==o||t[17]!==c?(a=c!==null&&c.docContext!==null?Ui(c.docContext.relativePath,o):``,t[16]=o,t[17]=c,t[18]=a):a=t[18];let d=a,x;t[19]!==c||t[20]!==d?(x=()=>{c!==null&&Db(d)},t[19]=c,t[20]=d,t[21]=x):x=t[21],_=x;let S=f&&!g;if(i.length===0&&!S){b=null;break bb0}h=Lk,t[22]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Z.jsxs)(Bk,{children:[(0,Z.jsx)(ua,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`O7_W_a`})]}),t[22]=y):y=t[22],m=Vk,v=i.map(t=>{let r=!p,{displayName:i}=t,a=n(e?{id:`1ZpfyB`,values:{displayName:i,hint:e}}:{id:`WqLq6M`,values:{displayName:i}});return(0,Z.jsxs)(zk,{disabled:!r,onSelect:()=>{c&&u(t.id,c)},"data-testid":`empty-space-open-in-${t.id}`,"aria-label":a,children:[(0,Z.jsx)(xb,{id:t.id,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:t.displayName}),e?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:e}):null]},t.id)})}t[0]=n,t[1]=o,t[2]=u,t[3]=c,t[4]=p,t[5]=l,t[6]=f,t[7]=m,t[8]=h,t[9]=g,t[10]=_,t[11]=v,t[12]=y,t[13]=b}else m=t[7],h=t[8],g=t[9],_=t[10],v=t[11],y=t[12],b=t[13];if(b!==Symbol.for(`react.early_return_sentinel`))return b;let x;t[23]!==n||t[24]!==g||t[25]!==_||t[26]!==p||t[27]!==f?(x=f&&!g?(0,Z.jsxs)(zk,{onSelect:_,disabled:p,"data-testid":`empty-space-open-in-claude-web-fallback`,"aria-label":n({id:`aA51jP`}),children:[(0,Z.jsx)(Bt,{className:`size-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:(0,Z.jsx)(s,{id:`0S9PW_`})}),(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`pcfY8r`})})]}):null,t[23]=n,t[24]=g,t[25]=_,t[26]=p,t[27]=f,t[28]=x):x=t[28];let S;t[29]!==m||t[30]!==v||t[31]!==x?(S=(0,Z.jsxs)(m,{children:[v,x]}),t[29]=m,t[30]=v,t[31]=x,t[32]=S):S=t[32];let C;return t[33]!==h||t[34]!==y||t[35]!==S?(C=(0,Z.jsxs)(h,{children:[y,S]}),t[33]=h,t[34]=y,t[35]=S,t[36]=C):C=t[36],C}var gU=(e,t,n)=>Kl(e,t,n,`ProjectSwitcher`);function _U(e){let t=(0,$.c)(90),{bridge:n}=e,{_:r}=i(),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=[],t[0]=a):a=t[0];let[o,c]=(0,Q.useState)(a),[l,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(!1),g=nO(),_;t[1]!==r||t[2]!==n.project||t[3]!==l?(_=()=>{if(!l)return;let e=!1;return gU(async()=>{let t=await n.project.listRecent();e||c(t)},r({id:`fYKgzG`})),()=>{e=!0}},t[1]=r,t[2]=n.project,t[3]=l,t[4]=_):_=t[4];let v;t[5]!==r||t[6]!==n||t[7]!==l?(v=[l,n,r],t[5]=r,t[6]=n,t[7]=l,t[8]=v):v=t[8],(0,Q.useEffect)(_,v);let y;t[9]!==r||t[10]!==n.project?(y=e=>{d(!1),gU(()=>n.project.open({path:e,target:`new-window`,entryPoint:`recents`}),r({id:`SUOoXn`}))},t[9]=r,t[10]=n.project,t[11]=y):y=t[11];let b=y,x;t[12]!==r||t[13]!==n.dialog||t[14]!==n.project?(x=()=>{d(!1),gU(async()=>{let e=await n.dialog.openFolder();e&&await n.project.open({path:e,target:`new-window`,entryPoint:`pick-existing`})},r({id:`gmJ0An`}))},t[12]=r,t[13]=n.dialog,t[14]=n.project,t[15]=x):x=t[15];let S=x,C;t[16]!==r||t[17]!==n.navigator?(C=()=>{d(!1),gU(()=>n.navigator.open(),r({id:`jol95m`}))},t[16]=r,t[17]=n.navigator,t[18]=C):C=t[18];let w=C,T;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(T=()=>{d(!1),h(!0)},t[19]=T):T=t[19];let E=T,D=n.config.projectPath,k,A,j,M,N,P,F,I,L,R;if(t[20]!==r||t[21]!==g||t[22]!==n.config.projectName||t[23]!==n.config.projectPath||t[24]!==D||t[25]!==l||t[26]!==b||t[27]!==o||t[28]!==f){let e;t[39]===D?e=t[40]:(e=e=>e.path!==D,t[39]=D,t[40]=e);let i=o.filter(e),a=f.trim().toLowerCase(),c=a?i.filter(e=>e.name.toLowerCase().includes(a)||e.path.toLowerCase().includes(a)):i;A=Ya,P=l,t[41]===Symbol.for(`react.memo_cache_sentinel`)?(F=e=>{d(e),e||p(``)},t[41]=F):F=t[41];let u=g!==null&&`h-auto py-1.5`,m;t[42]===u?m=t[43]:(m=Gi(`justify-between text-sidebar-foreground/70 hover:text-sidebar-foreground! data-open:hover:text-sidebar-foreground!`,u),t[42]=u,t[43]=m);let h;t[44]===r?h=t[45]:(h=r({id:`zZ_I5K`}),t[44]=r,t[45]=h);let _;t[46]===n.config.projectName?_=t[47]:(_=(0,Z.jsx)(`span`,{className:`truncate`,children:n.config.projectName}),t[46]=n.config.projectName,t[47]=_);let v;t[48]===g?v=t[49]:(v=g===null?null:(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1 text-xs text-sidebar-foreground/50 group-hover/menu-button:text-sidebar-foreground`,"data-testid":`project-switcher-branch`,children:[(0,Z.jsx)(Ae,{"aria-hidden":`true`,className:`size-3! shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:g})]}),t[48]=g,t[49]=v);let y;t[50]!==_||t[51]!==v?(y=(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[_,v]}),t[50]=_,t[51]=v,t[52]=y):y=t[52];let x;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,Z.jsx)(zc,{"aria-hidden":`true`,className:`opacity-60`}),t[53]=x):x=t[53],t[54]!==n.config.projectPath||t[55]!==m||t[56]!==h||t[57]!==y?(I=(0,Z.jsx)(Ho,{asChild:!0,children:(0,Z.jsxs)(XD,{className:m,"data-testid":`project-switcher-trigger`,"aria-label":h,title:n.config.projectPath,children:[y,x]})}),t[54]=n.config.projectPath,t[55]=m,t[56]=h,t[57]=y,t[58]=I):I=t[58],k=xo,L=`start`,R=`top`,j=`min-w-[260px]`,M=`project-switcher-menu`,N=i.length===0?(0,Z.jsx)(No,{className:`font-normal text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`HNnVG1`})}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(yS,{className:`mb-1 h-8 border-0 shadow-none has-[[data-slot=input-group-control]:focus-visible]:ring-0`,children:[(0,Z.jsx)(wS,{"aria-label":r({id:`H8Ng4Z`}),placeholder:r({id:`8S1E33`}),value:f,onChange:e=>p(e.target.value),onKeyDown:vU,"data-testid":`project-switcher-search`}),(0,Z.jsx)(xS,{children:(0,Z.jsx)(O,{"aria-hidden":`true`})})]}),(0,Z.jsx)(Vo,{}),c.length===0?(0,Z.jsx)(No,{className:`font-normal text-muted-foreground text-xs`,role:`status`,"aria-live":`polite`,children:(0,Z.jsx)(s,{id:`pEQFsW`})}):(0,Z.jsx)(`div`,{className:`max-h-64 overflow-y-auto overscroll-contain subtle-scrollbar scroll-fade-mask`,children:c.slice(0,10).map(e=>(0,Z.jsxs)(Wo,{disabled:e.missing,onSelect:()=>b(e.path),className:`flex flex-col items-start gap-0.5`,"data-testid":`project-switcher-recent-${e.path}`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,Z.jsxs)(`span`,{className:`max-w-[240px] truncate text-muted-foreground text-xs`,children:[e.path,e.missing?r({id:`2Znqb1`}):``]})]},e.path))})]}),t[20]=r,t[21]=g,t[22]=n.config.projectName,t[23]=n.config.projectPath,t[24]=D,t[25]=l,t[26]=b,t[27]=o,t[28]=f,t[29]=k,t[30]=A,t[31]=j,t[32]=M,t[33]=N,t[34]=P,t[35]=F,t[36]=I,t[37]=L,t[38]=R}else k=t[29],A=t[30],j=t[31],M=t[32],N=t[33],P=t[34],F=t[35],I=t[36],L=t[37],R=t[38];let z;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,Z.jsx)(Vo,{}),t[59]=z):z=t[59];let B,V;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,Z.jsx)(yt,{"aria-hidden":`true`,className:`text-muted-foreground`}),V=(0,Z.jsx)(s,{id:`PVUn_c`}),t[60]=B,t[61]=V):(B=t[60],V=t[61]);let H;t[62]===S?H=t[63]:(H=(0,Z.jsxs)(Wo,{onSelect:S,"data-testid":`project-switcher-open-folder`,children:[B,V]}),t[62]=S,t[63]=H);let U,W;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(U=(0,Z.jsx)(u,{"aria-hidden":`true`,className:`text-muted-foreground`}),W=(0,Z.jsx)(s,{id:`2Xs2jo`}),t[64]=U,t[65]=W):(U=t[64],W=t[65]);let G;t[66]===w?G=t[67]:(G=(0,Z.jsxs)(Wo,{onSelect:w,"data-testid":`project-switcher-switch-project`,children:[U,W]}),t[66]=w,t[67]=G);let K;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(K=(0,Z.jsxs)(Wo,{onSelect:E,"data-testid":`project-switcher-new-project`,children:[(0,Z.jsx)(ge,{"aria-hidden":`true`,className:`text-muted-foreground`}),(0,Z.jsx)(s,{id:`gKi-a_`})]}),t[68]=K):K=t[68];let q;t[69]!==k||t[70]!==j||t[71]!==M||t[72]!==N||t[73]!==H||t[74]!==G||t[75]!==L||t[76]!==R?(q=(0,Z.jsxs)(k,{align:L,side:R,className:j,"data-testid":M,children:[N,z,H,G,K]}),t[69]=k,t[70]=j,t[71]=M,t[72]=N,t[73]=H,t[74]=G,t[75]=L,t[76]=R,t[77]=q):q=t[77];let J;t[78]!==A||t[79]!==P||t[80]!==F||t[81]!==I||t[82]!==q?(J=(0,Z.jsxs)(A,{open:P,onOpenChange:F,children:[I,q]}),t[78]=A,t[79]=P,t[80]=F,t[81]=I,t[82]=q,t[83]=J):J=t[83];let Y;t[84]!==n||t[85]!==m?(Y=(0,Z.jsx)(bd,{open:m,onOpenChange:h,bridge:n}),t[84]=n,t[85]=m,t[86]=Y):Y=t[86];let ee;return t[87]!==J||t[88]!==Y?(ee=(0,Z.jsxs)(Z.Fragment,{children:[J,Y]}),t[87]=J,t[88]=Y,t[89]=ee):ee=t[89],ee}function vU(e){return e.stopPropagation()}function yU(e,t){let n=e instanceof Error?e:Error(String(e));console.warn(JSON.stringify({event:`jsx-render-failure`,component:`sidebarSearchPill`,rawComponentName:`sidebarSearchPill`,error:String(n),stack:t.componentStack})),si(`sidebarSearchPill`)}function bU(e){let t=(0,$.c)(8),{onClick:n,className:r}=e,i;t[0]===r?i=t[1]:(i=Gi(`rounded-lg h-9 w-full justify-start gap-2 px-3 font-normal text-muted-foreground`,r),t[0]=r,t[1]=i);let a;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(O,{"aria-hidden":`true`}),t[2]=a):a=t[2];let o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(`span`,{className:`flex-1 text-left text-sm`,children:(0,Z.jsx)(s,{id:`A1taO8`})}),t[3]=o):o=t[3];let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Z.jsx)(D,{className:`text-foreground/70`,children:Ms(`command-palette`)}),t[4]=c):c=t[4];let l;return t[5]!==n||t[6]!==i?(l=(0,Z.jsxs)(Qi,{variant:`outline`,onClick:n,"data-telemetry-event":`ok.sidebar.search_pill.click`,className:i,children:[a,o,c]}),t[5]=n,t[6]=i,t[7]=l):l=t[7],l}function xU(e){let t=(0,$.c)(36),{notice:n,onDismiss:r}=e,{_:a}=i(),o=n.variant===`error`?`border-destructive/60`:`border-sidebar-border`,s;t[0]===a?s=t[1]:(s=a({id:`GUYwCr`}),t[0]=a,t[1]=s);let c;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Z.jsx)(ss,{"aria-hidden":`true`,className:`size-3`}),t[2]=c):c=t[2];let l;t[3]!==r||t[4]!==s?(l=(0,Z.jsx)(Qi,{variant:`ghost`,size:`icon`,className:`size-5 shrink-0 text-muted-foreground hover:text-sidebar-foreground`,"aria-label":s,onClick:r,children:c}),t[3]=r,t[4]=s,t[5]=l):l=t[5];let u=l;if(n.secondaryAction){let e=`update-notice-${n.id}`,r=`flex flex-col gap-2 rounded-md border bg-sidebar-accent/30 px-2 py-2 text-xs text-muted-foreground ${o}`,i;t[6]===n.body?i=t[7]:(i=(0,Z.jsx)(`span`,{className:`flex-1 leading-snug`,children:n.body}),t[6]=n.body,t[7]=i);let a;t[8]!==u||t[9]!==i?(a=(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[i,u]}),t[8]=u,t[9]=i,t[10]=a):a=t[10];let s;t[11]===n.action?s=t[12]:(s=n.action?(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-xs font-medium underline underline-offset-2 decoration-muted-foreground/40 hover:text-sidebar-foreground hover:decoration-sidebar-foreground`,onClick:()=>{n.action?.onClick()},children:n.action.label}):null,t[11]=n.action,t[12]=s);let c;t[13]===n.secondaryAction?c=t[14]:(c=()=>{n.secondaryAction?.onClick()},t[13]=n.secondaryAction,t[14]=c);let l;t[15]!==n.secondaryAction.label||t[16]!==c?(l=(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-xs font-medium underline underline-offset-2 decoration-muted-foreground/40 hover:text-sidebar-foreground hover:decoration-sidebar-foreground`,onClick:c,children:n.secondaryAction.label}),t[15]=n.secondaryAction.label,t[16]=c,t[17]=l):l=t[17];let d;t[18]!==l||t[19]!==s?(d=(0,Z.jsxs)(`div`,{className:`flex gap-3 pl-1`,children:[s,l]}),t[18]=l,t[19]=s,t[20]=d):d=t[20];let f;return t[21]!==d||t[22]!==e||t[23]!==r||t[24]!==a?(f=(0,Z.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":e,className:r,children:[a,d]}),t[21]=d,t[22]=e,t[23]=r,t[24]=a,t[25]=f):f=t[25],f}let d=`update-notice-${n.id}`,f=`flex items-center gap-2 rounded-md border bg-sidebar-accent/30 px-2 py-1.5 text-xs text-muted-foreground ${o}`,p;t[26]===n.body?p=t[27]:(p=(0,Z.jsx)(`span`,{className:`flex-1 leading-snug`,children:n.body}),t[26]=n.body,t[27]=p);let m;t[28]===n.action?m=t[29]:(m=n.action?(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-xs font-medium underline underline-offset-2 decoration-muted-foreground/40 hover:text-sidebar-foreground hover:decoration-sidebar-foreground`,onClick:()=>{n.action?.onClick()},children:n.action.label}):null,t[28]=n.action,t[29]=m);let h;return t[30]!==u||t[31]!==d||t[32]!==f||t[33]!==p||t[34]!==m?(h=(0,Z.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":d,className:f,children:[p,m,u]}),t[30]=u,t[31]=d,t[32]=f,t[33]=p,t[34]=m,t[35]=h):h=t[35],h}function SU(e){if(e.length===0)return null;let t=e[0];if(!t)return null;for(let n=1;n<e.length;n++){let r=e[n];r&&r.priority<t.priority&&(t=r)}return t}function CU(){let e=(0,$.c)(7),t=(0,Q.useSyncExternalStore)(Pp,Np,Np),n;e[0]===t?n=e[1]:(n=SU(t),e[0]=t,e[1]=n);let r=n;if(!r)return null;let i;e[2]===r?i=e[3]:(i=()=>{r.onDismiss?.(),Mp(r.id)},e[2]=r,e[3]=i);let a;return e[4]!==r||e[5]!==i?(a=(0,Z.jsx)(`div`,{"data-testid":`update-notices-list`,children:(0,Z.jsx)(xU,{notice:r,onDismiss:i})}),e[4]=r,e[5]=i,e[6]=a):a=e[6],a}function wU(e,t,n){return e?.kind===`doc`&&t||e?.kind===`folder-index`&&t?Lh(n.contentDir,Rh(t),n.pathSeparator):e?.kind===`folder`?Lh(n.contentDir,e.folderPath,n.pathSeparator):e?.kind===`asset`?Lh(n.contentDir,e.assetPath,n.pathSeparator):n.contentDir}function TU(e,t,n){if((e?.kind===`doc`||e?.kind===`folder-index`)&&t){let e=t.lastIndexOf(`/`);return e<0?n.contentDir:Lh(n.contentDir,t.slice(0,e),n.pathSeparator)}if(e?.kind===`folder`)return Lh(n.contentDir,e.folderPath,n.pathSeparator);if(e?.kind===`asset`){let t=e.assetPath.lastIndexOf(`/`);return t<0?n.contentDir:Lh(n.contentDir,e.assetPath.slice(0,t),n.pathSeparator)}return n.contentDir}function EU(e,t){return(e?.kind===`doc`||e?.kind===`folder-index`)&&t?Rh(t):e?.kind===`folder`?e.folderPath:e?.kind===`asset`?e.assetPath:``}function DU(e,t,n){return e===null?Bh({workspace:n}):e.kind===`folder`?n?Vh({folderRelativePath:e.folderPath,workspace:n}):null:e.kind===`doc`||e.kind===`folder-index`?zh({docName:t,workspace:n}):null}var OU={folderCount:0,expandedCount:0},kU=`button, [role="button"], [role="menuitem"], input, textarea, select, a[href]`;function AU(e){return typeof Element>`u`||!(e instanceof Element)?!1:e.closest(kU)!==null}function jU(e){let t=(0,$.c)(2),{onOpenSearch:n}=e,r;return t[0]===n?r=t[1]:(r=(0,Z.jsx)(x,{name:`file-sidebar`,children:(0,Z.jsx)(NU,{onOpenSearch:n})}),t[0]=n,t[1]=r),r}var MU=e=>{let t=(0,$.c)(15),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({icon:n,label:r,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===n?a=t[5]:(a=(0,Z.jsx)(n,{"aria-hidden":`true`}),t[4]=n,t[5]=a);let o;t[6]!==r||t[7]!==i||t[8]!==a?(o=(0,Z.jsx)(Tr,{asChild:!0,children:(0,Z.jsx)(Qi,{variant:`ghost`,size:`icon-sm`,"aria-label":r,...i,children:a})}),t[6]=r,t[7]=i,t[8]=a,t[9]=o):o=t[9];let s;t[10]===r?s=t[11]:(s=(0,Z.jsx)(nr,{children:r}),t[10]=r,t[11]=s);let c;return t[12]!==o||t[13]!==s?(c=(0,Z.jsxs)(Yn,{children:[o,s]}),t[12]=o,t[13]=s,t[14]=c):c=t[14],c};function NU(e){let t=(0,$.c)(200),{onOpenSearch:n}=e,{_:r}=i(),[a,o]=(0,Q.useState)(null),{activeDocName:c,activeTarget:l}=pt(),u;t[0]!==c||t[1]!==l?(u=l?.kind===`folder`||l?.kind===`folder-index`?l.folderPath:qr(c),t[0]=c,t[1]=l,t[2]=u):u=t[2];let d=u,f=typeof window<`u`&&window.okDesktop!=null,{state:p,toggleSidebar:m}=ID(),h=ih(),g=p===`expanded`,_=f&&p===`collapsed`,[v,y]=(0,Q.useState)(OU),b,x;t[3]===a?(b=t[4],x=t[5]):(b=()=>{if(a!==null)return y(a.getFolderState()),a.subscribe(()=>{y(a.getFolderState())})},x=[a],t[3]=a,t[4]=b,t[5]=x),(0,Q.useEffect)(b,x);let S,C;t[6]===a?(S=t[7],C=t[8]):(S=()=>{if(a!==null)return dx(e=>{let t=e.initialDir??``;if(e.template){a.createFromTemplate(e.template.folder,e.template.name);return}a.startCreating(`file`,t)})},C=[a],t[6]=a,t[7]=S,t[8]=C),(0,Q.useEffect)(S,C);let w=v.folderCount>0,T=w&&v.expandedCount===v.folderCount,E=v.expandedCount===0,D=eo(``),O=eo(d===``?null:d),k=d===``?D:O,A=D.state.status===`ready`?(D.state.data.folder.templates_available?.length??0)>0:!0,j=k.state.status===`ready`?(k.state.data.folder.templates_available?.length??0)>0:!0,M=typeof window<`u`?window.okDesktop:void 0,N=Mo(),P=ug().states,{dispatch:F}=$h(),I;t[9]===N?I=t[10]:(I=Bh({workspace:N}),t[9]=N,t[10]=I);let L=I,{projectLocalBinding:R,merged:z}=gt(),B=z?.appearance?.sidebar?.showHiddenFiles??!1,V=z?.appearance?.sidebar?.showAllFiles??!1,H=w&&!T,U=w&&!E,G=H||U,K=FU,q;t[11]!==a||t[12]!==N?(q=()=>{N&&a?.startCreating(`file`,``)},t[11]=a,t[12]=N,t[13]=q):q=t[13];let J=q,Y;t[14]!==a||t[15]!==N?(Y=e=>{N&&a?.createFromTemplate(``,e)},t[14]=a,t[15]=N,t[16]=Y):Y=t[16];let ee=Y,te;t[17]!==a||t[18]!==N?(te=()=>{N&&a?.startCreating(`folder`,``)},t[17]=a,t[18]=N,t[19]=te):te=t[19];let ne=te,re;t[20]===N?re=t[21]:(re=()=>{!N||!M||M.shell.showItemInFolder(N.contentDir)},t[20]=N,t[21]=re);let ie=re,ae;t[22]===N?ae=t[23]:(ae=()=>{!N||!M||MV(M,N.contentDir)},t[22]=N,t[23]=ae);let oe=ae,se;t[24]!==r||t[25]!==N?(se=async()=>{if(N)try{await navigator.clipboard.writeText(N.contentDir),gs.success(r({id:`6_ZOw4`}),{description:N.contentDir})}catch(e){console.warn(`[FileSidebar] clipboard write failed:`,e),gs.error(r({id:`vfRlCI`}))}},t[24]=r,t[25]=N,t[26]=se):se=t[26];let ce=se,le;t[27]!==r||t[28]!==R?(le=e=>{if(R===null)return;let t=R.patch({appearance:{sidebar:{showHiddenFiles:e}}});t.ok||(console.warn(`[FileSidebar] showHiddenFiles toggle rejected:`,Er(t.error)),gs.error(r({id:`P47EWZ`}),{description:Er(t.error)}))},t[27]=r,t[28]=R,t[29]=le):le=t[29];let ue=le,de;t[30]!==r||t[31]!==R?(de=e=>{if(R===null)return;let t=R.patch({appearance:{sidebar:{showAllFiles:e}}});t.ok||(console.warn(`[FileSidebar] showAllFiles toggle rejected:`,Er(t.error)),gs.error(r({id:`P47EWZ`}),{description:Er(t.error)}))},t[30]=r,t[31]=R,t[32]=de):de=t[32];let fe=de,pe;t[33]===a?pe=t[34]:(pe=()=>{a?.expandAll()},t[33]=a,t[34]=pe);let me=pe,he;t[35]===a?he=t[36]:(he=()=>{a?.collapseAll()},t[35]=a,t[36]=he);let ge=he,_e,ve;t[37]!==V||t[38]!==U||t[39]!==H||t[40]!==B||t[41]!==p?(_e=()=>{M&&M.editor.notifyViewMenuStateChanged({showHiddenFiles:B,showAllFiles:V,canExpandAll:H,canCollapseAll:U,sidebarVisible:p===`expanded`})},ve=[M,B,V,H,U,p],t[37]=V,t[38]=U,t[39]=H,t[40]=B,t[41]=p,t[42]=_e,t[43]=ve):(_e=t[42],ve=t[43]),(0,Q.useEffect)(_e,ve);let ye,be;t[44]!==r||t[45]!==c||t[46]!==l||t[47]!==F||t[48]!==P||t[49]!==d||t[50]!==R||t[51]!==V||t[52]!==B||t[53]!==m||t[54]!==a||t[55]!==N?(ye=()=>{if(M)return M.onMenuAction(e=>{switch(e){case`new-doc`:if(!N||!a)return;a.startCreating(`file`,d);return;case`new-folder`:if(!N||!a)return;a.startCreating(`folder`,d);return;case`new-from-template`:if(!N||!a)return;a.startCreatingFromTemplate(d);return;case`rename`:if(!l)return;RV(l);return;case`duplicate`:if(!l)return;BV(l);return;case`move-to-trash`:if(!l)return;IV(l);return;case`reveal-in-finder`:{if(!M||!N)return;let e=wU(l,c,N);M.shell.showItemInFolder(e);return}case`open-in-terminal`:if(!M||!N)return;MV(M,TU(l,c,N));return;case`send-to-ai`:{let e=sh.filter(e=>P[e.id]?.installed===!0);if(e.length===0){gs.error(r({id:`LKOLNn`}));return}let t=DU(l,c,N);if(!t)return;let[n]=e;if(!n)return;F(n.id,t);return}case`copy-full-path`:{if(!N)return;let e=wU(l,c,N);navigator.clipboard.writeText(e).then(()=>gs.success(r({id:`6_ZOw4`}),{description:e})).catch(e=>{console.warn(`[FileSidebar] clipboard write failed:`,e),gs.error(r({id:`vfRlCI`}))});return}case`copy-relative-path`:{let e=EU(l,c);if(e===``){gs.error(r({id:`74eHt-`}));return}navigator.clipboard.writeText(e).then(()=>gs.success(r({id:`haHgQj`}),{description:e})).catch(e=>{console.warn(`[FileSidebar] clipboard write failed:`,e),gs.error(r({id:`5QGTaA`}))});return}case`toggle-show-hidden-files`:{if(R===null)return;let e=R.patch({appearance:{sidebar:{showHiddenFiles:!B}}});e.ok||(console.warn(`[FileSidebar] toggle-show-hidden-files rejected:`,Er(e.error)),gs.error(r({id:`P47EWZ`}),{description:Er(e.error)}));return}case`toggle-show-all-files`:{if(R===null)return;let e=R.patch({appearance:{sidebar:{showAllFiles:!V}}});e.ok||(console.warn(`[FileSidebar] toggle-show-all-files rejected:`,Er(e.error)),gs.error(r({id:`P47EWZ`}),{description:Er(e.error)}));return}case`expand-all-tree`:a?.expandAll();return;case`collapse-all-tree`:a?.collapseAll();return;case`toggle-sidebar`:m();return;case`delete`:case`toggle-source`:case`save-version`:case`version-history`:case`focus-search`:case`focus-command-palette`:case`toggle-doc-panel`:return}})},be=[M,a,N,l,c,d,R,B,V,P,F,m,r],t[44]=r,t[45]=c,t[46]=l,t[47]=F,t[48]=P,t[49]=d,t[50]=R,t[51]=V,t[52]=B,t[53]=m,t[54]=a,t[55]=N,t[56]=ye,t[57]=be):(ye=t[56],be=t[57]),(0,Q.useEffect)(ye,be);let xe=f&&g&&`motion-safe:delay-100`,Se=_&&`opacity-0`,Ce;t[58]!==xe||t[59]!==Se?(Ce=Gi(`flex-row h-12 items-center py-0 px-3`,f?`justify-end`:`justify-between`,f&&`motion-safe:transition-opacity motion-safe:duration-100 motion-safe:ease-out`,xe,Se,f&&`[-webkit-app-region:drag]`),t[58]=xe,t[59]=Se,t[60]=Ce):Ce=t[60];let we;t[61]===g?we=t[62]:(we=g&&!f?(0,Z.jsx)(`span`,{className:`shrink-0 font-mono text-sm uppercase tracking-wider text-sidebar-foreground/50`,children:(0,Z.jsx)(s,{id:`sER-bs`})}):null,t[61]=g,t[62]=we);let Te;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(Te=Gi(`flex items-center gap-1`,f&&`[&>*]:[-webkit-app-region:no-drag]`),t[63]=Te):Te=t[63];let Ee;t[64]!==r||t[65]!==T||t[66]!==w||t[67]!==E||t[68]!==a?(Ee=w?(0,Z.jsxs)(Ya,{children:[(0,Z.jsx)(Ho,{asChild:!0,children:(0,Z.jsx)(MU,{icon:cl,label:r({id:`Lu_dOh`})})}),(0,Z.jsxs)(xo,{align:`end`,children:[T?null:(0,Z.jsxs)(Wo,{onSelect:()=>a?.expandAll(),children:[(0,Z.jsx)(Vl,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`b392Dr`})]}),E?null:(0,Z.jsxs)(Wo,{onSelect:()=>a?.collapseAll(),children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`BBtVak`})]})]})]}):null,t[64]=r,t[65]=T,t[66]=w,t[67]=E,t[68]=a,t[69]=Ee):Ee=t[69];let De;t[70]===r?De=t[71]:(De=r({id:`MW64zN`}),t[70]=r,t[71]=De);let Oe;t[72]!==d||t[73]!==a?(Oe=()=>a?.startCreating(`file`,d),t[72]=d,t[73]=a,t[74]=Oe):Oe=t[74];let ke;t[75]!==De||t[76]!==Oe?(ke=(0,Z.jsx)(MU,{icon:Nl,label:De,onClick:Oe}),t[75]=De,t[76]=Oe,t[77]=ke):ke=t[77];let Ae;t[78]!==r||t[79]!==j||t[80]!==d||t[81]!==a?(Ae=j?(0,Z.jsxs)(Ya,{children:[(0,Z.jsx)(Ho,{asChild:!0,children:(0,Z.jsx)(MU,{icon:mo,label:r({id:`Uuj_R4`})})}),(0,Z.jsx)(xo,{align:`end`,children:(0,Z.jsx)(OV,{parentDir:d,onSelectTemplate:e=>a?.createFromTemplate(d,e),ItemComponent:Wo})})]}):null,t[78]=r,t[79]=j,t[80]=d,t[81]=a,t[82]=Ae):Ae=t[82];let je;t[83]===r?je=t[84]:(je=r({id:`tX5yOZ`}),t[83]=r,t[84]=je);let Me;t[85]!==d||t[86]!==a?(Me=()=>a?.startCreating(`folder`,d),t[85]=d,t[86]=a,t[87]=Me):Me=t[87];let Ne;t[88]!==je||t[89]!==Me?(Ne=(0,Z.jsx)(MU,{icon:el,label:je,onClick:Me}),t[88]=je,t[89]=Me,t[90]=Ne):Ne=t[90];let Pe;t[91]!==Ee||t[92]!==ke||t[93]!==Ae||t[94]!==Ne?(Pe=(0,Z.jsxs)(`div`,{className:Te,children:[Ee,ke,Ae,Ne]}),t[91]=Ee,t[92]=ke,t[93]=Ae,t[94]=Ne,t[95]=Pe):Pe=t[95];let Fe;t[96]!==Ce||t[97]!==we||t[98]!==Pe?(Fe=(0,Z.jsxs)(WD,{"data-electron-drag":f?``:void 0,className:Ce,children:[we,Pe]}),t[96]=Ce,t[97]=we,t[98]=Pe,t[99]=Fe):Fe=t[99];let Ie=f&&g&&`motion-safe:delay-100`,Le=_&&`opacity-0`,Re;t[100]!==Ie||t[101]!==Le?(Re=Gi(`px-2 pb-2`,f&&`[-webkit-app-region:no-drag]`,f&&`motion-safe:transition-opacity motion-safe:duration-100 motion-safe:ease-out`,Ie,Le),t[100]=Ie,t[101]=Le,t[102]=Re):Re=t[102];let ze;t[103]===p?ze=t[104]:(ze=[p],t[103]=p,t[104]=ze);let Ve;t[105]===n?Ve=t[106]:(Ve=(0,Z.jsx)(bU,{onClick:n}),t[105]=n,t[106]=Ve);let He;t[107]!==ze||t[108]!==Ve?(He=(0,Z.jsx)(W,{fallbackRender:PU,onError:yU,resetKeys:ze,children:Ve}),t[107]=ze,t[108]=Ve,t[109]=He):He=t[109];let Ue;t[110]!==Re||t[111]!==He?(Ue=(0,Z.jsx)(`div`,{className:Re,children:He}),t[110]=Re,t[111]=He,t[112]=Ue):Ue=t[112];let We;t[113]===Symbol.for(`react.memo_cache_sentinel`)?(We=(0,Z.jsxs)(KD,{children:[(0,Z.jsx)(SA,{}),(0,Z.jsx)(RH,{ref:o})]}),t[113]=We):We=t[113];let Ge;t[114]===Symbol.for(`react.memo_cache_sentinel`)?(Ge=(0,Z.jsxs)(GD,{className:`px-0`,children:[(0,Z.jsx)(CU,{}),typeof window<`u`&&window.okDesktop?(0,Z.jsx)(qD,{children:(0,Z.jsx)(JD,{children:(0,Z.jsx)(_U,{bridge:window.okDesktop})})}):null]}),t[114]=Ge):Ge=t[114];let Ke=!(h&&p===`collapsed`),qe;t[115]===Ke?qe=t[116]:(qe=(0,Z.jsx)(HD,{enableToggle:!1,enableDrag:Ke}),t[115]=Ke,t[116]=qe);let X;t[117]!==Fe||t[118]!==Ue||t[119]!==qe?(X=(0,Z.jsx)(Ik,{asChild:!0,children:(0,Z.jsxs)(`div`,{className:`contents`,onContextMenu:K,children:[Fe,Ue,We,Ge,qe]})}),t[117]=Fe,t[118]=Ue,t[119]=qe,t[120]=X):X=t[120];let Je=!N,Ye,Xe;t[121]===Symbol.for(`react.memo_cache_sentinel`)?(Ye=(0,Z.jsx)(Nl,{"aria-hidden":`true`}),Xe=(0,Z.jsx)(s,{id:`MW64zN`}),t[121]=Ye,t[122]=Xe):(Ye=t[121],Xe=t[122]);let Ze;t[123]!==J||t[124]!==Je?(Ze=(0,Z.jsxs)(zk,{disabled:Je,onSelect:J,"data-testid":`empty-space-menu-new-file`,children:[Ye,Xe]}),t[123]=J,t[124]=Je,t[125]=Ze):Ze=t[125];let Qe=!N||!A,$e,et;t[126]===Symbol.for(`react.memo_cache_sentinel`)?($e=(0,Z.jsx)(mo,{"aria-hidden":`true`}),et=(0,Z.jsx)(s,{id:`Uuj_R4`}),t[126]=$e,t[127]=et):($e=t[126],et=t[127]);let tt;t[128]===Qe?tt=t[129]:(tt=(0,Z.jsxs)(Bk,{disabled:Qe,"data-testid":`empty-space-menu-new-from-template`,children:[$e,et]}),t[128]=Qe,t[129]=tt);let nt;t[130]===ee?nt=t[131]:(nt=(0,Z.jsx)(Vk,{children:(0,Z.jsx)(OV,{parentDir:``,onSelectTemplate:ee,ItemComponent:zk})}),t[130]=ee,t[131]=nt);let rt;t[132]!==tt||t[133]!==nt?(rt=(0,Z.jsxs)(Lk,{children:[tt,nt]}),t[132]=tt,t[133]=nt,t[134]=rt):rt=t[134];let it=!N,at,ot;t[135]===Symbol.for(`react.memo_cache_sentinel`)?(at=(0,Z.jsx)(el,{"aria-hidden":`true`}),ot=(0,Z.jsx)(s,{id:`tX5yOZ`}),t[135]=at,t[136]=ot):(at=t[135],ot=t[136]);let st;t[137]!==ne||t[138]!==it?(st=(0,Z.jsxs)(zk,{disabled:it,onSelect:ne,"data-testid":`empty-space-menu-new-folder`,children:[at,ot]}),t[137]=ne,t[138]=it,t[139]=st):st=t[139];let ct;t[140]===Symbol.for(`react.memo_cache_sentinel`)?(ct=(0,Z.jsx)(Uk,{}),t[140]=ct):ct=t[140];let lt;t[141]!==r||t[142]!==ie||t[143]!==N?(lt=M?(0,Z.jsxs)(zk,{disabled:!N,onSelect:ie,"data-testid":`empty-space-menu-reveal-in-finder`,"aria-label":r(N?{id:`LtSYdi`}:{id:`o2yoFu`}),children:[(0,Z.jsx)(yt,{"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:(0,Z.jsx)(s,{id:`LtSYdi`})}),N?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`wTcjov`})})]}):null,t[141]=r,t[142]=ie,t[143]=N,t[144]=lt):lt=t[144];let ut;t[145]!==F||t[146]!==L||t[147]!==P?(ut=(0,Z.jsx)(hU,{input:L,installStates:P,dispatch:F,webFallbackVisible:!1}),t[145]=F,t[146]=L,t[147]=P,t[148]=ut):ut=t[148];let dt;t[149]!==r||t[150]!==oe||t[151]!==N?(dt=M?(0,Z.jsxs)(zk,{disabled:!N,onSelect:oe,"data-testid":`empty-space-menu-open-in-terminal`,"aria-label":r(N?{id:`BJpGCq`}:{id:`_6IEmc`}),children:[(0,Z.jsx)(Rl,{"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:(0,Z.jsx)(s,{id:`BJpGCq`})}),N?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`wTcjov`})})]}):null,t[149]=r,t[150]=oe,t[151]=N,t[152]=dt):dt=t[152];let ft=!N,mt;t[153]!==r||t[154]!==N?(mt=r(N?{id:`Up2_7p`}:{id:`U8CD-l`}),t[153]=r,t[154]=N,t[155]=mt):mt=t[155];let ht;t[156]===Symbol.for(`react.memo_cache_sentinel`)?(ht=(0,Z.jsx)(Be,{"aria-hidden":`true`}),t[156]=ht):ht=t[156];let _t;t[157]===Symbol.for(`react.memo_cache_sentinel`)?(_t=(0,Z.jsx)(`span`,{className:`flex-1`,children:(0,Z.jsx)(s,{id:`Up2_7p`})}),t[157]=_t):_t=t[157];let vt;t[158]===N?vt=t[159]:(vt=N?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:(0,Z.jsx)(s,{id:`wTcjov`})}),t[158]=N,t[159]=vt);let bt;t[160]!==ce||t[161]!==ft||t[162]!==mt||t[163]!==vt?(bt=(0,Z.jsxs)(zk,{disabled:ft,onSelect:ce,"data-testid":`empty-space-menu-copy-full-path`,"aria-label":mt,children:[ht,_t,vt]}),t[160]=ce,t[161]=ft,t[162]=mt,t[163]=vt,t[164]=bt):bt=t[164];let xt;t[165]===Symbol.for(`react.memo_cache_sentinel`)?(xt=(0,Z.jsx)(Uk,{}),t[165]=xt):xt=t[165];let St=R===null,Ct;t[166]===Symbol.for(`react.memo_cache_sentinel`)?(Ct=(0,Z.jsx)(s,{id:`K_wz1u`}),t[166]=Ct):Ct=t[166];let wt;t[167]!==ue||t[168]!==B||t[169]!==St?(wt=(0,Z.jsx)(Hk,{checked:B,onCheckedChange:ue,disabled:St,"data-testid":`empty-space-menu-show-hidden-files`,children:Ct}),t[167]=ue,t[168]=B,t[169]=St,t[170]=wt):wt=t[170];let Tt=R===null,Et;t[171]===Symbol.for(`react.memo_cache_sentinel`)?(Et=(0,Z.jsx)(s,{id:`i8dKs-`}),t[171]=Et):Et=t[171];let Dt;t[172]!==fe||t[173]!==V||t[174]!==Tt?(Dt=(0,Z.jsx)(Hk,{checked:V,onCheckedChange:fe,disabled:Tt,"data-testid":`empty-space-menu-show-all-files`,children:Et}),t[172]=fe,t[173]=V,t[174]=Tt,t[175]=Dt):Dt=t[175];let Ot;t[176]===G?Ot=t[177]:(Ot=G?(0,Z.jsx)(Uk,{}):null,t[176]=G,t[177]=Ot);let kt;t[178]!==me||t[179]!==H?(kt=H?(0,Z.jsxs)(zk,{onSelect:me,"data-testid":`empty-space-menu-expand-all`,children:[(0,Z.jsx)(Vl,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`OlAl5i`})]}):null,t[178]=me,t[179]=H,t[180]=kt):kt=t[180];let At;t[181]!==ge||t[182]!==U?(At=U?(0,Z.jsxs)(zk,{onSelect:ge,"data-testid":`empty-space-menu-collapse-all`,children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`qvWGzP`})]}):null,t[181]=ge,t[182]=U,t[183]=At):At=t[183];let jt;t[184]!==Ze||t[185]!==rt||t[186]!==st||t[187]!==lt||t[188]!==ut||t[189]!==dt||t[190]!==bt||t[191]!==wt||t[192]!==Dt||t[193]!==Ot||t[194]!==kt||t[195]!==At?(jt=(0,Z.jsxs)(Rk,{children:[Ze,rt,st,ct,lt,ut,dt,bt,xt,wt,Dt,Ot,kt,At]}),t[184]=Ze,t[185]=rt,t[186]=st,t[187]=lt,t[188]=ut,t[189]=dt,t[190]=bt,t[191]=wt,t[192]=Dt,t[193]=Ot,t[194]=kt,t[195]=At,t[196]=jt):jt=t[196];let Mt;return t[197]!==X||t[198]!==jt?(Mt=(0,Z.jsx)(BD,{variant:`inset`,children:(0,Z.jsxs)(Fk,{children:[X,jt]})}),t[197]=X,t[198]=jt,t[199]=Mt):Mt=t[199],Mt}function PU(){return null}function FU(e){AU(e.target)&&(e.preventDefault(),e.stopPropagation())}function IU(e){let t=e.shareTargetExists,n=e.dirtyConflicts.conflicts,r=e.dirtyConflicts.files;return t&&!n?{kind:`A`,openCurrentEnabled:!0,switchEnabled:!0,conflictingFiles:r}:!t&&!n?{kind:`B`,openCurrentEnabled:!1,switchEnabled:!0,conflictingFiles:r}:t&&n?{kind:`C`,openCurrentEnabled:!0,switchEnabled:!1,conflictingFiles:r}:{kind:`D`,openCurrentEnabled:!1,switchEnabled:!1,conflictingFiles:r}}function LU(e){return e.detached?e.currentHeadSha:e.currentBranch??`HEAD`}function RU(e){if(e.ok)return{action:`await-cc1`};switch(e.reason){case`dirty-conflict`:return{action:`rerender-conflict`,files:e.files??[]};case`branch-not-found`:return{action:`dismiss-with-toast`,reason:`branch-not-found`};case`fetch-failed`:case`checkout-failed`:return{action:`stay-with-toast`,reason:e.reason};case`branch-in-other-worktree`:{let t=e.otherWorktreePath;return t===void 0||t.length===0?{action:`stay-with-toast`,reason:`checkout-failed`}:{action:`pivot-to-other-worktree`,otherWorktreePath:t}}default:{let t=e.reason;throw Error(`Unhandled CheckoutFailureReason: ${String(t)}`)}}}var zU={phase:`loading`};function BU(e,t){return e.phase===`loading`?t===null?{phase:`error`}:{phase:`ready`,info:t}:e}function VU(e,t){return e.phase===`ready`?{phase:`switching`,info:e.info,pendingDoc:t}:e}function HU(e,t){if(e.phase!==`switching`)return{state:e};if(t===null)return{state:{phase:`ready`,info:e.info},sideEffect:{kind:`toast`,reason:`proxy-null`}};let n=RU(t);return n.action===`await-cc1`?{state:{phase:`awaiting-cc1-recycle`,pendingDoc:e.pendingDoc}}:n.action===`rerender-conflict`?{state:{phase:`ready`,info:{...e.info,dirtyConflicts:{conflicts:!0,files:n.files.slice()}}}}:n.action===`pivot-to-other-worktree`?{state:{phase:`branch-in-other-worktree`,info:e.info,otherWorktreePath:n.otherWorktreePath,pendingDoc:e.pendingDoc}}:n.action===`dismiss-with-toast`?{state:{phase:`dismissed`,reason:n.reason},sideEffect:{kind:`toast`,reason:n.reason}}:{state:{phase:`ready`,info:e.info},sideEffect:{kind:`toast`,reason:n.reason}}}function UU(e){return e!==null&&e.kind===`project-branch-switch`}function WU(e){let t=(0,$.c)(146),{bridge:n,store:r}=e,a=r===void 0?Wd:r,{_:o}=i(),c=(0,Q.useSyncExternalStore)(a.subscribe,a.getSnapshot,XU),[l,u]=(0,Q.useState)(zU),d=(0,Q.useRef)(!1),f=(0,Q.useRef)(!1),p;t[0]===c?p=t[1]:(p=UU(c)?c:null,t[0]=c,t[1]=p);let m=p,h;t[2]!==o||t[3]!==m?.share.target.kind?(h=m?.share.target.kind===`folder`?o({id:`ugoTXs`}):o({id:`XH30C4`}),t[2]=o,t[3]=m?.share.target.kind,t[4]=h):h=t[4];let g=h,_;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{u(zU),d.current=!1,f.current=!1},t[5]=_):_=t[5];let v;t[6]===c?v=t[7]:(v=[c],t[6]=c,t[7]=v),(0,Q.useEffect)(_,v);let y;t[8]!==m||t[9]!==n?(y=()=>{m&&(d.current||(d.current=!0,n.project.fetchBranchInfo({projectPath:m.projectPath,branch:m.share.branch,kind:m.share.target.kind,path:C(m.share.target)}).then(e=>{u(t=>BU(t,e))}).catch(e=>{console.warn(`[receive] branch-info-fetch-failed`,e instanceof Error?e.message:e),u(YU)})))},t[8]=m,t[9]=n,t[10]=y):y=t[10];let b;t[11]===m?b=t[12]:(b=[m],t[11]=m,t[12]=b),(0,Q.useEffect)(y,b);let x;t[13]!==o||t[14]!==m||t[15]!==l.phase||t[16]!==n||t[17]!==a||t[18]!==g?(x=()=>{if(l.phase!==`awaiting-cc1-recycle`||!m)return;let e=m.share.branch;if(!e){a.dismiss();return}if(f.current)return;f.current=!0;let t=!1;return n.project.awaitBranchSwitched({projectPath:m.projectPath,branch:e,timeoutMs:3e4}).then(r=>{if(!t){if(r.ok){console.log(Xl({branch_dialog_action:`branch-switch-complete`,branch:e})),n.project.open({path:m.projectPath,target:`new-window`,entryPoint:`share-receive`,pendingDeepLinkTarget:{kind:m.share.target.kind,path:C(m.share.target)},pendingBranch:e}).catch(e=>{console.warn(`[receive] warm-focus-dispatch-failed branch_action=switch`,e instanceof Error?e.message:e),gs.error(o({id:`gQV-9w`,values:{targetNoun:g}}))}),a.dismiss();return}console.log(Xl({branch_dialog_action:`branch-switch-timeout`,branch:e})),gs.error(o({id:`LBwUR6`,values:{targetNoun:g}})),a.dismiss()}}).catch(e=>{t||(console.warn(`[receive] awaitBranchSwitched rejected`,e instanceof Error?e.message:e),gs.error(o({id:`Jw6EC4`,values:{targetNoun:g}})),a.dismiss())}),()=>{t=!0}},t[13]=o,t[14]=m,t[15]=l.phase,t[16]=n,t[17]=a,t[18]=g,t[19]=x):x=t[19];let S;if(t[20]!==m||t[21]!==l.phase?(S=[l.phase,m],t[20]=m,t[21]=l.phase,t[22]=S):S=t[22],(0,Q.useEffect)(x,S),!m)return null;let{share:w,projectPath:T,currentBranch:E}=m,D=w.branch,O;t[23]!==o||t[24]!==l.info||t[25]!==l.phase||t[26]!==n.project||t[27]!==T||t[28]!==w.target||t[29]!==D||t[30]!==a?(O=function(){l.phase===`ready`&&IU(l.info).switchEnabled&&(console.log(Xl({branch_dialog_action:`switch`,branch_action:`switch`,branch:D})),u(e=>VU(e,C(w.target))),n.project.runCheckout({projectPath:T,branch:D}).then(e=>{let t=null,n=!1;u(r=>{let{state:i,sideEffect:a}=HU(r,e);return a&&(t=a.reason,n=i.phase===`dismissed`),i}),t===`branch-not-found`?gs.error(o({id:`NJyQi_`,values:{shareBranch:D}})):t===`fetch-failed`?gs.error(o({id:`bWLmRK`})):(t===`checkout-failed`||t===`proxy-null`)&&gs.error(o({id:`c863eW`,values:{shareBranch:D}})),n&&a.dismiss()}).catch(e=>{console.warn(`[receive] runCheckout rejected branch_action=switch`,e instanceof Error?e.message:e),u(JU),gs.error(o({id:`c863eW`,values:{shareBranch:D}}))}))},t[23]=o,t[24]=l.info,t[25]=l.phase,t[26]=n.project,t[27]=T,t[28]=w.target,t[29]=D,t[30]=a,t[31]=O):O=t[31];let k=O,A;t[32]!==o||t[33]!==n.project||t[34]!==T||t[35]!==w.target||t[36]!==D||t[37]!==a||t[38]!==g?(A=function(){console.log(Xl({branch_dialog_action:`open-current`,branch:D})),n.project.open({path:T,target:`new-window`,entryPoint:`share-receive`,pendingDeepLinkTarget:{kind:w.target.kind,path:C(w.target)}}).catch(e=>{console.warn(`[receive] warm-focus-dispatch-failed branch_action=open-current`,e instanceof Error?e.message:e),gs.error(o({id:`b5aNbi`,values:{targetNoun:g}}))}),a.dismiss()},t[32]=o,t[33]=n.project,t[34]=T,t[35]=w.target,t[36]=D,t[37]=a,t[38]=g,t[39]=A):A=t[39];let j=A,M;t[40]!==o||t[41]!==l.otherWorktreePath||t[42]!==l.phase||t[43]!==n.project||t[44]!==w.target||t[45]!==D||t[46]!==a?(M=function(){if(l.phase!==`branch-in-other-worktree`)return;let e=l.otherWorktreePath;console.log(Xl({branch_dialog_action:`pivot-to-other-worktree`,branch:D})),n.project.open({path:e,target:`new-window`,entryPoint:`share-receive`,pendingDeepLinkTarget:{kind:w.target.kind,path:C(w.target)},pendingBranch:D}).catch(t=>{console.warn(`[receive] pivot-open-failed branch_action=pivot-to-other-worktree`,t instanceof Error?t.message:t),gs.error(o({id:`LdABLa`,values:{target:e}}))}),a.dismiss()},t[40]=o,t[41]=l.otherWorktreePath,t[42]=l.phase,t[43]=n.project,t[44]=w.target,t[45]=D,t[46]=a,t[47]=M):M=t[47];let N=M,P;t[48]===a?P=t[49]:(P=function(){console.log(Xl({branch_dialog_action:`cancel`})),a.dismiss()},t[48]=a,t[49]=P);let F=P,I,L,R,z,B,V,H,U,W,G,K,q,J,Y,ee,te,ne;if(t[50]!==o||t[51]!==l.info||t[52]!==l.otherWorktreePath||t[53]!==l.phase||t[54]!==F||t[55]!==E||t[56]!==w.branch||t[57]!==w.owner||t[58]!==w.repo||t[59]!==w.target||t[60]!==D||t[61]!==g){ne=l.phase===`ready`||l.phase===`switching`?IU(l.info):null;let e;t[79]!==l.info||t[80]!==l.phase||t[81]!==E?(e=l.phase===`ready`||l.phase===`switching`?LU(l.info):E??`HEAD`,t[79]=l.info,t[80]=l.phase,t[81]=E,t[82]=e):e=t[82];let n=e;V=l.phase===`switching`||l.phase===`awaiting-cc1-recycle`;let r;t[83]===o?r=t[84]:(r=o({id:`OuY8t9`}),t[83]=o,t[84]=r),z=r;let i;t[85]!==o||t[86]!==D?(i=o({id:`_BthEY`,values:{shareBranch:D}}),t[85]=o,t[86]=D,t[87]=i):i=t[87],B=i;let a=l.phase===`loading`,c=l.phase===`error`;R=ps,ee=!0,t[88]===F?te=t[89]:(te=e=>{e||F()},t[88]=F,t[89]=te),L=ls,G=`sm:max-w-xl`,K=`share-branch-switch-dialog`,q=qU,J=KU;let u;t[90]===g?u=t[91]:(u=(0,Z.jsx)(cs,{children:(0,Z.jsx)(s,{id:`RY6Bq1`,values:{targetNoun:g}})}),t[90]=g,t[91]=u);let d=w.owner,f=w.repo,p;t[92]===w.target?p=t[93]:(p=C(w.target),t[92]=w.target,t[93]=p);let m;t[94]!==w.owner||t[95]!==w.repo||t[96]!==p?(m=(0,Z.jsx)(os,{className:`sr-only`,children:(0,Z.jsx)(s,{id:`f8jU-L`,values:{0:d,1:f,2:p}})}),t[94]=w.owner,t[95]=w.repo,t[96]=p,t[97]=m):m=t[97],t[98]!==u||t[99]!==m?(Y=(0,Z.jsxs)(fs,{children:[u,m]}),t[98]=u,t[99]=m,t[100]=Y):Y=t[100],I=us;let h=w.owner,_=w.repo,v;t[101]===w.target?v=t[102]:(v=C(w.target),t[101]=w.target,t[102]=v),t[103]!==w.branch||t[104]!==w.owner||t[105]!==w.repo||t[106]!==w.target.kind||t[107]!==v?(H=(0,Z.jsx)(`div`,{className:`mb-4`,children:(0,Z.jsx)(Id,{owner:h,repo:_,path:v,kind:w.target.kind,branch:w.branch,testId:`share-branch-switch-metadata`,branchTestId:`share-branch-switch-metadata-branch`})}),t[103]=w.branch,t[104]=w.owner,t[105]=w.repo,t[106]=w.target.kind,t[107]=v,t[108]=H):H=t[108],U=l.phase===`branch-in-other-worktree`?(0,Z.jsxs)(`div`,{className:`text-sm text-muted-foreground`,"data-testid":`share-branch-switch-in-other-worktree`,children:[(0,Z.jsx)(`p`,{className:`leading-6`,children:(0,Z.jsx)(s,{id:`yjExfe`,values:{shareBranch:D},components:{0:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`})}})}),(0,Z.jsx)(`p`,{className:`mt-2 break-all rounded bg-muted px-2 py-1 font-mono text-xs text-foreground/80`,"data-testid":`share-branch-switch-in-other-worktree-path`,children:l.otherWorktreePath})]}):a?(0,Z.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`share-branch-switch-loading`,role:`status`,"aria-live":`polite`,children:[(0,Z.jsx)(wt,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`jerqF0`})]}):c?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:(0,Z.jsx)(s,{id:`w4hMYl`})}):ne?.kind===`D`?(0,Z.jsx)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:(0,Z.jsx)(s,{id:`XnoA1k`,values:{targetNoun:g,shareBranch:D},components:{0:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`})}})}):ne?.kind===`B`?(0,Z.jsx)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:(0,Z.jsx)(s,{id:`sZ2IOu`,values:{targetNoun:g,shareBranch:D,currentLabel:n},components:{0:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`}),1:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`})}})}):(0,Z.jsx)(`p`,{className:`text-sm leading-6 text-muted-foreground`,children:(0,Z.jsx)(s,{id:`_902BE`,values:{targetNoun:g,shareBranch:D,currentLabel:n},components:{0:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`}),1:(0,Z.jsx)(`code`,{className:`rounded-sm bg-muted px-1 py-0.5 text-foreground/80`})}})}),W=ne&&!ne.switchEnabled&&ne.conflictingFiles.length>0?(0,Z.jsxs)(`div`,{className:`mt-3 rounded-md border border-border bg-muted/30 p-3 text-1sm`,"data-testid":`share-branch-switch-conflict`,children:[(0,Z.jsx)(`p`,{className:`font-medium text-foreground/90`,children:(0,Z.jsx)(s,{id:`n2lRue`})}),(0,Z.jsx)(`ul`,{id:`share-receive-branch-conflict-files`,className:`mt-1 list-disc space-y-0.5 pl-5 text-muted-foreground`,children:ne.conflictingFiles.map(GU)})]}):null,t[50]=o,t[51]=l.info,t[52]=l.otherWorktreePath,t[53]=l.phase,t[54]=F,t[55]=E,t[56]=w.branch,t[57]=w.owner,t[58]=w.repo,t[59]=w.target,t[60]=D,t[61]=g,t[62]=I,t[63]=L,t[64]=R,t[65]=z,t[66]=B,t[67]=V,t[68]=H,t[69]=U,t[70]=W,t[71]=G,t[72]=K,t[73]=q,t[74]=J,t[75]=Y,t[76]=ee,t[77]=te,t[78]=ne}else I=t[62],L=t[63],R=t[64],z=t[65],B=t[66],V=t[67],H=t[68],U=t[69],W=t[70],G=t[71],K=t[72],q=t[73],J=t[74],Y=t[75],ee=t[76],te=t[77],ne=t[78];let re;t[109]===V?re=t[110]:(re=V?(0,Z.jsxs)(`p`,{className:`mt-3 flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`share-branch-switch-switching`,role:`status`,"aria-live":`polite`,children:[(0,Z.jsx)(wt,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),(0,Z.jsx)(s,{id:`CU3AiE`})]}):null,t[109]=V,t[110]=re);let ie;t[111]!==I||t[112]!==H||t[113]!==U||t[114]!==W||t[115]!==re?(ie=(0,Z.jsxs)(I,{children:[H,U,W,re]}),t[111]=I,t[112]=H,t[113]=U,t[114]=W,t[115]=re,t[116]=ie):ie=t[116];let ae;t[117]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(0,Z.jsx)(s,{id:`dEgA5A`}),t[117]=ae):ae=t[117];let oe;t[118]===F?oe=t[119]:(oe=(0,Z.jsx)(Qi,{variant:`ghost`,className:`font-mono uppercase`,onClick:F,"data-testid":`share-branch-switch-cancel`,children:ae}),t[118]=F,t[119]=oe);let se;t[120]!==l.phase||t[121]!==j||t[122]!==N||t[123]!==k||t[124]!==z||t[125]!==B||t[126]!==V||t[127]!==ne?(se=l.phase===`branch-in-other-worktree`?(0,Z.jsx)(Qi,{onClick:N,"data-testid":`share-branch-switch-in-other-worktree-pivot`,children:(0,Z.jsx)(s,{id:`hyCxJY`})}):(0,Z.jsxs)(`div`,{className:`flex flex-col-reverse gap-2 sm:flex-row sm:gap-2`,children:[ne?.openCurrentEnabled?(0,Z.jsxs)(Qi,{variant:`outline`,className:`font-mono uppercase`,onClick:j,disabled:V,"data-testid":`share-branch-switch-open-current`,children:[(0,Z.jsx)(fl,{className:`size-3.5`,"aria-hidden":!0}),z]}):null,(0,Z.jsx)(Qi,{onClick:k,disabled:!ne?.switchEnabled||V,"aria-disabled":!ne?.switchEnabled||V,"aria-describedby":ne&&!ne.switchEnabled&&ne.conflictingFiles.length>0?`share-receive-branch-conflict-files`:void 0,"data-testid":`share-branch-switch-switch`,children:V?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(wt,{className:`size-3.5 animate-spin`,"aria-hidden":`true`}),B]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ae,{className:`size-3.5`,"aria-hidden":!0}),B]})})]}),t[120]=l.phase,t[121]=j,t[122]=N,t[123]=k,t[124]=z,t[125]=B,t[126]=V,t[127]=ne,t[128]=se):se=t[128];let ce;t[129]!==oe||t[130]!==se?(ce=(0,Z.jsxs)(ds,{className:`sm:justify-between`,children:[oe,se]}),t[129]=oe,t[130]=se,t[131]=ce):ce=t[131];let le;t[132]!==L||t[133]!==G||t[134]!==K||t[135]!==q||t[136]!==J||t[137]!==Y||t[138]!==ie||t[139]!==ce?(le=(0,Z.jsxs)(L,{className:G,"data-testid":K,onInteractOutside:q,onPointerDownOutside:J,children:[Y,ie,ce]}),t[132]=L,t[133]=G,t[134]=K,t[135]=q,t[136]=J,t[137]=Y,t[138]=ie,t[139]=ce,t[140]=le):le=t[140];let ue;return t[141]!==R||t[142]!==ee||t[143]!==te||t[144]!==le?(ue=(0,Z.jsx)(R,{open:ee,onOpenChange:te,children:le}),t[141]=R,t[142]=ee,t[143]=te,t[144]=le,t[145]=ue):ue=t[145],ue}function GU(e){return(0,Z.jsx)(`li`,{children:(0,Z.jsx)(`code`,{className:`text-foreground/80`,children:e})},e)}function KU(e){e.preventDefault()}function qU(e){e.preventDefault()}function JU(e){return HU(e,null).state}function YU(e){return BU(e,null)}function XU(){return null}function ZU(){let e=(0,$.c)(17),t=Dn(),{collabUrl:n,setSystemProvider:r,updateServerInstanceId:i,onBranchSwitched:a,observeBranch:o,observeDiskAck:s,refreshServerInfo:c}=pt(),l;e[0]!==o||e[1]!==s||e[2]!==a||e[3]!==c||e[4]!==i?(l={updateServerInstanceId:i,onBranchSwitched:a,observeBranch:o,observeDiskAck:s,refreshServerInfo:c},e[0]=o,e[1]=s,e[2]=a,e[3]=c,e[4]=i,e[5]=l):l=e[5];let u=(0,Q.useRef)(l),d;e[6]!==o||e[7]!==s||e[8]!==a||e[9]!==c||e[10]!==i?(d=()=>{u.current={updateServerInstanceId:i,onBranchSwitched:a,observeBranch:o,observeDiskAck:s,refreshServerInfo:c}},e[6]=o,e[7]=s,e[8]=a,e[9]=c,e[10]=i,e[11]=d):d=e[11],(0,Q.useEffect)(d);let f,p;return e[12]!==n||e[13]!==t||e[14]!==r?(f=()=>{if(n===null)return;let e=new zt,i=new Ze({url:n,name:Mi,document:e,onStateless:e=>{let{payload:t}=e;fe(t,{onServerInfo:e=>{u.current.updateServerInstanceId(e.serverInstanceId),e.currentBranch!==void 0&&u.current.observeBranch(e.currentBranch)},onBranchSwitched:e=>{u.current.onBranchSwitched(e.branch)},onDiskAck:e=>{u.current.observeDiskAck(e.docName,e.sv)},onDerivedView:rW,onConfigValidationRejected:nW,onConfigIgnoreNestedError:tW,onUnknown:eW})},onClose:$U,onDisconnect:QU}),a=ni(e=>{(e.includes(`files`)||e.includes(`backlinks`))&&(t.invalidateQueries({queryKey:[`backlinks`]}),t.invalidateQueries({queryKey:[`forward-links`]})),(e.includes(`files`)||e.includes(`graph`))&&(t.invalidateQueries({queryKey:[`orphans`]}),t.invalidateQueries({queryKey:[`hubs`]}))}),o=E(()=>{u.current.refreshServerInfo()});i.on(`synced`,()=>{Ti([`files`,`backlinks`,`graph`]),o()});let s=new Set,c=()=>{if(i.awareness)for(let[e,t]of i.awareness.getStates().entries())s.has(e)||t.user?.type===`agent`&&(s.add(e),console.warn(`[agent-presence] observed stale AwarenessUser.type === 'agent' from clientID ${e} — probably a stale bundled client`))};return i.awareness?.on(`change`,c),r(i),()=>{a(),i.awareness?.off(`change`,c),r(null),i.destroy(),e.destroy()}},p=[t,n,r],e[12]=n,e[13]=t,e[14]=r,e[15]=f,e[16]=p):(f=e[15],p=e[16]),(0,Q.useEffect)(f,p),null}function QU(){console.warn(`[CC1] __system__ disconnected - derived views may be stale`)}function $U(e){let{event:t}=e;console.warn(`[CC1] __system__ connection closed:`,t.code,t.reason)}function eW(e){console.warn(`[CC1] Unparseable stateless payload, skipping:`,e.slice(0,100))}function tW(e){Bo(e)}function nW(e){Uo(e)}function rW(e){Ti([e.ch])}var iW=`#install-claude-desktop`;function aW(e){return e===`#settings`||e===iW}function oW(e,t,n){return[e,t,n].map(e=>[...e].sort().join(`\0`)).join(``)}function sW(){let e=(0,$.c)(23),{clearTarget:t,syncOpenTabsWithKnownTargets:n,tabSessionLoaded:r}=pt(),{openTargetTransition:i}=Et(),{assetPaths:a,folderPaths:o,loading:s,pageMeta:c,pages:l,pagesBySlug:u,pagesByBasename:d}=ki(),f=(0,Q.useRef)(null),p;e[0]!==a||e[1]!==o||e[2]!==l?(p=oW(l,o,a),e[0]=a,e[1]=o,e[2]=l,e[3]=p):p=e[3];let m=p,h,g;e[4]!==a||e[5]!==o||e[6]!==s||e[7]!==l||e[8]!==n||e[9]!==r||e[10]!==m?(h=()=>{s||!r||f.current===m||(f.current=m,n({pages:l,folderPaths:o,assetPaths:a}))},g=[a,o,s,l,n,r,m],e[4]=a,e[5]=o,e[6]=s,e[7]=l,e[8]=n,e[9]=r,e[10]=m,e[11]=h,e[12]=g):(h=e[11],g=e[12]),(0,Q.useEffect)(h,g);let _,v;return e[13]!==t||e[14]!==o||e[15]!==s||e[16]!==i||e[17]!==c||e[18]!==l||e[19]!==d||e[20]!==u?(_=()=>{e();function e(){if(aW(window.location.hash))return;let e=Hn(window.location.hash);if(e){let t=_i(e.split(`.`).pop()??``);b(`ok/nav/hash-change`,{docName:null,kind:`asset`}),i({kind:`asset`,target:e,assetPath:e,mediaKind:t});return}if(Sr(window.location.hash)){b(`ok/nav/hash-change`,{docName:null,kind:`folder`}),i({kind:`folder`,target:``,folderPath:``});return}let n=yr(window.location.hash);if(!n){b(`ok/nav/hash-change`,{docName:null,kind:`clear`}),t();return}if(s){b(`ok/nav/hash-change`,{docName:n,kind:`deferred-loading`});return}let r=ji(n,{pages:l,folderPaths:o,pagesBySlug:u,pagesByBasename:d});if(r.kind===`missing`&&/\/+$/.test(n.trim())){b(`ok/nav/hash-change`,{docName:n,kind:`deferred-missing-folder`});return}let a=Yr(Kr(r),c);b(`ok/nav/hash-change`,{docName:n,kind:a.kind}),i(a)}return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},v=[t,o,s,i,c,l,u,d],e[13]=t,e[14]=o,e[15]=s,e[16]=i,e[17]=c,e[18]=l,e[19]=d,e[20]=u,e[21]=_,e[22]=v):(_=e[21],v=e[22]),(0,Q.useEffect)(_,v),null}function cW(){let e=(0,$.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],(0,Q.useEffect)(lW,t),null}function lW(){let e=fW;if(!e(window.location.hash))return;let t=new AbortController;return _e(t.signal).then(n=>{if(t.signal.aborted||n.status!==`ok`)return;let r=n.config.paneTarget;r?.startsWith(`#/`)&&e(window.location.hash)&&(window.location.hash=r,fetch(`/api/config`,{method:`DELETE`}).catch(dW))}).catch(uW),()=>t.abort()}function uW(){}function dW(){}function fW(e){return!aW(e)&&!Hn(e)&&!yr(e)&&(e===``||e===`#`||e===`#/`)}function pW(){let e=(0,$.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[0]=t):t=e[0],(0,Q.useEffect)(mW,t),null}function mW(){let e=function(e){let t=e.target;lh({target:t,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,key:e.key})&&(e.preventDefault(),window.location.hash!==`#settings`&&(window.location.hash=ch))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}function hW(){let e=(0,$.c)(4),{activeTarget:t}=pt(),n=typeof window<`u`?window.okDesktop??null:null,r=t?.kind===`doc`||t?.kind===`folder`||t?.kind===`asset`?t.kind:null,i=t?.kind===`doc`?t.docName:t?.kind===`folder`?t.folderPath:t?.kind===`asset`?t.assetPath:null,a,o;return e[0]!==i||e[1]!==r?(a=()=>{if(n){if(r===null){n.editor.notifyActiveTargetChanged({kind:null});return}i!==null&&n.editor.notifyActiveTargetChanged({kind:r,identifier:i})}},o=[n,r,i],e[0]=i,e[1]=r,e[2]=a,e[3]=o):(a=e[2],o=e[3]),(0,Q.useEffect)(a,o),null}function gW(){let e=(0,$.c)(8),{activeDocName:t,activeTarget:n}=pt(),[r,i]=(0,Q.useState)(!1),a;e[0]!==t||e[1]!==n?(a=n?.kind===`folder`?n.folderPath:qr(t),e[0]=t,e[1]=n,e[2]=a):a=e[2];let o=a,s,c;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>{let e=function(e){let t=e.target;Dm({target:t,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,key:e.key})&&(e.preventDefault(),i(!0))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},c=[],e[3]=s,e[4]=c):(s=e[3],c=e[4]),(0,Q.useEffect)(s,c);let l;return e[5]!==r||e[6]!==o?(l=(0,Z.jsx)(km,{open:r,onOpenChange:i,kind:`file`,initialDir:o}),e[5]=r,e[6]=o,e[7]=l):l=e[7],l}function _W(){let e=(0,$.c)(18),t=typeof window<`u`?window.okDesktop??null:null,n=typeof window<`u`&&window.okDesktop!=null,[r,i]=(0,Q.useState)(!1),a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(Og,{}),e[0]=a):a=e[0];let o,s,c,l,u,d,f,p,m,h;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Z.jsx)(ZU,{}),c=(0,Z.jsx)(sW,{}),l=(0,Z.jsx)(cW,{}),u=(0,Z.jsx)(hW,{}),d=(0,Z.jsx)(gW,{}),f=(0,Z.jsx)(pW,{}),p=!1,m=t?(0,Z.jsx)(kg,{bridge:t}):null,h=(0,Z.jsx)(Md,{}),s=t?(0,Z.jsx)(WU,{bridge:t}):null,e[1]=o,e[2]=s,e[3]=c,e[4]=l,e[5]=u,e[6]=d,e[7]=f,e[8]=p,e[9]=m,e[10]=h):(o=e[1],s=e[2],c=e[3],l=e[4],u=e[5],d=e[6],f=e[7],p=e[8],m=e[9],h=e[10]);let g;e[11]===r?g=e[12]:(g=(0,Z.jsx)(bg,{bridge:t,open:r,onOpenChange:i}),e[11]=r,e[12]=g);let _;e[13]===Symbol.for(`react.memo_cache_sentinel`)?(_=n&&(0,Z.jsx)(`div`,{"aria-hidden":`true`,"data-testid":`editor-window-chrome-drag-strip`,"data-electron-drag":``,className:`pointer-events-none fixed inset-x-0 top-0 z-50 h-2 [-webkit-app-region:drag]`}),e[13]=_):_=e[13];let v;e[14]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Z.jsx)(jU,{onOpenSearch:()=>i(!0)}),e[14]=v):v=e[14];let y;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,Z.jsxs)(LD,{className:`h-screen overflow-hidden`,children:[v,(0,Z.jsx)(UD,{className:`overflow-hidden h-[calc(100vh-var(--layout-inset-offset))]`,children:(0,Z.jsx)(bA,{onOpenSearch:()=>i(!0)})})]}),e[15]=y):y=e[15];let b;return e[16]===g?b=e[17]:(b=(0,Z.jsx)(x,{name:`app`,children:(0,Z.jsx)(Pt,{children:(0,Z.jsxs)(Lt,{children:[a,(0,Z.jsxs)(yi,{children:[o,c,l,u,d,f,p,m,h,s,g,_,y]})]})})}),e[16]=g,e[17]=b),b}gc(),pf({apiOrigin:typeof window<`u`?window.okDesktop?.config.apiOrigin:void 0}),Ef(),ep()&&op(),Fp(),typeof window<`u`&&Of({bridge:window.okDesktop}),typeof window<`u`&&Vf({bridge:window.okDesktop}),typeof window<`u`&&As({bridge:window.okDesktop}),typeof window<`u`&&Es({bridge:window.okDesktop}),typeof window<`u`&&jf({bridge:window.okDesktop}),typeof window<`u`&&Gd({bridge:window.okDesktop});var vW=new Tc({defaultOptions:{queries:{retry:1,staleTime:1e4}}}),yW=document.getElementById(`root`);if(!yW)throw Error(`Root element not found`);var bW=typeof window<`u`&&window.okDesktop?.config.mode===`navigator`;(0,Fc.createRoot)(yW).render((0,Z.jsx)(Q.StrictMode,{children:(0,Z.jsx)(a,{i18n:lr,children:(0,Z.jsx)(yn,{client:vW,children:(0,Z.jsxs)(Rr,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,disableTransitionOnChange:!0,storageKey:`ok-theme-v1`,children:[(0,Z.jsx)(fr,{children:bW&&window.okDesktop?(0,Z.jsx)(of,{bridge:window.okDesktop}):(0,Z.jsx)(_W,{})}),(0,Z.jsx)(df,{richColors:!0,closeButton:!0})]})})})}));
@@ -48,7 +48,7 @@
48
48
  -->
49
49
  <script>(() => { let t = 'system'; try { const r = localStorage.getItem('ok-theme-v1'); if (r === 'light' || r === 'dark' || r === 'system') t = r; } catch {} let dark = t === 'dark'; if (t === 'system') { try { dark = window.matchMedia('(prefers-color-scheme: dark)').matches; } catch {} } if (dark) document.documentElement.classList.add('dark'); if (window.okDesktop) document.documentElement.classList.add('electron-mode'); })();</script>
50
50
  <style>html { background-color: #fafafa } html.dark { background-color: #171717 }</style>
51
- <script type="module" crossorigin src="./assets/index-C1LyLfKJ.js"></script>
51
+ <script type="module" crossorigin src="./assets/index-BfBcR9P5.js"></script>
52
52
  <link rel="modulepreload" crossorigin href="./assets/chunk-CFjPhJqf.js">
53
53
  <link rel="modulepreload" crossorigin href="./assets/preload-helper-2ej06EnG.js">
54
54
  <link rel="modulepreload" crossorigin href="./assets/w3c-keyname-B5t0fahT.js">
@@ -1,2 +1,2 @@
1
- import{h as e,n as t}from"./init-BjjtQpJ4.mjs";import{t as n}from"./is-object-C-4FJ0rP.mjs";import{join as r}from"node:path";import{existsSync as i,readFileSync as a}from"node:fs";const o=[[`@inkeep/open-knowledge`,`ui`],[`-y`,`@inkeep/open-knowledge`,`ui`],t];function s(e){if(e.runtimeExecutable===`/bin/sh`&&Array.isArray(e.runtimeArgs)){let t=e.runtimeArgs[2];if(typeof t==`string`){if(t.includes(`# ok-ui-v1`))return`canonical`;if(/# ok-ui-v\d+/.test(t))return`legacy-bare`}return`preserved`}if(e.runtimeExecutable===`npx`&&Array.isArray(e.runtimeArgs)){for(let t of o)if(c(e.runtimeArgs,t))return`legacy-bare`}return`preserved`}function c(e,t){if(e.length!==t.length)return!1;for(let n=0;n<t.length;n++)if(e[n]!==t[n])return!1;return!0}function l(t){let o=t.logger??u,c=r(t.projectDir,`.claude`,`launch.json`);if(t.reclaimDisableEnv===`1`)return o({event:`launch-json-repair-skipped`,reason:`reclaim-disabled`}),{outcome:{configPath:c,outcome:`skipped-reclaim-disabled`},repairedCount:0};if(!i(c))return{outcome:{configPath:c,outcome:`no-file`},repairedCount:0};let l;try{let e=a(c,`utf-8`).trim();l=e?JSON.parse(e):{}}catch(e){let t=e instanceof Error?e.message:String(e);return o({event:`launch-json-repair-read-failed`,configPath:c,error:t}),{outcome:{configPath:c,outcome:`read-failed`,error:t},repairedCount:0}}if(!n(l)){let e=`launch.json root is not an object`;return o({event:`launch-json-repair-read-failed`,configPath:c,error:e}),{outcome:{configPath:c,outcome:`read-failed`,error:e},repairedCount:0}}let d=l.configurations;if(!Array.isArray(d))return{outcome:{configPath:c,outcome:`no-entry`},repairedCount:0};let f=d.find(e=>n(e)&&e.name===`open-knowledge-ui`);if(!f)return{outcome:{configPath:c,outcome:`no-entry`},repairedCount:0};let p=s(f);if(p===`canonical`)return{outcome:{configPath:c,outcome:`canonical`},repairedCount:0};if(p===`preserved`)return{outcome:{configPath:c,outcome:`preserved`},repairedCount:0};let m=e(t.projectDir,{mode:`published`});if(m.action===`failed`){let e=m.error??`unknown write failure`;return o({event:`launch-json-repair-write-failed`,configPath:c,error:e}),{outcome:{configPath:c,outcome:`write-failed`,error:e},repairedCount:0}}return o({event:`launch-json-repair-applied`,configPath:c}),{outcome:{configPath:c,outcome:`repaired`},repairedCount:1}}function u(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{l as repairLaunchJson};
2
- //# sourceMappingURL=repair-launch-json-CBHiWTWu.mjs.map
1
+ import{h as e,n as t}from"./init-Ctu92Awt.mjs";import{t as n}from"./is-object-C-4FJ0rP.mjs";import{join as r}from"node:path";import{existsSync as i,readFileSync as a}from"node:fs";const o=[[`@inkeep/open-knowledge`,`ui`],[`-y`,`@inkeep/open-knowledge`,`ui`],t];function s(e){if(e.runtimeExecutable===`/bin/sh`&&Array.isArray(e.runtimeArgs)){let t=e.runtimeArgs[2];if(typeof t==`string`){if(t.includes(`# ok-ui-v1`))return`canonical`;if(/# ok-ui-v\d+/.test(t))return`legacy-bare`}return`preserved`}if(e.runtimeExecutable===`npx`&&Array.isArray(e.runtimeArgs)){for(let t of o)if(c(e.runtimeArgs,t))return`legacy-bare`}return`preserved`}function c(e,t){if(e.length!==t.length)return!1;for(let n=0;n<t.length;n++)if(e[n]!==t[n])return!1;return!0}function l(t){let o=t.logger??u,c=r(t.projectDir,`.claude`,`launch.json`);if(t.reclaimDisableEnv===`1`)return o({event:`launch-json-repair-skipped`,reason:`reclaim-disabled`}),{outcome:{configPath:c,outcome:`skipped-reclaim-disabled`},repairedCount:0};if(!i(c))return{outcome:{configPath:c,outcome:`no-file`},repairedCount:0};let l;try{let e=a(c,`utf-8`).trim();l=e?JSON.parse(e):{}}catch(e){let t=e instanceof Error?e.message:String(e);return o({event:`launch-json-repair-read-failed`,configPath:c,error:t}),{outcome:{configPath:c,outcome:`read-failed`,error:t},repairedCount:0}}if(!n(l)){let e=`launch.json root is not an object`;return o({event:`launch-json-repair-read-failed`,configPath:c,error:e}),{outcome:{configPath:c,outcome:`read-failed`,error:e},repairedCount:0}}let d=l.configurations;if(!Array.isArray(d))return{outcome:{configPath:c,outcome:`no-entry`},repairedCount:0};let f=d.find(e=>n(e)&&e.name===`open-knowledge-ui`);if(!f)return{outcome:{configPath:c,outcome:`no-entry`},repairedCount:0};let p=s(f);if(p===`canonical`)return{outcome:{configPath:c,outcome:`canonical`},repairedCount:0};if(p===`preserved`)return{outcome:{configPath:c,outcome:`preserved`},repairedCount:0};let m=e(t.projectDir,{mode:`published`});if(m.action===`failed`){let e=m.error??`unknown write failure`;return o({event:`launch-json-repair-write-failed`,configPath:c,error:e}),{outcome:{configPath:c,outcome:`write-failed`,error:e},repairedCount:0}}return o({event:`launch-json-repair-applied`,configPath:c}),{outcome:{configPath:c,outcome:`repaired`},repairedCount:1}}function u(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{l as repairLaunchJson};
2
+ //# sourceMappingURL=repair-launch-json-dWYTCWls.mjs.map
@@ -1,2 +1,2 @@
1
- import{D as e,d as t,g as n,j as r,k as i}from"./init-BjjtQpJ4.mjs";import{t as a}from"./mcp-migrate-event-BF8ILHwp.mjs";import{homedir as o}from"node:os";function s(t){let n=t.logger??u,r=t.home??o(),a=[];if(t.reclaimDisableEnv===`1`)return n({event:`mcp-config-repair-skipped`,reason:`reclaim-disabled`}),{outcomes:a,repairedCount:0};for(let o of e){let e=i[o],s=c(()=>e.configPath(``,r));if(s!==null&&a.push(l({scope:`user`,editorId:o,target:e,home:r,cwd:``,configPath:s,configPathOverride:void 0,logger:n})),e.projectConfigPath){let r=e.projectConfigPath,i=c(()=>r(t.projectDir));i!==null&&a.push(l({scope:`project`,editorId:o,target:e,home:void 0,cwd:t.projectDir,configPath:i,configPathOverride:i,logger:n}))}}return{outcomes:a,repairedCount:a.filter(e=>e.outcome===`repaired`).length}}function c(e){try{return e()}catch{return null}}function l(e){let i={scope:e.scope,editorId:e.editorId,configPath:e.configPath},o=t(e.target,e.cwd,e.home,e.configPathOverride);if(o===null)return{...i,outcome:`no-entry`};if(r(o))return{...i,outcome:`canonical`};e.logger(a({scope:e.scope,surface:`cli-repair`,editorId:e.editorId,configPath:e.configPath,priorEntry:o}));let s=n(e.target,e.cwd,{mode:`published`,skipAvailabilityCheck:!0},e.home,e.configPathOverride);if(s.action===`failed`){let t=s.error??`unknown write failure`;return e.logger({event:`mcp-config-repair-write-failed`,scope:e.scope,editorId:e.editorId,configPath:e.configPath,error:t}),{...i,outcome:`write-failed`,error:t}}return{...i,outcome:`repaired`}}function u(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{s as repairMcpConfigs};
2
- //# sourceMappingURL=repair-mcp-configs-s94bDnZZ.mjs.map
1
+ import{D as e,d as t,g as n,j as r,k as i}from"./init-Ctu92Awt.mjs";import{t as a}from"./mcp-migrate-event-BF8ILHwp.mjs";import{homedir as o}from"node:os";function s(t){let n=t.logger??u,r=t.home??o(),a=[];if(t.reclaimDisableEnv===`1`)return n({event:`mcp-config-repair-skipped`,reason:`reclaim-disabled`}),{outcomes:a,repairedCount:0};for(let o of e){let e=i[o],s=c(()=>e.configPath(``,r));if(s!==null&&a.push(l({scope:`user`,editorId:o,target:e,home:r,cwd:``,configPath:s,configPathOverride:void 0,logger:n})),e.projectConfigPath){let r=e.projectConfigPath,i=c(()=>r(t.projectDir));i!==null&&a.push(l({scope:`project`,editorId:o,target:e,home:void 0,cwd:t.projectDir,configPath:i,configPathOverride:i,logger:n}))}}return{outcomes:a,repairedCount:a.filter(e=>e.outcome===`repaired`).length}}function c(e){try{return e()}catch{return null}}function l(e){let i={scope:e.scope,editorId:e.editorId,configPath:e.configPath},o=t(e.target,e.cwd,e.home,e.configPathOverride);if(o===null)return{...i,outcome:`no-entry`};if(r(o))return{...i,outcome:`canonical`};e.logger(a({scope:e.scope,surface:`cli-repair`,editorId:e.editorId,configPath:e.configPath,priorEntry:o}));let s=n(e.target,e.cwd,{mode:`published`,skipAvailabilityCheck:!0},e.home,e.configPathOverride);if(s.action===`failed`){let t=s.error??`unknown write failure`;return e.logger({event:`mcp-config-repair-write-failed`,scope:e.scope,editorId:e.editorId,configPath:e.configPath,error:t}),{...i,outcome:`write-failed`,error:t}}return{...i,outcome:`repaired`}}function u(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{s as repairMcpConfigs};
2
+ //# sourceMappingURL=repair-mcp-configs-zqCKhtNX.mjs.map
@@ -1,7 +1,7 @@
1
- import{o as e}from"./chunk-FK9Q3tQk.mjs";import{t}from"./esm-CEs3LWY3.mjs";import{c as n,l as r,s as i}from"./server-lock-BpjJj3OD-2pOoEhSP.mjs";import"./gh-detect-BveVRAue.mjs";import{g as a,h as o,k as s}from"./init-BjjtQpJ4.mjs";import{Sr as c}from"./dist-sld-_d9T.mjs";import"./loader-BSyhsuGY.mjs";import{c as l}from"./colors-BtKMHmBX.mjs";import"./preview-C6kOnHJr.mjs";import{n as u}from"./write-project-skill-ppRYJ9T2.mjs";import{spawnSync as d}from"node:child_process";import{basename as f,dirname as p,isAbsolute as m,join as h,relative as ee,resolve as g}from"node:path";import{existsSync as _,lstatSync as te,readFileSync as v,readdirSync as y,statSync as b}from"node:fs";import{hostname as x}from"node:os";import{readFile as S,realpath as C}from"node:fs/promises";function w(e,t,a={}){let o=r(e,t);if(!_(o))return{status:`missing`,lockPath:o};let s;try{s=JSON.parse(v(o,`utf-8`))}catch{return{status:`corrupt`,lockPath:o}}if(!s||typeof s!=`object`||!n(s.pid))return{status:`corrupt`,lockPath:o};let c=s;if(!(a.isAlive??i)(c.pid))return{status:`dead-pid`,lockPath:o,lock:c};let l=a.host??x();return c.hostname===l?{status:`alive`,lockPath:o,lock:c}:{status:`foreign-host`,lockPath:o,lock:c}}function T(e){return e.replace(/:\d+$/,``)}function E(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:T(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[\w.-]+@)?([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:T(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:T(e[1]),owner:e[2],name:e[3]}}{let e=/^(?:[\w.-]+@)?([\w.-]+):([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e?.[1].includes(`.`)||e&&t.startsWith(`git@`))return{protocol:`ssh`,hostname:e[1],owner:e[2],name:e[3]}}{let e=/^git:([\w.-]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:e[1],owner:e[2],name:e[3]}}if(!t.includes(`://`)&&!t.includes(`@`)&&!t.startsWith(`/`)){let e=/^([\w.-]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e)return{protocol:`https`,hostname:`github.com`,owner:e[1],name:e[2]}}return null}function D(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`).filter(e=>e.length>0);if(n.length<5||n[2]!==`blob`)return null;let r,i,a,o;try{r=decodeURIComponent(n[0]),i=decodeURIComponent(n[1]),a=decodeURIComponent(n[3]),o=n.slice(4).map(e=>decodeURIComponent(e))}catch{return null}return!r||!i||!a||o.length===0||o.some(e=>e.length===0)?null:{owner:r,repo:i,branch:a,path:o.join(`/`)}}function O(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`);if(n.length<5||n[0]!==``||n[3]!==`tree`)return null;let r=n.slice(5);r.length===1&&r[0]===``&&r.pop();let i,a,o,s;try{i=decodeURIComponent(n[1]),a=decodeURIComponent(n[2]),o=decodeURIComponent(n[4]),s=r.map(e=>decodeURIComponent(e))}catch{return null}return!i||!a||!o||s.some(e=>e.length===0)?null:{owner:i,repo:a,branch:o,path:s.join(`/`)}}function k(e){let t=D(e);if(t)return{kind:`doc`,...t};let n=O(e);return n?{kind:`folder`,...n}:null}const A=2e3,j=2e3,ne=[/cli\.mjs/,/(^|[\s/])(open-knowledge|ok)\s+(start|mcp|ui)(\s|$)/,/Open Knowledge(?:\.app| Helper)/,/(^|[\s/])bun([\s/]).*?(run dev|packages\/app|vite|hocuspocus)/,/(^|[\s/])node([\s/]).*?(packages\/(cli|app)|vite|hocuspocus)/,/(^|\s)--ok-lock-dir-b64=/,/(^|\s)--ok-project-path=/];function M(e){return ne.some(t=>t.test(e))}function re(e){let t=e.trim().split(/\s+/).find(e=>e.startsWith(`--ok-lock-dir-b64=`));if(t==null)return null;let n=t.slice(18);if(!n)return null;try{let e=Buffer.from(n,`base64url`).toString(`utf8`);return m(e)?e:null}catch{return null}}function ie(e){let t=e.indexOf(`--ok-project-path=`);if(t===-1)return null;let n=t+18,r=e.slice(n),i=r.search(/\s--/),a=(i===-1?r:r.slice(0,i)).trim();return a&&m(a)?a:null}function ae(e){let t=[];for(let n of e.split(`
1
+ import{o as e}from"./chunk-FK9Q3tQk.mjs";import{t}from"./esm-CEs3LWY3.mjs";import{c as n,l as r,s as i}from"./server-lock-BpjJj3OD-2pOoEhSP.mjs";import"./gh-detect-BveVRAue.mjs";import{g as a,h as o,k as s}from"./init-Ctu92Awt.mjs";import{Sr as c}from"./dist-sld-_d9T.mjs";import"./loader-DLF6I7F7.mjs";import{c as l}from"./colors-BtKMHmBX.mjs";import"./preview-BiAC5DG4.mjs";import{n as u}from"./write-project-skill-ppRYJ9T2.mjs";import{spawnSync as d}from"node:child_process";import{basename as f,dirname as p,isAbsolute as m,join as h,relative as ee,resolve as g}from"node:path";import{existsSync as _,lstatSync as te,readFileSync as v,readdirSync as y,statSync as b}from"node:fs";import{hostname as x}from"node:os";import{readFile as S,realpath as C}from"node:fs/promises";function w(e,t,a={}){let o=r(e,t);if(!_(o))return{status:`missing`,lockPath:o};let s;try{s=JSON.parse(v(o,`utf-8`))}catch{return{status:`corrupt`,lockPath:o}}if(!s||typeof s!=`object`||!n(s.pid))return{status:`corrupt`,lockPath:o};let c=s;if(!(a.isAlive??i)(c.pid))return{status:`dead-pid`,lockPath:o,lock:c};let l=a.host??x();return c.hostname===l?{status:`alive`,lockPath:o,lock:c}:{status:`foreign-host`,lockPath:o,lock:c}}function T(e){return e.replace(/:\d+$/,``)}function E(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:T(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[\w.-]+@)?([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:T(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:T(e[1]),owner:e[2],name:e[3]}}{let e=/^(?:[\w.-]+@)?([\w.-]+):([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e?.[1].includes(`.`)||e&&t.startsWith(`git@`))return{protocol:`ssh`,hostname:e[1],owner:e[2],name:e[3]}}{let e=/^git:([\w.-]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:e[1],owner:e[2],name:e[3]}}if(!t.includes(`://`)&&!t.includes(`@`)&&!t.startsWith(`/`)){let e=/^([\w.-]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e)return{protocol:`https`,hostname:`github.com`,owner:e[1],name:e[2]}}return null}function D(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`).filter(e=>e.length>0);if(n.length<5||n[2]!==`blob`)return null;let r,i,a,o;try{r=decodeURIComponent(n[0]),i=decodeURIComponent(n[1]),a=decodeURIComponent(n[3]),o=n.slice(4).map(e=>decodeURIComponent(e))}catch{return null}return!r||!i||!a||o.length===0||o.some(e=>e.length===0)?null:{owner:r,repo:i,branch:a,path:o.join(`/`)}}function O(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`);if(n.length<5||n[0]!==``||n[3]!==`tree`)return null;let r=n.slice(5);r.length===1&&r[0]===``&&r.pop();let i,a,o,s;try{i=decodeURIComponent(n[1]),a=decodeURIComponent(n[2]),o=decodeURIComponent(n[4]),s=r.map(e=>decodeURIComponent(e))}catch{return null}return!i||!a||!o||s.some(e=>e.length===0)?null:{owner:i,repo:a,branch:o,path:s.join(`/`)}}function k(e){let t=D(e);if(t)return{kind:`doc`,...t};let n=O(e);return n?{kind:`folder`,...n}:null}const A=2e3,j=2e3,ne=[/cli\.mjs/,/(^|[\s/])(open-knowledge|ok)\s+(start|mcp|ui)(\s|$)/,/Open Knowledge(?:\.app| Helper)/,/(^|[\s/])bun([\s/]).*?(run dev|packages\/app|vite|hocuspocus)/,/(^|[\s/])node([\s/]).*?(packages\/(cli|app)|vite|hocuspocus)/,/(^|\s)--ok-lock-dir-b64=/,/(^|\s)--ok-project-path=/];function M(e){return ne.some(t=>t.test(e))}function re(e){let t=e.trim().split(/\s+/).find(e=>e.startsWith(`--ok-lock-dir-b64=`));if(t==null)return null;let n=t.slice(18);if(!n)return null;try{let e=Buffer.from(n,`base64url`).toString(`utf8`);return m(e)?e:null}catch{return null}}function ie(e){let t=e.indexOf(`--ok-project-path=`);if(t===-1)return null;let n=t+18,r=e.slice(n),i=r.search(/\s--/),a=(i===-1?r:r.slice(0,i)).trim();return a&&m(a)?a:null}function ae(e){let t=[];for(let n of e.split(`
2
2
  `)){let e=n.trim();if(!e)continue;let r=e.indexOf(` `);if(r===-1)continue;let i=e.slice(0,r),a=e.slice(r+1),o=Number.parseInt(i,10);!Number.isNaN(o)&&M(a)&&t.push({pid:o,command:a})}return t}function oe(e){let t=[],n=e.split(`
3
3
  `);for(let e=1;e<n.length;e++){let r=n[e]?.trim();if(!r)continue;let i=r.indexOf(` `);if(i===-1)continue;let a=r.slice(0,i),o=r.slice(i+1).trim(),s=Number.parseInt(a,10);!Number.isNaN(s)&&M(o)&&t.push({pid:s,command:o})}return t}async function se(){let e=d(`pgrep`,[`-a`,`-f`,`cli\\.mjs|open-knowledge|Open Knowledge(\\.app| Helper)|--ok-lock-dir-b64=|--ok-project-path=|(^|[ /])ok[ ]+(start|mcp|ui)([ ]|$)|packages/(cli|app)|hocuspocus|vite`],{encoding:`utf-8`,timeout:A});if(!(e.error!=null&&e.error.code===`ENOENT`)){let t=e.stdout??``,n=ae(t);if(n.length>0||t.trim()===``)return n}let t=d(`ps`,[`-axo`,`pid,command`],{encoding:`utf-8`,timeout:A});return t.error!=null||!t.stdout?[]:oe(t.stdout)}function ce(e){let t=e.trim().split(/\s+/).filter(Boolean);for(let e of t){if(e.startsWith(`@`))continue;let t=f(e);if(t===`open-knowledge`||t===`ok`||e.endsWith(`/packages/cli/src/cli.ts`)||e.endsWith(`/packages/cli/dist/cli.mjs`)||t===`cli.mjs`||t===`cli.ts`)return e}return null}function N(e){let t=d(`ps`,[`-p`,String(e),`-o`,`command=`],{encoding:`utf-8`,timeout:A});return t.error!=null||!t.stdout?null:t.stdout.trim()||null}function P(e){let t=d(`ps`,[`-p`,String(e),`-o`,`%cpu=,%mem=`],{encoding:`utf-8`,timeout:A});if(t.error!=null||!t.stdout)return null;let[n,r]=t.stdout.trim().split(/\s+/),i=Number.parseFloat(n??``),a=Number.parseFloat(r??``);return Number.isNaN(i)||Number.isNaN(a)?null:{cpuPercent:i,memPercent:a}}async function F(e){let t=d(`lsof`,[`-p`,String(e),`-a`,`-d`,`cwd`,`-Fn`],{encoding:`utf-8`,timeout:A});if(t.error!=null)return null;let n=t.stdout??``;for(let e of n.split(`
4
4
  `))if(e.startsWith(`n`)&&e.length>1)return e.slice(1);return null}function I(e){let t=[],n=e.split(`
5
5
  `);for(let e=1;e<n.length;e++){let r=n[e]?.trim();if(!r)continue;let i=r.split(/\s+/);if(i.length<2)continue;let a=Number.parseInt(i[1]??``,10);Number.isNaN(a)||t.push(a)}return[...new Set(t)]}function L(e){return _(h(e,`server.lock`))||_(h(e,`ui.lock`))}function R(e,t){for(let n of[h(t,`.ok`,`local`),h(t,`.ok`)])_(n)&&L(n)&&e.add(n)}function z(e,t){let n=0,r=(t,i)=>{if(n>=j||(n++,R(e,t),i>=3))return;let a;try{a=y(t)}catch{return}for(let e of a){if(n>=j)return;if(e===`node_modules`||e===`.git`||e===`Library`||e.startsWith(`.`)&&e!==`.ok`)continue;let a=h(t,e),o=!1;try{o=te(a).isDirectory()}catch{continue}o&&r(a,i+1)}};r(t,0)}async function B(){let e=new Set,t=await se(),n=t.map(e=>F(e.pid)),r=await Promise.all(n);for(let n of t){let t=re(n.command);t!=null&&_(t)&&e.add(t);let r=ie(n.command);r!=null&&R(e,r)}for(let t of r)t!=null&&R(e,t);let i=d(`lsof`,[`-iTCP`,`-sTCP:LISTEN`,`-nP`],{encoding:`utf-8`,timeout:A});if(i.error==null&&i.stdout){let n=I(i.stdout),r=new Set(t.map(e=>e.pid)),a=n.filter(e=>!r.has(e)).map(e=>F(e)),o=await Promise.all(a);for(let t of o)t!=null&&R(e,t)}(e.size===0||r.some(e=>e===`/`))&&z(e,process.cwd());let a=new Map;for(let t of e)try{let e=await C(t);a.set(e,e)}catch{a.set(t,t)}return[...a.values()]}var V=e(l(),1);function H(e){return e==null?!1:e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function U(e,t=Date.now()){let n=new Date(e).getTime();if(Number.isNaN(n))return`—`;let r=t-n,i=Math.floor(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60);if(a<60)return`${a}m ago`;let o=Math.floor(a/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}function W(e,t,n,r,i,a){if(t.status===`missing`||t.status===`corrupt`)return null;let o=t.lock,s=null;if(n.status!==`missing`&&n.status!==`corrupt`){let e=n.lock;s={port:e.port,status:n.status,pid:e.pid,startedAt:e.startedAt,usage:a}}return{directory:o.worktreeRoot,server:{port:o.port,status:t.status,pid:o.pid,startedAt:o.startedAt,usage:i},ui:s,hostname:o.hostname,lockPath:t.lockPath,binary:r==null?null:ce(r),command:r,isDesktop:H(r)}}function G(e){return e.ui==null?!1:e.ui.status===`alive`||e.ui.status===`foreign-host`}function K(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:t===`dead-pid`&&G(e)?`ui-orphan`:`stale`}const le=new Set([`running`,`desktop`,`foreign`,`ui-orphan`]);function ue(e){switch(e){case`running`:return V.default.green(e);case`desktop`:return V.default.blue(e);case`foreign`:return V.default.cyan(e);case`ui-orphan`:return V.default.magenta(e);case`stale`:return V.default.yellow(e)}}function q(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function de(e){return`${q(e.server.usage)} | ${q(e.ui?.usage??null)}`}function fe(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null||e.ui.status===`dead-pid`?`—`:String(e.ui.port)}`}function pe(e){if(e.length===0)return`No open-knowledge servers found.`;let t=[`DIRECTORY`,`PORTS (API/UI)`,`CPU/MEM (API | UI)`,`STATUS`,`PID`,`STARTED`,`BINARY`],n=e.map(e=>{let t=K(e),n=t===`ui-orphan`&&e.ui!=null?e.ui.pid:e.server.pid;return[e.directory,fe(e),de(e),t,String(n),U(e.server.startedAt),e.binary??`—`]}),r=t.length,i=t.map(e=>e.length);for(let e of n)for(let t=0;t<r;t++)i[t]=Math.max(i[t]??0,(e[t]??``).length);let a=t.map((e,t)=>e.padEnd(i[t]??0)).join(` `).trimEnd(),o=e.map((e,t)=>{let a=n[t]??[],o=[];for(let t=0;t<r;t++){let n=(a[t]??``).padEnd(i[t]??0);if(t===3){let r=a[t]??``;n=ue(K(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=V.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
6
6
  `)}async function J(e={}){let t=e.discover??B,n=e.inspect??w,r=e.log??(e=>console.log(e)),i=e.resolveCommand??N,a=e.resolveUsage??P,o=await t(),s=[];for(let e of o){let t=n(e,`server`),r=n(e,`ui`),o=W(e,t,r,t.status===`missing`||t.status===`corrupt`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`?null:a(t.lock.pid),r.status===`missing`||r.status===`corrupt`?null:a(r.lock.pid));o!=null&&s.push(o)}if(e.json){let e=s.map(e=>({...e,displayStatus:K(e)}));r(JSON.stringify(e,null,2));return}r(pe(e.all?s:s.filter(e=>le.has(K(e)))))}function me(){return new t(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale (dead-pid) entries (foreign-host shows by default)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await J({all:t.all===!0||e===`all`,json:t.json===!0})})}function he(e,t,n={}){let r=n.isAlive??i,a=[];for(let[n,i]of[[`server`,e],[`ui`,t]])(i.status===`alive`||i.status===`foreign-host`&&r(i.lock.pid))&&a.push({name:n,pid:i.lock.pid,port:i.lock.port});return{targets:a}}function Y(e){let t=e.inspect??(t=>w(e.lockDir,t)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=he(t(`server`),t(`ui`),{isAlive:e.isAlive});if(a.targets.length===0)return r(`No running open-knowledge processes.`),{stopped:[],failed:[],hadTargets:!1};let o=[],s=[];for(let e of a.targets)try{n(e.pid,`SIGTERM`),o.push(e)}catch(t){s.push({target:e,error:t instanceof Error?t.message:String(t)})}return o.length>0&&r(`Stopped: ${o.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `)}`),s.length>0&&i(`Failed to stop: ${s.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `)}`),{stopped:o,failed:s,hadTargets:!0}}function X(e,t){return e.status===`alive`?!0:e.status===`foreign-host`?t(e.lock.pid):!1}async function Z(e,t=i){let n=await B(),r=null;for(let i of n){let n=w(i,`server`),a=w(i,`ui`);if(X(n,t)&&n.lock.port===e||X(a,t)&&a.lock.port===e)return i;r===null&&(X(n,t)&&n.lock.pid===e||X(a,t)&&a.lock.pid===e)&&(r=i)}return r}function Q(e){let t=Y({lockDir:e});return t.failed.length>0&&(process.exitCode=1),t}function ge(e){return new t(`stop`).description(`Stop open-knowledge server(s). With no argument: stops the server for the current directory. Pass a port number, a directory path, or "all" to target globally.`).argument(`[target...]`,`port number, directory path (spaces OK), or "all"`).action(async t=>{let n=t.length===0?void 0:t.join(` `);if(n===void 0){e();let t=Y({lockDir:c(process.cwd()),log:()=>{}});if(t.hadTargets){if(t.stopped.length>0){let e=t.stopped.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);console.log(`Stopped: ${e}`)}t.failed.length>0&&(process.exitCode=1)}else await J({});return}if(n===`all`){let e=await B();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let n of e){let e=w(n,`server`),r=w(n,`ui`);!X(e,i)&&!X(r,i)||(Q(n),t++)}t===0&&console.log(`No running open-knowledge servers found.`);return}if(/^\d+$/.test(n)){let e=Number.parseInt(n,10),t=await Z(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}Q(t);return}Q(c(n))})}async function _e(e,t){let n,r;try{n=await C(g(e)),r=await C(g(p(e)))}catch{return{kind:`not-git`}}if(!$(n,r))return{kind:`symlink-escape`};let i=h(n,`.git`),a;try{a=b(i)}catch{return{kind:`not-git`}}let o;if(a.isDirectory()){let e;try{e=await C(i)}catch{return{kind:`not-git`}}if(!$(e,n))return{kind:`symlink-escape`};o=e}else if(a.isFile()){let e;try{e=await S(i,`utf-8`)}catch{return{kind:`not-git`}}let t=/^gitdir:\s*(.+)$/m.exec(e.trim());if(!t)return{kind:`not-git`};let r=t[1].trim(),a=m(r)?r:g(n,r);try{o=await C(a)}catch{return{kind:`not-git`}}}else return{kind:`not-git`};let s=h(await ve(o),`config`),c;try{c=await S(s,`utf-8`)}catch{return{kind:`not-git`}}let l=be(c);if(l===null)return{kind:`no-origin`};let u=E(l);if(u===null||u.hostname!==`github.com`)return{kind:`non-github`};let d=u.owner.toLowerCase()===t.owner.toLowerCase(),f=u.name.toLowerCase()===t.repo.toLowerCase();return!d||!f?{kind:`wrong-repo`,actualOwner:u.owner,actualRepo:u.name}:{kind:`ok`,gitRemoteUrl:`https://github.com/${u.owner}/${u.name}.git`}}async function ve(e){let t;try{t=(await S(h(e,`commondir`),`utf-8`)).trim()}catch{return e}if(t.length===0)return e;let n=m(t)?t:g(e,t);try{return await C(n)}catch{return n}}function $(e,t){if(e===t)return!0;let n=ee(t,e);return n.length>0&&!n.startsWith(`..`)&&!m(n)}function ye(e){let t=e.indexOf(`#`),n=e.indexOf(`;`),r=-1;return t>=0&&n>=0?r=Math.min(t,n):t>=0?r=t:n>=0&&(r=n),(r===-1?e:e.slice(0,r)).trim()}function be(e){let t=!1;for(let n of e.split(/\r?\n/)){let e=ye(n);if(e.length===0)continue;if(e.startsWith(`[`)){t=/^\[\s*remote\s+["']origin["']\s*\]$/.test(e);continue}if(!t)continue;let r=/^url\s*=\s*(.+)$/.exec(e);if(r)return xe(r[1])}return null}function xe(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t}const Se=[{id:`mcp-config`,write(e,t,n){let r=e.projectConfigPath?.(t);if(!r)return{integration:`mcp-config`,editorId:e.id,action:`skipped-unsupported`};try{let i=a(e,t,n,void 0,r);return i.action===`written`||i.action===`overwritten`?{integration:`mcp-config`,editorId:e.id,action:i.action,path:i.configPath}:i.action===`failed`?{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:i.error??`unknown failure`}:{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:`unexpected project-scope action: ${i.action}`}}catch(t){return{integration:`mcp-config`,editorId:e.id,action:`failed`,path:r,error:t instanceof Error?t.message:String(t)}}}},{id:`project-skill`,write(e,t,n){try{let n=u(e,t);return{integration:`project-skill`,editorId:e.id,action:n.action,...n.path?{path:n.path}:{},...n.error?{error:n.error}:{}}}catch(t){return{integration:`project-skill`,editorId:e.id,action:`failed`,error:t instanceof Error?t.message:String(t)}}}}];function Ce(e,t,n={},r=Se){let i=[];for(let a of t){let t=s[a];for(let a of r)i.push(a.write(t,e,n))}return i}function we(e,t,n={}){return{integrations:Ce(e,t,n),claudeLaunchJson:t.includes(`claude`)?o(e,n):void 0}}export{me as a,P as c,O as d,E as f,ge as i,D as l,_e as n,B as o,w as p,Y as r,N as s,we as t,k as u};
7
- //# sourceMappingURL=src-B1QW6YWQ.mjs.map
7
+ //# sourceMappingURL=src-jN1tBoyd.mjs.map
@@ -0,0 +1 @@
1
+ import{h as e}from"./start-D474Z7JL.mjs";export{e as startCommand};
@@ -1,3 +1,3 @@
1
- import{n as e,t}from"./esm-CEs3LWY3.mjs";import{bn as n,pt as r}from"./server-lock-BpjJj3OD-2pOoEhSP.mjs";import{i,t as a}from"./gh-detect-BveVRAue.mjs";import{In as o}from"./dist-sld-_d9T.mjs";import{n as s}from"./constants-Dz5iTLUD.mjs";import{spawn as c}from"node:child_process";import{basename as l,dirname as u,join as d}from"node:path";import{closeSync as f,existsSync as p,mkdirSync as m,openSync as h,statSync as g}from"node:fs";import{homedir as _}from"node:os";import{setTimeout as v}from"node:timers/promises";const y=`Open Knowledge.app`,b=`/Applications/${y}`;function x(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return g(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function S(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}if(C(e,b))return b;let t=d(e.homeDir??_(),`Applications`,y);return C(e,t)?t:null}function C(e,t){try{let n=d(t,`Contents`,`MacOS`,`Open Knowledge`),r=e.statSync(n);return r&&typeof r.isFile==`function`?r.isFile():!1}catch{return!1}}function w(e){if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`};if(e.platform!==`darwin`)return{available:!1,reason:`darwin-only`};let t;try{t=S(e)}catch{return{available:!1,reason:`stat-error`}}return t?e.env.OK_FORCE_DESKTOP===`1`?{available:!0,reason:`available`,bundlePath:t}:e.isTTY!==!0||e.env.SSH_CONNECTION||e.env.SSH_TTY?{available:!1,reason:`headless`,bundlePath:t}:{available:!0,reason:`available`,bundlePath:t}:{available:!1,reason:`no-bundle`}}function T(e){(e.log??(e=>console.error(e)))("Launching Open Knowledge desktop (use `ok start` for the browser server, or `OK_FORCE_BROWSER=1` to always skip)");let t={...process.env};delete t.ELECTRON_RUN_AS_NODE,e.spawn(`open`,[`-b`,`com.inkeep.open-knowledge`],{detached:!0,stdio:`ignore`,env:t}).unref()}function E(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found at ${b}. Install via DMG, or omit --mode for browser mode.`;case`darwin-only`:return`Desktop app is macOS-only on this release. Use --mode=browser, or omit --mode for the server fallback.`;case`headless`:return`Desktop launch is gated in headless contexts (CI, SSH, non-TTY stdout). Set OK_FORCE_DESKTOP=1 to override, or use --mode=browser.`;case`force-browser`:return`OK_FORCE_BROWSER=1 is set — desktop dispatch is disabled. Unset it to use --mode=app.`;case`stat-error`:return`Failed to inspect desktop bundle at ${b} (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available at ${b} but launch dispatch did not fire (caller bug).`}}function D(e){return d(u(e),`..`,`Frameworks`,`Open Knowledge Server.app`,`Contents`,`MacOS`,`Open Knowledge Helper`)}const O=/\/[^/]+\.app\/Contents\/MacOS\/[^/]+$/;function k(e){if(e.platform!==`darwin`||!O.test(e.execPath))return null;let t=D(e.execPath);return e.exists(t)?t:null}function A(e={}){let t=e.execPath??process.execPath,n=e.platform??process.platform,r=e.argv??process.argv,i=e.exists??p,a=r[1];return a?{command:k({execPath:t,platform:n,exists:i})??t,prefixArgs:[a]}:(console.warn(`[self-spawn] process.argv[1] is empty — falling back to \`npx -y @inkeep/open-knowledge@latest\`. This re-introduces the registry-fetch surface that re-exec was fixing. Observed argv: ${JSON.stringify(r)}`),{command:`npx`,prefixArgs:[`-y`,`@inkeep/open-knowledge@latest`]})}function j(e,t){return e.host??t.HOST??`localhost`}function M(e){let t=l(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var N=class extends Error{cwd;constructor(e){super("This directory isn't set up yet. Run `ok init` first, then `ok start` again."),this.name=`OkDirMissingError`,this.cwd=e}};function P(e){return e.uiLock?e.isAlive(e.uiLock.pid)?{action:`skip`,reason:`alive`,pid:e.uiLock.pid,port:e.uiLock.port}:{action:`spawn`,reason:`stale`,stalePid:e.uiLock.pid}:{action:`spawn`,reason:`absent`}}function F(e){p(e.lockDir)||m(e.lockDir,{recursive:!0});let t=h(d(e.lockDir,n),`w`),r=e.spawn??c,{PORT:i,...a}=process.env,o=A();try{let n=r(o.command,[...o.prefixArgs,...e.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,t],cwd:e.cwd,env:{...a,ELECTRON_RUN_AS_NODE:`1`}});return n.unref(),n}finally{try{f(t)}catch{}}}function I(e,t,n){return e??(n===void 0?t:void 0)}function L(e,t){return e!==void 0&&t!==null&&t.port>0}function R(e,t,n){return e??(t!=null&&!n?1:0)}async function z(e){let t=e.spawn??c,n=A(),{PORT:r,...i}=process.env,a=t(n.command,[...n.prefixArgs,`ui`,`--port`,String(e.uiPort)],{cwd:e.cwd,stdio:`inherit`,env:{...i,ELECTRON_RUN_AS_NODE:`1`}}),o=!1,s=e=>{o=!0;try{a.kill(e)}catch{}},l=()=>s(`SIGINT`),u=()=>s(`SIGTERM`);process.once(`SIGINT`,l),process.once(`SIGTERM`,u),await new Promise(e=>{a.on(`exit`,(t,n)=>{process.exitCode=R(t,n,o),e()}),a.on(`error`,t=>{console.error(`[start] connect fallback: failed to spawn ok ui — ${t instanceof Error?t.message:String(t)}`),process.exitCode=1,e()})}),process.removeListener(`SIGINT`,l),process.removeListener(`SIGTERM`,u)}async function B(e){let t=e.now()+e.timeoutMs;for(;e.now()<t;){let t=e.readUiLock();if(t&&t.port>0)return t.port;await e.sleep(e.pollIntervalMs)}let n=e.readUiLock();return n&&n.port>0?n.port:null}const V=r;function H(e){let t=e.sigtermGraceMs??V,n=e.sigtermPollIntervalMs??200,r=e.sleep??(e=>v(e));return async()=>{try{let i=e.readUiLock();if(i&&e.isAlive(i.pid))try{e.killPid(i.pid,`SIGTERM`),e.log?.info({pid:i.pid,port:i.port},`idle-shutdown: SIGTERM UI sibling`);let a=Date.now()+t;for(;Date.now()<a&&e.isAlive(i.pid);)await r(n);if(e.isAlive(i.pid))try{e.killPid(i.pid,`SIGKILL`),e.log?.warn({pid:i.pid,graceMs:t},`idle-shutdown: SIGTERM grace expired — escalated to SIGKILL`)}catch(t){e.log?.error({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: SIGKILL failed`)}}catch(t){e.log?.warn({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: failed to SIGTERM UI sibling`)}}catch(t){e.log?.warn({err:t instanceof Error?t.message:String(t)},`idle-shutdown: UI lookup failed; proceeding with destroy`)}await e.destroy()}}async function U(e){let{config:t,cwd:n,host:r}=e,s=e.skipAutoInit??!1,c=e.skipUiAutoSpawn??!1,l=e.idleThresholdMs??18e5,{existsSync:u,mkdirSync:d}=await import(`node:fs`),{bootServer:f,getLogger:p,isProcessAlive:m,readUiLock:h,resolveContentDir:g}=await import(`./dist-Bj_IaFF5.mjs`),_=e.log??p(`start`);if(!s&&!o(n))throw new N(n);let y=process.env.OK_RECLAIM_DISABLE??null;try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-s94bDnZZ.mjs`)).repairMcpConfigs)({projectDir:n,reclaimDisableEnv:y})}catch(e){_.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-CBHiWTWu.mjs`)).repairLaunchJson)({projectDir:n,reclaimDisableEnv:y})}catch(e){_.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-B9lFVB-G.mjs`)).repairSkills)({projectDir:n,reclaimDisableEnv:y})}catch(e){_.warn({err:e},`[start] skill repair sweep failed; continuing`)}let b=g(t,n);u(b)||(d(b,{recursive:!0}),_.info({contentDir:b},`Created content directory`));let x=null,S=async({lockDir:t})=>{if(x=P({uiLock:h(t),isAlive:m}),x.action===`spawn`&&!c)try{let r=e.uiPort===void 0?void 0:[`ui`,`--port`,String(e.uiPort)];F({lockDir:t,cwd:n,spawn:e.spawn,args:r}),_.info({reason:x.reason,uiPort:e.uiPort},`[start] auto-spawned ok ui sibling`)}catch(e){console.warn(`[start] failed to auto-spawn ok ui: ${e instanceof Error?e.message:String(e)}`)}else x.action===`skip`&&_.info({port:x.port,pid:x.pid},`UI already running at port ${x.port}`)},C=e.reactShellDistDir===void 0,w=i(),T=await f({config:t,contentDir:b,projectDir:n,contentRoot:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:a,tokenStore:w,localOpCliArgs:[process.execPath,process.argv[1]],attachUiSibling:C,idleShutdownMs:l,skipAutoInit:!0,...C?{spawnUiSiblingFn:S}:{},idleShutdownHandler:e=>H({readUiLock:()=>h(T.lockDir),isAlive:m,killPid:(e,t)=>{process.kill(e,t)},destroy:e,log:_}),log:_,...e.serveContentAssets?{serveContentAssets:!0}:{},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}});x||={action:`skip`,reason:`alive`,pid:0,port:0};let E=x,D=null;if(E.action===`skip`)D=E.port>0?E.port:null;else if(!c){let t=e.uiBindTimeoutMs??3e3;D=await B({readUiLock:()=>h(T.lockDir),now:Date.now,sleep:e=>v(e),timeoutMs:t,pollIntervalMs:50}),D===null&&_.warn({timeoutMs:t},`[start] ok ui did not bind within timeout — banner falls back to API URL`)}return{httpServer:T.httpServer,destroy:T.destroy,lockDir:T.lockDir,contentDir:b,port:T.port,ready:T.ready,degraded:T.degraded,uiSpawnDecision:x,resolvedUiPort:D}}function W(t){if(t===`browser`||t===`app`)return t;throw new e(`--mode must be 'browser' or 'app'`)}function G(t){let n=Number.parseInt(t,10);if(Number.isNaN(n)||n<1||n>65535)throw new e(`--ui-port must be a port number between 1 and 65535`);return n}async function K(e,t){let{renderBanner:n}=await import(`./banner-D39r_H1d.mjs`),{dim:r,error:i,warning:a}=await import(`./colors-t2HkW8lF.mjs`),o=process.cwd(),c=e;process.title=M(o);let l=j(t,process.env),u=t.port===void 0?void 0:Number(t.port),d=process.env.PORT?Number(process.env.PORT):void 0,f=t.uiPort===void 0?void 0:Number(t.uiPort),p=I(u,d,f);if(f!==void 0){let{readServerLock:e,resolveLockDir:t}=await import(`./dist-Bj_IaFF5.mjs`);if(L(f,e(t(o)))){await z({cwd:o,uiPort:f});return}}let m;try{m=await U({config:c,cwd:o,host:l,port:p,...f===void 0?{}:{uiPort:f},...t.serveContentAssets?{serveContentAssets:!0}:{},...t.reactShellDistDir?{reactShellDistDir:t.reactShellDistDir}:{}})}catch(e){e instanceof N&&(console.error(i(e.message)),process.exit(1));let t=await import(`./dist-Bj_IaFF5.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),f!==void 0&&q(e,t)){await z({cwd:o,uiPort:f});return}let n=J(e,o,t);n!==null&&(console.error(i(n)),process.exit(1)),console.error(`${i(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let h=!1,g=async e=>{if(!h){h=!0,console.log(r(`\nShutting down (${e})`));try{await m.destroy()}catch(e){console.error(`${i(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)}};process.once(`SIGINT`,()=>{g(`SIGINT`)}),process.once(`SIGTERM`,()=>{g(`SIGTERM`)});let _=`http://${l}:${m.port}`,v=l===`0.0.0.0`||l===`::`?`http://0.0.0.0:${m.port}`:void 0,y=m.resolvedUiPort,b=y!==null&&y>0?`http://${l}:${y}`:_;console.log(n({name:`open-knowledge`,version:s,localUrl:b,apiUrl:b===_?void 0:_,networkUrl:v}));let x={"shadow-repo":`Version history and branch-switch safety unavailable`,"file-watcher":`External file changes will not sync to the editor`,"head-watcher":`Git branch switches may cause document inconsistency`};m.ready.then(async()=>{if(m.degraded.length>0){console.log();for(let e of m.degraded){let t=x[e]??`${e} (check server logs for details)`;console.warn(` ${a(`⚠`)} ${a(e)}: ${r(t)}`)}console.log()}if(t.open){let{openBrowser:e}=await import(`./open-browser-C6LU_1mt.mjs`);e(b)}}).catch(e=>{console.error(` ${i(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}function q(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function J(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=d(t,`.ok`),r=n.readServerLock(e);return r?r.kind===`interactive`?`Open Knowledge desktop is currently running on this project. Quit it or use --cwd to point elsewhere.`:r.kind===`mcp-spawned`?"An MCP-spawned server holds this lock; it should release on idle-shutdown (~30 min). Or run `ok stop`.":"Open Knowledge server is already running on this project — check `ok status` or `ok stop`.":"Open Knowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function Y(e){return new t(`start`).description(`Start the knowledge base collab server`).option(`-p, --port <port>`,`Server port`,void 0).option(`--ui-port <port>`,`Pin the ok ui sibling to <port> and connect (not exit) if a server already runs here — the worktree-preview recipe path`,G).option(`-H, --host <host>`,`Server host`,void 0).option(`--open`,`Open browser after start`).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,W).option(`--serve-content-assets`,`Serve content assets from this server`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path> (suppresses ok ui sibling)`).action(async t=>{let n=e();if(t.mode===`app`){t.open&&(process.stderr.write(`error: option '--mode=app' cannot be combined with '--open' (--open opens a browser tab against the local server, which app mode does not boot)
1
+ import{n as e,t}from"./esm-CEs3LWY3.mjs";import{bn as n,pt as r}from"./server-lock-BpjJj3OD-2pOoEhSP.mjs";import{i,t as a}from"./gh-detect-BveVRAue.mjs";import{In as o}from"./dist-sld-_d9T.mjs";import{n as s}from"./constants-DU4TbLA_.mjs";import{spawn as c}from"node:child_process";import{basename as l,dirname as u,join as d}from"node:path";import{closeSync as f,existsSync as p,mkdirSync as m,openSync as h,statSync as g}from"node:fs";import{homedir as _}from"node:os";import{setTimeout as v}from"node:timers/promises";const y=`Open Knowledge.app`,b=`/Applications/${y}`;function x(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return g(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function S(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}if(C(e,b))return b;let t=d(e.homeDir??_(),`Applications`,y);return C(e,t)?t:null}function C(e,t){try{let n=d(t,`Contents`,`MacOS`,`Open Knowledge`),r=e.statSync(n);return r&&typeof r.isFile==`function`?r.isFile():!1}catch{return!1}}function w(e){if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`};if(e.platform!==`darwin`)return{available:!1,reason:`darwin-only`};let t;try{t=S(e)}catch{return{available:!1,reason:`stat-error`}}return t?e.env.OK_FORCE_DESKTOP===`1`?{available:!0,reason:`available`,bundlePath:t}:e.isTTY!==!0||e.env.SSH_CONNECTION||e.env.SSH_TTY?{available:!1,reason:`headless`,bundlePath:t}:{available:!0,reason:`available`,bundlePath:t}:{available:!1,reason:`no-bundle`}}function T(e){(e.log??(e=>console.error(e)))("Launching Open Knowledge desktop (use `ok start` for the browser server, or `OK_FORCE_BROWSER=1` to always skip)");let t={...process.env};delete t.ELECTRON_RUN_AS_NODE,e.spawn(`open`,[`-b`,`com.inkeep.open-knowledge`],{detached:!0,stdio:`ignore`,env:t}).unref()}function E(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found at ${b}. Install via DMG, or omit --mode for browser mode.`;case`darwin-only`:return`Desktop app is macOS-only on this release. Use --mode=browser, or omit --mode for the server fallback.`;case`headless`:return`Desktop launch is gated in headless contexts (CI, SSH, non-TTY stdout). Set OK_FORCE_DESKTOP=1 to override, or use --mode=browser.`;case`force-browser`:return`OK_FORCE_BROWSER=1 is set — desktop dispatch is disabled. Unset it to use --mode=app.`;case`stat-error`:return`Failed to inspect desktop bundle at ${b} (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available at ${b} but launch dispatch did not fire (caller bug).`}}function D(e){return d(u(e),`..`,`Frameworks`,`Open Knowledge Server.app`,`Contents`,`MacOS`,`Open Knowledge Helper`)}const O=/\/[^/]+\.app\/Contents\/MacOS\/[^/]+$/;function k(e){if(e.platform!==`darwin`||!O.test(e.execPath))return null;let t=D(e.execPath);return e.exists(t)?t:null}function A(e={}){let t=e.execPath??process.execPath,n=e.platform??process.platform,r=e.argv??process.argv,i=e.exists??p,a=r[1];return a?{command:k({execPath:t,platform:n,exists:i})??t,prefixArgs:[a]}:(console.warn(`[self-spawn] process.argv[1] is empty — falling back to \`npx -y @inkeep/open-knowledge@latest\`. This re-introduces the registry-fetch surface that re-exec was fixing. Observed argv: ${JSON.stringify(r)}`),{command:`npx`,prefixArgs:[`-y`,`@inkeep/open-knowledge@latest`]})}function j(e,t){return e.host??t.HOST??`localhost`}function M(e){let t=l(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var N=class extends Error{cwd;constructor(e){super("This directory isn't set up yet. Run `ok init` first, then `ok start` again."),this.name=`OkDirMissingError`,this.cwd=e}};function P(e){return e.uiLock?e.isAlive(e.uiLock.pid)?{action:`skip`,reason:`alive`,pid:e.uiLock.pid,port:e.uiLock.port}:{action:`spawn`,reason:`stale`,stalePid:e.uiLock.pid}:{action:`spawn`,reason:`absent`}}function F(e){p(e.lockDir)||m(e.lockDir,{recursive:!0});let t=h(d(e.lockDir,n),`w`),r=e.spawn??c,{PORT:i,...a}=process.env,o=A();try{let n=r(o.command,[...o.prefixArgs,...e.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,t],cwd:e.cwd,env:{...a,ELECTRON_RUN_AS_NODE:`1`}});return n.unref(),n}finally{try{f(t)}catch{}}}function I(e,t,n){return e??(n===void 0?t:void 0)}function L(e,t){return e!==void 0&&t!==null&&t.port>0}function R(e,t,n){return e??(t!=null&&!n?1:0)}async function z(e){let t=e.spawn??c,n=A(),{PORT:r,...i}=process.env,a=t(n.command,[...n.prefixArgs,`ui`,`--port`,String(e.uiPort)],{cwd:e.cwd,stdio:`inherit`,env:{...i,ELECTRON_RUN_AS_NODE:`1`}}),o=!1,s=e=>{o=!0;try{a.kill(e)}catch{}},l=()=>s(`SIGINT`),u=()=>s(`SIGTERM`);process.once(`SIGINT`,l),process.once(`SIGTERM`,u),await new Promise(e=>{a.on(`exit`,(t,n)=>{process.exitCode=R(t,n,o),e()}),a.on(`error`,t=>{console.error(`[start] connect fallback: failed to spawn ok ui — ${t instanceof Error?t.message:String(t)}`),process.exitCode=1,e()})}),process.removeListener(`SIGINT`,l),process.removeListener(`SIGTERM`,u)}async function B(e){let t=e.now()+e.timeoutMs;for(;e.now()<t;){let t=e.readUiLock();if(t&&t.port>0)return t.port;await e.sleep(e.pollIntervalMs)}let n=e.readUiLock();return n&&n.port>0?n.port:null}const V=r;function H(e){let t=e.sigtermGraceMs??V,n=e.sigtermPollIntervalMs??200,r=e.sleep??(e=>v(e));return async()=>{try{let i=e.readUiLock();if(i&&e.isAlive(i.pid))try{e.killPid(i.pid,`SIGTERM`),e.log?.info({pid:i.pid,port:i.port},`idle-shutdown: SIGTERM UI sibling`);let a=Date.now()+t;for(;Date.now()<a&&e.isAlive(i.pid);)await r(n);if(e.isAlive(i.pid))try{e.killPid(i.pid,`SIGKILL`),e.log?.warn({pid:i.pid,graceMs:t},`idle-shutdown: SIGTERM grace expired — escalated to SIGKILL`)}catch(t){e.log?.error({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: SIGKILL failed`)}}catch(t){e.log?.warn({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: failed to SIGTERM UI sibling`)}}catch(t){e.log?.warn({err:t instanceof Error?t.message:String(t)},`idle-shutdown: UI lookup failed; proceeding with destroy`)}await e.destroy()}}async function U(e){let{config:t,cwd:n,host:r}=e,s=e.skipAutoInit??!1,c=e.skipUiAutoSpawn??!1,l=e.idleThresholdMs??18e5,{existsSync:u,mkdirSync:d}=await import(`node:fs`),{bootServer:f,getLogger:p,isProcessAlive:m,readUiLock:h,resolveContentDir:g}=await import(`./dist-Bj_IaFF5.mjs`),_=e.log??p(`start`);if(!s&&!o(n))throw new N(n);let y=process.env.OK_RECLAIM_DISABLE??null;try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-zqCKhtNX.mjs`)).repairMcpConfigs)({projectDir:n,reclaimDisableEnv:y})}catch(e){_.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-dWYTCWls.mjs`)).repairLaunchJson)({projectDir:n,reclaimDisableEnv:y})}catch(e){_.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-B9lFVB-G.mjs`)).repairSkills)({projectDir:n,reclaimDisableEnv:y})}catch(e){_.warn({err:e},`[start] skill repair sweep failed; continuing`)}let b=g(t,n);u(b)||(d(b,{recursive:!0}),_.info({contentDir:b},`Created content directory`));let x=null,S=async({lockDir:t})=>{if(x=P({uiLock:h(t),isAlive:m}),x.action===`spawn`&&!c)try{let r=e.uiPort===void 0?void 0:[`ui`,`--port`,String(e.uiPort)];F({lockDir:t,cwd:n,spawn:e.spawn,args:r}),_.info({reason:x.reason,uiPort:e.uiPort},`[start] auto-spawned ok ui sibling`)}catch(e){console.warn(`[start] failed to auto-spawn ok ui: ${e instanceof Error?e.message:String(e)}`)}else x.action===`skip`&&_.info({port:x.port,pid:x.pid},`UI already running at port ${x.port}`)},C=e.reactShellDistDir===void 0,w=i(),T=await f({config:t,contentDir:b,projectDir:n,contentRoot:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:a,tokenStore:w,localOpCliArgs:[process.execPath,process.argv[1]],attachUiSibling:C,idleShutdownMs:l,skipAutoInit:!0,...C?{spawnUiSiblingFn:S}:{},idleShutdownHandler:e=>H({readUiLock:()=>h(T.lockDir),isAlive:m,killPid:(e,t)=>{process.kill(e,t)},destroy:e,log:_}),log:_,...e.serveContentAssets?{serveContentAssets:!0}:{},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}});x||={action:`skip`,reason:`alive`,pid:0,port:0};let E=x,D=null;if(E.action===`skip`)D=E.port>0?E.port:null;else if(!c){let t=e.uiBindTimeoutMs??3e3;D=await B({readUiLock:()=>h(T.lockDir),now:Date.now,sleep:e=>v(e),timeoutMs:t,pollIntervalMs:50}),D===null&&_.warn({timeoutMs:t},`[start] ok ui did not bind within timeout — banner falls back to API URL`)}return{httpServer:T.httpServer,destroy:T.destroy,lockDir:T.lockDir,contentDir:b,port:T.port,ready:T.ready,degraded:T.degraded,uiSpawnDecision:x,resolvedUiPort:D}}function W(t){if(t===`browser`||t===`app`)return t;throw new e(`--mode must be 'browser' or 'app'`)}function G(t){let n=Number.parseInt(t,10);if(Number.isNaN(n)||n<1||n>65535)throw new e(`--ui-port must be a port number between 1 and 65535`);return n}async function K(e,t){let{renderBanner:n}=await import(`./banner-D39r_H1d.mjs`),{dim:r,error:i,warning:a}=await import(`./colors-t2HkW8lF.mjs`),o=process.cwd(),c=e;process.title=M(o);let l=j(t,process.env),u=t.port===void 0?void 0:Number(t.port),d=process.env.PORT?Number(process.env.PORT):void 0,f=t.uiPort===void 0?void 0:Number(t.uiPort),p=I(u,d,f);if(f!==void 0){let{readServerLock:e,resolveLockDir:t}=await import(`./dist-Bj_IaFF5.mjs`);if(L(f,e(t(o)))){await z({cwd:o,uiPort:f});return}}let m;try{m=await U({config:c,cwd:o,host:l,port:p,...f===void 0?{}:{uiPort:f},...t.serveContentAssets?{serveContentAssets:!0}:{},...t.reactShellDistDir?{reactShellDistDir:t.reactShellDistDir}:{}})}catch(e){e instanceof N&&(console.error(i(e.message)),process.exit(1));let t=await import(`./dist-Bj_IaFF5.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),f!==void 0&&q(e,t)){await z({cwd:o,uiPort:f});return}let n=J(e,o,t);n!==null&&(console.error(i(n)),process.exit(1)),console.error(`${i(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let h=!1,g=async e=>{if(!h){h=!0,console.log(r(`\nShutting down (${e})`));try{await m.destroy()}catch(e){console.error(`${i(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)}};process.once(`SIGINT`,()=>{g(`SIGINT`)}),process.once(`SIGTERM`,()=>{g(`SIGTERM`)});let _=`http://${l}:${m.port}`,v=l===`0.0.0.0`||l===`::`?`http://0.0.0.0:${m.port}`:void 0,y=m.resolvedUiPort,b=y!==null&&y>0?`http://${l}:${y}`:_;console.log(n({name:`open-knowledge`,version:s,localUrl:b,apiUrl:b===_?void 0:_,networkUrl:v}));let x={"shadow-repo":`Version history and branch-switch safety unavailable`,"file-watcher":`External file changes will not sync to the editor`,"head-watcher":`Git branch switches may cause document inconsistency`};m.ready.then(async()=>{if(m.degraded.length>0){console.log();for(let e of m.degraded){let t=x[e]??`${e} (check server logs for details)`;console.warn(` ${a(`⚠`)} ${a(e)}: ${r(t)}`)}console.log()}if(t.open){let{openBrowser:e}=await import(`./open-browser-C6LU_1mt.mjs`);e(b)}}).catch(e=>{console.error(` ${i(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}function q(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function J(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=d(t,`.ok`),r=n.readServerLock(e);return r?r.kind===`interactive`?`Open Knowledge desktop is currently running on this project. Quit it or use --cwd to point elsewhere.`:r.kind===`mcp-spawned`?"An MCP-spawned server holds this lock; it should release on idle-shutdown (~30 min). Or run `ok stop`.":"Open Knowledge server is already running on this project — check `ok status` or `ok stop`.":"Open Knowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function Y(e){return new t(`start`).description(`Start the knowledge base collab server`).option(`-p, --port <port>`,`Server port`,void 0).option(`--ui-port <port>`,`Pin the ok ui sibling to <port> and connect (not exit) if a server already runs here — the worktree-preview recipe path`,G).option(`-H, --host <host>`,`Server host`,void 0).option(`--open`,`Open browser after start`).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,W).option(`--serve-content-assets`,`Serve content assets from this server`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path> (suppresses ok ui sibling)`).action(async t=>{let n=e();if(t.mode===`app`){t.open&&(process.stderr.write(`error: option '--mode=app' cannot be combined with '--open' (--open opens a browser tab against the local server, which app mode does not boot)
2
2
  `),process.exit(2));let e=[];if(t.port!==void 0&&e.push(`--port`),t.uiPort!==void 0&&e.push(`--ui-port`),t.host!==void 0&&e.push(`--host`),e.length>0){let t=process.env.OK_LOG_LEVEL??`info`;(t===`debug`||t===`trace`)&&console.error(`--mode=app: ignoring ${e.join(`, `)}`)}let n=w(x());if(n.available){T({spawn:c});return}console.error(E(n.reason)),process.exit(1)}await K(n,t)})}export{A as _,R as a,T as b,M as c,j as d,K as f,J as g,Y as h,H as i,q as l,F as m,B as n,z as o,L as p,U as r,P as s,N as t,I as u,x as v,w as y};
3
- //# sourceMappingURL=start-7bpluiOA.mjs.map
3
+ //# sourceMappingURL=start-D474Z7JL.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/open-knowledge",
3
- "version": "0.9.2-beta.8",
3
+ "version": "0.9.2-beta.9",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "repository": {
@@ -1,2 +0,0 @@
1
- import"./server-lock-BpjJj3OD-2pOoEhSP.mjs";var e=`0.9.2-beta.8`;const t=`config.yml`,n=e;export{n,t};
2
- //# sourceMappingURL=constants-Dz5iTLUD.mjs.map
@@ -1 +0,0 @@
1
- import{m as e}from"./init-BjjtQpJ4.mjs";export{e as runInit};
@@ -1 +0,0 @@
1
- import{n as e}from"./loader-BSyhsuGY.mjs";export{e as loadConfig};
@@ -1 +0,0 @@
1
- import{n as e,t}from"./preview-C6kOnHJr.mjs";export{t as formatPreviewBlock,e as previewContent};
@@ -1 +0,0 @@
1
- import{h as e}from"./start-7bpluiOA.mjs";export{e as startCommand};