cladogram 0.5.5-beta.6 → 0.5.5-beta.8

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.
@@ -19,6 +19,10 @@ const registryEntrySchema = z.strictObject({
19
19
  version: z.string().min(1).max(64),
20
20
  description: z.string().max(400).default(''),
21
21
  category: z.enum(['ui', 'executor', 'template', 'view', 'renderer']).default('ui'),
22
+ kind: z.enum(['multi', 'tool', 'hybrid', 'executor', 'ui']).optional(),
23
+ source: z.enum(['official', 'team']).optional(),
24
+ icon: z.string().max(16).optional(),
25
+ readme: z.string().max(4000).optional(),
22
26
  author: z.string().max(80).default('community'),
23
27
  engines: z.strictObject({ clado: z.string().min(1).max(120) }).default({ clado: '^0.5.4' }),
24
28
  permissions: z.array(z.string().max(120)).max(64).default([]),
@@ -58,6 +62,9 @@ export function auditPluginPermissions(manifestData = {}) {
58
62
  for (const exec of executors) {
59
63
  items.push({ permission: `acp.executor:${exec.id}`, risk: 'high', summary: `注册本机 ACP 开发执行器:${exec.name || exec.id} (${exec.command})` });
60
64
  }
65
+ if (!executors.length && manifestData.category === 'executor') {
66
+ items.push({ permission: 'acp.executor', risk: 'high', summary: '注册本机 ACP 开发执行器进程' });
67
+ }
61
68
  const highestRisk = items.some(i => i.risk === 'high') ? 'high' : items.some(i => i.risk === 'medium') ? 'medium' : 'low';
62
69
  return { highestRisk, items };
63
70
  }
@@ -277,21 +284,57 @@ const DEFAULT_REGISTRY = {
277
284
  registryVersion: 1,
278
285
  name: 'Clado Built-in Starter Catalog',
279
286
  plugins: [
287
+ {
288
+ id: 'starter.sticky-notes',
289
+ name: '画布便签',
290
+ version: '1.2.0',
291
+ icon: '📌',
292
+ kind: 'multi',
293
+ source: 'official',
294
+ description: '在画布任意位置贴多张独立便签,支持长按切换色卡、多选汇总并让 AI 按 ID 单独或批量读取修改。',
295
+ readme: '数据以结构化 JSON 持久化于子工作区 `.clado/objects/`,长按画布空白或卡片即可贴便签,长按便签可选中并发给当前 Agent 会话。',
296
+ category: 'ui',
297
+ author: 'Clado Labs',
298
+ engines: { clado: '^0.5.4' },
299
+ permissions: ['ui.mount:sidebar', 'canvas.document.read', 'canvas.selection.read'],
300
+ },
280
301
  {
281
302
  id: 'starter.review-sidebar',
282
303
  name: '画布评审侧栏(官方脚手架示例)',
283
304
  version: '0.1.0',
305
+ icon: '🧭',
306
+ kind: 'tool',
307
+ source: 'official',
284
308
  description: '展示如何读取画布文档与选区并向 AI 暴露结构化能力;可通过 clado plugin create --kind ui 一键生成。',
309
+ readme: '只读访问当前打开画布标题与选中节点数量,并注册 `inspect.summary` 能力供 Agent 调用。',
285
310
  category: 'ui',
286
311
  author: 'Clado',
287
312
  engines: { clado: '^0.5.4' },
288
313
  permissions: ['ui.mount:sidebar', 'canvas.document.read', 'canvas.selection.read'],
289
314
  },
315
+ {
316
+ id: 'starter.lofi-player',
317
+ name: 'Lo-Fi 专注播放器',
318
+ version: '1.0.0',
319
+ icon: '♫',
320
+ kind: 'hybrid',
321
+ source: 'team',
322
+ description: '视图+工具双级长按示例:长按外框调整组件尺寸,长按歌名子区域独立切换喜欢或自绘音波选中态。',
323
+ readme: '演示多实例容器与内部 `data-subtarget` 子区域靶点的双级上下文菜单及自绘音波选中态。',
324
+ category: 'ui',
325
+ author: 'Community',
326
+ engines: { clado: '^0.5.4' },
327
+ permissions: ['ui.mount:sidebar', 'canvas.selection.read'],
328
+ },
290
329
  {
291
330
  id: 'starter.acp-executor',
292
331
  name: 'ACP 外包编码执行器(官方脚手架示例)',
293
332
  version: '0.1.0',
333
+ icon: '⚡',
334
+ kind: 'executor',
335
+ source: 'official',
294
336
  description: '将画布设计规格一键派发给外部 ACP 编码 Agent(Codex / Claude Code / Gemini CLI 等);可通过 clado plugin create --kind executor 一键生成。',
337
+ readme: '高敏执行器级插件,安装前自动展示进程调用权限审计清单,支持在会话详情「派发开发」中直接调用。',
295
338
  category: 'executor',
296
339
  author: 'Clado',
297
340
  engines: { clado: '^0.5.4' },
@@ -300,6 +343,60 @@ const DEFAULT_REGISTRY = {
300
343
  ],
301
344
  };
302
345
 
346
+ export function buildCatalogPluginFiles(entry) {
347
+ const isExecutor = entry.category === 'executor' || entry.kind === 'executor';
348
+ const manifest = {
349
+ manifestVersion: 1,
350
+ id: entry.id,
351
+ name: entry.name,
352
+ version: entry.version || '0.1.0',
353
+ engines: entry.engines || { clado: '^0.5.4' },
354
+ protocols: ['1.0'],
355
+ entrypoints: { ui: { path: 'ui/index.html' } },
356
+ permissions: entry.permissions?.length ? entry.permissions : ['ui.mount:sidebar', 'canvas.document.read'],
357
+ contributes: {
358
+ mounts: [{ id: 'panel', slot: 'sidebar' }],
359
+ capabilities: [],
360
+ ...(isExecutor ? {
361
+ executors: [{
362
+ id: entry.id.replace(/\./g, '-') + '-acp',
363
+ name: entry.name,
364
+ protocol: 'acp',
365
+ command: 'echo',
366
+ args: [`[${entry.name}] Ready`],
367
+ capabilities: ['code.implement', 'test.run'],
368
+ description: entry.description || '',
369
+ }],
370
+ } : {}),
371
+ },
372
+ };
373
+ const html = `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><link rel="stylesheet" href="/plugin-ui.css"><link rel="stylesheet" href="./style.css"></head><body><div class="card"><strong>${entry.name}</strong><p>${entry.description || ''}</p></div><script src="/clado-plugin-sdk.js"></script><script src="./main.js"></script></body></html>`;
374
+ const js = `window.CladoPlugin?.ready?.catch?.(() => {});\n`;
375
+ const css = `.card{padding:12px;font-size:12.5px;line-height:1.5}.card p{margin:6px 0 0;color:var(--clado-ui-muted,#667085)}`;
376
+ const b64 = s => Buffer.from(s, 'utf8').toString('base64');
377
+ return {
378
+ files: [
379
+ { path: 'clado-plugin.json', data: b64(JSON.stringify(manifest, null, 2) + '\n') },
380
+ { path: 'ui/index.html', data: b64(html) },
381
+ { path: 'ui/main.js', data: b64(js) },
382
+ { path: 'ui/style.css', data: b64(css) },
383
+ ],
384
+ audit: auditPluginPermissions(manifest),
385
+ };
386
+ }
387
+
388
+ export async function installCatalogPlugin(ctx, id, { runtime = null, registry = '', fetchImpl = fetch } = {}) {
389
+ const reg = await loadRegistryIndex({ registry, stateDir: ctx.state, fetchImpl });
390
+ const entry = reg.plugins.find(p => p.id === id);
391
+ if (!entry) fail(`未在插件市场中找到插件:${id}`, 404);
392
+ if (entry.sourceDir) {
393
+ return installPluginFromDirectory(ctx, entry.sourceDir, runtime);
394
+ }
395
+ const { files, audit } = buildCatalogPluginFiles(entry);
396
+ const installed = installWorkspacePlugin(ctx, files, runtime);
397
+ return { ...installed, audit };
398
+ }
399
+
303
400
  export async function loadRegistryIndex({ registry = '', stateDir = '', fetchImpl = fetch } = {}) {
304
401
  const source = registry || process.env.CLADO_PLUGIN_REGISTRY || (stateDir && existsSync(join(stateDir, 'plugin-registry.json')) ? join(stateDir, 'plugin-registry.json') : '');
305
402
  let rawData = DEFAULT_REGISTRY;
@@ -340,5 +437,6 @@ export function searchRegistry(registryData, query = '') {
340
437
  || item.name.toLowerCase().includes(q)
341
438
  || item.description.toLowerCase().includes(q)
342
439
  || item.category.toLowerCase().includes(q)
440
+ || (item.kind && item.kind.toLowerCase().includes(q))
343
441
  );
344
442
  }
@@ -17,11 +17,29 @@ const specs = {
17
17
  'clado.agent': {
18
18
  name: { type: 'string', minLength: 1, maxLength: 80 },
19
19
  mode: { enum: ['auto', 'builtin', 'acp'] },
20
- provider: { enum: ['auto', 'openai', 'anthropic'] },
20
+ providerId: { type: 'string', minLength: 1, maxLength: 64 },
21
+ provider: { enum: ['auto', 'openai', 'anthropic', 'custom'] },
21
22
  baseUrl: { type: 'string', minLength: 1, maxLength: 512 },
22
23
  apiKey: { type: 'string', maxLength: 512 },
23
24
  model: { type: 'string', minLength: 1, maxLength: 128 },
24
- persona: { enum: ['architect', 'qa', 'auditor', 'custom'] },
25
+ providers: {
26
+ type: 'object',
27
+ maxProperties: 24,
28
+ additionalProperties: {
29
+ type: 'object',
30
+ additionalProperties: false,
31
+ properties: {
32
+ label: { type: 'string', maxLength: 80 },
33
+ protocol: { enum: ['openai', 'anthropic'] },
34
+ baseUrl: { type: 'string', maxLength: 512 },
35
+ apiKey: { type: 'string', maxLength: 512 },
36
+ model: { type: 'string', maxLength: 128 },
37
+ enabled: { type: 'boolean' },
38
+ models: { type: 'array', maxItems: 80, items: { type: 'string', maxLength: 128 } },
39
+ },
40
+ },
41
+ },
42
+ persona: { enum: ['architect', 'coder', 'qa', 'auditor', 'custom'] },
25
43
  personaPrompt: { type: 'string', maxLength: 4000 },
26
44
  command: { type: 'string', minLength: 1, maxLength: 2048, pattern: '^.+' },
27
45
  args: { type: 'array', maxItems: 32, items: { type: 'string', maxLength: 2048 } },
@@ -51,7 +69,15 @@ const specs = {
51
69
  const defaults = {
52
70
  'clado.brand': { showScreenshot: true },
53
71
  'clado.directory': { showFilename: true },
54
- 'clado.agent': { name: 'ZCode', command: process.env.CLADO_ZCODE_ACP_PATH || 'zcode-acp-server', args: [], env: {}, placeholder: '写下一个想法…' },
72
+ 'clado.agent': {
73
+ name: 'Clado',
74
+ mode: 'builtin',
75
+ providerId: 'openai',
76
+ command: process.env.CLADO_ZCODE_ACP_PATH || 'zcode-acp-server',
77
+ args: [],
78
+ env: {},
79
+ placeholder: '写下一个想法…',
80
+ },
55
81
  };
56
82
  const fileName = 'plugin-settings.json';
57
83
  const maxBytes = 1024 * 1024;
@@ -0,0 +1,223 @@
1
+ /**
2
+ * 本机工作区中心(Workspace Hub):
3
+ * - 最近打开工作区持久化(~/.clado/recent-workspaces.json)
4
+ * - 本机目录安全浏览(供网页端选择/切换/新建项目目录)
5
+ * - 浏览器端一键新建初始画布文档(告别“必须先用外部客户端建文档”的死胡同)
6
+ */
7
+
8
+ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
9
+ import { homedir } from 'node:os';
10
+ import { basename, dirname, join, resolve } from 'node:path';
11
+ import { DocumentError, scanDirectory, workspacePath } from '../workspace/documents.js';
12
+ import { contextFor, initialize } from '../workspace/storage.js';
13
+ import { userTemplatePaths } from '../skill/templates.js';
14
+
15
+ const MAX_RECENTS = 16;
16
+
17
+ function recentsFilePath() {
18
+ const dir = userTemplatePaths().state;
19
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true, mode: 0o700 });
20
+ return join(dir, 'recent-workspaces.json');
21
+ }
22
+
23
+ function countMarkdownInWorkspace(wsDir) {
24
+ try {
25
+ const cladoDoc = join(wsDir, '.clado', 'doc');
26
+ if (existsSync(cladoDoc) && lstatSync(cladoDoc).isDirectory()) {
27
+ return scanDirectory(cladoDoc).documents.length;
28
+ }
29
+ return scanDirectory(wsDir).documents.length;
30
+ } catch {
31
+ return 0;
32
+ }
33
+ }
34
+
35
+ export function readRecentWorkspaces() {
36
+ const file = recentsFilePath();
37
+ if (!existsSync(file)) return [];
38
+ try {
39
+ const raw = JSON.parse(readFileSync(file, 'utf8'));
40
+ if (!Array.isArray(raw)) return [];
41
+ const out = [];
42
+ for (const item of raw) {
43
+ if (!item || typeof item.path !== 'string') continue;
44
+ const p = resolve(item.path);
45
+ try {
46
+ if (!existsSync(p) || !statSync(p).isDirectory()) continue;
47
+ out.push({
48
+ path: p,
49
+ name: basename(p) || p,
50
+ hasClado: existsSync(join(p, '.clado')),
51
+ isGit: existsSync(join(p, '.git')),
52
+ documents: countMarkdownInWorkspace(p),
53
+ lastOpenedAt: item.lastOpenedAt || new Date().toISOString(),
54
+ });
55
+ } catch {}
56
+ }
57
+ return out.slice(0, MAX_RECENTS);
58
+ } catch {
59
+ return [];
60
+ }
61
+ }
62
+
63
+ export function recordRecentWorkspace(wsPath) {
64
+ if (!wsPath) return [];
65
+ const clean = resolve(wsPath);
66
+ const existing = readRecentWorkspaces().filter(item => item.path !== clean);
67
+ const next = [
68
+ {
69
+ path: clean,
70
+ name: basename(clean) || clean,
71
+ lastOpenedAt: new Date().toISOString(),
72
+ },
73
+ ...existing,
74
+ ].slice(0, MAX_RECENTS);
75
+ try {
76
+ writeFileSync(recentsFilePath(), JSON.stringify(next, null, 2) + '\n', { mode: 0o600 });
77
+ } catch {}
78
+ return readRecentWorkspaces();
79
+ }
80
+
81
+ export function browseLocalFolders(dirInput = '') {
82
+ const home = homedir();
83
+ const target = dirInput ? resolve(String(dirInput)) : home;
84
+ if (!existsSync(target)) {
85
+ throw new DocumentError(`目录不存在:${target}`, 404);
86
+ }
87
+ const st = statSync(target);
88
+ const currentDir = st.isDirectory() ? target : dirname(target);
89
+ const parent = dirname(currentDir);
90
+ const parentDir = parent !== currentDir ? parent : '';
91
+
92
+ const entries = [];
93
+ let rawEntries = [];
94
+ try {
95
+ rawEntries = readdirSync(currentDir, { withFileTypes: true });
96
+ } catch {
97
+ throw new DocumentError(`无权读取目录:${currentDir}`, 403);
98
+ }
99
+
100
+ for (const entry of rawEntries) {
101
+ if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'dist' || entry.name === '$RECYCLE.BIN') {
102
+ continue;
103
+ }
104
+ const full = join(currentDir, entry.name);
105
+ try {
106
+ const info = lstatSync(full);
107
+ if (!info.isDirectory() || info.isSymbolicLink()) continue;
108
+ let mdCount = 0;
109
+ const hasClado = existsSync(join(full, '.clado'));
110
+ const isGit = existsSync(join(full, '.git'));
111
+ if (hasClado && existsSync(join(full, '.clado', 'doc'))) {
112
+ try {
113
+ mdCount = readdirSync(join(full, '.clado', 'doc')).filter(n => /\.mdc?$/i.test(n)).length;
114
+ } catch {}
115
+ } else {
116
+ try {
117
+ mdCount = readdirSync(full).filter(n => /\.mdc?$/i.test(n) && !/^readme\.md$/i.test(n)).length;
118
+ } catch {}
119
+ }
120
+ entries.push({
121
+ name: entry.name,
122
+ path: full,
123
+ hasClado,
124
+ isGit,
125
+ mdCount,
126
+ });
127
+ } catch {}
128
+ }
129
+
130
+ entries.sort((a, b) => {
131
+ const scoreA = (a.hasClado ? 4 : 0) + (a.isGit ? 2 : 0) + (a.mdCount > 0 ? 1 : 0);
132
+ const scoreB = (b.hasClado ? 4 : 0) + (b.isGit ? 2 : 0) + (b.mdCount > 0 ? 1 : 0);
133
+ if (scoreA !== scoreB) return scoreB - scoreA;
134
+ return a.name.localeCompare(b.name, 'zh-CN');
135
+ });
136
+
137
+ return {
138
+ currentDir,
139
+ parentDir,
140
+ homeDir: home,
141
+ hasClado: existsSync(join(currentDir, '.clado')),
142
+ isGit: existsSync(join(currentDir, '.git')),
143
+ entries: entries.slice(0, 120),
144
+ };
145
+ }
146
+
147
+ export function resolveWorkspaceSelection(targetPath, { createIfMissing = false, project = true } = {}) {
148
+ if (!targetPath || typeof targetPath !== 'string') {
149
+ throw new DocumentError('请提供有效的工作区目录路径。', 400);
150
+ }
151
+ const clean = resolve(targetPath.trim());
152
+ if (!existsSync(clean)) {
153
+ if (!createIfMissing) throw new DocumentError(`目录不存在:${clean}(可勾选新建目录)`, 404);
154
+ mkdirSync(clean, { recursive: true });
155
+ }
156
+ const st = statSync(clean);
157
+ if (!st.isDirectory()) throw new DocumentError('工作区路径必须是文件夹。', 400);
158
+
159
+ let workspace = clean;
160
+ let root = clean;
161
+ if (basename(clean) === 'doc' && basename(dirname(clean)) === '.clado') {
162
+ workspace = dirname(dirname(clean));
163
+ root = clean;
164
+ } else if (
165
+ project
166
+ || existsSync(join(clean, '.clado/workspace.json'))
167
+ || existsSync(join(clean, 'package.json'))
168
+ || existsSync(join(clean, '.git'))
169
+ || !scanDirectory(clean).documents.some(d => !/^readme\.md$/i.test(d.file))
170
+ ) {
171
+ const ctx = contextFor(clean, clean);
172
+ workspace = clean;
173
+ root = ctx.documents;
174
+ }
175
+ const rootCtx = contextFor(workspace, workspace, root);
176
+ initialize(rootCtx);
177
+ return { workspace, root, rootCtx };
178
+ }
179
+
180
+ export function createStarterCanvas(docRoot, { title = '系统架构概览', file = '' } = {}) {
181
+ const cleanTitle = String(title || '系统架构概览').trim().slice(0, 80) || '系统架构概览';
182
+ const slug = String(file || '')
183
+ .trim()
184
+ .replace(/\.mdc?$/i, '')
185
+ .replace(/[\\/:*?"<>|]/g, '-')
186
+ .slice(0, 64);
187
+
188
+ let fileName = (slug || 'overview') + '.md';
189
+ if (!file && existsSync(join(docRoot, fileName))) {
190
+ let idx = 2;
191
+ while (existsSync(join(docRoot, `canvas-${idx}.md`)) && idx < 99) idx++;
192
+ fileName = `canvas-${idx}.md`;
193
+ }
194
+
195
+ const fullPath = workspacePath(docRoot, fileName, true);
196
+ if (existsSync(fullPath)) {
197
+ throw new DocumentError(`画布文件已存在:${fileName}`, 409);
198
+ }
199
+ if (!existsSync(dirname(fullPath))) mkdirSync(dirname(fullPath), { recursive: true });
200
+
201
+ const body = [
202
+ `# ${cleanTitle}`,
203
+ '',
204
+ '在此梳理核心模块职责、接口契约与关键状态流转 [#核心入口|blue](#entry-contract),下游衔接 [协作与演进边界](#协作与演进边界)。',
205
+ '',
206
+ '## 核心入口契约 {#entry-contract}',
207
+ '',
208
+ '- 明确输入校验、幂等边界与状态推进条件',
209
+ '- 可在右下角直接让 Clado Agent 扫描当前代码库自动补全卡片',
210
+ '',
211
+ '# 协作与演进边界',
212
+ '',
213
+ '记录模块间调用约定、异常兜底与待确认事项。',
214
+ '',
215
+ '## 待办与验收点',
216
+ '',
217
+ '- 选中任意卡片或长按贴上便签,一键发给当前分身深化设计',
218
+ '',
219
+ ].join('\n');
220
+
221
+ writeFileSync(fullPath, body, 'utf8');
222
+ return { file: fileName, title: cleanTitle };
223
+ }