cladogram 0.5.5-beta.8 → 0.6.0-beta.1
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 +102 -79
- package/bin/clado.js +1 -1
- package/docs/release.md +14 -0
- package/package.json +3 -3
- package/plugins/agent/index.js +906 -2535
- package/plugins/agent/style.css +381 -1388
- package/plugins/brand/index.js +84 -466
- package/plugins/brand/style.css +39 -172
- package/plugins/directory/index.js +33 -11
- package/plugins/directory/style.css +47 -0
- package/plugins/view-controls/index.js +17 -1
- package/plugins/view-controls/style.css +47 -29
- package/src/agent/clado-tools.js +299 -0
- package/src/agent/pi-bridge.js +487 -0
- package/src/agent/pi-config.js +630 -0
- package/src/html/plugin-ui.css +159 -134
- package/src/html/plugin-ui.js +3 -2
- package/src/server/agent.js +339 -1431
- package/src/server/assets/library.css +396 -11
- package/src/server/assets/library.html +37 -4
- package/src/server/assets/library.js +474 -203
- package/src/server/plugin-registry.js +7 -7
- package/src/server/plugins.js +62 -10
- package/src/server/workspace-hub.js +78 -1
- package/src/server/workspace.js +29 -12
- package/src/agent/context.js +0 -430
- package/src/agent/executors.js +0 -213
- package/src/agent/probe.js +0 -234
- package/src/agent/providers/anthropic.js +0 -220
- package/src/agent/providers/index.js +0 -235
- package/src/agent/providers/openai.js +0 -146
- package/src/agent/runtime.js +0 -947
- package/src/agent/sessions.js +0 -336
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clado Spatial Canvas Tools for Pi 1.x SDK
|
|
3
|
+
*
|
|
4
|
+
* 将 Clado 的空间画布读写、便签/画布组件、相机聚焦与交互式决策卡
|
|
5
|
+
* 以原生 Pi ToolDefinition 暴露给每一个 Pi AgentSession。
|
|
6
|
+
* 无任何阻塞式权限确认弹窗(遵循 Pi 原生流畅执行哲学)。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { defineTool } from '@earendil-works/pi-coding-agent';
|
|
10
|
+
import { deleteCanvasObject, listCanvasObjects, saveCanvasObject } from '../workspace/objects.js';
|
|
11
|
+
|
|
12
|
+
function textResult(data, details = undefined) {
|
|
13
|
+
const text = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
|
|
14
|
+
return {
|
|
15
|
+
content: [{ type: 'text', text }],
|
|
16
|
+
details: details ?? (typeof data === 'object' ? data : { text }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createCladoPiTools({
|
|
21
|
+
workspace,
|
|
22
|
+
stateDir,
|
|
23
|
+
workspaceService,
|
|
24
|
+
events = null,
|
|
25
|
+
emit = () => {},
|
|
26
|
+
waitForUserAnswer = null,
|
|
27
|
+
}) {
|
|
28
|
+
const runMcp = async (tool, input = {}) => {
|
|
29
|
+
if (!workspaceService) throw new Error('Clado workspaceService 未就绪。');
|
|
30
|
+
return workspaceService(tool, { workspace, ...input });
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return [
|
|
34
|
+
defineTool({
|
|
35
|
+
name: 'clado_list',
|
|
36
|
+
label: '列出画布',
|
|
37
|
+
description: '列出当前 Clado 工作区中的所有空间画布(.md/.mdc 文档)及卡片数量。',
|
|
38
|
+
promptSnippet: '列出工作区所有 Clado 画布文档',
|
|
39
|
+
parameters: {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {},
|
|
42
|
+
},
|
|
43
|
+
async execute() {
|
|
44
|
+
const res = await runMcp('clado_documents', { action: 'list' });
|
|
45
|
+
return textResult(res);
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
|
|
49
|
+
defineTool({
|
|
50
|
+
name: 'clado_read',
|
|
51
|
+
label: '读取画布',
|
|
52
|
+
description: '读取指定画布的完整结构(卡片列表、标题路径、正文、语义标签与连线关系)。',
|
|
53
|
+
promptSnippet: '读取 Clado 画布的卡片、标签与连线结构',
|
|
54
|
+
parameters: {
|
|
55
|
+
type: 'object',
|
|
56
|
+
properties: {
|
|
57
|
+
file: { type: 'string', description: '画布相对路径,如 payment-arch.md' },
|
|
58
|
+
view: { type: 'string', enum: ['outline', 'full'], description: 'outline 仅目录结构,full 返回完整卡片正文' },
|
|
59
|
+
},
|
|
60
|
+
required: ['file'],
|
|
61
|
+
},
|
|
62
|
+
async execute(_id, params) {
|
|
63
|
+
const res = await runMcp('clado_documents', {
|
|
64
|
+
action: 'read',
|
|
65
|
+
file: params.file,
|
|
66
|
+
includeContent: params.view !== 'outline',
|
|
67
|
+
});
|
|
68
|
+
return textResult(res);
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
|
|
72
|
+
defineTool({
|
|
73
|
+
name: 'clado_create',
|
|
74
|
+
label: '新建画布',
|
|
75
|
+
description: '在当前工作区创建一张新的 Clado 空间画布文档(Markdown 格式,支持卡片标题、语义标签与卡片连线)。',
|
|
76
|
+
promptSnippet: '新建一张 Clado 空间画布文档',
|
|
77
|
+
parameters: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: {
|
|
80
|
+
file: { type: 'string', description: '新画布文件名(如 arch-overview.md)' },
|
|
81
|
+
title: { type: 'string', description: '可选:画布标题(留空将自动从首行 # 标题或文件名推导)' },
|
|
82
|
+
templateId: { type: 'string', description: '可选:模板 ID(留空自动选用工作区默认模板)' },
|
|
83
|
+
content: { type: 'string', description: 'Markdown 正文(支持 # 卡片标题、## 子节与语义标签/连线)' },
|
|
84
|
+
},
|
|
85
|
+
required: ['file', 'content'],
|
|
86
|
+
},
|
|
87
|
+
async execute(_id, params) {
|
|
88
|
+
const rawBody = String(params.content || '').replace(/^\uFEFF/, '');
|
|
89
|
+
const source = rawBody.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, '');
|
|
90
|
+
const headingMatch = source.match(/^#\s+(.+)$/m);
|
|
91
|
+
const title = String(params.title || headingMatch?.[1] || params.file.replace(/\.mdc?$/i, '')).trim().slice(0, 80);
|
|
92
|
+
let templateId = params.templateId;
|
|
93
|
+
if (!templateId) {
|
|
94
|
+
try {
|
|
95
|
+
const tplList = await runMcp('clado_templates', { action: 'list' });
|
|
96
|
+
templateId = tplList?.templates?.[0]?.id || 'architecture';
|
|
97
|
+
} catch {
|
|
98
|
+
templateId = 'architecture';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const res = await runMcp('clado_documents', {
|
|
102
|
+
action: 'create',
|
|
103
|
+
file: params.file,
|
|
104
|
+
title,
|
|
105
|
+
templateId,
|
|
106
|
+
source,
|
|
107
|
+
});
|
|
108
|
+
return textResult(res);
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
111
|
+
|
|
112
|
+
defineTool({
|
|
113
|
+
name: 'clado_nodes',
|
|
114
|
+
label: '编辑画布卡片',
|
|
115
|
+
description: '批量增删改指定画布上的卡片与子节(使用 clado_batch operations),自动刷新前端实时画布。',
|
|
116
|
+
promptSnippet: '增删改 Clado 画布上的卡片节点与内容',
|
|
117
|
+
parameters: {
|
|
118
|
+
type: 'object',
|
|
119
|
+
properties: {
|
|
120
|
+
file: { type: 'string', description: '目标画布文件名' },
|
|
121
|
+
operations: {
|
|
122
|
+
type: 'array',
|
|
123
|
+
description: '节点变更操作数组,每项包含 type (node.create/node.update/node.delete/node.rename/node.move)、file、node 等字段',
|
|
124
|
+
items: { type: 'object' },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
required: ['file', 'operations'],
|
|
128
|
+
},
|
|
129
|
+
async execute(_id, params) {
|
|
130
|
+
const ops = (params.operations || []).map(op => ({
|
|
131
|
+
file: params.file,
|
|
132
|
+
...op,
|
|
133
|
+
type: op.type || (op.op ? 'node.' + op.op : 'node.update'),
|
|
134
|
+
}));
|
|
135
|
+
const res = await runMcp('clado_batch', { operations: ops });
|
|
136
|
+
return textResult(res);
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
|
|
140
|
+
defineTool({
|
|
141
|
+
name: 'clado_links',
|
|
142
|
+
label: '查看或编辑画布连线',
|
|
143
|
+
description: '列出或在画布卡片之间创建/删除依赖连线。',
|
|
144
|
+
promptSnippet: '查看或编辑画布卡片之间的依赖连线',
|
|
145
|
+
parameters: {
|
|
146
|
+
type: 'object',
|
|
147
|
+
properties: {
|
|
148
|
+
action: { type: 'string', enum: ['list', 'add', 'remove'], description: '默认 list' },
|
|
149
|
+
file: { type: 'string', description: '目标画布文件名' },
|
|
150
|
+
node: { type: 'array', items: { type: 'string' } },
|
|
151
|
+
targetFile: { type: 'string' },
|
|
152
|
+
targetNode: { type: 'array', items: { type: 'string' } },
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
async execute(_id, params) {
|
|
156
|
+
const res = await runMcp('clado_links', {
|
|
157
|
+
action: params.action || 'list',
|
|
158
|
+
...params,
|
|
159
|
+
});
|
|
160
|
+
return textResult(res);
|
|
161
|
+
},
|
|
162
|
+
}),
|
|
163
|
+
|
|
164
|
+
defineTool({
|
|
165
|
+
name: 'canvas_objects_list',
|
|
166
|
+
label: '查看便签与画布组件',
|
|
167
|
+
description: '列出当前工作区画布上所有空间便签与独立组件。',
|
|
168
|
+
promptSnippet: '查看画布上的便签与独立组件',
|
|
169
|
+
parameters: { type: 'object', properties: {} },
|
|
170
|
+
async execute() {
|
|
171
|
+
const objects = stateDir ? listCanvasObjects(stateDir) : [];
|
|
172
|
+
return textResult({ objects });
|
|
173
|
+
},
|
|
174
|
+
}),
|
|
175
|
+
|
|
176
|
+
defineTool({
|
|
177
|
+
name: 'canvas_objects_upsert',
|
|
178
|
+
label: '创建或更新便签',
|
|
179
|
+
description: '在空间画布上创建或更新一张便签(sticky_note)或画布对象,用于标注待确认备忘、风险提示或验收要点。',
|
|
180
|
+
promptSnippet: '在画布上贴便签或更新画布对象',
|
|
181
|
+
parameters: {
|
|
182
|
+
type: 'object',
|
|
183
|
+
properties: {
|
|
184
|
+
id: { type: 'string', description: '可选对象 ID(留空则新建)' },
|
|
185
|
+
kind: { type: 'string', description: '对象类型,默认为 sticky_note' },
|
|
186
|
+
title: { type: 'string', description: '便签标题' },
|
|
187
|
+
body: { type: 'string', description: '便签正文内容' },
|
|
188
|
+
color: { type: 'string', description: '颜色风格:amber / sky / mint / violet / rose' },
|
|
189
|
+
x: { type: 'number', description: '画布 X 坐标' },
|
|
190
|
+
y: { type: 'number', description: '画布 Y 坐标' },
|
|
191
|
+
},
|
|
192
|
+
required: ['title', 'body'],
|
|
193
|
+
},
|
|
194
|
+
async execute(_id, params) {
|
|
195
|
+
if (!stateDir) return textResult({ error: '当前工作区不支持画布对象持久化。' });
|
|
196
|
+
const saved = saveCanvasObject(stateDir, {
|
|
197
|
+
...(params.id ? { id: params.id } : {}),
|
|
198
|
+
kind: params.kind || 'sticky_note',
|
|
199
|
+
title: params.title,
|
|
200
|
+
data: {
|
|
201
|
+
body: params.body,
|
|
202
|
+
color: params.color || 'amber',
|
|
203
|
+
},
|
|
204
|
+
x: typeof params.x === 'number' ? params.x : 340,
|
|
205
|
+
y: typeof params.y === 'number' ? params.y : 140,
|
|
206
|
+
});
|
|
207
|
+
events?.emit(workspace, 'objects.updated', { action: 'save', object: saved });
|
|
208
|
+
return textResult({ ok: true, object: saved });
|
|
209
|
+
},
|
|
210
|
+
}),
|
|
211
|
+
|
|
212
|
+
defineTool({
|
|
213
|
+
name: 'canvas_objects_delete',
|
|
214
|
+
label: '删除便签',
|
|
215
|
+
description: '删除指定 ID 的空间便签或画布对象。',
|
|
216
|
+
parameters: {
|
|
217
|
+
type: 'object',
|
|
218
|
+
properties: {
|
|
219
|
+
id: { type: 'string', description: '要删除的对象 ID' },
|
|
220
|
+
},
|
|
221
|
+
required: ['id'],
|
|
222
|
+
},
|
|
223
|
+
async execute(_id, params) {
|
|
224
|
+
if (!stateDir) return textResult({ deleted: false });
|
|
225
|
+
const deleted = deleteCanvasObject(stateDir, params.id);
|
|
226
|
+
if (deleted) events?.emit(workspace, 'objects.updated', { action: 'delete', id: params.id });
|
|
227
|
+
return textResult({ deleted, id: params.id });
|
|
228
|
+
},
|
|
229
|
+
}),
|
|
230
|
+
|
|
231
|
+
defineTool({
|
|
232
|
+
name: 'canvas_focus',
|
|
233
|
+
label: '聚焦画布卡片',
|
|
234
|
+
description: '通知浏览器画布平滑将视角聚焦到指定文件的指定卡片标题上,方便用户即时查看修改结果。',
|
|
235
|
+
promptSnippet: '将用户画布镜头平滑聚焦到指定卡片',
|
|
236
|
+
parameters: {
|
|
237
|
+
type: 'object',
|
|
238
|
+
properties: {
|
|
239
|
+
file: { type: 'string', description: '画布文件名' },
|
|
240
|
+
heading: { type: 'string', description: '目标卡片标题' },
|
|
241
|
+
},
|
|
242
|
+
required: ['file'],
|
|
243
|
+
},
|
|
244
|
+
async execute(_id, params) {
|
|
245
|
+
emit({ type: 'focus', file: params.file, heading: params.heading || '' });
|
|
246
|
+
events?.emit(workspace, 'canvas.focus', { file: params.file, heading: params.heading || '' });
|
|
247
|
+
return textResult({ ok: true, focused: params });
|
|
248
|
+
},
|
|
249
|
+
}),
|
|
250
|
+
|
|
251
|
+
defineTool({
|
|
252
|
+
name: 'ask_user',
|
|
253
|
+
label: '向用户确认决策',
|
|
254
|
+
description: '当存在架构分歧、关键契约拍板或需要用户确认下一步流转方向时,在工作台渲染一张交互式香槟玻璃决策卡片等待用户选择。',
|
|
255
|
+
promptSnippet: '渲染交互式决策卡片向用户确认方案选择',
|
|
256
|
+
parameters: {
|
|
257
|
+
type: 'object',
|
|
258
|
+
properties: {
|
|
259
|
+
question: { type: 'string', description: '简洁明确的决策问题' },
|
|
260
|
+
options: {
|
|
261
|
+
type: 'array',
|
|
262
|
+
description: '2~4 个可选方案',
|
|
263
|
+
items: {
|
|
264
|
+
type: 'object',
|
|
265
|
+
properties: {
|
|
266
|
+
id: { type: 'string' },
|
|
267
|
+
label: { type: 'string' },
|
|
268
|
+
description: { type: 'string' },
|
|
269
|
+
},
|
|
270
|
+
required: ['label'],
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
required: ['question'],
|
|
275
|
+
},
|
|
276
|
+
async execute(toolCallId, params, signal) {
|
|
277
|
+
const questionId = 'q_' + toolCallId.slice(0, 12);
|
|
278
|
+
const options = Array.isArray(params.options)
|
|
279
|
+
? params.options.map((o, idx) => ({
|
|
280
|
+
id: String(o?.id || ('opt_' + (idx + 1))),
|
|
281
|
+
label: String(o?.label || '').trim(),
|
|
282
|
+
description: String(o?.description || '').trim(),
|
|
283
|
+
})).filter(o => o.label)
|
|
284
|
+
: [];
|
|
285
|
+
emit({
|
|
286
|
+
type: 'ask_user',
|
|
287
|
+
questionId,
|
|
288
|
+
question: String(params.question || ''),
|
|
289
|
+
options,
|
|
290
|
+
});
|
|
291
|
+
if (!waitForUserAnswer) {
|
|
292
|
+
return textResult({ questionId, answer: '用户暂未开启交互确认,请按最稳妥方案继续。' });
|
|
293
|
+
}
|
|
294
|
+
const answer = await waitForUserAnswer(questionId, signal);
|
|
295
|
+
return textResult({ questionId, answer });
|
|
296
|
+
},
|
|
297
|
+
}),
|
|
298
|
+
];
|
|
299
|
+
}
|