@inkeep/open-knowledge 0.40.0-beta.0 → 0.40.0-beta.1

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 (139) hide show
  1. package/dist/{acp-harness-probe-Bhi4Llqu.mjs → acp-harness-probe-CI5eMrtp.mjs} +2 -2
  2. package/dist/assets/skills/discovery/SKILL.md +1 -1
  3. package/dist/assets/skills/project/SKILL.md +1 -1
  4. package/dist/assets/skills/write-skill/SKILL.md +1 -1
  5. package/dist/cli.mjs +37 -37
  6. package/dist/config-schema.json +50 -3
  7. package/dist/config.project-local.schema.json +50 -3
  8. package/dist/config.project.schema.json +38 -3
  9. package/dist/config.user.schema.json +38 -3
  10. package/dist/constants-CkXW_O1Z.mjs +2 -0
  11. package/dist/fs-traced-CIBSRy3q.mjs +1 -0
  12. package/dist/{fs-traced-CyCraqZx.mjs → fs-traced-PoaSX4-V.mjs} +2 -2
  13. package/dist/{git-handle-BvHrr8BH.mjs → git-handle-DQgl5oTH.mjs} +2 -2
  14. package/dist/git-handle-Dv50ya_5.mjs +1 -0
  15. package/dist/index.d.mts +34 -18
  16. package/dist/index.mjs +1 -1
  17. package/dist/init-BG8F8jyV.mjs +1 -0
  18. package/dist/{init-ExES21Y6.mjs → init-DqAj6DLP.mjs} +3 -3
  19. package/dist/{launch-json-removal-DPv1JCcm.mjs → launch-json-removal-DMBq4-k5.mjs} +2 -2
  20. package/dist/loader-48vYo7np.mjs +1 -0
  21. package/dist/{loader-ieLA3dNB.mjs → loader-CuzKavqN.mjs} +2 -2
  22. package/dist/md-manager-BFa4uLFA.mjs +2 -0
  23. package/dist/{open-browser-DuW0JuiI.mjs → open-browser-D3OpxES8.mjs} +2 -2
  24. package/dist/parse-worker.mjs +1 -1
  25. package/dist/{preview-BomWJpxb.mjs → preview-DNAkJMSB.mjs} +2 -2
  26. package/dist/preview-hDB5CK12.mjs +1 -0
  27. package/dist/public/assets/{ActivityModeContent-CXKjTMzk.js → ActivityModeContent-dWIhYEu6.js} +1 -1
  28. package/dist/public/assets/{AgentDiffPane-sDXcTCmp.js → AgentDiffPane-ZSMGc24S.js} +1 -1
  29. package/dist/public/assets/{AgentThreadClientBinder-CpSn5y_B.js → AgentThreadClientBinder-CLmx-vqX.js} +1 -1
  30. package/dist/public/assets/{AppMenubar-hPGBtMtR.js → AppMenubar-BuB4TAd6.js} +1 -1
  31. package/dist/public/assets/{CodeMirrorPropInput-BbkcIhWZ.js → CodeMirrorPropInput-C9WmN90w.js} +1 -1
  32. package/dist/public/assets/{ConsentDialogBody-D9xWEY09.js → ConsentDialogBody-BBzNYhHt.js} +1 -1
  33. package/dist/public/assets/{CopyButton-Cbumgow3.js → CopyButton-Ja2824Ao.js} +1 -1
  34. package/dist/public/assets/DocumentContext-BcbJIejF.js +38 -0
  35. package/dist/public/assets/EnableSyncConfirmDialog-DPaSz-wC.js +1 -0
  36. package/dist/public/assets/FeedbackForm-BeMx2Cc0.js +1 -0
  37. package/dist/public/assets/{GraphPanel-YytKkcWc.js → GraphPanel-BpzaeAQp.js} +1 -1
  38. package/dist/public/assets/{ManagedArtifactProperties-CUEp_TTL.js → ManagedArtifactProperties-CQXgVT_Z.js} +1 -1
  39. package/dist/public/assets/{McpConsentDialogBody-55HPQg6h.js → McpConsentDialogBody-DHTkre7u.js} +1 -1
  40. package/dist/public/assets/{MermaidDocEditor-DSOgLfw2.js → MermaidDocEditor-DL9NPMko.js} +1 -1
  41. package/dist/public/assets/{PropertyPanel-BCaH4sHq.js → PropertyPanel-DEgQa4x9.js} +2 -2
  42. package/dist/public/assets/{ReportBugDialogBody-CclyuUz8.js → ReportBugDialogBody-DrIG1ML_.js} +1 -1
  43. package/dist/public/assets/SettingsDialogBody-BZ10IzbM.js +7 -0
  44. package/dist/public/assets/{ShareBranchSwitchDialog-COlZI5OE.js → ShareBranchSwitchDialog-C179lw0C.js} +1 -1
  45. package/dist/public/assets/{ShareReceiveDialog-B6PbEmCF.js → ShareReceiveDialog-TtY0UQrE.js} +1 -1
  46. package/dist/public/assets/{ShareReceiveMissDialog-By8esj_5.js → ShareReceiveMissDialog-op0Pk4ih.js} +1 -1
  47. package/dist/public/assets/{SkillEditorActions-BgwpFpi1.js → SkillEditorActions-DVAUJ782.js} +1 -1
  48. package/dist/public/assets/{SourceEditor-DxRPfKvz.js → SourceEditor-Nfwr4rkI.js} +1 -1
  49. package/dist/public/assets/{TerminalPanel-D-hojFQG.js → TerminalPanel-DqAeIpPV.js} +1 -1
  50. package/dist/public/assets/{TerminalSessionsHost-41AB3mFJ.js → TerminalSessionsHost-CMZ3pfB8.js} +2 -2
  51. package/dist/public/assets/{TerminalWindowApp-CZ7Efhd5.js → TerminalWindowApp-C0nQcTDF.js} +1 -1
  52. package/dist/public/assets/{ThreadView-Dk1Lkb4i.js → ThreadView-Dd8w-hhw.js} +1 -1
  53. package/dist/public/assets/{TimelineDiffPane-BdeqO5w9.js → TimelineDiffPane-DKx6CcI9.js} +1 -1
  54. package/dist/public/assets/{agent-diff-store-DZZjM0GE.js → agent-diff-store-_LaXNJgH.js} +1 -1
  55. package/dist/public/assets/{agent-visibility-DPFbzl9a.js → agent-visibility-CaL4MDEH.js} +1 -1
  56. package/dist/public/assets/auth-state-cache-9Mxvjb5G.js +11 -0
  57. package/dist/public/assets/{calendar-p-DzPplr.js → calendar-HuZ4s1vW.js} +1 -1
  58. package/dist/public/assets/{checkbox-Cn88M3G6.js → checkbox-DAZcO8UL.js} +1 -1
  59. package/dist/public/assets/client-version-yw5_4u_I.js +1 -0
  60. package/dist/public/assets/{config-provider-U3uVQf2B.js → config-provider-BgOkEHZH.js} +1 -1
  61. package/dist/public/assets/{dist-BXtMv5Fj.js → dist-Bjs7qRWH.js} +1 -1
  62. package/dist/public/assets/{dist-DGxOU4wq.js → dist-CHLZ8lz0.js} +144 -144
  63. package/dist/public/assets/{doc-hash-C29Il1da.js → doc-hash-Bgdowslw.js} +1 -1
  64. package/dist/public/assets/{documents-events-C3fByfiC.js → documents-events-HEfBwy2y.js} +1 -1
  65. package/dist/public/assets/{dropdown-menu-CcKe8PiU.js → dropdown-menu-DVTufjNA.js} +1 -1
  66. package/dist/public/assets/{file-tree-adapter-azEoLHfQ.js → file-tree-adapter-Bvk6LAfH.js} +1 -1
  67. package/dist/public/assets/{index-CTYMeNHV.js → index-DsA_F7eu.js} +103 -103
  68. package/dist/public/assets/index-G6x9YQiR.css +1 -0
  69. package/dist/public/assets/{keyboard-shortcuts-OXotyOGw.js → keyboard-shortcuts-DEJA0SzW.js} +1 -1
  70. package/dist/public/assets/{lint-config-client-DvKzk8M8.js → lint-config-client-DJccpgCS.js} +1 -1
  71. package/dist/public/assets/{navigation-targets-iYhj2VsX.js → navigation-targets-CPuDxLos.js} +1 -1
  72. package/dist/public/assets/{open-managed-artifact-tab-Z57LM2Z4.js → open-managed-artifact-tab-D70MXBHT.js} +1 -1
  73. package/dist/public/assets/pending-receive-nav-store-CMbR1DlR.js +1 -0
  74. package/dist/public/assets/{prop-types-Cl0YMuHg.js → prop-types-X3nIYAt7.js} +1 -1
  75. package/dist/public/assets/{receive-store-COHKqsBX.js → receive-store-CXRtunGe.js} +1 -1
  76. package/dist/public/assets/{selection-context-eU_Qktbs.js → selection-context-BiPXU2rp.js} +1 -1
  77. package/dist/public/assets/{skill-actions-CCrGq1Wm.js → skill-actions-8sFn_d3u.js} +1 -1
  78. package/dist/public/assets/{skills-api-CwVreKtE.js → skills-api-C_fjXVRf.js} +1 -1
  79. package/dist/public/assets/{src-BlFvgbgm.js → src-Bv1hrVBW.js} +1 -1
  80. package/dist/public/assets/{target-navigation-intent-D6vBZdSf.js → target-navigation-intent-DW8AJzuM.js} +1 -1
  81. package/dist/public/assets/{telemetry-impl-Cc4_2Kuv.js → telemetry-impl-5fGxwbNg.js} +1 -1
  82. package/dist/public/assets/{telemetry-startup-CusPaTq7.js → telemetry-startup-CLLgwJqA.js} +1 -1
  83. package/dist/public/assets/{terminal-launch-events-6XYN8k0p.js → terminal-launch-events-CuvBwfob.js} +1 -1
  84. package/dist/public/assets/{terminal-telemetry-q3LpCe-1.js → terminal-telemetry-qJ0O-9wu.js} +1 -1
  85. package/dist/public/assets/{typing-burst-detector-QvmBKNOB.js → typing-burst-detector-CY0OrGne.js} +1 -1
  86. package/dist/public/assets/{use-activity-panel-DvA9ZLA6.js → use-activity-panel-DEqogtJb.js} +1 -1
  87. package/dist/public/assets/{use-apply-config-color-theme-BImxeKNx.js → use-apply-config-color-theme-CbAc42DQ.js} +2 -2
  88. package/dist/public/assets/{use-collab-url-CTOu_iWG.js → use-collab-url-CDJf5CAl.js} +1 -1
  89. package/dist/public/assets/{use-live-xterm-theme-dAhd07IY.js → use-live-xterm-theme-DsNSOoA7.js} +1 -1
  90. package/dist/public/assets/{use-terminal-enabled-Bmmmi7AO.js → use-terminal-enabled-CjyUXLzD.js} +1 -1
  91. package/dist/public/assets/{use-timeline-entry-diff-D6MUvrZG.js → use-timeline-entry-diff-CaKIZSP2.js} +1 -1
  92. package/dist/public/assets/{use-workspace-BtamMVXo.js → use-workspace-CHGWiUmE.js} +1 -1
  93. package/dist/public/assets/{workspace-paths--K9QhxwT.js → workspace-paths-DgJUp1dw.js} +1 -1
  94. package/dist/public/index.html +48 -48
  95. package/dist/{repair-launch-json-DdRk9h7e.mjs → repair-launch-json-tt6Tjedd.mjs} +2 -2
  96. package/dist/{repair-mcp-configs-Bwoyzwk6.mjs → repair-mcp-configs-Bn1d1oSd.mjs} +2 -2
  97. package/dist/{repair-skills-DRI7dgZc.mjs → repair-skills-BVXDXZaA.mjs} +2 -2
  98. package/dist/repair-skills-D7MJ6bSo.mjs +1 -0
  99. package/dist/schemas/v0/config.project-local.schema.json +50 -3
  100. package/dist/schemas/v0/config.project.schema.json +38 -3
  101. package/dist/schemas/v0/config.user.schema.json +38 -3
  102. package/dist/server-lock-Bhmg0tcS.mjs +1 -0
  103. package/dist/{server-lock-BaFI-pb-.mjs → server-lock-DWsOY8Sf.mjs} +2 -2
  104. package/dist/{sleep-D9-JSiMz.mjs → sleep-CnRgOMGV.mjs} +24 -24
  105. package/dist/{src-DSErWJqy.mjs → src-DQTDRmqk.mjs} +1 -1
  106. package/dist/src-DVrFd0vk.mjs +3272 -0
  107. package/dist/{src-MWQj7voD.mjs → src-IQdx1yfl.mjs} +63 -58
  108. package/dist/{src-Cp0c_AY8.mjs → src-VT3q7v5V.mjs} +2 -2
  109. package/dist/start-3HnyNbf6.mjs +1 -0
  110. package/dist/{start-BgYmpGSW.mjs → start-BQRik_0l.mjs} +2 -2
  111. package/dist/{write-project-skill-DeeYFQNz.mjs → write-project-skill-SrjlunKm.mjs} +4 -4
  112. package/package.json +5 -5
  113. package/dist/constants-C5569GdH.mjs +0 -2
  114. package/dist/fs-traced-BfHcMmET.mjs +0 -1
  115. package/dist/git-handle-Do3oiyRv.mjs +0 -1
  116. package/dist/init-ByFsxFwA.mjs +0 -1
  117. package/dist/loader-DR445aRM.mjs +0 -1
  118. package/dist/md-manager-DU8cDKTu.mjs +0 -2
  119. package/dist/preview-CzenDf6w.mjs +0 -1
  120. package/dist/public/assets/DocumentContext-D8AcgFCE.js +0 -38
  121. package/dist/public/assets/EnableSyncConfirmDialog-BS38VGMB.js +0 -1
  122. package/dist/public/assets/FeedbackForm-BaEEePNZ.js +0 -1
  123. package/dist/public/assets/SettingsDialogBody-D0NhLCiz.js +0 -7
  124. package/dist/public/assets/auth-state-cache-w1vT3ODb.js +0 -11
  125. package/dist/public/assets/client-version-CF0d0O9l.js +0 -1
  126. package/dist/public/assets/index-BxtMW1aW.css +0 -1
  127. package/dist/public/assets/pending-receive-nav-store-DG2tvh9-.js +0 -1
  128. package/dist/repair-skills-Cdc-D-_T.mjs +0 -1
  129. package/dist/server-lock-BWzPKU9E.mjs +0 -1
  130. package/dist/src-DUna3ewt.mjs +0 -3272
  131. package/dist/start-CkPrN2AC.mjs +0 -1
  132. /package/dist/public/assets/{RegisteredAgentIcon--E1135hW.js → RegisteredAgentIcon-B57vI5w6.js} +0 -0
  133. /package/dist/public/assets/{arrow-up-right-BKliW282.js → arrow-up-right-Bzc4GmE5.js} +0 -0
  134. /package/dist/public/assets/{check-D3jznJmG.js → check-D_9hlB38.js} +0 -0
  135. /package/dist/public/assets/{chevron-down-0vl-mPeL.js → chevron-down-CQd32BUC.js} +0 -0
  136. /package/dist/public/assets/{chevron-left-fiDaD9J4.js → chevron-left-4ixwi2VD.js} +0 -0
  137. /package/dist/public/assets/{chevron-right-zaL9JagC.js → chevron-right-cXK7rcek.js} +0 -0
  138. /package/dist/public/assets/{copy-DmfcimOx.js → copy-Dwat-rG5.js} +0 -0
  139. /package/dist/public/assets/{eye-CmnH89UE.js → eye-DuFNDQPj.js} +0 -0
