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,642 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { getArgValue, isHelpFlag, wantsHelp } from './help.js';
|
|
3
|
+
import { isHostChinese } from '../utils/locale.js';
|
|
4
|
+
function formatTimeAgo(ms) {
|
|
5
|
+
const sec = Math.floor(ms / 1000);
|
|
6
|
+
if (sec < 60)
|
|
7
|
+
return '刚刚';
|
|
8
|
+
const min = Math.floor(sec / 60);
|
|
9
|
+
if (min < 60)
|
|
10
|
+
return `${min}分钟前`;
|
|
11
|
+
const hour = Math.floor(min / 60);
|
|
12
|
+
if (hour < 24)
|
|
13
|
+
return `${hour}小时前`;
|
|
14
|
+
const day = Math.floor(hour / 24);
|
|
15
|
+
return `${day}天前`;
|
|
16
|
+
}
|
|
17
|
+
function formatBytes(bytes) {
|
|
18
|
+
if (bytes < 1024)
|
|
19
|
+
return `${bytes}B`;
|
|
20
|
+
if (bytes < 1024 * 1024)
|
|
21
|
+
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
22
|
+
return `${(bytes / 1024 / 1024).toFixed(1)}MB`;
|
|
23
|
+
}
|
|
24
|
+
// ==================== Agent ====================
|
|
25
|
+
export async function cmdAgent(args) {
|
|
26
|
+
const sub = args[0];
|
|
27
|
+
const formatJson = getArgValue(args, '--format') === 'json';
|
|
28
|
+
const commands = new Set(['list', 'show', 'new', 'enable', 'disable', 'get', 'set', 'rename', 'ready', 'reload', 'delete']);
|
|
29
|
+
if (!sub || isHelpFlag(sub) || (wantsHelp(args) && !commands.has(sub))) {
|
|
30
|
+
console.log(`用法: ec agent <command>
|
|
31
|
+
|
|
32
|
+
Commands:
|
|
33
|
+
list 列出所有 agent
|
|
34
|
+
show <aid> 查看 agent 详情(身份 + 配置 + 连接 + 会话 + 路径)
|
|
35
|
+
new [aid] 交互式创建 agent
|
|
36
|
+
new <aid> --non-interactive ... 非交互式创建
|
|
37
|
+
enable <aid> 启用 agent
|
|
38
|
+
disable <aid> 停用 agent
|
|
39
|
+
get <aid> <key> 读取单个配置字段(支持点路径)
|
|
40
|
+
set <aid> <key> <val> 修改单个配置字段(支持点路径)
|
|
41
|
+
rename <aid> <name> 修改 agent.md 中的显示名称
|
|
42
|
+
ready <aid> 标记 bootstrap 完成,进入 active 状态
|
|
43
|
+
reload [aid] 热重载配置(无参数=全量 resync)
|
|
44
|
+
delete <aid> [--purge] 删除 agent
|
|
45
|
+
|
|
46
|
+
Options:
|
|
47
|
+
--format json 输出 JSON 格式
|
|
48
|
+
--help, -h 各子命令均支持,查看详细用法
|
|
49
|
+
|
|
50
|
+
示例:
|
|
51
|
+
ec agent list
|
|
52
|
+
ec agent show mybot.agentid.pub
|
|
53
|
+
ec agent new mybot.agentid.pub
|
|
54
|
+
ec agent enable mybot.agentid.pub
|
|
55
|
+
ec agent get mybot.agentid.pub active_baseagent
|
|
56
|
+
ec agent set mybot.agentid.pub active_baseagent codex
|
|
57
|
+
ec agent rename mybot.agentid.pub "New Name"
|
|
58
|
+
ec agent ready mybot.agentid.pub
|
|
59
|
+
ec agent delete mybot.agentid.pub --purge`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const { agentList, agentShow, agentCreateInteractive, agentCreateNonInteractive, agentReload, agentEnable, agentDisable, agentGet, agentSet, agentRename, agentDelete, agentReady, } = await import('./agent.js');
|
|
63
|
+
// --- list ---
|
|
64
|
+
if (sub === 'list') {
|
|
65
|
+
if (wantsHelp(args)) {
|
|
66
|
+
console.log(`用法: ec agent list [--format json]
|
|
67
|
+
|
|
68
|
+
列出所有 agent,显示名称、状态、渠道、项目、基座、最后活跃时间。`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const result = await agentList();
|
|
72
|
+
if (!result.ok) {
|
|
73
|
+
if (formatJson) {
|
|
74
|
+
console.log(JSON.stringify(result));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
console.error(`❌ ${result.error}`);
|
|
78
|
+
}
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
if (formatJson) {
|
|
82
|
+
console.log(JSON.stringify(result, null, 2));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (result.agents.length === 0) {
|
|
86
|
+
console.log('No agents configured.');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
// 表头跟随系统语言
|
|
90
|
+
const isChinese = isHostChinese();
|
|
91
|
+
const headers = isChinese
|
|
92
|
+
? { name: '名称', personal: 'Personal名', status: '状态', channels: '渠道', project: '项目', baseagent: '基座', lastActive: '最后活跃' }
|
|
93
|
+
: { name: 'NAME', personal: 'PERSONAL', status: 'STATUS', channels: 'CHANNELS', project: 'PROJECT', baseagent: 'BASEAGENT', lastActive: 'LAST ACTIVE' };
|
|
94
|
+
// 计算各列实际需要的宽度
|
|
95
|
+
let maxNameLen = headers.name.length;
|
|
96
|
+
let maxPersonalLen = headers.personal.length;
|
|
97
|
+
let maxStatusLen = headers.status.length;
|
|
98
|
+
let maxChannelsLen = headers.channels.length;
|
|
99
|
+
let maxProjectLen = headers.project.length;
|
|
100
|
+
let maxBaseagentLen = headers.baseagent.length;
|
|
101
|
+
for (const info of result.agents) {
|
|
102
|
+
maxNameLen = Math.max(maxNameLen, info.name.length);
|
|
103
|
+
maxPersonalLen = Math.max(maxPersonalLen, (info.personalName || '—').length);
|
|
104
|
+
maxStatusLen = Math.max(maxStatusLen, (info.status || 'stopped').length);
|
|
105
|
+
const channelsStr = info.channels?.length > 0 ? info.channels.join(', ') : '—';
|
|
106
|
+
maxChannelsLen = Math.max(maxChannelsLen, channelsStr.length);
|
|
107
|
+
const projectStr = info.projectPath ? path.basename(info.projectPath) : '—';
|
|
108
|
+
maxProjectLen = Math.max(maxProjectLen, projectStr.length);
|
|
109
|
+
maxBaseagentLen = Math.max(maxBaseagentLen, (info.baseagent || '—').length);
|
|
110
|
+
}
|
|
111
|
+
// 加 2 作为列间距
|
|
112
|
+
const colName = maxNameLen + 2;
|
|
113
|
+
const colPersonal = maxPersonalLen + 2;
|
|
114
|
+
const colStatus = maxStatusLen + 2;
|
|
115
|
+
const colChannels = maxChannelsLen + 1;
|
|
116
|
+
const colProject = maxProjectLen + 2;
|
|
117
|
+
const colBaseagent = maxBaseagentLen + 2;
|
|
118
|
+
console.log(headers.name.padEnd(colName) + headers.personal.padEnd(colPersonal) + headers.status.padEnd(colStatus) + headers.channels.padEnd(colChannels) +
|
|
119
|
+
headers.project.padEnd(colProject) + headers.baseagent.padEnd(colBaseagent) + headers.lastActive);
|
|
120
|
+
for (const info of result.agents) {
|
|
121
|
+
const name = info.name;
|
|
122
|
+
const personal = info.personalName || '—';
|
|
123
|
+
const status = info.status || 'stopped';
|
|
124
|
+
const channels = info.channels?.length > 0 ? info.channels.join(', ') : '—';
|
|
125
|
+
const project = info.projectPath ? path.basename(info.projectPath) : '—';
|
|
126
|
+
const baseagent = info.baseagent || '—';
|
|
127
|
+
const lastActive = info.lastActivity ? formatTimeAgo(Date.now() - info.lastActivity) : '—';
|
|
128
|
+
console.log(name.padEnd(colName) + personal.padEnd(colPersonal) + status.padEnd(colStatus) + channels.padEnd(colChannels) +
|
|
129
|
+
project.padEnd(colProject) + baseagent.padEnd(colBaseagent) + lastActive);
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
// --- new ---
|
|
134
|
+
if (sub === 'new') {
|
|
135
|
+
if (wantsHelp(args)) {
|
|
136
|
+
console.log(`用法: ec agent new [aid] 交互式创建
|
|
137
|
+
ec agent new <aid> --non-interactive [选项]
|
|
138
|
+
|
|
139
|
+
非交互模式选项:
|
|
140
|
+
--baseagent <claude|codex|gemini> 默认: PATH 中第一个可用
|
|
141
|
+
--project <absolute path> 必填
|
|
142
|
+
--owner <aid>
|
|
143
|
+
--name <display-name>
|
|
144
|
+
--description <text>
|
|
145
|
+
--force 覆盖已有 config.json
|
|
146
|
+
--format json 输出 JSON
|
|
147
|
+
|
|
148
|
+
示例:
|
|
149
|
+
ec agent new mybot.agentid.pub
|
|
150
|
+
ec agent new mybot.agentid.pub --non-interactive --project /abs/path --baseagent claude`);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const name = args[1];
|
|
154
|
+
const nonInteractive = args.includes('--non-interactive');
|
|
155
|
+
if (nonInteractive) {
|
|
156
|
+
if (!name) {
|
|
157
|
+
console.error('Usage: ec agent new <aid> --non-interactive ...');
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
const getArg = (flag) => {
|
|
161
|
+
const idx = args.indexOf(flag);
|
|
162
|
+
return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : undefined;
|
|
163
|
+
};
|
|
164
|
+
const result = await agentCreateNonInteractive({
|
|
165
|
+
aid: name,
|
|
166
|
+
baseagent: getArg('--baseagent'),
|
|
167
|
+
project: getArg('--project') || '',
|
|
168
|
+
owner: getArg('--owner'),
|
|
169
|
+
name: getArg('--name'),
|
|
170
|
+
description: getArg('--description'),
|
|
171
|
+
force: args.includes('--force'),
|
|
172
|
+
});
|
|
173
|
+
if (!result.ok) {
|
|
174
|
+
if (formatJson) {
|
|
175
|
+
console.log(JSON.stringify(result));
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
console.error(`❌ ${result.error}`);
|
|
179
|
+
}
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
if (formatJson) {
|
|
183
|
+
console.log(JSON.stringify(result, null, 2));
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
console.log(`✓ Created: ${result.configPath}`);
|
|
187
|
+
console.log(result.agentmdUploaded
|
|
188
|
+
? ' ✓ agent.md 已发布'
|
|
189
|
+
: ' ⚠ agent.md 上传失败(可用 ec aid agentmd put 重试)');
|
|
190
|
+
console.log(result.hotLoaded
|
|
191
|
+
? ' ✓ 已热重载,agent 已上线'
|
|
192
|
+
: result.hotLoadError
|
|
193
|
+
? ` ✗ 热重载失败:${result.hotLoadError}`
|
|
194
|
+
: ' ⚠ 服务未运行,下次 ec start 时生效');
|
|
195
|
+
if (result.ownerBoundAid) {
|
|
196
|
+
console.log(` ✓ agent owner 已绑定: ${result.ownerBoundAid}`);
|
|
197
|
+
}
|
|
198
|
+
else if (result.ownerBindSkipped) {
|
|
199
|
+
console.log(' ⚠ agent owner 未通过二维码绑定');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
const result = await agentCreateInteractive({ suggestedName: name });
|
|
205
|
+
if (!result.ok) {
|
|
206
|
+
if (formatJson) {
|
|
207
|
+
console.log(JSON.stringify(result));
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
console.error(`❌ ${result.error}`);
|
|
211
|
+
}
|
|
212
|
+
process.exit(1);
|
|
213
|
+
}
|
|
214
|
+
if (formatJson) {
|
|
215
|
+
console.log(JSON.stringify(result, null, 2));
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
console.log(`\n✓ Created: ${result.configPath}`);
|
|
219
|
+
console.log(result.agentmdUploaded
|
|
220
|
+
? ' ✓ agent.md 已发布'
|
|
221
|
+
: ' ⚠ agent.md 上传失败(可用 ec aid agentmd put 重试)');
|
|
222
|
+
console.log(result.hotLoaded
|
|
223
|
+
? ' ✓ 已热重载,agent 已上线'
|
|
224
|
+
: result.hotLoadError
|
|
225
|
+
? ` ✗ 热重载失败:${result.hotLoadError}`
|
|
226
|
+
: ' ⚠ 服务未运行,下次 ec start 时生效');
|
|
227
|
+
if (result.ownerBoundAid) {
|
|
228
|
+
console.log(` ✓ agent owner 已绑定: ${result.ownerBoundAid}`);
|
|
229
|
+
}
|
|
230
|
+
else if (result.ownerBindSkipped) {
|
|
231
|
+
console.log(' ⚠ agent owner 未通过二维码绑定');
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
// --- sync-aids (deprecated, commented out) ---
|
|
238
|
+
// if (sub === 'sync-aids') {
|
|
239
|
+
// const result = await agentSyncAids();
|
|
240
|
+
// if (!result.ok) {
|
|
241
|
+
// if (formatJson) { console.log(JSON.stringify(result)); }
|
|
242
|
+
// else { console.error(`❌ ${result.error}`); }
|
|
243
|
+
// process.exit(1);
|
|
244
|
+
// }
|
|
245
|
+
// if (formatJson) {
|
|
246
|
+
// console.log(JSON.stringify(result, null, 2));
|
|
247
|
+
// return;
|
|
248
|
+
// }
|
|
249
|
+
// if (result.created.length === 0) {
|
|
250
|
+
// console.log('所有本地 AID 都已有对应 agent,无需同步。');
|
|
251
|
+
// } else {
|
|
252
|
+
// console.log(`✓ 同步完成:新建 ${result.created.length} 个 agent(模板: ${result.template})`);
|
|
253
|
+
// for (const aid of result.created) console.log(` ✓ ${aid}`);
|
|
254
|
+
// if (result.hotReloaded) console.log(' ✓ 已热加载到运行中的进程');
|
|
255
|
+
// else console.log(' evolcore 未运行,新 agent 将在下次启动时加载。');
|
|
256
|
+
// }
|
|
257
|
+
// return;
|
|
258
|
+
// }
|
|
259
|
+
// --- reload ---
|
|
260
|
+
if (sub === 'reload') {
|
|
261
|
+
if (wantsHelp(args)) {
|
|
262
|
+
console.log(`用法: ec agent reload [aid] [--format json]
|
|
263
|
+
|
|
264
|
+
热重载 agent 配置。
|
|
265
|
+
无参数 全量 resync(扫磁盘,新增上线、删除下线、修改热更新)
|
|
266
|
+
<aid> 仅热重载指定 agent`);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const target = args[1] && !args[1].startsWith('--') ? args[1] : undefined;
|
|
270
|
+
const result = await agentReload(target);
|
|
271
|
+
if (!result.ok) {
|
|
272
|
+
if (formatJson) {
|
|
273
|
+
console.log(JSON.stringify(result));
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
console.error(`✗ ${result.error}`);
|
|
277
|
+
}
|
|
278
|
+
process.exit(1);
|
|
279
|
+
}
|
|
280
|
+
if (formatJson) {
|
|
281
|
+
console.log(JSON.stringify(result, null, 2));
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (target) {
|
|
285
|
+
console.log(`✓ Agent "${target}" reloaded`);
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
console.log('✓ Agent resync 完成:');
|
|
289
|
+
for (const line of (result.results || []))
|
|
290
|
+
console.log(` ${line}`);
|
|
291
|
+
}
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
// --- enable ---
|
|
295
|
+
if (sub === 'enable') {
|
|
296
|
+
if (wantsHelp(args)) {
|
|
297
|
+
console.log(`用法: ec agent enable <aid> [--format json]
|
|
298
|
+
|
|
299
|
+
启用 agent。若服务运行中会热重载,否则下次 ec start 时生效。`);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const aid = args[1];
|
|
303
|
+
if (!aid) {
|
|
304
|
+
console.error('用法: ec agent enable <aid>');
|
|
305
|
+
process.exit(1);
|
|
306
|
+
}
|
|
307
|
+
const result = await agentEnable(aid);
|
|
308
|
+
if (!result.ok) {
|
|
309
|
+
if (formatJson) {
|
|
310
|
+
console.log(JSON.stringify(result));
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
console.error(`❌ ${result.error}`);
|
|
314
|
+
}
|
|
315
|
+
process.exit(1);
|
|
316
|
+
}
|
|
317
|
+
if (formatJson) {
|
|
318
|
+
console.log(JSON.stringify(result, null, 2));
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
console.log(`✓ ${aid} enabled${result.reloaded ? ' (hot-reloaded)' : ''}`);
|
|
322
|
+
}
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
// --- disable ---
|
|
326
|
+
if (sub === 'disable') {
|
|
327
|
+
if (wantsHelp(args)) {
|
|
328
|
+
console.log(`用法: ec agent disable <aid> [--format json]
|
|
329
|
+
|
|
330
|
+
停用 agent。若服务运行中会热重载离线,否则在配置中标记为禁用。`);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const aid = args[1];
|
|
334
|
+
if (!aid) {
|
|
335
|
+
console.error('用法: ec agent disable <aid>');
|
|
336
|
+
process.exit(1);
|
|
337
|
+
}
|
|
338
|
+
const result = await agentDisable(aid);
|
|
339
|
+
if (!result.ok) {
|
|
340
|
+
if (formatJson) {
|
|
341
|
+
console.log(JSON.stringify(result));
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
console.error(`❌ ${result.error}`);
|
|
345
|
+
}
|
|
346
|
+
process.exit(1);
|
|
347
|
+
}
|
|
348
|
+
if (formatJson) {
|
|
349
|
+
console.log(JSON.stringify(result, null, 2));
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
console.log(`✓ ${aid} disabled${result.reloaded ? ' (hot-reloaded)' : ''}`);
|
|
353
|
+
}
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
// --- get ---
|
|
357
|
+
if (sub === 'get') {
|
|
358
|
+
if (wantsHelp(args)) {
|
|
359
|
+
console.log(`用法: ec agent get <aid> <key> [--format json]
|
|
360
|
+
|
|
361
|
+
读取单个配置字段。key 支持点路径,如 "channels.aun.enabled"。
|
|
362
|
+
托管任务通过 daemon 统一鉴权;无会话的本机 CLI 走控制面。
|
|
363
|
+
|
|
364
|
+
示例:
|
|
365
|
+
ec agent get mybot.agentid.pub active_baseagent
|
|
366
|
+
ec agent get mybot.agentid.pub observable
|
|
367
|
+
ec agent get mybot.agentid.pub channels.aun.enabled`);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const aid = args[1];
|
|
371
|
+
const key = args[2];
|
|
372
|
+
if (!aid || !key) {
|
|
373
|
+
console.error('用法: ec agent get <aid> <key>');
|
|
374
|
+
process.exit(1);
|
|
375
|
+
}
|
|
376
|
+
const result = await agentGet(aid, key);
|
|
377
|
+
if (!result.ok) {
|
|
378
|
+
if (formatJson) {
|
|
379
|
+
console.log(JSON.stringify(result));
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
console.error(`❌ ${result.error}`);
|
|
383
|
+
}
|
|
384
|
+
process.exit(1);
|
|
385
|
+
}
|
|
386
|
+
if (formatJson) {
|
|
387
|
+
console.log(JSON.stringify(result, null, 2));
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
const val = result.value;
|
|
391
|
+
console.log(typeof val === 'object' ? JSON.stringify(val, null, 2) : String(val));
|
|
392
|
+
}
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
// --- set ---
|
|
396
|
+
if (sub === 'set') {
|
|
397
|
+
if (wantsHelp(args)) {
|
|
398
|
+
console.log(`用法: ec agent set <aid> <key> <value> [--format json]
|
|
399
|
+
|
|
400
|
+
修改单个配置字段。key 支持点路径。本机控制面会尝试热重载;托管任务如需重载须另行执行 agent reload。
|
|
401
|
+
托管任务通过 daemon 统一鉴权;无会话的本机 CLI 走控制面。
|
|
402
|
+
|
|
403
|
+
示例:
|
|
404
|
+
ec agent set mybot.agentid.pub active_baseagent codex
|
|
405
|
+
ec agent set mybot.agentid.pub observable true
|
|
406
|
+
ec agent set mybot.agentid.pub observable false
|
|
407
|
+
ec agent set mybot.agentid.pub channels.aun.enabled true`);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const aid = args[1];
|
|
411
|
+
const key = args[2];
|
|
412
|
+
const val = args[3];
|
|
413
|
+
if (!aid || !key || val === undefined) {
|
|
414
|
+
console.error('用法: ec agent set <aid> <key> <value>');
|
|
415
|
+
process.exit(1);
|
|
416
|
+
}
|
|
417
|
+
const result = await agentSet(aid, key, val);
|
|
418
|
+
if (!result.ok) {
|
|
419
|
+
if (formatJson) {
|
|
420
|
+
console.log(JSON.stringify(result));
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
console.error(`❌ ${result.error}`);
|
|
424
|
+
}
|
|
425
|
+
process.exit(1);
|
|
426
|
+
}
|
|
427
|
+
if (formatJson) {
|
|
428
|
+
console.log(JSON.stringify(result, null, 2));
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
console.log(`✓ ${aid} ${key} = ${JSON.stringify(result.value)}${result.reloaded ? ' (hot-reloaded)' : ''}`);
|
|
432
|
+
}
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
// --- ready ---
|
|
436
|
+
if (sub === 'ready') {
|
|
437
|
+
if (wantsHelp(args)) {
|
|
438
|
+
console.log(`用法: ec agent ready <aid> [--format json]
|
|
439
|
+
|
|
440
|
+
标记 agent bootstrap 已完成,将 lifecycle 切换为 active。该命令允许 agent 在工具调用中自报完成。`);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
const aid = args[1];
|
|
444
|
+
if (!aid) {
|
|
445
|
+
console.error('用法: ec agent ready <aid>');
|
|
446
|
+
process.exit(1);
|
|
447
|
+
}
|
|
448
|
+
const result = await agentReady(aid);
|
|
449
|
+
if (!result.ok) {
|
|
450
|
+
if (formatJson) {
|
|
451
|
+
console.log(JSON.stringify(result));
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
console.error(`❌ ${result.error}`);
|
|
455
|
+
}
|
|
456
|
+
process.exit(1);
|
|
457
|
+
}
|
|
458
|
+
if (formatJson) {
|
|
459
|
+
console.log(JSON.stringify(result, null, 2));
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
console.log(`✓ ${aid} lifecycle=active${result.reloaded ? ' (runtime updated)' : ' (daemon offline or not updated)'}`);
|
|
463
|
+
}
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
// --- delete ---
|
|
467
|
+
if (sub === 'delete') {
|
|
468
|
+
if (wantsHelp(args)) {
|
|
469
|
+
console.log(`用法: ec agent delete <aid> [--purge] [--format json]
|
|
470
|
+
|
|
471
|
+
删除 agent 的配置。
|
|
472
|
+
--purge 同时清除该 agent 的会话、消息、日志等运行时数据
|
|
473
|
+
默认 仅删除 config.json,运行时数据保留`);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const aid = args[1];
|
|
477
|
+
if (!aid) {
|
|
478
|
+
console.error('用法: ec agent delete <aid> [--purge]');
|
|
479
|
+
process.exit(1);
|
|
480
|
+
}
|
|
481
|
+
const purge = args.includes('--purge');
|
|
482
|
+
const result = await agentDelete(aid, purge);
|
|
483
|
+
if (!result.ok) {
|
|
484
|
+
if (formatJson) {
|
|
485
|
+
console.log(JSON.stringify(result));
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
console.error(`❌ ${result.error}`);
|
|
489
|
+
}
|
|
490
|
+
process.exit(1);
|
|
491
|
+
}
|
|
492
|
+
if (formatJson) {
|
|
493
|
+
console.log(JSON.stringify(result, null, 2));
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
console.log(`✓ ${aid} deleted${purge ? ' (purged)' : ''}`);
|
|
497
|
+
}
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
// --- show ---
|
|
501
|
+
if (sub === 'show') {
|
|
502
|
+
if (wantsHelp(args)) {
|
|
503
|
+
console.log(`用法: ec agent show <aid> [--format json]
|
|
504
|
+
|
|
505
|
+
查看 agent 详情:身份、配置、连接状态、会话路径等。`);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const aid = args[1];
|
|
509
|
+
if (!aid) {
|
|
510
|
+
console.error('用法: ec agent show <aid>');
|
|
511
|
+
process.exit(1);
|
|
512
|
+
}
|
|
513
|
+
const result = await agentShow(aid);
|
|
514
|
+
if (!result.ok) {
|
|
515
|
+
if (formatJson) {
|
|
516
|
+
console.log(JSON.stringify(result));
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
console.error(result.error);
|
|
520
|
+
}
|
|
521
|
+
process.exit(1);
|
|
522
|
+
}
|
|
523
|
+
if (formatJson) {
|
|
524
|
+
console.log(JSON.stringify(result, null, 2));
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
printAgentShowHuman(result);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
// --- rename ---
|
|
531
|
+
if (sub === 'rename') {
|
|
532
|
+
if (wantsHelp(args)) {
|
|
533
|
+
console.log(`用法: ec agent rename <aid> <name> [--format json]
|
|
534
|
+
|
|
535
|
+
修改本地 AIDs/<aid>/agent.md 中的 name 字段。`);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const aid = args[1];
|
|
539
|
+
const name = args[2];
|
|
540
|
+
if (!aid || !name) {
|
|
541
|
+
console.error('用法: ec agent rename <aid> <name>');
|
|
542
|
+
process.exit(1);
|
|
543
|
+
}
|
|
544
|
+
const result = await agentRename(aid, name);
|
|
545
|
+
if (!result.ok) {
|
|
546
|
+
if (formatJson) {
|
|
547
|
+
console.log(JSON.stringify(result));
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
console.error(result.error);
|
|
551
|
+
}
|
|
552
|
+
process.exit(1);
|
|
553
|
+
}
|
|
554
|
+
if (formatJson) {
|
|
555
|
+
console.log(JSON.stringify(result, null, 2));
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
console.log(`✓ ${aid} renamed to ${result.name}`);
|
|
559
|
+
}
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
// --- default: `ec agent <aid>` (shorthand for show) ---
|
|
563
|
+
const result = await agentShow(sub);
|
|
564
|
+
if (!result.ok) {
|
|
565
|
+
if (formatJson) {
|
|
566
|
+
console.log(JSON.stringify(result));
|
|
567
|
+
}
|
|
568
|
+
else {
|
|
569
|
+
console.error(result.error);
|
|
570
|
+
}
|
|
571
|
+
process.exit(1);
|
|
572
|
+
}
|
|
573
|
+
if (formatJson) {
|
|
574
|
+
console.log(JSON.stringify(result, null, 2));
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
printAgentShowHuman(result);
|
|
578
|
+
}
|
|
579
|
+
function printAgentShowHuman(result) {
|
|
580
|
+
console.log(`${result.aid} (${result.status})\n`);
|
|
581
|
+
if (result.identity.name || result.identity.description) {
|
|
582
|
+
console.log(' Identity');
|
|
583
|
+
if (result.identity.name)
|
|
584
|
+
console.log(` Name: ${result.identity.name}`);
|
|
585
|
+
if (result.identity.description)
|
|
586
|
+
console.log(` Description: ${result.identity.description}`);
|
|
587
|
+
console.log('');
|
|
588
|
+
}
|
|
589
|
+
console.log(' Config');
|
|
590
|
+
console.log(` Baseagent: ${result.config.baseagent || '—'}`);
|
|
591
|
+
if (result.config.model)
|
|
592
|
+
console.log(` Model: ${result.config.model}`);
|
|
593
|
+
if (result.config.effort)
|
|
594
|
+
console.log(` Effort: ${result.config.effort}`);
|
|
595
|
+
if (result.config.chatmode)
|
|
596
|
+
console.log(` Chatmode: private=${result.config.chatmode.private} group=${result.config.chatmode.group}`);
|
|
597
|
+
console.log(` Channels: ${result.config.channels.length > 0 ? result.config.channels.join(', ') : '—'}`);
|
|
598
|
+
console.log('');
|
|
599
|
+
if (result.connection) {
|
|
600
|
+
const c = result.connection;
|
|
601
|
+
console.log(' Connection');
|
|
602
|
+
console.log(` Status: ${c.status}`);
|
|
603
|
+
console.log(` Uptime: ${c.uptime_ms != null ? formatDurationMs(c.uptime_ms) : '—'}`);
|
|
604
|
+
console.log(` Reconnects: ${c.reconnect_count}`);
|
|
605
|
+
console.log(` Msgs recv: ${c.messages_received}`);
|
|
606
|
+
console.log(` Msgs sent: ${c.messages_sent}`);
|
|
607
|
+
console.log(` Bytes in: ${formatBytes(c.bytes_received)}`);
|
|
608
|
+
console.log(` Bytes out: ${formatBytes(c.bytes_sent)}`);
|
|
609
|
+
console.log(` Last recv: ${c.last_received_at ? formatTimeAgo(Date.now() - new Date(c.last_received_at).getTime()) : '—'}`);
|
|
610
|
+
console.log(` Last sent: ${c.last_sent_at ? formatTimeAgo(Date.now() - new Date(c.last_sent_at).getTime()) : '—'}`);
|
|
611
|
+
console.log(` Peers: ${c.unique_peer_count}`);
|
|
612
|
+
console.log('');
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
console.log(' Connection (daemon offline)');
|
|
616
|
+
console.log('');
|
|
617
|
+
}
|
|
618
|
+
console.log(' Sessions');
|
|
619
|
+
console.log(` Active: ${result.sessions.active}`);
|
|
620
|
+
console.log(` Last active: ${result.sessions.last_activity ? formatTimeAgo(Date.now() - new Date(result.sessions.last_activity).getTime()) : '—'}`);
|
|
621
|
+
console.log('');
|
|
622
|
+
console.log(' Paths');
|
|
623
|
+
console.log(` Config: ${result.paths.config}`);
|
|
624
|
+
console.log(` Agent.md: ${result.paths.agent_md}`);
|
|
625
|
+
console.log(` Project: ${result.paths.project || '—'}`);
|
|
626
|
+
console.log(` Data: ${result.paths.data}`);
|
|
627
|
+
}
|
|
628
|
+
function formatDurationMs(ms) {
|
|
629
|
+
const sec = Math.floor(ms / 1000);
|
|
630
|
+
if (sec < 60)
|
|
631
|
+
return `${sec}s`;
|
|
632
|
+
const min = Math.floor(sec / 60);
|
|
633
|
+
const s = sec % 60;
|
|
634
|
+
if (min < 60)
|
|
635
|
+
return `${min}m${String(s).padStart(2, '0')}s`;
|
|
636
|
+
const hour = Math.floor(min / 60);
|
|
637
|
+
const m = min % 60;
|
|
638
|
+
if (hour < 24)
|
|
639
|
+
return `${hour}h${String(m).padStart(2, '0')}m${String(s).padStart(2, '0')}s`;
|
|
640
|
+
const day = Math.floor(hour / 24);
|
|
641
|
+
return `${day}d${hour % 24}h${String(m).padStart(2, '0')}m`;
|
|
642
|
+
}
|