@askexenow/exe-os 0.9.61 → 0.9.63
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/deploy/stack-manifests/v0.9.json +62 -13
- package/dist/bin/backfill-conversations.js +210 -2
- package/dist/bin/backfill-responses.js +210 -2
- package/dist/bin/backfill-vectors.js +47 -2
- package/dist/bin/cleanup-stale-review-tasks.js +210 -2
- package/dist/bin/cli.js +488 -25
- package/dist/bin/exe-agent-config.js +2 -2
- package/dist/bin/exe-agent.js +2 -2
- package/dist/bin/exe-assign.js +210 -2
- package/dist/bin/exe-boot.js +47 -2
- package/dist/bin/exe-call.js +2 -2
- package/dist/bin/exe-cloud.js +2 -2
- package/dist/bin/exe-dispatch.js +210 -2
- package/dist/bin/exe-doctor.js +2691 -1212
- package/dist/bin/exe-export-behaviors.js +210 -2
- package/dist/bin/exe-forget.js +264 -2
- package/dist/bin/exe-gateway.js +210 -2
- package/dist/bin/exe-heartbeat.js +212 -4
- package/dist/bin/exe-kill.js +210 -2
- package/dist/bin/exe-launch-agent.js +210 -2
- package/dist/bin/exe-link.js +47 -2
- package/dist/bin/exe-new-employee.js +113 -3
- package/dist/bin/exe-pending-messages.js +210 -2
- package/dist/bin/exe-pending-notifications.js +210 -2
- package/dist/bin/exe-pending-reviews.js +210 -2
- package/dist/bin/exe-rename.js +210 -2
- package/dist/bin/exe-review.js +210 -2
- package/dist/bin/exe-search.js +234 -3
- package/dist/bin/exe-session-cleanup.js +210 -2
- package/dist/bin/exe-settings.js +2 -2
- package/dist/bin/exe-start-codex.js +322 -4
- package/dist/bin/exe-start-opencode.js +336 -4
- package/dist/bin/exe-status.js +210 -2
- package/dist/bin/exe-team.js +210 -2
- package/dist/bin/git-sweep.js +210 -2
- package/dist/bin/graph-backfill.js +210 -2
- package/dist/bin/graph-export.js +210 -2
- package/dist/bin/install.js +113 -3
- package/dist/bin/intercom-check.js +210 -2
- package/dist/bin/scan-tasks.js +210 -2
- package/dist/bin/setup.js +47 -2
- package/dist/bin/shard-migrate.js +210 -2
- package/dist/bin/stack-update.js +158 -13
- package/dist/bin/update.js +2 -2
- package/dist/gateway/index.js +210 -2
- package/dist/hooks/bug-report-worker.js +321 -44
- package/dist/hooks/codex-stop-task-finalizer.js +210 -2
- package/dist/hooks/commit-complete.js +210 -2
- package/dist/hooks/error-recall.js +234 -3
- package/dist/hooks/exe-heartbeat-hook.js +2 -2
- package/dist/hooks/ingest-worker.js +2 -2
- package/dist/hooks/ingest.js +210 -2
- package/dist/hooks/instructions-loaded.js +210 -2
- package/dist/hooks/notification.js +210 -2
- package/dist/hooks/post-compact.js +210 -2
- package/dist/hooks/post-tool-combined.js +234 -3
- package/dist/hooks/pre-compact.js +446 -111
- package/dist/hooks/pre-tool-use.js +210 -2
- package/dist/hooks/prompt-submit.js +234 -3
- package/dist/hooks/session-end.js +347 -124
- package/dist/hooks/session-start.js +236 -5
- package/dist/hooks/stop.js +210 -2
- package/dist/hooks/subagent-stop.js +210 -2
- package/dist/hooks/summary-worker.js +171 -74
- package/dist/index.js +210 -2
- package/dist/lib/agent-config.js +2 -2
- package/dist/lib/cloud-sync.js +47 -2
- package/dist/lib/config.js +2 -2
- package/dist/lib/consolidation.js +2 -2
- package/dist/lib/database.js +47 -2
- package/dist/lib/db-daemon-client.js +2 -2
- package/dist/lib/db.js +47 -2
- package/dist/lib/device-registry.js +47 -2
- package/dist/lib/embedder.js +2 -2
- package/dist/lib/employee-templates.js +2 -2
- package/dist/lib/employees.js +2 -2
- package/dist/lib/exe-daemon-client.js +2 -2
- package/dist/lib/exe-daemon.js +592 -10
- package/dist/lib/hybrid-search.js +234 -3
- package/dist/lib/identity.js +2 -2
- package/dist/lib/license.js +2 -2
- package/dist/lib/messaging.js +2 -2
- package/dist/lib/reminders.js +2 -2
- package/dist/lib/schedules.js +47 -2
- package/dist/lib/skill-learning.js +2 -2
- package/dist/lib/store.js +210 -2
- package/dist/lib/task-router.js +2 -2
- package/dist/lib/tasks.js +2 -2
- package/dist/lib/tmux-routing.js +2 -2
- package/dist/lib/token-spend.js +2 -2
- package/dist/mcp/server.js +608 -10
- package/dist/mcp/tools/complete-reminder.js +2 -2
- package/dist/mcp/tools/create-reminder.js +2 -2
- package/dist/mcp/tools/create-task.js +2 -2
- package/dist/mcp/tools/deactivate-behavior.js +2 -2
- package/dist/mcp/tools/list-reminders.js +2 -2
- package/dist/mcp/tools/list-tasks.js +2 -2
- package/dist/mcp/tools/send-message.js +2 -2
- package/dist/mcp/tools/update-task.js +2 -2
- package/dist/runtime/index.js +210 -2
- package/dist/tui/App.js +210 -2
- package/package.json +3 -2
- package/stack.release.json +23 -7
|
@@ -310,8 +310,8 @@ var init_config = __esm({
|
|
|
310
310
|
rerankerAutoTrigger: {
|
|
311
311
|
enabled: true,
|
|
312
312
|
broadQueryMinCardinality: 5e4,
|
|
313
|
-
fetchTopK:
|
|
314
|
-
returnTopK:
|
|
313
|
+
fetchTopK: 200,
|
|
314
|
+
returnTopK: 20
|
|
315
315
|
}
|
|
316
316
|
},
|
|
317
317
|
graphRagEnabled: true,
|
|
@@ -2709,6 +2709,51 @@ async function ensureSchema() {
|
|
|
2709
2709
|
VALUES (new.rowid, new.content_text, new.sender_name, new.agent_response);
|
|
2710
2710
|
END;
|
|
2711
2711
|
`);
|
|
2712
|
+
await client.executeMultiple(`
|
|
2713
|
+
CREATE TABLE IF NOT EXISTS memory_cards (
|
|
2714
|
+
id TEXT PRIMARY KEY,
|
|
2715
|
+
memory_id TEXT NOT NULL,
|
|
2716
|
+
agent_id TEXT NOT NULL,
|
|
2717
|
+
session_id TEXT NOT NULL,
|
|
2718
|
+
project_name TEXT,
|
|
2719
|
+
timestamp TEXT NOT NULL,
|
|
2720
|
+
card_type TEXT NOT NULL,
|
|
2721
|
+
subject TEXT,
|
|
2722
|
+
predicate TEXT,
|
|
2723
|
+
object TEXT,
|
|
2724
|
+
content TEXT NOT NULL,
|
|
2725
|
+
source_ref TEXT,
|
|
2726
|
+
confidence REAL DEFAULT 0.6,
|
|
2727
|
+
active INTEGER DEFAULT 1,
|
|
2728
|
+
created_at TEXT NOT NULL
|
|
2729
|
+
);
|
|
2730
|
+
|
|
2731
|
+
CREATE INDEX IF NOT EXISTS idx_memory_cards_agent
|
|
2732
|
+
ON memory_cards(agent_id, active, timestamp);
|
|
2733
|
+
|
|
2734
|
+
CREATE INDEX IF NOT EXISTS idx_memory_cards_memory
|
|
2735
|
+
ON memory_cards(memory_id);
|
|
2736
|
+
|
|
2737
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memory_cards_fts
|
|
2738
|
+
USING fts5(content, subject, predicate, object, content='memory_cards', content_rowid='rowid');
|
|
2739
|
+
|
|
2740
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ai AFTER INSERT ON memory_cards BEGIN
|
|
2741
|
+
INSERT INTO memory_cards_fts(rowid, content, subject, predicate, object)
|
|
2742
|
+
VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
|
|
2743
|
+
END;
|
|
2744
|
+
|
|
2745
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ad AFTER DELETE ON memory_cards BEGIN
|
|
2746
|
+
INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
|
|
2747
|
+
VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
|
|
2748
|
+
END;
|
|
2749
|
+
|
|
2750
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_au AFTER UPDATE ON memory_cards BEGIN
|
|
2751
|
+
INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
|
|
2752
|
+
VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
|
|
2753
|
+
INSERT INTO memory_cards_fts(rowid, content, subject, predicate, object)
|
|
2754
|
+
VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
|
|
2755
|
+
END;
|
|
2756
|
+
`);
|
|
2712
2757
|
try {
|
|
2713
2758
|
await client.execute({
|
|
2714
2759
|
sql: `ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3`,
|
|
@@ -3998,6 +4043,164 @@ ${p.content}`).join("\n\n");
|
|
|
3998
4043
|
}
|
|
3999
4044
|
});
|
|
4000
4045
|
|
|
4046
|
+
// src/lib/memory-cards.ts
|
|
4047
|
+
var memory_cards_exports = {};
|
|
4048
|
+
__export(memory_cards_exports, {
|
|
4049
|
+
extractMemoryCards: () => extractMemoryCards,
|
|
4050
|
+
insertMemoryCardsForBatch: () => insertMemoryCardsForBatch,
|
|
4051
|
+
searchMemoryCards: () => searchMemoryCards
|
|
4052
|
+
});
|
|
4053
|
+
import { createHash as createHash2 } from "crypto";
|
|
4054
|
+
function stableId(memoryId, type, content) {
|
|
4055
|
+
return createHash2("sha256").update(`${memoryId}:${type}:${content}`).digest("hex").slice(0, 32);
|
|
4056
|
+
}
|
|
4057
|
+
function cleanText(text) {
|
|
4058
|
+
return text.replace(/```[\s\S]*?```/g, " ").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
|
4059
|
+
}
|
|
4060
|
+
function splitSentences(text) {
|
|
4061
|
+
return cleanText(text).split(/(?<=[.!?])\s+|\n+/).map((s) => s.trim()).filter((s) => s.length >= 24 && s.length <= MAX_SENTENCE_CHARS);
|
|
4062
|
+
}
|
|
4063
|
+
function inferCardType(sentence, toolName) {
|
|
4064
|
+
const lower = sentence.toLowerCase();
|
|
4065
|
+
if (toolName === "store_decision" || /\b(decided|decision|adr|approved|rejected)\b/.test(lower)) return "decision";
|
|
4066
|
+
if (/\b(prefers|preference|likes|dislikes|wants|doesn't want|does not want)\b/.test(lower)) return "preference";
|
|
4067
|
+
if (/\b(changed|updated|replaced|now|no longer|instead|supersedes)\b/.test(lower)) return "belief_update";
|
|
4068
|
+
if (toolName && ["Read", "Write", "Edit", "Bash"].includes(toolName)) return "code";
|
|
4069
|
+
if (/\b(meeting|deadline|shipped|launched|completed|failed|blocked|assigned|created)\b/.test(lower)) return "event";
|
|
4070
|
+
return "fact";
|
|
4071
|
+
}
|
|
4072
|
+
function extractSubject(sentence, agentId) {
|
|
4073
|
+
const explicit = sentence.match(/\b([A-Z][a-zA-Z0-9_-]{2,}(?:\s+[A-Z][a-zA-Z0-9_-]{2,})?)\b/);
|
|
4074
|
+
return explicit?.[1] ?? agentId;
|
|
4075
|
+
}
|
|
4076
|
+
function predicateFor(type) {
|
|
4077
|
+
switch (type) {
|
|
4078
|
+
case "preference":
|
|
4079
|
+
return "prefers";
|
|
4080
|
+
case "belief_update":
|
|
4081
|
+
return "updated";
|
|
4082
|
+
case "decision":
|
|
4083
|
+
return "decided";
|
|
4084
|
+
case "event":
|
|
4085
|
+
return "happened";
|
|
4086
|
+
case "code":
|
|
4087
|
+
return "implemented";
|
|
4088
|
+
default:
|
|
4089
|
+
return "states";
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
4092
|
+
function extractMemoryCards(row) {
|
|
4093
|
+
const sentences = splitSentences(row.raw_text);
|
|
4094
|
+
const cards = [];
|
|
4095
|
+
for (const sentence of sentences) {
|
|
4096
|
+
const type = inferCardType(sentence, row.tool_name);
|
|
4097
|
+
const subject = extractSubject(sentence, row.agent_id);
|
|
4098
|
+
const content = sentence.length > MAX_SENTENCE_CHARS ? `${sentence.slice(0, MAX_SENTENCE_CHARS - 1)}\u2026` : sentence;
|
|
4099
|
+
cards.push({
|
|
4100
|
+
id: stableId(row.id, type, content),
|
|
4101
|
+
memory_id: row.id,
|
|
4102
|
+
agent_id: row.agent_id,
|
|
4103
|
+
session_id: row.session_id,
|
|
4104
|
+
project_name: row.project_name ?? null,
|
|
4105
|
+
timestamp: row.timestamp,
|
|
4106
|
+
card_type: type,
|
|
4107
|
+
subject,
|
|
4108
|
+
predicate: predicateFor(type),
|
|
4109
|
+
object: content,
|
|
4110
|
+
content,
|
|
4111
|
+
source_ref: row.id,
|
|
4112
|
+
confidence: type === "fact" ? 0.55 : 0.65
|
|
4113
|
+
});
|
|
4114
|
+
if (cards.length >= MAX_CARDS_PER_MEMORY) break;
|
|
4115
|
+
}
|
|
4116
|
+
return cards;
|
|
4117
|
+
}
|
|
4118
|
+
async function insertMemoryCardsForBatch(rows) {
|
|
4119
|
+
const cards = rows.flatMap(extractMemoryCards);
|
|
4120
|
+
if (cards.length === 0) return 0;
|
|
4121
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4122
|
+
const client = getClient();
|
|
4123
|
+
const stmts = cards.map((card) => ({
|
|
4124
|
+
sql: `INSERT OR IGNORE INTO memory_cards
|
|
4125
|
+
(id, memory_id, agent_id, session_id, project_name, timestamp, card_type,
|
|
4126
|
+
subject, predicate, object, content, source_ref, confidence, active, created_at)
|
|
4127
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?)`,
|
|
4128
|
+
args: [
|
|
4129
|
+
card.id,
|
|
4130
|
+
card.memory_id,
|
|
4131
|
+
card.agent_id,
|
|
4132
|
+
card.session_id,
|
|
4133
|
+
card.project_name,
|
|
4134
|
+
card.timestamp,
|
|
4135
|
+
card.card_type,
|
|
4136
|
+
card.subject,
|
|
4137
|
+
card.predicate,
|
|
4138
|
+
card.object,
|
|
4139
|
+
card.content,
|
|
4140
|
+
card.source_ref,
|
|
4141
|
+
card.confidence,
|
|
4142
|
+
now
|
|
4143
|
+
]
|
|
4144
|
+
}));
|
|
4145
|
+
await client.batch(stmts, "write");
|
|
4146
|
+
return cards.length;
|
|
4147
|
+
}
|
|
4148
|
+
function buildMatchExpr(queryText) {
|
|
4149
|
+
const terms = queryText.toLowerCase().split(/\s+/).filter((t) => t.length >= 3).map((t) => t.replace(/[^a-z0-9_]/g, "")).filter((t) => t.length >= 3).slice(0, 12);
|
|
4150
|
+
if (terms.length === 0) return null;
|
|
4151
|
+
return terms.map((t) => `${t}*`).join(terms.length >= 3 ? " AND " : " OR ");
|
|
4152
|
+
}
|
|
4153
|
+
async function searchMemoryCards(queryText, agentId, options) {
|
|
4154
|
+
const limit = options?.limit ?? 10;
|
|
4155
|
+
const matchExpr = buildMatchExpr(queryText);
|
|
4156
|
+
if (!matchExpr) return [];
|
|
4157
|
+
let sql = `SELECT c.id, c.memory_id, c.agent_id, c.session_id, c.project_name,
|
|
4158
|
+
c.timestamp, c.card_type, c.content, c.source_ref, c.confidence
|
|
4159
|
+
FROM memory_cards c
|
|
4160
|
+
JOIN memory_cards_fts fts ON c.rowid = fts.rowid
|
|
4161
|
+
WHERE memory_cards_fts MATCH ?
|
|
4162
|
+
AND c.agent_id = ?
|
|
4163
|
+
AND COALESCE(c.active, 1) = 1`;
|
|
4164
|
+
const args = [matchExpr, agentId];
|
|
4165
|
+
if (options?.projectName) {
|
|
4166
|
+
sql += ` AND c.project_name = ?`;
|
|
4167
|
+
args.push(options.projectName);
|
|
4168
|
+
}
|
|
4169
|
+
if (options?.since) {
|
|
4170
|
+
sql += ` AND c.timestamp >= ?`;
|
|
4171
|
+
args.push(options.since);
|
|
4172
|
+
}
|
|
4173
|
+
sql += ` ORDER BY rank LIMIT ?`;
|
|
4174
|
+
args.push(limit);
|
|
4175
|
+
const result = await getClient().execute({ sql, args });
|
|
4176
|
+
return result.rows.map((row) => ({
|
|
4177
|
+
id: `card:${String(row.id)}`,
|
|
4178
|
+
agent_id: String(row.agent_id),
|
|
4179
|
+
agent_role: "memory_card",
|
|
4180
|
+
session_id: String(row.session_id),
|
|
4181
|
+
timestamp: String(row.timestamp),
|
|
4182
|
+
tool_name: `memory_card:${String(row.card_type)}`,
|
|
4183
|
+
project_name: row.project_name == null ? "" : String(row.project_name),
|
|
4184
|
+
has_error: false,
|
|
4185
|
+
raw_text: `[${String(row.card_type)}] ${String(row.content)}
|
|
4186
|
+
Source memory: ${String(row.source_ref ?? row.memory_id)}`,
|
|
4187
|
+
vector: [],
|
|
4188
|
+
importance: 6,
|
|
4189
|
+
status: "active",
|
|
4190
|
+
confidence: Number(row.confidence ?? 0.6),
|
|
4191
|
+
last_accessed: String(row.timestamp)
|
|
4192
|
+
}));
|
|
4193
|
+
}
|
|
4194
|
+
var MAX_CARDS_PER_MEMORY, MAX_SENTENCE_CHARS;
|
|
4195
|
+
var init_memory_cards = __esm({
|
|
4196
|
+
"src/lib/memory-cards.ts"() {
|
|
4197
|
+
"use strict";
|
|
4198
|
+
init_database();
|
|
4199
|
+
MAX_CARDS_PER_MEMORY = 6;
|
|
4200
|
+
MAX_SENTENCE_CHARS = 360;
|
|
4201
|
+
}
|
|
4202
|
+
});
|
|
4203
|
+
|
|
4001
4204
|
// src/lib/store.ts
|
|
4002
4205
|
var store_exports = {};
|
|
4003
4206
|
__export(store_exports, {
|
|
@@ -4336,6 +4539,11 @@ async function flushBatch() {
|
|
|
4336
4539
|
const globalClient = getClient();
|
|
4337
4540
|
const globalStmts = batch.map(buildStmt);
|
|
4338
4541
|
await globalClient.batch(globalStmts, "write");
|
|
4542
|
+
try {
|
|
4543
|
+
const { insertMemoryCardsForBatch: insertMemoryCardsForBatch2 } = await Promise.resolve().then(() => (init_memory_cards(), memory_cards_exports));
|
|
4544
|
+
await insertMemoryCardsForBatch2(batch);
|
|
4545
|
+
} catch {
|
|
4546
|
+
}
|
|
4339
4547
|
schedulePostWriteMemoryHygiene(batch.map((row) => row.id));
|
|
4340
4548
|
_pendingRecords.splice(0, batch.length);
|
|
4341
4549
|
try {
|
|
@@ -5838,9 +6046,18 @@ async function hybridSearch(queryText, agentId, options) {
|
|
|
5838
6046
|
} catch {
|
|
5839
6047
|
}
|
|
5840
6048
|
}
|
|
5841
|
-
const
|
|
6049
|
+
const includeStructuredCards = effectiveIsBroad || effectiveOptions.includeStructuredCards === true;
|
|
6050
|
+
const [ftsResults, vectorResults, cardResults, grepResults] = await Promise.all([
|
|
5842
6051
|
lightweightSearch(effectiveQuery, agentId, fetchOptions),
|
|
5843
6052
|
queryVector ? searchMemories(queryVector, agentId, fetchOptions) : Promise.resolve([]),
|
|
6053
|
+
includeStructuredCards ? (async () => {
|
|
6054
|
+
try {
|
|
6055
|
+
const { searchMemoryCards: searchMemoryCards2 } = await Promise.resolve().then(() => (init_memory_cards(), memory_cards_exports));
|
|
6056
|
+
return await searchMemoryCards2(effectiveQuery, agentId, fetchOptions);
|
|
6057
|
+
} catch {
|
|
6058
|
+
return [];
|
|
6059
|
+
}
|
|
6060
|
+
})() : Promise.resolve([]),
|
|
5844
6061
|
grepPromise
|
|
5845
6062
|
]);
|
|
5846
6063
|
const lists = [];
|
|
@@ -5853,6 +6070,10 @@ async function hybridSearch(queryText, agentId, options) {
|
|
|
5853
6070
|
lists.push(vectorResults);
|
|
5854
6071
|
weights.push(1);
|
|
5855
6072
|
}
|
|
6073
|
+
if (cardResults.length > 0) {
|
|
6074
|
+
lists.push(cardResults);
|
|
6075
|
+
weights.push(1.2);
|
|
6076
|
+
}
|
|
5856
6077
|
if (grepResults.length > 0) {
|
|
5857
6078
|
lists.push(grepResults);
|
|
5858
6079
|
weights.push(0.5);
|
|
@@ -5921,6 +6142,7 @@ async function hybridSearch(queryText, agentId, options) {
|
|
|
5921
6142
|
signals: {
|
|
5922
6143
|
fts: ftsResults.length,
|
|
5923
6144
|
vector: vectorResults.length,
|
|
6145
|
+
cards: cardResults.length,
|
|
5924
6146
|
grep: grepResults.length,
|
|
5925
6147
|
entityBoost: entityBoostRan,
|
|
5926
6148
|
reranker: rerankedAndBlended !== null,
|
|
@@ -6070,6 +6292,15 @@ async function lightweightSearch(queryText, agentId, options) {
|
|
|
6070
6292
|
if (options?.includeSource && results.length > 0) {
|
|
6071
6293
|
await attachDocumentMetadata(results);
|
|
6072
6294
|
}
|
|
6295
|
+
if (options?.includeStructuredCards !== true) return results;
|
|
6296
|
+
try {
|
|
6297
|
+
const { searchMemoryCards: searchMemoryCards2 } = await Promise.resolve().then(() => (init_memory_cards(), memory_cards_exports));
|
|
6298
|
+
const cardResults = await searchMemoryCards2(queryText, agentId, options);
|
|
6299
|
+
if (cardResults.length > 0) {
|
|
6300
|
+
return rrfMergeMulti([results, cardResults], limit, RRF_K, [1, 1.2]);
|
|
6301
|
+
}
|
|
6302
|
+
} catch {
|
|
6303
|
+
}
|
|
6073
6304
|
return results;
|
|
6074
6305
|
}
|
|
6075
6306
|
async function ftsQuery(client, matchExpr, agentId, options, limit) {
|
package/dist/lib/identity.js
CHANGED
package/dist/lib/license.js
CHANGED
package/dist/lib/messaging.js
CHANGED
package/dist/lib/reminders.js
CHANGED
package/dist/lib/schedules.js
CHANGED
|
@@ -246,8 +246,8 @@ var init_config = __esm({
|
|
|
246
246
|
rerankerAutoTrigger: {
|
|
247
247
|
enabled: true,
|
|
248
248
|
broadQueryMinCardinality: 5e4,
|
|
249
|
-
fetchTopK:
|
|
250
|
-
returnTopK:
|
|
249
|
+
fetchTopK: 200,
|
|
250
|
+
returnTopK: 20
|
|
251
251
|
}
|
|
252
252
|
},
|
|
253
253
|
graphRagEnabled: true,
|
|
@@ -2505,6 +2505,51 @@ async function ensureSchema() {
|
|
|
2505
2505
|
VALUES (new.rowid, new.content_text, new.sender_name, new.agent_response);
|
|
2506
2506
|
END;
|
|
2507
2507
|
`);
|
|
2508
|
+
await client.executeMultiple(`
|
|
2509
|
+
CREATE TABLE IF NOT EXISTS memory_cards (
|
|
2510
|
+
id TEXT PRIMARY KEY,
|
|
2511
|
+
memory_id TEXT NOT NULL,
|
|
2512
|
+
agent_id TEXT NOT NULL,
|
|
2513
|
+
session_id TEXT NOT NULL,
|
|
2514
|
+
project_name TEXT,
|
|
2515
|
+
timestamp TEXT NOT NULL,
|
|
2516
|
+
card_type TEXT NOT NULL,
|
|
2517
|
+
subject TEXT,
|
|
2518
|
+
predicate TEXT,
|
|
2519
|
+
object TEXT,
|
|
2520
|
+
content TEXT NOT NULL,
|
|
2521
|
+
source_ref TEXT,
|
|
2522
|
+
confidence REAL DEFAULT 0.6,
|
|
2523
|
+
active INTEGER DEFAULT 1,
|
|
2524
|
+
created_at TEXT NOT NULL
|
|
2525
|
+
);
|
|
2526
|
+
|
|
2527
|
+
CREATE INDEX IF NOT EXISTS idx_memory_cards_agent
|
|
2528
|
+
ON memory_cards(agent_id, active, timestamp);
|
|
2529
|
+
|
|
2530
|
+
CREATE INDEX IF NOT EXISTS idx_memory_cards_memory
|
|
2531
|
+
ON memory_cards(memory_id);
|
|
2532
|
+
|
|
2533
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memory_cards_fts
|
|
2534
|
+
USING fts5(content, subject, predicate, object, content='memory_cards', content_rowid='rowid');
|
|
2535
|
+
|
|
2536
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ai AFTER INSERT ON memory_cards BEGIN
|
|
2537
|
+
INSERT INTO memory_cards_fts(rowid, content, subject, predicate, object)
|
|
2538
|
+
VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
|
|
2539
|
+
END;
|
|
2540
|
+
|
|
2541
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ad AFTER DELETE ON memory_cards BEGIN
|
|
2542
|
+
INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
|
|
2543
|
+
VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
|
|
2544
|
+
END;
|
|
2545
|
+
|
|
2546
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_au AFTER UPDATE ON memory_cards BEGIN
|
|
2547
|
+
INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
|
|
2548
|
+
VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
|
|
2549
|
+
INSERT INTO memory_cards_fts(rowid, content, subject, predicate, object)
|
|
2550
|
+
VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
|
|
2551
|
+
END;
|
|
2552
|
+
`);
|
|
2508
2553
|
try {
|
|
2509
2554
|
await client.execute({
|
|
2510
2555
|
sql: `ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3`,
|
package/dist/lib/store.js
CHANGED
|
@@ -255,8 +255,8 @@ var init_config = __esm({
|
|
|
255
255
|
rerankerAutoTrigger: {
|
|
256
256
|
enabled: true,
|
|
257
257
|
broadQueryMinCardinality: 5e4,
|
|
258
|
-
fetchTopK:
|
|
259
|
-
returnTopK:
|
|
258
|
+
fetchTopK: 200,
|
|
259
|
+
returnTopK: 20
|
|
260
260
|
}
|
|
261
261
|
},
|
|
262
262
|
graphRagEnabled: true,
|
|
@@ -2505,6 +2505,51 @@ async function ensureSchema() {
|
|
|
2505
2505
|
VALUES (new.rowid, new.content_text, new.sender_name, new.agent_response);
|
|
2506
2506
|
END;
|
|
2507
2507
|
`);
|
|
2508
|
+
await client.executeMultiple(`
|
|
2509
|
+
CREATE TABLE IF NOT EXISTS memory_cards (
|
|
2510
|
+
id TEXT PRIMARY KEY,
|
|
2511
|
+
memory_id TEXT NOT NULL,
|
|
2512
|
+
agent_id TEXT NOT NULL,
|
|
2513
|
+
session_id TEXT NOT NULL,
|
|
2514
|
+
project_name TEXT,
|
|
2515
|
+
timestamp TEXT NOT NULL,
|
|
2516
|
+
card_type TEXT NOT NULL,
|
|
2517
|
+
subject TEXT,
|
|
2518
|
+
predicate TEXT,
|
|
2519
|
+
object TEXT,
|
|
2520
|
+
content TEXT NOT NULL,
|
|
2521
|
+
source_ref TEXT,
|
|
2522
|
+
confidence REAL DEFAULT 0.6,
|
|
2523
|
+
active INTEGER DEFAULT 1,
|
|
2524
|
+
created_at TEXT NOT NULL
|
|
2525
|
+
);
|
|
2526
|
+
|
|
2527
|
+
CREATE INDEX IF NOT EXISTS idx_memory_cards_agent
|
|
2528
|
+
ON memory_cards(agent_id, active, timestamp);
|
|
2529
|
+
|
|
2530
|
+
CREATE INDEX IF NOT EXISTS idx_memory_cards_memory
|
|
2531
|
+
ON memory_cards(memory_id);
|
|
2532
|
+
|
|
2533
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memory_cards_fts
|
|
2534
|
+
USING fts5(content, subject, predicate, object, content='memory_cards', content_rowid='rowid');
|
|
2535
|
+
|
|
2536
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ai AFTER INSERT ON memory_cards BEGIN
|
|
2537
|
+
INSERT INTO memory_cards_fts(rowid, content, subject, predicate, object)
|
|
2538
|
+
VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
|
|
2539
|
+
END;
|
|
2540
|
+
|
|
2541
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ad AFTER DELETE ON memory_cards BEGIN
|
|
2542
|
+
INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
|
|
2543
|
+
VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
|
|
2544
|
+
END;
|
|
2545
|
+
|
|
2546
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_au AFTER UPDATE ON memory_cards BEGIN
|
|
2547
|
+
INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
|
|
2548
|
+
VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
|
|
2549
|
+
INSERT INTO memory_cards_fts(rowid, content, subject, predicate, object)
|
|
2550
|
+
VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
|
|
2551
|
+
END;
|
|
2552
|
+
`);
|
|
2508
2553
|
try {
|
|
2509
2554
|
await client.execute({
|
|
2510
2555
|
sql: `ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3`,
|
|
@@ -3322,6 +3367,164 @@ ${p.content}`).join("\n\n");
|
|
|
3322
3367
|
}
|
|
3323
3368
|
});
|
|
3324
3369
|
|
|
3370
|
+
// src/lib/memory-cards.ts
|
|
3371
|
+
var memory_cards_exports = {};
|
|
3372
|
+
__export(memory_cards_exports, {
|
|
3373
|
+
extractMemoryCards: () => extractMemoryCards,
|
|
3374
|
+
insertMemoryCardsForBatch: () => insertMemoryCardsForBatch,
|
|
3375
|
+
searchMemoryCards: () => searchMemoryCards
|
|
3376
|
+
});
|
|
3377
|
+
import { createHash as createHash2 } from "crypto";
|
|
3378
|
+
function stableId(memoryId, type, content) {
|
|
3379
|
+
return createHash2("sha256").update(`${memoryId}:${type}:${content}`).digest("hex").slice(0, 32);
|
|
3380
|
+
}
|
|
3381
|
+
function cleanText(text) {
|
|
3382
|
+
return text.replace(/```[\s\S]*?```/g, " ").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
|
3383
|
+
}
|
|
3384
|
+
function splitSentences(text) {
|
|
3385
|
+
return cleanText(text).split(/(?<=[.!?])\s+|\n+/).map((s) => s.trim()).filter((s) => s.length >= 24 && s.length <= MAX_SENTENCE_CHARS);
|
|
3386
|
+
}
|
|
3387
|
+
function inferCardType(sentence, toolName) {
|
|
3388
|
+
const lower = sentence.toLowerCase();
|
|
3389
|
+
if (toolName === "store_decision" || /\b(decided|decision|adr|approved|rejected)\b/.test(lower)) return "decision";
|
|
3390
|
+
if (/\b(prefers|preference|likes|dislikes|wants|doesn't want|does not want)\b/.test(lower)) return "preference";
|
|
3391
|
+
if (/\b(changed|updated|replaced|now|no longer|instead|supersedes)\b/.test(lower)) return "belief_update";
|
|
3392
|
+
if (toolName && ["Read", "Write", "Edit", "Bash"].includes(toolName)) return "code";
|
|
3393
|
+
if (/\b(meeting|deadline|shipped|launched|completed|failed|blocked|assigned|created)\b/.test(lower)) return "event";
|
|
3394
|
+
return "fact";
|
|
3395
|
+
}
|
|
3396
|
+
function extractSubject(sentence, agentId) {
|
|
3397
|
+
const explicit = sentence.match(/\b([A-Z][a-zA-Z0-9_-]{2,}(?:\s+[A-Z][a-zA-Z0-9_-]{2,})?)\b/);
|
|
3398
|
+
return explicit?.[1] ?? agentId;
|
|
3399
|
+
}
|
|
3400
|
+
function predicateFor(type) {
|
|
3401
|
+
switch (type) {
|
|
3402
|
+
case "preference":
|
|
3403
|
+
return "prefers";
|
|
3404
|
+
case "belief_update":
|
|
3405
|
+
return "updated";
|
|
3406
|
+
case "decision":
|
|
3407
|
+
return "decided";
|
|
3408
|
+
case "event":
|
|
3409
|
+
return "happened";
|
|
3410
|
+
case "code":
|
|
3411
|
+
return "implemented";
|
|
3412
|
+
default:
|
|
3413
|
+
return "states";
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
3416
|
+
function extractMemoryCards(row) {
|
|
3417
|
+
const sentences = splitSentences(row.raw_text);
|
|
3418
|
+
const cards = [];
|
|
3419
|
+
for (const sentence of sentences) {
|
|
3420
|
+
const type = inferCardType(sentence, row.tool_name);
|
|
3421
|
+
const subject = extractSubject(sentence, row.agent_id);
|
|
3422
|
+
const content = sentence.length > MAX_SENTENCE_CHARS ? `${sentence.slice(0, MAX_SENTENCE_CHARS - 1)}\u2026` : sentence;
|
|
3423
|
+
cards.push({
|
|
3424
|
+
id: stableId(row.id, type, content),
|
|
3425
|
+
memory_id: row.id,
|
|
3426
|
+
agent_id: row.agent_id,
|
|
3427
|
+
session_id: row.session_id,
|
|
3428
|
+
project_name: row.project_name ?? null,
|
|
3429
|
+
timestamp: row.timestamp,
|
|
3430
|
+
card_type: type,
|
|
3431
|
+
subject,
|
|
3432
|
+
predicate: predicateFor(type),
|
|
3433
|
+
object: content,
|
|
3434
|
+
content,
|
|
3435
|
+
source_ref: row.id,
|
|
3436
|
+
confidence: type === "fact" ? 0.55 : 0.65
|
|
3437
|
+
});
|
|
3438
|
+
if (cards.length >= MAX_CARDS_PER_MEMORY) break;
|
|
3439
|
+
}
|
|
3440
|
+
return cards;
|
|
3441
|
+
}
|
|
3442
|
+
async function insertMemoryCardsForBatch(rows) {
|
|
3443
|
+
const cards = rows.flatMap(extractMemoryCards);
|
|
3444
|
+
if (cards.length === 0) return 0;
|
|
3445
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3446
|
+
const client = getClient();
|
|
3447
|
+
const stmts = cards.map((card) => ({
|
|
3448
|
+
sql: `INSERT OR IGNORE INTO memory_cards
|
|
3449
|
+
(id, memory_id, agent_id, session_id, project_name, timestamp, card_type,
|
|
3450
|
+
subject, predicate, object, content, source_ref, confidence, active, created_at)
|
|
3451
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?)`,
|
|
3452
|
+
args: [
|
|
3453
|
+
card.id,
|
|
3454
|
+
card.memory_id,
|
|
3455
|
+
card.agent_id,
|
|
3456
|
+
card.session_id,
|
|
3457
|
+
card.project_name,
|
|
3458
|
+
card.timestamp,
|
|
3459
|
+
card.card_type,
|
|
3460
|
+
card.subject,
|
|
3461
|
+
card.predicate,
|
|
3462
|
+
card.object,
|
|
3463
|
+
card.content,
|
|
3464
|
+
card.source_ref,
|
|
3465
|
+
card.confidence,
|
|
3466
|
+
now
|
|
3467
|
+
]
|
|
3468
|
+
}));
|
|
3469
|
+
await client.batch(stmts, "write");
|
|
3470
|
+
return cards.length;
|
|
3471
|
+
}
|
|
3472
|
+
function buildMatchExpr(queryText) {
|
|
3473
|
+
const terms = queryText.toLowerCase().split(/\s+/).filter((t) => t.length >= 3).map((t) => t.replace(/[^a-z0-9_]/g, "")).filter((t) => t.length >= 3).slice(0, 12);
|
|
3474
|
+
if (terms.length === 0) return null;
|
|
3475
|
+
return terms.map((t) => `${t}*`).join(terms.length >= 3 ? " AND " : " OR ");
|
|
3476
|
+
}
|
|
3477
|
+
async function searchMemoryCards(queryText, agentId, options) {
|
|
3478
|
+
const limit = options?.limit ?? 10;
|
|
3479
|
+
const matchExpr = buildMatchExpr(queryText);
|
|
3480
|
+
if (!matchExpr) return [];
|
|
3481
|
+
let sql = `SELECT c.id, c.memory_id, c.agent_id, c.session_id, c.project_name,
|
|
3482
|
+
c.timestamp, c.card_type, c.content, c.source_ref, c.confidence
|
|
3483
|
+
FROM memory_cards c
|
|
3484
|
+
JOIN memory_cards_fts fts ON c.rowid = fts.rowid
|
|
3485
|
+
WHERE memory_cards_fts MATCH ?
|
|
3486
|
+
AND c.agent_id = ?
|
|
3487
|
+
AND COALESCE(c.active, 1) = 1`;
|
|
3488
|
+
const args = [matchExpr, agentId];
|
|
3489
|
+
if (options?.projectName) {
|
|
3490
|
+
sql += ` AND c.project_name = ?`;
|
|
3491
|
+
args.push(options.projectName);
|
|
3492
|
+
}
|
|
3493
|
+
if (options?.since) {
|
|
3494
|
+
sql += ` AND c.timestamp >= ?`;
|
|
3495
|
+
args.push(options.since);
|
|
3496
|
+
}
|
|
3497
|
+
sql += ` ORDER BY rank LIMIT ?`;
|
|
3498
|
+
args.push(limit);
|
|
3499
|
+
const result = await getClient().execute({ sql, args });
|
|
3500
|
+
return result.rows.map((row) => ({
|
|
3501
|
+
id: `card:${String(row.id)}`,
|
|
3502
|
+
agent_id: String(row.agent_id),
|
|
3503
|
+
agent_role: "memory_card",
|
|
3504
|
+
session_id: String(row.session_id),
|
|
3505
|
+
timestamp: String(row.timestamp),
|
|
3506
|
+
tool_name: `memory_card:${String(row.card_type)}`,
|
|
3507
|
+
project_name: row.project_name == null ? "" : String(row.project_name),
|
|
3508
|
+
has_error: false,
|
|
3509
|
+
raw_text: `[${String(row.card_type)}] ${String(row.content)}
|
|
3510
|
+
Source memory: ${String(row.source_ref ?? row.memory_id)}`,
|
|
3511
|
+
vector: [],
|
|
3512
|
+
importance: 6,
|
|
3513
|
+
status: "active",
|
|
3514
|
+
confidence: Number(row.confidence ?? 0.6),
|
|
3515
|
+
last_accessed: String(row.timestamp)
|
|
3516
|
+
}));
|
|
3517
|
+
}
|
|
3518
|
+
var MAX_CARDS_PER_MEMORY, MAX_SENTENCE_CHARS;
|
|
3519
|
+
var init_memory_cards = __esm({
|
|
3520
|
+
"src/lib/memory-cards.ts"() {
|
|
3521
|
+
"use strict";
|
|
3522
|
+
init_database();
|
|
3523
|
+
MAX_CARDS_PER_MEMORY = 6;
|
|
3524
|
+
MAX_SENTENCE_CHARS = 360;
|
|
3525
|
+
}
|
|
3526
|
+
});
|
|
3527
|
+
|
|
3325
3528
|
// src/lib/store.ts
|
|
3326
3529
|
init_memory();
|
|
3327
3530
|
init_database();
|
|
@@ -4112,6 +4315,11 @@ async function flushBatch() {
|
|
|
4112
4315
|
const globalClient = getClient();
|
|
4113
4316
|
const globalStmts = batch.map(buildStmt);
|
|
4114
4317
|
await globalClient.batch(globalStmts, "write");
|
|
4318
|
+
try {
|
|
4319
|
+
const { insertMemoryCardsForBatch: insertMemoryCardsForBatch2 } = await Promise.resolve().then(() => (init_memory_cards(), memory_cards_exports));
|
|
4320
|
+
await insertMemoryCardsForBatch2(batch);
|
|
4321
|
+
} catch {
|
|
4322
|
+
}
|
|
4115
4323
|
schedulePostWriteMemoryHygiene(batch.map((row) => row.id));
|
|
4116
4324
|
_pendingRecords.splice(0, batch.length);
|
|
4117
4325
|
try {
|
package/dist/lib/task-router.js
CHANGED
package/dist/lib/tasks.js
CHANGED
package/dist/lib/tmux-routing.js
CHANGED