cladogram 0.5.5-beta.2 → 0.5.5-beta.4

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/clado.js CHANGED
@@ -314,6 +314,7 @@ ${c.bold('用法')}
314
314
  clado serve [项目目录或文档目录] [--port 4317] [--entry overview.mdc]
315
315
  clado build [目录或文件.mdc] [选项]
316
316
  clado install [目录] [--to agents] [--list] [--dry-run] [--force]
317
+ clado plugin <list|create|install|remove|search> [参数] 管理工作区插件、脚手架与市场索引
317
318
  clado update [--check] 检查并升级全局 npm 安装;--check 只检查
318
319
  clado changelog 查看随安装包提供的版本更新说明
319
320
  clado help / version
@@ -332,6 +333,9 @@ ${c.bold('选项')}
332
333
  --port=4317 网页与 MCP 共用本机端口,0 为自动分配
333
334
  --experimental-plugins serve 启用 .clado/plugins 下的本地 UI 插件
334
335
  --agent=acp|codex|off 灵感 Agent(默认 acp,预设 ZCode)
336
+ --kind=ui|executor plugin create 模板类型(默认 ui)
337
+ --name=文字 plugin create 显示名称
338
+ --registry=路径或URL plugin search 使用的轻量市场索引
335
339
  -o, --out=路径 build 输出(默认 clado.html)
336
340
  --split build 为每份文档单独输出 HTML
337
341
  --title=文字 build 显示标题
@@ -372,6 +376,10 @@ async function main() {
372
376
  port: { type: 'string' },
373
377
  'experimental-plugins': { type: 'boolean' },
374
378
  agent: { type: 'string' },
379
+ // ---- 只有 plugin 用
380
+ kind: { type: 'string' },
381
+ name: { type: 'string' },
382
+ registry: { type: 'string' },
375
383
  },
376
384
  allowPositionals: true,
377
385
  strict: true,
