@askexenow/exe-os 0.9.300 → 0.9.301
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/deploy/compose/erp-nginx/nginx.conf +6 -3
- package/dist/active-agent-UNJO6AJ2.js +27 -0
- package/dist/active-agent-Y5LSIMVC.js +28 -0
- package/dist/agentic-ontology-QEV7GI3T.js +25 -0
- package/dist/backfill-metadata-RQZ4BN7G.js +600 -0
- package/dist/behaviors-A3L5CWMK.js +46 -0
- package/dist/bin/agentic-ontology-backfill.js +5 -5
- package/dist/bin/agentic-reflection-backfill.js +6 -6
- package/dist/bin/agentic-semantic-label.js +5 -5
- package/dist/bin/backfill-conversations.js +4 -4
- package/dist/bin/backfill-responses.js +4 -4
- package/dist/bin/backfill-vectors.js +5 -5
- package/dist/bin/bulk-sync-postgres.js +7 -7
- package/dist/bin/cc-doctor.js +4 -4
- package/dist/bin/cleanup-stale-review-tasks.js +9 -9
- package/dist/bin/cli.js +15 -15
- package/dist/bin/exe-agent-config.js +2 -2
- package/dist/bin/exe-agent.js +4 -4
- package/dist/bin/exe-assign.js +5 -5
- package/dist/bin/exe-boot.js +23 -18
- package/dist/bin/exe-call.js +4 -4
- package/dist/bin/exe-cloud.js +7 -7
- package/dist/bin/exe-dispatch.js +9 -9
- package/dist/bin/exe-doctor.js +2 -2
- package/dist/bin/exe-export-behaviors.js +7 -7
- package/dist/bin/exe-forget.js +6 -6
- package/dist/bin/exe-gateway.js +7 -7
- package/dist/bin/exe-healthcheck.js +4 -4
- package/dist/bin/exe-heartbeat.js +9 -9
- package/dist/bin/exe-kill.js +12 -12
- package/dist/bin/exe-launch-agent.js +16 -16
- package/dist/bin/exe-new-employee.js +6 -6
- package/dist/bin/exe-pending-messages.js +10 -10
- package/dist/bin/exe-pending-notifications.js +9 -9
- package/dist/bin/exe-pending-reviews.js +9 -9
- package/dist/bin/exe-rename.js +4 -4
- package/dist/bin/exe-review.js +11 -11
- package/dist/bin/exe-search.js +5 -5
- package/dist/bin/exe-session-cleanup.js +14 -14
- package/dist/bin/exe-settings.js +7 -7
- package/dist/bin/exe-start-codex.js +11 -11
- package/dist/bin/exe-start-opencode.js +8 -8
- package/dist/bin/exe-status.js +10 -10
- package/dist/bin/exe-team.js +3 -3
- package/dist/bin/exe-watchdog.js +3 -3
- package/dist/bin/git-sweep.js +10 -10
- package/dist/bin/graph-backfill.js +4 -4
- package/dist/bin/graph-export.js +5 -5
- package/dist/bin/import-history.js +7 -7
- package/dist/bin/install.js +6 -6
- package/dist/bin/intercom-check.js +4 -4
- package/dist/bin/mcp-sessions.js +2 -2
- package/dist/bin/orchestration-metrics.js +4 -4
- package/dist/bin/postgres-agentic-reflection-backfill.js +2 -2
- package/dist/bin/postgres-agentic-semantic-backfill.js +1 -1
- package/dist/bin/scan-tasks.js +9 -9
- package/dist/bin/setup.js +1 -1
- package/dist/bin/shard-migrate.js +4 -4
- package/dist/capability-cards-VTGDTOZ4.js +89 -0
- package/dist/capacity-monitor-G2MAJPRP.js +51 -0
- package/dist/catchup-brief-VBGEJQRS.js +175 -0
- package/dist/chunk-24JVDLQJ.js +345 -0
- package/dist/chunk-2T3OYZMR.js +1158 -0
- package/dist/chunk-3ABY3QDX.js +199 -0
- package/dist/chunk-3G3ECFB5.js +668 -0
- package/dist/chunk-3LHOFGHT.js +280 -0
- package/dist/chunk-3RA62PNQ.js +58 -0
- package/dist/chunk-3XRS5AVV.js +567 -0
- package/dist/chunk-3YK7X5FD.js +1186 -0
- package/dist/chunk-4L6PVYFE.js +54 -0
- package/dist/chunk-4O67LBMK.js +377 -0
- package/dist/chunk-4OIU3N6U.js +167 -0
- package/dist/chunk-5SYYMNPE.js +30 -0
- package/dist/chunk-5TO5PH7O.js +304 -0
- package/dist/chunk-5XD2Y463.js +402 -0
- package/dist/chunk-63AENHJC.js +123 -0
- package/dist/chunk-673IFJYB.js +731 -0
- package/dist/chunk-7AWH47AR.js +448 -0
- package/dist/chunk-7P4B6AEP.js +227 -0
- package/dist/chunk-7VHOALNC.js +244 -0
- package/dist/chunk-ASJHCAVL.js +38 -0
- package/dist/chunk-DICIFTCS.js +150 -0
- package/dist/chunk-DIFI5JDC.js +76 -0
- package/dist/chunk-DPOIJ5SM.js +284 -0
- package/dist/chunk-FAZNXNA5.js +33 -0
- package/dist/chunk-FCHG5RC4.js +197 -0
- package/dist/chunk-FFKSPZO2.js +157 -0
- package/dist/chunk-FNHYH5U6.js +331 -0
- package/dist/chunk-FWPDAQ6Q.js +1350 -0
- package/dist/chunk-FZB73QOI.js +210 -0
- package/dist/chunk-GJBR6QLD.js +630 -0
- package/dist/chunk-GRSYAHKI.js +535 -0
- package/dist/chunk-J5HFRVNW.js +362 -0
- package/dist/chunk-J6SD7LT2.js +171 -0
- package/dist/chunk-JURL2S27.js +128 -0
- package/dist/chunk-KPUYYOFS.js +122 -0
- package/dist/chunk-LAFARYU5.js +456 -0
- package/dist/chunk-LSDXEHKL.js +381 -0
- package/dist/chunk-MS2EOZJQ.js +290 -0
- package/dist/chunk-MUIMJGSQ.js +128 -0
- package/dist/chunk-NJMPNYBS.js +427 -0
- package/dist/chunk-OJACH2JF.js +128 -0
- package/dist/chunk-OO4IFABD.js +382 -0
- package/dist/chunk-Q65NCNL4.js +1352 -0
- package/dist/chunk-QIGS2LRT.js +735 -0
- package/dist/chunk-S73ZAJ2S.js +262 -0
- package/dist/chunk-SJ4UF7YK.js +1094 -0
- package/dist/chunk-SOZ7D77I.js +204 -0
- package/dist/chunk-TDX2LK2M.js +240 -0
- package/dist/chunk-U5RKGLV6.js +50 -0
- package/dist/chunk-UFGTHBHP.js +127 -0
- package/dist/chunk-ULCYWCPI.js +1079 -0
- package/dist/chunk-V6LOEOXG.js +3372 -0
- package/dist/chunk-VAZOVAW4.js +2162 -0
- package/dist/chunk-VEUQVKKT.js +185 -0
- package/dist/chunk-VIDDJ5RF.js +214 -0
- package/dist/chunk-VNB4ROYG.js +348 -0
- package/dist/chunk-VWUQFZFB.js +395 -0
- package/dist/chunk-W77GRCNA.js +85 -0
- package/dist/chunk-WVMG4ZRH.js +14597 -0
- package/dist/chunk-WYVOTRRZ.js +129 -0
- package/dist/chunk-XQQ7D4I4.js +85 -0
- package/dist/chunk-YHJPTIPR.js +836 -0
- package/dist/chunk-YLKS7KKC.js +2145 -0
- package/dist/chunk-YU3KEVCO.js +333 -0
- package/dist/chunk-ZDPU3JTF.js +221 -0
- package/dist/chunk-ZDY4LYAJ.js +81 -0
- package/dist/chunk-ZG33AACD.js +70 -0
- package/dist/chunk-ZKHPZ6KN.js +181 -0
- package/dist/chunk-ZO2TM5N5.js +97 -0
- package/dist/chunk-ZSUACDQC.js +4388 -0
- package/dist/co-activation-XM25BLZM.js +74 -0
- package/dist/co-occurrence-CKEMDPWO.js +95 -0
- package/dist/core-memory-ZDA76EU3.js +110 -0
- package/dist/crdt-sync-BJKZB6T6.js +33 -0
- package/dist/crm-webhook-E5PAFAUN.js +10 -0
- package/dist/cto-delegation-gate-EMY6ZZ2F.js +280 -0
- package/dist/daemon-orchestration-Y5Y6YNE3.js +143 -0
- package/dist/db-backup-HFJ53IBU.js +43 -0
- package/dist/doc-graph-extractor-ID45AQ2P.js +133 -0
- package/dist/dreaming-N6B7KBIE.js +34 -0
- package/dist/exe-drift-CPUEAPIU.js +70 -0
- package/dist/exe-export-4RTGDV53.js +77 -0
- package/dist/exe-import-AZMIF34Z.js +80 -0
- package/dist/exe-key-LJV23AJI.js +673 -0
- package/dist/exe-snapshot-ZOZBW7V6.js +338 -0
- package/dist/fast-db-init-ATRZGHOL.js +7 -0
- package/dist/gateway/index.js +8 -8
- package/dist/git-staleness-XNOKI4D3.js +112 -0
- package/dist/git-task-sweep-3MO4OVND.js +42 -0
- package/dist/global-procedures-EBAPPWGZ.js +22 -0
- package/dist/graph-auto-extract-VJOUQBPK.js +183 -0
- package/dist/hooks/bug-report-worker.js +11 -11
- package/dist/hooks/codex-stop-task-finalizer.js +11 -11
- package/dist/hooks/commit-complete.js +11 -11
- package/dist/hooks/error-recall.js +6 -6
- package/dist/hooks/exe-heartbeat-hook.js +3 -3
- package/dist/hooks/ingest.js +6 -6
- package/dist/hooks/instructions-loaded.js +4 -4
- package/dist/hooks/manifest.json +19 -19
- package/dist/hooks/notification.js +4 -4
- package/dist/hooks/post-compact.js +11 -11
- package/dist/hooks/post-tool-combined.js +5 -5
- package/dist/hooks/pre-compact.js +12 -12
- package/dist/hooks/pre-tool-use.js +14 -14
- package/dist/hooks/prompt-submit.js +26 -24
- package/dist/hooks/session-end.js +15 -15
- package/dist/hooks/session-start.js +12 -12
- package/dist/hooks/stop.js +14 -14
- package/dist/hooks/subagent-stop.js +10 -10
- package/dist/hooks/summary-worker.js +14 -14
- package/dist/index.js +17 -17
- package/dist/installer-37KFNAWE.js +344 -0
- package/dist/installer-F55NR4E2.js +298 -0
- package/dist/installer-KOYBUS4J.js +40 -0
- package/dist/lib/cloud-sync.js +7 -7
- package/dist/lib/consolidation.js +5 -5
- package/dist/lib/database.js +2 -2
- package/dist/lib/db.js +2 -2
- package/dist/lib/employee-templates.js +4 -4
- package/dist/lib/employees.js +2 -2
- package/dist/lib/exe-daemon.js +40 -40
- package/dist/lib/hybrid-search.js +5 -5
- package/dist/lib/identity.js +2 -2
- package/dist/lib/messaging.js +9 -9
- package/dist/lib/reminders.js +3 -3
- package/dist/lib/schedules.js +5 -5
- package/dist/lib/session-registry.js +4 -4
- package/dist/lib/skill-learning.js +6 -6
- package/dist/lib/store.js +4 -4
- package/dist/lib/task-router.js +3 -3
- package/dist/lib/tasks.js +10 -10
- package/dist/lib/tmux-routing.js +8 -8
- package/dist/lib/token-spend.js +3 -3
- package/dist/mcp/register-tools.js +54 -54
- package/dist/mcp/server.js +55 -55
- package/dist/mcp/tools/complete-reminder.js +4 -4
- package/dist/mcp/tools/create-reminder.js +4 -4
- package/dist/mcp/tools/create-task.js +12 -12
- package/dist/mcp/tools/deactivate-behavior.js +7 -7
- package/dist/mcp/tools/list-reminders.js +4 -4
- package/dist/mcp/tools/list-tasks.js +12 -12
- package/dist/mcp/tools/send-message.js +11 -11
- package/dist/mcp/tools/update-task.js +11 -11
- package/dist/mcp-http-config-7KJZI7UD.js +31 -0
- package/dist/memory-cards-ZIT7ZKL5.js +180 -0
- package/dist/memory-graph-extractor-LY2VORZT.js +22 -0
- package/dist/memory-poisoning-defense-SEM25TY5.js +224 -0
- package/dist/memory-reflection-J2W7CJ7C.js +244 -0
- package/dist/notifications-RLMSI4YE.js +47 -0
- package/dist/orchestration-events-TGQYA72K.js +27 -0
- package/dist/orchestrator-JQD5G3CW.js +35 -0
- package/dist/pipeline-router-3Q3YBYSM.js +15 -0
- package/dist/plan-limits-YGXTYCW4.js +28 -0
- package/dist/project-boot-TDOZKKDR.js +299 -0
- package/dist/projection-worker-TMKUSVGD.js +1084 -0
- package/dist/prospective-memory-CNJDBNWF.js +232 -0
- package/dist/reranker-YQIRNGDM.js +19 -0
- package/dist/retrieval-health-M5BVB7EV.js +12 -0
- package/dist/review-polling-ZMB3OBPC.js +126 -0
- package/dist/runtime/index.js +11 -11
- package/dist/session-events-UTMCKDIN.js +38 -0
- package/dist/session-kill-telemetry-FRQA5MVD.js +31 -0
- package/dist/session-scope-2BD6QLNI.js +88 -0
- package/dist/setup-wizard-W64I6SHC.js +12 -0
- package/dist/skill-refinement-FXCXTUS2.js +159 -0
- package/dist/steward-gate-JDR3SLH3.js +15 -0
- package/dist/task-enforcement-WCEA4FZI.js +506 -0
- package/dist/task-scope-L5GDL2AV.js +37 -0
- package/dist/tasks-crud-S36AFYYM.js +79 -0
- package/dist/tasks-notify-W2W2BJRB.js +40 -0
- package/dist/tasks-review-34WV7BX2.js +49 -0
- package/dist/telemetry-upload-3CSVO3J7.js +741 -0
- package/dist/token-budget-ZG2MQ5GD.js +86 -0
- package/dist/tool-telemetry-ODL4F2CW.js +17 -0
- package/dist/tui/App.js +16 -16
- package/dist/tui-data-Z5UF7KEI.js +260 -0
- package/dist/wiki-acl-SZFHCEC4.js +111 -0
- package/dist/worker-gate-OOO6BWZ6.js +21 -0
- package/dist/workflow-engine-QY3IFFR2.js +28 -0
- package/dist/worktree-CNOQZBNT.js +28 -0
- package/dist/worktree-sweep-SE7ITXC4.js +21 -0
- package/package.json +1 -1
- package/release-notes.json +88 -88
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadEmployeesSync
|
|
3
|
+
} from "./chunk-V6LOEOXG.js";
|
|
4
|
+
|
|
5
|
+
// src/adapters/mcp-http-config.ts
|
|
6
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
7
|
+
import { randomBytes } from "crypto";
|
|
8
|
+
import { execFileSync } from "child_process";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import os from "os";
|
|
11
|
+
var DEFAULT_MCP_HTTP_PORT = "48739";
|
|
12
|
+
function resolveDefaultAgentId() {
|
|
13
|
+
if (process.env.AGENT_ID && process.env.AGENT_ID !== "default") return process.env.AGENT_ID;
|
|
14
|
+
try {
|
|
15
|
+
const coo = loadEmployeesSync().find((e) => e.role === "COO");
|
|
16
|
+
if (coo) return coo.name;
|
|
17
|
+
} catch {
|
|
18
|
+
}
|
|
19
|
+
return "exe";
|
|
20
|
+
}
|
|
21
|
+
var DEFAULT_MCP_HTTP_AGENT_ID = resolveDefaultAgentId();
|
|
22
|
+
var DEFAULT_MCP_HTTP_AGENT_ROLE = "COO";
|
|
23
|
+
function sanitizePort(raw) {
|
|
24
|
+
const v = raw?.trim();
|
|
25
|
+
if (!v) return null;
|
|
26
|
+
if (!/^\d+$/.test(v)) return null;
|
|
27
|
+
const port = Number(v);
|
|
28
|
+
if (!Number.isInteger(port) || port <= 0 || port > 65535) return null;
|
|
29
|
+
return v;
|
|
30
|
+
}
|
|
31
|
+
function configMcpPort(homeDir = os.homedir()) {
|
|
32
|
+
try {
|
|
33
|
+
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? path.join(homeDir, ".exe-os");
|
|
34
|
+
const configPath = path.join(dir, "config.json");
|
|
35
|
+
if (!existsSync(configPath)) return null;
|
|
36
|
+
const cfg = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
37
|
+
const candidate = cfg.mcpPort ?? cfg.fixedMcpPort;
|
|
38
|
+
if (candidate == null) return null;
|
|
39
|
+
return sanitizePort(String(candidate));
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function mcpHttpPort(homeDir = os.homedir()) {
|
|
45
|
+
return sanitizePort(process.env.EXE_MCP_PORT) ?? configMcpPort(homeDir) ?? DEFAULT_MCP_HTTP_PORT;
|
|
46
|
+
}
|
|
47
|
+
function mcpHttpUrl(homeDir = os.homedir()) {
|
|
48
|
+
return `http://127.0.0.1:${mcpHttpPort(homeDir)}/mcp`;
|
|
49
|
+
}
|
|
50
|
+
function persistMcpPortToConfig(port = DEFAULT_MCP_HTTP_PORT, homeDir = os.homedir()) {
|
|
51
|
+
try {
|
|
52
|
+
if (!sanitizePort(port)) return;
|
|
53
|
+
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? path.join(homeDir, ".exe-os");
|
|
54
|
+
const configPath = path.join(dir, "config.json");
|
|
55
|
+
if (!existsSync(configPath)) return;
|
|
56
|
+
const cfg = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
57
|
+
if (cfg.mcpPort === port) return;
|
|
58
|
+
cfg.mcpPort = port;
|
|
59
|
+
writeFileSync(configPath, `${JSON.stringify(cfg, null, 2)}
|
|
60
|
+
`, "utf-8");
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function readOrCreateDaemonToken(homeDir = os.homedir()) {
|
|
65
|
+
const exeDir = path.join(homeDir, ".exe-os");
|
|
66
|
+
const tokenPath = path.join(exeDir, "exed.token");
|
|
67
|
+
if (existsSync(tokenPath)) {
|
|
68
|
+
try {
|
|
69
|
+
const token2 = readFileSync(tokenPath, "utf-8").trim();
|
|
70
|
+
if (/^[a-f0-9]{64}$/i.test(token2)) return token2;
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const token = randomBytes(32).toString("hex");
|
|
75
|
+
mkdirSync(exeDir, { recursive: true });
|
|
76
|
+
writeFileSync(tokenPath, `${token}
|
|
77
|
+
`, "utf-8");
|
|
78
|
+
try {
|
|
79
|
+
chmodSync(tokenPath, 384);
|
|
80
|
+
} catch {
|
|
81
|
+
}
|
|
82
|
+
return token;
|
|
83
|
+
}
|
|
84
|
+
function buildMcpHttpHeaders(homeDir = os.homedir(), opts = {}) {
|
|
85
|
+
const agentId = opts.useShellPlaceholders ? "${AGENT_ID:-exe}" : opts.agentId ?? DEFAULT_MCP_HTTP_AGENT_ID;
|
|
86
|
+
const agentRole = opts.useShellPlaceholders ? "${AGENT_ROLE:-COO}" : opts.agentRole ?? DEFAULT_MCP_HTTP_AGENT_ROLE;
|
|
87
|
+
let sessionName = process.env.EXE_SESSION_NAME ?? "";
|
|
88
|
+
if (!sessionName && !opts.useShellPlaceholders) {
|
|
89
|
+
try {
|
|
90
|
+
const sock = process.env.EXE_TMUX_SOCKET;
|
|
91
|
+
const tmuxArgs = sock ? ["-L", sock, "display-message", "-p", "#{session_name}"] : ["display-message", "-p", "#{session_name}"];
|
|
92
|
+
const tmuxSession = execFileSync("tmux", tmuxArgs, {
|
|
93
|
+
encoding: "utf8",
|
|
94
|
+
timeout: 2e3
|
|
95
|
+
}).trim();
|
|
96
|
+
if (tmuxSession) sessionName = tmuxSession;
|
|
97
|
+
} catch {
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const headers = {
|
|
101
|
+
Authorization: `Bearer ${readOrCreateDaemonToken(homeDir)}`,
|
|
102
|
+
"X-Agent-Id": agentId,
|
|
103
|
+
"X-Agent-Role": agentRole
|
|
104
|
+
};
|
|
105
|
+
if (sessionName && !opts.useShellPlaceholders) headers["X-Exe-Session"] = sessionName;
|
|
106
|
+
return headers;
|
|
107
|
+
}
|
|
108
|
+
function buildClaudeHttpMcpEntry(homeDir = os.homedir()) {
|
|
109
|
+
const entry = {
|
|
110
|
+
type: "http",
|
|
111
|
+
url: mcpHttpUrl(),
|
|
112
|
+
headers: buildMcpHttpHeaders(homeDir, { useShellPlaceholders: true })
|
|
113
|
+
};
|
|
114
|
+
delete entry.headers["X-Exe-Session"];
|
|
115
|
+
return entry;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export {
|
|
119
|
+
DEFAULT_MCP_HTTP_PORT,
|
|
120
|
+
DEFAULT_MCP_HTTP_AGENT_ID,
|
|
121
|
+
DEFAULT_MCP_HTTP_AGENT_ROLE,
|
|
122
|
+
mcpHttpPort,
|
|
123
|
+
mcpHttpUrl,
|
|
124
|
+
persistMcpPortToConfig,
|
|
125
|
+
readOrCreateDaemonToken,
|
|
126
|
+
buildMcpHttpHeaders,
|
|
127
|
+
buildClaudeHttpMcpEntry
|
|
128
|
+
};
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CC_NATIVE_ONLY_CUTOFF,
|
|
3
|
+
compareSemver,
|
|
4
|
+
detectAutoupdaterVar
|
|
5
|
+
} from "./chunk-FRNXQSB4.js";
|
|
6
|
+
import {
|
|
7
|
+
checkCpuStealSync
|
|
8
|
+
} from "./chunk-SSC7EKY2.js";
|
|
9
|
+
import {
|
|
10
|
+
readMcpHttpEvents,
|
|
11
|
+
summarizeMcpTransport
|
|
12
|
+
} from "./chunk-3V6KXHSV.js";
|
|
13
|
+
import {
|
|
14
|
+
mcpHttpPort
|
|
15
|
+
} from "./chunk-MUIMJGSQ.js";
|
|
16
|
+
import {
|
|
17
|
+
EXE_AI_DIR
|
|
18
|
+
} from "./chunk-R36FAN53.js";
|
|
19
|
+
import {
|
|
20
|
+
isMainModule
|
|
21
|
+
} from "./chunk-6Y4B3QF6.js";
|
|
22
|
+
|
|
23
|
+
// src/bin/exe-healthcheck.ts
|
|
24
|
+
import { existsSync, readFileSync, readdirSync } from "fs";
|
|
25
|
+
import path from "path";
|
|
26
|
+
import { execSync } from "child_process";
|
|
27
|
+
import { fileURLToPath } from "url";
|
|
28
|
+
var CC_NATIVE_ONLY_CUTOFF2 = CC_NATIVE_ONLY_CUTOFF;
|
|
29
|
+
var compareSemver2 = compareSemver;
|
|
30
|
+
var detectAutoupdaterVar2 = detectAutoupdaterVar;
|
|
31
|
+
function findPackageRoot() {
|
|
32
|
+
let dir = path.dirname(fileURLToPath(import.meta.url));
|
|
33
|
+
const { root } = path.parse(dir);
|
|
34
|
+
while (dir !== root) {
|
|
35
|
+
if (existsSync(path.join(dir, "package.json"))) return dir;
|
|
36
|
+
dir = path.dirname(dir);
|
|
37
|
+
}
|
|
38
|
+
throw new Error("Cannot find package root");
|
|
39
|
+
}
|
|
40
|
+
function checkBuildIntegrity(pkgRoot) {
|
|
41
|
+
const results = [];
|
|
42
|
+
const tsupConfig = path.join(pkgRoot, "tsup.config.ts");
|
|
43
|
+
if (!existsSync(tsupConfig)) {
|
|
44
|
+
return [{ name: "build/tsup-config", pass: false, detail: "tsup.config.ts not found" }];
|
|
45
|
+
}
|
|
46
|
+
const configContent = readFileSync(tsupConfig, "utf-8");
|
|
47
|
+
const entryMatches = configContent.matchAll(/"([^"]+)":\s*"src\//g);
|
|
48
|
+
const missing = [];
|
|
49
|
+
let total = 0;
|
|
50
|
+
for (const match of entryMatches) {
|
|
51
|
+
const outputKey = match[1];
|
|
52
|
+
const expectedPath = path.join(pkgRoot, "dist", `${outputKey}.js`);
|
|
53
|
+
total++;
|
|
54
|
+
if (!existsSync(expectedPath)) {
|
|
55
|
+
missing.push(`dist/${outputKey}.js`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (missing.length > 0) {
|
|
59
|
+
results.push({
|
|
60
|
+
name: "build/entry-points",
|
|
61
|
+
pass: false,
|
|
62
|
+
detail: `${missing.length}/${total} entry points missing:
|
|
63
|
+
${missing.join("\n ")}`
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
results.push({
|
|
67
|
+
name: "build/entry-points",
|
|
68
|
+
pass: true,
|
|
69
|
+
detail: `${total} entry points verified`
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return results;
|
|
73
|
+
}
|
|
74
|
+
function checkEmbedPipeline(pkgRoot) {
|
|
75
|
+
const results = [];
|
|
76
|
+
const daemonPath = path.join(pkgRoot, "dist", "lib", "exe-daemon.js");
|
|
77
|
+
if (!existsSync(daemonPath)) {
|
|
78
|
+
results.push({
|
|
79
|
+
name: "exed/daemon-exists",
|
|
80
|
+
pass: false,
|
|
81
|
+
detail: `exe-daemon.js not found at ${daemonPath}`
|
|
82
|
+
});
|
|
83
|
+
return results;
|
|
84
|
+
}
|
|
85
|
+
results.push({ name: "exed/daemon-exists", pass: true, detail: "dist/lib/exe-daemon.js exists" });
|
|
86
|
+
const entryDirs = ["dist/hooks", "dist/bin", "dist/mcp"];
|
|
87
|
+
for (const dir of entryDirs) {
|
|
88
|
+
const fullDir = path.join(pkgRoot, dir);
|
|
89
|
+
if (!existsSync(fullDir)) continue;
|
|
90
|
+
let walkDir = fullDir;
|
|
91
|
+
const { root } = path.parse(walkDir);
|
|
92
|
+
let foundRoot = null;
|
|
93
|
+
while (walkDir !== root) {
|
|
94
|
+
if (existsSync(path.join(walkDir, "package.json"))) {
|
|
95
|
+
foundRoot = walkDir;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
walkDir = path.dirname(walkDir);
|
|
99
|
+
}
|
|
100
|
+
if (!foundRoot) {
|
|
101
|
+
results.push({
|
|
102
|
+
name: `exed/reachable-from-${dir}`,
|
|
103
|
+
pass: false,
|
|
104
|
+
detail: `Cannot find package root from ${dir}`
|
|
105
|
+
});
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const resolvedDaemon = path.join(foundRoot, "dist", "lib", "exe-daemon.js");
|
|
109
|
+
const reachable = existsSync(resolvedDaemon);
|
|
110
|
+
results.push({
|
|
111
|
+
name: `exed/reachable-from-${dir}`,
|
|
112
|
+
pass: reachable,
|
|
113
|
+
detail: reachable ? `Resolves to ${resolvedDaemon}` : `NOT FOUND: ${resolvedDaemon}`
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return results;
|
|
117
|
+
}
|
|
118
|
+
function checkTaskSystem(pkgRoot) {
|
|
119
|
+
const results = [];
|
|
120
|
+
const scannerPath = path.join(pkgRoot, "dist", "bin", "scan-tasks.js");
|
|
121
|
+
if (!existsSync(scannerPath)) {
|
|
122
|
+
results.push({ name: "tasks/scanner", pass: false, detail: "scan-tasks.js not found" });
|
|
123
|
+
return results;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
execSync(`node "${scannerPath}" /tmp/nonexistent-healthcheck-test --format=json 2>/dev/null`, {
|
|
127
|
+
timeout: 1e4,
|
|
128
|
+
encoding: "utf-8"
|
|
129
|
+
});
|
|
130
|
+
results.push({ name: "tasks/scanner", pass: true, detail: "scan-tasks.js runs without import errors" });
|
|
131
|
+
} catch (err) {
|
|
132
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
133
|
+
if (msg.includes("Cannot find module") || msg.includes("ERR_MODULE_NOT_FOUND") || msg.includes("SyntaxError")) {
|
|
134
|
+
results.push({ name: "tasks/scanner", pass: false, detail: `Import error: ${msg.slice(0, 200)}` });
|
|
135
|
+
} else {
|
|
136
|
+
results.push({ name: "tasks/scanner", pass: true, detail: "scan-tasks.js runs (no import errors)" });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return results;
|
|
140
|
+
}
|
|
141
|
+
function checkWorkerSpawning(pkgRoot) {
|
|
142
|
+
const results = [];
|
|
143
|
+
const workerPath = path.join(pkgRoot, "dist", "hooks", "ingest-worker.js");
|
|
144
|
+
if (!existsSync(workerPath)) {
|
|
145
|
+
results.push({ name: "workers/ingest-worker", pass: false, detail: "ingest-worker.js not found" });
|
|
146
|
+
return results;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
execSync(`node --check "${workerPath}" 2>&1`, { timeout: 1e4, encoding: "utf-8" });
|
|
150
|
+
results.push({ name: "workers/ingest-worker", pass: true, detail: "ingest-worker.js parses OK" });
|
|
151
|
+
} catch (err) {
|
|
152
|
+
results.push({
|
|
153
|
+
name: "workers/ingest-worker",
|
|
154
|
+
pass: false,
|
|
155
|
+
detail: `Parse error: ${err instanceof Error ? err.message.slice(0, 200) : String(err)}`
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const hooksDir = path.join(pkgRoot, "dist", "hooks");
|
|
159
|
+
if (existsSync(hooksDir)) {
|
|
160
|
+
const hookFiles = readdirSync(hooksDir).filter((f) => f.endsWith(".js") && !f.endsWith(".js.map"));
|
|
161
|
+
let hooksPassed = 0;
|
|
162
|
+
const hooksFailed = [];
|
|
163
|
+
for (const hook of hookFiles) {
|
|
164
|
+
try {
|
|
165
|
+
execSync(`node --check "${path.join(hooksDir, hook)}" 2>&1`, { timeout: 1e4, encoding: "utf-8" });
|
|
166
|
+
hooksPassed++;
|
|
167
|
+
} catch {
|
|
168
|
+
hooksFailed.push(hook);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (hooksFailed.length > 0) {
|
|
172
|
+
results.push({
|
|
173
|
+
name: "workers/hooks-parse",
|
|
174
|
+
pass: false,
|
|
175
|
+
detail: `${hooksFailed.length}/${hookFiles.length} hooks fail to parse: ${hooksFailed.join(", ")}`
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
results.push({
|
|
179
|
+
name: "workers/hooks-parse",
|
|
180
|
+
pass: true,
|
|
181
|
+
detail: `${hooksPassed} hook entry points parse OK`
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return results;
|
|
186
|
+
}
|
|
187
|
+
function checkMcpTransport() {
|
|
188
|
+
const results = [];
|
|
189
|
+
const pidPath = path.join(EXE_AI_DIR, "exed.pid");
|
|
190
|
+
const tokenPath = path.join(EXE_AI_DIR, "exed.token");
|
|
191
|
+
let daemonAlive = false;
|
|
192
|
+
if (existsSync(pidPath)) {
|
|
193
|
+
try {
|
|
194
|
+
const pid = parseInt(readFileSync(pidPath, "utf8").trim(), 10);
|
|
195
|
+
process.kill(pid, 0);
|
|
196
|
+
daemonAlive = true;
|
|
197
|
+
results.push({ name: "mcp/daemon-process", pass: true, detail: `exed process alive (pid ${pid})` });
|
|
198
|
+
} catch {
|
|
199
|
+
results.push({ name: "mcp/daemon-process", pass: false, detail: "exed.pid exists but process is not alive; restart exe-os/exed" });
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
results.push({ name: "mcp/daemon-process", pass: false, detail: "No exed.pid found; daemon is not running" });
|
|
203
|
+
}
|
|
204
|
+
if (daemonAlive && existsSync(tokenPath)) {
|
|
205
|
+
try {
|
|
206
|
+
const token = readFileSync(tokenPath, "utf8").trim();
|
|
207
|
+
const port = /^\d+$/.test(mcpHttpPort()) ? mcpHttpPort() : "48739";
|
|
208
|
+
const url = `http://127.0.0.1:${port}/mcp`;
|
|
209
|
+
const response = execSync(
|
|
210
|
+
`curl -sS -i -m 1 -H "Authorization: Bearer ${token}" -H 'Accept: application/json, text/event-stream' ${url}`,
|
|
211
|
+
{ encoding: "utf8", timeout: 1500 }
|
|
212
|
+
);
|
|
213
|
+
const jsonRpcError = response.includes("Content-Type: application/json") && response.includes("missing MCP session");
|
|
214
|
+
results.push({
|
|
215
|
+
name: "mcp/http-endpoint",
|
|
216
|
+
pass: jsonRpcError,
|
|
217
|
+
detail: jsonRpcError ? "MCP HTTP endpoint reachable; missing-session probe returns JSON-RPC (expected)" : "MCP HTTP endpoint reachable but did not return expected JSON-RPC missing-session response"
|
|
218
|
+
});
|
|
219
|
+
} catch (err) {
|
|
220
|
+
const msg = err instanceof Error ? err.message.slice(0, 180) : String(err);
|
|
221
|
+
const timedOut = msg.includes("ETIMEDOUT") || msg.includes("timed out") || msg.includes("killed");
|
|
222
|
+
results.push({
|
|
223
|
+
name: "mcp/http-endpoint",
|
|
224
|
+
pass: false,
|
|
225
|
+
detail: timedOut ? "Daemon alive but MCP unresponsive (timed out after 1.5s)" : `MCP HTTP endpoint not reachable: ${msg}`
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
} else if (daemonAlive) {
|
|
229
|
+
results.push({ name: "mcp/http-endpoint", pass: false, detail: "Daemon is alive but exed.token is missing; cannot probe MCP HTTP" });
|
|
230
|
+
}
|
|
231
|
+
const events = readMcpHttpEvents(200);
|
|
232
|
+
const summary = summarizeMcpTransport(events);
|
|
233
|
+
results.push({
|
|
234
|
+
name: "mcp/local-event-log",
|
|
235
|
+
pass: true,
|
|
236
|
+
detail: `${events.length} recent event(s); activeSessions=${summary.activeSessions ?? "unknown"}; lastHandshake=${summary.lastSuccessfulHandshake ?? "none"}; lastTool=${summary.lastSuccessfulToolCall ?? "none"}`
|
|
237
|
+
});
|
|
238
|
+
results.push({
|
|
239
|
+
name: "mcp/monitor-summary",
|
|
240
|
+
pass: true,
|
|
241
|
+
detail: `Privacy-safe local monitor summary: ${path.join(EXE_AI_DIR, "monitor", "mcp-transport-summary.json")}`
|
|
242
|
+
});
|
|
243
|
+
return results;
|
|
244
|
+
}
|
|
245
|
+
function checkClaudeCodeInstall() {
|
|
246
|
+
const results = [];
|
|
247
|
+
const execPath = process.env.CLAUDE_CODE_EXECPATH ?? "";
|
|
248
|
+
if (execPath.length > 0 && (execPath.includes("claude/versions/") || execPath.includes("claude.exe") || execPath.includes("claude-native"))) {
|
|
249
|
+
results.push({
|
|
250
|
+
name: "cc/execpath-clean",
|
|
251
|
+
pass: false,
|
|
252
|
+
detail: `CLAUDE_CODE_EXECPATH points to native binary: "${execPath}" \u2014 20K phantom billing risk. Unset it: unset CLAUDE_CODE_EXECPATH`
|
|
253
|
+
});
|
|
254
|
+
} else {
|
|
255
|
+
results.push({
|
|
256
|
+
name: "cc/execpath-clean",
|
|
257
|
+
pass: true,
|
|
258
|
+
detail: execPath ? `CLAUDE_CODE_EXECPATH=${execPath} (node runtime, OK)` : "CLAUDE_CODE_EXECPATH is unset"
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
const claudePath = execSync("which claude 2>/dev/null || true", { encoding: "utf8", timeout: 5e3 }).trim();
|
|
263
|
+
if (!claudePath) {
|
|
264
|
+
results.push({
|
|
265
|
+
name: "cc/cli-binary",
|
|
266
|
+
pass: false,
|
|
267
|
+
detail: "claude not found in PATH"
|
|
268
|
+
});
|
|
269
|
+
} else {
|
|
270
|
+
let resolved = claudePath;
|
|
271
|
+
try {
|
|
272
|
+
resolved = execSync(`readlink -f "${claudePath}" 2>/dev/null || readlink "${claudePath}" 2>/dev/null || echo "${claudePath}"`, {
|
|
273
|
+
encoding: "utf8",
|
|
274
|
+
timeout: 5e3
|
|
275
|
+
}).trim();
|
|
276
|
+
} catch {
|
|
277
|
+
}
|
|
278
|
+
if (resolved.includes("bin/claude.exe") || resolved.includes("bin/claude-native")) {
|
|
279
|
+
results.push({
|
|
280
|
+
name: "cc/cli-binary",
|
|
281
|
+
pass: false,
|
|
282
|
+
detail: `claude resolves to native binary: ${resolved}. Should be cli.js. Run: npm install -g @anthropic-ai/claude-code@2.1.98`
|
|
283
|
+
});
|
|
284
|
+
} else {
|
|
285
|
+
results.push({
|
|
286
|
+
name: "cc/cli-binary",
|
|
287
|
+
pass: true,
|
|
288
|
+
detail: `claude resolves to: ${resolved}`
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
} catch {
|
|
293
|
+
results.push({
|
|
294
|
+
name: "cc/cli-binary",
|
|
295
|
+
pass: false,
|
|
296
|
+
detail: "Failed to check claude binary path"
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
const versionsDir = path.join(
|
|
300
|
+
process.env.HOME ?? process.env.USERPROFILE ?? "",
|
|
301
|
+
".local",
|
|
302
|
+
"share",
|
|
303
|
+
"claude",
|
|
304
|
+
"versions"
|
|
305
|
+
);
|
|
306
|
+
if (existsSync(versionsDir)) {
|
|
307
|
+
try {
|
|
308
|
+
const entries = readdirSync(versionsDir);
|
|
309
|
+
if (entries.length > 0) {
|
|
310
|
+
results.push({
|
|
311
|
+
name: "cc/native-cache-clean",
|
|
312
|
+
pass: false,
|
|
313
|
+
detail: `${entries.length} cached native version(s) found in ${versionsDir}: ${entries.slice(0, 3).join(", ")}${entries.length > 3 ? "..." : ""}. Remove: rm -rf "${versionsDir}"`
|
|
314
|
+
});
|
|
315
|
+
} else {
|
|
316
|
+
results.push({
|
|
317
|
+
name: "cc/native-cache-clean",
|
|
318
|
+
pass: true,
|
|
319
|
+
detail: `${versionsDir} is empty`
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
} catch {
|
|
323
|
+
results.push({
|
|
324
|
+
name: "cc/native-cache-clean",
|
|
325
|
+
pass: true,
|
|
326
|
+
detail: `${versionsDir} not readable (OK)`
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
} else {
|
|
330
|
+
results.push({
|
|
331
|
+
name: "cc/native-cache-clean",
|
|
332
|
+
pass: true,
|
|
333
|
+
detail: `${versionsDir} does not exist`
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
const disableOld = detectAutoupdaterVar2("DISABLE_AUTOUPDATER");
|
|
337
|
+
const disableNew = detectAutoupdaterVar2("CLAUDE_CODE_AUTOUPDATER_DISABLED");
|
|
338
|
+
if (!disableOld && !disableNew) {
|
|
339
|
+
results.push({
|
|
340
|
+
name: "cc/autoupdater-disabled",
|
|
341
|
+
pass: false,
|
|
342
|
+
detail: "Neither DISABLE_AUTOUPDATER=1 nor CLAUDE_CODE_AUTOUPDATER_DISABLED=1 is set in the environment or your shell profile. Auto-updater may install infected native binary. Export both in your shell profile."
|
|
343
|
+
});
|
|
344
|
+
} else {
|
|
345
|
+
const describe = (label, hit) => {
|
|
346
|
+
if (!hit) return null;
|
|
347
|
+
if (hit.source === "env") return `${label}=1 (env)`;
|
|
348
|
+
return `${label}=1 (~/${hit.profile})`;
|
|
349
|
+
};
|
|
350
|
+
const which = [
|
|
351
|
+
describe("DISABLE_AUTOUPDATER", disableOld),
|
|
352
|
+
describe("CLAUDE_CODE_AUTOUPDATER_DISABLED", disableNew)
|
|
353
|
+
].filter(Boolean).join(" + ");
|
|
354
|
+
results.push({
|
|
355
|
+
name: "cc/autoupdater-disabled",
|
|
356
|
+
pass: true,
|
|
357
|
+
detail: `Auto-updater disabled via ${which}`
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
const ccVersion = execSync("claude --version 2>/dev/null || echo unknown", {
|
|
362
|
+
encoding: "utf8",
|
|
363
|
+
timeout: 5e3
|
|
364
|
+
}).trim();
|
|
365
|
+
const versionMatch = ccVersion.match(/(\d+\.\d+\.\d+)/);
|
|
366
|
+
if (versionMatch) {
|
|
367
|
+
const ver = versionMatch[1];
|
|
368
|
+
const isRisky = compareSemver2(ver, CC_NATIVE_ONLY_CUTOFF2) >= 0;
|
|
369
|
+
results.push({
|
|
370
|
+
name: "cc/version",
|
|
371
|
+
pass: !isRisky,
|
|
372
|
+
detail: isRisky ? `CC version ${ver} \u2014 \u2265${CC_NATIVE_ONLY_CUTOFF2} ships native binary only. Pin: npm install -g @anthropic-ai/claude-code@2.1.98` : `CC version ${ver}`
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
} catch {
|
|
376
|
+
}
|
|
377
|
+
return results;
|
|
378
|
+
}
|
|
379
|
+
function checkCpuSteal() {
|
|
380
|
+
const steal = checkCpuStealSync();
|
|
381
|
+
if (!steal.available) {
|
|
382
|
+
return [{ name: "host/cpu-steal", pass: true, detail: `n/a \u2014 ${steal.message}` }];
|
|
383
|
+
}
|
|
384
|
+
const pass = steal.severity === "ok";
|
|
385
|
+
return [{
|
|
386
|
+
name: "host/cpu-steal",
|
|
387
|
+
pass,
|
|
388
|
+
detail: steal.severity === "critical" ? `\u{1F534} CRITICAL: ${steal.message}` : steal.severity === "warning" ? `\u{1F7E0} WARN: ${steal.message}` : steal.message
|
|
389
|
+
}];
|
|
390
|
+
}
|
|
391
|
+
function runHealthCheck() {
|
|
392
|
+
const pkgRoot = findPackageRoot();
|
|
393
|
+
const results = [
|
|
394
|
+
...checkBuildIntegrity(pkgRoot),
|
|
395
|
+
...checkEmbedPipeline(pkgRoot),
|
|
396
|
+
...checkTaskSystem(pkgRoot),
|
|
397
|
+
...checkWorkerSpawning(pkgRoot),
|
|
398
|
+
...checkMcpTransport(),
|
|
399
|
+
...checkClaudeCodeInstall(),
|
|
400
|
+
...checkCpuSteal()
|
|
401
|
+
];
|
|
402
|
+
const passed = results.filter((r) => r.pass).length;
|
|
403
|
+
const failed = results.filter((r) => !r.pass).length;
|
|
404
|
+
return { results, passed, failed };
|
|
405
|
+
}
|
|
406
|
+
if (isMainModule(import.meta.url) && (process.argv[1] ?? "").includes("exe-healthcheck")) {
|
|
407
|
+
const { results, passed, failed } = runHealthCheck();
|
|
408
|
+
console.log("\n exe-os Health Check\n");
|
|
409
|
+
for (const r of results) {
|
|
410
|
+
const icon = r.pass ? "\x1B[32m\u2713\x1B[0m" : "\x1B[31m\u2717\x1B[0m";
|
|
411
|
+
console.log(` ${icon} ${r.name}`);
|
|
412
|
+
console.log(` ${r.detail}`);
|
|
413
|
+
}
|
|
414
|
+
console.log(`
|
|
415
|
+
${passed} passed, ${failed} failed
|
|
416
|
+
`);
|
|
417
|
+
process.exit(failed > 0 ? 1 : 0);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export {
|
|
421
|
+
CC_NATIVE_ONLY_CUTOFF2 as CC_NATIVE_ONLY_CUTOFF,
|
|
422
|
+
compareSemver2 as compareSemver,
|
|
423
|
+
detectAutoupdaterVar2 as detectAutoupdaterVar,
|
|
424
|
+
checkClaudeCodeInstall,
|
|
425
|
+
checkCpuSteal,
|
|
426
|
+
runHealthCheck
|
|
427
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCurrentSessionScope,
|
|
3
|
+
strictSessionScopeFilter
|
|
4
|
+
} from "./chunk-ZSUACDQC.js";
|
|
5
|
+
import {
|
|
6
|
+
getProjectName
|
|
7
|
+
} from "./chunk-OPU3NYOO.js";
|
|
8
|
+
|
|
9
|
+
// src/lib/session-events.ts
|
|
10
|
+
import { randomUUID } from "crypto";
|
|
11
|
+
async function ensureSessionEventsTable(client) {
|
|
12
|
+
await client.execute(`
|
|
13
|
+
CREATE TABLE IF NOT EXISTS session_events (
|
|
14
|
+
id TEXT PRIMARY KEY,
|
|
15
|
+
agent_id TEXT NOT NULL,
|
|
16
|
+
agent_role TEXT NOT NULL,
|
|
17
|
+
session_id TEXT NOT NULL,
|
|
18
|
+
session_scope TEXT,
|
|
19
|
+
project_name TEXT NOT NULL,
|
|
20
|
+
event_index INTEGER NOT NULL,
|
|
21
|
+
event_type TEXT NOT NULL,
|
|
22
|
+
tool_name TEXT,
|
|
23
|
+
tool_use_id TEXT,
|
|
24
|
+
content TEXT NOT NULL,
|
|
25
|
+
payload_json TEXT,
|
|
26
|
+
has_error INTEGER NOT NULL DEFAULT 0,
|
|
27
|
+
created_at TEXT NOT NULL
|
|
28
|
+
)
|
|
29
|
+
`);
|
|
30
|
+
await client.execute(`
|
|
31
|
+
CREATE INDEX IF NOT EXISTS idx_session_events_agent_time
|
|
32
|
+
ON session_events(agent_id, created_at DESC)
|
|
33
|
+
`);
|
|
34
|
+
await client.execute(`
|
|
35
|
+
CREATE INDEX IF NOT EXISTS idx_session_events_session_index
|
|
36
|
+
ON session_events(session_id, event_index)
|
|
37
|
+
`);
|
|
38
|
+
await client.execute(`
|
|
39
|
+
CREATE INDEX IF NOT EXISTS idx_session_events_scope_agent_time
|
|
40
|
+
ON session_events(session_scope, agent_id, created_at DESC)
|
|
41
|
+
`);
|
|
42
|
+
}
|
|
43
|
+
async function recordSessionEvent(client, input) {
|
|
44
|
+
if (!input.content || input.content.trim().length === 0) return;
|
|
45
|
+
await ensureSessionEventsTable(client);
|
|
46
|
+
const maxResult = await client.execute({
|
|
47
|
+
sql: "SELECT COALESCE(MAX(event_index), 0) AS max_index FROM session_events WHERE session_id = ?",
|
|
48
|
+
args: [input.sessionId]
|
|
49
|
+
});
|
|
50
|
+
const currentMax = Number(maxResult.rows[0]?.max_index ?? 0);
|
|
51
|
+
const eventIndex = Number.isFinite(currentMax) ? currentMax + 1 : 1;
|
|
52
|
+
await client.execute({
|
|
53
|
+
sql: `INSERT INTO session_events (
|
|
54
|
+
id, agent_id, agent_role, session_id, session_scope, project_name,
|
|
55
|
+
event_index, event_type, tool_name, tool_use_id, content,
|
|
56
|
+
payload_json, has_error, created_at
|
|
57
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
58
|
+
args: [
|
|
59
|
+
randomUUID(),
|
|
60
|
+
input.agentId,
|
|
61
|
+
input.agentRole,
|
|
62
|
+
input.sessionId,
|
|
63
|
+
input.sessionScope ?? getCurrentSessionScope(),
|
|
64
|
+
input.projectName ?? getProjectName(input.cwd),
|
|
65
|
+
eventIndex,
|
|
66
|
+
input.eventType,
|
|
67
|
+
input.toolName ?? null,
|
|
68
|
+
input.toolUseId ?? null,
|
|
69
|
+
input.content,
|
|
70
|
+
input.payloadJson ?? null,
|
|
71
|
+
input.hasError ? 1 : 0,
|
|
72
|
+
input.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async function listRecentSessionEvents(client, options) {
|
|
77
|
+
await ensureSessionEventsTable(client);
|
|
78
|
+
const conditions = ["agent_id = ?"];
|
|
79
|
+
const args = [options.agentId];
|
|
80
|
+
if (options.sessionId) {
|
|
81
|
+
conditions.push("session_id = ?");
|
|
82
|
+
args.push(options.sessionId);
|
|
83
|
+
}
|
|
84
|
+
if (options.eventType) {
|
|
85
|
+
conditions.push("event_type = ?");
|
|
86
|
+
args.push(options.eventType);
|
|
87
|
+
}
|
|
88
|
+
if (options.projectName && options.projectName !== "all") {
|
|
89
|
+
conditions.push("project_name = ?");
|
|
90
|
+
args.push(options.projectName);
|
|
91
|
+
}
|
|
92
|
+
const scope = strictSessionScopeFilter(options.sessionScope);
|
|
93
|
+
const where = `WHERE ${conditions.join(" AND ")}${scope.sql}`;
|
|
94
|
+
args.push(...scope.args);
|
|
95
|
+
args.push(Math.min(Math.max(options.limit ?? 20, 1), 100));
|
|
96
|
+
const result = await client.execute({
|
|
97
|
+
sql: `SELECT id, agent_id, agent_role, session_id, session_scope,
|
|
98
|
+
project_name, event_index, event_type, tool_name, tool_use_id,
|
|
99
|
+
content, payload_json, has_error, created_at
|
|
100
|
+
FROM session_events
|
|
101
|
+
${where}
|
|
102
|
+
ORDER BY created_at DESC, event_index DESC
|
|
103
|
+
LIMIT ?`,
|
|
104
|
+
args
|
|
105
|
+
});
|
|
106
|
+
return result.rows.map((row) => ({
|
|
107
|
+
id: String(row.id),
|
|
108
|
+
agentId: String(row.agent_id),
|
|
109
|
+
agentRole: String(row.agent_role),
|
|
110
|
+
sessionId: String(row.session_id),
|
|
111
|
+
sessionScope: row.session_scope == null ? null : String(row.session_scope),
|
|
112
|
+
projectName: String(row.project_name),
|
|
113
|
+
eventIndex: Number(row.event_index),
|
|
114
|
+
eventType: String(row.event_type),
|
|
115
|
+
toolName: row.tool_name == null ? null : String(row.tool_name),
|
|
116
|
+
toolUseId: row.tool_use_id == null ? null : String(row.tool_use_id),
|
|
117
|
+
content: String(row.content),
|
|
118
|
+
payloadJson: row.payload_json == null ? null : String(row.payload_json),
|
|
119
|
+
hasError: Number(row.has_error) === 1,
|
|
120
|
+
createdAt: String(row.created_at)
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export {
|
|
125
|
+
ensureSessionEventsTable,
|
|
126
|
+
recordSessionEvent,
|
|
127
|
+
listRecentSessionEvents
|
|
128
|
+
};
|