evolcore 0.0.43-test.6 → 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 +95 -0
- package/bin/ecmsg.js +188 -58
- 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/baseagent-availability.js +1 -1
- package/dist/agents/claude-runner.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- 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 +6 -1
- package/dist/channels/aun.js +277 -49
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +7 -3
- 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 +11 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +109 -0
- package/dist/cli/index.js +60 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/net-check.js +1 -1
- package/dist/cli/restart-monitor.js +160 -83
- package/dist/cli/services-command.js +137 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +103 -13
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +8 -8
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +45 -15
- package/dist/config-store.js +2 -1
- package/dist/core/agent-ipc-registration.js +25 -4
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +106 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-authorizer.js +2 -0
- package/dist/core/auth/operation-catalog.js +29 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +20 -12
- package/dist/core/command/agent-control.js +12 -2
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/agent-template-menu.js +147 -0
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +80 -17
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +468 -0
- package/dist/core/command/menu-catalog.js +15 -0
- package/dist/core/command/menu-handler.js +216 -90
- package/dist/core/command/menu-protocol.js +71 -13
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +22 -5
- package/dist/core/daemon-lifecycle.js +323 -191
- package/dist/core/handoff/runtime.js +45 -13
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +50 -7
- package/dist/core/legacy-rename.js +41 -0
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +252 -17
- package/dist/core/message/im-renderer.js +116 -85
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-queue.js +66 -15
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +29 -5
- package/dist/core/message/response-engine.js +194 -61
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +50 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/pack-auth.js +94 -0
- package/dist/core/pack-install.js +194 -0
- package/dist/core/permission/ec-command-parser.js +51 -17
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/rate-window.js +48 -0
- package/dist/core/relation/peer-identity.js +28 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +67 -28
- package/dist/core/session/session-idle-monitor.js +59 -19
- package/dist/core/session/session-manager.js +13 -4
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/core/thread/thread-service.js +52 -3
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/eck/message-renderer.js +2 -0
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +124 -0
- package/dist/event-center/bus-gate.js +154 -0
- package/dist/event-center/bus-host.js +307 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +127 -0
- package/dist/event-center/daemon.js +44 -0
- package/dist/event-center/directory-source.js +55 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +73 -0
- package/dist/event-center/ipc-operation.js +423 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +207 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +463 -0
- package/dist/event-center/runtime.js +837 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +51 -0
- package/dist/event-center/validation.js +435 -0
- package/dist/index.js +424 -135
- package/dist/ipc.js +106 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/engines/v1/proactive-flow.js +4 -2
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +550 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +215 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +98 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/scheduler.js +38 -0
- package/dist/trigger/script-sandbox.js +170 -24
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +6 -3
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +9 -15
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +3 -1
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/agent.md +22 -1
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +227 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +5 -3
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +28 -1
- package/kits/docs/evolcore/msg.md +21 -9
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +294 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/docs/evolcore/thread-chain.md +15 -3
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +1 -0
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-group/SKILL.md +5 -8
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +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 +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +1 -5
- package/kits/templates/system-fragments/thread.md +13 -10
- package/package.json +5 -6
- 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/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
package/dist/ipc.js
CHANGED
|
@@ -76,6 +76,8 @@ const LOCAL_CONTROL_COMMANDS = new Set([
|
|
|
76
76
|
'ecweb.ability',
|
|
77
77
|
'upgrade.op',
|
|
78
78
|
'provider.op',
|
|
79
|
+
'agent-template.op',
|
|
80
|
+
'invoke.op',
|
|
79
81
|
'ecweb.init',
|
|
80
82
|
'ecweb.basic-settings',
|
|
81
83
|
'ecweb.message.context',
|
|
@@ -96,7 +98,7 @@ const MEMORY_COMMAND_ENDPOINTS = new Set([
|
|
|
96
98
|
'memory.create', 'memory.update', 'memory.archive', 'memory.demote', 'memory.consolidate',
|
|
97
99
|
]);
|
|
98
100
|
const DELEGATED_ARGV_ENDPOINTS = new Set([
|
|
99
|
-
'agent.op', 'ability.op', 'config.op', 'peer.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op', 'proxy.op', 'provider.op',
|
|
101
|
+
'agent.op', 'ability.op', 'config.op', 'peer.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op', 'proxy.op', 'provider.op', 'invoke.op',
|
|
100
102
|
'upgrade.op',
|
|
101
103
|
'ctl', 'diag', 'menu-client.request', 'task.resume', 'queue.op', 'storage.auth', 'storage.upload',
|
|
102
104
|
'trigger.op', 'skill.refresh', 'thread.op', 'local-command-context', 'evolagent.bootstrapComplete', 'status.auth', 'logs.query', ...MEMORY_COMMAND_ENDPOINTS,
|
|
@@ -126,7 +128,7 @@ function requiresLocalControlToken(cmd) {
|
|
|
126
128
|
const type = String(cmd.type ?? '');
|
|
127
129
|
const sessionId = typeof cmd.sessionId === 'string' && cmd.sessionId.trim();
|
|
128
130
|
const delegated = typeof cmd.delegationToken === 'string' && cmd.delegationToken.trim();
|
|
129
|
-
if (type === 'provider.op' || type === 'upgrade.op')
|
|
131
|
+
if (type === 'provider.op' || type === 'upgrade.op' || type === 'invoke.op')
|
|
130
132
|
return !sessionId || !delegated || cmd.actorSessionId !== undefined;
|
|
131
133
|
if (cmd.type === 'evolagent.initialize' || LOCAL_CONTROL_COMMANDS.has(type))
|
|
132
134
|
return true;
|
|
@@ -135,7 +137,7 @@ function requiresLocalControlToken(cmd) {
|
|
|
135
137
|
// Ownership has an explicit, non-fallback authentication contract below.
|
|
136
138
|
if (type === 'aid.ownership')
|
|
137
139
|
return false;
|
|
138
|
-
if (type === 'skill.refresh' || type === 'thread.op')
|
|
140
|
+
if (type === 'skill.refresh' || type === 'thread.op' || type === 'events.op' || type === 'services.op')
|
|
139
141
|
return !sessionId || !delegated;
|
|
140
142
|
if (type === 'ability.op')
|
|
141
143
|
return !sessionId && !delegated;
|
|
@@ -216,6 +218,7 @@ export class IpcServer {
|
|
|
216
218
|
triggerExecutor;
|
|
217
219
|
proxyExecutor;
|
|
218
220
|
providerExecutor;
|
|
221
|
+
invokeExecutor;
|
|
219
222
|
upgradeExecutor;
|
|
220
223
|
consolidationLaunchExecutor;
|
|
221
224
|
consolidationCheckExecutor;
|
|
@@ -248,6 +251,8 @@ export class IpcServer {
|
|
|
248
251
|
msgOperationExecutor;
|
|
249
252
|
fsOperationExecutor;
|
|
250
253
|
threadOperationExecutor;
|
|
254
|
+
eventsOperationExecutor;
|
|
255
|
+
servicesOperationExecutor;
|
|
251
256
|
dingtalkContactBindExecutor;
|
|
252
257
|
feishuContactBindExecutor;
|
|
253
258
|
qqbotContactBindExecutor;
|
|
@@ -389,6 +394,12 @@ export class IpcServer {
|
|
|
389
394
|
setThreadOperationExecutor(executor) {
|
|
390
395
|
this.threadOperationExecutor = executor;
|
|
391
396
|
}
|
|
397
|
+
setEventsOperationExecutor(executor) {
|
|
398
|
+
this.eventsOperationExecutor = executor;
|
|
399
|
+
}
|
|
400
|
+
setServicesOperationExecutor(executor) {
|
|
401
|
+
this.servicesOperationExecutor = executor;
|
|
402
|
+
}
|
|
392
403
|
setAgentReloadExecutor(executor) {
|
|
393
404
|
this.agentReloadExecutor = executor;
|
|
394
405
|
}
|
|
@@ -541,6 +552,9 @@ export class IpcServer {
|
|
|
541
552
|
setProviderExecutor(executor) {
|
|
542
553
|
this.providerExecutor = executor;
|
|
543
554
|
}
|
|
555
|
+
setInvokeExecutor(executor) {
|
|
556
|
+
this.invokeExecutor = executor;
|
|
557
|
+
}
|
|
544
558
|
setUpgradeExecutor(executor) {
|
|
545
559
|
this.upgradeExecutor = executor;
|
|
546
560
|
}
|
|
@@ -1254,6 +1268,29 @@ export class IpcServer {
|
|
|
1254
1268
|
const { executeProviderOperation } = await import('./config/provider-ipc-service.js');
|
|
1255
1269
|
return executeProviderOperation({ argv: cmd.argv });
|
|
1256
1270
|
}
|
|
1271
|
+
case 'invoke.op': {
|
|
1272
|
+
const hasDelegatedFields = cmd.sessionId !== undefined || cmd.delegationToken !== undefined
|
|
1273
|
+
|| cmd.actorSessionId !== undefined;
|
|
1274
|
+
if (hasDelegatedFields) {
|
|
1275
|
+
if (typeof cmd.sessionId !== 'string' || !cmd.sessionId
|
|
1276
|
+
|| typeof cmd.delegationToken !== 'string' || !cmd.delegationToken
|
|
1277
|
+
|| cmd.actorSessionId !== undefined) {
|
|
1278
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'invoke.op requires a session and task delegation token' };
|
|
1279
|
+
}
|
|
1280
|
+
if (!this.invokeExecutor)
|
|
1281
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'managed invoke executor is unavailable' };
|
|
1282
|
+
return this.invokeExecutor({
|
|
1283
|
+
argv: cmd.argv,
|
|
1284
|
+
input: cmd.input,
|
|
1285
|
+
sessionId: cmd.sessionId,
|
|
1286
|
+
delegationToken: cmd.delegationToken,
|
|
1287
|
+
delegationCommandHash: cmd.delegationCommandHash,
|
|
1288
|
+
requestId,
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
const { executeInvokeOperation } = await import('./config/invoke-ipc-service.js');
|
|
1292
|
+
return executeInvokeOperation({ argv: cmd.argv, input: cmd.input });
|
|
1293
|
+
}
|
|
1257
1294
|
case 'upgrade.op': {
|
|
1258
1295
|
const hasDelegatedFields = cmd.sessionId !== undefined || cmd.delegationToken !== undefined
|
|
1259
1296
|
|| cmd.actorSessionId !== undefined;
|
|
@@ -1766,7 +1803,7 @@ export class IpcServer {
|
|
|
1766
1803
|
}
|
|
1767
1804
|
case 'local-command-context': {
|
|
1768
1805
|
if (!Array.isArray(cmd.argv) || cmd.argv.some((value) => typeof value !== 'string')
|
|
1769
|
-
|| !['skill', 'stats', 'session', '
|
|
1806
|
+
|| !['skill', 'stats', 'session', 'team'].includes(cmd.argv[0]) || typeof cmd.sessionId !== 'string' || !cmd.sessionId
|
|
1770
1807
|
|| typeof cmd.delegationToken !== 'string' || !cmd.delegationToken) {
|
|
1771
1808
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Local command requires argv and task credentials' };
|
|
1772
1809
|
}
|
|
@@ -1783,13 +1820,15 @@ export class IpcServer {
|
|
|
1783
1820
|
if (!context?.selfAid || !context.peerRole || context.peerRole === 'none') {
|
|
1784
1821
|
return { ok: false, code: 'NOT_ALLOWED', error: 'Current task identity and role are unavailable' };
|
|
1785
1822
|
}
|
|
1786
|
-
if (cmd.argv[0] === '
|
|
1823
|
+
if (cmd.argv[0] === 'team'
|
|
1787
1824
|
&& (context.channel !== 'aun' || context.chatType !== 'private' || context.peerRole !== 'owner' || !context.peerId)) {
|
|
1788
|
-
return { ok: false, code: 'NOT_ALLOWED', error: '
|
|
1825
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'Team workspace commands require the current Agent owner in an AUN private chat' };
|
|
1789
1826
|
}
|
|
1790
|
-
if (cmd.argv[0] === '
|
|
1791
|
-
&& (cmd.argv[1] === '
|
|
1792
|
-
|
|
1827
|
+
if (cmd.argv[0] === 'team' && context.permissionMode === 'readonly'
|
|
1828
|
+
&& (cmd.argv[1] === 'workspace' && cmd.argv[2] === 'init'
|
|
1829
|
+
|| cmd.argv[1] === 'navigation' && cmd.argv[2] === 'update'
|
|
1830
|
+
|| cmd.argv[1] === 'members' && cmd.argv[2] === 'update')) {
|
|
1831
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'Readonly tasks cannot change Team Workspace state' };
|
|
1793
1832
|
}
|
|
1794
1833
|
const fullAccessTask = context.processRole === 'fullaccess-run'
|
|
1795
1834
|
&& context.dataScope === 'daemon' && context.permissionMode === 'fullaccess';
|
|
@@ -1925,6 +1964,9 @@ export class IpcServer {
|
|
|
1925
1964
|
timeoutMs: typeof cmd.timeoutMs === 'number' && Number.isFinite(cmd.timeoutMs) ? cmd.timeoutMs : undefined,
|
|
1926
1965
|
delegationToken: typeof cmd.delegationToken === 'string' ? cmd.delegationToken : undefined,
|
|
1927
1966
|
delegationCommandHash: typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined,
|
|
1967
|
+
// 非托管跨话题自派(`ecmsg send --from <self> --thread T --to <self>`)没有委托凭证,
|
|
1968
|
+
// 用本机 controlToken 证明「这是本机控制面调用」;只对跨话题自派生效,见 sender。
|
|
1969
|
+
localControl: !cmd.delegationToken && this.hasValidControlToken(cmd.controlToken),
|
|
1928
1970
|
log,
|
|
1929
1971
|
});
|
|
1930
1972
|
}
|
|
@@ -2142,7 +2184,7 @@ export class IpcServer {
|
|
|
2142
2184
|
if (disabled)
|
|
2143
2185
|
return disabled;
|
|
2144
2186
|
const ownerAid = taskCtx.selfAid
|
|
2145
|
-
? ownerResolver.
|
|
2187
|
+
? ownerResolver.owner(taskCtx.selfAid)
|
|
2146
2188
|
: undefined;
|
|
2147
2189
|
const { launchConsolidation } = await import('./core/memory/consolidation.js');
|
|
2148
2190
|
if (!this.consolidationLaunchExecutor) {
|
|
@@ -2514,6 +2556,22 @@ export class IpcServer {
|
|
|
2514
2556
|
};
|
|
2515
2557
|
return await this.threadOperationExecutor(req);
|
|
2516
2558
|
}
|
|
2559
|
+
case 'events.op': {
|
|
2560
|
+
if (!this.eventsOperationExecutor)
|
|
2561
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'events.op not configured' };
|
|
2562
|
+
return await this.eventsOperationExecutor({
|
|
2563
|
+
...cmd,
|
|
2564
|
+
caller: this.packCaller(cmd),
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
case 'services.op': {
|
|
2568
|
+
if (!this.servicesOperationExecutor)
|
|
2569
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'services.op not configured' };
|
|
2570
|
+
return await this.servicesOperationExecutor({
|
|
2571
|
+
...cmd,
|
|
2572
|
+
caller: this.packCaller(cmd),
|
|
2573
|
+
});
|
|
2574
|
+
}
|
|
2517
2575
|
case 'evolagent.initialize': {
|
|
2518
2576
|
if (cmd.sessionId || cmd.delegationToken)
|
|
2519
2577
|
return { ok: false, code: 'NOT_ALLOWED', error: 'Managed callers must use agent.op' };
|
|
@@ -2533,6 +2591,19 @@ export class IpcServer {
|
|
|
2533
2591
|
}
|
|
2534
2592
|
return await this.agentOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
|
|
2535
2593
|
}
|
|
2594
|
+
case 'agent-template.op': {
|
|
2595
|
+
if (cmd.sessionId !== undefined || cmd.delegationToken !== undefined)
|
|
2596
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'Managed template commands must use agent.op' };
|
|
2597
|
+
try {
|
|
2598
|
+
if (!Array.isArray(cmd.argv) || cmd.argv.some((arg) => typeof arg !== 'string'))
|
|
2599
|
+
throw new Error('argv required');
|
|
2600
|
+
const { executeHostTemplateCommand } = await import('./cli/agent-template.js');
|
|
2601
|
+
return await executeHostTemplateCommand(cmd.argv);
|
|
2602
|
+
}
|
|
2603
|
+
catch (error) {
|
|
2604
|
+
return { ok: false, code: error.code ?? 'INVALID_ARGUMENT', error: error.message };
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2536
2607
|
case 'skill.refresh': {
|
|
2537
2608
|
if (!this.skillRefreshExecutor) {
|
|
2538
2609
|
return { ok: false, code: 'NOT_CONFIGURED', error: 'skill.refresh not configured' };
|
|
@@ -2913,8 +2984,11 @@ export class IpcServer {
|
|
|
2913
2984
|
const disabled = this.checkMemoryEnabled(mc, mode, taskCtx);
|
|
2914
2985
|
if (disabled)
|
|
2915
2986
|
return { error: disabled };
|
|
2987
|
+
// Owner 判定必须与上下文注入同源:response-engine 侧用 resolveContextOwner(),
|
|
2988
|
+
// 底层同样是 ownerResolver.owner()。两处口径只能一起改,否则记忆会写进
|
|
2989
|
+
// 一个 owner 的目录、注入时却去另一个 owner 的目录找。
|
|
2916
2990
|
const ownerAid = taskCtx.selfAid
|
|
2917
|
-
? ownerResolver.
|
|
2991
|
+
? ownerResolver.owner(taskCtx.selfAid)
|
|
2918
2992
|
: undefined;
|
|
2919
2993
|
if (allowed === 'owner' && !ownerAid) {
|
|
2920
2994
|
return { error: { ok: false, code: 'INVALID_REQUEST', error: '当前 agent 未配置 owner' } };
|
|
@@ -2983,7 +3057,7 @@ export class IpcServer {
|
|
|
2983
3057
|
try {
|
|
2984
3058
|
if (!this.consolidationLaunchExecutor)
|
|
2985
3059
|
return;
|
|
2986
|
-
const ownerAid = ownerResolver.
|
|
3060
|
+
const ownerAid = ownerResolver.owner(selfAid);
|
|
2987
3061
|
await this.consolidationLaunchExecutor({
|
|
2988
3062
|
taskCtx,
|
|
2989
3063
|
mode: 'forget',
|
|
@@ -2995,6 +3069,26 @@ export class IpcServer {
|
|
|
2995
3069
|
}
|
|
2996
3070
|
catch { /* 触发失败不影响本次写入结果 */ }
|
|
2997
3071
|
}
|
|
3072
|
+
/**
|
|
3073
|
+
* 事件/服务运维命令的调用方身份。
|
|
3074
|
+
*
|
|
3075
|
+
* 主机终端(持有效 control token、无托管会话)→ local-control;
|
|
3076
|
+
* 其余按托管会话处理,角色取自该会话的 TaskRuntimeContext.peerRole。
|
|
3077
|
+
* 角色解析不出来时留空,由 `authorizePackTarget` 按最保守档拒绝管理类命令。
|
|
3078
|
+
*/
|
|
3079
|
+
packCaller(cmd) {
|
|
3080
|
+
const sessionId = typeof cmd.sessionId === 'string' && cmd.sessionId ? cmd.sessionId : undefined;
|
|
3081
|
+
const delegated = typeof cmd.delegationToken === 'string' && !!cmd.delegationToken;
|
|
3082
|
+
if (!sessionId && !delegated && this.hasValidControlToken(cmd.controlToken)) {
|
|
3083
|
+
return { kind: 'local-control' };
|
|
3084
|
+
}
|
|
3085
|
+
const context = sessionId ? this.taskRuntimeContextProvider?.({ sessionId }) : undefined;
|
|
3086
|
+
return {
|
|
3087
|
+
kind: 'managed',
|
|
3088
|
+
...(context?.selfAid ? { selfAid: context.selfAid } : {}),
|
|
3089
|
+
...(context?.peerRole ? { peerRole: context.peerRole } : {}),
|
|
3090
|
+
};
|
|
3091
|
+
}
|
|
2998
3092
|
hasValidControlToken(value) {
|
|
2999
3093
|
if (!this.controlToken || typeof value !== 'string')
|
|
3000
3094
|
return false;
|
package/dist/paths.js
CHANGED
|
@@ -105,6 +105,18 @@ export function agentMdPath(aid, root = resolveRoot()) {
|
|
|
105
105
|
export function agentDir(aid) {
|
|
106
106
|
return path.join(resolveRoot(), 'agents', aid);
|
|
107
107
|
}
|
|
108
|
+
/** Default per-Agent artifact workspace. */
|
|
109
|
+
export function agentWorkspaceDir(aid, root = resolveRoot()) {
|
|
110
|
+
return path.join(root, 'agents', aid, 'workspace');
|
|
111
|
+
}
|
|
112
|
+
/** Historical default workspace location, read only for one-time relocation. */
|
|
113
|
+
export function legacyTeamWorkspaceDir(aid, root = resolveRoot()) {
|
|
114
|
+
return path.join(root, 'team-workspaces', aid);
|
|
115
|
+
}
|
|
116
|
+
/** Agent-owned deliverables, independent of the current project/PA workspace. */
|
|
117
|
+
export function agentOutputDir(aid) {
|
|
118
|
+
return path.join(agentDir(aid), 'output');
|
|
119
|
+
}
|
|
108
120
|
export function agentConfig(aid) {
|
|
109
121
|
return path.join(agentDir(aid), 'config.json');
|
|
110
122
|
}
|
|
@@ -248,6 +260,14 @@ export function channelStatePath(channelKey, ...parts) {
|
|
|
248
260
|
export function agentTriggersDir(aid) {
|
|
249
261
|
return path.join(agentDir(aid), 'triggers');
|
|
250
262
|
}
|
|
263
|
+
/** 事件中心目录:events-config.json + 事件包(pack.json / ledger.jsonl / scripts/ / logs/)。 */
|
|
264
|
+
export function agentEventsDir(aid) {
|
|
265
|
+
return path.join(agentDir(aid), 'events');
|
|
266
|
+
}
|
|
267
|
+
/** 服务路由目录:services-config.json 与服务包(pack.json / scripts/ / logs/ / ledger)。 */
|
|
268
|
+
export function agentServicesDir(aid) {
|
|
269
|
+
return path.join(agentDir(aid), 'services');
|
|
270
|
+
}
|
|
251
271
|
/** 话题数据的统一根目录:索引、摘要、续读锚点、跨会话收件箱都收在这里。 */
|
|
252
272
|
export function agentThreadsDir(aid) {
|
|
253
273
|
return path.join(agentDataDir(aid), 'threads');
|
package/dist/product.js
CHANGED
|
@@ -21,6 +21,20 @@ export const TARGET_PACKAGE_ROOT_ENV = 'EVOLCORE_TARGET_PACKAGE_ROOT';
|
|
|
21
21
|
export const SESSION_ID_ENV = 'EVOLCORE_SESSION_ID';
|
|
22
22
|
export const SELF_AID_ENV = 'EVOLCORE_SELF_AID';
|
|
23
23
|
export const CODEX_HOOK_TOKEN_ENV = 'EVOLCORE_CODEX_HOOK_TOKEN';
|
|
24
|
+
/** Task identity and authority must not outlive the task in supervised services. */
|
|
25
|
+
export const SERVICE_SESSION_ENV_NAMES = [
|
|
26
|
+
SESSION_ID_ENV,
|
|
27
|
+
SELF_AID_ENV,
|
|
28
|
+
CODEX_HOOK_TOKEN_ENV,
|
|
29
|
+
'EVOLCORE_TASK_RUNTIME_CONTEXT',
|
|
30
|
+
'EVOLCORE_SESSION_RUNTIME_DIR',
|
|
31
|
+
'EVOLCORE_RUNTIME_LOCK_DIR',
|
|
32
|
+
'EVOLCORE_DELEGATION_TOKEN',
|
|
33
|
+
'EVOLCORE_CODEX_SESSION_TOKEN',
|
|
34
|
+
'EVOLCORE_DELEGATED_EXECUTION_SPEC',
|
|
35
|
+
'EVOLCORE_DAEMON_RUNTIME_EPOCH',
|
|
36
|
+
];
|
|
37
|
+
export const CODEX_HEADER_ENV_PREFIX = 'EVOLCORE_CODEX_HEADER_';
|
|
24
38
|
export const DEFAULT_RUNTIME_HOME_DIRNAME = '.evolcore';
|
|
25
39
|
export const INSTANCE_SOCKET_FILENAME = 'daemon.sock';
|
|
26
40
|
export const WINDOWS_PIPE_PREFIX = 'daemon';
|
package/dist/proxy/manager.js
CHANGED
|
@@ -225,10 +225,11 @@ export class ServiceProxyManager {
|
|
|
225
225
|
return { ok: true, operations: [...MUTATIONS], reloadByMode: { managed: 'restart', external: 'unmanaged' } };
|
|
226
226
|
}
|
|
227
227
|
if (request.operation === 'list' || request.operation === 'status') {
|
|
228
|
+
const selectedServices = request.operation === 'status' && service ? [service] : services;
|
|
228
229
|
return {
|
|
229
230
|
ok: true,
|
|
230
231
|
providerAid: this.options.providerAid,
|
|
231
|
-
services:
|
|
232
|
+
services: selectedServices.map(item => ({
|
|
232
233
|
...this.describe(item),
|
|
233
234
|
configRev: serviceRevision(item),
|
|
234
235
|
runtime: (item.name === 'ecweb' && serviceRuntimeMode(item) === 'managed' ? this.options.ecwebSupervisor?.status() : undefined)
|
|
@@ -236,6 +237,9 @@ export class ServiceProxyManager {
|
|
|
236
237
|
name: item.name, state: item.enabled ? 'unknown' : 'disabled',
|
|
237
238
|
failureCount: 0, restartCount: 0, generation: 0,
|
|
238
239
|
managed: serviceRuntimeMode(item) === 'managed',
|
|
240
|
+
healthy: null,
|
|
241
|
+
hasProbe: !!item.port || (item.name === 'ecweb' && serviceRuntimeMode(item) === 'managed'),
|
|
242
|
+
endpointHealth: 'unknown',
|
|
239
243
|
},
|
|
240
244
|
})),
|
|
241
245
|
proxy: { ...this.proxyTransport },
|
|
@@ -9,6 +9,7 @@ import { getProcessStartTimeAsync, startTimeMatches } from '../utils/process-int
|
|
|
9
9
|
import * as platform from '../utils/cross-platform.js';
|
|
10
10
|
import { logger as defaultLogger } from '../utils/logger.js';
|
|
11
11
|
import { atomicWriteJson } from '../utils/atomic-write.js';
|
|
12
|
+
import { sanitizeServiceEnvironment } from '../core/permission/shell-environment.js';
|
|
12
13
|
function sleep(ms) {
|
|
13
14
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
14
15
|
}
|
|
@@ -262,7 +263,10 @@ export class ServiceSupervisor {
|
|
|
262
263
|
return this.queueOperation(name, async () => {
|
|
263
264
|
const active = this.active.get(name);
|
|
264
265
|
if (!active)
|
|
265
|
-
return {
|
|
266
|
+
return {
|
|
267
|
+
name, state: 'disabled', failureCount: 0, restartCount: 0, generation: 0, managed: false,
|
|
268
|
+
healthy: null, hasProbe: !!this.desired.get(name)?.port, endpointHealth: 'unknown',
|
|
269
|
+
};
|
|
266
270
|
if (active.config.runtime?.mode !== 'managed') {
|
|
267
271
|
throw Object.assign(new Error('external service lifecycle is not managed: ' + name), { code: 'EXTERNAL_SERVICE_UNMANAGED' });
|
|
268
272
|
}
|
|
@@ -491,6 +495,8 @@ export class ServiceSupervisor {
|
|
|
491
495
|
}
|
|
492
496
|
active.intentionalStop = false;
|
|
493
497
|
active.state = 'starting';
|
|
498
|
+
active.healthy = undefined;
|
|
499
|
+
active.checkedAt = undefined;
|
|
494
500
|
active.lastError = undefined;
|
|
495
501
|
active.lastErrorCode = undefined;
|
|
496
502
|
const run = async () => {
|
|
@@ -512,7 +518,7 @@ export class ServiceSupervisor {
|
|
|
512
518
|
// service away from services[].port and make readiness probe the
|
|
513
519
|
// wrong listener.
|
|
514
520
|
env: {
|
|
515
|
-
...process.env,
|
|
521
|
+
...sanitizeServiceEnvironment(process.env),
|
|
516
522
|
...(active.config.port === undefined ? {} : { PORT: String(active.config.port) }),
|
|
517
523
|
},
|
|
518
524
|
});
|
|
@@ -852,15 +858,18 @@ export class ServiceSupervisor {
|
|
|
852
858
|
}
|
|
853
859
|
}
|
|
854
860
|
snapshotOne(active) {
|
|
861
|
+
const hasProbe = !!active.config.port;
|
|
862
|
+
const healthy = hasProbe && active.state !== 'disabled' ? active.healthy ?? null : null;
|
|
855
863
|
return {
|
|
856
864
|
name: active.config.name,
|
|
857
865
|
state: active.state,
|
|
858
866
|
...(active.pid ? { pid: active.pid } : {}),
|
|
859
867
|
...(active.config.port ? { port: active.config.port } : {}),
|
|
860
868
|
...(active.startedAt ? { startedAt: active.startedAt } : {}),
|
|
861
|
-
|
|
869
|
+
healthy,
|
|
870
|
+
hasProbe,
|
|
862
871
|
...(active.checkedAt ? { checkedAt: active.checkedAt } : {}),
|
|
863
|
-
endpointHealth:
|
|
872
|
+
endpointHealth: healthy === null ? 'unknown' : healthy ? 'healthy' : 'unhealthy',
|
|
864
873
|
failureCount: active.failureCount,
|
|
865
874
|
restartCount: active.restartCount,
|
|
866
875
|
...(active.lastError ? { lastError: active.lastError } : {}),
|
|
@@ -137,9 +137,11 @@ function hasSuccessfulSendReceipt(result, isError, requiresBusinessReturn = fals
|
|
|
137
137
|
return false;
|
|
138
138
|
}
|
|
139
139
|
function sendHint(state) {
|
|
140
|
+
// 提示与 `[reply]` 段、ECK 模板保持同一口径:正式回复统一写 `ecmsg send`。
|
|
141
|
+
// 私聊与群聊它会自己落到 `ec msg send` / `ec group send`,不必让模型两套写法轮换。
|
|
140
142
|
return state.chatType === 'group'
|
|
141
|
-
? { cmdHint: '
|
|
142
|
-
: { cmdHint: '
|
|
143
|
+
? { cmdHint: 'ecmsg send', target: '群里' }
|
|
144
|
+
: { cmdHint: 'ecmsg send', target: '对方' };
|
|
143
145
|
}
|
|
144
146
|
/**
|
|
145
147
|
* 结算当前轮:本轮有意图表达成功 → 清零(不再 +1);否则 +1。
|
|
@@ -16,7 +16,7 @@ import { isChatMode } from '../../../core/message/peer-mode.js';
|
|
|
16
16
|
* 单会话响应模式(architecture.md §4.1)—— 合并原 interactive / proactive。
|
|
17
17
|
*
|
|
18
18
|
* 本层是薄包装:不含处理行为,全部钩子委托 V1 引擎的 flow。chatMode 决定用哪个
|
|
19
|
-
* flow(interactive / proactive
|
|
19
|
+
* flow(interactive / proactive),取值来自 modeConfig.chatMode(宿主按配置层级
|
|
20
20
|
* 解析后注入,见 implementation-plan.md §三;无 auto 值)。
|
|
21
21
|
*/
|
|
22
22
|
export class SingleSessionMode {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 服务分发:全局并发上限 + 每包队列容量。
|
|
3
|
+
*
|
|
4
|
+
* 与 event-center 的 dispatcher 不同:服务调用需要「等到脚本结果才能回复」,
|
|
5
|
+
* 所以这里是带背压的 await 语义,而不是 fire-and-forget。队列满时立即
|
|
6
|
+
* 用 QUEUE_FULL 拒绝,避免调用方无限等待。
|
|
7
|
+
*/
|
|
8
|
+
import { logger } from '../utils/logger.js';
|
|
9
|
+
export const DEFAULT_DISPATCHER_LIMITS = { maxConcurrency: 5, queueSize: 100 };
|
|
10
|
+
export class ServiceDispatcher {
|
|
11
|
+
scriptRunner;
|
|
12
|
+
limits;
|
|
13
|
+
running = 0;
|
|
14
|
+
waiters = [];
|
|
15
|
+
pendingByPack = new Map();
|
|
16
|
+
closed = false;
|
|
17
|
+
constructor(scriptRunner, limits = DEFAULT_DISPATCHER_LIMITS) {
|
|
18
|
+
this.scriptRunner = scriptRunner;
|
|
19
|
+
this.limits = limits;
|
|
20
|
+
}
|
|
21
|
+
setLimits(limits) {
|
|
22
|
+
this.limits = { ...this.limits, ...limits };
|
|
23
|
+
}
|
|
24
|
+
/** 队列满 / 已关闭时返回 QUEUE_FULL / DISPATCHER_CLOSED 结果,不抛错。 */
|
|
25
|
+
async run(pack, handler, message) {
|
|
26
|
+
if (this.closed) {
|
|
27
|
+
return {
|
|
28
|
+
outcome: 'error',
|
|
29
|
+
exitCode: 0,
|
|
30
|
+
durationMs: 0,
|
|
31
|
+
stdoutPreview: '',
|
|
32
|
+
stderrPreview: '',
|
|
33
|
+
error: { code: 'DISPATCHER_CLOSED', message: 'services dispatcher is shutting down' },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const pending = this.pendingByPack.get(pack.id) ?? 0;
|
|
37
|
+
if (pending >= this.limits.queueSize) {
|
|
38
|
+
return {
|
|
39
|
+
outcome: 'error',
|
|
40
|
+
exitCode: 0,
|
|
41
|
+
durationMs: 0,
|
|
42
|
+
stdoutPreview: '',
|
|
43
|
+
stderrPreview: '',
|
|
44
|
+
error: { code: 'QUEUE_FULL', message: `service pack ${pack.id} queue is full` },
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
this.pendingByPack.set(pack.id, pending + 1);
|
|
48
|
+
try {
|
|
49
|
+
await this.acquire();
|
|
50
|
+
try {
|
|
51
|
+
return await this.scriptRunner.run(pack, handler, message);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
logger.warn(`[Services] ${pack.id} handler for ${message.type} crashed: ${error instanceof Error ? error.message : String(error)}`);
|
|
55
|
+
return {
|
|
56
|
+
outcome: 'error',
|
|
57
|
+
exitCode: 0,
|
|
58
|
+
durationMs: 0,
|
|
59
|
+
stdoutPreview: '',
|
|
60
|
+
stderrPreview: '',
|
|
61
|
+
error: { code: 'DISPATCHER_ERROR', message: error instanceof Error ? error.message : String(error) },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
this.release();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
const remaining = (this.pendingByPack.get(pack.id) ?? 1) - 1;
|
|
70
|
+
if (remaining <= 0)
|
|
71
|
+
this.pendingByPack.delete(pack.id);
|
|
72
|
+
else
|
|
73
|
+
this.pendingByPack.set(pack.id, remaining);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
acquire() {
|
|
77
|
+
if (this.running < this.limits.maxConcurrency) {
|
|
78
|
+
this.running++;
|
|
79
|
+
return Promise.resolve();
|
|
80
|
+
}
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
this.waiters.push({ resolve, reject });
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
release() {
|
|
86
|
+
const waiter = this.waiters.shift();
|
|
87
|
+
if (waiter)
|
|
88
|
+
waiter.resolve();
|
|
89
|
+
else
|
|
90
|
+
this.running = Math.max(0, this.running - 1);
|
|
91
|
+
}
|
|
92
|
+
/** 关闭:拒绝新任务,唤醒所有等待者让其按 DISPATCHER_CLOSED 返回。 */
|
|
93
|
+
close() {
|
|
94
|
+
this.closed = true;
|
|
95
|
+
this.pendingByPack.clear();
|
|
96
|
+
for (const waiter of this.waiters.splice(0)) {
|
|
97
|
+
waiter.resolve();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 包内幂等(.idempotency.jsonl):按 (fromAid, request_id) 去重,窗口 24 小时。
|
|
3
|
+
*
|
|
4
|
+
* 与 `claimInboundMessage` 是两层不同的东西:后者管传输层 `message_id` 重投,
|
|
5
|
+
* 这里管对端用同一 `request_id` 重试。命中时回上次结果,脚本不再执行。
|
|
6
|
+
*/
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
export const IDEMPOTENCY_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
10
|
+
function key(from, requestId) {
|
|
11
|
+
return `${from}\u0000${requestId}`;
|
|
12
|
+
}
|
|
13
|
+
export class IdempotencyStore {
|
|
14
|
+
filePath;
|
|
15
|
+
records = new Map();
|
|
16
|
+
loadedMtimeMs = -1;
|
|
17
|
+
constructor(filePath) {
|
|
18
|
+
this.filePath = filePath;
|
|
19
|
+
}
|
|
20
|
+
/** 按文件 mtime 懒加载;文件被外部改动时重读。 */
|
|
21
|
+
ensureLoaded(now = Date.now()) {
|
|
22
|
+
let mtimeMs = 0;
|
|
23
|
+
try {
|
|
24
|
+
mtimeMs = fs.statSync(this.filePath).mtimeMs;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// 文件不存在:视为空表。
|
|
28
|
+
}
|
|
29
|
+
if (mtimeMs === this.loadedMtimeMs) {
|
|
30
|
+
this.evict(now);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.records.clear();
|
|
34
|
+
try {
|
|
35
|
+
const text = fs.readFileSync(this.filePath, 'utf8');
|
|
36
|
+
for (const line of text.split('\n')) {
|
|
37
|
+
if (!line)
|
|
38
|
+
continue;
|
|
39
|
+
try {
|
|
40
|
+
const record = JSON.parse(line);
|
|
41
|
+
if (typeof record.from === 'string' && typeof record.requestId === 'string'
|
|
42
|
+
&& Number.isFinite(record.ts) && record.result && typeof record.result === 'object') {
|
|
43
|
+
this.records.set(key(record.from, record.requestId), record);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// 跳过坏行
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// 读失败按空表处理,下次调用再试。
|
|
53
|
+
}
|
|
54
|
+
this.loadedMtimeMs = mtimeMs;
|
|
55
|
+
this.evict(now);
|
|
56
|
+
}
|
|
57
|
+
evict(now) {
|
|
58
|
+
const cutoff = now - IDEMPOTENCY_WINDOW_MS;
|
|
59
|
+
for (const [entryKey, record] of this.records) {
|
|
60
|
+
if (record.ts < cutoff)
|
|
61
|
+
this.records.delete(entryKey);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** 命中的上次结果;未命中返回 undefined。 */
|
|
65
|
+
lookup(from, requestId, now = Date.now()) {
|
|
66
|
+
this.ensureLoaded(now);
|
|
67
|
+
const record = this.records.get(key(from, requestId));
|
|
68
|
+
if (!record)
|
|
69
|
+
return undefined;
|
|
70
|
+
if (record.ts < now - IDEMPOTENCY_WINDOW_MS) {
|
|
71
|
+
this.records.delete(key(from, requestId));
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
return record;
|
|
75
|
+
}
|
|
76
|
+
/** 记录一次成功执行的结果。IO 失败吞掉:去重是优化,不是正确性前提。 */
|
|
77
|
+
record(from, requestId, result, now = Date.now()) {
|
|
78
|
+
this.ensureLoaded(now);
|
|
79
|
+
const record = { ts: now, from, requestId, result };
|
|
80
|
+
this.records.set(key(from, requestId), record);
|
|
81
|
+
try {
|
|
82
|
+
fs.mkdirSync(path.dirname(this.filePath), { recursive: true });
|
|
83
|
+
fs.appendFileSync(this.filePath, `${JSON.stringify(record)}\n`, 'utf8');
|
|
84
|
+
this.loadedMtimeMs = fs.statSync(this.filePath).mtimeMs;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// 写失败不影响本次回复,只是下次重试会再执行一遍。
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本机身份:type / exttype 从 agent.md frontmatter 读。
|
|
3
|
+
*
|
|
4
|
+
* `requires` 判定与 ECK 的 hasServicePacks 都读它。名片变更频率极低,
|
|
5
|
+
* 由调用方在加载时算一次并缓存,热重载(ec aid agentmd set)时失效。
|
|
6
|
+
*
|
|
7
|
+
* 优先读本地 `AIDs/<aid>/agent.md`(daemon 启动即可用,不依赖 AUN 连接);
|
|
8
|
+
* 本地缺失时再走 AIDStore.resolve(网络路径)。
|
|
9
|
+
*/
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import { agentMdPath } from '../paths.js';
|
|
12
|
+
import { parseAgentMdFrontmatter } from '../core/relation/peer-identity.js';
|
|
13
|
+
function identityFromFrontmatter(aid, frontmatter) {
|
|
14
|
+
const type = String(frontmatter?.type ?? 'agent').trim() || 'agent';
|
|
15
|
+
const exttype = String(frontmatter?.exttype ?? '').trim();
|
|
16
|
+
return { aid, type, exttype };
|
|
17
|
+
}
|
|
18
|
+
/** 本地名片(同步,不触发网络)。文件缺失时返回 undefined。 */
|
|
19
|
+
export function readLocalSelfIdentity(aid) {
|
|
20
|
+
try {
|
|
21
|
+
const content = fs.readFileSync(agentMdPath(aid), 'utf8');
|
|
22
|
+
return identityFromFrontmatter(aid, parseAgentMdFrontmatter(content));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 读本机名片的 type / exttype。
|
|
30
|
+
* `AIDStore.resolve` → `ResolveResult.agent_md.frontmatter`;`client.getType()` 只读 type。
|
|
31
|
+
* 本地读不到时才走网络。两处都读不到时按 `agent` / 空 exttype 处理(fail-closed:
|
|
32
|
+
* 只有 `requires` 含 `agent` 或 `*` 的包才会激活)。
|
|
33
|
+
*/
|
|
34
|
+
export async function resolveSelfIdentity(store, aid) {
|
|
35
|
+
const local = readLocalSelfIdentity(aid);
|
|
36
|
+
if (local)
|
|
37
|
+
return local;
|
|
38
|
+
if (!store)
|
|
39
|
+
return { aid, type: 'agent', exttype: '' };
|
|
40
|
+
try {
|
|
41
|
+
const result = await store.resolve(aid);
|
|
42
|
+
const frontmatter = result.ok ? result.data.agent_md?.frontmatter : undefined;
|
|
43
|
+
return identityFromFrontmatter(aid, frontmatter);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return { aid, type: 'agent', exttype: '' };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** services 模式:本机名片 type 精确等于 services。 */
|
|
50
|
+
export function isServicesIdentity(identity) {
|
|
51
|
+
return identity.type === 'services';
|
|
52
|
+
}
|