memax-cli 0.1.0-alpha.3 → 0.1.0-alpha.30

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 (127) hide show
  1. package/assets/skills/memax-memory/SKILL.md +154 -0
  2. package/dist/commands/agent-sessions.d.ts +32 -0
  3. package/dist/commands/agent-sessions.d.ts.map +1 -0
  4. package/dist/commands/agent-sessions.js +761 -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 +82 -0
  9. package/dist/commands/agent-sessions.test.js.map +1 -0
  10. package/dist/commands/auth.d.ts +1 -0
  11. package/dist/commands/auth.d.ts.map +1 -1
  12. package/dist/commands/auth.js +14 -7
  13. package/dist/commands/auth.js.map +1 -1
  14. package/dist/commands/capture.d.ts +17 -0
  15. package/dist/commands/capture.d.ts.map +1 -0
  16. package/dist/commands/capture.js +61 -0
  17. package/dist/commands/capture.js.map +1 -0
  18. package/dist/commands/delete.d.ts +1 -1
  19. package/dist/commands/delete.d.ts.map +1 -1
  20. package/dist/commands/delete.js +22 -5
  21. package/dist/commands/delete.js.map +1 -1
  22. package/dist/commands/hub.d.ts +4 -0
  23. package/dist/commands/hub.d.ts.map +1 -0
  24. package/dist/commands/hub.js +53 -0
  25. package/dist/commands/hub.js.map +1 -0
  26. package/dist/commands/list.d.ts +2 -1
  27. package/dist/commands/list.d.ts.map +1 -1
  28. package/dist/commands/list.js +35 -8
  29. package/dist/commands/list.js.map +1 -1
  30. package/dist/commands/login.d.ts.map +1 -1
  31. package/dist/commands/login.js +27 -5
  32. package/dist/commands/login.js.map +1 -1
  33. package/dist/commands/mcp.d.ts.map +1 -1
  34. package/dist/commands/mcp.js +275 -42
  35. package/dist/commands/mcp.js.map +1 -1
  36. package/dist/commands/push.d.ts +4 -1
  37. package/dist/commands/push.d.ts.map +1 -1
  38. package/dist/commands/push.js +51 -11
  39. package/dist/commands/push.js.map +1 -1
  40. package/dist/commands/recall.d.ts +7 -0
  41. package/dist/commands/recall.d.ts.map +1 -1
  42. package/dist/commands/recall.js +164 -39
  43. package/dist/commands/recall.js.map +1 -1
  44. package/dist/commands/recall.test.d.ts +2 -0
  45. package/dist/commands/recall.test.d.ts.map +1 -0
  46. package/dist/commands/recall.test.js +31 -0
  47. package/dist/commands/recall.test.js.map +1 -0
  48. package/dist/commands/setup-hooks.d.ts +12 -0
  49. package/dist/commands/setup-hooks.d.ts.map +1 -0
  50. package/dist/commands/setup-hooks.js +193 -0
  51. package/dist/commands/setup-hooks.js.map +1 -0
  52. package/dist/commands/setup-instructions.d.ts +21 -0
  53. package/dist/commands/setup-instructions.d.ts.map +1 -0
  54. package/dist/commands/setup-instructions.js +172 -0
  55. package/dist/commands/setup-instructions.js.map +1 -0
  56. package/dist/commands/setup-mcp.d.ts +14 -0
  57. package/dist/commands/setup-mcp.d.ts.map +1 -0
  58. package/dist/commands/setup-mcp.js +278 -0
  59. package/dist/commands/setup-mcp.js.map +1 -0
  60. package/dist/commands/setup-types.d.ts +20 -0
  61. package/dist/commands/setup-types.d.ts.map +1 -0
  62. package/dist/commands/setup-types.js +60 -0
  63. package/dist/commands/setup-types.js.map +1 -0
  64. package/dist/commands/setup.d.ts +6 -1
  65. package/dist/commands/setup.d.ts.map +1 -1
  66. package/dist/commands/setup.js +146 -306
  67. package/dist/commands/setup.js.map +1 -1
  68. package/dist/commands/show.d.ts.map +1 -1
  69. package/dist/commands/show.js +10 -13
  70. package/dist/commands/show.js.map +1 -1
  71. package/dist/commands/sync.d.ts +33 -2
  72. package/dist/commands/sync.d.ts.map +1 -1
  73. package/dist/commands/sync.js +1066 -119
  74. package/dist/commands/sync.js.map +1 -1
  75. package/dist/commands/sync.test.d.ts +2 -0
  76. package/dist/commands/sync.test.d.ts.map +1 -0
  77. package/dist/commands/sync.test.js +130 -0
  78. package/dist/commands/sync.test.js.map +1 -0
  79. package/dist/commands/topic.d.ts +20 -0
  80. package/dist/commands/topic.d.ts.map +1 -0
  81. package/dist/commands/topic.js +87 -0
  82. package/dist/commands/topic.js.map +1 -0
  83. package/dist/index.js +131 -14
  84. package/dist/index.js.map +1 -1
  85. package/dist/lib/client.d.ts +7 -0
  86. package/dist/lib/client.d.ts.map +1 -0
  87. package/dist/lib/client.js +72 -0
  88. package/dist/lib/client.js.map +1 -0
  89. package/dist/lib/config.d.ts +42 -0
  90. package/dist/lib/config.d.ts.map +1 -1
  91. package/dist/lib/config.js +63 -0
  92. package/dist/lib/config.js.map +1 -1
  93. package/dist/lib/project-context.d.ts +50 -0
  94. package/dist/lib/project-context.d.ts.map +1 -0
  95. package/dist/lib/project-context.js +201 -0
  96. package/dist/lib/project-context.js.map +1 -0
  97. package/dist/lib/project-context.test.d.ts +2 -0
  98. package/dist/lib/project-context.test.d.ts.map +1 -0
  99. package/dist/lib/project-context.test.js +75 -0
  100. package/dist/lib/project-context.test.js.map +1 -0
  101. package/dist/lib/prompt.d.ts +7 -0
  102. package/dist/lib/prompt.d.ts.map +1 -0
  103. package/dist/lib/prompt.js +41 -0
  104. package/dist/lib/prompt.js.map +1 -0
  105. package/package.json +17 -13
  106. package/.vscode/mcp.json +0 -8
  107. package/dist/lib/api.d.ts +0 -4
  108. package/dist/lib/api.d.ts.map +0 -1
  109. package/dist/lib/api.js +0 -95
  110. package/dist/lib/api.js.map +0 -1
  111. package/src/commands/auth.ts +0 -92
  112. package/src/commands/config.ts +0 -27
  113. package/src/commands/delete.ts +0 -20
  114. package/src/commands/hook.ts +0 -243
  115. package/src/commands/list.ts +0 -38
  116. package/src/commands/login.ts +0 -162
  117. package/src/commands/mcp.ts +0 -357
  118. package/src/commands/push.ts +0 -82
  119. package/src/commands/recall.ts +0 -163
  120. package/src/commands/setup.ts +0 -682
  121. package/src/commands/show.ts +0 -35
  122. package/src/commands/sync.ts +0 -403
  123. package/src/index.ts +0 -192
  124. package/src/lib/api.ts +0 -110
  125. package/src/lib/config.ts +0 -61
  126. package/src/lib/credentials.ts +0 -42
  127. package/tsconfig.json +0 -9
