wiki-graph 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2059,7 +2059,7 @@ WHERE overlay.entry_path IN (?, ?)
2059
2059
  AND overlay.kind = 'file'
2060
2060
  AND overlay.workspace_path IS NOT NULL
2061
2061
  ORDER BY overlay.updated_at ASC
2062
- `,[lt,N],At)))}async function DU(t,e){let r=await He(t.archiveKey,t.entryPath,"write");try{let n=await He(t.archiveKey,t.entryPath,"state");try{let i=await Ot(t.archiveKey,t.entryPath);if(i?.workspacePath===void 0||i.workspacePath!==t.workspacePath||!await MU(i,e))return{freedBytes:0,removed:!1};let a=await Se(i.workspacePath);return e.dryRun||(await dn(i.archiveKey,i.entryPath),await tT(i.workspacePath,{force:!0}),a+=await Nc(OU(i.workspacePath))),{freedBytes:a,removed:!0}}finally{await n()}}finally{await r()}}async function MU(t,e){return await cs(t.archiveKey,t.entryPath)||t.workspacePath===void 0?!1:await WU(t)?!0:!(!e.force&&e.now-t.updatedAt<36e5||t.entryPath===N&&!e.force)}async function WU(t){return t.workspacePath===void 0||!await Pt(t.workspacePath)||!await Pt(t.archivePath)?!0:t.entryPath!==N?!1:await jb(t)!=="current"}async function FU(t){let e=ls(),r;try{r=await LU(e,{withFileTypes:!0})}catch(o){if(w(o)&&o.code==="ENOENT")return{freedBytes:0,removed:0,scanned:0};throw o}let n=0,i=0,a=0;for(let o of r){if(!o.isDirectory())continue;let s=o.name;if(await ds(s))continue;let c=new Set((await dr(s)).map(u=>u.workspacePath).filter(u=>u!==void 0));for(let u of await kl(eT(e,s))){if(a+=1,Fp(AU(u))||c.has(u))continue;let l=await Se(u);t.dryRun||await tT(u,{force:!0}),n+=l,i+=1}if(!t.dryRun){let u=await jp(eT(e,s));n+=u.freedBytes,i+=u.removed,a+=u.scanned}}return{freedBytes:n,removed:i,scanned:a}}var rT=d(()=>{"use strict";Va();T();El();st();Be();Mi();un();Il();mt();ji()});var nT=d(()=>{"use strict";Zv();vh();fs();rT()});var Th=d(()=>{"use strict";nT()});import{resolve as jU}from"path";var M,iT=d(()=>{"use strict";L();Th();Rn();Ec();M=class{#e;#t=new Qn;constructor(e){this.#e=jU(e)}async read(e,r={}){return await this.readDocument(async(n,i)=>await e(new Sr(n,i)),r)}async readDocument(e,r={}){return await this.#t.withArchiveSession(this.#e,async n=>{if(r.documentDirPath!==void 0)return await n.materializeReadWorkspace(r.documentDirPath,async a=>{let o=await ye.open(a);try{return await e(o,a)}finally{await o.release()}});let i=await ye.open(this.#e,{fileStore:n.createFileStore({readonlyDatabase:!0,...r.searchIndexWritebackPolicy===void 0?{}:{searchIndexWritebackPolicy:r.searchIndexWritebackPolicy}})});try{return await e(i,this.#e)}finally{await i.release()}})}async write(e,r={}){return await this.#t.withArchiveSession(this.#e,async n=>{let i=await ye.open(this.#e,{fileStore:n.createFileStore({...r.searchIndexWritebackPolicy===void 0?{}:{searchIndexWritebackPolicy:r.searchIndexWritebackPolicy}})});try{return await e(i)}finally{try{await i.release()}finally{await gn(this.#e)}}})}}});var ze=d(()=>{"use strict";Lt();hb();iT();Th()});import{createHash as Jpe}from"crypto";import{mkdir as Qpe,readdir as GU,rm as BU,stat as Xpe,writeFile as Vpe}from"fs/promises";import{join as aT}from"path";async function Qv(t){let e=aT(Pe(),"library"),r=await UU();if(r===void 0)return{freedBytes:0,removed:0,scanned:0};let n=new Set(r.map(c=>String(c))),i=await GU(e,{withFileTypes:!0}).catch(c=>{if(w(c)&&c.code==="ENOENT")return[];throw c}),a=0,o=0,s=0;for(let c of i){if(!c.isDirectory()||(a+=1,n.has(c.name)))continue;let u=Number(c.name);if(Number.isInteger(u)&&await jg(u))continue;let l=aT(e,c.name),m=await Se(l);t.dryRun||await BU(l,{force:!0,recursive:!0}),o+=1,s+=m}return{freedBytes:s,removed:o,scanned:a}}async function UU(){let t=await A(oe(),"");try{return await t.queryAll("SELECT id FROM libraries",void 0,e=>y(e,"id"))}catch{return}finally{await t.close()}}var mo=d(()=>{"use strict";x();Xt();Ii();L();ze();Hi();hn();Va();se();T();po();rn();Ci()});import{randomBytes as fhe}from"crypto";import{constants as ghe,copyFile as bhe,mkdir as She,opendir as whe,realpath as Ehe,rename as khe,rm as Ihe,stat as xhe}from"fs/promises";import{dirname as vhe,isAbsolute as The,join as _he,relative as Che,resolve as Phe}from"path";var qU,Ghe,po=d(()=>{"use strict";x();L();se();vt();ze();T();rn();mo();Ci();qU=`
2062
+ `,[lt,N],At)))}async function DU(t,e){let r=await He(t.archiveKey,t.entryPath,"write");try{let n=await He(t.archiveKey,t.entryPath,"state");try{let i=await Ot(t.archiveKey,t.entryPath);if(i?.workspacePath===void 0||i.workspacePath!==t.workspacePath||!await MU(i,e))return{freedBytes:0,removed:!1};let a=await Se(i.workspacePath);return e.dryRun||(await dn(i.archiveKey,i.entryPath),await tT(i.workspacePath,{force:!0}),a+=await Nc(OU(i.workspacePath))),{freedBytes:a,removed:!0}}finally{await n()}}finally{await r()}}async function MU(t,e){return await cs(t.archiveKey,t.entryPath)||t.workspacePath===void 0?!1:await WU(t)?!0:!(!e.force&&e.now-t.updatedAt<36e5||t.entryPath===N&&!e.force)}async function WU(t){return t.workspacePath===void 0||!await Pt(t.workspacePath)||!await Pt(t.archivePath)?!0:t.entryPath!==N?!1:await jb(t)!=="current"}async function FU(t){let e=ls(),r;try{r=await LU(e,{withFileTypes:!0})}catch(o){if(w(o)&&o.code==="ENOENT")return{freedBytes:0,removed:0,scanned:0};throw o}let n=0,i=0,a=0;for(let o of r){if(!o.isDirectory())continue;let s=o.name;if(await ds(s))continue;let c=new Set((await dr(s)).map(u=>u.workspacePath).filter(u=>u!==void 0));for(let u of await kl(eT(e,s))){if(a+=1,Fp(AU(u))||c.has(u))continue;let l=await Se(u);t.dryRun||await tT(u,{force:!0}),n+=l,i+=1}if(!t.dryRun){let u=await jp(eT(e,s));n+=u.freedBytes,i+=u.removed,a+=u.scanned}}return{freedBytes:n,removed:i,scanned:a}}var rT=d(()=>{"use strict";Va();T();El();st();Be();Mi();un();Il();mt();ji()});var nT=d(()=>{"use strict";Zv();vh();fs();rT()});var Th=d(()=>{"use strict";nT()});import{resolve as jU}from"path";var M,iT=d(()=>{"use strict";L();Th();Rn();Ec();M=class{#e;#t=new Qn;constructor(e){this.#e=jU(e)}async read(e,r={}){return await this.readDocument(async(n,i)=>await e(new Sr(n,i)),r)}async readDocument(e,r={}){return await this.#t.withArchiveSession(this.#e,async n=>{if(r.documentDirPath!==void 0)return await n.materializeReadWorkspace(r.documentDirPath,async a=>{let o=await ye.open(a);try{return await e(o,a)}finally{await o.release()}});let i=await ye.open(this.#e,{fileStore:n.createFileStore({readonlyDatabase:!0,...r.searchIndexWritebackPolicy===void 0?{}:{searchIndexWritebackPolicy:r.searchIndexWritebackPolicy}})});try{return await e(i,this.#e)}finally{await i.release()}})}async write(e,r={}){return await this.#t.withArchiveSession(this.#e,async n=>{let i=await ye.open(this.#e,{fileStore:n.createFileStore({...r.searchIndexWritebackPolicy===void 0?{}:{searchIndexWritebackPolicy:r.searchIndexWritebackPolicy}})});try{return await e(i)}finally{try{await i.release()}finally{await gn(this.#e)}}})}}});var ze=d(()=>{"use strict";Lt();hb();iT();Th()});import{createHash as Jpe}from"crypto";import{mkdir as Qpe,readdir as GU,rm as BU,stat as Xpe,writeFile as Vpe}from"fs/promises";import{join as aT}from"path";async function Qv(t){let e=aT(Pe(),"library"),r=await UU();if(r===void 0)return{freedBytes:0,removed:0,scanned:0};let n=new Set(r.map(c=>String(c))),i=await GU(e,{withFileTypes:!0}).catch(c=>{if(w(c)&&c.code==="ENOENT")return[];throw c}),a=0,o=0,s=0;for(let c of i){if(!c.isDirectory()||(a+=1,n.has(c.name)))continue;let u=Number(c.name);if(Number.isInteger(u)&&await jg(u))continue;let l=aT(e,c.name),m=await Se(l);t.dryRun||await BU(l,{force:!0,recursive:!0}),o+=1,s+=m}return{freedBytes:s,removed:o,scanned:a}}async function UU(){let t=await A(oe(),"");try{return await t.queryAll("SELECT id FROM libraries",void 0,e=>y(e,"id"))}catch{return}finally{await t.close()}}var mo=d(()=>{"use strict";x();Xt();Ii();L();ze();Hi();hn();Va();se();T();po();rn();Ci()});import{randomBytes as yhe}from"crypto";import{constants as bhe,copyFile as She,mkdir as whe,opendir as Ehe,realpath as khe,rename as Ihe,rm as xhe,stat as Rhe}from"fs/promises";import{dirname as The,isAbsolute as _he,join as Che,relative as Phe,resolve as Lhe}from"path";var qU,Bhe,po=d(()=>{"use strict";x();L();se();vt();ze();T();rn();mo();Ci();qU=`
2063
2063
  id INTEGER PRIMARY KEY AUTOINCREMENT,
