roam-research-mcp 4.0.1 → 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 CHANGED
@@ -20,6 +20,21 @@ Whether you want to give Claude superpowers over your knowledge base or just wan
20
20
 
21
21
  ![Before and after: copy-pasting notes into Roam by hand, versus Claude and your terminal reading and writing the graph directly — install with npm i -g roam-research-mcp, then `roam save "idea"` or pipe with `echo "Buy milk" | roam save --todo`](./roam-research-mcp-sketchnote.png)
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.
@@ -369,46 +369,30 @@ This cheatsheet is syntax only. How to tag, when to use a page ref versus a hash
369
369
 
370
370
  ---
371
371
  <personalization_layer>
372
- # Roam: Nova operating notes (server-side supplement)
373
372
 
374
- Style conventions (voice, `#Nova` attribution, tagging, namespacing, formatting) live on the `[[roam/agent guidelines]]` page and arrive through `roam_get_guidelines`. This file carries only what that page deliberately leaves out: the mechanics behind the `#@Nova` handshake, so an interactive session produces the same artifacts as the nightly job and neither one answers a block twice.
373
+ # Roam Preferences — Personalization Layer
375
374
 
376
- ## The `#@Nova` handshake: mechanics
375
+ > This section contains YOUR specific conventions, tagging philosophy, and graph-specific rules. Customize to match your workflow.
376
+
377
+ ---
378
+
379
+ ## Graph-Level Behaviors
380
+
381
+
382
+ ## Tagging Philosophy
383
+
384
+
385
+ ## Formatting Conventions
377
386
 
378
- Ownership rules are on the guidelines page (`#@Nova` is Ian's, `#@Nova-DONE` is Nova's, never self-tag). What follows is the output shape the nightly job writes and checks for.
379
387
 
380
- ### Reading the request
381
- - The request is the tagged block's text with `#@Nova` removed, plus every child block that is not a `[NOVA]` reply, read as further instructions.
382
- - Context is the page title, the ancestor chain, and the sibling blocks under the same parent. Fetch any URL present before answering.
383
- - Empty tag line and no children means "review and respond to the surrounding context."
388
+ ## Constraints & Guardrails
384
389
 
385
- ### Writing the reply
386
- - First child of the tagged block: `[NOVA] <one-line summary, at most 150 characters>`.
387
- - The rest of the reply nests under that `[NOVA]` block as ordinary blocks. Headings and bullets become nesting.
388
- - Then flip the tag in place: `#@Nova` becomes `#@Nova-DONE`. Leave the rest of the block text untouched. A `{{[[TODO]]}}` on the block stays as-is; that checkbox is Ian's.
389
- - Then embed on today's daily page under a `## Nova Responses` heading: a block `Nova response on [[<origin page>]]` with the child `{{[[embed]]: ((<uid of the [NOVA] block>))}}`. The guidelines' root-level rule for daily pages applies to memories; Nova responses go under this heading.
390
390
 
391
- ### Idempotency
392
- - A block that already has a `[NOVA]` child is answered. Do not answer it again, even if the tag still reads `#@Nova`. The nightly cleanup pass removes stray duplicates; do not create them.
393
- - `#@Nova-DONE` is never a work queue. Search `@Nova` for open items and skip anything containing `-DONE`.
391
+ ## Custom Rules
394
392
 
395
- ### Who runs when (America/Los_Angeles)
396
- | When | Job | Scope |
397
- |---|---|---|
398
- | 03:00 nightly | AI Intel sweep, `Skills/AIIntel/Tools/ProcessTriage.ts` | `#@Nova` and `#Status/*` on the `AI Intel Report` and `PAI-Anthropic Report` pages |
399
- | 04:30 nightly | `Skills/Productivity/scripts/ProcessNovaTodos.ts`, EventBridge job `nova_todo_processing` | `#@Nova` on every other page |
400
- | Interactive | This session, when Ian points at a block or asks for a sweep | Same output shape as above |
401
393
 
