evolcore 0.0.43-test.2 → 0.0.43-test.4
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 +44 -1
- package/bin/ecmsg.js +229 -0
- package/bin/install-codex-managed-hooks.mjs +130 -8
- package/dist/ability/application-service.js +37 -0
- package/dist/ability/resources.js +28 -0
- package/dist/ability/runtime.js +6 -1
- package/dist/agents/claude-runner.js +7 -5
- package/dist/agents/codex/app-server-client.js +0 -12
- package/dist/agents/codex-runner.js +0 -37
- package/dist/agents/ecagent-runner.js +138 -36
- package/dist/aun/aid/agentmd.js +52 -13
- package/dist/aun/menu/client.js +8 -7
- package/dist/aun/menu/index.js +1 -1
- package/dist/aun/menu/transport.js +8 -5
- package/dist/aun/msg/p2p.js +4 -2
- package/dist/aun/service-proxy.js +3 -0
- package/dist/channels/aun.js +105 -53
- package/dist/channels/daemon.js +14 -2
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +31 -11
- package/dist/cli/agent.js +9 -3
- package/dist/cli/aun-commands.js +19 -21
- package/dist/cli/daemon-commands.js +30 -18
- package/dist/cli/directory.js +98 -56
- package/dist/cli/getmeta-command.js +2 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/init.js +13 -5
- package/dist/cli/peer.js +2 -1
- package/dist/cli/task-context.js +3 -1
- package/dist/cli/trigger-command.js +20 -14
- package/dist/config/access-policy.js +0 -1
- package/dist/config/boot-log.js +12 -2
- package/dist/config/builtin-role-templates.js +2 -2
- package/dist/config/builtin-roles.js +2 -1
- package/dist/config/config-field-policy.js +7 -0
- package/dist/config/config-manager.js +30 -10
- package/dist/config/peer-role-resolver.js +23 -1
- package/dist/config/role-schema.js +25 -1
- package/dist/config/role-service.js +9 -4
- package/dist/config/role-store.js +30 -8
- package/dist/config/schema-migration.js +121 -0
- package/dist/core/agent-application-service.js +11 -0
- package/dist/core/agent-ipc-registration.js +2 -0
- package/dist/core/agent-runtime.js +41 -9
- package/dist/core/auth/auth-gateway.js +14 -4
- package/dist/core/auth/operation-authorizer.js +19 -1
- package/dist/core/auth/operation-catalog.js +12 -2
- package/dist/core/baseagent-loader.js +11 -3
- package/dist/core/bootstrap-service.js +8 -0
- package/dist/core/channel-loader.js +61 -23
- package/dist/core/channel-runtime.js +5 -0
- package/dist/core/command/agent-control.js +5 -2
- package/dist/core/command/agentmd-menu-request.js +50 -0
- package/dist/core/command/agentmd-menu.js +156 -0
- package/dist/core/command/chatmode-config.js +46 -0
- package/dist/core/command/command-handler.js +44 -17
- package/dist/core/command/daemon-diagnostics.js +2 -1
- package/dist/core/command/menu-catalog.js +14 -1
- package/dist/core/command/menu-handler.js +74 -24
- package/dist/core/command/menu-protocol.js +8 -0
- package/dist/core/command/role-menu.js +23 -9
- package/dist/core/command/slash-handler.js +52 -47
- package/dist/core/daemon-lifecycle.js +43 -17
- package/dist/core/event-catalog.js +19 -0
- package/dist/core/evolagent-registry.js +3 -0
- package/dist/core/evolagent.js +5 -4
- package/dist/core/ipc-registration.js +6 -0
- package/dist/core/lifecycle-notice.js +185 -0
- package/dist/core/message/aun-ipc-sender.js +30 -24
- package/dist/core/message/contact-admission.js +1 -19
- package/dist/core/message/im-renderer.js +81 -40
- package/dist/core/message/message-admission.js +21 -62
- package/dist/core/message/message-bridge.js +18 -5
- package/dist/core/message/message-utils.js +9 -0
- package/dist/core/message/peer-mode.js +16 -8
- package/dist/core/message/response-engine.js +67 -47
- package/dist/core/model/model-capabilities.js +37 -0
- package/dist/core/model/model-catalog.js +6 -2
- package/dist/core/ownership/owner-resolver.js +74 -36
- package/dist/core/permission/ec-command-parser.js +62 -13
- package/dist/core/plugin-lifecycle.js +6 -2
- package/dist/core/relation/pa-team.js +132 -0
- package/dist/core/role/runtime-policy.js +4 -3
- package/dist/core/thread/thread-service.js +6 -4
- package/dist/directory/owner-directory-admission.js +0 -3
- package/dist/directory/owner-directory-cache.js +201 -17
- package/dist/directory/owner-directory-markdown.js +44 -21
- package/dist/directory/owner-directory-policy.js +1 -1
- package/dist/directory/owner-directory-query-operation.js +218 -98
- package/dist/directory/owner-directory-request-operation.js +76 -0
- package/dist/directory/owner-directory-scope.js +35 -4
- package/dist/directory/owner-directory-search.js +76 -23
- package/dist/directory/owner-directory-store.js +5 -38
- package/dist/directory/owner-directory-text.js +60 -0
- package/dist/eck/kit-renderer.js +6 -3
- package/dist/eck/message-renderer.js +2 -5
- package/dist/ecweb/message-context-service.js +4 -0
- package/dist/ecweb/runtime/lifecycle.js +29 -5
- package/dist/ecweb/runtime/supervisor.js +83 -27
- package/dist/index.js +209 -38
- package/dist/paths.js +4 -2
- package/dist/product.js +1 -0
- package/dist/proxy/service-supervisor.js +377 -141
- package/dist/response-system/engines/v1/index.js +2 -4
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/trigger/audit.js +3 -2
- package/dist/trigger/authorization.js +2 -3
- package/dist/trigger/history.js +4 -3
- package/dist/trigger/ipc-service.js +24 -19
- package/dist/trigger/manager.js +3 -5
- package/dist/trigger/parser.js +4 -21
- package/dist/trigger/patch.js +3 -15
- package/dist/trigger/scheduler.js +53 -13
- package/dist/trigger/validation.js +0 -13
- package/dist/utils/error-utils.js +15 -5
- package/dist/utils/macos-autostart.js +31 -0
- package/dist/utils/model-prices.jsonl +15 -8
- package/dist/utils/process-introspect.js +21 -1
- package/dist/utils/startup-trace.js +7 -1
- package/dist/utils/windows-autostart.js +1 -0
- package/ecagent/README.md +18 -0
- package/ecagent/dist/harness/agent-harness.d.ts +2 -0
- package/ecagent/dist/harness/agent-harness.js +24 -8
- package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
- package/ecagent/dist/harness/compaction/compaction.js +7 -4
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/directory.md +125 -35
- package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
- package/kits/docs/evolcore/file-navigation.md +279 -0
- package/kits/docs/evolcore/menu-protocol.md +1 -0
- package/kits/docs/evolcore/model.md +5 -3
- package/kits/docs/evolcore/msg.md +1 -0
- package/kits/docs/evolcore/peer.md +2 -1
- package/kits/docs/evolcore/response.md +4 -2
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +1 -1
- package/kits/docs/evolcore/tool-authorization.md +4 -1
- package/kits/docs/evolcore/trigger.md +10 -7
- package/kits/docs/identity/ROLE_DETAIL.md +2 -0
- package/kits/eck_manifest.json +6 -23
- package/kits/eck_manifest.memory.json +26 -1
- package/kits/rules/01-overview.md +42 -44
- package/kits/rules/02-navigation.md +44 -53
- package/kits/rules/03-identity.md +21 -25
- package/kits/rules/04-relation.md +23 -33
- package/kits/rules/05-venue.md +24 -25
- package/kits/schemas/_meta.json +10 -10
- package/kits/schemas/agent-config.schema.19.json +10 -6
- package/kits/schemas/relation-config.schema.12.json +2 -2
- package/kits/schemas/role-config.schema.2.json +5 -5
- package/kits/schemas/role-registry.schema.1.json +3 -2
- package/kits/skills/ec-service-proxy/SKILL.md +10 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/soul/00-GUIDE.md +20 -42
- package/kits/templates/system-fragments/channel.md +2 -2
- package/kits/templates/system-fragments/commands.md +1 -1
- package/kits/templates/system-fragments/directory-contacts.md +1 -1
- package/kits/templates/system-fragments/identity.md +0 -1
- package/kits/templates/system-fragments/personal-assistant.md +2 -17
- package/kits/templates/system-fragments/reply.md +7 -0
- package/kits/templates/system-fragments/session.md +6 -2
- package/package.json +18 -13
- package/dist/eck/paactive-context.js +0 -45
- package/dist/response-system/engines/v1/paactive-flow.js +0 -18
- package/kits/eck_manifest.paactive.json +0 -528
- package/kits/eck_message_manifest.paactive.json +0 -233
- package/kits/templates/message-fragments/paactive/item.md +0 -3
- package/kits/templates/system-fragments/paactive/channel.md +0 -25
- package/kits/templates/system-fragments/paactive/reply.md +0 -25
- package/kits/templates/system-fragments/paactive/session.md +0 -32
package/dist/aun/menu/client.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
4
|
import { createShortConnection } from '../rpc/client.js';
|
|
5
|
-
import { MENU_MESSAGE_TTL_SECONDS } from './transport.js';
|
|
5
|
+
import { MENU_MESSAGE_CLASS, MENU_MESSAGE_TTL_SECONDS } from './transport.js';
|
|
6
6
|
import { SLOT } from '../aid/store.js';
|
|
7
7
|
import { isValidAid } from '../aid/validation.js';
|
|
8
8
|
import { resolveRoot } from '../../paths.js';
|
|
@@ -125,7 +125,7 @@ export class ManagedMenuClient {
|
|
|
125
125
|
});
|
|
126
126
|
const sent = this.send({
|
|
127
127
|
to: options.targetAid, payload: request, encrypt: true,
|
|
128
|
-
ttl: MENU_MESSAGE_TTL_SECONDS, protected_headers: headers,
|
|
128
|
+
message_class: MENU_MESSAGE_CLASS, ttl: MENU_MESSAGE_TTL_SECONDS, protected_headers: headers,
|
|
129
129
|
}, options.beforeSend)
|
|
130
130
|
.then(result => {
|
|
131
131
|
if (!(result?.message_id ?? result?.message?.message_id))
|
|
@@ -276,7 +276,7 @@ async function pollResponse(conn, targetAid, requestId, timeoutMs, initialAfterS
|
|
|
276
276
|
const deadline = Date.now() + timeoutMs;
|
|
277
277
|
let afterSeq = initialAfterSeq;
|
|
278
278
|
while (Date.now() < deadline) {
|
|
279
|
-
const result = await callClient(conn, 'message.pull', { after_seq: afterSeq, limit: PULL_LIMIT });
|
|
279
|
+
const result = await callClient(conn, 'message.pull', { message_class: MENU_MESSAGE_CLASS, after_seq: afterSeq, limit: PULL_LIMIT });
|
|
280
280
|
const messages = Array.isArray(result?.messages) ? result.messages : [];
|
|
281
281
|
let maxSeq = afterSeq;
|
|
282
282
|
for (const message of messages) {
|
|
@@ -290,7 +290,7 @@ async function pollResponse(conn, targetAid, requestId, timeoutMs, initialAfterS
|
|
|
290
290
|
if (response && messageFrom === targetAid && response.id === requestId) {
|
|
291
291
|
if (Number.isSafeInteger(maxSeq) && maxSeq > afterSeq) {
|
|
292
292
|
try {
|
|
293
|
-
await callClient(conn, 'message.ack', { seq: maxSeq });
|
|
293
|
+
await callClient(conn, 'message.ack', { message_class: MENU_MESSAGE_CLASS, seq: maxSeq });
|
|
294
294
|
}
|
|
295
295
|
catch (error) {
|
|
296
296
|
throw new MenuClientError('ACK_FAILED', error?.message ?? String(error));
|
|
@@ -302,7 +302,7 @@ async function pollResponse(conn, targetAid, requestId, timeoutMs, initialAfterS
|
|
|
302
302
|
if (Number.isSafeInteger(maxSeq) && maxSeq > afterSeq) {
|
|
303
303
|
afterSeq = maxSeq;
|
|
304
304
|
try {
|
|
305
|
-
await callClient(conn, 'message.ack', { seq: afterSeq });
|
|
305
|
+
await callClient(conn, 'message.ack', { message_class: MENU_MESSAGE_CLASS, seq: afterSeq });
|
|
306
306
|
}
|
|
307
307
|
catch (error) {
|
|
308
308
|
throw new MenuClientError('ACK_FAILED', error?.message ?? String(error));
|
|
@@ -316,7 +316,7 @@ async function pollResponse(conn, targetAid, requestId, timeoutMs, initialAfterS
|
|
|
316
316
|
async function drainBaseline(conn) {
|
|
317
317
|
let afterSeq = 0;
|
|
318
318
|
for (let page = 0; page < 200; page += 1) {
|
|
319
|
-
const result = await callClient(conn, 'message.pull', { after_seq: afterSeq, limit: PULL_LIMIT });
|
|
319
|
+
const result = await callClient(conn, 'message.pull', { message_class: MENU_MESSAGE_CLASS, after_seq: afterSeq, limit: PULL_LIMIT });
|
|
320
320
|
const messages = Array.isArray(result?.messages) ? result.messages : [];
|
|
321
321
|
let maxSeq = Math.max(afterSeq, Number(result?.server_ack_seq) || 0);
|
|
322
322
|
for (const message of messages) {
|
|
@@ -326,7 +326,7 @@ async function drainBaseline(conn) {
|
|
|
326
326
|
}
|
|
327
327
|
if (maxSeq > afterSeq) {
|
|
328
328
|
try {
|
|
329
|
-
await callClient(conn, 'message.ack', { seq: maxSeq });
|
|
329
|
+
await callClient(conn, 'message.ack', { message_class: MENU_MESSAGE_CLASS, seq: maxSeq });
|
|
330
330
|
}
|
|
331
331
|
catch (error) {
|
|
332
332
|
throw new MenuClientError('ACK_FAILED', error?.message ?? String(error));
|
|
@@ -363,6 +363,7 @@ async function sendOnce(options, request, timeoutMs) {
|
|
|
363
363
|
to: options.targetAid,
|
|
364
364
|
payload: request,
|
|
365
365
|
encrypt,
|
|
366
|
+
message_class: MENU_MESSAGE_CLASS,
|
|
366
367
|
ttl: MENU_MESSAGE_TTL_SECONDS,
|
|
367
368
|
...(encrypt ? { protected_headers: headers } : {}),
|
|
368
369
|
});
|
package/dist/aun/menu/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { ManagedMenuClient, MenuClientError, executeMenuClientRequest } from './client.js';
|
|
2
|
-
export { MENU_MESSAGE_TTL_SECONDS, MENU_VOLATILE_SDK_VERSION, menuSenderDeviceId, menuTransportParams, supportsMenuVolatileTransport, } from './transport.js';
|
|
2
|
+
export { MENU_MESSAGE_TTL_SECONDS, MENU_MESSAGE_CLASS, MENU_VOLATILE_SDK_VERSION, menuSenderDeviceId, menuTransportParams, supportsMenuVolatileTransport, } from './transport.js';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Message Service TTL in seconds; unrelated to Menu execution/client timeouts. */
|
|
2
2
|
export const MENU_MESSAGE_TTL_SECONDS = 60;
|
|
3
|
+
/** Menu is an application control protocol, so it uses the AUN control stream. */
|
|
4
|
+
export const MENU_MESSAGE_CLASS = 'control';
|
|
3
5
|
export const MENU_VOLATILE_SDK_VERSION = '0.5.17';
|
|
4
6
|
function parseSdkVersion(value) {
|
|
5
7
|
if (typeof value !== 'string' || !/^\d+\.\d+\.\d+$/.test(value.trim()))
|
|
@@ -30,22 +32,23 @@ export function menuTransportParams(method, params) {
|
|
|
30
32
|
if (method !== 'message.send' || typeof params.payload?.type !== 'string'
|
|
31
33
|
|| !params.payload.type.startsWith('menu.'))
|
|
32
34
|
return params;
|
|
33
|
-
if (params.payload.type !== 'menu.response' && params.payload.type !== 'menu.event')
|
|
34
|
-
return { ...params, ttl: MENU_MESSAGE_TTL_SECONDS };
|
|
35
|
+
if (params.payload.type !== 'menu.response' && params.payload.type !== 'menu.event') {
|
|
36
|
+
return { ...params, message_class: MENU_MESSAGE_CLASS, ttl: MENU_MESSAGE_TTL_SECONDS };
|
|
37
|
+
}
|
|
35
38
|
const { to_device_id: target, menu_client_sdk_version: sdkVersion, menu_client_volatile_v1: capability, ...rest } = params;
|
|
36
39
|
delete rest.device_id;
|
|
37
40
|
if (!supportsMenuVolatileTransport(sdkVersion ?? params.protected_headers?.sdk_version, capability)) {
|
|
38
41
|
// Evol App versions backed by fastaun < 0.5.17 do not consume the
|
|
39
42
|
// volatile cursor or understand device-targeted Menu responses.
|
|
40
|
-
return rest;
|
|
43
|
+
return { ...rest, message_class: MENU_MESSAGE_CLASS };
|
|
41
44
|
}
|
|
42
45
|
if (target === undefined)
|
|
43
|
-
return { ...rest, ttl: MENU_MESSAGE_TTL_SECONDS };
|
|
46
|
+
return { ...rest, message_class: MENU_MESSAGE_CLASS, ttl: MENU_MESSAGE_TTL_SECONDS };
|
|
44
47
|
const deviceId = menuSenderDeviceId(target);
|
|
45
48
|
if (!deviceId) {
|
|
46
49
|
throw Object.assign(new Error('Invalid Menu reply device'), { code: 'INVALID_MENU_REPLY_DEVICE', retryable: false });
|
|
47
50
|
}
|
|
48
51
|
// device_id takes precedence in the SDK; do not let it override the captured
|
|
49
52
|
// request sender. A rejected target is never retried as an AID broadcast.
|
|
50
|
-
return { ...rest, ttl: MENU_MESSAGE_TTL_SECONDS, to_device_id: deviceId };
|
|
53
|
+
return { ...rest, message_class: MENU_MESSAGE_CLASS, ttl: MENU_MESSAGE_TTL_SECONDS, to_device_id: deviceId };
|
|
51
54
|
}
|
package/dist/aun/msg/p2p.js
CHANGED
|
@@ -44,7 +44,8 @@ export function daemonTaskSendIpcTimeoutMs(file = false, requestTimeoutMs) {
|
|
|
44
44
|
export function resolveAunMessageEncrypt(explicit) {
|
|
45
45
|
if (typeof explicit === 'boolean')
|
|
46
46
|
return explicit;
|
|
47
|
-
|
|
47
|
+
// 默认明文:只有显式 --encrypt 或 daemon.json 配置 aun.defaultEncrypt 才加密。
|
|
48
|
+
return readDaemonConfigForSend().aun?.defaultEncrypt ?? false;
|
|
48
49
|
}
|
|
49
50
|
function buildSimplePayload(body) {
|
|
50
51
|
switch (body.mode) {
|
|
@@ -187,7 +188,8 @@ async function daemonMsgSendResult(args, payload, runtimeContext, daemonResult)
|
|
|
187
188
|
}
|
|
188
189
|
const sent = {
|
|
189
190
|
ok: true,
|
|
190
|
-
|
|
191
|
+
// handoff_id 是内部投递实例,不再冒充 message_id 回给调用方。
|
|
192
|
+
message_id: daemonResult.message_id || '',
|
|
191
193
|
handoff_id: daemonResult.handoff_id,
|
|
192
194
|
target_session_id: daemonResult.target_session_id,
|
|
193
195
|
seq: daemonResult.seq,
|
|
@@ -62,6 +62,9 @@ function discoverInstancePort(serviceName, expectedPort) {
|
|
|
62
62
|
&& isProcessAlive(rec.pid)
|
|
63
63
|
&& typeof rec.startedAt === 'number'
|
|
64
64
|
&& Number.isFinite(rec.startedAt)
|
|
65
|
+
&& (raw.owner !== 'evolcore-service-supervisor'
|
|
66
|
+
|| ((raw.state === undefined || raw.state === 'ready')
|
|
67
|
+
&& startTimeMatches(rec.startedAt, getProcessStartTime(rec.pid))))
|
|
65
68
|
&& (serviceName !== 'ecweb' || !('schemaVersion' in rec) || startTimeMatches(rec.startedAt, getProcessStartTime(rec.pid)))
|
|
66
69
|
&& rec.startedAt >= 0
|
|
67
70
|
&& Number.isInteger(rec.port)
|
package/dist/channels/aun.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { E2EEError, validateAIDFormat } from '@agentunion/fastaun';
|
|
2
2
|
import { sanitizeMenuLogValue } from '../core/command/menu-protocol.js';
|
|
3
|
-
import {
|
|
4
|
-
import { evaluateOutboundContactAdmission } from '../core/message/message-admission.js';
|
|
3
|
+
import { buildContactRequest, contactIntroductionText, consumeContactIntroductionBudget, currentContactBinding, verifiedContactBinding, evaluateAppContactAdmission, executeContactGrant, isContactControlPayload, reconcileTemporaryContactGrants, sameContactBinding, isolatedContactSource, saveIsolatedContactSource, contactSourceDigest, CONTACT_EVENT_TTL_MS, FRIEND_INVITE_TYPE, FRIEND_INVITE_RESULT_TYPE, isFriendInvitePayload, parseFriendInvite, recordedFriendInviteDecision, decideFriendInvite, markFriendInviteWelcomed, buildFriendInviteResult, friendPayloadRouteValid, friendInviteWelcomeText } from '../core/message/contact-admission.js';
|
|
5
4
|
import crypto from 'crypto';
|
|
6
5
|
import { performance } from 'node:perf_hooks';
|
|
7
6
|
import fs from 'fs';
|
|
@@ -45,6 +44,7 @@ import * as outbox from '../aun/outbox.js';
|
|
|
45
44
|
import { aunProtectedHeaders } from '../aun/model-headers.js';
|
|
46
45
|
import { formatSize } from '../utils/media-cache.js';
|
|
47
46
|
import { formatPeerKey, PeerIdentityCache } from '../core/relation/peer-identity.js';
|
|
47
|
+
import { preparePaTeamQualification, registerPaTeamClient, unregisterPaTeamClient } from '../core/relation/pa-team.js';
|
|
48
48
|
import { isHClassPath } from '../core/permission/protected-paths.js';
|
|
49
49
|
import { consumeAunCausation, registerAunCausation } from '../core/causation/aun-association.js';
|
|
50
50
|
import { deriveCausation, normalizeCausation } from '../core/causation/context.js';
|
|
@@ -72,6 +72,8 @@ const OBSERVER_GROUP_MEMBERS_PAGE_SIZE = 200;
|
|
|
72
72
|
const OBSERVER_GROUP_MEMBERS_MAX_PAGES = 100;
|
|
73
73
|
const AUN_SEND_LOG_TEXT_MAX_LENGTH = 60;
|
|
74
74
|
const AUN_MAX_PAYLOAD_SIZE = 512 * 1024;
|
|
75
|
+
/** AUN volatile TTL for online/offline lifecycle notices (gateway cap is 3600s). */
|
|
76
|
+
export const DEFAULT_LIFECYCLE_NOTICE_TTL_SECONDS = 1_800;
|
|
75
77
|
const OWNER_DIRECTORY_ACK_TTL_SECONDS = 30;
|
|
76
78
|
const OWNER_DIRECTORY_RETRY_BASE_MS = 1_000;
|
|
77
79
|
const OWNER_DIRECTORY_RETRY_MAX_MS = 60_000;
|
|
@@ -587,6 +589,22 @@ function sentOutboxResult(messageId) {
|
|
|
587
589
|
? { status: 'sent', messageId }
|
|
588
590
|
: { status: 'permanent', error: 'AUN send completed without a remote message_id', code: 'MISSING_MESSAGE_ID' };
|
|
589
591
|
}
|
|
592
|
+
/**
|
|
593
|
+
* Wire contract for agent online/offline notices. Kept in one place so EvolApp
|
|
594
|
+
* and tests can rely on the same field names.
|
|
595
|
+
*/
|
|
596
|
+
export function buildAunLifecycleNoticePayload(args) {
|
|
597
|
+
const name = args.agentName.trim() || args.selfAid;
|
|
598
|
+
return {
|
|
599
|
+
type: 'notice',
|
|
600
|
+
subtype: args.online ? 'agent.online' : 'agent.offline',
|
|
601
|
+
severity: 'info',
|
|
602
|
+
text: `${name} ${args.online ? '已上线' : '已下线'}`,
|
|
603
|
+
agent_aid: args.selfAid,
|
|
604
|
+
agent_name: name,
|
|
605
|
+
sent_at: args.sentAt ?? Date.now(),
|
|
606
|
+
};
|
|
607
|
+
}
|
|
590
608
|
function setIfDefined(target, key, value) {
|
|
591
609
|
if (value !== undefined)
|
|
592
610
|
target[key] = value;
|
|
@@ -765,7 +783,7 @@ export class AUNChannel {
|
|
|
765
783
|
if (options.targetAid !== target || JSON.stringify(options.request) !== request || Date.now() >= expires) {
|
|
766
784
|
throw Object.assign(new Error('Managed Menu operation changed or expired'), { code: 'CONTACT_DENIED' });
|
|
767
785
|
}
|
|
768
|
-
if (!this.config.pureIdentity
|
|
786
|
+
if (!this.config.pureIdentity
|
|
769
787
|
&& (!binding || !sameContactBinding(binding, currentContactBinding(this.config.aid)))) {
|
|
770
788
|
throw Object.assign(new Error('Managed Menu Owner relation unavailable or changed'), { code: 'CONTACT_OWNERSHIP_UNAVAILABLE' });
|
|
771
789
|
}
|
|
@@ -810,8 +828,7 @@ export class AUNChannel {
|
|
|
810
828
|
// 自动从 data 推断顶层字段(self_aid / peer_aid / group_id / task_id / chatmode),
|
|
811
829
|
// 便于 jq 过滤:`jq 'select(.task_id == "task-xxx")'`
|
|
812
830
|
const inbound = data && typeof data === 'object' ? data : {};
|
|
813
|
-
const isolateTrace = dir === 'IN' && event === 'message.received'
|
|
814
|
-
&& !this.config.pureIdentity && appContactAdmissionEnabled(this.config.aid);
|
|
831
|
+
const isolateTrace = dir === 'IN' && event === 'message.received' && !this.config.pureIdentity;
|
|
815
832
|
const safeData = isolateTrace ? {
|
|
816
833
|
message_id: inbound.message_id, seq: inbound.seq,
|
|
817
834
|
envelope: { from: inbound.envelope?.from, to: inbound.envelope?.to, encrypted: inbound.envelope?.encrypted },
|
|
@@ -856,7 +873,7 @@ export class AUNChannel {
|
|
|
856
873
|
callClient(method, params, lane = 'normal', onStart, onPrepared, beforeSend) {
|
|
857
874
|
params = menuTransportParams(method, params);
|
|
858
875
|
const client = this.client;
|
|
859
|
-
const appOwned = !this.config.pureIdentity
|
|
876
|
+
const appOwned = !this.config.pureIdentity;
|
|
860
877
|
const friendPayload = typeof params.payload?.type === 'string' && params.payload.type.startsWith('friend.');
|
|
861
878
|
const binding = appOwned || friendPayload ? currentContactBinding(this.config.aid) : undefined;
|
|
862
879
|
onPrepared?.(params);
|
|
@@ -1746,10 +1763,8 @@ export class AUNChannel {
|
|
|
1746
1763
|
// Let Core and the SDK reuse valid consensus; explicit authorization/bind operations
|
|
1747
1764
|
// own their fresh checks. Material changes invalidate the SDK cache themselves.
|
|
1748
1765
|
const ownership = await ownerResolver.refresh(selfAid, { allowTransient: true, source: 'directory.runtime' });
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
const ownerAid = ownerResolver.owner(selfAid) ?? ownerResolver.knownOwner(selfAid);
|
|
1752
|
-
logger.info(`${this.logPrefix()} ownerResolver result: selfAid=${selfAid}, ownerAid=${ownerAid || 'undefined'} (protocol=${ownerResolver.owner(selfAid) || 'none'}, known=${ownerResolver.knownOwner(selfAid) || 'none'})`);
|
|
1766
|
+
const ownerAid = ownerResolver.owner(selfAid);
|
|
1767
|
+
logger.info(`${this.logPrefix()} ownerResolver result: selfAid=${selfAid}, ownerAid=${ownerAid || 'undefined'}`);
|
|
1753
1768
|
if (ownership.refreshFailure) {
|
|
1754
1769
|
const code = ownership.refreshFailure.code || 'UNKNOWN';
|
|
1755
1770
|
logger.warn(`${this.logPrefix()} Owner relationship refresh failed: status=${ownership.consensusStatus} code=${code}`);
|
|
@@ -1761,9 +1776,8 @@ export class AUNChannel {
|
|
|
1761
1776
|
logger.debug(`${this.logPrefix()} Owner directory unavailable: owner=${ownerAid ? 'known' : 'unknown'}, connectionChanged=${this.client !== client || !this.connected}`);
|
|
1762
1777
|
return;
|
|
1763
1778
|
}
|
|
1764
|
-
const
|
|
1765
|
-
|
|
1766
|
-
if (appOwned && !relationVersion)
|
|
1779
|
+
const relationVersion = currentContactBinding(selfAid)?.relation_version;
|
|
1780
|
+
if (!relationVersion)
|
|
1767
1781
|
return;
|
|
1768
1782
|
if (this.ownerDirectoryCache?.client !== client || this.ownerDirectoryCache.ownerAid !== ownerAid
|
|
1769
1783
|
|| this.ownerDirectoryRelationVersion !== relationVersion) {
|
|
@@ -1771,7 +1785,7 @@ export class AUNChannel {
|
|
|
1771
1785
|
// the new cache implementation own storage and event synchronization.
|
|
1772
1786
|
const directory = path.join(this.agentDir, 'directory');
|
|
1773
1787
|
const cache = new OwnerDirectoryCache({
|
|
1774
|
-
onSnapshotApplying: snapshot => { if (
|
|
1788
|
+
onSnapshotApplying: snapshot => { if (isCurrent())
|
|
1775
1789
|
reconcileTemporaryContactGrants(selfAid, snapshot); },
|
|
1776
1790
|
relationVersion,
|
|
1777
1791
|
isCurrent: () => isCurrent(),
|
|
@@ -1789,8 +1803,8 @@ export class AUNChannel {
|
|
|
1789
1803
|
});
|
|
1790
1804
|
const isCurrent = () => this.client === client && this.connected
|
|
1791
1805
|
&& this.ownerDirectoryCache?.cache === cache
|
|
1792
|
-
&&
|
|
1793
|
-
&&
|
|
1806
|
+
&& ownerResolver.owner(selfAid) === ownerAid
|
|
1807
|
+
&& currentContactBinding(selfAid)?.relation_version === relationVersion;
|
|
1794
1808
|
const agentMd = new OwnerDirectoryAgentMdSync({
|
|
1795
1809
|
selfAid,
|
|
1796
1810
|
aunPath: this.config.keystorePath || resolveRoot(),
|
|
@@ -1884,7 +1898,7 @@ export class AUNChannel {
|
|
|
1884
1898
|
const view = await ownerResolver.refresh(this.config.aid, { maxAgeMs: 0, source: 'directory.authorization' });
|
|
1885
1899
|
const binding = verifiedContactBinding(this.config.aid, view);
|
|
1886
1900
|
if (!binding || senderAid !== binding.owner_aid || grant.owner_aid !== senderAid || grant.grantee_aid !== this.config.aid
|
|
1887
|
-
||
|
|
1901
|
+
|| grant.relation_version !== binding.relation_version)
|
|
1888
1902
|
return;
|
|
1889
1903
|
const runtime = await this.getOwnerDirectoryRuntime();
|
|
1890
1904
|
if (!runtime)
|
|
@@ -1963,7 +1977,7 @@ export class AUNChannel {
|
|
|
1963
1977
|
const view = await ownerResolver.refresh(selfAid, { maxAgeMs: 0, source: 'directory.grant' });
|
|
1964
1978
|
const binding = verifiedContactBinding(selfAid, view);
|
|
1965
1979
|
if (!binding || senderAid !== binding.owner_aid || parsed.owner_aid !== senderAid || parsed.grantee_aid !== selfAid
|
|
1966
|
-
||
|
|
1980
|
+
|| parsed.relation_version !== binding.relation_version) {
|
|
1967
1981
|
logger.warn(`${this.logPrefix()} owner.directory.grant ignored: sender or relation binding is not verified`);
|
|
1968
1982
|
return;
|
|
1969
1983
|
}
|
|
@@ -1982,7 +1996,7 @@ export class AUNChannel {
|
|
|
1982
1996
|
// 不再等"下一条入站消息"——那条消息可能几小时后才来。
|
|
1983
1997
|
await runtime.cache.handleOwnerChangedEvent(senderAid);
|
|
1984
1998
|
try {
|
|
1985
|
-
await runtime.cache.processPendingIfNeeded();
|
|
1999
|
+
await runtime.cache.processPendingIfNeeded('grant');
|
|
1986
2000
|
await runtime.cache.applyFromSharedCache();
|
|
1987
2001
|
logger.info(`${this.logPrefix()} owner.directory.grant: pulled and applied after authorization (total=${runtime.cache.readSnapshot('contacts')?.total ?? 'none'})`);
|
|
1988
2002
|
}
|
|
@@ -2119,7 +2133,8 @@ export class AUNChannel {
|
|
|
2119
2133
|
}
|
|
2120
2134
|
}
|
|
2121
2135
|
shouldEncrypt(_peerId) {
|
|
2122
|
-
|
|
2136
|
+
// 默认明文:只有显式 --encrypt 或 daemon.json 配置 aun.defaultEncrypt 才加密。
|
|
2137
|
+
return this.config.defaultEncrypt ?? false;
|
|
2123
2138
|
}
|
|
2124
2139
|
/** Effective channel default for callers that must persist a concrete transport choice. */
|
|
2125
2140
|
getDefaultEncrypt() {
|
|
@@ -2337,6 +2352,7 @@ export class AUNChannel {
|
|
|
2337
2352
|
this.observerGroupMemberFetches.clear();
|
|
2338
2353
|
// Clean up existing client if any
|
|
2339
2354
|
if (this.client) {
|
|
2355
|
+
unregisterPaTeamClient(this.config.aid, this.client);
|
|
2340
2356
|
ownerResolver.detachClient(this.config.aid, this.client);
|
|
2341
2357
|
this.trace('OUT', 'client.close', { reason: 'initClient' });
|
|
2342
2358
|
try {
|
|
@@ -2378,6 +2394,7 @@ export class AUNChannel {
|
|
|
2378
2394
|
const localConfig = loadAgent(aidName);
|
|
2379
2395
|
ownerResolver.setAgentConfiguredOwners(aidName, configuredOwnerList(localConfig));
|
|
2380
2396
|
ownerResolver.attachClient(aidName, client);
|
|
2397
|
+
registerPaTeamClient(aidName, client, store);
|
|
2381
2398
|
try {
|
|
2382
2399
|
await this.config.onClientReady?.(client);
|
|
2383
2400
|
}
|
|
@@ -2446,7 +2463,7 @@ export class AUNChannel {
|
|
|
2446
2463
|
if (data && typeof data === 'object') {
|
|
2447
2464
|
const d = data;
|
|
2448
2465
|
const payloadType = d.payload?.type ?? d.envelope?.type ?? '';
|
|
2449
|
-
if (payloadType === 'text' &&
|
|
2466
|
+
if (payloadType === 'text' && this.config.pureIdentity) {
|
|
2450
2467
|
const msgId = d.message_id ?? d.id ?? '';
|
|
2451
2468
|
const from = d.from ?? d.envelope?.from ?? '';
|
|
2452
2469
|
const to = d.to ?? d.envelope?.to ?? this.config.aid ?? '';
|
|
@@ -3201,22 +3218,13 @@ export class AUNChannel {
|
|
|
3201
3218
|
}
|
|
3202
3219
|
}
|
|
3203
3220
|
/**
|
|
3204
|
-
*
|
|
3205
|
-
* versioned Owner snapshot; legacy agents by deniedAids / allowedAids / allowAllContacts / directory tiers.
|
|
3221
|
+
* Friend invites use the same app-v1 decision as ordinary private messages.
|
|
3206
3222
|
*/
|
|
3207
3223
|
async judgeFriendInvite(selfAid, applicantAid) {
|
|
3208
|
-
|
|
3209
|
-
const decision = evaluateAppContactAdmission(selfAid, applicantAid);
|
|
3210
|
-
if (decision.allow)
|
|
3211
|
-
return { kind: decision.reason === 'temporary' ? 'owner' : 'accept', reason: decision.reason };
|
|
3212
|
-
return { kind: decision.reason === 'blocked' || decision.reason === 'unavailable' ? 'silent' : 'owner', reason: decision.reason };
|
|
3213
|
-
}
|
|
3214
|
-
const decision = await evaluateOutboundContactAdmission({ selfAid, targetAid: applicantAid });
|
|
3224
|
+
const decision = evaluateAppContactAdmission(selfAid, applicantAid);
|
|
3215
3225
|
if (decision.allow)
|
|
3216
|
-
return { kind: decision.
|
|
3217
|
-
|
|
3218
|
-
|| decision.code === 'CONTACT_DIRECTORY_UNAVAILABLE' || decision.code === 'CONTACT_POLICY_INVALID';
|
|
3219
|
-
return { kind: silent ? 'silent' : 'owner', reason: decision.code };
|
|
3226
|
+
return { kind: decision.reason === 'temporary' ? 'owner' : 'accept', reason: decision.reason };
|
|
3227
|
+
return { kind: decision.reason === 'blocked' || decision.reason === 'unavailable' ? 'silent' : 'owner', reason: decision.reason };
|
|
3220
3228
|
}
|
|
3221
3229
|
async sendFriendInviteResult(invite, decision, inboundMessageId) {
|
|
3222
3230
|
const result = buildFriendInviteResult(this.config.aid, invite, decision);
|
|
@@ -3264,16 +3272,7 @@ export class AUNChannel {
|
|
|
3264
3272
|
}
|
|
3265
3273
|
return;
|
|
3266
3274
|
}
|
|
3267
|
-
const appOwned = !this.config.pureIdentity
|
|
3268
|
-
if (!appOwned && !this.config.pureIdentity) {
|
|
3269
|
-
try {
|
|
3270
|
-
if (isolatedContactSource(this.config.aid, fromAid, messageId))
|
|
3271
|
-
return;
|
|
3272
|
-
}
|
|
3273
|
-
catch {
|
|
3274
|
-
return;
|
|
3275
|
-
}
|
|
3276
|
-
}
|
|
3275
|
+
const appOwned = !this.config.pureIdentity;
|
|
3277
3276
|
if (!appOwned && !this.claimInboundMessage('private', messageId, seq))
|
|
3278
3277
|
return;
|
|
3279
3278
|
const protectedHeaders = verifiedProtectedHeaders(msg, env);
|
|
@@ -3403,6 +3402,7 @@ export class AUNChannel {
|
|
|
3403
3402
|
// 解析对端身份(30天缓存)
|
|
3404
3403
|
const selfAgentDir = path.join(resolvePaths().agentsDir, this.config.aid);
|
|
3405
3404
|
const peerIdentity = await PeerIdentityCache.resolve('aun', fromAid, selfAgentDir, this.store, false, this.config.keystorePath || resolveRoot());
|
|
3405
|
+
await preparePaTeamQualification(this.config.aid, fromAid);
|
|
3406
3406
|
const shortAid = this.getShortAid(fromAid);
|
|
3407
3407
|
const displayName = peerIdentity.name || shortAid;
|
|
3408
3408
|
// 详细 dispatch 决策日志:记录消息为何被路由到 agent
|
|
@@ -4744,6 +4744,7 @@ export class AUNChannel {
|
|
|
4744
4744
|
}
|
|
4745
4745
|
// Force close SDK client,中断它内部的重连循环
|
|
4746
4746
|
if (this.client) {
|
|
4747
|
+
unregisterPaTeamClient(this.config.aid, this.client);
|
|
4747
4748
|
ownerResolver.detachClient(this.config.aid, this.client);
|
|
4748
4749
|
this.trace('OUT', 'client.close', { reason: `takeover_${reason}` });
|
|
4749
4750
|
this.client.close().catch(() => { });
|
|
@@ -4770,6 +4771,7 @@ export class AUNChannel {
|
|
|
4770
4771
|
logger.debug(`${this.logPrefix()} TS-layer reconnect (${reason}) succeeded but generation stale, closing stale client`);
|
|
4771
4772
|
this.stopOwnerDirectoryRefresh();
|
|
4772
4773
|
if (this.client) {
|
|
4774
|
+
unregisterPaTeamClient(this.config.aid, this.client);
|
|
4773
4775
|
ownerResolver.detachClient(this.config.aid, this.client);
|
|
4774
4776
|
this.client.close().catch(() => { });
|
|
4775
4777
|
this.client = null;
|
|
@@ -5282,10 +5284,13 @@ export class AUNChannel {
|
|
|
5282
5284
|
}
|
|
5283
5285
|
}
|
|
5284
5286
|
appContactOutboundBlock(channelId, delivery, payload, params) {
|
|
5285
|
-
if (delivery.chatType === 'group' || this.config.pureIdentity
|
|
5287
|
+
if (delivery.chatType === 'group' || this.config.pureIdentity
|
|
5286
5288
|
|| this.hasContactControlPermit(channelId, payload, params))
|
|
5287
5289
|
return undefined;
|
|
5288
5290
|
const decision = evaluateAppContactAdmission(this.config.aid, channelId);
|
|
5291
|
+
if (params?.encrypt === true && params?.rawPayload === true && parseFriendInvite(payload, this.config.aid, channelId)
|
|
5292
|
+
&& decision.reason === 'not_in_contacts')
|
|
5293
|
+
return undefined;
|
|
5289
5294
|
if (decision.allow)
|
|
5290
5295
|
return undefined;
|
|
5291
5296
|
return { status: decision.reason === 'unavailable' ? 'retry' : 'permanent',
|
|
@@ -5805,7 +5810,7 @@ export class AUNChannel {
|
|
|
5805
5810
|
async requestOutboundContact(args) {
|
|
5806
5811
|
const selfAid = this.config.aid;
|
|
5807
5812
|
const binding = currentContactBinding(selfAid);
|
|
5808
|
-
if (!
|
|
5813
|
+
if (!binding) {
|
|
5809
5814
|
return { ok: false, code: 'CONTACT_DIRECTORY_UNAVAILABLE', error: '本端 Owner 关系不可用,未发送申请或原消息' };
|
|
5810
5815
|
}
|
|
5811
5816
|
const decision = evaluateAppContactAdmission(selfAid, args.to);
|
|
@@ -5886,7 +5891,7 @@ export class AUNChannel {
|
|
|
5886
5891
|
code: 'INVALID_REQUEST_TTL',
|
|
5887
5892
|
};
|
|
5888
5893
|
}
|
|
5889
|
-
const contactBlock = this.appContactOutboundBlock(args.to, { chatType: 'private' }, finalPayload);
|
|
5894
|
+
const contactBlock = this.appContactOutboundBlock(args.to, { chatType: 'private' }, finalPayload, { encrypt: args.encrypt, rawPayload: preserveRawPayload });
|
|
5890
5895
|
if (contactBlock)
|
|
5891
5896
|
return { ok: false, code: contactBlock.code, error: contactBlock.error };
|
|
5892
5897
|
if (preserveRawPayload && jsonUtf8Size(finalPayload) > AUN_MAX_PAYLOAD_SIZE) {
|
|
@@ -5906,6 +5911,7 @@ export class AUNChannel {
|
|
|
5906
5911
|
let peerRole = null;
|
|
5907
5912
|
try {
|
|
5908
5913
|
const { resolvePeerRoleDetail } = await import('../config/peer-role-resolver.js');
|
|
5914
|
+
await preparePaTeamQualification(this.config.aid, args.to);
|
|
5909
5915
|
peerRole = resolvePeerRoleDetail({
|
|
5910
5916
|
selfAid: this.config.aid,
|
|
5911
5917
|
channelKey: `aun#${this.config.aid}#main`,
|
|
@@ -6012,6 +6018,29 @@ export class AUNChannel {
|
|
|
6012
6018
|
};
|
|
6013
6019
|
}
|
|
6014
6020
|
}
|
|
6021
|
+
/**
|
|
6022
|
+
* Send an online/offline system notice to the bound Owner as an AUN volatile
|
|
6023
|
+
* message: nothing is persisted in the outbox or the local message log, and
|
|
6024
|
+
* the gateway drops it after the TTL. Best-effort by design.
|
|
6025
|
+
*/
|
|
6026
|
+
async sendLifecycleNotice(args) {
|
|
6027
|
+
const requested = Math.trunc(args.ttlSeconds ?? DEFAULT_LIFECYCLE_NOTICE_TTL_SECONDS);
|
|
6028
|
+
const ttl = Number.isFinite(requested)
|
|
6029
|
+
? Math.min(MAX_AUN_VOLATILE_TTL_SECONDS, Math.max(1, requested))
|
|
6030
|
+
: DEFAULT_LIFECYCLE_NOTICE_TTL_SECONDS;
|
|
6031
|
+
return this.sendDaemonMsg({
|
|
6032
|
+
to: args.to,
|
|
6033
|
+
payload: buildAunLifecycleNoticePayload({
|
|
6034
|
+
selfAid: this.getAid() || this.config.aid,
|
|
6035
|
+
agentName: args.agentName,
|
|
6036
|
+
online: args.online,
|
|
6037
|
+
sentAt: args.now?.() ?? Date.now(),
|
|
6038
|
+
}),
|
|
6039
|
+
// Preserve the notice verbatim: no session state, topic name or mentions.
|
|
6040
|
+
rawPayload: true,
|
|
6041
|
+
ttl,
|
|
6042
|
+
});
|
|
6043
|
+
}
|
|
6015
6044
|
/** Public contracts use this AID's existing authenticated storage connection. */
|
|
6016
6045
|
get abilityPublisherAid() { return this._aid || this.config.aid; }
|
|
6017
6046
|
async publishAbilityDocuments(documents, expectedIndexes = []) {
|
|
@@ -6723,7 +6752,6 @@ export class AUNChannel {
|
|
|
6723
6752
|
if (delivery.chatType === 'group') {
|
|
6724
6753
|
logger.info(`${this.logPrefix()} thought.put ok group=${targetId} task=${taskId} stage=${stage} encrypt=${encrypt} tid=${tid ?? '?'}`);
|
|
6725
6754
|
this.eventBus?.publish?.({ type: 'message:thought-put', agentName: this.config.aid, channelId, taskId, text: thoughtText });
|
|
6726
|
-
this.forwardOutbound(putRes);
|
|
6727
6755
|
if (thoughtText) {
|
|
6728
6756
|
const statsContext = await this.groupStatsContext(channelId);
|
|
6729
6757
|
this.aidStatsCollector?.recordOutbound(this.config.aid, channelId, Buffer.byteLength(thoughtText, 'utf-8'), thoughtText, false, encrypt, context?.metadata?.chatmode ?? 'proactive', 'thought', statsContext);
|
|
@@ -6732,7 +6760,6 @@ export class AUNChannel {
|
|
|
6732
6760
|
else {
|
|
6733
6761
|
logger.info(`${this.logPrefix()} thought.put ok p2p=${this.peerLabel(targetId)} task=${taskId} stage=${stage} encrypt=${encrypt} tid=${tid ?? '?'}`);
|
|
6734
6762
|
this.eventBus?.publish?.({ type: 'message:thought-put', agentName: this.config.aid, channelId, taskId, text: thoughtText });
|
|
6735
|
-
this.forwardOutbound(putRes);
|
|
6736
6763
|
if (thoughtText) {
|
|
6737
6764
|
this.aidStatsCollector?.recordOutbound(this.config.aid, targetId, Buffer.byteLength(thoughtText, 'utf-8'), thoughtText, false, encrypt, context?.metadata?.chatmode ?? 'proactive', 'thought');
|
|
6738
6765
|
}
|
|
@@ -7450,11 +7477,19 @@ export class AUNChannel {
|
|
|
7450
7477
|
}
|
|
7451
7478
|
await this.sendStructuredOrThrow(channelId, payloadObj, context);
|
|
7452
7479
|
}
|
|
7453
|
-
|
|
7480
|
+
/**
|
|
7481
|
+
* `clientCloseBudgetMs` 只给退出路径用:SDK 的 `close()` 要等 WebSocket 关闭握手
|
|
7482
|
+
* (`transport.js` 里 `ws.on('close')` 后面挂了 3s 兜底),正常也要 2.4s 才返回。
|
|
7483
|
+
* daemon 马上 `exit(0)`,握手等不完的 socket 会随进程消失,为此等满没有意义——
|
|
7484
|
+
* 传入预算时到点就往下走,不再等 SDK。
|
|
7485
|
+
*/
|
|
7486
|
+
async disconnect(clientCloseBudgetMs) {
|
|
7454
7487
|
this.stopOwnerDirectoryRefresh();
|
|
7455
7488
|
this.configuredOwnerBindEpoch++;
|
|
7456
|
-
if (this.client)
|
|
7489
|
+
if (this.client) {
|
|
7490
|
+
unregisterPaTeamClient(this.config.aid, this.client);
|
|
7457
7491
|
ownerResolver.detachClient(this.config.aid, this.client);
|
|
7492
|
+
}
|
|
7458
7493
|
this.managedMenuClient.close();
|
|
7459
7494
|
this.intentionalDisconnect = true;
|
|
7460
7495
|
if (this.reconnectTimer) {
|
|
@@ -7463,8 +7498,25 @@ export class AUNChannel {
|
|
|
7463
7498
|
}
|
|
7464
7499
|
if (this.client) {
|
|
7465
7500
|
this.trace('OUT', 'client.close', { reason: 'disconnect' });
|
|
7501
|
+
// 未等到 close 的 promise 可能稍后 reject(握手被进程退出截断),全程吞掉以免 unhandledRejection。
|
|
7502
|
+
const closing = this.client.close().catch(() => { });
|
|
7466
7503
|
try {
|
|
7467
|
-
|
|
7504
|
+
if (clientCloseBudgetMs === undefined) {
|
|
7505
|
+
await closing;
|
|
7506
|
+
}
|
|
7507
|
+
else {
|
|
7508
|
+
let timer;
|
|
7509
|
+
try {
|
|
7510
|
+
await Promise.race([
|
|
7511
|
+
closing,
|
|
7512
|
+
new Promise(resolve => { timer = setTimeout(resolve, clientCloseBudgetMs); }),
|
|
7513
|
+
]);
|
|
7514
|
+
}
|
|
7515
|
+
finally {
|
|
7516
|
+
if (timer)
|
|
7517
|
+
clearTimeout(timer);
|
|
7518
|
+
}
|
|
7519
|
+
}
|
|
7468
7520
|
this.trace('OUT', 'client.close.ok', { reason: 'disconnect' });
|
|
7469
7521
|
}
|
|
7470
7522
|
catch (e) {
|
|
@@ -8186,7 +8238,7 @@ export class AUNChannelPlugin {
|
|
|
8186
8238
|
policy,
|
|
8187
8239
|
options: { flushDelay: inst.flushDelay ?? DEFAULT_FLUSH_DELAY_SECONDS, fileMarkerPattern: createSendFileMarkerPattern() },
|
|
8188
8240
|
connect: () => channel.connect(),
|
|
8189
|
-
disconnect: () => channel.disconnect(),
|
|
8241
|
+
disconnect: (clientCloseBudgetMs) => channel.disconnect(clientCloseBudgetMs),
|
|
8190
8242
|
onProjectPathRequest: () => Promise.resolve(ctx.defaultProjectPath),
|
|
8191
8243
|
registerBridge(bridge, channelType) {
|
|
8192
8244
|
bridge.register(adapter.channelName, (handler) => channel.onMessage(async (opts) => {
|
package/dist/channels/daemon.js
CHANGED
|
@@ -3,6 +3,7 @@ import { ExecutionTimeoutError } from '../utils/error-utils.js';
|
|
|
3
3
|
import { logger } from '../utils/logger.js';
|
|
4
4
|
import { normalizeExecutionMode } from '../trigger/validation.js';
|
|
5
5
|
import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
|
|
6
|
+
import { preparePaTeamQualification } from '../core/relation/pa-team.js';
|
|
6
7
|
import { assertSystemSessionLaunchable } from '../core/system-session/registry.js';
|
|
7
8
|
import { sessionTopicThreadId } from '../core/thread/topic-id.js';
|
|
8
9
|
const DEFAULT_WATCHDOG_MS = 11 * 60 * 1000;
|
|
@@ -146,6 +147,9 @@ export class DaemonChannel {
|
|
|
146
147
|
}
|
|
147
148
|
if (ctx.signal?.aborted)
|
|
148
149
|
onAbort();
|
|
150
|
+
if (message.triggerMeta?.originChannelType === 'aun' && message.triggerMeta.originChatType !== 'group') {
|
|
151
|
+
await preparePaTeamQualification(ctx.trigger.agentAid, message.triggerMeta.originPeerId);
|
|
152
|
+
}
|
|
149
153
|
if (!slot?.terminalClaim) {
|
|
150
154
|
void this.messageQueue.enqueue(ctx.session.id, message, ctx.projectPath, {
|
|
151
155
|
interruptible: false,
|
|
@@ -288,7 +292,7 @@ export class DaemonChannel {
|
|
|
288
292
|
// 反馈目标与触发方式(consolidation.ts 在 normalize 后补挂的字段):
|
|
289
293
|
// 收尾时据此投递反馈,并判断是否该反馈(定时触发不反馈)。
|
|
290
294
|
const { feedbackOrigin, consolidationTriggeredBy } = trigger.execution;
|
|
291
|
-
|
|
295
|
+
const metadata = {
|
|
292
296
|
channelKey: this.channelKey,
|
|
293
297
|
peerId: `trigger:${trigger.id}`,
|
|
294
298
|
peerName: trigger.name,
|
|
@@ -299,7 +303,15 @@ export class DaemonChannel {
|
|
|
299
303
|
...(consolidationMemoryDir ? { consolidationMemoryDir } : {}),
|
|
300
304
|
...(feedbackOrigin ? { feedbackOrigin } : {}),
|
|
301
305
|
...(consolidationTriggeredBy ? { consolidationTriggeredBy } : {}),
|
|
302
|
-
}
|
|
306
|
+
};
|
|
307
|
+
const session = await this.sessionManager.getOrCreateSession(this.channelName, channelId, projectPath, threadId, metadata, trigger.name, undefined, 'private', baseagent, trigger.agentAid, this.channelName, 'system');
|
|
308
|
+
if (session.baseagent === baseagent)
|
|
309
|
+
return session;
|
|
310
|
+
const inheritedSession = await this.sessionManager.getOrCreateSession(this.channelName, channelId, projectPath, `${threadId}:baseagent:${baseagent}`, metadata, trigger.name, undefined, 'private', baseagent, trigger.agentAid, this.channelName, 'system');
|
|
311
|
+
if (inheritedSession.baseagent !== baseagent) {
|
|
312
|
+
throw new Error(`Trigger session baseagent mismatch: expected ${baseagent}, got ${inheritedSession.baseagent}`);
|
|
313
|
+
}
|
|
314
|
+
return inheritedSession;
|
|
303
315
|
}
|
|
304
316
|
executionDeadlineAt(startedAt = Date.now()) {
|
|
305
317
|
return this.totalExecutionMs === undefined
|
|
@@ -82,6 +82,7 @@ function printAgentNewHelp() {
|
|
|
82
82
|
--project <path> 默认: 当前目录
|
|
83
83
|
--baseagent <claude|codex|gemini|ecagent>
|
|
84
84
|
默认: defaults 配置,否则检测本机可用基座
|
|
85
|
+
--provider <id> 指定该 Base Agent 使用的 Provider
|
|
85
86
|
--model <id> 初始化可选;须在主机当前基座的可见模型目录中
|
|
86
87
|
--effort <level> 初始化可选;需同时指定 model,auto 使用默认强度
|
|
87
88
|
--owner <aid> 必填;初始协议 Owner 绑定意图
|
|
@@ -381,6 +382,7 @@ Options:
|
|
|
381
382
|
aid: name,
|
|
382
383
|
project: getArg('--project'),
|
|
383
384
|
baseagent: getArg('--baseagent'),
|
|
385
|
+
provider: getArg('--provider'),
|
|
384
386
|
...ownerOptions,
|
|
385
387
|
...avatarOptions,
|
|
386
388
|
name: getArg('--name'),
|
|
@@ -411,6 +413,8 @@ Options:
|
|
|
411
413
|
console.log(` AID: ${plan.aid}`);
|
|
412
414
|
console.log(` Project: ${plan.project}`);
|
|
413
415
|
console.log(` Baseagent: ${plan.baseagent} (${plan.baseagentSource})`);
|
|
416
|
+
if (plan.provider)
|
|
417
|
+
console.log(` Provider: ${plan.provider}`);
|
|
414
418
|
console.log(` Owner: ${plan.owner || '未设置'} (${plan.ownerSource})`);
|
|
415
419
|
console.log(` Name: ${plan.name} (${plan.nameSource})`);
|
|
416
420
|
if (plan.description)
|
|
@@ -422,6 +426,7 @@ Options:
|
|
|
422
426
|
const result = await agentCreateNonInteractive({
|
|
423
427
|
aid: plan.aid,
|
|
424
428
|
baseagent: plan.baseagent,
|
|
429
|
+
provider: plan.provider,
|
|
425
430
|
project: plan.project,
|
|
426
431
|
owner: plan.owner,
|
|
427
432
|
name: plan.name,
|