rootr-cli 0.7.1 → 0.8.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/bin/rootr.js CHANGED
@@ -26,6 +26,7 @@ const USAGE = `Rootr CLI v${pkg.version}
26
26
  rootr ws 내 워크스페이스 목록 (id\tname, 열 수 없는 곳은 표시)
27
27
  rootr use <id|이름|주소> 활성 워크스페이스 전환 (그 워크스페이스용 키도 기억)
28
28
  rootr ask <question> [--workspace <w>] GraphRAG 질의응답 (RCA), 인용 포함 출력
29
+ rootr db create [--file <spec.json>] [--parent <path|id>] 표(DATABASE) 생성 — 컬럼 순서 그대로, 행까지 한 번에
29
30
  rootr config [--api-key <k>] [--workspace <w>] [--base-url <u>] 설정 조회/저장
30
31
  rootr config --add-key <k> [--label <name>] [--workspace <w>] 워크스페이스별 키 추가 등록
31
32
  rootr mcp MCP stdio 서버 구동 (도구 90종+ — README 참고)
@@ -433,6 +434,44 @@ async function cmdMcp() {
433
434
 
434
435
  // ---- entry ------------------------------------------------------------
435
436
 
437
+
438
+ /**
439
+ * 표(DATABASE) 만들기 — 컬럼 순서를 그대로 지키려면 한 번에 만들어야 한다.
440
+ *
441
+ * 스펙은 JSON으로 받는다(파일 또는 표준입력): `{ name, properties[], views?, rows? }`.
442
+ * 컬럼을 하나씩 붙이는 방식은 호출 순서가 곧 컬럼 순서가 되어 옮겨온 표가 뒤죽박죽이
443
+ * 됐다 — 그래서 CLI도 "한 번에" 쪽만 제공한다.
444
+ */
445
+ async function cmdDb(args) {
446
+ const sub = args._[0];
447
+ if (sub !== 'create') {
448
+ throw new Error('사용법: rootr db create [--file <spec.json>] [--parent <path|id>] [--ws <id>]');
449
+ }
450
+ const raw = typeof args.file === 'string' ? readFileSync(args.file, 'utf8') : await readStdin();
451
+ let spec;
452
+ try {
453
+ spec = JSON.parse(raw);
454
+ } catch {
455
+ throw new Error('스펙을 JSON으로 읽을 수 없습니다. { "name": "...", "properties": [...] } 형태여야 합니다.');
456
+ }
457
+ if (!spec.name && !spec.path) throw new Error('스펙에 name 또는 path가 있어야 합니다.');
458
+
459
+ const client = makeClient();
460
+ let parentId = spec.parentId;
461
+ if (typeof args.parent === 'string') {
462
+ const resolved = await resolveTarget(client, args.parent);
463
+ if (!resolved.existed) throw new Error(`부모를 찾을 수 없습니다: ${args.parent}`);
464
+ parentId = resolved.id;
465
+ }
466
+ const ws = args.ws || client.workspace;
467
+ if (!ws) throw new Error('워크스페이스를 알 수 없습니다. --ws 를 주거나 rootr use 로 정하세요.');
468
+
469
+ const db = await client.createDatabase(ws, { ...spec, parentId });
470
+ const cols = (db.properties || []).map((p) => p.name).join(', ');
471
+ console.log(`표 생성: ${db.path ?? db.name} (${db.id})`);
472
+ if (cols) console.log(`컬럼 순서: ${cols}`);
473
+ if (typeof db.rowCount === 'number') console.log(`행: ${db.rowCount}개`);
474
+ }
436
475
  async function main() {
437
476
  const argv = process.argv.slice(2);
438
477
  const args = parseArgs(argv);
@@ -474,6 +513,8 @@ async function main() {
474
513
  return cmdConfig(args);
475
514
  case 'use':
476
515
  return cmdUse(args);
516
+ case 'db':
517
+ return cmdDb(args);
477
518
  case 'mcp':
478
519
  return cmdMcp(args);
479
520
  default:
package/lib/client.js CHANGED
@@ -550,7 +550,68 @@ export class RootrClient {
550
550
  });
551
551
  }
552
552
 
553
- // ---- Databases (rows) -------------------------------------------------
553
+ // ---- Templates ---------------------------------------------------------
554
+ // 문서 양식(템플릿). 인앱 어시스턴트는 예전부터 쓸 수 있었는데 MCP·CLI에는
555
+ // 없어서, 밖에서 붙은 에이전트는 양식이 있는 줄도 모르고 매번 맨바닥부터
556
+ // 만들었다(2026-08-18 점검에서 드러난 구멍).
557
+
558
+ async listTemplates(workspace) {
559
+ return this.request(`/workspaces/${encodeURIComponent(workspace)}/templates`);
560
+ }
561
+
562
+ async applyTemplate(workspace, templateId, { parentId } = {}) {
563
+ return this.request(
564
+ `/workspaces/${encodeURIComponent(workspace)}/templates/${encodeURIComponent(templateId)}/apply`,
565
+ { method: 'POST', body: { parentId } },
566
+ );
567
+ }
568
+
569
+ async createTemplate(workspace, { name, emoji, description, kind, spec } = {}) {
570
+ return this.request(`/workspaces/${encodeURIComponent(workspace)}/templates`, {
571
+ method: 'POST',
572
+ body: { name, emoji, description, kind, spec },
573
+ });
574
+ }
575
+
576
+ async saveTemplateFromNode(workspace, nodeId, { name, emoji, description } = {}) {
577
+ return this.request(
578
+ `/workspaces/${encodeURIComponent(workspace)}/templates/from-node/${encodeURIComponent(nodeId)}`,
579
+ { method: 'POST', body: { name, emoji, description } },
580
+ );
581
+ }
582
+
583
+ async updateTemplate(workspace, templateId, patch = {}) {
584
+ return this.request(
585
+ `/workspaces/${encodeURIComponent(workspace)}/templates/${encodeURIComponent(templateId)}`,
586
+ { method: 'PATCH', body: patch },
587
+ );
588
+ }
589
+
590
+ // ---- Databases --------------------------------------------------------
591
+
592
+ /**
593
+ * Create a DATABASE node with its columns (and optionally its first rows) in
594
+ * ONE call. `properties` order IS the column order — that is the whole point:
595
+ * building a table by adding columns one at a time made the order depend on
596
+ * the order of the calls, which is how migrated tables came out scrambled.
597
+ */
598
+ async createDatabase(workspace, { name, parentId, path, createParents, autoRename, icon, properties, views, rows } = {}) {
599
+ return this.request(`/workspaces/${encodeURIComponent(workspace)}/databases`, {
600
+ method: 'POST',
601
+ body: { name, parentId, path, createParents, autoRename, icon, properties, views, rows },
602
+ });
603
+ }
604
+
605
+ /**
606
+ * 뷰 하나만 고친다(이름·감출 컬럼·그룹 기준). PATCH /databases/:id 는 views 배열을
607
+ * 통째로 갈아끼워서 빠뜨린 뷰가 사라지는데, 여기서는 서버가 그 뷰만 병합한다.
608
+ */
609
+ async updateDatabaseView(databaseId, viewId, patch = {}) {
610
+ return this.request(
611
+ `/databases/${encodeURIComponent(databaseId)}/views/${encodeURIComponent(viewId)}`,
612
+ { method: 'PATCH', body: patch },
613
+ );
614
+ }
554
615
 
555
616
  /** Database definition: { id, name, icon, path, properties[], views[], rowCount }. */
556
617
  async getDatabase(databaseId) {
@@ -1,6 +1,14 @@
1
1
  import { z } from 'zod';
2
2
 
3
- import { jsonResult, errorResult, makeClient, resolveNodeId, NODE_TARGET_HINT } from './shared.js';
3
+ import {
4
+ jsonResult,
5
+ errorResult,
6
+ makeClient,
7
+ requireWorkspace,
8
+ resolveNodeId,
9
+ resolveOptionalNodeId,
10
+ NODE_TARGET_HINT,
11
+ } from './shared.js';
4
12
 
5
13
  /** Human text for the `databaseId` param — accepts a path just like the document tools. */
6
14
  const DATABASE_TARGET_DESC = `DATABASE node id${NODE_TARGET_HINT} (e.g. "/제작 공정/칸반")`;
@@ -33,6 +41,118 @@ function resolveValueKeys(properties, values) {
33
41
  * "status" column = move a kanban card between columns).
34
42
  */
35
43
  export function registerDatabaseTools(server) {
44
+ server.registerTool(
45
+ 'rootr_create_database',
46
+ {
47
+ title: 'Create a Rootr database (table / board / kanban)',
48
+ description:
49
+ 'Create a DATABASE node — a typed table with columns, views and rows — in ONE call, optionally seeded with ' +
50
+ 'its first rows. **Use this whenever you need a table**: moving a Notion database over, building a kanban ' +
51
+ 'board, a task/requirement/risk tracker, anything with trackable rows. Do NOT fake a table with a markdown ' +
52
+ 'document, and do NOT create an empty database and then add columns one by one — `properties` order IS the ' +
53
+ 'column order, so one call keeps the columns in exactly the order you list them. ' +
54
+ 'The FIRST property must be type "title" (the row label). Other types: text | number | select | ' +
55
+ 'multi_select | date | checkbox | url | person. select/multi_select take options:[{name,color}]. ' +
56
+ 'Views default to a single table view; a "board" view needs config.groupBy = a select property id, a ' +
57
+ '"timeline" view needs config.dateProp. Row `values` are keyed by column NAME (or id); date values are ' +
58
+ '{ start: "YYYY-MM-DD", end? }, multi_select is string[].',
59
+ annotations: { readOnlyHint: false, destructiveHint: false },
60
+ inputSchema: {
61
+ name: z.string().describe('Table name, e.g. "업무 목록"'),
62
+ parentId: z.string().optional().describe(`Parent folder id${NODE_TARGET_HINT}; workspace root if omitted`),
63
+ path: z.string().optional().describe('Full path incl. name — wins over parentId+name, e.g. "/팀/업무 목록"'),
64
+ createParents: z.boolean().optional().describe('Create missing folders in `path` (default false)'),
65
+ icon: z.string().optional().describe('Emoji icon for the node'),
66
+ properties: z
67
+ .array(
68
+ z.object({
69
+ name: z.string().describe('Column header, e.g. "담당자"'),
70
+ type: z
71
+ .enum(['title', 'text', 'number', 'select', 'multi_select', 'date', 'checkbox', 'url', 'person'])
72
+ .describe('Column type; the FIRST property must be "title"'),
73
+ options: z
74
+ .array(z.object({ name: z.string(), color: z.string() }))
75
+ .optional()
76
+ .describe('select/multi_select only: the choices'),
77
+ }),
78
+ )
79
+ .optional()
80
+ .describe('Columns IN DISPLAY ORDER. Defaults to a single title column named "Name".'),
81
+ views: z
82
+ .array(z.record(z.unknown()))
83
+ .optional()
84
+ .describe('Views, e.g. [{ name: "보드", type: "board", config: { groupBy: "<select property id>" } }]'),
85
+ rows: z
86
+ .array(z.object({ values: z.record(z.unknown()) }))
87
+ .optional()
88
+ .describe('Initial rows, e.g. [{ values: { "이름": "킥오프", "기한": { "start": "2026-08-01" } } }]'),
89
+ workspace: z.string().optional().describe('Workspace id; defaults to ROOTR_WORKSPACE/config if omitted'),
90
+ },
91
+ },
92
+ async ({ name, parentId, path, createParents, icon, properties, views, rows, workspace }) => {
93
+ try {
94
+ const ws = requireWorkspace(workspace);
95
+ const client = makeClient(ws);
96
+ parentId = await resolveOptionalNodeId(client, parentId);
97
+ const database = await client.createDatabase(ws, {
98
+ name,
99
+ parentId,
100
+ path,
101
+ createParents,
102
+ icon,
103
+ properties,
104
+ views,
105
+ rows,
106
+ });
107
+ return jsonResult(database);
108
+ } catch (err) {
109
+ return errorResult(err);
110
+ }
111
+ },
112
+ );
113
+
114
+ server.registerTool(
115
+ 'rootr_update_view',
116
+ {
117
+ title: 'Edit a database view (hide columns, rename, regroup)',
118
+ description:
119
+ 'Change ONE view of a Rootr (루터) DATABASE. Use `hiddenProps` to choose which columns that view shows — ' +
120
+ 'the same table can look different per view (a "담당자" view hiding the amounts, etc). Hiding a column ' +
121
+ 'does NOT erase its values: it disappears from that view only and comes back when you unhide it. ' +
122
+ 'Columns may be given by NAME or id; the title column cannot be hidden and is ignored if listed. ' +
123
+ 'Pass an empty array to show everything again. Only the fields you pass change, and other views are untouched.',
124
+ annotations: { readOnlyHint: false, destructiveHint: false },
125
+ inputSchema: {
126
+ databaseId: z.string().describe(DATABASE_TARGET_DESC),
127
+ viewId: z.string().describe('View id or view NAME (from rootr_read_database)'),
128
+ hiddenProps: z
129
+ .array(z.string())
130
+ .optional()
131
+ .describe('Columns to hide in this view, by name or id. [] shows every column again.'),
132
+ name: z.string().optional().describe('New view name'),
133
+ groupBy: z.string().optional().describe('board view: the select column to group by (name or id)'),
134
+ dateProp: z.string().optional().describe('calendar/timeline view: the date column (name or id)'),
135
+ endDateProp: z.string().optional().describe('timeline view: the end-date column (name or id)'),
136
+ },
137
+ },
138
+ async ({ databaseId, viewId, hiddenProps, name, groupBy, dateProp, endDateProp }) => {
139
+ try {
140
+ const client = makeClient();
141
+ const id = await resolveNodeId(client, databaseId);
142
+ const view = await client.updateDatabaseView(id, viewId, {
143
+ hiddenProps,
144
+ name,
145
+ groupBy,
146
+ dateProp,
147
+ endDateProp,
148
+ });
149
+ return jsonResult({ view });
150
+ } catch (err) {
151
+ return errorResult(err);
152
+ }
153
+ },
154
+ );
155
+
36
156
  server.registerTool(
37
157
  'rootr_read_database',
38
158
  {
@@ -0,0 +1,156 @@
1
+ import { z } from 'zod';
2
+
3
+ import {
4
+ jsonResult,
5
+ errorResult,
6
+ makeClient,
7
+ requireWorkspace,
8
+ resolveNodeId,
9
+ resolveOptionalNodeId,
10
+ NODE_TARGET_HINT,
11
+ } from './shared.js';
12
+
13
+ /**
14
+ * 문서 양식(템플릿) 도구.
15
+ *
16
+ * REST와 인앱 어시스턴트에는 예전부터 있었는데 MCP·CLI에만 없었다. 그래서 밖에서
17
+ * 붙은 에이전트(Claude 등)는 워크스페이스에 쓸 만한 양식이 이미 있는 줄도 모르고
18
+ * 매번 맨바닥부터 문서를 지어냈다 — 2026-08-18 점검에서 드러난 구멍이다.
19
+ *
20
+ * 양식은 세 종류다: `document`(마크다운 한 장), `database`(컬럼·뷰가 짜인 표),
21
+ * `tree`(폴더+문서+표가 얽힌 묶음). 빌트인 양식과 워크스페이스가 직접 만든 양식이
22
+ * 같은 목록에 함께 나온다.
23
+ */
24
+ export function registerTemplateTools(server) {
25
+ server.registerTool(
26
+ 'rootr_list_templates',
27
+ {
28
+ title: 'List document/database templates',
29
+ description:
30
+ 'List the templates available in a Rootr (루터) workspace — builtins plus anything this workspace saved. ' +
31
+ 'Each has an id, name, emoji, description and `kind` (document | database | tree). ' +
32
+ '**Call this before building a document or table from scratch**: if a fitting template exists, ' +
33
+ 'rootr_apply_template gives the team their own agreed format instead of a shape you invented.',
34
+ annotations: { readOnlyHint: true, destructiveHint: false },
35
+ inputSchema: {
36
+ workspace: z.string().optional().describe('Workspace id; defaults to ROOTR_WORKSPACE/config if omitted'),
37
+ },
38
+ },
39
+ async ({ workspace }) => {
40
+ try {
41
+ const ws = requireWorkspace(workspace);
42
+ return jsonResult(await makeClient(ws).listTemplates(ws));
43
+ } catch (err) {
44
+ return errorResult(err);
45
+ }
46
+ },
47
+ );
48
+
49
+ server.registerTool(
50
+ 'rootr_apply_template',
51
+ {
52
+ title: 'Create a node from a template',
53
+ description:
54
+ 'Instantiate a Rootr (루터) template — creates the real node(s) it describes and returns the created node. ' +
55
+ 'A `document` template makes one document, `database` makes a table with its columns and views already set, ' +
56
+ '`tree` makes a whole folder/document/table structure. Get ids from rootr_list_templates.',
57
+ annotations: { readOnlyHint: false, destructiveHint: false },
58
+ inputSchema: {
59
+ templateId: z.string().describe('Template id from rootr_list_templates'),
60
+ parentId: z
61
+ .string()
62
+ .optional()
63
+ .describe(`Parent folder id${NODE_TARGET_HINT}; workspace root if omitted`),
64
+ workspace: z.string().optional().describe('Workspace id; defaults to ROOTR_WORKSPACE/config if omitted'),
65
+ },
66
+ },
67
+ async ({ templateId, parentId, workspace }) => {
68
+ try {
69
+ const ws = requireWorkspace(workspace);
70
+ const client = makeClient(ws);
71
+ parentId = await resolveOptionalNodeId(client, parentId);
72
+ return jsonResult(await client.applyTemplate(ws, templateId, { parentId }));
73
+ } catch (err) {
74
+ return errorResult(err);
75
+ }
76
+ },
77
+ );
78
+
79
+ server.registerTool(
80
+ 'rootr_save_as_template',
81
+ {
82
+ title: 'Save a node (or an inline spec) as a template',
83
+ description:
84
+ 'Turn something into a reusable Rootr (루터) template. Either pass `nodeId` to capture an existing ' +
85
+ 'document/table/folder as-is, or pass `kind` + `spec` to define one inline. Use this when the user says ' +
86
+ '"make this the standard format" or asks for a new form/양식. ' +
87
+ 'NOTE: a template is workspace-wide and readable by every member — do not capture a restricted node ' +
88
+ 'unless the user means to share its content with the whole workspace.',
89
+ annotations: { readOnlyHint: false, destructiveHint: false },
90
+ inputSchema: {
91
+ name: z.string().describe('Template name, e.g. "주간 보고서 양식"'),
92
+ nodeId: z
93
+ .string()
94
+ .optional()
95
+ .describe(`Capture this existing node${NODE_TARGET_HINT}. Omit when passing kind+spec instead.`),
96
+ kind: z
97
+ .enum(['document', 'database', 'tree'])
98
+ .optional()
99
+ .describe('Inline definition: document (markdown) | database (columns+views) | tree (structure)'),
100
+ spec: z
101
+ .record(z.unknown())
102
+ .optional()
103
+ .describe('Inline definition body, matching `kind`. Ignored when nodeId is given.'),
104
+ emoji: z.string().optional().describe('Emoji shown in the template gallery'),
105
+ description: z.string().optional().describe('One line on when to use it'),
106
+ workspace: z.string().optional().describe('Workspace id; defaults to ROOTR_WORKSPACE/config if omitted'),
107
+ },
108
+ },
109
+ async ({ name, nodeId, kind, spec, emoji, description, workspace }) => {
110
+ try {
111
+ const ws = requireWorkspace(workspace);
112
+ const client = makeClient(ws);
113
+ if (nodeId) {
114
+ const id = await resolveNodeId(client, nodeId);
115
+ return jsonResult(await client.saveTemplateFromNode(ws, id, { name, emoji, description }));
116
+ }
117
+ if (!kind || !spec) {
118
+ throw new Error('Pass either nodeId, or both kind and spec.');
119
+ }
120
+ return jsonResult(await client.createTemplate(ws, { name, emoji, description, kind, spec }));
121
+ } catch (err) {
122
+ return errorResult(err);
123
+ }
124
+ },
125
+ );
126
+
127
+ server.registerTool(
128
+ 'rootr_update_template',
129
+ {
130
+ title: 'Edit a template',
131
+ description:
132
+ 'Change a Rootr (루터) template — its name, emoji, description or `spec`. Editing a builtin transparently ' +
133
+ 'creates a workspace copy, so the builtin itself is never damaged. Use this for "change the standard format" ' +
134
+ 'requests instead of saving a second near-identical template.',
135
+ annotations: { readOnlyHint: false, destructiveHint: false },
136
+ inputSchema: {
137
+ templateId: z.string().describe('Template id from rootr_list_templates'),
138
+ name: z.string().optional().describe('New name'),
139
+ emoji: z.string().optional().describe('New emoji'),
140
+ description: z.string().optional().describe('New one-line description'),
141
+ spec: z.record(z.unknown()).optional().describe('Replacement body, matching the template kind'),
142
+ workspace: z.string().optional().describe('Workspace id; defaults to ROOTR_WORKSPACE/config if omitted'),
143
+ },
144
+ },
145
+ async ({ templateId, name, emoji, description, spec, workspace }) => {
146
+ try {
147
+ const ws = requireWorkspace(workspace);
148
+ return jsonResult(
149
+ await makeClient(ws).updateTemplate(ws, templateId, { name, emoji, description, spec }),
150
+ );
151
+ } catch (err) {
152
+ return errorResult(err);
153
+ }
154
+ },
155
+ );
156
+ }
package/lib/mcp.js CHANGED
@@ -7,6 +7,7 @@ import { registerLogTools } from './mcp-tools/logs.js';
7
7
  import { registerAskTools } from './mcp-tools/ask.js';
8
8
  import { registerIssueTools } from './mcp-tools/issues.js';
9
9
  import { registerDatabaseTools } from './mcp-tools/databases.js';
10
+ import { registerTemplateTools } from './mcp-tools/templates.js';
10
11
  import { registerWebhookTools } from './mcp-tools/webhooks.js';
11
12
  import { registerMiscTools } from './mcp-tools/misc.js';
12
13
  import { registerCrmTools } from './mcp-tools/crm.js';
@@ -122,6 +123,7 @@ export function buildMcpServer({ name, version }) {
122
123
  withQuotaWarnings(server);
123
124
 
124
125
  registerDocumentTools(server);
126
+ registerTemplateTools(server);
125
127
  registerWorkspaceTools(server);
126
128
  registerLogTools(server);
127
129
  registerAskTools(server);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rootr-cli",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Official Rootr CLI + MCP server — read, write, edit and search Rootr documents from the shell or from an AI agent.",
5
5
  "type": "module",
6
6
  "bin": {