@mingxy/cerebro 1.6.8 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/logger.js ADDED
@@ -0,0 +1,42 @@
1
+ import { appendFileSync, mkdirSync, existsSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ const LOG_DIR = join(homedir(), ".config", "ourmem");
5
+ const LOG_FILE = join(LOG_DIR, "plugin.log");
6
+ function ensureLogDir() {
7
+ if (!existsSync(LOG_DIR)) {
8
+ try {
9
+ mkdirSync(LOG_DIR, { recursive: true });
10
+ }
11
+ catch {
12
+ // silently fail if we can't create log directory
13
+ }
14
+ }
15
+ }
16
+ function writeLog(level, ...args) {
17
+ ensureLogDir();
18
+ const timestamp = new Date().toISOString();
19
+ const message = args
20
+ .map((a) => (typeof a === "string" ? a : JSON.stringify(a)))
21
+ .join(" ");
22
+ const line = `[${timestamp}] [${level}] ${message}\n`;
23
+ try {
24
+ appendFileSync(LOG_FILE, line);
25
+ }
26
+ catch {
27
+ // silently fail if we can't write to log file
28
+ }
29
+ }
30
+ export function logInfo(...args) {
31
+ writeLog("INFO", ...args);
32
+ }
33
+ export function logWarn(...args) {
34
+ writeLog("WARN", ...args);
35
+ }
36
+ export function logError(...args) {
37
+ writeLog("ERROR", ...args);
38
+ }
39
+ export function logDebug(...args) {
40
+ writeLog("DEBUG", ...args);
41
+ }
42
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AACrD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;AAE7C,SAAS,YAAY;IACnB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,iDAAiD;QACnD,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAa,EAAE,GAAG,IAAe;IACjD,YAAY,EAAE,CAAC;IACf,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC3C,MAAM,OAAO,GAAG,IAAI;SACjB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3D,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,MAAM,IAAI,GAAG,IAAI,SAAS,MAAM,KAAK,KAAK,OAAO,IAAI,CAAC;IACtD,IAAI,CAAC;QACH,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,8CAA8C;IAChD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,GAAG,IAAe;IACxC,QAAQ,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,GAAG,IAAe;IACxC,QAAQ,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,GAAG,IAAe;IACzC,QAAQ,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,GAAG,IAAe;IACzC,QAAQ,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function stripPrivateContent(text: string): string;
2
+ export declare function isFullyPrivate(text: string): boolean;
3
+ //# sourceMappingURL=privacy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privacy.d.ts","sourceRoot":"","sources":["../src/privacy.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKpD"}
@@ -0,0 +1,10 @@
1
+ export function stripPrivateContent(text) {
2
+ return text.replace(/<private>[\s\S]*?<\/private>/gi, "[REDACTED]");
3
+ }
4
+ export function isFullyPrivate(text) {
5
+ const stripped = stripPrivateContent(text)
6
+ .replace(/\[REDACTED\]/g, "")
7
+ .trim();
8
+ return stripped.length === 0;
9
+ }
10
+ //# sourceMappingURL=privacy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privacy.js","sourceRoot":"","sources":["../src/privacy.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,gCAAgC,EAAE,YAAY,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,IAAI,CAAC;SACvC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;SAC5B,IAAI,EAAE,CAAC;IACV,OAAO,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC;AAC/B,CAAC"}
package/dist/tags.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function getUserTag(email: string): string;
2
+ export declare function getProjectTag(directory: string): string;
3
+ //# sourceMappingURL=tags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAMvD"}
package/dist/tags.js ADDED
@@ -0,0 +1,13 @@
1
+ import { createHash } from "crypto";
2
+ export function getUserTag(email) {
3
+ const hash = createHash("sha256").update(email).digest("hex").slice(0, 16);
4
+ return `omem_user_${hash}`;
5
+ }
6
+ export function getProjectTag(directory) {
7
+ const hash = createHash("sha256")
8
+ .update(directory)
9
+ .digest("hex")
10
+ .slice(0, 16);
11
+ return `omem_project_${hash}`;
12
+ }
13
+ //# sourceMappingURL=tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3E,OAAO,aAAa,IAAI,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,SAAiB;IAC7C,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC;SAC9B,MAAM,CAAC,SAAS,CAAC;SACjB,MAAM,CAAC,KAAK,CAAC;SACb,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAChB,OAAO,gBAAgB,IAAI,EAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1,202 @@
1
+ import type { OmemClient } from "./client.js";
2
+ export interface ToolContext {
3
+ agentId?: string;
4
+ getSessionId: () => string | undefined;
5
+ }
6
+ export declare function buildTools(client: OmemClient, containerTags: string[], context: ToolContext): {
7
+ memory_store: {
8
+ description: string;
9
+ args: {
10
+ content: import("zod").ZodString;
11
+ tags: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
12
+ source: import("zod").ZodString;
13
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
14
+ visibility: import("zod").ZodOptional<import("zod").ZodString>;
15
+ };
16
+ execute(args: {
17
+ content: string;
18
+ source: string;
19
+ tags?: string[] | undefined;
20
+ scope?: string | undefined;
21
+ visibility?: string | undefined;
22
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
23
+ };
24
+ memory_search: {
25
+ description: string;
26
+ args: {
27
+ query: import("zod").ZodString;
28
+ limit: import("zod").ZodOptional<import("zod").ZodNumber>;
29
+ scope: import("zod").ZodOptional<import("zod").ZodString>;
30
+ };
31
+ execute(args: {
32
+ query: string;
33
+ limit?: number | undefined;
34
+ scope?: string | undefined;
35
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
36
+ };
37
+ memory_get: {
38
+ description: string;
39
+ args: {
40
+ id: import("zod").ZodString;
41
+ };
42
+ execute(args: {
43
+ id: string;
44
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
45
+ };
46
+ memory_update: {
47
+ description: string;
48
+ args: {
49
+ id: import("zod").ZodString;
50
+ content: import("zod").ZodString;
51
+ tags: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
52
+ };
53
+ execute(args: {
54
+ id: string;
55
+ content: string;
56
+ tags?: string[] | undefined;
57
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
58
+ };
59
+ memory_profile: {
60
+ description: string;
61
+ args: {};
62
+ execute(args: Record<string, never>, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
63
+ };
64
+ memory_list: {
65
+ description: string;
66
+ args: {
67
+ limit: import("zod").ZodOptional<import("zod").ZodNumber>;
68
+ };
69
+ execute(args: {
70
+ limit?: number | undefined;
71
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
72
+ };
73
+ session_recalls: {
74
+ description: string;
75
+ args: {
76
+ session_id: import("zod").ZodString;
77
+ };
78
+ execute(args: {
79
+ session_id: string;
80
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
81
+ };
82
+ memory_ingest: {
83
+ description: string;
84
+ args: {
85
+ messages: import("zod").ZodArray<import("zod").ZodObject<{
86
+ role: import("zod").ZodString;
87
+ content: import("zod").ZodString;
88
+ }, import("zod/v4/core").$strip>>;
89
+ mode: import("zod").ZodOptional<import("zod").ZodEnum<{
90
+ smart: "smart";
91
+ raw: "raw";
92
+ }>>;
93
+ tags: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
94
+ session_id: import("zod").ZodOptional<import("zod").ZodString>;
95
+ };
96
+ execute(args: {
97
+ messages: {
98
+ role: string;
99
+ content: string;
100
+ }[];
101
+ mode?: "smart" | "raw" | undefined;
102
+ tags?: string[] | undefined;
103
+ session_id?: string | undefined;
104
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
105
+ };
106
+ memory_stats: {
107
+ description: string;
108
+ args: {};
109
+ execute(args: Record<string, never>, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
110
+ };
111
+ memory_delete: {
112
+ description: string;
113
+ args: {
114
+ id: import("zod").ZodString;
115
+ };
116
+ execute(args: {
117
+ id: string;
118
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
119
+ };
120
+ space_create: {
121
+ description: string;
122
+ args: {
123
+ name: import("zod").ZodString;
124
+ space_type: import("zod").ZodString;
125
+ members: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
126
+ user_id: import("zod").ZodString;
127
+ role: import("zod").ZodString;
128
+ }, import("zod/v4/core").$strip>>>;
129
+ };
130
+ execute(args: {
131
+ name: string;
132
+ space_type: string;
133
+ members?: {
134
+ user_id: string;
135
+ role: string;
136
+ }[] | undefined;
137
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
138
+ };
139
+ space_list: {
140
+ description: string;
141
+ args: {};
142
+ execute(args: Record<string, never>, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
143
+ };
144
+ space_add_member: {
145
+ description: string;
146
+ args: {
147
+ space_id: import("zod").ZodString;
148
+ user_id: import("zod").ZodString;
149
+ role: import("zod").ZodString;
150
+ };
151
+ execute(args: {
152
+ space_id: string;
153
+ user_id: string;
154
+ role: string;
155
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
156
+ };
157
+ memory_share: {
158
+ description: string;
159
+ args: {
160
+ memory_id: import("zod").ZodString;
161
+ target_space: import("zod").ZodString;
162
+ };
163
+ execute(args: {
164
+ memory_id: string;
165
+ target_space: string;
166
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
167
+ };
168
+ memory_pull: {
169
+ description: string;
170
+ args: {
171
+ memory_id: import("zod").ZodString;
172
+ source_space: import("zod").ZodString;
173
+ visibility: import("zod").ZodOptional<import("zod").ZodString>;
174
+ };
175
+ execute(args: {
176
+ memory_id: string;
177
+ source_space: string;
178
+ visibility?: string | undefined;
179
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
180
+ };
181
+ memory_reshare: {
182
+ description: string;
183
+ args: {
184
+ memory_id: import("zod").ZodString;
185
+ target_space: import("zod").ZodOptional<import("zod").ZodString>;
186
+ };
187
+ execute(args: {
188
+ memory_id: string;
189
+ target_space?: string | undefined;
190
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
191
+ };
192
+ memory_toggle: {
193
+ description: string;
194
+ args: {
195
+ state: import("zod").ZodOptional<import("zod").ZodString>;
196
+ };
197
+ execute(args: {
198
+ state?: string | undefined;
199
+ }, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
200
+ };
201
+ };
202
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAsB9C,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;CACxC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuX3F"}
package/dist/tools.js ADDED
@@ -0,0 +1,337 @@
1
+ import { tool } from "@opencode-ai/plugin";
2
+ import { isAutoStoreEnabled, setAutoStoreEnabled } from "./index.js";
3
+ function extractMemoryIds(result) {
4
+ if (!result)
5
+ return [];
6
+ if (Array.isArray(result)) {
7
+ return result.map((m) => m.id).filter(Boolean);
8
+ }
9
+ if (typeof result === "object" && result !== null) {
10
+ const r = result;
11
+ if (Array.isArray(r.memories)) {
12
+ return r.memories.map((m) => m.id).filter(Boolean);
13
+ }
14
+ if (Array.isArray(r.results)) {
15
+ return r.results
16
+ .map((m) => m.id ?? m.memory?.id)
17
+ .filter(Boolean);
18
+ }
19
+ }
20
+ return [];
21
+ }
22
+ export function buildTools(client, containerTags, context) {
23
+ return {
24
+ memory_store: tool({
25
+ description: "Store a new memory in the user's long-term memory. " +
26
+ "Use when the user explicitly asks to remember something, " +
27
+ "or when you identify important preferences, facts, or decisions worth preserving.",
28
+ args: {
29
+ content: tool.schema.string().describe("The information to remember"),
30
+ tags: tool.schema
31
+ .array(tool.schema.string())
32
+ .optional()
33
+ .describe("Optional categorization tags"),
34
+ source: tool.schema
35
+ .string()
36
+ .describe("Origin context, e.g. 'conversation', 'code-review', 'user-input'"),
37
+ scope: tool.schema
38
+ .string()
39
+ .optional()
40
+ .describe("Memory scope: 'project' (default, only visible in this project) or 'global' (visible across all projects)"),
41
+ visibility: tool.schema
42
+ .string()
43
+ .optional()
44
+ .describe("Memory visibility: 'global' (default, visible to all agents) or 'private' (only visible to the storing agent). Use 'private' for sensitive data like credentials, personal info, or anything the user wouldn't want shared."),
45
+ },
46
+ async execute(args) {
47
+ const allTags = [...containerTags, ...(args.tags ?? [])];
48
+ const result = await client.createMemory(args.content, allTags, args.source, args.scope ?? "project", context.agentId, context.getSessionId(), args.visibility);
49
+ if (!result)
50
+ return JSON.stringify({ ok: false, error: "The omem server may be unavailable." });
51
+ return JSON.stringify({ ok: true, id: result.id, tags: result.tags });
52
+ },
53
+ }),
54
+ memory_search: tool({
55
+ description: "Search the user's long-term memory by semantic similarity. " +
56
+ "Use to recall previously stored preferences, facts, or context.",
57
+ args: {
58
+ query: tool.schema.string().describe("Natural-language search query"),
59
+ limit: tool.schema
60
+ .number()
61
+ .optional()
62
+ .describe("Max results to return (default 10)"),
63
+ scope: tool.schema
64
+ .string()
65
+ .optional()
66
+ .describe("Optional scope filter"),
67
+ },
68
+ async execute(args) {
69
+ const results = await client.searchMemories(args.query, args.limit ?? 10, args.scope, containerTags);
70
+ if (results.length === 0)
71
+ return JSON.stringify({ ok: true, count: 0, results: [] });
72
+ const items = results.map((r) => ({
73
+ id: r.memory.id,
74
+ score: r.score,
75
+ content: r.memory.content.slice(0, 200),
76
+ }));
77
+ return JSON.stringify({ ok: true, count: results.length, results: items });
78
+ },
79
+ }),
80
+ memory_get: tool({
81
+ description: "Retrieve a specific memory by its ID.",
82
+ args: {
83
+ id: tool.schema.string().describe("Memory ID"),
84
+ },
85
+ async execute(args) {
86
+ const memory = await client.getMemory(args.id);
87
+ if (!memory)
88
+ return JSON.stringify({ ok: false, error: "not found" });
89
+ return JSON.stringify({ ok: true, memory });
90
+ },
91
+ }),
92
+ memory_update: tool({
93
+ description: "Update the content or tags of an existing memory. " +
94
+ "Use when information needs correction or enrichment.",
95
+ args: {
96
+ id: tool.schema.string().describe("Memory ID to update"),
97
+ content: tool.schema.string().describe("New content"),
98
+ tags: tool.schema
99
+ .array(tool.schema.string())
100
+ .optional()
101
+ .describe("Replacement tags"),
102
+ },
103
+ async execute(args) {
104
+ const result = await client.updateMemory(args.id, args.content, args.tags);
105
+ if (!result)
106
+ return JSON.stringify({ ok: false, error: `Failed to update memory ${args.id}` });
107
+ return JSON.stringify({ ok: true, id: args.id });
108
+ },
109
+ }),
110
+ memory_profile: tool({
111
+ description: "Get the user profile synthesized from stored memories. Shows preferences, patterns, and key information.",
112
+ args: {},
113
+ async execute() {
114
+ const profile = await client.getProfile();
115
+ if (!profile)
116
+ return JSON.stringify({ ok: false, error: "Failed to get profile" });
117
+ return JSON.stringify({ ok: true, profile });
118
+ },
119
+ }),
120
+ memory_list: tool({
121
+ description: "List the most recent memories. Use to browse what's been remembered without a search query.",
122
+ args: {
123
+ limit: tool.schema
124
+ .number()
125
+ .optional()
126
+ .describe("Max memories to return (default: 20)"),
127
+ },
128
+ async execute(args) {
129
+ const memories = await client.listRecent(args.limit ?? 20);
130
+ if (memories.length === 0)
131
+ return JSON.stringify({ ok: true, count: 0, memories: [] });
132
+ const items = memories.map((m) => ({
133
+ id: m.id,
134
+ content: m.content.slice(0, 120),
135
+ category: m.category,
136
+ tags: m.tags,
137
+ }));
138
+ return JSON.stringify({ ok: true, count: memories.length, memories: items });
139
+ },
140
+ }),
141
+ session_recalls: tool({
142
+ description: "List the injection records for a session. Use to see what memories have been recalled into the current session.",
143
+ args: {
144
+ session_id: tool.schema
145
+ .string()
146
+ .describe("Session ID to query recall records for"),
147
+ },
148
+ async execute(args) {
149
+ const recalls = await client.listSessionRecalls(args.session_id);
150
+ if (recalls.length === 0)
151
+ return JSON.stringify({ ok: true, count: 0, recalls: [] });
152
+ return JSON.stringify({ ok: true, count: recalls.length, recalls });
153
+ },
154
+ }),
155
+ memory_ingest: tool({
156
+ description: "Ingest conversation messages for intelligent extraction. The system extracts atomic facts, deduplicates, and reconciles with existing memories.",
157
+ args: {
158
+ messages: tool.schema
159
+ .array(tool.schema.object({
160
+ role: tool.schema.string().describe("Message role: user, assistant, or system"),
161
+ content: tool.schema.string().describe("Message content"),
162
+ }))
163
+ .describe("Conversation messages to ingest"),
164
+ mode: tool.schema
165
+ .enum(["smart", "raw"])
166
+ .optional()
167
+ .describe("Extraction mode: 'smart' (default) or 'raw'"),
168
+ tags: tool.schema
169
+ .array(tool.schema.string())
170
+ .optional()
171
+ .describe("Tags to apply to extracted memories"),
172
+ session_id: tool.schema
173
+ .string()
174
+ .optional()
175
+ .describe("Session ID to associate with the ingestion"),
176
+ },
177
+ async execute(args) {
178
+ const result = await client.ingestMessages(args.messages, {
179
+ mode: args.mode ?? "smart",
180
+ tags: args.tags,
181
+ sessionId: args.session_id,
182
+ });
183
+ if (result === null)
184
+ return JSON.stringify({ ok: false, error: "Ingestion failed" });
185
+ if (args.session_id) {
186
+ const memoryIds = extractMemoryIds(result);
187
+ if (memoryIds.length > 0) {
188
+ await client.recordSessionRecall(args.session_id, memoryIds, "manual", args.messages.map((m) => m.content).join("\n").slice(0, 200), 0, 0).catch(() => { });
189
+ }
190
+ }
191
+ return JSON.stringify({ ok: true, result });
192
+ },
193
+ }),
194
+ memory_stats: tool({
195
+ description: "Get statistics about stored memories — counts by category, type, tier, and timeline.",
196
+ args: {},
197
+ async execute() {
198
+ const stats = await client.getStats();
199
+ if (!stats)
200
+ return JSON.stringify({ ok: false, error: "Failed to get stats" });
201
+ return JSON.stringify({ ok: true, stats });
202
+ },
203
+ }),
204
+ memory_delete: tool({
205
+ description: "Delete a memory by ID. Use when the user asks to forget something.",
206
+ args: {
207
+ id: tool.schema.string().describe("Memory ID to delete"),
208
+ },
209
+ async execute(args) {
210
+ try {
211
+ await client.deleteMemory(args.id);
212
+ return JSON.stringify({ ok: true, id: args.id });
213
+ }
214
+ catch {
215
+ return JSON.stringify({ ok: false, error: `Failed to delete memory ${args.id}` });
216
+ }
217
+ },
218
+ }),
219
+ space_create: tool({
220
+ description: "Create a shared space (team or organization) for sharing memories across users and agents.",
221
+ args: {
222
+ name: tool.schema.string().describe("Name of the space"),
223
+ space_type: tool.schema
224
+ .string()
225
+ .describe("Type of space: 'team' or 'organization'"),
226
+ members: tool.schema
227
+ .array(tool.schema.object({
228
+ user_id: tool.schema.string().describe("User/tenant ID to add"),
229
+ role: tool.schema.string().describe("Member role: admin, member, or reader"),
230
+ }))
231
+ .optional()
232
+ .describe("Initial members to add"),
233
+ },
234
+ async execute(args) {
235
+ const result = await client.createSpace(args.name, args.space_type, args.members);
236
+ if (!result)
237
+ return JSON.stringify({ ok: false, error: "Failed to create space" });
238
+ return JSON.stringify({ ok: true, space: result });
239
+ },
240
+ }),
241
+ space_list: tool({
242
+ description: "List all spaces you own or are a member of.",
243
+ args: {},
244
+ async execute() {
245
+ const spaces = await client.listSpaces();
246
+ return JSON.stringify({ ok: true, spaces });
247
+ },
248
+ }),
249
+ space_add_member: tool({
250
+ description: "Add a user to an existing shared space with a specified role.",
251
+ args: {
252
+ space_id: tool.schema.string().describe("Space ID"),
253
+ user_id: tool.schema.string().describe("User/tenant ID to add"),
254
+ role: tool.schema.string().describe("Role: admin, member, or reader"),
255
+ },
256
+ async execute(args) {
257
+ const result = await client.addSpaceMember(args.space_id, args.user_id, args.role);
258
+ if (!result)
259
+ return JSON.stringify({ ok: false, error: "Failed to add member" });
260
+ return JSON.stringify({ ok: true, result });
261
+ },
262
+ }),
263
+ memory_share: tool({
264
+ description: "Share a memory to a team or organization space. Creates a copy with provenance tracking.",
265
+ args: {
266
+ memory_id: tool.schema.string().describe("Memory ID to share"),
267
+ target_space: tool.schema.string().describe("Target space ID"),
268
+ },
269
+ async execute(args) {
270
+ const result = await client.shareMemory(args.memory_id, args.target_space);
271
+ if (!result)
272
+ return JSON.stringify({ ok: false, error: "Failed to share memory" });
273
+ return JSON.stringify({ ok: true, result });
274
+ },
275
+ }),
276
+ memory_pull: tool({
277
+ description: "Pull a shared memory from a team/organization space into your personal space.",
278
+ args: {
279
+ memory_id: tool.schema.string().describe("Memory ID to pull"),
280
+ source_space: tool.schema.string().describe("Source space ID"),
281
+ visibility: tool.schema
282
+ .string()
283
+ .optional()
284
+ .describe("Visibility of the pulled copy"),
285
+ },
286
+ async execute(args) {
287
+ const result = await client.pullMemory(args.memory_id, args.source_space, args.visibility);
288
+ if (!result)
289
+ return JSON.stringify({ ok: false, error: "Failed to pull memory" });
290
+ return JSON.stringify({ ok: true, result });
291
+ },
292
+ }),
293
+ memory_reshare: tool({
294
+ description: "Refresh a stale shared copy with the latest content and vector from the source memory.",
295
+ args: {
296
+ memory_id: tool.schema.string().describe("Shared copy memory ID to refresh"),
297
+ target_space: tool.schema
298
+ .string()
299
+ .optional()
300
+ .describe("Target space containing the copy (optional)"),
301
+ },
302
+ async execute(args) {
303
+ const result = await client.reshareMemory(args.memory_id, args.target_space);
304
+ if (!result)
305
+ return JSON.stringify({ ok: false, error: "Failed to reshare memory" });
306
+ return JSON.stringify({ ok: true, result });
307
+ },
308
+ }),
309
+ memory_toggle: tool({
310
+ description: "Toggle Cerebro auto-store ON or OFF for current session. Does NOT affect manual memory_store calls.",
311
+ args: {
312
+ state: tool.schema
313
+ .string()
314
+ .optional()
315
+ .describe("Set to 'on' or 'off'. Omit to check current status."),
316
+ },
317
+ async execute(args) {
318
+ const sessionId = context.getSessionId();
319
+ if (!sessionId)
320
+ return JSON.stringify({ ok: false, error: "No active session" });
321
+ if (args.state === "on") {
322
+ setAutoStoreEnabled(sessionId, true);
323
+ return JSON.stringify({ ok: true, auto_store: true, message: "Cerebro auto-store: ON" });
324
+ }
325
+ else if (args.state === "off") {
326
+ setAutoStoreEnabled(sessionId, false);
327
+ return JSON.stringify({ ok: true, auto_store: false, message: "Cerebro auto-store: OFF" });
328
+ }
329
+ else {
330
+ const current = isAutoStoreEnabled(sessionId);
331
+ return JSON.stringify({ ok: true, auto_store: current, message: `Cerebro auto-store: ${current ? "ON" : "OFF"}` });
332
+ }
333
+ },
334
+ }),
335
+ };
336
+ }
337
+ //# sourceMappingURL=tools.js.map