remnote-bridge 0.1.10 → 0.1.11

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.
@@ -49,7 +49,7 @@ export function createMessageRouter(plugin: ReactRNPlugin): (request: BridgeRequ
49
49
  case 'read_globe':
50
50
  return readGlobe(plugin, request.payload as { depth?: number; maxNodes?: number; maxSiblings?: number });
51
51
  case 'read_context':
52
- return readContext(plugin, request.payload as { mode?: 'focus' | 'page'; ancestorLevels?: number; maxNodes?: number; maxSiblings?: number; depth?: number });
52
+ return readContext(plugin, request.payload as { mode?: 'focus' | 'page'; ancestorLevels?: number; maxNodes?: number; maxSiblings?: number; depth?: number; focusRemId?: string });
53
53
  case 'search':
54
54
  return search(plugin, request.payload as { query: string; numResults?: number });
55
55
 
@@ -27,6 +27,7 @@ export interface ReadContextPayload {
27
27
  maxNodes?: number;
28
28
  maxSiblings?: number;
29
29
  depth?: number;
30
+ focusRemId?: string;
30
31
  }
31
32
 
32
33
  export interface ReadContextResult {
@@ -46,12 +47,14 @@ export async function readContext(
46
47
  maxNodes = 200,
47
48
  maxSiblings = 20,
48
49
  depth = 3,
50
+ focusRemId,
49
51
  } = payload;
50
52
 
51
53
  if (mode === 'page') {
54
+ if (focusRemId) throw new Error('focusRemId 仅在 focus 模式下有效,page 模式下请勿指定');
52
55
  return readContextPage(plugin, { maxNodes, maxSiblings, depth });
53
56
  }
54
- return readContextFocus(plugin, { ancestorLevels, maxNodes, maxSiblings });
57
+ return readContextFocus(plugin, { ancestorLevels, maxNodes, maxSiblings, focusRemId });
55
58
  }
56
59
 
57
60
  // ────────────────────────── Page 模式 ──────────────────────────
@@ -87,10 +90,16 @@ async function readContextPage(
87
90
 
88
91
  async function readContextFocus(
89
92
  plugin: ReactRNPlugin,
90
- opts: { ancestorLevels: number; maxNodes: number; maxSiblings: number },
93
+ opts: { ancestorLevels: number; maxNodes: number; maxSiblings: number; focusRemId?: string },
91
94
  ): Promise<ReadContextResult> {
92
- const focusRem = await plugin.focus.getFocusedRem();
93
- if (!focusRem) throw new Error('当前没有聚焦的 Rem,请先在 RemNote 中点击一个 Rem');
95
+ let focusRem: Rem | undefined;
96
+ if (opts.focusRemId) {
97
+ focusRem = await plugin.rem.findOne(opts.focusRemId);
98
+ if (!focusRem) throw new Error(`指定的 Rem 不存在: ${opts.focusRemId}`);
99
+ } else {
100
+ focusRem = await plugin.focus.getFocusedRem();
101
+ if (!focusRem) throw new Error('当前没有聚焦的 Rem,请先在 RemNote 中点击一个 Rem');
102
+ }
94
103
 
95
104
  const breadcrumb = await buildBreadcrumb(plugin, focusRem);
96
105
 
@@ -27,7 +27,7 @@
27
27
  ### 人类模式
28
28
 
29
29
  ```bash
30
- remnote-bridge read-context [--mode <mode>] [--ancestor-levels <N>] [--depth <N>] [--max-nodes <N>] [--max-siblings <N>]
30
+ remnote-bridge read-context [--mode <mode>] [--ancestor-levels <N>] [--depth <N>] [--max-nodes <N>] [--max-siblings <N>] [--focus-rem-id <remId>]
31
31
  ```
32
32
 
33
33
  | 参数/选项 | 类型 | 必需 | 说明 |
@@ -37,6 +37,7 @@ remnote-bridge read-context [--mode <mode>] [--ancestor-levels <N>] [--depth <N>
37
37
  | `--depth <N>` | integer | 否 | 展开深度(默认 3,仅 page 模式) |
38
38
  | `--max-nodes <N>` | integer | 否 | 全局节点上限(默认 200) |
39
39
  | `--max-siblings <N>` | integer | 否 | 每个父节点下展示的 children 上限(默认 20) |
40
+ | `--focus-rem-id <remId>` | string | 否 | 指定鱼眼中心 Rem ID(仅 focus 模式,默认使用当前焦点) |
40
41
 
41
42
  Focus 模式输出示例:
42
43
 
@@ -73,6 +74,7 @@ Page 模式输出示例:
73
74
 
74
75
  ```bash
75
76
  remnote-bridge read-context --json '{"mode":"focus","ancestorLevels":3,"maxNodes":100}'
77
+ remnote-bridge read-context --json '{"mode":"focus","focusRemId":"kLrIOHJLyMd8Y2lyA","ancestorLevels":2}'
76
78
  remnote-bridge read-context --json '{"mode":"page","depth":5,"maxSiblings":10}'
77
79
  ```
78
80
 
@@ -87,6 +89,7 @@ remnote-bridge read-context --json '{"mode":"page","depth":5,"maxSiblings":10}'
87
89
  | `depth` | number | 否 | 展开深度(默认 3,仅 page 模式) |
88
90
  | `maxNodes` | number | 否 | 全局节点上限(默认 200) |
89
91
  | `maxSiblings` | number | 否 | 每个父节点下展示的 children 上限(默认 20) |
92
+ | `focusRemId` | string | 否 | 指定鱼眼中心 Rem ID(仅 focus 模式,默认使用当前焦点) |
90
93
 
91
94
  ---
92
95
 
@@ -124,7 +127,7 @@ remnote-bridge read-context --json '{"mode":"page","depth":5,"maxSiblings":10}'
124
127
  }
125
128
  ```
126
129
 
127
- ### 无焦点 Rem(focus 模式)
130
+ ### 无焦点 Rem(focus 模式,未指定 focusRemId)
128
131
 
129
132
  ```json
130
133
  {
@@ -135,6 +138,28 @@ remnote-bridge read-context --json '{"mode":"page","depth":5,"maxSiblings":10}'
135
138
  }
136
139
  ```
137
140
 
141
+ ### focusRemId 指定的 Rem 不存在
142
+
143
+ ```json
144
+ {
145
+ "ok": false,
146
+ "command": "read-context",
147
+ "error": "指定的 Rem 不存在: kLrIOHJLyMd8Y2lyA",
148
+ "timestamp": "2026-03-07T10:00:00.000Z"
149
+ }
150
+ ```
151
+
152
+ ### page 模式下误传 focusRemId
153
+
154
+ ```json
155
+ {
156
+ "ok": false,
157
+ "command": "read-context",
158
+ "error": "focusRemId 仅在 focus 模式下有效,page 模式下请勿指定",
159
+ "timestamp": "2026-03-07T10:00:00.000Z"
160
+ }
161
+ ```
162
+
138
163
  ### 无打开的页面(page 模式)
139
164
 
140
165
  ```json
@@ -182,15 +207,15 @@ remnote-bridge read-context --json '{"mode":"page","depth":5,"maxSiblings":10}'
182
207
  ## 内部流程
183
208
 
184
209
  ```
185
- 1. CLI 解析参数(mode, ancestorLevels, depth, maxNodes, maxSiblings)
210
+ 1. CLI 解析参数(mode, ancestorLevels, depth, maxNodes, maxSiblings, focusRemId
186
211
  2. sendRequest → WS → daemon
187
212
  3. daemon ContextReadHandler:
188
213
  ├─ 合并配置默认值(config.ts)
189
- └─ forwardToPlugin('read_context', { mode, ancestorLevels, depth, maxNodes, maxSiblings })
214
+ └─ forwardToPlugin('read_context', { mode, ancestorLevels, depth, maxNodes, maxSiblings, focusRemId })
190
215
  4. Plugin 端 readContext() 分支:
191
216
 
192
217
  ├─ mode === 'focus' → readContextFocus():
193
- │ ├─ plugin.focus.getFocusedRem() → 获取焦点 Rem
218
+ │ ├─ focusRemId ? plugin.rem.findOne(focusRemId) : plugin.focus.getFocusedRem() → 获取焦点 Rem
194
219
  │ ├─ 向上追溯 ancestorLevels 层 → ancestorPath[]
195
220
  │ ├─ buildBreadcrumb(plugin, focusRem) → 面包屑路径
196
221
  │ ├─ 从最顶层祖先开始递归 buildFisheyeNode():
@@ -274,8 +299,8 @@ focus 模式的核心特点是**渐进式展开**——离焦点越近,展开
274
299
 
275
300
  | 维度 | focus 模式 | page 模式 |
276
301
  |:-----|:----------|:----------|
277
- | 触发点 | 当前焦点 Rem(光标位置) | 当前打开的页面 Rem |
278
- | SDK 入口 | `plugin.focus.getFocusedRem()` | `plugin.window.getFocusedPaneId()` → `getOpenPaneRemId()` |
302
+ | 触发点 | 当前焦点 Rem 或指定 `focusRemId` | 当前打开的页面 Rem |
303
+ | SDK 入口 | `focusRemId` ? `plugin.rem.findOne()` : `plugin.focus.getFocusedRem()` | `plugin.window.getFocusedPaneId()` → `getOpenPaneRemId()` |
279
304
  | 深度参数 | `ancestorLevels`(向上几层) | `depth`(向下几层) |
280
305
  | 展开策略 | 鱼眼(焦点完全展开,周围递减) | 均匀展开(全树同深度控制) |
281
306
  | 大纲头注释 | `<!-- path: ... -->` + `<!-- focus: Name (id) -->` | `<!-- page: Name -->` + `<!-- path: ... -->` |
@@ -345,7 +370,8 @@ focus 模式的核心特点是**渐进式展开**——离焦点越近,展开
345
370
  ## 注意事项
346
371
 
347
372
  - read-context **不缓存**结果——每次调用都重新从 SDK 获取最新数据
348
- - focus 模式需要用户在 RemNote 中有焦点 Rem(光标需在某个 Rem 上)
373
+ - focus 模式需要用户在 RemNote 中有焦点 Rem(光标需在某个 Rem 上),或通过 `focusRemId` 指定任意 Rem 作为鱼眼中心
374
+ - `focusRemId` 仅在 focus 模式下有效,page 模式下传入会报错
349
375
  - page 模式需要 RemNote 中有打开的页面
350
376
  - 输出使用 `createMinimalSerializableRem` 序列化,不包含 backText、practiceDirection 等详细信息
351
377
  - Powerup 过滤是硬编码的,无法通过参数关闭