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