memax-cli 0.1.0-alpha.4 → 0.1.0-alpha.41

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.
Files changed (177) hide show
  1. package/assets/skills/memax-memory/SKILL.md +154 -0
  2. package/dist/commands/agent-sessions.d.ts +62 -0
  3. package/dist/commands/agent-sessions.d.ts.map +1 -0
  4. package/dist/commands/agent-sessions.js +1338 -0
  5. package/dist/commands/agent-sessions.js.map +1 -0
  6. package/dist/commands/agent-sessions.test.d.ts +2 -0
  7. package/dist/commands/agent-sessions.test.d.ts.map +1 -0
  8. package/dist/commands/agent-sessions.test.js +255 -0
  9. package/dist/commands/agent-sessions.test.js.map +1 -0
  10. package/dist/commands/agents.d.ts +3 -0
  11. package/dist/commands/agents.d.ts.map +1 -0
  12. package/dist/commands/agents.js +36 -0
  13. package/dist/commands/agents.js.map +1 -0
  14. package/dist/commands/ask.d.ts +13 -0
  15. package/dist/commands/ask.d.ts.map +1 -0
  16. package/dist/commands/ask.js +459 -0
  17. package/dist/commands/ask.js.map +1 -0
  18. package/dist/commands/auth.d.ts +3 -0
  19. package/dist/commands/auth.d.ts.map +1 -1
  20. package/dist/commands/auth.js +38 -7
  21. package/dist/commands/auth.js.map +1 -1
  22. package/dist/commands/capture.d.ts +19 -0
  23. package/dist/commands/capture.d.ts.map +1 -0
  24. package/dist/commands/capture.js +69 -0
  25. package/dist/commands/capture.js.map +1 -0
  26. package/dist/commands/config.d.ts +2 -0
  27. package/dist/commands/config.d.ts.map +1 -1
  28. package/dist/commands/config.js +13 -0
  29. package/dist/commands/config.js.map +1 -1
  30. package/dist/commands/delete.d.ts +3 -1
  31. package/dist/commands/delete.d.ts.map +1 -1
  32. package/dist/commands/delete.js +30 -5
  33. package/dist/commands/delete.js.map +1 -1
  34. package/dist/commands/dreams.d.ts +22 -0
  35. package/dist/commands/dreams.d.ts.map +1 -0
  36. package/dist/commands/dreams.js +205 -0
  37. package/dist/commands/dreams.js.map +1 -0
  38. package/dist/commands/dreams.test.d.ts +2 -0
  39. package/dist/commands/dreams.test.d.ts.map +1 -0
  40. package/dist/commands/dreams.test.js +39 -0
  41. package/dist/commands/dreams.test.js.map +1 -0
  42. package/dist/commands/hook.d.ts +2 -0
  43. package/dist/commands/hook.d.ts.map +1 -1
  44. package/dist/commands/hook.js +6 -0
  45. package/dist/commands/hook.js.map +1 -1
  46. package/dist/commands/hub.d.ts +31 -0
  47. package/dist/commands/hub.d.ts.map +1 -0
  48. package/dist/commands/hub.js +295 -0
  49. package/dist/commands/hub.js.map +1 -0
  50. package/dist/commands/hub.test.d.ts +2 -0
  51. package/dist/commands/hub.test.d.ts.map +1 -0
  52. package/dist/commands/hub.test.js +62 -0
  53. package/dist/commands/hub.test.js.map +1 -0
  54. package/dist/commands/list.d.ts +8 -1
  55. package/dist/commands/list.d.ts.map +1 -1
  56. package/dist/commands/list.js +110 -9
  57. package/dist/commands/list.js.map +1 -1
  58. package/dist/commands/list.test.d.ts +2 -0
  59. package/dist/commands/list.test.d.ts.map +1 -0
  60. package/dist/commands/list.test.js +14 -0
  61. package/dist/commands/list.test.js.map +1 -0
  62. package/dist/commands/login.d.ts +2 -0
  63. package/dist/commands/login.d.ts.map +1 -1
  64. package/dist/commands/login.js +50 -19
  65. package/dist/commands/login.js.map +1 -1
  66. package/dist/commands/mcp.d.ts.map +1 -1
  67. package/dist/commands/mcp.js +285 -42
  68. package/dist/commands/mcp.js.map +1 -1
  69. package/dist/commands/push.d.ts +6 -1
  70. package/dist/commands/push.d.ts.map +1 -1
  71. package/dist/commands/push.js +73 -11
  72. package/dist/commands/push.js.map +1 -1
  73. package/dist/commands/recall.d.ts +9 -0
  74. package/dist/commands/recall.d.ts.map +1 -1
  75. package/dist/commands/recall.js +206 -39
  76. package/dist/commands/recall.js.map +1 -1
  77. package/dist/commands/recall.test.d.ts +2 -0
  78. package/dist/commands/recall.test.d.ts.map +1 -0
  79. package/dist/commands/recall.test.js +31 -0
  80. package/dist/commands/recall.test.js.map +1 -0
  81. package/dist/commands/setup-hooks.d.ts +12 -0
  82. package/dist/commands/setup-hooks.d.ts.map +1 -0
  83. package/dist/commands/setup-hooks.js +193 -0
  84. package/dist/commands/setup-hooks.js.map +1 -0
  85. package/dist/commands/setup-instructions.d.ts +21 -0
  86. package/dist/commands/setup-instructions.d.ts.map +1 -0
  87. package/dist/commands/setup-instructions.js +172 -0
  88. package/dist/commands/setup-instructions.js.map +1 -0
  89. package/dist/commands/setup-mcp.d.ts +14 -0
  90. package/dist/commands/setup-mcp.d.ts.map +1 -0
  91. package/dist/commands/setup-mcp.js +288 -0
  92. package/dist/commands/setup-mcp.js.map +1 -0
  93. package/dist/commands/setup-types.d.ts +20 -0
  94. package/dist/commands/setup-types.d.ts.map +1 -0
  95. package/dist/commands/setup-types.js +60 -0
  96. package/dist/commands/setup-types.js.map +1 -0
  97. package/dist/commands/setup.d.ts +8 -1
  98. package/dist/commands/setup.d.ts.map +1 -1
  99. package/dist/commands/setup.js +163 -307
  100. package/dist/commands/setup.js.map +1 -1
  101. package/dist/commands/show.d.ts +2 -0
  102. package/dist/commands/show.d.ts.map +1 -1
  103. package/dist/commands/show.js +25 -13
  104. package/dist/commands/show.js.map +1 -1
  105. package/dist/commands/sync.d.ts +47 -2
  106. package/dist/commands/sync.d.ts.map +1 -1
  107. package/dist/commands/sync.js +1299 -119
  108. package/dist/commands/sync.js.map +1 -1
  109. package/dist/commands/sync.test.d.ts +2 -0
  110. package/dist/commands/sync.test.d.ts.map +1 -0
  111. package/dist/commands/sync.test.js +130 -0
  112. package/dist/commands/sync.test.js.map +1 -0
  113. package/dist/commands/topic.d.ts +32 -0
  114. package/dist/commands/topic.d.ts.map +1 -0
  115. package/dist/commands/topic.js +223 -0
  116. package/dist/commands/topic.js.map +1 -0
  117. package/dist/commands/topic.test.d.ts +2 -0
  118. package/dist/commands/topic.test.d.ts.map +1 -0
  119. package/dist/commands/topic.test.js +114 -0
  120. package/dist/commands/topic.test.js.map +1 -0
  121. package/dist/index.js +35 -125
  122. package/dist/index.js.map +1 -1
  123. package/dist/lib/client.d.ts +9 -0
  124. package/dist/lib/client.d.ts.map +1 -0
  125. package/dist/lib/client.js +77 -0
  126. package/dist/lib/client.js.map +1 -0
  127. package/dist/lib/config.d.ts +45 -0
  128. package/dist/lib/config.d.ts.map +1 -1
  129. package/dist/lib/config.js +74 -1
  130. package/dist/lib/config.js.map +1 -1
  131. package/dist/lib/hubs.d.ts +7 -0
  132. package/dist/lib/hubs.d.ts.map +1 -0
  133. package/dist/lib/hubs.js +33 -0
  134. package/dist/lib/hubs.js.map +1 -0
  135. package/dist/lib/hubs.test.d.ts +2 -0
  136. package/dist/lib/hubs.test.d.ts.map +1 -0
  137. package/dist/lib/hubs.test.js +58 -0
  138. package/dist/lib/hubs.test.js.map +1 -0
  139. package/dist/lib/project-context.d.ts +56 -0
  140. package/dist/lib/project-context.d.ts.map +1 -0
  141. package/dist/lib/project-context.js +231 -0
  142. package/dist/lib/project-context.js.map +1 -0
  143. package/dist/lib/project-context.test.d.ts +2 -0
  144. package/dist/lib/project-context.test.d.ts.map +1 -0
  145. package/dist/lib/project-context.test.js +75 -0
  146. package/dist/lib/project-context.test.js.map +1 -0
  147. package/dist/lib/prompt.d.ts +7 -0
  148. package/dist/lib/prompt.d.ts.map +1 -0
  149. package/dist/lib/prompt.js +41 -0
  150. package/dist/lib/prompt.js.map +1 -0
  151. package/dist/lib/trash.d.ts +6 -0
  152. package/dist/lib/trash.d.ts.map +1 -0
  153. package/dist/lib/trash.js +28 -0
  154. package/dist/lib/trash.js.map +1 -0
  155. package/package.json +17 -13
  156. package/.vscode/mcp.json +0 -8
  157. package/dist/lib/api.d.ts +0 -4
  158. package/dist/lib/api.d.ts.map +0 -1
  159. package/dist/lib/api.js +0 -95
  160. package/dist/lib/api.js.map +0 -1
  161. package/src/commands/auth.ts +0 -92
  162. package/src/commands/config.ts +0 -27
  163. package/src/commands/delete.ts +0 -20
  164. package/src/commands/hook.ts +0 -243
  165. package/src/commands/list.ts +0 -38
  166. package/src/commands/login.ts +0 -162
  167. package/src/commands/mcp.ts +0 -357
  168. package/src/commands/push.ts +0 -82
  169. package/src/commands/recall.ts +0 -163
  170. package/src/commands/setup.ts +0 -682
  171. package/src/commands/show.ts +0 -35
  172. package/src/commands/sync.ts +0 -403
  173. package/src/index.ts +0 -192
  174. package/src/lib/api.ts +0 -110
  175. package/src/lib/config.ts +0 -61
  176. package/src/lib/credentials.ts +0 -42
  177. package/tsconfig.json +0 -9