2064
2064
  library_id INTEGER NOT NULL,
2065
2065
  public_id TEXT NOT NULL,
@@ -2072,7 +2072,7 @@ ORDER BY overlay.updated_at ASC
2072
2072
  created_at TEXT NOT NULL,
2073
2073
  updated_at TEXT NOT NULL,
2074
2074
  UNIQUE(library_id, public_id)
2075
- `,Ghe=`
2075
+ `,Bhe=`
2076
2076
  CREATE TABLE IF NOT EXISTS library_archives (
2077
2077
  ${qU}
2078
2078
  );
@@ -2082,16 +2082,16 @@ ${qU}
2082
2082
 
2083
2083
  CREATE INDEX IF NOT EXISTS idx_library_archives_library_path
2084
2084
  ON library_archives(library_id, relative_path);
2085
- `});var Ph=d(()=>{"use strict";ze();po();rn()});var cT=d(()=>{"use strict";Es();xs();Gi();As();Ls();De();Os();mr();hn();mo();Ph()});var dT=d(()=>{"use strict";km();xs();cT();De();po();Ph();rn();mo()});var bd=d(()=>{"use strict";rn();po();dT();mo();Ci()});import{posix as xfe,resolve as Rfe,sep as vfe}from"path";import{open as _fe}from"yauzl";var uT=d(()=>{"use strict"});import{createWriteStream as Ffe}from"fs";import{mkdir as Gfe}from"fs/promises";import{dirname as Ufe,resolve as Hfe}from"path";import{pipeline as $fe}from"stream/promises";var lT=d(()=>{"use strict";uT()});var Lh=d(()=>{"use strict"});var mT=d(()=>{"use strict";x();Lh()});import{readFile as eye,readdir as tye}from"fs/promises";import{join as nye}from"path";var pT=d(()=>{"use strict";T()});import{join as sye}from"path";var hT=d(()=>{"use strict";x();Lh()});import{readFile as mye,readdir as pye}from"fs/promises";import{join as fye}from"path";var fT=d(()=>{"use strict";Ju();T()});import{mkdir as wye,writeFile as Eye}from"fs/promises";import{join as Iye}from"path";var yT=d(()=>{"use strict"});import{rm as Aye}from"fs/promises";import{join as Nye}from"path";var gT=d(()=>{"use strict";x();pT();hT();fT();yT()});var bT=d(()=>{"use strict";gT()});import{rm as Jye}from"fs/promises";import{join as Qye,resolve as Xye}from"path";var Ah=d(()=>{"use strict";ut();L();ze();lT();mT();bT()});import{rm as age}from"fs/promises";import{homedir as sge}from"os";import{resolve as dge}from"path";var ST=d(()=>{"use strict";bd();se();Ah();ze();rs()});var H=d(()=>{"use strict";Ve();tf();qd();ai();_e();Pf();Po();To();bd();se();ut();Tn();la();vr();Rp();qt();rt();ze();L();Zt();Rn();rs();ST();hn();Ah();T();qt();hn();qt();qt();qt();qt();Bt();vr();L();Un()});function pe(t,e){return`${t}
2086
- See: ${e}`}var me,Oh=d(()=>{"use strict";H();me={command:`${"wg"} --help`,config:`${"wg"} help config`,format:`${"wg"} help format`,readiness:`${"wg"} help readiness`,root:`${"wg"} --help`,runtime:`${"wg"} help runtime`,uri:`${"wg"} help uri`}});import{extname as Hbe}from"path";var wT=d(()=>{"use strict";Oh()});import{AsyncLocalStorage as rH}from"async_hooks";function Sd(){return $t.getStore()?.cwd??process.cwd()}function ET(){return $t.getStore()?.env??process.env}function kT(){return $t.getStore()?.devProjectRoot}function IT(){return $t.getStore()?.stateDir}function xT(){return nH??$t.getStore()?.queueAutostart??!0}function Nh(){return $t.getStore()?.stdout??process.stdout}function RT(){return $t.getStore()?.stdoutIsTTY??Nh().isTTY}function vT(t){let e=$t.getStore();if(e===void 0){process.exitCode=t;return}e.exitCode=t}var $t,nH,Xn=d(()=>{"use strict";$t=new rH});import{createReadStream as Vbe}from"fs";import{rm as Zbe}from"fs/promises";import{join as tSe}from"path";async function ie(t){await iH(t)}async function iH(t){await new Promise((e,r)=>{Nh().write(t,n=>{if(n==null){e();return}if(aH(n)){vT(0),e();return}r(n)})})}function aH(t){return t.code==="EPIPE"}var TT=d(()=>{"use strict";H();Xn()});function ho(t){return`${JSON.stringify(wd(t),null,2)}
2085
+ `});var Ph=d(()=>{"use strict";ze();po();rn()});var cT=d(()=>{"use strict";Es();xs();Gi();As();Ls();De();Os();mr();hn();mo();Ph()});var dT=d(()=>{"use strict";km();xs();cT();De();po();Ph();rn();mo()});var bd=d(()=>{"use strict";rn();po();dT();mo();Ci()});import{posix as Rfe,resolve as vfe,sep as Tfe}from"path";import{open as Cfe}from"yauzl";var uT=d(()=>{"use strict"});import{createWriteStream as jfe}from"fs";import{mkdir as Bfe}from"fs/promises";import{dirname as Hfe,resolve as qfe}from"path";import{pipeline as Kfe}from"stream/promises";var lT=d(()=>{"use strict";uT()});var Lh=d(()=>{"use strict"});var mT=d(()=>{"use strict";x();Lh()});import{readFile as tye,readdir as rye}from"fs/promises";import{join as iye}from"path";var pT=d(()=>{"use strict";T()});import{join as cye}from"path";var hT=d(()=>{"use strict";x();Lh()});import{readFile as pye,readdir as hye}from"fs/promises";import{join as yye}from"path";var fT=d(()=>{"use strict";Ju();T()});import{mkdir as Eye,writeFile as kye}from"fs/promises";import{join as xye}from"path";var yT=d(()=>{"use strict"});import{rm as Oye}from"fs/promises";import{join as Dye}from"path";var gT=d(()=>{"use strict";x();pT();hT();fT();yT()});var bT=d(()=>{"use strict";gT()});import{rm as zye}from"fs/promises";import{join as Xye,resolve as Vye}from"path";var Ah=d(()=>{"use strict";ut();L();ze();lT();mT();bT()});import{rm as oge}from"fs/promises";import{homedir as cge}from"os";import{resolve as uge}from"path";var ST=d(()=>{"use strict";bd();se();Ah();ze();rs()});var H=d(()=>{"use strict";Ve();tf();qd();ai();_e();Pf();Po();To();bd();se();ut();Tn();la();vr();Rp();qt();rt();ze();L();Zt();Rn();rs();ST();hn();Ah();T();qt();hn();qt();qt();qt();qt();Bt();vr();L();Un()});function pe(t,e){return`${t}
2086
+ See: ${e}`}var me,Oh=d(()=>{"use strict";H();me={command:`${"wg"} --help`,config:`${"wg"} help config`,format:`${"wg"} help format`,readiness:`${"wg"} help readiness`,root:`${"wg"} --help`,runtime:`${"wg"} help runtime`,uri:`${"wg"} help uri`}});import{extname as Kbe}from"path";var wT=d(()=>{"use strict";Oh()});import{AsyncLocalStorage as rH}from"async_hooks";function Sd(){return $t.getStore()?.cwd??process.cwd()}function ET(){return $t.getStore()?.env??process.env}function kT(){return $t.getStore()?.devProjectRoot}function IT(){return $t.getStore()?.stateDir}function xT(){return nH??$t.getStore()?.queueAutostart??!0}function Nh(){return $t.getStore()?.stdout??process.stdout}function RT(){return $t.getStore()?.stdoutIsTTY??Nh().isTTY}function vT(t){let e=$t.getStore();if(e===void 0){process.exitCode=t;return}e.exitCode=t}var $t,nH,Xn=d(()=>{"use strict";$t=new rH});import{createReadStream as eSe}from"fs";import{rm as rSe}from"fs/promises";import{join as iSe}from"path";async function ie(t){await iH(t)}async function iH(t){await new Promise((e,r)=>{Nh().write(t,n=>{if(n==null){e();return}if(aH(n)){vT(0),e();return}r(n)})})}function aH(t){return t.code==="EPIPE"}var TT=d(()=>{"use strict";H();Xn()});function ho(t){return`${JSON.stringify(wd(t),null,2)}
2087
2087
  `}function _T(t){return`${JSON.stringify(wd(t))}
