@askexenow/exe-os 0.8.80 → 0.8.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/backfill-conversations.js +359 -267
- package/dist/bin/backfill-responses.js +357 -265
- package/dist/bin/backfill-vectors.js +339 -264
- package/dist/bin/cleanup-stale-review-tasks.js +315 -256
- package/dist/bin/cli.js +494 -240
- package/dist/bin/exe-agent.js +141 -46
- package/dist/bin/exe-assign.js +151 -63
- package/dist/bin/exe-boot.js +294 -115
- package/dist/bin/exe-call.js +76 -51
- package/dist/bin/exe-cloud.js +58 -45
- package/dist/bin/exe-dispatch.js +434 -277
- package/dist/bin/exe-doctor.js +317 -246
- package/dist/bin/exe-export-behaviors.js +328 -248
- package/dist/bin/exe-forget.js +314 -231
- package/dist/bin/exe-gateway.js +2676 -1402
- package/dist/bin/exe-heartbeat.js +329 -264
- package/dist/bin/exe-kill.js +324 -244
- package/dist/bin/exe-launch-agent.js +574 -463
- package/dist/bin/exe-link.js +1055 -95
- package/dist/bin/exe-new-employee.js +49 -54
- package/dist/bin/exe-pending-messages.js +310 -253
- package/dist/bin/exe-pending-notifications.js +299 -228
- package/dist/bin/exe-pending-reviews.js +314 -245
- package/dist/bin/exe-rename.js +259 -195
- package/dist/bin/exe-review.js +140 -64
- package/dist/bin/exe-search.js +543 -356
- package/dist/bin/exe-session-cleanup.js +463 -382
- package/dist/bin/exe-settings.js +129 -99
- package/dist/bin/exe-start.sh +6 -6
- package/dist/bin/exe-status.js +95 -36
- package/dist/bin/exe-team.js +116 -51
- package/dist/bin/git-sweep.js +482 -307
- package/dist/bin/graph-backfill.js +357 -245
- package/dist/bin/graph-export.js +324 -244
- package/dist/bin/install.js +33 -10
- package/dist/bin/scan-tasks.js +481 -307
- package/dist/bin/setup.js +1147 -140
- package/dist/bin/shard-migrate.js +321 -241
- package/dist/bin/update.js +1 -7
- package/dist/bin/wiki-sync.js +318 -238
- package/dist/gateway/index.js +2656 -1383
- package/dist/hooks/bug-report-worker.js +641 -472
- package/dist/hooks/commit-complete.js +482 -307
- package/dist/hooks/error-recall.js +363 -135
- package/dist/hooks/exe-heartbeat-hook.js +97 -27
- package/dist/hooks/ingest-worker.js +584 -397
- package/dist/hooks/ingest.js +123 -58
- package/dist/hooks/instructions-loaded.js +212 -82
- package/dist/hooks/notification.js +200 -70
- package/dist/hooks/post-compact.js +199 -81
- package/dist/hooks/pre-compact.js +352 -140
- package/dist/hooks/pre-tool-use.js +416 -278
- package/dist/hooks/prompt-ingest-worker.js +376 -299
- package/dist/hooks/prompt-submit.js +414 -188
- package/dist/hooks/response-ingest-worker.js +408 -338
- package/dist/hooks/session-end.js +209 -83
- package/dist/hooks/session-start.js +382 -158
- package/dist/hooks/stop.js +209 -83
- package/dist/hooks/subagent-stop.js +209 -85
- package/dist/hooks/summary-worker.js +606 -510
- package/dist/index.js +2133 -855
- package/dist/lib/cloud-sync.js +1175 -184
- package/dist/lib/config.js +1 -9
- package/dist/lib/consolidation.js +71 -34
- package/dist/lib/database.js +166 -14
- package/dist/lib/device-registry.js +189 -117
- package/dist/lib/embedder.js +6 -10
- package/dist/lib/employee-templates.js +134 -39
- package/dist/lib/employees.js +30 -7
- package/dist/lib/exe-daemon-client.js +5 -7
- package/dist/lib/exe-daemon.js +514 -152
- package/dist/lib/hybrid-search.js +543 -356
- package/dist/lib/identity-templates.js +15 -15
- package/dist/lib/identity.js +19 -15
- package/dist/lib/license.js +1 -7
- package/dist/lib/messaging.js +157 -135
- package/dist/lib/reminders.js +97 -0
- package/dist/lib/schedules.js +302 -231
- package/dist/lib/skill-learning.js +33 -27
- package/dist/lib/status-brief.js +11 -14
- package/dist/lib/store.js +326 -237
- package/dist/lib/task-router.js +105 -1
- package/dist/lib/tasks.js +233 -116
- package/dist/lib/tmux-routing.js +173 -56
- package/dist/lib/ws-client.js +13 -3
- package/dist/mcp/server.js +2009 -1015
- package/dist/mcp/tools/complete-reminder.js +97 -0
- package/dist/mcp/tools/create-reminder.js +97 -0
- package/dist/mcp/tools/create-task.js +426 -262
- package/dist/mcp/tools/deactivate-behavior.js +119 -44
- package/dist/mcp/tools/list-reminders.js +97 -0
- package/dist/mcp/tools/list-tasks.js +56 -57
- package/dist/mcp/tools/send-message.js +206 -143
- package/dist/mcp/tools/update-task.js +259 -85
- package/dist/runtime/index.js +495 -316
- package/dist/tui/App.js +1128 -919
- package/package.json +2 -10
- package/src/commands/exe/afk.md +8 -8
- package/src/commands/exe/assign.md +1 -1
- package/src/commands/exe/build-adv.md +1 -1
- package/src/commands/exe/call.md +10 -10
- package/src/commands/exe/employee-heartbeat.md +9 -6
- package/src/commands/exe/heartbeat.md +5 -5
- package/src/commands/exe/intercom.md +26 -15
- package/src/commands/exe/launch.md +2 -2
- package/src/commands/exe/new-employee.md +1 -1
- package/src/commands/exe/review.md +2 -2
- package/src/commands/exe/schedule.md +1 -1
- package/src/commands/exe/sessions.md +2 -2
- package/src/commands/exe.md +22 -20
|
@@ -56,7 +56,7 @@ function wrapWithRetry(client) {
|
|
|
56
56
|
return (sql) => retryOnBusy(() => target.execute(sql), "execute");
|
|
57
57
|
}
|
|
58
58
|
if (prop === "batch") {
|
|
59
|
-
return (stmts) => retryOnBusy(() => target.batch(stmts), "batch");
|
|
59
|
+
return (stmts, mode) => retryOnBusy(() => target.batch(stmts, mode), "batch");
|
|
60
60
|
}
|
|
61
61
|
return Reflect.get(target, prop, receiver);
|
|
62
62
|
}
|
|
@@ -72,6 +72,283 @@ var init_db_retry = __esm({
|
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
+
// src/lib/config.ts
|
|
76
|
+
var config_exports = {};
|
|
77
|
+
__export(config_exports, {
|
|
78
|
+
CONFIG_MIGRATIONS: () => CONFIG_MIGRATIONS,
|
|
79
|
+
CONFIG_PATH: () => CONFIG_PATH,
|
|
80
|
+
CURRENT_CONFIG_VERSION: () => CURRENT_CONFIG_VERSION,
|
|
81
|
+
DB_PATH: () => DB_PATH,
|
|
82
|
+
EXE_AI_DIR: () => EXE_AI_DIR,
|
|
83
|
+
LEGACY_LANCE_PATH: () => LEGACY_LANCE_PATH,
|
|
84
|
+
MODELS_DIR: () => MODELS_DIR,
|
|
85
|
+
loadConfig: () => loadConfig,
|
|
86
|
+
loadConfigFrom: () => loadConfigFrom,
|
|
87
|
+
loadConfigSync: () => loadConfigSync,
|
|
88
|
+
migrateConfig: () => migrateConfig,
|
|
89
|
+
saveConfig: () => saveConfig
|
|
90
|
+
});
|
|
91
|
+
import { readFile, writeFile, mkdir, chmod } from "fs/promises";
|
|
92
|
+
import { readFileSync, existsSync, renameSync } from "fs";
|
|
93
|
+
import path from "path";
|
|
94
|
+
import os from "os";
|
|
95
|
+
function resolveDataDir() {
|
|
96
|
+
if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
|
|
97
|
+
if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
|
|
98
|
+
const newDir = path.join(os.homedir(), ".exe-os");
|
|
99
|
+
const legacyDir = path.join(os.homedir(), ".exe-mem");
|
|
100
|
+
if (!existsSync(newDir) && existsSync(legacyDir)) {
|
|
101
|
+
try {
|
|
102
|
+
renameSync(legacyDir, newDir);
|
|
103
|
+
process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
|
|
104
|
+
`);
|
|
105
|
+
} catch {
|
|
106
|
+
return legacyDir;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return newDir;
|
|
110
|
+
}
|
|
111
|
+
function migrateLegacyConfig(raw) {
|
|
112
|
+
if ("r2" in raw) {
|
|
113
|
+
process.stderr.write(
|
|
114
|
+
"[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"
|
|
115
|
+
);
|
|
116
|
+
delete raw.r2;
|
|
117
|
+
}
|
|
118
|
+
if ("syncIntervalMs" in raw) {
|
|
119
|
+
delete raw.syncIntervalMs;
|
|
120
|
+
}
|
|
121
|
+
return raw;
|
|
122
|
+
}
|
|
123
|
+
function migrateConfig(raw) {
|
|
124
|
+
const fromVersion = typeof raw.config_version === "number" ? raw.config_version : 0;
|
|
125
|
+
let currentVersion = fromVersion;
|
|
126
|
+
let migrated = false;
|
|
127
|
+
if (currentVersion > CURRENT_CONFIG_VERSION) {
|
|
128
|
+
return { config: raw, migrated: false, fromVersion };
|
|
129
|
+
}
|
|
130
|
+
for (const migration of CONFIG_MIGRATIONS) {
|
|
131
|
+
if (currentVersion === migration.from && migration.to <= CURRENT_CONFIG_VERSION) {
|
|
132
|
+
raw = migration.migrate(raw);
|
|
133
|
+
currentVersion = migration.to;
|
|
134
|
+
migrated = true;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { config: raw, migrated, fromVersion };
|
|
138
|
+
}
|
|
139
|
+
function normalizeScalingRoadmap(raw) {
|
|
140
|
+
const defaultAuto = DEFAULT_CONFIG.scalingRoadmap.rerankerAutoTrigger;
|
|
141
|
+
const userRoadmap = raw.scalingRoadmap ?? {};
|
|
142
|
+
const userAuto = userRoadmap.rerankerAutoTrigger ?? {};
|
|
143
|
+
if (userAuto.enabled === void 0 && raw.rerankerEnabled !== void 0) {
|
|
144
|
+
userAuto.enabled = raw.rerankerEnabled;
|
|
145
|
+
}
|
|
146
|
+
raw.scalingRoadmap = {
|
|
147
|
+
...userRoadmap,
|
|
148
|
+
rerankerAutoTrigger: { ...defaultAuto, ...userAuto }
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function normalizeSessionLifecycle(raw) {
|
|
152
|
+
const defaultSL = DEFAULT_CONFIG.sessionLifecycle;
|
|
153
|
+
const userSL = raw.sessionLifecycle ?? {};
|
|
154
|
+
raw.sessionLifecycle = { ...defaultSL, ...userSL };
|
|
155
|
+
}
|
|
156
|
+
function normalizeAutoUpdate(raw) {
|
|
157
|
+
const defaultAU = DEFAULT_CONFIG.autoUpdate;
|
|
158
|
+
const userAU = raw.autoUpdate ?? {};
|
|
159
|
+
raw.autoUpdate = { ...defaultAU, ...userAU };
|
|
160
|
+
}
|
|
161
|
+
async function loadConfig() {
|
|
162
|
+
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
163
|
+
await mkdir(dir, { recursive: true });
|
|
164
|
+
const configPath = path.join(dir, "config.json");
|
|
165
|
+
if (!existsSync(configPath)) {
|
|
166
|
+
return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
|
|
167
|
+
}
|
|
168
|
+
const raw = await readFile(configPath, "utf-8");
|
|
169
|
+
try {
|
|
170
|
+
let parsed = JSON.parse(raw);
|
|
171
|
+
parsed = migrateLegacyConfig(parsed);
|
|
172
|
+
const { config: migratedCfg, migrated, fromVersion } = migrateConfig(parsed);
|
|
173
|
+
if (migrated) {
|
|
174
|
+
process.stderr.write(`[exe-os] Config migrated from v${fromVersion} to v${migratedCfg.config_version}
|
|
175
|
+
`);
|
|
176
|
+
try {
|
|
177
|
+
await writeFile(configPath, JSON.stringify(migratedCfg, null, 2) + "\n");
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
normalizeScalingRoadmap(migratedCfg);
|
|
182
|
+
normalizeSessionLifecycle(migratedCfg);
|
|
183
|
+
normalizeAutoUpdate(migratedCfg);
|
|
184
|
+
const config = { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
|
|
185
|
+
if (config.dbPath.startsWith("~")) {
|
|
186
|
+
config.dbPath = config.dbPath.replace(/^~/, os.homedir());
|
|
187
|
+
}
|
|
188
|
+
return config;
|
|
189
|
+
} catch {
|
|
190
|
+
return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function loadConfigSync() {
|
|
194
|
+
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
195
|
+
const configPath = path.join(dir, "config.json");
|
|
196
|
+
if (!existsSync(configPath)) {
|
|
197
|
+
return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
const raw = readFileSync(configPath, "utf-8");
|
|
201
|
+
let parsed = JSON.parse(raw);
|
|
202
|
+
parsed = migrateLegacyConfig(parsed);
|
|
203
|
+
const { config: migratedCfg } = migrateConfig(parsed);
|
|
204
|
+
normalizeScalingRoadmap(migratedCfg);
|
|
205
|
+
normalizeSessionLifecycle(migratedCfg);
|
|
206
|
+
normalizeAutoUpdate(migratedCfg);
|
|
207
|
+
return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
|
|
208
|
+
} catch {
|
|
209
|
+
return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async function saveConfig(config) {
|
|
213
|
+
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
214
|
+
await mkdir(dir, { recursive: true });
|
|
215
|
+
const configPath = path.join(dir, "config.json");
|
|
216
|
+
await writeFile(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
217
|
+
if (config.cloud?.apiKey) {
|
|
218
|
+
await chmod(configPath, 384);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
async function loadConfigFrom(configPath) {
|
|
222
|
+
const raw = await readFile(configPath, "utf-8");
|
|
223
|
+
try {
|
|
224
|
+
let parsed = JSON.parse(raw);
|
|
225
|
+
parsed = migrateLegacyConfig(parsed);
|
|
226
|
+
const { config: migratedCfg } = migrateConfig(parsed);
|
|
227
|
+
normalizeScalingRoadmap(migratedCfg);
|
|
228
|
+
normalizeSessionLifecycle(migratedCfg);
|
|
229
|
+
normalizeAutoUpdate(migratedCfg);
|
|
230
|
+
return { ...DEFAULT_CONFIG, ...migratedCfg };
|
|
231
|
+
} catch {
|
|
232
|
+
return { ...DEFAULT_CONFIG };
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
var EXE_AI_DIR, DB_PATH, MODELS_DIR, CONFIG_PATH, LEGACY_LANCE_PATH, CURRENT_CONFIG_VERSION, DEFAULT_CONFIG, CONFIG_MIGRATIONS;
|
|
236
|
+
var init_config = __esm({
|
|
237
|
+
"src/lib/config.ts"() {
|
|
238
|
+
"use strict";
|
|
239
|
+
EXE_AI_DIR = resolveDataDir();
|
|
240
|
+
DB_PATH = path.join(EXE_AI_DIR, "memories.db");
|
|
241
|
+
MODELS_DIR = path.join(EXE_AI_DIR, "models");
|
|
242
|
+
CONFIG_PATH = path.join(EXE_AI_DIR, "config.json");
|
|
243
|
+
LEGACY_LANCE_PATH = path.join(EXE_AI_DIR, "local.lance");
|
|
244
|
+
CURRENT_CONFIG_VERSION = 1;
|
|
245
|
+
DEFAULT_CONFIG = {
|
|
246
|
+
config_version: CURRENT_CONFIG_VERSION,
|
|
247
|
+
dbPath: DB_PATH,
|
|
248
|
+
modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
|
|
249
|
+
embeddingDim: 1024,
|
|
250
|
+
batchSize: 20,
|
|
251
|
+
flushIntervalMs: 1e4,
|
|
252
|
+
autoIngestion: true,
|
|
253
|
+
autoRetrieval: true,
|
|
254
|
+
searchMode: "hybrid",
|
|
255
|
+
hookSearchMode: "hybrid",
|
|
256
|
+
fileGrepEnabled: true,
|
|
257
|
+
splashEffect: true,
|
|
258
|
+
consolidationEnabled: true,
|
|
259
|
+
consolidationIntervalMs: 6 * 60 * 60 * 1e3,
|
|
260
|
+
consolidationModel: "claude-haiku-4-5-20251001",
|
|
261
|
+
consolidationMaxCallsPerRun: 20,
|
|
262
|
+
selfQueryRouter: true,
|
|
263
|
+
selfQueryModel: "claude-haiku-4-5-20251001",
|
|
264
|
+
rerankerEnabled: true,
|
|
265
|
+
scalingRoadmap: {
|
|
266
|
+
rerankerAutoTrigger: {
|
|
267
|
+
enabled: true,
|
|
268
|
+
broadQueryMinCardinality: 5e4,
|
|
269
|
+
fetchTopK: 150,
|
|
270
|
+
returnTopK: 5
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
graphRagEnabled: true,
|
|
274
|
+
wikiEnabled: false,
|
|
275
|
+
wikiUrl: "",
|
|
276
|
+
wikiApiKey: "",
|
|
277
|
+
wikiSyncIntervalMs: 30 * 60 * 1e3,
|
|
278
|
+
wikiWorkspaceMapping: {},
|
|
279
|
+
wikiAutoUpdate: true,
|
|
280
|
+
wikiAutoUpdateThreshold: 0.5,
|
|
281
|
+
wikiAutoUpdateCreateNew: true,
|
|
282
|
+
skillLearning: true,
|
|
283
|
+
skillThreshold: 3,
|
|
284
|
+
skillModel: "claude-haiku-4-5-20251001",
|
|
285
|
+
exeHeartbeat: {
|
|
286
|
+
enabled: true,
|
|
287
|
+
intervalSeconds: 60,
|
|
288
|
+
staleInProgressThresholdHours: 2
|
|
289
|
+
},
|
|
290
|
+
sessionLifecycle: {
|
|
291
|
+
idleKillEnabled: true,
|
|
292
|
+
idleKillTicksRequired: 3,
|
|
293
|
+
idleKillIntercomAckWindowMs: 1e4,
|
|
294
|
+
maxAutoInstances: 10
|
|
295
|
+
},
|
|
296
|
+
autoUpdate: {
|
|
297
|
+
checkOnBoot: true,
|
|
298
|
+
autoInstall: false,
|
|
299
|
+
checkIntervalMs: 24 * 60 * 60 * 1e3
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
CONFIG_MIGRATIONS = [
|
|
303
|
+
{
|
|
304
|
+
from: 0,
|
|
305
|
+
to: 1,
|
|
306
|
+
migrate: (cfg) => {
|
|
307
|
+
cfg.config_version = 1;
|
|
308
|
+
return cfg;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
];
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// src/lib/employees.ts
|
|
316
|
+
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
317
|
+
import { existsSync as existsSync2, symlinkSync, readlinkSync, readFileSync as readFileSync2, renameSync as renameSync2, unlinkSync, writeFileSync } from "fs";
|
|
318
|
+
import { execSync } from "child_process";
|
|
319
|
+
import path2 from "path";
|
|
320
|
+
import os2 from "os";
|
|
321
|
+
function normalizeRole(role) {
|
|
322
|
+
return (role ?? "").trim().toLowerCase();
|
|
323
|
+
}
|
|
324
|
+
function isCoordinatorRole(role) {
|
|
325
|
+
return normalizeRole(role) === normalizeRole(COORDINATOR_ROLE);
|
|
326
|
+
}
|
|
327
|
+
function getCoordinatorEmployee(employees) {
|
|
328
|
+
return employees.find((e) => isCoordinatorRole(e.role));
|
|
329
|
+
}
|
|
330
|
+
function getCoordinatorName(employees = loadEmployeesSync()) {
|
|
331
|
+
return getCoordinatorEmployee(employees)?.name ?? DEFAULT_COORDINATOR_TEMPLATE_NAME;
|
|
332
|
+
}
|
|
333
|
+
function loadEmployeesSync(employeesPath = EMPLOYEES_PATH) {
|
|
334
|
+
if (!existsSync2(employeesPath)) return [];
|
|
335
|
+
try {
|
|
336
|
+
return JSON.parse(readFileSync2(employeesPath, "utf-8"));
|
|
337
|
+
} catch {
|
|
338
|
+
return [];
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
var EMPLOYEES_PATH, DEFAULT_COORDINATOR_TEMPLATE_NAME, COORDINATOR_ROLE;
|
|
342
|
+
var init_employees = __esm({
|
|
343
|
+
"src/lib/employees.ts"() {
|
|
344
|
+
"use strict";
|
|
345
|
+
init_config();
|
|
346
|
+
EMPLOYEES_PATH = path2.join(EXE_AI_DIR, "exe-employees.json");
|
|
347
|
+
DEFAULT_COORDINATOR_TEMPLATE_NAME = "exe";
|
|
348
|
+
COORDINATOR_ROLE = "COO";
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
75
352
|
// src/lib/database.ts
|
|
76
353
|
import { createClient } from "@libsql/client";
|
|
77
354
|
async function initDatabase(config) {
|
|
@@ -205,22 +482,24 @@ async function ensureSchema() {
|
|
|
205
482
|
ON behaviors(agent_id, active);
|
|
206
483
|
`);
|
|
207
484
|
try {
|
|
485
|
+
const coordinatorName = getCoordinatorName();
|
|
208
486
|
const existing = await client.execute({
|
|
209
|
-
sql: "SELECT COUNT(*) as cnt FROM behaviors WHERE agent_id =
|
|
210
|
-
args: []
|
|
487
|
+
sql: "SELECT COUNT(*) as cnt FROM behaviors WHERE agent_id = ?",
|
|
488
|
+
args: [coordinatorName]
|
|
211
489
|
});
|
|
212
490
|
if (Number(existing.rows[0]?.cnt) === 0) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
491
|
+
const seededAt = "2026-03-25T00:00:00Z";
|
|
492
|
+
for (const [domain, content] of [
|
|
493
|
+
["workflow", `Don't ask "keep going?" \u2014 just keep executing phases/plans autonomously`],
|
|
494
|
+
["tool-use", "Always use create_task MCP tool, never write .md files directly for task creation"],
|
|
495
|
+
["workflow", "Auto-start reviewing when idle and reviews are pending \u2014 never ask founder for permission"]
|
|
496
|
+
]) {
|
|
497
|
+
await client.execute({
|
|
498
|
+
sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, content, active, created_at, updated_at)
|
|
499
|
+
VALUES (hex(randomblob(16)), ?, NULL, ?, ?, 1, ?, ?)`,
|
|
500
|
+
args: [coordinatorName, domain, content, seededAt, seededAt]
|
|
501
|
+
});
|
|
502
|
+
}
|
|
224
503
|
}
|
|
225
504
|
} catch {
|
|
226
505
|
}
|
|
@@ -912,6 +1191,39 @@ async function ensureSchema() {
|
|
|
912
1191
|
} catch {
|
|
913
1192
|
}
|
|
914
1193
|
}
|
|
1194
|
+
try {
|
|
1195
|
+
await client.execute({
|
|
1196
|
+
sql: `ALTER TABLE memories ADD COLUMN draft INTEGER DEFAULT 0`,
|
|
1197
|
+
args: []
|
|
1198
|
+
});
|
|
1199
|
+
} catch {
|
|
1200
|
+
}
|
|
1201
|
+
try {
|
|
1202
|
+
await client.execute(
|
|
1203
|
+
`CREATE INDEX IF NOT EXISTS idx_memories_draft ON memories(draft) WHERE draft = 1`
|
|
1204
|
+
);
|
|
1205
|
+
} catch {
|
|
1206
|
+
}
|
|
1207
|
+
try {
|
|
1208
|
+
await client.execute({
|
|
1209
|
+
sql: `ALTER TABLE memories ADD COLUMN memory_type TEXT DEFAULT 'raw'`,
|
|
1210
|
+
args: []
|
|
1211
|
+
});
|
|
1212
|
+
} catch {
|
|
1213
|
+
}
|
|
1214
|
+
try {
|
|
1215
|
+
await client.execute(
|
|
1216
|
+
`CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(memory_type)`
|
|
1217
|
+
);
|
|
1218
|
+
} catch {
|
|
1219
|
+
}
|
|
1220
|
+
try {
|
|
1221
|
+
await client.execute({
|
|
1222
|
+
sql: `ALTER TABLE memories ADD COLUMN trajectory TEXT`,
|
|
1223
|
+
args: []
|
|
1224
|
+
});
|
|
1225
|
+
} catch {
|
|
1226
|
+
}
|
|
915
1227
|
}
|
|
916
1228
|
async function disposeDatabase() {
|
|
917
1229
|
if (_client) {
|
|
@@ -925,6 +1237,7 @@ var init_database = __esm({
|
|
|
925
1237
|
"src/lib/database.ts"() {
|
|
926
1238
|
"use strict";
|
|
927
1239
|
init_db_retry();
|
|
1240
|
+
init_employees();
|
|
928
1241
|
_client = null;
|
|
929
1242
|
_resilientClient = null;
|
|
930
1243
|
initTurso = initDatabase;
|
|
@@ -933,15 +1246,15 @@ var init_database = __esm({
|
|
|
933
1246
|
});
|
|
934
1247
|
|
|
935
1248
|
// src/lib/keychain.ts
|
|
936
|
-
import { readFile, writeFile, unlink, mkdir, chmod } from "fs/promises";
|
|
937
|
-
import { existsSync } from "fs";
|
|
938
|
-
import
|
|
939
|
-
import
|
|
1249
|
+
import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
|
|
1250
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1251
|
+
import path3 from "path";
|
|
1252
|
+
import os3 from "os";
|
|
940
1253
|
function getKeyDir() {
|
|
941
|
-
return process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ??
|
|
1254
|
+
return process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? path3.join(os3.homedir(), ".exe-os");
|
|
942
1255
|
}
|
|
943
1256
|
function getKeyPath() {
|
|
944
|
-
return
|
|
1257
|
+
return path3.join(getKeyDir(), "master.key");
|
|
945
1258
|
}
|
|
946
1259
|
async function tryKeytar() {
|
|
947
1260
|
try {
|
|
@@ -962,11 +1275,11 @@ async function getMasterKey() {
|
|
|
962
1275
|
}
|
|
963
1276
|
}
|
|
964
1277
|
const keyPath = getKeyPath();
|
|
965
|
-
if (!
|
|
1278
|
+
if (!existsSync3(keyPath)) {
|
|
966
1279
|
return null;
|
|
967
1280
|
}
|
|
968
1281
|
try {
|
|
969
|
-
const content = await
|
|
1282
|
+
const content = await readFile3(keyPath, "utf-8");
|
|
970
1283
|
return Buffer.from(content.trim(), "base64");
|
|
971
1284
|
} catch {
|
|
972
1285
|
return null;
|
|
@@ -981,254 +1294,6 @@ var init_keychain = __esm({
|
|
|
981
1294
|
}
|
|
982
1295
|
});
|
|
983
1296
|
|
|
984
|
-
// src/lib/config.ts
|
|
985
|
-
var config_exports = {};
|
|
986
|
-
__export(config_exports, {
|
|
987
|
-
CONFIG_MIGRATIONS: () => CONFIG_MIGRATIONS,
|
|
988
|
-
CONFIG_PATH: () => CONFIG_PATH,
|
|
989
|
-
COO_AGENT_NAME: () => COO_AGENT_NAME,
|
|
990
|
-
CURRENT_CONFIG_VERSION: () => CURRENT_CONFIG_VERSION,
|
|
991
|
-
DB_PATH: () => DB_PATH,
|
|
992
|
-
EXE_AI_DIR: () => EXE_AI_DIR,
|
|
993
|
-
LEGACY_LANCE_PATH: () => LEGACY_LANCE_PATH,
|
|
994
|
-
MODELS_DIR: () => MODELS_DIR,
|
|
995
|
-
loadConfig: () => loadConfig,
|
|
996
|
-
loadConfigFrom: () => loadConfigFrom,
|
|
997
|
-
loadConfigSync: () => loadConfigSync,
|
|
998
|
-
migrateConfig: () => migrateConfig,
|
|
999
|
-
saveConfig: () => saveConfig
|
|
1000
|
-
});
|
|
1001
|
-
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2, chmod as chmod2 } from "fs/promises";
|
|
1002
|
-
import { readFileSync, existsSync as existsSync2, renameSync } from "fs";
|
|
1003
|
-
import path2 from "path";
|
|
1004
|
-
import os2 from "os";
|
|
1005
|
-
function resolveDataDir() {
|
|
1006
|
-
if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
|
|
1007
|
-
if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
|
|
1008
|
-
const newDir = path2.join(os2.homedir(), ".exe-os");
|
|
1009
|
-
const legacyDir = path2.join(os2.homedir(), ".exe-mem");
|
|
1010
|
-
if (!existsSync2(newDir) && existsSync2(legacyDir)) {
|
|
1011
|
-
try {
|
|
1012
|
-
renameSync(legacyDir, newDir);
|
|
1013
|
-
process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
|
|
1014
|
-
`);
|
|
1015
|
-
} catch {
|
|
1016
|
-
return legacyDir;
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
return newDir;
|
|
1020
|
-
}
|
|
1021
|
-
function migrateLegacyConfig(raw) {
|
|
1022
|
-
if ("r2" in raw) {
|
|
1023
|
-
process.stderr.write(
|
|
1024
|
-
"[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"
|
|
1025
|
-
);
|
|
1026
|
-
delete raw.r2;
|
|
1027
|
-
}
|
|
1028
|
-
if ("syncIntervalMs" in raw) {
|
|
1029
|
-
delete raw.syncIntervalMs;
|
|
1030
|
-
}
|
|
1031
|
-
return raw;
|
|
1032
|
-
}
|
|
1033
|
-
function migrateConfig(raw) {
|
|
1034
|
-
const fromVersion = typeof raw.config_version === "number" ? raw.config_version : 0;
|
|
1035
|
-
let currentVersion = fromVersion;
|
|
1036
|
-
let migrated = false;
|
|
1037
|
-
if (currentVersion > CURRENT_CONFIG_VERSION) {
|
|
1038
|
-
return { config: raw, migrated: false, fromVersion };
|
|
1039
|
-
}
|
|
1040
|
-
for (const migration of CONFIG_MIGRATIONS) {
|
|
1041
|
-
if (currentVersion === migration.from && migration.to <= CURRENT_CONFIG_VERSION) {
|
|
1042
|
-
raw = migration.migrate(raw);
|
|
1043
|
-
currentVersion = migration.to;
|
|
1044
|
-
migrated = true;
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
return { config: raw, migrated, fromVersion };
|
|
1048
|
-
}
|
|
1049
|
-
function normalizeScalingRoadmap(raw) {
|
|
1050
|
-
const defaultAuto = DEFAULT_CONFIG.scalingRoadmap.rerankerAutoTrigger;
|
|
1051
|
-
const userRoadmap = raw.scalingRoadmap ?? {};
|
|
1052
|
-
const userAuto = userRoadmap.rerankerAutoTrigger ?? {};
|
|
1053
|
-
if (userAuto.enabled === void 0 && raw.rerankerEnabled !== void 0) {
|
|
1054
|
-
userAuto.enabled = raw.rerankerEnabled;
|
|
1055
|
-
}
|
|
1056
|
-
raw.scalingRoadmap = {
|
|
1057
|
-
...userRoadmap,
|
|
1058
|
-
rerankerAutoTrigger: { ...defaultAuto, ...userAuto }
|
|
1059
|
-
};
|
|
1060
|
-
}
|
|
1061
|
-
function normalizeSessionLifecycle(raw) {
|
|
1062
|
-
const defaultSL = DEFAULT_CONFIG.sessionLifecycle;
|
|
1063
|
-
const userSL = raw.sessionLifecycle ?? {};
|
|
1064
|
-
raw.sessionLifecycle = { ...defaultSL, ...userSL };
|
|
1065
|
-
}
|
|
1066
|
-
function normalizeAutoUpdate(raw) {
|
|
1067
|
-
const defaultAU = DEFAULT_CONFIG.autoUpdate;
|
|
1068
|
-
const userAU = raw.autoUpdate ?? {};
|
|
1069
|
-
raw.autoUpdate = { ...defaultAU, ...userAU };
|
|
1070
|
-
}
|
|
1071
|
-
async function loadConfig() {
|
|
1072
|
-
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
1073
|
-
await mkdir2(dir, { recursive: true });
|
|
1074
|
-
const configPath = path2.join(dir, "config.json");
|
|
1075
|
-
if (!existsSync2(configPath)) {
|
|
1076
|
-
return { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db") };
|
|
1077
|
-
}
|
|
1078
|
-
const raw = await readFile2(configPath, "utf-8");
|
|
1079
|
-
try {
|
|
1080
|
-
let parsed = JSON.parse(raw);
|
|
1081
|
-
parsed = migrateLegacyConfig(parsed);
|
|
1082
|
-
const { config: migratedCfg, migrated, fromVersion } = migrateConfig(parsed);
|
|
1083
|
-
if (migrated) {
|
|
1084
|
-
process.stderr.write(`[exe-os] Config migrated from v${fromVersion} to v${migratedCfg.config_version}
|
|
1085
|
-
`);
|
|
1086
|
-
try {
|
|
1087
|
-
await writeFile2(configPath, JSON.stringify(migratedCfg, null, 2) + "\n");
|
|
1088
|
-
} catch {
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
normalizeScalingRoadmap(migratedCfg);
|
|
1092
|
-
normalizeSessionLifecycle(migratedCfg);
|
|
1093
|
-
normalizeAutoUpdate(migratedCfg);
|
|
1094
|
-
const config = { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db"), ...migratedCfg };
|
|
1095
|
-
if (config.dbPath.startsWith("~")) {
|
|
1096
|
-
config.dbPath = config.dbPath.replace(/^~/, os2.homedir());
|
|
1097
|
-
}
|
|
1098
|
-
return config;
|
|
1099
|
-
} catch {
|
|
1100
|
-
return { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db") };
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
function loadConfigSync() {
|
|
1104
|
-
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
1105
|
-
const configPath = path2.join(dir, "config.json");
|
|
1106
|
-
if (!existsSync2(configPath)) {
|
|
1107
|
-
return { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db") };
|
|
1108
|
-
}
|
|
1109
|
-
try {
|
|
1110
|
-
const raw = readFileSync(configPath, "utf-8");
|
|
1111
|
-
let parsed = JSON.parse(raw);
|
|
1112
|
-
parsed = migrateLegacyConfig(parsed);
|
|
1113
|
-
const { config: migratedCfg } = migrateConfig(parsed);
|
|
1114
|
-
normalizeScalingRoadmap(migratedCfg);
|
|
1115
|
-
normalizeSessionLifecycle(migratedCfg);
|
|
1116
|
-
normalizeAutoUpdate(migratedCfg);
|
|
1117
|
-
return { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db"), ...migratedCfg };
|
|
1118
|
-
} catch {
|
|
1119
|
-
return { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db") };
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
async function saveConfig(config) {
|
|
1123
|
-
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
1124
|
-
await mkdir2(dir, { recursive: true });
|
|
1125
|
-
const configPath = path2.join(dir, "config.json");
|
|
1126
|
-
await writeFile2(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
1127
|
-
if (config.cloud?.apiKey) {
|
|
1128
|
-
await chmod2(configPath, 384);
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
async function loadConfigFrom(configPath) {
|
|
1132
|
-
const raw = await readFile2(configPath, "utf-8");
|
|
1133
|
-
try {
|
|
1134
|
-
let parsed = JSON.parse(raw);
|
|
1135
|
-
parsed = migrateLegacyConfig(parsed);
|
|
1136
|
-
const { config: migratedCfg } = migrateConfig(parsed);
|
|
1137
|
-
normalizeScalingRoadmap(migratedCfg);
|
|
1138
|
-
normalizeSessionLifecycle(migratedCfg);
|
|
1139
|
-
normalizeAutoUpdate(migratedCfg);
|
|
1140
|
-
return { ...DEFAULT_CONFIG, ...migratedCfg };
|
|
1141
|
-
} catch {
|
|
1142
|
-
return { ...DEFAULT_CONFIG };
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
var EXE_AI_DIR, DB_PATH, MODELS_DIR, CONFIG_PATH, COO_AGENT_NAME, LEGACY_LANCE_PATH, CURRENT_CONFIG_VERSION, DEFAULT_CONFIG, CONFIG_MIGRATIONS;
|
|
1146
|
-
var init_config = __esm({
|
|
1147
|
-
"src/lib/config.ts"() {
|
|
1148
|
-
"use strict";
|
|
1149
|
-
EXE_AI_DIR = resolveDataDir();
|
|
1150
|
-
DB_PATH = path2.join(EXE_AI_DIR, "memories.db");
|
|
1151
|
-
MODELS_DIR = path2.join(EXE_AI_DIR, "models");
|
|
1152
|
-
CONFIG_PATH = path2.join(EXE_AI_DIR, "config.json");
|
|
1153
|
-
COO_AGENT_NAME = "exe";
|
|
1154
|
-
LEGACY_LANCE_PATH = path2.join(EXE_AI_DIR, "local.lance");
|
|
1155
|
-
CURRENT_CONFIG_VERSION = 1;
|
|
1156
|
-
DEFAULT_CONFIG = {
|
|
1157
|
-
config_version: CURRENT_CONFIG_VERSION,
|
|
1158
|
-
dbPath: DB_PATH,
|
|
1159
|
-
modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
|
|
1160
|
-
embeddingDim: 1024,
|
|
1161
|
-
batchSize: 20,
|
|
1162
|
-
flushIntervalMs: 1e4,
|
|
1163
|
-
autoIngestion: true,
|
|
1164
|
-
autoRetrieval: true,
|
|
1165
|
-
searchMode: "hybrid",
|
|
1166
|
-
hookSearchMode: "hybrid",
|
|
1167
|
-
fileGrepEnabled: true,
|
|
1168
|
-
splashEffect: true,
|
|
1169
|
-
consolidationEnabled: true,
|
|
1170
|
-
consolidationIntervalMs: 6 * 60 * 60 * 1e3,
|
|
1171
|
-
consolidationModel: "claude-haiku-4-5-20251001",
|
|
1172
|
-
consolidationMaxCallsPerRun: 20,
|
|
1173
|
-
selfQueryRouter: true,
|
|
1174
|
-
selfQueryModel: "claude-haiku-4-5-20251001",
|
|
1175
|
-
rerankerEnabled: true,
|
|
1176
|
-
scalingRoadmap: {
|
|
1177
|
-
rerankerAutoTrigger: {
|
|
1178
|
-
enabled: true,
|
|
1179
|
-
broadQueryMinCardinality: 5e4,
|
|
1180
|
-
fetchTopK: 150,
|
|
1181
|
-
returnTopK: 5
|
|
1182
|
-
}
|
|
1183
|
-
},
|
|
1184
|
-
graphRagEnabled: true,
|
|
1185
|
-
wikiEnabled: false,
|
|
1186
|
-
wikiUrl: "",
|
|
1187
|
-
wikiApiKey: "",
|
|
1188
|
-
wikiSyncIntervalMs: 30 * 60 * 1e3,
|
|
1189
|
-
wikiWorkspaceMapping: {
|
|
1190
|
-
exe: "Executive",
|
|
1191
|
-
yoshi: "Engineering",
|
|
1192
|
-
mari: "Marketing",
|
|
1193
|
-
tom: "Engineering",
|
|
1194
|
-
sasha: "Production"
|
|
1195
|
-
},
|
|
1196
|
-
wikiAutoUpdate: true,
|
|
1197
|
-
wikiAutoUpdateThreshold: 0.5,
|
|
1198
|
-
wikiAutoUpdateCreateNew: true,
|
|
1199
|
-
skillLearning: true,
|
|
1200
|
-
skillThreshold: 3,
|
|
1201
|
-
skillModel: "claude-haiku-4-5-20251001",
|
|
1202
|
-
exeHeartbeat: {
|
|
1203
|
-
enabled: true,
|
|
1204
|
-
intervalSeconds: 60,
|
|
1205
|
-
staleInProgressThresholdHours: 2
|
|
1206
|
-
},
|
|
1207
|
-
sessionLifecycle: {
|
|
1208
|
-
idleKillEnabled: true,
|
|
1209
|
-
idleKillTicksRequired: 3,
|
|
1210
|
-
idleKillIntercomAckWindowMs: 1e4,
|
|
1211
|
-
maxAutoInstances: 10
|
|
1212
|
-
},
|
|
1213
|
-
autoUpdate: {
|
|
1214
|
-
checkOnBoot: true,
|
|
1215
|
-
autoInstall: false,
|
|
1216
|
-
checkIntervalMs: 24 * 60 * 60 * 1e3
|
|
1217
|
-
}
|
|
1218
|
-
};
|
|
1219
|
-
CONFIG_MIGRATIONS = [
|
|
1220
|
-
{
|
|
1221
|
-
from: 0,
|
|
1222
|
-
to: 1,
|
|
1223
|
-
migrate: (cfg) => {
|
|
1224
|
-
cfg.config_version = 1;
|
|
1225
|
-
return cfg;
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
];
|
|
1229
|
-
}
|
|
1230
|
-
});
|
|
1231
|
-
|
|
1232
1297
|
// src/lib/state-bus.ts
|
|
1233
1298
|
var StateBus, orgBus;
|
|
1234
1299
|
var init_state_bus = __esm({
|
|
@@ -1297,12 +1362,12 @@ __export(shard_manager_exports, {
|
|
|
1297
1362
|
listShards: () => listShards,
|
|
1298
1363
|
shardExists: () => shardExists
|
|
1299
1364
|
});
|
|
1300
|
-
import
|
|
1301
|
-
import { existsSync as
|
|
1365
|
+
import path4 from "path";
|
|
1366
|
+
import { existsSync as existsSync4, mkdirSync, readdirSync } from "fs";
|
|
1302
1367
|
import { createClient as createClient2 } from "@libsql/client";
|
|
1303
1368
|
function initShardManager(encryptionKey) {
|
|
1304
1369
|
_encryptionKey = encryptionKey;
|
|
1305
|
-
if (!
|
|
1370
|
+
if (!existsSync4(SHARDS_DIR)) {
|
|
1306
1371
|
mkdirSync(SHARDS_DIR, { recursive: true });
|
|
1307
1372
|
}
|
|
1308
1373
|
_shardingEnabled = true;
|
|
@@ -1323,7 +1388,7 @@ function getShardClient(projectName) {
|
|
|
1323
1388
|
}
|
|
1324
1389
|
const cached = _shards.get(safeName);
|
|
1325
1390
|
if (cached) return cached;
|
|
1326
|
-
const dbPath =
|
|
1391
|
+
const dbPath = path4.join(SHARDS_DIR, `${safeName}.db`);
|
|
1327
1392
|
const client = createClient2({
|
|
1328
1393
|
url: `file:${dbPath}`,
|
|
1329
1394
|
encryptionKey: _encryptionKey
|
|
@@ -1333,10 +1398,10 @@ function getShardClient(projectName) {
|
|
|
1333
1398
|
}
|
|
1334
1399
|
function shardExists(projectName) {
|
|
1335
1400
|
const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1336
|
-
return
|
|
1401
|
+
return existsSync4(path4.join(SHARDS_DIR, `${safeName}.db`));
|
|
1337
1402
|
}
|
|
1338
1403
|
function listShards() {
|
|
1339
|
-
if (!
|
|
1404
|
+
if (!existsSync4(SHARDS_DIR)) return [];
|
|
1340
1405
|
return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
|
|
1341
1406
|
}
|
|
1342
1407
|
async function ensureShardSchema(client) {
|
|
@@ -1406,7 +1471,11 @@ async function ensureShardSchema(client) {
|
|
|
1406
1471
|
"ALTER TABLE memories ADD COLUMN source_path TEXT",
|
|
1407
1472
|
"ALTER TABLE memories ADD COLUMN source_type TEXT DEFAULT 'text'",
|
|
1408
1473
|
"ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3",
|
|
1409
|
-
"ALTER TABLE memories ADD COLUMN supersedes_id TEXT"
|
|
1474
|
+
"ALTER TABLE memories ADD COLUMN supersedes_id TEXT",
|
|
1475
|
+
// MS-11: draft staging, MS-6a: memory_type, MS-7: trajectory
|
|
1476
|
+
"ALTER TABLE memories ADD COLUMN draft INTEGER DEFAULT 0",
|
|
1477
|
+
"ALTER TABLE memories ADD COLUMN memory_type TEXT DEFAULT 'raw'",
|
|
1478
|
+
"ALTER TABLE memories ADD COLUMN trajectory TEXT"
|
|
1410
1479
|
]) {
|
|
1411
1480
|
try {
|
|
1412
1481
|
await client.execute(col);
|
|
@@ -1518,7 +1587,7 @@ var init_shard_manager = __esm({
|
|
|
1518
1587
|
"src/lib/shard-manager.ts"() {
|
|
1519
1588
|
"use strict";
|
|
1520
1589
|
init_config();
|
|
1521
|
-
SHARDS_DIR =
|
|
1590
|
+
SHARDS_DIR = path4.join(EXE_AI_DIR, "shards");
|
|
1522
1591
|
_shards = /* @__PURE__ */ new Map();
|
|
1523
1592
|
_encryptionKey = null;
|
|
1524
1593
|
_shardingEnabled = false;
|
|
@@ -1536,26 +1605,26 @@ var init_platform_procedures = __esm({
|
|
|
1536
1605
|
title: "What is exe-os \u2014 the operating model every agent must understand",
|
|
1537
1606
|
domain: "architecture",
|
|
1538
1607
|
priority: "p0",
|
|
1539
|
-
content: "Exe OS is an AI employee operating system. A founder runs 5-10 AI agents as a real org: COO
|
|
1608
|
+
content: "Exe OS is an AI employee operating system. A founder runs 5-10 AI agents as a real org: COO, CTO, CMO, engineers, and content production specialists. Each agent has identity, expertise, and experience layers \u2014 persistent memory that makes them better over time. All data is local-first, E2EE, owned by the user. The MCP server is the ONLY data interface \u2014 never access the DB directly."
|
|
1540
1609
|
},
|
|
1541
1610
|
{
|
|
1542
1611
|
title: "Mode 1 \u2014 how exe-os runs inside Claude Code",
|
|
1543
1612
|
domain: "architecture",
|
|
1544
1613
|
priority: "p0",
|
|
1545
|
-
content: "Mode 1: exe-os runs AS hooks + MCP + skills inside Claude Code. The founder opens CC
|
|
1614
|
+
content: "Mode 1: exe-os runs AS hooks + MCP + skills inside Claude Code. The founder opens CC and boots the COO. The COO manages employees in tmux sessions. Each coordinator session is a separate CC window/project. Employees run in their own tmux panes via create_task auto-spawn. The founder talks to the COO; the COO orchestrates the team. CC is the shell, exe-os is the brain."
|
|
1546
1615
|
},
|
|
1547
1616
|
{
|
|
1548
|
-
title: "Sessions explained \u2014
|
|
1617
|
+
title: "Sessions explained \u2014 coordinator session names and projects",
|
|
1549
1618
|
domain: "architecture",
|
|
1550
1619
|
priority: "p0",
|
|
1551
|
-
content: "Each
|
|
1620
|
+
content: "Each coordinator session is an isolated project session. One might be exe-os development, another might be exe-wiki. Each session spawns its own employees using {employee}-{coordinatorSession}. Sessions share the same memory DB but tasks are scoped to the session that created them. A founder can run multiple projects simultaneously. Sessions never interfere with each other."
|
|
1552
1621
|
},
|
|
1553
1622
|
// --- Hierarchy and dispatch ---
|
|
1554
1623
|
{
|
|
1555
1624
|
title: "Chain of command \u2014 who talks to whom",
|
|
1556
1625
|
domain: "workflow",
|
|
1557
1626
|
priority: "p0",
|
|
1558
|
-
content: "Founder
|
|
1627
|
+
content: "Founder -> COO -> CTO/CMO. CTO -> engineers. CMO -> content production. Never skip levels: the COO does not bypass managers for specialist work. Specialists report to their manager. If you need cross-team info, use ask_team_memory \u2014 don't read other agents' task folders. Each level owns dispatch downward and review upward."
|
|
1559
1628
|
},
|
|
1560
1629
|
{
|
|
1561
1630
|
title: "Single dispatch path \u2014 create_task only",
|
|
@@ -1565,30 +1634,30 @@ var init_platform_procedures = __esm({
|
|
|
1565
1634
|
},
|
|
1566
1635
|
// --- Session isolation ---
|
|
1567
1636
|
{
|
|
1568
|
-
title: "Session scoping \u2014 stay in your
|
|
1637
|
+
title: "Session scoping \u2014 stay in your coordinator boundary",
|
|
1569
1638
|
domain: "security",
|
|
1570
1639
|
priority: "p0",
|
|
1571
|
-
content: "Session scoping is mandatory. Managers dispatch to workers within their own
|
|
1640
|
+
content: "Session scoping is mandatory. Managers dispatch to workers within their own coordinator session ONLY. Employee sessions use {employee}-{coordinatorSession}. Cross-session dispatch is blocked by the system. Verify session names before dispatch. Tasks are scoped to the creating coordinator session."
|
|
1572
1641
|
},
|
|
1573
1642
|
{
|
|
1574
1643
|
title: "Session isolation \u2014 never touch another session's work",
|
|
1575
1644
|
domain: "workflow",
|
|
1576
1645
|
priority: "p0",
|
|
1577
|
-
content:
|
|
1646
|
+
content: "Sessions are isolated. A coordinator session owns ONLY tasks it dispatched. (1) Never close/update/cancel tasks from another coordinator session. (2) Never review work from a different session \u2014 report that it belongs to another session and skip. (3) Ignore other sessions' items in list_tasks results. (4) Employees inherit session: employee sessions work ONLY on their parent coordinator session's tasks. Cross-session work is a system violation."
|
|
1578
1647
|
},
|
|
1579
1648
|
// --- Engineering: session scoping in code ---
|
|
1580
1649
|
{
|
|
1581
1650
|
title: "Three-dimensional scoping \u2014 session, project, role \u2014 enforced in every query",
|
|
1582
1651
|
domain: "architecture",
|
|
1583
1652
|
priority: "p0",
|
|
1584
|
-
content: "Every DB query, notification, review count, and task operation MUST be scoped on 3 dimensions: (1) Session \u2014 filter by session_scope matching current
|
|
1653
|
+
content: "Every DB query, notification, review count, and task operation MUST be scoped on 3 dimensions: (1) Session \u2014 filter by session_scope matching the current coordinator session. (2) Project \u2014 filter by project_name. (3) Role \u2014 agents only see data at their hierarchy level. When writing ANY function that touches tasks, reviews, messages, or notifications: always accept a sessionScope parameter and pass it to the SQL WHERE clause. Unscoped queries are bugs. Test by running 2+ coordinator sessions simultaneously."
|
|
1585
1654
|
},
|
|
1586
1655
|
// --- Hard constraints ---
|
|
1587
1656
|
{
|
|
1588
1657
|
title: "What you CANNOT do in exe-os \u2014 hard constraints",
|
|
1589
1658
|
domain: "security",
|
|
1590
1659
|
priority: "p0",
|
|
1591
|
-
content: "NEVER: (1) Access the database directly \u2014 it's SQLCipher encrypted, always fails. Use MCP tools only. (2) Manually spawn tmux sessions \u2014 create_task handles it. (3) Run git checkout main \u2014 agents work in worktrees. (4) Modify another agent's in-progress task. (5) Push to remote \u2014
|
|
1660
|
+
content: "NEVER: (1) Access the database directly \u2014 it's SQLCipher encrypted, always fails. Use MCP tools only. (2) Manually spawn tmux sessions \u2014 create_task handles it. (3) Run git checkout main \u2014 agents work in worktrees. (4) Modify another agent's in-progress task. (5) Push to remote \u2014 the COO reviews and pushes. (6) Skip update_task(done) \u2014 it's the ONLY way your work gets reviewed. (7) Run git init."
|
|
1592
1661
|
},
|
|
1593
1662
|
// --- Operations ---
|
|
1594
1663
|
{
|
|
@@ -1828,7 +1897,10 @@ async function writeMemory(record) {
|
|
|
1828
1897
|
source_path: record.source_path ?? null,
|
|
1829
1898
|
source_type: record.source_type ?? null,
|
|
1830
1899
|
tier: record.tier ?? classifyTier(record),
|
|
1831
|
-
supersedes_id: record.supersedes_id ?? null
|
|
1900
|
+
supersedes_id: record.supersedes_id ?? null,
|
|
1901
|
+
draft: record.draft ? 1 : 0,
|
|
1902
|
+
memory_type: record.memory_type ?? "raw",
|
|
1903
|
+
trajectory: record.trajectory ? JSON.stringify(record.trajectory) : null
|
|
1832
1904
|
};
|
|
1833
1905
|
_pendingRecords.push(dbRow);
|
|
1834
1906
|
orgBus.emit({
|
|
@@ -1883,6 +1955,9 @@ async function flushBatch() {
|
|
|
1883
1955
|
const sourceType = row.source_type ?? null;
|
|
1884
1956
|
const tier = row.tier ?? 3;
|
|
1885
1957
|
const supersedesId = row.supersedes_id ?? null;
|
|
1958
|
+
const draft = row.draft ? 1 : 0;
|
|
1959
|
+
const memoryType = row.memory_type ?? "raw";
|
|
1960
|
+
const trajectory = row.trajectory ?? null;
|
|
1886
1961
|
return {
|
|
1887
1962
|
sql: hasVector ? `INSERT OR IGNORE INTO memories
|
|
1888
1963
|
(id, agent_id, agent_role, session_id, timestamp,
|
|
@@ -1890,15 +1965,15 @@ async function flushBatch() {
|
|
|
1890
1965
|
has_error, raw_text, vector, version, task_id, importance, status,
|
|
1891
1966
|
confidence, last_accessed,
|
|
1892
1967
|
workspace_id, document_id, user_id, char_offset, page_number,
|
|
1893
|
-
source_path, source_type, tier, supersedes_id)
|
|
1894
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, vector32(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` : `INSERT OR IGNORE INTO memories
|
|
1968
|
+
source_path, source_type, tier, supersedes_id, draft, memory_type, trajectory)
|
|
1969
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, vector32(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` : `INSERT OR IGNORE INTO memories
|
|
1895
1970
|
(id, agent_id, agent_role, session_id, timestamp,
|
|
1896
1971
|
tool_name, project_name,
|
|
1897
1972
|
has_error, raw_text, vector, version, task_id, importance, status,
|
|
1898
1973
|
confidence, last_accessed,
|
|
1899
1974
|
workspace_id, document_id, user_id, char_offset, page_number,
|
|
1900
|
-
source_path, source_type, tier, supersedes_id)
|
|
1901
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
1975
|
+
source_path, source_type, tier, supersedes_id, draft, memory_type, trajectory)
|
|
1976
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
1902
1977
|
args: hasVector ? [
|
|
1903
1978
|
row.id,
|
|
1904
1979
|
row.agent_id,
|
|
@@ -1924,7 +1999,10 @@ async function flushBatch() {
|
|
|
1924
1999
|
sourcePath,
|
|
1925
2000
|
sourceType,
|
|
1926
2001
|
tier,
|
|
1927
|
-
supersedesId
|
|
2002
|
+
supersedesId,
|
|
2003
|
+
draft,
|
|
2004
|
+
memoryType,
|
|
2005
|
+
trajectory
|
|
1928
2006
|
] : [
|
|
1929
2007
|
row.id,
|
|
1930
2008
|
row.agent_id,
|
|
@@ -1949,7 +2027,10 @@ async function flushBatch() {
|
|
|
1949
2027
|
sourcePath,
|
|
1950
2028
|
sourceType,
|
|
1951
2029
|
tier,
|
|
1952
|
-
supersedesId
|
|
2030
|
+
supersedesId,
|
|
2031
|
+
draft,
|
|
2032
|
+
memoryType,
|
|
2033
|
+
trajectory
|
|
1953
2034
|
]
|
|
1954
2035
|
};
|
|
1955
2036
|
};
|
|
@@ -2018,6 +2099,8 @@ async function searchMemories(queryVector, agentId, options) {
|
|
|
2018
2099
|
const limit = options?.limit ?? 10;
|
|
2019
2100
|
const statusFilter = options?.includeArchived ? "" : `
|
|
2020
2101
|
AND COALESCE(status, 'active') = 'active'`;
|
|
2102
|
+
const draftFilter = options?.includeDrafts ? "" : `
|
|
2103
|
+
AND (draft = 0 OR draft IS NULL)`;
|
|
2021
2104
|
let sql = `SELECT id, agent_id, agent_role, session_id, timestamp,
|
|
2022
2105
|
tool_name, project_name,
|
|
2023
2106
|
has_error, raw_text, vector, importance, status,
|
|
@@ -2027,7 +2110,7 @@ async function searchMemories(queryVector, agentId, options) {
|
|
|
2027
2110
|
source_path, source_type
|
|
2028
2111
|
FROM memories
|
|
2029
2112
|
WHERE agent_id = ?
|
|
2030
|
-
AND vector IS NOT NULL${statusFilter}
|
|
2113
|
+
AND vector IS NOT NULL${statusFilter}${draftFilter}
|
|
2031
2114
|
AND COALESCE(confidence, 0.7) >= 0.3`;
|
|
2032
2115
|
const args = [agentId];
|
|
2033
2116
|
const scope = buildWikiScopeFilter(options, "");
|
|
@@ -2049,6 +2132,10 @@ async function searchMemories(queryVector, agentId, options) {
|
|
|
2049
2132
|
sql += ` AND timestamp >= ?`;
|
|
2050
2133
|
args.push(options.since);
|
|
2051
2134
|
}
|
|
2135
|
+
if (options?.memoryType) {
|
|
2136
|
+
sql += ` AND memory_type = ?`;
|
|
2137
|
+
args.push(options.memoryType);
|
|
2138
|
+
}
|
|
2052
2139
|
sql += ` ORDER BY vector_distance_cos(vector, vector32(?))`;
|
|
2053
2140
|
args.push(vectorToBlob(queryVector));
|
|
2054
2141
|
sql += ` LIMIT ?`;
|
|
@@ -2274,7 +2361,7 @@ var init_self_query_router = __esm({
|
|
|
2274
2361
|
},
|
|
2275
2362
|
is_broad_query: {
|
|
2276
2363
|
type: "boolean",
|
|
2277
|
-
description: "True if the query is exploratory/broad (e.g., 'what has
|
|
2364
|
+
description: "True if the query is exploratory/broad (e.g., 'what has the CTO been working on', 'summarize recent activity'). False if targeted (e.g., 'how did we fix the auth bug')."
|
|
2278
2365
|
}
|
|
2279
2366
|
},
|
|
2280
2367
|
required: ["semantic_query", "project_filter", "role_filter", "time_filter", "is_broad_query"]
|
|
@@ -2287,8 +2374,8 @@ var init_self_query_router = __esm({
|
|
|
2287
2374
|
import net from "net";
|
|
2288
2375
|
import { spawn } from "child_process";
|
|
2289
2376
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
2290
|
-
import { existsSync as
|
|
2291
|
-
import
|
|
2377
|
+
import { existsSync as existsSync5, unlinkSync as unlinkSync2, readFileSync as readFileSync3, openSync, closeSync, statSync } from "fs";
|
|
2378
|
+
import path5 from "path";
|
|
2292
2379
|
import { fileURLToPath } from "url";
|
|
2293
2380
|
function handleData(chunk) {
|
|
2294
2381
|
_buffer += chunk.toString();
|
|
@@ -2314,9 +2401,9 @@ function handleData(chunk) {
|
|
|
2314
2401
|
}
|
|
2315
2402
|
}
|
|
2316
2403
|
function cleanupStaleFiles() {
|
|
2317
|
-
if (
|
|
2404
|
+
if (existsSync5(PID_PATH)) {
|
|
2318
2405
|
try {
|
|
2319
|
-
const pid = parseInt(
|
|
2406
|
+
const pid = parseInt(readFileSync3(PID_PATH, "utf8").trim(), 10);
|
|
2320
2407
|
if (pid > 0) {
|
|
2321
2408
|
try {
|
|
2322
2409
|
process.kill(pid, 0);
|
|
@@ -2327,21 +2414,21 @@ function cleanupStaleFiles() {
|
|
|
2327
2414
|
} catch {
|
|
2328
2415
|
}
|
|
2329
2416
|
try {
|
|
2330
|
-
|
|
2417
|
+
unlinkSync2(PID_PATH);
|
|
2331
2418
|
} catch {
|
|
2332
2419
|
}
|
|
2333
2420
|
try {
|
|
2334
|
-
|
|
2421
|
+
unlinkSync2(SOCKET_PATH);
|
|
2335
2422
|
} catch {
|
|
2336
2423
|
}
|
|
2337
2424
|
}
|
|
2338
2425
|
}
|
|
2339
2426
|
function findPackageRoot() {
|
|
2340
|
-
let dir =
|
|
2341
|
-
const { root } =
|
|
2427
|
+
let dir = path5.dirname(fileURLToPath(import.meta.url));
|
|
2428
|
+
const { root } = path5.parse(dir);
|
|
2342
2429
|
while (dir !== root) {
|
|
2343
|
-
if (
|
|
2344
|
-
dir =
|
|
2430
|
+
if (existsSync5(path5.join(dir, "package.json"))) return dir;
|
|
2431
|
+
dir = path5.dirname(dir);
|
|
2345
2432
|
}
|
|
2346
2433
|
return null;
|
|
2347
2434
|
}
|
|
@@ -2351,8 +2438,8 @@ function spawnDaemon() {
|
|
|
2351
2438
|
process.stderr.write("[exed-client] WARN: cannot find package root\n");
|
|
2352
2439
|
return;
|
|
2353
2440
|
}
|
|
2354
|
-
const daemonPath =
|
|
2355
|
-
if (!
|
|
2441
|
+
const daemonPath = path5.join(pkgRoot, "dist", "lib", "exe-daemon.js");
|
|
2442
|
+
if (!existsSync5(daemonPath)) {
|
|
2356
2443
|
process.stderr.write(`[exed-client] WARN: daemon script not found at ${daemonPath}
|
|
2357
2444
|
`);
|
|
2358
2445
|
return;
|
|
@@ -2360,7 +2447,7 @@ function spawnDaemon() {
|
|
|
2360
2447
|
const resolvedPath = daemonPath;
|
|
2361
2448
|
process.stderr.write(`[exed-client] Spawning daemon: ${resolvedPath}
|
|
2362
2449
|
`);
|
|
2363
|
-
const logPath =
|
|
2450
|
+
const logPath = path5.join(path5.dirname(SOCKET_PATH), "exed.log");
|
|
2364
2451
|
let stderrFd = "ignore";
|
|
2365
2452
|
try {
|
|
2366
2453
|
stderrFd = openSync(logPath, "a");
|
|
@@ -2371,6 +2458,10 @@ function spawnDaemon() {
|
|
|
2371
2458
|
stdio: ["ignore", "ignore", stderrFd],
|
|
2372
2459
|
env: {
|
|
2373
2460
|
...process.env,
|
|
2461
|
+
TMUX: void 0,
|
|
2462
|
+
// Daemon is global — must not inherit session scope
|
|
2463
|
+
TMUX_PANE: void 0,
|
|
2464
|
+
// Prevents resolveExeSession() from scoping to one session
|
|
2374
2465
|
EXE_DAEMON_SOCK: SOCKET_PATH,
|
|
2375
2466
|
EXE_DAEMON_PID: PID_PATH
|
|
2376
2467
|
}
|
|
@@ -2393,7 +2484,7 @@ function acquireSpawnLock() {
|
|
|
2393
2484
|
const stat = statSync(SPAWN_LOCK_PATH);
|
|
2394
2485
|
if (Date.now() - stat.mtimeMs > SPAWN_LOCK_STALE_MS) {
|
|
2395
2486
|
try {
|
|
2396
|
-
|
|
2487
|
+
unlinkSync2(SPAWN_LOCK_PATH);
|
|
2397
2488
|
} catch {
|
|
2398
2489
|
}
|
|
2399
2490
|
try {
|
|
@@ -2410,7 +2501,7 @@ function acquireSpawnLock() {
|
|
|
2410
2501
|
}
|
|
2411
2502
|
function releaseSpawnLock() {
|
|
2412
2503
|
try {
|
|
2413
|
-
|
|
2504
|
+
unlinkSync2(SPAWN_LOCK_PATH);
|
|
2414
2505
|
} catch {
|
|
2415
2506
|
}
|
|
2416
2507
|
}
|
|
@@ -2522,9 +2613,9 @@ async function pingDaemon() {
|
|
|
2522
2613
|
}
|
|
2523
2614
|
function killAndRespawnDaemon() {
|
|
2524
2615
|
process.stderr.write("[exed-client] Killing daemon for restart...\n");
|
|
2525
|
-
if (
|
|
2616
|
+
if (existsSync5(PID_PATH)) {
|
|
2526
2617
|
try {
|
|
2527
|
-
const pid = parseInt(
|
|
2618
|
+
const pid = parseInt(readFileSync3(PID_PATH, "utf8").trim(), 10);
|
|
2528
2619
|
if (pid > 0) {
|
|
2529
2620
|
try {
|
|
2530
2621
|
process.kill(pid, "SIGKILL");
|
|
@@ -2541,11 +2632,11 @@ function killAndRespawnDaemon() {
|
|
|
2541
2632
|
_connected = false;
|
|
2542
2633
|
_buffer = "";
|
|
2543
2634
|
try {
|
|
2544
|
-
|
|
2635
|
+
unlinkSync2(PID_PATH);
|
|
2545
2636
|
} catch {
|
|
2546
2637
|
}
|
|
2547
2638
|
try {
|
|
2548
|
-
|
|
2639
|
+
unlinkSync2(SOCKET_PATH);
|
|
2549
2640
|
} catch {
|
|
2550
2641
|
}
|
|
2551
2642
|
spawnDaemon();
|
|
@@ -2608,9 +2699,9 @@ var init_exe_daemon_client = __esm({
|
|
|
2608
2699
|
"src/lib/exe-daemon-client.ts"() {
|
|
2609
2700
|
"use strict";
|
|
2610
2701
|
init_config();
|
|
2611
|
-
SOCKET_PATH = process.env.EXE_DAEMON_SOCK ?? process.env.EXE_EMBED_SOCK ??
|
|
2612
|
-
PID_PATH = process.env.EXE_DAEMON_PID ?? process.env.EXE_EMBED_PID ??
|
|
2613
|
-
SPAWN_LOCK_PATH =
|
|
2702
|
+
SOCKET_PATH = process.env.EXE_DAEMON_SOCK ?? process.env.EXE_EMBED_SOCK ?? path5.join(EXE_AI_DIR, "exed.sock");
|
|
2703
|
+
PID_PATH = process.env.EXE_DAEMON_PID ?? process.env.EXE_EMBED_PID ?? path5.join(EXE_AI_DIR, "exed.pid");
|
|
2704
|
+
SPAWN_LOCK_PATH = path5.join(EXE_AI_DIR, "exed-spawn.lock");
|
|
2614
2705
|
SPAWN_LOCK_STALE_MS = 3e4;
|
|
2615
2706
|
CONNECT_TIMEOUT_MS = 15e3;
|
|
2616
2707
|
REQUEST_TIMEOUT_MS = 3e4;
|
|
@@ -2661,10 +2752,10 @@ async function disposeEmbedder() {
|
|
|
2661
2752
|
async function embedDirect(text) {
|
|
2662
2753
|
const llamaCpp = await import("node-llama-cpp");
|
|
2663
2754
|
const { MODELS_DIR: MODELS_DIR2 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
2664
|
-
const { existsSync:
|
|
2665
|
-
const
|
|
2666
|
-
const modelPath =
|
|
2667
|
-
if (!
|
|
2755
|
+
const { existsSync: existsSync8 } = await import("fs");
|
|
2756
|
+
const path9 = await import("path");
|
|
2757
|
+
const modelPath = path9.join(MODELS_DIR2, "jina-embeddings-v5-small-q4_k_m.gguf");
|
|
2758
|
+
if (!existsSync8(modelPath)) {
|
|
2668
2759
|
throw new Error(`Embedding model not found at ${modelPath}. Run '/exe-setup' to download it.`);
|
|
2669
2760
|
}
|
|
2670
2761
|
const llama = await llamaCpp.getLlama();
|
|
@@ -2698,34 +2789,34 @@ __export(project_name_exports, {
|
|
|
2698
2789
|
_resetCache: () => _resetCache,
|
|
2699
2790
|
getProjectName: () => getProjectName
|
|
2700
2791
|
});
|
|
2701
|
-
import { execSync } from "child_process";
|
|
2702
|
-
import
|
|
2792
|
+
import { execSync as execSync2 } from "child_process";
|
|
2793
|
+
import path6 from "path";
|
|
2703
2794
|
function getProjectName(cwd) {
|
|
2704
2795
|
const dir = cwd ?? process.cwd();
|
|
2705
2796
|
if (_cached && _cachedCwd === dir) return _cached;
|
|
2706
2797
|
try {
|
|
2707
2798
|
let repoRoot;
|
|
2708
2799
|
try {
|
|
2709
|
-
const gitCommonDir =
|
|
2800
|
+
const gitCommonDir = execSync2("git rev-parse --path-format=absolute --git-common-dir", {
|
|
2710
2801
|
cwd: dir,
|
|
2711
2802
|
encoding: "utf8",
|
|
2712
2803
|
timeout: 2e3,
|
|
2713
2804
|
stdio: ["pipe", "pipe", "pipe"]
|
|
2714
2805
|
}).trim();
|
|
2715
|
-
repoRoot =
|
|
2806
|
+
repoRoot = path6.dirname(gitCommonDir);
|
|
2716
2807
|
} catch {
|
|
2717
|
-
repoRoot =
|
|
2808
|
+
repoRoot = execSync2("git rev-parse --show-toplevel", {
|
|
2718
2809
|
cwd: dir,
|
|
2719
2810
|
encoding: "utf8",
|
|
2720
2811
|
timeout: 2e3,
|
|
2721
2812
|
stdio: ["pipe", "pipe", "pipe"]
|
|
2722
2813
|
}).trim();
|
|
2723
2814
|
}
|
|
2724
|
-
_cached =
|
|
2815
|
+
_cached = path6.basename(repoRoot);
|
|
2725
2816
|
_cachedCwd = dir;
|
|
2726
2817
|
return _cached;
|
|
2727
2818
|
} catch {
|
|
2728
|
-
_cached =
|
|
2819
|
+
_cached = path6.basename(dir);
|
|
2729
2820
|
_cachedCwd = dir;
|
|
2730
2821
|
return _cached;
|
|
2731
2822
|
}
|
|
@@ -2748,14 +2839,14 @@ var file_grep_exports = {};
|
|
|
2748
2839
|
__export(file_grep_exports, {
|
|
2749
2840
|
grepProjectFiles: () => grepProjectFiles
|
|
2750
2841
|
});
|
|
2751
|
-
import { execSync as
|
|
2752
|
-
import { readFileSync as
|
|
2753
|
-
import
|
|
2842
|
+
import { execSync as execSync3 } from "child_process";
|
|
2843
|
+
import { readFileSync as readFileSync4, readdirSync as readdirSync2, statSync as statSync2, existsSync as existsSync6 } from "fs";
|
|
2844
|
+
import path7 from "path";
|
|
2754
2845
|
import crypto from "crypto";
|
|
2755
2846
|
function hasRipgrep() {
|
|
2756
2847
|
if (_hasRg === null) {
|
|
2757
2848
|
try {
|
|
2758
|
-
|
|
2849
|
+
execSync3("rg --version", { stdio: "ignore", timeout: 2e3 });
|
|
2759
2850
|
_hasRg = true;
|
|
2760
2851
|
} catch {
|
|
2761
2852
|
_hasRg = false;
|
|
@@ -2790,7 +2881,7 @@ async function grepProjectFiles(query, projectRoot, options) {
|
|
|
2790
2881
|
session_id: "file-grep",
|
|
2791
2882
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2792
2883
|
tool_name: "file_grep",
|
|
2793
|
-
project_name:
|
|
2884
|
+
project_name: path7.basename(projectRoot),
|
|
2794
2885
|
has_error: false,
|
|
2795
2886
|
raw_text: `${prefix} ${buildSnippet(hit, projectRoot)}`,
|
|
2796
2887
|
vector: null,
|
|
@@ -2802,7 +2893,7 @@ function getChunkContext(filePath, lineNumber) {
|
|
|
2802
2893
|
try {
|
|
2803
2894
|
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
2804
2895
|
if (ext !== "ts" && ext !== "tsx" && ext !== "js" && ext !== "jsx") return "";
|
|
2805
|
-
const source =
|
|
2896
|
+
const source = readFileSync4(filePath, "utf8");
|
|
2806
2897
|
const lines = source.split("\n");
|
|
2807
2898
|
for (let i = Math.min(lineNumber - 1, lines.length - 1); i >= 0; i--) {
|
|
2808
2899
|
const line = lines[i];
|
|
@@ -2821,7 +2912,7 @@ function grepWithRipgrep(pattern, projectRoot, patterns) {
|
|
|
2821
2912
|
const globs = (patterns ?? DEFAULT_PATTERNS).map((p) => `--glob '${p}'`).join(" ");
|
|
2822
2913
|
const excludes = EXCLUDE_DIRS.map((d) => `--glob '!${d}'`).join(" ");
|
|
2823
2914
|
const cmd = `rg -i -c --hidden --no-config --no-ignore '${pattern.replace(/'/g, "\\'")}' . ${globs} ${excludes} --max-filesize ${MAX_FILE_SIZE} 2>/dev/null || true`;
|
|
2824
|
-
const output =
|
|
2915
|
+
const output = execSync3(cmd, {
|
|
2825
2916
|
cwd: projectRoot,
|
|
2826
2917
|
encoding: "utf8",
|
|
2827
2918
|
timeout: 3e3,
|
|
@@ -2836,12 +2927,12 @@ function grepWithRipgrep(pattern, projectRoot, patterns) {
|
|
|
2836
2927
|
const matchCount = parseInt(line.slice(colonIdx + 1));
|
|
2837
2928
|
if (isNaN(matchCount) || matchCount === 0) continue;
|
|
2838
2929
|
try {
|
|
2839
|
-
const firstMatch =
|
|
2930
|
+
const firstMatch = execSync3(
|
|
2840
2931
|
`rg -i -n --hidden '${pattern.replace(/'/g, "\\'")}' '${filePath}' --max-count 1 2>/dev/null | head -1`,
|
|
2841
2932
|
{ cwd: projectRoot, encoding: "utf8", timeout: 1e3 }
|
|
2842
2933
|
).trim();
|
|
2843
2934
|
const lineNum = parseInt(firstMatch.split(":")[0] ?? "1");
|
|
2844
|
-
const totalLines =
|
|
2935
|
+
const totalLines = execSync3(`wc -l < '${filePath}'`, {
|
|
2845
2936
|
cwd: projectRoot,
|
|
2846
2937
|
encoding: "utf8",
|
|
2847
2938
|
timeout: 1e3
|
|
@@ -2864,11 +2955,11 @@ function grepWithNodeFs(pattern, projectRoot, patterns) {
|
|
|
2864
2955
|
const files = collectFiles(projectRoot, patterns ?? DEFAULT_PATTERNS);
|
|
2865
2956
|
const hits = [];
|
|
2866
2957
|
for (const filePath of files.slice(0, MAX_FILES)) {
|
|
2867
|
-
const absPath =
|
|
2958
|
+
const absPath = path7.join(projectRoot, filePath);
|
|
2868
2959
|
try {
|
|
2869
2960
|
const stat = statSync2(absPath);
|
|
2870
2961
|
if (stat.size > MAX_FILE_SIZE) continue;
|
|
2871
|
-
const content =
|
|
2962
|
+
const content = readFileSync4(absPath, "utf8");
|
|
2872
2963
|
const lines = content.split("\n");
|
|
2873
2964
|
const matches = content.match(regex);
|
|
2874
2965
|
if (!matches || matches.length === 0) continue;
|
|
@@ -2891,15 +2982,15 @@ function collectFiles(root, patterns) {
|
|
|
2891
2982
|
const files = [];
|
|
2892
2983
|
function walk(dir, relative) {
|
|
2893
2984
|
if (files.length >= MAX_FILES) return;
|
|
2894
|
-
const basename =
|
|
2985
|
+
const basename = path7.basename(dir);
|
|
2895
2986
|
if (EXCLUDE_DIRS.includes(basename)) return;
|
|
2896
2987
|
try {
|
|
2897
2988
|
const entries = readdirSync2(dir, { withFileTypes: true });
|
|
2898
2989
|
for (const entry of entries) {
|
|
2899
2990
|
if (files.length >= MAX_FILES) return;
|
|
2900
|
-
const rel =
|
|
2991
|
+
const rel = path7.join(relative, entry.name);
|
|
2901
2992
|
if (entry.isDirectory()) {
|
|
2902
|
-
walk(
|
|
2993
|
+
walk(path7.join(dir, entry.name), rel);
|
|
2903
2994
|
} else if (entry.isFile()) {
|
|
2904
2995
|
for (const pat of patterns) {
|
|
2905
2996
|
if (matchGlob(rel, pat)) {
|
|
@@ -2931,7 +3022,7 @@ function matchGlob(filePath, pattern) {
|
|
|
2931
3022
|
if (slashIdx !== -1) {
|
|
2932
3023
|
const dir = pattern.slice(0, slashIdx);
|
|
2933
3024
|
const ext2 = pattern.slice(slashIdx + 1).replace("*", "");
|
|
2934
|
-
const fileDir =
|
|
3025
|
+
const fileDir = path7.dirname(filePath);
|
|
2935
3026
|
return fileDir === dir && filePath.endsWith(ext2);
|
|
2936
3027
|
}
|
|
2937
3028
|
const ext = pattern.replace("*", "");
|
|
@@ -2939,9 +3030,9 @@ function matchGlob(filePath, pattern) {
|
|
|
2939
3030
|
}
|
|
2940
3031
|
function buildSnippet(hit, projectRoot) {
|
|
2941
3032
|
try {
|
|
2942
|
-
const absPath =
|
|
2943
|
-
if (!
|
|
2944
|
-
const lines =
|
|
3033
|
+
const absPath = path7.join(projectRoot, hit.filePath);
|
|
3034
|
+
if (!existsSync6(absPath)) return hit.matchLine;
|
|
3035
|
+
const lines = readFileSync4(absPath, "utf8").split("\n");
|
|
2945
3036
|
const start = Math.max(0, hit.lineNumber - 3);
|
|
2946
3037
|
const end = Math.min(lines.length, hit.lineNumber + 2);
|
|
2947
3038
|
return lines.slice(start, end).join("\n").slice(0, 500);
|
|
@@ -2975,8 +3066,8 @@ __export(reranker_exports, {
|
|
|
2975
3066
|
rerank: () => rerank,
|
|
2976
3067
|
rerankWithScores: () => rerankWithScores
|
|
2977
3068
|
});
|
|
2978
|
-
import
|
|
2979
|
-
import { existsSync as
|
|
3069
|
+
import path8 from "path";
|
|
3070
|
+
import { existsSync as existsSync7 } from "fs";
|
|
2980
3071
|
function resetIdleTimer() {
|
|
2981
3072
|
if (_idleTimer) clearTimeout(_idleTimer);
|
|
2982
3073
|
_idleTimer = setTimeout(() => {
|
|
@@ -2987,18 +3078,18 @@ function resetIdleTimer() {
|
|
|
2987
3078
|
}
|
|
2988
3079
|
}
|
|
2989
3080
|
function isRerankerAvailable() {
|
|
2990
|
-
return
|
|
3081
|
+
return existsSync7(path8.join(MODELS_DIR, RERANKER_MODEL_FILE));
|
|
2991
3082
|
}
|
|
2992
3083
|
function getRerankerModelPath() {
|
|
2993
|
-
return
|
|
3084
|
+
return path8.join(MODELS_DIR, RERANKER_MODEL_FILE);
|
|
2994
3085
|
}
|
|
2995
3086
|
async function ensureLoaded() {
|
|
2996
3087
|
if (_rerankerContext) {
|
|
2997
3088
|
resetIdleTimer();
|
|
2998
3089
|
return;
|
|
2999
3090
|
}
|
|
3000
|
-
const modelPath =
|
|
3001
|
-
if (!
|
|
3091
|
+
const modelPath = path8.join(MODELS_DIR, RERANKER_MODEL_FILE);
|
|
3092
|
+
if (!existsSync7(modelPath)) {
|
|
3002
3093
|
throw new Error(
|
|
3003
3094
|
`Reranker model not found at ${modelPath}. Run /exe-setup to download it.`
|
|
3004
3095
|
);
|
|
@@ -3085,6 +3176,8 @@ async function hybridSearch(queryText, agentId, options) {
|
|
|
3085
3176
|
return lightweightSearch(queryText, agentId, options);
|
|
3086
3177
|
}
|
|
3087
3178
|
const limit = options?.limit ?? 10;
|
|
3179
|
+
const trajectoryResults = await trajectoryBypass(queryText, agentId, options, limit);
|
|
3180
|
+
if (trajectoryResults !== null) return trajectoryResults;
|
|
3088
3181
|
let effectiveQuery = queryText;
|
|
3089
3182
|
let effectiveOptions = { ...options };
|
|
3090
3183
|
let _isBroadQuery = false;
|
|
@@ -3311,6 +3404,8 @@ async function lightweightSearch(queryText, agentId, options) {
|
|
|
3311
3404
|
async function ftsQuery(client, matchExpr, agentId, options, limit) {
|
|
3312
3405
|
const statusFilter = options?.includeArchived ? "" : `
|
|
3313
3406
|
AND COALESCE(m.status, 'active') = 'active'`;
|
|
3407
|
+
const draftFilter = options?.includeDrafts ? "" : `
|
|
3408
|
+
AND (m.draft = 0 OR m.draft IS NULL)`;
|
|
3314
3409
|
let sql = `SELECT m.id, m.agent_id, m.agent_role, m.session_id, m.timestamp,
|
|
3315
3410
|
m.tool_name, m.project_name,
|
|
3316
3411
|
m.has_error, m.raw_text, m.vector, m.task_id,
|
|
@@ -3321,7 +3416,7 @@ async function ftsQuery(client, matchExpr, agentId, options, limit) {
|
|
|
3321
3416
|
FROM memories m
|
|
3322
3417
|
JOIN memories_fts fts ON m.rowid = fts.rowid
|
|
3323
3418
|
WHERE memories_fts MATCH ?
|
|
3324
|
-
AND m.agent_id = ?${statusFilter}
|
|
3419
|
+
AND m.agent_id = ?${statusFilter}${draftFilter}
|
|
3325
3420
|
AND COALESCE(m.confidence, 0.7) >= 0.3`;
|
|
3326
3421
|
const args = [matchExpr, agentId];
|
|
3327
3422
|
const scope = buildWikiScopeFilter(options, "m.");
|
|
@@ -3343,6 +3438,10 @@ async function ftsQuery(client, matchExpr, agentId, options, limit) {
|
|
|
3343
3438
|
sql += ` AND m.timestamp >= ?`;
|
|
3344
3439
|
args.push(options.since);
|
|
3345
3440
|
}
|
|
3441
|
+
if (options?.memoryType) {
|
|
3442
|
+
sql += ` AND m.memory_type = ?`;
|
|
3443
|
+
args.push(options.memoryType);
|
|
3444
|
+
}
|
|
3346
3445
|
sql += ` ORDER BY rank LIMIT ?`;
|
|
3347
3446
|
args.push(limit);
|
|
3348
3447
|
const result = await client.execute({ sql, args });
|
|
@@ -3375,6 +3474,8 @@ async function recentRecords(agentId, options, limit) {
|
|
|
3375
3474
|
const client = getClient();
|
|
3376
3475
|
const statusFilter = options?.includeArchived ? "" : `
|
|
3377
3476
|
AND COALESCE(status, 'active') = 'active'`;
|
|
3477
|
+
const draftFilter = options?.includeDrafts ? "" : `
|
|
3478
|
+
AND (draft = 0 OR draft IS NULL)`;
|
|
3378
3479
|
let sql = `SELECT id, agent_id, agent_role, session_id, timestamp,
|
|
3379
3480
|
tool_name, project_name,
|
|
3380
3481
|
has_error, raw_text, vector, task_id,
|
|
@@ -3383,7 +3484,7 @@ async function recentRecords(agentId, options, limit) {
|
|
|
3383
3484
|
char_offset, page_number,
|
|
3384
3485
|
source_path, source_type
|
|
3385
3486
|
FROM memories
|
|
3386
|
-
WHERE agent_id = ?${statusFilter}
|
|
3487
|
+
WHERE agent_id = ?${statusFilter}${draftFilter}
|
|
3387
3488
|
AND COALESCE(confidence, 0.7) >= 0.3`;
|
|
3388
3489
|
const args = [agentId];
|
|
3389
3490
|
const scope = buildWikiScopeFilter(options, "");
|
|
@@ -3405,6 +3506,10 @@ async function recentRecords(agentId, options, limit) {
|
|
|
3405
3506
|
sql += ` AND timestamp >= ?`;
|
|
3406
3507
|
args.push(options.since);
|
|
3407
3508
|
}
|
|
3509
|
+
if (options?.memoryType) {
|
|
3510
|
+
sql += ` AND memory_type = ?`;
|
|
3511
|
+
args.push(options.memoryType);
|
|
3512
|
+
}
|
|
3408
3513
|
sql += ` ORDER BY timestamp DESC LIMIT ?`;
|
|
3409
3514
|
args.push(limit);
|
|
3410
3515
|
const result = await client.execute({ sql, args });
|
|
@@ -3433,6 +3538,88 @@ async function recentRecords(agentId, options, limit) {
|
|
|
3433
3538
|
source_type: row.source_type ?? null
|
|
3434
3539
|
}));
|
|
3435
3540
|
}
|
|
3541
|
+
var KNOWN_TOOLS = /* @__PURE__ */ new Set([
|
|
3542
|
+
"Bash",
|
|
3543
|
+
"Read",
|
|
3544
|
+
"Write",
|
|
3545
|
+
"Edit",
|
|
3546
|
+
"Grep",
|
|
3547
|
+
"Glob",
|
|
3548
|
+
"Agent",
|
|
3549
|
+
"Skill",
|
|
3550
|
+
"WebSearch",
|
|
3551
|
+
"WebFetch"
|
|
3552
|
+
]);
|
|
3553
|
+
function detectToolQuery(query) {
|
|
3554
|
+
const lower = query.toLowerCase().trim();
|
|
3555
|
+
for (const tool of KNOWN_TOOLS) {
|
|
3556
|
+
if (lower === tool.toLowerCase()) return tool;
|
|
3557
|
+
if (lower.startsWith(tool.toLowerCase() + " ")) return tool;
|
|
3558
|
+
if (lower.includes(`tool:${tool.toLowerCase()}`)) return tool;
|
|
3559
|
+
}
|
|
3560
|
+
return null;
|
|
3561
|
+
}
|
|
3562
|
+
async function trajectoryBypass(queryText, agentId, options, limit) {
|
|
3563
|
+
const toolName = detectToolQuery(queryText);
|
|
3564
|
+
if (!toolName) return null;
|
|
3565
|
+
try {
|
|
3566
|
+
const client = getClient();
|
|
3567
|
+
const statusFilter = options?.includeArchived ? "" : `
|
|
3568
|
+
AND COALESCE(status, 'active') = 'active'`;
|
|
3569
|
+
const draftFilter = options?.includeDrafts ? "" : `
|
|
3570
|
+
AND (draft = 0 OR draft IS NULL)`;
|
|
3571
|
+
let sql = `SELECT id, agent_id, agent_role, session_id, timestamp,
|
|
3572
|
+
tool_name, project_name,
|
|
3573
|
+
has_error, raw_text, vector, task_id,
|
|
3574
|
+
importance, status, confidence, last_accessed,
|
|
3575
|
+
workspace_id, document_id, user_id,
|
|
3576
|
+
char_offset, page_number,
|
|
3577
|
+
source_path, source_type
|
|
3578
|
+
FROM memories
|
|
3579
|
+
WHERE trajectory IS NOT NULL
|
|
3580
|
+
AND json_extract(trajectory, '$.tool') = ?
|
|
3581
|
+
AND agent_id = ?${statusFilter}${draftFilter}`;
|
|
3582
|
+
const args = [toolName, agentId];
|
|
3583
|
+
if (options?.projectName) {
|
|
3584
|
+
sql += ` AND project_name = ?`;
|
|
3585
|
+
args.push(options.projectName);
|
|
3586
|
+
}
|
|
3587
|
+
if (options?.since) {
|
|
3588
|
+
sql += ` AND timestamp >= ?`;
|
|
3589
|
+
args.push(options.since);
|
|
3590
|
+
}
|
|
3591
|
+
sql += ` ORDER BY timestamp DESC LIMIT ?`;
|
|
3592
|
+
args.push(limit);
|
|
3593
|
+
const result = await client.execute({ sql, args });
|
|
3594
|
+
if (result.rows.length < 3) return null;
|
|
3595
|
+
return result.rows.map((row) => ({
|
|
3596
|
+
id: row.id,
|
|
3597
|
+
agent_id: row.agent_id,
|
|
3598
|
+
agent_role: row.agent_role,
|
|
3599
|
+
session_id: row.session_id,
|
|
3600
|
+
timestamp: row.timestamp,
|
|
3601
|
+
tool_name: row.tool_name,
|
|
3602
|
+
project_name: row.project_name,
|
|
3603
|
+
has_error: row.has_error === 1,
|
|
3604
|
+
raw_text: row.raw_text,
|
|
3605
|
+
vector: row.vector == null ? [] : Array.isArray(row.vector) ? row.vector : Array.from(row.vector),
|
|
3606
|
+
task_id: row.task_id ?? null,
|
|
3607
|
+
importance: row.importance ?? 5,
|
|
3608
|
+
status: row.status ?? "active",
|
|
3609
|
+
confidence: row.confidence ?? 0.7,
|
|
3610
|
+
last_accessed: row.last_accessed ?? row.timestamp,
|
|
3611
|
+
workspace_id: row.workspace_id ?? null,
|
|
3612
|
+
document_id: row.document_id ?? null,
|
|
3613
|
+
user_id: row.user_id ?? null,
|
|
3614
|
+
char_offset: row.char_offset ?? null,
|
|
3615
|
+
page_number: row.page_number ?? null,
|
|
3616
|
+
source_path: row.source_path ?? null,
|
|
3617
|
+
source_type: row.source_type ?? null
|
|
3618
|
+
}));
|
|
3619
|
+
} catch {
|
|
3620
|
+
return null;
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3436
3623
|
export {
|
|
3437
3624
|
estimateCardinality,
|
|
3438
3625
|
hybridSearch,
|