evolcore 0.0.43-test.5 → 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 +95 -0
- package/bin/ecmsg.js +281 -81
- package/dist/agents/baseagent-availability.js +20 -5
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +36 -3
- package/dist/agents/codex-runner.js +75 -8
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +306 -30
- package/dist/cli/agent-create.js +18 -8
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +34 -65
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +38 -3
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/init.js +75 -0
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +67 -50
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-logs.js +6 -4
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +1 -8
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/provider-identity-migration.js +92 -17
- package/dist/config/provider-local-sync.js +2 -0
- package/dist/config/providers-config.js +13 -0
- package/dist/config/providers-management.js +100 -10
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +86 -88
- package/dist/config/snapshot.js +70 -41
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +146 -15
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +75 -42
- package/dist/core/channel-loader.js +45 -13
- package/dist/core/channel-runtime.js +116 -45
- 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 +58 -16
- 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 +206 -87
- package/dist/core/command/menu-protocol.js +142 -22
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/role-menu.js +27 -15
- 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 +45 -15
- package/dist/core/daemon-lifecycle.js +478 -75
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +130 -42
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +4 -4
- 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 +51 -11
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +149 -19
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +57 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +163 -52
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +55 -7
- package/dist/core/ownership/owner-resolver.js +8 -0
- package/dist/core/permission/ec-command-parser.js +14 -3
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +163 -3
- package/dist/core/session/session-idle-monitor.js +9 -1
- package/dist/core/session/session-manager.js +36 -2
- 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 +42 -30
- package/dist/directory/owner-directory-cache.js +143 -126
- package/dist/directory/owner-directory-query-operation.js +9 -8
- 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 +14 -8
- package/dist/ecweb/runtime/supervisor.js +62 -30
- 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 +751 -268
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +43 -18
- package/dist/proxy/service-supervisor.js +78 -35
- 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 +21 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +175 -13
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +109 -10
- package/dist/utils/startup-trace.js +222 -44
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +10 -17
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/ctl.md +2 -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 +2 -2
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +27 -8
- package/kits/docs/evolcore/provider.md +23 -3
- 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 +45 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +5 -6
- 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/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +9 -7
- package/kits/templates/system-fragments/reply.md +2 -6
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +11 -9
- package/package.json +5 -6
- 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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { authorizeLocalCommand } from './task-context.js';
|
|
3
|
+
import { agentWorkspaceDir } from '../paths.js';
|
|
4
|
+
import { readTeamWorkspaceNavigation, upsertTeamWorkspaceNavigation, removeTeamWorkspaceNavigation, updateTeamWorkspaceNavigation, } from '../core/command/team-workspace-store.js';
|
|
5
|
+
import { readTeamMembers, updateTeamMembers } from '../core/command/team-workspace-team.js';
|
|
6
|
+
import { TeamWorkspaceBootstrapService, TeamWorkspaceInitializer } from '../core/command/team-workspace-bootstrap.js';
|
|
7
|
+
const USAGE = `用法: ec team workspace init [--workspace <绝对路径>]
|
|
8
|
+
ec team navigation show
|
|
9
|
+
ec team navigation update --upsert-json <entries-json> [--expected-revision <n>]
|
|
10
|
+
ec team navigation update --remove-ids-json <ids-json> [--expected-revision <n>]
|
|
11
|
+
ec team navigation update --replace-json <entries-json> [--expected-revision <n>]
|
|
12
|
+
ec team members show
|
|
13
|
+
ec team members update --members-json <aids-json>
|
|
14
|
+
|
|
15
|
+
所有命令只输出 JSON;只允许当前 Agent Owner 的 AUN 私聊托管会话。`;
|
|
16
|
+
class TeamWorkspaceCommandError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
constructor(code, message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.name = 'TeamWorkspaceCommandError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function parseJsonFlag(args, flag) {
|
|
25
|
+
const index = args.indexOf(flag);
|
|
26
|
+
if (index < 0 || !args[index + 1])
|
|
27
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', `${flag} is required`);
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(args[index + 1]);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', `${flag} must contain valid JSON`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function assertFlags(args, allowed) {
|
|
36
|
+
const seen = new Set();
|
|
37
|
+
for (let index = 0; index < args.length; index += 2) {
|
|
38
|
+
const flag = args[index];
|
|
39
|
+
if (!allowed.includes(flag) || seen.has(flag) || !args[index + 1]) {
|
|
40
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', `Unexpected or duplicate argument: ${flag ?? ''}`);
|
|
41
|
+
}
|
|
42
|
+
seen.add(flag);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function expectedRevision(args, current) {
|
|
46
|
+
const index = args.indexOf('--expected-revision');
|
|
47
|
+
if (index < 0)
|
|
48
|
+
return current;
|
|
49
|
+
const raw = args[index + 1];
|
|
50
|
+
if (!raw || !/^\d+$/.test(raw))
|
|
51
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', '--expected-revision must be a non-negative integer');
|
|
52
|
+
const revision = Number(raw);
|
|
53
|
+
if (!Number.isSafeInteger(revision))
|
|
54
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', '--expected-revision must be a safe integer');
|
|
55
|
+
return revision;
|
|
56
|
+
}
|
|
57
|
+
function output(value) { process.stdout.write(`${JSON.stringify(value, null, 2)}\n`); }
|
|
58
|
+
function assertOwnerContext(context) {
|
|
59
|
+
if (context.channel !== 'aun' || context.chatType !== 'private' || context.peerRole !== 'owner' || !context.selfAid || !context.peerId) {
|
|
60
|
+
throw new TeamWorkspaceCommandError('NOT_ALLOWED', 'Team workspace commands require the current Agent Owner in an AUN private chat');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function initializeWorkspace(aid, ownerAid, suppliedPath) {
|
|
64
|
+
if (suppliedPath && !path.isAbsolute(suppliedPath))
|
|
65
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', '--workspace must be an absolute path');
|
|
66
|
+
const result = new TeamWorkspaceInitializer().initialize({ agentAid: aid, ownerAid }, suppliedPath ?? agentWorkspaceDir(aid), { allowExistingContent: !!suppliedPath });
|
|
67
|
+
return { workspaceId: result.state.workspaceId, navigationRevision: result.state.navigationRevision, rootPath: result.state.rootPath };
|
|
68
|
+
}
|
|
69
|
+
export async function cmdTeamWorkspace(rawArgs) {
|
|
70
|
+
if (rawArgs.length === 0 || rawArgs.includes('--help') || rawArgs.includes('-h')) {
|
|
71
|
+
console.log(USAGE);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const context = await authorizeLocalCommand(['team', ...rawArgs]);
|
|
76
|
+
assertOwnerContext(context);
|
|
77
|
+
if (rawArgs[0] === 'workspace' && rawArgs[1] === 'init') {
|
|
78
|
+
const pathIndex = rawArgs.indexOf('--workspace');
|
|
79
|
+
const workspace = pathIndex >= 0 ? rawArgs[pathIndex + 1] : undefined;
|
|
80
|
+
if (pathIndex >= 0 && (!workspace || rawArgs.length !== 4))
|
|
81
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
82
|
+
if (pathIndex < 0 && rawArgs.length !== 2)
|
|
83
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
84
|
+
if (!workspace)
|
|
85
|
+
new TeamWorkspaceBootstrapService().migrateLegacyDefault({ agentAid: context.selfAid, ownerAid: context.peerId });
|
|
86
|
+
output({ ok: true, ...initializeWorkspace(context.selfAid, context.peerId, workspace) });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (rawArgs[0] === 'navigation' && rawArgs[1] === 'show' && rawArgs.length === 2) {
|
|
90
|
+
new TeamWorkspaceBootstrapService().migrateLegacyDefault({ agentAid: context.selfAid, ownerAid: context.peerId });
|
|
91
|
+
output({ ok: true, ...readTeamWorkspaceNavigation(context.selfAid) });
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (rawArgs[0] === 'navigation' && rawArgs[1] === 'update') {
|
|
95
|
+
new TeamWorkspaceBootstrapService().migrateLegacyDefault({ agentAid: context.selfAid, ownerAid: context.peerId });
|
|
96
|
+
assertFlags(rawArgs.slice(2), ['--upsert-json', '--remove-ids-json', '--replace-json', '--expected-revision']);
|
|
97
|
+
const modes = ['--upsert-json', '--remove-ids-json', '--replace-json'].filter(flag => rawArgs.includes(flag));
|
|
98
|
+
if (modes.length !== 1)
|
|
99
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', 'Specify exactly one navigation update mode');
|
|
100
|
+
const navigation = readTeamWorkspaceNavigation(context.selfAid);
|
|
101
|
+
const revision = expectedRevision(rawArgs, navigation.navigationRevision);
|
|
102
|
+
const mode = modes[0];
|
|
103
|
+
const value = parseJsonFlag(rawArgs, mode);
|
|
104
|
+
let result;
|
|
105
|
+
if (mode === '--upsert-json')
|
|
106
|
+
result = upsertTeamWorkspaceNavigation(context.selfAid, revision, value);
|
|
107
|
+
else if (mode === '--remove-ids-json')
|
|
108
|
+
result = removeTeamWorkspaceNavigation(context.selfAid, revision, value);
|
|
109
|
+
else
|
|
110
|
+
result = updateTeamWorkspaceNavigation(context.selfAid, revision, value);
|
|
111
|
+
output({ ok: true, action: mode.slice(2, -5), ...result });
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (rawArgs[0] === 'members' && rawArgs[1] === 'show' && rawArgs.length === 2) {
|
|
115
|
+
output({ ok: true, aid: context.selfAid, members: readTeamMembers(context.selfAid) });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (rawArgs[0] === 'members' && rawArgs[1] === 'update') {
|
|
119
|
+
assertFlags(rawArgs.slice(2), ['--members-json']);
|
|
120
|
+
if (rawArgs.length !== 4)
|
|
121
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
122
|
+
const members = parseJsonFlag(rawArgs, '--members-json');
|
|
123
|
+
const result = updateTeamMembers(context.selfAid, members);
|
|
124
|
+
output({ ok: true, aid: context.selfAid, ...result });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
throw new TeamWorkspaceCommandError('INVALID_ARGUMENT', USAGE);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
const source = error;
|
|
131
|
+
process.stderr.write(`${JSON.stringify({ ok: false, code: source.code ?? 'TEAM_WORKSPACE_FAILED', error: error instanceof Error ? error.message : String(error) })}\n`);
|
|
132
|
+
process.exitCode = 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -15,7 +15,7 @@ const HELP_TEXT = `
|
|
|
15
15
|
list <peer> 列出与某对端的所有话题
|
|
16
16
|
show <ref> 查看单个话题的元数据
|
|
17
17
|
history <ref> 读取话题历史消息
|
|
18
|
-
create <peer> --name
|
|
18
|
+
create <peer> --name 新建话题(对端类型按关系证据自动识别,--group/--private 可覆盖)
|
|
19
19
|
rename <ref> <名称> 修改话题名称(仅本端)
|
|
20
20
|
label <ref> <标签> 设置话题标签
|
|
21
21
|
status <ref> <状态> 更新话题业务状态
|
|
@@ -382,7 +382,11 @@ export async function runThreadCommand(args) {
|
|
|
382
382
|
}
|
|
383
383
|
const label = argValue(args, '--label');
|
|
384
384
|
const topicStatus = argValue(args, '--status');
|
|
385
|
-
|
|
385
|
+
// 对端类型:显式 --group / --private 优先;都不写时 daemon 侧按关系证据
|
|
386
|
+
// 推断(这里不能自行补值——daemon 会用 argv 重建请求,两者必须一致)。
|
|
387
|
+
const peerKind = hasFlag(args, '--group')
|
|
388
|
+
? 'group'
|
|
389
|
+
: hasFlag(args, '--private') ? 'private' : undefined;
|
|
386
390
|
const resp = await sendOp({ op: 'create', selfAid, peer, name, label, topicStatus, peerKind });
|
|
387
391
|
if (!resp.ok) {
|
|
388
392
|
console.error(`✗ ${resp.error}`);
|
package/dist/cli/watch-logs.js
CHANGED
|
@@ -10,7 +10,8 @@ export function shortLogName(file) {
|
|
|
10
10
|
const stem = baseName.replace(WATCH_LOG_FILE, '');
|
|
11
11
|
return stem
|
|
12
12
|
.replace(/-\d{8}(?:-\d{2})?$/, '') // -YYYYMMDD[-HH](按日/小时轮转)
|
|
13
|
-
.replace(/-\d{4}-\d{2}-\d{2}
|
|
13
|
+
.replace(/-\d{4}-\d{2}-\d{2}(?:-\d{2})?$/, '')
|
|
14
|
+
.replace(/-[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i, '');
|
|
14
15
|
}
|
|
15
16
|
/** 从支持的日志文件名列表推导去重、字母序的类型列表。 */
|
|
16
17
|
export function deriveLogTypes(files) {
|
|
@@ -26,15 +27,16 @@ export function deriveLogTypes(files) {
|
|
|
26
27
|
export function computePreChecked(types, saved) {
|
|
27
28
|
if (saved === undefined)
|
|
28
29
|
return new Set(types);
|
|
29
|
-
const savedSet = new Set(saved);
|
|
30
|
+
const savedSet = new Set(saved.map(shortLogName));
|
|
30
31
|
return new Set(types.filter(t => savedSet.has(t)));
|
|
31
32
|
}
|
|
32
33
|
/** 返回 requested 中不在 available 里的无效类型。 */
|
|
33
34
|
export function validateLogTypes(requested, available) {
|
|
34
35
|
const set = new Set(available);
|
|
35
|
-
return requested.filter(
|
|
36
|
+
return requested.filter(type => !set.has(shortLogName(type)));
|
|
36
37
|
}
|
|
37
38
|
/** 只保留类型命中 filterTypes 的文件路径。 */
|
|
38
39
|
export function filterLogFiles(files, filterTypes) {
|
|
39
|
-
|
|
40
|
+
const normalizedTypes = new Set([...filterTypes].map(shortLogName));
|
|
41
|
+
return files.filter(file => normalizedTypes.has(shortLogName(file)));
|
|
40
42
|
}
|
package/dist/cli/watch-msg.js
CHANGED
|
@@ -302,7 +302,7 @@ function renderMessagesPanel(state, width, height) {
|
|
|
302
302
|
const isGroup = m.chatType === 'group';
|
|
303
303
|
const chatTag = isGroup ? `${MAGENTA}[群聊]${RST}` : '';
|
|
304
304
|
const encLabel = m.encrypt ? '密文' : '明文';
|
|
305
|
-
const modeLabel = m.chatmode === '
|
|
305
|
+
const modeLabel = m.chatmode === 'proactive' ? '自主' : '响应';
|
|
306
306
|
const metaTags = (m.encrypt != null || m.chatmode) ? `${MAGENTA}[${encLabel}|${modeLabel}]${RST}` : '';
|
|
307
307
|
// observer 插话:醒目标记,与对端真实消息区分
|
|
308
308
|
const injectTag = m.source === 'owner-inject' ? `${YELLOW}[插话]${RST}` : '';
|
package/dist/config/boot-log.js
CHANGED
|
@@ -19,7 +19,7 @@ import { ensureAccessPolicyMigrationOnStartup, ensureAgentModelProviderMigration
|
|
|
19
19
|
import { ensureContactBookV2OnStartup } from './peer-book-v2-startup.js';
|
|
20
20
|
import { synchronizeAllManagementPeersSync } from './peer-book-store.js';
|
|
21
21
|
import { readInstalledEvolcoreVersion, readFastaunVersion } from '../utils/evolcore-version.js';
|
|
22
|
-
import { readCurrent, readWVersion, writeWVersion, materializeVersion, listAllVersions, diffVersions, snapshot, isConfigSnapshotsEnabled, ensureStartupConfigSnapshot, incrementSuccessCount, retentionCleanup, writeSnapshotConfigFile, removeSnapshotConfigFile, } from './snapshot.js';
|
|
22
|
+
import { readCurrent, readWVersion, writeWVersion, materializeVersion, listAllVersions, diffVersions, snapshot, isConfigSnapshotsEnabled, ensureStartupConfigSnapshot, incrementSuccessCount, retentionCleanup, writeSnapshotConfigFile, removeSnapshotConfigFile, snapshotManagesFile, } from './snapshot.js';
|
|
23
23
|
const MAX_LINES = 300;
|
|
24
24
|
const KEEP_MIN = 150;
|
|
25
25
|
const FALLBACK_MAX_TRIES = 20;
|
|
@@ -98,10 +98,12 @@ export async function prepareStartupConfig(recoverRoleMutations, onStep) {
|
|
|
98
98
|
step('providerIdentity');
|
|
99
99
|
const providerIdentityMigration = await ensureProviderIdentityMigrationOnStartup();
|
|
100
100
|
if (providerIdentityMigration) {
|
|
101
|
-
const message = `Provider domain ID migration: ${providerIdentityMigration.summary.providersMigrated} provider(s), ${providerIdentityMigration.changedFiles} file(s)`
|
|
102
|
-
+ (providerIdentityMigration.backup ? `; backup: ${providerIdentityMigration.backup}` : '');
|
|
101
|
+
const message = `Provider domain ID migration: ${providerIdentityMigration.summary.providersMigrated} provider(s), ${providerIdentityMigration.changedFiles} file(s), ${providerIdentityMigration.summary.aliasesRemoved} alias(es) removed`
|
|
102
|
+
+ (providerIdentityMigration.backup ? `; backup version: ${providerIdentityMigration.backup}` : '');
|
|
103
103
|
logger.info(message);
|
|
104
104
|
console.error(message);
|
|
105
|
+
if (providerIdentityMigration.changedFiles && !providerIdentityMigration.backup)
|
|
106
|
+
logger.warn('[config] Provider migration completed without a version backup because configSnapshots=false; transaction recovery remains enabled');
|
|
105
107
|
if (providerIdentityMigration.pending.length) {
|
|
106
108
|
logger.warn(`[config] Provider domain required for legacy entries: ${providerIdentityMigration.pending.join(', ')}`);
|
|
107
109
|
}
|
|
@@ -413,7 +415,7 @@ async function expandToW(version, root) {
|
|
|
413
415
|
const { collectConfigFiles } = await import('./snapshot.js');
|
|
414
416
|
const existing = collectConfigFiles(root);
|
|
415
417
|
for (const rel of existing) {
|
|
416
|
-
if (!files.has(rel))
|
|
418
|
+
if (!files.has(rel) && snapshotManagesFile(m, rel))
|
|
417
419
|
removeSnapshotConfigFile(root, rel);
|
|
418
420
|
}
|
|
419
421
|
for (const [rel, content] of files) {
|
|
@@ -4,7 +4,7 @@ export { expectedRoleRank, ROLE_RANKS } from './role-ranks.js';
|
|
|
4
4
|
export const BUILTIN_USER_ROLES = ['member', 'visitor'];
|
|
5
5
|
export const MANAGEMENT_ROLES = ['owner', 'admin'];
|
|
6
6
|
export const DAEMON_OWNER_ROLE = 'daemon-owner';
|
|
7
|
-
export const
|
|
7
|
+
export const DEFAULT_INTERNAL_CONTACT_ROLE = 'member';
|
|
8
8
|
export function isManagementRole(role) {
|
|
9
9
|
return role === 'owner' || role === 'admin';
|
|
10
10
|
}
|
|
@@ -18,7 +18,7 @@ export function isReservedRoleName(role) {
|
|
|
18
18
|
export function getBuiltinRolesConfig() {
|
|
19
19
|
return {
|
|
20
20
|
$schema_version: 1,
|
|
21
|
-
defaultRoles: { private: null, group: null,
|
|
21
|
+
defaultRoles: { private: null, group: null, internalContact: DEFAULT_INTERNAL_CONTACT_ROLE },
|
|
22
22
|
roles: Object.fromEntries(BUILTIN_USER_ROLES.flatMap(roleId => {
|
|
23
23
|
const definition = readBuiltinRoleTemplate(roleId).definition;
|
|
24
24
|
return definition ? [[roleId, definition]] : [];
|
|
@@ -328,9 +328,9 @@ export function parseConfigFieldValue(fieldPath, rawValue) {
|
|
|
328
328
|
? { ok: true, value: raw }
|
|
329
329
|
: { ok: false, reason: 'Config field chatmode.group is fixed to proactive' };
|
|
330
330
|
}
|
|
331
|
-
return raw === 'interactive' || raw === 'proactive'
|
|
331
|
+
return raw === 'interactive' || raw === 'proactive'
|
|
332
332
|
? { ok: true, value: raw }
|
|
333
|
-
: { ok: false, reason: `Config field ${fieldPath} must be interactive
|
|
333
|
+
: { ok: false, reason: `Config field ${fieldPath} must be interactive or proactive` };
|
|
334
334
|
case 'mention-mode':
|
|
335
335
|
return raw === 'disabled' || raw === 'mention-only' || raw === 'auto'
|
|
336
336
|
? { ok: true, value: raw }
|
|
@@ -978,10 +978,6 @@ export function write(target, value, sel, opts = {}) {
|
|
|
978
978
|
// 1. Schema 校验
|
|
979
979
|
if (!opts.skipValidate) {
|
|
980
980
|
validateOrThrow(schema, normalized, target);
|
|
981
|
-
if (target === ConfigTarget.Relation && normalized.chatmode?.private === 'paactive'
|
|
982
|
-
&& (!sel?.peerKey?.startsWith('aun#') || normalized.targetKind !== 'private')) {
|
|
983
|
-
throw new ConfigError('SCHEMA_INVALID', 'paactive only supports AUN private relations');
|
|
984
|
-
}
|
|
985
981
|
if (target === ConfigTarget.Defaults || target === ConfigTarget.Agent || target === ConfigTarget.Relation) {
|
|
986
982
|
const previous = atomicReadJson(file) ?? {};
|
|
987
983
|
const inherited = target === ConfigTarget.Defaults ? {}
|
|
@@ -1480,7 +1476,7 @@ function configSkeleton(target, sel) {
|
|
|
1480
1476
|
}
|
|
1481
1477
|
const spec = props[key];
|
|
1482
1478
|
if (spec && 'default' in spec)
|
|
1483
|
-
skeleton[key] = spec.default;
|
|
1479
|
+
skeleton[key] = cloneConfigValue(spec.default);
|
|
1484
1480
|
else if (spec?.type === 'array')
|
|
1485
1481
|
skeleton[key] = [];
|
|
1486
1482
|
else if (spec?.type === 'object')
|
|
@@ -1558,9 +1554,6 @@ export function normalizeDefaultsBehaviorCompat(defaults) {
|
|
|
1558
1554
|
if (!normalized.chatmode && (chatMode === 'interactive' || chatMode === 'proactive')) {
|
|
1559
1555
|
normalized.chatmode = { private: chatMode, group: 'proactive', nothuman: chatMode };
|
|
1560
1556
|
}
|
|
1561
|
-
else if (!normalized.chatmode && chatMode === 'paactive') {
|
|
1562
|
-
normalized.chatmode = { private: 'paactive', group: 'proactive', nothuman: 'proactive' };
|
|
1563
|
-
}
|
|
1564
1557
|
if (normalized.mentionMode === undefined && (config.mentionMode === 'disabled' || config.mentionMode === 'mention-only' || config.mentionMode === 'auto')) {
|
|
1565
1558
|
normalized.mentionMode = config.mentionMode;
|
|
1566
1559
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ec invoke` 的 argv 解析与 daemon 侧执行。
|
|
3
|
+
*
|
|
4
|
+
* 鉴权与 `provider.op` 同一条链:本地控制令牌或任务委托令牌。
|
|
5
|
+
* 与 provider.op 的差别在于 invoke **不做配置变更**,也不受 fullaccess 限制——
|
|
6
|
+
* 调用一个已登记的端点不改变任何状态。
|
|
7
|
+
*/
|
|
8
|
+
import { executeInvoke } from '../core/invoke/invoke-service.js';
|
|
9
|
+
function argumentError(message) {
|
|
10
|
+
throw Object.assign(new Error(message), { code: 'INVALID_ARGUMENT' });
|
|
11
|
+
}
|
|
12
|
+
const SAFE_ID = /^[A-Za-z0-9_-]+$/u;
|
|
13
|
+
const PROHIBITED = new Set(['__proto__', 'constructor', 'prototype']);
|
|
14
|
+
/** 解析 `ec invoke` 的 argv(含首个 'invoke')。 */
|
|
15
|
+
export function parseInvokeArgv(argv) {
|
|
16
|
+
if (!Array.isArray(argv) || argv.some(value => typeof value !== 'string') || argv[0] !== 'invoke') {
|
|
17
|
+
argumentError('invoke.op requires invoke argv');
|
|
18
|
+
}
|
|
19
|
+
const options = new Map();
|
|
20
|
+
const flags = new Set();
|
|
21
|
+
const valueFlags = new Set(['--provider', '--service', '--model', '--out', '--timeout', '--timeout-ms', '--retries', '--input', '--input-file', '--format']);
|
|
22
|
+
const boolFlags = new Set(['--dry-run']);
|
|
23
|
+
for (let index = 1; index < argv.length; index++) {
|
|
24
|
+
const token = argv[index];
|
|
25
|
+
if (!token.startsWith('-'))
|
|
26
|
+
argumentError(`unexpected argument: ${token}`);
|
|
27
|
+
const separator = token.indexOf('=');
|
|
28
|
+
const name = separator < 0 ? token : token.slice(0, separator);
|
|
29
|
+
if (boolFlags.has(name)) {
|
|
30
|
+
if (separator >= 0)
|
|
31
|
+
argumentError(`${name} does not take a value`);
|
|
32
|
+
flags.add(name);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (!valueFlags.has(name))
|
|
36
|
+
argumentError(`unknown or duplicate option: ${name}`);
|
|
37
|
+
if (options.has(name))
|
|
38
|
+
argumentError(`unknown or duplicate option: ${name}`);
|
|
39
|
+
const value = separator < 0 ? argv[++index] : token.slice(separator + 1);
|
|
40
|
+
if (typeof value !== 'string' || !value || value.startsWith('--'))
|
|
41
|
+
argumentError(`${name} requires a value`);
|
|
42
|
+
options.set(name, value);
|
|
43
|
+
}
|
|
44
|
+
if (options.has('--format') && options.get('--format') !== 'json' && options.get('--format') !== 'text') {
|
|
45
|
+
argumentError('--format must be json or text');
|
|
46
|
+
}
|
|
47
|
+
const providerId = options.get('--provider');
|
|
48
|
+
const serviceType = options.get('--service');
|
|
49
|
+
if (!providerId)
|
|
50
|
+
argumentError('--provider is required');
|
|
51
|
+
if (!serviceType)
|
|
52
|
+
argumentError('--service is required');
|
|
53
|
+
if (!SAFE_ID.test(providerId) || PROHIBITED.has(providerId))
|
|
54
|
+
argumentError('invalid provider id');
|
|
55
|
+
if (!SAFE_ID.test(serviceType) || PROHIBITED.has(serviceType))
|
|
56
|
+
argumentError('invalid service type');
|
|
57
|
+
// 输入可以走 argv(--input / --input-file),也可以由 IPC 单独携带(cmd.input)。
|
|
58
|
+
// 这里只做结构校验,「恰好一种」由 executeInvokeOperation 结合 cmd.input 判定。
|
|
59
|
+
const hasInput = options.has('--input');
|
|
60
|
+
const hasInputFile = options.has('--input-file');
|
|
61
|
+
if (hasInput && hasInputFile)
|
|
62
|
+
argumentError('--input and --input-file are mutually exclusive');
|
|
63
|
+
const retriesRaw = options.get('--retries');
|
|
64
|
+
if (retriesRaw !== undefined && !/^\d+$/u.test(retriesRaw))
|
|
65
|
+
argumentError('--retries must be a non-negative integer');
|
|
66
|
+
// daemon 侧统一收毫秒:`--timeout-ms` 是 CLI 换算后的形态;`--timeout` 也按毫秒接受。
|
|
67
|
+
const timeoutRaw = options.get('--timeout-ms') ?? options.get('--timeout');
|
|
68
|
+
if (timeoutRaw !== undefined && !/^\d+$/u.test(timeoutRaw))
|
|
69
|
+
argumentError('timeout must be a positive integer (ms)');
|
|
70
|
+
return {
|
|
71
|
+
providerId,
|
|
72
|
+
serviceType,
|
|
73
|
+
model: options.get('--model'),
|
|
74
|
+
out: options.get('--out'),
|
|
75
|
+
timeoutMs: timeoutRaw === undefined ? undefined : Number(timeoutRaw),
|
|
76
|
+
retries: retriesRaw === undefined ? undefined : Number(retriesRaw),
|
|
77
|
+
dryRun: flags.has('--dry-run'),
|
|
78
|
+
input: hasInput ? options.get('--input') : undefined,
|
|
79
|
+
inputFile: hasInputFile ? options.get('--input-file') : undefined,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function parseInput(text) {
|
|
83
|
+
if (text === undefined)
|
|
84
|
+
return undefined;
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(text.replace(/^/u, ''));
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
argumentError('invoke input must be valid JSON');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Standalone IPC callers have already presented the local control token. */
|
|
93
|
+
export async function executeInvokeOperation(command) {
|
|
94
|
+
try {
|
|
95
|
+
const parsed = parseInvokeArgv(command.argv);
|
|
96
|
+
// CLI 已在本地读好 --input / --input-file,通过 cmd.input 传文本;
|
|
97
|
+
// 直接在 argv 里带 --input 的调用方也支持。
|
|
98
|
+
const inputText = command.input !== undefined ? String(command.input) : parsed.input;
|
|
99
|
+
if (inputText === undefined)
|
|
100
|
+
argumentError('exactly one of --input or --input-file is required');
|
|
101
|
+
const input = parseInput(inputText);
|
|
102
|
+
const request = {
|
|
103
|
+
providerId: parsed.providerId,
|
|
104
|
+
serviceType: parsed.serviceType,
|
|
105
|
+
model: parsed.model,
|
|
106
|
+
input,
|
|
107
|
+
outPath: parsed.out,
|
|
108
|
+
timeoutMs: parsed.timeoutMs,
|
|
109
|
+
retries: parsed.retries,
|
|
110
|
+
dryRun: parsed.dryRun,
|
|
111
|
+
};
|
|
112
|
+
return await executeInvoke(request);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
const failure = error;
|
|
116
|
+
return { ok: false, code: failure.code ?? 'INVALID_ARGUMENT', error: failure.message ?? 'Invoke failed' };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -120,7 +120,7 @@ export function resolvePeerRoleDetail(ctx) {
|
|
|
120
120
|
const store = readRoleStore(ctx.selfAid);
|
|
121
121
|
const valid = !store.diagnostics.some(diagnostic => diagnostic.code === 'INVALID_ROLE_REGISTRY'
|
|
122
122
|
|| diagnostic.code === 'MISSING_ROLE_REGISTRY');
|
|
123
|
-
const role = valid ? normalizeDefaultRole(store.registry.defaultRoles.
|
|
123
|
+
const role = valid ? normalizeDefaultRole(store.registry.defaultRoles.internalContact ?? 'member', ctx.selfAid) : null;
|
|
124
124
|
return resultFor(role, 'internal-contact-default', actor, ctx.selfAid);
|
|
125
125
|
}
|
|
126
126
|
if (ctx.chatType === 'private') {
|
|
@@ -2,12 +2,13 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { isDeepStrictEqual } from 'node:util';
|
|
4
4
|
import { providerIdentity } from './provider-identity.js';
|
|
5
|
-
import { providerEnvironmentVariable } from './providers-config.js';
|
|
5
|
+
import { initializationRuntimePlan, providerEnvironmentVariable } from './providers-config.js';
|
|
6
6
|
import { validateProvidersFile } from './providers-config.js';
|
|
7
|
-
export function planProviderIdentityMigration(home, registry) {
|
|
7
|
+
export function planProviderIdentityMigration(home, registry, options = {}) {
|
|
8
|
+
home = path.resolve(home);
|
|
8
9
|
const changes = [];
|
|
9
10
|
const expected = [];
|
|
10
|
-
const summary = { providersMigrated: 0, skippedProviders: 0, filesChanged: 0, referencesUpdated: 0 };
|
|
11
|
+
const summary = { providersMigrated: 0, skippedProviders: 0, filesChanged: 0, referencesUpdated: 0, aliasesRemoved: 0 };
|
|
11
12
|
const pending = [];
|
|
12
13
|
const providerFile = path.join(home, 'providers.json');
|
|
13
14
|
const readJson = (file) => {
|
|
@@ -79,6 +80,10 @@ export function planProviderIdentityMigration(home, registry) {
|
|
|
79
80
|
target.services = services;
|
|
80
81
|
};
|
|
81
82
|
for (const [oldId, provider] of Object.entries(source.providers).sort(([left], [right]) => left.localeCompare(right))) {
|
|
83
|
+
if (options.preserveProviderIds) {
|
|
84
|
+
providers[oldId] = provider;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
82
87
|
let identity;
|
|
83
88
|
try {
|
|
84
89
|
identity = providerIdentity(provider);
|
|
@@ -123,36 +128,56 @@ export function planProviderIdentityMigration(home, registry) {
|
|
|
123
128
|
if (Object.hasOwn(providers, alias))
|
|
124
129
|
throw new Error(`Provider ID conflicts with an old ID: ${alias} -> ${target}`);
|
|
125
130
|
}
|
|
126
|
-
const normalizedRegistry = validateProvidersFile({ $schema_version: 2, providers,
|
|
131
|
+
const normalizedRegistry = validateProvidersFile({ $schema_version: 2, providers,
|
|
132
|
+
...(!options.cleanupAliases && Object.keys(aliases).length ? { aliases } : {}) });
|
|
133
|
+
if (options.cleanupAliases)
|
|
134
|
+
summary.aliasesRemoved = Object.keys(aliases).length;
|
|
127
135
|
const queue = (file, before, value) => {
|
|
128
136
|
changes.push({ file, kind: 'provider-domain-id', before, after: JSON.stringify(value, null, 2) + String.fromCharCode(10) });
|
|
129
137
|
summary.filesChanged++;
|
|
130
138
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
139
|
+
const finish = () => {
|
|
140
|
+
if (!isDeepStrictEqual(original.value, normalizedRegistry))
|
|
141
|
+
queue(providerFile, original.text, normalizedRegistry);
|
|
134
142
|
return { home, changes, summary, pending, expected, registry: normalizedRegistry };
|
|
143
|
+
};
|
|
144
|
+
if (!Object.keys(aliases).length)
|
|
145
|
+
return finish();
|
|
135
146
|
const agentsDir = path.join(home, 'agents');
|
|
136
|
-
if (
|
|
137
|
-
return { home, changes, summary, pending, expected, registry: normalizedRegistry };
|
|
138
|
-
if (fs.lstatSync(agentsDir).isSymbolicLink())
|
|
147
|
+
if (fs.existsSync(agentsDir) && fs.lstatSync(agentsDir).isSymbolicLink())
|
|
139
148
|
throw new Error('Provider migration does not follow agent directory symlinks');
|
|
140
149
|
const files = [path.join(agentsDir, 'defaults.json')];
|
|
141
|
-
for (const agent of fs.readdirSync(agentsDir, { withFileTypes: true })) {
|
|
150
|
+
for (const agent of fs.existsSync(agentsDir) ? fs.readdirSync(agentsDir, { withFileTypes: true }) : []) {
|
|
151
|
+
if (agent.isSymbolicLink())
|
|
152
|
+
throw new Error('Provider migration does not follow agent directory symlinks');
|
|
142
153
|
if (!agent.isDirectory() || !/^[a-z0-9-]+(?:[.][a-z0-9-]+){2,}$/iu.test(agent.name))
|
|
143
154
|
continue;
|
|
144
155
|
const agentDir = path.join(agentsDir, agent.name);
|
|
145
156
|
files.push(path.join(agentDir, 'config.json'));
|
|
157
|
+
files.push(path.join(agentDir, 'data', 'initialization.json'));
|
|
146
158
|
const relations = path.join(agentDir, 'relations');
|
|
147
159
|
if (!fs.existsSync(relations))
|
|
148
160
|
continue;
|
|
149
161
|
if (fs.lstatSync(relations).isSymbolicLink())
|
|
150
162
|
throw new Error('Provider migration does not follow relation directory symlinks');
|
|
151
163
|
for (const relation of fs.readdirSync(relations, { withFileTypes: true })) {
|
|
164
|
+
if (relation.isSymbolicLink())
|
|
165
|
+
throw new Error('Provider migration does not follow relation directory symlinks');
|
|
152
166
|
if (relation.isDirectory())
|
|
153
167
|
files.push(path.join(relations, relation.name, 'config.json'));
|
|
154
168
|
}
|
|
155
169
|
}
|
|
170
|
+
const ecwebDir = path.join(home, 'data', 'ecweb');
|
|
171
|
+
files.push(path.join(ecwebDir, 'init-state.json'));
|
|
172
|
+
const creationsDir = path.join(ecwebDir, 'agent-creations');
|
|
173
|
+
if (fs.existsSync(creationsDir)) {
|
|
174
|
+
if (fs.lstatSync(creationsDir).isSymbolicLink())
|
|
175
|
+
throw new Error('Provider migration does not follow creation directory symlinks');
|
|
176
|
+
for (const entry of fs.readdirSync(creationsDir, { withFileTypes: true })) {
|
|
177
|
+
if (entry.name.endsWith('.json'))
|
|
178
|
+
files.push(path.join(creationsDir, entry.name));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
156
181
|
const rewriteSelection = (value) => {
|
|
157
182
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
158
183
|
return 0;
|
|
@@ -176,27 +201,77 @@ export function planProviderIdentityMigration(home, registry) {
|
|
|
176
201
|
return count;
|
|
177
202
|
};
|
|
178
203
|
const rewriteSelections = (value) => {
|
|
179
|
-
if (!value || typeof value !== 'object'
|
|
204
|
+
if (!value || typeof value !== 'object')
|
|
180
205
|
return 0;
|
|
181
|
-
let count =
|
|
206
|
+
let count = rewriteSelection(value);
|
|
182
207
|
for (const entry of Object.values(value)) {
|
|
183
|
-
count +=
|
|
208
|
+
count += rewriteSelections(entry);
|
|
184
209
|
}
|
|
185
210
|
return count;
|
|
186
211
|
};
|
|
187
212
|
for (const file of files) {
|
|
188
|
-
|
|
213
|
+
for (let parent = path.dirname(file); parent !== home; parent = path.dirname(parent)) {
|
|
214
|
+
if (fs.existsSync(parent) && fs.lstatSync(parent).isSymbolicLink())
|
|
215
|
+
throw new Error('Provider migration does not follow configuration symlinks');
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
if (fs.lstatSync(file).isSymbolicLink())
|
|
219
|
+
throw new Error('Provider migration does not follow configuration symlinks');
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
if (error.code !== 'ENOENT')
|
|
223
|
+
throw error;
|
|
224
|
+
expected.push({ file, before: null });
|
|
189
225
|
continue;
|
|
226
|
+
}
|
|
190
227
|
const parsed = readJson(file);
|
|
191
228
|
let count = 0;
|
|
192
229
|
count += rewriteSelections(parsed.value.baseagents);
|
|
193
230
|
count += rewriteSelections(parsed.value.agents);
|
|
194
231
|
count += rewriteSelections(parsed.value.Services);
|
|
195
|
-
count +=
|
|
232
|
+
count += rewriteSelections(parsed.value.decision_model);
|
|
233
|
+
if (path.basename(file) === 'initialization.json') {
|
|
234
|
+
const record = parsed.value;
|
|
235
|
+
if (!record.plan || typeof record.plan !== 'object' || Array.isArray(record.plan))
|
|
236
|
+
throw new Error('Invalid initialization plan during Provider migration');
|
|
237
|
+
const runtime = initializationRuntimePlan(record);
|
|
238
|
+
if (typeof runtime.provider === 'string' && Object.hasOwn(aliases, runtime.provider)) {
|
|
239
|
+
record.providerMigration = { from: record.plan.provider, to: aliases[runtime.provider] };
|
|
240
|
+
count++;
|
|
241
|
+
}
|
|
242
|
+
if (record.providerMigration && !Object.hasOwn(providers, record.providerMigration.to))
|
|
243
|
+
throw new Error('Initialization Provider migration target is missing');
|
|
244
|
+
}
|
|
245
|
+
else if (file.startsWith(ecwebDir + path.sep)) {
|
|
246
|
+
const creation = parsed.value.creation;
|
|
247
|
+
if (creation?.plan) {
|
|
248
|
+
const runtime = initializationRuntimePlan(creation);
|
|
249
|
+
if (runtime.provider && Object.hasOwn(aliases, runtime.provider)) {
|
|
250
|
+
creation.providerMigration = { from: creation.plan.provider, to: aliases[runtime.provider] };
|
|
251
|
+
count++;
|
|
252
|
+
}
|
|
253
|
+
if (creation.providerMigration && !Object.hasOwn(providers, creation.providerMigration.to))
|
|
254
|
+
throw new Error('Creation Provider migration target is missing');
|
|
255
|
+
}
|
|
256
|
+
const ids = parsed.value.providerIds;
|
|
257
|
+
if (ids && typeof ids === 'object' && !Array.isArray(ids)) {
|
|
258
|
+
for (const [key, value] of Object.entries(ids)) {
|
|
259
|
+
if (typeof value === 'string' && Object.hasOwn(aliases, value)) {
|
|
260
|
+
ids[key] = aliases[value];
|
|
261
|
+
count++;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
count += rewriteSelection(parsed.value.plan);
|
|
268
|
+
const creation = parsed.value.creation;
|
|
269
|
+
count += rewriteSelection(creation?.plan);
|
|
270
|
+
}
|
|
196
271
|
if (!count)
|
|
197
272
|
continue;
|
|
198
273
|
summary.referencesUpdated += count;
|
|
199
274
|
queue(file, parsed.text, parsed.value);
|
|
200
275
|
}
|
|
201
|
-
return
|
|
276
|
+
return finish();
|
|
202
277
|
}
|
|
@@ -127,6 +127,8 @@ export async function syncLocalProviders() {
|
|
|
127
127
|
}
|
|
128
128
|
plan.summary.filesChanged = plan.changes.length;
|
|
129
129
|
const backup = commitProviderSyncMigration(plan);
|
|
130
|
+
if (plan.changes.length && !backup)
|
|
131
|
+
warnings.push('CONFIG_SNAPSHOTS_DISABLED');
|
|
130
132
|
for (const change of plan.changes) {
|
|
131
133
|
const parts = path.relative(home, change.file).split(path.sep);
|
|
132
134
|
if (parts[0] === 'providers.json')
|
|
@@ -347,6 +347,19 @@ export function resolveProviderModelOverrides(providerId, serviceType, config, b
|
|
|
347
347
|
export function providerIsConfigured(config) {
|
|
348
348
|
return config?.provider !== undefined;
|
|
349
349
|
}
|
|
350
|
+
export function initializationRuntimePlan(record) {
|
|
351
|
+
const migration = record.providerMigration;
|
|
352
|
+
if (migration === undefined)
|
|
353
|
+
return record.plan;
|
|
354
|
+
if (!migration || typeof migration !== 'object' || Array.isArray(migration))
|
|
355
|
+
throw new Error('Invalid initialization Provider migration binding');
|
|
356
|
+
if (typeof migration.from !== 'string' || migration.from !== record.plan.provider || typeof migration.to !== 'string'
|
|
357
|
+
|| !/^[A-Za-z0-9_-]+$/u.test(migration.to)
|
|
358
|
+
|| ['__proto__', 'constructor', 'prototype'].includes(migration.to)) {
|
|
359
|
+
throw new Error('Invalid initialization Provider migration binding');
|
|
360
|
+
}
|
|
361
|
+
return { ...record.plan, provider: migration.to };
|
|
362
|
+
}
|
|
350
363
|
export function resolveServiceSelection(selections, serviceType, resolve) {
|
|
351
364
|
const selection = selections?.[serviceType];
|
|
352
365
|
if (!selection)
|