@inkeep/open-knowledge 0.54.0-beta.0 → 0.54.0-beta.2

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 (115) hide show
  1. package/dist/{acp-harness-probe-BAU5A5o3.mjs → acp-harness-probe-CdgnSiX1.mjs} +2 -2
  2. package/dist/cli.mjs +6 -6
  3. package/dist/constants-BfTkfLb_.mjs +2 -0
  4. package/dist/index.mjs +1 -1
  5. package/dist/{init-DqyJAJAm.mjs → init-BMOmCTtk.mjs} +3 -3
  6. package/dist/init-BgBNBsz1.mjs +1 -0
  7. package/dist/{launch-json-removal-CBpeW9Ah.mjs → launch-json-removal-lcolwR_B.mjs} +2 -2
  8. package/dist/{loader-BkusT1hI.mjs → loader-21jtkH8-.mjs} +2 -2
  9. package/dist/loader-DBCQd3aT.mjs +1 -0
  10. package/dist/{open-browser-BqA6XiT0.mjs → open-browser-DYnRS1jz.mjs} +2 -2
  11. package/dist/preview-CX7XU2cj.mjs +1 -0
  12. package/dist/{preview-kSEjxYuX.mjs → preview-DILIawX2.mjs} +2 -2
  13. package/dist/public/assets/{ActivityModeContent-CQnmKBGo.js → ActivityModeContent-BLw3WMWz.js} +1 -1
  14. package/dist/public/assets/{AgentDiffPane-BMJtHPB0.js → AgentDiffPane-DrZCRBSs.js} +1 -1
  15. package/dist/public/assets/{AgentThreadClientBinder-CSCbo226.js → AgentThreadClientBinder-CWcDlN8A.js} +1 -1
  16. package/dist/public/assets/{ChangedOutsideBadge-DGYi7hdZ.js → ChangedOutsideBadge-BRBEndlT.js} +1 -1
  17. package/dist/public/assets/{CodeMirrorPropInput-DywYyBz8.js → CodeMirrorPropInput-B5_xejDl.js} +1 -1
  18. package/dist/public/assets/{DocumentContext-CKR9tIsX.js → DocumentContext-y4udwaSS.js} +1 -1
  19. package/dist/public/assets/{EditorModeToggle-CiWiUMD4.js → EditorModeToggle-BlT04JPF.js} +1 -1
  20. package/dist/public/assets/{EnableSyncConfirmDialog-PNZ3-bzD.js → EnableSyncConfirmDialog-BKrwMqLx.js} +1 -1
  21. package/dist/public/assets/FeedbackForm-lEn2xy5h.js +1 -0
  22. package/dist/public/assets/{ImportSkillDialog-D_zbPvrz.js → ImportSkillDialog-Cx_uO9te.js} +1 -1
  23. package/dist/public/assets/{LintConfigEditor-CmDISx0R.js → LintConfigEditor-DpkMgp67.js} +1 -1
  24. package/dist/public/assets/{ManagedArtifactProperties-D1j8yV7G.js → ManagedArtifactProperties-DQV6Xkkp.js} +1 -1
  25. package/dist/public/assets/ManagedArtifactProperties-DfOLsWxL.js +1 -0
  26. package/dist/public/assets/{MermaidDocEditor-CClwSJEd.js → MermaidDocEditor-D02-RjZh.js} +1 -1
  27. package/dist/public/assets/SchemaConfigEditor-DhU_jWFU.js +1 -0
  28. package/dist/public/assets/{SessionsHost-DvCES4YX.js → SessionsHost-aL9Yi0YA.js} +2 -2
  29. package/dist/public/assets/{SettingsDialogBody-CGs75yJY.js → SettingsDialogBody-FvV7PJ-x.js} +4 -4
  30. package/dist/public/assets/{ShareReceiveMissDialog-B-CD8c9A.js → ShareReceiveMissDialog-C6Fw1jSy.js} +1 -1
  31. package/dist/public/assets/{SkillToolbarControls-BbJJTW3S.js → SkillToolbarControls-CV5iqOyh.js} +1 -1
  32. package/dist/public/assets/{SourceEditor-Dakmm381.js → SourceEditor-Cgcjeeix.js} +1 -1
  33. package/dist/public/assets/{TerminalWindowApp-Bzecjegv.js → TerminalWindowApp-pFQbcyvr.js} +1 -1
  34. package/dist/public/assets/{TextDocEditor-B73XTMKM.js → TextDocEditor-BIvaeGcP.js} +1 -1
  35. package/dist/public/assets/ThreadView-uJiWLV3S.js +10 -0
  36. package/dist/public/assets/{TimelineDiffPane-BnuEYjxI.js → TimelineDiffPane-DP3x-bCT.js} +1 -1
  37. package/dist/public/assets/{agent-diff-store-CJK-vc6Z.js → agent-diff-store-BvJOHqlb.js} +1 -1
  38. package/dist/public/assets/{auth-state-cache-BR8S3JrV.js → auth-state-cache-B-pvyyml.js} +1 -1
  39. package/dist/public/assets/{client-version-stzG9fok.js → client-version-Dl9MDBtc.js} +1 -1
  40. package/dist/public/assets/{comment-chips-VYzrfZOz.js → comment-chips-JdDlBBOC.js} +1 -1
  41. package/dist/public/assets/{config-provider-K5pliovj.js → config-provider-BEm_X5z4.js} +3 -3
  42. package/dist/public/assets/{follow-file-CoVZeHYJ.js → follow-file-DXj47N4P.js} +4 -4
  43. package/dist/public/assets/globals-CJLw9I7s.css +1 -0
  44. package/dist/public/assets/i18n-9-u0vIHQ.js +1 -0
  45. package/dist/public/assets/{index-CQiP7zms.js → index-CzQHudrL.js} +7 -7
  46. package/dist/public/assets/messages-70uyb6Sl.js +1 -0
  47. package/dist/public/assets/messages-BZmGV91Y.js +1 -0
  48. package/dist/public/assets/messages-C5UOlhWV.js +1 -0
  49. package/dist/public/assets/messages-C9FmY7uu.js +1 -0
  50. package/dist/public/assets/messages-CW3KcnxY.js +1 -0
  51. package/dist/public/assets/messages-CaxDnJNi.js +1 -0
  52. package/dist/public/assets/messages-CdzCdHWg.js +1 -0
  53. package/dist/public/assets/messages-D0j48ldR.js +1 -0
  54. package/dist/public/assets/messages-DvPjiVuw.js +1 -0
  55. package/dist/public/assets/messages-h8GDTlCf.js +1 -0
  56. package/dist/public/assets/messages-vdVQRalr.js +1 -0
  57. package/dist/public/assets/{pending-receive-nav-store-CaeSNfXj.js → pending-receive-nav-store-NNPZxbyU.js} +1 -1
  58. package/dist/public/assets/schema-fields-view-intent-DGCRVgw4.js +1 -0
  59. package/dist/public/assets/{selection-context-DPs8vxvW.js → selection-context-DaBEt_qe.js} +1 -1
  60. package/dist/public/assets/{skill-actions-CzmorCTi.js → skill-actions-rrqHJf1p.js} +1 -1
  61. package/dist/public/assets/{src-B87zThCs.js → src-D9vfSdRg.js} +1 -1
  62. package/dist/public/assets/{telemetry-impl-DSYzVKpq.js → telemetry-impl-CyzYpIO_.js} +1 -1
  63. package/dist/public/assets/{telemetry-startup-Da9NTocG.js → telemetry-startup-D_qndbLQ.js} +1 -1
  64. package/dist/public/assets/thread-client-CDd-DZmX.js +1 -0
  65. package/dist/public/assets/{typing-burst-detector-BY-anD9p.js → typing-burst-detector-4lnkqJUG.js} +1 -1
  66. package/dist/public/assets/{uninstall-wgIMFaoT.js → uninstall-DvHaOfxL.js} +1 -1
  67. package/dist/public/assets/{use-activity-panel-DqTP5DTk.js → use-activity-panel-YwUA1Y9R.js} +1 -1
  68. package/dist/public/assets/{use-open-skill-BK6woDan.js → use-open-skill-CLA3orpv.js} +1 -1
  69. package/dist/public/assets/{use-popular-skills-Wut1asdd.js → use-popular-skills-DRLF7dJB.js} +1 -1
  70. package/dist/public/assets/{use-terminal-enabled-CuoUv2VD.js → use-terminal-enabled-NR-FDyhW.js} +1 -1
  71. package/dist/public/assets/{use-timeline-entry-diff-Ci46DL5w.js → use-timeline-entry-diff-D_UL2qvn.js} +1 -1
  72. package/dist/public/index.html +23 -23
  73. package/dist/public/uninstall.html +5 -5
  74. package/dist/{repair-launch-json-CbCU3tYc.mjs → repair-launch-json-BGuk6v5-.mjs} +2 -2
  75. package/dist/{repair-mcp-configs-DDEeRKrI.mjs → repair-mcp-configs-CxB7cmFQ.mjs} +2 -2
  76. package/dist/{repair-skills-DTNqAGfI.mjs → repair-skills-CfH-4HV1.mjs} +2 -2
  77. package/dist/repair-skills-eHShRAdH.mjs +1 -0
  78. package/dist/{skill-teardown-ottam6sV.mjs → skill-teardown-BDCZSEP-.mjs} +2 -2
  79. package/dist/src-D3K5FFwY.mjs +1 -0
  80. package/dist/{src-BA3VPog2.mjs → src-D3S37RZY.mjs} +2 -2
  81. package/dist/{src-BF0nCoer.mjs → src-DCqoFl4a.mjs} +1 -1
  82. package/dist/src-Da93CAF3.mjs +2040 -0
  83. package/dist/start-9YOKl_ky.mjs +1 -0
  84. package/dist/{start-BbzEXh_C.mjs → start-Buf2BHBD.mjs} +4 -4
  85. package/dist/{ui-B7mhq8_g.mjs → ui-CGn0Cm6_.mjs} +3 -3
  86. package/dist/{write-project-skill-DWGQrWRr.mjs → write-project-skill-Bzg8sfOX.mjs} +2 -2
  87. package/package.json +4 -4
  88. package/dist/constants-CdO7Ip8K.mjs +0 -2
  89. package/dist/init-Cc1kMhai.mjs +0 -1
  90. package/dist/loader-COoyAZy6.mjs +0 -1
  91. package/dist/preview-eDBiuPbb.mjs +0 -1
  92. package/dist/public/assets/FeedbackForm-CNHw5U32.js +0 -1
  93. package/dist/public/assets/ManagedArtifactProperties-C5neRevI.js +0 -1
  94. package/dist/public/assets/SchemaConfigEditor-DmzRjNLX.js +0 -1
  95. package/dist/public/assets/ThreadView-Dyqxn2Co.js +0 -10
  96. package/dist/public/assets/globals-Cl9DVROF.css +0 -1
  97. package/dist/public/assets/i18n-DdNV3ihn.js +0 -1
  98. package/dist/public/assets/messages-BD6xU0hl.js +0 -1
  99. package/dist/public/assets/messages-BrOihCC2.js +0 -1
  100. package/dist/public/assets/messages-CeGZ3qGI.js +0 -1
  101. package/dist/public/assets/messages-DLAxD4Ea.js +0 -1
  102. package/dist/public/assets/messages-DiRAd1Pa.js +0 -1
  103. package/dist/public/assets/messages-DoSs73jK.js +0 -1
  104. package/dist/public/assets/messages-FGGtYX0Z.js +0 -1
  105. package/dist/public/assets/messages-QNJusJtV.js +0 -1
  106. package/dist/public/assets/messages-T7J7xjCi.js +0 -1
  107. package/dist/public/assets/messages-rE7VifgH.js +0 -1
  108. package/dist/public/assets/messages-zscDryNK.js +0 -1
  109. package/dist/public/assets/schema-fields-view-intent-D0jz38_6.js +0 -1
  110. package/dist/public/assets/thread-client-DnaLPSLV.js +0 -1
  111. package/dist/repair-skills-DI3Fy43j.mjs +0 -1
  112. package/dist/src-BPm9wAhY.mjs +0 -1
  113. package/dist/src-BXlWNOZp.mjs +0 -2040
  114. package/dist/start-CfJGPzvO.mjs +0 -1
  115. /package/dist/public/assets/{globals-CI7YXh9U.js → globals-DMS6iUdG.js} +0 -0
