evolcore 0.0.43-test.7 → 0.0.45
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 +47 -0
- package/bin/ecmsg.js +22 -9
- 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/claude-runner.js +1 -1
- 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 +1 -1
- package/dist/channels/aun.js +47 -32
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +5 -1
- 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 +5 -0
- package/dist/cli/ecmsg-gateway.js +2 -2
- package/dist/cli/events-command.js +45 -9
- package/dist/cli/index.js +29 -0
- package/dist/cli/net-check.js +1 -1
- package/dist/cli/restart-monitor.js +115 -36
- package/dist/cli/services-command.js +29 -3
- package/dist/cli/thread-command.js +97 -11
- package/dist/config/boot-log.js +8 -8
- package/dist/config/schema-migration.js +41 -16
- package/dist/core/agent-ipc-registration.js +25 -4
- package/dist/core/agent-runtime.js +2 -0
- package/dist/core/auth/operation-authorizer.js +2 -0
- package/dist/core/auth/operation-catalog.js +11 -2
- package/dist/core/channel-runtime.js +16 -9
- package/dist/core/command/agent-control.js +11 -1
- package/dist/core/command/agent-template-menu.js +147 -0
- package/dist/core/command/command-handler.js +27 -6
- package/dist/core/command/eventcenter-menu.js +158 -28
- package/dist/core/command/menu-catalog.js +8 -1
- package/dist/core/command/menu-handler.js +18 -6
- package/dist/core/command/menu-protocol.js +11 -2
- package/dist/core/daemon-control.js +14 -0
- package/dist/core/daemon-lifecycle.js +262 -189
- package/dist/core/handoff/runtime.js +42 -10
- package/dist/core/ipc-registration.js +5 -1
- package/dist/core/legacy-rename.js +41 -0
- package/dist/core/message/aun-ipc-sender.js +118 -13
- package/dist/core/message/im-renderer.js +88 -1
- package/dist/core/message/message-queue.js +66 -15
- package/dist/core/message/pending-hints.js +29 -5
- package/dist/core/message/response-engine.js +37 -7
- package/dist/core/message/send-routing.js +13 -6
- package/dist/core/pack-auth.js +94 -0
- package/dist/core/pack-install.js +194 -0
- package/dist/core/permission/ec-command-parser.js +49 -16
- package/dist/core/rate-window.js +48 -0
- package/dist/core/relation/peer-identity.js +28 -0
- package/dist/core/session/session-fs-store.js +66 -26
- package/dist/core/session/session-idle-monitor.js +59 -19
- package/dist/core/session/session-manager.js +13 -4
- package/dist/core/thread/thread-route.js +2 -2
- package/dist/core/thread/thread-service.js +52 -3
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/message-renderer.js +2 -0
- package/dist/event-center/admission-materializer.js +22 -12
- package/dist/event-center/bus-gate.js +20 -2
- package/dist/event-center/bus-host.js +46 -29
- package/dist/event-center/bus-resolver.js +1 -1
- package/dist/event-center/center-config.js +41 -14
- package/dist/event-center/daemon.js +1 -2
- package/dist/event-center/directory-source.js +3 -1
- package/dist/event-center/index-generator.js +12 -2
- package/dist/event-center/ipc-operation.js +140 -25
- package/dist/event-center/pack-loader.js +61 -56
- package/dist/event-center/pack-manager.js +2 -2
- package/dist/event-center/registry.js +242 -17
- package/dist/event-center/runtime.js +271 -75
- package/dist/event-center/types.js +20 -4
- package/dist/event-center/validation.js +34 -12
- package/dist/index.js +147 -44
- package/dist/ipc.js +44 -4
- package/dist/paths.js +2 -2
- package/dist/response-system/engines/v1/proactive-flow.js +4 -2
- package/dist/services/index.js +3 -3
- package/dist/services/ipc-operation.js +99 -7
- package/dist/services/pack-manager.js +17 -6
- package/dist/services/router.js +8 -5
- package/dist/services/validation.js +5 -5
- package/dist/trigger/scheduler.js +38 -0
- package/dist/trigger/script-sandbox.js +52 -2
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +6 -3
- package/kits/docs/aun/ABILITY_CALLING.md +4 -3
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +3 -3
- package/kits/docs/evolcore/agent.md +22 -1
- package/kits/docs/evolcore/event-center.md +30 -10
- package/kits/docs/evolcore/fs.md +4 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -1
- package/kits/docs/evolcore/msg.md +8 -8
- package/kits/docs/evolcore/response.md +2 -2
- package/kits/docs/evolcore/services.md +27 -10
- package/kits/docs/evolcore/thread-chain.md +15 -3
- package/kits/rules/06-channel.md +1 -0
- package/kits/skills/ability/references/calling.md +2 -2
- package/kits/skills/ec-group/SKILL.md +5 -8
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-trigger/SKILL.md +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 +1 -1
- package/kits/templates/system-fragments/commands.md +1 -1
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/thread.md +3 -2
- package/package.json +4 -3
- 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/event-center/client-factory.js +0 -50
package/dist/channels/aun.js
CHANGED
|
@@ -87,6 +87,10 @@ const AUN_TOPIC_NAME_PAYLOAD_TYPES = new Set([
|
|
|
87
87
|
'text', 'file', 'image', 'audio', 'voice', 'video', 'quote', 'link', 'merge',
|
|
88
88
|
'action_card', 'card', 'notice', 'error', 'activity', 'thought',
|
|
89
89
|
]);
|
|
90
|
+
/** Automatic PA output shares the activity queue, not the ordinary reply path. */
|
|
91
|
+
function isAgentFinalPayload(payload) {
|
|
92
|
+
return payload.type === 'custom' && payload.kind === 'agent_final';
|
|
93
|
+
}
|
|
90
94
|
function jsonUtf8Size(value) {
|
|
91
95
|
return Buffer.byteLength(JSON.stringify(value), 'utf8');
|
|
92
96
|
}
|
|
@@ -808,7 +812,7 @@ export class AUNChannel {
|
|
|
808
812
|
ownerDirectoryRetryAttempts = 0;
|
|
809
813
|
ownerDirectoryResolvedSignature;
|
|
810
814
|
store = null;
|
|
811
|
-
/** 服务路由实例(懒建;services
|
|
815
|
+
/** 服务路由实例(懒建;services-config.json 不存在时也建,只是总闸关闭)。 */
|
|
812
816
|
serviceRouter = null;
|
|
813
817
|
/**
|
|
814
818
|
* 本 agent 的工程目录,由插件从 `ChannelBuildContext.defaultProjectPath` 注入。
|
|
@@ -816,7 +820,7 @@ export class AUNChannel {
|
|
|
816
820
|
* 保证同一条 invoke 链路上所有消费方看到的是同一个目录。
|
|
817
821
|
*/
|
|
818
822
|
defaultProjectPath;
|
|
819
|
-
/** 实际连接的网关 URL
|
|
823
|
+
/** 实际连接的网关 URL,来自 SDK 连接状态事件。 */
|
|
820
824
|
gatewayUrl = '';
|
|
821
825
|
projectPathProvider;
|
|
822
826
|
sessionStateResolver;
|
|
@@ -2649,29 +2653,8 @@ export class AUNChannel {
|
|
|
2649
2653
|
}
|
|
2650
2654
|
});
|
|
2651
2655
|
}
|
|
2652
|
-
//
|
|
2653
|
-
|
|
2654
|
-
logger.info(`${this.logPrefix()} Authenticating as ${aidName}...`);
|
|
2655
|
-
this.trace('OUT', 'auth.authenticate', { aid: aidName });
|
|
2656
|
-
const auth = await client.authenticate();
|
|
2657
|
-
this.trace('OUT', 'auth.authenticate.ok', { aid: client.aid, gateway: auth?.gateway, hasToken: !!auth?.access_token });
|
|
2658
|
-
this.trace('IN', 'auth.result', { aid: client.aid, gateway: auth?.gateway, hasToken: !!auth?.access_token });
|
|
2659
|
-
const resolvedGateway = typeof auth?.gateway === 'string' ? auth.gateway : '';
|
|
2660
|
-
this.gatewayUrl = resolvedGateway;
|
|
2661
|
-
logger.info(`${this.logPrefix()} Authenticated as ${client.aid ?? '?'}, gateway=${resolvedGateway}`);
|
|
2662
|
-
}
|
|
2663
|
-
catch (e) {
|
|
2664
|
-
const errMsg = e.message || String(e);
|
|
2665
|
-
const errName = e.constructor?.name || 'Error';
|
|
2666
|
-
this.trace('OUT', 'auth.authenticate.error', { error: errMsg, name: errName });
|
|
2667
|
-
logger.error(`${this.logPrefix()} Authentication failed (${errName}): ${errMsg}`);
|
|
2668
|
-
if (e.stack)
|
|
2669
|
-
logger.debug(`${this.logPrefix()} Auth stack: ${e.stack}`);
|
|
2670
|
-
this.setAidStatus('failed', { lastError: `${errName}: ${errMsg}`.slice(0, 80) });
|
|
2671
|
-
this.scheduleReconnect();
|
|
2672
|
-
throw new Error(`Authentication failed: ${errName}: ${errMsg}`);
|
|
2673
|
-
}
|
|
2674
|
-
// Connect (SDK auto_reconnect handles transient failures)
|
|
2656
|
+
// connect() owns discovery and authentication. Calling authenticate() first
|
|
2657
|
+
// makes the SDK discover the gateway twice; state events provide its URL.
|
|
2675
2658
|
try {
|
|
2676
2659
|
const extraInfo = buildConnectExtraInfo({
|
|
2677
2660
|
aid: this.config.aid,
|
|
@@ -5516,11 +5499,28 @@ export class AUNChannel {
|
|
|
5516
5499
|
this.groupInviteDelivered?.(entry.postSend.requestId, messageId);
|
|
5517
5500
|
}
|
|
5518
5501
|
}
|
|
5502
|
+
/**
|
|
5503
|
+
* 目标是否为本端自己的 AID(self-address)。
|
|
5504
|
+
*
|
|
5505
|
+
* 跨话题自派不是跨主体通讯:收件人就是本端,联系人名录里有没有自己、名录快照是否
|
|
5506
|
+
* 可用都不该成为门槛。发送器层(`aun-ipc-sender.ts`)已按此短路,这里补上
|
|
5507
|
+
* 渠道层——否则 `sendDaemonMsg` / `callClient` 会再判一次,在名录缺自身
|
|
5508
|
+
* 条目或快照不可用的 Agent 上把跨话题派生挡成 CONTACT_DENIED。
|
|
5509
|
+
*/
|
|
5510
|
+
isSelfAddressedTarget(channelId) {
|
|
5511
|
+
const normalize = (value) => String(value ?? '').trim().replace(/^@/, '').toLowerCase();
|
|
5512
|
+
const self = normalize(this.config.aid);
|
|
5513
|
+
const target = normalize(channelId);
|
|
5514
|
+
return !!self && !!target && self === target;
|
|
5515
|
+
}
|
|
5519
5516
|
appContactOutboundBlock(channelId, delivery, payload, params) {
|
|
5520
5517
|
// 服务回复是对一次已到达请求的应答,不是主动联系;且拒绝信息本身必须能送达,
|
|
5521
5518
|
// 否则调用方只会看到超时。
|
|
5522
5519
|
if (delivery.chatType === 'private' && delivery.service)
|
|
5523
5520
|
return undefined;
|
|
5521
|
+
// 跨话题自派:收件人是本端,不是跨主体通讯,不适用联系人准入(同 aun-ipc-sender)。
|
|
5522
|
+
if (this.isSelfAddressedTarget(channelId))
|
|
5523
|
+
return undefined;
|
|
5524
5524
|
if (delivery.chatType === 'group' || this.config.pureIdentity
|
|
5525
5525
|
|| this.hasContactControlPermit(channelId, payload, params))
|
|
5526
5526
|
return undefined;
|
|
@@ -5537,6 +5537,9 @@ export class AUNChannel {
|
|
|
5537
5537
|
async prepareAppContactOutbound(channelId, delivery, payload, params) {
|
|
5538
5538
|
if (delivery.chatType === 'private' && delivery.service)
|
|
5539
5539
|
return undefined;
|
|
5540
|
+
// 跨话题自派:收件人是本端,连通告归属刷新这一跳都不需要。
|
|
5541
|
+
if (this.isSelfAddressedTarget(channelId))
|
|
5542
|
+
return undefined;
|
|
5540
5543
|
if (delivery.chatType === 'private' && !this.config.pureIdentity
|
|
5541
5544
|
&& !this.hasContactControlPermit(channelId, payload, params)
|
|
5542
5545
|
&& !this.acceptsVerifiedOwnership(channelId, payload, params)) {
|
|
@@ -5605,10 +5608,11 @@ export class AUNChannel {
|
|
|
5605
5608
|
// Truncate payload if too large (AUN SDK limit: 1MB)
|
|
5606
5609
|
const friendPayload = typeof payload.type === 'string' && payload.type.startsWith('friend.');
|
|
5607
5610
|
const truncatedPayload = friendPayload ? payloadWithCausationRef : this.truncatePayloadIfNeeded(await this.withSessionState(channelId, payloadWithCausationRef, context), label);
|
|
5608
|
-
if (payload.type === 'activity' && truncatedPayload.type !== 'activity')
|
|
5611
|
+
if ((payload.type === 'activity' && truncatedPayload.type !== 'activity')
|
|
5612
|
+
|| (isAgentFinalPayload(payload) && !isAgentFinalPayload(truncatedPayload))) {
|
|
5609
5613
|
return {
|
|
5610
5614
|
ok: false, status: 'permanent', code: 'PAYLOAD_TOO_LARGE',
|
|
5611
|
-
error: '
|
|
5615
|
+
error: 'automatic output payload cannot fit the AUN limit without losing its structure',
|
|
5612
5616
|
};
|
|
5613
5617
|
}
|
|
5614
5618
|
const params = { payload: truncatedPayload, encrypt };
|
|
@@ -5675,9 +5679,12 @@ export class AUNChannel {
|
|
|
5675
5679
|
return payload;
|
|
5676
5680
|
const entry = ThreadService.findThreadById(this.config.aid, threadId);
|
|
5677
5681
|
const type = payload.type;
|
|
5682
|
+
// 自发(target=本端)时 peer 是本端,而话题对端是别人;两者不相等不能当成
|
|
5683
|
+
// 话题不匹配。这种情况仍要带上话题名,客户端才能把这条消息正确归位。
|
|
5684
|
+
const selfAddressed = peer.trim().toLowerCase() === this.config.aid.trim().toLowerCase();
|
|
5678
5685
|
if (!entry || typeof threadId !== 'string' || threadId !== entry.threadId
|
|
5679
|
-
|| typeof type !== 'string' || !AUN_TOPIC_NAME_PAYLOAD_TYPES.has(type)
|
|
5680
|
-
|| entry.peer.trim().toLowerCase() !== peer.trim().toLowerCase()
|
|
5686
|
+
|| typeof type !== 'string' || (!AUN_TOPIC_NAME_PAYLOAD_TYPES.has(type) && !isAgentFinalPayload(payload))
|
|
5687
|
+
|| (!selfAddressed && entry.peer.trim().toLowerCase() !== peer.trim().toLowerCase())
|
|
5681
5688
|
|| (entry.channelType && entry.channelType !== 'aun')) {
|
|
5682
5689
|
return payload;
|
|
5683
5690
|
}
|
|
@@ -5922,7 +5929,10 @@ export class AUNChannel {
|
|
|
5922
5929
|
const result = await this.sendContentPayload(channelId, payload, {
|
|
5923
5930
|
// Activity items use the durable activity queue so reconnect draining
|
|
5924
5931
|
// preserves their ordering relative to other lifecycle events.
|
|
5925
|
-
queue: payload.type === 'activity' ? 'activity' : undefined,
|
|
5932
|
+
queue: payload.type === 'activity' || isAgentFinalPayload(payload) ? 'activity' : undefined,
|
|
5933
|
+
...(isAgentFinalPayload(payload) && payload.task_id ? {
|
|
5934
|
+
dedupeKey: `agent-final:${payload.session_id ?? ''}:${payload.task_id}`,
|
|
5935
|
+
} : {}),
|
|
5926
5936
|
contentKind: 'custom',
|
|
5927
5937
|
context,
|
|
5928
5938
|
logText: logText ?? this.payloadLogText(payload, 'custom'),
|
|
@@ -6251,7 +6261,7 @@ export class AUNChannel {
|
|
|
6251
6261
|
}
|
|
6252
6262
|
this.forwardOutbound(result, args.debug);
|
|
6253
6263
|
let logWritten = false;
|
|
6254
|
-
//
|
|
6264
|
+
// 跨话题自派(`--to <本端AID>`)不写出站日志:chatDir 会按 (to=本端, self=本端) 算成
|
|
6255
6265
|
// 「我↔我」目录,`ThreadService.listPeers` 的磁盘兜底会把它列成真实对端,
|
|
6256
6266
|
// 而话题 T 的历史里也会凭空多出一条「发给本端自己」的出站记录。
|
|
6257
6267
|
// 「自己收到了什么」由本地注入那条入站记录(source='self-address')表达。
|
|
@@ -8252,7 +8262,12 @@ export class AUNChannelPlugin {
|
|
|
8252
8262
|
channel.sendProcessingStatus(channelId, 'progress', envelope.sessionId ?? envelope.taskId, envelope.taskId, replyCtx, metadata);
|
|
8253
8263
|
continue;
|
|
8254
8264
|
}
|
|
8255
|
-
|
|
8265
|
+
let aunPayload = channel.buildActivityPayload(envelope, replyCtx, item);
|
|
8266
|
+
if (envelope.chatmode === 'proactive' && envelope.activityTransport === 'message'
|
|
8267
|
+
&& payload.isFinal === true && (item.kind === 'text' || (item.kind === 'summary' && !item.is_error))) {
|
|
8268
|
+
const { item: _item, type: _type, ...base } = aunPayload;
|
|
8269
|
+
aunPayload = { ...base, type: 'custom', kind: 'agent_final', text: item.text };
|
|
8270
|
+
}
|
|
8256
8271
|
if (envelope.chatmode === 'proactive' && envelope.activityTransport !== 'message') {
|
|
8257
8272
|
await channel.sendThought(channelId, envelope.taskId, aunPayload, replyCtx);
|
|
8258
8273
|
}
|
|
@@ -107,6 +107,10 @@ function printAgentNewHelp() {
|
|
|
107
107
|
export async function cmdAgent(args) {
|
|
108
108
|
args = canonicalizeEvolcoreCommandArgv(['ec', 'agent', ...args]).slice(2);
|
|
109
109
|
const sub = args[0];
|
|
110
|
+
if (sub === 'template') {
|
|
111
|
+
const { cmdAgentTemplate } = await import('./agent-template.js');
|
|
112
|
+
return cmdAgentTemplate(args.slice(1));
|
|
113
|
+
}
|
|
110
114
|
if (sub === 'new') {
|
|
111
115
|
const nameIndex = args.indexOf('--name');
|
|
112
116
|
if (nameIndex >= 0)
|
|
@@ -130,6 +134,7 @@ Commands:
|
|
|
130
134
|
list 列出所有 agent
|
|
131
135
|
show <aid> 查看 agent 详情(身份 + 配置 + 连接 + 会话 + 路径)
|
|
132
136
|
host <aid> 查看 agent 所在主机信息(位置、daemon、硬件、版本)
|
|
137
|
+
template <command> 模板清单、打包、上传、预检、安装及任务查询
|
|
133
138
|
new <aid> ... 创建并激活(默认 --initialize,隐含非交互)
|
|
134
139
|
new <aid> --bootstrap ... 创建后进入 Bootstrap(隐含非交互)
|
|
135
140
|
initialize <aid> --resume 恢复一次性初始化
|
package/dist/cli/agent-create.js
CHANGED
|
@@ -1596,8 +1596,12 @@ export class AgentInitializationService {
|
|
|
1596
1596
|
if (r.configSaved && (!config || config.enabled === false))
|
|
1597
1597
|
failure('INITIALIZE_TARGET_CHANGED');
|
|
1598
1598
|
const baseagentConfig = config?.baseagents?.[r.plan.baseagent];
|
|
1599
|
+
// Config loading strips trailing separators; compare canonical paths while
|
|
1600
|
+
// preserving the frozen plan and fingerprint for existing receipts.
|
|
1601
|
+
const project = config?.projects?.defaultPath;
|
|
1599
1602
|
if (config && (config.initialization?.operationId !== r.operationId || config.initialization.mode !== 'supplied'
|
|
1600
|
-
|| config.active_baseagent !== r.plan.baseagent
|
|
1603
|
+
|| config.active_baseagent !== r.plan.baseagent
|
|
1604
|
+
|| typeof project !== 'string' || !path.isAbsolute(project) || path.resolve(project) !== path.resolve(r.plan.project)
|
|
1601
1605
|
|| (r.plan.model !== undefined && baseagentConfig?.model !== r.plan.model)
|
|
1602
1606
|
|| (r.plan.effort !== undefined && baseagentConfig?.effort !== r.plan.effort))) {
|
|
1603
1607
|
failure('INITIALIZE_TARGET_CHANGED');
|
|
@@ -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
|
|
@@ -1494,6 +1494,11 @@ function renderStatusOverview(snapshot) {
|
|
|
1494
1494
|
+ ` · 恢复登记 ${agents.filter(agent => agent.recovery).length}/${agents.length}`
|
|
1495
1495
|
+ ` · Trigger ${startup.triggers.loaded}/${startup.triggers.total}`],
|
|
1496
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
|
+
]] : []),
|
|
1497
1502
|
...(startup.priorityRelease === 'timeout' || startup.optionalRelease === 'timeout'
|
|
1498
1503
|
? [['启动放行', '已按等待预算放行后续模块;正常 Ready 仍按实际条件判断']] : []),
|
|
1499
1504
|
]);
|
|
@@ -138,9 +138,9 @@ function looksLikeAid(value) {
|
|
|
138
138
|
}
|
|
139
139
|
export function buildDownstreamArgv(route, text, passthrough) {
|
|
140
140
|
const scope = route.peer.peerKind === 'group' ? 'group' : 'msg';
|
|
141
|
-
//
|
|
141
|
+
// 收件人:私聊跨话题自派时是本端,否则是话题对端。用 route.peer.id 会把跨话题自派消息
|
|
142
142
|
// 实际投给话题对端(下游按位置参数认目标,--thread 只决定落点会话)。
|
|
143
|
-
// 群发送恒以群 AID
|
|
143
|
+
// 群发送恒以群 AID 为目标,跨话题自派不适用于群。
|
|
144
144
|
const targetId = scope === 'group' ? route.peer.id : route.recipientId;
|
|
145
145
|
// 目标为原生 ID 时必须靠 --thread 推导,写成位置参数会变成正文的一部分。
|
|
146
146
|
const targetAsPositional = looksLikeAid(targetId)
|
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `ec events` CLI:事件中心运维(status / ledger / tail / doctor / reload /
|
|
3
|
-
* daemon-control
|
|
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 解析执行。
|
|
4
6
|
*/
|
|
5
7
|
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
6
9
|
import { ipcQuery } from '../ipc.js';
|
|
10
|
+
import { readDelegationCredential, hashCurrentDelegatedCommand } from '../core/auth/agent-delegation.js';
|
|
7
11
|
import { resolvePaths } from '../paths.js';
|
|
8
12
|
const HELP = `ec events — 事件中心运维
|
|
9
13
|
|
|
10
14
|
用法:
|
|
11
15
|
ec events status [<包名>] [--aid <aid>] 每包状态
|
|
12
|
-
ec events ledger <包名> [--tail N]
|
|
16
|
+
ec events ledger [<包名>] [--tail N] 台账(不传包名=中心台账)
|
|
13
17
|
ec events tail <包名> [--tail N] 事件日志
|
|
14
18
|
ec events doctor <包名> 诊断
|
|
15
19
|
ec events reload [<包名>] 重载(重新扫描目录并重建订阅)
|
|
16
|
-
ec events
|
|
17
|
-
ec events
|
|
18
|
-
ec events
|
|
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 <事件>]
|
|
19
23
|
ec events publish <包名> <事件> --data '<json>' [--ttl <秒>]
|
|
20
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
|
+
|
|
21
33
|
事件是 TTL 内的在线通知:不落库、不重放。详见 $KITS_DOCS/evolcore/event-center.md`;
|
|
22
34
|
function readControlToken() {
|
|
23
35
|
try {
|
|
@@ -28,9 +40,20 @@ function readControlToken() {
|
|
|
28
40
|
}
|
|
29
41
|
}
|
|
30
42
|
async function queryEvents(argv) {
|
|
31
|
-
|
|
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();
|
|
32
52
|
try {
|
|
33
|
-
const response = await ipcQuery(resolvePaths().socket, {
|
|
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 });
|
|
34
57
|
if (!response || typeof response !== 'object')
|
|
35
58
|
return { transportError: 'invalid daemon response' };
|
|
36
59
|
return { response };
|
|
@@ -50,8 +73,21 @@ function printResult(result, json) {
|
|
|
50
73
|
}
|
|
51
74
|
console.log(String(result));
|
|
52
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
|
+
}
|
|
53
89
|
export async function runEventsCommand(argv) {
|
|
54
|
-
const args = [...argv];
|
|
90
|
+
const args = resolveFromPath([...argv]);
|
|
55
91
|
const json = args.includes('--json');
|
|
56
92
|
if (args.length === 0 || args[0] === 'help' || args[0] === '--help') {
|
|
57
93
|
console.log(HELP);
|
package/dist/cli/index.js
CHANGED
|
@@ -94,6 +94,27 @@ AUN:
|
|
|
94
94
|
MESSAGE_LOG 消息日志(默认: true)
|
|
95
95
|
EVENT_LOG 事件日志(默认: true)
|
|
96
96
|
CHANNEL_LOGS 渠道边界审计日志(默认: false;也可用 daemon.json.debug.channelLogs)`;
|
|
97
|
+
/**
|
|
98
|
+
* 顶层命令全集,必须与下方 switch 的 case(以及版本别名分支)同步。
|
|
99
|
+
*
|
|
100
|
+
* 用于在托管任务里区分「命令不存在」和「命令存在但被策略拒绝」:
|
|
101
|
+
* 白名单守卫只认识自己那份 allowlist,未知命令会先被它拦下并报成
|
|
102
|
+
* NOT_ALLOWED,看起来像权限问题,实际只是打错了命令名。
|
|
103
|
+
*/
|
|
104
|
+
export const KNOWN_TOP_LEVEL_COMMANDS = new Set([
|
|
105
|
+
'init', 'start', 'stop', 'restart', 'restart-monitor',
|
|
106
|
+
'upgrade', 'update', 'status', 'logs', 'watch',
|
|
107
|
+
'mode', 'mv', 'diagnose', 'data', 'net', 'integrity',
|
|
108
|
+
'ctl', 'memory', 'queue', 'task', 'trigger', 'proxy', 'team',
|
|
109
|
+
'agent', 'aid', 'rpc', 'diag', 'menu-client',
|
|
110
|
+
'storage', 'fs', 'msg', 'thread', 'events', 'services',
|
|
111
|
+
'session', 'getmeta', 'group', 'model', 'skill', 'response',
|
|
112
|
+
'config', 'peer', 'directory', 'role', 'stats',
|
|
113
|
+
'provider', 'invoke', 'ability',
|
|
114
|
+
// 版本三个别名在 switch 之前统一处理(含只在早期分支出现的 -V)。
|
|
115
|
+
'version', '-v', '-V', '--version',
|
|
116
|
+
'bench', 'link-rules',
|
|
117
|
+
]);
|
|
97
118
|
function printLifecycleHelp(command) {
|
|
98
119
|
const help = {
|
|
99
120
|
start: `用法: ec start [--foreground] [--diagnose|-d] [--debug] [--as-mode dev|install]\n\n --foreground 前台运行,适合 systemd 或容器直接管理\n --diagnose, -d 以诊断模式启动 daemon\n --debug 调试模式:注册调试 IPC,可在宿主终端以任意 session 身份发命令\n --as-mode 覆盖运行模式判定(仅本次启动生效,不写配置):\n install = 按安装模式(校验随包文件完整性,篡改自动恢复)\n dev = 按开发模式(不校验随包文件)`,
|
|
@@ -170,6 +191,14 @@ export async function main(args) {
|
|
|
170
191
|
await resolveDebugContext(args);
|
|
171
192
|
// 注入完成后剥除 --as-session <sessionId> 两个参数,避免子命令把它们当作未知参数
|
|
172
193
|
const strippedArgs = stripAsSessionArgs(args);
|
|
194
|
+
// 未知命令先于托管策略判定:白名单守卫不掌握命令全集,先跑会把
|
|
195
|
+
// `ec self` 这类不存在的命令报成 NOT_ALLOWED,误导成权限问题。
|
|
196
|
+
if (!isHelpFlag(cmd) && !KNOWN_TOP_LEVEL_COMMANDS.has(cmd)) {
|
|
197
|
+
console.error(`未知命令: ${cmd}`);
|
|
198
|
+
console.log(MAIN_HELP);
|
|
199
|
+
process.exitCode = 1;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
173
202
|
try {
|
|
174
203
|
await assertManagedTopLevelCommandAllowed(cmd, strippedArgs);
|
|
175
204
|
}
|
package/dist/cli/net-check.js
CHANGED
|
@@ -39,7 +39,7 @@ const i18n = {
|
|
|
39
39
|
sessionReady: isZh ? '会话就绪' : 'session ready',
|
|
40
40
|
pingOk: isZh ? '响应正常' : 'response ok',
|
|
41
41
|
pingFailed: isZh ? '失败' : 'failed',
|
|
42
|
-
msgOk: isZh ? '
|
|
42
|
+
msgOk: isZh ? '自派自收成功' : 'self-send ok',
|
|
43
43
|
msgFailed: isZh ? '消息发送失败' : 'message send failed',
|
|
44
44
|
noGateway: isZh ? '响应中无网关地址' : 'no gateway in response',
|
|
45
45
|
fetchGwFailed: isZh ? '获取网关失败' : 'fetch gateway failed',
|