cladogram 0.5.5-beta.1 → 0.5.5-beta.3
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 +2 -0
- package/docs/release.md +14 -2
- package/package.json +1 -1
- package/plugins/agent/index.js +457 -24
- package/plugins/agent/style.css +299 -8
- package/skills/clado/SKILL.md +1 -0
- package/src/agent/executors.js +213 -0
- package/src/agent/probe.js +176 -0
- package/src/agent/providers/anthropic.js +220 -0
- package/src/agent/providers/index.js +52 -0
- package/src/agent/providers/openai.js +146 -0
- package/src/agent/runtime.js +557 -0
- package/src/agent/sessions.js +129 -0
- package/src/core/media-links.js +165 -11
- package/src/core/parse.js +25 -4
- package/src/html/canvas-ui.css +64 -1
- package/src/html/canvas-wires.js +2 -2
- package/src/html/media-anchors.js +174 -28
- package/src/html/mindmap-connectors.js +12 -10
- package/src/html/page.js +4 -0
- package/src/html/runtime-api.js +136 -5
- package/src/html/runtime.js +17 -218
- package/src/html/view-registry.js +95 -0
- package/src/html/views/view-cards.js +28 -0
- package/src/html/views/view-doc.js +51 -0
- package/src/html/views/view-mindmap.js +173 -0
- package/src/server/agent.js +331 -14
- package/src/server/assets/library-canvas.js +11 -2
- package/src/server/assets/library.js +92 -5
- package/src/server/events.js +189 -0
- package/src/server/mcp.js +10 -5
- package/src/server/plugin-settings.js +26 -0
- package/src/server/plugins.js +16 -3
- package/src/server/workspace.js +41 -3
- package/src/workspace/service.js +58 -21
- package/templates/test-cases.mdc +47 -0
package/src/workspace/service.js
CHANGED
|
@@ -7,7 +7,7 @@ import { ancestorTemplateContexts, contextFor, discoverWorkspaces, initialize, l
|
|
|
7
7
|
import { allReferences, linkHref, resolveReference, rewriteReferences } from './references.js';
|
|
8
8
|
import { editContent, paragraphs, paragraphLocations, contentLocation } from './content.js';
|
|
9
9
|
import { markdownLinks } from '../core/links.js';
|
|
10
|
-
import { blockMedia, mediaLinkLocations, mediaLinkTitle, mediaPointFits, mediaTargetPoint
|
|
10
|
+
import { blockMedia, findTargetLineOffset, formatTargetPoint, mediaBlockByIndex, mediaLinkLocations, mediaLinkTitle, mediaPointFits, mediaTargetPoint } from '../core/media-links.js';
|
|
11
11
|
import { sortDiagnostics, summarizeDiagnostics } from '../core/diagnostics.js';
|
|
12
12
|
|
|
13
13
|
const copySnapshot = state => ({ ...state, documents: new Map(state.documents), templates: new Map(state.templates) });
|
|
@@ -30,9 +30,28 @@ function locatedReferences(documents) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function targetMediaPoint(record, point) {
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
33
|
+
if (!record || !point) return null;
|
|
34
|
+
if (point.kind === 'line') {
|
|
35
|
+
const found = findTargetLineOffset(record.node.content, point.text);
|
|
36
|
+
if (!found) return null;
|
|
37
|
+
const loc = contentLocation(record.node.content, found.start, found.end, record.node.location.bodyStartLine);
|
|
38
|
+
return { kind: 'line', text: point.text, paragraph: loc.paragraph, documentLine: loc.startLine };
|
|
39
|
+
}
|
|
40
|
+
const index = point.kind === 'table' ? point.table : point.block;
|
|
41
|
+
const block = mediaBlockByIndex(record.node.content, point.kind, index);
|
|
42
|
+
if (!block) return null;
|
|
43
|
+
if (point.kind === 'table') {
|
|
44
|
+
if (point.row > block.media.rows && !point.text) return null;
|
|
45
|
+
return publicMediaPoint(record, { ...block, point: { kind: 'table', row: point.row, ...(point.text ? { text: point.text } : {}) } });
|
|
46
|
+
}
|
|
47
|
+
if (point.kind === 'code') {
|
|
48
|
+
if (point.line > block.media.lines.length && !point.text) return null;
|
|
49
|
+
return publicMediaPoint(record, { ...block, point: { kind: 'code', line: point.line, ...(point.text ? { text: point.text } : {}) } });
|
|
50
|
+
}
|
|
51
|
+
if (point.kind === 'mermaid') {
|
|
52
|
+
return publicMediaPoint(record, { ...block, point: { kind: 'mermaid', nodeId: point.nodeId } });
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
36
55
|
}
|
|
37
56
|
|
|
38
57
|
function publicMediaPoint(record, media) {
|
|
@@ -63,7 +82,7 @@ function receipt(op, operationIndex, feedback = {}) {
|
|
|
63
82
|
}
|
|
64
83
|
|
|
65
84
|
function resolveResults(state, results) {
|
|
66
|
-
return results.map(({ contentText, contentRange, contentBodyVersion, mediaLinkOnly, ...result }) => {
|
|
85
|
+
return results.map(({ contentText, contentRange, contentBodyVersion, mediaLinkOnly, hasTargetPoint, ...result }) => {
|
|
67
86
|
if (result.kind === 'template') return { ...result, deleted: !state.templates.has(result.file), ...(state.templates.has(result.file) ? { version: versionOf(state.templates.get(result.file)) } : {}) };
|
|
68
87
|
if (result.deleted || !state.documents.has(result.file)) return { ...result, deleted: true };
|
|
69
88
|
const source = state.documents.get(result.file), tree = treeOf(source, result.file), located = { ...result, version: versionOf(source) };
|
|
@@ -79,11 +98,13 @@ function resolveResults(state, results) {
|
|
|
79
98
|
else {
|
|
80
99
|
located.contentLocationStatus = 'exact';
|
|
81
100
|
located.contentLocation = contentLocation(record.node.content, start, start + contentText.length, record.node.location.bodyStartLine);
|
|
82
|
-
if (mediaLinkOnly) {
|
|
101
|
+
if (mediaLinkOnly || hasTargetPoint) {
|
|
83
102
|
const links = markdownLinks(record.node.content);
|
|
84
103
|
const link = links.find(ref => ref.start === start);
|
|
85
|
-
|
|
86
|
-
|
|
104
|
+
if (mediaLinkOnly) {
|
|
105
|
+
const point = mediaLinkLocations(record.node.content, links).get(start);
|
|
106
|
+
if (point?.valid) located.sourcePoint = publicMediaPoint(record, point);
|
|
107
|
+
}
|
|
87
108
|
const targetPoint = mediaTargetPoint(link?.title), target = link && resolveReference(link.target, result.file, state.documents);
|
|
88
109
|
if (targetPoint && target?.path) located.targetPoint = targetMediaPoint(findNode(getTree(state, target.file), target.path), targetPoint);
|
|
89
110
|
}
|
|
@@ -195,8 +216,8 @@ function checkWriteBase(state, op, workspaceGuarded) {
|
|
|
195
216
|
}
|
|
196
217
|
if (!workspaceGuarded && type === 'node.move' && op.index !== undefined && op.targetFile && op.targetFile !== file) fail('跨文档按序号移动需要 expectedWorkspaceVersion。', 400, { code: 'WRITE_BASE_REQUIRED' });
|
|
197
218
|
if (workspaceGuarded || expectedFileVersion !== undefined) return;
|
|
198
|
-
const needsFileVersion = type === 'node.create' && op.index !== undefined || type === 'node.move' && op.index !== undefined || type === 'link.connect' && op.targetPoint;
|
|
199
|
-
if (needsFileVersion) fail('
|
|
219
|
+
const needsFileVersion = type === 'node.create' && op.index !== undefined || type === 'node.move' && op.index !== undefined || type === 'link.connect' && op.targetPoint && op.targetPoint.kind !== 'line';
|
|
220
|
+
if (needsFileVersion) fail('按同级序号或目标段落编号写入,需要 expectedFileVersion。', 400, { code: 'WRITE_BASE_REQUIRED' });
|
|
200
221
|
if (expectedNodeVersion !== undefined) return;
|
|
201
222
|
const safeWithoutVersion = ['document.create', 'document.copy', 'node.create'].includes(type) ||
|
|
202
223
|
type === 'node.update' && position?.anchor !== undefined ||
|
|
@@ -233,7 +254,7 @@ function applyOperation(ctx, state, op) {
|
|
|
233
254
|
}
|
|
234
255
|
const file = required(op.file, 'file'); safeFile(ctx.documents, file);
|
|
235
256
|
if (type === 'document.create') {
|
|
236
|
-
if (!/\.mdc
|
|
257
|
+
if (!/\.mdc?$/i.test(file)) fail('文档扩展名需要 .md 或 .mdc。');
|
|
237
258
|
if (state.documents.has(file)) fail('文档已存在,未覆盖。', 409);
|
|
238
259
|
const title = required(op.title, 'title'); checkTitle(title);
|
|
239
260
|
const template = templateInfo(ctx, state, required(op.templateId, 'templateId'));
|
|
@@ -244,7 +265,7 @@ function applyOperation(ctx, state, op) {
|
|
|
244
265
|
if (!state.documents.has(file)) fail('文档不存在:' + file, 404);
|
|
245
266
|
if (type === 'document.copy') {
|
|
246
267
|
const newFile = required(op.newFile, 'newFile'); safeFile(ctx.documents, newFile);
|
|
247
|
-
if (!/\.mdc
|
|
268
|
+
if (!/\.mdc?$/i.test(newFile)) fail('复制后的文档扩展名需要 .md 或 .mdc。');
|
|
248
269
|
if (state.documents.has(newFile)) fail('目标文档已存在,未覆盖。', 409);
|
|
249
270
|
state.documents.set(newFile, state.documents.get(file));
|
|
250
271
|
rewriteReferences(before, state.documents, { file, newFile, copy: true }); return;
|
|
@@ -326,9 +347,8 @@ function applyOperation(ctx, state, op) {
|
|
|
326
347
|
const label = op.label || targetPath?.at(-1) || targetTree.doc.title;
|
|
327
348
|
if (/[\r\n\[\]]/.test(label)) fail('label 需要单行文字,不能含方括号。');
|
|
328
349
|
let placement = op.position;
|
|
329
|
-
if (op.
|
|
350
|
+
if ((op.sourcePoint || op.targetPoint) && targetFile !== file) fail('精确线端点要连接同一画布内的节点。');
|
|
330
351
|
if (op.sourcePoint) {
|
|
331
|
-
if (targetFile !== file) fail('精确线端点要连接同一画布内的节点。');
|
|
332
352
|
if (op.position || op.before || op.after) fail('sourcePoint 已经确定位置,独立连线标注不接受 position、before 或 after。');
|
|
333
353
|
const block = paragraphs(record.node.content)[op.sourcePoint.paragraph - 1];
|
|
334
354
|
if (!block || !mediaPointFits(blockMedia(block.text), op.sourcePoint)) fail('指定段落中找不到这个代码行、表格行或 Mermaid 节点。', 422, { code: 'INVALID_MEDIA_SOURCE' });
|
|
@@ -336,11 +356,28 @@ function applyOperation(ctx, state, op) {
|
|
|
336
356
|
}
|
|
337
357
|
let title = op.sourcePoint ? mediaLinkTitle(op.sourcePoint) : '';
|
|
338
358
|
if (op.targetPoint) {
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
if (
|
|
342
|
-
|
|
343
|
-
|
|
359
|
+
const tp = op.targetPoint;
|
|
360
|
+
let formattedTarget = '';
|
|
361
|
+
if (tp.kind === 'line') {
|
|
362
|
+
if (!findTargetLineOffset(targetRecord.node.content, tp.text)) {
|
|
363
|
+
fail('目标节点正文中找不到指定的行锚点文本:' + tp.text, 422, { code: 'INVALID_MEDIA_TARGET' });
|
|
364
|
+
}
|
|
365
|
+
formattedTarget = formatTargetPoint({ kind: 'line', text: tp.text }, { standalone: !op.sourcePoint });
|
|
366
|
+
} else {
|
|
367
|
+
const blocks = paragraphs(targetRecord.node.content).slice(0, tp.paragraph);
|
|
368
|
+
const last = blocks.at(-1);
|
|
369
|
+
if (last?.index !== tp.paragraph || !mediaPointFits(blockMedia(last.text), tp)) {
|
|
370
|
+
fail('目标段落中找不到指定的代码行、表格行或 Mermaid 节点。', 422, { code: 'INVALID_MEDIA_TARGET' });
|
|
371
|
+
}
|
|
372
|
+
const blockIndex = blocks.filter(block => blockMedia(block.text)?.kind === tp.kind).length;
|
|
373
|
+
const spec = tp.kind === 'table'
|
|
374
|
+
? { kind: 'table', table: blockIndex, row: tp.row, ...(tp.text ? { text: tp.text } : {}) }
|
|
375
|
+
: tp.kind === 'code'
|
|
376
|
+
? { kind: 'code', block: blockIndex, line: tp.line, ...(tp.text ? { text: tp.text } : {}) }
|
|
377
|
+
: { kind: 'mermaid', block: blockIndex, nodeId: tp.nodeId };
|
|
378
|
+
formattedTarget = formatTargetPoint(spec, { standalone: !op.sourcePoint });
|
|
379
|
+
}
|
|
380
|
+
title = title ? (title + ';' + formattedTarget) : formattedTarget;
|
|
344
381
|
}
|
|
345
382
|
const linkText = '[' + label + '](<' + href + '>' + (title ? ' "' + title + '"' : '') + ')';
|
|
346
383
|
const text = (op.before || '') + linkText + (op.after || '');
|
|
@@ -351,13 +388,13 @@ function applyOperation(ctx, state, op) {
|
|
|
351
388
|
if (op.sourcePoint && !mediaLinkLocations(edited.content, links).get(expectedStart)?.valid) fail('无法将链接绑定到指定内容。', 422, { code: 'INVALID_MEDIA_SOURCE' });
|
|
352
389
|
checkBody(edited.content);
|
|
353
390
|
state.documents.set(file, replaceNodeBody(tree, record.node, edited.content));
|
|
354
|
-
return { contentText: linkText, contentRange: { start: expectedStart, end: expectedStart + linkText.length }, contentBodyVersion: versionOf(edited.content), placement: placement || { mode: 'append' }, mediaLinkOnly: !!op.sourcePoint };
|
|
391
|
+
return { contentText: linkText, contentRange: { start: expectedStart, end: expectedStart + linkText.length }, contentBodyVersion: versionOf(edited.content), placement: placement || { mode: 'append' }, mediaLinkOnly: !!op.sourcePoint, hasTargetPoint: !!op.targetPoint };
|
|
355
392
|
}
|
|
356
393
|
if (type === 'link.disconnect') {
|
|
357
394
|
const matching = locatedReferences(before).filter(r => r.file === file && samePath(r.node, record.path) && (op.linkIndex === undefined || r.linkIndex === op.linkIndex) && (op.linkIndex !== undefined && op.targetFile === undefined && op.targetNode === undefined || r.target.file === (op.targetFile || file) && samePath(r.target.path, op.targetNode || null)));
|
|
358
395
|
if (!matching.length) fail('找不到这条链接。', 404);
|
|
359
396
|
let content = record.node.content;
|
|
360
|
-
for (const ref of matching.sort((a, b) => b.link.start - a.link.start)) content = content.slice(0, ref.link.start) + (ref.
|
|
397
|
+
for (const ref of matching.sort((a, b) => b.link.start - a.link.start)) content = content.slice(0, ref.link.start) + (ref.sourcePoint ? '' : ref.label) + content.slice(ref.link.end);
|
|
361
398
|
state.documents.set(file, replaceNodeBody(tree, record.node, content)); return;
|
|
362
399
|
}
|
|
363
400
|
fail('不支持的操作:' + type);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: test-cases
|
|
3
|
+
name: 测试用例脑图
|
|
4
|
+
version: "0.1"
|
|
5
|
+
purpose: 用脑图逐层拆解需求的测试场景,覆盖正常流、边界条件、异常流与回归检查点,方便评审补漏与开发后验收。
|
|
6
|
+
hard_constraints:
|
|
7
|
+
- 一个一级标题代表一个被测模块或核心能力,二级按测试维度分节(正常流、边界条件、异常流、回归检查点),三级及以下落到具体可验证用例。
|
|
8
|
+
- 每条用例必须写清前置条件、触发动作和可观察的预期结果,不能只写一句抽象标题。
|
|
9
|
+
- 每个被测模块至少覆盖正常流、边界条件和异常流三个维度,不得只测主干 happy path。
|
|
10
|
+
- 涉及已有系统改造时,必须结合本地真实代码或调用链画布补齐回归检查点,不凭空编造未核对的字段或接口。
|
|
11
|
+
- 跨文档关联到对应的需求概览、调用链或数据设计文档时,优先在具体用例行内做行内链接,避免孤立卡片和裸卡片连卡片。
|
|
12
|
+
- 多卡画布中每张卡至少参与一条真实跨卡关联(例如前置依赖或上下游链路),单卡豁免。
|
|
13
|
+
soft_constraints:
|
|
14
|
+
- 使用“🟩 新增”“🟨 修改”“🟥 删除”标明本期变更涉及的用例,“🟦 需求原文”标可追溯的逐字引用,“🟪 特别说明”标测试环境或数据准备约束。图标和文字一起写。
|
|
15
|
+
- 优先切到脑图视图评审用例覆盖度,复杂断言数据或参数组合用精简表格表达,避免在单节点塞入大段文字。
|
|
16
|
+
organization: 一级按被测模块/接口分卡,二级固定拆出正常流、边界条件、异常流与回归检查点,三级写具体场景与断言;推荐在脑图视图中展开评审。
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
# {{title}}
|
|
20
|
+
|
|
21
|
+
本画布梳理「{{title}}」的核心测试范围与验收标准,建议切到 **脑图视图** 逐层评审覆盖度。
|
|
22
|
+
|
|
23
|
+
## 正常流
|
|
24
|
+
|
|
25
|
+
### 🟩 新增:核心主干链路通过
|
|
26
|
+
- **前置条件**:测试账号与基础数据准备就绪,依赖服务返回正常。
|
|
27
|
+
- **操作步骤**:使用合法参数触发主流程。
|
|
28
|
+
- **预期结果**:返回成功状态,核心数据正确落库且状态流转符合设计契约。
|
|
29
|
+
|
|
30
|
+
## 边界条件
|
|
31
|
+
|
|
32
|
+
### 🟩 新增:极限值与幂等边界
|
|
33
|
+
- **前置条件**:构造临界输入(如数量为 `0` / 最大上限、重复提交同一请求键)。
|
|
34
|
+
- **操作步骤**:分别提交临界参数与并发重放请求。
|
|
35
|
+
- **预期结果**:参数校验准确拦截非法边界;幂等请求只生效一次,不产生重复数据。
|
|
36
|
+
|
|
37
|
+
## 异常流
|
|
38
|
+
|
|
39
|
+
### 🟩 新增:下游失败与回滚保护
|
|
40
|
+
- **前置条件**:模拟下游依赖超时、返回错误码或资源不足。
|
|
41
|
+
- **操作步骤**:触发主流程并观察异常出口。
|
|
42
|
+
- **预期结果**:返回明确错误码,已占用的临时状态或资源正确回滚,不留脏数据。
|
|
43
|
+
|
|
44
|
+
## 回归检查点
|
|
45
|
+
|
|
46
|
+
### 🟪 特别说明:存量逻辑不受影响
|
|
47
|
+
- 核对未变更的原有入口与兼容参数行为保持一致,确认无破坏性回归。
|