2088
- `}function wd(t){if(t===null||typeof t=="boolean"||typeof t=="number"||typeof t=="string")return t;if(Array.isArray(t))return t.map(e=>wd(e)??null);if(typeof t=="object")return sH(t)}function sH(t){let e=Object.entries(t).map(([n,i],a)=>({index:a,key:n,priority:oH.get(n)??Number.MAX_SAFE_INTEGER,value:i})),r={};for(let n of e.sort((i,a)=>i.priority-a.priority||i.index-a.index)){let i=wd(n.value);i!==void 0&&(r[n.key]=i)}return r}var oH,CT=d(()=>{"use strict";oH=new Map(["at","seq","uri","id","jobId","type","target","label","labels","title","state","name","qid","predicate","subjectLabel","objectLabel","subjectQid","objectQid","score","queueRank","chapter","chapterId","fragment","fragmentId","position","range","start","end","shown","total","count","mentionCount","nodeCount","edgeCount","summaryCount","limit","order","match","lens","terms","types","chapters","query","objects","items","nextCursor","archiveKey","archivePath","workspacePath","eventsPath","createdAt","updatedAt","finishedAt","currentStep","step","phase","phaseDetail","phaseDone","phaseTotal","phaseUnit","words","totalWords","outputTokens","authors","language","identifier","publisher","publishedAt","sourceFormat","snippet","summary","description","recommendation","risk","error","message","children","nodes","links","neighbors","incoming","outgoing","nodeGroups","sourceFragments","sources","tree","meta","evidence","content","source","text","prompt","llmJSON","errorJSON"].map((t,e)=>[t,e]))});function dH(t){return t!==""&&cH.test(t)?t:`'${t.replaceAll("'","'\\''")}'`}function uH(t){return t.map(dH).join(" ")}function Dh(t){return uH(["wg",...t])}var cH,PT=d(()=>{"use strict";H();cH=/^[A-Za-z0-9_@%+=:,./-]+$/u});var LT=d(()=>{"use strict"});import{existsSync as uSe,readFileSync as lSe}from"fs";import{dirname as pSe,join as hSe,parse as fSe,resolve as ySe}from"path";var AT=d(()=>{"use strict";Xn()});var gt=d(()=>{"use strict";Oh();wT();TT();CT();PT();LT();AT()});async function Ed(t){return await pH(async e=>await hH(e,t))}function mH(t,e){switch(t){case"llm":return yH(e);case"concurrent":return gH(e);case"wikispine":return bH(e)}}async function pH(t){let e=await A(oe(),lH);try{return await t(e)}finally{await e.close()}}async function hH(t,e){let r=await t.queryOne("SELECT value_json FROM config_sections WHERE section = ?",[e],n=>String(n.value_json));return r===void 0?{}:fH(e,r)}function fH(t,e){let r;try{r=JSON.parse(e)}catch(n){throw new Error(`Invalid local config JSON for ${t}: ${SH(n)}`)}if(r===null||typeof r!="object"||Array.isArray(r))throw new Error(`Invalid local config section ${t}: expected object.`);return mH(t,r)}function yH(t){let e=new Set(["apiKey","baseURL","model","name","provider"]),r=new Set(["anthropic","google","openai","openai-compatible"]),n={};for(let[i,a]of Object.entries(t)){if(!e.has(i))throw new Error(`Unknown llm config key: ${i}`);if(typeof a!="string"||a.trim()==="")throw new Error(`llm.${i} must be a non-empty string.`);let o=a.trim();if(i==="provider"&&!r.has(o))throw new Error(`Unknown llm.provider: ${o}`);n[i]=o}return n}function gH(t){let e=new Set(["job","request"]),r={};for(let[n,i]of Object.entries(t)){if(!e.has(n))throw new Error(`Unknown concurrent config key: ${n}`);let a=typeof i=="number"?i:typeof i=="string"?Number(i):NaN;if(!Number.isInteger(a)||a<=0)throw new Error(`concurrent.${n} must be a positive integer.`);r[n]=a}return r}function bH(t){let e=new Set(["provider"]),r=new Set(["cli","fetch"]),n={};for(let[i,a]of Object.entries(t)){if(!e.has(i))throw new Error(`Unknown wikispine config key: ${i}`);if(typeof a!="string"||a.trim()==="")throw new Error(`wikispine.${i} must be a non-empty string.`);let o=a.trim();if(i==="provider"&&!r.has(o))throw new Error(`Unknown wikispine.provider: ${o}`);n[i]=o}return n}function SH(t){return t instanceof Error?t.message:String(t)}var lH,Mh=d(()=>{"use strict";H();H();lH=`
2088
+ `}function wd(t){if(t===null||typeof t=="boolean"||typeof t=="number"||typeof t=="string")return t;if(Array.isArray(t))return t.map(e=>wd(e)??null);if(typeof t=="object")return sH(t)}function sH(t){let e=Object.entries(t).map(([n,i],a)=>({index:a,key:n,priority:oH.get(n)??Number.MAX_SAFE_INTEGER,value:i})),r={};for(let n of e.sort((i,a)=>i.priority-a.priority||i.index-a.index)){let i=wd(n.value);i!==void 0&&(r[n.key]=i)}return r}var oH,CT=d(()=>{"use strict";oH=new Map(["at","seq","uri","id","jobId","type","target","label","labels","title","state","name","qid","predicate","subjectLabel","objectLabel","subjectQid","objectQid","score","queueRank","chapter","chapterId","fragment","fragmentId","position","range","start","end","shown","total","count","mentionCount","nodeCount","edgeCount","summaryCount","limit","order","match","lens","terms","types","chapters","query","objects","items","nextCursor","archiveKey","archivePath","workspacePath","eventsPath","createdAt","updatedAt","finishedAt","currentStep","step","phase","phaseDetail","phaseDone","phaseTotal","phaseUnit","words","totalWords","outputTokens","authors","language","identifier","publisher","publishedAt","sourceFormat","snippet","summary","description","recommendation","risk","error","message","children","nodes","links","neighbors","incoming","outgoing","nodeGroups","sourceFragments","sources","tree","meta","evidence","content","source","text","prompt","llmJSON","errorJSON"].map((t,e)=>[t,e]))});function dH(t){return t!==""&&cH.test(t)?t:`'${t.replaceAll("'","'\\''")}'`}function uH(t){return t.map(dH).join(" ")}function Dh(t){return uH(["wg",...t])}var cH,PT=d(()=>{"use strict";H();cH=/^[A-Za-z0-9_@%+=:,./-]+$/u});var LT=d(()=>{"use strict"});import{existsSync as pSe,readFileSync as hSe}from"fs";import{dirname as ySe,join as gSe,parse as bSe,resolve as SSe}from"path";var AT=d(()=>{"use strict";Xn()});var gt=d(()=>{"use strict";Oh();wT();TT();CT();PT();LT();AT()});async function Ed(t){return await pH(async e=>await hH(e,t))}function mH(t,e){switch(t){case"llm":return yH(e);case"concurrent":return gH(e);case"wikispine":return bH(e)}}async function pH(t){let e=await A(oe(),lH);try{return await t(e)}finally{await e.close()}}async function hH(t,e){let r=await t.queryOne("SELECT value_json FROM config_sections WHERE section = ?",[e],n=>String(n.value_json));return r===void 0?{}:fH(e,r)}function fH(t,e){let r;try{r=JSON.parse(e)}catch(n){throw new Error(`Invalid local config JSON for ${t}: ${SH(n)}`)}if(r===null||typeof r!="object"||Array.isArray(r))throw new Error(`Invalid local config section ${t}: expected object.`);return mH(t,r)}function yH(t){let e=new Set(["apiKey","baseURL","model","name","provider"]),r=new Set(["anthropic","google","openai","openai-compatible"]),n={};for(let[i,a]of Object.entries(t)){if(!e.has(i))throw new Error(`Unknown llm config key: ${i}`);if(typeof a!="string"||a.trim()==="")throw new Error(`llm.${i} must be a non-empty string.`);let o=a.trim();if(i==="provider"&&!r.has(o))throw new Error(`Unknown llm.provider: ${o}`);n[i]=o}return n}function gH(t){let e=new Set(["job","request"]),r={};for(let[n,i]of Object.entries(t)){if(!e.has(n))throw new Error(`Unknown concurrent config key: ${n}`);let a=typeof i=="number"?i:typeof i=="string"?Number(i):NaN;if(!Number.isInteger(a)||a<=0)throw new Error(`concurrent.${n} must be a positive integer.`);r[n]=a}return r}function bH(t){let e=new Set(["provider"]),r=new Set(["cli","fetch"]),n={};for(let[i,a]of Object.entries(t)){if(!e.has(i))throw new Error(`Unknown wikispine config key: ${i}`);if(typeof a!="string"||a.trim()==="")throw new Error(`wikispine.${i} must be a non-empty string.`);let o=a.trim();if(i==="provider"&&!r.has(o))throw new Error(`Unknown wikispine.provider: ${o}`);n[i]=o}return n}function SH(t){return t instanceof Error?t.message:String(t)}var lH,Mh=d(()=>{"use strict";H();H();lH=`
2089
2089
  CREATE TABLE IF NOT EXISTS config_sections (
2090
2090
  section TEXT PRIMARY KEY,
2091
2091
  value_json TEXT NOT NULL,
2092
2092
  updated_at INTEGER NOT NULL
2093
2093
  );