@@ -1,357 +0,0 @@
1
- import { Command } from "commander";
2
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
- import {
5
- CallToolRequestSchema,
6
- ListToolsRequestSchema,
7
- } from "@modelcontextprotocol/sdk/types.js";
8
- import { apiGet, apiPost } from "../lib/api.js";
9
-
10
- interface RecallResult {
11
- notes: Array<{
12
- id: string;
13
- title: string;
14
- chunk_content: string;
15
- heading_chain: string;
16
- relevance_score: number;
17
- category: string;
18
- source: string;
19
- age: string;
20
- }>;
21
- query_metadata: {
22
- intent: string;
23
- total_candidates: number;
24
- latency_ms: number;
25
- };
26
- }
27
-
28
- interface NoteResult {
29
- id: string;
30
- title: string;
31
- category: string;
32
- source: string;
33
- tags: string[];
34
- summary: string;
35
- created_at: string;
36
- }
37
-
38
- function createServer(): Server {
39
- const server = new Server(
40
- { name: "memax", version: "0.0.1" },
41
- { capabilities: { tools: {} } },
42
- );
43
-
44
- server.setRequestHandler(ListToolsRequestSchema, async () => ({
45
- tools: [
46
- {
47
- name: "memax_recall",
48
- description:
49
- "Search the user's Memax knowledge base with a natural language query. " +
50
- "Returns relevant memories ranked by relevance. Use this when you need " +
51
- "background information about the project, team processes, or past decisions.",
52
- inputSchema: {
53
- type: "object" as const,
54
- properties: {
55
- query: {
56
- type: "string",
57
- description: "Natural language search query",
58
- },
59
- limit: {
60
- type: "number",
61
- description: "Max results to return (default 5)",
62
- },
63
- category: {
64
- type: "string",
65
- description:
66
- "Filter by category prefix (e.g. 'core', 'decisions', 'process')",
67
- },
68
- },
69
- required: ["query"],
70
- },
71
- },
72
- {
73
- name: "memax_push",
74
- description:
75
- "Save a piece of knowledge to the user's Memax knowledge base. " +
76
- "Auto-categorized by AI if no category is provided.",
77
- inputSchema: {
78
- type: "object" as const,
79
- properties: {
80
- content: {
81
- type: "string",
82
- description: "The knowledge content to save",
83
- },
84
- title: {
85
- type: "string",
86
- description: "Optional title (auto-generated if omitted)",
87
- },
88
- category: {
89
- type: "string",
90
- description:
91
- "Category (e.g. 'decisions/adr', 'core/architecture'). Auto-detected if omitted.",
92
- },
93
- tags: {
94
- type: "array",
95
- items: { type: "string" },
96
- description: "Tags for the memory",
97
- },
98
- },
99
- required: ["content"],
100
- },
101
- },
102
- {
103
- name: "memax_get",
104
- description:
105
- "Get the full content of a specific note by ID. " +
106
- "Use this after memax_recall to read the complete content of a relevant memory.",
107
- inputSchema: {
108
- type: "object" as const,
109
- properties: {
110
- id: {
111
- type: "string",
112
- description:
113
- "The note ID (from memax_recall or memax_search results)",
114
- },
115
- },
116
- required: ["id"],
117
- },
118
- },
119
- {
120
- name: "memax_search",
121
- description:
122
- "List notes filtered by category or tags. " +
123
- "For browsing and structured lookups, not semantic search. " +
124
- "Use memax_recall for natural language queries instead.",
125
- inputSchema: {
126
- type: "object" as const,
127
- properties: {
128
- category: {
129
- type: "string",
130
- description: "Filter by category prefix",
131
- },
132
- limit: {
133
- type: "number",
134
- description: "Max results to return (default 10)",
135
- },
136
- },
137
- },
138
- },
139
- ],
140
- }));
141
-
142
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
143
- const { name, arguments: args } = request.params;
144
-
145
- switch (name) {
146
- case "memax_recall": {
147
- const typedArgs = args as {
148
- query: string;
149
- limit?: number;
150
- category?: string;
151
- };
152
- try {
153
- const result = await apiPost<RecallResult>("/v1/recall", {
154
- query: typedArgs.query,
155
- limit: typedArgs.limit ?? 5,
156
- category: typedArgs.category ?? "",
157
- source: "mcp",
158
- working_dir: process.cwd(),
159
- });
160
-
161
- const notes = result.notes ?? [];
162
- if (notes.length === 0) {
163
- return {
164
- content: [{ type: "text" as const, text: "No results found." }],
165
- };
166
- }
167
-
168
- const formatted = notes
169
- .map((n, i) => {
170
- const score = (n.relevance_score * 100).toFixed(0);
171
- const heading = n.heading_chain ? ` — ${n.heading_chain}` : "";
172
- return (
173
- `[${i + 1}] ${n.title} [${n.category}, ${score}%, ${n.age}] (id: ${n.id})${heading}\n` +
174
- n.chunk_content
175
- );
176
- })
177
- .join("\n\n");
178
-
179
- return { content: [{ type: "text" as const, text: formatted }] };
180
- } catch (err) {
181
- return {
182
- content: [
183
- {
184
- type: "text" as const,
185
- text: `Recall failed: ${(err as Error).message}`,
186
- },
187
- ],
188
- isError: true,
189
- };
190
- }
191
- }
192
-
193
- case "memax_push": {
194
- const typedArgs = args as {
195
- content: string;
196
- title?: string;
197
- category?: string;
198
- tags?: string[];
199
- };
200
- try {
201
- const note = await apiPost<NoteResult>("/v1/notes", {
202
- content: typedArgs.content,
203
- title: typedArgs.title ?? "",
204
- category: typedArgs.category ?? "",
205
- tags: typedArgs.tags ?? [],
206
- source: "mcp",
207
- });
208
-
209
- return {
210
- content: [
211
- {
212
- type: "text" as const,
213
- text: `Saved: ${note.title} (id: ${note.id})`,
214
- },
215
- ],
216
- };
217
- } catch (err) {
218
- return {
219
- content: [
220
- {
221
- type: "text" as const,
222
- text: `Push failed: ${(err as Error).message}`,
223
- },
224
- ],
225
- isError: true,
226
- };
227
- }
228
- }
229
-
230
- case "memax_get": {
231
- const typedArgs = args as { id: string };
232
- try {
233
- const note = await apiGet<{
234
- id: string;
235
- title: string;
236
- content: string;
237
- summary: string;
238
- category: string;
239
- tags: string[];
240
- source: string;
241
- source_path: string;
242
- created_at: string;
243
- updated_at: string;
244
- }>(`/v1/notes/${typedArgs.id}`);
245
-
246
- const parts = [
247
- `# ${note.title}`,
248
- `Category: ${note.category} | Source: ${note.source} | Created: ${note.created_at}`,
249
- ];
250
- if (note.tags?.length > 0) {
251
- parts.push(`Tags: ${note.tags.join(", ")}`);
252
- }
253
- if (note.source_path) {
254
- parts.push(`Source: ${note.source_path}`);
255
- }
256
- if (note.summary) {
257
- parts.push(`\n## Summary\n${note.summary}`);
258
- }
259
- parts.push(`\n## Content\n${note.content}`);
260
-
261
- return {
262
- content: [{ type: "text" as const, text: parts.join("\n") }],
263
- };
264
- } catch (err) {
265
- return {
266
- content: [
267
- {
268
- type: "text" as const,
269
- text: `Get failed: ${(err as Error).message}`,
270
- },
271
- ],
272
- isError: true,
273
- };
274
- }
275
- }
276
-
277
- case "memax_search": {
278
- const typedArgs = args as {
279
- category?: string;
280
- limit?: number;
281
- };
282
- try {
283
- const notes = (await apiGet<NoteResult[]>("/v1/notes")) ?? [];
284
-
285
- let filtered = notes;
286
- if (typedArgs.category) {
287
- filtered = notes.filter((n) =>
288
- n.category.startsWith(typedArgs.category!),
289
- );
290
- }
291
-
292
- const limited = filtered.slice(0, typedArgs.limit ?? 10);
293
-
294
- if (limited.length === 0) {
295
- return {
296
- content: [{ type: "text" as const, text: "No notes found." }],
297
- };
298
- }
299
-
300
- const formatted = limited
301
- .map(
302
- (n) => `- ${n.title} [${n.category}] — ${n.source} (id: ${n.id})`,
303
- )
304
- .join("\n");
305
-
306
- return { content: [{ type: "text" as const, text: formatted }] };
307
- } catch (err) {
308
- return {
309
- content: [
310
- {
311
- type: "text" as const,
312
- text: `Search failed: ${(err as Error).message}`,
313
- },
314
- ],
315
- isError: true,
316
- };
317
- }
318
- }
319
-
320
- default:
321
- return {
322
- content: [{ type: "text" as const, text: `Unknown tool: ${name}` }],
323
- isError: true,
324
- };
325
- }
326
- });
327
-
328
- return server;
329
- }
330
-
331
- async function mcpServeCommand(): Promise<void> {
332
- const server = createServer();
333
- const transport = new StdioServerTransport();
334
- await server.connect(transport);
335
-
336
- // Keep the process alive — some agent launchers close stdin early
337
- // which makes Node think the event loop is empty and exit.
338
- await new Promise<void>((resolve) => {
339
- process.on("SIGINT", resolve);
340
- process.on("SIGTERM", resolve);
341
- // Also resolve if stdin closes (transport disconnected)
342
- process.stdin.on("end", resolve);
343
- });
344
-
345
- await server.close();
346
- }
347
-
348
- export function registerMcpCommand(program: Command): void {
349
- const mcp = program
350
- .command("mcp")
351
- .description("Model Context Protocol server for AI agents");
352
-
353
- mcp
354
- .command("serve")
355
- .description("Start MCP server on stdio")
356
- .action(mcpServeCommand);
357
- }
@@ -1,82 +0,0 @@
1
- import chalk from "chalk";
2
- import { readFileSync } from "node:fs";
3
- import { basename } from "node:path";
4
- import { apiPost } from "../lib/api.js";
5
- import type { Note } from "@memaxlabs/shared";
6
-
7
- interface PushOptions {
8
- file?: string;
9
- category?: string;
10
- tags?: string;
11
- ttl?: string;
12
- stdin?: boolean;
13
- title?: string;
14
- }
15
-
16
- export async function pushCommand(options: PushOptions): Promise<void> {
17
- let content: string;
18
- let title = options.title ?? "";
19
- let sourcePath = "";
20
-
21
- if (options.file) {
22
- try {
23
- content = readFileSync(options.file, "utf-8");
24
- sourcePath = options.file;
25
- if (!title) {
26
- title = basename(options.file);
27
- }
28
- } catch (err) {
29
- console.error(chalk.red(`Error reading file: ${options.file}`));
30
- process.exit(1);
31
- }
32
- } else if (options.stdin || !process.stdin.isTTY) {
33
- const chunks: Buffer[] = [];
34
- for await (const chunk of process.stdin) {
35
- chunks.push(chunk);
36
- }
37
- content = Buffer.concat(chunks).toString("utf-8");
38
- } else {
39
- console.error(chalk.red("Provide --file <path> or pipe content via stdin"));
40
- process.exit(1);
41
- }
42
-
43
- if (!content.trim()) {
44
- console.error(chalk.red("No content to push"));
45
- process.exit(1);
46
- }
47
-
48
- const tags = options.tags ? options.tags.split(",").map((t) => t.trim()) : [];
49
-
50
- // Auto-detect URL content: single-line http(s) URL -> content_type "link"
51
- const trimmed = content.trim();
52
- const isURL =
53
- (trimmed.startsWith("http://") || trimmed.startsWith("https://")) &&
54
- !trimmed.includes("\n");
55
-
56
- let contentType = sourcePath.endsWith(".md") ? "markdown" : "text";
57
- if (isURL) {
58
- contentType = "link";
59
- }
60
-
61
- try {
62
- const note = await apiPost<Note>("/v1/notes", {
63
- content,
64
- title,
65
- category: options.category ?? "",
66
- tags,
67
- source: "cli",
68
- source_path: sourcePath,
69
- content_type: contentType,
70
- });
71
-
72
- console.log(chalk.green("Saved"), chalk.bold(note.title));
73
- console.log(
74
- chalk.gray(
75
- ` id: ${note.id} category: ${note.category} source: ${note.source}`,
76
- ),
77
- );
78
- } catch (err) {
79
- console.error(chalk.red(`Push failed: ${(err as Error).message}`));
80
- process.exit(1);
81
- }
82
- }
@@ -1,163 +0,0 @@
1
- import chalk from "chalk";
2
- import { apiPost } from "../lib/api.js";
3
-
4
- interface RecallResult {
5
- notes: Array<{
6
- id: string;
7
- title: string;
8
- chunk_content: string;
9
- heading_chain: string;
10
- relevance_score: number;
11
- category: string;
12
- source: string;
13
- age: string;
14
- }>;
15
- query_metadata: {
16
- intent: string;
17
- total_candidates: number;
18
- latency_ms: number;
19
- };
20
- }
21
-
22
- interface RecallOptions {
23
- category?: string;
24
- tags?: string;
25
- limit?: string;
26
- format?: string;
27
- includeArchived?: boolean;
28
- hook?: boolean;
29
- maxTokens?: string;
30
- }
31
-
32
- export async function recallCommand(
33
- query: string | undefined,
34
- options: RecallOptions,
35
- ): Promise<void> {
36
- if (!query) {
37
- // Read from stdin if no query argument
38
- if (!process.stdin.isTTY) {
39
- const chunks: Buffer[] = [];
40
- for await (const chunk of process.stdin) {
41
- chunks.push(chunk);
42
- }
43
- query = Buffer.concat(chunks).toString("utf-8").trim();
44
- }
45
- if (!query) {
46
- console.error(chalk.red('Provide a query: memax recall "your question"'));
47
- process.exit(1);
48
- }
49
- }
50
-
51
- const limit = parseInt(options.limit ?? "5", 10);
52
-
53
- try {
54
- const result = await apiPost<RecallResult>("/v1/recall", {
55
- query,
56
- category: options.category ?? "",
57
- limit,
58
- include_archived: options.includeArchived ?? false,
59
- source: options.hook ? "hook" : "cli",
60
- working_dir: process.cwd(),
61
- });
62
-
63
- const notes = result.notes ?? [];
64
-
65
- if (options.format === "json") {
66
- console.log(JSON.stringify({ ...result, notes }, null, 2));
67
- return;
68
- }
69
-
70
- // Hook mode: output clean context for agent injection
71
- if (options.hook) {
72
- if (notes.length === 0) return;
73
- let output = "<memax-context>\n";
74
- output += "## Relevant Context (from Memax)\n\n";
75
- for (const note of notes) {
76
- const heading = note.heading_chain ? ` — ${note.heading_chain}` : "";
77
- output += `### ${note.title} [${note.category}, ${note.age}]${heading}\n`;
78
- output += note.chunk_content + "\n\n";
79
- }
80
- output += "</memax-context>";
81
-
82
- // Truncate to fit within token budget (1 token ≈ 4 characters)
83
- const maxTokens = options.maxTokens
84
- ? parseInt(options.maxTokens, 10)
85
- : undefined;
86
- if (maxTokens) {
87
- const maxChars = maxTokens * 4;
88
- if (output.length > maxChars) {
89
- output =
90
- output.substring(0, maxChars - 50) +
91
- "\n\n[truncated to fit token budget]\n</memax-context>";
92
- }
93
- }
94
-
95
- console.log(output);
96
- return;
97
- }
98
-
99
- // Pipe-friendly plain text output when stdout is not a TTY
100
- if (!process.stdout.isTTY) {
101
- if (notes.length === 0) {
102
- return;
103
- }
104
- for (const note of notes) {
105
- const score = (note.relevance_score * 100).toFixed(0);
106
- console.log(
107
- `${note.title} [${note.category}] ${score}% · ${note.age} (${note.id})`,
108
- );
109
- if (note.heading_chain) {
110
- console.log(` ${note.heading_chain}`);
111
- }
112
- const lines = note.chunk_content.split("\n").slice(0, 3);
113
- for (const line of lines) {
114
- console.log(` ${line}`);
115
- }
116
- console.log();
117
- }
118
- return;
119
- }
120
-
121
- // Human-readable output
122
- if (notes.length === 0) {
123
- console.log(chalk.yellow("No results found."));
124
- console.log(
125
- chalk.gray(
126
- ` Searched ${result.query_metadata.total_candidates} chunks in ${result.query_metadata.latency_ms}ms`,
127
- ),
128
- );
129
- return;
130
- }
131
-
132
- console.log(
133
- chalk.blue(`${notes.length} result${notes.length > 1 ? "s" : ""}`),
134
- chalk.gray(
135
- `(${result.query_metadata.total_candidates} chunks searched, ${result.query_metadata.latency_ms}ms)`,
136
- ),
137
- );
138
- console.log();
139
-
140
- for (const note of notes) {
141
- const score = (note.relevance_score * 100).toFixed(0);
142
- console.log(
143
- chalk.bold(note.title),
144
- chalk.gray(`[${note.category}]`),
145
- chalk.cyan(`${score}%`),
146
- chalk.gray(`· ${note.age}`),
147
- );
148
- console.log(chalk.gray(` id: ${note.id}`));
149
- if (note.heading_chain) {
150
- console.log(chalk.gray(` ${note.heading_chain}`));
151
- }
152
- // Show first 3 lines of chunk content
153
- const lines = note.chunk_content.split("\n").slice(0, 3);
154
- for (const line of lines) {
155
- console.log(chalk.white(` ${line}`));
156
- }
157
- console.log();
158
- }
159
- } catch (err) {
160
- console.error(chalk.red(`Recall failed: ${(err as Error).message}`));
161
- process.exit(1);
162
- }
163
- }