@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
|
@@ -356,7 +356,7 @@ function wrapWithRetry(client) {
|
|
|
356
356
|
return (sql) => retryOnBusy(() => target.execute(sql), "execute");
|
|
357
357
|
}
|
|
358
358
|
if (prop === "batch") {
|
|
359
|
-
return (stmts) => retryOnBusy(() => target.batch(stmts), "batch");
|
|
359
|
+
return (stmts, mode) => retryOnBusy(() => target.batch(stmts, mode), "batch");
|
|
360
360
|
}
|
|
361
361
|
return Reflect.get(target, prop, receiver);
|
|
362
362
|
}
|
|
@@ -372,6 +372,240 @@ var init_db_retry = __esm({
|
|
|
372
372
|
}
|
|
373
373
|
});
|
|
374
374
|
|
|
375
|
+
// src/lib/config.ts
|
|
376
|
+
import { readFile, writeFile, mkdir, chmod } from "fs/promises";
|
|
377
|
+
import { readFileSync as readFileSync3, existsSync as existsSync3, renameSync as renameSync2 } from "fs";
|
|
378
|
+
import path3 from "path";
|
|
379
|
+
import os3 from "os";
|
|
380
|
+
function resolveDataDir() {
|
|
381
|
+
if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
|
|
382
|
+
if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
|
|
383
|
+
const newDir = path3.join(os3.homedir(), ".exe-os");
|
|
384
|
+
const legacyDir = path3.join(os3.homedir(), ".exe-mem");
|
|
385
|
+
if (!existsSync3(newDir) && existsSync3(legacyDir)) {
|
|
386
|
+
try {
|
|
387
|
+
renameSync2(legacyDir, newDir);
|
|
388
|
+
process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
|
|
389
|
+
`);
|
|
390
|
+
} catch {
|
|
391
|
+
return legacyDir;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return newDir;
|
|
395
|
+
}
|
|
396
|
+
function migrateLegacyConfig(raw) {
|
|
397
|
+
if ("r2" in raw) {
|
|
398
|
+
process.stderr.write(
|
|
399
|
+
"[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"
|
|
400
|
+
);
|
|
401
|
+
delete raw.r2;
|
|
402
|
+
}
|
|
403
|
+
if ("syncIntervalMs" in raw) {
|
|
404
|
+
delete raw.syncIntervalMs;
|
|
405
|
+
}
|
|
406
|
+
return raw;
|
|
407
|
+
}
|
|
408
|
+
function migrateConfig(raw) {
|
|
409
|
+
const fromVersion = typeof raw.config_version === "number" ? raw.config_version : 0;
|
|
410
|
+
let currentVersion = fromVersion;
|
|
411
|
+
let migrated = false;
|
|
412
|
+
if (currentVersion > CURRENT_CONFIG_VERSION) {
|
|
413
|
+
return { config: raw, migrated: false, fromVersion };
|
|
414
|
+
}
|
|
415
|
+
for (const migration of CONFIG_MIGRATIONS) {
|
|
416
|
+
if (currentVersion === migration.from && migration.to <= CURRENT_CONFIG_VERSION) {
|
|
417
|
+
raw = migration.migrate(raw);
|
|
418
|
+
currentVersion = migration.to;
|
|
419
|
+
migrated = true;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return { config: raw, migrated, fromVersion };
|
|
423
|
+
}
|
|
424
|
+
function normalizeScalingRoadmap(raw) {
|
|
425
|
+
const defaultAuto = DEFAULT_CONFIG.scalingRoadmap.rerankerAutoTrigger;
|
|
426
|
+
const userRoadmap = raw.scalingRoadmap ?? {};
|
|
427
|
+
const userAuto = userRoadmap.rerankerAutoTrigger ?? {};
|
|
428
|
+
if (userAuto.enabled === void 0 && raw.rerankerEnabled !== void 0) {
|
|
429
|
+
userAuto.enabled = raw.rerankerEnabled;
|
|
430
|
+
}
|
|
431
|
+
raw.scalingRoadmap = {
|
|
432
|
+
...userRoadmap,
|
|
433
|
+
rerankerAutoTrigger: { ...defaultAuto, ...userAuto }
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
function normalizeSessionLifecycle(raw) {
|
|
437
|
+
const defaultSL = DEFAULT_CONFIG.sessionLifecycle;
|
|
438
|
+
const userSL = raw.sessionLifecycle ?? {};
|
|
439
|
+
raw.sessionLifecycle = { ...defaultSL, ...userSL };
|
|
440
|
+
}
|
|
441
|
+
function normalizeAutoUpdate(raw) {
|
|
442
|
+
const defaultAU = DEFAULT_CONFIG.autoUpdate;
|
|
443
|
+
const userAU = raw.autoUpdate ?? {};
|
|
444
|
+
raw.autoUpdate = { ...defaultAU, ...userAU };
|
|
445
|
+
}
|
|
446
|
+
async function loadConfig() {
|
|
447
|
+
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
448
|
+
await mkdir(dir, { recursive: true });
|
|
449
|
+
const configPath = path3.join(dir, "config.json");
|
|
450
|
+
if (!existsSync3(configPath)) {
|
|
451
|
+
return { ...DEFAULT_CONFIG, dbPath: path3.join(dir, "memories.db") };
|
|
452
|
+
}
|
|
453
|
+
const raw = await readFile(configPath, "utf-8");
|
|
454
|
+
try {
|
|
455
|
+
let parsed = JSON.parse(raw);
|
|
456
|
+
parsed = migrateLegacyConfig(parsed);
|
|
457
|
+
const { config: migratedCfg, migrated, fromVersion } = migrateConfig(parsed);
|
|
458
|
+
if (migrated) {
|
|
459
|
+
process.stderr.write(`[exe-os] Config migrated from v${fromVersion} to v${migratedCfg.config_version}
|
|
460
|
+
`);
|
|
461
|
+
try {
|
|
462
|
+
await writeFile(configPath, JSON.stringify(migratedCfg, null, 2) + "\n");
|
|
463
|
+
} catch {
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
normalizeScalingRoadmap(migratedCfg);
|
|
467
|
+
normalizeSessionLifecycle(migratedCfg);
|
|
468
|
+
normalizeAutoUpdate(migratedCfg);
|
|
469
|
+
const config = { ...DEFAULT_CONFIG, dbPath: path3.join(dir, "memories.db"), ...migratedCfg };
|
|
470
|
+
if (config.dbPath.startsWith("~")) {
|
|
471
|
+
config.dbPath = config.dbPath.replace(/^~/, os3.homedir());
|
|
472
|
+
}
|
|
473
|
+
return config;
|
|
474
|
+
} catch {
|
|
475
|
+
return { ...DEFAULT_CONFIG, dbPath: path3.join(dir, "memories.db") };
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
var EXE_AI_DIR, DB_PATH, MODELS_DIR, CONFIG_PATH, LEGACY_LANCE_PATH, CURRENT_CONFIG_VERSION, DEFAULT_CONFIG, CONFIG_MIGRATIONS;
|
|
479
|
+
var init_config = __esm({
|
|
480
|
+
"src/lib/config.ts"() {
|
|
481
|
+
"use strict";
|
|
482
|
+
EXE_AI_DIR = resolveDataDir();
|
|
483
|
+
DB_PATH = path3.join(EXE_AI_DIR, "memories.db");
|
|
484
|
+
MODELS_DIR = path3.join(EXE_AI_DIR, "models");
|
|
485
|
+
CONFIG_PATH = path3.join(EXE_AI_DIR, "config.json");
|
|
486
|
+
LEGACY_LANCE_PATH = path3.join(EXE_AI_DIR, "local.lance");
|
|
487
|
+
CURRENT_CONFIG_VERSION = 1;
|
|
488
|
+
DEFAULT_CONFIG = {
|
|
489
|
+
config_version: CURRENT_CONFIG_VERSION,
|
|
490
|
+
dbPath: DB_PATH,
|
|
491
|
+
modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
|
|
492
|
+
embeddingDim: 1024,
|
|
493
|
+
batchSize: 20,
|
|
494
|
+
flushIntervalMs: 1e4,
|
|
495
|
+
autoIngestion: true,
|
|
496
|
+
autoRetrieval: true,
|
|
497
|
+
searchMode: "hybrid",
|
|
498
|
+
hookSearchMode: "hybrid",
|
|
499
|
+
fileGrepEnabled: true,
|
|
500
|
+
splashEffect: true,
|
|
501
|
+
consolidationEnabled: true,
|
|
502
|
+
consolidationIntervalMs: 6 * 60 * 60 * 1e3,
|
|
503
|
+
consolidationModel: "claude-haiku-4-5-20251001",
|
|
504
|
+
consolidationMaxCallsPerRun: 20,
|
|
505
|
+
selfQueryRouter: true,
|
|
506
|
+
selfQueryModel: "claude-haiku-4-5-20251001",
|
|
507
|
+
rerankerEnabled: true,
|
|
508
|
+
scalingRoadmap: {
|
|
509
|
+
rerankerAutoTrigger: {
|
|
510
|
+
enabled: true,
|
|
511
|
+
broadQueryMinCardinality: 5e4,
|
|
512
|
+
fetchTopK: 150,
|
|
513
|
+
returnTopK: 5
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
graphRagEnabled: true,
|
|
517
|
+
wikiEnabled: false,
|
|
518
|
+
wikiUrl: "",
|
|
519
|
+
wikiApiKey: "",
|
|
520
|
+
wikiSyncIntervalMs: 30 * 60 * 1e3,
|
|
521
|
+
wikiWorkspaceMapping: {},
|
|
522
|
+
wikiAutoUpdate: true,
|
|
523
|
+
wikiAutoUpdateThreshold: 0.5,
|
|
524
|
+
wikiAutoUpdateCreateNew: true,
|
|
525
|
+
skillLearning: true,
|
|
526
|
+
skillThreshold: 3,
|
|
527
|
+
skillModel: "claude-haiku-4-5-20251001",
|
|
528
|
+
exeHeartbeat: {
|
|
529
|
+
enabled: true,
|
|
530
|
+
intervalSeconds: 60,
|
|
531
|
+
staleInProgressThresholdHours: 2
|
|
532
|
+
},
|
|
533
|
+
sessionLifecycle: {
|
|
534
|
+
idleKillEnabled: true,
|
|
535
|
+
idleKillTicksRequired: 3,
|
|
536
|
+
idleKillIntercomAckWindowMs: 1e4,
|
|
537
|
+
maxAutoInstances: 10
|
|
538
|
+
},
|
|
539
|
+
autoUpdate: {
|
|
540
|
+
checkOnBoot: true,
|
|
541
|
+
autoInstall: false,
|
|
542
|
+
checkIntervalMs: 24 * 60 * 60 * 1e3
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
CONFIG_MIGRATIONS = [
|
|
546
|
+
{
|
|
547
|
+
from: 0,
|
|
548
|
+
to: 1,
|
|
549
|
+
migrate: (cfg) => {
|
|
550
|
+
cfg.config_version = 1;
|
|
551
|
+
return cfg;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
];
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
// src/lib/employees.ts
|
|
559
|
+
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
560
|
+
import { existsSync as existsSync4, symlinkSync, readlinkSync, readFileSync as readFileSync4, renameSync as renameSync3, unlinkSync, writeFileSync as writeFileSync3 } from "fs";
|
|
561
|
+
import { execSync as execSync3 } from "child_process";
|
|
562
|
+
import path4 from "path";
|
|
563
|
+
import os4 from "os";
|
|
564
|
+
function normalizeRole(role) {
|
|
565
|
+
return (role ?? "").trim().toLowerCase();
|
|
566
|
+
}
|
|
567
|
+
function isCoordinatorRole(role) {
|
|
568
|
+
return normalizeRole(role) === normalizeRole(COORDINATOR_ROLE);
|
|
569
|
+
}
|
|
570
|
+
function getCoordinatorEmployee(employees) {
|
|
571
|
+
return employees.find((e) => isCoordinatorRole(e.role));
|
|
572
|
+
}
|
|
573
|
+
function getCoordinatorName(employees = loadEmployeesSync()) {
|
|
574
|
+
return getCoordinatorEmployee(employees)?.name ?? DEFAULT_COORDINATOR_TEMPLATE_NAME;
|
|
575
|
+
}
|
|
576
|
+
function isCoordinatorName(agentName, employees = loadEmployeesSync()) {
|
|
577
|
+
if (!agentName) return false;
|
|
578
|
+
return agentName.toLowerCase() === getCoordinatorName(employees).toLowerCase();
|
|
579
|
+
}
|
|
580
|
+
function loadEmployeesSync(employeesPath = EMPLOYEES_PATH) {
|
|
581
|
+
if (!existsSync4(employeesPath)) return [];
|
|
582
|
+
try {
|
|
583
|
+
return JSON.parse(readFileSync4(employeesPath, "utf-8"));
|
|
584
|
+
} catch {
|
|
585
|
+
return [];
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
function getEmployee(employees, name) {
|
|
589
|
+
return employees.find((e) => e.name.toLowerCase() === name.toLowerCase());
|
|
590
|
+
}
|
|
591
|
+
function isMultiInstance(agentName, employees) {
|
|
592
|
+
const roster = employees ?? loadEmployeesSync();
|
|
593
|
+
const emp = getEmployee(roster, agentName);
|
|
594
|
+
if (!emp) return false;
|
|
595
|
+
return MULTI_INSTANCE_ROLES.has(emp.role.toLowerCase());
|
|
596
|
+
}
|
|
597
|
+
var EMPLOYEES_PATH, DEFAULT_COORDINATOR_TEMPLATE_NAME, COORDINATOR_ROLE, MULTI_INSTANCE_ROLES;
|
|
598
|
+
var init_employees = __esm({
|
|
599
|
+
"src/lib/employees.ts"() {
|
|
600
|
+
"use strict";
|
|
601
|
+
init_config();
|
|
602
|
+
EMPLOYEES_PATH = path4.join(EXE_AI_DIR, "exe-employees.json");
|
|
603
|
+
DEFAULT_COORDINATOR_TEMPLATE_NAME = "exe";
|
|
604
|
+
COORDINATOR_ROLE = "COO";
|
|
605
|
+
MULTI_INSTANCE_ROLES = /* @__PURE__ */ new Set(["principal engineer", "content production specialist", "staff code reviewer"]);
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
|
|
375
609
|
// src/lib/database.ts
|
|
376
610
|
var database_exports = {};
|
|
377
611
|
__export(database_exports, {
|
|
@@ -519,22 +753,24 @@ async function ensureSchema() {
|
|
|
519
753
|
ON behaviors(agent_id, active);
|
|
520
754
|
`);
|
|
521
755
|
try {
|
|
756
|
+
const coordinatorName = getCoordinatorName();
|
|
522
757
|
const existing = await client.execute({
|
|
523
|
-
sql: "SELECT COUNT(*) as cnt FROM behaviors WHERE agent_id =
|
|
524
|
-
args: []
|
|
758
|
+
sql: "SELECT COUNT(*) as cnt FROM behaviors WHERE agent_id = ?",
|
|
759
|
+
args: [coordinatorName]
|
|
525
760
|
});
|
|
526
761
|
if (Number(existing.rows[0]?.cnt) === 0) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
762
|
+
const seededAt = "2026-03-25T00:00:00Z";
|
|
763
|
+
for (const [domain, content] of [
|
|
764
|
+
["workflow", `Don't ask "keep going?" \u2014 just keep executing phases/plans autonomously`],
|
|
765
|
+
["tool-use", "Always use create_task MCP tool, never write .md files directly for task creation"],
|
|
766
|
+
["workflow", "Auto-start reviewing when idle and reviews are pending \u2014 never ask founder for permission"]
|
|
767
|
+
]) {
|
|
768
|
+
await client.execute({
|
|
769
|
+
sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, content, active, created_at, updated_at)
|
|
770
|
+
VALUES (hex(randomblob(16)), ?, NULL, ?, ?, 1, ?, ?)`,
|
|
771
|
+
args: [coordinatorName, domain, content, seededAt, seededAt]
|
|
772
|
+
});
|
|
773
|
+
}
|
|
538
774
|
}
|
|
539
775
|
} catch {
|
|
540
776
|
}
|
|
@@ -1207,264 +1443,76 @@ async function ensureSchema() {
|
|
|
1207
1443
|
try {
|
|
1208
1444
|
await client.execute({
|
|
1209
1445
|
sql: `ALTER TABLE memories ADD COLUMN supersedes_id TEXT`,
|
|
1210
|
-
args: []
|
|
1211
|
-
});
|
|
1212
|
-
} catch {
|
|
1213
|
-
}
|
|
1214
|
-
try {
|
|
1215
|
-
await client.execute(
|
|
1216
|
-
`CREATE INDEX IF NOT EXISTS idx_memories_supersedes ON memories(supersedes_id) WHERE supersedes_id IS NOT NULL`
|
|
1217
|
-
);
|
|
1218
|
-
} catch {
|
|
1219
|
-
}
|
|
1220
|
-
for (const col of [
|
|
1221
|
-
"ALTER TABLE tasks ADD COLUMN checkpoint TEXT",
|
|
1222
|
-
"ALTER TABLE tasks ADD COLUMN checkpoint_count INTEGER DEFAULT 0"
|
|
1223
|
-
]) {
|
|
1224
|
-
try {
|
|
1225
|
-
await client.execute(col);
|
|
1226
|
-
} catch {
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
async function disposeDatabase() {
|
|
1231
|
-
if (_client) {
|
|
1232
|
-
_client.close();
|
|
1233
|
-
_client = null;
|
|
1234
|
-
_resilientClient = null;
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
var _client, _resilientClient, initTurso, disposeTurso;
|
|
1238
|
-
var init_database = __esm({
|
|
1239
|
-
"src/lib/database.ts"() {
|
|
1240
|
-
"use strict";
|
|
1241
|
-
init_db_retry();
|
|
1242
|
-
_client = null;
|
|
1243
|
-
_resilientClient = null;
|
|
1244
|
-
initTurso = initDatabase;
|
|
1245
|
-
disposeTurso = disposeDatabase;
|
|
1246
|
-
}
|
|
1247
|
-
});
|
|
1248
|
-
|
|
1249
|
-
// src/lib/config.ts
|
|
1250
|
-
import { readFile, writeFile, mkdir, chmod } from "fs/promises";
|
|
1251
|
-
import { readFileSync as readFileSync3, existsSync as existsSync3, renameSync as renameSync2 } from "fs";
|
|
1252
|
-
import path3 from "path";
|
|
1253
|
-
import os3 from "os";
|
|
1254
|
-
function resolveDataDir() {
|
|
1255
|
-
if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
|
|
1256
|
-
if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
|
|
1257
|
-
const newDir = path3.join(os3.homedir(), ".exe-os");
|
|
1258
|
-
const legacyDir = path3.join(os3.homedir(), ".exe-mem");
|
|
1259
|
-
if (!existsSync3(newDir) && existsSync3(legacyDir)) {
|
|
1260
|
-
try {
|
|
1261
|
-
renameSync2(legacyDir, newDir);
|
|
1262
|
-
process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
|
|
1263
|
-
`);
|
|
1264
|
-
} catch {
|
|
1265
|
-
return legacyDir;
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
return newDir;
|
|
1269
|
-
}
|
|
1270
|
-
function migrateLegacyConfig(raw) {
|
|
1271
|
-
if ("r2" in raw) {
|
|
1272
|
-
process.stderr.write(
|
|
1273
|
-
"[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"
|
|
1274
|
-
);
|
|
1275
|
-
delete raw.r2;
|
|
1276
|
-
}
|
|
1277
|
-
if ("syncIntervalMs" in raw) {
|
|
1278
|
-
delete raw.syncIntervalMs;
|
|
1279
|
-
}
|
|
1280
|
-
return raw;
|
|
1281
|
-
}
|
|
1282
|
-
function migrateConfig(raw) {
|
|
1283
|
-
const fromVersion = typeof raw.config_version === "number" ? raw.config_version : 0;
|
|
1284
|
-
let currentVersion = fromVersion;
|
|
1285
|
-
let migrated = false;
|
|
1286
|
-
if (currentVersion > CURRENT_CONFIG_VERSION) {
|
|
1287
|
-
return { config: raw, migrated: false, fromVersion };
|
|
1446
|
+
args: []
|
|
1447
|
+
});
|
|
1448
|
+
} catch {
|
|
1288
1449
|
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1450
|
+
try {
|
|
1451
|
+
await client.execute(
|
|
1452
|
+
`CREATE INDEX IF NOT EXISTS idx_memories_supersedes ON memories(supersedes_id) WHERE supersedes_id IS NOT NULL`
|
|
1453
|
+
);
|
|
1454
|
+
} catch {
|
|
1455
|
+
}
|
|
1456
|
+
for (const col of [
|
|
1457
|
+
"ALTER TABLE tasks ADD COLUMN checkpoint TEXT",
|
|
1458
|
+
"ALTER TABLE tasks ADD COLUMN checkpoint_count INTEGER DEFAULT 0"
|
|
1459
|
+
]) {
|
|
1460
|
+
try {
|
|
1461
|
+
await client.execute(col);
|
|
1462
|
+
} catch {
|
|
1294
1463
|
}
|
|
1295
1464
|
}
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
if (userAuto.enabled === void 0 && raw.rerankerEnabled !== void 0) {
|
|
1303
|
-
userAuto.enabled = raw.rerankerEnabled;
|
|
1465
|
+
try {
|
|
1466
|
+
await client.execute({
|
|
1467
|
+
sql: `ALTER TABLE memories ADD COLUMN draft INTEGER DEFAULT 0`,
|
|
1468
|
+
args: []
|
|
1469
|
+
});
|
|
1470
|
+
} catch {
|
|
1304
1471
|
}
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
}
|
|
1310
|
-
function normalizeSessionLifecycle(raw) {
|
|
1311
|
-
const defaultSL = DEFAULT_CONFIG.sessionLifecycle;
|
|
1312
|
-
const userSL = raw.sessionLifecycle ?? {};
|
|
1313
|
-
raw.sessionLifecycle = { ...defaultSL, ...userSL };
|
|
1314
|
-
}
|
|
1315
|
-
function normalizeAutoUpdate(raw) {
|
|
1316
|
-
const defaultAU = DEFAULT_CONFIG.autoUpdate;
|
|
1317
|
-
const userAU = raw.autoUpdate ?? {};
|
|
1318
|
-
raw.autoUpdate = { ...defaultAU, ...userAU };
|
|
1319
|
-
}
|
|
1320
|
-
async function loadConfig() {
|
|
1321
|
-
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
1322
|
-
await mkdir(dir, { recursive: true });
|
|
1323
|
-
const configPath = path3.join(dir, "config.json");
|
|
1324
|
-
if (!existsSync3(configPath)) {
|
|
1325
|
-
return { ...DEFAULT_CONFIG, dbPath: path3.join(dir, "memories.db") };
|
|
1472
|
+
try {
|
|
1473
|
+
await client.execute(
|
|
1474
|
+
`CREATE INDEX IF NOT EXISTS idx_memories_draft ON memories(draft) WHERE draft = 1`
|
|
1475
|
+
);
|
|
1476
|
+
} catch {
|
|
1326
1477
|
}
|
|
1327
|
-
const raw = await readFile(configPath, "utf-8");
|
|
1328
1478
|
try {
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
process.stderr.write(`[exe-os] Config migrated from v${fromVersion} to v${migratedCfg.config_version}
|
|
1334
|
-
`);
|
|
1335
|
-
try {
|
|
1336
|
-
await writeFile(configPath, JSON.stringify(migratedCfg, null, 2) + "\n");
|
|
1337
|
-
} catch {
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
normalizeScalingRoadmap(migratedCfg);
|
|
1341
|
-
normalizeSessionLifecycle(migratedCfg);
|
|
1342
|
-
normalizeAutoUpdate(migratedCfg);
|
|
1343
|
-
const config = { ...DEFAULT_CONFIG, dbPath: path3.join(dir, "memories.db"), ...migratedCfg };
|
|
1344
|
-
if (config.dbPath.startsWith("~")) {
|
|
1345
|
-
config.dbPath = config.dbPath.replace(/^~/, os3.homedir());
|
|
1346
|
-
}
|
|
1347
|
-
return config;
|
|
1479
|
+
await client.execute({
|
|
1480
|
+
sql: `ALTER TABLE memories ADD COLUMN memory_type TEXT DEFAULT 'raw'`,
|
|
1481
|
+
args: []
|
|
1482
|
+
});
|
|
1348
1483
|
} catch {
|
|
1349
|
-
return { ...DEFAULT_CONFIG, dbPath: path3.join(dir, "memories.db") };
|
|
1350
1484
|
}
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
EXE_AI_DIR = resolveDataDir();
|
|
1357
|
-
DB_PATH = path3.join(EXE_AI_DIR, "memories.db");
|
|
1358
|
-
MODELS_DIR = path3.join(EXE_AI_DIR, "models");
|
|
1359
|
-
CONFIG_PATH = path3.join(EXE_AI_DIR, "config.json");
|
|
1360
|
-
LEGACY_LANCE_PATH = path3.join(EXE_AI_DIR, "local.lance");
|
|
1361
|
-
CURRENT_CONFIG_VERSION = 1;
|
|
1362
|
-
DEFAULT_CONFIG = {
|
|
1363
|
-
config_version: CURRENT_CONFIG_VERSION,
|
|
1364
|
-
dbPath: DB_PATH,
|
|
1365
|
-
modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
|
|
1366
|
-
embeddingDim: 1024,
|
|
1367
|
-
batchSize: 20,
|
|
1368
|
-
flushIntervalMs: 1e4,
|
|
1369
|
-
autoIngestion: true,
|
|
1370
|
-
autoRetrieval: true,
|
|
1371
|
-
searchMode: "hybrid",
|
|
1372
|
-
hookSearchMode: "hybrid",
|
|
1373
|
-
fileGrepEnabled: true,
|
|
1374
|
-
splashEffect: true,
|
|
1375
|
-
consolidationEnabled: true,
|
|
1376
|
-
consolidationIntervalMs: 6 * 60 * 60 * 1e3,
|
|
1377
|
-
consolidationModel: "claude-haiku-4-5-20251001",
|
|
1378
|
-
consolidationMaxCallsPerRun: 20,
|
|
1379
|
-
selfQueryRouter: true,
|
|
1380
|
-
selfQueryModel: "claude-haiku-4-5-20251001",
|
|
1381
|
-
rerankerEnabled: true,
|
|
1382
|
-
scalingRoadmap: {
|
|
1383
|
-
rerankerAutoTrigger: {
|
|
1384
|
-
enabled: true,
|
|
1385
|
-
broadQueryMinCardinality: 5e4,
|
|
1386
|
-
fetchTopK: 150,
|
|
1387
|
-
returnTopK: 5
|
|
1388
|
-
}
|
|
1389
|
-
},
|
|
1390
|
-
graphRagEnabled: true,
|
|
1391
|
-
wikiEnabled: false,
|
|
1392
|
-
wikiUrl: "",
|
|
1393
|
-
wikiApiKey: "",
|
|
1394
|
-
wikiSyncIntervalMs: 30 * 60 * 1e3,
|
|
1395
|
-
wikiWorkspaceMapping: {
|
|
1396
|
-
exe: "Executive",
|
|
1397
|
-
yoshi: "Engineering",
|
|
1398
|
-
mari: "Marketing",
|
|
1399
|
-
tom: "Engineering",
|
|
1400
|
-
sasha: "Production"
|
|
1401
|
-
},
|
|
1402
|
-
wikiAutoUpdate: true,
|
|
1403
|
-
wikiAutoUpdateThreshold: 0.5,
|
|
1404
|
-
wikiAutoUpdateCreateNew: true,
|
|
1405
|
-
skillLearning: true,
|
|
1406
|
-
skillThreshold: 3,
|
|
1407
|
-
skillModel: "claude-haiku-4-5-20251001",
|
|
1408
|
-
exeHeartbeat: {
|
|
1409
|
-
enabled: true,
|
|
1410
|
-
intervalSeconds: 60,
|
|
1411
|
-
staleInProgressThresholdHours: 2
|
|
1412
|
-
},
|
|
1413
|
-
sessionLifecycle: {
|
|
1414
|
-
idleKillEnabled: true,
|
|
1415
|
-
idleKillTicksRequired: 3,
|
|
1416
|
-
idleKillIntercomAckWindowMs: 1e4,
|
|
1417
|
-
maxAutoInstances: 10
|
|
1418
|
-
},
|
|
1419
|
-
autoUpdate: {
|
|
1420
|
-
checkOnBoot: true,
|
|
1421
|
-
autoInstall: false,
|
|
1422
|
-
checkIntervalMs: 24 * 60 * 60 * 1e3
|
|
1423
|
-
}
|
|
1424
|
-
};
|
|
1425
|
-
CONFIG_MIGRATIONS = [
|
|
1426
|
-
{
|
|
1427
|
-
from: 0,
|
|
1428
|
-
to: 1,
|
|
1429
|
-
migrate: (cfg) => {
|
|
1430
|
-
cfg.config_version = 1;
|
|
1431
|
-
return cfg;
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
];
|
|
1485
|
+
try {
|
|
1486
|
+
await client.execute(
|
|
1487
|
+
`CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(memory_type)`
|
|
1488
|
+
);
|
|
1489
|
+
} catch {
|
|
1435
1490
|
}
|
|
1436
|
-
});
|
|
1437
|
-
|
|
1438
|
-
// src/lib/employees.ts
|
|
1439
|
-
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
1440
|
-
import { existsSync as existsSync4, symlinkSync, readlinkSync, readFileSync as readFileSync4, renameSync as renameSync3, unlinkSync, writeFileSync as writeFileSync3 } from "fs";
|
|
1441
|
-
import { execSync as execSync3 } from "child_process";
|
|
1442
|
-
import path4 from "path";
|
|
1443
|
-
import os4 from "os";
|
|
1444
|
-
function loadEmployeesSync(employeesPath = EMPLOYEES_PATH) {
|
|
1445
|
-
if (!existsSync4(employeesPath)) return [];
|
|
1446
1491
|
try {
|
|
1447
|
-
|
|
1492
|
+
await client.execute({
|
|
1493
|
+
sql: `ALTER TABLE memories ADD COLUMN trajectory TEXT`,
|
|
1494
|
+
args: []
|
|
1495
|
+
});
|
|
1448
1496
|
} catch {
|
|
1449
|
-
return [];
|
|
1450
1497
|
}
|
|
1451
1498
|
}
|
|
1452
|
-
function
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
if (!emp) return false;
|
|
1459
|
-
return MULTI_INSTANCE_ROLES.has(emp.role.toLowerCase());
|
|
1499
|
+
async function disposeDatabase() {
|
|
1500
|
+
if (_client) {
|
|
1501
|
+
_client.close();
|
|
1502
|
+
_client = null;
|
|
1503
|
+
_resilientClient = null;
|
|
1504
|
+
}
|
|
1460
1505
|
}
|
|
1461
|
-
var
|
|
1462
|
-
var
|
|
1463
|
-
"src/lib/
|
|
1506
|
+
var _client, _resilientClient, initTurso, disposeTurso;
|
|
1507
|
+
var init_database = __esm({
|
|
1508
|
+
"src/lib/database.ts"() {
|
|
1464
1509
|
"use strict";
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1510
|
+
init_db_retry();
|
|
1511
|
+
init_employees();
|
|
1512
|
+
_client = null;
|
|
1513
|
+
_resilientClient = null;
|
|
1514
|
+
initTurso = initDatabase;
|
|
1515
|
+
disposeTurso = disposeDatabase;
|
|
1468
1516
|
}
|
|
1469
1517
|
});
|
|
1470
1518
|
|
|
@@ -1720,6 +1768,7 @@ __export(tasks_crud_exports, {
|
|
|
1720
1768
|
ensureArchitectureDoc: () => ensureArchitectureDoc,
|
|
1721
1769
|
ensureGitignoreExe: () => ensureGitignoreExe,
|
|
1722
1770
|
extractParentFromContext: () => extractParentFromContext,
|
|
1771
|
+
isTmuxSessionAlive: () => isTmuxSessionAlive,
|
|
1723
1772
|
listTasks: () => listTasks,
|
|
1724
1773
|
resolveTask: () => resolveTask,
|
|
1725
1774
|
slugify: () => slugify,
|
|
@@ -1970,6 +2019,36 @@ async function listTasks(input) {
|
|
|
1970
2019
|
tokensWarnedAt: r.tokens_warned_at !== null ? Number(r.tokens_warned_at) : null
|
|
1971
2020
|
}));
|
|
1972
2021
|
}
|
|
2022
|
+
function isTmuxSessionAlive(identifier) {
|
|
2023
|
+
if (!identifier || identifier === "unknown") return true;
|
|
2024
|
+
try {
|
|
2025
|
+
if (identifier.startsWith("%")) {
|
|
2026
|
+
const output = execSync4("tmux list-panes -a -F '#{pane_id}'", {
|
|
2027
|
+
timeout: 2e3,
|
|
2028
|
+
encoding: "utf8",
|
|
2029
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
2030
|
+
});
|
|
2031
|
+
return output.split("\n").some((l) => l.trim() === identifier);
|
|
2032
|
+
} else {
|
|
2033
|
+
execSync4(`tmux has-session -t ${JSON.stringify(identifier)}`, {
|
|
2034
|
+
timeout: 2e3,
|
|
2035
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
2036
|
+
});
|
|
2037
|
+
return true;
|
|
2038
|
+
}
|
|
2039
|
+
} catch {
|
|
2040
|
+
if (identifier.startsWith("%")) return true;
|
|
2041
|
+
try {
|
|
2042
|
+
execSync4("tmux list-sessions", {
|
|
2043
|
+
timeout: 2e3,
|
|
2044
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
2045
|
+
});
|
|
2046
|
+
return false;
|
|
2047
|
+
} catch {
|
|
2048
|
+
return true;
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
1973
2052
|
function checkStaleCompletion(taskContext, taskCreatedAt) {
|
|
1974
2053
|
if (!taskContext) return null;
|
|
1975
2054
|
if (!DELEGATION_KEYWORDS.test(taskContext)) return null;
|
|
@@ -2032,13 +2111,59 @@ ${input.result}` : `\u26A0\uFE0F ${warning}`;
|
|
|
2032
2111
|
});
|
|
2033
2112
|
if (claim.rowsAffected === 0) {
|
|
2034
2113
|
const current = await client.execute({
|
|
2035
|
-
sql: "SELECT status, assigned_tmux FROM tasks WHERE id = ?",
|
|
2114
|
+
sql: "SELECT status, assigned_tmux, assigned_by FROM tasks WHERE id = ?",
|
|
2036
2115
|
args: [taskId]
|
|
2037
2116
|
});
|
|
2038
2117
|
const cur = current.rows[0];
|
|
2039
|
-
const
|
|
2040
|
-
const
|
|
2041
|
-
|
|
2118
|
+
const curStatus = cur?.status ?? "unknown";
|
|
2119
|
+
const claimedBySession = cur?.assigned_tmux ?? "";
|
|
2120
|
+
const assignedBy = cur?.assigned_by ?? "";
|
|
2121
|
+
if (curStatus === "in_progress" && claimedBySession && !isTmuxSessionAlive(claimedBySession)) {
|
|
2122
|
+
process.stderr.write(
|
|
2123
|
+
`[tasks] Auto-releasing dead claim on ${taskId} (was ${claimedBySession})
|
|
2124
|
+
`
|
|
2125
|
+
);
|
|
2126
|
+
await client.execute({
|
|
2127
|
+
sql: "UPDATE tasks SET status = 'open', assigned_tmux = NULL, updated_at = ? WHERE id = ?",
|
|
2128
|
+
args: [now, taskId]
|
|
2129
|
+
});
|
|
2130
|
+
const retried = await client.execute({
|
|
2131
|
+
sql: `UPDATE tasks SET status = 'in_progress', assigned_tmux = ?, updated_at = ? WHERE id = ? AND status = 'open'`,
|
|
2132
|
+
args: [tmuxSession, now, taskId]
|
|
2133
|
+
});
|
|
2134
|
+
if (retried.rowsAffected > 0) {
|
|
2135
|
+
try {
|
|
2136
|
+
await writeCheckpoint({
|
|
2137
|
+
taskId,
|
|
2138
|
+
step: "reclaimed_dead_session",
|
|
2139
|
+
contextSummary: `Task reclaimed after dead session ${claimedBySession} released.`
|
|
2140
|
+
});
|
|
2141
|
+
} catch {
|
|
2142
|
+
}
|
|
2143
|
+
return { row, taskFile, now, taskId };
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
if (curStatus === "in_progress" && input.callerAgentId && (input.callerAgentId === assignedBy || input.callerAgentId === "exe")) {
|
|
2147
|
+
process.stderr.write(
|
|
2148
|
+
`[tasks] Assigner override: ${input.callerAgentId} reclaiming ${taskId}
|
|
2149
|
+
`
|
|
2150
|
+
);
|
|
2151
|
+
await client.execute({
|
|
2152
|
+
sql: `UPDATE tasks SET status = 'in_progress', assigned_tmux = ?, updated_at = ? WHERE id = ?`,
|
|
2153
|
+
args: [tmuxSession, now, taskId]
|
|
2154
|
+
});
|
|
2155
|
+
try {
|
|
2156
|
+
await writeCheckpoint({
|
|
2157
|
+
taskId,
|
|
2158
|
+
step: "assigner_override",
|
|
2159
|
+
contextSummary: `Task force-reclaimed by assigner ${input.callerAgentId}.`
|
|
2160
|
+
});
|
|
2161
|
+
} catch {
|
|
2162
|
+
}
|
|
2163
|
+
return { row, taskFile, now, taskId };
|
|
2164
|
+
}
|
|
2165
|
+
const claimedBy = claimedBySession ? ` (claimed by ${claimedBySession})` : "";
|
|
2166
|
+
throw new Error(`${TASK_ALREADY_CLAIMED_PREFIX}: task ${taskId} is ${curStatus}${claimedBy}`);
|
|
2042
2167
|
}
|
|
2043
2168
|
try {
|
|
2044
2169
|
await writeCheckpoint({
|
|
@@ -2136,7 +2261,7 @@ var init_tasks_crud = __esm({
|
|
|
2136
2261
|
"use strict";
|
|
2137
2262
|
init_database();
|
|
2138
2263
|
init_task_scope();
|
|
2139
|
-
DELEGATION_KEYWORDS = /parallel|delegate|wave|
|
|
2264
|
+
DELEGATION_KEYWORDS = /parallel|delegate|wave|worktree|multi-instance/i;
|
|
2140
2265
|
TASK_ALREADY_CLAIMED_PREFIX = "TASK_ALREADY_CLAIMED";
|
|
2141
2266
|
}
|
|
2142
2267
|
});
|
|
@@ -2493,7 +2618,7 @@ function findSessionForProject(projectName) {
|
|
|
2493
2618
|
const sessions = listSessions();
|
|
2494
2619
|
for (const s of sessions) {
|
|
2495
2620
|
const proj = s.projectDir.split("/").filter(Boolean).pop();
|
|
2496
|
-
if (proj === projectName && s.agentId === "exe") return s;
|
|
2621
|
+
if (proj === projectName && (s.agentId === "exe" || isCoordinatorName(s.agentId))) return s;
|
|
2497
2622
|
}
|
|
2498
2623
|
return null;
|
|
2499
2624
|
}
|
|
@@ -2533,12 +2658,13 @@ var init_session_scope = __esm({
|
|
|
2533
2658
|
init_session_registry();
|
|
2534
2659
|
init_project_name();
|
|
2535
2660
|
init_tmux_routing();
|
|
2661
|
+
init_employees();
|
|
2536
2662
|
}
|
|
2537
2663
|
});
|
|
2538
2664
|
|
|
2539
2665
|
// src/lib/tasks-notify.ts
|
|
2540
2666
|
async function dispatchTaskToEmployee(input) {
|
|
2541
|
-
if (input.assignedTo === "exe") return { dispatched: "skipped" };
|
|
2667
|
+
if (input.assignedTo === "exe" || isCoordinatorName(input.assignedTo)) return { dispatched: "skipped" };
|
|
2542
2668
|
let crossProject = false;
|
|
2543
2669
|
if (input.projectName) {
|
|
2544
2670
|
try {
|
|
@@ -2981,6 +3107,24 @@ async function updateTask(input) {
|
|
|
2981
3107
|
});
|
|
2982
3108
|
} catch {
|
|
2983
3109
|
}
|
|
3110
|
+
const assignedAgent = String(row.assigned_to);
|
|
3111
|
+
if (!isCoordinatorName(assignedAgent)) {
|
|
3112
|
+
try {
|
|
3113
|
+
const draftClient = getClient();
|
|
3114
|
+
if (input.status === "done") {
|
|
3115
|
+
await draftClient.execute({
|
|
3116
|
+
sql: `UPDATE memories SET draft = 0 WHERE agent_id = ? AND draft = 1`,
|
|
3117
|
+
args: [assignedAgent]
|
|
3118
|
+
});
|
|
3119
|
+
} else if (input.status === "cancelled") {
|
|
3120
|
+
await draftClient.execute({
|
|
3121
|
+
sql: `DELETE FROM memories WHERE agent_id = ? AND draft = 1`,
|
|
3122
|
+
args: [assignedAgent]
|
|
3123
|
+
});
|
|
3124
|
+
}
|
|
3125
|
+
} catch {
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
2984
3128
|
try {
|
|
2985
3129
|
const client = getClient();
|
|
2986
3130
|
const cascaded = await client.execute({
|
|
@@ -2999,8 +3143,8 @@ async function updateTask(input) {
|
|
|
2999
3143
|
}
|
|
3000
3144
|
const isTerminal = input.status === "done" || input.status === "needs_review";
|
|
3001
3145
|
if (isTerminal) {
|
|
3002
|
-
const
|
|
3003
|
-
if (!
|
|
3146
|
+
const isCoordinator = String(row.assigned_to) === "exe" || isCoordinatorName(String(row.assigned_to));
|
|
3147
|
+
if (!isCoordinator) {
|
|
3004
3148
|
notifyTaskDone();
|
|
3005
3149
|
}
|
|
3006
3150
|
await markTaskNotificationsRead(taskFile);
|
|
@@ -3024,7 +3168,7 @@ async function updateTask(input) {
|
|
|
3024
3168
|
}
|
|
3025
3169
|
}
|
|
3026
3170
|
}
|
|
3027
|
-
if (input.status === "done" && String(row.assigned_to) !== "exe" && !process.env.VITEST) {
|
|
3171
|
+
if (input.status === "done" && String(row.assigned_to) !== "exe" && !isCoordinatorName(String(row.assigned_to)) && !process.env.VITEST) {
|
|
3028
3172
|
Promise.resolve().then(() => (init_skill_learning(), skill_learning_exports)).then(
|
|
3029
3173
|
({ captureAndLearn: captureAndLearn2 }) => captureAndLearn2({
|
|
3030
3174
|
taskId,
|
|
@@ -3040,7 +3184,7 @@ async function updateTask(input) {
|
|
|
3040
3184
|
});
|
|
3041
3185
|
}
|
|
3042
3186
|
let nextTask;
|
|
3043
|
-
if (isTerminal && String(row.assigned_to) !== "exe") {
|
|
3187
|
+
if (isTerminal && String(row.assigned_to) !== "exe" && !isCoordinatorName(String(row.assigned_to))) {
|
|
3044
3188
|
try {
|
|
3045
3189
|
nextTask = await findNextTask(String(row.assigned_to));
|
|
3046
3190
|
} catch {
|
|
@@ -3067,12 +3211,14 @@ async function updateTask(input) {
|
|
|
3067
3211
|
async function deleteTask(taskId, baseDir) {
|
|
3068
3212
|
const client = getClient();
|
|
3069
3213
|
const { taskFile, assignedTo, assignedBy, taskSlug } = await deleteTaskCore(taskId, baseDir);
|
|
3070
|
-
const
|
|
3214
|
+
const coordinatorName = getCoordinatorName();
|
|
3215
|
+
const reviewer = assignedBy || coordinatorName;
|
|
3071
3216
|
const reviewSlug = `review-${assignedTo}-${taskSlug}`;
|
|
3072
3217
|
const reviewFile = `exe/${reviewer}/${reviewSlug}.md`;
|
|
3218
|
+
const legacyReviewFile = `exe/${coordinatorName}/${reviewSlug}.md`;
|
|
3073
3219
|
await client.execute({
|
|
3074
|
-
sql: "DELETE FROM tasks WHERE task_file = ? OR task_file = ?",
|
|
3075
|
-
args: [reviewFile, `exe/exe/${reviewSlug}.md`]
|
|
3220
|
+
sql: "DELETE FROM tasks WHERE task_file = ? OR task_file = ? OR task_file = ?",
|
|
3221
|
+
args: [reviewFile, legacyReviewFile, `exe/exe/${reviewSlug}.md`]
|
|
3076
3222
|
});
|
|
3077
3223
|
await markAsReadByTaskFile(taskFile);
|
|
3078
3224
|
await markAsReadByTaskFile(reviewFile);
|
|
@@ -3084,6 +3230,7 @@ var init_tasks = __esm({
|
|
|
3084
3230
|
init_config();
|
|
3085
3231
|
init_notifications();
|
|
3086
3232
|
init_state_bus();
|
|
3233
|
+
init_employees();
|
|
3087
3234
|
init_tasks_crud();
|
|
3088
3235
|
init_tasks_review();
|
|
3089
3236
|
init_tasks_crud();
|
|
@@ -3169,7 +3316,7 @@ function _resetLastRelaunchCache() {
|
|
|
3169
3316
|
}
|
|
3170
3317
|
async function lastResumeCreatedAtMs(agentId) {
|
|
3171
3318
|
const client = getClient();
|
|
3172
|
-
const cmScope = sessionScopeFilter();
|
|
3319
|
+
const cmScope = sessionScopeFilter(null);
|
|
3173
3320
|
const result = await client.execute({
|
|
3174
3321
|
sql: `SELECT MAX(created_at) AS last_created_at
|
|
3175
3322
|
FROM tasks
|
|
@@ -3194,7 +3341,7 @@ async function createOrRefreshResumeTask(agentId, projectDir, openTasks) {
|
|
|
3194
3341
|
const client = getClient();
|
|
3195
3342
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3196
3343
|
const context = buildResumeContext(agentId, openTasks);
|
|
3197
|
-
const rdScope = sessionScopeFilter();
|
|
3344
|
+
const rdScope = sessionScopeFilter(null);
|
|
3198
3345
|
const existing = await client.execute({
|
|
3199
3346
|
sql: `SELECT id FROM tasks
|
|
3200
3347
|
WHERE assigned_to = ?
|
|
@@ -3228,7 +3375,7 @@ async function pollCapacityDead() {
|
|
|
3228
3375
|
const transport = getTransport();
|
|
3229
3376
|
const relaunched = [];
|
|
3230
3377
|
const registered = listSessions().filter(
|
|
3231
|
-
(s) => s.agentId !== "exe"
|
|
3378
|
+
(s) => s.agentId !== "exe" && !isCoordinatorName(s.agentId)
|
|
3232
3379
|
);
|
|
3233
3380
|
if (registered.length === 0) return [];
|
|
3234
3381
|
let liveSessions;
|
|
@@ -3288,7 +3435,7 @@ async function pollCapacityDead() {
|
|
|
3288
3435
|
reason: "capacity"
|
|
3289
3436
|
});
|
|
3290
3437
|
const client = getClient();
|
|
3291
|
-
const rlScope = sessionScopeFilter();
|
|
3438
|
+
const rlScope = sessionScopeFilter(null);
|
|
3292
3439
|
const openTasks = await client.execute({
|
|
3293
3440
|
sql: `SELECT id, title, priority, task_file, status
|
|
3294
3441
|
FROM tasks
|
|
@@ -3342,6 +3489,7 @@ var init_capacity_monitor = __esm({
|
|
|
3342
3489
|
init_session_kill_telemetry();
|
|
3343
3490
|
init_tmux_routing();
|
|
3344
3491
|
init_task_scope();
|
|
3492
|
+
init_employees();
|
|
3345
3493
|
CAPACITY_PATTERNS = [
|
|
3346
3494
|
/conversation is too long/i,
|
|
3347
3495
|
/maximum context length/i,
|
|
@@ -3491,7 +3639,7 @@ function employeeSessionName(employee, exeSession, instance) {
|
|
|
3491
3639
|
exeSession = root;
|
|
3492
3640
|
} else {
|
|
3493
3641
|
throw new Error(
|
|
3494
|
-
`Invalid
|
|
3642
|
+
`Invalid coordinator session "${exeSession}" \u2014 contains a dash but no recognizable root session. Pass a root session name.`
|
|
3495
3643
|
);
|
|
3496
3644
|
}
|
|
3497
3645
|
}
|
|
@@ -3511,8 +3659,10 @@ function parseParentExe(sessionName, agentId) {
|
|
|
3511
3659
|
return match?.[1] ?? null;
|
|
3512
3660
|
}
|
|
3513
3661
|
function extractRootExe(name) {
|
|
3514
|
-
|
|
3515
|
-
|
|
3662
|
+
if (!name) return null;
|
|
3663
|
+
if (!name.includes("-")) return name;
|
|
3664
|
+
const parts = name.split("-").filter(Boolean);
|
|
3665
|
+
return parts.length > 0 ? parts[parts.length - 1] : null;
|
|
3516
3666
|
}
|
|
3517
3667
|
function registerParentExe(sessionKey, parentExe, dispatchedBy) {
|
|
3518
3668
|
if (!existsSync10(SESSION_CACHE)) {
|
|
@@ -3657,12 +3807,14 @@ function isSessionBusy(sessionName) {
|
|
|
3657
3807
|
return state === "thinking" || state === "tool";
|
|
3658
3808
|
}
|
|
3659
3809
|
function isExeSession(sessionName) {
|
|
3660
|
-
|
|
3810
|
+
const matchesBaseWithInstance = (baseName) => sessionName === baseName || sessionName.startsWith(baseName) && /^\d+$/.test(sessionName.slice(baseName.length));
|
|
3811
|
+
const coordinatorName = getCoordinatorName();
|
|
3812
|
+
return matchesBaseWithInstance(coordinatorName) || matchesBaseWithInstance("exe");
|
|
3661
3813
|
}
|
|
3662
3814
|
function sendIntercom(targetSession) {
|
|
3663
3815
|
const transport = getTransport();
|
|
3664
3816
|
if (isExeSession(targetSession)) {
|
|
3665
|
-
logIntercom(`
|
|
3817
|
+
logIntercom(`SKIP_COORDINATOR \u2192 ${targetSession} (coordinator sessions use prompt-submit hook)`);
|
|
3666
3818
|
return "skipped_exe";
|
|
3667
3819
|
}
|
|
3668
3820
|
if (isDebounced(targetSession)) {
|
|
@@ -3714,7 +3866,7 @@ function notifyParentExe(sessionKey) {
|
|
|
3714
3866
|
if (result === "failed") {
|
|
3715
3867
|
const rootExe = resolveExeSession();
|
|
3716
3868
|
if (rootExe && rootExe !== target) {
|
|
3717
|
-
process.stderr.write(`[intercom] notifyParentExe: dispatcher ${target} dead, falling back to root
|
|
3869
|
+
process.stderr.write(`[intercom] notifyParentExe: dispatcher ${target} dead, falling back to root coordinator session ${rootExe}
|
|
3718
3870
|
`);
|
|
3719
3871
|
const fallback = sendIntercom(rootExe);
|
|
3720
3872
|
return fallback !== "failed";
|
|
@@ -3724,8 +3876,8 @@ function notifyParentExe(sessionKey) {
|
|
|
3724
3876
|
return true;
|
|
3725
3877
|
}
|
|
3726
3878
|
function ensureEmployee(employeeName, exeSession, projectDir, opts) {
|
|
3727
|
-
if (employeeName === "exe") {
|
|
3728
|
-
return { status: "failed", sessionName: "", error: "
|
|
3879
|
+
if (employeeName === "exe" || isCoordinatorName(employeeName)) {
|
|
3880
|
+
return { status: "failed", sessionName: "", error: "The COO is not a dispatchable employee" };
|
|
3729
3881
|
}
|
|
3730
3882
|
try {
|
|
3731
3883
|
assertEmployeeLimitSync();
|
|
@@ -3734,8 +3886,8 @@ function ensureEmployee(employeeName, exeSession, projectDir, opts) {
|
|
|
3734
3886
|
return { status: "failed", sessionName: "", error: err.message };
|
|
3735
3887
|
}
|
|
3736
3888
|
}
|
|
3737
|
-
if (
|
|
3738
|
-
const bare = employeeName.
|
|
3889
|
+
if (employeeName.includes("-")) {
|
|
3890
|
+
const bare = employeeName.split("-")[0].replace(/\d+$/, "");
|
|
3739
3891
|
return {
|
|
3740
3892
|
status: "failed",
|
|
3741
3893
|
sessionName: "",
|
|
@@ -3754,7 +3906,7 @@ function ensureEmployee(employeeName, exeSession, projectDir, opts) {
|
|
|
3754
3906
|
return {
|
|
3755
3907
|
status: "failed",
|
|
3756
3908
|
sessionName: "",
|
|
3757
|
-
error: `Invalid
|
|
3909
|
+
error: `Invalid coordinator session "${exeSession}" \u2014 contains a dash but no recognizable root session. Pass a root session name.`
|
|
3758
3910
|
};
|
|
3759
3911
|
}
|
|
3760
3912
|
}
|
|
@@ -3911,8 +4063,8 @@ function spawnEmployee(employeeName, exeSession, projectDir, opts) {
|
|
|
3911
4063
|
const ctxContent = [
|
|
3912
4064
|
`## Session Context`,
|
|
3913
4065
|
`You are running in tmux session: ${sessionName}.`,
|
|
3914
|
-
`Your parent
|
|
3915
|
-
`Your employees (if any) use the -${exeSession} suffix
|
|
4066
|
+
`Your parent coordinator session is ${exeSession}.`,
|
|
4067
|
+
`Your employees (if any) use the -${exeSession} suffix.`
|
|
3916
4068
|
].join("\n");
|
|
3917
4069
|
writeFileSync6(ctxFile, ctxContent);
|
|
3918
4070
|
sessionContextFlag = ` --append-system-prompt-file ${ctxFile}`;
|
|
@@ -4016,6 +4168,7 @@ var init_tmux_routing = __esm({
|
|
|
4016
4168
|
init_provider_table();
|
|
4017
4169
|
init_intercom_queue();
|
|
4018
4170
|
init_plan_limits();
|
|
4171
|
+
init_employees();
|
|
4019
4172
|
SPAWN_LOCK_DIR = path13.join(os6.homedir(), ".exe-os", "spawn-locks");
|
|
4020
4173
|
SESSION_CACHE = path13.join(os6.homedir(), ".exe-os", "session-cache");
|
|
4021
4174
|
BEHAVIORS_EXPORT_TIMEOUT_MS = 1e4;
|
|
@@ -4233,7 +4386,11 @@ async function ensureShardSchema(client) {
|
|
|
4233
4386
|
"ALTER TABLE memories ADD COLUMN source_path TEXT",
|
|
4234
4387
|
"ALTER TABLE memories ADD COLUMN source_type TEXT DEFAULT 'text'",
|
|
4235
4388
|
"ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3",
|
|
4236
|
-
"ALTER TABLE memories ADD COLUMN supersedes_id TEXT"
|
|
4389
|
+
"ALTER TABLE memories ADD COLUMN supersedes_id TEXT",
|
|
4390
|
+
// MS-11: draft staging, MS-6a: memory_type, MS-7: trajectory
|
|
4391
|
+
"ALTER TABLE memories ADD COLUMN draft INTEGER DEFAULT 0",
|
|
4392
|
+
"ALTER TABLE memories ADD COLUMN memory_type TEXT DEFAULT 'raw'",
|
|
4393
|
+
"ALTER TABLE memories ADD COLUMN trajectory TEXT"
|
|
4237
4394
|
]) {
|
|
4238
4395
|
try {
|
|
4239
4396
|
await client.execute(col);
|
|
@@ -4363,26 +4520,26 @@ var init_platform_procedures = __esm({
|
|
|
4363
4520
|
title: "What is exe-os \u2014 the operating model every agent must understand",
|
|
4364
4521
|
domain: "architecture",
|
|
4365
4522
|
priority: "p0",
|
|
4366
|
-
content: "Exe OS is an AI employee operating system. A founder runs 5-10 AI agents as a real org: COO
|
|
4523
|
+
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."
|
|
4367
4524
|
},
|
|
4368
4525
|
{
|
|
4369
4526
|
title: "Mode 1 \u2014 how exe-os runs inside Claude Code",
|
|
4370
4527
|
domain: "architecture",
|
|
4371
4528
|
priority: "p0",
|
|
4372
|
-
content: "Mode 1: exe-os runs AS hooks + MCP + skills inside Claude Code. The founder opens CC
|
|
4529
|
+
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."
|
|
4373
4530
|
},
|
|
4374
4531
|
{
|
|
4375
|
-
title: "Sessions explained \u2014
|
|
4532
|
+
title: "Sessions explained \u2014 coordinator session names and projects",
|
|
4376
4533
|
domain: "architecture",
|
|
4377
4534
|
priority: "p0",
|
|
4378
|
-
content: "Each
|
|
4535
|
+
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."
|
|
4379
4536
|
},
|
|
4380
4537
|
// --- Hierarchy and dispatch ---
|
|
4381
4538
|
{
|
|
4382
4539
|
title: "Chain of command \u2014 who talks to whom",
|
|
4383
4540
|
domain: "workflow",
|
|
4384
4541
|
priority: "p0",
|
|
4385
|
-
content: "Founder
|
|
4542
|
+
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."
|
|
4386
4543
|
},
|
|
4387
4544
|
{
|
|
4388
4545
|
title: "Single dispatch path \u2014 create_task only",
|
|
@@ -4392,30 +4549,30 @@ var init_platform_procedures = __esm({
|
|
|
4392
4549
|
},
|
|
4393
4550
|
// --- Session isolation ---
|
|
4394
4551
|
{
|
|
4395
|
-
title: "Session scoping \u2014 stay in your
|
|
4552
|
+
title: "Session scoping \u2014 stay in your coordinator boundary",
|
|
4396
4553
|
domain: "security",
|
|
4397
4554
|
priority: "p0",
|
|
4398
|
-
content: "Session scoping is mandatory. Managers dispatch to workers within their own
|
|
4555
|
+
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."
|
|
4399
4556
|
},
|
|
4400
4557
|
{
|
|
4401
4558
|
title: "Session isolation \u2014 never touch another session's work",
|
|
4402
4559
|
domain: "workflow",
|
|
4403
4560
|
priority: "p0",
|
|
4404
|
-
content:
|
|
4561
|
+
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."
|
|
4405
4562
|
},
|
|
4406
4563
|
// --- Engineering: session scoping in code ---
|
|
4407
4564
|
{
|
|
4408
4565
|
title: "Three-dimensional scoping \u2014 session, project, role \u2014 enforced in every query",
|
|
4409
4566
|
domain: "architecture",
|
|
4410
4567
|
priority: "p0",
|
|
4411
|
-
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
|
|
4568
|
+
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."
|
|
4412
4569
|
},
|
|
4413
4570
|
// --- Hard constraints ---
|
|
4414
4571
|
{
|
|
4415
4572
|
title: "What you CANNOT do in exe-os \u2014 hard constraints",
|
|
4416
4573
|
domain: "security",
|
|
4417
4574
|
priority: "p0",
|
|
4418
|
-
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
|
|
4575
|
+
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."
|
|
4419
4576
|
},
|
|
4420
4577
|
// --- Operations ---
|
|
4421
4578
|
{
|
|
@@ -4655,7 +4812,10 @@ async function writeMemory(record) {
|
|
|
4655
4812
|
source_path: record.source_path ?? null,
|
|
4656
4813
|
source_type: record.source_type ?? null,
|
|
4657
4814
|
tier: record.tier ?? classifyTier(record),
|
|
4658
|
-
supersedes_id: record.supersedes_id ?? null
|
|
4815
|
+
supersedes_id: record.supersedes_id ?? null,
|
|
4816
|
+
draft: record.draft ? 1 : 0,
|
|
4817
|
+
memory_type: record.memory_type ?? "raw",
|
|
4818
|
+
trajectory: record.trajectory ? JSON.stringify(record.trajectory) : null
|
|
4659
4819
|
};
|
|
4660
4820
|
_pendingRecords.push(dbRow);
|
|
4661
4821
|
orgBus.emit({
|
|
@@ -4710,6 +4870,9 @@ async function flushBatch() {
|
|
|
4710
4870
|
const sourceType = row.source_type ?? null;
|
|
4711
4871
|
const tier = row.tier ?? 3;
|
|
4712
4872
|
const supersedesId = row.supersedes_id ?? null;
|
|
4873
|
+
const draft = row.draft ? 1 : 0;
|
|
4874
|
+
const memoryType = row.memory_type ?? "raw";
|
|
4875
|
+
const trajectory = row.trajectory ?? null;
|
|
4713
4876
|
return {
|
|
4714
4877
|
sql: hasVector ? `INSERT OR IGNORE INTO memories
|
|
4715
4878
|
(id, agent_id, agent_role, session_id, timestamp,
|
|
@@ -4717,15 +4880,15 @@ async function flushBatch() {
|
|
|
4717
4880
|
has_error, raw_text, vector, version, task_id, importance, status,
|
|
4718
4881
|
confidence, last_accessed,
|
|
4719
4882
|
workspace_id, document_id, user_id, char_offset, page_number,
|
|
4720
|
-
source_path, source_type, tier, supersedes_id)
|
|
4721
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, vector32(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` : `INSERT OR IGNORE INTO memories
|
|
4883
|
+
source_path, source_type, tier, supersedes_id, draft, memory_type, trajectory)
|
|
4884
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, vector32(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` : `INSERT OR IGNORE INTO memories
|
|
4722
4885
|
(id, agent_id, agent_role, session_id, timestamp,
|
|
4723
4886
|
tool_name, project_name,
|
|
4724
4887
|
has_error, raw_text, vector, version, task_id, importance, status,
|
|
4725
4888
|
confidence, last_accessed,
|
|
4726
4889
|
workspace_id, document_id, user_id, char_offset, page_number,
|
|
4727
|
-
source_path, source_type, tier, supersedes_id)
|
|
4728
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
4890
|
+
source_path, source_type, tier, supersedes_id, draft, memory_type, trajectory)
|
|
4891
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
4729
4892
|
args: hasVector ? [
|
|
4730
4893
|
row.id,
|
|
4731
4894
|
row.agent_id,
|
|
@@ -4751,7 +4914,10 @@ async function flushBatch() {
|
|
|
4751
4914
|
sourcePath,
|
|
4752
4915
|
sourceType,
|
|
4753
4916
|
tier,
|
|
4754
|
-
supersedesId
|
|
4917
|
+
supersedesId,
|
|
4918
|
+
draft,
|
|
4919
|
+
memoryType,
|
|
4920
|
+
trajectory
|
|
4755
4921
|
] : [
|
|
4756
4922
|
row.id,
|
|
4757
4923
|
row.agent_id,
|
|
@@ -4776,7 +4942,10 @@ async function flushBatch() {
|
|
|
4776
4942
|
sourcePath,
|
|
4777
4943
|
sourceType,
|
|
4778
4944
|
tier,
|
|
4779
|
-
supersedesId
|
|
4945
|
+
supersedesId,
|
|
4946
|
+
draft,
|
|
4947
|
+
memoryType,
|
|
4948
|
+
trajectory
|
|
4780
4949
|
]
|
|
4781
4950
|
};
|
|
4782
4951
|
};
|
|
@@ -4845,6 +5014,8 @@ async function searchMemories(queryVector, agentId, options) {
|
|
|
4845
5014
|
const limit = options?.limit ?? 10;
|
|
4846
5015
|
const statusFilter = options?.includeArchived ? "" : `
|
|
4847
5016
|
AND COALESCE(status, 'active') = 'active'`;
|
|
5017
|
+
const draftFilter = options?.includeDrafts ? "" : `
|
|
5018
|
+
AND (draft = 0 OR draft IS NULL)`;
|
|
4848
5019
|
let sql = `SELECT id, agent_id, agent_role, session_id, timestamp,
|
|
4849
5020
|
tool_name, project_name,
|
|
4850
5021
|
has_error, raw_text, vector, importance, status,
|
|
@@ -4854,7 +5025,7 @@ async function searchMemories(queryVector, agentId, options) {
|
|
|
4854
5025
|
source_path, source_type
|
|
4855
5026
|
FROM memories
|
|
4856
5027
|
WHERE agent_id = ?
|
|
4857
|
-
AND vector IS NOT NULL${statusFilter}
|
|
5028
|
+
AND vector IS NOT NULL${statusFilter}${draftFilter}
|
|
4858
5029
|
AND COALESCE(confidence, 0.7) >= 0.3`;
|
|
4859
5030
|
const args = [agentId];
|
|
4860
5031
|
const scope = buildWikiScopeFilter(options, "");
|
|
@@ -4876,6 +5047,10 @@ async function searchMemories(queryVector, agentId, options) {
|
|
|
4876
5047
|
sql += ` AND timestamp >= ?`;
|
|
4877
5048
|
args.push(options.since);
|
|
4878
5049
|
}
|
|
5050
|
+
if (options?.memoryType) {
|
|
5051
|
+
sql += ` AND memory_type = ?`;
|
|
5052
|
+
args.push(options.memoryType);
|
|
5053
|
+
}
|
|
4879
5054
|
sql += ` ORDER BY vector_distance_cos(vector, vector32(?))`;
|
|
4880
5055
|
args.push(vectorToBlob(queryVector));
|
|
4881
5056
|
sql += ` LIMIT ?`;
|