@askexenow/exe-os 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/package.json +1 -1
  2. package/dist/bin/backfill-responses.js +0 -2064
  3. package/dist/bin/backfill-vectors.js +0 -1771
  4. package/dist/bin/cleanup-stale-review-tasks.js +0 -1468
  5. package/dist/bin/cli.js +0 -21371
  6. package/dist/bin/exe-agent.js +0 -2016
  7. package/dist/bin/exe-assign.js +0 -2176
  8. package/dist/bin/exe-boot.js +0 -6332
  9. package/dist/bin/exe-call.js +0 -341
  10. package/dist/bin/exe-cloud.js +0 -861
  11. package/dist/bin/exe-dispatch.js +0 -1159
  12. package/dist/bin/exe-doctor.js +0 -1786
  13. package/dist/bin/exe-export-behaviors.js +0 -1637
  14. package/dist/bin/exe-forget.js +0 -1784
  15. package/dist/bin/exe-gateway.js +0 -8140
  16. package/dist/bin/exe-healthcheck.js +0 -207
  17. package/dist/bin/exe-heartbeat.js +0 -1778
  18. package/dist/bin/exe-kill.js +0 -1622
  19. package/dist/bin/exe-launch-agent.js +0 -1847
  20. package/dist/bin/exe-link.js +0 -192
  21. package/dist/bin/exe-new-employee.js +0 -1384
  22. package/dist/bin/exe-pending-messages.js +0 -1576
  23. package/dist/bin/exe-pending-notifications.js +0 -1450
  24. package/dist/bin/exe-pending-reviews.js +0 -1598
  25. package/dist/bin/exe-repo-drift.js +0 -95
  26. package/dist/bin/exe-review.js +0 -1742
  27. package/dist/bin/exe-search.js +0 -3116
  28. package/dist/bin/exe-session-cleanup.js +0 -3360
  29. package/dist/bin/exe-settings.js +0 -365
  30. package/dist/bin/exe-status.js +0 -1661
  31. package/dist/bin/exe-team.js +0 -1453
  32. package/dist/bin/git-sweep.js +0 -2441
  33. package/dist/bin/graph-backfill.js +0 -2111
  34. package/dist/bin/graph-export.js +0 -1747
  35. package/dist/bin/install.js +0 -661
  36. package/dist/bin/list-providers.js +0 -140
  37. package/dist/bin/scan-tasks.js +0 -2039
  38. package/dist/bin/setup.js +0 -2717
  39. package/dist/bin/shard-migrate.js +0 -1637
  40. package/dist/bin/update.js +0 -98
  41. package/dist/bin/wiki-sync.js +0 -1657
  42. package/dist/gateway/index.js +0 -9256
  43. package/dist/hooks/bug-report-worker.js +0 -2903
  44. package/dist/hooks/commit-complete.js +0 -2364
  45. package/dist/hooks/error-recall.js +0 -3327
  46. package/dist/hooks/exe-heartbeat-hook.js +0 -237
  47. package/dist/hooks/ingest-worker.js +0 -5065
  48. package/dist/hooks/ingest.js +0 -695
  49. package/dist/hooks/instructions-loaded.js +0 -2069
  50. package/dist/hooks/notification.js +0 -1915
  51. package/dist/hooks/post-compact.js +0 -1940
  52. package/dist/hooks/pre-compact.js +0 -1935
  53. package/dist/hooks/pre-tool-use.js +0 -2380
  54. package/dist/hooks/prompt-ingest-worker.js +0 -2291
  55. package/dist/hooks/prompt-submit.js +0 -5189
  56. package/dist/hooks/response-ingest-worker.js +0 -2431
  57. package/dist/hooks/session-end.js +0 -2196
  58. package/dist/hooks/session-start.js +0 -3259
  59. package/dist/hooks/stop.js +0 -2025
  60. package/dist/hooks/subagent-stop.js +0 -1915
  61. package/dist/hooks/summary-worker.js +0 -2931
  62. package/dist/index.js +0 -12327
  63. package/dist/lib/cloud-sync.js +0 -500
  64. package/dist/lib/config.js +0 -235
  65. package/dist/lib/consolidation.js +0 -481
  66. package/dist/lib/crypto.js +0 -51
  67. package/dist/lib/database.js +0 -834
  68. package/dist/lib/device-registry.js +0 -1009
  69. package/dist/lib/embedder.js +0 -645
  70. package/dist/lib/employee-templates.js +0 -570
  71. package/dist/lib/employees.js +0 -182
  72. package/dist/lib/error-detector.js +0 -156
  73. package/dist/lib/exe-daemon-client.js +0 -456
  74. package/dist/lib/exe-daemon.js +0 -8699
  75. package/dist/lib/file-grep.js +0 -215
  76. package/dist/lib/hybrid-search.js +0 -3064
  77. package/dist/lib/identity-templates.js +0 -441
  78. package/dist/lib/identity.js +0 -228
  79. package/dist/lib/keychain.js +0 -145
  80. package/dist/lib/license.js +0 -382
  81. package/dist/lib/messaging.js +0 -1389
  82. package/dist/lib/reminders.js +0 -63
  83. package/dist/lib/schedules.js +0 -1525
  84. package/dist/lib/session-registry.js +0 -52
  85. package/dist/lib/skill-learning.js +0 -488
  86. package/dist/lib/status-brief.js +0 -240
  87. package/dist/lib/store.js +0 -1740
  88. package/dist/lib/task-router.js +0 -128
  89. package/dist/lib/tasks.js +0 -2585
  90. package/dist/lib/tmux-routing.js +0 -2969
  91. package/dist/lib/tmux-status.js +0 -261
  92. package/dist/lib/tmux-transport.js +0 -83
  93. package/dist/lib/transport.js +0 -128
  94. package/dist/lib/ws-auth.js +0 -19
  95. package/dist/lib/ws-client.js +0 -160
  96. package/dist/mcp/server.js +0 -10812
  97. package/dist/mcp/tools/complete-reminder.js +0 -67
  98. package/dist/mcp/tools/create-reminder.js +0 -52
  99. package/dist/mcp/tools/create-task.js +0 -1903
  100. package/dist/mcp/tools/deactivate-behavior.js +0 -268
  101. package/dist/mcp/tools/list-reminders.js +0 -62
  102. package/dist/mcp/tools/list-tasks.js +0 -491
  103. package/dist/mcp/tools/send-message.js +0 -1395
  104. package/dist/mcp/tools/update-task.js +0 -1807
  105. package/dist/runtime/index.js +0 -7201
  106. package/dist/tui/App.js +0 -17874
