cladogram 0.5.5-beta.7 → 0.5.5-beta.9
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 +33 -10
- package/docs/release.md +13 -0
- package/package.json +1 -1
- package/plugins/agent/index.js +1150 -47
- package/plugins/agent/style.css +252 -10
- package/plugins/brand/index.js +13 -1
- package/plugins/directory/index.js +43 -4
- package/plugins/directory/style.css +47 -0
- package/src/agent/commands.js +204 -0
- package/src/agent/context.js +18 -3
- package/src/agent/mcp-client.js +308 -0
- package/src/agent/providers/index.js +197 -14
- package/src/agent/runtime.js +50 -2
- package/src/agent/sessions.js +2 -0
- package/src/agent/skills.js +190 -0
- package/src/html/plugin-ui.css +95 -2
- package/src/server/agent.js +418 -32
- package/src/server/assets/library.js +281 -2
- package/src/server/plugin-settings.js +28 -2
- package/src/server/plugins.js +61 -9
- package/src/server/workspace-hub.js +250 -0
- package/src/server/workspace.js +129 -11
|
@@ -1,42 +1,225 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 统一模型协议路由器与多供应商注册中心(OpenAI 兼容 + Anthropic 原生 + 本地免密)。
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { streamOpenAI } from './openai.js';
|
|
6
6
|
import { streamAnthropic } from './anthropic.js';
|
|
7
7
|
|
|
8
|
+
export const PROVIDER_PRESETS = [
|
|
9
|
+
{
|
|
10
|
+
id: 'openai',
|
|
11
|
+
label: 'OpenAI',
|
|
12
|
+
protocol: 'openai',
|
|
13
|
+
defaultBaseUrl: 'https://api.openai.com/v1',
|
|
14
|
+
defaultModel: 'gpt-4.1',
|
|
15
|
+
models: ['gpt-4.1', 'gpt-4.1-mini', 'gpt-4o', 'o4-mini'],
|
|
16
|
+
requiresKey: true,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: 'anthropic',
|
|
20
|
+
label: 'Anthropic',
|
|
21
|
+
protocol: 'anthropic',
|
|
22
|
+
defaultBaseUrl: 'https://api.anthropic.com/v1',
|
|
23
|
+
defaultModel: 'claude-sonnet-4-5',
|
|
24
|
+
models: ['claude-sonnet-4-5', 'claude-opus-4-5', 'claude-3-7-sonnet-latest'],
|
|
25
|
+
requiresKey: true,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'deepseek',
|
|
29
|
+
label: 'DeepSeek',
|
|
30
|
+
protocol: 'openai',
|
|
31
|
+
defaultBaseUrl: 'https://api.deepseek.com/v1',
|
|
32
|
+
defaultModel: 'deepseek-chat',
|
|
33
|
+
models: ['deepseek-chat', 'deepseek-reasoner'],
|
|
34
|
+
requiresKey: true,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 'openrouter',
|
|
38
|
+
label: 'OpenRouter',
|
|
39
|
+
protocol: 'openai',
|
|
40
|
+
defaultBaseUrl: 'https://openrouter.ai/api/v1',
|
|
41
|
+
defaultModel: 'anthropic/claude-sonnet-4',
|
|
42
|
+
models: ['anthropic/claude-sonnet-4', 'openai/gpt-4.1', 'google/gemini-2.5-pro', 'deepseek/deepseek-r1'],
|
|
43
|
+
requiresKey: true,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'siliconflow',
|
|
47
|
+
label: '硅基流动 SiliconFlow',
|
|
48
|
+
protocol: 'openai',
|
|
49
|
+
defaultBaseUrl: 'https://api.siliconflow.cn/v1',
|
|
50
|
+
defaultModel: 'deepseek-ai/DeepSeek-V3',
|
|
51
|
+
models: ['deepseek-ai/DeepSeek-V3', 'deepseek-ai/DeepSeek-R1', 'Qwen/Qwen2.5-Coder-32B-Instruct'],
|
|
52
|
+
requiresKey: true,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'ollama',
|
|
56
|
+
label: 'Ollama 本地',
|
|
57
|
+
protocol: 'openai',
|
|
58
|
+
defaultBaseUrl: 'http://127.0.0.1:11434/v1',
|
|
59
|
+
defaultModel: 'qwen2.5-coder:14b',
|
|
60
|
+
models: ['qwen2.5-coder:14b', 'llama3.3', 'deepseek-r1:14b'],
|
|
61
|
+
requiresKey: false,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'custom',
|
|
65
|
+
label: '自定义兼容接口',
|
|
66
|
+
protocol: 'openai',
|
|
67
|
+
defaultBaseUrl: 'https://api.openai.com/v1',
|
|
68
|
+
defaultModel: 'gpt-4.1-mini',
|
|
69
|
+
models: [],
|
|
70
|
+
requiresKey: true,
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
export function getProviderPreset(id) {
|
|
75
|
+
return PROVIDER_PRESETS.find(p => p.id === id) || null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function maskApiKey(key = '') {
|
|
79
|
+
const clean = String(key || '').trim();
|
|
80
|
+
if (!clean) return '';
|
|
81
|
+
if (clean.length <= 8) return '••••' + clean.slice(-2);
|
|
82
|
+
return clean.slice(0, 3) + '••••' + clean.slice(-4);
|
|
83
|
+
}
|
|
84
|
+
|
|
8
85
|
export function resolveProvider(config = {}) {
|
|
9
|
-
const
|
|
86
|
+
const activeId = String(config.providerId || '').toLowerCase();
|
|
87
|
+
const profile = (activeId && config.providers?.[activeId]) || {};
|
|
88
|
+
const explicit = String(profile.protocol || config.provider || process.env.CLADO_LLM_PROVIDER || 'auto').toLowerCase();
|
|
10
89
|
if (explicit === 'anthropic' || explicit === 'openai') return explicit;
|
|
11
|
-
const
|
|
90
|
+
const preset = getProviderPreset(activeId);
|
|
91
|
+
if (preset?.protocol === 'anthropic') return 'anthropic';
|
|
92
|
+
const baseUrl = String(profile.baseUrl || config.baseUrl || config.apiBaseUrl || process.env.CLADO_LLM_BASE_URL || '');
|
|
12
93
|
if (/anthropic\.com/i.test(baseUrl)) return 'anthropic';
|
|
13
94
|
if (!baseUrl && process.env.ANTHROPIC_API_KEY && !process.env.OPENAI_API_KEY && !process.env.CLADO_LLM_API_KEY) {
|
|
14
95
|
return 'anthropic';
|
|
15
96
|
}
|
|
16
|
-
const model = String(config.model || process.env.CLADO_LLM_MODEL || '');
|
|
97
|
+
const model = String(profile.model || config.model || process.env.CLADO_LLM_MODEL || '');
|
|
17
98
|
if (!baseUrl && /^claude-/i.test(model)) return 'anthropic';
|
|
18
99
|
return 'openai';
|
|
19
100
|
}
|
|
20
101
|
|
|
21
102
|
export function resolveProviderCredentials(config = {}) {
|
|
103
|
+
const activeId = String(config.providerId || '').toLowerCase();
|
|
104
|
+
const preset = getProviderPreset(activeId);
|
|
105
|
+
const profile = (activeId && config.providers?.[activeId]) || {};
|
|
22
106
|
const provider = resolveProvider(config);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
107
|
+
|
|
108
|
+
const rawKey = profile.apiKey
|
|
109
|
+
?? config.apiKey
|
|
110
|
+
?? process.env.CLADO_LLM_API_KEY
|
|
111
|
+
?? (provider === 'anthropic' ? process.env.ANTHROPIC_API_KEY : process.env.OPENAI_API_KEY)
|
|
112
|
+
?? '';
|
|
113
|
+
const hasApiKey = Boolean(String(rawKey || '').trim());
|
|
114
|
+
|
|
115
|
+
const baseUrl = String(
|
|
116
|
+
profile.baseUrl
|
|
117
|
+
|| config.baseUrl
|
|
118
|
+
|| config.apiBaseUrl
|
|
119
|
+
|| preset?.defaultBaseUrl
|
|
28
120
|
|| process.env.CLADO_LLM_BASE_URL
|
|
29
|
-
|| (provider === 'anthropic' ? 'https://api.anthropic.com/v1' : 'https://api.openai.com/v1')
|
|
30
|
-
|
|
121
|
+
|| (provider === 'anthropic' ? 'https://api.anthropic.com/v1' : 'https://api.openai.com/v1')
|
|
122
|
+
).trim();
|
|
123
|
+
|
|
124
|
+
const isKeylessLocal = preset?.requiresKey === false || /^https?:\/\/(127\.0\.0\.1|localhost):11434(\/|$)/i.test(baseUrl);
|
|
125
|
+
const apiKey = hasApiKey ? String(rawKey).trim() : (isKeylessLocal ? 'ollama' : '');
|
|
126
|
+
const configured = hasApiKey || Boolean(activeId === 'ollama' && profile.enabled !== false && config.providers?.ollama);
|
|
127
|
+
|
|
128
|
+
const model = String(
|
|
129
|
+
profile.model
|
|
130
|
+
|| config.model
|
|
131
|
+
|| preset?.defaultModel
|
|
31
132
|
|| process.env.CLADO_LLM_MODEL
|
|
32
|
-
|| (provider === 'anthropic' ? 'claude-sonnet-4-5' : 'gpt-4.1-mini')
|
|
33
|
-
|
|
133
|
+
|| (provider === 'anthropic' ? 'claude-sonnet-4-5' : 'gpt-4.1-mini')
|
|
134
|
+
).trim();
|
|
135
|
+
|
|
136
|
+
const resolvedId = preset?.id || (provider === 'anthropic' ? 'anthropic' : 'openai');
|
|
137
|
+
const providerLabel = profile.label || preset?.label || (provider === 'anthropic' ? 'Anthropic' : 'OpenAI');
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
providerId: resolvedId,
|
|
141
|
+
providerLabel,
|
|
142
|
+
provider,
|
|
143
|
+
apiKey,
|
|
144
|
+
hasApiKey,
|
|
145
|
+
configured,
|
|
146
|
+
baseUrl,
|
|
147
|
+
model,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function listConfiguredModels(config = {}) {
|
|
152
|
+
const out = [];
|
|
153
|
+
const providersMap = config.providers && typeof config.providers === 'object' ? config.providers : {};
|
|
154
|
+
const seen = new Set();
|
|
155
|
+
|
|
156
|
+
for (const preset of PROVIDER_PRESETS) {
|
|
157
|
+
const prof = providersMap[preset.id];
|
|
158
|
+
if (!prof) continue;
|
|
159
|
+
const hasKey = Boolean(String(prof.apiKey || '').trim()) || preset.requiresKey === false;
|
|
160
|
+
if (!hasKey) continue;
|
|
161
|
+
const models = Array.isArray(prof.models) && prof.models.length
|
|
162
|
+
? prof.models
|
|
163
|
+
: [prof.model || preset.defaultModel, ...(preset.models || [])].filter(Boolean);
|
|
164
|
+
const uniqueModels = [...new Set(models)].slice(0, 12);
|
|
165
|
+
for (const m of uniqueModels) {
|
|
166
|
+
const k = `${preset.id}::${m}`;
|
|
167
|
+
if (seen.has(k)) continue;
|
|
168
|
+
seen.add(k);
|
|
169
|
+
out.push({
|
|
170
|
+
providerId: preset.id,
|
|
171
|
+
providerLabel: prof.label || preset.label,
|
|
172
|
+
model: m,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// 兼容旧版单组顶层配置
|
|
178
|
+
if (!out.length) {
|
|
179
|
+
const creds = resolveProviderCredentials(config);
|
|
180
|
+
if (creds.configured) {
|
|
181
|
+
out.push({
|
|
182
|
+
providerId: creds.providerId,
|
|
183
|
+
providerLabel: creds.providerLabel,
|
|
184
|
+
model: creds.model,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export async function fetchProviderModels({ protocol = 'openai', baseUrl = '', apiKey = '', fetchImpl = fetch } = {}) {
|
|
192
|
+
const cleanBase = String(baseUrl || '').replace(/\/+$/, '');
|
|
193
|
+
if (!cleanBase) throw new Error('请先填写 API Base URL。');
|
|
194
|
+
const headers = { accept: 'application/json' };
|
|
195
|
+
if (protocol === 'anthropic') {
|
|
196
|
+
if (apiKey) headers['x-api-key'] = apiKey;
|
|
197
|
+
headers['anthropic-version'] = '2023-06-01';
|
|
198
|
+
} else if (apiKey) {
|
|
199
|
+
headers.authorization = `Bearer ${apiKey}`;
|
|
200
|
+
}
|
|
201
|
+
const res = await fetchImpl(`${cleanBase}/models`, {
|
|
202
|
+
method: 'GET',
|
|
203
|
+
headers,
|
|
204
|
+
signal: AbortSignal.timeout(6500),
|
|
205
|
+
});
|
|
206
|
+
if (!res.ok) {
|
|
207
|
+
const txt = await res.text().catch(() => '');
|
|
208
|
+
throw new Error(`拉取模型列表失败(HTTP ${res.status})${txt ? ':' + txt.slice(0, 140) : ''}`);
|
|
209
|
+
}
|
|
210
|
+
const body = await res.json();
|
|
211
|
+
const rawList = Array.isArray(body?.data) ? body.data : (Array.isArray(body?.models) ? body.models : []);
|
|
212
|
+
const ids = rawList
|
|
213
|
+
.map(item => (typeof item === 'string' ? item : (item?.id || item?.name || '')))
|
|
214
|
+
.map(s => String(s).trim())
|
|
215
|
+
.filter(Boolean);
|
|
216
|
+
return [...new Set(ids)].slice(0, 60);
|
|
34
217
|
}
|
|
35
218
|
|
|
36
219
|
export async function streamModelTurn(options) {
|
|
37
220
|
const creds = resolveProviderCredentials(options.config);
|
|
38
221
|
if (!creds.apiKey) {
|
|
39
|
-
throw new Error('
|
|
222
|
+
throw new Error('尚未配置供应商与模型 API Key。请点击输入框左侧模型按钮或「Agent 设置 → 供应商与模型」完成配置。');
|
|
40
223
|
}
|
|
41
224
|
const fn = creds.provider === 'anthropic' ? streamAnthropic : streamOpenAI;
|
|
42
225
|
return fn({
|
package/src/agent/runtime.js
CHANGED
|
@@ -18,6 +18,8 @@ import { createRunRecord, updateRunRecord } from './executors.js';
|
|
|
18
18
|
import { classifyShellCommand, executeWorkspaceCommand, probeGitDiff, probeRead, probeSearch, probeTree } from './probe.js';
|
|
19
19
|
import { streamModelTurn } from './providers/index.js';
|
|
20
20
|
import { resolvePersona } from './sessions.js';
|
|
21
|
+
import { callExternalMcpTool, discoverExternalMcpTools } from './mcp-client.js';
|
|
22
|
+
import { formatSkillsCatalog, listSkills, readSkill } from './skills.js';
|
|
21
23
|
|
|
22
24
|
const MAX_STEPS = 12;
|
|
23
25
|
|
|
@@ -120,6 +122,20 @@ function toolDefinitions({ enablePeers = false } = {}) {
|
|
|
120
122
|
},
|
|
121
123
|
},
|
|
122
124
|
},
|
|
125
|
+
{
|
|
126
|
+
type: 'function',
|
|
127
|
+
function: {
|
|
128
|
+
name: 'load_skill',
|
|
129
|
+
description: '按需加载已挂载技能库(SKILL.md)中的完整专业指南与 SOP。',
|
|
130
|
+
parameters: {
|
|
131
|
+
type: 'object',
|
|
132
|
+
properties: {
|
|
133
|
+
name: { type: 'string', description: '技能标识(slug)或名称' },
|
|
134
|
+
},
|
|
135
|
+
required: ['name'],
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
123
139
|
{
|
|
124
140
|
type: 'function',
|
|
125
141
|
function: {
|
|
@@ -472,6 +488,11 @@ function humanizeToolStatus(name, args = {}) {
|
|
|
472
488
|
if (name === 'message_peer') return `正在呼叫「${args.target || ''}」…`;
|
|
473
489
|
if (name === 'canvas_objects_read') return args.id ? `正在读取组件 #${args.id}…` : '正在读取画布组件…';
|
|
474
490
|
if (name === 'canvas_objects_write') return args.action === 'delete' ? `正在移除组件 #${args.id || ''}…` : '正在更新画布便签/组件…';
|
|
491
|
+
if (name === 'load_skill') return `正在读取技能「${args.name || ''}」…`;
|
|
492
|
+
if (name.startsWith('mcp__')) {
|
|
493
|
+
const parts = name.split('__');
|
|
494
|
+
return `正在调用外部 MCP · ${parts[1] || ''}/${parts[2] || name}…`;
|
|
495
|
+
}
|
|
475
496
|
if (name.startsWith('clado_')) {
|
|
476
497
|
const target = (Array.isArray(args.node) && args.node.at(-1)) || args.title || args.file || '画布';
|
|
477
498
|
return `正在编辑画布 · ${String(target).slice(0, 12)}…`;
|
|
@@ -488,6 +509,8 @@ export async function runVerticalAgent({
|
|
|
488
509
|
events = null,
|
|
489
510
|
config = {},
|
|
490
511
|
debugConfig = null,
|
|
512
|
+
pluginMeta = null,
|
|
513
|
+
preloadedSkill = '',
|
|
491
514
|
history = [],
|
|
492
515
|
canvasBaseline = null,
|
|
493
516
|
activePeerLocks = [],
|
|
@@ -507,9 +530,20 @@ export async function runVerticalAgent({
|
|
|
507
530
|
fetchImpl = fetch,
|
|
508
531
|
}) {
|
|
509
532
|
const effectiveDebug = debugConfig || (stateDir ? readAgentDebugConfig(stateDir).config : undefined);
|
|
510
|
-
const
|
|
533
|
+
const pluginDirs = Array.isArray(pluginMeta?.pluginDirs) ? pluginMeta.pluginDirs : [];
|
|
534
|
+
const pluginMcp = Array.isArray(pluginMeta?.pluginMcp) ? pluginMeta.pluginMcp : [];
|
|
535
|
+
const pluginPersonasMap = Object.fromEntries(
|
|
536
|
+
(Array.isArray(pluginMeta?.pluginPersonas) ? pluginMeta.pluginPersonas : []).map(p => [p.id, p]),
|
|
537
|
+
);
|
|
538
|
+
const mergedPersonas = { ...pluginPersonasMap, ...(effectiveDebug?.personas || {}) };
|
|
539
|
+
const activePersona = resolvePersona(persona || config.persona, config.personaPrompt, mergedPersonas);
|
|
511
540
|
const isPlanOnly = execMode === 'plan';
|
|
512
541
|
|
|
542
|
+
const availableSkills = listSkills(workspace, { pluginDirs });
|
|
543
|
+
const skillsCatalogText = formatSkillsCatalog(availableSkills);
|
|
544
|
+
const preloadedSkillObj = preloadedSkill ? readSkill(workspace, preloadedSkill, { pluginDirs }) : null;
|
|
545
|
+
const externalMcp = await discoverExternalMcpTools(workspace, { pluginMcp }).catch(() => ({ definitions: [], registry: new Map(), errors: [] }));
|
|
546
|
+
|
|
513
547
|
const run = createRunRecord(stateDir, {
|
|
514
548
|
kind: 'builtin',
|
|
515
549
|
mode,
|
|
@@ -547,6 +581,8 @@ export async function runVerticalAgent({
|
|
|
547
581
|
? '【重要限制:当前处于「规划(只读)」模式】严禁修改画布文档或执行写命令;仅允许使用只读探针查证、拆解步骤(todo_write)或调用 ask_user 与用户对齐方案。'
|
|
548
582
|
: '',
|
|
549
583
|
MODE_PROMPTS[mode] || MODE_PROMPTS.general,
|
|
584
|
+
skillsCatalogText,
|
|
585
|
+
preloadedSkillObj ? `【本次命令预加载技能:${preloadedSkillObj.name}】\n${preloadedSkillObj.body}` : '',
|
|
550
586
|
].filter(Boolean).join('\n\n');
|
|
551
587
|
|
|
552
588
|
const isResume = Boolean(resumeToolResult || resumeCommandResult);
|
|
@@ -596,10 +632,22 @@ export async function runVerticalAgent({
|
|
|
596
632
|
conversation.push({ role: 'user', content: segmented.seg4UserContent });
|
|
597
633
|
}
|
|
598
634
|
|
|
599
|
-
const tools =
|
|
635
|
+
const tools = [
|
|
636
|
+
...toolDefinitions({ enablePeers: Boolean(peerCoordinator) }),
|
|
637
|
+
...externalMcp.definitions,
|
|
638
|
+
];
|
|
600
639
|
|
|
601
640
|
async function executeTool(name, rawArgs) {
|
|
602
641
|
const args = rawArgs && typeof rawArgs === 'object' ? rawArgs : {};
|
|
642
|
+
if (name === 'load_skill') {
|
|
643
|
+
const found = readSkill(workspace, args.name, { pluginDirs });
|
|
644
|
+
if (!found) return { ok: false, error: `未找到技能:${args.name || ''}` };
|
|
645
|
+
return { ok: true, slug: found.slug, name: found.name, description: found.description, instructions: found.body };
|
|
646
|
+
}
|
|
647
|
+
if (externalMcp.registry.has(name)) {
|
|
648
|
+
const entry = externalMcp.registry.get(name);
|
|
649
|
+
return await callExternalMcpTool(entry, args, workspace);
|
|
650
|
+
}
|
|
603
651
|
if (name === 'todo_write') {
|
|
604
652
|
const list = Array.isArray(args.todos)
|
|
605
653
|
? args.todos.slice(0, 12).map(t => ({
|
package/src/agent/sessions.js
CHANGED
|
@@ -133,6 +133,7 @@ export function saveSessionRecord(stateDir, record) {
|
|
|
133
133
|
title: String(record.title || existing?.title || '新会话').slice(0, 60),
|
|
134
134
|
persona,
|
|
135
135
|
pal: record.pal || existing?.pal || paletteForPersona(persona),
|
|
136
|
+
engine: (record.engine || existing?.engine) === 'acp' ? 'acp' : 'builtin',
|
|
136
137
|
mode: record.mode || existing?.mode || 'design',
|
|
137
138
|
execMode: (record.execMode || existing?.execMode) === 'plan' ? 'plan' : 'act',
|
|
138
139
|
archived: record.archived !== undefined ? Boolean(record.archived) : Boolean(existing?.archived),
|
|
@@ -214,6 +215,7 @@ export function listSessionRecords(stateDir, limitOrOptions = 20) {
|
|
|
214
215
|
title: data.title || '未命名会话',
|
|
215
216
|
persona: data.persona || 'architect',
|
|
216
217
|
pal: data.pal || paletteForPersona(data.persona || 'architect'),
|
|
218
|
+
engine: data.engine === 'acp' ? 'acp' : 'builtin',
|
|
217
219
|
mode: data.mode || 'design',
|
|
218
220
|
execMode: data.execMode === 'plan' ? 'plan' : 'act',
|
|
219
221
|
archived,
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clado 原生 Agent 技能体系(Skills):
|
|
3
|
+
* - 标准 SKILL.md(YAML Frontmatter + Markdown 正文),兼容主流 Agent 技能规范;
|
|
4
|
+
* - 三层发现优先级:工作区(.clado/skills/<slug>/SKILL.md) > 全局(~/.clado/skills/<slug>/SKILL.md) > 已安装插件(<pluginDir>/skills/<slug>/SKILL.md);
|
|
5
|
+
* - 渐进式披露:系统提示词仅注入紧凑目录(name + description),Agent 按需调用 load_skill 工具拉取完整指南。
|
|
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 SLUG_RE = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;
|
|
14
|
+
|
|
15
|
+
function globalSkillsDir() {
|
|
16
|
+
return join(userTemplatePaths().state, 'skills');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function workspaceSkillsDir(workspace) {
|
|
20
|
+
return workspace ? join(workspace, '.clado', 'skills') : '';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function parseSkillMarkdown(raw, fallbackSlug = '') {
|
|
24
|
+
const text = String(raw || '').replace(/\r\n/g, '\n');
|
|
25
|
+
let meta = {};
|
|
26
|
+
let body = text.trim();
|
|
27
|
+
|
|
28
|
+
const fm = text.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
29
|
+
if (fm) {
|
|
30
|
+
try {
|
|
31
|
+
const parsed = YAML.parse(fm[1]);
|
|
32
|
+
if (parsed && typeof parsed === 'object') meta = parsed;
|
|
33
|
+
} catch {}
|
|
34
|
+
body = fm[2].trim();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const name = typeof meta.name === 'string' && meta.name.trim() ? meta.name.trim() : fallbackSlug;
|
|
38
|
+
const description = typeof meta.description === 'string' && meta.description.trim()
|
|
39
|
+
? meta.description.trim()
|
|
40
|
+
: (body.split('\n').find(line => line.trim() && !line.startsWith('#')) || '自定义 Agent 技能').slice(0, 140);
|
|
41
|
+
const tags = Array.isArray(meta.tags) ? meta.tags.map(t => String(t).trim()).filter(Boolean) : [];
|
|
42
|
+
return { name, description, tags, body };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function serializeSkillMarkdown({ name, description, tags = [], body = '' }) {
|
|
46
|
+
const fm = { name: String(name || '').trim(), description: String(description || '').trim() };
|
|
47
|
+
if (Array.isArray(tags) && tags.length) fm.tags = tags;
|
|
48
|
+
return `---\n${YAML.stringify(fm).trim()}\n---\n\n${String(body || '').trim()}\n`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function scanSkillsInDir(dir, scope, pluginId = '') {
|
|
52
|
+
if (!dir || !existsSync(dir)) return [];
|
|
53
|
+
const items = [];
|
|
54
|
+
let entries = [];
|
|
55
|
+
try {
|
|
56
|
+
entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
57
|
+
} catch {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
if (entry.name.startsWith('.')) continue;
|
|
62
|
+
const full = join(dir, entry.name);
|
|
63
|
+
try {
|
|
64
|
+
const st = lstatSync(full);
|
|
65
|
+
if (st.isSymbolicLink()) continue;
|
|
66
|
+
if (st.isDirectory()) {
|
|
67
|
+
const skillFile = join(full, 'SKILL.md');
|
|
68
|
+
if (!existsSync(skillFile) || !lstatSync(skillFile).isFile()) continue;
|
|
69
|
+
const parsed = parseSkillMarkdown(readFileSync(skillFile, 'utf8'), entry.name);
|
|
70
|
+
items.push({
|
|
71
|
+
slug: entry.name,
|
|
72
|
+
name: parsed.name || entry.name,
|
|
73
|
+
description: parsed.description,
|
|
74
|
+
tags: parsed.tags,
|
|
75
|
+
body: parsed.body,
|
|
76
|
+
scope,
|
|
77
|
+
...(pluginId ? { pluginId } : {}),
|
|
78
|
+
path: skillFile,
|
|
79
|
+
});
|
|
80
|
+
} else if (st.isFile() && /\.md$/i.test(entry.name)) {
|
|
81
|
+
const slug = entry.name.replace(/\.md$/i, '');
|
|
82
|
+
const parsed = parseSkillMarkdown(readFileSync(full, 'utf8'), slug);
|
|
83
|
+
items.push({
|
|
84
|
+
slug,
|
|
85
|
+
name: parsed.name || slug,
|
|
86
|
+
description: parsed.description,
|
|
87
|
+
tags: parsed.tags,
|
|
88
|
+
body: parsed.body,
|
|
89
|
+
scope,
|
|
90
|
+
...(pluginId ? { pluginId } : {}),
|
|
91
|
+
path: full,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
} catch {}
|
|
95
|
+
}
|
|
96
|
+
return items;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function listSkills(workspace, { pluginDirs = [], includeBody = false } = {}) {
|
|
100
|
+
const merged = new Map();
|
|
101
|
+
|
|
102
|
+
for (const p of pluginDirs || []) {
|
|
103
|
+
if (!p?.dir) continue;
|
|
104
|
+
for (const item of scanSkillsInDir(join(p.dir, 'skills'), 'plugin', p.id || '')) {
|
|
105
|
+
merged.set(item.slug, item);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
for (const item of scanSkillsInDir(globalSkillsDir(), 'global')) {
|
|
109
|
+
merged.set(item.slug, item);
|
|
110
|
+
}
|
|
111
|
+
for (const item of scanSkillsInDir(workspaceSkillsDir(workspace), 'workspace')) {
|
|
112
|
+
merged.set(item.slug, item);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return [...merged.values()].map(item => (
|
|
116
|
+
includeBody
|
|
117
|
+
? item
|
|
118
|
+
: {
|
|
119
|
+
slug: item.slug,
|
|
120
|
+
name: item.name,
|
|
121
|
+
description: item.description,
|
|
122
|
+
tags: item.tags,
|
|
123
|
+
scope: item.scope,
|
|
124
|
+
...(item.pluginId ? { pluginId: item.pluginId } : {}),
|
|
125
|
+
}
|
|
126
|
+
));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function readSkill(workspace, nameOrSlug, { pluginDirs = [] } = {}) {
|
|
130
|
+
const needle = String(nameOrSlug || '').trim().toLowerCase();
|
|
131
|
+
if (!needle) return null;
|
|
132
|
+
const all = listSkills(workspace, { pluginDirs, includeBody: true });
|
|
133
|
+
return all.find(s => s.slug.toLowerCase() === needle || s.name.toLowerCase() === needle) || null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function saveSkill(workspace, { slug, name, description, tags = [], body = '', scope = 'workspace' } = {}) {
|
|
137
|
+
const cleanSlug = String(slug || name || '')
|
|
138
|
+
.trim()
|
|
139
|
+
.toLowerCase()
|
|
140
|
+
.replace(/[^a-z0-9_-]+/g, '-')
|
|
141
|
+
.replace(/^-+|-+$/g, '')
|
|
142
|
+
.slice(0, 63);
|
|
143
|
+
if (!SLUG_RE.test(cleanSlug)) {
|
|
144
|
+
throw new Error('技能标识(slug)需使用英文字母、数字、连字符或下划线,如 api-contract。');
|
|
145
|
+
}
|
|
146
|
+
const cleanName = String(name || cleanSlug).trim().slice(0, 80);
|
|
147
|
+
const cleanDesc = String(description || '').trim().slice(0, 260) || '自定义 Agent 技能';
|
|
148
|
+
const cleanBody = String(body || '').trim();
|
|
149
|
+
if (!cleanBody) throw new Error('技能正文内容不能为空。');
|
|
150
|
+
|
|
151
|
+
const baseDir = scope === 'global' || !workspace ? globalSkillsDir() : workspaceSkillsDir(workspace);
|
|
152
|
+
const skillDir = join(baseDir, cleanSlug);
|
|
153
|
+
mkdirSync(skillDir, { recursive: true, mode: 0o700 });
|
|
154
|
+
const filePath = join(skillDir, 'SKILL.md');
|
|
155
|
+
writeFileSync(filePath, serializeSkillMarkdown({ name: cleanName, description: cleanDesc, tags, body: cleanBody }), 'utf8');
|
|
156
|
+
return {
|
|
157
|
+
slug: cleanSlug,
|
|
158
|
+
name: cleanName,
|
|
159
|
+
description: cleanDesc,
|
|
160
|
+
tags,
|
|
161
|
+
body: cleanBody,
|
|
162
|
+
scope: scope === 'global' || !workspace ? 'global' : 'workspace',
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function deleteSkill(workspace, { slug, scope = 'workspace' } = {}) {
|
|
167
|
+
const cleanSlug = String(slug || '').trim();
|
|
168
|
+
if (!SLUG_RE.test(cleanSlug)) return false;
|
|
169
|
+
const baseDir = scope === 'global' || !workspace ? globalSkillsDir() : workspaceSkillsDir(workspace);
|
|
170
|
+
const targetDir = join(baseDir, cleanSlug);
|
|
171
|
+
const targetFile = join(baseDir, cleanSlug + '.md');
|
|
172
|
+
if (existsSync(targetDir)) {
|
|
173
|
+
rmSync(targetDir, { recursive: true, force: true });
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
if (existsSync(targetFile)) {
|
|
177
|
+
rmSync(targetFile, { force: true });
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function formatSkillsCatalog(skills = []) {
|
|
184
|
+
if (!Array.isArray(skills) || !skills.length) return '';
|
|
185
|
+
const lines = [
|
|
186
|
+
'【已挂载技能库(按需调用 load_skill 工具读取完整指南)】',
|
|
187
|
+
...skills.slice(0, 40).map(s => `- ${s.slug} (${s.name}): ${s.description}`),
|
|
188
|
+
];
|
|
189
|
+
return lines.join('\n');
|
|
190
|
+
}
|
package/src/html/plugin-ui.css
CHANGED
|
@@ -84,9 +84,15 @@
|
|
|
84
84
|
.clado-plugin-slot[data-slot="top-left"] { top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); max-width: calc(100vw - 250px); flex-direction: column; align-items: start; }
|
|
85
85
|
.clado-plugin-slot[data-slot="top-right"] { top: max(14px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); flex-direction: column; align-items: end; }
|
|
86
86
|
.clado-plugin-slot[data-slot="bottom-left"] { bottom: max(16px, env(safe-area-inset-bottom)); left: max(16px, env(safe-area-inset-left)); align-items: end; }
|
|
87
|
-
.clado-plugin-slot[data-slot="bottom-right"] { bottom: max(
|
|
87
|
+
.clado-plugin-slot[data-slot="bottom-right"] { bottom: max(14px, env(safe-area-inset-bottom)); right: max(16px, env(safe-area-inset-right)); flex-direction: column-reverse; align-items: end; z-index: 26; max-width: calc(100vw - 20px); }
|
|
88
88
|
.clado-plugin-slot[data-slot="bottom-center"] { left: 10px; right: 10px; bottom: max(12px, env(safe-area-inset-bottom)); justify-content: center; align-items: end; z-index: 26; }
|
|
89
|
-
@media (max-width:
|
|
89
|
+
@media (max-width: 760px) {
|
|
90
|
+
.clado-plugin-slot[data-slot="bottom-right"] {
|
|
91
|
+
left: 10px;
|
|
92
|
+
right: 10px;
|
|
93
|
+
bottom: max(12px, env(safe-area-inset-bottom));
|
|
94
|
+
max-width: calc(100vw - 20px);
|
|
95
|
+
}
|
|
90
96
|
body[data-agent-dock="open"] .clado-plugin-slot[data-slot="bottom-left"] {
|
|
91
97
|
opacity: 0;
|
|
92
98
|
transform: translateY(8px) scale(.96);
|
|
@@ -489,3 +495,90 @@
|
|
|
489
495
|
:root[data-theme="dark"] .clado-risk-medium { color: #fbbf24; }
|
|
490
496
|
:root[data-theme="dark"] .clado-risk-high { color: #fda4af; }
|
|
491
497
|
|
|
498
|
+
/* ============ 36% 冰晶毛玻璃本机工作区选择器与新项目启动台 ============ */
|
|
499
|
+
.clado-launchpad-wrap {
|
|
500
|
+
min-height: 100%;
|
|
501
|
+
display: flex;
|
|
502
|
+
align-items: center;
|
|
503
|
+
justify-content: center;
|
|
504
|
+
padding: 64px 16px 110px;
|
|
505
|
+
background-image: radial-gradient(rgba(15, 23, 42, 0.08) 1px, transparent 1px);
|
|
506
|
+
background-size: 22px 22px;
|
|
507
|
+
}
|
|
508
|
+
:root[data-theme="dark"] .clado-launchpad-wrap {
|
|
509
|
+
background-image: radial-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px);
|
|
510
|
+
}
|
|
511
|
+
.clado-launchpad-card {
|
|
512
|
+
width: 100%;
|
|
513
|
+
max-width: 460px;
|
|
514
|
+
padding: 22px 20px;
|
|
515
|
+
border-radius: 24px;
|
|
516
|
+
text-align: left;
|
|
517
|
+
display: flex;
|
|
518
|
+
flex-direction: column;
|
|
519
|
+
gap: 14px;
|
|
520
|
+
background: rgba(255, 255, 255, 0.42);
|
|
521
|
+
backdrop-filter: blur(22px) saturate(185%) brightness(1.06);
|
|
522
|
+
-webkit-backdrop-filter: blur(22px) saturate(185%) brightness(1.06);
|
|
523
|
+
border: 1px solid rgba(255, 255, 255, 0.86);
|
|
524
|
+
box-shadow: 0 12px 32px rgba(15, 23, 42, 0.06), 0 0 0 0.5px rgba(15, 23, 42, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.96);
|
|
525
|
+
}
|
|
526
|
+
:root[data-theme="dark"] .clado-launchpad-card {
|
|
527
|
+
background: rgba(20, 25, 36, 0.44);
|
|
528
|
+
border-color: rgba(255, 255, 255, 0.18);
|
|
529
|
+
box-shadow: 0 16px 38px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.22);
|
|
530
|
+
}
|
|
531
|
+
.clado-launchpad-actions {
|
|
532
|
+
display: grid;
|
|
533
|
+
grid-template-columns: 1fr;
|
|
534
|
+
gap: 8px;
|
|
535
|
+
}
|
|
536
|
+
.clado-launchpad-btn {
|
|
537
|
+
appearance: none;
|
|
538
|
+
width: 100%;
|
|
539
|
+
padding: 11px 13px;
|
|
540
|
+
border-radius: 14px;
|
|
541
|
+
border: 1px solid var(--clado-ui-well-border);
|
|
542
|
+
background: var(--clado-ui-well);
|
|
543
|
+
color: var(--clado-ui-text);
|
|
544
|
+
font: inherit;
|
|
545
|
+
text-align: left;
|
|
546
|
+
cursor: pointer;
|
|
547
|
+
display: flex;
|
|
548
|
+
align-items: center;
|
|
549
|
+
justify-content: space-between;
|
|
550
|
+
gap: 10px;
|
|
551
|
+
transition: background-color 150ms ease, transform 140ms ease, border-color 150ms ease;
|
|
552
|
+
}
|
|
553
|
+
.clado-launchpad-btn:hover {
|
|
554
|
+
background: var(--clado-ui-hover);
|
|
555
|
+
border-color: var(--clado-ui-glass-outline);
|
|
556
|
+
}
|
|
557
|
+
.clado-launchpad-btn:active { transform: scale(0.99); }
|
|
558
|
+
.clado-launchpad-btn.primary {
|
|
559
|
+
background: rgba(37, 99, 235, 0.11);
|
|
560
|
+
border-color: rgba(37, 99, 235, 0.28);
|
|
561
|
+
}
|
|
562
|
+
.clado-folder-row {
|
|
563
|
+
appearance: none;
|
|
564
|
+
width: 100%;
|
|
565
|
+
padding: 8px 10px;
|
|
566
|
+
border-radius: 10px;
|
|
567
|
+
border: 1px solid transparent;
|
|
568
|
+
background: transparent;
|
|
569
|
+
color: var(--clado-ui-text);
|
|
570
|
+
font: inherit;
|
|
571
|
+
font-size: 12.5px;
|
|
572
|
+
text-align: left;
|
|
573
|
+
cursor: pointer;
|
|
574
|
+
display: flex;
|
|
575
|
+
align-items: center;
|
|
576
|
+
justify-content: space-between;
|
|
577
|
+
gap: 8px;
|
|
578
|
+
}
|
|
579
|
+
.clado-folder-row:hover {
|
|
580
|
+
background: var(--clado-ui-hover);
|
|
581
|
+
border-color: var(--clado-ui-well-border);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
|