@automagik/genie 4.260501.2 → 4.260501.3
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/genie.js
CHANGED
|
@@ -931,7 +931,7 @@ ${errCtx.stack}`;d.reject(err)}else d.resolve(msg)}});return sub.requestSubject=
|
|
|
931
931
|
FROM session_sync
|
|
932
932
|
WHERE id = 'backfill'
|
|
933
933
|
LIMIT 1
|
|
934
|
-
`;if(rows.length===0)return{driftPct:null,detail:"no prior backfill row \u2014 first run will seed"};let row=rows[0];if(row.total_bytes<=0)return{driftPct:0,detail:"no JSONL bytes discovered yet"};let pct=Math.max(0,row.total_bytes-row.processed_bytes)/row.total_bytes*100,display=pct.toFixed(1);return{driftPct:pct,detail:`processed ${row.processed_bytes}/${row.total_bytes} bytes (drift ${display}%)`}}catch(err){return{driftPct:null,detail:`drift probe failed: ${err.message}`}}}async function defaultRunBackfillSync(){if(!await isAvailable())return{ranSync:!1,driftPct:null,detail:"pg unavailable \u2014 backfill skipped"};return(async()=>{try{let sql=await getConnection(),{startBackfill:startBackfill2}=await Promise.resolve().then(() => (init_session_backfill(),exports_session_backfill));await startBackfill2(sql)}catch{}})(),{ranSync:!0,driftPct:null,detail:"background convergence kicked \u2014 `genie doctor --fix` to wait"}}async function defaultRunBackfillBlocking(){if(!await isAvailable())return{ranSync:!1,driftPct:null,detail:"pg unavailable \u2014 backfill skipped"};let sql=await getConnection(),{startBackfill:startBackfill2}=await Promise.resolve().then(() => (init_session_backfill(),exports_session_backfill));await startBackfill2(sql);let after=await defaultMeasureBackfillDrift();return{ranSync:!0,driftPct:after.driftPct,detail:after.detail}}async function defaultListOrphanedZombies(){try{let{listExhaustedZombies:listExhaustedZombies2}=await Promise.resolve().then(() => (init_agent_registry(),exports_agent_registry));return await listExhaustedZombies2()}catch{return[]}}function safeIsDirectory(path2){try{return statSync5(path2).isDirectory()}catch{return!1}}function summarizeInboxes(inboxesDir2){let inboxFiles=[];try{inboxFiles=readdirSync6(inboxesDir2).filter((f)=>f.endsWith(".json"))}catch{return{newestMs:null,hasContent:!1}}let newestMs=null,hasContent=!1;for(let f of inboxFiles)try{let st=statSync5(join24(inboxesDir2,f));if(newestMs===null||st.mtimeMs>newestMs)newestMs=st.mtimeMs;if(st.size>2)hasContent=!0}catch{}return{newestMs,hasContent}}function classifyTeamDir2(name,base,now){let dir=join24(base,name);if(!safeIsDirectory(dir))return null;if(existsSync19(join24(dir,"config.json")))return null;let inboxesDir2=join24(dir,"inboxes");if(!safeIsDirectory(inboxesDir2))return null;let{newestMs,hasContent}=summarizeInboxes(inboxesDir2),orphan={teamName:name,path:dir,newestInboxMs:newestMs,hasContent},active=hasContent&&newestMs!==null&&now-newestMs<ORPHAN_FRESH_WINDOW_MS;return{orphan,active}}function defaultScanTeamConfigOrphans(){let base=teamsBaseDir3(),result2={active:[],stale:[]};if(!existsSync19(base))return result2;let now=Date.now();for(let name of readdirSync6(base)){if(name.startsWith(".")||name==="_archive")continue;let classified=classifyTeamDir2(name,base,now);if(!classified)continue;(classified.active?result2.active:result2.stale).push(classified.orphan)}return result2}function defaultArchiveStaleTeamConfigs(orphans){if(orphans.length===0)return[];let archiveRoot=join24(teamsBaseDir3(),"_archive");mkdirSync9(archiveRoot,{recursive:!0});let ts3=new Date().toISOString().replace(/[:.]/g,"-"),archived=[];for(let o of orphans){let dest=join24(archiveRoot,`${o.teamName}-${ts3}`);try{renameSync4(o.path,dest),archived.push(dest)}catch{}}return archived}async function defaultRecordAudit(eventType,name,details){await recordAuditEvent("command","serve_start",eventType,"serve",{precondition:name,...details})}async function checkPartition(health,autoFix,deps){if(health.partition_health==="ok"||health.partition_health==="warn")return{name:"partition",status:"ok",detail:health.next_rotation_at?`next rotation: ${health.next_rotation_at}`:void 0};if(health.partition_health==="unknown")return{name:"partition",status:"skipped",detail:"pg unavailable \u2014 skipping partition probe"};if(!autoFix)return{name:"partition",status:"refused",detail:"today's partition is missing or rotation is overdue",fixCommand:"genie doctor --observability # then re-run; or `genie serve start` (without --no-fix)"};let result2=await deps.runPartitionMaintenance();return{name:"partition",status:"fixed",detail:`created/present ${result2.createdOrPresent}, dropped ${result2.dropped}; next rotation ${result2.nextRotationAt??"unknown"}`}}async function checkWatchdog(health,autoFix,deps){if(deps.platform!=="linux")return{name:"watchdog",status:"skipped",detail:"watchdog install is Linux/systemd only"};if(health.watchdog==="ok")return{name:"watchdog",status:"ok"};if(!autoFix)return{name:"watchdog",status:"refused",detail:health.watchdog_detail??"watchdog units missing",fixCommand:"sudo bun run packages/watchdog/src/cli.ts install"};try{let result2=await deps.installWatchdog();return{name:"watchdog",status:"fixed",detail:`wrote ${result2.filesWritten.length}, skipped ${result2.filesSkipped.length}`}}catch(err){return{name:"watchdog",status:"refused",detail:`auto-install failed: ${err.message}`,fixCommand:"sudo bun run packages/watchdog/src/cli.ts install"}}}async function checkBackfill(autoFix,deps){let drift=await deps.measureBackfillDrift();if(drift.driftPct===null)return{name:"backfill",status:"skipped",detail:drift.detail};if(drift.driftPct<BACKFILL_DRIFT_THRESHOLD_PCT)return{name:"backfill",status:"ok",detail:drift.detail};if(!autoFix)return{name:"backfill",status:"refused",detail:drift.detail,fixCommand:`genie sessions sync # drift ${drift.driftPct.toFixed(1)}% > ${BACKFILL_DRIFT_THRESHOLD_PCT}%`};return{name:"backfill",status:"fixed",detail:(await deps.runBackfillSync()).detail}}async function checkDeadPaneZombies(deps){let orphans=await deps.listOrphanedZombies();if(orphans.length===0)return{name:"dead_pane_zombies",status:"ok"};return{name:"dead_pane_zombies",status:"refused",detail:`${orphans.length} exhausted zombie(s) past TTL; visible in \`genie status\``,fixCommand:"genie prune --zombies # archive eligible rows"}}function checkTeamConfigOrphans(autoFix,deps){let scan=deps.scanTeamConfigOrphans();if(scan.active.length===0&&scan.stale.length===0)return{name:"team_config_orphans",status:"ok"};if(!autoFix){let summary=`active=${scan.active.length} stale=${scan.stale.length}`,firstActive=scan.active[0]?.teamName;return{name:"team_config_orphans",status:"refused",detail:summary,fixCommand:firstActive?`genie team repair ${firstActive} # active orphan; stale dirs archive on auto-fix`:"genie serve start # auto-fix archives stale orphans"}}let archivedPaths=deps.archiveStaleTeamConfigs(scan.stale);if(scan.active.length>0)return{name:"team_config_orphans",status:"refused",detail:`archived ${archivedPaths.length} stale; ${scan.active.length} active orphan(s) need repair`,fixCommand:`genie team repair ${scan.active[0].teamName}`};return{name:"team_config_orphans",status:"fixed",detail:`archived ${archivedPaths.length} stale orphan(s)`}}function bindDefaults(deps){return{collectHealth:deps?.collectHealth??collectObservabilityHealth,runPartitionMaintenance:deps?.runPartitionMaintenance??defaultRunPartitionMaintenance,installWatchdog:deps?.installWatchdog??defaultInstallWatchdog,runBackfillSync:deps?.runBackfillSync??defaultRunBackfillSync,measureBackfillDrift:deps?.measureBackfillDrift??defaultMeasureBackfillDrift,listOrphanedZombies:deps?.listOrphanedZombies??defaultListOrphanedZombies,scanTeamConfigOrphans:deps?.scanTeamConfigOrphans??defaultScanTeamConfigOrphans,archiveStaleTeamConfigs:deps?.archiveStaleTeamConfigs??defaultArchiveStaleTeamConfigs,platform:deps?.platform??process.platform,recordAudit:deps?.recordAudit??defaultRecordAudit,log:deps?.log??((line)=>console.log(line))}}async function ensureServeReady(opts){let deps=bindDefaults(opts.deps),health=await deps.collectHealth(),results=[];results.push(await checkPartition(health,opts.autoFix,deps)),results.push(await checkBackfill(opts.autoFix,deps)),results.push(await checkDeadPaneZombies(deps)),await emitAuditEvents(results,deps);let ok=results.every((r)=>r.status==="ok"||r.status==="fixed"||r.status==="skipped");return printReport(results,deps.log),{ok,results}}function formatDuration(ms){if(ms<1000)return`${ms}ms`;return`${(ms/1000).toFixed(1)}s`}function logMaintenanceStepStart(log,silent,label){if(!silent)log(` ${label}...`);return Date.now()}function logMaintenanceStepDone(log,silent,label,startedAt){if(!silent)log(` done ${label} (${formatDuration(Date.now()-startedAt)})`)}async function runDoctorMaintenance(opts={}){let rawRunBackfillSync=opts.deps?.runBackfillSync??defaultRunBackfillBlocking,deps=bindDefaults({...opts.deps,runBackfillSync:defaultRunBackfillBlocking,log:opts.silent?()=>{}:opts.deps?.log});deps.runBackfillSync=async()=>{let startedAt2=logMaintenanceStepStart(deps.log,opts.silent,"Running session backfill convergence (can take minutes on large transcript history)");try{return await rawRunBackfillSync()}finally{logMaintenanceStepDone(deps.log,opts.silent,"session backfill convergence",startedAt2)}};let startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Collecting observability health"),health=await deps.collectHealth();logMaintenanceStepDone(deps.log,opts.silent,"observability health",startedAt);let results=[];startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Checking runtime event partitions"),results.push(await checkPartition(health,!0,deps)),logMaintenanceStepDone(deps.log,opts.silent,"runtime event partitions",startedAt),startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Checking watchdog install"),results.push(await checkWatchdog(health,!0,deps)),logMaintenanceStepDone(deps.log,opts.silent,"watchdog install",startedAt),startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Checking session backfill drift"),results.push(await checkBackfill(!0,deps)),logMaintenanceStepDone(deps.log,opts.silent,"session backfill drift",startedAt),startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Checking exhausted zombie rows"),results.push(await checkDeadPaneZombies(deps)),logMaintenanceStepDone(deps.log,opts.silent,"exhausted zombie rows",startedAt),startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Checking Claude team config orphans"),results.push(checkTeamConfigOrphans(!0,deps)),logMaintenanceStepDone(deps.log,opts.silent,"Claude team config orphans",startedAt),await emitAuditEvents(results,deps);let ok=results.every((r)=>r.status==="ok"||r.status==="fixed"||r.status==="skipped");return printReport(results,deps.log),{ok,results}}async function emitAuditEvents(results,deps){for(let result2 of results)if(result2.status==="fixed")await deps.recordAudit("serve.precondition.fixed",result2.name,{detail:result2.detail??null}).catch(()=>{});else if(result2.status==="refused")await deps.recordAudit("serve.precondition.refused",result2.name,{detail:result2.detail??null,fix_command:result2.fixCommand??null}).catch(()=>{})}function printReport(results,log){log(" Preconditions:");for(let r of results){let tag=statusTag(r.status),suffix=r.detail?` \u2014 ${r.detail}`:"";if(log(` ${tag} ${r.name}${suffix}`),r.status==="refused"&&r.fixCommand)log(` \u2192 ${r.fixCommand}`)}}function statusTag(status){switch(status){case"ok":return"[ok]";case"fixed":return"[fix]";case"refused":return"[!!]";case"skipped":return"[--]"}}var BACKFILL_DRIFT_THRESHOLD_PCT=5,ORPHAN_FRESH_WINDOW_MS=86400000;var init_ensure_ready=__esm(()=>{init_observability_health();init_audit();init_db()});var exports_doctor={};__export(exports_doctor,{runPostUpdateMaintenance:()=>runPostUpdateMaintenance,findStaleGenieCandidates:()=>findStaleGenieCandidates,findBundledTmuxConfigDir:()=>findBundledTmuxConfigDir,doctorCommand:()=>doctorCommand,checkTmuxConfigs:()=>checkTmuxConfigs,checkLegacyAgentFrontmatter:()=>checkLegacyAgentFrontmatter,checkGenieAgentTemplate:()=>checkGenieAgentTemplate});import{execFileSync as execFileSync2}from"child_process";import{copyFileSync as copyFileSync2,existsSync as existsSync20,mkdirSync as mkdirSync10,readFileSync as readFileSync13,readdirSync as readdirSync7,statSync as statSync6,unlinkSync as unlinkSync6,writeFileSync as writeFileSync7}from"fs";import{homedir as homedir20}from"os";import{dirname as dirname8,join as join25,resolve as resolve3}from"path";import{fileURLToPath as fileURLToPath3}from"url";var{$:$3}=globalThis.Bun;function printSectionHeader(title){console.log(),console.log(`\x1B[1m${title}:\x1B[0m`)}function printCheckResult(result2){let icon={pass:"\x1B[32m\u2713\x1B[0m",fail:"\x1B[31m\u2717\x1B[0m",warn:"\x1B[33m!\x1B[0m"}[result2.status],message=result2.message?` ${result2.message}`:"";if(console.log(` ${icon} ${result2.name}${message}`),result2.suggestion)console.log(` \x1B[2m${result2.suggestion}\x1B[0m`)}async function checkPrerequisites(){let results=[],tmuxCheck=await checkCommand("tmux");if(tmuxCheck.exists)results.push({name:"tmux",status:"pass",message:tmuxCheck.version||""});else results.push({name:"tmux",status:"fail",suggestion:"Install with: brew install tmux (or apt install tmux)"});let jqCheck=await checkCommand("jq");if(jqCheck.exists)results.push({name:"jq",status:"pass",message:jqCheck.version||""});else results.push({name:"jq",status:"fail",suggestion:"Install with: brew install jq (or apt install jq)"});let bunCheck=await checkCommand("bun");if(bunCheck.exists)results.push({name:"bun",status:"pass",message:bunCheck.version||""});else results.push({name:"bun",status:"fail",suggestion:"Install with: curl -fsSL https://bun.sh/install | bash"});let claudeCheck=await checkCommand("claude");if(claudeCheck.exists)results.push({name:"Claude Code",status:"pass",message:claudeCheck.version||""});else results.push({name:"Claude Code",status:"warn",suggestion:"Install with: npm install -g @anthropic-ai/claude-code"});let codexCheck=await checkCommand("codex");if(codexCheck.exists)results.push({name:"Codex CLI",status:"pass",message:codexCheck.version||""});else results.push({name:"Codex CLI",status:"warn",suggestion:"Install via OpenAI account; codex is optional unless using --provider codex"});let requiredForSpawn=["genie","bun","node","npm","git","claude","codex"];for(let bin of requiredForSpawn){let interactivePath=await resolveBinaryInteractive(bin),nonInteractivePath=await resolveBinaryNonInteractive(bin);if(interactivePath&&nonInteractivePath)results.push({name:`Non-interactive PATH: ${bin}`,status:"pass",message:nonInteractivePath});else if(interactivePath&&!nonInteractivePath)results.push({name:`Non-interactive PATH: ${bin}`,status:"warn",message:"interactive-only",suggestion:`Move PATH export from ~/.bashrc to ~/.profile so spawn-scripts can resolve ${bin}. (Or use a stable symlink in ~/.local/bin.)`});else if(!interactivePath&&bin!=="codex"){if(bin==="genie"||bin==="node"||bin==="npm"||bin==="git")results.push({name:`Non-interactive PATH: ${bin}`,status:"warn",message:"not in non-interactive PATH",suggestion:`Add ${bin} to ~/.profile (not just ~/.bashrc). Some flows (e.g. genie update) shell out to bare '${bin}' from non-interactive subprocesses.`})}}return results}async function resolveBinaryInteractive(bin){try{return(await $3`command -v ${bin}`.quiet().text()).trim()||null}catch{return null}}async function resolveBinaryNonInteractive(bin){try{return(await $3`sh -c "command -v ${bin}"`.quiet().text()).trim()||null}catch{return null}}async function checkConfiguration(){let results=[];if(genieConfigExists())results.push({name:"Genie config exists",status:"pass",message:contractClaudePath(getGenieConfigPath())});else results.push({name:"Genie config exists",status:"warn",message:"not found",suggestion:"Run: genie setup"});if(isSetupComplete())results.push({name:"Setup complete",status:"pass"});else results.push({name:"Setup complete",status:"warn",message:"not completed",suggestion:"Run: genie setup"});let claudeSettingsPath=getClaudeSettingsPath();if(existsSync20(claudeSettingsPath))results.push({name:"Claude settings exists",status:"pass",message:contractClaudePath(claudeSettingsPath)});else results.push({name:"Claude settings exists",status:"warn",message:"not found",suggestion:"Claude Code creates this on first run"});return results}async function checkTmux(){let results=[];try{if((await $3`${tmuxBin()} -L genie list-sessions 2>/dev/null`.quiet()).exitCode===0)results.push({name:"Server running",status:"pass"});else return results.push({name:"Server running",status:"warn",message:"no sessions",suggestion:"Start with: tmux new-session -d -s genie"}),results}catch{return results.push({name:"Server running",status:"warn",message:"could not check"}),results}let sessionName=(await loadGenieConfig()).session.name;try{if((await $3`${tmuxBin()} -L genie has-session -t ${`=${sessionName}`} 2>/dev/null`.quiet()).exitCode===0)results.push({name:`Session '${sessionName}' exists`,status:"pass"});else results.push({name:`Session '${sessionName}' exists`,status:"warn",suggestion:`Start with: tmux new-session -d -s ${sessionName}`})}catch{results.push({name:`Session '${sessionName}' exists`,status:"warn",message:"could not check"})}return results}async function checkWorkerProfiles(){let results=[];if(!genieConfigExists())return results.push({name:"Worker profiles",status:"warn",message:"no genie config",suggestion:"Run: genie setup"}),results;let config=await loadGenieConfig(),profiles=config.workerProfiles;if(!profiles||Object.keys(profiles).length===0)return results.push({name:"Worker profiles",status:"pass",message:"none configured (using defaults)"}),results;let totalProfiles=Object.keys(profiles).length;results.push({name:"Profiles configured",status:"pass",message:`${totalProfiles} profile${totalProfiles===1?"":"s"}`});for(let name of Object.keys(profiles))results.push({name:`Profile '${name}'`,status:"pass",message:"claude (direct)"});if(config.defaultWorkerProfile)if(profiles[config.defaultWorkerProfile])results.push({name:"Default profile",status:"pass",message:config.defaultWorkerProfile});else results.push({name:"Default profile",status:"warn",message:`'${config.defaultWorkerProfile}' not found`,suggestion:"Run: genie profiles default <profile>"});return results}async function checkBridge(){let results=[];try{let{getBridgeStatus:getBridgeStatus2,removeBridgePidfile:removeBridgePidfile2}=await Promise.resolve().then(() => (init_bridge_status(),exports_bridge_status)),res=await getBridgeStatus2(void 0,{});if(res.state==="stopped")return results.push({name:"Bridge",status:"warn",message:"stopped (no pidfile)",suggestion:"Start the bridge with: genie serve"}),results;if(res.state==="stale"){if(res.pidfile)removeBridgePidfile2();return results.push({name:"Bridge",status:"fail",message:`stale: ${res.detail}`,suggestion:"Restart the bridge with: genie serve restart"}),results}let{pong,pidfile}=res;if(!pong||!pidfile)return results.push({name:"Bridge",status:"warn",message:"running state missing pong/pidfile metadata"}),results;let uptimeSec=Math.round(pong.uptimeMs/1000);results.push({name:"Bridge running",status:"pass",message:`running (pid ${pong.pid}, uptime ${uptimeSec}s)`}),results.push({name:"NATS ping",status:"pass",message:`pong in ${res.latencyMs??0}ms (${pidfile.natsUrl})`}),results.push({name:"Subjects",status:"pass",message:pong.subjects.join(", ")})}catch(err){let detail=err instanceof Error?err.message:String(err);results.push({name:"Bridge module",status:"warn",message:`could not probe bridge: ${detail}`})}return results}function checkGenieAgentTemplate(workspaceRoot){let root=workspaceRoot??findWorkspace()?.root;if(!root)return[];let genieDir=join25(root,"agents","genie");if(!existsSync20(genieDir))return[];let agentsMd=join25(genieDir,"AGENTS.md"),agentYaml=join25(genieDir,"agent.yaml"),issues=[];if(existsSync20(agentsMd))try{if(readFileSync13(agentsMd,"utf-8").includes(STALE_GENIE_AGENTS_MD_MARKER))issues.push("AGENTS.md uses generic placeholder template")}catch{}if(existsSync20(agentYaml))try{let text=readFileSync13(agentYaml,"utf-8");if(!STALE_GENIE_AGENT_YAML_MISSING_MODEL_REGEX.test(text))issues.push("agent.yaml missing model field (TUI falls back to gray)")}catch{}if(issues.length===0)return[{name:"agents/genie scaffold up to date",status:"pass"}];return[{name:"agents/genie stale scaffold",status:"warn",message:issues.join("; "),suggestion:"Run: genie doctor --fix (re-emits genie specialist templates, preserves user edits)"}]}function findBundledTmuxConfigDir(){try{let moduleDir=dirname8(fileURLToPath3(import.meta.url));for(let i2=0;i2<6;i2+=1){let candidate=resolve3(moduleDir,"../".repeat(i2+1),"scripts","tmux");if(existsSync20(join25(candidate,"tui-tmux.conf"))&&existsSync20(join25(candidate,"genie.tmux.conf")))return candidate}}catch{}return null}function checkTmuxConfigs(){if(!findBundledTmuxConfigDir())return[{name:"tmux configs",status:"pass",message:"bundled configs unavailable (skipped)"}];let home=join25(homedir20(),".genie"),stale=[],expectedSnippet="unbind -n MouseDown3Pane";for(let file of["tui-tmux.conf","tmux.conf"]){let installedPath=join25(home,file);if(!existsSync20(installedPath))continue;try{if(!readFileSync13(installedPath,"utf-8").includes(expectedSnippet))stale.push(file)}catch{stale.push(file)}}if(stale.length===0)return[{name:"~/.genie tmux configs up to date",status:"pass"}];return[{name:"~/.genie tmux configs stale",status:"warn",message:`missing right-click unbind in: ${stale.join(", ")}`,suggestion:"Run: genie doctor --fix (refreshes ~/.genie tmux configs from bundled scripts/tmux/)"}]}function isAgentDirectory(path2){try{return statSync6(path2).isDirectory()}catch{return!1}}function hasLegacyFrontmatter(agentDir){let yamlPath=join25(agentDir,"agent.yaml"),agentsMdPath=join25(agentDir,"AGENTS.md");if(!existsSync20(yamlPath)||!existsSync20(agentsMdPath))return!1;try{return readFileSync13(agentsMdPath,"utf-8").slice(0,4).startsWith("---")}catch{return!1}}function checkLegacyAgentFrontmatter(workspaceRoot){let results=[],root=workspaceRoot??findWorkspace()?.root;if(!root)return[];let agentsDir=join25(root,"agents");if(!existsSync20(agentsDir))return[];let entries;try{entries=readdirSync7(agentsDir)}catch{return[]}for(let name of entries){let agentDir=join25(agentsDir,name);if(!isAgentDirectory(agentDir))continue;if(!hasLegacyFrontmatter(agentDir))continue;results.push({name:`agents/${name}/AGENTS.md`,status:"warn",message:"legacy frontmatter detected (ignored by sync)",suggestion:`Move config into agents/${name}/agent.yaml \u2014 AGENTS.md is prompt-only post-migration.`})}if(results.length===0)results.push({name:"No legacy frontmatter in agents/*/AGENTS.md",status:"pass"});return results}function runCheckSection(label,results,counts){printSectionHeader(label);for(let result2 of results){if(printCheckResult(result2),result2.status==="fail")counts.errors=!0;if(result2.status==="warn")counts.warnings=!0}}async function doctorCommand(options){if(options?.fix){await doctorFix();return}if(options?.fixTeamOrphans){await runFixTeamOrphans({dryRun:Boolean(options.dryRun),json:Boolean(options.json)});return}if(options?.observability){await runObservabilityCheck(Boolean(options.json));return}if(options?.perf){let{runPerfCheck:runPerfCheck2}=await Promise.resolve().then(() => (init_perf_check(),exports_perf_check));await runPerfCheck2(Boolean(options.json));return}console.log(),console.log("\x1B[1mGenie Doctor\x1B[0m"),console.log(`\x1B[2m${"\u2500".repeat(40)}\x1B[0m`);let counts={errors:!1,warnings:!1};if(runCheckSection("Prerequisites",await checkPrerequisites(),counts),runCheckSection("Installer Resolution",await collectInstallerResolution(),counts),runCheckSection("Configuration",await checkConfiguration(),counts),runCheckSection("Tmux",await checkTmux(),counts),runCheckSection("Tmux Configs",checkTmuxConfigs(),counts),runCheckSection("Worker Profiles",await checkWorkerProfiles(),counts),runCheckSection("Omni Bridge",await checkBridge(),counts),runCheckSection("Agent Config",checkLegacyAgentFrontmatter(),counts),runCheckSection("Genie Specialist",checkGenieAgentTemplate(),counts),printDoctorSummary(counts),counts.errors)process.exit(1)}function printObservabilityReport(report){if(console.log(),console.log("\x1B[1mObservability Health\x1B[0m"),console.log(`\x1B[2m${"\u2500".repeat(40)}\x1B[0m`),console.log(` partition_health: ${report.partition_health}`),console.log(` partition_count: ${report.partition_count}`),console.log(` next_rotation_at: ${report.next_rotation_at??"n/a"}`),console.log(` oldest_partition: ${report.oldest_partition??"n/a"}`),console.log(` newest_partition: ${report.newest_partition??"n/a"}`),console.log(` GENIE_WIDE_EMIT: ${report.wide_emit_flag}`),report.message)console.log(` note: ${report.message}`);console.log()}async function runObservabilityCheck(json2){let report=await collectObservabilityHealth();if(json2)console.log(JSON.stringify(report,null,2));else printObservabilityReport(report);if(report.partition_health==="fail")process.exit(1)}async function runFixTeamOrphans(opts){let{archiveOrphanTeamConfigs:archiveOrphanTeamConfigs2}=await Promise.resolve().then(() => (init_archive_orphan_team_configs(),exports_archive_orphan_team_configs)),decisions=archiveOrphanTeamConfigs2({dryRun:opts.dryRun});if(opts.json){console.log(JSON.stringify({dryRun:opts.dryRun,decisions},null,2));return}if(decisions.length===0){console.log(" no team config dirs found \u2014 nothing to do");return}for(let d of decisions){let tag=d.classification==="stale"?opts.dryRun?"WOULD ARCHIVE":"ARCHIVED":d.classification.toUpperCase(),tail=d.archivedTo?` \u2192 ${d.archivedTo}`:"";console.log(` [${tag}] ${d.team} \u2014 ${d.reason}${tail}`)}let stale=decisions.filter((d)=>d.classification==="stale").length,active=decisions.filter((d)=>d.classification==="active").length;console.log(`
|
|
934
|
+
`;if(rows.length===0)return{driftPct:null,detail:"no prior backfill row \u2014 first run will seed"};let row=rows[0];if(row.total_bytes<=0)return{driftPct:0,detail:"no JSONL bytes discovered yet"};let pct=Math.max(0,row.total_bytes-row.processed_bytes)/row.total_bytes*100,display=pct.toFixed(1);return{driftPct:pct,detail:`processed ${row.processed_bytes}/${row.total_bytes} bytes (drift ${display}%)`}}catch(err){return{driftPct:null,detail:`drift probe failed: ${err.message}`}}}async function defaultRunBackfillSync(){if(!await isAvailable())return{ranSync:!1,driftPct:null,detail:"pg unavailable \u2014 backfill skipped"};return(async()=>{try{let sql=await getConnection(),{startBackfill:startBackfill2}=await Promise.resolve().then(() => (init_session_backfill(),exports_session_backfill));await startBackfill2(sql)}catch{}})(),{ranSync:!0,driftPct:null,detail:"background convergence kicked \u2014 `genie doctor --fix` to wait"}}async function defaultRunBackfillBlocking(){if(!await isAvailable())return{ranSync:!1,driftPct:null,detail:"pg unavailable \u2014 backfill skipped"};let sql=await getConnection(),{startBackfill:startBackfill2}=await Promise.resolve().then(() => (init_session_backfill(),exports_session_backfill));await startBackfill2(sql);let after=await defaultMeasureBackfillDrift();return{ranSync:!0,driftPct:after.driftPct,detail:after.detail}}async function defaultListOrphanedZombies(){try{let{listExhaustedZombies:listExhaustedZombies2}=await Promise.resolve().then(() => (init_agent_registry(),exports_agent_registry));return await listExhaustedZombies2()}catch{return[]}}function safeIsDirectory(path2){try{return statSync5(path2).isDirectory()}catch{return!1}}function summarizeInboxes(inboxesDir2){let inboxFiles=[];try{inboxFiles=readdirSync6(inboxesDir2).filter((f)=>f.endsWith(".json"))}catch{return{newestMs:null,hasContent:!1}}let newestMs=null,hasContent=!1;for(let f of inboxFiles)try{let st=statSync5(join24(inboxesDir2,f));if(newestMs===null||st.mtimeMs>newestMs)newestMs=st.mtimeMs;if(st.size>2)hasContent=!0}catch{}return{newestMs,hasContent}}function classifyTeamDir2(name,base,now){let dir=join24(base,name);if(!safeIsDirectory(dir))return null;if(existsSync19(join24(dir,"config.json")))return null;let inboxesDir2=join24(dir,"inboxes");if(!safeIsDirectory(inboxesDir2))return null;let{newestMs,hasContent}=summarizeInboxes(inboxesDir2),orphan={teamName:name,path:dir,newestInboxMs:newestMs,hasContent},active=hasContent&&newestMs!==null&&now-newestMs<ORPHAN_FRESH_WINDOW_MS;return{orphan,active}}function defaultScanTeamConfigOrphans(){let base=teamsBaseDir3(),result2={active:[],stale:[]};if(!existsSync19(base))return result2;let now=Date.now();for(let name of readdirSync6(base)){if(name.startsWith(".")||name==="_archive")continue;let classified=classifyTeamDir2(name,base,now);if(!classified)continue;(classified.active?result2.active:result2.stale).push(classified.orphan)}return result2}function defaultArchiveStaleTeamConfigs(orphans){if(orphans.length===0)return[];let archiveRoot=join24(teamsBaseDir3(),"_archive");mkdirSync9(archiveRoot,{recursive:!0});let ts3=new Date().toISOString().replace(/[:.]/g,"-"),archived=[];for(let o of orphans){let dest=join24(archiveRoot,`${o.teamName}-${ts3}`);try{renameSync4(o.path,dest),archived.push(dest)}catch{}}return archived}async function defaultRecordAudit(eventType,name,details){await recordAuditEvent("command","serve_start",eventType,"serve",{precondition:name,...details})}async function checkPartition(health,autoFix,deps){if(health.partition_health==="ok"||health.partition_health==="warn")return{name:"partition",status:"ok",detail:health.next_rotation_at?`next rotation: ${health.next_rotation_at}`:void 0};if(health.partition_health==="unknown")return{name:"partition",status:"skipped",detail:"pg unavailable \u2014 skipping partition probe"};if(!autoFix)return{name:"partition",status:"refused",detail:"today's partition is missing or rotation is overdue",fixCommand:"genie doctor --observability # then re-run; or `genie serve start` (without --no-fix)"};let result2=await deps.runPartitionMaintenance();return{name:"partition",status:"fixed",detail:`created/present ${result2.createdOrPresent}, dropped ${result2.dropped}; next rotation ${result2.nextRotationAt??"unknown"}`}}async function checkWatchdog(health,autoFix,deps){if(deps.platform!=="linux")return{name:"watchdog",status:"skipped",detail:"watchdog install is Linux/systemd only"};if(health.watchdog==="ok")return{name:"watchdog",status:"ok"};if(!autoFix)return{name:"watchdog",status:"refused",detail:health.watchdog_detail??"watchdog units missing",fixCommand:"sudo bun run packages/watchdog/src/cli.ts install"};try{let result2=await deps.installWatchdog();return{name:"watchdog",status:"fixed",detail:`wrote ${result2.filesWritten.length}, skipped ${result2.filesSkipped.length}`}}catch(err){return{name:"watchdog",status:"refused",detail:`auto-install failed: ${err.message}`,fixCommand:"sudo bun run packages/watchdog/src/cli.ts install"}}}async function checkBackfill(autoFix,deps){let drift=await deps.measureBackfillDrift();if(drift.driftPct===null)return{name:"backfill",status:"skipped",detail:drift.detail};if(drift.driftPct<BACKFILL_DRIFT_THRESHOLD_PCT)return{name:"backfill",status:"ok",detail:drift.detail};if(!autoFix)return{name:"backfill",status:"refused",detail:drift.detail,fixCommand:`genie sessions sync # drift ${drift.driftPct.toFixed(1)}% > ${BACKFILL_DRIFT_THRESHOLD_PCT}%`};return{name:"backfill",status:"fixed",detail:(await deps.runBackfillSync()).detail}}async function checkDeadPaneZombies(deps){let orphans=await deps.listOrphanedZombies();if(orphans.length===0)return{name:"dead_pane_zombies",status:"ok"};return{name:"dead_pane_zombies",status:"refused",detail:`${orphans.length} exhausted zombie(s) past TTL; visible in \`genie status\``,fixCommand:"genie prune --zombies # archive eligible rows"}}function checkTeamConfigOrphans(autoFix,deps){let scan=deps.scanTeamConfigOrphans();if(scan.active.length===0&&scan.stale.length===0)return{name:"team_config_orphans",status:"ok"};if(!autoFix){let summary=`active=${scan.active.length} stale=${scan.stale.length}`,firstActive=scan.active[0]?.teamName;return{name:"team_config_orphans",status:"refused",detail:summary,fixCommand:firstActive?`genie team repair ${firstActive} # active orphan; stale dirs archive on auto-fix`:"genie serve start # auto-fix archives stale orphans"}}let archivedPaths=deps.archiveStaleTeamConfigs(scan.stale);if(scan.active.length>0)return{name:"team_config_orphans",status:"refused",detail:`archived ${archivedPaths.length} stale; ${scan.active.length} active orphan(s) need repair`,fixCommand:`genie team repair ${scan.active[0].teamName}`};return{name:"team_config_orphans",status:"fixed",detail:`archived ${archivedPaths.length} stale orphan(s)`}}function bindDefaults(deps){return{collectHealth:deps?.collectHealth??collectObservabilityHealth,runPartitionMaintenance:deps?.runPartitionMaintenance??defaultRunPartitionMaintenance,installWatchdog:deps?.installWatchdog??defaultInstallWatchdog,runBackfillSync:deps?.runBackfillSync??defaultRunBackfillSync,measureBackfillDrift:deps?.measureBackfillDrift??defaultMeasureBackfillDrift,listOrphanedZombies:deps?.listOrphanedZombies??defaultListOrphanedZombies,scanTeamConfigOrphans:deps?.scanTeamConfigOrphans??defaultScanTeamConfigOrphans,archiveStaleTeamConfigs:deps?.archiveStaleTeamConfigs??defaultArchiveStaleTeamConfigs,platform:deps?.platform??process.platform,recordAudit:deps?.recordAudit??defaultRecordAudit,log:deps?.log??((line)=>console.log(line))}}async function ensureServeReady(opts){let deps=bindDefaults(opts.deps),health=await deps.collectHealth(),results=[];results.push(await checkPartition(health,opts.autoFix,deps)),results.push(await checkBackfill(opts.autoFix,deps)),results.push(await checkDeadPaneZombies(deps)),await emitAuditEvents(results,deps);let ok=results.every((r)=>r.status==="ok"||r.status==="fixed"||r.status==="skipped");return printReport(results,deps.log),{ok,results}}function formatDuration(ms){if(ms<1000)return`${ms}ms`;return`${(ms/1000).toFixed(1)}s`}function logMaintenanceStepStart(log,silent,label){if(!silent)log(` ${label}...`);return Date.now()}function logMaintenanceStepDone(log,silent,label,startedAt){if(!silent)log(` done ${label} (${formatDuration(Date.now()-startedAt)})`)}async function runDoctorMaintenance(opts={}){let rawRunBackfillSync=opts.deps?.runBackfillSync??defaultRunBackfillBlocking,deps=bindDefaults({...opts.deps,runBackfillSync:defaultRunBackfillBlocking,log:opts.silent?()=>{}:opts.deps?.log});deps.runBackfillSync=async()=>{let startedAt2=logMaintenanceStepStart(deps.log,opts.silent,"Running session backfill convergence (can take minutes on large transcript history)");try{return await rawRunBackfillSync()}finally{logMaintenanceStepDone(deps.log,opts.silent,"session backfill convergence",startedAt2)}};let startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Collecting observability health"),health=await deps.collectHealth();logMaintenanceStepDone(deps.log,opts.silent,"observability health",startedAt);let results=[];startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Checking runtime event partitions"),results.push(await checkPartition(health,!0,deps)),logMaintenanceStepDone(deps.log,opts.silent,"runtime event partitions",startedAt),startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Checking watchdog install"),results.push(await checkWatchdog(health,!0,deps)),logMaintenanceStepDone(deps.log,opts.silent,"watchdog install",startedAt),startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Checking session backfill drift"),results.push(await checkBackfill(!0,deps)),logMaintenanceStepDone(deps.log,opts.silent,"session backfill drift",startedAt),startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Checking exhausted zombie rows"),results.push(await checkDeadPaneZombies(deps)),logMaintenanceStepDone(deps.log,opts.silent,"exhausted zombie rows",startedAt),startedAt=logMaintenanceStepStart(deps.log,opts.silent,"Checking Claude team config orphans"),results.push(checkTeamConfigOrphans(!0,deps)),logMaintenanceStepDone(deps.log,opts.silent,"Claude team config orphans",startedAt),await emitAuditEvents(results,deps);let ok=results.every((r)=>r.status==="ok"||r.status==="fixed"||r.status==="skipped");return printReport(results,deps.log),{ok,results}}async function emitAuditEvents(results,deps){for(let result2 of results)if(result2.status==="fixed")await deps.recordAudit("serve.precondition.fixed",result2.name,{detail:result2.detail??null}).catch(()=>{});else if(result2.status==="refused")await deps.recordAudit("serve.precondition.refused",result2.name,{detail:result2.detail??null,fix_command:result2.fixCommand??null}).catch(()=>{})}function printReport(results,log){log(" Preconditions:");for(let r of results){let tag=statusTag(r.status),suffix=r.detail?` \u2014 ${r.detail}`:"";if(log(` ${tag} ${r.name}${suffix}`),r.status==="refused"&&r.fixCommand)log(` \u2192 ${r.fixCommand}`)}}function statusTag(status){switch(status){case"ok":return"[ok]";case"fixed":return"[fix]";case"refused":return"[!!]";case"skipped":return"[--]"}}var BACKFILL_DRIFT_THRESHOLD_PCT=5,ORPHAN_FRESH_WINDOW_MS=86400000;var init_ensure_ready=__esm(()=>{init_observability_health();init_audit();init_db()});var exports_doctor={};__export(exports_doctor,{runPostUpdateMaintenance:()=>runPostUpdateMaintenance,findStaleGenieCandidates:()=>findStaleGenieCandidates,findBundledTmuxConfigDir:()=>findBundledTmuxConfigDir,doctorCommand:()=>doctorCommand,checkTmuxConfigs:()=>checkTmuxConfigs,checkLegacyAgentFrontmatter:()=>checkLegacyAgentFrontmatter,checkGenieAgentTemplate:()=>checkGenieAgentTemplate});import{execFileSync as execFileSync2}from"child_process";import{copyFileSync as copyFileSync2,existsSync as existsSync20,mkdirSync as mkdirSync10,readFileSync as readFileSync13,readdirSync as readdirSync7,statSync as statSync6,unlinkSync as unlinkSync6,writeFileSync as writeFileSync7}from"fs";import{homedir as homedir20}from"os";import{dirname as dirname8,join as join25,resolve as resolve3}from"path";import{fileURLToPath as fileURLToPath3}from"url";var{$:$3}=globalThis.Bun;function printSectionHeader(title){console.log(),console.log(`\x1B[1m${title}:\x1B[0m`)}function printCheckResult(result2){let icon={pass:"\x1B[32m\u2713\x1B[0m",fail:"\x1B[31m\u2717\x1B[0m",warn:"\x1B[33m!\x1B[0m"}[result2.status],message=result2.message?` ${result2.message}`:"";if(console.log(` ${icon} ${result2.name}${message}`),result2.suggestion)console.log(` \x1B[2m${result2.suggestion}\x1B[0m`)}async function checkPrerequisites(){let results=[],tmuxCheck=await checkCommand("tmux");if(tmuxCheck.exists)results.push({name:"tmux",status:"pass",message:tmuxCheck.version||""});else results.push({name:"tmux",status:"fail",suggestion:"Install with: brew install tmux (or apt install tmux)"});let jqCheck=await checkCommand("jq");if(jqCheck.exists)results.push({name:"jq",status:"pass",message:jqCheck.version||""});else results.push({name:"jq",status:"fail",suggestion:"Install with: brew install jq (or apt install jq)"});let bunCheck=await checkCommand("bun");if(bunCheck.exists)results.push({name:"bun",status:"pass",message:bunCheck.version||""});else results.push({name:"bun",status:"fail",suggestion:"Install with: curl -fsSL https://bun.sh/install | bash"});let claudeCheck=await checkCommand("claude");if(claudeCheck.exists)results.push({name:"Claude Code",status:"pass",message:claudeCheck.version||""});else results.push({name:"Claude Code",status:"warn",suggestion:"Install with: npm install -g @anthropic-ai/claude-code"});let codexCheck=await checkCommand("codex");if(codexCheck.exists)results.push({name:"Codex CLI",status:"pass",message:codexCheck.version||""});else results.push({name:"Codex CLI",status:"warn",suggestion:"Install via OpenAI account; codex is optional unless using --provider codex"});let requiredForSpawn=["genie","bun","node","npm","git","claude","codex"];for(let bin of requiredForSpawn){let interactivePath=await resolveBinaryInteractive(bin),nonInteractivePath=await resolveBinaryNonInteractive(bin);if(interactivePath&&nonInteractivePath)results.push({name:`Non-interactive PATH: ${bin}`,status:"pass",message:nonInteractivePath});else if(interactivePath&&!nonInteractivePath)results.push({name:`Non-interactive PATH: ${bin}`,status:"warn",message:"interactive-only",suggestion:`Move PATH export from ~/.bashrc to ~/.profile so spawn-scripts can resolve ${bin}. (Or use a stable symlink in ~/.local/bin.)`});else if(!interactivePath&&bin!=="codex"){if(bin==="genie"||bin==="node"||bin==="npm"||bin==="git")results.push({name:`Non-interactive PATH: ${bin}`,status:"warn",message:"not in non-interactive PATH",suggestion:`Add ${bin} to ~/.profile (not just ~/.bashrc). Some flows (e.g. genie update) shell out to bare '${bin}' from non-interactive subprocesses.`})}}return results}async function resolveBinaryInteractive(bin){try{return(await $3`command -v ${bin}`.quiet().text()).trim()||null}catch{return null}}async function resolveBinaryNonInteractive(bin){try{return(await $3`sh -c "command -v ${bin}"`.quiet().text()).trim()||null}catch{return null}}async function checkConfiguration(){let results=[];if(genieConfigExists())results.push({name:"Genie config exists",status:"pass",message:contractClaudePath(getGenieConfigPath())});else results.push({name:"Genie config exists",status:"warn",message:"not found",suggestion:"Run: genie setup"});if(isSetupComplete())results.push({name:"Setup complete",status:"pass"});else results.push({name:"Setup complete",status:"warn",message:"not completed",suggestion:"Run: genie setup"});let claudeSettingsPath=getClaudeSettingsPath();if(existsSync20(claudeSettingsPath))results.push({name:"Claude settings exists",status:"pass",message:contractClaudePath(claudeSettingsPath)});else results.push({name:"Claude settings exists",status:"warn",message:"not found",suggestion:"Claude Code creates this on first run"});return results}async function checkTmux(){let results=[];try{if((await $3`${tmuxBin()} -L genie list-sessions 2>/dev/null`.quiet()).exitCode===0)results.push({name:"Server running",status:"pass"});else return results.push({name:"Server running",status:"warn",message:"no sessions",suggestion:"Start with: tmux new-session -d -s genie"}),results}catch{return results.push({name:"Server running",status:"warn",message:"could not check"}),results}let sessionName=(await loadGenieConfig()).session.name;try{if((await $3`${tmuxBin()} -L genie has-session -t ${`=${sessionName}`} 2>/dev/null`.quiet()).exitCode===0)results.push({name:`Session '${sessionName}' exists`,status:"pass"});else results.push({name:`Session '${sessionName}' exists`,status:"warn",suggestion:`Start with: tmux new-session -d -s ${sessionName}`})}catch{results.push({name:`Session '${sessionName}' exists`,status:"warn",message:"could not check"})}return results}async function checkWorkerProfiles(){let results=[];if(!genieConfigExists())return results.push({name:"Worker profiles",status:"warn",message:"no genie config",suggestion:"Run: genie setup"}),results;let config=await loadGenieConfig(),profiles=config.workerProfiles;if(!profiles||Object.keys(profiles).length===0)return results.push({name:"Worker profiles",status:"pass",message:"none configured (using defaults)"}),results;let totalProfiles=Object.keys(profiles).length;results.push({name:"Profiles configured",status:"pass",message:`${totalProfiles} profile${totalProfiles===1?"":"s"}`});for(let name of Object.keys(profiles))results.push({name:`Profile '${name}'`,status:"pass",message:"claude (direct)"});if(config.defaultWorkerProfile)if(profiles[config.defaultWorkerProfile])results.push({name:"Default profile",status:"pass",message:config.defaultWorkerProfile});else results.push({name:"Default profile",status:"warn",message:`'${config.defaultWorkerProfile}' not found`,suggestion:"Run: genie profiles default <profile>"});return results}async function checkBridge(){let results=[];try{let{getBridgeStatus:getBridgeStatus2,removeBridgePidfile:removeBridgePidfile2}=await Promise.resolve().then(() => (init_bridge_status(),exports_bridge_status)),res=await getBridgeStatus2(void 0,{});if(res.state==="stopped")return results.push({name:"Bridge",status:"warn",message:"stopped (no pidfile)",suggestion:"Start the bridge with: genie serve"}),results;if(res.state==="stale"){if(res.pidfile)removeBridgePidfile2();return results.push({name:"Bridge",status:"fail",message:`stale: ${res.detail}`,suggestion:"Restart the bridge with: genie serve restart"}),results}let{pong,pidfile}=res;if(!pong||!pidfile)return results.push({name:"Bridge",status:"warn",message:"running state missing pong/pidfile metadata"}),results;let uptimeSec=Math.round(pong.uptimeMs/1000);results.push({name:"Bridge running",status:"pass",message:`running (pid ${pong.pid}, uptime ${uptimeSec}s)`}),results.push({name:"NATS ping",status:"pass",message:`pong in ${res.latencyMs??0}ms (${pidfile.natsUrl})`}),results.push({name:"Subjects",status:"pass",message:pong.subjects.join(", ")})}catch(err){let detail=err instanceof Error?err.message:String(err);results.push({name:"Bridge module",status:"warn",message:`could not probe bridge: ${detail}`})}return results}function checkGenieAgentTemplate(workspaceRoot){let root=workspaceRoot??findWorkspace()?.root;if(!root)return[];let genieDir=join25(root,"agents","genie");if(!existsSync20(genieDir))return[];let agentsMd=join25(genieDir,"AGENTS.md"),agentYaml=join25(genieDir,"agent.yaml"),issues=[];if(existsSync20(agentsMd))try{if(readFileSync13(agentsMd,"utf-8").includes(STALE_GENIE_AGENTS_MD_MARKER))issues.push("AGENTS.md uses generic placeholder template")}catch{}if(existsSync20(agentYaml))try{let text=readFileSync13(agentYaml,"utf-8");if(!STALE_GENIE_AGENT_YAML_MISSING_MODEL_REGEX.test(text))issues.push("agent.yaml missing model field (TUI falls back to gray)")}catch{}if(issues.length===0)return[{name:"agents/genie scaffold up to date",status:"pass"}];return[{name:"agents/genie stale scaffold",status:"warn",message:issues.join("; "),suggestion:"Run: genie doctor --fix (re-emits genie specialist templates, preserves user edits)"}]}function findBundledTmuxConfigDir(){try{let moduleDir=dirname8(fileURLToPath3(import.meta.url));for(let i2=0;i2<6;i2+=1){let candidate=resolve3(moduleDir,"../".repeat(i2+1),"scripts","tmux");if(existsSync20(join25(candidate,"tui-tmux.conf"))&&existsSync20(join25(candidate,"genie.tmux.conf")))return candidate}}catch{}return null}function checkTmuxConfigs(){if(!findBundledTmuxConfigDir())return[{name:"tmux configs",status:"pass",message:"bundled configs unavailable (skipped)"}];let home=join25(homedir20(),".genie"),stale=[],expectedSnippet="unbind -n MouseDown3Pane";for(let file of["tui-tmux.conf","tmux.conf"]){let installedPath=join25(home,file);if(!existsSync20(installedPath))continue;try{if(!readFileSync13(installedPath,"utf-8").includes(expectedSnippet))stale.push(file)}catch{stale.push(file)}}if(stale.length===0)return[{name:"~/.genie tmux configs up to date",status:"pass"}];return[{name:"~/.genie tmux configs stale",status:"warn",message:`missing right-click unbind in: ${stale.join(", ")}`,suggestion:"Run: genie doctor --fix (refreshes ~/.genie tmux configs from bundled scripts/tmux/)"}]}function isAgentDirectory(path2){try{return statSync6(path2).isDirectory()}catch{return!1}}function hasLegacyFrontmatter(agentDir){let yamlPath=join25(agentDir,"agent.yaml"),agentsMdPath=join25(agentDir,"AGENTS.md");if(!existsSync20(yamlPath)||!existsSync20(agentsMdPath))return!1;try{return readFileSync13(agentsMdPath,"utf-8").slice(0,4).startsWith("---")}catch{return!1}}function checkLegacyAgentFrontmatter(workspaceRoot){let results=[],root=workspaceRoot??findWorkspace()?.root;if(!root)return[];let agentsDir=join25(root,"agents");if(!existsSync20(agentsDir))return[];let entries;try{entries=readdirSync7(agentsDir)}catch{return[]}for(let name of entries){let agentDir=join25(agentsDir,name);if(!isAgentDirectory(agentDir))continue;if(!hasLegacyFrontmatter(agentDir))continue;results.push({name:`agents/${name}/AGENTS.md`,status:"warn",message:"legacy frontmatter detected (ignored by sync)",suggestion:`Move config into agents/${name}/agent.yaml \u2014 AGENTS.md is prompt-only post-migration.`})}if(results.length===0)results.push({name:"No legacy frontmatter in agents/*/AGENTS.md",status:"pass"});return results}async function checkPgserveCanonical(){let results=[],canonicalPort=null;try{let out=execFileSync2("pgserve",["port"],{encoding:"utf8",timeout:3000,stdio:["ignore","pipe","ignore"]}),parsed=Number.parseInt(out.trim(),10);if(Number.isFinite(parsed)&&parsed>0&&parsed<=65535)canonicalPort=parsed}catch{}if(canonicalPort===null)return results.push({name:"pgserve binary",status:"warn",message:"not on PATH (or `pgserve port` failed)",suggestion:"Install canonical pgserve: bun add -g pgserve@^2.1.0 (then run `pgserve install` to register under pm2)"}),results;results.push({name:"pgserve binary",status:"pass",message:`canonical port ${canonicalPort}`});try{let status=execFileSync2("pgserve",["status","--json"],{encoding:"utf8",timeout:3000,stdio:["ignore","pipe","ignore"]}),parsed=JSON.parse(status);if(parsed.installed===!0&&parsed.status==="online")results.push({name:"pgserve under pm2",status:"pass",message:`online \u2014 shared backbone for genie-serve + omni-api on :${canonicalPort}`});else if(parsed.installed===!0)results.push({name:"pgserve under pm2",status:"warn",message:`registered but status=${parsed.status??"unknown"}`,suggestion:"Recover with: pm2 restart pgserve (logs: ~/.pgserve/logs/)"});else results.push({name:"pgserve under pm2",status:"warn",message:"binary present but not registered under pm2",suggestion:"Register canonical pgserve: pgserve install"})}catch{results.push({name:"pgserve under pm2",status:"warn",message:"`pgserve status` failed (pm2 unreachable?)",suggestion:"Verify pm2: pm2 list | Re-register: pgserve install"})}return results}function runCheckSection(label,results,counts){printSectionHeader(label);for(let result2 of results){if(printCheckResult(result2),result2.status==="fail")counts.errors=!0;if(result2.status==="warn")counts.warnings=!0}}async function doctorCommand(options){if(options?.fix){await doctorFix();return}if(options?.fixTeamOrphans){await runFixTeamOrphans({dryRun:Boolean(options.dryRun),json:Boolean(options.json)});return}if(options?.observability){await runObservabilityCheck(Boolean(options.json));return}if(options?.perf){let{runPerfCheck:runPerfCheck2}=await Promise.resolve().then(() => (init_perf_check(),exports_perf_check));await runPerfCheck2(Boolean(options.json));return}console.log(),console.log("\x1B[1mGenie Doctor\x1B[0m"),console.log(`\x1B[2m${"\u2500".repeat(40)}\x1B[0m`);let counts={errors:!1,warnings:!1};if(runCheckSection("Prerequisites",await checkPrerequisites(),counts),runCheckSection("Installer Resolution",await collectInstallerResolution(),counts),runCheckSection("Configuration",await checkConfiguration(),counts),runCheckSection("Tmux",await checkTmux(),counts),runCheckSection("Tmux Configs",checkTmuxConfigs(),counts),runCheckSection("Worker Profiles",await checkWorkerProfiles(),counts),runCheckSection("Pgserve (canonical backbone)",await checkPgserveCanonical(),counts),runCheckSection("Omni Bridge",await checkBridge(),counts),runCheckSection("Agent Config",checkLegacyAgentFrontmatter(),counts),runCheckSection("Genie Specialist",checkGenieAgentTemplate(),counts),printDoctorSummary(counts),counts.errors)process.exit(1)}function printObservabilityReport(report){if(console.log(),console.log("\x1B[1mObservability Health\x1B[0m"),console.log(`\x1B[2m${"\u2500".repeat(40)}\x1B[0m`),console.log(` partition_health: ${report.partition_health}`),console.log(` partition_count: ${report.partition_count}`),console.log(` next_rotation_at: ${report.next_rotation_at??"n/a"}`),console.log(` oldest_partition: ${report.oldest_partition??"n/a"}`),console.log(` newest_partition: ${report.newest_partition??"n/a"}`),console.log(` GENIE_WIDE_EMIT: ${report.wide_emit_flag}`),report.message)console.log(` note: ${report.message}`);console.log()}async function runObservabilityCheck(json2){let report=await collectObservabilityHealth();if(json2)console.log(JSON.stringify(report,null,2));else printObservabilityReport(report);if(report.partition_health==="fail")process.exit(1)}async function runFixTeamOrphans(opts){let{archiveOrphanTeamConfigs:archiveOrphanTeamConfigs2}=await Promise.resolve().then(() => (init_archive_orphan_team_configs(),exports_archive_orphan_team_configs)),decisions=archiveOrphanTeamConfigs2({dryRun:opts.dryRun});if(opts.json){console.log(JSON.stringify({dryRun:opts.dryRun,decisions},null,2));return}if(decisions.length===0){console.log(" no team config dirs found \u2014 nothing to do");return}for(let d of decisions){let tag=d.classification==="stale"?opts.dryRun?"WOULD ARCHIVE":"ARCHIVED":d.classification.toUpperCase(),tail=d.archivedTo?` \u2192 ${d.archivedTo}`:"";console.log(` [${tag}] ${d.team} \u2014 ${d.reason}${tail}`)}let stale=decisions.filter((d)=>d.classification==="stale").length,active=decisions.filter((d)=>d.classification==="active").length;console.log(`
|
|
935
935
|
${decisions.length} dirs inspected, ${stale} archived, ${active} flagged active.`)}function printDoctorSummary(counts){if(console.log(),console.log(`\x1B[2m${"\u2500".repeat(40)}\x1B[0m`),counts.errors)console.log("\x1B[31mSome checks failed.\x1B[0m Run \x1B[36mgenie setup\x1B[0m to fix.");else if(counts.warnings)console.log("\x1B[33mSome warnings detected.\x1B[0m Everything should still work.");else console.log("\x1B[32mAll checks passed!\x1B[0m");console.log()}function legacyPgserveRepairEnabled(){return process.env.GENIE_PG_FORCE_TCP==="1"||process.env.GENIE_DOCTOR_FIX_LEGACY_PGSERVE==="1"}async function killStalePostgres(genieHome3){if(!legacyPgserveRepairEnabled()){console.log(" Skipping legacy pgserve v1 process cleanup (v1/v2 coexistence)");return}console.log(" Killing stale Genie legacy pgserve processes...");try{let{execSync:execSync4}=await import("child_process"),escaped=join25(genieHome3,"data","pgserve").replace(/\//g,"\\/");execSync4(`pkill -9 -f "postgres.*${escaped}" 2>/dev/null || true`,{stdio:"ignore",timeout:5000}),execSync4(`pkill -9 -f "pgserve.*${escaped}" 2>/dev/null || true`,{stdio:"ignore",timeout:5000}),console.log(" \x1B[32m\u2713\x1B[0m Stale Genie legacy pgserve processes killed")}catch{console.log(" \x1B[33m!\x1B[0m Could not kill stale Genie legacy pgserve processes")}}async function cleanSharedMemory(){console.log(" Cleaning shared memory...");try{let{execSync:execSync4}=await import("child_process");if(process.platform==="darwin")execSync4("ipcs -m 2>/dev/null | awk '/^m/ {print $2}' | xargs -I{} ipcrm -m {} 2>/dev/null || true",{stdio:"ignore",timeout:5000});else execSync4("ipcs -m 2>/dev/null | awk '$6 == 0 {print $2}' | xargs -I{} ipcrm -m {} 2>/dev/null || true",{stdio:"ignore",timeout:5000});console.log(" \x1B[32m\u2713\x1B[0m Shared memory cleaned")}catch{console.log(" \x1B[32m\u2713\x1B[0m No stale shared memory")}}async function stopExistingDaemon(pidFile){try{let{readFileSync:readFileSync14}=await import("fs"),pid=Number.parseInt(readFileSync14(pidFile,"utf-8").trim(),10);if(!Number.isNaN(pid)&&pid>0)try{process.kill(pid,"SIGTERM"),console.log(` \x1B[32m\u2713\x1B[0m Stopped existing daemon (PID ${pid})`),await new Promise((r)=>setTimeout(r,1000))}catch{}}catch{}}function removeStaleFiles(genieHome3,pidFile){let files=[pidFile];if(legacyPgserveRepairEnabled())files.push(join25(genieHome3,"pgserve.port"),join25(genieHome3,"data","pgserve","postmaster.pid"));else console.log(" Leaving legacy pgserve v1 port/data files untouched (v1/v2 coexistence)");for(let file of files)if(existsSync20(file))try{unlinkSync6(file),console.log(` \x1B[32m\u2713\x1B[0m Removed ${file}`)}catch{console.log(` \x1B[33m!\x1B[0m Could not remove ${file}`)}}async function restartDaemon(){console.log(" Restarting daemon...");try{let{spawn:spawn2}=await import("child_process"),bunPath=process.execPath??"bun",genieBin=process.argv[1]??"genie";spawn2(bunPath,[genieBin,"daemon","start"],{detached:!0,stdio:"ignore"}).unref(),await new Promise((resolve4)=>setTimeout(resolve4,2000)),console.log(" \x1B[32m\u2713\x1B[0m Daemon restart initiated")}catch{console.log(" \x1B[33m!\x1B[0m Could not restart daemon \u2014 run: genie daemon start")}}function isAgentsMdUserEdited(target,fresh){if(!existsSync20(target))return!1;try{let current=readFileSync13(target,"utf-8");if(current.trim().length===0)return!1;if(current.includes(STALE_GENIE_AGENTS_MD_MARKER))return!1;return current!==fresh}catch{return!1}}function writeGenieTemplate(targetDir,name,content){let target=join25(targetDir,name),userEdited=name==="AGENTS.md"&&isAgentsMdUserEdited(target,content),writeTo=userEdited?`${target}.new`:target;try{writeFileSync7(writeTo,content);let marker=userEdited?`wrote ${name}.new (user edits preserved \u2014 merge manually)`:`wrote ${name}`;console.log(` \x1B[32m\u2713\x1B[0m ${marker}`)}catch(err){let detail=err instanceof Error?err.message:String(err);console.log(` \x1B[31m\u2717\x1B[0m ${name}: ${detail}`)}}function fixGenieAgentTemplate(workspaceRoot){let root=workspaceRoot??findWorkspace()?.root;if(!root){console.log(" \x1B[33m!\x1B[0m No workspace detected \u2014 skipping genie-template repair");return}let genieDir=join25(root,"agents","genie");if(!existsSync20(genieDir)){console.log(" \x1B[2m\xB7\x1B[0m No agents/genie directory \u2014 skipping");return}console.log(" Refreshing agents/genie scaffold..."),writeGenieTemplate(genieDir,"AGENTS.md",GENIE_AGENTS_TEMPLATE),writeGenieTemplate(genieDir,"SOUL.md",GENIE_SOUL_TEMPLATE),writeGenieTemplate(genieDir,"HEARTBEAT.md",GENIE_HEARTBEAT_TEMPLATE)}function ensureGenieHomeDir(home){if(existsSync20(home))return!0;try{return mkdirSync10(home,{recursive:!0}),!0}catch{return console.log(` \x1B[31m\u2717\x1B[0m Could not create ${home}`),!1}}function refreshTmuxConfFile(bundledDir,home,srcFile,dstFile){let src=join25(bundledDir,srcFile),dst=join25(home,dstFile);if(!existsSync20(src))return;if(existsSync20(dst))try{copyFileSync2(dst,`${dst}.bak`)}catch{}try{copyFileSync2(src,dst),console.log(` \x1B[32m\u2713\x1B[0m wrote ${dstFile} (previous saved as ${dstFile}.bak)`)}catch(err){let detail=err instanceof Error?err.message:String(err);console.log(` \x1B[31m\u2717\x1B[0m ${dstFile}: ${detail}`)}}function fixTmuxConfigs(){let bundledDir=findBundledTmuxConfigDir();if(!bundledDir){console.log(" \x1B[33m!\x1B[0m Bundled tmux configs not found \u2014 skipping");return}let home=join25(homedir20(),".genie");if(!ensureGenieHomeDir(home))return;console.log(" Refreshing ~/.genie tmux configs..."),refreshTmuxConfFile(bundledDir,home,"tui-tmux.conf","tui-tmux.conf"),refreshTmuxConfFile(bundledDir,home,"genie.tmux.conf","tmux.conf")}async function runMaintenancePreconditions(silent=!1,log){try{let{runDoctorMaintenance:runDoctorMaintenance2}=await Promise.resolve().then(() => (init_ensure_ready(),exports_ensure_ready));await runDoctorMaintenance2({silent,deps:log?{log}:void 0})}catch(err){let msg=err instanceof Error?err.message:String(err);if(!silent)console.warn(` Maintenance preconditions skipped: ${msg}`)}}async function doctorFix(){console.log(`
|
|
936
936
|
\x1B[1mGenie Doctor \u2014 Auto Fix\x1B[0m`),console.log(`\x1B[2m${"\u2500".repeat(40)}\x1B[0m
|
|
937
937
|
`);let genieHome3=process.env.GENIE_HOME??join25(homedir20(),".genie");await killStalePostgres(genieHome3),await cleanSharedMemory();let pidFile=join25(genieHome3,"scheduler.pid");await stopExistingDaemon(pidFile),removeStaleFiles(genieHome3,pidFile),fixGenieAgentTemplate(),fixTmuxConfigs(),await runMaintenancePreconditions(),await restartDaemon(),console.log(`
|
|
@@ -3890,12 +3890,12 @@ Bus `);for(let i2=1;i2<parts.length;i2++){let usb2=parseLinuxUsb(parts[i2]);resu
|
|
|
3890
3890
|
`;appendFileSync5(logPath,line,{mode:420})}catch{}}function installTuiExitSignals(){let exitOnSignal=(signal)=>{process.exit(signal==="SIGHUP"?0:128+(signal==="SIGINT"?2:15))};process.on("SIGHUP",exitOnSignal),process.on("SIGINT",exitOnSignal),process.on("SIGTERM",exitOnSignal)}async function launchTui(){installTuiExitSignals(),await recordTuiLaunchBreadcrumb();let{renderNav:renderNav2}=await init_render().then(() => exports_render);await renderNav2()}var TUI_CRASH_LOG_BANNER_PREFIX="--- tui-launch ",TUI_CRASH_LOG_RECOVERY_MAX_BYTES=65536,TUI_CRASH_LOG_RECOVERY_MAX_MSG_CHARS=3000;var init_tui=()=>{};var exports_resolve_agent_cwd={};__export(exports_resolve_agent_cwd,{resolveAgentFromCwd:()=>resolveAgentFromCwd});import{existsSync as existsSync75}from"fs";import{basename as basename17,dirname as dirname31,join as join92,relative as relative10,sep as sep3}from"path";function isRelativeWithin(rel,original){return!rel.startsWith("..")&&rel!==original}function resolveFromCanonicalDir(cwd,agentsDir){let relToAgents=relative10(agentsDir,cwd);if(!isRelativeWithin(relToAgents,cwd))return null;let segments=relToAgents.split(sep3).filter(Boolean);if(segments.length===0)return null;let agentName=segments[0];if(!existsSync75(join92(agentsDir,agentName,"AGENTS.md")))return null;let source=segments.length===1?"exact":"parent";return{agent:agentName,source}}function resolveFromWalkUp(cwd,workspaceRoot){let wsRel=relative10(workspaceRoot,cwd);if(!isRelativeWithin(wsRel,cwd))return null;let current=cwd;while(current!==workspaceRoot&¤t!==dirname31(current)){if(existsSync75(join92(current,"AGENTS.md")))return{agent:basename17(current),source:"parent"};current=dirname31(current)}return null}function resolveAgentFromCwd(cwd,workspaceRoot){return resolveFromCanonicalDir(cwd,join92(workspaceRoot,"agents"))??resolveFromWalkUp(cwd,workspaceRoot)??{agent:"genie",source:"default"}}var init_resolve_agent_cwd=()=>{};var import__=__toESM(require_commander(),1),{program,createCommand,createArgument,createOption,CommanderError,InvalidArgumentError,InvalidOptionArgumentError,Command,Argument,Option,Help}=import__.default;init_doctor();import{execFileSync as execFileSync3,spawnSync as spawnSync2}from"child_process";import{existsSync as existsSync21,mkdirSync as mkdirSync11,writeFileSync as writeFileSync8}from"fs";import{homedir as homedir21}from"os";import{join as join26}from"path";var PM2_PROCESS_NAME="genie-serve",HARDENED_DEFAULTS={maxRestarts:50,minUptimeMs:1e4,restartDelayMs:4000,expBackoffRestartDelayMs:100,maxMemory:process.env.GENIE_SERVE_MAX_MEMORY||"4G",killTimeoutMs:60000,logDateFormat:"YYYY-MM-DD HH:mm:ss.SSS"};function getLogsDir(){return join26(homedir21(),".genie","logs")}function ok(msg){process.stdout.write(`genie install: ${msg}
|
|
3891
3891
|
`)}function note(msg){process.stderr.write(`genie install: ${msg}
|
|
3892
3892
|
`)}function fail(msg){process.stderr.write(`genie install: ${msg}
|
|
3893
|
-
`),process.exit(1)}function which(cmd){try{return execFileSync3("which",[cmd],{encoding:"utf8",timeout:3000,stdio:["ignore","pipe","ignore"]}).trim()||null}catch{return null}}function pm2GetProcess(name){try{let out=execFileSync3("pm2",["jlist"],{encoding:"utf8",timeout:5000,stdio:["ignore","pipe","ignore"]});return JSON.parse(out).find((p)=>p.name===name)??null}catch{return null}}function pm2IsAvailable(){try{return execFileSync3("pm2",["--version"],{encoding:"utf8",timeout:3000,stdio:["ignore","pipe","ignore"]}),!0}catch{return!1}}function pgserveIsAvailable(){return which("pgserve")!==null}function tryPgserveInstall(){if(!pgserveIsAvailable())return note("pgserve binary not found in PATH. Skipping the canonical pgserve hookup. Install with: bun add -g pgserve (then re-run genie install)."),!1;let result2=spawnSync2("pgserve",["install"],{stdio:"inherit"});if(result2.status!==0)return note(`pgserve install exited with code ${result2.status}. Continuing \u2014 genie-serve registration proceeds.`),!1;return!0}function resolveGenieBinary(){let wired=which("genie");if(wired)return wired;return process.argv[1]??"genie"}function getEcosystemConfigPath(){return join26(homedir21(),".genie",`${PM2_PROCESS_NAME}.config.cjs`)}function buildEcosystemConfigSource(geniePath){let logs={out:join26(getLogsDir(),`${PM2_PROCESS_NAME}-out.log`),error:join26(getLogsDir(),`${PM2_PROCESS_NAME}-error.log`)},cfg={name:PM2_PROCESS_NAME,script:geniePath,args:"serve start --headless --no-tui --no-interactive",interpreter:"none",autorestart:!0,max_restarts:HARDENED_DEFAULTS.maxRestarts,min_uptime:HARDENED_DEFAULTS.minUptimeMs,restart_delay:HARDENED_DEFAULTS.restartDelayMs,exp_backoff_restart_delay:HARDENED_DEFAULTS.expBackoffRestartDelayMs,max_memory_restart:HARDENED_DEFAULTS.maxMemory,kill_timeout:HARDENED_DEFAULTS.killTimeoutMs,log_date_format:HARDENED_DEFAULTS.logDateFormat,error_file:logs.error,out_file:logs.out,merge_logs:!0,time:!0};return`// Generated by \`genie install\` \u2014 do not edit by hand.
|
|
3893
|
+
`),process.exit(1)}function which(cmd){try{return execFileSync3("which",[cmd],{encoding:"utf8",timeout:3000,stdio:["ignore","pipe","ignore"]}).trim()||null}catch{return null}}function pm2GetProcess(name){try{let out=execFileSync3("pm2",["jlist"],{encoding:"utf8",timeout:5000,stdio:["ignore","pipe","ignore"]});return JSON.parse(out).find((p)=>p.name===name)??null}catch{return null}}function pm2IsAvailable(){try{return execFileSync3("pm2",["--version"],{encoding:"utf8",timeout:3000,stdio:["ignore","pipe","ignore"]}),!0}catch{return!1}}function pgserveIsAvailable(){return which("pgserve")!==null}function tryPgserveInstall(){if(!pgserveIsAvailable())return note("pgserve binary not found in PATH. Skipping the canonical pgserve hookup. Install with: bun add -g pgserve (then re-run genie install)."),!1;let result2=spawnSync2("pgserve",["install"],{stdio:"inherit"});if(result2.status!==0)return note(`pgserve install exited with code ${result2.status}. Continuing \u2014 genie-serve registration proceeds.`),!1;return!0}function tryPgservePort(){if(!pgserveIsAvailable())return null;let result2=spawnSync2("pgserve",["port"],{encoding:"utf8",timeout:5000});if(result2.status!==0)return null;let port=Number.parseInt((result2.stdout??"").trim(),10);if(!Number.isFinite(port)||port<=0||port>65535)return null;return port}function buildGenieDatabaseUrl(port){return`postgresql://postgres:postgres@localhost:${port}/genie`}function resolveGenieBinary(){let wired=which("genie");if(wired)return wired;return process.argv[1]??"genie"}function getEcosystemConfigPath(){return join26(homedir21(),".genie",`${PM2_PROCESS_NAME}.config.cjs`)}function buildEcosystemConfigSource(geniePath,databaseUrl){let logs={out:join26(getLogsDir(),`${PM2_PROCESS_NAME}-out.log`),error:join26(getLogsDir(),`${PM2_PROCESS_NAME}-error.log`)},cfg={name:PM2_PROCESS_NAME,script:geniePath,args:"serve start --headless --no-tui --no-interactive",interpreter:"none",autorestart:!0,max_restarts:HARDENED_DEFAULTS.maxRestarts,min_uptime:HARDENED_DEFAULTS.minUptimeMs,restart_delay:HARDENED_DEFAULTS.restartDelayMs,exp_backoff_restart_delay:HARDENED_DEFAULTS.expBackoffRestartDelayMs,max_memory_restart:HARDENED_DEFAULTS.maxMemory,kill_timeout:HARDENED_DEFAULTS.killTimeoutMs,log_date_format:HARDENED_DEFAULTS.logDateFormat,error_file:logs.error,out_file:logs.out,merge_logs:!0,time:!0};if(databaseUrl)cfg.env={DATABASE_URL:databaseUrl};return`// Generated by \`genie install\` \u2014 do not edit by hand.
|
|
3894
3894
|
// Regenerated on every \`genie install\` invocation.
|
|
3895
3895
|
module.exports = {
|
|
3896
3896
|
apps: [${JSON.stringify(cfg,null,2)}],
|
|
3897
3897
|
};
|
|
3898
|
-
`}function writeEcosystemConfig(geniePath){let path2=getEcosystemConfigPath();return ensureLogsDir(),writeFileSync8(path2,buildEcosystemConfigSource(geniePath),{mode:420}),path2}function buildPm2StartArgs(geniePath){return["start",writeEcosystemConfig(geniePath),"--update-env"]}function ensureLogsDir(){let dir=getLogsDir();if(!existsSync21(dir))mkdirSync11(dir,{recursive:!0,mode:493})}async function installCommand(options={}){if(!pm2IsAvailable())fail("pm2 not found in PATH. Install with: bun add -g pm2 (or npm i -g pm2)");if(!options.skipPgserve)tryPgserveInstall();let existing=pm2GetProcess(PM2_PROCESS_NAME);if(existing){ok(`already installed (pm2 process "${PM2_PROCESS_NAME}", status=${existing.pm2_env?.status??"unknown"}). Use \`pm2 restart genie-serve\` to pick up code changes.`);return}ensureLogsDir();let geniePath=resolveGenieBinary(),pm2Args=buildPm2StartArgs(geniePath),result2=spawnSync2("pm2",pm2Args,{stdio:"inherit"});if(result2.status!==0)fail(`pm2 start failed (exit ${result2.status}). Logs: ${getLogsDir()}/${PM2_PROCESS_NAME}-error.log`);ok(`installed: pm2 process "${PM2_PROCESS_NAME}" (logs: ${getLogsDir()})`),ok("the genie bridge will now survive shell closure and host reboots (after `pm2 save` + `pm2 startup`).")}init_setup();init_shortcuts();import{existsSync as existsSync24}from"fs";import{homedir as homedir25}from"os";import{join as join30}from"path";async function shortcutsShowCommand(){displayShortcuts();let home=homedir25(),tmuxConf=join30(home,".tmux.conf"),zshrc=join30(home,".zshrc"),bashrc=join30(home,".bashrc");if(console.log("Installation status:"),isShortcutsInstalled(tmuxConf))console.log(" \x1B[32m\u2713\x1B[0m tmux.conf");else console.log(" \x1B[33m-\x1B[0m tmux.conf");let shellRc=existsSync24(zshrc)?zshrc:bashrc;if(isShortcutsInstalled(shellRc))console.log(` \x1B[32m\u2713\x1B[0m ${shellRc.replace(home,"~")}`);else console.log(` \x1B[33m-\x1B[0m ${shellRc.replace(home,"~")}`);console.log(),console.log("Run \x1B[36mgenie shortcuts install\x1B[0m to install shortcuts."),console.log("Run \x1B[36mgenie shortcuts uninstall\x1B[0m to remove shortcuts."),console.log()}async function shortcutsInstallCommand(){await installShortcuts()}async function shortcutsUninstallCommand(){await uninstallShortcuts()}init_esm14();init_claude_settings();init_genie_config2();import{existsSync as existsSync25,lstatSync,rmSync as rmSync2,unlinkSync as unlinkSync8}from"fs";import{homedir as homedir26}from"os";import{join as join31}from"path";var ORCHESTRATION_RULES_PATH=join31(homedir26(),".claude","rules","genie-orchestration.md"),LOCAL_BIN=join31(homedir26(),".local","bin"),SYMLINKS=["genie","term"];function isGenieSymlink(path3){try{if(!existsSync25(path3))return!1;if(!lstatSync(path3).isSymbolicLink())return!1;return!0}catch{return!1}}function removeSymlinks(){let removed=[];for(let name of SYMLINKS){let symlinkPath=join31(LOCAL_BIN,name);if(isGenieSymlink(symlinkPath))try{unlinkSync8(symlinkPath),removed.push(name)}catch{}}return removed}function tryRemoveStep(label,successMsg,fn){console.log(`\x1B[2m${label}\x1B[0m`);try{fn(),console.log(` \x1B[32m+\x1B[0m ${successMsg}`)}catch(error){let message=error instanceof Error?error.message:String(error);console.log(` \x1B[33m!\x1B[0m ${label.replace("...","")} failed: ${message}`)}}function performUninstall(hasHookScript,existingSymlinks,genieDir,hasGenieDir){if(hasHookScript)tryRemoveStep("Removing hook script...","Hook script removed",()=>removeHookScript());if(existingSymlinks.length>0){console.log("\x1B[2mRemoving symlinks...\x1B[0m");let removed=removeSymlinks();if(removed.length>0)console.log(` \x1B[32m+\x1B[0m Removed: ${removed.join(", ")}`)}if(existsSync25(ORCHESTRATION_RULES_PATH))tryRemoveStep("Removing orchestration rules...","Orchestration rules removed (~/.claude/rules/genie-orchestration.md)",()=>unlinkSync8(ORCHESTRATION_RULES_PATH));if(hasGenieDir)tryRemoveStep("Removing genie directory...","Directory removed",()=>rmSync2(genieDir,{recursive:!0,force:!0}))}async function uninstallCommand(){console.log(),console.log("\x1B[1m\x1B[33m Uninstall Genie CLI\x1B[0m"),console.log();let genieDir=getGenieDir(),hasGenieDir=existsSync25(genieDir),hasHookScript=hookScriptExists(),hasOrchestrationRules=existsSync25(ORCHESTRATION_RULES_PATH),existingSymlinks=SYMLINKS.filter((name)=>isGenieSymlink(join31(LOCAL_BIN,name)));if(console.log("\x1B[2mThis will remove:\x1B[0m"),hasHookScript)console.log(" \x1B[31m-\x1B[0m Hook script (~/.claude/hooks/genie-bash-hook.sh)");if(hasOrchestrationRules)console.log(" \x1B[31m-\x1B[0m Orchestration rules (~/.claude/rules/genie-orchestration.md)");if(hasGenieDir)console.log(` \x1B[31m-\x1B[0m Genie directory (${contractPath(genieDir)})`);if(existingSymlinks.length>0)console.log(` \x1B[31m-\x1B[0m Symlinks from ~/.local/bin: ${existingSymlinks.join(", ")}`);if(console.log(),!hasGenieDir&&!hasHookScript&&!hasOrchestrationRules&&existingSymlinks.length===0){console.log("\x1B[33mNothing to uninstall.\x1B[0m"),console.log();return}if(!await esm_default4({message:"Are you sure you want to uninstall Genie CLI?",default:!1})){console.log(),console.log("\x1B[2mUninstall cancelled.\x1B[0m"),console.log();return}console.log(),performUninstall(hasHookScript,existingSymlinks,genieDir,hasGenieDir),console.log(),console.log("\x1B[32m+\x1B[0m Genie CLI uninstalled."),console.log(),console.log("\x1B[2mNote: If you installed via npm/bun, also run:\x1B[0m"),console.log(" \x1B[36mbun remove -g @automagik/genie\x1B[0m"),console.log(" \x1B[2mor\x1B[0m"),console.log(" \x1B[36mnpm uninstall -g @automagik/genie\x1B[0m"),console.log()}init_genie_config2();import{execSync as execSync4,spawn as spawn3}from"child_process";import{chmodSync as chmodSync2,closeSync as closeSync3,copyFileSync as copyFileSync3,existsSync as existsSync26,mkdirSync as mkdirSync14,openSync as openSync3,readFileSync as readFileSync17,readSync as readSync2,readdirSync as readdirSync8,rmSync as rmSync3,statSync as statSync7,writeFileSync as writeFileSync12}from"fs";import{chmod,copyFile,mkdir as mkdir5,unlink as unlink2}from"fs/promises";import{homedir as homedir27}from"os";import{join as join32}from"path";var GENIE_HOME2=process.env.GENIE_HOME||join32(homedir27(),".genie"),GENIE_SRC=join32(GENIE_HOME2,"src"),GENIE_BIN=join32(GENIE_HOME2,"bin"),LOCAL_BIN2=join32(homedir27(),".local","bin"),TRUTHY=new Set(["1","true","yes","on"]),UPDATE_DIAGNOSTIC_SCHEMA_VERSION=1;function log(message){console.log(`\x1B[32m\u25B8\x1B[0m ${message}`)}function success(message){console.log(`\x1B[32m\u2714\x1B[0m ${message}`)}function error(message){console.log(`\x1B[31m\u2716\x1B[0m ${message}`)}function formatDuration2(ms){if(ms<1000)return`${ms}ms`;return`${(ms/1000).toFixed(1)}s`}function isTruthyEnv(value){return value!==void 0&&TRUTHY.has(value.trim().toLowerCase())}async function withTemporaryEnv(key,value,fn){let previous=process.env[key];process.env[key]=value;try{return await fn()}finally{if(previous===void 0)delete process.env[key];else process.env[key]=previous}}function safeExec(command,timeoutMs=1500){try{return execSync4(command,{encoding:"utf-8",stdio:["ignore","pipe","pipe"],timeout:timeoutMs}).trim()}catch(err){let stdout=err.stdout;if(typeof stdout==="string"&&stdout.trim())return stdout.trim();return""}}function safeRead(path3,maxChars=4000){try{let value=readFileSync17(path3,"utf-8");if(value.length<=maxChars)return value;return value.slice(value.length-maxChars)}catch{return null}}function tailLines(path3,maxBytes=64000,maxLines=200){let fd=null;try{let stat4=statSync7(path3),bytesToRead=Math.min(stat4.size,maxBytes),buffer2=Buffer.alloc(bytesToRead);return fd=openSync3(path3,"r"),readSync2(fd,buffer2,0,bytesToRead,Math.max(0,stat4.size-bytesToRead)),buffer2.toString("utf-8").split(/\r?\n/).map((line)=>line.trim()).filter(Boolean).slice(-maxLines)}catch{return[]}finally{if(fd!==null)try{closeSync3(fd)}catch{}}}function summarizeJsonlSignals(path3){let signals2=new Map;for(let line of tailLines(path3))try{let event=JSON.parse(line),level=typeof event.level==="string"?event.level:"unknown";if(level!=="error"&&level!=="warn")continue;let name=typeof event.event==="string"?event.event:"unknown",key=`${level}:${name}`,existing=signals2.get(key)??{level,event:name,count:0};if(existing.count++,typeof event.timestamp==="string")existing.lastTimestamp=event.timestamp;if(typeof event.error==="string")existing.lastError=event.error;signals2.set(key,existing)}catch{}return[...signals2.values()].sort((a,b2)=>b2.count-a.count).slice(0,10)}async function collectUpdateDiagnostics(ctx,maintenance){let logsDir=join32(GENIE_HOME2,"logs");mkdirSync14(logsDir,{recursive:!0});let generatedAt=new Date().toISOString(),safeStamp=generatedAt.replace(/[:.]/g,"-"),path3=join32(logsDir,`update-diagnostics-${safeStamp}.json`),schedulerLog=join32(logsDir,"scheduler.log"),tuiCrashLog=join32(logsDir,"tui-crash.log"),signals2=summarizeJsonlSignals(schedulerLog),diagnostics={schemaVersion:UPDATE_DIAGNOSTIC_SCHEMA_VERSION,generatedAt,update:ctx,runtime:{platform:process.platform,arch:process.arch,cwd:process.cwd(),node:process.version,bun:(await runCommandSilent("bun",["--version"])).output.trim()||null,npm:(await runCommandSilent("npm",["--version"])).output.trim()||null,genie:{which:(await runCommandSilent("which",["genie"])).output.trim()||null,tuiDisabled:isTruthyEnv(process.env.GENIE_TUI_DISABLE),updateSkipMaintenance:isTruthyEnv(process.env.GENIE_UPDATE_SKIP_MAINTENANCE)}},paths:{genieHome:GENIE_HOME2,logsDir,servePid:safeRead(join32(GENIE_HOME2,"serve.pid"),200),pgservePort:safeRead(join32(GENIE_HOME2,"pgserve.port"),200),schedulerLog,tuiCrashLog},processSnapshot:{genie:safeExec("ps -axo pid,ppid,pgid,stat,pcpu,pmem,etime,command -r | rg -i 'dist/genie.js|/src/genie.ts|pgserve|postgres -D .*\\.genie/data/pgserve|tmux -L genie-tui|bun' || true",2000)||null,tuiTmux:safeExec("tmux -L genie-tui ls 2>/dev/null || true",1000)||null},maintenance:{...maintenance,pgAutostartDisabled:!0,legend:{"[ok]":"healthy","[fix]":"fixed during maintenance","[--]":"skipped/non-blocking","[!!]":"operator action needed; update still completed"}},recentLogSignals:{scheduler:signals2,schedulerTail:tailLines(schedulerLog,32000,80),tuiCrashTail:tailLines(tuiCrashLog,32000,80)}};return writeFileSync12(path3,`${JSON.stringify(diagnostics,null,2)}
|
|
3898
|
+
`}function writeEcosystemConfig(geniePath,databaseUrl){let path2=getEcosystemConfigPath();return ensureLogsDir(),writeFileSync8(path2,buildEcosystemConfigSource(geniePath,databaseUrl),{mode:420}),path2}function buildPm2StartArgs(geniePath,databaseUrl){return["start",writeEcosystemConfig(geniePath,databaseUrl),"--update-env"]}function ensureLogsDir(){let dir=getLogsDir();if(!existsSync21(dir))mkdirSync11(dir,{recursive:!0,mode:493})}async function installCommand(options={}){if(!pm2IsAvailable())fail("pm2 not found in PATH. Install with: bun add -g pm2 (or npm i -g pm2)");let canonicalDatabaseUrl;if(!options.skipPgserve){if(tryPgserveInstall()){let port=tryPgservePort();if(port!==null)canonicalDatabaseUrl=buildGenieDatabaseUrl(port),ok(`canonical pgserve detected; genie-serve will connect to ${canonicalDatabaseUrl}`)}}let existing=pm2GetProcess(PM2_PROCESS_NAME);if(existing){ok(`already installed (pm2 process "${PM2_PROCESS_NAME}", status=${existing.pm2_env?.status??"unknown"}). Use \`pm2 delete genie-serve && genie install\` to refresh the env (e.g. to pick up a new canonical pgserve URL).`);return}ensureLogsDir();let geniePath=resolveGenieBinary(),pm2Args=buildPm2StartArgs(geniePath,canonicalDatabaseUrl),result2=spawnSync2("pm2",pm2Args,{stdio:"inherit"});if(result2.status!==0)fail(`pm2 start failed (exit ${result2.status}). Logs: ${getLogsDir()}/${PM2_PROCESS_NAME}-error.log`);if(ok(`installed: pm2 process "${PM2_PROCESS_NAME}" (logs: ${getLogsDir()})`),canonicalDatabaseUrl)ok(`genie-serve env DATABASE_URL \u2192 ${canonicalDatabaseUrl}`);ok("the genie bridge will now survive shell closure and host reboots (after `pm2 save` + `pm2 startup`).")}init_setup();init_shortcuts();import{existsSync as existsSync24}from"fs";import{homedir as homedir25}from"os";import{join as join30}from"path";async function shortcutsShowCommand(){displayShortcuts();let home=homedir25(),tmuxConf=join30(home,".tmux.conf"),zshrc=join30(home,".zshrc"),bashrc=join30(home,".bashrc");if(console.log("Installation status:"),isShortcutsInstalled(tmuxConf))console.log(" \x1B[32m\u2713\x1B[0m tmux.conf");else console.log(" \x1B[33m-\x1B[0m tmux.conf");let shellRc=existsSync24(zshrc)?zshrc:bashrc;if(isShortcutsInstalled(shellRc))console.log(` \x1B[32m\u2713\x1B[0m ${shellRc.replace(home,"~")}`);else console.log(` \x1B[33m-\x1B[0m ${shellRc.replace(home,"~")}`);console.log(),console.log("Run \x1B[36mgenie shortcuts install\x1B[0m to install shortcuts."),console.log("Run \x1B[36mgenie shortcuts uninstall\x1B[0m to remove shortcuts."),console.log()}async function shortcutsInstallCommand(){await installShortcuts()}async function shortcutsUninstallCommand(){await uninstallShortcuts()}init_esm14();init_claude_settings();init_genie_config2();import{existsSync as existsSync25,lstatSync,rmSync as rmSync2,unlinkSync as unlinkSync8}from"fs";import{homedir as homedir26}from"os";import{join as join31}from"path";var ORCHESTRATION_RULES_PATH=join31(homedir26(),".claude","rules","genie-orchestration.md"),LOCAL_BIN=join31(homedir26(),".local","bin"),SYMLINKS=["genie","term"];function isGenieSymlink(path3){try{if(!existsSync25(path3))return!1;if(!lstatSync(path3).isSymbolicLink())return!1;return!0}catch{return!1}}function removeSymlinks(){let removed=[];for(let name of SYMLINKS){let symlinkPath=join31(LOCAL_BIN,name);if(isGenieSymlink(symlinkPath))try{unlinkSync8(symlinkPath),removed.push(name)}catch{}}return removed}function tryRemoveStep(label,successMsg,fn){console.log(`\x1B[2m${label}\x1B[0m`);try{fn(),console.log(` \x1B[32m+\x1B[0m ${successMsg}`)}catch(error){let message=error instanceof Error?error.message:String(error);console.log(` \x1B[33m!\x1B[0m ${label.replace("...","")} failed: ${message}`)}}function performUninstall(hasHookScript,existingSymlinks,genieDir,hasGenieDir){if(hasHookScript)tryRemoveStep("Removing hook script...","Hook script removed",()=>removeHookScript());if(existingSymlinks.length>0){console.log("\x1B[2mRemoving symlinks...\x1B[0m");let removed=removeSymlinks();if(removed.length>0)console.log(` \x1B[32m+\x1B[0m Removed: ${removed.join(", ")}`)}if(existsSync25(ORCHESTRATION_RULES_PATH))tryRemoveStep("Removing orchestration rules...","Orchestration rules removed (~/.claude/rules/genie-orchestration.md)",()=>unlinkSync8(ORCHESTRATION_RULES_PATH));if(hasGenieDir)tryRemoveStep("Removing genie directory...","Directory removed",()=>rmSync2(genieDir,{recursive:!0,force:!0}))}async function uninstallCommand(){console.log(),console.log("\x1B[1m\x1B[33m Uninstall Genie CLI\x1B[0m"),console.log();let genieDir=getGenieDir(),hasGenieDir=existsSync25(genieDir),hasHookScript=hookScriptExists(),hasOrchestrationRules=existsSync25(ORCHESTRATION_RULES_PATH),existingSymlinks=SYMLINKS.filter((name)=>isGenieSymlink(join31(LOCAL_BIN,name)));if(console.log("\x1B[2mThis will remove:\x1B[0m"),hasHookScript)console.log(" \x1B[31m-\x1B[0m Hook script (~/.claude/hooks/genie-bash-hook.sh)");if(hasOrchestrationRules)console.log(" \x1B[31m-\x1B[0m Orchestration rules (~/.claude/rules/genie-orchestration.md)");if(hasGenieDir)console.log(` \x1B[31m-\x1B[0m Genie directory (${contractPath(genieDir)})`);if(existingSymlinks.length>0)console.log(` \x1B[31m-\x1B[0m Symlinks from ~/.local/bin: ${existingSymlinks.join(", ")}`);if(console.log(),!hasGenieDir&&!hasHookScript&&!hasOrchestrationRules&&existingSymlinks.length===0){console.log("\x1B[33mNothing to uninstall.\x1B[0m"),console.log();return}if(!await esm_default4({message:"Are you sure you want to uninstall Genie CLI?",default:!1})){console.log(),console.log("\x1B[2mUninstall cancelled.\x1B[0m"),console.log();return}console.log(),performUninstall(hasHookScript,existingSymlinks,genieDir,hasGenieDir),console.log(),console.log("\x1B[32m+\x1B[0m Genie CLI uninstalled."),console.log(),console.log("\x1B[2mNote: If you installed via npm/bun, also run:\x1B[0m"),console.log(" \x1B[36mbun remove -g @automagik/genie\x1B[0m"),console.log(" \x1B[2mor\x1B[0m"),console.log(" \x1B[36mnpm uninstall -g @automagik/genie\x1B[0m"),console.log()}init_genie_config2();import{execSync as execSync4,spawn as spawn3}from"child_process";import{chmodSync as chmodSync2,closeSync as closeSync3,copyFileSync as copyFileSync3,existsSync as existsSync26,mkdirSync as mkdirSync14,openSync as openSync3,readFileSync as readFileSync17,readSync as readSync2,readdirSync as readdirSync8,rmSync as rmSync3,statSync as statSync7,writeFileSync as writeFileSync12}from"fs";import{chmod,copyFile,mkdir as mkdir5,unlink as unlink2}from"fs/promises";import{homedir as homedir27}from"os";import{join as join32}from"path";var GENIE_HOME2=process.env.GENIE_HOME||join32(homedir27(),".genie"),GENIE_SRC=join32(GENIE_HOME2,"src"),GENIE_BIN=join32(GENIE_HOME2,"bin"),LOCAL_BIN2=join32(homedir27(),".local","bin"),TRUTHY=new Set(["1","true","yes","on"]),UPDATE_DIAGNOSTIC_SCHEMA_VERSION=1;function log(message){console.log(`\x1B[32m\u25B8\x1B[0m ${message}`)}function success(message){console.log(`\x1B[32m\u2714\x1B[0m ${message}`)}function error(message){console.log(`\x1B[31m\u2716\x1B[0m ${message}`)}function formatDuration2(ms){if(ms<1000)return`${ms}ms`;return`${(ms/1000).toFixed(1)}s`}function isTruthyEnv(value){return value!==void 0&&TRUTHY.has(value.trim().toLowerCase())}async function withTemporaryEnv(key,value,fn){let previous=process.env[key];process.env[key]=value;try{return await fn()}finally{if(previous===void 0)delete process.env[key];else process.env[key]=previous}}function safeExec(command,timeoutMs=1500){try{return execSync4(command,{encoding:"utf-8",stdio:["ignore","pipe","pipe"],timeout:timeoutMs}).trim()}catch(err){let stdout=err.stdout;if(typeof stdout==="string"&&stdout.trim())return stdout.trim();return""}}function safeRead(path3,maxChars=4000){try{let value=readFileSync17(path3,"utf-8");if(value.length<=maxChars)return value;return value.slice(value.length-maxChars)}catch{return null}}function tailLines(path3,maxBytes=64000,maxLines=200){let fd=null;try{let stat4=statSync7(path3),bytesToRead=Math.min(stat4.size,maxBytes),buffer2=Buffer.alloc(bytesToRead);return fd=openSync3(path3,"r"),readSync2(fd,buffer2,0,bytesToRead,Math.max(0,stat4.size-bytesToRead)),buffer2.toString("utf-8").split(/\r?\n/).map((line)=>line.trim()).filter(Boolean).slice(-maxLines)}catch{return[]}finally{if(fd!==null)try{closeSync3(fd)}catch{}}}function summarizeJsonlSignals(path3){let signals2=new Map;for(let line of tailLines(path3))try{let event=JSON.parse(line),level=typeof event.level==="string"?event.level:"unknown";if(level!=="error"&&level!=="warn")continue;let name=typeof event.event==="string"?event.event:"unknown",key=`${level}:${name}`,existing=signals2.get(key)??{level,event:name,count:0};if(existing.count++,typeof event.timestamp==="string")existing.lastTimestamp=event.timestamp;if(typeof event.error==="string")existing.lastError=event.error;signals2.set(key,existing)}catch{}return[...signals2.values()].sort((a,b2)=>b2.count-a.count).slice(0,10)}async function collectUpdateDiagnostics(ctx,maintenance){let logsDir=join32(GENIE_HOME2,"logs");mkdirSync14(logsDir,{recursive:!0});let generatedAt=new Date().toISOString(),safeStamp=generatedAt.replace(/[:.]/g,"-"),path3=join32(logsDir,`update-diagnostics-${safeStamp}.json`),schedulerLog=join32(logsDir,"scheduler.log"),tuiCrashLog=join32(logsDir,"tui-crash.log"),signals2=summarizeJsonlSignals(schedulerLog),diagnostics={schemaVersion:UPDATE_DIAGNOSTIC_SCHEMA_VERSION,generatedAt,update:ctx,runtime:{platform:process.platform,arch:process.arch,cwd:process.cwd(),node:process.version,bun:(await runCommandSilent("bun",["--version"])).output.trim()||null,npm:(await runCommandSilent("npm",["--version"])).output.trim()||null,genie:{which:(await runCommandSilent("which",["genie"])).output.trim()||null,tuiDisabled:isTruthyEnv(process.env.GENIE_TUI_DISABLE),updateSkipMaintenance:isTruthyEnv(process.env.GENIE_UPDATE_SKIP_MAINTENANCE)}},paths:{genieHome:GENIE_HOME2,logsDir,servePid:safeRead(join32(GENIE_HOME2,"serve.pid"),200),pgservePort:safeRead(join32(GENIE_HOME2,"pgserve.port"),200),schedulerLog,tuiCrashLog},processSnapshot:{genie:safeExec("ps -axo pid,ppid,pgid,stat,pcpu,pmem,etime,command -r | rg -i 'dist/genie.js|/src/genie.ts|pgserve|postgres -D .*\\.genie/data/pgserve|tmux -L genie-tui|bun' || true",2000)||null,tuiTmux:safeExec("tmux -L genie-tui ls 2>/dev/null || true",1000)||null},maintenance:{...maintenance,pgAutostartDisabled:!0,legend:{"[ok]":"healthy","[fix]":"fixed during maintenance","[--]":"skipped/non-blocking","[!!]":"operator action needed; update still completed"}},recentLogSignals:{scheduler:signals2,schedulerTail:tailLines(schedulerLog,32000,80),tuiCrashTail:tailLines(tuiCrashLog,32000,80)}};return writeFileSync12(path3,`${JSON.stringify(diagnostics,null,2)}
|
|
3899
3899
|
`),{path:path3,signals:signals2}}async function runCommand(command,args,cwd){return new Promise((resolve4)=>{let output=[],child=spawn3(command,args,{cwd,stdio:["inherit","pipe","pipe"],env:{...process.env,FORCE_COLOR:"1"}});child.stdout?.on("data",(data)=>{let str2=data.toString();output.push(str2),process.stdout.write(str2)}),child.stderr?.on("data",(data)=>{let str2=data.toString();output.push(str2),process.stderr.write(str2)}),child.on("close",(code)=>{resolve4({success:code===0,output:output.join("")})}),child.on("error",(err)=>{error(err.message),resolve4({success:!1,output:err.message})})})}async function getGitInfo(cwd){try{let branchResult=await runCommandSilent("git",["rev-parse","--abbrev-ref","HEAD"],cwd),commitResult=await runCommandSilent("git",["rev-parse","--short","HEAD"],cwd),dateResult=await runCommandSilent("git",["log","-1","--format=%ci"],cwd);if(branchResult.success&&commitResult.success&&dateResult.success)return{branch:branchResult.output.trim(),commit:commitResult.output.trim(),commitDate:dateResult.output.trim().split(" ")[0]}}catch{}return null}async function runCommandSilent(command,args,cwd,timeoutMs=4000){return new Promise((resolve4)=>{let output=[],settled=!1,child=spawn3(command,args,{cwd,stdio:["inherit","pipe","pipe"]}),timer2=setTimeout(()=>{if(settled)return;settled=!0,child.kill("SIGTERM"),resolve4({success:!1,output:`Timed out after ${timeoutMs}ms`})},timeoutMs);child.stdout?.on("data",(data)=>{output.push(data.toString())}),child.stderr?.on("data",(data)=>{output.push(data.toString())}),child.on("close",(code)=>{if(settled)return;settled=!0,clearTimeout(timer2),resolve4({success:code===0,output:output.join("")})}),child.on("error",(err)=>{if(settled)return;settled=!0,clearTimeout(timer2),resolve4({success:!1,output:err.message})})})}function detectFromBinaryPath(path3){let resolved=path3;try{resolved=__require("fs").realpathSync(path3)}catch{}if(resolved.includes(".bun"))return"bun";if(resolved.includes("node_modules"))return"npm";if(path3===join32(LOCAL_BIN2,"genie")||resolved.startsWith(GENIE_BIN))return"source";return null}async function detectInstallationType(){let whichResult=await runCommandSilent("which",["genie"]);if(whichResult.success){let detected=detectFromBinaryPath(whichResult.output.trim());if(detected)return detected}if(genieConfigExists())try{let config=await loadGenieConfig();if(config.installMethod)return config.installMethod}catch{}if(existsSync26(join32(GENIE_SRC,".git")))return"source";return(await runCommandSilent("which",["bun"])).success?"bun":"npm"}async function updateViaBun(channel){try{__require("fs").unlinkSync(join32(homedir27(),".bun","install","global","bun.lock"))}catch{}if(log(`Updating via bun (channel: ${channel})...`),!(await runCommand("bun",["add","-g",`@automagik/genie@${channel}`])).success)return error("Failed to update via bun"),!1;return console.log(),success(`Genie CLI updated via bun (${channel})!`),!0}async function updateViaNpm(channel){if(log(`Updating via npm (channel: ${channel})...`),!(await runCommand("npm",["install","-g",`@automagik/genie@${channel}`])).success)return error("Failed to update via npm"),!1;return console.log(),success(`Genie CLI updated via npm (${channel})!`),!0}async function detectGlobalInstalls(){let found=new Set,[npmResult,bunResult]=await Promise.all([runCommandSilent("npm",["list","-g","@automagik/genie"]),runCommandSilent("bun",["pm","ls","-g"])]);if(npmResult.success&&!npmResult.output.includes("(empty)"))found.add("npm");if(bunResult.success&&bunResult.output.includes("@automagik/genie"))found.add("bun");return found}async function updateSource(){if(!existsSync26(GENIE_SRC))error(`Source install path not found: ${GENIE_SRC}`),console.error(" Detection picked the source-install path, but the directory does not exist."),console.error(" This usually means a stale install hint (config or ~/.genie/src/.git) is"),console.error(" pointing somewhere genuine. Either:"),console.error(` 1. Re-clone the source: git clone https://github.com/automagik-dev/genie ${GENIE_SRC}`),console.error(" 2. Update via package manager instead: genie update --next --via bun"),console.error(" 3. Inspect detection: genie doctor --update-detection"),process.exit(1);if(!existsSync26(join32(GENIE_SRC,".git")))error(`Source install path is not a git checkout: ${GENIE_SRC}`),console.error(` ${GENIE_SRC} exists but has no .git/. Cannot run \`git fetch\` from it.`),console.error(` Either delete ${GENIE_SRC} and re-clone, or update via package manager:`),console.error(" genie update --next --via bun"),process.exit(1);let beforeInfo=await getGitInfo(GENIE_SRC);if(beforeInfo)console.log(`Current: \x1B[2m${beforeInfo.branch}@${beforeInfo.commit} (${beforeInfo.commitDate})\x1B[0m`),console.log();if(log("Fetching latest changes..."),!(await runCommand("git",["fetch","origin"],GENIE_SRC)).success)error("Failed to fetch from origin"),process.exit(1);if(log("Resetting to origin/main..."),!(await runCommand("git",["reset","--hard","origin/main"],GENIE_SRC)).success)error("Failed to reset to origin/main"),process.exit(1);console.log();let afterInfo=await getGitInfo(GENIE_SRC);if(beforeInfo&&afterInfo&&beforeInfo.commit===afterInfo.commit){success("Already up to date!"),console.log();return}if(log("Installing dependencies..."),!(await runCommand("bun",["install"],GENIE_SRC)).success)error("Failed to install dependencies"),process.exit(1);if(console.log(),log("Building..."),!(await runCommand("bun",["run","build"],GENIE_SRC)).success)error("Failed to build"),process.exit(1);console.log(),log("Installing binaries...");try{await mkdir5(GENIE_BIN,{recursive:!0}),await mkdir5(LOCAL_BIN2,{recursive:!0});let binaries=["genie.js","term.js"],names=["genie","term"];for(let i2=0;i2<binaries.length;i2++){let src=join32(GENIE_SRC,"dist",binaries[i2]),binDest=join32(GENIE_BIN,binaries[i2]),linkDest=join32(LOCAL_BIN2,names[i2]);await copyFile(src,binDest),await chmod(binDest,493),await symlinkOrCopy(binDest,linkDest)}for(let legacy of["claudio.js","claudio"]){let legacyBin=join32(GENIE_BIN,legacy),legacyLink=join32(LOCAL_BIN2,legacy);try{await unlink2(legacyBin)}catch{}try{await unlink2(legacyLink)}catch{}}success("Binaries installed")}catch(err){error(`Failed to install binaries: ${err}`),process.exit(1)}if(console.log(),console.log("\x1B[2m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\x1B[0m"),success("Genie CLI updated successfully!"),console.log(),afterInfo)console.log(`Version: \x1B[36m${afterInfo.branch}@${afterInfo.commit}\x1B[0m (${afterInfo.commitDate})`),console.log()}async function symlinkOrCopy(src,dest){let{symlink:symlink2,unlink:unlink3}=await import("fs/promises");try{if(existsSync26(dest))await unlink3(dest);await symlink2(src,dest)}catch{await copyFile(src,dest)}}function copyDirSync(src,dest){mkdirSync14(dest,{recursive:!0});for(let entry2 of readdirSync8(src,{withFileTypes:!0})){let srcPath=join32(src,entry2.name),destPath=join32(dest,entry2.name);if(entry2.isDirectory())copyDirSync(srcPath,destPath);else copyFileSync3(srcPath,destPath)}}async function resolveGlobalPkgDir(installType){if(installType==="bun"){let bunPath=join32(homedir27(),".bun","install","global","node_modules","@automagik","genie");if(existsSync26(bunPath))return bunPath}if(installType==="npm"){let npmRootResult=await runCommandSilent("npm",["root","-g"]);if(npmRootResult.success){let npmPath=join32(npmRootResult.output.trim(),"@automagik","genie");if(existsSync26(npmPath))return npmPath}}let bunFallback=join32(homedir27(),".bun","install","global","node_modules","@automagik","genie");if(existsSync26(bunFallback))return bunFallback;let npmRootFallback=await runCommandSilent("npm",["root","-g"]);if(npmRootFallback.success){let npmPath=join32(npmRootFallback.output.trim(),"@automagik","genie");if(existsSync26(npmPath))return npmPath}return null}function updatePluginRegistry(claudePlugins,cacheDir,version){let registryPath=join32(claudePlugins,"installed_plugins.json");try{if(!existsSync26(registryPath))return;let registry=JSON.parse(readFileSync17(registryPath,"utf-8")),entries=registry.plugins?.["genie@automagik"];if(!Array.isArray(entries))return;for(let entry2 of entries)if(entry2.scope==="user")entry2.installPath=cacheDir,entry2.version=version,entry2.lastUpdated=new Date().toISOString();writeFileSync12(registryPath,JSON.stringify(registry,null,2))}catch(err){log(`Registry update failed (non-fatal): ${err}`)}}function syncTmuxConf(tmuxScriptsSrc){mkdirSync14(GENIE_HOME2,{recursive:!0});let tmuxConfSrc=join32(tmuxScriptsSrc,"genie.tmux.conf"),tmuxConfDest=join32(GENIE_HOME2,"tmux.conf");if(existsSync26(tmuxConfSrc))try{copyFileSync3(tmuxConfSrc,tmuxConfDest),success(`Installed tmux config to ${tmuxConfDest}`);try{let{tmuxBin:tmuxBin2}=(init_ensure_tmux(),__toCommonJS(exports_ensure_tmux));execSync4(`${tmuxBin2()} -L genie source-file '${tmuxConfDest}'`,{stdio:"ignore"}),success("Reloaded genie tmux server configuration")}catch{}}catch{}let tuiConfSrc=join32(tmuxScriptsSrc,"tui-tmux.conf"),tuiConfDest=join32(GENIE_HOME2,"tui-tmux.conf");if(existsSync26(tuiConfSrc))try{copyFileSync3(tuiConfSrc,tuiConfDest),success(`Installed TUI tmux config to ${tuiConfDest}`)}catch{}let themeSrc=join32(tmuxScriptsSrc,".generated.theme.conf"),themeDest=join32(GENIE_HOME2,".generated.theme.conf");if(existsSync26(themeSrc))try{copyFileSync3(themeSrc,themeDest),success(`Installed tmux theme to ${themeDest}`)}catch{}let osc52Src=join32(tmuxScriptsSrc,"osc52-copy.sh"),osc52Dest=join32(GENIE_HOME2,"scripts","osc52-copy.sh");if(existsSync26(osc52Src))try{copyFileSync3(osc52Src,osc52Dest),chmodSync2(osc52Dest,493),success(`Installed OSC 52 clipboard helper to ${osc52Dest}`)}catch{}}function syncTmuxScripts(globalPkgDir){let tmuxScriptsSrc=join32(globalPkgDir,"scripts","tmux");if(!existsSync26(tmuxScriptsSrc))return;let scriptsDir=join32(GENIE_HOME2,"scripts");mkdirSync14(scriptsDir,{recursive:!0});let scriptCount=0;for(let entry2 of readdirSync8(tmuxScriptsSrc))if(entry2.endsWith(".sh")||entry2==="genie.tmux.conf"||entry2==="tui-tmux.conf"||entry2===".generated.theme.conf"){let src=join32(tmuxScriptsSrc,entry2),dest=join32(scriptsDir,entry2);copyFileSync3(src,dest);try{chmodSync2(dest,entry2.endsWith(".sh")?493:420)}catch{}scriptCount++}if(scriptCount>0)success(`Refreshed ${scriptCount} tmux scripts at ${scriptsDir}`);syncTmuxConf(tmuxScriptsSrc)}function syncMarketplaceVersion(claudePlugins,version){let marketplacePath=join32(claudePlugins,"marketplaces","automagik",".claude-plugin","marketplace.json");try{if(!existsSync26(marketplacePath))return;let data=JSON.parse(readFileSync17(marketplacePath,"utf-8"));if(Array.isArray(data.plugins)){for(let plugin of data.plugins)if(plugin.name==="genie")plugin.version=version}writeFileSync12(marketplacePath,JSON.stringify(data,null,2)),success(`Updated marketplace.json to v${version}`)}catch(err){log(`Marketplace version update failed (non-fatal): ${err}`)}}function syncPluginPackageVersion(claudePlugins,version){let pkgPath=join32(claudePlugins,"marketplaces","automagik","plugins","genie","package.json");try{if(!existsSync26(pkgPath))return;let data=JSON.parse(readFileSync17(pkgPath,"utf-8"));data.version=version,writeFileSync12(pkgPath,JSON.stringify(data,null,2)),success(`Updated plugin package.json to v${version}`)}catch(err){log(`Plugin package.json update failed (non-fatal): ${err}`)}}function syncSkillsSymlink(claudePlugins,version){let skillsLink=join32(claudePlugins,"marketplaces","automagik","plugins","genie","skills"),cacheSkills=join32("..","..","..","..","cache","automagik","genie",version,"skills");try{let{symlinkSync,unlinkSync:unlinkSync9,lstatSync:lstatSync2}=__require("fs");try{lstatSync2(skillsLink),unlinkSync9(skillsLink)}catch{}symlinkSync(cacheSkills,skillsLink),success(`Skills symlink \u2192 cache/${version}/skills`)}catch(err){log(`Skills symlink update failed (non-fatal): ${err}`)}}async function syncPlugin(installType){log("Syncing Claude Code plugin...");let globalPkgDir=await resolveGlobalPkgDir(installType);if(!globalPkgDir)return log("Could not find installed package \u2014 skipping plugin sync"),{skippedReason:"installed package not found"};let pluginSrc=join32(globalPkgDir,"plugins","genie");if(!existsSync26(pluginSrc))return log("Plugin source not found in package \u2014 skipping plugin sync"),{globalPkgDir,skippedReason:"plugin source not found in package"};let version;try{version=JSON.parse(readFileSync17(join32(globalPkgDir,"package.json"),"utf-8")).version}catch{return log("Could not read package version \u2014 skipping plugin sync"),{globalPkgDir,skippedReason:"could not read package version"}}let claudePlugins=join32(homedir27(),".claude","plugins"),cacheDir=join32(claudePlugins,"cache","automagik","genie",version);try{if(existsSync26(cacheDir))rmSync3(cacheDir,{recursive:!0,force:!0});copyDirSync(pluginSrc,cacheDir);let skillsSrc=join32(globalPkgDir,"skills");if(existsSync26(skillsSrc)&&!existsSync26(join32(cacheDir,"skills")))copyDirSync(skillsSrc,join32(cacheDir,"skills"))}catch(err){return error(`Failed to copy plugin: ${err}`),{version,globalPkgDir,cacheDir,skippedReason:`failed to copy plugin: ${err}`}}return updatePluginRegistry(claudePlugins,cacheDir,version),syncMarketplaceVersion(claudePlugins,version),syncPluginPackageVersion(claudePlugins,version),syncSkillsSymlink(claudePlugins,version),syncTmuxScripts(globalPkgDir),success(`Plugin synced to v${version}`),{version,globalPkgDir,cacheDir}}async function resolveChannel(options){if(options.next)return"next";if(options.stable)return"latest";if(genieConfigExists())try{let config=await loadGenieConfig();if(config.updateChannel)return config.updateChannel}catch{}return"latest"}async function persistChannel(channel){try{let config=await loadGenieConfig();config.updateChannel=channel,await saveGenieConfig(config)}catch{}}async function updateCommand(options={}){console.log(),console.log("\x1B[1m\uD83E\uDDDE Genie CLI Update\x1B[0m"),console.log("\x1B[2m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\x1B[0m"),console.log();let channel=await resolveChannel(options);if(options.next||options.stable)await persistChannel(channel);let installType=await detectInstallationType();if(log(`Detected installation: ${installType}`),log(`Channel: ${channel}${channel==="next"?" (dev builds)":" (stable)"}`),console.log(),installType==="unknown")error("No Genie CLI installation found"),console.log(),console.log("Install method not configured. Please reinstall genie:"),console.log("\x1B[36m curl -fsSL https://raw.githubusercontent.com/automagik-dev/genie/main/install.sh | bash\x1B[0m"),console.log(),process.exit(1);if(installType==="source"){await updateSource();return}let globalInstalls=await detectGlobalInstalls(),primaryMethod=installType;if(!(primaryMethod==="bun"?await updateViaBun(channel):await updateViaNpm(channel)))process.exit(1);let secondaryMethod=primaryMethod==="bun"?"npm":"bun";if(globalInstalls.has(secondaryMethod)){if(console.log(),log(`Also updating ${secondaryMethod}-global install...`),!(secondaryMethod==="bun"?await updateViaBun(channel):await updateViaNpm(channel)))error(`Secondary update via ${secondaryMethod} failed (non-blocking)`)}let plugin=await syncPlugin(installType);await runPostUpdateMaintenanceSafe(options,{channel,installType,primaryMethod,globalInstalls:[...globalInstalls].sort(),plugin})}function printPostUpdateMaintenanceIntro(){console.log(),log("Running post-update maintenance..."),console.log(" Purpose: make first launch after update fast and collect upgrade health signals."),console.log(" Checks: runtime partitions, watchdog status, session backfill drift, zombie rows, team config orphans."),console.log(" PG policy: read-only; uses an already-running pgserve when available and will not auto-start it."),console.log(" Legend: [ok]=healthy, [fix]=fixed, [--]=skipped/non-blocking, [!!]=operator action needed.")}async function runMaintenanceWithCapturedLines(maintenanceLines){let{runPostUpdateMaintenance:runPostUpdateMaintenance2}=await Promise.resolve().then(() => (init_doctor(),exports_doctor));await withTemporaryEnv("GENIE_PG_NO_AUTOSTART","1",()=>runPostUpdateMaintenance2({log:(line)=>{maintenanceLines.push(line),console.log(line)}}))}function printDiagnosticsSummary(diagnostics){if(log("Post-update diagnostics captured."),console.log(` Report: ${diagnostics.path}`),console.log(" Include this file when opening a GitHub issue; it contains install metadata, step output,"),console.log(" local process state, and recent scheduler/TUI log signals."),diagnostics.signals.length===0)return;console.log(" Recent scheduler signals:");for(let signal of diagnostics.signals.slice(0,3)){let errorDetail=signal.lastError?` \u2014 ${signal.lastError}`:"";console.log(` ${signal.level}:${signal.event} \xD7${signal.count}${errorDetail}`)}}async function capturePostUpdateDiagnostics(diagnosticsCtx,maintenance){if(!diagnosticsCtx)return;try{let diagnostics=await collectUpdateDiagnostics(diagnosticsCtx,maintenance);printDiagnosticsSummary(diagnostics)}catch(err){let msg=err instanceof Error?err.message:String(err);log(`Post-update diagnostics capture failed (non-fatal): ${msg}`)}}async function runPostUpdateMaintenanceSafe(options={},diagnosticsCtx){if(options.skipMaintenance||isTruthyEnv(process.env.GENIE_UPDATE_SKIP_MAINTENANCE)){log("Skipping post-update maintenance (requested).");return}let startedAt=Date.now(),maintenanceLines=[],outcome="completed",maintenanceError;try{printPostUpdateMaintenanceIntro(),await runMaintenanceWithCapturedLines(maintenanceLines),success(`Post-update maintenance complete (${formatDuration2(Date.now()-startedAt)}).`)}catch(err){outcome="failed",maintenanceError=err instanceof Error?err.message:String(err),error(`Post-update maintenance skipped: ${maintenanceError}`)}await capturePostUpdateDiagnostics(diagnosticsCtx,{outcome,durationMs:Date.now()-startedAt,lines:maintenanceLines,error:maintenanceError})}init_version();init_trust();init_trust();init_trust();import{execSync as execSync5}from"child_process";import{existsSync as existsSync29,mkdirSync as mkdirSync15,readFileSync as readFileSync20,renameSync as renameSync5,writeFileSync as writeFileSync13}from"fs";import{dirname as dirname10,isAbsolute,join as join34,resolve as resolve5}from"path";function resolveOriginUrl(repoRoot){try{return execSync5("git config --get remote.origin.url",{cwd:repoRoot,encoding:"utf-8"}).trim()||null}catch{return null}}function findRepoRoot(start){let current=start;while(current!=="/"){if(existsSync29(join34(current,".git")))return current;current=dirname10(current)}return null}function writeTrustFile(path3,file){let dir=dirname10(path3);if(!existsSync29(dir))mkdirSync15(dir,{recursive:!0});let sorted={version:1,entries:[...file.entries].sort((a,b2)=>a.path.localeCompare(b2.path))},serialized=`${JSON.stringify(sorted,null,2)}
|
|
3900
3900
|
`,tmpPath=`${path3}.tmp.${process.pid}`;writeFileSync13(tmpPath,serialized,"utf-8"),renameSync5(tmpPath,path3)}async function trustAction(target,options){let trustPath=defaultTrustPath();if(!target){let current2=readTrustFile(trustPath);if(current2.entries.length===0){console.log(`(trust file empty: ${trustPath})`);return}console.log(`Trusted hooks (${current2.entries.length}, from ${trustPath}):`);for(let entry2 of current2.entries){let scope2=entry2.scope==="repo"?`repo:${entry2.repoRemoteUrl??"?"}`:entry2.scope;if(console.log(` ${entry2.path}`),console.log(` scope: ${scope2}`),console.log(` sha256: ${entry2.sha256}`),console.log(` trusted: ${entry2.trustedAt}`),entry2.capabilities&&entry2.capabilities.length>0)console.log(` caps: ${entry2.capabilities.join(", ")}`);if(entry2.note)console.log(` note: ${entry2.note}`)}return}let filePath=isAbsolute(target)?target:resolve5(process.cwd(),target);if(!existsSync29(filePath))console.error(`Error: file not found: ${filePath}`),process.exit(1);if(!filePath.endsWith(".ts"))console.error(`Error: trust target must be a .ts file: ${filePath}`),process.exit(1);let scope,repoRemoteUrl;if(options.repo){scope="repo";let repoRoot=findRepoRoot(dirname10(filePath));if(!repoRoot)console.error(`Error: --repo passed but no .git directory found above ${filePath}`),process.exit(1);let remote=resolveOriginUrl(repoRoot);if(!remote)console.error(`Error: --repo passed but ${repoRoot} has no remote.origin.url`),process.exit(1);repoRemoteUrl=remote}else if(options.team)scope="team";else scope="global";let sha=sha256OfFile(filePath),source=readFileSync20(filePath,"utf-8"),capabilities=parseCapabilities(source);if(console.log(`About to trust: ${filePath}`),console.log(` scope: ${scope==="repo"?`repo:${repoRemoteUrl}`:scope}`),console.log(` sha256: ${sha}`),capabilities.length>0)console.log(` caps: ${capabilities.join(", ")}`);if(options.note)console.log(` note: ${options.note}`);if(!options.yes&&process.stdin.isTTY){process.stdout.write("Confirm? (y/N) ");let buf=Buffer.alloc(8),read=0;try{read=(await import("fs")).readSync(0,buf,0,buf.length,null)}catch{console.error("Error: cannot read confirmation; pass --yes to trust non-interactively"),process.exit(1)}let answer=buf.subarray(0,read).toString().trim().toLowerCase();if(answer!=="y"&&answer!=="yes")console.log("Aborted."),process.exit(1)}let current=readTrustFile(trustPath),newEntry={path:filePath,sha256:sha,scope,repoRemoteUrl,trustedAt:new Date().toISOString(),note:options.note,capabilities:capabilities.length>0?capabilities:void 0},next={version:1,entries:[...current.entries.filter((e)=>e.path!==filePath),newEntry]};writeTrustFile(trustPath,next),console.log(`Trusted ${filePath} \u2192 ${trustPath}`)}function registerHookTrustCommand(parent){parent.command("trust [path]").description("Add a .ts hook file to the trust allowlist (or list current entries when [path] is omitted)").option("--repo","Scope to current repo (pinned to remote.origin.url)").option("--global","Scope globally (default)").option("--team <name>","Scope to a specific team directory").option("--note <text>","Free-form note saved with the entry").option("--yes","Skip the interactive confirmation prompt").action(trustAction)}import{appendFileSync as appendFileSync3,mkdirSync as mkdirSync16,statSync as statSync8}from"fs";import{connect as connect2}from"net";import{homedir as homedir29}from"os";import{dirname as dirname11,join as join35}from"path";function defaultSocketPath(){if(process.env.GENIE_HOOK_SOCK)return process.env.GENIE_HOOK_SOCK;let home=process.env.GENIE_HOME??join35(homedir29(),".genie");return join35(home,"hook.sock")}function fallbackLogPath2(){let home=process.env.GENIE_HOME??join35(homedir29(),".genie");return join35(home,"hook-fallback.log")}var MAX_FRAME_BYTES=1048576,FALLBACK_LOG_MAX_BYTES=104857600,DEFAULT_TIMEOUT_MS=5000;function readStdinSync(){let chunks=[],total=0,fd=0,buf=Buffer.alloc(65536);while(!0){let n;try{n=__require("fs").readSync(fd,buf,0,buf.length,null)}catch{break}if(n===0)break;if(chunks.push(Buffer.from(buf.subarray(0,n))),total+=n,total>MAX_FRAME_BYTES)break}return Buffer.concat(chunks,Math.min(total,MAX_FRAME_BYTES))}function summarizePayload(payload){try{let obj=JSON.parse(payload.toString("utf-8")),event=typeof obj.hook_event_name==="string"?obj.hook_event_name:null,tool=typeof obj.tool_name==="string"?obj.tool_name:null,command=null,ti=obj.tool_input;if(ti&&typeof ti.command==="string")command=ti.command.split(`
|
|
3901
3901
|
`)[0].slice(0,256);return{event,tool,command}}catch{return{event:null,tool:null,command:null}}}function appendFallback(record){let path3=fallbackLogPath2();try{mkdirSync16(dirname11(path3),{recursive:!0});let writeFresh=!1;try{if(statSync8(path3).size>=FALLBACK_LOG_MAX_BYTES)writeFresh=!0}catch{}let line=`${JSON.stringify(record)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automagik/genie",
|
|
3
|
-
"version": "4.260501.
|
|
3
|
+
"version": "4.260501.3",
|
|
4
4
|
"description": "Collaborative terminal toolkit for human + AI workflows. NOTE: the npm distribution is being soft-deprecated — the canonical install is `curl -fsSL https://get.automagik.dev/genie | bash` (cosign + SLSA verified). See https://automagik.dev/genie/security/distribution-sovereignty",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "genie",
|
|
3
|
-
"version": "4.260501.
|
|
3
|
+
"version": "4.260501.3",
|
|
4
4
|
"description": "Human-AI partnership for Claude Code. Share a terminal, orchestrate workers, evolve together. Brainstorm ideas, turn them into wishes, execute with /work, validate with /review, and ship as one team.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Namastex Labs"
|