@@ -0,0 +1 @@
1
+ import{T as e,_ as t,m as n,n as r}from"./start-Buf2BHBD.mjs";export{r as bootStartServer,n as resolveBundledReactShellDir,t as resolveHost,e as startCommand};
@@ -1,12 +1,12 @@
1
- import{M as e}from"./sleep-C7muMiHm.mjs";import{Hs as t,Js as n,Ks as r,Vs as i,Ws as a,qs as o}from"./src-BqZfalMj.mjs";import{Pn as s,a as ee,si as c}from"./src-BXlWNOZp.mjs";import{b as l,v as u,y as d}from"./write-project-skill-DWGQrWRr.mjs";import{a as f,c as p,d as m,i as h,o as g,r as _,t as v}from"./acp-harness-probe-BAU5A5o3.mjs";import{n as y}from"./constants-CdO7Ip8K.mjs";import{spawn as b}from"node:child_process";import{basename as x,resolve as S}from"node:path";import{existsSync as C}from"node:fs";import{rm as w}from"node:fs/promises";import{setTimeout as te}from"node:timers/promises";function T(e,t){return e.bind?.[0]??e.host??t.HOST??`127.0.0.1`}function E(e){if(e===`ui`||e===`server`)return e;throw new d(`--only must be 'ui' or 'server'`)}function D(e=C){let t=import.meta.dirname??new URL(`.`,import.meta.url).pathname;return[S(t,`public`),S(t,`../../app/dist`),S(t,`../../../app/dist`)].find(t=>e(t))}function O(e){if(e.explicitDir!==void 0)return{dir:e.explicitDir,missingBundle:!1};if(e.only===`server`)return{dir:void 0,missingBundle:!1};let t=e.findBundledDir();return{dir:t,missingBundle:t===void 0}}function k(t){if(t===`off`)return`off`;if(!e.test(t))throw new d(`--idle-shutdown must be 'off' or a duration like 90s, 30m, 2h`);return t}function A(e){return e===`localhost`||e===`::1`||e===`[::1]`||e.startsWith(`127.`)}function j(e){return!e.flagBindSet&&!e.okBindSet&&e.hostEnvSet&&e.fileBindCount>1}function M(e){return!e.openBrowser||e.remoteEnabled||e.ephemeral||e.only===`server`||!e.servesUi?!1:e.legacyOpen?!0:(e.explicitOn||A(e.host))&&e.isTTY}function N(e,t){return t&&(e===`::`||e===`::1`||e===`[::1]`||e===`localhost`||e===`0.0.0.0`)?{host:`127.0.0.1`,coerced:!0}:{host:e,coerced:!1}}function P(e,n){return t(n)?e:{externalUrl:e.externalUrl,idleShutdown:e.idleShutdown}}function F(e,t){if(e===void 0||e===!1)return null;let n=typeof e==`string`?e:t;if(n===void 0||n===``)return{ok:!1,errorMessage:"--remote requires a public tunnel URL — pass it (`ok start --remote https://<your-tunnel-host>`) or set remote.url in .ok/config.yml."};let r;try{r=new URL(n)}catch{return{ok:!1,errorMessage:`remote.url is not a valid URL: ${n}`}}if(r.protocol!==`https:`)return{ok:!1,errorMessage:`remote.url must be https — it is the public tunnel URL remote clients connect to (got: ${n})`};let i=n.replace(/\/+$/,``);return{ok:!0,url:i,serverOverlay:{externalUrl:i,allowExternal:!0,idleShutdown:`off`}}}function I(e,t){let n;try{n=new URL(t)}catch{throw new d(`${e} is not a valid URL: ${t}`)}if(n.protocol!==`http:`&&n.protocol!==`https:`)throw new d(`${e} must be an http(s) origin (got: ${t})`);return t}function L(e){return I(`--external-url`,e)}function ne(e){return e.externalUrl??e.publicUrl}function R(e){return I(`--public-url`,e)}function z(e){let t=x(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var B=class extends Error{cwd;constructor(e){super("This directory isn't set up yet. Run `ok init` first, then `ok start` again."),this.name=`OkDirMissingError`,this.cwd=e}};function V(e,t,n=!1){return e??(n?void 0:t)}function H(e,t,n=e=>w(e,{recursive:!0,force:!0})){return async()=>{try{await e()}finally{try{await n(t)}catch(e){process.stderr.write(`[start] ephemeral temp dir reap failed for ${t}: ${e instanceof Error?e.message:String(e)}\n`)}}}}function U(e,t={}){let n=t.exit??(e=>process.exit(e)),r=t.getActiveHandles??(()=>{let e=process._getActiveHandles;return e?e.call(process):null});return async()=>{let i=!1;try{await e()}catch(e){i=!0,t.log?.error({err:e},`idle-shutdown: destroy failed — exiting anyway`)}finally{let e=null;try{let t=r();if(t!==null){e={};for(let n of t){let t=n?.constructor?.name??`unknown`;e[t]=(e[t]??0)+1}}}catch{e=null}t.log?.info({event:`idle-shutdown-exit`,exitCode:+!!i,openHandles:e??{},handlesAvailable:e!==null},`idle-shutdown: teardown finished — exiting process`),n(+!!i)}}}async function W(e){let{config:t,cwd:n,host:r}=e,i=e.skipAutoInit??!1,a=e.idleThresholdMs===void 0?18e5:e.idleThresholdMs,{existsSync:o,mkdirSync:l}=await import(`node:fs`),{basename:u,dirname:d}=await import(`node:path`),{bootServer:f,getLogger:h,resolveContentDir:g,resolveLockDir:_,waitForServerLockDrain:y}=await import(`./src-BF0nCoer.mjs`),b=e.log??h(`start`),x=e.singleFile!==void 0,S=e.projectDir??n,C=x?ee(e.singleFile).canonicalFilePath:void 0,w=C?d(C):void 0,te=C?u(C):void 0;if(!x){if(!i&&!s(n))throw new B(n);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{let t=typeof e.event==`string`?e.event:``;(t.endsWith(`-failed`)||t.endsWith(`-error`)||t.endsWith(`-missing`))&&b.warn({event:e},`[start] reclaim sweep reported a problem`)};try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-DDEeRKrI.mjs`)).repairMcpConfigs)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){b.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-CbCU3tYc.mjs`)).repairLaunchJson)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){b.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-DI3Fy43j.mjs`)).repairSkills)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){b.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let T=w??g(t,n);!x&&!o(T)&&(l(T,{recursive:!0}),b.info({contentDir:T},`Created content directory`));let E=m(),D=c();{let e=_(x?S:n),t=Date.now(),r=await y(e);r!==`no-drain`&&b.info({event:`start-waited-for-draining-predecessor`,outcome:r,waitedMs:Date.now()-t,drainLockDir:e},r===`released`?`[start] predecessor server finished draining — proceeding`:`[start] predecessor server still draining after wait — proceeding to collide`)}let O=await f({config:t,contentDir:T,projectDir:x?S:n,contentRoot:x?void 0:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:p,tokenStore:E,embeddingsKeyStore:D,...x?{ephemeral:!0,singleDocRelPath:te,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],probeHarnessManagedMcpEntry:(e,t)=>v(e,t),idleShutdownMs:a,...e.serverRuntime===void 0?{}:{serverRuntime:e.serverRuntime},...e.bind===void 0?{}:{bind:e.bind},skipAutoInit:!0,idleShutdownHandler:t=>{let n=t;return U(x?H(n,S):n,{log:b,exit:e.idleExit})},log:b,...e.serveContentAssets===void 0?{}:{serveContentAssets:e.serveContentAssets},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}});return{httpServer:O.httpServer,destroy:O.destroy,lockDir:O.lockDir,contentDir:T,port:O.port,ready:O.ready,degraded:O.degraded}}function G(e){if(e===`browser`||e===`app`)return e;throw new d(`--mode must be 'browser' or 'app'`)}function K(e){return e.OK_CONSOLE_LEVEL!==void 0||e.LOG_LEVEL!==void 0?null:`warn`}function q(e){let t=[`Stopping OpenKnowledge…`,`Saving pending changes and releasing the server lock — this can take a few seconds.`];return e===`SIGINT`&&t.push(`Press Ctrl+C again to force quit.`),t}async function J(e,t){let s=K(process.env);s!==null&&(process.env.OK_CONSOLE_LEVEL=s);let{renderBanner:ee}=await import(`./banner-Ev4hKBM4.mjs`),{accent:c,dim:l,error:u,warning:d}=await import(`./colors-MGDi6UGf.mjs`),f=process.cwd(),p=t.remote!==void 0&&t.remote!==!1;process.title=z(f),p&&console.warn(d("--remote is deprecated — use `OK_IDLE_SHUTDOWN=off OK_ALLOW_EXTERNAL=1 ok start --external-url <url>` instead (add --bind to serve a non-loopback address; keep OK_IDLE_SHUTDOWN=off — the idle timer only counts WS clients and would tear the server down under a live remote MCP client). The flag now just expands to those server.* keys and will be removed in a later release.")),t.publicUrl!==void 0&&console.warn(d(`--public-url is deprecated — use --external-url <url> (same value and semantics; the key was renamed to server.externalUrl). The old spelling will be removed in a later release.`)),a(e).externalUrlFromDeprecatedKey&&console.warn(d(`[config] server.publicUrl is deprecated — use server.externalUrl instead (same value and semantics). If this config is committed and shared, keep both keys until every collaborator has upgraded — older versions read only server.publicUrl; see https://openknowledge.ai/docs/reference/configuration. The old key will be removed in a later release.`));let m=F(t.remote,e.remote?.url);m!==null&&!m.ok&&(console.error(u(m.errorMessage)),process.exit(78));let h=m?.ok?m:null,g=h!==null;h!==null&&console.warn(d([``,`⚠ REMOTE ACCESS ENABLED — no server-side authentication.`,` Anyone who can reach ${h.url} has FULL control of this`,` knowledge base, including sync, publishing, credentials, and local operations.`,` Restrict who can reach it at the tunnel: ngrok OAuth, Cloudflare Access,`,` Tailscale ACLs, or equivalent edge auth.`,``].join(`
1
+ import{M as e}from"./sleep-C7muMiHm.mjs";import{Hs as t,Js as n,Ks as r,Vs as i,Ws as a,qs as o}from"./src-BqZfalMj.mjs";import{Pn as s,a as ee,si as c}from"./src-Da93CAF3.mjs";import{b as l,v as u,y as d}from"./write-project-skill-Bzg8sfOX.mjs";import{a as f,c as p,d as m,i as h,o as g,r as _,t as v}from"./acp-harness-probe-CdgnSiX1.mjs";import{n as y}from"./constants-BfTkfLb_.mjs";import{spawn as b}from"node:child_process";import{basename as x,resolve as S}from"node:path";import{existsSync as C}from"node:fs";import{rm as w}from"node:fs/promises";import{setTimeout as te}from"node:timers/promises";function T(e,t){return e.bind?.[0]??e.host??t.HOST??`127.0.0.1`}function E(e){if(e===`ui`||e===`server`)return e;throw new d(`--only must be 'ui' or 'server'`)}function D(e=C){let t=import.meta.dirname??new URL(`.`,import.meta.url).pathname;return[S(t,`public`),S(t,`../../app/dist`),S(t,`../../../app/dist`)].find(t=>e(t))}function O(e){if(e.explicitDir!==void 0)return{dir:e.explicitDir,missingBundle:!1};if(e.only===`server`)return{dir:void 0,missingBundle:!1};let t=e.findBundledDir();return{dir:t,missingBundle:t===void 0}}function k(t){if(t===`off`)return`off`;if(!e.test(t))throw new d(`--idle-shutdown must be 'off' or a duration like 90s, 30m, 2h`);return t}function A(e){return e===`localhost`||e===`::1`||e===`[::1]`||e.startsWith(`127.`)}function j(e){return!e.flagBindSet&&!e.okBindSet&&e.hostEnvSet&&e.fileBindCount>1}function M(e){return!e.openBrowser||e.remoteEnabled||e.ephemeral||e.only===`server`||!e.servesUi?!1:e.legacyOpen?!0:(e.explicitOn||A(e.host))&&e.isTTY}function N(e,t){return t&&(e===`::`||e===`::1`||e===`[::1]`||e===`localhost`||e===`0.0.0.0`)?{host:`127.0.0.1`,coerced:!0}:{host:e,coerced:!1}}function P(e,n){return t(n)?e:{externalUrl:e.externalUrl,idleShutdown:e.idleShutdown}}function F(e,t){if(e===void 0||e===!1)return null;let n=typeof e==`string`?e:t;if(n===void 0||n===``)return{ok:!1,errorMessage:"--remote requires a public tunnel URL — pass it (`ok start --remote https://<your-tunnel-host>`) or set remote.url in .ok/config.yml."};let r;try{r=new URL(n)}catch{return{ok:!1,errorMessage:`remote.url is not a valid URL: ${n}`}}if(r.protocol!==`https:`)return{ok:!1,errorMessage:`remote.url must be https — it is the public tunnel URL remote clients connect to (got: ${n})`};let i=n.replace(/\/+$/,``);return{ok:!0,url:i,serverOverlay:{externalUrl:i,allowExternal:!0,idleShutdown:`off`}}}function I(e,t){let n;try{n=new URL(t)}catch{throw new d(`${e} is not a valid URL: ${t}`)}if(n.protocol!==`http:`&&n.protocol!==`https:`)throw new d(`${e} must be an http(s) origin (got: ${t})`);return t}function L(e){return I(`--external-url`,e)}function ne(e){return e.externalUrl??e.publicUrl}function R(e){return I(`--public-url`,e)}function z(e){let t=x(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var B=class extends Error{cwd;constructor(e){super("This directory isn't set up yet. Run `ok init` first, then `ok start` again."),this.name=`OkDirMissingError`,this.cwd=e}};function V(e,t,n=!1){return e??(n?void 0:t)}function H(e,t,n=e=>w(e,{recursive:!0,force:!0})){return async()=>{try{await e()}finally{try{await n(t)}catch(e){process.stderr.write(`[start] ephemeral temp dir reap failed for ${t}: ${e instanceof Error?e.message:String(e)}\n`)}}}}function U(e,t={}){let n=t.exit??(e=>process.exit(e)),r=t.getActiveHandles??(()=>{let e=process._getActiveHandles;return e?e.call(process):null});return async()=>{let i=!1;try{await e()}catch(e){i=!0,t.log?.error({err:e},`idle-shutdown: destroy failed — exiting anyway`)}finally{let e=null;try{let t=r();if(t!==null){e={};for(let n of t){let t=n?.constructor?.name??`unknown`;e[t]=(e[t]??0)+1}}}catch{e=null}t.log?.info({event:`idle-shutdown-exit`,exitCode:+!!i,openHandles:e??{},handlesAvailable:e!==null},`idle-shutdown: teardown finished — exiting process`),n(+!!i)}}}async function W(e){let{config:t,cwd:n,host:r}=e,i=e.skipAutoInit??!1,a=e.idleThresholdMs===void 0?18e5:e.idleThresholdMs,{existsSync:o,mkdirSync:l}=await import(`node:fs`),{basename:u,dirname:d}=await import(`node:path`),{bootServer:f,getLogger:h,resolveContentDir:g,resolveLockDir:_,waitForServerLockDrain:y}=await import(`./src-DCqoFl4a.mjs`),b=e.log??h(`start`),x=e.singleFile!==void 0,S=e.projectDir??n,C=x?ee(e.singleFile).canonicalFilePath:void 0,w=C?d(C):void 0,te=C?u(C):void 0;if(!x){if(!i&&!s(n))throw new B(n);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{let t=typeof e.event==`string`?e.event:``;(t.endsWith(`-failed`)||t.endsWith(`-error`)||t.endsWith(`-missing`))&&b.warn({event:e},`[start] reclaim sweep reported a problem`)};try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-CxB7cmFQ.mjs`)).repairMcpConfigs)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){b.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-BGuk6v5-.mjs`)).repairLaunchJson)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){b.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-eHShRAdH.mjs`)).repairSkills)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){b.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let T=w??g(t,n);!x&&!o(T)&&(l(T,{recursive:!0}),b.info({contentDir:T},`Created content directory`));let E=m(),D=c();{let e=_(x?S:n),t=Date.now(),r=await y(e);r!==`no-drain`&&b.info({event:`start-waited-for-draining-predecessor`,outcome:r,waitedMs:Date.now()-t,drainLockDir:e},r===`released`?`[start] predecessor server finished draining — proceeding`:`[start] predecessor server still draining after wait — proceeding to collide`)}let O=await f({config:t,contentDir:T,projectDir:x?S:n,contentRoot:x?void 0:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:p,tokenStore:E,embeddingsKeyStore:D,...x?{ephemeral:!0,singleDocRelPath:te,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],probeHarnessManagedMcpEntry:(e,t)=>v(e,t),idleShutdownMs:a,...e.serverRuntime===void 0?{}:{serverRuntime:e.serverRuntime},...e.bind===void 0?{}:{bind:e.bind},skipAutoInit:!0,idleShutdownHandler:t=>{let n=t;return U(x?H(n,S):n,{log:b,exit:e.idleExit})},log:b,...e.serveContentAssets===void 0?{}:{serveContentAssets:e.serveContentAssets},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}});return{httpServer:O.httpServer,destroy:O.destroy,lockDir:O.lockDir,contentDir:T,port:O.port,ready:O.ready,degraded:O.degraded}}function G(e){if(e===`browser`||e===`app`)return e;throw new d(`--mode must be 'browser' or 'app'`)}function K(e){return e.OK_CONSOLE_LEVEL!==void 0||e.LOG_LEVEL!==void 0?null:`warn`}function q(e){let t=[`Stopping OpenKnowledge…`,`Saving pending changes and releasing the server lock — this can take a few seconds.`];return e===`SIGINT`&&t.push(`Press Ctrl+C again to force quit.`),t}async function J(e,t){let s=K(process.env);s!==null&&(process.env.OK_CONSOLE_LEVEL=s);let{renderBanner:ee}=await import(`./banner-Ev4hKBM4.mjs`),{accent:c,dim:l,error:u,warning:d}=await import(`./colors-MGDi6UGf.mjs`),f=process.cwd(),p=t.remote!==void 0&&t.remote!==!1;process.title=z(f),p&&console.warn(d("--remote is deprecated — use `OK_IDLE_SHUTDOWN=off OK_ALLOW_EXTERNAL=1 ok start --external-url <url>` instead (add --bind to serve a non-loopback address; keep OK_IDLE_SHUTDOWN=off — the idle timer only counts WS clients and would tear the server down under a live remote MCP client). The flag now just expands to those server.* keys and will be removed in a later release.")),t.publicUrl!==void 0&&console.warn(d(`--public-url is deprecated — use --external-url <url> (same value and semantics; the key was renamed to server.externalUrl). The old spelling will be removed in a later release.`)),a(e).externalUrlFromDeprecatedKey&&console.warn(d(`[config] server.publicUrl is deprecated — use server.externalUrl instead (same value and semantics). If this config is committed and shared, keep both keys until every collaborator has upgraded — older versions read only server.publicUrl; see https://openknowledge.ai/docs/reference/configuration. The old key will be removed in a later release.`));let m=F(t.remote,e.remote?.url);m!==null&&!m.ok&&(console.error(u(m.errorMessage)),process.exit(78));let h=m?.ok?m:null,g=h!==null;h!==null&&console.warn(d([``,`⚠ REMOTE ACCESS ENABLED — no server-side authentication.`,` Anyone who can reach ${h.url} has FULL control of this`,` knowledge base, including sync, publishing, credentials, and local operations.`,` Restrict who can reach it at the tunnel: ngrok OAuth, Cloudflare Access,`,` Tailscale ACLs, or equivalent edge auth.`,``].join(`
2
2
  `)));let _;try{_=n(process.env)}catch(e){throw e instanceof r&&(console.error(u(e.message)),process.exit(78)),e}for(let e of _.diagnostics)console.warn(d(`[config] ${e.message}`));let v=o(e,_.layer),b=_.overrides.some(e=>e.envVar===`OK_BIND`),x=t.bind!==void 0&&t.bind.length>0?t.bind:t.host===void 0?void 0:[t.host],S=process.env.HOST,C=S!==void 0&&S.trim()!==``?S:void 0,w=a(v),T=x??(b||C===void 0?[...w.bind]:[C]);j({flagBindSet:x!==void 0,okBindSet:b,hostEnvSet:C!==void 0,fileBindCount:w.bind.length})&&console.warn(d(`[config] HOST=${C} overrides server.bind — dropping the file-configured addresses (${w.bind.join(`, `)}). Use OK_BIND with a space-separated list to keep multiple binds.`));let E=T[0]??`127.0.0.1`,k=N(E,g);k.coerced&&console.warn(`remote access is enabled and ${E} is not an IPv4 loopback bind — tunnels proxy to 127.0.0.1, so binding ${E} would leave the tunnel dialing a dead port. Using 127.0.0.1.`);let A=k.host,I=g?[A]:T,L=h===null?{}:P(h.serverOverlay,I);h!==null&&!(`allowExternal`in L)&&console.warn(d(`--remote does not consent to exposing a non-loopback bind (${I.join(`, `)}) — the tunnel is the only ingress the alias vouches for. Consent explicitly with OK_ALLOW_EXTERNAL=1 (or server.allowExternal in .ok/local/config.yml), or drop the non-loopback bind.`));let R=ne(t),H=a(o(v,{server:{bind:I,...L,...R===void 0?{}:{externalUrl:R}}}));if(!g&&H.allowExternal&&(!H.loopbackOnly||H.externalUrl)){let e=H.externalUrl??H.bind.join(`, `);console.warn(d([``,`⚠ EXTERNAL ACCESS ENABLED (server.allowExternal) — no server-side authentication.`,` This server is reachable beyond this machine (${e}). Anyone who can`,` reach it has FULL control of this knowledge base — sync, publishing, GitHub`,` credentials, and local operations (clone, sign-in, repo spawn).`,` Restrict who can reach it at the edge: a Tailscale ACL, a reverse proxy with`,` auth (Cloudflare Access, oauth2-proxy), or a firewall.`,``].join(`
3
- `)))}let U=t.port===void 0?void 0:Number(t.port),G=_.overrides.find(e=>e.envVar===`PORT`)?.value,J=a(e).port,ae=e.server?.port;g&&U===void 0&&G!==void 0&&console.warn(`remote access is enabled — ignoring env PORT=${process.env.PORT}; the tunnel's port mapping targets the stable remote port (${J??24550}). Pass --port to override deliberately.`);let oe=V(U,G,g)??(g?J??24550:ae),se=O({explicitDir:t.reactShellDistDir,only:t.only,findBundledDir:D}),Z=se.dir;se.missingBundle&&console.warn(g?`remote access: bundled web UI not found — serving /mcp and /api only over the tunnel.`:`bundled web UI not found — serving /api and /mcp only. Reinstall @inkeep/open-knowledge, or build packages/app in a source checkout.`);let Q;try{Q=await W({config:e,cwd:f,host:A,port:oe,bind:I,...t.serveContentAssets===void 0?{}:{serveContentAssets:t.serveContentAssets},...Z?{reactShellDistDir:Z}:{},idleThresholdMs:i((g?void 0:t.idleShutdown)??H.idleShutdown),serverRuntime:H,...t.singleFile?{singleFile:t.singleFile}:{},...t.projectDir?{projectDir:t.projectDir}:{}})}catch(e){e instanceof B&&(console.error(u(e.message)),process.exit(1));let t=await import(`./src-BF0nCoer.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),e instanceof t.ExposureConsentError&&(console.error(u(e.message)),process.exit(78)),(e instanceof t.SingleFileNotFoundError||e instanceof t.SingleFileNotAFileError||e instanceof t.SingleFileNotMarkdownError)&&(console.error(u(e.message)),process.exit(1)),re(e,t)){let e=t.resolveLockDir(f),n=null;try{n=await Y({readServerLock:()=>t.readServerLock(e),readUiLock:()=>t.readUiLock(e),now:Date.now,sleep:e=>te(e),timeoutMs:3e3,pollIntervalMs:50})}catch(e){process.stderr.write(`[start] spawn-or-reuse: lock poll failed (${e instanceof Error?e.message:String(e)}) — falling back to the collision message\n`)}if(n!==null){let[e,...t]=X(n);console.log(c(e));for(let e of t)console.log(l(e));process.exit(0)}}let n=ie(e,f,t);n!==null&&(console.error(u(n)),process.exit(1)),console.error(`${u(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let ce=!1,$=async e=>{if(ce)return;ce=!0;let[t,...n]=q(e);console.log(c(`\n${t}`));for(let e of n)console.log(l(` ${e}`));try{await Q.destroy()}catch(e){console.error(`${u(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)};process.once(`SIGINT`,()=>{$(`SIGINT`)}),process.once(`SIGTERM`,()=>{$(`SIGTERM`)});let le=`http://${A.includes(`:`)&&!A.startsWith(`[`)?`[${A}]`:A}:${Q.port}`,ue=A===`0.0.0.0`||A===`::`?`http://0.0.0.0:${Q.port}`:void 0,de=le;console.log(ee({name:`open-knowledge`,version:y,localUrl:de,networkUrl:ue,nextSteps:[`Open the Editor URL in your browser to start editing.`]}));let fe={"shadow-repo":`Version history and branch-switch safety unavailable`,"file-watcher":`External file changes will not sync to the editor`,"head-watcher":`Git branch switches may cause document inconsistency`};Q.ready.then(async()=>{if(Q.degraded.length>0){console.log();for(let e of Q.degraded){let t=fe[e]??`${e} (check server logs for details)`;console.warn(` ${d(`⚠`)} ${d(e)}: ${l(t)}`)}console.log()}if(M({openBrowser:t.openBrowser!==!1&&H.openBrowser,explicitOn:t.openBrowser!==!1&&v.server?.openBrowser===!0,legacyOpen:t.open===!0,host:A,isTTY:process.stdout.isTTY===!0,remoteEnabled:g,ephemeral:t.singleFile!==void 0,only:t.only,servesUi:Z!==void 0})){let{openBrowser:e}=await import(`./open-browser-BqA6XiT0.mjs`);e(de)}}).catch(e=>{console.error(` ${u(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}async function Y(e){let t=e.now()+e.timeoutMs,n=e.readServerLock();for(;n!==null&&n.draining!==!0&&n.port<=0&&e.now()<t;)await e.sleep(e.pollIntervalMs),n=e.readServerLock();if(n===null||n.draining===!0||n.port<=0)return null;if(n.capabilities?.includes(`ui`)===!0&&n.url!==void 0)return{url:n.url,kind:n.kind,pid:n.pid,servesUi:!0};let r=e.readUiLock();return r!==null&&r.port>0?{url:r.url??`http://localhost:${r.port}`,kind:n.kind,pid:n.pid,servesUi:!1}:{url:n.url??`http://127.0.0.1:${n.port}`,kind:n.kind,pid:n.pid,servesUi:!1}}function X(e){return[`${e.kind===`mcp-spawned`?`An MCP-spawned OpenKnowledge server is already running on this project`:`OpenKnowledge is already running on this project`} (pid ${e.pid}).`,` ${e.url}`,"Leaving it running — run `ok stop` first if you want a fresh server."]}function re(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function ie(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=n.readServerLock(n.resolveLockDir(t));return e&&e.kind===`mcp-spawned`?"An MCP-spawned server holds this lock; it should release on idle-shutdown (~30 min). Or run `ok stop`.":"OpenKnowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function ae(e){return new u(`start`).description(`Start the OpenKnowledge server (UI + API + MCP + collab on one port)`).option(`-p, --port <port>`,`Server port`,void 0).option(`--bind <address>`,`Bind address (repeatable; default 127.0.0.1 — loopback only)`,(e,t)=>[...t??[],e]).addOption(new l(`-H, --host <host>`,`Deprecated alias of --bind`).hideHelp()).option(`--no-open-browser`,`Do not open the browser after start (interactive loopback starts open it by default)`).addOption(new l(`--open`,`Deprecated: force-open the browser after start`).hideHelp()).option(`--only <module>`,`Serve one module: 'server' (API + MCP only, no shell or browser) or 'ui' (shell + proxy only; requires --server-url)`,E).option(`--server-url <url>`,`Project-server URL the --only ui process proxies to (e.g. http://127.0.0.1:24550)`).option(`--idle-shutdown <duration>`,`Shut the server down after this long with no connected clients ('off', or a duration like 90s, 30m, 2h; default 30m)`,k).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,G).option(`--serve-content-assets`,`Serve content assets from this server (now the default; kept for compatibility)`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path>`).option(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).option(`--project-dir <dir>`,`Throwaway project root for --single-file (where ephemeral .ok/ state lives)`).option(`--external-url <url>`,`Canonical external origin clients dial (sets server.externalUrl for this run) — its host joins the Host/Origin allowlists and issued URLs. External exposure additionally requires consent (OK_ALLOW_EXTERNAL=1 or server.allowExternal).`,L).option(`--public-url <url>`,`Deprecated alias of --external-url (the former name of that flag) — same value and semantics.`,R).option(`--remote [url]`,`Deprecated alias: expands to --external-url <url> + OK_ALLOW_EXTERNAL consent on a loopback bind. Serves through a tunnel with NO server-side auth (anyone who can reach the URL has full control — restrict access at the tunnel with edge auth). Bare --remote uses remote.url from .ok/config.yml; --remote <url> supplies it for this run.`).action(async t=>{let n=e();if(t.serverUrl!==void 0&&t.only!==`ui`&&(process.stderr.write(`error: option '--server-url' requires '--only ui'
3
+ `)))}let U=t.port===void 0?void 0:Number(t.port),G=_.overrides.find(e=>e.envVar===`PORT`)?.value,J=a(e).port,ae=e.server?.port;g&&U===void 0&&G!==void 0&&console.warn(`remote access is enabled — ignoring env PORT=${process.env.PORT}; the tunnel's port mapping targets the stable remote port (${J??24550}). Pass --port to override deliberately.`);let oe=V(U,G,g)??(g?J??24550:ae),se=O({explicitDir:t.reactShellDistDir,only:t.only,findBundledDir:D}),Z=se.dir;se.missingBundle&&console.warn(g?`remote access: bundled web UI not found — serving /mcp and /api only over the tunnel.`:`bundled web UI not found — serving /api and /mcp only. Reinstall @inkeep/open-knowledge, or build packages/app in a source checkout.`);let Q;try{Q=await W({config:e,cwd:f,host:A,port:oe,bind:I,...t.serveContentAssets===void 0?{}:{serveContentAssets:t.serveContentAssets},...Z?{reactShellDistDir:Z}:{},idleThresholdMs:i((g?void 0:t.idleShutdown)??H.idleShutdown),serverRuntime:H,...t.singleFile?{singleFile:t.singleFile}:{},...t.projectDir?{projectDir:t.projectDir}:{}})}catch(e){e instanceof B&&(console.error(u(e.message)),process.exit(1));let t=await import(`./src-DCqoFl4a.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),e instanceof t.ExposureConsentError&&(console.error(u(e.message)),process.exit(78)),(e instanceof t.SingleFileNotFoundError||e instanceof t.SingleFileNotAFileError||e instanceof t.SingleFileNotMarkdownError)&&(console.error(u(e.message)),process.exit(1)),re(e,t)){let e=t.resolveLockDir(f),n=null;try{n=await Y({readServerLock:()=>t.readServerLock(e),readUiLock:()=>t.readUiLock(e),now:Date.now,sleep:e=>te(e),timeoutMs:3e3,pollIntervalMs:50})}catch(e){process.stderr.write(`[start] spawn-or-reuse: lock poll failed (${e instanceof Error?e.message:String(e)}) — falling back to the collision message\n`)}if(n!==null){let[e,...t]=X(n);console.log(c(e));for(let e of t)console.log(l(e));process.exit(0)}}let n=ie(e,f,t);n!==null&&(console.error(u(n)),process.exit(1)),console.error(`${u(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let ce=!1,$=async e=>{if(ce)return;ce=!0;let[t,...n]=q(e);console.log(c(`\n${t}`));for(let e of n)console.log(l(` ${e}`));try{await Q.destroy()}catch(e){console.error(`${u(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)};process.once(`SIGINT`,()=>{$(`SIGINT`)}),process.once(`SIGTERM`,()=>{$(`SIGTERM`)});let le=`http://${A.includes(`:`)&&!A.startsWith(`[`)?`[${A}]`:A}:${Q.port}`,ue=A===`0.0.0.0`||A===`::`?`http://0.0.0.0:${Q.port}`:void 0,de=le;console.log(ee({name:`open-knowledge`,version:y,localUrl:de,networkUrl:ue,nextSteps:[`Open the Editor URL in your browser to start editing.`]}));let fe={"shadow-repo":`Version history and branch-switch safety unavailable`,"file-watcher":`External file changes will not sync to the editor`,"head-watcher":`Git branch switches may cause document inconsistency`};Q.ready.then(async()=>{if(Q.degraded.length>0){console.log();for(let e of Q.degraded){let t=fe[e]??`${e} (check server logs for details)`;console.warn(` ${d(`⚠`)} ${d(e)}: ${l(t)}`)}console.log()}if(M({openBrowser:t.openBrowser!==!1&&H.openBrowser,explicitOn:t.openBrowser!==!1&&v.server?.openBrowser===!0,legacyOpen:t.open===!0,host:A,isTTY:process.stdout.isTTY===!0,remoteEnabled:g,ephemeral:t.singleFile!==void 0,only:t.only,servesUi:Z!==void 0})){let{openBrowser:e}=await import(`./open-browser-DYnRS1jz.mjs`);e(de)}}).catch(e=>{console.error(` ${u(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}async function Y(e){let t=e.now()+e.timeoutMs,n=e.readServerLock();for(;n!==null&&n.draining!==!0&&n.port<=0&&e.now()<t;)await e.sleep(e.pollIntervalMs),n=e.readServerLock();if(n===null||n.draining===!0||n.port<=0)return null;if(n.capabilities?.includes(`ui`)===!0&&n.url!==void 0)return{url:n.url,kind:n.kind,pid:n.pid,servesUi:!0};let r=e.readUiLock();return r!==null&&r.port>0?{url:r.url??`http://localhost:${r.port}`,kind:n.kind,pid:n.pid,servesUi:!1}:{url:n.url??`http://127.0.0.1:${n.port}`,kind:n.kind,pid:n.pid,servesUi:!1}}function X(e){return[`${e.kind===`mcp-spawned`?`An MCP-spawned OpenKnowledge server is already running on this project`:`OpenKnowledge is already running on this project`} (pid ${e.pid}).`,` ${e.url}`,"Leaving it running — run `ok stop` first if you want a fresh server."]}function re(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function ie(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=n.readServerLock(n.resolveLockDir(t));return e&&e.kind===`mcp-spawned`?"An MCP-spawned server holds this lock; it should release on idle-shutdown (~30 min). Or run `ok stop`.":"OpenKnowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function ae(e){return new u(`start`).description(`Start the OpenKnowledge server (UI + API + MCP + collab on one port)`).option(`-p, --port <port>`,`Server port`,void 0).option(`--bind <address>`,`Bind address (repeatable; default 127.0.0.1 — loopback only)`,(e,t)=>[...t??[],e]).addOption(new l(`-H, --host <host>`,`Deprecated alias of --bind`).hideHelp()).option(`--no-open-browser`,`Do not open the browser after start (interactive loopback starts open it by default)`).addOption(new l(`--open`,`Deprecated: force-open the browser after start`).hideHelp()).option(`--only <module>`,`Serve one module: 'server' (API + MCP only, no shell or browser) or 'ui' (shell + proxy only; requires --server-url)`,E).option(`--server-url <url>`,`Project-server URL the --only ui process proxies to (e.g. http://127.0.0.1:24550)`).option(`--idle-shutdown <duration>`,`Shut the server down after this long with no connected clients ('off', or a duration like 90s, 30m, 2h; default 30m)`,k).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,G).option(`--serve-content-assets`,`Serve content assets from this server (now the default; kept for compatibility)`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path>`).option(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).option(`--project-dir <dir>`,`Throwaway project root for --single-file (where ephemeral .ok/ state lives)`).option(`--external-url <url>`,`Canonical external origin clients dial (sets server.externalUrl for this run) — its host joins the Host/Origin allowlists and issued URLs. External exposure additionally requires consent (OK_ALLOW_EXTERNAL=1 or server.allowExternal).`,L).option(`--public-url <url>`,`Deprecated alias of --external-url (the former name of that flag) — same value and semantics.`,R).option(`--remote [url]`,`Deprecated alias: expands to --external-url <url> + OK_ALLOW_EXTERNAL consent on a loopback bind. Serves through a tunnel with NO server-side auth (anyone who can reach the URL has full control — restrict access at the tunnel with edge auth). Bare --remote uses remote.url from .ok/config.yml; --remote <url> supplies it for this run.`).action(async t=>{let n=e();if(t.serverUrl!==void 0&&t.only!==`ui`&&(process.stderr.write(`error: option '--server-url' requires '--only ui'
4
4
  `),process.exit(2)),t.externalUrl!==void 0&&t.publicUrl!==void 0&&(process.stderr.write(`error: option '--public-url' cannot be combined with '--external-url' (--public-url is a deprecated alias of --external-url)
5
5
  `),process.exit(2)),(t.externalUrl!==void 0||t.publicUrl!==void 0)&&t.remote!==void 0&&t.remote!==!1){let e=t.externalUrl===void 0?`--public-url`:`--external-url`;process.stderr.write(`error: option '--remote' cannot be combined with '${e}' (--remote is a deprecated alias that sets server.externalUrl)\n`),process.exit(2)}if(t.singleFile!==void 0&&t.remote!==void 0&&t.remote!==!1&&(process.stderr.write(`error: option '--single-file' cannot be combined with '--remote' — ephemeral single-file mode has no project and no consented root to serve remotely
6
6
  `),process.exit(2)),t.only===`server`&&t.reactShellDistDir!==void 0&&(process.stderr.write(`error: option '--only server' cannot be combined with '--react-shell-dist-dir'
7
7
  `),process.exit(2)),t.only===`ui`){{let{warning:e}=await import(`./colors-MGDi6UGf.mjs`);console.error(e("[start] `--only ui` is deprecated — plain `ok start` serves the editor UI, API, and MCP on one port. The split-mode proxy will be removed in a future release."))}t.serverUrl===void 0&&(process.stderr.write(`error: '--only ui' requires '--server-url <url>' (where the project server runs)
8
8
  `),process.exit(2)),t.mode===`app`&&(process.stderr.write(`error: option '--only ui' cannot be combined with '--mode app'
9
9
  `),process.exit(2)),t.remote!==void 0&&t.remote!==!1&&(process.stderr.write(`error: option '--only ui' cannot be combined with '--remote'
10
- `),process.exit(2));let{runUiCommand:e}=await import(`./ui-B7mhq8_g.mjs`);await e(n,{...t.port===void 0?{}:{port:String(t.port)},...t.bind?.[0]===void 0?t.host===void 0?{}:{host:t.host}:{host:t.bind[0]},upstreamUrl:t.serverUrl});return}if(t.mode===`app`){t.open&&(process.stderr.write(`error: option '--mode=app' cannot be combined with '--open' (--open opens a browser tab against the local server, which app mode does not boot)
10
+ `),process.exit(2));let{runUiCommand:e}=await import(`./ui-CGn0Cm6_.mjs`);await e(n,{...t.port===void 0?{}:{port:String(t.port)},...t.bind?.[0]===void 0?t.host===void 0?{}:{host:t.host}:{host:t.bind[0]},upstreamUrl:t.serverUrl});return}if(t.mode===`app`){t.open&&(process.stderr.write(`error: option '--mode=app' cannot be combined with '--open' (--open opens a browser tab against the local server, which app mode does not boot)
11
11
  `),process.exit(2));let e=[];if(t.port!==void 0&&e.push(`--port`),t.bind!==void 0&&e.push(`--bind`),t.host!==void 0&&e.push(`--host`),t.only!==void 0&&e.push(`--only`),t.serverUrl!==void 0&&e.push(`--server-url`),t.idleShutdown!==void 0&&e.push(`--idle-shutdown`),t.openBrowser===!1&&e.push(`--no-open-browser`),t.externalUrl!==void 0&&e.push(`--external-url`),t.publicUrl!==void 0&&e.push(`--public-url`),t.remote!==void 0&&t.remote!==!1&&e.push(`--remote`),e.length>0){let t=process.env.OK_LOG_LEVEL??`info`;(t===`debug`||t===`trace`)&&console.error(`--mode=app: ignoring ${e.join(`, `)}`)}let n=h(_());if(n.available){f({spawn:b},n);return}console.error(g(n.reason)),process.exit(1)}await J(n,t)})}export{M as C,H as D,ie as E,U as O,P as S,ae as T,T as _,F as a,O as b,A as c,k as d,E as f,ne as g,V as h,z as i,re as l,D as m,W as n,X as o,R as p,N as r,q as s,B as t,L as u,Y as v,j as w,J as x,K as y};
12
- //# sourceMappingURL=start-BbzEXh_C.mjs.map
12
+ //# sourceMappingURL=start-Buf2BHBD.mjs.map
@@ -1,3 +1,3 @@
1
- import{Q as e,it as t,tt as n}from"./sleep-C7muMiHm.mjs";import{Yo as r,ao as i,dt as a}from"./src-BqZfalMj.mjs";import{An as o,Mn as s,jn as c}from"./src-BXlWNOZp.mjs";import{randomUUID as l}from"node:crypto";import{createServer as u,request as d}from"node:http";import{connect as f}from"node:net";function p(e,t,n,r,a){let o=`urn:uuid:${l()}`;if(e.headersSent||e.writableEnded||e.destroyed){console.error(`[ok ui] emitProblem called after headers sent — suppressed`,{type:n,status:t,instance:o});return}let s={type:n,title:r,status:t,instance:o,...a===void 0?{}:{detail:a}},c=i.safeParse(s);if(!c.success){console.error(`[ok ui] emitProblem produced an invalid ProblemDetails body:`,{issues:c.error.issues,originalStatus:t,body:s}),e.writeHead(500,{"Content-Type":`application/problem+json`,"X-Content-Type-Options":`nosniff`,"Cache-Control":`no-store`}),e.end(JSON.stringify({type:`urn:ok:error:internal-server-error`,title:`Internal server error.`,status:500,instance:o}));return}e.writeHead(t,{"Content-Type":`application/problem+json`,"X-Content-Type-Options":`nosniff`,"Cache-Control":`no-store`}),e.end(JSON.stringify(s))}const m=1e4;function h(e,t){let n=e.socket?.remoteAddress;if(n!==void 0&&!c(n))return p(t,403,`urn:ok:error:loopback-required`,`Request must originate from a loopback address.`),!0;if(!o(e.headers.host))return p(t,403,`urn:ok:error:host-not-allowed`,`Host header is not in the loopback allowlist.`),!0;let r=e.headers.origin;return r!==void 0&&!s(r)?(p(t,403,`urn:ok:error:invalid-origin`,`Origin header is not in the loopback allowlist.`),!0):!1}const g=3e4;function _(e,t){let n=e.socket?.remoteAddress;if(n!==void 0&&!c(n)||!o(e.headers.host))return t.destroy(),!0;let r=e.headers.origin;return typeof r==`string`&&!s(r)?(t.destroy(),!0):!1}function v(e,t,n,r,i,a){a.add(t),t.once(`close`,()=>a.delete(t));let o=f({host:r,port:i,timeout:m});a.add(o),o.once(`close`,()=>a.delete(o));let s=!1,c=n=>{if(!s){if(s=!0,n!==void 0){let t=n.err;console.warn(JSON.stringify({event:n.event,upstreamHost:r,upstreamPort:i,url:e.url,code:t instanceof Error?t.code:void 0,message:t instanceof Error?t.message:void 0}))}try{o.destroy()}catch{}try{t.destroy()}catch{}}};o.once(`connect`,()=>{o.setTimeout(0);let a=[`${e.method??`GET`} ${e.url??`/`} HTTP/1.1`,`host: ${r}:${i}`];for(let[t,n]of Object.entries(e.headers))if(t.toLowerCase()!==`host`&&n!==void 0)if(Array.isArray(n))for(let e of n)a.push(`${t}: ${e}`);else a.push(`${t}: ${n}`);try{o.write(`${a.join(`\r
2
- `)}\r\n\r\n`),n.length>0&&o.write(n)}catch(e){c({event:`proxy-upgrade-handshake-write-failed`,err:e});return}o.on(`data`,e=>{t.writable&&t.write(e)}),t.on(`data`,e=>{o.writable&&o.write(e)})}),o.once(`timeout`,()=>{c({event:`proxy-upgrade-upstream-connect-timeout`})}),o.on(`error`,e=>c({event:`proxy-upgrade-upstream-error`,err:e})),t.on(`error`,e=>c({event:`proxy-upgrade-client-error`,err:e})),o.once(`close`,()=>c()),t.once(`close`,()=>c())}const y=[`connection`,`keep-alive`,`proxy-authenticate`,`proxy-authorization`,`te`,`trailer`,`transfer-encoding`,`upgrade`,`cookie`,`set-cookie`];async function b(e){let t=e.upstreamTimeoutMs??m,n=new Set,r=u((n,r)=>{h(n,r)||x(n,r,e.upstreamHost,e.upstreamPort,t)});r.on(`upgrade`,(t,r,i)=>{_(t,r)||v(t,r,i,e.upstreamHost,e.upstreamPort,n)}),await new Promise((t,n)=>{let i=e=>n(e);r.once(`error`,i),r.listen(e.listenPort,e.host,()=>{r.off(`error`,i),t()})});let i=r.address();return{httpServer:r,port:typeof i==`object`&&i?i.port:e.listenPort,close:()=>new Promise(e=>{for(let e of n)try{e.destroy()}catch{}n.clear(),r.close(()=>e()),r.closeIdleConnections()})}}function ee(e,t,n){x(e,t,n.upstreamHost,n.upstreamPort,n.upstreamTimeoutMs??m)}function x(e,t,n,r,i){let a={...e.headers};delete a.host;for(let e of y)delete a[e];e.setTimeout(g,()=>{if(t.headersSent)try{t.end()}catch{}else try{p(t,408,`urn:ok:error:request-timeout`,`Proxy request exceeded the per-request deadline.`,`Slow-loris-class: client did not finish within ${g/1e3}s.`)}catch{}try{e.socket?.destroy()}catch{}});let o=d({host:n,port:r,method:e.method,path:e.url,headers:{...a,host:`${n}:${r}`}},e=>{let n={...e.headers};for(let e of y)delete n[e];t.writeHead(e.statusCode??502,n),e.pipe(t),e.once(`error`,()=>{try{t.end()}catch{}})});i>0&&o.setTimeout(i,()=>{if(!t.headersSent)p(t,504,`urn:ok:error:gateway-timeout`,`Upstream did not respond before the gateway deadline.`,`Upstream timeout: ${i/1e3}s elapsed without a response.`);else try{t.end()}catch{}o.destroy()}),o.on(`error`,()=>{if(!t.headersSent)p(t,502,`urn:ok:error:collab-server-not-running`,`Collab server is unreachable.`,`Upstream connection failed or dropped before a response was received.`);else try{t.end()}catch{}}),e.on(`error`,()=>{o.destroy()}),e.pipe(o)}async function S(e){await Promise.all(e.map(e=>new Promise(t=>{e.close(()=>t())})))}function C(e){let t;try{t=new URL(e)}catch{throw Error(`Invalid --server-url '${e}' — expected e.g. http://127.0.0.1:24550`)}if(t.protocol!==`http:`)throw Error(`--server-url must be http: (got '${t.protocol}//') — the UI proxy speaks plain HTTP; terminate TLS at your ingress`);let n=t.port===``?80:Number(t.port);return{host:t.hostname.replace(/^\[(.+)\]$/,`$1`),port:n}}async function w(i){let{existsSync:o}=await import(`node:fs`),{createServer:s}=await import(`node:http`),{resolve:c}=await import(`node:path`),{acquireUiLock:l,buildIngressPolicy:u,createAssetServeMiddleware:d,createContentFilter:f,readServerLock:m,releaseUiLock:g,updateUiLockPort:y}=await import(`./src-BF0nCoer.mjs`),{default:b}=await import(`./build-BcDJ6qQ2.mjs`),{resolveContentDir:x,resolveLockDir:S}=await import(`./src-BF0nCoer.mjs`),w=x(i.config,i.cwd),E=S(i.cwd);l(E,{port:0,worktreeRoot:i.cwd});let D=import.meta.dirname??new URL(`.`,import.meta.url).pathname,O=[c(D,`public`),c(D,`../../app/dist`),c(D,`../../../app/dist`)],k=i.assetDir??O.find(e=>o(e)),A=k?b(k,{single:!0,gzip:!0,etag:!0,dev:!0,extensions:[]}):null,j=o(w)?d({contentFilter:f({projectDir:i.cwd,contentDir:w}),contentSirv:b(w,{dotfiles:!1,dev:!0,extensions:[]}),inlineExtensions:t,assetExtensions:e,blocklistExtensions:n,ingressPolicy:u({})}):null,M=i.upstreamUrl===void 0?null:C(i.upstreamUrl),N=()=>{if(M!==null)return M;let e=m(E);return!e||e.port<=0?null:{host:r,port:e.port}},P=i.port,F=null,I=(e,t)=>{let n=e.url?.split(`?`)[0];if((n===`/`||n===``)&&(e.url=`/index.html`),!(n?.startsWith(`/api/`)&&h(e,t))){if(n===`/api/config`&&(e.method===`GET`||e.method===`HEAD`)){F?.();let n=e.headers.host??`localhost:${P}`,r=N()===null?null:`ws://${n}/collab`,i=JSON.stringify({collabUrl:r,previewUrl:null,port:P});t.setHeader(`Content-Type`,`application/json`),t.setHeader(`Cache-Control`,`no-store`),t.setHeader(`X-Content-Type-Options`,`nosniff`),t.statusCode=200,e.method===`HEAD`?t.end():t.end(i);return}if(n?.startsWith(`/api/`)){F?.();let r=N();if(r===null){p(t,503,`urn:ok:error:collab-server-not-running`,"Collab server not running. Start `ok start` or run `ok status`.",`Path: ${n}`);return}ee(e,t,{upstreamHost:r.host,upstreamPort:r.port});return}if(A&&n?.startsWith(`/assets/`)){A(e,t,()=>{j?j(e,t,()=>T(t)):T(t)});return}if(j){j(e,t,()=>{A?A(e,t):T(t)});return}if(A){A(e,t);return}T(t)}},L=new Set,R=(e,t,n)=>{if(_(e,t))return;let r=e.url?.split(`?`)[0]??``;if(r!==`/collab`&&!r.startsWith(`/collab/`)){t.destroy();return}let i=N();if(i===null){console.warn(JSON.stringify({event:`ok-ui-upgrade-no-collab-lock`,url:r,reason:"server.lock missing or port unbound — is `ok start` running?"})),t.destroy();return}v(e,t,n,i.host,i.port,L)},z=()=>{for(let e of L)try{e.destroy()}catch{}L.clear()},te=i.host===void 0?[`::1`,`127.0.0.1`]:[i.host],B=[],V=i.port,ne=e=>e instanceof Error&&e.code===`EADDRINUSE`,H=async()=>{await Promise.all(B.splice(0).map(e=>new Promise(t=>{try{e.close(()=>t())}catch{t()}})))},U=async e=>{V=e;for(let e of te){let t=s(I);t.on(`upgrade`,R),B.push(t),await new Promise((n,r)=>{let i=e=>r(e);t.once(`error`,i),t.listen(V,e,()=>{t.off(`error`,i);let e=t.address();typeof e==`object`&&e&&(V=e.port),n()})})}};try{try{await U(i.port)}catch(e){if(i.fallbackToKernel===!0&&ne(e))await H(),await U(0);else throw e}}catch(e){await H();try{g(E)}catch{}throw e}let W=V;P=W,y(E,W,`http://localhost:${W}`);let G=i.scheduler??a,K=i.safetyNetMs??432e5,q=null,J=!1,Y=!1,X=()=>{J||(J=!0,q!==null&&(G.clearTimeout(q),q=null))},Z=()=>{if(X(),!Y){Y=!0;try{g(E)}catch{}}},Q=()=>{J||K<=0||(q!==null&&(G.clearTimeout(q),q=null),q=G.setTimeout(()=>{q=null,console.warn(`[ui] safety-net (${K}ms) reached — shutting down (D-025 backstop)`);try{i.onSafetyNet?.()}catch{}z();for(let e of B)try{e.close()}catch{}Z()},K))},$=()=>{J||K<=0||Q()};return F=$,Q(),{httpServers:B,port:W,release:Z,detachSafetyNet:X,nudgeSafetyNet:$,drainUpgradeSockets:z}}function T(e){e.headersSent||e.writableEnded||e.destroyed||(e.setHeader(`X-Content-Type-Options`,`nosniff`),e.setHeader(`Cache-Control`,`no-store`),e.statusCode=404,e.end())}function E(e,t){if(e!==void 0){let t=Number.parseInt(e,10);if(Number.isNaN(t)||t<0||t>65535)throw Error(`Invalid --port value '${e}'`);return{port:t,fallbackToKernel:!1}}if(t!==void 0&&t!==``){let e=Number.parseInt(t,10);if(Number.isNaN(e)||e<0||e>65535)throw Error(`Invalid PORT env value '${t}'`);return{port:e,fallbackToKernel:!1}}return{port:39847,fallbackToKernel:!0}}async function D(e){let t=e.readLock??(async()=>{let{readUiLock:t}=await import(`./src-BF0nCoer.mjs`);return t(e.lockDir)}),n=await t();if(!n)throw Error(`UI lock collision reported but the lock disappeared before handling — retry acquiring.`);if(n.port===e.requestedPort&&n.port>0)return{mode:`already-running`,port:n.port};let r=n.port;if(r===0){let n=Date.now()+(e.pollDeadlineMs??2e3),i=e.pollIntervalMs??100;for(;Date.now()<n;){await new Promise(e=>{setTimeout(e,i)});let e=await t();if(e&&e.port>0){r=e.port;break}}if(r===0)throw Error("UI did not bind within 2s; run `ok clean`");if(r===e.requestedPort)return{mode:`already-running`,port:r}}return{mode:`proxy`,handle:await b({listenPort:e.requestedPort,host:e.host,upstreamHost:`localhost`,upstreamPort:r}),upstreamPort:r}}async function O(e,t){let{dim:n}=await import(`./colors-MGDi6UGf.mjs`),{UiLockCollisionError:r}=await import(`./src-BF0nCoer.mjs`),{resolveLockDir:i}=await import(`./src-BF0nCoer.mjs`),a=t.host;if(t.upstreamUrl!==void 0)try{C(t.upstreamUrl)}catch(e){console.error(e instanceof Error?e.message:String(e)),process.exit(2)}let o;try{o=E(t.port,process.env.PORT)}catch(e){console.error(e instanceof Error?e.message:String(e)),process.exit(2)}let s=o.port;try{let r=await w({config:e,cwd:process.cwd(),port:s,fallbackToKernel:o.fallbackToKernel,host:a,...t.upstreamUrl===void 0?{}:{upstreamUrl:t.upstreamUrl}}),i=a===void 0||a===`::`||a===`0.0.0.0`?`localhost`:a;console.log(`${n(`[ui]`)} listening on http://${i}:${r.port}`);let c=!1,l=e=>{if(c)return;c=!0,console.log(n(`\n[ui] Shutting down (${e})`)),r.detachSafetyNet();let t=()=>{try{r.release()}finally{process.exit(process.exitCode??0)}};r.drainUpgradeSockets(),S(r.httpServers).then(t,t),setTimeout(t,2e3).unref()};process.once(`SIGINT`,()=>l(`SIGINT`)),process.once(`SIGTERM`,()=>l(`SIGTERM`));return}catch(e){if(!(e instanceof r))throw e;let t=i(process.cwd()),o=a??`localhost`,c;try{c=await D({requestedPort:s,host:o,lockDir:t})}catch(e){console.error(e instanceof Error?e.message:String(e)),process.exit(1)}if(c.mode===`already-running`){if(console.log(`UI already running at http://${o}:${c.port}`),k(process)){await new Promise(e=>{let t=t=>{console.log(n(`\n[ui-keepalive] Shutting down (${t})`)),e()};process.once(`SIGINT`,()=>t(`SIGINT`)),process.once(`SIGTERM`,()=>t(`SIGTERM`))});return}process.exit(0)}console.log(`UI running at http://${o}:${c.upstreamPort}; acting as HTTP proxy on port ${c.handle.port}`);let l=!1,u=e=>{l||(l=!0,console.log(n(`\n[ui-proxy] Shutting down (${e})`)),c.handle.close().finally(()=>process.exit(process.exitCode??0)),setTimeout(()=>process.exit(process.exitCode??0),2e3).unref())};process.once(`SIGINT`,()=>u(`SIGINT`)),process.once(`SIGTERM`,()=>u(`SIGTERM`))}}function k(e){let t=e.stdout.isTTY===!0,n=typeof e.env.PORT==`string`&&e.env.PORT!==``;return!t||n}export{O as runUiCommand};
3
- //# sourceMappingURL=ui-B7mhq8_g.mjs.map
1
+ import{Q as e,it as t,tt as n}from"./sleep-C7muMiHm.mjs";import{Yo as r,ao as i,dt as a}from"./src-BqZfalMj.mjs";import{An as o,Mn as s,jn as c}from"./src-Da93CAF3.mjs";import{randomUUID as l}from"node:crypto";import{createServer as u,request as d}from"node:http";import{connect as f}from"node:net";function p(e,t,n,r,a){let o=`urn:uuid:${l()}`;if(e.headersSent||e.writableEnded||e.destroyed){console.error(`[ok ui] emitProblem called after headers sent — suppressed`,{type:n,status:t,instance:o});return}let s={type:n,title:r,status:t,instance:o,...a===void 0?{}:{detail:a}},c=i.safeParse(s);if(!c.success){console.error(`[ok ui] emitProblem produced an invalid ProblemDetails body:`,{issues:c.error.issues,originalStatus:t,body:s}),e.writeHead(500,{"Content-Type":`application/problem+json`,"X-Content-Type-Options":`nosniff`,"Cache-Control":`no-store`}),e.end(JSON.stringify({type:`urn:ok:error:internal-server-error`,title:`Internal server error.`,status:500,instance:o}));return}e.writeHead(t,{"Content-Type":`application/problem+json`,"X-Content-Type-Options":`nosniff`,"Cache-Control":`no-store`}),e.end(JSON.stringify(s))}const m=1e4;function h(e,t){let n=e.socket?.remoteAddress;if(n!==void 0&&!c(n))return p(t,403,`urn:ok:error:loopback-required`,`Request must originate from a loopback address.`),!0;if(!o(e.headers.host))return p(t,403,`urn:ok:error:host-not-allowed`,`Host header is not in the loopback allowlist.`),!0;let r=e.headers.origin;return r!==void 0&&!s(r)?(p(t,403,`urn:ok:error:invalid-origin`,`Origin header is not in the loopback allowlist.`),!0):!1}const g=3e4;function _(e,t){let n=e.socket?.remoteAddress;if(n!==void 0&&!c(n)||!o(e.headers.host))return t.destroy(),!0;let r=e.headers.origin;return typeof r==`string`&&!s(r)?(t.destroy(),!0):!1}function v(e,t,n,r,i,a){a.add(t),t.once(`close`,()=>a.delete(t));let o=f({host:r,port:i,timeout:m});a.add(o),o.once(`close`,()=>a.delete(o));let s=!1,c=n=>{if(!s){if(s=!0,n!==void 0){let t=n.err;console.warn(JSON.stringify({event:n.event,upstreamHost:r,upstreamPort:i,url:e.url,code:t instanceof Error?t.code:void 0,message:t instanceof Error?t.message:void 0}))}try{o.destroy()}catch{}try{t.destroy()}catch{}}};o.once(`connect`,()=>{o.setTimeout(0);let a=[`${e.method??`GET`} ${e.url??`/`} HTTP/1.1`,`host: ${r}:${i}`];for(let[t,n]of Object.entries(e.headers))if(t.toLowerCase()!==`host`&&n!==void 0)if(Array.isArray(n))for(let e of n)a.push(`${t}: ${e}`);else a.push(`${t}: ${n}`);try{o.write(`${a.join(`\r
2
+ `)}\r\n\r\n`),n.length>0&&o.write(n)}catch(e){c({event:`proxy-upgrade-handshake-write-failed`,err:e});return}o.on(`data`,e=>{t.writable&&t.write(e)}),t.on(`data`,e=>{o.writable&&o.write(e)})}),o.once(`timeout`,()=>{c({event:`proxy-upgrade-upstream-connect-timeout`})}),o.on(`error`,e=>c({event:`proxy-upgrade-upstream-error`,err:e})),t.on(`error`,e=>c({event:`proxy-upgrade-client-error`,err:e})),o.once(`close`,()=>c()),t.once(`close`,()=>c())}const y=[`connection`,`keep-alive`,`proxy-authenticate`,`proxy-authorization`,`te`,`trailer`,`transfer-encoding`,`upgrade`,`cookie`,`set-cookie`];async function b(e){let t=e.upstreamTimeoutMs??m,n=new Set,r=u((n,r)=>{h(n,r)||x(n,r,e.upstreamHost,e.upstreamPort,t)});r.on(`upgrade`,(t,r,i)=>{_(t,r)||v(t,r,i,e.upstreamHost,e.upstreamPort,n)}),await new Promise((t,n)=>{let i=e=>n(e);r.once(`error`,i),r.listen(e.listenPort,e.host,()=>{r.off(`error`,i),t()})});let i=r.address();return{httpServer:r,port:typeof i==`object`&&i?i.port:e.listenPort,close:()=>new Promise(e=>{for(let e of n)try{e.destroy()}catch{}n.clear(),r.close(()=>e()),r.closeIdleConnections()})}}function ee(e,t,n){x(e,t,n.upstreamHost,n.upstreamPort,n.upstreamTimeoutMs??m)}function x(e,t,n,r,i){let a={...e.headers};delete a.host;for(let e of y)delete a[e];e.setTimeout(g,()=>{if(t.headersSent)try{t.end()}catch{}else try{p(t,408,`urn:ok:error:request-timeout`,`Proxy request exceeded the per-request deadline.`,`Slow-loris-class: client did not finish within ${g/1e3}s.`)}catch{}try{e.socket?.destroy()}catch{}});let o=d({host:n,port:r,method:e.method,path:e.url,headers:{...a,host:`${n}:${r}`}},e=>{let n={...e.headers};for(let e of y)delete n[e];t.writeHead(e.statusCode??502,n),e.pipe(t),e.once(`error`,()=>{try{t.end()}catch{}})});i>0&&o.setTimeout(i,()=>{if(!t.headersSent)p(t,504,`urn:ok:error:gateway-timeout`,`Upstream did not respond before the gateway deadline.`,`Upstream timeout: ${i/1e3}s elapsed without a response.`);else try{t.end()}catch{}o.destroy()}),o.on(`error`,()=>{if(!t.headersSent)p(t,502,`urn:ok:error:collab-server-not-running`,`Collab server is unreachable.`,`Upstream connection failed or dropped before a response was received.`);else try{t.end()}catch{}}),e.on(`error`,()=>{o.destroy()}),e.pipe(o)}async function S(e){await Promise.all(e.map(e=>new Promise(t=>{e.close(()=>t())})))}function C(e){let t;try{t=new URL(e)}catch{throw Error(`Invalid --server-url '${e}' — expected e.g. http://127.0.0.1:24550`)}if(t.protocol!==`http:`)throw Error(`--server-url must be http: (got '${t.protocol}//') — the UI proxy speaks plain HTTP; terminate TLS at your ingress`);let n=t.port===``?80:Number(t.port);return{host:t.hostname.replace(/^\[(.+)\]$/,`$1`),port:n}}async function w(i){let{existsSync:o}=await import(`node:fs`),{createServer:s}=await import(`node:http`),{resolve:c}=await import(`node:path`),{acquireUiLock:l,buildIngressPolicy:u,createAssetServeMiddleware:d,createContentFilter:f,readServerLock:m,releaseUiLock:g,updateUiLockPort:y}=await import(`./src-DCqoFl4a.mjs`),{default:b}=await import(`./build-BcDJ6qQ2.mjs`),{resolveContentDir:x,resolveLockDir:S}=await import(`./src-DCqoFl4a.mjs`),w=x(i.config,i.cwd),E=S(i.cwd);l(E,{port:0,worktreeRoot:i.cwd});let D=import.meta.dirname??new URL(`.`,import.meta.url).pathname,O=[c(D,`public`),c(D,`../../app/dist`),c(D,`../../../app/dist`)],k=i.assetDir??O.find(e=>o(e)),A=k?b(k,{single:!0,gzip:!0,etag:!0,dev:!0,extensions:[]}):null,j=o(w)?d({contentFilter:f({projectDir:i.cwd,contentDir:w}),contentSirv:b(w,{dotfiles:!1,dev:!0,extensions:[]}),inlineExtensions:t,assetExtensions:e,blocklistExtensions:n,ingressPolicy:u({})}):null,M=i.upstreamUrl===void 0?null:C(i.upstreamUrl),N=()=>{if(M!==null)return M;let e=m(E);return!e||e.port<=0?null:{host:r,port:e.port}},P=i.port,F=null,I=(e,t)=>{let n=e.url?.split(`?`)[0];if((n===`/`||n===``)&&(e.url=`/index.html`),!(n?.startsWith(`/api/`)&&h(e,t))){if(n===`/api/config`&&(e.method===`GET`||e.method===`HEAD`)){F?.();let n=e.headers.host??`localhost:${P}`,r=N()===null?null:`ws://${n}/collab`,i=JSON.stringify({collabUrl:r,previewUrl:null,port:P});t.setHeader(`Content-Type`,`application/json`),t.setHeader(`Cache-Control`,`no-store`),t.setHeader(`X-Content-Type-Options`,`nosniff`),t.statusCode=200,e.method===`HEAD`?t.end():t.end(i);return}if(n?.startsWith(`/api/`)){F?.();let r=N();if(r===null){p(t,503,`urn:ok:error:collab-server-not-running`,"Collab server not running. Start `ok start` or run `ok status`.",`Path: ${n}`);return}ee(e,t,{upstreamHost:r.host,upstreamPort:r.port});return}if(A&&n?.startsWith(`/assets/`)){A(e,t,()=>{j?j(e,t,()=>T(t)):T(t)});return}if(j){j(e,t,()=>{A?A(e,t):T(t)});return}if(A){A(e,t);return}T(t)}},L=new Set,R=(e,t,n)=>{if(_(e,t))return;let r=e.url?.split(`?`)[0]??``;if(r!==`/collab`&&!r.startsWith(`/collab/`)){t.destroy();return}let i=N();if(i===null){console.warn(JSON.stringify({event:`ok-ui-upgrade-no-collab-lock`,url:r,reason:"server.lock missing or port unbound — is `ok start` running?"})),t.destroy();return}v(e,t,n,i.host,i.port,L)},z=()=>{for(let e of L)try{e.destroy()}catch{}L.clear()},te=i.host===void 0?[`::1`,`127.0.0.1`]:[i.host],B=[],V=i.port,ne=e=>e instanceof Error&&e.code===`EADDRINUSE`,H=async()=>{await Promise.all(B.splice(0).map(e=>new Promise(t=>{try{e.close(()=>t())}catch{t()}})))},U=async e=>{V=e;for(let e of te){let t=s(I);t.on(`upgrade`,R),B.push(t),await new Promise((n,r)=>{let i=e=>r(e);t.once(`error`,i),t.listen(V,e,()=>{t.off(`error`,i);let e=t.address();typeof e==`object`&&e&&(V=e.port),n()})})}};try{try{await U(i.port)}catch(e){if(i.fallbackToKernel===!0&&ne(e))await H(),await U(0);else throw e}}catch(e){await H();try{g(E)}catch{}throw e}let W=V;P=W,y(E,W,`http://localhost:${W}`);let G=i.scheduler??a,K=i.safetyNetMs??432e5,q=null,J=!1,Y=!1,X=()=>{J||(J=!0,q!==null&&(G.clearTimeout(q),q=null))},Z=()=>{if(X(),!Y){Y=!0;try{g(E)}catch{}}},Q=()=>{J||K<=0||(q!==null&&(G.clearTimeout(q),q=null),q=G.setTimeout(()=>{q=null,console.warn(`[ui] safety-net (${K}ms) reached — shutting down (D-025 backstop)`);try{i.onSafetyNet?.()}catch{}z();for(let e of B)try{e.close()}catch{}Z()},K))},$=()=>{J||K<=0||Q()};return F=$,Q(),{httpServers:B,port:W,release:Z,detachSafetyNet:X,nudgeSafetyNet:$,drainUpgradeSockets:z}}function T(e){e.headersSent||e.writableEnded||e.destroyed||(e.setHeader(`X-Content-Type-Options`,`nosniff`),e.setHeader(`Cache-Control`,`no-store`),e.statusCode=404,e.end())}function E(e,t){if(e!==void 0){let t=Number.parseInt(e,10);if(Number.isNaN(t)||t<0||t>65535)throw Error(`Invalid --port value '${e}'`);return{port:t,fallbackToKernel:!1}}if(t!==void 0&&t!==``){let e=Number.parseInt(t,10);if(Number.isNaN(e)||e<0||e>65535)throw Error(`Invalid PORT env value '${t}'`);return{port:e,fallbackToKernel:!1}}return{port:39847,fallbackToKernel:!0}}async function D(e){let t=e.readLock??(async()=>{let{readUiLock:t}=await import(`./src-DCqoFl4a.mjs`);return t(e.lockDir)}),n=await t();if(!n)throw Error(`UI lock collision reported but the lock disappeared before handling — retry acquiring.`);if(n.port===e.requestedPort&&n.port>0)return{mode:`already-running`,port:n.port};let r=n.port;if(r===0){let n=Date.now()+(e.pollDeadlineMs??2e3),i=e.pollIntervalMs??100;for(;Date.now()<n;){await new Promise(e=>{setTimeout(e,i)});let e=await t();if(e&&e.port>0){r=e.port;break}}if(r===0)throw Error("UI did not bind within 2s; run `ok clean`");if(r===e.requestedPort)return{mode:`already-running`,port:r}}return{mode:`proxy`,handle:await b({listenPort:e.requestedPort,host:e.host,upstreamHost:`localhost`,upstreamPort:r}),upstreamPort:r}}async function O(e,t){let{dim:n}=await import(`./colors-MGDi6UGf.mjs`),{UiLockCollisionError:r}=await import(`./src-DCqoFl4a.mjs`),{resolveLockDir:i}=await import(`./src-DCqoFl4a.mjs`),a=t.host;if(t.upstreamUrl!==void 0)try{C(t.upstreamUrl)}catch(e){console.error(e instanceof Error?e.message:String(e)),process.exit(2)}let o;try{o=E(t.port,process.env.PORT)}catch(e){console.error(e instanceof Error?e.message:String(e)),process.exit(2)}let s=o.port;try{let r=await w({config:e,cwd:process.cwd(),port:s,fallbackToKernel:o.fallbackToKernel,host:a,...t.upstreamUrl===void 0?{}:{upstreamUrl:t.upstreamUrl}}),i=a===void 0||a===`::`||a===`0.0.0.0`?`localhost`:a;console.log(`${n(`[ui]`)} listening on http://${i}:${r.port}`);let c=!1,l=e=>{if(c)return;c=!0,console.log(n(`\n[ui] Shutting down (${e})`)),r.detachSafetyNet();let t=()=>{try{r.release()}finally{process.exit(process.exitCode??0)}};r.drainUpgradeSockets(),S(r.httpServers).then(t,t),setTimeout(t,2e3).unref()};process.once(`SIGINT`,()=>l(`SIGINT`)),process.once(`SIGTERM`,()=>l(`SIGTERM`));return}catch(e){if(!(e instanceof r))throw e;let t=i(process.cwd()),o=a??`localhost`,c;try{c=await D({requestedPort:s,host:o,lockDir:t})}catch(e){console.error(e instanceof Error?e.message:String(e)),process.exit(1)}if(c.mode===`already-running`){if(console.log(`UI already running at http://${o}:${c.port}`),k(process)){await new Promise(e=>{let t=t=>{console.log(n(`\n[ui-keepalive] Shutting down (${t})`)),e()};process.once(`SIGINT`,()=>t(`SIGINT`)),process.once(`SIGTERM`,()=>t(`SIGTERM`))});return}process.exit(0)}console.log(`UI running at http://${o}:${c.upstreamPort}; acting as HTTP proxy on port ${c.handle.port}`);let l=!1,u=e=>{l||(l=!0,console.log(n(`\n[ui-proxy] Shutting down (${e})`)),c.handle.close().finally(()=>process.exit(process.exitCode??0)),setTimeout(()=>process.exit(process.exitCode??0),2e3).unref())};process.once(`SIGINT`,()=>u(`SIGINT`)),process.once(`SIGTERM`,()=>u(`SIGTERM`))}}function k(e){let t=e.stdout.isTTY===!0,n=typeof e.env.PORT==`string`&&e.env.PORT!==``;return!t||n}export{O as runUiCommand};
3
+ //# sourceMappingURL=ui-CGn0Cm6_.mjs.map
@@ -1,4 +1,4 @@
1
- import{i as e,o as t,t as n}from"./chunk-DTipWd-i.mjs";import{$o as r,cs as i,fs as a,ss as o}from"./src-BqZfalMj.mjs";import{yr as s,zr as c}from"./src-BXlWNOZp.mjs";import{basename as l,dirname as u,isAbsolute as d,join as f,posix as p,relative as m,resolve as h,sep as g,win32 as _}from"node:path";import{cpSync as ee,existsSync as v,lstatSync as te,mkdirSync as y,readFileSync as ne,realpathSync as b,rmSync as x,statSync as re}from"node:fs";import{homedir as S}from"node:os";var C=n((e=>{var t=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},n=class extends t{constructor(e){super(1,`commander.invalidArgument`,e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};e.CommanderError=t,e.InvalidArgumentError=n})),w=n((e=>{let{InvalidArgumentError:t}=C();var n=class{constructor(e,t){switch(this.description=t||``,this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case`<`:this.required=!0,this._name=e.slice(1,-1);break;case`[`:this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.endsWith(`...`)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,n)=>{if(!this.argChoices.includes(e))throw new t(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,n):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function r(e){let t=e.name()+(e.variadic===!0?`...`:``);return e.required?`<`+t+`>`:`[`+t+`]`}e.Argument=n,e.humanReadableArgName=r})),T=n((e=>{let{humanReadableArgName:t}=w();var n=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(e=>!e._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((e,t)=>e.name().localeCompare(t.name())),t}compareOptions(e,t){let n=e=>e.short?e.short.replace(/^-/,``):e.long.replace(/^--/,``);return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(e=>!e.hidden),n=e._getHelpOption();if(n&&!n.hidden){let r=n.short&&e._findOption(n.short),i=n.long&&e._findOption(n.long);!r&&!i?t.push(n):n.long&&!i?t.push(e.createOption(n.long,n.description)):n.short&&!r&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let e=n.options.filter(e=>!e.hidden);t.push(...e)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||``}),e.registeredArguments.find(e=>e.description)?e.registeredArguments:[]}subcommandTerm(e){let n=e.registeredArguments.map(e=>t(e)).join(` `);return e._name+(e._aliases[0]?`|`+e._aliases[0]:``)+(e.options.length?` [options]`:``)+(n?` `+n:``)}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(n)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(n)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+`|`+e._aliases[0]);let n=``;for(let t=e.parent;t;t=t.parent)n=t.name()+` `+n;return n+t+` `+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue==`boolean`)&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,``]}groupItems(e,t,n){let r=new Map;return e.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[])}),t.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[]),r.get(t).push(e)}),r}formatHelp(e,t){let n=t.padWidth(e,t),r=t.helpWidth??80;function i(e,r){return t.formatItem(e,n,r,t)}let a=[`${t.styleTitle(`Usage:`)} ${t.styleUsage(t.commandUsage(e))}`,``],o=t.commandDescription(e);o.length>0&&(a=a.concat([t.boxWrap(t.styleCommandDescription(o),r),``]));let s=t.visibleArguments(e).map(e=>i(t.styleArgumentTerm(t.argumentTerm(e)),t.styleArgumentDescription(t.argumentDescription(e))));if(a=a.concat(this.formatItemList(`Arguments:`,s,t)),this.groupItems(e.options,t.visibleOptions(e),e=>e.helpGroupHeading??`Options:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),t.showGlobalOptions){let n=t.visibleGlobalOptions(e).map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(`Global Options:`,n,t))}return this.groupItems(e.commands,t.visibleCommands(e),e=>e.helpGroup()||`Commands:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleSubcommandTerm(t.subcommandTerm(e)),t.styleSubcommandDescription(t.subcommandDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),a.join(`
1
+ import{i as e,o as t,t as n}from"./chunk-DTipWd-i.mjs";import{$o as r,cs as i,fs as a,ss as o}from"./src-BqZfalMj.mjs";import{yr as s,zr as c}from"./src-Da93CAF3.mjs";import{basename as l,dirname as u,isAbsolute as d,join as f,posix as p,relative as m,resolve as h,sep as g,win32 as _}from"node:path";import{cpSync as ee,existsSync as v,lstatSync as te,mkdirSync as y,readFileSync as ne,realpathSync as b,rmSync as x,statSync as re}from"node:fs";import{homedir as S}from"node:os";var C=n((e=>{var t=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},n=class extends t{constructor(e){super(1,`commander.invalidArgument`,e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};e.CommanderError=t,e.InvalidArgumentError=n})),w=n((e=>{let{InvalidArgumentError:t}=C();var n=class{constructor(e,t){switch(this.description=t||``,this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case`<`:this.required=!0,this._name=e.slice(1,-1);break;case`[`:this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.endsWith(`...`)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,n)=>{if(!this.argChoices.includes(e))throw new t(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,n):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function r(e){let t=e.name()+(e.variadic===!0?`...`:``);return e.required?`<`+t+`>`:`[`+t+`]`}e.Argument=n,e.humanReadableArgName=r})),T=n((e=>{let{humanReadableArgName:t}=w();var n=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(e=>!e._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((e,t)=>e.name().localeCompare(t.name())),t}compareOptions(e,t){let n=e=>e.short?e.short.replace(/^-/,``):e.long.replace(/^--/,``);return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(e=>!e.hidden),n=e._getHelpOption();if(n&&!n.hidden){let r=n.short&&e._findOption(n.short),i=n.long&&e._findOption(n.long);!r&&!i?t.push(n):n.long&&!i?t.push(e.createOption(n.long,n.description)):n.short&&!r&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let e=n.options.filter(e=>!e.hidden);t.push(...e)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||``}),e.registeredArguments.find(e=>e.description)?e.registeredArguments:[]}subcommandTerm(e){let n=e.registeredArguments.map(e=>t(e)).join(` `);return e._name+(e._aliases[0]?`|`+e._aliases[0]:``)+(e.options.length?` [options]`:``)+(n?` `+n:``)}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(n)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(n)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+`|`+e._aliases[0]);let n=``;for(let t=e.parent;t;t=t.parent)n=t.name()+` `+n;return n+t+` `+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue==`boolean`)&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,``]}groupItems(e,t,n){let r=new Map;return e.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[])}),t.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[]),r.get(t).push(e)}),r}formatHelp(e,t){let n=t.padWidth(e,t),r=t.helpWidth??80;function i(e,r){return t.formatItem(e,n,r,t)}let a=[`${t.styleTitle(`Usage:`)} ${t.styleUsage(t.commandUsage(e))}`,``],o=t.commandDescription(e);o.length>0&&(a=a.concat([t.boxWrap(t.styleCommandDescription(o),r),``]));let s=t.visibleArguments(e).map(e=>i(t.styleArgumentTerm(t.argumentTerm(e)),t.styleArgumentDescription(t.argumentDescription(e))));if(a=a.concat(this.formatItemList(`Arguments:`,s,t)),this.groupItems(e.options,t.visibleOptions(e),e=>e.helpGroupHeading??`Options:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),t.showGlobalOptions){let n=t.visibleGlobalOptions(e).map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(`Global Options:`,n,t))}return this.groupItems(e.commands,t.visibleCommands(e),e=>e.helpGroup()||`Commands:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleSubcommandTerm(t.subcommandTerm(e)),t.styleSubcommandDescription(t.subcommandDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),a.join(`
2
2
  `)}displayWidth(e){return r(e).length}styleTitle(e){return e}styleUsage(e){return e.split(` `).map(e=>e===`[options]`?this.styleOptionText(e):e===`[command]`?this.styleSubcommandText(e):e[0]===`[`||e[0]===`<`?this.styleArgumentText(e):this.styleCommandText(e)).join(` `)}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(` `).map(e=>e===`[options]`?this.styleOptionText(e):e[0]===`[`||e[0]===`<`?this.styleArgumentText(e):this.styleSubcommandText(e)).join(` `)}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,t,n,r){let i=` `.repeat(2);if(!n)return i+e;let a=e.padEnd(t+e.length-r.displayWidth(e)),o=(this.helpWidth??80)-t-2-2,s;return s=o<this.minWidthToWrap||r.preformatted(n)?n:r.boxWrap(n,o).replace(/\n/g,`
3
3
  `+` `.repeat(t+2)),i+a+` `.repeat(2)+s.replace(/\n/g,`\n${i}`)}boxWrap(e,t){if(t<this.minWidthToWrap)return e;let n=e.split(/\r\n|\n/),r=/[\s]*[^\s]+/g,i=[];return n.forEach(e=>{let n=e.match(r);if(n===null){i.push(``);return}let a=[n.shift()],o=this.displayWidth(a[0]);n.forEach(e=>{let n=this.displayWidth(e);if(o+n<=t){a.push(e),o+=n;return}i.push(a.join(``));let r=e.trimStart();a=[r],o=this.displayWidth(r)}),i.push(a.join(``))}),i.join(`
4
4
  `)}};function r(e){return e.replace(/\x1b\[\d*(;\d*)*m/g,``)}e.Help=n,e.stripColor=r})),E=n((e=>{let{InvalidArgumentError:t}=C();var n=class{constructor(e,t){this.flags=e,this.description=t||``,this.required=e.includes(`<`),this.optional=e.includes(`[`),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let n=a(e);this.short=n.shortFlag,this.long=n.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith(`--no-`)),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e==`string`&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,n)=>{if(!this.argChoices.includes(e))throw new t(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,n):e},this}name(){return this.long?this.long.replace(/^--/,``):this.short.replace(/^-/,``)}attributeName(){return this.negate?i(this.name().replace(/^no-/,``)):i(this.name())}helpGroup(e){return this.helpGroupHeading=e,this}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},r=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(e=>{e.negate?this.negativeOptions.set(e.attributeName(),e):this.positiveOptions.set(e.attributeName(),e)}),this.negativeOptions.forEach((e,t)=>{this.positiveOptions.has(t)&&this.dualOptions.add(t)})}valueFromOption(e,t){let n=t.attributeName();if(!this.dualOptions.has(n))return!0;let r=this.negativeOptions.get(n).presetArg,i=r===void 0?!1:r;return t.negate===(i===e)}};function i(e){return e.split(`-`).reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function a(e){let t,n,r=/^-[^-]$/,i=/^--[^-]/,a=e.split(/[ |,]+/).concat(`guard`);if(r.test(a[0])&&(t=a.shift()),i.test(a[0])&&(n=a.shift()),!t&&r.test(a[0])&&(t=a.shift()),!t&&i.test(a[0])&&(t=n,n=a.shift()),a[0].startsWith(`-`)){let t=a[0],n=`option creation failed due to '${t}' in option flags '${e}'`;throw/^-[^-][^-]/.test(t)?Error(`${n}
@@ -53,4 +53,4 @@ foreach ($d in $dirs) {
53
53
  }
54
54
  [Console]::Error.WriteLine('OpenKnowledge: install Node.js 24+ (npm i -g @inkeep/open-knowledge), then restart your editor')
55
55
  exit 127`,P=`// ok-pi-bridge`,F=`${P}-v1`,I=`ok-pi-managed-extension`;function L(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.command===`/bin/sh`){if(!Array.isArray(t.args)||t.args[0]!==`-l`||t.args[1]!==`-c`)return!1;let e=t.args[2];return typeof e==`string`&&e.includes(`# ok-mcp-v2`)}if(t.command===`powershell`){if(!Array.isArray(t.args)||t.args[0]!==`-NoProfile`||t.args[1]!==`-NonInteractive`||t.args[2]!==`-Command`)return!1;let e=t.args[3];return typeof e==`string`&&e.includes(`# ok-mcp-win-v1`)}if(t.type===`local`&&Array.isArray(t.command)){if(t.command[0]===`/bin/sh`){if(t.command[1]!==`-l`||t.command[2]!==`-c`)return!1;let e=t.command[3];return typeof e==`string`&&e.includes(`# ok-mcp-v2`)}if(t.command[0]===`powershell`){if(t.command[1]!==`-NoProfile`||t.command[2]!==`-NonInteractive`||t.command[3]!==`-Command`)return!1;let e=t.command[4];return typeof e==`string`&&e.includes(`# ok-mcp-win-v1`)}return!1}if(t.command===`ok-pi-managed-extension`){if(!Array.isArray(t.args))return!1;let e=t.args[0];return typeof e==`string`&&e.startsWith(F)}return!1}function R(e=process.argv[1]){if(!e)throw Error(`Cannot infer the local CLI entry for --dev-mcp because process.argv[1] is empty.`);let t=h(e);if(l(t)===`cli.mjs`&&l(u(t))===`dist`)return t;let n=t.split(g),r=n.lastIndexOf(`packages`);if(r===-1||n[r+1]!==`cli`)throw Error(`Cannot infer the repo root for --dev-mcp from ${t}. Run the local CLI from this repo so the built dist path can be derived.`);let i=n.slice(0,r);return f(i.length===0?g:i.join(g),`packages`,`cli`,`dist`,`cli.mjs`)}function z(e={}){return e.mode===`dev`?{command:A,args:[R(),`mcp`],env:{...j}}:(e.platformName??process.platform)===`win32`?{command:`powershell`,args:[`-NoProfile`,`-NonInteractive`,`-Command`,N]}:{command:`/bin/sh`,args:[`-l`,`-c`,M]}}function _e(e={}){return e.mode===`dev`?{type:`local`,enabled:!0,command:[A,R(),`mcp`],environment:{...j}}:(e.platformName??process.platform)===`win32`?{type:`local`,enabled:!0,command:[`powershell`,`-NoProfile`,`-NonInteractive`,`-Command`,N]}:{type:`local`,enabled:!0,command:[`/bin/sh`,`-l`,`-c`,M]}}function ve(e){if(typeof e!=`object`||!e)return!1;let t=e;return B(t,z({mode:`published`,platformName:`darwin`}))||B(t,z({mode:`published`,platformName:`win32`}))}function B(e,t){return Object.keys(e).length===Object.keys(t).length?ye(e,t):!1}function ye(e,t){if(e.command!==t.command)return!1;let n=t.args;return!Array.isArray(n)||!Array.isArray(e.args)||e.args.length!==n.length?!1:e.args.every((e,t)=>e===n[t])}function V(e,t){let n=e=>typeof e==`string`&&e.includes(`# ok-mcp`);return t===`/bin/sh`?e[0]===`-l`&&e[1]===`-c`&&n(e[2]):t===`powershell`?e[0]===`-NoProfile`&&e[1]===`-NonInteractive`&&e[2]===`-Command`&&n(e[3]):!1}function be(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.enabled===!1||typeof t.command!=`string`||!Array.isArray(t.args)?!1:V(t.args,t.command)}function xe(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.type!==`local`||t.enabled===!1||!Array.isArray(t.command))return!1;let[n,...r]=t.command;return typeof n==`string`&&V(r,n)}function H(e){return e===`win32`?_:p}function Se(e={}){let t=e.platformName??process.platform,n=e.home??S(),r=e.env??process.env,i=H(t);return t===`darwin`?i.join(n,`Library`,`Application Support`):t===`win32`?r.APPDATA??i.join(n,`AppData`,`Roaming`):r.XDG_CONFIG_HOME??i.join(n,`.config`)}function Ce(e={}){let t=e.platformName??process.platform,n=e.home??S();return H(t).join(n,`.claude.json`)}function U(e={}){let t=e.platformName??process.platform,n=e.home??S(),r=e.env??process.env;if(t===`darwin`)return p.join(n,`Library`,`Application Support`,`Claude`,`claude_desktop_config.json`);if(t===`win32`){let e=r.APPDATA??_.join(n,`AppData`,`Roaming`);return _.join(e,`Claude`,`claude_desktop_config.json`)}throw Error(`Claude Desktop is not available on ${t}. Supported: macOS, Windows.`)}function W(e={}){let t=e.platformName??process.platform,n=e.home??S();return H(t).join(n,`.cursor`,`mcp.json`)}function we(e={}){let t=e.platformName??process.platform,n=e.home??S();return(e.env??process.env).CODEX_HOME??H(t).join(n,`.codex`)}function G(e={}){return H(e.platformName??process.platform).join(we(e),`config.toml`)}function K(e={}){let t=e.platformName??process.platform,n=e.home??S(),r=(e.env??process.env).COPILOT_HOME??H(t).join(n,`.copilot`);return H(t).join(r,`mcp-config.json`)}function Te(e={}){let t=e.platformName??process.platform,n=e.home??S(),r=e.env??process.env,i=H(t);if(t===`win32`){let e=r.APPDATA??i.join(n,`AppData`,`Roaming`);return i.join(e,`opencode`)}let a=r.XDG_CONFIG_HOME??i.join(n,`.config`);return i.join(a,`opencode`)}function q(e={}){return H(e.platformName??process.platform).join(Te(e),`opencode.json`)}function Ee(e={}){let t=e.platformName??process.platform,n=e.home??S();return H(t).join(n,`.openclaw`,`openclaw.json`)}function De(e={}){let t=e.platformName??process.platform,n=e.home??S();return H(t).join(n,`.hermes`,`config.yaml`)}function Oe(e={}){let t=e.platformName??process.platform,n=e.home??S();return(e.env??process.env).PI_CODING_AGENT_DIR??H(t).join(n,`.pi`,`agent`)}function ke(e={}){let t=e.platformName??process.platform,n=e.home??S();return H(t).join(n,`.gemini`,`config`,`mcp_config.json`)}function Ae(e,t){let n=H(t),r=n.join(e,`.lmstudio`,`mcp.json`),i=n.join(e,`.cache`,`lm-studio`,`mcp.json`);return t===`darwin`?[i,r]:[r,i]}function J(e={}){let t=e.platformName??process.platform,n=Ae(e.home??S(),t);return n.find(e=>v(e))||n.find(e=>v(u(e)))||n[0]}const Y={claude:{id:`claude`,label:k.claude,configPath:(e,t)=>Ce({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>r,buildEntry:(e,t)=>z(t),scope:`global`,detectPath:(e,t)=>f(t??S(),`.claude`),projectConfigPath:e=>f(e,`.mcp.json`),projectSkillPath:e=>f(e,`.claude`,`skills`,`open-knowledge`,`SKILL.md`)},"claude-desktop":{id:`claude-desktop`,label:k[`claude-desktop`],configPath:(e,t)=>U({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>r,buildEntry:(e,t)=>z(t),scope:`global`,detectPath:(e,t)=>u(U({home:t}))},cursor:{id:`cursor`,label:k.cursor,configPath:(e,t)=>W({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>r,buildEntry:(e,t)=>z(t),scope:`global`,detectPath:(e,t)=>u(W({home:t})),projectConfigPath:e=>f(e,`.cursor`,`mcp.json`),projectSkillPath:e=>f(e,`.cursor`,`skills`,`open-knowledge`,`SKILL.md`)},codex:{id:`codex`,label:k.codex,configPath:(e,t)=>G({home:t}),format:`toml`,topLevelKey:`mcp_servers`,serverName:()=>r,buildEntry:(e,t)=>z(t),scope:`global`,detectPath:(e,t)=>u(G({home:t})),projectConfigPath:e=>f(e,`.codex`,`config.toml`),projectSkillPath:e=>f(e,`.codex`,`skills`,`open-knowledge`,`SKILL.md`)},copilot:{id:`copilot`,label:k.copilot,configPath:(e,t)=>K({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>r,buildEntry:(e,t)=>z(t),scope:`global`,detectPath:(e,t)=>u(K({home:t})),projectSkillPath:e=>f(e,`.github`,`skills`,`open-knowledge`,`SKILL.md`)},opencode:{id:`opencode`,label:k.opencode,configPath:(e,t)=>q({home:t}),format:`json`,topLevelKey:`mcp`,serverName:()=>r,buildEntry:(e,t)=>_e(t),scope:`global`,detectPath:(e,t)=>u(q({home:t})),projectConfigPath:e=>f(e,`opencode.json`),projectSkillPath:e=>f(e,`.opencode`,`skills`,`open-knowledge`,`SKILL.md`)},openclaw:{id:`openclaw`,label:k.openclaw,configPath:(e,t)=>Ee({home:t}),format:`json`,topLevelKey:`mcp`,serverMapSubKey:`servers`,serverName:()=>r,buildEntry:(e,t)=>z(t),scope:`global`,detectPath:(e,t)=>f(t??S(),`.openclaw`),offerOnlyWhenDetected:!0},pi:{id:`pi`,label:k.pi,configPath:()=>{throw Error("Pi has no user-global MCP config; OK's integration is the project-scoped bridge extension at .pi/extensions/open-knowledge.ts (run `ok init` in the project).")},format:`file`,topLevelKey:`mcpServers`,serverName:()=>r,buildEntry:()=>{throw Error(`Pi has no MCP entry shape; the managed bridge file is built by buildPiExtensionSource (integrations/pi-extension.ts).`)},scope:`project`,detectPath:(e,t)=>Oe({home:t}),projectConfigPath:e=>f(e,`.pi`,`extensions`,`open-knowledge.ts`),projectSkillPath:e=>f(e,`.pi`,`skills`,`open-knowledge`,`SKILL.md`)},antigravity:{id:`antigravity`,label:k.antigravity,configPath:(e,t)=>ke({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>r,buildEntry:(e,t)=>z(t),scope:`global`,detectPath:(e,t)=>f(t??S(),`.gemini`),offerOnlyWhenDetected:!0},"lm-studio":{id:`lm-studio`,label:k[`lm-studio`],configPath:(e,t)=>J({home:t}),format:`json`,topLevelKey:`mcpServers`,serverName:()=>r,buildEntry:(e,t)=>z(t),scope:`global`,detectPath:(e,t)=>u(J({home:t})),offerOnlyWhenDetected:!0},hermes:{id:`hermes`,label:k.hermes,configPath:(e,t)=>De({home:t}),format:`yaml`,topLevelKey:`mcp_servers`,serverName:()=>r,buildEntry:(e,t)=>z(t),scope:`global`,detectPath:(e,t)=>f(t??S(),`.hermes`),offerOnlyWhenDetected:!0}};function je(e){let t=e.filter(e=>!Object.hasOwn(Y,e));if(t.length>0)throw Error(`Unknown editor(s): ${t.join(`, `)}. Valid options: ${O.join(`, `)}`);return e.map(e=>Y[e])}function X(e,t){let n;try{n=te(e)}catch(e){if(e.code!==`ENOENT`)throw e}if(n?.isSymbolicLink())throw Error(`Refusing to write through a symbolic link at ${e}. Remove the symlink and re-run project setup.`);Z(e,t)}function Me(e,t){Z(e,t)}function Z(e,t){let n;try{n=b(t)}catch{n=h(t)}let r=u(e);for(;r.length>1&&r!==g;){let t;try{t=b(r)}catch(e){if(e.code===`ENOENT`){r=u(r);continue}throw e}let i=m(n,t);if(i===``||!i.startsWith(`..`)&&!d(i))return;throw Error(`Refusing to write at ${e}: ancestor ${r} resolves to ${t}, which is outside the project directory ${n}. A symbolic link in the path likely escapes the project. Remove the symlink and re-run project setup.`)}}function Q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ne(e,t,n){try{if(re(n).size>10485760)return!1}catch{return!1}let r;try{r=ne(n,`utf-8`)}catch{return!1}let i=[],a=c(r.charCodeAt(0)===65279?r.slice(1):r,i,{allowTrailingComma:!0,disallowComments:!1});if(i.length>0||!Q(a))return!1;let o=a[e.topLevelKey];if(!Q(o))return!1;let s=e.serverMapSubKey?o[e.serverMapSubKey]:o;return Q(s)?Q(s[e.serverName(t)]):!1}function Pe(e,t,n={}){if(e.id!==`copilot`)return!0;try{return Ne(e,t,e.configPath(t,n.home))}catch{return!1}}function $(e,t,n={}){let r=e.projectSkillPath?.(t);if(!r)return{editorId:e.id,label:e.label,action:`skipped-unsupported`,path:``};if(!Pe(e,t,n))return{editorId:e.id,label:e.label,action:`skipped-prerequisite`,path:r};try{let n=s(`project`,{checkDesktop:!0}),i=u(r);X(i,t);let a=v(r)?`overwritten`:`written`;return x(i,{recursive:!0,force:!0}),y(u(i),{recursive:!0}),ee(n,i,{recursive:!0}),{editorId:e.id,label:e.label,action:a,path:r}}catch(t){return{editorId:e.id,label:e.label,action:`failed`,path:r,error:t instanceof Error?t.message:String(t)}}}export{je as _,k as a,me as b,P as c,z as d,be as f,Se as g,xe as h,O as i,F as l,ve as m,Me as n,Y as o,L as p,$ as r,ge as s,X as t,I as u,fe as v,D as y};
56
- //# sourceMappingURL=write-project-skill-DWGQrWRr.mjs.map
56
+ //# sourceMappingURL=write-project-skill-Bzg8sfOX.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/open-knowledge",
3
- "version": "0.54.0-beta.0",
3
+ "version": "0.54.0-beta.2",
4
4
  "license": "GPL-3.0-or-later",
5
5
  "private": false,
6
6
  "type": "module",
@@ -62,10 +62,10 @@
62
62
  "ajv-formats": "^3.0.1",
63
63
  "tsdown": "^0.21.7",
64
64
  "typescript": "^5.9.3",
65
- "@inkeep/open-knowledge-app": "0.54.0-beta.0",
66
- "@inkeep/open-knowledge-core": "0.54.0-beta.0",
65
+ "@inkeep/open-knowledge-app": "0.54.0-beta.2",
67
66
  "@inkeep/open-knowledge-native-config": "0.0.0",
68
- "@inkeep/open-knowledge-server": "0.54.0-beta.0"
67
+ "@inkeep/open-knowledge-core": "0.54.0-beta.2",
68
+ "@inkeep/open-knowledge-server": "0.54.0-beta.2"
69
69
  },
70
70
  "scripts": {
71
71
  "build:cli": "rm -rf dist && tsdown",
@@ -1,2 +0,0 @@
1
- import"./src-BqZfalMj.mjs";var e=`0.54.0-beta.0`;const t=`config.yml`,n=e;export{n,t};
2
- //# sourceMappingURL=constants-CdO7Ip8K.mjs.map
@@ -1 +0,0 @@
1
- import{g as e}from"./init-DqyJAJAm.mjs";export{e as runInit};
@@ -1 +0,0 @@
1
- import{n as e}from"./loader-BkusT1hI.mjs";export{e as loadConfig};
@@ -1 +0,0 @@
1
- import{n as e,t}from"./preview-kSEjxYuX.mjs";export{t as formatPreviewBlock,e as previewContent};
@@ -1 +0,0 @@
1
- import{t as e}from"./index-CQiP7zms.js";export{e as FeedbackForm};
@@ -1 +0,0 @@
1
- import{t as e}from"./ManagedArtifactProperties-D1j8yV7G.js";export{e as ManagedArtifactProperties};
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CYidjpOJ.js";import{t}from"./jsx-runtime-BUgB2tll.js";import{t as n}from"./react-f2sANaYj.js";import{n as r,r as i}from"./dist-Nvb76hAm.js";import{t as a}from"./compiler-runtime-BfE3aGVn.js";import{t as o}from"./utils-CPqDy6Hr.js";import{t as s}from"./button-CA0dewJJ.js";import{t as c}from"./label-B5yNUINo.js";import{i as l,n as u,o as d,s as f,t as p}from"./select-CguJodwX.js";import{t as m}from"./switch-B2sF5R0q.js";import{n as h}from"./dist-B6jB2qbD2.js";import{t as g}from"./createLucideIcon-Bhw2PmPp.js";import{t as _}from"./braces-CJEjDc1f.js";import{t as v}from"./case-sensitive-CE1B0vR4.js";import{t as y}from"./hash-PyoMEEnH.js";import{t as b}from"./trash-2-BWJWOK8-.js";import{t as x}from"./input-BFt4qZaV.js";import{d as S,f as C,o as w,r as T,s as E}from"./lint-config-client-kEetoezQ.js";import{i as D,r as ee,t as O}from"./EditorModeToggle-CiWiUMD4.js";import{t as k}from"./tag-pill-input-Bcisv-E4.js";import{t as te}from"./useLintConfigViewMode-DX8l9aBY.js";import{i as A,r as ne,t as re}from"./schema-fields-view-intent-D0jz38_6.js";var j=g(`brackets`,[[`path`,{d:`M16 3h3a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-3`,key:`1kt8lf`}],[`path`,{d:`M8 21H5a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h3`,key:`gduv9`}]]),M=g(`list-checks`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]),N=g(`toggle-left`,[[`circle`,{cx:`9`,cy:`12`,r:`3`,key:`u3jwor`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`7`,key:`g7kal2`}]]),P=a(),F=e(n(),1),I=t(),ie=[`string`,`number`,`boolean`,`array`,`object`],L=[`string`,`number`,`boolean`,`enum`,`array`,`object`],R=[`string`,`number`,`boolean`,`enum`,`object`],z={string:{Icon:v,className:`text-green-500`},number:{Icon:y,className:`text-blue-500`},boolean:{Icon:N,className:`text-orange-500`},enum:{Icon:M,className:`text-yellow-500`},array:{Icon:j,className:`text-pink-500`},object:{Icon:_,className:`text-purple-500`}};function ae(e){let t=(0,P.c)(8),{option:n}=e,{Icon:r,className:i}=z[n],a;t[0]===i?a=t[1]:(a=o(`size-3.5 shrink-0`,i),t[0]=i,t[1]=a);let s;t[2]!==r||t[3]!==a?(s=(0,I.jsx)(r,{"aria-hidden":!0,className:a}),t[2]=r,t[3]=a,t[4]=s):s=t[4];let c;return t[5]!==n||t[6]!==s?(c=(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[s,n]}),t[5]=n,t[6]=s,t[7]=c):c=t[7],c}function oe(e){let t=(0,P.c)(5),{option:n}=e,{Icon:r,className:i}=z[n],a;t[0]===i?a=t[1]:(a=o(`size-4 shrink-0`,i),t[0]=i,t[1]=a);let s;return t[2]!==r||t[3]!==a?(s=(0,I.jsx)(r,{"aria-hidden":!0,className:a}),t[2]=r,t[3]=a,t[4]=s):s=t[4],s}var se=4,B=new Set([`$schema`,`type`,`properties`,`required`]),ce=new Set([`type`,`enum`,`pattern`,`format`,`items`,`description`,`properties`,`required`]);function V(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function le(e){return e===void 0?[]:Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:null}function ue(e){if(Object.keys(e).some(e=>!ce.has(e)))return!0;let t=e.items;if(t!==void 0){if(!V(t))return!0;let e=new Set([`enum`,`type`,`properties`,`required`,`description`]);if(Object.keys(t).some(t=>!e.has(t)))return!0}return!1}function de(e,t){return[...e.map(e=>typeof e==`string`?e:`[]`),t].join(`.`)}function fe(e){let t=(0,P.c)(28),{file:n}=e,{_:a}=i(),{data:o}=S(),s,c,l,u,d,f,p;if(t[0]!==a||t[1]!==o?.effective.plugins.frontmatter.schemas||t[2]!==n){let e=o?.effective.plugins.frontmatter.schemas.find(e=>e.file===n)?.schema,i=V(e)?Object.keys(e).filter(pe):[],m;t[10]!==a||t[11]!==n?(m={save:(e,t,r)=>{(async()=>{let i=await C(n,e,t,r);i.ok?T():h.error(i.errorDetail??a({id:`IQgeSn`}))})()},rename:(e,t,r)=>{(async()=>{let i=await E(n,e,t,r);i.ok?T():h.error(i.errorDetail??a({id:`kooyLJ`}))})()},remove:(e,t)=>{(async()=>{let r=await w(n,e,t);r.ok?T():h.error(r.errorDetail??a({id:`qC7PwZ`}))})()}},t[10]=a,t[11]=n,t[12]=m):m=t[12],c=m,u=`space-y-3`,d=`frontmatter-field-editor-${n}`,f=e===void 0&&(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:(0,I.jsx)(r,{id:`ri6zS-`})}),t[13]!==n||t[14]!==i?(p=i.length>0&&(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`frontmatter-schema-root-preserved-${n}`,children:(0,I.jsx)(r,{id:`98FP1E`,values:{0:i.join(`, `)}})}),t[13]=n,t[14]=i,t[15]=p):p=t[15],s=me,l=V(e)?e:{},t[0]=a,t[1]=o?.effective.plugins.frontmatter.schemas,t[2]=n,t[3]=s,t[4]=c,t[5]=l,t[6]=u,t[7]=d,t[8]=f,t[9]=p}else s=t[3],c=t[4],l=t[5],u=t[6],d=t[7],f=t[8],p=t[9];let m;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(m=[],t[16]=m):m=t[16];let g=`frontmatter-add-field-${n}`,_;t[17]!==s||t[18]!==c||t[19]!==l||t[20]!==g?(_=(0,I.jsx)(s,{node:l,parentPath:m,depth:0,addInputId:g,ops:c}),t[17]=s,t[18]=c,t[19]=l,t[20]=g,t[21]=_):_=t[21];let v;return t[22]!==u||t[23]!==d||t[24]!==f||t[25]!==p||t[26]!==_?(v=(0,I.jsxs)(`div`,{className:u,"data-testid":d,children:[f,p,_]}),t[22]=u,t[23]=d,t[24]=f,t[25]=p,t[26]=_,t[27]=v):v=t[27],v}function pe(e){return!B.has(e)}function me(e){let t=(0,P.c)(19),{node:n,parentPath:r,depth:i,addInputId:a,ops:o}=e,s;t[0]===n.properties?s=t[1]:(s=V(n.properties)?n.properties:{},t[0]=n.properties,t[1]=s);let c=s,l,u;if(t[2]!==i||t[3]!==n.required||t[4]!==o||t[5]!==r||t[6]!==c){let e=Array.isArray(n.required)?n.required.filter(H):[];l=`space-y-2`,u=Object.entries(c).map(t=>{let[n,a]=t;return(0,I.jsx)(he,{field:n,property:V(a)?a:{},isRequired:e.includes(n),parentPath:r,depth:i,ops:o},n)}),t[2]=i,t[3]=n.required,t[4]=o,t[5]=r,t[6]=c,t[7]=l,t[8]=u}else l=t[7],u=t[8];let d;t[9]!==o||t[10]!==r?(d=e=>o.save(e,{type:`string`},r),t[9]=o,t[10]=r,t[11]=d):d=t[11];let f;t[12]!==a||t[13]!==d?(f=(0,I.jsx)(U,{inputId:a,onAdd:d}),t[12]=a,t[13]=d,t[14]=f):f=t[14];let p;return t[15]!==l||t[16]!==u||t[17]!==f?(p=(0,I.jsxs)(`div`,{className:l,children:[u,f]}),t[15]=l,t[16]=u,t[17]=f,t[18]=p):p=t[18],p}function H(e){return typeof e==`string`}function he(e){let t=(0,P.c)(170),{field:n,property:a,isRequired:o,parentPath:l,depth:h,ops:g}=e,{_}=i(),[v,y]=(0,F.useState)(!1),[x,S]=(0,F.useState)(!1),C;t[0]!==n||t[1]!==l?(C=de(l,n),t[0]=n,t[1]=l,t[2]=C):C=t[2];let w=C,T=typeof a.type==`string`&&ie.includes(a.type)?a.type:void 0,E;t[3]===a.enum?E=t[4]:(E=le(a.enum),t[3]=a.enum,t[4]=E);let D=E,ee;t[5]===a.items?ee=t[6]:(ee=V(a.items)?a.items:{},t[5]=a.items,t[6]=ee);let O=ee,te;t[7]===O.enum?te=t[8]:(te=le(O.enum),t[7]=O.enum,t[8]=te);let A=te,ne=typeof a.pattern==`string`?a.pattern:``,re=typeof a.description==`string`?a.description:``,j;t[9]===a?j=t[10]:(j=ue(a),t[9]=a,t[10]=j);let M=j,N=T!==`array`&&T!==`object`&&D!==null&&(v||T===void 0&&D.length>0),z=T===`object`&&h<se,ae;t[11]===O.type?ae=t[12]:(ae=typeof O.type==`string`&&R.includes(O.type)?O.type:void 0,t[11]=O.type,t[12]=ae);let B=ae,ce=B!==`object`&&A!==null&&(x||B===void 0&&A.length>0),fe=T===`array`&&B===`object`&&h<se,pe=`frontmatter-field-row-${w}`,H;t[13]!==N||t[14]!==T?(H=(N||T!==void 0)&&(0,I.jsx)(oe,{option:N?`enum`:T}),t[13]=N,t[14]=T,t[15]=H):H=t[15];let he=`frontmatter-field-name-${w}`,U;t[16]===_?U=t[17]:(U=_({id:`nrXDdR`}),t[16]=_,t[17]=U);let W;t[18]!==n||t[19]!==g||t[20]!==l?(W=e=>{e!==``&&e!==n&&g.rename(n,e,l)},t[18]=n,t[19]=g,t[20]=l,t[21]=W):W=t[21];let G;t[22]!==n||t[23]!==U||t[24]!==W||t[25]!==he?(G=(0,I.jsx)(ve,{id:he,initial:n,ariaLabel:U,className:`h-7 w-36 shrink-0 font-mono text-sm font-medium`,onCommit:W}),t[22]=n,t[23]=U,t[24]=W,t[25]=he,t[26]=G):G=t[26];let ye=`frontmatter-field-description-${w}`,K;t[27]===_?K=t[28]:(K=_({id:`PGPGsL`}),t[27]=_,t[28]=K);let q;t[29]!==_||t[30]!==n?(q=_({id:`IFALcX`,values:{field:n}}),t[29]=_,t[30]=n,t[31]=q):q=t[31];let J;t[32]!==n||t[33]!==g||t[34]!==l?(J=e=>g.save(n,{description:e===``?null:e},l),t[32]=n,t[33]=g,t[34]=l,t[35]=J):J=t[35];let Y;t[36]!==re||t[37]!==ye||t[38]!==K||t[39]!==q||t[40]!==J?(Y=(0,I.jsx)(ve,{id:ye,initial:re,placeholder:K,ariaLabel:q,className:`h-7 min-w-0 flex-1`,onCommit:J}),t[36]=re,t[37]=ye,t[38]=K,t[39]=q,t[40]=J,t[41]=Y):Y=t[41];let be=`frontmatter-field-required-${w}`,xe;t[42]===Symbol.for(`react.memo_cache_sentinel`)?(xe=(0,I.jsx)(r,{id:`TMLAx2`}),t[42]=xe):xe=t[42];let X;t[43]===be?X=t[44]:(X=(0,I.jsx)(c,{htmlFor:be,className:`shrink-0 text-xs text-muted-foreground`,children:xe}),t[43]=be,t[44]=X);let Se=`frontmatter-field-required-${w}`,Z;t[45]!==n||t[46]!==g||t[47]!==l?(Z=e=>g.save(n,{required:e},l),t[45]=n,t[46]=g,t[47]=l,t[48]=Z):Z=t[48];let Ce=`frontmatter-field-required-${w}`,we;t[49]!==o||t[50]!==Se||t[51]!==Z||t[52]!==Ce?(we=(0,I.jsx)(m,{id:Se,checked:o,onCheckedChange:Z,"data-testid":Ce}),t[49]=o,t[50]=Se,t[51]=Z,t[52]=Ce,t[53]=we):we=t[53];let Te;t[54]!==n||t[55]!==g||t[56]!==l?(Te=()=>g.remove(n,l),t[54]=n,t[55]=g,t[56]=l,t[57]=Te):Te=t[57];let Ee;t[58]!==_||t[59]!==n?(Ee=_({id:`bF22t6`,values:{field:n}}),t[58]=_,t[59]=n,t[60]=Ee):Ee=t[60];let De=`frontmatter-field-remove-${w}`,Oe;t[61]===Symbol.for(`react.memo_cache_sentinel`)?(Oe=(0,I.jsx)(b,{"aria-hidden":!0,className:`size-4`}),t[61]=Oe):Oe=t[61];let ke;t[62]!==Te||t[63]!==Ee||t[64]!==De?(ke=(0,I.jsx)(s,{variant:`ghost`,size:`icon`,className:`size-7 shrink-0`,onClick:Te,"aria-label":Ee,"data-testid":De,children:Oe}),t[62]=Te,t[63]=Ee,t[64]=De,t[65]=ke):ke=t[65];let Ae;t[66]!==G||t[67]!==Y||t[68]!==X||t[69]!==we||t[70]!==ke||t[71]!==H?(Ae=(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[H,G,Y,X,we,ke]}),t[66]=G,t[67]=Y,t[68]=X,t[69]=we,t[70]=ke,t[71]=H,t[72]=Ae):Ae=t[72];let je;t[73]!==w||t[74]!==M?(je=M&&(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`frontmatter-field-preserved-${w}`,children:(0,I.jsx)(r,{id:`TdlVEN`})}),t[73]=w,t[74]=M,t[75]=je):je=t[75];let Me=`frontmatter-field-type-${w}`,Ne;t[76]===Symbol.for(`react.memo_cache_sentinel`)?(Ne=(0,I.jsx)(r,{id:`-zy2Nq`}),t[76]=Ne):Ne=t[76];let Pe;t[77]===Me?Pe=t[78]:(Pe=(0,I.jsx)(c,{className:`text-xs`,htmlFor:Me,children:Ne}),t[77]=Me,t[78]=Pe);let Fe=N?`enum`:T??``,Ie;t[79]!==D?.length||t[80]!==n||t[81]!==g||t[82]!==l?(Ie=e=>{if(e===`enum`){y(!0);return}y(!1);let t=e!==`string`&&(D?.length??0)>0?{type:e,enum:null}:{type:e};g.save(n,t,l)},t[79]=D?.length,t[80]=n,t[81]=g,t[82]=l,t[83]=Ie):Ie=t[83];let Le=`frontmatter-field-type-${w}`,Re=`frontmatter-field-type-${w}`,Q;t[84]===_?Q=t[85]:(Q=_({id:`EkUnmS`}),t[84]=_,t[85]=Q);let ze;t[86]===Q?ze=t[87]:(ze=(0,I.jsx)(f,{placeholder:Q}),t[86]=Q,t[87]=ze);let Be;t[88]!==Le||t[89]!==Re||t[90]!==ze?(Be=(0,I.jsx)(d,{id:Le,"data-testid":Re,children:ze}),t[88]=Le,t[89]=Re,t[90]=ze,t[91]=Be):Be=t[91];let Ve;t[92]===Symbol.for(`react.memo_cache_sentinel`)?(Ve=(0,I.jsx)(u,{children:L.map(_e)}),t[92]=Ve):Ve=t[92];let He;t[93]!==Fe||t[94]!==Ie||t[95]!==Be?(He=(0,I.jsxs)(p,{value:Fe,onValueChange:Ie,children:[Be,Ve]}),t[93]=Fe,t[94]=Ie,t[95]=Be,t[96]=He):He=t[96];let Ue;t[97]!==Pe||t[98]!==He?(Ue=(0,I.jsxs)(`div`,{className:`space-y-1`,children:[Pe,He]}),t[97]=Pe,t[98]=He,t[99]=Ue):Ue=t[99];let We=`frontmatter-field-pattern-${w}`,Ge;t[100]===Symbol.for(`react.memo_cache_sentinel`)?(Ge=(0,I.jsx)(r,{id:`cstC0z`}),t[100]=Ge):Ge=t[100];let Ke;t[101]===We?Ke=t[102]:(Ke=(0,I.jsx)(c,{className:`text-xs`,htmlFor:We,children:Ge}),t[101]=We,t[102]=Ke);let qe=`frontmatter-field-pattern-${w}`,Je;t[103]!==n||t[104]!==g||t[105]!==l?(Je=e=>g.save(n,{pattern:e===``?null:e},l),t[103]=n,t[104]=g,t[105]=l,t[106]=Je):Je=t[106];let Ye;t[107]!==ne||t[108]!==qe||t[109]!==Je?(Ye=(0,I.jsx)(ve,{id:qe,initial:ne,onCommit:Je}),t[107]=ne,t[108]=qe,t[109]=Je,t[110]=Ye):Ye=t[110];let Xe;t[111]!==Ke||t[112]!==Ye?(Xe=(0,I.jsxs)(`div`,{className:`space-y-1`,children:[Ke,Ye]}),t[111]=Ke,t[112]=Ye,t[113]=Xe):Xe=t[113];let Ze;t[114]!==Ue||t[115]!==Xe?(Ze=(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[Ue,Xe]}),t[114]=Ue,t[115]=Xe,t[116]=Ze):Ze=t[116];let Qe;t[117]!==_||t[118]!==D||t[119]!==n||t[120]!==g||t[121]!==l||t[122]!==w||t[123]!==T?(Qe=T!==`array`&&T!==`object`&&D!==null&&(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(c,{className:`text-xs`,htmlFor:`frontmatter-field-enum-${w}`,children:(0,I.jsx)(r,{id:`UGeJuP`})}),(0,I.jsx)(k,{id:`frontmatter-field-enum-${w}`,value:D,grammar:`free-text`,onChange:e=>g.save(n,{enum:e.length===0?null:e},l),placeholder:_({id:`5tcmwY`}),"aria-label":_({id:`5qQr1u`,values:{field:n}})})]}),t[117]=_,t[118]=D,t[119]=n,t[120]=g,t[121]=l,t[122]=w,t[123]=T,t[124]=Qe):Qe=t[124];let $e;t[125]!==_||t[126]!==n||t[127]!==A?.length||t[128]!==B||t[129]!==g||t[130]!==l||t[131]!==w||t[132]!==ce||t[133]!==T?($e=T===`array`&&(0,I.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(c,{className:`text-xs`,htmlFor:`frontmatter-field-items-type-${w}`,children:(0,I.jsx)(r,{id:`6pe_G5`})}),(0,I.jsxs)(p,{value:ce?`enum`:B??``,onValueChange:e=>{if(e===`enum`){S(!0);return}S(!1);let t=e!==`string`&&(A?.length??0)>0?{itemsType:e,itemsEnum:null}:{itemsType:e};g.save(n,t,l)},children:[(0,I.jsx)(d,{id:`frontmatter-field-items-type-${w}`,"data-testid":`frontmatter-field-items-type-${w}`,children:(0,I.jsx)(f,{placeholder:_({id:`EkUnmS`})})}),(0,I.jsx)(u,{children:R.map(ge)})]})]})}),t[125]=_,t[126]=n,t[127]=A?.length,t[128]=B,t[129]=g,t[130]=l,t[131]=w,t[132]=ce,t[133]=T,t[134]=$e):$e=t[134];let et;t[135]!==_||t[136]!==n||t[137]!==A||t[138]!==B||t[139]!==g||t[140]!==l||t[141]!==w||t[142]!==T?(et=T===`array`&&B!==`object`&&A!==null&&(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(c,{className:`text-xs`,htmlFor:`frontmatter-field-items-enum-${w}`,children:(0,I.jsx)(r,{id:`ezUmoU`})}),(0,I.jsx)(k,{id:`frontmatter-field-items-enum-${w}`,value:A,grammar:`free-text`,onChange:e=>g.save(n,{itemsEnum:e.length===0?null:e},l),placeholder:_({id:`5tcmwY`}),"aria-label":_({id:`e60wew`,values:{field:n}})})]}),t[135]=_,t[136]=n,t[137]=A,t[138]=B,t[139]=g,t[140]=l,t[141]=w,t[142]=T,t[143]=et):et=t[143];let tt;t[144]!==h||t[145]!==n||t[146]!==O||t[147]!==g||t[148]!==l||t[149]!==w||t[150]!==fe?(tt=fe&&(0,I.jsxs)(`div`,{className:`ml-2 space-y-1 border-l pl-3 pt-1`,"data-testid":`frontmatter-field-item-children-${w}`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:(0,I.jsx)(r,{id:`wU8WyK`})}),(0,I.jsx)(me,{node:O,parentPath:[...l,n,{items:!0}],depth:h+1,addInputId:`frontmatter-add-field-${w}.[]`,ops:g})]}),t[144]=h,t[145]=n,t[146]=O,t[147]=g,t[148]=l,t[149]=w,t[150]=fe,t[151]=tt):tt=t[151];let $;t[152]!==h||t[153]!==n||t[154]!==g||t[155]!==l||t[156]!==w||t[157]!==a||t[158]!==z?($=z&&(0,I.jsxs)(`div`,{className:`ml-2 space-y-1 border-l pl-3 pt-1`,"data-testid":`frontmatter-field-children-${w}`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:(0,I.jsx)(r,{id:`9nIrRp`})}),(0,I.jsx)(me,{node:a,parentPath:[...l,n],depth:h+1,addInputId:`frontmatter-add-field-${w}`,ops:g})]}),t[152]=h,t[153]=n,t[154]=g,t[155]=l,t[156]=w,t[157]=a,t[158]=z,t[159]=$):$=t[159];let nt;return t[160]!==Ae||t[161]!==je||t[162]!==Ze||t[163]!==Qe||t[164]!==$e||t[165]!==et||t[166]!==tt||t[167]!==$||t[168]!==pe?(nt=(0,I.jsxs)(`div`,{className:`space-y-2 rounded-md border p-3`,"data-testid":pe,children:[Ae,je,Ze,Qe,$e,et,tt,$]}),t[160]=Ae,t[161]=je,t[162]=Ze,t[163]=Qe,t[164]=$e,t[165]=et,t[166]=tt,t[167]=$,t[168]=pe,t[169]=nt):nt=t[169],nt}function ge(e){return(0,I.jsx)(l,{value:e,children:(0,I.jsx)(ae,{option:e})},e)}function _e(e){return(0,I.jsx)(l,{value:e,children:(0,I.jsx)(ae,{option:e})},e)}function U(e){let t=(0,P.c)(24),{inputId:n,onAdd:i}=e,[a,o]=(0,F.useState)(``),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,I.jsx)(r,{id:`Va3xJe`}),t[0]=l):l=t[0];let u;t[1]===n?u=t[2]:(u=(0,I.jsx)(c,{htmlFor:n,className:`text-xs`,children:l}),t[1]=n,t[2]=u);let d;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(d=e=>o(e.target.value),t[3]=d):d=t[3];let f=`${n}-input`,p;t[4]!==n||t[5]!==a||t[6]!==f?(p=(0,I.jsx)(x,{id:n,value:a,onChange:d,placeholder:`owner`,"data-testid":f}),t[4]=n,t[5]=a,t[6]=f,t[7]=p):p=t[7];let m;t[8]!==u||t[9]!==p?(m=(0,I.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[u,p]}),t[8]=u,t[9]=p,t[10]=m):m=t[10];let h;t[11]===a?h=t[12]:(h=a.trim(),t[11]=a,t[12]=h);let g=h===``,_;t[13]!==a||t[14]!==i?(_=()=>{i(a.trim()),o(``)},t[13]=a,t[14]=i,t[15]=_):_=t[15];let v=`${n}-save`,y;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,I.jsx)(r,{id:`m16xKo`}),t[16]=y):y=t[16];let b;t[17]!==v||t[18]!==g||t[19]!==_?(b=(0,I.jsx)(s,{size:`sm`,variant:`outline`,disabled:g,onClick:_,"data-testid":v,children:y}),t[17]=v,t[18]=g,t[19]=_,t[20]=b):b=t[20];let S;return t[21]!==b||t[22]!==m?(S=(0,I.jsxs)(`div`,{className:`flex items-end gap-2`,children:[m,b]}),t[21]=b,t[22]=m,t[23]=S):S=t[23],S}function ve(e){let t=(0,P.c)(15),{id:n,initial:r,onCommit:i,placeholder:a,ariaLabel:o,className:s}=e,[c,l]=(0,F.useState)(r),u;t[0]!==c||t[1]!==r||t[2]!==i?(u=()=>{c.trim()!==r&&i(c.trim())},t[0]=c,t[1]=r,t[2]=i,t[3]=u):u=t[3];let d=u,f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=e=>l(e.target.value),t[4]=f):f=t[4];let p;t[5]===d?p=t[6]:(p=e=>{e.key===`Enter`&&d()},t[5]=d,t[6]=p);let m;return t[7]!==o||t[8]!==s||t[9]!==d||t[10]!==c||t[11]!==n||t[12]!==a||t[13]!==p?(m=(0,I.jsx)(x,{id:n,value:c,onChange:f,onBlur:d,onKeyDown:p,placeholder:a,"aria-label":o,className:s,"data-testid":n}),t[7]=o,t[8]=s,t[9]=d,t[10]=c,t[11]=n,t[12]=a,t[13]=p,t[14]=m):m=t[14],m}function W(e){return`/api/asset-text?path=${encodeURIComponent(e)}`}function G(e){let t=(0,P.c)(45),{assetPath:n}=e,{_:r}=i(),[a,o]=te(),[s,c]=(0,F.useState)(null),l=s??a,u;t[0]===o?u=t[1]:(u=e=>{c(e),o(e)},t[0]=o,t[1]=u);let d=u,f,p;t[2]===n?(f=t[3],p=t[4]):(f=()=>{let e=e=>{e===n&&re(e)&&c(`rules`)};return e(n),ne(e)},p=[n],t[2]=n,t[3]=f,t[4]=p),(0,F.useEffect)(f,p);let{data:m}=S(),h;t[5]===m?.effective.plugins.frontmatter.schemas?h=t[6]:(h=m?.effective.plugins.frontmatter.schemas??[],t[5]=m?.effective.plugins.frontmatter.schemas,t[6]=h);let g;if(t[7]!==n||t[8]!==h){let e;t[10]===n?e=t[11]:(e=e=>e.file===n,t[10]=n,t[11]=e),g=h.some(e),t[7]=n,t[8]=h,t[9]=g}else g=t[9];let _=g,v=!_||l===`source`,y;t[12]===n?y=t[13]:(y=n.split(`/`).pop()??n,t[12]=n,t[13]=y);let b=y,x;t[14]===b?x=t[15]:(x=b.includes(`.`)?(b.split(`.`).pop()??``).toLowerCase():``,t[14]=b,t[15]=x);let C=x,w;t[16]===n?w=t[17]:(w=(0,I.jsx)(ee,{entry:{kind:`asset`,path:n},className:`shrink-0 border-b bg-background px-3 py-1.5`}),t[16]=n,t[17]=w);let T;t[18]===d?T=t[19]:(T=e=>d(e===`source`?`source`:`rules`),t[18]=d,t[19]=T);let E=!_,k;t[20]===r?k=t[21]:(k=r({id:`vF68cg`}),t[20]=r,t[21]=k);let j;t[22]===r?j=t[23]:(j=r({id:`wdxz7K`}),t[22]=r,t[23]=j);let M;t[24]===r?M=t[25]:(M=r({id:`nc-ipN`}),t[24]=r,t[25]=M);let N;t[26]!==v||t[27]!==E||t[28]!==k||t[29]!==j||t[30]!==M||t[31]!==T?(N=(0,I.jsx)(O,{isSourceMode:v,onModeChange:T,wysiwygDisabled:E,wysiwygLabel:k,sourceLabel:j,wysiwygDisabledReason:M}),t[26]=v,t[27]=E,t[28]=k,t[29]=j,t[30]=M,t[31]=T,t[32]=N):N=t[32];let ie;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(ie=(0,I.jsx)(A,{className:`absolute left-3 top-1/2 h-4 -translate-y-1/2 px-1 text-[10px]`}),t[33]=ie):ie=t[33];let L;t[34]===N?L=t[35]:(L=(0,I.jsxs)(`div`,{className:`relative flex shrink-0 items-center justify-center border-b bg-background py-2`,children:[N,ie]}),t[34]=N,t[35]=L);let R;t[36]!==n||t[37]!==C||t[38]!==b||t[39]!==v?(R=v?(0,I.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,I.jsx)(D,{src:W(n),assetPath:n,fileName:b,extension:C},n)}):(0,I.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-4 sm:px-6`,children:(0,I.jsx)(`div`,{className:`mx-auto w-full max-w-3xl`,children:(0,I.jsx)(fe,{file:n})})}),t[36]=n,t[37]=C,t[38]=b,t[39]=v,t[40]=R):R=t[40];let z;return t[41]!==L||t[42]!==R||t[43]!==w?(z=(0,I.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background`,"data-schema-config-editor":``,children:[w,L,R]}),t[41]=L,t[42]=R,t[43]=w,t[44]=z):z=t[44],z}export{G as SchemaConfigEditor};