@inkeep/open-knowledge 0.4.0-beta.23 → 0.4.0-beta.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/THIRD_PARTY_NOTICES.md +5 -0
  2. package/dist/assets/skills/open-knowledge/SKILL.md +1 -1
  3. package/dist/cli.mjs +4 -4
  4. package/dist/constants-CZmHtQUh.mjs +2 -0
  5. package/dist/index.mjs +1 -1
  6. package/dist/{init-ngbjAPEx.mjs → init-CMfH982u.mjs} +3 -3
  7. package/dist/init-DesafuF7.mjs +1 -0
  8. package/dist/loader-C9UcssXM.mjs +1 -0
  9. package/dist/{loader-CJa2PwIk.mjs → loader-DvG1wpAx.mjs} +2 -2
  10. package/dist/preview-C8UFVYvI.mjs +1 -0
  11. package/dist/{preview-g-B-YX9w.mjs → preview-DgYoFNt8.mjs} +2 -2
  12. package/dist/public/assets/{ActivityModeContent-DXTQGJYg.js → ActivityModeContent-C9by936Y.js} +1 -1
  13. package/dist/public/assets/{ConsentDialogBody-BPEdQGkb.js → ConsentDialogBody-Ch5CwNgh.js} +1 -1
  14. package/dist/public/assets/DocumentContext-BWaxMbNn.js +37 -0
  15. package/dist/public/assets/{GraphPanel-Bpz5FkWv.js → GraphPanel-BIq7awkX.js} +1 -1
  16. package/dist/public/assets/{McpConsentDialogBody-bOHJX0J3.js → McpConsentDialogBody-8EQrQlPS.js} +1 -1
  17. package/dist/public/assets/OutlinePanel-B5lJ2ZKC.js +2 -0
  18. package/dist/public/assets/SettingsDialog-C7u67QFY.js +11 -0
  19. package/dist/public/assets/{SourceEditor-BX2bkk3k.js → SourceEditor-BoEQaOVh.js} +2 -2
  20. package/dist/public/assets/{agent-presence-Ds2n3U5P.js → agent-presence-BrTlNKmt.js} +1 -1
  21. package/dist/public/assets/{checkbox-DRtAIYeh.js → checkbox-DBLbPikY.js} +1 -1
  22. package/dist/public/assets/config-validation-events-CQhUgigt.js +10 -0
  23. package/dist/public/assets/{dialog-CKgDyF3E.js → dialog-BFN-ujuF.js} +1 -1
  24. package/dist/public/assets/{dist-ClFYZdbN.js → dist-Bej94Urx.js} +1 -1
  25. package/dist/public/assets/{dist-1cEl720w.js → dist-Cg-Qaqw_.js} +1 -1
  26. package/dist/public/assets/{dist-Dy1vgWd7.js → dist-OTL8-1C2.js} +1 -1
  27. package/dist/public/assets/{doc-hash-Bch8gJGz.js → doc-hash-DAxgYkBj.js} +119 -119
  28. package/dist/public/assets/index-BzPHdvNz.css +1 -0
  29. package/dist/public/assets/index-C0DBsuvp.js +1853 -0
  30. package/dist/public/assets/{input-CK6fFyb4.js → input-BOmkuBId.js} +1 -1
  31. package/dist/public/assets/{label-DsL9nuZ1.js → label-Dv_9VZWz.js} +1 -1
  32. package/dist/public/assets/{panel-BgMqDESF.js → panel-8fydlQgn.js} +1 -1
  33. package/dist/public/assets/{target-navigation-intent-7oKUkgn7.js → target-navigation-intent-CKIqVD_0.js} +1 -1
  34. package/dist/public/assets/{textarea-DeHOTn8t.js → textarea-57j4gLcZ.js} +1 -1
  35. package/dist/public/assets/{toggle-group-B9AHQBy6.js → toggle-group-CHwk3w0Y.js} +1 -1
  36. package/dist/public/assets/{tooltip-CONp_Pmy.js → tooltip-DNV87xh_.js} +1 -1
  37. package/dist/public/index.html +20 -20
  38. package/dist/{src-BlDqmpar.mjs → src-Bdc8vmx9.mjs} +2 -2
  39. package/dist/start-1_WAnc88.mjs +1 -0
  40. package/dist/{start-CzXb9OWd.mjs → start-CPFpaTRH.mjs} +2 -2
  41. package/package.json +1 -1
  42. package/dist/constants-D-Kk6PDS.mjs +0 -2
  43. package/dist/init-DsKniKF7.mjs +0 -1
  44. package/dist/loader-BKJCUkvm.mjs +0 -1
  45. package/dist/preview-CFScUs-A.mjs +0 -1
  46. package/dist/public/assets/DocumentContext-CKzRBTvD.js +0 -37
  47. package/dist/public/assets/OutlinePanel-l_cN_l_u.js +0 -2
  48. package/dist/public/assets/SettingsDialog-CAOM5xyh.js +0 -11
  49. package/dist/public/assets/config-validation-events-C-i-gTpF.js +0 -10
  50. package/dist/public/assets/index-Cit-_pfo.js +0 -1853
  51. package/dist/public/assets/index-rvXPVXkP.css +0 -1
  52. package/dist/start-Cjd_Q-tt.mjs +0 -1
  53. /package/dist/public/assets/{button-BsFpqlpT.js → button-C1nwPVFQ.js} +0 -0
@@ -892,6 +892,11 @@ Homepage: https://mozilla.github.io/pdf.js/
892
892
 
893
893
  _(LICENSE template present but no copyright line filled in; refer to the package source for canonical attribution.)_
894
894
 
895
+ ### `scheduler-polyfill@1.3.0`
896
+ Homepage: https://github.com/GoogleChromeLabs/scheduler-polyfill
897
+
898
+ _(LICENSE template present but no copyright line filled in; refer to the package source for canonical attribution.)_
899
+
895
900
  ### `tunnel-agent@0.6.0`
896
901
  Homepage: https://github.com/mikeal/tunnel-agent
897
902
 
