toon-memory 2.8.0 → 2.9.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/README.md +2 -2
- package/dist/cli/capture.js +41 -10
- package/dist/cli/session-start.js +6 -6
- package/dist/cli/setup.js +36 -33
- package/mcp/server.js +269 -252
- package/package.json +2 -2
- package/src/cli/agents.ts +8 -5
- package/src/cli/capture-toggle.ts +4 -4
- package/src/cli/capture.ts +5 -0
- package/src/cli/commands.ts +15 -15
- package/src/cli/constants.ts +1 -1
- package/src/cli/session-start.ts +6 -6
- package/src/cli/setup.ts +8 -8
- package/src/lib/context.ts +78 -57
- package/src/lib/quality.ts +16 -11
- package/src/mcp/archive.ts +5 -4
- package/src/mcp/config.ts +9 -1
- package/src/mcp/observations.ts +28 -1
- package/src/mcp/resources.ts +3 -3
- package/src/mcp/scoring.ts +3 -6
- package/src/mcp/tools.ts +179 -187
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ Read [How toon-memory Makes Your AI Agent Smarter](https://luiggival08.github.io
|
|
|
61
61
|
|
|
62
62
|
## Features
|
|
63
63
|
|
|
64
|
-
- **
|
|
64
|
+
- **21 MCP tools** — Full memory management via Model Context Protocol, including `memory_smart_recall` (unified recall), `memory_sessions` for multi-session coordination, and `context_*` tools for one-call context generation (briefing, diff, focus, health audit, export)
|
|
65
65
|
- **MCP Resources** — Read memory as context without tool invocations, including a System Primer (auto-generated knowledge map)
|
|
66
66
|
- **15 agents supported** — OpenCode, VS Code, Claude Code, Cursor, Windsurf, Cline, Continue, Codex CLI, Gemini CLI, Zed, Antigravity, Aider, KiloCode, OpenClaw, Kiro
|
|
67
67
|
- **Interactive installer** — Select which agents to configure from a menu
|
|
@@ -1156,7 +1156,7 @@ toon-memory/
|
|
|
1156
1156
|
│ │ ├── setup.ts # CLI commands
|
|
1157
1157
|
│ │ └── toon-memory.ts # CLI runner
|
|
1158
1158
|
│ ├── mcp/
|
|
1159
|
-
│ │ └── server.ts # MCP server (
|
|
1159
|
+
│ │ └── server.ts # MCP server (21 tools + 3 resources)
|
|
1160
1160
|
│ ├── lib/
|
|
1161
1161
|
│ │ ├── lock.ts # Advisory file lock + atomic write
|
|
1162
1162
|
│ │ ├── sessions.ts # Multi-session coordination
|
package/dist/cli/capture.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/cli/capture.ts
|
|
2
|
-
import { readFileSync as
|
|
3
|
-
import { join as
|
|
2
|
+
import { readFileSync as readFileSync4, existsSync as existsSync4, mkdirSync as mkdirSync2 } from "fs";
|
|
3
|
+
import { join as join3 } from "path";
|
|
4
4
|
import { createHash } from "crypto";
|
|
5
5
|
|
|
6
6
|
// src/lib/lock.ts
|
|
@@ -171,15 +171,45 @@ function endSession(agent, sessionId) {
|
|
|
171
171
|
heartbeat(agent, sessionId, { ended: true });
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
// src/
|
|
174
|
+
// src/mcp/observations.ts
|
|
175
|
+
import { readFileSync as readFileSync3, existsSync as existsSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
176
|
+
|
|
177
|
+
// src/mcp/config.ts
|
|
178
|
+
import { join as join2 } from "path";
|
|
175
179
|
var MEMORY_DIR = join2(process.cwd(), ".toon-memory", "memory");
|
|
180
|
+
var MEMORY_FILE = join2(MEMORY_DIR, "data.toon");
|
|
181
|
+
var ARCHIVE_FILE = join2(MEMORY_DIR, "archive.toon");
|
|
176
182
|
var OBSERVATIONS_FILE = join2(MEMORY_DIR, "observations.toon");
|
|
177
183
|
var CONFIG_FILE = join2(MEMORY_DIR, "config.json");
|
|
184
|
+
|
|
185
|
+
// src/mcp/observations.ts
|
|
186
|
+
var MAX_OBSERVATIONS = 500;
|
|
187
|
+
function pruneObservations() {
|
|
188
|
+
if (!existsSync3(OBSERVATIONS_FILE)) return 0;
|
|
189
|
+
const data = readFileSync3(OBSERVATIONS_FILE, "utf-8");
|
|
190
|
+
const lines = data.split("\n");
|
|
191
|
+
const headerIdx = lines.findIndex((l) => l.startsWith("observations["));
|
|
192
|
+
if (headerIdx === -1) return 0;
|
|
193
|
+
const entryLines = lines.slice(headerIdx + 1).filter((l) => l.trim().length > 0);
|
|
194
|
+
if (entryLines.length <= MAX_OBSERVATIONS) return 0;
|
|
195
|
+
const toRemove = entryLines.length - MAX_OBSERVATIONS;
|
|
196
|
+
const pruned = entryLines.slice(toRemove);
|
|
197
|
+
const kept = entryLines.slice(0, MAX_OBSERVATIONS);
|
|
198
|
+
lines[headerIdx] = lines[headerIdx].replace(/\[\d+\|/, `[${kept.length}|`);
|
|
199
|
+
lines.splice(headerIdx + 1, lines.length - headerIdx - 1, ...kept.map((l) => ` ${l.trim()}`));
|
|
200
|
+
writeFileSync3(OBSERVATIONS_FILE, lines.join("\n"));
|
|
201
|
+
return toRemove;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/cli/capture.ts
|
|
205
|
+
var MEMORY_DIR2 = join3(process.cwd(), ".toon-memory", "memory");
|
|
206
|
+
var OBSERVATIONS_FILE2 = join3(MEMORY_DIR2, "observations.toon");
|
|
207
|
+
var CONFIG_FILE2 = join3(MEMORY_DIR2, "config.json");
|
|
178
208
|
var DEDUP_WINDOW_MS = 5 * 60 * 1e3;
|
|
179
209
|
function captureEnabled() {
|
|
180
210
|
if (process.env.TOON_MEMORY_CAPTURE) return true;
|
|
181
211
|
try {
|
|
182
|
-
const cfg = JSON.parse(
|
|
212
|
+
const cfg = JSON.parse(readFileSync4(CONFIG_FILE2, "utf-8"));
|
|
183
213
|
if (cfg && cfg.capture) return true;
|
|
184
214
|
} catch {
|
|
185
215
|
}
|
|
@@ -218,11 +248,11 @@ function derive(tool, input) {
|
|
|
218
248
|
return { file: String(file || "").trim(), summary };
|
|
219
249
|
}
|
|
220
250
|
function ensureMemoryDir() {
|
|
221
|
-
if (!
|
|
251
|
+
if (!existsSync4(MEMORY_DIR2)) mkdirSync2(MEMORY_DIR2, { recursive: true });
|
|
222
252
|
}
|
|
223
253
|
function appendObservation(row) {
|
|
224
254
|
ensureMemoryDir();
|
|
225
|
-
let data =
|
|
255
|
+
let data = existsSync4(OBSERVATIONS_FILE2) ? readFileSync4(OBSERVATIONS_FILE2, "utf-8") : "version: 1\nobservations[0|]{ts|session|agent|branch|tool|hash|file|summary}:\n";
|
|
226
256
|
const lines = data.split("\n");
|
|
227
257
|
let headerIdx = lines.findIndex((l) => l.startsWith("observations["));
|
|
228
258
|
if (headerIdx === -1) {
|
|
@@ -235,13 +265,13 @@ function appendObservation(row) {
|
|
|
235
265
|
const count = match ? parseInt(match[1]) : 0;
|
|
236
266
|
lines[headerIdx] = lines[headerIdx].replace(/\[\d+\|/, `[${count + 1}|`);
|
|
237
267
|
lines.splice(headerIdx + 1, lines.length - headerIdx - 1, ...entryLines.map((l) => ` ${l}`));
|
|
238
|
-
withLockSync(
|
|
268
|
+
withLockSync(OBSERVATIONS_FILE2, () => atomicWrite(OBSERVATIONS_FILE2, lines.join("\n")));
|
|
239
269
|
}
|
|
240
270
|
function main() {
|
|
241
271
|
const agent = process.argv[2] || "agent";
|
|
242
272
|
let raw = "";
|
|
243
273
|
try {
|
|
244
|
-
raw =
|
|
274
|
+
raw = readFileSync4(0, "utf-8");
|
|
245
275
|
} catch {
|
|
246
276
|
process.exit(0);
|
|
247
277
|
}
|
|
@@ -268,8 +298,8 @@ function main() {
|
|
|
268
298
|
const hash = createHash("sha256").update(`${effectiveTool}|${normalized}`).digest("hex").slice(0, 16);
|
|
269
299
|
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
270
300
|
const branch = currentBranch();
|
|
271
|
-
if (
|
|
272
|
-
const data =
|
|
301
|
+
if (existsSync4(OBSERVATIONS_FILE2)) {
|
|
302
|
+
const data = readFileSync4(OBSERVATIONS_FILE2, "utf-8");
|
|
273
303
|
for (const line of data.split("\n")) {
|
|
274
304
|
if (!line.startsWith(" ")) continue;
|
|
275
305
|
const p = line.trim().split("|");
|
|
@@ -281,6 +311,7 @@ function main() {
|
|
|
281
311
|
}
|
|
282
312
|
if (!isStop && !toolName) process.exit(0);
|
|
283
313
|
appendObservation(`${ts}|${sessionId}|${agent}|${branch}|${effectiveTool}|${hash}|${file}|${summary}`);
|
|
314
|
+
pruneObservations();
|
|
284
315
|
process.exit(0);
|
|
285
316
|
}
|
|
286
317
|
main();
|
|
@@ -177,25 +177,25 @@ function main() {
|
|
|
177
177
|
const others = view.active.filter((s) => s.id !== sessionId && !s.ended);
|
|
178
178
|
const lines = [];
|
|
179
179
|
lines.push("toon-memory:");
|
|
180
|
-
lines.push(`
|
|
180
|
+
lines.push(` This session: ${agent} @ ${currentBranch()} (window ${Math.round(SESSION_TTL_MS / 6e4)} min)`);
|
|
181
181
|
if (others.length > 0) {
|
|
182
|
-
lines.push(`
|
|
182
|
+
lines.push(` Other active sessions (${others.length}):`);
|
|
183
183
|
for (const s of others) {
|
|
184
184
|
const files = Object.keys(s.files).slice(0, 5).join(", ") || "\u2014";
|
|
185
185
|
lines.push(` \u2022 ${s.agent} @ ${s.branch} \u2014 ${files}`);
|
|
186
186
|
}
|
|
187
187
|
} else {
|
|
188
|
-
lines.push("
|
|
188
|
+
lines.push(" No other active sessions.");
|
|
189
189
|
}
|
|
190
190
|
if (view.conflicts.length > 0) {
|
|
191
|
-
lines.push(` \u26A0\uFE0F
|
|
191
|
+
lines.push(` \u26A0\uFE0F Soft conflicts (${view.conflicts.length}): use memory_sessions for details.`);
|
|
192
192
|
for (const c of view.conflicts) {
|
|
193
193
|
lines.push(` \u2022 ${c.file}`);
|
|
194
194
|
}
|
|
195
195
|
} else {
|
|
196
|
-
lines.push("
|
|
196
|
+
lines.push(" No file conflicts detected.");
|
|
197
197
|
}
|
|
198
|
-
lines.push("
|
|
198
|
+
lines.push(" Use memory_recall before reading files and memory_sessions to coordinate.");
|
|
199
199
|
console.log(lines.join("\n"));
|
|
200
200
|
process.exit(0);
|
|
201
201
|
}
|
package/dist/cli/setup.js
CHANGED
|
@@ -29,7 +29,7 @@ Persistent memory for this project. Use it to avoid re-investigating things.
|
|
|
29
29
|
`;
|
|
30
30
|
var OPENCODE_PASSIVE_INSTRUCTION = `# toon-memory
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
Memory auto-injects via .opencode/instructions/memory-autoload.md; use memory_recall only as fallback.
|
|
33
33
|
`;
|
|
34
34
|
|
|
35
35
|
// src/cli/capture-toggle.ts
|
|
@@ -46,11 +46,11 @@ function captureToggle(enable) {
|
|
|
46
46
|
config.capture = enable;
|
|
47
47
|
writeFileSync(CAPTURE_CONFIG, JSON.stringify(config, null, 2));
|
|
48
48
|
if (enable) {
|
|
49
|
-
console.log("\n\u{1F534}
|
|
50
|
-
console.log("
|
|
51
|
-
console.log("
|
|
49
|
+
console.log("\n\u{1F534} Activity capture ENABLED.");
|
|
50
|
+
console.log("Hooks will write observations to .toon-memory/memory/observations.toon.");
|
|
51
|
+
console.log("Review with `memory_captured` and promote with `memory_remember`.\n");
|
|
52
52
|
} else {
|
|
53
|
-
console.log("\n\u26AA
|
|
53
|
+
console.log("\n\u26AA Activity capture DISABLED.\n");
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -178,16 +178,18 @@ function detectAgents() {
|
|
|
178
178
|
local: join3(projectRoot, ".cursor", "mcp.json"),
|
|
179
179
|
mcpKey: "mcpServers",
|
|
180
180
|
format: "json",
|
|
181
|
-
needsHooks:
|
|
182
|
-
needsInstructions: false
|
|
181
|
+
needsHooks: true,
|
|
182
|
+
needsInstructions: false,
|
|
183
|
+
captureJson: ["PostToolUse", "Stop"]
|
|
183
184
|
});
|
|
184
185
|
agents.push({
|
|
185
186
|
name: "windsurf",
|
|
186
187
|
global: join3(HOME, ".codeium", "windsurf", "mcp_config.json"),
|
|
187
188
|
mcpKey: "mcpServers",
|
|
188
189
|
format: "json",
|
|
189
|
-
needsHooks:
|
|
190
|
-
needsInstructions: false
|
|
190
|
+
needsHooks: true,
|
|
191
|
+
needsInstructions: false,
|
|
192
|
+
captureJson: ["PostToolUse", "Stop"]
|
|
191
193
|
});
|
|
192
194
|
agents.push({
|
|
193
195
|
name: "cline",
|
|
@@ -222,7 +224,8 @@ function detectAgents() {
|
|
|
222
224
|
format: "json",
|
|
223
225
|
needsHooks: true,
|
|
224
226
|
needsInstructions: true,
|
|
225
|
-
instructionFile: join3(projectRoot, ".gemini", "GEMINI.md")
|
|
227
|
+
instructionFile: join3(projectRoot, ".gemini", "GEMINI.md"),
|
|
228
|
+
captureJson: ["PostToolUse", "Stop"]
|
|
226
229
|
});
|
|
227
230
|
agents.push({
|
|
228
231
|
name: "zed",
|
|
@@ -721,9 +724,9 @@ var MEMORY_DIR2 = join7(projectRoot, ".toon-memory", "memory");
|
|
|
721
724
|
var CAPTURE_CONFIG2 = join7(MEMORY_DIR2, "config.json");
|
|
722
725
|
async function promptAgentSelection(agents) {
|
|
723
726
|
return checkbox({
|
|
724
|
-
message: "
|
|
727
|
+
message: "Which agents do you want to configure?",
|
|
725
728
|
choices: agents.map((a) => ({
|
|
726
|
-
name: `${a.name} (${a.format === "none" ? "
|
|
729
|
+
name: `${a.name} (${a.format === "none" ? "instructions" : a.global ? "local/global" : "local only"})`,
|
|
727
730
|
value: a,
|
|
728
731
|
checked: true
|
|
729
732
|
}))
|
|
@@ -763,23 +766,23 @@ async function init(scope, agentFilter) {
|
|
|
763
766
|
return;
|
|
764
767
|
}
|
|
765
768
|
finalScope = await select({
|
|
766
|
-
message: "
|
|
769
|
+
message: "Scope:",
|
|
767
770
|
choices: [
|
|
768
|
-
{ name: "Local (
|
|
771
|
+
{ name: "Local (project)", value: "local" },
|
|
769
772
|
{ name: "Global (~home)", value: "global" }
|
|
770
773
|
],
|
|
771
774
|
default: finalScope
|
|
772
775
|
});
|
|
773
|
-
const ok = await confirm({ message: "
|
|
776
|
+
const ok = await confirm({ message: "Proceed?", default: true });
|
|
774
777
|
if (!ok) {
|
|
775
|
-
console.log("\
|
|
778
|
+
console.log("\nInstallation cancelled.\n");
|
|
776
779
|
return;
|
|
777
780
|
}
|
|
778
781
|
} else {
|
|
779
782
|
selected = agents;
|
|
780
783
|
}
|
|
781
784
|
console.log(`
|
|
782
|
-
|
|
785
|
+
Installing (${finalScope}) \u2014 ${selected.map((a) => a.name).join(", ")}...
|
|
783
786
|
`);
|
|
784
787
|
for (const agent of selected) {
|
|
785
788
|
installForAgent(agent, finalScope);
|
|
@@ -1089,30 +1092,30 @@ function dumpMemory() {
|
|
|
1089
1092
|
}
|
|
1090
1093
|
async function interactiveInstall() {
|
|
1091
1094
|
if (!process.stdin.isTTY) {
|
|
1092
|
-
console.log("\n\u{1F9E0} toon-memory \u2014
|
|
1093
|
-
console.log("
|
|
1095
|
+
console.log("\n\u{1F9E0} toon-memory \u2014 interactive installation requires a terminal.");
|
|
1096
|
+
console.log("Run 'toon-memory init [--agent <name>]' for non-interactive installation.\n");
|
|
1094
1097
|
return;
|
|
1095
1098
|
}
|
|
1096
1099
|
const agents = detectAgents();
|
|
1097
1100
|
const selected = await promptAgentSelection(agents);
|
|
1098
1101
|
if (selected.length === 0) {
|
|
1099
|
-
console.log("\nNo
|
|
1102
|
+
console.log("\nNo agents selected. Nothing installed.\n");
|
|
1100
1103
|
return;
|
|
1101
1104
|
}
|
|
1102
1105
|
const scope = await select({
|
|
1103
|
-
message: "
|
|
1106
|
+
message: "Scope:",
|
|
1104
1107
|
choices: [
|
|
1105
|
-
{ name: "Local (
|
|
1108
|
+
{ name: "Local (project)", value: "local" },
|
|
1106
1109
|
{ name: "Global (~home)", value: "global" }
|
|
1107
1110
|
]
|
|
1108
1111
|
});
|
|
1109
|
-
const ok = await confirm({ message: "
|
|
1112
|
+
const ok = await confirm({ message: "Proceed?", default: true });
|
|
1110
1113
|
if (!ok) {
|
|
1111
|
-
console.log("\
|
|
1114
|
+
console.log("\nInstallation cancelled.\n");
|
|
1112
1115
|
return;
|
|
1113
1116
|
}
|
|
1114
1117
|
console.log(`
|
|
1115
|
-
|
|
1118
|
+
Installing (${scope}) \u2014 ${selected.map((a) => a.name).join(", ")}...
|
|
1116
1119
|
`);
|
|
1117
1120
|
installMemoryDir();
|
|
1118
1121
|
const deps = extractProjectDeps(projectRoot);
|
|
@@ -1323,16 +1326,16 @@ if (args.length === 0) {
|
|
|
1323
1326
|
await interactiveInstall();
|
|
1324
1327
|
process.exit(0);
|
|
1325
1328
|
}
|
|
1326
|
-
console.log(`
|
|
1329
|
+
console.log(`Unknown command: '${args[0]}'
|
|
1327
1330
|
`);
|
|
1328
1331
|
printUsage();
|
|
1329
1332
|
process.exit(1);
|
|
1330
1333
|
function printUsage() {
|
|
1331
|
-
console.log(`
|
|
1332
|
-
|
|
1333
|
-
Init: toon-memory init [--agent <
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1334
|
+
console.log(`Usage: toon-memory <command> [options]
|
|
1335
|
+
Commands: init, status, stats, export, import, watch, uninstall, capture, upgrade, mcp
|
|
1336
|
+
Init: toon-memory init [--agent <name> --agent <name>...] [--scope local|global]
|
|
1337
|
+
Without --agent: interactive agent and scope selector.
|
|
1338
|
+
With --agent: non-interactive installation (default: scope local).
|
|
1339
|
+
Options: -v/--version, -h/--help
|
|
1340
|
+
No arguments starts the interactive installer.`);
|
|
1338
1341
|
}
|