402
- - Both nightly jobs post their own Telegram summary. An interactive answer does not need one.
403
- - Dry run by hand: `bun $PAI_DIR/Skills/Productivity/scripts/ProcessNovaTodos.ts --dry-run`. Add `--cleanup` to only remove duplicate `[NOVA]` blocks.
404
- - On AI Intel pages, `#Status/ExecSum`, `#Status/Explore`, `#Status/Backburner`, and `#Status/Reject` run unattended. `#Status/Implement`, `#Status/PRD`, and `#@Nova` wait for an interactive session. Processed items end as `#Status/Processed`.
394
+ ## Integration Notes
405
395
 
406
- ## Retired conventions
407
- - `#PAI/do`, `#PAI/done`, `#PAI/hold`, `#PAI/ignore`: replaced by `#@Nova` and `#@Nova-DONE`. Nothing processes them and no block carried them as of September 6th, 2026. Never create them. If one turns up, treat it as `#@Nova`.
408
- - The `| [[Date]]` suffix once used to surface nested results on the daily page: replaced by the embed above.
396
+ <!-- CUSTOMIZE: Any rules about how Roam integrates with your other tools/systems -->
409
397
 
410
- ## Ian's capture tags (not Nova's queue)
411
- - `{{[[TODO]]}} #task <action>` on the daily page is Ian's capture inbox. ProcessFlow routes it to OmniFocus weekly. Do not convert `#task` to `#@Nova` unprompted; Ian decides what to delegate.
412
- - `#researchThis` means look into this later. It is not a task and not a delegation.
413
- - `#suggested-next-action` is a follow-up Nova proposes under a reply. Ian adds `#@Nova` to delegate it or checks it `{{[[DONE]]}}` to close it himself.
414
- </personalization_layer>
398
+ </personalization_layer>
@@ -8,6 +8,9 @@ import { parseMarkdown, generateBlockUid, parseMarkdownHeadingLevel } from '../.
8
8
  import { printDebug, exitWithError } from '../utils/output.js';
9
9
  import { resolveGraph } from '../utils/graph.js';
10
10
  import { readStdin } from '../utils/input.js';
11
+ import { resolveParentRef, resolvePageRef } from '../utils/ref-resolver.js';
12
+ import { parentUidHint } from '../utils/ref-classifier.js';
13
+ import { uidExists } from '../../shared/page-validator.js';
11
14
  import { formatRoamDate, sanitizeTagName } from '../../utils/helpers.js';
12
15
  import { q, createPage as roamCreatePage } from '@roam-research/roam-api-sdk';
13
16
  /**
@@ -77,16 +80,6 @@ function adjustLevelsForHeadingHierarchy(blocks) {
77
80
  }
78
81
  return result;
79
82
  }
80
- /**
81
- * Check if a string looks like a Roam block UID (9 alphanumeric chars with _ or -)
82
- */
83
- function isBlockUid(value) {
84
- // Strip (( )) wrapper if present
85
- const cleaned = value.replace(/^\(\(|\)\)$/g, '');
86
- // Require at least one digit — real Roam UIDs are randomly generated and
87
- // virtually always contain numbers, while page titles like "Learnings" don't.
88
- return /^[a-zA-Z0-9_-]{9}$/.test(cleaned) && /\d/.test(cleaned);
89
- }
90
83
  /**
91
84
  * Check if content looks like a JSON array
92
85
  */
@@ -125,7 +118,8 @@ async function getDailyPageUid(graph) {
125
118
  return findOrCreatePage(graph, dateStr);
126
119
  }
127
120
  /**
128
- * Find or create a heading block on a page
121
+ * Find or create a heading block on a page. `created` tells the caller whether
122
+ * a block was added, so it can say so: a created parent is otherwise invisible.
129
123
  */
