@clarionstack/notesia 0.2.0 → 0.2.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/bin/notesia.mjs +5 -2
- package/package.json +1 -1
- package/src/commands.mjs +29 -13
- package/src/io.mjs +5 -1
- package/src/mcp.mjs +2 -2
package/bin/notesia.mjs
CHANGED
|
@@ -18,6 +18,8 @@ if (argv[0] === 'version' || argv[0] === '-v' || argv[0] === '--version') {
|
|
|
18
18
|
process.exit(0);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
const ARG_ERROR_CODES = new Set(['INVALID_ARGS', 'INVALID_OP', 'MISSING_ARGS', 'SELECTOR_REQUIRED']);
|
|
22
|
+
|
|
21
23
|
// Dispatch `notesia import` and `notesia mcp` to dedicated handlers
|
|
22
24
|
if (argv[0] === 'import') {
|
|
23
25
|
runImport(argv.slice(1)).catch((error) => {
|
|
@@ -32,7 +34,8 @@ if (argv[0] === 'import') {
|
|
|
32
34
|
} else {
|
|
33
35
|
runCli(argv).catch((error) => {
|
|
34
36
|
const message = error?.message || 'notesia CLI failed';
|
|
35
|
-
|
|
36
|
-
process.
|
|
37
|
+
const prefix = error?.code ? `${error.code}: ` : '';
|
|
38
|
+
process.stderr.write(`${prefix}${message}\n`);
|
|
39
|
+
process.exit(ARG_ERROR_CODES.has(error?.code) ? 2 : 1);
|
|
37
40
|
});
|
|
38
41
|
}
|
package/package.json
CHANGED
package/src/commands.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
readInputContent as defaultReadInputContent,
|
|
17
17
|
} from './io.mjs';
|
|
18
18
|
|
|
19
|
-
const SUPPORTED_OPS = new Set([
|
|
19
|
+
export const SUPPORTED_OPS = new Set([
|
|
20
20
|
'get',
|
|
21
21
|
'list',
|
|
22
22
|
'store',
|
|
@@ -47,6 +47,7 @@ const OP_ALIASES = new Map([
|
|
|
47
47
|
['retrieve', 'get'],
|
|
48
48
|
['storage', 'store'],
|
|
49
49
|
['whoami', 'auth-status'],
|
|
50
|
+
['folders', 'folder-list'],
|
|
50
51
|
]);
|
|
51
52
|
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
52
53
|
const KB_SESSION_TTL_MS = 24 * 60 * 60 * 1000;
|
|
@@ -168,6 +169,18 @@ function readFlagValue(args, index) {
|
|
|
168
169
|
return value;
|
|
169
170
|
}
|
|
170
171
|
|
|
172
|
+
function parseOptionalFolderId(rawValue, flagName) {
|
|
173
|
+
const normalized = String(rawValue ?? '').trim().toLowerCase();
|
|
174
|
+
if (normalized === '0' || normalized === 'null' || normalized === 'root') {
|
|
175
|
+
return 0;
|
|
176
|
+
}
|
|
177
|
+
const numeric = Number(rawValue);
|
|
178
|
+
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
179
|
+
throw new CliCommandError('INVALID_ARGS', `${flagName} must be a non-negative number (or 0/null/root)`);
|
|
180
|
+
}
|
|
181
|
+
return numeric;
|
|
182
|
+
}
|
|
183
|
+
|
|
171
184
|
export function parseArgs(argv = []) {
|
|
172
185
|
const args = [...argv];
|
|
173
186
|
const rawOp = args.shift();
|
|
@@ -302,10 +315,7 @@ export function parseArgs(argv = []) {
|
|
|
302
315
|
}
|
|
303
316
|
|
|
304
317
|
if (token === '--folder-id') {
|
|
305
|
-
parsed.folderId =
|
|
306
|
-
if (!Number.isFinite(parsed.folderId)) {
|
|
307
|
-
throw new CliCommandError('INVALID_ARGS', '--folder-id must be a number');
|
|
308
|
-
}
|
|
318
|
+
parsed.folderId = parseOptionalFolderId(readFlagValue(args, i), '--folder-id');
|
|
309
319
|
i += 1;
|
|
310
320
|
continue;
|
|
311
321
|
}
|
|
@@ -352,11 +362,7 @@ export function parseArgs(argv = []) {
|
|
|
352
362
|
}
|
|
353
363
|
|
|
354
364
|
if (token === '--parent-id') {
|
|
355
|
-
|
|
356
|
-
if (!Number.isFinite(parentId) || parentId < 0) {
|
|
357
|
-
throw new CliCommandError('INVALID_ARGS', '--parent-id must be a non-negative number');
|
|
358
|
-
}
|
|
359
|
-
parsed.parentId = parentId;
|
|
365
|
+
parsed.parentId = parseOptionalFolderId(readFlagValue(args, i), '--parent-id');
|
|
360
366
|
i += 1;
|
|
361
367
|
continue;
|
|
362
368
|
}
|
|
@@ -413,6 +419,16 @@ export function parseArgs(argv = []) {
|
|
|
413
419
|
continue;
|
|
414
420
|
}
|
|
415
421
|
|
|
422
|
+
if (token === '--tags') {
|
|
423
|
+
const rawTags = readFlagValue(args, i);
|
|
424
|
+
for (const item of rawTags.split(',')) {
|
|
425
|
+
const trimmed = item.trim();
|
|
426
|
+
if (trimmed) parsed.tags.push(trimmed);
|
|
427
|
+
}
|
|
428
|
+
i += 1;
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
|
|
416
432
|
throw new CliCommandError('INVALID_ARGS', `Unknown argument: ${token} `);
|
|
417
433
|
}
|
|
418
434
|
|
|
@@ -449,10 +465,10 @@ function usageText() {
|
|
|
449
465
|
' tags [--format table|json]',
|
|
450
466
|
' tag add --id <id>|--supabase-id <uuid>|--match-title <title> --tag <name> [--tag <name2>]...',
|
|
451
467
|
' tag remove --id <id>|--supabase-id <uuid>|--match-title <title> --tag <name> [--tag <name2>]...',
|
|
452
|
-
' folder list [--format table|json]',
|
|
468
|
+
' folder list [--format table|json] (alias: folders)',
|
|
453
469
|
' folder create --name <name> [--parent-id <id>] [--icon <icon>] [--format text|json]',
|
|
454
470
|
' folder rename --id <id> --name <new> [--format text|json]',
|
|
455
|
-
' folder move --id <id> --parent-id <id> [--format text|json] (0 = root)',
|
|
471
|
+
' folder move --id <id> --parent-id <id> [--format text|json] (0/null = root)',
|
|
456
472
|
' folder delete --id <id> [--format text|json] (empty folders only)',
|
|
457
473
|
' mcp (start stdio MCP server for external AI agents)',
|
|
458
474
|
' sync',
|
|
@@ -528,7 +544,7 @@ function buildPayload(parsed, pipedContent) {
|
|
|
528
544
|
if (parsed.op === 'store') {
|
|
529
545
|
return {
|
|
530
546
|
title: parsed.title || undefined,
|
|
531
|
-
folder_id: parsed.folderId
|
|
547
|
+
folder_id: parsed.folderId === null || parsed.folderId === undefined || parsed.folderId === 0 ? null : parsed.folderId,
|
|
532
548
|
content: parsed.content ?? pipedContent ?? '',
|
|
533
549
|
tags: parsed.tags,
|
|
534
550
|
};
|
package/src/io.mjs
CHANGED
|
@@ -129,7 +129,11 @@ export function printListResult(result, {
|
|
|
129
129
|
|
|
130
130
|
writeStdout(buildListTable(notes));
|
|
131
131
|
if (typeof result?.total === 'number') {
|
|
132
|
-
|
|
132
|
+
const details = [];
|
|
133
|
+
if (typeof result?.offset === 'number' && result.offset > 0) details.push(`offset: ${result.offset}`);
|
|
134
|
+
if (result?.has_more) details.push('more available');
|
|
135
|
+
const suffix = details.length > 0 ? ` (${details.join(', ')})` : '';
|
|
136
|
+
writeStdout(`Total: ${result.total}${suffix}\n`);
|
|
133
137
|
}
|
|
134
138
|
}
|
|
135
139
|
|
package/src/mcp.mjs
CHANGED
|
@@ -385,7 +385,7 @@ const TOOL_BY_NAME = new Map(MCP_TOOLS.map((tool) => [tool.name, tool]));
|
|
|
385
385
|
|
|
386
386
|
export function createMcpMessageHandler({
|
|
387
387
|
requestBridge = defaultRequestBridge,
|
|
388
|
-
serverVersion = '0.2.
|
|
388
|
+
serverVersion = '0.2.1',
|
|
389
389
|
} = {}) {
|
|
390
390
|
return async function handleMcpMessage(message) {
|
|
391
391
|
if (!message || typeof message !== 'object' || message.jsonrpc !== '2.0') {
|
|
@@ -545,7 +545,7 @@ export async function runMcpServer(args = [], {
|
|
|
545
545
|
stdout = process.stdout,
|
|
546
546
|
stderr = process.stderr,
|
|
547
547
|
requestBridge = defaultRequestBridge,
|
|
548
|
-
serverVersion = '0.2.
|
|
548
|
+
serverVersion = '0.2.1',
|
|
549
549
|
} = {}) {
|
|
550
550
|
if (args.includes('--help') || args.includes('-h')) {
|
|
551
551
|
stdout.write(mcpUsageText());
|