2094
- `});import{z as he}from"zod";async function Id(t){let[e,r,n]=await Promise.all([Ed("llm"),Ed("concurrent"),Ed("wikispine")]),i=t?.llmJSON===void 0?void 0:kH(t.llmJSON),a=NT({apiKey:fo(i?.apiKey,kd(e.apiKey)),baseURL:fo(i?.baseURL,kd(e.baseURL)),model:fo(i?.model,kd(e.model)),name:fo(i?.name,kd(e.name)),provider:fo(i?.provider,vH(e.provider))}),o=OT(r.request),s=OT(r.job),c=TH(n);return{...s===void 0&&o===void 0?{}:{concurrent:{...s===void 0?{}:{job:s},...o===void 0?{}:{request:o}}},...a===void 0?{}:{llm:a},...c===void 0?{}:{wikispine:c}}}function kH(t){let e=CH(t);if(e===void 0)throw new Error(pe("--llm must be a non-empty JSON object.",me.config));let r;try{r=JSON.parse(e)}catch(c){throw new Error(pe(`Invalid --llm JSON: ${PH(c)}`,me.config))}let n=EH.safeParse(r);if(!n.success)throw new Error(pe(`Invalid --llm config: ${n.error.issues.map(c=>`${c.path.join(".")||"<root>"}: ${c.message}`).join("; ")}`,me.config));let i=n.data.llm??n.data,a=i.provider??IH(i),o=RH(i),s=NT({apiKey:i.apiKey,baseURL:o,model:i.model,name:i.name,provider:a});if(s===void 0)throw new Error(pe("--llm must contain at least one supported LLM field.",me.config));return s}function IH(t){return t.provider===void 0&&(t.baseURL!==void 0||t.baseUrl!==void 0||t.chatCompletionsUrl!==void 0)?"openai-compatible":t.provider}function xH(t){if(t.chatCompletionsUrl===void 0)return;let e="/chat/completions";if(!t.chatCompletionsUrl.endsWith(e))throw new Error(pe("--llm chatCompletionsUrl must end with /chat/completions when baseURL is not provided.",me.config));return t.chatCompletionsUrl.slice(0,-e.length)}function RH(t){return t.baseURL!==void 0?t.baseURL:t.baseUrl!==void 0?t.baseUrl:xH(t)}function NT(t){if(!(t.apiKey===void 0&&t.baseURL===void 0&&t.model===void 0&&t.name===void 0&&t.provider===void 0))return{...t.apiKey===void 0?{}:{apiKey:t.apiKey},...t.baseURL===void 0?{}:{baseURL:t.baseURL},...t.model===void 0?{}:{model:t.model},...t.name===void 0?{}:{name:t.name},...t.provider===void 0?{}:{provider:t.provider}}}function vH(t){if(typeof t!="string")return;let e=Wh.safeParse(t);return e.success?e.data:void 0}function TH(t){let e=_H(t.provider);if(e!==void 0)return{provider:e}}function _H(t){return t==="cli"||t==="fetch"?t:void 0}function kd(t){return typeof t=="string"?t:void 0}function OT(t){return typeof t=="number"&&Number.isInteger(t)&&t>0?t:void 0}function fo(t,e){return t??e}function CH(t){let e=t?.trim();return e===void 0||e===""?void 0:e}function PH(t){return t instanceof Error?t.message:String(t)}var wH,Wh,EH,xd=d(()=>{"use strict";gt();Mh();wH=["anthropic","google","openai","openai-compatible"],Wh=he.enum(wH),EH=he.object({apiKey:he.string().min(1).optional(),baseURL:he.string().min(1).optional(),baseUrl:he.string().min(1).optional(),chatCompletionsUrl:he.string().min(1).optional(),llm:he.object({apiKey:he.string().min(1).optional(),baseURL:he.string().min(1).optional(),baseUrl:he.string().min(1).optional(),chatCompletionsUrl:he.string().min(1).optional(),model:he.string().min(1).optional(),name:he.string().min(1).optional(),provider:Wh.optional()}).optional(),model:he.string().min(1).optional(),name:he.string().min(1).optional(),provider:Wh.optional()})});import{createAnthropic as LH}from"@ai-sdk/anthropic";import{createGoogleGenerativeAI as AH}from"@ai-sdk/google";import{createOpenAI as OH}from"@ai-sdk/openai";import{createOpenAICompatible as NH}from"@ai-sdk/openai-compatible";function DT(t){let e=t.llm;if(e?.provider===void 0||e.model===void 0)throw new Error(pe("Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model.",me.config));return{model:DH(e.provider,e.model,{apiKey:e.apiKey,baseURL:e.baseURL,name:e.name}),...t.concurrent?.request===void 0?{}:{concurrent:t.concurrent.request}}}function DH(t,e,r){switch(t){case"anthropic":return LH({...r.apiKey===void 0?{}:{apiKey:r.apiKey},...r.name===void 0?{}:{name:r.name}})(e);case"google":return AH({...r.apiKey===void 0?{}:{apiKey:r.apiKey},...r.name===void 0?{}:{name:r.name}})(e);case"openai":{if(r.baseURL!==void 0)throw new Error(pe("openai does not accept llm.baseURL or baseURL in --llm JSON. Use openai-compatible for third-party OpenAI-style APIs.",me.config));return OH({...r.apiKey===void 0?{}:{apiKey:r.apiKey},...r.name===void 0?{}:{name:r.name}})(e)}case"openai-compatible":{if(r.baseURL===void 0)throw new Error(pe("openai-compatible requires llm.baseURL or baseURL in --llm JSON.",me.config));return NH({baseURL:r.baseURL,name:r.name??MH(r.baseURL),...r.apiKey===void 0?{}:{apiKey:r.apiKey}})(e)}}}function MH(t){try{return new URL(t).hostname}catch{return"openai-compatible"}}var Fh=d(()=>{"use strict";gt()});function MT(t,e,r,n,i){let a=WH(t),o=Math.max(r,Math.ceil(e/a.wordsPerCall)),s=Math.max(1,t==="reading-graph"?1:n.request),c=Math.ceil(o/s),u=e*a.secondsPerWord;return{model:i,timeSeconds:{max:Math.ceil(c*a.maxSecondsPerCall+u),min:Math.ceil(c*a.minSecondsPerCall+u)},tokens:{cacheableInput:Math.ceil(e*a.cacheableInputTokenPerWord),input:Math.ceil(e*a.inputTokenPerWord),output:Math.ceil(e*a.outputTokenPerWord)}}}function WT(t){if(!t.hasGenerationWork)return[];let e=[],r=t.concurrent.request<4?6:t.concurrent.request<8?8:void 0;return r!==void 0&&e.push({command:`wg wikg://local/config/concurrent put request ${r}`,current:t.concurrent.request,kind:"request",message:"LLM request concurrency can often be higher. Use at least 4; 6-8 is usually faster when the provider allows it.",recommended:r}),t.concurrent.job<4&&t.chapters>1&&e.push({command:"wg wikg://local/config/concurrent put job 4",current:t.concurrent.job,kind:"job",message:"Multiple chapters need generation and job concurrency is below 4. Raising it lets chapter jobs run in parallel.",recommended:4}),e}function FT(t){return t?.model===void 0?"not configured":t.provider===void 0?t.model:`${t.provider}/${t.model}`}function jh(t){if(t<60)return`${t}s`;let e=Math.round(t/60);return e<60?`${e}m`:`${Math.round(e/60)}h`}function WH(t){switch(t){case"knowledge-graph":return{cacheableInputTokenPerWord:60,inputTokenPerWord:80,maxSecondsPerCall:35,minSecondsPerCall:15,outputTokenPerWord:25,secondsPerWord:.02,wordsPerCall:35};case"reading-graph":return{cacheableInputTokenPerWord:20,inputTokenPerWord:25,maxSecondsPerCall:45,minSecondsPerCall:15,outputTokenPerWord:4,secondsPerWord:.01,wordsPerCall:160};case"reading-summary":return{cacheableInputTokenPerWord:45,inputTokenPerWord:55,maxSecondsPerCall:25,minSecondsPerCall:10,outputTokenPerWord:4,secondsPerWord:.01,wordsPerCall:110}}}var jT=d(()=>{"use strict"});import{clearLine as USe,cursorTo as HSe,moveCursor as qSe}from"readline";var GT=d(()=>{"use strict"});function FH(t){let e=t.counters??[],r=e.length===0?"":` ${e.map(jH).join(" | ")}`,n=GH(t.metricGroups);return`${t.phase}${r}${n===""?"":` ${n}`}`}function jH(t){return t.name===t.unit?`${t.name} ${t.done}/${t.total}`:`${t.name} ${t.done}/${t.total} ${t.unit}`}function GH(t){return t===void 0?"":t.flatMap(r=>{let n=r.metrics.map(i=>`${i.name}: ${i.value}`);return n.length===0?[]:[`[${r.name} ${n.join(" / ")}]`]}).join(" ")}function BH(t){let e=t.counters??[];return e.length>0&&e.every(r=>r.total>0&&r.done>=r.total)}var Rd,BT=d(()=>{"use strict";gt();gt();Xn();Rd=class{#e;#t;#r;#n;#i;#a=!1;constructor(e){this.#e=e.jsonl,this.#t=e.throttleMs,this.#r=e.tty??RT()===!0}async write(e){if(!(e.kind==="status"&&!this.#l(e))){if(this.#e){await this.#s(_T(e.json));return}if(e.kind==="status"){await this.#c(FH(e));return}await this.#o(e.text)}}async#o(e){this.#r&&this.#a&&(await ie(`
2094
+ `});import{z as he}from"zod";async function Id(t){let[e,r,n]=await Promise.all([Ed("llm"),Ed("concurrent"),Ed("wikispine")]),i=t?.llmJSON===void 0?void 0:kH(t.llmJSON),a=NT({apiKey:fo(i?.apiKey,kd(e.apiKey)),baseURL:fo(i?.baseURL,kd(e.baseURL)),model:fo(i?.model,kd(e.model)),name:fo(i?.name,kd(e.name)),provider:fo(i?.provider,vH(e.provider))}),o=OT(r.request),s=OT(r.job),c=TH(n);return{...s===void 0&&o===void 0?{}:{concurrent:{...s===void 0?{}:{job:s},...o===void 0?{}:{request:o}}},...a===void 0?{}:{llm:a},...c===void 0?{}:{wikispine:c}}}function kH(t){let e=CH(t);if(e===void 0)throw new Error(pe("--llm must be a non-empty JSON object.",me.config));let r;try{r=JSON.parse(e)}catch(c){throw new Error(pe(`Invalid --llm JSON: ${PH(c)}`,me.config))}let n=EH.safeParse(r);if(!n.success)throw new Error(pe(`Invalid --llm config: ${n.error.issues.map(c=>`${c.path.join(".")||"<root>"}: ${c.message}`).join("; ")}`,me.config));let i=n.data.llm??n.data,a=i.provider??IH(i),o=RH(i),s=NT({apiKey:i.apiKey,baseURL:o,model:i.model,name:i.name,provider:a});if(s===void 0)throw new Error(pe("--llm must contain at least one supported LLM field.",me.config));return s}function IH(t){return t.provider===void 0&&(t.baseURL!==void 0||t.baseUrl!==void 0||t.chatCompletionsUrl!==void 0)?"openai-compatible":t.provider}function xH(t){if(t.chatCompletionsUrl===void 0)return;let e="/chat/completions";if(!t.chatCompletionsUrl.endsWith(e))throw new Error(pe("--llm chatCompletionsUrl must end with /chat/completions when baseURL is not provided.",me.config));return t.chatCompletionsUrl.slice(0,-e.length)}function RH(t){return t.baseURL!==void 0?t.baseURL:t.baseUrl!==void 0?t.baseUrl:xH(t)}function NT(t){if(!(t.apiKey===void 0&&t.baseURL===void 0&&t.model===void 0&&t.name===void 0&&t.provider===void 0))return{...t.apiKey===void 0?{}:{apiKey:t.apiKey},...t.baseURL===void 0?{}:{baseURL:t.baseURL},...t.model===void 0?{}:{model:t.model},...t.name===void 0?{}:{name:t.name},...t.provider===void 0?{}:{provider:t.provider}}}function vH(t){if(typeof t!="string")return;let e=Wh.safeParse(t);return e.success?e.data:void 0}function TH(t){let e=_H(t.provider);if(e!==void 0)return{provider:e}}function _H(t){return t==="cli"||t==="fetch"?t:void 0}function kd(t){return typeof t=="string"?t:void 0}function OT(t){return typeof t=="number"&&Number.isInteger(t)&&t>0?t:void 0}function fo(t,e){return t??e}function CH(t){let e=t?.trim();return e===void 0||e===""?void 0:e}function PH(t){return t instanceof Error?t.message:String(t)}var wH,Wh,EH,xd=d(()=>{"use strict";gt();Mh();wH=["anthropic","google","openai","openai-compatible"],Wh=he.enum(wH),EH=he.object({apiKey:he.string().min(1).optional(),baseURL:he.string().min(1).optional(),baseUrl:he.string().min(1).optional(),chatCompletionsUrl:he.string().min(1).optional(),llm:he.object({apiKey:he.string().min(1).optional(),baseURL:he.string().min(1).optional(),baseUrl:he.string().min(1).optional(),chatCompletionsUrl:he.string().min(1).optional(),model:he.string().min(1).optional(),name:he.string().min(1).optional(),provider:Wh.optional()}).optional(),model:he.string().min(1).optional(),name:he.string().min(1).optional(),provider:Wh.optional()})});import{createAnthropic as LH}from"@ai-sdk/anthropic";import{createGoogleGenerativeAI as AH}from"@ai-sdk/google";import{createOpenAI as OH}from"@ai-sdk/openai";import{createOpenAICompatible as NH}from"@ai-sdk/openai-compatible";function DT(t){let e=t.llm;if(e?.provider===void 0||e.model===void 0)throw new Error(pe("Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model.",me.config));return{model:DH(e.provider,e.model,{apiKey:e.apiKey,baseURL:e.baseURL,name:e.name}),...t.concurrent?.request===void 0?{}:{concurrent:t.concurrent.request}}}function DH(t,e,r){switch(t){case"anthropic":return LH({...r.apiKey===void 0?{}:{apiKey:r.apiKey},...r.name===void 0?{}:{name:r.name}})(e);case"google":return AH({...r.apiKey===void 0?{}:{apiKey:r.apiKey},...r.name===void 0?{}:{name:r.name}})(e);case"openai":{if(r.baseURL!==void 0)throw new Error(pe("openai does not accept llm.baseURL or baseURL in --llm JSON. Use openai-compatible for third-party OpenAI-style APIs.",me.config));return OH({...r.apiKey===void 0?{}:{apiKey:r.apiKey},...r.name===void 0?{}:{name:r.name}})(e)}case"openai-compatible":{if(r.baseURL===void 0)throw new Error(pe("openai-compatible requires llm.baseURL or baseURL in --llm JSON.",me.config));return NH({baseURL:r.baseURL,name:r.name??MH(r.baseURL),...r.apiKey===void 0?{}:{apiKey:r.apiKey}})(e)}}}function MH(t){try{return new URL(t).hostname}catch{return"openai-compatible"}}var Fh=d(()=>{"use strict";gt()});function MT(t,e,r,n,i){let a=WH(t),o=Math.max(r,Math.ceil(e/a.wordsPerCall)),s=Math.max(1,t==="reading-graph"?1:n.request),c=Math.ceil(o/s),u=e*a.secondsPerWord;return{model:i,timeSeconds:{max:Math.ceil(c*a.maxSecondsPerCall+u),min:Math.ceil(c*a.minSecondsPerCall+u)},tokens:{cacheableInput:Math.ceil(e*a.cacheableInputTokenPerWord),input:Math.ceil(e*a.inputTokenPerWord),output:Math.ceil(e*a.outputTokenPerWord)}}}function WT(t){if(!t.hasGenerationWork)return[];let e=[],r=t.concurrent.request<4?6:t.concurrent.request<8?8:void 0;return r!==void 0&&e.push({command:`wg wikg://local/config/concurrent put request ${r}`,current:t.concurrent.request,kind:"request",message:"LLM request concurrency can often be higher. Use at least 4; 6-8 is usually faster when the provider allows it.",recommended:r}),t.concurrent.job<4&&t.chapters>1&&e.push({command:"wg wikg://local/config/concurrent put job 4",current:t.concurrent.job,kind:"job",message:"Multiple chapters need generation and job concurrency is below 4. Raising it lets chapter jobs run in parallel.",recommended:4}),e}function FT(t){return t?.model===void 0?"not configured":t.provider===void 0?t.model:`${t.provider}/${t.model}`}function jh(t){if(t<60)return`${t}s`;let e=Math.round(t/60);return e<60?`${e}m`:`${Math.round(e/60)}h`}function WH(t){switch(t){case"knowledge-graph":return{cacheableInputTokenPerWord:60,inputTokenPerWord:80,maxSecondsPerCall:35,minSecondsPerCall:15,outputTokenPerWord:25,secondsPerWord:.02,wordsPerCall:35};case"reading-graph":return{cacheableInputTokenPerWord:20,inputTokenPerWord:25,maxSecondsPerCall:45,minSecondsPerCall:15,outputTokenPerWord:4,secondsPerWord:.01,wordsPerCall:160};case"reading-summary":return{cacheableInputTokenPerWord:45,inputTokenPerWord:55,maxSecondsPerCall:25,minSecondsPerCall:10,outputTokenPerWord:4,secondsPerWord:.01,wordsPerCall:110}}}var jT=d(()=>{"use strict"});import{clearLine as $Se,cursorTo as KSe,moveCursor as JSe}from"readline";var GT=d(()=>{"use strict"});function FH(t){let e=t.counters??[],r=e.length===0?"":` ${e.map(jH).join(" | ")}`,n=GH(t.metricGroups);return`${t.phase}${r}${n===""?"":` ${n}`}`}function jH(t){return t.name===t.unit?`${t.name} ${t.done}/${t.total}`:`${t.name} ${t.done}/${t.total} ${t.unit}`}function GH(t){return t===void 0?"":t.flatMap(r=>{let n=r.metrics.map(i=>`${i.name}: ${i.value}`);return n.length===0?[]:[`[${r.name} ${n.join(" / ")}]`]}).join(" ")}function BH(t){let e=t.counters??[];return e.length>0&&e.every(r=>r.total>0&&r.done>=r.total)}var Rd,BT=d(()=>{"use strict";gt();gt();Xn();Rd=class{#e;#t;#r;#n;#i;#a=!1;constructor(e){this.#e=e.jsonl,this.#t=e.throttleMs,this.#r=e.tty??RT()===!0}async write(e){if(!(e.kind==="status"&&!this.#l(e))){if(this.#e){await this.#s(_T(e.json));return}if(e.kind==="status"){await this.#c(FH(e));return}await this.#o(e.text)}}async#o(e){this.#r&&this.#a&&(await ie(`
2095
2095
  `),this.#a=!1),await this.#s(`${e}
