evolcore 0.0.43-test.7 → 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 +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
|
@@ -39,6 +39,17 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
39
39
|
if (!taskSession || taskSession.selfAID !== delegation.grant.selfAid) {
|
|
40
40
|
return fail('INVALID_DELEGATION', 'delegation does not match the current session');
|
|
41
41
|
}
|
|
42
|
+
let templateOperation;
|
|
43
|
+
if (sub === 'template') {
|
|
44
|
+
try {
|
|
45
|
+
const { parseTemplateCommand } = await import('../cli/agent-template.js');
|
|
46
|
+
const parsed = parseTemplateCommand(argv.slice(2));
|
|
47
|
+
templateOperation = 'agent.template.' + (parsed.action === 'status' ? 'query' : parsed.action);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return fail(error.code ?? 'INVALID_ARGUMENT', error.message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
42
53
|
if (shorthand)
|
|
43
54
|
argv = ['agent', 'show', ...argv.slice(1)];
|
|
44
55
|
const taskAid = delegation.grant.selfAid;
|
|
@@ -53,7 +64,7 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
53
64
|
if (delegation.grant.chatType !== 'private')
|
|
54
65
|
return fail('NOT_ALLOWED', 'welcome requires a private conversation');
|
|
55
66
|
}
|
|
56
|
-
const targetAid = sub === 'list'
|
|
67
|
+
const targetAid = sub === 'list' || sub === 'template'
|
|
57
68
|
? undefined
|
|
58
69
|
: sub === 'welcome'
|
|
59
70
|
? taskAid
|
|
@@ -71,7 +82,7 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
71
82
|
return fail('INVALID_ARGS', error.message);
|
|
72
83
|
}
|
|
73
84
|
}
|
|
74
|
-
const operation = sub === 'list' ? 'agent.list'
|
|
85
|
+
const operation = templateOperation ?? (sub === 'list' ? 'agent.list'
|
|
75
86
|
: sub === 'show' ? 'agent.show'
|
|
76
87
|
: sub === 'welcome' ? 'agent.welcome'
|
|
77
88
|
: sub === 'rename' ? 'agent.rename'
|
|
@@ -80,7 +91,7 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
80
91
|
: sub === 'enable' ? 'agent.enable'
|
|
81
92
|
: sub === 'disable' ? 'agent.disable'
|
|
82
93
|
: sub === 'reload' ? 'agent.reload'
|
|
83
|
-
: sub === 'delete' ? 'agent.delete' : undefined;
|
|
94
|
+
: sub === 'delete' ? 'agent.delete' : undefined);
|
|
84
95
|
if (!operation)
|
|
85
96
|
return fail('INVALID_ARGS', `unsupported managed agent command: ${sub}`);
|
|
86
97
|
if (sub === 'delete' && argv.includes('--purge') && !argv.includes('--confirm-purge')) {
|
|
@@ -109,7 +120,7 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
109
120
|
subject,
|
|
110
121
|
intent: {
|
|
111
122
|
operation,
|
|
112
|
-
scope: operation === 'agent.show' || operation === 'agent.welcome' || operation === 'agent.rename'
|
|
123
|
+
scope: templateOperation ? 'process' : operation === 'agent.show' || operation === 'agent.welcome' || operation === 'agent.rename'
|
|
113
124
|
? 'agent'
|
|
114
125
|
: operation === 'agent.reload' && targetAid
|
|
115
126
|
? 'agent'
|
|
@@ -129,6 +140,16 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
129
140
|
const reasonCode = decision.command?.reasonCode;
|
|
130
141
|
return fail(decision.code, decision.reason, reasonCode);
|
|
131
142
|
}
|
|
143
|
+
if (templateOperation) {
|
|
144
|
+
try {
|
|
145
|
+
const { executeTemplateCommand } = await import('../cli/agent-template.js');
|
|
146
|
+
const result = await executeTemplateCommand(delegation.grant.actorId, argv.slice(2));
|
|
147
|
+
return result.ok ? { ok: true, result } : result;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return fail(error.code ?? 'INVALID_ARGUMENT', error.message);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
132
153
|
const { execAgentAction, execAgentOptions, execAgentQuery } = await import('./command/agent-control.js');
|
|
133
154
|
if (operation === 'agent.list') {
|
|
134
155
|
const result = await execAgentOptions({ options: 'all' }, agentApplicationService);
|
|
@@ -684,6 +684,8 @@ const AUDITED_WORKFLOW_SHA256 = {
|
|
|
684
684
|
'0.5.32': '7333bede3bb0a5dc5cd7e500dc2c91d23c5c772590659540c640d5f6eabc2f1d',
|
|
685
685
|
// 0.5.33 adds batch_id propagation; audited start/read/write/notify ordering is unchanged.
|
|
686
686
|
'0.5.33': '55b6d41331b4dfc6b377be9f4ff28d322af5e06fc4539c5d0120cb15419623f6',
|
|
687
|
+
// 0.5.34 retains this exact workflow; real SDK read/execute boundaries were revalidated.
|
|
688
|
+
'0.5.34': '55b6d41331b4dfc6b377be9f4ff28d322af5e06fc4539c5d0120cb15419623f6',
|
|
687
689
|
};
|
|
688
690
|
export function initializationBindPreflightFailure(error) {
|
|
689
691
|
if (!(error instanceof Error) || error.code !== 'ECONNRESET')
|
|
@@ -8,6 +8,8 @@ import { formatPeerKey, parsePeerKey } from '../relation/peer-identity.js';
|
|
|
8
8
|
import { sameGroupAid } from '../../aun/group/index.js';
|
|
9
9
|
import { ownerResolver } from '../ownership/owner-resolver.js';
|
|
10
10
|
const DAEMON_OWNER_PROCESS_OPERATIONS = new Set([
|
|
11
|
+
...['inspect', 'build', 'push', 'pull', 'deploy', 'query'].map(action => 'agent.template.' + action),
|
|
12
|
+
'model.provider.catalog',
|
|
11
13
|
'agent.list',
|
|
12
14
|
'agent.create',
|
|
13
15
|
'agent.initialize',
|
|
@@ -159,13 +159,15 @@ const OPERATIONS = [
|
|
|
159
159
|
...[
|
|
160
160
|
['event.center.current', 'Read event center status'],
|
|
161
161
|
['event.center.update', 'Update event center status'],
|
|
162
|
-
['event.
|
|
163
|
-
['event.
|
|
162
|
+
['event.rules.current', 'Read event rules (allow/deny)'],
|
|
163
|
+
['event.rules.update', 'Update event rules (allow/deny)'],
|
|
164
164
|
['event.packs.list', 'List event packs'],
|
|
165
165
|
['event.register.list', 'List registered events'],
|
|
166
166
|
['event.register.update', 'Update registered events'],
|
|
167
167
|
['event.subscribers.list', 'List event subscribers'],
|
|
168
168
|
['event.stats.current', 'Read event publication statistics'],
|
|
169
|
+
['event.publishStats.current', 'Read per-pack event publication statistics'],
|
|
170
|
+
['event.records.list', 'Read event delivery records'],
|
|
169
171
|
].map(([id, description]) => ({
|
|
170
172
|
id,
|
|
171
173
|
category: id.endsWith('.current') || id.endsWith('.list') ? 'read' : 'write-agent',
|
|
@@ -227,6 +229,13 @@ const OPERATIONS = [
|
|
|
227
229
|
sources: ['agent-tool'],
|
|
228
230
|
},
|
|
229
231
|
// ── Model Operations ──
|
|
232
|
+
...['inspect', 'build', 'push', 'pull', 'deploy', 'query'].map(action => ({
|
|
233
|
+
id: 'agent.template.' + action, category: 'process',
|
|
234
|
+
dangerous: !['inspect', 'query'].includes(action), defaultScopes: ['process'],
|
|
235
|
+
description: 'Agent template ' + action, sources: ['menu', 'control', 'agent-tool', 'ecweb'],
|
|
236
|
+
})),
|
|
237
|
+
{ id: 'model.provider.catalog', category: 'process', dangerous: false, defaultScopes: ['process'],
|
|
238
|
+
description: 'Read a Provider model catalog without changing Agent configuration', sources: ['menu', 'control', 'ecweb'] },
|
|
230
239
|
{
|
|
231
240
|
id: 'baseagent.models.list',
|
|
232
241
|
category: 'read',
|
|
@@ -66,8 +66,10 @@ export function createChannelConnectionRuntime(dependencies) {
|
|
|
66
66
|
const followups = new StartupTaskQueue();
|
|
67
67
|
const connections = new Map();
|
|
68
68
|
const subscriptions = new Map();
|
|
69
|
-
const queuePendingObserverHints = async (aid, channelKey) => {
|
|
70
|
-
const pending = await
|
|
69
|
+
const queuePendingObserverHints = async (aid, channelKey, snapshot) => {
|
|
70
|
+
const pending = await (snapshot
|
|
71
|
+
? pendingInterruptHints(dependencies.sessionsDir, aid, channelKey, snapshot)
|
|
72
|
+
: pendingInterruptHints(dependencies.sessionsDir, aid, channelKey));
|
|
71
73
|
if (dependencies.isCancelled?.())
|
|
72
74
|
return;
|
|
73
75
|
const results = await Promise.allSettled(pending.map(pending => dependencies.responseEngine.scheduleObserverHint({ ...pending, selfAid: aid })
|
|
@@ -351,17 +353,22 @@ export function createChannelStartupNotifications({ channelInstances, agentRegis
|
|
|
351
353
|
...(restartDelivery.delivery ? { delivery: restartDelivery.delivery } : {}),
|
|
352
354
|
replyContext: Object.keys(replyContext).length > 0 ? replyContext : undefined,
|
|
353
355
|
});
|
|
354
|
-
const restartNotice = pending.outcome === '
|
|
356
|
+
const restartNotice = pending.outcome === 'rollback-failed'
|
|
355
357
|
? {
|
|
356
|
-
text:
|
|
357
|
-
subtype: 'restarted-
|
|
358
|
+
text: `❌ 升级失败且整包回滚未成功,服务未确认恢复。${pending.outcomeReason ? `原因:${pending.outcomeReason}。` : ''}请检查安装目录和备份。`,
|
|
359
|
+
subtype: 'restarted-rollback-failed',
|
|
358
360
|
}
|
|
359
|
-
: pending.outcome === '
|
|
361
|
+
: pending.outcome === 'rolled-back'
|
|
360
362
|
? {
|
|
361
|
-
text:
|
|
362
|
-
subtype: 'restarted-
|
|
363
|
+
text: `⚠️ 服务已重启,但运行的是上一个版本。${pending.outcomeReason ? `原因:${pending.outcomeReason}。` : ''}本次改动未生效,请检查后重试。`,
|
|
364
|
+
subtype: 'restarted-rolled-back',
|
|
363
365
|
}
|
|
364
|
-
:
|
|
366
|
+
: pending.outcome === 'upgraded'
|
|
367
|
+
? {
|
|
368
|
+
text: `✅ 服务重启成功!${pending.outcomeReason ? `${pending.outcomeReason}` : ''}`,
|
|
369
|
+
subtype: 'restarted-upgraded',
|
|
370
|
+
}
|
|
371
|
+
: { text: '✅ 服务重启成功!', subtype: 'restarted' };
|
|
365
372
|
await sendSystemPayload(adapter, envelope, {
|
|
366
373
|
kind: 'system.notice',
|
|
367
374
|
text: restartNotice.text,
|
|
@@ -1160,7 +1160,7 @@ export function resolveProjectPath(explicit, aid, defaults) {
|
|
|
1160
1160
|
return deriveAgentProjectPath(root, aid);
|
|
1161
1161
|
}
|
|
1162
1162
|
/** name=agent 的 menu.query:查单个 agent 详情,附构建进度(D3)。 */
|
|
1163
|
-
export async function execAgentQuery(args, service, subject) {
|
|
1163
|
+
export async function execAgentQuery(args, service, subject, runtime) {
|
|
1164
1164
|
const aid = args?.aid;
|
|
1165
1165
|
if (!aid)
|
|
1166
1166
|
return { error: '缺少 aid', code: 'INVALID_ARGS' };
|
|
@@ -1224,8 +1224,18 @@ export async function execAgentQuery(args, service, subject) {
|
|
|
1224
1224
|
const safeAgentConfig = safeConfig ?? {};
|
|
1225
1225
|
const ownership = ownerResolver.snapshot(aid);
|
|
1226
1226
|
const fullaccessStatus = agentFullAccessStatus(aid, subject?.principalId ?? subject?.actorId);
|
|
1227
|
+
// This cross-relation counter is only available to the verified Agent Owner
|
|
1228
|
+
// over a private AUN transport. It never includes counterpart identities.
|
|
1229
|
+
const canReadActivePeers = subject?.selfAid === aid && subject.role === 'owner'
|
|
1230
|
+
&& subject.channelType === 'aun' && subject.chatType === 'private'
|
|
1231
|
+
&& subject.menuTransportChatType !== 'group' && !subject.fromControlChannel
|
|
1232
|
+
&& !!subject.principalId && ownerResolver.isOwner(aid, subject.principalId);
|
|
1233
|
+
const activePeers = canReadActivePeers ? runtime?.getActivePrivatePeerCountBySelfAID?.(aid) : undefined;
|
|
1227
1234
|
const data = {
|
|
1228
1235
|
...res,
|
|
1236
|
+
...(typeof activePeers === 'number' && Number.isSafeInteger(activePeers) && activePeers >= 0 ? {
|
|
1237
|
+
sessions: { ...res.sessions, active_peers: activePeers },
|
|
1238
|
+
} : {}),
|
|
1229
1239
|
...(initialization ? { initialization } : {}),
|
|
1230
1240
|
...(usable === undefined ? {} : { usable }),
|
|
1231
1241
|
config: {
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { isValidAid } from '../../aun/aid/validation.js';
|
|
2
|
+
import { getAgentTemplateService } from '../../agent-template/service.js';
|
|
3
|
+
import { TEMPLATE_ACTIONS, templateError } from '../../agent-template/types.js';
|
|
4
|
+
import { authorizeFreshOperation } from '../auth/auth-gateway.js';
|
|
5
|
+
import { getProviderCatalog } from '../model/model-catalog.js';
|
|
6
|
+
export function isTemplateRequest(request) {
|
|
7
|
+
return (request.name === 'agent' || request.cmd === '/agent')
|
|
8
|
+
&& (TEMPLATE_ACTIONS.includes(request.action) || request.args?.view === 'template-job');
|
|
9
|
+
}
|
|
10
|
+
export function isProviderModelCatalog(request) {
|
|
11
|
+
return (request.name === 'model' || request.cmd === '/model') && request.args?.view === 'catalog' && request.args?.scope === 'process';
|
|
12
|
+
}
|
|
13
|
+
export function validateTemplateRequest(request) {
|
|
14
|
+
try {
|
|
15
|
+
const record = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
16
|
+
const memberKey = (key) => /^[a-z0-9][a-z0-9_-]{0,31}$/.test(key);
|
|
17
|
+
const validateSelections = (value) => {
|
|
18
|
+
if (value.providers !== undefined && !record(value.providers)
|
|
19
|
+
|| value.externalAids !== undefined && (!record(value.externalAids)
|
|
20
|
+
|| Object.entries(value.externalAids).some(([from, to]) => !isValidAid(from) || typeof to !== 'string' || !isValidAid(to)))) {
|
|
21
|
+
throw new Error('Invalid member Provider or external AID selections');
|
|
22
|
+
}
|
|
23
|
+
for (const [name, selection] of Object.entries(value.providers ?? {})) {
|
|
24
|
+
if (!['claude', 'codex', 'ecagent', 'gemini'].includes(name) || !record(selection)
|
|
25
|
+
|| Object.keys(selection).some(k => !['provider', 'model', 'effort'].includes(k))
|
|
26
|
+
|| !/^provider-\d{8}$/.test(selection.provider) || selection.model !== undefined && (typeof selection.model !== 'string' || !selection.model.trim())
|
|
27
|
+
|| selection.effort !== undefined && selection.effort !== null && !['low', 'medium', 'high', 'xhigh', 'max'].includes(selection.effort)) {
|
|
28
|
+
throw new Error('Invalid Provider/model/effort selection');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const args = request.args;
|
|
33
|
+
if (!args || typeof args !== 'object' || Array.isArray(args))
|
|
34
|
+
throw new Error('args object required');
|
|
35
|
+
let allowed;
|
|
36
|
+
if (args.view === 'template-job') {
|
|
37
|
+
if (request.type !== 'menu.query' || !!args.jobId === !!args.requestId)
|
|
38
|
+
throw new Error('Use query with jobId or requestId');
|
|
39
|
+
if (args.jobId !== undefined && !/^job_[a-f0-9-]{36}$/.test(args.jobId)
|
|
40
|
+
|| args.requestId !== undefined && (typeof args.requestId !== 'string' || !args.requestId.trim() || args.requestId.length > 200))
|
|
41
|
+
throw new Error('Invalid task identifier');
|
|
42
|
+
allowed = ['view', 'jobId', 'requestId'];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (request.type !== 'menu.action')
|
|
46
|
+
throw new Error('Template actions use menu.action');
|
|
47
|
+
const fields = { inspect: ['aid'], build: ['aid', 'template', 'include'],
|
|
48
|
+
push: ['buildId', 'ownerAid', 'targetPath', 'releasedFindings'], pull: ['location', 'download', 'digest', 'targetAid', 'targets'],
|
|
49
|
+
deploy: ['pullId', 'providers', 'externalAids', 'members'] };
|
|
50
|
+
allowed = fields[request.action];
|
|
51
|
+
if (!allowed)
|
|
52
|
+
throw new Error('Unsupported template action');
|
|
53
|
+
if (['inspect', 'build'].includes(request.action) && !isValidAid(args.aid))
|
|
54
|
+
throw new Error('aid required');
|
|
55
|
+
if (request.action === 'build' && (!args.template?.version || !args.template?.name || !args.include))
|
|
56
|
+
throw new Error('template.version/name and include required');
|
|
57
|
+
if (request.action === 'pull' && (!isValidAid(args.location?.aid)
|
|
58
|
+
|| typeof args.location?.path !== 'string' || !args.location.path.startsWith('/templates/')
|
|
59
|
+
|| !/^[A-Za-z0-9]{10}$/.test(args.download?.shareId) || !/^sha256:[a-f0-9]{64}$/.test(args.digest)))
|
|
60
|
+
throw new Error('Invalid package location, shareId, digest or targetAid');
|
|
61
|
+
if (request.action === 'pull') {
|
|
62
|
+
if (args.targets === undefined) {
|
|
63
|
+
if (!isValidAid(args.targetAid))
|
|
64
|
+
throw new Error('targetAid or targets mapping required');
|
|
65
|
+
}
|
|
66
|
+
else if (args.targetAid !== undefined || !record(args.targets) || !Object.keys(args.targets).length
|
|
67
|
+
|| Object.entries(args.targets).some(([key, aid]) => !memberKey(key) || typeof aid !== 'string' || !isValidAid(aid))
|
|
68
|
+
|| new Set(Object.values(args.targets)).size !== Object.keys(args.targets).length) {
|
|
69
|
+
throw new Error('Map members to distinct existing Agent AIDs; do not mix targetAid and targets');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (request.action === 'push' && (!/^build_[a-f0-9-]{36}$/.test(args.buildId) || !isValidAid(args.ownerAid)
|
|
73
|
+
|| typeof args.targetPath !== 'string' || !args.targetPath.startsWith('/templates/')
|
|
74
|
+
|| args.releasedFindings !== undefined && (!Array.isArray(args.releasedFindings) || !args.releasedFindings.every((f) => typeof f === 'string'))))
|
|
75
|
+
throw new Error('Invalid push arguments');
|
|
76
|
+
if (request.action === 'deploy' && (!/^pull_[a-f0-9-]{36}$/.test(args.pullId)
|
|
77
|
+
|| args.providers !== undefined && (!args.providers || typeof args.providers !== 'object' || Array.isArray(args.providers))
|
|
78
|
+
|| args.externalAids !== undefined && (!args.externalAids || typeof args.externalAids !== 'object' || Array.isArray(args.externalAids)
|
|
79
|
+
|| Object.entries(args.externalAids).some(([from, to]) => !isValidAid(from) || typeof to !== 'string' || !isValidAid(to)))))
|
|
80
|
+
throw new Error('Invalid deploy arguments');
|
|
81
|
+
if (request.action === 'deploy') {
|
|
82
|
+
validateSelections(args);
|
|
83
|
+
if (args.members !== undefined) {
|
|
84
|
+
if (!record(args.members) || args.providers !== undefined || args.externalAids !== undefined)
|
|
85
|
+
throw new Error('Use members or single-Agent selections');
|
|
86
|
+
for (const [key, selection] of Object.entries(args.members)) {
|
|
87
|
+
if (!memberKey(key) || !record(selection) || Object.keys(selection).some(k => !['providers', 'externalAids'].includes(k))) {
|
|
88
|
+
throw new Error('Invalid member selection');
|
|
89
|
+
}
|
|
90
|
+
validateSelections(selection);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (Object.keys(args).some(k => !allowed.includes(k)))
|
|
96
|
+
throw new Error('Unknown template argument');
|
|
97
|
+
if (request.agent !== undefined)
|
|
98
|
+
throw new Error('Use action target fields, not top-level agent');
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return { code: 'INVALID_ARGUMENT', message: error.message };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export async function executeTemplateMenu(request, subject, source) {
|
|
106
|
+
try {
|
|
107
|
+
const invalid = validateTemplateRequest(request);
|
|
108
|
+
if (invalid)
|
|
109
|
+
throw templateError(invalid.code, invalid.message);
|
|
110
|
+
if (!subject?.fromControlChannel || !subject.isDaemonOwner || !subject.principalId
|
|
111
|
+
|| subject.processRole === 'daemon-service' || !subject.ecwebManagement && subject.menuEncrypted !== true) {
|
|
112
|
+
throw templateError('NOT_ALLOWED', 'Template operations require an encrypted DaemonOwner Control request', { reason: 'DAEMON_OWNER_REQUIRED' });
|
|
113
|
+
}
|
|
114
|
+
const operation = request.type === 'menu.query' ? 'agent.template.query' : 'agent.template.' + request.action;
|
|
115
|
+
const decision = await authorizeFreshOperation({ source, subject,
|
|
116
|
+
intent: { operation, scope: 'process', source, args: request.args } });
|
|
117
|
+
if (!decision.allow)
|
|
118
|
+
throw templateError('NOT_ALLOWED', 'Template operation denied');
|
|
119
|
+
const service = getAgentTemplateService();
|
|
120
|
+
return { data: request.type === 'menu.query' ? await service.query(subject.principalId, request.args)
|
|
121
|
+
: await service.action(subject.principalId, request.id, request.action, request.args) };
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return { error: error.message, code: error.code ?? 'TEMPLATE_FAILED', ...(error.data ? { data: error.data } : {}) };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export async function executeProviderModelCatalog(request, subject, source) {
|
|
128
|
+
try {
|
|
129
|
+
const args = request.args;
|
|
130
|
+
if (request.type !== 'menu.query' || request.agent !== undefined || !args
|
|
131
|
+
|| Object.keys(args).some(k => !['scope', 'view', 'providerId', 'baseagent', 'serviceType', 'refresh'].includes(k))
|
|
132
|
+
|| !/^provider-\d{8}$/.test(args.providerId) || !['claude', 'codex', 'ecagent', 'gemini'].includes(args.baseagent)
|
|
133
|
+
|| args.refresh !== undefined && typeof args.refresh !== 'boolean'
|
|
134
|
+
|| args.serviceType !== undefined && typeof args.serviceType !== 'string')
|
|
135
|
+
throw templateError('INVALID_ARGUMENT', 'Invalid process model catalog query');
|
|
136
|
+
if (!subject?.fromControlChannel || !subject.isDaemonOwner)
|
|
137
|
+
throw templateError('NOT_ALLOWED', 'DaemonOwner Control context required');
|
|
138
|
+
const decision = await authorizeFreshOperation({ source, subject,
|
|
139
|
+
intent: { operation: 'model.provider.catalog', scope: 'process', source, args } });
|
|
140
|
+
if (!decision.allow)
|
|
141
|
+
throw templateError('NOT_ALLOWED', 'Model catalog query denied');
|
|
142
|
+
return { data: await getProviderCatalog(args.providerId, args.serviceType, args.refresh === true, false, args.baseagent) };
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return { error: error.message, code: error.code ?? 'MODEL_UNAVAILABLE' };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -3569,6 +3569,25 @@ export class CommandHandler {
|
|
|
3569
3569
|
return { ok: false, error: `❌ --before 不是有效时间(支持 ${TIME_ARG_FORMATS})` };
|
|
3570
3570
|
if (after !== undefined && before !== undefined && after >= before)
|
|
3571
3571
|
return { ok: false, error: '❌ --after 必须早于 --before' };
|
|
3572
|
+
// 跨会话查看:跨话题自派落点是别的话题会话,队列不在当前会话里,没有这个
|
|
3573
|
+
// 选择器就只能靠 daemon 日志反推。只读,不允许借它改动别的会话。
|
|
3574
|
+
const requestedSessionId = this.extractArg(args, '--session');
|
|
3575
|
+
if (requestedSessionId && (args.includes('--clear') || args.includes('--cancel') || args.includes('--interrupt'))) {
|
|
3576
|
+
return { ok: false, error: '❌ --session 只用于查看,不能跨会话清空/取消/打断' };
|
|
3577
|
+
}
|
|
3578
|
+
let targetSessionId = sessionId;
|
|
3579
|
+
if (requestedSessionId && requestedSessionId !== sessionId) {
|
|
3580
|
+
const [current, target] = await Promise.all([
|
|
3581
|
+
this.sessionManager.getSessionById(sessionId),
|
|
3582
|
+
this.sessionManager.getSessionById(requestedSessionId),
|
|
3583
|
+
]);
|
|
3584
|
+
if (!target)
|
|
3585
|
+
return { ok: false, error: `❌ 找不到会话 ${requestedSessionId}` };
|
|
3586
|
+
if (!current || target.selfAID !== current.selfAID) {
|
|
3587
|
+
return { ok: false, error: '❌ --session 只能查看本 Agent 的会话' };
|
|
3588
|
+
}
|
|
3589
|
+
targetSessionId = requestedSessionId;
|
|
3590
|
+
}
|
|
3572
3591
|
// 操作分支
|
|
3573
3592
|
if (args.includes('--clear')) {
|
|
3574
3593
|
const count = this.messageQueue.clearBySession(sessionId);
|
|
@@ -3590,11 +3609,12 @@ export class CommandHandler {
|
|
|
3590
3609
|
: { ok: false, error: `❌ 当前无处理中任务` };
|
|
3591
3610
|
}
|
|
3592
3611
|
// 查询
|
|
3593
|
-
const items = this.messageQueue.getQueueItemsBySession(
|
|
3612
|
+
const items = this.messageQueue.getQueueItemsBySession(targetSessionId, { after, before });
|
|
3613
|
+
const title = targetSessionId === sessionId ? undefined : `会话 ${targetSessionId} 队列`;
|
|
3594
3614
|
if (formatJson) {
|
|
3595
|
-
return { ok: true, result: JSON.stringify({ items }, null, 2) };
|
|
3615
|
+
return { ok: true, result: JSON.stringify({ sessionId: targetSessionId, items }, null, 2) };
|
|
3596
3616
|
}
|
|
3597
|
-
return { ok: true, result: renderQueueItemsCtl(items, showId, full) };
|
|
3617
|
+
return { ok: true, result: renderQueueItemsCtl(items, showId, full, title) };
|
|
3598
3618
|
}
|
|
3599
3619
|
}
|
|
3600
3620
|
function parseQueueTimeArg(value) {
|
|
@@ -3603,11 +3623,12 @@ function parseQueueTimeArg(value) {
|
|
|
3603
3623
|
/**
|
|
3604
3624
|
* ctl 专用渲染:不显示 session 标识列(因为只有一个 session)
|
|
3605
3625
|
*/
|
|
3606
|
-
function renderQueueItemsCtl(items, showId, full) {
|
|
3626
|
+
function renderQueueItemsCtl(items, showId, full, title) {
|
|
3627
|
+
const heading = title ?? '当前会话队列';
|
|
3607
3628
|
if (items.length === 0) {
|
|
3608
|
-
return
|
|
3629
|
+
return `${heading} (0 条待处理)\n\n(无待处理消息)`;
|
|
3609
3630
|
}
|
|
3610
|
-
const lines = [
|
|
3631
|
+
const lines = [`${heading} (${items.length} 条待处理)`, ''];
|
|
3611
3632
|
// 计算列宽
|
|
3612
3633
|
const maxIdLen = showId ? Math.max(...items.map(i => i.messageId?.length ?? 0)) : 0;
|
|
3613
3634
|
const maxNameLen = Math.max(...items.map(i => (i.peerName ? `[${i.peerName}]`.length : 0)));
|