130
124
  async function findOrCreateHeading(graph, pageUid, heading, headingLevel) {
131
125
  // Search for existing heading block
@@ -138,7 +132,7 @@ async function findOrCreateHeading(graph, pageUid, heading, headingLevel) {
138
132
  [?block :block/uid ?uid]]`;
139
133
  const headingResults = await q(graph, headingQuery, [pageUid, heading]);
140
134
  if (headingResults && headingResults.length > 0) {
141
- return headingResults[0][0];
135
+ return { uid: headingResults[0][0], created: false };
142
136
  }
143
137
  // Create the heading block
144
138
  const batchOps = new BatchOperations(graph);
@@ -150,7 +144,7 @@ async function findOrCreateHeading(graph, pageUid, heading, headingLevel) {
150
144
  uid: headingUid,
151
145
  ...(headingLevel && { heading: headingLevel })
152
146
  }]);
153
- return headingUid;
147
+ return { uid: headingUid, created: true };
154
148
  }
155
149
  /**
156
150
  * Parse JSON content blocks
@@ -186,8 +180,9 @@ export function createSaveCommand() {
186
180
  .argument('[input]', 'Text, file path, or "-" for stdin (auto-detected)')
187
181
  .option('--title <title>', 'Create a new page with this title')
188
182
  .option('--update', 'Update existing page using smart diff (preserves block UIDs)')
189
- .option('-p, --page <ref>', 'Target page by title or UID (default: daily page, creates if missing)')
190
- .option('--parent <ref>', 'Nest under block UID ((uid)) or heading text (creates if missing). Use # prefix for heading level: "## Section"')
183
+ .option('-p, --page <ref>', 'Target page by title (creates if missing), or by UID as ((uid)) (must exist). Default: daily page')
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')
191
186
  .option('-c, --categories <tags>', 'Comma-separated tags appended to first block')
192
187
  .option('-t, --todo [text]', 'Add TODO item(s) to daily page. Accepts inline text or stdin')
193
188
  .option('--json', 'Force JSON array format: [{text, level, heading?}, ...]')
@@ -198,19 +193,32 @@ export function createSaveCommand() {
198
193
  .option('--write-key <key>', 'Write confirmation key (non-default graphs)')
199
194
  .option('--debug', 'Show debug information')
200
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
+
201
208
  Examples:
202
209
  # Quick saves to daily page
203
210
  roam save "Quick note" # Single block
204
211
  roam save "# Important" -c "work,urgent" # H1 heading with tags
205
212
  roam save --todo "Buy groceries" # TODO item
206
213
 
207
- # Save under heading (creates if missing)
208
- roam save --parent "## Notes" "My note" # Under H2 "Notes" heading
209
- roam save --parent "((blockUid9))" "Child" # Under specific block
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
210
218
 
211
219
  # Target specific page
212
220
  roam save -p "Project X" "Status update" # By title (creates if missing)
213
- roam save -p "pageUid123" "Note" # By UID
221
+ roam save -p "((pageUid12))" "Note" # By UID (must exist)
214
222
 
215
223
  # File operations
216
224
  roam save notes.md --title "My Notes" # Create page from file
@@ -350,24 +358,6 @@ JSON format (--json):
350
358
  const categories = options.categories
351
359
  ? options.categories.split(',').map(c => c.trim()).filter(Boolean)
352
360
  : undefined;
353
- // Determine parent type if specified
354
- let parentUid;
355
- let parentHeading;
356
- let parentHeadingLevel;
357
- if (options.parent) {
358
- const cleanedParent = options.parent.replace(/^\(\(|\)\)$/g, '');
359
- if (isBlockUid(cleanedParent)) {
360
- parentUid = cleanedParent;
361
- }
362
- else {
363
- // Parse heading syntax from parent text
364
- const { heading_level, content } = parseMarkdownHeadingLevel(options.parent);
365
- parentHeading = content;
366
- if (heading_level > 0) {
367
- parentHeadingLevel = heading_level;
368
- }
369
- }
370
- }
371
361
  // Parse --order option
372
362
  let orderValue = 'last';
373
363
  if (options.order !== undefined) {
@@ -394,8 +384,7 @@ JSON format (--json):
394
384
  printDebug('Order', orderValue);
395
385
  printDebug('Graph', options.graph || 'default');
396
386
  printDebug('Content blocks', contentBlocks.length);
397
- printDebug('Parent UID', parentUid || 'none');
398
- printDebug('Parent heading', parentHeading || 'none');
387
+ printDebug('Parent', options.parentUid ?? options.parent ?? 'none');
399
388
  printDebug('Target page', options.page || 'daily page');
400
389
  printDebug('Categories', categories || 'none');
401
390
  printDebug('Title', options.title || 'none');
@@ -411,6 +400,28 @@ JSON format (--json):
411
400
  console.error('');
412
401
  }
413
402
  const graph = resolveGraph(options, true);
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.
405
+ const exists = (uid) => uidExists(graph, uid);
406
+ const parentTarget = await resolveParentRef({ parent: options.parent, parentUid: options.parentUid }, exists);
407
+ let parentUid;
408
+ let parentHeading;
409
+ let parentHeadingLevel;
410
+ if (parentTarget?.kind === 'uid') {
411
+ parentUid = parentTarget.uid;
412
+ }
413
+ else if (parentTarget) {
414
+ // Parse heading syntax from parent text
415
+ const { heading_level, content } = parseMarkdownHeadingLevel(parentTarget.text);
416
+ parentHeading = content;
417
+ if (heading_level > 0) {
418
+ parentHeadingLevel = heading_level;
419
+ }
420
+ }
421
+ if (options.debug) {
422
+ printDebug('Parent UID', parentUid || 'none');
423
+ printDebug('Parent heading', parentHeading || 'none');
424
+ }
414
425
  // Determine operation mode based on options
415
426
  const hasParent = parentUid || parentHeading;
416
427
  const hasTitle = options.title;
@@ -515,14 +526,12 @@ JSON format (--json):
515
526
  // Parent heading or target page: get target page UID first
516
527
  let pageUid;
517
528
  if (options.page) {
518
- // Strip (( )) wrapper if UID, but NOT [[ ]] (that's valid page title syntax)
519
- const cleanedPage = options.page.replace(/^\(\(|\)\)$/g, '');
520
- if (isBlockUid(cleanedPage)) {
521
- pageUid = cleanedPage;
522
- }
523
- else {
524
- pageUid = await findOrCreatePage(graph, options.page);
525
- }
529
+ // ((uid)) must exist; a bare 9-character value is a UID only if the
530
+ // graph has it, otherwise a title ("Learnings"). [[ ]] is left alone.
531
+ const pageTarget = await resolvePageRef(options.page, exists);
532
+ pageUid = pageTarget.kind === 'uid'
533
+ ? pageTarget.uid
534
+ : await findOrCreatePage(graph, pageTarget.title);
526
535
  }
527
536
  else {
528
537
  pageUid = await getDailyPageUid(graph);
@@ -533,7 +542,16 @@ JSON format (--json):
533
542
  // Resolve heading to parent UID if specified
534
543
  let targetParentUid;
535
544
  if (parentHeading) {
536
- targetParentUid = await findOrCreateHeading(graph, pageUid, parentHeading, parentHeadingLevel);
545
+ const heading = await findOrCreateHeading(graph, pageUid, parentHeading, parentHeadingLevel);
546
+ targetParentUid = heading.uid;
547
+ if (heading.created) {
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);
554
+ }
537
555
  }
538
556
  else {
539
557
  targetParentUid = pageUid;
@@ -0,0 +1,56 @@
1
+ /**
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`.)
6
+ *
7
+ * This replaces a heuristic that required a digit before believing a value was
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
10
+ * 9-character UID from a 9-character title like "Learnings"; that case is
11
+ * reported as `ambiguous` and the caller asks the graph.
12
+ */
13
+ const UID_SHAPE = /^[a-zA-Z0-9_-]{9}$/;
14
+ const WRAPPED = /^\(\((.*)\)\)$/s;
15
+ export function classifyRef(raw) {
16
+ const inner = raw.match(WRAPPED)?.[1];
17
+ if (inner !== undefined && UID_SHAPE.test(inner)) {
18
+ return { kind: 'uid', uid: inner };
19
+ }
20
+ if (UID_SHAPE.test(raw)) {
21
+ return { kind: 'ambiguous', value: raw };
22
+ }
23
+ return { kind: 'text', value: raw };
24
+ }
25
+ /**
26
+ * Parse the value of `--parent-uid`, which is never text. Accepts `uid` or
27
+ * `((uid))`; throws on anything else.
28
+ */
29
+ export function parseUidFlag(raw) {
30
+ const candidate = raw.match(WRAPPED)?.[1] ?? raw;
31
+ if (!UID_SHAPE.test(candidate)) {
32
+ throw new Error(`--parent-uid expects a 9-character block UID (uid or "((uid))"), got "${raw}". ` +
33
+ `To nest under a block by its text, use --parent.`);
34
+ }
35
+ return candidate;
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
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Resolve `roam save`'s `--parent-uid`, `--parent` and `--page` values to a
3
+ * target, asking the graph only where shape cannot decide.
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
+ *
9
+ * Nothing here writes. Callers resolve every reference before their first
10
+ * write, so a reference that cannot be resolved leaves the graph untouched.
11
+ */
12
+ import { classifyRef, parseUidFlag } from './ref-classifier.js';
13
+ async function requireUid(uid, flag, exists) {
14
+ if (!(await exists(uid))) {
15
+ throw new Error(`${flag}: no block or page with UID "${uid}" exists in this graph. Nothing was written.`);
16
+ }
17
+ return uid;
18
+ }
19
+ export async function resolveParentRef(options, exists) {
20
+ const { parent, parentUid } = options;
21
+ if (parent !== undefined && parentUid !== undefined) {
22
+ throw new Error('Use either --parent (the text of the parent block) or --parent-uid (its UID), not both.');
23
+ }
24
+ if (parentUid !== undefined) {
25
+ const uid = await requireUid(parseUidFlag(parentUid), '--parent-uid', exists);
26
+ return { kind: 'uid', uid };
27
+ }
28
+ if (parent === undefined)
29
+ return undefined;
30
+ return { kind: 'heading', text: parent };
31
+ }
32
+ export async function resolvePageRef(page, exists) {
33
+ const ref = classifyRef(page);
34
+ switch (ref.kind) {
35
+ case 'uid':
36
+ return { kind: 'uid', uid: await requireUid(ref.uid, '--page', exists) };
37
+ case 'ambiguous':
38
+ return (await exists(ref.value))
39
+ ? { kind: 'uid', uid: ref.value }
40
+ : { kind: 'title', title: ref.value };
41
+ case 'text':
42
+ return { kind: 'title', title: ref.value };
43
+ }
44
+ }
@@ -106,6 +106,20 @@ async function batchCheckExistence(graph, uids, config = DEFAULT_RATE_LIMIT_CONF
106
106
  }
107
107
  throw new McpError(ErrorCode.InternalError, `Rate limit exceeded checking page existence after ${config.maxRetries} retries: ${lastError?.message || 'Unknown error'}`);
108
108
  }
