abmind 0.1.3 → 0.1.5-alpha.1
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/CHANGELOG.md +47 -0
- package/README.md +90 -61
- package/config/.env.memory.example +114 -0
- package/dist/cli/abmind-backup.js +10 -10
- package/dist/cli/abmind-backup.js.map +1 -1
- package/dist/cli/abmind-bundle.js +4 -0
- package/dist/cli/abmind-bundle.js.map +1 -1
- package/dist/cli/abmind-hook-notification.d.ts +6 -0
- package/dist/cli/abmind-hook-notification.d.ts.map +1 -0
- package/dist/cli/abmind-hook-notification.js +56 -0
- package/dist/cli/abmind-hook-notification.js.map +1 -0
- package/dist/cli/abmind-hook-postToolUse.d.ts +10 -0
- package/dist/cli/abmind-hook-postToolUse.d.ts.map +1 -0
- package/dist/cli/abmind-hook-postToolUse.js +85 -0
- package/dist/cli/abmind-hook-postToolUse.js.map +1 -0
- package/dist/cli/abmind-hook-postcompact.d.ts +9 -0
- package/dist/cli/abmind-hook-postcompact.d.ts.map +1 -0
- package/dist/cli/abmind-hook-postcompact.js +64 -0
- package/dist/cli/abmind-hook-postcompact.js.map +1 -0
- package/dist/cli/abmind-hook-postuserprompt.d.ts +7 -0
- package/dist/cli/abmind-hook-postuserprompt.d.ts.map +1 -0
- package/dist/cli/abmind-hook-postuserprompt.js +69 -0
- package/dist/cli/abmind-hook-postuserprompt.js.map +1 -0
- package/dist/cli/abmind-hook-preToolUse.d.ts +10 -0
- package/dist/cli/abmind-hook-preToolUse.d.ts.map +1 -0
- package/dist/cli/abmind-hook-preToolUse.js +61 -0
- package/dist/cli/abmind-hook-preToolUse.js.map +1 -0
- package/dist/cli/abmind-hook-precompact.d.ts +7 -0
- package/dist/cli/abmind-hook-precompact.d.ts.map +1 -0
- package/dist/cli/abmind-hook-precompact.js +63 -0
- package/dist/cli/abmind-hook-precompact.js.map +1 -0
- package/dist/cli/abmind-hook-preuserprompt.d.ts +16 -0
- package/dist/cli/abmind-hook-preuserprompt.d.ts.map +1 -0
- package/dist/cli/abmind-hook-preuserprompt.js +125 -0
- package/dist/cli/abmind-hook-preuserprompt.js.map +1 -0
- package/dist/cli/abmind-hook-store.js +26 -3
- package/dist/cli/abmind-hook-store.js.map +1 -1
- package/dist/cli/abmind-hook-subagentstart.d.ts +6 -0
- package/dist/cli/abmind-hook-subagentstart.d.ts.map +1 -0
- package/dist/cli/abmind-hook-subagentstart.js +56 -0
- package/dist/cli/abmind-hook-subagentstart.js.map +1 -0
- package/dist/cli/abmind-hook-subagentstop.d.ts +6 -0
- package/dist/cli/abmind-hook-subagentstop.d.ts.map +1 -0
- package/dist/cli/abmind-hook-subagentstop.js +58 -0
- package/dist/cli/abmind-hook-subagentstop.js.map +1 -0
- package/dist/cli/abmind-hook-toolfailure.d.ts +7 -0
- package/dist/cli/abmind-hook-toolfailure.d.ts.map +1 -0
- package/dist/cli/abmind-hook-toolfailure.js +66 -0
- package/dist/cli/abmind-hook-toolfailure.js.map +1 -0
- package/dist/cli/abmind-hook-wakeup.js +10 -0
- package/dist/cli/abmind-hook-wakeup.js.map +1 -1
- package/dist/cli/abmind-install.js +251 -11
- package/dist/cli/abmind-install.js.map +1 -1
- package/dist/cli/abmind-restore.d.ts +1 -1
- package/dist/cli/abmind-restore.js +14 -36
- package/dist/cli/abmind-restore.js.map +1 -1
- package/dist/cli/abmind-retro-extract.js +41 -5
- package/dist/cli/abmind-retro-extract.js.map +1 -1
- package/dist/cli/abmind-sleep-state.js +1 -1
- package/dist/cli/abmind-sleep-state.js.map +1 -1
- package/dist/cli/abmind.js +2 -0
- package/dist/cli/abmind.js.map +1 -1
- package/dist/src/backup.d.ts +3 -1
- package/dist/src/backup.d.ts.map +1 -1
- package/dist/src/backup.js +11 -4
- package/dist/src/backup.js.map +1 -1
- package/dist/src/context-engine.d.ts +1 -1
- package/dist/src/context-engine.d.ts.map +1 -1
- package/dist/src/context-engine.js +1 -1
- package/dist/src/context-engine.js.map +1 -1
- package/dist/src/context-orchestrator.js +3 -3
- package/dist/src/context-orchestrator.js.map +1 -1
- package/dist/src/crypto.d.ts +6 -0
- package/dist/src/crypto.d.ts.map +1 -1
- package/dist/src/crypto.js +100 -17
- package/dist/src/crypto.js.map +1 -1
- package/dist/src/ensure-initialized.d.ts +1 -1
- package/dist/src/ensure-initialized.js +1 -1
- package/dist/src/env-schema.d.ts +2 -0
- package/dist/src/env-schema.d.ts.map +1 -1
- package/dist/src/env-schema.js +3 -1
- package/dist/src/env-schema.js.map +1 -1
- package/dist/src/index.d.ts +5 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/keyring.d.ts +9 -0
- package/dist/src/keyring.d.ts.map +1 -0
- package/dist/src/keyring.js +60 -0
- package/dist/src/keyring.js.map +1 -0
- package/dist/src/mem-types.d.ts +1 -1
- package/dist/src/mem-types.d.ts.map +1 -1
- package/dist/src/memory-backend.d.ts +3 -0
- package/dist/src/memory-backend.d.ts.map +1 -1
- package/dist/src/memory-config.js +1 -1
- package/dist/src/memory-config.js.map +1 -1
- package/dist/src/memory-db.d.ts +1 -6
- package/dist/src/memory-db.d.ts.map +1 -1
- package/dist/src/memory-db.js +7 -1
- package/dist/src/memory-db.js.map +1 -1
- package/dist/src/memory-editor.d.ts +1 -0
- package/dist/src/memory-editor.d.ts.map +1 -1
- package/dist/src/memory-editor.js +17 -16
- package/dist/src/memory-editor.js.map +1 -1
- package/dist/src/memory-ipc-client.d.ts +3 -0
- package/dist/src/memory-ipc-client.d.ts.map +1 -1
- package/dist/src/memory-ipc-client.js +4 -0
- package/dist/src/memory-ipc-client.js.map +1 -1
- package/dist/src/message-store.js +1 -1
- package/dist/src/message-store.js.map +1 -1
- package/dist/src/recall-benchmark.js +4 -2
- package/dist/src/recall-benchmark.js.map +1 -1
- package/dist/src/redact-secrets.d.ts.map +1 -1
- package/dist/src/redact-secrets.js +3 -0
- package/dist/src/redact-secrets.js.map +1 -1
- package/dist/src/session-context.d.ts +6 -5
- package/dist/src/session-context.d.ts.map +1 -1
- package/dist/src/session-context.js +134 -66
- package/dist/src/session-context.js.map +1 -1
- package/dist/src/sleep/levels.d.ts +7 -6
- package/dist/src/sleep/levels.d.ts.map +1 -1
- package/dist/src/sleep/levels.js.map +1 -1
- package/dist/src/sleep/orchestrator.d.ts +1 -1
- package/dist/src/sleep/orchestrator.d.ts.map +1 -1
- package/dist/src/sleep/orchestrator.js +80 -38
- package/dist/src/sleep/orchestrator.js.map +1 -1
- package/dist/src/sleep/sleep-daily-summary.d.ts +6 -2
- package/dist/src/sleep/sleep-daily-summary.d.ts.map +1 -1
- package/dist/src/sleep/sleep-daily-summary.js +34 -12
- package/dist/src/sleep/sleep-daily-summary.js.map +1 -1
- package/dist/src/sleep/sleep-extract-daily.d.ts.map +1 -1
- package/dist/src/sleep/sleep-extract-daily.js +3 -0
- package/dist/src/sleep/sleep-extract-daily.js.map +1 -1
- package/dist/src/sleep/sleep-prompt-loader.js +3 -3
- package/dist/src/sleep/sleep-prompt-loader.js.map +1 -1
- package/dist/src/sleep-data-access.d.ts +4 -2
- package/dist/src/sleep-data-access.d.ts.map +1 -1
- package/dist/src/sleep-data-access.js +49 -13
- package/dist/src/sleep-data-access.js.map +1 -1
- package/dist/src/sqlite-backend.d.ts +3 -0
- package/dist/src/sqlite-backend.d.ts.map +1 -1
- package/dist/src/sqlite-backend.js +3 -0
- package/dist/src/sqlite-backend.js.map +1 -1
- package/dist/src/status-block.d.ts +7 -0
- package/dist/src/status-block.d.ts.map +1 -0
- package/dist/src/status-block.js +67 -0
- package/dist/src/status-block.js.map +1 -0
- package/dist/src/wake-up-renderer.d.ts +0 -5
- package/dist/src/wake-up-renderer.d.ts.map +1 -1
- package/dist/src/wake-up-renderer.js +0 -34
- package/dist/src/wake-up-renderer.js.map +1 -1
- package/package.json +6 -3
- package/prompts/sleep/03-retrospective.md +23 -0
- package/prompts/sleep/04-extract-memories.md +3 -0
- package/prompts/sleep/06-retro-derive.md +39 -0
- package/prompts/sleep/08-memory-maintenance.md +39 -0
- package/prompts/sleep/{13-consolidation.md → 11-consolidation.md} +4 -1
- package/templates/core/SOUL.md +24 -0
- package/templates/core/agent_notes.md +7 -0
- package/templates/core/core_facts.md +10 -0
- package/templates/core/memory-tools.md +43 -0
- package/templates/core/user_profile.md +7 -0
- package/templates/with-abmind-hooks.json +26 -0
- package/dist/cli/abmind-backfill.d.ts +0 -3
- package/dist/cli/abmind-backfill.d.ts.map +0 -1
- package/dist/cli/abmind-backfill.js +0 -64
- package/dist/cli/abmind-backfill.js.map +0 -1
- package/dist/cli/abmind-memory-stats.d.ts +0 -3
- package/dist/cli/abmind-memory-stats.d.ts.map +0 -1
- package/dist/cli/abmind-memory-stats.js +0 -45
- package/dist/cli/abmind-memory-stats.js.map +0 -1
- package/dist/cli/abmind-reset.d.ts +0 -11
- package/dist/cli/abmind-reset.d.ts.map +0 -1
- package/dist/cli/abmind-reset.js +0 -143
- package/dist/cli/abmind-reset.js.map +0 -1
- package/dist/cli/abmind-status.d.ts +0 -3
- package/dist/cli/abmind-status.d.ts.map +0 -1
- package/dist/cli/abmind-status.js +0 -45
- package/dist/cli/abmind-status.js.map +0 -1
- package/prompts/sleep/03-extract-from-daily.md +0 -3
- package/prompts/sleep/04-retrospective.md +0 -30
- package/prompts/sleep/07-topic-assignment.md +0 -23
- package/prompts/sleep/08-core-promotion.md +0 -26
- package/prompts/sleep/09-merge.md +0 -19
- package/prompts/sleep/12-core-knowledge.md +0 -14
- package/prompts/sleep/14-emotion-context.md +0 -17
- /package/prompts/sleep/{15-contradiction-and-graph.md → 05-contradiction-and-graph.md} +0 -0
- /package/prompts/sleep/{06-feedback.md → 07-feedback.md} +0 -0
- /package/prompts/sleep/{10-translation.md → 09-translation.md} +0 -0
- /package/prompts/sleep/{11-skill-review.md → 10-skill-review.md} +0 -0
- /package/prompts/sleep/{16-rem-synthesis.md → 12-rem-synthesis.md} +0 -0
|
@@ -1,83 +1,151 @@
|
|
|
1
1
|
import { localTime, localDateTime } from "./local-time.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { getAbmindEnv } from "./env-schema.js";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
5
|
+
export const SESSION_HISTORY_MIN_MSGS = 8;
|
|
4
6
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
+
* Build session-start context for injection after /new, /reset, or restart.
|
|
8
|
+
* Budget-based interleaved fill: dailies + recent messages (#615).
|
|
7
9
|
*/
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
export function buildSessionStartContext(memory, userId, maxContext, opts) {
|
|
11
|
+
const env = getAbmindEnv();
|
|
12
|
+
const ctxWindow = maxContext ?? 128000;
|
|
13
|
+
const pct = parseFloat(process.env["SESSION_HISTORY_PCT"] ?? "3");
|
|
14
|
+
const minMsgs = parseInt(process.env["SESSION_HISTORY_MIN_MSGS"] ?? "8", 10);
|
|
15
|
+
const cap = parseInt(process.env["SESSION_HISTORY_CAP"] ?? "25000", 10);
|
|
16
|
+
const budget = Math.min(Math.floor(ctxWindow * pct / 100), cap);
|
|
17
|
+
// --- Load sources ---
|
|
18
|
+
let recentRows = loadRecentUserMessages(memory, minMsgs + 50); // fetch extra for enrichment
|
|
19
|
+
// Age filter (Code sessions — discard messages older than maxAgeMs)
|
|
20
|
+
if (opts?.maxAgeMs) {
|
|
21
|
+
const cutoff = Date.now() - opts.maxAgeMs;
|
|
22
|
+
recentRows = recentRows.filter(r => r.timestamp >= cutoff);
|
|
23
|
+
}
|
|
24
|
+
const dailies = opts?.skipDailies ? [] : loadDailySummaries(memory.getConfig().memoryDir, 14);
|
|
25
|
+
// --- Floor: 1 daily + min messages (always included) ---
|
|
26
|
+
const recentBucket = [];
|
|
27
|
+
const dailyBucket = [];
|
|
28
|
+
// Floor messages — take NEWEST (last N elements, since recentRows is oldest-first after reverse+filter)
|
|
29
|
+
const floorStart = Math.max(0, recentRows.length - minMsgs);
|
|
30
|
+
for (let i = floorStart; i < recentRows.length; i++) {
|
|
31
|
+
recentBucket.push(formatMessage(recentRows[i]));
|
|
32
|
+
}
|
|
33
|
+
// Floor daily
|
|
34
|
+
if (dailies.length > 0) {
|
|
35
|
+
dailyBucket.push(dailies[0].content);
|
|
36
|
+
}
|
|
37
|
+
let used = recentBucket.join("\n").length + dailyBucket.join("\n").length;
|
|
38
|
+
// --- Enrichment cycle: fill BACKWARD (older messages) + forward (older dailies) within budget ---
|
|
39
|
+
let msgCursor = floorStart - 1;
|
|
40
|
+
let dailyCursor = 1;
|
|
41
|
+
while (used < budget) {
|
|
42
|
+
let added = false;
|
|
43
|
+
if (msgCursor >= 0) {
|
|
44
|
+
const line = formatMessage(recentRows[msgCursor]);
|
|
45
|
+
if (used + line.length <= budget) {
|
|
46
|
+
recentBucket.unshift(line); // prepend to maintain chronological order
|
|
47
|
+
used += line.length;
|
|
48
|
+
msgCursor--;
|
|
49
|
+
added = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (dailyCursor < dailies.length) {
|
|
53
|
+
const entry = dailies[dailyCursor].content;
|
|
54
|
+
if (used + entry.length <= budget) {
|
|
55
|
+
dailyBucket.push(entry);
|
|
56
|
+
used += entry.length;
|
|
57
|
+
dailyCursor++;
|
|
58
|
+
added = true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!added)
|
|
19
62
|
break;
|
|
20
|
-
lines.shift();
|
|
21
63
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* Build session-start context for injection after /new, /reset, or restart.
|
|
26
|
-
* Returns the latest daily summary, or recent messages if no daily covers the gap.
|
|
27
|
-
* Wrapped in REQ-4 temporal markers.
|
|
28
|
-
*/
|
|
29
|
-
export function buildSessionStartContext(memory, userId) {
|
|
30
|
-
const daily = memory.getLatestCompaction(userId);
|
|
31
|
-
const dailyTs = daily?.timestamp ?? 0;
|
|
32
|
-
const lastMsgTs = memory.store?.getLastMessageTimestamp() ?? 0;
|
|
64
|
+
// --- Assemble: clean separation, temporal order ---
|
|
65
|
+
if (recentBucket.length === 0 && dailyBucket.length === 0)
|
|
66
|
+
return null;
|
|
33
67
|
const now = localDateTime(new Date());
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
endedAt = localDateTime(new Date(lastMsgTs));
|
|
68
|
+
const lastMsgTs = recentRows.length > 0 ? recentRows[recentRows.length - 1].timestamp : Date.now();
|
|
69
|
+
const endedAt = localDateTime(new Date(lastMsgTs));
|
|
70
|
+
const parts = [];
|
|
71
|
+
if (dailyBucket.length > 0) {
|
|
72
|
+
parts.push("[PAST DAYS]\n" + dailyBucket.join("\n\n"));
|
|
40
73
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
endedAt = localDateTime(new Date(dailyTs));
|
|
74
|
+
if (recentBucket.length > 0) {
|
|
75
|
+
parts.push(`[RECENT — last session, ended ${endedAt}]\n` + recentBucket.join("\n"));
|
|
44
76
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
77
|
+
// Emotional tone
|
|
78
|
+
const tone = getEmotionalTone(memory, userId);
|
|
79
|
+
if (tone)
|
|
80
|
+
parts.push(tone);
|
|
81
|
+
parts.push(`[SESSION START — ${now}]`);
|
|
82
|
+
return parts.join("\n\n");
|
|
83
|
+
}
|
|
84
|
+
function formatMessage(row) {
|
|
85
|
+
const time = localTime(new Date(row.timestamp));
|
|
86
|
+
return `[${time}] ${row.content}`;
|
|
87
|
+
}
|
|
88
|
+
function loadRecentUserMessages(memory, limit) {
|
|
89
|
+
if (!memory.store)
|
|
90
|
+
return [];
|
|
91
|
+
try {
|
|
92
|
+
const rows = memory.store.getMessagesSince(0, limit);
|
|
93
|
+
// getMessagesSince returns oldest first — reverse for newest first, filter to user only
|
|
94
|
+
return [...rows].reverse().filter(r => r.role === "user" && r.content.trim());
|
|
49
95
|
}
|
|
50
|
-
|
|
51
|
-
return
|
|
96
|
+
catch {
|
|
97
|
+
return [];
|
|
52
98
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
99
|
+
}
|
|
100
|
+
function loadDailySummaries(memoryDir, days) {
|
|
101
|
+
const dir = join(memoryDir, "daily");
|
|
102
|
+
try {
|
|
103
|
+
const files = readdirSync(dir).filter(f => f.endsWith(".md")).sort().reverse(); // newest first
|
|
104
|
+
const cutoff = Date.now() - days * 86_400_000;
|
|
105
|
+
const results = [];
|
|
106
|
+
for (const file of files) {
|
|
107
|
+
const m = file.match(/daily_(\d{4})-(\d{2})-(\d{2})\.md/);
|
|
108
|
+
if (!m)
|
|
109
|
+
continue;
|
|
110
|
+
const ts = new Date(`${m[1]}-${m[2]}-${m[3]}T00:00:00Z`).getTime();
|
|
111
|
+
if (ts < cutoff)
|
|
112
|
+
break;
|
|
113
|
+
const content = readFileSync(join(dir, file), "utf-8").trim();
|
|
114
|
+
if (content)
|
|
115
|
+
results.push({ timestamp: ts, content });
|
|
116
|
+
}
|
|
117
|
+
return results;
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function getEmotionalTone(memory, userId) {
|
|
57
124
|
try {
|
|
58
125
|
const db = memory.getDatabase();
|
|
59
|
-
if (db)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const top = [...tagCounts.entries()].sort((a, b) => b[1] - a[1]).slice(0, 3).map(([t]) => t);
|
|
73
|
-
const contexts = rows.map(r => r.emotion_context).filter(Boolean).slice(0, 2);
|
|
74
|
-
if (top.length > 0) {
|
|
75
|
-
emotionalTone = `\n[Last session tone: ${top.join(", ")}${contexts.length > 0 ? ` (${contexts.join("; ")})` : ""}]`;
|
|
76
|
-
}
|
|
126
|
+
if (!db)
|
|
127
|
+
return null;
|
|
128
|
+
const rows = db.prepare(`SELECT emotion_tags, emotion_context FROM extracted_memories
|
|
129
|
+
WHERE user_id = ? AND emotion_tags IS NOT NULL AND emotion_tags != ''
|
|
130
|
+
ORDER BY created_at DESC LIMIT 5`).all(userId);
|
|
131
|
+
if (rows.length === 0)
|
|
132
|
+
return null;
|
|
133
|
+
const tagCounts = new Map();
|
|
134
|
+
for (const r of rows) {
|
|
135
|
+
for (const t of r.emotion_tags.split(",")) {
|
|
136
|
+
const tag = t.trim();
|
|
137
|
+
if (tag)
|
|
138
|
+
tagCounts.set(tag, (tagCounts.get(tag) ?? 0) + 1);
|
|
77
139
|
}
|
|
78
140
|
}
|
|
141
|
+
const top = [...tagCounts.entries()].sort((a, b) => b[1] - a[1]).slice(0, 3).map(([t]) => t);
|
|
142
|
+
const contexts = rows.map(r => r.emotion_context).filter(Boolean).slice(0, 2);
|
|
143
|
+
if (top.length === 0)
|
|
144
|
+
return null;
|
|
145
|
+
return `[Last session tone: ${top.join(", ")}${contexts.length > 0 ? ` (${contexts.join("; ")})` : ""}]`;
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return null;
|
|
79
149
|
}
|
|
80
|
-
catch { /* */ }
|
|
81
|
-
return `[LAST SESSION SUMMARY — ended ${endedAt}]\n${body}${emotionalTone}\n[SESSION START — ${now}]`;
|
|
82
150
|
}
|
|
83
151
|
//# sourceMappingURL=session-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-context.js","sourceRoot":"","sources":["../../src/session-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"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,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC;IAC3G,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,IAAI,CAAC;IAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* - basic: 1 LLM call. Single-shot combined prompt. Frontier-model-only.
|
|
5
5
|
* Prompt: prompts/sleep/basic.md. Emits ===DAILY=== + ===MEMORIES===.
|
|
6
|
-
* - budget: ~3
|
|
7
|
-
* - normal: ~
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* - budget: ~3 calls daily, ~5 on curation day (adds retro + derive).
|
|
7
|
+
* - normal: ~7 calls daily, ~15 on curation day. Default.
|
|
8
|
+
* Daily: gc-noise, daily-summary, retrospective, extract-memories,
|
|
9
|
+
* retro-derive, feedback, contradiction+graph.
|
|
10
|
+
* Curation adds: topic-assignment, core-promotion, merge, translation,
|
|
11
|
+
* skill-review, consolidation, emotion-context, rem-synthesis.
|
|
12
|
+
* - ultimate: ~15 calls every night. All steps, no weekly gating.
|
|
12
13
|
*
|
|
13
14
|
* See docs/plans/163-sleep-to-abmind.md for audience + tradeoff notes.
|
|
14
15
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"levels.d.ts","sourceRoot":"","sources":["../../../src/sleep/levels.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"levels.d.ts","sourceRoot":"","sources":["../../../src/sleep/levels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;AAI1E,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,CAI3C;AAED,kFAAkF;AAClF,eAAO,MAAM,aAAa,EAAE,KAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"levels.js","sourceRoot":"","sources":["../../../src/sleep/levels.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"levels.js","sourceRoot":"","sources":["../../../src/sleep/levels.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,GAAqB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAU,CAAC;AAE9F,0DAA0D;AAC1D,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,MAAM,KAAK,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC9B,IAAK,MAA4B,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAc,CAAC;IACzE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,wBAAwB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxF,CAAC;AAED,kFAAkF;AAClF,MAAM,CAAC,MAAM,aAAa,GAAU,QAAQ,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Called via runSleepCycle({ runtime, level, ... }). Gathers system state,
|
|
6
6
|
* runs through a pipeline of prompt-driven steps (gc-noise, daily-summary,
|
|
7
|
-
* extract-
|
|
7
|
+
* extract-memories, retrospective, retro-derive, etc.), persists audit log, returns result.
|
|
8
8
|
*
|
|
9
9
|
* Library-only — no CLI entry point here. Standalone entry lives in
|
|
10
10
|
* cli/abmind-sleep.ts.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../../src/sleep/orchestrator.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG;AAoBH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,C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;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAE5E,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAmBjD;AAmdD;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAomBrE"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Called via runSleepCycle({ runtime, level, ... }). Gathers system state,
|
|
6
6
|
* runs through a pipeline of prompt-driven steps (gc-noise, daily-summary,
|
|
7
|
-
* extract-
|
|
7
|
+
* extract-memories, retrospective, retro-derive, etc.), persists audit log, returns result.
|
|
8
8
|
*
|
|
9
9
|
* Library-only — no CLI entry point here. Standalone entry lives in
|
|
10
10
|
* cli/abmind-sleep.ts.
|
|
@@ -42,7 +42,7 @@ function toIsoDate(ts) {
|
|
|
42
42
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
43
43
|
}
|
|
44
44
|
/** Steps whose failure blocks watermark advance. Public so tests can derive reject targets. */
|
|
45
|
-
export const ESSENTIAL_STEPS = new Set(["daily-summary", "extract-
|
|
45
|
+
export const ESSENTIAL_STEPS = new Set(["daily-summary", "extract-memories", "retrospective"]);
|
|
46
46
|
const CATCHUP_MAX_AGE_DAYS = 3;
|
|
47
47
|
/** Thrown by runSleepCycle when memory layer fails to initialize. */
|
|
48
48
|
export class SleepInitError extends Error {
|
|
@@ -401,12 +401,12 @@ async function runCatchUp(locks, sleepData, memoryConfig, steps, flags, runtime,
|
|
|
401
401
|
}
|
|
402
402
|
writeStateFile(lock.path, lock.state);
|
|
403
403
|
}
|
|
404
|
-
// 04b — extract from daily (needs daily file to exist)
|
|
405
|
-
if (needed.includes("extract-
|
|
404
|
+
// 04b — extract memories from daily (needs daily file to exist)
|
|
405
|
+
if (needed.includes("extract-memories")) {
|
|
406
406
|
const dailyPath = join(memoryConfig.memoryDir, "daily", `daily_${dateStrToFormatted(lock.dateStr)}.md`);
|
|
407
407
|
if (!existsSync(dailyPath)) {
|
|
408
408
|
logInfo(TAG, `[CATCH-UP] ⏭ 04b — no daily file for ${lock.dateStr}`);
|
|
409
|
-
lock.state.steps["extract-
|
|
409
|
+
lock.state.steps["extract-memories"] = { status: "skipped" };
|
|
410
410
|
}
|
|
411
411
|
else {
|
|
412
412
|
const start = Date.now();
|
|
@@ -414,12 +414,12 @@ async function runCatchUp(locks, sleepData, memoryConfig, steps, flags, runtime,
|
|
|
414
414
|
const userId = sleepData.getPrimaryUserId();
|
|
415
415
|
const result = await extractFromDaily(dailyPath, userId, (p) => sendWithRetry(runtime, p, "catch-up-04b", flags.verbose, budget).then(r => { if (r === null)
|
|
416
416
|
throw new LLMUnavailableError(); return r; }));
|
|
417
|
-
lock.state.steps["extract-
|
|
418
|
-
logInfo(TAG, `[CATCH-UP] ✓ 04b-extract-
|
|
417
|
+
lock.state.steps["extract-memories"] = { status: "ok", duration: Math.round((Date.now() - start) / 100) / 10 };
|
|
418
|
+
logInfo(TAG, `[CATCH-UP] ✓ 04b-extract-memories for ${lock.dateStr} (${((Date.now() - start) / 1000).toFixed(1)}s) — ${result.slice(0, 80)}`);
|
|
419
419
|
}
|
|
420
420
|
catch (err) {
|
|
421
421
|
logWarn(TAG, `[CATCH-UP] ✗ 04b for ${lock.dateStr}: ${err instanceof Error ? err.message : String(err)}`);
|
|
422
|
-
lock.state.steps["extract-
|
|
422
|
+
lock.state.steps["extract-memories"] = { status: "failed", duration: Math.round((Date.now() - start) / 100) / 10 };
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
425
|
writeStateFile(lock.path, lock.state);
|
|
@@ -485,6 +485,11 @@ export async function runSleepCycle(opts) {
|
|
|
485
485
|
try {
|
|
486
486
|
const sleepData = memory.getSleepData();
|
|
487
487
|
const db = memory.db; // access DB for meta writes
|
|
488
|
+
// TTL: clean ephemeral system/agent messages older than 24h
|
|
489
|
+
try {
|
|
490
|
+
db.prepare("DELETE FROM messages WHERE user_id IN ('system', 'agent') AND timestamp < ?").run(Date.now() - 86_400_000);
|
|
491
|
+
}
|
|
492
|
+
catch { /* */ }
|
|
488
493
|
const { metaSet, metaIncrement, metaGetInt } = await import("../meta-store.js");
|
|
489
494
|
// Record attempt
|
|
490
495
|
metaSet(db, "sleep_last_attempt_ts", Date.now());
|
|
@@ -532,7 +537,7 @@ export async function runSleepCycle(opts) {
|
|
|
532
537
|
const wiredResults = await runWiredPreTasks(sleepData, memoryConfig.memoryDir, memory);
|
|
533
538
|
logInfo(TAG, `[SLEEP] Wired: ${formatWiredResults(wiredResults)}`);
|
|
534
539
|
// Build candidate lists for conditional prompts
|
|
535
|
-
const candidates = sleepData.buildSleepCandidates();
|
|
540
|
+
const candidates = sleepData.buildSleepCandidates(getAbmindEnv().sleepModelName ?? "unknown");
|
|
536
541
|
logInfo(TAG, `[SLEEP] Candidates: topics=${candidates.untaggedMemories ? "yes" : "none"}, promote=${candidates.promotionCandidates ? "yes" : "none"}, contradict=${candidates.contradictions ? "yes" : "none"}, merge=${candidates.mergeCandidates ? "yes" : "none"}, translate=${candidates.translationIssues ? "yes" : "none"}, emotion-ctx=${candidates.emotionContextGaps ? "yes" : "none"}, feedback=${candidates.recallFeedback ? "yes" : "none"}`);
|
|
537
542
|
// Load step files + build vars
|
|
538
543
|
const vars = buildSleepVars(snapshot);
|
|
@@ -563,7 +568,7 @@ export async function runSleepCycle(opts) {
|
|
|
563
568
|
}
|
|
564
569
|
}
|
|
565
570
|
catch { /* no garbage file */ }
|
|
566
|
-
const msgs = sleepData.getMessagesAfter(lastSleepTs);
|
|
571
|
+
const msgs = sleepData.getMessagesAfter(lastSleepTs, sleepData.getPrimaryUserId());
|
|
567
572
|
const lines = msgs
|
|
568
573
|
.filter(m => !garbageIds.has(m.id) && !m.content.startsWith("[SYSTEM"))
|
|
569
574
|
.map(m => `[${m.role}]${m.emotion_score ? ` (emotion:${m.emotion_score})` : ""} ${m.content.slice(0, 500)}`);
|
|
@@ -578,6 +583,7 @@ export async function runSleepCycle(opts) {
|
|
|
578
583
|
// Set remaining missing vars
|
|
579
584
|
vars.MESSAGES_SINCE_WATERMARK = vars.CLEAN_MESSAGES; // same data, different name for gc-noise
|
|
580
585
|
vars.RETRO_PATH = join(memoryConfig.memoryDir, "daily", `daily_${toIsoDate(now())}.md`);
|
|
586
|
+
vars.DAILY_PATH = vars.RETRO_PATH; // step 03 appends retro to the daily file
|
|
581
587
|
try {
|
|
582
588
|
const { getLatestConsolidationFile } = await import("../consolidation-search.js");
|
|
583
589
|
const latest = getLatestConsolidationFile(memoryConfig.memoryDir, "weekly");
|
|
@@ -586,6 +592,20 @@ export async function runSleepCycle(opts) {
|
|
|
586
592
|
catch {
|
|
587
593
|
vars.CONSOLIDATION_PATH = "No consolidation files yet.";
|
|
588
594
|
}
|
|
595
|
+
// Output path for consolidation — weekly or quarterly
|
|
596
|
+
const todayIso = new Date(now()).toISOString().slice(0, 10); // YYYY-MM-DD
|
|
597
|
+
const weeklyDir = join(memoryConfig.memoryDir, "weekly");
|
|
598
|
+
const quarterlyDir = join(memoryConfig.memoryDir, "quarterly");
|
|
599
|
+
mkdirSync(weeklyDir, { recursive: true });
|
|
600
|
+
mkdirSync(quarterlyDir, { recursive: true });
|
|
601
|
+
const month = new Date(now()).getMonth(); // 0-based
|
|
602
|
+
const isQuarterBoundary = month % 3 === 0 && new Date(now()).getDate() <= 7;
|
|
603
|
+
if (isQuarterBoundary) {
|
|
604
|
+
vars.CONSOLIDATION_OUTPUT_PATH = join(quarterlyDir, `quarterly_${todayIso}.md`);
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
vars.CONSOLIDATION_OUTPUT_PATH = join(weeklyDir, `weekly_${todayIso}.md`);
|
|
608
|
+
}
|
|
589
609
|
const steps = loadSleepSteps();
|
|
590
610
|
// Merge snapshot vars + bridge vars into one map for JIT substitution
|
|
591
611
|
const snapshotVars = buildSleepVars(snapshot);
|
|
@@ -611,56 +631,50 @@ export async function runSleepCycle(opts) {
|
|
|
611
631
|
const curationDay = getAbmindEnv().sleepCurationDay;
|
|
612
632
|
const today = new Date(now()).toLocaleDateString("en", { weekday: "long" }).toLowerCase();
|
|
613
633
|
const isCurationDay = today === curationDay;
|
|
614
|
-
const BUDGET_ONLY = new Set(["gc-noise", "daily-summary", "extract-
|
|
615
|
-
const
|
|
616
|
-
const
|
|
617
|
-
|
|
634
|
+
const BUDGET_ONLY = new Set(["gc-noise", "daily-summary", "extract-memories"]);
|
|
635
|
+
const BUDGET_CURATION = new Set([...BUDGET_ONLY, "retrospective", "retro-derive"]);
|
|
636
|
+
const WEEKLY_ONLY = new Set(["memory-maintenance", "translation",
|
|
637
|
+
"skill-review", "consolidation", "rem-synthesis"]);
|
|
638
|
+
if (quality === "budget" && !isCurationDay) {
|
|
618
639
|
for (const step of steps) {
|
|
619
640
|
if (!BUDGET_ONLY.has(step.name))
|
|
620
641
|
skipSet.add(step.name);
|
|
621
642
|
}
|
|
622
643
|
logInfo(TAG, `[SLEEP] Quality=budget — only essential extraction`);
|
|
623
644
|
}
|
|
645
|
+
else if (quality === "budget" && isCurationDay) {
|
|
646
|
+
for (const step of steps) {
|
|
647
|
+
if (!BUDGET_CURATION.has(step.name))
|
|
648
|
+
skipSet.add(step.name);
|
|
649
|
+
}
|
|
650
|
+
logInfo(TAG, `[SLEEP] Quality=budget (curation day) — adds retro + derive`);
|
|
651
|
+
}
|
|
624
652
|
else if (quality === "normal" && !isCurationDay) {
|
|
625
653
|
for (const name of WEEKLY_ONLY)
|
|
626
654
|
skipSet.add(name);
|
|
627
|
-
|
|
628
|
-
skipSet.add(name);
|
|
629
|
-
logInfo(TAG, `[SLEEP] Quality=normal — weekly + ultimate prompts skipped (curation day: ${curationDay})`);
|
|
655
|
+
logInfo(TAG, `[SLEEP] Quality=normal — weekly prompts skipped (curation day: ${curationDay})`);
|
|
630
656
|
}
|
|
631
657
|
else if (quality === "normal" && isCurationDay) {
|
|
632
|
-
|
|
633
|
-
skipSet.add(name);
|
|
634
|
-
logInfo(TAG, `[SLEEP] Quality=normal (curation day) — ultimate prompts skipped`);
|
|
658
|
+
logInfo(TAG, `[SLEEP] Quality=normal (curation day) — all steps`);
|
|
635
659
|
}
|
|
636
660
|
else {
|
|
637
|
-
// ultimate:
|
|
638
|
-
if (!isCurationDay)
|
|
639
|
-
skipSet.add("rem-synthesis");
|
|
661
|
+
// ultimate: all steps every night
|
|
640
662
|
logInfo(TAG, `[SLEEP] Quality=${quality}${isCurationDay ? " (curation day)" : ""} — all eligible`);
|
|
641
663
|
}
|
|
642
664
|
// Candidate-driven skips (empty = nothing to do)
|
|
643
665
|
if (!candidates.recallFeedback)
|
|
644
666
|
skipSet.add("feedback");
|
|
645
|
-
if
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
if (!candidates.mergeCandidates)
|
|
650
|
-
skipSet.add("merge");
|
|
651
|
-
if (!candidates.translationIssues)
|
|
652
|
-
skipSet.add("translation-check");
|
|
667
|
+
// memory-maintenance: skip if ALL three inputs are empty
|
|
668
|
+
if (!candidates.untaggedMemories && !candidates.mergeCandidates && !candidates.emotionContextGaps)
|
|
669
|
+
skipSet.add("memory-maintenance");
|
|
670
|
+
// promotion candidates are optional input to retro-derive — don't skip the step for it
|
|
653
671
|
if (!candidates.translationIssues)
|
|
654
672
|
skipSet.add("translation");
|
|
655
|
-
if (!candidates.emotionContextGaps)
|
|
656
|
-
skipSet.add("emotion-context");
|
|
657
|
-
if (!candidates.emotionContextGaps)
|
|
658
|
-
skipSet.add("emotion-context-backfill");
|
|
659
673
|
// Legacy skip names (old prompt files)
|
|
660
674
|
if (snapshot.topicFiles.length === 0)
|
|
661
675
|
skipSet.add("topic-reorg");
|
|
662
676
|
if (snapshot.dbStats.extractedMemoryCount < 10) {
|
|
663
|
-
skipSet.add("
|
|
677
|
+
skipSet.add("memory-maintenance");
|
|
664
678
|
skipSet.add("darwinism");
|
|
665
679
|
}
|
|
666
680
|
if (snapshot.dbStats.extractedMemoryCount < 20)
|
|
@@ -699,6 +713,11 @@ export async function runSleepCycle(opts) {
|
|
|
699
713
|
let dailySummaryPath = null;
|
|
700
714
|
try {
|
|
701
715
|
// ── LLM call budget (hard safety limit) ──
|
|
716
|
+
// On resume: reset llmCalls to completed step count (don't carry stale counter)
|
|
717
|
+
if (isResume) {
|
|
718
|
+
const completedCount = Object.values(state.steps).filter(s => s.status === "ok").length;
|
|
719
|
+
state.llmCalls = completedCount;
|
|
720
|
+
}
|
|
702
721
|
const budget = new LlmBudget(state, statePath);
|
|
703
722
|
// ── Catch-up: recover failed essentials from previous days ──
|
|
704
723
|
const sleepDir = join(memoryConfig.memoryDir, "sleep");
|
|
@@ -707,6 +726,29 @@ export async function runSleepCycle(opts) {
|
|
|
707
726
|
logInfo(TAG, `[CATCH-UP] Found ${previousLocks.length} previous lock(s)`);
|
|
708
727
|
await runCatchUp(previousLocks, sleepData, memoryConfig, steps, flags, runtime, budget);
|
|
709
728
|
}
|
|
729
|
+
// Housekeeping: move misplaced daily/consolidation_* to weekly/ (#640)
|
|
730
|
+
try {
|
|
731
|
+
const dailyDir = join(memoryConfig.memoryDir, "daily");
|
|
732
|
+
if (existsSync(dailyDir)) {
|
|
733
|
+
for (const f of readdirSync(dailyDir).filter(fn => fn.startsWith("consolidation_"))) {
|
|
734
|
+
const m = f.match(/consolidation_(\d{4})-(\d{2})-week(\d)/);
|
|
735
|
+
if (m) {
|
|
736
|
+
const [, year, month, week] = m;
|
|
737
|
+
const day = (parseInt(week) - 1) * 7 + 1;
|
|
738
|
+
const approxDate = `${year}-${month}-${String(Math.min(day, 28)).padStart(2, "0")}`;
|
|
739
|
+
const dest = join(weeklyDir, `weekly_${approxDate}.md`);
|
|
740
|
+
if (!existsSync(dest)) {
|
|
741
|
+
const { renameSync } = await import("node:fs");
|
|
742
|
+
renameSync(join(dailyDir, f), dest);
|
|
743
|
+
logInfo(TAG, `[HOUSEKEEPING] Moved ${f} → weekly_${approxDate}.md`);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
catch (err) {
|
|
750
|
+
logWarn(TAG, `[HOUSEKEEPING] consolidation migration failed: ${err}`);
|
|
751
|
+
}
|
|
710
752
|
emitProgress("starting");
|
|
711
753
|
let consecutiveFailures = 0;
|
|
712
754
|
// Create day directory for per-step logs
|
|
@@ -779,10 +821,10 @@ export async function runSleepCycle(opts) {
|
|
|
779
821
|
logInfo(TAG, `[SLEEP] ${state.steps[step.name]?.status === "ok" ? "✓" : "✗"} ${step.name} (${((Date.now() - start) / 1000).toFixed(1)}s)`);
|
|
780
822
|
continue;
|
|
781
823
|
}
|
|
782
|
-
if (step.name === "extract-
|
|
824
|
+
if (step.name === "extract-memories") {
|
|
783
825
|
// Resume path: if daily-summary already completed in a prior run, the
|
|
784
826
|
// in-memory dailySummaryPath is null. Recover it from the lock's
|
|
785
|
-
// recorded path so extract-
|
|
827
|
+
// recorded path so extract-memories can still run. #181.
|
|
786
828
|
if (!dailySummaryPath) {
|
|
787
829
|
const priorPath = state.steps["daily-summary"]?.path;
|
|
788
830
|
if (priorPath && existsSync(priorPath)) {
|