@@ -1,162 +0,0 @@
1
- import { createServer } from "node:http";
2
- import { loadConfig } from "../lib/config.js";
3
- import { saveCredentials } from "../lib/credentials.js";
4
-
5
- interface TokenPair {
6
- access_token: string;
7
- refresh_token: string;
8
- expires_in: number;
9
- }
10
-
11
- export async function loginCommand(): Promise<void> {
12
- const config = loadConfig();
13
- const apiUrl = config.api_url;
14
-
15
- // Start a temporary local server to receive the OAuth callback
16
- const port = await findFreePort();
17
- const callbackUrl = `http://localhost:${port}/callback`;
18
-
19
- const tokenPromise = new Promise<TokenPair>((resolve, reject) => {
20
- const server = createServer(async (req, res) => {
21
- const url = new URL(req.url!, `http://localhost:${port}`);
22
-
23
- if (url.pathname === "/callback") {
24
- const code = url.searchParams.get("code");
25
-
26
- if (code) {
27
- // Exchange the one-time code for tokens via POST
28
- try {
29
- const exchangeRes = await fetch(`${apiUrl}/v1/auth/exchange`, {
30
- method: "POST",
31
- headers: { "Content-Type": "application/json" },
32
- body: JSON.stringify({ code }),
33
- });
34
- const json = (await exchangeRes.json()) as {
35
- data?: TokenPair;
36
- error?: { message: string };
37
- };
38
-
39
- if (json.data) {
40
- res.writeHead(200, { "Content-Type": "text/html" });
41
- res.end(`
42
- <html><body style="font-family: system-ui; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0;">
43
- <div style="text-align: center;">
44
- <h2 style="font-weight: 600;">Logged in to Memax</h2>
45
- <p style="color: #64748b;">You can close this tab and return to your terminal.</p>
46
- </div>
47
- </body></html>
48
- `);
49
- resolve(json.data);
50
- } else {
51
- res.writeHead(400, { "Content-Type": "text/html" });
52
- res.end(
53
- `<html><body><h2>Login failed</h2><p>${json.error?.message ?? "Token exchange failed."}</p></body></html>`,
54
- );
55
- reject(
56
- new Error(json.error?.message ?? "Token exchange failed."),
57
- );
58
- }
59
- } catch (err) {
60
- res.writeHead(500, { "Content-Type": "text/html" });
61
- res.end(
62
- "<html><body><h2>Login failed</h2><p>Could not reach Memax API.</p></body></html>",
63
- );
64
- reject(new Error("Could not reach Memax API for token exchange."));
65
- }
66
- } else {
67
- res.writeHead(400, { "Content-Type": "text/html" });
68
- res.end(
69
- "<html><body><h2>Login failed</h2><p>No authorization code received.</p></body></html>",
70
- );
71
- reject(new Error("No authorization code received from callback."));
72
- }
73
-
74
- // Close the server and force-kill connections so the process exits
75
- setTimeout(() => {
76
- server.close();
77
- server.closeAllConnections();
78
- }, 500);
79
- }
80
- });
81
-
82
- server.listen(port);
83
-
84
- // Timeout after 2 minutes
85
- setTimeout(() => {
86
- server.close();
87
- reject(
88
- new Error("Login timed out — no callback received within 2 minutes."),
89
- );
90
- }, 120_000);
91
- });
92
-
93
- // Build the GitHub OAuth URL with our local callback as the redirect
94
- const authUrl = `${apiUrl}/v1/auth/github?redirect_uri=${encodeURIComponent(callbackUrl)}`;
95
-
96
- console.log("\n Opening browser for GitHub login...\n");
97
- console.log(` If the browser doesn't open, visit:\n ${authUrl}\n`);
98
-
99
- // Try to open the browser
100
- try {
101
- const { exec } = await import("node:child_process");
102
- const cmd =
103
- process.platform === "darwin"
104
- ? `open "${authUrl}"`
105
- : process.platform === "win32"
106
- ? `start "${authUrl}"`
107
- : `xdg-open "${authUrl}"`;
108
- exec(cmd);
109
- } catch {
110
- // Browser open failed — user can copy the URL
111
- }
112
-
113
- try {
114
- const tokens = await tokenPromise;
115
- saveCredentials({
116
- access_token: tokens.access_token,
117
- refresh_token: tokens.refresh_token,
118
- expires_at: Date.now() + tokens.expires_in * 1000,
119
- });
120
- console.log(
121
- " Logged in successfully. Credentials saved to ~/.memax/credentials.json\n",
122
- );
123
- } catch (err) {
124
- console.error(` Login failed: ${(err as Error).message}\n`);
125
- process.exit(1);
126
- }
127
- }
128
-
129
- export async function logoutCommand(): Promise<void> {
130
- const { clearCredentials } = await import("../lib/credentials.js");
131
- clearCredentials();
132
- console.log(" Logged out. Credentials cleared.\n");
133
- }
134
-
135
- export async function whoamiCommand(): Promise<void> {
136
- const { loadCredentials } = await import("../lib/credentials.js");
137
- const { apiGet } = await import("../lib/api.js");
138
-
139
- const creds = loadCredentials();
140
- if (!creds?.access_token) {
141
- console.log(" Not logged in. Run: memax login\n");
142
- return;
143
- }
144
-
145
- try {
146
- const user = await apiGet<{ name: string; email: string }>("/v1/auth/me");
147
- console.log(` ${user.name} (${user.email})\n`);
148
- } catch {
149
- console.log(" Session expired or invalid. Run: memax login\n");
150
- }
151
- }
152
-
153
- async function findFreePort(): Promise<number> {
154
- return new Promise((resolve) => {
155
- const server = createServer();
156
- server.listen(0, () => {
157
- const addr = server.address();
158
- const port = typeof addr === "object" && addr ? addr.port : 0;
159
- server.close(() => resolve(port));
160
- });
161
- });
162
- }
@@ -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
- }