evolcore 0.0.43-test.6 → 0.0.43-test.8
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 +95 -0
- package/bin/ecmsg.js +188 -58
- package/dist/agent-template/jobs.js +62 -0
- package/dist/agent-template/runtime.js +214 -0
- package/dist/agent-template/service.js +465 -0
- package/dist/agent-template/tool-runner.js +45 -0
- package/dist/agent-template/types.js +5 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/claude-runner.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/aid/agentmd.js +56 -1
- package/dist/aun/aid/client.js +3 -1
- package/dist/aun/menu/client.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +277 -49
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +7 -3
- package/dist/cli/agent-template.js +124 -0
- package/dist/cli/aun-commands.js +2 -2
- package/dist/cli/ctl-command.js +2 -1
- package/dist/cli/daemon-commands.js +11 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +109 -0
- package/dist/cli/index.js +60 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/net-check.js +1 -1
- package/dist/cli/restart-monitor.js +160 -83
- package/dist/cli/services-command.js +137 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +103 -13
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +8 -8
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +45 -15
- package/dist/config-store.js +2 -1
- package/dist/core/agent-ipc-registration.js +25 -4
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +106 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-authorizer.js +2 -0
- package/dist/core/auth/operation-catalog.js +29 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +20 -12
- package/dist/core/command/agent-control.js +12 -2
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/agent-template-menu.js +147 -0
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +80 -17
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +468 -0
- package/dist/core/command/menu-catalog.js +15 -0
- package/dist/core/command/menu-handler.js +216 -90
- package/dist/core/command/menu-protocol.js +71 -13
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +22 -5
- package/dist/core/daemon-lifecycle.js +323 -191
- package/dist/core/handoff/runtime.js +45 -13
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +50 -7
- package/dist/core/legacy-rename.js +41 -0
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +252 -17
- package/dist/core/message/im-renderer.js +116 -85
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-queue.js +66 -15
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +29 -5
- package/dist/core/message/response-engine.js +194 -61
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +50 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/pack-auth.js +94 -0
- package/dist/core/pack-install.js +194 -0
- package/dist/core/permission/ec-command-parser.js +51 -17
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/rate-window.js +48 -0
- package/dist/core/relation/peer-identity.js +28 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +67 -28
- package/dist/core/session/session-idle-monitor.js +59 -19
- package/dist/core/session/session-manager.js +13 -4
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/core/thread/thread-service.js +52 -3
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/eck/message-renderer.js +2 -0
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +124 -0
- package/dist/event-center/bus-gate.js +154 -0
- package/dist/event-center/bus-host.js +307 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +127 -0
- package/dist/event-center/daemon.js +44 -0
- package/dist/event-center/directory-source.js +55 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +73 -0
- package/dist/event-center/ipc-operation.js +423 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +207 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +463 -0
- package/dist/event-center/runtime.js +837 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +51 -0
- package/dist/event-center/validation.js +435 -0
- package/dist/index.js +424 -135
- package/dist/ipc.js +106 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/engines/v1/proactive-flow.js +4 -2
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +550 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +215 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +98 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/scheduler.js +38 -0
- package/dist/trigger/script-sandbox.js +170 -24
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +6 -3
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +9 -15
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +3 -1
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/agent.md +22 -1
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +227 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +5 -3
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +28 -1
- package/kits/docs/evolcore/msg.md +21 -9
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +294 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/docs/evolcore/thread-chain.md +15 -3
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +1 -0
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-group/SKILL.md +5 -8
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/message-fragments/item.md +1 -1
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +1 -5
- package/kits/templates/system-fragments/thread.md +13 -10
- package/package.json +5 -6
- package/scripts/agent-template/index.mjs +40 -0
- package/scripts/agent-template/inspect.mjs +240 -0
- package/scripts/agent-template/overlay.mjs +71 -0
- package/scripts/agent-template/pack.mjs +169 -0
- package/scripts/agent-template/shared/common.mjs +235 -0
- package/scripts/agent-template/shared/evolcore.mjs +75 -0
- package/scripts/agent-template/shared/plan.mjs +129 -0
- package/scripts/agent-template/shared/team-schema.json +70 -0
- package/scripts/agent-template/shared/template-contract.mjs +154 -0
- package/scripts/agent-template/shared/template-package.mjs +265 -0
- package/scripts/agent-template/shared/template-runtime.mjs +80 -0
- package/scripts/agent-template/shared/template.mjs +142 -0
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { getArgValue, queryDaemon, wantsHelp } from './help.js';
|
|
4
|
+
import { runManagedAgentOperation } from './agent.js';
|
|
5
|
+
import { resolvePaths } from '../paths.js';
|
|
6
|
+
import { MAIN_CLI_BIN, SESSION_ID_ENV } from '../product.js';
|
|
7
|
+
import { getDaemonOwners, refreshOwnershipForAuthorization } from '../core/ownership/owner-resolver.js';
|
|
8
|
+
import { getAgentTemplateService } from '../agent-template/service.js';
|
|
9
|
+
import { validateTemplateRequest } from '../core/command/agent-template-menu.js';
|
|
10
|
+
import { templateError } from '../agent-template/types.js';
|
|
11
|
+
export function parseTemplateCommand(argv) {
|
|
12
|
+
const action = argv[0];
|
|
13
|
+
const target = argv[1];
|
|
14
|
+
const value = (flag) => getArgValue(argv, flag);
|
|
15
|
+
const json = (flag, fallback) => value(flag) ? JSON.parse(value(flag)) : fallback;
|
|
16
|
+
const comma = (flag) => value(flag)?.split(',').map(v => v.trim()).filter(Boolean) ?? [];
|
|
17
|
+
const allowed = new Set(['--request-id', '--wait', '--format', '--version', '--id', '--name', '--description', '--os', '--baseagent',
|
|
18
|
+
'--baseagents-json', '--skill', '--trigger', '--workspace', '--owner', '--path', '--released-json', '--share-id', '--digest',
|
|
19
|
+
'--agent', '--targets-json', '--members-json', '--providers-json', '--external-aids-json']);
|
|
20
|
+
for (let i = 2; i < argv.length; i += 2) {
|
|
21
|
+
if (!allowed.has(argv[i]) || argv[i + 1] === undefined || argv[i + 1].startsWith('--'))
|
|
22
|
+
throw new Error('Invalid template option: ' + argv[i]);
|
|
23
|
+
}
|
|
24
|
+
let args;
|
|
25
|
+
if (action === 'inspect')
|
|
26
|
+
args = { aid: target };
|
|
27
|
+
else if (action === 'build') {
|
|
28
|
+
const baseagents = comma('--baseagent');
|
|
29
|
+
args = { aid: target, template: { id: value('--id'), version: value('--version'), name: value('--name') ?? target?.split('.')[0],
|
|
30
|
+
description: value('--description') }, include: {
|
|
31
|
+
...(value('--os') ? { platforms: comma('--os') } : {}),
|
|
32
|
+
...(baseagents.length ? { baseagents: baseagents.map((name, i) => ({ name, default: i === 0 })) } : {}),
|
|
33
|
+
...(value('--baseagents-json') ? { baseagents: json('--baseagents-json', []) } : {}),
|
|
34
|
+
triggers: comma('--trigger'), skills: comma('--skill'), files: comma('--workspace'),
|
|
35
|
+
} };
|
|
36
|
+
}
|
|
37
|
+
else if (action === 'push')
|
|
38
|
+
args = { buildId: target, ownerAid: value('--owner'), targetPath: value('--path'), releasedFindings: json('--released-json', []) };
|
|
39
|
+
else if (action === 'pull') {
|
|
40
|
+
const separator = target?.indexOf(':/') ?? -1;
|
|
41
|
+
args = { location: { aid: target?.slice(0, separator), path: target?.slice(separator + 1) },
|
|
42
|
+
download: { shareId: value('--share-id') }, digest: value('--digest'), targetAid: value('--agent'),
|
|
43
|
+
...(value('--targets-json') ? { targets: json('--targets-json', {}) } : {}) };
|
|
44
|
+
}
|
|
45
|
+
else if (action === 'deploy')
|
|
46
|
+
args = { pullId: target,
|
|
47
|
+
...(value('--members-json') ? { members: json('--members-json', {}),
|
|
48
|
+
...(value('--providers-json') ? { providers: json('--providers-json', {}) } : {}),
|
|
49
|
+
...(value('--external-aids-json') ? { externalAids: json('--external-aids-json', {}) } : {}) }
|
|
50
|
+
: { providers: json('--providers-json', {}), externalAids: json('--external-aids-json', {}) }) };
|
|
51
|
+
else if (action === 'status')
|
|
52
|
+
args = { view: 'template-job', jobId: target };
|
|
53
|
+
else
|
|
54
|
+
throw new Error('Expected inspect/build/push/pull/deploy/status');
|
|
55
|
+
args = JSON.parse(JSON.stringify(args));
|
|
56
|
+
const invalid = validateTemplateRequest({ name: 'agent', type: action === 'status' ? 'menu.query' : 'menu.action', action, args });
|
|
57
|
+
if (invalid)
|
|
58
|
+
throw new Error(invalid.message);
|
|
59
|
+
const wait = Number(value('--wait') ?? 60);
|
|
60
|
+
if (!Number.isFinite(wait) || wait < 0 || wait > 300)
|
|
61
|
+
throw new Error('--wait must be 0–300 seconds');
|
|
62
|
+
return { action: action, args, requestId: value('--request-id') ?? randomUUID(), wait };
|
|
63
|
+
}
|
|
64
|
+
export async function executeTemplateCommand(actor, argv) {
|
|
65
|
+
const parsed = parseTemplateCommand(argv);
|
|
66
|
+
const service = getAgentTemplateService();
|
|
67
|
+
if (parsed.action === 'status')
|
|
68
|
+
return { ok: true, data: await service.query(actor, parsed.args) };
|
|
69
|
+
const data = await service.action(actor, parsed.requestId, parsed.action, parsed.args);
|
|
70
|
+
if (data.jobId && parsed.wait) {
|
|
71
|
+
let timer;
|
|
72
|
+
try {
|
|
73
|
+
await Promise.race([service.wait(data.jobId), new Promise(resolve => { timer = setTimeout(resolve, parsed.wait * 1000); })]);
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
if (timer)
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
}
|
|
79
|
+
const event = await service.query(actor, { jobId: data.jobId });
|
|
80
|
+
if (event.status === 'failed')
|
|
81
|
+
return { ok: false, code: event.code, error: event.message, data: event.data, jobId: data.jobId };
|
|
82
|
+
return { ok: true, data: event.status === 'succeeded' ? { ...event.data, jobId: data.jobId } : event };
|
|
83
|
+
}
|
|
84
|
+
return { ok: true, data };
|
|
85
|
+
}
|
|
86
|
+
/** Called only after IPC has authenticated the standalone host control token. */
|
|
87
|
+
export async function executeHostTemplateCommand(argv) {
|
|
88
|
+
await refreshOwnershipForAuthorization(undefined, { force: true, allowTransient: false, source: 'agent-template-cli' });
|
|
89
|
+
const actor = getDaemonOwners()[0];
|
|
90
|
+
if (!actor)
|
|
91
|
+
throw templateError('NOT_ALLOWED', 'Verified DaemonOwner required');
|
|
92
|
+
return executeTemplateCommand(actor, argv);
|
|
93
|
+
}
|
|
94
|
+
export async function cmdAgentTemplate(args) {
|
|
95
|
+
if (!args.length || wantsHelp(args)) {
|
|
96
|
+
console.log(`${MAIN_CLI_BIN} agent template <inspect|build|push|pull|deploy|status> <aid|id|location> [options]\n`
|
|
97
|
+
+ 'build: --version X.Y.Z --name NAME [--os linux,darwin] [--baseagents-json JSON] [--skill a,b] [--trigger a,b] [--workspace dist,docs]\n'
|
|
98
|
+
+ 'push: --owner AID --path /templates/ID/ID-VERSION.ectpl [--released-json JSON]\n'
|
|
99
|
+
+ 'pull: OWNER:/templates/ID/ID-VERSION.ectpl --share-id CODE --digest sha256:HASH (--agent AID | --targets-json KEY_TO_AID_JSON)\n'
|
|
100
|
+
+ 'deploy: PULL_ID [--providers-json JSON] [--external-aids-json JSON] | --members-json KEY_TO_SELECTIONS_JSON\n'
|
|
101
|
+
+ 'All commands: --format json --request-id ID --wait 0..300 (default 60). status JOB_ID recovers a task.');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
parseTemplateCommand(args);
|
|
106
|
+
let result;
|
|
107
|
+
if (process.env[SESSION_ID_ENV])
|
|
108
|
+
result = await runManagedAgentOperation(['template', ...args], 310_000);
|
|
109
|
+
else {
|
|
110
|
+
const controlToken = fs.readFileSync(resolvePaths().controlToken, 'utf8').trim();
|
|
111
|
+
const { response, transportError } = await queryDaemon(resolvePaths().socket, { type: 'agent-template.op', controlToken, argv: args }, 310_000);
|
|
112
|
+
if (!response)
|
|
113
|
+
throw new Error(transportError ? JSON.stringify(transportError) : 'Daemon unavailable');
|
|
114
|
+
result = response;
|
|
115
|
+
}
|
|
116
|
+
console.log(JSON.stringify(result, null, 2));
|
|
117
|
+
if (result.ok === false)
|
|
118
|
+
process.exitCode = 1;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.error(JSON.stringify({ ok: false, code: error.code ?? 'INVALID_ARGUMENT', error: error.message }));
|
|
122
|
+
process.exitCode = 1;
|
|
123
|
+
}
|
|
124
|
+
}
|
package/dist/cli/aun-commands.js
CHANGED
|
@@ -1957,7 +1957,7 @@ Options:
|
|
|
1957
1957
|
}
|
|
1958
1958
|
}
|
|
1959
1959
|
}
|
|
1960
|
-
// 宿主终端的简化式:`
|
|
1960
|
+
// 宿主终端的简化式:`ecmsg send '<正文>' --from <selfAid> --thread <ref>`
|
|
1961
1961
|
// 没有托管会话上下文,本端只能由 --self 给出;对端由话题引用推导。
|
|
1962
1962
|
// 这和托管会话里的简化式是同一语义,只是本端来源不同。
|
|
1963
1963
|
if (sub === 'send' && !process.env.EVOLCORE_SESSION_ID) {
|
|
@@ -2005,7 +2005,7 @@ Options:
|
|
|
2005
2005
|
if (!isValidAid(from)) {
|
|
2006
2006
|
console.error(`❌ 无效 AID 格式: ${from}`);
|
|
2007
2007
|
if (sub === 'send') {
|
|
2008
|
-
console.error('提示:宿主终端可用 `
|
|
2008
|
+
console.error('提示:宿主终端可用 `ecmsg send \'<正文>\' --from <本端AID> --thread <话题id> --check-every 5m`');
|
|
2009
2009
|
}
|
|
2010
2010
|
process.exit(1);
|
|
2011
2011
|
}
|
package/dist/cli/ctl-command.js
CHANGED
|
@@ -16,7 +16,8 @@ const CTL_HELP = `用法: ec ctl <command> [args...]
|
|
|
16
16
|
|
|
17
17
|
文件:
|
|
18
18
|
file [channel] <path> 发送项目内文件
|
|
19
|
-
queue [--after <time>] [--before <time>]
|
|
19
|
+
queue [--session <id>] [--after <time>] [--before <time>]
|
|
20
|
+
查看/管理会话消息队列(--session 只读查看其它会话)
|
|
20
21
|
|
|
21
22
|
示例:
|
|
22
23
|
ec ctl status
|
|
@@ -32,7 +32,8 @@ import { logLevelRank } from '../utils/logger.js';
|
|
|
32
32
|
import { inspectDataMigrationRequirement } from '../core/data-migration.js';
|
|
33
33
|
import { readHostInfo, readVersionInfo } from '../utils/host-info.js';
|
|
34
34
|
import { queryStatusActivity, queryStatusActivityByAgent } from '../stats/query.js';
|
|
35
|
-
import {
|
|
35
|
+
import { DAEMON_PROBE_TIMEOUT_MS, DAEMON_SHUTDOWN_TIMEOUT_MS, probeDaemon, requestDaemonShutdown } from './daemon-lifecycle-client.js';
|
|
36
|
+
export { DAEMON_SHUTDOWN_TIMEOUT_MS, requestDaemonShutdown, stopCodexAppServerOrphans } from './daemon-lifecycle-client.js';
|
|
36
37
|
import { DEFAULT_ECWEB_PORT, ecwebService, serviceRuntimeMode, setEcwebEnabled } from '../config/daemon-services.js';
|
|
37
38
|
import { checkCodexProjectPath, inspectCodexManagedHook, ensureCodexManagedHook, runCodexHookLaunchDiagnostic, } from '../agents/codex/diagnostics.js';
|
|
38
39
|
import { formatClaudeSandboxDependencies, formatCodexSandboxAvailability, inspectClaudeSandboxDependencies, inspectCodexSandboxAvailability, probeClaudeSandboxDependencies, probeCodexSandboxAvailability, } from '../core/permission/sandbox-runtime.js';
|
|
@@ -135,37 +136,6 @@ function printNoSelfAgentHints(options) {
|
|
|
135
136
|
console.log(` - ${skippedAgent.dirName}: ${skippedAgent.reason}`);
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
|
-
// Windows named-pipe connection setup can take a couple of seconds on a busy
|
|
139
|
-
// host (especially on the first request after the daemon starts). A one-second
|
|
140
|
-
// probe causes `ec stop` to skip the IPC shutdown path and fall back to
|
|
141
|
-
// taskkill, even though the daemon is healthy and able to shut down gracefully.
|
|
142
|
-
const DAEMON_PROBE_TIMEOUT_MS = platform.isWindows ? 5_000 : 1_000;
|
|
143
|
-
export const DAEMON_SHUTDOWN_TIMEOUT_MS = platform.isWindows ? 10_000 : 3_000;
|
|
144
|
-
async function probeDaemon(socketPath, timeoutMs = DAEMON_PROBE_TIMEOUT_MS, throwOnError = false) {
|
|
145
|
-
const response = await ipcQuery(socketPath, { type: 'ping' }, timeoutMs, { throwOnError });
|
|
146
|
-
if (response?.pong !== true || !Number.isInteger(response.pid) || response.pid <= 0)
|
|
147
|
-
return null;
|
|
148
|
-
return response;
|
|
149
|
-
}
|
|
150
|
-
/** Ask the daemon to run its own graceful shutdown lifecycle. */
|
|
151
|
-
export async function requestDaemonShutdown(socketPath, timeoutMs = DAEMON_SHUTDOWN_TIMEOUT_MS, reason = 'cli', expectedPids, traceId) {
|
|
152
|
-
const daemon = await probeDaemon(socketPath, Math.min(timeoutMs, DAEMON_PROBE_TIMEOUT_MS));
|
|
153
|
-
if (!daemon || (expectedPids && !expectedPids.has(daemon.pid)))
|
|
154
|
-
return null;
|
|
155
|
-
const response = await ipcQuery(socketPath, {
|
|
156
|
-
type: 'shutdown',
|
|
157
|
-
reason,
|
|
158
|
-
expectedPid: daemon.pid,
|
|
159
|
-
// 让 daemon 侧退出阶段落进同一条停止甘特图(时间轴按同一次停止对齐)。
|
|
160
|
-
...(traceId ? { traceId } : {}),
|
|
161
|
-
}, timeoutMs);
|
|
162
|
-
if (response?.ok !== true || response.accepted !== true
|
|
163
|
-
|| !Number.isInteger(response.pid) || response.pid <= 0
|
|
164
|
-
|| response.pid !== daemon.pid) {
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
return response.pid;
|
|
168
|
-
}
|
|
169
139
|
function hasVisibleDaemonPid(status, ping) {
|
|
170
140
|
return status.mains.some(entry => entry.alive && entry.record.pid === ping.pid);
|
|
171
141
|
}
|
|
@@ -1513,16 +1483,22 @@ function renderStatusOverview(snapshot) {
|
|
|
1513
1483
|
renderStatusFields(overviewFields);
|
|
1514
1484
|
const startup = snapshot.daemon.startup;
|
|
1515
1485
|
if (startup) {
|
|
1516
|
-
const phases = { classifying: '识别待恢复任务(控制面可用)', recovering: '优先恢复进行中任务', loading: '
|
|
1517
|
-
const states = { waiting: '等待前置阶段', starting: '启动中', recovering: '恢复运行中任务', ready: '已就绪', failed: '失败', disabled: '已禁用' };
|
|
1486
|
+
const phases = { classifying: '识别待恢复任务(控制面可用)', recovering: '优先恢复进行中任务', loading: '完成启动准入', ready: '正常 Ready', failed: '启动未就绪(关键模块失败)' };
|
|
1487
|
+
const states = { waiting: '等待前置阶段', starting: '启动中', recovering: '恢复运行中任务', ready: '已就绪', failed: '失败', disabled: '已禁用', deferred: '按需加载(未加载)' };
|
|
1518
1488
|
const agents = startup.agents;
|
|
1519
1489
|
renderStatusFields([
|
|
1520
1490
|
['启动进度', phases[startup.phase]],
|
|
1521
1491
|
['已加载', `Runner ${agents.filter(agent => agent.runner === 'ready').length}/${agents.length}`
|
|
1492
|
+
+ `(按需 ${agents.filter(agent => agent.runner === 'deferred').length})`
|
|
1522
1493
|
+ ` · AUN ${agents.filter(agent => agent.aun).length}/${agents.length}`
|
|
1523
1494
|
+ ` · 恢复登记 ${agents.filter(agent => agent.recovery).length}/${agents.length}`
|
|
1524
1495
|
+ ` · Trigger ${startup.triggers.loaded}/${startup.triggers.total}`],
|
|
1525
1496
|
['ECWeb 启动', states[startup.ecweb]],
|
|
1497
|
+
...(startup.backgroundRecovery ? [['后台恢复',
|
|
1498
|
+
`Handoff ${startup.backgroundRecovery.handoff.completed}/${startup.backgroundRecovery.handoff.total}`
|
|
1499
|
+
+ (startup.backgroundRecovery.handoff.retrying ? `(重试 ${startup.backgroundRecovery.handoff.retrying})` : '')
|
|
1500
|
+
+ ` · 历史空闲计时 ${{ waiting: '等待 Ready', restoring: '恢复中', ready: '完成', cancelled: '已取消' }[startup.backgroundRecovery.sessionIdle]}`,
|
|
1501
|
+
]] : []),
|
|
1526
1502
|
...(startup.priorityRelease === 'timeout' || startup.optionalRelease === 'timeout'
|
|
1527
1503
|
? [['启动放行', '已按等待预算放行后续模块;正常 Ready 仍按实际条件判断']] : []),
|
|
1528
1504
|
]);
|
|
@@ -2938,7 +2914,7 @@ async function cmdWatchAid() {
|
|
|
2938
2914
|
// 标记生成:[明文/密文|自主/响应](紫色=工具渲染标记)
|
|
2939
2915
|
const mkTags = (encrypt, chatmode) => {
|
|
2940
2916
|
const enc = encrypt ? '密文' : '明文';
|
|
2941
|
-
const mode = chatmode === '
|
|
2917
|
+
const mode = chatmode === 'proactive' ? '自主' : '响应';
|
|
2942
2918
|
return `${MAGENTA}[${enc}|${mode}]${RST}`;
|
|
2943
2919
|
};
|
|
2944
2920
|
let msgPreview = '';
|
|
@@ -3393,37 +3369,6 @@ async function stopStartedEcweb(pid, expectedStartedAt) {
|
|
|
3393
3369
|
return false;
|
|
3394
3370
|
return platform.waitForProcessExit(pid, 5_000);
|
|
3395
3371
|
}
|
|
3396
|
-
/** 清理 EvolCore 登记的 codex app-server 孤儿进程,返回清理的进程数。 */
|
|
3397
|
-
export function stopCodexAppServerOrphans() {
|
|
3398
|
-
const entries = listCodexAppServerProcesses();
|
|
3399
|
-
if (entries.length === 0)
|
|
3400
|
-
return 0;
|
|
3401
|
-
const codexProcs = new Set(platform.findProcesses('codex app-server'));
|
|
3402
|
-
let killed = 0;
|
|
3403
|
-
for (const entry of entries) {
|
|
3404
|
-
const { pid, startedAt } = entry.record;
|
|
3405
|
-
if (!platform.isProcessRunning(pid)) {
|
|
3406
|
-
unregisterCodexAppServerProcess(entry.filePath);
|
|
3407
|
-
continue;
|
|
3408
|
-
}
|
|
3409
|
-
// PID 复用时丢弃登记,不发送信号;命令行探测失败则保留登记,等待下次重试。
|
|
3410
|
-
const actualStartedAt = getProcessStartTime(pid);
|
|
3411
|
-
if (!startTimeMatches(startedAt, actualStartedAt)) {
|
|
3412
|
-
unregisterCodexAppServerProcess(entry.filePath);
|
|
3413
|
-
continue;
|
|
3414
|
-
}
|
|
3415
|
-
if (!codexProcs.has(pid))
|
|
3416
|
-
continue;
|
|
3417
|
-
try {
|
|
3418
|
-
if (platform.killProcess(pid, true)) {
|
|
3419
|
-
killed++;
|
|
3420
|
-
unregisterCodexAppServerProcess(entry.filePath);
|
|
3421
|
-
}
|
|
3422
|
-
}
|
|
3423
|
-
catch { }
|
|
3424
|
-
}
|
|
3425
|
-
return killed;
|
|
3426
|
-
}
|
|
3427
3372
|
/** Stop managed ECWeb, including verified listeners without instance records. */
|
|
3428
3373
|
async function stopManagedEcweb(p) {
|
|
3429
3374
|
try {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ipcQuery } from '../ipc.js';
|
|
2
|
+
import * as platform from '../utils/cross-platform.js';
|
|
3
|
+
import { getProcessStartTime, startTimeMatches } from '../utils/process-introspect.js';
|
|
4
|
+
import { listCodexAppServerProcesses, unregisterCodexAppServerProcess } from '../agents/codex/app-server-registry.js';
|
|
5
|
+
// A busy Windows named pipe may need several seconds to accept a connection.
|
|
6
|
+
export const DAEMON_PROBE_TIMEOUT_MS = platform.isWindows ? 5_000 : 1_000;
|
|
7
|
+
export const DAEMON_SHUTDOWN_TIMEOUT_MS = platform.isWindows ? 10_000 : 3_000;
|
|
8
|
+
export async function probeDaemon(socketPath, timeoutMs = DAEMON_PROBE_TIMEOUT_MS, throwOnError = false) {
|
|
9
|
+
const response = await ipcQuery(socketPath, { type: 'ping' }, timeoutMs, { throwOnError });
|
|
10
|
+
if (response?.pong !== true || !Number.isInteger(response.pid) || response.pid <= 0)
|
|
11
|
+
return null;
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
14
|
+
/** Ask the verified daemon to run its own graceful shutdown lifecycle. */
|
|
15
|
+
export async function requestDaemonShutdown(socketPath, timeoutMs = DAEMON_SHUTDOWN_TIMEOUT_MS, reason = 'cli', expectedPids, traceId) {
|
|
16
|
+
const daemon = await probeDaemon(socketPath, Math.min(timeoutMs, DAEMON_PROBE_TIMEOUT_MS));
|
|
17
|
+
if (!daemon || (expectedPids && !expectedPids.has(daemon.pid)))
|
|
18
|
+
return null;
|
|
19
|
+
const response = await ipcQuery(socketPath, {
|
|
20
|
+
type: 'shutdown',
|
|
21
|
+
reason,
|
|
22
|
+
expectedPid: daemon.pid,
|
|
23
|
+
...(traceId ? { traceId } : {}),
|
|
24
|
+
}, timeoutMs);
|
|
25
|
+
if (response?.ok !== true || response.accepted !== true
|
|
26
|
+
|| !Number.isInteger(response.pid) || response.pid <= 0
|
|
27
|
+
|| response.pid !== daemon.pid)
|
|
28
|
+
return null;
|
|
29
|
+
return response.pid;
|
|
30
|
+
}
|
|
31
|
+
/** Clean up only registered, identity-verified EvolCore Codex app-server children. */
|
|
32
|
+
export function stopCodexAppServerOrphans() {
|
|
33
|
+
const entries = listCodexAppServerProcesses();
|
|
34
|
+
if (entries.length === 0)
|
|
35
|
+
return 0;
|
|
36
|
+
const codexProcs = new Set(platform.findProcesses('codex app-server'));
|
|
37
|
+
let killed = 0;
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
const { pid, startedAt } = entry.record;
|
|
40
|
+
if (!platform.isProcessRunning(pid)) {
|
|
41
|
+
unregisterCodexAppServerProcess(entry.filePath);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
// Discard reused PIDs without signalling; retain unverified commands to retry.
|
|
45
|
+
const actualStartedAt = getProcessStartTime(pid);
|
|
46
|
+
if (!startTimeMatches(startedAt, actualStartedAt)) {
|
|
47
|
+
unregisterCodexAppServerProcess(entry.filePath);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (!codexProcs.has(pid))
|
|
51
|
+
continue;
|
|
52
|
+
try {
|
|
53
|
+
if (platform.killProcess(pid, true)) {
|
|
54
|
+
killed++;
|
|
55
|
+
unregisterCodexAppServerProcess(entry.filePath);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch { }
|
|
59
|
+
}
|
|
60
|
+
return killed;
|
|
61
|
+
}
|
|
@@ -83,6 +83,11 @@ export function parseGatewayArgs(args) {
|
|
|
83
83
|
continue;
|
|
84
84
|
}
|
|
85
85
|
if (PASSTHROUGH_VALUE_FLAGS.has(flag)) {
|
|
86
|
+
// `--self` 是 `--from` 的历史别名,已从网关移除:本端只由 `--from` 表达。
|
|
87
|
+
// 显式拒绝而不是透传——透传会被下游当成未知选项,或更糟:被当成正文。
|
|
88
|
+
if (flag === '--self') {
|
|
89
|
+
return { ok: false, error: '--self 已不再支持;本端请用 --from <本端AID>' };
|
|
90
|
+
}
|
|
86
91
|
const value = args[++index];
|
|
87
92
|
if (value === undefined)
|
|
88
93
|
return { ok: false, error: `${token} 需要一个值` };
|
|
@@ -133,11 +138,15 @@ function looksLikeAid(value) {
|
|
|
133
138
|
}
|
|
134
139
|
export function buildDownstreamArgv(route, text, passthrough) {
|
|
135
140
|
const scope = route.peer.peerKind === 'group' ? 'group' : 'msg';
|
|
141
|
+
// 收件人:私聊跨话题自派时是本端,否则是话题对端。用 route.peer.id 会把跨话题自派消息
|
|
142
|
+
// 实际投给话题对端(下游按位置参数认目标,--thread 只决定落点会话)。
|
|
143
|
+
// 群发送恒以群 AID 为目标,跨话题自派不适用于群。
|
|
144
|
+
const targetId = scope === 'group' ? route.peer.id : route.recipientId;
|
|
136
145
|
// 目标为原生 ID 时必须靠 --thread 推导,写成位置参数会变成正文的一部分。
|
|
137
|
-
const targetAsPositional = looksLikeAid(
|
|
146
|
+
const targetAsPositional = looksLikeAid(targetId)
|
|
138
147
|
|| (route.peer.peerKind === 'group' && !route.crossTopic);
|
|
139
148
|
const argv = targetAsPositional
|
|
140
|
-
? [scope, 'send', route.self,
|
|
149
|
+
? [scope, 'send', route.self, targetId, ...text, ...passthrough]
|
|
141
150
|
: [scope, 'send', route.self, ...text, ...passthrough];
|
|
142
151
|
// 首次联系:主话题还没被创建,带上 --thread 反而会被下游判成"话题不存在",
|
|
143
152
|
// 所以按普通私聊发出,会话随这条消息建立,也就不建复查。
|
|
@@ -149,6 +158,30 @@ export function buildDownstreamArgv(route, text, passthrough) {
|
|
|
149
158
|
argv.push(route.encryptResolved ? '--encrypt' : '--no-encrypt');
|
|
150
159
|
return argv;
|
|
151
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* 群 AID 的 base 简写展开(`g-18127` → `g-18127.agentid.cn`)。
|
|
163
|
+
*
|
|
164
|
+
* 网关必须在构造路由**之前**完成这一步:`--to g-18127` 若不展开,既判不出它是群
|
|
165
|
+
* (类型解析拿不到证据),也拼不出主话题 id,会直接 `TOPIC_REQUIRED`。
|
|
166
|
+
*
|
|
167
|
+
* 只处理裸 base:已含 issuer 的值原样返回,私聊 AID 不受影响。
|
|
168
|
+
* issuer 取本端 AID 的域,与 `ec group send` / 托管 group 操作的调用口径一致。
|
|
169
|
+
* 展开失败(非群 AID 形态)时同样原样返回,交给后续判定按私聊处理。
|
|
170
|
+
*/
|
|
171
|
+
export function expandGroupBase(selfAid, value, normalizeGroupAid) {
|
|
172
|
+
const id = String(value ?? '').trim().replace(/^@/, '');
|
|
173
|
+
if (!id || id.includes('.'))
|
|
174
|
+
return id;
|
|
175
|
+
const issuer = String(selfAid ?? '').split('.').slice(1).join('.');
|
|
176
|
+
if (!issuer)
|
|
177
|
+
return id;
|
|
178
|
+
try {
|
|
179
|
+
return normalizeGroupAid?.(id, issuer) ?? id;
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return id;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
152
185
|
/**
|
|
153
186
|
* 校验 `--thread` 是否需要在本地索引里查表。
|
|
154
187
|
*
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ec events` CLI:事件中心运维(status / ledger / tail / doctor / reload / rules / publish / pack)。
|
|
3
|
+
* daemon-control 风格:宿主终端读本地 control token;托管会话带 sessionId + 委托令牌
|
|
4
|
+
* (daemon 据此解析调用方身份与角色,见 pack-auth.ts 的 PackCaller 模型)。
|
|
5
|
+
* 经 events.op 转发,daemon 解析执行。
|
|
6
|
+
*/
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { ipcQuery } from '../ipc.js';
|
|
10
|
+
import { readDelegationCredential, hashCurrentDelegatedCommand } from '../core/auth/agent-delegation.js';
|
|
11
|
+
import { resolvePaths } from '../paths.js';
|
|
12
|
+
const HELP = `ec events — 事件中心运维
|
|
13
|
+
|
|
14
|
+
用法:
|
|
15
|
+
ec events status [<包名>] [--aid <aid>] 每包状态
|
|
16
|
+
ec events ledger [<包名>] [--tail N] 台账(不传包名=中心台账)
|
|
17
|
+
ec events tail <包名> [--tail N] 事件日志
|
|
18
|
+
ec events doctor <包名> 诊断
|
|
19
|
+
ec events reload [<包名>] 重载(重新扫描目录并重建订阅)
|
|
20
|
+
ec events rules add <事件> --publish <aid> [--subscribe <aid>] [--deny]
|
|
21
|
+
ec events rules remove <事件> --publish <aid> [--subscribe <aid>] [--deny]
|
|
22
|
+
ec events rules show [--event <事件>]
|
|
23
|
+
ec events publish <包名> <事件> --data '<json>' [--ttl <秒>]
|
|
24
|
+
|
|
25
|
+
安装与卸载(L 类目录只能由 daemon 代写):
|
|
26
|
+
ec events pack add <包名> --from <源目录> [--aid <aid>]
|
|
27
|
+
ec events pack remove <包名> [--aid <aid>] [--purge]
|
|
28
|
+
ec events pack list [--aid <aid>]
|
|
29
|
+
|
|
30
|
+
add 遇到已安装的包直接报错,先 remove 再装。
|
|
31
|
+
remove 默认把日志与台账归档到 <包>/logs/archive-<时间戳>/;--purge 连归档一起删。
|
|
32
|
+
|
|
33
|
+
事件是 TTL 内的在线通知:不落库、不重放。详见 $KITS_DOCS/evolcore/event-center.md`;
|
|
34
|
+
function readControlToken() {
|
|
35
|
+
try {
|
|
36
|
+
return fs.readFileSync(resolvePaths().controlToken, 'utf8').trim() || undefined;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function queryEvents(argv) {
|
|
43
|
+
// 托管会话优先带 delegation 身份:daemon 要靠它判定 owner/admin/member,
|
|
44
|
+
// 只带 control token 会被当成"主机终端",任何角色都能管理。
|
|
45
|
+
// 委托令牌缺失时快速失败:托管任务不该回退去借宿主 control token 充当本机身份。
|
|
46
|
+
const sessionId = process.env.EVOLCORE_SESSION_ID;
|
|
47
|
+
const delegationToken = sessionId ? readDelegationCredential() : undefined;
|
|
48
|
+
if (sessionId && !delegationToken) {
|
|
49
|
+
return { transportError: 'DELEGATION_REQUIRED: 当前任务缺少委托令牌' };
|
|
50
|
+
}
|
|
51
|
+
const controlToken = delegationToken ? undefined : readControlToken();
|
|
52
|
+
try {
|
|
53
|
+
const response = await ipcQuery(resolvePaths().socket, {
|
|
54
|
+
type: 'events.op', argv, controlToken,
|
|
55
|
+
...(sessionId && delegationToken ? { sessionId, delegationToken, delegationCommandHash: hashCurrentDelegatedCommand() } : {}),
|
|
56
|
+
}, 20_000, { throwOnError: false });
|
|
57
|
+
if (!response || typeof response !== 'object')
|
|
58
|
+
return { transportError: 'invalid daemon response' };
|
|
59
|
+
return { response };
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return { transportError: error instanceof Error ? error.message : String(error) };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function printResult(result, json) {
|
|
66
|
+
if (json) {
|
|
67
|
+
console.log(JSON.stringify(result, null, 2));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (result && typeof result === 'object') {
|
|
71
|
+
console.log(JSON.stringify(result, null, 2));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
console.log(String(result));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* `--from` 在 CLI 侧 resolve 成绝对路径:daemon 的 cwd 与调用方(agent 工作区)不同,
|
|
78
|
+
* 相对路径传到 daemon 会指到别处。
|
|
79
|
+
*/
|
|
80
|
+
function resolveFromPath(args) {
|
|
81
|
+
const index = args.indexOf('--from');
|
|
82
|
+
if (index < 0 || index + 1 >= args.length)
|
|
83
|
+
return args;
|
|
84
|
+
const raw = args[index + 1];
|
|
85
|
+
const next = [...args];
|
|
86
|
+
next[index + 1] = path.resolve(raw);
|
|
87
|
+
return next;
|
|
88
|
+
}
|
|
89
|
+
export async function runEventsCommand(argv) {
|
|
90
|
+
const args = resolveFromPath([...argv]);
|
|
91
|
+
const json = args.includes('--json');
|
|
92
|
+
if (args.length === 0 || args[0] === 'help' || args[0] === '--help') {
|
|
93
|
+
console.log(HELP);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const query = await queryEvents(args);
|
|
97
|
+
if ('transportError' in query) {
|
|
98
|
+
console.error(`daemon 不可达:${query.transportError}`);
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const { response } = query;
|
|
103
|
+
if (!response.ok) {
|
|
104
|
+
console.error(`${response.code ?? 'ERROR'}: ${response.error ?? 'unknown error'}`);
|
|
105
|
+
process.exitCode = 1;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
printResult(response.result, json);
|
|
109
|
+
}
|