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
|
@@ -93,6 +93,7 @@
|
|
|
93
93
|
return result;
|
|
94
94
|
},
|
|
95
95
|
} : null,
|
|
96
|
+
openWorkspacePicker: config.canSwitchWorkspace && !offline ? () => openWorkspacePicker() : null,
|
|
96
97
|
setTheme: theme => {
|
|
97
98
|
if (modalLocked()) return;
|
|
98
99
|
try { localStorage.setItem('clado-theme', theme); } catch {}
|
|
@@ -121,6 +122,10 @@
|
|
|
121
122
|
openFromCapability,
|
|
122
123
|
workspaceUrl,
|
|
123
124
|
switchWorkspace: id => { location.href = workspaceUrl(id); },
|
|
125
|
+
openWorkspacePicker: config.canSwitchWorkspace && !offline ? () => openWorkspacePicker() : null,
|
|
126
|
+
createCanvas: config.canSwitchWorkspace && !offline ? () => createCanvasFlow() : null,
|
|
127
|
+
renameCanvas: config.canSwitchWorkspace && !offline ? doc => renameCanvasFlow(doc) : null,
|
|
128
|
+
deleteCanvas: config.canSwitchWorkspace && !offline ? doc => deleteCanvasFlow(doc) : null,
|
|
124
129
|
refresh: () => scan(true),
|
|
125
130
|
back: () => {
|
|
126
131
|
if (modalLocked()) return;
|
|
@@ -143,6 +148,280 @@
|
|
|
143
148
|
}
|
|
144
149
|
const selectionTab = config.selection ? crypto.randomUUID() : null;
|
|
145
150
|
let aiSelection = null, selectionRequest = Promise.resolve(), pageHidden = false;
|
|
151
|
+
|
|
152
|
+
// ============ 本机工作区中心(选择/浏览/新建工作区 + 新项目首屏启动台) ============
|
|
153
|
+
let wsPickerOverlay = null;
|
|
154
|
+
async function createCanvasFlow(defaultTitle = '') {
|
|
155
|
+
if (!config.canSwitchWorkspace || offline) return;
|
|
156
|
+
const title = defaultTitle || window.prompt('输入新画布标题:', '系统架构概览');
|
|
157
|
+
if (!title || !title.trim()) return;
|
|
158
|
+
try {
|
|
159
|
+
const res = await fetch(withWorkspace('/library/fs-workspaces'), {
|
|
160
|
+
method: 'POST',
|
|
161
|
+
headers: { 'content-type': 'application/json' },
|
|
162
|
+
body: JSON.stringify({ action: 'create_canvas', title: title.trim() }),
|
|
163
|
+
});
|
|
164
|
+
const data = await res.json();
|
|
165
|
+
if (!res.ok) throw new Error(data.error || '创建画布失败');
|
|
166
|
+
pendingOpen = data.file;
|
|
167
|
+
await scan(true);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
directory.showMessage('新建画布失败', err.message || '请稍后重试');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function renameCanvasFlow(doc) {
|
|
174
|
+
if (!config.canSwitchWorkspace || offline || !doc?.file) return;
|
|
175
|
+
const nextName = window.prompt('重命名画布文件(保留 .md):', doc.file);
|
|
176
|
+
if (!nextName || !nextName.trim() || nextName.trim() === doc.file) return;
|
|
177
|
+
try {
|
|
178
|
+
const res = await fetch(withWorkspace('/library/fs-workspaces'), {
|
|
179
|
+
method: 'POST',
|
|
180
|
+
headers: { 'content-type': 'application/json' },
|
|
181
|
+
body: JSON.stringify({ action: 'rename_canvas', oldFile: doc.file, newFile: nextName.trim() }),
|
|
182
|
+
});
|
|
183
|
+
const data = await res.json();
|
|
184
|
+
if (!res.ok) throw new Error(data.error || '重命名画布失败');
|
|
185
|
+
if (selected === doc.file) {
|
|
186
|
+
selected = '';
|
|
187
|
+
pendingOpen = data.file;
|
|
188
|
+
}
|
|
189
|
+
await scan(true);
|
|
190
|
+
} catch (err) {
|
|
191
|
+
directory.showMessage('重命名画布失败', err.message || '请稍后重试');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function deleteCanvasFlow(doc) {
|
|
196
|
+
if (!config.canSwitchWorkspace || offline || !doc?.file) return;
|
|
197
|
+
if (!window.confirm(`确定要永久删除画布「${doc.title || doc.file}」(${doc.file}) 吗?`)) return;
|
|
198
|
+
try {
|
|
199
|
+
const res = await fetch(withWorkspace('/library/fs-workspaces'), {
|
|
200
|
+
method: 'POST',
|
|
201
|
+
headers: { 'content-type': 'application/json' },
|
|
202
|
+
body: JSON.stringify({ action: 'delete_canvas', file: doc.file }),
|
|
203
|
+
});
|
|
204
|
+
const data = await res.json();
|
|
205
|
+
if (!res.ok) throw new Error(data.error || '删除画布失败');
|
|
206
|
+
if (selected === doc.file) {
|
|
207
|
+
selected = '';
|
|
208
|
+
version = '';
|
|
209
|
+
saveView();
|
|
210
|
+
}
|
|
211
|
+
await scan(true);
|
|
212
|
+
} catch (err) {
|
|
213
|
+
directory.showMessage('删除画布失败', err.message || '请稍后重试');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function applyWorkspaceSwitch(targetPath, { createIfMissing = false, initStarterCanvas = false } = {}) {
|
|
218
|
+
if (!targetPath || !targetPath.trim()) return;
|
|
219
|
+
const res = await fetch('/library/fs-workspaces', {
|
|
220
|
+
method: 'POST',
|
|
221
|
+
headers: { 'content-type': 'application/json' },
|
|
222
|
+
body: JSON.stringify({
|
|
223
|
+
action: 'select',
|
|
224
|
+
path: targetPath.trim(),
|
|
225
|
+
createIfMissing,
|
|
226
|
+
initStarterCanvas,
|
|
227
|
+
}),
|
|
228
|
+
});
|
|
229
|
+
const data = await res.json();
|
|
230
|
+
if (!res.ok) throw new Error(data.error || '切换工作区失败');
|
|
231
|
+
try { sessionStorage.removeItem(storageKey); } catch {}
|
|
232
|
+
location.href = '/';
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function ensureWorkspacePicker() {
|
|
236
|
+
if (wsPickerOverlay || !document.body) return wsPickerOverlay;
|
|
237
|
+
wsPickerOverlay = document.createElement('div');
|
|
238
|
+
wsPickerOverlay.id = 'clado-workspace-picker';
|
|
239
|
+
wsPickerOverlay.className = 'clado-market-overlay';
|
|
240
|
+
wsPickerOverlay.innerHTML = `
|
|
241
|
+
<div class="clado-market-sheet" style="max-width:500px;">
|
|
242
|
+
<div class="clado-market-well" style="padding:12px 14px;display:flex;align-items:center;justify-content:space-between;gap:8px;">
|
|
243
|
+
<div>
|
|
244
|
+
<strong style="font-size:15px;">选择或新建工作区</strong>
|
|
245
|
+
<div data-ws-cur style="font-size:11px;color:var(--clado-ui-muted);margin-top:2px;"></div>
|
|
246
|
+
</div>
|
|
247
|
+
<button type="button" class="clado-market-tab active" data-ws-close style="padding:5px 11px;">关闭</button>
|
|
248
|
+
</div>
|
|
249
|
+
|
|
250
|
+
<div class="clado-market-well" data-ws-recents-wrap style="padding:11px 12px;display:none;flex-direction:column;gap:5px;">
|
|
251
|
+
<div style="font-size:11px;font-weight:650;color:var(--clado-ui-muted);">最近打开的项目</div>
|
|
252
|
+
<div data-ws-recents style="display:flex;flex-direction:column;gap:3px;"></div>
|
|
253
|
+
</div>
|
|
254
|
+
|
|
255
|
+
<div class="clado-market-well" style="padding:11px 12px;display:flex;flex-direction:column;gap:8px;">
|
|
256
|
+
<div style="display:flex;align-items:center;justify-content:space-between;gap:6px;">
|
|
257
|
+
<span style="font-size:11.5px;font-weight:650;color:var(--clado-ui-muted);">浏览本机目录</span>
|
|
258
|
+
<div style="display:flex;gap:4px;">
|
|
259
|
+
<button type="button" class="clado-market-tab active" data-ws-up style="font-size:11px;padding:3px 8px;">↑ 上级</button>
|
|
260
|
+
<button type="button" class="clado-market-tab active" data-ws-home style="font-size:11px;padding:3px 8px;">⌂ 主目录</button>
|
|
261
|
+
</div>
|
|
262
|
+
</div>
|
|
263
|
+
<div data-ws-browse-list style="max-height:190px;overflow-y:auto;display:flex;flex-direction:column;gap:2px;"></div>
|
|
264
|
+
</div>
|
|
265
|
+
|
|
266
|
+
<div class="clado-market-well" style="padding:12px;display:flex;flex-direction:column;gap:8px;">
|
|
267
|
+
<div style="font-size:11.5px;color:var(--clado-ui-muted);">目标工作区路径(回车浏览目录,或直接输入新目录路径自动创建)</div>
|
|
268
|
+
<div style="display:flex;gap:6px;">
|
|
269
|
+
<input type="text" data-ws-input style="flex:1;height:35px;padding:0 11px;border-radius:10px;border:1px solid var(--clado-ui-well-border);background:var(--clado-ui-well);color:var(--clado-ui-text);font:inherit;font-size:12.5px;outline:none;" placeholder="/path/to/your-project" />
|
|
270
|
+
<button type="button" class="clado-market-tab active" data-ws-go style="height:35px;padding:0 11px;font-size:12px;">浏览</button>
|
|
271
|
+
</div>
|
|
272
|
+
<div data-ws-err style="font-size:11.5px;color:#e11d48;display:none;"></div>
|
|
273
|
+
<div style="display:flex;gap:8px;flex-wrap:wrap;">
|
|
274
|
+
<button type="button" class="clado-market-tab active" data-ws-open style="flex:1;height:35px;font-size:12.5px;">打开此目录</button>
|
|
275
|
+
<button type="button" data-ws-init style="flex:1.2;height:35px;border:0;border-radius:10px;background:var(--clado-ui-brand);color:#fff;font:inherit;font-size:12.5px;font-weight:600;cursor:pointer;">在此新建工作区并建首张画布</button>
|
|
276
|
+
</div>
|
|
277
|
+
</div>
|
|
278
|
+
</div>`;
|
|
279
|
+
document.body.append(wsPickerOverlay);
|
|
280
|
+
|
|
281
|
+
let parentDir = '';
|
|
282
|
+
let homeDir = '';
|
|
283
|
+
const curEl = wsPickerOverlay.querySelector('[data-ws-cur]');
|
|
284
|
+
const recentsWrap = wsPickerOverlay.querySelector('[data-ws-recents-wrap]');
|
|
285
|
+
const recentsList = wsPickerOverlay.querySelector('[data-ws-recents]');
|
|
286
|
+
const browseList = wsPickerOverlay.querySelector('[data-ws-browse-list]');
|
|
287
|
+
const pathInput = wsPickerOverlay.querySelector('[data-ws-input]');
|
|
288
|
+
const errEl = wsPickerOverlay.querySelector('[data-ws-err]');
|
|
289
|
+
|
|
290
|
+
const showErr = msg => {
|
|
291
|
+
errEl.textContent = msg || '';
|
|
292
|
+
errEl.style.display = msg ? 'block' : 'none';
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const loadDir = async (dir = '') => {
|
|
296
|
+
showErr('');
|
|
297
|
+
try {
|
|
298
|
+
const qs = dir ? '?dir=' + encodeURIComponent(dir) : '';
|
|
299
|
+
const res = await fetch('/library/fs-workspaces' + qs, { cache: 'no-store' });
|
|
300
|
+
const data = await res.json();
|
|
301
|
+
if (!res.ok) throw new Error(data.error || '读取目录失败');
|
|
302
|
+
parentDir = data.parentDir || '';
|
|
303
|
+
homeDir = data.homeDir || '';
|
|
304
|
+
curEl.textContent = data.hubMode ? '请选择一个项目目录开始协作' : `当前:${data.currentWorkspace}`;
|
|
305
|
+
pathInput.value = data.currentDir || data.currentWorkspace || '';
|
|
306
|
+
|
|
307
|
+
const recents = Array.isArray(data.recentWorkspaces) ? data.recentWorkspaces : [];
|
|
308
|
+
if (recents.length) {
|
|
309
|
+
recentsWrap.style.display = 'flex';
|
|
310
|
+
recentsList.replaceChildren();
|
|
311
|
+
for (const r of recents.slice(0, 5)) {
|
|
312
|
+
const row = document.createElement('button');
|
|
313
|
+
row.type = 'button';
|
|
314
|
+
row.className = 'clado-folder-row';
|
|
315
|
+
row.innerHTML = `<span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"><strong>${r.name}</strong> <small style="color:var(--clado-ui-muted);">${r.path}</small></span><span style="font-size:11px;color:var(--clado-ui-brand);flex:none;">${r.documents ?? 0} 画布</span>`;
|
|
316
|
+
row.onclick = () => applyWorkspaceSwitch(r.path, { createIfMissing: false }).catch(e => showErr(e.message));
|
|
317
|
+
recentsList.append(row);
|
|
318
|
+
}
|
|
319
|
+
} else {
|
|
320
|
+
recentsWrap.style.display = 'none';
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
browseList.replaceChildren();
|
|
324
|
+
const entries = Array.isArray(data.entries) ? data.entries : [];
|
|
325
|
+
if (!entries.length) {
|
|
326
|
+
const empty = document.createElement('div');
|
|
327
|
+
empty.style.cssText = 'padding:12px;text-align:center;color:var(--clado-ui-muted);font-size:12px;';
|
|
328
|
+
empty.textContent = '当前文件夹下暂无子目录,可直接打开此目录或下方输入新子目录名新建。';
|
|
329
|
+
browseList.append(empty);
|
|
330
|
+
} else {
|
|
331
|
+
for (const item of entries) {
|
|
332
|
+
const row = document.createElement('button');
|
|
333
|
+
row.type = 'button';
|
|
334
|
+
row.className = 'clado-folder-row';
|
|
335
|
+
row.dataset.folderPath = item.path;
|
|
336
|
+
const badges = [
|
|
337
|
+
item.hasClado ? '<span style="color:#059669;font-weight:600;">Clado</span>' : '',
|
|
338
|
+
item.isGit ? '<span style="color:var(--clado-ui-muted);">Git</span>' : '',
|
|
339
|
+
item.mdCount ? `<span>${item.mdCount} md</span>` : '',
|
|
340
|
+
].filter(Boolean).join(' · ');
|
|
341
|
+
row.innerHTML = `<span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">📁 ${item.name}</span><small style="color:var(--clado-ui-subtle);flex:none;">${badges || '进入 ›'}</small>`;
|
|
342
|
+
row.onclick = () => loadDir(item.path);
|
|
343
|
+
browseList.append(row);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} catch (err) {
|
|
347
|
+
showErr(err.message || '读取目录失败');
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
wsPickerOverlay.addEventListener('click', ev => {
|
|
352
|
+
if (ev.target === wsPickerOverlay || ev.target.closest('[data-ws-close]')) {
|
|
353
|
+
wsPickerOverlay.classList.remove('show');
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
pathInput.addEventListener('keydown', ev => {
|
|
357
|
+
if (ev.key === 'Enter') {
|
|
358
|
+
ev.preventDefault();
|
|
359
|
+
if (pathInput.value.trim()) loadDir(pathInput.value.trim());
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
wsPickerOverlay.querySelector('[data-ws-go]').onclick = () => {
|
|
363
|
+
if (pathInput.value.trim()) loadDir(pathInput.value.trim());
|
|
364
|
+
};
|
|
365
|
+
wsPickerOverlay.querySelector('[data-ws-up]').onclick = () => { if (parentDir) loadDir(parentDir); };
|
|
366
|
+
wsPickerOverlay.querySelector('[data-ws-home]').onclick = () => { if (homeDir) loadDir(homeDir); };
|
|
367
|
+
wsPickerOverlay.querySelector('[data-ws-open]').onclick = () => {
|
|
368
|
+
applyWorkspaceSwitch(pathInput.value, { createIfMissing: true, initStarterCanvas: false }).catch(e => showErr(e.message));
|
|
369
|
+
};
|
|
370
|
+
wsPickerOverlay.querySelector('[data-ws-init]').onclick = () => {
|
|
371
|
+
applyWorkspaceSwitch(pathInput.value, { createIfMissing: true, initStarterCanvas: true }).catch(e => showErr(e.message));
|
|
372
|
+
};
|
|
373
|
+
wsPickerOverlay._loadDir = loadDir;
|
|
374
|
+
return wsPickerOverlay;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function openWorkspacePicker(initialDir = '') {
|
|
378
|
+
if (!config.canSwitchWorkspace || offline || !document.body) return;
|
|
379
|
+
const modal = ensureWorkspacePicker();
|
|
380
|
+
if (!modal) return;
|
|
381
|
+
modal.classList.add('show');
|
|
382
|
+
modal._loadDir(initialDir);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (config.canSwitchWorkspace && !offline && document.body) {
|
|
386
|
+
window.addEventListener('clado:open-workspace-picker', () => openWorkspacePicker());
|
|
387
|
+
const emptyEl = $('#emptyState');
|
|
388
|
+
if (emptyEl) {
|
|
389
|
+
const wsTitle = config.hubMode ? '欢迎使用 Clado · 请先选择工作区' : `当前工作区:${config.workspaceName || '未命名项目'}`;
|
|
390
|
+
const wsSub = config.hubMode
|
|
391
|
+
? '选择一个已有代码仓库或新建空白工作区,配置好模型供应商即可开始与多角色分身协作设计。'
|
|
392
|
+
: `路径:${config.workspacePath || '.'} · 当前目录尚无画布文档,你可以一键新建首张画布或直接在右下角向 Agent 提问。`;
|
|
393
|
+
emptyEl.style.padding = '0';
|
|
394
|
+
emptyEl.innerHTML = `
|
|
395
|
+
<div class="clado-launchpad-wrap">
|
|
396
|
+
<div class="clado-launchpad-card">
|
|
397
|
+
<div>
|
|
398
|
+
<div style="font-size:16px;font-weight:700;color:var(--clado-ui-text);">${wsTitle}</div>
|
|
399
|
+
<div style="font-size:12px;line-height:1.55;color:var(--clado-ui-muted);margin-top:5px;">${wsSub}</div>
|
|
400
|
+
</div>
|
|
401
|
+
<div class="clado-launchpad-actions">
|
|
402
|
+
<button type="button" class="clado-launchpad-btn primary" data-lp-pick>
|
|
403
|
+
<span><strong>📂 选择或切换本机工作区</strong><br/><small style="color:var(--clado-ui-muted);">浏览电脑目录、打开已有仓库或新建项目</small></span>
|
|
404
|
+
<span style="color:var(--clado-ui-brand);font-weight:700;">›</span>
|
|
405
|
+
</button>
|
|
406
|
+
<button type="button" class="clado-launchpad-btn" data-lp-new-canvas>
|
|
407
|
+
<span><strong>✨ 在当前工作区新建首张画布</strong><br/><small style="color:var(--clado-ui-muted);">立即创建初始架构画布进入三视图协作</small></span>
|
|
408
|
+
<span style="opacity:.5;">+</span>
|
|
409
|
+
</button>
|
|
410
|
+
<button type="button" class="clado-launchpad-btn" data-lp-llm>
|
|
411
|
+
<span><strong>⚙ 配置供应商与主力模型</strong><br/><small style="color:var(--clado-ui-muted);">支持 OpenAI / Anthropic / DeepSeek / OpenRouter / Ollama</small></span>
|
|
412
|
+
<span style="opacity:.5;">›</span>
|
|
413
|
+
</button>
|
|
414
|
+
</div>
|
|
415
|
+
</div>
|
|
416
|
+
</div>`;
|
|
417
|
+
emptyEl.querySelector('[data-lp-pick]').onclick = () => openWorkspacePicker();
|
|
418
|
+
emptyEl.querySelector('[data-lp-new-canvas]').onclick = () => createCanvasFlow('系统架构概览');
|
|
419
|
+
emptyEl.querySelector('[data-lp-llm]').onclick = () => window.dispatchEvent(new CustomEvent('clado:open-llm-settings'));
|
|
420
|
+
}
|
|
421
|
+
if (config.hubMode) {
|
|
422
|
+
setTimeout(() => openWorkspacePicker(), 60);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
146
425
|
const liveObjectsEnabled = Boolean(config.selection && !offline && document.body);
|
|
147
426
|
let canvasObjectsList = [];
|
|
148
427
|
const objectSelection = new Map();
|
|
@@ -543,7 +822,7 @@
|
|
|
543
822
|
if (!container) {
|
|
544
823
|
container = document.createElement('div');
|
|
545
824
|
container.className = 'empty-workspaces';
|
|
546
|
-
$('#emptyState').append(container);
|
|
825
|
+
($('#emptyState .clado-launchpad-card') || $('#emptyState')).append(container);
|
|
547
826
|
}
|
|
548
827
|
container.replaceChildren();
|
|
549
828
|
const title = document.createElement('div');
|
|
@@ -682,7 +961,7 @@
|
|
|
682
961
|
else if (!doc) { $('#updateError').textContent = '当前 Markdown 已删除或暂时无法解析,保留上次画面。有效文档仍可从目录打开。'; $('#updateError').hidden = false; status('当前画布未更新', true); $('#canvasLoading').hidden = true; post('ready'); }
|
|
683
962
|
else { $('#updateError').hidden = true; if (force || doc.version !== version) { open(selected, version ? '' : pendingAnchor, { update: true }); } else { flushPendingTouch(); status('已同步 ' + new Date(doc.modified).toLocaleTimeString('zh-CN', { hour12: false })); } }
|
|
684
963
|
}
|
|
685
|
-
} catch { status('连接中断,正在重连', true); $('#updateError').textContent = '目录连接中断,保留当前画面。服务恢复后自动重连。'; $('#updateError').hidden = false; $('#canvasLoading').hidden = true; post('ready'); }
|
|
964
|
+
} catch { if (pageHidden) return; status('连接中断,正在重连', true); $('#updateError').textContent = '目录连接中断,保留当前画面。服务恢复后自动重连。'; $('#updateError').hidden = false; $('#canvasLoading').hidden = true; post('ready'); }
|
|
686
965
|
finally {
|
|
687
966
|
busy = false;
|
|
688
967
|
if (pendingRescan) { pendingRescan = false; scan(true); }
|
|
@@ -17,10 +17,28 @@ const specs = {
|
|
|
17
17
|
'clado.agent': {
|
|
18
18
|
name: { type: 'string', minLength: 1, maxLength: 80 },
|
|
19
19
|
mode: { enum: ['auto', 'builtin', 'acp'] },
|
|
20
|
-
|
|
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 },
|
|
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
|
+
},
|
|
24
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: '^.+' },
|
|
@@ -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': {
|
|
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;
|
package/src/server/plugins.js
CHANGED
|
@@ -23,6 +23,22 @@ const permission = z.enum([
|
|
|
23
23
|
...PLUGIN_SLOTS.map(slot => 'ui.mount:' + slot),
|
|
24
24
|
...PLUGIN_FIELDS.map(field => 'canvas.' + field + '.read'),
|
|
25
25
|
]);
|
|
26
|
+
const pluginMcpEntry = z.strictObject({
|
|
27
|
+
name: z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,47}$/),
|
|
28
|
+
type: z.enum(['stdio', 'http', 'streamable-http']).optional(),
|
|
29
|
+
command: z.string().trim().min(1).max(200).optional(),
|
|
30
|
+
args: z.array(z.string().max(200)).max(32).optional(),
|
|
31
|
+
env: z.record(z.string(), z.string()).optional(),
|
|
32
|
+
url: z.string().trim().min(1).max(400).optional(),
|
|
33
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
34
|
+
enabled: z.boolean().optional(),
|
|
35
|
+
});
|
|
36
|
+
const pluginPersonaEntry = z.strictObject({
|
|
37
|
+
id: z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,31}$/),
|
|
38
|
+
name: z.string().trim().min(1).max(40),
|
|
39
|
+
prompt: z.string().max(4000).default(''),
|
|
40
|
+
initContext: z.string().max(2000).default(''),
|
|
41
|
+
});
|
|
26
42
|
const manifest = z.strictObject({
|
|
27
43
|
manifestVersion: z.literal(1),
|
|
28
44
|
id: pluginId,
|
|
@@ -33,15 +49,19 @@ const manifest = z.strictObject({
|
|
|
33
49
|
}, '需要有效 SemVer'),
|
|
34
50
|
engines: z.strictObject({ clado: z.string().min(1).max(200) }),
|
|
35
51
|
protocols: z.array(z.string().regex(/^\d+\.\d+$/)).min(1).max(16),
|
|
36
|
-
entrypoints: z.strictObject({ ui: z.strictObject({ path: z.string().max(240).regex(uiPath) }) }),
|
|
52
|
+
entrypoints: z.strictObject({ ui: z.strictObject({ path: z.string().max(240).regex(uiPath) }).optional() }).optional(),
|
|
37
53
|
permissions: z.array(z.union([permission, capabilityPermission])).max(64).default([]),
|
|
38
54
|
configuration: pluginConfiguration.optional(),
|
|
39
55
|
contributes: z.strictObject({
|
|
40
56
|
mounts: z.array(z.strictObject({
|
|
41
57
|
id: mountId, slot: z.enum(PLUGIN_SLOTS),
|
|
42
|
-
})).
|
|
58
|
+
})).max(8).default([]),
|
|
43
59
|
capabilities: z.array(capabilityDefinition).max(16).default([]),
|
|
44
60
|
executors: z.array(executorSchema).max(8).default([]),
|
|
61
|
+
mcp: z.array(pluginMcpEntry).max(16).default([]),
|
|
62
|
+
personas: z.array(pluginPersonaEntry).max(12).default([]),
|
|
63
|
+
skills: z.boolean().optional(),
|
|
64
|
+
commands: z.boolean().optional(),
|
|
45
65
|
events: z.tuple([]).optional(),
|
|
46
66
|
}),
|
|
47
67
|
});
|
|
@@ -110,12 +130,27 @@ function readManifest(root) {
|
|
|
110
130
|
throw new Error(`插件需要 Clado ${data.engines.clado},当前版本为 ${VERSION}。`);
|
|
111
131
|
}
|
|
112
132
|
if (!data.protocols.includes(PLUGIN_PROTOCOL)) throw new Error(`插件需要声明协议 ${PLUGIN_PROTOCOL}。`);
|
|
113
|
-
const mounts = data.contributes.mounts;
|
|
133
|
+
const mounts = data.contributes.mounts || [];
|
|
114
134
|
if (new Set(mounts.map(mount => mount.id)).size !== mounts.length) throw new Error('挂载 ID 重复。');
|
|
115
135
|
for (const { slot } of mounts) {
|
|
116
136
|
if (!data.permissions.includes('ui.mount:' + slot)) throw new Error(`缺少挂载权限 ui.mount:${slot}。`);
|
|
117
137
|
}
|
|
118
|
-
|
|
138
|
+
const hasUi = Boolean(data.entrypoints?.ui?.path);
|
|
139
|
+
const hasAgentBundle = Boolean(
|
|
140
|
+
data.contributes.executors?.length
|
|
141
|
+
|| data.contributes.mcp?.length
|
|
142
|
+
|| data.contributes.personas?.length
|
|
143
|
+
|| data.contributes.skills
|
|
144
|
+
|| data.contributes.commands
|
|
145
|
+
|| existsSync(join(root, 'skills'))
|
|
146
|
+
|| existsSync(join(root, 'commands'))
|
|
147
|
+
);
|
|
148
|
+
if (hasUi) {
|
|
149
|
+
if (!mounts.length) throw new Error('声明了 UI 入口的插件至少需要一个挂载点(contributes.mounts)。');
|
|
150
|
+
readPackageFile(root, data.entrypoints.ui.path.split('/'), 2 * 1024 * 1024);
|
|
151
|
+
} else if (!hasAgentBundle) {
|
|
152
|
+
throw new Error('插件需要提供 UI 入口或至少声明一项能力(skills / commands / mcp / personas / executors)。');
|
|
153
|
+
}
|
|
119
154
|
return { data, capabilities: compileCapabilities(data.id, mounts, data.contributes.capabilities),
|
|
120
155
|
configuration: compileConfiguration(data.configuration) };
|
|
121
156
|
}
|
|
@@ -127,8 +162,13 @@ export function installWorkspacePlugin(ctx, files, runtime) {
|
|
|
127
162
|
for (const file of files) {
|
|
128
163
|
if (typeof file?.path !== 'string' || typeof file.data !== 'string' || file.path.length > 240) fail('插件文件参数无效。');
|
|
129
164
|
const parts = file.path.split('/');
|
|
130
|
-
|
|
131
|
-
|
|
165
|
+
const ext = extname(file.path).toLowerCase();
|
|
166
|
+
const isManifest = file.path === 'clado-plugin.json';
|
|
167
|
+
const isUiAsset = parts[0] === 'ui' && contentTypes.has(ext);
|
|
168
|
+
const isBundleDoc = (parts[0] === 'skills' || parts[0] === 'commands') && (ext === '.md' || ext === '.json' || ext === '.txt');
|
|
169
|
+
if (!parts.every(part => segment.test(part)) || (!isManifest && !isUiAsset && !isBundleDoc)) {
|
|
170
|
+
fail('插件包仅接受清单、ui 静态资源以及 skills / commands 文本文件。');
|
|
171
|
+
}
|
|
132
172
|
if (parsed.has(file.path)) fail('插件包中有重复的文件路径。');
|
|
133
173
|
const data = Buffer.from(file.data, 'base64');
|
|
134
174
|
if (data.toString('base64') !== file.data) fail('插件文件编码无效。');
|
|
@@ -178,16 +218,28 @@ export function loadWorkspacePlugins(state) {
|
|
|
178
218
|
if (error.code !== 'ENOENT') warnings.push({ directory: '.clado/plugins', message: error.message });
|
|
179
219
|
}
|
|
180
220
|
const candidates = new Map();
|
|
221
|
+
const pluginDirs = [];
|
|
222
|
+
const pluginMcp = [];
|
|
223
|
+
const pluginPersonas = [];
|
|
181
224
|
function register(root, { data, capabilities: declared, configuration }) {
|
|
182
225
|
configurations.set(data.id, configuration);
|
|
183
226
|
capabilities.push(...declared);
|
|
227
|
+
pluginDirs.push({ id: data.id, dir: root });
|
|
228
|
+
for (const m of data.contributes.mcp || []) {
|
|
229
|
+
pluginMcp.push({ ...m, pluginId: data.id });
|
|
230
|
+
}
|
|
231
|
+
for (const p of data.contributes.personas || []) {
|
|
232
|
+
pluginPersonas.push({ ...p, pluginId: data.id });
|
|
233
|
+
}
|
|
184
234
|
const key = randomUUID();
|
|
185
235
|
packages.set(key, root);
|
|
186
236
|
plugins.push({
|
|
187
237
|
id: data.id, name: data.name, version: data.version,
|
|
188
|
-
entry: ASSETS + key + '/' + data.entrypoints.ui.path,
|
|
189
|
-
permissions: data.permissions, mounts: data.contributes.mounts, capabilities: declared.map(item => item.descriptor),
|
|
238
|
+
...(data.entrypoints?.ui?.path ? { entry: ASSETS + key + '/' + data.entrypoints.ui.path } : {}),
|
|
239
|
+
permissions: data.permissions, mounts: data.contributes.mounts || [], capabilities: declared.map(item => item.descriptor),
|
|
190
240
|
...(data.contributes.executors?.length ? { executors: data.contributes.executors } : {}),
|
|
241
|
+
...(data.contributes.mcp?.length ? { mcp: data.contributes.mcp.map(m => m.name) } : {}),
|
|
242
|
+
...(data.contributes.personas?.length ? { personas: data.contributes.personas.map(p => p.id) } : {}),
|
|
191
243
|
});
|
|
192
244
|
}
|
|
193
245
|
for (const entry of entries) {
|
|
@@ -232,7 +284,7 @@ export function loadWorkspacePlugins(state) {
|
|
|
232
284
|
});
|
|
233
285
|
res.end(req.method === 'HEAD' ? undefined : body);
|
|
234
286
|
}
|
|
235
|
-
return { descriptor, warnings, serveAsset, hasAsset: key => packages.has(key), capabilities, configurations, register };
|
|
287
|
+
return { descriptor, warnings, serveAsset, hasAsset: key => packages.has(key), capabilities, configurations, register, pluginDirs, pluginMcp, pluginPersonas };
|
|
236
288
|
}
|
|
237
289
|
|
|
238
290
|
export function inspectWorkspacePlugins(state) {
|