@@ -1,695 +0,0 @@
1
- // src/lib/config.ts
2
- import { readFile, writeFile, mkdir } from "fs/promises";
3
- import { readFileSync, existsSync, renameSync } from "fs";
4
- import path from "path";
5
- import os from "os";
6
- function resolveDataDir() {
7
- if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
8
- if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
9
- const newDir = path.join(os.homedir(), ".exe-os");
10
- const legacyDir = path.join(os.homedir(), ".exe-mem");
11
- if (!existsSync(newDir) && existsSync(legacyDir)) {
12
- try {
13
- renameSync(legacyDir, newDir);
14
- process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
15
- `);
16
- } catch {
17
- return legacyDir;
18
- }
19
- }
20
- return newDir;
21
- }
22
- var EXE_AI_DIR = resolveDataDir();
23
- var DB_PATH = path.join(EXE_AI_DIR, "memories.db");
24
- var MODELS_DIR = path.join(EXE_AI_DIR, "models");
25
- var CONFIG_PATH = path.join(EXE_AI_DIR, "config.json");
26
- var LEGACY_LANCE_PATH = path.join(EXE_AI_DIR, "local.lance");
27
- var CURRENT_CONFIG_VERSION = 1;
28
- var DEFAULT_CONFIG = {
29
- config_version: CURRENT_CONFIG_VERSION,
30
- dbPath: DB_PATH,
31
- modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
32
- embeddingDim: 1024,
33
- batchSize: 20,
34
- flushIntervalMs: 1e4,
35
- autoIngestion: true,
36
- autoRetrieval: true,
37
- searchMode: "hybrid",
38
- hookSearchMode: "hybrid",
39
- fileGrepEnabled: true,
40
- splashEffect: true,
41
- consolidationEnabled: true,
42
- consolidationIntervalMs: 6 * 60 * 60 * 1e3,
43
- consolidationModel: "claude-haiku-4-5-20251001",
44
- consolidationMaxCallsPerRun: 20,
45
- selfQueryRouter: true,
46
- selfQueryModel: "claude-haiku-4-5-20251001",
47
- rerankerEnabled: true,
48
- scalingRoadmap: {
49
- rerankerAutoTrigger: {
50
- enabled: true,
51
- broadQueryMinCardinality: 5e4,
52
- fetchTopK: 150,
53
- returnTopK: 5
54
- }
55
- },
56
- graphRagEnabled: true,
57
- wikiEnabled: false,
58
- wikiUrl: "",
59
- wikiApiKey: "",
60
- wikiSyncIntervalMs: 30 * 60 * 1e3,
61
- wikiWorkspaceMapping: {
62
- exe: "Executive",
63
- yoshi: "Engineering",
64
- mari: "Marketing",
65
- tom: "Engineering",
66
- sasha: "Production"
67
- },
68
- wikiAutoUpdate: true,
69
- wikiAutoUpdateThreshold: 0.5,
70
- wikiAutoUpdateCreateNew: true,
71
- skillLearning: true,
72
- skillThreshold: 3,
73
- skillModel: "claude-haiku-4-5-20251001",
74
- exeHeartbeat: {
75
- enabled: true,
76
- intervalSeconds: 60,
77
- staleInProgressThresholdHours: 2
78
- },
79
- sessionLifecycle: {
80
- idleKillEnabled: true,
81
- idleKillTicksRequired: 3,
82
- idleKillIntercomAckWindowMs: 1e4,
83
- maxAutoInstances: 10
84
- },
85
- autoUpdate: {
86
- checkOnBoot: true,
87
- autoInstall: false,
88
- checkIntervalMs: 24 * 60 * 60 * 1e3
89
- }
90
- };
91
- function migrateLegacyConfig(raw) {
92
- if ("r2" in raw) {
93
- process.stderr.write(
94
- "[exe-os] Warning: config.json contains deprecated 'r2' field from v1.0. R2 sync has been replaced in v1.1. The 'r2' field will be ignored.\n"
95
- );
96
- delete raw.r2;
97
- }
98
- if ("syncIntervalMs" in raw) {
99
- delete raw.syncIntervalMs;
100
- }
101
- return raw;
102
- }
103
- var CONFIG_MIGRATIONS = [
104
- {
105
- from: 0,
106
- to: 1,
107
- migrate: (cfg) => {
108
- cfg.config_version = 1;
109
- return cfg;
110
- }
111
- }
112
- ];
113
- function migrateConfig(raw) {
114
- const fromVersion = typeof raw.config_version === "number" ? raw.config_version : 0;
115
- let currentVersion = fromVersion;
116
- let migrated = false;
117
- if (currentVersion > CURRENT_CONFIG_VERSION) {
118
- return { config: raw, migrated: false, fromVersion };
119
- }
120
- for (const migration of CONFIG_MIGRATIONS) {
121
- if (currentVersion === migration.from && migration.to <= CURRENT_CONFIG_VERSION) {
122
- raw = migration.migrate(raw);
123
- currentVersion = migration.to;
124
- migrated = true;
125
- }
126
- }
127
- return { config: raw, migrated, fromVersion };
128
- }
129
- function normalizeScalingRoadmap(raw) {
130
- const defaultAuto = DEFAULT_CONFIG.scalingRoadmap.rerankerAutoTrigger;
131
- const userRoadmap = raw.scalingRoadmap ?? {};
132
- const userAuto = userRoadmap.rerankerAutoTrigger ?? {};
133
- if (userAuto.enabled === void 0 && raw.rerankerEnabled !== void 0) {
134
- userAuto.enabled = raw.rerankerEnabled;
135
- }
136
- raw.scalingRoadmap = {
137
- ...userRoadmap,
138
- rerankerAutoTrigger: { ...defaultAuto, ...userAuto }
139
- };
140
- }
141
- function normalizeSessionLifecycle(raw) {
142
- const defaultSL = DEFAULT_CONFIG.sessionLifecycle;
143
- const userSL = raw.sessionLifecycle ?? {};
144
- raw.sessionLifecycle = { ...defaultSL, ...userSL };
145
- }
146
- function normalizeAutoUpdate(raw) {
147
- const defaultAU = DEFAULT_CONFIG.autoUpdate;
148
- const userAU = raw.autoUpdate ?? {};
149
- raw.autoUpdate = { ...defaultAU, ...userAU };
150
- }
151
- function loadConfigSync() {
152
- const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
153
- const configPath = path.join(dir, "config.json");
154
- if (!existsSync(configPath)) {
155
- return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
156
- }
157
- try {
158
- const raw = readFileSync(configPath, "utf-8");
159
- let parsed = JSON.parse(raw);
160
- parsed = migrateLegacyConfig(parsed);
161
- const { config: migratedCfg } = migrateConfig(parsed);
162
- normalizeScalingRoadmap(migratedCfg);
163
- normalizeSessionLifecycle(migratedCfg);
164
- normalizeAutoUpdate(migratedCfg);
165
- return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
166
- } catch {
167
- return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
168
- }
169
- }
170
-
171
- // src/adapters/claude/hooks/ingest.ts
172
- import { spawn } from "child_process";
173
- import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2, existsSync as existsSync2, openSync, closeSync } from "fs";
174
- import path3 from "path";
175
- import { fileURLToPath } from "url";
176
-
177
- // src/adapters/claude/active-agent.ts
178
- import { readFileSync as readFileSync2, writeFileSync, mkdirSync, unlinkSync, readdirSync } from "fs";
179
- import { execSync as execSync2 } from "child_process";
180
- import path2 from "path";
181
-
182
- // src/lib/session-key.ts
183
- import { execSync } from "child_process";
184
- var _cached = null;
185
- function getSessionKey() {
186
- if (_cached) return _cached;
187
- let pid = process.ppid;
188
- for (let i = 0; i < 10; i++) {
189
- try {
190
- const info = execSync(`ps -p ${pid} -o ppid=,comm=`, {
191
- encoding: "utf8",
192
- timeout: 2e3
193
- }).trim();
194
- const match = info.match(/^\s*(\d+)\s+(.+)$/);
195
- if (!match) break;
196
- const [, ppid, cmd] = match;
197
- if (cmd === "claude" || cmd.endsWith("/claude")) {
198
- _cached = String(pid);
199
- return _cached;
200
- }
201
- pid = parseInt(ppid, 10);
202
- if (pid <= 1) break;
203
- } catch {
204
- break;
205
- }
206
- }
207
- _cached = process.env.CLAUDE_CODE_SSE_PORT ?? String(process.ppid);
208
- return _cached;
209
- }
210
-
211
- // src/adapters/claude/active-agent.ts
212
- var CACHE_DIR = path2.join(EXE_AI_DIR, "session-cache");
213
- var STALE_MS = 24 * 60 * 60 * 1e3;
214
- function getMarkerPath() {
215
- return path2.join(CACHE_DIR, `active-agent-${getSessionKey()}.json`);
216
- }
217
- function getActiveAgent() {
218
- try {
219
- const markerPath = getMarkerPath();
220
- const raw = readFileSync2(markerPath, "utf8");
221
- const data = JSON.parse(raw);
222
- if (data.agentId) {
223
- if (data.startedAt) {
224
- const age = Date.now() - new Date(data.startedAt).getTime();
225
- if (age > STALE_MS) {
226
- try {
227
- unlinkSync(markerPath);
228
- } catch {
229
- }
230
- } else {
231
- return {
232
- agentId: data.agentId,
233
- agentRole: data.agentRole || "employee"
234
- };
235
- }
236
- } else {
237
- return {
238
- agentId: data.agentId,
239
- agentRole: data.agentRole || "employee"
240
- };
241
- }
242
- }
243
- } catch {
244
- }
245
- try {
246
- const sessionName = execSync2(
247
- "tmux display-message -p '#{session_name}' 2>/dev/null",
248
- { encoding: "utf8", timeout: 2e3 }
249
- ).trim();
250
- const empMatch = sessionName.match(/^(\w+)-exe\d+$/);
251
- if (empMatch && empMatch[1] !== "exe") {
252
- return { agentId: empMatch[1], agentRole: "employee" };
253
- }
254
- if (/^exe\d+$/.test(sessionName)) {
255
- return { agentId: "exe", agentRole: "COO" };
256
- }
257
- } catch {
258
- }
259
- return {
260
- agentId: process.env.AGENT_ID || "default",
261
- agentRole: process.env.AGENT_ROLE || "employee"
262
- };
263
- }
264
-
265
- // src/lib/error-detector.ts
266
- import crypto from "crypto";
267
-
268
- // src/lib/mcp-prefix.ts
269
- var MCP_PRIMARY_KEY = "exe-os";
270
- var MCP_LEGACY_KEY = "exe-mem";
271
- var MCP_TOOL_PREFIXES = [
272
- `mcp__${MCP_PRIMARY_KEY}__`,
273
- `mcp__${MCP_LEGACY_KEY}__`
274
- ];
275
- function isExeMcpTool(toolName) {
276
- if (!toolName) return false;
277
- return MCP_TOOL_PREFIXES.some((p) => toolName.startsWith(p));
278
- }
279
-
280
- // src/lib/error-detector.ts
281
- var ERROR_PATTERNS = [
282
- /\bError\b/i,
283
- /\bERR!\b/,
284
- /\bFAIL(ED|URE)?\b/i,
285
- /\bException\b/i,
286
- /\bTraceback\b/,
287
- /\bpanic\b/,
288
- /\bSIGSEGV\b/,
289
- /\bSIGABRT\b/,
290
- /exit code [1-9]/i,
291
- /non-zero (exit|status)/i,
292
- /command not found/i,
293
- /permission denied/i,
294
- /ENOENT/,
295
- /EACCES/,
296
- /ENOMEM/
297
- ];
298
- var FILE_CONTENT_TOOLS = /* @__PURE__ */ new Set([
299
- "Read",
300
- "Write",
301
- "Edit",
302
- "Glob",
303
- "Grep",
304
- "NotebookEdit"
305
- ]);
306
- var STDERR_IGNORE_PATTERNS = [
307
- /^warning\b/i,
308
- /\bDeprecationWarning\b/,
309
- /^hint:/i,
310
- /^npm warn\b/i,
311
- /^npm notice\b/i,
312
- /^\(node:\d+\) \w*Warning:/,
313
- /^Cloning into/,
314
- /^Already on/,
315
- /^Switched to/,
316
- /^Your branch is/,
317
- /^Auto-merging/,
318
- /^\s*$/
319
- ];
320
- function isRealStderr(stderr) {
321
- const lines = stderr.trim().split("\n");
322
- const meaningful = lines.filter(
323
- (line) => line.trim().length > 0 && !STDERR_IGNORE_PATTERNS.some((p) => p.test(line))
324
- );
325
- return meaningful.length > 0;
326
- }
327
- function logSuppression(exitCode, stderr, stdout) {
328
- process.stderr.write(
329
- `[error-detector] suppressed bash non-zero exit: code=${exitCode} stderr_len=${stderr.length} stdout_len=${stdout.length}
330
- `
331
- );
332
- }
333
- function detectError(data) {
334
- const response = data.tool_response;
335
- if (!response) return false;
336
- const toolName = data.tool_name ?? "";
337
- if (FILE_CONTENT_TOOLS.has(toolName)) {
338
- return response.type === "error" || response.error != null;
339
- }
340
- if (toolName === "Bash") {
341
- const exitCode = typeof response.exitCode === "number" ? response.exitCode : 0;
342
- const stderr = typeof response.stderr === "string" ? response.stderr : "";
343
- const stdout = typeof response.stdout === "string" ? response.stdout : "";
344
- if (exitCode === 141) {
345
- logSuppression(exitCode, stderr, stdout);
346
- return false;
347
- }
348
- if (stderr.trim().length > 0 && isRealStderr(stderr)) return true;
349
- if (exitCode !== 0 && !isRealStderr(stderr) && stdout.trim().length > 0) {
350
- logSuppression(exitCode, stderr, stdout);
351
- return false;
352
- }
353
- if (exitCode !== 0) return true;
354
- return false;
355
- }
356
- if (response.type === "error" || response.error != null || response.isError === true) {
357
- return true;
358
- }
359
- if (typeof response.stderr === "string" && response.stderr.trim().length > 0) {
360
- if (isRealStderr(response.stderr)) return true;
361
- }
362
- const textParts = [];
363
- if (typeof response.stdout === "string") textParts.push(response.stdout);
364
- if (typeof response.output === "string") textParts.push(response.output);
365
- if (typeof response.text === "string") textParts.push(response.text);
366
- if (typeof response.message === "string") textParts.push(response.message);
367
- if (textParts.length === 0) return false;
368
- const text = textParts.join("\n");
369
- return ERROR_PATTERNS.some((pattern) => pattern.test(text));
370
- }
371
- function isExeOsError(data) {
372
- const toolName = data.tool_name ?? "";
373
- if (isExeMcpTool(toolName)) return true;
374
- if (toolName === "Bash") {
375
- const cmd = String(data.tool_input?.command ?? "");
376
- if (/\bexe-os\b|exe-boot|exe-healthcheck|scan-tasks|exe-call/.test(cmd)) return true;
377
- if (/node.*dist\/(bin|hooks|lib)\//.test(cmd)) return true;
378
- }
379
- return false;
380
- }
381
- var USER_ERROR_PATTERNS = [
382
- /not found:?\s/i,
383
- /expected \d+ words/i,
384
- /provide either/i,
385
- /invalid.*parameter/i,
386
- /already exists/i,
387
- /Multiple tasks match/i,
388
- /Use a more specific identifier/i
389
- ];
390
- var SYSTEM_BUG_PATTERNS = [
391
- /SQLITE_ERROR/,
392
- /Cannot find module/,
393
- /ERR_MODULE_NOT_FOUND/,
394
- /TypeError:/,
395
- /ReferenceError:/,
396
- /Cannot read propert/,
397
- /is not a function/,
398
- /ENOENT.*dist\//,
399
- /dimension mismatch/i,
400
- /unhealthy.*model/i,
401
- /constraint.*violat/i
402
- ];
403
- function classifyError(errorText) {
404
- if (USER_ERROR_PATTERNS.some((p) => p.test(errorText))) return "user";
405
- if (SYSTEM_BUG_PATTERNS.some((p) => p.test(errorText))) return "system";
406
- if (/at\s+\S+\s+\(.*exe-os.*\)/m.test(errorText)) return "system";
407
- if (/at\s+\S+\s+\(.*dist\/(lib|bin|hooks|mcp)\//m.test(errorText)) return "system";
408
- return "unknown";
409
- }
410
- function errorFingerprint(toolName, errorText) {
411
- const normalized = errorText.replace(/\d{4}-\d{2}-\d{2}T[\d:.]+Z/g, "TIMESTAMP").replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, "UUID").replace(/\/Users\/[^\s]+/g, "PATH").replace(/:\d+:\d+/g, ":LINE:COL").slice(0, 200);
412
- return crypto.createHash("sha256").update(`${toolName}:${normalized}`).digest("hex").slice(0, 16);
413
- }
414
-
415
- // src/adapters/claude/hooks/ingest.ts
416
- if (!process.env.AGENT_ID) {
417
- process.env.AGENT_ID = "default";
418
- process.env.AGENT_ROLE = "employee";
419
- }
420
- if (!loadConfigSync().autoIngestion) {
421
- process.exit(0);
422
- }
423
- var WORKER_LOG_PATH = path3.join(EXE_AI_DIR, "workers.log");
424
- function openWorkerLog() {
425
- try {
426
- return openSync(WORKER_LOG_PATH, "a");
427
- } catch {
428
- return "ignore";
429
- }
430
- }
431
- var ALLOWED_TOOL_RE = /^(Bash|Edit|Write|Read|Glob|Grep|Agent|mcp__.*)$/;
432
- var WRITE_TOOL_RE = /^(Bash|Edit|Write)$/;
433
- var SUMMARY_INTERVAL = 25;
434
- var MIN_WRITES_FOR_SUMMARY = 3;
435
- var COUNTER_DIR = path3.join(EXE_AI_DIR, "session-cache");
436
- function getCounterPath(sessionId) {
437
- return path3.join(COUNTER_DIR, `counter-${sessionId}.json`);
438
- }
439
- function loadCounter(sessionId) {
440
- try {
441
- const raw = readFileSync3(getCounterPath(sessionId), "utf8");
442
- return JSON.parse(raw);
443
- } catch {
444
- return { total: 0, writes: 0, pipelineWrites: 0, lastSummaryAt: 0, pipelineDetected: false };
445
- }
446
- }
447
- function saveCounter(sessionId, counter) {
448
- try {
449
- mkdirSync2(COUNTER_DIR, { recursive: true });
450
- writeFileSync2(getCounterPath(sessionId), JSON.stringify(counter));
451
- } catch {
452
- }
453
- }
454
- var MAX_INPUT_SIZE = 1e6;
455
- var input = "";
456
- process.stdin.setEncoding("utf8");
457
- process.stdin.on("data", (chunk) => {
458
- if (input.length < MAX_INPUT_SIZE) {
459
- input += chunk;
460
- }
461
- });
462
- process.stdin.on("end", () => {
463
- try {
464
- const data = JSON.parse(input);
465
- if (!data.tool_name) {
466
- process.exit(0);
467
- }
468
- const agent = getActiveAgent();
469
- if (/^(Read|Write|Edit)$/.test(data.tool_name) && agent.agentId !== "exe" && agent.agentId !== "default") {
470
- const filePath = data.tool_input?.file_path ?? "";
471
- const exeMatch = filePath.match(/exe\/([^/]+)\//);
472
- if (exeMatch && exeMatch[1] !== agent.agentId) {
473
- const target = exeMatch[1];
474
- const warning = JSON.stringify({
475
- hookSpecificOutput: {
476
- hookEventName: "PostToolUse",
477
- additionalContext: `## Boundary Violation
478
- BOUNDARY VIOLATION: You accessed exe/${target}/ \u2014 that is ${target}'s workspace, not yours.
479
- Your workspace is exe/${agent.agentId}/. Use ask_team_memory("${target}") if you need context from their work.
480
- Do NOT read, write, or modify files in another employee's folder.`
481
- }
482
- });
483
- process.stdout.write(warning);
484
- }
485
- }
486
- if (/^(Read|Glob|Grep|Bash)$/.test(data.tool_name) && agent.agentId === "exe") {
487
- const target = data.tool_input?.file_path ?? data.tool_input?.path ?? data.tool_input?.pattern ?? String(data.tool_input?.command ?? "");
488
- if (/exe\/exe\//.test(target)) {
489
- const warning = JSON.stringify({
490
- hookSpecificOutput: {
491
- hookEventName: "PostToolUse",
492
- additionalContext: `## Review Count Warning
493
- WARNING: exe/exe/ may contain stale done review files. NEVER count files here to determine review counts.
494
- The boot brief has the correct open review count from the DB. Use that number, not filesystem counts.
495
- Open reviews are tracked in the tasks table: SELECT COUNT(*) FROM tasks WHERE assigned_to = 'exe' AND status IN ('open','in_progress') AND task_file LIKE '%review-%'`
496
- }
497
- });
498
- process.stdout.write(warning);
499
- }
500
- }
501
- if (/^(Write|Bash)$/.test(data.tool_name) && agent.agentId !== "exe" && agent.agentId !== "default") {
502
- const filePath = data.tool_input?.file_path ?? String(data.tool_input?.command ?? "");
503
- const outputMatch = filePath.match(/exe\/output\/([^/\-]+)-([^/]+)/);
504
- if (outputMatch) {
505
- const outputAgent = outputMatch[1];
506
- if (outputAgent !== agent.agentId) {
507
- const warning = JSON.stringify({
508
- hookSpecificOutput: {
509
- hookEventName: "PostToolUse",
510
- additionalContext: `## Boundary Violation
511
- You wrote to exe/output/${outputAgent}-* \u2014 only ${outputAgent} can write files with that prefix.
512
- Your output files must start with: exe/output/${agent.agentId}-`
513
- }
514
- });
515
- process.stdout.write(warning);
516
- }
517
- }
518
- }
519
- const detectData = { tool_name: data.tool_name, tool_response: data.tool_response };
520
- if (detectError(detectData) && isExeOsError(data) && agent.agentId !== "default") {
521
- const errorText = JSON.stringify(data.tool_response).slice(0, 1e3);
522
- const classification = classifyError(errorText);
523
- if (classification === "system" && data.session_id) {
524
- const fp = errorFingerprint(data.tool_name, errorText);
525
- const fpFilePath = path3.join(COUNTER_DIR, `bug-fingerprints-${data.session_id}.json`);
526
- let fpData = {
527
- seen: {},
528
- taskCount: 0,
529
- lastTaskAt: ""
530
- };
531
- try {
532
- fpData = JSON.parse(readFileSync3(fpFilePath, "utf8"));
533
- } catch {
534
- }
535
- const now = (/* @__PURE__ */ new Date()).toISOString();
536
- const alreadySeen = fp in fpData.seen;
537
- const rateLimited = fpData.taskCount >= 5 || fpData.lastTaskAt && Date.now() - new Date(fpData.lastTaskAt).getTime() < 6e4;
538
- if (alreadySeen) {
539
- fpData.seen[fp].count++;
540
- fpData.seen[fp].lastAt = now;
541
- } else if (rateLimited) {
542
- fpData.seen[fp] = { count: 1, firstAt: now, lastAt: now };
543
- if (fpData.taskCount >= 5) {
544
- process.stderr.write("[ingest] Auto-bug rate limit reached (5 tasks this session). Suppressing.\n");
545
- }
546
- } else {
547
- fpData.seen[fp] = { count: 1, firstAt: now, lastAt: now };
548
- fpData.taskCount++;
549
- fpData.lastTaskAt = now;
550
- const bugWorkerPath = path3.resolve(
551
- path3.dirname(fileURLToPath(import.meta.url)),
552
- "bug-report-worker.js"
553
- );
554
- if (existsSync2(bugWorkerPath)) {
555
- const stderrFd2 = openWorkerLog();
556
- const projectName = process.cwd().split(path3.sep).pop() ?? "unknown";
557
- const bugToolInput = data.tool_input ?? {};
558
- const bugWorker = spawn(process.execPath, [bugWorkerPath], {
559
- detached: true,
560
- stdio: ["ignore", "ignore", stderrFd2],
561
- env: {
562
- ...process.env,
563
- BUG_TOOL_NAME: data.tool_name,
564
- BUG_ERROR_TEXT: errorText,
565
- BUG_TOOL_INPUT: JSON.stringify(bugToolInput).slice(0, 500),
566
- BUG_FINGERPRINT: fp,
567
- BUG_AGENT_ID: agent.agentId,
568
- BUG_AGENT_ROLE: agent.agentRole,
569
- BUG_PROJECT_NAME: projectName
570
- }
571
- });
572
- bugWorker.unref();
573
- if (typeof stderrFd2 === "number") try {
574
- closeSync(stderrFd2);
575
- } catch {
576
- }
577
- } else {
578
- process.stderr.write(`[ingest] WARN: bug-report-worker not found at ${bugWorkerPath}
579
- `);
580
- }
581
- }
582
- try {
583
- mkdirSync2(COUNTER_DIR, { recursive: true });
584
- writeFileSync2(fpFilePath, JSON.stringify(fpData));
585
- } catch {
586
- }
587
- }
588
- }
589
- if (data.session_id && agent.agentId !== "exe" && agent.agentId !== "default") {
590
- const counter = loadCounter(data.session_id);
591
- counter.total++;
592
- if (WRITE_TOOL_RE.test(data.tool_name)) {
593
- counter.writes++;
594
- counter.pipelineWrites++;
595
- }
596
- if (data.tool_name === "Skill" && data.tool_input?.skill === "exe-build-e2e") {
597
- counter.pipelineDetected = true;
598
- }
599
- const callsSinceLastSummary = counter.total - counter.lastSummaryAt;
600
- if (callsSinceLastSummary >= SUMMARY_INTERVAL && counter.writes >= MIN_WRITES_FOR_SUMMARY) {
601
- const summaryWorkerPath = path3.resolve(
602
- path3.dirname(fileURLToPath(import.meta.url)),
603
- "summary-worker.js"
604
- );
605
- if (existsSync2(summaryWorkerPath)) {
606
- const stderrFd2 = openWorkerLog();
607
- const summaryWorker = spawn(process.execPath, [summaryWorkerPath], {
608
- detached: true,
609
- stdio: ["ignore", "ignore", stderrFd2],
610
- env: {
611
- ...process.env,
612
- AGENT_ID: agent.agentId,
613
- AGENT_ROLE: agent.agentRole,
614
- EXE_SUMMARY_SINCE: String(counter.lastSummaryAt),
615
- EXE_SUMMARY_TOTAL: String(callsSinceLastSummary),
616
- EXE_SUMMARY_WRITES: String(counter.writes)
617
- }
618
- });
619
- summaryWorker.unref();
620
- if (typeof stderrFd2 === "number") try {
621
- closeSync(stderrFd2);
622
- } catch {
623
- }
624
- } else {
625
- process.stderr.write(`[ingest] WARN: summary-worker not found at ${summaryWorkerPath}
626
- `);
627
- }
628
- counter.lastSummaryAt = counter.total;
629
- counter.writes = 0;
630
- }
631
- saveCounter(data.session_id, counter);
632
- if (WRITE_TOOL_RE.test(data.tool_name) && counter.pipelineWrites >= 3 && !counter.pipelineDetected) {
633
- const warning = JSON.stringify({
634
- hookSpecificOutput: {
635
- hookEventName: "PostToolUse",
636
- additionalContext: "## Pipeline Warning\nWARNING: You are writing code without running the exe-build-e2e pipeline.\nIf this task adds capability or changes behavior, run /exe-build-e2e first.\nIf this is a minor fix (typo, config, one-liner), you can ignore this warning."
637
- }
638
- });
639
- process.stdout.write(warning);
640
- }
641
- }
642
- if (data.tool_name === "Bash" && agent.agentId !== "default") {
643
- const bashOutput = typeof data.tool_response === "string" ? data.tool_response : JSON.stringify(data.tool_response ?? "");
644
- const commitMatch = bashOutput.match(/\[(\S+)\s+([a-f0-9]{7,40})\]\s+(.+)/);
645
- if (commitMatch) {
646
- const commitWorkerPath = path3.resolve(
647
- path3.dirname(fileURLToPath(import.meta.url)),
648
- "commit-complete.js"
649
- );
650
- if (existsSync2(commitWorkerPath)) {
651
- const stderrFd2 = openWorkerLog();
652
- const projectName = process.cwd().split(path3.sep).pop() ?? "unknown";
653
- const commitWorker = spawn(process.execPath, [commitWorkerPath], {
654
- detached: true,
655
- stdio: ["ignore", "ignore", stderrFd2],
656
- env: {
657
- ...process.env,
658
- COMMIT_HASH: commitMatch[2],
659
- COMMIT_MESSAGE: commitMatch[3].trim(),
660
- AGENT_ID: agent.agentId,
661
- PROJECT_NAME: projectName
662
- }
663
- });
664
- commitWorker.unref();
665
- if (typeof stderrFd2 === "number") try {
666
- closeSync(stderrFd2);
667
- } catch {
668
- }
669
- }
670
- }
671
- }
672
- if (!ALLOWED_TOOL_RE.test(data.tool_name)) {
673
- process.exit(0);
674
- }
675
- const workerPath = path3.resolve(
676
- path3.dirname(fileURLToPath(import.meta.url)),
677
- "ingest-worker.js"
678
- );
679
- const stderrFd = openWorkerLog();
680
- const worker = spawn(process.execPath, [workerPath], {
681
- detached: true,
682
- stdio: ["pipe", "ignore", stderrFd],
683
- env: { ...process.env, AGENT_ID: agent.agentId, AGENT_ROLE: agent.agentRole }
684
- });
685
- worker.stdin.write(input);
686
- worker.stdin.end();
687
- worker.unref();
688
- if (typeof stderrFd === "number") try {
689
- closeSync(stderrFd);
690
- } catch {
691
- }
692
- } catch {
693
- }
694
- process.exit(0);
695
- });