roam-research-mcp 1.3.2 → 1.6.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 +187 -25
- package/build/Roam_Markdown_Cheatsheet.md +11 -2
- package/build/cli/commands/get.js +79 -0
- package/build/cli/commands/refs.js +122 -0
- package/build/cli/commands/save.js +121 -0
- package/build/cli/commands/search.js +79 -0
- package/build/cli/roam.js +18 -0
- package/build/cli/utils/output.js +88 -0
- package/build/diff/actions.js +93 -0
- package/build/diff/actions.test.js +125 -0
- package/build/diff/diff.js +155 -0
- package/build/diff/diff.test.js +202 -0
- package/build/diff/index.js +43 -0
- package/build/diff/matcher.js +118 -0
- package/build/diff/matcher.test.js +198 -0
- package/build/diff/parser.js +114 -0
- package/build/diff/parser.test.js +281 -0
- package/build/diff/types.js +27 -0
- package/build/diff/types.test.js +57 -0
- package/build/search/block-ref-search.js +34 -7
- package/build/server/roam-server.js +7 -0
- package/build/tools/operations/pages.js +95 -0
- package/build/tools/schemas.js +29 -2
- package/build/tools/tool-handlers.js +4 -0
- package/package.json +9 -5
- package/build/cli/import-markdown.js +0 -98
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { initializeGraph } from '@roam-research/roam-api-sdk';
|
|
3
|
-
import { API_TOKEN, GRAPH_NAME } from '../config/environment.js';
|
|
4
|
-
import { PageOperations } from '../tools/operations/pages.js';
|
|
5
|
-
import { parseMarkdown } from '../markdown-utils.js';
|
|
6
|
-
/**
|
|
7
|
-
* Flatten nested MarkdownNode[] to flat array with absolute levels
|
|
8
|
-
*/
|
|
9
|
-
function flattenNodes(nodes, baseLevel = 1) {
|
|
10
|
-
const result = [];
|
|
11
|
-
for (const node of nodes) {
|
|
12
|
-
result.push({
|
|
13
|
-
text: node.content,
|
|
14
|
-
level: baseLevel,
|
|
15
|
-
...(node.heading_level && { heading: node.heading_level })
|
|
16
|
-
});
|
|
17
|
-
if (node.children.length > 0) {
|
|
18
|
-
result.push(...flattenNodes(node.children, baseLevel + 1));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Read all input from stdin
|
|
25
|
-
*/
|
|
26
|
-
async function readStdin() {
|
|
27
|
-
const chunks = [];
|
|
28
|
-
for await (const chunk of process.stdin) {
|
|
29
|
-
chunks.push(chunk);
|
|
30
|
-
}
|
|
31
|
-
return Buffer.concat(chunks).toString('utf-8');
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Show usage help
|
|
35
|
-
*/
|
|
36
|
-
function showUsage() {
|
|
37
|
-
console.error('Usage: roam-import <page-title>');
|
|
38
|
-
console.error('');
|
|
39
|
-
console.error('Reads markdown from stdin and imports to Roam Research.');
|
|
40
|
-
console.error('');
|
|
41
|
-
console.error('Examples:');
|
|
42
|
-
console.error(' cat document.md | roam-import "Meeting Notes"');
|
|
43
|
-
console.error(' pbpaste | roam-import "Ideas"');
|
|
44
|
-
console.error(' echo "- Item 1\\n- Item 2" | roam-import "Quick Note"');
|
|
45
|
-
console.error('');
|
|
46
|
-
console.error('Environment variables required:');
|
|
47
|
-
console.error(' ROAM_API_TOKEN Your Roam Research API token');
|
|
48
|
-
console.error(' ROAM_GRAPH_NAME Your Roam graph name');
|
|
49
|
-
}
|
|
50
|
-
async function main() {
|
|
51
|
-
// Parse CLI arguments
|
|
52
|
-
const args = process.argv.slice(2);
|
|
53
|
-
const pageTitle = args[0];
|
|
54
|
-
if (!pageTitle || pageTitle === '--help' || pageTitle === '-h') {
|
|
55
|
-
showUsage();
|
|
56
|
-
process.exit(pageTitle ? 0 : 1);
|
|
57
|
-
}
|
|
58
|
-
// Check if stdin is a TTY (no input piped)
|
|
59
|
-
if (process.stdin.isTTY) {
|
|
60
|
-
console.error('Error: No input received. Pipe markdown content to this command.');
|
|
61
|
-
console.error('');
|
|
62
|
-
showUsage();
|
|
63
|
-
process.exit(1);
|
|
64
|
-
}
|
|
65
|
-
// Read markdown from stdin
|
|
66
|
-
const markdownContent = await readStdin();
|
|
67
|
-
if (!markdownContent.trim()) {
|
|
68
|
-
console.error('Error: Empty input received.');
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
// Initialize Roam graph
|
|
72
|
-
const graph = initializeGraph({
|
|
73
|
-
token: API_TOKEN,
|
|
74
|
-
graph: GRAPH_NAME
|
|
75
|
-
});
|
|
76
|
-
// Parse markdown to nodes
|
|
77
|
-
const nodes = parseMarkdown(markdownContent);
|
|
78
|
-
// Flatten nested structure to content blocks
|
|
79
|
-
const contentBlocks = flattenNodes(nodes);
|
|
80
|
-
if (contentBlocks.length === 0) {
|
|
81
|
-
console.error('Error: No content blocks parsed from input.');
|
|
82
|
-
process.exit(1);
|
|
83
|
-
}
|
|
84
|
-
// Create page with content
|
|
85
|
-
const pageOps = new PageOperations(graph);
|
|
86
|
-
const result = await pageOps.createPage(pageTitle, contentBlocks);
|
|
87
|
-
if (result.success) {
|
|
88
|
-
console.log(`Created page '${pageTitle}' (uid: ${result.uid})`);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
console.error(`Failed to create page '${pageTitle}'`);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
main().catch((error) => {
|
|
96
|
-
console.error(`Error: ${error.message}`);
|
|
97
|
-
process.exit(1);
|
|
98
|
-
});
|