@@ -406,8 +414,9 @@ async function main() {
406
414
  if (flags.check && !['update', 'upgrade'].includes(command)) throw new UsageError('--check 仅用于 clado update 或 clado upgrade。');
407
415
  if (flags['experimental-plugins'] && command !== 'serve') throw new UsageError('--experimental-plugins 仅用于 clado serve。');
408
416
  if (flags.agent !== undefined && (command !== 'serve' || !['acp','codex','off'].includes(flags.agent))) throw new UsageError('--agent 支持 acp、codex 或 off,仅用于 serve。');
417
+ if ((flags.kind !== undefined || flags.name !== undefined || flags.registry !== undefined) && command !== 'plugin') throw new UsageError('--kind / --name / --registry 仅用于 clado plugin。');
409
418
  // Skill 安装、帮助和版本查询只依赖 Node 内置模块;不提前加载 YAML 或 MCP。
410
- if (['init', 'build', 'serve'].includes(command)) {
419
+ if (['init', 'build', 'serve', 'plugin'].includes(command)) {
411
420
  ({ DocumentError } = await import('../src/workspace/documents.js'));
412
421
  }
413
422
  switch (command) {
@@ -439,6 +448,83 @@ async function main() {
439
448
  }
440
449
  case 'install':
441
450
  return await cmdInstall(rest, flags);
451
+ case 'plugin': {
452
+ const [sub, ...subArgs] = rest;
453
+ if (!sub || !['list', 'create', 'install', 'remove', 'search'].includes(sub)) {
454
+ throw new UsageError('用法:clado plugin <list|create|install|remove|search> [参数]');
455
+ }
456
+ const [{ contextFor, initialize }, { BUILT_IN_PLUGINS }, registryMod] = await Promise.all([
457
+ import('../src/workspace/storage.js'),
458
+ import('../src/server/plugins.js'),
459
+ import('../src/server/plugin-registry.js'),
460
+ ]);
461
+ if (sub === 'list') {
462
+ if (subArgs.length > 1) throw new UsageError('用法:clado plugin list [工作区目录]');
463
+ const ws = resolve(subArgs[0] || '.');
464
+ const ctx = contextFor(ws, ws);
465
+ const installed = registryMod.listInstalledWorkspacePlugins(ctx.state);
466
+ const payload = { workspace: ws, builtin: BUILT_IN_PLUGINS, installed };
467
+ if (flags.json) { process.stdout.write(JSON.stringify(payload) + '\n'); return 0; }
468
+ process.stdout.write(`内置受保护插件(${BUILT_IN_PLUGINS.length}):\n`);
469
+ for (const p of BUILT_IN_PLUGINS) process.stdout.write(` - ${p.id} [${p.kind}]\n`);
470
+ process.stdout.write(`\n工作区已安装插件(${installed.length}):\n`);
471
+ if (!installed.length) process.stdout.write(' (无;可用 clado plugin create 或 clado plugin install 添加)\n');
472
+ for (const p of installed) {
473
+ process.stdout.write(` - ${p.id}@${p.version} (${p.name}) · 风险级别:${p.audit.highestRisk}\n`);
474
+ }
475
+ return 0;
476
+ }
477
+ if (sub === 'create') {
478
+ if (subArgs.length < 1 || subArgs.length > 2) throw new UsageError('用法:clado plugin create <pluginId> [输出目录] [--kind ui|executor] [--name 显示名]');
479
+ const created = registryMod.scaffoldPlugin({
480
+ id: subArgs[0],
481
+ dir: subArgs[1] || subArgs[0],
482
+ kind: flags.kind || 'ui',
483
+ name: flags.name,
484
+ });
485
+ if (flags.json) { process.stdout.write(JSON.stringify(created) + '\n'); return 0; }
486
+ process.stdout.write(`已生成插件脚手架:${displayPath(created.directory)} (${created.id}, ${created.kind})\n`);
487
+ process.stdout.write(`权限审计(${created.audit.highestRisk}):${created.audit.items.map(i => i.permission).join(', ')}\n`);
488
+ process.stdout.write(`下一步:clado plugin install ${displayPath(created.directory)} <工作区目录>\n`);
489
+ return 0;
490
+ }
491
+ if (sub === 'install') {
492
+ if (subArgs.length < 1 || subArgs.length > 2) throw new UsageError('用法:clado plugin install <插件本地目录> [工作区目录]');
493
+ const ws = resolve(subArgs[1] || '.');
494
+ if (!existsSync(ws)) mkdirSync(ws, { recursive: true });
495
+ const ctx = contextFor(ws, ws);
496
+ initialize(ctx);
497
+ const installed = registryMod.installPluginFromDirectory(ctx, subArgs[0]);
498
+ if (flags.json) { process.stdout.write(JSON.stringify(installed) + '\n'); return 0; }
499
+ process.stdout.write(`已安装插件 ${installed.id}@${installed.version} (${installed.name}) → ${displayPath(ctx.state)}/plugins/${installed.id}\n`);
500
+ process.stdout.write(`权限审计(${installed.audit.highestRisk}):${installed.audit.items.map(i => i.summary).join(';') || '无额外权限'}\n`);
501
+ return 0;
502
+ }
503
+ if (sub === 'remove') {
504
+ if (subArgs.length < 1 || subArgs.length > 2) throw new UsageError('用法:clado plugin remove <pluginId> [工作区目录]');
505
+ const ws = resolve(subArgs[1] || '.');
506
+ const ctx = contextFor(ws, ws);
507
+ const removed = registryMod.removeWorkspacePlugin(ctx, subArgs[0]);
508
+ if (flags.json) { process.stdout.write(JSON.stringify(removed) + '\n'); return 0; }
509
+ process.stdout.write(`已卸载插件:${removed.id}\n`);
510
+ return 0;
511
+ }
512
+ if (sub === 'search') {
513
+ const query = subArgs.join(' ');
514
+ const ws = resolve('.');
515
+ const ctx = contextFor(ws, ws);
516
+ const reg = await registryMod.loadRegistryIndex({ registry: flags.registry || '', stateDir: ctx.state });
517
+ const results = registryMod.searchRegistry(reg, query);
518
+ const payload = { registry: reg.name, origin: reg.origin, query, results };
519
+ if (flags.json) { process.stdout.write(JSON.stringify(payload) + '\n'); return 0; }
520
+ process.stdout.write(`插件索引:${reg.name}(命中 ${results.length} 项)\n`);
521
+ for (const item of results) {
522
+ process.stdout.write(` - ${item.id}@${item.version} [${item.category}] ${item.name}(风险:${item.audit.highestRisk})\n ${item.description}\n`);
523
+ }
524
+ return 0;
525
+ }
526
+ return 0;
527
+ }
442
528
  case 'update':
443
529
  case 'upgrade': {
444
530
  if (rest.length || flags.json && !flags.check) throw new UsageError('用法:clado update [--check [--json]]');
@@ -476,7 +562,7 @@ async function main() {
476
562
  return 0;
477
563
  default:
478
564
  process.stderr.write(`${c.red('✖')} 没有这个命令:"${command}"\n`);
479
- process.stderr.write(`${c.dim('可用命令:init / build / serve / install / update / changelog / help / version。文档操作请连接 serve 的 MCP。试试: clado --help')}\n`);
565
+ process.stderr.write(`${c.dim('可用命令:init / build / serve / install / plugin / update / changelog / help / version。文档操作请连接 serve 的 MCP。试试: clado --help')}\n`);
480
566
  return 2;
481
567
  }
482
568
  } catch (err) {
package/docs/release.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # 版本更新说明
2
2
 
3
+ ## 0.5.5-beta.4 · 轻量插件市场底座、`clado plugin` CLI 与权限审计(灰度版)
4
+
5
+ - 新增 `clado plugin <list|create|install|remove|search>` 完整命令行插件管理:支持一键生成可运行的 UI 能力插件(`--kind ui`)与 ACP 外包执行器插件(`--kind executor`)脚手架、本地安全打包安装与卸载。
6
+ - 新增轻量 JSON 插件市场索引(支持内置示例源、工作区 `.clado/plugin-registry.json` 企业私有源与远程 HTTP(S) 源)以及在线服务端点 `GET /library/plugin-registry`、`DELETE /library/install-plugin`。
7
+ - 新增插件权限分级风险审计(`low` / `medium` / `high`),严格守护 `clado.*` 内置命名空间不可覆盖、不可伪造、不可卸载。
8
+
9
+ ## 0.5.5-beta.3 · 对称「行连行」与稳定语义锚点(灰度版)
10
+
11
+ - 画布连线升级为 100% 标准 Markdown 对称表达:行内正文/列表行(`clado:to:line:<锚点>`)与代码块/表格/Mermaid 起点(`;to:line|code|table|mermaid:...`)均可精准落点到目标卡的正文行、代码行、表格数据行或 Mermaid 节点,彻底消除“仅 MCP 可见”的不对称能力。
12
+ - 引入稳定语义锚点与行号漂移兜底:目标正文行按语义短语定位、目标代码行与表格行支持附带语义 `text` 兜底,上方增删行时连线依然准确命中,并在解析阶段新增 `MD_MEDIA_LINK_TARGET` 诊断校验。
13
+ - MCP `clado_links` 全面放开对称 `targetPoint`(`line` / `code` / `table` / `mermaid`)并支持直接搭配行内 `position` 使用;卡片视图与脑图视图双视图一致渲染目标卡左侧精准蓝条、虚线引线与点击闪烁高亮。
14
+
3
15
  ## 0.5.5-beta.2 · 系统级内置原生 Agent、双协议流式与跟随 AI 视角(灰度版)
4
16
 
5
17
  - 新增系统级内置原生 Agent(`clado.agent`),支持 OpenAI 兼容与 Anthropic 原生双协议真 Token 流式输出(含 Anthropic Prompt Caching 与可折叠 `思考过程` 实时渲染)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cladogram",
3
- "version": "0.5.5-beta.2",
3
+ "version": "0.5.5-beta.4",
4
4
  "description": "MDC 三视图工作区与 MCP 文档服务:模板、节点、链接、批量操作和单文件交付",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -235,7 +235,7 @@ function toolDefinitions() {
235
235
  type: 'function',
236
236
  function: {
237
237
  name: 'clado_links',
238
- description: '建立或断开卡片/内容行连线(action: list|connect|disconnect;优先用 sourcePoint 或行内 position:{mode:"replace",anchor})。',
238
+ description: '建立或断开卡片/内容行连线(action: list|connect|disconnect;支持对称行连行:起点可用行内 position:{mode:"replace",anchor} 或 sourcePoint,落点可用 targetPoint 指定正文行 line+text / 代码行 code / 表格行 table / Mermaid 节点 mermaid)。',
239
239
  parameters: {
240
240
  type: 'object',
241
241
  properties: {
@@ -5,8 +5,101 @@ const vendor = { exports: {} };
5
5
  runInNewContext(readFileSync(new URL('../vendor/marked.umd.js', import.meta.url), 'utf8'), { module: vendor, exports: vendor.exports });
6
6
  const { lexer } = vendor.exports;
7
7
 
8
+ function safeDecode(value) {
9
+ try { return decodeURIComponent(value); } catch { return null; }
10
+ }
11
+
12
+ export function hasTargetSpec(title) {
13
+ return Boolean(title && (/^clado:to:/.test(title) || /;to:/.test(title)));
14
+ }
15
+
16
+ export function isTargetOnlyTitle(title) {
17
+ return Boolean(title && /^clado:to:/.test(title));
18
+ }
19
+
20
+ export function mediaTargetPoint(title) {
21
+ if (!title || typeof title !== 'string') return null;
22
+ let spec = null;
23
+ if (title.startsWith('clado:to:')) spec = title.slice('clado:to:'.length);
24
+ else {
25
+ const idx = title.indexOf(';to:');
26
+ if (idx < 0) return null;
27
+ spec = title.slice(idx + ';to:'.length);
28
+ }
29
+ if (!spec || /\s/.test(spec)) return null;
30
+
31
+ // 旧版简写:to:<tableIdx>:<row>
32
+ const legacyTable = /^([1-9]\d*):([1-9]\d*)$/.exec(spec);
33
+ if (legacyTable) {
34
+ const table = +legacyTable[1], row = +legacyTable[2];
35
+ if (!Number.isSafeInteger(table) || !Number.isSafeInteger(row)) return null;
36
+ return { kind: 'table', table, row };
37
+ }
38
+
39
+ // 对称表格行:to:table:<tableIdx>:<row>[:<encodedText>]
40
+ const tableMatch = /^table:([1-9]\d*):([1-9]\d*)(?::([^\s;]+))?$/.exec(spec);
41
+ if (tableMatch) {
42
+ const table = +tableMatch[1], row = +tableMatch[2];
43
+ if (!Number.isSafeInteger(table) || !Number.isSafeInteger(row)) return null;
44
+ const text = tableMatch[3] ? safeDecode(tableMatch[3]) : undefined;
45
+ if (tableMatch[3] && (!text || /[\r\n]/.test(text))) return null;
46
+ return { kind: 'table', table, row, ...(text ? { text } : {}) };
47
+ }
48
+
49
+ // 对称代码块行:to:code:<blockIdx>:<line>[:<encodedText>]
50
+ const codeMatch = /^code:([1-9]\d*):([1-9]\d*)(?::([^\s;]+))?$/.exec(spec);
51
+ if (codeMatch) {
52
+ const block = +codeMatch[1], line = +codeMatch[2];
53
+ if (!Number.isSafeInteger(block) || !Number.isSafeInteger(line)) return null;
54
+ const text = codeMatch[3] ? safeDecode(codeMatch[3]) : undefined;
55
+ if (codeMatch[3] && (!text || /[\r\n]/.test(text))) return null;
56
+ return { kind: 'code', block, line, ...(text ? { text } : {}) };
57
+ }
58
+
59
+ // 对称 Mermaid 节点:to:mermaid:<blockIdx>:<nodeId>
60
+ const mermaidMatch = /^mermaid:([1-9]\d*):([\w.-]+)$/.exec(spec);
61
+ if (mermaidMatch) {
62
+ const block = +mermaidMatch[1];
63
+ if (!Number.isSafeInteger(block)) return null;
64
+ return { kind: 'mermaid', block, nodeId: mermaidMatch[2] };
65
+ }
66
+
67
+ // 稳定语义正文/列表行锚点:to:line:<encodedText>
68
+ const lineMatch = /^line:([^\s;]+)$/.exec(spec);
69
+ if (lineMatch) {
70
+ const text = safeDecode(lineMatch[1]);
71
+ if (!text || !text.trim() || /[\r\n]/.test(text)) return null;
72
+ return { kind: 'line', text };
73
+ }
74
+
75
+ return null;
76
+ }
77
+
78
+ export function formatTargetPoint(point, { standalone = false } = {}) {
79
+ if (!point || !point.kind) return '';
80
+ const prefix = standalone ? 'clado:to:' : 'to:';
81
+ if (point.kind === 'line') {
82
+ return prefix + 'line:' + encodeURIComponent(point.text);
83
+ }
84
+ if (point.kind === 'code') {
85
+ return prefix + 'code:' + point.block + ':' + point.line + (point.text ? ':' + encodeURIComponent(point.text) : '');
86
+ }
87
+ if (point.kind === 'mermaid') {
88
+ return prefix + 'mermaid:' + point.block + ':' + point.nodeId;
89
+ }
90
+ if (point.kind === 'table') {
91
+ if (!standalone && !point.text) return 'to:' + point.table + ':' + point.row;
92
+ return prefix + 'table:' + point.table + ':' + point.row + (point.text ? ':' + encodeURIComponent(point.text) : '');
93
+ }
94
+ return '';
95
+ }
96
+
8
97
  export function mediaLinkPoint(title) {
9
- const match = /^clado:(code|table|mermaid):([^\s;]+)(?:;text:([^\s;]+))?(?:;to:[1-9]\d*:[1-9]\d*)?$/.exec(title || '');
98
+ if (!title || typeof title !== 'string') return null;
99
+ const toIdx = title.indexOf(';to:');
100
+ if (toIdx >= 0 && !mediaTargetPoint(title)) return null;
101
+ const head = toIdx >= 0 ? title.slice(0, toIdx) : title;
102
+ const match = /^clado:(code|table|mermaid):([^\s;]+)(?:;text:([^\s;]+))?$/.exec(head);
10
103
  if (!match) return null;
11
104
  const [, kind, value, encodedText] = match;
12
105
  if (encodedText && kind !== 'code') return null;
@@ -16,11 +109,6 @@ export function mediaLinkPoint(title) {
16
109
  catch { return null; }
17
110
  }
18
111
 
19
- export function mediaTargetPoint(title) {
20
- const match = /;to:([1-9]\d*):([1-9]\d*)$/.exec(title || '');
21
- return match ? { kind: 'table', table: +match[1], row: +match[2] } : null;
22
- }
23
-
24
112
  export function mediaLinkTitle(point) {
25
113
  return 'clado:' + point.kind + ':' + (point.line ?? point.row ?? point.nodeId) + (point.text ? ';text:' + encodeURIComponent(point.text) : '');
26
114
  }
@@ -40,7 +128,7 @@ export function codeReferenceOffset(line, reference) {
40
128
  }
41
129
 
42
130
  export function mediaBlock(token) {
43
- if (token?.type === 'table') return { kind: 'table', rows: token.rows.length };
131
+ if (token?.type === 'table') return { kind: 'table', rows: token.rows.length, rawRows: token.rows.map(r => r.map(c => c.text).join(' | ')) };
44
132
  if (token?.type !== 'code') return null;
45
133
  if (/^mermaid(?:\s|$)/i.test(token.lang || '')) return { kind: 'mermaid', source: token.text };
46
134
  return { kind: 'code', lines: token.text.split('\n') };
@@ -51,15 +139,49 @@ export function blockMedia(text) {
51
139
  return tokens.length === 1 ? mediaBlock(tokens[0]) : null;
52
140
  }
53
141
 
54
- export function tableBlock(markdown, index) {
142
+ export function mediaBlockByIndex(markdown, kind, index) {
55
143
  let offset = 0, count = 0;
56
144
  for (const token of lexer(markdown)) {
57
- if (token.type === 'table' && ++count === index) return { blockStart: offset, blockEnd: offset + token.raw.trimEnd().length, rows: token.rows.length };
145
+ const block = mediaBlock(token);
146
+ if (block?.kind === kind && ++count === index) {
147
+ return {
148
+ blockStart: offset,
149
+ blockEnd: offset + token.raw.trimEnd().length,
150
+ media: block,
151
+ ...(kind === 'table' ? { rows: block.rows } : {}),
152
+ };
153
+ }
58
154
  offset += token.raw.length;
59
155
  }
60
156
  return null;
61
157
  }
62
158
 
159
+ export function tableBlock(markdown, index) {
160
+ return mediaBlockByIndex(markdown, 'table', index);
161
+ }
162
+
163
+ export function findTargetLineOffset(markdown, needle) {
164
+ if (!markdown || !needle || !needle.trim()) return null;
165
+ const lines = markdown.split('\n');
166
+ let fence = null, offset = 0;
167
+ for (let i = 0; i < lines.length; i++) {
168
+ const line = lines[i];
169
+ const f = /^ {0,3}(`{3,}|~{3,})/.exec(line);
170
+ if (f) {
171
+ if (!fence) fence = f[1];
172
+ else if (f[1][0] === fence[0] && f[1].length >= fence.length) fence = null;
173
+ offset += line.length + 1;
174
+ continue;
175
+ }
176
+ if (!fence && line.includes(needle)) {
177
+ const idx = line.indexOf(needle);
178
+ return { lineNumber: i + 1, start: offset + idx, end: offset + idx + needle.length };
179
+ }
180
+ offset += line.length + 1;
181
+ }
182
+ return null;
183
+ }
184
+
63
185
  export function mediaPointFits(media, point) {
64
186
  if (media?.kind !== point?.kind) return false;
65
187
  if (point.kind === 'code') {
@@ -68,7 +190,11 @@ export function mediaPointFits(media, point) {
68
190
  if (!point.text) return true;
69
191
  return codeReferenceOffset(line, point.text) >= 0;
70
192
  }
71
- if (point.kind === 'table') return point.row <= media.rows;
193
+ if (point.kind === 'table') {
194
+ if (point.row > media.rows) return false;
195
+ if (!point.text) return true;
196
+ return Boolean(media.rawRows?.[point.row - 1]?.includes(point.text));
197
+ }
72
198
  const statements = media.source.split(/\n|;/).filter(line => !/^\s*(?:%%|flowchart\b|graph\b|classDef\b|class\s|style\s|linkStyle\b|direction\b|end\s*$)/.test(line));
73
199
  return statements.some(line => {
74
200
  const graph = line.replace(/"(?:[^"\\]|\\.)*"|\[[^\]\n]*\]|\{[^{}\n]*\}|\([^()\n]*\)|\|[^|\n]*\|/g, ' ');
@@ -76,9 +202,37 @@ export function mediaPointFits(media, point) {
76
202
  });
77
203
  }
78
204
 
205
+ export function targetPointFits(markdown, point) {
206
+ if (!point || !point.kind) return false;
207
+ if (point.kind === 'line') return Boolean(findTargetLineOffset(markdown, point.text));
208
+ if (point.kind === 'table') {
209
+ const found = mediaBlockByIndex(markdown, 'table', point.table);
210
+ if (!found) return false;
211
+ if (point.row <= found.media.rows && (!point.text || found.media.rawRows?.[point.row - 1]?.includes(point.text))) return true;
212
+ if (point.text && found.media.rawRows?.some(r => r.includes(point.text))) return true;
213
+ return false;
214
+ }
215
+ if (point.kind === 'code') {
216
+ const found = mediaBlockByIndex(markdown, 'code', point.block);
217
+ if (!found) return false;
218
+ if (mediaPointFits(found.media, { kind: 'code', line: point.line, text: point.text })) return true;
219
+ // 语义漂移兜底:若目标代码块行号移动,但带了稳定 text 锚点且在块内唯一匹配,仍视为有效!
220
+ if (point.text) {
221
+ const hits = found.media.lines.filter(line => codeReferenceOffset(line, point.text) >= 0);
222
+ return hits.length === 1;
223
+ }
224
+ return false;
225
+ }
226
+ if (point.kind === 'mermaid') {
227
+ const found = mediaBlockByIndex(markdown, 'mermaid', point.block);
228
+ return Boolean(found && mediaPointFits(found.media, { kind: 'mermaid', nodeId: point.nodeId }));
229
+ }
230
+ return false;
231
+ }
232
+
79
233
  // A standalone annotation follows its media block. Consecutive annotations share that block.
80
234
  export function mediaLinkLocations(markdown, links) {
81
- const annotated = links.filter(link => link.title?.startsWith('clado:'));
235
+ const annotated = links.filter(link => link.title?.startsWith('clado:') && !isTargetOnlyTitle(link.title));
82
236
  if (!annotated.length) return new Map();
83
237
  const locations = new Map();
84
238
  let offset = 0, media = null, blockStart, blockEnd;
package/src/core/parse.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  import { parse as parseYaml } from 'yaml';
8
8
  import { markdownLinks } from './links.js';
9
- import { mediaLinkLocations } from './media-links.js';
9
+ import { hasTargetSpec, isTargetOnlyTitle, mediaLinkLocations, mediaTargetPoint, targetPointFits } from './media-links.js';
10
10
 
11
11
  /** 开头 `---` 包的 front matter */
12
12
  const FRONT_MATTER = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
@@ -320,8 +320,17 @@ export function parseDocument(text, opts = {}) {
320
320
  * 字段,把线连到对方的 `## id` 上才说得清是哪个字段对哪个字段。
321
321
  * 键和 targets 一样用链接的**原文**(客户端是拿渲染出来的 href 查表的)。
322
322
  */
323
- const anchors = Object.create(null), targetNodes = Object.create(null), titleOf = new Map();
324
- for (const c of cards) { titleOf.set(c.id,c.title); const walk=ns=>ns.forEach(n=>{titleOf.set(n.id,n.title);walk(n.kids);});walk(c.nodes); }
323
+ const anchors = Object.create(null), targetNodes = Object.create(null), titleOf = new Map(), bodyOf = new Map();
324
+ for (const c of cards) {
325
+ titleOf.set(c.id, c.title);
326
+ bodyOf.set(c.id, c._entry.body.join('\n'));
327
+ const walk = ns => ns.forEach(n => {
328
+ titleOf.set(n.id, n.title);
329
+ bodyOf.set(n.id, n._entry.body.join('\n'));
330
+ walk(n.kids);
331
+ });
332
+ walk(c.nodes);
333
+ }
325
334
  const edgePairs = [];
326
335
 
327
336
  /** 从一张卡出发,逐层处理每个节点 */
@@ -343,7 +352,12 @@ export function parseDocument(text, opts = {}) {
343
352
  // 围栏里示范用的 `[文字](目标)` 不该在图上长出一条线来。
344
353
  for (const link of links) {
345
354
  const lineNo = e.line + source.slice(0, link.start).split('\n').length;
346
- if (link.title?.startsWith('clado:') && !mediaLocations.get(link.start)?.valid) {
355
+ if (isTargetOnlyTitle(link.title)) {
356
+ if (!mediaTargetPoint(link.title)) {
357
+ at('error', 'MD_MEDIA_LINK_TARGET', '连线落点语法不合法。', '使用 clado:to:line:<锚点文本>、clado:to:code:<块>:<行>、clado:to:table:<表>:<行> 或 clado:to:mermaid:<图>:<节点ID>。', lineNo);
358
+ continue;
359
+ }
360
+ } else if (link.title?.startsWith('clado:') && !mediaLocations.get(link.start)?.valid) {
347
361
  at('error', 'MD_MEDIA_LINK_SOURCE', '连线起点未匹配到对应代码行、表格行或 Mermaid 节点。', '用 MCP 重新定位到正确的内容块。', lineNo);
348
362
  continue;
349
363
  }
@@ -395,6 +409,13 @@ export function parseDocument(text, opts = {}) {
395
409
  targets[raw] = '';
396
410
  continue;
397
411
  }
412
+ if (hasTargetSpec(link.title)) {
413
+ const tp = mediaTargetPoint(link.title);
414
+ if (!tp || !targetPointFits(bodyOf.get(got.id) || '', tp)) {
415
+ at('error', 'MD_MEDIA_LINK_TARGET', '连线落点未匹配到目标节点内的对应正文行、代码行、表格行或 Mermaid 节点。', '核对目标卡片中的锚点文本、行号或块编号。', lineNo);
416
+ continue;
417
+ }
418
+ }
398
419
  const mine = e.level === 1 ? card.id : node.id;
399
420
  const theirs = cardOf.get(got.id) || got.id;
400
421
  if (got.id === mine && !anchor) continue;
@@ -12,7 +12,7 @@
12
12
  .markdown-body a.media-jump{position:absolute;z-index:3;width:20px;height:20px;transform:translate(-50%,-50%);border:0;border-radius:50%;background:transparent}
13
13
  .media-jump::after{content:'';position:absolute;inset:7px;border:1px solid var(--accent);border-radius:50%;background:var(--panel)}
14
14
  .media-jump:hover::after,.media-jump:focus-visible::after{background:var(--accent)}
15
- .markdown-body tr.media-target-flash>td{background:var(--accent-soft)}
15
+ .markdown-body tr.media-target-flash>td,.markdown-body .media-target-flash:not(tr){background:var(--accent-soft);border-radius:4px}
16
16
  .media-stems{position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none;z-index:2}
17
17
  .media-stems path{fill:none;stroke:var(--accent);stroke-width:1.2;stroke-opacity:.38;stroke-dasharray:3 4;stroke-linecap:round}
18
18
  .media-stems circle{fill:var(--panel);stroke:var(--accent);stroke-width:1.2;stroke-opacity:.65}
@@ -49,7 +49,7 @@ drawWires = function () {
49
49
  input.dataset.edge = targetId;
50
50
  target.append(input);
51
51
  canvasMediaStem(input, landing, true);
52
- } else if (port.dataset.mediaPoint?.includes(';to:')) return;
52
+ } else if (canvasHasTargetSpec(port.dataset.mediaPoint)) return;
53
53
  else if (port.dataset.anchor) {
54
54
  var heading = $$('.slice-head', target).find(function (h) { return port.dataset.anchorId ? h.closest('.slice').dataset.id === port.dataset.anchorId : h.textContent.trim() === port.dataset.anchor; });
55
55
  if (heading) {
@@ -67,7 +67,7 @@ drawWires = function () {
67
67
  }
68
68
  var from = point ? canvasSourceStem(svg, port, point) : canvasPort(svg, port);
69
69
  var d = canvasWirePath(from, canvasPort(svg, input));
70
- paths.push('<path class="' + (port.dataset.soft ? 'w-soft' : '') + '" data-source-id="' + esc(sourceId) + '" data-target-id="' + esc(targetId) + '"' + (point ? ' data-media-point="' + esc(port.dataset.mediaPoint) + '"' : '') + ' d="' + d + '"/>');
70
+ paths.push('<path class="' + (port.dataset.soft ? 'w-soft' : '') + '" data-source-id="' + esc(sourceId) + '" data-target-id="' + esc(targetId) + '"' + (port.dataset.mediaPoint ? ' data-media-point="' + esc(port.dataset.mediaPoint) + '"' : '') + ' d="' + d + '"/>');
71
71
  });
72
72
  svg.innerHTML = paths.join('');
73
73
  };