cladogram 0.5.5-beta.9 → 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.
@@ -24,7 +24,7 @@ const registryEntrySchema = z.strictObject({
24
24
  icon: z.string().max(16).optional(),
25
25
  readme: z.string().max(4000).optional(),
26
26
  author: z.string().max(80).default('community'),
27
- engines: z.strictObject({ clado: z.string().min(1).max(120) }).default({ clado: '^0.5.4' }),
27
+ engines: z.strictObject({ clado: z.string().min(1).max(120) }).default({ clado: '>=0.5.4 <1.0.0' }),
28
28
  permissions: z.array(z.string().max(120)).max(64).default([]),
29
29
  homepage: z.string().max(512).optional(),
30
30
  sourceDir: z.string().max(512).optional(),
@@ -83,7 +83,7 @@ export function scaffoldPlugin({ dir, id, name, kind = 'ui' }) {
83
83
  if (existsSync(targetDir)) fail(`目标目录已存在:${targetDir}`, 409);
84
84
 
85
85
  const displayName = (name || id.split('.').pop()).trim();
86
- const baseRange = '^0.5.4';
86
+ const baseRange = '>=0.5.4 <1.0.0';
87
87
  const manifest = {
88
88
  manifestVersion: 1,
89
89
  id,
@@ -295,7 +295,7 @@ const DEFAULT_REGISTRY = {
295
295
  readme: '数据以结构化 JSON 持久化于子工作区 `.clado/objects/`,长按画布空白或卡片即可贴便签,长按便签可选中并发给当前 Agent 会话。',
296
296
  category: 'ui',
297
297
  author: 'Clado Labs',
298
- engines: { clado: '^0.5.4' },
298
+ engines: { clado: '>=0.5.4 <1.0.0' },
299
299
  permissions: ['ui.mount:sidebar', 'canvas.document.read', 'canvas.selection.read'],
300
300
  },
301
301
  {
@@ -309,7 +309,7 @@ const DEFAULT_REGISTRY = {
309
309
  readme: '只读访问当前打开画布标题与选中节点数量,并注册 `inspect.summary` 能力供 Agent 调用。',
310
310
  category: 'ui',
311
311
  author: 'Clado',
312
- engines: { clado: '^0.5.4' },
312
+ engines: { clado: '>=0.5.4 <1.0.0' },
313
313
  permissions: ['ui.mount:sidebar', 'canvas.document.read', 'canvas.selection.read'],
314
314
  },
315
315
  {
@@ -323,7 +323,7 @@ const DEFAULT_REGISTRY = {
323
323
  readme: '演示多实例容器与内部 `data-subtarget` 子区域靶点的双级上下文菜单及自绘音波选中态。',
324
324
  category: 'ui',
325
325
  author: 'Community',
326
- engines: { clado: '^0.5.4' },
326
+ engines: { clado: '>=0.5.4 <1.0.0' },
327
327
  permissions: ['ui.mount:sidebar', 'canvas.selection.read'],
328
328
  },
329
329
  {
@@ -337,7 +337,7 @@ const DEFAULT_REGISTRY = {
337
337
  readme: '高敏执行器级插件,安装前自动展示进程调用权限审计清单,支持在会话详情「派发开发」中直接调用。',
338
338
  category: 'executor',
339
339
  author: 'Clado',
340
- engines: { clado: '^0.5.4' },
340
+ engines: { clado: '>=0.5.4 <1.0.0' },
341
341
  permissions: ['ui.mount:sidebar', 'canvas.document.read'],
342
342
  },
343
343
  ],
@@ -350,7 +350,7 @@ export function buildCatalogPluginFiles(entry) {
350
350
  id: entry.id,
351
351
  name: entry.name,
352
352
  version: entry.version || '0.1.0',
353
- engines: entry.engines || { clado: '^0.5.4' },
353
+ engines: entry.engines || { clado: '>=0.5.4 <1.0.0' },
354
354
  protocols: ['1.0'],
355
355
  entrypoints: { ui: { path: 'ui/index.html' } },
356
356
  permissions: entry.permissions?.length ? entry.permissions : ['ui.mount:sidebar', 'canvas.document.read'],
@@ -8,8 +8,8 @@ import { DocumentError } from '../workspace/documents.js';
8
8
  import { capabilityDefinition, capabilityPermission, compileCapabilities, mountId, pluginId } from './plugin-capabilities.js';
9
9
  import { captureDefinition } from './canvas-capture.js';
10
10
  import { compileConfiguration, pluginConfiguration } from './plugin-settings.js';
11
- import { executorSchema } from '../agent/executors.js';
12
11
  import { locked, fail } from '../workspace/storage.js';
12
+ const executorSchema = z.object({ id: z.string().min(1), name: z.string().min(1) }).passthrough();
13
13
 
14
14
  export const PLUGIN_PROTOCOL = '1.0';
15
15
  export const PLUGIN_SLOTS = ['topbar', 'bottombar', 'sidebar', 'bottom-left', 'canvas-overlay', 'top-left', 'top-right', 'bottom-right'];
@@ -32,6 +32,52 @@ function countMarkdownInWorkspace(wsDir) {
32
32
  }
33
33
  }
34
34
 
35
+ const CODE_EXT_LANG = {
36
+ ts: 'TypeScript', tsx: 'TypeScript', js: 'JavaScript', jsx: 'JavaScript', mjs: 'JavaScript',
37
+ py: 'Python', go: 'Go', rs: 'Rust', java: 'Java', kt: 'Kotlin', rb: 'Ruby', php: 'PHP', vue: 'Vue', svelte: 'Svelte',
38
+ };
39
+
40
+ export function detectWorkspaceProfile(wsDir) {
41
+ let gitBranch = '';
42
+ try {
43
+ const headFile = join(wsDir, '.git', 'HEAD');
44
+ if (existsSync(headFile)) {
45
+ const text = readFileSync(headFile, 'utf8').trim();
46
+ const m = text.match(/^ref:\s*refs\/heads\/(.+)$/);
47
+ gitBranch = m ? m[1] : text.slice(0, 7);
48
+ }
49
+ } catch {}
50
+
51
+ let codeFiles = 0;
52
+ const langCounts = new Map();
53
+ const walk = (dir, depth) => {
54
+ if (depth > 3 || codeFiles >= 300) return;
55
+ let items = [];
56
+ try { items = readdirSync(dir, { withFileTypes: true }); } catch { return; }
57
+ for (const item of items) {
58
+ if (item.name.startsWith('.') || item.name === 'node_modules' || item.name === 'dist' || item.name === 'build' || item.name === 'vendor' || item.name === 'target') continue;
59
+ const full = join(dir, item.name);
60
+ if (item.isDirectory()) {
61
+ walk(full, depth + 1);
62
+ } else if (item.isFile()) {
63
+ const ext = item.name.split('.').pop()?.toLowerCase() || '';
64
+ const lang = CODE_EXT_LANG[ext];
65
+ if (lang) {
66
+ codeFiles++;
67
+ langCounts.set(lang, (langCounts.get(lang) || 0) + 1);
68
+ }
69
+ }
70
+ }
71
+ };
72
+ try { walk(wsDir, 0); } catch {}
73
+ let primaryLang = '';
74
+ let maxCount = 0;
75
+ for (const [lang, cnt] of langCounts) {
76
+ if (cnt > maxCount) { maxCount = cnt; primaryLang = lang; }
77
+ }
78
+ return { gitBranch, codeFiles, primaryLang };
79
+ }
80
+
35
81
  export function readRecentWorkspaces() {
36
82
  const file = recentsFilePath();
37
83
  if (!existsSync(file)) return [];
@@ -44,11 +90,15 @@ export function readRecentWorkspaces() {
44
90
  const p = resolve(item.path);
45
91
  try {
46
92
  if (!existsSync(p) || !statSync(p).isDirectory()) continue;
93
+ const prof = detectWorkspaceProfile(p);
47
94
  out.push({
48
95
  path: p,
49
96
  name: basename(p) || p,
50
97
  hasClado: existsSync(join(p, '.clado')),
51
98
  isGit: existsSync(join(p, '.git')),
99
+ gitBranch: prof.gitBranch,
100
+ codeFiles: prof.codeFiles,
101
+ primaryLang: prof.primaryLang,
52
102
  documents: countMarkdownInWorkspace(p),
53
103
  lastOpenedAt: item.lastOpenedAt || new Date().toISOString(),
54
104
  });
@@ -19,6 +19,7 @@ import {
19
19
  browseLocalFolders,
20
20
  createStarterCanvas,
21
21
  deleteCanvasDocument,
22
+ detectWorkspaceProfile,
22
23
  readRecentWorkspaces,
23
24
  recordRecentWorkspace,
24
25
  renameCanvasDocument,
@@ -77,7 +78,7 @@ export function createWorkspaceHandler(directory, options = {}) {
77
78
  }
78
79
  if (options.agent && url.pathname === '/library/agent/meta') {
79
80
  const target = resolveTarget(url);
80
- options.agent.handleMeta(req, res, target.workspace); return true;
81
+ await options.agent.handleMeta(req, res, target.workspace); return true;
81
82
  }
82
83
  if (options.agent && url.pathname === '/library/agent/sessions') {
83
84
  const target = resolveTarget(url);
@@ -316,7 +317,7 @@ export function createWorkspaceHandler(directory, options = {}) {
316
317
  }
317
318
  };
318
319
  }
319
- export async function startWorkspace(input, { port = 4317, mode = 'cards', theme = 'light', entry, project = false, hubMode = false, experimentalPlugins = false, agent: agentName = 'acp' } = {}) {
320
+ export async function startWorkspace(input, { port = 4317, mode = 'cards', theme = 'light', entry, project = false, hubMode = false, experimentalPlugins = false, agent: agentName = 'pi' } = {}) {
320
321
  const path = resolve(input);
321
322
  if (!existsSync(path) && !/\.mdc?$/i.test(path)) mkdirSync(path, { recursive: true });
322
323
  if (statSync(path).isFile() && !/\.mdc?$/i.test(path)) throw new DocumentError('serve 文件需要 .mdc 或 .md 扩展名。');
@@ -407,27 +408,14 @@ export async function startWorkspace(input, { port = 4317, mode = 'cards', theme
407
408
  mcpUrl: liveMcpUrl,
408
409
  workspaceService: mcpService,
409
410
  events,
410
- resolveSettings: () => rootRuntime.settings.agentLaunch(),
411
- saveSettings: updater => {
412
- const cur = rootRuntime.settings.read('clado.agent');
413
- const next = updater(cur.value);
414
- return rootRuntime.settings.save('clado.agent', next, cur.value).value;
415
- },
416
411
  resolveRuntimeInfo: targetWorkspace => {
417
412
  const rt = runtimeFor(contextFor(workspace, targetWorkspace, root));
418
413
  return {
419
414
  stateDir: rt.ctx.state,
420
415
  documentRoot: rt.root,
421
416
  pluginDescriptors: rt.plugins?.descriptor.plugins || [],
422
- pluginDirs: rt.plugins?.pluginDirs || [],
423
- pluginMcp: rt.plugins?.pluginMcp || [],
424
- pluginPersonas: rt.plugins?.pluginPersonas || [],
425
417
  };
426
418
  },
427
- ...(agentName === 'acp' && { resolveLaunch: () => {
428
- const { command, args, env } = rootRuntime.settings.agentLaunch();
429
- return { command, args, env };
430
- } }),
431
419
  }) : null;
432
420
  function installPlugin(targetWorkspace, files) {
433
421
  const rt = runtimeFor(contextFor(workspace, targetWorkspace, root));
@@ -513,6 +501,7 @@ export async function startWorkspace(input, { port = 4317, mode = 'cards', theme
513
501
  return {
514
502
  currentWorkspace: workspace,
515
503
  currentName: basename(workspace),
504
+ currentProfile: detectWorkspaceProfile(workspace),
516
505
  hubMode: activeHubMode,
517
506
  recentWorkspaces: readRecentWorkspaces(),
518
507
  ...browseLocalFolders(dir || workspace),
@@ -1,204 +0,0 @@
1
- /**
2
- * Clado 斜杠命令体系(Slash Commands, `/xxx`):
3
- * - 内置 4 条高频命令(/arch、/test、/diff、/dispatch),统一收编原先写死的工作流入口;
4
- * - 支持工作区(.clado/commands/<name>.md)、全局(~/.clado/commands/<name>.md)与插件(<pluginDir>/commands/<name>.md)自定义命令;
5
- * - 支持 YAML Frontmatter(description / skill / workflow / persona)与 `{{args}}` 参数插值。
6
- */
7
-
8
- import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
9
- import { join } from 'node:path';
10
- import YAML from 'yaml';
11
- import { userTemplatePaths } from '../skill/templates.js';
12
-
13
- const CMD_RE = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,47}$/;
14
-
15
- export const BUILTIN_COMMANDS = Object.freeze([
16
- Object.freeze({
17
- name: 'arch',
18
- description: '读取源码并在画布中梳理系统架构与调用链',
19
- workflow: 'design',
20
- persona: 'architect',
21
- prompt: '请先用代码探针核对真实源码结构,再用画布工具梳理或更新架构设计与调用链:{{args}}',
22
- scope: 'builtin',
23
- }),
24
- Object.freeze({
25
- name: 'test',
26
- description: '基于当前画布或源码生成脑图测试用例',
27
- workflow: 'qa',
28
- persona: 'qa',
29
- prompt: '请阅读当前画布与相关源码,按 test-cases 模板生成覆盖正常流、边界与异常流的脑图测试用例:{{args}}',
30
- scope: 'builtin',
31
- }),
32
- Object.freeze({
33
- name: 'diff',
34
- description: '读取本地 Git Diff,对照画布设计逐项验收与归档',
35
- workflow: 'audit',
36
- persona: 'auditor',
37
- prompt: '请调用 probe_git_diff 读取本地真实代码变更,对照画布契约逐项验收并指出遗漏或偏离项:{{args}}',
38
- scope: 'builtin',
39
- }),
40
- Object.freeze({
41
- name: 'dispatch',
42
- description: '打包当前架构规格并派发给外部 ACP 执行器落地编码',
43
- workflow: 'dispatch',
44
- persona: 'coder',
45
- prompt: '{{args}}',
46
- scope: 'builtin',
47
- }),
48
- ]);
49
-
50
- function globalCommandsDir() {
51
- return join(userTemplatePaths().state, 'commands');
52
- }
53
-
54
- function workspaceCommandsDir(workspace) {
55
- return workspace ? join(workspace, '.clado', 'commands') : '';
56
- }
57
-
58
- export function parseCommandMarkdown(raw, fallbackName = '') {
59
- const text = String(raw || '').replace(/\r\n/g, '\n');
60
- let meta = {};
61
- let body = text.trim();
62
-
63
- const fm = text.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
64
- if (fm) {
65
- try {
66
- const parsed = YAML.parse(fm[1]);
67
- if (parsed && typeof parsed === 'object') meta = parsed;
68
- } catch {}
69
- body = fm[2].trim();
70
- }
71
-
72
- return {
73
- name: typeof meta.name === 'string' && CMD_RE.test(meta.name.trim()) ? meta.name.trim() : fallbackName,
74
- description: typeof meta.description === 'string' && meta.description.trim()
75
- ? meta.description.trim()
76
- : (body.split('\n')[0] || '自定义斜杠命令').slice(0, 100),
77
- skill: typeof meta.skill === 'string' ? meta.skill.trim() : '',
78
- workflow: typeof meta.workflow === 'string' ? meta.workflow.trim() : '',
79
- persona: typeof meta.persona === 'string' ? meta.persona.trim() : '',
80
- prompt: body,
81
- };
82
- }
83
-
84
- export function serializeCommandMarkdown({ description = '', skill = '', workflow = '', persona = '', prompt = '' }) {
85
- const fm = {};
86
- if (description) fm.description = String(description).trim();
87
- if (skill) fm.skill = String(skill).trim();
88
- if (workflow) fm.workflow = String(workflow).trim();
89
- if (persona) fm.persona = String(persona).trim();
90
- const header = Object.keys(fm).length ? `---\n${YAML.stringify(fm).trim()}\n---\n\n` : '';
91
- return `${header}${String(prompt || '').trim()}\n`;
92
- }
93
-
94
- function scanCommandsInDir(dir, scope, pluginId = '') {
95
- if (!dir || !existsSync(dir)) return [];
96
- const items = [];
97
- let entries = [];
98
- try {
99
- entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
100
- } catch {
101
- return [];
102
- }
103
- for (const entry of entries) {
104
- if (entry.name.startsWith('.') || !/\.md$/i.test(entry.name)) continue;
105
- const slug = entry.name.replace(/\.md$/i, '');
106
- if (!CMD_RE.test(slug)) continue;
107
- const full = join(dir, entry.name);
108
- try {
109
- const st = lstatSync(full);
110
- if (!st.isFile() || st.isSymbolicLink()) continue;
111
- const parsed = parseCommandMarkdown(readFileSync(full, 'utf8'), slug);
112
- items.push({
113
- ...parsed,
114
- name: parsed.name || slug,
115
- scope,
116
- ...(pluginId ? { pluginId } : {}),
117
- });
118
- } catch {}
119
- }
120
- return items;
121
- }
122
-
123
- export function listCommands(workspace, { pluginDirs = [] } = {}) {
124
- const merged = new Map();
125
- for (const cmd of BUILTIN_COMMANDS) merged.set(cmd.name, { ...cmd });
126
-
127
- for (const p of pluginDirs || []) {
128
- if (!p?.dir) continue;
129
- for (const cmd of scanCommandsInDir(join(p.dir, 'commands'), 'plugin', p.id || '')) {
130
- merged.set(cmd.name, cmd);
131
- }
132
- }
133
- for (const cmd of scanCommandsInDir(globalCommandsDir(), 'global')) {
134
- merged.set(cmd.name, cmd);
135
- }
136
- for (const cmd of scanCommandsInDir(workspaceCommandsDir(workspace), 'workspace')) {
137
- merged.set(cmd.name, cmd);
138
- }
139
-
140
- return [...merged.values()];
141
- }
142
-
143
- export function saveCommand(workspace, { name, description = '', prompt = '', skill = '', workflow = '', persona = '', scope = 'workspace' } = {}) {
144
- const cleanName = String(name || '')
145
- .trim()
146
- .replace(/^\/+/, '')
147
- .toLowerCase();
148
- if (!CMD_RE.test(cleanName)) {
149
- throw new Error('命令名仅支持英文字母、数字、连字符或下划线(如 review、api-spec)。');
150
- }
151
- const cleanPrompt = String(prompt || '').trim();
152
- if (!cleanPrompt) throw new Error('命令提示词模板不能为空。');
153
-
154
- const baseDir = scope === 'global' || !workspace ? globalCommandsDir() : workspaceCommandsDir(workspace);
155
- mkdirSync(baseDir, { recursive: true, mode: 0o700 });
156
- const filePath = join(baseDir, `${cleanName}.md`);
157
- writeFileSync(filePath, serializeCommandMarkdown({ description, skill, workflow, persona, prompt: cleanPrompt }), 'utf8');
158
- return {
159
- name: cleanName,
160
- description: String(description || cleanPrompt.slice(0, 80)).trim(),
161
- skill: String(skill || '').trim(),
162
- workflow: String(workflow || '').trim(),
163
- persona: String(persona || '').trim(),
164
- prompt: cleanPrompt,
165
- scope: scope === 'global' || !workspace ? 'global' : 'workspace',
166
- };
167
- }
168
-
169
- export function deleteCommand(workspace, { name, scope = 'workspace' } = {}) {
170
- const cleanName = String(name || '').trim().replace(/^\/+/, '').toLowerCase();
171
- if (!CMD_RE.test(cleanName)) return false;
172
- const baseDir = scope === 'global' || !workspace ? globalCommandsDir() : workspaceCommandsDir(workspace);
173
- const filePath = join(baseDir, `${cleanName}.md`);
174
- if (!existsSync(filePath)) return false;
175
- rmSync(filePath, { force: true });
176
- return true;
177
- }
178
-
179
- export function expandSlashCommand(workspace, rawInput = '', { pluginDirs = [] } = {}) {
180
- const text = String(rawInput || '').trim();
181
- const m = text.match(/^\/([a-zA-Z0-9][a-zA-Z0-9_-]{0,47})(?:\s+([\s\S]*))?$/);
182
- if (!m) return null;
183
-
184
- const cmdName = m[1].toLowerCase();
185
- const args = (m[2] || '').trim();
186
- const cmd = listCommands(workspace, { pluginDirs }).find(c => c.name.toLowerCase() === cmdName);
187
- if (!cmd) return null;
188
-
189
- let expanded = cmd.prompt || '';
190
- if (expanded.includes('{{args}}')) {
191
- expanded = expanded.replace(/\{\{args\}\}/g, args || '(当前画布与项目上下文)');
192
- } else if (args) {
193
- expanded = expanded ? `${expanded}\n\n补充参数:${args}` : args;
194
- }
195
-
196
- return {
197
- command: cmd,
198
- args,
199
- prompt: expanded.trim() || text,
200
- workflow: cmd.workflow || '',
201
- persona: cmd.persona || '',
202
- skill: cmd.skill || '',
203
- };
204
- }