cladogram 0.5.5-beta.8 → 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/docs/release.md +7 -0
- package/package.json +1 -1
- package/plugins/agent/index.js +615 -41
- package/plugins/agent/style.css +100 -0
- package/plugins/directory/index.js +25 -3
- 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/runtime.js +50 -2
- package/src/agent/skills.js +190 -0
- package/src/server/agent.js +177 -8
- package/src/server/assets/library.js +46 -0
- package/src/server/plugins.js +61 -9
- package/src/server/workspace-hub.js +28 -1
- package/src/server/workspace.js +28 -0
package/plugins/agent/style.css
CHANGED
|
@@ -1529,3 +1529,103 @@
|
|
|
1529
1529
|
border-color: var(--clado-ui-brand);
|
|
1530
1530
|
}
|
|
1531
1531
|
|
|
1532
|
+
/* `/` 斜杠命令自动补全浮层 + MCP/Skills/Commands 生态卡片 */
|
|
1533
|
+
.clado-slash-menu {
|
|
1534
|
+
position: fixed;
|
|
1535
|
+
z-index: 96;
|
|
1536
|
+
min-width: 240px;
|
|
1537
|
+
max-width: min(360px, calc(100vw - 20px));
|
|
1538
|
+
max-height: 260px;
|
|
1539
|
+
overflow-y: auto;
|
|
1540
|
+
padding: 6px;
|
|
1541
|
+
border-radius: 16px;
|
|
1542
|
+
display: flex;
|
|
1543
|
+
flex-direction: column;
|
|
1544
|
+
gap: 2px;
|
|
1545
|
+
background: var(--clado-agent-popover);
|
|
1546
|
+
backdrop-filter: blur(24px) saturate(190%);
|
|
1547
|
+
-webkit-backdrop-filter: blur(24px) saturate(190%);
|
|
1548
|
+
border: 1px solid var(--clado-agent-outline);
|
|
1549
|
+
box-shadow: var(--clado-agent-shadow);
|
|
1550
|
+
font: 12.5px/1.35 system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
|
|
1551
|
+
color: var(--clado-ui-text);
|
|
1552
|
+
opacity: 0;
|
|
1553
|
+
pointer-events: none;
|
|
1554
|
+
transform: translateY(6px) scale(0.96);
|
|
1555
|
+
transform-origin: bottom left;
|
|
1556
|
+
transition: opacity 150ms var(--clado-ease-spring), transform 170ms var(--clado-ease-spring);
|
|
1557
|
+
}
|
|
1558
|
+
.clado-slash-menu.open {
|
|
1559
|
+
opacity: 1;
|
|
1560
|
+
pointer-events: auto;
|
|
1561
|
+
transform: translateY(0) scale(1);
|
|
1562
|
+
}
|
|
1563
|
+
.clado-slash-item {
|
|
1564
|
+
appearance: none;
|
|
1565
|
+
border: 1px solid transparent;
|
|
1566
|
+
background: transparent;
|
|
1567
|
+
color: var(--clado-ui-text);
|
|
1568
|
+
font: inherit;
|
|
1569
|
+
padding: 7px 9px;
|
|
1570
|
+
border-radius: 10px;
|
|
1571
|
+
text-align: left;
|
|
1572
|
+
cursor: pointer;
|
|
1573
|
+
display: flex;
|
|
1574
|
+
flex-direction: column;
|
|
1575
|
+
gap: 2px;
|
|
1576
|
+
}
|
|
1577
|
+
.clado-slash-item:hover,
|
|
1578
|
+
.clado-slash-item.active {
|
|
1579
|
+
background: var(--clado-agent-active);
|
|
1580
|
+
border-color: var(--clado-agent-outline);
|
|
1581
|
+
}
|
|
1582
|
+
.clado-slash-item-head {
|
|
1583
|
+
display: flex;
|
|
1584
|
+
align-items: center;
|
|
1585
|
+
justify-content: space-between;
|
|
1586
|
+
gap: 8px;
|
|
1587
|
+
}
|
|
1588
|
+
.clado-slash-item-name {
|
|
1589
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
1590
|
+
font-weight: 650;
|
|
1591
|
+
color: var(--clado-ui-brand);
|
|
1592
|
+
}
|
|
1593
|
+
.clado-slash-item-scope {
|
|
1594
|
+
font-size: 10.5px;
|
|
1595
|
+
color: var(--clado-ui-subtle);
|
|
1596
|
+
}
|
|
1597
|
+
.clado-slash-item-desc {
|
|
1598
|
+
font-size: 11.5px;
|
|
1599
|
+
color: var(--clado-ui-muted);
|
|
1600
|
+
overflow: hidden;
|
|
1601
|
+
text-overflow: ellipsis;
|
|
1602
|
+
white-space: nowrap;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
.clado-eco-card {
|
|
1606
|
+
padding: 10px 11px;
|
|
1607
|
+
border-radius: 13px;
|
|
1608
|
+
border: 1px solid var(--clado-agent-well-border);
|
|
1609
|
+
background: var(--clado-agent-well);
|
|
1610
|
+
display: flex;
|
|
1611
|
+
flex-direction: column;
|
|
1612
|
+
gap: 6px;
|
|
1613
|
+
}
|
|
1614
|
+
.clado-eco-row {
|
|
1615
|
+
display: flex;
|
|
1616
|
+
align-items: center;
|
|
1617
|
+
justify-content: space-between;
|
|
1618
|
+
gap: 8px;
|
|
1619
|
+
}
|
|
1620
|
+
.clado-eco-badge {
|
|
1621
|
+
display: inline-flex;
|
|
1622
|
+
align-items: center;
|
|
1623
|
+
padding: 1px 7px;
|
|
1624
|
+
border-radius: 999px;
|
|
1625
|
+
font-size: 10.5px;
|
|
1626
|
+
font-weight: 600;
|
|
1627
|
+
background: rgba(37, 99, 235, 0.1);
|
|
1628
|
+
color: var(--clado-ui-brand);
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
function renderTree(container, documents, { selected='', query='', onOpen=()=>{}, folders=new Set() } = {}) {
|
|
2
|
+
function renderTree(container, documents, { selected='', query='', onOpen=()=>{}, onRename=null, onDelete=null, folders=new Set() } = {}) {
|
|
3
3
|
const needle=query.trim().toLocaleLowerCase(), root={folders:new Map(),files:[]};
|
|
4
4
|
for(const doc of documents) {
|
|
5
5
|
if(needle && !(doc.title+' '+doc.file).toLocaleLowerCase().includes(needle))continue;
|
|
@@ -15,9 +15,26 @@
|
|
|
15
15
|
const children=document.createElement('div');children.className='tree-children';details.append(children);render(folder,children);parent.append(details);
|
|
16
16
|
}
|
|
17
17
|
for(const doc of node.files) {
|
|
18
|
+
const row=document.createElement('div');row.className='document-row';
|
|
18
19
|
const button=document.createElement('button');button.className='clado-ui-button document-button';button.dataset.file=doc.file;if(doc.file===selected)button.setAttribute('aria-current','page');
|
|
19
20
|
const strong=document.createElement('strong');strong.textContent=doc.title;
|
|
20
|
-
const small=document.createElement('small');small.textContent=doc.file.split('/').pop();button.append(strong,small);button.onclick=()=>onOpen(doc.file);
|
|
21
|
+
const small=document.createElement('small');small.textContent=doc.file.split('/').pop();button.append(strong,small);button.onclick=()=>onOpen(doc.file);
|
|
22
|
+
row.append(button);
|
|
23
|
+
if (onRename || onDelete) {
|
|
24
|
+
const ops=document.createElement('span');ops.className='document-row-ops';
|
|
25
|
+
if (onRename) {
|
|
26
|
+
const ren=document.createElement('button');ren.type='button';ren.className='doc-op-btn';ren.title='重命名画布';ren.setAttribute('aria-label','重命名画布 '+doc.file);ren.textContent='✎';
|
|
27
|
+
ren.onclick=ev=>{ev.stopPropagation();onRename(doc);};
|
|
28
|
+
ops.append(ren);
|
|
29
|
+
}
|
|
30
|
+
if (onDelete) {
|
|
31
|
+
const del=document.createElement('button');del.type='button';del.className='doc-op-btn danger';del.title='删除画布';del.setAttribute('aria-label','删除画布 '+doc.file);del.textContent='×';
|
|
32
|
+
del.onclick=ev=>{ev.stopPropagation();onDelete(doc);};
|
|
33
|
+
ops.append(del);
|
|
34
|
+
}
|
|
35
|
+
row.append(ops);
|
|
36
|
+
}
|
|
37
|
+
parent.append(row);
|
|
21
38
|
}
|
|
22
39
|
}
|
|
23
40
|
render(root,container);
|
|
@@ -86,7 +103,12 @@
|
|
|
86
103
|
$('#fileCount').textContent = index.documents.length;
|
|
87
104
|
$('.directory-heading strong').textContent = index.root || 'Markdown';
|
|
88
105
|
renderTree($('#documentList'), index.documents, {
|
|
89
|
-
selected,
|
|
106
|
+
selected,
|
|
107
|
+
query,
|
|
108
|
+
folders,
|
|
109
|
+
onOpen: file => { setOpen(false); actions.open(file); },
|
|
110
|
+
onRename: actions.renameCanvas ? doc => actions.renameCanvas(doc) : null,
|
|
111
|
+
onDelete: actions.deleteCanvas ? doc => actions.deleteCanvas(doc) : null,
|
|
90
112
|
});
|
|
91
113
|
$('#skippedButton').hidden = !index.skipped.length;
|
|
92
114
|
$('#skippedButton').textContent = index.skipped.length + ' 份文档未收录 · 查看原因';
|
|
@@ -164,3 +164,50 @@
|
|
|
164
164
|
border-radius: 24px;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
+
|
|
168
|
+
.document-row {
|
|
169
|
+
display: flex;
|
|
170
|
+
align-items: center;
|
|
171
|
+
gap: 2px;
|
|
172
|
+
position: relative;
|
|
173
|
+
}
|
|
174
|
+
.document-row > .document-button {
|
|
175
|
+
flex: 1 1 auto;
|
|
176
|
+
min-width: 0;
|
|
177
|
+
}
|
|
178
|
+
.document-row-ops {
|
|
179
|
+
display: inline-flex;
|
|
180
|
+
align-items: center;
|
|
181
|
+
gap: 2px;
|
|
182
|
+
flex: 0 0 auto;
|
|
183
|
+
opacity: 0.42;
|
|
184
|
+
transition: opacity 140ms ease;
|
|
185
|
+
}
|
|
186
|
+
.document-row:hover .document-row-ops,
|
|
187
|
+
.document-row:focus-within .document-row-ops {
|
|
188
|
+
opacity: 1;
|
|
189
|
+
}
|
|
190
|
+
.doc-op-btn {
|
|
191
|
+
appearance: none;
|
|
192
|
+
border: 0;
|
|
193
|
+
background: transparent;
|
|
194
|
+
color: var(--clado-ui-muted);
|
|
195
|
+
width: 24px;
|
|
196
|
+
height: 24px;
|
|
197
|
+
border-radius: 7px;
|
|
198
|
+
font: inherit;
|
|
199
|
+
font-size: 12px;
|
|
200
|
+
cursor: pointer;
|
|
201
|
+
display: inline-flex;
|
|
202
|
+
align-items: center;
|
|
203
|
+
justify-content: center;
|
|
204
|
+
}
|
|
205
|
+
.doc-op-btn:hover {
|
|
206
|
+
background: var(--clado-ui-hover);
|
|
207
|
+
color: var(--clado-ui-text);
|
|
208
|
+
}
|
|
209
|
+
.doc-op-btn.danger:hover {
|
|
210
|
+
color: #e11d48;
|
|
211
|
+
background: rgba(225, 29, 72, 0.1);
|
|
212
|
+
}
|
|
213
|
+
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clado 斜杠命令体系(Slash Commands, `/xxx`):
|
|
3
|
+
* - 内置 4 条高频命令(/arch、/test、/diff、/dispatch),统一收编原先写死的工作流入口;
|
|
4
|
+
* - 支持工作区(.clado/commands/<name>.md)、全局(~/.clado/commands/<name>.md)与插件(<pluginDir>/commands/<name>.md)自定义命令;
|
|
5
|
+
* - 支持 YAML Frontmatter(description / skill / workflow / persona)与 `{{args}}` 参数插值。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import YAML from 'yaml';
|
|
11
|
+
import { userTemplatePaths } from '../skill/templates.js';
|
|
12
|
+
|
|
13
|
+
const CMD_RE = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,47}$/;
|
|
14
|
+
|
|
15
|
+
export const BUILTIN_COMMANDS = Object.freeze([
|
|
16
|
+
Object.freeze({
|
|
17
|
+
name: 'arch',
|
|
18
|
+
description: '读取源码并在画布中梳理系统架构与调用链',
|
|
19
|
+
workflow: 'design',
|
|
20
|
+
persona: 'architect',
|
|
21
|
+
prompt: '请先用代码探针核对真实源码结构,再用画布工具梳理或更新架构设计与调用链:{{args}}',
|
|
22
|
+
scope: 'builtin',
|
|
23
|
+
}),
|
|
24
|
+
Object.freeze({
|
|
25
|
+
name: 'test',
|
|
26
|
+
description: '基于当前画布或源码生成脑图测试用例',
|
|
27
|
+
workflow: 'qa',
|
|
28
|
+
persona: 'qa',
|
|
29
|
+
prompt: '请阅读当前画布与相关源码,按 test-cases 模板生成覆盖正常流、边界与异常流的脑图测试用例:{{args}}',
|
|
30
|
+
scope: 'builtin',
|
|
31
|
+
}),
|
|
32
|
+
Object.freeze({
|
|
33
|
+
name: 'diff',
|
|
34
|
+
description: '读取本地 Git Diff,对照画布设计逐项验收与归档',
|
|
35
|
+
workflow: 'audit',
|
|
36
|
+
persona: 'auditor',
|
|
37
|
+
prompt: '请调用 probe_git_diff 读取本地真实代码变更,对照画布契约逐项验收并指出遗漏或偏离项:{{args}}',
|
|
38
|
+
scope: 'builtin',
|
|
39
|
+
}),
|
|
40
|
+
Object.freeze({
|
|
41
|
+
name: 'dispatch',
|
|
42
|
+
description: '打包当前架构规格并派发给外部 ACP 执行器落地编码',
|
|
43
|
+
workflow: 'dispatch',
|
|
44
|
+
persona: 'coder',
|
|
45
|
+
prompt: '{{args}}',
|
|
46
|
+
scope: 'builtin',
|
|
47
|
+
}),
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
function globalCommandsDir() {
|
|
51
|
+
return join(userTemplatePaths().state, 'commands');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function workspaceCommandsDir(workspace) {
|
|
55
|
+
return workspace ? join(workspace, '.clado', 'commands') : '';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function parseCommandMarkdown(raw, fallbackName = '') {
|
|
59
|
+
const text = String(raw || '').replace(/\r\n/g, '\n');
|
|
60
|
+
let meta = {};
|
|
61
|
+
let body = text.trim();
|
|
62
|
+
|
|
63
|
+
const fm = text.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
64
|
+
if (fm) {
|
|
65
|
+
try {
|
|
66
|
+
const parsed = YAML.parse(fm[1]);
|
|
67
|
+
if (parsed && typeof parsed === 'object') meta = parsed;
|
|
68
|
+
} catch {}
|
|
69
|
+
body = fm[2].trim();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
name: typeof meta.name === 'string' && CMD_RE.test(meta.name.trim()) ? meta.name.trim() : fallbackName,
|
|
74
|
+
description: typeof meta.description === 'string' && meta.description.trim()
|
|
75
|
+
? meta.description.trim()
|
|
76
|
+
: (body.split('\n')[0] || '自定义斜杠命令').slice(0, 100),
|
|
77
|
+
skill: typeof meta.skill === 'string' ? meta.skill.trim() : '',
|
|
78
|
+
workflow: typeof meta.workflow === 'string' ? meta.workflow.trim() : '',
|
|
79
|
+
persona: typeof meta.persona === 'string' ? meta.persona.trim() : '',
|
|
80
|
+
prompt: body,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function serializeCommandMarkdown({ description = '', skill = '', workflow = '', persona = '', prompt = '' }) {
|
|
85
|
+
const fm = {};
|
|
86
|
+
if (description) fm.description = String(description).trim();
|
|
87
|
+
if (skill) fm.skill = String(skill).trim();
|
|
88
|
+
if (workflow) fm.workflow = String(workflow).trim();
|
|
89
|
+
if (persona) fm.persona = String(persona).trim();
|
|
90
|
+
const header = Object.keys(fm).length ? `---\n${YAML.stringify(fm).trim()}\n---\n\n` : '';
|
|
91
|
+
return `${header}${String(prompt || '').trim()}\n`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function scanCommandsInDir(dir, scope, pluginId = '') {
|
|
95
|
+
if (!dir || !existsSync(dir)) return [];
|
|
96
|
+
const items = [];
|
|
97
|
+
let entries = [];
|
|
98
|
+
try {
|
|
99
|
+
entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
100
|
+
} catch {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
if (entry.name.startsWith('.') || !/\.md$/i.test(entry.name)) continue;
|
|
105
|
+
const slug = entry.name.replace(/\.md$/i, '');
|
|
106
|
+
if (!CMD_RE.test(slug)) continue;
|
|
107
|
+
const full = join(dir, entry.name);
|
|
108
|
+
try {
|
|
109
|
+
const st = lstatSync(full);
|
|
110
|
+
if (!st.isFile() || st.isSymbolicLink()) continue;
|
|
111
|
+
const parsed = parseCommandMarkdown(readFileSync(full, 'utf8'), slug);
|
|
112
|
+
items.push({
|
|
113
|
+
...parsed,
|
|
114
|
+
name: parsed.name || slug,
|
|
115
|
+
scope,
|
|
116
|
+
...(pluginId ? { pluginId } : {}),
|
|
117
|
+
});
|
|
118
|
+
} catch {}
|
|
119
|
+
}
|
|
120
|
+
return items;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function listCommands(workspace, { pluginDirs = [] } = {}) {
|
|
124
|
+
const merged = new Map();
|
|
125
|
+
for (const cmd of BUILTIN_COMMANDS) merged.set(cmd.name, { ...cmd });
|
|
126
|
+
|
|
127
|
+
for (const p of pluginDirs || []) {
|
|
128
|
+
if (!p?.dir) continue;
|
|
129
|
+
for (const cmd of scanCommandsInDir(join(p.dir, 'commands'), 'plugin', p.id || '')) {
|
|
130
|
+
merged.set(cmd.name, cmd);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (const cmd of scanCommandsInDir(globalCommandsDir(), 'global')) {
|
|
134
|
+
merged.set(cmd.name, cmd);
|
|
135
|
+
}
|
|
136
|
+
for (const cmd of scanCommandsInDir(workspaceCommandsDir(workspace), 'workspace')) {
|
|
137
|
+
merged.set(cmd.name, cmd);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return [...merged.values()];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function saveCommand(workspace, { name, description = '', prompt = '', skill = '', workflow = '', persona = '', scope = 'workspace' } = {}) {
|
|
144
|
+
const cleanName = String(name || '')
|
|
145
|
+
.trim()
|
|
146
|
+
.replace(/^\/+/, '')
|
|
147
|
+
.toLowerCase();
|
|
148
|
+
if (!CMD_RE.test(cleanName)) {
|
|
149
|
+
throw new Error('命令名仅支持英文字母、数字、连字符或下划线(如 review、api-spec)。');
|
|
150
|
+
}
|
|
151
|
+
const cleanPrompt = String(prompt || '').trim();
|
|
152
|
+
if (!cleanPrompt) throw new Error('命令提示词模板不能为空。');
|
|
153
|
+
|
|
154
|
+
const baseDir = scope === 'global' || !workspace ? globalCommandsDir() : workspaceCommandsDir(workspace);
|
|
155
|
+
mkdirSync(baseDir, { recursive: true, mode: 0o700 });
|
|
156
|
+
const filePath = join(baseDir, `${cleanName}.md`);
|
|
157
|
+
writeFileSync(filePath, serializeCommandMarkdown({ description, skill, workflow, persona, prompt: cleanPrompt }), 'utf8');
|
|
158
|
+
return {
|
|
159
|
+
name: cleanName,
|
|
160
|
+
description: String(description || cleanPrompt.slice(0, 80)).trim(),
|
|
161
|
+
skill: String(skill || '').trim(),
|
|
162
|
+
workflow: String(workflow || '').trim(),
|
|
163
|
+
persona: String(persona || '').trim(),
|
|
164
|
+
prompt: cleanPrompt,
|
|
165
|
+
scope: scope === 'global' || !workspace ? 'global' : 'workspace',
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function deleteCommand(workspace, { name, scope = 'workspace' } = {}) {
|
|
170
|
+
const cleanName = String(name || '').trim().replace(/^\/+/, '').toLowerCase();
|
|
171
|
+
if (!CMD_RE.test(cleanName)) return false;
|
|
172
|
+
const baseDir = scope === 'global' || !workspace ? globalCommandsDir() : workspaceCommandsDir(workspace);
|
|
173
|
+
const filePath = join(baseDir, `${cleanName}.md`);
|
|
174
|
+
if (!existsSync(filePath)) return false;
|
|
175
|
+
rmSync(filePath, { force: true });
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function expandSlashCommand(workspace, rawInput = '', { pluginDirs = [] } = {}) {
|
|
180
|
+
const text = String(rawInput || '').trim();
|
|
181
|
+
const m = text.match(/^\/([a-zA-Z0-9][a-zA-Z0-9_-]{0,47})(?:\s+([\s\S]*))?$/);
|
|
182
|
+
if (!m) return null;
|
|
183
|
+
|
|
184
|
+
const cmdName = m[1].toLowerCase();
|
|
185
|
+
const args = (m[2] || '').trim();
|
|
186
|
+
const cmd = listCommands(workspace, { pluginDirs }).find(c => c.name.toLowerCase() === cmdName);
|
|
187
|
+
if (!cmd) return null;
|
|
188
|
+
|
|
189
|
+
let expanded = cmd.prompt || '';
|
|
190
|
+
if (expanded.includes('{{args}}')) {
|
|
191
|
+
expanded = expanded.replace(/\{\{args\}\}/g, args || '(当前画布与项目上下文)');
|
|
192
|
+
} else if (args) {
|
|
193
|
+
expanded = expanded ? `${expanded}\n\n补充参数:${args}` : args;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
command: cmd,
|
|
198
|
+
args,
|
|
199
|
+
prompt: expanded.trim() || text,
|
|
200
|
+
workflow: cmd.workflow || '',
|
|
201
|
+
persona: cmd.persona || '',
|
|
202
|
+
skill: cmd.skill || '',
|
|
203
|
+
};
|
|
204
|
+
}
|
package/src/agent/context.js
CHANGED
|
@@ -62,16 +62,29 @@ function sanitizeConfig(raw = {}) {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
const rawPersonas = raw.personas && typeof raw.personas === 'object' ? raw.personas : {};
|
|
65
|
+
const builtinIds = new Set(PERSONA_TEMPLATES.map(t => t.id));
|
|
65
66
|
for (const tpl of PERSONA_TEMPLATES) {
|
|
66
67
|
const item = rawPersonas[tpl.id] && typeof rawPersonas[tpl.id] === 'object' ? rawPersonas[tpl.id] : {};
|
|
67
68
|
out.personas[tpl.id] = {
|
|
68
|
-
name: tpl.name,
|
|
69
|
+
name: typeof item.name === 'string' && item.name.trim() ? item.name.trim().slice(0, 40) : tpl.name,
|
|
69
70
|
pal: tpl.pal,
|
|
70
71
|
summary: tpl.summary,
|
|
71
72
|
prompt: typeof item.prompt === 'string' && item.prompt.trim() ? item.prompt.trim().slice(0, 4000) : tpl.prompt,
|
|
72
73
|
initContext: typeof item.initContext === 'string' ? item.initContext.trim().slice(0, 2000) : tpl.initContext,
|
|
73
74
|
};
|
|
74
75
|
}
|
|
76
|
+
for (const [k, v] of Object.entries(rawPersonas)) {
|
|
77
|
+
if (builtinIds.has(k) || !/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,31}$/.test(k)) continue;
|
|
78
|
+
if (!v || typeof v !== 'object') continue;
|
|
79
|
+
out.personas[k] = {
|
|
80
|
+
name: typeof v.name === 'string' && v.name.trim() ? v.name.trim().slice(0, 40) : k,
|
|
81
|
+
pal: typeof v.pal === 'string' ? v.pal : 'violet',
|
|
82
|
+
summary: typeof v.summary === 'string' ? v.summary.slice(0, 80) : (typeof v.prompt === 'string' ? v.prompt.trim().slice(0, 48) : '自定义人设'),
|
|
83
|
+
prompt: typeof v.prompt === 'string' ? v.prompt.trim().slice(0, 4000) : '',
|
|
84
|
+
initContext: typeof v.initContext === 'string' ? v.initContext.trim().slice(0, 2000) : '',
|
|
85
|
+
custom: true,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
75
88
|
return out;
|
|
76
89
|
}
|
|
77
90
|
|
|
@@ -103,8 +116,10 @@ export function saveAgentDebugConfig(stateDir, patch = {}, { scope = 'global' }
|
|
|
103
116
|
const nextPersonas = { ...current.personas };
|
|
104
117
|
if (patch.personas && typeof patch.personas === 'object') {
|
|
105
118
|
for (const [k, v] of Object.entries(patch.personas)) {
|
|
106
|
-
if (
|
|
107
|
-
|
|
119
|
+
if (v === null) {
|
|
120
|
+
delete nextPersonas[k];
|
|
121
|
+
} else if (v && typeof v === 'object' && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,31}$/.test(k)) {
|
|
122
|
+
nextPersonas[k] = { ...(nextPersonas[k] || {}), ...v };
|
|
108
123
|
}
|
|
109
124
|
}
|
|
110
125
|
}
|