109
+ /**
110
+ * Check whether a single UID names an existing entity (page or block).
111
+ * Shares the session cache with `ensurePagesExist`, so a UID confirmed here is
112
+ * not queried again when a batch then writes under it.
113
+ */
114
+ export async function uidExists(graph, uid) {
115
+ if (pageUidCache.hasUid(uid))
116
+ return true;
117
+ const existing = await batchCheckExistence(graph, [uid]);
118
+ if (!existing.has(uid))
119
+ return false;
120
+ pageUidCache.addUid(uid);
121
+ return true;
122
+ }
109
123
  /**
110
124
  * Batch create daily pages that don't exist.
111
125
  * Uses Roam's createPage API.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roam-research-mcp",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "description": "MCP server and CLI for Roam Research",
5
5
  "private": false,
6
6
  "repository": {
@@ -31,11 +31,10 @@
31
31
  "scripts": {
32
32
  "build": "echo \"Using custom instructions: .roam/${CUSTOM_INSTRUCTIONS_PREFIX}custom-instructions.md\" && tsc && cat Roam_Markdown_Cheatsheet.md .roam/${CUSTOM_INSTRUCTIONS_PREFIX}custom-instructions.md > build/Roam_Markdown_Cheatsheet.md && chmod 755 build/index.js build/cli/roam.js",
33
33
  "clean": "rm -rf build",
34
- "prepublishOnly": "node scripts/check-bundled-cheatsheet.mjs",
34
+ "prepublishOnly": "npm run clean && npm run build && node scripts/check-bundled-cheatsheet.mjs",
35
35
  "watch": "tsc --watch",
36
36
  "inspector": "npx @modelcontextprotocol/inspector build/index.js",
37
37
  "start": "node build/index.js",
38
- "prepublishOnly": "npm run clean && npm run build",
39
38
  "release": "standard-version",
40
39
  "release:patch": "standard-version --release-as patch",
41
40
  "release:minor": "standard-version --release-as minor",