evolclaw 3.1.5 → 3.1.7
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/CHANGELOG.md +68 -3
- package/dist/agents/claude-runner.js +69 -24
- package/dist/agents/kit-renderer.js +78 -321
- package/dist/agents/manifest-engine.js +243 -0
- package/dist/agents/message-renderer.js +112 -0
- package/dist/aun/aid/agentmd.js +10 -3
- package/dist/aun/msg/group.js +2 -2
- package/dist/channels/aun.js +154 -18
- package/dist/channels/dingtalk.js +1 -1
- package/dist/channels/feishu.js +31 -9
- package/dist/channels/qqbot.js +1 -1
- package/dist/channels/wechat.js +1 -1
- package/dist/channels/wecom.js +1 -1
- package/dist/cli/agent.js +10 -11
- package/dist/cli/bench.js +1 -5
- package/dist/cli/help.js +8 -0
- package/dist/cli/index.js +91 -128
- package/dist/cli/init.js +37 -21
- package/dist/cli/link-rules.js +1 -7
- package/dist/cli/model.js +231 -6
- package/dist/config-store.js +1 -22
- package/dist/core/command-handler.js +181 -48
- package/dist/core/evolagent.js +0 -18
- package/dist/core/message/im-renderer.js +9 -20
- package/dist/core/message/message-bridge.js +9 -10
- package/dist/core/message/message-processor.js +188 -39
- package/dist/core/message/message-queue.js +15 -1
- package/dist/core/relation/peer-identity.js +23 -11
- package/dist/core/trigger/parser.js +4 -4
- package/dist/core/trigger/scheduler.js +43 -13
- package/dist/index.js +102 -52
- package/dist/ipc.js +1 -1
- package/dist/utils/error-utils.js +6 -0
- package/dist/utils/process-introspect.js +7 -5
- package/kits/docs/INDEX.md +4 -8
- package/kits/docs/context-assembly.md +1 -0
- package/kits/docs/evolclaw/INDEX.md +43 -0
- package/kits/docs/evolclaw/group.md +13 -6
- package/kits/docs/evolclaw/model.md +51 -0
- package/kits/docs/evolclaw/msg.md +5 -0
- package/kits/docs/venues/group.md +13 -1
- package/kits/eck_manifest.json +9 -0
- package/kits/eck_message_manifest.json +14 -0
- package/kits/rules/06-channel.md +5 -1
- package/kits/templates/message-fragments/item.md +2 -0
- package/kits/templates/system-fragments/baseagent.md +7 -1
- package/kits/templates/system-fragments/channel.md +7 -5
- package/kits/templates/system-fragments/commands.md +19 -0
- package/kits/templates/system-fragments/session.md +12 -0
- package/kits/templates/system-fragments/venue.md +15 -0
- package/package.json +3 -3
|
@@ -1,123 +1,45 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import {
|
|
3
|
+
import { eckDebugDir } from '../paths.js';
|
|
4
4
|
import { logger } from '../utils/logger.js';
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
selfName: '当前 agent 的显示名',
|
|
15
|
-
hasPersona: '是否有 persona 内容',
|
|
16
|
-
hasWorkingMemory: '是否有 working memory',
|
|
17
|
-
peerId: '对端在该渠道的原生 ID',
|
|
18
|
-
peerKey: '对端跨渠道唯一标识(channel#urlEncode(peerId))',
|
|
19
|
-
peerName: '对端显示名',
|
|
20
|
-
peerRole: '对端角色(owner/admin/guest/anonymous)',
|
|
21
|
-
peerType: '对端类型(human/agent)',
|
|
22
|
-
groupId: '群组 ID(群聊时)',
|
|
23
|
-
chatType: '聊天类型(private=私聊 / group=群聊 / null=本地开发)',
|
|
24
|
-
channel: '渠道类型(aun/feishu/wechat/dingtalk/qqbot/wecom)',
|
|
25
|
-
venueUid: '场所唯一标识(预留)',
|
|
26
|
-
dispatch: '群分发模式(mention=被@才响应 / broadcast=所有消息都响应)',
|
|
27
|
-
clientType: '客户端类型(desktop/web/mobile)',
|
|
28
|
-
permissionMode: '权限模式(auto/bypass/request/edit/plan/noask/readonly)',
|
|
29
|
-
capabilities: '当前渠道支持的能力列表',
|
|
30
|
-
project: '当前项目目录名',
|
|
31
|
-
sessionId: 'evolclaw 会话 ID',
|
|
32
|
-
sessionName: '会话名称',
|
|
33
|
-
sessionKey: '会话路由键(channelType#urlEncode(channelId)#urlEncode(threadId))',
|
|
34
|
-
sessionCreatedAt: '会话创建时间(ISO)',
|
|
35
|
-
threadId: '话题 ID(多话题路由时)',
|
|
36
|
-
chatMode: '会话模式(interactive=同步交互 / proactive=主动推送)',
|
|
37
|
-
readonly: '是否只读模式',
|
|
38
|
-
baseAgent: 'base agent 规范值(claude/codex/gemini/hermes)',
|
|
39
|
-
baseAgentName: 'base agent 显示名',
|
|
40
|
-
baseAgentModel: 'base agent 使用的模型',
|
|
41
|
-
agentSessionId: 'base agent 会话 ID',
|
|
42
|
-
};
|
|
43
|
-
function buildPathMappings(vars) {
|
|
44
|
-
const pkgRoot = getPackageRoot();
|
|
45
|
-
const evolHome = String(vars['EVOLCLAW_HOME'] || resolveRoot());
|
|
46
|
-
const selfAid = vars['selfAid'] ? String(vars['selfAid']) : '';
|
|
47
|
-
const currentProject = vars['CURRENT_PROJECT'] ? String(vars['CURRENT_PROJECT']) : '';
|
|
48
|
-
const mappings = [
|
|
49
|
-
{ prefix: path.join(pkgRoot, 'kits', 'rules'), alias: '$KITS_RULES' },
|
|
50
|
-
{ prefix: path.join(pkgRoot, 'kits', 'templates', 'system-fragments'), alias: '$KITS_FRAGMENTS' },
|
|
51
|
-
{ prefix: path.join(pkgRoot, 'kits', 'templates'), alias: '$KITS_TEMPLATES' },
|
|
52
|
-
{ prefix: path.join(pkgRoot, 'kits', 'docs'), alias: '$KITS_DOCS' },
|
|
53
|
-
{ prefix: path.join(pkgRoot, 'kits'), alias: '$KITS' },
|
|
54
|
-
{ prefix: pkgRoot, alias: '$PACKAGE_ROOT' },
|
|
55
|
-
];
|
|
56
|
-
if (selfAid) {
|
|
57
|
-
mappings.push({ prefix: path.join(evolHome, 'agents', selfAid, 'personal'), alias: '$PERSONAL_DIR' });
|
|
58
|
-
mappings.push({ prefix: path.join(evolHome, 'agents', selfAid, 'relations'), alias: '$RELATIONS_DIR' });
|
|
59
|
-
mappings.push({ prefix: path.join(evolHome, 'agents', selfAid, 'venues'), alias: '$VENUES_DIR' });
|
|
60
|
-
mappings.push({ prefix: path.join(evolHome, 'agents', selfAid), alias: '$AGENT_DIR' });
|
|
61
|
-
}
|
|
62
|
-
mappings.push({ prefix: evolHome, alias: '$EVOLCLAW_HOME' });
|
|
63
|
-
if (currentProject) {
|
|
64
|
-
mappings.push({ prefix: currentProject, alias: '$CURRENT_PROJECT' });
|
|
65
|
-
}
|
|
66
|
-
// Sort by prefix length descending so longer (more specific) paths match first
|
|
67
|
-
mappings.sort((a, b) => b.prefix.length - a.prefix.length);
|
|
68
|
-
return mappings;
|
|
69
|
-
}
|
|
70
|
-
function shortenPath(filePath, mappings) {
|
|
71
|
-
const normalized = filePath.replace(/\\/g, '/');
|
|
72
|
-
for (const { prefix, alias } of mappings) {
|
|
73
|
-
const normalizedPrefix = prefix.replace(/\\/g, '/');
|
|
74
|
-
if (normalized.startsWith(normalizedPrefix)) {
|
|
75
|
-
const rest = normalized.slice(normalizedPrefix.length);
|
|
76
|
-
return alias + rest;
|
|
77
|
-
}
|
|
5
|
+
import { loadManifest, invalidateManifestCache, evaluateWhen, renderTemplate, resolvePathWithDiag, loadSectionFiles, buildPathMappings, shortenPath, } from './manifest-engine.js';
|
|
6
|
+
const MANIFEST_FILE = 'eck_manifest.json';
|
|
7
|
+
// ── Caches ──
|
|
8
|
+
const _sessionPathCache = new Map();
|
|
9
|
+
function getSessionCache(sessionId) {
|
|
10
|
+
let cache = _sessionPathCache.get(sessionId);
|
|
11
|
+
if (!cache) {
|
|
12
|
+
cache = new Map();
|
|
13
|
+
_sessionPathCache.set(sessionId, cache);
|
|
78
14
|
}
|
|
79
|
-
return
|
|
15
|
+
return cache;
|
|
80
16
|
}
|
|
81
|
-
// ── Cache ──
|
|
82
|
-
let _manifestCache = null;
|
|
83
|
-
const _sessionPathCache = new Map();
|
|
84
|
-
// ── Public API ──
|
|
85
17
|
export function loadKitManifest() {
|
|
86
|
-
|
|
87
|
-
logger.info(`[KitRenderer] Loaded manifest: ${
|
|
18
|
+
const sections = loadManifest(MANIFEST_FILE);
|
|
19
|
+
logger.info(`[KitRenderer] Loaded manifest: ${sections.length} sections`);
|
|
88
20
|
}
|
|
89
21
|
export function invalidateKitCache() {
|
|
90
|
-
|
|
22
|
+
invalidateManifestCache();
|
|
91
23
|
_sessionPathCache.clear();
|
|
92
24
|
}
|
|
93
25
|
export function invalidateSessionCache(sessionId) {
|
|
94
26
|
_sessionPathCache.delete(sessionId);
|
|
95
27
|
}
|
|
28
|
+
// ── Main render ──
|
|
96
29
|
export function renderKitSections(ctx) {
|
|
97
|
-
|
|
98
|
-
loadKitManifest();
|
|
99
|
-
const sections = _manifestCache;
|
|
30
|
+
const sections = loadManifest(MANIFEST_FILE);
|
|
100
31
|
const fileParts = [];
|
|
101
32
|
const fragmentParts = [];
|
|
102
33
|
const pathMappings = buildPathMappings(ctx.vars);
|
|
34
|
+
const sessionCache = getSessionCache(ctx.sessionId);
|
|
103
35
|
const diagnostics = [];
|
|
104
36
|
for (const section of sections) {
|
|
105
37
|
const rawPath = section.type === 'file' ? (section.file ?? '') : (section.path ?? '');
|
|
106
38
|
const diag = {
|
|
107
|
-
id: section.id,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
pattern: section.pattern,
|
|
112
|
-
needsInjection: section.needsInjection,
|
|
113
|
-
when: section.when,
|
|
114
|
-
enabled: section.enabled !== false,
|
|
115
|
-
whenPassed: false,
|
|
116
|
-
resolvedPath: null,
|
|
117
|
-
resolveStatus: 'no-path',
|
|
118
|
-
fileCount: 0,
|
|
119
|
-
used: false,
|
|
120
|
-
injected: false,
|
|
39
|
+
id: section.id, description: section.description, type: section.type, rawPath,
|
|
40
|
+
pattern: section.pattern, needsInjection: section.needsInjection, when: section.when,
|
|
41
|
+
enabled: section.enabled !== false, whenPassed: false, resolvedPath: null,
|
|
42
|
+
resolveStatus: 'no-path', fileCount: 0, used: false, injected: false,
|
|
121
43
|
};
|
|
122
44
|
if (section.enabled === false) {
|
|
123
45
|
diag.resolveStatus = 'skipped-disabled';
|
|
@@ -131,13 +53,13 @@ export function renderKitSections(ctx) {
|
|
|
131
53
|
continue;
|
|
132
54
|
}
|
|
133
55
|
if (rawPath) {
|
|
134
|
-
const
|
|
135
|
-
diag.resolvedPath =
|
|
136
|
-
diag.resolveStatus =
|
|
137
|
-
if (
|
|
138
|
-
diag.unresolvedTokens =
|
|
56
|
+
const r = resolvePathWithDiag(rawPath, ctx.vars);
|
|
57
|
+
diag.resolvedPath = r.resolved;
|
|
58
|
+
diag.resolveStatus = r.status;
|
|
59
|
+
if (r.unresolvedTokens.length > 0)
|
|
60
|
+
diag.unresolvedTokens = r.unresolvedTokens;
|
|
139
61
|
}
|
|
140
|
-
const files = loadSectionFiles(section, ctx);
|
|
62
|
+
const files = loadSectionFiles(section, ctx.vars, sessionCache);
|
|
141
63
|
diag.fileCount = files.length;
|
|
142
64
|
if (files.length === 0) {
|
|
143
65
|
diagnostics.push(diag);
|
|
@@ -186,215 +108,56 @@ export function cleanEckDebug() {
|
|
|
186
108
|
}
|
|
187
109
|
catch { /* dir doesn't exist yet */ }
|
|
188
110
|
}
|
|
189
|
-
// CHUNK_CONTINUE_2
|
|
190
|
-
// ── Manifest loading ──
|
|
191
|
-
function loadAndMergeManifest() {
|
|
192
|
-
const kitsPath = path.join(kitsDir(), 'eck_manifest.json');
|
|
193
|
-
const eckPath = path.join(resolveRoot(), 'eck', 'eck_manifest.json');
|
|
194
|
-
let base;
|
|
195
|
-
try {
|
|
196
|
-
base = JSON.parse(fs.readFileSync(kitsPath, 'utf-8'));
|
|
197
|
-
}
|
|
198
|
-
catch (err) {
|
|
199
|
-
logger.error(`[KitRenderer] Failed to load kits/eck_manifest.json: ${err}`);
|
|
200
|
-
return [];
|
|
201
|
-
}
|
|
202
|
-
if (!fs.existsSync(eckPath)) {
|
|
203
|
-
return sortSections(base.sections);
|
|
204
|
-
}
|
|
205
|
-
try {
|
|
206
|
-
const override = JSON.parse(fs.readFileSync(eckPath, 'utf-8'));
|
|
207
|
-
if (override.mode === 'replace') {
|
|
208
|
-
return sortSections(override.sections);
|
|
209
|
-
}
|
|
210
|
-
const merged = new Map();
|
|
211
|
-
for (const s of base.sections)
|
|
212
|
-
merged.set(s.id, { ...s });
|
|
213
|
-
for (const s of override.sections) {
|
|
214
|
-
const existing = merged.get(s.id);
|
|
215
|
-
if (existing) {
|
|
216
|
-
merged.set(s.id, { ...existing, ...s });
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
merged.set(s.id, s);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return sortSections([...merged.values()]);
|
|
223
|
-
}
|
|
224
|
-
catch (err) {
|
|
225
|
-
logger.warn(`[KitRenderer] Failed to load eck override, using kits only: ${err}`);
|
|
226
|
-
return sortSections(base.sections);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function sortSections(sections) {
|
|
230
|
-
return sections.slice().sort((a, b) => a.order - b.order);
|
|
231
|
-
}
|
|
232
|
-
// ── Section content loading ──
|
|
233
|
-
function loadSectionFiles(section, ctx) {
|
|
234
|
-
if (section.type === 'file' && section.file) {
|
|
235
|
-
const result = loadFileSection(section.file, ctx);
|
|
236
|
-
return result ? [result] : [];
|
|
237
|
-
}
|
|
238
|
-
if (section.type === 'directory' && section.path) {
|
|
239
|
-
return loadDirectorySection(section.path, section.pattern, ctx);
|
|
240
|
-
}
|
|
241
|
-
return [];
|
|
242
|
-
}
|
|
243
|
-
function loadFileSection(filePath, ctx) {
|
|
244
|
-
const resolved = resolvePath(filePath, ctx);
|
|
245
|
-
if (!resolved)
|
|
246
|
-
return null;
|
|
247
|
-
const sessionCache = getSessionCache(ctx.sessionId);
|
|
248
|
-
if (sessionCache.has(resolved))
|
|
249
|
-
return [resolved, sessionCache.get(resolved)];
|
|
250
|
-
try {
|
|
251
|
-
const content = fs.readFileSync(resolved, 'utf-8');
|
|
252
|
-
sessionCache.set(resolved, content);
|
|
253
|
-
return [resolved, content];
|
|
254
|
-
}
|
|
255
|
-
catch {
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function loadDirectorySection(dirPath, pattern, ctx) {
|
|
260
|
-
const resolved = resolvePath(dirPath, ctx);
|
|
261
|
-
if (!resolved)
|
|
262
|
-
return [];
|
|
263
|
-
return readDirectoryFiles(resolved, pattern).map(([name, content]) => [path.join(resolved, name), content]);
|
|
264
|
-
}
|
|
265
|
-
// ── Path resolution ──
|
|
266
|
-
function resolvePath(rawPath, ctx) {
|
|
267
|
-
const r = resolvePathWithDiag(rawPath, ctx);
|
|
268
|
-
return r.status === 'ok' ? r.resolved : null;
|
|
269
|
-
}
|
|
270
|
-
function resolvePathWithDiag(rawPath, ctx) {
|
|
271
|
-
const unresolved = [];
|
|
272
|
-
let resolved = rawPath.replace(/\$([A-Z_]+)/g, (_m, name) => {
|
|
273
|
-
const val = ctx.vars[name];
|
|
274
|
-
if (val === undefined || val === null || val === false || val === '') {
|
|
275
|
-
unresolved.push(`$${name}`);
|
|
276
|
-
return '';
|
|
277
|
-
}
|
|
278
|
-
return String(val);
|
|
279
|
-
});
|
|
280
|
-
resolved = resolved.replace(/\{\{(\w+)\}\}/g, (_m, key) => {
|
|
281
|
-
const val = ctx.vars[key];
|
|
282
|
-
if (val === undefined || val === null || val === false || val === '') {
|
|
283
|
-
unresolved.push(`{{${key}}}`);
|
|
284
|
-
return '';
|
|
285
|
-
}
|
|
286
|
-
return String(val);
|
|
287
|
-
});
|
|
288
|
-
if (!resolved || resolved.includes('$') || resolved.includes('{{')) {
|
|
289
|
-
return { resolved: resolved || null, status: 'unresolved-vars', unresolvedTokens: unresolved };
|
|
290
|
-
}
|
|
291
|
-
if (unresolved.length > 0) {
|
|
292
|
-
// 占位符是非必需变量,但有的解析为空——视为未解析
|
|
293
|
-
return { resolved, status: 'unresolved-vars', unresolvedTokens: unresolved };
|
|
294
|
-
}
|
|
295
|
-
if (!fs.existsSync(resolved)) {
|
|
296
|
-
return { resolved, status: 'not-exist', unresolvedTokens: unresolved };
|
|
297
|
-
}
|
|
298
|
-
return { resolved, status: 'ok', unresolvedTokens: unresolved };
|
|
299
|
-
}
|
|
300
|
-
// CHUNK_CONTINUE_5
|
|
301
|
-
// ── Directory reading ──
|
|
302
|
-
function readDirectoryFiles(dirPath, pattern) {
|
|
303
|
-
const glob = pattern || '*.md';
|
|
304
|
-
try {
|
|
305
|
-
const files = fs.readdirSync(dirPath)
|
|
306
|
-
.filter(f => matchGlob(f, glob))
|
|
307
|
-
.sort();
|
|
308
|
-
return files.map(f => {
|
|
309
|
-
const content = fs.readFileSync(path.join(dirPath, f), 'utf-8');
|
|
310
|
-
return [f, content];
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
catch {
|
|
314
|
-
return [];
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
function matchGlob(filename, pattern) {
|
|
318
|
-
const regex = pattern
|
|
319
|
-
.replace(/\./g, '\\.')
|
|
320
|
-
.replace(/\*/g, '.*')
|
|
321
|
-
.replace(/\{([^}]+)\}/g, (_, alts) => `(${alts.split(',').join('|')})`);
|
|
322
|
-
return new RegExp(`^${regex}$`).test(filename);
|
|
323
|
-
}
|
|
324
|
-
// ── When condition evaluation ──
|
|
325
|
-
function evaluateWhen(when, vars) {
|
|
326
|
-
if (when === 'always')
|
|
327
|
-
return true;
|
|
328
|
-
if (when.var !== undefined) {
|
|
329
|
-
const val = vars[when.var];
|
|
330
|
-
if (when.eq !== undefined) {
|
|
331
|
-
// 把 undefined 视作 null 的等价物,便于 manifest 用 eq:null/neq:null 表达"未注入"
|
|
332
|
-
if (when.eq === null)
|
|
333
|
-
return val === null || val === undefined;
|
|
334
|
-
return val === when.eq;
|
|
335
|
-
}
|
|
336
|
-
if (when.neq !== undefined) {
|
|
337
|
-
if (when.neq === null)
|
|
338
|
-
return val !== null && val !== undefined;
|
|
339
|
-
return val !== when.neq;
|
|
340
|
-
}
|
|
341
|
-
if (when.in !== undefined)
|
|
342
|
-
return when.in.includes(val);
|
|
343
|
-
if (when.nin !== undefined)
|
|
344
|
-
return !when.nin.includes(val);
|
|
345
|
-
}
|
|
346
|
-
if (when.any)
|
|
347
|
-
return when.any.some(k => isTruthy(vars[k]));
|
|
348
|
-
if (when.all)
|
|
349
|
-
return when.all.every(k => isTruthy(vars[k]));
|
|
350
|
-
return true;
|
|
351
|
-
}
|
|
352
|
-
function isTruthy(val) {
|
|
353
|
-
return val !== undefined && val !== null && val !== false && val !== '' && val !== 0;
|
|
354
|
-
}
|
|
355
|
-
// CHUNK_CONTINUE_6
|
|
356
|
-
// ── Template rendering ──
|
|
357
|
-
function resolveConditions(template, vars) {
|
|
358
|
-
// Find innermost {{?...}}...{{/}} block (no nested {{? inside) and resolve it.
|
|
359
|
-
// Repeat until no blocks remain.
|
|
360
|
-
const inner = /\{\{\?(\w+)(?:(!=|=)([^}]*))?\}\}([^]*?)\{\{\/\}\}/;
|
|
361
|
-
let result = template;
|
|
362
|
-
let prev;
|
|
363
|
-
do {
|
|
364
|
-
prev = result;
|
|
365
|
-
result = result.replace(inner, (_match, key, op, value, body) => {
|
|
366
|
-
if (op === '=')
|
|
367
|
-
return String(vars[key]) === value ? body : '';
|
|
368
|
-
if (op === '!=')
|
|
369
|
-
return String(vars[key]) !== value ? body : '';
|
|
370
|
-
return isTruthy(vars[key]) ? body : '';
|
|
371
|
-
});
|
|
372
|
-
} while (result !== prev);
|
|
373
|
-
return result;
|
|
374
|
-
}
|
|
375
|
-
function renderTemplate(template, vars) {
|
|
376
|
-
// Pass 1: resolve nested conditionals inside-out
|
|
377
|
-
let result = resolveConditions(template, vars);
|
|
378
|
-
// Pass 2: variable substitution {{key}}
|
|
379
|
-
result = result.replace(/\{\{(\w+)\}\}/g, (_match, key) => {
|
|
380
|
-
const val = vars[key];
|
|
381
|
-
if (!isTruthy(val))
|
|
382
|
-
return '';
|
|
383
|
-
return String(val);
|
|
384
|
-
});
|
|
385
|
-
// Pass 3: remove blank lines
|
|
386
|
-
return result.split('\n').filter(line => line.trim() !== '').join('\n');
|
|
387
|
-
}
|
|
388
|
-
// ── Session cache helper ──
|
|
389
|
-
function getSessionCache(sessionId) {
|
|
390
|
-
let cache = _sessionPathCache.get(sessionId);
|
|
391
|
-
if (!cache) {
|
|
392
|
-
cache = new Map();
|
|
393
|
-
_sessionPathCache.set(sessionId, cache);
|
|
394
|
-
}
|
|
395
|
-
return cache;
|
|
396
|
-
}
|
|
397
111
|
// ── Debug output ──
|
|
112
|
+
const PARAM_DESCRIPTIONS = {
|
|
113
|
+
EVOLCLAW_HOME: '用户数据根目录',
|
|
114
|
+
PACKAGE_ROOT: 'evolclaw 包根目录',
|
|
115
|
+
CURRENT_PROJECT: '当前项目完整路径',
|
|
116
|
+
PERSONAL_DIR: '当前 agent 个人数据目录',
|
|
117
|
+
RELATIONS_DIR: '当前 agent 关系数据目录',
|
|
118
|
+
VENUES_DIR: '当前 agent 环境数据目录',
|
|
119
|
+
selfAid: '当前 agent 的 AID',
|
|
120
|
+
selfName: '当前 agent 的显示名',
|
|
121
|
+
hasPersona: '是否有 persona 内容',
|
|
122
|
+
hasWorkingMemory: '是否有 working memory',
|
|
123
|
+
peerId: '对端在该渠道的原生 ID',
|
|
124
|
+
peerKey: '对端跨渠道唯一标识(channel#urlEncode(peerId))',
|
|
125
|
+
peerName: '对端显示名',
|
|
126
|
+
peerRole: '对端角色(owner/admin/guest/anonymous)',
|
|
127
|
+
peerType: '对端类型(human/agent)',
|
|
128
|
+
sameDevice: '对端与本端同一物理设备(E2EE 消息 proximity,仅加密消息有值)',
|
|
129
|
+
sameNetwork: '对端与本端在同一网络内',
|
|
130
|
+
sameEgressIp: '对端与本端共享同一出口 IP',
|
|
131
|
+
groupId: '群组 ID(群聊时)',
|
|
132
|
+
chatType: '聊天类型(private=私聊 / group=群聊 / null=本地开发)',
|
|
133
|
+
channel: '渠道类型(aun/feishu/wechat/dingtalk/qqbot/wecom)',
|
|
134
|
+
venueUid: '场所唯一标识(预留)',
|
|
135
|
+
dispatch: '群分发模式(mention=被@才响应 / broadcast=所有消息都响应)',
|
|
136
|
+
clientType: '客户端类型(desktop/web/mobile)',
|
|
137
|
+
permissionMode: '权限模式(auto/bypass/request/edit/plan/noask/readonly)',
|
|
138
|
+
capabilities: '当前渠道支持的能力列表',
|
|
139
|
+
project: '当前项目目录名',
|
|
140
|
+
sessionId: 'evolclaw 会话 ID',
|
|
141
|
+
sessionName: '会话名称',
|
|
142
|
+
sessionKey: '会话路由键(channelType#urlEncode(channelId)#urlEncode(threadId))',
|
|
143
|
+
sessionCreatedAt: '会话创建时间(ISO)',
|
|
144
|
+
timezone: 'IANA 时区名(把 ISO 时间戳转本地时间用,如 Asia/Shanghai)',
|
|
145
|
+
tzOffset: '当前 UTC 偏移(如 +08:00)',
|
|
146
|
+
localDate: '当前本地日期(YYYY-MM-DD,按 timezone)',
|
|
147
|
+
weekday: '当前本地星期几(按 timezone+locale)',
|
|
148
|
+
osInfo: '操作系统及版本(如 Windows 11 Pro (win32 10.0.26200))',
|
|
149
|
+
threadId: '话题 ID(多话题路由时)',
|
|
150
|
+
chatMode: '会话模式(interactive=同步交互 / proactive=主动推送)',
|
|
151
|
+
readonly: '是否只读模式',
|
|
152
|
+
evolclawMode: 'evolclaw 运行模式(dev=源码仓库可直接修改 | install=全局安装包只读)',
|
|
153
|
+
baseAgent: 'base agent 规范值(claude/codex/gemini/hermes)',
|
|
154
|
+
baseAgentName: 'base agent 显示名',
|
|
155
|
+
baseAgentModel: 'base agent 引擎底座模型(evolclaw 作用域无配置时的兜底)',
|
|
156
|
+
effectiveModel: '当前实际生效模型(关系级 > agent级 > 全局 优先级解析结果)',
|
|
157
|
+
modelFallbackActive: 'evolclaw 配置的模型不可用,当前正在使用降级模型',
|
|
158
|
+
modelFallbackModel: '当前降级使用的 base agent 模型名',
|
|
159
|
+
agentSessionId: 'base agent 会话 ID',
|
|
160
|
+
};
|
|
398
161
|
function writeDebugFiles(ctx, output, fragmentsOutput, diagnostics) {
|
|
399
162
|
const now = new Date();
|
|
400
163
|
const ts = now.toISOString().replace(/[T:.]/g, '-').slice(0, 19);
|
|
@@ -404,18 +167,13 @@ function writeDebugFiles(ctx, output, fragmentsOutput, diagnostics) {
|
|
|
404
167
|
sessionId: ctx.sessionId,
|
|
405
168
|
params: Object.entries(ctx.vars)
|
|
406
169
|
.filter(([, v]) => v !== undefined && v !== null)
|
|
407
|
-
.map(([name, value]) => ({
|
|
408
|
-
name,
|
|
409
|
-
value,
|
|
410
|
-
description: PARAM_DESCRIPTIONS[name] || '',
|
|
411
|
-
})),
|
|
170
|
+
.map(([name, value]) => ({ name, value, description: PARAM_DESCRIPTIONS[name] || '' })),
|
|
412
171
|
};
|
|
413
172
|
fs.writeFile(path.join(dir, `vars-${ts}.json`), JSON.stringify(varsData, null, 2), () => { });
|
|
414
173
|
if (output)
|
|
415
174
|
fs.writeFile(path.join(dir, `context-${ts}.md`), output, () => { });
|
|
416
|
-
if (fragmentsOutput)
|
|
175
|
+
if (fragmentsOutput)
|
|
417
176
|
fs.writeFile(path.join(dir, `fragments-${ts}.md`), fragmentsOutput, () => { });
|
|
418
|
-
}
|
|
419
177
|
fs.writeFile(path.join(dir, `manifest-${ts}.md`), formatManifestDiagnostics(ctx, diagnostics), () => { });
|
|
420
178
|
}
|
|
421
179
|
function formatManifestDiagnostics(ctx, diagnostics) {
|
|
@@ -468,7 +226,6 @@ function formatManifestDiagnostics(ctx, diagnostics) {
|
|
|
468
226
|
lines.push(`| ${idx + 1} | ${d.id} | ${status} | ${d.type} | ${rawPath} | ${resolvedShort} | ${d.fileCount} | ${d.used ? 'Y' : '·'} | ${d.injected ? 'Y' : '·'} |`);
|
|
469
227
|
});
|
|
470
228
|
lines.push('');
|
|
471
|
-
// 详细列出每个 section
|
|
472
229
|
lines.push(`## Section details`);
|
|
473
230
|
lines.push('');
|
|
474
231
|
for (const d of diagnostics) {
|