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,384 @@
|
|
|
1
|
+
import { ConfigError, ConfigTarget, ensureFile, listFields, read, resolveEffectiveFieldWithSource, resolveEffectiveWithSources, validateConfigFile, write, } from './config-manager.js';
|
|
2
|
+
import { collectConfigFiles, diffVersions, listAllVersions, prune, readCurrent, restore, snapshot, isConfigSnapshotsEnabled, } from './snapshot.js';
|
|
3
|
+
import { readBootLog } from './boot-log.js';
|
|
4
|
+
import { currentVersion, fieldSchemaDefault, isSchemaName, listSchemaNames, listSchemaVersions, readRawSchema, schemaHistoryEntry, } from './schema-registry.js';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { resolvePaths, agentDir, agentRelationConfig } from '../paths.js';
|
|
8
|
+
export const AUTHENTICATED_CONFIG_ROLE_ENV = 'EVOLCORE_AUTHENTICATED_CONFIG_ROLE';
|
|
9
|
+
export function executeResolvedConfigCommand(command, options = {}) {
|
|
10
|
+
try {
|
|
11
|
+
const missingAgent = selectedAgentError(command);
|
|
12
|
+
if (missingAgent)
|
|
13
|
+
return missingAgent;
|
|
14
|
+
if (command.kind === 'field')
|
|
15
|
+
return executeResolvedConfigOperation(command, options);
|
|
16
|
+
if (command.kind === 'scoped')
|
|
17
|
+
return executeScoped(command, options);
|
|
18
|
+
return executeGlobal(command);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error instanceof ConfigError)
|
|
22
|
+
return { ok: false, code: error.code, error: error.message, ...(error.data !== undefined ? { data: error.data } : {}) };
|
|
23
|
+
return { ok: false, code: 'CONFIG_ERROR', error: error instanceof Error ? error.message : String(error) };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function executeResolvedConfigOperation(op, options = {}) {
|
|
27
|
+
try {
|
|
28
|
+
const missingAgent = selectedAgentError(op);
|
|
29
|
+
if (missingAgent)
|
|
30
|
+
return missingAgent;
|
|
31
|
+
if (op.subcommand === 'get')
|
|
32
|
+
return executeGet(op, options);
|
|
33
|
+
if (op.subcommand === 'set')
|
|
34
|
+
return executeSet(op, options);
|
|
35
|
+
return executeUnset(op, options);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error instanceof ConfigError)
|
|
39
|
+
return { ok: false, code: error.code, error: error.message, ...(error.data !== undefined ? { data: error.data } : {}) };
|
|
40
|
+
return { ok: false, code: 'CONFIG_ERROR', error: error instanceof Error ? error.message : String(error) };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function selectedAgentError(command) {
|
|
44
|
+
if (!command.self || fs.existsSync(agentDir(command.self)))
|
|
45
|
+
return undefined;
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
code: 'AGENT_NOT_FOUND',
|
|
49
|
+
error: `Agent "${command.self}" does not exist. Create it with "ec agent create --aid ${command.self}".`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function executeScoped(command, options) {
|
|
53
|
+
const selector = selectorFor(command, options);
|
|
54
|
+
const target = targetForScope(command.configScope);
|
|
55
|
+
if (command.subcommand === 'show') {
|
|
56
|
+
return {
|
|
57
|
+
ok: true,
|
|
58
|
+
subcommand: 'show',
|
|
59
|
+
scope: command.configScope,
|
|
60
|
+
configs: { [target]: read(target, selector) || {} },
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (command.subcommand === 'effective') {
|
|
64
|
+
if (command.configScope === 'process') {
|
|
65
|
+
return {
|
|
66
|
+
ok: true,
|
|
67
|
+
subcommand: 'effective',
|
|
68
|
+
scope: command.configScope,
|
|
69
|
+
effective: read(ConfigTarget.Process, selector) || {},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const effective = {};
|
|
73
|
+
for (const [key, item] of Object.entries(resolveEffectiveWithSources(selector))) {
|
|
74
|
+
effective[key] = { value: item.value, source: item.source };
|
|
75
|
+
}
|
|
76
|
+
return { ok: true, subcommand: 'effective', scope: command.configScope, effective };
|
|
77
|
+
}
|
|
78
|
+
if (command.subcommand === 'fields') {
|
|
79
|
+
let fields = listFields(command.configScope);
|
|
80
|
+
if (command.field) {
|
|
81
|
+
fields = fields.filter(route => route.field === command.field || route.field.startsWith(`${command.field}.`));
|
|
82
|
+
}
|
|
83
|
+
return { ok: true, subcommand: 'fields', scope: command.configScope, fields };
|
|
84
|
+
}
|
|
85
|
+
if (command.subcommand === 'validate') {
|
|
86
|
+
const validation = validateConfigFile(target, selector);
|
|
87
|
+
const errors = validation.errors;
|
|
88
|
+
return {
|
|
89
|
+
ok: true,
|
|
90
|
+
subcommand: 'validate',
|
|
91
|
+
valid: errors.length === 0,
|
|
92
|
+
results: [{
|
|
93
|
+
target,
|
|
94
|
+
ok: errors.length === 0,
|
|
95
|
+
...(!validation.exists ? { error: '(not found, skipped)' } : {}),
|
|
96
|
+
...(errors.length > 0 ? { error: errors.join('; ') } : {}),
|
|
97
|
+
}],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
ensureFile(target, selector);
|
|
101
|
+
return { ok: true, subcommand: 'init', scope: command.configScope };
|
|
102
|
+
}
|
|
103
|
+
function executeGlobal(command) {
|
|
104
|
+
if (isSnapshotManagementCommand(command.subcommand) && !isConfigSnapshotsEnabled()) {
|
|
105
|
+
return {
|
|
106
|
+
ok: false,
|
|
107
|
+
code: 'FEATURE_DISABLED',
|
|
108
|
+
error: '配置快照功能已关闭;请设置 configSnapshots=true',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (command.subcommand === 'list') {
|
|
112
|
+
return { ok: true, subcommand: 'list', files: collectConfigFiles(resolvePaths().root) };
|
|
113
|
+
}
|
|
114
|
+
if (command.subcommand === 'snapshot') {
|
|
115
|
+
return {
|
|
116
|
+
ok: true,
|
|
117
|
+
subcommand: 'snapshot',
|
|
118
|
+
...snapshot('manual', { full: command.full, description: command.description }),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (command.subcommand === 'prune') {
|
|
122
|
+
const dryRun = !command.yes;
|
|
123
|
+
return {
|
|
124
|
+
ok: true,
|
|
125
|
+
subcommand: 'prune',
|
|
126
|
+
dryRun,
|
|
127
|
+
...prune({ keepFull: command.keepFull, keepDelta: command.keepDelta, dryRun }),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (command.subcommand === 'history') {
|
|
131
|
+
return { ok: true, subcommand: 'history', versions: listAllVersions() };
|
|
132
|
+
}
|
|
133
|
+
if (command.subcommand === 'diff') {
|
|
134
|
+
const [first, second] = command.versions;
|
|
135
|
+
const result = diffVersions(first, second);
|
|
136
|
+
if ('error' in result)
|
|
137
|
+
return { ok: false, code: 'VERSION_NOT_FOUND', error: result.error };
|
|
138
|
+
return { ok: true, subcommand: 'diff', ...result };
|
|
139
|
+
}
|
|
140
|
+
if (command.subcommand === 'restore') {
|
|
141
|
+
const result = restore(command.version);
|
|
142
|
+
if (!result.ok || !result.version) {
|
|
143
|
+
return { ok: false, code: 'RESTORE_FAILED', error: result.error || 'restore failed' };
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
ok: true,
|
|
147
|
+
subcommand: 'restore',
|
|
148
|
+
version: result.version,
|
|
149
|
+
appliedFiles: result.appliedFiles ?? 0,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
if (command.subcommand === 'current') {
|
|
153
|
+
return {
|
|
154
|
+
ok: true,
|
|
155
|
+
subcommand: 'current',
|
|
156
|
+
current: readCurrent(),
|
|
157
|
+
lastBoot: readBootLog(1)[0] ?? null,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (command.subcommand === 'schema') {
|
|
161
|
+
return executeSchema(command);
|
|
162
|
+
}
|
|
163
|
+
return { ok: true, subcommand: 'boots', boots: readBootLog(command.count ?? 10) };
|
|
164
|
+
}
|
|
165
|
+
function isSnapshotManagementCommand(subcommand) {
|
|
166
|
+
return subcommand === 'snapshot'
|
|
167
|
+
|| subcommand === 'prune'
|
|
168
|
+
|| subcommand === 'history'
|
|
169
|
+
|| subcommand === 'diff'
|
|
170
|
+
|| subcommand === 'restore'
|
|
171
|
+
|| subcommand === 'current'
|
|
172
|
+
|| subcommand === 'boots';
|
|
173
|
+
}
|
|
174
|
+
function executeSchema(command) {
|
|
175
|
+
// 无 name:列出全部 schema 及各自当前版本
|
|
176
|
+
if (!command.schemaName) {
|
|
177
|
+
return {
|
|
178
|
+
ok: true,
|
|
179
|
+
subcommand: 'schema',
|
|
180
|
+
mode: 'overview',
|
|
181
|
+
schemas: listSchemaNames().map(name => ({ name, current: currentVersion(name) })),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
const name = command.schemaName;
|
|
185
|
+
if (!isSchemaName(name)) {
|
|
186
|
+
return {
|
|
187
|
+
ok: false,
|
|
188
|
+
code: 'UNKNOWN_SCHEMA',
|
|
189
|
+
error: `Unknown schema: ${name} (known: ${listSchemaNames().join(', ')})`,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const current = currentVersion(name);
|
|
193
|
+
// --list:列出磁盘上全部版本,标记当前,附 history 元信息
|
|
194
|
+
if (command.schemaList) {
|
|
195
|
+
const versions = listSchemaVersions(name).map(version => {
|
|
196
|
+
const history = schemaHistoryEntry(name, version);
|
|
197
|
+
return {
|
|
198
|
+
version,
|
|
199
|
+
current: version === current,
|
|
200
|
+
...(history ? { date: history.date, description: history.description } : {}),
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
return { ok: true, subcommand: 'schema', mode: 'versions', name, current, versions };
|
|
204
|
+
}
|
|
205
|
+
// 内容:指定版本,缺省取当前版本
|
|
206
|
+
const version = command.schemaVersion ?? current;
|
|
207
|
+
if (!listSchemaVersions(name).includes(version)) {
|
|
208
|
+
return {
|
|
209
|
+
ok: false,
|
|
210
|
+
code: 'SCHEMA_VERSION_NOT_FOUND',
|
|
211
|
+
error: `Schema ${name} has no version ${version} (available: ${listSchemaVersions(name).join(', ')})`,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
ok: true,
|
|
216
|
+
subcommand: 'schema',
|
|
217
|
+
mode: 'content',
|
|
218
|
+
name,
|
|
219
|
+
version,
|
|
220
|
+
current: version === current,
|
|
221
|
+
content: readRawSchema(name, version),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function executeGet(op, options) {
|
|
225
|
+
const selector = selectorFor(op, options);
|
|
226
|
+
if (op.configScope === 'process') {
|
|
227
|
+
const config = read(ConfigTarget.Process, selector) || {};
|
|
228
|
+
const stored = getNested(config, op.field);
|
|
229
|
+
if (stored !== undefined) {
|
|
230
|
+
return { ok: true, subcommand: 'get', field: op.field, value: stored, scope: op.configScope };
|
|
231
|
+
}
|
|
232
|
+
return getWithSchemaDefault(op, null);
|
|
233
|
+
}
|
|
234
|
+
const withSource = resolveEffectiveFieldWithSource(op.field, selector);
|
|
235
|
+
// 关系级作用域下始终诊断 relation 层的贡献情况:命中非 relation 层时解释回退原因
|
|
236
|
+
// (对端不存在/无配置文件/未设值),命中 relation 层但值非法时给出告警。
|
|
237
|
+
const note = op.configScope === 'relation'
|
|
238
|
+
? diagnoseRelationLayer(op, withSource.source?.target === ConfigTarget.Relation)
|
|
239
|
+
: undefined;
|
|
240
|
+
if (withSource.source) {
|
|
241
|
+
return {
|
|
242
|
+
ok: true,
|
|
243
|
+
subcommand: 'get',
|
|
244
|
+
field: op.field,
|
|
245
|
+
value: withSource.value,
|
|
246
|
+
scope: op.configScope,
|
|
247
|
+
source: withSource.source,
|
|
248
|
+
...(note ? { note } : {}),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
return getWithSchemaDefault(op, null, note);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* 关系级取值时诊断 relation 层。
|
|
255
|
+
* @param hitRelation 最终取值是否来自 relation 层。
|
|
256
|
+
* - 未命中 relation:解释为何回退(对端不存在 / 无配置文件 / JSON 损坏 / 该字段未设)。
|
|
257
|
+
* - 命中 relation:正常无需说明;但若该值不在 schema 候选清单内,给出"非法值"告警。
|
|
258
|
+
*/
|
|
259
|
+
function diagnoseRelationLayer(op, hitRelation) {
|
|
260
|
+
if (!op.self || !op.peerKey)
|
|
261
|
+
return undefined;
|
|
262
|
+
const relFile = agentRelationConfig(op.self, op.peerKey);
|
|
263
|
+
if (!fs.existsSync(relFile)) {
|
|
264
|
+
return hitRelation ? undefined
|
|
265
|
+
: `relation layer skipped: peer "${op.peerKey}" has no config file (${relPath(relFile)})`;
|
|
266
|
+
}
|
|
267
|
+
let relConfig;
|
|
268
|
+
try {
|
|
269
|
+
relConfig = JSON.parse(fs.readFileSync(relFile, 'utf-8'));
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
return `relation config ${relPath(relFile)} is not readable JSON (${error instanceof Error ? error.message : String(error)})`;
|
|
273
|
+
}
|
|
274
|
+
const stored = getNested(relConfig, op.field);
|
|
275
|
+
if (stored === undefined) {
|
|
276
|
+
return hitRelation ? undefined
|
|
277
|
+
: `relation layer skipped: "${op.field}" not set for peer "${op.peerKey}"`;
|
|
278
|
+
}
|
|
279
|
+
const allowed = op.route?.enum;
|
|
280
|
+
if (allowed && !allowed.includes(stored)) {
|
|
281
|
+
return `relation value ${JSON.stringify(stored)} is not a valid ${op.field} (expected: ${allowed.join(' | ')})`;
|
|
282
|
+
}
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
function relPath(absolute) {
|
|
286
|
+
return path.relative(resolvePaths().root, absolute);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* 各存储层都无值时的兜底:若 schema 为该字段声明了 `default`,展示出厂默认并标记
|
|
290
|
+
* schemaDefault=true(仅影响 `ec config get` 的展示;运行时 resolveEffective 不受影响,
|
|
291
|
+
* 未设值仍为 undefined,以保留协议层回退等既有语义)。
|
|
292
|
+
*/
|
|
293
|
+
function getWithSchemaDefault(op, absent, note) {
|
|
294
|
+
const nt = note ? { note } : {};
|
|
295
|
+
const schemaDefault = op.route ? fieldSchemaDefault(op.route.schema, op.field) : undefined;
|
|
296
|
+
if (schemaDefault !== undefined) {
|
|
297
|
+
return { ok: true, subcommand: 'get', field: op.field, value: schemaDefault, scope: op.configScope, schemaDefault: true, ...nt };
|
|
298
|
+
}
|
|
299
|
+
return { ok: true, subcommand: 'get', field: op.field, value: absent, scope: op.configScope, ...nt };
|
|
300
|
+
}
|
|
301
|
+
function executeSet(op, options) {
|
|
302
|
+
if (!op.route)
|
|
303
|
+
return { ok: false, code: 'UNKNOWN_FIELD', error: `Unknown config field: ${op.field}` };
|
|
304
|
+
const selector = selectorFor(op, options);
|
|
305
|
+
const existing = read(op.route.target, selector) || {};
|
|
306
|
+
if (op.route.merge === 'list') {
|
|
307
|
+
const previous = getNested(existing, op.field);
|
|
308
|
+
const previousItems = Array.isArray(previous) ? previous : [];
|
|
309
|
+
const nextItems = Array.isArray(op.value) ? op.value : [op.value];
|
|
310
|
+
const merged = [...new Set([...previousItems, ...nextItems].map(value => typeof value === 'object' ? JSON.stringify(value) : value))]
|
|
311
|
+
.map(value => {
|
|
312
|
+
try {
|
|
313
|
+
return typeof value === 'string' && value.startsWith('{') ? JSON.parse(value) : value;
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
return value;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
setNested(existing, op.field, merged);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
setNested(existing, op.field, op.value);
|
|
323
|
+
}
|
|
324
|
+
ensureFile(op.route.target, selector);
|
|
325
|
+
write(op.route.target, existing, selector);
|
|
326
|
+
return {
|
|
327
|
+
ok: true,
|
|
328
|
+
subcommand: 'set',
|
|
329
|
+
field: op.field,
|
|
330
|
+
value: op.value,
|
|
331
|
+
scope: op.configScope,
|
|
332
|
+
file: op.route.schema,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function executeUnset(op, options) {
|
|
336
|
+
if (!op.route)
|
|
337
|
+
return { ok: false, code: 'UNKNOWN_FIELD', error: `Unknown config field: ${op.field}` };
|
|
338
|
+
const selector = selectorFor(op, options);
|
|
339
|
+
const existing = read(op.route.target, selector);
|
|
340
|
+
if (!existing) {
|
|
341
|
+
return { ok: true, subcommand: 'unset', field: op.field, removed: false, scope: op.configScope };
|
|
342
|
+
}
|
|
343
|
+
const parts = op.field.split('.');
|
|
344
|
+
let current = existing;
|
|
345
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
346
|
+
if (current == null)
|
|
347
|
+
break;
|
|
348
|
+
current = current[parts[i]];
|
|
349
|
+
}
|
|
350
|
+
const leaf = parts[parts.length - 1];
|
|
351
|
+
const removed = !!current && typeof current === 'object' && Object.prototype.hasOwnProperty.call(current, leaf);
|
|
352
|
+
if (removed)
|
|
353
|
+
delete current[leaf];
|
|
354
|
+
write(op.route.target, existing, selector);
|
|
355
|
+
return { ok: true, subcommand: 'unset', field: op.field, removed, scope: op.configScope };
|
|
356
|
+
}
|
|
357
|
+
function selectorFor(command, options = {}) {
|
|
358
|
+
return {
|
|
359
|
+
...(command.self ? { self: command.self } : {}),
|
|
360
|
+
...(command.peerKey ? { peerKey: command.peerKey } : {}),
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function targetForScope(scope) {
|
|
364
|
+
if (scope === 'process')
|
|
365
|
+
return ConfigTarget.Process;
|
|
366
|
+
if (scope === 'defaults')
|
|
367
|
+
return ConfigTarget.Defaults;
|
|
368
|
+
if (scope === 'agent')
|
|
369
|
+
return ConfigTarget.Agent;
|
|
370
|
+
return ConfigTarget.Relation;
|
|
371
|
+
}
|
|
372
|
+
function setNested(object, dotPath, value) {
|
|
373
|
+
const parts = dotPath.split('.');
|
|
374
|
+
let current = object;
|
|
375
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
376
|
+
if (!current[parts[i]] || typeof current[parts[i]] !== 'object')
|
|
377
|
+
current[parts[i]] = {};
|
|
378
|
+
current = current[parts[i]];
|
|
379
|
+
}
|
|
380
|
+
current[parts[parts.length - 1]] = value;
|
|
381
|
+
}
|
|
382
|
+
function getNested(object, dotPath) {
|
|
383
|
+
return dotPath.split('.').reduce((value, key) => value == null ? undefined : value[key], object);
|
|
384
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isValidAid } from '../aun/aid/validation.js';
|
|
2
|
+
const CHANNEL_SEGMENT = /^[A-Za-z0-9_-]+$/;
|
|
3
|
+
/** Parse the canonical channel instance key used by Contact aliases. */
|
|
4
|
+
export function parseContactChannelKey(value) {
|
|
5
|
+
if (typeof value !== 'string')
|
|
6
|
+
return null;
|
|
7
|
+
const text = value.trim();
|
|
8
|
+
const parts = text.split('#');
|
|
9
|
+
if (parts.length !== 3)
|
|
10
|
+
return null;
|
|
11
|
+
const [rawType, selfAid, channelName] = parts;
|
|
12
|
+
const channelType = rawType.toLowerCase();
|
|
13
|
+
if (!CHANNEL_SEGMENT.test(channelType)
|
|
14
|
+
|| rawType !== channelType
|
|
15
|
+
|| !isValidAid(selfAid)
|
|
16
|
+
|| !CHANNEL_SEGMENT.test(channelName))
|
|
17
|
+
return null;
|
|
18
|
+
return {
|
|
19
|
+
channelType,
|
|
20
|
+
selfAid,
|
|
21
|
+
channelName,
|
|
22
|
+
channelKey: `${channelType}#${selfAid}#${channelName}`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Validate that a runtime channelKey belongs to the expected Agent and channel type. */
|
|
26
|
+
export function normalizeContactChannelKey(selfAid, channelType, channelKey) {
|
|
27
|
+
const parsed = parseContactChannelKey(channelKey);
|
|
28
|
+
const expectedType = String(channelType || '').trim().toLowerCase();
|
|
29
|
+
const expectedSelf = String(selfAid || '').trim();
|
|
30
|
+
if (!parsed || parsed.channelType !== expectedType || parsed.selfAid !== expectedSelf)
|
|
31
|
+
return null;
|
|
32
|
+
return parsed.channelKey;
|
|
33
|
+
}
|
|
34
|
+
/** Format `<channelKey>:<urlEncode(peerId)>`. */
|
|
35
|
+
export function formatContactAlias(channelKey, peerId) {
|
|
36
|
+
const parsed = parseContactChannelKey(channelKey);
|
|
37
|
+
const peer = String(peerId || '').trim();
|
|
38
|
+
if (!parsed || parsed.channelType === 'aun' || !peer) {
|
|
39
|
+
throw new Error(`Invalid Contact alias input: ${String(channelKey)}:${String(peerId)}`);
|
|
40
|
+
}
|
|
41
|
+
return `${parsed.channelKey}:${encodeURIComponent(peer)}`;
|
|
42
|
+
}
|
|
43
|
+
/** Parse and canonicalize a stored Contact alias. Non-canonical URL encoding is rejected. */
|
|
44
|
+
export function parseContactAlias(value, expectedSelfAid) {
|
|
45
|
+
if (typeof value !== 'string')
|
|
46
|
+
return null;
|
|
47
|
+
const text = value.trim();
|
|
48
|
+
const separator = text.indexOf(':');
|
|
49
|
+
if (separator <= 0 || separator === text.length - 1)
|
|
50
|
+
return null;
|
|
51
|
+
const parsedChannel = parseContactChannelKey(text.slice(0, separator));
|
|
52
|
+
if (!parsedChannel || parsedChannel.channelType === 'aun')
|
|
53
|
+
return null;
|
|
54
|
+
if (expectedSelfAid !== undefined && parsedChannel.selfAid !== String(expectedSelfAid || '').trim())
|
|
55
|
+
return null;
|
|
56
|
+
const encodedPeerId = text.slice(separator + 1);
|
|
57
|
+
let peerId;
|
|
58
|
+
try {
|
|
59
|
+
peerId = decodeURIComponent(encodedPeerId);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (!peerId || encodeURIComponent(peerId) !== encodedPeerId)
|
|
65
|
+
return null;
|
|
66
|
+
const alias = `${parsedChannel.channelKey}:${encodedPeerId}`;
|
|
67
|
+
return { ...parsedChannel, peerId, alias };
|
|
68
|
+
}
|