memax-cli 0.0.1 → 0.1.0-alpha.10

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 (91) hide show
  1. package/.vscode/mcp.json +8 -0
  2. package/dist/commands/auth.d.ts +6 -0
  3. package/dist/commands/auth.d.ts.map +1 -0
  4. package/dist/commands/auth.js +62 -0
  5. package/dist/commands/auth.js.map +1 -0
  6. package/dist/commands/capture.d.ts +17 -0
  7. package/dist/commands/capture.d.ts.map +1 -0
  8. package/dist/commands/capture.js +61 -0
  9. package/dist/commands/capture.js.map +1 -0
  10. package/dist/commands/config.d.ts +3 -0
  11. package/dist/commands/config.d.ts.map +1 -0
  12. package/dist/commands/config.js +24 -0
  13. package/dist/commands/config.js.map +1 -0
  14. package/dist/commands/delete.d.ts +4 -0
  15. package/dist/commands/delete.d.ts.map +1 -0
  16. package/dist/commands/delete.js +45 -0
  17. package/dist/commands/delete.js.map +1 -0
  18. package/dist/commands/hook.d.ts +2 -0
  19. package/dist/commands/hook.d.ts.map +1 -0
  20. package/dist/commands/hook.js +189 -0
  21. package/dist/commands/hook.js.map +1 -0
  22. package/dist/commands/list.d.ts +8 -0
  23. package/dist/commands/list.d.ts.map +1 -0
  24. package/dist/commands/list.js +23 -0
  25. package/dist/commands/list.js.map +1 -0
  26. package/dist/commands/login.d.ts +4 -0
  27. package/dist/commands/login.d.ts.map +1 -0
  28. package/dist/commands/login.js +131 -0
  29. package/dist/commands/login.js.map +1 -0
  30. package/dist/commands/mcp.d.ts +3 -0
  31. package/dist/commands/mcp.d.ts.map +1 -0
  32. package/dist/commands/mcp.js +384 -0
  33. package/dist/commands/mcp.js.map +1 -0
  34. package/dist/commands/push.d.ts +11 -0
  35. package/dist/commands/push.d.ts.map +1 -0
  36. package/dist/commands/push.js +98 -0
  37. package/dist/commands/push.js.map +1 -0
  38. package/dist/commands/recall.d.ts +12 -0
  39. package/dist/commands/recall.d.ts.map +1 -0
  40. package/dist/commands/recall.js +107 -0
  41. package/dist/commands/recall.js.map +1 -0
  42. package/dist/commands/setup.d.ts +16 -0
  43. package/dist/commands/setup.d.ts.map +1 -0
  44. package/dist/commands/setup.js +869 -0
  45. package/dist/commands/setup.js.map +1 -0
  46. package/dist/commands/show.d.ts +2 -0
  47. package/dist/commands/show.d.ts.map +1 -0
  48. package/dist/commands/show.js +29 -0
  49. package/dist/commands/show.js.map +1 -0
  50. package/dist/commands/sync.d.ts +12 -0
  51. package/dist/commands/sync.d.ts.map +1 -0
  52. package/dist/commands/sync.js +414 -0
  53. package/dist/commands/sync.js.map +1 -0
  54. package/dist/index.d.ts +3 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +168 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/lib/api.d.ts +4 -0
  59. package/dist/lib/api.d.ts.map +1 -0
  60. package/dist/lib/api.js +95 -0
  61. package/dist/lib/api.js.map +1 -0
  62. package/dist/lib/config.d.ts +10 -0
  63. package/dist/lib/config.d.ts.map +1 -0
  64. package/dist/lib/config.js +49 -0
  65. package/dist/lib/config.js.map +1 -0
  66. package/dist/lib/credentials.d.ts +11 -0
  67. package/dist/lib/credentials.d.ts.map +1 -0
  68. package/dist/lib/credentials.js +36 -0
  69. package/dist/lib/credentials.js.map +1 -0
  70. package/package.json +39 -4
  71. package/src/commands/auth.ts +92 -0
  72. package/src/commands/capture.ts +86 -0
  73. package/src/commands/config.ts +27 -0
  74. package/src/commands/delete.ts +58 -0
  75. package/src/commands/hook.ts +243 -0
  76. package/src/commands/list.ts +38 -0
  77. package/src/commands/login.ts +164 -0
  78. package/src/commands/mcp.ts +490 -0
  79. package/src/commands/push.ts +137 -0
  80. package/src/commands/recall.ts +163 -0
  81. package/src/commands/setup.ts +1129 -0
  82. package/src/commands/show.ts +35 -0
  83. package/src/commands/sync.ts +506 -0
  84. package/src/index.ts +223 -0
  85. package/src/lib/api.ts +110 -0
  86. package/src/lib/config.ts +61 -0
  87. package/src/lib/credentials.ts +42 -0
  88. package/tsconfig.json +9 -0
  89. package/LICENSE +0 -24
  90. package/README.md +0 -2
  91. package/bin/memax.js +0 -13
@@ -0,0 +1,163 @@
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
+ }