evolcore 0.0.43-test.1 → 0.0.43-test.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/CHANGELOG.md +31 -1
- package/README.md +22 -0
- package/dist/agents/claude-runner.js +26 -2
- package/dist/agents/codex/app-server-client.js +12 -0
- package/dist/agents/codex-runner.js +49 -8
- package/dist/agents/ecagent-runner.js +39 -15
- package/dist/agents/gemini-runner.js +15 -12
- package/dist/agents/tool-time-context.js +55 -0
- package/dist/aun/aid/agentmd.js +21 -1
- package/dist/aun/menu/client.js +1 -1
- package/dist/aun/model-headers.js +17 -0
- package/dist/aun/msg/p2p.js +7 -2
- package/dist/channels/aun.js +522 -50
- package/dist/channels/builtin-plugins.js +16 -11
- package/dist/channels/daemon.js +4 -0
- package/dist/channels/dingtalk.js +83 -31
- package/dist/channels/feishu.js +29 -13
- package/dist/channels/qqbot.js +32 -11
- package/dist/channels/wechat.js +13 -3
- package/dist/channels/wecom.js +67 -27
- package/dist/cli/agent-command.js +3 -86
- package/dist/cli/agent-create.js +20 -6
- package/dist/cli/agent.js +1 -79
- package/dist/cli/aun-commands.js +18 -19
- package/dist/cli/config.js +1 -1
- package/dist/cli/daemon-commands.js +47 -2
- package/dist/cli/data-command.js +9 -1
- package/dist/cli/debug-mode.js +1 -1
- package/dist/cli/diag.js +1 -1
- package/dist/cli/directory.js +149 -91
- package/dist/cli/getmeta-command.js +1 -1
- package/dist/cli/index.js +79 -22
- package/dist/cli/init.js +1 -23
- package/dist/cli/link-rules.js +1 -1
- package/dist/cli/managed-command-guard.js +0 -1
- package/dist/cli/pa-workspace-command.js +36 -2
- package/dist/cli/peer.js +3 -2
- package/dist/cli/restart-monitor.js +17 -3
- package/dist/cli/role.js +1 -1
- package/dist/cli/session-command.js +1 -1
- package/dist/cli/stats.js +2 -2
- package/dist/cli/task-context.js +3 -1
- package/dist/cli/thread-command.js +1 -1
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/builtin-role-templates.js +2 -2
- package/dist/config/builtin-roles.js +2 -1
- package/dist/config/config-field-policy.js +7 -2
- package/dist/config/config-manager.js +32 -10
- package/dist/config/peer-role-resolver.js +23 -1
- package/dist/config/role-schema.js +29 -4
- package/dist/config/role-service.js +12 -7
- package/dist/config/role-store.js +30 -8
- package/dist/config-store.js +75 -4
- package/dist/core/agent-ipc-registration.js +16 -59
- package/dist/core/auth/auth-gateway.js +14 -4
- package/dist/core/auth/authorization-audit.js +52 -14
- package/dist/core/auth/operation-authorizer.js +17 -11
- package/dist/core/auth/operation-catalog.js +5 -13
- package/dist/core/channel-loader.js +152 -16
- package/dist/core/channel-runtime.js +5 -0
- package/dist/core/command/agent-control.js +2 -1
- package/dist/core/command/agentmd-menu-request.js +50 -0
- package/dist/core/command/agentmd-menu.js +156 -0
- package/dist/core/command/cli-intent-parser.js +0 -8
- package/dist/core/command/command-handler.js +47 -40
- package/dist/core/command/connect-menu.js +7 -3
- package/dist/core/command/menu-catalog.js +16 -2
- package/dist/core/command/menu-handler.js +107 -14
- package/dist/core/command/menu-protocol.js +28 -0
- package/dist/core/command/role-menu.js +23 -9
- package/dist/core/command/slash-handler.js +139 -51
- package/dist/core/daemon-file-cache.js +3 -3
- package/dist/core/daemon-lifecycle.js +9 -1
- package/dist/core/evolagent-registry.js +5 -4
- package/dist/core/evolagent.js +10 -12
- package/dist/core/handoff/argv-parse.js +115 -0
- package/dist/core/handoff/ipc-registration.js +1 -1
- package/dist/core/ipc-registration.js +19 -2
- package/dist/core/lifecycle-notice.js +185 -0
- package/dist/core/memory/consolidation.js +8 -1
- package/dist/core/memory/relation-sweep.js +20 -8
- package/dist/core/message/aun-ipc-sender.js +35 -2
- package/dist/core/message/contact-admission.js +530 -0
- package/dist/core/message/im-renderer.js +111 -16
- package/dist/core/message/message-admission.js +29 -54
- package/dist/core/message/message-bridge.js +62 -8
- package/dist/core/message/message-utils.js +9 -5
- package/dist/core/message/peer-mode.js +55 -13
- package/dist/core/message/response-engine.js +298 -78
- package/dist/core/message/retry-scheduler.js +4 -0
- package/dist/core/ownership/owner-resolver.js +72 -34
- package/dist/core/permission/ec-command-parser.js +25 -38
- package/dist/core/permission/readonly-shell-query.js +34 -8
- package/dist/core/permission/tool-policy.js +50 -5
- package/dist/core/relation/pa-team.js +127 -0
- package/dist/core/role/runtime-policy.js +18 -5
- package/dist/core/session/session-manager.js +9 -1
- package/dist/core/soul.js +66 -0
- package/dist/core/system-session/memory.js +2 -2
- package/dist/core/thread/thread-service.js +6 -4
- package/dist/directory/contact-admission-paths.js +9 -0
- package/dist/directory/owner-directory-admission.js +125 -29
- package/dist/directory/owner-directory-cache.js +554 -58
- package/dist/directory/owner-directory-identity.js +60 -0
- package/dist/directory/owner-directory-markdown.js +154 -58
- package/dist/directory/owner-directory-policy.js +108 -0
- package/dist/directory/owner-directory-query-operation.js +399 -90
- package/dist/directory/owner-directory-remarks.js +29 -2
- package/dist/directory/owner-directory-request-operation.js +76 -0
- package/dist/directory/owner-directory-scope.js +35 -4
- package/dist/directory/owner-directory-search.js +118 -33
- package/dist/directory/owner-directory-store.js +117 -30
- package/dist/directory/owner-directory-text.js +60 -0
- package/dist/eck/kit-renderer.js +18 -8
- package/dist/eck/manifest-engine.js +55 -6
- package/dist/ecweb/basic-settings-service.js +2 -2
- package/dist/ecweb/message-context-service.js +28 -16
- package/dist/index.js +20 -5
- package/dist/ipc.js +1 -1
- package/dist/paths.js +29 -1
- package/dist/product.js +1 -0
- package/dist/response-system/config-resolver.js +1 -1
- package/dist/response-system/engines/v1/index.js +2 -1
- package/dist/response-system/modes/single-session/index.js +7 -2
- package/dist/trigger/scheduler.js +7 -4
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/error-utils.js +12 -7
- package/dist/utils/logger.js +13 -4
- package/dist/utils/npm-ops.js +2 -2
- package/dist/utils/windows-autostart.js +1 -1
- package/ecagent/README.md +18 -0
- package/ecagent/dist/agent-loop.js +43 -1
- package/ecagent/dist/harness/agent-harness.d.ts +2 -0
- package/ecagent/dist/harness/agent-harness.js +24 -8
- package/ecagent/dist/harness/compaction/compaction.js +3 -0
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/context-assembly.md +21 -6
- package/kits/docs/eck_templates/INDEX.template.md +1 -2
- package/kits/docs/evolcore/INDEX.md +4 -1
- package/kits/docs/evolcore/agent-create.md +5 -5
- package/kits/docs/evolcore/agent.md +4 -9
- package/kits/docs/evolcore/directory.md +227 -0
- package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
- package/kits/docs/evolcore/file-navigation.md +265 -0
- package/kits/docs/evolcore/menu-protocol.md +55 -0
- package/kits/docs/evolcore/msg.md +1 -0
- package/kits/docs/evolcore/peer.md +2 -1
- package/kits/docs/evolcore/response.md +7 -1
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +1 -1
- package/kits/docs/evolcore/trigger.md +4 -0
- package/kits/docs/identity/ROLE_DETAIL.md +2 -0
- package/kits/docs/prompt-loading-architecture.md +6 -2
- package/kits/eck_manifest.auxiliary.json +1 -0
- package/kits/eck_manifest.json +64 -7
- package/kits/eck_manifest.memory.json +93 -4
- package/kits/rules/01-overview.md +2 -2
- package/kits/rules/03-identity.md +10 -9
- package/kits/rules/05-venue.md +2 -4
- package/kits/rules/06-channel.md +1 -1
- package/kits/schemas/_meta.json +44 -3
- package/kits/schemas/agent-config.schema.18.json +5 -0
- package/kits/schemas/agent-config.schema.19.json +924 -0
- package/kits/schemas/agent-config.schema.20.json +925 -0
- package/kits/schemas/relation-config.schema.12.json +289 -0
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/schemas/role-config.schema.2.json +215 -0
- package/kits/schemas/role-config.schema.3.json +1038 -0
- package/kits/schemas/role-registry.schema.1.json +3 -2
- package/kits/skills/ec-skill/scripts/cli.mjs +3 -2
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +109 -53
- package/kits/skills/personal-assistant/references/02-bootstrap.md +73 -30
- package/kits/skills/personal-assistant/scripts/clean.mjs +35 -18
- package/kits/skills/personal-assistant/scripts/init.mjs +41 -2
- package/kits/skills/personal-assistant/scripts/lib/persona.mjs +185 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +55 -4
- package/kits/skills/personal-assistant/scripts/pa.mjs +173 -0
- package/kits/skills/personal-assistant/scripts/uninstall.mjs +130 -0
- package/kits/skills/personal-assistant/templates/persona-section.md +3 -3
- package/kits/templates/message-fragments/handoff-request-to-target.md +1 -1
- package/kits/templates/soul/00-GUIDE.md +39 -0
- package/kits/templates/soul/01-identity.md +5 -0
- package/kits/templates/soul/02-persona.md +11 -0
- package/kits/templates/soul/03-duties.md +5 -0
- package/kits/templates/soul/04-working-style.md +5 -0
- package/kits/templates/system-fragments/bootstrap.md +7 -7
- package/kits/templates/system-fragments/channel.md +2 -2
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +9 -0
- package/kits/templates/system-fragments/memory.md +1 -1
- package/kits/templates/system-fragments/personal-assistant.md +50 -0
- package/kits/templates/system-fragments/reply.md +7 -0
- package/kits/templates/system-fragments/session.md +6 -2
- package/package.json +3 -2
- package/dist/cli/handoff-command.js +0 -353
- package/dist/directory/owner-directory-remark-operation.js +0 -147
- package/kits/docs/evolcore/self-summary.md +0 -29
package/dist/eck/kit-renderer.js
CHANGED
|
@@ -81,9 +81,11 @@ export function renderKitSections(ctx, manifestFile = DEFAULT_MANIFEST_FILE) {
|
|
|
81
81
|
// by agent configuration normalization while leaving explicit invalid
|
|
82
82
|
// values untouched for fail-closed manifest conditions.
|
|
83
83
|
const resolvedLifecycle = resolveAgentLifecycle({ lifecycle: ctx.vars.lifecycle });
|
|
84
|
-
const vars =
|
|
85
|
-
|
|
86
|
-
: {
|
|
84
|
+
const vars = {
|
|
85
|
+
...ctx.vars,
|
|
86
|
+
...(resolvedLifecycle === null ? {} : { lifecycle: resolvedLifecycle }),
|
|
87
|
+
activePush: ctx.vars.chatMode === 'proactive' || ctx.vars.chatMode === 'paactive',
|
|
88
|
+
};
|
|
87
89
|
const renderCtx = { ...ctx, vars };
|
|
88
90
|
const pathMappings = buildPathMappings(vars);
|
|
89
91
|
const sessionCache = getSessionCache(ctx.sessionId);
|
|
@@ -174,8 +176,9 @@ export function renderKitSections(ctx, manifestFile = DEFAULT_MANIFEST_FILE) {
|
|
|
174
176
|
diag.injected = true;
|
|
175
177
|
}
|
|
176
178
|
}
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
+
// 单目录段超限:注入截断说明行。单文件截断的说明已随该文件内容一起追加,
|
|
180
|
+
// 这里只在确实有文件被丢弃时补一行,避免出现「0 个文件未加载」的空话。
|
|
181
|
+
if (diag.dirOverflow && diag.dirOverflow.droppedFiles > 0) {
|
|
179
182
|
const ov = diag.dirOverflow;
|
|
180
183
|
const displayPath = shortenPath(diag.resolvedPath ?? rawPath, pathMappings);
|
|
181
184
|
const note = `[注意] 目录 ${displayPath} 未完整加载:${ov.droppedFiles} 个文件未加载` +
|
|
@@ -235,9 +238,15 @@ const PARAM_DESCRIPTIONS = {
|
|
|
235
238
|
selfName: '当前 agent 的显示名',
|
|
236
239
|
lifecycle: '当前 agent 生命周期(created/ownerpending/bootstrapping/active)',
|
|
237
240
|
isBootstrapping: '当前 agent 是否处于 bootstrap 首次设定阶段',
|
|
238
|
-
hasPersona: '
|
|
239
|
-
hasWorkingMemory: '是否有 working memory',
|
|
241
|
+
hasPersona: '是否有自我定义内容(soul/ 下除指南外有非空文件)',
|
|
240
242
|
hasOwnerDirectory: '是否有 Owner 名录注入文件($AGENT_DIR/directory/directory.md)',
|
|
243
|
+
ownerAid: 'Owner 的 AID(名录快照为准,未落地时退回静态配置)',
|
|
244
|
+
ownerName: 'Owner 的显示名(名录快照)',
|
|
245
|
+
personalAssistantAid: '个人助理的 AID(名录快照;没有个人助理时为空)',
|
|
246
|
+
personalAssistantName: '个人助理的显示名(名录快照)',
|
|
247
|
+
isPersonalAssistant: '当前 agent 是否就是 Owner 的个人助理(即时比较,读不到身份时为 false)',
|
|
248
|
+
isOwner: '当前 agent 是否就是名录里的 Owner(即时比较;Owner 通常是人,一般恒为 false)',
|
|
249
|
+
contactsState: '准入现状一句话:内部联系人/外部联系人/名录外的人分别可不可联系',
|
|
241
250
|
peerId: '对端在该渠道的原生 ID',
|
|
242
251
|
peerKey: '对端跨渠道唯一标识(channel#urlEncode(peerId))',
|
|
243
252
|
peerName: '对端显示名',
|
|
@@ -271,7 +280,8 @@ const PARAM_DESCRIPTIONS = {
|
|
|
271
280
|
weekday: '当前本地星期几(按 timezone+locale)',
|
|
272
281
|
osInfo: '操作系统及版本(如 Windows 11 Pro (win32 10.0.26200))',
|
|
273
282
|
threadId: '话题 ID(多话题路由时)',
|
|
274
|
-
chatMode: '会话模式(interactive=同步交互 / proactive
|
|
283
|
+
chatMode: '会话模式(interactive=同步交互 / proactive=主动推送 / paactive=PA activity)',
|
|
284
|
+
activePush: '是否通过托管发送命令发送正式回复(true/false)',
|
|
275
285
|
isTriggerTask: '当前任务是否来源于 Trigger(true/false)',
|
|
276
286
|
proactivePreTool1stMsgChk: 'proactive 前置工具首消息检查(true/false)',
|
|
277
287
|
proactiveToolUseReminder: 'proactive 工具调用提醒(true/false)',
|
|
@@ -12,6 +12,8 @@ import { readVerifiedText, isShippedPath } from '../core/file-integrity/read.js'
|
|
|
12
12
|
export const DIR_MAX_FILES = 20;
|
|
13
13
|
/** 单目录段默认最多总字节(40KB) */
|
|
14
14
|
export const DIR_MAX_BYTES = 40 * 1024;
|
|
15
|
+
/** 单目录段里单个文件的默认上限(8KB);超过截断,避免单个失控文件吃光整段乃至全局额度 */
|
|
16
|
+
export const DIR_MAX_FILE_BYTES = 8 * 1024;
|
|
15
17
|
/** 整个清单默认最多文件数 */
|
|
16
18
|
export const TOTAL_MAX_FILES = 50;
|
|
17
19
|
/** 整个清单默认最多总字节(100KB) */
|
|
@@ -407,9 +409,14 @@ export function loadSectionFiles(section, vars, sessionCache, overflowOut) {
|
|
|
407
409
|
const resolved = resolvePath(section.path, vars);
|
|
408
410
|
if (!resolved)
|
|
409
411
|
return [];
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
412
|
+
const limits = {
|
|
413
|
+
maxFiles: section.maxFiles ?? DIR_MAX_FILES,
|
|
414
|
+
maxBytes: section.maxBytes ?? DIR_MAX_BYTES,
|
|
415
|
+
maxFileBytes: section.maxFileBytes ?? DIR_MAX_FILE_BYTES,
|
|
416
|
+
skipUnchangedTemplate: section.skipUnchangedTemplate,
|
|
417
|
+
unchangedTemplateKeep: section.unchangedTemplateKeep,
|
|
418
|
+
};
|
|
419
|
+
const { files, overflow } = readDirectoryFiles(resolved, section.pattern, limits, vars);
|
|
413
420
|
if (overflow && overflowOut)
|
|
414
421
|
overflowOut.value = overflow;
|
|
415
422
|
return files.map(([name, content]) => [path.join(resolved, name), content]);
|
|
@@ -425,10 +432,18 @@ function loadFileSection(filePath, vars, sessionCache) {
|
|
|
425
432
|
return content === null ? null : [resolved, content];
|
|
426
433
|
}
|
|
427
434
|
/**
|
|
428
|
-
*
|
|
435
|
+
* 读取目录下匹配文件,受三层限额约束:
|
|
436
|
+
* - maxFiles:文件数上限,超出的文件不加载;
|
|
437
|
+
* - maxBytes:本段总字节上限,超出的文件不加载;
|
|
438
|
+
* - maxFileBytes:单文件上限,超出的**截断**(不丢弃,其余文件照常加载)。
|
|
439
|
+
*
|
|
440
|
+
* 单文件限额存在的意义:没有它时「至少保留 1 个文件」的规则会让一个超大文件直接吃光
|
|
441
|
+
* 本段额度(甚至全局总闸),把后面所有段挤掉。截断只损失一个文件末尾,不影响其它段。
|
|
442
|
+
*
|
|
429
443
|
* 返回已加载文件 + 溢出信息(超限时)。按 fileCache 缓存目录列表与文件内容。
|
|
430
444
|
*/
|
|
431
|
-
function readDirectoryFiles(dirPath, pattern,
|
|
445
|
+
function readDirectoryFiles(dirPath, pattern, limits, vars) {
|
|
446
|
+
const { maxFiles, maxBytes, maxFileBytes, skipUnchangedTemplate, unchangedTemplateKeep } = limits;
|
|
432
447
|
const glob = pattern || '*.md';
|
|
433
448
|
const cacheOptions = sectionCacheOptions(dirPath, vars);
|
|
434
449
|
const readNames = () => {
|
|
@@ -447,6 +462,7 @@ function readDirectoryFiles(dirPath, pattern, maxFiles, maxBytes, vars) {
|
|
|
447
462
|
const out = [];
|
|
448
463
|
let usedBytes = 0;
|
|
449
464
|
let overflow;
|
|
465
|
+
const truncated = [];
|
|
450
466
|
for (let i = 0; i < names.length; i++) {
|
|
451
467
|
const f = names[i];
|
|
452
468
|
// 文件数限额
|
|
@@ -455,9 +471,20 @@ function readDirectoryFiles(dirPath, pattern, maxFiles, maxBytes, vars) {
|
|
|
455
471
|
break;
|
|
456
472
|
}
|
|
457
473
|
const fp = path.join(dirPath, f);
|
|
458
|
-
|
|
474
|
+
let content = loadKitsDoc(fp, vars);
|
|
459
475
|
if (content === null)
|
|
460
476
|
continue;
|
|
477
|
+
// 仍是未改动的骨架:占位说明不算内容,跳过(不计入文件数与字节)。
|
|
478
|
+
if (skipUnchangedTemplate
|
|
479
|
+
&& !unchangedTemplateKeep?.includes(f)
|
|
480
|
+
&& matchesTemplate(content, f, skipUnchangedTemplate))
|
|
481
|
+
continue;
|
|
482
|
+
// 单文件限额:截断而不是丢弃,避免一个失控文件挤掉整段。
|
|
483
|
+
const originalBytes = Buffer.byteLength(content, 'utf-8');
|
|
484
|
+
if (originalBytes > maxFileBytes) {
|
|
485
|
+
content = `${truncateUtf8(content, maxFileBytes)}\n\n[注意] 本文件超过单文件上限 ${formatKb(maxFileBytes)},已截断(原 ${formatKb(originalBytes)})。`;
|
|
486
|
+
truncated.push({ name: f, originalBytes, limit: maxFileBytes });
|
|
487
|
+
}
|
|
461
488
|
// 字节限额(至少加载一个文件,避免单个超大文件导致空目录)
|
|
462
489
|
const size = Buffer.byteLength(content, 'utf-8');
|
|
463
490
|
if (out.length > 0 && usedBytes + size > maxBytes) {
|
|
@@ -467,8 +494,30 @@ function readDirectoryFiles(dirPath, pattern, maxFiles, maxBytes, vars) {
|
|
|
467
494
|
usedBytes += size;
|
|
468
495
|
out.push([f, content]);
|
|
469
496
|
}
|
|
497
|
+
if (truncated.length > 0) {
|
|
498
|
+
overflow = { ...(overflow ?? { droppedFiles: 0, reason: 'bytes', limit: maxBytes }), truncated };
|
|
499
|
+
}
|
|
470
500
|
return { files: out, overflow };
|
|
471
501
|
}
|
|
502
|
+
/** 按字节上限截断文本,并回退到 UTF-8 字符边界,避免切出半个汉字。 */
|
|
503
|
+
function truncateUtf8(text, maxBytes) {
|
|
504
|
+
const buf = Buffer.from(text, 'utf-8');
|
|
505
|
+
let end = maxBytes;
|
|
506
|
+
// 0b10xxxxxx 是 UTF-8 续字节;落在续字节上说明切在字符中间,往前退。
|
|
507
|
+
while (end > 0 && (buf[end] & 0xc0) === 0x80)
|
|
508
|
+
end -= 1;
|
|
509
|
+
return buf.subarray(0, end).toString('utf-8');
|
|
510
|
+
}
|
|
511
|
+
function formatKb(bytes) {
|
|
512
|
+
return bytes >= 1024 ? `${Math.round(bytes / 1024)}KB` : `${bytes}B`;
|
|
513
|
+
}
|
|
514
|
+
/** 内容是否仍与 `kits/templates/<templateDir>/<同名文件>` 完全一致(未改动的骨架)。 */
|
|
515
|
+
function matchesTemplate(content, name, templateDir) {
|
|
516
|
+
const template = loadKitsDoc(path.join(kitsDir(), 'templates', templateDir, name), {});
|
|
517
|
+
if (template === null)
|
|
518
|
+
return false;
|
|
519
|
+
return content.trim() === template.trim();
|
|
520
|
+
}
|
|
472
521
|
function matchGlob(filename, pattern) {
|
|
473
522
|
const regex = pattern
|
|
474
523
|
.replace(/\./g, '\\.')
|
|
@@ -322,7 +322,7 @@ function assertServices(value) {
|
|
|
322
322
|
value.forEach((service, index) => {
|
|
323
323
|
if (!isRecord(service))
|
|
324
324
|
throw makeError(`services[${index}] must be an object`, 'INVALID_SETTINGS_VALUE');
|
|
325
|
-
const allowedKeys = new Set(['name', 'enabled', 'port', 'proxy']);
|
|
325
|
+
const allowedKeys = new Set(['name', 'enabled', 'port', 'runtime', 'health', 'proxy']);
|
|
326
326
|
if (Object.keys(service).some(key => !allowedKeys.has(key)))
|
|
327
327
|
throw makeError(`services[${index}] contains an unsupported field`, 'INVALID_SETTINGS_VALUE');
|
|
328
328
|
const name = assertString(service.name, `services[${index}].name`, { max: 64 });
|
|
@@ -509,7 +509,7 @@ function validateDefaultsValue(fieldPath, value) {
|
|
|
509
509
|
return;
|
|
510
510
|
}
|
|
511
511
|
if (fieldPath === 'config.chatMode') {
|
|
512
|
-
if (!['interactive', 'proactive'].includes(String(value)))
|
|
512
|
+
if (!['interactive', 'proactive', 'paactive'].includes(String(value)))
|
|
513
513
|
throw makeError(`${fieldPath} is invalid`, 'INVALID_SETTINGS_VALUE');
|
|
514
514
|
return;
|
|
515
515
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
2
2
|
import { resolvePeerDisplayLabel } from '../config/peer-book.js';
|
|
3
3
|
import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
|
|
4
|
+
import { ConfigTarget, read } from '../config/config-manager.js';
|
|
5
|
+
import { resolveAgentLifecycle } from '../config/lifecycle.js';
|
|
4
6
|
import { resolveChatMode } from '../core/message/peer-mode.js';
|
|
5
7
|
import { resolvePermissionMode } from '../core/model/config-scope.js';
|
|
6
8
|
import { formatPeerKey } from '../core/relation/peer-identity.js';
|
|
9
|
+
import { preparePaTeamQualification } from '../core/relation/pa-team.js';
|
|
7
10
|
const REQUEST_FIELDS = new Set([
|
|
8
11
|
'selfAid', 'channelType', 'channelKey', 'chatType', 'actorId',
|
|
9
12
|
'conversationId', 'peerType', 'sessionId', 'displayQueries',
|
|
@@ -82,31 +85,40 @@ export function createEcwebMessageContextProvider(sessionManager, resolveRuntime
|
|
|
82
85
|
throw new MessageContextRequestError('sessionId must be an EvolCore session identifier');
|
|
83
86
|
}
|
|
84
87
|
const peerKey = formatPeerKey(identity.channelType, conversationId);
|
|
88
|
+
if (identity.channelType === 'aun' && chatType === 'private') {
|
|
89
|
+
await preparePaTeamQualification(identity.selfAid, identity.actorId);
|
|
90
|
+
}
|
|
85
91
|
const detail = resolvePeerRoleDetail({ ...identity, chatType, conversationId, peerType });
|
|
86
92
|
const role = detail.effectiveRole || 'none';
|
|
93
|
+
const candidate = sessionId ? await sessionManager.getSessionById(sessionId) : undefined;
|
|
94
|
+
const scopedSession = candidate?.selfAID === identity.selfAid
|
|
95
|
+
&& candidate.channelType === identity.channelType
|
|
96
|
+
&& candidate.channelId === conversationId
|
|
97
|
+
? candidate : undefined;
|
|
87
98
|
const result = {
|
|
88
99
|
role,
|
|
89
100
|
roleSource: detail.source,
|
|
90
101
|
permissionMode: resolvePermissionMode({ self: identity.selfAid, peerKey, role }),
|
|
91
|
-
chatMode: resolveChatMode({
|
|
102
|
+
chatMode: resolveChatMode({
|
|
103
|
+
self: identity.selfAid, peerKey, role, chatType, peerType,
|
|
104
|
+
channelType: identity.channelType,
|
|
105
|
+
lifecycle: resolveAgentLifecycle(read(ConfigTarget.Agent, { self: identity.selfAid }) ?? {}),
|
|
106
|
+
sessionType: scopedSession?.sessionType ?? scopedSession?.metadata?.sessionType ?? 'main',
|
|
107
|
+
}),
|
|
92
108
|
...(peerLabels ? { peerLabels } : {}),
|
|
93
109
|
};
|
|
94
|
-
if (
|
|
95
|
-
const session =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const fileInfo = sessionManager.getSessionFileInfo(session.projectPath, session.agentSessionId, session.baseagent, session.selfAID);
|
|
105
|
-
if (Number.isFinite(fileInfo.turns) && fileInfo.turns > 0)
|
|
106
|
-
result.turns = fileInfo.turns;
|
|
107
|
-
}
|
|
108
|
-
catch { }
|
|
110
|
+
if (scopedSession) {
|
|
111
|
+
const session = scopedSession;
|
|
112
|
+
const status = resolveRuntimeStatus?.(session);
|
|
113
|
+
if (status)
|
|
114
|
+
result.status = status;
|
|
115
|
+
if (session.agentSessionId && session.projectPath && session.baseagent) {
|
|
116
|
+
try {
|
|
117
|
+
const fileInfo = sessionManager.getSessionFileInfo(session.projectPath, session.agentSessionId, session.baseagent, session.selfAID);
|
|
118
|
+
if (Number.isFinite(fileInfo.turns) && fileInfo.turns > 0)
|
|
119
|
+
result.turns = fileInfo.turns;
|
|
109
120
|
}
|
|
121
|
+
catch { }
|
|
110
122
|
}
|
|
111
123
|
}
|
|
112
124
|
return result;
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,7 @@ import { createDelegationAuthorizer } from './core/auth/delegation-authorization
|
|
|
47
47
|
import { registerProxyIpcExecutor } from './proxy/ipc-service.js';
|
|
48
48
|
import { ownerResolver, getDaemonOwners, getPrimaryOwner } from './core/ownership/owner-resolver.js';
|
|
49
49
|
import { cleanupStartupHandoffs, recoverStartupHandoffs, releaseRestoredQueue, resumePendingSessions, createDaemonShutdown, daemonConversationTotalExecutionMs, daemonConversationWatchdogMs, daemonIdleTimeoutMs, } from './core/daemon-lifecycle.js';
|
|
50
|
+
import { createLifecycleNoticeService } from './core/lifecycle-notice.js';
|
|
50
51
|
import { BootstrapService, createBootstrapCompletionHandler, createBootstrapOwnerBoundHandler } from './core/bootstrap-service.js';
|
|
51
52
|
import { MessageCache } from './core/message/message-cache.js';
|
|
52
53
|
import { createAunHandoffSender } from './core/message/aun-ipc-sender.js';
|
|
@@ -366,7 +367,7 @@ async function main() {
|
|
|
366
367
|
// 渠道插件系统
|
|
367
368
|
trace.mark('daemon.channelCreate');
|
|
368
369
|
const channelLoader = new ChannelLoader(daemonCfg.debug, daemonCfg.aun?.defaultEncrypt);
|
|
369
|
-
registerBuiltinChannelPlugins(channelLoader);
|
|
370
|
+
await registerBuiltinChannelPlugins(channelLoader);
|
|
370
371
|
// Create channel instances: 每个 self-agent 各自的 channels
|
|
371
372
|
const evolagentInstances = [];
|
|
372
373
|
for (const agent of agentRegistry.runnableAgents()) {
|
|
@@ -688,10 +689,10 @@ async function main() {
|
|
|
688
689
|
return !!inst && inst.channel.getStatus?.().connected === true;
|
|
689
690
|
};
|
|
690
691
|
const contactBindIpcExecutor = (channelType) => {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
692
|
+
return {
|
|
693
|
+
register: (request) => channelLoader.contactBindRegistry.registerPending(channelType, request),
|
|
694
|
+
isChannelReady: isContactBindChannelReady,
|
|
695
|
+
};
|
|
695
696
|
};
|
|
696
697
|
cmdHandler.setAgentStorageClientResolver(createAgentStorageClientResolver(channelInstances));
|
|
697
698
|
const msgBridge = new MessageBridge(defaultProjectPath, sessionManager, processor, messageQueue, cmdHandler, eventBus, primaryAgent?.config.debounce, processLevelOwners);
|
|
@@ -763,6 +764,11 @@ async function main() {
|
|
|
763
764
|
// handoff 启动恢复是否还在收集 hint。与"队列是否已放行"是两件事:
|
|
764
765
|
// 队列有超时兜底会提前放行,而恢复可能还在等渠道。
|
|
765
766
|
let startupRecoveryPending = true;
|
|
767
|
+
// AUN 上下线系统提示(volatile)。系统行为,无配置开关。
|
|
768
|
+
const lifecycleNotices = createLifecycleNoticeService({
|
|
769
|
+
channelInstances,
|
|
770
|
+
resolveAgent: (channelKey, channelName) => agentRegistry.resolveByChannel(channelKey) ?? agentRegistry.resolveByChannel(channelName),
|
|
771
|
+
});
|
|
766
772
|
const { markChannelConnected, unregisterRuntimeChannel, queuePendingObserverHints } = createChannelConnectionRuntime({
|
|
767
773
|
...channelRuntimeDependencies,
|
|
768
774
|
channelInstances,
|
|
@@ -770,6 +776,7 @@ async function main() {
|
|
|
770
776
|
bootstrapService,
|
|
771
777
|
ensureTriggerSchedulerStarted,
|
|
772
778
|
sendOnlineNoticeForChannel,
|
|
779
|
+
sendLifecycleNoticeForChannel: instance => lifecycleNotices.online(instance),
|
|
773
780
|
trySendPendingRestartNotice,
|
|
774
781
|
sessionsDir: paths.sessionsDir,
|
|
775
782
|
startupObserverRecoveries,
|
|
@@ -841,6 +848,10 @@ async function main() {
|
|
|
841
848
|
trace.mark('daemon.ipcCreate');
|
|
842
849
|
const ipcServer = new IpcServer(resolvePaths().socket, createIpcStatusProvider({
|
|
843
850
|
channelInstances,
|
|
851
|
+
getChannelRuntimeSnapshot: () => channelLoader.getSnapshot(agentRegistry.list().flatMap(info => {
|
|
852
|
+
const agent = agentRegistry.get(info.aid);
|
|
853
|
+
return agent ? [agent] : [];
|
|
854
|
+
})),
|
|
844
855
|
statsCollector,
|
|
845
856
|
agentRegistry,
|
|
846
857
|
messageQueue,
|
|
@@ -1226,6 +1237,10 @@ async function main() {
|
|
|
1226
1237
|
// 显式触发更可控。
|
|
1227
1238
|
shutdown = createDaemonShutdown({
|
|
1228
1239
|
disposePluginResources: () => daemonPluginLifecycle.dispose(),
|
|
1240
|
+
lifecycleNotices: {
|
|
1241
|
+
beginShutdown: () => lifecycleNotices.beginShutdown(),
|
|
1242
|
+
sendOffline: signal => lifecycleNotices.sendOffline(signal),
|
|
1243
|
+
},
|
|
1229
1244
|
ipcServer,
|
|
1230
1245
|
readySignalPath,
|
|
1231
1246
|
bindService,
|
package/dist/ipc.js
CHANGED
|
@@ -1174,7 +1174,7 @@ export class IpcServer {
|
|
|
1174
1174
|
}
|
|
1175
1175
|
if (cmd.argv !== undefined && ['handoff-status', 'handoff-list', 'handoff-trace'].includes(cmd.type)) {
|
|
1176
1176
|
try {
|
|
1177
|
-
const { parseList, parseTrace } = await import('./
|
|
1177
|
+
const { parseList, parseTrace } = await import('./core/handoff/argv-parse.js');
|
|
1178
1178
|
if (!Array.isArray(cmd.argv) || cmd.argv[0] !== 'handoff' || `handoff-${cmd.argv[1]}` !== cmd.type) {
|
|
1179
1179
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Handoff endpoint does not match argv' };
|
|
1180
1180
|
}
|
package/dist/paths.js
CHANGED
|
@@ -2,11 +2,29 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import os from 'os';
|
|
4
4
|
import crypto from 'crypto';
|
|
5
|
-
import { DAEMON_CONFIG_FILENAME, DEFAULT_RUNTIME_HOME_DIRNAME, INSTANCE_SOCKET_FILENAME, RUNTIME_HOME_ENV, WINDOWS_PIPE_PREFIX, } from './product.js';
|
|
5
|
+
import { DAEMON_CONFIG_FILENAME, DEFAULT_RUNTIME_HOME_DIRNAME, INSTANCE_SOCKET_FILENAME, RUNTIME_HOME_ENV, TEST_TMPDIR_ENV, WINDOWS_PIPE_PREFIX, } from './product.js';
|
|
6
6
|
import { migrateLegacyAgentJsonlLogs } from './core/audit/log-integrity.js';
|
|
7
7
|
const isWindows = process.platform === 'win32';
|
|
8
8
|
let _root = null;
|
|
9
9
|
export function resolveRoot() {
|
|
10
|
+
// Tests may clear their per-case home while asynchronous callbacks are
|
|
11
|
+
// still running. Keep those callbacks in the suite's temporary root rather
|
|
12
|
+
// than falling back to the developer's live runtime directory.
|
|
13
|
+
if (process.env.EVOLCORE_TEST === '1') {
|
|
14
|
+
const testRoot = process.env[RUNTIME_HOME_ENV] || process.env.EVOLCORE_TEST_ROOT;
|
|
15
|
+
// Managed children narrow TMPDIR to their session directory. The test
|
|
16
|
+
// harness retains the original boundary across that deliberate change.
|
|
17
|
+
const tempDir = process.env[TEST_TMPDIR_ENV] || process.env.TMPDIR;
|
|
18
|
+
if (!testRoot || !path.isAbsolute(testRoot) || !tempDir || !path.isAbsolute(tempDir)) {
|
|
19
|
+
throw new Error('Test runtime requires an absolute isolated root inside TMPDIR');
|
|
20
|
+
}
|
|
21
|
+
const relative = path.relative(path.resolve(tempDir), path.resolve(testRoot));
|
|
22
|
+
if (!relative || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
23
|
+
throw new Error('Test runtime root must stay inside TMPDIR');
|
|
24
|
+
}
|
|
25
|
+
_root = testRoot;
|
|
26
|
+
return _root;
|
|
27
|
+
}
|
|
10
28
|
if (_root)
|
|
11
29
|
return _root;
|
|
12
30
|
if (process.env[RUNTIME_HOME_ENV]) {
|
|
@@ -105,6 +123,16 @@ export function agentPeerAuditPath(aid) {
|
|
|
105
123
|
export function agentPersonalDir(aid) {
|
|
106
124
|
return path.join(agentDir(aid), 'personal');
|
|
107
125
|
}
|
|
126
|
+
/** 常驻自我定义目录:其中每个非空 .md 都会注入 system prompt。 */
|
|
127
|
+
export function agentSoulDir(aid) {
|
|
128
|
+
return path.join(agentPersonalDir(aid), 'soul');
|
|
129
|
+
}
|
|
130
|
+
/** soul 目录的机制指南文件名;注入时排除(它不是人格内容)。 */
|
|
131
|
+
export const SOUL_GUIDE_FILE = '00-GUIDE.md';
|
|
132
|
+
/** soul 目录里承载「我是谁」的分册。 */
|
|
133
|
+
export const SOUL_IDENTITY_FILE = '01-identity.md';
|
|
134
|
+
/** soul 目录里承载「性格与表达」的分册;创建时给的 persona 正文与旧版合集都落到这里。 */
|
|
135
|
+
export const SOUL_PERSONA_FILE = '02-persona.md';
|
|
108
136
|
/** Agent-owned Bootstrap completion welcome template. */
|
|
109
137
|
export function agentWelcomePath(aid) {
|
|
110
138
|
return path.join(agentPersonalDir(aid), 'welcome.md');
|
package/dist/product.js
CHANGED
|
@@ -16,6 +16,7 @@ export const MIN_ECWEB_VERSION = '0.0.8';
|
|
|
16
16
|
export const DAEMON_CONFIG_FILENAME = 'daemon.json';
|
|
17
17
|
export const DAEMON_SCHEMA_NAME = 'daemon';
|
|
18
18
|
export const RUNTIME_HOME_ENV = 'EVOLCORE_HOME';
|
|
19
|
+
export const TEST_TMPDIR_ENV = 'EVOLCORE_TEST_TMPDIR';
|
|
19
20
|
export const TARGET_PACKAGE_ROOT_ENV = 'EVOLCORE_TARGET_PACKAGE_ROOT';
|
|
20
21
|
export const SESSION_ID_ENV = 'EVOLCORE_SESSION_ID';
|
|
21
22
|
export const SELF_AID_ENV = 'EVOLCORE_SELF_AID';
|
|
@@ -22,8 +22,8 @@ export function resolveEffectiveResponseModeConfig(registry, config, resolvedCha
|
|
|
22
22
|
const modeSpecificParams = config.responseModeParams?.[resolved.mode.id] ?? {};
|
|
23
23
|
const modeConfig = {
|
|
24
24
|
...responseModeSchemaDefaults(resolved.mode),
|
|
25
|
-
...(resolvedChatMode !== undefined ? { chatmode: resolvedChatMode } : {}),
|
|
26
25
|
...modeSpecificParams,
|
|
26
|
+
...(resolvedChatMode !== undefined ? { chatmode: resolvedChatMode } : {}),
|
|
27
27
|
};
|
|
28
28
|
return { ...resolved, modeConfig };
|
|
29
29
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* V1 引擎 —— 单会话处理行为的载体。
|
|
3
3
|
*
|
|
4
|
-
* 对外只暴露 flowForChatMode:按 chatMode
|
|
4
|
+
* 对外只暴露 flowForChatMode:按 chatMode 取对应执行流(interactive / proactive)。
|
|
5
5
|
* chatMode 分流收拢于此,模式层(modes/single-session)与调用方不再散布分支。
|
|
6
6
|
*/
|
|
7
7
|
import { interactiveFlow } from './interactive-flow.js';
|
|
@@ -9,6 +9,7 @@ import { proactiveFlow } from './proactive-flow.js';
|
|
|
9
9
|
const FLOWS = {
|
|
10
10
|
interactive: interactiveFlow,
|
|
11
11
|
proactive: proactiveFlow,
|
|
12
|
+
paactive: interactiveFlow,
|
|
12
13
|
};
|
|
13
14
|
/** 按 chatMode 取处理流。 */
|
|
14
15
|
export function flowForChatMode(chatMode) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FIFOQueue } from '../../queues/fifo-queue.js';
|
|
2
2
|
import { flowForChatMode } from '../../engines/v1/index.js';
|
|
3
3
|
import { loadSchema } from '../../../config/schema-registry.js';
|
|
4
|
+
import { isChatMode } from '../../../core/message/peer-mode.js';
|
|
4
5
|
/**
|
|
5
6
|
* 模式桶 schema —— 候选值与默认值的**唯一事实源**,从当前 single-session schema
|
|
6
7
|
* 读取(随包分发、config schema 子命令可展示、write 时桶专项校验共用同一份)。
|
|
@@ -15,7 +16,7 @@ import { loadSchema } from '../../../config/schema-registry.js';
|
|
|
15
16
|
* 单会话响应模式(architecture.md §4.1)—— 合并原 interactive / proactive。
|
|
16
17
|
*
|
|
17
18
|
* 本层是薄包装:不含处理行为,全部钩子委托 V1 引擎的 flow。chatMode 决定用哪个
|
|
18
|
-
* flow(interactive / proactive),取值来自 modeConfig.chatMode(宿主按配置层级
|
|
19
|
+
* flow(interactive / proactive;paactive 复用 interactive),取值来自 modeConfig.chatMode(宿主按配置层级
|
|
19
20
|
* 解析后注入,见 implementation-plan.md §三;无 auto 值)。
|
|
20
21
|
*/
|
|
21
22
|
export class SingleSessionMode {
|
|
@@ -53,7 +54,11 @@ export class SingleSessionMode {
|
|
|
53
54
|
chatMode() {
|
|
54
55
|
const cfg = this.context?.modeConfig;
|
|
55
56
|
const value = cfg?.chatmode ?? cfg?.chatMode;
|
|
56
|
-
|
|
57
|
+
if (value === undefined)
|
|
58
|
+
return 'interactive';
|
|
59
|
+
if (!isChatMode(value))
|
|
60
|
+
throw new Error(`[single-session] unknown chatMode: ${String(value)}`);
|
|
61
|
+
return value;
|
|
57
62
|
}
|
|
58
63
|
flow() {
|
|
59
64
|
return flowForChatMode(this.chatMode());
|
|
@@ -2,6 +2,7 @@ import crypto from 'crypto';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { CronExpressionParser } from 'cron-parser';
|
|
4
4
|
import { logger } from '../utils/logger.js';
|
|
5
|
+
import { isNoopText } from '../core/message/message-utils.js';
|
|
5
6
|
import { matchTriggerEvent, TriggerEventSource } from './event-source.js';
|
|
6
7
|
import { definitionRevision, executionTimeoutMs, parseDurationMs, previewText, renderTemplate, resolveScriptPath, sha256, validateConcurrencyCombination, } from './validation.js';
|
|
7
8
|
import { TargetSessionLockRegistry } from './session-lock.js';
|
|
@@ -1042,10 +1043,11 @@ export class TriggerRuntimeScheduler {
|
|
|
1042
1043
|
},
|
|
1043
1044
|
});
|
|
1044
1045
|
const sentinel = definition.execution.noopSentinel ?? '[[NOOP]]';
|
|
1046
|
+
const isNoop = daemonReply.outcome === 'success' && isNoopText(daemonReply.text, sentinel);
|
|
1045
1047
|
const reply = {
|
|
1046
1048
|
...daemonReply,
|
|
1047
|
-
outcome:
|
|
1048
|
-
text:
|
|
1049
|
+
outcome: isNoop ? 'noop' : daemonReply.outcome,
|
|
1050
|
+
text: isNoop ? '' : daemonReply.text,
|
|
1049
1051
|
};
|
|
1050
1052
|
return {
|
|
1051
1053
|
branch: branchFromReply(reply),
|
|
@@ -1444,10 +1446,11 @@ export class TriggerRuntimeScheduler {
|
|
|
1444
1446
|
},
|
|
1445
1447
|
});
|
|
1446
1448
|
const sentinel = definition.execution.noopSentinel ?? '[[NOOP]]';
|
|
1449
|
+
const isNoop = daemonReply.outcome === 'success' && isNoopText(daemonReply.text, sentinel);
|
|
1447
1450
|
const reply = {
|
|
1448
1451
|
...daemonReply,
|
|
1449
|
-
outcome:
|
|
1450
|
-
text:
|
|
1452
|
+
outcome: isNoop ? 'noop' : daemonReply.outcome,
|
|
1453
|
+
text: isNoop ? '' : daemonReply.text,
|
|
1451
1454
|
};
|
|
1452
1455
|
return {
|
|
1453
1456
|
branch: branchFromReply(reply),
|
|
@@ -9,6 +9,10 @@ const MAX_EXECUTION_TIMEOUT_MS = 2_147_483_647;
|
|
|
9
9
|
export const TRIGGER_SCHEMA_VERSION = 3.1;
|
|
10
10
|
const LEGACY_TRIGGER_SCHEMA_VERSION = 4;
|
|
11
11
|
const DEFAULT_NOOP_SENTINEL = '[[NOOP]]';
|
|
12
|
+
/** Only a leading sentinel controls delivery; later mentions are ordinary prose. */
|
|
13
|
+
export function isTriggerNoopText(text, sentinel) {
|
|
14
|
+
return !!sentinel && text.trimStart().startsWith(sentinel);
|
|
15
|
+
}
|
|
12
16
|
const LIMIT_DURATION_RE = /^[1-9]\d*(s|m|h|d)$/;
|
|
13
17
|
const TRIGGER_EFFORTS = new Set(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
14
18
|
const PERMISSION_MODES = new Set([
|
|
@@ -450,7 +450,7 @@ export function _setDictPath(p) {
|
|
|
450
450
|
// - 中文:上下文过长
|
|
451
451
|
//
|
|
452
452
|
// ⚠️ 新增措辞统一往这里加,不要再在各模块本地复制正则。
|
|
453
|
-
export const CONTEXT_TOO_LONG_PATTERN = /prompt is too long|input is too long|context too long|context limit|context_length_exceeded|context_window_exceeded|context window limit|reached its context window|exceed(?:s|ed)? the context window|maximum context length
|
|
453
|
+
export const CONTEXT_TOO_LONG_PATTERN = /prompt is too long|input is too long|context (?:is )?too (?:long|large)|context limit|context_length_exceeded|context_window_exceeded|context window limit|reached its context window|exceed(?:s|ed)? the context window|maximum context length|上下文(?:过长|过大)/i;
|
|
454
454
|
/** 判断一段文本是否为「上下文过长」类错误。空文本返回 false。 */
|
|
455
455
|
export function isContextTooLongText(text) {
|
|
456
456
|
if (!text)
|
|
@@ -459,6 +459,7 @@ export function isContextTooLongText(text) {
|
|
|
459
459
|
}
|
|
460
460
|
// ── 错误分类 / 重试 / 消息 ──────────────────────────────────────────
|
|
461
461
|
const RETRYABLE_HTTP_STATUS_PATTERN = /\b(?:api error|http|status|last status|status code)\s*:?\s*(?:429|5\d{2})\b|\b429\b[^.\n\r]*(?:too many requests|rate limit)|(?:too many requests|rate limit)[^.\n\r]*\b429\b/i;
|
|
462
|
+
const GATEWAY_REQUEST_TIMEOUT_PATTERN = /\bgateway request timed out\b/i;
|
|
462
463
|
function hasRetryableHttpStatus(text) {
|
|
463
464
|
return RETRYABLE_HTTP_STATUS_PATTERN.test(text);
|
|
464
465
|
}
|
|
@@ -500,6 +501,9 @@ export function classifyError(error) {
|
|
|
500
501
|
if (error?.code === CLAUDE_CODE_STARTUP_FAILED) {
|
|
501
502
|
return ErrorType.CLAUDE_CODE_STARTUP_FAILED;
|
|
502
503
|
}
|
|
504
|
+
if (msg.includes('context_compact_failed') || isContextTooLongText(getErrorRawText(error))) {
|
|
505
|
+
return ErrorType.CONTEXT_TOO_LONG;
|
|
506
|
+
}
|
|
503
507
|
// 字典优先 — 命中则直接返回
|
|
504
508
|
const rule = matchErrorRule(msg);
|
|
505
509
|
if (rule) {
|
|
@@ -512,9 +516,6 @@ export function classifyError(error) {
|
|
|
512
516
|
return ErrorType.UNKNOWN;
|
|
513
517
|
}
|
|
514
518
|
// 内置兜底规则(结构性、稳定的错误模式)
|
|
515
|
-
if (msg.includes('context_compact_failed') || isContextTooLongText(msg)) {
|
|
516
|
-
return ErrorType.CONTEXT_TOO_LONG;
|
|
517
|
-
}
|
|
518
519
|
if (msg.includes('invalid_model') || msg.includes('model_not_found')
|
|
519
520
|
|| msg.includes('no such model') || msg.includes('unknown model')
|
|
520
521
|
|| /api error: 404\b/.test(msg)) {
|
|
@@ -526,7 +527,7 @@ export function classifyError(error) {
|
|
|
526
527
|
if (hasRetryableHttpStatus(msg)) {
|
|
527
528
|
return ErrorType.API_ERROR;
|
|
528
529
|
}
|
|
529
|
-
if (msg.includes('timeout') || msg.includes('etimedout')) {
|
|
530
|
+
if (msg.includes('timeout') || msg.includes('etimedout') || GATEWAY_REQUEST_TIMEOUT_PATTERN.test(msg)) {
|
|
530
531
|
return ErrorType.SDK_TIMEOUT;
|
|
531
532
|
}
|
|
532
533
|
if (msg.includes('enoent') || msg.includes('corrupt')) {
|
|
@@ -558,6 +559,8 @@ export function isRetryableError(error) {
|
|
|
558
559
|
const lower = msg.toLowerCase();
|
|
559
560
|
if (lower.includes('invalid jsonl session file') || lower.includes('invalid session file'))
|
|
560
561
|
return false;
|
|
562
|
+
if (lower.includes('context_compact_failed') || isContextTooLongText(getErrorRawText(error)))
|
|
563
|
+
return false;
|
|
561
564
|
// The idle watchdog emits this exact terminal error when a runner stops
|
|
562
565
|
// producing events. The provider session remains resumable, so the task
|
|
563
566
|
// recovery trigger must be allowed to continue the original session.
|
|
@@ -575,6 +578,8 @@ export function isRetryableError(error) {
|
|
|
575
578
|
// 包成 "exceeded retry limit, last status: 429 Too Many Requests"。
|
|
576
579
|
if (hasRetryableHttpStatus(lower))
|
|
577
580
|
return true;
|
|
581
|
+
if (GATEWAY_REQUEST_TIMEOUT_PATTERN.test(lower))
|
|
582
|
+
return true;
|
|
578
583
|
return false;
|
|
579
584
|
}
|
|
580
585
|
function sandboxInitializationErrorMessage(error, prefix) {
|
|
@@ -676,7 +681,7 @@ export function getErrorMessage(error, terminalReason, includeEmoji = true) {
|
|
|
676
681
|
}
|
|
677
682
|
// 字典优先 — 命中且有自定义消息则直接返回
|
|
678
683
|
const rule = matchErrorRule(msg.toLowerCase());
|
|
679
|
-
if (rule?.message)
|
|
684
|
+
if (rule?.message && (!isContextTooLongText(msg) || rule.type === ErrorType.CONTEXT_TOO_LONG))
|
|
680
685
|
return rule.message;
|
|
681
686
|
// 内置兜底规则(结构性错误)
|
|
682
687
|
if (msg.includes('CONTEXT_COMPACT_FAILED') || isContextTooLongText(msg)) {
|
|
@@ -701,7 +706,7 @@ export function getErrorMessage(error, terminalReason, includeEmoji = true) {
|
|
|
701
706
|
if (hasRetryableHttpStatus(msg)) {
|
|
702
707
|
return `${warnPrefix}API 服务暂时不可用,请稍后重试`;
|
|
703
708
|
}
|
|
704
|
-
if (msg.includes('timeout')) {
|
|
709
|
+
if (msg.includes('timeout') || GATEWAY_REQUEST_TIMEOUT_PATTERN.test(msg)) {
|
|
705
710
|
return `${warnPrefix}请求超时,请重试`;
|
|
706
711
|
}
|
|
707
712
|
if (msg)
|
package/dist/utils/logger.js
CHANGED
|
@@ -83,6 +83,10 @@ export function logPreview(value, maxLength = 240) {
|
|
|
83
83
|
const singleLine = text.replace(/\s+/gu, ' ').trim();
|
|
84
84
|
return singleLine.length <= maxLength ? singleLine : `${singleLine.slice(0, Math.max(0, maxLength - 3)).trimEnd()}...`;
|
|
85
85
|
}
|
|
86
|
+
function isMissingLogContext(value) {
|
|
87
|
+
return typeof value !== 'string' || !value.trim()
|
|
88
|
+
|| ['unknown', '<unknown>', '<none>', 'undefined', 'null'].includes(value.trim().toLowerCase());
|
|
89
|
+
}
|
|
86
90
|
/** Keep structured log streams joinable even when a producer only knows one
|
|
87
91
|
* of the lifecycle identifiers. Existing fields remain source-of-truth; this
|
|
88
92
|
* only supplies aliases used by daily interception analysis. */
|
|
@@ -122,7 +126,10 @@ export function normalizeStructuredLog(data) {
|
|
|
122
126
|
?? nested?.requestId
|
|
123
127
|
?? nested?.request_id;
|
|
124
128
|
const sessionId = data.sessionId ?? data.session_id ?? nested?.sessionId ?? nested?.session_id;
|
|
125
|
-
const
|
|
129
|
+
const agentAidCandidates = [data.agentAid, data.agent_aid, data.selfAid,
|
|
130
|
+
nested?.agentAid, nested?.agent_aid, nested?.selfAid];
|
|
131
|
+
const agentAid = agentAidCandidates.find(value => !isMissingLogContext(value))
|
|
132
|
+
?? agentAidCandidates.find(value => value != null);
|
|
126
133
|
const rawAgentName = data.agentName ?? data.agent_name ?? nested?.agentName ?? nested?.agent_name;
|
|
127
134
|
// Lifecycle streams should carry both the stable AID and a display label.
|
|
128
135
|
// When a producer only knows the AID, use that same value as the label so
|
|
@@ -137,8 +144,7 @@ export function normalizeStructuredLog(data) {
|
|
|
137
144
|
const rawPermissionMode = data.permissionMode ?? data.permission_mode ?? nested?.permissionMode ?? nested?.permission_mode;
|
|
138
145
|
// Normalize legacy values at the log boundary. Preserve an explicit
|
|
139
146
|
// `unknown` marker for records that genuinely arrived without context.
|
|
140
|
-
const permissionMode =
|
|
141
|
-
&& rawPermissionMode !== 'unknown'
|
|
147
|
+
const permissionMode = !isMissingLogContext(rawPermissionMode)
|
|
142
148
|
? normalizeExecutionPermissionMode(rawPermissionMode)
|
|
143
149
|
: rawPermissionMode;
|
|
144
150
|
const toolName = data.toolName ?? data.tool ?? data.name ?? nested?.toolName ?? nested?.name;
|
|
@@ -194,7 +200,10 @@ export function normalizeStructuredLog(data) {
|
|
|
194
200
|
}))
|
|
195
201
|
: undefined;
|
|
196
202
|
const missingContextFields = lifecycleRecord
|
|
197
|
-
? ['sessionId', 'agentAid', 'permissionMode'].filter(field =>
|
|
203
|
+
? ['sessionId', 'agentAid', 'permissionMode'].filter(field => {
|
|
204
|
+
const value = { sessionId, agentAid, permissionMode: rawPermissionMode }[field];
|
|
205
|
+
return isMissingLogContext(value);
|
|
206
|
+
})
|
|
198
207
|
: [];
|
|
199
208
|
return {
|
|
200
209
|
...data,
|