cladogram 0.5.3 → 0.5.5-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -6
- package/bin/clado.js +17 -6
- package/docs/plugin-development.md +135 -0
- package/docs/plugin-ui.md +43 -0
- package/docs/release.md +14 -0
- package/package.json +7 -1
- package/plugins/agent/index.js +181 -0
- package/plugins/agent/style.css +105 -0
- package/plugins/brand/index.js +262 -0
- package/plugins/brand/style.css +162 -0
- package/plugins/directory/capabilities.json +27 -0
- package/plugins/directory/index.js +201 -0
- package/plugins/directory/style.css +59 -0
- package/plugins/view-controls/index.js +58 -0
- package/plugins/view-controls/style.css +66 -0
- package/skills/clado/SKILL.md +19 -15
- package/src/html/app-css.js +69 -47
- package/src/html/canvas-chain.js +7 -7
- package/src/html/canvas-focus.js +2 -4
- package/src/html/canvas-screenshot.js +199 -0
- package/src/html/canvas-ui.css +5 -9
- package/src/html/canvas-ui.js +35 -27
- package/src/html/page.js +11 -37
- package/src/html/plugin-assets.js +33 -0
- package/src/html/plugin-ui.css +188 -0
- package/src/html/plugin-ui.js +51 -0
- package/src/html/runtime-api.js +41 -0
- package/src/html/runtime.js +164 -87
- package/src/server/agent.js +223 -0
- package/src/server/assets/clado-plugin-sdk.js +111 -0
- package/src/server/assets/library-canvas.js +14 -10
- package/src/server/assets/library-plugin-bridge.js +84 -0
- package/src/server/assets/library-plugins.css +39 -0
- package/src/server/assets/library-plugins.js +200 -0
- package/src/server/assets/library.css +8 -6
- package/src/server/assets/library.html +3 -13
- package/src/server/assets/library.js +280 -47
- package/src/server/canvas-capture.js +47 -0
- package/src/server/export.js +6 -3
- package/src/server/mcp.js +40 -17
- package/src/server/plugin-capabilities.js +188 -0
- package/src/server/plugin-settings.js +117 -0
- package/src/server/plugins.js +236 -0
- package/src/server/workspace.js +222 -29
- package/src/skill/install.js +1 -1
- package/src/skill/targets.js +3 -3
- package/src/util/update.js +3 -2
- package/src/vendor/html-to-image.min.js +24 -0
- package/src/workspace/service.js +21 -13
- package/src/workspace/storage.js +88 -20
- package/templates/business-flow.mdc +1 -1
- package/templates/call-chain.mdc +1 -1
- package/templates/data-design.mdc +1 -1
- package/src/server/assets/tree.js +0 -26
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join, extname } from 'node:path';
|
|
4
|
+
import semver from 'semver';
|
|
5
|
+
import { z } from 'zod/v4';
|
|
6
|
+
import { VERSION } from '../util/version.js';
|
|
7
|
+
import { DocumentError } from '../workspace/documents.js';
|
|
8
|
+
import { capabilityDefinition, capabilityPermission, compileCapabilities, mountId, pluginId } from './plugin-capabilities.js';
|
|
9
|
+
import { captureDefinition } from './canvas-capture.js';
|
|
10
|
+
import { compileConfiguration, pluginConfiguration } from './plugin-settings.js';
|
|
11
|
+
import { locked, fail } from '../workspace/storage.js';
|
|
12
|
+
|
|
13
|
+
export const PLUGIN_PROTOCOL = '1.0';
|
|
14
|
+
export const PLUGIN_SLOTS = ['topbar', 'bottombar', 'sidebar', 'bottom-left', 'canvas-overlay', 'top-left', 'top-right', 'bottom-right'];
|
|
15
|
+
export const PLUGIN_FIELDS = ['document', 'selection', 'graph', 'viewport'];
|
|
16
|
+
const ASSETS = '/library/plugin-assets/';
|
|
17
|
+
const SDK = '/clado-plugin-sdk.js';
|
|
18
|
+
const UI_CSS = '/plugin-ui.css';
|
|
19
|
+
const segment = /^[a-zA-Z0-9_-][a-zA-Z0-9_.-]*$/;
|
|
20
|
+
const uiPath = /^ui\/(?:[a-zA-Z0-9_-][a-zA-Z0-9_.-]*\/)*[a-zA-Z0-9_-][a-zA-Z0-9_.-]*\.html$/;
|
|
21
|
+
const permission = z.enum([
|
|
22
|
+
...PLUGIN_SLOTS.map(slot => 'ui.mount:' + slot),
|
|
23
|
+
...PLUGIN_FIELDS.map(field => 'canvas.' + field + '.read'),
|
|
24
|
+
]);
|
|
25
|
+
const manifest = z.strictObject({
|
|
26
|
+
manifestVersion: z.literal(1),
|
|
27
|
+
id: pluginId,
|
|
28
|
+
name: z.string().trim().min(1).max(80),
|
|
29
|
+
version: z.string().max(128).refine(value => {
|
|
30
|
+
const parsed = semver.parse(value);
|
|
31
|
+
return parsed && parsed.version + (parsed.build.length ? '+' + parsed.build.join('.') : '') === value;
|
|
32
|
+
}, '需要有效 SemVer'),
|
|
33
|
+
engines: z.strictObject({ clado: z.string().min(1).max(200) }),
|
|
34
|
+
protocols: z.array(z.string().regex(/^\d+\.\d+$/)).min(1).max(16),
|
|
35
|
+
entrypoints: z.strictObject({ ui: z.strictObject({ path: z.string().max(240).regex(uiPath) }) }),
|
|
36
|
+
permissions: z.array(z.union([permission, capabilityPermission])).max(64).default([]),
|
|
37
|
+
configuration: pluginConfiguration.optional(),
|
|
38
|
+
contributes: z.strictObject({
|
|
39
|
+
mounts: z.array(z.strictObject({
|
|
40
|
+
id: mountId, slot: z.enum(PLUGIN_SLOTS),
|
|
41
|
+
})).min(1).max(8),
|
|
42
|
+
capabilities: z.array(capabilityDefinition).max(16).default([]),
|
|
43
|
+
events: z.tuple([]).optional(),
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
const builtInMounts = ['brand', 'view-controls', 'directory', 'agent'];
|
|
47
|
+
const builtInIds = ['clado.host', ...builtInMounts.map(mount => 'clado.' + mount)];
|
|
48
|
+
export function builtInCapabilities(agentEnabled) {
|
|
49
|
+
const screenshot = compileCapabilities('clado.host', [{ id: 'canvas' }], [captureDefinition]);
|
|
50
|
+
const extensions = builtInMounts.filter(mount => mount !== 'agent' || agentEnabled).flatMap(mount => {
|
|
51
|
+
let raw;
|
|
52
|
+
try { raw = readFileSync(new URL('../../plugins/' + mount + '/capabilities.json', import.meta.url), 'utf8'); }
|
|
53
|
+
catch (error) { if (error.code === 'ENOENT') return []; throw error; }
|
|
54
|
+
return compileCapabilities('clado.' + mount, [{ id: mount }], JSON.parse(raw));
|
|
55
|
+
});
|
|
56
|
+
return [...screenshot, ...extensions];
|
|
57
|
+
}
|
|
58
|
+
export const builtInGrants = () => new Map(builtInIds.map(id => [id, id === 'clado.agent' ? ['capability.call:clado.directory/directory.open'] : []]));
|
|
59
|
+
const contentTypes = new Map(Object.entries({
|
|
60
|
+
'.html': 'text/html; charset=utf-8',
|
|
61
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
62
|
+
'.mjs': 'text/javascript; charset=utf-8',
|
|
63
|
+
'.css': 'text/css; charset=utf-8',
|
|
64
|
+
'.json': 'application/json; charset=utf-8',
|
|
65
|
+
'.svg': 'image/svg+xml',
|
|
66
|
+
'.png': 'image/png',
|
|
67
|
+
'.jpg': 'image/jpeg',
|
|
68
|
+
'.jpeg': 'image/jpeg',
|
|
69
|
+
'.gif': 'image/gif',
|
|
70
|
+
'.webp': 'image/webp',
|
|
71
|
+
'.woff2': 'font/woff2',
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
// The workspace opted into loading these packages. Still keep every file read
|
|
75
|
+
// inside its package, and avoid following symlinks or opening special files.
|
|
76
|
+
function readPackageFile(root, parts, maxBytes) {
|
|
77
|
+
let path = root;
|
|
78
|
+
if (!lstatSync(path).isDirectory()) throw new Error('插件包需要是实体目录。');
|
|
79
|
+
for (const part of parts.slice(0, -1)) {
|
|
80
|
+
path = join(path, part);
|
|
81
|
+
if (!lstatSync(path).isDirectory()) throw new Error('插件资源目录无效。');
|
|
82
|
+
}
|
|
83
|
+
path = join(path, parts.at(-1));
|
|
84
|
+
const info = lstatSync(path);
|
|
85
|
+
if (!info.isFile() || info.size > maxBytes) throw new Error('插件文件类型或大小无效。');
|
|
86
|
+
return readFileSync(path);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function readManifest(root) {
|
|
90
|
+
const result = manifest.safeParse(JSON.parse(readPackageFile(root, ['clado-plugin.json'], 64 * 1024).toString('utf8')));
|
|
91
|
+
if (!result.success) {
|
|
92
|
+
const issue = result.error.issues[0];
|
|
93
|
+
throw new Error(`清单字段 ${issue.path.join('.') || '根对象'} 无效:${issue.message}`);
|
|
94
|
+
}
|
|
95
|
+
const data = result.data;
|
|
96
|
+
if (builtInIds.includes(data.id)) throw new Error(data.id + ' 是 Clado 保留 ID。');
|
|
97
|
+
if (!semver.validRange(data.engines.clado) || !semver.satisfies(VERSION, data.engines.clado)) {
|
|
98
|
+
throw new Error(`插件需要 Clado ${data.engines.clado},当前版本为 ${VERSION}。`);
|
|
99
|
+
}
|
|
100
|
+
if (!data.protocols.includes(PLUGIN_PROTOCOL)) throw new Error(`插件需要声明协议 ${PLUGIN_PROTOCOL}。`);
|
|
101
|
+
const mounts = data.contributes.mounts;
|
|
102
|
+
if (new Set(mounts.map(mount => mount.id)).size !== mounts.length) throw new Error('挂载 ID 重复。');
|
|
103
|
+
for (const { slot } of mounts) {
|
|
104
|
+
if (!data.permissions.includes('ui.mount:' + slot)) throw new Error(`缺少挂载权限 ui.mount:${slot}。`);
|
|
105
|
+
}
|
|
106
|
+
readPackageFile(root, data.entrypoints.ui.path.split('/'), 2 * 1024 * 1024);
|
|
107
|
+
return { data, capabilities: compileCapabilities(data.id, mounts, data.contributes.capabilities),
|
|
108
|
+
configuration: compileConfiguration(data.configuration) };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function installWorkspacePlugin(ctx, files, runtime) {
|
|
112
|
+
if (!Array.isArray(files) || !files.length || files.length > 256) fail('请选择一个插件目录,最多 256 个文件。');
|
|
113
|
+
const parsed = new Map();
|
|
114
|
+
let size = 0;
|
|
115
|
+
for (const file of files) {
|
|
116
|
+
if (typeof file?.path !== 'string' || typeof file.data !== 'string' || file.path.length > 240) fail('插件文件参数无效。');
|
|
117
|
+
const parts = file.path.split('/');
|
|
118
|
+
if (!parts.every(part => segment.test(part)) ||
|
|
119
|
+
(file.path !== 'clado-plugin.json' && (parts[0] !== 'ui' || !contentTypes.has(extname(file.path).toLowerCase())))) fail('插件包仅接受清单和 ui 目录中的资源。');
|
|
120
|
+
if (parsed.has(file.path)) fail('插件包中有重复的文件路径。');
|
|
121
|
+
const data = Buffer.from(file.data, 'base64');
|
|
122
|
+
if (data.toString('base64') !== file.data) fail('插件文件编码无效。');
|
|
123
|
+
size += data.length;
|
|
124
|
+
if (data.length > 2 * 1024 * 1024 || size > 8 * 1024 * 1024) fail('插件包超过大小限制。', 413);
|
|
125
|
+
parsed.set(file.path, data);
|
|
126
|
+
}
|
|
127
|
+
if (!parsed.has('clado-plugin.json')) fail('插件目录缺少 clado-plugin.json。');
|
|
128
|
+
return locked(ctx, () => {
|
|
129
|
+
const directory = join(ctx.state, 'plugins');
|
|
130
|
+
if (!existsSync(directory)) mkdirSync(directory);
|
|
131
|
+
if (!lstatSync(directory).isDirectory()) fail('插件目录需要是实体目录。');
|
|
132
|
+
const stage = join(directory, '.install-' + randomUUID());
|
|
133
|
+
mkdirSync(stage, { mode: 0o700 });
|
|
134
|
+
try {
|
|
135
|
+
for (const [file, body] of parsed) {
|
|
136
|
+
const target = join(stage, file);
|
|
137
|
+
if (file.includes('/')) mkdirSync(join(target, '..'), { recursive: true });
|
|
138
|
+
writeFileSync(target, body, { flag: 'wx' });
|
|
139
|
+
}
|
|
140
|
+
let definition;
|
|
141
|
+
try { definition = readManifest(stage); }
|
|
142
|
+
catch (error) { fail(error.message, 422); }
|
|
143
|
+
const { id, name, version } = definition.data;
|
|
144
|
+
const target = join(directory, id);
|
|
145
|
+
const duplicate = readdirSync(directory, { withFileTypes: true }).some(entry => {
|
|
146
|
+
if (!entry.isDirectory() || entry.name.startsWith('.')) return false;
|
|
147
|
+
try { return readManifest(join(directory, entry.name)).data.id === id; }
|
|
148
|
+
catch { return false; }
|
|
149
|
+
});
|
|
150
|
+
if (existsSync(target) || duplicate) fail('已经安装了同 ID 的插件。', 409);
|
|
151
|
+
renameSync(stage, target);
|
|
152
|
+
runtime?.register(target, definition);
|
|
153
|
+
return { id, name, version, active: !!runtime };
|
|
154
|
+
} finally { rmSync(stage, { recursive: true, force: true }); }
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function loadWorkspacePlugins(state) {
|
|
159
|
+
const directory = join(state, 'plugins');
|
|
160
|
+
const plugins = [], warnings = [], packages = new Map(), capabilities = [], configurations = new Map();
|
|
161
|
+
let entries = [];
|
|
162
|
+
try {
|
|
163
|
+
if (!lstatSync(directory).isDirectory()) throw new Error('插件目录需要是实体目录。');
|
|
164
|
+
entries = readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error.code !== 'ENOENT') warnings.push({ directory: '.clado/plugins', message: error.message });
|
|
167
|
+
}
|
|
168
|
+
const candidates = new Map();
|
|
169
|
+
function register(root, { data, capabilities: declared, configuration }) {
|
|
170
|
+
configurations.set(data.id, configuration);
|
|
171
|
+
capabilities.push(...declared);
|
|
172
|
+
const key = randomUUID();
|
|
173
|
+
packages.set(key, root);
|
|
174
|
+
plugins.push({
|
|
175
|
+
id: data.id, name: data.name, version: data.version,
|
|
176
|
+
entry: ASSETS + key + '/' + data.entrypoints.ui.path,
|
|
177
|
+
permissions: data.permissions, mounts: data.contributes.mounts, capabilities: declared.map(item => item.descriptor),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
for (const entry of entries) {
|
|
181
|
+
if (entry.name.startsWith('.') || (!entry.isDirectory() && !entry.isSymbolicLink())) continue;
|
|
182
|
+
const root = join(directory, entry.name);
|
|
183
|
+
try {
|
|
184
|
+
const { data, capabilities, configuration } = readManifest(root);
|
|
185
|
+
const copies = candidates.get(data.id) || [];
|
|
186
|
+
copies.push({ data, capabilities, configuration, root, directory: entry.name });
|
|
187
|
+
candidates.set(data.id, copies);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
warnings.push({ directory: entry.name, message: error.code === 'ENOENT' ? '缺少插件清单或 UI 入口。' : error.message });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
for (const copies of candidates.values()) {
|
|
193
|
+
if (copies.length !== 1) {
|
|
194
|
+
for (const copy of copies) warnings.push({ directory: copy.directory, message: '插件 ID 重复:' + copy.data.id });
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
register(copies[0].root, copies[0]);
|
|
198
|
+
}
|
|
199
|
+
const descriptor = { workspaceId: randomUUID(), protocol: PLUGIN_PROTOCOL, slots: PLUGIN_SLOTS, fields: PLUGIN_FIELDS, plugins };
|
|
200
|
+
function serveAsset(req, res, url) {
|
|
201
|
+
const [key, ...parts] = url.pathname.slice(ASSETS.length).split('/').map(decodeURIComponent);
|
|
202
|
+
const root = packages.get(key), type = contentTypes.get(extname(parts.at(-1) || '').toLowerCase());
|
|
203
|
+
if (!root || !type || parts[0] !== 'ui' || !parts.every(part => segment.test(part))) {
|
|
204
|
+
throw new DocumentError('插件资源不存在。', 404);
|
|
205
|
+
}
|
|
206
|
+
let body;
|
|
207
|
+
try {
|
|
208
|
+
if (!lstatSync(directory).isDirectory()) throw new Error();
|
|
209
|
+
body = readPackageFile(root, parts, 2 * 1024 * 1024);
|
|
210
|
+
} catch {
|
|
211
|
+
throw new DocumentError('插件资源不可读。', 404);
|
|
212
|
+
}
|
|
213
|
+
const origin = 'http://' + req.headers.host;
|
|
214
|
+
const ui = origin + ASSETS + key + '/ui/';
|
|
215
|
+
res.writeHead(200, {
|
|
216
|
+
'content-type': type, 'cache-control': 'no-store', 'x-content-type-options': 'nosniff',
|
|
217
|
+
'access-control-allow-origin': 'null',
|
|
218
|
+
'content-security-policy': `sandbox allow-scripts; default-src 'none'; script-src ${ui} ${origin + SDK}; style-src ${ui} ${origin + UI_CSS}; img-src ${ui} data:; font-src ${ui}; form-action 'none'; base-uri 'none'; frame-ancestors ${origin}`,
|
|
219
|
+
});
|
|
220
|
+
res.end(req.method === 'HEAD' ? undefined : body);
|
|
221
|
+
}
|
|
222
|
+
return { descriptor, warnings, serveAsset, hasAsset: key => packages.has(key), capabilities, configurations, register };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function inspectWorkspacePlugins(state) {
|
|
226
|
+
const directory = join(state, 'plugins');
|
|
227
|
+
if (!existsSync(directory) || !lstatSync(directory).isDirectory()) return [];
|
|
228
|
+
return readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
|
|
229
|
+
if (!entry.isDirectory() || entry.name.startsWith('.')) return [];
|
|
230
|
+
try {
|
|
231
|
+
const raw = JSON.parse(readPackageFile(join(directory, entry.name), ['clado-plugin.json'], 64 * 1024));
|
|
232
|
+
const { id, name, version } = manifest.parse(raw);
|
|
233
|
+
return builtInIds.includes(id) ? [] : [{ id, name, version, pending: true, reason: '待启用第三方插件' }];
|
|
234
|
+
} catch { return []; }
|
|
235
|
+
});
|
|
236
|
+
}
|
package/src/server/workspace.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { createServer } from 'node:http';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
3
|
import { readFileSync, statSync, existsSync, mkdirSync } from 'node:fs';
|
|
3
|
-
import { dirname, resolve, basename, join, relative } from 'node:path';
|
|
4
|
+
import { dirname, resolve, basename, join, relative, sep, isAbsolute } from 'node:path';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
5
6
|
import { renderHtml } from '../html/page.js';
|
|
7
|
+
import { pluginMarkup, workspacePluginAssets } from '../html/plugin-assets.js';
|
|
6
8
|
import { scanDirectory, workspacePath, readDocument, DocumentError } from '../workspace/documents.js';
|
|
7
|
-
import { contextFor, initialize } from '../workspace/storage.js';
|
|
9
|
+
import { contextFor, discoverWorkspaces, initialize } from '../workspace/storage.js';
|
|
8
10
|
import { createWorkspaceService } from '../workspace/service.js';
|
|
9
11
|
import { createMcpHandler } from './mcp.js';
|
|
12
|
+
import { builtInCapabilities, builtInGrants, inspectWorkspacePlugins, installWorkspacePlugin, loadWorkspacePlugins } from './plugins.js';
|
|
13
|
+
import { createCapabilityRegistry } from './plugin-capabilities.js';
|
|
14
|
+
import { createPluginSettings } from './plugin-settings.js';
|
|
10
15
|
import { z } from 'zod/v4';
|
|
11
16
|
const assets = join(dirname(fileURLToPath(import.meta.url)), 'assets');
|
|
12
17
|
const resourceTypes = {png:'image/png',jpg:'image/jpeg',jpeg:'image/jpeg',gif:'image/gif',webp:'image/webp',svg:'image/svg+xml',pdf:'application/pdf',txt:'text/plain',csv:'text/csv',json:'application/json'};
|
|
@@ -18,19 +23,28 @@ const viewSelection = z.object({
|
|
|
18
23
|
}).strict();
|
|
19
24
|
export function createWorkspaceHandler(directory, options = {}) {
|
|
20
25
|
const root = resolve(directory);
|
|
21
|
-
const assetNames = new Set(['library.html','library.css','library.js','library-canvas.js'
|
|
26
|
+
const assetNames = new Set(['library.html','library.css','library.js','library-canvas.js']);
|
|
27
|
+
if (options.capabilities) assetNames.add('library-plugin-bridge.js');
|
|
28
|
+
if (options.plugins || options.experimentalPlugins) for (const name of ['library-plugins.js', 'library-plugins.css', 'clado-plugin-sdk.js']) assetNames.add(name);
|
|
22
29
|
const send = (res, status, type, body) => { res.writeHead(status, { 'content-type': type + '; charset=utf-8', 'cache-control':'no-store', 'x-content-type-options':'nosniff' }); res.end(body); };
|
|
23
30
|
const json = (res, status, data) => send(res, status, types.json, JSON.stringify(data));
|
|
24
31
|
const safeJson = data => JSON.stringify(data).replace(/</g,'\\u003c');
|
|
32
|
+
const resolveTarget = url => options.resolveWorkspace
|
|
33
|
+
? options.resolveWorkspace(url.searchParams.get('workspace'))
|
|
34
|
+
: { id: '', workspace: root, root, workspaceId: options.plugins?.descriptor.workspaceId || '', plugins: options.plugins || null, settings: options.settings || null, inactivePlugins: options.inactivePlugins };
|
|
25
35
|
return async function handle(req, res, url) {
|
|
26
36
|
const route = url.pathname.slice(1);
|
|
27
|
-
|
|
37
|
+
const pluginFile = workspacePluginAssets.get(url.pathname);
|
|
38
|
+
if (!url.pathname.startsWith('/library/') && !assetNames.has(route) && !pluginFile && !(options.entrypoint && route === '')) return false;
|
|
28
39
|
try {
|
|
29
40
|
const host = req.headers.host;
|
|
30
41
|
if (!/^(127\.0\.0\.1|localhost)(:\d+)?$/.test(host || '')) throw new DocumentError('只接受本机预览请求。',403);
|
|
31
|
-
|
|
42
|
+
const pluginsEnabled = !!(options.plugins || options.experimentalPlugins);
|
|
43
|
+
const pluginAsset = pluginsEnabled && url.pathname.startsWith('/library/plugin-assets/');
|
|
44
|
+
if (req.headers.origin && req.headers.origin !== 'http://' + host && !(pluginAsset && req.headers.origin === 'null')) throw new DocumentError('来源不匹配。',403);
|
|
32
45
|
if (url.pathname === '/library/selection' && options.publishSelection && req.method === 'POST') {
|
|
33
46
|
if (req.headers.origin !== 'http://' + host || req.headers['content-type'] !== 'application/json') throw new DocumentError('选区只接受同源页面请求。', 403);
|
|
47
|
+
const target = resolveTarget(url);
|
|
34
48
|
const chunks = []; let size = 0;
|
|
35
49
|
for await (const chunk of req) {
|
|
36
50
|
size += chunk.length;
|
|
@@ -39,44 +53,140 @@ export function createWorkspaceHandler(directory, options = {}) {
|
|
|
39
53
|
}
|
|
40
54
|
const selection = viewSelection.safeParse(JSON.parse(Buffer.concat(chunks).toString('utf8')));
|
|
41
55
|
if (!selection.success) throw new DocumentError('选区参数不合法。', 400);
|
|
42
|
-
workspacePath(root, selection.data.file, selection.data.nodes.length === 0);
|
|
43
|
-
options.publishSelection(selection.data);
|
|
56
|
+
workspacePath(target.root, selection.data.file, selection.data.nodes.length === 0);
|
|
57
|
+
options.publishSelection(target.workspace, selection.data);
|
|
44
58
|
json(res, 200, { ok: true }); return true;
|
|
45
59
|
}
|
|
60
|
+
if (options.agent && url.pathname === '/library/agent') {
|
|
61
|
+
const target = resolveTarget(url);
|
|
62
|
+
await options.agent.handle(req, res, target.workspace); return true;
|
|
63
|
+
}
|
|
64
|
+
if (url.pathname === '/library/plugin-settings') {
|
|
65
|
+
const target = resolveTarget(url);
|
|
66
|
+
if (!target.settings) throw new DocumentError('没有这个预览入口;文档操作请使用 /mcp。',404);
|
|
67
|
+
const id = url.searchParams.get('id');
|
|
68
|
+
if (req.method === 'GET') { json(res, 200, target.settings.read(id)); return true; }
|
|
69
|
+
if (req.method !== 'POST' || req.headers.origin !== 'http://' + host || req.headers['content-type'] !== 'application/json') {
|
|
70
|
+
throw new DocumentError('插件设置只接受同源页面写入。', 403);
|
|
71
|
+
}
|
|
72
|
+
const chunks = []; let size = 0;
|
|
73
|
+
for await (const chunk of req) {
|
|
74
|
+
size += chunk.length;
|
|
75
|
+
if (size > 1048576) throw new DocumentError('插件设置太大。', 413);
|
|
76
|
+
chunks.push(chunk);
|
|
77
|
+
}
|
|
78
|
+
const { value, expected } = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
79
|
+
json(res, 200, target.settings.save(id, value, expected));
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
if (options.installPlugin && url.pathname === '/library/install-plugin') {
|
|
83
|
+
if (req.method !== 'POST' || req.headers.origin !== 'http://' + host || req.headers['content-type'] !== 'application/json') {
|
|
84
|
+
throw new DocumentError('插件安装需要在工作区页面操作。', 403);
|
|
85
|
+
}
|
|
86
|
+
const target = resolveTarget(url);
|
|
87
|
+
const chunks = []; let size = 0;
|
|
88
|
+
for await (const chunk of req) {
|
|
89
|
+
size += chunk.length;
|
|
90
|
+
if (size > 12 * 1024 * 1024) throw new DocumentError('插件包太大。', 413);
|
|
91
|
+
chunks.push(chunk);
|
|
92
|
+
}
|
|
93
|
+
json(res, 201, options.installPlugin(target.workspace, JSON.parse(Buffer.concat(chunks).toString('utf8'))?.files));
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (options.capabilities && url.pathname === '/library/plugin-bridge') {
|
|
97
|
+
const view = z.uuid().safeParse(url.searchParams.get('viewId'));
|
|
98
|
+
if (!view.success) throw new DocumentError('需要有效的 viewId。', 400);
|
|
99
|
+
if (req.method === 'GET' && req.headers.accept === 'text/event-stream' &&
|
|
100
|
+
(!req.headers['sec-fetch-site'] || req.headers['sec-fetch-site'] === 'same-origin')) {
|
|
101
|
+
const target = resolveTarget(url);
|
|
102
|
+
options.capabilities.connect(view.data, res, target.workspace, target.workspaceId); return true;
|
|
103
|
+
}
|
|
104
|
+
if (req.method !== 'POST' || req.headers.origin !== 'http://' + host || req.headers['content-type'] !== 'application/json') {
|
|
105
|
+
throw new DocumentError('插件通信只接受同源页面请求。', 403);
|
|
106
|
+
}
|
|
107
|
+
const captureId = url.searchParams.get('captureId');
|
|
108
|
+
const limit = captureId ? options.capabilities.captureResultLimit(view.data, captureId) : 262144;
|
|
109
|
+
if (!limit) throw new DocumentError('截图请求已结束或不存在。', 409);
|
|
110
|
+
const chunks = []; let size = 0;
|
|
111
|
+
for await (const chunk of req) {
|
|
112
|
+
size += chunk.length;
|
|
113
|
+
if (size > limit) throw new DocumentError('插件消息太大。', 413);
|
|
114
|
+
chunks.push(chunk);
|
|
115
|
+
}
|
|
116
|
+
const message = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
117
|
+
if (captureId && (message?.action !== 'result' || message.callId !== captureId)) {
|
|
118
|
+
throw new DocumentError('截图响应与请求不匹配。', 400);
|
|
119
|
+
}
|
|
120
|
+
json(res, 200, await options.capabilities.receive(view.data, message));
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
46
123
|
if (req.method !== 'GET' && req.method !== 'HEAD') throw new DocumentError('不支持这个请求方法。',405);
|
|
124
|
+
if (url.pathname === '/library/workspaces.json') {
|
|
125
|
+
const workspaces = options.listWorkspaces
|
|
126
|
+
? options.listWorkspaces()
|
|
127
|
+
: [{ id: '', name: basename(root), workspace: root, documentRoot: root, documents: scanDirectory(root).documents.length }];
|
|
128
|
+
json(res, 200, { scope: options.scopeName || basename(root), workspaces }); return true;
|
|
129
|
+
}
|
|
130
|
+
if (pluginsEnabled && url.pathname === '/library/plugins.json') {
|
|
131
|
+
const target = resolveTarget(url);
|
|
132
|
+
const values = target.settings?.values() || {};
|
|
133
|
+
const descriptor = target.plugins.descriptor;
|
|
134
|
+
json(res, 200, { ...descriptor, plugins: descriptor.plugins.map(plugin => ({ ...plugin, settings: values[plugin.id] || {} })) }); return true;
|
|
135
|
+
}
|
|
136
|
+
if (pluginAsset) {
|
|
137
|
+
if (options.servePluginAsset) options.servePluginAsset(req, res, url);
|
|
138
|
+
else options.plugins.serveAsset(req, res, url);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
if (pluginFile) {
|
|
142
|
+
send(res, 200, types[route.split('.').pop()], readFileSync(pluginFile, 'utf8')); return true;
|
|
143
|
+
}
|
|
47
144
|
if (assetNames.has(route) || (options.entrypoint && route === '')) {
|
|
48
|
-
const name = route || 'library.html'; let body = readFileSync(join(assets,name),'utf8');
|
|
145
|
+
const name = route || 'library.html'; let body = readFileSync(join(assets, name),'utf8');
|
|
49
146
|
if (name === 'library.html') {
|
|
50
|
-
|
|
147
|
+
const target = resolveTarget(url);
|
|
148
|
+
const plugins = pluginMarkup({ workspace: true, agent: !!options.agent });
|
|
149
|
+
body = body.replace('<!--CLADO-PLUGIN-STYLES-->', () => plugins.styles)
|
|
150
|
+
.replace('<!--CLADO-PLUGIN-SCRIPTS-->', () => plugins.scripts);
|
|
151
|
+
const pluginAssets = (options.capabilities ? '<script src="/library-plugin-bridge.js"></script>' : '') +
|
|
152
|
+
(target.plugins ? '<link rel="stylesheet" href="/library-plugins.css"><script src="/library-plugins.js"></script>' : '');
|
|
153
|
+
body = body.replace('</head>', pluginAssets + '</head>');
|
|
154
|
+
const pluginCatalog = target.plugins?.descriptor.plugins.map(({ id, name, version }) => ({ id, name, version })) || target.inactivePlugins?.() || [];
|
|
155
|
+
const pluginPreferenceKey = createHash('sha256').update(target.workspace).digest('hex');
|
|
156
|
+
const pluginSettings = Object.fromEntries(Object.entries(target.settings?.values() || {}).filter(([id]) => id.startsWith('clado.') && !pluginCatalog.some(plugin => plugin.id === id)));
|
|
157
|
+
body = body.replace('<script src="library.js">','<script>window.__CLADO_WORKSPACE__='+safeJson({mode:options.mode || 'cards',theme:options.theme || 'light',entry:target.id ? '' : (options.entry || ''),workspaceId:target.id,workspaceName:basename(target.workspace),workspacePath:target.workspace,multiWorkspace:!!options.listWorkspaces,selection:!!options.publishSelection,plugins:!!target.plugins,agent:!!options.agent,agentProfile:options.agentProfile,pluginCatalog,pluginPreferenceKey,pluginSettings,hasPluginSettings:!!target.settings,canInstallPlugins:!!options.installPlugin})+';</script><script src="library.js">');
|
|
51
158
|
}
|
|
52
159
|
send(res,200,types[name.split('.').pop()],body); return true;
|
|
53
160
|
}
|
|
54
161
|
if (url.pathname === '/library/index.json') {
|
|
55
|
-
const
|
|
56
|
-
|
|
162
|
+
const target = resolveTarget(url);
|
|
163
|
+
const result = scanDirectory(target.root);
|
|
164
|
+
json(res,200,{root:(target.id || basename(target.root))+'/',workspaceId:target.id,workspace:target.workspace,documents:result.documents,skipped:result.skipped}); return true;
|
|
57
165
|
}
|
|
58
166
|
const name = url.searchParams.get('file');
|
|
59
167
|
if (url.pathname === '/library/resource') {
|
|
168
|
+
const target = resolveTarget(url);
|
|
60
169
|
const type = resourceTypes[String(name).split('.').pop().toLowerCase()];
|
|
61
170
|
if (!type) throw new DocumentError('不支持的资源类型。',415);
|
|
62
|
-
const path=workspacePath(root,name,false,true);
|
|
171
|
+
const path=workspacePath(target.root,name,false,true);
|
|
63
172
|
res.writeHead(200,{'content-type':type,'x-content-type-options':'nosniff','content-security-policy':"default-src 'none'; sandbox",'cache-control':'no-store'});res.end(readFileSync(path));return true;
|
|
64
173
|
}
|
|
65
174
|
if (!['/library/source.mdc','/library/canvas'].includes(url.pathname)) throw new DocumentError('没有这个预览入口;文档操作请使用 /mcp。',404);
|
|
66
|
-
const
|
|
175
|
+
const target = resolveTarget(url);
|
|
176
|
+
const file = workspacePath(target.root,name), item = readDocument(file);
|
|
67
177
|
if (url.pathname === '/library/source.mdc') { send(res,200,types.md,item.source); return true; }
|
|
68
178
|
if (item.diagnostics.some(d=>d.severity==='error')) throw new DocumentError('文档暂时无法解析。',422,item.diagnostics);
|
|
69
|
-
const mode = ['
|
|
70
|
-
let html = (options.render || renderHtml)(item.doc,item.diagnostics,{file:name,title:item.doc.title,mode,theme:options.theme || 'light',library:true});
|
|
179
|
+
const mode = ['cards','mindmap','doc'].includes(url.searchParams.get('mode')) ? url.searchParams.get('mode') : (options.mode || 'cards');
|
|
180
|
+
let html = (options.render || renderHtml)(item.doc,item.diagnostics,{file:name,title:item.doc.title,mode,theme:['light','dark'].includes(url.searchParams.get('theme')) ? url.searchParams.get('theme') : options.theme || 'light',library:true,workspaceChrome:url.searchParams.get('chrome') === 'workspace'});
|
|
71
181
|
const bodyEnd = html.lastIndexOf('</body>');
|
|
72
|
-
html = html.slice(0,bodyEnd) + '<script>window.__CLADO_FILE_PATH__='+safeJson(name)+';window.__CLADO_FILE_VERSION__='+safeJson(item.version)+';window.__CLADO_ANCHOR__='+safeJson(url.searchParams.get('anchor') || '')+';</script><script src="/library-canvas.js"></script>' + html.slice(bodyEnd);
|
|
182
|
+
html = html.slice(0,bodyEnd) + '<script>window.__CLADO_FILE_PATH__='+safeJson(name)+';window.__CLADO_FILE_VERSION__='+safeJson(item.version)+';window.__CLADO_ANCHOR__='+safeJson(url.searchParams.get('anchor') || '')+';window.__CLADO_WORKSPACE_ID__='+safeJson(target.id)+';</script><script src="/library-canvas.js"></script>' + html.slice(bodyEnd);
|
|
73
183
|
send(res,200,types.html,html); return true;
|
|
74
184
|
} catch (error) {
|
|
75
|
-
json(res,error.status || (error instanceof SyntaxError ? 400 : 500),{error:error.message,diagnostics:error.diagnostics || []}); return true;
|
|
185
|
+
json(res,error.status || (error instanceof SyntaxError ? 400 : 500),{error:error.message,diagnostics:error.diagnostics || [], ...(error.details && { details: error.details })}); return true;
|
|
76
186
|
}
|
|
77
187
|
};
|
|
78
188
|
}
|
|
79
|
-
export async function startWorkspace(input, { port = 4317, mode = '
|
|
189
|
+
export async function startWorkspace(input, { port = 4317, mode = 'cards', theme = 'light', entry, project = false, experimentalPlugins = false, agent: agentName = 'acp' } = {}) {
|
|
80
190
|
const path = resolve(input);
|
|
81
191
|
if (!existsSync(path) && !/\.mdc?$/i.test(path)) mkdirSync(path, { recursive: true });
|
|
82
192
|
if (statSync(path).isFile() && !/\.mdc?$/i.test(path)) throw new DocumentError('serve 文件需要 .mdc 或 .md 扩展名。');
|
|
@@ -85,29 +195,112 @@ export async function startWorkspace(input, { port = 4317, mode = 'mindmap', the
|
|
|
85
195
|
else if (project || existsSync(join(root, '.clado/workspace.json')) || existsSync(join(root, 'package.json')) || existsSync(join(root, '.git')) || (statSync(path).isDirectory() && !scanDirectory(root).documents.some(d => !/^readme\.md$/i.test(d.file)))) {
|
|
86
196
|
const ctx = contextFor(root, root); workspace = root; root = ctx.documents;
|
|
87
197
|
}
|
|
88
|
-
const
|
|
198
|
+
const rootCtx = contextFor(workspace, workspace, root); initialize(rootCtx);
|
|
199
|
+
const runtimes = new Map();
|
|
200
|
+
function runtimeFor(ctx) {
|
|
201
|
+
const existing = runtimes.get(ctx.workspace);
|
|
202
|
+
if (existing) { existing.ctx = ctx; existing.root = ctx.documents; return existing; }
|
|
203
|
+
const wsPlugins = experimentalPlugins ? loadWorkspacePlugins(ctx.state) : null;
|
|
204
|
+
const wsSettings = createPluginSettings(ctx, wsPlugins?.configurations);
|
|
205
|
+
const wsGrants = builtInGrants();
|
|
206
|
+
for (const { id, permissions } of wsPlugins?.descriptor.plugins || []) wsGrants.set(id, permissions);
|
|
207
|
+
const wsProviders = [...builtInCapabilities(agentName !== 'off'), ...(wsPlugins?.capabilities || [])];
|
|
208
|
+
const rt = {
|
|
209
|
+
id: relative(workspace, ctx.workspace).split(sep).join('/'),
|
|
210
|
+
workspace: ctx.workspace,
|
|
211
|
+
root: ctx.documents,
|
|
212
|
+
ctx,
|
|
213
|
+
workspaceId: wsPlugins?.descriptor.workspaceId || randomUUID(),
|
|
214
|
+
plugins: wsPlugins,
|
|
215
|
+
settings: wsSettings,
|
|
216
|
+
grants: wsGrants,
|
|
217
|
+
providers: wsProviders,
|
|
218
|
+
inactivePlugins: () => inspectWorkspacePlugins(ctx.state),
|
|
219
|
+
};
|
|
220
|
+
runtimes.set(ctx.workspace, rt);
|
|
221
|
+
return rt;
|
|
222
|
+
}
|
|
223
|
+
const rootRuntime = runtimeFor(rootCtx);
|
|
224
|
+
function resolveWorkspaceParam(param) {
|
|
225
|
+
if (!param) return rootRuntime;
|
|
226
|
+
if (typeof param !== 'string' || isAbsolute(param) || param.includes('\\') || param.includes('\0') ||
|
|
227
|
+
param.split('/').some(segment => !segment || segment === '.' || segment === '..' || segment.startsWith('.'))) {
|
|
228
|
+
throw new DocumentError('工作区路径不合法。', 400);
|
|
229
|
+
}
|
|
230
|
+
const ctx = contextFor(workspace, resolve(workspace, param), root);
|
|
231
|
+
if (!existsSync(ctx.documents) && !existsSync(ctx.state)) throw new DocumentError('工作区不存在或尚未初始化。', 404);
|
|
232
|
+
return runtimeFor(ctx);
|
|
233
|
+
}
|
|
234
|
+
const resolveMcpWorkspace = target => runtimeFor(contextFor(workspace, target, root)).workspace;
|
|
235
|
+
const capabilities = createCapabilityRegistry({
|
|
236
|
+
workspace, workspaceId: rootRuntime.workspaceId,
|
|
237
|
+
providers: rootRuntime.providers, grants: rootRuntime.grants,
|
|
238
|
+
resolveWorkspace: resolveMcpWorkspace,
|
|
239
|
+
providersFor: target => runtimeFor(contextFor(workspace, target, root)).providers,
|
|
240
|
+
grantsFor: target => runtimeFor(contextFor(workspace, target, root)).grants,
|
|
241
|
+
});
|
|
89
242
|
const entryFile = entry ? relative(root,workspacePath(root,entry)).split('\\').join('/') : (statSync(path).isFile() ? basename(path) : '');
|
|
90
243
|
if (entryFile) {
|
|
91
244
|
const item=readDocument(workspacePath(root,entryFile));
|
|
92
245
|
if(item.diagnostics.some(d=>d.severity==='error'))throw new DocumentError('入口 Markdown 无法解析。',422,item.diagnostics);
|
|
93
246
|
}
|
|
94
|
-
|
|
95
|
-
const publishSelection = next => {
|
|
247
|
+
const selections = new Map();
|
|
248
|
+
const publishSelection = (targetWorkspace, next) => {
|
|
249
|
+
const current = selections.get(targetWorkspace);
|
|
96
250
|
if (next.refresh) {
|
|
97
|
-
if (
|
|
98
|
-
if (next.refresh === 'render')
|
|
99
|
-
else if (
|
|
100
|
-
} else if (next.nodes.length)
|
|
101
|
-
else if (
|
|
251
|
+
if (current?.tab !== next.tab || current.file !== next.file) return;
|
|
252
|
+
if (next.refresh === 'render') selections.set(targetWorkspace, { ...next, expiresAt: Date.now() + 120000 });
|
|
253
|
+
else if (current.version === next.version) current.expiresAt = Date.now() + 120000;
|
|
254
|
+
} else if (next.nodes.length) selections.set(targetWorkspace, { ...next, expiresAt: Date.now() + 120000 });
|
|
255
|
+
else if (current?.tab === next.tab) selections.delete(targetWorkspace);
|
|
102
256
|
};
|
|
103
|
-
const
|
|
104
|
-
|
|
257
|
+
const readSelection = targetWorkspace => {
|
|
258
|
+
const current = selections.get(targetWorkspace);
|
|
259
|
+
return current?.expiresAt > Date.now() ? current : null;
|
|
260
|
+
};
|
|
261
|
+
const agent = agentName !== 'off' ? (await import('./agent.js')).createAgentHandler({
|
|
262
|
+
workspace, mcpUrl: () => 'http://127.0.0.1:' + server.address().port + '/mcp',
|
|
263
|
+
...(agentName === 'acp' && { resolveLaunch: () => {
|
|
264
|
+
const { command, args, env } = rootRuntime.settings.agentLaunch();
|
|
265
|
+
return { command, args, env };
|
|
266
|
+
} }),
|
|
267
|
+
}) : null;
|
|
268
|
+
function installPlugin(targetWorkspace, files) {
|
|
269
|
+
const rt = runtimeFor(contextFor(workspace, targetWorkspace, root));
|
|
270
|
+
const previous = rt.plugins?.capabilities.length || 0;
|
|
271
|
+
const installed = installWorkspacePlugin(rt.ctx, files, rt.plugins);
|
|
272
|
+
if (rt.plugins) {
|
|
273
|
+
const descriptor = rt.plugins.descriptor.plugins.find(plugin => plugin.id === installed.id);
|
|
274
|
+
rt.grants.set(installed.id, descriptor.permissions);
|
|
275
|
+
rt.providers.push(...rt.plugins.capabilities.slice(previous));
|
|
276
|
+
rt.settings.register(installed.id, rt.plugins.configurations.get(installed.id));
|
|
277
|
+
}
|
|
278
|
+
return installed;
|
|
279
|
+
}
|
|
280
|
+
function servePluginAsset(req, res, url) {
|
|
281
|
+
const key = decodeURIComponent(url.pathname.slice('/library/plugin-assets/'.length).split('/')[0] || '');
|
|
282
|
+
for (const rt of runtimes.values()) {
|
|
283
|
+
if (rt.plugins?.hasAsset(key)) { rt.plugins.serveAsset(req, res, url); return; }
|
|
284
|
+
}
|
|
285
|
+
throw new DocumentError('插件资源不存在。', 404);
|
|
286
|
+
}
|
|
287
|
+
const handle = createWorkspaceHandler(root,{
|
|
288
|
+
entrypoint:true,mode,theme,entry:entryFile,publishSelection,
|
|
289
|
+
plugins:rootRuntime.plugins,experimentalPlugins,servePluginAsset,
|
|
290
|
+
agent,agentProfile:agentName,capabilities,settings:rootRuntime.settings,installPlugin,
|
|
291
|
+
resolveWorkspace:resolveWorkspaceParam,
|
|
292
|
+
listWorkspaces:() => discoverWorkspaces(workspace, root),
|
|
293
|
+
scopeName:basename(workspace),
|
|
294
|
+
inactivePlugins:rootRuntime.inactivePlugins,
|
|
295
|
+
});
|
|
296
|
+
const mcp = createMcpHandler(createWorkspaceService(workspace, { documentRoot: root, readSelection }), capabilities.invoke);
|
|
105
297
|
const server = createServer(async (req,res) => {
|
|
106
298
|
try { const url = new URL(req.url,'http://127.0.0.1'); if (!await mcp(req,res,url) && !await handle(req,res,url)) { res.writeHead(404);res.end('Not found'); } }
|
|
107
299
|
catch { if (!res.headersSent) res.writeHead(500);res.end('预览请求失败'); }
|
|
108
300
|
});
|
|
301
|
+
if (agent) server.on('close', agent.close);
|
|
109
302
|
await new Promise((resolve,reject) => { server.once('error',reject); server.listen(port,'127.0.0.1',resolve); });
|
|
110
303
|
const file = entryFile ? '?file='+encodeURIComponent(entryFile) : '';
|
|
111
304
|
const origin = 'http://127.0.0.1:'+server.address().port;
|
|
112
|
-
return {server,url:origin+'/'+file,mcpUrl:origin+'/mcp',workspace,root};
|
|
305
|
+
return {server,url:origin+'/'+file,mcpUrl:origin+'/mcp',workspace,root,pluginWarnings:rootRuntime.plugins?.warnings || [],stopAgent:agent?.close,stopCapabilities:capabilities.close};
|
|
113
306
|
}
|
package/src/skill/install.js
CHANGED
|
@@ -312,6 +312,6 @@ export function installTo(cwd, ids, opts = {}) {
|
|
|
312
312
|
* 是无害的额外键,于是统一都带上,省得一张表里两套写法。
|
|
313
313
|
*/
|
|
314
314
|
function ownFileText(body) {
|
|
315
|
-
const desc = '用 clado 把 Markdown
|
|
315
|
+
const desc = '用 clado 把 Markdown 编译成自包含的网页(卡片 / 脑图 / 文档三种模式)';
|
|
316
316
|
return `---\ndescription: ${desc}\nalwaysApply: false\n---\n\n${body}`;
|
|
317
317
|
}
|
package/src/skill/targets.js
CHANGED
|
@@ -157,7 +157,7 @@ export function findTarget(id) {
|
|
|
157
157
|
export function ruleBody(skillPath) {
|
|
158
158
|
return `# clado —— Markdown 三视图工作区
|
|
159
159
|
|
|
160
|
-
这个项目用 Clado 维护 Markdown
|
|
160
|
+
这个项目用 Clado 维护 Markdown 画布,在卡片、脑图和文档视图中讨论与迭代,也可打包成单个离线 HTML。
|
|
161
161
|
|
|
162
162
|
写或改画布前,先读 Skill 入口:
|
|
163
163
|
|
|
@@ -176,9 +176,9 @@ export function ruleBody(skillPath) {
|
|
|
176
176
|
|
|
177
177
|
clado serve
|
|
178
178
|
|
|
179
|
-
连接输出的 Streamable HTTP MCP。每次调用提供输出的 workspace,先 clado_workspace inspect,再 clado_templates read 提示词,用 clado_documents create 按模板初始化 .mdc;节点、链接与批量操作也用MCP
|
|
179
|
+
连接输出的 Streamable HTTP MCP。每次调用提供输出的 workspace,先 clado_workspace inspect,再 clado_templates read 提示词,用 clado_documents create 按模板初始化 .mdc;节点、链接与批量操作也用MCP。跨卡连接优先从具体内容行出发(代码行、表格数据行、Mermaid 节点或步骤正文内的行内链接),避免为凑连线单独追加裸的卡片连卡片。正文直接传多行字符串。新建、追加和唯一原文编辑可直接提交;覆盖和删除使用对应的版本。用户提到选中的卡片时通过 clado_workspace selection 读取。模板可在项目 create/update,用 pull 从用户库复制,用 push 同步到用户库;push 同时带 expectedUserTemplateVersion。
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
网页只展示卡片/脑图/文档,保存后自动更新。交付可用 clado build --entry overview.mdc --mode cards;默认生成只读 clado.html。工具不执行文档里的SQL、脚本或发布任务。
|
|
182
182
|
|
|
183
183
|
`;
|
|
184
184
|
}
|
package/src/util/update.js
CHANGED
|
@@ -10,9 +10,10 @@ const cacheLifetime = 24 * 60 * 60 * 1000;
|
|
|
10
10
|
|
|
11
11
|
function updateInfo(latest) {
|
|
12
12
|
if (typeof latest !== 'string' || !stableVersion.test(latest)) throw new Error('npm 未返回可用的稳定版本。');
|
|
13
|
-
const
|
|
13
|
+
const [core, pre = ''] = VERSION.split('-');
|
|
14
|
+
const installed = core.split('.').map(Number), remote = latest.split('.').map(Number);
|
|
14
15
|
const difference = remote.map((part, index) => part - installed[index]).find(value => value !== 0) || 0;
|
|
15
|
-
return { current: VERSION, latest, updateAvailable: difference > 0 };
|
|
16
|
+
return { current: VERSION, latest, updateAvailable: difference > 0 || (difference === 0 && Boolean(pre)) };
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export async function checkUpdate() {
|