@@ -150,11 +150,33 @@
150
150
  },
151
151
  "autoSync": {
152
152
  "default": {
153
+ "mode": null,
153
154
  "enabled": null,
154
155
  "default": null
155
156
  },
156
157
  "type": "object",
157
158
  "properties": {
159
+ "mode": {
160
+ "default": null,
161
+ "anyOf": [
162
+ {
163
+ "type": "string",
164
+ "enum": [
165
+ "off",
166
+ "follow",
167
+ "full",
168
+ "pull"
169
+ ],
170
+ "scope": "project-local",
171
+ "agentSettable": false,
172
+ "defaultScope": "project-local",
173
+ "description": "How this machine syncs this project with its git remote: 'off' (no sync), 'follow' (one-directional — pull remote changes, never push your own; 'pull' is accepted as a legacy alias), or 'full' (bidirectional pull and push). null = not chosen yet (onboarding asks). Per-machine (project-local) — not shared. Supersedes the legacy autoSync.enabled boolean."
174
+ },
175
+ {
176
+ "type": "null"
177
+ }
178
+ ]
179
+ },
158
180
  "enabled": {
159
181
  "default": null,
160
182
  "anyOf": [
@@ -163,7 +185,7 @@
163
185
  "scope": "project-local",
164
186
  "agentSettable": false,
165
187
  "defaultScope": "project-local",
166
- "description": "Whether this machine auto-pulls and auto-pushes git commits for this project. null = not chosen yet (onboarding asks). Per-machine (project-local) — not shared."
188
+ "description": "Legacy per-machine sync toggle, superseded by autoSync.mode. Read only when mode is absent (true = full, false = off). null = not chosen yet. Per-machine (project-local) — not shared."
167
189
  },
168
190
  {
169
191
  "type": "null"
@@ -174,11 +196,24 @@
174
196
  "default": null,
175
197
  "anyOf": [
176
198
  {
177
- "type": "boolean",
199
+ "anyOf": [
200
+ {
201
+ "type": "boolean"
202
+ },
203
+ {
204
+ "type": "string",
205
+ "enum": [
206
+ "off",
207
+ "follow",
208
+ "full",
209
+ "pull"
210
+ ]
211
+ }
212
+ ],
178
213
  "scope": "project",
179
214
  "agentSettable": false,
180
215
  "defaultScope": "project",
181
- "description": "Committed project default for a machine's autoSync.enabled on first open: true = auto-sync on, false = off, null = ask (show the onboarding prompt). Shared via git. A per-machine autoSync.enabled choice overrides it."
216
+ "description": "Committed project default for a machine's sync mode on first open: 'off' | 'follow' | 'full', or the legacy boolean (true = full, false = off). null = ask (show the onboarding prompt). Shared via git. A per-machine autoSync.mode choice overrides it."
182
217
  },
183
218
  {
184
219
  "type": "null"
@@ -0,0 +1 @@
1
+ import{a as e,o as t,r as n}from"./server-lock-DWsOY8Sf.mjs";export{n as markServerLockDraining,e as releaseServerLock,t as updateServerLockPort};
@@ -1,2 +1,2 @@
1
- import"./src-MWQj7voD.mjs";import{r as e}from"./logger-B7Z8XO-z.mjs";import{dirname as t,join as n,resolve as r}from"node:path";import{closeSync as i,existsSync as a,mkdirSync as o,openSync as s,readFileSync as c,unlinkSync as l,writeFileSync as u,writeSync as d}from"node:fs";import{homedir as f,hostname as p}from"node:os";import{fileURLToPath as m}from"node:url";import{randomUUID as h}from"node:crypto";function g(e){return new URL(e.url??``,`http://localhost`).searchParams}function _(e){let t=e?.code;return typeof t==`string`?t:void 0}const v=/^[A-Za-z0-9-]{8,64}$/;let y=null;function b(e){return n(e??f(),`.ok`,`machine-id`)}function x(n){if(n===void 0&&y!==null)return y;let r=b(n),i=null;try{let e=c(r,`utf-8`).trim();v.test(e)&&(i=e)}catch{}if(i===null){i=h();try{o(t(r),{recursive:!0}),u(r,`${i}\n`,{encoding:`utf-8`,mode:384})}catch(t){e(`machine-id`).warn({path:r,err:t},`Failed to persist ${r} — using an ephemeral per-process id; lock ownership checks will fail closed (collision) instead of recognizing this machine: ${t instanceof Error?t.message:String(t)}`)}}return n===void 0&&(y=i),i}function S(e){try{return process.kill(e,0),!0}catch(e){return!!(e&&typeof e==`object`&&`code`in e&&e.code===`EPERM`)}}function C(e){return!(typeof e!=`number`||!Number.isInteger(e)||e<2||e>2147483647)}function w(){try{let e=r(t(m(import.meta.url)),`..`,`package.json`),n=JSON.parse(c(e,`utf-8`));if(typeof n.version==`string`&&n.version.length>0)return n.version}catch{}return`0.0.0-unknown`}const T=w(),E=1,D=e(`process-lock`);var O=class extends Error{existing;lockPath;lockName;constructor(e,t,n){super(`OpenKnowledge ${n} already running on port ${e.port} (pid ${e.pid}, started ${e.startedAt}). Stop it first or use a different directory. Lock: ${t}`),this.name=`ProcessLockCollisionError`,this.existing=e,this.lockPath=t,this.lockName=n}};function k(e,t){return r(e,`${t}.lock`)}const A=new Map;function j(e){A.set(e,(A.get(e)??0)+1)}function M(e){let t=A.get(e);return t===void 0||t<=1?(A.delete(e),!0):(A.set(e,t-1),!1)}function N(e){return typeof e.machineId==`string`?e.machineId===x():e.hostname===p()}const P=new Set;let F=!1;function I(e){P.add(e),!F&&(F=!0,process.on(`exit`,()=>{for(let e of P)try{let t=JSON.parse(c(e,`utf-8`));if(t?.pid!==process.pid||typeof t.machineId==`string`&&t.machineId!==x()||t.machineId===void 0&&typeof t.hostname==`string`&&t.hostname!==p())continue;l(e)}catch{}}))}function L(e,t){try{let n=JSON.parse(c(e,`utf-8`));return n&&typeof n==`object`&&C(n.pid)?n:(D.warn({lockPath:e},`${t} Corrupt lock file at ${e} — replacing`),null)}catch{return D.warn({lockPath:e},`${t} Corrupt lock file at ${e} — replacing`),null}}function R(e){let{lockName:t,lockDir:n,metadata:r}=e,c=`[${t}-lock]`;o(n,{recursive:!0});let f=k(n,t),m={pid:process.pid,hostname:p(),port:r.port,startedAt:new Date().toISOString(),worktreeRoot:r.worktreeRoot,machineId:x(),...r.kind!==void 0&&{kind:r.kind},...r.parentPid!==void 0&&{parentPid:r.parentPid},...r.capabilities!==void 0&&{capabilities:r.capabilities},protocolVersion:r.protocolVersion??1,runtimeVersion:r.runtimeVersion??T},h=JSON.stringify(m,null,2);for(let e=0;e<3;e++){if(!a(f))try{let e=s(f,`wx`,384);try{d(e,h)}finally{i(e)}return j(f),I(f),z({lockName:t,lockDir:n,lockPath:f})}catch(e){if(_(e)!==`EEXIST`)throw e}let e=L(f,c);if(e){if(N(e)&&e.pid===process.pid)return u(f,h,{encoding:`utf-8`,mode:384}),j(f),I(f),z({lockName:t,lockDir:n,lockPath:f});if(S(e.pid))throw new O(e,f,t);D.warn({pid:e.pid,host:e.hostname},`${c} Stale lock detected (pid=${e.pid}, host=${e.hostname}) — replacing`)}try{l(f)}catch{}}throw Error(`${c} Failed to acquire ${f} after 3 attempts (concurrent acquire contention).`)}function z(e){let{lockName:t,lockDir:n,lockPath:r}=e;return{lockPath:r,release:()=>G({lockName:t,lockDir:n}),updatePort:e=>B({lockName:t,lockDir:n,port:e})}}function B(e){let{lockName:t,lockDir:n,port:r}=e,i=`[${t}-lock]`,o=k(n,t);if(!a(o)){D.warn({lockPath:o},`${i} Lock file missing at ${o} during port update — skipping`);return}let s;try{let e=JSON.parse(c(o,`utf-8`));if(!e||typeof e!=`object`||!C(e.pid)){D.warn({lockPath:o},`${i} Corrupt lock at ${o} during port update — skipping`);return}s=e}catch{D.warn({lockPath:o},`${i} Unreadable lock at ${o} during port update — skipping`);return}if(s.pid===process.pid&&N(s)){s.port=r;try{u(o,JSON.stringify(s,null,2),{encoding:`utf-8`,mode:384})}catch(e){D.warn({lockPath:o,err:e},`${i} Failed to update port in ${o}: ${e instanceof Error?e.message:String(e)}`)}}}function V(e){let{lockName:t,lockDir:n}=e,r=`[${t}-lock]`,i=k(n,t);if((A.get(i)??0)>1)return;let a;try{let e=JSON.parse(c(i,`utf-8`));if(!e||typeof e!=`object`||!C(e.pid)){D.warn({lockPath:i},`${r} Corrupt lock at ${i} during draining mark — skipping`);return}a=e}catch(e){_(e)!==`ENOENT`&&D.warn({lockPath:i,err:e},`${r} Unreadable lock at ${i} during draining mark — skipping: ${e instanceof Error?e.message:String(e)}`);return}if(a.pid===process.pid&&N(a)&&a.draining!==!0){a.draining=!0;try{u(i,JSON.stringify(a,null,2),{encoding:`utf-8`,mode:384})}catch(e){D.warn({lockPath:i,err:e},`${r} Failed to mark ${i} draining: ${e instanceof Error?e.message:String(e)}`)}}}function H(e){let{lockName:t,lockDir:n}=e,r=k(n,t);if(!a(r))return null;let i;try{let e=JSON.parse(c(r,`utf-8`));if(!e||typeof e!=`object`||!C(e.pid))return null;i=e}catch{return null}if(!N(i))return null;if(!S(i.pid)){try{l(r)}catch{}return null}return i}function U(e){let{lockName:t,lockDir:n}=e,r=k(n,t);if(!a(r))return{status:`absent`};let i;try{i=JSON.parse(c(r,`utf-8`))}catch{return{status:`incompatible`,reason:`corrupt`,raw:void 0}}if(!i||typeof i!=`object`)return{status:`incompatible`,reason:`corrupt`,raw:i};let o=i;if(!C(o.pid)||typeof o.hostname!=`string`||typeof o.port!=`number`||typeof o.startedAt!=`string`||typeof o.worktreeRoot!=`string`)return{status:`incompatible`,reason:`corrupt`,raw:i};let s={pid:o.pid,hostname:o.hostname,port:o.port,startedAt:o.startedAt,worktreeRoot:o.worktreeRoot,machineId:typeof o.machineId==`string`?o.machineId:void 0,draining:o.draining===!0?!0:void 0,protocolVersion:typeof o.protocolVersion==`number`?o.protocolVersion:void 0,runtimeVersion:typeof o.runtimeVersion==`string`?o.runtimeVersion:void 0};if(!N(s))return{status:`stale`,lock:s};if(!S(s.pid)){try{l(r)}catch{}return{status:`stale`,lock:s}}return s.protocolVersion===void 0||s.runtimeVersion===void 0?{status:`incompatible`,reason:`missing-fields`,raw:i}:{status:`live`,lock:s}}async function W(e){let{lockName:t,lockDir:n}=e,r=e.timeoutMs??1e4,i=e.pollIntervalMs??100,a=e.readLock??(()=>H({lockName:t,lockDir:n})),o=e.sleep??(e=>new Promise(t=>setTimeout(t,e))),s=a();if(s===null||s.draining!==!0)return`no-drain`;let c=Date.now()+r;for(;Date.now()<c;){await o(i);let e=a();if(e===null)return`released`;if(e.draining!==!0)return`no-drain`}return`timeout`}function G(e){let{lockName:t,lockDir:n,deferUnlinkToExit:r=!1}=e,i=`[${t}-lock]`,o=k(n,t);if(M(o)){if(r){V({lockName:t,lockDir:n});return}if(a(o))try{let e=JSON.parse(c(o,`utf-8`));if(!e||typeof e!=`object`||typeof e.pid!=`number`||e.pid!==process.pid||!N(e))return;l(o),P.delete(o)}catch(e){D.warn({lockPath:o,err:e},`${i} Failed to release ${o}: ${e instanceof Error?e.message:String(e)}`)}}}var K=class extends O{constructor(e,t){super(e,t,`server`),this.name=`ServerLockCollisionError`}};function q(e,t){try{return R({lockName:`server`,lockDir:e,metadata:t}).lockPath}catch(e){throw e instanceof O&&e.lockName===`server`?new K(e.existing,e.lockPath):e}}function J(e,t){B({lockName:`server`,lockDir:e,port:t})}function Y(e){return H({lockName:`server`,lockDir:e})}function X(e,t){G({lockName:`server`,lockDir:e,...t})}function Z(e){V({lockName:`server`,lockDir:e})}function Q(e,t){return W({lockName:`server`,lockDir:e,...t})}export{g as S,E as _,X as a,x as b,O as c,V as d,H as f,T as g,B as h,Y as i,R as l,G as m,q as n,J as o,U as p,Z as r,Q as s,K as t,k as u,S as v,_ as x,C as y};
2
- //# sourceMappingURL=server-lock-BaFI-pb-.mjs.map
1
+ import"./src-IQdx1yfl.mjs";import{r as e}from"./logger-B7Z8XO-z.mjs";import{dirname as t,join as n,resolve as r}from"node:path";import{closeSync as i,existsSync as a,mkdirSync as o,openSync as s,readFileSync as c,unlinkSync as l,writeFileSync as u,writeSync as d}from"node:fs";import{homedir as f,hostname as p}from"node:os";import{fileURLToPath as m}from"node:url";import{randomUUID as h}from"node:crypto";function g(e){return new URL(e.url??``,`http://localhost`).searchParams}function _(e){let t=e?.code;return typeof t==`string`?t:void 0}const v=/^[A-Za-z0-9-]{8,64}$/;let y=null;function b(e){return n(e??f(),`.ok`,`machine-id`)}function x(n){if(n===void 0&&y!==null)return y;let r=b(n),i=null;try{let e=c(r,`utf-8`).trim();v.test(e)&&(i=e)}catch{}if(i===null){i=h();try{o(t(r),{recursive:!0}),u(r,`${i}\n`,{encoding:`utf-8`,mode:384})}catch(t){e(`machine-id`).warn({path:r,err:t},`Failed to persist ${r} — using an ephemeral per-process id; lock ownership checks will fail closed (collision) instead of recognizing this machine: ${t instanceof Error?t.message:String(t)}`)}}return n===void 0&&(y=i),i}function S(e){try{return process.kill(e,0),!0}catch(e){return!!(e&&typeof e==`object`&&`code`in e&&e.code===`EPERM`)}}function C(e){return!(typeof e!=`number`||!Number.isInteger(e)||e<2||e>2147483647)}function w(){try{let e=r(t(m(import.meta.url)),`..`,`package.json`),n=JSON.parse(c(e,`utf-8`));if(typeof n.version==`string`&&n.version.length>0)return n.version}catch{}return`0.0.0-unknown`}const T=w(),E=1,D=e(`process-lock`);var O=class extends Error{existing;lockPath;lockName;constructor(e,t,n){super(`OpenKnowledge ${n} already running on port ${e.port} (pid ${e.pid}, started ${e.startedAt}). Stop it first or use a different directory. Lock: ${t}`),this.name=`ProcessLockCollisionError`,this.existing=e,this.lockPath=t,this.lockName=n}};function k(e,t){return r(e,`${t}.lock`)}const A=new Map;function j(e){A.set(e,(A.get(e)??0)+1)}function M(e){let t=A.get(e);return t===void 0||t<=1?(A.delete(e),!0):(A.set(e,t-1),!1)}function N(e){return typeof e.machineId==`string`?e.machineId===x():e.hostname===p()}const P=new Set;let F=!1;function I(e){P.add(e),!F&&(F=!0,process.on(`exit`,()=>{for(let e of P)try{let t=JSON.parse(c(e,`utf-8`));if(t?.pid!==process.pid||typeof t.machineId==`string`&&t.machineId!==x()||t.machineId===void 0&&typeof t.hostname==`string`&&t.hostname!==p())continue;l(e)}catch{}}))}function L(e,t){try{let n=JSON.parse(c(e,`utf-8`));return n&&typeof n==`object`&&C(n.pid)?n:(D.warn({lockPath:e},`${t} Corrupt lock file at ${e} — replacing`),null)}catch{return D.warn({lockPath:e},`${t} Corrupt lock file at ${e} — replacing`),null}}function R(e){let{lockName:t,lockDir:n,metadata:r}=e,c=`[${t}-lock]`;o(n,{recursive:!0});let f=k(n,t),m={pid:process.pid,hostname:p(),port:r.port,startedAt:new Date().toISOString(),worktreeRoot:r.worktreeRoot,machineId:x(),...r.kind!==void 0&&{kind:r.kind},...r.parentPid!==void 0&&{parentPid:r.parentPid},...r.capabilities!==void 0&&{capabilities:r.capabilities},protocolVersion:r.protocolVersion??1,runtimeVersion:r.runtimeVersion??T},h=JSON.stringify(m,null,2);for(let e=0;e<3;e++){if(!a(f))try{let e=s(f,`wx`,384);try{d(e,h)}finally{i(e)}return j(f),I(f),z({lockName:t,lockDir:n,lockPath:f})}catch(e){if(_(e)!==`EEXIST`)throw e}let e=L(f,c);if(e){if(N(e)&&e.pid===process.pid)return u(f,h,{encoding:`utf-8`,mode:384}),j(f),I(f),z({lockName:t,lockDir:n,lockPath:f});if(S(e.pid))throw new O(e,f,t);D.warn({pid:e.pid,host:e.hostname},`${c} Stale lock detected (pid=${e.pid}, host=${e.hostname}) — replacing`)}try{l(f)}catch{}}throw Error(`${c} Failed to acquire ${f} after 3 attempts (concurrent acquire contention).`)}function z(e){let{lockName:t,lockDir:n,lockPath:r}=e;return{lockPath:r,release:()=>G({lockName:t,lockDir:n}),updatePort:e=>B({lockName:t,lockDir:n,port:e})}}function B(e){let{lockName:t,lockDir:n,port:r}=e,i=`[${t}-lock]`,o=k(n,t);if(!a(o)){D.warn({lockPath:o},`${i} Lock file missing at ${o} during port update — skipping`);return}let s;try{let e=JSON.parse(c(o,`utf-8`));if(!e||typeof e!=`object`||!C(e.pid)){D.warn({lockPath:o},`${i} Corrupt lock at ${o} during port update — skipping`);return}s=e}catch{D.warn({lockPath:o},`${i} Unreadable lock at ${o} during port update — skipping`);return}if(s.pid===process.pid&&N(s)){s.port=r;try{u(o,JSON.stringify(s,null,2),{encoding:`utf-8`,mode:384})}catch(e){D.warn({lockPath:o,err:e},`${i} Failed to update port in ${o}: ${e instanceof Error?e.message:String(e)}`)}}}function V(e){let{lockName:t,lockDir:n}=e,r=`[${t}-lock]`,i=k(n,t);if((A.get(i)??0)>1)return;let a;try{let e=JSON.parse(c(i,`utf-8`));if(!e||typeof e!=`object`||!C(e.pid)){D.warn({lockPath:i},`${r} Corrupt lock at ${i} during draining mark — skipping`);return}a=e}catch(e){_(e)!==`ENOENT`&&D.warn({lockPath:i,err:e},`${r} Unreadable lock at ${i} during draining mark — skipping: ${e instanceof Error?e.message:String(e)}`);return}if(a.pid===process.pid&&N(a)&&a.draining!==!0){a.draining=!0;try{u(i,JSON.stringify(a,null,2),{encoding:`utf-8`,mode:384})}catch(e){D.warn({lockPath:i,err:e},`${r} Failed to mark ${i} draining: ${e instanceof Error?e.message:String(e)}`)}}}function H(e){let{lockName:t,lockDir:n}=e,r=k(n,t);if(!a(r))return null;let i;try{let e=JSON.parse(c(r,`utf-8`));if(!e||typeof e!=`object`||!C(e.pid))return null;i=e}catch{return null}if(!N(i))return null;if(!S(i.pid)){try{l(r)}catch{}return null}return i}function U(e){let{lockName:t,lockDir:n}=e,r=k(n,t);if(!a(r))return{status:`absent`};let i;try{i=JSON.parse(c(r,`utf-8`))}catch{return{status:`incompatible`,reason:`corrupt`,raw:void 0}}if(!i||typeof i!=`object`)return{status:`incompatible`,reason:`corrupt`,raw:i};let o=i;if(!C(o.pid)||typeof o.hostname!=`string`||typeof o.port!=`number`||typeof o.startedAt!=`string`||typeof o.worktreeRoot!=`string`)return{status:`incompatible`,reason:`corrupt`,raw:i};let s={pid:o.pid,hostname:o.hostname,port:o.port,startedAt:o.startedAt,worktreeRoot:o.worktreeRoot,machineId:typeof o.machineId==`string`?o.machineId:void 0,draining:o.draining===!0?!0:void 0,protocolVersion:typeof o.protocolVersion==`number`?o.protocolVersion:void 0,runtimeVersion:typeof o.runtimeVersion==`string`?o.runtimeVersion:void 0};if(!N(s))return{status:`stale`,lock:s};if(!S(s.pid)){try{l(r)}catch{}return{status:`stale`,lock:s}}return s.protocolVersion===void 0||s.runtimeVersion===void 0?{status:`incompatible`,reason:`missing-fields`,raw:i}:{status:`live`,lock:s}}async function W(e){let{lockName:t,lockDir:n}=e,r=e.timeoutMs??1e4,i=e.pollIntervalMs??100,a=e.readLock??(()=>H({lockName:t,lockDir:n})),o=e.sleep??(e=>new Promise(t=>setTimeout(t,e))),s=a();if(s===null||s.draining!==!0)return`no-drain`;let c=Date.now()+r;for(;Date.now()<c;){await o(i);let e=a();if(e===null)return`released`;if(e.draining!==!0)return`no-drain`}return`timeout`}function G(e){let{lockName:t,lockDir:n,deferUnlinkToExit:r=!1}=e,i=`[${t}-lock]`,o=k(n,t);if(M(o)){if(r){V({lockName:t,lockDir:n});return}if(a(o))try{let e=JSON.parse(c(o,`utf-8`));if(!e||typeof e!=`object`||typeof e.pid!=`number`||e.pid!==process.pid||!N(e))return;l(o),P.delete(o)}catch(e){D.warn({lockPath:o,err:e},`${i} Failed to release ${o}: ${e instanceof Error?e.message:String(e)}`)}}}var K=class extends O{constructor(e,t){super(e,t,`server`),this.name=`ServerLockCollisionError`}};function q(e,t){try{return R({lockName:`server`,lockDir:e,metadata:t}).lockPath}catch(e){throw e instanceof O&&e.lockName===`server`?new K(e.existing,e.lockPath):e}}function J(e,t){B({lockName:`server`,lockDir:e,port:t})}function Y(e){return H({lockName:`server`,lockDir:e})}function X(e,t){G({lockName:`server`,lockDir:e,...t})}function Z(e){V({lockName:`server`,lockDir:e})}function Q(e,t){return W({lockName:`server`,lockDir:e,...t})}export{g as S,E as _,X as a,x as b,O as c,V as d,H as f,T as g,B as h,Y as i,R as l,G as m,q as n,J as o,U as p,Z as r,Q as s,K as t,k as u,S as v,_ as x,C as y};
2
+ //# sourceMappingURL=server-lock-DWsOY8Sf.mjs.map