evolcore 0.0.43-test.4 → 0.0.43-test.6
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 +93 -0
- package/bin/ecmsg.js +437 -91
- package/dist/agents/baseagent-availability.js +19 -4
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +14 -3
- package/dist/agents/codex-runner.js +18 -23
- package/dist/aun/aid/agentmd.js +25 -0
- package/dist/aun/aid/control-aid.js +15 -0
- package/dist/aun/aid/identity.js +8 -0
- package/dist/aun/aid/ownership-operation.js +12 -3
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +99 -23
- package/dist/channels/daemon.js +2 -2
- package/dist/cli/agent-create.js +19 -7
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +19 -4
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +42 -4
- package/dist/cli/directory.js +3 -1
- package/dist/cli/ecmsg-gateway.js +206 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +120 -13
- package/dist/cli/provider-command.js +82 -5
- package/dist/cli/restart-monitor.js +35 -24
- package/dist/cli/stats.js +8 -1
- package/dist/cli/task-context.js +41 -1
- package/dist/cli/watch-logs.js +6 -4
- package/dist/config/boot-log.js +16 -3
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-manager.js +5 -14
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +6 -6
- package/dist/config/provider-identity-migration.js +277 -0
- package/dist/config/provider-identity.js +37 -0
- package/dist/config/provider-ipc-service.js +40 -3
- package/dist/config/provider-local-sync.js +155 -0
- package/dist/config/providers-config.js +45 -4
- package/dist/config/providers-management.js +242 -76
- package/dist/config/providers.js +4 -1
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +143 -86
- package/dist/config/snapshot.js +70 -41
- package/dist/core/agent-runtime.js +48 -9
- package/dist/core/auth/auth-gateway.js +5 -3
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +3 -1
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/baseagent-loader.js +114 -11
- package/dist/core/channel-loader.js +36 -13
- package/dist/core/channel-runtime.js +112 -42
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +16 -11
- package/dist/core/command/menu-handler.js +8 -3
- package/dist/core/command/menu-protocol.js +80 -7
- package/dist/core/command/provider-menu.js +4 -2
- package/dist/core/command/role-menu.js +29 -17
- package/dist/core/command/slash-handler.js +52 -16
- package/dist/core/daemon-control.js +42 -15
- package/dist/core/daemon-lifecycle.js +411 -67
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +139 -45
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +7 -6
- package/dist/core/ipc-registration.js +5 -4
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/message/aun-ipc-sender.js +83 -5
- package/dist/core/message/message-admission.js +2 -0
- package/dist/core/message/message-bridge.js +53 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +33 -25
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +320 -0
- package/dist/core/ownership/owner-resolver.js +112 -8
- package/dist/core/permission/ec-command-parser.js +159 -16
- package/dist/core/permission/readonly-shell-query.js +66 -7
- package/dist/core/permission/tool-error-code.js +13 -1
- package/dist/core/permission/tool-policy.js +74 -20
- package/dist/core/relation/same-owner-proof.js +131 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-fs-store.js +164 -3
- package/dist/core/session/session-idle-monitor.js +103 -17
- package/dist/core/session/session-manager.js +105 -18
- package/dist/core/thread/thread-route.js +5 -2
- package/dist/directory/owner-directory-admission.js +26 -1
- package/dist/directory/owner-directory-cache.js +739 -109
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +6 -3
- package/dist/directory/owner-directory-scope.js +12 -0
- package/dist/directory/owner-directory-search.js +5 -1
- package/dist/directory/owner-directory-store.js +28 -0
- package/dist/ecweb/basic-settings-service.js +15 -1
- package/dist/ecweb/message-context-service.js +2 -2
- package/dist/ecweb/providers-service.js +3 -1
- package/dist/ecweb/runtime/lifecycle.js +26 -15
- package/dist/ecweb/runtime/supervisor.js +120 -51
- package/dist/index.js +551 -250
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +40 -17
- package/dist/proxy/service-supervisor.js +67 -33
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +4 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +81 -8
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +188 -12
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +64 -1
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/startup-trace.js +160 -19
- package/dist/utils/windows-autostart.js +41 -7
- package/ecagent/dist/harness/env/nodejs.js +46 -2
- package/kits/docs/aun/ABILITY_CALLING.md +6 -6
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/channels/feishu.md +2 -2
- package/kits/docs/context-assembly.md +20 -4
- package/kits/docs/evolcore/INDEX.md +5 -3
- package/kits/docs/evolcore/agent.md +2 -2
- package/kits/docs/evolcore/aid.md +8 -2
- package/kits/docs/evolcore/ctl.md +15 -5
- package/kits/docs/evolcore/directory.md +48 -15
- package/kits/docs/evolcore/group.md +8 -8
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +32 -3
- package/kits/docs/evolcore/msg.md +38 -30
- package/kits/docs/evolcore/provider.md +57 -5
- package/kits/docs/evolcore/response.md +2 -2
- package/kits/docs/evolcore/thread-chain.md +11 -13
- package/kits/docs/evolcore/tool-authorization.md +17 -0
- package/kits/docs/evolcore/trigger.md +2 -2
- package/kits/docs/identity/ROLE_DETAIL.md +1 -1
- package/kits/docs/prompt-loading-architecture.md +30 -20
- package/kits/eck_manifest.auxiliary.json +5 -5
- package/kits/eck_manifest.json +44 -32
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/01-overview.md +1 -1
- package/kits/rules/06-channel.md +7 -8
- package/kits/schemas/_meta.json +7 -1
- package/kits/schemas/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/providers.schema.2.json +74 -0
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- package/kits/skills/aid-ability/SKILL.md +7 -7
- package/kits/skills/ec-agent-create/SKILL.md +1 -0
- package/kits/skills/ec-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +3 -10
- package/kits/skills/ec-trigger/SKILL.md +9 -9
- package/kits/skills/ec-trigger/references/examples.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +5 -5
- package/kits/templates/system-fragments/commands.md +7 -6
- package/kits/templates/system-fragments/directory-contacts.md +10 -3
- package/kits/templates/system-fragments/personal-assistant.md +22 -3
- package/kits/templates/system-fragments/reply.md +48 -28
- package/kits/templates/system-fragments/session.md +3 -10
- package/kits/templates/system-fragments/thread.md +5 -5
- package/package.json +4 -4
|
@@ -43,6 +43,13 @@ export function showActivitiesPolicy(mode, chatType, _identity) {
|
|
|
43
43
|
export class ChannelLoader {
|
|
44
44
|
processDebug;
|
|
45
45
|
aunDefaultEncrypt;
|
|
46
|
+
connectionAdmission;
|
|
47
|
+
setConnectionAdmission(admit) {
|
|
48
|
+
this.connectionAdmission = admit;
|
|
49
|
+
}
|
|
50
|
+
connectInstance(instance) {
|
|
51
|
+
return this.connectionAdmission ? this.connectionAdmission(instance) : instance.connect();
|
|
52
|
+
}
|
|
46
53
|
plugins = new Map();
|
|
47
54
|
providerStatuses = new Map();
|
|
48
55
|
instanceStatuses = new Map();
|
|
@@ -141,15 +148,12 @@ export class ChannelLoader {
|
|
|
141
148
|
* AUN is always created implicitly from agent.aid (no explicit entry required).
|
|
142
149
|
*/
|
|
143
150
|
async createForAgent(agent) {
|
|
151
|
+
const aun = await this.createAunForAgent(agent);
|
|
152
|
+
const external = await this.createExternalForAgent(agent);
|
|
153
|
+
return [...aun, ...external];
|
|
154
|
+
}
|
|
155
|
+
async createAunForAgent(agent) {
|
|
144
156
|
assertAgentAidAvailable(agent.aid);
|
|
145
|
-
const ctx = {
|
|
146
|
-
agentName: agent.aid,
|
|
147
|
-
defaultProjectPath: agent.config.projects?.defaultPath ?? process.cwd(),
|
|
148
|
-
debug: this.processDebug,
|
|
149
|
-
aunDefaultEncrypt: this.aunDefaultEncrypt,
|
|
150
|
-
};
|
|
151
|
-
// Build the full list of config instances to create.
|
|
152
|
-
// AUN is synthesised from agent.aid; any explicit aun entry in channels[] is skipped.
|
|
153
157
|
const aunEffName = agent.effectiveChannelName('aun', 'main');
|
|
154
158
|
const aunInst = {
|
|
155
159
|
type: 'aun',
|
|
@@ -158,14 +162,26 @@ export class ChannelLoader {
|
|
|
158
162
|
enabled: true,
|
|
159
163
|
keystorePath: agent.config.aun?.keystorePath,
|
|
160
164
|
};
|
|
161
|
-
|
|
165
|
+
return this._buildInstances([aunInst], this.buildContext(agent));
|
|
166
|
+
}
|
|
167
|
+
async createExternalForAgent(agent) {
|
|
168
|
+
assertAgentAidAvailable(agent.aid);
|
|
169
|
+
const configInsts = [];
|
|
162
170
|
for (const inst of agent.config.channels) {
|
|
163
171
|
if (inst.type === 'aun')
|
|
164
172
|
continue;
|
|
165
173
|
const effName = agent.effectiveChannelName(inst.type, inst.name);
|
|
166
174
|
configInsts.push({ ...inst, name: effName });
|
|
167
175
|
}
|
|
168
|
-
return this._buildInstances(configInsts,
|
|
176
|
+
return this._buildInstances(configInsts, this.buildContext(agent));
|
|
177
|
+
}
|
|
178
|
+
buildContext(agent) {
|
|
179
|
+
return {
|
|
180
|
+
agentName: agent.aid,
|
|
181
|
+
defaultProjectPath: agent.config.projects?.defaultPath ?? process.cwd(),
|
|
182
|
+
debug: this.processDebug,
|
|
183
|
+
aunDefaultEncrypt: this.aunDefaultEncrypt,
|
|
184
|
+
};
|
|
169
185
|
}
|
|
170
186
|
/** Build runtime instances for a list of config instances + context. */
|
|
171
187
|
async _buildInstances(configInsts, ctx) {
|
|
@@ -278,7 +294,7 @@ export class ChannelLoader {
|
|
|
278
294
|
throw error;
|
|
279
295
|
}
|
|
280
296
|
}
|
|
281
|
-
async connectAll(instances, { concurrency = 3, intervalMs = 50, beforeConnect, shouldConnect, onConnected, onFailed } = {}) {
|
|
297
|
+
async connectAll(instances, { concurrency = 3, intervalMs = 50, beforeConnect, shouldConnect, onConnected, onFailed, connect } = {}) {
|
|
282
298
|
const connected = [];
|
|
283
299
|
const failed = [];
|
|
284
300
|
const inflight = new Set();
|
|
@@ -294,7 +310,9 @@ export class ChannelLoader {
|
|
|
294
310
|
const startConnection = (inst) => {
|
|
295
311
|
const task = (async () => {
|
|
296
312
|
try {
|
|
297
|
-
await inst.
|
|
313
|
+
const started = await (connect ? connect(inst) : this.connectInstance(inst));
|
|
314
|
+
if (started === false || inst.lifecycle?.signal.aborted || shouldConnect?.(inst) === false)
|
|
315
|
+
return;
|
|
298
316
|
connected.push(inst.adapter.channelName);
|
|
299
317
|
if (onConnected) {
|
|
300
318
|
void Promise.resolve().then(() => onConnected(inst)).catch(callbackErr => {
|
|
@@ -538,7 +556,12 @@ export function buildReloadHooks(deps) {
|
|
|
538
556
|
try {
|
|
539
557
|
registerChannelInstance(newInst);
|
|
540
558
|
onChannelStarted?.(newInst);
|
|
541
|
-
await
|
|
559
|
+
const started = await channelLoader.connectInstance(newInst);
|
|
560
|
+
if (started === false) {
|
|
561
|
+
await newInst.disconnect();
|
|
562
|
+
unregisterChannelInstance?.(channelName);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
542
565
|
channelInstances.push(newInst);
|
|
543
566
|
await onChannelConnected?.(newInst);
|
|
544
567
|
logger.info(`[Reload] Started channel: ${channelName}`);
|
|
@@ -16,6 +16,7 @@ import { isManagementRole } from '../config/builtin-roles.js';
|
|
|
16
16
|
import { pendingInterruptHints } from './message/pending-hints.js';
|
|
17
17
|
import { logger } from '../utils/logger.js';
|
|
18
18
|
import { sessionLocalTopicId } from './thread/topic-id.js';
|
|
19
|
+
import { StartupTaskQueue } from './daemon-lifecycle.js';
|
|
19
20
|
export function createAgentStorageClientResolver(channelInstances) {
|
|
20
21
|
return (channelKey, targetAid) => {
|
|
21
22
|
const instance = channelInstances.find(candidate => candidate.channelType === 'aun'
|
|
@@ -61,58 +62,133 @@ export function preloadChannelThreads(channelInstances, sessionManager) {
|
|
|
61
62
|
}
|
|
62
63
|
export function createChannelConnectionRuntime(dependencies) {
|
|
63
64
|
const { channelInstances, connectedChannels } = dependencies;
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.
|
|
65
|
+
const followups = new StartupTaskQueue();
|
|
66
|
+
const connections = new Map();
|
|
67
|
+
const subscriptions = new Map();
|
|
68
|
+
const queuePendingObserverHints = async (aid, channelKey) => {
|
|
69
|
+
const pending = await pendingInterruptHints(dependencies.sessionsDir, aid, channelKey);
|
|
70
|
+
if (dependencies.isCancelled?.())
|
|
71
|
+
return;
|
|
72
|
+
const results = await Promise.allSettled(pending.map(pending => dependencies.responseEngine.scheduleObserverHint({ ...pending, selfAid: aid })
|
|
73
|
+
.then(result => {
|
|
74
|
+
if (result === 'SESSION_NOT_FOUND')
|
|
75
|
+
logger.warn(`[ObserverHint] recovery target missing hint=${pending.hintId}`);
|
|
76
|
+
})
|
|
77
|
+
.catch(error => {
|
|
78
|
+
logger.warn(`[ObserverHint] recovery failed hint=${pending.hintId}: ${error}`);
|
|
79
|
+
throw error;
|
|
80
|
+
})));
|
|
81
|
+
const failure = results.find(result => result.status === 'rejected');
|
|
82
|
+
if (failure?.status === 'rejected')
|
|
83
|
+
throw failure.reason;
|
|
84
|
+
};
|
|
72
85
|
const markChannelConnected = async (instance) => {
|
|
73
86
|
const name = instance.adapter.channelName;
|
|
74
87
|
const key = instance.adapter.channelKey;
|
|
75
|
-
if (
|
|
88
|
+
if (dependencies.isCancelled?.() || !channelInstances.includes(instance)
|
|
89
|
+
|| instance.lifecycle?.signal.aborted || instance.channel.getStatus?.().connected === false)
|
|
90
|
+
return;
|
|
91
|
+
if (connections.get(key)?.instance === instance)
|
|
76
92
|
return;
|
|
93
|
+
const connection = { instance };
|
|
94
|
+
connections.set(key, connection);
|
|
77
95
|
connectedChannels.add(name);
|
|
78
96
|
connectedChannels.add(key);
|
|
79
97
|
const type = instance.channelType || name;
|
|
80
98
|
dependencies.eventBus.publish({ type: 'channel:connected', channel: type.toLowerCase(), channelName: name, timestamp: Date.now() });
|
|
81
99
|
const agent = dependencies.resolveOwningAgent(key, name);
|
|
100
|
+
if (instance.channelType === 'aun' && agent && !dependencies.isStartupRecoveryPending()) {
|
|
101
|
+
void queuePendingObserverHints(agent.aid, key)
|
|
102
|
+
.catch(error => logger.warn(`[ObserverHint] reconnect recovery failed for ${agent.aid}: ${error}`));
|
|
103
|
+
}
|
|
104
|
+
const valid = () => !dependencies.isCancelled?.()
|
|
105
|
+
&& connections.get(key) === connection && channelInstances.includes(instance)
|
|
106
|
+
&& instance.lifecycle?.signal.aborted !== true
|
|
107
|
+
&& instance.channel.getStatus?.().connected !== false;
|
|
108
|
+
const enqueue = (name, run) => followups.run(async () => {
|
|
109
|
+
try {
|
|
110
|
+
await run();
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
logger.warn(`[ChannelStartup] ${key} ${name} failed: ${error}`);
|
|
114
|
+
}
|
|
115
|
+
}, valid);
|
|
116
|
+
// AUN protocol work and external platform notices have separate assembly.
|
|
82
117
|
if (instance.channelType === 'aun' && agent) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
118
|
+
let authorizationReady = false;
|
|
119
|
+
while (valid() && !authorizationReady) {
|
|
120
|
+
await enqueue('authorization', async () => {
|
|
121
|
+
authorizationReady = await dependencies.refreshAunAuthorization?.(agent.aid) !== false;
|
|
122
|
+
});
|
|
123
|
+
if (valid() && !authorizationReady) {
|
|
124
|
+
await new Promise(resolve => { const timer = setTimeout(resolve, 1_000); timer.unref?.(); });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (valid())
|
|
128
|
+
await enqueue('lifecycle notice', () => dependencies.sendLifecycleNoticeForChannel?.(instance));
|
|
86
129
|
}
|
|
87
|
-
|
|
88
|
-
dependencies.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
dependencies.trySendPendingRestartNotice(),
|
|
98
|
-
]);
|
|
130
|
+
else {
|
|
131
|
+
await enqueue('online notice', () => dependencies.sendOnlineNoticeForChannel(instance));
|
|
132
|
+
}
|
|
133
|
+
await enqueue('bootstrap', () => dependencies.bootstrapService.tryStartBootstrap({
|
|
134
|
+
adapter: instance.adapter,
|
|
135
|
+
channelKey: key,
|
|
136
|
+
channelType: instance.channelType || type,
|
|
137
|
+
source: 'connected',
|
|
138
|
+
}));
|
|
139
|
+
await enqueue('restart notice', () => dependencies.trySendPendingRestartNotice());
|
|
99
140
|
};
|
|
100
141
|
const markChannelDisconnected = (channelName) => {
|
|
101
142
|
connectedChannels.delete(channelName);
|
|
102
|
-
const instance = channelInstances.find(candidate => candidate.adapter.channelName === channelName
|
|
143
|
+
const instance = channelInstances.find(candidate => candidate.adapter.channelName === channelName
|
|
144
|
+
|| candidate.adapter.channelKey === channelName);
|
|
103
145
|
if (instance)
|
|
104
146
|
connectedChannels.delete(instance.adapter.channelKey);
|
|
147
|
+
if (instance)
|
|
148
|
+
connectedChannels.delete(instance.adapter.channelName);
|
|
149
|
+
if (instance)
|
|
150
|
+
connections.delete(instance.adapter.channelKey);
|
|
105
151
|
};
|
|
106
152
|
const unregisterRuntimeChannel = (channelName) => {
|
|
153
|
+
for (const [instance, unsubscribe] of subscriptions) {
|
|
154
|
+
if (instance.adapter.channelName === channelName || instance.adapter.channelKey === channelName) {
|
|
155
|
+
unsubscribe();
|
|
156
|
+
subscriptions.delete(instance);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
107
159
|
markChannelDisconnected(channelName);
|
|
108
160
|
dependencies.processor.unregisterChannel(channelName);
|
|
109
161
|
dependencies.commandHandler.unregisterChannel(channelName);
|
|
110
162
|
dependencies.messageBridge.removeChannel(channelName);
|
|
111
163
|
};
|
|
112
|
-
|
|
164
|
+
const observeChannel = (instance) => {
|
|
165
|
+
if (instance.channelType !== 'aun' || subscriptions.has(instance)
|
|
166
|
+
|| typeof instance.channel.onTransportState !== 'function')
|
|
167
|
+
return;
|
|
168
|
+
const unsubscribe = instance.channel.onTransportState((ready) => {
|
|
169
|
+
if (!channelInstances.includes(instance) || instance.lifecycle?.signal.aborted)
|
|
170
|
+
return;
|
|
171
|
+
if (ready)
|
|
172
|
+
void markChannelConnected(instance).catch(error => logger.warn(`[ChannelStartup] ${instance.adapter.channelKey}: ${error}`));
|
|
173
|
+
else if (connections.get(instance.adapter.channelKey)?.instance === instance)
|
|
174
|
+
markChannelDisconnected(instance.adapter.channelKey);
|
|
175
|
+
});
|
|
176
|
+
subscriptions.set(instance, unsubscribe);
|
|
177
|
+
instance.lifecycle?.defer(unsubscribe, 'AUN transport readiness');
|
|
178
|
+
};
|
|
179
|
+
return {
|
|
180
|
+
markChannelConnected, markChannelDisconnected, unregisterRuntimeChannel, queuePendingObserverHints, observeChannel,
|
|
181
|
+
stop: () => {
|
|
182
|
+
followups.stop();
|
|
183
|
+
connections.clear();
|
|
184
|
+
for (const unsubscribe of subscriptions.values())
|
|
185
|
+
unsubscribe();
|
|
186
|
+
subscriptions.clear();
|
|
187
|
+
},
|
|
188
|
+
};
|
|
113
189
|
}
|
|
114
190
|
export function registerChannelInstance(inst, dependencies) {
|
|
115
|
-
const { defaultProjectPath, defaultPolicy, processor, commandHandler, interactionRouter, messageBridge, eventBus, sessionManager,
|
|
191
|
+
const { defaultProjectPath, defaultPolicy, processor, commandHandler, interactionRouter, messageBridge, eventBus, sessionManager, resolveOwningAgent, } = dependencies;
|
|
116
192
|
wrapChannelSend(inst, {
|
|
117
193
|
eventBus,
|
|
118
194
|
sessionManager,
|
|
@@ -142,21 +218,15 @@ export function registerChannelInstance(inst, dependencies) {
|
|
|
142
218
|
const channelType = inst.channelType || inst.adapter.channelName;
|
|
143
219
|
inst.registerBridge?.(messageBridge, channelType);
|
|
144
220
|
inst.registerHooks?.({ eventBus, sessionManager, lifecycle: inst.lifecycle });
|
|
145
|
-
|
|
146
|
-
if (typeof channelForObserver.setObserverConfigResolver === 'function') {
|
|
221
|
+
if (inst.channelType === 'aun') {
|
|
147
222
|
const channelKey = inst.adapter.channelKey;
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
return {
|
|
151
|
-
observable: owningAgent?.getObservable() ?? false,
|
|
152
|
-
owners: owningAgent ? getOwners(owningAgent.aid) : [],
|
|
153
|
-
};
|
|
223
|
+
inst.channel.setObserverConfigResolver(() => {
|
|
224
|
+
const agent = dependencies.resolveOwningAgent(channelKey, inst.adapter.channelName);
|
|
225
|
+
return { observable: agent?.getObservable() ?? false, owners: agent ? getOwners(agent.aid) : [] };
|
|
154
226
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
hasSession: target => responseEngine.hasObserverTargetSession(target),
|
|
159
|
-
schedule: target => responseEngine.scheduleObserverHint(target),
|
|
227
|
+
inst.channel.setObserverHintRuntime({
|
|
228
|
+
hasSession: (target) => dependencies.responseEngine.hasObserverTargetSession(target),
|
|
229
|
+
schedule: (target) => dependencies.responseEngine.scheduleObserverHint(target),
|
|
160
230
|
});
|
|
161
231
|
}
|
|
162
232
|
inst.channel.onRecall?.((messageId, selfAID) => {
|
|
@@ -171,11 +241,11 @@ export function createChannelStartupNotifications({ channelInstances, agentRegis
|
|
|
171
241
|
const sendOnlineNoticeForChannel = (inst) => {
|
|
172
242
|
// AUN 的上线提示改走 volatile 生命周期通知(见 lifecycle-notice.ts),
|
|
173
243
|
// 这里只保留非 AUN 渠道的 durable 通知,避免同时开启时重复两条。
|
|
174
|
-
if (inst.channelType === 'aun')
|
|
244
|
+
if (!upmsg || inst.channelType === 'aun')
|
|
175
245
|
return;
|
|
176
246
|
const name = inst.adapter.channelName;
|
|
177
247
|
const agent = agentRegistry.resolveByChannel(inst.adapter.channelKey) ?? agentRegistry.resolveByChannel(name);
|
|
178
|
-
if (!agent
|
|
248
|
+
if (!agent)
|
|
179
249
|
return;
|
|
180
250
|
const ownerAid = getFirstStaticAgentOwner(agent.aid);
|
|
181
251
|
if (!ownerAid)
|
|
@@ -256,7 +256,8 @@ function parseAidCommand(argv, source, defaultSelfAid) {
|
|
|
256
256
|
...(subjectAid ? { self: subjectAid } : {}),
|
|
257
257
|
...(command.subjectAid ? { subjectAid: command.subjectAid } : {}),
|
|
258
258
|
...(command.action === 'status' && command.refresh ? { refresh: true } : {}),
|
|
259
|
-
...(command.action === 'bind' ? { ownerAid: command.ownerAid } : {}),
|
|
259
|
+
...(command.action === 'bind' || command.action === 'reset-rejection' ? { ownerAid: command.ownerAid } : {}),
|
|
260
|
+
...(command.action === 'reset-rejection' ? { action: command.action } : {}),
|
|
260
261
|
...(command.action === 'transfer' ? { subAid: command.subAid, newOwnerAid: command.newOwnerAid } : {}),
|
|
261
262
|
...(command.action === 'accept' || command.action === 'reject'
|
|
262
263
|
? { decision: command.action, operationId: command.operationId } : {}),
|
|
@@ -8,7 +8,7 @@ import { renderCommandCardAsText } from '../interaction-router.js';
|
|
|
8
8
|
import { buildEnvelope, deliveryTargetFromSession, isInteractionSendAccepted, replyContextFromSession, sendInteractionPayload } from '../message/message-utils.js';
|
|
9
9
|
import { sessionTopicThreadId } from '../thread/topic-id.js';
|
|
10
10
|
import { resolvePaths, getPackageRoot, resolveRoot } from '../../paths.js';
|
|
11
|
-
import { loadDaemonConfig } from '../../config-store.js';
|
|
11
|
+
import { loadAgent, loadDaemonConfig } from '../../config-store.js';
|
|
12
12
|
import { parseOwnershipCommand, executeOwnershipCommand, ownershipFailure } from '../../aun/aid/ownership-operation.js';
|
|
13
13
|
import { ownerResolver, refreshOwnershipForAuthorization } from '../ownership/owner-resolver.js';
|
|
14
14
|
import { logger } from '../../utils/logger.js';
|
|
@@ -356,15 +356,17 @@ export class CommandHandler {
|
|
|
356
356
|
getTriggerSchedulerForAgent(agentAid) {
|
|
357
357
|
return this.triggerSchedulerResolver?.(agentAid) ?? (this.triggerSchedulerFallbackAid === agentAid ? this.triggerSchedulerFallback : undefined);
|
|
358
358
|
}
|
|
359
|
-
assertSessionLoopTrigger(session) {
|
|
359
|
+
assertSessionLoopTrigger(session, once = false) {
|
|
360
360
|
const daemonAid = this.getDaemonTriggerOwnerAid();
|
|
361
361
|
const schedulers = new Set([
|
|
362
362
|
this.getTriggerSchedulerForAgent(session.selfAID ?? ''),
|
|
363
363
|
daemonAid ? this.getTriggerSchedulerForAgent(daemonAid) : undefined,
|
|
364
364
|
]);
|
|
365
365
|
const triggers = [...schedulers].flatMap(scheduler => scheduler?.list({ all: true }) ?? [])
|
|
366
|
-
.filter(definition =>
|
|
367
|
-
|
|
366
|
+
.filter(definition => once
|
|
367
|
+
? definition.id === '__session-idle-check' && isDaemonEventSessionTrigger(definition)
|
|
368
|
+
: definition.id === '__session-idle-check'
|
|
369
|
+
|| (definition.source.type === 'event' && definition.source.eventPattern === 'session:idle'));
|
|
368
370
|
if (triggers.length === 0) {
|
|
369
371
|
throw sessionLoopError('LOOP_TRIGGER_NOT_FOUND', '未找到 session:idle Trigger,无法开启 loop');
|
|
370
372
|
}
|
|
@@ -1036,7 +1038,7 @@ export class CommandHandler {
|
|
|
1036
1038
|
return false;
|
|
1037
1039
|
return !!userId && topic.metadata?.peerId === userId;
|
|
1038
1040
|
}
|
|
1039
|
-
buildTopicMenuItem(s, metadataOnly = false) {
|
|
1041
|
+
async buildTopicMenuItem(s, metadataOnly = false) {
|
|
1040
1042
|
const displayName = displaySessionTitle(s.name, sessionTopicThreadId(s) || s.id.slice(0, 8));
|
|
1041
1043
|
const item = {
|
|
1042
1044
|
value: sessionTopicThreadId(s) ?? '',
|
|
@@ -1050,10 +1052,10 @@ export class CommandHandler {
|
|
|
1050
1052
|
if (s.agentSessionId) {
|
|
1051
1053
|
item.agentSessionId = s.agentSessionId;
|
|
1052
1054
|
if (!metadataOnly) {
|
|
1053
|
-
const
|
|
1054
|
-
if (
|
|
1055
|
-
item.turns =
|
|
1056
|
-
const firstMsg =
|
|
1055
|
+
const summary = await this.sessionManager.readSessionMenuSummary(s.projectPath, s.agentSessionId, s.baseagent, s.selfAID);
|
|
1056
|
+
if (summary.turns)
|
|
1057
|
+
item.turns = summary.turns;
|
|
1058
|
+
const firstMsg = summary.firstMessage;
|
|
1057
1059
|
if (firstMsg)
|
|
1058
1060
|
item.preview = firstMsg.length > 80 ? firstMsg.slice(0, 80) + '...' : firstMsg;
|
|
1059
1061
|
}
|
|
@@ -2060,7 +2062,9 @@ export class CommandHandler {
|
|
|
2060
2062
|
const command = parseOwnershipCommand(argv);
|
|
2061
2063
|
const targetAid = command.subjectAid ?? grant.selfAid;
|
|
2062
2064
|
const fullAccess = hasTrustedFullAccessDelegation(grant);
|
|
2063
|
-
|
|
2065
|
+
if (command.action !== 'reset-rejection' || !loadAgent(targetAid)) {
|
|
2066
|
+
ownerResolver.assertLocalSubject(targetAid);
|
|
2067
|
+
}
|
|
2064
2068
|
if (command.action === 'status') {
|
|
2065
2069
|
return { ok: true, state: await executeOwnershipCommand(command, grant.selfAid) };
|
|
2066
2070
|
}
|
|
@@ -2096,7 +2100,8 @@ export class CommandHandler {
|
|
|
2096
2100
|
args: {
|
|
2097
2101
|
self: targetAid,
|
|
2098
2102
|
targetAgentAid: targetAid,
|
|
2099
|
-
...(command.action === 'bind' ? { ownerAid: command.ownerAid } : {}),
|
|
2103
|
+
...(command.action === 'bind' || command.action === 'reset-rejection' ? { ownerAid: command.ownerAid } : {}),
|
|
2104
|
+
...(command.action === 'reset-rejection' ? { action: command.action } : {}),
|
|
2100
2105
|
...(command.action === 'transfer' ? { subAid: command.subAid, newOwnerAid: command.newOwnerAid } : {}),
|
|
2101
2106
|
...(command.action === 'accept' || command.action === 'reject'
|
|
2102
2107
|
? { decision: command.action, operationId: command.operationId } : {}),
|
|
@@ -2032,9 +2032,14 @@ export async function getSubMenuItems(cmd, channel, channelId, userId, args, ove
|
|
|
2032
2032
|
}
|
|
2033
2033
|
}
|
|
2034
2034
|
const metadataOnly = args?.metadataOnly === true;
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2035
|
+
const topics = sessions.filter((s) => isTopicSession(s)
|
|
2036
|
+
&& (!hasLabel || s.label === label) && (!topicStatus || s.topicStatus === topicStatus));
|
|
2037
|
+
const items = [];
|
|
2038
|
+
for (let offset = 0; offset < topics.length; offset += 4) {
|
|
2039
|
+
items.push(...await Promise.all(topics.slice(offset, offset + 4)
|
|
2040
|
+
.map((s) => this.buildTopicMenuItem(s, metadataOnly))));
|
|
2041
|
+
}
|
|
2042
|
+
return items;
|
|
2038
2043
|
}
|
|
2039
2044
|
if (cmd === '/s' || cmd === '/session' || cmd === '/del') {
|
|
2040
2045
|
const sessions = await this.sessionManager.listSessions(channel, channelId);
|
|
@@ -9,6 +9,58 @@ import { parseFileSearchArgs } from './file-search.js';
|
|
|
9
9
|
import { validateProviderMenuRequest } from '../../config/provider-menu-request.js';
|
|
10
10
|
import { validatePaWorkspaceItemsArgs } from './pa-workspace-items.js';
|
|
11
11
|
import { validateAgentMdMenuRequest } from './agentmd-menu-request.js';
|
|
12
|
+
const RETRY_DELAYS_MS = [250, 750, 2_000];
|
|
13
|
+
const RETRY_WINDOW_MS = 5_000;
|
|
14
|
+
export function isRetryableMenuTransportError(error) {
|
|
15
|
+
if (!error || typeof error !== 'object')
|
|
16
|
+
return false;
|
|
17
|
+
const value = error;
|
|
18
|
+
const code = String(value.code ?? '').toUpperCase();
|
|
19
|
+
if (['CONTACT_DENIED', 'CONTACT_OWNERSHIP_CHANGED', 'PERMISSION_DENIED', 'FORBIDDEN'].includes(code))
|
|
20
|
+
return false;
|
|
21
|
+
return value.retryable === true;
|
|
22
|
+
}
|
|
23
|
+
export async function deliverMenuResponse(send, options) {
|
|
24
|
+
const startedAt = performance.now();
|
|
25
|
+
let sendAttempts = 0;
|
|
26
|
+
const fail = (retryStopReason, error) => {
|
|
27
|
+
options.onComplete?.({ sendAttempts, retryStopReason });
|
|
28
|
+
throw error;
|
|
29
|
+
};
|
|
30
|
+
for (let attempt = 0;; attempt++) {
|
|
31
|
+
try {
|
|
32
|
+
sendAttempts++;
|
|
33
|
+
await send();
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
const delay = RETRY_DELAYS_MS[attempt];
|
|
37
|
+
if (!isRetryableMenuTransportError(error))
|
|
38
|
+
fail('transport-error', error);
|
|
39
|
+
if (delay === undefined)
|
|
40
|
+
fail('transport-retry-exhausted', error);
|
|
41
|
+
if (performance.now() - startedAt + delay > RETRY_WINDOW_MS)
|
|
42
|
+
fail('transport-retry-window-expired', error);
|
|
43
|
+
options.onRetry?.(attempt + 1, error, delay);
|
|
44
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
45
|
+
if (performance.now() - startedAt >= RETRY_WINDOW_MS)
|
|
46
|
+
fail('transport-retry-window-expired', error);
|
|
47
|
+
let allowed = false;
|
|
48
|
+
try {
|
|
49
|
+
allowed = await options.canRetry();
|
|
50
|
+
}
|
|
51
|
+
catch (guardError) {
|
|
52
|
+
fail('retry-guard-error', guardError);
|
|
53
|
+
}
|
|
54
|
+
if (!allowed)
|
|
55
|
+
fail('retry-guard-rejected', error);
|
|
56
|
+
if (performance.now() - startedAt >= RETRY_WINDOW_MS)
|
|
57
|
+
fail('transport-retry-window-expired', error);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
options.onComplete?.({ sendAttempts });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
12
64
|
export const MENU_REQUEST_TYPES = new Set([
|
|
13
65
|
'menu.token.request',
|
|
14
66
|
'menu.list',
|
|
@@ -194,6 +246,9 @@ export function normalizeMenuResponseTiming(timing, clock = {}) {
|
|
|
194
246
|
* its own inbound-to-outbound processing time.
|
|
195
247
|
*/
|
|
196
248
|
export function withMenuProcessingTime(response, timing, clock = {}) {
|
|
249
|
+
return { ...response, processing_ms: menuElapsedMs(timing, clock) };
|
|
250
|
+
}
|
|
251
|
+
function menuElapsedMs(timing, clock = {}) {
|
|
197
252
|
const receivedAtMono = typeof timing.receivedAtMono === 'number' && Number.isFinite(timing.receivedAtMono)
|
|
198
253
|
? timing.receivedAtMono
|
|
199
254
|
: undefined;
|
|
@@ -205,9 +260,15 @@ export function withMenuProcessingTime(response, timing, clock = {}) {
|
|
|
205
260
|
: receivedAt !== undefined
|
|
206
261
|
? (clock.wallNow ?? Date.now()) - receivedAt
|
|
207
262
|
: 0;
|
|
208
|
-
return
|
|
209
|
-
|
|
210
|
-
|
|
263
|
+
return Math.max(0, Math.round(Number.isFinite(elapsed) ? elapsed : 0));
|
|
264
|
+
}
|
|
265
|
+
/** Log-only timing: delivery includes all send attempts, retry waits and guard checks. */
|
|
266
|
+
export function beginMenuDeliveryTiming(timing) {
|
|
267
|
+
const started = performance.now();
|
|
268
|
+
const processingMs = menuElapsedMs(timing, { monotonicNow: started });
|
|
269
|
+
return () => {
|
|
270
|
+
const transportMs = Math.max(0, Math.round(performance.now() - started));
|
|
271
|
+
return { processingMs, transportMs, totalMs: processingMs + transportMs };
|
|
211
272
|
};
|
|
212
273
|
}
|
|
213
274
|
export function evaluateEvolMenuVersionGate(input) {
|
|
@@ -930,16 +991,25 @@ export function logMenuRequestReceived(request, context) {
|
|
|
930
991
|
request: menuRequestBusinessFields(request),
|
|
931
992
|
});
|
|
932
993
|
}
|
|
994
|
+
export function logMenuResponseRetry(request, context, attempt, delayMs, error) {
|
|
995
|
+
const code = error && typeof error === 'object' && 'code' in error ? String(error.code) : undefined;
|
|
996
|
+
writeMenuFlowRecord({ ...menuFlowBaseRecord(request, context), event: 'menu.response.retry',
|
|
997
|
+
phase: 'scheduled', attempt, delayMs, code, retryable: true });
|
|
998
|
+
}
|
|
933
999
|
export function logMenuRequestCompleted(request, response, context, options) {
|
|
934
1000
|
const error = response && 'error' in response ? response.error : undefined;
|
|
1001
|
+
const detail = options.transportError && typeof options.transportError === 'object'
|
|
1002
|
+
? options.transportError : undefined;
|
|
935
1003
|
const transportError = options.transportError instanceof Error
|
|
936
|
-
? { message: sanitizeLogString(options.transportError.message)
|
|
1004
|
+
? { message: sanitizeLogString(options.transportError.message),
|
|
1005
|
+
...(detail?.code === undefined ? {} : { code: sanitizeLogString(String(detail.code)) }),
|
|
1006
|
+
...(detail?.retryable === undefined ? {} : { retryable: isRetryableMenuTransportError(options.transportError) }) }
|
|
937
1007
|
: options.transportError === undefined
|
|
938
1008
|
? undefined
|
|
939
1009
|
: { message: sanitizeLogString(String(options.transportError)) };
|
|
940
|
-
const processingMs = response && typeof response.processing_ms === 'number'
|
|
1010
|
+
const processingMs = options.processingMs ?? (response && typeof response.processing_ms === 'number'
|
|
941
1011
|
? response.processing_ms
|
|
942
|
-
: undefined;
|
|
1012
|
+
: undefined);
|
|
943
1013
|
let responseBytes;
|
|
944
1014
|
if (response) {
|
|
945
1015
|
try {
|
|
@@ -952,8 +1022,11 @@ export function logMenuRequestCompleted(request, response, context, options) {
|
|
|
952
1022
|
event: options.delivery === 'failed' ? 'menu.request.failed' : 'menu.request.completed',
|
|
953
1023
|
delivery: options.delivery,
|
|
954
1024
|
processingMs,
|
|
1025
|
+
transportMs: options.transportMs,
|
|
1026
|
+
totalMs: options.totalMs,
|
|
955
1027
|
responseBytes,
|
|
956
|
-
|
|
1028
|
+
sendAttempts: options.sendAttempts,
|
|
1029
|
+
reason: options.retryStopReason ?? options.reason,
|
|
957
1030
|
result: response && 'data' in response ? sanitizeMenuLogValue(response.data) : undefined,
|
|
958
1031
|
warning: response && 'warning' in response ? sanitizeMenuLogValue(response.warning) : undefined,
|
|
959
1032
|
error: error ? sanitizeMenuLogValue(error) : transportError,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createProvider, parseProviderImport, readProvidersSnapshot, updateProvider } from '../../config/providers-management.js';
|
|
2
2
|
import { parseProviderObject, providerFailure } from '../../config/provider-ipc-service.js';
|
|
3
|
+
import { resolveProviderId } from '../../config/providers-config.js';
|
|
3
4
|
import { validateProviderMenuRequest } from '../../config/provider-menu-request.js';
|
|
4
5
|
import { authorizeFreshOperation } from '../auth/auth-gateway.js';
|
|
5
6
|
export async function executeProviderMenu(request, subject, source) {
|
|
@@ -28,8 +29,9 @@ export async function executeProviderMenu(request, subject, source) {
|
|
|
28
29
|
const snapshot = readProvidersSnapshot();
|
|
29
30
|
if (operation === 'list')
|
|
30
31
|
return { data: snapshot };
|
|
31
|
-
const
|
|
32
|
-
|
|
32
|
+
const providerId = resolveProviderId(args.providerId, snapshot);
|
|
33
|
+
const provider = snapshot.providers[providerId];
|
|
34
|
+
return provider ? { data: { providerId, provider, revision: snapshot.revision } }
|
|
33
35
|
: { error: 'Provider not found', code: 'NOT_FOUND' };
|
|
34
36
|
}
|
|
35
37
|
if (operation === 'create' || operation === 'import') {
|