@inkeep/open-knowledge 0.5.0-beta.47 → 0.5.0-beta.48

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
3
3
  description: "MUST invoke when the project contains a .ok/ directory — before any read or edit of .md / .mdx files, any mcp__open-knowledge__ tool call, and any write_document / edit_document. Skip if no .ok/ — not an Open Knowledge project. Carries preview-attach (open preview browser at session start; one-shot on `action: attach-preview-once`; surface to user on `action: start-ui` when no UI is running), STOP rules for native Read/Grep/Edit on in-scope markdown, grounding rules (every factual claim needs a source), standard markdown linking with get_dead_links verification, image sourcing + alt-text + source-citation rules, folder-first organization with opt-in nested .ok/ frontmatter + templates, and the anti-pattern table."
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.5.0-beta.47"
6
+ version: "0.5.0-beta.48"
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{Ai as n,B as r,Ci as i,D as a,Di as o,Dn as s,E as c,Ei as l,Gn as u,Gr as d,Gt as f,Hr as p,Jn as m,Kr as h,Mi as ee,Oi as g,Si as _,Ti as v,U as y,Ur as b,Wr as x,Xr as te,Yr as ne,Z as re,bi as ie,cr as ae,it as oe,ji as se,ki as ce,m as le,nn as ue,nt as de,pi as fe,pn as pe,qr as me,vi as he,wi as ge,xi as _e,z as ve,zn as ye}from"./dist-DHj61EG5.mjs";import{n as be,r as xe,t as S}from"./dist-bundle-BSdjl7Rj.mjs";import{A as Se,C as Ce,D as we,E as Te,O as Ee,S as De,T as Oe,b as ke,k as Ae,o as je,p as Me,w as Ne,x as Pe,y as Fe}from"./init-CmQ_C7Dm.mjs";import{c as Ie,f as Le,l as Re,n as ze,s as C}from"./server-lock-D7DXNVql-BRVVzA6T.mjs";import{i as Be}from"./git-handle-DwfYp_z--CfyPz4Dz.mjs";import{n as Ve}from"./constants-BbmMpMCp.mjs";import{i as He}from"./src-CzxqX1w-.mjs";import{n as Ue,t as We}from"./loader-CHhQuNxK.mjs";import{d as Ge,f as Ke,l as qe,m as Je,p as Ye,s as Xe}from"./start-B5WsKMpt.mjs";import{c as Ze,i as w,n as T,o as E,r as D,s as Qe,t as O}from"./colors-BtKMHmBX.mjs";import{execFileSync as $e,execSync as et,spawn as tt,spawnSync as k}from"node:child_process";import nt,{basename as rt,dirname as it,isAbsolute as at,join as A,relative as ot,resolve as j}from"node:path";import{closeSync as st,existsSync as M,mkdirSync as ct,mkdtempSync as lt,openSync as ut,readFileSync as N,readdirSync as dt,realpathSync as ft,rmSync as pt,statSync as mt,unlinkSync as ht,writeFileSync as gt}from"node:fs";import _t from"node:process";import{homedir as vt,hostname as yt,tmpdir as bt}from"node:os";import{fileURLToPath as xt}from"node:url";import{AsyncLocalStorage as St,AsyncResource as Ct}from"node:async_hooks";import{stripVTControlCharacters as wt,styleText as P}from"node:util";import*as Tt from"node:readline";import{randomUUID as Et}from"node:crypto";import{realpath as Dt}from"node:fs/promises";import{setTimeout as Ot}from"node:timers/promises";import{createInterface as kt}from"node:readline/promises";var At=ee();const jt=`open-knowledge`;var Mt=class{backend=`keyring`;async get(e){let{Entry:t}=await import(`@napi-rs/keyring`);try{let n=new t(jt,e).getPassword();return n==null?null:JSON.parse(n)}catch{return null}}async set(e,t,n,r){let{Entry:i}=await import(`@napi-rs/keyring`),a=new i(jt,e),o={login:t,token:n,...r};a.setPassword(JSON.stringify(o))}async clear(e){let{Entry:t}=await import(`@napi-rs/keyring`);try{new t(jt,e).deletePassword()}catch{}}},Nt=class{backend=`file`;authFile;constructor(e){this.authFile=e??A(vt(),`.ok`,`auth.yml`)}read(){if(!M(this.authFile))return{};try{return(0,At.parse)(N(this.authFile,`utf-8`))??{}}catch(e){let t=e instanceof Error?e.message:`unknown error`;return process.stderr.write(`[auth] Failed to parse ${this.authFile}: ${t}. Starting with empty credentials.\n`),{}}}write(e){let t=it(this.authFile);M(t)||ct(t,{recursive:!0,mode:448}),gt(this.authFile,(0,At.stringify)(e),{mode:384})}async get(e){return this.read()[e]??null}async set(e,t,n,r){let i=this.read();i[e]={login:t,token:n,...r},this.write(i)}async clear(e){let t=this.read();delete t[e],this.write(t)}};async function Pt(e){try{let{Entry:e}=await import(`@napi-rs/keyring`);return new e(jt,`__probe__`),process.stderr.write(`[auth] token storage: OS keychain
2
+ import{o as e}from"./chunk-FK9Q3tQk.mjs";import{t}from"./esm-CEs3LWY3.mjs";import{Ai as n,B as r,Ci as i,D as a,Di as o,Dn as s,E as c,Ei as l,Gn as u,Gr as d,Gt as f,Hr as p,Jn as m,Kr as h,Mi as ee,Oi as g,Si as _,Ti as v,U as y,Ur as b,Wr as x,Xr as te,Yr as ne,Z as re,bi as ie,cr as ae,it as oe,ji as se,ki as ce,m as le,nn as ue,nt as de,pi as fe,pn as pe,qr as me,vi as he,wi as ge,xi as _e,z as ve,zn as ye}from"./dist-DHj61EG5.mjs";import{n as be,r as xe,t as S}from"./dist-bundle-BSdjl7Rj.mjs";import{A as Se,C as Ce,D as we,E as Te,O as Ee,S as De,T as Oe,b as ke,k as Ae,o as je,p as Me,w as Ne,x as Pe,y as Fe}from"./init-OOHQMBAG.mjs";import{c as Ie,f as Le,l as Re,n as ze,s as C}from"./server-lock-D7DXNVql-BRVVzA6T.mjs";import{i as Be}from"./git-handle-DwfYp_z--CfyPz4Dz.mjs";import{n as Ve}from"./constants-xPQnQB6p.mjs";import{i as He}from"./src-C0OBIJW_.mjs";import{n as Ue,t as We}from"./loader-BeazNH_4.mjs";import{d as Ge,f as Ke,l as qe,m as Je,p as Ye,s as Xe}from"./start-BvMp3jiu.mjs";import{c as Ze,i as w,n as T,o as E,r as D,s as Qe,t as O}from"./colors-BtKMHmBX.mjs";import{execFileSync as $e,execSync as et,spawn as tt,spawnSync as k}from"node:child_process";import nt,{basename as rt,dirname as it,isAbsolute as at,join as A,relative as ot,resolve as j}from"node:path";import{closeSync as st,existsSync as M,mkdirSync as ct,mkdtempSync as lt,openSync as ut,readFileSync as N,readdirSync as dt,realpathSync as ft,rmSync as pt,statSync as mt,unlinkSync as ht,writeFileSync as gt}from"node:fs";import _t from"node:process";import{homedir as vt,hostname as yt,tmpdir as bt}from"node:os";import{fileURLToPath as xt}from"node:url";import{AsyncLocalStorage as St,AsyncResource as Ct}from"node:async_hooks";import{stripVTControlCharacters as wt,styleText as P}from"node:util";import*as Tt from"node:readline";import{randomUUID as Et}from"node:crypto";import{realpath as Dt}from"node:fs/promises";import{setTimeout as Ot}from"node:timers/promises";import{createInterface as kt}from"node:readline/promises";var At=ee();const jt=`open-knowledge`;var Mt=class{backend=`keyring`;async get(e){let{Entry:t}=await import(`@napi-rs/keyring`);try{let n=new t(jt,e).getPassword();return n==null?null:JSON.parse(n)}catch{return null}}async set(e,t,n,r){let{Entry:i}=await import(`@napi-rs/keyring`),a=new i(jt,e),o={login:t,token:n,...r};a.setPassword(JSON.stringify(o))}async clear(e){let{Entry:t}=await import(`@napi-rs/keyring`);try{new t(jt,e).deletePassword()}catch{}}},Nt=class{backend=`file`;authFile;constructor(e){this.authFile=e??A(vt(),`.ok`,`auth.yml`)}read(){if(!M(this.authFile))return{};try{return(0,At.parse)(N(this.authFile,`utf-8`))??{}}catch(e){let t=e instanceof Error?e.message:`unknown error`;return process.stderr.write(`[auth] Failed to parse ${this.authFile}: ${t}. Starting with empty credentials.\n`),{}}}write(e){let t=it(this.authFile);M(t)||ct(t,{recursive:!0,mode:448}),gt(this.authFile,(0,At.stringify)(e),{mode:384})}async get(e){return this.read()[e]??null}async set(e,t,n,r){let i=this.read();i[e]={login:t,token:n,...r},this.write(i)}async clear(e){let t=this.read();delete t[e],this.write(t)}};async function Pt(e){try{let{Entry:e}=await import(`@napi-rs/keyring`);return new e(jt,`__probe__`),process.stderr.write(`[auth] token storage: OS keychain
3
3
  `),new Mt}catch{return process.stderr.write(`[auth] token storage: file (~/.ok/auth.yml)
4
4
  `),new Nt(e)}}async function Ft(e,t){let n=[],r=new Nt(t);await r.get(e)!=null&&(await r.clear(e),n.push(`file`));try{let{Entry:t}=await import(`@napi-rs/keyring`);new t(jt,`__probe__`);let r=new Mt;await r.get(e)!=null&&(await r.clear(e),n.push(`keychain`))}catch{}return{touched:n}}async function It(e,t,n){let r=Lt(await Rt(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 Lt(e){let t={};for(let n of e.split(`
5
5
  `)){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 Rt(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 zt(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 It(process.stdin,process.stdout,t);process.exit(n)}),n}function Bt(e){let t=e.endpoint.DEFAULTS;return/^https:\/\/(api\.)?github\.com$/.test(t.baseUrl)?`https://github.com`:t.baseUrl.replace(`/api/v3`,``)}async function Vt(e,t,n){let r={baseUrl:Bt(e),headers:{accept:`application/json`},...n},i=await e(t,r);if(`error`in i.data){let n=new be(`${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 Ht(e){let t=e.request||S,n={client_id:e.clientId};return`scopes`in e&&Array.isArray(e.scopes)&&(n.scope=e.scopes.join(` `)),Vt(t,`POST /login/device/code`,n)}async function Ut(e){let t=await Vt(e.request||S,`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=Wt(e,t.data.expires_in),n.refreshTokenExpiresAt=Wt(e,t.data.refresh_token_expires_in)}delete n.scopes}return{...t,authentication:n}}function Wt(e,t){return new Date(e+t*1e3).toISOString()}async function Gt(e,t){let n=Kt(e,t.auth);if(n)return n;let{data:r}=await Ht({clientType:e.clientType,clientId:e.clientId,request:t.request||e.request,scopes:t.auth.scopes||e.scopes});await e.onVerification(r);let i=await Jt(t.request||e.request,e.clientId,e.clientType,r);return e.authentication=i,i}function Kt(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 qt(e){await new Promise(t=>setTimeout(t,e*1e3))}async function Jt(e,t,n,r){try{let i={clientId:t,request:e,code:r.device_code},{authentication:a}=n===`oauth-app`?await Ut({...i,clientType:`oauth-app`}):await Ut({...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 qt(r.interval),Jt(e,t,n,r);if(a===`slow_down`)return await qt(r.interval+7),Jt(e,t,n,r);throw i}}async function Yt(e,t){return Gt(e,{auth:t})}async function Xt(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 Gt(e,{request:t,auth:{type:`oauth`}});return i.headers.authorization=`token ${a}`,t(i)}var Zt=`0.0.0-development`;function Qt(e){let t=e.request||S.defaults({headers:{"user-agent":`octokit-auth-oauth-device.js/${Zt} ${xe()}`}}),{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(Yt.bind(null,i),{hook:Xt.bind(null,i)})}async function $t(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=Qt({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-BmF5_Mcp.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 en={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 tn;(function(e){})(tn||={});function nn(e){return n(ie,e)}function rn(){return process.env.OPEN_KNOWLEDGE_GITHUB_CLIENT_ID??`Ov23liqlSd0V1MwR6rhI`}const an=new Set([`gitlab.com`,`bitbucket.org`,`codeberg.org`,`gitea.com`,`sr.ht`,`sourcehut.org`]);function F(e){let t=e.toLowerCase().replace(/:\d+$/,``);an.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 on(e,t){e&&process.stdout.write(`${JSON.stringify(t)}\n`)}async function sn(e,t,n=$t){let r=rn(),{host:i,json:a}=e;F(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?on(!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?on(!0,{type:`complete`,host:i,login:s}):process.stderr.write(`✓ Logged in as ${s} on ${i}\n`)}function cn(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 sn(t,await e())})}const ln=e=>e.name===`enter`||e.name===`return`;var un=class extends Error{name=`AbortPromptError`;message=`Prompt was aborted`;constructor(e){super(),this.cause=e?.cause}},dn=class extends Error{name=`CancelPromptError`;message=`Prompt was canceled`},fn=class extends Error{name=`ExitPromptError`},pn=class extends Error{name=`HookError`},mn=class extends Error{name=`ValidationError`};const hn=new St;function gn(e){return{rl:e,hooks:[],hooksCleanup:[],hooksEffect:[],index:0,handleChange(){}}}function _n(e,t){let n=gn(e);return hn.run(n,()=>{function e(e){n.handleChange=()=>{n.index=0,e()},n.handleChange()}return t(e)})}function I(){let e=hn.getStore();if(!e)throw new pn(`[Inquirer] Hook functions can only be called from within a prompt`);return e}function vn(){return I().rl}function yn(e){return Ct.bind((...t)=>{let n=I(),r=!1,i=n.handleChange;n.handleChange=()=>{r=!0};let a=e(...t);return r&&i(),n.handleChange=i,a})}function bn(e){let t=I(),{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(){I().handleChange()}const L={queue(e){let t=I(),{index:n}=t;t.hooksEffect.push(()=>{t.hooksCleanup[n]?.();let r=e(vn());if(r!=null&&typeof r!=`function`)throw new mn(`useEffect return value must be a cleanup function or nothing.`);t.hooksCleanup[n]=r})},run(){let e=I();yn(()=>{e.hooksEffect.forEach(e=>{e()}),e.hooksEffect.length=0})()},clearAll(){let e=I();e.hooksCleanup.forEach(e=>{e?.()}),e.hooksEffect.length=0,e.hooksCleanup.length=0}};function Sn(e){return typeof e==`function`}function R(e){return bn(t=>{let n=Ct.bind(function(e){t.get()!==e&&(t.set(e),xn())});if(t.initialized)return[t.get(),n];let r=Sn(e)?e():e;return t.set(r),[r,n]})}function Cn(e,t){bn(n=>{let r=n.get();(!Array.isArray(r)||t.some((e,t)=>!Object.is(e,r[t])))&&L.queue(e),n.set(t)})}const wn={prefix:{idle:P(`blue`,`?`),done:P(`green`,Se.tick)},spinner:{interval:80,frames:[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`].map(e=>P(`yellow`,e))},style:{answer:e=>P(`cyan`,e),message:e=>P(`bold`,e),error:e=>P(`red`,`> ${e}`),defaultAnswer:e=>P(`dim`,`(${e})`),help:e=>P(`dim`,e),highlight:e=>P(`cyan`,e),key:e=>P(`cyan`,P(`bold`,`<${e}>`))}};function Tn(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 En(...e){let t={};for(let n of e)for(let[e,r]of Object.entries(n)){let n=t[e];t[e]=Tn(n)&&Tn(r)?En(n,r):r}return t}function Dn(...e){return En(wn,...e.filter(e=>e!=null))}function On({status:e=`idle`,theme:t}){let[n,r]=R(!1),[i,a]=R(0),{prefix:o,spinner:s}=Dn(t);return Cn(()=>{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 kn(e){return R({current:e})[0]}function An(e){let t=kn(e);t.current=e,Cn(e=>{let n=!1,r=yn((r,i)=>{n||t.current(i,e)});return e.input.on(`keypress`,r),()=>{n=!0,e.input.removeListener(`keypress`,r)}},[])}var jn=e(Ae(),1);function Mn(e,t){return e.split(`
@@ -19,10 +19,10 @@ import{o as e}from"./chunk-FK9Q3tQk.mjs";import{t}from"./esm-CEs3LWY3.mjs";impor
19
19
  `)}function Gr(){return new t(`signout`).description(`Remove stored credentials`).option(`--host <host>`,`GitHub hostname`,`github.com`).action(async e=>{await Wr(e)})}async function Kr(e,t,n=Br){let r=n(e);if(r.available&&r.token)return{tier:`A`,token:r.token};let i=await t.get(e);return i==null?{tier:`none`}:{tier:i.gitProtocol===`ssh`?`C`:`B`,token:i.token}}async function qr(e,t){let{host:n,json:r}=e;F(n);let i=await Kr(n,t);i.tier===`none`&&(r?process.stdout.write(`${JSON.stringify({type:`status`,host:n,authenticated:!1})}\n`):process.stderr.write(`Not logged in to ${n}\n`),process.exit(1));let a=n===`github.com`?void 0:`https://${n}/api/v3`,o=new B({auth:i.token,...a?{baseUrl:a}:{}});try{let{data:e}=await o.users.getAuthenticated();r?process.stdout.write(`${JSON.stringify({type:`status`,host:n,authenticated:!0,tier:i.tier,login:e.login,name:e.name,email:e.email})}\n`):process.stderr.write(`✓ Logged in as ${e.login} on ${n}\n`)}catch{r?process.stdout.write(JSON.stringify({type:`status`,host:n,authenticated:!1,error:`token invalid`})+`
20
20
  `):process.stderr.write(`✗ Token invalid for ${n}\n`),process.exit(1)}}function Jr(e){return new t(`status`).description(`Show authentication status`).option(`--host <host>`,`GitHub or GitHub Enterprise hostname`,`github.com`).option(`--json`,`Output JSON`,!1).action(async t=>{await qr(t,await e())})}function Yr(){let e=new t(`auth`);e.description(`GitHub authentication management`);let n=()=>Pt();return e.addCommand(cn(n)),e.addCommand(Jr(n)),e.addCommand(Ur(n)),e.addCommand(Gr()),e.addCommand(Rr(n)),e.addCommand(zt(n)),e}function V(e,t,n={}){let r=Re(e,t);if(!M(r))return{status:`missing`,lockPath:r};let i;try{i=JSON.parse(N(r,`utf-8`))}catch{return{status:`corrupt`,lockPath:r}}if(!i||typeof i!=`object`||!Ie(i.pid))return{status:`corrupt`,lockPath:r};let a=i;if(!(n.isAlive??C)(a.pid))return{status:`dead-pid`,lockPath:r,lock:a};let o=n.host??yt();return a.hostname===o?{status:`alive`,lockPath:r,lock:a}:{status:`foreign-host`,lockPath:r,lock:a}}function Xr(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 Zr(e){let t=e.inspect??(t=>V(e.lockDir,t)),n=e.unlink??(e=>ht(e)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=Xr(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 Qr(e){return new t(`clean`).description(`Prune stale / corrupt open-knowledge lock files (never touches live locks)`).action(()=>{e(),Zr({lockDir:m(process.cwd())}).failed.length>0&&(process.exitCode=1)})}async function $r(e,t,n={},r=Br){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 ei(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 ti=[[`count`,0,10],[`compress`,10,20],[`receiv`,20,60],[`resolv`,60,100]];function ni(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 ti)if(n.includes(e))return{stage:t[1],pct:Math.round(i+r/100*(a-i))};return null}function H(e,t){e&&process.stdout.write(`${JSON.stringify(t)}\n`)}function ri(e,t,n){return e===`https`&&t===`github.com`&&n}async function ii(e,t,n,r=process.cwd()){let i=He(e);if(!i)throw Error(`Invalid git URL: ${e}`);let a=t.dir?j(r,t.dir):j(r,i.name);if(M(a)&&dt(a).length>0)throw Error(`Target directory is not empty: ${a}`);let o=await Pt(),s=i.protocol===`https`&&i.hostname===`github.com`?await ei(i.owner,i.name):!1,c=ri(i.protocol,i.hostname,s)?{tier:`none`,credentialArgs:[]}:await $r(i.hostname,o,{}),l=Be({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(`
21
21
  `)){let n=ni(e);n&&n.pct!==u&&(u=n.pct,H(t.json,{type:`progress`,pct:n.pct,stage:n.stage}),t.json||process.stderr.write(`\r Cloning ${n.pct}%`))}})}),await l.clone(e,a,[`--progress`]),t.json||process.stderr.write(`
22
- `);try{let{runInit:e}=await import(`./init-CU0LqAeV.mjs`),n=await e({cwd:a,mcp:!1});if(n.contentUpdated.length>0){let e=`auto-init: updated ${n.contentUpdated.join(`, `)}`;t.json?H(!0,{type:`warning`,message:e}):process.stderr.write(` ${e}\n`)}}catch(e){let n=e instanceof Error?e.message:String(e);t.json?H(!0,{type:`warning`,message:`auto-init: ${n}`}):process.stderr.write(` auto-init: ${n}\n`)}try{ai(a)}catch(e){let n=e instanceof Error?e.message:String(e);t.json?H(!0,{type:`warning`,message:`git-exclude: ${n}`}):process.stderr.write(` git-exclude: ${n}\n`)}return a}function ai(e){let t=A(e,`.git`,`info`,`exclude`);if(!M(t))return`no-exclude`;let n=N(t,`utf-8`),r=new Set([`.ok`,`.ok/`,`/.ok`,`/.ok/`]);return n.split(`
22
+ `);try{let{runInit:e}=await import(`./init-Bp6innPX.mjs`),n=await e({cwd:a,mcp:!1});if(n.contentUpdated.length>0){let e=`auto-init: updated ${n.contentUpdated.join(`, `)}`;t.json?H(!0,{type:`warning`,message:e}):process.stderr.write(` ${e}\n`)}}catch(e){let n=e instanceof Error?e.message:String(e);t.json?H(!0,{type:`warning`,message:`auto-init: ${n}`}):process.stderr.write(` auto-init: ${n}\n`)}try{ai(a)}catch(e){let n=e instanceof Error?e.message:String(e);t.json?H(!0,{type:`warning`,message:`git-exclude: ${n}`}):process.stderr.write(` git-exclude: ${n}\n`)}return a}function ai(e){let t=A(e,`.git`,`info`,`exclude`);if(!M(t))return`no-exclude`;let n=N(t,`utf-8`),r=new Set([`.ok`,`.ok/`,`/.ok`,`/.ok/`]);return n.split(`
23
23
  `).map(e=>e.trim()).some(e=>r.has(e))?`already-present`:(gt(t,`${n}${n.length===0||n.endsWith(`
24
24
  `)?``:`
25
- `}.ok/\n`,`utf-8`),`appended`)}function oi(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).action(async(t,n,r)=>{let i=e();try{let a=await ii(t,{json:r.json,dir:n},i);if(r.json)H(!0,{type:`complete`,dir:a});else{process.stderr.write(`✓ Cloned to ${a}\n`),process.chdir(a);let{startCommand:t}=await import(`./start-Duh1Cxij.mjs`);await t(e).parseAsync([],{from:`user`})}}catch(e){let t=e instanceof Error?e.message:String(e);r.json?H(!0,{type:`error`,message:t}):process.stderr.write(`✗ ${t}\n`),process.exitCode=1}})}const si=[[`sync`],[`persistence`,`debounceMs`],[`persistence`,`maxDebounceMs`],[`server`,`port`],[`content`,`include`],[`content`,`exclude`]];function ci(e={}){let t=e.log??(e=>console.error(e)),n=e.error??(e=>console.error(e)),r=e.loadConfigFn??Ue;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 li(e){let t=(0,At.parseDocument)(N(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 si)t.hasIn(e)&&n.push(e.join(`.`));return n}function ui(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function di(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=ui(i)?i:{};e[r]=a,e=a}e[n[n.length-1]]=null}return t}async function fi(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??te,s=[];(r===`project`||r===`both`)&&s.push({scope:`project`,absPath:ne(`project`,a,e.homedirOverride)}),(r===`user`||r===`both`)&&s.push({scope:`user`,absPath:ne(`user`,a,e.homedirOverride)});let c=[],l=!0;for(let{scope:t,absPath:n}of s){if(!M(n)){c.push({path:n,scope:t,found:[],removed:[]});continue}let r;try{r=li(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:di(si.filter(e=>r.includes(e.join(`.`)))),homedirOverride:e.homedirOverride});if(!s.ok){c.push({path:n,scope:t,found:r,removed:[],error:fe(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 pi(){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(()=>{ci({}).ok||(process.exitCode=1)}),e.command(`migrate`).description(`Remove deprecated config fields (sync.*, persistence.{debounceMs,maxDebounceMs}, server.port, content.{include,exclude}) idempotently`).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 fi({scope:t,dryRun:e.dryRun})).ok||(process.exitCode=1)}),e}var U=e(Ze(),1);const W=2e3,mi=[/cli\.mjs/,/(^|[\s/])(open-knowledge|ok)\s+(start|mcp|ui)(\s|$)/,/(^|[\s/])bun([\s/]).*?(run dev|packages\/app|vite|hocuspocus)/,/(^|[\s/])node([\s/]).*?(packages\/(cli|app)|vite|hocuspocus)/,/(^|\s)--ok-lock-dir-b64=/];function hi(e){return mi.some(t=>t.test(e))}function gi(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 at(e)?e:null}catch{return null}}function _i(e){let t=[];for(let n of e.split(`
25
+ `}.ok/\n`,`utf-8`),`appended`)}function oi(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).action(async(t,n,r)=>{let i=e();try{let a=await ii(t,{json:r.json,dir:n},i);if(r.json)H(!0,{type:`complete`,dir:a});else{process.stderr.write(`✓ Cloned to ${a}\n`),process.chdir(a);let{startCommand:t}=await import(`./start-BvYwQHjm.mjs`);await t(e).parseAsync([],{from:`user`})}}catch(e){let t=e instanceof Error?e.message:String(e);r.json?H(!0,{type:`error`,message:t}):process.stderr.write(`✗ ${t}\n`),process.exitCode=1}})}const si=[[`sync`],[`persistence`,`debounceMs`],[`persistence`,`maxDebounceMs`],[`server`,`port`],[`content`,`include`],[`content`,`exclude`]];function ci(e={}){let t=e.log??(e=>console.error(e)),n=e.error??(e=>console.error(e)),r=e.loadConfigFn??Ue;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 li(e){let t=(0,At.parseDocument)(N(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 si)t.hasIn(e)&&n.push(e.join(`.`));return n}function ui(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function di(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=ui(i)?i:{};e[r]=a,e=a}e[n[n.length-1]]=null}return t}async function fi(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??te,s=[];(r===`project`||r===`both`)&&s.push({scope:`project`,absPath:ne(`project`,a,e.homedirOverride)}),(r===`user`||r===`both`)&&s.push({scope:`user`,absPath:ne(`user`,a,e.homedirOverride)});let c=[],l=!0;for(let{scope:t,absPath:n}of s){if(!M(n)){c.push({path:n,scope:t,found:[],removed:[]});continue}let r;try{r=li(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:di(si.filter(e=>r.includes(e.join(`.`)))),homedirOverride:e.homedirOverride});if(!s.ok){c.push({path:n,scope:t,found:r,removed:[],error:fe(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 pi(){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(()=>{ci({}).ok||(process.exitCode=1)}),e.command(`migrate`).description(`Remove deprecated config fields (sync.*, persistence.{debounceMs,maxDebounceMs}, server.port, content.{include,exclude}) idempotently`).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 fi({scope:t,dryRun:e.dryRun})).ok||(process.exitCode=1)}),e}var U=e(Ze(),1);const W=2e3,mi=[/cli\.mjs/,/(^|[\s/])(open-knowledge|ok)\s+(start|mcp|ui)(\s|$)/,/(^|[\s/])bun([\s/]).*?(run dev|packages\/app|vite|hocuspocus)/,/(^|[\s/])node([\s/]).*?(packages\/(cli|app)|vite|hocuspocus)/,/(^|\s)--ok-lock-dir-b64=/];function hi(e){return mi.some(t=>t.test(e))}function gi(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 at(e)?e:null}catch{return null}}function _i(e){let t=[];for(let n of e.split(`
26
26
  `)){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)&&hi(a)&&t.push({pid:o,command:a})}return t}function vi(e){let t=[],n=e.split(`
27
27
  `);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)&&hi(o)&&t.push({pid:s,command:o})}return t}async function yi(){let e=k(`pgrep`,[`-a`,`-f`,`cli\\.mjs|open-knowledge|--ok-lock-dir-b64=|(^|[ /])ok[ ]+(start|mcp|ui)([ ]|$)|packages/(cli|app)|hocuspocus|vite`],{encoding:`utf-8`,timeout:W});if(!(e.error!=null&&e.error.code===`ENOENT`)){let t=e.stdout??``,n=_i(t);if(n.length>0||t.trim()===``)return n}let t=k(`ps`,[`-axo`,`pid,command`],{encoding:`utf-8`,timeout:W});return t.error!=null||!t.stdout?[]:vi(t.stdout)}function bi(e){let t=e.trim().split(/\s+/).filter(Boolean);for(let e of t){if(e.startsWith(`@`))continue;let t=rt(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 xi(e){let t=k(`ps`,[`-p`,String(e),`-o`,`command=`],{encoding:`utf-8`,timeout:W});return t.error!=null||!t.stdout?null:t.stdout.trim()||null}function Si(e){let t=k(`ps`,[`-p`,String(e),`-o`,`%cpu=,%mem=`],{encoding:`utf-8`,timeout:W});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 Ci(e){let t=k(`lsof`,[`-p`,String(e),`-a`,`-d`,`cwd`,`-Fn`],{encoding:`utf-8`,timeout:W});if(t.error!=null)return null;let n=t.stdout??``;for(let e of n.split(`
28
28
  `))if(e.startsWith(`n`)&&e.length>1)return e.slice(1);return null}function wi(e){let t=[],n=e.split(`
@@ -59,7 +59,7 @@ setTimeout(() => process.exit(2), ${t+1e4});
59
59
  `,r),o=-1;if(i!==-1&&a!==-1?o=Math.min(i,a):i===-1?a!==-1&&(o=a):o=i===e.length-1?-1:i,o===-1){n=e.slice(r);break}else{let n=e.slice(r,o);t.push(n),r=o+1,e[r-1]===`\r`&&e[r]===`
60
60
  `&&r++}}return[t,n]}var mo=class extends TransformStream{constructor({onError:e,onRetry:t,onComment:n}={}){let r;super({start(i){r=fo({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 ho={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2};var Y=class extends Error{constructor(e,t){super(`Streamable HTTP error: ${t}`),this.code=e}},go=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=Qi(t?.fetch,t?.requestInit),this._sessionId=t?.sessionId,this._reconnectionOptions=t?.reconnectionOptions??ho}async _authThenStart(){if(!this._authProvider)throw new J(`No auth provider`);let e;try{e=await Ha(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 J;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=Zi(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 Y(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 mo({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=b.parse(JSON.parse(e.data));me(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 J(`No auth provider`);if(await Ha(this._authProvider,{serverUrl:this._url,authorizationCode:e,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})!==`AUTHORIZED`)throw new J(`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:h(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 Y(401,`Server returned 401 after successful authentication`);let{resourceMetadataUrl:t,scope:n}=Ka(o);if(this._resourceMetadataUrl=t,this._scope=n,await Ha(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})!==`AUTHORIZED`)throw new J;return this._hasCompletedAuthFlow=!0,this.send(e)}if(o.status===403&&this._authProvider){let{resourceMetadataUrl:t,scope:n,error:r}=Ka(o);if(r===`insufficient_scope`){let r=o.headers.get(`WWW-Authenticate`);if(this._lastUpscopingHeader===r)throw new Y(403,`Server returned 403 after trying upscoping`);if(n&&(this._scope=n),t&&(this._resourceMetadataUrl=t),this._lastUpscopingHeader=r??void 0,await Ha(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetch})!==`AUTHORIZED`)throw new J;return this.send(e)}}throw new Y(o.status,`Error POSTing to endpoint: ${t}`)}if(this._hasCompletedAuthFlow=!1,this._lastUpscopingHeader=void 0,o.status===202){await o.body?.cancel(),d(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=>b.parse(e)):[b.parse(e)];for(let e of t)this.onmessage?.(e)}else throw await o.body?.cancel(),new Y(-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 Y(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 _o(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 vo(e){if(e===void 0||e===``)return;let t=Number.parseInt(e,10);if(!(Number.isNaN(t)||t<=0))return t}function yo(e){return e===`0.0.0.0`||e===`::`?`localhost`:e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}function bo(e,t){return`http://${yo(e)}:${t}/mcp`}function xo(e,t){return`ws://${yo(e)}:${t}`}function So(e){let t=new URL(e);return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.pathname=``,t.search=``,t.hash=``,t.toString().replace(/\/$/,``)}function Co(e,t){if(!(!e||e.port<=0)&&t(e.pid))return e.port}function wo(e){return M(e)?N(e,`utf-8`).trim():``}function To(e,t){return`server did not start within ${e}ms${t?` stderr:\n${t}`:``}`}function Eo(e){if(e&&typeof e==`object`&&`method`in e&&`id`in e)return e.id}function Do(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 Oo(e,t){return{jsonrpc:`2.0`,id:e,error:{code:-32e3,message:t instanceof Error?t.message:String(t)}}}async function ko(e){let t=e.readLock??(()=>Le(e.lockDir)),n=e.isAlive??C,r=e.sleep??(e=>Ot(e)),i=e.spawn??tt,a=e.readErrorLog??wo,o=e.openErrorLog??(e=>ut(e,`w`)),s=e.closeFd??st,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 bo(`localhost`,t)}let u=Co(t(),n);if(u!==void 0)return bo(`localhost`,u);if(e.envAutoStart===`0`)throw Error(`Open Knowledge server is not running and OK_MCP_AUTOSTART=0 disables auto-start.`);M(e.lockDir)||ct(e.lockDir,{recursive:!0});let d=A(e.lockDir,`last-spawn-error.log`),f=o(d),p,m,h=Ge();try{try{p=i(h.command,[...h.prefixArgs,`start`],{detached:!0,stdio:[`ignore`,`ignore`,f],cwd:e.contentDir,env:{...process.env,OK_LOCK_KIND:`mcp-spawned`}}),p.on(`error`,e=>{m=e instanceof Error?e.message:String(e)}),p.unref()}catch(e){m=e instanceof Error?e.message:String(e)}}finally{try{s(f)}catch{}}let ee=Date.now()+c;for(;Date.now()<ee;){if(m){let e=a(d),t=e?` stderr:\n${e}`:``;throw Error(`spawn failed: ${m}${t}`)}await r(l);let e=Co(t(),n);if(e!==void 0)return bo(`localhost`,e)}if(m){let e=a(d),t=e?` stderr:\n${e}`:``;throw Error(`spawn failed: ${m}${t}`)}throw Error(To(c,a(d)))}function Ao(e,t){if(e.portOverride!==void 0)return So(t);let n=e.readLock??(()=>Le(e.lockDir)),r=e.isAlive??C,i=Co(n(),r);if(i!==void 0)return xo(`localhost`,i)}async function jo(e,t={}){let n=t.stderr??process.stderr,r=t.requestTimeoutMs??12e4,i=t.createStdioTransport?t.createStdioTransport(t.stdin,t.stdout):new Ki(t.stdin,t.stdout),a=t.createHttpTransport?t.createHttpTransport(new URL(e)):new go(new URL(e),{fetch:_o(r),...t.connectionId===void 0?{}:{requestInit:{headers:{[c]: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 l=Promise.resolve();i.onmessage=e=>{l=l.then(async()=>{try{await a.send(e)}catch(t){let r=Eo(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(Oo(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=Do(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 Mo(e){let t=e.stderr??process.stderr,n=e.bridgeFn??jo,r=await ko(e),i=e.createConnectionId?.()??Et(),a=!1,o=(e.startKeepalive??Xi)({connectionId:i,resolveWsUrl:async()=>Ao(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 No=xt(import.meta.url);function Po(e){let t=j(e);for(;;){if(pe(t))return t;let n=it(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 \`${he}\`).`);t=n}}function Fo(e){try{let t=new URL(e);return t.protocol===`file:`?xt(t):void 0}catch{return}}async function Io(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=Fo(n[0].uri);return r===void 0&&e.log?.(`single root URI not usable as fs path: ${n[0].uri}`),r}async function Lo(e,t){if(e!==void 0)return Po(e);let n=await t();if(n!==void 0)return Po(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 Ro(e){let t=process.stderr,n=e.spawnTimeoutMs??vo(process.env.OK_MCP_SPAWN_TIMEOUT_MS),r=e.envAutoStart??process.env.OK_MCP_AUTOSTART,i=We({startupCwd:e.startupCwd,startupConfig:e.startupConfig}),o=new p({name:a,version:ze},{instructions:oe({dir:`.`})});ue(o);let s=Et(),c={current:{connectionId:s,displayName:s,colorSeed:s}},l=new Map,d=e=>{if(l.has(e))return;let n=f(e),r=c.current,i=Xi({connectionId:s,displayName:r.displayName,clientName:r.clientInfo?.name??r.displayName,colorSeed:r.colorSeed,resolveWsUrl:async()=>Ao({lockDir:n,contentDir:e},``),log:n=>t.write(`[mcp] keepalive[${e}]: ${n}\n`)});l.set(e,i)},m=()=>Io({getClientCapabilities:()=>o.server.getClientCapabilities(),listRoots:()=>o.server.listRoots(),log:e=>t.write(`[mcp] ${e}\n`)}),h=e=>Lo(e,m),ee=async e=>{let t;if(e===void 0){let e=await m();if(e===void 0)return;t=Po(e)}else t=Po(e);let a=await i(t),o=await ko({lockDir:f(t),contentDir:u(a,t),envAutoStart:r,...n===void 0?{}:{timeoutMs:n}});return d(t),o.replace(/\/mcp$/,``)};o.server.oninitialized=()=>{let e=o.server.getClientVersion(),t=ae(e?.name,s);c.current={connectionId:s,clientInfo:e?{name:t,version:e.version}:void 0,displayName:t,colorSeed:t}},ye(o,{serverUrl:ee,resolveCwd:h,config:i,identityRef:c});let g=new Ki,_=!1,v,y=async()=>{if(_)return;_=!0,v?.stop();for(let e of l.values())try{e.close()}catch(e){t.write(`[mcp] keepalive close error: ${e instanceof Error?e.message:String(e)}\n`)}l.clear();let e=await Promise.allSettled([o.close(),g.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 o.connect(g),t.write(`[mcp] global stdio server ready (per-call project routing)
61
61
  `);let b=!1,x=()=>{b||(b=!0,setTimeout(()=>{t.write(`[mcp] shutdown deadline (5s) reached — forcing exit(1)
62
- `),process.exit(1)},5e3).unref(),y().finally(()=>{process.exit(0)}))};if(process.once(`SIGINT`,x),process.once(`SIGTERM`,x),process.platform===`darwin`){let e=Yi(No,{realpathSync:ft,statInoSync:e=>mt(e).ino,log:e=>t.write(`${e}\n`)});if(e!==void 0){t.write(`[mcp] bundle identity anchor=${e.resolvedPath} inode=${e.inode} version=${ze}\n`);let{resolvedPath:n,inode:r}=e;v=Ji({detect:()=>qi({bundleAnchorPath:No,currentInode:r,platform:process.platform,realpath:ft,statInode:e=>mt(e).ino}),onReplaced:e=>{t.write(`[mcp] bundle replaced anchor=${n} bootInode=${e.currentInode} onDiskInode=${e.onDiskInode} version=${ze} — exiting for host respawn\n`),x()},log:e=>t.write(`[mcp] ${e}\n`)})}}return{close:y}}function zo(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`,void 0).action(async t=>{try{let n=e(),r=process.cwd();if(t.port!==void 0){let e=vo(process.env.OK_MCP_SPAWN_TIMEOUT_MS);await Mo({lockDir:``,contentDir:``,portOverride:t.port,envAutoStart:process.env.OK_MCP_AUTOSTART,timeoutMs:e});return}await Ro({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 Bo(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-DA93kG_C.mjs`),r=e(),i=process.cwd(),a=u(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 Vo(e){return e==null?!1:e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function Ho(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 Uo(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:bi(r),command:r,isDesktop:Vo(r)}}function Wo(e){return e.ui==null?!1:e.ui.status===`alive`||e.ui.status===`foreign-host`}function Go(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:t===`dead-pid`&&Wo(e)?`ui-orphan`:`stale`}const Ko=new Set([`running`,`desktop`,`foreign`,`ui-orphan`]);function qo(e){switch(e){case`running`:return U.default.green(e);case`desktop`:return U.default.blue(e);case`foreign`:return U.default.cyan(e);case`ui-orphan`:return U.default.magenta(e);case`stale`:return U.default.yellow(e)}}function Jo(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function Yo(e){return`${Jo(e.server.usage)} | ${Jo(e.ui?.usage??null)}`}function Xo(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null||e.ui.status===`dead-pid`?`—`:String(e.ui.port)}`}function Zo(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=Go(e),n=t===`ui-orphan`&&e.ui!=null?e.ui.pid:e.server.pid;return[e.directory,Xo(e),Yo(e),t,String(n),Ho(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=qo(Go(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=U.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
62
+ `),process.exit(1)},5e3).unref(),y().finally(()=>{process.exit(0)}))};if(process.once(`SIGINT`,x),process.once(`SIGTERM`,x),process.platform===`darwin`){let e=Yi(No,{realpathSync:ft,statInoSync:e=>mt(e).ino,log:e=>t.write(`${e}\n`)});if(e!==void 0){t.write(`[mcp] bundle identity anchor=${e.resolvedPath} inode=${e.inode} version=${ze}\n`);let{resolvedPath:n,inode:r}=e;v=Ji({detect:()=>qi({bundleAnchorPath:No,currentInode:r,platform:process.platform,realpath:ft,statInode:e=>mt(e).ino}),onReplaced:e=>{t.write(`[mcp] bundle replaced anchor=${n} bootInode=${e.currentInode} onDiskInode=${e.onDiskInode} version=${ze} — exiting for host respawn\n`),x()},log:e=>t.write(`[mcp] ${e}\n`)})}}return{close:y}}function zo(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`,void 0).action(async t=>{try{let n=e(),r=process.cwd();if(t.port!==void 0){let e=vo(process.env.OK_MCP_SPAWN_TIMEOUT_MS);await Mo({lockDir:``,contentDir:``,portOverride:t.port,envAutoStart:process.env.OK_MCP_AUTOSTART,timeoutMs:e});return}await Ro({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 Bo(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-DMNyrQqL.mjs`),r=e(),i=process.cwd(),a=u(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 Vo(e){return e==null?!1:e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function Ho(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 Uo(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:bi(r),command:r,isDesktop:Vo(r)}}function Wo(e){return e.ui==null?!1:e.ui.status===`alive`||e.ui.status===`foreign-host`}function Go(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:t===`dead-pid`&&Wo(e)?`ui-orphan`:`stale`}const Ko=new Set([`running`,`desktop`,`foreign`,`ui-orphan`]);function qo(e){switch(e){case`running`:return U.default.green(e);case`desktop`:return U.default.blue(e);case`foreign`:return U.default.cyan(e);case`ui-orphan`:return U.default.magenta(e);case`stale`:return U.default.yellow(e)}}function Jo(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function Yo(e){return`${Jo(e.server.usage)} | ${Jo(e.ui?.usage??null)}`}function Xo(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null||e.ui.status===`dead-pid`?`—`:String(e.ui.port)}`}function Zo(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=Go(e),n=t===`ui-orphan`&&e.ui!=null?e.ui.pid:e.server.pid;return[e.directory,Xo(e),Yo(e),t,String(n),Ho(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=qo(Go(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=U.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
63
63
  `)}async function Qo(e={}){let t=e.discover??Ti,n=e.inspect??V,r=e.log??(e=>console.log(e)),i=e.resolveCommand??xi,a=e.resolveUsage??Si,o=await t(),s=[];for(let e of o){let t=n(e,`server`),r=n(e,`ui`),o=Uo(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:Go(e)}));r(JSON.stringify(e,null,2));return}r(Zo(e.all?s:s.filter(e=>Ko.has(Go(e)))))}function $o(){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 Qo({all:t.all===!0||e===`all`,json:t.json===!0})})}function X(e,t){e&&process.stdout.write(`${JSON.stringify(t)}\n`)}async function es(e,t,n=process.cwd()){let r=e.op??`sync`,i=Le(m(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`},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}`)}X(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=Be({baseDir:n});if(r===`sync`||r===`pull`){X(e.json,{type:`step`,step:`pull`});let t=await a.pull();X(e.json,{type:`pull`,summary:t.summary}),e.json||process.stderr.write(` pull: ${t.summary.changes} changes\n`)}(r===`sync`||r===`push`)&&(X(e.json,{type:`step`,step:`push`}),await a.push(),X(e.json,{type:`push`,ok:!0}),e.json||process.stderr.write(` push: ok
64
64
  `)),X(e.json,{type:`complete`,op:r}),e.json||process.stderr.write(`✓ ${r} complete\n`)}function ts(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 es({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 ns(e){return new t(`pull`).description(`Pull changes from the remote`).option(`--json`,`Output JSONL progress events`,!1).action(async t=>{try{await es({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 rs(e){return new t(`push`).description(`Push commits to the remote`).option(`--json`,`Output JSONL progress events`,!1).action(async t=>{try{await es({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 is(e){return typeof e==`string`&&r.includes(e)}async function as(e={}){let t=j(e.cwd??process.cwd()),n=e.pack??`knowledge-base`;if(!ve[n])return{status:`failed`,message:`${D(`Error:`)} Unknown pack "${n}". Available: ${r.join(`, `)}`,exitCode:1};let i;try{i=await s({projectDir:t,rootDir:e.root,packId:n})}catch(e){return e instanceof y?{status:`prerequisite-missing`,message:`${D(`Error:`)} ${e.message}`,exitCode:1}:{status:`failed`,message:`${D(`Error:`)} ${e instanceof Error?e.message:String(e)}`,exitCode:1}}if(i.created.length===0){let e=ve[n].name;return{status:`no-op`,message:`${E(`Your ${e} pack is already seeded.`)}\n${T(`Nothing to do.`)}`,plan:i,exitCode:0}}if(e.dryRun)return{status:`dry-run`,message:`${O(`Plan (dry-run — no changes made):`)}\n\n${ss(i,t)}`,plan:i,exitCode:0};if(!e.yes&&!await cs(`${O(`Plan:`)}\n\n${ss(i,t)}\n\n${O(`Apply?`)} ${T(`[Y/n] `)}`,e.confirmStream))return{status:`cancelled`,message:T(`Cancelled.`),plan:i,exitCode:0};let a=await re(i,{projectDir:t,packId:n});if(a.errors.length>0){let e=a.errors.map(e=>` ${D(`✗`)} ${e.path}: ${e.error}`);return{status:`failed`,message:[`${Qe(`Applied`)} ${a.applied} entries, ${Qe(String(a.errors.length))} error(s):`,...e].join(`
65
65
  `),plan:i,exitCode:1}}let o=ve[n].name;return{status:`applied`,message:`${E(`✓ Seeded ${o}`)} ${T(`(${a.applied} entries, ${a.durationMs}ms)`)}`,plan:i,exitCode:0}}function os(){let e=[O(`Available packs:`)];for(let t of r){let n=ve[t];e.push(` ${E(t)} ${T(`—`)} ${n.name}: ${n.description}`)}return e.join(`
@@ -0,0 +1,2 @@
1
+ import"./dist-DHj61EG5.mjs";var e=`0.5.0-beta.48`;const t=`config.yml`,n=e;export{n,t};
2
+ //# sourceMappingURL=constants-xPQnQB6p.mjs.map
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{d as e,f as t,g as n,h as r,i,m as a,r as o,s,t as c,u as l,v as u,y as d}from"./init-CmQ_C7Dm.mjs";import{i as f,n as p,r as m,t as h}from"./src-CzxqX1w-.mjs";import{n as g}from"./loader-CHhQuNxK.mjs";import{n as _}from"./preview-CIgVuEry.mjs";export{a as ALL_EDITOR_IDS,r as EDITOR_LABELS,n as EDITOR_TARGETS,c as LAUNCH_CONFIG_NAME,o as classifyExistingMcpEntry,i as detectInstalledEditors,d as initContent,g as loadConfig,m as parseGitHubBlobUrl,f as parseGitUrl,_ as previewContent,s as readExistingMcpEntry,u as resolveProjectRoot,l as scaffoldLaunchJson,p as validateLocalFolderForShare,e as writeEditorMcpConfig,h as writeProjectAiIntegrations,t as writeUserMcpConfigs};
1
+ import{d as e,f as t,g as n,h as r,i,m as a,r as o,s,t as c,u as l,v as u,y as d}from"./init-OOHQMBAG.mjs";import{i as f,n as p,r as m,t as h}from"./src-C0OBIJW_.mjs";import{n as g}from"./loader-BeazNH_4.mjs";import{n as _}from"./preview-D4eVomfX.mjs";export{a as ALL_EDITOR_IDS,r as EDITOR_LABELS,n as EDITOR_TARGETS,c as LAUNCH_CONFIG_NAME,o as classifyExistingMcpEntry,i as detectInstalledEditors,d as initContent,g as loadConfig,m as parseGitHubBlobUrl,f as parseGitUrl,_ as previewContent,s as readExistingMcpEntry,u as resolveProjectRoot,l as scaffoldLaunchJson,p as validateLocalFolderForShare,e as writeEditorMcpConfig,h as writeProjectAiIntegrations,t as writeUserMcpConfigs};
@@ -0,0 +1 @@
1
+ import{l as e}from"./init-OOHQMBAG.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{$r as a,D as o,Mt as s,N as c,Pt as l,Wn as u,_i as d,ai as f,an as p,ci as m,ei as h,fi as g,gi as _,ii as v,in as y,oi as b,on as x,pn as S,un as C}from"./dist-DHj61EG5.mjs";import{n as ee,t as te}from"./constants-BbmMpMCp.mjs";import{t as w}from"./is-object-C-4FJ0rP.mjs";import{i as T,o as E,r as ne,s as D,t as O}from"./colors-BtKMHmBX.mjs";import{t as re}from"./preview-CIgVuEry.mjs";import{execFileSync as ie}from"node:child_process";import ae,{basename as oe,dirname as k,isAbsolute as A,join as j,posix as M,relative as N,resolve as P,sep as F,win32 as I}from"node:path";import{cpSync as se,existsSync as L,lstatSync as ce,mkdirSync as R,readFileSync as z,realpathSync as le,rmSync as ue,writeFileSync as B}from"node:fs";import V from"node:process";import{homedir as H}from"node:os";import{AsyncLocalStorage as de,AsyncResource as fe}from"node:async_hooks";import{stripVTControlCharacters as pe,styleText as U}from"node:util";import*as me from"node:readline";import{randomUUID as he}from"node:crypto";import{createServer as ge,request as _e}from"node:http";import{connect as ve}from"node:net";function ye(){return V.platform.startsWith(`win`)?!!V.env.CI||!!V.env.WT_SESSION||!!V.env.TERMINUS_SUBLIME||V.env.ConEmuTask===`{cmd::Cmder}`||V.env.TERM_PROGRAM===`Terminus-Sublime`||V.env.TERM_PROGRAM===`vscode`||V.env.TERM===`xterm-256color`||V.env.TERM===`alacritty`||V.env.TERMINAL_EMULATOR===`JetBrains-JediTerm`:V.env.TERM!==`linux`}const be={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:`╱`},xe={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:`⅒`},Se={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`},Ce={...be,...xe},we={...be,...Se},W=ye()?Ce:we;Object.entries(xe);var Te=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 Ee=(()=>{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}})(),De=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,Oe=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,ke=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Ae=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,je=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,Me=/\t{1,1000}/y,Ne=/[\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,Pe=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Fe=/\p{M}+/gu,Ie={limit:1/0,ellipsis:``},Le=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?Le(i,Ie,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[Pe,l],[ke,0],[Ae,o],[Me,s],[Ne,c],[je,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(Fe,``)){let t=e.codePointAt(0)||0;if(S=De(t)?2:Oe(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===je?Ee(e.slice(p,n.lastIndex)):n===Ne?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}},Re={limit:1/0,ellipsis:``,ellipsisWidth:0},G=(e,t={})=>Le(e,Re,t).width,ze=`]8;;`,Be=RegExp(`(?:\\[(?<code>\\d+)m|\\${ze}(?<uri>.*))`,`y`),Ve=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},He=e=>`[${e}m`,Ue=e=>`${ze}${e}`,We=(e,t,n)=>{let r=t[Symbol.iterator](),i=!1,a=!1,o=e.at(-1),s=o===void 0?0:G(o),c=r.next(),l=r.next(),u=0;for(;!c.done;){let o=c.value,d=G(o);s+d<=n?e[e.length-1]+=o:(e.push(o),s=0),(o===`\x1B`||o===`›`)&&(i=!0,a=t.startsWith(ze,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())},Ge=e=>{let t=e.split(` `),n=t.length;for(;n&&!G(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},Ke=(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=G(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=G(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(``),We(s,r,t),c=G(s.at(-1)??``);continue}if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){We(s,r,t),c=G(s.at(-1)??``);continue}s.push(``),c=0}if(c+i>t&&n.wordWrap===!1){We(s,r,t),c=G(s.at(-1)??``);continue}s[s.length-1]+=r,c+=i}n.trim!==!1&&(s=s.map(e=>Ge(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{$r as a,D as o,Mt as s,N as c,Pt as l,Wn as u,_i as d,ai as f,an as p,ci as m,ei as h,fi as g,gi as _,ii as v,in as y,oi as b,on as x,pn as S,un as C}from"./dist-DHj61EG5.mjs";import{n as ee,t as te}from"./constants-xPQnQB6p.mjs";import{t as w}from"./is-object-C-4FJ0rP.mjs";import{i as T,o as E,r as ne,s as D,t as O}from"./colors-BtKMHmBX.mjs";import{t as re}from"./preview-D4eVomfX.mjs";import{execFileSync as ie}from"node:child_process";import ae,{basename as oe,dirname as k,isAbsolute as A,join as j,posix as M,relative as N,resolve as P,sep as F,win32 as I}from"node:path";import{cpSync as se,existsSync as L,lstatSync as ce,mkdirSync as R,readFileSync as z,realpathSync as le,rmSync as ue,writeFileSync as B}from"node:fs";import V from"node:process";import{homedir as H}from"node:os";import{AsyncLocalStorage as de,AsyncResource as fe}from"node:async_hooks";import{stripVTControlCharacters as pe,styleText as U}from"node:util";import*as me from"node:readline";import{randomUUID as he}from"node:crypto";import{createServer as ge,request as _e}from"node:http";import{connect as ve}from"node:net";function ye(){return V.platform.startsWith(`win`)?!!V.env.CI||!!V.env.WT_SESSION||!!V.env.TERMINUS_SUBLIME||V.env.ConEmuTask===`{cmd::Cmder}`||V.env.TERM_PROGRAM===`Terminus-Sublime`||V.env.TERM_PROGRAM===`vscode`||V.env.TERM===`xterm-256color`||V.env.TERM===`alacritty`||V.env.TERMINAL_EMULATOR===`JetBrains-JediTerm`:V.env.TERM!==`linux`}const be={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:`╱`},xe={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:`⅒`},Se={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`},Ce={...be,...xe},we={...be,...Se},W=ye()?Ce:we;Object.entries(xe);var Te=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 Ee=(()=>{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}})(),De=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,Oe=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,ke=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Ae=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,je=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,Me=/\t{1,1000}/y,Ne=/[\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,Pe=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Fe=/\p{M}+/gu,Ie={limit:1/0,ellipsis:``},Le=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?Le(i,Ie,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[Pe,l],[ke,0],[Ae,o],[Me,s],[Ne,c],[je,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(Fe,``)){let t=e.codePointAt(0)||0;if(S=De(t)?2:Oe(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===je?Ee(e.slice(p,n.lastIndex)):n===Ne?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}},Re={limit:1/0,ellipsis:``,ellipsisWidth:0},G=(e,t={})=>Le(e,Re,t).width,ze=`]8;;`,Be=RegExp(`(?:\\[(?<code>\\d+)m|\\${ze}(?<uri>.*))`,`y`),Ve=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},He=e=>`[${e}m`,Ue=e=>`${ze}${e}`,We=(e,t,n)=>{let r=t[Symbol.iterator](),i=!1,a=!1,o=e.at(-1),s=o===void 0?0:G(o),c=r.next(),l=r.next(),u=0;for(;!c.done;){let o=c.value,d=G(o);s+d<=n?e[e.length-1]+=o:(e.push(o),s=0),(o===`\x1B`||o===`›`)&&(i=!0,a=t.startsWith(ze,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())},Ge=e=>{let t=e.split(` `),n=t.length;for(;n&&!G(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},Ke=(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=G(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=G(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(``),We(s,r,t),c=G(s.at(-1)??``);continue}if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){We(s,r,t),c=G(s.at(-1)??``);continue}s.push(``),c=0}if(c+i>t&&n.wordWrap===!1){We(s,r,t),c=G(s.at(-1)??``);continue}s[s.length-1]+=r,c+=i}n.trim!==!1&&(s=s.map(e=>Ge(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===`›`){Be.lastIndex=e+1;let t=Be.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+=Ue(``));let e=i?Ve(i):void 0;i&&e&&(r+=He(e))}else t===`
4
4
  `&&(i&&Ve(i)&&(r+=He(i)),a&&(r+=Ue(a)))}return r},qe=/\r?\n/;function Je(e,t,n){return String(e).normalize().split(qe).map(e=>Ke(e,t,n)).join(`
@@ -405,5 +405,5 @@ last-spawn-error.log
405
405
  `)?n:`${n}\n`,`utf-8`)}function Br(e,t){let n;try{n=le(t)}catch{n=P(t)}let r;try{r=ce(e)}catch(e){if(e.code!==`ENOENT`)throw e}if(r?.isSymbolicLink())throw Error(`Refusing to write through a symbolic link at ${e}. Remove the symlink and re-run \`ok init\`, or pass \`--no-mcp\` to skip MCP config writes.`);let i=k(e);for(;i.length>1&&i!==F;){let t;try{t=le(i)}catch(e){if(e.code===`ENOENT`){i=k(i);continue}throw e}let r=N(n,t);if(r===``||!r.startsWith(`..`)&&!A(r))return;throw Error(`Refusing to write at ${e}: ancestor ${i} resolves to ${t}, which is outside the project directory ${n}. A symbolic link in the path likely escapes the project. Remove the symlink and re-run, or pass \`--no-mcp\`.`)}}const Vr=e=>e!==`project`,Hr=e=>e!==`user`;async function Ur(){let e=await dn({message:`Where should the MCP server be configured?
406
406
  `,required:!1,theme:{icon:{checked:`[x]`,unchecked:`[ ]`}},choices:[{name:`User-level (~/.claude.json, ~/.cursor/mcp.json, …)`,value:`user`,checked:!0},{name:`Project-level (.mcp.json, .cursor/mcp.json, …)`,value:`project`,checked:!0}]});return e.includes(`user`)&&e.includes(`project`)?`both`:e.includes(`user`)?`user`:e.includes(`project`)?`project`:null}async function Wr(e){return e.mcp===!1?null:e.scope?e.scope:e.isTTY??process.stdout.isTTY?(e.promptFn??Ur)():`both`}const Gr=`0.0.1`,Kr=`open-knowledge-ui`,qr=[`-y`,`@inkeep/open-knowledge@latest`,`ui`];function Jr(e,t={}){let n=j(e,`.claude`,`launch.json`),r=t.cliPath===void 0?t.mode===`dev`?{name:Kr,runtimeExecutable:`node`,runtimeArgs:[or(),`ui`],port:kr,autoPort:!0}:{name:Kr,runtimeExecutable:`npx`,runtimeArgs:[...qr],port:kr,autoPort:!0}:{name:Kr,runtimeExecutable:t.cliPath,runtimeArgs:[`ui`],port:kr,autoPort:!0};try{if(Br(n,e),!L(n))return R(k(n),{recursive:!0}),B(n,`${JSON.stringify({version:Gr,configurations:[r]},null,2)}\n`,`utf-8`),{action:`created`,configPath:n};let t=z(n,`utf-8`).trim(),i=t?JSON.parse(t):{};if(!w(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=>w(e)&&e.name===`open-knowledge-ui`);o>=0?a[o]=r:a.push(r);let s={...i,version:i.version??Gr,configurations:a};return B(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 Yr(e,t,n){try{return L(e.detectPath?.(t,n)??k(e.configPath(t,n)))}catch{return!1}}function Xr(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&&!Yr(e,t,r))return{editorId:e.id,label:e.label,action:`skipped-missing`,configPath:o,serverName:a};if(i!==void 0)try{Br(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.format===`toml`?Lr(o):Ir(o)}catch(t){return{editorId:e.id,label:e.label,action:`failed`,configPath:o,serverName:a,error:t instanceof Error?t.message:String(t)}}let c=s[e.topLevelKey]??{},l=c[a],u;try{u=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)}}let d={...s,[e.topLevelKey]:{...c,[a]:u}};try{e.format===`toml`?zr(o,d):Rr(o,d)}catch(t){return{editorId:e.id,label:e.label,action:`failed`,configPath:o,serverName:a,error:t instanceof Error?t.message:String(t)}}return{editorId:e.id,label:e.label,action:l===void 0?`written`:`overwritten`,configPath:o,serverName:a,...i===void 0?{}:{configScope:`project`}}}function Zr(e,t){let n=e.projectSkillPath?.(t);if(!n)return{editorId:e.id,label:e.label,action:`skipped-unsupported`,path:``};try{let r=u(),i=k(n);Br(i,t);let a=L(n)?`overwritten`:`written`;return ue(i,{recursive:!0,force:!0}),R(k(i),{recursive:!0}),se(r,i,{recursive:!0}),{editorId:e.id,label:e.label,action:a,path:n}}catch(t){return{editorId:e.id,label:e.label,action:`failed`,path:n,error:t instanceof Error?t.message:String(t)}}}function Qr(e,t){let n=e.projectConfigPath?.(t);if(!(!n||!L(n)))return{editorId:e.id,label:e.label,path:n}}async function $r(e){let t=vr(e.editors),n={mode:`published`,cliPath:e.cliPath,skipAvailabilityCheck:!0};return t.map(t=>Xr(t,``,n,e.home))}function ei(e,t,n,r){let i=ti(e,t,n,r);return i.kind===`present`?i.entry:null}function ti(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=z(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`?Lr(i):Ir(i)}catch(e){return{kind:`corrupt`,error:e instanceof Error?e.message:String(e)}}let s=o[e.topLevelKey];if(!w(s))return{kind:`no-entry`};let c=s[e.serverName(t)];return w(c)?{kind:`present`,entry:c}:{kind:`no-entry`}}async function ni(e={}){let t=P(e.cwd??process.cwd()),n=tr(t,{homeDir:e.home}),r=n.projectRoot,i=!L(j(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 ${N(r,t)} because it contains a .git folder`);let a={mode:e.devMcp?`dev`:`published`},o=await l(r),c;try{c=Qn(r,{contentDir:n.defaultContentDir})}catch(t){let n=Q.claude.configPath(r,e.home);return{projectRoot:r,contentCreated:[],contentUpdated:[],contentSkipped:[],editors:[],projectSkills:[],legacyProjectConfigs:[],didGitInit:o.didInit,claudeDesktopDetected:!1,mcpAction:`failed`,mcpPath:n,mcpError:`Content scaffolding failed: ${t instanceof Error?t.message:String(t)}`}}let u=await Wr({scope:e.scope,mcp:e.mcp,isTTY:e.isTTY,promptFn:e.promptFn}),d=e.editors??ii(r,e.home),f=e.editors??nr.filter(e=>Q[e].projectConfigPath!==void 0),p=vr(d),m=vr(f),h=e.mcp===!1||u===null,g=Array.from(new Map([...p,...h?[]:m].map(e=>[e.id,e])).values()),_=p.filter(t=>Yr(t,r,e.home)),v=[],b=[],x=new Set;for(let t of g){if(h){let n=``;try{n=t.configPath(r,e.home)}catch{}v.push({editorId:t.id,label:t.label,action:`skipped-flag`,configPath:n,serverName:t.serverName(r)});continue}if(Vr(u)&&p.includes(t)&&v.push(Xr(t,r,a,e.home)),Hr(u)&&m.includes(t)&&t.projectConfigPath){let n=t.projectConfigPath(r),i=Xr(t,r,a,e.home,n);v.push(i),(i.action===`written`||i.action===`overwritten`)&&(x.add(n),b.push(Zr(t,r)))}}let S=!h&&u!==null&&Hr(u)?m.filter(e=>!e.projectConfigPath).map(e=>e.label):void 0,C=h?[]:_.map(e=>Qr(e,r)).filter(e=>e!==void 0).filter(e=>!x.has(e.path)),ee=_.some(e=>e.id===`claude`)&&!h?Jr(r,a):void 0,te=await(e.installUserSkill??y)({home:e.home}),w=s({home:e.home}),T=h?`skipped-flag`:`skipped-missing`,E=v.find(e=>e.editorId===`claude`)??v[0]??{action:T,configPath:Q.claude.configPath(r,e.home)};return{projectRoot:r,contentCreated:c.created,contentUpdated:c.updated,contentSkipped:c.skipped,editors:v,projectSkills:b,legacyProjectConfigs:C,launchJson:ee,skillInstall:te,didGitInit:o.didInit,claudeDesktopDetected:w,mcpAction:E.action,mcpPath:E.configPath,mcpError:`error`in E?E.error:void 0,projectScopeUnsupportedLabels:S}}function ri(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)?N(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)`);let c=j(t,`.ok`);if(e.contentCreated.length>0||e.contentUpdated.length>0?(n.push(O(`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(O(`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(O(`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(O(`MCP server configuration:`)),n.push(` No supported editor config directories detected; skipped MCP registration`);else{n.push(O(`MCP server configuration:`));for(let r of e.editors){let i=r.configPath.startsWith(t)?N(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} ${E(`registered`)}${a}${u}`);break;case`overwritten`:n.push(` ${c}${l}${i} ${E(`updated`)}${a}${u}`);break;case`skipped-missing`:n.push(` ${c}${l}${i} config root missing; skipped`);break;case`failed`:n.push(` ${c}${l}${i} ${ne(`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(O(`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?N(t,r.path):``;switch(r.action){case`written`:n.push(` ${e}${i}${a} ${E(`installed`)}`);break;case`overwritten`:n.push(` ${e}${i}${a} ${E(`updated`)}`);break;case`skipped-unsupported`:n.push(` ${e}${i}no known project skill surface; skipped`);break;case`failed`:n.push(` ${e}${i}${a} ${ne(`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} ${N(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(O(`User-global skill:`)),e.skillInstall){case`installed`:n.push(` open-knowledge ${E(`installed to detected agent hosts`)} via \`npx skills\``);break;case`skip-current`:n.push(` open-knowledge ${E(`already installed at current version`)}`);break;case`failed`:n.push(` ${D(`open-knowledge install failed — MCP still configured; run manually:`)}`),n.push(` ${D(` 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: ${O(`ok install-skill`)}`)),e.preview?(n.push(``),n.push(re(e.preview,t))):e.previewWarning&&(n.push(``),n.push(`Content preview unavailable: ${e.previewWarning}`)),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(`${E(`✓`)} ${O(`Next steps:`)}`),n.push(` 1. Open your editor (${T(r.join(` / `))})`),n.push(` 2. Approve the MCP server when prompted`),n.push(` 3. (Optional) scaffold the starter knowledge-base structure:`),n.push(` - ${T(`ok seed`)} — empty repo, Karpathy 3-layer`),n.push(` - ${T(`mcp__open-knowledge__discover`)} — existing repo, extract conventions`),n.push(` 4. Use the MCP workflow tools as you build the wiki:`),n.push(` - ${T(`mcp__open-knowledge__ingest`)} — capture an external source`),n.push(` - ${T(`mcp__open-knowledge__research`)} — gather sources and write findings`),n.push(` - ${T(`mcp__open-knowledge__consolidate`)} — promote research to canonical articles`)}return n.join(`
407
407
  `)}function ii(e,t){let n=[];for(let r of nr)Yr(Q[r],e,t)&&n.push(r);return n}function ai(){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`])).action(async e=>{let t=process.cwd(),n;try{n=await ni({cwd:t,mcp:e.mcp,devMcp:e.devMcp,scope:e.scope})}catch(e){if(e instanceof c){process.stderr.write(`open-knowledge requires git to initialize a parent repo. Install git or run 'git init' yourself, then re-run.
408
- `),e.stderr&&process.stderr.write(`${e.stderr.trim()}\n`),process.exitCode=1;return}throw e}try{let{previewContent:e}=await import(`./preview-DA93kG_C.mjs`),{loadConfig:t}=await import(`./loader-CKCKCJLW.mjs`),{resolveContentDir:r}=await import(`./dist-ChwYnRqt.mjs`),{config:i}=t(n.projectRoot),a=r(i,n.projectRoot);n.preview=e({projectDir:n.projectRoot,contentDir:a})}catch(e){n.previewWarning=e instanceof Error?e.message:String(e)}process.stdout.write(`${ri(n,n.projectRoot)}\n`),(n.editors.some(e=>e.action===`failed`)||n.mcpAction===`failed`)&&(process.exitCode=1)})}export{W as A,pt as C,Ye as D,ot as E,Je as O,ut as S,ht as T,ir as _,ri as a,ft as b,Wr as c,Xr as d,$r as f,Q as g,rr as h,ii as i,Te as k,ni as l,nr as m,qr as n,ai as o,Fr as p,ti as r,ei as s,Kr as t,Jr as u,tr as v,dt as w,lt as x,Qn as y};
409
- //# sourceMappingURL=init-CmQ_C7Dm.mjs.map
408
+ `),e.stderr&&process.stderr.write(`${e.stderr.trim()}\n`),process.exitCode=1;return}throw e}try{let{previewContent:e}=await import(`./preview-DMNyrQqL.mjs`),{loadConfig:t}=await import(`./loader-uwvpQlbv.mjs`),{resolveContentDir:r}=await import(`./dist-ChwYnRqt.mjs`),{config:i}=t(n.projectRoot),a=r(i,n.projectRoot);n.preview=e({projectDir:n.projectRoot,contentDir:a})}catch(e){n.previewWarning=e instanceof Error?e.message:String(e)}process.stdout.write(`${ri(n,n.projectRoot)}\n`),(n.editors.some(e=>e.action===`failed`)||n.mcpAction===`failed`)&&(process.exitCode=1)})}export{W as A,pt as C,Ye as D,ot as E,Je as O,ut as S,ht as T,ir as _,ri as a,ft as b,Wr as c,Xr as d,$r as f,Q as g,rr as h,ii as i,Te as k,ni as l,nr as m,qr as n,ai as o,Fr as p,ti as r,ei as s,Kr as t,Jr as u,tr as v,dt as w,lt as x,Qn as y};
409
+ //# sourceMappingURL=init-OOHQMBAG.mjs.map
@@ -1,4 +1,4 @@
1
- import{Jr as e,Mi as t,Yr as n,f as r,pi as i,yi as a}from"./dist-DHj61EG5.mjs";import{t as o}from"./constants-BbmMpMCp.mjs";import{t as s}from"./is-object-C-4FJ0rP.mjs";import{resolve as c}from"node:path";import{existsSync as l,readFileSync as u}from"node:fs";import{realpath as d}from"node:fs/promises";async function f(e){let t=c(e);try{return await d(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 p=t();function m(e,t){let n={...e};for(let r of Object.keys(t)){let i=e[r],a=t[r];s(a)&&s(i)?n[r]=m(i,a):a!==void 0&&(n[r]=a)}return n}function h(e){if(!l(e))return{value:null,path:e,source:null,doc:null};let t;try{t=u(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,p.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 s(r)?{value:r,path:e,source:t,doc:n}:{value:null,path:e,source:t,doc:n}}const g=[`include`,`exclude`];function _(e){let t="Run `ok config migrate` to strip the obsolete key from config.yml automatically, or remove it by hand.";return e===`exclude`?[`Move these patterns to .okignore at the project root (gitignore syntax, 1:1 migration).`,t].join(` `):[`content.include has been removed.`,`For subdirectory scoping, set content.dir in .ok/config.yml instead.`,`For pattern-based filtering, use .okignore (gitignore syntax — exclude-only; do not copy include patterns directly).`,t].join(` `)}function v(e){let t=e.value;if(!s(t))return[];let n=t.content;if(!s(n))return[];let r=[];for(let t of g)if(t in n){let n=[`content`,t],i;e.doc!==null&&e.source!==null&&(i=a({file:e.path,source:e.source,doc:e.doc,path:n})),r.push({code:`REMOVED_KEY`,path:n,redirect:_(t),...i===void 0?{}:{source:i}})}return r}function y(e,t){return e.map(e=>{let n=e.path.map(e=>typeof e==`symbol`?String(e):e),r={path:n,message:e.message,issueCode:e.code};if(t.doc!==null&&t.source!==null){let e=a({file:t.path,source:t.source,doc:t.doc,path:n});if(e!==void 0)return{...r,source:e}}return r})}function b(t){let a=t??process.cwd(),s=[],l=n(`user`,a),u=e({absPath:l}),d={};u.valid&&u.source!==void 0?(d=m(d,u.value),s.push(l)):u.valid;let f=c(a,`.ok`,o),p=h(f);if(p.value!==null){let e=v(p);if(e.length>0)throw Error(e.map(i).join(`
1
+ import{Jr as e,Mi as t,Yr as n,f as r,pi as i,yi as a}from"./dist-DHj61EG5.mjs";import{t as o}from"./constants-xPQnQB6p.mjs";import{t as s}from"./is-object-C-4FJ0rP.mjs";import{resolve as c}from"node:path";import{existsSync as l,readFileSync as u}from"node:fs";import{realpath as d}from"node:fs/promises";async function f(e){let t=c(e);try{return await d(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 p=t();function m(e,t){let n={...e};for(let r of Object.keys(t)){let i=e[r],a=t[r];s(a)&&s(i)?n[r]=m(i,a):a!==void 0&&(n[r]=a)}return n}function h(e){if(!l(e))return{value:null,path:e,source:null,doc:null};let t;try{t=u(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,p.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 s(r)?{value:r,path:e,source:t,doc:n}:{value:null,path:e,source:t,doc:n}}const g=[`include`,`exclude`];function _(e){let t="Run `ok config migrate` to strip the obsolete key from config.yml automatically, or remove it by hand.";return e===`exclude`?[`Move these patterns to .okignore at the project root (gitignore syntax, 1:1 migration).`,t].join(` `):[`content.include has been removed.`,`For subdirectory scoping, set content.dir in .ok/config.yml instead.`,`For pattern-based filtering, use .okignore (gitignore syntax — exclude-only; do not copy include patterns directly).`,t].join(` `)}function v(e){let t=e.value;if(!s(t))return[];let n=t.content;if(!s(n))return[];let r=[];for(let t of g)if(t in n){let n=[`content`,t],i;e.doc!==null&&e.source!==null&&(i=a({file:e.path,source:e.source,doc:e.doc,path:n})),r.push({code:`REMOVED_KEY`,path:n,redirect:_(t),...i===void 0?{}:{source:i}})}return r}function y(e,t){return e.map(e=>{let n=e.path.map(e=>typeof e==`symbol`?String(e):e),r={path:n,message:e.message,issueCode:e.code};if(t.doc!==null&&t.source!==null){let e=a({file:t.path,source:t.source,doc:t.doc,path:n});if(e!==void 0)return{...r,source:e}}return r})}function b(t){let a=t??process.cwd(),s=[],l=n(`user`,a),u=e({absPath:l}),d={};u.valid&&u.source!==void 0?(d=m(d,u.value),s.push(l)):u.valid;let f=c(a,`.ok`,o),p=h(f);if(p.value!==null){let e=v(p);if(e.length>0)throw Error(e.map(i).join(`
2
2
 
3
3
  `));d=m(d,p.value),s.push(f)}x(d,[`upload`,`maxBytes`],`streaming uploads have no user-facing cap`),x(d,[`github`,`oauthAppClientId`],`use the OPEN_KNOWLEDGE_GITHUB_CLIENT_ID env var instead`),x(d,[`server`,`host`],`use the --host flag or HOST env var instead`),x(d,[`server`,`openOnAgentEdit`]),x(d,[`mcp`,`autoStart`],`to disable auto-start, set OK_MCP_AUTOSTART=0`),x(d,[`mcp`,`tools`,`read_document`,`historyDepth`]),x(d,[`mcp`,`tools`,`grep`,`maxResults`]),x(d,[`mcp`,`tools`,`search`,`maxResults`]),x(d,[`preview`,`baseUrl`],"preview URLs now resolve only to the running UI process — start one with `ok ui`");let g=r.safeParse(d);if(!g.success){let e={code:`SCHEMA_INVALID`,issues:y(g.error.issues,p)};throw Error(i(e))}return{config:g.data,sources:s}}function x(e,t,n){let r=e;for(let e=0;e<t.length-1;e++){if(!s(r))return;r=r[t[e]]}if(!s(r))return;let i=t[t.length-1];if(r[i]===void 0)return;let a=t.join(`.`);console.warn(`[config] ${a} is no longer user-configurable; ${n??`the value is hardcoded in @inkeep/open-knowledge-core`}. Remove the key to silence this warning.`)}function S(e){let t=e.cacheMs??1e3,n=e.loadConfigFn??b,r=new Map,i=new Map,a=f(e.startupCwd);return async o=>{let s=await f(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{b as n,S as t};
4
- //# sourceMappingURL=loader-CHhQuNxK.mjs.map
4
+ //# sourceMappingURL=loader-BeazNH_4.mjs.map
@@ -0,0 +1 @@
1
+ import{n as e}from"./loader-BeazNH_4.mjs";export{e as loadConfig};
@@ -1,3 +1,3 @@
1
- import{xt as e}from"./dist-DHj61EG5.mjs";import"./constants-BbmMpMCp.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{xt as e}from"./dist-DHj61EG5.mjs";import"./constants-xPQnQB6p.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-CIgVuEry.mjs.map
3
+ //# sourceMappingURL=preview-D4eVomfX.mjs.map
@@ -0,0 +1 @@
1
+ import{n as e,t}from"./preview-D4eVomfX.mjs";export{t as formatPreviewBlock,e as previewContent};
@@ -1915,4 +1915,4 @@ This template lives at an ancestor folder — deleting affects every folder unde
1915
1915
  `;function wB(e){DB(e);let t=e.querySelector(`[data-item-rename-input]`);if(!t)return;let n=t.closest(`[data-item-section="content"]`),r=t.closest(`[data-type="item"]`);if(!n||!r)return;let i=r.dataset.itemPath??``;if(i.endsWith(`/`))return;let a=oB(i);a&&(OB(n,a),r.getAttribute(`data-ok-renaming`)!==a&&r.setAttribute(vB,a),TB(a),!t.hasAttribute(yB)&&(kB(t,a),t.setAttribute(yB,``)))}function TB(e){bB=e,xB!==null&&clearTimeout(xB),xB=setTimeout(EB,SB)}function EB(){bB=null,xB!==null&&(clearTimeout(xB),xB=null)}function DB(e){let t=e.querySelectorAll(`[${vB}]`);for(let e of t){if(e.querySelector(`[data-item-rename-input]`))continue;let t=e.getAttribute(vB);if(!t){e.removeAttribute(vB);continue}let n=e.dataset.itemPath??``;if(n.toLowerCase().endsWith(t.toLowerCase())){e.removeAttribute(vB);continue}let r=oB(n);r&&r.toLowerCase()!==t.toLowerCase()&&e.removeAttribute(vB)}if(bB===null)return;let n=e.querySelectorAll(`[data-type="item"][data-item-path]`),r=!1;for(let e of n){let t=e.dataset.itemPath??``;!t||t.endsWith(`/`)||oB(t)||(r=!0,e.getAttribute(`data-item-selected`)===`true`&&e.getAttribute(`data-ok-renaming`)!==bB&&e.setAttribute(vB,bB))}let i=!!e.querySelector(`[data-item-rename-input]`);!r&&!i&&EB()}function OB(e,t){let n=e.querySelector(`[${_B}]`);n||(n=e.ownerDocument.createElement(`span`),n.setAttribute(_B,``),n.setAttribute(`aria-hidden`,`true`),e.appendChild(n)),n.textContent!==t&&(n.textContent=t)}function kB(e,t){let n=e.value;if(!n.toLowerCase().endsWith(t.toLowerCase()))return;let r=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,`value`)?.set;if(!r)return;let i=n.slice(0,-t.length);r.call(e,i),e.dispatchEvent(new Event(`input`,{bubbles:!0})),e.setSelectionRange(0,i.length)}function AB(e){return{selectedFilePath:e,selectedFolderPath:null,navigationPath:e}}function jB(e,t,n={}){if(!e)return AB(t);let r=ur(e);if(t&&r!==t)return AB(t);switch(e.kind){case`doc`:return AB(t??e.docName);case`folder`:case`folder-index`:return{selectedFilePath:null,selectedFolderPath:e.folderPath,navigationPath:e.folderPath};case`missing`:return t&&n.isKnownDocument?.(t)?AB(t):{selectedFilePath:null,selectedFolderPath:null,navigationPath:null};case`asset`:return{selectedFilePath:null,selectedFolderPath:null,navigationPath:null}}}function MB(e,t){if(!e)return{kind:`none`};let n=t.find(t=>GD(t)===e);if(n&&Hn(n))return{kind:`asset`,path:n.path,hash:Gr(n.path),mediaKind:n.mediaKind};let r=YD(e);return e.endsWith(`/`)?t.some(e=>ti(e)?e.path===r||e.path.startsWith(`${r}/`):(Hn(e)?e.path:e.docName).startsWith(`${r}/`))?{kind:`folder`,path:r}:{kind:`none`}:t.some(e=>hn(e)&&e.docName===r)?{kind:`document`,path:r}:{kind:`none`}}var NB=`You can restore this file from the Trash.`;function PB(e){let t=NB,n=`Move to Trash`,r=`Moving`;if(e.length===0)return{title:`Are you sure you want to delete the selected items?`,detail:t,listedTargets:null,confirmLabel:n,confirmLabelBusy:r};if(e.length===1){let i=e[0];return i?i.kind===`folder`?{title:`Are you sure you want to delete '${i.name}' and its contents?`,detail:t,listedTargets:null,confirmLabel:n,confirmLabelBusy:r}:{title:`Are you sure you want to delete '${i.name}'?`,detail:t,listedTargets:null,confirmLabel:n,confirmLabelBusy:r}:{title:`Are you sure you want to delete the selected item?`,detail:t,listedTargets:null,confirmLabel:n,confirmLabelBusy:r}}let i=e.some(e=>e.kind===`folder`),a=e.some(e=>e.kind===`file`);return i&&a?{title:`Are you sure you want to delete the following ${e.length} files/directories and their contents?`,detail:t,listedTargets:e,confirmLabel:n,confirmLabelBusy:r}:i?{title:`Are you sure you want to delete the following ${e.length} directories and their contents?`,detail:t,listedTargets:e,confirmLabel:n,confirmLabelBusy:r}:{title:`Are you sure you want to delete the following ${e.length} files?`,detail:t,listedTargets:e,confirmLabel:n,confirmLabelBusy:r}}function FB(e,t){return e===`web`?null:PB(t)}function IB(e){return e.kind===`folder`?`${e.name}/`:e.docExt?`${e.name}${e.docExt}`:e.name}var LB=[`not-found`,`permission-denied`,`system-error`,`path-escape`];function RB(e){return typeof e==`string`&&LB.includes(e)?e:`system-error`}var zB={"not-found":`File not found`,"permission-denied":`Permission denied`,"system-error":`System error`,"path-escape":`Path resolves outside project`};function BB(e){let t=zB[e.reason];return e.detail?`Reason: ${t} (${e.detail})`:`Reason: ${t}`}function VB(e){return e.kind===`folder`?`${e.name}/`:e.name}function HB(e){let t=(0,$.c)(33),{failedTargets:n,isSubmitting:r,onDeletePermanently:i,onRetry:a,onCancel:o}=e,s=n.length>1,c=n[0],l;t[0]!==n.length||t[1]!==s||t[2]!==c?(l=s?`${n.length} items could not be moved to the Trash. Do you want to permanently delete instead?`:c?`Could not move "${VB(c)}" to the Trash. Do you want to permanently delete instead?\n${BB(c)}`:`Do you want to permanently delete instead?`,t[0]=n.length,t[1]=s,t[2]=c,t[3]=l):l=t[3];let u=l,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Z.jsx)(bo,{children:`Couldn't move to Trash`}),t[4]=d):d=t[4];let f;t[5]===u?f=t[6]:(f=(0,Z.jsxs)(Ao,{children:[d,(0,Z.jsx)(vo,{className:`whitespace-pre-wrap`,children:u})]}),t[5]=u,t[6]=f);let p;t[7]!==n||t[8]!==s?(p=s?(0,Z.jsx)(Do,{children:(0,Z.jsx)(`ul`,{className:`flex flex-col gap-2 text-xs`,children:n.map(UB)})}):null,t[7]=n,t[8]=s,t[9]=p):p=t[9];let m;t[10]!==r||t[11]!==o?(m=(0,Z.jsx)(Y,{variant:`outline`,className:`font-mono uppercase`,onClick:o,disabled:r,"data-testid":`trash-failure-modal-cancel`,children:`Cancel`}),t[10]=r,t[11]=o,t[12]=m):m=t[12];let h;t[13]===r?h=t[14]:(h=r?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ue,{className:`size-4 animate-spin`}),` Retrying`]}):`Retry`,t[13]=r,t[14]=h);let g;t[15]!==r||t[16]!==a||t[17]!==h?(g=(0,Z.jsx)(Y,{variant:`outline`,className:`font-mono uppercase`,onClick:a,disabled:r,"data-testid":`trash-failure-modal-retry`,children:h}),t[15]=r,t[16]=a,t[17]=h,t[18]=g):g=t[18];let _;t[19]===r?_=t[20]:(_=r?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ue,{className:`size-4 animate-spin`}),` Deleting`]}):`Delete Permanently`,t[19]=r,t[20]=_);let v;t[21]!==r||t[22]!==i||t[23]!==_?(v=(0,Z.jsx)(Y,{variant:`destructive`,onClick:i,disabled:r,"data-testid":`trash-failure-modal-delete-permanently`,children:_}),t[21]=r,t[22]=i,t[23]=_,t[24]=v):v=t[24];let y;t[25]!==m||t[26]!==g||t[27]!==v?(y=(0,Z.jsxs)(Oo,{children:[m,g,v]}),t[25]=m,t[26]=g,t[27]=v,t[28]=y):y=t[28];let b;return t[29]!==y||t[30]!==f||t[31]!==p?(b=(0,Z.jsxs)(wo,{className:`sm:max-w-md`,children:[f,p,y]}),t[29]=y,t[30]=f,t[31]=p,t[32]=b):b=t[32],b}function UB(e){return(0,Z.jsxs)(`li`,{"data-testid":`trash-failure-modal-target`,children:[(0,Z.jsx)(`div`,{className:`font-mono text-foreground`,children:VB(e)}),(0,Z.jsx)(`div`,{className:`text-muted-foreground`,children:BB(e)})]},e.path)}function WB(e){return e?.isDirectory()?e:null}function GB(e,t){let n=t.getPath();for(let t of e.getSelectedPaths())t!==n&&e.getItem(t)?.deselect();t.isSelected()||t.select()}function KB(e,t,n,r){let i=(0,$.c)(6),a,o;i[0]!==n||i[1]!==t||i[2]!==e||i[3]!==r?(a=()=>{let i=()=>{queueMicrotask(()=>{r.current=!1})};if(r.current=!0,!t){for(let t of e.getSelectedPaths())e.getItem(t)?.deselect();i();return}let a=n?n.split(`\0`):[];for(let t of a){let n=WB(e.getItem(t));n&&!n.isExpanded()&&n.expand()}let o=e.getItem(t);if(!o){i();return}GB(e,o),o.focus(),i()},o=[n,t,e,r],i[0]=n,i[1]=t,i[2]=e,i[3]=r,i[4]=a,i[5]=o):(a=i[4],o=i[5]),(0,Q.useEffect)(a,o)}var qB={"not-found":`Terminal.app not found`,"spawn-error":`Could not launch Terminal`,timeout:`Terminal took too long to respond`,"path-escape":`Path resolves outside the project`,"ipc-error":`Lost connection to the main process`};async function JB(e,t){let n;try{n=await e.shell.openInTerminal(t)}catch(e){console.warn(`[shell] openInTerminal IPC threw`,{dirAbsPath:t,err:e}),X.error(`Could not open Terminal`,{description:qB[`ipc-error`]});return}n.ok||(console.warn(`[shell] openInTerminal failed`,{reason:n.reason,dirAbsPath:t}),X.error(`Could not open Terminal`,{description:qB[n.reason]}))}var YB=`open-knowledge:file-tree-menu-action-delete`,XB=`open-knowledge:file-tree-menu-action-rename`;function ZB(e){window.dispatchEvent(new CustomEvent(YB,{detail:{target:e}}))}function QB(e){let t=t=>{let n=t.detail;n?.target&&e(n.target)};return window.addEventListener(YB,t),()=>window.removeEventListener(YB,t)}function $B(e){window.dispatchEvent(new CustomEvent(XB,{detail:{target:e}}))}function eV(e){let t=t=>{let n=t.detail;n?.target&&e(n.target)};return window.addEventListener(XB,t),()=>window.removeEventListener(XB,t)}function tV(e){let t=!1,n=!1,r=!1;async function i(){if(!r){t=!0;try{await e()}finally{t=!1,r?n=!1:n&&(n=!1,i())}}}return{request(){if(!r){if(t){n=!0;return}i()}},dispose(){r=!0,n=!1}}}function nV(e){return e?`No workspace`:null}function rV(e){let t=(0,$.c)(39),{input:n,installStates:r,dispatch:i,webFallbackVisible:a}=e,o=a===void 0?!0:a,s=n===null,c;t[0]===s?c=t[1]:(c=nV(s),t[0]=s,t[1]=c);let l=c,u,d,f,p,m,h;if(t[2]!==i||t[3]!==l||t[4]!==n||t[5]!==s||t[6]!==r){let e;t[13]===r?e=t[14]:(e=e=>r[e.id]?.installed===!0,t[13]=r,t[14]=e);let a=xm.filter(e);f=r[`claude-code`]?.installed===!0;let o;t[15]===n?o=t[16]:(o=n!==null&&n.docContext!==null?$r(n.docContext.relativePath):``,t[15]=n,t[16]=o);let c=o,g;t[17]!==n||t[18]!==c?(g=()=>{n!==null&&qx(c)},t[17]=n,t[18]=c,t[19]=g):g=t[19],p=g,d=Xa,t[20]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Z.jsxs)(xa,{children:[(0,Z.jsx)(Fi,{"aria-hidden":`true`}),`Open with AI`]}),t[20]=h):h=t[20],u=ta;let _;t[21]!==i||t[22]!==l||t[23]!==n||t[24]!==s?(_=e=>{let t=!s,r=l?`Open with AI ${e.displayName}, ${l}`:`Open with AI ${e.displayName}`;return(0,Z.jsxs)(ya,{disabled:!t,onSelect:()=>{n&&i(e.id,n)},"data-testid":`file-tree-open-in-${e.id}`,"aria-label":r,children:[(0,Z.jsx)(Vx,{id:e.id,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:e.displayName}),l?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:l}):null]},e.id)},t[21]=i,t[22]=l,t[23]=n,t[24]=s,t[25]=_):_=t[25],m=a.map(_),t[2]=i,t[3]=l,t[4]=n,t[5]=s,t[6]=r,t[7]=u,t[8]=d,t[9]=f,t[10]=p,t[11]=m,t[12]=h}else u=t[7],d=t[8],f=t[9],p=t[10],m=t[11],h=t[12];let g;t[26]!==f||t[27]!==p||t[28]!==s||t[29]!==o?(g=o&&!f?(0,Z.jsxs)(ya,{onSelect:p,disabled:s,"data-testid":`file-tree-open-in-claude-web-fallback`,"aria-label":`Open in claude.ai, opens in browser with prompt pre-filled`,children:[(0,Z.jsx)(he,{className:`size-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:`Open in claude.ai →`}),(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:`opens in browser`})]}):null,t[26]=f,t[27]=p,t[28]=s,t[29]=o,t[30]=g):g=t[30];let _;t[31]!==u||t[32]!==m||t[33]!==g?(_=(0,Z.jsxs)(u,{children:[m,g]}),t[31]=u,t[32]=m,t[33]=g,t[34]=_):_=t[34];let v;return t[35]!==d||t[36]!==h||t[37]!==_?(v=(0,Z.jsxs)(d,{children:[h,_]}),t[35]=d,t[36]=h,t[37]=_,t[38]=v):v=t[38],v}var iV=it(`HOVER_INTENT_MS`,80),aV=3,oV=20,sV=new Map,cV=new Set,lV=[],uV=new Map;function dV(e){for(uV.delete(e),uV.set(e,!0);uV.size>oV;){let e=uV.keys().next().value;if(e===void 0)break;uV.delete(e)}}function fV(e){cV.delete(e),mV()}function pV(e,t){let n=Date.now();dt(`ok/sidebar/prewarm-success`,{docName:e,t:n,poolEventId:t}),$e(e,t,n)}function mV(){for(;cV.size<aV&&lV.length>0;){let e=lV.shift();if(!e)break;if(!uV.has(e.docName)){cV.add(e.docName),dV(e.docName);try{let t=e.prewarm(e.docName);t&&pV(e.docName,t)}catch(t){dt(`ok/sidebar/prewarm-failed`,{docName:e.docName,message:t instanceof Error?t.message:String(t)})}finally{fV(e.docName)}}}}function hV(e,t){if(Be(e)||uV.has(e))return;let n=sV.get(e);n&&clearTimeout(n.timer);let r=setTimeout(()=>{if(sV.delete(e),cV.size>=aV){lV.push({docName:e,prewarm:t});return}dV(e),cV.add(e);try{let n=t(e);n&&pV(e,n)}catch(t){dt(`ok/sidebar/prewarm-failed`,{docName:e,message:t instanceof Error?t.message:String(t)})}finally{fV(e)}},iV);sV.set(e,{timer:r,prewarm:t})}function gV(e){let t=sV.get(e);t&&(clearTimeout(t.timer),sV.delete(e))}var _V=/\.(md|mdx)$/i;function vV(e){if(window.location.hash===e)return;let{pathname:t,search:n}=window.location;window.history.replaceState(null,``,`${t}${n}${e}`)}function yV(e){let t=e.match(/^"(.+)" already exists\.$/);return t?t[1]:null}function bV(e){let t=e.match(_V);return t?t[0]:null}async function xV(e,t){try{await navigator.clipboard.writeText(e),X.success(`Copied ${t}`,{description:e})}catch(e){console.warn(`[FileTree] clipboard write failed:`,e),X.error(`Could not copy ${t}`)}}var SV=new Set([`agents`,`agent`,`claude`,`skill`]),CV=`ok-file-tree-link-decoration`,wV=`ok-file-tree-agent-decoration`;function TV(e){return e.map(([e,{key:t,...n}])=>`<${e} ${Object.entries(n).map(([e,t])=>`${e}="${t}"`).join(` `)} />`).join(``)}function EV(e,t){return`<symbol id="${e}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${TV(t)}</symbol>`}var DV=`<svg data-icon-sprite aria-hidden="true" width="0" height="0">
1916
1916
  ${EV(CV,c)}
1917
1917
  ${EV(wV,Ws)}
1918
- </svg>`,OV=`${uB}\n${CB}`;function kV(e){return{...Sj({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 AV(e){let t=e.split(`/`).pop()?.replace(/\.md$/i,``).toLowerCase();return!!t&&SV.has(t)}function jV(e){return e===`darwin`?`Reveal in Finder`:e===`win32`?`Reveal in File Explorer`:`Open Containing Folder`}function MV(e){let t=(0,$.c)(14),{item:n,workspace:r,onClose:i}=e,a=typeof window<`u`?window.okDesktop:void 0;if(!a)return null;let o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=jV(a.platform),t[0]=o):o=t[0];let s=o,c=r?null:`No workspace`,l=!r,u;t[1]!==n||t[2]!==i||t[3]!==r?(u=()=>{if(!r)return;i();let e=nh(r.contentDir,nO(n),r.pathSeparator);a.shell.showItemInFolder(e)},t[1]=n,t[2]=i,t[3]=r,t[4]=u):u=t[4];let d=c?`${s}, ${c}`:s,f,p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Z.jsx)(R,{"aria-hidden":`true`}),p=(0,Z.jsx)(`span`,{className:`flex-1`,children:s}),t[5]=f,t[6]=p):(f=t[5],p=t[6]);let m;t[7]===c?m=t[8]:(m=c?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:c}):null,t[7]=c,t[8]=m);let h;return t[9]!==l||t[10]!==u||t[11]!==d||t[12]!==m?(h=(0,Z.jsxs)(ya,{disabled:l,onSelect:u,"aria-label":d,children:[f,p,m]}),t[9]=l,t[10]=u,t[11]=d,t[12]=m,t[13]=h):h=t[13],h}function NV(e){let t=(0,$.c)(12),{dirAbsPath:n,onClose:r}=e,i=typeof window<`u`?window.okDesktop:void 0;if(!i)return null;let a=n===null?`No workspace`:null,o=n===null,s;t[0]!==n||t[1]!==r?(s=()=>{n!==null&&(r(),JB(i,n))},t[0]=n,t[1]=r,t[2]=s):s=t[2];let c=a?`Open in Terminal, ${a}`:`Open in Terminal`,l,u;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Z.jsx)(Yc,{"aria-hidden":`true`}),u=(0,Z.jsx)(`span`,{className:`flex-1`,children:`Open in Terminal`}),t[3]=l,t[4]=u):(l=t[3],u=t[4]);let d;t[5]===a?d=t[6]:(d=a?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:a}):null,t[5]=a,t[6]=d);let f;return t[7]!==o||t[8]!==s||t[9]!==c||t[10]!==d?(f=(0,Z.jsxs)(ya,{disabled:o,onSelect:s,"aria-label":c,children:[l,u,d]}),t[7]=o,t[8]=s,t[9]=c,t[10]=d,t[11]=f):f=t[11],f}function PV(e){return tO({kind:e.endsWith(`/`)?`directory`:`file`,name:e,path:e})}function FV(e,t){return e!==t&&e.startsWith(t)}function IV(e,t){let n=[...new Set(e)].filter(e=>!t(e)),r=n.filter(e=>e.endsWith(`/`));return n.filter(e=>!r.some(t=>FV(e,t))).map(PV)}function LV(e,t){return e===t||e.startsWith(`${t}/`)}function RV(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 zV(e,t,n){let r=new Set,i=new Set;for(let a of e){if(a.kind===`file`){r.add(a.path);continue}i.add(a.path);for(let e of t)hn(e)&&e.docName.startsWith(`${a.path}/`)&&r.add(e.docName);for(let e of n){let t=qD(e);LV(t,a.path)&&i.add(t)}}return{docNames:r,folderPaths:i}}function BV(e,t){return e.kind===`file`?t.kind===`file`&&e.path===t.createdPath:LV(t.createdPath,e.path)}function VV(e){let t=(0,$.c)(75),{item:n,context:r,anyActionBusy:i,workspace:a,handoff:o,model:s,okignoreBinding:c,projectLocalBinding:l,mergedConfig:u,onStartCreating:f,onStartCreatingFromTemplate:p,onDelete:h,onExpandSubtree:g,onCollapseSubtree:_,folderTreePaths:v,isAsset:y,isAssetTreePath:b}=e,x,S,C,w,T,D,O,k;if(t[0]!==y||t[1]!==b||t[2]!==n||t[3]!==u?.appearance?.sidebar?.showAllFiles||t[4]!==u?.appearance?.sidebar?.showHiddenFiles||t[5]!==s||t[6]!==c||t[7]!==l){k=tO(n),w=n.kind===`directory`,x=!y&&c!==null,C=w?`Hide folder`:`Hide this file`,D=u?.appearance?.sidebar?.showHiddenFiles??!1,T=u?.appearance?.sidebar?.showAllFiles??!1,S=l!==null;let e=s.getSelectedPaths();O=e.includes(k.treePath)?IV(e,b):[],t[0]=y,t[1]=b,t[2]=n,t[3]=u?.appearance?.sidebar?.showAllFiles,t[4]=u?.appearance?.sidebar?.showHiddenFiles,t[5]=s,t[6]=c,t[7]=l,t[8]=x,t[9]=S,t[10]=C,t[11]=w,t[12]=T,t[13]=D,t[14]=O,t[15]=k}else x=t[8],S=t[9],C=t[10],w=t[11],T=t[12],D=t[13],O=t[14],k=t[15];let A=O,j;t[16]!==A||t[17]!==k?(j=A.length>1?A:[k],t[16]=A,t[17]=k,t[18]=j):j=t[18];let M=j,N=M.length>1?`Delete ${M.length} Items`:`Delete`,P,F,I;if(t[19]!==y||t[20]!==w||t[21]!==n||t[22]!==a){P=w&&a?nh(a.contentDir,nO(n),a.pathSeparator):null;let e;if(t[26]!==w||t[27]!==n||t[28]!==a){bb0:{if(!a||w){e=null;break bb0}let t=nO(n),r=t.lastIndexOf(`/`);if(r===-1){e=a.contentDir;break bb0}e=nh(a.contentDir,t.slice(0,r),a.pathSeparator)}t[26]=w,t[27]=n,t[28]=a,t[29]=e}else e=t[29];F=e,I=y?null:w?oh({folderAbsPath:P??``,folderRelativePath:nO(n),workspace:a}):ih({docName:WD(n.path),workspace:a}),t[19]=y,t[20]=w,t[21]=n,t[22]=a,t[23]=P,t[24]=F,t[25]=I}else P=t[23],F=t[24],I=t[25];let L=I,R;t[30]===r?R=t[31]:(R=()=>r.close({restoreFocus:!1}),t[30]=r,t[31]=R);let z=R,B;t[32]===r?B=t[33]:(B=()=>r.close(),t[32]=r,t[33]=B);let V=B,H;t[34]===l?H=t[35]:(H=e=>{if(l===null)return;let t=l.patch({appearance:{sidebar:{showHiddenFiles:e}}});t.ok||(console.warn(`[FileTree] showHiddenFiles toggle rejected:`,Nn(t.error)),X.error(`Could not update sidebar settings`,{description:Nn(t.error)}))},t[34]=l,t[35]=H);let U=H,W;t[36]===l?W=t[37]:(W=e=>{if(l===null)return;let t=l.patch({appearance:{sidebar:{showAllFiles:e}}});t.ok||(console.warn(`[FileTree] showAllFiles toggle rejected:`,Nn(t.error)),X.error(`Could not update sidebar settings`,{description:Nn(t.error)}))},t[36]=l,t[37]=W);let G=W,K=0,q=0;if(w){let e=JD(n.path);for(let t of v)(t===e||t.startsWith(e))&&(K++,WB(s.getItem(t))?.isExpanded()&&q++)}let ee=w&&q<K,te=w&&q>0,ne;t[38]===V?ne=t[39]:(ne=e=>{e||V()},t[38]=V,t[39]=ne);let re;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,Z.jsx)(ba,{asChild:!0,children:(0,Z.jsx)(`span`,{"aria-hidden":`true`,"data-file-tree-context-menu-root":`true`,className:`block size-px`})}),t[40]=re):re=t[40];let ie;t[41]!==i||t[42]!==x||t[43]!==S||t[44]!==V||t[45]!==z||t[46]!==N||t[47]!==M||t[48]!==P||t[49]!==G||t[50]!==U||t[51]!==o||t[52]!==L||t[53]!==C||t[54]!==y||t[55]!==w||t[56]!==n||t[57]!==s||t[58]!==c||t[59]!==_||t[60]!==h||t[61]!==g||t[62]!==f||t[63]!==p||t[64]!==F||t[65]!==T||t[66]!==D||t[67]!==te||t[68]!==ee||t[69]!==k||t[70]!==a?(ie=(0,Z.jsx)(_a,{sideOffset:0,align:`start`,"data-file-tree-context-menu-root":`true`,className:`min-w-52`,children:w?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(ya,{disabled:i,onSelect:()=>{z(),f(`file`,qD(n.path))},children:[(0,Z.jsx)(Wc,{"aria-hidden":`true`}),`New File`]}),(0,Z.jsxs)(ya,{disabled:i,onSelect:()=>{z(),p(qD(n.path))},children:[(0,Z.jsx)(oc,{"aria-hidden":`true`}),`New from template`]}),(0,Z.jsxs)(ya,{disabled:i,onSelect:()=>{z(),f(`folder`,qD(n.path))},children:[(0,Z.jsx)(uc,{"aria-hidden":`true`}),`New Folder`]}),(0,Z.jsx)(na,{}),(0,Z.jsx)(MV,{item:n,workspace:a,onClose:V}),(0,Z.jsx)(rV,{input:L,installStates:o.installStates,isElectronHost:o.isElectronHost,dispatch:o.dispatch,webFallbackVisible:!1}),(0,Z.jsx)(NV,{dirAbsPath:P,onClose:V}),(0,Z.jsxs)(Xa,{children:[(0,Z.jsxs)(xa,{children:[(0,Z.jsx)(E,{"aria-hidden":`true`}),`Copy Path`]}),(0,Z.jsxs)(ta,{children:[(0,Z.jsx)(ya,{disabled:!a,onSelect:()=>{a&&(V(),xV(nh(a.contentDir,nO(n),a.pathSeparator),`full path`))},children:`Full Path`}),(0,Z.jsx)(ya,{onSelect:()=>{V(),xV(nO(n),`relative path`)},children:`Relative Path`})]})]}),(0,Z.jsx)(na,{}),(0,Z.jsx)($i,{checked:D,onCheckedChange:U,disabled:!S,"data-testid":`file-tree-menu-show-hidden-files`,children:`Show Hidden Files`}),(0,Z.jsx)($i,{checked:T,onCheckedChange:G,disabled:!S,"data-testid":`file-tree-menu-show-all-files`,children:`Show all files`}),ee||te?(0,Z.jsx)(na,{}):null,ee?(0,Z.jsxs)(ya,{onSelect:()=>{V(),g(n.path)},children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),`Expand All`]}):null,te?(0,Z.jsxs)(ya,{onSelect:()=>{V(),_(n.path)},children:[(0,Z.jsx)(cc,{"aria-hidden":`true`}),`Collapse All`]}):null,(0,Z.jsx)(na,{}),(0,Z.jsxs)(ya,{disabled:i,onSelect:()=>{z(),s.startRenaming(n.path)},children:[(0,Z.jsx)(m,{"aria-hidden":`true`}),`Rename`]}),(0,Z.jsxs)(ya,{"data-testid":`file-tree-menu-hide`,disabled:!x,onSelect:()=>{if(!c)return;V();let e=gB(k),t=no(c.current()),n=Ka(t,e);if(n===t)return;c.patch(Ja(n));let r=k.path.split(`/`).pop()||k.path;X.success(`Hidden folder “${r}”`,{description:`Manage hidden files in Settings → Ignore patterns.`,duration:5e3})},children:[(0,Z.jsx)(d,{"aria-hidden":`true`}),C]}),(0,Z.jsxs)(ya,{variant:`destructive`,disabled:i,onSelect:()=>{V(),h(M)},children:[(0,Z.jsx)(Ue,{"aria-hidden":`true`}),N]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(MV,{item:n,workspace:a,onClose:V}),!y&&(0,Z.jsx)(rV,{input:L,installStates:o.installStates,isElectronHost:o.isElectronHost,dispatch:o.dispatch,webFallbackVisible:!0}),(0,Z.jsx)(NV,{dirAbsPath:F,onClose:V}),(0,Z.jsxs)(Xa,{children:[(0,Z.jsxs)(xa,{children:[(0,Z.jsx)(E,{"aria-hidden":`true`}),`Copy Path`]}),(0,Z.jsxs)(ta,{children:[(0,Z.jsx)(ya,{disabled:!a,onSelect:()=>{a&&(V(),xV(nh(a.contentDir,nO(n),a.pathSeparator),`full path`))},children:`Full Path`}),(0,Z.jsx)(ya,{onSelect:()=>{V(),xV(nO(n),`relative path`)},children:`Relative Path`})]})]}),y?null:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(na,{}),(0,Z.jsxs)(ya,{disabled:i,onSelect:()=>{z(),s.startRenaming(n.path)},children:[(0,Z.jsx)(m,{"aria-hidden":`true`}),`Rename`]}),(0,Z.jsxs)(ya,{"data-testid":`file-tree-menu-hide`,disabled:!x,onSelect:()=>{if(!c)return;V();let e=gB(k),t=no(c.current()),n=Ka(t,e);if(n===t)return;c.patch(Ja(n));let r=k.path.split(`/`).pop()||k.path;X.success(`Hidden “${r}”`,{description:`Manage hidden files in Settings → Ignore patterns.`,duration:5e3})},children:[(0,Z.jsx)(d,{"aria-hidden":`true`}),C]}),(0,Z.jsxs)(ya,{variant:`destructive`,disabled:i,onSelect:()=>{V(),h(M)},children:[(0,Z.jsx)(Ue,{"aria-hidden":`true`}),N]})]})]})}),t[41]=i,t[42]=x,t[43]=S,t[44]=V,t[45]=z,t[46]=N,t[47]=M,t[48]=P,t[49]=G,t[50]=U,t[51]=o,t[52]=L,t[53]=C,t[54]=y,t[55]=w,t[56]=n,t[57]=s,t[58]=c,t[59]=_,t[60]=h,t[61]=g,t[62]=f,t[63]=p,t[64]=F,t[65]=T,t[66]=D,t[67]=te,t[68]=ee,t[69]=k,t[70]=a,t[71]=ie):ie=t[71];let ae;return t[72]!==ie||t[73]!==ne?(ae=(0,Z.jsxs)(va,{open:!0,modal:!1,onOpenChange:ne,children:[re,ie]}),t[72]=ie,t[73]=ne,t[74]=ae):ae=t[74],ae}function HV(e){let t=(0,$.c)(226),{ref:n}=e,{activeDocName:r,activeTarget:i,closeTabs:a,closeDocument:o,closeAndClearForRename:s,getPoolActiveDocName:c,isNewTabActive:u,openTarget:d,prewarm:f,remapTabsForRename:p}=ot(),{notifySidebarFileSelected:m}=aD(),{resolvedTheme:h}=vr(),{addPage:g}=qr(),_;t[0]!==m||t[1]!==d?(_=function(e){d({kind:`doc`,target:e,docName:e},{tabBehavior:`replace-active`}),vV(Tr(e)),m()},t[0]=m,t[1]=d,t[2]=_):_=t[2];let v=_,y;t[3]!==m||t[4]!==d?(y=function(e){let t=or(e);d({kind:`folder`,target:e,folderPath:e},{tabBehavior:`replace-active`}),vV(t),m()},t[3]=m,t[4]=d,t[5]=y):y=t[5];let b=y,x;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(x=[],t[6]=x):x=t[6];let[S,C]=(0,Q.useState)(x),[w,T]=(0,Q.useState)(!0),[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(null),[M,N]=(0,Q.useState)(null),[P,F]=(0,Q.useState)(null),[I,L]=(0,Q.useState)(null),R=(0,Q.useRef)(S),z;t[7]!==S||t[8]!==b||t[9]!==v||t[10]!==m||t[11]!==d?(z=function(e,t){let n=MB(e,t===void 0?S:t);if(n.kind===`none`){console.debug(`[FileTree] Dropped selection for unknown docName:`,YD(e));return}if(n.kind===`asset`){d({kind:`asset`,target:n.path,assetPath:n.path,mediaKind:n.mediaKind},{tabBehavior:`replace-active`}),vV(n.hash),m();return}if(n.kind===`folder`){b(n.path);return}v(n.path)},t[7]=S,t[8]=b,t[9]=v,t[10]=m,t[11]=d,t[12]=z):z=t[12];let B=z,V=(0,Q.useRef)(r),H;t[13]===S?H=t[14]:(H=new Set(S.filter(Hn).map(cH)),t[13]=S,t[14]=H);let U=H,W=(0,Q.useRef)(U),G;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(G=[],t[15]=G):G=t[15];let K=(0,Q.useRef)(G),q=(0,Q.useRef)(null),ee=(0,Q.useRef)(sH),te=(0,Q.useRef)(null),ne=(0,Q.useRef)(null),re=(0,Q.useRef)(!1),ie=(0,Q.useRef)(null),ae=(0,Q.useRef)(!1),oe=(0,Q.useRef)(!1),se=(0,Q.useRef)(null),ce=(0,Q.useRef)(null),le=(0,Q.useRef)(oH),J=(0,Q.useRef)(aH),ue=(0,Q.useRef)(iH),de=(0,Q.useRef)(rH),fe=(0,Q.useRef)(i),{selectedFilePath:pe,selectedFolderPath:me,navigationPath:he}=jB(i,u?null:r),ge=pe?UD(pe,S.find(e=>hn(e)&&e.docName===pe)?.docExt):me?JD(me):i?.kind===`asset`?i.assetPath:null,_e=Oh().states,{dispatch:ve}=_h(),ye;t[16]!==ve||t[17]!==_e?(ye={installStates:_e,isElectronHost:typeof window<`u`&&window.okDesktop!=null,dispatch:ve},t[16]=ve,t[17]=_e,t[18]=ye):ye=t[18];let be=ye,{okignoreBinding:xe,projectLocalBinding:Se,merged:Ce}=Ga(),we=Ce?.appearance?.sidebar?.showHiddenFiles??!1,Te=Ce?.appearance?.sidebar?.showAllFiles??!1,Ee;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(Ee=()=>ie.current===null,t[19]=Ee):Ee=t[19];let De=Ee,Oe;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(Oe=[],t[20]=Oe):Oe=t[20];let ke;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(ke={set:`complete`,spriteSheet:DV},t[21]=ke):ke=t[21];let Ae;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(Ae={contextMenu:{enabled:!0,triggerMode:`both`,buttonVisibility:`when-needed`}},t[22]=Ae):Ae=t[22];let je;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(je={canDrag:De,canDrop:De,onDropComplete:e=>de.current(e),onDropError:nH},t[23]=je):je=t[23];let Me;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(Me={paths:Oe,flattenEmptyDirectories:!1,initialExpansion:`closed`,fileTreeSearchMode:`hide-non-matches`,initialVisibleRowCount:18,stickyFolders:!0,icons:ke,unsafeCSS:OV,composition:Ae,dragAndDrop:je,renaming:{canRename:De,onRename:e=>J.current(e),onError:e=>ue.current(e)},onSelectionChange:e=>le.current(e),renderRowDecoration:e=>{let{item:t}=e;if(t.kind!==`file`)return null;let n=R.current.find(e=>hn(e)&&UD(e.docName,e.docExt)===t.path);return n?.isSymlink?{icon:CV,title:n.targetPath?`Symlink to ${n.targetPath}`:`Symlink`}:AV(t.path)?{icon:wV,title:`Agent configuration file`}:null}},t[24]=Me):Me=t[24];let{model:Ne}=aB(Me),Pe;t[25]===Ne?Pe=t[26]:(Pe=function(e){let t=Ne.getItem(e)??Ne.getItem(JD(e));return t?.isDirectory()?JD(qD(t.getPath())):e},t[25]=Ne,t[26]=Pe);let Fe=Pe,Le,Re;t[27]===S?(Le=t[28],Re=t[29]):(Re=XD(S),Le=ZD(Re),t[27]=S,t[28]=Le,t[29]=Re);let ze=Le,Be=(0,Q.useRef)(Re),Ve;t[30]===S?Ve=t[31]:(Ve=$D(S),t[30]=S,t[31]=Ve);let He=Ve,Ue=(0,Q.useRef)(He),We=me?eO(JD(me)).slice(0,-1):eO(ge??he),Ge=We.join(`\0`),Ke;if(t[32]!==Ne){let e=()=>{let e=new Set;for(let t of Ue.current)WB(Ne.getItem(t))?.isExpanded()&&e.add(t);return e};Ke=t=>{let n=new Set($D(t??R.current)),r=e();for(let e of K.current)r.add(e);return[...r].filter(e=>n.has(e))},t[32]=Ne,t[33]=Ke}else Ke=t[33];let qe=Ke,Je;t[34]!==qe||t[35]!==Ne?(Je=e=>{let t=XD(e??R.current);Ne.resetPaths(t,{initialExpandedPaths:qe(e)})},t[34]=qe,t[35]=Ne,t[36]=Je):Je=t[36];let Ye=Je,Xe;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(Xe=e=>{te.current=QD(e)},t[37]=Xe):Xe=t[37];let Qe=Xe,$e;t[38]===Symbol.for(`react.memo_cache_sentinel`)?($e=e=>W.current.has(e),t[38]=$e):$e=t[38];let et=$e,tt=function(e){let t=yV(e);if(!t||bV(t))return!1;let n=Ne.getFocusedPath()??Ne.getSelectedPaths()[0]??null;if(!n||n.endsWith(`/`)||et(n))return!1;let r=bV(n);if(!r)return!1;let i=JD(t);if(!Ue.current.includes(i))return!1;let a=`${t}${r}`;return Be.current.includes(a)?!1:(Ot({sourcePath:n,destinationPath:a,isFolder:!1}),Ne.move(n,a),!0)},nt;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(nt=e=>{let t=e??q.current;!t||q.current!==t||(t.disposeCommitListener(),q.current=null)},t[39]=nt):nt=t[39];let rt=nt,it;t[40]!==rt||t[41]!==o||t[42]!==a||t[43]!==Ye?(it=async function(e,t){let n=t===void 0?{}:t,r=n.updateUi??!0,i=n.restoreLocation??r;rt(e),r&&k(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=await l(t,`Failed to clean up pending ${e.kind}`);if(n.ok)return;let i=`${n.title} - ${e.kind} "${e.createdPath}" still exists on disk`;r?X.error(i):console.warn(`[FileTree] cleanup pending create failed: ${i}`),r&&(k(null),Ye());return}}catch(t){console.warn(`[FileTree] cleanup pending create failed:`,t),r&&X.error(`Network error - ${e.kind} "${e.createdPath}" still exists on disk`),r&&(k(null),Ye());return}r&&(e.kind===`file`?o(e.createdPath):a([lt(e.createdPath)],{force:!0})),r&&C(t=>{let n=pO(t,e.kind===`file`?[e.createdPath]:[],e.kind===`folder`?e.createdPath:void 0);return Qe(n),n}),Fr([`files`,`backlinks`,`graph`]),i&&(window.location.hash=e.previousHash),r&&k(null)},t[40]=rt,t[41]=o,t[42]=a,t[43]=Ye,t[44]=it):it=t[44];let at=it,st,ct;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(st=()=>()=>{let e=q.current;e&&ee.current(e,{restoreLocation:!1,updateUi:!1}).catch(tH)},ct=[],t[45]=st,t[46]=ct):(st=t[45],ct=t[46]),(0,Q.useEffect)(st,ct);let ut,dt;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(ut=()=>{let e=!0,t=tV(async function(){try{let t=oe.current,n=await l(await fetch(t?`/api/documents?showAll=true`:`/api/documents`),`Failed to load documents`);if(!e)return;if(!n.ok)D(n.title);else{let e=li.safeParse(n.body);if(!e.success)D(`Documents response did not match expected shape.`);else{let n=ae.current||t;C(ai(e.data.documents,n)),D(null)}}}catch(t){let n=t;e&&D(`Could not reach server`),console.warn(`[FileTree] fetch failed:`,n)}e&&T(!1)});se.current=()=>t.request(),t.request();let n=()=>{document.visibilityState===`visible`&&t.request()};window.addEventListener(`focus`,n),window.addEventListener(`visibilitychange`,n);let r=br(e=>{e.includes(`files`)&&t.request()});return()=>{e=!1,se.current=null,t.dispose(),window.removeEventListener(`focus`,n),window.removeEventListener(`visibilitychange`,n),r()}},dt=[],t[47]=ut,t[48]=dt):(ut=t[47],dt=t[48]),(0,Q.useEffect)(ut,dt);let ft=(0,Q.useRef)(!0),pt;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(pt=()=>{if(ft.current){ft.current=!1;return}se.current?.()},t[49]=pt):pt=t[49];let mt;t[50]===we?mt=t[51]:(mt=[we],t[50]=we,t[51]=mt),(0,Q.useEffect)(pt,mt);let ht=(0,Q.useRef)(!0),gt;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(gt=()=>{if(ht.current){ht.current=!1;return}se.current?.()},t[52]=gt):gt=t[52];let _t;t[53]===Te?_t=t[54]:(_t=[Te],t[53]=Te,t[54]=_t),(0,Q.useEffect)(gt,_t);let vt,yt;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(vt=()=>{let e=!0;return fetch(`/api/workspace`).then(async t=>{let n=await t.json();if(!e||!t.ok)return;let r=Ze(Kr,n,`workspace`,null);r&&L({contentDir:r.contentDir,pathSeparator:r.pathSeparator})}).catch(eH),()=>{e=!1}},yt=[],t[55]=vt,t[56]=yt):(vt=t[55],yt=t[56]),(0,Q.useEffect)(vt,yt);let bt;t[57]!==qe||t[58]!==Ne||t[59]!==ze?(bt=()=>{if(te.current===ze){te.current=null;return}Ne.resetPaths(Be.current,{initialExpandedPaths:qe()})},t[57]=qe,t[58]=Ne,t[59]=ze,t[60]=bt):bt=t[60];let xt;t[61]!==Ne||t[62]!==ze?(xt=[Ne,ze],t[61]=Ne,t[62]=ze,t[63]=xt):xt=t[63],(0,Q.useEffect)(bt,xt),KB(Ne,ge,Ge,re);let St,Ct;t[64]===Ne?(St=t[65],Ct=t[66]):(St=()=>Ne.subscribe(()=>{if(!Ne.isSearchOpen())for(let e of K.current){let t=WB(Ne.getItem(e));t&&!t.isExpanded()&&t.expand()}}),Ct=[Ne],t[64]=Ne,t[65]=St,t[66]=Ct),(0,Q.useEffect)(St,Ct);let wt,Tt;t[67]===Ne?(wt=t[68],Tt=t[69]):(wt=()=>Ne.onMutation(`remove`,e=>{let t=q.current;!t||e.path!==t.renamePath||ee.current(t)}),Tt=[Ne],t[67]=Ne,t[68]=wt,t[69]=Tt),(0,Q.useEffect)(wt,Tt);let Et;t[70]!==g||t[71]!==s||t[72]!==c||t[73]!==b||t[74]!==p?(Et=async(e,t,n)=>{let r=t===void 0?[]:t,i=n?.docName??V.current,a=mO(i,e),o=n?.folderPath??(fe.current?.kind===`folder`?fe.current.folderPath:null),l=o?Ie(o,r):null,u=hO(e,c());await Promise.all(u.map(e=>s(e)));for(let t of e)g(t.toDocName);p(e,r),C(t=>{let n=fO(t,e,r);return Qe(n),n}),o&&l&&l!==o?b(l):a&&a!==i&&(window.location.hash=Tr(a)),Fr([`files`,`backlinks`,`graph`])},t[70]=g,t[71]=s,t[72]=c,t[73]=b,t[74]=p,t[75]=Et):Et=t[75];let Dt=Et;async function Ot(e){let t=rO(e.sourcePath,e.isFolder);k(t),D(null);try{if(!e.isFolder&&et(t)){X.error(`Assets cannot be renamed from the sidebar`),queueMicrotask(()=>{Ye()}),rt(),k(null);return}let n=cB(e.sourcePath,e.destinationPath,e.isFolder);if(n.kind===`block`){X.error(`File extensions are managed automatically - please rename without changing the extension`),queueMicrotask(()=>{Ye()}),rt(),k(null);return}let r=rO(n.destinationPath,e.isFolder),i=e.isFolder?{kind:`folder`,fromPath:qD(t),toPath:qD(r)}:{kind:`file`,fromPath:WD(t),toPath:WD(r)},a={docName:V.current,folderPath:fe.current?.kind===`folder`?fe.current.folderPath:null},o=await l(await fetch(`/api/rename-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(i)}),`Failed to rename path`);if(!o.ok){X.error(o.title),D(o.title),Ye();let e=q.current;e&&e.renamePath===t?await at(e):rt(),k(null);return}let s=Ze(Zn,o.body,`rename-path`,{renamed:[]});try{await Dt(s.renamed,e.isFolder?[{fromPath:qD(t),toPath:qD(r)}]:[],a)}catch(e){console.warn(`[FileTree] post-rename reconciliation failed`,{err:e,sourceTreePath:t,destinationTreePath:r,renamedCount:s.renamed.length}),X.error(`Rename succeeded but the sidebar may be out of date — refresh to resync`)}rt(),k(null)}catch(e){console.warn(`[FileTree] rename failed:`,e),X.error(`Network error — please try again`),D(`Network error — please try again`),Ye();let n=q.current;n&&n.renamePath===t?await at(n):rt(),k(null)}}let kt;t[76]!==Dt||t[77]!==Ye?(kt=async function(e){let t=e.draggedPaths.map(t=>{let n=oO(t,e.target);return t===n?null:{sourcePath:t,destinationTreePath:n}}).filter($V);if(t.length!==0){if(t.some(e=>et(e.sourcePath))){X.error(`Assets cannot be moved from the sidebar`),Ye();return}k(t[0]?.sourcePath??null),D(null);try{let e=[],n=[],r={docName:V.current,folderPath:fe.current?.kind===`folder`?fe.current.folderPath:null};for(let r of t){let t=r.sourcePath.endsWith(`/`),i=t?{kind:`folder`,fromPath:qD(r.sourcePath),toPath:qD(r.destinationTreePath)}:{kind:`file`,fromPath:WD(r.sourcePath),toPath:WD(r.destinationTreePath)},a=await l(await fetch(`/api/rename-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(i)}),`Failed to move`);if(!a.ok){X.error(a.title),D(a.title),Ye(),k(null);return}let o=Ze(Zn,a.body,`rename-path:drop`,{renamed:[]});e=e.concat(o.renamed),t&&n.push({fromPath:qD(r.sourcePath),toPath:qD(r.destinationTreePath)})}try{await Dt(e,n,r)}catch(n){console.warn(`[FileTree] post-move reconciliation failed`,{err:n,operationCount:t.length,renamedCount:e.length}),X.error(`Move succeeded but the sidebar may be out of date — refresh to resync`)}k(null)}catch(e){console.warn(`[FileTree] move failed:`,e),X.error(`Network error — please try again`),Ye(),k(null)}}},t[76]=Dt,t[77]=Ye,t[78]=kt):kt=t[78];let At=kt,jt;t[79]===Symbol.for(`react.memo_cache_sentinel`)?(jt=function(e){F({parentDir:e})},t[79]=jt):jt=t[79];let Mt=jt,Nt;t[80]!==at||t[81]!==rt||t[82]!==Ne||t[83]!==b||t[84]!==v||t[85]!==Ye||t[86]!==Re?(Nt=async function(e,t){if(ie.current)return;let n=q.current;n&&rt(n);try{let n=iO(e,t,[...Re,...Ue.current]);k(n.renamePath),ie.current=n.renamePath;let r=window.location.hash,i;if(e===`file`){let e=aO(`file`,n.addPath),t=await l(await fetch(`/api/create-page`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:e})}),`Failed to create file`);if(!t.ok){X.error(t.title),D(t.title),k(null),ie.current=null;return}let r=WD(e),a=Ze(wr,t.body,`create-page`,{docName:r}).docName;i=a;let o=e.toLowerCase().endsWith(`.mdx`)?`.mdx`:`.md`;C(e=>{if(e.some(e=>hn(e)&&e.docName===a))return e;let t=[...e,{kind:`document`,docName:a,docExt:o,modified:new Date().toISOString(),size:0}];return Qe(t),t}),Fr([`files`,`backlinks`,`graph`]),v(a)}else{let e=qD(n.addPath),t=await l(await fetch(`/api/create-folder`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:e})}),`Failed to create folder`);if(!t.ok){X.error(t.title),D(t.title),k(null),ie.current=null;return}i=Ze(Lr,t.body,`create-folder`,{path:e}).path,C(e=>{if(e.some(e=>ti(e)&&e.path===i))return e;let t=[...e,{kind:`folder`,path:i,modified:new Date().toISOString(),size:0}];return Qe(t),t}),Fr([`files`]),b(i)}let a=!1,o=e=>{if(e.key!==`Enter`)return;let t=q.current;!t||t.renamePath!==n.renamePath||queueMicrotask(()=>rt(t))};document.addEventListener(`keydown`,o,!0),q.current={kind:e,renamePath:n.renamePath,createdPath:i,previousHash:r,disposeCommitListener:()=>{a||(a=!0,document.removeEventListener(`keydown`,o,!0))}},k(null),ie.current=null,Ne.add(n.addPath),Ne.startRenaming(n.renamePath,{removeIfCanceled:!0})}catch(e){console.warn(`[FileTree] create placeholder failed:`,e),X.error(`Could not start creating a new item`);let t=q.current;t?await at(t):rt(),k(null),ie.current=null,Ye()}},t[80]=at,t[81]=rt,t[82]=Ne,t[83]=b,t[84]=v,t[85]=Ye,t[86]=Re,t[87]=Nt):Nt=t[87];let Pt=Nt,Ft;t[88]===Ne?Ft=t[89]:(Ft=function(e){let t=JD(e);(0,Q.startTransition)(()=>{for(let e of Ue.current)if(e===t||e.startsWith(t)){let t=WB(Ne.getItem(e));t&&t.expand()}})},t[88]=Ne,t[89]=Ft);let It=Ft,Lt;t[90]===Ne?Lt=t[91]:(Lt=function(e){let t=JD(e),n=new Set(K.current);(0,Q.startTransition)(()=>{for(let e of[...Ue.current].reverse())if((e===t||e.startsWith(t))&&!n.has(e)){let t=WB(Ne.getItem(e));t&&t.collapse()}})},t[90]=Ne,t[91]=Lt);let Rt=Lt,zt;t[92]!==B||t[93]!==We||t[94]!==r||t[95]!==i||t[96]!==U||t[97]!==O||t[98]!==at||t[99]!==S||t[100]!==He||t[101]!==At||t[102]!==Ot||t[103]!==Fe||t[104]!==tt||t[105]!==Te||t[106]!==we||t[107]!==Re?(zt=()=>{R.current=S,V.current=r,fe.current=i,W.current=U,ie.current=O,ae.current=we,oe.current=Te,Be.current=Re,Ue.current=He,K.current=We,ee.current=at,le.current=e=>{if(re.current||e.length!==1)return;let t=e[0];t&&B(Fe(t),S)},ue.current=e=>{tt(e)||X.error(e)},J.current=Ot,de.current=At},t[92]=B,t[93]=We,t[94]=r,t[95]=i,t[96]=U,t[97]=O,t[98]=at,t[99]=S,t[100]=He,t[101]=At,t[102]=Ot,t[103]=Fe,t[104]=tt,t[105]=Te,t[106]=we,t[107]=Re,t[108]=zt):zt=t[108],(0,Q.useLayoutEffect)(zt);let Bt,Vt;t[109]===Ne?(Bt=t[110],Vt=t[111]):(Bt=()=>{let e=e=>{if(!(e.metaKey||e.ctrlKey)||e.altKey||e.key.toLowerCase()!==`a`||RV(e.target))return;let t=ce.current,n=e.target,r=document.activeElement,i=n instanceof Node&&t?.contains(n),a=r instanceof Node&&t?.contains(r);if(!i&&!a)return;let o=new Set([...Ue.current,...Be.current]);re.current=!0;for(let e of o)!e||W.current.has(e)||Ne.getItem(e)?.select();queueMicrotask(()=>{re.current=!1}),e.preventDefault(),e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},Vt=[Ne],t[109]=Ne,t[110]=Bt,t[111]=Vt),(0,Q.useEffect)(Bt,Vt);let Ht,Ut;t[112]!==S.length||t[113]!==w?(Ht=()=>{if(w||S.length===0)return;let e=ce.current?.querySelector(tj)?.shadowRoot;if(!e)return;let t=QV,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()},Ut=[w,S.length],t[112]=S.length,t[113]=w,t[114]=Ht,t[115]=Ut):(Ht=t[114],Ut=t[115]),(0,Q.useEffect)(Ht,Ut);let Wt,Gt;t[116]!==S.length||t[117]!==w?(Wt=()=>{if(w||S.length===0)return;let e=ce.current?.querySelector(tj)?.shadowRoot;if(!e)return;let t=()=>dB(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()},Gt=[w,S.length],t[116]=S.length,t[117]=w,t[118]=Wt,t[119]=Gt):(Wt=t[118],Gt=t[119]),(0,Q.useEffect)(Wt,Gt);let Kt,qt;t[120]!==S.length||t[121]!==w?(Kt=()=>{if(w||S.length===0)return;let e=ce.current?.querySelector(tj)?.shadowRoot;if(!e)return;let t=()=>wB(e);t();let n=new MutationObserver(t);return n.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`data-item-path`]}),()=>n.disconnect()},qt=[w,S.length],t[120]=S.length,t[121]=w,t[122]=Kt,t[123]=qt):(Kt=t[122],qt=t[123]),(0,Q.useEffect)(Kt,qt);let Jt;t[124]===Symbol.for(`react.memo_cache_sentinel`)?(Jt={folderCount:0,expandedCount:0},t[124]=Jt):Jt=t[124];let Yt=(0,Q.useRef)(Jt),Xt=(0,Q.useRef)(Pt),Zt=(0,Q.useRef)(Mt),Qt;t[125]===Pt?Qt=t[126]:(Qt=()=>{Xt.current=Pt,Zt.current=Mt},t[125]=Pt,t[126]=Qt),(0,Q.useEffect)(Qt);let $t,en;t[127]===Ne?($t=t[128],en=t[129]):($t=()=>({startCreating(e,t){Xt.current(e,t)},startCreatingFromTemplate(e){Zt.current(e)},expandAll(){(0,Q.startTransition)(()=>{for(let e of Ue.current){let t=WB(Ne.getItem(e));t&&t.expand()}})},collapseAll(){let e=new Set(K.current);(0,Q.startTransition)(()=>{for(let t of[...Ue.current].reverse()){if(e.has(t))continue;let n=WB(Ne.getItem(t));n&&n.collapse()}})},getFolderState(){let e=Ue.current,t=0;for(let n of e)WB(Ne.getItem(n))?.isExpanded()&&t++;let n=e.length,r=Yt.current;if(r.folderCount===n&&r.expandedCount===t)return r;let i={folderCount:n,expandedCount:t};return Yt.current=i,i},subscribe(e){return Ne.subscribe(e)}}),en=[Ne],t[127]=Ne,t[128]=$t,t[129]=en),(0,Q.useImperativeHandle)(n,$t,en);let tn;t[130]!==rt||t[131]!==s||t[132]!==a||t[133]!==Ne?(tn=async function(e,t,n){let r=zV(e,R.current,Ue.current),i=q.current;i&&e.some(e=>BV(e,i))&&(i.kind===`file`?r.docNames.add(i.createdPath):r.folderPaths.add(i.createdPath),rt(i));let o=new Set([...r.docNames,...t]),c=new Set([...r.folderPaths,...n]);a([...[...o].map(ZV),...[...c].map(XV)],{force:!0}),await Promise.all([...o].map(e=>s(e)));for(let t of e){let e=t.kind===`folder`?JD(t.path):UD(t.path,t.docExt);Ne.getItem(e)&&Ne.remove(e,t.kind===`folder`?{recursive:!0}:void 0)}C(e=>{let t=pO(e,[...o]);for(let e of c)t=pO(t,[],e);return Qe(t),t}),Fr([`files`,`backlinks`,`graph`])},t[130]=rt,t[131]=s,t[132]=a,t[133]=Ne,t[134]=tn):tn=t[134];let nn=tn,rn;t[135]===nn?rn=t[136]:(rn=async function(e){let t=[],n=[],r=[];for(let i of e){k(i.path);let e=await l(await fetch(`/api/delete-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:i.kind,path:i.path})}),`Failed to delete path`);if(!e.ok)return r.length>0&&await nn(r,t,n),X.error(e.title),!1;let a=Ze(ei,e.body,`delete-path`,{deletedDocNames:[]});t.push(...a.deletedDocNames),i.kind===`folder`&&n.push(i.path),r.push(i)}return await nn(r,t,n),!0},t[135]=nn,t[136]=rn);let an=rn,on;t[137]===Symbol.for(`react.memo_cache_sentinel`)?(on=async function(e,t,n){let r=[],i=[];for(let a of e){k(a.path);let e=gO(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:RB(o.reason),detail:o.detail})}return{trashed:r,failed:i}},t[137]=on):on=t[137];let sn=on,cn;t[138]===Symbol.for(`react.memo_cache_sentinel`)?(cn=async function(e){let t=[],n=[],r=[];for(let i of e)try{let e=await l(await fetch(`/api/trash/cleanup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:i.kind,path:i.path})}),`Failed to clean up after trash`);if(!e.ok){console.warn(`[FileTree] trash-cleanup failed`,{target:`${i.kind}:${i.path}`,reason:e.title}),r.push({target:i,reason:e.title});continue}let a=Ze(ir,e.body,`trash-cleanup`,{deletedDocNames:[]});t.push(...a.deletedDocNames),i.kind===`folder`&&n.push(i.path)}catch(e){let t=e;console.warn(`[FileTree] trash-cleanup threw`,{target:`${i.kind}:${i.path}`,err:t}),r.push({target:i,reason:`Network error during cleanup`})}if(r.length>0){let e=r.length,t=e===1?`item`:`items`;X.error(`Server-side cleanup failed for ${e} ${t}`,{description:`The file is in your Trash; the file-watcher will reconcile.`})}return r.length===e.length&&e.length>0?null:{deletedDocNames:t,deletedFolderPaths:n}},t[138]=cn):cn=t[138];let ln=cn,un;t[139]!==nn||t[140]!==an||t[141]!==Ye||t[142]!==I?(un=async function(e){let t=e[0];if(!t)return;k(t.path),j(null);let n=typeof window<`u`?window.okDesktop:void 0;try{if(n&&I){let{trashed:t,failed:r}=await sn(e,n,I);if(t.length>0){let e=await ln(t);e?await nn(t,e.deletedDocNames,e.deletedFolderPaths):await nn(t,t.filter(YV).map(JV),t.filter(qV).map(KV))}r.length>0&&N({failed:r,originalTargets:[...e]}),k(null)}else{let t=await an(e);k(null),t||Ye()}}catch(e){let t=e,n=t instanceof Error?t.message:String(t);console.warn(`[FileTree] delete failed:`,t),X.error(`Could not complete delete`,{description:n}),k(null),Ye()}},t[139]=nn,t[140]=an,t[141]=Ye,t[142]=I,t[143]=un):un=t[143];let dn=un,fn;t[144]!==an||t[145]!==Ye||t[146]!==M?(fn=async function(){if(!M)return;let e=new Set(M.failed.map(GV)),t=M.originalTargets.filter(t=>e.has(`${t.kind}:${t.path}`));if(N(null),t.length!==0){k(t[0]?.path??null);try{let e=await an(t);k(null),e||Ye()}catch(e){let t=e,n=t instanceof Error?t.message:String(t);console.warn(`[FileTree] hard-delete fallback failed:`,t),X.error(`Could not complete delete`,{description:n}),k(null),Ye()}}},t[144]=an,t[145]=Ye,t[146]=M,t[147]=fn):fn=t[147];let pn=fn,mn;t[148]!==dn||t[149]!==M?(mn=async function(){if(!M)return;let e=new Set(M.failed.map(WV)),t=M.originalTargets.filter(t=>e.has(`${t.kind}:${t.path}`));N(null),await dn(t)},t[148]=dn,t[149]=M,t[150]=mn):mn=t[150];let gn=mn,_n=(0,Q.useRef)(dn),vn;t[151]===dn?vn=t[152]:(vn=()=>{_n.current=dn},t[151]=dn,t[152]=vn),(0,Q.useEffect)(vn);let yn,bn;t[153]===Symbol.for(`react.memo_cache_sentinel`)?(yn=()=>QB(e=>{if(e.kind===`doc`||e.kind===`folder-index`){let t=e.docName,n=R.current.find(e=>hn(e)&&e.docName===t);_n.current([{kind:`file`,path:t,name:t.split(`/`).pop()??t,docExt:n?.docExt}]);return}if(e.kind===`folder`){_n.current([{kind:`folder`,path:e.folderPath,name:e.folderPath.split(`/`).pop()??e.folderPath}]);return}console.warn(JSON.stringify({event:`file-tree-menu-action-delete-unsupported-kind`,kind:e.kind}))}),bn=[],t[153]=yn,t[154]=bn):(yn=t[153],bn=t[154]),(0,Q.useEffect)(yn,bn);let xn,Sn;t[155]===Ne?(xn=t[156],Sn=t[157]):(xn=()=>eV(e=>{if(e.kind===`doc`||e.kind===`folder-index`){let t=e.docName,n=UD(t,R.current.find(e=>hn(e)&&e.docName===t)?.docExt);Ne.startRenaming(n);return}if(e.kind===`folder`){Ne.startRenaming(e.folderPath);return}console.warn(JSON.stringify({event:`file-tree-menu-action-rename-unsupported-kind`,kind:e.kind}))}),Sn=[Ne],t[155]=Ne,t[156]=xn,t[157]=Sn),(0,Q.useEffect)(xn,Sn);let Cn;t[158]===Symbol.for(`react.memo_cache_sentinel`)?(Cn=function(){let e=ne.current;e&&gV(e),ne.current=null},t[158]=Cn):Cn=t[158];let wn=Cn,Tn;t[159]===f?Tn=t[160]:(Tn=function(e){let t=lH(e.nativeEvent);if(!t||t.endsWith(`/`)){wn();return}let n=WD(t),r=R.current.find(e=>GD(e)===t);if(r&&Hn(r)){wn();return}ne.current!==n&&(wn(),ne.current=n,hV(n,e=>f(e)))},t[159]=f,t[160]=Tn);let En=Tn,Dn;t[161]!==B||t[162]!==Ne||t[163]!==b?(Dn=function(e){if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=uH(e.nativeEvent);if(!t||t.getAttribute(`aria-selected`)!==`true`)return;let n=t.dataset.itemPath;if(!n)return;let r=t.dataset.itemType===`folder`?JD(n):n;if(Ne.getSelectedPaths().length!==1)return;if(t.dataset.itemType===`folder`){let e=qD(r);if(window.location.hash===or(e))return;queueMicrotask(()=>b(e));return}let i=WD(r);window.location.hash!==Tr(i)&&queueMicrotask(()=>B(r))},t[161]=B,t[162]=Ne,t[163]=b,t[164]=Dn):Dn=t[164];let On=Dn;if(w){let e;return t[165]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(fH,{}),t[165]=e):e=t[165],e}if(S.length===0){if(E){let e;return t[166]===E?e=t[167]:(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:E})}),t[166]=E,t[167]=e),e}let e;t[168]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(`span`,{className:`select-none text-sidebar-foreground/30 text-sm`,children:`No files yet.`}),t[168]=e):e=t[168];let n;return t[169]===Pt?n=t[170]:(n=(0,Z.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 py-8`,children:[e,(0,Z.jsx)(Y,{variant:`link`,size:`sm`,className:`font-mono uppercase`,onClick:()=>Pt(`file`,``),children:`Create your first file`})]}),t[169]=Pt,t[170]=n),n}let kn=O!==null,An=A?.targets[0]??null,jn;t[171]===E?jn=t[172]:(jn=E&&(0,Z.jsx)(`span`,{role:`alert`,className:`px-3 pb-1 text-destructive text-xs`,children:E}),t[171]=E,t[172]=jn);let Mn;t[173]===h?Mn=t[174]:(Mn=kV(h),t[173]=h,t[174]=Mn);let Nn;t[175]!==kn||t[176]!==U||t[177]!==Rt||t[178]!==It||t[179]!==He||t[180]!==be||t[181]!==Ce||t[182]!==Ne||t[183]!==xe||t[184]!==Se||t[185]!==Pt||t[186]!==I?(Nn=(e,t)=>(0,Z.jsx)(VV,{item:e,context:t,anyActionBusy:kn,workspace:I,handoff:be,model:Ne,okignoreBinding:xe,projectLocalBinding:Se,mergedConfig:Ce,onStartCreating:Pt,onStartCreatingFromTemplate:Mt,onDelete:e=>j({targets:e}),onExpandSubtree:It,onCollapseSubtree:Rt,folderTreePaths:He,isAsset:U.has(e.path),isAssetTreePath:et}),t[175]=kn,t[176]=U,t[177]=Rt,t[178]=It,t[179]=He,t[180]=be,t[181]=Ce,t[182]=Ne,t[183]=xe,t[184]=Se,t[185]=Pt,t[186]=I,t[187]=Nn):Nn=t[187];let Pn;t[188]!==On||t[189]!==En||t[190]!==Ne||t[191]!==jn||t[192]!==Mn||t[193]!==Nn?(Pn=(0,Z.jsx)(`div`,{ref:ce,className:`flex min-h-0 flex-1 flex-col`,children:(0,Z.jsx)(iB,{header:jn,model:Ne,style:Mn,onClickCapture:On,onMouseMove:En,onMouseLeave:wn,renderContextMenu:Nn})}),t[188]=On,t[189]=En,t[190]=Ne,t[191]=jn,t[192]=Mn,t[193]=Nn,t[194]=Pn):Pn=t[194];let Fn=!!A,In;t[195]===O?In=t[196]:(In=e=>{!e&&!O&&j(null)},t[195]=O,t[196]=In);let Ln;t[197]!==O||t[198]!==A||t[199]!==dn||t[200]!==An?(Ln=A&&An&&(0,Z.jsx)(io,{...(()=>{let e=FB(typeof window<`u`&&window.okDesktop!=null?`electron`:`web`,A.targets);return e?{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(UV)}):null}:{itemName:A.targets.length===1?`${An.name}${An.kind===`file`?An.docExt??`.md`:`/`}`:void 0,customTitle:A.targets.length>1?`Delete selected items`:void 0,customDescription:A.targets.length>1?`Are you sure you want to delete ${A.targets.length} selected items? Folders and all files inside them will be deleted. This action cannot be undone.`:An.kind===`folder`?`Are you sure you want to delete ${An.name}/ and all files inside? This action cannot be undone.`:void 0}})(),isSubmitting:O!==null,onDelete:()=>dn(A.targets)}),t[197]=O,t[198]=A,t[199]=dn,t[200]=An,t[201]=Ln):Ln=t[201];let Rn;t[202]!==Fn||t[203]!==In||t[204]!==Ln?(Rn=(0,Z.jsx)(jo,{open:Fn,onOpenChange:In,children:Ln}),t[202]=Fn,t[203]=In,t[204]=Ln,t[205]=Rn):Rn=t[205];let zn=!!M,Bn;t[206]===O?Bn=t[207]:(Bn=e=>{!e&&!O&&N(null)},t[206]=O,t[207]=Bn);let Vn;t[208]!==O||t[209]!==pn||t[210]!==gn||t[211]!==M?(Vn=M&&(0,Z.jsx)(HB,{failedTargets:M.failed,isSubmitting:O!==null,onDeletePermanently:pn,onRetry:gn,onCancel:()=>N(null)}),t[208]=O,t[209]=pn,t[210]=gn,t[211]=M,t[212]=Vn):Vn=t[212];let Un;t[213]!==zn||t[214]!==Bn||t[215]!==Vn?(Un=(0,Z.jsx)(jo,{open:zn,onOpenChange:Bn,children:Vn}),t[213]=zn,t[214]=Bn,t[215]=Vn,t[216]=Un):Un=t[216];let Wn=P!==null,Gn;t[217]===Symbol.for(`react.memo_cache_sentinel`)?(Gn=e=>{e||F(null)},t[217]=Gn):Gn=t[217];let Kn=P?.parentDir??``,qn;t[218]!==Wn||t[219]!==Kn?(qn=(0,Z.jsx)(Hp,{open:Wn,onOpenChange:Gn,kind:`file`,initialDir:Kn}),t[218]=Wn,t[219]=Kn,t[220]=qn):qn=t[220];let Jn;return t[221]!==Pn||t[222]!==Rn||t[223]!==Un||t[224]!==qn?(Jn=(0,Z.jsxs)(Z.Fragment,{children:[Pn,Rn,Un,qn]}),t[221]=Pn,t[222]=Rn,t[223]=Un,t[224]=qn,t[225]=Jn):Jn=t[225],Jn}function UV(e){return(0,Z.jsx)(`li`,{"data-testid":`delete-target-row`,children:IB(e)},`${e.kind}:${e.path}`)}function WV(e){return`${e.kind}:${e.path}`}function GV(e){return`${e.kind}:${e.path}`}function KV(e){return e.path}function qV(e){return e.kind===`folder`}function JV(e){return e.path}function YV(e){return e.kind===`file`}function XV(e){return lt(e)}function ZV(e){return Je(e)}function QV(e){return e.endsWith(`/`)?e.slice(0,-1):e}function $V(e){return!!e}function eH(e){console.warn(`[FileTree] /api/workspace fetch failed:`,e)}function tH(e){console.warn(`[FileTree] unmount cleanup failed:`,e)}function nH(e){X.error(e)}function rH(){}function iH(e){return X.error(e)}function aH(){}function oH(){}async function sH(){}function cH(e){return GD(e)}function lH(e){return uH(e)?.dataset.itemPath??null}function uH(e){for(let t of e.composedPath())if(t instanceof HTMLElement&&t.dataset.itemPath)return t;return null}var dH=[`w-3/4`,`w-2/3`,`w-4/5`,`w-1/2`,`w-3/5`,`w-2/3`];function fH(){let e=(0,$.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Z.jsx)(`div`,{className:`flex flex-1 flex-col gap-1 px-2 py-2`,role:`status`,"aria-busy":`true`,"aria-label":`Loading files`,children:dH.map(pH)}),e[0]=t):t=e[0],t}function pH(e,t){return(0,Z.jsxs)(`div`,{className:`flex h-6 items-center gap-2`,children:[(0,Z.jsx)(Ma,{className:`h-3 w-3 shrink-0 rounded-sm`}),(0,Z.jsx)(Ma,{className:`h-3 ${e}`})]},t)}function mH(e){return e?`No workspace`:null}function hH(e){let t=(0,$.c)(41),{input:n,installStates:r,dispatch:i,webFallbackVisible:a}=e,o=a===void 0?!0:a,s=n===null,c;t[0]===s?c=t[1]:(c=mH(s),t[0]=s,t[1]=c);let l=c,u,d,f,p,m,h,g;if(t[2]!==i||t[3]!==l||t[4]!==n||t[5]!==s||t[6]!==r||t[7]!==o){g=Symbol.for(`react.early_return_sentinel`);bb0:{let e;t[15]===r?e=t[16]:(e=e=>r[e.id]?.installed===!0,t[15]=r,t[16]=e);let a=xm.filter(e);f=r[`claude-code`]?.installed===!0;let c;t[17]===n?c=t[18]:(c=n!==null&&n.docContext!==null?$r(n.docContext.relativePath):``,t[17]=n,t[18]=c);let _=c,v;t[19]!==n||t[20]!==_?(v=()=>{n!==null&&qx(_)},t[19]=n,t[20]=_,t[21]=v):v=t[21],p=v;let y=o&&!f;if(a.length===0&&!y){g=null;break bb0}d=xO,t[22]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Z.jsxs)(wO,{children:[(0,Z.jsx)(Fi,{"aria-hidden":`true`}),`Open with AI`]}),t[22]=h):h=t[22],u=TO;let b;t[23]!==i||t[24]!==l||t[25]!==n||t[26]!==s?(b=e=>{let t=!s,r=l?`Open with AI ${e.displayName}, ${l}`:`Open with AI ${e.displayName}`;return(0,Z.jsxs)(CO,{disabled:!t,onSelect:()=>{n&&i(e.id,n)},"data-testid":`empty-space-open-in-${e.id}`,"aria-label":r,children:[(0,Z.jsx)(Vx,{id:e.id,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:e.displayName}),l?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:l}):null]},e.id)},t[23]=i,t[24]=l,t[25]=n,t[26]=s,t[27]=b):b=t[27],m=a.map(b)}t[2]=i,t[3]=l,t[4]=n,t[5]=s,t[6]=r,t[7]=o,t[8]=u,t[9]=d,t[10]=f,t[11]=p,t[12]=m,t[13]=h,t[14]=g}else u=t[8],d=t[9],f=t[10],p=t[11],m=t[12],h=t[13],g=t[14];if(g!==Symbol.for(`react.early_return_sentinel`))return g;let _;t[28]!==f||t[29]!==p||t[30]!==s||t[31]!==o?(_=o&&!f?(0,Z.jsxs)(CO,{onSelect:p,disabled:s,"data-testid":`empty-space-open-in-claude-web-fallback`,"aria-label":`Open in claude.ai, opens in browser with prompt pre-filled`,children:[(0,Z.jsx)(he,{className:`size-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:`Open in claude.ai →`}),(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:`opens in browser`})]}):null,t[28]=f,t[29]=p,t[30]=s,t[31]=o,t[32]=_):_=t[32];let v;t[33]!==u||t[34]!==m||t[35]!==_?(v=(0,Z.jsxs)(u,{children:[m,_]}),t[33]=u,t[34]=m,t[35]=_,t[36]=v):v=t[36];let y;return t[37]!==d||t[38]!==h||t[39]!==v?(y=(0,Z.jsxs)(d,{children:[h,v]}),t[37]=d,t[38]=h,t[39]=v,t[40]=y):y=t[40],y}var gH=(e,t,n)=>il(e,t,n,`ProjectSwitcher`);function _H(e){let t=(0,$.c)(59),{bridge:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0];let[i,a]=(0,Q.useState)(r),[o,s]=(0,Q.useState)(!1),c;t[1]!==n.project||t[2]!==o?(c=()=>{if(!o)return;let e=!1;return gH(async()=>{let t=await n.project.listRecent();e||a(t)},`Failed to load recent projects.`),()=>{e=!0}},t[1]=n.project,t[2]=o,t[3]=c):c=t[3];let l;t[4]!==n||t[5]!==o?(l=[o,n],t[4]=n,t[5]=o,t[6]=l):l=t[6],(0,Q.useEffect)(c,l);let u;t[7]===n.project?u=t[8]:(u=e=>{s(!1),gH(()=>n.project.open({path:e,target:`new-window`,entryPoint:`recents`}),`Failed to open project.`)},t[7]=n.project,t[8]=u);let d=u,f;t[9]!==n.dialog||t[10]!==n.project?(f=()=>{s(!1),gH(async()=>{let e=await n.dialog.openFolder();e&&await n.project.open({path:e,target:`new-window`,entryPoint:`pick-existing`})},`Failed to open folder.`)},t[9]=n.dialog,t[10]=n.project,t[11]=f):f=t[11];let p=f,m;t[12]===n.navigator?m=t[13]:(m=()=>{s(!1),gH(()=>n.navigator.open(),`Failed to open Project Navigator.`)},t[12]=n.navigator,t[13]=m);let h=m,g=n.config.projectPath,_,v,y,b,x,S,C,w,T,E,D;if(t[14]!==n.config.projectName||t[15]!==g||t[16]!==o||t[17]!==d||t[18]!==i){let e;t[30]===g?e=t[31]:(e=e=>e.path!==g,t[30]=g,t[31]=e);let r=i.filter(e);v=va,S=o,C=s;let a;t[32]===n.config.projectName?a=t[33]:(a=(0,Z.jsx)(`span`,{className:`truncate`,children:n.config.projectName}),t[32]=n.config.projectName,t[33]=a);let c;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Z.jsx)(qs,{"aria-hidden":`true`,className:`opacity-60`}),t[34]=c):c=t[34],t[35]===a?w=t[36]:(w=(0,Z.jsx)(ba,{asChild:!0,children:(0,Z.jsxs)(yD,{className:`justify-between text-sidebar-foreground/70`,"data-testid":`project-switcher-trigger`,title:`Open project menu`,children:[a,c]})}),t[35]=a,t[36]=w),_=_a,T=`start`,E=`top`,D=`min-w-[260px]`,y=`project-switcher-menu`,t[37]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Z.jsx)(Qi,{className:`font-mono font-normal tracking-wide uppercase text-muted-foreground text-xs`,children:`Recent projects`}),t[37]=b):b=t[37],x=r.length===0?(0,Z.jsx)(Qi,{className:`font-normal text-muted-foreground text-xs`,children:`No other recent projects.`}):r.slice(0,10).map(e=>(0,Z.jsxs)(ya,{disabled:e.missing,onSelect:()=>d(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?` (missing)`:``]})]},e.path)),t[14]=n.config.projectName,t[15]=g,t[16]=o,t[17]=d,t[18]=i,t[19]=_,t[20]=v,t[21]=y,t[22]=b,t[23]=x,t[24]=S,t[25]=C,t[26]=w,t[27]=T,t[28]=E,t[29]=D}else _=t[19],v=t[20],y=t[21],b=t[22],x=t[23],S=t[24],C=t[25],w=t[26],T=t[27],E=t[28],D=t[29];let O;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,Z.jsx)(na,{}),t[38]=O):O=t[38];let k;t[39]===p?k=t[40]:(k=(0,Z.jsx)(ya,{onSelect:p,"data-testid":`project-switcher-open-folder`,children:`Open folder`}),t[39]=p,t[40]=k);let A;t[41]===h?A=t[42]:(A=(0,Z.jsx)(ya,{onSelect:h,"data-testid":`project-switcher-switch-project`,children:`Switch Project`}),t[41]=h,t[42]=A);let j;t[43]!==_||t[44]!==y||t[45]!==b||t[46]!==x||t[47]!==k||t[48]!==A||t[49]!==T||t[50]!==E||t[51]!==D?(j=(0,Z.jsxs)(_,{align:T,side:E,className:D,"data-testid":y,children:[b,x,O,k,A]}),t[43]=_,t[44]=y,t[45]=b,t[46]=x,t[47]=k,t[48]=A,t[49]=T,t[50]=E,t[51]=D,t[52]=j):j=t[52];let M;return t[53]!==v||t[54]!==S||t[55]!==C||t[56]!==w||t[57]!==j?(M=(0,Z.jsxs)(v,{open:S,onOpenChange:C,children:[w,j]}),t[53]=v,t[54]=S,t[55]=C,t[56]=w,t[57]=j,t[58]=M):M=t[58],M}function vH(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})),Hr(`sidebarSearchPill`)}function yH(e){let t=(0,$.c)(8),{onClick:n,className:r}=e,i;t[0]===r?i=t[1]:(i=mi(`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,o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(Me,{"aria-hidden":`true`}),o=(0,Z.jsx)(`span`,{className:`flex-1 text-left text-sm`,children:`Search`}),t[2]=a,t[3]=o):(a=t[2],o=t[3]);let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,Z.jsx)(OS,{className:`text-foreground/70`,children:Dn()?`⌘ K`:`Ctrl K`}),t[4]=s):s=t[4];let c;return t[5]!==n||t[6]!==i?(c=(0,Z.jsxs)(Y,{variant:`outline`,onClick:n,"data-telemetry-event":`ok.sidebar.search_pill.click`,className:i,children:[a,o,s]}),t[5]=n,t[6]=i,t[7]=c):c=t[7],c}function bH(e){let t=(0,$.c)(33),{notice:n,onDismiss:r}=e,i=n.variant===`error`?`border-destructive/60`:`border-sidebar-border`,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(_o,{"aria-hidden":`true`,className:`size-3`}),t[0]=a):a=t[0];let o;t[1]===r?o=t[2]:(o=(0,Z.jsx)(Y,{variant:`ghost`,size:`icon`,className:`size-5 shrink-0 text-muted-foreground hover:text-sidebar-foreground`,"aria-label":`Dismiss notice`,onClick:r,children:a}),t[1]=r,t[2]=o);let s=o;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 ${i}`,a;t[3]===n.body?a=t[4]:(a=(0,Z.jsx)(`span`,{className:`flex-1 leading-snug`,children:n.body}),t[3]=n.body,t[4]=a);let o;t[5]!==s||t[6]!==a?(o=(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[a,s]}),t[5]=s,t[6]=a,t[7]=o):o=t[7];let c;t[8]===n.action?c=t[9]:(c=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[8]=n.action,t[9]=c);let l;t[10]===n.secondaryAction?l=t[11]:(l=()=>{n.secondaryAction?.onClick()},t[10]=n.secondaryAction,t[11]=l);let u;t[12]!==n.secondaryAction.label||t[13]!==l?(u=(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:l,children:n.secondaryAction.label}),t[12]=n.secondaryAction.label,t[13]=l,t[14]=u):u=t[14];let d;t[15]!==c||t[16]!==u?(d=(0,Z.jsxs)(`div`,{className:`flex gap-3 pl-1`,children:[c,u]}),t[15]=c,t[16]=u,t[17]=d):d=t[17];let f;return t[18]!==d||t[19]!==e||t[20]!==r||t[21]!==o?(f=(0,Z.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":e,className:r,children:[o,d]}),t[18]=d,t[19]=e,t[20]=r,t[21]=o,t[22]=f):f=t[22],f}let c=`update-notice-${n.id}`,l=`flex items-center gap-2 rounded-md border bg-sidebar-accent/30 px-2 py-1.5 text-xs text-muted-foreground ${i}`,u;t[23]===n.body?u=t[24]:(u=(0,Z.jsx)(`span`,{className:`flex-1 leading-snug`,children:n.body}),t[23]=n.body,t[24]=u);let d;t[25]===n.action?d=t[26]:(d=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[25]=n.action,t[26]=d);let f;return t[27]!==s||t[28]!==c||t[29]!==l||t[30]!==u||t[31]!==d?(f=(0,Z.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":c,className:l,children:[u,d,s]}),t[27]=s,t[28]=c,t[29]=l,t[30]=u,t[31]=d,t[32]=f):f=t[32],f}function xH(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 SH(){let e=(0,$.c)(7),t=(0,Q.useSyncExternalStore)(qf,Kf,Kf),n;e[0]===t?n=e[1]:(n=xH(t),e[0]=t,e[1]=n);let r=n;if(!r)return null;let i;e[2]===r.id?i=e[3]:(i=()=>{Gf(r.id)},e[2]=r.id,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)(bH,{notice:r,onDismiss:i})}),e[4]=r,e[5]=i,e[6]=a):a=e[6],a}function CH(e,t,n){return e?.kind===`doc`&&t||e?.kind===`folder-index`&&t?nh(n.contentDir,rh(t),n.pathSeparator):e?.kind===`folder`?nh(n.contentDir,e.folderPath,n.pathSeparator):n.contentDir}function wH(e,t,n){if((e?.kind===`doc`||e?.kind===`folder-index`)&&t){let e=t.lastIndexOf(`/`);return e<0?n.contentDir:nh(n.contentDir,t.slice(0,e),n.pathSeparator)}return e?.kind===`folder`?nh(n.contentDir,e.folderPath,n.pathSeparator):n.contentDir}function TH(e,t){return(e?.kind===`doc`||e?.kind===`folder-index`)&&t?rh(t):e?.kind===`folder`?e.folderPath:``}function EH(e,t,n){return e===null?ah({workspace:n}):e.kind===`folder`?n?oh({folderAbsPath:nh(n.contentDir,e.folderPath,n.pathSeparator),folderRelativePath:e.folderPath,workspace:n}):null:e.kind===`doc`||e.kind===`folder-index`?ih({docName:t,workspace:n}):null}var DH={folderCount:0,expandedCount:0},OH=`button, [role="button"], [role="menuitem"], input, textarea, select, a[href]`;function kH(e){return typeof Element>`u`||!(e instanceof Element)?!1:e.closest(OH)!==null}function AH(e){let t=(0,$.c)(2),{onOpenSearch:n}=e,r;return t[0]===n?r=t[1]:(r=(0,Z.jsx)(Ve,{name:`file-sidebar`,children:(0,Z.jsx)(MH,{onOpenSearch:n})}),t[0]=n,t[1]=r),r}var jH=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)(kr,{asChild:!0,children:(0,Z.jsx)(Y,{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)(vn,{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 MH(e){let t=(0,$.c)(164),{onOpenSearch:n}=e,[r,i]=(0,Q.useState)(null),{activeDocName:a,activeTarget:o}=ot(),s;t[0]!==a||t[1]!==o?(s=o?.kind===`folder`||o?.kind===`folder-index`?o.folderPath:sr(a),t[0]=a,t[1]=o,t[2]=s):s=t[2];let c=s,l=typeof window<`u`&&window.okDesktop!=null,{state:u}=aD(),d=u===`expanded`,f=l&&u===`collapsed`,[p,m]=(0,Q.useState)(DH),h,g;t[3]===r?(h=t[4],g=t[5]):(h=()=>{if(r!==null)return m(r.getFolderState()),r.subscribe(()=>{m(r.getFolderState())})},g=[r],t[3]=r,t[4]=h,t[5]=g),(0,Q.useEffect)(h,g);let _,v;t[6]===r?(_=t[7],v=t[8]):(_=()=>{if(r!==null)return MS(()=>{r.startCreating(`file`,``)})},v=[r],t[6]=r,t[7]=_,t[8]=v),(0,Q.useEffect)(_,v);let y=p.folderCount>0,b=y&&p.expandedCount===p.folderCount,x=p.expandedCount===0,S=Aa(``),C=S.state.status===`ready`?(S.state.data.folder.templates_available?.length??0)>0:!0,w=typeof window<`u`?window.okDesktop:void 0,T=km(),D=Oh().states,{dispatch:k}=_h(),A;t[9]===T?A=t[10]:(A=ah({workspace:T}),t[9]=T,t[10]=A);let j=A,{projectLocalBinding:M,merged:N}=Ga(),P=N?.appearance?.sidebar?.showHiddenFiles??!1,F=N?.appearance?.sidebar?.showAllFiles??!1,I=y&&!b,L=y&&!x,z=I||L,B=IH,V;t[11]!==r||t[12]!==T?(V=()=>{T&&r?.startCreating(`file`,``)},t[11]=r,t[12]=T,t[13]=V):V=t[13];let H=V,U;t[14]!==r||t[15]!==T?(U=()=>{T&&r?.startCreatingFromTemplate(``)},t[14]=r,t[15]=T,t[16]=U):U=t[16];let W=U,G;t[17]!==r||t[18]!==T?(G=()=>{T&&r?.startCreating(`folder`,``)},t[17]=r,t[18]=T,t[19]=G):G=t[19];let K=G,q;t[20]===T?q=t[21]:(q=()=>{!T||!w||w.shell.showItemInFolder(T.contentDir)},t[20]=T,t[21]=q);let ee=q,te;t[22]===T?te=t[23]:(te=()=>{!T||!w||JB(w,T.contentDir)},t[22]=T,t[23]=te);let ne=te,re;t[24]===T?re=t[25]:(re=async()=>{if(T)try{await navigator.clipboard.writeText(T.contentDir),X.success(`Copied full path`,{description:T.contentDir})}catch(e){console.warn(`[FileSidebar] clipboard write failed:`,e),X.error(`Could not copy full path`)}},t[24]=T,t[25]=re);let ie=re,ae;t[26]===M?ae=t[27]:(ae=e=>{if(M===null)return;let t=M.patch({appearance:{sidebar:{showHiddenFiles:e}}});t.ok||(console.warn(`[FileSidebar] showHiddenFiles toggle rejected:`,Nn(t.error)),X.error(`Could not update sidebar settings`,{description:Nn(t.error)}))},t[26]=M,t[27]=ae);let oe=ae,se;t[28]===M?se=t[29]:(se=e=>{if(M===null)return;let t=M.patch({appearance:{sidebar:{showAllFiles:e}}});t.ok||(console.warn(`[FileSidebar] showAllFiles toggle rejected:`,Nn(t.error)),X.error(`Could not update sidebar settings`,{description:Nn(t.error)}))},t[28]=M,t[29]=se);let ce=se,le;t[30]===r?le=t[31]:(le=()=>{r?.expandAll()},t[30]=r,t[31]=le);let J=le,ue;t[32]===r?ue=t[33]:(ue=()=>{r?.collapseAll()},t[32]=r,t[33]=ue);let de=ue,fe,pe;t[34]!==F||t[35]!==L||t[36]!==I||t[37]!==P?(fe=()=>{w&&w.editor.notifyViewMenuStateChanged({showHiddenFiles:P,showAllFiles:F,canExpandAll:I,canCollapseAll:L})},pe=[w,P,F,I,L],t[34]=F,t[35]=L,t[36]=I,t[37]=P,t[38]=fe,t[39]=pe):(fe=t[38],pe=t[39]),(0,Q.useEffect)(fe,pe);let me,he;t[40]!==a||t[41]!==o||t[42]!==k||t[43]!==D||t[44]!==c||t[45]!==M||t[46]!==F||t[47]!==P||t[48]!==r||t[49]!==T?(me=()=>{if(w)return w.onMenuAction(e=>{switch(e){case`new-doc`:if(!T||!r)return;r.startCreating(`file`,c);return;case`new-folder`:if(!T||!r)return;r.startCreating(`folder`,c);return;case`new-from-template`:if(!T||!r)return;r.startCreatingFromTemplate(c);return;case`rename`:if(!o)return;$B(o);return;case`move-to-trash`:if(!o)return;ZB(o);return;case`reveal-in-finder`:{if(!w||!T)return;let e=CH(o,a,T);w.shell.showItemInFolder(e);return}case`open-in-terminal`:if(!w||!T)return;JB(w,wH(o,a,T));return;case`send-to-ai`:{let e=xm.filter(e=>D[e.id]?.installed===!0);if(e.length===0){X.error(`No AI agents installed`);return}let t=EH(o,a,T);if(!t)return;let[n]=e;if(!n)return;k(n.id,t);return}case`copy-full-path`:{if(!T)return;let e=CH(o,a,T);navigator.clipboard.writeText(e).then(()=>X.success(`Copied full path`,{description:e})).catch(FH);return}case`copy-relative-path`:{let e=TH(o,a);if(e===``){X.error(`No file or folder selected`);return}navigator.clipboard.writeText(e).then(()=>X.success(`Copied relative path`,{description:e})).catch(PH);return}case`toggle-show-hidden-files`:{if(M===null)return;let e=M.patch({appearance:{sidebar:{showHiddenFiles:!P}}});e.ok||(console.warn(`[FileSidebar] toggle-show-hidden-files rejected:`,Nn(e.error)),X.error(`Could not update sidebar settings`,{description:Nn(e.error)}));return}case`toggle-show-all-files`:{if(M===null)return;let e=M.patch({appearance:{sidebar:{showAllFiles:!F}}});e.ok||(console.warn(`[FileSidebar] toggle-show-all-files rejected:`,Nn(e.error)),X.error(`Could not update sidebar settings`,{description:Nn(e.error)}));return}case`expand-all-tree`:r?.expandAll();return;case`collapse-all-tree`:r?.collapseAll();return;case`delete`:case`toggle-sidebar`:case`toggle-source`:case`save-version`:case`version-history`:case`focus-search`:case`focus-command-palette`:return}})},he=[w,r,T,o,a,c,M,P,F,D,k],t[40]=a,t[41]=o,t[42]=k,t[43]=D,t[44]=c,t[45]=M,t[46]=F,t[47]=P,t[48]=r,t[49]=T,t[50]=me,t[51]=he):(me=t[50],he=t[51]),(0,Q.useEffect)(me,he);let ge=f&&`opacity-0`,_e;t[52]===ge?_e=t[53]:(_e=mi(`flex-row h-12 items-center py-0 px-3`,l?`justify-end`:`justify-between`,l&&`motion-safe:transition-opacity motion-safe:duration-100 motion-safe:ease-out`,ge,l&&`[-webkit-app-region:drag]`),t[52]=ge,t[53]=_e);let ve;t[54]===d?ve=t[55]:(ve=d&&!l?(0,Z.jsx)(`span`,{className:`shrink-0 font-mono text-sm uppercase tracking-wider text-sidebar-foreground/50`,children:`Files`}):null,t[54]=d,t[55]=ve);let ye;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(ye=mi(`flex items-center gap-1`,l&&`[&>*]:[-webkit-app-region:no-drag]`),t[56]=ye):ye=t[56];let be;t[57]!==b||t[58]!==y||t[59]!==x||t[60]!==r?(be=y?(0,Z.jsxs)(va,{children:[(0,Z.jsx)(ba,{asChild:!0,children:(0,Z.jsx)(jH,{icon:yc,label:`Tree View Options`})}),(0,Z.jsxs)(_a,{align:`end`,children:[b?null:(0,Z.jsxs)(ya,{onSelect:()=>r?.expandAll(),children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),`Expand All`]}),x?null:(0,Z.jsxs)(ya,{onSelect:()=>r?.collapseAll(),children:[(0,Z.jsx)(cc,{"aria-hidden":`true`}),`Collapse All`]})]})]}):null,t[57]=b,t[58]=y,t[59]=x,t[60]=r,t[61]=be):be=t[61];let xe;t[62]!==c||t[63]!==r?(xe=(0,Z.jsx)(jH,{icon:Wc,label:`New File`,onClick:()=>r?.startCreating(`file`,c)}),t[62]=c,t[63]=r,t[64]=xe):xe=t[64];let Se;t[65]!==C||t[66]!==c||t[67]!==r?(Se=C?(0,Z.jsx)(jH,{icon:oc,label:`New from template`,onClick:()=>r?.startCreatingFromTemplate(c)}):null,t[65]=C,t[66]=c,t[67]=r,t[68]=Se):Se=t[68];let Ce;t[69]!==c||t[70]!==r?(Ce=(0,Z.jsx)(jH,{icon:uc,label:`New Folder`,onClick:()=>r?.startCreating(`folder`,c)}),t[69]=c,t[70]=r,t[71]=Ce):Ce=t[71];let we;t[72]!==be||t[73]!==xe||t[74]!==Se||t[75]!==Ce?(we=(0,Z.jsxs)(`div`,{className:ye,children:[be,xe,Se,Ce]}),t[72]=be,t[73]=xe,t[74]=Se,t[75]=Ce,t[76]=we):we=t[76];let Te;t[77]!==_e||t[78]!==ve||t[79]!==we?(Te=(0,Z.jsxs)(pD,{className:_e,children:[ve,we]}),t[77]=_e,t[78]=ve,t[79]=we,t[80]=Te):Te=t[80];let Ee=f&&`opacity-0`,De;t[81]===Ee?De=t[82]:(De=mi(`px-2 pb-2`,l&&`[-webkit-app-region:no-drag]`,l&&`motion-safe:transition-opacity motion-safe:duration-100 motion-safe:ease-out`,Ee),t[81]=Ee,t[82]=De);let Oe;t[83]===u?Oe=t[84]:(Oe=[u],t[83]=u,t[84]=Oe);let ke;t[85]===n?ke=t[86]:(ke=(0,Z.jsx)(yH,{onClick:n}),t[85]=n,t[86]=ke);let Ae;t[87]!==Oe||t[88]!==ke?(Ae=(0,Z.jsx)(O,{fallbackRender:NH,onError:vH,resetKeys:Oe,children:ke}),t[87]=Oe,t[88]=ke,t[89]=Ae):Ae=t[89];let je;t[90]!==De||t[91]!==Ae?(je=(0,Z.jsx)(`div`,{className:De,children:Ae}),t[90]=De,t[91]=Ae,t[92]=je):je=t[92];let Me;t[93]===Symbol.for(`react.memo_cache_sentinel`)?(Me=(0,Z.jsx)(hD,{children:(0,Z.jsx)(HV,{ref:i})}),t[93]=Me):Me=t[93];let Ne,Pe;t[94]===Symbol.for(`react.memo_cache_sentinel`)?(Ne=(0,Z.jsxs)(mD,{className:`px-0`,children:[typeof window<`u`&&window.okDesktop?(0,Z.jsx)(gD,{children:(0,Z.jsx)(_D,{children:(0,Z.jsx)(_H,{bridge:window.okDesktop})})}):null,(0,Z.jsx)(SH,{})]}),Pe=(0,Z.jsx)(dD,{enableToggle:!1}),t[94]=Ne,t[95]=Pe):(Ne=t[94],Pe=t[95]);let Fe;t[96]!==Te||t[97]!==je?(Fe=(0,Z.jsx)(bO,{asChild:!0,children:(0,Z.jsxs)(`div`,{className:`contents`,onContextMenu:B,children:[Te,je,Me,Ne,Pe]})}),t[96]=Te,t[97]=je,t[98]=Fe):Fe=t[98];let Ie=!T,Le;t[99]===Symbol.for(`react.memo_cache_sentinel`)?(Le=(0,Z.jsx)(Wc,{"aria-hidden":`true`}),t[99]=Le):Le=t[99];let Re;t[100]!==H||t[101]!==Ie?(Re=(0,Z.jsxs)(CO,{disabled:Ie,onSelect:H,"data-testid":`empty-space-menu-new-file`,children:[Le,`New File`]}),t[100]=H,t[101]=Ie,t[102]=Re):Re=t[102];let ze=!T||!C,Be;t[103]===Symbol.for(`react.memo_cache_sentinel`)?(Be=(0,Z.jsx)(oc,{"aria-hidden":`true`}),t[103]=Be):Be=t[103];let Ve;t[104]!==W||t[105]!==ze?(Ve=(0,Z.jsxs)(CO,{disabled:ze,onSelect:W,"data-testid":`empty-space-menu-new-from-template`,children:[Be,`New from template`]}),t[104]=W,t[105]=ze,t[106]=Ve):Ve=t[106];let He=!T,Ue;t[107]===Symbol.for(`react.memo_cache_sentinel`)?(Ue=(0,Z.jsx)(uc,{"aria-hidden":`true`}),t[107]=Ue):Ue=t[107];let We;t[108]!==K||t[109]!==He?(We=(0,Z.jsxs)(CO,{disabled:He,onSelect:K,"data-testid":`empty-space-menu-new-folder`,children:[Ue,`New Folder`]}),t[108]=K,t[109]=He,t[110]=We):We=t[110];let Ge;t[111]===Symbol.for(`react.memo_cache_sentinel`)?(Ge=(0,Z.jsx)(DO,{}),t[111]=Ge):Ge=t[111];let Ke;t[112]!==ee||t[113]!==T?(Ke=w?(0,Z.jsxs)(CO,{disabled:!T,onSelect:ee,"data-testid":`empty-space-menu-reveal-in-finder`,"aria-label":T?`Reveal in Finder`:`Reveal in Finder, No workspace`,children:[(0,Z.jsx)(R,{"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:`Reveal in Finder`}),T?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:`No workspace`})]}):null,t[112]=ee,t[113]=T,t[114]=Ke):Ke=t[114];let qe;t[115]!==k||t[116]!==j||t[117]!==D?(qe=(0,Z.jsx)(hH,{input:j,installStates:D,dispatch:k,webFallbackVisible:!1}),t[115]=k,t[116]=j,t[117]=D,t[118]=qe):qe=t[118];let Je;t[119]!==ne||t[120]!==T?(Je=w?(0,Z.jsxs)(CO,{disabled:!T,onSelect:ne,"data-testid":`empty-space-menu-open-in-terminal`,"aria-label":T?`Open in Terminal`:`Open in Terminal, No workspace`,children:[(0,Z.jsx)(Yc,{"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:`Open in Terminal`}),T?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:`No workspace`})]}):null,t[119]=ne,t[120]=T,t[121]=Je):Je=t[121];let Ye=!T,Xe=T?`Copy full path`:`Copy full path, No workspace`,Ze,Qe;t[122]===Symbol.for(`react.memo_cache_sentinel`)?(Ze=(0,Z.jsx)(E,{"aria-hidden":`true`}),Qe=(0,Z.jsx)(`span`,{className:`flex-1`,children:`Copy full path`}),t[122]=Ze,t[123]=Qe):(Ze=t[122],Qe=t[123]);let $e;t[124]===T?$e=t[125]:($e=T?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:`No workspace`}),t[124]=T,t[125]=$e);let et;t[126]!==ie||t[127]!==Ye||t[128]!==Xe||t[129]!==$e?(et=(0,Z.jsxs)(CO,{disabled:Ye,onSelect:ie,"data-testid":`empty-space-menu-copy-full-path`,"aria-label":Xe,children:[Ze,Qe,$e]}),t[126]=ie,t[127]=Ye,t[128]=Xe,t[129]=$e,t[130]=et):et=t[130];let tt;t[131]===Symbol.for(`react.memo_cache_sentinel`)?(tt=(0,Z.jsx)(DO,{}),t[131]=tt):tt=t[131];let nt=M===null,rt;t[132]!==oe||t[133]!==P||t[134]!==nt?(rt=(0,Z.jsx)(EO,{checked:P,onCheckedChange:oe,disabled:nt,"data-testid":`empty-space-menu-show-hidden-files`,children:`Show Hidden Files`}),t[132]=oe,t[133]=P,t[134]=nt,t[135]=rt):rt=t[135];let it=M===null,at;t[136]!==ce||t[137]!==F||t[138]!==it?(at=(0,Z.jsx)(EO,{checked:F,onCheckedChange:ce,disabled:it,"data-testid":`empty-space-menu-show-all-files`,children:`Show all files`}),t[136]=ce,t[137]=F,t[138]=it,t[139]=at):at=t[139];let st;t[140]===z?st=t[141]:(st=z?(0,Z.jsx)(DO,{}):null,t[140]=z,t[141]=st);let ct;t[142]!==J||t[143]!==I?(ct=I?(0,Z.jsxs)(CO,{onSelect:J,"data-testid":`empty-space-menu-expand-all`,children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),`Expand all`]}):null,t[142]=J,t[143]=I,t[144]=ct):ct=t[144];let lt;t[145]!==de||t[146]!==L?(lt=L?(0,Z.jsxs)(CO,{onSelect:de,"data-testid":`empty-space-menu-collapse-all`,children:[(0,Z.jsx)(cc,{"aria-hidden":`true`}),`Collapse all`]}):null,t[145]=de,t[146]=L,t[147]=lt):lt=t[147];let ut;t[148]!==Re||t[149]!==Ve||t[150]!==We||t[151]!==Ke||t[152]!==qe||t[153]!==Je||t[154]!==et||t[155]!==rt||t[156]!==at||t[157]!==st||t[158]!==ct||t[159]!==lt?(ut=(0,Z.jsxs)(SO,{children:[Re,Ve,We,Ge,Ke,qe,Je,et,tt,rt,at,st,ct,lt]}),t[148]=Re,t[149]=Ve,t[150]=We,t[151]=Ke,t[152]=qe,t[153]=Je,t[154]=et,t[155]=rt,t[156]=at,t[157]=st,t[158]=ct,t[159]=lt,t[160]=ut):ut=t[160];let dt;return t[161]!==Fe||t[162]!==ut?(dt=(0,Z.jsx)(lD,{variant:`inset`,children:(0,Z.jsxs)(yO,{children:[Fe,ut]})}),t[161]=Fe,t[162]=ut,t[163]=dt):dt=t[163],dt}function NH(){return null}function PH(e){console.warn(`[FileSidebar] clipboard write failed:`,e),X.error(`Could not copy relative path`)}function FH(e){console.warn(`[FileSidebar] clipboard write failed:`,e),X.error(`Could not copy full path`)}function IH(e){kH(e.target)&&(e.preventDefault(),e.stopPropagation())}function LH(){let e=(0,$.c)(17),t=ln(),{collabUrl:n,setSystemProvider:r,updateServerInstanceId:i,onBranchSwitched:a,observeBranch:o,observeDiskAck:s,refreshServerInfo:c}=ot(),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 Se,i=new _t({url:n,name:$n,document:e,onStateless:e=>{let{payload:t}=e;_(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:UH,onConfigValidationRejected:HH,onConfigIgnoreNestedError:VH,onUnknown:BH})},onClose:zH,onDisconnect:RH}),a=br(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=q(()=>{u.current.refreshServerInfo()});i.on(`synced`,()=>{Fr([`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 RH(){console.warn(`[CC1] __system__ disconnected - derived views may be stale`)}function zH(e){let{event:t}=e;console.warn(`[CC1] __system__ connection closed:`,t.code,t.reason)}function BH(e){console.warn(`[CC1] Unparseable stateless payload, skipping:`,e.slice(0,100))}function VH(e){Za(e)}function HH(e){eo(e)}function UH(e){Fr([e.ch])}var WH=`#install-claude-desktop`;function GH(e){return e===`#settings`||e===WH}function KH(e,t,n){return[e,t,n].map(e=>[...e].sort().join(`\0`)).join(``)}function qH(){let e=(0,$.c)(20),{clearTarget:t,syncOpenTabsWithKnownTargets:n,tabSessionLoaded:r}=ot(),{openTargetTransition:i}=gt(),{assetPaths:a,folderPaths:o,loading:s,pages:c}=qr(),l=(0,Q.useRef)(null),u;e[0]!==a||e[1]!==o||e[2]!==c?(u=KH(c,o,a),e[0]=a,e[1]=o,e[2]=c,e[3]=u):u=e[3];let d=u,f,p;e[4]!==a||e[5]!==o||e[6]!==s||e[7]!==c||e[8]!==n||e[9]!==r||e[10]!==d?(f=()=>{s||!r||l.current===d||(l.current=d,n({pages:c,folderPaths:o,assetPaths:a}))},p=[a,o,s,c,n,r,d],e[4]=a,e[5]=o,e[6]=s,e[7]=c,e[8]=n,e[9]=r,e[10]=d,e[11]=f,e[12]=p):(f=e[11],p=e[12]),(0,Q.useEffect)(f,p);let m,h;return e[13]!==t||e[14]!==o||e[15]!==s||e[16]!==i||e[17]!==c?(m=()=>{e();function e(){if(GH(window.location.hash))return;let e=Jr(window.location.hash);if(e){let t=Er(e.split(`.`).pop()??``);dt(`ok/nav/hash-change`,{docName:null,kind:`asset`}),i({kind:`asset`,target:e,assetPath:e,mediaKind:t});return}let n=Rr(window.location.hash);if(!n){dt(`ok/nav/hash-change`,{docName:null,kind:`clear`}),t();return}if(s){dt(`ok/nav/hash-change`,{docName:n,kind:`deferred-loading`});return}let r=Yr(n,{pages:c,folderPaths:o});if(r.kind===`missing`&&/\/+$/.test(n.trim())){dt(`ok/nav/hash-change`,{docName:n,kind:`deferred-missing-folder`});return}let a=jr(r);dt(`ok/nav/hash-change`,{docName:n,kind:a.kind}),i(a)}return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},h=[t,o,s,i,c],e[13]=t,e[14]=o,e[15]=s,e[16]=i,e[17]=c,e[18]=m,e[19]=h):(m=e[18],h=e[19]),(0,Q.useEffect)(m,h),null}function JH(){let e=(0,$.c)(5),[t,n]=(0,Q.useState)(typeof window<`u`&&window.location.hash===WH),r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=function(){window.location.hash===WH&&n(!0)};return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),(0,Q.useEffect)(r,i);let a;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=function(e){if(n(e),!e&&window.location.hash===WH){let{pathname:e,search:t}=window.location;window.history.replaceState(null,``,`${e}${t}`)}},e[2]=a):a=e[2];let o=a,s;return e[3]===t?s=e[4]:(s=(0,Z.jsx)(Ta,{open:t,onOpenChange:o}),e[3]=t,e[4]=s),s}function YH(){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)(XH,t),null}function XH(){let e=function(e){let t=e.target;Cm({target:t,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,key:e.key})&&(e.preventDefault(),window.location.hash!==`#settings`&&(window.location.hash=Sm))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}function ZH(){let e=(0,$.c)(4),{activeTarget:t}=ot(),n=typeof window<`u`?window.okDesktop??null:null,r=t?.kind===`doc`||t?.kind===`folder`?t.kind:null,i=t?.kind===`doc`?t.docName:t?.kind===`folder`?t.folderPath: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 QH(){let e=(0,$.c)(8),{activeDocName:t,activeTarget:n}=ot(),[r,i]=(0,Q.useState)(!1),a;e[0]!==t||e[1]!==n?(a=n?.kind===`folder`?n.folderPath:sr(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;Bp({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)(Hp,{open:r,onOpenChange:i,kind:`file`,initialDir:o}),e[5]=r,e[6]=o,e[7]=l):l=e[7],l}function $H(){let e=(0,$.c)(21),t=typeof window<`u`?window.okDesktop??null:null,n=typeof window<`u`&&window.okDesktop!=null,[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=t?ol({bridge:t,authQueryTransport:ul(),cloneTransport:gl(),openSignIn:()=>new Promise(e=>{c(()=>e),o(!0)})}):null,e[0]=l):l=e[0];let u=l,d;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Z.jsx)(Gh,{}),e[1]=d):d=e[1];let f,p,m,h,g,_,v,y;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Z.jsx)(LH,{}),p=(0,Z.jsx)(qH,{}),m=(0,Z.jsx)(ZH,{}),h=(0,Z.jsx)(QH,{}),g=(0,Z.jsx)(YH,{}),_=(0,Z.jsx)(JH,{}),v=(0,Z.jsx)(Td,{}),y=t&&u?(0,Z.jsx)(zd,{bridge:t,cloneController:u}):null,e[2]=f,e[3]=p,e[4]=m,e[5]=h,e[6]=g,e[7]=_,e[8]=v,e[9]=y):(f=e[2],p=e[3],m=e[4],h=e[5],g=e[6],_=e[7],v=e[8],y=e[9]);let b;e[10]!==a||e[11]!==s?(b=t?(0,Z.jsx)(qu,{open:a,onOpenChange:e=>{e||(o(!1),s?.(null),c(null))},onSuccess:e=>{s?.({authenticated:!0,host:`github.com`,login:e.login}),c(null)}}):null,e[10]=a,e[11]=s,e[12]=b):b=e[12];let x;e[13]===r?x=e[14]:(x=(0,Z.jsx)(Rh,{bridge:t,open:r,onOpenChange:i}),e[13]=r,e[14]=x);let S;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(S=n&&(0,Z.jsx)(`div`,{"aria-hidden":`true`,"data-testid":`editor-window-chrome-drag-strip`,className:`pointer-events-none fixed inset-x-0 top-0 z-50 h-2 [-webkit-app-region:drag]`}),e[15]=S):S=e[15];let C;e[16]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Z.jsx)(AH,{onOpenSearch:()=>i(!0)}),e[16]=C):C=e[16];let w;e[17]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Z.jsxs)(oD,{className:`h-screen overflow-hidden`,children:[C,(0,Z.jsx)(fD,{className:`overflow-hidden h-[calc(100vh-var(--layout-inset-offset))]`,children:(0,Z.jsx)(Uk,{})})]}),e[17]=w):w=e[17];let T;return e[18]!==b||e[19]!==x?(T=(0,Z.jsx)(Ve,{name:`app`,children:(0,Z.jsx)(bt,{children:(0,Z.jsxs)(to,{children:[d,(0,Z.jsxs)(zr,{children:[f,p,m,h,g,_,v,y,b,x,S,w]})]})})}),e[18]=b,e[19]=x,e[20]=T):T=e[20],T}ws(),typeof window<`u`&&window.okDesktop?.config.apiOrigin&&Yd({apiOrigin:window.okDesktop.config.apiOrigin}),hf()&&xf(),Jf(),typeof window<`u`&&Qd({bridge:window.okDesktop}),typeof window<`u`&&Xo({bridge:window.okDesktop}),typeof window<`u`&&Ko({bridge:window.okDesktop}),typeof window<`u`&&tf({bridge:window.okDesktop}),typeof window<`u`&&Rd({bridge:window.okDesktop});var eU=new Ns({defaultOptions:{queries:{retry:1,staleTime:1e4}}}),tU=document.getElementById(`root`);if(!tU)throw Error(`Root element not found`);var nU=typeof window<`u`&&window.okDesktop?.config.mode===`navigator`;(0,Us.createRoot)(tU).render((0,Z.jsx)(Q.StrictMode,{children:(0,Z.jsx)(tn,{client:eU,children:(0,Z.jsxs)(pr,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,disableTransitionOnChange:!0,storageKey:`ok-theme-v1`,children:[(0,Z.jsx)(zn,{children:nU&&window.okDesktop?(0,Z.jsx)(Wd,{bridge:window.okDesktop}):(0,Z.jsx)($H,{})}),(0,Z.jsx)(Jd,{richColors:!0,closeButton:!0})]})})}));
1918
+ </svg>`,OV=`${uB}\n${CB}`;function kV(e){return{...Sj({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 AV(e){let t=e.split(`/`).pop()?.replace(/\.md$/i,``).toLowerCase();return!!t&&SV.has(t)}function jV(e){return e===`darwin`?`Reveal in Finder`:e===`win32`?`Reveal in File Explorer`:`Open Containing Folder`}function MV(e){let t=(0,$.c)(14),{item:n,workspace:r,onClose:i}=e,a=typeof window<`u`?window.okDesktop:void 0;if(!a)return null;let o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=jV(a.platform),t[0]=o):o=t[0];let s=o,c=r?null:`No workspace`,l=!r,u;t[1]!==n||t[2]!==i||t[3]!==r?(u=()=>{if(!r)return;i();let e=nh(r.contentDir,nO(n),r.pathSeparator);a.shell.showItemInFolder(e)},t[1]=n,t[2]=i,t[3]=r,t[4]=u):u=t[4];let d=c?`${s}, ${c}`:s,f,p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Z.jsx)(R,{"aria-hidden":`true`}),p=(0,Z.jsx)(`span`,{className:`flex-1`,children:s}),t[5]=f,t[6]=p):(f=t[5],p=t[6]);let m;t[7]===c?m=t[8]:(m=c?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:c}):null,t[7]=c,t[8]=m);let h;return t[9]!==l||t[10]!==u||t[11]!==d||t[12]!==m?(h=(0,Z.jsxs)(ya,{disabled:l,onSelect:u,"aria-label":d,children:[f,p,m]}),t[9]=l,t[10]=u,t[11]=d,t[12]=m,t[13]=h):h=t[13],h}function NV(e){let t=(0,$.c)(12),{dirAbsPath:n,onClose:r}=e,i=typeof window<`u`?window.okDesktop:void 0;if(!i)return null;let a=n===null?`No workspace`:null,o=n===null,s;t[0]!==n||t[1]!==r?(s=()=>{n!==null&&(r(),JB(i,n))},t[0]=n,t[1]=r,t[2]=s):s=t[2];let c=a?`Open in Terminal, ${a}`:`Open in Terminal`,l,u;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Z.jsx)(Yc,{"aria-hidden":`true`}),u=(0,Z.jsx)(`span`,{className:`flex-1`,children:`Open in Terminal`}),t[3]=l,t[4]=u):(l=t[3],u=t[4]);let d;t[5]===a?d=t[6]:(d=a?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:a}):null,t[5]=a,t[6]=d);let f;return t[7]!==o||t[8]!==s||t[9]!==c||t[10]!==d?(f=(0,Z.jsxs)(ya,{disabled:o,onSelect:s,"aria-label":c,children:[l,u,d]}),t[7]=o,t[8]=s,t[9]=c,t[10]=d,t[11]=f):f=t[11],f}function PV(e){return tO({kind:e.endsWith(`/`)?`directory`:`file`,name:e,path:e})}function FV(e,t){return e!==t&&e.startsWith(t)}function IV(e,t){let n=[...new Set(e)].filter(e=>!t(e)),r=n.filter(e=>e.endsWith(`/`));return n.filter(e=>!r.some(t=>FV(e,t))).map(PV)}function LV(e,t){return e===t||e.startsWith(`${t}/`)}function RV(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 zV(e,t,n){let r=new Set,i=new Set;for(let a of e){if(a.kind===`file`){r.add(a.path);continue}i.add(a.path);for(let e of t)hn(e)&&e.docName.startsWith(`${a.path}/`)&&r.add(e.docName);for(let e of n){let t=qD(e);LV(t,a.path)&&i.add(t)}}return{docNames:r,folderPaths:i}}function BV(e,t){return e.kind===`file`?t.kind===`file`&&e.path===t.createdPath:LV(t.createdPath,e.path)}function VV(e){let t=(0,$.c)(75),{item:n,context:r,anyActionBusy:i,workspace:a,handoff:o,model:s,okignoreBinding:c,projectLocalBinding:l,mergedConfig:u,onStartCreating:f,onStartCreatingFromTemplate:p,onDelete:h,onExpandSubtree:g,onCollapseSubtree:_,folderTreePaths:v,isAsset:y,isAssetTreePath:b}=e,x,S,C,w,T,D,O,k;if(t[0]!==y||t[1]!==b||t[2]!==n||t[3]!==u?.appearance?.sidebar?.showAllFiles||t[4]!==u?.appearance?.sidebar?.showHiddenFiles||t[5]!==s||t[6]!==c||t[7]!==l){k=tO(n),w=n.kind===`directory`,x=!y&&c!==null,C=w?`Hide folder`:`Hide this file`,D=u?.appearance?.sidebar?.showHiddenFiles??!1,T=u?.appearance?.sidebar?.showAllFiles??!1,S=l!==null;let e=s.getSelectedPaths();O=e.includes(k.treePath)?IV(e,b):[],t[0]=y,t[1]=b,t[2]=n,t[3]=u?.appearance?.sidebar?.showAllFiles,t[4]=u?.appearance?.sidebar?.showHiddenFiles,t[5]=s,t[6]=c,t[7]=l,t[8]=x,t[9]=S,t[10]=C,t[11]=w,t[12]=T,t[13]=D,t[14]=O,t[15]=k}else x=t[8],S=t[9],C=t[10],w=t[11],T=t[12],D=t[13],O=t[14],k=t[15];let A=O,j;t[16]!==A||t[17]!==k?(j=A.length>1?A:[k],t[16]=A,t[17]=k,t[18]=j):j=t[18];let M=j,N=M.length>1?`Delete ${M.length} Items`:`Delete`,P,F,I;if(t[19]!==y||t[20]!==w||t[21]!==n||t[22]!==a){P=w&&a?nh(a.contentDir,nO(n),a.pathSeparator):null;let e;if(t[26]!==w||t[27]!==n||t[28]!==a){bb0:{if(!a||w){e=null;break bb0}let t=nO(n),r=t.lastIndexOf(`/`);if(r===-1){e=a.contentDir;break bb0}e=nh(a.contentDir,t.slice(0,r),a.pathSeparator)}t[26]=w,t[27]=n,t[28]=a,t[29]=e}else e=t[29];F=e,I=y?null:w?oh({folderAbsPath:P??``,folderRelativePath:nO(n),workspace:a}):ih({docName:WD(n.path),workspace:a}),t[19]=y,t[20]=w,t[21]=n,t[22]=a,t[23]=P,t[24]=F,t[25]=I}else P=t[23],F=t[24],I=t[25];let L=I,R;t[30]===r?R=t[31]:(R=()=>r.close({restoreFocus:!1}),t[30]=r,t[31]=R);let z=R,B;t[32]===r?B=t[33]:(B=()=>r.close(),t[32]=r,t[33]=B);let V=B,H;t[34]===l?H=t[35]:(H=e=>{if(l===null)return;let t=l.patch({appearance:{sidebar:{showHiddenFiles:e}}});t.ok||(console.warn(`[FileTree] showHiddenFiles toggle rejected:`,Nn(t.error)),X.error(`Could not update sidebar settings`,{description:Nn(t.error)}))},t[34]=l,t[35]=H);let U=H,W;t[36]===l?W=t[37]:(W=e=>{if(l===null)return;let t=l.patch({appearance:{sidebar:{showAllFiles:e}}});t.ok||(console.warn(`[FileTree] showAllFiles toggle rejected:`,Nn(t.error)),X.error(`Could not update sidebar settings`,{description:Nn(t.error)}))},t[36]=l,t[37]=W);let G=W,K=0,q=0;if(w){let e=JD(n.path);for(let t of v)(t===e||t.startsWith(e))&&(K++,WB(s.getItem(t))?.isExpanded()&&q++)}let ee=w&&q<K,te=w&&q>0,ne;t[38]===V?ne=t[39]:(ne=e=>{e||V()},t[38]=V,t[39]=ne);let re;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,Z.jsx)(ba,{asChild:!0,children:(0,Z.jsx)(`span`,{"aria-hidden":`true`,"data-file-tree-context-menu-root":`true`,className:`block size-px`})}),t[40]=re):re=t[40];let ie;t[41]!==i||t[42]!==x||t[43]!==S||t[44]!==V||t[45]!==z||t[46]!==N||t[47]!==M||t[48]!==P||t[49]!==G||t[50]!==U||t[51]!==o||t[52]!==L||t[53]!==C||t[54]!==y||t[55]!==w||t[56]!==n||t[57]!==s||t[58]!==c||t[59]!==_||t[60]!==h||t[61]!==g||t[62]!==f||t[63]!==p||t[64]!==F||t[65]!==T||t[66]!==D||t[67]!==te||t[68]!==ee||t[69]!==k||t[70]!==a?(ie=(0,Z.jsx)(_a,{sideOffset:0,align:`start`,"data-file-tree-context-menu-root":`true`,className:`min-w-52`,children:w?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(ya,{disabled:i,onSelect:()=>{z(),f(`file`,qD(n.path))},children:[(0,Z.jsx)(Wc,{"aria-hidden":`true`}),`New File`]}),(0,Z.jsxs)(ya,{disabled:i,onSelect:()=>{z(),p(qD(n.path))},children:[(0,Z.jsx)(oc,{"aria-hidden":`true`}),`New from template`]}),(0,Z.jsxs)(ya,{disabled:i,onSelect:()=>{z(),f(`folder`,qD(n.path))},children:[(0,Z.jsx)(uc,{"aria-hidden":`true`}),`New Folder`]}),(0,Z.jsx)(na,{}),(0,Z.jsx)(MV,{item:n,workspace:a,onClose:V}),(0,Z.jsx)(rV,{input:L,installStates:o.installStates,isElectronHost:o.isElectronHost,dispatch:o.dispatch,webFallbackVisible:!1}),(0,Z.jsx)(NV,{dirAbsPath:P,onClose:V}),(0,Z.jsxs)(Xa,{children:[(0,Z.jsxs)(xa,{children:[(0,Z.jsx)(E,{"aria-hidden":`true`}),`Copy Path`]}),(0,Z.jsxs)(ta,{children:[(0,Z.jsx)(ya,{disabled:!a,onSelect:()=>{a&&(V(),xV(nh(a.contentDir,nO(n),a.pathSeparator),`full path`))},children:`Full Path`}),(0,Z.jsx)(ya,{onSelect:()=>{V(),xV(nO(n),`relative path`)},children:`Relative Path`})]})]}),(0,Z.jsx)(na,{}),(0,Z.jsx)($i,{checked:D,onCheckedChange:U,disabled:!S,"data-testid":`file-tree-menu-show-hidden-files`,children:`Show Hidden Files`}),(0,Z.jsx)($i,{checked:T,onCheckedChange:G,disabled:!S,"data-testid":`file-tree-menu-show-all-files`,children:`Show all files`}),ee||te?(0,Z.jsx)(na,{}):null,ee?(0,Z.jsxs)(ya,{onSelect:()=>{V(),g(n.path)},children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),`Expand All`]}):null,te?(0,Z.jsxs)(ya,{onSelect:()=>{V(),_(n.path)},children:[(0,Z.jsx)(cc,{"aria-hidden":`true`}),`Collapse All`]}):null,(0,Z.jsx)(na,{}),(0,Z.jsxs)(ya,{disabled:i,onSelect:()=>{z(),s.startRenaming(n.path)},children:[(0,Z.jsx)(m,{"aria-hidden":`true`}),`Rename`]}),(0,Z.jsxs)(ya,{"data-testid":`file-tree-menu-hide`,disabled:!x,onSelect:()=>{if(!c)return;V();let e=gB(k),t=no(c.current()),n=Ka(t,e);if(n===t)return;c.patch(Ja(n));let r=k.path.split(`/`).pop()||k.path;X.success(`Hidden folder “${r}”`,{description:`Manage hidden files in Settings → Ignore patterns.`,duration:5e3})},children:[(0,Z.jsx)(d,{"aria-hidden":`true`}),C]}),(0,Z.jsxs)(ya,{variant:`destructive`,disabled:i,onSelect:()=>{V(),h(M)},children:[(0,Z.jsx)(Ue,{"aria-hidden":`true`}),N]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(MV,{item:n,workspace:a,onClose:V}),!y&&(0,Z.jsx)(rV,{input:L,installStates:o.installStates,isElectronHost:o.isElectronHost,dispatch:o.dispatch,webFallbackVisible:!0}),(0,Z.jsx)(NV,{dirAbsPath:F,onClose:V}),(0,Z.jsxs)(Xa,{children:[(0,Z.jsxs)(xa,{children:[(0,Z.jsx)(E,{"aria-hidden":`true`}),`Copy Path`]}),(0,Z.jsxs)(ta,{children:[(0,Z.jsx)(ya,{disabled:!a,onSelect:()=>{a&&(V(),xV(nh(a.contentDir,nO(n),a.pathSeparator),`full path`))},children:`Full Path`}),(0,Z.jsx)(ya,{onSelect:()=>{V(),xV(nO(n),`relative path`)},children:`Relative Path`})]})]}),y?null:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(na,{}),(0,Z.jsxs)(ya,{disabled:i,onSelect:()=>{z(),s.startRenaming(n.path)},children:[(0,Z.jsx)(m,{"aria-hidden":`true`}),`Rename`]}),(0,Z.jsxs)(ya,{"data-testid":`file-tree-menu-hide`,disabled:!x,onSelect:()=>{if(!c)return;V();let e=gB(k),t=no(c.current()),n=Ka(t,e);if(n===t)return;c.patch(Ja(n));let r=k.path.split(`/`).pop()||k.path;X.success(`Hidden “${r}”`,{description:`Manage hidden files in Settings → Ignore patterns.`,duration:5e3})},children:[(0,Z.jsx)(d,{"aria-hidden":`true`}),C]}),(0,Z.jsxs)(ya,{variant:`destructive`,disabled:i,onSelect:()=>{V(),h(M)},children:[(0,Z.jsx)(Ue,{"aria-hidden":`true`}),N]})]})]})}),t[41]=i,t[42]=x,t[43]=S,t[44]=V,t[45]=z,t[46]=N,t[47]=M,t[48]=P,t[49]=G,t[50]=U,t[51]=o,t[52]=L,t[53]=C,t[54]=y,t[55]=w,t[56]=n,t[57]=s,t[58]=c,t[59]=_,t[60]=h,t[61]=g,t[62]=f,t[63]=p,t[64]=F,t[65]=T,t[66]=D,t[67]=te,t[68]=ee,t[69]=k,t[70]=a,t[71]=ie):ie=t[71];let ae;return t[72]!==ie||t[73]!==ne?(ae=(0,Z.jsxs)(va,{open:!0,modal:!1,onOpenChange:ne,children:[re,ie]}),t[72]=ie,t[73]=ne,t[74]=ae):ae=t[74],ae}function HV(e){let t=(0,$.c)(226),{ref:n}=e,{activeDocName:r,activeTarget:i,closeTabs:a,closeDocument:o,closeAndClearForRename:s,getPoolActiveDocName:c,isNewTabActive:u,openTarget:d,prewarm:f,remapTabsForRename:p}=ot(),{notifySidebarFileSelected:m}=aD(),{resolvedTheme:h}=vr(),{addPage:g}=qr(),_;t[0]!==m||t[1]!==d?(_=function(e){d({kind:`doc`,target:e,docName:e},{tabBehavior:`replace-active`}),vV(Tr(e)),m()},t[0]=m,t[1]=d,t[2]=_):_=t[2];let v=_,y;t[3]!==m||t[4]!==d?(y=function(e){let t=or(e);d({kind:`folder`,target:e,folderPath:e},{tabBehavior:`replace-active`}),vV(t),m()},t[3]=m,t[4]=d,t[5]=y):y=t[5];let b=y,x;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(x=[],t[6]=x):x=t[6];let[S,C]=(0,Q.useState)(x),[w,T]=(0,Q.useState)(!0),[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(null),[M,N]=(0,Q.useState)(null),[P,F]=(0,Q.useState)(null),[I,L]=(0,Q.useState)(null),R=(0,Q.useRef)(S),z;t[7]!==S||t[8]!==b||t[9]!==v||t[10]!==m||t[11]!==d?(z=function(e,t){let n=MB(e,t===void 0?S:t);if(n.kind===`none`){console.debug(`[FileTree] Dropped selection for unknown docName:`,YD(e));return}if(n.kind===`asset`){d({kind:`asset`,target:n.path,assetPath:n.path,mediaKind:n.mediaKind},{tabBehavior:`replace-active`}),vV(n.hash),m();return}if(n.kind===`folder`){b(n.path);return}v(n.path)},t[7]=S,t[8]=b,t[9]=v,t[10]=m,t[11]=d,t[12]=z):z=t[12];let B=z,V=(0,Q.useRef)(r),H;t[13]===S?H=t[14]:(H=new Set(S.filter(Hn).map(cH)),t[13]=S,t[14]=H);let U=H,W=(0,Q.useRef)(U),G;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(G=[],t[15]=G):G=t[15];let K=(0,Q.useRef)(G),q=(0,Q.useRef)(null),ee=(0,Q.useRef)(sH),te=(0,Q.useRef)(null),ne=(0,Q.useRef)(null),re=(0,Q.useRef)(!1),ie=(0,Q.useRef)(null),ae=(0,Q.useRef)(!1),oe=(0,Q.useRef)(!1),se=(0,Q.useRef)(null),ce=(0,Q.useRef)(null),le=(0,Q.useRef)(oH),J=(0,Q.useRef)(aH),ue=(0,Q.useRef)(iH),de=(0,Q.useRef)(rH),fe=(0,Q.useRef)(i),{selectedFilePath:pe,selectedFolderPath:me,navigationPath:he}=jB(i,u?null:r),ge=pe?UD(pe,S.find(e=>hn(e)&&e.docName===pe)?.docExt):me?JD(me):i?.kind===`asset`?i.assetPath:null,_e=Oh().states,{dispatch:ve}=_h(),ye;t[16]!==ve||t[17]!==_e?(ye={installStates:_e,isElectronHost:typeof window<`u`&&window.okDesktop!=null,dispatch:ve},t[16]=ve,t[17]=_e,t[18]=ye):ye=t[18];let be=ye,{okignoreBinding:xe,projectLocalBinding:Se,merged:Ce}=Ga(),we=Ce?.appearance?.sidebar?.showHiddenFiles??!1,Te=Ce?.appearance?.sidebar?.showAllFiles??!1,Ee;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(Ee=()=>ie.current===null,t[19]=Ee):Ee=t[19];let De=Ee,Oe;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(Oe=[],t[20]=Oe):Oe=t[20];let ke;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(ke={set:`complete`,spriteSheet:DV},t[21]=ke):ke=t[21];let Ae;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(Ae={contextMenu:{enabled:!0,triggerMode:`both`,buttonVisibility:`when-needed`}},t[22]=Ae):Ae=t[22];let je;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(je={canDrag:De,canDrop:De,onDropComplete:e=>de.current(e),onDropError:nH},t[23]=je):je=t[23];let Me;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(Me={paths:Oe,flattenEmptyDirectories:!1,initialExpansion:`closed`,fileTreeSearchMode:`hide-non-matches`,initialVisibleRowCount:18,stickyFolders:!0,icons:ke,unsafeCSS:OV,composition:Ae,dragAndDrop:je,renaming:{canRename:De,onRename:e=>J.current(e),onError:e=>ue.current(e)},onSelectionChange:e=>le.current(e),renderRowDecoration:e=>{let{item:t}=e;if(t.kind!==`file`)return null;let n=R.current.find(e=>hn(e)&&UD(e.docName,e.docExt)===t.path);return n?.isSymlink?{icon:CV,title:n.targetPath?`Symlink to ${n.targetPath}`:`Symlink`}:AV(t.path)?{icon:wV,title:`Agent configuration file`}:null}},t[24]=Me):Me=t[24];let{model:Ne}=aB(Me),Pe;t[25]===Ne?Pe=t[26]:(Pe=function(e){let t=Ne.getItem(e)??Ne.getItem(JD(e));return t?.isDirectory()?JD(qD(t.getPath())):e},t[25]=Ne,t[26]=Pe);let Fe=Pe,Le,Re;t[27]===S?(Le=t[28],Re=t[29]):(Re=XD(S),Le=ZD(Re),t[27]=S,t[28]=Le,t[29]=Re);let ze=Le,Be=(0,Q.useRef)(Re),Ve;t[30]===S?Ve=t[31]:(Ve=$D(S),t[30]=S,t[31]=Ve);let He=Ve,Ue=(0,Q.useRef)(He),We=me?eO(JD(me)).slice(0,-1):eO(ge??he),Ge=We.join(`\0`),Ke;if(t[32]!==Ne){let e=()=>{let e=new Set;for(let t of Ue.current)WB(Ne.getItem(t))?.isExpanded()&&e.add(t);return e};Ke=t=>{let n=new Set($D(t??R.current)),r=e();for(let e of K.current)r.add(e);return[...r].filter(e=>n.has(e))},t[32]=Ne,t[33]=Ke}else Ke=t[33];let qe=Ke,Je;t[34]!==qe||t[35]!==Ne?(Je=e=>{let t=XD(e??R.current);Ne.resetPaths(t,{initialExpandedPaths:qe(e)})},t[34]=qe,t[35]=Ne,t[36]=Je):Je=t[36];let Ye=Je,Xe;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(Xe=e=>{te.current=QD(e)},t[37]=Xe):Xe=t[37];let Qe=Xe,$e;t[38]===Symbol.for(`react.memo_cache_sentinel`)?($e=e=>W.current.has(e),t[38]=$e):$e=t[38];let et=$e,tt=function(e){let t=yV(e);if(!t||bV(t))return!1;let n=Ne.getFocusedPath()??Ne.getSelectedPaths()[0]??null;if(!n||n.endsWith(`/`)||et(n))return!1;let r=bV(n);if(!r)return!1;let i=JD(t);if(!Ue.current.includes(i))return!1;let a=`${t}${r}`;return Be.current.includes(a)?!1:(Ot({sourcePath:n,destinationPath:a,isFolder:!1}),Ne.move(n,a),!0)},nt;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(nt=e=>{let t=e??q.current;!t||q.current!==t||(t.disposeCommitListener(),q.current=null)},t[39]=nt):nt=t[39];let rt=nt,it;t[40]!==rt||t[41]!==o||t[42]!==a||t[43]!==Ye?(it=async function(e,t){let n=t===void 0?{}:t,r=n.updateUi??!0,i=n.restoreLocation??r;rt(e),r&&k(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=await l(t,`Failed to clean up pending ${e.kind}`);if(n.ok)return;let i=`${n.title} - ${e.kind} "${e.createdPath}" still exists on disk`;r?X.error(i):console.warn(`[FileTree] cleanup pending create failed: ${i}`),r&&(k(null),Ye());return}}catch(t){console.warn(`[FileTree] cleanup pending create failed:`,t),r&&X.error(`Network error - ${e.kind} "${e.createdPath}" still exists on disk`),r&&(k(null),Ye());return}r&&(e.kind===`file`?o(e.createdPath):a([lt(e.createdPath)],{force:!0})),r&&C(t=>{let n=pO(t,e.kind===`file`?[e.createdPath]:[],e.kind===`folder`?e.createdPath:void 0);return Qe(n),n}),Fr([`files`,`backlinks`,`graph`]),i&&(window.location.hash=e.previousHash),r&&k(null)},t[40]=rt,t[41]=o,t[42]=a,t[43]=Ye,t[44]=it):it=t[44];let at=it,st,ct;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(st=()=>()=>{let e=q.current;e&&ee.current(e,{restoreLocation:!1,updateUi:!1}).catch(tH)},ct=[],t[45]=st,t[46]=ct):(st=t[45],ct=t[46]),(0,Q.useEffect)(st,ct);let ut,dt;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(ut=()=>{let e=!0,t=tV(async function(){try{let t=oe.current,n=await l(await fetch(t?`/api/documents?showAll=true`:`/api/documents`),`Failed to load documents`);if(!e)return;if(!n.ok)D(n.title);else{let e=li.safeParse(n.body);if(!e.success)D(`Documents response did not match expected shape.`);else{let n=ae.current||t;C(ai(e.data.documents,n)),D(null)}}}catch(t){let n=t;e&&D(`Could not reach server`),console.warn(`[FileTree] fetch failed:`,n)}e&&T(!1)});se.current=()=>t.request(),t.request();let n=()=>{document.visibilityState===`visible`&&t.request()};window.addEventListener(`focus`,n),window.addEventListener(`visibilitychange`,n);let r=br(e=>{e.includes(`files`)&&t.request()});return()=>{e=!1,se.current=null,t.dispose(),window.removeEventListener(`focus`,n),window.removeEventListener(`visibilitychange`,n),r()}},dt=[],t[47]=ut,t[48]=dt):(ut=t[47],dt=t[48]),(0,Q.useEffect)(ut,dt);let ft=(0,Q.useRef)(!0),pt;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(pt=()=>{if(ft.current){ft.current=!1;return}se.current?.()},t[49]=pt):pt=t[49];let mt;t[50]===we?mt=t[51]:(mt=[we],t[50]=we,t[51]=mt),(0,Q.useEffect)(pt,mt);let ht=(0,Q.useRef)(!0),gt;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(gt=()=>{if(ht.current){ht.current=!1;return}se.current?.()},t[52]=gt):gt=t[52];let _t;t[53]===Te?_t=t[54]:(_t=[Te],t[53]=Te,t[54]=_t),(0,Q.useEffect)(gt,_t);let vt,yt;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(vt=()=>{let e=!0;return fetch(`/api/workspace`).then(async t=>{let n=await t.json();if(!e||!t.ok)return;let r=Ze(Kr,n,`workspace`,null);r&&L({contentDir:r.contentDir,pathSeparator:r.pathSeparator})}).catch(eH),()=>{e=!1}},yt=[],t[55]=vt,t[56]=yt):(vt=t[55],yt=t[56]),(0,Q.useEffect)(vt,yt);let bt;t[57]!==qe||t[58]!==Ne||t[59]!==ze?(bt=()=>{if(te.current===ze){te.current=null;return}Ne.resetPaths(Be.current,{initialExpandedPaths:qe()})},t[57]=qe,t[58]=Ne,t[59]=ze,t[60]=bt):bt=t[60];let xt;t[61]!==Ne||t[62]!==ze?(xt=[Ne,ze],t[61]=Ne,t[62]=ze,t[63]=xt):xt=t[63],(0,Q.useEffect)(bt,xt),KB(Ne,ge,Ge,re);let St,Ct;t[64]===Ne?(St=t[65],Ct=t[66]):(St=()=>Ne.subscribe(()=>{if(!Ne.isSearchOpen())for(let e of K.current){let t=WB(Ne.getItem(e));t&&!t.isExpanded()&&t.expand()}}),Ct=[Ne],t[64]=Ne,t[65]=St,t[66]=Ct),(0,Q.useEffect)(St,Ct);let wt,Tt;t[67]===Ne?(wt=t[68],Tt=t[69]):(wt=()=>Ne.onMutation(`remove`,e=>{let t=q.current;!t||e.path!==t.renamePath||ee.current(t)}),Tt=[Ne],t[67]=Ne,t[68]=wt,t[69]=Tt),(0,Q.useEffect)(wt,Tt);let Et;t[70]!==g||t[71]!==s||t[72]!==c||t[73]!==b||t[74]!==p?(Et=async(e,t,n)=>{let r=t===void 0?[]:t,i=n?.docName??V.current,a=mO(i,e),o=n?.folderPath??(fe.current?.kind===`folder`?fe.current.folderPath:null),l=o?Ie(o,r):null,u=hO(e,c());await Promise.all(u.map(e=>s(e)));for(let t of e)g(t.toDocName);p(e,r),C(t=>{let n=fO(t,e,r);return Qe(n),n}),o&&l&&l!==o?b(l):a&&a!==i&&(window.location.hash=Tr(a)),Fr([`files`,`backlinks`,`graph`])},t[70]=g,t[71]=s,t[72]=c,t[73]=b,t[74]=p,t[75]=Et):Et=t[75];let Dt=Et;async function Ot(e){let t=rO(e.sourcePath,e.isFolder);k(t),D(null);try{if(!e.isFolder&&et(t)){X.error(`Assets cannot be renamed from the sidebar`),queueMicrotask(()=>{Ye()}),rt(),k(null);return}let n=cB(e.sourcePath,e.destinationPath,e.isFolder);if(n.kind===`block`){X.error(`File extensions are managed automatically - please rename without changing the extension`),queueMicrotask(()=>{Ye()}),rt(),k(null);return}let r=rO(n.destinationPath,e.isFolder),i=e.isFolder?{kind:`folder`,fromPath:qD(t),toPath:qD(r)}:{kind:`file`,fromPath:WD(t),toPath:WD(r)},a={docName:V.current,folderPath:fe.current?.kind===`folder`?fe.current.folderPath:null},o=await l(await fetch(`/api/rename-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(i)}),`Failed to rename path`);if(!o.ok){X.error(o.title),D(o.title),Ye();let e=q.current;e&&e.renamePath===t?await at(e):rt(),k(null);return}let s=Ze(Zn,o.body,`rename-path`,{renamed:[]});try{await Dt(s.renamed,e.isFolder?[{fromPath:qD(t),toPath:qD(r)}]:[],a)}catch(e){console.warn(`[FileTree] post-rename reconciliation failed`,{err:e,sourceTreePath:t,destinationTreePath:r,renamedCount:s.renamed.length}),X.error(`Rename succeeded but the sidebar may be out of date — refresh to resync`)}rt(),k(null)}catch(e){console.warn(`[FileTree] rename failed:`,e),X.error(`Network error — please try again`),D(`Network error — please try again`),Ye();let n=q.current;n&&n.renamePath===t?await at(n):rt(),k(null)}}let kt;t[76]!==Dt||t[77]!==Ye?(kt=async function(e){let t=e.draggedPaths.map(t=>{let n=oO(t,e.target);return t===n?null:{sourcePath:t,destinationTreePath:n}}).filter($V);if(t.length!==0){if(t.some(e=>et(e.sourcePath))){X.error(`Assets cannot be moved from the sidebar`),Ye();return}k(t[0]?.sourcePath??null),D(null);try{let e=[],n=[],r={docName:V.current,folderPath:fe.current?.kind===`folder`?fe.current.folderPath:null};for(let r of t){let t=r.sourcePath.endsWith(`/`),i=t?{kind:`folder`,fromPath:qD(r.sourcePath),toPath:qD(r.destinationTreePath)}:{kind:`file`,fromPath:WD(r.sourcePath),toPath:WD(r.destinationTreePath)},a=await l(await fetch(`/api/rename-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(i)}),`Failed to move`);if(!a.ok){X.error(a.title),D(a.title),Ye(),k(null);return}let o=Ze(Zn,a.body,`rename-path:drop`,{renamed:[]});e=e.concat(o.renamed),t&&n.push({fromPath:qD(r.sourcePath),toPath:qD(r.destinationTreePath)})}try{await Dt(e,n,r)}catch(n){console.warn(`[FileTree] post-move reconciliation failed`,{err:n,operationCount:t.length,renamedCount:e.length}),X.error(`Move succeeded but the sidebar may be out of date — refresh to resync`)}k(null)}catch(e){console.warn(`[FileTree] move failed:`,e),X.error(`Network error — please try again`),Ye(),k(null)}}},t[76]=Dt,t[77]=Ye,t[78]=kt):kt=t[78];let At=kt,jt;t[79]===Symbol.for(`react.memo_cache_sentinel`)?(jt=function(e){F({parentDir:e})},t[79]=jt):jt=t[79];let Mt=jt,Nt;t[80]!==at||t[81]!==rt||t[82]!==Ne||t[83]!==b||t[84]!==v||t[85]!==Ye||t[86]!==Re?(Nt=async function(e,t){if(ie.current)return;let n=q.current;n&&rt(n);try{let n=iO(e,t,[...Re,...Ue.current]);k(n.renamePath),ie.current=n.renamePath;let r=window.location.hash,i;if(e===`file`){let e=aO(`file`,n.addPath),t=await l(await fetch(`/api/create-page`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:e})}),`Failed to create file`);if(!t.ok){X.error(t.title),D(t.title),k(null),ie.current=null;return}let r=WD(e),a=Ze(wr,t.body,`create-page`,{docName:r}).docName;i=a;let o=e.toLowerCase().endsWith(`.mdx`)?`.mdx`:`.md`;C(e=>{if(e.some(e=>hn(e)&&e.docName===a))return e;let t=[...e,{kind:`document`,docName:a,docExt:o,modified:new Date().toISOString(),size:0}];return Qe(t),t}),Fr([`files`,`backlinks`,`graph`]),v(a)}else{let e=qD(n.addPath),t=await l(await fetch(`/api/create-folder`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:e})}),`Failed to create folder`);if(!t.ok){X.error(t.title),D(t.title),k(null),ie.current=null;return}i=Ze(Lr,t.body,`create-folder`,{path:e}).path,C(e=>{if(e.some(e=>ti(e)&&e.path===i))return e;let t=[...e,{kind:`folder`,path:i,modified:new Date().toISOString(),size:0}];return Qe(t),t}),Fr([`files`]),b(i)}let a=!1,o=e=>{if(e.key!==`Enter`)return;let t=q.current;!t||t.renamePath!==n.renamePath||queueMicrotask(()=>rt(t))};document.addEventListener(`keydown`,o,!0),q.current={kind:e,renamePath:n.renamePath,createdPath:i,previousHash:r,disposeCommitListener:()=>{a||(a=!0,document.removeEventListener(`keydown`,o,!0))}},k(null),ie.current=null,Ne.add(n.addPath),Ne.startRenaming(n.renamePath,{removeIfCanceled:!0})}catch(e){console.warn(`[FileTree] create placeholder failed:`,e),X.error(`Could not start creating a new item`);let t=q.current;t?await at(t):rt(),k(null),ie.current=null,Ye()}},t[80]=at,t[81]=rt,t[82]=Ne,t[83]=b,t[84]=v,t[85]=Ye,t[86]=Re,t[87]=Nt):Nt=t[87];let Pt=Nt,Ft;t[88]===Ne?Ft=t[89]:(Ft=function(e){let t=JD(e);(0,Q.startTransition)(()=>{for(let e of Ue.current)if(e===t||e.startsWith(t)){let t=WB(Ne.getItem(e));t&&t.expand()}})},t[88]=Ne,t[89]=Ft);let It=Ft,Lt;t[90]===Ne?Lt=t[91]:(Lt=function(e){let t=JD(e),n=new Set(K.current);(0,Q.startTransition)(()=>{for(let e of[...Ue.current].reverse())if((e===t||e.startsWith(t))&&!n.has(e)){let t=WB(Ne.getItem(e));t&&t.collapse()}})},t[90]=Ne,t[91]=Lt);let Rt=Lt,zt;t[92]!==B||t[93]!==We||t[94]!==r||t[95]!==i||t[96]!==U||t[97]!==O||t[98]!==at||t[99]!==S||t[100]!==He||t[101]!==At||t[102]!==Ot||t[103]!==Fe||t[104]!==tt||t[105]!==Te||t[106]!==we||t[107]!==Re?(zt=()=>{R.current=S,V.current=r,fe.current=i,W.current=U,ie.current=O,ae.current=we,oe.current=Te,Be.current=Re,Ue.current=He,K.current=We,ee.current=at,le.current=e=>{if(re.current||e.length!==1)return;let t=e[0];t&&B(Fe(t),S)},ue.current=e=>{tt(e)||X.error(e)},J.current=Ot,de.current=At},t[92]=B,t[93]=We,t[94]=r,t[95]=i,t[96]=U,t[97]=O,t[98]=at,t[99]=S,t[100]=He,t[101]=At,t[102]=Ot,t[103]=Fe,t[104]=tt,t[105]=Te,t[106]=we,t[107]=Re,t[108]=zt):zt=t[108],(0,Q.useLayoutEffect)(zt);let Bt,Vt;t[109]===Ne?(Bt=t[110],Vt=t[111]):(Bt=()=>{let e=e=>{if(!(e.metaKey||e.ctrlKey)||e.altKey||e.key.toLowerCase()!==`a`||RV(e.target))return;let t=ce.current,n=e.target,r=document.activeElement,i=n instanceof Node&&t?.contains(n),a=r instanceof Node&&t?.contains(r);if(!i&&!a)return;let o=new Set([...Ue.current,...Be.current]);re.current=!0;for(let e of o)!e||W.current.has(e)||Ne.getItem(e)?.select();queueMicrotask(()=>{re.current=!1}),e.preventDefault(),e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},Vt=[Ne],t[109]=Ne,t[110]=Bt,t[111]=Vt),(0,Q.useEffect)(Bt,Vt);let Ht,Ut;t[112]!==S.length||t[113]!==w?(Ht=()=>{if(w||S.length===0)return;let e=ce.current?.querySelector(tj)?.shadowRoot;if(!e)return;let t=QV,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()},Ut=[w,S.length],t[112]=S.length,t[113]=w,t[114]=Ht,t[115]=Ut):(Ht=t[114],Ut=t[115]),(0,Q.useEffect)(Ht,Ut);let Wt,Gt;t[116]!==S.length||t[117]!==w?(Wt=()=>{if(w||S.length===0)return;let e=ce.current?.querySelector(tj)?.shadowRoot;if(!e)return;let t=()=>dB(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()},Gt=[w,S.length],t[116]=S.length,t[117]=w,t[118]=Wt,t[119]=Gt):(Wt=t[118],Gt=t[119]),(0,Q.useEffect)(Wt,Gt);let Kt,qt;t[120]!==S.length||t[121]!==w?(Kt=()=>{if(w||S.length===0)return;let e=ce.current?.querySelector(tj)?.shadowRoot;if(!e)return;let t=()=>wB(e);t();let n=new MutationObserver(t);return n.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`data-item-path`]}),()=>n.disconnect()},qt=[w,S.length],t[120]=S.length,t[121]=w,t[122]=Kt,t[123]=qt):(Kt=t[122],qt=t[123]),(0,Q.useEffect)(Kt,qt);let Jt;t[124]===Symbol.for(`react.memo_cache_sentinel`)?(Jt={folderCount:0,expandedCount:0},t[124]=Jt):Jt=t[124];let Yt=(0,Q.useRef)(Jt),Xt=(0,Q.useRef)(Pt),Zt=(0,Q.useRef)(Mt),Qt;t[125]===Pt?Qt=t[126]:(Qt=()=>{Xt.current=Pt,Zt.current=Mt},t[125]=Pt,t[126]=Qt),(0,Q.useEffect)(Qt);let $t,en;t[127]===Ne?($t=t[128],en=t[129]):($t=()=>({startCreating(e,t){Xt.current(e,t)},startCreatingFromTemplate(e){Zt.current(e)},expandAll(){(0,Q.startTransition)(()=>{for(let e of Ue.current){let t=WB(Ne.getItem(e));t&&t.expand()}})},collapseAll(){let e=new Set(K.current);(0,Q.startTransition)(()=>{for(let t of[...Ue.current].reverse()){if(e.has(t))continue;let n=WB(Ne.getItem(t));n&&n.collapse()}})},getFolderState(){let e=Ue.current,t=0;for(let n of e)WB(Ne.getItem(n))?.isExpanded()&&t++;let n=e.length,r=Yt.current;if(r.folderCount===n&&r.expandedCount===t)return r;let i={folderCount:n,expandedCount:t};return Yt.current=i,i},subscribe(e){return Ne.subscribe(e)}}),en=[Ne],t[127]=Ne,t[128]=$t,t[129]=en),(0,Q.useImperativeHandle)(n,$t,en);let tn;t[130]!==rt||t[131]!==s||t[132]!==a||t[133]!==Ne?(tn=async function(e,t,n){let r=zV(e,R.current,Ue.current),i=q.current;i&&e.some(e=>BV(e,i))&&(i.kind===`file`?r.docNames.add(i.createdPath):r.folderPaths.add(i.createdPath),rt(i));let o=new Set([...r.docNames,...t]),c=new Set([...r.folderPaths,...n]);a([...[...o].map(ZV),...[...c].map(XV)],{force:!0}),await Promise.all([...o].map(e=>s(e)));for(let t of e){let e=t.kind===`folder`?JD(t.path):UD(t.path,t.docExt);Ne.getItem(e)&&Ne.remove(e,t.kind===`folder`?{recursive:!0}:void 0)}C(e=>{let t=pO(e,[...o]);for(let e of c)t=pO(t,[],e);return Qe(t),t}),Fr([`files`,`backlinks`,`graph`])},t[130]=rt,t[131]=s,t[132]=a,t[133]=Ne,t[134]=tn):tn=t[134];let nn=tn,rn;t[135]===nn?rn=t[136]:(rn=async function(e){let t=[],n=[],r=[];for(let i of e){k(i.path);let e=await l(await fetch(`/api/delete-path`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:i.kind,path:i.path})}),`Failed to delete path`);if(!e.ok)return r.length>0&&await nn(r,t,n),X.error(e.title),!1;let a=Ze(ei,e.body,`delete-path`,{deletedDocNames:[]});t.push(...a.deletedDocNames),i.kind===`folder`&&n.push(i.path),r.push(i)}return await nn(r,t,n),!0},t[135]=nn,t[136]=rn);let an=rn,on;t[137]===Symbol.for(`react.memo_cache_sentinel`)?(on=async function(e,t,n){let r=[],i=[];for(let a of e){k(a.path);let e=gO(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:RB(o.reason),detail:o.detail})}return{trashed:r,failed:i}},t[137]=on):on=t[137];let sn=on,cn;t[138]===Symbol.for(`react.memo_cache_sentinel`)?(cn=async function(e){let t=[],n=[],r=[];for(let i of e)try{let e=await l(await fetch(`/api/trash/cleanup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:i.kind,path:i.path})}),`Failed to clean up after trash`);if(!e.ok){console.warn(`[FileTree] trash-cleanup failed`,{target:`${i.kind}:${i.path}`,reason:e.title}),r.push({target:i,reason:e.title});continue}let a=Ze(ir,e.body,`trash-cleanup`,{deletedDocNames:[]});t.push(...a.deletedDocNames),i.kind===`folder`&&n.push(i.path)}catch(e){let t=e;console.warn(`[FileTree] trash-cleanup threw`,{target:`${i.kind}:${i.path}`,err:t}),r.push({target:i,reason:`Network error during cleanup`})}if(r.length>0){let e=r.length,t=e===1?`item`:`items`;X.error(`Server-side cleanup failed for ${e} ${t}`,{description:`The file is in your Trash; the file-watcher will reconcile.`})}return r.length===e.length&&e.length>0?null:{deletedDocNames:t,deletedFolderPaths:n}},t[138]=cn):cn=t[138];let ln=cn,un;t[139]!==nn||t[140]!==an||t[141]!==Ye||t[142]!==I?(un=async function(e){let t=e[0];if(!t)return;k(t.path),j(null);let n=typeof window<`u`?window.okDesktop:void 0;try{if(n&&I){let{trashed:t,failed:r}=await sn(e,n,I);if(t.length>0){let e=await ln(t);e?await nn(t,e.deletedDocNames,e.deletedFolderPaths):await nn(t,t.filter(YV).map(JV),t.filter(qV).map(KV))}r.length>0&&N({failed:r,originalTargets:[...e]}),k(null)}else{let t=await an(e);k(null),t||Ye()}}catch(e){let t=e,n=t instanceof Error?t.message:String(t);console.warn(`[FileTree] delete failed:`,t),X.error(`Could not complete delete`,{description:n}),k(null),Ye()}},t[139]=nn,t[140]=an,t[141]=Ye,t[142]=I,t[143]=un):un=t[143];let dn=un,fn;t[144]!==an||t[145]!==Ye||t[146]!==M?(fn=async function(){if(!M)return;let e=new Set(M.failed.map(GV)),t=M.originalTargets.filter(t=>e.has(`${t.kind}:${t.path}`));if(N(null),t.length!==0){k(t[0]?.path??null);try{let e=await an(t);k(null),e||Ye()}catch(e){let t=e,n=t instanceof Error?t.message:String(t);console.warn(`[FileTree] hard-delete fallback failed:`,t),X.error(`Could not complete delete`,{description:n}),k(null),Ye()}}},t[144]=an,t[145]=Ye,t[146]=M,t[147]=fn):fn=t[147];let pn=fn,mn;t[148]!==dn||t[149]!==M?(mn=async function(){if(!M)return;let e=new Set(M.failed.map(WV)),t=M.originalTargets.filter(t=>e.has(`${t.kind}:${t.path}`));N(null),await dn(t)},t[148]=dn,t[149]=M,t[150]=mn):mn=t[150];let gn=mn,_n=(0,Q.useRef)(dn),vn;t[151]===dn?vn=t[152]:(vn=()=>{_n.current=dn},t[151]=dn,t[152]=vn),(0,Q.useEffect)(vn);let yn,bn;t[153]===Symbol.for(`react.memo_cache_sentinel`)?(yn=()=>QB(e=>{if(e.kind===`doc`||e.kind===`folder-index`){let t=e.docName,n=R.current.find(e=>hn(e)&&e.docName===t);_n.current([{kind:`file`,path:t,name:t.split(`/`).pop()??t,docExt:n?.docExt}]);return}if(e.kind===`folder`){_n.current([{kind:`folder`,path:e.folderPath,name:e.folderPath.split(`/`).pop()??e.folderPath}]);return}console.warn(JSON.stringify({event:`file-tree-menu-action-delete-unsupported-kind`,kind:e.kind}))}),bn=[],t[153]=yn,t[154]=bn):(yn=t[153],bn=t[154]),(0,Q.useEffect)(yn,bn);let xn,Sn;t[155]===Ne?(xn=t[156],Sn=t[157]):(xn=()=>eV(e=>{if(e.kind===`doc`||e.kind===`folder-index`){let t=e.docName,n=UD(t,R.current.find(e=>hn(e)&&e.docName===t)?.docExt);Ne.startRenaming(n);return}if(e.kind===`folder`){Ne.startRenaming(e.folderPath);return}console.warn(JSON.stringify({event:`file-tree-menu-action-rename-unsupported-kind`,kind:e.kind}))}),Sn=[Ne],t[155]=Ne,t[156]=xn,t[157]=Sn),(0,Q.useEffect)(xn,Sn);let Cn;t[158]===Symbol.for(`react.memo_cache_sentinel`)?(Cn=function(){let e=ne.current;e&&gV(e),ne.current=null},t[158]=Cn):Cn=t[158];let wn=Cn,Tn;t[159]===f?Tn=t[160]:(Tn=function(e){let t=lH(e.nativeEvent);if(!t||t.endsWith(`/`)){wn();return}let n=WD(t),r=R.current.find(e=>GD(e)===t);if(r&&Hn(r)){wn();return}ne.current!==n&&(wn(),ne.current=n,hV(n,e=>f(e)))},t[159]=f,t[160]=Tn);let En=Tn,Dn;t[161]!==B||t[162]!==Ne||t[163]!==b?(Dn=function(e){if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=uH(e.nativeEvent);if(!t||t.getAttribute(`aria-selected`)!==`true`)return;let n=t.dataset.itemPath;if(!n)return;let r=t.dataset.itemType===`folder`?JD(n):n;if(Ne.getSelectedPaths().length!==1)return;if(t.dataset.itemType===`folder`){let e=qD(r);if(window.location.hash===or(e))return;queueMicrotask(()=>b(e));return}let i=WD(r);window.location.hash!==Tr(i)&&queueMicrotask(()=>B(r))},t[161]=B,t[162]=Ne,t[163]=b,t[164]=Dn):Dn=t[164];let On=Dn;if(w){let e;return t[165]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(fH,{}),t[165]=e):e=t[165],e}if(S.length===0){if(E){let e;return t[166]===E?e=t[167]:(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:E})}),t[166]=E,t[167]=e),e}let e;t[168]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(`span`,{className:`select-none text-sidebar-foreground/30 text-sm`,children:`No files yet.`}),t[168]=e):e=t[168];let n;return t[169]===Pt?n=t[170]:(n=(0,Z.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 py-8`,children:[e,(0,Z.jsx)(Y,{variant:`link`,size:`sm`,className:`font-mono uppercase`,onClick:()=>Pt(`file`,``),children:`Create your first file`})]}),t[169]=Pt,t[170]=n),n}let kn=O!==null,An=A?.targets[0]??null,jn;t[171]===E?jn=t[172]:(jn=E&&(0,Z.jsx)(`span`,{role:`alert`,className:`px-3 pb-1 text-destructive text-xs`,children:E}),t[171]=E,t[172]=jn);let Mn;t[173]===h?Mn=t[174]:(Mn=kV(h),t[173]=h,t[174]=Mn);let Nn;t[175]!==kn||t[176]!==U||t[177]!==Rt||t[178]!==It||t[179]!==He||t[180]!==be||t[181]!==Ce||t[182]!==Ne||t[183]!==xe||t[184]!==Se||t[185]!==Pt||t[186]!==I?(Nn=(e,t)=>(0,Z.jsx)(VV,{item:e,context:t,anyActionBusy:kn,workspace:I,handoff:be,model:Ne,okignoreBinding:xe,projectLocalBinding:Se,mergedConfig:Ce,onStartCreating:Pt,onStartCreatingFromTemplate:Mt,onDelete:e=>j({targets:e}),onExpandSubtree:It,onCollapseSubtree:Rt,folderTreePaths:He,isAsset:U.has(e.path),isAssetTreePath:et}),t[175]=kn,t[176]=U,t[177]=Rt,t[178]=It,t[179]=He,t[180]=be,t[181]=Ce,t[182]=Ne,t[183]=xe,t[184]=Se,t[185]=Pt,t[186]=I,t[187]=Nn):Nn=t[187];let Pn;t[188]!==On||t[189]!==En||t[190]!==Ne||t[191]!==jn||t[192]!==Mn||t[193]!==Nn?(Pn=(0,Z.jsx)(`div`,{ref:ce,className:`flex min-h-0 flex-1 flex-col`,children:(0,Z.jsx)(iB,{header:jn,model:Ne,style:Mn,onClickCapture:On,onMouseMove:En,onMouseLeave:wn,renderContextMenu:Nn})}),t[188]=On,t[189]=En,t[190]=Ne,t[191]=jn,t[192]=Mn,t[193]=Nn,t[194]=Pn):Pn=t[194];let Fn=!!A,In;t[195]===O?In=t[196]:(In=e=>{!e&&!O&&j(null)},t[195]=O,t[196]=In);let Ln;t[197]!==O||t[198]!==A||t[199]!==dn||t[200]!==An?(Ln=A&&An&&(0,Z.jsx)(io,{...(()=>{let e=FB(typeof window<`u`&&window.okDesktop!=null?`electron`:`web`,A.targets);return e?{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(UV)}):null}:{itemName:A.targets.length===1?`${An.name}${An.kind===`file`?An.docExt??`.md`:`/`}`:void 0,customTitle:A.targets.length>1?`Delete selected items`:void 0,customDescription:A.targets.length>1?`Are you sure you want to delete ${A.targets.length} selected items? Folders and all files inside them will be deleted. This action cannot be undone.`:An.kind===`folder`?`Are you sure you want to delete ${An.name}/ and all files inside? This action cannot be undone.`:void 0}})(),isSubmitting:O!==null,onDelete:()=>dn(A.targets)}),t[197]=O,t[198]=A,t[199]=dn,t[200]=An,t[201]=Ln):Ln=t[201];let Rn;t[202]!==Fn||t[203]!==In||t[204]!==Ln?(Rn=(0,Z.jsx)(jo,{open:Fn,onOpenChange:In,children:Ln}),t[202]=Fn,t[203]=In,t[204]=Ln,t[205]=Rn):Rn=t[205];let zn=!!M,Bn;t[206]===O?Bn=t[207]:(Bn=e=>{!e&&!O&&N(null)},t[206]=O,t[207]=Bn);let Vn;t[208]!==O||t[209]!==pn||t[210]!==gn||t[211]!==M?(Vn=M&&(0,Z.jsx)(HB,{failedTargets:M.failed,isSubmitting:O!==null,onDeletePermanently:pn,onRetry:gn,onCancel:()=>N(null)}),t[208]=O,t[209]=pn,t[210]=gn,t[211]=M,t[212]=Vn):Vn=t[212];let Un;t[213]!==zn||t[214]!==Bn||t[215]!==Vn?(Un=(0,Z.jsx)(jo,{open:zn,onOpenChange:Bn,children:Vn}),t[213]=zn,t[214]=Bn,t[215]=Vn,t[216]=Un):Un=t[216];let Wn=P!==null,Gn;t[217]===Symbol.for(`react.memo_cache_sentinel`)?(Gn=e=>{e||F(null)},t[217]=Gn):Gn=t[217];let Kn=P?.parentDir??``,qn;t[218]!==Wn||t[219]!==Kn?(qn=(0,Z.jsx)(Hp,{open:Wn,onOpenChange:Gn,kind:`file`,initialDir:Kn}),t[218]=Wn,t[219]=Kn,t[220]=qn):qn=t[220];let Jn;return t[221]!==Pn||t[222]!==Rn||t[223]!==Un||t[224]!==qn?(Jn=(0,Z.jsxs)(Z.Fragment,{children:[Pn,Rn,Un,qn]}),t[221]=Pn,t[222]=Rn,t[223]=Un,t[224]=qn,t[225]=Jn):Jn=t[225],Jn}function UV(e){return(0,Z.jsx)(`li`,{"data-testid":`delete-target-row`,children:IB(e)},`${e.kind}:${e.path}`)}function WV(e){return`${e.kind}:${e.path}`}function GV(e){return`${e.kind}:${e.path}`}function KV(e){return e.path}function qV(e){return e.kind===`folder`}function JV(e){return e.path}function YV(e){return e.kind===`file`}function XV(e){return lt(e)}function ZV(e){return Je(e)}function QV(e){return e.endsWith(`/`)?e.slice(0,-1):e}function $V(e){return!!e}function eH(e){console.warn(`[FileTree] /api/workspace fetch failed:`,e)}function tH(e){console.warn(`[FileTree] unmount cleanup failed:`,e)}function nH(e){X.error(e)}function rH(){}function iH(e){return X.error(e)}function aH(){}function oH(){}async function sH(){}function cH(e){return GD(e)}function lH(e){return uH(e)?.dataset.itemPath??null}function uH(e){for(let t of e.composedPath())if(t instanceof HTMLElement&&t.dataset.itemPath)return t;return null}var dH=[`w-3/4`,`w-2/3`,`w-4/5`,`w-1/2`,`w-3/5`,`w-2/3`];function fH(){let e=(0,$.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Z.jsx)(`div`,{className:`flex flex-1 flex-col gap-1 px-2 py-2`,role:`status`,"aria-busy":`true`,"aria-label":`Loading files`,children:dH.map(pH)}),e[0]=t):t=e[0],t}function pH(e,t){return(0,Z.jsxs)(`div`,{className:`flex h-6 items-center gap-2`,children:[(0,Z.jsx)(Ma,{className:`h-3 w-3 shrink-0 rounded-sm`}),(0,Z.jsx)(Ma,{className:`h-3 ${e}`})]},t)}function mH(e){return e?`No workspace`:null}function hH(e){let t=(0,$.c)(41),{input:n,installStates:r,dispatch:i,webFallbackVisible:a}=e,o=a===void 0?!0:a,s=n===null,c;t[0]===s?c=t[1]:(c=mH(s),t[0]=s,t[1]=c);let l=c,u,d,f,p,m,h,g;if(t[2]!==i||t[3]!==l||t[4]!==n||t[5]!==s||t[6]!==r||t[7]!==o){g=Symbol.for(`react.early_return_sentinel`);bb0:{let e;t[15]===r?e=t[16]:(e=e=>r[e.id]?.installed===!0,t[15]=r,t[16]=e);let a=xm.filter(e);f=r[`claude-code`]?.installed===!0;let c;t[17]===n?c=t[18]:(c=n!==null&&n.docContext!==null?$r(n.docContext.relativePath):``,t[17]=n,t[18]=c);let _=c,v;t[19]!==n||t[20]!==_?(v=()=>{n!==null&&qx(_)},t[19]=n,t[20]=_,t[21]=v):v=t[21],p=v;let y=o&&!f;if(a.length===0&&!y){g=null;break bb0}d=xO,t[22]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Z.jsxs)(wO,{children:[(0,Z.jsx)(Fi,{"aria-hidden":`true`}),`Open with AI`]}),t[22]=h):h=t[22],u=TO;let b;t[23]!==i||t[24]!==l||t[25]!==n||t[26]!==s?(b=e=>{let t=!s,r=l?`Open with AI ${e.displayName}, ${l}`:`Open with AI ${e.displayName}`;return(0,Z.jsxs)(CO,{disabled:!t,onSelect:()=>{n&&i(e.id,n)},"data-testid":`empty-space-open-in-${e.id}`,"aria-label":r,children:[(0,Z.jsx)(Vx,{id:e.id,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:e.displayName}),l?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:l}):null]},e.id)},t[23]=i,t[24]=l,t[25]=n,t[26]=s,t[27]=b):b=t[27],m=a.map(b)}t[2]=i,t[3]=l,t[4]=n,t[5]=s,t[6]=r,t[7]=o,t[8]=u,t[9]=d,t[10]=f,t[11]=p,t[12]=m,t[13]=h,t[14]=g}else u=t[8],d=t[9],f=t[10],p=t[11],m=t[12],h=t[13],g=t[14];if(g!==Symbol.for(`react.early_return_sentinel`))return g;let _;t[28]!==f||t[29]!==p||t[30]!==s||t[31]!==o?(_=o&&!f?(0,Z.jsxs)(CO,{onSelect:p,disabled:s,"data-testid":`empty-space-open-in-claude-web-fallback`,"aria-label":`Open in claude.ai, opens in browser with prompt pre-filled`,children:[(0,Z.jsx)(he,{className:`size-4`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:`Open in claude.ai →`}),(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:`opens in browser`})]}):null,t[28]=f,t[29]=p,t[30]=s,t[31]=o,t[32]=_):_=t[32];let v;t[33]!==u||t[34]!==m||t[35]!==_?(v=(0,Z.jsxs)(u,{children:[m,_]}),t[33]=u,t[34]=m,t[35]=_,t[36]=v):v=t[36];let y;return t[37]!==d||t[38]!==h||t[39]!==v?(y=(0,Z.jsxs)(d,{children:[h,v]}),t[37]=d,t[38]=h,t[39]=v,t[40]=y):y=t[40],y}var gH=(e,t,n)=>il(e,t,n,`ProjectSwitcher`);function _H(e){let t=(0,$.c)(59),{bridge:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=[],t[0]=r):r=t[0];let[i,a]=(0,Q.useState)(r),[o,s]=(0,Q.useState)(!1),c;t[1]!==n.project||t[2]!==o?(c=()=>{if(!o)return;let e=!1;return gH(async()=>{let t=await n.project.listRecent();e||a(t)},`Failed to load recent projects.`),()=>{e=!0}},t[1]=n.project,t[2]=o,t[3]=c):c=t[3];let l;t[4]!==n||t[5]!==o?(l=[o,n],t[4]=n,t[5]=o,t[6]=l):l=t[6],(0,Q.useEffect)(c,l);let u;t[7]===n.project?u=t[8]:(u=e=>{s(!1),gH(()=>n.project.open({path:e,target:`new-window`,entryPoint:`recents`}),`Failed to open project.`)},t[7]=n.project,t[8]=u);let d=u,f;t[9]!==n.dialog||t[10]!==n.project?(f=()=>{s(!1),gH(async()=>{let e=await n.dialog.openFolder();e&&await n.project.open({path:e,target:`new-window`,entryPoint:`pick-existing`})},`Failed to open folder.`)},t[9]=n.dialog,t[10]=n.project,t[11]=f):f=t[11];let p=f,m;t[12]===n.navigator?m=t[13]:(m=()=>{s(!1),gH(()=>n.navigator.open(),`Failed to open Project Navigator.`)},t[12]=n.navigator,t[13]=m);let h=m,g=n.config.projectPath,_,v,y,b,x,S,C,w,T,E,D;if(t[14]!==n.config.projectName||t[15]!==g||t[16]!==o||t[17]!==d||t[18]!==i){let e;t[30]===g?e=t[31]:(e=e=>e.path!==g,t[30]=g,t[31]=e);let r=i.filter(e);v=va,S=o,C=s;let a;t[32]===n.config.projectName?a=t[33]:(a=(0,Z.jsx)(`span`,{className:`truncate`,children:n.config.projectName}),t[32]=n.config.projectName,t[33]=a);let c;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Z.jsx)(qs,{"aria-hidden":`true`,className:`opacity-60`}),t[34]=c):c=t[34],t[35]===a?w=t[36]:(w=(0,Z.jsx)(ba,{asChild:!0,children:(0,Z.jsxs)(yD,{className:`justify-between text-sidebar-foreground/70`,"data-testid":`project-switcher-trigger`,title:`Open project menu`,children:[a,c]})}),t[35]=a,t[36]=w),_=_a,T=`start`,E=`top`,D=`min-w-[260px]`,y=`project-switcher-menu`,t[37]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Z.jsx)(Qi,{className:`font-mono font-normal tracking-wide uppercase text-muted-foreground text-xs`,children:`Recent projects`}),t[37]=b):b=t[37],x=r.length===0?(0,Z.jsx)(Qi,{className:`font-normal text-muted-foreground text-xs`,children:`No other recent projects.`}):r.slice(0,10).map(e=>(0,Z.jsxs)(ya,{disabled:e.missing,onSelect:()=>d(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?` (missing)`:``]})]},e.path)),t[14]=n.config.projectName,t[15]=g,t[16]=o,t[17]=d,t[18]=i,t[19]=_,t[20]=v,t[21]=y,t[22]=b,t[23]=x,t[24]=S,t[25]=C,t[26]=w,t[27]=T,t[28]=E,t[29]=D}else _=t[19],v=t[20],y=t[21],b=t[22],x=t[23],S=t[24],C=t[25],w=t[26],T=t[27],E=t[28],D=t[29];let O;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,Z.jsx)(na,{}),t[38]=O):O=t[38];let k;t[39]===p?k=t[40]:(k=(0,Z.jsx)(ya,{onSelect:p,"data-testid":`project-switcher-open-folder`,children:`Open folder`}),t[39]=p,t[40]=k);let A;t[41]===h?A=t[42]:(A=(0,Z.jsx)(ya,{onSelect:h,"data-testid":`project-switcher-switch-project`,children:`Switch Project`}),t[41]=h,t[42]=A);let j;t[43]!==_||t[44]!==y||t[45]!==b||t[46]!==x||t[47]!==k||t[48]!==A||t[49]!==T||t[50]!==E||t[51]!==D?(j=(0,Z.jsxs)(_,{align:T,side:E,className:D,"data-testid":y,children:[b,x,O,k,A]}),t[43]=_,t[44]=y,t[45]=b,t[46]=x,t[47]=k,t[48]=A,t[49]=T,t[50]=E,t[51]=D,t[52]=j):j=t[52];let M;return t[53]!==v||t[54]!==S||t[55]!==C||t[56]!==w||t[57]!==j?(M=(0,Z.jsxs)(v,{open:S,onOpenChange:C,children:[w,j]}),t[53]=v,t[54]=S,t[55]=C,t[56]=w,t[57]=j,t[58]=M):M=t[58],M}function vH(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})),Hr(`sidebarSearchPill`)}function yH(e){let t=(0,$.c)(8),{onClick:n,className:r}=e,i;t[0]===r?i=t[1]:(i=mi(`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,o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(Me,{"aria-hidden":`true`}),o=(0,Z.jsx)(`span`,{className:`flex-1 text-left text-sm`,children:`Search`}),t[2]=a,t[3]=o):(a=t[2],o=t[3]);let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,Z.jsx)(OS,{className:`text-foreground/70`,children:Dn()?`⌘ K`:`Ctrl K`}),t[4]=s):s=t[4];let c;return t[5]!==n||t[6]!==i?(c=(0,Z.jsxs)(Y,{variant:`outline`,onClick:n,"data-telemetry-event":`ok.sidebar.search_pill.click`,className:i,children:[a,o,s]}),t[5]=n,t[6]=i,t[7]=c):c=t[7],c}function bH(e){let t=(0,$.c)(33),{notice:n,onDismiss:r}=e,i=n.variant===`error`?`border-destructive/60`:`border-sidebar-border`,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(_o,{"aria-hidden":`true`,className:`size-3`}),t[0]=a):a=t[0];let o;t[1]===r?o=t[2]:(o=(0,Z.jsx)(Y,{variant:`ghost`,size:`icon`,className:`size-5 shrink-0 text-muted-foreground hover:text-sidebar-foreground`,"aria-label":`Dismiss notice`,onClick:r,children:a}),t[1]=r,t[2]=o);let s=o;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 ${i}`,a;t[3]===n.body?a=t[4]:(a=(0,Z.jsx)(`span`,{className:`flex-1 leading-snug`,children:n.body}),t[3]=n.body,t[4]=a);let o;t[5]!==s||t[6]!==a?(o=(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[a,s]}),t[5]=s,t[6]=a,t[7]=o):o=t[7];let c;t[8]===n.action?c=t[9]:(c=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[8]=n.action,t[9]=c);let l;t[10]===n.secondaryAction?l=t[11]:(l=()=>{n.secondaryAction?.onClick()},t[10]=n.secondaryAction,t[11]=l);let u;t[12]!==n.secondaryAction.label||t[13]!==l?(u=(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:l,children:n.secondaryAction.label}),t[12]=n.secondaryAction.label,t[13]=l,t[14]=u):u=t[14];let d;t[15]!==c||t[16]!==u?(d=(0,Z.jsxs)(`div`,{className:`flex gap-3 pl-1`,children:[c,u]}),t[15]=c,t[16]=u,t[17]=d):d=t[17];let f;return t[18]!==d||t[19]!==e||t[20]!==r||t[21]!==o?(f=(0,Z.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":e,className:r,children:[o,d]}),t[18]=d,t[19]=e,t[20]=r,t[21]=o,t[22]=f):f=t[22],f}let c=`update-notice-${n.id}`,l=`flex items-center gap-2 rounded-md border bg-sidebar-accent/30 px-2 py-1.5 text-xs text-muted-foreground ${i}`,u;t[23]===n.body?u=t[24]:(u=(0,Z.jsx)(`span`,{className:`flex-1 leading-snug`,children:n.body}),t[23]=n.body,t[24]=u);let d;t[25]===n.action?d=t[26]:(d=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[25]=n.action,t[26]=d);let f;return t[27]!==s||t[28]!==c||t[29]!==l||t[30]!==u||t[31]!==d?(f=(0,Z.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":c,className:l,children:[u,d,s]}),t[27]=s,t[28]=c,t[29]=l,t[30]=u,t[31]=d,t[32]=f):f=t[32],f}function xH(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 SH(){let e=(0,$.c)(7),t=(0,Q.useSyncExternalStore)(qf,Kf,Kf),n;e[0]===t?n=e[1]:(n=xH(t),e[0]=t,e[1]=n);let r=n;if(!r)return null;let i;e[2]===r.id?i=e[3]:(i=()=>{Gf(r.id)},e[2]=r.id,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)(bH,{notice:r,onDismiss:i})}),e[4]=r,e[5]=i,e[6]=a):a=e[6],a}function CH(e,t,n){return e?.kind===`doc`&&t||e?.kind===`folder-index`&&t?nh(n.contentDir,rh(t),n.pathSeparator):e?.kind===`folder`?nh(n.contentDir,e.folderPath,n.pathSeparator):n.contentDir}function wH(e,t,n){if((e?.kind===`doc`||e?.kind===`folder-index`)&&t){let e=t.lastIndexOf(`/`);return e<0?n.contentDir:nh(n.contentDir,t.slice(0,e),n.pathSeparator)}return e?.kind===`folder`?nh(n.contentDir,e.folderPath,n.pathSeparator):n.contentDir}function TH(e,t){return(e?.kind===`doc`||e?.kind===`folder-index`)&&t?rh(t):e?.kind===`folder`?e.folderPath:``}function EH(e,t,n){return e===null?ah({workspace:n}):e.kind===`folder`?n?oh({folderAbsPath:nh(n.contentDir,e.folderPath,n.pathSeparator),folderRelativePath:e.folderPath,workspace:n}):null:e.kind===`doc`||e.kind===`folder-index`?ih({docName:t,workspace:n}):null}var DH={folderCount:0,expandedCount:0},OH=`button, [role="button"], [role="menuitem"], input, textarea, select, a[href]`;function kH(e){return typeof Element>`u`||!(e instanceof Element)?!1:e.closest(OH)!==null}function AH(e){let t=(0,$.c)(2),{onOpenSearch:n}=e,r;return t[0]===n?r=t[1]:(r=(0,Z.jsx)(Ve,{name:`file-sidebar`,children:(0,Z.jsx)(MH,{onOpenSearch:n})}),t[0]=n,t[1]=r),r}var jH=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)(kr,{asChild:!0,children:(0,Z.jsx)(Y,{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)(vn,{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 MH(e){let t=(0,$.c)(164),{onOpenSearch:n}=e,[r,i]=(0,Q.useState)(null),{activeDocName:a,activeTarget:o}=ot(),s;t[0]!==a||t[1]!==o?(s=o?.kind===`folder`||o?.kind===`folder-index`?o.folderPath:sr(a),t[0]=a,t[1]=o,t[2]=s):s=t[2];let c=s,l=typeof window<`u`&&window.okDesktop!=null,{state:u}=aD(),d=u===`expanded`,f=l&&u===`collapsed`,[p,m]=(0,Q.useState)(DH),h,g;t[3]===r?(h=t[4],g=t[5]):(h=()=>{if(r!==null)return m(r.getFolderState()),r.subscribe(()=>{m(r.getFolderState())})},g=[r],t[3]=r,t[4]=h,t[5]=g),(0,Q.useEffect)(h,g);let _,v;t[6]===r?(_=t[7],v=t[8]):(_=()=>{if(r!==null)return MS(()=>{r.startCreating(`file`,``)})},v=[r],t[6]=r,t[7]=_,t[8]=v),(0,Q.useEffect)(_,v);let y=p.folderCount>0,b=y&&p.expandedCount===p.folderCount,x=p.expandedCount===0,S=Aa(``),C=S.state.status===`ready`?(S.state.data.folder.templates_available?.length??0)>0:!0,w=typeof window<`u`?window.okDesktop:void 0,T=km(),D=Oh().states,{dispatch:k}=_h(),A;t[9]===T?A=t[10]:(A=ah({workspace:T}),t[9]=T,t[10]=A);let j=A,{projectLocalBinding:M,merged:N}=Ga(),P=N?.appearance?.sidebar?.showHiddenFiles??!1,F=N?.appearance?.sidebar?.showAllFiles??!1,I=y&&!b,L=y&&!x,z=I||L,B=IH,V;t[11]!==r||t[12]!==T?(V=()=>{T&&r?.startCreating(`file`,``)},t[11]=r,t[12]=T,t[13]=V):V=t[13];let H=V,U;t[14]!==r||t[15]!==T?(U=()=>{T&&r?.startCreatingFromTemplate(``)},t[14]=r,t[15]=T,t[16]=U):U=t[16];let W=U,G;t[17]!==r||t[18]!==T?(G=()=>{T&&r?.startCreating(`folder`,``)},t[17]=r,t[18]=T,t[19]=G):G=t[19];let K=G,q;t[20]===T?q=t[21]:(q=()=>{!T||!w||w.shell.showItemInFolder(T.contentDir)},t[20]=T,t[21]=q);let ee=q,te;t[22]===T?te=t[23]:(te=()=>{!T||!w||JB(w,T.contentDir)},t[22]=T,t[23]=te);let ne=te,re;t[24]===T?re=t[25]:(re=async()=>{if(T)try{await navigator.clipboard.writeText(T.contentDir),X.success(`Copied full path`,{description:T.contentDir})}catch(e){console.warn(`[FileSidebar] clipboard write failed:`,e),X.error(`Could not copy full path`)}},t[24]=T,t[25]=re);let ie=re,ae;t[26]===M?ae=t[27]:(ae=e=>{if(M===null)return;let t=M.patch({appearance:{sidebar:{showHiddenFiles:e}}});t.ok||(console.warn(`[FileSidebar] showHiddenFiles toggle rejected:`,Nn(t.error)),X.error(`Could not update sidebar settings`,{description:Nn(t.error)}))},t[26]=M,t[27]=ae);let oe=ae,se;t[28]===M?se=t[29]:(se=e=>{if(M===null)return;let t=M.patch({appearance:{sidebar:{showAllFiles:e}}});t.ok||(console.warn(`[FileSidebar] showAllFiles toggle rejected:`,Nn(t.error)),X.error(`Could not update sidebar settings`,{description:Nn(t.error)}))},t[28]=M,t[29]=se);let ce=se,le;t[30]===r?le=t[31]:(le=()=>{r?.expandAll()},t[30]=r,t[31]=le);let J=le,ue;t[32]===r?ue=t[33]:(ue=()=>{r?.collapseAll()},t[32]=r,t[33]=ue);let de=ue,fe,pe;t[34]!==F||t[35]!==L||t[36]!==I||t[37]!==P?(fe=()=>{w&&w.editor.notifyViewMenuStateChanged({showHiddenFiles:P,showAllFiles:F,canExpandAll:I,canCollapseAll:L})},pe=[w,P,F,I,L],t[34]=F,t[35]=L,t[36]=I,t[37]=P,t[38]=fe,t[39]=pe):(fe=t[38],pe=t[39]),(0,Q.useEffect)(fe,pe);let me,he;t[40]!==a||t[41]!==o||t[42]!==k||t[43]!==D||t[44]!==c||t[45]!==M||t[46]!==F||t[47]!==P||t[48]!==r||t[49]!==T?(me=()=>{if(w)return w.onMenuAction(e=>{switch(e){case`new-doc`:if(!T||!r)return;r.startCreating(`file`,c);return;case`new-folder`:if(!T||!r)return;r.startCreating(`folder`,c);return;case`new-from-template`:if(!T||!r)return;r.startCreatingFromTemplate(c);return;case`rename`:if(!o)return;$B(o);return;case`move-to-trash`:if(!o)return;ZB(o);return;case`reveal-in-finder`:{if(!w||!T)return;let e=CH(o,a,T);w.shell.showItemInFolder(e);return}case`open-in-terminal`:if(!w||!T)return;JB(w,wH(o,a,T));return;case`send-to-ai`:{let e=xm.filter(e=>D[e.id]?.installed===!0);if(e.length===0){X.error(`No AI agents installed`);return}let t=EH(o,a,T);if(!t)return;let[n]=e;if(!n)return;k(n.id,t);return}case`copy-full-path`:{if(!T)return;let e=CH(o,a,T);navigator.clipboard.writeText(e).then(()=>X.success(`Copied full path`,{description:e})).catch(FH);return}case`copy-relative-path`:{let e=TH(o,a);if(e===``){X.error(`No file or folder selected`);return}navigator.clipboard.writeText(e).then(()=>X.success(`Copied relative path`,{description:e})).catch(PH);return}case`toggle-show-hidden-files`:{if(M===null)return;let e=M.patch({appearance:{sidebar:{showHiddenFiles:!P}}});e.ok||(console.warn(`[FileSidebar] toggle-show-hidden-files rejected:`,Nn(e.error)),X.error(`Could not update sidebar settings`,{description:Nn(e.error)}));return}case`toggle-show-all-files`:{if(M===null)return;let e=M.patch({appearance:{sidebar:{showAllFiles:!F}}});e.ok||(console.warn(`[FileSidebar] toggle-show-all-files rejected:`,Nn(e.error)),X.error(`Could not update sidebar settings`,{description:Nn(e.error)}));return}case`expand-all-tree`:r?.expandAll();return;case`collapse-all-tree`:r?.collapseAll();return;case`delete`:case`toggle-sidebar`:case`toggle-source`:case`save-version`:case`version-history`:case`focus-search`:case`focus-command-palette`:return}})},he=[w,r,T,o,a,c,M,P,F,D,k],t[40]=a,t[41]=o,t[42]=k,t[43]=D,t[44]=c,t[45]=M,t[46]=F,t[47]=P,t[48]=r,t[49]=T,t[50]=me,t[51]=he):(me=t[50],he=t[51]),(0,Q.useEffect)(me,he);let ge=f&&`opacity-0`,_e;t[52]===ge?_e=t[53]:(_e=mi(`flex-row h-12 items-center py-0 px-3`,l?`justify-end`:`justify-between`,l&&`motion-safe:transition-opacity motion-safe:duration-100 motion-safe:ease-out`,ge,l&&`[-webkit-app-region:drag]`),t[52]=ge,t[53]=_e);let ve;t[54]===d?ve=t[55]:(ve=d&&!l?(0,Z.jsx)(`span`,{className:`shrink-0 font-mono text-sm uppercase tracking-wider text-sidebar-foreground/50`,children:`Files`}):null,t[54]=d,t[55]=ve);let ye;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(ye=mi(`flex items-center gap-1`,l&&`[&>*]:[-webkit-app-region:no-drag]`),t[56]=ye):ye=t[56];let be;t[57]!==b||t[58]!==y||t[59]!==x||t[60]!==r?(be=y?(0,Z.jsxs)(va,{children:[(0,Z.jsx)(ba,{asChild:!0,children:(0,Z.jsx)(jH,{icon:yc,label:`Tree View Options`})}),(0,Z.jsxs)(_a,{align:`end`,children:[b?null:(0,Z.jsxs)(ya,{onSelect:()=>r?.expandAll(),children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),`Expand All`]}),x?null:(0,Z.jsxs)(ya,{onSelect:()=>r?.collapseAll(),children:[(0,Z.jsx)(cc,{"aria-hidden":`true`}),`Collapse All`]})]})]}):null,t[57]=b,t[58]=y,t[59]=x,t[60]=r,t[61]=be):be=t[61];let xe;t[62]!==c||t[63]!==r?(xe=(0,Z.jsx)(jH,{icon:Wc,label:`New File`,onClick:()=>r?.startCreating(`file`,c)}),t[62]=c,t[63]=r,t[64]=xe):xe=t[64];let Se;t[65]!==C||t[66]!==c||t[67]!==r?(Se=C?(0,Z.jsx)(jH,{icon:oc,label:`New from template`,onClick:()=>r?.startCreatingFromTemplate(c)}):null,t[65]=C,t[66]=c,t[67]=r,t[68]=Se):Se=t[68];let Ce;t[69]!==c||t[70]!==r?(Ce=(0,Z.jsx)(jH,{icon:uc,label:`New Folder`,onClick:()=>r?.startCreating(`folder`,c)}),t[69]=c,t[70]=r,t[71]=Ce):Ce=t[71];let we;t[72]!==be||t[73]!==xe||t[74]!==Se||t[75]!==Ce?(we=(0,Z.jsxs)(`div`,{className:ye,children:[be,xe,Se,Ce]}),t[72]=be,t[73]=xe,t[74]=Se,t[75]=Ce,t[76]=we):we=t[76];let Te;t[77]!==_e||t[78]!==ve||t[79]!==we?(Te=(0,Z.jsxs)(pD,{className:_e,children:[ve,we]}),t[77]=_e,t[78]=ve,t[79]=we,t[80]=Te):Te=t[80];let Ee=f&&`opacity-0`,De;t[81]===Ee?De=t[82]:(De=mi(`px-2 pb-2`,l&&`[-webkit-app-region:no-drag]`,l&&`motion-safe:transition-opacity motion-safe:duration-100 motion-safe:ease-out`,Ee),t[81]=Ee,t[82]=De);let Oe;t[83]===u?Oe=t[84]:(Oe=[u],t[83]=u,t[84]=Oe);let ke;t[85]===n?ke=t[86]:(ke=(0,Z.jsx)(yH,{onClick:n}),t[85]=n,t[86]=ke);let Ae;t[87]!==Oe||t[88]!==ke?(Ae=(0,Z.jsx)(O,{fallbackRender:NH,onError:vH,resetKeys:Oe,children:ke}),t[87]=Oe,t[88]=ke,t[89]=Ae):Ae=t[89];let je;t[90]!==De||t[91]!==Ae?(je=(0,Z.jsx)(`div`,{className:De,children:Ae}),t[90]=De,t[91]=Ae,t[92]=je):je=t[92];let Me;t[93]===Symbol.for(`react.memo_cache_sentinel`)?(Me=(0,Z.jsx)(hD,{children:(0,Z.jsx)(HV,{ref:i})}),t[93]=Me):Me=t[93];let Ne,Pe;t[94]===Symbol.for(`react.memo_cache_sentinel`)?(Ne=(0,Z.jsxs)(mD,{className:`px-0`,children:[(0,Z.jsx)(SH,{}),typeof window<`u`&&window.okDesktop?(0,Z.jsx)(gD,{children:(0,Z.jsx)(_D,{children:(0,Z.jsx)(_H,{bridge:window.okDesktop})})}):null]}),Pe=(0,Z.jsx)(dD,{enableToggle:!1}),t[94]=Ne,t[95]=Pe):(Ne=t[94],Pe=t[95]);let Fe;t[96]!==Te||t[97]!==je?(Fe=(0,Z.jsx)(bO,{asChild:!0,children:(0,Z.jsxs)(`div`,{className:`contents`,onContextMenu:B,children:[Te,je,Me,Ne,Pe]})}),t[96]=Te,t[97]=je,t[98]=Fe):Fe=t[98];let Ie=!T,Le;t[99]===Symbol.for(`react.memo_cache_sentinel`)?(Le=(0,Z.jsx)(Wc,{"aria-hidden":`true`}),t[99]=Le):Le=t[99];let Re;t[100]!==H||t[101]!==Ie?(Re=(0,Z.jsxs)(CO,{disabled:Ie,onSelect:H,"data-testid":`empty-space-menu-new-file`,children:[Le,`New File`]}),t[100]=H,t[101]=Ie,t[102]=Re):Re=t[102];let ze=!T||!C,Be;t[103]===Symbol.for(`react.memo_cache_sentinel`)?(Be=(0,Z.jsx)(oc,{"aria-hidden":`true`}),t[103]=Be):Be=t[103];let Ve;t[104]!==W||t[105]!==ze?(Ve=(0,Z.jsxs)(CO,{disabled:ze,onSelect:W,"data-testid":`empty-space-menu-new-from-template`,children:[Be,`New from template`]}),t[104]=W,t[105]=ze,t[106]=Ve):Ve=t[106];let He=!T,Ue;t[107]===Symbol.for(`react.memo_cache_sentinel`)?(Ue=(0,Z.jsx)(uc,{"aria-hidden":`true`}),t[107]=Ue):Ue=t[107];let We;t[108]!==K||t[109]!==He?(We=(0,Z.jsxs)(CO,{disabled:He,onSelect:K,"data-testid":`empty-space-menu-new-folder`,children:[Ue,`New Folder`]}),t[108]=K,t[109]=He,t[110]=We):We=t[110];let Ge;t[111]===Symbol.for(`react.memo_cache_sentinel`)?(Ge=(0,Z.jsx)(DO,{}),t[111]=Ge):Ge=t[111];let Ke;t[112]!==ee||t[113]!==T?(Ke=w?(0,Z.jsxs)(CO,{disabled:!T,onSelect:ee,"data-testid":`empty-space-menu-reveal-in-finder`,"aria-label":T?`Reveal in Finder`:`Reveal in Finder, No workspace`,children:[(0,Z.jsx)(R,{"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:`Reveal in Finder`}),T?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:`No workspace`})]}):null,t[112]=ee,t[113]=T,t[114]=Ke):Ke=t[114];let qe;t[115]!==k||t[116]!==j||t[117]!==D?(qe=(0,Z.jsx)(hH,{input:j,installStates:D,dispatch:k,webFallbackVisible:!1}),t[115]=k,t[116]=j,t[117]=D,t[118]=qe):qe=t[118];let Je;t[119]!==ne||t[120]!==T?(Je=w?(0,Z.jsxs)(CO,{disabled:!T,onSelect:ne,"data-testid":`empty-space-menu-open-in-terminal`,"aria-label":T?`Open in Terminal`:`Open in Terminal, No workspace`,children:[(0,Z.jsx)(Yc,{"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:`Open in Terminal`}),T?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:`No workspace`})]}):null,t[119]=ne,t[120]=T,t[121]=Je):Je=t[121];let Ye=!T,Xe=T?`Copy full path`:`Copy full path, No workspace`,Ze,Qe;t[122]===Symbol.for(`react.memo_cache_sentinel`)?(Ze=(0,Z.jsx)(E,{"aria-hidden":`true`}),Qe=(0,Z.jsx)(`span`,{className:`flex-1`,children:`Copy full path`}),t[122]=Ze,t[123]=Qe):(Ze=t[122],Qe=t[123]);let $e;t[124]===T?$e=t[125]:($e=T?null:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`ml-2 text-muted-foreground text-xs`,children:`No workspace`}),t[124]=T,t[125]=$e);let et;t[126]!==ie||t[127]!==Ye||t[128]!==Xe||t[129]!==$e?(et=(0,Z.jsxs)(CO,{disabled:Ye,onSelect:ie,"data-testid":`empty-space-menu-copy-full-path`,"aria-label":Xe,children:[Ze,Qe,$e]}),t[126]=ie,t[127]=Ye,t[128]=Xe,t[129]=$e,t[130]=et):et=t[130];let tt;t[131]===Symbol.for(`react.memo_cache_sentinel`)?(tt=(0,Z.jsx)(DO,{}),t[131]=tt):tt=t[131];let nt=M===null,rt;t[132]!==oe||t[133]!==P||t[134]!==nt?(rt=(0,Z.jsx)(EO,{checked:P,onCheckedChange:oe,disabled:nt,"data-testid":`empty-space-menu-show-hidden-files`,children:`Show Hidden Files`}),t[132]=oe,t[133]=P,t[134]=nt,t[135]=rt):rt=t[135];let it=M===null,at;t[136]!==ce||t[137]!==F||t[138]!==it?(at=(0,Z.jsx)(EO,{checked:F,onCheckedChange:ce,disabled:it,"data-testid":`empty-space-menu-show-all-files`,children:`Show all files`}),t[136]=ce,t[137]=F,t[138]=it,t[139]=at):at=t[139];let st;t[140]===z?st=t[141]:(st=z?(0,Z.jsx)(DO,{}):null,t[140]=z,t[141]=st);let ct;t[142]!==J||t[143]!==I?(ct=I?(0,Z.jsxs)(CO,{onSelect:J,"data-testid":`empty-space-menu-expand-all`,children:[(0,Z.jsx)(Qc,{"aria-hidden":`true`}),`Expand all`]}):null,t[142]=J,t[143]=I,t[144]=ct):ct=t[144];let lt;t[145]!==de||t[146]!==L?(lt=L?(0,Z.jsxs)(CO,{onSelect:de,"data-testid":`empty-space-menu-collapse-all`,children:[(0,Z.jsx)(cc,{"aria-hidden":`true`}),`Collapse all`]}):null,t[145]=de,t[146]=L,t[147]=lt):lt=t[147];let ut;t[148]!==Re||t[149]!==Ve||t[150]!==We||t[151]!==Ke||t[152]!==qe||t[153]!==Je||t[154]!==et||t[155]!==rt||t[156]!==at||t[157]!==st||t[158]!==ct||t[159]!==lt?(ut=(0,Z.jsxs)(SO,{children:[Re,Ve,We,Ge,Ke,qe,Je,et,tt,rt,at,st,ct,lt]}),t[148]=Re,t[149]=Ve,t[150]=We,t[151]=Ke,t[152]=qe,t[153]=Je,t[154]=et,t[155]=rt,t[156]=at,t[157]=st,t[158]=ct,t[159]=lt,t[160]=ut):ut=t[160];let dt;return t[161]!==Fe||t[162]!==ut?(dt=(0,Z.jsx)(lD,{variant:`inset`,children:(0,Z.jsxs)(yO,{children:[Fe,ut]})}),t[161]=Fe,t[162]=ut,t[163]=dt):dt=t[163],dt}function NH(){return null}function PH(e){console.warn(`[FileSidebar] clipboard write failed:`,e),X.error(`Could not copy relative path`)}function FH(e){console.warn(`[FileSidebar] clipboard write failed:`,e),X.error(`Could not copy full path`)}function IH(e){kH(e.target)&&(e.preventDefault(),e.stopPropagation())}function LH(){let e=(0,$.c)(17),t=ln(),{collabUrl:n,setSystemProvider:r,updateServerInstanceId:i,onBranchSwitched:a,observeBranch:o,observeDiskAck:s,refreshServerInfo:c}=ot(),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 Se,i=new _t({url:n,name:$n,document:e,onStateless:e=>{let{payload:t}=e;_(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:UH,onConfigValidationRejected:HH,onConfigIgnoreNestedError:VH,onUnknown:BH})},onClose:zH,onDisconnect:RH}),a=br(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=q(()=>{u.current.refreshServerInfo()});i.on(`synced`,()=>{Fr([`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 RH(){console.warn(`[CC1] __system__ disconnected - derived views may be stale`)}function zH(e){let{event:t}=e;console.warn(`[CC1] __system__ connection closed:`,t.code,t.reason)}function BH(e){console.warn(`[CC1] Unparseable stateless payload, skipping:`,e.slice(0,100))}function VH(e){Za(e)}function HH(e){eo(e)}function UH(e){Fr([e.ch])}var WH=`#install-claude-desktop`;function GH(e){return e===`#settings`||e===WH}function KH(e,t,n){return[e,t,n].map(e=>[...e].sort().join(`\0`)).join(``)}function qH(){let e=(0,$.c)(20),{clearTarget:t,syncOpenTabsWithKnownTargets:n,tabSessionLoaded:r}=ot(),{openTargetTransition:i}=gt(),{assetPaths:a,folderPaths:o,loading:s,pages:c}=qr(),l=(0,Q.useRef)(null),u;e[0]!==a||e[1]!==o||e[2]!==c?(u=KH(c,o,a),e[0]=a,e[1]=o,e[2]=c,e[3]=u):u=e[3];let d=u,f,p;e[4]!==a||e[5]!==o||e[6]!==s||e[7]!==c||e[8]!==n||e[9]!==r||e[10]!==d?(f=()=>{s||!r||l.current===d||(l.current=d,n({pages:c,folderPaths:o,assetPaths:a}))},p=[a,o,s,c,n,r,d],e[4]=a,e[5]=o,e[6]=s,e[7]=c,e[8]=n,e[9]=r,e[10]=d,e[11]=f,e[12]=p):(f=e[11],p=e[12]),(0,Q.useEffect)(f,p);let m,h;return e[13]!==t||e[14]!==o||e[15]!==s||e[16]!==i||e[17]!==c?(m=()=>{e();function e(){if(GH(window.location.hash))return;let e=Jr(window.location.hash);if(e){let t=Er(e.split(`.`).pop()??``);dt(`ok/nav/hash-change`,{docName:null,kind:`asset`}),i({kind:`asset`,target:e,assetPath:e,mediaKind:t});return}let n=Rr(window.location.hash);if(!n){dt(`ok/nav/hash-change`,{docName:null,kind:`clear`}),t();return}if(s){dt(`ok/nav/hash-change`,{docName:n,kind:`deferred-loading`});return}let r=Yr(n,{pages:c,folderPaths:o});if(r.kind===`missing`&&/\/+$/.test(n.trim())){dt(`ok/nav/hash-change`,{docName:n,kind:`deferred-missing-folder`});return}let a=jr(r);dt(`ok/nav/hash-change`,{docName:n,kind:a.kind}),i(a)}return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},h=[t,o,s,i,c],e[13]=t,e[14]=o,e[15]=s,e[16]=i,e[17]=c,e[18]=m,e[19]=h):(m=e[18],h=e[19]),(0,Q.useEffect)(m,h),null}function JH(){let e=(0,$.c)(5),[t,n]=(0,Q.useState)(typeof window<`u`&&window.location.hash===WH),r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=function(){window.location.hash===WH&&n(!0)};return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),(0,Q.useEffect)(r,i);let a;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=function(e){if(n(e),!e&&window.location.hash===WH){let{pathname:e,search:t}=window.location;window.history.replaceState(null,``,`${e}${t}`)}},e[2]=a):a=e[2];let o=a,s;return e[3]===t?s=e[4]:(s=(0,Z.jsx)(Ta,{open:t,onOpenChange:o}),e[3]=t,e[4]=s),s}function YH(){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)(XH,t),null}function XH(){let e=function(e){let t=e.target;Cm({target:t,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,key:e.key})&&(e.preventDefault(),window.location.hash!==`#settings`&&(window.location.hash=Sm))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}function ZH(){let e=(0,$.c)(4),{activeTarget:t}=ot(),n=typeof window<`u`?window.okDesktop??null:null,r=t?.kind===`doc`||t?.kind===`folder`?t.kind:null,i=t?.kind===`doc`?t.docName:t?.kind===`folder`?t.folderPath: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 QH(){let e=(0,$.c)(8),{activeDocName:t,activeTarget:n}=ot(),[r,i]=(0,Q.useState)(!1),a;e[0]!==t||e[1]!==n?(a=n?.kind===`folder`?n.folderPath:sr(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;Bp({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)(Hp,{open:r,onOpenChange:i,kind:`file`,initialDir:o}),e[5]=r,e[6]=o,e[7]=l):l=e[7],l}function $H(){let e=(0,$.c)(21),t=typeof window<`u`?window.okDesktop??null:null,n=typeof window<`u`&&window.okDesktop!=null,[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=t?ol({bridge:t,authQueryTransport:ul(),cloneTransport:gl(),openSignIn:()=>new Promise(e=>{c(()=>e),o(!0)})}):null,e[0]=l):l=e[0];let u=l,d;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Z.jsx)(Gh,{}),e[1]=d):d=e[1];let f,p,m,h,g,_,v,y;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Z.jsx)(LH,{}),p=(0,Z.jsx)(qH,{}),m=(0,Z.jsx)(ZH,{}),h=(0,Z.jsx)(QH,{}),g=(0,Z.jsx)(YH,{}),_=(0,Z.jsx)(JH,{}),v=(0,Z.jsx)(Td,{}),y=t&&u?(0,Z.jsx)(zd,{bridge:t,cloneController:u}):null,e[2]=f,e[3]=p,e[4]=m,e[5]=h,e[6]=g,e[7]=_,e[8]=v,e[9]=y):(f=e[2],p=e[3],m=e[4],h=e[5],g=e[6],_=e[7],v=e[8],y=e[9]);let b;e[10]!==a||e[11]!==s?(b=t?(0,Z.jsx)(qu,{open:a,onOpenChange:e=>{e||(o(!1),s?.(null),c(null))},onSuccess:e=>{s?.({authenticated:!0,host:`github.com`,login:e.login}),c(null)}}):null,e[10]=a,e[11]=s,e[12]=b):b=e[12];let x;e[13]===r?x=e[14]:(x=(0,Z.jsx)(Rh,{bridge:t,open:r,onOpenChange:i}),e[13]=r,e[14]=x);let S;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(S=n&&(0,Z.jsx)(`div`,{"aria-hidden":`true`,"data-testid":`editor-window-chrome-drag-strip`,className:`pointer-events-none fixed inset-x-0 top-0 z-50 h-2 [-webkit-app-region:drag]`}),e[15]=S):S=e[15];let C;e[16]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Z.jsx)(AH,{onOpenSearch:()=>i(!0)}),e[16]=C):C=e[16];let w;e[17]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Z.jsxs)(oD,{className:`h-screen overflow-hidden`,children:[C,(0,Z.jsx)(fD,{className:`overflow-hidden h-[calc(100vh-var(--layout-inset-offset))]`,children:(0,Z.jsx)(Uk,{})})]}),e[17]=w):w=e[17];let T;return e[18]!==b||e[19]!==x?(T=(0,Z.jsx)(Ve,{name:`app`,children:(0,Z.jsx)(bt,{children:(0,Z.jsxs)(to,{children:[d,(0,Z.jsxs)(zr,{children:[f,p,m,h,g,_,v,y,b,x,S,w]})]})})}),e[18]=b,e[19]=x,e[20]=T):T=e[20],T}ws(),typeof window<`u`&&window.okDesktop?.config.apiOrigin&&Yd({apiOrigin:window.okDesktop.config.apiOrigin}),hf()&&xf(),Jf(),typeof window<`u`&&Qd({bridge:window.okDesktop}),typeof window<`u`&&Xo({bridge:window.okDesktop}),typeof window<`u`&&Ko({bridge:window.okDesktop}),typeof window<`u`&&tf({bridge:window.okDesktop}),typeof window<`u`&&Rd({bridge:window.okDesktop});var eU=new Ns({defaultOptions:{queries:{retry:1,staleTime:1e4}}}),tU=document.getElementById(`root`);if(!tU)throw Error(`Root element not found`);var nU=typeof window<`u`&&window.okDesktop?.config.mode===`navigator`;(0,Us.createRoot)(tU).render((0,Z.jsx)(Q.StrictMode,{children:(0,Z.jsx)(tn,{client:eU,children:(0,Z.jsxs)(pr,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,disableTransitionOnChange:!0,storageKey:`ok-theme-v1`,children:[(0,Z.jsx)(zn,{children:nU&&window.okDesktop?(0,Z.jsx)(Wd,{bridge:window.okDesktop}):(0,Z.jsx)($H,{})}),(0,Z.jsx)(Jd,{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-D6UM1028.js"></script>
51
+ <script type="module" crossorigin src="./assets/index-Dhi_j7Vk.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{n as e,u as t}from"./init-CmQ_C7Dm.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`]];function s(t){if(t.runtimeExecutable!==`npx`||!Array.isArray(t.runtimeArgs))return`preserved`;if(c(t.runtimeArgs,e))return`canonical`;for(let e of o)if(c(t.runtimeArgs,e))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(e){let o=e.logger??u,c=r(e.projectDir,`.claude`,`launch.json`);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=t(e.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-tbV_XaNr.mjs.map
1
+ import{n as e,u as t}from"./init-OOHQMBAG.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`]];function s(t){if(t.runtimeExecutable!==`npx`||!Array.isArray(t.runtimeArgs))return`preserved`;if(c(t.runtimeArgs,e))return`canonical`;for(let e of o)if(c(t.runtimeArgs,e))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(e){let o=e.logger??u,c=r(e.projectDir,`.claude`,`launch.json`);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=t(e.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-DKyFyGxy.mjs.map
@@ -1,2 +1,2 @@
1
- import{_ as e,d as t,g as n,m as r,s as i}from"./init-CmQ_C7Dm.mjs";import{homedir as a}from"node:os";const o=[[`@inkeep/open-knowledge`,`mcp`],[`-y`,`@inkeep/open-knowledge`,`mcp`]];function s(t){if(t.command!==`npx`||!Array.isArray(t.args))return`preserved`;if(c(t.args,e))return`canonical`;for(let e of o)if(c(t.args,e))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(e){let t=e.logger??f,i=e.home??a(),o=[];for(let a of r){let r=n[a],s=u(()=>r.configPath(``,i));if(s!==null&&o.push(d({scope:`user`,editorId:a,target:r,home:i,cwd:``,configPath:s,configPathOverride:void 0,logger:t})),r.projectConfigPath){let n=r.projectConfigPath,i=u(()=>n(e.projectDir));i!==null&&o.push(d({scope:`project`,editorId:a,target:r,home:void 0,cwd:e.projectDir,configPath:i,configPathOverride:i,logger:t}))}}return{outcomes:o,repairedCount:o.filter(e=>e.outcome===`repaired`).length}}function u(e){try{return e()}catch{return null}}function d(e){let n={scope:e.scope,editorId:e.editorId,configPath:e.configPath},r=i(e.target,e.cwd,e.home,e.configPathOverride);if(r===null)return{...n,outcome:`no-entry`};let a=s(r);if(a===`canonical`)return{...n,outcome:`canonical`};if(a===`preserved`)return{...n,outcome:`preserved`};let o=t(e.target,e.cwd,{mode:`published`,skipAvailabilityCheck:!0},e.home,e.configPathOverride);if(o.action===`failed`){let t=o.error??`unknown write failure`;return e.logger({event:`mcp-config-repair-write-failed`,scope:e.scope,editorId:e.editorId,configPath:e.configPath,error:t}),{...n,outcome:`write-failed`,error:t}}return e.logger({event:`mcp-config-repair-applied`,scope:e.scope,editorId:e.editorId,configPath:e.configPath}),{...n,outcome:`repaired`}}function f(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{l as repairMcpConfigs};
2
- //# sourceMappingURL=repair-mcp-configs-B9q5NKQh.mjs.map
1
+ import{_ as e,d as t,g as n,m as r,s as i}from"./init-OOHQMBAG.mjs";import{homedir as a}from"node:os";const o=[[`@inkeep/open-knowledge`,`mcp`],[`-y`,`@inkeep/open-knowledge`,`mcp`]];function s(t){if(t.command!==`npx`||!Array.isArray(t.args))return`preserved`;if(c(t.args,e))return`canonical`;for(let e of o)if(c(t.args,e))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(e){let t=e.logger??f,i=e.home??a(),o=[];for(let a of r){let r=n[a],s=u(()=>r.configPath(``,i));if(s!==null&&o.push(d({scope:`user`,editorId:a,target:r,home:i,cwd:``,configPath:s,configPathOverride:void 0,logger:t})),r.projectConfigPath){let n=r.projectConfigPath,i=u(()=>n(e.projectDir));i!==null&&o.push(d({scope:`project`,editorId:a,target:r,home:void 0,cwd:e.projectDir,configPath:i,configPathOverride:i,logger:t}))}}return{outcomes:o,repairedCount:o.filter(e=>e.outcome===`repaired`).length}}function u(e){try{return e()}catch{return null}}function d(e){let n={scope:e.scope,editorId:e.editorId,configPath:e.configPath},r=i(e.target,e.cwd,e.home,e.configPathOverride);if(r===null)return{...n,outcome:`no-entry`};let a=s(r);if(a===`canonical`)return{...n,outcome:`canonical`};if(a===`preserved`)return{...n,outcome:`preserved`};let o=t(e.target,e.cwd,{mode:`published`,skipAvailabilityCheck:!0},e.home,e.configPathOverride);if(o.action===`failed`){let t=o.error??`unknown write failure`;return e.logger({event:`mcp-config-repair-write-failed`,scope:e.scope,editorId:e.editorId,configPath:e.configPath,error:t}),{...n,outcome:`write-failed`,error:t}}return e.logger({event:`mcp-config-repair-applied`,scope:e.scope,editorId:e.editorId,configPath:e.configPath}),{...n,outcome:`repaired`}}function f(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{l as repairMcpConfigs};
2
+ //# sourceMappingURL=repair-mcp-configs-Bd5strDU.mjs.map
@@ -1,2 +1,2 @@
1
- import{d as e,g as t,u as n}from"./init-CmQ_C7Dm.mjs";import"./loader-CHhQuNxK.mjs";import"./preview-CIgVuEry.mjs";import{dirname as r,isAbsolute as i,join as a,relative as o,resolve as s}from"node:path";import{statSync as c}from"node:fs";import{readFile as l,realpath as u}from"node:fs/promises";function d(e){return e.replace(/:\d+$/,``)}function f(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:d(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[\w.-]+@)?([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:d(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:d(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 p(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(`/`)}}async function m(e,t){let n,o;try{n=await u(s(e)),o=await u(s(r(e)))}catch{return{kind:`not-git`}}if(!h(n,o))return{kind:`symlink-escape`};let d=a(n,`.git`),p;try{p=c(d)}catch{return{kind:`not-git`}}let m;if(p.isDirectory()){let e;try{e=await u(d)}catch{return{kind:`not-git`}}if(!h(e,n))return{kind:`symlink-escape`};m=e}else if(p.isFile()){let e;try{e=await l(d,`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=i(r)?r:s(n,r);try{m=await u(a)}catch{return{kind:`not-git`}}}else return{kind:`not-git`};let g=a(m,`config`),v;try{v=await l(g,`utf-8`)}catch{return{kind:`not-git`}}let y=_(v);if(y===null)return{kind:`no-origin`};let b=f(y);if(b===null||b.hostname!==`github.com`)return{kind:`non-github`};let x=b.owner.toLowerCase()===t.owner.toLowerCase(),S=b.name.toLowerCase()===t.repo.toLowerCase();return!x||!S?{kind:`wrong-repo`,actualOwner:b.owner,actualRepo:b.name}:{kind:`ok`,gitRemoteUrl:`https://github.com/${b.owner}/${b.name}.git`}}function h(e,t){if(e===t)return!0;let n=o(t,e);return n.length>0&&!n.startsWith(`..`)&&!i(n)}function g(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 _(e){let t=!1;for(let n of e.split(/\r?\n/)){let e=g(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 v(r[1])}return null}function v(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t}function y(r,i,a={}){let o=[];for(let n of i){let i=t[n],s=i.projectConfigPath?.(r);if(!s){o.push({editorId:n,outcome:`skipped-no-project-surface`});continue}let c;try{c=e(i,r,a,void 0,s)}catch(e){o.push({editorId:n,outcome:`failed`,error:e instanceof Error?e.message:String(e)});continue}if(c.action===`written`||c.action===`overwritten`){o.push({editorId:n,outcome:c.action});continue}if(c.action===`failed`){o.push({editorId:n,outcome:`failed`,error:c.error});continue}o.push({editorId:n,outcome:`failed`,error:`unexpected project-scope action: ${c.action}`})}return{editorOutcomes:o,claudeLaunchJson:i.includes(`claude`)?n(r,a):void 0}}export{f as i,m as n,p as r,y as t};
2
- //# sourceMappingURL=src-CzxqX1w-.mjs.map
1
+ import{d as e,g as t,u as n}from"./init-OOHQMBAG.mjs";import"./loader-BeazNH_4.mjs";import"./preview-D4eVomfX.mjs";import{dirname as r,isAbsolute as i,join as a,relative as o,resolve as s}from"node:path";import{statSync as c}from"node:fs";import{readFile as l,realpath as u}from"node:fs/promises";function d(e){return e.replace(/:\d+$/,``)}function f(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:d(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[\w.-]+@)?([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:d(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:d(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 p(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(`/`)}}async function m(e,t){let n,o;try{n=await u(s(e)),o=await u(s(r(e)))}catch{return{kind:`not-git`}}if(!h(n,o))return{kind:`symlink-escape`};let d=a(n,`.git`),p;try{p=c(d)}catch{return{kind:`not-git`}}let m;if(p.isDirectory()){let e;try{e=await u(d)}catch{return{kind:`not-git`}}if(!h(e,n))return{kind:`symlink-escape`};m=e}else if(p.isFile()){let e;try{e=await l(d,`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=i(r)?r:s(n,r);try{m=await u(a)}catch{return{kind:`not-git`}}}else return{kind:`not-git`};let g=a(m,`config`),v;try{v=await l(g,`utf-8`)}catch{return{kind:`not-git`}}let y=_(v);if(y===null)return{kind:`no-origin`};let b=f(y);if(b===null||b.hostname!==`github.com`)return{kind:`non-github`};let x=b.owner.toLowerCase()===t.owner.toLowerCase(),S=b.name.toLowerCase()===t.repo.toLowerCase();return!x||!S?{kind:`wrong-repo`,actualOwner:b.owner,actualRepo:b.name}:{kind:`ok`,gitRemoteUrl:`https://github.com/${b.owner}/${b.name}.git`}}function h(e,t){if(e===t)return!0;let n=o(t,e);return n.length>0&&!n.startsWith(`..`)&&!i(n)}function g(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 _(e){let t=!1;for(let n of e.split(/\r?\n/)){let e=g(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 v(r[1])}return null}function v(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t}function y(r,i,a={}){let o=[];for(let n of i){let i=t[n],s=i.projectConfigPath?.(r);if(!s){o.push({editorId:n,outcome:`skipped-no-project-surface`});continue}let c;try{c=e(i,r,a,void 0,s)}catch(e){o.push({editorId:n,outcome:`failed`,error:e instanceof Error?e.message:String(e)});continue}if(c.action===`written`||c.action===`overwritten`){o.push({editorId:n,outcome:c.action});continue}if(c.action===`failed`){o.push({editorId:n,outcome:`failed`,error:c.error});continue}o.push({editorId:n,outcome:`failed`,error:`unexpected project-scope action: ${c.action}`})}return{editorOutcomes:o,claudeLaunchJson:i.includes(`claude`)?n(r,a):void 0}}export{f as i,m as n,p as r,y as t};
2
+ //# sourceMappingURL=src-C0OBIJW_.mjs.map
@@ -1,3 +1,3 @@
1
- import{n as e,t}from"./esm-CEs3LWY3.mjs";import{pn as n}from"./dist-DHj61EG5.mjs";import{n as r}from"./constants-BbmMpMCp.mjs";import{spawn as i}from"node:child_process";import{join as a}from"node:path";import{closeSync as o,existsSync as s,mkdirSync as c,openSync as l,statSync as u}from"node:fs";import{homedir as d}from"node:os";import{setTimeout as f}from"node:timers/promises";const p=`Open Knowledge.app`,m=`/Applications/${p}`;function h(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return u(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function g(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}if(_(e,m))return m;let t=a(e.homeDir??d(),`Applications`,p);return _(e,t)?t:null}function _(e,t){try{let n=a(t,`Contents`,`MacOS`,`Open Knowledge`),r=e.statSync(n);return r&&typeof r.isFile==`function`?r.isFile():!1}catch{return!1}}function v(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=g(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 y(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 b(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found at ${m}. 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 ${m} (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available at ${m} but launch dispatch did not fire (caller bug).`}}function x(){let e=process.execPath,t=process.argv[1];return t?{command:e,prefixArgs:[t]}:(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(process.argv)}`),{command:`npx`,prefixArgs:[`-y`,`@inkeep/open-knowledge@latest`]})}function S(e,t){return e.host??t.HOST??`localhost`}var C=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 w(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 T(e){s(e.lockDir)||c(e.lockDir,{recursive:!0});let t=l(a(e.lockDir,`last-spawn-error.log`),`w`),n=e.spawn??i,{PORT:r,...u}=process.env,d=x();try{let r=n(d.command,[...d.prefixArgs,...e.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,t],cwd:e.cwd,env:u});return r.unref(),r}finally{try{o(t)}catch{}}}async function E(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}function D(e){let t=e.sigtermGraceMs??1e4,n=e.sigtermPollIntervalMs??200,r=e.sleep??(e=>f(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 O(e){let{config:t,cwd:r,host:i}=e,a=e.skipAutoInit??!1,o=e.skipUiAutoSpawn??!1,s=e.idleThresholdMs??18e5,{existsSync:c,mkdirSync:l}=await import(`node:fs`),{bootServer:u,getLogger:d,isProcessAlive:p,readUiLock:m,resolveContentDir:h}=await import(`./dist-ChwYnRqt.mjs`),g=e.log??d(`start`);if(!a&&!n(r))throw new C(r);try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-B9q5NKQh.mjs`)).repairMcpConfigs)({projectDir:r})}catch(e){g.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-tbV_XaNr.mjs`)).repairLaunchJson)({projectDir:r})}catch(e){g.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}let _=h(t,r);c(_)||(l(_,{recursive:!0}),g.info({contentDir:_},`Created content directory`));let v=null,y=await u({config:t,contentDir:_,projectDir:r,contentRoot:t.content.dir,port:e.port,host:i,quiet:!1,localOpCliArgs:[process.execPath,process.argv[1]],attachUiSibling:!0,idleShutdownMs:s,skipAutoInit:!0,spawnUiSiblingFn:async({lockDir:t})=>{if(v=w({uiLock:m(t),isAlive:p}),v.action===`spawn`&&!o)try{T({lockDir:t,cwd:r,spawn:e.spawn}),g.info({reason:v.reason},`[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 v.action===`skip`&&g.info({port:v.port,pid:v.pid},`UI already running at port ${v.port}`)},idleShutdownHandler:e=>D({readUiLock:()=>m(y.lockDir),isAlive:p,killPid:(e,t)=>{process.kill(e,t)},destroy:e,log:g}),log:g});v||={action:`skip`,reason:`alive`,pid:0,port:0};let b=v,x=null;if(b.action===`skip`)x=b.port>0?b.port:null;else if(!o){let t=e.uiBindTimeoutMs??3e3;x=await E({readUiLock:()=>m(y.lockDir),now:Date.now,sleep:e=>f(e),timeoutMs:t,pollIntervalMs:50}),x===null&&g.warn({timeoutMs:t},`[start] ok ui did not bind within timeout — banner falls back to API URL`)}return{httpServer:y.httpServer,destroy:y.destroy,lockDir:y.lockDir,contentDir:_,port:y.port,ready:y.ready,degraded:y.degraded,uiSpawnDecision:v,resolvedUiPort:x}}function k(t){if(t===`browser`||t===`app`)return t;throw new e(`--mode must be 'browser' or 'app'`)}async function A(e,t){let{renderBanner:n}=await import(`./banner-COfNQySC.mjs`),{dim:i,error:a,warning:o}=await import(`./colors-BCE2jNgl.mjs`),s=process.cwd(),c=e,l=S(t,process.env),u=t.port===void 0?void 0:Number(t.port),d=process.env.PORT?Number(process.env.PORT):void 0,f=u??d,p;try{p=await O({config:c,cwd:s,host:l,port:f})}catch(e){e instanceof C&&(console.error(a(e.message)),process.exit(1));let t=j(e,s,await import(`./dist-ChwYnRqt.mjs`));t!==null&&(console.error(a(t)),process.exit(1)),console.error(`${a(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let m=!1,h=async e=>{if(!m){m=!0,console.log(i(`\nShutting down (${e})`));try{await p.destroy()}catch(e){console.error(`${a(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)}};process.once(`SIGINT`,()=>{h(`SIGINT`)}),process.once(`SIGTERM`,()=>{h(`SIGTERM`)});let g=`http://${l}:${p.port}`,_=l===`0.0.0.0`||l===`::`?`http://0.0.0.0:${p.port}`:void 0,v=p.resolvedUiPort,y=v!==null&&v>0?`http://${l}:${v}`:g;console.log(n({name:`open-knowledge`,version:r,localUrl:y,apiUrl:y===g?void 0:g,networkUrl:_}));let b={"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`};p.ready.then(async()=>{if(p.degraded.length>0){console.log();for(let e of p.degraded){let t=b[e]??`${e} (check server logs for details)`;console.warn(` ${o(`⚠`)} ${o(e)}: ${i(t)}`)}console.log()}if(t.open){let{openBrowser:e}=await import(`./open-browser-Be-7qaQ9.mjs`);e(y)}}).catch(e=>{console.error(` ${a(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}function j(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=a(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 M(e){return new t(`start`).description(`Start the knowledge base collab server`).option(`-p, --port <port>`,`Server port`,void 0).option(`-H, --host <host>`,`Server host`,void 0).option(`--open`,`Open browser after start`).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,k).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{pn as n}from"./dist-DHj61EG5.mjs";import{n as r}from"./constants-xPQnQB6p.mjs";import{spawn as i}from"node:child_process";import{join as a}from"node:path";import{closeSync as o,existsSync as s,mkdirSync as c,openSync as l,statSync as u}from"node:fs";import{homedir as d}from"node:os";import{setTimeout as f}from"node:timers/promises";const p=`Open Knowledge.app`,m=`/Applications/${p}`;function h(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return u(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function g(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}if(_(e,m))return m;let t=a(e.homeDir??d(),`Applications`,p);return _(e,t)?t:null}function _(e,t){try{let n=a(t,`Contents`,`MacOS`,`Open Knowledge`),r=e.statSync(n);return r&&typeof r.isFile==`function`?r.isFile():!1}catch{return!1}}function v(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=g(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 y(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 b(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found at ${m}. 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 ${m} (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available at ${m} but launch dispatch did not fire (caller bug).`}}function x(){let e=process.execPath,t=process.argv[1];return t?{command:e,prefixArgs:[t]}:(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(process.argv)}`),{command:`npx`,prefixArgs:[`-y`,`@inkeep/open-knowledge@latest`]})}function S(e,t){return e.host??t.HOST??`localhost`}var C=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 w(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 T(e){s(e.lockDir)||c(e.lockDir,{recursive:!0});let t=l(a(e.lockDir,`last-spawn-error.log`),`w`),n=e.spawn??i,{PORT:r,...u}=process.env,d=x();try{let r=n(d.command,[...d.prefixArgs,...e.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,t],cwd:e.cwd,env:u});return r.unref(),r}finally{try{o(t)}catch{}}}async function E(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}function D(e){let t=e.sigtermGraceMs??1e4,n=e.sigtermPollIntervalMs??200,r=e.sleep??(e=>f(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 O(e){let{config:t,cwd:r,host:i}=e,a=e.skipAutoInit??!1,o=e.skipUiAutoSpawn??!1,s=e.idleThresholdMs??18e5,{existsSync:c,mkdirSync:l}=await import(`node:fs`),{bootServer:u,getLogger:d,isProcessAlive:p,readUiLock:m,resolveContentDir:h}=await import(`./dist-ChwYnRqt.mjs`),g=e.log??d(`start`);if(!a&&!n(r))throw new C(r);try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-Bd5strDU.mjs`)).repairMcpConfigs)({projectDir:r})}catch(e){g.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-DKyFyGxy.mjs`)).repairLaunchJson)({projectDir:r})}catch(e){g.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}let _=h(t,r);c(_)||(l(_,{recursive:!0}),g.info({contentDir:_},`Created content directory`));let v=null,y=await u({config:t,contentDir:_,projectDir:r,contentRoot:t.content.dir,port:e.port,host:i,quiet:!1,localOpCliArgs:[process.execPath,process.argv[1]],attachUiSibling:!0,idleShutdownMs:s,skipAutoInit:!0,spawnUiSiblingFn:async({lockDir:t})=>{if(v=w({uiLock:m(t),isAlive:p}),v.action===`spawn`&&!o)try{T({lockDir:t,cwd:r,spawn:e.spawn}),g.info({reason:v.reason},`[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 v.action===`skip`&&g.info({port:v.port,pid:v.pid},`UI already running at port ${v.port}`)},idleShutdownHandler:e=>D({readUiLock:()=>m(y.lockDir),isAlive:p,killPid:(e,t)=>{process.kill(e,t)},destroy:e,log:g}),log:g});v||={action:`skip`,reason:`alive`,pid:0,port:0};let b=v,x=null;if(b.action===`skip`)x=b.port>0?b.port:null;else if(!o){let t=e.uiBindTimeoutMs??3e3;x=await E({readUiLock:()=>m(y.lockDir),now:Date.now,sleep:e=>f(e),timeoutMs:t,pollIntervalMs:50}),x===null&&g.warn({timeoutMs:t},`[start] ok ui did not bind within timeout — banner falls back to API URL`)}return{httpServer:y.httpServer,destroy:y.destroy,lockDir:y.lockDir,contentDir:_,port:y.port,ready:y.ready,degraded:y.degraded,uiSpawnDecision:v,resolvedUiPort:x}}function k(t){if(t===`browser`||t===`app`)return t;throw new e(`--mode must be 'browser' or 'app'`)}async function A(e,t){let{renderBanner:n}=await import(`./banner-COfNQySC.mjs`),{dim:i,error:a,warning:o}=await import(`./colors-BCE2jNgl.mjs`),s=process.cwd(),c=e,l=S(t,process.env),u=t.port===void 0?void 0:Number(t.port),d=process.env.PORT?Number(process.env.PORT):void 0,f=u??d,p;try{p=await O({config:c,cwd:s,host:l,port:f})}catch(e){e instanceof C&&(console.error(a(e.message)),process.exit(1));let t=j(e,s,await import(`./dist-ChwYnRqt.mjs`));t!==null&&(console.error(a(t)),process.exit(1)),console.error(`${a(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let m=!1,h=async e=>{if(!m){m=!0,console.log(i(`\nShutting down (${e})`));try{await p.destroy()}catch(e){console.error(`${a(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)}};process.once(`SIGINT`,()=>{h(`SIGINT`)}),process.once(`SIGTERM`,()=>{h(`SIGTERM`)});let g=`http://${l}:${p.port}`,_=l===`0.0.0.0`||l===`::`?`http://0.0.0.0:${p.port}`:void 0,v=p.resolvedUiPort,y=v!==null&&v>0?`http://${l}:${v}`:g;console.log(n({name:`open-knowledge`,version:r,localUrl:y,apiUrl:y===g?void 0:g,networkUrl:_}));let b={"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`};p.ready.then(async()=>{if(p.degraded.length>0){console.log();for(let e of p.degraded){let t=b[e]??`${e} (check server logs for details)`;console.warn(` ${o(`⚠`)} ${o(e)}: ${i(t)}`)}console.log()}if(t.open){let{openBrowser:e}=await import(`./open-browser-Be-7qaQ9.mjs`);e(y)}}).catch(e=>{console.error(` ${a(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}function j(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=a(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 M(e){return new t(`start`).description(`Start the knowledge base collab server`).option(`-p, --port <port>`,`Server port`,void 0).option(`-H, --host <host>`,`Server host`,void 0).option(`--open`,`Open browser after start`).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,k).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.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=v(h());if(n.available){y({spawn:i});return}console.error(b(n.reason)),process.exit(1)}await A(n,t)})}export{w as a,T as c,x as d,h as f,D as i,M as l,y as m,E as n,S as o,v as p,O as r,A as s,C as t,j as u};
3
- //# sourceMappingURL=start-B5WsKMpt.mjs.map
3
+ //# sourceMappingURL=start-BvMp3jiu.mjs.map
@@ -0,0 +1 @@
1
+ import{l as e}from"./start-BvMp3jiu.mjs";export{e as startCommand};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/open-knowledge",
3
- "version": "0.5.0-beta.47",
3
+ "version": "0.5.0-beta.48",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "repository": {
@@ -1,2 +0,0 @@
1
- import"./dist-DHj61EG5.mjs";var e=`0.5.0-beta.47`;const t=`config.yml`,n=e;export{n,t};
2
- //# sourceMappingURL=constants-BbmMpMCp.mjs.map
@@ -1 +0,0 @@
1
- import{l as e}from"./init-CmQ_C7Dm.mjs";export{e as runInit};
@@ -1 +0,0 @@
1
- import{n as e}from"./loader-CHhQuNxK.mjs";export{e as loadConfig};
@@ -1 +0,0 @@
1
- import{n as e,t}from"./preview-CIgVuEry.mjs";export{t as formatPreviewBlock,e as previewContent};
@@ -1 +0,0 @@
1
- import{l as e}from"./start-B5WsKMpt.mjs";export{e as startCommand};