@askexenow/exe-os 0.9.60 → 0.9.62
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 +282 -7
- package/dist/bin/backfill-responses.js +282 -7
- package/dist/bin/backfill-vectors.js +119 -7
- package/dist/bin/cc-doctor.js +376 -0
- package/dist/bin/cleanup-stale-review-tasks.js +282 -7
- package/dist/bin/cli.js +455 -77
- package/dist/bin/customer-readiness.js +33 -0
- package/dist/bin/exe-agent-config.js +2 -2
- package/dist/bin/exe-agent.js +3 -3
- package/dist/bin/exe-assign.js +282 -7
- package/dist/bin/exe-boot.js +125 -13
- package/dist/bin/exe-call.js +3 -3
- package/dist/bin/exe-cloud.js +2 -2
- package/dist/bin/exe-dispatch.js +282 -7
- package/dist/bin/exe-doctor.js +119 -7
- package/dist/bin/exe-export-behaviors.js +282 -7
- package/dist/bin/exe-forget.js +336 -7
- package/dist/bin/exe-gateway.js +282 -7
- package/dist/bin/exe-heartbeat.js +284 -9
- package/dist/bin/exe-kill.js +282 -7
- package/dist/bin/exe-launch-agent.js +282 -7
- package/dist/bin/exe-link.js +121 -9
- package/dist/bin/exe-new-employee.js +50 -21
- package/dist/bin/exe-pending-messages.js +282 -7
- package/dist/bin/exe-pending-notifications.js +282 -7
- package/dist/bin/exe-pending-reviews.js +282 -7
- package/dist/bin/exe-rename.js +282 -7
- package/dist/bin/exe-review.js +282 -7
- package/dist/bin/exe-search.js +306 -8
- package/dist/bin/exe-session-cleanup.js +282 -7
- package/dist/bin/exe-settings.js +2 -2
- package/dist/bin/exe-start-codex.js +326 -21
- package/dist/bin/exe-start-opencode.js +304 -10
- package/dist/bin/exe-status.js +282 -7
- package/dist/bin/exe-team.js +282 -7
- package/dist/bin/git-sweep.js +282 -7
- package/dist/bin/graph-backfill.js +282 -7
- package/dist/bin/graph-export.js +282 -7
- package/dist/bin/install.js +58 -33
- package/dist/bin/intercom-check.js +282 -7
- package/dist/bin/pre-build-guard.js +98 -0
- package/dist/bin/scan-tasks.js +282 -7
- package/dist/bin/setup.js +122 -10
- package/dist/bin/shard-migrate.js +282 -7
- package/dist/bin/stack-update.js +79 -11
- package/dist/bin/update.js +2 -2
- package/dist/gateway/index.js +288 -13
- package/dist/hooks/bug-report-worker.js +282 -7
- package/dist/hooks/codex-stop-task-finalizer.js +282 -7
- package/dist/hooks/commit-complete.js +282 -7
- package/dist/hooks/error-recall.js +306 -8
- package/dist/hooks/exe-heartbeat-hook.js +2 -2
- package/dist/hooks/ingest-worker.js +2 -2
- package/dist/hooks/ingest.js +282 -7
- package/dist/hooks/instructions-loaded.js +282 -7
- package/dist/hooks/notification.js +282 -7
- package/dist/hooks/post-compact.js +282 -7
- package/dist/hooks/post-tool-combined.js +306 -8
- package/dist/hooks/pre-compact.js +282 -7
- package/dist/hooks/pre-tool-use.js +282 -7
- package/dist/hooks/prompt-submit.js +306 -8
- package/dist/hooks/session-end.js +282 -7
- package/dist/hooks/session-start.js +308 -10
- package/dist/hooks/stop.js +282 -7
- package/dist/hooks/subagent-stop.js +282 -7
- package/dist/hooks/summary-worker.js +125 -13
- package/dist/index.js +288 -13
- package/dist/lib/agent-config.js +2 -2
- package/dist/lib/cloud-sync.js +121 -9
- package/dist/lib/config.js +2 -2
- package/dist/lib/consolidation.js +2 -2
- package/dist/lib/database.js +115 -3
- package/dist/lib/db-daemon-client.js +2 -2
- package/dist/lib/db.js +115 -3
- package/dist/lib/device-registry.js +115 -3
- package/dist/lib/embedder.js +2 -2
- package/dist/lib/employee-templates.js +3 -3
- package/dist/lib/employees.js +2 -2
- package/dist/lib/exe-daemon-client.js +2 -2
- package/dist/lib/exe-daemon.js +339 -31
- package/dist/lib/hybrid-search.js +306 -8
- 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 +119 -7
- package/dist/lib/skill-learning.js +2 -2
- package/dist/lib/store.js +282 -7
- 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 +339 -31
- 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 +282 -7
- package/dist/tui/App.js +290 -15
- package/package.json +3 -2
- package/stack.release.json +23 -7
package/dist/bin/exe-forget.js
CHANGED
|
@@ -247,8 +247,8 @@ var init_config = __esm({
|
|
|
247
247
|
rerankerAutoTrigger: {
|
|
248
248
|
enabled: true,
|
|
249
249
|
broadQueryMinCardinality: 5e4,
|
|
250
|
-
fetchTopK:
|
|
251
|
-
returnTopK:
|
|
250
|
+
fetchTopK: 200,
|
|
251
|
+
returnTopK: 20
|
|
252
252
|
}
|
|
253
253
|
},
|
|
254
254
|
graphRagEnabled: true,
|
|
@@ -2504,7 +2504,7 @@ async function ensureSchema() {
|
|
|
2504
2504
|
ON session_kills(agent_id);
|
|
2505
2505
|
`);
|
|
2506
2506
|
await client.execute(`
|
|
2507
|
-
CREATE TABLE IF NOT EXISTS
|
|
2507
|
+
CREATE TABLE IF NOT EXISTS company_procedures (
|
|
2508
2508
|
id TEXT PRIMARY KEY,
|
|
2509
2509
|
title TEXT NOT NULL,
|
|
2510
2510
|
content TEXT NOT NULL,
|
|
@@ -2515,6 +2515,73 @@ async function ensureSchema() {
|
|
|
2515
2515
|
updated_at TEXT NOT NULL
|
|
2516
2516
|
)
|
|
2517
2517
|
`);
|
|
2518
|
+
const legacyProcedureObject = await client.execute({
|
|
2519
|
+
sql: "SELECT type FROM sqlite_master WHERE name = 'global_procedures'",
|
|
2520
|
+
args: []
|
|
2521
|
+
});
|
|
2522
|
+
const legacyProcedureType = legacyProcedureObject.rows[0]?.type == null ? null : String(legacyProcedureObject.rows[0].type);
|
|
2523
|
+
if (legacyProcedureType === "table") {
|
|
2524
|
+
await client.execute(`
|
|
2525
|
+
INSERT OR IGNORE INTO company_procedures
|
|
2526
|
+
(id, title, content, priority, domain, active, created_at, updated_at)
|
|
2527
|
+
SELECT id, title, content, priority, domain, active, created_at, updated_at
|
|
2528
|
+
FROM global_procedures
|
|
2529
|
+
`);
|
|
2530
|
+
await client.executeMultiple(`
|
|
2531
|
+
CREATE TRIGGER IF NOT EXISTS global_procedures_mirror_insert
|
|
2532
|
+
AFTER INSERT ON global_procedures
|
|
2533
|
+
BEGIN
|
|
2534
|
+
INSERT OR IGNORE INTO company_procedures
|
|
2535
|
+
(id, title, content, priority, domain, active, created_at, updated_at)
|
|
2536
|
+
VALUES
|
|
2537
|
+
(NEW.id, NEW.title, NEW.content, NEW.priority, NEW.domain, NEW.active, NEW.created_at, NEW.updated_at);
|
|
2538
|
+
END;
|
|
2539
|
+
|
|
2540
|
+
CREATE TRIGGER IF NOT EXISTS global_procedures_mirror_update
|
|
2541
|
+
AFTER UPDATE ON global_procedures
|
|
2542
|
+
BEGIN
|
|
2543
|
+
UPDATE company_procedures
|
|
2544
|
+
SET title = NEW.title,
|
|
2545
|
+
content = NEW.content,
|
|
2546
|
+
priority = NEW.priority,
|
|
2547
|
+
domain = NEW.domain,
|
|
2548
|
+
active = NEW.active,
|
|
2549
|
+
created_at = NEW.created_at,
|
|
2550
|
+
updated_at = NEW.updated_at
|
|
2551
|
+
WHERE id = OLD.id;
|
|
2552
|
+
END;
|
|
2553
|
+
`);
|
|
2554
|
+
} else {
|
|
2555
|
+
await client.execute(`
|
|
2556
|
+
CREATE VIEW IF NOT EXISTS global_procedures AS
|
|
2557
|
+
SELECT id, title, content, priority, domain, active, created_at, updated_at
|
|
2558
|
+
FROM company_procedures
|
|
2559
|
+
`);
|
|
2560
|
+
await client.executeMultiple(`
|
|
2561
|
+
CREATE TRIGGER IF NOT EXISTS global_procedures_insert
|
|
2562
|
+
INSTEAD OF INSERT ON global_procedures
|
|
2563
|
+
BEGIN
|
|
2564
|
+
INSERT INTO company_procedures
|
|
2565
|
+
(id, title, content, priority, domain, active, created_at, updated_at)
|
|
2566
|
+
VALUES
|
|
2567
|
+
(NEW.id, NEW.title, NEW.content, NEW.priority, NEW.domain, NEW.active, NEW.created_at, NEW.updated_at);
|
|
2568
|
+
END;
|
|
2569
|
+
|
|
2570
|
+
CREATE TRIGGER IF NOT EXISTS global_procedures_update
|
|
2571
|
+
INSTEAD OF UPDATE ON global_procedures
|
|
2572
|
+
BEGIN
|
|
2573
|
+
UPDATE company_procedures
|
|
2574
|
+
SET title = NEW.title,
|
|
2575
|
+
content = NEW.content,
|
|
2576
|
+
priority = NEW.priority,
|
|
2577
|
+
domain = NEW.domain,
|
|
2578
|
+
active = NEW.active,
|
|
2579
|
+
created_at = NEW.created_at,
|
|
2580
|
+
updated_at = NEW.updated_at
|
|
2581
|
+
WHERE id = OLD.id;
|
|
2582
|
+
END;
|
|
2583
|
+
`);
|
|
2584
|
+
}
|
|
2518
2585
|
await client.executeMultiple(`
|
|
2519
2586
|
CREATE TABLE IF NOT EXISTS conversations (
|
|
2520
2587
|
id TEXT PRIMARY KEY,
|
|
@@ -2654,6 +2721,51 @@ async function ensureSchema() {
|
|
|
2654
2721
|
VALUES (new.rowid, new.content_text, new.sender_name, new.agent_response);
|
|
2655
2722
|
END;
|
|
2656
2723
|
`);
|
|
2724
|
+
await client.executeMultiple(`
|
|
2725
|
+
CREATE TABLE IF NOT EXISTS memory_cards (
|
|
2726
|
+
id TEXT PRIMARY KEY,
|
|
2727
|
+
memory_id TEXT NOT NULL,
|
|
2728
|
+
agent_id TEXT NOT NULL,
|
|
2729
|
+
session_id TEXT NOT NULL,
|
|
2730
|
+
project_name TEXT,
|
|
2731
|
+
timestamp TEXT NOT NULL,
|
|
2732
|
+
card_type TEXT NOT NULL,
|
|
2733
|
+
subject TEXT,
|
|
2734
|
+
predicate TEXT,
|
|
2735
|
+
object TEXT,
|
|
2736
|
+
content TEXT NOT NULL,
|
|
2737
|
+
source_ref TEXT,
|
|
2738
|
+
confidence REAL DEFAULT 0.6,
|
|
2739
|
+
active INTEGER DEFAULT 1,
|
|
2740
|
+
created_at TEXT NOT NULL
|
|
2741
|
+
);
|
|
2742
|
+
|
|
2743
|
+
CREATE INDEX IF NOT EXISTS idx_memory_cards_agent
|
|
2744
|
+
ON memory_cards(agent_id, active, timestamp);
|
|
2745
|
+
|
|
2746
|
+
CREATE INDEX IF NOT EXISTS idx_memory_cards_memory
|
|
2747
|
+
ON memory_cards(memory_id);
|
|
2748
|
+
|
|
2749
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memory_cards_fts
|
|
2750
|
+
USING fts5(content, subject, predicate, object, content='memory_cards', content_rowid='rowid');
|
|
2751
|
+
|
|
2752
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ai AFTER INSERT ON memory_cards BEGIN
|
|
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
|
+
|
|
2757
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ad AFTER DELETE ON memory_cards BEGIN
|
|
2758
|
+
INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
|
|
2759
|
+
VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
|
|
2760
|
+
END;
|
|
2761
|
+
|
|
2762
|
+
CREATE TRIGGER IF NOT EXISTS memory_cards_fts_au AFTER UPDATE ON memory_cards BEGIN
|
|
2763
|
+
INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
|
|
2764
|
+
VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
|
|
2765
|
+
INSERT INTO memory_cards_fts(rowid, content, subject, predicate, object)
|
|
2766
|
+
VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
|
|
2767
|
+
END;
|
|
2768
|
+
`);
|
|
2657
2769
|
try {
|
|
2658
2770
|
await client.execute({
|
|
2659
2771
|
sql: `ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3`,
|
|
@@ -3863,7 +3975,7 @@ var init_platform_procedures = __esm({
|
|
|
3863
3975
|
title: "MCP tools \u2014 advanced (triggers, skills, orchestration)",
|
|
3864
3976
|
domain: "tool-use",
|
|
3865
3977
|
priority: "p1",
|
|
3866
|
-
content: "create_trigger: set up a scheduled recurring agent job (cron). list_triggers: view active triggers. load_skill: load a slash-command skill dynamically. apply_starter_pack: import a pre-built behavior + identity pack for a role. export_orchestration: export full org state (tasks, behaviors, identities) as portable JSON. import_orchestration: import org state into a new instance. deploy_client: deploy a customer client instance. query_company_brain: unified RAG query across all company knowledge. create_reminder: set a text reminder (shown in boot brief). list_reminders: view pending reminders. complete_reminder: mark a reminder done.
|
|
3978
|
+
content: "create_trigger: set up a scheduled recurring agent job (cron). list_triggers: view active triggers. load_skill: load a slash-command skill dynamically. apply_starter_pack: import a pre-built behavior + identity pack for a role. export_orchestration: export full org state (tasks, behaviors, identities) as portable JSON. import_orchestration: import org state into a new instance. deploy_client: deploy a customer client instance. query_company_brain: unified RAG query across all company knowledge. create_reminder: set a text reminder (shown in boot brief). list_reminders: view pending reminders. complete_reminder: mark a reminder done. company_procedure: manage customer-owned company procedures (Layer 0; actions: store, list, deactivate). Legacy aliases: global_procedure, store_global_procedure, list_global_procedures, deactivate_global_procedure."
|
|
3867
3979
|
}
|
|
3868
3980
|
];
|
|
3869
3981
|
PLATFORM_PROCEDURE_TITLES = new Set(
|
|
@@ -3884,7 +3996,7 @@ import { randomUUID as randomUUID2 } from "crypto";
|
|
|
3884
3996
|
async function loadGlobalProcedures() {
|
|
3885
3997
|
const client = getClient();
|
|
3886
3998
|
const result = await client.execute({
|
|
3887
|
-
sql: "SELECT * FROM
|
|
3999
|
+
sql: "SELECT * FROM company_procedures WHERE active = 1 ORDER BY priority ASC, created_at ASC",
|
|
3888
4000
|
args: []
|
|
3889
4001
|
});
|
|
3890
4002
|
const allRows = result.rows;
|
|
@@ -3913,7 +4025,7 @@ async function storeGlobalProcedure(input) {
|
|
|
3913
4025
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3914
4026
|
const client = getClient();
|
|
3915
4027
|
await client.execute({
|
|
3916
|
-
sql: `INSERT INTO
|
|
4028
|
+
sql: `INSERT INTO company_procedures (id, title, content, priority, domain, active, created_at, updated_at)
|
|
3917
4029
|
VALUES (?, ?, ?, ?, ?, 1, ?, ?)`,
|
|
3918
4030
|
args: [id, input.title, input.content, input.priority ?? "p0", input.domain ?? null, now, now]
|
|
3919
4031
|
});
|
|
@@ -3924,7 +4036,7 @@ async function deactivateGlobalProcedure(id) {
|
|
|
3924
4036
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3925
4037
|
const client = getClient();
|
|
3926
4038
|
const result = await client.execute({
|
|
3927
|
-
sql: "UPDATE
|
|
4039
|
+
sql: "UPDATE company_procedures SET active = 0, updated_at = ? WHERE id = ?",
|
|
3928
4040
|
args: [now, id]
|
|
3929
4041
|
});
|
|
3930
4042
|
await loadGlobalProcedures();
|
|
@@ -3943,6 +4055,164 @@ ${p.content}`).join("\n\n");
|
|
|
3943
4055
|
}
|
|
3944
4056
|
});
|
|
3945
4057
|
|
|
4058
|
+
// src/lib/memory-cards.ts
|
|
4059
|
+
var memory_cards_exports = {};
|
|
4060
|
+
__export(memory_cards_exports, {
|
|
4061
|
+
extractMemoryCards: () => extractMemoryCards,
|
|
4062
|
+
insertMemoryCardsForBatch: () => insertMemoryCardsForBatch,
|
|
4063
|
+
searchMemoryCards: () => searchMemoryCards
|
|
4064
|
+
});
|
|
4065
|
+
import { createHash as createHash2 } from "crypto";
|
|
4066
|
+
function stableId(memoryId, type, content) {
|
|
4067
|
+
return createHash2("sha256").update(`${memoryId}:${type}:${content}`).digest("hex").slice(0, 32);
|
|
4068
|
+
}
|
|
4069
|
+
function cleanText(text) {
|
|
4070
|
+
return text.replace(/```[\s\S]*?```/g, " ").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
|
4071
|
+
}
|
|
4072
|
+
function splitSentences(text) {
|
|
4073
|
+
return cleanText(text).split(/(?<=[.!?])\s+|\n+/).map((s) => s.trim()).filter((s) => s.length >= 24 && s.length <= MAX_SENTENCE_CHARS);
|
|
4074
|
+
}
|
|
4075
|
+
function inferCardType(sentence, toolName) {
|
|
4076
|
+
const lower = sentence.toLowerCase();
|
|
4077
|
+
if (toolName === "store_decision" || /\b(decided|decision|adr|approved|rejected)\b/.test(lower)) return "decision";
|
|
4078
|
+
if (/\b(prefers|preference|likes|dislikes|wants|doesn't want|does not want)\b/.test(lower)) return "preference";
|
|
4079
|
+
if (/\b(changed|updated|replaced|now|no longer|instead|supersedes)\b/.test(lower)) return "belief_update";
|
|
4080
|
+
if (toolName && ["Read", "Write", "Edit", "Bash"].includes(toolName)) return "code";
|
|
4081
|
+
if (/\b(meeting|deadline|shipped|launched|completed|failed|blocked|assigned|created)\b/.test(lower)) return "event";
|
|
4082
|
+
return "fact";
|
|
4083
|
+
}
|
|
4084
|
+
function extractSubject(sentence, agentId) {
|
|
4085
|
+
const explicit = sentence.match(/\b([A-Z][a-zA-Z0-9_-]{2,}(?:\s+[A-Z][a-zA-Z0-9_-]{2,})?)\b/);
|
|
4086
|
+
return explicit?.[1] ?? agentId;
|
|
4087
|
+
}
|
|
4088
|
+
function predicateFor(type) {
|
|
4089
|
+
switch (type) {
|
|
4090
|
+
case "preference":
|
|
4091
|
+
return "prefers";
|
|
4092
|
+
case "belief_update":
|
|
4093
|
+
return "updated";
|
|
4094
|
+
case "decision":
|
|
4095
|
+
return "decided";
|
|
4096
|
+
case "event":
|
|
4097
|
+
return "happened";
|
|
4098
|
+
case "code":
|
|
4099
|
+
return "implemented";
|
|
4100
|
+
default:
|
|
4101
|
+
return "states";
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
4104
|
+
function extractMemoryCards(row) {
|
|
4105
|
+
const sentences = splitSentences(row.raw_text);
|
|
4106
|
+
const cards = [];
|
|
4107
|
+
for (const sentence of sentences) {
|
|
4108
|
+
const type = inferCardType(sentence, row.tool_name);
|
|
4109
|
+
const subject = extractSubject(sentence, row.agent_id);
|
|
4110
|
+
const content = sentence.length > MAX_SENTENCE_CHARS ? `${sentence.slice(0, MAX_SENTENCE_CHARS - 1)}\u2026` : sentence;
|
|
4111
|
+
cards.push({
|
|
4112
|
+
id: stableId(row.id, type, content),
|
|
4113
|
+
memory_id: row.id,
|
|
4114
|
+
agent_id: row.agent_id,
|
|
4115
|
+
session_id: row.session_id,
|
|
4116
|
+
project_name: row.project_name ?? null,
|
|
4117
|
+
timestamp: row.timestamp,
|
|
4118
|
+
card_type: type,
|
|
4119
|
+
subject,
|
|
4120
|
+
predicate: predicateFor(type),
|
|
4121
|
+
object: content,
|
|
4122
|
+
content,
|
|
4123
|
+
source_ref: row.id,
|
|
4124
|
+
confidence: type === "fact" ? 0.55 : 0.65
|
|
4125
|
+
});
|
|
4126
|
+
if (cards.length >= MAX_CARDS_PER_MEMORY) break;
|
|
4127
|
+
}
|
|
4128
|
+
return cards;
|
|
4129
|
+
}
|
|
4130
|
+
async function insertMemoryCardsForBatch(rows) {
|
|
4131
|
+
const cards = rows.flatMap(extractMemoryCards);
|
|
4132
|
+
if (cards.length === 0) return 0;
|
|
4133
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4134
|
+
const client = getClient();
|
|
4135
|
+
const stmts = cards.map((card) => ({
|
|
4136
|
+
sql: `INSERT OR IGNORE INTO memory_cards
|
|
4137
|
+
(id, memory_id, agent_id, session_id, project_name, timestamp, card_type,
|
|
4138
|
+
subject, predicate, object, content, source_ref, confidence, active, created_at)
|
|
4139
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?)`,
|
|
4140
|
+
args: [
|
|
4141
|
+
card.id,
|
|
4142
|
+
card.memory_id,
|
|
4143
|
+
card.agent_id,
|
|
4144
|
+
card.session_id,
|
|
4145
|
+
card.project_name,
|
|
4146
|
+
card.timestamp,
|
|
4147
|
+
card.card_type,
|
|
4148
|
+
card.subject,
|
|
4149
|
+
card.predicate,
|
|
4150
|
+
card.object,
|
|
4151
|
+
card.content,
|
|
4152
|
+
card.source_ref,
|
|
4153
|
+
card.confidence,
|
|
4154
|
+
now
|
|
4155
|
+
]
|
|
4156
|
+
}));
|
|
4157
|
+
await client.batch(stmts, "write");
|
|
4158
|
+
return cards.length;
|
|
4159
|
+
}
|
|
4160
|
+
function buildMatchExpr(queryText) {
|
|
4161
|
+
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);
|
|
4162
|
+
if (terms.length === 0) return null;
|
|
4163
|
+
return terms.map((t) => `${t}*`).join(terms.length >= 3 ? " AND " : " OR ");
|
|
4164
|
+
}
|
|
4165
|
+
async function searchMemoryCards(queryText, agentId, options) {
|
|
4166
|
+
const limit = options?.limit ?? 10;
|
|
4167
|
+
const matchExpr = buildMatchExpr(queryText);
|
|
4168
|
+
if (!matchExpr) return [];
|
|
4169
|
+
let sql = `SELECT c.id, c.memory_id, c.agent_id, c.session_id, c.project_name,
|
|
4170
|
+
c.timestamp, c.card_type, c.content, c.source_ref, c.confidence
|
|
4171
|
+
FROM memory_cards c
|
|
4172
|
+
JOIN memory_cards_fts fts ON c.rowid = fts.rowid
|
|
4173
|
+
WHERE memory_cards_fts MATCH ?
|
|
4174
|
+
AND c.agent_id = ?
|
|
4175
|
+
AND COALESCE(c.active, 1) = 1`;
|
|
4176
|
+
const args = [matchExpr, agentId];
|
|
4177
|
+
if (options?.projectName) {
|
|
4178
|
+
sql += ` AND c.project_name = ?`;
|
|
4179
|
+
args.push(options.projectName);
|
|
4180
|
+
}
|
|
4181
|
+
if (options?.since) {
|
|
4182
|
+
sql += ` AND c.timestamp >= ?`;
|
|
4183
|
+
args.push(options.since);
|
|
4184
|
+
}
|
|
4185
|
+
sql += ` ORDER BY rank LIMIT ?`;
|
|
4186
|
+
args.push(limit);
|
|
4187
|
+
const result = await getClient().execute({ sql, args });
|
|
4188
|
+
return result.rows.map((row) => ({
|
|
4189
|
+
id: `card:${String(row.id)}`,
|
|
4190
|
+
agent_id: String(row.agent_id),
|
|
4191
|
+
agent_role: "memory_card",
|
|
4192
|
+
session_id: String(row.session_id),
|
|
4193
|
+
timestamp: String(row.timestamp),
|
|
4194
|
+
tool_name: `memory_card:${String(row.card_type)}`,
|
|
4195
|
+
project_name: row.project_name == null ? "" : String(row.project_name),
|
|
4196
|
+
has_error: false,
|
|
4197
|
+
raw_text: `[${String(row.card_type)}] ${String(row.content)}
|
|
4198
|
+
Source memory: ${String(row.source_ref ?? row.memory_id)}`,
|
|
4199
|
+
vector: [],
|
|
4200
|
+
importance: 6,
|
|
4201
|
+
status: "active",
|
|
4202
|
+
confidence: Number(row.confidence ?? 0.6),
|
|
4203
|
+
last_accessed: String(row.timestamp)
|
|
4204
|
+
}));
|
|
4205
|
+
}
|
|
4206
|
+
var MAX_CARDS_PER_MEMORY, MAX_SENTENCE_CHARS;
|
|
4207
|
+
var init_memory_cards = __esm({
|
|
4208
|
+
"src/lib/memory-cards.ts"() {
|
|
4209
|
+
"use strict";
|
|
4210
|
+
init_database();
|
|
4211
|
+
MAX_CARDS_PER_MEMORY = 6;
|
|
4212
|
+
MAX_SENTENCE_CHARS = 360;
|
|
4213
|
+
}
|
|
4214
|
+
});
|
|
4215
|
+
|
|
3946
4216
|
// src/lib/store.ts
|
|
3947
4217
|
var store_exports = {};
|
|
3948
4218
|
__export(store_exports, {
|
|
@@ -4281,6 +4551,11 @@ async function flushBatch() {
|
|
|
4281
4551
|
const globalClient = getClient();
|
|
4282
4552
|
const globalStmts = batch.map(buildStmt);
|
|
4283
4553
|
await globalClient.batch(globalStmts, "write");
|
|
4554
|
+
try {
|
|
4555
|
+
const { insertMemoryCardsForBatch: insertMemoryCardsForBatch2 } = await Promise.resolve().then(() => (init_memory_cards(), memory_cards_exports));
|
|
4556
|
+
await insertMemoryCardsForBatch2(batch);
|
|
4557
|
+
} catch {
|
|
4558
|
+
}
|
|
4284
4559
|
schedulePostWriteMemoryHygiene(batch.map((row) => row.id));
|
|
4285
4560
|
_pendingRecords.splice(0, batch.length);
|
|
4286
4561
|
try {
|
|
@@ -4628,6 +4903,7 @@ init_database();
|
|
|
4628
4903
|
// src/lib/hybrid-search.ts
|
|
4629
4904
|
init_store();
|
|
4630
4905
|
init_database();
|
|
4906
|
+
var RRF_K = 60;
|
|
4631
4907
|
function appendMemoryTypeFilter(sql, args, column, options) {
|
|
4632
4908
|
if (options?.memoryTypes && options.memoryTypes.length > 0) {
|
|
4633
4909
|
const uniqueTypes = [...new Set(options.memoryTypes)];
|
|
@@ -4639,6 +4915,50 @@ function appendMemoryTypeFilter(sql, args, column, options) {
|
|
|
4639
4915
|
}
|
|
4640
4916
|
return sql;
|
|
4641
4917
|
}
|
|
4918
|
+
function recencyScore(timestamp) {
|
|
4919
|
+
const daysSince = (Date.now() - new Date(timestamp).getTime()) / (1e3 * 60 * 60 * 24);
|
|
4920
|
+
return 1 / (1 + daysSince * 0.01);
|
|
4921
|
+
}
|
|
4922
|
+
function normalizedImportance(importance) {
|
|
4923
|
+
return ((importance ?? 5) - 1) / 9;
|
|
4924
|
+
}
|
|
4925
|
+
function frecencyBoost(lastAccessed, timestamp) {
|
|
4926
|
+
const accessTime = lastAccessed ? new Date(lastAccessed).getTime() : new Date(timestamp).getTime();
|
|
4927
|
+
const hoursSince = Math.max(0, (Date.now() - accessTime) / (1e3 * 60 * 60));
|
|
4928
|
+
return Math.exp(-0.01 * hoursSince);
|
|
4929
|
+
}
|
|
4930
|
+
function sourceConfidence(record) {
|
|
4931
|
+
const tool = record.tool_name?.toLowerCase() ?? "";
|
|
4932
|
+
if (tool === "manual" || tool === "store_memory") return 0.95;
|
|
4933
|
+
if (tool === "auto-summary" || tool === "consolidation") return 0.9;
|
|
4934
|
+
if (tool === "userprompt" || tool === "assistantresponse") return 0.75;
|
|
4935
|
+
if (tool === "bash" || tool === "write" || tool === "edit") return 0.6;
|
|
4936
|
+
if (tool === "file_grep" || tool === "file_read") return 0.5;
|
|
4937
|
+
return record.confidence ?? 0.5;
|
|
4938
|
+
}
|
|
4939
|
+
function rrfMergeMulti(lists, limit, k = RRF_K, weights) {
|
|
4940
|
+
const scores = /* @__PURE__ */ new Map();
|
|
4941
|
+
for (let listIdx = 0; listIdx < lists.length; listIdx++) {
|
|
4942
|
+
const list = lists[listIdx];
|
|
4943
|
+
const weight = weights?.[listIdx] ?? 1;
|
|
4944
|
+
for (let i = 0; i < list.length; i++) {
|
|
4945
|
+
const rec = list[i];
|
|
4946
|
+
const entry = scores.get(rec.id) ?? { rrfScore: 0, record: rec };
|
|
4947
|
+
entry.rrfScore += weight * (1 / (k + i + 1));
|
|
4948
|
+
scores.set(rec.id, entry);
|
|
4949
|
+
}
|
|
4950
|
+
}
|
|
4951
|
+
const entries = Array.from(scores.values()).map((e) => {
|
|
4952
|
+
const recency = recencyScore(e.record.timestamp);
|
|
4953
|
+
const importance = normalizedImportance(e.record.importance);
|
|
4954
|
+
const confidence = sourceConfidence(e.record);
|
|
4955
|
+
const frecency = frecencyBoost(e.record.last_accessed, e.record.timestamp);
|
|
4956
|
+
const baseScore = e.rrfScore * 0.45 + recency * 0.24 + importance * 0.21 + confidence * 0.1;
|
|
4957
|
+
const finalScore = baseScore * (1 + 0.3 * frecency);
|
|
4958
|
+
return { score: finalScore, record: e.record };
|
|
4959
|
+
});
|
|
4960
|
+
return entries.sort((a, b) => b.score - a.score).slice(0, limit).map((e) => e.record);
|
|
4961
|
+
}
|
|
4642
4962
|
async function lightweightSearch(queryText, agentId, options) {
|
|
4643
4963
|
const client = getClient();
|
|
4644
4964
|
const limit = options?.limit ?? 5;
|
|
@@ -4664,6 +4984,15 @@ async function lightweightSearch(queryText, agentId, options) {
|
|
|
4664
4984
|
if (options?.includeSource && results.length > 0) {
|
|
4665
4985
|
await attachDocumentMetadata(results);
|
|
4666
4986
|
}
|
|
4987
|
+
if (options?.includeStructuredCards !== true) return results;
|
|
4988
|
+
try {
|
|
4989
|
+
const { searchMemoryCards: searchMemoryCards2 } = await Promise.resolve().then(() => (init_memory_cards(), memory_cards_exports));
|
|
4990
|
+
const cardResults = await searchMemoryCards2(queryText, agentId, options);
|
|
4991
|
+
if (cardResults.length > 0) {
|
|
4992
|
+
return rrfMergeMulti([results, cardResults], limit, RRF_K, [1, 1.2]);
|
|
4993
|
+
}
|
|
4994
|
+
} catch {
|
|
4995
|
+
}
|
|
4667
4996
|
return results;
|
|
4668
4997
|
}
|
|
4669
4998
|
async function ftsQuery(client, matchExpr, agentId, options, limit) {
|