evolcore 0.0.49 → 0.0.50
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 +64 -1
- package/bin/ecmsg.js +9 -4
- package/dist/ability/caller/authorization.js +21 -0
- package/dist/ability/caller/command.js +164 -0
- package/dist/ability/caller/contract.js +102 -0
- package/dist/ability/caller/daemon.js +158 -0
- package/dist/ability/caller/service.js +380 -0
- package/dist/ability/command-contract.js +5 -0
- package/dist/ability/daemon.js +5 -1
- package/dist/ability/interop-v1.js +10 -3
- package/dist/ability/management.js +1 -0
- package/dist/agent-template/jobs.js +173 -1
- package/dist/agent-template/runtime.js +280 -6
- package/dist/agent-template/service.js +1159 -40
- package/dist/agent-template/types.js +2 -1
- package/dist/agents/baseagent-availability.js +27 -3
- package/dist/agents/baseagent-capability-adapter.js +102 -0
- package/dist/agents/baseagent-plugin-descriptor.js +274 -0
- package/dist/agents/baseagent-plugin-loader.js +145 -0
- package/dist/agents/baseagent.js +68 -2
- package/dist/agents/claude-gateway/agent-registration.js +389 -0
- package/dist/agents/claude-gateway/binding.js +96 -0
- package/dist/agents/claude-gateway/inbox.js +138 -0
- package/dist/agents/claude-gateway/index.js +125 -0
- package/dist/agents/claude-gateway/listing.js +330 -0
- package/dist/agents/claude-gateway/router.js +328 -0
- package/dist/agents/claude-gateway/sessions.js +128 -0
- package/dist/agents/claude-gateway/terminal.js +250 -0
- package/dist/agents/claude-gateway/transcript.js +272 -0
- package/dist/agents/claude-gateway/types.js +14 -0
- package/dist/agents/claude-runner.js +6 -10
- package/dist/agents/codex-runner.js +4 -1
- package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
- package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
- package/dist/agents/gemini/index.js +51 -0
- package/dist/aun/aid/control-aid.js +52 -32
- package/dist/aun/group/invite-service.js +6 -36
- package/dist/aun/group/operations.js +6 -0
- package/dist/aun/msg/mention-schema.js +1 -1
- package/dist/aun/msg/p2p.js +29 -1
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +537 -189
- package/dist/cli/ability-command.js +42 -0
- package/dist/cli/agent-command.js +20 -1
- package/dist/cli/agent-create.js +78 -18
- package/dist/cli/agent-template.js +5 -3
- package/dist/cli/agent.js +91 -0
- package/dist/cli/aun-commands.js +92 -34
- package/dist/cli/bench.js +5 -2
- package/dist/cli/config.js +22 -6
- package/dist/cli/daemon-commands.js +245 -101
- package/dist/cli/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +23 -4
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +1 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/services-command.js +11 -9
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +17 -8
- package/dist/config/config-manager.js +86 -46
- package/dist/config/config-operation-service.js +22 -1
- package/dist/config/gateway-config.js +9 -8
- package/dist/config/owner-config.js +0 -16
- package/dist/config/peer-role-resolver.js +1 -7
- package/dist/config/providers-config.js +99 -16
- package/dist/config/providers-management.js +35 -19
- package/dist/config/resolved-config-op.js +1 -42
- package/dist/config/schema-migration.js +78 -5
- package/dist/config/schema-registry.js +52 -7
- package/dist/config-store.js +1309 -17
- package/dist/core/agent-application-service.js +220 -1
- package/dist/core/agent-ipc-registration.js +19 -2
- package/dist/core/agent-reload-coordinator.js +5 -0
- package/dist/core/agent-runtime.js +198 -54
- package/dist/core/auth/agent-delegation.js +14 -0
- package/dist/core/auth/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +50 -7
- package/dist/core/baseagent-loader.js +30 -3
- package/dist/core/capability/capability-manager.js +16 -7
- package/dist/core/channel-runtime.js +4 -2
- package/dist/core/command/agent-control.js +20 -2
- package/dist/core/command/agent-template-menu.js +4 -3
- package/dist/core/command/cli-intent-parser.js +15 -0
- package/dist/core/command/menu-catalog.js +20 -4
- package/dist/core/command/menu-file-path.js +70 -0
- package/dist/core/command/menu-handler.js +91 -72
- package/dist/core/command/menu-protocol.js +5 -0
- package/dist/core/command/menu-query-batch.js +2 -2
- package/dist/core/command/private-mention-menu.js +71 -0
- package/dist/core/command/slash-handler.js +17 -26
- package/dist/core/command/team-workspace-bootstrap.js +2 -1
- package/dist/core/command/topic-slash.js +7 -1
- package/dist/core/daemon-bootstrap.js +0 -4
- package/dist/core/daemon-control.js +2 -1
- package/dist/core/daemon-lifecycle.js +13 -5
- package/dist/core/evolagent-registry.js +12 -7
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/core/host-snapshot.js +8 -3
- package/dist/core/initialization/service.js +3 -0
- package/dist/core/interaction-router.js +130 -0
- package/dist/core/ipc-registration.js +4 -0
- package/dist/core/memory/consolidation-context.js +2 -1
- package/dist/core/memory/consolidation.js +35 -64
- package/dist/core/message/aun-ipc-sender.js +98 -21
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/message-bridge.js +105 -6
- package/dist/core/message/message-log.js +8 -0
- package/dist/core/message/message-queue.js +5 -3
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +23 -8
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +4 -0
- package/dist/core/permission/ec-command-parser.js +182 -58
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +9 -2
- package/dist/core/permission/tool-policy.js +21 -9
- package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
- package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
- package/dist/core/session/session-manager.js +47 -10
- package/dist/core/session/session-mapper.js +16 -0
- package/dist/core/skill/index-generator.js +2 -3
- package/dist/core/skill/switch-resolver.js +3 -0
- package/dist/core/thread/command-parser.js +4 -1
- package/dist/core/thread/ipc-operation.js +4 -2
- package/dist/core/thread/thread-operation.js +25 -10
- package/dist/core/thread/thread-service.js +294 -55
- package/dist/core/thread/topic-id.js +52 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/eck/kit-renderer.js +2 -1
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/index.js +116 -41
- package/dist/ipc.js +58 -2
- package/dist/paths.js +48 -1
- package/dist/pay/command.js +38 -0
- package/dist/pay/protocol.js +136 -0
- package/dist/pay/runtime.js +188 -0
- package/dist/pay/service.js +384 -0
- package/dist/pay/store.js +81 -0
- package/dist/response-system/engines/v1/proactive-flow.js +29 -2
- package/dist/services/dispatcher.js +23 -5
- package/dist/services/host/main.js +388 -0
- package/dist/services/host/protocol.js +118 -0
- package/dist/services/host/resident.js +310 -0
- package/dist/services/host-client.js +386 -0
- package/dist/services/host-deploy.js +180 -0
- package/dist/services/host-launch.js +117 -0
- package/dist/services/host-recycle.js +203 -0
- package/dist/services/host-runtime.js +802 -0
- package/dist/services/idempotency.js +44 -86
- package/dist/services/index-generator.js +4 -3
- package/dist/services/index.js +176 -18
- package/dist/services/ipc-operation.js +204 -44
- package/dist/services/script-runner.js +515 -83
- package/dist/services/validation.js +109 -4
- package/dist/trigger/application-service.js +6 -4
- package/dist/trigger/local-files.js +19 -9
- package/dist/trigger/scheduler.js +22 -12
- package/dist/trigger/script-sandbox.js +51 -20
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +73 -0
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- package/dist/utils/restart-safety.js +14 -1
- package/dist/utils/system-memory.js +113 -25
- package/dist/utils/systemd-lifecycle.js +154 -0
- package/dist/utils/windows-shell-trust.js +7 -3
- package/kits/docs/INDEX.md +3 -2
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/evolcore/INDEX.md +7 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +20 -3
- package/kits/docs/evolcore/config.md +1 -1
- package/kits/docs/evolcore/group.md +2 -1
- package/kits/docs/evolcore/memory-tags.md +2 -0
- package/kits/docs/evolcore/menu-client.md +3 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -0
- package/kits/docs/evolcore/model.md +3 -0
- package/kits/docs/evolcore/msg.md +68 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +21 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -0
- package/kits/rules/01-overview.md +11 -32
- package/kits/rules/02-navigation.md +7 -0
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +38 -5
- package/kits/schemas/agent-config.schema.21.json +974 -0
- package/kits/schemas/agent-config.schema.22.json +977 -0
- package/kits/schemas/agent-config.schema.23.json +958 -0
- package/kits/schemas/daemon.schema.10.json +373 -0
- package/kits/schemas/daemon.schema.9.json +12 -0
- package/kits/schemas/defaults.schema.7.json +472 -0
- package/kits/schemas/providers.schema.3.json +18 -2
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/skills/.switches.json +13 -1
- package/kits/skills/ability/SKILL.md +229 -34
- package/kits/skills/ability/STRUCTURE.md +333 -0
- package/kits/skills/ability/references/cli.md +208 -0
- package/kits/skills/ability/references/development.md +107 -37
- package/kits/skills/ability/references/management.md +106 -46
- package/kits/skills/ability/references/runtime-protocol.md +65 -63
- package/kits/skills/agent-output-cards/SKILL.md +12 -5
- package/kits/skills/ec-group/SKILL.md +8 -6
- package/kits/skills/ec-group/TASK.md +186 -0
- package/kits/skills/ec-group/WORKLOG.md +180 -0
- package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
- package/kits/skills/ec-pay/SKILL.md +101 -0
- package/kits/skills/ec-pay/references/pay-cli.md +110 -0
- package/kits/skills/ec-provider/SKILL.md +1 -1
- package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
- package/kits/skills/ec-service-call/SKILL.md +135 -0
- package/kits/skills/ec-service-pack/SKILL.md +277 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/workflow.md +46 -0
- package/kits/templates/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +4 -3
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +27 -129
- package/kits/templates/system-fragments/venue.md +16 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +37 -23
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +16 -4
- package/scripts/agent-template/shared/team-schema.json +20 -4
- package/scripts/agent-template/shared/template-contract.mjs +53 -13
- package/scripts/agent-template/shared/template-package.mjs +90 -26
- package/scripts/agent-template/shared/template-runtime.mjs +111 -1
- package/scripts/agent-template/shared/template.mjs +65 -7
- package/scripts/agent-template/team-pack.mjs +89 -33
- package/scripts/agent-template/team-preview.mjs +249 -5
- package/kits/docs/aun/ABILITY_CALLING.md +0 -280
- package/kits/docs/evolcore/ability.md +0 -185
- package/kits/skills/ability/references/calling.md +0 -56
- package/kits/skills/ability/references/contract-checklist.md +0 -37
- package/kits/skills/ability/references/recovery.md +0 -27
- /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { ConfigTarget, mutateConfig, read } from '../../config/config-manager.js';
|
|
3
|
+
const MODES = ['disabled', 'mention-only'];
|
|
4
|
+
export function validatePrivateMentionMenuRequest(request) {
|
|
5
|
+
if (!['menu.query', 'menu.options', 'menu.update'].includes(String(request.type))) {
|
|
6
|
+
return { code: 'NOT_SUPPORTED', message: 'private-mention-mode supports query, options and update' };
|
|
7
|
+
}
|
|
8
|
+
const args = request.args;
|
|
9
|
+
if (args !== undefined && (!args || typeof args !== 'object' || Array.isArray(args))) {
|
|
10
|
+
return { code: 'INVALID_ARGUMENT', message: 'args must be an object' };
|
|
11
|
+
}
|
|
12
|
+
if (args?.scope !== undefined && args.scope !== 'agent') {
|
|
13
|
+
return { code: 'SCOPE_MISMATCH', message: 'Private mention mode is Agent-scoped' };
|
|
14
|
+
}
|
|
15
|
+
const allowed = ['scope', 'self', 'context', ...(request.type === 'menu.update' ? ['expectedRevision'] : [])];
|
|
16
|
+
if (Object.keys(args ?? {}).some(key => !allowed.includes(key))) {
|
|
17
|
+
return { code: 'INVALID_ARGUMENT', message: 'Unsupported private-mention-mode argument' };
|
|
18
|
+
}
|
|
19
|
+
if (request.type === 'menu.update') {
|
|
20
|
+
if (!MODES.includes(request.value)) {
|
|
21
|
+
return { code: 'INVALID_ARGUMENT', message: 'value must be disabled or mention-only' };
|
|
22
|
+
}
|
|
23
|
+
if (typeof args?.expectedRevision !== 'string' || !args.expectedRevision.trim()) {
|
|
24
|
+
return { code: 'INVALID_ARGUMENT', message: 'args.expectedRevision is required' };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
function state(self, config) {
|
|
30
|
+
const override = MODES.includes(config?.privateMentionMode)
|
|
31
|
+
? config.privateMentionMode : null;
|
|
32
|
+
return {
|
|
33
|
+
scope: 'agent',
|
|
34
|
+
mode: override ?? 'disabled',
|
|
35
|
+
override,
|
|
36
|
+
source: override === null ? 'builtin' : 'agent',
|
|
37
|
+
revision: 'sha256:' + createHash('sha256').update(JSON.stringify([self, 'privateMentionMode', override])).digest('hex'),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Called after the standard Menu operation authorization; never spawns a CLI. */
|
|
41
|
+
export function executePrivateMentionMenu(kind, self, role, args, value) {
|
|
42
|
+
const invalid = validatePrivateMentionMenuRequest({ type: `menu.${kind}`, args, value });
|
|
43
|
+
if (invalid)
|
|
44
|
+
throw invalid;
|
|
45
|
+
if (!self)
|
|
46
|
+
throw { code: 'MISSING_AID', message: 'A target Agent is required' };
|
|
47
|
+
if (args?.self !== undefined && args.self !== self) {
|
|
48
|
+
throw { code: 'FORBIDDEN', message: 'Only the receiving Agent may be targeted' };
|
|
49
|
+
}
|
|
50
|
+
if (kind === 'update') {
|
|
51
|
+
// Keep this invariant even if a trusted fullaccess policy bypasses role rules.
|
|
52
|
+
if (role !== 'owner')
|
|
53
|
+
throw { code: 'FORBIDDEN', message: 'Private mention mode can only be changed by the Agent Owner' };
|
|
54
|
+
const mutation = mutateConfig(ConfigTarget.Agent, { self }, config => {
|
|
55
|
+
const current = state(self, config);
|
|
56
|
+
if (current.revision !== args.expectedRevision) {
|
|
57
|
+
throw { code: 'CONFLICT', message: 'Private mention mode has changed', data: { currentRevision: current.revision } };
|
|
58
|
+
}
|
|
59
|
+
config.privateMentionMode = value;
|
|
60
|
+
return state(self, config);
|
|
61
|
+
});
|
|
62
|
+
return { ...mutation.value, changed: mutation.changed, effectiveFrom: 'next-message' };
|
|
63
|
+
}
|
|
64
|
+
const current = state(self, read(ConfigTarget.Agent, { self }, { cache: false }));
|
|
65
|
+
if (kind === 'query')
|
|
66
|
+
return current;
|
|
67
|
+
return [
|
|
68
|
+
{ value: 'disabled', label: '处理所有私聊消息' },
|
|
69
|
+
{ value: 'mention-only', label: '只处理被 @ 的私聊消息' },
|
|
70
|
+
].map(item => ({ ...item, selected: item.value === current.mode, revision: current.revision }));
|
|
71
|
+
}
|
|
@@ -4,12 +4,12 @@ import { normalizeBaseagent, resolveBaseagentModelSelection } from '../../agents
|
|
|
4
4
|
import { buildEnvelope, isDeliveryTargetForChannel } from '../message/message-utils.js';
|
|
5
5
|
import { resolvePaths, getPackageRoot, daemonControlDir } from '../../paths.js';
|
|
6
6
|
import { logger } from '../../utils/logger.js';
|
|
7
|
-
import { shouldSuppressRealRestart, createRestartRequest, updateRestartRequest, removeRestartRequest } from '../../utils/restart-safety.js';
|
|
8
|
-
import { RESTART_REQUEST_ID_ENV } from '../../product.js';
|
|
7
|
+
import { shouldSuppressRealRestart, createRestartRequest, readRestartRequest, updateRestartRequest, removeRestartRequest } from '../../utils/restart-safety.js';
|
|
8
|
+
import { RESTART_REQUEST_ID_ENV, RUNTIME_HOME_ENV, SESSION_ID_ENV } from '../../product.js';
|
|
9
|
+
import { AGENT_DELEGATION_TOKEN_ENV } from '../auth/agent-delegation.js';
|
|
9
10
|
import crypto from 'crypto';
|
|
10
11
|
import path from 'path';
|
|
11
12
|
import fs from 'fs';
|
|
12
|
-
import { ensureFreshPackageVersionInfo } from '../../utils/package-version-info.js';
|
|
13
13
|
import { executeUpgradeAction, formatUpgradeResult, subscribeUpgradeJob } from '../../utils/upgrade-jobs.js';
|
|
14
14
|
import { loadDaemonConfig } from '../../config-store.js';
|
|
15
15
|
import { formatPairingCodeMessage } from '../../ecweb/pairing.js';
|
|
@@ -37,7 +37,7 @@ import { chatmodeFieldForPeer, isChatMode, isPrivateChatmodeRoleLocked, resolveC
|
|
|
37
37
|
import { normalizePermissionMode as normalizePermissionModeContract, PUBLIC_PERMISSION_MODES } from '../permission/mode.js';
|
|
38
38
|
import { isManagementRole } from '../../config/builtin-roles.js';
|
|
39
39
|
import { isSystemControlChannel } from '../system-channels.js';
|
|
40
|
-
import {
|
|
40
|
+
import { resolveCliEntry, launchMonitorAndConfirm, isProcessRunning } from '../../utils/cross-platform.js';
|
|
41
41
|
import { hasLiveRestartMonitor } from '../../utils/instance-registry.js';
|
|
42
42
|
import { guardIdleCommand, guardGroupSlashCommand, guardKnownCommand, guardRoleCommand, guardThreadCommand, isRecognizedSlashCommand, normalizeSlashContent, parseFullAccessCommand, probeSessionActivity, } from './slash-gate.js';
|
|
43
43
|
import { MAX_AUN_ATTACHMENT_SIZE } from '../../aun/msg/upload.js';
|
|
@@ -3202,12 +3202,6 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3202
3202
|
autoUpgrade = false;
|
|
3203
3203
|
}
|
|
3204
3204
|
}
|
|
3205
|
-
if (!suppressRealRestart && autoUpgrade) {
|
|
3206
|
-
await ensureFreshPackageVersionInfo(undefined, {
|
|
3207
|
-
source: 'slash-restart',
|
|
3208
|
-
log: message => logger.info(`[System] ${message}`),
|
|
3209
|
-
});
|
|
3210
|
-
}
|
|
3211
3205
|
const restartInfo = {
|
|
3212
3206
|
channel,
|
|
3213
3207
|
channelId,
|
|
@@ -3220,12 +3214,9 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3220
3214
|
...(restartReplyContext?.replyToMessageId ? { rootId: restartReplyContext.replyToMessageId } : {}),
|
|
3221
3215
|
};
|
|
3222
3216
|
if (!suppressRealRestart) {
|
|
3223
|
-
//
|
|
3224
|
-
//
|
|
3225
|
-
|
|
3226
|
-
const monitorEntry = resolveMonitorLaunch(getPackageRoot(), path.join(resolvePaths().root, 'data', 'monitor-stage'));
|
|
3227
|
-
if (monitorEntry.note)
|
|
3228
|
-
logger.info(`[System] ${monitorEntry.note}`);
|
|
3217
|
+
// CLI owns backend selection for Menu and slash alike. In particular,
|
|
3218
|
+
// a detached monitor cannot survive shutdown of its owning systemd unit.
|
|
3219
|
+
const monitorEntry = resolveCliEntry(getPackageRoot());
|
|
3229
3220
|
if (!fs.existsSync(monitorEntry.entry)) {
|
|
3230
3221
|
logger.error(`[System] Refusing restart: restart-monitor entry not found: ${monitorEntry.entry}`);
|
|
3231
3222
|
return { code: 'RESTART_ENTRY_MISSING', entry: monitorEntry.entry };
|
|
@@ -3235,18 +3226,20 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3235
3226
|
const pendingFile = path.join(controlDir, 'restart-pending.json');
|
|
3236
3227
|
if (await hasLiveRestartMonitor()
|
|
3237
3228
|
|| !createRestartRequest(pendingFile, restartInfo, isProcessRunning)) {
|
|
3238
|
-
if (monitorEntry.stageDir)
|
|
3239
|
-
cleanupMonitorStage(monitorEntry.stageDir);
|
|
3240
3229
|
return { code: 'RESTART_PENDING_CONFIRMATION', reason: '已有重启请求正在处理', requestId: restartInfo.requestId };
|
|
3241
3230
|
}
|
|
3242
|
-
const confirmation = await launchMonitorAndConfirm([...monitorEntry.args, 'restart
|
|
3231
|
+
const confirmation = await launchMonitorAndConfirm([...monitorEntry.args, 'restart', autoUpgrade ? '--apply-package-upgrades' : '--skip-package-upgrades'], {
|
|
3232
|
+
[RUNTIME_HOME_ENV]: resolvePaths().root, [RESTART_REQUEST_ID_ENV]: restartInfo.requestId,
|
|
3233
|
+
[SESSION_ID_ENV]: '', [AGENT_DELEGATION_TOKEN_ENV]: '',
|
|
3234
|
+
}, () => ['accepted', 'ready'].includes(readRestartRequest(pendingFile, restartInfo.requestId)?.status ?? ''), pid => hasLiveRestartMonitor({ excludePid: pid, requestId: restartInfo.requestId, phase: 'accepted' }), {
|
|
3243
3235
|
requestId: restartInfo.requestId,
|
|
3244
3236
|
logFilePath: path.join(resolvePaths().logs, `restart-launch-${restartInfo.requestId}.log`),
|
|
3245
3237
|
onSpawn: pid => { updateRestartRequest(pendingFile, restartInfo.requestId, { launcherPid: pid }); },
|
|
3246
3238
|
isPendingInRegistry: () => hasLiveRestartMonitor({ requestId: restartInfo.requestId }),
|
|
3247
3239
|
});
|
|
3248
3240
|
if (!confirmation.ok) {
|
|
3249
|
-
|
|
3241
|
+
const pending = readRestartRequest(pendingFile, restartInfo.requestId);
|
|
3242
|
+
if (confirmation.pending || (pending?.backend === 'systemd' && ['requested', 'accepted'].includes(pending.status))) {
|
|
3250
3243
|
logger.warn(`[System] Restart ownership remains unconfirmed (requestId=${restartInfo.requestId}, PID=${confirmation.pid ?? 'unknown'})`);
|
|
3251
3244
|
return {
|
|
3252
3245
|
code: 'RESTART_PENDING_CONFIRMATION',
|
|
@@ -3255,15 +3248,13 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3255
3248
|
...(confirmation.pid ? { pid: confirmation.pid } : {}),
|
|
3256
3249
|
};
|
|
3257
3250
|
}
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
cleanupMonitorStage(monitorEntry.stageDir);
|
|
3261
|
-
removeRestartRequest(pendingFile, restartInfo.requestId);
|
|
3251
|
+
if (pending?.backend !== 'systemd')
|
|
3252
|
+
removeRestartRequest(pendingFile, restartInfo.requestId);
|
|
3262
3253
|
logger.error(`[System] Refusing restart: restart-monitor did not come up (${confirmation.reason})`);
|
|
3263
3254
|
for (const line of (confirmation.stderrTail ?? '').split(/\r?\n/).filter(Boolean).slice(-8)) {
|
|
3264
3255
|
logger.error(`[System] | ${line}`);
|
|
3265
3256
|
}
|
|
3266
|
-
return { code: 'RESTART_MONITOR_DEAD', reason: confirmation.reason ?? 'unknown' };
|
|
3257
|
+
return { code: 'RESTART_MONITOR_DEAD', reason: pending?.reason ?? confirmation.reason ?? 'unknown' };
|
|
3267
3258
|
}
|
|
3268
3259
|
}
|
|
3269
3260
|
else {
|
|
@@ -3301,7 +3292,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3301
3292
|
});
|
|
3302
3293
|
await adapter.send(envelope, {
|
|
3303
3294
|
kind: 'system.notice',
|
|
3304
|
-
text: '🔄
|
|
3295
|
+
text: '🔄 重启请求已接管,服务正在重启;完成后会另行通知。',
|
|
3305
3296
|
subtype: 'system.restart.pending',
|
|
3306
3297
|
});
|
|
3307
3298
|
// 等待消息发送完成后再延迟 kill
|
|
@@ -23,7 +23,8 @@ export function resolveTeamWorkspaceIdentity(agentAid) {
|
|
|
23
23
|
const config = read(ConfigTarget.Agent, { self: agentAid }, { cache: false });
|
|
24
24
|
if (!config)
|
|
25
25
|
return null;
|
|
26
|
-
|
|
26
|
+
// Ownership comes from the protocol alone; config never supplies an Owner.
|
|
27
|
+
const ownerAid = ownerResolver.owner(agentAid);
|
|
27
28
|
if (!ownerAid || !isValidAid(ownerAid))
|
|
28
29
|
return null;
|
|
29
30
|
return { agentAid, ownerAid };
|
|
@@ -314,7 +314,13 @@ export async function handleTopicSlash(ctx) {
|
|
|
314
314
|
name,
|
|
315
315
|
...(status ? { topicStatus: status } : {}),
|
|
316
316
|
});
|
|
317
|
-
|
|
317
|
+
// 本地无名片缓存只提示、不阻止:建话题不发消息,离线也必须可建。
|
|
318
|
+
// 提示必须带补救动作,否则用户只知道"可能投递不了"却不知道下一步做什么。
|
|
319
|
+
const unverified = created.peerUnverified === true
|
|
320
|
+
? `\n⚠ 对端 ${created.peer} 本地无名片缓存,消息可能无法投递`
|
|
321
|
+
+ `\n 补拉名片后即可正常发送:ec aid agentmd get ${created.peer}`
|
|
322
|
+
: '';
|
|
323
|
+
return result(`✅ 已创建话题: ${created.name}\nref: ${created.threadId}${unverified}`);
|
|
318
324
|
}
|
|
319
325
|
if (sub === 'rename') {
|
|
320
326
|
const ref = refSource(positional, flags);
|
|
@@ -42,10 +42,6 @@ export async function runBindBootstrapDaemon(daemonCfg, ecwebSupervisor) {
|
|
|
42
42
|
});
|
|
43
43
|
bindService.startCleanup();
|
|
44
44
|
ownerResolver.setDaemonAid(daemonCfg.aid);
|
|
45
|
-
ownerResolver.setConfiguredOwners(daemonCfg.aid, [
|
|
46
|
-
daemonCfg.owner,
|
|
47
|
-
...(daemonCfg.owners ?? []),
|
|
48
|
-
].filter((owner) => typeof owner === 'string'));
|
|
49
45
|
let controlChannel;
|
|
50
46
|
let shutdown;
|
|
51
47
|
let pendingShutdownReason;
|
|
@@ -28,7 +28,8 @@ export function startDaemonControlAid({ daemonCfg, cmdHandler, bindService, diag
|
|
|
28
28
|
agentName: daemonCfg.aid,
|
|
29
29
|
channelName: 'control',
|
|
30
30
|
pureIdentity: true,
|
|
31
|
-
|
|
31
|
+
// No configured Owner: card publication validates whatever the remote
|
|
32
|
+
// ownership consensus reports, never a local declaration.
|
|
32
33
|
defaultEncrypt: daemonCfg.aun?.defaultEncrypt,
|
|
33
34
|
aunTrace: daemonCfg.debug?.aunTrace,
|
|
34
35
|
aunSdkLog: daemonCfg.debug?.aunSdkLog,
|
|
@@ -348,6 +348,7 @@ export class StartupTaskQueue {
|
|
|
348
348
|
active = 0;
|
|
349
349
|
stopped = false;
|
|
350
350
|
timer;
|
|
351
|
+
immediate;
|
|
351
352
|
constructor(concurrency = 2, intervalMs = 50) {
|
|
352
353
|
this.concurrency = concurrency;
|
|
353
354
|
this.intervalMs = intervalMs;
|
|
@@ -368,16 +369,20 @@ export class StartupTaskQueue {
|
|
|
368
369
|
this.stopped = true;
|
|
369
370
|
if (this.timer)
|
|
370
371
|
clearTimeout(this.timer);
|
|
372
|
+
if (this.immediate)
|
|
373
|
+
clearImmediate(this.immediate);
|
|
371
374
|
this.timer = undefined;
|
|
375
|
+
this.immediate = undefined;
|
|
372
376
|
for (const task of this.pending.splice(0))
|
|
373
377
|
task.resolve(false);
|
|
374
378
|
}
|
|
375
379
|
schedule() {
|
|
376
|
-
if (this.stopped || this.timer || this.active >= this.concurrency || !this.pending.length)
|
|
380
|
+
if (this.stopped || this.timer || this.immediate || this.active >= this.concurrency || !this.pending.length)
|
|
377
381
|
return;
|
|
378
382
|
// Yield between admissions even when tasks finish synchronously.
|
|
379
|
-
|
|
383
|
+
const admit = () => {
|
|
380
384
|
this.timer = undefined;
|
|
385
|
+
this.immediate = undefined;
|
|
381
386
|
// Choose at admission time, so newly classified priority work can pass
|
|
382
387
|
// queued idle channels. Never hold a free slot for unclassified work;
|
|
383
388
|
// already-running connections finish within the existing concurrency cap.
|
|
@@ -398,7 +403,11 @@ export class StartupTaskQueue {
|
|
|
398
403
|
this.schedule();
|
|
399
404
|
});
|
|
400
405
|
this.schedule();
|
|
401
|
-
}
|
|
406
|
+
};
|
|
407
|
+
if (this.intervalMs === 0)
|
|
408
|
+
this.immediate = setImmediate(admit);
|
|
409
|
+
else
|
|
410
|
+
this.timer = setTimeout(admit, this.intervalMs);
|
|
402
411
|
}
|
|
403
412
|
}
|
|
404
413
|
/** Observe startup task admission without delaying IPC or background services. */
|
|
@@ -669,7 +678,7 @@ export async function resumePendingSessions({ sessionManager, messageQueue, drop
|
|
|
669
678
|
sessionManager.clearProcessing(session.id);
|
|
670
679
|
}
|
|
671
680
|
}
|
|
672
|
-
export function createDaemonShutdown({ disposePluginResources, lifecycleNotices, stopOwnership, ipcServer, readySignalPath, bindService, ecwebSupervisor, messageQueue, permissionGateway, removePermissionConfigListener, stopStatsPersistence, triggerSchedulers, agentMap, eventBus,
|
|
681
|
+
export function createDaemonShutdown({ disposePluginResources, lifecycleNotices, stopOwnership, ipcServer, readySignalPath, bindService, ecwebSupervisor, messageQueue, permissionGateway, removePermissionConfigListener, stopStatsPersistence, triggerSchedulers, agentMap, eventBus, groupInviteReviewService, channelLoader, channelInstances, startupRunners, waitForRunnerLoads, cancelStartup, controlChannel, sessionManager, removeAll, exit, }) {
|
|
673
682
|
let shutdownSignal = 'unknown';
|
|
674
683
|
let shutdownInProgress = false;
|
|
675
684
|
return async (signal, traceId) => {
|
|
@@ -795,7 +804,6 @@ export function createDaemonShutdown({ disposePluginResources, lifecycleNotices,
|
|
|
795
804
|
});
|
|
796
805
|
});
|
|
797
806
|
eventBus.publish({ type: 'system:shutdown', timestamp: Date.now() });
|
|
798
|
-
removeGroupInviteConfigListener();
|
|
799
807
|
await shutdownStep('daemon.groupInvite', 'stop group invitation review', () => groupInviteReviewService.dispose());
|
|
800
808
|
await shutdownStep('daemon.skillWatcher', 'stop global skill watcher', async () => {
|
|
801
809
|
const { stopGlobalSkillWatcher } = await import('./skill/global-watcher.js');
|
|
@@ -5,12 +5,11 @@ import { logger } from '../utils/logger.js';
|
|
|
5
5
|
import { aidLocalDir } from '../paths.js';
|
|
6
6
|
import { readSoulContent } from './soul.js';
|
|
7
7
|
import { invalidateAgentDisplayName, resolveAgentDisplayName } from '../aun/aid/agentmd.js';
|
|
8
|
-
import { loadAllAgents, ensureAgentDirSkeleton, loadAgent, validateAgentConfig, } from '../config-store.js';
|
|
8
|
+
import { loadAllAgents, ensureAgentDirSkeleton, loadAgent, agentProjectChangeGate, assertAgentProjectChangeReady, validateAgentConfig, } from '../config-store.js';
|
|
9
9
|
import { ConfigTarget, assertAgentAidAvailable, read as readConfig, resolveEffective } from '../config/config-manager.js';
|
|
10
10
|
import { ensureInitialRoleRegistry } from '../config/role-service.js';
|
|
11
11
|
import { resolveAgentLifecycle } from '../config/lifecycle.js';
|
|
12
12
|
import { getOwners, getPrimaryOwner, ownerResolver } from './ownership/owner-resolver.js';
|
|
13
|
-
import { configuredOwnerList } from '../config/owner-config.js';
|
|
14
13
|
import { assertTemplateInstallationReady } from '../agent-template/jobs.js';
|
|
15
14
|
// ── Channel Fingerprint ───────────────────────────────────────────────────
|
|
16
15
|
// 用于检测多 agent 之间复用同一外部凭证的冲突(appId、aid、token 等)。
|
|
@@ -96,7 +95,6 @@ export class EvolAgentRegistry {
|
|
|
96
95
|
for (const expandedRaw of rawAgents) {
|
|
97
96
|
try {
|
|
98
97
|
const raw = readConfig(ConfigTarget.Agent, { self: expandedRaw.aid }, { cache: true }) ?? expandedRaw;
|
|
99
|
-
ownerResolver.setAgentConfiguredOwners(expandedRaw.aid, configuredOwnerList(raw));
|
|
100
98
|
const precheck = precheckAgentConfig(expandedRaw.aid, raw);
|
|
101
99
|
if (precheck) {
|
|
102
100
|
this.registerErrorAgent(raw, `${precheck.code}: ${precheck.detail}`);
|
|
@@ -106,6 +104,13 @@ export class EvolAgentRegistry {
|
|
|
106
104
|
// still reload through ConfigManager's normal atomic reader.
|
|
107
105
|
const merged = resolveEffective({ self: expandedRaw.aid }, { cache: true });
|
|
108
106
|
const agent = new EvolAgent(raw, merged);
|
|
107
|
+
const projectGate = agentProjectChangeGate(agent.aid);
|
|
108
|
+
if (projectGate) {
|
|
109
|
+
agent.status = projectGate.state === 'recovery' ? 'error' : 'stopped';
|
|
110
|
+
if (projectGate.state === 'recovery')
|
|
111
|
+
agent.error = 'PROJECT_RECOVERY_REQUIRED';
|
|
112
|
+
this.manuallyStopped.add(agent.aid);
|
|
113
|
+
}
|
|
109
114
|
ensureAgentDirSkeleton(expandedRaw.aid);
|
|
110
115
|
ensureInitialRoleRegistry(expandedRaw.aid);
|
|
111
116
|
this.agents.set(agent.aid, agent);
|
|
@@ -116,7 +121,6 @@ export class EvolAgentRegistry {
|
|
|
116
121
|
}
|
|
117
122
|
for (const { agent: expandedRaw, reason } of invalidAgents) {
|
|
118
123
|
const raw = readConfig(ConfigTarget.Agent, { self: expandedRaw.aid }, { cache: true }) ?? expandedRaw;
|
|
119
|
-
ownerResolver.setAgentConfiguredOwners(expandedRaw.aid, configuredOwnerList(raw));
|
|
120
124
|
this.registerErrorAgent(raw, reason);
|
|
121
125
|
}
|
|
122
126
|
this.detectAndFlagConflicts();
|
|
@@ -242,12 +246,13 @@ export class EvolAgentRegistry {
|
|
|
242
246
|
this.personalNameCache.delete(aid);
|
|
243
247
|
}
|
|
244
248
|
runnableAgents() {
|
|
245
|
-
return this.allAgents().filter(a => a.status === 'stopped');
|
|
249
|
+
return this.allAgents().filter(a => a.status === 'stopped' && !agentProjectChangeGate(a.aid));
|
|
246
250
|
}
|
|
247
251
|
getSkipped() {
|
|
248
252
|
return [...this.skipped];
|
|
249
253
|
}
|
|
250
254
|
loadNewAgent(aid) {
|
|
255
|
+
assertAgentProjectChangeReady(aid);
|
|
251
256
|
assertAgentAidAvailable(aid);
|
|
252
257
|
if (this.agents.has(aid)) {
|
|
253
258
|
logger.info(`[EvolAgentRegistry] agent ${aid} already loaded, skipping`);
|
|
@@ -288,7 +293,6 @@ export class EvolAgentRegistry {
|
|
|
288
293
|
return this.registerErrorAgent(expandedRaw, `${precheck.code}: ${precheck.detail}`);
|
|
289
294
|
}
|
|
290
295
|
const raw = readConfig(ConfigTarget.Agent, { self: aid }, { cache: true }) ?? expandedRaw;
|
|
291
|
-
ownerResolver.setAgentConfiguredOwners(aid, configuredOwnerList(raw));
|
|
292
296
|
const merged = resolveEffective({ self: aid }, {});
|
|
293
297
|
const agent = new EvolAgent(raw, merged);
|
|
294
298
|
ensureAgentDirSkeleton(aid);
|
|
@@ -305,6 +309,7 @@ export class EvolAgentRegistry {
|
|
|
305
309
|
if (!oldAgent)
|
|
306
310
|
throw new Error(`Agent "${aidOrName}" not found`);
|
|
307
311
|
assertTemplateInstallationReady(oldAgent.aid, options.recoveryJobId);
|
|
312
|
+
assertAgentProjectChangeReady(oldAgent.aid);
|
|
308
313
|
await hooks.beforeAgentOperation?.(oldAgent.aid);
|
|
309
314
|
const expandedRaw = loadAgent(oldAgent.aid);
|
|
310
315
|
if (!expandedRaw)
|
|
@@ -316,7 +321,6 @@ export class EvolAgentRegistry {
|
|
|
316
321
|
if (precheck)
|
|
317
322
|
throw new Error(`Precheck failed: ${precheck.detail}`);
|
|
318
323
|
const raw = readConfig(ConfigTarget.Agent, { self: oldAgent.aid }, { cache: true }) ?? expandedRaw;
|
|
319
|
-
ownerResolver.setAgentConfiguredOwners(oldAgent.aid, configuredOwnerList(raw));
|
|
320
324
|
const merged = resolveEffective({ self: raw.aid }, {});
|
|
321
325
|
if (oldAgent.status === 'disabled' && raw.enabled === false
|
|
322
326
|
|| (options.preserveStopped && oldAgent.status === 'stopped' || options.restoreStopped) && raw.enabled !== false) {
|
|
@@ -578,6 +582,7 @@ export class EvolAgentRegistry {
|
|
|
578
582
|
logger.info(`[Registry] Stopped agent ${aidOrName}`);
|
|
579
583
|
}
|
|
580
584
|
async startAgent(aidOrName, hooks) {
|
|
585
|
+
assertAgentProjectChangeReady(aidOrName);
|
|
581
586
|
assertAgentAidAvailable(aidOrName);
|
|
582
587
|
assertTemplateInstallationReady(aidOrName);
|
|
583
588
|
const agent = this.agents.get(aidOrName);
|
|
@@ -39,7 +39,7 @@ export class HandoffDeliveryFailedError extends Error {
|
|
|
39
39
|
export class TriggerHandoffRequiredForbiddenError extends Error {
|
|
40
40
|
code = 'TRIGGER_HANDOFF_REQUIRED_FORBIDDEN';
|
|
41
41
|
constructor() {
|
|
42
|
-
super('Trigger 的跨会话
|
|
42
|
+
super('Trigger 的跨会话 ecmsg send 只允许 --return none,不能使用 required');
|
|
43
43
|
this.name = 'TriggerHandoffRequiredForbiddenError';
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -10,7 +10,7 @@ import fs from 'node:fs';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import { parseDocument } from 'yaml';
|
|
12
12
|
import { resolvePaths, agentMdPath } from '../paths.js';
|
|
13
|
-
import { readHostInfo, probeVirtualization, probeRuntimes, readVersionInfo, readRuntimeInfo } from '../utils/host-info.js';
|
|
13
|
+
import { readHostInfo, probeVirtualization, probeOsProductName, probeRuntimes, readVersionInfo, readRuntimeInfo } from '../utils/host-info.js';
|
|
14
14
|
import { loadDaemonConfig } from '../config-store.js';
|
|
15
15
|
const EMPTY_RUNTIMES = { python: null, go: null, claudeCode: null, claudeCodeBundled: null, codex: null, ecagent: null };
|
|
16
16
|
function staticCachePath() {
|
|
@@ -24,6 +24,7 @@ function readStaticCache() {
|
|
|
24
24
|
return {
|
|
25
25
|
virtualization: (raw.virtualization ?? 'unknown'),
|
|
26
26
|
runtimes: { ...EMPTY_RUNTIMES, ...(raw.runtimes ?? {}) },
|
|
27
|
+
productName: typeof raw.productName === 'string' && raw.productName.trim() ? raw.productName.trim() : null,
|
|
27
28
|
cachedAt: typeof raw.cachedAt === 'string' ? raw.cachedAt : new Date(0).toISOString(),
|
|
28
29
|
};
|
|
29
30
|
}
|
|
@@ -133,26 +134,30 @@ export function createHostSnapshotProvider(deps) {
|
|
|
133
134
|
const staticState = {
|
|
134
135
|
virtualization: cached?.virtualization ?? 'unknown',
|
|
135
136
|
runtimes: cached?.runtimes ?? EMPTY_RUNTIMES,
|
|
137
|
+
productName: cached?.productName ?? null,
|
|
136
138
|
cachedAt: cached?.cachedAt ?? null,
|
|
137
139
|
virtualizationProbed: false,
|
|
138
140
|
runtimesProbed: false,
|
|
139
141
|
};
|
|
140
142
|
const versions = readVersionInfo();
|
|
141
143
|
const probe = async () => {
|
|
142
|
-
const [virtualization, runtimes] = await Promise.all([
|
|
144
|
+
const [virtualization, runtimes, productName] = await Promise.all([
|
|
143
145
|
probeVirtualization().then(value => ({ value }), () => ({ value: staticState.virtualization })),
|
|
144
146
|
probeRuntimes().then(value => ({ value }), () => ({ value: staticState.runtimes })),
|
|
147
|
+
probeOsProductName().then(value => ({ value }), () => ({ value: staticState.productName })),
|
|
145
148
|
]);
|
|
146
149
|
staticState.virtualization = virtualization.value;
|
|
147
150
|
staticState.runtimes = runtimes.value;
|
|
151
|
+
staticState.productName = productName.value;
|
|
148
152
|
staticState.virtualizationProbed = true;
|
|
149
153
|
staticState.runtimesProbed = true;
|
|
150
154
|
staticState.cachedAt = new Date().toISOString();
|
|
151
|
-
writeStaticCache({ virtualization: staticState.virtualization, runtimes: staticState.runtimes, cachedAt: staticState.cachedAt });
|
|
155
|
+
writeStaticCache({ virtualization: staticState.virtualization, runtimes: staticState.runtimes, productName: staticState.productName, cachedAt: staticState.cachedAt });
|
|
152
156
|
};
|
|
153
157
|
const getHost = () => {
|
|
154
158
|
const host = readHostInfo(versions.evolcore, resolvePaths().root, { runtimes: staticState.runtimes });
|
|
155
159
|
host.os.virtualization = staticState.virtualization;
|
|
160
|
+
host.os.productName = staticState.productName;
|
|
156
161
|
// CPU 只有 daemon 有采样值;采样未启动时宁可给 null,也不给一个骗人的数字。
|
|
157
162
|
host.hardware.cpuUsagePercent = deps.getSystemCpuPercent?.() ?? null;
|
|
158
163
|
return host;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { createRequire } from 'node:module';
|
|
5
6
|
import { resolvePaths } from '../../paths.js';
|
|
@@ -270,6 +271,8 @@ export class EcwebInitializationService {
|
|
|
270
271
|
qrSvg: scannable ? qrSvg({
|
|
271
272
|
type: 'evolcore.bind', version: readInstalledEvolcoreVersion(),
|
|
272
273
|
platform: process.platform === 'win32' ? 'windows' : process.platform,
|
|
274
|
+
// 机器名随二维码带给 App:主机列表的默认显示名要用它,而不是 agent 的名字。
|
|
275
|
+
hostName: os.hostname(),
|
|
273
276
|
bindType: 'daemon', subjectAid: state.controlAid,
|
|
274
277
|
token: binding.token, expiresAt: binding.expiresAt,
|
|
275
278
|
}) : null,
|
|
@@ -1,4 +1,134 @@
|
|
|
1
1
|
import { logger } from '../utils/logger.js';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { agentDataDir } from '../paths.js';
|
|
5
|
+
import { atomicRead, atomicWriteJson, withFileLock } from '../utils/atomic-write.js';
|
|
6
|
+
import { MAX_WIDGET_VALUES_BYTES } from '../aun/msg/upload.js';
|
|
7
|
+
function widgetCardFile(selfAid, messageId) {
|
|
8
|
+
const key = crypto.createHash('sha256').update(messageId).digest('hex');
|
|
9
|
+
return path.join(agentDataDir(selfAid), 'aun', 'widget-cards', `${key}.json`);
|
|
10
|
+
}
|
|
11
|
+
export function readWidgetCard(selfAid, messageId) {
|
|
12
|
+
if (!messageId || messageId.length > 512)
|
|
13
|
+
return undefined;
|
|
14
|
+
const raw = atomicRead(widgetCardFile(selfAid, messageId));
|
|
15
|
+
if (raw === null)
|
|
16
|
+
return undefined;
|
|
17
|
+
const record = JSON.parse(raw);
|
|
18
|
+
if (record.version !== 1 || record.messageId !== messageId || !record.channelId || !record.initiatorAid
|
|
19
|
+
|| !['private', 'group'].includes(record.chatType)
|
|
20
|
+
|| !['pending', 'submitting', 'completed', 'cancelled'].includes(record.status)
|
|
21
|
+
|| typeof record.encrypted !== 'boolean'
|
|
22
|
+
|| (record.expiresAt !== undefined && (typeof record.expiresAt !== 'number' || !Number.isFinite(record.expiresAt)))) {
|
|
23
|
+
throw new Error('Invalid WidgetCard binding');
|
|
24
|
+
}
|
|
25
|
+
return record;
|
|
26
|
+
}
|
|
27
|
+
/** Replayed outbox delivery must never re-open a card that has already been answered. */
|
|
28
|
+
export function registerWidgetCard(selfAid, binding) {
|
|
29
|
+
const previous = readWidgetCard(selfAid, binding.messageId);
|
|
30
|
+
if (previous) {
|
|
31
|
+
if (previous.channelId !== binding.channelId || previous.chatType !== binding.chatType
|
|
32
|
+
|| previous.threadId !== binding.threadId || previous.initiatorAid !== binding.initiatorAid) {
|
|
33
|
+
throw new Error('WidgetCard binding conflicts with an existing delivery');
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
atomicWriteJson(widgetCardFile(selfAid, binding.messageId), binding);
|
|
38
|
+
}
|
|
39
|
+
export function cancelWidgetCard(selfAid, messageId) {
|
|
40
|
+
const binding = readWidgetCard(selfAid, messageId);
|
|
41
|
+
if (!binding || binding.status === 'completed' || binding.status === 'cancelled')
|
|
42
|
+
return;
|
|
43
|
+
atomicWriteJson(widgetCardFile(selfAid, messageId), { ...binding, status: 'cancelled' });
|
|
44
|
+
}
|
|
45
|
+
function widgetError(message, code = 'INVALID_WIDGET_REPLY') {
|
|
46
|
+
throw Object.assign(new Error(message), { code });
|
|
47
|
+
}
|
|
48
|
+
export function validateWidgetValues(values) {
|
|
49
|
+
if (!values || typeof values !== 'object' || Array.isArray(values))
|
|
50
|
+
widgetError('表单结果必须是 JSON 对象');
|
|
51
|
+
let nodes = 0;
|
|
52
|
+
const visit = (value, depth) => {
|
|
53
|
+
if (++nodes > 5000 || depth > 16)
|
|
54
|
+
widgetError('表单数据结构过于复杂');
|
|
55
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
56
|
+
return;
|
|
57
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
58
|
+
return;
|
|
59
|
+
if (!value || typeof value !== 'object')
|
|
60
|
+
widgetError('表单包含无效 JSON 值');
|
|
61
|
+
if (Array.isArray(value)) {
|
|
62
|
+
for (const item of value)
|
|
63
|
+
visit(item, depth + 1);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (const [key, item] of Object.entries(value)) {
|
|
67
|
+
if (['__proto__', 'prototype', 'constructor'].includes(key))
|
|
68
|
+
widgetError('表单包含保留字段名');
|
|
69
|
+
visit(item, depth + 1);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
visit(values, 0);
|
|
73
|
+
if (Buffer.byteLength(JSON.stringify(values), 'utf8') > MAX_WIDGET_VALUES_BYTES)
|
|
74
|
+
widgetError('表单结果超过 64 KiB');
|
|
75
|
+
}
|
|
76
|
+
/** Durable one-shot reply association. An interrupted dispatch is never blindly replayed. */
|
|
77
|
+
export async function acceptWidgetCardReply(input) {
|
|
78
|
+
const payload = input.payload;
|
|
79
|
+
if (payload.type !== 'widget_card_reply')
|
|
80
|
+
widgetError('无效的表单回复类型');
|
|
81
|
+
const cardId = payload.card_message_id;
|
|
82
|
+
const submissionId = payload.submission_id;
|
|
83
|
+
if (typeof cardId !== 'string' || !cardId || cardId.length > 512
|
|
84
|
+
|| typeof submissionId !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(submissionId)) {
|
|
85
|
+
widgetError('缺少有效的原卡片或提交标识');
|
|
86
|
+
}
|
|
87
|
+
if (payload.action !== 'submit' && payload.action !== 'cancel')
|
|
88
|
+
widgetError('无效的表单动作');
|
|
89
|
+
if (payload.action === 'submit')
|
|
90
|
+
validateWidgetValues(payload.values);
|
|
91
|
+
const file = widgetCardFile(input.selfAid, cardId);
|
|
92
|
+
return withFileLock(`${file}.lock`, async () => {
|
|
93
|
+
const binding = readWidgetCard(input.selfAid, cardId);
|
|
94
|
+
if (!binding)
|
|
95
|
+
widgetError('卡片已失效,请重新发起', 'WIDGET_CARD_EXPIRED');
|
|
96
|
+
if (!input.senderAid || input.senderAid !== binding.initiatorAid
|
|
97
|
+
|| input.channelId !== binding.channelId || input.chatType !== binding.chatType
|
|
98
|
+
|| (payload.thread_id !== undefined && payload.thread_id !== binding.threadId)
|
|
99
|
+
|| (binding.encrypted && !input.encrypted)
|
|
100
|
+
|| (binding.sensitive && (!input.encrypted || input.chatType !== 'private'))) {
|
|
101
|
+
widgetError('该回复不符合原卡片的操作者或会话约束', 'WIDGET_CARD_FORBIDDEN');
|
|
102
|
+
}
|
|
103
|
+
if (binding.status === 'completed' || binding.status === 'cancelled') {
|
|
104
|
+
if (binding.submissionId === submissionId)
|
|
105
|
+
return 'duplicate';
|
|
106
|
+
widgetError('卡片已答复,请勿重复提交', 'WIDGET_CARD_COMPLETED');
|
|
107
|
+
}
|
|
108
|
+
if (binding.expiresAt !== undefined && binding.expiresAt <= Date.now())
|
|
109
|
+
widgetError('卡片已失效,请重新发起', 'WIDGET_CARD_EXPIRED');
|
|
110
|
+
if (binding.status !== 'pending')
|
|
111
|
+
widgetError('上次提交正在处理或结果待核实,请勿重复提交', 'WIDGET_CARD_IN_FLIGHT');
|
|
112
|
+
binding.status = 'submitting';
|
|
113
|
+
binding.submissionId = submissionId;
|
|
114
|
+
atomicWriteJson(file, binding);
|
|
115
|
+
try {
|
|
116
|
+
await input.dispatch(binding, payload.action, payload.values);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
// Match ActionInteraction callback failures: a live failure remains retryable.
|
|
120
|
+
// A process crash leaves the durable 'submitting' marker and cannot replay blindly.
|
|
121
|
+
const current = readWidgetCard(input.selfAid, cardId);
|
|
122
|
+
if (current?.status === 'submitting' && current.submissionId === submissionId) {
|
|
123
|
+
atomicWriteJson(file, { ...current, status: 'pending' });
|
|
124
|
+
}
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
binding.status = payload.action === 'cancel' ? 'cancelled' : 'completed';
|
|
128
|
+
atomicWriteJson(file, binding);
|
|
129
|
+
return 'accepted';
|
|
130
|
+
});
|
|
131
|
+
}
|
|
2
132
|
export class InteractionRouter {
|
|
3
133
|
handlers = new Map();
|
|
4
134
|
/** sessionId → 该会话当前待应答的交互数量,用于触发 wait 生命周期钩子 */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { registerPaymentRuntime } from '../pay/runtime.js';
|
|
1
2
|
import { createEventsOperationExecutor } from '../event-center/ipc-operation.js';
|
|
2
3
|
import { createServicesOperationExecutor } from '../services/ipc-operation.js';
|
|
3
4
|
import { ecwebInitializationService } from './initialization/service.js';
|
|
@@ -292,6 +293,9 @@ export function registerDaemonIpc({ lifecycle, ipcServer, agentRegistry, agentDe
|
|
|
292
293
|
messageQueue,
|
|
293
294
|
createCrossThreadReviewTrigger: input => createManagedCrossThreadReviewTrigger(input, triggerIpcDependencies),
|
|
294
295
|
});
|
|
296
|
+
const disposePayments = registerPaymentRuntime({ ipcServer, channelInstances, sessionManager, messageQueue,
|
|
297
|
+
authorize: authorizeManagedAgentOperation });
|
|
298
|
+
lifecycle?.defer(disposePayments, 'payment-runtime');
|
|
295
299
|
if (eventCenter) {
|
|
296
300
|
ipcServer.setEventsOperationExecutor(createEventsOperationExecutor({
|
|
297
301
|
registry: eventCenter,
|
|
@@ -642,7 +642,8 @@ export function serializeConsolidationContext(input) {
|
|
|
642
642
|
lines.push(`\`${feedbackFilePath(batchDir)}\``);
|
|
643
643
|
lines.push('');
|
|
644
644
|
lines.push('这是本次会话唯一可以直接写入的文件(文件已建好,直接写即可);写别的路径会被拒绝。不要用 shell 重定向、`tee` 或其它写入命令。');
|
|
645
|
-
lines.push('
|
|
645
|
+
lines.push('反馈会以系统通知的形式原样发给用户:**只写一行纯文本**,不要 Markdown、标题、列表或换行——对端不解析格式,标记会原样显示。');
|
|
646
|
+
lines.push('未写入则收尾时回退到默认统计模板(模式、触发方式、新建/更新/归档条数等)。');
|
|
646
647
|
const text = lines.join('\n');
|
|
647
648
|
// ── 写批次目录(任务书唯一落点)────────────────────────────────────────────
|
|
648
649
|
// 不再写会话运行目录:任务书落在 $EVOLCORE_HOME/tmp 或 %TEMP%/ec-session-<hash>/
|