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
|
@@ -5,7 +5,7 @@ import { LogicalQueueBridge } from './logical-queue-bridge.js';
|
|
|
5
5
|
import { normalizeCausation } from '../causation/context.js';
|
|
6
6
|
import { KeyedFairMutex } from '../handoff/mutex.js';
|
|
7
7
|
import { ExecutionTimeoutError, OrphanedTargetSessionError, isExecutionFailure } from '../../utils/error-utils.js';
|
|
8
|
-
import { isTopicThreadId } from '../thread/topic-id.js';
|
|
8
|
+
import { isTopicThreadId, normalizeTopicAid, safeFormatMainTopicId } from '../thread/topic-id.js';
|
|
9
9
|
const DEFAULT_AGENT_NAME = '<unknown>';
|
|
10
10
|
const RESTART_RESUME_CONTENT = 'evolcore 服务已重启,请继续之前未完成的任务。';
|
|
11
11
|
export class MessageQueue {
|
|
@@ -421,6 +421,7 @@ export class MessageQueue {
|
|
|
421
421
|
projectPath: item.projectPath,
|
|
422
422
|
agentName: item.agentName,
|
|
423
423
|
role: item.role,
|
|
424
|
+
priority: item.priority,
|
|
424
425
|
resolve: item.resolve,
|
|
425
426
|
reject: item.reject,
|
|
426
427
|
enqueuedAt: item.enqueuedAt ?? item.message.enqueuedAt,
|
|
@@ -432,6 +433,7 @@ export class MessageQueue {
|
|
|
432
433
|
projectPath: part.projectPath,
|
|
433
434
|
agentName: part.agentName,
|
|
434
435
|
role: part.role,
|
|
436
|
+
priority: part.priority,
|
|
435
437
|
resolve: part.resolve,
|
|
436
438
|
reject: part.reject,
|
|
437
439
|
enqueuedAt: part.enqueuedAt ?? part.message.enqueuedAt,
|
|
@@ -484,6 +486,7 @@ export class MessageQueue {
|
|
|
484
486
|
projectPath: part.projectPath,
|
|
485
487
|
agentName: part.agentName,
|
|
486
488
|
role: part.role,
|
|
489
|
+
priority: part.priority,
|
|
487
490
|
enqueuedAt,
|
|
488
491
|
};
|
|
489
492
|
}
|
|
@@ -495,6 +498,7 @@ export class MessageQueue {
|
|
|
495
498
|
projectPath: item.projectPath,
|
|
496
499
|
agentName: item.agentName,
|
|
497
500
|
role: item.role,
|
|
501
|
+
priority: item.priority,
|
|
498
502
|
enqueuedAt,
|
|
499
503
|
parts: item.parts?.map(part => this.serializePart(part, enqueuedAt)),
|
|
500
504
|
};
|
|
@@ -509,6 +513,7 @@ export class MessageQueue {
|
|
|
509
513
|
projectPath: item.projectPath,
|
|
510
514
|
agentName: item.agentName || DEFAULT_AGENT_NAME,
|
|
511
515
|
role: item.role,
|
|
516
|
+
priority: item.priority,
|
|
512
517
|
resolve: () => { },
|
|
513
518
|
reject: () => { },
|
|
514
519
|
enqueuedAt,
|
|
@@ -548,6 +553,7 @@ export class MessageQueue {
|
|
|
548
553
|
projectPath: item.projectPath,
|
|
549
554
|
agentName: item.agentName || DEFAULT_AGENT_NAME,
|
|
550
555
|
role: item.role,
|
|
556
|
+
priority: item.priority,
|
|
551
557
|
resolve: () => { },
|
|
552
558
|
reject: () => { },
|
|
553
559
|
enqueuedAt: sourceEnqueuedAt,
|
|
@@ -576,6 +582,7 @@ export class MessageQueue {
|
|
|
576
582
|
projectPath: merged.projectPath,
|
|
577
583
|
agentName: merged.agentName,
|
|
578
584
|
role: this.highestRole(parts),
|
|
585
|
+
priority: parts.some(part => part.priority) || undefined,
|
|
579
586
|
resolve: () => parts.forEach(part => part.resolve()),
|
|
580
587
|
reject: (error) => parts.forEach(part => part.reject(error)),
|
|
581
588
|
enqueuedAt: this.earliestPartEnqueuedAt(parts),
|
|
@@ -931,6 +938,16 @@ export class MessageQueue {
|
|
|
931
938
|
for (const bucket of parsed.queues) {
|
|
932
939
|
restored += this.restoreBucket(bucket, restoredKeys);
|
|
933
940
|
}
|
|
941
|
+
// Include restored ordinary input in the logical FIFO before new input
|
|
942
|
+
// can arrive. Durable internal priority remains a physical queue prefix.
|
|
943
|
+
for (const key of restoredKeys) {
|
|
944
|
+
this.logicalQueue.clear(key);
|
|
945
|
+
for (const item of this.queues.get(key) ?? []) {
|
|
946
|
+
if (!item.priority && item.message.source !== 'owner-inject' && item.message.attentionPolicy !== 'interrupt') {
|
|
947
|
+
this.logicalQueue.enqueue(key, item.message);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
934
951
|
this.persistQueuesImmediate();
|
|
935
952
|
this.persistDurableDedup();
|
|
936
953
|
if (restored > 0) {
|
|
@@ -967,7 +984,7 @@ export class MessageQueue {
|
|
|
967
984
|
this.blockedQueues.delete(key);
|
|
968
985
|
continue;
|
|
969
986
|
}
|
|
970
|
-
if (!this.processing.has(key) && !this.blockedReason?.(head.message))
|
|
987
|
+
if (!this.processing.has(key) && !this.blockedReason?.(head.message, this.sessionKeyFromQueueKey(key)))
|
|
971
988
|
void this.processNext(key);
|
|
972
989
|
}
|
|
973
990
|
if (this.blockedQueues.size)
|
|
@@ -1090,14 +1107,15 @@ export class MessageQueue {
|
|
|
1090
1107
|
enqueuedAt,
|
|
1091
1108
|
timestamp: message.receivedAt ?? message.timestamp ?? enqueuedAt,
|
|
1092
1109
|
};
|
|
1093
|
-
const queuedItem = { message, projectPath, agentName, role: options?.role, resolve: queuedResolve, reject: queuedReject, enqueuedAt };
|
|
1110
|
+
const queuedItem = { message, projectPath, agentName, role: options?.role, priority: options?.priority, resolve: queuedResolve, reject: queuedReject, enqueuedAt };
|
|
1094
1111
|
if (options?.priority) {
|
|
1095
|
-
const firstOrdinary = queue.findIndex(item => item.message.source !== 'owner-inject'
|
|
1112
|
+
const firstOrdinary = queue.findIndex(item => item.message.source !== 'owner-inject'
|
|
1113
|
+
&& (message.source === 'owner-inject' || !item.priority));
|
|
1096
1114
|
queue.splice(firstOrdinary < 0 ? queue.length : firstOrdinary, 0, queuedItem);
|
|
1097
1115
|
}
|
|
1098
1116
|
else
|
|
1099
1117
|
queue.push(queuedItem);
|
|
1100
|
-
if (message.source !== 'owner-inject' && message.attentionPolicy !== 'interrupt')
|
|
1118
|
+
if (!options?.priority && message.source !== 'owner-inject' && message.attentionPolicy !== 'interrupt')
|
|
1101
1119
|
this.logicalQueue.enqueue(queueKey, message);
|
|
1102
1120
|
abortHandler = () => {
|
|
1103
1121
|
if (settled || aborting)
|
|
@@ -1266,9 +1284,10 @@ export class MessageQueue {
|
|
|
1266
1284
|
return;
|
|
1267
1285
|
}
|
|
1268
1286
|
// 逻辑队列重排:让响应模式的出队策略决定队首(默认 FIFO,不改变顺序)
|
|
1269
|
-
if (queue[0]?.message.source !== 'owner-inject' && queue[0]?.message.attentionPolicy !== 'interrupt')
|
|
1287
|
+
if (!queue[0]?.priority && queue[0]?.message.source !== 'owner-inject' && queue[0]?.message.attentionPolicy !== 'interrupt')
|
|
1270
1288
|
this.logicalQueue.reorderPhysical(queueKey, queue);
|
|
1271
|
-
const
|
|
1289
|
+
const sessionId = this.sessionKeyFromQueueKey(queueKey);
|
|
1290
|
+
const blocked = this.blockedReason?.(queue[0].message, sessionId);
|
|
1272
1291
|
if (blocked) {
|
|
1273
1292
|
if (this.blockedQueues.get(queueKey) !== blocked) {
|
|
1274
1293
|
logger.info(`[Queue] waiting: key=${queueKey} dependency=${blocked}`);
|
|
@@ -1282,7 +1301,7 @@ export class MessageQueue {
|
|
|
1282
1301
|
}
|
|
1283
1302
|
this.blockedQueues.delete(queueKey);
|
|
1284
1303
|
// 贪心合并:群聊按完整时间线,旧路径/私聊按 peerId
|
|
1285
|
-
const items = this.dequeueGreedy(queue);
|
|
1304
|
+
const items = this.dequeueGreedy(queue, sessionId);
|
|
1286
1305
|
// 同步逻辑队列:移除所有被合并处理的消息
|
|
1287
1306
|
if (items.length > 0) {
|
|
1288
1307
|
const processedIds = items.map(item => item.message.messageId).filter((id) => !!id);
|
|
@@ -1301,6 +1320,7 @@ export class MessageQueue {
|
|
|
1301
1320
|
projectPath: merged.projectPath,
|
|
1302
1321
|
agentName: merged.agentName,
|
|
1303
1322
|
role: this.highestRole(rawParts),
|
|
1323
|
+
priority: rawParts.some(part => part.priority) || undefined,
|
|
1304
1324
|
resolve: () => rawParts.forEach(part => part.resolve()),
|
|
1305
1325
|
reject: (error) => rawParts.forEach(part => part.reject(error)),
|
|
1306
1326
|
enqueuedAt: this.earliestPartEnqueuedAt(rawParts),
|
|
@@ -1410,7 +1430,7 @@ export class MessageQueue {
|
|
|
1410
1430
|
// 与 enqueue 路径保持同一条件,避免把 owner-inject/interrupt 消息写进逻辑队列。
|
|
1411
1431
|
this.logicalQueue.clear(queueKey);
|
|
1412
1432
|
for (const item of queue) {
|
|
1413
|
-
if (item.message.source !== 'owner-inject' && item.message.attentionPolicy !== 'interrupt') {
|
|
1433
|
+
if (!item.priority && item.message.source !== 'owner-inject' && item.message.attentionPolicy !== 'interrupt') {
|
|
1414
1434
|
this.logicalQueue.enqueue(queueKey, item.message);
|
|
1415
1435
|
}
|
|
1416
1436
|
}
|
|
@@ -1423,11 +1443,11 @@ export class MessageQueue {
|
|
|
1423
1443
|
* 群聊入队携带 role,此时取出当前所有群聊 pending 并按时间线合并;
|
|
1424
1444
|
* role 只作为逐条元数据,不作为分批边界。未携带 role 的旧路径/私聊按 peerId 合并。
|
|
1425
1445
|
*/
|
|
1426
|
-
dequeueGreedy(queue) {
|
|
1446
|
+
dequeueGreedy(queue, sessionId) {
|
|
1427
1447
|
const first = queue.shift();
|
|
1428
1448
|
const result = [first];
|
|
1429
1449
|
if (this.isOriginHandoff(first.message)) {
|
|
1430
|
-
while (queue.length > 0 && !this.blockedReason?.(queue[0].message) && this.canMergeOriginHandoffs(first, queue[0])) {
|
|
1450
|
+
while (queue.length > 0 && !this.blockedReason?.(queue[0].message, sessionId) && this.canMergeOriginHandoffs(first, queue[0])) {
|
|
1431
1451
|
result.push(queue.shift());
|
|
1432
1452
|
}
|
|
1433
1453
|
if (result.length > 1) {
|
|
@@ -1443,7 +1463,7 @@ export class MessageQueue {
|
|
|
1443
1463
|
if (mergeSubmittedResume) {
|
|
1444
1464
|
const remaining = [];
|
|
1445
1465
|
for (const item of queue) {
|
|
1446
|
-
if (!this.blockedReason?.(item.message) && !this.isMergeBarrier(item.message) && this.canDequeueAfterSubmittedResume(first, item)) {
|
|
1466
|
+
if (!this.blockedReason?.(item.message, sessionId) && !this.isMergeBarrier(item.message) && this.canDequeueAfterSubmittedResume(first, item)) {
|
|
1447
1467
|
result.push(item);
|
|
1448
1468
|
}
|
|
1449
1469
|
else {
|
|
@@ -1463,7 +1483,7 @@ export class MessageQueue {
|
|
|
1463
1483
|
else if (mergeGroupTimeline) {
|
|
1464
1484
|
const remaining = [];
|
|
1465
1485
|
for (const item of queue) {
|
|
1466
|
-
if (!this.blockedReason?.(item.message) && !this.isMergeBarrier(item.message) && this.canDequeueGroupTimeline(first, item)) {
|
|
1486
|
+
if (!this.blockedReason?.(item.message, sessionId) && !this.isMergeBarrier(item.message) && this.canDequeueGroupTimeline(first, item)) {
|
|
1467
1487
|
result.push(item);
|
|
1468
1488
|
}
|
|
1469
1489
|
else {
|
|
@@ -1475,7 +1495,7 @@ export class MessageQueue {
|
|
|
1475
1495
|
result.sort((a, b) => this.firstTimestamp(a) - this.firstTimestamp(b));
|
|
1476
1496
|
}
|
|
1477
1497
|
else {
|
|
1478
|
-
while (queue.length > 0 && !this.blockedReason?.(queue[0].message) && !this.isMergeBarrier(queue[0].message) && queue[0].message.peerId === mergeKey) {
|
|
1498
|
+
while (queue.length > 0 && !this.blockedReason?.(queue[0].message, sessionId) && !this.isMergeBarrier(queue[0].message) && queue[0].message.peerId === mergeKey) {
|
|
1479
1499
|
result.push(queue.shift());
|
|
1480
1500
|
}
|
|
1481
1501
|
}
|
|
@@ -1616,8 +1636,14 @@ export class MessageQueue {
|
|
|
1616
1636
|
subMessages.push(...m.items.map(sub => ({ ...sub, peerRole: sub.peerRole ?? item.role })));
|
|
1617
1637
|
}
|
|
1618
1638
|
else {
|
|
1639
|
+
// 跨话题自派:会话对端是话题对端(用于路由/权限),信封头署名仍是本端,
|
|
1640
|
+
// 否则模型会以为这条「我派的活」是对端说的话。
|
|
1641
|
+
const selfAddressed = m.source === 'self-address';
|
|
1619
1642
|
subMessages.push({
|
|
1620
|
-
peerId: m.
|
|
1643
|
+
peerId: selfAddressed ? (m.selfAID || m.peerId) : m.peerId,
|
|
1644
|
+
peerName: selfAddressed ? undefined : m.peerName,
|
|
1645
|
+
peerType: selfAddressed ? 'agent' : m.peerType,
|
|
1646
|
+
selfAddressed: selfAddressed || undefined,
|
|
1621
1647
|
peerRole: item.role,
|
|
1622
1648
|
sameDevice: m.sameDevice, sameNetwork: m.sameNetwork, sameEgressIp: m.sameEgressIp,
|
|
1623
1649
|
encrypted: m.encrypted,
|
|
@@ -2026,6 +2052,31 @@ export class MessageQueue {
|
|
|
2026
2052
|
}
|
|
2027
2053
|
return total;
|
|
2028
2054
|
}
|
|
2055
|
+
/** Live AUN private counterparts, deduplicated across topics and projects. */
|
|
2056
|
+
getActivePrivatePeerCountBySelfAID(selfAID) {
|
|
2057
|
+
const self = normalizeTopicAid(selfAID).toLowerCase();
|
|
2058
|
+
const peers = new Set();
|
|
2059
|
+
for (const [queueKey, item] of this.activeBatches) {
|
|
2060
|
+
if (!this.processing.has(queueKey))
|
|
2061
|
+
continue;
|
|
2062
|
+
const message = item.message;
|
|
2063
|
+
const queueSelf = this.selfAIDFromQueueKey(queueKey) ?? message.selfAID;
|
|
2064
|
+
if (!queueSelf || normalizeTopicAid(queueSelf).toLowerCase() !== self)
|
|
2065
|
+
continue;
|
|
2066
|
+
if (message.chatType !== 'private')
|
|
2067
|
+
continue;
|
|
2068
|
+
const sessionKey = this.queueKeyToSessionKey.get(queueKey);
|
|
2069
|
+
const route = sessionKey ? this.parseSessionKey(sessionKey) : message;
|
|
2070
|
+
if (route.channelType !== 'aun')
|
|
2071
|
+
continue;
|
|
2072
|
+
// Use the conversation route, not the sender of an owner-injected input.
|
|
2073
|
+
const peer = normalizeTopicAid(route.channelId).toLowerCase();
|
|
2074
|
+
if (peer === self || !safeFormatMainTopicId(self, peer))
|
|
2075
|
+
continue;
|
|
2076
|
+
peers.add(peer);
|
|
2077
|
+
}
|
|
2078
|
+
return peers.size;
|
|
2079
|
+
}
|
|
2029
2080
|
/**
|
|
2030
2081
|
* 获取指定 agent 的处理中队列详情列表(用于阻塞提示,帮助 agent 判断等待时长)。
|
|
2031
2082
|
* 每项包含 queueKey(可从中解析 sessionId 和路径)和 agentName。
|
|
@@ -7,6 +7,10 @@ import crypto from 'crypto';
|
|
|
7
7
|
import { chatDirPath, appendJsonl, readAllJsonlLines, readAllJsonlLinesAsync, scanAgentChatDirsAsync } from '../session/session-fs-store.js';
|
|
8
8
|
import { logger } from '../../utils/logger.js';
|
|
9
9
|
const PENDING_HINTS_FILE = 'pending-hints.jsonl';
|
|
10
|
+
// A new hint may introduce a chat absent from startup's directory inventory.
|
|
11
|
+
// This process-local fence only controls inventory reuse; events are always read live.
|
|
12
|
+
let directoryVersion = 0;
|
|
13
|
+
export function pendingHintDirectoryVersion() { return directoryVersion; }
|
|
10
14
|
export const OBSERVER_HINT_FAILURE_MESSAGES = {
|
|
11
15
|
SESSION_NOT_FOUND: '目标 Agent session 不存在',
|
|
12
16
|
INTERRUPT_FAILED: 'Agent 当前任务中断失败',
|
|
@@ -121,12 +125,30 @@ function deleteFile(fp) {
|
|
|
121
125
|
function claimKey(claim) {
|
|
122
126
|
return targetKey(claim.sessionsDir, claim.channelType, claim.channelId, claim.selfAID, claim.chatType, claim.threadId, claim.channelKey);
|
|
123
127
|
}
|
|
124
|
-
export async function pendingInterruptHints(sessionsDir, selfAID, channelKey) {
|
|
128
|
+
export async function pendingInterruptHints(sessionsDir, selfAID, channelKey, snapshot) {
|
|
125
129
|
const pending = [];
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
const reusable = snapshot && snapshot.version === directoryVersion
|
|
131
|
+
&& snapshot.selfAID === selfAID && path.resolve(snapshot.sessionsDir) === path.resolve(sessionsDir);
|
|
132
|
+
const chats = (reusable ? snapshot.chats : await scanAgentChatDirsAsync(sessionsDir, selfAID, channelKey))
|
|
133
|
+
.filter(chat => chat.selfAID === selfAID && chat.channelType === 'aun' && chat.channelKey
|
|
134
|
+
&& (!channelKey || chat.channelKey === channelKey));
|
|
135
|
+
const results = new Array(chats.length);
|
|
136
|
+
let next = 0;
|
|
137
|
+
const reads = await Promise.allSettled(Array.from({ length: Math.min(8, chats.length) }, async () => {
|
|
138
|
+
while (next < chats.length) {
|
|
139
|
+
const index = next++;
|
|
140
|
+
results[index] = await readAllJsonlLinesAsync(path.join(chats[index].dirPath, PENDING_HINTS_FILE));
|
|
141
|
+
}
|
|
142
|
+
}));
|
|
143
|
+
for (const result of reads)
|
|
144
|
+
if (result.status === 'rejected')
|
|
145
|
+
throw result.reason;
|
|
146
|
+
// An add during asynchronous reads invalidates negative directory evidence.
|
|
147
|
+
// Retry from the live inventory; reconnects and failed scans always use it too.
|
|
148
|
+
if (reusable && snapshot.version !== directoryVersion)
|
|
149
|
+
return pendingInterruptHints(sessionsDir, selfAID, channelKey);
|
|
150
|
+
for (const [index, chat] of chats.entries()) {
|
|
151
|
+
const events = results[index];
|
|
130
152
|
const keys = new Set(events.filter(event => event.action === 'add')
|
|
131
153
|
.map(event => `${eventChatType(event)}\u0000${normThread(event.threadId)}`));
|
|
132
154
|
for (const key of keys) {
|
|
@@ -179,6 +201,7 @@ export function appendHintAddDetailed(sessionsDir, channelType, channelId, selfA
|
|
|
179
201
|
}
|
|
180
202
|
if (idExistsElsewhere(fp, hint.id))
|
|
181
203
|
return { ok: false, id: hint.id, code: 'CONFLICT' };
|
|
204
|
+
directoryVersion++;
|
|
182
205
|
fs.mkdirSync(path.dirname(fp), { recursive: true });
|
|
183
206
|
appendJsonl(fp, {
|
|
184
207
|
action: 'add',
|
|
@@ -200,6 +223,7 @@ export function appendHintAddDetailed(sessionsDir, channelType, channelId, selfA
|
|
|
200
223
|
export function appendHintAdd(sessionsDir, channelType, channelId, selfAID, hint) {
|
|
201
224
|
try {
|
|
202
225
|
const fp = hintsPath(sessionsDir, channelType, channelId, selfAID);
|
|
226
|
+
directoryVersion++;
|
|
203
227
|
fs.mkdirSync(path.dirname(fp), { recursive: true });
|
|
204
228
|
appendJsonl(fp, {
|
|
205
229
|
action: 'add', id: hint.id, text: hint.text,
|
|
@@ -3737,7 +3737,13 @@ export class ResponseEngine {
|
|
|
3737
3737
|
const registrySelfName = selfAid ? this.agentRegistry?.resolveDisplayName?.(selfAid) : undefined;
|
|
3738
3738
|
const adapterSelfName = typeof adapterAny._selfName === 'function' ? adapterAny._selfName() : undefined;
|
|
3739
3739
|
const selfName = registrySelfName ?? adapterSelfName;
|
|
3740
|
-
|
|
3740
|
+
// 跨话题自派(source=self-address):信封头仍显示 from=本端,但关系身份必须落回
|
|
3741
|
+
// 话题对端。否则 actorId/peerKey 都变成自己:角色掉到 none、权限 readonly,
|
|
3742
|
+
// 回复也会发给自己(投递失败后还被静默吞掉)。群会话不走这条(跨话题自派不适用群)。
|
|
3743
|
+
const selfAddressedTask = message.source === 'self-address' && session.chatType !== 'group';
|
|
3744
|
+
const peerName = selfAddressedTask
|
|
3745
|
+
? (session.metadata?.peerName || session.channelId)
|
|
3746
|
+
: (message.peerName || session.metadata?.peerName);
|
|
3741
3747
|
const peerIdRaw = message.peerId;
|
|
3742
3748
|
if (message.source === 'trigger' && message.triggerMeta?.originChannelType === 'aun'
|
|
3743
3749
|
&& message.triggerMeta.originChatType !== 'group') {
|
|
@@ -3760,7 +3766,8 @@ export class ResponseEngine {
|
|
|
3760
3766
|
// operator. Keep the historical private-chat fallback (where channelId
|
|
3761
3767
|
// is the peer identity for AUN), but fail closed for group messages that
|
|
3762
3768
|
// arrive without a sender/operator ID.
|
|
3763
|
-
|
|
3769
|
+
// 跨话题自派的路由身份取话题对端(会话 channelId),署名仍用 message.peerId。
|
|
3770
|
+
const turnPeerId = selfAddressedTask ? session.channelId : peerIdRaw;
|
|
3764
3771
|
const configActorId = authorizationIdentity?.actorId
|
|
3765
3772
|
?? (turnPeerId || (configChatType === 'private' ? message.channelId : undefined));
|
|
3766
3773
|
const peerKeyId = authorizationIdentity?.actorId ?? (session.chatType === 'group'
|
|
@@ -5612,8 +5619,13 @@ export class ResponseEngine {
|
|
|
5612
5619
|
labels: message.triggerMeta.labels,
|
|
5613
5620
|
},
|
|
5614
5621
|
} : {}),
|
|
5615
|
-
|
|
5616
|
-
|
|
5622
|
+
// 跨话题自派:信封头署名本端,让模型分清「我派的活」;但消息对端
|
|
5623
|
+
// (以及下面的 peerRole)仍是话题对端,路由与权限都按它来。
|
|
5624
|
+
peerId: message.source === 'self-address'
|
|
5625
|
+
? (message.selfAID || message.peerId) : message.peerId,
|
|
5626
|
+
peerName: message.source === 'self-address' ? undefined : (peerName || undefined),
|
|
5627
|
+
peerType: message.source === 'self-address' ? 'agent' : message.peerType,
|
|
5628
|
+
selfAddressed: message.source === 'self-address' || undefined,
|
|
5617
5629
|
peerRole: systemSessionMarker ? undefined : (message.batchRole || session.identity?.role || 'none'),
|
|
5618
5630
|
sameDevice: message.sameDevice, sameNetwork: message.sameNetwork, sameEgressIp: message.sameEgressIp,
|
|
5619
5631
|
encrypted: message.encrypted,
|
|
@@ -6601,6 +6613,16 @@ export class ResponseEngine {
|
|
|
6601
6613
|
}
|
|
6602
6614
|
return;
|
|
6603
6615
|
}
|
|
6616
|
+
if (!isNonErrorInterruptReason(preFlushInterrupt) && this.turnCoordinator.canPublish(turnLease)) {
|
|
6617
|
+
try {
|
|
6618
|
+
await renderer.flushProactiveFinal();
|
|
6619
|
+
}
|
|
6620
|
+
catch (error) {
|
|
6621
|
+
const tagged = error instanceof Error ? error : new Error(String(error));
|
|
6622
|
+
tagged._replyDeliveryFailed = true;
|
|
6623
|
+
throw tagged;
|
|
6624
|
+
}
|
|
6625
|
+
}
|
|
6604
6626
|
}
|
|
6605
6627
|
else {
|
|
6606
6628
|
await this.turnCoordinator.finish(session, turnLease, terminalInterrupt ? 'cancelled' : 'failed', permissionTerminalFailure ? 'permission_denied'
|
|
@@ -7498,12 +7520,20 @@ export class ResponseEngine {
|
|
|
7498
7520
|
return { session: bound, absoluteProjectPath: path.isAbsolute(bound.projectPath)
|
|
7499
7521
|
? bound.projectPath : path.resolve(process.cwd(), bound.projectPath) };
|
|
7500
7522
|
}
|
|
7501
|
-
// 话题会话创建时写入创建者和 replyContext(threadId
|
|
7523
|
+
// 话题会话创建时写入创建者和 replyContext(threadId 路由);主会话不写(避免群聊覆盖)。
|
|
7524
|
+
// 本端绝不能成为话题对端:私聊的 channelId 才是话题对端,任何把 peerId 写成
|
|
7525
|
+
// 本端的消息都在这里落回 channelId,否则话题会退化成「我↔我」、回复无处可投。
|
|
7526
|
+
const topicPeerId = message.peerId && message.peerId !== message.selfAID
|
|
7527
|
+
? message.peerId
|
|
7528
|
+
: message.channelId;
|
|
7529
|
+
const topicPeerName = message.peerName && message.peerName !== message.selfAID
|
|
7530
|
+
? message.peerName
|
|
7531
|
+
: undefined;
|
|
7502
7532
|
const metadata = isTopicThreadId(message.threadId)
|
|
7503
7533
|
? {
|
|
7504
7534
|
...(message.replyContext ? { replyContext: message.replyContext } : {}),
|
|
7505
|
-
...(
|
|
7506
|
-
...(
|
|
7535
|
+
...(topicPeerId ? { peerId: topicPeerId } : {}),
|
|
7536
|
+
...(topicPeerName ? { peerName: topicPeerName } : {}),
|
|
7507
7537
|
}
|
|
7508
7538
|
: undefined;
|
|
7509
7539
|
const owningAgent = this.agentRegistry?.resolveByChannel(message.channel);
|
|
@@ -234,14 +234,19 @@ export function resolveSendRoute(input, session, deps = {}) {
|
|
|
234
234
|
return fail('TOPIC_CONFLICT', `--thread 指向 ${peer.id},--to 指向 ${explicitPeer.id},两者冲突`, '--to 只能是话题对端或本端自己;一次发送只能有一个目标');
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
//
|
|
237
|
+
// 跨话题自派只适用于私聊话题:群投递的位置参数恒为群 AID,`--to 本端` 会被当成
|
|
238
238
|
// 发群消息,收件人与回执对不上,还会把本应给自己的内容发进群。
|
|
239
239
|
if (recipient === 'self' && peer.peerKind === 'group') {
|
|
240
|
-
return fail('INVALID_ARGUMENT', '群话题不支持发给自己', '
|
|
240
|
+
return fail('INVALID_ARGUMENT', '群话题不支持发给自己', '群消息的收件人恒为群;跨话题自派只用于私聊话题(--thread <私聊话题> --to <本端AID>)');
|
|
241
241
|
}
|
|
242
242
|
const recipientId = recipient === 'self' ? self : peer.id;
|
|
243
243
|
// 4. 跨话题判定
|
|
244
244
|
const crossTopic = !sameRoutePeer(peer, currentPeer, deps) || threadId !== currentThread;
|
|
245
|
+
// 自派必须换话题:同话题再跑一轮等于「无用户输入的跨话题自派回复」,没有独有场景
|
|
246
|
+
// (本轮续跑 / session loop / Trigger 都能覆盖),却容易形成自循环。
|
|
247
|
+
if (recipient === 'self' && !crossTopic) {
|
|
248
|
+
return fail('INVALID_ARGUMENT', '仅允许跨话题自派');
|
|
249
|
+
}
|
|
245
250
|
// 5. 复查周期
|
|
246
251
|
let checkEveryMs;
|
|
247
252
|
let checkEveryDefaulted = false;
|
|
@@ -280,7 +285,7 @@ export function resolveSendRoute(input, session, deps = {}) {
|
|
|
280
285
|
return fail('ENCRYPT_UNSUPPORTED', `目标对端 ${peer.id} 不在 AUN 网络上(channel=${peer.channelType}),无法端到端加密`, '去掉 --encrypt 或改用 --encrypt no');
|
|
281
286
|
}
|
|
282
287
|
// auto 的取值:
|
|
283
|
-
// -
|
|
288
|
+
// - 跨话题自派(recipient='self'):跟随话题 T 上一条消息的加密态(D4)。跨话题自派不是
|
|
284
289
|
// 被对端触发的,`inboundEncrypted` 描述的是当前会话而非话题 T,不能拿来用。
|
|
285
290
|
// - 其余:本轮被入站消息触发就沿用该消息,否则明文。
|
|
286
291
|
let lastTopicEncrypted;
|
|
@@ -340,19 +345,21 @@ function sourceLabel(source, field) {
|
|
|
340
345
|
* 格式:`from=<self> to=<id>(<来源>) thread=<threadId>(<来源>) chatType=<kind>`
|
|
341
346
|
* 推断补全的值标来源,全部为归一化后的实际生效值,不是输入原文。
|
|
342
347
|
*
|
|
343
|
-
*
|
|
348
|
+
* 跨话题自派(`recipient === 'self'`)时 `to` 回显本端 AID 并附 `recipient=self`,
|
|
344
349
|
* 让调用方一眼看出这不是发给对端的。话题仍按对端所属话题回显。
|
|
345
350
|
*/
|
|
346
351
|
export function formatRouteReceipt(route) {
|
|
347
352
|
const threadLabel = route.threadId ? route.threadId : 'main';
|
|
348
353
|
const target = route.recipient === 'self'
|
|
349
|
-
? `to=${route.recipientId}(
|
|
354
|
+
? `to=${route.recipientId}(跨话题自派)`
|
|
350
355
|
: `to=${route.peer.id}(${sourceLabel(route.source, 'peer')})`;
|
|
351
356
|
return [
|
|
352
357
|
`from=${route.self}`,
|
|
353
358
|
target,
|
|
354
359
|
`thread=${threadLabel}(${sourceLabel(route.source, 'thread')})`,
|
|
355
360
|
`chatType=${route.peer.peerKind}`,
|
|
356
|
-
...(route.recipient === 'self'
|
|
361
|
+
...(route.recipient === 'self'
|
|
362
|
+
? ['recipient=self', `topicPeer=${route.peer.id}`]
|
|
363
|
+
: []),
|
|
357
364
|
].join(' ');
|
|
358
365
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 事件包 / 服务包运维命令的授权判定。
|
|
3
|
+
*
|
|
4
|
+
* 权限模型(主机终端 > 同 AID > 跨 AID 逐级收紧):
|
|
5
|
+
*
|
|
6
|
+
* | 调用方 | 只读命令 | 需管理的命令 |
|
|
7
|
+
* | --- | --- | --- |
|
|
8
|
+
* | 主机终端(control token) | ✅ | ✅ |
|
|
9
|
+
* | 托管会话,目标 = 自己 AID | ✅ | owner / admin |
|
|
10
|
+
* | 托管会话,目标 ≠ 自己 AID | ✅ | 三重 owner |
|
|
11
|
+
*
|
|
12
|
+
* 「三重 owner」= ① 执行方 agent 的角色是 owner(admin 不够)② 执行方与目标
|
|
13
|
+
* AID 的协议 owner 是同一个 ③ 不是 daemon 控制面上的直接调用(那种走主机终端分支)。
|
|
14
|
+
*
|
|
15
|
+
* 为什么跨 AID 要额外一层:`pack add` 等于给目标 agent 安装一段以后会以它的身份
|
|
16
|
+
* 执行的代码。同 AID 是"自己装给自己的",跨 AID 则是"用别人的身份执行",
|
|
17
|
+
* 只有同一个 Owner 名下的两个 agent 之间才存在这种正当性。
|
|
18
|
+
*
|
|
19
|
+
* 为什么不读 `/public` 或名录里的转发关系:那些都是会被拷贝、会变的展示信息;
|
|
20
|
+
* 协议 owner 归属(`ownerResolver`)才是唯一可信判据。
|
|
21
|
+
*/
|
|
22
|
+
import { getProtocolOwner } from './ownership/owner-resolver.js';
|
|
23
|
+
const MANAGING_ROLES = new Set(['owner', 'admin']);
|
|
24
|
+
export function authorizePackTarget(input) {
|
|
25
|
+
// 主机终端:人自己在操作,OS 账户可读 control.token 就是信任边界。
|
|
26
|
+
if (input.caller.kind === 'local-control')
|
|
27
|
+
return { allowed: true };
|
|
28
|
+
const selfAid = input.caller.selfAid;
|
|
29
|
+
if (!selfAid) {
|
|
30
|
+
return { allowed: false, code: 'NOT_ALLOWED', error: '当前任务身份不可用;托管会话需要 sessionId 与 delegationToken' };
|
|
31
|
+
}
|
|
32
|
+
if (!input.requiresManagement)
|
|
33
|
+
return { allowed: true };
|
|
34
|
+
const role = input.caller.peerRole;
|
|
35
|
+
if (input.targetAid === selfAid) {
|
|
36
|
+
return role && MANAGING_ROLES.has(role)
|
|
37
|
+
? { allowed: true }
|
|
38
|
+
: {
|
|
39
|
+
allowed: false,
|
|
40
|
+
code: 'ROLE_ACCESS_DENIED',
|
|
41
|
+
error: `管理本机事件/服务包需要 owner 或 admin 身份(当前 ${role ?? 'none'})`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// 跨 AID:三重 owner —— 执行方本人、目标 AID、本机 daemon 都必须归属同一个 Owner。
|
|
45
|
+
if (role !== 'owner') {
|
|
46
|
+
return {
|
|
47
|
+
allowed: false,
|
|
48
|
+
code: 'ROLE_ACCESS_DENIED',
|
|
49
|
+
error: `跨 AID 管理需要 owner 身份(当前 ${role ?? 'none'};admin 不足以操作其它 agent)`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const selfOwner = getProtocolOwner(selfAid);
|
|
53
|
+
const targetOwner = getProtocolOwner(input.targetAid);
|
|
54
|
+
if (!selfOwner || !targetOwner) {
|
|
55
|
+
return {
|
|
56
|
+
allowed: false,
|
|
57
|
+
code: 'OWNERSHIP_UNAVAILABLE',
|
|
58
|
+
error: `跨 AID 管理需要双方都有协议 owner 归属(self=${selfOwner ?? 'none'}, target=${targetOwner ?? 'none'})`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (selfOwner !== targetOwner) {
|
|
62
|
+
return {
|
|
63
|
+
allowed: false,
|
|
64
|
+
code: 'CROSS_AGENT_DENIED',
|
|
65
|
+
error: `跨 AID 管理要求两个 agent 属于同一个 Owner(self owner=${selfOwner}, target owner=${targetOwner})`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// 第三重:本机 daemon 也必须归属同一个 Owner——否则是"别人的机器替别人装包"。
|
|
69
|
+
if (input.daemonAid && input.daemonAid !== selfAid) {
|
|
70
|
+
const daemonOwner = getProtocolOwner(input.daemonAid);
|
|
71
|
+
if (!daemonOwner) {
|
|
72
|
+
return {
|
|
73
|
+
allowed: false,
|
|
74
|
+
code: 'OWNERSHIP_UNAVAILABLE',
|
|
75
|
+
error: `跨 AID 管理需要本机 daemon(${input.daemonAid})的协议 owner 归属`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (daemonOwner !== selfOwner) {
|
|
79
|
+
return {
|
|
80
|
+
allowed: false,
|
|
81
|
+
code: 'CROSS_AGENT_DENIED',
|
|
82
|
+
error: `跨 AID 管理要求本机 daemon 也属于同一 Owner(daemon owner=${daemonOwner}, self owner=${selfOwner})`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { allowed: true };
|
|
87
|
+
}
|
|
88
|
+
/** 命令 → 是否需要管理权限。未列出的命令按"只读"处理。 */
|
|
89
|
+
export function isManagingEventsCommand(command) {
|
|
90
|
+
return command === 'pack' || command === 'rules';
|
|
91
|
+
}
|
|
92
|
+
export function isManagingServicesCommand(command) {
|
|
93
|
+
return command === 'pack' || command === 'enable' || command === 'disable';
|
|
94
|
+
}
|