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
|
@@ -7,8 +7,10 @@ import { logger } from '../../utils/logger.js';
|
|
|
7
7
|
import { validateIdleSeconds } from '../session/session-idle-monitor.js';
|
|
8
8
|
import { parseFileSearchArgs } from './file-search.js';
|
|
9
9
|
import { validateProviderMenuRequest } from '../../config/provider-menu-request.js';
|
|
10
|
-
import {
|
|
10
|
+
import { validateTeamWorkspaceItemsArgs } from './team-workspace-items.js';
|
|
11
|
+
import { isTeamMembersMenuRequest, validateTeamMembersMenuRequest } from './team-workspace-members-menu.js';
|
|
11
12
|
import { validateAgentMdMenuRequest } from './agentmd-menu-request.js';
|
|
13
|
+
import { validateEventsMenuRequest } from './eventcenter-menu.js';
|
|
12
14
|
const RETRY_DELAYS_MS = [250, 750, 2_000];
|
|
13
15
|
const RETRY_WINDOW_MS = 5_000;
|
|
14
16
|
export function isRetryableMenuTransportError(error) {
|
|
@@ -203,7 +205,7 @@ export const MENU_NAME_COMMANDS = Object.freeze({
|
|
|
203
205
|
file: '/file',
|
|
204
206
|
'agent-data-root': '/agent-data-root',
|
|
205
207
|
'relation-data-root': '/relation-data-root',
|
|
206
|
-
'
|
|
208
|
+
'team-workspace': '/team-workspace',
|
|
207
209
|
'agent-storage-root': '/agent-storage-root',
|
|
208
210
|
storage: '/storage',
|
|
209
211
|
gateway: '/gateway',
|
|
@@ -211,6 +213,7 @@ export const MENU_NAME_COMMANDS = Object.freeze({
|
|
|
211
213
|
capability: '/capability',
|
|
212
214
|
role: '/role',
|
|
213
215
|
connect: '/connect',
|
|
216
|
+
events: '/events',
|
|
214
217
|
});
|
|
215
218
|
export function menuCommandForName(name) {
|
|
216
219
|
if (typeof name !== 'string')
|
|
@@ -435,21 +438,57 @@ export function validateMenuRequest(request) {
|
|
|
435
438
|
if (taskError)
|
|
436
439
|
return taskError;
|
|
437
440
|
}
|
|
441
|
+
if (request.name === 'events' || firstCommandToken(request.cmd) === '/events') {
|
|
442
|
+
const error = validateEventsMenuRequest(request);
|
|
443
|
+
if (error)
|
|
444
|
+
return error;
|
|
445
|
+
}
|
|
438
446
|
if (request.name === 'pa-workspace' || firstCommandToken(request.cmd) === '/pa-workspace') {
|
|
439
|
-
|
|
440
|
-
|
|
447
|
+
return { code: 'NOT_SUPPORTED', message: 'PA Workspace was replaced by Team Workspace' };
|
|
448
|
+
}
|
|
449
|
+
if (request.name === 'team-workspace' || firstCommandToken(request.cmd) === '/team-workspace') {
|
|
441
450
|
const args = request.args;
|
|
442
|
-
|
|
451
|
+
if (isTeamMembersMenuRequest(request))
|
|
452
|
+
return validateTeamMembersMenuRequest(request);
|
|
453
|
+
if (type === 'menu.action') {
|
|
454
|
+
if (request.action !== 'retry-initialization')
|
|
455
|
+
return { code: 'NOT_SUPPORTED', message: 'Unsupported team-workspace action' };
|
|
456
|
+
const unknown = Object.keys(args ?? {}).find(key => !['managementVersion', 'operationId'].includes(key));
|
|
457
|
+
if (unknown)
|
|
458
|
+
return { code: 'INVALID_ARGUMENT', message: `team-workspace does not accept args.${unknown}` };
|
|
459
|
+
if (args?.managementVersion !== 1)
|
|
460
|
+
return { code: 'SCHEMA_VERSION_UNSUPPORTED', message: 'Unsupported Team workspace management version' };
|
|
461
|
+
if (typeof args?.operationId !== 'string' || !args.operationId.trim() || args.operationId.length > 200)
|
|
462
|
+
return { code: 'INVALID_ARGUMENT', message: 'retry-initialization requires args.operationId' };
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
if (type !== 'menu.query')
|
|
466
|
+
return { code: 'NOT_SUPPORTED', message: 'team-workspace only supports menu.query and menu.action' };
|
|
467
|
+
const unknown = Object.keys(args ?? {}).find(key => !['view', 'protocolVersion', 'managementVersion', 'context', 'from', 'to', 'timezone', 'path', 'offset', 'limit', 'indexRevision', 'jobId'].includes(key));
|
|
443
468
|
if (unknown)
|
|
444
|
-
return { code: 'INVALID_ARGUMENT', message: `
|
|
445
|
-
if (typeof args?.view !== 'string' || !['navigation', 'calendar', 'items'].includes(args.view))
|
|
446
|
-
return { code: 'INVALID_ARGUMENT', message: '
|
|
469
|
+
return { code: 'INVALID_ARGUMENT', message: `team-workspace does not accept args.${unknown}` };
|
|
470
|
+
if (typeof args?.view !== 'string' || !['navigation', 'calendar', 'items', 'workspace-info', 'job'].includes(args.view))
|
|
471
|
+
return { code: 'INVALID_ARGUMENT', message: 'team-workspace requires a supported view' };
|
|
472
|
+
if (['workspace-info', 'job'].includes(String(args.view))) {
|
|
473
|
+
if (args.managementVersion !== 1)
|
|
474
|
+
return { code: 'SCHEMA_VERSION_UNSUPPORTED', message: 'Management views require managementVersion=1' };
|
|
475
|
+
const managementUnknown = Object.keys(args).find(key => args.view === 'job'
|
|
476
|
+
? !['view', 'managementVersion', 'jobId'].includes(key)
|
|
477
|
+
: !['view', 'managementVersion'].includes(key));
|
|
478
|
+
if (managementUnknown)
|
|
479
|
+
return { code: 'INVALID_ARGUMENT', message: `Management view does not accept args.${managementUnknown}` };
|
|
480
|
+
if (args.view === 'job' && (typeof args.jobId !== 'string' || !args.jobId.trim()))
|
|
481
|
+
return { code: 'INVALID_ARGUMENT', message: 'job view requires args.jobId' };
|
|
482
|
+
if (args.view === 'workspace-info' && args.jobId !== undefined)
|
|
483
|
+
return { code: 'INVALID_ARGUMENT', message: 'workspace-info does not accept args.jobId' };
|
|
484
|
+
return null;
|
|
485
|
+
}
|
|
447
486
|
if (args?.view !== 'items' && ['path', 'offset', 'limit', 'indexRevision'].some(key => args?.[key] !== undefined)) {
|
|
448
487
|
return { code: 'INVALID_ARGUMENT', message: 'items arguments require items view' };
|
|
449
488
|
}
|
|
450
489
|
if (args?.view === 'items') {
|
|
451
490
|
try {
|
|
452
|
-
|
|
491
|
+
validateTeamWorkspaceItemsArgs(args);
|
|
453
492
|
}
|
|
454
493
|
catch (error) {
|
|
455
494
|
return { code: 'INVALID_ARGUMENT', message: error instanceof Error ? error.message : 'Invalid items arguments' };
|
|
@@ -490,8 +529,12 @@ export function validateMenuRequest(request) {
|
|
|
490
529
|
}
|
|
491
530
|
}
|
|
492
531
|
}
|
|
532
|
+
if (args?.managementVersion !== undefined)
|
|
533
|
+
return { code: 'INVALID_ARGUMENT', message: 'managementVersion is only valid for management views' };
|
|
534
|
+
if (args?.jobId !== undefined)
|
|
535
|
+
return { code: 'INVALID_ARGUMENT', message: 'jobId is only valid for job view' };
|
|
493
536
|
if (args?.protocolVersion !== undefined && args.protocolVersion !== 1) {
|
|
494
|
-
return { code: 'SCHEMA_VERSION_UNSUPPORTED', message: 'Unsupported
|
|
537
|
+
return { code: 'SCHEMA_VERSION_UNSUPPORTED', message: 'Unsupported Team workspace protocol version' };
|
|
495
538
|
}
|
|
496
539
|
}
|
|
497
540
|
if (type === 'menu.list' && Object.hasOwn(request, 'context')) {
|
|
@@ -522,6 +565,7 @@ export function validateMenuRequest(request) {
|
|
|
522
565
|
}
|
|
523
566
|
}
|
|
524
567
|
else if (type === 'menu.update'
|
|
568
|
+
&& !(request.name === 'events' || firstCommandToken(request.cmd) === '/events')
|
|
525
569
|
&& !((request.name === 'session' || request.cmd === '/session')
|
|
526
570
|
&& request.args?.resource === 'fullaccess')
|
|
527
571
|
&& (typeof request.value !== 'string' || request.value.length === 0)) {
|
|
@@ -693,7 +737,7 @@ const STABLE_CODES = new Set([
|
|
|
693
737
|
'TEMPORARILY_UNAVAILABLE', 'INTERNAL_ERROR', 'MISSING_SCOPE', 'UPGRADE_REQUIRED',
|
|
694
738
|
'NO_ACTIVE_UPDATE',
|
|
695
739
|
'MENU_TOKEN_REQUIRED', 'MENU_TOKEN_REJECTED', 'MENU_TOKEN_ENCRYPTION_REQUIRED',
|
|
696
|
-
'INVALID_CONTEXT', 'SCHEMA_VERSION_UNSUPPORTED', 'DEPENDENCY_UNAVAILABLE',
|
|
740
|
+
'INVALID_CONTEXT', 'SCHEMA_VERSION_UNSUPPORTED', 'DEPENDENCY_UNAVAILABLE', 'DEPENDENCY_FAILED',
|
|
697
741
|
'RATE_LIMITED', 'CATALOG_STALE', 'DATA_MIGRATION_REQUIRED',
|
|
698
742
|
'INVALID_CLIENT', 'REMOTE_ACCESS_TOKEN_INVALID', 'ECWEB_TOKEN_INVALID', 'CLIENT_BUSY', 'INVALID_RESPONSE', 'TIMEOUT',
|
|
699
743
|
'RESPONSE_TOO_LARGE',
|
|
@@ -703,6 +747,9 @@ const STABLE_CODES = new Set([
|
|
|
703
747
|
'LOOP_TRIGGER_NOT_FOUND', 'LOOP_TRIGGER_DISABLED', 'LOOP_TRIGGER_INVALID',
|
|
704
748
|
'ROOT_NOT_FOUND', 'ROOT_FORBIDDEN', 'ROOT_EXPIRED', 'ROOT_SCOPE_MISMATCH', 'ROOT_PEER_MISMATCH',
|
|
705
749
|
'NOT_CONFIGURED', 'WORKSPACE_UNAVAILABLE',
|
|
750
|
+
'TEAM_MEMBER_NOT_CONTACT', 'CONTACT_BOOK_INVALID',
|
|
751
|
+
'WORKSPACE_INITIALIZING', 'JOB_EXPIRED', 'OPERATION_ID_REUSED', 'PA_IDENTITY_UNAVAILABLE',
|
|
752
|
+
'DIRECTORY_OCCUPIED', 'STATISTICS_UNAVAILABLE', 'WORKSPACE_IDENTITY_MISMATCH',
|
|
706
753
|
'INVALID_ROOT_ID', 'MISSING_ROOT_ID', 'INVALID_ROOT_PATH', 'NOT_A_DIRECTORY', 'FILE_TOO_LARGE',
|
|
707
754
|
// Agent initialization uses these codes to distinguish a retryable failure,
|
|
708
755
|
// an actor mismatch, and a plan/state conflict at the App boundary.
|
|
@@ -713,6 +760,8 @@ const STABLE_CODES = new Set([
|
|
|
713
760
|
'CONTROL_AID_RESERVED', 'CONTROL_AID_CONFLICT', 'HOST_AID_RESERVED', 'AGENT_IDENTITY_UNVERIFIED',
|
|
714
761
|
'OWNER_UNAVAILABLE', 'OWNERSHIP_CONFLICT', 'PROTECTED_FIELD', 'AGENTMD_UNVERIFIED', 'AGENTMD_NOT_FOUND',
|
|
715
762
|
'REMOTE_VERSION_UNAVAILABLE', 'REMOTE_VERSION_CONFLICT', 'PUBLISH_NOT_CONFIRMED',
|
|
763
|
+
// Event center (menu events)
|
|
764
|
+
'EVENT_CENTER_NOT_STARTED', 'PACK_NOT_FOUND', 'PACK_INVALID', 'BUS_CONFLICT',
|
|
716
765
|
]);
|
|
717
766
|
export function normalizeMenuError(error) {
|
|
718
767
|
const source = error && typeof error === 'object' ? error : {};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { assertMenuSchemaVersion, bindMenuExecutionContextArgs, resolveMenuCatalogContext, } from './menu-catalog.js';
|
|
2
|
+
import { normalizeMenuError, validateMenuRequest } from './menu-protocol.js';
|
|
3
|
+
export const MENU_QUERY_BATCH_MAX_ITEMS = 32;
|
|
4
|
+
export const MENU_QUERY_BATCH_CONCURRENCY = 6;
|
|
5
|
+
// An explicit read-only surface. Never dispatch a client-supplied cmd or verb.
|
|
6
|
+
export const MENU_QUERY_BATCH_NAMES = [
|
|
7
|
+
'role', 'agent', 'baseagent', 'activity', 'effort', 'model', 'chatmode', 'team-workspace',
|
|
8
|
+
];
|
|
9
|
+
const QUERY_NAMES = new Set(MENU_QUERY_BATCH_NAMES);
|
|
10
|
+
const ROLE_VIEWS = new Set(['capabilities', 'target', 'role', 'requester']);
|
|
11
|
+
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
12
|
+
function record(value) {
|
|
13
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function invalid(message) { throw { code: 'INVALID_ARGUMENT', message }; }
|
|
16
|
+
function pointerParts(path) {
|
|
17
|
+
if (!path.startsWith('/') || path.length > 512 || /~(?![01])/.test(path)) {
|
|
18
|
+
invalid('argsFrom.path must be a JSON Pointer relative to the source item data');
|
|
19
|
+
}
|
|
20
|
+
const parts = path.slice(1).split('/').map(part => part.replace(/~1/g, '/').replace(/~0/g, '~'));
|
|
21
|
+
if (parts.length > 16 || parts.some(part => UNSAFE_KEYS.has(part)))
|
|
22
|
+
invalid('unsupported argsFrom.path');
|
|
23
|
+
return parts;
|
|
24
|
+
}
|
|
25
|
+
function queryItems(value) {
|
|
26
|
+
if (!Array.isArray(value) || value.length < 1 || value.length > MENU_QUERY_BATCH_MAX_ITEMS) {
|
|
27
|
+
invalid(`items must contain 1 to ${MENU_QUERY_BATCH_MAX_ITEMS} queries`);
|
|
28
|
+
}
|
|
29
|
+
const seen = new Set();
|
|
30
|
+
return value.map(raw => {
|
|
31
|
+
if (!record(raw))
|
|
32
|
+
invalid('each query item must be an object');
|
|
33
|
+
if (Object.keys(raw).some(key => !['itemId', 'name', 'args', 'context', 'argsFrom'].includes(key))) {
|
|
34
|
+
invalid('query items only accept itemId, name, args, context and argsFrom');
|
|
35
|
+
}
|
|
36
|
+
const itemId = typeof raw.itemId === 'string' ? raw.itemId.trim() : '';
|
|
37
|
+
const name = typeof raw.name === 'string' ? raw.name.trim() : '';
|
|
38
|
+
if (!itemId || itemId.length > 200 || seen.has(itemId))
|
|
39
|
+
invalid('itemId must be non-empty, unique and at most 200 characters');
|
|
40
|
+
if (!name || name.length > 100)
|
|
41
|
+
invalid('each query requires a name of at most 100 characters');
|
|
42
|
+
if (raw.args !== undefined && !record(raw.args))
|
|
43
|
+
invalid('query args must be an object');
|
|
44
|
+
const args = raw.args;
|
|
45
|
+
if (args && Object.keys(args).some(key => key === 'context' || UNSAFE_KEYS.has(key))) {
|
|
46
|
+
invalid('put context on the query item; unsafe argument keys are not supported');
|
|
47
|
+
}
|
|
48
|
+
if (raw.context !== undefined && !record(raw.context))
|
|
49
|
+
invalid('query context must be an object');
|
|
50
|
+
if (raw.argsFrom !== undefined) {
|
|
51
|
+
if (!record(raw.argsFrom))
|
|
52
|
+
invalid('argsFrom must be an object');
|
|
53
|
+
for (const [key, ref] of Object.entries(raw.argsFrom)) {
|
|
54
|
+
if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(key) || UNSAFE_KEYS.has(key) || key === 'context'
|
|
55
|
+
|| Object.prototype.hasOwnProperty.call(args ?? {}, key))
|
|
56
|
+
invalid('argsFrom must define distinct argument names');
|
|
57
|
+
if (!record(ref) || Object.keys(ref).some(field => field !== 'itemId' && field !== 'path')
|
|
58
|
+
|| typeof ref.itemId !== 'string' || !seen.has(ref.itemId) || typeof ref.path !== 'string') {
|
|
59
|
+
invalid('argsFrom must reference an earlier item using itemId and path');
|
|
60
|
+
}
|
|
61
|
+
pointerParts(ref.path);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
seen.add(itemId);
|
|
65
|
+
return { itemId, name, ...(args ? { args } : {}),
|
|
66
|
+
...(raw.context !== undefined ? { context: raw.context } : {}),
|
|
67
|
+
...(raw.argsFrom !== undefined ? { argsFrom: raw.argsFrom } : {}) };
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export function validateMenuQueryBatchArgs(value) {
|
|
71
|
+
if (!record(value))
|
|
72
|
+
invalid('query batch args must be an object');
|
|
73
|
+
if (Object.keys(value).some(key => !['view', 'schemaVersion', 'consistency', 'context', 'items'].includes(key))) {
|
|
74
|
+
invalid('unsupported query batch argument');
|
|
75
|
+
}
|
|
76
|
+
if (value.view !== 'queries')
|
|
77
|
+
throw { code: 'NOT_SUPPORTED', message: 'query batch requires args.view=queries' };
|
|
78
|
+
assertMenuSchemaVersion(value.schemaVersion);
|
|
79
|
+
if (value.consistency !== undefined && value.consistency !== 'best-effort') {
|
|
80
|
+
throw { code: 'NOT_SUPPORTED', message: 'Only best-effort batch consistency is supported' };
|
|
81
|
+
}
|
|
82
|
+
if (value.context !== undefined && !record(value.context))
|
|
83
|
+
invalid('batch context must be an object');
|
|
84
|
+
queryItems(value.items); // Validate the entire dependency graph before dispatching anything.
|
|
85
|
+
}
|
|
86
|
+
function referencedValue(result, ref) {
|
|
87
|
+
if (!result.ok)
|
|
88
|
+
throw { code: 'DEPENDENCY_FAILED', message: `Query dependency ${ref.itemId} failed`, data: { itemId: ref.itemId } };
|
|
89
|
+
let value = result.data;
|
|
90
|
+
for (const key of pointerParts(ref.path)) {
|
|
91
|
+
if ((!record(value) && !Array.isArray(value)) || !Object.prototype.hasOwnProperty.call(value, key)) {
|
|
92
|
+
throw { code: 'DEPENDENCY_FAILED', message: `Query dependency ${ref.itemId} has no value at ${ref.path}`, data: ref };
|
|
93
|
+
}
|
|
94
|
+
value = value[key];
|
|
95
|
+
}
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
export async function execMenuQueryBatch(input) {
|
|
99
|
+
validateMenuQueryBatchArgs(input.args);
|
|
100
|
+
const items = queryItems(input.args.items);
|
|
101
|
+
const pending = new Map();
|
|
102
|
+
const contexts = new Map();
|
|
103
|
+
let active = 0;
|
|
104
|
+
const waiters = [];
|
|
105
|
+
const limited = async (run) => {
|
|
106
|
+
if (active >= MENU_QUERY_BATCH_CONCURRENCY)
|
|
107
|
+
await new Promise(resolve => waiters.push(resolve));
|
|
108
|
+
else
|
|
109
|
+
active++;
|
|
110
|
+
try {
|
|
111
|
+
return await run();
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
const next = waiters.shift();
|
|
115
|
+
if (next)
|
|
116
|
+
next(); // Transfer the existing slot to the next query.
|
|
117
|
+
else
|
|
118
|
+
active--;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const run = async (item) => {
|
|
122
|
+
const header = { itemId: item.itemId, name: item.name };
|
|
123
|
+
try {
|
|
124
|
+
if (!QUERY_NAMES.has(item.name))
|
|
125
|
+
throw { code: 'NOT_SUPPORTED', message: `Query batch does not support ${item.name}` };
|
|
126
|
+
const args = { ...(item.args ?? {}) };
|
|
127
|
+
const refs = Object.entries(item.argsFrom ?? {});
|
|
128
|
+
const values = await Promise.all(refs.map(async ([key, ref]) => [key, referencedValue(await pending.get(ref.itemId), ref)]));
|
|
129
|
+
for (const [key, value] of values)
|
|
130
|
+
args[key] = value;
|
|
131
|
+
if (item.name === 'role' && !ROLE_VIEWS.has(String(args.view))) {
|
|
132
|
+
throw { code: 'NOT_SUPPORTED', message: 'Query batch supports role capabilities, target, role and requester views' };
|
|
133
|
+
}
|
|
134
|
+
if (item.name === 'team-workspace' && args.view !== 'members') {
|
|
135
|
+
throw { code: 'NOT_SUPPORTED', message: 'Query batch only supports the team-workspace members view' };
|
|
136
|
+
}
|
|
137
|
+
if (item.name === 'team-workspace'
|
|
138
|
+
&& (input.subject.menuTransportChatType ?? input.subject.chatType) !== 'private') {
|
|
139
|
+
throw { code: 'FORBIDDEN', message: 'Team members require an AUN private Agent conversation' };
|
|
140
|
+
}
|
|
141
|
+
const invalidRequest = validateMenuRequest({ type: 'menu.query', name: item.name, args });
|
|
142
|
+
if (invalidRequest)
|
|
143
|
+
throw invalidRequest;
|
|
144
|
+
return await limited(async () => {
|
|
145
|
+
// Keep the receiving Agent fixed, including for Control requests. The
|
|
146
|
+
// outer request selects its Agent; item arguments cannot impersonate it.
|
|
147
|
+
if (!input.subject.selfAid)
|
|
148
|
+
throw { code: 'MISSING_AID', message: 'Query batch requires a target Agent' };
|
|
149
|
+
for (const key of ['self', 'aid']) {
|
|
150
|
+
if (args[key] !== undefined && args[key] !== input.subject.selfAid) {
|
|
151
|
+
throw { code: 'FORBIDDEN', message: 'Query batch items must target the receiving Agent' };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
let subject = input.subject;
|
|
155
|
+
let channelId = input.channelId;
|
|
156
|
+
let queryArgs = args;
|
|
157
|
+
const request = item.context ?? input.args.context;
|
|
158
|
+
if (request !== undefined) {
|
|
159
|
+
const key = JSON.stringify(request);
|
|
160
|
+
let contextPromise = contexts.get(key);
|
|
161
|
+
if (!contextPromise) {
|
|
162
|
+
contextPromise = resolveMenuCatalogContext({ ...input, request: request });
|
|
163
|
+
contexts.set(key, contextPromise);
|
|
164
|
+
}
|
|
165
|
+
const context = await contextPromise;
|
|
166
|
+
if (context.kind === 'process')
|
|
167
|
+
throw { code: 'INVALID_CONTEXT', message: 'Query batches require an Agent or relation context' };
|
|
168
|
+
subject = context.subject;
|
|
169
|
+
channelId = context.channelId;
|
|
170
|
+
// These resource queries have their own exact argument contracts.
|
|
171
|
+
if (!['role', 'agent', 'team-workspace'].includes(item.name)) {
|
|
172
|
+
queryArgs = bindMenuExecutionContextArgs(args, context) ?? {};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (item.name === 'agent')
|
|
176
|
+
queryArgs = { ...queryArgs, aid: subject.selfAid };
|
|
177
|
+
if (item.name === 'role' && args.view !== 'requester')
|
|
178
|
+
queryArgs = { ...queryArgs, self: subject.selfAid };
|
|
179
|
+
const result = await input.execQuery(`/${item.name}`, channelId, queryArgs, subject);
|
|
180
|
+
if ('error' in result)
|
|
181
|
+
throw { code: result.code, message: result.error, data: result.data };
|
|
182
|
+
return { ...header, ok: true, data: result.data };
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
return { ...header, ok: false, error: normalizeMenuError(error) };
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
for (const item of items)
|
|
190
|
+
pending.set(item.itemId, run(item));
|
|
191
|
+
const results = await Promise.all(pending.values());
|
|
192
|
+
return { $schema_version: 1, kind: 'menu.query_batch', consistency: 'best-effort',
|
|
193
|
+
observedAt: Date.now(), items: results };
|
|
194
|
+
}
|
|
@@ -226,7 +226,7 @@ export async function guardIdleCommand(opts) {
|
|
|
226
226
|
return undefined;
|
|
227
227
|
let hasActiveStream = false;
|
|
228
228
|
try {
|
|
229
|
-
hasActiveStream = opts.getAgentForSession(threadSession)
|
|
229
|
+
hasActiveStream = opts.getAgentForSession(threadSession)?.hasActiveStream(threadSession.id) ?? false;
|
|
230
230
|
}
|
|
231
231
|
catch {
|
|
232
232
|
// Runner mismatch should not block recovery commands such as /baseagent.
|
|
@@ -448,8 +448,8 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
448
448
|
const activeSession = await this.sessionManager.getActiveSession(channel, channelId);
|
|
449
449
|
let activeAgent;
|
|
450
450
|
const getActiveAgent = () => {
|
|
451
|
-
if (!activeAgent)
|
|
452
|
-
activeAgent = this.
|
|
451
|
+
if (!activeAgent && activeSession)
|
|
452
|
+
activeAgent = this.getLoadedAgent(channel, activeSession.baseagent);
|
|
453
453
|
return activeAgent;
|
|
454
454
|
};
|
|
455
455
|
const getActiveAgentIfAvailable = () => {
|
|
@@ -491,7 +491,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
491
491
|
|| activeSession?.chatType
|
|
492
492
|
|| (chatType === 'group' ? 'group' : 'private');
|
|
493
493
|
const chatmodeChoices = activeChatType === 'group' ? 'proactive'
|
|
494
|
-
:
|
|
494
|
+
: 'interactive|proactive';
|
|
495
495
|
const groupSlash = applyGroupSlashPolicy && activeChatType === 'group';
|
|
496
496
|
if (applyGroupSlashPolicy) {
|
|
497
497
|
const groupGuard = guardGroupSlashCommand(normalizedContent, activeChatType);
|
|
@@ -570,7 +570,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
570
570
|
sessionManager: this.sessionManager,
|
|
571
571
|
messageQueue: this.messageQueue,
|
|
572
572
|
isSessionPaused: sessionId => this.processor?.isPauseRequested?.(sessionId) ?? false,
|
|
573
|
-
getAgentForSession: session => this.
|
|
573
|
+
getAgentForSession: session => this.getLoadedAgent(channel, session.baseagent),
|
|
574
574
|
});
|
|
575
575
|
if (idleGuard)
|
|
576
576
|
return idleGuard;
|
|
@@ -794,7 +794,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
794
794
|
const probeBackendActivity = (current, gateSnapshot) => {
|
|
795
795
|
const probes = {
|
|
796
796
|
paused: () => this.processor?.isPauseRequested?.(current.id) ?? false,
|
|
797
|
-
activeStream: () => this.
|
|
797
|
+
activeStream: () => this.getLoadedAgent(channel, current.baseagent)?.hasActiveStream(current.id) ?? false,
|
|
798
798
|
};
|
|
799
799
|
if (this.permissionGateway) {
|
|
800
800
|
probes.pendingPermission = () => this.permissionGateway.getPendingRequests(current.id).length > 0;
|
|
@@ -1286,7 +1286,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
1286
1286
|
const permSession = await getExistingSessionForCommand();
|
|
1287
1287
|
if (!permSession)
|
|
1288
1288
|
return { kind: 'command.result', text: '当前没有活跃会话' };
|
|
1289
|
-
const permAgent = this.
|
|
1289
|
+
const permAgent = await this.ensureAgent(channel, permSession.baseagent);
|
|
1290
1290
|
// 角色来自会话身份;permissionMode 只从该角色定义解析。
|
|
1291
1291
|
const permSelfAid = selfAID ?? permSession.selfAID ?? this.resolveSelfAID(channel);
|
|
1292
1292
|
const permChannelType = permSession.channelType ?? this.resolveChannelType(channel);
|
|
@@ -1420,7 +1420,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
1420
1420
|
if (!pauseSession) {
|
|
1421
1421
|
return { kind: 'system.notice', text: '当前没有活跃会话', subtype: 'session.pause.idle' };
|
|
1422
1422
|
}
|
|
1423
|
-
const pauseAgent = this.
|
|
1423
|
+
const pauseAgent = await this.ensureAgent(channel, pauseSession.baseagent);
|
|
1424
1424
|
const hasActiveTask = pauseAgent.hasActiveStream(pauseSession.id)
|
|
1425
1425
|
|| this.messageQueue.isProcessing(pauseSession.id);
|
|
1426
1426
|
if (!hasActiveTask) {
|
|
@@ -1511,6 +1511,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
1511
1511
|
const currentSession = await getExistingSessionForCommand();
|
|
1512
1512
|
const previousBaseagent = owningAgent.baseagent || this.parseDefaultBaseagent();
|
|
1513
1513
|
try {
|
|
1514
|
+
await this.ensureAgent(channel, args, owningAgent.aid);
|
|
1514
1515
|
owningAgent.setActiveBaseagent(args);
|
|
1515
1516
|
}
|
|
1516
1517
|
catch (error) {
|
|
@@ -1529,7 +1530,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
1529
1530
|
if (args === 'reset' || args === 'check') {
|
|
1530
1531
|
const modelSession = await getExistingSessionForCommand();
|
|
1531
1532
|
const fallbackBaseagent = modelSession?.baseagent || this.agentRegistry?.resolveByChannel(channel)?.baseagent || this.parseDefaultBaseagent();
|
|
1532
|
-
const modelAgent = this.
|
|
1533
|
+
const modelAgent = await this.ensureAgent(channel, fallbackBaseagent);
|
|
1533
1534
|
const modelChatType = modelSession?.chatType
|
|
1534
1535
|
?? (chatType === 'private' || chatType === 'group' ? chatType : undefined);
|
|
1535
1536
|
const peerKeyId = modelChatType === 'group'
|
|
@@ -1621,7 +1622,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
1621
1622
|
if (!args || args === 'list' || args === 'current') {
|
|
1622
1623
|
const modelSession = await getExistingSessionForCommand();
|
|
1623
1624
|
const fallbackBaseagent = modelSession?.baseagent || this.agentRegistry?.resolveByChannel(channel)?.baseagent || this.parseDefaultBaseagent();
|
|
1624
|
-
const modelAgent = this.
|
|
1625
|
+
const modelAgent = await this.ensureAgent(channel, fallbackBaseagent);
|
|
1625
1626
|
const modelTarget = resolveSlashRelationTarget.call(this, {
|
|
1626
1627
|
session: modelSession,
|
|
1627
1628
|
channel,
|
|
@@ -1774,7 +1775,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
1774
1775
|
}
|
|
1775
1776
|
// 切换模型写入 Agent 级 baseagents 配置;没有活跃会话时也不应创建空会话。
|
|
1776
1777
|
const fallbackBaseagent = modelSession?.baseagent || this.agentRegistry?.resolveByChannel(channel)?.baseagent || this.parseDefaultBaseagent();
|
|
1777
|
-
const modelAgent = this.
|
|
1778
|
+
const modelAgent = await this.ensureAgent(channel, fallbackBaseagent);
|
|
1778
1779
|
const modelSelector = { self: selfAID ?? modelSession?.selfAID ?? this.resolveSelfAID(channel) };
|
|
1779
1780
|
let configuredModel;
|
|
1780
1781
|
try {
|
|
@@ -1903,7 +1904,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
1903
1904
|
if (!args) {
|
|
1904
1905
|
const effortSession = await getExistingSessionForCommand();
|
|
1905
1906
|
const fallbackBaseagent = effortSession?.baseagent || this.agentRegistry?.resolveByChannel(channel)?.baseagent || this.parseDefaultBaseagent();
|
|
1906
|
-
const effortAgent = this.
|
|
1907
|
+
const effortAgent = await this.ensureAgent(channel, fallbackBaseagent);
|
|
1907
1908
|
const effortSelector = { self: selfAID ?? effortSession?.selfAID ?? this.resolveSelfAID(channel) };
|
|
1908
1909
|
let modelConfig = {};
|
|
1909
1910
|
try {
|
|
@@ -1969,7 +1970,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
1969
1970
|
}
|
|
1970
1971
|
const effortSession = await getExistingSessionForCommand();
|
|
1971
1972
|
const fallbackBaseagent = effortSession?.baseagent || this.agentRegistry?.resolveByChannel(channel)?.baseagent || this.parseDefaultBaseagent();
|
|
1972
|
-
const effortAgent = this.
|
|
1973
|
+
const effortAgent = await this.ensureAgent(channel, fallbackBaseagent);
|
|
1973
1974
|
const effortSelf = selfAID ?? effortSession?.selfAID ?? this.resolveSelfAID(channel);
|
|
1974
1975
|
let modelConfig = {};
|
|
1975
1976
|
try {
|
|
@@ -2216,7 +2217,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
2216
2217
|
return null;
|
|
2217
2218
|
return { kind: 'command.result', text: `✅ 中间输出模式: ${activityArg}(${label})` };
|
|
2218
2219
|
}
|
|
2219
|
-
// /chatmode 命令:私聊提供 interactive/proactive
|
|
2220
|
+
// /chatmode 命令:私聊提供 interactive/proactive,群聊固定 proactive
|
|
2220
2221
|
// - 查看:所有人可用
|
|
2221
2222
|
// - 设置:单聊任何角色可设置;群聊仅管理员可设置
|
|
2222
2223
|
if (normalizedContent === '/chatmode' || normalizedContent.startsWith('/chatmode ')) {
|
|
@@ -2229,9 +2230,6 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
2229
2230
|
...(activeChatType !== 'group'
|
|
2230
2231
|
? [{ key: 'interactive', name: '交互模式', desc: '被动响应:收到消息时才回复,回复直接显示' }] : []),
|
|
2231
2232
|
{ key: 'proactive', name: '主动模式', desc: '主动推进:流式输出静默,由 Agent 自调 ctl send 发声' },
|
|
2232
|
-
...((existingChatmodeSession?.channelType ?? this.resolveChannelType?.(channel)) === 'aun'
|
|
2233
|
-
&& activeChatType === 'private' && identity.role === 'owner'
|
|
2234
|
-
? [{ key: 'paactive', name: 'PA 模式', desc: '自动文本显示为 activity,正式回复由 Agent 显式发送' }] : []),
|
|
2235
2233
|
];
|
|
2236
2234
|
const interaction = {
|
|
2237
2235
|
type: 'interaction',
|
|
@@ -2291,29 +2289,23 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
2291
2289
|
if (target.field === 'group' && arg !== 'proactive') {
|
|
2292
2290
|
return { kind: 'command.error', text: '❌ 群聊仅支持 proactive 模式' };
|
|
2293
2291
|
}
|
|
2294
|
-
if (arg === 'paactive' && identity.role !== 'owner') {
|
|
2295
|
-
return { kind: 'command.error', text: '❌ paactive 模式仅限 owner' };
|
|
2296
|
-
}
|
|
2297
2292
|
if (arg === currentMode) {
|
|
2298
2293
|
return { kind: 'command.result', text: `📋 当前会话模式已是 ${arg}` };
|
|
2299
2294
|
}
|
|
2300
|
-
if (
|
|
2295
|
+
if (arg === 'interactive' && isPrivateChatmodeRoleLocked(target.field, target.role)) {
|
|
2301
2296
|
return { kind: 'command.error', text: '❌ 私聊交互模式仅限 owner/admin,当前角色固定为 proactive' };
|
|
2302
2297
|
}
|
|
2303
|
-
if (arg === 'paactive' && (target.field !== 'private' || !target.sel.peerKey?.startsWith('aun#'))) {
|
|
2304
|
-
return { kind: 'command.error', text: '❌ paactive 仅支持 AUN 人类私聊' };
|
|
2305
|
-
}
|
|
2306
2298
|
// 仅在真正需要切换时才要求会话空闲
|
|
2307
2299
|
if (chatmodeSession && threadId) {
|
|
2308
2300
|
const threadSession = await this.sessionManager.getThreadSession(channel, channelId, threadId);
|
|
2309
2301
|
if (threadSession) {
|
|
2310
|
-
const threadAgent = this.
|
|
2302
|
+
const threadAgent = await this.ensureAgent(channel, threadSession.baseagent);
|
|
2311
2303
|
if (threadAgent.hasActiveStream(threadSession.id) || this.messageQueue?.isProcessing(threadSession.id)) {
|
|
2312
2304
|
return { kind: 'command.error', text: '⚠️ 当前正在处理消息,请稍后再试\n使用 /stop 中断当前任务后重试' };
|
|
2313
2305
|
}
|
|
2314
2306
|
}
|
|
2315
2307
|
}
|
|
2316
|
-
else if (chatmodeSession && (getActiveAgent()
|
|
2308
|
+
else if (chatmodeSession && (getActiveAgent()?.hasActiveStream(chatmodeSession.id) || this.messageQueue?.isProcessing(chatmodeSession.id))) {
|
|
2317
2309
|
return { kind: 'command.error', text: '⚠️ 当前正在处理消息,请稍后再试\n使用 /stop 中断当前任务后重试' };
|
|
2318
2310
|
}
|
|
2319
2311
|
const chatmodeAuthDenied = await authorizeIntent({
|
|
@@ -2340,7 +2332,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
2340
2332
|
if (chatmodeAuthDenied)
|
|
2341
2333
|
return chatmodeAuthDenied;
|
|
2342
2334
|
try {
|
|
2343
|
-
writeChatmodeConfig({ ...target, scope: 'relation' }, arg
|
|
2335
|
+
writeChatmodeConfig({ ...target, scope: 'relation' }, arg);
|
|
2344
2336
|
}
|
|
2345
2337
|
catch (e) {
|
|
2346
2338
|
return { kind: 'command.error', text: `Failed to update relation chatmode: ${e?.message || e}` };
|
|
@@ -2458,11 +2450,11 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
2458
2450
|
if (!stopSession) {
|
|
2459
2451
|
return { kind: 'system.notice', text: '当前没有正在处理的任务', subtype: 'session.stop.idle' };
|
|
2460
2452
|
}
|
|
2461
|
-
const stopAgent = this.
|
|
2453
|
+
const stopAgent = this.getLoadedAgent(channel, stopSession.baseagent);
|
|
2462
2454
|
const sessionKey = stopSession.id;
|
|
2463
2455
|
this.processor?.clearPauseSession?.(sessionKey);
|
|
2464
2456
|
const queueLength = this.messageQueue.getQueueLength(sessionKey);
|
|
2465
|
-
const hasActive = stopAgent
|
|
2457
|
+
const hasActive = stopAgent?.hasActiveStream(sessionKey) ?? false;
|
|
2466
2458
|
const isProcessing = this.messageQueue.isProcessing(sessionKey);
|
|
2467
2459
|
if (queueLength === 0 && !hasActive && !isProcessing) {
|
|
2468
2460
|
// Even an idle session can have an undelivered task:error recovery.
|
|
@@ -2612,7 +2604,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
2612
2604
|
const projectPath = path.isAbsolute(session.projectPath)
|
|
2613
2605
|
? session.projectPath
|
|
2614
2606
|
: path.resolve(process.cwd(), session.projectPath);
|
|
2615
|
-
const currentSessionAgent = this.
|
|
2607
|
+
const currentSessionAgent = await this.ensureAgent(channel, session.baseagent);
|
|
2616
2608
|
if (!currentSessionAgent.capabilities?.compact) {
|
|
2617
2609
|
return { kind: 'command.error', text: `❌ 当前 Agent (${currentSessionAgent.name}) 不支持 /compact` };
|
|
2618
2610
|
}
|
|
@@ -2728,12 +2720,12 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
2728
2720
|
return { kind: 'command.result', text: `📊 会话状态:当前没有活跃会话\n发送消息或使用 /new [名称] 创建会话` };
|
|
2729
2721
|
}
|
|
2730
2722
|
const sessionKey = this.getQueueKey(session, channel, channelId);
|
|
2731
|
-
const sessionAgent = this.
|
|
2732
|
-
const isCurrentlyProcessing = this.messageQueue.isProcessing(sessionKey) || sessionAgent
|
|
2733
|
-
|| sessionAgent
|
|
2723
|
+
const sessionAgent = this.getLoadedAgent(channel, session.baseagent);
|
|
2724
|
+
const isCurrentlyProcessing = this.messageQueue.isProcessing(sessionKey) || sessionAgent?.hasActiveStream(sessionKey)
|
|
2725
|
+
|| sessionAgent?.hasActiveOperation?.(sessionKey) === true;
|
|
2734
2726
|
const queueLength = this.messageQueue.getQueueLength(sessionKey);
|
|
2735
2727
|
const isThread = isTopicSession(session);
|
|
2736
|
-
const executionState = sessionAgent
|
|
2728
|
+
const executionState = sessionAgent?.getExecutionState?.(sessionKey);
|
|
2737
2729
|
let sessionStatus = executionState === 'interrupting' ? '中断收尾中(等待旧执行退出)' : isCurrentlyProcessing || queueLength > 0 ? '处理中' : '空闲';
|
|
2738
2730
|
// 处理中时显示时长
|
|
2739
2731
|
if (isCurrentlyProcessing && executionState !== 'interrupting') {
|
|
@@ -2901,7 +2893,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
2901
2893
|
const newBaseagent = newSession.baseagent || newAgent?.baseagent || this.parseDefaultBaseagent();
|
|
2902
2894
|
// 与 /model 卡片保持一致:按 关系>角色>agent 解析实际生效的 model/effort,
|
|
2903
2895
|
// 不直接读 EvolAgent.model(那只是 agent 级静态配置,会无视关系/角色级覆盖)。
|
|
2904
|
-
const newRunner = this.
|
|
2896
|
+
const newRunner = await this.ensureAgent(channel, newSession.baseagent);
|
|
2905
2897
|
const newModelTarget = resolveSlashRelationTarget.call(this, {
|
|
2906
2898
|
session: newSession,
|
|
2907
2899
|
channel,
|
|
@@ -3888,7 +3880,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3888
3880
|
const oldName = displaySessionTitle(session.name, '(未命名)');
|
|
3889
3881
|
const success = await this.sessionManager.renameSession(session.id, newName);
|
|
3890
3882
|
if (success && session.agentSessionId) {
|
|
3891
|
-
const renameAgent = this.
|
|
3883
|
+
const renameAgent = await this.ensureAgent(channel, session.baseagent);
|
|
3892
3884
|
await renameAgent.setSessionName?.(session.agentSessionId, newName).catch((error) => {
|
|
3893
3885
|
logger.debug('[CommandHandler] Backend session rename sync failed:', error);
|
|
3894
3886
|
});
|
|
@@ -3961,9 +3953,9 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3961
3953
|
return { kind: 'command.error', text: `❌ 删除失败` };
|
|
3962
3954
|
}
|
|
3963
3955
|
this.eventBus.publish({ type: 'session:deleted', sessionId: targetSession.id });
|
|
3964
|
-
const targetAgent = this.
|
|
3956
|
+
const targetAgent = this.getLoadedAgent(channel, targetSession.baseagent);
|
|
3965
3957
|
this.processor?.clearPauseSession?.(targetSession.id);
|
|
3966
|
-
await targetAgent
|
|
3958
|
+
await targetAgent?.closeSession(targetSession.id);
|
|
3967
3959
|
return { kind: 'command.result', text: `✓ 已删除会话: ${displaySessionTitle(targetSession.name, sessionName)}\n会话文件已保留,可通过 CLI 访问` };
|
|
3968
3960
|
}
|
|
3969
3961
|
// /fork 命令:分支当前会话
|
|
@@ -3975,7 +3967,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
3975
3967
|
if (!session.agentSessionId) {
|
|
3976
3968
|
return { kind: 'command.error', text: `❌ 当前会话尚未初始化对话,无法分支\n\n请先发送一条消息,然后再使用 /fork` };
|
|
3977
3969
|
}
|
|
3978
|
-
const forkAgent = this.
|
|
3970
|
+
const forkAgent = await this.ensureAgent(channel, session.baseagent);
|
|
3979
3971
|
if (!forkAgent.capabilities?.fork) {
|
|
3980
3972
|
return { kind: 'command.error', text: `❌ 当前 Agent (${forkAgent.name}) 不支持 /fork\n\n可使用 /new 创建新会话替代` };
|
|
3981
3973
|
}
|
|
@@ -4015,7 +4007,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
4015
4007
|
if (!rewindBaseagent) {
|
|
4016
4008
|
return { kind: 'command.error', text: '❌ 当前会话缺少 baseagent 绑定,拒绝隐式切换' };
|
|
4017
4009
|
}
|
|
4018
|
-
const rewindAgent = this.
|
|
4010
|
+
const rewindAgent = await this.ensureAgent(channel, rewindBaseagent);
|
|
4019
4011
|
if (!session.agentSessionId) {
|
|
4020
4012
|
return { kind: 'command.error', text: '❌ 当前会话无历史记录\n\n请先发送一条消息,然后再使用 /rewind' };
|
|
4021
4013
|
}
|
|
@@ -4052,7 +4044,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
4052
4044
|
if (!current.agentSessionId) {
|
|
4053
4045
|
return '❌ 当前会话无历史记录\n\n请先发送一条消息,然后再使用 /rewind';
|
|
4054
4046
|
}
|
|
4055
|
-
const currentAgent = this.
|
|
4047
|
+
const currentAgent = await this.ensureAgent(channel, current.baseagent);
|
|
4056
4048
|
if (!currentAgent.getSessionMessages) {
|
|
4057
4049
|
return `❌ 当前 Agent (${currentAgent.name}) 不支持 /rewind`;
|
|
4058
4050
|
}
|
|
@@ -4075,7 +4067,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
4075
4067
|
if (!rewindBaseagent) {
|
|
4076
4068
|
return { kind: 'command.error', text: '❌ 当前会话缺少 baseagent 绑定,拒绝隐式切换' };
|
|
4077
4069
|
}
|
|
4078
|
-
const rewindAgent = this.
|
|
4070
|
+
const rewindAgent = await this.ensureAgent(channel, rewindBaseagent);
|
|
4079
4071
|
if (!session.agentSessionId) {
|
|
4080
4072
|
return { kind: 'command.error', text: '❌ 当前会话无历史记录\n\n请先发送一条消息,然后再使用 /rewind' };
|
|
4081
4073
|
}
|
|
@@ -4093,7 +4085,7 @@ export async function handleSlashCommand(content, channel, channelId, sendMessag
|
|
|
4093
4085
|
const repairSession = await getExistingSessionForCommand();
|
|
4094
4086
|
if (!repairSession)
|
|
4095
4087
|
return { kind: 'command.result', text: '当前没有活跃会话' };
|
|
4096
|
-
const repairAgent = this.
|
|
4088
|
+
const repairAgent = await this.ensureAgent(channel, repairSession.baseagent);
|
|
4097
4089
|
const { checkSessionFile, backupSessionFile } = await import('../session/session-file-health.js');
|
|
4098
4090
|
await interruptPausedSessionBeforeReplacement(repairSession);
|
|
4099
4091
|
try {
|