cladogram 0.5.5-beta.1 → 0.5.5-beta.3
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 +2 -0
- package/docs/release.md +14 -2
- package/package.json +1 -1
- package/plugins/agent/index.js +457 -24
- package/plugins/agent/style.css +299 -8
- package/skills/clado/SKILL.md +1 -0
- package/src/agent/executors.js +213 -0
- package/src/agent/probe.js +176 -0
- package/src/agent/providers/anthropic.js +220 -0
- package/src/agent/providers/index.js +52 -0
- package/src/agent/providers/openai.js +146 -0
- package/src/agent/runtime.js +557 -0
- package/src/agent/sessions.js +129 -0
- package/src/core/media-links.js +165 -11
- package/src/core/parse.js +25 -4
- package/src/html/canvas-ui.css +64 -1
- package/src/html/canvas-wires.js +2 -2
- package/src/html/media-anchors.js +174 -28
- package/src/html/mindmap-connectors.js +12 -10
- package/src/html/page.js +4 -0
- package/src/html/runtime-api.js +136 -5
- package/src/html/runtime.js +17 -218
- package/src/html/view-registry.js +95 -0
- package/src/html/views/view-cards.js +28 -0
- package/src/html/views/view-doc.js +51 -0
- package/src/html/views/view-mindmap.js +173 -0
- package/src/server/agent.js +331 -14
- package/src/server/assets/library-canvas.js +11 -2
- package/src/server/assets/library.js +92 -5
- package/src/server/events.js +189 -0
- package/src/server/mcp.js +10 -5
- package/src/server/plugin-settings.js +26 -0
- package/src/server/plugins.js +16 -3
- package/src/server/workspace.js +41 -3
- package/src/workspace/service.js +58 -21
- package/templates/test-cases.mdc +47 -0
package/plugins/agent/style.css
CHANGED
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
position: absolute;
|
|
23
23
|
right: 0;
|
|
24
24
|
bottom: calc(100% + 8px);
|
|
25
|
-
width: min(
|
|
26
|
-
height: min(
|
|
27
|
-
min-height:
|
|
25
|
+
width: min(410px, calc(100vw - 32px));
|
|
26
|
+
height: min(580px, calc(100dvh - 168px));
|
|
27
|
+
min-height: 240px;
|
|
28
28
|
display: flex;
|
|
29
29
|
flex-direction: column;
|
|
30
30
|
overflow: hidden;
|
|
@@ -33,18 +33,151 @@
|
|
|
33
33
|
display: flex;
|
|
34
34
|
align-items: center;
|
|
35
35
|
justify-content: space-between;
|
|
36
|
+
gap: 8px;
|
|
36
37
|
border-bottom: 1px solid var(--clado-ui-edge);
|
|
37
|
-
padding: 9px
|
|
38
|
+
padding: 9px 10px 9px 14px;
|
|
39
|
+
}
|
|
40
|
+
.clado-agent-heading {
|
|
41
|
+
min-width: 0;
|
|
42
|
+
display: flex;
|
|
43
|
+
flex-direction: column;
|
|
44
|
+
}
|
|
45
|
+
.clado-agent-header-actions {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
gap: 3px;
|
|
49
|
+
flex: none;
|
|
50
|
+
}
|
|
51
|
+
.clado-agent-header-actions .clado-ui-button {
|
|
52
|
+
min-height: 26px;
|
|
53
|
+
padding: 2px 7px;
|
|
54
|
+
font-size: 11.5px;
|
|
55
|
+
}
|
|
56
|
+
.clado-agent-follow[aria-pressed="true"] {
|
|
57
|
+
color: var(--clado-ui-accent);
|
|
58
|
+
background: var(--clado-ui-active);
|
|
38
59
|
}
|
|
39
60
|
.clado-agent-panel h2 { margin: 0; font-size: 14px; font-weight: 650; }
|
|
40
|
-
.clado-agent-provider {
|
|
41
|
-
|
|
61
|
+
.clado-agent-provider {
|
|
62
|
+
color: var(--clado-ui-muted);
|
|
63
|
+
font-size: 11px;
|
|
64
|
+
white-space: nowrap;
|
|
65
|
+
overflow: hidden;
|
|
66
|
+
text-overflow: ellipsis;
|
|
67
|
+
}
|
|
68
|
+
.clado-agent-close { font-size: 18px !important; padding-inline: 6px !important; }
|
|
69
|
+
.clado-agent-sessions {
|
|
70
|
+
max-height: 170px;
|
|
71
|
+
overflow: auto;
|
|
72
|
+
padding: 6px 10px;
|
|
73
|
+
border-bottom: 1px solid var(--clado-ui-edge);
|
|
74
|
+
background: color-mix(in srgb, var(--clado-ui-well) 70%, transparent);
|
|
75
|
+
display: flex;
|
|
76
|
+
flex-direction: column;
|
|
77
|
+
gap: 4px;
|
|
78
|
+
}
|
|
79
|
+
.clado-agent-sessions[hidden] { display: none; }
|
|
80
|
+
.clado-agent-sessions-empty {
|
|
81
|
+
padding: 10px 6px;
|
|
82
|
+
font-size: 11.5px;
|
|
83
|
+
color: var(--clado-ui-muted);
|
|
84
|
+
text-align: center;
|
|
85
|
+
}
|
|
86
|
+
.clado-agent-session-row {
|
|
87
|
+
display: flex;
|
|
88
|
+
align-items: center;
|
|
89
|
+
gap: 4px;
|
|
90
|
+
border-radius: 8px;
|
|
91
|
+
transition: background 140ms ease;
|
|
92
|
+
}
|
|
93
|
+
.clado-agent-session-row:hover, .clado-agent-session-row.active {
|
|
94
|
+
background: var(--clado-ui-active);
|
|
95
|
+
}
|
|
96
|
+
.clado-agent-session-open {
|
|
97
|
+
flex: 1;
|
|
98
|
+
min-width: 0;
|
|
99
|
+
border: 0;
|
|
100
|
+
background: transparent;
|
|
101
|
+
color: var(--clado-ui-text);
|
|
102
|
+
text-align: left;
|
|
103
|
+
padding: 5px 7px;
|
|
104
|
+
cursor: pointer;
|
|
105
|
+
display: flex;
|
|
106
|
+
flex-direction: column;
|
|
107
|
+
gap: 2px;
|
|
108
|
+
font: inherit;
|
|
109
|
+
}
|
|
110
|
+
.clado-agent-session-title {
|
|
111
|
+
font-size: 12px;
|
|
112
|
+
font-weight: 550;
|
|
113
|
+
white-space: nowrap;
|
|
114
|
+
overflow: hidden;
|
|
115
|
+
text-overflow: ellipsis;
|
|
116
|
+
}
|
|
117
|
+
.clado-agent-session-open small {
|
|
118
|
+
font-size: 10.5px;
|
|
119
|
+
color: var(--clado-ui-muted);
|
|
120
|
+
}
|
|
121
|
+
.clado-agent-session-open small.waiting {
|
|
122
|
+
color: #d97706;
|
|
123
|
+
font-weight: 600;
|
|
124
|
+
}
|
|
125
|
+
.clado-agent-session-del {
|
|
126
|
+
border: 0;
|
|
127
|
+
background: transparent;
|
|
128
|
+
color: var(--clado-ui-muted);
|
|
129
|
+
width: 24px;
|
|
130
|
+
height: 24px;
|
|
131
|
+
border-radius: 6px;
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
font-size: 14px;
|
|
134
|
+
flex: none;
|
|
135
|
+
}
|
|
136
|
+
.clado-agent-session-del:hover {
|
|
137
|
+
color: var(--clado-ui-text);
|
|
138
|
+
background: color-mix(in srgb, var(--clado-ui-edge) 50%, transparent);
|
|
139
|
+
}
|
|
140
|
+
.clado-agent-modes {
|
|
141
|
+
display: flex;
|
|
142
|
+
flex-wrap: wrap;
|
|
143
|
+
gap: 5px;
|
|
144
|
+
padding: 8px 12px 6px;
|
|
145
|
+
border-bottom: 1px solid color-mix(in srgb, var(--clado-ui-edge) 70%, transparent);
|
|
146
|
+
}
|
|
147
|
+
.clado-agent-chip {
|
|
148
|
+
min-height: 26px;
|
|
149
|
+
padding: 3px 9px;
|
|
150
|
+
font-size: 11.5px;
|
|
151
|
+
border-radius: 999px;
|
|
152
|
+
}
|
|
153
|
+
.clado-agent-persona-bar,
|
|
154
|
+
.clado-agent-executor-bar {
|
|
155
|
+
display: flex;
|
|
156
|
+
align-items: center;
|
|
157
|
+
gap: 8px;
|
|
158
|
+
padding: 6px 12px;
|
|
159
|
+
border-bottom: 1px solid color-mix(in srgb, var(--clado-ui-edge) 70%, transparent);
|
|
160
|
+
font-size: 11.5px;
|
|
161
|
+
color: var(--clado-ui-muted);
|
|
162
|
+
}
|
|
163
|
+
.clado-agent-persona-bar[hidden],
|
|
164
|
+
.clado-agent-executor-bar[hidden] { display: none; }
|
|
165
|
+
.clado-agent-select {
|
|
166
|
+
flex: 1;
|
|
167
|
+
min-width: 0;
|
|
168
|
+
padding: 4px 8px;
|
|
169
|
+
border: 1px solid var(--clado-ui-edge);
|
|
170
|
+
border-radius: 8px;
|
|
171
|
+
background: var(--clado-ui-well);
|
|
172
|
+
color: var(--clado-ui-text);
|
|
173
|
+
font: inherit;
|
|
174
|
+
}
|
|
42
175
|
.clado-agent-log {
|
|
43
176
|
flex: 1;
|
|
44
177
|
min-height: 0;
|
|
45
178
|
overflow: auto;
|
|
46
179
|
overscroll-behavior: contain;
|
|
47
|
-
padding:
|
|
180
|
+
padding: 13px;
|
|
48
181
|
display: flex;
|
|
49
182
|
flex-direction: column;
|
|
50
183
|
gap: 12px;
|
|
@@ -61,6 +194,7 @@
|
|
|
61
194
|
background: var(--clado-ui-active);
|
|
62
195
|
}
|
|
63
196
|
.clado-agent-message.assistant {
|
|
197
|
+
width: 100%;
|
|
64
198
|
padding-inline: 3px;
|
|
65
199
|
}
|
|
66
200
|
.clado-agent-message strong, .clado-agent-message small {
|
|
@@ -72,6 +206,163 @@
|
|
|
72
206
|
white-space: pre-wrap;
|
|
73
207
|
line-height: 1.55;
|
|
74
208
|
}
|
|
209
|
+
.clado-agent-thinking {
|
|
210
|
+
margin: 5px 0 6px;
|
|
211
|
+
padding: 5px 9px;
|
|
212
|
+
border-radius: 9px;
|
|
213
|
+
border: 1px solid color-mix(in srgb, var(--clado-ui-edge) 75%, transparent);
|
|
214
|
+
background: color-mix(in srgb, var(--clado-ui-well) 70%, transparent);
|
|
215
|
+
font-size: 11.5px;
|
|
216
|
+
}
|
|
217
|
+
.clado-agent-thinking summary {
|
|
218
|
+
cursor: pointer;
|
|
219
|
+
color: var(--clado-ui-muted);
|
|
220
|
+
font-weight: 550;
|
|
221
|
+
user-select: none;
|
|
222
|
+
}
|
|
223
|
+
.clado-agent-thinking pre {
|
|
224
|
+
margin: 6px 0 2px;
|
|
225
|
+
white-space: pre-wrap;
|
|
226
|
+
overflow-wrap: anywhere;
|
|
227
|
+
font-family: inherit;
|
|
228
|
+
font-size: 11.5px;
|
|
229
|
+
line-height: 1.5;
|
|
230
|
+
color: var(--clado-ui-muted);
|
|
231
|
+
}
|
|
232
|
+
.clado-agent-changes {
|
|
233
|
+
margin-top: 8px;
|
|
234
|
+
padding: 8px 10px;
|
|
235
|
+
border-radius: 10px;
|
|
236
|
+
border: 1px solid color-mix(in srgb, var(--clado-ui-accent) 26%, var(--clado-ui-edge));
|
|
237
|
+
background: color-mix(in srgb, var(--clado-ui-accent) 6%, var(--clado-ui-well));
|
|
238
|
+
}
|
|
239
|
+
.clado-agent-changes-title {
|
|
240
|
+
font-size: 11px;
|
|
241
|
+
font-weight: 600;
|
|
242
|
+
color: var(--clado-ui-accent);
|
|
243
|
+
margin-bottom: 5px;
|
|
244
|
+
}
|
|
245
|
+
.clado-agent-changes-list {
|
|
246
|
+
display: flex;
|
|
247
|
+
flex-direction: column;
|
|
248
|
+
gap: 3px;
|
|
249
|
+
}
|
|
250
|
+
.clado-agent-change-item {
|
|
251
|
+
border: 0;
|
|
252
|
+
background: transparent;
|
|
253
|
+
color: var(--clado-ui-text);
|
|
254
|
+
font: inherit;
|
|
255
|
+
font-size: 11.5px;
|
|
256
|
+
text-align: left;
|
|
257
|
+
padding: 4px 6px;
|
|
258
|
+
border-radius: 7px;
|
|
259
|
+
cursor: pointer;
|
|
260
|
+
display: flex;
|
|
261
|
+
align-items: center;
|
|
262
|
+
gap: 7px;
|
|
263
|
+
transition: background 140ms ease;
|
|
264
|
+
}
|
|
265
|
+
.clado-agent-change-item:hover {
|
|
266
|
+
background: var(--clado-ui-active);
|
|
267
|
+
}
|
|
268
|
+
.clado-agent-change-item .dot {
|
|
269
|
+
width: 6px;
|
|
270
|
+
height: 6px;
|
|
271
|
+
border-radius: 50%;
|
|
272
|
+
background: var(--clado-ui-accent);
|
|
273
|
+
flex: none;
|
|
274
|
+
}
|
|
275
|
+
.clado-agent-question {
|
|
276
|
+
margin-top: 8px;
|
|
277
|
+
padding: 10px 11px;
|
|
278
|
+
border-radius: 11px;
|
|
279
|
+
border: 1px solid rgb(217 119 6 / .42);
|
|
280
|
+
background: rgb(217 119 6 / .06);
|
|
281
|
+
display: flex;
|
|
282
|
+
flex-direction: column;
|
|
283
|
+
gap: 8px;
|
|
284
|
+
}
|
|
285
|
+
.clado-agent-question.answered {
|
|
286
|
+
border-color: var(--clado-ui-edge);
|
|
287
|
+
background: color-mix(in srgb, var(--clado-ui-well) 70%, transparent);
|
|
288
|
+
}
|
|
289
|
+
.clado-agent-question-badge {
|
|
290
|
+
font-size: 11px;
|
|
291
|
+
font-weight: 650;
|
|
292
|
+
color: #b45309;
|
|
293
|
+
}
|
|
294
|
+
[data-theme="dark"] .clado-agent-question-badge {
|
|
295
|
+
color: #fbbf24;
|
|
296
|
+
}
|
|
297
|
+
.clado-agent-question.answered .clado-agent-question-badge {
|
|
298
|
+
color: var(--clado-ui-muted);
|
|
299
|
+
}
|
|
300
|
+
.clado-agent-question-text {
|
|
301
|
+
font-size: 12.5px;
|
|
302
|
+
line-height: 1.5;
|
|
303
|
+
color: var(--clado-ui-text);
|
|
304
|
+
font-weight: 500;
|
|
305
|
+
}
|
|
306
|
+
.clado-agent-question-options {
|
|
307
|
+
display: flex;
|
|
308
|
+
flex-direction: column;
|
|
309
|
+
gap: 5px;
|
|
310
|
+
}
|
|
311
|
+
.clado-agent-option-btn {
|
|
312
|
+
border: 1px solid var(--clado-ui-edge);
|
|
313
|
+
border-radius: 9px;
|
|
314
|
+
background: var(--clado-ui-well);
|
|
315
|
+
color: var(--clado-ui-text);
|
|
316
|
+
padding: 7px 10px;
|
|
317
|
+
text-align: left;
|
|
318
|
+
cursor: pointer;
|
|
319
|
+
font: inherit;
|
|
320
|
+
display: flex;
|
|
321
|
+
flex-direction: column;
|
|
322
|
+
gap: 2px;
|
|
323
|
+
transition: border-color 140ms ease, background 140ms ease;
|
|
324
|
+
}
|
|
325
|
+
.clado-agent-option-btn:hover:not(:disabled) {
|
|
326
|
+
border-color: #d97706;
|
|
327
|
+
background: rgb(217 119 6 / .08);
|
|
328
|
+
}
|
|
329
|
+
.clado-agent-option-btn:disabled {
|
|
330
|
+
opacity: .55;
|
|
331
|
+
cursor: default;
|
|
332
|
+
}
|
|
333
|
+
.clado-agent-option-label {
|
|
334
|
+
font-size: 12px;
|
|
335
|
+
font-weight: 600;
|
|
336
|
+
}
|
|
337
|
+
.clado-agent-option-btn small {
|
|
338
|
+
font-size: 11px;
|
|
339
|
+
color: var(--clado-ui-muted);
|
|
340
|
+
}
|
|
341
|
+
.clado-agent-question-custom {
|
|
342
|
+
display: flex;
|
|
343
|
+
gap: 5px;
|
|
344
|
+
}
|
|
345
|
+
.clado-agent-question-custom input {
|
|
346
|
+
flex: 1;
|
|
347
|
+
min-width: 0;
|
|
348
|
+
padding: 5px 8px;
|
|
349
|
+
border: 1px solid var(--clado-ui-edge);
|
|
350
|
+
border-radius: 8px;
|
|
351
|
+
background: var(--clado-ui-well);
|
|
352
|
+
color: var(--clado-ui-text);
|
|
353
|
+
font: inherit;
|
|
354
|
+
font-size: 11.5px;
|
|
355
|
+
}
|
|
356
|
+
.clado-agent-option-submit {
|
|
357
|
+
min-height: 28px;
|
|
358
|
+
padding: 2px 10px;
|
|
359
|
+
font-size: 11.5px;
|
|
360
|
+
}
|
|
361
|
+
.clado-agent-question-answered {
|
|
362
|
+
font-size: 11.5px;
|
|
363
|
+
color: var(--clado-ui-accent);
|
|
364
|
+
font-weight: 550;
|
|
365
|
+
}
|
|
75
366
|
.clado-agent-status {
|
|
76
367
|
margin: 0 14px;
|
|
77
368
|
padding-block: 4px;
|
|
@@ -101,5 +392,5 @@
|
|
|
101
392
|
}
|
|
102
393
|
.clado-agent-panel textarea:focus-visible { outline: 2px solid var(--clado-ui-accent); outline-offset: 1px; }
|
|
103
394
|
@media (max-width: 460px) {
|
|
104
|
-
.clado-agent-panel { width: min(
|
|
395
|
+
.clado-agent-panel { width: min(410px, calc(100vw - 20px)); }
|
|
105
396
|
}
|
package/skills/clado/SKILL.md
CHANGED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP 执行器插件注册、任务包组装与运行记录(.clado/runs/)。
|
|
3
|
+
*
|
|
4
|
+
* 将外部 Coding Agent(ZCode / Claude Code / Codex / 自定义插件执行器)统一建模为
|
|
5
|
+
* 可发现、可派单的 ACP Executor,用户在 Clado 面板内一键外包开发并实时等待结果。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { randomUUID } from 'node:crypto';
|
|
9
|
+
import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { z } from 'zod/v4';
|
|
12
|
+
import { readDocument, scanDirectory, workspacePath } from '../workspace/documents.js';
|
|
13
|
+
|
|
14
|
+
export const executorSchema = z.strictObject({
|
|
15
|
+
id: z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/),
|
|
16
|
+
name: z.string().trim().min(1).max(80),
|
|
17
|
+
protocol: z.literal('acp').default('acp'),
|
|
18
|
+
command: z.string().trim().min(1).max(2048),
|
|
19
|
+
args: z.array(z.string().max(2048)).max(32).default([]),
|
|
20
|
+
env: z.record(z.string(), z.string().max(2048)).default({}),
|
|
21
|
+
capabilities: z.array(z.string().min(1).max(64)).max(16).default(['code.write', 'test.run']),
|
|
22
|
+
description: z.string().max(400).optional(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 发现工作区可用的全部 ACP 执行器(内置/用户配置 + 插件包声明的 contributes.executors)。
|
|
27
|
+
*/
|
|
28
|
+
export function discoverExecutors({ stateDir, settings = {}, pluginDescriptors = [] } = {}) {
|
|
29
|
+
const result = [];
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
const push = item => {
|
|
32
|
+
if (!item || seen.has(item.id)) return;
|
|
33
|
+
seen.add(item.id);
|
|
34
|
+
result.push(item);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (settings.command) {
|
|
38
|
+
push({
|
|
39
|
+
id: 'acp.default',
|
|
40
|
+
name: settings.name || '默认 ACP 执行器',
|
|
41
|
+
protocol: 'acp',
|
|
42
|
+
command: settings.command,
|
|
43
|
+
args: Array.isArray(settings.args) ? settings.args : [],
|
|
44
|
+
env: settings.env && typeof settings.env === 'object' ? settings.env : {},
|
|
45
|
+
capabilities: ['code.write', 'test.run'],
|
|
46
|
+
description: '来自「灵感」设置的默认外部 ACP Coding Agent',
|
|
47
|
+
source: 'settings',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const raw of Array.isArray(settings.executors) ? settings.executors : []) {
|
|
52
|
+
const parsed = executorSchema.safeParse(raw);
|
|
53
|
+
if (!parsed.success) continue;
|
|
54
|
+
push({ ...parsed.data, source: 'settings' });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 从已加载插件或 .clado/plugins/*/clado-plugin.json 发现声明式执行器
|
|
58
|
+
for (const plugin of pluginDescriptors) {
|
|
59
|
+
for (const raw of Array.isArray(plugin?.executors) ? plugin.executors : []) {
|
|
60
|
+
const parsed = executorSchema.safeParse(raw);
|
|
61
|
+
if (!parsed.success) continue;
|
|
62
|
+
push({ ...parsed.data, id: plugin.id + '/' + parsed.data.id, pluginId: plugin.id, source: 'plugin' });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (stateDir) {
|
|
67
|
+
const dir = join(stateDir, 'plugins');
|
|
68
|
+
if (existsSync(dir) && lstatSync(dir).isDirectory()) {
|
|
69
|
+
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
70
|
+
if (!entry.isDirectory() || entry.name.startsWith('.')) continue;
|
|
71
|
+
const manifestPath = join(dir, entry.name, 'clado-plugin.json');
|
|
72
|
+
if (!existsSync(manifestPath)) continue;
|
|
73
|
+
try {
|
|
74
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
75
|
+
const declared = manifest?.contributes?.executors;
|
|
76
|
+
if (!Array.isArray(declared) || !manifest?.id) continue;
|
|
77
|
+
for (const raw of declared) {
|
|
78
|
+
const parsed = executorSchema.safeParse(raw);
|
|
79
|
+
if (!parsed.success) continue;
|
|
80
|
+
push({
|
|
81
|
+
...parsed.data,
|
|
82
|
+
id: manifest.id + '/' + parsed.data.id,
|
|
83
|
+
pluginId: manifest.id,
|
|
84
|
+
source: 'plugin',
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
} catch {}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 面向前端的安全摘要(不向浏览器泄露 command/env 敏感细节)。
|
|
97
|
+
*/
|
|
98
|
+
export function publicExecutorList(executors) {
|
|
99
|
+
return executors.map(({ id, name, protocol, capabilities, description, source, pluginId }) => ({
|
|
100
|
+
id, name, protocol, capabilities, description: description || '', source, ...(pluginId ? { pluginId } : {}),
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 基于当前画布文档与选区,组装发给外部 ACP Coding Agent 的 Executable Spec 任务包。
|
|
106
|
+
*/
|
|
107
|
+
export function buildDispatchPrompt({ workspace, documentRoot, file, selection = [], instruction = '', mcpName = '' }) {
|
|
108
|
+
const blocks = [];
|
|
109
|
+
let specExcerpt = '';
|
|
110
|
+
let relatedTests = [];
|
|
111
|
+
|
|
112
|
+
if (documentRoot && file) {
|
|
113
|
+
try {
|
|
114
|
+
const fullPath = workspacePath(documentRoot, file);
|
|
115
|
+
const item = readDocument(fullPath);
|
|
116
|
+
specExcerpt = item.source.length > 24000
|
|
117
|
+
? item.source.slice(0, 24000) + '\n\n<!-- spec truncated; use Clado MCP to read full document -->'
|
|
118
|
+
: item.source;
|
|
119
|
+
} catch {}
|
|
120
|
+
try {
|
|
121
|
+
const { documents } = scanDirectory(documentRoot);
|
|
122
|
+
relatedTests = documents
|
|
123
|
+
.filter(d => d.file !== file && /test|用例|qa/i.test(d.file + ' ' + d.title))
|
|
124
|
+
.slice(0, 5)
|
|
125
|
+
.map(d => `${d.file}(${d.title})`);
|
|
126
|
+
} catch {}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
blocks.push({
|
|
130
|
+
type: 'text',
|
|
131
|
+
text: [
|
|
132
|
+
'你是通过 Clado ACP 执行器插件被派发的外部开发执行器(Coding Agent)。',
|
|
133
|
+
'你的任务是严格依据 Clado 画布中已拍板的设计规格与测试用例在本地仓库完成代码实现与测试验证。',
|
|
134
|
+
mcpName ? `执行期间可通过已连接的 ${mcpName} MCP 读取更多画布文档或更新实现备注(workspace: ${workspace})。` : '',
|
|
135
|
+
'完成后请给出简明实现总结:改了哪些文件、跑了哪些测试、是否有偏离设计之处。',
|
|
136
|
+
].filter(Boolean).join('\n'),
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
blocks.push({
|
|
140
|
+
type: 'text',
|
|
141
|
+
text: JSON.stringify({
|
|
142
|
+
workspace,
|
|
143
|
+
specFile: file || '',
|
|
144
|
+
selection,
|
|
145
|
+
relatedTestDocs: relatedTests,
|
|
146
|
+
}),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
if (specExcerpt) {
|
|
150
|
+
blocks.push({
|
|
151
|
+
type: 'text',
|
|
152
|
+
text: `以下为当前画布规格全文(${file}):\n\n${specExcerpt}`,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
blocks.push({
|
|
157
|
+
type: 'text',
|
|
158
|
+
text: '用户派发指令:\n' + (instruction.trim() || '请严格按上述 Clado 设计规格完成代码实现与测试验证。'),
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
return blocks;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* ── 轻量运行记录(.clado/runs/<runId>.json) ─────────────────── */
|
|
165
|
+
|
|
166
|
+
function runsDir(stateDir) {
|
|
167
|
+
const dir = join(stateDir, 'runs');
|
|
168
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
169
|
+
return dir;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function createRunRecord(stateDir, record) {
|
|
173
|
+
if (!stateDir) return { id: randomUUID(), ...record, createdAt: new Date().toISOString() };
|
|
174
|
+
const id = record.id || randomUUID();
|
|
175
|
+
const payload = {
|
|
176
|
+
id,
|
|
177
|
+
kind: record.kind || 'builtin',
|
|
178
|
+
mode: record.mode || 'design',
|
|
179
|
+
executorId: record.executorId || null,
|
|
180
|
+
file: record.file || '',
|
|
181
|
+
instruction: String(record.instruction || '').slice(0, 400),
|
|
182
|
+
status: 'running',
|
|
183
|
+
createdAt: new Date().toISOString(),
|
|
184
|
+
updatedAt: new Date().toISOString(),
|
|
185
|
+
summary: '',
|
|
186
|
+
touchedFiles: [],
|
|
187
|
+
};
|
|
188
|
+
try { writeFileSync(join(runsDir(stateDir), id + '.json'), JSON.stringify(payload, null, 2) + '\n'); } catch {}
|
|
189
|
+
return payload;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function updateRunRecord(stateDir, run, patch = {}) {
|
|
193
|
+
if (!run) return null;
|
|
194
|
+
const next = { ...run, ...patch, updatedAt: new Date().toISOString() };
|
|
195
|
+
if (stateDir && next.id) {
|
|
196
|
+
try { writeFileSync(join(runsDir(stateDir), next.id + '.json'), JSON.stringify(next, null, 2) + '\n'); } catch {}
|
|
197
|
+
}
|
|
198
|
+
return next;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function listRunRecords(stateDir, limit = 12) {
|
|
202
|
+
if (!stateDir) return [];
|
|
203
|
+
const dir = join(stateDir, 'runs');
|
|
204
|
+
if (!existsSync(dir) || !lstatSync(dir).isDirectory()) return [];
|
|
205
|
+
const items = [];
|
|
206
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
207
|
+
if (!entry.isFile() || !entry.name.endsWith('.json')) continue;
|
|
208
|
+
try { items.push(JSON.parse(readFileSync(join(dir, entry.name), 'utf8'))); } catch {}
|
|
209
|
+
}
|
|
210
|
+
return items
|
|
211
|
+
.sort((a, b) => String(b.createdAt || '').localeCompare(String(a.createdAt || '')))
|
|
212
|
+
.slice(0, limit);
|
|
213
|
+
}
|