@inkeep/open-knowledge 0.71.9 → 0.71.10
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/cli.mjs +21 -21
- package/dist/constants-CBd-Q37u.mjs +1 -0
- package/dist/{dist-LYaYuyF6.mjs → dist-B4TxkELG.mjs} +1 -1
- package/dist/dist-CjH-Sf5k.mjs +2096 -0
- package/dist/index.mjs +146 -146
- package/dist/{init-DKzRAP2P.mjs → init-BH-xYzaq.mjs} +63 -63
- package/dist/init-CIkCfP3v.mjs +1 -0
- package/dist/{launch-json-removal-CNbEIGbQ.mjs → launch-json-removal-Hu9HtvTf.mjs} +1 -1
- package/dist/{loader-BiZJHdwK.mjs → loader-CTDn6ZAg.mjs} +1 -1
- package/dist/loader-uo3T-fXX.mjs +1 -0
- package/dist/{md-manager-BGnqyqi1-BKu_gT6Z.mjs → md-manager-BGnqyqi1-BKxqDqfk.mjs} +154 -154
- package/dist/{open-browser-CfY26r-T.mjs → open-browser-DqgRF6In.mjs} +1 -1
- package/dist/parse-worker.mjs +1 -1
- package/dist/preview-C30dtIBY.mjs +1 -0
- package/dist/{preview-C_r01WSD.mjs → preview-fXj4S7Dm.mjs} +1 -1
- package/dist/{registry-probes-BANUPh4J.mjs → registry-probes-HHK87hoW.mjs} +2 -2
- package/dist/{removal-file-path-DsFzjsr2.mjs → removal-file-path-CEhc0VSj.mjs} +1 -1
- package/dist/{repair-launch-json-UV8aYTeF.mjs → repair-launch-json-CgEj-guz.mjs} +1 -1
- package/dist/{repair-mcp-configs-I08GSE9q.mjs → repair-mcp-configs-Cz6cPG1G.mjs} +1 -1
- package/dist/src-BEln9x-2.mjs +1 -0
- package/dist/src-CMOdq-h1.mjs +11 -0
- package/dist/{start-BeubOhRd.mjs → start-DxYIcUQw.mjs} +3 -3
- package/dist/start-L7DcD7lF.mjs +1 -0
- package/package.json +4 -4
- package/dist/constants-CtgW5q2S.mjs +0 -1
- package/dist/dist-B6i6qfgS.mjs +0 -2096
- package/dist/init-BZq_t-cO.mjs +0 -1
- package/dist/loader-ToxkBMQb.mjs +0 -1
- package/dist/preview-DR1A8Mjo.mjs +0 -1
- package/dist/src-BIsbVAMW.mjs +0 -1
- package/dist/src-uqJOug1O.mjs +0 -11
- package/dist/start-BlH0bGhn.mjs +0 -1
package/dist/init-BZq_t-cO.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./dist-B6i6qfgS.mjs";import{_ as e}from"./init-DKzRAP2P.mjs";export{e as runInit};
|
package/dist/loader-ToxkBMQb.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./loader-BiZJHdwK.mjs";export{e as loadConfig};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,t}from"./preview-C_r01WSD.mjs";export{t as formatPreviewBlock,e as previewContent};
|
package/dist/src-BIsbVAMW.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./md-manager-BGnqyqi1-BKu_gT6Z.mjs";import"./init-DKzRAP2P.mjs";import"./registry-probes-BANUPh4J.mjs";import"./src-uqJOug1O.mjs";import"./start-BeubOhRd.mjs";import{n as e}from"./loader-BiZJHdwK.mjs";import"./preview-C_r01WSD.mjs";import"./cli.mjs";import"./repair-mcp-configs-I08GSE9q.mjs";export{e as loadConfig};
|
package/dist/src-uqJOug1O.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-tZXQYakl.mjs";import{An as t,_c as n,dd as r,fo as i,gc as a,jn as o,qs as s,ru as c,ss as l,vs as u,yc as ee,zn as te}from"./md-manager-BGnqyqi1-BKu_gT6Z.mjs";import{$r as d,Co as ne,Ct as f,Fn as p,Gn as m,Gr as h,Qa as g,Qr as _,To as v,Xi as y,Yn as b,Zr as x,cr as S,gi as C,hi as w,m as T,wo as E,zr as D}from"./dist-B6i6qfgS.mjs";import{t as O}from"./yazl-BBz29IQN.mjs";import{at as k,ot as A,vt as j}from"./init-DKzRAP2P.mjs";import{b as M,l as re}from"./registry-probes-BANUPh4J.mjs";import{c as N}from"./colors-r_owlCuY.mjs";import{t as ie}from"./is-object-BGze3w87.mjs";import{n as ae}from"./constants-CtgW5q2S.mjs";import"./loader-BiZJHdwK.mjs";import"./preview-C_r01WSD.mjs";import{execSync as oe,spawnSync as se}from"node:child_process";import{basename as P,dirname as F,isAbsolute as ce,join as I,relative as L,resolve as R,sep as z}from"node:path";import{closeSync as le,cpSync as ue,createWriteStream as de,existsSync as B,lstatSync as fe,mkdirSync as V,mkdtempSync as pe,openSync as me,readFileSync as H,readSync as he,readdirSync as U,rmSync as W,rmdirSync as ge,statSync as _e,writeFileSync as G}from"node:fs";import{arch as ve,freemem as ye,homedir as K,hostname as be,platform as xe,release as Se,tmpdir as Ce,totalmem as we,type as Te,uptime as Ee}from"node:os";import"node:fs/promises";import{createHash as De}from"node:crypto";const Oe=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`lint`,`deinit`,`auth`]);function ke(e,t,n=b){if(e!==void 0&&!Oe.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let Ae=null;function je(e){Ae=e}function Me(){return Ae??process.cwd()}const Ne=`Open Knowledge`;function Pe(e={}){let t=e.platformName??process.platform,n=e.productName??`OpenKnowledge`;return k(t).join(A({...e,platformName:t}),n)}function Fe(e={}){let t=e.platformName??process.platform,n=e.home??K(),r=e.env??process.env,i=k(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 Ie(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 Le(e){let t=I(e,`state.json`);if(!B(t))return[];let n;try{n=JSON.parse(H(t,`utf-8`))}catch{return[]}return Ie(n)??[]}function Re(e){let t=I(e,`state.json`);if(!B(t))return!1;try{return Ie(JSON.parse(H(t,`utf-8`)))!==null}catch{return!1}}const ze=8192;function Be(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 Ve(e){return e.replace(/\\+\/?/g,e=>{if(!e.endsWith(`/`))return e;let t=e.length-1;return`${`\\`.repeat(t-t%2)}/`})}const He=RegExp(`("(?:${[`crashReporterKey`,`bootSessionUUID`,`deviceIdentifierForVendor`].join(`|`)})"\\s*:\\s*)"[^"]*"`,`g`);function Ue(e){return e.replace(He,`$1"[REDACTED-DEVICE-ID]"`)}function We(e){return Ue(Ve(e))}const Ge=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(\.\d+)? ([+-]\d{2})(\d{2})$/;function Ke(e){if(typeof e!=`string`)return null;let t=Ge.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 qe(e){let t=me(e,`r`);try{let e=Buffer.alloc(ze),n=0,r=!1;for(;n<ze;){let i=he(t,e,n,ze-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{le(t)}}function Je(e){try{let t=qe(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:Ke(a)}}catch{return{kind:`unreadable`}}}function Ye(e){return e===`OpenKnowledge`||e.startsWith(`OpenKnowledge `)}function Xe(e,t){let n={files:[],foreignIgnored:0,unparseable:0,droppedOverCap:0,windowDays:7},r;try{r=U(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=I(e,t.name),r;try{r=_e(n).mtimeMs}catch{continue}if(r<i)continue;let c=Je(n),l=c.kind===`named`&&c.timestampMs!==null?c.timestampMs:r;if(c.kind===`unreadable`){s+=1;continue}if(!Ye(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 q(){return I(K(),`.ok`,`bug-reports`)}function Ze(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`),n=q(),r=`${t}-bugreport`,i=I(n,`${r}.zip`);for(let e=2;B(i);e+=1)i=I(n,`${r}-${e}.zip`);return i}function Qe(e,t){let n=I(e,`.ok`,`config.yml`);if(B(n))try{let e=H(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 B(I(e,`.ok`))?De(`sha256`).update(R(e)).digest(`hex`).slice(0,12):null}function $e(){let e={timestamp:new Date().toISOString(),platform:xe(),osType:Te(),osRelease:Se(),hostname:`[redacted]`,uptime:Ee(),freeMem:ye(),totalMem:we(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=oe(`sw_vers -productVersion 2>/dev/null`,g({encoding:`utf8`})).trim()}catch{}try{let t=I(__dirname,`..`,`..`,`package.json`);B(t)&&(e.okVersion=JSON.parse(H(t,`utf8`)).version)}catch{}return e}const et=[{prefix:`cli`,projectTagged:!0},{prefix:`desktop`,projectTagged:!1},{prefix:`mcp`,projectTagged:!1}];function tt(e){let t=P(e);return et.some(e=>e.projectTagged&&t.startsWith(`${e.prefix}.`))}function nt(e,t){return ot(e,t).files}const rt=[`ShipIt_stderr.log`,`ShipIt_stdout.log`];function it(e,t=re){let n=I(e,`${t}.ShipIt`);if(!B(n))return[];let r;try{r=U(n)}catch{return[]}return rt.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=>I(n,e.entry)))}function at(e){if(!B(e))return[];try{let n=new Map;for(let r of U(e).filter(e=>e.endsWith(`.yaml`)).sort()){let e=r.endsWith(`.sent.yaml`)?r.slice(0,-t.length):r.slice(0,-5),i=n.get(e);i===void 0?n.set(e,[r]):i.push(r)}return[...n.values()].slice(-25).flat().map(t=>I(e,t))}catch{return[]}}function ot(e,t){if(!B(t))return{files:[],excludedByProjectSlug:0};let n=U(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>I(t,e));if(!e)return{files:n,excludedByProjectSlug:0};let r=n.filter(tt),i=[],a=r.filter(t=>{try{return H(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=>!tt(e)||o.has(e)),excludedByProjectSlug:r.length-o.size}}function st(e){let t=I(e,`.ok`,`local`);return B(t)?{files:[`server.lock`,`last-spawn-error.log`,a].map(e=>I(t,e)).filter(e=>B(e))}:{files:[]}}function ct(e){let t=I(e,`.ok`,`local`,`logs`);return B(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>I(t,e)).filter(e=>B(e))}:{files:[]}}function lt(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#${De(`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 ut(e){let t=e.revealDocNames?e.content:lt(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 J(e){for(let t of e.files)try{let n=H(t,`utf8`);ut({zipfile:e.zipfile,name:`${e.prefix}/${P(t)}`,content:t.endsWith(`.ips`)?We(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 dt(t){let{redact:n,outputPath:r,logger:i}=t,a=t.revealDocNames??!1,s=t.userLogsDir??I(K(),`.ok`,`logs`),c=t.projectDir?Qe(t.projectDir,i):null;V(F(r),{recursive:!0}),i?.info({projectSlug:c},`gathering diagnostic data`);let l=$e();l.desktop=t.desktop??null,l.language=t.language??null;let{files:u,excludedByProjectSlug:ee}=ot(c,s),{files:d}=t.projectDir?st(t.projectDir):{files:[]},{files:ne}=t.projectDir?ct(t.projectDir):{files:[]},f=t.shipItLogFiles??[],p=t.diagnosticReports?.files??[];i?.info({logFileCount:u.length,logFilesExcludedByProjectSlug:ee,lockFileCount:d.length,localSinkFileCount:ne.length,shipItLogFileCount:f.length,diagnosticReportCount:p.length},`files collected`);let m=[],h=[],{ZipFile:g}=await import(`./yazl-BsCX6KWo.mjs`).then(t=>e(t.default,1)),_=new g;J({zipfile:_,files:[...u,...f],prefix:`logs`,redact:n,revealDocNames:a,bundleFiles:h,redactions:m,logger:i}),J({zipfile:_,files:d,prefix:`lockdir`,redact:n,revealDocNames:a,bundleFiles:h,redactions:m,logger:i}),J({zipfile:_,files:ne,prefix:`local-logs`,redact:n,revealDocNames:a,bundleFiles:h,redactions:m,logger:i}),J({zipfile:_,files:t.bugReportLedgerFiles??[],prefix:o,redact:n,revealDocNames:a,bundleFiles:h,redactions:m,logger:i}),J({zipfile:_,files:p,prefix:`diagnostic-reports`,redact:n,revealDocNames:a,bundleFiles:h,redactions:m,logger:i});for(let e of t.extraFiles??[])try{let t=H(e.sourcePath),n=`extra/${e.zipName??P(e.sourcePath)}`;_.addBuffer(t,n),h.push(n)}catch(t){i?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&ut({zipfile:_,name:`note.txt`,content:t.note,redact:n,revealDocNames:a,bundleFiles:h,redactions:m});let v=new Set(p.map(e=>`diagnostic-reports/${P(e)}`)),y=h.filter(e=>v.has(e)),b=t.diagnosticReports===void 0?`not-collected (no collection attempted)`:Be(t.diagnosticReports,y.length);_.addBuffer(Buffer.from(`${b}\n`,`utf8`),`state/diagnostic-reports-status.txt`),h.push(`state/diagnostic-reports-status.txt`);let x=JSON.stringify(l,null,2);_.addBuffer(Buffer.from(x,`utf8`),`sysinfo.json`),h.push(`sysinfo.json`);let S={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:c,files:h,redactions:m,sysinfo:l};_.addBuffer(Buffer.from(JSON.stringify(S,null,2),`utf8`),`MANIFEST.json`);let C=m.reduce((e,t)=>e+t.lineCount,0),w=new Set(f.map(e=>`logs/${P(e)}`)),T=h.filter(e=>w.has(e)),E=new Set((t.bugReportLedgerFiles??[]).map(e=>`${o}/${P(e)}`)),D=h.filter(e=>E.has(e)),O=c?h.filter(e=>e.startsWith(`logs/`)&&!tt(e)&&!w.has(e)):[],k=y.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.`]:[],A=k.length>0?[`Redaction was disabled for this bundle; file contents are unmodified,`,`with one exception.`,...k]:[`Redaction was disabled for this bundle; file contents are unmodified.`],j=[`# Bug Report Bundle`,``,`Generated: ${S.generatedAt}`,`Project: ${c??`(unscoped)`}`,`Discipline version: ${S.disciplineVersion}`,``,`## Contents`,``,...h.map(e=>`- ${e}`),``,`## Privacy`,``,...O.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:`,...O.map(e=>`- ${e}`),``]:[],...T.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:`,...T.map(e=>`- ${e}`),``]:[],...y.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:`,...y.map(e=>`- ${e}`),``]:[],...D.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:`,...D.map(e=>`- ${e}`),``]:[],...n?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${te.join(`, `)}`,C>0?`${C} line(s) were scrubbed across ${m.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,...k,``,`This bundle is safe to attach to a GitHub issue.`]:A].join(`
|
|
2
|
-
`);_.addBuffer(Buffer.from(j,`utf8`),`README.md`),_.end();let M=de(r);return _.outputStream.pipe(M),await new Promise((e,t)=>{M.on(`close`,e),M.on(`error`,t)}),i?.info({bundlePath:r,fileCount:h.length,redactionCount:C},`bundle written`),{zipPath:r,summary:{projectSlug:c,files:h,redactions:m,redactedLineCount:C,generatedAt:S.generatedAt}}}var ft=c(),pt=e(O(),1),Y=e(N(),1);function mt(e){let t=v(`user`,e,e);return ne({absPath:t,sideline:!1,warn:()=>{}}).value.appearance?.language??`system`}function ht({home:e=K(),env:t=process.env}={}){let n=mt(e),{override:r,preferenceList:i}=E(t),{locale:a,source:o}=u({override:r,storedPreference:n,supportedLocales:ee,preferenceList:i,autoDetectableLocales:s});return{preference:n,locale:a,source:o,systemLanguages:i}}function gt(e,t){return t.length===0||!e.includes(t)?e:e.split(t).join(`<CONTENT_DIR>`)}function _t(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function X(e,t){if(typeof e==`string`)return gt(e,t.contentDir);if(Array.isArray(e))return e.map(e=>X(e,t));if(!_t(e))return e;let n={};for(let[r,i]of Object.entries(e))n[r]=X(i,t);return n}function vt(e,t){let n=H(e,`utf-8`);if(n.length===0)return;let r=n.endsWith(`
|
|
3
|
-
`),i=n.split(`
|
|
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=X(JSON.parse(n),t);a.push(JSON.stringify(e))}catch{a.push(n)}}}let o=r?`${a.join(`
|
|
5
|
-
`)}\n`:a.join(`
|
|
6
|
-
`);G(e,o)}function yt(e,t){let n=H(e,`utf-8`);if(n.trim().length!==0)try{let r=X(JSON.parse(n),t),i=n.endsWith(`
|
|
7
|
-
`)?`
|
|
8
|
-
`:``;G(e,`${JSON.stringify(r,null,2)}${i}`)}catch{let r=gt(n,t.contentDir);r!==n&&G(e,r)}}function bt(e,t){let n=H(e,`utf-8`),r=gt(n,t.contentDir);r!==n&&G(e,r)}function xt(e){try{return U(e,{withFileTypes:!0}).filter(e=>e.isFile()).map(t=>I(e,t.name))}catch{return[]}}const St=new Set([`agent-presence.json`,`agent-effects.json`,`runtime.json`]);function Ct(e){return/\.log\.\d+$/.test(e)}function wt(e){return e.endsWith(`.jsonl`)||e.endsWith(`.log`)||Ct(e)}const Tt=[`telemetry`,`logs`,`process`,`diagnostic-reports`];function Et(e){let t={contentDir:e.contentDir};for(let n of Tt)for(let r of xt(I(e.stagingDir,n)))wt(r)?vt(r,t):r.endsWith(`.json`)?yt(r,t):bt(r,t);for(let n of xt(I(e.stagingDir,`state`))){let e=P(n);n.endsWith(`.jsonl`)?vt(n,t):St.has(e)?yt(n,t):bt(n,t)}}const Dt=[`.ok`,`local`,`telemetry`],Ot=[`.ok`,`local`,`logs`],kt=[`.ok`,`local`,`loss-capture`],At=`spans-current.jsonl`,jt=`spans-prev.jsonl`,Mt=`server-current.jsonl`,Nt=`server-prev.jsonl`,Pt=`loss-current.jsonl`,Ft=`loss-prev.jsonl`;function It(e){return I(e,...Dt,At)}function Lt(e){return I(e,...Dt,jt)}function Rt(e){return I(e,...Ot,Mt)}function zt(e){return I(e,...Ot,Nt)}function Bt(e){return I(e,...kt,Pt)}function Vt(e){return I(e,...kt,Ft)}const Ht=1e3;async function Ut(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-presence`,{signal:AbortSignal.timeout(Ht)});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/agent-effects`,{signal:AbortSignal.timeout(Ht)});return t.ok?await t.text():null}catch{return null}}async function Gt(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/watcher-recent`,{signal:AbortSignal.timeout(Ht)});return t.ok?await t.text():null}catch{return null}}function Kt(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 qt(e){let t=I(e,`.git`,`ok`);if(!B(t))return null;let n=se(`git`,[`-C`,t,`log`,`--oneline`,`-50`],g({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function Jt(e){let t=I(e,`.git`,`ok`);if(!B(t))return null;let n=se(`git`,[`-C`,t,`for-each-ref`,`--sort=-creatordate`,`--count=50`,`--format=%(refname)%09%(creatordate:iso-strict)%09%(contents:subject)`,`refs/checkpoints/`],g({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function Yt(){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 Xt(){return{nodeVersion:process.version,platform:xe(),arch:ve()}}function Zt(){return process.env.OTEL_SDK_DISABLED===`false`}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Qt(e){if(!B(e))return{};let t;try{t=(0,ft.parse)(H(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(!Z(t))return{};let n=t.telemetry;if(!Z(n))return{};let r=n.localSink;return Z(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(Z(e))return en(e.maxBytes)}function nn(e){let t=Qt(v(`project`,e)),n=Qt(v(`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 De(`sha256`).update(e).digest(`hex`)}function an(e){let t=H(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=H(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(!B(e))return!1;try{return V(F(t),{recursive:!0}),e.endsWith(`.ips`)?G(t,We(H(e,`utf-8`))):ue(e,t),!0}catch{return!1}}function cn(e){let t=[],n=e=>{let r=U(e,{withFileTypes:!0});for(let i of r){let r=I(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(Ct(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(H(n,`utf-8`));a.length!==0&&(G(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 L(e,t).split(z).join(`/`)}async function hn(e){let t=R(e.contentDir),r=R(e.projectDir??e.contentDir),i=e.deps??{},s=i.fetchAgentPresence??Ut,c=i.fetchAgentEffects??Wt,l=i.fetchWatcherRecent??Gt,u=i.readShadowHead??qt,ee=i.readCheckpointRefs??Jt,te=i.now??(()=>new Date),d=i.okVersion??(()=>ae),ne=i.readDesktopEnv??Yt,f=i.readLanguage??ht,p=i.readRuntime??Xt,m=i.isOtlpPushEnabled??Zt,h=pe(I(Ce(),`ok-bundle-`));try{V(I(h,`telemetry`),{recursive:!0}),V(I(h,`logs`),{recursive:!0}),V(I(h,`state`),{recursive:!0}),Q(It(r),I(h,`telemetry`,At)),Q(Lt(r),I(h,`telemetry`,jt)),Q(Rt(r),I(h,`logs`,Mt)),Q(zt(r),I(h,`logs`,Nt));for(let t of e.userLogFiles??[])Q(t,I(h,`logs`,P(t)));for(let t of e.userStateFiles??[])Q(t,I(h,o,P(t)));let g=0;for(let t of e.diagnosticReports?.files??[])Q(t,I(h,`diagnostic-reports`,P(t)))&&(g+=1);let _=I(r,`.ok`,`local`),v=I(_,`server.lock`),y=`not-running`,b=`no server.lock`,x=null;if(B(v)){Q(v,I(h,`state`,`server.lock`));try{let e=H(v,`utf-8`),t=JSON.parse(e);typeof t.port==`number`?x=t.port:b=`lock present but no port`}catch{b=`lock present but unparseable`}}if(x!==null){let e=await s(x);e===null?b=`agent-presence endpoint at :${x} unreachable`:(G(I(h,`state`,`agent-presence.json`),e),y=`running`,b=``);let t=await c(x);t!==null&&G(I(h,`state`,`agent-effects.json`),t);let n=await l(x);if(n!==null){let e=Kt(n);e!==null&&G(I(h,`state`,`watcher-recent.jsonl`),e)}}let S=u(t);S!==null&&G(I(h,`state`,`shadow-head.txt`),S);let C=ee(t);C!==null&&G(I(h,`state`,`checkpoint-refs.txt`),C),Q(Bt(r),I(h,`state`,Pt)),Q(Vt(r),I(h,`state`,Ft)),Q(I(_,`last-spawn-error.log`),I(h,`state`,`last-spawn-error.log`)),Q(I(_,n),I(h,`state`,n)),Q(I(_,a),I(h,`state`,a));let w=p(),T=ne(),E=f(),D={ok:{version:d(),nodeVersion:w.nodeVersion,platform:w.platform,arch:w.arch},host:{desktop:T,language:E}};G(I(h,`state`,`runtime.json`),`${JSON.stringify(D,null,2)}\n`);let O=y===`running`?`running
|
|
10
|
-
`:`not-running (${b})\n`;G(I(h,`state`,`server-status.txt`),O);let k=e.diagnosticReports===void 0?`not-collected (no collection attempted)`:Be(e.diagnosticReports,g);if(G(I(h,`state`,`diagnostic-reports-status.txt`),`${k}\n`),e.processDir&&B(e.processDir)){let t=I(h,`process`);V(t,{recursive:!0}),ue(e.processDir,t,{recursive:!0})}let A=e.redact===!0;A&&Et({stagingDir:h,contentDir:t}),e.note&&G(I(h,`note.txt`),e.note);let j=null;e.scrubSecrets===!0&&(j=pn(h));for(let t of e.extraFiles??[])Q(t.sourcePath,I(h,`extra`,t.zipName??P(t.sourcePath)))||i.logger?.warn({sourcePath:t.sourcePath},`extra file missing; omitted from bundle`);let M=nn(r),re=cn(h),N=[],ie=0,ae=0;for(let e of re){let t=mn(h,e),n=_e(e).size,r=un(t)?an(e):0;N.push({path:t,bytes:n,lines:r}),ie+=n,(t.startsWith(`telemetry/`)||t.startsWith(`logs/`))&&(ae+=sn(e))}let oe={applied:A};j!==null&&(oe.secretScrub=j);let se={schemaVersion:2,createdAt:te().toISOString(),ok:{version:d(),nodeVersion:w.nodeVersion,platform:w.platform,arch:w.arch},host:{desktop:T,language:E},contentDir:{pathSha256:rn(t),absolutePath:A?`<CONTENT_DIR>`:t},telemetry:{localSink:M,otlpPushEnabled:m()},redaction:oe,serverStatus:y,files:N};G(I(h,`manifest.json`),`${JSON.stringify(se,null,2)}\n`);let F=re.some(e=>{try{return H(e,`utf-8`).includes(t)}catch{return!1}}),ce={stagedDiagnosticReports:g,totalBytes:ie,fileCount:N.length,docNameCount:ae,contentDirVisible:F,redacted:A},L=!1;return{stagingDir:h,manifest:se,summary:ce,cleanup:()=>{L||(L=!0,W(h,{recursive:!0,force:!0}))}}}catch(e){throw W(h,{recursive:!0,force:!0}),e}}async function gn(e){let{collected:t,outputPath:n}=e,r=F(n);if(!B(r))throw Error(`ok diagnose bundle: parent directory does not exist: ${r}. Create it or pass --out with an existing parent.`);let i=new pt.ZipFile,a=cn(t.stagingDir);for(let e of a){let n=mn(t.stagingDir,e);i.addFile(e,n)}i.end();let o=de(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=I(e,`.ok`,`config.yml`);if(B(n))try{let t=(0,ft.parse)(H(n,`utf-8`)),r=ie(t)?t.content:void 0,i=ie(r)?r.dir:void 0;if(typeof i==`string`&&i.length>0)return R(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 R(e)}async function vn(e,t,n,r,i){let a=Qe(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:[...nt(a,e.userLogsDir??I(K(),`.ok`,`logs`)),...it(e.cachesDir??I(K(),`Library`,`Caches`))],userStateFiles:at(e.bugReportsDir??q()),diagnosticReports:i,deps:{readDesktopEnv:n,readLanguage:r,logger:e.logger}});try{V(F(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??Yt,r=e.readLanguage??ht,i=()=>Xe(e.diagnosticReportsDir??I(K(),`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 dt({projectDir:t,redact:e.redact,revealDocNames:e.level===`full`,outputPath:e.outputPath,userLogsDir:e.userLogsDir,shipItLogFiles:it(e.cachesDir??I(K(),`Library`,`Caches`)),bugReportLedgerFiles:at(e.bugReportsDir??q()),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=d(e,t);if(!B(r))return{status:`missing`,lockPath:r};let i;try{i=JSON.parse(H(r,`utf-8`))}catch{return{status:`corrupt`,lockPath:r}}if(!i||typeof i!=`object`||!h(i.pid))return{status:`corrupt`,lockPath:r};let a=i;if(!(n.isAlive??D)(a.pid))return{status:`dead-pid`,lockPath:r,lock:a};if(typeof a.machineId==`string`)return a.machineId===(n.machineId??S())?{status:`alive`,lockPath:r,lock:a}:{status:`foreign-host`,lockPath:r,lock:a};let o=n.host??be();return a.hostname===o?{status:`alive`,lockPath:r,lock:a}:{status:`foreign-host`,lockPath:r,lock:a}}function bn(e){return e.replace(/:\d+$/,``)}function xn(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:bn(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[^/?#]*@)?([^@/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:bn(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:bn(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 Sn=[{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`}],Cn=[...f.map(e=>T[e]),`open-knowledge`];function wn(e){if(!ce(e))throw Error(`skill cleanup requires an absolute home directory; got ${JSON.stringify(e)}`);let t=R(e);if(t===z||F(t)===t)throw Error(`skill cleanup refuses to operate on the filesystem root (${t})`);return t}function Tn(e,t){let n=L(e,t);if(n.startsWith(`..`)||ce(n))return!1;let r=e;for(let e of n.split(z)){r=I(r,e);try{if(!fe(r).isDirectory())return!1}catch{return!1}}return!0}function En(e,t){try{return U(e).every(n=>t.has(I(e,n)))}catch{return!1}}function Dn(e){let t=wn(e),n=[],r=[],i=new Set;for(let e of Sn){let a=I(t,e.hostDir,`skills`);if(!Tn(t,a))continue;let o=Cn.map(e=>I(a,e)).filter(e=>B(e));n.push(...o);for(let e of o)i.add(e);let s=I(t,e.pruneRoot),c=a;for(;En(c,i)&&(r.push(c),i.add(c),c!==s);){let e=F(c);if(e===c||e===t||!e.startsWith(t+z))break;c=e}}return{skillDirs:n,emptyDirs:r}}function On(e){try{if(!fe(e).isDirectory())return!1;let t=U(e);return t.length===0||t.includes(`SKILL.md`)}catch{return!1}}function kn(e){let t=new Set,n=new Set;for(let r of Sn){let i=I(e,r.hostDir,`skills`);for(let e of Cn)t.add(I(i,e));let a=I(e,r.pruneRoot),o=i;for(;n.add(o),o!==a;){let t=F(o);if(t===o||t===e||!t.startsWith(e+z))break;o=t}}return{skillDirs:t,emptyDirs:n}}function An(e,t){let n=wn(e),r=kn(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(Tn(n,e)&&On(e))try{W(e,{recursive:!0,force:!0}),a.push(e)}catch{}for(let e of t.emptyDirs)if(Tn(n,e))try{ge(e),a.push(e)}catch{}return a}function jn(e){let t=wn(e),n=[];for(let e of f){let i=T[e];n.push({path:I(t,`.agents`,`skills`,i),bundleId:e,scope:`central`});for(let a of r)n.push({path:I(t,a.skillsRoot,i),bundleId:e,scope:`host`,hostDir:a.hostDir})}return n}function Mn(e,t){let n=[];for(let r of jn(e))if(r.bundleId===t)try{W(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 Nn(e){return e!=null&&e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function Pn(e,t=Date.now()){let n=i(e,t);return n===`unknown`?`—`:n}function Fn(e,t,n,r){if(t.status===`missing`||t.status===`corrupt`)return null;let i=t.lock,a=t.status===`alive`&&x(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:m(n),command:n,isDesktop:Nn(n)}}function In(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:`stale`}const Ln=new Set([`running`,`desktop`,`foreign`]);function Rn(e){switch(e){case`running`:return Y.default.green(e);case`desktop`:return Y.default.blue(e);case`foreign`:return Y.default.cyan(e);case`stale`:return Y.default.yellow(e)}}function zn(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function Bn(e){return`${zn(e.server.usage)} | ${zn(e.ui?.usage??null)}`}function Vn(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null?`—`:String(e.ui.port)}`}function Hn(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,Vn(e),Bn(e),In(e),String(e.server.pid),Pn(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=Rn(In(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=Y.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
|
|
11
|
-
`)}async function Un(e={}){let t=e.discover??p,n=e.inspect??(e=>$(e,`server`)),r=e.log??(e=>console.log(e)),i=e.resolveCommand??w,a=e.resolveUsage??C,o=await t(),s=[];for(let e of o){let t=n(e),r=Fn(e,t,t.status===`missing`||t.status===`corrupt`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`?null:a(t.lock.pid));r!=null&&s.push(r)}if(e.json){let e=s.map(e=>({...e,displayStatus:In(e)}));r(JSON.stringify(e,null,2));return}r(Hn(e.all?s:s.filter(e=>Ln.has(In(e)))))}function Wn(){return new j(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale (dead-pid) entries (foreign-host shows by default)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await Un({all:t.all===!0||e===`all`,json:t.json===!0})})}async function Gn(e,t=M()){let n=$(e,`server`);if(n.status!==`alive`&&n.status!==`foreign-host`)return null;let r=_(n.lock);if(r===null)return null;try{let n=await fetch(`${r}/api/server-info`,{signal:AbortSignal.timeout(1500)});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 Kn(e,t={}){return{targets:Jn(e,t.isAlive??D)?[{name:`server`,pid:e.lock.pid,port:e.lock.port}]:[]}}async function qn(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??Gn,o=e.logger??M(),s=Kn(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 Jn(e,t){return e.status===`alive`||e.status===`foreign-host`&&t(e.lock.pid)}async function Yn(e,t=D){let n=await p(),r=null;for(let i of n){let n=$(i,`server`);if(Jn(n,t)){if(n.lock.port===e)return i;r===null&&n.lock.pid===e&&(r=i)}}return r}async function Xn(e,t){let n=await qn({lockDir:e,force:t});return(n.failed.length>0||n.declined!==void 0)&&(process.exitCode=1),n}function Zn(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 Qn(e){let t=await p(),n=0;for(let r of t)r!==e&&Jn($(r,`server`),D)&&n++;return n}function $n(e){return new j(`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=y(process.cwd()),n=await qn({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 Qn(t);console.log(Zn(process.cwd(),e,{listingFollows:e>0})),e>0&&await Un({})}return}if(i===`all`){let e=await p();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let n of e)Jn($(n,`server`),D)&&(await Xn(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 Yn(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}await Xn(t,r);return}let a=R(Me(),i),o=y(a),s=[],c=await qn({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(Zn(a,await Qn(o)))})}export{Me as C,Re as S,ke as T,Be as _,An as a,Pe as b,jn as c,yn as d,hn as f,Xe as g,q as h,Wn as i,xn as l,Ze as m,qn as n,Dn as o,gn as p,$n as r,Mn as s,Gn as t,$ as u,Ne as v,je as w,Le as x,Fe as y};
|
package/dist/start-BlH0bGhn.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{S as e,m as t,p as n,r}from"./start-BeubOhRd.mjs";export{r as bootStartServer,n as resolveBundledReactShellDir,t as resolveHost,e as startCommand};
|