@askexenow/exe-os 0.9.289 → 0.9.290
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/active-agent-L22OENGJ.js +26 -0
- package/dist/active-agent-SVG6F6HY.js +27 -0
- package/dist/agentic-ontology-3GHJHLDY.js +25 -0
- package/dist/backfill-metadata-HJNVBORD.js +599 -0
- package/dist/behaviors-ROOZS234.js +39 -0
- package/dist/bin/agentic-ontology-backfill.js +5 -5
- package/dist/bin/agentic-reflection-backfill.js +6 -6
- package/dist/bin/agentic-semantic-label.js +5 -5
- package/dist/bin/backfill-conversations.js +4 -4
- package/dist/bin/backfill-responses.js +4 -4
- package/dist/bin/backfill-vectors.js +98 -13
- package/dist/bin/bulk-sync-postgres.js +6 -6
- package/dist/bin/cc-doctor.js +4 -4
- package/dist/bin/cleanup-stale-review-tasks.js +9 -9
- package/dist/bin/cli.js +51 -15
- package/dist/bin/exe-agent-config.js +2 -2
- package/dist/bin/exe-agent.js +4 -4
- package/dist/bin/exe-assign.js +5 -5
- package/dist/bin/exe-boot.js +16 -16
- package/dist/bin/exe-call.js +4 -4
- package/dist/bin/exe-cloud.js +23 -5
- package/dist/bin/exe-dispatch.js +9 -9
- package/dist/bin/exe-doctor.js +1 -1
- package/dist/bin/exe-export-behaviors.js +7 -7
- package/dist/bin/exe-forget.js +6 -6
- package/dist/bin/exe-gateway.js +7 -7
- package/dist/bin/exe-healthcheck.js +4 -4
- package/dist/bin/exe-heartbeat.js +9 -9
- package/dist/bin/exe-kill.js +12 -12
- package/dist/bin/exe-launch-agent.js +16 -16
- package/dist/bin/exe-new-employee.js +6 -6
- package/dist/bin/exe-pending-messages.js +10 -10
- package/dist/bin/exe-pending-notifications.js +9 -9
- package/dist/bin/exe-pending-reviews.js +9 -9
- package/dist/bin/exe-rename.js +4 -4
- package/dist/bin/exe-review.js +11 -11
- package/dist/bin/exe-search.js +5 -5
- package/dist/bin/exe-session-cleanup.js +14 -14
- package/dist/bin/exe-settings.js +4 -4
- package/dist/bin/exe-start-codex.js +11 -11
- package/dist/bin/exe-start-opencode.js +8 -8
- package/dist/bin/exe-status.js +10 -10
- package/dist/bin/exe-team.js +3 -3
- package/dist/bin/git-sweep.js +10 -10
- package/dist/bin/graph-backfill.js +4 -4
- package/dist/bin/graph-export.js +5 -5
- package/dist/bin/import-history.js +7 -7
- package/dist/bin/install.js +6 -6
- package/dist/bin/intercom-check.js +4 -4
- package/dist/bin/mcp-sessions.js +2 -2
- package/dist/bin/orchestration-metrics.js +4 -4
- package/dist/bin/postgres-agentic-reflection-backfill.js +2 -2
- package/dist/bin/postgres-agentic-semantic-backfill.js +1 -1
- package/dist/bin/scan-tasks.js +9 -9
- package/dist/bin/setup.js +1 -1
- package/dist/bin/shard-migrate.js +4 -4
- package/dist/capability-cards-O6XB2AU4.js +88 -0
- package/dist/capacity-monitor-ZE7CFVWH.js +50 -0
- package/dist/catchup-brief-3NONSIMA.js +174 -0
- package/dist/chunk-232DHK5C.js +1119 -0
- package/dist/chunk-272SJ4RN.js +129 -0
- package/dist/chunk-4NMTGHUE.js +127 -0
- package/dist/chunk-5PLW3QL6.js +668 -0
- package/dist/chunk-66EIYAF2.js +157 -0
- package/dist/chunk-6IPJF5QD.js +630 -0
- package/dist/chunk-6NSJTOXE.js +122 -0
- package/dist/chunk-6TLURATK.js +4318 -0
- package/dist/chunk-73JAJQRY.js +85 -0
- package/dist/chunk-7FTKXL5A.js +286 -0
- package/dist/chunk-7IRQSO3F.js +735 -0
- package/dist/chunk-7MINWZ3J.js +214 -0
- package/dist/chunk-7T5PS5DG.js +14439 -0
- package/dist/chunk-A74WXY4S.js +227 -0
- package/dist/chunk-AVD5C3NG.js +197 -0
- package/dist/chunk-B36MRLEP.js +58 -0
- package/dist/chunk-B4TCZ3PS.js +373 -0
- package/dist/chunk-BPLEJ3EU.js +411 -0
- package/dist/chunk-BTDPLFGK.js +221 -0
- package/dist/chunk-BU45UYTK.js +185 -0
- package/dist/chunk-CCAA6XOZ.js +284 -0
- package/dist/chunk-DBQ6I6K2.js +3276 -0
- package/dist/chunk-DDWFHEPG.js +345 -0
- package/dist/chunk-DSOKTUTT.js +167 -0
- package/dist/chunk-ETCARC76.js +836 -0
- package/dist/chunk-EZHTLPOS.js +280 -0
- package/dist/chunk-F3DQ3HDH.js +333 -0
- package/dist/chunk-F6ZCUDCN.js +244 -0
- package/dist/chunk-FI5Q6F5S.js +382 -0
- package/dist/chunk-FNQZGNSG.js +1094 -0
- package/dist/chunk-FVKTXXKK.js +128 -0
- package/dist/chunk-HHR5NB6N.js +377 -0
- package/dist/chunk-HRZLGHT6.js +290 -0
- package/dist/chunk-HSSRWMVA.js +68 -0
- package/dist/chunk-I3NVB5MG.js +85 -0
- package/dist/chunk-I7Z6MK2B.js +240 -0
- package/dist/chunk-ID4SMRYX.js +2078 -0
- package/dist/chunk-JXGHDROV.js +546 -0
- package/dist/chunk-KQY4QIEN.js +731 -0
- package/dist/chunk-LRSU2ZU2.js +38 -0
- package/dist/chunk-MFCL4GAN.js +2113 -0
- package/dist/chunk-MFGMVKGM.js +150 -0
- package/dist/chunk-NHGBVLCD.js +210 -0
- package/dist/chunk-NOEBJMNN.js +33 -0
- package/dist/chunk-NQ2VNTGL.js +538 -0
- package/dist/chunk-O4PZPM6H.js +204 -0
- package/dist/chunk-O5OW3YGQ.js +262 -0
- package/dist/chunk-OJQTONDJ.js +171 -0
- package/dist/chunk-OKZGUHE5.js +76 -0
- package/dist/chunk-OOH5M36Q.js +448 -0
- package/dist/chunk-P5ARTZP2.js +128 -0
- package/dist/chunk-PKRSYS7F.js +402 -0
- package/dist/chunk-PQWO5D3F.js +348 -0
- package/dist/chunk-Q6MJIJ2O.js +1352 -0
- package/dist/chunk-QKDRYZ2N.js +231 -0
- package/dist/chunk-RAV356E6.js +30 -0
- package/dist/chunk-RK7EAA53.js +1157 -0
- package/dist/chunk-RSLVAYWS.js +192 -0
- package/dist/chunk-SL6WJP2Q.js +123 -0
- package/dist/chunk-T57DOVGE.js +97 -0
- package/dist/chunk-TMCKL43Q.js +181 -0
- package/dist/chunk-TQZABASE.js +97 -0
- package/dist/chunk-UBWBEY6I.js +81 -0
- package/dist/chunk-UP7DNYG7.js +456 -0
- package/dist/chunk-V5MGYIZS.js +70 -0
- package/dist/chunk-XCPVYQVK.js +336 -0
- package/dist/chunk-XWVBLZRP.js +50 -0
- package/dist/chunk-YBTN5F2U.js +1068 -0
- package/dist/chunk-Z772TGD2.js +54 -0
- package/dist/chunk-ZAMPIXLH.js +1350 -0
- package/dist/chunk-ZYEOHGU5.js +362 -0
- package/dist/co-activation-WJTFJOTK.js +73 -0
- package/dist/co-occurrence-KFP6ZS7G.js +94 -0
- package/dist/core-memory-DBZJ72TV.js +110 -0
- package/dist/crdt-sync-6DVGRMTV.js +33 -0
- package/dist/crm-webhook-55T4Z6XJ.js +10 -0
- package/dist/cto-delegation-gate-SPM6LAL2.js +279 -0
- package/dist/daemon-orchestration-XZLWWIV4.js +138 -0
- package/dist/db-backup-JHCI47JQ.js +37 -0
- package/dist/doc-graph-extractor-4X23NP4I.js +132 -0
- package/dist/dreaming-TFZDGA72.js +33 -0
- package/dist/exe-drift-TEM7ELNY.js +69 -0
- package/dist/exe-export-CRCA4T4S.js +75 -0
- package/dist/exe-import-UZMMWNHJ.js +78 -0
- package/dist/exe-key-NQQXEDUA.js +672 -0
- package/dist/exe-snapshot-P7PUAJTV.js +337 -0
- package/dist/fast-db-init-G63PRINQ.js +7 -0
- package/dist/gateway/index.js +8 -8
- package/dist/git-staleness-42TTCFDP.js +111 -0
- package/dist/git-task-sweep-4LW5RYYO.js +41 -0
- package/dist/global-procedures-BVFRWJAV.js +21 -0
- package/dist/graph-auto-extract-4ZA7UC6C.js +182 -0
- package/dist/hooks/bug-report-worker.js +11 -11
- package/dist/hooks/codex-stop-task-finalizer.js +11 -11
- package/dist/hooks/commit-complete.js +11 -11
- package/dist/hooks/error-recall.js +6 -6
- package/dist/hooks/exe-heartbeat-hook.js +3 -3
- package/dist/hooks/ingest.js +6 -6
- package/dist/hooks/instructions-loaded.js +4 -4
- package/dist/hooks/manifest.json +19 -19
- package/dist/hooks/notification.js +4 -4
- package/dist/hooks/post-compact.js +10 -10
- package/dist/hooks/post-tool-combined.js +5 -5
- package/dist/hooks/pre-compact.js +11 -11
- package/dist/hooks/pre-tool-use.js +14 -14
- package/dist/hooks/prompt-submit.js +21 -21
- package/dist/hooks/session-end.js +15 -15
- package/dist/hooks/session-start.js +12 -12
- package/dist/hooks/stop.js +14 -14
- package/dist/hooks/subagent-stop.js +10 -10
- package/dist/hooks/summary-worker.js +14 -14
- package/dist/index.js +17 -17
- package/dist/installer-CBGRTGIF.js +297 -0
- package/dist/installer-DGU4WZKJ.js +39 -0
- package/dist/installer-WTWEOSEK.js +343 -0
- package/dist/lib/cloud-sync.js +4 -4
- package/dist/lib/consolidation.js +7 -5
- package/dist/lib/database.js +2 -2
- package/dist/lib/db.js +2 -2
- package/dist/lib/employee-templates.js +4 -4
- package/dist/lib/employees.js +2 -2
- package/dist/lib/exe-daemon.js +64 -43
- package/dist/lib/hybrid-search.js +5 -5
- package/dist/lib/identity.js +2 -2
- package/dist/lib/messaging.js +9 -9
- package/dist/lib/reminders.js +3 -3
- package/dist/lib/schedules.js +5 -5
- package/dist/lib/session-registry.js +4 -4
- package/dist/lib/skill-learning.js +6 -6
- package/dist/lib/store.js +4 -4
- package/dist/lib/task-router.js +3 -3
- package/dist/lib/tasks.js +10 -10
- package/dist/lib/tmux-routing.js +8 -8
- package/dist/lib/token-spend.js +3 -3
- package/dist/license-gate-OSPA2OD7.js +16 -0
- package/dist/mcp/register-tools.js +55 -55
- package/dist/mcp/server.js +117 -73
- package/dist/mcp/tools/complete-reminder.js +4 -4
- package/dist/mcp/tools/create-reminder.js +4 -4
- package/dist/mcp/tools/create-task.js +12 -12
- package/dist/mcp/tools/deactivate-behavior.js +7 -7
- package/dist/mcp/tools/list-reminders.js +4 -4
- package/dist/mcp/tools/list-tasks.js +12 -12
- package/dist/mcp/tools/send-message.js +11 -11
- package/dist/mcp/tools/update-task.js +11 -11
- package/dist/mcp-http-config-OGFPLJYH.js +28 -0
- package/dist/memory-cards-GJ3VHKAM.js +179 -0
- package/dist/memory-graph-extractor-TCTCM7PZ.js +21 -0
- package/dist/memory-poisoning-defense-FVLGA35X.js +223 -0
- package/dist/memory-reflection-BYJFIFSV.js +243 -0
- package/dist/notifications-AQKZFSR3.js +46 -0
- package/dist/orchestration-events-RDSYLFXZ.js +26 -0
- package/dist/orchestrator-2JTJQLPG.js +34 -0
- package/dist/pipeline-router-HBSTKHG5.js +14 -0
- package/dist/plan-limits-GQENSNTG.js +27 -0
- package/dist/project-boot-W2LTP7WW.js +299 -0
- package/dist/projection-worker-ZMT5KNJJ.js +1084 -0
- package/dist/prospective-memory-LANRNOJX.js +231 -0
- package/dist/reranker-QGJO6EHO.js +19 -0
- package/dist/retrieval-health-JE66LJ3I.js +11 -0
- package/dist/review-polling-IXJ57M6Q.js +125 -0
- package/dist/runtime/index.js +11 -11
- package/dist/session-events-XKG66APL.js +37 -0
- package/dist/session-kill-telemetry-VTU7YBII.js +30 -0
- package/dist/session-scope-TQZONLZL.js +87 -0
- package/dist/setup-wizard-PXK6SC2D.js +12 -0
- package/dist/skill-refinement-Y6LLKYRL.js +158 -0
- package/dist/steward-gate-QV2APBFB.js +14 -0
- package/dist/task-enforcement-GLDD2W5D.js +505 -0
- package/dist/task-scope-HMPIP6XB.js +36 -0
- package/dist/tasks-crud-FH2SFCNQ.js +78 -0
- package/dist/tasks-notify-3ZW2GLCS.js +39 -0
- package/dist/tasks-review-XERV6KZD.js +48 -0
- package/dist/telemetry-upload-R77W7I7G.js +740 -0
- package/dist/token-budget-NA4WQAY6.js +85 -0
- package/dist/tool-telemetry-D4Q76LAS.js +17 -0
- package/dist/tui/App.js +16 -16
- package/dist/tui-data-NJSEIA2Q.js +259 -0
- package/dist/wiki-acl-RE5IR5VV.js +111 -0
- package/dist/worker-gate-VN2POPFL.js +21 -0
- package/dist/workflow-engine-D7ALMSDM.js +28 -0
- package/dist/worktree-6I45JV5N.js +27 -0
- package/dist/worktree-sweep-IMDR3XHT.js +20 -0
- package/package.json +1 -1
- package/release-notes.json +88 -88
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import {
|
|
2
|
+
recordSessionKill
|
|
3
|
+
} from "./chunk-SL6WJP2Q.js";
|
|
4
|
+
import {
|
|
5
|
+
sessionScopeFilter,
|
|
6
|
+
verifyPaneAtCapacity,
|
|
7
|
+
writeNotification
|
|
8
|
+
} from "./chunk-6TLURATK.js";
|
|
9
|
+
import {
|
|
10
|
+
listSessions
|
|
11
|
+
} from "./chunk-QKDRYZ2N.js";
|
|
12
|
+
import {
|
|
13
|
+
getTransport
|
|
14
|
+
} from "./chunk-MVW62NIZ.js";
|
|
15
|
+
import {
|
|
16
|
+
recordOrchestrationEventBestEffort
|
|
17
|
+
} from "./chunk-6IPJF5QD.js";
|
|
18
|
+
import {
|
|
19
|
+
getClient,
|
|
20
|
+
isCoordinatorName
|
|
21
|
+
} from "./chunk-DBQ6I6K2.js";
|
|
22
|
+
|
|
23
|
+
// src/lib/capacity-monitor.ts
|
|
24
|
+
var CAPACITY_PATTERNS = [
|
|
25
|
+
/conversation is too long/i,
|
|
26
|
+
/maximum context length/i,
|
|
27
|
+
/context window.*(?:limit|exceed|full)/i,
|
|
28
|
+
/reached.*(?:token|context).*limit/i
|
|
29
|
+
];
|
|
30
|
+
var CONTENT_LINE_PREFIX = /^[\s>#\-*[]/;
|
|
31
|
+
var CONTENT_LINE_MARKERS = [
|
|
32
|
+
"RESUME:",
|
|
33
|
+
"intercom",
|
|
34
|
+
"capacity-monitor",
|
|
35
|
+
"CAPACITY_PATTERNS",
|
|
36
|
+
"isAtCapacity",
|
|
37
|
+
"CONTENT_LINE_MARKERS",
|
|
38
|
+
"pollCapacityDead",
|
|
39
|
+
"confirmCapacityKill",
|
|
40
|
+
"session_kills",
|
|
41
|
+
"capacity-monitor.test"
|
|
42
|
+
];
|
|
43
|
+
var SOURCE_CODE_MARKERS = [
|
|
44
|
+
/["'`/].*(?:maximum context length|conversation is too long)/i,
|
|
45
|
+
/(?:maximum context length|conversation is too long).*["'`/]/i
|
|
46
|
+
];
|
|
47
|
+
var RELAUNCH_COOLDOWN_MS = 5 * 60 * 1e3;
|
|
48
|
+
var _lastRelaunch = /* @__PURE__ */ new Map();
|
|
49
|
+
var RESUME_TITLE_PREFIX = "RESUME:";
|
|
50
|
+
var RESUME_TITLE_LIKE_PATTERN = `${RESUME_TITLE_PREFIX} % hit context capacity%`;
|
|
51
|
+
var RESUME_ACTIVE_STATUSES = ["open", "in_progress"];
|
|
52
|
+
function resumeTaskTitle(agentId) {
|
|
53
|
+
return `${RESUME_TITLE_PREFIX} ${agentId} hit context capacity \u2014 continue open tasks`;
|
|
54
|
+
}
|
|
55
|
+
function buildResumeContext(agentId, openTasks) {
|
|
56
|
+
const taskList = openTasks.map(
|
|
57
|
+
(r, i) => `${i + 1}. [${String(r.priority).toUpperCase()}] ${String(r.title)} (${String(r.task_file)})`
|
|
58
|
+
).join("\n");
|
|
59
|
+
return [
|
|
60
|
+
"## Context",
|
|
61
|
+
"",
|
|
62
|
+
`${agentId} hit context capacity and was auto-relaunched by the capacity monitor.`,
|
|
63
|
+
"Call recall_my_memory first \u2014 search for 'CONTEXT CHECKPOINT'. Pick up where the previous session stopped.",
|
|
64
|
+
"",
|
|
65
|
+
`You have ${openTasks.length} open task(s). Work through them in priority order:`,
|
|
66
|
+
"",
|
|
67
|
+
taskList,
|
|
68
|
+
"",
|
|
69
|
+
"Read each task file and chain through them. Build and commit after each one."
|
|
70
|
+
].join("\n");
|
|
71
|
+
}
|
|
72
|
+
var CONFIRMATION_WINDOW_MS = 3 * 60 * 1e3;
|
|
73
|
+
var _pendingCapacityKill = /* @__PURE__ */ new Map();
|
|
74
|
+
function filterPaneContent(paneOutput) {
|
|
75
|
+
return paneOutput.split("\n").filter((line) => {
|
|
76
|
+
if (CONTENT_LINE_PREFIX.test(line)) return false;
|
|
77
|
+
for (const marker of CONTENT_LINE_MARKERS) {
|
|
78
|
+
if (line.includes(marker)) return false;
|
|
79
|
+
}
|
|
80
|
+
for (const re of SOURCE_CODE_MARKERS) {
|
|
81
|
+
if (re.test(line)) return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}).join("\n");
|
|
85
|
+
}
|
|
86
|
+
var CC_CONTEXT_BAR_RE = /([\u2588\u2591\u2592\u2593]{10})\s+(\d+)%/;
|
|
87
|
+
var CTX_FLOOR_PERCENT = 50;
|
|
88
|
+
function extractContextPercent(paneOutput) {
|
|
89
|
+
const match = paneOutput.match(CC_CONTEXT_BAR_RE);
|
|
90
|
+
if (!match) return null;
|
|
91
|
+
const parsed = Number.parseInt(match[2], 10);
|
|
92
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
93
|
+
}
|
|
94
|
+
function isAtCapacity(paneOutput) {
|
|
95
|
+
const filtered = filterPaneContent(paneOutput);
|
|
96
|
+
return CAPACITY_PATTERNS.some((p) => p.test(filtered));
|
|
97
|
+
}
|
|
98
|
+
function confirmCapacityKill(agentId, now = Date.now()) {
|
|
99
|
+
const pendingSince = _pendingCapacityKill.get(agentId);
|
|
100
|
+
if (pendingSince === void 0) {
|
|
101
|
+
_pendingCapacityKill.set(agentId, now);
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (now - pendingSince > CONFIRMATION_WINDOW_MS) {
|
|
105
|
+
_pendingCapacityKill.set(agentId, now);
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
_pendingCapacityKill.delete(agentId);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
function _resetPendingCapacityKills() {
|
|
112
|
+
_pendingCapacityKill.clear();
|
|
113
|
+
}
|
|
114
|
+
function _resetLastRelaunchCache() {
|
|
115
|
+
_lastRelaunch.clear();
|
|
116
|
+
}
|
|
117
|
+
async function lastResumeCreatedAtMs(agentId, sessionScope) {
|
|
118
|
+
const client = getClient();
|
|
119
|
+
const cmScope = sessionScopeFilter(sessionScope ?? null);
|
|
120
|
+
const result = await client.execute({
|
|
121
|
+
sql: `SELECT MAX(created_at) AS last_created_at
|
|
122
|
+
FROM tasks
|
|
123
|
+
WHERE assigned_to = ? AND title LIKE ?${cmScope.sql}`,
|
|
124
|
+
args: [agentId, `${RESUME_TITLE_PREFIX} %`, ...cmScope.args]
|
|
125
|
+
});
|
|
126
|
+
const raw = result.rows[0]?.last_created_at;
|
|
127
|
+
if (raw === null || raw === void 0) return null;
|
|
128
|
+
const parsed = Date.parse(String(raw));
|
|
129
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
130
|
+
}
|
|
131
|
+
async function isWithinRelaunchCooldown(agentId, now = Date.now(), sessionScope) {
|
|
132
|
+
const cacheKey = sessionScope ? `${agentId}::${sessionScope}` : agentId;
|
|
133
|
+
const cached = _lastRelaunch.get(cacheKey);
|
|
134
|
+
if (cached !== void 0) return now - cached < RELAUNCH_COOLDOWN_MS;
|
|
135
|
+
const persisted = await lastResumeCreatedAtMs(agentId, sessionScope);
|
|
136
|
+
if (persisted === null) return false;
|
|
137
|
+
if (now - persisted >= RELAUNCH_COOLDOWN_MS) return false;
|
|
138
|
+
_lastRelaunch.set(cacheKey, persisted);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
async function createOrRefreshResumeTask(agentId, projectDir, openTasks, sessionScope) {
|
|
142
|
+
const client = getClient();
|
|
143
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
144
|
+
const context = buildResumeContext(agentId, openTasks);
|
|
145
|
+
const rdScope = sessionScopeFilter(sessionScope ?? null);
|
|
146
|
+
const existing = await client.execute({
|
|
147
|
+
sql: `SELECT id FROM tasks
|
|
148
|
+
WHERE assigned_to = ?
|
|
149
|
+
AND title LIKE ?
|
|
150
|
+
AND status IN (${RESUME_ACTIVE_STATUSES.map(() => "?").join(", ")})${rdScope.sql}
|
|
151
|
+
ORDER BY created_at DESC
|
|
152
|
+
LIMIT 1`,
|
|
153
|
+
args: [agentId, RESUME_TITLE_LIKE_PATTERN, ...RESUME_ACTIVE_STATUSES, ...rdScope.args]
|
|
154
|
+
});
|
|
155
|
+
if (existing.rows.length > 0) {
|
|
156
|
+
const taskId = String(existing.rows[0].id);
|
|
157
|
+
await client.execute({
|
|
158
|
+
sql: `UPDATE tasks SET context = ?, updated_at = ? WHERE id = ?`,
|
|
159
|
+
args: [context, now, taskId]
|
|
160
|
+
});
|
|
161
|
+
recordOrchestrationEventBestEffort({
|
|
162
|
+
eventType: "session.resumed",
|
|
163
|
+
source: "capacity-monitor.createOrRefreshResumeTask",
|
|
164
|
+
agentId,
|
|
165
|
+
taskId,
|
|
166
|
+
payload: { created: false, action: "refreshed" }
|
|
167
|
+
});
|
|
168
|
+
return { created: false, taskId };
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
const staleResumes = await client.execute({
|
|
172
|
+
sql: `SELECT id FROM tasks
|
|
173
|
+
WHERE assigned_to = ?
|
|
174
|
+
AND title LIKE ?
|
|
175
|
+
AND status IN (${RESUME_ACTIVE_STATUSES.map(() => "?").join(", ")})`,
|
|
176
|
+
args: [agentId, RESUME_TITLE_LIKE_PATTERN, ...RESUME_ACTIVE_STATUSES]
|
|
177
|
+
});
|
|
178
|
+
for (const row of staleResumes.rows) {
|
|
179
|
+
await client.execute({
|
|
180
|
+
sql: `UPDATE tasks SET status = 'cancelled', result = ?, updated_at = ? WHERE id = ?`,
|
|
181
|
+
args: ["Auto-cancelled: superseded by new RESUME task.", now, String(row.id)]
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
} catch {
|
|
185
|
+
}
|
|
186
|
+
const { createTask } = await import("./lib/tasks.js");
|
|
187
|
+
const task = await createTask({
|
|
188
|
+
title: resumeTaskTitle(agentId),
|
|
189
|
+
assignedTo: agentId,
|
|
190
|
+
assignedBy: "system",
|
|
191
|
+
projectName: projectDir.split("/").pop() ?? "unknown",
|
|
192
|
+
priority: "p0",
|
|
193
|
+
context,
|
|
194
|
+
baseDir: projectDir
|
|
195
|
+
});
|
|
196
|
+
recordOrchestrationEventBestEffort({
|
|
197
|
+
eventType: "session.resumed",
|
|
198
|
+
source: "capacity-monitor.createOrRefreshResumeTask",
|
|
199
|
+
agentId,
|
|
200
|
+
taskId: task.id,
|
|
201
|
+
payload: { created: true, action: "created", openTaskCount: openTasks.length }
|
|
202
|
+
});
|
|
203
|
+
return { created: true, taskId: task.id };
|
|
204
|
+
}
|
|
205
|
+
async function pollCapacityDead() {
|
|
206
|
+
const transport = getTransport();
|
|
207
|
+
const relaunched = [];
|
|
208
|
+
const registered = listSessions();
|
|
209
|
+
if (registered.length === 0) return [];
|
|
210
|
+
let liveSessions;
|
|
211
|
+
try {
|
|
212
|
+
liveSessions = transport.listSessions();
|
|
213
|
+
} catch {
|
|
214
|
+
return [];
|
|
215
|
+
}
|
|
216
|
+
for (const entry of registered) {
|
|
217
|
+
const { windowName, agentId, projectDir } = entry;
|
|
218
|
+
if (!liveSessions.includes(windowName)) continue;
|
|
219
|
+
const cmDashIdx = windowName.indexOf("-");
|
|
220
|
+
const cmDerivedScope = cmDashIdx >= 0 ? windowName.slice(cmDashIdx + 1) : null;
|
|
221
|
+
if (await isWithinRelaunchCooldown(agentId, Date.now(), cmDerivedScope)) continue;
|
|
222
|
+
let pane;
|
|
223
|
+
try {
|
|
224
|
+
pane = transport.capturePane(windowName, 15);
|
|
225
|
+
} catch {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (!isAtCapacity(pane)) continue;
|
|
229
|
+
const ctxPct = extractContextPercent(pane);
|
|
230
|
+
if (ctxPct !== null && ctxPct < CTX_FLOOR_PERCENT) {
|
|
231
|
+
process.stderr.write(
|
|
232
|
+
`[capacity-monitor] ctx-floor: ${agentId} at ${ctxPct}% in ${windowName} \u2014 below ${CTX_FLOOR_PERCENT}%. Skipping capacity kill (likely self-referential content or false positive).
|
|
233
|
+
`
|
|
234
|
+
);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (!confirmCapacityKill(agentId)) {
|
|
238
|
+
process.stderr.write(
|
|
239
|
+
`[capacity-monitor] ${agentId} matched capacity pattern once in ${windowName}. Awaiting confirmation on next tick.
|
|
240
|
+
`
|
|
241
|
+
);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const verify = await verifyPaneAtCapacity(windowName);
|
|
245
|
+
if (!verify.atCapacity) {
|
|
246
|
+
process.stderr.write(
|
|
247
|
+
`[capacity-monitor] verifyPaneAtCapacity rejected kill for ${agentId} in ${windowName} (reason: ${verify.reason}). Skipping.
|
|
248
|
+
`
|
|
249
|
+
);
|
|
250
|
+
void recordSessionKill({
|
|
251
|
+
sessionName: windowName,
|
|
252
|
+
agentId,
|
|
253
|
+
reason: "capacity_false_positive_blocked"
|
|
254
|
+
});
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
process.stderr.write(
|
|
258
|
+
`[capacity-monitor] Detected ${agentId} at capacity in session ${windowName} (confirmed). Auto-relaunching.
|
|
259
|
+
`
|
|
260
|
+
);
|
|
261
|
+
if (isCoordinatorName(agentId)) {
|
|
262
|
+
try {
|
|
263
|
+
const { loadConfigSync } = await import("./lib/config.js");
|
|
264
|
+
const cfg = loadConfigSync();
|
|
265
|
+
if (cfg.sessionLifecycle.autoRelaunchCoordinator !== false) {
|
|
266
|
+
const fs = await import("fs");
|
|
267
|
+
const path = await import("path");
|
|
268
|
+
const os = await import("os");
|
|
269
|
+
const markerDir = path.join(os.homedir(), ".exe-os", "session-cache");
|
|
270
|
+
fs.mkdirSync(markerDir, { recursive: true });
|
|
271
|
+
const markerPath = path.join(markerDir, `relaunch-${windowName}.json`);
|
|
272
|
+
fs.writeFileSync(markerPath, JSON.stringify({
|
|
273
|
+
reason: "context_full",
|
|
274
|
+
agentId,
|
|
275
|
+
projectDir,
|
|
276
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
277
|
+
}));
|
|
278
|
+
process.stderr.write(
|
|
279
|
+
`[capacity-monitor] Coordinator relaunch marker written: ${markerPath}
|
|
280
|
+
`
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
transport.kill(windowName);
|
|
284
|
+
void recordSessionKill({ sessionName: windowName, agentId, reason: "capacity" });
|
|
285
|
+
const coordCacheKey = cmDerivedScope ? `${agentId}::${cmDerivedScope}` : agentId;
|
|
286
|
+
_lastRelaunch.set(coordCacheKey, Date.now());
|
|
287
|
+
relaunched.push(agentId);
|
|
288
|
+
} catch (err) {
|
|
289
|
+
process.stderr.write(
|
|
290
|
+
`[capacity-monitor] Coordinator relaunch marker write failed: ${err instanceof Error ? err.message : String(err)}
|
|
291
|
+
`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
transport.kill(windowName);
|
|
298
|
+
void recordSessionKill({
|
|
299
|
+
sessionName: windowName,
|
|
300
|
+
agentId,
|
|
301
|
+
reason: "capacity"
|
|
302
|
+
});
|
|
303
|
+
const client = getClient();
|
|
304
|
+
const dashIdx = windowName.indexOf("-");
|
|
305
|
+
const derivedScope = dashIdx >= 0 ? windowName.slice(dashIdx + 1) : null;
|
|
306
|
+
const rlScope = sessionScopeFilter(derivedScope);
|
|
307
|
+
const openTasks = await client.execute({
|
|
308
|
+
sql: `SELECT id, title, priority, task_file, status
|
|
309
|
+
FROM tasks
|
|
310
|
+
WHERE assigned_to = ? AND status IN ('open', 'in_progress')${rlScope.sql}
|
|
311
|
+
ORDER BY
|
|
312
|
+
CASE priority WHEN 'p0' THEN 0 WHEN 'p1' THEN 1 WHEN 'p2' THEN 2 ELSE 3 END,
|
|
313
|
+
created_at ASC
|
|
314
|
+
LIMIT 10`,
|
|
315
|
+
args: [agentId, ...rlScope.args]
|
|
316
|
+
});
|
|
317
|
+
if (openTasks.rows.length === 0) {
|
|
318
|
+
process.stderr.write(
|
|
319
|
+
`[capacity-monitor] ${agentId} has no open tasks \u2014 skipping relaunch.
|
|
320
|
+
`
|
|
321
|
+
);
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
const { created } = await createOrRefreshResumeTask(
|
|
325
|
+
agentId,
|
|
326
|
+
projectDir,
|
|
327
|
+
openTasks.rows,
|
|
328
|
+
derivedScope
|
|
329
|
+
);
|
|
330
|
+
if (created) {
|
|
331
|
+
await writeNotification({
|
|
332
|
+
agentId: "system",
|
|
333
|
+
agentRole: "daemon",
|
|
334
|
+
event: "capacity_relaunch",
|
|
335
|
+
project: projectDir.split("/").pop() ?? "unknown",
|
|
336
|
+
summary: `${agentId} hit context capacity. Auto-relaunched with ${openTasks.rows.length} open task(s).`
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
const cacheKey = derivedScope ? `${agentId}::${derivedScope}` : agentId;
|
|
340
|
+
_lastRelaunch.set(cacheKey, Date.now());
|
|
341
|
+
if (created) relaunched.push(agentId);
|
|
342
|
+
} catch (err) {
|
|
343
|
+
process.stderr.write(
|
|
344
|
+
`[capacity-monitor] Failed to relaunch ${agentId}: ${err instanceof Error ? err.message : String(err)}
|
|
345
|
+
`
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return relaunched;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export {
|
|
353
|
+
CTX_FLOOR_PERCENT,
|
|
354
|
+
extractContextPercent,
|
|
355
|
+
isAtCapacity,
|
|
356
|
+
confirmCapacityKill,
|
|
357
|
+
_resetPendingCapacityKills,
|
|
358
|
+
_resetLastRelaunchCache,
|
|
359
|
+
isWithinRelaunchCooldown,
|
|
360
|
+
createOrRefreshResumeTask,
|
|
361
|
+
pollCapacityDead
|
|
362
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getClient
|
|
3
|
+
} from "./chunk-DBQ6I6K2.js";
|
|
4
|
+
import "./chunk-2I23RPSI.js";
|
|
5
|
+
import "./chunk-XCPVYQVK.js";
|
|
6
|
+
import "./chunk-PNQDP3OA.js";
|
|
7
|
+
import "./chunk-FXU7JOXK.js";
|
|
8
|
+
import "./chunk-5P3HOBZX.js";
|
|
9
|
+
import "./chunk-LYH5HE24.js";
|
|
10
|
+
import "./chunk-MLKGABMK.js";
|
|
11
|
+
|
|
12
|
+
// src/lib/co-activation.ts
|
|
13
|
+
async function recordCoActivations(entityIds) {
|
|
14
|
+
if (entityIds.length < 2) return;
|
|
15
|
+
const unique = [...new Set(entityIds)].slice(0, 20);
|
|
16
|
+
const client = getClient();
|
|
17
|
+
const pairs = [];
|
|
18
|
+
for (let i = 0; i < unique.length; i++) {
|
|
19
|
+
for (let j = i + 1; j < unique.length; j++) {
|
|
20
|
+
const idI = unique[i];
|
|
21
|
+
const idJ = unique[j];
|
|
22
|
+
const pair = idI < idJ ? [idI, idJ] : [idJ, idI];
|
|
23
|
+
pairs.push(pair);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (const [a, b] of pairs) {
|
|
27
|
+
await client.execute({
|
|
28
|
+
sql: `INSERT INTO co_activations (entity_a_id, entity_b_id, count, last_activated_at)
|
|
29
|
+
VALUES (?, ?, 1, datetime('now'))
|
|
30
|
+
ON CONFLICT (entity_a_id, entity_b_id)
|
|
31
|
+
DO UPDATE SET count = count + 1, last_activated_at = datetime('now')`,
|
|
32
|
+
args: [a, b]
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function getHotPairs(limit = 20) {
|
|
37
|
+
const client = getClient();
|
|
38
|
+
const result = await client.execute({
|
|
39
|
+
sql: `SELECT entity_a_id, entity_b_id, count, last_activated_at
|
|
40
|
+
FROM co_activations
|
|
41
|
+
ORDER BY count DESC
|
|
42
|
+
LIMIT ?`,
|
|
43
|
+
args: [limit]
|
|
44
|
+
});
|
|
45
|
+
return result.rows.map((r) => ({
|
|
46
|
+
entity_a_id: String(r.entity_a_id),
|
|
47
|
+
entity_b_id: String(r.entity_b_id),
|
|
48
|
+
count: Number(r.count),
|
|
49
|
+
last_activated_at: String(r.last_activated_at)
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
async function getCoActivationNeighbors(entityId, limit = 20) {
|
|
53
|
+
const client = getClient();
|
|
54
|
+
const result = await client.execute({
|
|
55
|
+
sql: `SELECT entity_a_id, entity_b_id, count, last_activated_at
|
|
56
|
+
FROM co_activations
|
|
57
|
+
WHERE entity_a_id = ? OR entity_b_id = ?
|
|
58
|
+
ORDER BY count DESC
|
|
59
|
+
LIMIT ?`,
|
|
60
|
+
args: [entityId, entityId, limit]
|
|
61
|
+
});
|
|
62
|
+
return result.rows.map((r) => ({
|
|
63
|
+
entity_a_id: String(r.entity_a_id),
|
|
64
|
+
entity_b_id: String(r.entity_b_id),
|
|
65
|
+
count: Number(r.count),
|
|
66
|
+
last_activated_at: String(r.last_activated_at)
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
getCoActivationNeighbors,
|
|
71
|
+
getHotPairs,
|
|
72
|
+
recordCoActivations
|
|
73
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
entityId,
|
|
3
|
+
normalizeEntityName
|
|
4
|
+
} from "./chunk-KBNMVPDE.js";
|
|
5
|
+
import "./chunk-GUMRIUI5.js";
|
|
6
|
+
import "./chunk-I7AW4237.js";
|
|
7
|
+
import {
|
|
8
|
+
getClient
|
|
9
|
+
} from "./chunk-DBQ6I6K2.js";
|
|
10
|
+
import "./chunk-2I23RPSI.js";
|
|
11
|
+
import "./chunk-XCPVYQVK.js";
|
|
12
|
+
import "./chunk-PNQDP3OA.js";
|
|
13
|
+
import "./chunk-FXU7JOXK.js";
|
|
14
|
+
import "./chunk-5P3HOBZX.js";
|
|
15
|
+
import "./chunk-LYH5HE24.js";
|
|
16
|
+
import "./chunk-MLKGABMK.js";
|
|
17
|
+
|
|
18
|
+
// src/lib/co-occurrence.ts
|
|
19
|
+
var SPECIFICITY = {
|
|
20
|
+
file: 5,
|
|
21
|
+
function: 4,
|
|
22
|
+
error: 3,
|
|
23
|
+
tool: 2,
|
|
24
|
+
agent: 1,
|
|
25
|
+
project: 0
|
|
26
|
+
};
|
|
27
|
+
function getSpecificity(type) {
|
|
28
|
+
return SPECIFICITY[type] ?? 1;
|
|
29
|
+
}
|
|
30
|
+
function coOccurrenceId(entityId1, entityId2) {
|
|
31
|
+
const sorted = [entityId1, entityId2].sort();
|
|
32
|
+
return `cooccur:${sorted[0]}:${sorted[1]}`;
|
|
33
|
+
}
|
|
34
|
+
async function actualEntityId(name, type, fallbackId) {
|
|
35
|
+
try {
|
|
36
|
+
const result = await getClient().execute({
|
|
37
|
+
sql: "SELECT id FROM entities WHERE LOWER(name) = LOWER(?) AND type = ? LIMIT 1",
|
|
38
|
+
args: [name, type]
|
|
39
|
+
});
|
|
40
|
+
return result.rows[0]?.id ? String(result.rows[0].id) : fallbackId;
|
|
41
|
+
} catch {
|
|
42
|
+
return fallbackId;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function createCoOccurrenceEdges(entities, _memoryId) {
|
|
46
|
+
if (entities.length < 2) return 0;
|
|
47
|
+
const client = getClient();
|
|
48
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
49
|
+
const seen = /* @__PURE__ */ new Set();
|
|
50
|
+
const deduped = entities.filter((e) => {
|
|
51
|
+
const key = `${e.type.toLowerCase()}:${normalizeEntityName(e.name)}`;
|
|
52
|
+
if (seen.has(key)) return false;
|
|
53
|
+
seen.add(key);
|
|
54
|
+
return true;
|
|
55
|
+
});
|
|
56
|
+
const sorted = deduped.sort((a, b) => getSpecificity(b.type) - getSpecificity(a.type));
|
|
57
|
+
const MAX_PAIRS = 10;
|
|
58
|
+
const pairs = [];
|
|
59
|
+
for (let i = 0; i < sorted.length && pairs.length < MAX_PAIRS; i++) {
|
|
60
|
+
for (let j = i + 1; j < sorted.length && pairs.length < MAX_PAIRS; j++) {
|
|
61
|
+
pairs.push([sorted[i], sorted[j]]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
let created = 0;
|
|
65
|
+
for (const [a, b] of pairs) {
|
|
66
|
+
const aName = normalizeEntityName(a.name);
|
|
67
|
+
const bName = normalizeEntityName(b.name);
|
|
68
|
+
const aType = a.type.toLowerCase();
|
|
69
|
+
const bType = b.type.toLowerCase();
|
|
70
|
+
const aId = await actualEntityId(aName, aType, entityId(aName, aType));
|
|
71
|
+
const bId = await actualEntityId(bName, bType, entityId(bName, bType));
|
|
72
|
+
if (aId === bId) continue;
|
|
73
|
+
const relId = coOccurrenceId(aId, bId);
|
|
74
|
+
const sortedIds = [aId, bId].sort();
|
|
75
|
+
const sourceId = sortedIds[0];
|
|
76
|
+
const targetId = sortedIds[1];
|
|
77
|
+
try {
|
|
78
|
+
await client.execute({
|
|
79
|
+
sql: `INSERT INTO relationships (id, source_entity_id, target_entity_id, type, weight, timestamp, properties)
|
|
80
|
+
VALUES (?, ?, ?, 'co_occurs_with', 1.0, ?, '{}')
|
|
81
|
+
ON CONFLICT(source_entity_id, target_entity_id, type) DO UPDATE SET
|
|
82
|
+
weight = MIN(weight + 0.1, 10.0),
|
|
83
|
+
timestamp = ?`,
|
|
84
|
+
args: [relId, sourceId, targetId, now, now]
|
|
85
|
+
});
|
|
86
|
+
created++;
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return created;
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
createCoOccurrenceEdges
|
|
94
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import "./chunk-MLKGABMK.js";
|
|
2
|
+
|
|
3
|
+
// src/lib/core-memory.ts
|
|
4
|
+
var MAX_CORE_ENTRIES = 10;
|
|
5
|
+
var MAX_ENTRY_LENGTH = 500;
|
|
6
|
+
var MAX_TOTAL_CHARS = 5e3;
|
|
7
|
+
async function getCoreMemory(agentId) {
|
|
8
|
+
try {
|
|
9
|
+
const { getClient } = await import("./lib/database.js");
|
|
10
|
+
const client = getClient();
|
|
11
|
+
const result = await client.execute({
|
|
12
|
+
sql: `SELECT key, value, updated_at FROM core_memory
|
|
13
|
+
WHERE agent_id = ? ORDER BY key ASC`,
|
|
14
|
+
args: [agentId]
|
|
15
|
+
});
|
|
16
|
+
return result.rows.map((r) => ({
|
|
17
|
+
key: String(r.key),
|
|
18
|
+
value: String(r.value),
|
|
19
|
+
updatedAt: String(r.updated_at)
|
|
20
|
+
}));
|
|
21
|
+
} catch {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function setCoreMemory(agentId, key, value) {
|
|
26
|
+
if (value.length > MAX_ENTRY_LENGTH) {
|
|
27
|
+
throw new Error(`Core memory value too long (${value.length}/${MAX_ENTRY_LENGTH} chars). Core memory is for key facts, not documents.`);
|
|
28
|
+
}
|
|
29
|
+
const { getClient } = await import("./lib/database.js");
|
|
30
|
+
const client = getClient();
|
|
31
|
+
const countResult = await client.execute({
|
|
32
|
+
sql: `SELECT COUNT(*) as cnt FROM core_memory WHERE agent_id = ?`,
|
|
33
|
+
args: [agentId]
|
|
34
|
+
});
|
|
35
|
+
const count = Number(countResult.rows[0]?.cnt ?? 0);
|
|
36
|
+
const existing = await client.execute({
|
|
37
|
+
sql: `SELECT key FROM core_memory WHERE agent_id = ? AND key = ?`,
|
|
38
|
+
args: [agentId, key]
|
|
39
|
+
});
|
|
40
|
+
if (existing.rows.length === 0 && count >= MAX_CORE_ENTRIES) {
|
|
41
|
+
const oldest = await client.execute({
|
|
42
|
+
sql: `SELECT key, value, updated_at FROM core_memory
|
|
43
|
+
WHERE agent_id = ? ORDER BY updated_at ASC LIMIT 1`,
|
|
44
|
+
args: [agentId]
|
|
45
|
+
});
|
|
46
|
+
if (oldest.rows.length > 0) {
|
|
47
|
+
const oldKey = String(oldest.rows[0].key);
|
|
48
|
+
const oldValue = String(oldest.rows[0].value);
|
|
49
|
+
try {
|
|
50
|
+
const { randomUUID } = await import("crypto");
|
|
51
|
+
const { writeMemory } = await import("./lib/store.js");
|
|
52
|
+
await writeMemory({
|
|
53
|
+
id: randomUUID(),
|
|
54
|
+
agent_id: agentId,
|
|
55
|
+
agent_role: "core-demotion",
|
|
56
|
+
session_id: "core-memory-demotion",
|
|
57
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
58
|
+
tool_name: "core_memory_demotion",
|
|
59
|
+
project_name: "exe-os",
|
|
60
|
+
has_error: false,
|
|
61
|
+
raw_text: `[Demoted from core memory] ${oldKey}: ${oldValue}`,
|
|
62
|
+
vector: null
|
|
63
|
+
});
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
await client.execute({
|
|
67
|
+
sql: `DELETE FROM core_memory WHERE agent_id = ? AND key = ?`,
|
|
68
|
+
args: [agentId, oldKey]
|
|
69
|
+
});
|
|
70
|
+
process.stderr.write(`[core-memory] Auto-demoted "${oldKey}" to regular memory (core full at ${MAX_CORE_ENTRIES})
|
|
71
|
+
`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const sizeResult = await client.execute({
|
|
75
|
+
sql: `SELECT COALESCE(SUM(LENGTH(value)), 0) as total FROM core_memory WHERE agent_id = ? AND key != ?`,
|
|
76
|
+
args: [agentId, key]
|
|
77
|
+
});
|
|
78
|
+
const currentSize = Number(sizeResult.rows[0]?.total ?? 0);
|
|
79
|
+
if (currentSize + value.length > MAX_TOTAL_CHARS) {
|
|
80
|
+
throw new Error(`Core memory would exceed ${MAX_TOTAL_CHARS} char limit. Delete entries or shorten values.`);
|
|
81
|
+
}
|
|
82
|
+
await client.execute({
|
|
83
|
+
sql: `INSERT OR REPLACE INTO core_memory (agent_id, key, value, updated_at)
|
|
84
|
+
VALUES (?, ?, ?, ?)`,
|
|
85
|
+
args: [agentId, key, value, (/* @__PURE__ */ new Date()).toISOString()]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function deleteCoreMemory(agentId, key) {
|
|
89
|
+
const { getClient } = await import("./lib/database.js");
|
|
90
|
+
const client = getClient();
|
|
91
|
+
const result = await client.execute({
|
|
92
|
+
sql: `DELETE FROM core_memory WHERE agent_id = ? AND key = ?`,
|
|
93
|
+
args: [agentId, key]
|
|
94
|
+
});
|
|
95
|
+
return (result.rowsAffected ?? 0) > 0;
|
|
96
|
+
}
|
|
97
|
+
function formatCoreMemoryBlock(entries) {
|
|
98
|
+
if (entries.length === 0) return null;
|
|
99
|
+
const lines = ["## Core Memory (always in context)", ""];
|
|
100
|
+
for (const e of entries) {
|
|
101
|
+
lines.push(`- **${e.key}:** ${e.value}`);
|
|
102
|
+
}
|
|
103
|
+
return lines.join("\n");
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
deleteCoreMemory,
|
|
107
|
+
formatCoreMemoryBlock,
|
|
108
|
+
getCoreMemory,
|
|
109
|
+
setCoreMemory
|
|
110
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
_setStatePath,
|
|
3
|
+
applyRemoteUpdate,
|
|
4
|
+
destroyCrdtDoc,
|
|
5
|
+
getDiffUpdate,
|
|
6
|
+
getFullState,
|
|
7
|
+
getStateVector,
|
|
8
|
+
importExistingBehaviors,
|
|
9
|
+
importExistingMemories,
|
|
10
|
+
initCrdtDoc,
|
|
11
|
+
isCrdtSyncEnabled,
|
|
12
|
+
onUpdate,
|
|
13
|
+
readAllBehaviors,
|
|
14
|
+
readAllMemories,
|
|
15
|
+
rebuildFromDb
|
|
16
|
+
} from "./chunk-BTDPLFGK.js";
|
|
17
|
+
import "./chunk-MLKGABMK.js";
|
|
18
|
+
export {
|
|
19
|
+
_setStatePath,
|
|
20
|
+
applyRemoteUpdate,
|
|
21
|
+
destroyCrdtDoc,
|
|
22
|
+
getDiffUpdate,
|
|
23
|
+
getFullState,
|
|
24
|
+
getStateVector,
|
|
25
|
+
importExistingBehaviors,
|
|
26
|
+
importExistingMemories,
|
|
27
|
+
initCrdtDoc,
|
|
28
|
+
isCrdtSyncEnabled,
|
|
29
|
+
onUpdate,
|
|
30
|
+
readAllBehaviors,
|
|
31
|
+
readAllMemories,
|
|
32
|
+
rebuildFromDb
|
|
33
|
+
};
|