roam-research-mcp 4.1.0 → 5.0.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/README.md +17 -0
- package/build/cli/commands/save.js +26 -12
- package/build/cli/utils/ref-classifier.js +26 -4
- package/build/cli/utils/ref-resolver.js +6 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,21 @@ Whether you want to give Claude superpowers over your knowledge base or just wan
|
|
|
20
20
|
|
|
21
21
|

|
|
22
22
|
|
|
23
|
+
## What's New in v5.0
|
|
24
|
+
|
|
25
|
+
**In one line:** `roam save` now has one flag for each way of naming a parent block, and neither one guesses. `--parent-uid` is always a UID; `--parent` is always text.
|
|
26
|
+
|
|
27
|
+
Until 4.1.0, `--parent` took either a block UID or heading text and decided which by looking for a digit in the value. About one Roam UID in five has no digit, so those saves were silently misrouted. 4.1.0 added `--parent-uid` and deprecated passing a UID to `--parent`. 5.0 finishes the split.
|
|
28
|
+
|
|
29
|
+
- **`--parent-uid <uid>`** nests under the block with that UID. It accepts `uid` or `((uid))`, and if no such block exists the command exits non-zero and writes nothing.
|
|
30
|
+
- **`--parent "<text>"`** nests under the block with that text on the target page, creating it if missing. It is never read as a UID. `--parent "((uid))"` finds or creates a block whose content is that reference, which was not reliably possible before.
|
|
31
|
+
- **Creating a parent block is announced** on stderr, with its UID. If the text you gave `--parent` looks like a UID, a second line says what happened and gives the `--parent-uid` command to use instead. Stdout is unchanged.
|
|
32
|
+
- **`roam save --help` leads with the choice.** A "Choosing a parent block" section sits above the examples, so the difference between the two flags is the first thing you read.
|
|
33
|
+
|
|
34
|
+
**Why a major.** `roam save --parent "((uid))"` and `roam save --parent <uid>` used to nest under that block and now nest under a block containing that text. **If a script passes a UID to `--parent`, change the flag to `--parent-uid`.** Only the CLI is affected: the MCP tools take `parent-uid` as a typed field and behave exactly as before, so if you use the server through an AI assistant, nothing is required of you.
|
|
35
|
+
|
|
36
|
+
Full detail is in the [changelog](CHANGELOG.md).
|
|
37
|
+
|
|
23
38
|
## What's New in v4.0
|
|
24
39
|
|
|
25
40
|
**In one line:** a block containing a soft line break (Shift+Enter) now survives a page rewrite. Read a page, write it back, and nothing moves.
|
|
@@ -180,6 +195,8 @@ Three things worth knowing:
|
|
|
180
195
|
- **Read tools deliberately have neither.** They already serialise their whole result into the text channel, so a schema would just double the payload.
|
|
181
196
|
- **These fields are additive-only.** Some clients validate live responses against a cached tool list, so a field will be added or deprecated — never renamed or removed outside a major version.
|
|
182
197
|
|
|
198
|
+
> **Upgrading to 5.0.0:** CLI only. `roam save --parent` is now always text, so a script passing a block UID to it (`--parent "((uid))"` or `--parent <uid>`) must switch to `--parent-uid`. Left unchanged, such a call exits 0 and nests your content under a new block containing the reference, on the daily page unless `-p` is given. MCP tools are unaffected. See the [changelog](CHANGELOG.md).
|
|
199
|
+
|
|
183
200
|
> **Upgrading to 4.0.0:** markdown reads of a page containing a soft line break (Shift+Enter) now render that break as `⏎` and carry a leading `<!-- roam:escaped-newlines -->` marker, so the page survives a write-back intact. Pages without multi-line blocks are byte-identical to 3.x. AI-assistant users need do nothing; scripts parsing markdown output of multi-line pages see the new encoding. See the [changelog](CHANGELOG.md).
|
|
184
201
|
|
|
185
202
|
> **Upgrading from 2.x:** three write-result fields were renamed — `uid` → `page_uid` (`roam_create_page`), `created_uids` → `created_blocks` (`roam_create_outline`, `roam_import_markdown`) and `preservedUids` → `preserved_uids` (`roam_update_page_markdown`). This only affects code that reads those names; if you use the server through an AI assistant, nothing changes. See the [changelog](CHANGELOG.md) for why.
|
|
@@ -9,6 +9,7 @@ import { printDebug, exitWithError } from '../utils/output.js';
|
|
|
9
9
|
import { resolveGraph } from '../utils/graph.js';
|
|
10
10
|
import { readStdin } from '../utils/input.js';
|
|
11
11
|
import { resolveParentRef, resolvePageRef } from '../utils/ref-resolver.js';
|
|
12
|
+
import { parentUidHint } from '../utils/ref-classifier.js';
|
|
12
13
|
import { uidExists } from '../../shared/page-validator.js';
|
|
13
14
|
import { formatRoamDate, sanitizeTagName } from '../../utils/helpers.js';
|
|
14
15
|
import { q, createPage as roamCreatePage } from '@roam-research/roam-api-sdk';
|
|
@@ -180,8 +181,8 @@ export function createSaveCommand() {
|
|
|
180
181
|
.option('--title <title>', 'Create a new page with this title')
|
|
181
182
|
.option('--update', 'Update existing page using smart diff (preserves block UIDs)')
|
|
182
183
|
.option('-p, --page <ref>', 'Target page by title (creates if missing), or by UID as ((uid)) (must exist). Default: daily page')
|
|
183
|
-
.option('--parent <text>', 'Nest under the block with this
|
|
184
|
-
.option('--parent-uid <uid>', 'Nest under the block with this UID
|
|
184
|
+
.option('--parent <text>', 'Nest under the block with this TEXT on the target page (creates if missing). Never a UID: to nest under a block by its UID, use --parent-uid. Use # prefix for heading level: "## Section"')
|
|
185
|
+
.option('--parent-uid <uid>', 'Nest under the block with this UID. Accepts uid or ((uid)). The block must exist, or nothing is written')
|
|
185
186
|
.option('-c, --categories <tags>', 'Comma-separated tags appended to first block')
|
|
186
187
|
.option('-t, --todo [text]', 'Add TODO item(s) to daily page. Accepts inline text or stdin')
|
|
187
188
|
.option('--json', 'Force JSON array format: [{text, level, heading?}, ...]')
|
|
@@ -192,15 +193,28 @@ export function createSaveCommand() {
|
|
|
192
193
|
.option('--write-key <key>', 'Write confirmation key (non-default graphs)')
|
|
193
194
|
.option('--debug', 'Show debug information')
|
|
194
195
|
.addHelpText('after', `
|
|
196
|
+
Choosing a parent block:
|
|
197
|
+
You know the block's UID -> --parent-uid <uid>
|
|
198
|
+
Content goes under that block. If no block has that UID, the command
|
|
199
|
+
fails and nothing is written. The block already has a page, so -p is
|
|
200
|
+
ignored.
|
|
201
|
+
You know the block's text -> --parent "<text>"
|
|
202
|
+
Content goes under the block with that text on the target page (the
|
|
203
|
+
daily page unless -p is given). The block is created if missing, and
|
|
204
|
+
stderr says so.
|
|
205
|
+
--parent is never a UID. --parent "((uid))" means a block containing that
|
|
206
|
+
reference, not the referenced block. Before 5.0 it meant the block itself.
|
|
207
|
+
|
|
195
208
|
Examples:
|
|
196
209
|
# Quick saves to daily page
|
|
197
210
|
roam save "Quick note" # Single block
|
|
198
211
|
roam save "# Important" -c "work,urgent" # H1 heading with tags
|
|
199
212
|
roam save --todo "Buy groceries" # TODO item
|
|
200
213
|
|
|
201
|
-
# Save under
|
|
202
|
-
roam save --parent
|
|
203
|
-
roam save --parent
|
|
214
|
+
# Save under a parent block (see "Choosing a parent block" above)
|
|
215
|
+
roam save --parent-uid blockUid9 "Child" # Under the block with this UID
|
|
216
|
+
roam save --parent "## Notes" "My note" # Under H2 "Notes" (creates if missing)
|
|
217
|
+
roam save --parent "((blockUid9))" "Child" # Under a block CONTAINING that reference
|
|
204
218
|
|
|
205
219
|
# Target specific page
|
|
206
220
|
roam save -p "Project X" "Status update" # By title (creates if missing)
|
|
@@ -386,9 +400,8 @@ JSON format (--json):
|
|
|
386
400
|
console.error('');
|
|
387
401
|
}
|
|
388
402
|
const graph = resolveGraph(options, true);
|
|
389
|
-
// Resolve the parent before any write.
|
|
390
|
-
//
|
|
391
|
-
// --parent value is a UID only if the graph has it.
|
|
403
|
+
// Resolve the parent before any write. --parent-uid is always a UID
|
|
404
|
+
// and must exist; --parent is always the text of the parent block.
|
|
392
405
|
const exists = (uid) => uidExists(graph, uid);
|
|
393
406
|
const parentTarget = await resolveParentRef({ parent: options.parent, parentUid: options.parentUid }, exists);
|
|
394
407
|
let parentUid;
|
|
@@ -396,10 +409,6 @@ JSON format (--json):
|
|
|
396
409
|
let parentHeadingLevel;
|
|
397
410
|
if (parentTarget?.kind === 'uid') {
|
|
398
411
|
parentUid = parentTarget.uid;
|
|
399
|
-
if (parentTarget.deprecated) {
|
|
400
|
-
console.error(`Warning: passing a block UID to --parent is deprecated. In 5.0 --parent will always mean ` +
|
|
401
|
-
`the text of the parent block. Use: --parent-uid ${parentUid}`);
|
|
402
|
-
}
|
|
403
412
|
}
|
|
404
413
|
else if (parentTarget) {
|
|
405
414
|
// Parse heading syntax from parent text
|
|
@@ -537,6 +546,11 @@ JSON format (--json):
|
|
|
537
546
|
targetParentUid = heading.uid;
|
|
538
547
|
if (heading.created) {
|
|
539
548
|
console.error(`Created parent block "${parentHeading}" (uid: ${heading.uid})`);
|
|
549
|
+
// Through 4.1.0 a UID here nested under that block. Say what
|
|
550
|
+
// happened instead, and how to get the other behaviour.
|
|
551
|
+
const hint = parentUidHint(options.parent ?? '');
|
|
552
|
+
if (hint)
|
|
553
|
+
console.error(hint);
|
|
540
554
|
}
|
|
541
555
|
}
|
|
542
556
|
else {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Classify a `roam save` reference
|
|
3
|
-
*
|
|
2
|
+
* Classify a `roam save --page` reference by what its shape can actually
|
|
3
|
+
* establish. Pure: no graph access. (`--parent` is always text; its value is
|
|
4
|
+
* classified only to word the hint in `parentUidHint`. `--parent-uid` is
|
|
5
|
+
* parsed by `parseUidFlag`.)
|
|
4
6
|
*
|
|
5
7
|
* This replaces a heuristic that required a digit before believing a value was
|
|
6
|
-
* a UID. About one block UID in five has no digit, so
|
|
7
|
-
*
|
|
8
|
+
* a UID. About one block UID in five has no digit, so a wrapped UID silently
|
|
9
|
+
* became text for those. Shape alone cannot tell a bare
|
|
8
10
|
* 9-character UID from a 9-character title like "Learnings"; that case is
|
|
9
11
|
* reported as `ambiguous` and the caller asks the graph.
|
|
10
12
|
*/
|
|
@@ -32,3 +34,23 @@ export function parseUidFlag(raw) {
|
|
|
32
34
|
}
|
|
33
35
|
return candidate;
|
|
34
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* `--parent` is always text. When its value is UID-shaped, the caller may have
|
|
39
|
+
* meant the block with that UID, which is what the same call did through
|
|
40
|
+
* 4.1.0. Returns the line that says so and names the flag to use, or undefined
|
|
41
|
+
* when the value is plainly text. Shape only: no graph access, so it cannot
|
|
42
|
+
* know whether such a block exists.
|
|
43
|
+
*/
|
|
44
|
+
export function parentUidHint(parent) {
|
|
45
|
+
const ref = classifyRef(parent);
|
|
46
|
+
switch (ref.kind) {
|
|
47
|
+
case 'uid':
|
|
48
|
+
return (`Note: --parent is always text, so this created a block containing that reference. ` +
|
|
49
|
+
`To nest under block ${ref.uid} itself, use: --parent-uid ${ref.uid}`);
|
|
50
|
+
case 'ambiguous':
|
|
51
|
+
return (`Note: --parent is always text, so "${ref.value}" was used as the block's text. ` +
|
|
52
|
+
`If it is a block UID, nest under that block with: --parent-uid ${ref.value}`);
|
|
53
|
+
case 'text':
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Resolve `roam save`'s `--parent-uid`, `--parent` and `--page` values to a
|
|
3
3
|
* target, asking the graph only where shape cannot decide.
|
|
4
4
|
*
|
|
5
|
+
* The two parent flags never overlap: `--parent-uid` is always a UID and
|
|
6
|
+
* `--parent` is always the text of the parent block, so `--parent "((uid))"`
|
|
7
|
+
* means a block whose content is that reference.
|
|
8
|
+
*
|
|
5
9
|
* Nothing here writes. Callers resolve every reference before their first
|
|
6
10
|
* write, so a reference that cannot be resolved leaves the graph untouched.
|
|
7
11
|
*/
|
|
@@ -19,21 +23,11 @@ export async function resolveParentRef(options, exists) {
|
|
|
19
23
|
}
|
|
20
24
|
if (parentUid !== undefined) {
|
|
21
25
|
const uid = await requireUid(parseUidFlag(parentUid), '--parent-uid', exists);
|
|
22
|
-
return { kind: 'uid', uid
|
|
26
|
+
return { kind: 'uid', uid };
|
|
23
27
|
}
|
|
24
28
|
if (parent === undefined)
|
|
25
29
|
return undefined;
|
|
26
|
-
|
|
27
|
-
switch (ref.kind) {
|
|
28
|
-
case 'uid':
|
|
29
|
-
return { kind: 'uid', uid: await requireUid(ref.uid, '--parent', exists), deprecated: true };
|
|
30
|
-
case 'ambiguous':
|
|
31
|
-
return (await exists(ref.value))
|
|
32
|
-
? { kind: 'uid', uid: ref.value, deprecated: true }
|
|
33
|
-
: { kind: 'heading', text: ref.value };
|
|
34
|
-
case 'text':
|
|
35
|
-
return { kind: 'heading', text: ref.value };
|
|
36
|
-
}
|
|
30
|
+
return { kind: 'heading', text: parent };
|
|
37
31
|
}
|
|
38
32
|
export async function resolvePageRef(page, exists) {
|
|
39
33
|
const ref = classifyRef(page);
|