@inkeep/open-knowledge 0.77.9-beta.0 → 0.77.9-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.
- package/dist/{chunk-XKWWSDBF-D2uvTQ0O.mjs → chunk-XKWWSDBF-CiyukTrj.mjs} +2 -2
- package/dist/cli.mjs +68 -68
- package/dist/config-schema.json +1 -1
- package/dist/config.user.schema.json +1 -1
- package/dist/constants-D7ISUGXs.mjs +1 -0
- package/dist/{dist-gqMlO9g5.mjs → dist-CdMoMubk.mjs} +484 -480
- package/dist/{dist-DeiwO3MR.mjs → dist-CupHag_I.mjs} +1 -1
- package/dist/{flag-coverage-6JEX67RU-DTi4Xp7_.mjs → flag-coverage-6JEX67RU-Byy8DkC9.mjs} +1 -1
- package/dist/index.mjs +213 -213
- package/dist/init-BnNTdvEi.mjs +1 -0
- package/dist/{init-C-24amuv.mjs → init-Co_mDPzI.mjs} +7 -7
- package/dist/{js-exec-VXN6TZ7U-CMKRxSof.mjs → js-exec-VXN6TZ7U-D--44jnh.mjs} +3 -3
- package/dist/{js-exec-VXN6TZ7U-DW1z0_f3.mjs → js-exec-VXN6TZ7U-Z8_USGOo.mjs} +4 -4
- package/dist/{launch-json-removal-DZGXboeh.mjs → launch-json-removal-BAhghBP0.mjs} +1 -1
- package/dist/loader-DpmPmZs_.mjs +1 -0
- package/dist/{loader-0WU8op48.mjs → loader-RbdwxE-e.mjs} +1 -1
- package/dist/{md-manager-BGnqyqi1-DKflYxqj.mjs → md-manager-BGnqyqi1-RmPtbV-6.mjs} +112 -112
- package/dist/{open-browser-Dz6ZNMx3.mjs → open-browser-yaMqhpHT.mjs} +1 -1
- package/dist/parse-worker.mjs +1 -1
- package/dist/{preview-BSLfKB1h.mjs → preview-D4W9ISBt.mjs} +1 -1
- package/dist/preview-h82xr4fS.mjs +1 -0
- package/dist/public/assets/{ActivityModeContent-BY6wH-wO.js → ActivityModeContent-BATxSUxv.js} +1 -1
- package/dist/public/assets/AddPropertiesButton-Bhz5D_tP.js +2 -0
- package/dist/public/assets/{AgentDiffPane-imVcQAvw.js → AgentDiffPane-BcLct3Tk.js} +1 -1
- package/dist/public/assets/{AgentIconCluster-CX0heJ76.js → AgentIconCluster-DOtER7-F.js} +1 -1
- package/dist/public/assets/{AgentThreadClientBinder-CM_Hnzrg.js → AgentThreadClientBinder-DadOvih9.js} +1 -1
- package/dist/public/assets/{BugReportHistory-CpWgA9i6.js → BugReportHistory-D_OEmcqh.js} +1 -1
- package/dist/public/assets/{BugReportHistoryDialog-Bh3IoStx.js → BugReportHistoryDialog-ZGMDK7sk.js} +1 -1
- package/dist/public/assets/{CodeMirrorPropInput-CKTzBmVA.js → CodeMirrorPropInput-Dvk3snLM.js} +1 -1
- package/dist/public/assets/{ConsentDialogBody-Crr37Gw8.js → ConsentDialogBody-CDquCfjj.js} +1 -1
- package/dist/public/assets/{DeleteConfirmationDialog-BTQgbqfd.js → DeleteConfirmationDialog-DaZfyQd8.js} +1 -1
- package/dist/public/assets/{DiffViewBoundary-8RVTpygC.js → DiffViewBoundary-DbhDbXy8.js} +1 -1
- package/dist/public/assets/{DocumentContext-C1m9UXHM.js → DocumentContext-MH9fqXuW.js} +11 -11
- package/dist/public/assets/{EditorModeToggle-iQ8C1HyA.js → EditorModeToggle-DClfDUEr.js} +1 -1
- package/dist/public/assets/{EnableSyncConfirmDialog-ot1ZDxq3.js → EnableSyncConfirmDialog-Cdv3n1kf.js} +1 -1
- package/dist/public/assets/{ExcalidrawDocEditor-YCIaO1FB.js → ExcalidrawDocEditor-DngKrGvf.js} +1 -1
- package/dist/public/assets/FeedbackForm-XP78idFj.js +1 -0
- package/dist/public/assets/{GraphPanel-C3eHn4gW.js → GraphPanel--beNjRT-.js} +1 -1
- package/dist/public/assets/{ImageAttachments-DSlR8TcI.js → ImageAttachments-CIihp_JJ.js} +1 -1
- package/dist/public/assets/{ImportSkillDialog-CkAJnfOt.js → ImportSkillDialog-DFsIu8AB.js} +1 -1
- package/dist/public/assets/{LintConfigEditor-IydG9Wjj.js → LintConfigEditor-OucnKI9n.js} +1 -1
- package/dist/public/assets/{ManagedArtifactProperties-BftkuLdv.js → ManagedArtifactProperties-CJpHReke.js} +1 -1
- package/dist/public/assets/ManagedArtifactProperties-dVdeWrTE.js +1 -0
- package/dist/public/assets/{MermaidDocEditor-BWUuY8HN.js → MermaidDocEditor-DAQKQTIg.js} +1 -1
- package/dist/public/assets/{OpenInAgentMenuItem-BAwvIzLB.js → OpenInAgentMenuItem-BzgmEFwX.js} +1 -1
- package/dist/public/assets/{PropertyDisplayRow-Uu4HftXO.js → PropertyDisplayRow-CR4LTYHm.js} +1 -1
- package/dist/public/assets/{RegisteredAgentIcon-9VM9CSSM.js → RegisteredAgentIcon-2cwevuRg.js} +1 -1
- package/dist/public/assets/{ReportBugDialogBody-DpKnchmQ.js → ReportBugDialogBody-B4etLNwK.js} +1 -1
- package/dist/public/assets/{ReportBugMenuTrigger-DSs8yLxa.js → ReportBugMenuTrigger-Bc5z0-Fu.js} +2 -2
- package/dist/public/assets/{SchemaConfigEditor-59CZ81RK.js → SchemaConfigEditor-DfMcNdGA.js} +1 -1
- package/dist/public/assets/{SessionsHost-BGDWcekB.js → SessionsHost-DS7-1kuO.js} +2 -2
- package/dist/public/assets/SettingsDialogBody-BFPgfIw-.js +12 -0
- package/dist/public/assets/{ShareBranchSwitchDialog-CTDAYuOX.js → ShareBranchSwitchDialog-CGaCBOnF.js} +1 -1
- package/dist/public/assets/{ShareReceiveDialog-Cuf5ASDY.js → ShareReceiveDialog-DFRKvuQJ.js} +1 -1
- package/dist/public/assets/{ShareReceiveMissDialog-XYo17yEk.js → ShareReceiveMissDialog-BXrtIcx4.js} +1 -1
- package/dist/public/assets/{SkillCostValue-BE6EBNfT.js → SkillCostValue-CaXVQav1.js} +1 -1
- package/dist/public/assets/{SkillEditBanner-BycfTypX.js → SkillEditBanner-D_7WTsJ7.js} +1 -1
- package/dist/public/assets/{SkillForkDialog-SINB-id1.js → SkillForkDialog-DQQGuXv8.js} +1 -1
- package/dist/public/assets/{SkillInstallMenu-6CFDq4BF.js → SkillInstallMenu-UGZNOesd.js} +1 -1
- package/dist/public/assets/{SkillOriginInline-Cgl8RIR-.js → SkillOriginInline-wHAllLhh.js} +1 -1
- package/dist/public/assets/{SkillToolbarControls-BK_AaeoX.js → SkillToolbarControls-dPfL3r5J.js} +1 -1
- package/dist/public/assets/{SlidesToolbarControls-60y5ydf2.js → SlidesToolbarControls-C_5MgL5R.js} +1 -1
- package/dist/public/assets/{SourceEditor-CBrv7dJo.js → SourceEditor-DgBYiBut.js} +1 -1
- package/dist/public/assets/{TerminalPanel-Bkzcs2Nj.js → TerminalPanel-CXjN_98-.js} +3 -3
- package/dist/public/assets/{TerminalWindowApp-D0A8V7Nm.js → TerminalWindowApp-CQzuZYuY.js} +1 -1
- package/dist/public/assets/{TextDocEditor-C6ucmNYD.js → TextDocEditor-Gj93hBqH.js} +1 -1
- package/dist/public/assets/ThreadView-C7sqK0is.js +21 -0
- package/dist/public/assets/{TimelineDiffPane-L_Q3Y78K.js → TimelineDiffPane-CRlgrJ2D.js} +1 -1
- package/dist/public/assets/{agent-connection-status-BgT1U0id.js → agent-connection-status-DSp5AbZq.js} +1 -1
- package/dist/public/assets/{auth-state-cache-NYgkVRT6.js → auth-state-cache-CglXQ28p.js} +1 -1
- package/dist/public/assets/{bug-report-send-manager-Bmqwf2M5.js → bug-report-send-manager-IdWBPFHN.js} +1 -1
- package/dist/public/assets/{client-version-DR53JJn2.js → client-version-Cfeq3w2f.js} +1 -1
- package/dist/public/assets/{comment-chips-DeBWzeAe.js → comment-chips-BDBYUGDo.js} +1 -1
- package/dist/public/assets/{config-provider-DiJSKkg8.js → config-provider-CB8Idy6z.js} +1 -1
- package/dist/public/assets/{css-color-to-hex-wMBAsSG3.js → css-color-to-hex-CMHRbt5X.js} +1 -1
- package/dist/public/assets/{diagnostic-breadcrumb-BjDNQhui.js → diagnostic-breadcrumb-DtVIthxV.js} +1 -1
- package/dist/public/assets/{dist-C_owXiVJ.js → dist-DDq2bd0-.js} +11 -11
- package/dist/public/assets/{doc-paths-dCv8glmi.js → doc-paths-CWMCOiOb.js} +1 -1
- package/dist/public/assets/{doc-undo-manager-CLhUJl8z.js → doc-undo-manager-Dgd_R1wH.js} +1 -1
- package/dist/public/assets/{documents-events-ByK-A_Qe.js → documents-events-BNOxHubi.js} +1 -1
- package/dist/public/assets/{file-tree-adapter-CrD2Zh_o.js → file-tree-adapter-CQyVXMVG.js} +1 -1
- package/dist/public/assets/{file-tree-utils-elC-lbdd.js → file-tree-utils-BgnPOQNb.js} +1 -1
- package/dist/public/assets/{folder-config-api-C6_l3om9.js → folder-config-api-CnTUk9rh.js} +1 -1
- package/dist/public/assets/{index-MPigSfWz.js → index-C-M9IPeM.js} +18 -18
- package/dist/public/assets/{launch-agent-thread-BTIPj2wd.js → launch-agent-thread-CE4umI5d.js} +1 -1
- package/dist/public/assets/{lint-config-client-DBFw6OHC.js → lint-config-client-D_KJIdJ0.js} +1 -1
- package/dist/public/assets/{markdownlint-rule-browser-BoWbwkTH.js → markdownlint-rule-browser-Dbi_T41A.js} +1 -1
- package/dist/public/assets/{messages-Dh8tUASl.js → messages-BBniyOLF.js} +1 -1
- package/dist/public/assets/{messages-DFb3Vzg0.js → messages-C-1V9628.js} +1 -1
- package/dist/public/assets/{messages-B2R3Y06g.js → messages-C-ujGeuR.js} +1 -1
- package/dist/public/assets/{messages-T88bnbcm.js → messages-CK2HIOIp.js} +1 -1
- package/dist/public/assets/{messages-BDBEmoWh.js → messages-CNb9VVVF.js} +1 -1
- package/dist/public/assets/{messages-Cu3nrgO4.js → messages-CP9Uo9SK.js} +1 -1
- package/dist/public/assets/{messages-CN6bx_s-.js → messages-CXQO0cdG.js} +1 -1
- package/dist/public/assets/{messages-y3Nv7XrJ.js → messages-CduVnYUK.js} +1 -1
- package/dist/public/assets/{messages-hVCpOrm3.js → messages-CzRStuhZ.js} +1 -1
- package/dist/public/assets/{messages-CbSNKie_.js → messages-DlYEa7go.js} +1 -1
- package/dist/public/assets/{messages-NQv6lBnJ.js → messages-Dmkb0uPj.js} +1 -1
- package/dist/public/assets/{messages-WhrJ5T4P.js → messages-G0BZY30Q.js} +1 -1
- package/dist/public/assets/{navigation-targets-CvNinRyp.js → navigation-targets-Czs2lfGZ.js} +1 -1
- package/dist/public/assets/{page-list-cache-DvhqPgdF.js → page-list-cache-C-TRKOCs.js} +1 -1
- package/dist/public/assets/{pending-receive-nav-store-o2g0a-Bn.js → pending-receive-nav-store-DU0fd5HG.js} +1 -1
- package/dist/public/assets/{preferred-session-events-K_HaJMAn.js → preferred-session-events-DmNk8hX1.js} +1 -1
- package/dist/public/assets/{progress-CkEBTFSF.js → progress-92g2HE0r.js} +3 -3
- package/dist/public/assets/{project-paths-BzuFAe-N.js → project-paths-D5u5ETp2.js} +1 -1
- package/dist/public/assets/{prop-types-DI-i5R8d.js → prop-types-DrIWG3Gx.js} +1 -1
- package/dist/public/assets/{receive-store-Djrqwgcm.js → receive-store-KjyHtK2Z.js} +1 -1
- package/dist/public/assets/{selection-context-DzTEr8je.js → selection-context-Dr8Dwtss.js} +1 -1
- package/dist/public/assets/{skill-scope-BnHkWlIp.js → skill-scope-PQ-EaBPe.js} +1 -1
- package/dist/public/assets/{skills-api-C9lYknem.js → skills-api-Bp10td_R.js} +1 -1
- package/dist/public/assets/{src-DWAR0qhq.js → src-D45teqFC.js} +1 -1
- package/dist/public/assets/{startup-marks--VxxzHYd.js → startup-marks-CrtY-I8L.js} +1 -1
- package/dist/public/assets/{tag-pill-input-L67HH_ro.js → tag-pill-input-ChT0p3uH.js} +1 -1
- package/dist/public/assets/{target-navigation-intent-DAHHkidf.js → target-navigation-intent-Dxn3CEpi.js} +1 -1
- package/dist/public/assets/{telemetry-startup-DhtP83qd.js → telemetry-startup-CNWCAxA7.js} +1 -1
- package/dist/public/assets/{terminal-command-events-DonTra6W.js → terminal-command-events-BtEB1nJF.js} +1 -1
- package/dist/public/assets/{terminal-launch-events-C87UeOVG.js → terminal-launch-events-z128lGYy.js} +1 -1
- package/dist/public/assets/{terminal-telemetry-rnrKpL-Q.js → terminal-telemetry-DWYzbPMs.js} +1 -1
- package/dist/public/assets/thread-client-DWy51KvB.js +3 -0
- package/dist/public/assets/{typing-burst-detector-BLuUdN-d.js → typing-burst-detector-C5hbfIC1.js} +1 -1
- package/dist/public/assets/{uninstall-Bnt3uUvy.js → uninstall-BJ0ruD6y.js} +1 -1
- package/dist/public/assets/{use-activity-panel-DhnfRmuH.js → use-activity-panel-B0hBttlz.js} +1 -1
- package/dist/public/assets/{use-apply-config-language-ChGKbbl6.js → use-apply-config-language-B0buol98.js} +2 -2
- package/dist/public/assets/{use-collab-url-DnDtI_86.js → use-collab-url-oh5407bM.js} +1 -1
- package/dist/public/assets/{use-conflicts-DYvfJWip.js → use-conflicts-DlwnAZby.js} +1 -1
- package/dist/public/assets/{use-live-xterm-theme-BDq8DzaU.js → use-live-xterm-theme-kTh86ROJ.js} +1 -1
- package/dist/public/assets/{use-open-skill-BK-vnG6-.js → use-open-skill-CfG5l4pa.js} +1 -1
- package/dist/public/assets/{use-settings-route-8XQTWK31.js → use-settings-route-kXDIfwuP.js} +1 -1
- package/dist/public/assets/{use-skill-origin-B1YmBhKN.js → use-skill-origin-nNSEYBhk.js} +1 -1
- package/dist/public/assets/{use-skills-CYMgz3tV.js → use-skills-BjbaVkdM.js} +1 -1
- package/dist/public/assets/{use-terminal-enabled-DYkPSupQ.js → use-terminal-enabled-Bz_EEFKW.js} +1 -1
- package/dist/public/assets/{use-timeline-entry-diff-CNgx0eFH.js → use-timeline-entry-diff-CxWiRlcf.js} +1 -1
- package/dist/public/assets/{use-workspace-TNZRqr22.js → use-workspace-B5fRmw0K.js} +1 -1
- package/dist/public/index.html +58 -58
- package/dist/public/uninstall.html +4 -4
- package/dist/{python3-DNGS4G3E-Dpff_XiH.mjs → python3-DNGS4G3E-CRyO5yp1.mjs} +2 -2
- package/dist/{python3-DNGS4G3E-DSWx_2Ia.mjs → python3-DNGS4G3E-CixyRGKv.mjs} +3 -3
- package/dist/registry-probes-BjsDFB65.mjs +17 -0
- package/dist/{removal-file-path-BXR6pfkp.mjs → removal-file-path-D6OEqNBM.mjs} +1 -1
- package/dist/{repair-launch-json-DP6KyVNN.mjs → repair-launch-json-BLnKg19X.mjs} +1 -1
- package/dist/{repair-mcp-configs-B4GpHKFe.mjs → repair-mcp-configs-hy238Kt4.mjs} +1 -1
- package/dist/schemas/v0/config.user.schema.json +1 -1
- package/dist/{sqlite3-TE5AIOTF-ButYCorg.mjs → sqlite3-TE5AIOTF-BK092fD6.mjs} +1 -1
- package/dist/{sqlite3-TE5AIOTF-D4yhY7wL.mjs → sqlite3-TE5AIOTF-DVwda1Ow.mjs} +3 -3
- package/dist/src-DUyBP196.mjs +1 -0
- package/dist/{src-BY955T7w.mjs → src-tuHpjXRh.mjs} +4 -4
- package/dist/start-BWVT5n3j.mjs +1 -0
- package/dist/{start-YF7-qdEa.mjs → start-DWDyuoi5.mjs} +3 -3
- package/package.json +4 -4
- package/dist/constants-CdiHNFvt.mjs +0 -1
- package/dist/init-BNRf8IKE.mjs +0 -1
- package/dist/loader-0rF9tfd3.mjs +0 -1
- package/dist/preview-CvKb1PXt.mjs +0 -1
- package/dist/public/assets/AddPropertiesButton-C09dSw6a.js +0 -2
- package/dist/public/assets/FeedbackForm-CDTuiQCm.js +0 -1
- package/dist/public/assets/ManagedArtifactProperties-Biuoihpn.js +0 -1
- package/dist/public/assets/SettingsDialogBody-BZT6pxq7.js +0 -12
- package/dist/public/assets/ThreadView-BIIMjhFk.js +0 -20
- package/dist/public/assets/thread-client-BS0s_MKD.js +0 -4
- package/dist/registry-probes-CADyDcpU.mjs +0 -17
- package/dist/src-DYZb5r4K.mjs +0 -1
- package/dist/start-C-EE421o.mjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e,i as t,t as n}from"./rolldown-runtime-DPpTSio4.mjs";import"./chunk-DXB73IDG-MLBj3lvC.mjs";import{t as r}from"./chunk-5QMZ5MUS-B37CnsNb.mjs";import{n as i,t as a}from"./chunk-A5O5YHGN-2_dxLAd1.mjs";import{n as o}from"./chunk-24IMIIXA-CZ-UxWg_.mjs";import{n as s,t as c}from"./chunk-3THT3N7L-DVKHLRUO.mjs";import{r as l,t as u}from"./chunk-74CEPOFO-BuzahJu2.mjs";import{existsSync as d}from"node:fs";import{dirname as f,join as p,sep as m}from"node:path";import{fileURLToPath as h}from"node:url";import{Worker as g}from"node:worker_threads";import{randomBytes as _}from"node:crypto";var v=e(n(((e,n)=>{var r=void 0,i=function(e){return r||(r=new Promise(function(r,i){var a=e===void 0?{}:e,o=a.onAbort;a.onAbort=function(e){i(Error(e)),o&&o(e)},a.postRun=a.postRun||[],a.postRun.push(function(){r(a)}),n=void 0;var s;s||=a===void 0?{}:a;var c=!!globalThis.window,l=!!globalThis.WorkerGlobalScope,u=globalThis.process?.versions?.node&&globalThis.process?.type!=`renderer`;s.onRuntimeInitialized=function(){function e(e,t){switch(typeof t){case`boolean`:N(e,+!!t);break;case`number`:de(e,t);break;case`string`:A(e,t,-1,-1);break;case`object`:if(t===null)fe(e);else if(t.length!=null){var n=Mt(t.length);C.set(t,n),j(e,n,t.length,-1),Nt(n)}else P(e,`Wrong API use : tried to return a value of an unknown type (`+t+`).`,-1);break;default:fe(e)}}function t(e,t){for(var n=[],r=0;r<e;r+=1){var i=M(t+4*r,`i32`),a=oe(i);if(a===1||a===2)i=ue(i);else if(a===3)i=ce(i);else if(a===4){a=i,i=se(a),a=le(a);for(var o=new Uint8Array(i),s=0;s<i;s+=1)o[s]=C[a+s];i=o}else i=null;n.push(i)}return n}function n(e,t){this.Qa=e,this.db=t,this.Oa=1,this.mb=[]}function r(e,t){if(this.db=t,this.fb=Et(e),this.fb===null)throw Error(`Unable to allocate memory for the SQL string`);this.lb=this.fb,this.$a=this.sb=null}function i(e){if(this.filename=`dbfile_`+(4294967295*Math.random()>>>0),e!=null){var t=this.filename,n=`/`,r=t;if(n&&(n=typeof n==`string`?n:Re(n),r=t?ge(n+`/`+t):n),t=Ae(!0,!0),r=Qe(r,t),e){if(typeof e==`string`){n=Array(e.length);for(var i=0,o=e.length;i<o;++i)n[i]=e.charCodeAt(i);e=n}at(r,t|146),n=st(r,577),dt(n,e,0,e.length,0),ct(n),at(r,t)}}this.handleError(c(this.filename,a)),this.db=M(a,`i32`),he(this.db),this.gb={},this.Sa={}}var a=Q(4),o=s.cwrap,c=o(`sqlite3_open`,`number`,[`string`,`number`]),l=o(`sqlite3_close_v2`,`number`,[`number`]),u=o(`sqlite3_exec`,`number`,[`number`,`string`,`number`,`number`,`number`]),d=o(`sqlite3_changes`,`number`,[`number`]),f=o(`sqlite3_prepare_v2`,`number`,[`number`,`string`,`number`,`number`,`number`]),p=o(`sqlite3_sql`,`string`,[`number`]),m=o(`sqlite3_normalized_sql`,`string`,[`number`]),h=o(`sqlite3_prepare_v2`,`number`,[`number`,`number`,`number`,`number`,`number`]),g=o(`sqlite3_bind_text`,`number`,[`number`,`number`,`number`,`number`,`number`]),_=o(`sqlite3_bind_blob`,`number`,[`number`,`number`,`number`,`number`,`number`]),v=o(`sqlite3_bind_double`,`number`,[`number`,`number`,`number`]),y=o(`sqlite3_bind_int`,`number`,[`number`,`number`,`number`]),b=o(`sqlite3_bind_parameter_index`,`number`,[`number`,`string`]),x=o(`sqlite3_step`,`number`,[`number`]),ee=o(`sqlite3_errmsg`,`string`,[`number`]),S=o(`sqlite3_column_count`,`number`,[`number`]),w=o(`sqlite3_data_count`,`number`,[`number`]),T=o(`sqlite3_column_double`,`number`,[`number`,`number`]),E=o(`sqlite3_column_text`,`string`,[`number`,`number`]),D=o(`sqlite3_column_blob`,`number`,[`number`,`number`]),te=o(`sqlite3_column_bytes`,`number`,[`number`,`number`]),ne=o(`sqlite3_column_type`,`number`,[`number`,`number`]),O=o(`sqlite3_column_name`,`string`,[`number`,`number`]),re=o(`sqlite3_reset`,`number`,[`number`]),k=o(`sqlite3_clear_bindings`,`number`,[`number`]),ie=o(`sqlite3_finalize`,`number`,[`number`]),ae=o(`sqlite3_create_function_v2`,`number`,`number string number number number number number number number`.split(` `)),oe=o(`sqlite3_value_type`,`number`,[`number`]),se=o(`sqlite3_value_bytes`,`number`,[`number`]),ce=o(`sqlite3_value_text`,`string`,[`number`]),le=o(`sqlite3_value_blob`,`number`,[`number`]),ue=o(`sqlite3_value_double`,`number`,[`number`]),de=o(`sqlite3_result_double`,``,[`number`,`number`]),fe=o(`sqlite3_result_null`,``,[`number`]),A=o(`sqlite3_result_text`,``,[`number`,`string`,`number`,`number`]),j=o(`sqlite3_result_blob`,``,[`number`,`number`,`number`,`number`]),N=o(`sqlite3_result_int`,``,[`number`,`number`]),P=o(`sqlite3_result_error`,``,[`number`,`string`,`number`]),me=o(`sqlite3_aggregate_context`,`number`,[`number`,`number`]),he=o(`RegisterExtensionFunctions`,`number`,[`number`]),_e=o(`sqlite3_update_hook`,`number`,[`number`,`number`,`number`]);n.prototype.bind=function(e){if(!this.Qa)throw`Statement closed`;return this.reset(),Array.isArray(e)?this.Gb(e):typeof e==`object`&&e?this.Hb(e):!0},n.prototype.step=function(){if(!this.Qa)throw`Statement closed`;this.Oa=1;var e=x(this.Qa);switch(e){case 100:return!0;case 101:return!1;default:throw this.db.handleError(e)}},n.prototype.Ab=function(e){return e??(e=this.Oa,this.Oa+=1),T(this.Qa,e)},n.prototype.Ob=function(e){if(e??(e=this.Oa,this.Oa+=1),e=E(this.Qa,e),typeof BigInt!=`function`)throw Error(`BigInt is not supported`);return BigInt(e)},n.prototype.Tb=function(e){return e??(e=this.Oa,this.Oa+=1),E(this.Qa,e)},n.prototype.getBlob=function(e){e??(e=this.Oa,this.Oa+=1);var t=te(this.Qa,e);e=D(this.Qa,e);for(var n=new Uint8Array(t),r=0;r<t;r+=1)n[r]=C[e+r];return n},n.prototype.get=function(e,t){t||={},e!=null&&this.bind(e)&&this.step(),e=[];for(var n=w(this.Qa),r=0;r<n;r+=1)switch(ne(this.Qa,r)){case 1:var i=t.useBigInt?this.Ob(r):this.Ab(r);e.push(i);break;case 2:e.push(this.Ab(r));break;case 3:e.push(this.Tb(r));break;case 4:e.push(this.getBlob(r));break;default:e.push(null)}return e},n.prototype.qb=function(){for(var e=[],t=S(this.Qa),n=0;n<t;n+=1)e.push(O(this.Qa,n));return e},n.prototype.zb=function(e,t){e=this.get(e,t),t=this.qb();for(var n={},r=0;r<t.length;r+=1)n[t[r]]=e[r];return n},n.prototype.Sb=function(){return p(this.Qa)},n.prototype.Pb=function(){return m(this.Qa)},n.prototype.run=function(e){return e!=null&&this.bind(e),this.step(),this.reset()},n.prototype.wb=function(e,t){t??(t=this.Oa,this.Oa+=1),e=Et(e),this.mb.push(e),this.db.handleError(g(this.Qa,t,e,-1,0))},n.prototype.Fb=function(e,t){t??(t=this.Oa,this.Oa+=1);var n=Mt(e.length);C.set(e,n),this.mb.push(n),this.db.handleError(_(this.Qa,t,n,e.length,0))},n.prototype.vb=function(e,t){t??(t=this.Oa,this.Oa+=1),this.db.handleError((e===(e|0)?y:v)(this.Qa,t,e))},n.prototype.Ib=function(e){e??(e=this.Oa,this.Oa+=1),_(this.Qa,e,0,0,0)},n.prototype.xb=function(e,t){switch(t??(t=this.Oa,this.Oa+=1),typeof e){case`string`:this.wb(e,t);return;case`number`:this.vb(e,t);return;case`bigint`:this.wb(e.toString(),t);return;case`boolean`:this.vb(e+0,t);return;case`object`:if(e===null){this.Ib(t);return}if(e.length!=null){this.Fb(e,t);return}}throw`Wrong API use : tried to bind a value of an unknown type (`+e+`).`},n.prototype.Hb=function(e){var t=this;return Object.keys(e).forEach(function(n){var r=b(t.Qa,n);r!==0&&t.xb(e[n],r)}),!0},n.prototype.Gb=function(e){for(var t=0;t<e.length;t+=1)this.xb(e[t],t+1);return!0},n.prototype.reset=function(){return this.freemem(),k(this.Qa)===0&&re(this.Qa)===0},n.prototype.freemem=function(){for(var e;(e=this.mb.pop())!==void 0;)Nt(e)},n.prototype.Ya=function(){this.freemem();var e=ie(this.Qa)===0;return delete this.db.gb[this.Qa],this.Qa=0,e},r.prototype.next=function(){if(this.fb===null)return{done:!0};if(this.$a!==null&&(this.$a.Ya(),this.$a=null),!this.db.db)throw this.ob(),Error(`Database closed`);var e=Lt(),t=Q(4);pe(a),pe(t);try{this.db.handleError(h(this.db.db,this.lb,-1,a,t)),this.lb=M(t,`i32`);var r=M(a,`i32`);return r===0?(this.ob(),{done:!0}):(this.$a=new n(r,this.db),this.db.gb[r]=this.$a,{value:this.$a,done:!1})}catch(e){throw this.sb=F(this.lb),this.ob(),e}finally{It(e)}},r.prototype.ob=function(){Nt(this.fb),this.fb=null},r.prototype.Qb=function(){return this.sb===null?F(this.lb):this.sb},typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`&&(r.prototype[Symbol.iterator]=function(){return this}),i.prototype.run=function(e,t){if(!this.db)throw`Database closed`;if(t){e=this.tb(e,t);try{e.step()}finally{e.Ya()}}else this.handleError(u(this.db,e,0,0,a));return this},i.prototype.exec=function(e,t,r){if(!this.db)throw`Database closed`;var i=null,o=null,s=null;try{s=o=Et(e);var c=Q(4);for(e=[];M(s,`i8`)!==0;){pe(a),pe(c),this.handleError(h(this.db,s,-1,a,c));var l=M(a,`i32`);if(s=M(c,`i32`),l!==0){var u=null;for(i=new n(l,this),t!=null&&i.bind(t);i.step();)u===null&&(u={columns:i.qb(),values:[]},e.push(u)),u.values.push(i.get(null,r));i.Ya()}}return e}catch(e){throw i&&i.Ya(),e}finally{o&&Nt(o)}},i.prototype.Mb=function(e,t,n,r,i){typeof t==`function`&&(r=n,n=t,t=void 0),e=this.tb(e,t);try{for(;e.step();)n(e.zb(null,i))}finally{e.Ya()}if(typeof r==`function`)return r()},i.prototype.tb=function(e,t){if(pe(a),this.handleError(f(this.db,e,-1,a,0)),e=M(a,`i32`),e===0)throw`Nothing to prepare`;var r=new n(e,this);return t!=null&&r.bind(t),this.gb[e]=r},i.prototype.Ub=function(e){return new r(e,this)},i.prototype.Nb=function(){Object.values(this.gb).forEach(function(e){e.Ya()}),Object.values(this.Sa).forEach(Z),this.Sa={},this.handleError(l(this.db));var e=ft(this.filename);return this.handleError(c(this.filename,a)),this.db=M(a,`i32`),he(this.db),e},i.prototype.close=function(){this.db!==null&&(Object.values(this.gb).forEach(function(e){e.Ya()}),Object.values(this.Sa).forEach(Z),this.Sa={},this.Za&&=(Z(this.Za),void 0),this.handleError(l(this.db)),nt(`/`+this.filename),this.db=null)},i.prototype.handleError=function(e){if(e===0)return null;throw e=ee(this.db),Error(e)},i.prototype.Rb=function(){return d(this.db)},i.prototype.Kb=function(n,r){Object.prototype.hasOwnProperty.call(this.Sa,n)&&(Z(this.Sa[n]),delete this.Sa[n]);var i=jt(function(n,i,a){i=t(i,a);try{var o=r.apply(null,i)}catch(e){P(n,e,-1);return}e(n,o)},`viii`);return this.Sa[n]=i,this.handleError(ae(this.db,n,r.length,1,0,i,0,0,0)),this},i.prototype.Jb=function(n,r){var i=r.init||function(){return null},a=r.finalize||function(e){return e},o=r.step;if(!o)throw`An aggregate function must have a step function in `+n;var s={};Object.hasOwnProperty.call(this.Sa,n)&&(Z(this.Sa[n]),delete this.Sa[n]),r=n+`__finalize`,Object.hasOwnProperty.call(this.Sa,r)&&(Z(this.Sa[r]),delete this.Sa[r]);var c=jt(function(e,n,r){var a=me(e,1);Object.hasOwnProperty.call(s,a)||(s[a]=i()),n=t(n,r),n=[s[a]].concat(n);try{s[a]=o.apply(null,n)}catch(t){delete s[a],P(e,t,-1)}},`viii`),l=jt(function(t){var n=me(t,1);try{var r=a(s[n])}catch(e){delete s[n],P(t,e,-1);return}e(t,r),delete s[n]},`vi`);return this.Sa[n]=c,this.Sa[r]=l,this.handleError(ae(this.db,n,o.length-1,1,0,0,c,l,0)),this},i.prototype.Zb=function(e){return this.Za&&=(_e(this.db,0,0),Z(this.Za),void 0),e?(this.Za=jt(function(t,n,r,i,a){switch(n){case 18:t=`insert`;break;case 23:t=`update`;break;case 9:t=`delete`;break;default:throw`unknown operationCode in updateHook callback: `+n}if(r=F(r),i=F(i),a>2**53-1)throw`rowId too big to fit inside a Number`;e(t,r,i,Number(a))},`viiiij`),_e(this.db,this.Za,0),this):this},n.prototype.bind=n.prototype.bind,n.prototype.step=n.prototype.step,n.prototype.get=n.prototype.get,n.prototype.getColumnNames=n.prototype.qb,n.prototype.getAsObject=n.prototype.zb,n.prototype.getSQL=n.prototype.Sb,n.prototype.getNormalizedSQL=n.prototype.Pb,n.prototype.run=n.prototype.run,n.prototype.reset=n.prototype.reset,n.prototype.freemem=n.prototype.freemem,n.prototype.free=n.prototype.Ya,r.prototype.next=r.prototype.next,r.prototype.getRemainingSQL=r.prototype.Qb,i.prototype.run=i.prototype.run,i.prototype.exec=i.prototype.exec,i.prototype.each=i.prototype.Mb,i.prototype.prepare=i.prototype.tb,i.prototype.iterateStatements=i.prototype.Ub,i.prototype.export=i.prototype.Nb,i.prototype.close=i.prototype.close,i.prototype.handleError=i.prototype.handleError,i.prototype.getRowsModified=i.prototype.Rb,i.prototype.create_function=i.prototype.Kb,i.prototype.create_aggregate=i.prototype.Jb,i.prototype.updateHook=i.prototype.Zb,s.Database=i};var d=`./this.program`,f=(e,t)=>{throw t},p=globalThis.document?.currentScript?.src;typeof __filename<`u`?p=__filename:l&&(p=self.location.href);var m=``,h,g;if(u){var _=t(`node:fs`);m=__dirname+`/`,g=e=>(e=S(e)?new URL(e):e,_.readFileSync(e)),h=async e=>(e=S(e)?new URL(e):e,_.readFileSync(e,void 0)),1<process.argv.length&&(d=process.argv[1].replace(/\\/g,`/`)),process.argv.slice(2),n!==void 0&&(n.exports=s),f=(e,t)=>{throw process.exitCode=e,t}}else if(c||l){try{m=new URL(`.`,p).href}catch{}l&&(g=e=>{var t=new XMLHttpRequest;return t.open(`GET`,e,!1),t.responseType=`arraybuffer`,t.send(null),new Uint8Array(t.response)}),h=async e=>{if(S(e))return new Promise((t,n)=>{var r=new XMLHttpRequest;r.open(`GET`,e,!0),r.responseType=`arraybuffer`,r.onload=()=>{r.status==200||r.status==0&&r.response?t(r.response):n(r.status)},r.onerror=n,r.send(null)});var t=await fetch(e,{credentials:`same-origin`});if(t.ok)return t.arrayBuffer();throw Error(t.status+` : `+t.url)}}var v=console.log.bind(console),y=console.error.bind(console),b,x=!1,ee,S=e=>e.startsWith(`file://`),C,w,T,E,D,te,ne,O;function re(){var e=Rt.buffer;C=new Int8Array(e),T=new Int16Array(e),w=new Uint8Array(e),new Uint16Array(e),E=new Int32Array(e),D=new Uint32Array(e),te=new Float32Array(e),ne=new Float64Array(e),O=new BigInt64Array(e),new BigUint64Array(e)}function k(e){throw s.onAbort?.(e),e=`Aborted(`+e+`)`,y(e),x=!0,new WebAssembly.RuntimeError(e+`. Build with -sASSERTIONS for more info.`)}var ie;async function ae(e){if(!b)try{var t=await h(e);return new Uint8Array(t)}catch{}if(e==ie&&b)e=new Uint8Array(b);else if(g)e=g(e);else throw`both async and sync fetching of the wasm failed`;return e}async function oe(e,t){try{var n=await ae(e);return await WebAssembly.instantiate(n,t)}catch(e){y(`failed to asynchronously prepare wasm: ${e}`),k(e)}}async function se(e){var t=ie;if(!b&&!S(t)&&!u)try{var n=fetch(t,{credentials:`same-origin`});return await WebAssembly.instantiateStreaming(n,e)}catch(e){y(`wasm streaming compile failed: ${e}`),y(`falling back to ArrayBuffer instantiation`)}return oe(t,e)}class ce{name=`ExitStatus`;constructor(e){this.message=`Program terminated with exit(${e})`,this.status=e}}var le=e=>{for(;0<e.length;)e.shift()(s)},ue=[],de=[],fe=()=>{var e=s.preRun.shift();de.push(e)},A=0,j=null;function M(e,t=`i8`){switch(t.endsWith(`*`)&&(t=`*`),t){case`i1`:return C[e];case`i8`:return C[e];case`i16`:return T[e>>1];case`i32`:return E[e>>2];case`i64`:return O[e>>3];case`float`:return te[e>>2];case`double`:return ne[e>>3];case`*`:return D[e>>2];default:k(`invalid type for getValue: ${t}`)}}var N=!0;function pe(e){var t=`i32`;switch(t.endsWith(`*`)&&(t=`*`),t){case`i1`:C[e]=0;break;case`i8`:C[e]=0;break;case`i16`:T[e>>1]=0;break;case`i32`:E[e>>2]=0;break;case`i64`:O[e>>3]=BigInt(0);break;case`float`:te[e>>2]=0;break;case`double`:ne[e>>3]=0;break;case`*`:D[e>>2]=0;break;default:k(`invalid type for setValue: ${t}`)}}var P=new TextDecoder,me=(e,t,n,r)=>{if(n=t+n,r)return n;for(;e[t]&&!(t>=n);)++t;return t},F=(e,t,n)=>e?P.decode(w.subarray(e,me(w,e,t,n))):``,he=(e,t)=>{for(var n=0,r=e.length-1;0<=r;r--){var i=e[r];i===`.`?e.splice(r,1):i===`..`?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n;n--)e.unshift(`..`);return e},ge=e=>{var t=e.charAt(0)===`/`,n=e.slice(-1)===`/`;return(e=he(e.split(`/`).filter(e=>!!e),!t).join(`/`))||t||(e=`.`),e&&n&&(e+=`/`),(t?`/`:``)+e},_e=e=>{var t=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(e).slice(1);return e=t[0],t=t[1],!e&&!t?`.`:(t&&=t.slice(0,-1),e+t)},ve=e=>e&&e.match(/([^\/]+|\/)\/*$/)[1],ye=()=>{if(u){var e=t(`node:crypto`);return t=>e.randomFillSync(t)}return e=>crypto.getRandomValues(e)},be=e=>{(be=ye())(e)},xe=(...e)=>{for(var t=``,n=!1,r=e.length-1;-1<=r&&!n;r--){if(n=0<=r?e[r]:`/`,typeof n!=`string`)throw TypeError(`Arguments to path.resolve must be strings`);if(!n)return``;t=n+`/`+t,n=n.charAt(0)===`/`}return t=he(t.split(`/`).filter(e=>!!e),!n).join(`/`),(n?`/`:``)+t||`.`},Se=e=>{var t=me(e,0);return P.decode(e.buffer?e.subarray(0,t):new Uint8Array(e.slice(0,t)))},Ce=[],we=e=>{for(var t=0,n=0;n<e.length;++n){var r=e.charCodeAt(n);127>=r?t++:2047>=r?t+=2:55296<=r&&57343>=r?(t+=4,++n):t+=3}return t},I=(e,t,n,r)=>{if(!(0<r))return 0;var i=n;r=n+r-1;for(var a=0;a<e.length;++a){var o=e.codePointAt(a);if(127>=o){if(n>=r)break;t[n++]=o}else if(2047>=o){if(n+1>=r)break;t[n++]=192|o>>6,t[n++]=128|o&63}else if(65535>=o){if(n+2>=r)break;t[n++]=224|o>>12,t[n++]=128|o>>6&63,t[n++]=128|o&63}else{if(n+3>=r)break;t[n++]=240|o>>18,t[n++]=128|o>>12&63,t[n++]=128|o>>6&63,t[n++]=128|o&63,a++}}return t[n]=0,n-i},Te=[];function Ee(e,t){Te[e]={input:[],output:[],eb:t},Ye(e,De)}var De={open(e){var t=Te[e.node.rdev];if(!t)throw new B(43);e.tty=t,e.seekable=!1},close(e){e.tty.eb.fsync(e.tty)},fsync(e){e.tty.eb.fsync(e.tty)},read(e,t,n,r){if(!e.tty||!e.tty.eb.Bb)throw new B(60);for(var i=0,a=0;a<r;a++){try{var o=e.tty.eb.Bb(e.tty)}catch{throw new B(29)}if(o===void 0&&i===0)throw new B(6);if(o==null)break;i++,t[n+a]=o}return i&&(e.node.atime=Date.now()),i},write(e,t,n,r){if(!e.tty||!e.tty.eb.ub)throw new B(60);try{for(var i=0;i<r;i++)e.tty.eb.ub(e.tty,t[n+i])}catch{throw new B(29)}return r&&(e.node.mtime=e.node.ctime=Date.now()),i}},Oe={Bb(){a:{if(!Ce.length){var e=null;if(u){var t=Buffer.alloc(256),n=0,r=process.stdin.fd;try{n=_.readSync(r,t,0,256)}catch(e){if(e.toString().includes(`EOF`))n=0;else throw e}0<n&&(e=t.slice(0,n).toString(`utf-8`))}else globalThis.window?.prompt&&(e=window.prompt(`Input: `),e!==null&&(e+=`
|
|
1
|
+
import{a as e,i as t,t as n}from"./rolldown-runtime-DPpTSio4.mjs";import"./chunk-DXB73IDG-MLBj3lvC.mjs";import{t as r}from"./chunk-5QMZ5MUS-B37CnsNb.mjs";import{n as i,t as a}from"./chunk-A5O5YHGN-2_dxLAd1.mjs";import{n as o}from"./chunk-24IMIIXA-CZ-UxWg_.mjs";import{n as s,t as c}from"./chunk-3THT3N7L-DVKHLRUO.mjs";import{r as l,t as u}from"./chunk-74CEPOFO-BuzahJu2.mjs";import{existsSync as d}from"node:fs";import{dirname as f,join as p,sep as m}from"node:path";import{fileURLToPath as h}from"node:url";import{randomBytes as g}from"node:crypto";import{Worker as _}from"node:worker_threads";var v=e(n(((e,n)=>{var r=void 0,i=function(e){return r||(r=new Promise(function(r,i){var a=e===void 0?{}:e,o=a.onAbort;a.onAbort=function(e){i(Error(e)),o&&o(e)},a.postRun=a.postRun||[],a.postRun.push(function(){r(a)}),n=void 0;var s;s||=a===void 0?{}:a;var c=!!globalThis.window,l=!!globalThis.WorkerGlobalScope,u=globalThis.process?.versions?.node&&globalThis.process?.type!=`renderer`;s.onRuntimeInitialized=function(){function e(e,t){switch(typeof t){case`boolean`:N(e,+!!t);break;case`number`:de(e,t);break;case`string`:A(e,t,-1,-1);break;case`object`:if(t===null)fe(e);else if(t.length!=null){var n=Mt(t.length);C.set(t,n),j(e,n,t.length,-1),Nt(n)}else P(e,`Wrong API use : tried to return a value of an unknown type (`+t+`).`,-1);break;default:fe(e)}}function t(e,t){for(var n=[],r=0;r<e;r+=1){var i=M(t+4*r,`i32`),a=oe(i);if(a===1||a===2)i=ue(i);else if(a===3)i=ce(i);else if(a===4){a=i,i=se(a),a=le(a);for(var o=new Uint8Array(i),s=0;s<i;s+=1)o[s]=C[a+s];i=o}else i=null;n.push(i)}return n}function n(e,t){this.Qa=e,this.db=t,this.Oa=1,this.mb=[]}function r(e,t){if(this.db=t,this.fb=Et(e),this.fb===null)throw Error(`Unable to allocate memory for the SQL string`);this.lb=this.fb,this.$a=this.sb=null}function i(e){if(this.filename=`dbfile_`+(4294967295*Math.random()>>>0),e!=null){var t=this.filename,n=`/`,r=t;if(n&&(n=typeof n==`string`?n:Re(n),r=t?ge(n+`/`+t):n),t=Ae(!0,!0),r=Qe(r,t),e){if(typeof e==`string`){n=Array(e.length);for(var i=0,o=e.length;i<o;++i)n[i]=e.charCodeAt(i);e=n}at(r,t|146),n=st(r,577),dt(n,e,0,e.length,0),ct(n),at(r,t)}}this.handleError(c(this.filename,a)),this.db=M(a,`i32`),he(this.db),this.gb={},this.Sa={}}var a=Q(4),o=s.cwrap,c=o(`sqlite3_open`,`number`,[`string`,`number`]),l=o(`sqlite3_close_v2`,`number`,[`number`]),u=o(`sqlite3_exec`,`number`,[`number`,`string`,`number`,`number`,`number`]),d=o(`sqlite3_changes`,`number`,[`number`]),f=o(`sqlite3_prepare_v2`,`number`,[`number`,`string`,`number`,`number`,`number`]),p=o(`sqlite3_sql`,`string`,[`number`]),m=o(`sqlite3_normalized_sql`,`string`,[`number`]),h=o(`sqlite3_prepare_v2`,`number`,[`number`,`number`,`number`,`number`,`number`]),g=o(`sqlite3_bind_text`,`number`,[`number`,`number`,`number`,`number`,`number`]),_=o(`sqlite3_bind_blob`,`number`,[`number`,`number`,`number`,`number`,`number`]),v=o(`sqlite3_bind_double`,`number`,[`number`,`number`,`number`]),y=o(`sqlite3_bind_int`,`number`,[`number`,`number`,`number`]),b=o(`sqlite3_bind_parameter_index`,`number`,[`number`,`string`]),x=o(`sqlite3_step`,`number`,[`number`]),ee=o(`sqlite3_errmsg`,`string`,[`number`]),S=o(`sqlite3_column_count`,`number`,[`number`]),w=o(`sqlite3_data_count`,`number`,[`number`]),T=o(`sqlite3_column_double`,`number`,[`number`,`number`]),E=o(`sqlite3_column_text`,`string`,[`number`,`number`]),D=o(`sqlite3_column_blob`,`number`,[`number`,`number`]),te=o(`sqlite3_column_bytes`,`number`,[`number`,`number`]),ne=o(`sqlite3_column_type`,`number`,[`number`,`number`]),O=o(`sqlite3_column_name`,`string`,[`number`,`number`]),re=o(`sqlite3_reset`,`number`,[`number`]),k=o(`sqlite3_clear_bindings`,`number`,[`number`]),ie=o(`sqlite3_finalize`,`number`,[`number`]),ae=o(`sqlite3_create_function_v2`,`number`,`number string number number number number number number number`.split(` `)),oe=o(`sqlite3_value_type`,`number`,[`number`]),se=o(`sqlite3_value_bytes`,`number`,[`number`]),ce=o(`sqlite3_value_text`,`string`,[`number`]),le=o(`sqlite3_value_blob`,`number`,[`number`]),ue=o(`sqlite3_value_double`,`number`,[`number`]),de=o(`sqlite3_result_double`,``,[`number`,`number`]),fe=o(`sqlite3_result_null`,``,[`number`]),A=o(`sqlite3_result_text`,``,[`number`,`string`,`number`,`number`]),j=o(`sqlite3_result_blob`,``,[`number`,`number`,`number`,`number`]),N=o(`sqlite3_result_int`,``,[`number`,`number`]),P=o(`sqlite3_result_error`,``,[`number`,`string`,`number`]),me=o(`sqlite3_aggregate_context`,`number`,[`number`,`number`]),he=o(`RegisterExtensionFunctions`,`number`,[`number`]),_e=o(`sqlite3_update_hook`,`number`,[`number`,`number`,`number`]);n.prototype.bind=function(e){if(!this.Qa)throw`Statement closed`;return this.reset(),Array.isArray(e)?this.Gb(e):typeof e==`object`&&e?this.Hb(e):!0},n.prototype.step=function(){if(!this.Qa)throw`Statement closed`;this.Oa=1;var e=x(this.Qa);switch(e){case 100:return!0;case 101:return!1;default:throw this.db.handleError(e)}},n.prototype.Ab=function(e){return e??(e=this.Oa,this.Oa+=1),T(this.Qa,e)},n.prototype.Ob=function(e){if(e??(e=this.Oa,this.Oa+=1),e=E(this.Qa,e),typeof BigInt!=`function`)throw Error(`BigInt is not supported`);return BigInt(e)},n.prototype.Tb=function(e){return e??(e=this.Oa,this.Oa+=1),E(this.Qa,e)},n.prototype.getBlob=function(e){e??(e=this.Oa,this.Oa+=1);var t=te(this.Qa,e);e=D(this.Qa,e);for(var n=new Uint8Array(t),r=0;r<t;r+=1)n[r]=C[e+r];return n},n.prototype.get=function(e,t){t||={},e!=null&&this.bind(e)&&this.step(),e=[];for(var n=w(this.Qa),r=0;r<n;r+=1)switch(ne(this.Qa,r)){case 1:var i=t.useBigInt?this.Ob(r):this.Ab(r);e.push(i);break;case 2:e.push(this.Ab(r));break;case 3:e.push(this.Tb(r));break;case 4:e.push(this.getBlob(r));break;default:e.push(null)}return e},n.prototype.qb=function(){for(var e=[],t=S(this.Qa),n=0;n<t;n+=1)e.push(O(this.Qa,n));return e},n.prototype.zb=function(e,t){e=this.get(e,t),t=this.qb();for(var n={},r=0;r<t.length;r+=1)n[t[r]]=e[r];return n},n.prototype.Sb=function(){return p(this.Qa)},n.prototype.Pb=function(){return m(this.Qa)},n.prototype.run=function(e){return e!=null&&this.bind(e),this.step(),this.reset()},n.prototype.wb=function(e,t){t??(t=this.Oa,this.Oa+=1),e=Et(e),this.mb.push(e),this.db.handleError(g(this.Qa,t,e,-1,0))},n.prototype.Fb=function(e,t){t??(t=this.Oa,this.Oa+=1);var n=Mt(e.length);C.set(e,n),this.mb.push(n),this.db.handleError(_(this.Qa,t,n,e.length,0))},n.prototype.vb=function(e,t){t??(t=this.Oa,this.Oa+=1),this.db.handleError((e===(e|0)?y:v)(this.Qa,t,e))},n.prototype.Ib=function(e){e??(e=this.Oa,this.Oa+=1),_(this.Qa,e,0,0,0)},n.prototype.xb=function(e,t){switch(t??(t=this.Oa,this.Oa+=1),typeof e){case`string`:this.wb(e,t);return;case`number`:this.vb(e,t);return;case`bigint`:this.wb(e.toString(),t);return;case`boolean`:this.vb(e+0,t);return;case`object`:if(e===null){this.Ib(t);return}if(e.length!=null){this.Fb(e,t);return}}throw`Wrong API use : tried to bind a value of an unknown type (`+e+`).`},n.prototype.Hb=function(e){var t=this;return Object.keys(e).forEach(function(n){var r=b(t.Qa,n);r!==0&&t.xb(e[n],r)}),!0},n.prototype.Gb=function(e){for(var t=0;t<e.length;t+=1)this.xb(e[t],t+1);return!0},n.prototype.reset=function(){return this.freemem(),k(this.Qa)===0&&re(this.Qa)===0},n.prototype.freemem=function(){for(var e;(e=this.mb.pop())!==void 0;)Nt(e)},n.prototype.Ya=function(){this.freemem();var e=ie(this.Qa)===0;return delete this.db.gb[this.Qa],this.Qa=0,e},r.prototype.next=function(){if(this.fb===null)return{done:!0};if(this.$a!==null&&(this.$a.Ya(),this.$a=null),!this.db.db)throw this.ob(),Error(`Database closed`);var e=Lt(),t=Q(4);pe(a),pe(t);try{this.db.handleError(h(this.db.db,this.lb,-1,a,t)),this.lb=M(t,`i32`);var r=M(a,`i32`);return r===0?(this.ob(),{done:!0}):(this.$a=new n(r,this.db),this.db.gb[r]=this.$a,{value:this.$a,done:!1})}catch(e){throw this.sb=F(this.lb),this.ob(),e}finally{It(e)}},r.prototype.ob=function(){Nt(this.fb),this.fb=null},r.prototype.Qb=function(){return this.sb===null?F(this.lb):this.sb},typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`&&(r.prototype[Symbol.iterator]=function(){return this}),i.prototype.run=function(e,t){if(!this.db)throw`Database closed`;if(t){e=this.tb(e,t);try{e.step()}finally{e.Ya()}}else this.handleError(u(this.db,e,0,0,a));return this},i.prototype.exec=function(e,t,r){if(!this.db)throw`Database closed`;var i=null,o=null,s=null;try{s=o=Et(e);var c=Q(4);for(e=[];M(s,`i8`)!==0;){pe(a),pe(c),this.handleError(h(this.db,s,-1,a,c));var l=M(a,`i32`);if(s=M(c,`i32`),l!==0){var u=null;for(i=new n(l,this),t!=null&&i.bind(t);i.step();)u===null&&(u={columns:i.qb(),values:[]},e.push(u)),u.values.push(i.get(null,r));i.Ya()}}return e}catch(e){throw i&&i.Ya(),e}finally{o&&Nt(o)}},i.prototype.Mb=function(e,t,n,r,i){typeof t==`function`&&(r=n,n=t,t=void 0),e=this.tb(e,t);try{for(;e.step();)n(e.zb(null,i))}finally{e.Ya()}if(typeof r==`function`)return r()},i.prototype.tb=function(e,t){if(pe(a),this.handleError(f(this.db,e,-1,a,0)),e=M(a,`i32`),e===0)throw`Nothing to prepare`;var r=new n(e,this);return t!=null&&r.bind(t),this.gb[e]=r},i.prototype.Ub=function(e){return new r(e,this)},i.prototype.Nb=function(){Object.values(this.gb).forEach(function(e){e.Ya()}),Object.values(this.Sa).forEach(Z),this.Sa={},this.handleError(l(this.db));var e=ft(this.filename);return this.handleError(c(this.filename,a)),this.db=M(a,`i32`),he(this.db),e},i.prototype.close=function(){this.db!==null&&(Object.values(this.gb).forEach(function(e){e.Ya()}),Object.values(this.Sa).forEach(Z),this.Sa={},this.Za&&=(Z(this.Za),void 0),this.handleError(l(this.db)),nt(`/`+this.filename),this.db=null)},i.prototype.handleError=function(e){if(e===0)return null;throw e=ee(this.db),Error(e)},i.prototype.Rb=function(){return d(this.db)},i.prototype.Kb=function(n,r){Object.prototype.hasOwnProperty.call(this.Sa,n)&&(Z(this.Sa[n]),delete this.Sa[n]);var i=jt(function(n,i,a){i=t(i,a);try{var o=r.apply(null,i)}catch(e){P(n,e,-1);return}e(n,o)},`viii`);return this.Sa[n]=i,this.handleError(ae(this.db,n,r.length,1,0,i,0,0,0)),this},i.prototype.Jb=function(n,r){var i=r.init||function(){return null},a=r.finalize||function(e){return e},o=r.step;if(!o)throw`An aggregate function must have a step function in `+n;var s={};Object.hasOwnProperty.call(this.Sa,n)&&(Z(this.Sa[n]),delete this.Sa[n]),r=n+`__finalize`,Object.hasOwnProperty.call(this.Sa,r)&&(Z(this.Sa[r]),delete this.Sa[r]);var c=jt(function(e,n,r){var a=me(e,1);Object.hasOwnProperty.call(s,a)||(s[a]=i()),n=t(n,r),n=[s[a]].concat(n);try{s[a]=o.apply(null,n)}catch(t){delete s[a],P(e,t,-1)}},`viii`),l=jt(function(t){var n=me(t,1);try{var r=a(s[n])}catch(e){delete s[n],P(t,e,-1);return}e(t,r),delete s[n]},`vi`);return this.Sa[n]=c,this.Sa[r]=l,this.handleError(ae(this.db,n,o.length-1,1,0,0,c,l,0)),this},i.prototype.Zb=function(e){return this.Za&&=(_e(this.db,0,0),Z(this.Za),void 0),e?(this.Za=jt(function(t,n,r,i,a){switch(n){case 18:t=`insert`;break;case 23:t=`update`;break;case 9:t=`delete`;break;default:throw`unknown operationCode in updateHook callback: `+n}if(r=F(r),i=F(i),a>2**53-1)throw`rowId too big to fit inside a Number`;e(t,r,i,Number(a))},`viiiij`),_e(this.db,this.Za,0),this):this},n.prototype.bind=n.prototype.bind,n.prototype.step=n.prototype.step,n.prototype.get=n.prototype.get,n.prototype.getColumnNames=n.prototype.qb,n.prototype.getAsObject=n.prototype.zb,n.prototype.getSQL=n.prototype.Sb,n.prototype.getNormalizedSQL=n.prototype.Pb,n.prototype.run=n.prototype.run,n.prototype.reset=n.prototype.reset,n.prototype.freemem=n.prototype.freemem,n.prototype.free=n.prototype.Ya,r.prototype.next=r.prototype.next,r.prototype.getRemainingSQL=r.prototype.Qb,i.prototype.run=i.prototype.run,i.prototype.exec=i.prototype.exec,i.prototype.each=i.prototype.Mb,i.prototype.prepare=i.prototype.tb,i.prototype.iterateStatements=i.prototype.Ub,i.prototype.export=i.prototype.Nb,i.prototype.close=i.prototype.close,i.prototype.handleError=i.prototype.handleError,i.prototype.getRowsModified=i.prototype.Rb,i.prototype.create_function=i.prototype.Kb,i.prototype.create_aggregate=i.prototype.Jb,i.prototype.updateHook=i.prototype.Zb,s.Database=i};var d=`./this.program`,f=(e,t)=>{throw t},p=globalThis.document?.currentScript?.src;typeof __filename<`u`?p=__filename:l&&(p=self.location.href);var m=``,h,g;if(u){var _=t(`node:fs`);m=__dirname+`/`,g=e=>(e=S(e)?new URL(e):e,_.readFileSync(e)),h=async e=>(e=S(e)?new URL(e):e,_.readFileSync(e,void 0)),1<process.argv.length&&(d=process.argv[1].replace(/\\/g,`/`)),process.argv.slice(2),n!==void 0&&(n.exports=s),f=(e,t)=>{throw process.exitCode=e,t}}else if(c||l){try{m=new URL(`.`,p).href}catch{}l&&(g=e=>{var t=new XMLHttpRequest;return t.open(`GET`,e,!1),t.responseType=`arraybuffer`,t.send(null),new Uint8Array(t.response)}),h=async e=>{if(S(e))return new Promise((t,n)=>{var r=new XMLHttpRequest;r.open(`GET`,e,!0),r.responseType=`arraybuffer`,r.onload=()=>{r.status==200||r.status==0&&r.response?t(r.response):n(r.status)},r.onerror=n,r.send(null)});var t=await fetch(e,{credentials:`same-origin`});if(t.ok)return t.arrayBuffer();throw Error(t.status+` : `+t.url)}}var v=console.log.bind(console),y=console.error.bind(console),b,x=!1,ee,S=e=>e.startsWith(`file://`),C,w,T,E,D,te,ne,O;function re(){var e=Rt.buffer;C=new Int8Array(e),T=new Int16Array(e),w=new Uint8Array(e),new Uint16Array(e),E=new Int32Array(e),D=new Uint32Array(e),te=new Float32Array(e),ne=new Float64Array(e),O=new BigInt64Array(e),new BigUint64Array(e)}function k(e){throw s.onAbort?.(e),e=`Aborted(`+e+`)`,y(e),x=!0,new WebAssembly.RuntimeError(e+`. Build with -sASSERTIONS for more info.`)}var ie;async function ae(e){if(!b)try{var t=await h(e);return new Uint8Array(t)}catch{}if(e==ie&&b)e=new Uint8Array(b);else if(g)e=g(e);else throw`both async and sync fetching of the wasm failed`;return e}async function oe(e,t){try{var n=await ae(e);return await WebAssembly.instantiate(n,t)}catch(e){y(`failed to asynchronously prepare wasm: ${e}`),k(e)}}async function se(e){var t=ie;if(!b&&!S(t)&&!u)try{var n=fetch(t,{credentials:`same-origin`});return await WebAssembly.instantiateStreaming(n,e)}catch(e){y(`wasm streaming compile failed: ${e}`),y(`falling back to ArrayBuffer instantiation`)}return oe(t,e)}class ce{name=`ExitStatus`;constructor(e){this.message=`Program terminated with exit(${e})`,this.status=e}}var le=e=>{for(;0<e.length;)e.shift()(s)},ue=[],de=[],fe=()=>{var e=s.preRun.shift();de.push(e)},A=0,j=null;function M(e,t=`i8`){switch(t.endsWith(`*`)&&(t=`*`),t){case`i1`:return C[e];case`i8`:return C[e];case`i16`:return T[e>>1];case`i32`:return E[e>>2];case`i64`:return O[e>>3];case`float`:return te[e>>2];case`double`:return ne[e>>3];case`*`:return D[e>>2];default:k(`invalid type for getValue: ${t}`)}}var N=!0;function pe(e){var t=`i32`;switch(t.endsWith(`*`)&&(t=`*`),t){case`i1`:C[e]=0;break;case`i8`:C[e]=0;break;case`i16`:T[e>>1]=0;break;case`i32`:E[e>>2]=0;break;case`i64`:O[e>>3]=BigInt(0);break;case`float`:te[e>>2]=0;break;case`double`:ne[e>>3]=0;break;case`*`:D[e>>2]=0;break;default:k(`invalid type for setValue: ${t}`)}}var P=new TextDecoder,me=(e,t,n,r)=>{if(n=t+n,r)return n;for(;e[t]&&!(t>=n);)++t;return t},F=(e,t,n)=>e?P.decode(w.subarray(e,me(w,e,t,n))):``,he=(e,t)=>{for(var n=0,r=e.length-1;0<=r;r--){var i=e[r];i===`.`?e.splice(r,1):i===`..`?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n;n--)e.unshift(`..`);return e},ge=e=>{var t=e.charAt(0)===`/`,n=e.slice(-1)===`/`;return(e=he(e.split(`/`).filter(e=>!!e),!t).join(`/`))||t||(e=`.`),e&&n&&(e+=`/`),(t?`/`:``)+e},_e=e=>{var t=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(e).slice(1);return e=t[0],t=t[1],!e&&!t?`.`:(t&&=t.slice(0,-1),e+t)},ve=e=>e&&e.match(/([^\/]+|\/)\/*$/)[1],ye=()=>{if(u){var e=t(`node:crypto`);return t=>e.randomFillSync(t)}return e=>crypto.getRandomValues(e)},be=e=>{(be=ye())(e)},xe=(...e)=>{for(var t=``,n=!1,r=e.length-1;-1<=r&&!n;r--){if(n=0<=r?e[r]:`/`,typeof n!=`string`)throw TypeError(`Arguments to path.resolve must be strings`);if(!n)return``;t=n+`/`+t,n=n.charAt(0)===`/`}return t=he(t.split(`/`).filter(e=>!!e),!n).join(`/`),(n?`/`:``)+t||`.`},Se=e=>{var t=me(e,0);return P.decode(e.buffer?e.subarray(0,t):new Uint8Array(e.slice(0,t)))},Ce=[],we=e=>{for(var t=0,n=0;n<e.length;++n){var r=e.charCodeAt(n);127>=r?t++:2047>=r?t+=2:55296<=r&&57343>=r?(t+=4,++n):t+=3}return t},I=(e,t,n,r)=>{if(!(0<r))return 0;var i=n;r=n+r-1;for(var a=0;a<e.length;++a){var o=e.codePointAt(a);if(127>=o){if(n>=r)break;t[n++]=o}else if(2047>=o){if(n+1>=r)break;t[n++]=192|o>>6,t[n++]=128|o&63}else if(65535>=o){if(n+2>=r)break;t[n++]=224|o>>12,t[n++]=128|o>>6&63,t[n++]=128|o&63}else{if(n+3>=r)break;t[n++]=240|o>>18,t[n++]=128|o>>12&63,t[n++]=128|o>>6&63,t[n++]=128|o&63,a++}}return t[n]=0,n-i},Te=[];function Ee(e,t){Te[e]={input:[],output:[],eb:t},Ye(e,De)}var De={open(e){var t=Te[e.node.rdev];if(!t)throw new B(43);e.tty=t,e.seekable=!1},close(e){e.tty.eb.fsync(e.tty)},fsync(e){e.tty.eb.fsync(e.tty)},read(e,t,n,r){if(!e.tty||!e.tty.eb.Bb)throw new B(60);for(var i=0,a=0;a<r;a++){try{var o=e.tty.eb.Bb(e.tty)}catch{throw new B(29)}if(o===void 0&&i===0)throw new B(6);if(o==null)break;i++,t[n+a]=o}return i&&(e.node.atime=Date.now()),i},write(e,t,n,r){if(!e.tty||!e.tty.eb.ub)throw new B(60);try{for(var i=0;i<r;i++)e.tty.eb.ub(e.tty,t[n+i])}catch{throw new B(29)}return r&&(e.node.mtime=e.node.ctime=Date.now()),i}},Oe={Bb(){a:{if(!Ce.length){var e=null;if(u){var t=Buffer.alloc(256),n=0,r=process.stdin.fd;try{n=_.readSync(r,t,0,256)}catch(e){if(e.toString().includes(`EOF`))n=0;else throw e}0<n&&(e=t.slice(0,n).toString(`utf-8`))}else globalThis.window?.prompt&&(e=window.prompt(`Input: `),e!==null&&(e+=`
|
|
2
2
|
`));if(!e){e=null;break a}t=Array(we(e)+1),e=I(e,t,0,t.length),t.length=e,Ce=t}e=Ce.shift()}return e},ub(e,t){t===null||t===10?(v(Se(e.output)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){0<e.output?.length&&(v(Se(e.output)),e.output=[])},hc(){return{bc:25856,dc:5,ac:191,cc:35387,$b:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},ic(){return 0},jc(){return[24,80]}},ke={ub(e,t){t===null||t===10?(y(Se(e.output)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){0<e.output?.length&&(y(Se(e.output)),e.output=[])}},L={Wa:null,Xa(){return L.createNode(null,`/`,16895,0)},createNode(e,t,n,r){if((n&61440)==24576||(n&61440)==4096)throw new B(63);return L.Wa||={dir:{node:{Ta:L.La.Ta,Ua:L.La.Ua,lookup:L.La.lookup,ib:L.La.ib,rename:L.La.rename,unlink:L.La.unlink,rmdir:L.La.rmdir,readdir:L.La.readdir,symlink:L.La.symlink},stream:{Va:L.Ma.Va}},file:{node:{Ta:L.La.Ta,Ua:L.La.Ua},stream:{Va:L.Ma.Va,read:L.Ma.read,write:L.Ma.write,jb:L.Ma.jb,kb:L.Ma.kb}},link:{node:{Ta:L.La.Ta,Ua:L.La.Ua,readlink:L.La.readlink},stream:{}},yb:{node:{Ta:L.La.Ta,Ua:L.La.Ua},stream:Je}},n=Ve(e,t,n,r),U(n.mode)?(n.La=L.Wa.dir.node,n.Ma=L.Wa.dir.stream,n.Na={}):(n.mode&61440)==32768?(n.La=L.Wa.file.node,n.Ma=L.Wa.file.stream,n.Ra=0,n.Na=null):(n.mode&61440)==40960?(n.La=L.Wa.link.node,n.Ma=L.Wa.link.stream):(n.mode&61440)==8192&&(n.La=L.Wa.yb.node,n.Ma=L.Wa.yb.stream),n.atime=n.mtime=n.ctime=Date.now(),e&&(e.Na[t]=n,e.atime=e.mtime=e.ctime=n.atime),n},fc(e){return e.Na?e.Na.subarray?e.Na.subarray(0,e.Ra):new Uint8Array(e.Na):new Uint8Array},La:{Ta(e){var t={};return t.dev=(e.mode&61440)==8192?e.id:1,t.ino=e.id,t.mode=e.mode,t.nlink=1,t.uid=0,t.gid=0,t.rdev=e.rdev,t.size=U(e.mode)?4096:(e.mode&61440)==32768?e.Ra:(e.mode&61440)==40960?e.link.length:0,t.atime=new Date(e.atime),t.mtime=new Date(e.mtime),t.ctime=new Date(e.ctime),t.blksize=4096,t.blocks=Math.ceil(t.size/t.blksize),t},Ua(e,t){for(var n of[`mode`,`atime`,`mtime`,`ctime`])t[n]!=null&&(e[n]=t[n]);t.size!==void 0&&(t=t.size,e.Ra!=t&&(t==0?(e.Na=null,e.Ra=0):(n=e.Na,e.Na=new Uint8Array(t),n&&e.Na.set(n.subarray(0,Math.min(t,e.Ra))),e.Ra=t)))},lookup(){throw L.nb||(L.nb=new B(44),L.nb.stack=`<generic error, no stack>`),L.nb},ib(e,t,n,r){return L.createNode(e,t,n,r)},rename(e,t,n){try{var r=H(t,n)}catch{}if(r){if(U(e.mode))for(var i in r.Na)throw new B(55);Be(r)}delete e.parent.Na[e.name],t.Na[n]=e,e.name=n,t.ctime=t.mtime=e.parent.ctime=e.parent.mtime=Date.now()},unlink(e,t){delete e.Na[t],e.ctime=e.mtime=Date.now()},rmdir(e,t){var n=H(e,t),r;for(r in n.Na)throw new B(55);delete e.Na[t],e.ctime=e.mtime=Date.now()},readdir(e){return[`.`,`..`,...Object.keys(e.Na)]},symlink(e,t,n){return e=L.createNode(e,t,41471,0),e.link=n,e},readlink(e){if((e.mode&61440)!=40960)throw new B(28);return e.link}},Ma:{read(e,t,n,r,i){var a=e.node.Na;if(i>=e.node.Ra)return 0;if(e=Math.min(e.node.Ra-i,r),8<e&&a.subarray)t.set(a.subarray(i,i+e),n);else for(r=0;r<e;r++)t[n+r]=a[i+r];return e},write(e,t,n,r,i,a){if(t.buffer===C.buffer&&(a=!1),!r)return 0;if(e=e.node,e.mtime=e.ctime=Date.now(),t.subarray&&(!e.Na||e.Na.subarray)){if(a)return e.Na=t.subarray(n,n+r),e.Ra=r;if(e.Ra===0&&i===0)return e.Na=t.slice(n,n+r),e.Ra=r;if(i+r<=e.Ra)return e.Na.set(t.subarray(n,n+r),i),r}a=i+r;var o=e.Na?e.Na.length:0;if(o>=a||(a=Math.max(a,o*(1048576>o?2:1.125)>>>0),o!=0&&(a=Math.max(a,256)),o=e.Na,e.Na=new Uint8Array(a),0<e.Ra&&e.Na.set(o.subarray(0,e.Ra),0)),e.Na.subarray&&t.subarray)e.Na.set(t.subarray(n,n+r),i);else for(a=0;a<r;a++)e.Na[i+a]=t[n+a];return e.Ra=Math.max(e.Ra,i+r),r},Va(e,t,n){if(n===1?t+=e.position:n===2&&(e.node.mode&61440)==32768&&(t+=e.node.Ra),0>t)throw new B(28);return t},jb(e,t,n,r,i){if((e.node.mode&61440)!=32768)throw new B(43);if(e=e.node.Na,i&2||!e||e.buffer!==C.buffer){i=!0,r=65536*Math.ceil(t/65536);var a=Pt(65536,r);if(a&&w.fill(0,a,a+r),r=a,!r)throw new B(48);e&&((0<n||n+t<e.length)&&(e=e.subarray?e.subarray(n,n+t):Array.prototype.slice.call(e,n,n+t)),C.set(e,r))}else i=!1,r=e.byteOffset;return{Xb:r,Eb:i}},kb(e,t,n,r){return L.Ma.write(e,t,0,r,n,!1),0}}},Ae=(e,t)=>{var n=0;return e&&(n|=365),t&&(n|=146),n},je=null,Me={},R=[],Ne=1,z=null,Pe=!1,Fe=!0,B=class{name=`ErrnoError`;constructor(e){this.Pa=e}},Ie=class{hb={};node=null;get flags(){return this.hb.flags}set flags(e){this.hb.flags=e}get position(){return this.hb.position}set position(e){this.hb.position=e}},Le=class{La={};Ma={};bb=null;constructor(e,t,n,r){e||=this,this.parent=e,this.Xa=e.Xa,this.id=Ne++,this.name=t,this.mode=n,this.rdev=r,this.atime=this.mtime=this.ctime=Date.now()}get read(){return(this.mode&365)==365}set read(e){e?this.mode|=365:this.mode&=-366}get write(){return(this.mode&146)==146}set write(e){e?this.mode|=146:this.mode&=-147}};function V(e,t={}){if(!e)throw new B(44);t.pb??=!0,e.charAt(0)===`/`||(e=`//`+e);var n=0;a:for(;40>n;n++){e=e.split(`/`).filter(e=>!!e);for(var r=je,i=`/`,a=0;a<e.length;a++){var o=a===e.length-1;if(o&&t.parent)break;if(e[a]!==`.`){if(e[a]===`..`){if(i=_e(i),r===r.parent){e=i+`/`+e.slice(a+1).join(`/`),n--;continue a}r=r.parent}else{i=ge(i+`/`+e[a]);try{r=H(r,e[a])}catch(e){if(e?.Pa===44&&o&&t.Wb)return{path:i};throw e}if(!r.bb||o&&!t.pb||(r=r.bb.root),(r.mode&61440)==40960&&(!o||t.ab)){if(!r.La.readlink)throw new B(52);r=r.La.readlink(r),r.charAt(0)===`/`||(r=_e(i)+`/`+r),e=r+`/`+e.slice(a+1).join(`/`);continue a}}}}return{path:i,node:r}}throw new B(32)}function Re(e){for(var t;;){if(e===e.parent)return e=e.Xa.Db,t?e[e.length-1]===`/`?e+t:`${e}/${t}`:e;t=t?`${e.name}/${t}`:e.name,e=e.parent}}function ze(e,t){for(var n=0,r=0;r<t.length;r++)n=(n<<5)-n+t.charCodeAt(r)|0;return(e+n>>>0)%z.length}function Be(e){var t=ze(e.parent.id,e.name);if(z[t]===e)z[t]=e.cb;else for(t=z[t];t;){if(t.cb===e){t.cb=e.cb;break}t=t.cb}}function H(e,t){var n=U(e.mode)?(n=W(e,`x`))?n:e.La.lookup?0:2:54;if(n)throw new B(n);for(n=z[ze(e.id,t)];n;n=n.cb){var r=n.name;if(n.parent.id===e.id&&r===t)return n}return e.La.lookup(e,t)}function Ve(e,t,n,r){return e=new Le(e,t,n,r),t=ze(e.parent.id,e.name),e.cb=z[t],z[t]=e}function U(e){return(e&61440)==16384}function W(e,t){return Fe?0:t.includes(`r`)&&!(e.mode&292)||t.includes(`w`)&&!(e.mode&146)||t.includes(`x`)&&!(e.mode&73)?2:0}function He(e,t){if(!U(e.mode))return 54;try{return H(e,t),20}catch{}return W(e,`wx`)}function Ue(e,t,n){try{var r=H(e,t)}catch(e){return e.Pa}if(e=W(e,`wx`))return e;if(n){if(!U(r.mode))return 54;if(r===r.parent||Re(r)===`/`)return 10}else if(U(r.mode))return 31;return 0}function We(e){if(!e)throw new B(63);return e}function G(e){if(e=R[e],!e)throw new B(8);return e}function Ge(e,t=-1){if(e=Object.assign(new Ie,e),t==-1)a:{for(t=0;4096>=t;t++)if(!R[t])break a;throw new B(33)}return e.fd=t,R[t]=e}function Ke(e,t=-1){return e=Ge(e,t),e.Ma?.ec?.(e),e}function qe(e,t,n){var r=e?.Ma.Ua;e=r?e:t,r??=t.La.Ua,We(r),r(e,n)}var Je={open(e){e.Ma=Me[e.node.rdev].Ma,e.Ma.open?.(e)},Va(){throw new B(70)}};function Ye(e,t){Me[e]={Ma:t}}function Xe(e,t){var n=t===`/`;if(n&&je)throw new B(10);if(!n&&t){var r=V(t,{pb:!1});if(t=r.path,r=r.node,r.bb)throw new B(10);if(!U(r.mode))throw new B(54)}t={type:e,kc:{},Db:t,Vb:[]},e=e.Xa(t),e.Xa=t,t.root=e,n?je=e:r&&(r.bb=t,r.Xa&&r.Xa.Vb.push(t))}function Ze(e,t,n){var r=V(e,{parent:!0}).node;if(e=ve(e),!e)throw new B(28);if(e===`.`||e===`..`)throw new B(20);var i=He(r,e);if(i)throw new B(i);if(!r.La.ib)throw new B(63);return r.La.ib(r,e,t,n)}function Qe(e,t=438){return Ze(e,t&4095|32768,0)}function K(e,t=511){return Ze(e,t&1023|16384,0)}function $e(e,t,n){n===void 0&&(n=t,t=438),Ze(e,t|8192,n)}function et(e,t){if(!xe(e))throw new B(44);var n=V(t,{parent:!0}).node;if(!n)throw new B(44);t=ve(t);var r=He(n,t);if(r)throw new B(r);if(!n.La.symlink)throw new B(63);n.La.symlink(n,t,e)}function tt(e){var t=V(e,{parent:!0}).node;e=ve(e);var n=H(t,e),r=Ue(t,e,!0);if(r)throw new B(r);if(!t.La.rmdir)throw new B(63);if(n.bb)throw new B(10);t.La.rmdir(t,e),Be(n)}function nt(e){var t=V(e,{parent:!0}).node;if(!t)throw new B(44);e=ve(e);var n=H(t,e),r=Ue(t,e,!1);if(r)throw new B(r);if(!t.La.unlink)throw new B(63);if(n.bb)throw new B(10);t.La.unlink(t,e),Be(n)}function rt(e,t){return e=V(e,{ab:!t}).node,We(e.La.Ta)(e)}function it(e,t,n,r){qe(e,t,{mode:n&4095|t.mode&-4096,ctime:Date.now(),Lb:r})}function at(e,t){e=typeof e==`string`?V(e,{ab:!0}).node:e,it(null,e,t)}function ot(e,t,n){if(U(t.mode))throw new B(31);if((t.mode&61440)!=32768)throw new B(28);var r=W(t,`w`);if(r)throw new B(r);qe(e,t,{size:n,timestamp:Date.now()})}function st(e,t,n=438){if(e===``)throw new B(44);if(typeof t==`string`){var r={r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090}[t];if(r===void 0)throw Error(`Unknown file open mode: ${t}`);t=r}if(n=t&64?n&4095|32768:0,typeof e==`object`)r=e;else{var i=e.endsWith(`/`),a=V(e,{ab:!(t&131072),Wb:!0});r=a.node,e=a.path}if(a=!1,t&64){if(r){if(t&128)throw new B(20)}else{if(i)throw new B(31);r=Ze(e,n|511,0),a=!0}}if(!r)throw new B(44);if((r.mode&61440)==8192&&(t&=-513),t&65536&&!U(r.mode))throw new B(54);if(!a&&(r?(r.mode&61440)==40960?i=32:(i=[`r`,`w`,`rw`][t&3],t&512&&(i+=`w`),i=U(r.mode)&&(i!==`r`||t&576)?31:W(r,i)):i=44,i))throw new B(i);return t&512&&!a&&(i=r,i=typeof i==`string`?V(i,{ab:!0}).node:i,ot(null,i,0)),t=Ge({node:r,path:Re(r),flags:t&-131713,seekable:!0,position:0,Ma:r.Ma,Yb:[],error:!1}),t.Ma.open&&t.Ma.open(t),a&&at(r,n&511),t}function ct(e){if(e.fd===null)throw new B(8);e.rb&&=null;try{e.Ma.close&&e.Ma.close(e)}catch(e){throw e}finally{R[e.fd]=null}e.fd=null}function lt(e,t,n){if(e.fd===null)throw new B(8);if(!e.seekable||!e.Ma.Va)throw new B(70);if(n!=0&&n!=1&&n!=2)throw new B(28);e.position=e.Ma.Va(e,t,n),e.Yb=[]}function ut(e,t,n,r,i){if(0>r||0>i)throw new B(28);if(e.fd===null||(e.flags&2097155)==1)throw new B(8);if(U(e.node.mode))throw new B(31);if(!e.Ma.read)throw new B(28);var a=i!==void 0;if(!a)i=e.position;else if(!e.seekable)throw new B(70);return t=e.Ma.read(e,t,n,r,i),a||(e.position+=t),t}function dt(e,t,n,r,i){if(0>r||0>i)throw new B(28);if(e.fd===null||!(e.flags&2097155))throw new B(8);if(U(e.node.mode))throw new B(31);if(!e.Ma.write)throw new B(28);e.seekable&&e.flags&1024&<(e,0,2);var a=i!==void 0;if(!a)i=e.position;else if(!e.seekable)throw new B(70);return t=e.Ma.write(e,t,n,r,i,void 0),a||(e.position+=t),t}function ft(e){var t=t||0,n=`binary`;n!==`utf8`&&n!==`binary`&&k(`Invalid encoding type "${n}"`),t=st(e,t),e=rt(e).size;var r=new Uint8Array(e);return ut(t,r,0,e,0),n===`utf8`&&(r=Se(r)),ct(t),r}function q(e,t,n){e=ge(`/dev/`+e);var r=Ae(!!t,!!n);q.Cb??=64;var i=q.Cb++<<8|0;Ye(i,{open(e){e.seekable=!1},close(){n?.buffer?.length&&n(10)},read(e,n,r,i){for(var a=0,o=0;o<i;o++){try{var s=t()}catch{throw new B(29)}if(s===void 0&&a===0)throw new B(6);if(s==null)break;a++,n[r+o]=s}return a&&(e.node.atime=Date.now()),a},write(e,t,r,i){for(var a=0;a<i;a++)try{n(t[r+a])}catch{throw new B(29)}return i&&(e.node.mtime=e.node.ctime=Date.now()),a}}),$e(e,r,i)}var J={};function Y(e,t,n){if(t.charAt(0)===`/`)return t;if(e=e===-100?`/`:G(e).path,t.length==0){if(!n)throw new B(44);return e}return e+`/`+t}function pt(e,t){D[e>>2]=t.dev,D[e+4>>2]=t.mode,D[e+8>>2]=t.nlink,D[e+12>>2]=t.uid,D[e+16>>2]=t.gid,D[e+20>>2]=t.rdev,O[e+24>>3]=BigInt(t.size),E[e+32>>2]=4096,E[e+36>>2]=t.blocks;var n=t.atime.getTime(),r=t.mtime.getTime(),i=t.ctime.getTime();return O[e+40>>3]=BigInt(Math.floor(n/1e3)),D[e+48>>2]=n%1e3*1e6,O[e+56>>3]=BigInt(Math.floor(r/1e3)),D[e+64>>2]=r%1e3*1e6,O[e+72>>3]=BigInt(Math.floor(i/1e3)),D[e+80>>2]=i%1e3*1e6,O[e+88>>3]=BigInt(t.ino),0}var mt=void 0,ht=()=>{var e=E[mt>>2];return mt+=4,e},gt=0,_t=[0,31,60,91,121,152,182,213,244,274,305,335],vt=[0,31,59,90,120,151,181,212,243,273,304,334],yt={},bt=e=>{ee=e,N||0<gt||(s.onExit?.(e),x=!0),f(e,new ce(e))},xt=e=>{if(!x)try{e()}catch(e){e instanceof ce||e==`unwind`||f(1,e)}finally{if(!(N||0<gt))try{ee=e=ee,bt(e)}catch(e){e instanceof ce||e==`unwind`||f(1,e)}}},St={},Ct=()=>{if(!wt){var e={USER:`web_user`,LOGNAME:`web_user`,PATH:`/`,PWD:`/`,HOME:`/home/web_user`,LANG:(globalThis.navigator?.language??`C`).replace(`-`,`_`)+`.UTF-8`,_:d||`./this.program`},t;for(t in St)St[t]===void 0?delete e[t]:e[t]=St[t];var n=[];for(t in e)n.push(`${t}=${e[t]}`);wt=n}return wt},wt,Tt=(e,t,n,r)=>{var i={string:e=>{var t=0;if(e!=null&&e!==0){t=we(e)+1;var n=Q(t);I(e,w,n,t),t=n}return t},array:e=>{var t=Q(e.length);return C.set(e,t),t}};e=s[`_`+e];var a=[],o=0;if(r)for(var c=0;c<r.length;c++){var l=i[n[c]];l?(o===0&&(o=Lt()),a[c]=l(r[c])):a[c]=r[c]}return n=e(...a),n=function(e){return o!==0&&It(o),t===`string`?F(e):t===`boolean`?!!e:e}(n)},Et=e=>{var t=we(e)+1,n=Mt(t);return n&&I(e,w,n,t),n},X,Dt=[],Z=e=>{X.delete($.get(e)),$.set(e,null),Dt.push(e)},Ot=e=>{let t=e.length;return[t%128|128,t>>7,...e]},kt={i:127,p:127,j:126,f:125,d:124,e:111},At=e=>Ot(Array.from(e,e=>kt[e])),jt=(e,t)=>{if(!X){X=new WeakMap;var n=$.length;if(X)for(var r=0;r<0+n;r++){var i=$.get(r);i&&X.set(i,r)}}if(n=X.get(e)||0)return n;n=Dt.length?Dt.pop():$.grow(1);try{$.set(n,e)}catch(r){if(!(r instanceof TypeError))throw r;t=Uint8Array.of(0,97,115,109,1,0,0,0,1,...Ot([1,96,...At(t.slice(1)),...At(t[0]===`v`?``:t[0])]),2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),t=new WebAssembly.Module(t),t=new WebAssembly.Instance(t,{e:{f:e}}).exports.f,$.set(n,t)}return X.set(e,n),n};if(z=Array(4096),Xe(L,`/`),K(`/tmp`),K(`/home`),K(`/home/web_user`),(function(){K(`/dev`),Ye(259,{read:()=>0,write:(e,t,n,r)=>r,Va:()=>0}),$e(`/dev/null`,259),Ee(1280,Oe),Ee(1536,ke),$e(`/dev/tty`,1280),$e(`/dev/tty1`,1536);var e=new Uint8Array(1024),t=0,n=()=>(t===0&&(be(e),t=e.byteLength),e[--t]);q(`random`,n),q(`urandom`,n),K(`/dev/shm`),K(`/dev/shm/tmp`)})(),(function(){K(`/proc`);var e=K(`/proc/self`);K(`/proc/self/fd`),Xe({Xa(){var t=Ve(e,`fd`,16895,73);return t.Ma={Va:L.Ma.Va},t.La={lookup(e,t){e=+t;var n=G(e);return e={parent:null,Xa:{Db:`fake`},La:{readlink:()=>n.path},id:e+1},e.parent=e},readdir(){return Array.from(R.entries()).filter(([,e])=>e).map(([e])=>e.toString())}},t}},`/proc/self/fd`)})(),s.noExitRuntime&&(N=s.noExitRuntime),s.print&&(v=s.print),s.printErr&&(y=s.printErr),s.wasmBinary&&(b=s.wasmBinary),s.thisProgram&&(d=s.thisProgram),s.preInit)for(typeof s.preInit==`function`&&(s.preInit=[s.preInit]);0<s.preInit.length;)s.preInit.shift()();s.stackSave=()=>Lt(),s.stackRestore=e=>It(e),s.stackAlloc=e=>Q(e),s.cwrap=(e,t,n,r)=>{var i=!n||n.every(e=>e===`number`||e===`boolean`);return t!==`string`&&i&&!r?s[`_`+e]:(...r)=>Tt(e,t,n,r)},s.addFunction=jt,s.removeFunction=Z,s.UTF8ToString=F,s.stringToNewUTF8=Et,s.writeArrayToMemory=(e,t)=>{C.set(e,t)};var Mt,Nt,Pt,Ft,It,Q,Lt,Rt,$,zt={a:(e,t,n,r)=>k(`Assertion failed: ${F(e)}, at: `+[t?F(t):`unknown filename`,n,r?F(r):`unknown function`]),i:function(e,t){try{return e=F(e),at(e,t),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},L:function(e,t,n){try{if(t=F(t),t=Y(e,t),n&-8)return-28;var r=V(t,{ab:!0}).node;return r?(e=``,n&4&&(e+=`r`),n&2&&(e+=`w`),n&1&&(e+=`x`),e&&W(r,e)?-2:0):-44}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},j:function(e,t){try{var n=G(e);return it(n,n.node,t,!1),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},h:function(e){try{var t=G(e);return qe(t,t.node,{timestamp:Date.now(),Lb:!1}),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},b:function(e,t,n){mt=n;try{var r=G(e);switch(t){case 0:var i=ht();if(0>i)break;for(;R[i];)i++;return Ke(r,i).fd;case 1:case 2:return 0;case 3:return r.flags;case 4:return i=ht(),r.flags|=i,0;case 12:return i=ht(),T[i+0>>1]=2,0;case 13:case 14:return 0}return-28}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},g:function(e,t){try{var n=G(e),r=n.node,i=n.Ma.Ta;return e=i?n:r,i??=r.La.Ta,We(i),pt(t,i(e))}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},H:function(e,t){t=-9007199254740992>t||9007199254740992<t?NaN:Number(t);try{if(isNaN(t))return-61;var n=G(e);if(0>t||!(n.flags&2097155))throw new B(28);return ot(n,n.node,t),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},G:function(e,t){try{if(t===0)return-28;var n=we(`/`)+1;return t<n?-68:(I(`/`,w,e,t),n)}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},K:function(e,t){try{return e=F(e),pt(t,rt(e,!0))}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},C:function(e,t,n){try{return t=F(t),t=Y(e,t),K(t,n),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},J:function(e,t,n,r){try{t=F(t);var i=r&256;return t=Y(e,t,r&4096),pt(n,i?rt(t,!0):rt(t))}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},x:function(e,t,n,r){mt=r;try{t=F(t),t=Y(e,t);var i=r?ht():0;return st(t,n,i).fd}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},v:function(e,t,n,r){try{if(t=F(t),t=Y(e,t),0>=r)return-28;var i=V(t).node;if(!i)throw new B(44);if(!i.La.readlink)throw new B(28);var a=i.La.readlink(i),o=Math.min(r,we(a)),s=C[n+o];return I(a,w,n,r+1),C[n+o]=s,o}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},u:function(e){try{return e=F(e),tt(e),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},f:function(e,t){try{return e=F(e),pt(t,rt(e))}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},r:function(e,t,n){try{if(t=F(t),t=Y(e,t),n){if(n===512)tt(t);else return-28}else nt(t);return 0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},q:function(e,t,n){try{t=F(t),t=Y(e,t,!0);var r=Date.now(),i,a;if(n){var o=D[n>>2]+4294967296*E[n+4>>2],s=E[n+8>>2];i=s==1073741823?r:s==1073741822?null:1e3*o+s/1e6,n+=16,o=D[n>>2]+4294967296*E[n+4>>2],s=E[n+8>>2],a=s==1073741823?r:s==1073741822?null:1e3*o+s/1e6}else a=i=r;if((a??i)!==null){e=i;var c=V(t,{ab:!0}).node;We(c.La.Ua)(c,{atime:e,mtime:a})}return 0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},m:()=>k(``),l:()=>{N=!1,gt=0},A:function(e,t){e=-9007199254740992>e||9007199254740992<e?NaN:Number(e),e=new Date(1e3*e),E[t>>2]=e.getSeconds(),E[t+4>>2]=e.getMinutes(),E[t+8>>2]=e.getHours(),E[t+12>>2]=e.getDate(),E[t+16>>2]=e.getMonth(),E[t+20>>2]=e.getFullYear()-1900,E[t+24>>2]=e.getDay();var n=e.getFullYear();E[t+28>>2]=(n%4!=0||n%100==0&&n%400!=0?vt:_t)[e.getMonth()]+e.getDate()-1|0,E[t+36>>2]=-(60*e.getTimezoneOffset()),n=new Date(e.getFullYear(),6,1).getTimezoneOffset();var r=new Date(e.getFullYear(),0,1).getTimezoneOffset();E[t+32>>2]=(n!=r&&e.getTimezoneOffset()==Math.min(r,n))|0},y:function(e,t,n,r,i,a,o){i=-9007199254740992>i||9007199254740992<i?NaN:Number(i);try{var s=G(r);if(t&2&&!(n&2)&&(s.flags&2097155)!=2||(s.flags&2097155)==1)throw new B(2);if(!s.Ma.jb)throw new B(43);if(!e)throw new B(28);var c=s.Ma.jb(s,e,i,t,n),l=c.Xb;return E[a>>2]=c.Eb,D[o>>2]=l,0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},z:function(e,t,n,r,i,a){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);try{var o=G(i);if(n&2){if(n=a,(o.node.mode&61440)!=32768)throw new B(43);if(!(r&2)){var s=w.slice(e,e+t);o.Ma.kb&&o.Ma.kb(o,s,n,t,r)}}}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},n:(e,t)=>(yt[e]&&(clearTimeout(yt[e].id),delete yt[e]),t&&(yt[e]={id:setTimeout(()=>{delete yt[e],xt(()=>Ft(e,performance.now()))},t),lc:t}),0),B:(e,t,n,r)=>{var i=new Date().getFullYear(),a=new Date(i,0,1).getTimezoneOffset();i=new Date(i,6,1).getTimezoneOffset(),D[e>>2]=60*Math.max(a,i),E[t>>2]=Number(a!=i),t=e=>{var t=Math.abs(e);return`UTC${0<=e?`-`:`+`}${String(Math.floor(t/60)).padStart(2,`0`)}${String(t%60).padStart(2,`0`)}`},e=t(a),t=t(i),i<a?(I(e,w,n,17),I(t,w,r,17)):(I(e,w,r,17),I(t,w,n,17))},d:()=>Date.now(),s:()=>2147483648,c:()=>performance.now(),o:e=>{var t=w.length;if(e>>>=0,2147483648<e)return!1;for(var n=1;4>=n;n*=2){var r=t*(1+.2/n);r=Math.min(r,e+100663296);a:{r=(Math.min(2147483648,65536*Math.ceil(Math.max(e,r)/65536))-Rt.buffer.byteLength+65535)/65536|0;try{Rt.grow(r),re();var i=1;break a}catch{}i=void 0}if(i)return!0}return!1},E:(e,t)=>{var n=0,r=0,i;for(i of Ct()){var a=t+n;D[e+r>>2]=a,n+=I(i,w,a,1/0)+1,r+=4}return 0},F:(e,t)=>{var n=Ct();D[e>>2]=n.length,e=0;for(var r of n)e+=we(r)+1;return D[t>>2]=e,0},e:function(e){try{return ct(G(e)),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},p:function(e,t){try{var n=G(e);return C[t]=n.tty?2:U(n.mode)?3:(n.mode&61440)==40960?7:4,T[t+2>>1]=0,O[t+8>>3]=BigInt(0),O[t+16>>3]=BigInt(0),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},w:function(e,t,n,r){try{a:{var i=G(e);e=t;for(var a,o=t=0;o<n;o++){var s=D[e>>2],c=D[e+4>>2];e+=8;var l=ut(i,C,s,c,a);if(0>l){var u=-1;break a}if(t+=l,l<c)break;a!==void 0&&(a+=l)}u=t}return D[r>>2]=u,0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},D:function(e,t,n,r){t=-9007199254740992>t||9007199254740992<t?NaN:Number(t);try{if(isNaN(t))return 61;var i=G(e);return lt(i,t,n),O[r>>3]=BigInt(i.position),i.rb&&t===0&&n===0&&(i.rb=null),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},I:function(e){try{var t=G(e);return t.Ma?.fsync?.(t)}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},t:function(e,t,n,r){try{a:{var i=G(e);e=t;for(var a,o=t=0;o<n;o++){var s=D[e>>2],c=D[e+4>>2];e+=8;var l=dt(i,C,s,c,a);if(0>l){var u=-1;break a}if(t+=l,l<c)break;a!==void 0&&(a+=l)}u=t}return D[r>>2]=u,0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},k:bt};function Bt(){function e(){if(s.calledRun=!0,!x){if(!s.noFSInit&&!Pe){var e,t;Pe=!0,e??=s.stdin,t??=s.stdout,n??=s.stderr,e?q(`stdin`,e):et(`/dev/tty`,`/dev/stdin`),t?q(`stdout`,null,t):et(`/dev/tty`,`/dev/stdout`),n?q(`stderr`,null,n):et(`/dev/tty1`,`/dev/stderr`),st(`/dev/stdin`,0),st(`/dev/stdout`,1),st(`/dev/stderr`,1)}if(Vt.N(),Fe=!1,s.onRuntimeInitialized?.(),s.postRun)for(typeof s.postRun==`function`&&(s.postRun=[s.postRun]);s.postRun.length;){var n=s.postRun.shift();ue.push(n)}le(ue)}}if(0<A)j=Bt;else{if(s.preRun)for(typeof s.preRun==`function`&&(s.preRun=[s.preRun]);s.preRun.length;)fe();le(de),0<A?j=Bt:s.setStatus?(s.setStatus(`Running...`),setTimeout(()=>{setTimeout(()=>s.setStatus(``),1),e()},1)):e()}}var Vt;return(async function(){function e(e){return e=Vt=e.exports,s._sqlite3_free=e.P,s._sqlite3_value_text=e.Q,s._sqlite3_prepare_v2=e.R,s._sqlite3_step=e.S,s._sqlite3_reset=e.T,s._sqlite3_exec=e.U,s._sqlite3_finalize=e.V,s._sqlite3_column_name=e.W,s._sqlite3_column_text=e.X,s._sqlite3_column_type=e.Y,s._sqlite3_errmsg=e.Z,s._sqlite3_clear_bindings=e._,s._sqlite3_value_blob=e.$,s._sqlite3_value_bytes=e.aa,s._sqlite3_value_double=e.ba,s._sqlite3_value_int=e.ca,s._sqlite3_value_type=e.da,s._sqlite3_result_blob=e.ea,s._sqlite3_result_double=e.fa,s._sqlite3_result_error=e.ga,s._sqlite3_result_int=e.ha,s._sqlite3_result_int64=e.ia,s._sqlite3_result_null=e.ja,s._sqlite3_result_text=e.ka,s._sqlite3_aggregate_context=e.la,s._sqlite3_column_count=e.ma,s._sqlite3_data_count=e.na,s._sqlite3_column_blob=e.oa,s._sqlite3_column_bytes=e.pa,s._sqlite3_column_double=e.qa,s._sqlite3_bind_blob=e.ra,s._sqlite3_bind_double=e.sa,s._sqlite3_bind_int=e.ta,s._sqlite3_bind_text=e.ua,s._sqlite3_bind_parameter_index=e.va,s._sqlite3_sql=e.wa,s._sqlite3_normalized_sql=e.xa,s._sqlite3_changes=e.ya,s._sqlite3_close_v2=e.za,s._sqlite3_create_function_v2=e.Aa,s._sqlite3_update_hook=e.Ba,s._sqlite3_open=e.Ca,Mt=s._malloc=e.Da,Nt=s._free=e.Ea,s._RegisterExtensionFunctions=e.Fa,Pt=e.Ga,Ft=e.Ha,It=e.Ia,Q=e.Ja,Lt=e.Ka,Rt=e.M,$=e.O,re(),A--,s.monitorRunDependencies?.(A),A==0&&j&&(e=j,j=null,e()),Vt}A++,s.monitorRunDependencies?.(A);var t={a:zt};return s.instantiateWasm?new Promise(n=>{s.instantiateWasm(t,(t,r)=>{n(e(t,r))})}):(ie??=s.locateFile?s.locateFile(`sql-wasm.wasm`,m):m+`sql-wasm.wasm`,e((await se(t)).instance))})(),Bt(),a}),r)};typeof e==`object`&&typeof n==`object`?(n.exports=i,n.exports.default=i):typeof define==`function`&&define.amd?define([],function(){return i}):typeof e==`object`&&(e.Module=i)}))(),1);function y(e,t,n){switch(n.mode){case`list`:return x(e,t,n);case`csv`:return ee(e,t,n);case`json`:return T(e,t);case`line`:return E(e,t,n);case`column`:return D(e,t,n);case`table`:return te(e,t,n);case`markdown`:return ne(e,t,n);case`tabs`:return O(e,t,n);case`box`:return re(e,t,n);case`quote`:return k(e,t,n);case`html`:return ie(e,t,n);case`ascii`:return oe(e,t,n)}}function b(e,t){return e==null?t:e instanceof Uint8Array||Buffer.isBuffer(e)?Buffer.from(e).toString(`utf8`):typeof e==`number`&&!Number.isInteger(e)?e.toPrecision(17).replace(/\.?0+$/,``):String(e)}function x(e,t,n){let r=[];n.header&&e.length>0&&r.push(e.join(n.separator));for(let e of t)r.push(e.map(e=>b(e,n.nullValue)).join(n.separator));return r.length>0?`${r.join(n.newline)}${n.newline}`:``}function ee(e,t,n){let r=[];n.header&&e.length>0&&r.push(e.map(S).join(`,`));for(let e of t)r.push(e.map(e=>S(b(e,n.nullValue))).join(`,`));return r.length>0?`${r.join(`
|
|
3
3
|
`)}
|
|
4
4
|
`:``}function S(e){return e.includes(`,`)||e.includes(`"`)||e.includes(`'`)||e.includes(`
|
|
@@ -23,7 +23,7 @@ import{a as e,i as t,t as n}from"./rolldown-runtime-DPpTSio4.mjs";import"./chunk
|
|
|
23
23
|
`,exitCode:1};t.nullValue=e[++o]}else if(s===`-cmd`){if(o+1>=e.length)return{stdout:``,stderr:`sqlite3: Error: missing argument to -cmd
|
|
24
24
|
`,exitCode:1};t.cmd=e[++o]}else{if(s.startsWith(`-`))return{stdout:``,stderr:`sqlite3: Error: unknown option: ${s.startsWith(`--`)?s.slice(1):s}
|
|
25
25
|
Use -help for a list of options.
|
|
26
|
-
`,exitCode:1};n===null?n=s:r===null&&(r=s)}}return{options:t,database:n,sql:r,showVersion:i}}async function ue(){let e=new(await(r.runTrustedAsync(()=>(0,v.default)()))).Database;try{let t=e.exec(`SELECT sqlite_version()`);return t.length>0&&t[0].values.length>0?String(t[0].values[0][0]):`unknown`}finally{e.close()}}function de(e=f(h(import.meta.url))){let t=[p(e,`sqlite3-worker.js`),p(e,`../../commands/sqlite3/worker.js`)];(e.endsWith(`${m}commands${m}sqlite3`)||e.endsWith(`/commands/sqlite3`))&&t.push(p(e,`worker.js`)),t.push(p(e,`../../../dist/commands/sqlite3/worker.js`));for(let e of t)if(d(e))return e;throw Error(`sqlite3 worker not found. Run 'pnpm build' to compile the worker.`)}var fe={createWorker(e,t){return new
|
|
26
|
+
`,exitCode:1};n===null?n=s:r===null&&(r=s)}}return{options:t,database:n,sql:r,showVersion:i}}async function ue(){let e=new(await(r.runTrustedAsync(()=>(0,v.default)()))).Database;try{let t=e.exec(`SELECT sqlite_version()`);return t.length>0&&t[0].values.length>0?String(t[0].values[0][0]):`unknown`}finally{e.close()}}function de(e=f(h(import.meta.url))){let t=[p(e,`sqlite3-worker.js`),p(e,`../../commands/sqlite3/worker.js`)];(e.endsWith(`${m}commands${m}sqlite3`)||e.endsWith(`/commands/sqlite3`))&&t.push(p(e,`worker.js`)),t.push(p(e,`../../../dist/commands/sqlite3/worker.js`));for(let e of t)if(d(e))return e;throw Error(`sqlite3 worker not found. Run 'pnpm build' to compile the worker.`)}var fe={createWorker(e,t){return new _(e,{workerData:t})},findWorkerPath:de};function A(){return g(16).toString(`hex`)}function j(e,t){if(!e||typeof e!=`object`)return{success:!1,error:`Malformed worker response`};let n=e;return typeof n.protocolToken!=`string`||n.protocolToken!==t?{success:!1,error:`Malformed worker response: invalid protocol token`}:n.type===`security-violation`?{success:!1,error:`Security violation: ${typeof n.violation?.type==`string`?n.violation.type:`unknown`}`}:typeof n.success==`boolean`?n.success?Array.isArray(n.results)?typeof n.hasModifications==`boolean`?n.dbBuffer!==null&&n.dbBuffer!==void 0&&!(n.dbBuffer instanceof Uint8Array)?{success:!1,error:`Malformed worker response: invalid dbBuffer`}:{success:!0,results:n.results,hasModifications:n.hasModifications,dbBuffer:n.dbBuffer===void 0?null:n.dbBuffer,defenseStats:n.defenseStats}:{success:!1,error:`Malformed worker response: missing hasModifications flag`}:{success:!1,error:`Malformed worker response: missing results array`}:{success:!1,error:typeof n.error==`string`&&n.error.length>0?n.error:`Worker execution failed`}:{success:!1,error:`Malformed worker response: missing success flag`}}async function M(e,t,n){try{let s=de();return await new Promise((l,u)=>{let d=r.runTrusted(()=>fe.createWorker(s,e)),f=o(n,`sqlite3`,`worker timeout callback`,()=>{d.terminate(),l({success:!1,error:`Query timeout: execution exceeded ${t}ms limit`})}),p=a(()=>{try{f()}catch(e){let t=e instanceof Error?e.message:String(e);l({success:!1,error:c(t)})}},t),m=o(n,`sqlite3`,`worker message callback`,t=>{i(p),l(j(t,e.protocolToken))}),h=o(n,`sqlite3`,`worker error callback`,e=>{i(p),u(e)}),g=o(n,`sqlite3`,`worker exit callback`,e=>{i(p),e!==0&&l({success:!1,error:`Worker exited with code ${e}`})});d.on(`message`,e=>{try{m(e)}catch(e){i(p);let t=e instanceof Error?e.message:String(e);l({success:!1,error:c(t)})}}),d.on(`error`,e=>{try{h(e)}catch(e){i(p);let t=e instanceof Error?e.message:String(e);u(Error(c(t)))}}),d.on(`exit`,e=>{try{g(e)}catch(e){i(p);let t=e instanceof Error?e.message:String(e);l({success:!1,error:c(t)})}})})}catch(e){let t=c(e.message);throw Error(`sqlite3 worker failed to load: ${t}`)}}var N={name:`sqlite3`,async execute(e,t){if(u(e)||e.includes(`-help`))return l(ce);let n=le(e);if(`exitCode`in n)return n;let{options:r,database:i,sql:a,showVersion:o}=n;if(o)return{stdout:`${await ue()}
|
|
27
27
|
`,stderr:``,exitCode:0};if(!i)return{stdout:``,stderr:`sqlite3: missing database argument
|
|
28
28
|
`,exitCode:1};let d=a||t.stdin.trim();if(r.cmd&&(d=r.cmd+(d?`; ${d}`:``)),!d)return{stdout:``,stderr:`sqlite3: no SQL provided
|
|
29
29
|
`,exitCode:1};let f=i===`:memory:`,p=``,m=null;try{f||(p=t.fs.resolvePath(t.cwd,i),await t.fs.exists(p)&&(m=await t.fs.readFileBuffer(p)))}catch(e){return{stdout:``,stderr:`sqlite3: unable to open database "${i}": ${s(e.message)}
|
|
@@ -34,4 +34,4 @@ Use -help for a list of options.
|
|
|
34
34
|
`,exitCode:1};b+=`Error: ${e.error}
|
|
35
35
|
`,x=!0}else e.columns&&e.rows&&(e.rows.length>0||r.header)&&(b+=y(e.columns,e.rows,v));if(_.hasModifications&&!r.readonly&&!f&&p&&_.dbBuffer)try{await t.fs.writeFile(p,_.dbBuffer)}catch(e){let t=s(e.message);return{stdout:b,stderr:`sqlite3: failed to write database: ${t}
|
|
36
36
|
`,exitCode:1}}return{stdout:b,stderr:``,exitCode:x&&r.bail?1:0}}};export{N as sqlite3Command};
|
|
37
|
-
//# sourceMappingURL=sqlite3-TE5AIOTF-
|
|
37
|
+
//# sourceMappingURL=sqlite3-TE5AIOTF-DVwda1Ow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./md-manager-BGnqyqi1-RmPtbV-6.mjs";import"./init-Co_mDPzI.mjs";import"./registry-probes-BjsDFB65.mjs";import"./src-tuHpjXRh.mjs";import"./start-DWDyuoi5.mjs";import{n as e}from"./loader-RbdwxE-e.mjs";import"./preview-D4W9ISBt.mjs";import"./cli.mjs";import"./repair-mcp-configs-hy238Kt4.mjs";export{e as loadConfig};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-tZXQYakl.mjs";import{Es as t,Gc as n,Hd as r,Ls as i,Mn as a,Nn as o,To as s,Vn as c,Wc as l,ju as u,qc as ee,xc as te}from"./md-manager-BGnqyqi1-DKflYxqj.mjs";import{$n as d,Ci as f,Fo as p,Kr as m,No as h,Po as g,Qr as _,Si as v,Tt as y,Yn as b,ai as x,fr as S,ia as C,ii as w,m as T,oi as E,so as D,zn as O}from"./dist-gqMlO9g5.mjs";import{t as k}from"./yazl-BBz29IQN.mjs";import{St as A,at as j,ot as M}from"./init-C-24amuv.mjs";import{b as N,l as ne}from"./registry-probes-CADyDcpU.mjs";import{c as P}from"./colors-r_owlCuY.mjs";import{t as F}from"./is-object-BGze3w87.mjs";import{n as re}from"./constants-CdiHNFvt.mjs";import"./loader-0WU8op48.mjs";import"./preview-BSLfKB1h.mjs";import{execSync as ie,spawnSync as I}from"node:child_process";import{basename as L,dirname as R,isAbsolute as ae,join as z,relative as oe,resolve as B,sep as V}from"node:path";import{closeSync as se,cpSync as ce,createWriteStream as le,existsSync as H,lstatSync as ue,mkdirSync as U,mkdtempSync as de,openSync as fe,readFileSync as W,readSync as pe,readdirSync as G,rmSync as K,rmdirSync as me,statSync as he,writeFileSync as q}from"node:fs";import{arch as ge,freemem as _e,homedir as J,hostname as ve,platform as ye,release as be,tmpdir as xe,totalmem as Se,type as Ce,uptime as we}from"node:os";import"node:fs/promises";import{createHash as Te}from"node:crypto";const Ee=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`lint`,`deinit`,`auth`]);function De(e,t,n=d){if(e!==void 0&&!Ee.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let Oe=null;function ke(e){Oe=e}function Ae(){return Oe??process.cwd()}const je=`Open Knowledge`;function Me(e={}){let t=e.platformName??process.platform,n=e.productName??`OpenKnowledge`;return j(t).join(M({...e,platformName:t}),n)}function Ne(e={}){let t=e.platformName??process.platform,n=e.home??J(),r=e.env??process.env,i=j(t),a;return a=t===`win32`?r.LOCALAPPDATA||i.join(n,`AppData`,`Local`):t===`darwin`?i.join(n,`Library`,`Caches`):r.XDG_CACHE_HOME||i.join(n,`.cache`),i.join(a,`@inkeepopen-knowledge-desktop-updater`)}function Pe(e){if(typeof e!=`object`||!e)return null;let t=e.recentProjects;if(!Array.isArray(t))return null;let n=[];for(let e of t){if(typeof e!=`object`||!e)continue;let t=e;typeof t.path==`string`&&typeof t.name==`string`&&n.push({path:t.path,name:t.name})}return n}function Fe(e){let t=z(e,`state.json`);if(!H(t))return[];let n;try{n=JSON.parse(W(t,`utf-8`))}catch{return[]}return Pe(n)??[]}function Ie(e){let t=z(e,`state.json`);if(!H(t))return!1;try{return Pe(JSON.parse(W(t,`utf-8`)))!==null}catch{return!1}}const Le=8192;function Re(e,t){if(e.outcome===`not-present`)return`not-present (no DiagnosticReports directory)`;if(e.outcome===`unreadable-directory`)return`unreadable (${e.directoryErrorCode??`unknown`} reading DiagnosticReports)`;let n=[`${e.windowDays}d`,`${e.foreignIgnored} other-process report(s) ignored`,`${e.unparseable} unparseable`];e.droppedOverCap>0&&n.push(`${e.droppedOverCap} older dropped over cap`);let r=e.files.length-t;return r>0&&n.push(`${r} vanished before staging`),e.outcome===`none-in-window`?`none found in window (${n.join(`; `)})`:`${t} collected (${n.join(`; `)})`}function ze(e){return e.replace(/\\+\/?/g,e=>{if(!e.endsWith(`/`))return e;let t=e.length-1;return`${`\\`.repeat(t-t%2)}/`})}const Be=RegExp(`("(?:${[`crashReporterKey`,`bootSessionUUID`,`deviceIdentifierForVendor`].join(`|`)})"\\s*:\\s*)"[^"]*"`,`g`);function Ve(e){return e.replace(Be,`$1"[REDACTED-DEVICE-ID]"`)}function He(e){return Ve(ze(e))}const Ue=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(\.\d+)? ([+-]\d{2})(\d{2})$/;function We(e){if(typeof e!=`string`)return null;let t=Ue.exec(e.trim());if(t===null)return null;let[,n,r,i=``,a,o]=t,s=Date.parse(`${n}T${r}${i}${a}:${o}`);return Number.isNaN(s)?null:s}function Ge(e){let t=fe(e,`r`);try{let e=Buffer.alloc(Le),n=0,r=!1;for(;n<Le;){let i=pe(t,e,n,Le-n,n);if(i===0){r=!0;break}let a=n;n+=i;let o=e.subarray(0,n).indexOf(10,a);if(o!==-1)return e.subarray(0,o).toString(`utf-8`)}return r?e.subarray(0,n).toString(`utf-8`):null}finally{se(t)}}function Ke(e){try{let t=Ge(e);if(t===null)return{kind:`unreadable`};let n=JSON.parse(t);if(typeof n!=`object`||!n)return{kind:`unreadable`};let{name:r,app_name:i,timestamp:a}=n,o=typeof r==`string`?r:typeof i==`string`?i:null;return o===null?{kind:`unreadable`}:{kind:`named`,name:o,timestampMs:We(a)}}catch{return{kind:`unreadable`}}}function qe(e){return e===`OpenKnowledge`||e.startsWith(`OpenKnowledge `)}function Je(e,t){let n={files:[],foreignIgnored:0,unparseable:0,droppedOverCap:0,windowDays:7},r;try{r=G(e,{withFileTypes:!0})}catch(e){let t=e.code;return t===`ENOENT`?{...n,outcome:`not-present`}:{...n,outcome:`unreadable-directory`,directoryErrorCode:t??`unknown`}}let i=t.getTime()-6048e5,a=[],o=0,s=0;for(let t of r){if(!t.isFile()||!t.name.endsWith(`.ips`))continue;let n=z(e,t.name),r;try{r=he(n).mtimeMs}catch{continue}if(r<i)continue;let c=Ke(n),l=c.kind===`named`&&c.timestampMs!==null?c.timestampMs:r;if(c.kind===`unreadable`){s+=1;continue}if(!qe(c.name)){o+=1;continue}a.push({path:n,atMs:l})}a.sort((e,t)=>t.atMs-e.atMs);let c=a.slice(0,25),l={foreignIgnored:o,unparseable:s,droppedOverCap:a.length-c.length,windowDays:7};return c.length===0?{...l,files:[],outcome:`none-in-window`}:{...l,files:c.map(e=>e.path),outcome:`collected`}}function Y(){return z(J(),`.ok`,`bug-reports`)}function Ye(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`),n=Y(),r=`${t}-bugreport`,i=z(n,`${r}.zip`);for(let e=2;H(i);e+=1)i=z(n,`${r}-${e}.zip`);return i}function Xe(e,t){let n=z(e,`.ok`,`config.yml`);if(H(n))try{let e=W(n,`utf8`).match(/^\s*name:\s*['"]?(.+?)['"]?\s*$/m);if(e?.[1])return e[1]}catch(e){t?.warn({configPath:n,err:e},`bug-report: failed to read .ok/config.yml for project slug; using path-hash fallback`)}return H(z(e,`.ok`))?Te(`sha256`).update(B(e)).digest(`hex`).slice(0,12):null}function Ze(){let e={timestamp:new Date().toISOString(),platform:ye(),osType:Ce(),osRelease:be(),hostname:`[redacted]`,uptime:we(),freeMem:_e(),totalMem:Se(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=ie(`sw_vers -productVersion 2>/dev/null`,D({encoding:`utf8`})).trim()}catch{}try{let t=z(__dirname,`..`,`..`,`package.json`);H(t)&&(e.okVersion=JSON.parse(W(t,`utf8`)).version)}catch{}return e}const Qe=[{prefix:`cli`,projectTagged:!0},{prefix:`desktop`,projectTagged:!1},{prefix:`mcp`,projectTagged:!1}];function $e(e){let t=L(e);return Qe.some(e=>e.projectTagged&&t.startsWith(`${e.prefix}.`))}function et(e,t){return it(e,t).files}const tt=[`ShipIt_stderr.log`,`ShipIt_stdout.log`];function nt(e,t=ne){let n=z(e,`${t}.ShipIt`);if(!H(n))return[];let r;try{r=G(n)}catch{return[]}return tt.flatMap(e=>r.map(t=>{if(t===e)return{entry:t,suffix:-1};if(!t.startsWith(`${e}.`))return null;let n=t.slice(e.length+1);return/^\d+$/.test(n)?{entry:t,suffix:Number(n)}:null}).filter(e=>e!==null).sort((e,t)=>e.suffix-t.suffix).slice(0,4).map(e=>z(n,e.entry)))}function rt(e){if(!H(e))return[];try{let t=new Map;for(let n of G(e).filter(e=>e.endsWith(`.yaml`)).sort()){let e=n.endsWith(`.sent.yaml`)?n.slice(0,-a.length):n.slice(0,-5),r=t.get(e);r===void 0?t.set(e,[n]):r.push(n)}return[...t.values()].slice(-25).flat().map(t=>z(e,t))}catch{return[]}}function it(e,t){if(!H(t))return{files:[],excludedByProjectSlug:0};let n=G(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>z(t,e));if(!e)return{files:n,excludedByProjectSlug:0};let r=n.filter($e),i=[],a=r.filter(t=>{try{return W(t,`utf8`).includes(`"project":"${e}"`)}catch{return i.push(t),!1}});if(a.length===0)return{files:n,excludedByProjectSlug:0};let o=new Set([...a,...i]);return{files:n.filter(e=>!$e(e)||o.has(e)),excludedByProjectSlug:r.length-o.size}}function at(e){let t=z(e,`.ok`,`local`);return H(t)?{files:[`server.lock`,`last-spawn-error.log`,l].map(e=>z(t,e)).filter(e=>H(e))}:{files:[]}}function ot(e){let t=z(e,`.ok`,`local`,`logs`);return H(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>z(t,e)).filter(e=>H(e))}:{files:[]}}function st(e){let t=0,n=new Map,r=e.replace(/("(?:docName|doc\.name|documentName)"\s*:\s*")((?:[^"\\]|\\.)*)"/g,(e,r,i)=>{t+=1;let a=n.get(i);return a===void 0&&(a=`doc#${Te(`sha256`).update(i).digest(`hex`).slice(0,12)}`,n.set(i,a)),`${r}${a}"`});for(let[e,i]of[...n].sort(([e],[t])=>t.length-e.length)){if(e.length===0||!r.includes(e))continue;let n=r.split(e);t+=n.length-1,r=n.join(i)}return{text:r,count:t}}function ct(e){let n=e.revealDocNames?e.content:st(e.content).text;if(e.redact){let{redacted:r,patterns:i,lineCount:a}=t(n);e.zipfile.addBuffer(Buffer.from(r,`utf8`),e.name),e.bundleFiles.push(e.name),i.length>0&&e.redactions.push({file:e.name,lineCount:a,patterns:i})}else e.zipfile.addBuffer(Buffer.from(n,`utf8`),e.name),e.bundleFiles.push(e.name)}function X(e){for(let t of e.files)try{let n=W(t,`utf8`);ct({zipfile:e.zipfile,name:`${e.prefix}/${L(t)}`,content:t.endsWith(`.ips`)?He(n):n,redact:e.redact,revealDocNames:e.revealDocNames,bundleFiles:e.bundleFiles,redactions:e.redactions})}catch(n){e.logger?.warn({file:t,prefix:e.prefix,err:n},`bug-report: skipped unreadable file`)}}async function lt(t){let{redact:n,outputPath:r,logger:i}=t,a=t.revealDocNames??!1,s=t.userLogsDir??z(J(),`.ok`,`logs`),l=t.projectDir?Xe(t.projectDir,i):null;U(R(r),{recursive:!0}),i?.info({projectSlug:l},`gathering diagnostic data`);let u=Ze();u.desktop=t.desktop??null,u.language=t.language??null;let{files:ee,excludedByProjectSlug:te}=it(l,s),{files:d}=t.projectDir?at(t.projectDir):{files:[]},{files:f}=t.projectDir?ot(t.projectDir):{files:[]},p=t.shipItLogFiles??[],m=t.diagnosticReports?.files??[];i?.info({logFileCount:ee.length,logFilesExcludedByProjectSlug:te,lockFileCount:d.length,localSinkFileCount:f.length,shipItLogFileCount:p.length,diagnosticReportCount:m.length},`files collected`);let h=[],g=[],{ZipFile:_}=await import(`./yazl-BsCX6KWo.mjs`).then(t=>e(t.default,1)),v=new _;X({zipfile:v,files:[...ee,...p],prefix:`logs`,redact:n,revealDocNames:a,bundleFiles:g,redactions:h,logger:i}),X({zipfile:v,files:d,prefix:`lockdir`,redact:n,revealDocNames:a,bundleFiles:g,redactions:h,logger:i}),X({zipfile:v,files:f,prefix:`local-logs`,redact:n,revealDocNames:a,bundleFiles:g,redactions:h,logger:i}),X({zipfile:v,files:t.bugReportLedgerFiles??[],prefix:o,redact:n,revealDocNames:a,bundleFiles:g,redactions:h,logger:i}),X({zipfile:v,files:m,prefix:`diagnostic-reports`,redact:n,revealDocNames:a,bundleFiles:g,redactions:h,logger:i});for(let e of t.extraFiles??[])try{let t=W(e.sourcePath),n=`extra/${e.zipName??L(e.sourcePath)}`;v.addBuffer(t,n),g.push(n)}catch(t){i?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&ct({zipfile:v,name:`note.txt`,content:t.note,redact:n,revealDocNames:a,bundleFiles:g,redactions:h});let y=new Set(m.map(e=>`diagnostic-reports/${L(e)}`)),b=g.filter(e=>y.has(e)),x=t.diagnosticReports===void 0?`not-collected (no collection attempted)`:Re(t.diagnosticReports,b.length);v.addBuffer(Buffer.from(`${x}\n`,`utf8`),`state/diagnostic-reports-status.txt`),g.push(`state/diagnostic-reports-status.txt`);let S=JSON.stringify(u,null,2);v.addBuffer(Buffer.from(S,`utf8`),`sysinfo.json`),g.push(`sysinfo.json`);let C={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:l,files:g,redactions:h,sysinfo:u};v.addBuffer(Buffer.from(JSON.stringify(C,null,2),`utf8`),`MANIFEST.json`);let w=h.reduce((e,t)=>e+t.lineCount,0),T=new Set(p.map(e=>`logs/${L(e)}`)),E=g.filter(e=>T.has(e)),D=new Set((t.bugReportLedgerFiles??[]).map(e=>`${o}/${L(e)}`)),O=g.filter(e=>D.has(e)),k=l?g.filter(e=>e.startsWith(`logs/`)&&!$e(e)&&!T.has(e)):[],A=b.length>0?[`Crash reports under diagnostic-reports/ are rewritten on the way in,`,`independently of this setting: escaped path separators are normalised`,`so the scrub above can read them, and the identifiers that link this`,`machine's bundles to each other are replaced. Nothing else is changed;`,`they are not byte-identical to the files macOS wrote.`]:[],j=A.length>0?[`Redaction was disabled for this bundle; file contents are unmodified,`,`with one exception.`,...A]:[`Redaction was disabled for this bundle; file contents are unmodified.`],M=[`# Bug Report Bundle`,``,`Generated: ${C.generatedAt}`,`Project: ${l??`(unscoped)`}`,`Discipline version: ${C.disciplineVersion}`,``,`## Contents`,``,...g.map(e=>`- ${e}`),``,`## Privacy`,``,...k.length>0?[`Scope: some collected logs are user-wide rather than project-scoped.`,`These are written once per machine per day and can contain activity`,`from other projects open on this machine, including captured console`,`output:`,...k.map(e=>`- ${e}`),``]:[],...E.length>0?[`Installer logs: written by the macOS update helper rather than by`,`OpenKnowledge itself, and machine-wide rather than scoped to any one`,`project. They record the install and update history of this app on`,`this machine. Only this app is collected, never other applications`,`that use the same update mechanism:`,...E.map(e=>`- ${e}`),``]:[],...b.length>0?[`Crash reports: written by macOS itself rather than by OpenKnowledge,`,`and machine-wide rather than scoped to any one project. They record`,`why the operating system ended a process of this app — the signal or`,`exception, the code-signing verdict, and whatever text the process`,`left behind as it died. They also carry machine details the OS puts`,`in every report: the account uid, the Mac model, and the name of the`,`process that launched this app, which on a managed machine can be`,`internal tooling. The identifiers that would link this machine's`,`bundles to each other are replaced before bundling. Only this`,`app's own reports are collected, never another application's, though`,`a report of ours still names the processes it ran alongside:`,...b.map(e=>`- ${e}`),``]:[],...O.length>0?[`Send history: a small record for each bug report previously generated`,`on this machine — when it was generated, whether sending it`,`succeeded, and why it failed if it did. This is what makes a failed`,`send diagnosable at all. It is machine-wide rather than scoped to`,`this project, so it names the other projects reports were filed`,`from. It carries no document content:`,...O.map(e=>`- ${e}`),``]:[],...n?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${c.join(`, `)}`,w>0?`${w} line(s) were scrubbed across ${h.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,...A,``,`This bundle is safe to attach to a GitHub issue.`]:j].join(`
|
|
2
|
-
`);v.addBuffer(Buffer.from(M,`utf8`),`README.md`),v.end();let N=le(
|
|
1
|
+
import{o as e}from"./rolldown-runtime-tZXQYakl.mjs";import{Bs as t,Hn as n,Jc as r,Nn as i,Oo as a,Pn as o,Pu as s,Xc as c,ks as l,qc as u,qd as ee,wc as te}from"./md-manager-BGnqyqi1-RmPtbV-6.mjs";import{$n as d,Ci as f,Fo as p,Kr as m,No as h,Po as g,Qr as _,Si as v,Tt as y,Yn as b,ai as x,fr as S,ia as C,ii as w,m as T,oi as E,so as D,zn as O}from"./dist-CdMoMubk.mjs";import{t as k}from"./yazl-BBz29IQN.mjs";import{St as A,at as j,ot as M}from"./init-Co_mDPzI.mjs";import{b as N,l as ne}from"./registry-probes-BjsDFB65.mjs";import{c as P}from"./colors-r_owlCuY.mjs";import{t as F}from"./is-object-BGze3w87.mjs";import{n as re}from"./constants-D7ISUGXs.mjs";import"./loader-RbdwxE-e.mjs";import"./preview-D4W9ISBt.mjs";import{execSync as ie,spawnSync as I}from"node:child_process";import{basename as L,dirname as R,isAbsolute as ae,join as z,relative as oe,resolve as B,sep as V}from"node:path";import{closeSync as se,cpSync as ce,createWriteStream as le,existsSync as H,lstatSync as ue,mkdirSync as U,mkdtempSync as de,openSync as fe,readFileSync as W,readSync as pe,readdirSync as G,rmSync as K,rmdirSync as me,statSync as he,writeFileSync as q}from"node:fs";import{arch as ge,freemem as _e,homedir as J,hostname as ve,platform as ye,release as be,tmpdir as xe,totalmem as Se,type as Ce,uptime as we}from"node:os";import"node:fs/promises";import{createHash as Te}from"node:crypto";const Ee=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`lint`,`deinit`,`auth`]);function De(e,t,n=d){if(e!==void 0&&!Ee.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let Oe=null;function ke(e){Oe=e}function Ae(){return Oe??process.cwd()}const je=`Open Knowledge`;function Me(e={}){let t=e.platformName??process.platform,n=e.productName??`OpenKnowledge`;return j(t).join(M({...e,platformName:t}),n)}function Ne(e={}){let t=e.platformName??process.platform,n=e.home??J(),r=e.env??process.env,i=j(t),a;return a=t===`win32`?r.LOCALAPPDATA||i.join(n,`AppData`,`Local`):t===`darwin`?i.join(n,`Library`,`Caches`):r.XDG_CACHE_HOME||i.join(n,`.cache`),i.join(a,`@inkeepopen-knowledge-desktop-updater`)}function Pe(e){if(typeof e!=`object`||!e)return null;let t=e.recentProjects;if(!Array.isArray(t))return null;let n=[];for(let e of t){if(typeof e!=`object`||!e)continue;let t=e;typeof t.path==`string`&&typeof t.name==`string`&&n.push({path:t.path,name:t.name})}return n}function Fe(e){let t=z(e,`state.json`);if(!H(t))return[];let n;try{n=JSON.parse(W(t,`utf-8`))}catch{return[]}return Pe(n)??[]}function Ie(e){let t=z(e,`state.json`);if(!H(t))return!1;try{return Pe(JSON.parse(W(t,`utf-8`)))!==null}catch{return!1}}const Le=8192;function Re(e,t){if(e.outcome===`not-present`)return`not-present (no DiagnosticReports directory)`;if(e.outcome===`unreadable-directory`)return`unreadable (${e.directoryErrorCode??`unknown`} reading DiagnosticReports)`;let n=[`${e.windowDays}d`,`${e.foreignIgnored} other-process report(s) ignored`,`${e.unparseable} unparseable`];e.droppedOverCap>0&&n.push(`${e.droppedOverCap} older dropped over cap`);let r=e.files.length-t;return r>0&&n.push(`${r} vanished before staging`),e.outcome===`none-in-window`?`none found in window (${n.join(`; `)})`:`${t} collected (${n.join(`; `)})`}function ze(e){return e.replace(/\\+\/?/g,e=>{if(!e.endsWith(`/`))return e;let t=e.length-1;return`${`\\`.repeat(t-t%2)}/`})}const Be=RegExp(`("(?:${[`crashReporterKey`,`bootSessionUUID`,`deviceIdentifierForVendor`].join(`|`)})"\\s*:\\s*)"[^"]*"`,`g`);function Ve(e){return e.replace(Be,`$1"[REDACTED-DEVICE-ID]"`)}function He(e){return Ve(ze(e))}const Ue=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(\.\d+)? ([+-]\d{2})(\d{2})$/;function We(e){if(typeof e!=`string`)return null;let t=Ue.exec(e.trim());if(t===null)return null;let[,n,r,i=``,a,o]=t,s=Date.parse(`${n}T${r}${i}${a}:${o}`);return Number.isNaN(s)?null:s}function Ge(e){let t=fe(e,`r`);try{let e=Buffer.alloc(Le),n=0,r=!1;for(;n<Le;){let i=pe(t,e,n,Le-n,n);if(i===0){r=!0;break}let a=n;n+=i;let o=e.subarray(0,n).indexOf(10,a);if(o!==-1)return e.subarray(0,o).toString(`utf-8`)}return r?e.subarray(0,n).toString(`utf-8`):null}finally{se(t)}}function Ke(e){try{let t=Ge(e);if(t===null)return{kind:`unreadable`};let n=JSON.parse(t);if(typeof n!=`object`||!n)return{kind:`unreadable`};let{name:r,app_name:i,timestamp:a}=n,o=typeof r==`string`?r:typeof i==`string`?i:null;return o===null?{kind:`unreadable`}:{kind:`named`,name:o,timestampMs:We(a)}}catch{return{kind:`unreadable`}}}function qe(e){return e===`OpenKnowledge`||e.startsWith(`OpenKnowledge `)}function Je(e,t){let n={files:[],foreignIgnored:0,unparseable:0,droppedOverCap:0,windowDays:7},r;try{r=G(e,{withFileTypes:!0})}catch(e){let t=e.code;return t===`ENOENT`?{...n,outcome:`not-present`}:{...n,outcome:`unreadable-directory`,directoryErrorCode:t??`unknown`}}let i=t.getTime()-6048e5,a=[],o=0,s=0;for(let t of r){if(!t.isFile()||!t.name.endsWith(`.ips`))continue;let n=z(e,t.name),r;try{r=he(n).mtimeMs}catch{continue}if(r<i)continue;let c=Ke(n),l=c.kind===`named`&&c.timestampMs!==null?c.timestampMs:r;if(c.kind===`unreadable`){s+=1;continue}if(!qe(c.name)){o+=1;continue}a.push({path:n,atMs:l})}a.sort((e,t)=>t.atMs-e.atMs);let c=a.slice(0,25),l={foreignIgnored:o,unparseable:s,droppedOverCap:a.length-c.length,windowDays:7};return c.length===0?{...l,files:[],outcome:`none-in-window`}:{...l,files:c.map(e=>e.path),outcome:`collected`}}function Y(){return z(J(),`.ok`,`bug-reports`)}function Ye(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`),n=Y(),r=`${t}-bugreport`,i=z(n,`${r}.zip`);for(let e=2;H(i);e+=1)i=z(n,`${r}-${e}.zip`);return i}function Xe(e,t){let n=z(e,`.ok`,`config.yml`);if(H(n))try{let e=W(n,`utf8`).match(/^\s*name:\s*['"]?(.+?)['"]?\s*$/m);if(e?.[1])return e[1]}catch(e){t?.warn({configPath:n,err:e},`bug-report: failed to read .ok/config.yml for project slug; using path-hash fallback`)}return H(z(e,`.ok`))?Te(`sha256`).update(B(e)).digest(`hex`).slice(0,12):null}function Ze(){let e={timestamp:new Date().toISOString(),platform:ye(),osType:Ce(),osRelease:be(),hostname:`[redacted]`,uptime:we(),freeMem:_e(),totalMem:Se(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=ie(`sw_vers -productVersion 2>/dev/null`,D({encoding:`utf8`})).trim()}catch{}try{let t=z(__dirname,`..`,`..`,`package.json`);H(t)&&(e.okVersion=JSON.parse(W(t,`utf8`)).version)}catch{}return e}const Qe=[{prefix:`cli`,projectTagged:!0},{prefix:`desktop`,projectTagged:!1},{prefix:`mcp`,projectTagged:!1}];function $e(e){let t=L(e);return Qe.some(e=>e.projectTagged&&t.startsWith(`${e.prefix}.`))}function et(e,t){return it(e,t).files}const tt=[`ShipIt_stderr.log`,`ShipIt_stdout.log`];function nt(e,t=ne){let n=z(e,`${t}.ShipIt`);if(!H(n))return[];let r;try{r=G(n)}catch{return[]}return tt.flatMap(e=>r.map(t=>{if(t===e)return{entry:t,suffix:-1};if(!t.startsWith(`${e}.`))return null;let n=t.slice(e.length+1);return/^\d+$/.test(n)?{entry:t,suffix:Number(n)}:null}).filter(e=>e!==null).sort((e,t)=>e.suffix-t.suffix).slice(0,4).map(e=>z(n,e.entry)))}function rt(e){if(!H(e))return[];try{let t=new Map;for(let n of G(e).filter(e=>e.endsWith(`.yaml`)).sort()){let e=n.endsWith(`.sent.yaml`)?n.slice(0,-i.length):n.slice(0,-5),r=t.get(e);r===void 0?t.set(e,[n]):r.push(n)}return[...t.values()].slice(-25).flat().map(t=>z(e,t))}catch{return[]}}function it(e,t){if(!H(t))return{files:[],excludedByProjectSlug:0};let n=G(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>z(t,e));if(!e)return{files:n,excludedByProjectSlug:0};let r=n.filter($e),i=[],a=r.filter(t=>{try{return W(t,`utf8`).includes(`"project":"${e}"`)}catch{return i.push(t),!1}});if(a.length===0)return{files:n,excludedByProjectSlug:0};let o=new Set([...a,...i]);return{files:n.filter(e=>!$e(e)||o.has(e)),excludedByProjectSlug:r.length-o.size}}function at(e){let t=z(e,`.ok`,`local`);return H(t)?{files:[`server.lock`,`last-spawn-error.log`,u].map(e=>z(t,e)).filter(e=>H(e))}:{files:[]}}function ot(e){let t=z(e,`.ok`,`local`,`logs`);return H(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>z(t,e)).filter(e=>H(e))}:{files:[]}}function st(e){let t=0,n=new Map,r=e.replace(/("(?:docName|doc\.name|documentName)"\s*:\s*")((?:[^"\\]|\\.)*)"/g,(e,r,i)=>{t+=1;let a=n.get(i);return a===void 0&&(a=`doc#${Te(`sha256`).update(i).digest(`hex`).slice(0,12)}`,n.set(i,a)),`${r}${a}"`});for(let[e,i]of[...n].sort(([e],[t])=>t.length-e.length)){if(e.length===0||!r.includes(e))continue;let n=r.split(e);t+=n.length-1,r=n.join(i)}return{text:r,count:t}}function ct(e){let t=e.revealDocNames?e.content:st(e.content).text;if(e.redact){let{redacted:n,patterns:r,lineCount:i}=l(t);e.zipfile.addBuffer(Buffer.from(n,`utf8`),e.name),e.bundleFiles.push(e.name),r.length>0&&e.redactions.push({file:e.name,lineCount:i,patterns:r})}else e.zipfile.addBuffer(Buffer.from(t,`utf8`),e.name),e.bundleFiles.push(e.name)}function X(e){for(let t of e.files)try{let n=W(t,`utf8`);ct({zipfile:e.zipfile,name:`${e.prefix}/${L(t)}`,content:t.endsWith(`.ips`)?He(n):n,redact:e.redact,revealDocNames:e.revealDocNames,bundleFiles:e.bundleFiles,redactions:e.redactions})}catch(n){e.logger?.warn({file:t,prefix:e.prefix,err:n},`bug-report: skipped unreadable file`)}}async function lt(t){let{redact:r,outputPath:i,logger:a}=t,s=t.revealDocNames??!1,c=t.userLogsDir??z(J(),`.ok`,`logs`),l=t.projectDir?Xe(t.projectDir,a):null;U(R(i),{recursive:!0}),a?.info({projectSlug:l},`gathering diagnostic data`);let u=Ze();u.desktop=t.desktop??null,u.language=t.language??null;let{files:ee,excludedByProjectSlug:te}=it(l,c),{files:d}=t.projectDir?at(t.projectDir):{files:[]},{files:f}=t.projectDir?ot(t.projectDir):{files:[]},p=t.shipItLogFiles??[],m=t.diagnosticReports?.files??[];a?.info({logFileCount:ee.length,logFilesExcludedByProjectSlug:te,lockFileCount:d.length,localSinkFileCount:f.length,shipItLogFileCount:p.length,diagnosticReportCount:m.length},`files collected`);let h=[],g=[],{ZipFile:_}=await import(`./yazl-BsCX6KWo.mjs`).then(t=>e(t.default,1)),v=new _;X({zipfile:v,files:[...ee,...p],prefix:`logs`,redact:r,revealDocNames:s,bundleFiles:g,redactions:h,logger:a}),X({zipfile:v,files:d,prefix:`lockdir`,redact:r,revealDocNames:s,bundleFiles:g,redactions:h,logger:a}),X({zipfile:v,files:f,prefix:`local-logs`,redact:r,revealDocNames:s,bundleFiles:g,redactions:h,logger:a}),X({zipfile:v,files:t.bugReportLedgerFiles??[],prefix:o,redact:r,revealDocNames:s,bundleFiles:g,redactions:h,logger:a}),X({zipfile:v,files:m,prefix:`diagnostic-reports`,redact:r,revealDocNames:s,bundleFiles:g,redactions:h,logger:a});for(let e of t.extraFiles??[])try{let t=W(e.sourcePath),n=`extra/${e.zipName??L(e.sourcePath)}`;v.addBuffer(t,n),g.push(n)}catch(t){a?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&ct({zipfile:v,name:`note.txt`,content:t.note,redact:r,revealDocNames:s,bundleFiles:g,redactions:h});let y=new Set(m.map(e=>`diagnostic-reports/${L(e)}`)),b=g.filter(e=>y.has(e)),x=t.diagnosticReports===void 0?`not-collected (no collection attempted)`:Re(t.diagnosticReports,b.length);v.addBuffer(Buffer.from(`${x}\n`,`utf8`),`state/diagnostic-reports-status.txt`),g.push(`state/diagnostic-reports-status.txt`);let S=JSON.stringify(u,null,2);v.addBuffer(Buffer.from(S,`utf8`),`sysinfo.json`),g.push(`sysinfo.json`);let C={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:l,files:g,redactions:h,sysinfo:u};v.addBuffer(Buffer.from(JSON.stringify(C,null,2),`utf8`),`MANIFEST.json`);let w=h.reduce((e,t)=>e+t.lineCount,0),T=new Set(p.map(e=>`logs/${L(e)}`)),E=g.filter(e=>T.has(e)),D=new Set((t.bugReportLedgerFiles??[]).map(e=>`${o}/${L(e)}`)),O=g.filter(e=>D.has(e)),k=l?g.filter(e=>e.startsWith(`logs/`)&&!$e(e)&&!T.has(e)):[],A=b.length>0?[`Crash reports under diagnostic-reports/ are rewritten on the way in,`,`independently of this setting: escaped path separators are normalised`,`so the scrub above can read them, and the identifiers that link this`,`machine's bundles to each other are replaced. Nothing else is changed;`,`they are not byte-identical to the files macOS wrote.`]:[],j=A.length>0?[`Redaction was disabled for this bundle; file contents are unmodified,`,`with one exception.`,...A]:[`Redaction was disabled for this bundle; file contents are unmodified.`],M=[`# Bug Report Bundle`,``,`Generated: ${C.generatedAt}`,`Project: ${l??`(unscoped)`}`,`Discipline version: ${C.disciplineVersion}`,``,`## Contents`,``,...g.map(e=>`- ${e}`),``,`## Privacy`,``,...k.length>0?[`Scope: some collected logs are user-wide rather than project-scoped.`,`These are written once per machine per day and can contain activity`,`from other projects open on this machine, including captured console`,`output:`,...k.map(e=>`- ${e}`),``]:[],...E.length>0?[`Installer logs: written by the macOS update helper rather than by`,`OpenKnowledge itself, and machine-wide rather than scoped to any one`,`project. They record the install and update history of this app on`,`this machine. Only this app is collected, never other applications`,`that use the same update mechanism:`,...E.map(e=>`- ${e}`),``]:[],...b.length>0?[`Crash reports: written by macOS itself rather than by OpenKnowledge,`,`and machine-wide rather than scoped to any one project. They record`,`why the operating system ended a process of this app — the signal or`,`exception, the code-signing verdict, and whatever text the process`,`left behind as it died. They also carry machine details the OS puts`,`in every report: the account uid, the Mac model, and the name of the`,`process that launched this app, which on a managed machine can be`,`internal tooling. The identifiers that would link this machine's`,`bundles to each other are replaced before bundling. Only this`,`app's own reports are collected, never another application's, though`,`a report of ours still names the processes it ran alongside:`,...b.map(e=>`- ${e}`),``]:[],...O.length>0?[`Send history: a small record for each bug report previously generated`,`on this machine — when it was generated, whether sending it`,`succeeded, and why it failed if it did. This is what makes a failed`,`send diagnosable at all. It is machine-wide rather than scoped to`,`this project, so it names the other projects reports were filed`,`from. It carries no document content:`,...O.map(e=>`- ${e}`),``]:[],...r?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${n.join(`, `)}`,w>0?`${w} line(s) were scrubbed across ${h.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,...A,``,`This bundle is safe to attach to a GitHub issue.`]:j].join(`
|
|
2
|
+
`);v.addBuffer(Buffer.from(M,`utf8`),`README.md`),v.end();let N=le(i);return v.outputStream.pipe(N),await new Promise((e,t)=>{N.on(`close`,e),N.on(`error`,t)}),a?.info({bundlePath:i,fileCount:g.length,redactionCount:w},`bundle written`),{zipPath:i,summary:{projectSlug:l,files:g,redactions:h,redactedLineCount:w,generatedAt:C.generatedAt}}}var ut=s(),dt=e(k(),1),Z=e(P(),1);function ft(e){let t=p(`user`,e,e);return h({absPath:t,sideline:!1,warn:()=>{}}).value.appearance?.language??`system`}function pt({home:e=J(),env:n=process.env}={}){let r=ft(e),{override:i,preferenceList:a}=g(n),{locale:o,source:s}=t({override:i,storedPreference:r,supportedLocales:c,preferenceList:a,autoDetectableLocales:te});return{preference:r,locale:o,source:s,systemLanguages:a}}function mt(e,t){return t.length===0||!e.includes(t)?e:e.split(t).join(`<CONTENT_DIR>`)}function ht(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function gt(e,t){if(typeof e==`string`)return mt(e,t.contentDir);if(Array.isArray(e))return e.map(e=>gt(e,t));if(!ht(e))return e;let n={};for(let[r,i]of Object.entries(e))n[r]=gt(i,t);return n}function _t(e,t){let n=W(e,`utf-8`);if(n.length===0)return;let r=n.endsWith(`
|
|
3
3
|
`),i=n.split(`
|
|
4
4
|
`),a=[];for(let e=0;e<i.length;e++){let n=i[e]??``;if(e!==i.length-1||n!==``){if(n.length===0){a.push(``);continue}try{let e=gt(JSON.parse(n),t);a.push(JSON.stringify(e))}catch{a.push(n)}}}let o=r?`${a.join(`
|
|
5
5
|
`)}\n`:a.join(`
|
|
6
6
|
`);q(e,o)}function vt(e,t){let n=W(e,`utf-8`);if(n.trim().length!==0)try{let r=gt(JSON.parse(n),t),i=n.endsWith(`
|
|
7
7
|
`)?`
|
|
8
8
|
`:``;q(e,`${JSON.stringify(r,null,2)}${i}`)}catch{let r=mt(n,t.contentDir);r!==n&&q(e,r)}}function yt(e,t){let n=W(e,`utf-8`),r=mt(n,t.contentDir);r!==n&&q(e,r)}function bt(e){try{return G(e,{withFileTypes:!0}).filter(e=>e.isFile()).map(t=>z(e,t.name))}catch{return[]}}const xt=new Set([`agent-presence.json`,`agent-effects.json`,`runtime.json`]);function St(e){return/\.log\.\d+$/.test(e)}function Ct(e){return e.endsWith(`.jsonl`)||e.endsWith(`.log`)||St(e)}const wt=[`telemetry`,`logs`,`process`,`diagnostic-reports`];function Tt(e){let t={contentDir:e.contentDir};for(let n of wt)for(let r of bt(z(e.stagingDir,n)))Ct(r)?_t(r,t):r.endsWith(`.json`)?vt(r,t):yt(r,t);for(let n of bt(z(e.stagingDir,`state`))){let e=L(n);n.endsWith(`.jsonl`)?_t(n,t):xt.has(e)?vt(n,t):yt(n,t)}}const Et=[`.ok`,`local`,`telemetry`],Dt=[`.ok`,`local`,`logs`],Ot=[`.ok`,`local`,`loss-capture`],kt=`spans-current.jsonl`,At=`spans-prev.jsonl`,jt=`server-current.jsonl`,Mt=`server-prev.jsonl`,Nt=`loss-current.jsonl`,Pt=`loss-prev.jsonl`;function Ft(e){return z(e,...Et,kt)}function It(e){return z(e,...Et,At)}function Lt(e){return z(e,...Dt,jt)}function Rt(e){return z(e,...Dt,Mt)}function zt(e){return z(e,...Ot,Nt)}function Bt(e){return z(e,...Ot,Pt)}const Vt=1e3;async function Ht(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-presence`,{signal:AbortSignal.timeout(Vt)});return t.ok?await t.text():null}catch{return null}}async function Ut(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-effects`,{signal:AbortSignal.timeout(Vt)});return t.ok?await t.text():null}catch{return null}}async function Wt(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/watcher-recent`,{signal:AbortSignal.timeout(Vt)});return t.ok?await t.text():null}catch{return null}}function Gt(e){try{let t=JSON.parse(e);if(typeof t!=`object`||!t)return null;let n=t.decisions;return Array.isArray(n)?n.length===0?``:`${n.map(e=>JSON.stringify(e)).join(`
|
|
9
|
-
`)}\n`:null}catch{return null}}function Kt(e){let t=z(e,`.git`,`ok`);if(!H(t))return null;let n=I(`git`,[`-C`,t,`log`,`--oneline`,`-50`],D({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function qt(e){let t=z(e,`.git`,`ok`);if(!H(t))return null;let n=I(`git`,[`-C`,t,`for-each-ref`,`--sort=-creatordate`,`--count=50`,`--format=%(refname)%09%(creatordate:iso-strict)%09%(contents:subject)`,`refs/checkpoints/`],D({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function Jt(){let e=process.env.OK_DESKTOP_VERSION,t=process.env.OK_DESKTOP_PACKAGED,n=process.env.OK_DESKTOP_CHANNEL;return e===void 0||t===void 0||n===void 0?null:{electronVersion:e,packaged:t===`1`||t.toLowerCase()===`true`,channel:n}}function Yt(){return{nodeVersion:process.version,platform:ye(),arch:ge()}}function Xt(){return process.env.OTEL_SDK_DISABLED===`false`}function Zt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Qt(e){if(!H(e))return{};let t;try{t=(0,ut.parse)(W(e,`utf-8`))}catch(t){return console.warn(`[ok diagnose bundle] failed to parse ${e} for manifest config; manifest will report schema defaults. Reason: ${t instanceof Error?t.message:String(t)}`),{}}if(!Zt(t))return{};let n=t.telemetry;if(!Zt(n))return{};let r=n.localSink;return Zt(r)?r:{}}function $t(e){return typeof e==`boolean`?e:void 0}function en(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function tn(e){if(Zt(e))return en(e.maxBytes)}function nn(e){let t=Qt(p(`project`,e)),n=Qt(p(`project-local`,e));return{enabled:$t(n.enabled)??$t(t.enabled)??!0,spansMaxBytes:tn(n.spans)??tn(t.spans)??52428800,logsMaxBytes:tn(n.logs)??tn(t.logs)??26214400}}function rn(e){return Te(`sha256`).update(e).digest(`hex`)}function an(e){let t=W(e),n=0;for(let e=0;e<t.length;e++)t[e]===10&&n++;return n}const on=[`"doc.name"`,`"docName"`];function sn(e){let t=W(e,`utf-8`),n=0;for(let e of on){let r=t.indexOf(e);for(;r!==-1;)n++,r=t.indexOf(e,r+e.length)}return n}function Q(e,t){if(!H(e))return!1;try{return U(R(t),{recursive:!0}),e.endsWith(`.ips`)?q(t,He(W(e,`utf-8`))):ce(e,t),!0}catch{return!1}}function cn(e){let t=[],n=e=>{let r=G(e,{withFileTypes:!0});for(let i of r){let r=z(e,i.name);i.isDirectory()?n(r):i.isFile()&&t.push(r)}};return n(e),t.sort()}const ln=new Set([`.jsonl`]);function un(e){let t=e.lastIndexOf(`.`);return t!==-1&&ln.has(e.slice(t))}const dn=new Set([`.jsonl`,`.json`,`.txt`,`.log`,`.lock`,`.yaml`,`.yml`,`.ips`]);function fn(e){if(St(e))return!0;let t=e.lastIndexOf(`.`);return t!==-1&&dn.has(e.slice(t))}function pn(e){let
|
|
10
|
-
`:`not-running (${x})\n`;q(z(g,`state`,`server-status.txt`),k);let A=e.diagnosticReports===void 0?`not-collected (no collection attempted)`:Re(e.diagnosticReports,_);if(q(z(g,`state`,`diagnostic-reports-status.txt`),`${A}\n`),e.processDir&&H(e.processDir)){let t=z(g,`process`);U(t,{recursive:!0}),ce(e.processDir,t,{recursive:!0})}let j=e.redact===!0;j&&Tt({stagingDir:g,contentDir:t}),e.note&&q(z(g,`note.txt`),e.note);let M=null;e.scrubSecrets===!0&&(M=pn(g));for(let t of e.extraFiles??[])Q(t.sourcePath,z(g,`extra`,t.zipName??L(t.sourcePath)))||i.logger?.warn({sourcePath:t.sourcePath},`extra file missing; omitted from bundle`);let N=nn(r),ne=cn(g),P=[],F=0,re=0;for(let e of ne){let t=mn(g,e),n=he(e).size,r=un(t)?an(e):0;P.push({path:t,bytes:n,lines:r}),F+=n,(t.startsWith(`telemetry/`)||t.startsWith(`logs/`))&&(re+=sn(e))}let ie={applied:j};M!==null&&(ie.secretScrub=M);let I={schemaVersion:2,createdAt:te().toISOString(),ok:{version:d(),nodeVersion:T.nodeVersion,platform:T.platform,arch:T.arch},host:{desktop:E,language:D},contentDir:{pathSha256:rn(t),absolutePath:j?`<CONTENT_DIR>`:t},telemetry:{localSink:N,otlpPushEnabled:h()},redaction:ie,serverStatus:b,files:P};q(z(g,`manifest.json`),`${JSON.stringify(I,null,2)}\n`);let R=ne.some(e=>{try{return W(e,`utf-8`).includes(t)}catch{return!1}}),ae={stagedDiagnosticReports:_,totalBytes:F,fileCount:P.length,docNameCount:re,contentDirVisible:R,redacted:j},oe=!1;return{stagingDir:g,manifest:I,summary:ae,cleanup:()=>{oe||(oe=!0,K(g,{recursive:!0,force:!0}))}}}catch(e){throw K(g,{recursive:!0,force:!0}),e}}async function gn(e){let{collected:t,outputPath:n}=e,r=R(n);if(!H(r))throw Error(`ok diagnose bundle: parent directory does not exist: ${r}. Create it or pass --out with an existing parent.`);let i=new dt.ZipFile,a=cn(t.stagingDir);for(let e of a){let n=mn(t.stagingDir,e);i.addFile(e,n)}i.end();let o=le(n);return i.outputStream.pipe(o),await new Promise((e,t)=>{o.on(`close`,e),o.on(`error`,t),i.outputStream.on(`error`,t)}),n}function _n(e,t){let n=z(e,`.ok`,`config.yml`);if(H(n))try{let t=(0,ut.parse)(W(n,`utf-8`)),r=F(t)?t.content:void 0,i=F(r)?r.dir:void 0;if(typeof i==`string`&&i.length>0)return B(e,i)}catch(e){t?.warn({configPath:n,err:e},`bug-report: failed to read .ok/config.yml; falling back to project root as content dir`)}return B(e)}async function vn(e,t,n,r,i){let a=Xe(t,e.logger),o=await hn({contentDir:_n(t,e.logger),projectDir:t,redact:e.redact,scrubSecrets:e.redact,note:e.note,extraFiles:e.extraFiles,userLogFiles:[...et(a,e.userLogsDir??z(J(),`.ok`,`logs`)),...nt(e.cachesDir??z(J(),`Library`,`Caches`))],userStateFiles:rt(e.bugReportsDir??Y()),diagnosticReports:i,deps:{readDesktopEnv:n,readLanguage:r,logger:e.logger}});try{U(R(e.outputPath),{recursive:!0}),await gn({collected:o,outputPath:e.outputPath});let t=o.manifest.redaction.secretScrub;return{zipPath:e.outputPath,summary:{level:`full`,systemWide:!1,projectSlug:a,files:o.manifest.files.map(e=>e.path),redactions:t?.redactions??[],redactedLineCount:t?.redactedLineCount??0,generatedAt:o.manifest.createdAt}}}finally{o.cleanup()}}async function yn(e){let{projectDir:t}=e,n=e.readDesktopEnv??Jt,r=e.readLanguage??pt,i=()=>Je(e.diagnosticReportsDir??z(J(),`Library`,`Logs`,`DiagnosticReports`),new Date);if(e.level===`full`&&t!==void 0)return vn(e,t,n,r,i());let{zipPath:a,summary:o}=await lt({projectDir:t,redact:e.redact,revealDocNames:e.level===`full`,outputPath:e.outputPath,userLogsDir:e.userLogsDir,shipItLogFiles:nt(e.cachesDir??z(J(),`Library`,`Caches`)),bugReportLedgerFiles:rt(e.bugReportsDir??Y()),diagnosticReports:e.level===`full`?i():void 0,logger:e.logger,note:e.note,extraFiles:e.extraFiles,desktop:n(),language:r()});return{zipPath:a,summary:{level:e.level,systemWide:t===void 0,projectSlug:o.projectSlug,files:o.files,redactions:o.redactions,redactedLineCount:o.redactedLineCount,generatedAt:o.generatedAt}}}function $(e,t,n={}){let r=E(e,t),i;try{i=W(r,`utf-8`)}catch(e){return e&&typeof e==`object`&&`code`in e&&e.code===`ENOENT`?{status:`missing`,lockPath:r}:{status:`read-error`,lockPath:r,error:e instanceof Error?e.message:String(e)}}let a;try{a=JSON.parse(i)}catch{return{status:`corrupt`,lockPath:r}}let o=a&&typeof a==`object`?a:{},s=`machineId`in o&&typeof o.machineId==`string`?o.machineId!==(n.machineId??S()):`hostname`in o&&typeof o.hostname==`string`&&o.hostname!==(n.host??ve());if(!a||typeof a!=`object`||!_(a.pid))return{status:`corrupt`,lockPath:r,...s?{foreignHost:!0}:{}};let c=a.pid,l=`machineId`in o&&typeof o.machineId==`string`||`hostname`in o&&typeof o.hostname==`string`;return s?{status:`foreign-host`,lockPath:r,lock:a}:(n.isAlive??m)(c)?l?{status:`alive`,lockPath:r,lock:a}:{status:`unverified-owner`,lockPath:r,pid:c}:{status:`dead-pid`,lockPath:r,lock:a}}function bn(e){return e.status===`unverified-owner`?`Cannot verify shutdown: the server lock at ${e.lockPath} does not record its owning machine, and its recorded process ${e.pid} is still running on this machine. Check whether process ${e.pid} is an OpenKnowledge server. If it is, stop it and retry. Do not remove the lock file while that process is running.`:`Cannot verify shutdown: the server lock at ${e.lockPath} belongs to another machine. Stop OpenKnowledge on the owning machine. Confirm that no OpenKnowledge server is using this directory on the owning machine or any other machine sharing it. Only then remove the stale lock file at ${e.lockPath} and retry cleanup.`}function xn(e){return e.replace(/:\d+$/,``)}function Sn(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:xn(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:xn(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:xn(e[1]),owner:e[2],name:e[3]}}{let e=/^(?:[\w.\-~%]+@)?([\w.-]+):([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e?.[1].includes(`.`)||e&&t.startsWith(`git@`))return{protocol:`ssh`,hostname:e[1],owner:e[2],name:e[3]}}{let e=/^git:([\w.-]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:e[1],owner:e[2],name:e[3]}}if(!t.includes(`://`)&&!t.includes(`@`)&&!t.startsWith(`/`)){let e=/^([\w.-]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e)return{protocol:`https`,hostname:`github.com`,owner:e[1],name:e[2]}}return null}const Cn=[{hostDir:`.adal`,pruneRoot:`.adal`},{hostDir:`.aider-desk`,pruneRoot:`.aider-desk`},{hostDir:`.astrbot/data`,pruneRoot:`.astrbot`},{hostDir:`.augment`,pruneRoot:`.augment`},{hostDir:`.autohand`,pruneRoot:`.autohand`},{hostDir:`.bob`,pruneRoot:`.bob`},{hostDir:`.codeartsdoer`,pruneRoot:`.codeartsdoer`},{hostDir:`.codebuddy`,pruneRoot:`.codebuddy`},{hostDir:`.codeium/windsurf`,pruneRoot:`.codeium`},{hostDir:`.codemaker`,pruneRoot:`.codemaker`},{hostDir:`.codestudio`,pruneRoot:`.codestudio`},{hostDir:`.commandcode`,pruneRoot:`.commandcode`},{hostDir:`.config/crush`,pruneRoot:`.config/crush`},{hostDir:`.config/devin`,pruneRoot:`.config/devin`},{hostDir:`.config/goose`,pruneRoot:`.config/goose`},{hostDir:`.config/kimchi/harness`,pruneRoot:`.config/kimchi`},{hostDir:`.continue`,pruneRoot:`.continue`},{hostDir:`.factory`,pruneRoot:`.factory`},{hostDir:`.forge`,pruneRoot:`.forge`},{hostDir:`.grok`,pruneRoot:`.grok`},{hostDir:`.iflow`,pruneRoot:`.iflow`},{hostDir:`.inferencesh`,pruneRoot:`.inferencesh`},{hostDir:`.jazz`,pruneRoot:`.jazz`},{hostDir:`.junie`,pruneRoot:`.junie`},{hostDir:`.kilocode`,pruneRoot:`.kilocode`},{hostDir:`.kiro`,pruneRoot:`.kiro`},{hostDir:`.kode`,pruneRoot:`.kode`},{hostDir:`.lingma`,pruneRoot:`.lingma`},{hostDir:`.mcpjam`,pruneRoot:`.mcpjam`},{hostDir:`.moxby`,pruneRoot:`.moxby`},{hostDir:`.mux`,pruneRoot:`.mux`},{hostDir:`.neovate`,pruneRoot:`.neovate`},{hostDir:`.ona`,pruneRoot:`.ona`},{hostDir:`.openhands`,pruneRoot:`.openhands`},{hostDir:`.pochi`,pruneRoot:`.pochi`},{hostDir:`.qoder`,pruneRoot:`.qoder`},{hostDir:`.qoder-cn`,pruneRoot:`.qoder-cn`},{hostDir:`.qwen`,pruneRoot:`.qwen`},{hostDir:`.reasonix`,pruneRoot:`.reasonix`},{hostDir:`.roo`,pruneRoot:`.roo`},{hostDir:`.rovodev`,pruneRoot:`.rovodev`},{hostDir:`.snowflake/cortex`,pruneRoot:`.snowflake`},{hostDir:`.tabnine/agent`,pruneRoot:`.tabnine`},{hostDir:`.terramind`,pruneRoot:`.terramind`},{hostDir:`.tinycloud`,pruneRoot:`.tinycloud`},{hostDir:`.trae`,pruneRoot:`.trae`},{hostDir:`.trae-cn`,pruneRoot:`.trae-cn`},{hostDir:`.vibe`,pruneRoot:`.vibe`},{hostDir:`.zcode`,pruneRoot:`.zcode`},{hostDir:`.zencoder`,pruneRoot:`.zencoder`}],wn=[...y.map(e=>T[e]),`open-knowledge`];function Tn(e){if(!ae(e))throw Error(`skill cleanup requires an absolute home directory; got ${JSON.stringify(e)}`);let t=B(e);if(t===V||R(t)===t)throw Error(`skill cleanup refuses to operate on the filesystem root (${t})`);return t}function En(e,t){let n=oe(e,t);if(n.startsWith(`..`)||ae(n))return!1;let r=e;for(let e of n.split(V)){r=z(r,e);try{if(!ue(r).isDirectory())return!1}catch{return!1}}return!0}function Dn(e,t){try{return G(e).every(n=>t.has(z(e,n)))}catch{return!1}}function On(e){let t=Tn(e),n=[],r=[],i=new Set;for(let e of Cn){let a=z(t,e.hostDir,`skills`);if(!En(t,a))continue;let o=wn.map(e=>z(a,e)).filter(e=>H(e));n.push(...o);for(let e of o)i.add(e);let s=z(t,e.pruneRoot),c=a;for(;Dn(c,i)&&(r.push(c),i.add(c),c!==s);){let e=R(c);if(e===c||e===t||!e.startsWith(t+V))break;c=e}}return{skillDirs:n,emptyDirs:r}}function kn(e){try{if(!ue(e).isDirectory())return!1;let t=G(e);return t.length===0||t.includes(`SKILL.md`)}catch{return!1}}function An(e){let t=new Set,n=new Set;for(let r of Cn){let i=z(e,r.hostDir,`skills`);for(let e of wn)t.add(z(i,e));let a=z(e,r.pruneRoot),o=i;for(;n.add(o),o!==a;){let t=R(o);if(t===o||t===e||!t.startsWith(e+V))break;o=t}}return{skillDirs:t,emptyDirs:n}}function jn(e,t){let n=Tn(e),r=An(n),i=[...t.skillDirs.filter(e=>!r.skillDirs.has(e)),...t.emptyDirs.filter(e=>!r.emptyDirs.has(e))];if(i.length>0)throw Error(`refusing skill cleanup — ${i.length} path(s) outside the known legacy set: ${i.join(`, `)}`);let a=[];for(let e of t.skillDirs)if(En(n,e)&&kn(e))try{K(e,{recursive:!0,force:!0}),a.push(e)}catch{}for(let e of t.emptyDirs)if(En(n,e))try{me(e),a.push(e)}catch{}return a}function Mn(e){let t=Tn(e),n=[];for(let e of y){let i=T[e];n.push({path:z(t,`.agents`,`skills`,i),bundleId:e,scope:`central`});for(let a of r)n.push({path:z(t,a.skillsRoot,i),bundleId:e,scope:`host`,hostDir:a.hostDir})}return n}function Nn(e,t){let n=[];for(let r of Mn(e))if(r.bundleId===t)try{K(r.path,{recursive:!0,force:!0})}catch(e){n.push(e instanceof Error?e:Error(String(e)))}if(n.length>0)throw AggregateError(n,`Failed to remove ${n.length} path(s) for ${t}`)}function Pn(e){return e!=null&&e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function Fn(e,t=Date.now()){if(e===null)return`—`;let n=s(e,t);return n===`unknown`?`—`:n}function In(e){let t=R(e);return L(e)===`local`&&L(t)===`.ok`?R(t):L(e)===`.ok`?t:null}function Ln(e,t,n,r){if(t.status===`missing`||t.status===`corrupt`||t.status===`read-error`)return null;if(t.status===`unverified-owner`)return{directory:In(e),server:{port:null,status:t.status,pid:t.pid,startedAt:null,usage:null},ui:null,hostname:null,lockPath:t.lockPath,binary:null,command:null,isDesktop:!1};let i=t.lock,a=t.status===`alive`&&w(i)?{port:i.port,status:t.status,pid:i.pid,startedAt:i.startedAt,usage:r}:null;return{directory:i.worktreeRoot,server:{port:i.port,status:t.status,pid:i.pid,startedAt:i.startedAt,usage:r},ui:a,hostname:i.hostname,lockPath:t.lockPath,binary:n==null?null:b(n),command:n,isDesktop:Pn(n)}}function Rn(e){let t=e.server.status;switch(t){case`unverified-owner`:return`unverified`;case`alive`:return e.isDesktop?`desktop`:`running`;case`foreign-host`:return e.isDesktop?`desktop`:`foreign`;case`dead-pid`:return`stale`;default:return t}}const zn=new Set([`running`,`desktop`,`foreign`,`unverified`]);function Bn(e){switch(e){case`running`:return Z.default.green(e);case`desktop`:return Z.default.blue(e);case`foreign`:return Z.default.cyan(e);case`unverified`:case`stale`:return Z.default.yellow(e)}}function Vn(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function Hn(e){return`${Vn(e.server.usage)} | ${Vn(e.ui?.usage??null)}`}function Un(e){return`${e.server.port===null?`—`:e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null?`—`:String(e.ui.port)}`}function Wn(e){if(e.length===0)return`No open-knowledge servers found.`;let t=[`DIRECTORY`,`PORTS (API/UI)`,`CPU/MEM (API | UI)`,`STATUS`,`PID`,`STARTED`,`BINARY`],n=e.map(e=>[e.directory??`—`,Un(e),Hn(e),Rn(e),String(e.server.pid),Fn(e.server.startedAt),e.binary??`—`]),r=t.length,i=t.map(e=>e.length);for(let e of n)for(let t=0;t<r;t++)i[t]=Math.max(i[t]??0,(e[t]??``).length);let a=t.map((e,t)=>e.padEnd(i[t]??0)).join(` `).trimEnd(),o=e.map((e,t)=>{let a=n[t]??[],o=[];for(let t=0;t<r;t++){let n=(a[t]??``).padEnd(i[t]??0);if(t===3){let r=a[t]??``;n=Bn(Rn(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=Z.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
|
|
9
|
+
`)}\n`:null}catch{return null}}function Kt(e){let t=z(e,`.git`,`ok`);if(!H(t))return null;let n=I(`git`,[`-C`,t,`log`,`--oneline`,`-50`],D({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function qt(e){let t=z(e,`.git`,`ok`);if(!H(t))return null;let n=I(`git`,[`-C`,t,`for-each-ref`,`--sort=-creatordate`,`--count=50`,`--format=%(refname)%09%(creatordate:iso-strict)%09%(contents:subject)`,`refs/checkpoints/`],D({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function Jt(){let e=process.env.OK_DESKTOP_VERSION,t=process.env.OK_DESKTOP_PACKAGED,n=process.env.OK_DESKTOP_CHANNEL;return e===void 0||t===void 0||n===void 0?null:{electronVersion:e,packaged:t===`1`||t.toLowerCase()===`true`,channel:n}}function Yt(){return{nodeVersion:process.version,platform:ye(),arch:ge()}}function Xt(){return process.env.OTEL_SDK_DISABLED===`false`}function Zt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Qt(e){if(!H(e))return{};let t;try{t=(0,ut.parse)(W(e,`utf-8`))}catch(t){return console.warn(`[ok diagnose bundle] failed to parse ${e} for manifest config; manifest will report schema defaults. Reason: ${t instanceof Error?t.message:String(t)}`),{}}if(!Zt(t))return{};let n=t.telemetry;if(!Zt(n))return{};let r=n.localSink;return Zt(r)?r:{}}function $t(e){return typeof e==`boolean`?e:void 0}function en(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function tn(e){if(Zt(e))return en(e.maxBytes)}function nn(e){let t=Qt(p(`project`,e)),n=Qt(p(`project-local`,e));return{enabled:$t(n.enabled)??$t(t.enabled)??!0,spansMaxBytes:tn(n.spans)??tn(t.spans)??52428800,logsMaxBytes:tn(n.logs)??tn(t.logs)??26214400}}function rn(e){return Te(`sha256`).update(e).digest(`hex`)}function an(e){let t=W(e),n=0;for(let e=0;e<t.length;e++)t[e]===10&&n++;return n}const on=[`"doc.name"`,`"docName"`];function sn(e){let t=W(e,`utf-8`),n=0;for(let e of on){let r=t.indexOf(e);for(;r!==-1;)n++,r=t.indexOf(e,r+e.length)}return n}function Q(e,t){if(!H(e))return!1;try{return U(R(t),{recursive:!0}),e.endsWith(`.ips`)?q(t,He(W(e,`utf-8`))):ce(e,t),!0}catch{return!1}}function cn(e){let t=[],n=e=>{let r=G(e,{withFileTypes:!0});for(let i of r){let r=z(e,i.name);i.isDirectory()?n(r):i.isFile()&&t.push(r)}};return n(e),t.sort()}const ln=new Set([`.jsonl`]);function un(e){let t=e.lastIndexOf(`.`);return t!==-1&&ln.has(e.slice(t))}const dn=new Set([`.jsonl`,`.json`,`.txt`,`.log`,`.lock`,`.yaml`,`.yml`,`.ips`]);function fn(e){if(St(e))return!0;let t=e.lastIndexOf(`.`);return t!==-1&&dn.has(e.slice(t))}function pn(e){let t=[];for(let n of cn(e)){let r=mn(e,n);if(!fn(r))continue;let{redacted:i,patterns:a,lineCount:o}=l(W(n,`utf-8`));a.length!==0&&(q(n,i),t.push({file:r,lineCount:o,patterns:a}))}return{redactions:t,redactedLineCount:t.reduce((e,t)=>e+t.lineCount,0)}}function mn(e,t){return oe(e,t).split(V).join(`/`)}async function hn(e){let t=B(e.contentDir),n=B(e.projectDir??e.contentDir),i=e.deps??{},a=i.fetchAgentPresence??Ht,s=i.fetchAgentEffects??Ut,c=i.fetchWatcherRecent??Wt,l=i.readShadowHead??Kt,ee=i.readCheckpointRefs??qt,te=i.now??(()=>new Date),d=i.okVersion??(()=>re),f=i.readDesktopEnv??Jt,p=i.readLanguage??pt,m=i.readRuntime??Yt,h=i.isOtlpPushEnabled??Xt,g=de(z(xe(),`ok-bundle-`));try{U(z(g,`telemetry`),{recursive:!0}),U(z(g,`logs`),{recursive:!0}),U(z(g,`state`),{recursive:!0}),Q(Ft(n),z(g,`telemetry`,kt)),Q(It(n),z(g,`telemetry`,At)),Q(Lt(n),z(g,`logs`,jt)),Q(Rt(n),z(g,`logs`,Mt));for(let t of e.userLogFiles??[])Q(t,z(g,`logs`,L(t)));for(let t of e.userStateFiles??[])Q(t,z(g,o,L(t)));let _=0;for(let t of e.diagnosticReports?.files??[])Q(t,z(g,`diagnostic-reports`,L(t)))&&(_+=1);let v=z(n,`.ok`,`local`),y=z(v,`server.lock`),b=`not-running`,x=`no server.lock`,S=null;if(H(y)){Q(y,z(g,`state`,`server.lock`));try{let e=W(y,`utf-8`),t=JSON.parse(e);typeof t.port==`number`?S=t.port:x=`lock present but no port`}catch{x=`lock present but unparseable`}}if(S!==null){let e=await a(S);e===null?x=`agent-presence endpoint at :${S} unreachable`:(q(z(g,`state`,`agent-presence.json`),e),b=`running`,x=``);let t=await s(S);t!==null&&q(z(g,`state`,`agent-effects.json`),t);let n=await c(S);if(n!==null){let e=Gt(n);e!==null&&q(z(g,`state`,`watcher-recent.jsonl`),e)}}let C=l(t);C!==null&&q(z(g,`state`,`shadow-head.txt`),C);let w=ee(t);w!==null&&q(z(g,`state`,`checkpoint-refs.txt`),w),Q(zt(n),z(g,`state`,Nt)),Q(Bt(n),z(g,`state`,Pt)),Q(z(v,`last-spawn-error.log`),z(g,`state`,`last-spawn-error.log`)),Q(z(v,r),z(g,`state`,r)),Q(z(v,u),z(g,`state`,u));let T=m(),E=f(),D=p(),O={ok:{version:d(),nodeVersion:T.nodeVersion,platform:T.platform,arch:T.arch},host:{desktop:E,language:D}};q(z(g,`state`,`runtime.json`),`${JSON.stringify(O,null,2)}\n`);let k=b===`running`?`running
|
|
10
|
+
`:`not-running (${x})\n`;q(z(g,`state`,`server-status.txt`),k);let A=e.diagnosticReports===void 0?`not-collected (no collection attempted)`:Re(e.diagnosticReports,_);if(q(z(g,`state`,`diagnostic-reports-status.txt`),`${A}\n`),e.processDir&&H(e.processDir)){let t=z(g,`process`);U(t,{recursive:!0}),ce(e.processDir,t,{recursive:!0})}let j=e.redact===!0;j&&Tt({stagingDir:g,contentDir:t}),e.note&&q(z(g,`note.txt`),e.note);let M=null;e.scrubSecrets===!0&&(M=pn(g));for(let t of e.extraFiles??[])Q(t.sourcePath,z(g,`extra`,t.zipName??L(t.sourcePath)))||i.logger?.warn({sourcePath:t.sourcePath},`extra file missing; omitted from bundle`);let N=nn(n),ne=cn(g),P=[],F=0,re=0;for(let e of ne){let t=mn(g,e),n=he(e).size,r=un(t)?an(e):0;P.push({path:t,bytes:n,lines:r}),F+=n,(t.startsWith(`telemetry/`)||t.startsWith(`logs/`))&&(re+=sn(e))}let ie={applied:j};M!==null&&(ie.secretScrub=M);let I={schemaVersion:2,createdAt:te().toISOString(),ok:{version:d(),nodeVersion:T.nodeVersion,platform:T.platform,arch:T.arch},host:{desktop:E,language:D},contentDir:{pathSha256:rn(t),absolutePath:j?`<CONTENT_DIR>`:t},telemetry:{localSink:N,otlpPushEnabled:h()},redaction:ie,serverStatus:b,files:P};q(z(g,`manifest.json`),`${JSON.stringify(I,null,2)}\n`);let R=ne.some(e=>{try{return W(e,`utf-8`).includes(t)}catch{return!1}}),ae={stagedDiagnosticReports:_,totalBytes:F,fileCount:P.length,docNameCount:re,contentDirVisible:R,redacted:j},oe=!1;return{stagingDir:g,manifest:I,summary:ae,cleanup:()=>{oe||(oe=!0,K(g,{recursive:!0,force:!0}))}}}catch(e){throw K(g,{recursive:!0,force:!0}),e}}async function gn(e){let{collected:t,outputPath:n}=e,r=R(n);if(!H(r))throw Error(`ok diagnose bundle: parent directory does not exist: ${r}. Create it or pass --out with an existing parent.`);let i=new dt.ZipFile,a=cn(t.stagingDir);for(let e of a){let n=mn(t.stagingDir,e);i.addFile(e,n)}i.end();let o=le(n);return i.outputStream.pipe(o),await new Promise((e,t)=>{o.on(`close`,e),o.on(`error`,t),i.outputStream.on(`error`,t)}),n}function _n(e,t){let n=z(e,`.ok`,`config.yml`);if(H(n))try{let t=(0,ut.parse)(W(n,`utf-8`)),r=F(t)?t.content:void 0,i=F(r)?r.dir:void 0;if(typeof i==`string`&&i.length>0)return B(e,i)}catch(e){t?.warn({configPath:n,err:e},`bug-report: failed to read .ok/config.yml; falling back to project root as content dir`)}return B(e)}async function vn(e,t,n,r,i){let a=Xe(t,e.logger),o=await hn({contentDir:_n(t,e.logger),projectDir:t,redact:e.redact,scrubSecrets:e.redact,note:e.note,extraFiles:e.extraFiles,userLogFiles:[...et(a,e.userLogsDir??z(J(),`.ok`,`logs`)),...nt(e.cachesDir??z(J(),`Library`,`Caches`))],userStateFiles:rt(e.bugReportsDir??Y()),diagnosticReports:i,deps:{readDesktopEnv:n,readLanguage:r,logger:e.logger}});try{U(R(e.outputPath),{recursive:!0}),await gn({collected:o,outputPath:e.outputPath});let t=o.manifest.redaction.secretScrub;return{zipPath:e.outputPath,summary:{level:`full`,systemWide:!1,projectSlug:a,files:o.manifest.files.map(e=>e.path),redactions:t?.redactions??[],redactedLineCount:t?.redactedLineCount??0,generatedAt:o.manifest.createdAt}}}finally{o.cleanup()}}async function yn(e){let{projectDir:t}=e,n=e.readDesktopEnv??Jt,r=e.readLanguage??pt,i=()=>Je(e.diagnosticReportsDir??z(J(),`Library`,`Logs`,`DiagnosticReports`),new Date);if(e.level===`full`&&t!==void 0)return vn(e,t,n,r,i());let{zipPath:a,summary:o}=await lt({projectDir:t,redact:e.redact,revealDocNames:e.level===`full`,outputPath:e.outputPath,userLogsDir:e.userLogsDir,shipItLogFiles:nt(e.cachesDir??z(J(),`Library`,`Caches`)),bugReportLedgerFiles:rt(e.bugReportsDir??Y()),diagnosticReports:e.level===`full`?i():void 0,logger:e.logger,note:e.note,extraFiles:e.extraFiles,desktop:n(),language:r()});return{zipPath:a,summary:{level:e.level,systemWide:t===void 0,projectSlug:o.projectSlug,files:o.files,redactions:o.redactions,redactedLineCount:o.redactedLineCount,generatedAt:o.generatedAt}}}function $(e,t,n={}){let r=E(e,t),i;try{i=W(r,`utf-8`)}catch(e){return e&&typeof e==`object`&&`code`in e&&e.code===`ENOENT`?{status:`missing`,lockPath:r}:{status:`read-error`,lockPath:r,error:e instanceof Error?e.message:String(e)}}let a;try{a=JSON.parse(i)}catch{return{status:`corrupt`,lockPath:r}}let o=a&&typeof a==`object`?a:{},s=`machineId`in o&&typeof o.machineId==`string`?o.machineId!==(n.machineId??S()):`hostname`in o&&typeof o.hostname==`string`&&o.hostname!==(n.host??ve());if(!a||typeof a!=`object`||!_(a.pid))return{status:`corrupt`,lockPath:r,...s?{foreignHost:!0}:{}};let c=a.pid,l=`machineId`in o&&typeof o.machineId==`string`||`hostname`in o&&typeof o.hostname==`string`;return s?{status:`foreign-host`,lockPath:r,lock:a}:(n.isAlive??m)(c)?l?{status:`alive`,lockPath:r,lock:a}:{status:`unverified-owner`,lockPath:r,pid:c}:{status:`dead-pid`,lockPath:r,lock:a}}function bn(e){return e.status===`unverified-owner`?`Cannot verify shutdown: the server lock at ${e.lockPath} does not record its owning machine, and its recorded process ${e.pid} is still running on this machine. Check whether process ${e.pid} is an OpenKnowledge server. If it is, stop it and retry. Do not remove the lock file while that process is running.`:`Cannot verify shutdown: the server lock at ${e.lockPath} belongs to another machine. Stop OpenKnowledge on the owning machine. Confirm that no OpenKnowledge server is using this directory on the owning machine or any other machine sharing it. Only then remove the stale lock file at ${e.lockPath} and retry cleanup.`}function xn(e){return e.replace(/:\d+$/,``)}function Sn(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:xn(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:xn(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:xn(e[1]),owner:e[2],name:e[3]}}{let e=/^(?:[\w.\-~%]+@)?([\w.-]+):([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e?.[1].includes(`.`)||e&&t.startsWith(`git@`))return{protocol:`ssh`,hostname:e[1],owner:e[2],name:e[3]}}{let e=/^git:([\w.-]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:e[1],owner:e[2],name:e[3]}}if(!t.includes(`://`)&&!t.includes(`@`)&&!t.startsWith(`/`)){let e=/^([\w.-]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e)return{protocol:`https`,hostname:`github.com`,owner:e[1],name:e[2]}}return null}const Cn=[{hostDir:`.adal`,pruneRoot:`.adal`},{hostDir:`.aider-desk`,pruneRoot:`.aider-desk`},{hostDir:`.astrbot/data`,pruneRoot:`.astrbot`},{hostDir:`.augment`,pruneRoot:`.augment`},{hostDir:`.autohand`,pruneRoot:`.autohand`},{hostDir:`.bob`,pruneRoot:`.bob`},{hostDir:`.codeartsdoer`,pruneRoot:`.codeartsdoer`},{hostDir:`.codebuddy`,pruneRoot:`.codebuddy`},{hostDir:`.codeium/windsurf`,pruneRoot:`.codeium`},{hostDir:`.codemaker`,pruneRoot:`.codemaker`},{hostDir:`.codestudio`,pruneRoot:`.codestudio`},{hostDir:`.commandcode`,pruneRoot:`.commandcode`},{hostDir:`.config/crush`,pruneRoot:`.config/crush`},{hostDir:`.config/devin`,pruneRoot:`.config/devin`},{hostDir:`.config/goose`,pruneRoot:`.config/goose`},{hostDir:`.config/kimchi/harness`,pruneRoot:`.config/kimchi`},{hostDir:`.continue`,pruneRoot:`.continue`},{hostDir:`.factory`,pruneRoot:`.factory`},{hostDir:`.forge`,pruneRoot:`.forge`},{hostDir:`.grok`,pruneRoot:`.grok`},{hostDir:`.iflow`,pruneRoot:`.iflow`},{hostDir:`.inferencesh`,pruneRoot:`.inferencesh`},{hostDir:`.jazz`,pruneRoot:`.jazz`},{hostDir:`.junie`,pruneRoot:`.junie`},{hostDir:`.kilocode`,pruneRoot:`.kilocode`},{hostDir:`.kiro`,pruneRoot:`.kiro`},{hostDir:`.kode`,pruneRoot:`.kode`},{hostDir:`.lingma`,pruneRoot:`.lingma`},{hostDir:`.mcpjam`,pruneRoot:`.mcpjam`},{hostDir:`.moxby`,pruneRoot:`.moxby`},{hostDir:`.mux`,pruneRoot:`.mux`},{hostDir:`.neovate`,pruneRoot:`.neovate`},{hostDir:`.ona`,pruneRoot:`.ona`},{hostDir:`.openhands`,pruneRoot:`.openhands`},{hostDir:`.pochi`,pruneRoot:`.pochi`},{hostDir:`.qoder`,pruneRoot:`.qoder`},{hostDir:`.qoder-cn`,pruneRoot:`.qoder-cn`},{hostDir:`.qwen`,pruneRoot:`.qwen`},{hostDir:`.reasonix`,pruneRoot:`.reasonix`},{hostDir:`.roo`,pruneRoot:`.roo`},{hostDir:`.rovodev`,pruneRoot:`.rovodev`},{hostDir:`.snowflake/cortex`,pruneRoot:`.snowflake`},{hostDir:`.tabnine/agent`,pruneRoot:`.tabnine`},{hostDir:`.terramind`,pruneRoot:`.terramind`},{hostDir:`.tinycloud`,pruneRoot:`.tinycloud`},{hostDir:`.trae`,pruneRoot:`.trae`},{hostDir:`.trae-cn`,pruneRoot:`.trae-cn`},{hostDir:`.vibe`,pruneRoot:`.vibe`},{hostDir:`.zcode`,pruneRoot:`.zcode`},{hostDir:`.zencoder`,pruneRoot:`.zencoder`}],wn=[...y.map(e=>T[e]),`open-knowledge`];function Tn(e){if(!ae(e))throw Error(`skill cleanup requires an absolute home directory; got ${JSON.stringify(e)}`);let t=B(e);if(t===V||R(t)===t)throw Error(`skill cleanup refuses to operate on the filesystem root (${t})`);return t}function En(e,t){let n=oe(e,t);if(n.startsWith(`..`)||ae(n))return!1;let r=e;for(let e of n.split(V)){r=z(r,e);try{if(!ue(r).isDirectory())return!1}catch{return!1}}return!0}function Dn(e,t){try{return G(e).every(n=>t.has(z(e,n)))}catch{return!1}}function On(e){let t=Tn(e),n=[],r=[],i=new Set;for(let e of Cn){let a=z(t,e.hostDir,`skills`);if(!En(t,a))continue;let o=wn.map(e=>z(a,e)).filter(e=>H(e));n.push(...o);for(let e of o)i.add(e);let s=z(t,e.pruneRoot),c=a;for(;Dn(c,i)&&(r.push(c),i.add(c),c!==s);){let e=R(c);if(e===c||e===t||!e.startsWith(t+V))break;c=e}}return{skillDirs:n,emptyDirs:r}}function kn(e){try{if(!ue(e).isDirectory())return!1;let t=G(e);return t.length===0||t.includes(`SKILL.md`)}catch{return!1}}function An(e){let t=new Set,n=new Set;for(let r of Cn){let i=z(e,r.hostDir,`skills`);for(let e of wn)t.add(z(i,e));let a=z(e,r.pruneRoot),o=i;for(;n.add(o),o!==a;){let t=R(o);if(t===o||t===e||!t.startsWith(e+V))break;o=t}}return{skillDirs:t,emptyDirs:n}}function jn(e,t){let n=Tn(e),r=An(n),i=[...t.skillDirs.filter(e=>!r.skillDirs.has(e)),...t.emptyDirs.filter(e=>!r.emptyDirs.has(e))];if(i.length>0)throw Error(`refusing skill cleanup — ${i.length} path(s) outside the known legacy set: ${i.join(`, `)}`);let a=[];for(let e of t.skillDirs)if(En(n,e)&&kn(e))try{K(e,{recursive:!0,force:!0}),a.push(e)}catch{}for(let e of t.emptyDirs)if(En(n,e))try{me(e),a.push(e)}catch{}return a}function Mn(e){let t=Tn(e),n=[];for(let e of y){let r=T[e];n.push({path:z(t,`.agents`,`skills`,r),bundleId:e,scope:`central`});for(let i of ee)n.push({path:z(t,i.skillsRoot,r),bundleId:e,scope:`host`,hostDir:i.hostDir})}return n}function Nn(e,t){let n=[];for(let r of Mn(e))if(r.bundleId===t)try{K(r.path,{recursive:!0,force:!0})}catch(e){n.push(e instanceof Error?e:Error(String(e)))}if(n.length>0)throw AggregateError(n,`Failed to remove ${n.length} path(s) for ${t}`)}function Pn(e){return e!=null&&e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function Fn(e,t=Date.now()){if(e===null)return`—`;let n=a(e,t);return n===`unknown`?`—`:n}function In(e){let t=R(e);return L(e)===`local`&&L(t)===`.ok`?R(t):L(e)===`.ok`?t:null}function Ln(e,t,n,r){if(t.status===`missing`||t.status===`corrupt`||t.status===`read-error`)return null;if(t.status===`unverified-owner`)return{directory:In(e),server:{port:null,status:t.status,pid:t.pid,startedAt:null,usage:null},ui:null,hostname:null,lockPath:t.lockPath,binary:null,command:null,isDesktop:!1};let i=t.lock,a=t.status===`alive`&&w(i)?{port:i.port,status:t.status,pid:i.pid,startedAt:i.startedAt,usage:r}:null;return{directory:i.worktreeRoot,server:{port:i.port,status:t.status,pid:i.pid,startedAt:i.startedAt,usage:r},ui:a,hostname:i.hostname,lockPath:t.lockPath,binary:n==null?null:b(n),command:n,isDesktop:Pn(n)}}function Rn(e){let t=e.server.status;switch(t){case`unverified-owner`:return`unverified`;case`alive`:return e.isDesktop?`desktop`:`running`;case`foreign-host`:return e.isDesktop?`desktop`:`foreign`;case`dead-pid`:return`stale`;default:return t}}const zn=new Set([`running`,`desktop`,`foreign`,`unverified`]);function Bn(e){switch(e){case`running`:return Z.default.green(e);case`desktop`:return Z.default.blue(e);case`foreign`:return Z.default.cyan(e);case`unverified`:case`stale`:return Z.default.yellow(e)}}function Vn(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function Hn(e){return`${Vn(e.server.usage)} | ${Vn(e.ui?.usage??null)}`}function Un(e){return`${e.server.port===null?`—`:e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null?`—`:String(e.ui.port)}`}function Wn(e){if(e.length===0)return`No open-knowledge servers found.`;let t=[`DIRECTORY`,`PORTS (API/UI)`,`CPU/MEM (API | UI)`,`STATUS`,`PID`,`STARTED`,`BINARY`],n=e.map(e=>[e.directory??`—`,Un(e),Hn(e),Rn(e),String(e.server.pid),Fn(e.server.startedAt),e.binary??`—`]),r=t.length,i=t.map(e=>e.length);for(let e of n)for(let t=0;t<r;t++)i[t]=Math.max(i[t]??0,(e[t]??``).length);let a=t.map((e,t)=>e.padEnd(i[t]??0)).join(` `).trimEnd(),o=e.map((e,t)=>{let a=n[t]??[],o=[];for(let t=0;t<r;t++){let n=(a[t]??``).padEnd(i[t]??0);if(t===3){let r=a[t]??``;n=Bn(Rn(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=Z.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
|
|
11
11
|
`)}async function Gn(e={}){let t=e.discover??O,n=e.inspect??(e=>$(e,`server`)),r=e.log??(e=>console.log(e)),i=e.resolveCommand??v,a=e.resolveUsage??f,o=await t(),s=[];for(let e of o){let t=n(e),r=Ln(e,t,t.status===`missing`||t.status===`corrupt`||t.status===`read-error`||t.status===`unverified-owner`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`||t.status===`read-error`||t.status===`unverified-owner`?null:a(t.lock.pid));r!=null&&s.push(r)}if(e.json){let e=s.map(e=>({...e,displayStatus:Rn(e)}));r(JSON.stringify(e,null,2));return}r(Wn(e.all?s:s.filter(e=>zn.has(Rn(e)))))}function Kn(){return new A(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale entries (foreign and unverified entries already show)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await Gn({all:t.all===!0||e===`all`,json:t.json===!0})})}async function qn(e,t=N()){let n=$(e,`server`);if(n.status!==`alive`&&n.status!==`foreign-host`)return null;let r=x(n.lock);if(r===null)return null;try{let n=await fetch(`${r}/api/server-info`,{signal:AbortSignal.timeout(1500),redirect:`manual`});if(!n.ok)return t?.warn({lockDir:e,baseUrl:r,outcome:`http-error`,status:n.status},`stop client-probe failed`),null;let i=(await n.json())?.collabClients;return typeof i==`number`&&Number.isFinite(i)?i:(t?.warn({lockDir:e,baseUrl:r,outcome:`no-client-count`,received:typeof i},`stop client-probe failed`),null)}catch(n){return t?.warn({lockDir:e,baseUrl:r,outcome:`unreachable`,err:n},`stop client-probe failed`),null}}function Jn(e,t={}){return{targets:Xn(e,t.isAlive??m)?[{name:`server`,pid:e.lock.pid,port:e.lock.port}]:[]}}async function Yn(e){let t=e.inspect??(()=>$(e.lockDir,`server`)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=e.probeClients??qn,o=e.logger??N(),s=Jn(t(),{isAlive:e.isAlive});if(s.targets.length===0)return r(`No running open-knowledge processes.`),o?.info({lockDir:e.lockDir,targets:0},`stop found nothing to signal`),{stopped:[],failed:[],hadTargets:!1};if(e.force!==!0){let t=await a(e.lockDir,o);if(t!==null&&t>0)return i(`Not stopping: ${t} collaboration client${t===1?``:`s`} (editor window${t===1?``:`s`} or agents) still connected to the server at ${e.lockDir}. Close them, or re-run with --force to terminate anyway.`),o?.warn({lockDir:e.lockDir,clients:t,pids:s.targets.map(e=>e.pid)},`stop declined: live collaboration clients`),{stopped:[],failed:[],hadTargets:!0,declined:{clients:t}}}let c=[],l=[];for(let e of s.targets)try{n(e.pid,`SIGTERM`),c.push(e)}catch(t){l.push({target:e,error:t instanceof Error?t.message:String(t)})}return c.length>0&&r(`Stopped: ${c.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `)}`),o?.info({lockDir:e.lockDir,signalled:c.map(e=>({name:e.name,pid:e.pid,port:e.port})),failed:l.map(({target:e,error:t})=>({pid:e.pid,error:t})),forced:e.force===!0},`stop signalled processes`),l.length>0&&i(`Failed to stop: ${l.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `)}`),{stopped:c,failed:l,hadTargets:!0}}function Xn(e,t){return e.status===`alive`||e.status===`foreign-host`&&t(e.lock.pid)}async function Zn(e,t=m){let n=await O(),r=null;for(let i of n){let n=$(i,`server`);if(Xn(n,t)){if(n.lock.port===e)return i;r===null&&n.lock.pid===e&&(r=i)}}return r}async function Qn(e,t){let n=await Yn({lockDir:e,force:t});return(n.failed.length>0||n.declined!==void 0)&&(process.exitCode=1),n}function $n(e,t,n={}){return t===0?`Nothing was running for ${e}, and no other open-knowledge servers are running.`:`Nothing was running for ${e}. ${t} other open-knowledge server${t===1?` is`:`s are`} running${n.listingFollows===!0?``:" — run `ok ps` to list them"}.`}async function er(e){let t=await O(),n=0;for(let r of t)r!==e&&Xn($(r,`server`),m)&&n++;return n}function tr(e){return new A(`stop`).description(`Stop open-knowledge server(s). With no argument: stops the server for the enclosing project — run it from anywhere inside the project. Pass a port number, a directory path, or "all" to target globally.`).argument(`[target...]`,`port number, directory path (spaces OK), or "all"`).option(`--force`,`Stop even when editor windows or agents are still connected to the server`).action(async(t,n)=>{let r=n.force===!0,i=t.length===0?void 0:t.join(` `);if(i===void 0){e();let t=C(process.cwd()),n=await Yn({lockDir:t,force:r,log:()=>{}});if(n.hadTargets){if(n.stopped.length>0){let e=n.stopped.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);console.log(`Stopped: ${e}`)}(n.failed.length>0||n.declined!==void 0)&&(process.exitCode=1)}else{let e=await er(t);console.log($n(process.cwd(),e,{listingFollows:e>0})),e>0&&await Gn({})}return}if(i===`all`){let e=await O();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let n of e)Xn($(n,`server`),m)&&(await Qn(n,r),t++);t===0&&console.log(`No running open-knowledge servers found.`);return}if(/^\d+$/.test(i)){let e=Number.parseInt(i,10),t=await Zn(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}await Qn(t,r);return}let a=B(Ae(),i),o=C(a),s=[],c=await Yn({lockDir:o,force:r,log:e=>s.push(e)});if((c.failed.length>0||c.declined!==void 0)&&(process.exitCode=1),c.hadTargets)for(let e of s)console.log(e);else console.log($n(a,await er(o)))})}export{Ie as C,De as E,Fe as S,ke as T,Je as _,jn as a,Ne as b,Mn as c,$ as d,yn as f,Y as g,Ye as h,Kn as i,Sn as l,gn as m,Yn as n,On as o,hn as p,tr as r,Nn as s,qn as t,bn as u,Re as v,Ae as w,Me as x,je as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{S as e,m as t,p as n,r}from"./start-DWDyuoi5.mjs";export{r as bootStartServer,n as resolveBundledReactShellDir,t as resolveHost,e as startCommand};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`)){let e=r.replace(ge,``),i=pe.exec(e)?.[1];if(i){n={login:i,active:!1},t.push(n);continue}if(me.test(e)){n=void 0;continue}n&&he.test(e)&&(n.active=!0)}return t}const ve={mode:`published`,skipAvailabilityCheck:!0,replaceEntry:!0};function K(){return{action:`failed`,errorId:`write-failed`}}function q(){return{action:`skipped-missing`,errorId:`surface-missing`}}function J(e,t,n){l(`agent-integrations-apply`).warn({editor:e,path:t,reason:n},`skill write failed`)}function Y(){return{action:`skipped-unsupported`,errorId:`no-writer`}}function ye(e){switch(e){case`removed`:return{action:`removed`};case`not-present`:return{action:`no-op`};case`left-foreign`:return{action:`skipped-foreign`,errorId:`foreign-artifact`};case`declined`:return{action:`declined`,errorId:`write-declined`}}}function be(e,t,n,r,i){let a=b[e];try{let o=A(a,t,n,r,i);return o.kind===`removed`&&o.trustDetail&&l(`agent-integrations-apply`).warn({editor:e,path:r??a.configPath(t,n),trust:o.trust,trustDetail:o.trustDetail},`MCP config removal retained Pi folder trust`),ye(o.kind)}catch(i){return l(`agent-integrations-apply`).warn({editor:e,path:r??a.configPath(t,n),reason:i instanceof Error?i.message:String(i)},`MCP config removal failed`),K()}}async function xe(e,t,n){if(b[e].scope!==`global`)return q();if(n===`absent`)return be(e,``,t.home,void 0,t.env);let r=(await x({editors:[e],home:t.home,replaceEntry:!0})).find(t=>t.editorId===e);if(r===void 0)return K();switch(r.action){case`written`:case`overwritten`:return{action:r.action};case`declined`:return{action:`declined`,errorId:`write-declined`};case`skipped-missing`:return q();case`skipped-flag`:return Y();default:return K()}}function Se(e,t,n){let i=r[e];if(i===null)return q();let a=re(t.cwd,i);if(n===`absent`)return be(e,t.cwd,t.home,a,t.env);let o=w(b[e],t.cwd,ve,void 0,a);switch(o.action){case`written`:case`overwritten`:return{action:o.action};case`declined`:return{action:`declined`,errorId:`write-declined`};default:return K()}}function Ce(e,t,n){let r=t.home??ae();if(n===`absent`){let t=M(e,r);switch(t.action){case`removed`:return{action:`removed`};case`not-present`:return{action:`no-op`};case`skipped-unsupported`:return q();case`failed`:return J(e,t.path,t.error),K()}}let i=T(e,r);switch(i.action){case`written`:return{action:`written`};case`overwritten`:return{action:`overwritten`};case`skipped-unsupported`:return q();case`failed`:return J(e,i.path,i.error),K()}}function we(e,t,n){if(n===`absent`){let n=_(b[e],t.cwd);switch(n.action){case`removed`:return{action:`removed`};case`not-present`:return{action:`no-op`};case`skipped-unsupported`:return q();case`failed`:return J(e,n.path,n.error),K()}}let r=v(b[e],t.cwd);switch(r.action){case`written`:return{action:`written`};case`overwritten`:return{action:`overwritten`};case`skipped-unsupported`:return q();case`skipped-prerequisite`:return{action:`skipped-prerequisite`,errorId:`dependency-failed`};case`failed`:return J(e,r.path,r.error),K()}}function Te(e){return t=>{if(t.pathId===void 0)return Y();let r=n(t.pathId);if(r===null||r.kind===`central-skill-store`)return Y();switch(r.kind){case`editor-user-config`:return xe(r.editor,e,t.desired);case`editor-project-config`:return Se(r.editor,e,t.desired);case`editor-project-skill-root`:return we(r.editor,e,t.desired);case`editor-user-skill-root`:return Ce(r.editor,e,t.desired)}}}function Ee(e,t){return e.bind?.[0]??t.HOST??`127.0.0.1`}function De(e){if(e===`server`)return e;throw new g(`--only must be 'server'`)}function Oe(e=V){let t=import.meta.dirname??new URL(`.`,import.meta.url).pathname;return[B(t,`public`),B(t,`../../app/dist`),B(t,`../../../app/dist`)].find(t=>e(t))}function ke(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 Ae(t){if(t===`off`)return`off`;if(!e.test(t))throw new g(`--idle-shutdown must be 'off' or a duration like 90s, 30m, 2h`);return t}function je(e){return e===`localhost`||e===`::1`||e===`[::1]`||e.startsWith(`127.`)}function Me(e){return!e.flagBindSet&&!e.okBindSet&&e.hostEnvSet&&e.fileBindCount>1}function Ne(e){return!e.openBrowser||e.ephemeral||e.only===`server`||!e.servesUi?!1:(e.explicitOn||je(e.host))&&e.isTTY}function Pe(e,t){let n;try{n=new URL(t)}catch{throw new g(`${e} is not a valid URL: ${t}`)}if(n.protocol!==`http:`&&n.protocol!==`https:`)throw new g(`${e} must be an http(s) origin (got: ${t})`);return t}function Fe(e){return Pe(`--external-url`,e)}function Ie(e){let t=R(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var X=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}},Z=class extends Error{projectDir;constructor(e){super(`--project-dir must be a throwaway ${p}* directory under the OS temp dir. Refusing to write ephemeral session state into ${e}. Omit --project-dir to let ok start create (and clean up) its own.`),this.name=`EphemeralProjectDirNotThrowawayError`,this.projectDir=e}};function Q(e,t={}){let n=t.tmpdirFn??oe,r=t.realpathFn??ie,i=e=>{try{return r(e)}catch(t){return t.code===`ENOENT`?B(e):null}},a=B(e),o;try{o=r(a)}catch(e){if(e.code===`ENOENT`){let e=i(z(a));o=e===null?null:B(e,R(a))}else o=null}if(o===null)return!1;let s=i(n());return s!==null&&z(o)===s&&R(o).startsWith(`ok-ephemeral-`)}function Le(e,t,n=e=>se(e,{recursive:!0,force:!0})){return async()=>{try{await e()}finally{if(Q(t))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`)}else process.stderr.write(`[start] leaving ${t} in place: only ${p}* dirs under the OS temp dir are removed on ephemeral teardown\n`)}}}function $(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 Re(e){let{config:t,cwd:n,host:r}=e,i=e.skipAutoInit??!1,a=e.idleThresholdMs===void 0?18e5:e.idleThresholdMs,{existsSync:o,mkdirSync:s}=await import(`node:fs`),{basename:c,dirname:l,resolve:u}=await import(`node:path`),{bootServer:f,createEphemeralProjectDir:p,getLogger:g,resolveContentDir:_,resolveLockDir:v,seedEphemeralProjectDir:y,waitForServerLockDrain:b}=await import(`./dist-DeiwO3MR.mjs`),x=e.log??g(`start`),C=e.singleFile!==void 0,w=C?h(e.singleFile).canonicalFilePath:void 0,T=w?l(w):void 0,D=w?c(w):void 0,O,A=!1;if(T!==void 0){if(e.projectDir!==void 0){if(O=e.projectDir,!Q(O))throw new Z(O);o(u(O,`.ok`,`config.yml`))||y(O,T)}else O=p(T),A=!0}let j=async()=>{if(!(!A||O===void 0)){if(!Q(O)){x.warn({ephemeralProjectDir:O},`[start] refusing to reap self-provisioned ephemeral dir: no longer resolves to an ok-ephemeral-* temp dir`);return}try{await se(O,{recursive:!0,force:!0})}catch(e){x.warn({err:e,ephemeralProjectDir:O},`[start] failed to reap self-provisioned ephemeral temp dir`)}}},M=O;if(!C){if(!i&&!m(n))throw new X(n);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{e.severity===`info`?x.debug({event:e},`[start] reclaim sweep event`):x.warn({event:e},`[start] reclaim sweep reported a problem`)};try{let i=(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-B4GpHKFe.mjs`)).repairMcpConfigs)({projectDir:n,reclaimDisableEnv:t,logger:r}).outcomes.filter(e=>e.outcome!==`no-entry`&&e.outcome!==`canonical`&&e.outcome!==`repaired`&&e.outcome!==`foreign`);i.length>0&&x.warn({unhealed:i},`[start] reclaim sweep left entries it could not heal`)}catch(e){x.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-DP6KyVNN.mjs`)).repairLaunchJson)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){x.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}}let P=T??_(t,n);!C&&!o(P)&&(s(P,{recursive:!0}),x.info({contentDir:P},`Created content directory`));let ne=F(),I=d(),L;try{{let e=v(O??n),t=Date.now(),r=await b(e);r!==`no-drain`&&x.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`)}L=await f({config:t,contentDir:P,projectDir:O??n,contentRoot:C?void 0:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:H,detectGhAccounts:de,tokenStore:ne,embeddingsKeyStore:I,mcpTomlEditor:S(),...C?{ephemeral:!0,singleDocRelPath:D,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],probeHarnessManagedMcpEntry:(e,t)=>k(e,t),probePiAcpBridge:e=>E(e),ensurePiAcpBridge:(e,t)=>N(e,void 0,void 0,void 0,t),agentIntegrations:(()=>{let e={cwd:O??n,home:ae(),env:process.env};return{probe:te(e),execute:Te(e),userSkillPresentAnywhere:ee}})(),idleShutdownMs:a,...e.serverRuntime===void 0?{}:{serverRuntime:e.serverRuntime},...e.bind===void 0?{}:{bind:e.bind},skipAutoInit:!0,idleShutdownHandler:t=>{let n=t;return $(M===void 0?n:Le(n,M),{log:x,exit:e.idleExit})},log:x,...e.serveContentAssets===void 0?{}:{serveContentAssets:e.serveContentAssets},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}})}catch(e){throw await j(),e}let R=L.destroy,z=A?async()=>{try{await R()}finally{await j()}}:R;return{httpServer:L.httpServer,destroy:z,lockDir:L.lockDir,contentDir:P,port:L.port,ready:L.ready,degraded:L.degraded}}function ze(e,t,n=()=>u({absPath:c(`user`,process.cwd()),sideline:!1,warn:()=>{}}).value){return t===void 0?e:n()}function Be(e){if(e===`browser`||e===`app`)return e;throw new g(`--mode must be 'browser' or 'app'`)}function Ve(e){return e.OK_CONSOLE_LEVEL!==void 0||e.LOG_LEVEL!==void 0?null:`warn`}function He(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 Ue(e,n){let r=ze(e,n.singleFile),c=Ve(process.env);c!==null&&(process.env.OK_CONSOLE_LEVEL=c);let{renderBanner:l}=await import(`./banner-kywHhVaC.mjs`),{accent:u,dim:d,error:f,warning:p}=await import(`./colors-SgU3JHQu.mjs`),m=process.cwd();process.title=Ie(m);let h;try{h=t(process.env)}catch(e){throw e instanceof o&&(console.error(f(e.message)),process.exit(78)),e}for(let e of h.diagnostics)console.warn(p(`[config] ${e.message}`));let g=s(r,h.layer),_=h.overrides.some(e=>e.envVar===`OK_BIND`),v=n.bind!==void 0&&n.bind.length>0?n.bind:void 0,y=process.env.HOST,b=y!==void 0&&y.trim()!==``?y:void 0,x=a(g),S=v??(_||b===void 0?[...x.bind]:[b]);Me({flagBindSet:v!==void 0,okBindSet:_,hostEnvSet:b!==void 0,fileBindCount:x.bind.length})&&console.warn(p(`[config] HOST=${b} overrides server.bind — dropping the file-configured addresses (${x.bind.join(`, `)}). Use OK_BIND with a space-separated list to keep multiple binds.`));let C=S[0]??`127.0.0.1`,w=S,T=n.externalUrl,E=a(s(g,{server:{bind:w,...T===void 0?{}:{externalUrl:T}}}));if(E.allowExternal&&(!E.loopbackOnly||E.externalUrl)){let e=E.externalUrl??E.bind.join(`, `);console.warn(p([``,`⚠ 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 D=n.port===void 0?void 0:Number(n.port),O=h.overrides.find(e=>e.envVar===`PORT`)?.value,ee=D??O??r.server?.port,k=ke({explicitDir:n.reactShellDistDir,only:n.only,findBundledDir:Oe}),A=k.dir;k.missingBundle&&console.warn(`bundled web UI not found — serving /api and /mcp only. Reinstall @inkeep/open-knowledge, or build packages/app in a source checkout.`);let j;try{j=await Re({config:r,cwd:m,host:C,port:ee,bind:w,...n.serveContentAssets===void 0?{}:{serveContentAssets:n.serveContentAssets},...A?{reactShellDistDir:A}:{},idleThresholdMs:
|
|
1
|
+
import{Hu as e,Io as t,Ld as n,Rc as r,Rs as i,Vs as a,fa as o,vt as s}from"./md-manager-BGnqyqi1-RmPtbV-6.mjs";import{Fo as c,Ko as l,No as u,ci as d,ii as f,k as p,qr as m,xi as h}from"./dist-CdMoMubk.mjs";import{Ct as g,I as _,R as v,St as y,Y as b,b as x,lt as S,wt as C,y as w}from"./init-Co_mDPzI.mjs";import{a as T,c as E,d as D,f as O,i as ee,n as k,o as A,p as j,r as M,s as N,t as te,u as P,v as F}from"./registry-probes-BjsDFB65.mjs";import{n as ne}from"./constants-D7ISUGXs.mjs";import{execFileSync as I,spawn as L}from"node:child_process";import{basename as R,dirname as z,join as re,resolve as B}from"node:path";import{existsSync as V,realpathSync as ie}from"node:fs";import{homedir as ae,tmpdir as oe}from"node:os";import{rm as se}from"node:fs/promises";import{setTimeout as ce}from"node:timers/promises";const le=[`/opt/homebrew/bin/gh`,`/usr/local/bin/gh`,`/opt/local/bin/gh`,`/snap/bin/gh`,`/usr/bin/gh`],ue={encoding:`utf-8`,stdio:[`ignore`,`pipe`,`pipe`],timeout:5e3,windowsHide:!0};function H(e,t={}){let{login:n}=t,r=t._exec??I,i=U(t._fileExists??V),a=e?[`--hostname`,e]:[];if(n){let e=W(r,i,[`auth`,`token`,...a,`--user`,n]);if(e)return{available:!0,token:e,resolvedLogin:n,fallback:!1}}let o=W(r,i,[`auth`,`token`,...a]);return o?n?{available:!0,token:o,fallback:!0}:{available:!0,token:o}:{available:!1}}function U(e){return[`gh`,...le.filter(e)]}function W(e,t,n){for(let r of t)try{let t=e(r,n,ue).toString().trim();if(t.length>0)return t}catch{}}function de(e,t={}){let n=t._exec??I,r=U(t._fileExists??V),i=[`auth`,`status`,...e?[`--hostname`,e]:[]],a=W(n,r,[...i,`--json`,`hosts`]);if(a!==void 0){let t=fe(a,e);if(t)return t}let o=W(n,r,i);if(o!==void 0){let e=_e(o);if(e.length>0)return e}}function G(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function fe(e,t){let n;try{n=JSON.parse(e)}catch{return}let r=G(G(n)?.hosts);if(!r||t!==void 0&&r[t]===void 0)return;let i=t===void 0?Object.values(r):[r[t]],a=[];for(let e of i){if(!Array.isArray(e))return;for(let t of e){let e=G(t);if(!e)continue;let n=e.login;typeof n==`string`&&n.length!==0&&a.push({login:n,active:e.active===!0})}}return a}const pe=/Logged in to \S+ account (\S+) \(/,me=/(?:Failed to log in to|Timeout trying to log in to) \S+/,he=/^\s*-\s*Active account:\s*true\s*$/,ge=/\u001b\[[0-9;]*m/g;function _e(e){let t=[],n;for(let r of e.split(`
|
|
2
|
+
`)){let e=r.replace(ge,``),i=pe.exec(e)?.[1];if(i){n={login:i,active:!1},t.push(n);continue}if(me.test(e)){n=void 0;continue}n&&he.test(e)&&(n.active=!0)}return t}const ve={mode:`published`,skipAvailabilityCheck:!0,replaceEntry:!0};function K(){return{action:`failed`,errorId:`write-failed`}}function q(){return{action:`skipped-missing`,errorId:`surface-missing`}}function J(e,t,n){l(`agent-integrations-apply`).warn({editor:e,path:t,reason:n},`skill write failed`)}function Y(){return{action:`skipped-unsupported`,errorId:`no-writer`}}function ye(e){switch(e){case`removed`:return{action:`removed`};case`not-present`:return{action:`no-op`};case`left-foreign`:return{action:`skipped-foreign`,errorId:`foreign-artifact`};case`declined`:return{action:`declined`,errorId:`write-declined`}}}function be(e,t,n,r,i){let a=b[e];try{let o=A(a,t,n,r,i);return o.kind===`removed`&&o.trustDetail&&l(`agent-integrations-apply`).warn({editor:e,path:r??a.configPath(t,n),trust:o.trust,trustDetail:o.trustDetail},`MCP config removal retained Pi folder trust`),ye(o.kind)}catch(i){return l(`agent-integrations-apply`).warn({editor:e,path:r??a.configPath(t,n),reason:i instanceof Error?i.message:String(i)},`MCP config removal failed`),K()}}async function xe(e,t,n){if(b[e].scope!==`global`)return q();if(n===`absent`)return be(e,``,t.home,void 0,t.env);let r=(await x({editors:[e],home:t.home,replaceEntry:!0})).find(t=>t.editorId===e);if(r===void 0)return K();switch(r.action){case`written`:case`overwritten`:return{action:r.action};case`declined`:return{action:`declined`,errorId:`write-declined`};case`skipped-missing`:return q();case`skipped-flag`:return Y();default:return K()}}function Se(e,t,r){let i=n[e];if(i===null)return q();let a=re(t.cwd,i);if(r===`absent`)return be(e,t.cwd,t.home,a,t.env);let o=w(b[e],t.cwd,ve,void 0,a);switch(o.action){case`written`:case`overwritten`:return{action:o.action};case`declined`:return{action:`declined`,errorId:`write-declined`};default:return K()}}function Ce(e,t,n){let r=t.home??ae();if(n===`absent`){let t=M(e,r);switch(t.action){case`removed`:return{action:`removed`};case`not-present`:return{action:`no-op`};case`skipped-unsupported`:return q();case`failed`:return J(e,t.path,t.error),K()}}let i=T(e,r);switch(i.action){case`written`:return{action:`written`};case`overwritten`:return{action:`overwritten`};case`skipped-unsupported`:return q();case`failed`:return J(e,i.path,i.error),K()}}function we(e,t,n){if(n===`absent`){let n=_(b[e],t.cwd);switch(n.action){case`removed`:return{action:`removed`};case`not-present`:return{action:`no-op`};case`skipped-unsupported`:return q();case`failed`:return J(e,n.path,n.error),K()}}let r=v(b[e],t.cwd);switch(r.action){case`written`:return{action:`written`};case`overwritten`:return{action:`overwritten`};case`skipped-unsupported`:return q();case`skipped-prerequisite`:return{action:`skipped-prerequisite`,errorId:`dependency-failed`};case`failed`:return J(e,r.path,r.error),K()}}function Te(t){return n=>{if(n.pathId===void 0)return Y();let r=e(n.pathId);if(r===null||r.kind===`central-skill-store`)return Y();switch(r.kind){case`editor-user-config`:return xe(r.editor,t,n.desired);case`editor-project-config`:return Se(r.editor,t,n.desired);case`editor-project-skill-root`:return we(r.editor,t,n.desired);case`editor-user-skill-root`:return Ce(r.editor,t,n.desired)}}}function Ee(e,t){return e.bind?.[0]??t.HOST??`127.0.0.1`}function De(e){if(e===`server`)return e;throw new g(`--only must be 'server'`)}function Oe(e=V){let t=import.meta.dirname??new URL(`.`,import.meta.url).pathname;return[B(t,`public`),B(t,`../../app/dist`),B(t,`../../../app/dist`)].find(t=>e(t))}function ke(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 Ae(e){if(e===`off`)return`off`;if(!r.test(e))throw new g(`--idle-shutdown must be 'off' or a duration like 90s, 30m, 2h`);return e}function je(e){return e===`localhost`||e===`::1`||e===`[::1]`||e.startsWith(`127.`)}function Me(e){return!e.flagBindSet&&!e.okBindSet&&e.hostEnvSet&&e.fileBindCount>1}function Ne(e){return!e.openBrowser||e.ephemeral||e.only===`server`||!e.servesUi?!1:(e.explicitOn||je(e.host))&&e.isTTY}function Pe(e,t){let n;try{n=new URL(t)}catch{throw new g(`${e} is not a valid URL: ${t}`)}if(n.protocol!==`http:`&&n.protocol!==`https:`)throw new g(`${e} must be an http(s) origin (got: ${t})`);return t}function Fe(e){return Pe(`--external-url`,e)}function Ie(e){let t=R(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var X=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}},Z=class extends Error{projectDir;constructor(e){super(`--project-dir must be a throwaway ${p}* directory under the OS temp dir. Refusing to write ephemeral session state into ${e}. Omit --project-dir to let ok start create (and clean up) its own.`),this.name=`EphemeralProjectDirNotThrowawayError`,this.projectDir=e}};function Q(e,t={}){let n=t.tmpdirFn??oe,r=t.realpathFn??ie,i=e=>{try{return r(e)}catch(t){return t.code===`ENOENT`?B(e):null}},a=B(e),o;try{o=r(a)}catch(e){if(e.code===`ENOENT`){let e=i(z(a));o=e===null?null:B(e,R(a))}else o=null}if(o===null)return!1;let s=i(n());return s!==null&&z(o)===s&&R(o).startsWith(`ok-ephemeral-`)}function Le(e,t,n=e=>se(e,{recursive:!0,force:!0})){return async()=>{try{await e()}finally{if(Q(t))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`)}else process.stderr.write(`[start] leaving ${t} in place: only ${p}* dirs under the OS temp dir are removed on ephemeral teardown\n`)}}}function $(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 Re(e){let{config:t,cwd:n,host:r}=e,i=e.skipAutoInit??!1,a=e.idleThresholdMs===void 0?18e5:e.idleThresholdMs,{existsSync:o,mkdirSync:s}=await import(`node:fs`),{basename:c,dirname:l,resolve:u}=await import(`node:path`),{bootServer:f,createEphemeralProjectDir:p,getLogger:g,resolveContentDir:_,resolveLockDir:v,seedEphemeralProjectDir:y,waitForServerLockDrain:b}=await import(`./dist-CupHag_I.mjs`),x=e.log??g(`start`),C=e.singleFile!==void 0,w=C?h(e.singleFile).canonicalFilePath:void 0,T=w?l(w):void 0,D=w?c(w):void 0,O,A=!1;if(T!==void 0){if(e.projectDir!==void 0){if(O=e.projectDir,!Q(O))throw new Z(O);o(u(O,`.ok`,`config.yml`))||y(O,T)}else O=p(T),A=!0}let j=async()=>{if(!(!A||O===void 0)){if(!Q(O)){x.warn({ephemeralProjectDir:O},`[start] refusing to reap self-provisioned ephemeral dir: no longer resolves to an ok-ephemeral-* temp dir`);return}try{await se(O,{recursive:!0,force:!0})}catch(e){x.warn({err:e,ephemeralProjectDir:O},`[start] failed to reap self-provisioned ephemeral temp dir`)}}},M=O;if(!C){if(!i&&!m(n))throw new X(n);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{e.severity===`info`?x.debug({event:e},`[start] reclaim sweep event`):x.warn({event:e},`[start] reclaim sweep reported a problem`)};try{let i=(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-hy238Kt4.mjs`)).repairMcpConfigs)({projectDir:n,reclaimDisableEnv:t,logger:r}).outcomes.filter(e=>e.outcome!==`no-entry`&&e.outcome!==`canonical`&&e.outcome!==`repaired`&&e.outcome!==`foreign`);i.length>0&&x.warn({unhealed:i},`[start] reclaim sweep left entries it could not heal`)}catch(e){x.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-BLnKg19X.mjs`)).repairLaunchJson)({projectDir:n,reclaimDisableEnv:t,logger:r})}catch(e){x.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}}let P=T??_(t,n);!C&&!o(P)&&(s(P,{recursive:!0}),x.info({contentDir:P},`Created content directory`));let ne=F(),I=d(),L;try{{let e=v(O??n),t=Date.now(),r=await b(e);r!==`no-drain`&&x.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`)}L=await f({config:t,contentDir:P,projectDir:O??n,contentRoot:C?void 0:t.content.dir,port:e.port,host:r,quiet:!1,detectGh:H,detectGhAccounts:de,tokenStore:ne,embeddingsKeyStore:I,mcpTomlEditor:S(),...C?{ephemeral:!0,singleDocRelPath:D,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],probeHarnessManagedMcpEntry:(e,t)=>k(e,t),probePiAcpBridge:e=>E(e),ensurePiAcpBridge:(e,t)=>N(e,void 0,void 0,void 0,t),agentIntegrations:(()=>{let e={cwd:O??n,home:ae(),env:process.env};return{probe:te(e),execute:Te(e),userSkillPresentAnywhere:ee}})(),idleShutdownMs:a,...e.serverRuntime===void 0?{}:{serverRuntime:e.serverRuntime},...e.bind===void 0?{}:{bind:e.bind},skipAutoInit:!0,idleShutdownHandler:t=>{let n=t;return $(M===void 0?n:Le(n,M),{log:x,exit:e.idleExit})},log:x,...e.serveContentAssets===void 0?{}:{serveContentAssets:e.serveContentAssets},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}})}catch(e){throw await j(),e}let R=L.destroy,z=A?async()=>{try{await R()}finally{await j()}}:R;return{httpServer:L.httpServer,destroy:z,lockDir:L.lockDir,contentDir:P,port:L.port,ready:L.ready,degraded:L.degraded}}function ze(e,t,n=()=>u({absPath:c(`user`,process.cwd()),sideline:!1,warn:()=>{}}).value){return t===void 0?e:n()}function Be(e){if(e===`browser`||e===`app`)return e;throw new g(`--mode must be 'browser' or 'app'`)}function Ve(e){return e.OK_CONSOLE_LEVEL!==void 0||e.LOG_LEVEL!==void 0?null:`warn`}function He(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 Ue(e,n){let r=ze(e,n.singleFile),c=Ve(process.env);c!==null&&(process.env.OK_CONSOLE_LEVEL=c);let{renderBanner:l}=await import(`./banner-kywHhVaC.mjs`),{accent:u,dim:d,error:f,warning:p}=await import(`./colors-SgU3JHQu.mjs`),m=process.cwd();process.title=Ie(m);let h;try{h=i(process.env)}catch(e){throw e instanceof s&&(console.error(f(e.message)),process.exit(78)),e}for(let e of h.diagnostics)console.warn(p(`[config] ${e.message}`));let g=o(r,h.layer),_=h.overrides.some(e=>e.envVar===`OK_BIND`),v=n.bind!==void 0&&n.bind.length>0?n.bind:void 0,y=process.env.HOST,b=y!==void 0&&y.trim()!==``?y:void 0,x=a(g),S=v??(_||b===void 0?[...x.bind]:[b]);Me({flagBindSet:v!==void 0,okBindSet:_,hostEnvSet:b!==void 0,fileBindCount:x.bind.length})&&console.warn(p(`[config] HOST=${b} overrides server.bind — dropping the file-configured addresses (${x.bind.join(`, `)}). Use OK_BIND with a space-separated list to keep multiple binds.`));let C=S[0]??`127.0.0.1`,w=S,T=n.externalUrl,E=a(o(g,{server:{bind:w,...T===void 0?{}:{externalUrl:T}}}));if(E.allowExternal&&(!E.loopbackOnly||E.externalUrl)){let e=E.externalUrl??E.bind.join(`, `);console.warn(p([``,`⚠ 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 D=n.port===void 0?void 0:Number(n.port),O=h.overrides.find(e=>e.envVar===`PORT`)?.value,ee=D??O??r.server?.port,k=ke({explicitDir:n.reactShellDistDir,only:n.only,findBundledDir:Oe}),A=k.dir;k.missingBundle&&console.warn(`bundled web UI not found — serving /api and /mcp only. Reinstall @inkeep/open-knowledge, or build packages/app in a source checkout.`);let j;try{j=await Re({config:r,cwd:m,host:C,port:ee,bind:w,...n.serveContentAssets===void 0?{}:{serveContentAssets:n.serveContentAssets},...A?{reactShellDistDir:A}:{},idleThresholdMs:t(n.idleShutdown??E.idleShutdown),serverRuntime:E,...n.singleFile?{singleFile:n.singleFile}:{},...n.projectDir?{projectDir:n.projectDir}:{}})}catch(e){e instanceof X&&(console.error(f(e.message)),process.exit(1)),e instanceof Z&&(console.error(f(e.message)),process.exit(1));let t=await import(`./dist-CupHag_I.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),e instanceof t.ExposureConsentError&&(console.error(f(e.message)),process.exit(78)),(e instanceof t.SingleFileNotFoundError||e instanceof t.SingleFileNotAFileError||e instanceof t.SingleFileNotMarkdownError)&&(console.error(f(e.message)),process.exit(1)),(e instanceof t.MissingOkConfigError||e instanceof t.DocumentDurabilityStateError)&&(console.error(f(e.message)),process.exit(1)),Ke(e,t)){let e=t.resolveLockDir(m),n=null;try{n=await We({readServerLock:()=>t.readServerLock(e),now:Date.now,sleep:e=>ce(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]=Ge(n);console.log(u(e));for(let e of t)console.log(d(e));process.exit(0)}}let n=qe(e,m,t);n!==null&&(console.error(f(n)),process.exit(1)),console.error(`${f(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let M=!1,N=async e=>{if(M)return;M=!0;let[t,...n]=He(e);console.log(u(`\n${t}`));for(let e of n)console.log(d(` ${e}`));try{await j.destroy(`external-signal`)}catch(e){console.error(`${f(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)};process.once(`SIGINT`,()=>{N(`SIGINT`)}),process.once(`SIGTERM`,()=>{N(`SIGTERM`)});let te=`http://${C.includes(`:`)&&!C.startsWith(`[`)?`[${C}]`:C}:${j.port}`,P=C===`0.0.0.0`||C===`::`?`http://0.0.0.0:${j.port}`:void 0,F=te;console.log(l({name:`open-knowledge`,version:ne,localUrl:F,networkUrl:P,nextSteps:[`Open the Editor URL in your browser to start editing.`]}));let I={"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`};j.ready.then(async()=>{if(j.degraded.length>0){console.log();for(let e of j.degraded){let t=I[e]??`${e} (check server logs for details)`;console.warn(` ${p(`⚠`)} ${p(e)}: ${d(t)}`)}console.log()}if(Ne({openBrowser:n.openBrowser!==!1&&E.openBrowser,explicitOn:n.openBrowser!==!1&&g.server?.openBrowser===!0,host:C,isTTY:process.stdout.isTTY===!0,ephemeral:n.singleFile!==void 0,only:n.only,servesUi:A!==void 0})){let{openBrowser:e}=await import(`./open-browser-yaMqhpHT.mjs`);e(F)}}).catch(e=>{console.error(` ${f(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}async function We(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();return n===null||n.draining===!0||n.port<=0?null:f(n)&&n.url!==void 0?{url:n.url,kind:n.kind,pid:n.pid,servesUi:!0}:{url:n.url??`http://127.0.0.1:${n.port}`,kind:n.kind,pid:n.pid,servesUi:!1}}function Ge(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 Ke(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function qe(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 Je(e){return new y(`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]).option(`--no-open-browser`,`Do not open the browser after start (interactive loopback starts open it by default)`).option(`--only <module>`,`Serve one module: 'server' (API + MCP only, no shell or browser)`,De).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)`,Ae).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,Be).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>`).addOption(new C(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).hideHelp()).addOption(new C(`--project-dir <dir>`,`Throwaway project root for --single-file (where ephemeral .ok/ state lives)`).hideHelp()).option(`--external-url <url>`,`Canonical external origin clients dial (sets server.externalUrl for this run) — its host joins the Host/Origin allowlists (CORS + external-Host admission). External exposure additionally requires consent (OK_ALLOW_EXTERNAL=1 or server.allowExternal).`,Fe).action(async t=>{let n=e();if(t.only===`server`&&t.reactShellDistDir!==void 0&&(process.stderr.write(`error: option '--only server' cannot be combined with '--react-shell-dist-dir'
|
|
4
4
|
`),process.exit(2)),t.projectDir!==void 0&&t.singleFile===void 0&&(process.stderr.write(`error: option '--project-dir' requires '--single-file'
|
|
5
5
|
`),process.exit(2)),t.mode===`app`){let e=[];if(t.port!==void 0&&e.push(`--port`),t.bind!==void 0&&e.push(`--bind`),t.only!==void 0&&e.push(`--only`),t.idleShutdown!==void 0&&e.push(`--idle-shutdown`),t.openBrowser===!1&&e.push(`--no-open-browser`),t.externalUrl!==void 0&&e.push(`--external-url`),e.length>0){let t=process.env.OK_LOG_LEVEL??`info`;(t===`debug`||t===`trace`)&&console.error(`--mode=app: ignoring ${e.join(`, `)}`)}let n=D(P());if(n.available){O({spawn:L},n);return}console.error(j(n.reason)),process.exit(1)}await Ue(n,t)})}export{qe as C,de as D,H as E,Je as S,$ as T,Ve as _,Ge as a,Ne as b,Q as c,Ae as d,De as f,ze as g,We as h,Ie as i,Ke as l,Ee as m,X as n,He as o,Oe as p,Re as r,je as s,Z as t,Fe as u,ke as v,Le as w,Me as x,Ue as y};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/open-knowledge",
|
|
3
|
-
"version": "0.77.9-beta.
|
|
3
|
+
"version": "0.77.9-beta.2",
|
|
4
4
|
"description": "Local-first, agent-friendly Markdown knowledge base with a cross-platform CLI and web editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"knowledge-base",
|
|
@@ -72,10 +72,10 @@
|
|
|
72
72
|
"ajv-formats": "^3.0.1",
|
|
73
73
|
"tsdown": "^0.22.14",
|
|
74
74
|
"typescript": "~7.0.2",
|
|
75
|
-
"@inkeep/open-knowledge-
|
|
75
|
+
"@inkeep/open-knowledge-app": "0.77.9-beta.2",
|
|
76
|
+
"@inkeep/open-knowledge-core": "0.77.9-beta.2",
|
|
76
77
|
"@inkeep/open-knowledge-native-config": "0.0.0",
|
|
77
|
-
"@inkeep/open-knowledge-
|
|
78
|
-
"@inkeep/open-knowledge-server": "0.77.9-beta.0"
|
|
78
|
+
"@inkeep/open-knowledge-server": "0.77.9-beta.2"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"build:cli": "rm -rf dist && tsdown",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./md-manager-BGnqyqi1-DKflYxqj.mjs";var e=`0.77.9-beta.0`;const t=`config.yml`,n=e;export{n,t};
|
package/dist/init-BNRf8IKE.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./dist-gqMlO9g5.mjs";import{_ as e}from"./init-C-24amuv.mjs";export{e as runInit};
|
package/dist/loader-0rF9tfd3.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./loader-0WU8op48.mjs";export{e as loadConfig};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,t}from"./preview-BSLfKB1h.mjs";export{t as formatPreviewBlock,e as previewContent};
|