evolcore 0.0.43-test.6 → 0.0.43-test.7
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 +48 -0
- package/bin/ecmsg.js +171 -54
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +234 -21
- package/dist/cli/agent-create.js +2 -2
- package/dist/cli/daemon-commands.js +6 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/restart-monitor.js +45 -47
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-msg.js +1 -1
- 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 +6 -1
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +104 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +4 -3
- package/dist/core/command/agent-control.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +53 -11
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +338 -0
- package/dist/core/command/menu-catalog.js +8 -0
- package/dist/core/command/menu-handler.js +198 -84
- package/dist/core/command/menu-protocol.js +60 -11
- 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 +8 -5
- package/dist/core/daemon-lifecycle.js +132 -73
- package/dist/core/handoff/runtime.js +3 -3
- 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 +46 -7
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +147 -17
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/response-engine.js +157 -54
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +43 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/permission/ec-command-parser.js +3 -2
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +2 -3
- 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/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/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 +114 -0
- package/dist/event-center/bus-gate.js +136 -0
- package/dist/event-center/bus-host.js +290 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +100 -0
- package/dist/event-center/client-factory.js +50 -0
- package/dist/event-center/daemon.js +45 -0
- package/dist/event-center/directory-source.js +53 -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 +63 -0
- package/dist/event-center/ipc-operation.js +308 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +202 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +238 -0
- package/dist/event-center/runtime.js +641 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +35 -0
- package/dist/event-center/validation.js +413 -0
- package/dist/index.js +285 -99
- package/dist/ipc.js +66 -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/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 +458 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +204 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +95 -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/script-sandbox.js +118 -22
- 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/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 +7 -14
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -0
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +207 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +3 -2
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +15 -3
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +277 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- 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-service-proxy/SKILL.md +34 -5
- 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/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +0 -5
- package/kits/templates/system-fragments/thread.md +10 -8
- package/package.json +3 -5
- 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,7 @@ const LOCAL_CONTROL_COMMANDS = new Set([
|
|
|
76
76
|
'ecweb.ability',
|
|
77
77
|
'upgrade.op',
|
|
78
78
|
'provider.op',
|
|
79
|
+
'invoke.op',
|
|
79
80
|
'ecweb.init',
|
|
80
81
|
'ecweb.basic-settings',
|
|
81
82
|
'ecweb.message.context',
|
|
@@ -96,7 +97,7 @@ const MEMORY_COMMAND_ENDPOINTS = new Set([
|
|
|
96
97
|
'memory.create', 'memory.update', 'memory.archive', 'memory.demote', 'memory.consolidate',
|
|
97
98
|
]);
|
|
98
99
|
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',
|
|
100
|
+
'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
101
|
'upgrade.op',
|
|
101
102
|
'ctl', 'diag', 'menu-client.request', 'task.resume', 'queue.op', 'storage.auth', 'storage.upload',
|
|
102
103
|
'trigger.op', 'skill.refresh', 'thread.op', 'local-command-context', 'evolagent.bootstrapComplete', 'status.auth', 'logs.query', ...MEMORY_COMMAND_ENDPOINTS,
|
|
@@ -126,7 +127,7 @@ function requiresLocalControlToken(cmd) {
|
|
|
126
127
|
const type = String(cmd.type ?? '');
|
|
127
128
|
const sessionId = typeof cmd.sessionId === 'string' && cmd.sessionId.trim();
|
|
128
129
|
const delegated = typeof cmd.delegationToken === 'string' && cmd.delegationToken.trim();
|
|
129
|
-
if (type === 'provider.op' || type === 'upgrade.op')
|
|
130
|
+
if (type === 'provider.op' || type === 'upgrade.op' || type === 'invoke.op')
|
|
130
131
|
return !sessionId || !delegated || cmd.actorSessionId !== undefined;
|
|
131
132
|
if (cmd.type === 'evolagent.initialize' || LOCAL_CONTROL_COMMANDS.has(type))
|
|
132
133
|
return true;
|
|
@@ -135,7 +136,7 @@ function requiresLocalControlToken(cmd) {
|
|
|
135
136
|
// Ownership has an explicit, non-fallback authentication contract below.
|
|
136
137
|
if (type === 'aid.ownership')
|
|
137
138
|
return false;
|
|
138
|
-
if (type === 'skill.refresh' || type === 'thread.op')
|
|
139
|
+
if (type === 'skill.refresh' || type === 'thread.op' || type === 'events.op' || type === 'services.op')
|
|
139
140
|
return !sessionId || !delegated;
|
|
140
141
|
if (type === 'ability.op')
|
|
141
142
|
return !sessionId && !delegated;
|
|
@@ -216,6 +217,7 @@ export class IpcServer {
|
|
|
216
217
|
triggerExecutor;
|
|
217
218
|
proxyExecutor;
|
|
218
219
|
providerExecutor;
|
|
220
|
+
invokeExecutor;
|
|
219
221
|
upgradeExecutor;
|
|
220
222
|
consolidationLaunchExecutor;
|
|
221
223
|
consolidationCheckExecutor;
|
|
@@ -248,6 +250,8 @@ export class IpcServer {
|
|
|
248
250
|
msgOperationExecutor;
|
|
249
251
|
fsOperationExecutor;
|
|
250
252
|
threadOperationExecutor;
|
|
253
|
+
eventsOperationExecutor;
|
|
254
|
+
servicesOperationExecutor;
|
|
251
255
|
dingtalkContactBindExecutor;
|
|
252
256
|
feishuContactBindExecutor;
|
|
253
257
|
qqbotContactBindExecutor;
|
|
@@ -389,6 +393,12 @@ export class IpcServer {
|
|
|
389
393
|
setThreadOperationExecutor(executor) {
|
|
390
394
|
this.threadOperationExecutor = executor;
|
|
391
395
|
}
|
|
396
|
+
setEventsOperationExecutor(executor) {
|
|
397
|
+
this.eventsOperationExecutor = executor;
|
|
398
|
+
}
|
|
399
|
+
setServicesOperationExecutor(executor) {
|
|
400
|
+
this.servicesOperationExecutor = executor;
|
|
401
|
+
}
|
|
392
402
|
setAgentReloadExecutor(executor) {
|
|
393
403
|
this.agentReloadExecutor = executor;
|
|
394
404
|
}
|
|
@@ -541,6 +551,9 @@ export class IpcServer {
|
|
|
541
551
|
setProviderExecutor(executor) {
|
|
542
552
|
this.providerExecutor = executor;
|
|
543
553
|
}
|
|
554
|
+
setInvokeExecutor(executor) {
|
|
555
|
+
this.invokeExecutor = executor;
|
|
556
|
+
}
|
|
544
557
|
setUpgradeExecutor(executor) {
|
|
545
558
|
this.upgradeExecutor = executor;
|
|
546
559
|
}
|
|
@@ -1254,6 +1267,29 @@ export class IpcServer {
|
|
|
1254
1267
|
const { executeProviderOperation } = await import('./config/provider-ipc-service.js');
|
|
1255
1268
|
return executeProviderOperation({ argv: cmd.argv });
|
|
1256
1269
|
}
|
|
1270
|
+
case 'invoke.op': {
|
|
1271
|
+
const hasDelegatedFields = cmd.sessionId !== undefined || cmd.delegationToken !== undefined
|
|
1272
|
+
|| cmd.actorSessionId !== undefined;
|
|
1273
|
+
if (hasDelegatedFields) {
|
|
1274
|
+
if (typeof cmd.sessionId !== 'string' || !cmd.sessionId
|
|
1275
|
+
|| typeof cmd.delegationToken !== 'string' || !cmd.delegationToken
|
|
1276
|
+
|| cmd.actorSessionId !== undefined) {
|
|
1277
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'invoke.op requires a session and task delegation token' };
|
|
1278
|
+
}
|
|
1279
|
+
if (!this.invokeExecutor)
|
|
1280
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'managed invoke executor is unavailable' };
|
|
1281
|
+
return this.invokeExecutor({
|
|
1282
|
+
argv: cmd.argv,
|
|
1283
|
+
input: cmd.input,
|
|
1284
|
+
sessionId: cmd.sessionId,
|
|
1285
|
+
delegationToken: cmd.delegationToken,
|
|
1286
|
+
delegationCommandHash: cmd.delegationCommandHash,
|
|
1287
|
+
requestId,
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
const { executeInvokeOperation } = await import('./config/invoke-ipc-service.js');
|
|
1291
|
+
return executeInvokeOperation({ argv: cmd.argv, input: cmd.input });
|
|
1292
|
+
}
|
|
1257
1293
|
case 'upgrade.op': {
|
|
1258
1294
|
const hasDelegatedFields = cmd.sessionId !== undefined || cmd.delegationToken !== undefined
|
|
1259
1295
|
|| cmd.actorSessionId !== undefined;
|
|
@@ -1766,7 +1802,7 @@ export class IpcServer {
|
|
|
1766
1802
|
}
|
|
1767
1803
|
case 'local-command-context': {
|
|
1768
1804
|
if (!Array.isArray(cmd.argv) || cmd.argv.some((value) => typeof value !== 'string')
|
|
1769
|
-
|| !['skill', 'stats', 'session', '
|
|
1805
|
+
|| !['skill', 'stats', 'session', 'team'].includes(cmd.argv[0]) || typeof cmd.sessionId !== 'string' || !cmd.sessionId
|
|
1770
1806
|
|| typeof cmd.delegationToken !== 'string' || !cmd.delegationToken) {
|
|
1771
1807
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Local command requires argv and task credentials' };
|
|
1772
1808
|
}
|
|
@@ -1783,13 +1819,15 @@ export class IpcServer {
|
|
|
1783
1819
|
if (!context?.selfAid || !context.peerRole || context.peerRole === 'none') {
|
|
1784
1820
|
return { ok: false, code: 'NOT_ALLOWED', error: 'Current task identity and role are unavailable' };
|
|
1785
1821
|
}
|
|
1786
|
-
if (cmd.argv[0] === '
|
|
1822
|
+
if (cmd.argv[0] === 'team'
|
|
1787
1823
|
&& (context.channel !== 'aun' || context.chatType !== 'private' || context.peerRole !== 'owner' || !context.peerId)) {
|
|
1788
|
-
return { ok: false, code: 'NOT_ALLOWED', error: '
|
|
1824
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'Team workspace commands require the current Agent owner in an AUN private chat' };
|
|
1789
1825
|
}
|
|
1790
|
-
if (cmd.argv[0] === '
|
|
1791
|
-
&& (cmd.argv[1] === '
|
|
1792
|
-
|
|
1826
|
+
if (cmd.argv[0] === 'team' && context.permissionMode === 'readonly'
|
|
1827
|
+
&& (cmd.argv[1] === 'workspace' && cmd.argv[2] === 'init'
|
|
1828
|
+
|| cmd.argv[1] === 'navigation' && cmd.argv[2] === 'update'
|
|
1829
|
+
|| cmd.argv[1] === 'members' && cmd.argv[2] === 'update')) {
|
|
1830
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'Readonly tasks cannot change Team Workspace state' };
|
|
1793
1831
|
}
|
|
1794
1832
|
const fullAccessTask = context.processRole === 'fullaccess-run'
|
|
1795
1833
|
&& context.dataScope === 'daemon' && context.permissionMode === 'fullaccess';
|
|
@@ -1925,6 +1963,9 @@ export class IpcServer {
|
|
|
1925
1963
|
timeoutMs: typeof cmd.timeoutMs === 'number' && Number.isFinite(cmd.timeoutMs) ? cmd.timeoutMs : undefined,
|
|
1926
1964
|
delegationToken: typeof cmd.delegationToken === 'string' ? cmd.delegationToken : undefined,
|
|
1927
1965
|
delegationCommandHash: typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined,
|
|
1966
|
+
// 非托管自发(`ecmsg send --from <self> --thread T --to <self>`)没有委托凭证,
|
|
1967
|
+
// 用本机 controlToken 证明「这是本机控制面调用」;只对自发生效,见 sender。
|
|
1968
|
+
localControl: !cmd.delegationToken && this.hasValidControlToken(cmd.controlToken),
|
|
1928
1969
|
log,
|
|
1929
1970
|
});
|
|
1930
1971
|
}
|
|
@@ -2142,7 +2183,7 @@ export class IpcServer {
|
|
|
2142
2183
|
if (disabled)
|
|
2143
2184
|
return disabled;
|
|
2144
2185
|
const ownerAid = taskCtx.selfAid
|
|
2145
|
-
? ownerResolver.
|
|
2186
|
+
? ownerResolver.owner(taskCtx.selfAid)
|
|
2146
2187
|
: undefined;
|
|
2147
2188
|
const { launchConsolidation } = await import('./core/memory/consolidation.js');
|
|
2148
2189
|
if (!this.consolidationLaunchExecutor) {
|
|
@@ -2514,6 +2555,16 @@ export class IpcServer {
|
|
|
2514
2555
|
};
|
|
2515
2556
|
return await this.threadOperationExecutor(req);
|
|
2516
2557
|
}
|
|
2558
|
+
case 'events.op': {
|
|
2559
|
+
if (!this.eventsOperationExecutor)
|
|
2560
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'events.op not configured' };
|
|
2561
|
+
return await this.eventsOperationExecutor(cmd);
|
|
2562
|
+
}
|
|
2563
|
+
case 'services.op': {
|
|
2564
|
+
if (!this.servicesOperationExecutor)
|
|
2565
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'services.op not configured' };
|
|
2566
|
+
return await this.servicesOperationExecutor(cmd);
|
|
2567
|
+
}
|
|
2517
2568
|
case 'evolagent.initialize': {
|
|
2518
2569
|
if (cmd.sessionId || cmd.delegationToken)
|
|
2519
2570
|
return { ok: false, code: 'NOT_ALLOWED', error: 'Managed callers must use agent.op' };
|
|
@@ -2913,8 +2964,11 @@ export class IpcServer {
|
|
|
2913
2964
|
const disabled = this.checkMemoryEnabled(mc, mode, taskCtx);
|
|
2914
2965
|
if (disabled)
|
|
2915
2966
|
return { error: disabled };
|
|
2967
|
+
// Owner 判定必须与上下文注入同源:response-engine 侧用 resolveContextOwner(),
|
|
2968
|
+
// 底层同样是 ownerResolver.owner()。两处口径只能一起改,否则记忆会写进
|
|
2969
|
+
// 一个 owner 的目录、注入时却去另一个 owner 的目录找。
|
|
2916
2970
|
const ownerAid = taskCtx.selfAid
|
|
2917
|
-
? ownerResolver.
|
|
2971
|
+
? ownerResolver.owner(taskCtx.selfAid)
|
|
2918
2972
|
: undefined;
|
|
2919
2973
|
if (allowed === 'owner' && !ownerAid) {
|
|
2920
2974
|
return { error: { ok: false, code: 'INVALID_REQUEST', error: '当前 agent 未配置 owner' } };
|
|
@@ -2983,7 +3037,7 @@ export class IpcServer {
|
|
|
2983
3037
|
try {
|
|
2984
3038
|
if (!this.consolidationLaunchExecutor)
|
|
2985
3039
|
return;
|
|
2986
|
-
const ownerAid = ownerResolver.
|
|
3040
|
+
const ownerAid = ownerResolver.owner(selfAid);
|
|
2987
3041
|
await this.consolidationLaunchExecutor({
|
|
2988
3042
|
taskCtx,
|
|
2989
3043
|
mode: 'forget',
|
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
|
+
/** 事件中心目录:center.json + 事件包(pack.json / ledger.jsonl / scripts/ / logs/)。 */
|
|
264
|
+
export function agentEventsDir(aid) {
|
|
265
|
+
return path.join(agentDir(aid), 'events');
|
|
266
|
+
}
|
|
267
|
+
/** 服务路由目录:router.json 与服务包(service.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 } : {}),
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生成 `$AGENT_DIR/services/.index.md`:本机已激活服务包的清单。
|
|
3
|
+
*
|
|
4
|
+
* 只列 active 包(requires 已通过)。空集时删除文件而不是写空文件——
|
|
5
|
+
* 让 manifest 的 `optional` 判定与文件存在性始终一致。
|
|
6
|
+
*
|
|
7
|
+
* 格式见 docs/eck/services-and-events-manifest.md §五。
|
|
8
|
+
*/
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { logger } from '../utils/logger.js';
|
|
12
|
+
export const SERVICES_INDEX_FILE = '.index.md';
|
|
13
|
+
/**
|
|
14
|
+
* @param servicesDir `$AGENT_DIR/services`
|
|
15
|
+
* @param selfAid 本机 AID,用于示例命令
|
|
16
|
+
* @param activePacks 已激活的包(requires 通过且 enabled)
|
|
17
|
+
*/
|
|
18
|
+
export function writeServicesIndex(servicesDir, selfAid, activePacks) {
|
|
19
|
+
const filePath = path.join(servicesDir, SERVICES_INDEX_FILE);
|
|
20
|
+
if (activePacks.length === 0) {
|
|
21
|
+
try {
|
|
22
|
+
if (fs.existsSync(filePath)) {
|
|
23
|
+
fs.unlinkSync(filePath);
|
|
24
|
+
logger.debug(`[services-index] ${SERVICES_INDEX_FILE} 已删除(无激活服务包)`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
logger.warn(`[services-index] cannot remove stale index: ${error instanceof Error ? error.message : String(error)}`);
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const lines = [];
|
|
33
|
+
lines.push(`[services] 本 Agent 已激活 ${activePacks.length} 个服务包,对外提供以下服务调用。`);
|
|
34
|
+
lines.push('');
|
|
35
|
+
lines.push('调用方式(对端视角):');
|
|
36
|
+
lines.push(` ec services describe <本AID> 查看完整参数与示例`);
|
|
37
|
+
lines.push(` ec services call <本AID> <type> --data '<json>'`);
|
|
38
|
+
lines.push('');
|
|
39
|
+
lines.push('本机管理:');
|
|
40
|
+
lines.push(' ec services status / doctor / ledger / tail / reload');
|
|
41
|
+
lines.push('');
|
|
42
|
+
lines.push('可用服务(type 即对端应发送的 payload.type):');
|
|
43
|
+
for (const pack of activePacks) {
|
|
44
|
+
lines.push(`- ${pack.id}(${pack.name})`);
|
|
45
|
+
for (const entry of pack.listen) {
|
|
46
|
+
const timeoutMs = entry.handler.timeoutMs ?? 30_000;
|
|
47
|
+
lines.push(` ${entry.type} ${entry.handler.script} timeout ${formatTimeout(timeoutMs)}`);
|
|
48
|
+
}
|
|
49
|
+
const first = pack.listen[0];
|
|
50
|
+
if (first) {
|
|
51
|
+
lines.push(` 示例: ec services call ${selfAid} ${exampleType(first.type)} --data '{}'`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
lines.push('');
|
|
55
|
+
try {
|
|
56
|
+
fs.mkdirSync(servicesDir, { recursive: true });
|
|
57
|
+
fs.writeFileSync(filePath, lines.join('\n'), 'utf8');
|
|
58
|
+
logger.debug(`[services-index] ${SERVICES_INDEX_FILE} 已生成(${activePacks.length} 个包)`);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
logger.warn(`[services-index] cannot write index: ${error instanceof Error ? error.message : String(error)}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** 通配 listen 的示例用具体 action 名,避免把 `*` 写进可复制命令。 */
|
|
65
|
+
function exampleType(listenType) {
|
|
66
|
+
return listenType.endsWith('.*') ? `${listenType.slice(0, -1)}example` : listenType;
|
|
67
|
+
}
|
|
68
|
+
function formatTimeout(timeoutMs) {
|
|
69
|
+
return timeoutMs % 1000 === 0 ? `${timeoutMs / 1000}s` : `${timeoutMs}ms`;
|
|
70
|
+
}
|