@@ -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`), 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. Authoritative — MCP server instructions and AGENTS.md overlap but do not substitute for the full attach rule, grounding rule, media rules, dead-link verification, and failure-mode guidance carried only here."
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.4.0-beta.23"
6
+ version: "0.4.0-beta.24"
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{Ar as n,Cr as r,Dr as i,Et as a,Kr as o,Nn as s,Nr as c,Sr as l,Tn as u,br as d,gr as f,hr as p,mr as m,n as h,nt as ee,q as te,qr as g,ur as _,xr as v}from"./dist-IguRFGXq.mjs";import{n as y,r as b,t as x}from"./dist-bundle-BSdjl7Rj.mjs";import{C as ne,S,_ as re,b as ie,g as ae,h as oe,m as C,r as se,v as w,w as ce,x as le,y as ue}from"./init-ngbjAPEx.mjs";import{c as de,f as T,l as fe,s as E}from"./server-lock-D7DXNVql-BRVVzA6T.mjs";import{i as pe}from"./git-handle-DwfYp_z--CfyPz4Dz.mjs";import{$ as me,B as he,Ft as ge,J as _e,Jt as ve,On as ye,Qt as be,T as xe,Yt as Se,dn as Ce,dr as we,fr as Te,gr as Ee,hr as De,jn as Oe,lr as ke,pr as Ae,ur as je}from"./dist-DSb6dRAy.mjs";import{n as Me}from"./constants-D-Kk6PDS.mjs";import{t as Ne}from"./loader-CJa2PwIk.mjs";import{d as Pe,f as Fe,l as Ie,m as Le,p as Re,s as ze}from"./start-CzXb9OWd.mjs";import{c as Be,i as Ve,n as D,o as O,r as He,s as k,t as A}from"./colors-BNufdynn.mjs";import"./src-BlDqmpar.mjs";import{execFileSync as Ue,spawn as We,spawnSync as j}from"node:child_process";import Ge,{basename as Ke,dirname as qe,join as M,relative as Je,resolve as N}from"node:path";import{closeSync as Ye,existsSync as P,mkdirSync as Xe,mkdtempSync as Ze,openSync as Qe,readFileSync as F,readdirSync as $e,rmSync as et,unlinkSync as tt,writeFileSync as nt}from"node:fs";import rt from"node:process";import{homedir as it,hostname as at,tmpdir as ot}from"node:os";import{AsyncLocalStorage as st,AsyncResource as ct}from"node:async_hooks";import{stripVTControlCharacters as lt,styleText as I}from"node:util";import*as ut from"node:readline";import{randomUUID as dt}from"node:crypto";import{realpath as ft}from"node:fs/promises";import{setTimeout as pt}from"node:timers/promises";import{createServer as mt,request as ht}from"node:http";import{createInterface as gt}from"node:readline/promises";var _t=g();const vt=`open-knowledge`;var yt=class{backend=`keyring`;async get(e){let{Entry:t}=await import(`@napi-rs/keyring`);try{let n=new t(vt,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(vt,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(vt,e).deletePassword()}catch{}}},bt=class{backend=`file`;authFile;constructor(e){this.authFile=e??M(it(),`.ok`,`auth.yml`)}read(){if(!P(this.authFile))return{};try{return(0,_t.parse)(F(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=qe(this.authFile);P(t)||Xe(t,{recursive:!0,mode:448}),nt(this.authFile,(0,_t.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 xt(e){try{let{Entry:e}=await import(`@napi-rs/keyring`);return new e(vt,`__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{Ar as n,Cr as r,Dr as i,Et as a,Kr as o,Nn as s,Nr as c,Sr as l,Tn as u,br as d,gr as f,hr as p,mr as m,n as h,nt as ee,q as te,qr as g,ur as _,xr as v}from"./dist-IguRFGXq.mjs";import{n as y,r as b,t as x}from"./dist-bundle-BSdjl7Rj.mjs";import{C as ne,S,_ as re,b as ie,g as ae,h as oe,m as C,r as se,v as w,w as ce,x as le,y as ue}from"./init-CMfH982u.mjs";import{c as de,f as T,l as fe,s as E}from"./server-lock-D7DXNVql-BRVVzA6T.mjs";import{i as pe}from"./git-handle-DwfYp_z--CfyPz4Dz.mjs";import{$ as me,B as he,Ft as ge,J as _e,Jt as ve,On as ye,Qt as be,T as xe,Yt as Se,dn as Ce,dr as we,fr as Te,gr as Ee,hr as De,jn as Oe,lr as ke,pr as Ae,ur as je}from"./dist-DSb6dRAy.mjs";import{n as Me}from"./constants-CZmHtQUh.mjs";import{t as Ne}from"./loader-DvG1wpAx.mjs";import{d as Pe,f as Fe,l as Ie,m as Le,p as Re,s as ze}from"./start-CPFpaTRH.mjs";import{c as Be,i as Ve,n as D,o as O,r as He,s as k,t as A}from"./colors-BNufdynn.mjs";import"./src-Bdc8vmx9.mjs";import{execFileSync as Ue,spawn as We,spawnSync as j}from"node:child_process";import Ge,{basename as Ke,dirname as qe,join as M,relative as Je,resolve as N}from"node:path";import{closeSync as Ye,existsSync as P,mkdirSync as Xe,mkdtempSync as Ze,openSync as Qe,readFileSync as F,readdirSync as $e,rmSync as et,unlinkSync as tt,writeFileSync as nt}from"node:fs";import rt from"node:process";import{homedir as it,hostname as at,tmpdir as ot}from"node:os";import{AsyncLocalStorage as st,AsyncResource as ct}from"node:async_hooks";import{stripVTControlCharacters as lt,styleText as I}from"node:util";import*as ut from"node:readline";import{randomUUID as dt}from"node:crypto";import{realpath as ft}from"node:fs/promises";import{setTimeout as pt}from"node:timers/promises";import{createServer as mt,request as ht}from"node:http";import{createInterface as gt}from"node:readline/promises";var _t=g();const vt=`open-knowledge`;var yt=class{backend=`keyring`;async get(e){let{Entry:t}=await import(`@napi-rs/keyring`);try{let n=new t(vt,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(vt,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(vt,e).deletePassword()}catch{}}},bt=class{backend=`file`;authFile;constructor(e){this.authFile=e??M(it(),`.ok`,`auth.yml`)}read(){if(!P(this.authFile))return{};try{return(0,_t.parse)(F(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=qe(this.authFile);P(t)||Xe(t,{recursive:!0,mode:448}),nt(this.authFile,(0,_t.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 xt(e){try{let{Entry:e}=await import(`@napi-rs/keyring`);return new e(vt,`__probe__`),process.stderr.write(`[auth] token storage: OS keychain
3
3
  `),new yt}catch{return process.stderr.write(`[auth] token storage: file (~/.ok/auth.yml)
4
4
  `),new bt(e)}}async function St(e,t,n){let r=Ct(await wt(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 Ct(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 wt(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 Tt(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 St(process.stdin,process.stdout,t);process.exit(n)}),n}function Et(e){let t=e.endpoint.DEFAULTS;return/^https:\/\/(api\.)?github\.com$/.test(t.baseUrl)?`https://github.com`:t.baseUrl.replace(`/api/v3`,``)}async function Dt(e,t,n){let r={baseUrl:Et(e),headers:{accept:`application/json`},...n},i=await e(t,r);if(`error`in i.data){let n=new y(`${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 Ot(e){let t=e.request||x,n={client_id:e.clientId};return`scopes`in e&&Array.isArray(e.scopes)&&(n.scope=e.scopes.join(` `)),Dt(t,`POST /login/device/code`,n)}async function kt(e){let t=await Dt(e.request||x,`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=At(e,t.data.expires_in),n.refreshTokenExpiresAt=At(e,t.data.refresh_token_expires_in)}delete n.scopes}return{...t,authentication:n}}function At(e,t){return new Date(e+t*1e3).toISOString()}async function jt(e,t){let n=Mt(e,t.auth);if(n)return n;let{data:r}=await Ot({clientType:e.clientType,clientId:e.clientId,request:t.request||e.request,scopes:t.auth.scopes||e.scopes});await e.onVerification(r);let i=await Pt(t.request||e.request,e.clientId,e.clientType,r);return e.authentication=i,i}function Mt(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 Nt(e){await new Promise(t=>setTimeout(t,e*1e3))}async function Pt(e,t,n,r){try{let i={clientId:t,request:e,code:r.device_code},{authentication:a}=n===`oauth-app`?await kt({...i,clientType:`oauth-app`}):await kt({...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 Nt(r.interval),Pt(e,t,n,r);if(a===`slow_down`)return await Nt(r.interval+7),Pt(e,t,n,r);throw i}}async function Ft(e,t){return jt(e,{auth:t})}async function It(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 jt(e,{request:t,auth:{type:`oauth`}});return i.headers.authorization=`token ${a}`,t(i)}var Lt=`0.0.0-development`;function Rt(e){let t=e.request||x.defaults({headers:{"user-agent":`octokit-auth-oauth-device.js/${Lt} ${b()}`}}),{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(Ft.bind(null,i),{hook:It.bind(null,i)})}async function zt(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=Rt({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 Bt={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 Vt;(function(e){})(Vt||={});function Ht(e){return c(_,e)}function Ut(){return process.env.OPEN_KNOWLEDGE_GITHUB_CLIENT_ID??`Ov23liqlSd0V1MwR6rhI`}const Wt=new Set([`gitlab.com`,`bitbucket.org`,`codeberg.org`,`gitea.com`,`sr.ht`,`sourcehut.org`]);function Gt(e){let t=e.toLowerCase().replace(/:\d+$/,``);Wt.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 Kt(e,t){e&&process.stdout.write(`${JSON.stringify(t)}\n`)}async function qt(e,t,n=zt){let r=Ut(),{host:i,json:a}=e;Gt(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?Kt(!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?Kt(!0,{type:`complete`,host:i,login:s}):process.stderr.write(`✓ Logged in as ${s} on ${i}\n`)}function Jt(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 qt(t,await e())})}const Yt=e=>e.name===`enter`||e.name===`return`;var Xt=class extends Error{name=`AbortPromptError`;message=`Prompt was aborted`;constructor(e){super(),this.cause=e?.cause}},Zt=class extends Error{name=`CancelPromptError`;message=`Prompt was canceled`},Qt=class extends Error{name=`ExitPromptError`},$t=class extends Error{name=`HookError`},en=class extends Error{name=`ValidationError`};const tn=new st;function nn(e){return{rl:e,hooks:[],hooksCleanup:[],hooksEffect:[],index:0,handleChange(){}}}function rn(e,t){let n=nn(e);return tn.run(n,()=>{function e(e){n.handleChange=()=>{n.index=0,e()},n.handleChange()}return t(e)})}function L(){let e=tn.getStore();if(!e)throw new $t(`[Inquirer] Hook functions can only be called from within a prompt`);return e}function an(){return L().rl}function on(e){return ct.bind((...t)=>{let n=L(),r=!1,i=n.handleChange;n.handleChange=()=>{r=!0};let a=e(...t);return r&&i(),n.handleChange=i,a})}function sn(e){let t=L(),{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 cn(){L().handleChange()}const ln={queue(e){let t=L(),{index:n}=t;t.hooksEffect.push(()=>{t.hooksCleanup[n]?.();let r=e(an());if(r!=null&&typeof r!=`function`)throw new en(`useEffect return value must be a cleanup function or nothing.`);t.hooksCleanup[n]=r})},run(){let e=L();on(()=>{e.hooksEffect.forEach(e=>{e()}),e.hooksEffect.length=0})()},clearAll(){let e=L();e.hooksCleanup.forEach(e=>{e?.()}),e.hooksEffect.length=0,e.hooksCleanup.length=0}};function un(e){return typeof e==`function`}function R(e){return sn(t=>{let n=ct.bind(function(e){t.get()!==e&&(t.set(e),cn())});if(t.initialized)return[t.get(),n];let r=un(e)?e():e;return t.set(r),[r,n]})}function dn(e,t){sn(n=>{let r=n.get();(!Array.isArray(r)||t.some((e,t)=>!Object.is(e,r[t])))&&ln.queue(e),n.set(t)})}const fn={prefix:{idle:I(`blue`,`?`),done:I(`green`,ce.tick)},spinner:{interval:80,frames:[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`].map(e=>I(`yellow`,e))},style:{answer:e=>I(`cyan`,e),message:e=>I(`bold`,e),error:e=>I(`red`,`> ${e}`),defaultAnswer:e=>I(`dim`,`(${e})`),help:e=>I(`dim`,e),highlight:e=>I(`cyan`,e),key:e=>I(`cyan`,I(`bold`,`<${e}>`))}};function pn(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 mn(...e){let t={};for(let n of e)for(let[e,r]of Object.entries(n)){let n=t[e];t[e]=pn(n)&&pn(r)?mn(n,r):r}return t}function hn(...e){return mn(fn,...e.filter(e=>e!=null))}function gn({status:e=`idle`,theme:t}){let[n,r]=R(!1),[i,a]=R(0),{prefix:o,spinner:s}=hn(t);return dn(()=>{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 _n(e){return R({current:e})[0]}function vn(e){let t=_n(e);t.current=e,dn(e=>{let n=!1,r=on((r,i)=>{n||t.current(i,e)});return e.input.on(`keypress`,r),()=>{n=!0,e.input.removeListener(`keypress`,r)}},[])}var yn=e(ne(),1);function bn(e,t){return e.split(`
@@ -17,10 +17,10 @@ import{o as e}from"./chunk-FK9Q3tQk.mjs";import{t}from"./esm-CEs3LWY3.mjs";impor
17
17
  `),process.exit(1)}await t.set(r,c,a,{gitProtocol:`https`,name:l,email:u}),i?process.stdout.write(`${JSON.stringify({type:`complete`,host:r,login:c})}\n`):process.stderr.write(`✓ PAT stored for ${c} on ${r}\n`)}function Dr(e){return new t(`pat`).description(`Store a Personal Access Token`).option(`--host <host>`,`GitHub or GitHub Enterprise hostname`,`github.com`).option(`--json`,`Output JSON`,!1).action(async t=>{await Er(t,await e())})}async function Or(e,t){let{host:n,json:r}=e;Gt(n);let i=await t.get(n);i??(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 Tr({auth:i.token,...a?{baseUrl:a}:{}}),s=[];for await(let e of o.paginate.iterator(o.repos.listForAuthenticatedUser,{per_page:100,sort:`updated`}))for(let t of e.data)s.push({full_name:t.full_name,clone_url:t.clone_url,private:t.private});if(r)process.stdout.write(`${JSON.stringify({type:`repos`,host:n,repos:s})}\n`);else for(let e of s)process.stdout.write(`${e.full_name} ${e.clone_url}\n`)}function kr(e){return new t(`repos`).description(`List accessible repositories`).option(`--host <host>`,`GitHub or GitHub Enterprise hostname`,`github.com`).option(`--json`,`Output JSON`,!1).action(async t=>{await Or(t,await e())})}async function Ar(e,t){let{host:n}=e;await t.clear(n),process.stderr.write(`✓ Signed out from ${n}\n`)}function jr(e){return new t(`signout`).description(`Remove stored credentials`).option(`--host <host>`,`GitHub hostname`,`github.com`).action(async t=>{await Ar(t,await e())})}async function Mr(e,t){let{host:n,json:r}=e;Gt(n);let i=await t.get(n);i??(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 Tr({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,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`})+`
18
18
  `):process.stderr.write(`✗ Token invalid for ${n}\n`),process.exit(1)}}function Nr(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 Mr(t,await e())})}function Pr(){let e=new t(`auth`);e.description(`GitHub authentication management`);let n=()=>xt();return e.addCommand(Jt(n)),e.addCommand(Nr(n)),e.addCommand(kr(n)),e.addCommand(jr(n)),e.addCommand(Dr(n)),e.addCommand(Tt(n)),e}function B(e,t,n={}){let r=fe(e,t);if(!P(r))return{status:`missing`,lockPath:r};let i;try{i=JSON.parse(F(r,`utf-8`))}catch{return{status:`corrupt`,lockPath:r}}if(!i||typeof i!=`object`||!de(i.pid))return{status:`corrupt`,lockPath:r};let a=i;if(!(n.isAlive??E)(a.pid))return{status:`dead-pid`,lockPath:r,lock:a};let o=n.host??at();return a.hostname===o?{status:`alive`,lockPath:r,lock:a}:{status:`foreign-host`,lockPath:r,lock:a}}function Fr(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 Ir(e){let t=e.inspect??(t=>B(e.lockDir,t)),n=e.unlink??(e=>tt(e)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=Fr(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 Lr(e){return new t(`clean`).description(`Prune stale / corrupt open-knowledge lock files (never touches live locks)`).action(()=>{e(),Ir({lockDir:Oe(process.cwd())}).failed.length>0&&(process.exitCode=1)})}function Rr(){try{let e=Ue(`gh`,[`auth`,`token`],{encoding:`utf-8`,stdio:[`ignore`,`pipe`,`pipe`],timeout:5e3}).trim();return e.length===0?{available:!1}:{available:!0,token:e}}catch{return{available:!1}}}async function zr(e,t,n={},r=Rr){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`]}}function Br(e){return e.replace(/:\d+$/,``)}function Vr(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:Br(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[\w.-]+@)?([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:Br(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:Br(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}const Hr=[[`count`,0,10],[`compress`,10,20],[`receiv`,20,60],[`resolv`,60,100]];function Ur(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 Hr)if(n.includes(e))return{stage:t[1],pct:Math.round(i+r/100*(a-i))};return null}function V(e,t){e&&process.stdout.write(`${JSON.stringify(t)}\n`)}async function Wr(e,t,n,r=process.cwd()){let i=Vr(e);if(!i)throw Error(`Invalid git URL: ${e}`);let a=t.dir?N(r,t.dir):N(r,i.name);if(P(a)&&$e(a).length>0)throw Error(`Target directory is not empty: ${a}`);let o=await xt(),s=await zr(i.hostname,o,{}),c=pe({baseDir:r,config:s.credentialArgs.length>=2?[s.credentialArgs[1]]:[],unsafe:{allowUnsafeCredentialHelper:!0}}).env({GIT_TERMINAL_PROMPT:`0`}),l=-1;c.outputHandler((e,n,r)=>{r.on(`data`,e=>{let n=e.toString(`utf-8`);for(let e of n.split(`
19
19
  `)){let n=Ur(e);n&&n.pct!==l&&(l=n.pct,V(t.json,{type:`progress`,pct:n.pct,stage:n.stage}),t.json||process.stderr.write(`\r Cloning… ${n.pct}%`))}})}),await c.clone(e,a,[`--progress`]),t.json||process.stderr.write(`
20
- `);try{let{runInit:e}=await import(`./init-DsKniKF7.mjs`),n=await e({cwd:a,mcp:!1});if(n.contentUpdated.length>0){let e=`auto-init: updated ${n.contentUpdated.join(`, `)}`;t.json?V(!0,{type:`warning`,message:e}):process.stderr.write(` ${e}\n`)}}catch(e){let n=e instanceof Error?e.message:String(e);t.json?V(!0,{type:`warning`,message:`auto-init: ${n}`}):process.stderr.write(` auto-init: ${n}\n`)}try{Gr(a)}catch(e){let n=e instanceof Error?e.message:String(e);t.json?V(!0,{type:`warning`,message:`git-exclude: ${n}`}):process.stderr.write(` git-exclude: ${n}\n`)}return a}function Gr(e){let t=M(e,`.git`,`info`,`exclude`);if(!P(t))return`no-exclude`;let n=F(t,`utf-8`),r=new Set([`.ok`,`.ok/`,`/.ok`,`/.ok/`]);return n.split(`
20
+ `);try{let{runInit:e}=await import(`./init-DesafuF7.mjs`),n=await e({cwd:a,mcp:!1});if(n.contentUpdated.length>0){let e=`auto-init: updated ${n.contentUpdated.join(`, `)}`;t.json?V(!0,{type:`warning`,message:e}):process.stderr.write(` ${e}\n`)}}catch(e){let n=e instanceof Error?e.message:String(e);t.json?V(!0,{type:`warning`,message:`auto-init: ${n}`}):process.stderr.write(` auto-init: ${n}\n`)}try{Gr(a)}catch(e){let n=e instanceof Error?e.message:String(e);t.json?V(!0,{type:`warning`,message:`git-exclude: ${n}`}):process.stderr.write(` git-exclude: ${n}\n`)}return a}function Gr(e){let t=M(e,`.git`,`info`,`exclude`);if(!P(t))return`no-exclude`;let n=F(t,`utf-8`),r=new Set([`.ok`,`.ok/`,`/.ok`,`/.ok/`]);return n.split(`
21
21
  `).map(e=>e.trim()).some(e=>r.has(e))?`already-present`:(nt(t,`${n}${n.length===0||n.endsWith(`
22
22
  `)?``:`
23
- `}.ok/\n`,`utf-8`),`appended`)}function Kr(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 Wr(t,{json:r.json,dir:n},i);if(r.json)V(!0,{type:`complete`,dir:a});else{process.stderr.write(`✓ Cloned to ${a}\n`),process.chdir(a);let{startCommand:t}=await import(`./start-Cjd_Q-tt.mjs`);await t(e).parseAsync([],{from:`user`})}}catch(e){let t=e instanceof Error?e.message:String(e);r.json?V(!0,{type:`error`,message:t}):process.stderr.write(`✗ ${t}\n`),process.exitCode=1}})}const qr=[[`sync`],[`persistence`,`debounceMs`],[`persistence`,`maxDebounceMs`],[`server`,`port`],[`content`,`include`],[`content`,`exclude`]];function Jr(e={}){let t=e.log??(e=>console.error(e)),n=e.error??(e=>console.error(e)),r=e.loadConfigFn??Ne;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 Yr(e){let t=(0,_t.parseDocument)(F(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 qr)t.hasIn(e)&&n.push(e.join(`.`));return n}function Xr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Zr(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=Xr(i)?i:{};e[r]=a,e=a}e[n[n.length-1]]=null}return t}async function Qr(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??Ee,c=[];(r===`project`||r===`both`)&&c.push({scope:`project`,absPath:De(`project`,a,e.homedirOverride)}),(r===`user`||r===`both`)&&c.push({scope:`user`,absPath:De(`user`,a,e.homedirOverride)});let l=[],u=!0;for(let{scope:t,absPath:n}of c){if(!P(n)){l.push({path:n,scope:t,found:[],removed:[]});continue}let r;try{r=Yr(n)}catch(e){let r=e instanceof Error?e.message:String(e);l.push({path:n,scope:t,found:[],removed:[],error:r}),u=!1;continue}if(r.length===0||i){l.push({path:n,scope:t,found:r,removed:[]});continue}let c=await o({cwd:a,scope:t,patch:Zr(qr.filter(e=>r.includes(e.join(`.`)))),homedirOverride:e.homedirOverride});if(!c.ok){l.push({path:n,scope:t,found:r,removed:[],error:s(c.error)}),u=!1;continue}l.push({path:n,scope:t,found:r,removed:r})}for(let e of l)e.error&&n(`✗ ${e.path}: ${e.error}`);let d=l.some(e=>e.error!==void 0),f=l.reduce((e,t)=>e+t.found.length,0);if(f===0&&!d)t(`No deprecated fields found.`);else if(f>0)for(let e of l)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:l,ok:u}}function $r(){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(()=>{Jr({}).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 Qr({scope:t,dryRun:e.dryRun})).ok||(process.exitCode=1)}),e}var H=e(Be(),1);const U=2e3,ei=[/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)/];function ti(e){return ei.some(t=>t.test(e))}async function ni(){let e=j(`pgrep`,[`-a`,`-f`,`cli\\.mjs|open-knowledge|(^|[ /])ok[ ]+(start|mcp|ui)([ ]|$)|packages/(cli|app)|hocuspocus|vite`],{encoding:`utf-8`,timeout:U});if(!(e.error!=null&&e.error.code===`ENOENT`)){let t=e.stdout??``,n=ri(t);if(n.length>0||t.trim()===``)return n}let t=j(`ps`,[`-axo`,`pid,command`],{encoding:`utf-8`,timeout:U});return t.error!=null||!t.stdout?[]:ii(t.stdout)}function ri(e){let t=[];for(let n of e.split(`
23
+ `}.ok/\n`,`utf-8`),`appended`)}function Kr(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 Wr(t,{json:r.json,dir:n},i);if(r.json)V(!0,{type:`complete`,dir:a});else{process.stderr.write(`✓ Cloned to ${a}\n`),process.chdir(a);let{startCommand:t}=await import(`./start-1_WAnc88.mjs`);await t(e).parseAsync([],{from:`user`})}}catch(e){let t=e instanceof Error?e.message:String(e);r.json?V(!0,{type:`error`,message:t}):process.stderr.write(`✗ ${t}\n`),process.exitCode=1}})}const qr=[[`sync`],[`persistence`,`debounceMs`],[`persistence`,`maxDebounceMs`],[`server`,`port`],[`content`,`include`],[`content`,`exclude`]];function Jr(e={}){let t=e.log??(e=>console.error(e)),n=e.error??(e=>console.error(e)),r=e.loadConfigFn??Ne;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 Yr(e){let t=(0,_t.parseDocument)(F(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 qr)t.hasIn(e)&&n.push(e.join(`.`));return n}function Xr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Zr(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=Xr(i)?i:{};e[r]=a,e=a}e[n[n.length-1]]=null}return t}async function Qr(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??Ee,c=[];(r===`project`||r===`both`)&&c.push({scope:`project`,absPath:De(`project`,a,e.homedirOverride)}),(r===`user`||r===`both`)&&c.push({scope:`user`,absPath:De(`user`,a,e.homedirOverride)});let l=[],u=!0;for(let{scope:t,absPath:n}of c){if(!P(n)){l.push({path:n,scope:t,found:[],removed:[]});continue}let r;try{r=Yr(n)}catch(e){let r=e instanceof Error?e.message:String(e);l.push({path:n,scope:t,found:[],removed:[],error:r}),u=!1;continue}if(r.length===0||i){l.push({path:n,scope:t,found:r,removed:[]});continue}let c=await o({cwd:a,scope:t,patch:Zr(qr.filter(e=>r.includes(e.join(`.`)))),homedirOverride:e.homedirOverride});if(!c.ok){l.push({path:n,scope:t,found:r,removed:[],error:s(c.error)}),u=!1;continue}l.push({path:n,scope:t,found:r,removed:r})}for(let e of l)e.error&&n(`✗ ${e.path}: ${e.error}`);let d=l.some(e=>e.error!==void 0),f=l.reduce((e,t)=>e+t.found.length,0);if(f===0&&!d)t(`No deprecated fields found.`);else if(f>0)for(let e of l)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:l,ok:u}}function $r(){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(()=>{Jr({}).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 Qr({scope:t,dryRun:e.dryRun})).ok||(process.exitCode=1)}),e}var H=e(Be(),1);const U=2e3,ei=[/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)/];function ti(e){return ei.some(t=>t.test(e))}async function ni(){let e=j(`pgrep`,[`-a`,`-f`,`cli\\.mjs|open-knowledge|(^|[ /])ok[ ]+(start|mcp|ui)([ ]|$)|packages/(cli|app)|hocuspocus|vite`],{encoding:`utf-8`,timeout:U});if(!(e.error!=null&&e.error.code===`ENOENT`)){let t=e.stdout??``,n=ri(t);if(n.length>0||t.trim()===``)return n}let t=j(`ps`,[`-axo`,`pid,command`],{encoding:`utf-8`,timeout:U});return t.error!=null||!t.stdout?[]:ii(t.stdout)}function ri(e){let t=[];for(let n of e.split(`
24
24
  `)){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)&&ti(a)&&t.push(o)}return t}function ii(e){let t=[],n=e.split(`
25
25
  `);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)&&ti(o)&&t.push(s)}return t}function ai(e){let t=e.trim().split(/\s+/).filter(Boolean);for(let e of t){if(e.startsWith(`@`))continue;let t=Ke(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 oi(e){let t=j(`ps`,[`-p`,String(e),`-o`,`command=`],{encoding:`utf-8`,timeout:U});return t.error!=null||!t.stdout?null:t.stdout.trim()||null}function si(e){let t=j(`ps`,[`-p`,String(e),`-o`,`%cpu=,%mem=`],{encoding:`utf-8`,timeout:U});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=j(`lsof`,[`-p`,String(e),`-a`,`-d`,`cwd`,`-Fn`],{encoding:`utf-8`,timeout:U});if(t.error!=null)return null;let n=t.stdout??``;for(let e of n.split(`
26
26
  `))if(e.startsWith(`n`)&&e.length>1)return e.slice(1);return null}function li(e){let t=[],n=e.split(`
@@ -55,7 +55,7 @@ setTimeout(() => process.exit(2), ${t+1e4});
55
55
  `,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]===`
56
56
  `&&r++}}return[t,n]}var Wa=class extends TransformStream{constructor({onError:e,onRetry:t,onComment:n}={}){let r;super({start(i){r=Ha({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 Ga={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2};var J=class extends Error{constructor(e,t){super(`Streamable HTTP error: ${t}`),this.code=e}},Ka=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=ki(t?.fetch,t?.requestInit),this._sessionId=t?.sessionId,this._reconnectionOptions=t?.reconnectionOptions??Ga}async _authThenStart(){if(!this._authProvider)throw new q(`No auth provider`);let e;try{e=await ya(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 q;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=Oi(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 J(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 Wa({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=ke.parse(JSON.parse(e.data));Ae(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 q(`No auth provider`);if(await ya(this._authProvider,{serverUrl:this._url,authorizationCode:e,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})!==`AUTHORIZED`)throw new q(`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:Te(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 J(401,`Server returned 401 after successful authentication`);let{resourceMetadataUrl:t,scope:n}=Ca(o);if(this._resourceMetadataUrl=t,this._scope=n,await ya(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})!==`AUTHORIZED`)throw new q;return this._hasCompletedAuthFlow=!0,this.send(e)}if(o.status===403&&this._authProvider){let{resourceMetadataUrl:t,scope:n,error:r}=Ca(o);if(r===`insufficient_scope`){let r=o.headers.get(`WWW-Authenticate`);if(this._lastUpscopingHeader===r)throw new J(403,`Server returned 403 after trying upscoping`);if(n&&(this._scope=n),t&&(this._resourceMetadataUrl=t),this._lastUpscopingHeader=r??void 0,await ya(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetch})!==`AUTHORIZED`)throw new q;return this.send(e)}}throw new J(o.status,`Error POSTing to endpoint: ${t}`)}if(this._hasCompletedAuthFlow=!1,this._lastUpscopingHeader=void 0,o.status===202){await o.body?.cancel(),we(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=>ke.parse(e)):[ke.parse(e)];for(let e of t)this.onmessage?.(e)}else throw await o.body?.cancel(),new J(-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 J(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})}},qa=class{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;let e=this._buffer.indexOf(`
57
57
  `);if(e===-1)return null;let t=this._buffer.toString(`utf8`,0,e).replace(/\r$/,``);return this._buffer=this._buffer.subarray(e+1),Ja(t)}clear(){this._buffer=void 0}};function Ja(e){return ke.parse(JSON.parse(e))}function Ya(e){return JSON.stringify(e)+`
58
- `}var Xa=class{constructor(e=rt.stdin,t=rt.stdout){this._stdin=e,this._stdout=t,this._readBuffer=new qa,this._started=!1,this._ondata=e=>{this._readBuffer.append(e),this.processReadBuffer()},this._onerror=e=>{this.onerror?.(e)}}async start(){if(this._started)throw Error(`StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.`);this._started=!0,this._stdin.on(`data`,this._ondata),this._stdin.on(`error`,this._onerror)}processReadBuffer(){for(;;)try{let e=this._readBuffer.readMessage();if(e===null)break;this.onmessage?.(e)}catch(e){this.onerror?.(e)}}async close(){this._stdin.off(`data`,this._ondata),this._stdin.off(`error`,this._onerror),this._stdin.listenerCount(`data`)===0&&this._stdin.pause(),this._readBuffer.clear(),this.onclose?.()}send(e){return new Promise(t=>{let n=Ya(e);this._stdout.write(n)?t():this._stdout.once(`drain`,t)})}};function Za(e){let t=e.scheduler??{setTimeout:(e,t)=>globalThis.setTimeout(e,t),clearTimeout:e=>globalThis.clearTimeout(e)},n=e.initialBackoffMs??1e3,r=e.maxBackoffMs??3e4,i=e.createWebSocket??(e=>new WebSocket(e)),a=e.logger??null,o=e.log,s=null,c=null,l=!1,u=n;function d(e,t,n){try{a?a[e](t,n):o?.(t)}catch{}}function f(){if(l)return;c!==null&&t.clearTimeout(c);let e=u;u=Math.min(u*2,r),d(`debug`,`scheduling reconnect`,{backoffMs:e}),c=t.setTimeout(()=>{c=null,p().catch(e=>d(`warn`,`reconnect failed`,{error:String(e)}))},e)}async function p(){if(l)return;let t;try{t=await e.resolveWsUrl()}catch(e){d(`warn`,`resolveWsUrl threw`,{error:String(e)}),f();return}if(!t){f();return}let r=e.connectionId?`&connectionId=${encodeURIComponent(e.connectionId)}`:``,a=`${t}/collab/keepalive?pid=${process.pid}${r}`;try{s=i(a)}catch(e){d(`warn`,`WebSocket constructor failed`,{url:a,error:String(e)}),s=null,f();return}s.addEventListener(`open`,()=>{d(`info`,`connected`,{url:t}),u=n}),s.addEventListener(`close`,()=>{l||(d(`info`,`disconnected`,{url:t}),s=null,f())}),s.addEventListener(`error`,()=>{d(`debug`,`websocket error observed`,{url:t,readyState:s?.readyState,reason:`error-event`})})}return queueMicrotask(()=>{p().catch(e=>d(`warn`,`initial connect failed`,{error:String(e)}))}),{close:()=>{if(!l&&(l=!0,c!==null&&(t.clearTimeout(c),c=null),s)){try{s.close()}catch{}s=null}},isConnected:()=>s!==null&&s.readyState===1}}function Qa(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 $a(e){if(e===void 0||e===``)return;let t=Number.parseInt(e,10);if(!(Number.isNaN(t)||t<=0))return t}function eo(e){return e===`0.0.0.0`||e===`::`?`localhost`:e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}function to(e,t){return`http://${eo(e)}:${t}/mcp`}function no(e,t){return`ws://${eo(e)}:${t}`}function ro(e){let t=new URL(e);return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.pathname=``,t.search=``,t.hash=``,t.toString().replace(/\/$/,``)}function io(e,t){if(!(!e||e.port<=0)&&t(e.pid))return e.port}function ao(e){return P(e)?F(e,`utf-8`).trim():``}function oo(e,t){return`server did not start within ${e}ms${t?` stderr:\n${t}`:``}`}function so(e){if(e&&typeof e==`object`&&`method`in e&&`id`in e)return e.id}function co(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 lo(e,t){return{jsonrpc:`2.0`,id:e,error:{code:-32e3,message:t instanceof Error?t.message:String(t)}}}async function uo(e){let t=e.readLock??(()=>T(e.lockDir)),n=e.isAlive??E,r=e.sleep??(e=>pt(e)),i=e.spawn??We,a=e.readErrorLog??ao,o=e.openErrorLog??(e=>Qe(e,`w`)),s=e.closeFd??Ye,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 to(`localhost`,t)}let u=io(t(),n);if(u!==void 0)return to(`localhost`,u);if(e.envAutoStart===`0`)throw Error(`Open Knowledge server is not running and OK_MCP_AUTOSTART=0 disables auto-start.`);P(e.lockDir)||Xe(e.lockDir,{recursive:!0});let d=M(e.lockDir,`last-spawn-error.log`),f=o(d),p,m,h=Pe();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=io(t(),n);if(e!==void 0)return to(`localhost`,e)}if(m){let e=a(d),t=e?` stderr:\n${e}`:``;throw Error(`spawn failed: ${m}${t}`)}throw Error(oo(c,a(d)))}function fo(e,t){if(e.portOverride!==void 0)return ro(t);let n=e.readLock??(()=>T(e.lockDir)),r=e.isAlive??E,i=io(n(),r);if(i!==void 0)return no(`localhost`,i)}async function po(e,t={}){let n=t.stderr??process.stderr,r=t.requestTimeoutMs??12e4,i=t.createStdioTransport?t.createStdioTransport(t.stdin,t.stdout):new Xa(t.stdin,t.stdout),a=t.createHttpTransport?t.createHttpTransport(new URL(e)):new Ka(new URL(e),{fetch:Qa(r),...t.connectionId===void 0?{}:{requestInit:{headers:{[xe]:t.connectionId}}}}),o=!1,s=async()=>{o||(o=!0,t.onclose?.(),await Promise.allSettled([i.close(),a.close()]))};i.onerror=e=>{n.write(`[mcp-shim] stdio error: ${e.message}\n`)},a.onerror=e=>{n.write(`[mcp-shim] HTTP transport error: ${e.message}\n`)},i.onclose=()=>{s()},a.onclose=()=>{s()};let c=Promise.resolve();i.onmessage=e=>{c=c.then(async()=>{try{await a.send(e)}catch(t){let r=so(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(lo(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=co(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??po,r=await uo(e),i=e.createConnectionId?.()??dt(),a=!1,o=(e.startKeepalive??Za)({connectionId:i,resolveWsUrl:async()=>fo(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)}function ho(e,t){return t===void 0?!P(N(e,`.ok`)):!1}function go(e){return new t(`mcp`).description(`Start MCP stdio server for project knowledge base`).option(`-p, --port <port>`,`Override port discovery and proxy to this HTTP MCP port`,void 0).action(async t=>{try{let n=e(),r=process.cwd();if(ho(r,t.port)){process.stderr.write(`[mcp] ${r} is not an Open Knowledge project (no .ok/); exiting. Run \`ok init\` to scaffold one.\n`),process.exitCode=1;return}let i=ye(n,r),a=$a(process.env.OK_MCP_SPAWN_TIMEOUT_MS);await mo({lockDir:ge(r),contentDir:i,portOverride:t.port,envAutoStart:process.env.OK_MCP_AUTOSTART,timeoutMs:a})}catch(e){process.stderr.write(`MCP server failed to start: ${e instanceof Error?e.message:String(e)}\n`),process.exitCode=1}})}function _o(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-CFScUs-A.mjs`),r=e(),i=process.cwd(),a=ye(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 yo(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 bo(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:ai(r),command:r,isDesktop:vo(r)}}function xo(e){return e.ui==null?!1:e.ui.status===`alive`||e.ui.status===`foreign-host`}function So(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:t===`dead-pid`&&xo(e)?`ui-orphan`:`stale`}const Co=new Set([`running`,`desktop`,`foreign`,`ui-orphan`]);function wo(e){switch(e){case`running`:return H.default.green(e);case`desktop`:return H.default.blue(e);case`foreign`:return H.default.cyan(e);case`ui-orphan`:return H.default.magenta(e);case`stale`:return H.default.yellow(e)}}function To(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function Eo(e){return`${To(e.server.usage)} | ${To(e.ui?.usage??null)}`}function Do(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null||e.ui.status===`dead-pid`?`—`:String(e.ui.port)}`}function Oo(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=So(e),n=t===`ui-orphan`&&e.ui!=null?e.ui.pid:e.server.pid;return[e.directory,Do(e),Eo(e),t,String(n),yo(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=wo(So(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=H.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
58
+ `}var Xa=class{constructor(e=rt.stdin,t=rt.stdout){this._stdin=e,this._stdout=t,this._readBuffer=new qa,this._started=!1,this._ondata=e=>{this._readBuffer.append(e),this.processReadBuffer()},this._onerror=e=>{this.onerror?.(e)}}async start(){if(this._started)throw Error(`StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.`);this._started=!0,this._stdin.on(`data`,this._ondata),this._stdin.on(`error`,this._onerror)}processReadBuffer(){for(;;)try{let e=this._readBuffer.readMessage();if(e===null)break;this.onmessage?.(e)}catch(e){this.onerror?.(e)}}async close(){this._stdin.off(`data`,this._ondata),this._stdin.off(`error`,this._onerror),this._stdin.listenerCount(`data`)===0&&this._stdin.pause(),this._readBuffer.clear(),this.onclose?.()}send(e){return new Promise(t=>{let n=Ya(e);this._stdout.write(n)?t():this._stdout.once(`drain`,t)})}};function Za(e){let t=e.scheduler??{setTimeout:(e,t)=>globalThis.setTimeout(e,t),clearTimeout:e=>globalThis.clearTimeout(e)},n=e.initialBackoffMs??1e3,r=e.maxBackoffMs??3e4,i=e.createWebSocket??(e=>new WebSocket(e)),a=e.logger??null,o=e.log,s=null,c=null,l=!1,u=n;function d(e,t,n){try{a?a[e](t,n):o?.(t)}catch{}}function f(){if(l)return;c!==null&&t.clearTimeout(c);let e=u;u=Math.min(u*2,r),d(`debug`,`scheduling reconnect`,{backoffMs:e}),c=t.setTimeout(()=>{c=null,p().catch(e=>d(`warn`,`reconnect failed`,{error:String(e)}))},e)}async function p(){if(l)return;let t;try{t=await e.resolveWsUrl()}catch(e){d(`warn`,`resolveWsUrl threw`,{error:String(e)}),f();return}if(!t){f();return}let r=e.connectionId?`&connectionId=${encodeURIComponent(e.connectionId)}`:``,a=`${t}/collab/keepalive?pid=${process.pid}${r}`;try{s=i(a)}catch(e){d(`warn`,`WebSocket constructor failed`,{url:a,error:String(e)}),s=null,f();return}s.addEventListener(`open`,()=>{d(`info`,`connected`,{url:t}),u=n}),s.addEventListener(`close`,()=>{l||(d(`info`,`disconnected`,{url:t}),s=null,f())}),s.addEventListener(`error`,()=>{d(`debug`,`websocket error observed`,{url:t,readyState:s?.readyState,reason:`error-event`})})}return queueMicrotask(()=>{p().catch(e=>d(`warn`,`initial connect failed`,{error:String(e)}))}),{close:()=>{if(!l&&(l=!0,c!==null&&(t.clearTimeout(c),c=null),s)){try{s.close()}catch{}s=null}},isConnected:()=>s!==null&&s.readyState===1}}function Qa(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 $a(e){if(e===void 0||e===``)return;let t=Number.parseInt(e,10);if(!(Number.isNaN(t)||t<=0))return t}function eo(e){return e===`0.0.0.0`||e===`::`?`localhost`:e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}function to(e,t){return`http://${eo(e)}:${t}/mcp`}function no(e,t){return`ws://${eo(e)}:${t}`}function ro(e){let t=new URL(e);return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.pathname=``,t.search=``,t.hash=``,t.toString().replace(/\/$/,``)}function io(e,t){if(!(!e||e.port<=0)&&t(e.pid))return e.port}function ao(e){return P(e)?F(e,`utf-8`).trim():``}function oo(e,t){return`server did not start within ${e}ms${t?` stderr:\n${t}`:``}`}function so(e){if(e&&typeof e==`object`&&`method`in e&&`id`in e)return e.id}function co(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 lo(e,t){return{jsonrpc:`2.0`,id:e,error:{code:-32e3,message:t instanceof Error?t.message:String(t)}}}async function uo(e){let t=e.readLock??(()=>T(e.lockDir)),n=e.isAlive??E,r=e.sleep??(e=>pt(e)),i=e.spawn??We,a=e.readErrorLog??ao,o=e.openErrorLog??(e=>Qe(e,`w`)),s=e.closeFd??Ye,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 to(`localhost`,t)}let u=io(t(),n);if(u!==void 0)return to(`localhost`,u);if(e.envAutoStart===`0`)throw Error(`Open Knowledge server is not running and OK_MCP_AUTOSTART=0 disables auto-start.`);P(e.lockDir)||Xe(e.lockDir,{recursive:!0});let d=M(e.lockDir,`last-spawn-error.log`),f=o(d),p,m,h=Pe();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=io(t(),n);if(e!==void 0)return to(`localhost`,e)}if(m){let e=a(d),t=e?` stderr:\n${e}`:``;throw Error(`spawn failed: ${m}${t}`)}throw Error(oo(c,a(d)))}function fo(e,t){if(e.portOverride!==void 0)return ro(t);let n=e.readLock??(()=>T(e.lockDir)),r=e.isAlive??E,i=io(n(),r);if(i!==void 0)return no(`localhost`,i)}async function po(e,t={}){let n=t.stderr??process.stderr,r=t.requestTimeoutMs??12e4,i=t.createStdioTransport?t.createStdioTransport(t.stdin,t.stdout):new Xa(t.stdin,t.stdout),a=t.createHttpTransport?t.createHttpTransport(new URL(e)):new Ka(new URL(e),{fetch:Qa(r),...t.connectionId===void 0?{}:{requestInit:{headers:{[xe]:t.connectionId}}}}),o=!1,s=async()=>{o||(o=!0,t.onclose?.(),await Promise.allSettled([i.close(),a.close()]))};i.onerror=e=>{n.write(`[mcp-shim] stdio error: ${e.message}\n`)},a.onerror=e=>{n.write(`[mcp-shim] HTTP transport error: ${e.message}\n`)},i.onclose=()=>{s()},a.onclose=()=>{s()};let c=Promise.resolve();i.onmessage=e=>{c=c.then(async()=>{try{await a.send(e)}catch(t){let r=so(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(lo(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=co(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??po,r=await uo(e),i=e.createConnectionId?.()??dt(),a=!1,o=(e.startKeepalive??Za)({connectionId:i,resolveWsUrl:async()=>fo(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)}function ho(e,t){return t===void 0?!P(N(e,`.ok`)):!1}function go(e){return new t(`mcp`).description(`Start MCP stdio server for project knowledge base`).option(`-p, --port <port>`,`Override port discovery and proxy to this HTTP MCP port`,void 0).action(async t=>{try{let n=e(),r=process.cwd();if(ho(r,t.port)){process.stderr.write(`[mcp] ${r} is not an Open Knowledge project (no .ok/); exiting. Run \`ok init\` to scaffold one.\n`),process.exitCode=1;return}let i=ye(n,r),a=$a(process.env.OK_MCP_SPAWN_TIMEOUT_MS);await mo({lockDir:ge(r),contentDir:i,portOverride:t.port,envAutoStart:process.env.OK_MCP_AUTOSTART,timeoutMs:a})}catch(e){process.stderr.write(`MCP server failed to start: ${e instanceof Error?e.message:String(e)}\n`),process.exitCode=1}})}function _o(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-C8UFVYvI.mjs`),r=e(),i=process.cwd(),a=ye(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 yo(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 bo(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:ai(r),command:r,isDesktop:vo(r)}}function xo(e){return e.ui==null?!1:e.ui.status===`alive`||e.ui.status===`foreign-host`}function So(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:t===`dead-pid`&&xo(e)?`ui-orphan`:`stale`}const Co=new Set([`running`,`desktop`,`foreign`,`ui-orphan`]);function wo(e){switch(e){case`running`:return H.default.green(e);case`desktop`:return H.default.blue(e);case`foreign`:return H.default.cyan(e);case`ui-orphan`:return H.default.magenta(e);case`stale`:return H.default.yellow(e)}}function To(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function Eo(e){return`${To(e.server.usage)} | ${To(e.ui?.usage??null)}`}function Do(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null||e.ui.status===`dead-pid`?`—`:String(e.ui.port)}`}function Oo(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=So(e),n=t===`ui-orphan`&&e.ui!=null?e.ui.pid:e.server.pid;return[e.directory,Do(e),Eo(e),t,String(n),yo(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=wo(So(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=H.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
59
59
  `)}async function ko(e={}){let t=e.discover??ui,n=e.inspect??B,r=e.log??(e=>console.log(e)),i=e.resolveCommand??oi,a=e.resolveUsage??si,o=await t(),s=[];for(let e of o){let t=n(e,`server`),r=n(e,`ui`),o=bo(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:So(e)}));r(JSON.stringify(e,null,2));return}r(Oo(e.all?s:s.filter(e=>Co.has(So(e)))))}function Ao(){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 ko({all:t.all===!0||e===`all`,json:t.json===!0})})}function Y(e,t){e&&process.stdout.write(`${JSON.stringify(t)}\n`)}async function jo(e,t,n=process.cwd()){let r=e.op??`sync`,i=T(Oe(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}`)}Y(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=pe({baseDir:n});if(r===`sync`||r===`pull`){Y(e.json,{type:`step`,step:`pull`});let t=await a.pull();Y(e.json,{type:`pull`,summary:t.summary}),e.json||process.stderr.write(` pull: ${t.summary.changes} changes\n`)}(r===`sync`||r===`push`)&&(Y(e.json,{type:`step`,step:`push`}),await a.push(),Y(e.json,{type:`push`,ok:!0}),e.json||process.stderr.write(` push: ok
60
60
  `)),Y(e.json,{type:`complete`,op:r}),e.json||process.stderr.write(`✓ ${r} complete\n`)}function Mo(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 jo({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 No(e){return new t(`pull`).description(`Pull changes from the remote`).option(`--json`,`Output JSONL progress events`,!1).action(async t=>{try{await jo({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 Po(e){return new t(`push`).description(`Push commits to the remote`).option(`--json`,`Output JSONL progress events`,!1).action(async t=>{try{await jo({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)}})}async function Fo(e={}){let t=N(e.cwd??process.cwd()),n;try{n=await Ce({projectDir:t,rootDir:e.root})}catch(e){return e instanceof he?{status:`prerequisite-missing`,message:`${He(`Error:`)} ${e.message}`,exitCode:1}:{status:`failed`,message:`${He(`Error:`)} ${e instanceof Error?e.message:String(e)}`,exitCode:1}}if(n.created.length===0)return{status:`no-op`,message:`${O(`Your knowledge base is already seeded.`)}\n${D(`Nothing to do.`)}`,plan:n,exitCode:0};if(e.dryRun)return{status:`dry-run`,message:`${A(`Plan (dry-run — no changes made):`)}\n\n${Io(n,t)}`,plan:n,exitCode:0};if(!e.yes&&!await Lo(`${A(`Plan:`)}\n\n${Io(n,t)}\n\n${A(`Apply?`)} ${D(`[Y/n] `)}`,e.confirmStream))return{status:`cancelled`,message:D(`Cancelled.`),plan:n,exitCode:0};let r=await _e(n,{projectDir:t});if(r.errors.length>0){let e=r.errors.map(e=>` ${He(`✗`)} ${e.path}: ${e.error}`);return{status:`failed`,message:[`${k(`Applied`)} ${r.applied} entries, ${k(String(r.errors.length))} error(s):`,...e].join(`
61
61
  `),plan:n,exitCode:1}}return{status:`applied`,message:`${O(`✓ Seeded knowledge base`)} ${D(`(${r.applied} entries, ${r.durationMs}ms)`)}`,plan:n,exitCode:0}}function Io(e,t){let n=[],r=e.created.filter(e=>e.kind===`folder`),i=e.created.filter(e=>e.kind===`file`);if(r.length>0){n.push(A(`Folders to create:`));for(let e of r)n.push(` ${O(`+`)} ${Ve(Je(t,N(t,e.path))||e.path)}${D(`/`)}`)}if(i.length>0){n.length>0&&n.push(``),n.push(A(`Files to create:`));for(let e of i)n.push(` ${O(`+`)} ${Ve(Je(t,N(t,e.path))||e.path)}`)}if(e.skipped.length>0){n.length>0&&n.push(``),n.push(D(`Already present (skipped):`));for(let t of e.skipped)n.push(` ${D(`· ${t.path} (${t.reason})`)}`)}if(e.warnings.length>0){n.length>0&&n.push(``),n.push(k(`Warnings:`));for(let t of e.warnings)n.push(` ${k(`!`)} ${t}`)}return n.join(`
@@ -0,0 +1,2 @@
1
+ import"./dist-IguRFGXq.mjs";var e=`0.4.0-beta.24`;const t=`config.yml`,n=e;export{n,t};
2
+ //# sourceMappingURL=constants-CZmHtQUh.mjs.map
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{c as e,d as t,f as n,i as r,l as i,p as a,t as o,u as s}from"./init-ngbjAPEx.mjs";import{t as c}from"./loader-CJa2PwIk.mjs";import{n as l}from"./preview-g-B-YX9w.mjs";import{t as u}from"./src-BlDqmpar.mjs";export{s as ALL_EDITOR_IDS,t as EDITOR_TARGETS,o as detectInstalledEditors,a as initContent,c as loadConfig,l as previewContent,r as readExistingMcpEntry,n as resolveProjectRoot,e as writeEditorMcpConfig,u as writeProjectAiIntegrations,i as writeUserMcpConfigs};
1
+ import{c as e,d as t,f as n,i as r,l as i,p as a,t as o,u as s}from"./init-CMfH982u.mjs";import{t as c}from"./loader-DvG1wpAx.mjs";import{n as l}from"./preview-DgYoFNt8.mjs";import{t as u}from"./src-Bdc8vmx9.mjs";export{s as ALL_EDITOR_IDS,t as EDITOR_TARGETS,o as detectInstalledEditors,a as initContent,c as loadConfig,l as previewContent,r as readExistingMcpEntry,n as resolveProjectRoot,e as writeEditorMcpConfig,u as writeProjectAiIntegrations,i as writeUserMcpConfigs};
@@ -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{er as a,nr as o}from"./dist-IguRFGXq.mjs";import{Dn as s,E as c,Et as l,M as u,Ot as d,qt as f}from"./dist-DSb6dRAy.mjs";import{n as p,t as m}from"./constants-D-Kk6PDS.mjs";import{t as h}from"./is-object-DF0ZeuvD.mjs";import{i as g,o as _,r as v,s as y,t as b}from"./colors-BNufdynn.mjs";import{t as x}from"./preview-g-B-YX9w.mjs";import{execFileSync as S}from"node:child_process";import ee,{basename as te,dirname as C,isAbsolute as ne,join as w,posix as T,relative as E,resolve as D,sep as O,win32 as re}from"node:path";import{cpSync as ie,existsSync as k,lstatSync as ae,mkdirSync as A,readFileSync as j,realpathSync as oe,rmSync as se,writeFileSync as M}from"node:fs";import N from"node:process";import{homedir as P}from"node:os";import{AsyncLocalStorage as ce,AsyncResource as le}from"node:async_hooks";import{stripVTControlCharacters as ue,styleText as F}from"node:util";import*as de from"node:readline";function fe(){return N.platform.startsWith(`win`)?!!N.env.CI||!!N.env.WT_SESSION||!!N.env.TERMINUS_SUBLIME||N.env.ConEmuTask===`{cmd::Cmder}`||N.env.TERM_PROGRAM===`Terminus-Sublime`||N.env.TERM_PROGRAM===`vscode`||N.env.TERM===`xterm-256color`||N.env.TERM===`alacritty`||N.env.TERMINAL_EMULATOR===`JetBrains-JediTerm`:N.env.TERM!==`linux`}const pe={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:`╱`},me={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:`⅒`},he={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`},ge={...pe,...me},_e={...pe,...he},I=fe()?ge:_e;Object.entries(me);var ve=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 ye=(()=>{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}})(),be=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,xe=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,Se=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Ce=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,we=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,Te=/\t{1,1000}/y,Ee=/[\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,De=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Oe=/\p{M}+/gu,ke={limit:1/0,ellipsis:``},Ae=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?Ae(i,ke,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[De,l],[Se,0],[Ce,o],[Te,s],[Ee,c],[we,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(Oe,``)){let t=e.codePointAt(0)||0;if(S=be(t)?2:xe(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===we?ye(e.slice(p,n.lastIndex)):n===Ee?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}},je={limit:1/0,ellipsis:``,ellipsisWidth:0},L=(e,t={})=>Ae(e,je,t).width,Me=`]8;;`,Ne=RegExp(`(?:\\[(?<code>\\d+)m|\\${Me}(?<uri>.*))`,`y`),Pe=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},Fe=e=>`[${e}m`,Ie=e=>`${Me}${e}`,Le=(e,t,n)=>{let r=t[Symbol.iterator](),i=!1,a=!1,o=e.at(-1),s=o===void 0?0:L(o),c=r.next(),l=r.next(),u=0;for(;!c.done;){let o=c.value,d=L(o);s+d<=n?e[e.length-1]+=o:(e.push(o),s=0),(o===`\x1B`||o===`›`)&&(i=!0,a=t.startsWith(Me,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())},Re=e=>{let t=e.split(` `),n=t.length;for(;n&&!L(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},ze=(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=L(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=L(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(``),Le(s,r,t),c=L(s.at(-1)??``);continue}if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){Le(s,r,t),c=L(s.at(-1)??``);continue}s.push(``),c=0}if(c+i>t&&n.wordWrap===!1){Le(s,r,t),c=L(s.at(-1)??``);continue}s[s.length-1]+=r,c+=i}n.trim!==!1&&(s=s.map(e=>Re(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{er as a,nr as o}from"./dist-IguRFGXq.mjs";import{Dn as s,E as c,Et as l,M as u,Ot as d,qt as f}from"./dist-DSb6dRAy.mjs";import{n as p,t as m}from"./constants-CZmHtQUh.mjs";import{t as h}from"./is-object-DF0ZeuvD.mjs";import{i as g,o as _,r as v,s as y,t as b}from"./colors-BNufdynn.mjs";import{t as x}from"./preview-DgYoFNt8.mjs";import{execFileSync as S}from"node:child_process";import ee,{basename as te,dirname as C,isAbsolute as ne,join as w,posix as T,relative as E,resolve as D,sep as O,win32 as re}from"node:path";import{cpSync as ie,existsSync as k,lstatSync as ae,mkdirSync as A,readFileSync as j,realpathSync as oe,rmSync as se,writeFileSync as M}from"node:fs";import N from"node:process";import{homedir as P}from"node:os";import{AsyncLocalStorage as ce,AsyncResource as le}from"node:async_hooks";import{stripVTControlCharacters as ue,styleText as F}from"node:util";import*as de from"node:readline";function fe(){return N.platform.startsWith(`win`)?!!N.env.CI||!!N.env.WT_SESSION||!!N.env.TERMINUS_SUBLIME||N.env.ConEmuTask===`{cmd::Cmder}`||N.env.TERM_PROGRAM===`Terminus-Sublime`||N.env.TERM_PROGRAM===`vscode`||N.env.TERM===`xterm-256color`||N.env.TERM===`alacritty`||N.env.TERMINAL_EMULATOR===`JetBrains-JediTerm`:N.env.TERM!==`linux`}const pe={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:`╱`},me={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:`⅒`},he={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`},ge={...pe,...me},_e={...pe,...he},I=fe()?ge:_e;Object.entries(me);var ve=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 ye=(()=>{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}})(),be=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,xe=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,Se=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Ce=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,we=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,Te=/\t{1,1000}/y,Ee=/[\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,De=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Oe=/\p{M}+/gu,ke={limit:1/0,ellipsis:``},Ae=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?Ae(i,ke,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[De,l],[Se,0],[Ce,o],[Te,s],[Ee,c],[we,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(Oe,``)){let t=e.codePointAt(0)||0;if(S=be(t)?2:xe(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===we?ye(e.slice(p,n.lastIndex)):n===Ee?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}},je={limit:1/0,ellipsis:``,ellipsisWidth:0},L=(e,t={})=>Ae(e,je,t).width,Me=`]8;;`,Ne=RegExp(`(?:\\[(?<code>\\d+)m|\\${Me}(?<uri>.*))`,`y`),Pe=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},Fe=e=>`[${e}m`,Ie=e=>`${Me}${e}`,Le=(e,t,n)=>{let r=t[Symbol.iterator](),i=!1,a=!1,o=e.at(-1),s=o===void 0?0:L(o),c=r.next(),l=r.next(),u=0;for(;!c.done;){let o=c.value,d=L(o);s+d<=n?e[e.length-1]+=o:(e.push(o),s=0),(o===`\x1B`||o===`›`)&&(i=!0,a=t.startsWith(Me,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())},Re=e=>{let t=e.split(` `),n=t.length;for(;n&&!L(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},ze=(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=L(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=L(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(``),Le(s,r,t),c=L(s.at(-1)??``);continue}if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){Le(s,r,t),c=L(s.at(-1)??``);continue}s.push(``),c=0}if(c+i>t&&n.wordWrap===!1){Le(s,r,t),c=L(s.at(-1)??``);continue}s[s.length-1]+=r,c+=i}n.trim!==!1&&(s=s.map(e=>Re(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===`›`){Ne.lastIndex=e+1;let t=Ne.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+=Ie(``));let e=i?Pe(i):void 0;i&&e&&(r+=Fe(e))}else t===`
4
4
  `&&(i&&Pe(i)&&(r+=Fe(i)),a&&(r+=Ie(a)))}return r},Be=/\r?\n/;function Ve(e,t,n){return String(e).normalize().split(Be).map(e=>ze(e,t,n)).join(`
@@ -404,5 +404,5 @@ last-spawn-error.log
404
404
  `)?n:`${n}\n`,`utf-8`)}function sr(e,t){let n;try{n=oe(t)}catch{n=D(t)}let r;try{r=ae(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=C(e);for(;i.length>1&&i!==O;){let t;try{t=oe(i)}catch(e){if(e.code===`ENOENT`){i=C(i);continue}throw e}let r=E(n,t);if(r===``||!r.startsWith(`..`)&&!ne(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 cr=e=>e!==`project`,lr=e=>e!==`user`;async function ur(){let e=await tn({message:`Where should the MCP server be configured?
405
405
  `,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 dr(e){return e.mcp===!1?null:e.scope?e.scope:e.isTTY??process.stdout.isTTY?(e.promptFn??ur)():`both`}const fr=`0.0.1`,pr=`open-knowledge-ui`;function mr(e,t={}){let n=w(e,`.claude`,`launch.json`),r=t.mode===`dev`?{name:pr,runtimeExecutable:`node`,runtimeArgs:[qn(),`ui`],port:3e3}:{name:pr,runtimeExecutable:`npx`,runtimeArgs:[`@inkeep/open-knowledge`,`ui`],port:3e3};try{if(sr(n,e),!k(n))return A(C(n),{recursive:!0}),M(n,`${JSON.stringify({version:fr,configurations:[r]},null,2)}\n`,`utf-8`),{action:`created`,configPath:n};let t=j(n,`utf-8`).trim(),i=t?JSON.parse(t):{};if(!h(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=>h(e)&&e.name===pr);o>=0?a[o]=r:a.push(r);let s={...i,version:i.version??fr,configurations:a};return M(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 hr(e,t,n){try{return k(e.detectPath?.(t,n)??C(e.configPath(t,n)))}catch{return!1}}function $(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&&!hr(e,t,r))return{editorId:e.id,label:e.label,action:`skipped-missing`,configPath:o,serverName:a};if(i!==void 0)try{sr(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`?ir(o):rr(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`?or(o,d):ar(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 gr(e,t){let n=e.projectSkillPath?.(t);if(!n)return{editorId:e.id,label:e.label,action:`skipped-unsupported`,path:``};try{let r=s(),i=C(n);sr(i,t);let a=k(n)?`overwritten`:`written`;return se(i,{recursive:!0,force:!0}),A(C(i),{recursive:!0}),ie(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 _r(e,t){let n=e.projectConfigPath?.(t);if(!(!n||!k(n)))return{editorId:e.id,label:e.label,path:n}}async function vr(e){let t=nr(e.editors),n={mode:`published`,cliPath:e.cliPath,skipAvailabilityCheck:!0};return t.map(t=>$(t,``,n,e.home))}function yr(e,t,n){let r;try{r=e.configPath(t,n)}catch{return null}let i;try{i=e.format===`toml`?ir(r):rr(r)}catch{return null}let a=i[e.topLevelKey];if(!h(a))return null;let o=a[e.serverName(t)];return h(o)?o:null}async function br(e={}){let t=Wn(D(e.cwd??process.cwd()),{homeDir:e.home}),n=t.projectRoot,r=!k(w(n,`.ok`));t.ancestorPromoted?console.log(`[ok] Opened existing project at ${n}`):t.gitRootPromoted&&r&&console.log(`[ok] Initialized OK at ${n} (scoped to ${t.defaultContentDir}/)`);let i={mode:e.devMcp?`dev`:`published`},a=await d(n),o;try{o=Vn(n,{contentDir:t.defaultContentDir})}catch(t){let r=Q.claude.configPath(n,e.home);return{projectRoot:n,contentCreated:[],contentUpdated:[],contentSkipped:[],editors:[],projectSkills:[],legacyProjectConfigs:[],didGitInit:a.didInit,claudeDesktopDetected:!1,mcpAction:`failed`,mcpPath:r,mcpError:`Content scaffolding failed: ${t instanceof Error?t.message:String(t)}`}}let s=await dr({scope:e.scope,mcp:e.mcp,isTTY:e.isTTY,promptFn:e.promptFn}),c=e.editors??Sr(n,e.home),u=e.editors??J.filter(e=>Q[e].projectConfigPath!==void 0),p=nr(c),m=nr(u),h=e.mcp===!1||s===null,g=Array.from(new Map([...p,...h?[]:m].map(e=>[e.id,e])).values()),_=p.filter(t=>hr(t,n,e.home)),v=[],y=[],b=new Set;for(let t of g){if(h){let r=``;try{r=t.configPath(n,e.home)}catch{}v.push({editorId:t.id,label:t.label,action:`skipped-flag`,configPath:r,serverName:t.serverName(n)});continue}if(cr(s)&&p.includes(t)&&v.push($(t,n,i,e.home)),lr(s)&&m.includes(t)&&t.projectConfigPath){let r=t.projectConfigPath(n),a=$(t,n,i,e.home,r);v.push(a),(a.action===`written`||a.action===`overwritten`)&&(b.add(r),y.push(gr(t,n)))}}let x=!h&&s!==null&&lr(s)?m.filter(e=>!e.projectConfigPath).map(e=>e.label):void 0,S=h?[]:_.map(e=>_r(e,n)).filter(e=>e!==void 0).filter(e=>!b.has(e.path)),ee=_.some(e=>e.id===`claude`)&&!h?mr(n,i):void 0,te=await(e.installUserSkill??f)({home:e.home}),C=l({home:e.home}),ne=h?`skipped-flag`:`skipped-missing`,T=v.find(e=>e.editorId===`claude`)??v[0]??{action:ne,configPath:Q.claude.configPath(n,e.home)};return{projectRoot:n,contentCreated:o.created,contentUpdated:o.updated,contentSkipped:o.skipped,editors:v,projectSkills:y,legacyProjectConfigs:S,launchJson:ee,skillInstall:te,didGitInit:a.didInit,claudeDesktopDetected:C,mcpAction:T.action,mcpPath:T.configPath,mcpError:`error`in T?T.error:void 0,projectScopeUnsupportedLabels:x}}function xr(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)?E(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=w(t,`.ok`);if(e.contentCreated.length>0||e.contentUpdated.length>0?(n.push(b(`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(b(`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(b(`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(b(`MCP server configuration:`)),n.push(` No supported editor config directories detected; skipped MCP registration`);else{n.push(b(`MCP server configuration:`));for(let r of e.editors){let i=r.configPath.startsWith(t)?E(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} ${_(`registered`)}${a}${u}`);break;case`overwritten`:n.push(` ${c}${l}${i} ${_(`updated`)}${a}${u}`);break;case`skipped-missing`:n.push(` ${c}${l}${i} config root missing; skipped`);break;case`failed`:n.push(` ${c}${l}${i} ${v(`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(b(`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?E(t,r.path):``;switch(r.action){case`written`:n.push(` ${e}${i}${a} ${_(`installed`)}`);break;case`overwritten`:n.push(` ${e}${i}${a} ${_(`updated`)}`);break;case`skipped-unsupported`:n.push(` ${e}${i}no known project skill surface; skipped`);break;case`failed`:n.push(` ${e}${i}${a} ${v(`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} ${E(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(b(`User-global skill:`)),e.skillInstall){case`installed`:n.push(` open-knowledge ${_(`installed to detected agent hosts`)} via \`npx skills\``);break;case`skip-current`:n.push(` open-knowledge ${_(`already installed at current version`)}`);break;case`failed`:n.push(` ${y(`open-knowledge install failed — MCP still configured; run manually:`)}`),n.push(` ${y(` 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: ${b(`ok install-skill`)}`)),e.preview?(n.push(``),n.push(x(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(`${_(`✓`)} ${b(`Next steps:`)}`),n.push(` 1. Open your editor (${g(r.join(` / `))})`),n.push(` 2. Approve the MCP server when prompted`),n.push(` 3. (Optional) scaffold the starter knowledge-base structure:`),n.push(` - ${g(`ok seed`)}`),n.push(` 4. Use the three MCP workflow tools as you build the wiki:`),n.push(` - ${g(`mcp__open-knowledge__ingest`)} — capture an external source`),n.push(` - ${g(`mcp__open-knowledge__research`)} — gather sources and write findings`),n.push(` - ${g(`mcp__open-knowledge__consolidate`)} — promote research to canonical articles`)}return n.join(`
406
406
  `)}function Sr(e,t){let n=[];for(let r of J)hr(Q[r],e,t)&&n.push(r);return n}function Cr(){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 br({cwd:t,mcp:e.mcp,devMcp:e.devMcp,scope:e.scope})}catch(e){if(e instanceof u){process.stderr.write(`open-knowledge requires git to initialize a parent repo. Install git or run 'git init' yourself, then re-run.
407
- `),e.stderr&&process.stderr.write(`${e.stderr.trim()}\n`),process.exitCode=1;return}throw e}try{let{previewContent:e}=await import(`./preview-CFScUs-A.mjs`),{loadConfig:t}=await import(`./loader-BKJCUkvm.mjs`),{resolveContentDir:r}=await import(`./dist-BT7_1SJl.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(`${xr(n,n.projectRoot)}\n`),(n.editors.some(e=>e.action===`failed`)||n.mcpAction===`failed`)&&(process.exitCode=1)})}export{ve as C,Ve as S,ot as _,dr as a,$e as b,$ as c,Q as d,Wn as f,rt as g,nt as h,yr as i,vr as l,at as m,xr as n,br as o,Vn as p,Cr as r,mr as s,Sr as t,J as u,it as v,I as w,He as x,ct as y};
408
- //# sourceMappingURL=init-ngbjAPEx.mjs.map
407
+ `),e.stderr&&process.stderr.write(`${e.stderr.trim()}\n`),process.exitCode=1;return}throw e}try{let{previewContent:e}=await import(`./preview-C8UFVYvI.mjs`),{loadConfig:t}=await import(`./loader-C9UcssXM.mjs`),{resolveContentDir:r}=await import(`./dist-BT7_1SJl.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(`${xr(n,n.projectRoot)}\n`),(n.editors.some(e=>e.action===`failed`)||n.mcpAction===`failed`)&&(process.exitCode=1)})}export{ve as C,Ve as S,ot as _,dr as a,$e as b,$ as c,Q as d,Wn as f,rt as g,nt as h,yr as i,vr as l,at as m,xr as n,br as o,Vn as p,Cr as r,mr as s,Sr as t,J as u,it as v,I as w,He as x,ct as y};
408
+ //# sourceMappingURL=init-CMfH982u.mjs.map
@@ -0,0 +1 @@
1
+ import{o as e}from"./init-CMfH982u.mjs";export{e as runInit};
@@ -0,0 +1 @@
1
+ import{t as e}from"./loader-DvG1wpAx.mjs";export{e as loadConfig};
@@ -1,4 +1,4 @@
1
- import{Nn as e,ar as t,qr as n}from"./dist-IguRFGXq.mjs";import{f as r,mr as i}from"./dist-DSb6dRAy.mjs";import{t as a}from"./constants-D-Kk6PDS.mjs";import{t as o}from"./is-object-DF0ZeuvD.mjs";import{resolve as s}from"node:path";import{existsSync as c,readFileSync as l}from"node:fs";import{homedir as u}from"node:os";var d=n();function f(e,t){let n={...e};for(let r of Object.keys(t)){let i=e[r],a=t[r];o(a)&&o(i)?n[r]=f(i,a):a!==void 0&&(n[r]=a)}return n}function p(e){if(!c(e))return{value:null,path:e,source:null,doc:null};let t;try{t=l(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,d.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 o(r)?{value:r,path:e,source:t,doc:n}:{value:null,path:e,source:t,doc:n}}const m=[`include`,`exclude`];function h(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 g(e){let n=e.value;if(!o(n))return[];let r=n.content;if(!o(r))return[];let i=[];for(let n of m)if(n in r){let r=[`content`,n],a;e.doc!==null&&e.source!==null&&(a=t({file:e.path,source:e.source,doc:e.doc,path:r})),i.push({code:`REMOVED_KEY`,path:r,redirect:h(n),...a===void 0?{}:{source:a}})}return i}function _(e,n){return e.map(e=>{let r=e.path.map(e=>typeof e==`symbol`?String(e):e),i={path:r,message:e.message,issueCode:e.code};if(n.doc!==null&&n.source!==null){let e=t({file:n.path,source:n.source,doc:n.doc,path:r});if(e!==void 0)return{...i,source:e}}return i})}function v(t){let n=t??process.cwd(),o=[],c=s(u(),`.ok`,a),l=i({absPath:c}),d={};l.valid&&l.source!==void 0?(d=f(d,l.value),o.push(c)):l.valid;let m=s(n,`.ok`,a),h=p(m);if(h.value!==null){let t=g(h);if(t.length>0)throw Error(t.map(e).join(`
1
+ import{Nn as e,ar as t,qr as n}from"./dist-IguRFGXq.mjs";import{f as r,mr as i}from"./dist-DSb6dRAy.mjs";import{t as a}from"./constants-CZmHtQUh.mjs";import{t as o}from"./is-object-DF0ZeuvD.mjs";import{resolve as s}from"node:path";import{existsSync as c,readFileSync as l}from"node:fs";import{homedir as u}from"node:os";var d=n();function f(e,t){let n={...e};for(let r of Object.keys(t)){let i=e[r],a=t[r];o(a)&&o(i)?n[r]=f(i,a):a!==void 0&&(n[r]=a)}return n}function p(e){if(!c(e))return{value:null,path:e,source:null,doc:null};let t;try{t=l(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,d.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 o(r)?{value:r,path:e,source:t,doc:n}:{value:null,path:e,source:t,doc:n}}const m=[`include`,`exclude`];function h(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 g(e){let n=e.value;if(!o(n))return[];let r=n.content;if(!o(r))return[];let i=[];for(let n of m)if(n in r){let r=[`content`,n],a;e.doc!==null&&e.source!==null&&(a=t({file:e.path,source:e.source,doc:e.doc,path:r})),i.push({code:`REMOVED_KEY`,path:r,redirect:h(n),...a===void 0?{}:{source:a}})}return i}function _(e,n){return e.map(e=>{let r=e.path.map(e=>typeof e==`symbol`?String(e):e),i={path:r,message:e.message,issueCode:e.code};if(n.doc!==null&&n.source!==null){let e=t({file:n.path,source:n.source,doc:n.doc,path:r});if(e!==void 0)return{...i,source:e}}return i})}function v(t){let n=t??process.cwd(),o=[],c=s(u(),`.ok`,a),l=i({absPath:c}),d={};l.valid&&l.source!==void 0?(d=f(d,l.value),o.push(c)):l.valid;let m=s(n,`.ok`,a),h=p(m);if(h.value!==null){let t=g(h);if(t.length>0)throw Error(t.map(e).join(`
2
2
 
3
3
  `));d=f(d,h.value),o.push(m)}y(d,[`upload`,`maxBytes`],`streaming uploads have no user-facing cap`),y(d,[`github`,`oauthAppClientId`],`use the OPEN_KNOWLEDGE_GITHUB_CLIENT_ID env var instead`),y(d,[`server`,`host`],`use the --host flag or HOST env var instead`),y(d,[`server`,`openOnAgentEdit`]),y(d,[`mcp`,`autoStart`],`to disable auto-start, set OK_MCP_AUTOSTART=0`),y(d,[`mcp`,`tools`,`read_document`,`historyDepth`]),y(d,[`mcp`,`tools`,`grep`,`maxResults`]),y(d,[`mcp`,`tools`,`search`,`maxResults`]);let v=r.safeParse(d);if(!v.success){let t={code:`SCHEMA_INVALID`,issues:_(v.error.issues,h)};throw Error(e(t))}return{config:v.data,sources:o}}function y(e,t,n){let r=e;for(let e=0;e<t.length-1;e++){if(!o(r))return;r=r[t[e]]}if(!o(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.`)}export{v as t};
4
- //# sourceMappingURL=loader-CJa2PwIk.mjs.map
4
+ //# sourceMappingURL=loader-DvG1wpAx.mjs.map
@@ -0,0 +1 @@
1
+ import{n as e,t}from"./preview-DgYoFNt8.mjs";export{t as formatPreviewBlock,e as previewContent};
@@ -1,3 +1,3 @@
1
- import{ht as e}from"./dist-DSb6dRAy.mjs";import"./constants-D-Kk6PDS.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{ht as e}from"./dist-DSb6dRAy.mjs";import"./constants-CZmHtQUh.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-g-B-YX9w.mjs.map
3
+ //# sourceMappingURL=preview-DgYoFNt8.mjs.map
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ActivityPanelDiffView-DeDaG2lq.js","./chunk-CFjPhJqf.js","./compiler-runtime-CVnuRdak.js","./ActivityPanelDiffView-legcy4jI.css"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./preload-helper-2ej06EnG.js";import{n,r,t as i}from"./compiler-runtime-CVnuRdak.js";import{Dt as a,U as o,W as s,p as c}from"./doc-hash-Bch8gJGz.js";import{C as l,t as u}from"./button-BsFpqlpT.js";import{Wt as d,Z as f,an as p,in as m,n as h,on as g,r as _}from"./DocumentContext-CKzRBTvD.js";import{f as v,i as y,m as b,r as x,t as S}from"./agent-presence-Ds2n3U5P.js";import{p as C}from"./dist-Dy1vgWd7.js";import{i as w,n as T,t as E}from"./tooltip-CONp_Pmy.js";import{a as D,c as O,i as k,o as ee,s as te,t as ne}from"./dialog-CKgDyF3E.js";var re=l(`rewind`,[[`path`,{d:`M12 6a2 2 0 0 0-3.414-1.414l-6 6a2 2 0 0 0 0 2.828l6 6A2 2 0 0 0 12 18z`,key:`2a1g8i`}],[`path`,{d:`M22 6a2 2 0 0 0-3.414-1.414l-6 6a2 2 0 0 0 0 2.828l6 6A2 2 0 0 0 22 18z`,key:`rg3s36`}]]),A=i(),j=e(n(),1),ie=500,ae=64;async function oe(e){let t=`/api/agent-activity?agentId=${encodeURIComponent(e)}`,n=await fetch(t),r;try{r=await n.json()}catch(e){throw new f(`Could not parse /api/agent-activity response.`,{cause:e,status:n.status})}if(!n.ok){let e=a.safeParse(r);throw e.success?Error(e.data.title):new f(`/api/agent-activity returned a non-RFC-9457 error response.`,{cause:e.error,status:n.status})}let i=o.safeParse(r);if(!i.success)throw new f(`/api/agent-activity returned a body that did not match AgentActivitySuccessSchema.`,{cause:i.error,status:n.status});return i.data}async function se(e,t,n){let r=`/api/agent-burst-diff?agentId=${encodeURIComponent(e)}&docName=${encodeURIComponent(t)}&stackIndex=${n}`,i=await fetch(r),o;try{o=await i.json()}catch(e){throw new f(`Could not parse /api/agent-burst-diff response.`,{cause:e,status:i.status})}if(!i.ok){let e=a.safeParse(o);throw e.success?Error(e.data.title):new f(`/api/agent-burst-diff returned a non-RFC-9457 error response.`,{cause:e.error,status:i.status})}let c=s.safeParse(o);if(!c.success)throw new f(`/api/agent-burst-diff returned a body that did not match AgentBurstDiffSuccessSchema.`,{cause:c.error,status:i.status});return c.data.diff}function ce(e){let t=(0,A.c)(23),{systemProvider:n}=h(),[r,i]=(0,j.useState)(null),[a,o]=(0,j.useState)(`idle`),[s,l]=(0,j.useState)(null),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=new y(ae),t[0]=u):u=t[0];let d=(0,j.useRef)(u),f=(0,j.useRef)(0),p;t[1]===n?p=t[2]:(p=e=>{let t=f.current+=1;o(`loading`),l(null),oe(e).then(r=>{if(f.current!==t)return;let a=ue(n,e);i({...r,writingDocs:a}),o(`ready`)}).catch(e=>{f.current===t&&(l(e instanceof Error?e.message:String(e)),o(`error`))})},t[1]=n,t[2]=p);let m=p,g;t[3]!==e||t[4]!==m?(g=()=>{if(!e){f.current+=1,i(null),o(`idle`),l(null),d.current.clear();return}d.current.clear(),m(e);let t=null,n=c(n=>{n.includes(`session-activity`)&&(t&&clearTimeout(t),t=setTimeout(()=>{t=null,m(e)},ie))});return()=>{t&&clearTimeout(t),n()}},t[3]=e,t[4]=m,t[5]=g):g=t[5];let _;t[6]===e?_=t[7]:(_=[e],t[6]=e,t[7]=_),(0,j.useEffect)(g,_);let v,b;t[8]!==e||t[9]!==n?(v=()=>{if(!e||!n)return;let t=()=>{if(!n.awareness)return;let t=ue(n,e);i(e=>!e||le(e.writingDocs,t)?e:{...e,writingDocs:t})},r=n.awareness;if(!r||typeof r.on!=`function`){t();return}r.on(`update`,t),t();let a=setInterval(t,1e3);return()=>{clearInterval(a),typeof r.off==`function`&&r.off(`update`,t)}},b=[e,n],t[8]=e,t[9]=n,t[10]=v,t[11]=b):(v=t[10],b=t[11]),(0,j.useEffect)(v,b);let x;t[12]===e?x=t[13]:(x=async(t,n)=>{if(!e)return``;let r=`${t}\0${n}`,i=d.current.get(r);if(i!==void 0)return i;let a=await se(e,t,n);return d.current.set(r,a),a},t[12]=e,t[13]=x);let S=x,C;t[14]!==e||t[15]!==m?(C=()=>{e&&m(e)},t[14]=e,t[15]=m,t[16]=C):C=t[16];let w=C,T;return t[17]!==r||t[18]!==s||t[19]!==S||t[20]!==w||t[21]!==a?(T={data:r,status:a,error:s,reload:w,fetchBurstDiff:S},t[17]=r,t[18]=s,t[19]=S,t[20]=w,t[21]=a,t[22]=T):T=t[22],T}function le(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function ue(e,t){let n=new Set;if(!e)return n;let r=e.awareness;if(!S(r))return n;let i=[t,t.startsWith(`agent-`)?t.slice(6):`agent-${t}`];for(let e of r.getStates().values()){let t=e.agentPresence;if(t)for(let e of i){let r=t[e];r&&r.mode===`writing`&&r.currentDoc&&n.add(r.currentDoc)}}return n}var M=r(),de=(0,j.lazy)(async()=>({default:(await t(()=>import(`./ActivityPanelDiffView-DeDaG2lq.js`),__vite__mapDeps([0,1,2,3]),import.meta.url)).ActivityPanelDiffView}));function fe(e,t){let n=Math.max(0,t-e);return n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function pe(e){let t=(0,A.c)(38),{burst:n,docName:r,fetchBurstDiff:i}=e,[a,o]=(0,j.useState)(!1),[s,c]=(0,j.useState)(null),[l,u]=(0,j.useState)(null),[d,f]=(0,j.useState)(!1),[m,h]=(0,j.useState)(N),_,v;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{let e=setInterval(()=>h(Date.now()),3e4);return()=>clearInterval(e)},v=[],t[0]=_,t[1]=v):(_=t[0],v=t[1]),(0,j.useEffect)(_,v);let y;t[2]!==n.stackIndex||t[3]!==s||t[4]!==r||t[5]!==a||t[6]!==i||t[7]!==d?(y=()=>{let e=!a;o(e),e&&s===null&&!d&&(f(!0),u(null),i(r,n.stackIndex).then(e=>{c(e),f(!1)}).catch(e=>{u(e instanceof Error?e.message:String(e)),f(!1)}))},t[2]=n.stackIndex,t[3]=s,t[4]=r,t[5]=a,t[6]=i,t[7]=d,t[8]=y):y=t[8];let b=y,x=`${a?`Collapse`:`Expand`} burst ${n.stackIndex+1} diff`,S;t[9]===a?S=t[10]:(S=a?(0,M.jsx)(g,{className:`size-3 shrink-0`,"aria-hidden":`true`}):(0,M.jsx)(p,{className:`size-3 shrink-0`,"aria-hidden":`true`}),t[9]=a,t[10]=S);let C;t[11]!==n.ts||t[12]!==m?(C=fe(n.ts,m),t[11]=n.ts,t[12]=m,t[13]=C):C=t[13];let w;t[14]===C?w=t[15]:(w=(0,M.jsx)(`span`,{className:`font-mono`,children:C}),t[14]=C,t[15]=w);let T;t[16]===n.additions?T=t[17]:(T=(0,M.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,n.additions]}),t[16]=n.additions,t[17]=T);let E;t[18]===n.deletions?E=t[19]:(E=(0,M.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,n.deletions]}),t[18]=n.deletions,t[19]=E);let D;t[20]!==T||t[21]!==E?(D=(0,M.jsxs)(`span`,{className:`ml-auto font-mono`,children:[T,` `,E]}),t[20]=T,t[21]=E,t[22]=D):D=t[22];let O;t[23]!==a||t[24]!==D||t[25]!==x||t[26]!==S||t[27]!==w||t[28]!==b?(O=(0,M.jsxs)(`button`,{type:`button`,onClick:b,className:`flex w-full items-center gap-2 px-4 py-1.5 text-xs text-muted-foreground hover:bg-muted/40`,"aria-expanded":a,"aria-label":x,children:[S,w,D]}),t[23]=a,t[24]=D,t[25]=x,t[26]=S,t[27]=w,t[28]=b,t[29]=O):O=t[29];let k;t[30]!==s||t[31]!==a||t[32]!==l||t[33]!==d?(k=a?(0,M.jsx)(`div`,{className:`bg-muted/20`,children:d?(0,M.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground italic`,children:`Loading diff…`}):l?(0,M.jsxs)(`div`,{className:`px-4 py-2 text-xs text-destructive`,children:[`Failed: `,l]}):s===null?(0,M.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground italic`,children:`No diff.`}):(0,M.jsx)(j.Suspense,{fallback:(0,M.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground italic`,children:`Loading diff…`}),children:(0,M.jsx)(de,{diff:s})})}):null,t[30]=s,t[31]=a,t[32]=l,t[33]=d,t[34]=k):k=t[34];let ee;return t[35]!==O||t[36]!==k?(ee=(0,M.jsxs)(`div`,{className:`border-t border-border/50`,children:[O,k]}),t[35]=O,t[36]=k,t[37]=ee):ee=t[37],ee}function N(){return Date.now()}function me(e,t){let n=Math.max(0,t-e);return n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function P(e){let t=(0,A.c)(93),{file:n,sessionAlive:r,isWriting:i,onNavigate:a,onUndoLast:o,onUndoAll:s,fetchBurstDiff:c}=e,[l,d]=(0,j.useState)(!1),[f,m]=(0,j.useState)(!1),[h,_]=(0,j.useState)(!1),[y,b]=(0,j.useState)(ge),x,S;if(t[0]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>{let e=setInterval(()=>b(Date.now()),3e4);return()=>clearInterval(e)},S=[],t[0]=x,t[1]=S):(x=t[0],S=t[1]),(0,j.useEffect)(x,S),n.bursts.length===0)return null;let C=!r||n.bursts.length===0||h,ie=r?n.bursts.length===0?`Nothing to undo on this file`:null:`Session ended — undo unavailable`,ae;t[2]!==C||t[3]!==n.docName||t[4]!==o?(ae=e=>{e.stopPropagation(),!C&&(_(!0),Promise.resolve(o(n.docName)).finally(()=>_(!1)))},t[2]=C,t[3]=n.docName,t[4]=o,t[5]=ae):ae=t[5];let oe=ae,se;t[6]===C?se=t[7]:(se=e=>{e.stopPropagation(),!C&&m(!0)},t[6]=C,t[7]=se);let ce=se,le;t[8]!==C||t[9]!==n.docName||t[10]!==s?(le=()=>{m(!1),!C&&(_(!0),Promise.resolve(s(n.docName)).finally(()=>_(!1)))},t[8]=C,t[9]=n.docName,t[10]=s,t[11]=le):le=t[11];let ue=le,de;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(de=()=>d(he),t[12]=de):de=t[12];let fe=l?`Collapse ${n.docName}`:`Expand ${n.docName}`,N;t[13]===l?N=t[14]:(N=l?(0,M.jsx)(g,{className:`size-4`,"aria-hidden":`true`}):(0,M.jsx)(p,{className:`size-4`,"aria-hidden":`true`}),t[13]=l,t[14]=N);let P;t[15]!==l||t[16]!==fe||t[17]!==N?(P=(0,M.jsx)(`button`,{type:`button`,onClick:de,className:`flex size-5 shrink-0 items-center justify-center rounded hover:bg-muted`,"aria-expanded":l,"aria-label":fe,"data-testid":`activity-panel-file-row-carrot`,children:N}),t[15]=l,t[16]=fe,t[17]=N,t[18]=P):P=t[18];let F;t[19]!==n.docName||t[20]!==a?(F=()=>a(n.docName),t[19]=n.docName,t[20]=a,t[21]=F):F=t[21];let _e=`Navigate to ${n.docName}`,I;t[22]!==n.docName||t[23]!==F||t[24]!==_e?(I=(0,M.jsx)(`button`,{type:`button`,onClick:F,className:`min-w-0 flex-1 truncate text-left text-foreground hover:underline focus-visible:outline-ring`,"aria-label":_e,"data-testid":`activity-panel-file-row-filename`,title:n.docName,children:n.docName}),t[22]=n.docName,t[23]=F,t[24]=_e,t[25]=I):I=t[25];let ve=`Undo last edit on ${n.docName}`,ye;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(ye=(0,M.jsx)(v,{className:`size-3.5`,"aria-hidden":`true`}),t[26]=ye):ye=t[26];let L;t[27]!==C||t[28]!==oe||t[29]!==ve?(L=(0,M.jsx)(w,{asChild:!0,children:(0,M.jsx)(u,{type:`button`,variant:`ghost`,size:`icon`,className:`size-6 shrink-0`,onClick:oe,disabled:C,"aria-label":ve,"data-testid":`activity-panel-undo-last`,children:ye})}),t[27]=C,t[28]=oe,t[29]=ve,t[30]=L):L=t[30];let be=ie??`Undo last edit`,R;t[31]===be?R=t[32]:(R=(0,M.jsx)(T,{side:`bottom`,children:be}),t[31]=be,t[32]=R);let z;t[33]!==L||t[34]!==R?(z=(0,M.jsxs)(E,{children:[L,R]}),t[33]=L,t[34]=R,t[35]=z):z=t[35];let xe=`Undo all edits on ${n.docName}`,Se;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(Se=(0,M.jsx)(re,{className:`size-3.5`,"aria-hidden":`true`}),t[36]=Se):Se=t[36];let B;t[37]!==C||t[38]!==ce||t[39]!==xe?(B=(0,M.jsx)(w,{asChild:!0,children:(0,M.jsx)(u,{type:`button`,variant:`ghost`,size:`icon`,className:`size-6 shrink-0`,onClick:ce,disabled:C,"aria-label":xe,"data-testid":`activity-panel-undo-all`,children:Se})}),t[37]=C,t[38]=ce,t[39]=xe,t[40]=B):B=t[40];let Ce=ie??`Undo all edits`,V;t[41]===Ce?V=t[42]:(V=(0,M.jsx)(T,{side:`bottom`,children:Ce}),t[41]=Ce,t[42]=V);let H;t[43]!==B||t[44]!==V?(H=(0,M.jsxs)(E,{children:[B,V]}),t[43]=B,t[44]=V,t[45]=H):H=t[45];let U;t[46]===n.additionsTotal?U=t[47]:(U=(0,M.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,n.additionsTotal]}),t[46]=n.additionsTotal,t[47]=U);let W;t[48]===n.deletionsTotal?W=t[49]:(W=(0,M.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,n.deletionsTotal]}),t[48]=n.deletionsTotal,t[49]=W);let G;t[50]!==U||t[51]!==W?(G=(0,M.jsxs)(`span`,{className:`shrink-0 font-mono text-xs`,children:[U,` `,W]}),t[50]=U,t[51]=W,t[52]=G):G=t[52];let K;t[53]!==n.lastTs||t[54]!==y?(K=me(n.lastTs,y),t[53]=n.lastTs,t[54]=y,t[55]=K):K=t[55];let q;t[56]===K?q=t[57]:(q=(0,M.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:K}),t[56]=K,t[57]=q);let J;t[58]===i?J=t[59]:(J=i?(0,M.jsx)(`span`,{className:`shrink-0 text-[11px] text-primary animate-pulse`,role:`status`,children:`writing…`}):null,t[58]=i,t[59]=J);let Y;t[60]!==I||t[61]!==z||t[62]!==H||t[63]!==G||t[64]!==q||t[65]!==J||t[66]!==P?(Y=(0,M.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-sm`,children:[P,I,z,H,G,q,J]}),t[60]=I,t[61]=z,t[62]=H,t[63]=G,t[64]=q,t[65]=J,t[66]=P,t[67]=Y):Y=t[67];let X;t[68]!==l||t[69]!==c||t[70]!==n.bursts||t[71]!==n.docName?(X=l?(0,M.jsx)(`div`,{children:n.bursts.map(e=>(0,M.jsx)(pe,{burst:e,docName:n.docName,fetchBurstDiff:c},`${n.docName}:${e.stackIndex}`))}):null,t[68]=l,t[69]=c,t[70]=n.bursts,t[71]=n.docName,t[72]=X):X=t[72];let we;t[73]===Symbol.for(`react.memo_cache_sentinel`)?(we=(0,M.jsx)(O,{children:`Undo all edits on this file?`}),t[73]=we):we=t[73];let Z;t[74]===n.docName?Z=t[75]:(Z=(0,M.jsx)(`span`,{className:`font-mono text-foreground`,children:n.docName}),t[74]=n.docName,t[75]=Z);let Te=n.bursts.length===1?``:`s`,Q;t[76]!==n.bursts.length||t[77]!==Z||t[78]!==Te?(Q=(0,M.jsxs)(te,{children:[we,(0,M.jsxs)(D,{children:[`This will revert every change this agent has made to`,` `,Z,` in their current session (`,n.bursts.length,` burst`,Te,`). Other files and other writers are not affected.`]})]}),t[76]=n.bursts.length,t[77]=Z,t[78]=Te,t[79]=Q):Q=t[79];let Ee;t[80]===Symbol.for(`react.memo_cache_sentinel`)?(Ee=(0,M.jsx)(u,{type:`button`,variant:`outline`,onClick:()=>m(!1),"data-testid":`activity-panel-undo-all-cancel`,children:`Cancel`}),t[80]=Ee):Ee=t[80];let $;t[81]===ue?$=t[82]:($=(0,M.jsxs)(ee,{children:[Ee,(0,M.jsx)(u,{type:`button`,variant:`destructive`,onClick:ue,"data-testid":`activity-panel-undo-all-confirm`,children:`Undo all`})]}),t[81]=ue,t[82]=$);let De;t[83]!==Q||t[84]!==$?(De=(0,M.jsxs)(k,{className:`sm:max-w-md`,children:[Q,$]}),t[83]=Q,t[84]=$,t[85]=De):De=t[85];let Oe;t[86]!==f||t[87]!==De?(Oe=(0,M.jsx)(ne,{open:f,onOpenChange:m,children:De}),t[86]=f,t[87]=De,t[88]=Oe):Oe=t[88];let ke;return t[89]!==Y||t[90]!==X||t[91]!==Oe?(ke=(0,M.jsxs)(`div`,{className:`border-b border-border`,"data-testid":`activity-panel-file-row`,children:[Y,X,Oe]}),t[89]=Y,t[90]=X,t[91]=Oe,t[92]=ke):ke=t[92],ke}function he(e){return!e}function ge(){return Date.now()}async function F(e){let t=await fetch(`/api/agent-undo`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,agentId:e.connectionId})});if(!t.ok)throw Error(`agent-undo failed: HTTP ${t.status}`)}function _e(e){return`#/${e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`)}`}function I(e){typeof window>`u`||(window.location.hash=_e(e))}function ve(){let e=(0,A.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,M.jsxs)(`div`,{className:`flex h-full items-center justify-center p-6 text-muted-foreground`,role:`status`,"aria-busy":`true`,children:[(0,M.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":`true`}),(0,M.jsx)(`span`,{className:`text-sm`,children:`Loading agent activity…`})]}),e[0]=t):t=e[0],t}function ye(e){let t=(0,A.c)(9),{error:n,onRetry:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,M.jsx)(m,{className:`size-6 text-destructive`,"aria-hidden":`true`}),t[0]=i):i=t[0];let a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,M.jsx)(`p`,{className:`text-sm font-medium`,children:`Failed to load activity`}),t[1]=a):a=t[1];let o;t[2]===n?o=t[3]:(o=(0,M.jsxs)(`div`,{className:`space-y-1`,children:[a,(0,M.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]}),t[2]=n,t[3]=o);let s;t[4]===r?s=t[5]:(s=(0,M.jsx)(u,{type:`button`,variant:`outline`,size:`sm`,onClick:r,children:`Retry`}),t[4]=r,t[5]=s);let c;return t[6]!==o||t[7]!==s?(c=(0,M.jsxs)(`div`,{className:`flex flex-col items-center gap-3 p-6 text-center`,role:`alert`,"data-testid":`activity-panel-error`,children:[i,o,s]}),t[6]=o,t[7]=s,t[8]=c):c=t[8],c}function L(){let e=(0,A.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,M.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-muted-foreground`,"data-testid":`activity-panel-empty`,children:(0,M.jsx)(`p`,{className:`text-sm italic`,children:`No edits yet.`})}),e[0]=t):t=e[0],t}function be(e){let t=(0,A.c)(8),{onExit:n}=e,r;t[0]===n?r=t[1]:(r=(0,M.jsx)(R,{onClick:n}),t[0]=n,t[1]=r);let i;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,M.jsx)(`h2`,{className:`truncate text-sm font-medium`,children:`Agent activity`}),t[2]=i):i=t[2];let a;t[3]===r?a=t[4]:(a=(0,M.jsxs)(`div`,{className:`flex shrink-0 flex-row items-center gap-2 border-b border-border px-3 py-2`,children:[r,i]}),t[3]=r,t[4]=a);let o;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,M.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-muted-foreground`,children:(0,M.jsx)(`p`,{className:`text-center text-sm italic`,children:`Click an agent's avatar in the presence bar to view their session.`})}),t[5]=o):o=t[5];let s;return t[6]===a?s=t[7]:(s=(0,M.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col`,"data-testid":`activity-panel-no-agent`,"aria-label":`Agent activity`,children:[a,o]}),t[6]=a,t[7]=s),s}function R(e){let t=(0,A.c)(6),{onClick:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,M.jsx)(b,{}),t[0]=r):r=t[0];let i;t[1]===n?i=t[2]:(i=(0,M.jsx)(w,{asChild:!0,children:(0,M.jsx)(u,{type:`button`,variant:`ghost`,size:`icon`,className:`size-7 shrink-0`,onClick:n,"aria-label":`Back to document view`,"data-testid":`docpanel-exit-agent-mode`,children:r})}),t[1]=n,t[2]=i);let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,M.jsx)(T,{side:`bottom`,children:`Back to document view`}),t[3]=a):a=t[3];let o;return t[4]===i?o=t[5]:(o=(0,M.jsxs)(E,{children:[i,a]}),t[4]=i,t[5]=o),o}function z(e){let t=(0,A.c)(9),{lastTs:n}=e,[r]=(0,j.useState)(xe),i;t[0]!==n||t[1]!==r?(i=n?Se(r-n):null,t[0]=n,t[1]=r,t[2]=i):i=t[2];let a=i,o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,M.jsx)(`span`,{className:`font-medium`,children:`Session ended`}),t[3]=o):o=t[3];let s;t[4]===a?s=t[5]:(s=a?(0,M.jsxs)(`span`,{children:[` · `,a]}):null,t[4]=a,t[5]=s);let c;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,M.jsx)(`div`,{className:`mt-1 opacity-80`,children:`Undo buttons are disabled — per-session state has been garbage-collected.`}),t[6]=c):c=t[6];let l;return t[7]===s?l=t[8]:(l=(0,M.jsxs)(`div`,{className:`border-b border-border bg-muted/40 px-4 py-3 text-xs text-muted-foreground`,"data-testid":`activity-panel-session-ended`,children:[o,s,c]}),t[7]=s,t[8]=l),l}function xe(){return Date.now()}function Se(e){let t=Math.max(0,e);return t<6e4?`${Math.round(t/1e3)}s ago`:t<36e5?`${Math.round(t/6e4)}m ago`:`${Math.round(t/36e5)}h ago`}function B(e){let t=(0,A.c)(10),{agent:n,size:r}=e,i=r===void 0?28:r,a;t[0]!==n.color||t[1]!==i?(a={backgroundColor:n.color,width:i,height:i},t[0]=n.color,t[1]=i,t[2]=a):a=t[2];let o=i*.57,s=i*.57,c;t[3]!==n.icon||t[4]!==o||t[5]!==s?(c=(0,M.jsx)(x,{icon:n.icon,width:o,height:s}),t[3]=n.icon,t[4]=o,t[5]=s,t[6]=c):c=t[6];let l;return t[7]!==a||t[8]!==c?(l=(0,M.jsx)(`span`,{className:`inline-flex shrink-0 items-center justify-center rounded-full text-white ring-2 ring-background`,style:a,"aria-hidden":`true`,children:c}),t[7]=a,t[8]=c,t[9]=l):l=t[9],l}function Ce(e){let t=(0,A.c)(20),{data:n,status:r,error:i,reload:a,fetchBurstDiff:o,onExit:s,onNavigate:c,onUndoLast:l,onUndoAll:u}=e,d=n?.files?.[0]?.lastTs??null,f;t[0]===s?f=t[1]:(f=(0,M.jsx)(R,{onClick:s}),t[0]=s,t[1]=f);let p;t[2]===n?p=t[3]:(p=n?.agent?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(B,{agent:n.agent}),(0,M.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,M.jsx)(`h2`,{className:`truncate text-sm font-medium`,children:n.agent.displayName}),(0,M.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,children:[n.sessionAlive?`Active`:`Ended`,n.files.length>0?` · ${n.files.length} file${n.files.length===1?``:`s`}`:``]})]})]}):(0,M.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,M.jsx)(`h2`,{className:`truncate text-sm font-medium`,children:`Agent activity`})}),t[2]=n,t[3]=p);let m;t[4]!==f||t[5]!==p?(m=(0,M.jsxs)(`div`,{className:`flex flex-row items-center gap-2 border-b border-border px-3 py-2 shrink-0`,children:[f,p]}),t[4]=f,t[5]=p,t[6]=m):m=t[6];let h;t[7]!==n||t[8]!==i||t[9]!==o||t[10]!==d||t[11]!==c||t[12]!==u||t[13]!==l||t[14]!==a||t[15]!==r?(h=(0,M.jsx)(`div`,{className:`flex-1 overflow-y-auto`,"data-testid":`activity-panel-body`,children:r===`loading`&&n===null?(0,M.jsx)(ve,{}):r===`error`&&i?(0,M.jsx)(ye,{error:i,onRetry:a}):n===null?(0,M.jsx)(L,{}):(0,M.jsxs)(M.Fragment,{children:[n.sessionAlive?null:(0,M.jsx)(z,{lastTs:d}),n.files.length===0?(0,M.jsx)(L,{}):n.files.map(e=>(0,M.jsx)(P,{file:e,sessionAlive:n.sessionAlive,isWriting:n.writingDocs.has(e.docName),onNavigate:c,onUndoLast:l,onUndoAll:u,fetchBurstDiff:o},e.docName))]})}),t[7]=n,t[8]=i,t[9]=o,t[10]=d,t[11]=c,t[12]=u,t[13]=l,t[14]=a,t[15]=r,t[16]=h):h=t[16];let g;return t[17]!==m||t[18]!==h?(g=(0,M.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col`,"data-testid":`activity-panel`,"aria-label":`Agent activity`,children:[m,h]}),t[17]=m,t[18]=h,t[19]=g):g=t[19],g}function V(){let e=(0,A.c)(22),{docPanelAgentId:t,closeActivityPanel:n}=h(),{openDocumentTransition:r}=_(),{data:i,status:a,error:o,reload:s,fetchBurstDiff:c}=ce(t);if(t===null){let t;return e[0]===n?t=e[1]:(t=(0,M.jsx)(be,{onExit:n}),e[0]=n,e[1]=t),t}let l;e[2]===r?l=e[3]:(l=e=>{r(e),I(e)},e[2]=r,e[3]=l);let u=l,d;e[4]!==i||e[5]!==t||e[6]!==s?(d=async e=>{try{await F({connectionId:t,docName:e,scope:`last`,agentName:i?.agent?.displayName}),s()}catch(e){let t=e,n=t instanceof Error?t.message:String(t);C.error(`Undo failed: ${n}`),s()}},e[4]=i,e[5]=t,e[6]=s,e[7]=d):d=e[7];let f=d,p;e[8]!==i||e[9]!==t||e[10]!==s?(p=async e=>{try{await F({connectionId:t,docName:e,scope:`file`,agentName:i?.agent?.displayName}),C.success(`Undone all edits on ${e}`),s()}catch(e){let t=e,n=t instanceof Error?t.message:String(t);C.error(`Undo all failed: ${n}`),s()}},e[8]=i,e[9]=t,e[10]=s,e[11]=p):p=e[11];let m=p,g;return e[12]!==n||e[13]!==i||e[14]!==o||e[15]!==c||e[16]!==u||e[17]!==m||e[18]!==f||e[19]!==s||e[20]!==a?(g=(0,M.jsx)(Ce,{data:i,status:a,error:o,reload:s,fetchBurstDiff:c,onExit:n,onNavigate:u,onUndoLast:f,onUndoAll:m}),e[12]=n,e[13]=i,e[14]=o,e[15]=c,e[16]=u,e[17]=m,e[18]=f,e[19]=s,e[20]=a,e[21]=g):g=e[21],g}export{V as ActivityModeContent};
2
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./preload-helper-2ej06EnG.js";import{n,r,t as i}from"./compiler-runtime-CVnuRdak.js";import{Q as a,Zt as o,dn as s,fn as c,n as l,pn as u,r as d}from"./DocumentContext-BWaxMbNn.js";import{Dt as f,U as p,W as m,p as h}from"./doc-hash-DAxgYkBj.js";import{C as g,t as _}from"./button-C1nwPVFQ.js";import{f as v,i as y,m as b,r as x,t as S}from"./agent-presence-BrTlNKmt.js";import{p as C}from"./dist-OTL8-1C2.js";import{i as w,n as T,t as E}from"./tooltip-DNV87xh_.js";import{a as D,c as O,i as k,o as ee,s as te,t as ne}from"./dialog-BFN-ujuF.js";var re=g(`rewind`,[[`path`,{d:`M12 6a2 2 0 0 0-3.414-1.414l-6 6a2 2 0 0 0 0 2.828l6 6A2 2 0 0 0 12 18z`,key:`2a1g8i`}],[`path`,{d:`M22 6a2 2 0 0 0-3.414-1.414l-6 6a2 2 0 0 0 0 2.828l6 6A2 2 0 0 0 22 18z`,key:`rg3s36`}]]),A=i(),j=e(n(),1),ie=500,ae=64;async function oe(e){let t=`/api/agent-activity?agentId=${encodeURIComponent(e)}`,n=await fetch(t),r;try{r=await n.json()}catch(e){throw new a(`Could not parse /api/agent-activity response.`,{cause:e,status:n.status})}if(!n.ok){let e=f.safeParse(r);throw e.success?Error(e.data.title):new a(`/api/agent-activity returned a non-RFC-9457 error response.`,{cause:e.error,status:n.status})}let i=p.safeParse(r);if(!i.success)throw new a(`/api/agent-activity returned a body that did not match AgentActivitySuccessSchema.`,{cause:i.error,status:n.status});return i.data}async function se(e,t,n){let r=`/api/agent-burst-diff?agentId=${encodeURIComponent(e)}&docName=${encodeURIComponent(t)}&stackIndex=${n}`,i=await fetch(r),o;try{o=await i.json()}catch(e){throw new a(`Could not parse /api/agent-burst-diff response.`,{cause:e,status:i.status})}if(!i.ok){let e=f.safeParse(o);throw e.success?Error(e.data.title):new a(`/api/agent-burst-diff returned a non-RFC-9457 error response.`,{cause:e.error,status:i.status})}let s=m.safeParse(o);if(!s.success)throw new a(`/api/agent-burst-diff returned a body that did not match AgentBurstDiffSuccessSchema.`,{cause:s.error,status:i.status});return s.data.diff}function ce(e){let t=(0,A.c)(23),{systemProvider:n}=l(),[r,i]=(0,j.useState)(null),[a,o]=(0,j.useState)(`idle`),[s,c]=(0,j.useState)(null),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=new y(ae),t[0]=u):u=t[0];let d=(0,j.useRef)(u),f=(0,j.useRef)(0),p;t[1]===n?p=t[2]:(p=e=>{let t=f.current+=1;o(`loading`),c(null),oe(e).then(r=>{if(f.current!==t)return;let a=ue(n,e);i({...r,writingDocs:a}),o(`ready`)}).catch(e=>{f.current===t&&(c(e instanceof Error?e.message:String(e)),o(`error`))})},t[1]=n,t[2]=p);let m=p,g;t[3]!==e||t[4]!==m?(g=()=>{if(!e){f.current+=1,i(null),o(`idle`),c(null),d.current.clear();return}d.current.clear(),m(e);let t=null,n=h(n=>{n.includes(`session-activity`)&&(t&&clearTimeout(t),t=setTimeout(()=>{t=null,m(e)},ie))});return()=>{t&&clearTimeout(t),n()}},t[3]=e,t[4]=m,t[5]=g):g=t[5];let _;t[6]===e?_=t[7]:(_=[e],t[6]=e,t[7]=_),(0,j.useEffect)(g,_);let v,b;t[8]!==e||t[9]!==n?(v=()=>{if(!e||!n)return;let t=()=>{if(!n.awareness)return;let t=ue(n,e);i(e=>!e||le(e.writingDocs,t)?e:{...e,writingDocs:t})},r=n.awareness;if(!r||typeof r.on!=`function`){t();return}r.on(`update`,t),t();let a=setInterval(t,1e3);return()=>{clearInterval(a),typeof r.off==`function`&&r.off(`update`,t)}},b=[e,n],t[8]=e,t[9]=n,t[10]=v,t[11]=b):(v=t[10],b=t[11]),(0,j.useEffect)(v,b);let x;t[12]===e?x=t[13]:(x=async(t,n)=>{if(!e)return``;let r=`${t}\0${n}`,i=d.current.get(r);if(i!==void 0)return i;let a=await se(e,t,n);return d.current.set(r,a),a},t[12]=e,t[13]=x);let S=x,C;t[14]!==e||t[15]!==m?(C=()=>{e&&m(e)},t[14]=e,t[15]=m,t[16]=C):C=t[16];let w=C,T;return t[17]!==r||t[18]!==s||t[19]!==S||t[20]!==w||t[21]!==a?(T={data:r,status:a,error:s,reload:w,fetchBurstDiff:S},t[17]=r,t[18]=s,t[19]=S,t[20]=w,t[21]=a,t[22]=T):T=t[22],T}function le(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function ue(e,t){let n=new Set;if(!e)return n;let r=e.awareness;if(!S(r))return n;let i=[t,t.startsWith(`agent-`)?t.slice(6):`agent-${t}`];for(let e of r.getStates().values()){let t=e.agentPresence;if(t)for(let e of i){let r=t[e];r&&r.mode===`writing`&&r.currentDoc&&n.add(r.currentDoc)}}return n}var M=r(),de=(0,j.lazy)(async()=>({default:(await t(()=>import(`./ActivityPanelDiffView-DeDaG2lq.js`),__vite__mapDeps([0,1,2,3]),import.meta.url)).ActivityPanelDiffView}));function fe(e,t){let n=Math.max(0,t-e);return n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function pe(e){let t=(0,A.c)(38),{burst:n,docName:r,fetchBurstDiff:i}=e,[a,o]=(0,j.useState)(!1),[s,l]=(0,j.useState)(null),[d,f]=(0,j.useState)(null),[p,m]=(0,j.useState)(!1),[h,g]=(0,j.useState)(N),_,v;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{let e=setInterval(()=>g(Date.now()),3e4);return()=>clearInterval(e)},v=[],t[0]=_,t[1]=v):(_=t[0],v=t[1]),(0,j.useEffect)(_,v);let y;t[2]!==n.stackIndex||t[3]!==s||t[4]!==r||t[5]!==a||t[6]!==i||t[7]!==p?(y=()=>{let e=!a;o(e),e&&s===null&&!p&&(m(!0),f(null),i(r,n.stackIndex).then(e=>{l(e),m(!1)}).catch(e=>{f(e instanceof Error?e.message:String(e)),m(!1)}))},t[2]=n.stackIndex,t[3]=s,t[4]=r,t[5]=a,t[6]=i,t[7]=p,t[8]=y):y=t[8];let b=y,x=`${a?`Collapse`:`Expand`} burst ${n.stackIndex+1} diff`,S;t[9]===a?S=t[10]:(S=a?(0,M.jsx)(u,{className:`size-3 shrink-0`,"aria-hidden":`true`}):(0,M.jsx)(c,{className:`size-3 shrink-0`,"aria-hidden":`true`}),t[9]=a,t[10]=S);let C;t[11]!==n.ts||t[12]!==h?(C=fe(n.ts,h),t[11]=n.ts,t[12]=h,t[13]=C):C=t[13];let w;t[14]===C?w=t[15]:(w=(0,M.jsx)(`span`,{className:`font-mono`,children:C}),t[14]=C,t[15]=w);let T;t[16]===n.additions?T=t[17]:(T=(0,M.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,n.additions]}),t[16]=n.additions,t[17]=T);let E;t[18]===n.deletions?E=t[19]:(E=(0,M.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,n.deletions]}),t[18]=n.deletions,t[19]=E);let D;t[20]!==T||t[21]!==E?(D=(0,M.jsxs)(`span`,{className:`ml-auto font-mono`,children:[T,` `,E]}),t[20]=T,t[21]=E,t[22]=D):D=t[22];let O;t[23]!==a||t[24]!==D||t[25]!==x||t[26]!==S||t[27]!==w||t[28]!==b?(O=(0,M.jsxs)(`button`,{type:`button`,onClick:b,className:`flex w-full items-center gap-2 px-4 py-1.5 text-xs text-muted-foreground hover:bg-muted/40`,"aria-expanded":a,"aria-label":x,children:[S,w,D]}),t[23]=a,t[24]=D,t[25]=x,t[26]=S,t[27]=w,t[28]=b,t[29]=O):O=t[29];let k;t[30]!==s||t[31]!==a||t[32]!==d||t[33]!==p?(k=a?(0,M.jsx)(`div`,{className:`bg-muted/20`,children:p?(0,M.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground italic`,children:`Loading diff…`}):d?(0,M.jsxs)(`div`,{className:`px-4 py-2 text-xs text-destructive`,children:[`Failed: `,d]}):s===null?(0,M.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground italic`,children:`No diff.`}):(0,M.jsx)(j.Suspense,{fallback:(0,M.jsx)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground italic`,children:`Loading diff…`}),children:(0,M.jsx)(de,{diff:s})})}):null,t[30]=s,t[31]=a,t[32]=d,t[33]=p,t[34]=k):k=t[34];let ee;return t[35]!==O||t[36]!==k?(ee=(0,M.jsxs)(`div`,{className:`border-t border-border/50`,children:[O,k]}),t[35]=O,t[36]=k,t[37]=ee):ee=t[37],ee}function N(){return Date.now()}function me(e,t){let n=Math.max(0,t-e);return n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function P(e){let t=(0,A.c)(93),{file:n,sessionAlive:r,isWriting:i,onNavigate:a,onUndoLast:o,onUndoAll:s,fetchBurstDiff:l}=e,[d,f]=(0,j.useState)(!1),[p,m]=(0,j.useState)(!1),[h,g]=(0,j.useState)(!1),[y,b]=(0,j.useState)(ge),x,S;if(t[0]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>{let e=setInterval(()=>b(Date.now()),3e4);return()=>clearInterval(e)},S=[],t[0]=x,t[1]=S):(x=t[0],S=t[1]),(0,j.useEffect)(x,S),n.bursts.length===0)return null;let C=!r||n.bursts.length===0||h,ie=r?n.bursts.length===0?`Nothing to undo on this file`:null:`Session ended — undo unavailable`,ae;t[2]!==C||t[3]!==n.docName||t[4]!==o?(ae=e=>{e.stopPropagation(),!C&&(g(!0),Promise.resolve(o(n.docName)).finally(()=>g(!1)))},t[2]=C,t[3]=n.docName,t[4]=o,t[5]=ae):ae=t[5];let oe=ae,se;t[6]===C?se=t[7]:(se=e=>{e.stopPropagation(),!C&&m(!0)},t[6]=C,t[7]=se);let ce=se,le;t[8]!==C||t[9]!==n.docName||t[10]!==s?(le=()=>{m(!1),!C&&(g(!0),Promise.resolve(s(n.docName)).finally(()=>g(!1)))},t[8]=C,t[9]=n.docName,t[10]=s,t[11]=le):le=t[11];let ue=le,de;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(de=()=>f(he),t[12]=de):de=t[12];let fe=d?`Collapse ${n.docName}`:`Expand ${n.docName}`,N;t[13]===d?N=t[14]:(N=d?(0,M.jsx)(u,{className:`size-4`,"aria-hidden":`true`}):(0,M.jsx)(c,{className:`size-4`,"aria-hidden":`true`}),t[13]=d,t[14]=N);let P;t[15]!==d||t[16]!==fe||t[17]!==N?(P=(0,M.jsx)(`button`,{type:`button`,onClick:de,className:`flex size-5 shrink-0 items-center justify-center rounded hover:bg-muted`,"aria-expanded":d,"aria-label":fe,"data-testid":`activity-panel-file-row-carrot`,children:N}),t[15]=d,t[16]=fe,t[17]=N,t[18]=P):P=t[18];let F;t[19]!==n.docName||t[20]!==a?(F=()=>a(n.docName),t[19]=n.docName,t[20]=a,t[21]=F):F=t[21];let _e=`Navigate to ${n.docName}`,I;t[22]!==n.docName||t[23]!==F||t[24]!==_e?(I=(0,M.jsx)(`button`,{type:`button`,onClick:F,className:`min-w-0 flex-1 truncate text-left text-foreground hover:underline focus-visible:outline-ring`,"aria-label":_e,"data-testid":`activity-panel-file-row-filename`,title:n.docName,children:n.docName}),t[22]=n.docName,t[23]=F,t[24]=_e,t[25]=I):I=t[25];let ve=`Undo last edit on ${n.docName}`,ye;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(ye=(0,M.jsx)(v,{className:`size-3.5`,"aria-hidden":`true`}),t[26]=ye):ye=t[26];let L;t[27]!==C||t[28]!==oe||t[29]!==ve?(L=(0,M.jsx)(w,{asChild:!0,children:(0,M.jsx)(_,{type:`button`,variant:`ghost`,size:`icon`,className:`size-6 shrink-0`,onClick:oe,disabled:C,"aria-label":ve,"data-testid":`activity-panel-undo-last`,children:ye})}),t[27]=C,t[28]=oe,t[29]=ve,t[30]=L):L=t[30];let be=ie??`Undo last edit`,R;t[31]===be?R=t[32]:(R=(0,M.jsx)(T,{side:`bottom`,children:be}),t[31]=be,t[32]=R);let z;t[33]!==L||t[34]!==R?(z=(0,M.jsxs)(E,{children:[L,R]}),t[33]=L,t[34]=R,t[35]=z):z=t[35];let xe=`Undo all edits on ${n.docName}`,Se;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(Se=(0,M.jsx)(re,{className:`size-3.5`,"aria-hidden":`true`}),t[36]=Se):Se=t[36];let B;t[37]!==C||t[38]!==ce||t[39]!==xe?(B=(0,M.jsx)(w,{asChild:!0,children:(0,M.jsx)(_,{type:`button`,variant:`ghost`,size:`icon`,className:`size-6 shrink-0`,onClick:ce,disabled:C,"aria-label":xe,"data-testid":`activity-panel-undo-all`,children:Se})}),t[37]=C,t[38]=ce,t[39]=xe,t[40]=B):B=t[40];let Ce=ie??`Undo all edits`,V;t[41]===Ce?V=t[42]:(V=(0,M.jsx)(T,{side:`bottom`,children:Ce}),t[41]=Ce,t[42]=V);let H;t[43]!==B||t[44]!==V?(H=(0,M.jsxs)(E,{children:[B,V]}),t[43]=B,t[44]=V,t[45]=H):H=t[45];let U;t[46]===n.additionsTotal?U=t[47]:(U=(0,M.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,n.additionsTotal]}),t[46]=n.additionsTotal,t[47]=U);let W;t[48]===n.deletionsTotal?W=t[49]:(W=(0,M.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,n.deletionsTotal]}),t[48]=n.deletionsTotal,t[49]=W);let G;t[50]!==U||t[51]!==W?(G=(0,M.jsxs)(`span`,{className:`shrink-0 font-mono text-xs`,children:[U,` `,W]}),t[50]=U,t[51]=W,t[52]=G):G=t[52];let K;t[53]!==n.lastTs||t[54]!==y?(K=me(n.lastTs,y),t[53]=n.lastTs,t[54]=y,t[55]=K):K=t[55];let q;t[56]===K?q=t[57]:(q=(0,M.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-muted-foreground`,children:K}),t[56]=K,t[57]=q);let J;t[58]===i?J=t[59]:(J=i?(0,M.jsx)(`span`,{className:`shrink-0 text-[11px] text-primary animate-pulse`,role:`status`,children:`writing…`}):null,t[58]=i,t[59]=J);let Y;t[60]!==I||t[61]!==z||t[62]!==H||t[63]!==G||t[64]!==q||t[65]!==J||t[66]!==P?(Y=(0,M.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-sm`,children:[P,I,z,H,G,q,J]}),t[60]=I,t[61]=z,t[62]=H,t[63]=G,t[64]=q,t[65]=J,t[66]=P,t[67]=Y):Y=t[67];let X;t[68]!==d||t[69]!==l||t[70]!==n.bursts||t[71]!==n.docName?(X=d?(0,M.jsx)(`div`,{children:n.bursts.map(e=>(0,M.jsx)(pe,{burst:e,docName:n.docName,fetchBurstDiff:l},`${n.docName}:${e.stackIndex}`))}):null,t[68]=d,t[69]=l,t[70]=n.bursts,t[71]=n.docName,t[72]=X):X=t[72];let we;t[73]===Symbol.for(`react.memo_cache_sentinel`)?(we=(0,M.jsx)(O,{children:`Undo all edits on this file?`}),t[73]=we):we=t[73];let Z;t[74]===n.docName?Z=t[75]:(Z=(0,M.jsx)(`span`,{className:`font-mono text-foreground`,children:n.docName}),t[74]=n.docName,t[75]=Z);let Te=n.bursts.length===1?``:`s`,Q;t[76]!==n.bursts.length||t[77]!==Z||t[78]!==Te?(Q=(0,M.jsxs)(te,{children:[we,(0,M.jsxs)(D,{children:[`This will revert every change this agent has made to`,` `,Z,` in their current session (`,n.bursts.length,` burst`,Te,`). Other files and other writers are not affected.`]})]}),t[76]=n.bursts.length,t[77]=Z,t[78]=Te,t[79]=Q):Q=t[79];let Ee;t[80]===Symbol.for(`react.memo_cache_sentinel`)?(Ee=(0,M.jsx)(_,{type:`button`,variant:`outline`,onClick:()=>m(!1),"data-testid":`activity-panel-undo-all-cancel`,children:`Cancel`}),t[80]=Ee):Ee=t[80];let $;t[81]===ue?$=t[82]:($=(0,M.jsxs)(ee,{children:[Ee,(0,M.jsx)(_,{type:`button`,variant:`destructive`,onClick:ue,"data-testid":`activity-panel-undo-all-confirm`,children:`Undo all`})]}),t[81]=ue,t[82]=$);let De;t[83]!==Q||t[84]!==$?(De=(0,M.jsxs)(k,{className:`sm:max-w-md`,children:[Q,$]}),t[83]=Q,t[84]=$,t[85]=De):De=t[85];let Oe;t[86]!==p||t[87]!==De?(Oe=(0,M.jsx)(ne,{open:p,onOpenChange:m,children:De}),t[86]=p,t[87]=De,t[88]=Oe):Oe=t[88];let ke;return t[89]!==Y||t[90]!==X||t[91]!==Oe?(ke=(0,M.jsxs)(`div`,{className:`border-b border-border`,"data-testid":`activity-panel-file-row`,children:[Y,X,Oe]}),t[89]=Y,t[90]=X,t[91]=Oe,t[92]=ke):ke=t[92],ke}function he(e){return!e}function ge(){return Date.now()}async function F(e){let t=await fetch(`/api/agent-undo`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,agentId:e.connectionId})});if(!t.ok)throw Error(`agent-undo failed: HTTP ${t.status}`)}function _e(e){return`#/${e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`)}`}function I(e){typeof window>`u`||(window.location.hash=_e(e))}function ve(){let e=(0,A.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,M.jsxs)(`div`,{className:`flex h-full items-center justify-center p-6 text-muted-foreground`,role:`status`,"aria-busy":`true`,children:[(0,M.jsx)(o,{className:`mr-2 size-4 animate-spin`,"aria-hidden":`true`}),(0,M.jsx)(`span`,{className:`text-sm`,children:`Loading agent activity…`})]}),e[0]=t):t=e[0],t}function ye(e){let t=(0,A.c)(9),{error:n,onRetry:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,M.jsx)(s,{className:`size-6 text-destructive`,"aria-hidden":`true`}),t[0]=i):i=t[0];let a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,M.jsx)(`p`,{className:`text-sm font-medium`,children:`Failed to load activity`}),t[1]=a):a=t[1];let o;t[2]===n?o=t[3]:(o=(0,M.jsxs)(`div`,{className:`space-y-1`,children:[a,(0,M.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]}),t[2]=n,t[3]=o);let c;t[4]===r?c=t[5]:(c=(0,M.jsx)(_,{type:`button`,variant:`outline`,size:`sm`,onClick:r,children:`Retry`}),t[4]=r,t[5]=c);let l;return t[6]!==o||t[7]!==c?(l=(0,M.jsxs)(`div`,{className:`flex flex-col items-center gap-3 p-6 text-center`,role:`alert`,"data-testid":`activity-panel-error`,children:[i,o,c]}),t[6]=o,t[7]=c,t[8]=l):l=t[8],l}function L(){let e=(0,A.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,M.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-muted-foreground`,"data-testid":`activity-panel-empty`,children:(0,M.jsx)(`p`,{className:`text-sm italic`,children:`No edits yet.`})}),e[0]=t):t=e[0],t}function be(e){let t=(0,A.c)(8),{onExit:n}=e,r;t[0]===n?r=t[1]:(r=(0,M.jsx)(R,{onClick:n}),t[0]=n,t[1]=r);let i;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,M.jsx)(`h2`,{className:`truncate text-sm font-medium`,children:`Agent activity`}),t[2]=i):i=t[2];let a;t[3]===r?a=t[4]:(a=(0,M.jsxs)(`div`,{className:`flex shrink-0 flex-row items-center gap-2 border-b border-border px-3 py-2`,children:[r,i]}),t[3]=r,t[4]=a);let o;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,M.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-muted-foreground`,children:(0,M.jsx)(`p`,{className:`text-center text-sm italic`,children:`Click an agent's avatar in the presence bar to view their session.`})}),t[5]=o):o=t[5];let s;return t[6]===a?s=t[7]:(s=(0,M.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col`,"data-testid":`activity-panel-no-agent`,"aria-label":`Agent activity`,children:[a,o]}),t[6]=a,t[7]=s),s}function R(e){let t=(0,A.c)(6),{onClick:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,M.jsx)(b,{}),t[0]=r):r=t[0];let i;t[1]===n?i=t[2]:(i=(0,M.jsx)(w,{asChild:!0,children:(0,M.jsx)(_,{type:`button`,variant:`ghost`,size:`icon`,className:`size-7 shrink-0`,onClick:n,"aria-label":`Back to document view`,"data-testid":`docpanel-exit-agent-mode`,children:r})}),t[1]=n,t[2]=i);let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,M.jsx)(T,{side:`bottom`,children:`Back to document view`}),t[3]=a):a=t[3];let o;return t[4]===i?o=t[5]:(o=(0,M.jsxs)(E,{children:[i,a]}),t[4]=i,t[5]=o),o}function z(e){let t=(0,A.c)(9),{lastTs:n}=e,[r]=(0,j.useState)(xe),i;t[0]!==n||t[1]!==r?(i=n?Se(r-n):null,t[0]=n,t[1]=r,t[2]=i):i=t[2];let a=i,o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,M.jsx)(`span`,{className:`font-medium`,children:`Session ended`}),t[3]=o):o=t[3];let s;t[4]===a?s=t[5]:(s=a?(0,M.jsxs)(`span`,{children:[` · `,a]}):null,t[4]=a,t[5]=s);let c;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,M.jsx)(`div`,{className:`mt-1 opacity-80`,children:`Undo buttons are disabled — per-session state has been garbage-collected.`}),t[6]=c):c=t[6];let l;return t[7]===s?l=t[8]:(l=(0,M.jsxs)(`div`,{className:`border-b border-border bg-muted/40 px-4 py-3 text-xs text-muted-foreground`,"data-testid":`activity-panel-session-ended`,children:[o,s,c]}),t[7]=s,t[8]=l),l}function xe(){return Date.now()}function Se(e){let t=Math.max(0,e);return t<6e4?`${Math.round(t/1e3)}s ago`:t<36e5?`${Math.round(t/6e4)}m ago`:`${Math.round(t/36e5)}h ago`}function B(e){let t=(0,A.c)(10),{agent:n,size:r}=e,i=r===void 0?28:r,a;t[0]!==n.color||t[1]!==i?(a={backgroundColor:n.color,width:i,height:i},t[0]=n.color,t[1]=i,t[2]=a):a=t[2];let o=i*.57,s=i*.57,c;t[3]!==n.icon||t[4]!==o||t[5]!==s?(c=(0,M.jsx)(x,{icon:n.icon,width:o,height:s}),t[3]=n.icon,t[4]=o,t[5]=s,t[6]=c):c=t[6];let l;return t[7]!==a||t[8]!==c?(l=(0,M.jsx)(`span`,{className:`inline-flex shrink-0 items-center justify-center rounded-full text-white ring-2 ring-background`,style:a,"aria-hidden":`true`,children:c}),t[7]=a,t[8]=c,t[9]=l):l=t[9],l}function Ce(e){let t=(0,A.c)(20),{data:n,status:r,error:i,reload:a,fetchBurstDiff:o,onExit:s,onNavigate:c,onUndoLast:l,onUndoAll:u}=e,d=n?.files?.[0]?.lastTs??null,f;t[0]===s?f=t[1]:(f=(0,M.jsx)(R,{onClick:s}),t[0]=s,t[1]=f);let p;t[2]===n?p=t[3]:(p=n?.agent?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(B,{agent:n.agent}),(0,M.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,M.jsx)(`h2`,{className:`truncate text-sm font-medium`,children:n.agent.displayName}),(0,M.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,children:[n.sessionAlive?`Active`:`Ended`,n.files.length>0?` · ${n.files.length} file${n.files.length===1?``:`s`}`:``]})]})]}):(0,M.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,M.jsx)(`h2`,{className:`truncate text-sm font-medium`,children:`Agent activity`})}),t[2]=n,t[3]=p);let m;t[4]!==f||t[5]!==p?(m=(0,M.jsxs)(`div`,{className:`flex flex-row items-center gap-2 border-b border-border px-3 py-2 shrink-0`,children:[f,p]}),t[4]=f,t[5]=p,t[6]=m):m=t[6];let h;t[7]!==n||t[8]!==i||t[9]!==o||t[10]!==d||t[11]!==c||t[12]!==u||t[13]!==l||t[14]!==a||t[15]!==r?(h=(0,M.jsx)(`div`,{className:`flex-1 overflow-y-auto`,"data-testid":`activity-panel-body`,children:r===`loading`&&n===null?(0,M.jsx)(ve,{}):r===`error`&&i?(0,M.jsx)(ye,{error:i,onRetry:a}):n===null?(0,M.jsx)(L,{}):(0,M.jsxs)(M.Fragment,{children:[n.sessionAlive?null:(0,M.jsx)(z,{lastTs:d}),n.files.length===0?(0,M.jsx)(L,{}):n.files.map(e=>(0,M.jsx)(P,{file:e,sessionAlive:n.sessionAlive,isWriting:n.writingDocs.has(e.docName),onNavigate:c,onUndoLast:l,onUndoAll:u,fetchBurstDiff:o},e.docName))]})}),t[7]=n,t[8]=i,t[9]=o,t[10]=d,t[11]=c,t[12]=u,t[13]=l,t[14]=a,t[15]=r,t[16]=h):h=t[16];let g;return t[17]!==m||t[18]!==h?(g=(0,M.jsxs)(`section`,{className:`flex h-full min-h-0 flex-col`,"data-testid":`activity-panel`,"aria-label":`Agent activity`,children:[m,h]}),t[17]=m,t[18]=h,t[19]=g):g=t[19],g}function V(){let e=(0,A.c)(22),{docPanelAgentId:t,closeActivityPanel:n}=l(),{openDocumentTransition:r}=d(),{data:i,status:a,error:o,reload:s,fetchBurstDiff:c}=ce(t);if(t===null){let t;return e[0]===n?t=e[1]:(t=(0,M.jsx)(be,{onExit:n}),e[0]=n,e[1]=t),t}let u;e[2]===r?u=e[3]:(u=e=>{r(e),I(e)},e[2]=r,e[3]=u);let f=u,p;e[4]!==i||e[5]!==t||e[6]!==s?(p=async e=>{try{await F({connectionId:t,docName:e,scope:`last`,agentName:i?.agent?.displayName}),s()}catch(e){let t=e,n=t instanceof Error?t.message:String(t);C.error(`Undo failed: ${n}`),s()}},e[4]=i,e[5]=t,e[6]=s,e[7]=p):p=e[7];let m=p,h;e[8]!==i||e[9]!==t||e[10]!==s?(h=async e=>{try{await F({connectionId:t,docName:e,scope:`file`,agentName:i?.agent?.displayName}),C.success(`Undone all edits on ${e}`),s()}catch(e){let t=e,n=t instanceof Error?t.message:String(t);C.error(`Undo all failed: ${n}`),s()}},e[8]=i,e[9]=t,e[10]=s,e[11]=h):h=e[11];let g=h,_;return e[12]!==n||e[13]!==i||e[14]!==o||e[15]!==c||e[16]!==f||e[17]!==g||e[18]!==m||e[19]!==s||e[20]!==a?(_=(0,M.jsx)(Ce,{data:i,status:a,error:o,reload:s,fetchBurstDiff:c,onExit:n,onNavigate:f,onUndoLast:m,onUndoAll:g}),e[12]=n,e[13]=i,e[14]=o,e[15]=c,e[16]=f,e[17]=g,e[18]=m,e[19]=s,e[20]=a,e[21]=_):_=e[21],_}export{V as ActivityModeContent};
@@ -1,2 +1,2 @@
1
- import{o as e}from"./chunk-CFjPhJqf.js";import{n as t,r as n,t as r}from"./compiler-runtime-CVnuRdak.js";import{t as i}from"./button-BsFpqlpT.js";import{p as a}from"./dist-Dy1vgWd7.js";import{a as o,c as s,i as c,n as l,o as u,s as ee,t as te}from"./dialog-CKgDyF3E.js";import{t as ne}from"./input-CK6fFyb4.js";import{t as d}from"./consent-store-lB0p7dI5.js";import{t as re}from"./textarea-DeHOTn8t.js";var ie=r(),f=e(t(),1),p=n(),ae=750,oe={root:`You picked the filesystem root (/). Scaffolding here will scan every file on this machine — make sure that's what you want.`,home:`You picked your home directory. OK will index everything in your home tree — large and may surface personal files.`,"home-documents":`You picked ~/Documents. OK will index every markdown file under it. If you only want to manage a sub-folder, choose a smaller scope.`,"home-desktop":`You picked ~/Desktop. OK will index everything on your desktop.`,"home-downloads":`You picked ~/Downloads. Files there are usually transient — consider a stable folder instead.`,"volumes-mount":`This path is on an external volume (/Volumes/...). OK will lose track of files when the drive ejects.`,"drive-root":`This looks like a drive root (e.g., C:\\). Scaffolding here will scan an entire drive.`},m={error:e=>a.error(e)};function se(e){let t=(0,ie.c)(9),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{store:r,toast:i,payload:a}=n,o=r===void 0?d:r,s=i===void 0?m:i,c;t[2]!==a||t[3]!==o?(c=a??o.getSnapshot(),t[2]=a,t[3]=o,t[4]=c):c=t[4];let l=c;if(!l)return null;let u;return t[5]!==l||t[6]!==o||t[7]!==s?(u=(0,p.jsx)(h,{payload:l,store:o,toast:s}),t[5]=l,t[6]=o,t[7]=s,t[8]=u):u=t[8],u}function h(e){let t=(0,ie.c)(96),{payload:n,store:r,toast:a}=e,[d,oe]=(0,f.useState)(n.defaultContentDir),[m,se]=(0,f.useState)(``),h;t[0]===n.editorOptions?h=t[1]:(h=()=>new Set(n.editorOptions.map(le)),t[0]=n.editorOptions,t[1]=h);let[g,pe]=(0,f.useState)(h),[me,he]=(0,f.useState)(null),[_,ge]=(0,f.useState)(!1),[_e,ve]=(0,f.useState)(null),ye,be;t[2]===d?(ye=t[3],be=t[4]):(ye=()=>{if(!de(d)){he(null);return}let e=!1,t=setTimeout(()=>{let t=window.okDesktop;t&&t.onboarding.probeContent({contentDir:d}).then(t=>{e||he(t)}).catch(t=>{e||he({ok:!1,error:t instanceof Error?t.message:`probe failed`})})},ae);return()=>{e=!0,clearTimeout(t)}},be=[d],t[2]=d,t[3]=ye,t[4]=be),(0,f.useEffect)(ye,be);let xe;t[5]===d?xe=t[6]:(xe=de(d),t[5]=d,t[6]=xe);let v=xe,y=_||!v,b;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(b=function(e){pe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},t[7]=b):b=t[7];let Se=b,x;t[8]===n.projectDir?x=t[9]:(x=async function(){let e=window.okDesktop;if(!e)return;let t;try{t=await e.dialog.openFolder({defaultPath:n.projectDir})}catch(e){let t=e;ve(t instanceof Error?t.message:`Could not open folder picker`);return}if(t===null)return;let r=ue(n.projectDir,t);if(r===null){ve(`Selection must be inside the project`);return}ve(null),oe(r)},t[8]=n.projectDir,t[9]=x);let Ce=x,S;t[10]!==m||t[11]!==d||t[12]!==g||t[13]!==r||t[14]!==a?(S=async function(){ge(!0);let e=await r.confirm({initGit:!0,contentDir:d,additionalIgnores:m,editorIds:Array.from(g)});e.ok||(a.error(e.error),ge(!1))},t[10]=m,t[11]=d,t[12]=g,t[13]=r,t[14]=a,t[15]=S):S=t[15];let we=S,C;t[16]!==we||t[17]!==y?(C=function(e){e.preventDefault(),!y&&we()},t[16]=we,t[17]=y,t[18]=C):C=t[18];let Te=C,w;t[19]!==r||t[20]!==a?(w=async function(){ge(!0);let e=await r.cancel();e.ok||(a.error(e.error),ge(!1))},t[19]=r,t[20]=a,t[21]=w):w=t[21];let T=w,E;t[22]!==_||t[23]!==T?(E=function(e){!e&&!_&&T()},t[22]=_,t[23]=T,t[24]=E):E=t[24];let Ee=E,D;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,p.jsx)(s,{children:`Open this folder with Open Knowledge`}),t[25]=D):D=t[25];let O;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,p.jsxs)(ee,{children:[D,(0,p.jsxs)(o,{children:[`Open Knowledge will create a `,(0,p.jsx)(`code`,{children:`.ok/`}),` folder to track this project's metadata. Click Start to proceed with the defaults below — adjust any field first, or Cancel to leave the folder untouched.`]})]}),t[26]=O):O=t[26];let k;t[27]!==n.defaultContentDir||t[28]!==n.gitRootPromoted||t[29]!==n.projectDir?(k=n.gitRootPromoted?(0,p.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`OK will be initialized at `,(0,p.jsx)(`code`,{children:n.projectDir}),` (one .ok/ per git repo). Scoped to `,(0,p.jsxs)(`code`,{children:[n.defaultContentDir,`/`]}),` — change "Content directory" if you want a different scope.`]}):null,t[27]=n.defaultContentDir,t[28]=n.gitRootPromoted,t[29]=n.projectDir,t[30]=k):k=t[30];let A;t[31]===n.warnings?A=t[32]:(A=n.warnings.length>0?(0,p.jsx)(`div`,{role:`alert`,className:`rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-700 dark:bg-amber-950 dark:text-amber-200`,children:n.warnings.map(ce)}):null,t[31]=n.warnings,t[32]=A);let j;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,p.jsx)(`label`,{htmlFor:`consent-content-dir`,className:`mb-1 block text-sm font-medium`,children:`Content directory`}),t[33]=j):j=t[33];let De;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(De=e=>{oe(e.target.value),ve(null)},t[34]=De):De=t[34];let Oe=!v,M;t[35]!==_||t[36]!==d||t[37]!==Oe?(M=(0,p.jsx)(ne,{id:`consent-content-dir`,value:d,onChange:De,disabled:_,"aria-invalid":Oe,"data-testid":`consent-content-dir`,className:`flex-1`}),t[35]=_,t[36]=d,t[37]=Oe,t[38]=M):M=t[38];let N;t[39]===Ce?N=t[40]:(N=()=>void Ce(),t[39]=Ce,t[40]=N);let P;t[41]!==_||t[42]!==N?(P=(0,p.jsx)(i,{type:`button`,variant:`outline`,disabled:_,onClick:N,"data-testid":`consent-content-dir-browse`,children:`Browse…`}),t[41]=_,t[42]=N,t[43]=P):P=t[43];let F;t[44]!==M||t[45]!==P?(F=(0,p.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[M,P]}),t[44]=M,t[45]=P,t[46]=F):F=t[46];let I;t[47]!==_e||t[48]!==v||t[49]!==me?(I=_e===null?v?(0,p.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,"data-testid":`consent-preview`,children:fe(me)}):(0,p.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,"data-testid":`consent-content-dir-error`,children:`Content directory must be inside the project`}):(0,p.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,"data-testid":`consent-content-dir-browse-error`,children:_e}),t[47]=_e,t[48]=v,t[49]=me,t[50]=I):I=t[50];let L;t[51]!==F||t[52]!==I?(L=(0,p.jsxs)(`div`,{children:[j,F,I]}),t[51]=F,t[52]=I,t[53]=L):L=t[53];let R;t[54]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,p.jsx)(`label`,{htmlFor:`consent-additional-ignores`,className:`mb-1 block text-sm font-medium`,children:`Ignore patterns`}),t[54]=R):R=t[54];let z;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(z=e=>se(e.target.value),t[55]=z):z=t[55];let B;t[56]!==m||t[57]!==_?(B=(0,p.jsx)(re,{id:`consent-additional-ignores`,value:m,onChange:z,disabled:_,placeholder:`tmp/
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{n as t,r as n,t as r}from"./compiler-runtime-CVnuRdak.js";import{t as i}from"./button-C1nwPVFQ.js";import{p as a}from"./dist-OTL8-1C2.js";import{a as o,c as s,i as c,n as l,o as u,s as ee,t as te}from"./dialog-BFN-ujuF.js";import{t as ne}from"./input-BOmkuBId.js";import{t as d}from"./consent-store-lB0p7dI5.js";import{t as re}from"./textarea-57j4gLcZ.js";var ie=r(),f=e(t(),1),p=n(),ae=750,oe={root:`You picked the filesystem root (/). Scaffolding here will scan every file on this machine — make sure that's what you want.`,home:`You picked your home directory. OK will index everything in your home tree — large and may surface personal files.`,"home-documents":`You picked ~/Documents. OK will index every markdown file under it. If you only want to manage a sub-folder, choose a smaller scope.`,"home-desktop":`You picked ~/Desktop. OK will index everything on your desktop.`,"home-downloads":`You picked ~/Downloads. Files there are usually transient — consider a stable folder instead.`,"volumes-mount":`This path is on an external volume (/Volumes/...). OK will lose track of files when the drive ejects.`,"drive-root":`This looks like a drive root (e.g., C:\\). Scaffolding here will scan an entire drive.`},m={error:e=>a.error(e)};function se(e){let t=(0,ie.c)(9),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{store:r,toast:i,payload:a}=n,o=r===void 0?d:r,s=i===void 0?m:i,c;t[2]!==a||t[3]!==o?(c=a??o.getSnapshot(),t[2]=a,t[3]=o,t[4]=c):c=t[4];let l=c;if(!l)return null;let u;return t[5]!==l||t[6]!==o||t[7]!==s?(u=(0,p.jsx)(h,{payload:l,store:o,toast:s}),t[5]=l,t[6]=o,t[7]=s,t[8]=u):u=t[8],u}function h(e){let t=(0,ie.c)(96),{payload:n,store:r,toast:a}=e,[d,oe]=(0,f.useState)(n.defaultContentDir),[m,se]=(0,f.useState)(``),h;t[0]===n.editorOptions?h=t[1]:(h=()=>new Set(n.editorOptions.map(le)),t[0]=n.editorOptions,t[1]=h);let[g,pe]=(0,f.useState)(h),[me,he]=(0,f.useState)(null),[_,ge]=(0,f.useState)(!1),[_e,ve]=(0,f.useState)(null),ye,be;t[2]===d?(ye=t[3],be=t[4]):(ye=()=>{if(!de(d)){he(null);return}let e=!1,t=setTimeout(()=>{let t=window.okDesktop;t&&t.onboarding.probeContent({contentDir:d}).then(t=>{e||he(t)}).catch(t=>{e||he({ok:!1,error:t instanceof Error?t.message:`probe failed`})})},ae);return()=>{e=!0,clearTimeout(t)}},be=[d],t[2]=d,t[3]=ye,t[4]=be),(0,f.useEffect)(ye,be);let xe;t[5]===d?xe=t[6]:(xe=de(d),t[5]=d,t[6]=xe);let v=xe,y=_||!v,b;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(b=function(e){pe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},t[7]=b):b=t[7];let Se=b,x;t[8]===n.projectDir?x=t[9]:(x=async function(){let e=window.okDesktop;if(!e)return;let t;try{t=await e.dialog.openFolder({defaultPath:n.projectDir})}catch(e){let t=e;ve(t instanceof Error?t.message:`Could not open folder picker`);return}if(t===null)return;let r=ue(n.projectDir,t);if(r===null){ve(`Selection must be inside the project`);return}ve(null),oe(r)},t[8]=n.projectDir,t[9]=x);let Ce=x,S;t[10]!==m||t[11]!==d||t[12]!==g||t[13]!==r||t[14]!==a?(S=async function(){ge(!0);let e=await r.confirm({initGit:!0,contentDir:d,additionalIgnores:m,editorIds:Array.from(g)});e.ok||(a.error(e.error),ge(!1))},t[10]=m,t[11]=d,t[12]=g,t[13]=r,t[14]=a,t[15]=S):S=t[15];let we=S,C;t[16]!==we||t[17]!==y?(C=function(e){e.preventDefault(),!y&&we()},t[16]=we,t[17]=y,t[18]=C):C=t[18];let Te=C,w;t[19]!==r||t[20]!==a?(w=async function(){ge(!0);let e=await r.cancel();e.ok||(a.error(e.error),ge(!1))},t[19]=r,t[20]=a,t[21]=w):w=t[21];let T=w,E;t[22]!==_||t[23]!==T?(E=function(e){!e&&!_&&T()},t[22]=_,t[23]=T,t[24]=E):E=t[24];let Ee=E,D;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,p.jsx)(s,{children:`Open this folder with Open Knowledge`}),t[25]=D):D=t[25];let O;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,p.jsxs)(ee,{children:[D,(0,p.jsxs)(o,{children:[`Open Knowledge will create a `,(0,p.jsx)(`code`,{children:`.ok/`}),` folder to track this project's metadata. Click Start to proceed with the defaults below — adjust any field first, or Cancel to leave the folder untouched.`]})]}),t[26]=O):O=t[26];let k;t[27]!==n.defaultContentDir||t[28]!==n.gitRootPromoted||t[29]!==n.projectDir?(k=n.gitRootPromoted?(0,p.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`OK will be initialized at `,(0,p.jsx)(`code`,{children:n.projectDir}),` (one .ok/ per git repo). Scoped to `,(0,p.jsxs)(`code`,{children:[n.defaultContentDir,`/`]}),` — change "Content directory" if you want a different scope.`]}):null,t[27]=n.defaultContentDir,t[28]=n.gitRootPromoted,t[29]=n.projectDir,t[30]=k):k=t[30];let A;t[31]===n.warnings?A=t[32]:(A=n.warnings.length>0?(0,p.jsx)(`div`,{role:`alert`,className:`rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-700 dark:bg-amber-950 dark:text-amber-200`,children:n.warnings.map(ce)}):null,t[31]=n.warnings,t[32]=A);let j;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,p.jsx)(`label`,{htmlFor:`consent-content-dir`,className:`mb-1 block text-sm font-medium`,children:`Content directory`}),t[33]=j):j=t[33];let De;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(De=e=>{oe(e.target.value),ve(null)},t[34]=De):De=t[34];let Oe=!v,M;t[35]!==_||t[36]!==d||t[37]!==Oe?(M=(0,p.jsx)(ne,{id:`consent-content-dir`,value:d,onChange:De,disabled:_,"aria-invalid":Oe,"data-testid":`consent-content-dir`,className:`flex-1`}),t[35]=_,t[36]=d,t[37]=Oe,t[38]=M):M=t[38];let N;t[39]===Ce?N=t[40]:(N=()=>void Ce(),t[39]=Ce,t[40]=N);let P;t[41]!==_||t[42]!==N?(P=(0,p.jsx)(i,{type:`button`,variant:`outline`,disabled:_,onClick:N,"data-testid":`consent-content-dir-browse`,children:`Browse…`}),t[41]=_,t[42]=N,t[43]=P):P=t[43];let F;t[44]!==M||t[45]!==P?(F=(0,p.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[M,P]}),t[44]=M,t[45]=P,t[46]=F):F=t[46];let I;t[47]!==_e||t[48]!==v||t[49]!==me?(I=_e===null?v?(0,p.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,"data-testid":`consent-preview`,children:fe(me)}):(0,p.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,"data-testid":`consent-content-dir-error`,children:`Content directory must be inside the project`}):(0,p.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,"data-testid":`consent-content-dir-browse-error`,children:_e}),t[47]=_e,t[48]=v,t[49]=me,t[50]=I):I=t[50];let L;t[51]!==F||t[52]!==I?(L=(0,p.jsxs)(`div`,{children:[j,F,I]}),t[51]=F,t[52]=I,t[53]=L):L=t[53];let R;t[54]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,p.jsx)(`label`,{htmlFor:`consent-additional-ignores`,className:`mb-1 block text-sm font-medium`,children:`Ignore patterns`}),t[54]=R):R=t[54];let z;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(z=e=>se(e.target.value),t[55]=z):z=t[55];let B;t[56]!==m||t[57]!==_?(B=(0,p.jsx)(re,{id:`consent-additional-ignores`,value:m,onChange:z,disabled:_,placeholder:`tmp/
2
2
  *.draft.md`,rows:3,"data-testid":`consent-additional-ignores`}),t[56]=m,t[57]=_,t[58]=B):B=t[58];let V;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,p.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`One pattern per line — appended to `,(0,p.jsx)(`code`,{children:`.okignore`}),`.`]}),t[59]=V):V=t[59];let H;t[60]===B?H=t[61]:(H=(0,p.jsxs)(`div`,{children:[R,B,V]}),t[60]=B,t[61]=H);let U;t[62]===Symbol.for(`react.memo_cache_sentinel`)?(U=(0,p.jsx)(`legend`,{className:`text-sm font-medium`,children:`Connect to AI tools`}),t[62]=U):U=t[62];let W;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(W=(0,p.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`All editors are checked by default — uncheck the ones you don't use. Each checked editor's project-MCP config is written; the Claude Code entry also scaffolds`,` `,(0,p.jsx)(`code`,{children:`.claude/launch.json`}),`.`]}),t[63]=W):W=t[63];let G;if(t[64]!==_||t[65]!==g||t[66]!==n.editorOptions){let e;t[68]!==_||t[69]!==g?(e=e=>(0,p.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:g.has(e.id),onChange:()=>Se(e.id),disabled:_,className:`size-4 shrink-0 rounded accent-primary`,"data-testid":`consent-editor-${e.id}`}),(0,p.jsx)(`span`,{children:e.label}),(0,p.jsx)(`span`,{className:`text-xs text-muted-foreground`,"data-testid":`consent-editor-${e.id}-scope`,children:e.hasProjectConfig?`(project + user)`:`(user-level only)`})]},e.id),t[68]=_,t[69]=g,t[70]=e):e=t[70],G=n.editorOptions.map(e),t[64]=_,t[65]=g,t[66]=n.editorOptions,t[67]=G}else G=t[67];let K;t[71]===G?K=t[72]:(K=(0,p.jsxs)(`fieldset`,{className:`space-y-2 pb-2`,children:[U,W,G]}),t[71]=G,t[72]=K);let q;t[73]!==k||t[74]!==A||t[75]!==L||t[76]!==H||t[77]!==K?(q=(0,p.jsxs)(l,{className:`space-y-4`,children:[k,A,L,H,K]}),t[73]=k,t[74]=A,t[75]=L,t[76]=H,t[77]=K,t[78]=q):q=t[78];let J;t[79]===T?J=t[80]:(J=()=>void T(),t[79]=T,t[80]=J);let Y;t[81]!==_||t[82]!==J?(Y=(0,p.jsx)(i,{type:`button`,variant:`outline`,className:`font-mono uppercase`,onClick:J,disabled:_,"data-testid":`consent-cancel`,children:`Cancel`}),t[81]=_,t[82]=J,t[83]=Y):Y=t[83];let X;t[84]===y?X=t[85]:(X=(0,p.jsx)(i,{type:`submit`,disabled:y,"data-testid":`consent-start`,children:`Start`}),t[84]=y,t[85]=X);let Z;t[86]!==Y||t[87]!==X?(Z=(0,p.jsxs)(u,{children:[Y,X]}),t[86]=Y,t[87]=X,t[88]=Z):Z=t[88];let Q;t[89]!==Te||t[90]!==q||t[91]!==Z?(Q=(0,p.jsxs)(c,{className:`sm:max-w-lg motion-reduce:duration-0 motion-reduce:data-open:animate-none motion-reduce:data-closed:animate-none`,children:[O,(0,p.jsxs)(`form`,{onSubmit:Te,"data-testid":`consent-form`,className:`flex min-h-0 flex-1 flex-col`,children:[q,Z]})]}),t[89]=Te,t[90]=q,t[91]=Z,t[92]=Q):Q=t[92];let $;return t[93]!==Ee||t[94]!==Q?($=(0,p.jsx)(te,{open:!0,onOpenChange:Ee,children:Q}),t[93]=Ee,t[94]=Q,t[95]=$):$=t[95],$}function ce(e){return(0,p.jsx)(`p`,{className:`mb-1 last:mb-0`,children:oe[e.kind]},e.kind)}function le(e){return e.id}function ue(e,t){let n=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||(e.startsWith(`/`)?`/`:``),r=n(e),i=n(t);if(r===i)return`.`;let a=r.endsWith(`/`)?r:`${r}/`;return i.startsWith(a)?i.slice(a.length):null}function de(e){if(e===``||e===`.`)return!0;if(e.startsWith(`/`)||/^[A-Za-z]:/.test(e))return!1;let t=e.replace(/\\/g,`/`).split(`/`),n=0;for(let e of t)if(!(e===``||e===`.`))if(e===`..`){if(--n,n<0)return!1}else n+=1;return!0}function fe(e){if(e===null)return`Counting markdown files…`;if(!e.ok)return`Preview unavailable: ${e.error}`;let t=e.truncated?`≥ 50,000`:String(e.count);return e.sample.length===0?`Found ${t} markdown files`:`Found ${t} markdown files; sample: ${e.sample.join(`, `)}`}export{se as default,de as isContentDirSafe,ue as relativeToProject};