2096
2096
  `)}async#s(e){await ie(e)}async#c(e){if(this.#r){await ie(`\r\x1B[2K${e}`),this.#a=!0;return}await this.#s(`${e}
2097
2097
  `)}#l(e){let r=e.phase,n=BH(e),i=Date.now(),a=this.#n===void 0?Number.POSITIVE_INFINITY:i-this.#n;return r!==this.#i||n||this.#n===void 0||a>=this.#t?(this.#n=i,this.#i=r,!0):!1}}});function UT(t,e){let r=DT(t);return new St({dataDirPath:Kt(),sampling:kc({...r.temperature===void 0?{}:{temperature:r.temperature},...r.topP===void 0?{}:{topP:r.topP}}),...r,...e?.cacheDirPath===void 0?{}:{cacheDirPath:e.cacheDirPath},...e?.logDirPath===void 0?{}:{logDirPath:e.logDirPath},...e?.onStreamProgress===void 0?{}:{onStreamProgress:e.onStreamProgress},...e?.onTokenUsage===void 0?{}:{onTokenUsage:e.onTokenUsage}})}async function vd(t){let e=await Id({...t.llmJSON===void 0?{}:{llmJSON:t.llmJSON}});if(e.llm?.provider===void 0||e.llm.model===void 0)throw new Error(pe("Missing LLM configuration. Set --llm for one run, or configure `wikg://local/config/llm` with provider and model.",me.config));return e}var HT=d(()=>{"use strict";H();H();H();H();xd();gt();Fh()});var yo=d(()=>{"use strict";xd();Fh();Mh();jT();GT();BT();HT()});import{spawn as UH}from"child_process";import{existsSync as HH}from"fs";import{join as Gh,resolve as qH}from"path";function qT(t,e={}){let r=$H(t,e.args??[]);return UH(r.command,r.args,{cwd:Sd(),detached:e.detached===!0,env:ET(),stdio:e.detached===!0?"ignore":["ignore","pipe","pipe"]})}function $H(t,e){let r=kT(),n=IT();return r!==void 0&&n!==void 0?{args:[Gh(r,"node_modules","tsx","dist","cli.mjs"),Gh(r,"packages","cli","src","bin",`${t}.ts`),"--wikigraph-internal-child",t,"--wikigraph-state-dir",n,...e],command:process.execPath}:{args:[KH(t),"--wikigraph-internal-child",t,...n===void 0?[]:["--wikigraph-state-dir",n],...e],command:process.execPath}}function KH(t){let e=`${t}.js`,r=globalThis.__WIKIGRAPH_CLI_DIST_DIR__??qH(Sd(),"packages","cli","dist"),n=Gh(r,e);return HH(n),n}var $T=d(()=>{"use strict";Xn()});function _d(t){let e={job:t.config.concurrent?.job??3,request:t.config.concurrent?.request??6},r=t.chapters.reduce((o,s)=>o+s.words,0),n=FT(t.config.llm),i=zH({chapters:t.chapters,concurrent:e,model:n,target:t.target}),a=Math.max(0,...i.map(o=>o.chapters));return{chapters:t.chapters.length,concurrent:e,includesPrerequisites:i.some(o=>o.prerequisite),performanceHints:WT({chapters:a,concurrent:e,hasGenerationWork:i.length>0}),planning:QH(n,i),steps:i,target:t.target,words:r}}function zH(t){switch(t.target){case"knowledge-graph":return[Td({chapters:t.chapters,concurrent:t.concurrent,model:t.model,prerequisite:!1,task:"knowledge-graph"})].filter(e=>e.chapters>0);case"reading-graph":return[Td({chapters:t.chapters.filter(e=>e.stage==="sourced"),concurrent:t.concurrent,model:t.model,prerequisite:!1,task:"reading-graph"})].filter(e=>e.chapters>0);case"reading-summary":{let e=t.chapters.filter(n=>n.stage==="sourced"),r=t.chapters.filter(n=>n.stage==="sourced"||n.stage==="graphed");return[Td({chapters:e,concurrent:t.concurrent,model:t.model,prerequisite:!0,task:"reading-graph"}),Td({chapters:r,concurrent:t.concurrent,model:t.model,prerequisite:!1,task:"reading-summary"})].filter(n=>n.chapters>0)}}}function Td(t){let e=t.chapters.reduce((r,n)=>r+n.words,0);return{chapters:t.chapters.length,planning:MT(t.task,e,t.chapters.length,t.concurrent,t.model),prerequisite:t.prerequisite,task:t.task,words:e}}function QH(t,e){return{model:t,timeSeconds:{max:e.reduce((r,n)=>r+n.planning.timeSeconds.max,0),min:e.reduce((r,n)=>r+n.planning.timeSeconds.min,0)},tokens:{cacheableInput:e.reduce((r,n)=>r+n.planning.tokens.cacheableInput,0),input:e.reduce((r,n)=>r+n.planning.tokens.input,0),output:e.reduce((r,n)=>r+n.planning.tokens.output,0)}}}function Uh(t){return{chapters:t.chapters,concurrent:t.concurrent,includesPrerequisites:t.includesPrerequisites,performanceHints:t.performanceHints,steps:t.steps.map(e=>({chapters:e.chapters,prerequisite:e.prerequisite,task:e.task,tokens:e.planning.tokens,waitSeconds:e.planning.timeSeconds,words:e.words})),target:t.target,tokens:t.planning.tokens,waitSeconds:t.planning.timeSeconds,words:t.words,model:t.planning.model}}function Hh(t){return["Estimate:",` Work: ${t.target} over ${t.chapters} chapter${t.chapters===1?"":"s"} / ${t.words} words`,...t.includesPrerequisites?[" Includes prerequisite Reading Graph work where missing."]:[],` Model: ${t.planning.model}`,` Tokens: ${t.planning.tokens.input} input / ${t.planning.tokens.cacheableInput} cacheable input / ${t.planning.tokens.output} output`,` Wait: ${jh(t.planning.timeSeconds.min)}-${jh(t.planning.timeSeconds.max)}`,` Current concurrency: job=${t.concurrent.job} request=${t.concurrent.request}`,...XH(t.performanceHints)]}function XH(t){return t.length===0?[]:["Performance hints:",...t.flatMap(e=>[` ${e.message}`,` Command: ${e.command}`])]}var Cd=d(()=>{"use strict";yo()});async function JT(t,e){if(e.json){await ie(ho({items:t.map(Pd)}));return}if(t.length===0){await ie(`No jobs.