evolcore 0.0.1 → 0.0.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 +64 -0
- package/LICENSE +21 -0
- package/MIGRATION-0.5.0.md +378 -0
- package/README.md +318 -14
- package/ROLE_ACCESS_CONTROL.md +174 -0
- package/assets/.env.template +4 -0
- package/bin/ec-safe-output.js +161 -0
- package/bin/ec.js +29 -0
- package/dist/agents/baseagent.js +163 -0
- package/dist/agents/claude-runner.js +2565 -0
- package/dist/agents/codex-app-server-client.js +448 -0
- package/dist/agents/codex-runner.js +2682 -0
- package/dist/agents/gemini-runner.js +666 -0
- package/dist/agents/runner-types.js +75 -0
- package/dist/aun/aid/agentmd.js +216 -0
- package/dist/aun/aid/client.js +132 -0
- package/dist/aun/aid/control-aid.js +91 -0
- package/dist/aun/aid/identity.js +518 -0
- package/dist/aun/aid/index.js +4 -0
- package/dist/aun/aid/store.js +74 -0
- package/dist/aun/aid/types.js +1 -0
- package/dist/aun/aid/validation.js +21 -0
- package/dist/aun/group-identity.js +10 -0
- package/dist/aun/msg/group-index.js +6 -0
- package/dist/aun/msg/group.js +1231 -0
- package/dist/aun/msg/history.js +123 -0
- package/dist/aun/msg/index.js +5 -0
- package/dist/aun/msg/p2p.js +393 -0
- package/dist/aun/msg/payload-type.js +27 -0
- package/dist/aun/msg/upload.js +137 -0
- package/dist/aun/outbox.js +168 -0
- package/dist/aun/rpc/caller.js +42 -0
- package/dist/aun/rpc/connection.js +25 -0
- package/dist/aun/rpc/index.js +2 -0
- package/dist/aun/service-proxy.js +225 -0
- package/dist/aun/storage/download.js +29 -0
- package/dist/aun/storage/index.js +3 -0
- package/dist/aun/storage/manage.js +10 -0
- package/dist/aun/storage/upload.js +68 -0
- package/dist/channels/aun.js +4164 -0
- package/dist/channels/contact-bind-code.js +134 -0
- package/dist/channels/daemon.js +422 -0
- package/dist/channels/dingtalk.js +1479 -0
- package/dist/channels/feishu.js +1865 -0
- package/dist/channels/qqbot.js +409 -0
- package/dist/channels/wechat.js +817 -0
- package/dist/channels/wecom-card.js +101 -0
- package/dist/channels/wecom-onboarding.js +82 -0
- package/dist/channels/wecom-state.js +191 -0
- package/dist/channels/wecom.js +1157 -0
- package/dist/cli/agent-command.js +642 -0
- package/dist/cli/agent.js +1059 -0
- package/dist/cli/aun-commands.js +2003 -0
- package/dist/cli/bench.js +1228 -0
- package/dist/cli/cli-argv.js +66 -0
- package/dist/cli/code-stats.js +329 -0
- package/dist/cli/command-log.js +82 -0
- package/dist/cli/config-selector.js +69 -0
- package/dist/cli/config.js +261 -0
- package/dist/cli/contact.js +71 -0
- package/dist/cli/ctl-command.js +62 -0
- package/dist/cli/daemon-commands.js +2750 -0
- package/dist/cli/fs-command.js +1447 -0
- package/dist/cli/handoff-command.js +302 -0
- package/dist/cli/help.js +35 -0
- package/dist/cli/index.js +374 -0
- package/dist/cli/init-channel.js +1372 -0
- package/dist/cli/init.js +590 -0
- package/dist/cli/link-rules.js +240 -0
- package/dist/cli/model.js +591 -0
- package/dist/cli/net-check.js +723 -0
- package/dist/cli/queue-command.js +150 -0
- package/dist/cli/raw-key-input.js +25 -0
- package/dist/cli/response.js +344 -0
- package/dist/cli/restart-monitor.js +480 -0
- package/dist/cli/stats.js +609 -0
- package/dist/cli/task-context.js +80 -0
- package/dist/cli/trigger-command.js +545 -0
- package/dist/cli/version.js +93 -0
- package/dist/cli/watch-logs.js +33 -0
- package/dist/cli/watch-msg.js +673 -0
- package/dist/config/boot-log.js +266 -0
- package/dist/config/builtin-role-templates.js +42 -0
- package/dist/config/builtin-roles.js +91 -0
- package/dist/config/config-batch-get.js +11 -0
- package/dist/config/config-field-policy.js +261 -0
- package/dist/config/config-manager.js +1120 -0
- package/dist/config/config-operation-service.js +384 -0
- package/dist/config/contact-alias.js +68 -0
- package/dist/config/contact-book-store.js +454 -0
- package/dist/config/contact-book-v2-startup.js +35 -0
- package/dist/config/contact-book.js +224 -0
- package/dist/config/contact-operation-service.js +110 -0
- package/dist/config/gateway-config.js +858 -0
- package/dist/config/lifecycle.js +17 -0
- package/dist/config/mention-mode.js +27 -0
- package/dist/config/merge.js +161 -0
- package/dist/config/owner-policy.js +4 -0
- package/dist/config/peer-role-resolver.js +218 -0
- package/dist/config/resolved-config-op.js +483 -0
- package/dist/config/role-config-v4-startup.js +32 -0
- package/dist/config/role-config-v5-startup.js +27 -0
- package/dist/config/role-ranks.js +18 -0
- package/dist/config/role-schema.js +105 -0
- package/dist/config/role-service.js +156 -0
- package/dist/config/role-store.js +215 -0
- package/dist/config/roles.js +64 -0
- package/dist/config/schema-registry.js +154 -0
- package/dist/config/snapshot.js +598 -0
- package/dist/config-store.js +501 -0
- package/dist/core/auth/agent-delegation.js +111 -0
- package/dist/core/auth/auth-gateway.js +166 -0
- package/dist/core/auth/authenticated-actor.js +6 -0
- package/dist/core/auth/authorization-audit.js +119 -0
- package/dist/core/auth/operation-authorizer.js +720 -0
- package/dist/core/auth/operation-catalog.js +731 -0
- package/dist/core/baseagent-loader.js +54 -0
- package/dist/core/bootstrap-service.js +175 -0
- package/dist/core/capability/capability-manager.js +316 -0
- package/dist/core/capability/providers/claude-capability-provider.js +176 -0
- package/dist/core/capability/providers/codex-capability-provider.js +148 -0
- package/dist/core/capability/providers/gemini-capability-provider.js +10 -0
- package/dist/core/capability/types.js +27 -0
- package/dist/core/causation/audit.js +103 -0
- package/dist/core/causation/aun-association.js +111 -0
- package/dist/core/causation/context.js +93 -0
- package/dist/core/causation/index.js +4 -0
- package/dist/core/causation/types.js +2 -0
- package/dist/core/channel-loader.js +277 -0
- package/dist/core/command/agent-control.js +616 -0
- package/dist/core/command/cli-intent-parser.js +225 -0
- package/dist/core/command/command-handler.js +1733 -0
- package/dist/core/command/connect-menu.js +374 -0
- package/dist/core/command/menu-handler.js +3452 -0
- package/dist/core/command/menu-protocol.js +247 -0
- package/dist/core/command/role-menu.js +1623 -0
- package/dist/core/command/slash-gate.js +148 -0
- package/dist/core/command/slash-handler.js +3066 -0
- package/dist/core/daemon-file-cache.js +222 -0
- package/dist/core/event-bus.js +32 -0
- package/dist/core/event-catalog.js +810 -0
- package/dist/core/evolagent-registry.js +545 -0
- package/dist/core/evolagent.js +342 -0
- package/dist/core/handoff/dispatcher.js +229 -0
- package/dist/core/handoff/mutex.js +46 -0
- package/dist/core/handoff/runtime.js +324 -0
- package/dist/core/handoff/store.js +537 -0
- package/dist/core/handoff/types.js +12 -0
- package/dist/core/inference/text-inference.js +173 -0
- package/dist/core/interaction-registration.js +10 -0
- package/dist/core/interaction-router.js +278 -0
- package/dist/core/message/create-status.js +67 -0
- package/dist/core/message/im-renderer.js +659 -0
- package/dist/core/message/items-formatter.js +76 -0
- package/dist/core/message/logical-queue-bridge.js +123 -0
- package/dist/core/message/message-bridge.js +874 -0
- package/dist/core/message/message-cache.js +56 -0
- package/dist/core/message/message-log.js +339 -0
- package/dist/core/message/message-processor.js +4 -0
- package/dist/core/message/message-queue.js +1446 -0
- package/dist/core/message/message-utils.js +76 -0
- package/dist/core/message/peer-mode.js +105 -0
- package/dist/core/message/pending-hints.js +232 -0
- package/dist/core/message/response-depth.js +33 -0
- package/dist/core/message/response-engine.js +4020 -0
- package/dist/core/message/response-snapshot.js +83 -0
- package/dist/core/message/send-receipt.js +24 -0
- package/dist/core/message/stream-debouncer.js +139 -0
- package/dist/core/message/stream-idle-monitor.js +124 -0
- package/dist/core/model/config-scope.js +162 -0
- package/dist/core/model/field-scope.js +78 -0
- package/dist/core/model/model-catalog.js +227 -0
- package/dist/core/model/model-diagnostics.js +182 -0
- package/dist/core/model/model-permission.js +90 -0
- package/dist/core/permission/approval-gateway.js +1017 -0
- package/dist/core/permission/ec-command-parser.js +347 -0
- package/dist/core/permission/execution-sandbox.js +16 -0
- package/dist/core/permission/index.js +6 -0
- package/dist/core/permission/mode.js +24 -0
- package/dist/core/permission/sandbox-runtime.js +265 -0
- package/dist/core/permission/tool-policy.js +1019 -0
- package/dist/core/permission/unix-socket-policy.js +99 -0
- package/dist/core/protected-paths.js +332 -0
- package/dist/core/relation/peer-identity.js +222 -0
- package/dist/core/relation/peer-key.js +1 -0
- package/dist/core/role/runtime-policy.js +141 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +218 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +333 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +181 -0
- package/dist/core/session/session-file-adapter.js +7 -0
- package/dist/core/session/session-file-health.js +45 -0
- package/dist/core/session/session-fs-store.js +273 -0
- package/dist/core/session/session-key.js +24 -0
- package/dist/core/session/session-manager.js +1643 -0
- package/dist/core/session/session-mapper.js +100 -0
- package/dist/core/session/session-renew.js +314 -0
- package/dist/core/session/session-title.js +128 -0
- package/dist/core/session/session-turn-coordinator.js +205 -0
- package/dist/core/session/session-turns.js +67 -0
- package/dist/core/system-channels.js +29 -0
- package/dist/eck/baseagent-caps.js +18 -0
- package/dist/eck/detect.js +47 -0
- package/dist/eck/group-rules-sync.js +345 -0
- package/dist/eck/init.js +77 -0
- package/dist/eck/kit-renderer.js +359 -0
- package/dist/eck/manifest-engine.js +446 -0
- package/dist/eck/message-renderer.js +199 -0
- package/dist/eck/rules-loader.js +28 -0
- package/dist/index.js +2926 -4
- package/dist/ipc.js +777 -0
- package/dist/paths.js +262 -0
- package/dist/product.js +18 -0
- package/dist/response-system/context-builder.js +71 -0
- package/dist/response-system/coordinator.js +117 -0
- package/dist/response-system/decision-executor.js +86 -0
- package/dist/response-system/engines/v1/index.js +21 -0
- package/dist/response-system/engines/v1/interactive-flow.js +27 -0
- package/dist/response-system/engines/v1/proactive-flow.js +137 -0
- package/dist/response-system/engines/v1/types.js +1 -0
- package/dist/response-system/extensions.js +41 -0
- package/dist/response-system/index.js +6 -0
- package/dist/response-system/modes/index.js +7 -0
- package/dist/response-system/modes/single-session/index.js +72 -0
- package/dist/response-system/queues/fifo-queue.js +44 -0
- package/dist/response-system/queues/index.js +6 -0
- package/dist/response-system/queues/lifo-queue.js +42 -0
- package/dist/response-system/queues/priority-queue.js +63 -0
- package/dist/response-system/registry.js +97 -0
- package/dist/response-system/resolver.js +37 -0
- package/dist/response-system/selector.js +23 -0
- package/dist/response-system/types.js +7 -0
- package/dist/stats/billing.js +163 -0
- package/dist/stats/budget.js +93 -0
- package/dist/stats/db.js +403 -0
- package/dist/stats/eck-vars.js +89 -0
- package/dist/stats/index.js +11 -0
- package/dist/stats/normalizer.js +80 -0
- package/dist/stats/price-resolver.js +138 -0
- package/dist/stats/query.js +763 -0
- package/dist/stats/role-budget.js +168 -0
- package/dist/stats/writer.js +151 -0
- package/dist/trigger/anomaly-store.js +258 -0
- package/dist/trigger/audit.js +152 -0
- package/dist/trigger/event-source.js +119 -0
- package/dist/trigger/feedback.js +685 -0
- package/dist/trigger/history.js +290 -0
- package/dist/trigger/manager.js +294 -0
- package/dist/trigger/parser.js +595 -0
- package/dist/trigger/patch.js +155 -0
- package/dist/trigger/scheduler.js +1602 -0
- package/dist/trigger/script-executor.js +155 -0
- package/dist/trigger/state.js +145 -0
- package/dist/trigger/types.js +1 -0
- package/dist/trigger/validation.js +634 -0
- package/dist/types.js +12 -0
- package/dist/utils/aid-bind.js +313 -0
- package/dist/utils/atomic-write.js +95 -0
- package/dist/utils/avatar-upload.js +123 -0
- package/dist/utils/cross-platform.js +297 -0
- package/dist/utils/ecweb-utils.js +73 -0
- package/dist/utils/error-dict.json +153 -0
- package/dist/utils/error-utils.js +349 -0
- package/dist/utils/instance-registry.js +444 -0
- package/dist/utils/locale.js +21 -0
- package/dist/utils/log-writer.js +270 -0
- package/dist/utils/logger.js +89 -0
- package/dist/utils/markdown-to-plain-text.js +20 -0
- package/dist/utils/media-cache.js +274 -0
- package/dist/utils/model-prices.jsonl +20 -0
- package/dist/utils/npm-ops.js +210 -0
- package/dist/utils/process-introspect.js +133 -0
- package/dist/utils/process-tree-stats.js +271 -0
- package/dist/utils/project-path.js +74 -0
- package/dist/utils/restart-safety.js +31 -0
- package/dist/utils/stats.js +410 -0
- package/dist/utils/system-memory.js +62 -0
- package/dist/utils/tool-summary.js +284 -0
- package/dist/utils/welcome.js +268 -0
- package/kits/docs/GUIDE.md +20 -0
- package/kits/docs/INDEX.md +66 -0
- package/kits/docs/aun/CHEATSHEET.md +19 -0
- package/kits/docs/aun/SYNC_PROTOCOL.md +15 -0
- package/kits/docs/channels/aun.md +65 -0
- package/kits/docs/channels/feishu.md +56 -0
- package/kits/docs/context-assembly.md +366 -0
- package/kits/docs/eck_templates/GUIDE.template.md +22 -0
- package/kits/docs/eck_templates/INDEX.template.md +28 -0
- package/kits/docs/eck_templates/path-registry.template.md +33 -0
- package/kits/docs/eck_templates/runtime.template.md +19 -0
- package/kits/docs/evolcore/INDEX.md +68 -0
- package/kits/docs/evolcore/agent.md +77 -0
- package/kits/docs/evolcore/aid.md +52 -0
- package/kits/docs/evolcore/config.md +149 -0
- package/kits/docs/evolcore/contact.md +57 -0
- package/kits/docs/evolcore/ctl.md +46 -0
- package/kits/docs/evolcore/event.md +216 -0
- package/kits/docs/evolcore/fs-architecture.md +1215 -0
- package/kits/docs/evolcore/fs.md +110 -0
- package/kits/docs/evolcore/group-fs.md +17 -0
- package/kits/docs/evolcore/group-rules.md +226 -0
- package/kits/docs/evolcore/group.md +150 -0
- package/kits/docs/evolcore/model.md +50 -0
- package/kits/docs/evolcore/msg.md +136 -0
- package/kits/docs/evolcore/response.md +75 -0
- package/kits/docs/evolcore/rpc.md +37 -0
- package/kits/docs/evolcore/self-summary.md +29 -0
- package/kits/docs/evolcore/stats.md +83 -0
- package/kits/docs/evolcore/storage.md +50 -0
- package/kits/docs/evolcore/trigger.md +539 -0
- package/kits/docs/identity/AID_PROFILE_SPEC.md +26 -0
- package/kits/docs/identity/PATH_OPS.md +16 -0
- package/kits/docs/identity/ROLE_DETAIL.md +23 -0
- package/kits/docs/identity/identity-tools.md +26 -0
- package/kits/docs/path-registry.md +43 -0
- package/kits/docs/prompt-loading-architecture.md +266 -0
- package/kits/docs/venues/aun-group.md +45 -0
- package/kits/docs/venues/aun-private.md +10 -0
- package/kits/docs/venues/client-desktop.md +10 -0
- package/kits/docs/venues/client-mobile.md +10 -0
- package/kits/docs/venues/feishu-group.md +13 -0
- package/kits/docs/venues/feishu-private.md +9 -0
- package/kits/docs/venues/group.md +25 -0
- package/kits/docs/venues/private.md +10 -0
- package/kits/eck_manifest.auxiliary.json +43 -0
- package/kits/eck_manifest.json +203 -0
- package/kits/eck_message_manifest.json +63 -0
- package/kits/migrations/README-role-config-v4.md +32 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +747 -0
- package/kits/migrations/migrate-role-config-v4.mjs +623 -0
- package/kits/migrations/migrate-role-config-v5.mjs +346 -0
- package/kits/migrations/rename-config-file.mjs +99 -0
- package/kits/rules/01-overview.md +142 -0
- package/kits/rules/02-navigation.md +76 -0
- package/kits/rules/03-identity.md +34 -0
- package/kits/rules/04-relation.md +59 -0
- package/kits/rules/05-venue.md +44 -0
- package/kits/rules/06-channel.md +59 -0
- package/kits/schemas/_meta.json +32 -0
- package/kits/schemas/agent-config.schema.1.json +177 -0
- package/kits/schemas/agent-config.schema.2.json +239 -0
- package/kits/schemas/agent-config.schema.3.json +119 -0
- package/kits/schemas/agent-config.schema.4.json +208 -0
- package/kits/schemas/agent-config.schema.5.json +326 -0
- package/kits/schemas/agent-config.schema.6.json +322 -0
- package/kits/schemas/contact-book.schema.1.json +36 -0
- package/kits/schemas/contact-book.schema.2.json +43 -0
- package/kits/schemas/daemon.schema.1.json +90 -0
- package/kits/schemas/defaults.schema.1.json +81 -0
- package/kits/schemas/menu-exec-schema-commands.md +208 -0
- package/kits/schemas/migrations/README.md +28 -0
- package/kits/schemas/relation-config.schema.1.json +158 -0
- package/kits/schemas/relation-config.schema.2.json +73 -0
- package/kits/schemas/relation-config.schema.3.json +50 -0
- package/kits/schemas/relation-config.schema.4.json +47 -0
- package/kits/schemas/relation-config.schema.5.json +47 -0
- package/kits/schemas/role-config.schema.1.json +201 -0
- package/kits/schemas/role-registry.schema.1.json +35 -0
- package/kits/schemas/single-session.schema.1.json +31 -0
- package/kits/templates/bootstrap-welcome.md +15 -0
- package/kits/templates/message-fragments/handoff-request-to-target.md +13 -0
- package/kits/templates/message-fragments/handoff-response-to-origin.md +10 -0
- package/kits/templates/message-fragments/inject-default.md +2 -0
- package/kits/templates/message-fragments/item.md +2 -0
- package/kits/templates/roles/admin.json +9 -0
- package/kits/templates/roles/member.json +41 -0
- package/kits/templates/roles/owner.json +9 -0
- package/kits/templates/roles/visitor.json +40 -0
- package/kits/templates/system-fragments/baseagent.md +14 -0
- package/kits/templates/system-fragments/bootstrap.md +16 -0
- package/kits/templates/system-fragments/channel.md +48 -0
- package/kits/templates/system-fragments/commands.md +28 -0
- package/kits/templates/system-fragments/identity.md +11 -0
- package/kits/templates/system-fragments/relation.md +19 -0
- package/kits/templates/system-fragments/session.md +53 -0
- package/kits/templates/system-fragments/venue.md +31 -0
- package/package.json +50 -15
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { isEckSnapshotsEnabled } from '../config-store.js';
|
|
4
|
+
import { eckDebugDir } from '../paths.js';
|
|
5
|
+
import { logger } from '../utils/logger.js';
|
|
6
|
+
import { loadManifest, loadManifestMeta, invalidateManifestCache, evaluateWhen, renderTemplate, renderLoopSection, resolvePathWithDiag, loadSectionFiles, loadChildTemplate, buildPathMappings, shortenPath, } from './manifest-engine.js';
|
|
7
|
+
const DEFAULT_MANIFEST_FILE = 'eck_manifest.json';
|
|
8
|
+
// ── Caches ──
|
|
9
|
+
const _sessionPathCache = new Map();
|
|
10
|
+
function getSessionCache(sessionId) {
|
|
11
|
+
let cache = _sessionPathCache.get(sessionId);
|
|
12
|
+
if (!cache) {
|
|
13
|
+
cache = new Map();
|
|
14
|
+
_sessionPathCache.set(sessionId, cache);
|
|
15
|
+
}
|
|
16
|
+
return cache;
|
|
17
|
+
}
|
|
18
|
+
export function loadKitManifest() {
|
|
19
|
+
const sections = loadManifest(DEFAULT_MANIFEST_FILE);
|
|
20
|
+
logger.info(`[KitRenderer] Loaded manifest: ${sections.length} sections`);
|
|
21
|
+
}
|
|
22
|
+
export function invalidateKitCache() {
|
|
23
|
+
invalidateManifestCache();
|
|
24
|
+
_sessionPathCache.clear();
|
|
25
|
+
}
|
|
26
|
+
export function invalidateSessionCache(sessionId) {
|
|
27
|
+
_sessionPathCache.delete(sessionId);
|
|
28
|
+
}
|
|
29
|
+
// ── Main render ──
|
|
30
|
+
/**
|
|
31
|
+
* 渲染单个 section 的一份文件内容。
|
|
32
|
+
* - 有 loop:file 作为 wrapper,加载 childFile,走三段式 renderLoopSection。
|
|
33
|
+
* - 无 loop:needsInjection 则模板渲染,否则原样。
|
|
34
|
+
* 系统提示词层的 loop 数据视为可信(背压信号等),不做 content 哨兵化。
|
|
35
|
+
*/
|
|
36
|
+
function renderSectionContent(section, rawContent, vars) {
|
|
37
|
+
if (section.loop) {
|
|
38
|
+
const childTpl = loadChildTemplate(section.loop.childFile, vars);
|
|
39
|
+
if (childTpl === null)
|
|
40
|
+
return ''; // child 模板缺失 → 该段落空
|
|
41
|
+
return renderLoopSection(rawContent, childTpl, section.loop.forEach, vars,
|
|
42
|
+
/* stripBlankLines */ true, section.loop.separator ?? '\n');
|
|
43
|
+
}
|
|
44
|
+
return section.needsInjection ? renderTemplate(rawContent, vars) : rawContent;
|
|
45
|
+
}
|
|
46
|
+
export function renderKitSections(ctx, manifestFile = DEFAULT_MANIFEST_FILE) {
|
|
47
|
+
const sections = loadManifest(manifestFile);
|
|
48
|
+
const meta = loadManifestMeta(manifestFile);
|
|
49
|
+
const fileParts = [];
|
|
50
|
+
const fragmentParts = [];
|
|
51
|
+
const pathMappings = buildPathMappings(ctx.vars);
|
|
52
|
+
const sessionCache = getSessionCache(ctx.sessionId);
|
|
53
|
+
const diagnostics = [];
|
|
54
|
+
// 总闸计数(跨所有段累计)
|
|
55
|
+
let totalFiles = 0;
|
|
56
|
+
let totalBytes = 0;
|
|
57
|
+
let capReached = false;
|
|
58
|
+
const skippedByCap = []; // 因总闸超限未加载的 section id
|
|
59
|
+
for (const section of sections) {
|
|
60
|
+
const rawPath = section.type === 'file' ? (section.file ?? '') : (section.path ?? '');
|
|
61
|
+
const diag = {
|
|
62
|
+
id: section.id, description: section.description, type: section.type, rawPath,
|
|
63
|
+
pattern: section.pattern, needsInjection: section.needsInjection, when: section.when,
|
|
64
|
+
enabled: section.enabled !== false, whenPassed: false, resolvedPath: null,
|
|
65
|
+
resolveStatus: 'no-path', fileCount: 0, used: false, injected: false,
|
|
66
|
+
};
|
|
67
|
+
// 总闸已触发:后续命中的段一律不加载,只记录 id
|
|
68
|
+
if (capReached) {
|
|
69
|
+
diag.skippedByTotalCap = true;
|
|
70
|
+
// 仅当该段本会命中时才计入"未加载"集合(enabled 且 when 通过)
|
|
71
|
+
if (section.enabled !== false && evaluateWhen(section.when, ctx.vars)) {
|
|
72
|
+
diag.whenPassed = true;
|
|
73
|
+
skippedByCap.push(section.id);
|
|
74
|
+
}
|
|
75
|
+
diagnostics.push(diag);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (section.enabled === false) {
|
|
79
|
+
diag.resolveStatus = 'skipped-disabled';
|
|
80
|
+
diagnostics.push(diag);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
diag.whenPassed = evaluateWhen(section.when, ctx.vars);
|
|
84
|
+
if (!diag.whenPassed) {
|
|
85
|
+
diag.resolveStatus = 'skipped-when';
|
|
86
|
+
diagnostics.push(diag);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (rawPath) {
|
|
90
|
+
const r = resolvePathWithDiag(rawPath, ctx.vars);
|
|
91
|
+
diag.resolvedPath = r.resolved;
|
|
92
|
+
diag.resolveStatus = r.status;
|
|
93
|
+
if (r.unresolvedTokens.length > 0)
|
|
94
|
+
diag.unresolvedTokens = r.unresolvedTokens;
|
|
95
|
+
}
|
|
96
|
+
const overflowOut = {};
|
|
97
|
+
const files = loadSectionFiles(section, ctx.vars, sessionCache, overflowOut);
|
|
98
|
+
diag.fileCount = files.length;
|
|
99
|
+
if (overflowOut.value)
|
|
100
|
+
diag.dirOverflow = overflowOut.value;
|
|
101
|
+
// 路径解析成功但读出 0 文件 → 文件/目录不存在(存在性不再单独 syscall,
|
|
102
|
+
// 由内容读取顺带得到;详见 manifest-engine.resolvePathWithDiag)。
|
|
103
|
+
if (files.length === 0) {
|
|
104
|
+
if (diag.resolveStatus === 'ok')
|
|
105
|
+
diag.resolveStatus = 'not-exist';
|
|
106
|
+
diagnostics.push(diag);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
let anyUsed = false;
|
|
110
|
+
for (const [filePath, rawContent] of files) {
|
|
111
|
+
// 总闸检查(文件数 / 字节):达到即停止本段及后续所有段
|
|
112
|
+
const size = Buffer.byteLength(rawContent, 'utf-8');
|
|
113
|
+
if (totalFiles >= meta.totalMaxFiles || totalBytes + size > meta.totalMaxBytes) {
|
|
114
|
+
capReached = true;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
const content = renderSectionContent(section, rawContent, ctx.vars);
|
|
118
|
+
if (!content.trim()) {
|
|
119
|
+
diag.emptyContent = true;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const label = section.description ? `${section.id} — ${section.description}` : section.id;
|
|
123
|
+
const displayPath = shortenPath(filePath, pathMappings);
|
|
124
|
+
const part = `Contenu de ${displayPath} (${label}):\n\n${content.trimEnd()}`;
|
|
125
|
+
fileParts.push(part);
|
|
126
|
+
totalFiles += 1;
|
|
127
|
+
totalBytes += size;
|
|
128
|
+
anyUsed = true;
|
|
129
|
+
if (section.needsInjection) {
|
|
130
|
+
fragmentParts.push(part);
|
|
131
|
+
diag.injected = true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// 单目录段超限:注入截断说明行
|
|
135
|
+
if (diag.dirOverflow) {
|
|
136
|
+
const ov = diag.dirOverflow;
|
|
137
|
+
const displayPath = shortenPath(diag.resolvedPath ?? rawPath, pathMappings);
|
|
138
|
+
const note = `[注意] 目录 ${displayPath} 未完整加载:${ov.droppedFiles} 个文件未加载` +
|
|
139
|
+
`(达${ov.reason === 'files' ? '文件数' : '字节'}上限 ${ov.limit}${ov.reason === 'bytes' ? ' 字节' : ' 个'})。`;
|
|
140
|
+
fileParts.push(note);
|
|
141
|
+
}
|
|
142
|
+
diag.used = anyUsed;
|
|
143
|
+
// 本段触发总闸但一个文件都没用上 → 也算"未加载"
|
|
144
|
+
if (capReached && !anyUsed && evaluateWhen(section.when, ctx.vars)) {
|
|
145
|
+
diag.skippedByTotalCap = true;
|
|
146
|
+
diag.whenPassed = true;
|
|
147
|
+
skippedByCap.push(section.id);
|
|
148
|
+
}
|
|
149
|
+
diagnostics.push(diag);
|
|
150
|
+
}
|
|
151
|
+
// 总闸超限:末尾注入总截断说明(含未加载 section id 集合)
|
|
152
|
+
if (capReached && skippedByCap.length > 0) {
|
|
153
|
+
const note = `[注意] 上下文清单总量超限(>${meta.totalMaxFiles} 文件 / >${Math.round(meta.totalMaxBytes / 1024)}KB),` +
|
|
154
|
+
`以下 section 未加载:${skippedByCap.join(', ')}。`;
|
|
155
|
+
fileParts.push(note);
|
|
156
|
+
}
|
|
157
|
+
const body = fileParts.join('\n\n');
|
|
158
|
+
const output = fileParts.length > 0
|
|
159
|
+
? `<system-reminder>\nEvolCore Context Kit documents are shown below.\n\n${body}\n\nIMPORTANT: Use this context when it affects the current interaction.\n</system-reminder>`
|
|
160
|
+
: '';
|
|
161
|
+
const fragmentsOutput = fragmentParts.length > 0 ? fragmentParts.join('\n\n') : '';
|
|
162
|
+
writeDebugFiles(ctx, output, fragmentsOutput, diagnostics);
|
|
163
|
+
return output;
|
|
164
|
+
}
|
|
165
|
+
export function cleanEckDebug() {
|
|
166
|
+
if (!isEckSnapshotsEnabled())
|
|
167
|
+
return;
|
|
168
|
+
const dir = eckDebugDir();
|
|
169
|
+
const cutoff = Date.now() - 24 * 60 * 60 * 1000;
|
|
170
|
+
try {
|
|
171
|
+
for (const f of fs.readdirSync(dir)) {
|
|
172
|
+
const fp = path.join(dir, f);
|
|
173
|
+
try {
|
|
174
|
+
if (fs.statSync(fp).mtimeMs < cutoff)
|
|
175
|
+
fs.unlinkSync(fp);
|
|
176
|
+
}
|
|
177
|
+
catch { /* skip */ }
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch { /* dir doesn't exist yet */ }
|
|
181
|
+
}
|
|
182
|
+
// ── Debug output ──
|
|
183
|
+
const PARAM_DESCRIPTIONS = {
|
|
184
|
+
EVOLCORE_HOME: '用户数据根目录',
|
|
185
|
+
PACKAGE_ROOT: 'evolcore 包根目录',
|
|
186
|
+
CURRENT_PROJECT: '当前项目完整路径',
|
|
187
|
+
PERSONAL_DIR: '当前 agent 个人数据目录',
|
|
188
|
+
RELATIONS_DIR: '当前 agent 关系数据目录',
|
|
189
|
+
VENUES_DIR: '当前 agent 环境数据目录',
|
|
190
|
+
selfAid: '当前 agent 的 AID',
|
|
191
|
+
selfName: '当前 agent 的显示名',
|
|
192
|
+
lifecycle: '当前 agent 生命周期(created/bootstrapping/active)',
|
|
193
|
+
isBootstrapping: '当前 agent 是否处于 bootstrap 首次设定阶段',
|
|
194
|
+
hasPersona: '是否有 persona 内容',
|
|
195
|
+
hasWorkingMemory: '是否有 working memory',
|
|
196
|
+
peerId: '对端在该渠道的原生 ID',
|
|
197
|
+
peerKey: '对端跨渠道唯一标识(channel#urlEncode(peerId))',
|
|
198
|
+
peerName: '对端显示名',
|
|
199
|
+
peerRole: '对端角色(owner/admin/member/visitor/none)',
|
|
200
|
+
peerType: '对端类型(human/agent)',
|
|
201
|
+
sameDevice: '对端与本端同一物理设备(SDK 0.4.9 起明文/密文消息均可携带,具体字段以网关下发为准)',
|
|
202
|
+
sameNetwork: '对端与本端在同一网络内',
|
|
203
|
+
sameEgressIp: '对端与本端共享同一出口 IP',
|
|
204
|
+
groupId: '群组 ID(群聊时)',
|
|
205
|
+
groupRulesPath: '群规则本地物化文件(relations/<peerKey>/rules.md)',
|
|
206
|
+
groupRulesStatus: '群规则同步状态(synced/cached/missing/forbidden/invalid_metadata/file_mismatch/too_large/unreadable/error)',
|
|
207
|
+
groupRulesError: '群规则同步错误',
|
|
208
|
+
chatType: '聊天类型(private=私聊 / group=群聊 / null=本地开发)',
|
|
209
|
+
channel: '渠道类型(aun/feishu/wechat/dingtalk/qqbot/wecom)',
|
|
210
|
+
venueUid: '场所唯一标识(预留)',
|
|
211
|
+
mentionMode: '群 @ 处理模式(mention-only=被@才响应 / disabled=所有消息都响应)',
|
|
212
|
+
clientType: '客户端类型(desktop/web/mobile)',
|
|
213
|
+
permissionMode: '权限模式(readonly/auto/request/bypass;旧值会安全迁移)',
|
|
214
|
+
capabilities: '当前渠道支持的能力列表',
|
|
215
|
+
fileCapable: '当前交互模式下是否支持用文件标记发送文件(兼容别名)',
|
|
216
|
+
supportsFileMarker: '当前交互模式下是否支持用文件标记发送文件',
|
|
217
|
+
project: '当前项目目录名',
|
|
218
|
+
sessionId: 'evolcore 会话 ID',
|
|
219
|
+
sessionName: '会话名称',
|
|
220
|
+
sessionKey: '会话路由键(channelType#urlEncode(channelId)#urlEncode(threadId))',
|
|
221
|
+
sessionCreatedAt: '会话创建时间(ISO)',
|
|
222
|
+
timezone: 'IANA 时区名(把 ISO 时间戳转本地时间用,如 Asia/Shanghai)',
|
|
223
|
+
tzOffset: '当前 UTC 偏移(如 +08:00)',
|
|
224
|
+
localDate: '当前本地日期(YYYY-MM-DD,按 timezone)',
|
|
225
|
+
weekday: '当前本地星期几(按 timezone+locale)',
|
|
226
|
+
osInfo: '操作系统及版本(如 Windows 11 Pro (win32 10.0.26200))',
|
|
227
|
+
threadId: '话题 ID(多话题路由时)',
|
|
228
|
+
chatMode: '会话模式(interactive=同步交互 / proactive=主动推送)',
|
|
229
|
+
proactivePreTool1stMsgChk: 'proactive 前置工具首消息检查(true/false)',
|
|
230
|
+
proactiveToolUseReminder: 'proactive 工具调用提醒(true/false)',
|
|
231
|
+
proactiveFirstSendRequired: '当前消息是否要求首次非发送工具前先发送表态',
|
|
232
|
+
proactiveToolReportRequired: '当前消息是否要求按工具调用次数汇报进展',
|
|
233
|
+
proactiveToolReportInterval: 'proactive 工具进展汇报间隔',
|
|
234
|
+
proactiveSendTargetLabel: 'proactive 发送目标标签(对方/群里)',
|
|
235
|
+
readonly: '是否只读模式',
|
|
236
|
+
evolcoreMode: 'evolcore 运行模式(dev=源码仓库可直接修改 | install=全局安装包只读)',
|
|
237
|
+
baseAgent: 'base agent 规范值(claude/codex/gemini/hermes)',
|
|
238
|
+
baseAgentName: 'base agent 显示名',
|
|
239
|
+
baseAgentModel: 'base agent 引擎底座模型(evolcore 作用域无配置时的兜底)',
|
|
240
|
+
effectiveModel: '当前实际生效模型(关系级 > agent级 > 全局 优先级解析结果)',
|
|
241
|
+
modelFallbackActive: 'evolcore 配置的模型不可用,当前正在使用降级模型',
|
|
242
|
+
modelFallbackModel: '当前降级使用的 base agent 模型名',
|
|
243
|
+
agentSessionId: 'base agent 会话 ID',
|
|
244
|
+
};
|
|
245
|
+
function writeDebugFiles(ctx, output, fragmentsOutput, diagnostics) {
|
|
246
|
+
if (!isEckSnapshotsEnabled())
|
|
247
|
+
return;
|
|
248
|
+
try {
|
|
249
|
+
const now = new Date();
|
|
250
|
+
const ts = now.toISOString().replace(/[T:.]/g, '-').slice(0, 19);
|
|
251
|
+
const dir = eckDebugDir();
|
|
252
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
253
|
+
const write = (file, content) => {
|
|
254
|
+
fs.writeFile(path.join(dir, file), content, (error) => {
|
|
255
|
+
if (error)
|
|
256
|
+
logger.debug(`[KitRenderer] debug write failed (${file}): ${error.message}`);
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
const varsData = {
|
|
260
|
+
timestamp: now.toISOString(),
|
|
261
|
+
sessionId: ctx.sessionId,
|
|
262
|
+
params: Object.entries(ctx.vars)
|
|
263
|
+
.filter(([, v]) => v !== undefined && v !== null)
|
|
264
|
+
.map(([name, value]) => ({ name, value, description: PARAM_DESCRIPTIONS[name] || '' })),
|
|
265
|
+
};
|
|
266
|
+
write(`vars-${ts}.json`, JSON.stringify(varsData, null, 2));
|
|
267
|
+
if (output)
|
|
268
|
+
write(`context-${ts}.md`, output);
|
|
269
|
+
if (fragmentsOutput)
|
|
270
|
+
write(`fragments-${ts}.md`, fragmentsOutput);
|
|
271
|
+
write(`manifest-${ts}.md`, formatManifestDiagnostics(ctx, diagnostics));
|
|
272
|
+
}
|
|
273
|
+
catch (e) {
|
|
274
|
+
logger.debug(`[KitRenderer] debug write failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function formatManifestDiagnostics(ctx, diagnostics) {
|
|
278
|
+
const STATUS_ICON = {
|
|
279
|
+
'ok': 'OK',
|
|
280
|
+
'unresolved-vars': 'UNRESOLVED-VARS',
|
|
281
|
+
'not-exist': 'NOT-EXIST',
|
|
282
|
+
'skipped-disabled': 'SKIPPED(disabled)',
|
|
283
|
+
'skipped-when': 'SKIPPED(when)',
|
|
284
|
+
'no-path': 'NO-PATH',
|
|
285
|
+
};
|
|
286
|
+
const used = diagnostics.filter(d => d.used).length;
|
|
287
|
+
const skippedWhen = diagnostics.filter(d => d.resolveStatus === 'skipped-when').length;
|
|
288
|
+
const errors = diagnostics.filter(d => d.resolveStatus === 'unresolved-vars' || d.resolveStatus === 'not-exist').length;
|
|
289
|
+
const lines = [];
|
|
290
|
+
lines.push(`# ECK Manifest Diagnostics`);
|
|
291
|
+
lines.push('');
|
|
292
|
+
lines.push(`- timestamp: ${new Date().toISOString()}`);
|
|
293
|
+
lines.push(`- sessionId: ${ctx.sessionId}`);
|
|
294
|
+
lines.push(`- sections total: ${diagnostics.length}`);
|
|
295
|
+
lines.push(`- sections used: ${used}`);
|
|
296
|
+
lines.push(`- sections skipped (when=false): ${skippedWhen}`);
|
|
297
|
+
lines.push(`- sections with errors (unresolved-vars/not-exist): ${errors}`);
|
|
298
|
+
lines.push('');
|
|
299
|
+
if (errors > 0) {
|
|
300
|
+
lines.push(`## Errors`);
|
|
301
|
+
lines.push('');
|
|
302
|
+
for (const d of diagnostics) {
|
|
303
|
+
if (d.resolveStatus !== 'unresolved-vars' && d.resolveStatus !== 'not-exist')
|
|
304
|
+
continue;
|
|
305
|
+
lines.push(`### ${d.id}${d.description ? ' — ' + d.description : ''}`);
|
|
306
|
+
lines.push(`- status: ${STATUS_ICON[d.resolveStatus]}`);
|
|
307
|
+
lines.push(`- type: ${d.type}`);
|
|
308
|
+
lines.push(`- raw path: \`${d.rawPath}\``);
|
|
309
|
+
lines.push(`- resolved: \`${d.resolvedPath ?? '(null)'}\``);
|
|
310
|
+
if (d.unresolvedTokens && d.unresolvedTokens.length > 0) {
|
|
311
|
+
lines.push(`- unresolved tokens: ${d.unresolvedTokens.map(t => '`' + t + '`').join(', ')}`);
|
|
312
|
+
}
|
|
313
|
+
lines.push('');
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
lines.push(`## All sections`);
|
|
317
|
+
lines.push('');
|
|
318
|
+
lines.push(`| order | id | status | type | raw path | resolved | files | used | injected |`);
|
|
319
|
+
lines.push(`|---|---|---|---|---|---|---|---|---|`);
|
|
320
|
+
diagnostics.forEach((d, idx) => {
|
|
321
|
+
const status = STATUS_ICON[d.resolveStatus];
|
|
322
|
+
const rawPath = d.rawPath ? '`' + d.rawPath + '`' : '—';
|
|
323
|
+
const resolvedShort = d.resolvedPath ? '`' + (d.resolvedPath.length > 60 ? '…' + d.resolvedPath.slice(-58) : d.resolvedPath) + '`' : '—';
|
|
324
|
+
lines.push(`| ${idx + 1} | ${d.id} | ${status} | ${d.type} | ${rawPath} | ${resolvedShort} | ${d.fileCount} | ${d.used ? 'Y' : '·'} | ${d.injected ? 'Y' : '·'} |`);
|
|
325
|
+
});
|
|
326
|
+
lines.push('');
|
|
327
|
+
lines.push(`## Section details`);
|
|
328
|
+
lines.push('');
|
|
329
|
+
for (const d of diagnostics) {
|
|
330
|
+
lines.push(`### ${d.id}${d.description ? ' — ' + d.description : ''}`);
|
|
331
|
+
lines.push(`- status: ${STATUS_ICON[d.resolveStatus]}`);
|
|
332
|
+
lines.push(`- type: ${d.type}`);
|
|
333
|
+
if (d.rawPath)
|
|
334
|
+
lines.push(`- raw path: \`${d.rawPath}\``);
|
|
335
|
+
if (d.pattern)
|
|
336
|
+
lines.push(`- pattern: \`${d.pattern}\``);
|
|
337
|
+
if (d.when !== undefined)
|
|
338
|
+
lines.push(`- when: \`${JSON.stringify(d.when)}\` → ${d.whenPassed ? 'true' : 'false'}`);
|
|
339
|
+
lines.push(`- needsInjection: ${d.needsInjection ? 'true' : 'false'}`);
|
|
340
|
+
lines.push(`- enabled: ${d.enabled}`);
|
|
341
|
+
if (d.resolvedPath)
|
|
342
|
+
lines.push(`- resolved: \`${d.resolvedPath}\``);
|
|
343
|
+
if (d.unresolvedTokens && d.unresolvedTokens.length > 0) {
|
|
344
|
+
lines.push(`- unresolved tokens: ${d.unresolvedTokens.map(t => '`' + t + '`').join(', ')}`);
|
|
345
|
+
}
|
|
346
|
+
lines.push(`- file count: ${d.fileCount}`);
|
|
347
|
+
if (d.emptyContent)
|
|
348
|
+
lines.push(`- note: 文件存在但渲染后内容为空`);
|
|
349
|
+
if (d.dirOverflow) {
|
|
350
|
+
lines.push(`- dir overflow: ${d.dirOverflow.droppedFiles} 文件未加载(达${d.dirOverflow.reason === 'files' ? '文件数' : '字节'}上限 ${d.dirOverflow.limit})`);
|
|
351
|
+
}
|
|
352
|
+
if (d.skippedByTotalCap)
|
|
353
|
+
lines.push(`- skipped: 总闸超限未加载`);
|
|
354
|
+
lines.push(`- used in output: ${d.used ? 'yes' : 'no'}`);
|
|
355
|
+
lines.push(`- injected as fragment: ${d.injected ? 'yes' : 'no'}`);
|
|
356
|
+
lines.push('');
|
|
357
|
+
}
|
|
358
|
+
return lines.join('\n');
|
|
359
|
+
}
|