evolcore 0.0.43-test.4 → 0.0.43-test.6
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 +93 -0
- package/bin/ecmsg.js +437 -91
- package/dist/agents/baseagent-availability.js +19 -4
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +14 -3
- package/dist/agents/codex-runner.js +18 -23
- package/dist/aun/aid/agentmd.js +25 -0
- package/dist/aun/aid/control-aid.js +15 -0
- package/dist/aun/aid/identity.js +8 -0
- package/dist/aun/aid/ownership-operation.js +12 -3
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +99 -23
- package/dist/channels/daemon.js +2 -2
- package/dist/cli/agent-create.js +19 -7
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +19 -4
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +42 -4
- package/dist/cli/directory.js +3 -1
- package/dist/cli/ecmsg-gateway.js +206 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +120 -13
- package/dist/cli/provider-command.js +82 -5
- package/dist/cli/restart-monitor.js +35 -24
- package/dist/cli/stats.js +8 -1
- package/dist/cli/task-context.js +41 -1
- package/dist/cli/watch-logs.js +6 -4
- package/dist/config/boot-log.js +16 -3
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-manager.js +5 -14
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +6 -6
- package/dist/config/provider-identity-migration.js +277 -0
- package/dist/config/provider-identity.js +37 -0
- package/dist/config/provider-ipc-service.js +40 -3
- package/dist/config/provider-local-sync.js +155 -0
- package/dist/config/providers-config.js +45 -4
- package/dist/config/providers-management.js +242 -76
- package/dist/config/providers.js +4 -1
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +143 -86
- package/dist/config/snapshot.js +70 -41
- package/dist/core/agent-runtime.js +48 -9
- package/dist/core/auth/auth-gateway.js +5 -3
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +3 -1
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/baseagent-loader.js +114 -11
- package/dist/core/channel-loader.js +36 -13
- package/dist/core/channel-runtime.js +112 -42
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +16 -11
- package/dist/core/command/menu-handler.js +8 -3
- package/dist/core/command/menu-protocol.js +80 -7
- package/dist/core/command/provider-menu.js +4 -2
- package/dist/core/command/role-menu.js +29 -17
- package/dist/core/command/slash-handler.js +52 -16
- package/dist/core/daemon-control.js +42 -15
- package/dist/core/daemon-lifecycle.js +411 -67
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +139 -45
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +7 -6
- package/dist/core/ipc-registration.js +5 -4
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/message/aun-ipc-sender.js +83 -5
- package/dist/core/message/message-admission.js +2 -0
- package/dist/core/message/message-bridge.js +53 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +33 -25
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +320 -0
- package/dist/core/ownership/owner-resolver.js +112 -8
- package/dist/core/permission/ec-command-parser.js +159 -16
- package/dist/core/permission/readonly-shell-query.js +66 -7
- package/dist/core/permission/tool-error-code.js +13 -1
- package/dist/core/permission/tool-policy.js +74 -20
- package/dist/core/relation/same-owner-proof.js +131 -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-fs-store.js +164 -3
- package/dist/core/session/session-idle-monitor.js +103 -17
- package/dist/core/session/session-manager.js +105 -18
- package/dist/core/thread/thread-route.js +5 -2
- package/dist/directory/owner-directory-admission.js +26 -1
- package/dist/directory/owner-directory-cache.js +739 -109
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +6 -3
- package/dist/directory/owner-directory-scope.js +12 -0
- package/dist/directory/owner-directory-search.js +5 -1
- package/dist/directory/owner-directory-store.js +28 -0
- package/dist/ecweb/basic-settings-service.js +15 -1
- package/dist/ecweb/message-context-service.js +2 -2
- package/dist/ecweb/providers-service.js +3 -1
- package/dist/ecweb/runtime/lifecycle.js +26 -15
- package/dist/ecweb/runtime/supervisor.js +120 -51
- package/dist/index.js +551 -250
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +40 -17
- package/dist/proxy/service-supervisor.js +67 -33
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +4 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +81 -8
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +188 -12
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +64 -1
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/startup-trace.js +160 -19
- package/dist/utils/windows-autostart.js +41 -7
- package/ecagent/dist/harness/env/nodejs.js +46 -2
- package/kits/docs/aun/ABILITY_CALLING.md +6 -6
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/channels/feishu.md +2 -2
- package/kits/docs/context-assembly.md +20 -4
- package/kits/docs/evolcore/INDEX.md +5 -3
- package/kits/docs/evolcore/agent.md +2 -2
- package/kits/docs/evolcore/aid.md +8 -2
- package/kits/docs/evolcore/ctl.md +15 -5
- package/kits/docs/evolcore/directory.md +48 -15
- package/kits/docs/evolcore/group.md +8 -8
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +32 -3
- package/kits/docs/evolcore/msg.md +38 -30
- package/kits/docs/evolcore/provider.md +57 -5
- package/kits/docs/evolcore/response.md +2 -2
- package/kits/docs/evolcore/thread-chain.md +11 -13
- package/kits/docs/evolcore/tool-authorization.md +17 -0
- package/kits/docs/evolcore/trigger.md +2 -2
- package/kits/docs/identity/ROLE_DETAIL.md +1 -1
- package/kits/docs/prompt-loading-architecture.md +30 -20
- package/kits/eck_manifest.auxiliary.json +5 -5
- package/kits/eck_manifest.json +44 -32
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/01-overview.md +1 -1
- package/kits/rules/06-channel.md +7 -8
- package/kits/schemas/_meta.json +7 -1
- 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/providers.schema.2.json +74 -0
- 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/aid-ability/SKILL.md +7 -7
- package/kits/skills/ec-agent-create/SKILL.md +1 -0
- 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 +3 -10
- package/kits/skills/ec-trigger/SKILL.md +9 -9
- package/kits/skills/ec-trigger/references/examples.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +5 -5
- package/kits/templates/system-fragments/commands.md +7 -6
- package/kits/templates/system-fragments/directory-contacts.md +10 -3
- package/kits/templates/system-fragments/personal-assistant.md +22 -3
- package/kits/templates/system-fragments/reply.md +48 -28
- package/kits/templates/system-fragments/session.md +3 -10
- package/kits/templates/system-fragments/thread.md +5 -5
- package/package.json +4 -4
|
@@ -5,7 +5,7 @@ import { agentRelationConfig, agentRelationsDir, agentRoleConfig, agentRolesInde
|
|
|
5
5
|
import { registerFile, unregisterFile } from '../core/file-integrity/store.js';
|
|
6
6
|
import { currentVersion, loadSchema } from './schema-registry.js';
|
|
7
7
|
import { clearRoleStoreCache, getStoredRoleRegistry, isRoleName, readRoleStore, roleRegistryExists, } from './role-store.js';
|
|
8
|
-
import {
|
|
8
|
+
import { DEFAULT_INTERNAL_CONTACT_ROLE, expectedRoleRank, isManagementRole } from './builtin-roles.js';
|
|
9
9
|
import { readBuiltinRoleTemplate } from './builtin-role-templates.js';
|
|
10
10
|
import { normalizeRoleEffortCompat, validateRoleConfig } from './role-schema.js';
|
|
11
11
|
export class RoleServiceError extends Error {
|
|
@@ -30,7 +30,7 @@ export function ensureInitialRoleRegistry(selfAid) {
|
|
|
30
30
|
writeRoleRegistry(selfAid, {
|
|
31
31
|
$schema_version: 1,
|
|
32
32
|
roles: ['owner', 'admin', 'member', 'visitor'],
|
|
33
|
-
defaultRoles: { private: null, group: null,
|
|
33
|
+
defaultRoles: { private: null, group: null, internalContact: DEFAULT_INTERNAL_CONTACT_ROLE },
|
|
34
34
|
});
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
@@ -125,8 +125,8 @@ export function unregisterRole(selfAid, roleId, replacementRoleId) {
|
|
|
125
125
|
defaultRoles: {
|
|
126
126
|
private: registry.defaultRoles.private === roleId ? (replacement ?? null) : registry.defaultRoles.private,
|
|
127
127
|
group: registry.defaultRoles.group === roleId ? (replacement ?? null) : registry.defaultRoles.group,
|
|
128
|
-
|
|
129
|
-
? (replacement ??
|
|
128
|
+
internalContact: (registry.defaultRoles.internalContact ?? DEFAULT_INTERNAL_CONTACT_ROLE) === roleId
|
|
129
|
+
? (replacement ?? DEFAULT_INTERNAL_CONTACT_ROLE) : registry.defaultRoles.internalContact,
|
|
130
130
|
},
|
|
131
131
|
};
|
|
132
132
|
validateRegistry(selfAid, nextRegistry);
|
|
@@ -174,8 +174,8 @@ function validateRegistry(selfAid, value) {
|
|
|
174
174
|
const registry = normalized;
|
|
175
175
|
if (!registry.roles.includes('visitor'))
|
|
176
176
|
throw new RoleServiceError('VISITOR_REQUIRED', 'visitor must remain registered');
|
|
177
|
-
for (const role of ['private', 'group', '
|
|
178
|
-
const selected = role === '
|
|
177
|
+
for (const role of ['private', 'group', 'internalContact']) {
|
|
178
|
+
const selected = role === 'internalContact' ? registry.defaultRoles.internalContact ?? DEFAULT_INTERNAL_CONTACT_ROLE : registry.defaultRoles[role];
|
|
179
179
|
if (selected !== null && (selected === 'owner' || !registry.roles.includes(selected))) {
|
|
180
180
|
throw new RoleServiceError('INVALID_DEFAULT_ROLE', `defaultRoles.${role} must reference an assignable registered role`);
|
|
181
181
|
}
|
|
@@ -206,8 +206,8 @@ function findRoleReferences(selfAid, roleId, registry) {
|
|
|
206
206
|
references.push('defaultRoles.private');
|
|
207
207
|
if (registry.defaultRoles.group === roleId)
|
|
208
208
|
references.push('defaultRoles.group');
|
|
209
|
-
if ((registry.defaultRoles.
|
|
210
|
-
references.push('defaultRoles.
|
|
209
|
+
if ((registry.defaultRoles.internalContact ?? DEFAULT_INTERNAL_CONTACT_ROLE) === roleId)
|
|
210
|
+
references.push('defaultRoles.internalContact');
|
|
211
211
|
const relations = agentRelationsDir(selfAid);
|
|
212
212
|
if (!fs.existsSync(relations))
|
|
213
213
|
return references;
|
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { atomicReadJson } from '../utils/atomic-write.js';
|
|
4
4
|
import { agentRoleConfig, agentRolesDir, agentRolesIndex, kitsRoleTemplatesDir, resolvePaths, } from '../paths.js';
|
|
5
|
-
import { applyManagementRoleCeiling,
|
|
5
|
+
import { applyManagementRoleCeiling, DEFAULT_INTERNAL_CONTACT_ROLE, expectedRoleRank, getManagementRoleDefinition } from './builtin-roles.js';
|
|
6
6
|
import { readBuiltinRoleTemplate } from './builtin-role-templates.js';
|
|
7
7
|
import { loadSchema } from './schema-registry.js';
|
|
8
8
|
import { normalizeRoleEffortCompat, normalizeRoleGroupChatmodeCompat, validateRoleConfig } from './role-schema.js';
|
|
@@ -88,7 +88,6 @@ export function roleIsAssignable(selfAid, roleId) {
|
|
|
88
88
|
function readRegistry(selfAid, diagnostics) {
|
|
89
89
|
const file = agentRolesIndex(selfAid);
|
|
90
90
|
let raw;
|
|
91
|
-
let invalidPaTeam = false;
|
|
92
91
|
try {
|
|
93
92
|
raw = atomicReadJson(file);
|
|
94
93
|
}
|
|
@@ -102,30 +101,29 @@ function readRegistry(selfAid, diagnostics) {
|
|
|
102
101
|
}
|
|
103
102
|
if (raw !== null) {
|
|
104
103
|
const schema = loadSchema('role-registry');
|
|
104
|
+
// 旧键名迁移:`paTeam` → `internalContact`。schema 已不再接受旧键
|
|
105
|
+
// (additionalProperties:false),所以必须在校验前改名,否则一份存量
|
|
106
|
+
// 注册表会被判成整份非法、连带丢掉 roles 列表。
|
|
105
107
|
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
106
108
|
const record = raw;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
if (Object.hasOwn(
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
invalidPaTeam = true;
|
|
118
|
-
}
|
|
109
|
+
const defaults = record.defaultRoles;
|
|
110
|
+
if (defaults && typeof defaults === 'object' && !Array.isArray(defaults)) {
|
|
111
|
+
const legacy = defaults;
|
|
112
|
+
if (Object.hasOwn(legacy, 'paTeam')) {
|
|
113
|
+
const migrated = { ...legacy };
|
|
114
|
+
const carried = migrated.paTeam;
|
|
115
|
+
delete migrated.paTeam;
|
|
116
|
+
if (!Object.hasOwn(migrated, 'internalContact'))
|
|
117
|
+
migrated.internalContact = carried;
|
|
118
|
+
raw = { ...record, defaultRoles: migrated };
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
if (schema.validate(raw)) {
|
|
123
123
|
const value = raw;
|
|
124
124
|
const roles = [...new Set(value.roles)];
|
|
125
|
-
const defaultRoles = { ...value.defaultRoles,
|
|
126
|
-
for (const scene of ['private', 'group', '
|
|
127
|
-
if (scene === 'paTeam' && invalidPaTeam)
|
|
128
|
-
continue;
|
|
125
|
+
const defaultRoles = { ...value.defaultRoles, internalContact: value.defaultRoles.internalContact ?? DEFAULT_INTERNAL_CONTACT_ROLE };
|
|
126
|
+
for (const scene of ['private', 'group', 'internalContact']) {
|
|
129
127
|
const selected = defaultRoles[scene];
|
|
130
128
|
if (selected === null || (roles.includes(selected) && selected !== 'owner'))
|
|
131
129
|
continue;
|
|
@@ -133,11 +131,13 @@ function readRegistry(selfAid, diagnostics) {
|
|
|
133
131
|
code: 'INVALID_ROLE_ASSIGNMENT',
|
|
134
132
|
roleId: selected,
|
|
135
133
|
file: path.relative(resolvePaths().root, file),
|
|
136
|
-
message: `defaultRoles.${scene} references invalid or unregistered role ${selected}; ${scene === '
|
|
137
|
-
? '
|
|
134
|
+
message: `defaultRoles.${scene} references invalid or unregistered role ${selected}; ${scene === 'internalContact'
|
|
135
|
+
? 'internal-contact default role is disabled' : `using ${scene === 'group' ? 'member' : 'visitor'} fallback`}`,
|
|
138
136
|
});
|
|
139
|
-
if (scene !== '
|
|
137
|
+
if (scene !== 'internalContact')
|
|
140
138
|
defaultRoles[scene] = null;
|
|
139
|
+
else
|
|
140
|
+
defaultRoles[scene] = '';
|
|
141
141
|
}
|
|
142
142
|
return { ...value, roles, defaultRoles };
|
|
143
143
|
}
|
|
@@ -156,7 +156,7 @@ function readRegistry(selfAid, diagnostics) {
|
|
|
156
156
|
return fallbackRegistry();
|
|
157
157
|
}
|
|
158
158
|
function fallbackRegistry() {
|
|
159
|
-
return { $schema_version: 1, roles: [...BUILTIN_ROLES], defaultRoles: { private: null, group: null,
|
|
159
|
+
return { $schema_version: 1, roles: [...BUILTIN_ROLES], defaultRoles: { private: null, group: null, internalContact: DEFAULT_INTERNAL_CONTACT_ROLE } };
|
|
160
160
|
}
|
|
161
161
|
function readDefinition(selfAid, roleId, diagnostics) {
|
|
162
162
|
const local = agentRoleConfig(selfAid, roleId);
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
3
|
import fs from 'fs';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import { resolvePaths } from '../paths.js';
|
|
5
|
-
import { ConfigError } from './config-manager.js';
|
|
6
|
+
import { acquireConfigMutationLock, ConfigError } from './config-manager.js';
|
|
6
7
|
import { firstConfiguredOwner } from './owner-config.js';
|
|
7
|
-
import { resolveLegacyBaseagentModelSelection } from '../agents/baseagent.js';
|
|
8
8
|
import { loadSchema } from './schema-registry.js';
|
|
9
|
+
import { planProviderIdentityMigration } from './provider-identity-migration.js';
|
|
10
|
+
import { providerIdentity } from './provider-identity.js';
|
|
11
|
+
import { snapshot } from './snapshot.js';
|
|
9
12
|
const MIGRATION_KIND = {
|
|
10
13
|
'auxiliary-model-v1': 'auxiliary-model',
|
|
11
14
|
'agent-only-model-v1': 'agent-only-model',
|
|
12
15
|
'agent-model-provider-v1': 'agent-only-model',
|
|
13
16
|
'provider-service-type-v1': 'provider-service-type',
|
|
17
|
+
'provider-domain-id-v1': 'provider-domain-id',
|
|
14
18
|
'relation-config-v11-v1': 'agent-only-model',
|
|
15
19
|
'published-schema-consolidation-v1': 'agent-only-model',
|
|
16
20
|
'legacy-model-selection-v1': 'agent-only-model',
|
|
@@ -597,25 +601,30 @@ function recoverJournal(home, id) {
|
|
|
597
601
|
function applyMigration(plan, id) {
|
|
598
602
|
if (plan.changes.length === 0)
|
|
599
603
|
return null;
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
604
|
+
let backup;
|
|
605
|
+
if (id === 'provider-domain-id-v1') {
|
|
606
|
+
const result = snapshot('schema-migration', { root: plan.home, description: 'before Provider identity migration',
|
|
607
|
+
expectedFiles: new Map(plan.changes.map(item => [path.relative(plan.home, item.file).split(path.sep).join('/'), item.before])) });
|
|
608
|
+
backup = result.version ?? null;
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
612
|
+
backup = path.join(plan.home, 'backups', `${id}-migration`, stamp);
|
|
613
|
+
fs.mkdirSync(path.join(backup, 'files'), { recursive: true });
|
|
614
|
+
for (const item of plan.changes) {
|
|
615
|
+
if (item.before === null)
|
|
616
|
+
continue;
|
|
617
|
+
const destination = path.join(backup, 'files', path.relative(plan.home, item.file));
|
|
618
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
619
|
+
fs.writeFileSync(destination, item.before);
|
|
620
|
+
}
|
|
621
|
+
fs.writeFileSync(path.join(backup, 'manifest.json'), jsonText({
|
|
622
|
+
schemaVersion: 1,
|
|
623
|
+
createdAt: new Date().toISOString(),
|
|
624
|
+
summary: plan.summary,
|
|
625
|
+
files: plan.changes.map(item => ({ path: path.relative(plan.home, item.file), kind: item.kind })),
|
|
626
|
+
}));
|
|
609
627
|
}
|
|
610
|
-
fs.writeFileSync(path.join(backup, 'manifest.json'), jsonText({
|
|
611
|
-
schemaVersion: 1,
|
|
612
|
-
createdAt: new Date().toISOString(),
|
|
613
|
-
summary: plan.summary,
|
|
614
|
-
files: plan.changes.map(item => ({
|
|
615
|
-
path: path.relative(plan.home, item.file),
|
|
616
|
-
kind: item.kind,
|
|
617
|
-
})),
|
|
618
|
-
}));
|
|
619
628
|
writeJournal(plan, 'prepared', id);
|
|
620
629
|
try {
|
|
621
630
|
for (const item of plan.changes)
|
|
@@ -671,7 +680,7 @@ export async function ensureAuxiliaryModelMigrationOnStartup() {
|
|
|
671
680
|
throw new ConfigError('AUXILIARY_MODEL_MIGRATION_FAILED', `Automatic Session Renew auxiliary-model schema migration failed: ${detail}`, { cause: error });
|
|
672
681
|
}
|
|
673
682
|
}
|
|
674
|
-
// ── Preserve
|
|
683
|
+
// ── Preserve explicit Owner selections once, before removing legacy relation settings. ──
|
|
675
684
|
export function runLegacyModelSelectionMigration(options = {}) {
|
|
676
685
|
const home = path.resolve(options.home || resolvePaths().root);
|
|
677
686
|
const id = 'legacy-model-selection-v1';
|
|
@@ -694,7 +703,6 @@ export function runLegacyModelSelectionMigration(options = {}) {
|
|
|
694
703
|
const defaults = fs.existsSync(defaultsFile) ? readJson(defaultsFile).value : {};
|
|
695
704
|
if (!isRecord(defaults))
|
|
696
705
|
throw new Error(`${defaultsFile}: defaults configuration must be an object`);
|
|
697
|
-
const inheritedBlocks = baseagentSource(defaults) ?? {};
|
|
698
706
|
const entries = fs.existsSync(agentsRoot) ? fs.readdirSync(agentsRoot, { withFileTypes: true }) : [];
|
|
699
707
|
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
700
708
|
if (!entry.isDirectory() || !validAid(entry.name))
|
|
@@ -731,7 +739,6 @@ export function runLegacyModelSelectionMigration(options = {}) {
|
|
|
731
739
|
let nextBlocks = { ...blocks };
|
|
732
740
|
for (const backend of backends) {
|
|
733
741
|
const block = isRecord(blocks[backend]) ? blocks[backend] : {};
|
|
734
|
-
const inherited = isRecord(inheritedBlocks[backend]) ? inheritedBlocks[backend] : {};
|
|
735
742
|
const ownerSelection = ownerSelections.get(backend);
|
|
736
743
|
const nextBlock = { ...block };
|
|
737
744
|
const migrated = { aid: entry.name, baseagent: backend };
|
|
@@ -747,24 +754,6 @@ export function runLegacyModelSelectionMigration(options = {}) {
|
|
|
747
754
|
migrated.effort = ownerSelection.effort;
|
|
748
755
|
migrated.effortSource = 'owner-relation';
|
|
749
756
|
}
|
|
750
|
-
// Preserve the runner's historical selection when no Agent/defaults
|
|
751
|
-
// model exists and the Owner relation did not provide one. This is a
|
|
752
|
-
// one-time compatibility fallback; other relation values are ignored.
|
|
753
|
-
const hasAgentModel = typeof block.model === 'string' && block.model.trim().length > 0;
|
|
754
|
-
const hasDefaultModel = typeof inherited.model === 'string' && inherited.model.trim().length > 0;
|
|
755
|
-
if (backend === baseagent && !hasAgentModel && !hasDefaultModel && ownerSelection?.model === undefined) {
|
|
756
|
-
const legacy = resolveLegacyBaseagentModelSelection(backend);
|
|
757
|
-
if (legacy) {
|
|
758
|
-
nextBlock.model = legacy.model;
|
|
759
|
-
migrated.model = legacy.model;
|
|
760
|
-
migrated.modelSource = legacy.source;
|
|
761
|
-
if (!block.effort && ownerSelection?.effort === undefined && legacy.effort) {
|
|
762
|
-
nextBlock.effort = legacy.effort;
|
|
763
|
-
migrated.effort = legacy.effort;
|
|
764
|
-
migrated.effortSource = legacy.source;
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
757
|
if (Object.keys(migrated).length > 2) {
|
|
769
758
|
nextBlocks = { ...nextBlocks, [backend]: nextBlock };
|
|
770
759
|
selections.push(migrated);
|
|
@@ -902,7 +891,6 @@ function planAgentOnlyModelMigration(home) {
|
|
|
902
891
|
: fs.existsSync(defaultsFile) ? readJson(defaultsFile).value : {};
|
|
903
892
|
if (!isRecord(defaultsRaw))
|
|
904
893
|
throw new Error(`${defaultsFile}: defaults configuration must be an object`);
|
|
905
|
-
const inheritedBlocks = baseagentSource(defaultsRaw) ?? {};
|
|
906
894
|
const agentEntries = fs.readdirSync(agentsRoot, { withFileTypes: true })
|
|
907
895
|
.sort((left, right) => left.name.localeCompare(right.name));
|
|
908
896
|
for (const entry of agentEntries) {
|
|
@@ -932,7 +920,6 @@ function planAgentOnlyModelMigration(home) {
|
|
|
932
920
|
const migrated = [];
|
|
933
921
|
for (const backend of backends) {
|
|
934
922
|
const block = isRecord(sourceBlocks[backend]) ? sourceBlocks[backend] : {};
|
|
935
|
-
const inherited = isRecord(inheritedBlocks[backend]) ? inheritedBlocks[backend] : {};
|
|
936
923
|
const owner = ownerSelections.get(backend);
|
|
937
924
|
const next = { ...block };
|
|
938
925
|
if (owner?.model !== undefined && owner.model !== block.model) {
|
|
@@ -945,20 +932,6 @@ function planAgentOnlyModelMigration(home) {
|
|
|
945
932
|
migrated.push(`baseagents.${backend}.effort from owner relation`);
|
|
946
933
|
summary.ownerEffortsPromoted += 1;
|
|
947
934
|
}
|
|
948
|
-
const hasAgentModel = typeof block.model === 'string' && block.model.trim().length > 0;
|
|
949
|
-
const hasDefaultModel = typeof inherited.model === 'string' && inherited.model.trim().length > 0;
|
|
950
|
-
if (backend === selected && !hasAgentModel && !hasDefaultModel && owner?.model === undefined) {
|
|
951
|
-
const legacy = resolveLegacyBaseagentModelSelection(backend);
|
|
952
|
-
if (legacy) {
|
|
953
|
-
next.model = legacy.model;
|
|
954
|
-
migrated.push(`baseagents.${backend}.model from ${legacy.source}`);
|
|
955
|
-
summary.legacyModelsRestored += 1;
|
|
956
|
-
if (!block.effort && owner?.effort === undefined && legacy.effort) {
|
|
957
|
-
next.effort = legacy.effort;
|
|
958
|
-
migrated.push(`baseagents.${backend}.effort from ${legacy.source}`);
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
935
|
if (Object.keys(next).length > 0)
|
|
963
936
|
nextBlocks[backend] = next;
|
|
964
937
|
}
|
|
@@ -1054,37 +1027,32 @@ const BASEAGENT_SERVICE_TYPES = {
|
|
|
1054
1027
|
gemini: 'gemini',
|
|
1055
1028
|
ecagent: 'text',
|
|
1056
1029
|
};
|
|
1057
|
-
/**
|
|
1058
|
-
* providers.json 中已存在同 baseUrl 且同凭证的服务时复用该条目,避免重复登记。
|
|
1059
|
-
* 端点相同但凭证不同必须单独建条目:否则显式 apiKey 会在迁移中丢失。
|
|
1060
|
-
*/
|
|
1061
1030
|
function findProviderForConnection(providers, connection) {
|
|
1062
1031
|
for (const [providerId, provider] of Object.entries(providers)) {
|
|
1063
1032
|
if (!isRecord(provider) || !isRecord(provider.common))
|
|
1064
1033
|
continue;
|
|
1065
1034
|
const baseUrl = typeof provider.common.baseUrl === 'string' ? provider.common.baseUrl.trim() : '';
|
|
1066
|
-
|
|
1035
|
+
try {
|
|
1036
|
+
if (providerIdentity(provider).domain
|
|
1037
|
+
!== providerIdentity({ common: { baseUrl: connection.baseUrl } }).domain)
|
|
1038
|
+
continue;
|
|
1039
|
+
if (new URL(baseUrl).origin !== new URL(connection.baseUrl).origin)
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
catch {
|
|
1067
1043
|
continue;
|
|
1044
|
+
}
|
|
1068
1045
|
const existingKey = typeof provider.common.apiKey === 'string' ? provider.common.apiKey.trim() : '';
|
|
1069
1046
|
if (connection.apiKey && existingKey !== connection.apiKey)
|
|
1070
1047
|
continue;
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1048
|
+
if (connection.headers && !isDeepStrictEqual(provider.common.headers, connection.headers))
|
|
1049
|
+
continue;
|
|
1050
|
+
if (connection.queryParams && !isDeepStrictEqual(provider.common.queryParams, connection.queryParams))
|
|
1051
|
+
continue;
|
|
1052
|
+
return providerId;
|
|
1074
1053
|
}
|
|
1075
1054
|
return undefined;
|
|
1076
1055
|
}
|
|
1077
|
-
function createProviderId(providers) {
|
|
1078
|
-
let sequence = 1;
|
|
1079
|
-
for (const providerId of Object.keys(providers)) {
|
|
1080
|
-
const match = /^provider-(\d+)$/u.exec(providerId);
|
|
1081
|
-
if (match)
|
|
1082
|
-
sequence = Math.max(sequence, Number(match[1]) + 1);
|
|
1083
|
-
}
|
|
1084
|
-
while (hasOwn(providers, `provider-${sequence}`))
|
|
1085
|
-
sequence += 1;
|
|
1086
|
-
return `provider-${sequence}`;
|
|
1087
|
-
}
|
|
1088
1056
|
/** 旧写法 $ENV:NAME 统一成 providers 认识的整体引用 ${NAME};明文原样保留。 */
|
|
1089
1057
|
function normalizeProviderSecret(value) {
|
|
1090
1058
|
if (typeof value !== 'string')
|
|
@@ -1146,15 +1114,42 @@ function connectionFromDecisionModel(block) {
|
|
|
1146
1114
|
path: servicePath,
|
|
1147
1115
|
};
|
|
1148
1116
|
}
|
|
1149
|
-
function registerConnection(providers, connection, servicePath, summary) {
|
|
1117
|
+
function registerConnection(providers, connection, servicePath, summary, aliases) {
|
|
1150
1118
|
const existing = findProviderForConnection(providers, connection);
|
|
1151
|
-
const
|
|
1119
|
+
const identity = providerIdentity({ common: { baseUrl: connection.baseUrl } });
|
|
1120
|
+
const providerId = existing ?? identity.providerId;
|
|
1121
|
+
if (!existing) {
|
|
1122
|
+
if (hasOwn(aliases, providerId))
|
|
1123
|
+
throw Object.assign(new Error('Provider ID is reserved by a legacy alias'), { code: 'PROVIDER_ID_COLLISION' });
|
|
1124
|
+
for (const [candidateId, candidate] of Object.entries(providers)) {
|
|
1125
|
+
let domain;
|
|
1126
|
+
try {
|
|
1127
|
+
domain = providerIdentity(candidate).domain;
|
|
1128
|
+
}
|
|
1129
|
+
catch { }
|
|
1130
|
+
if (candidateId === providerId || domain === identity.domain) {
|
|
1131
|
+
throw Object.assign(new Error('Legacy Provider connection conflicts with an existing domain; reconcile before migration'), {
|
|
1132
|
+
code: candidateId === providerId && domain !== identity.domain ? 'PROVIDER_ID_COLLISION' : 'PROVIDER_CONFLICT',
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1152
1137
|
const current = existing && isRecord(providers[existing]) ? providers[existing] : undefined;
|
|
1153
1138
|
const common = current && isRecord(current.common) ? { ...current.common } : {};
|
|
1154
1139
|
const services = current && isRecord(current.services) ? { ...current.services } : {};
|
|
1140
|
+
const baseUrl = typeof common.baseUrl === 'string' ? common.baseUrl : connection.baseUrl;
|
|
1141
|
+
const endpoint = new URL(servicePath || '.', connection.baseUrl.endsWith('/') ? connection.baseUrl : `${connection.baseUrl}/`);
|
|
1142
|
+
const existingService = services[connection.serviceType];
|
|
1143
|
+
if (isRecord(existingService)) {
|
|
1144
|
+
const existingEndpoint = new URL(typeof existingService.path === 'string' && existingService.path ? existingService.path : '.', baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`);
|
|
1145
|
+
if (existingEndpoint.href.replace(/\/+$/u, '') !== endpoint.href.replace(/\/+$/u, '')) {
|
|
1146
|
+
throw Object.assign(new Error('Legacy Provider service endpoint conflicts; reconcile before migration'), { code: 'PROVIDER_CONFLICT' });
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
const targetPath = baseUrl === connection.baseUrl ? servicePath : `${endpoint.pathname}${endpoint.search}${endpoint.hash}`;
|
|
1155
1150
|
const nextCommon = {
|
|
1156
1151
|
...common,
|
|
1157
|
-
baseUrl
|
|
1152
|
+
baseUrl,
|
|
1158
1153
|
...(connection.apiKey && !common.apiKey ? { apiKey: connection.apiKey } : {}),
|
|
1159
1154
|
...(connection.headers ? { headers: connection.headers } : {}),
|
|
1160
1155
|
...(connection.queryParams ? { queryParams: connection.queryParams } : {}),
|
|
@@ -1163,11 +1158,11 @@ function registerConnection(providers, connection, servicePath, summary) {
|
|
|
1163
1158
|
...services,
|
|
1164
1159
|
[connection.serviceType]: {
|
|
1165
1160
|
...(isRecord(services[connection.serviceType]) ? services[connection.serviceType] : {}),
|
|
1166
|
-
...(
|
|
1161
|
+
...(targetPath ? { path: targetPath } : {}),
|
|
1167
1162
|
...(connection.serviceType === 'decision' ? { style: 'systemone' } : {}),
|
|
1168
1163
|
},
|
|
1169
1164
|
};
|
|
1170
|
-
const nextProvider = { ...(current ?? {}), common: nextCommon, services: nextServices };
|
|
1165
|
+
const nextProvider = { ...(current ?? {}), domain: identity.domain, common: nextCommon, services: nextServices };
|
|
1171
1166
|
if (!hasOwn(nextProvider, 'name'))
|
|
1172
1167
|
nextProvider.name = providerId;
|
|
1173
1168
|
providers[providerId] = nextProvider;
|
|
@@ -1213,11 +1208,14 @@ function planAgentModelProviderMigration(home) {
|
|
|
1213
1208
|
}
|
|
1214
1209
|
const providersFile = path.join(home, 'providers.json');
|
|
1215
1210
|
let providers = {};
|
|
1211
|
+
let providerRegistry = {};
|
|
1216
1212
|
if (fs.existsSync(providersFile)) {
|
|
1217
1213
|
try {
|
|
1218
1214
|
const raw = readJson(providersFile).value;
|
|
1219
|
-
if (isRecord(raw) && isRecord(raw.providers))
|
|
1215
|
+
if (isRecord(raw) && isRecord(raw.providers)) {
|
|
1216
|
+
providerRegistry = raw;
|
|
1220
1217
|
providers = { ...raw.providers };
|
|
1218
|
+
}
|
|
1221
1219
|
}
|
|
1222
1220
|
catch {
|
|
1223
1221
|
providers = {};
|
|
@@ -1235,7 +1233,7 @@ function planAgentModelProviderMigration(home) {
|
|
|
1235
1233
|
const serviceType = BASEAGENT_SERVICE_TYPES[name];
|
|
1236
1234
|
const connection = serviceType ? connectionFromBlock(block, serviceType) : undefined;
|
|
1237
1235
|
if (connection)
|
|
1238
|
-
defaultConnections.set(name, registerConnection(providers, connection, '', summary));
|
|
1236
|
+
defaultConnections.set(name, registerConnection(providers, connection, '', summary, isRecord(providerRegistry.aliases) ? providerRegistry.aliases : {}));
|
|
1239
1237
|
}
|
|
1240
1238
|
}
|
|
1241
1239
|
for (const [file, entry] of parsed) {
|
|
@@ -1271,7 +1269,7 @@ function planAgentModelProviderMigration(home) {
|
|
|
1271
1269
|
.map(field => `baseagents.${name}.${field}`));
|
|
1272
1270
|
if (serviceType && block.provider === undefined) {
|
|
1273
1271
|
const providerId = own
|
|
1274
|
-
? registerConnection(providers, own, '', summary)
|
|
1272
|
+
? registerConnection(providers, own, '', summary, isRecord(providerRegistry.aliases) ? providerRegistry.aliases : {})
|
|
1275
1273
|
: defaultConnections.get(name);
|
|
1276
1274
|
if (providerId)
|
|
1277
1275
|
block.provider = providerId;
|
|
@@ -1286,7 +1284,7 @@ function planAgentModelProviderMigration(home) {
|
|
|
1286
1284
|
const decisionMigrated = ownDecision ? connectionFromDecisionModel(ownDecision) : undefined;
|
|
1287
1285
|
let decisionSelection;
|
|
1288
1286
|
if (decisionMigrated) {
|
|
1289
|
-
const providerId = registerConnection(providers, decisionMigrated.connection, decisionMigrated.path, summary);
|
|
1287
|
+
const providerId = registerConnection(providers, decisionMigrated.connection, decisionMigrated.path, summary, isRecord(providerRegistry.aliases) ? providerRegistry.aliases : {});
|
|
1290
1288
|
const model = typeof ownDecision.model === 'string' ? ownDecision.model.trim() : '';
|
|
1291
1289
|
decisionSelection = { provider: providerId, ...(model ? { model } : {}) };
|
|
1292
1290
|
summary.decisionModelsMigrated += 1;
|
|
@@ -1313,7 +1311,7 @@ function planAgentModelProviderMigration(home) {
|
|
|
1313
1311
|
summary.filesChanged += 1;
|
|
1314
1312
|
}
|
|
1315
1313
|
if (Object.keys(providers).length > 0) {
|
|
1316
|
-
const nextText = jsonText({ $schema_version: 1, providers });
|
|
1314
|
+
const nextText = jsonText({ $schema_version: 1, ...providerRegistry, providers });
|
|
1317
1315
|
if (nextText !== providersBefore) {
|
|
1318
1316
|
changes.push({ file: providersFile, kind: 'agent-only-model', before: providersBefore, after: nextText });
|
|
1319
1317
|
details.push({ file: 'providers.json', removed: [] });
|
|
@@ -1415,6 +1413,65 @@ function planProviderServiceTypeMigration(home) {
|
|
|
1415
1413
|
}
|
|
1416
1414
|
return { home, changes, summary, details };
|
|
1417
1415
|
}
|
|
1416
|
+
export function runProviderIdentitySchemaMigration(options = {}) {
|
|
1417
|
+
const id = 'provider-domain-id-v1';
|
|
1418
|
+
const home = path.resolve(options.home || resolvePaths().root);
|
|
1419
|
+
const release = acquireLock(home, id);
|
|
1420
|
+
try {
|
|
1421
|
+
assertDaemonStopped(home);
|
|
1422
|
+
recoverJournal(home, id);
|
|
1423
|
+
const plan = planProviderIdentityMigration(home, undefined, { cleanupAliases: true });
|
|
1424
|
+
const backup = options.apply ? commitProviderSyncMigration(plan, true) : null;
|
|
1425
|
+
return { ok: true, mode: options.apply ? 'applied' : 'dry-run',
|
|
1426
|
+
home, changedFiles: plan.changes.length, backup, summary: plan.summary, pending: plan.pending };
|
|
1427
|
+
}
|
|
1428
|
+
finally {
|
|
1429
|
+
release();
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
export async function ensureProviderIdentityMigrationOnStartup() {
|
|
1433
|
+
try {
|
|
1434
|
+
const result = runProviderIdentitySchemaMigration({ apply: true });
|
|
1435
|
+
return result.changedFiles === 0 && result.pending.length === 0 ? null : result;
|
|
1436
|
+
}
|
|
1437
|
+
catch (error) {
|
|
1438
|
+
throw new ConfigError('PROVIDER_IDENTITY_MIGRATION_FAILED', 'Automatic Provider identity migration failed; resolve conflicting domains or connection settings before restarting', { cause: error });
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
export function commitProviderSyncMigration(plan, migrationLocked = false) {
|
|
1442
|
+
const id = 'provider-domain-id-v1';
|
|
1443
|
+
const releaseMigration = migrationLocked ? () => { } : acquireLock(plan.home, id);
|
|
1444
|
+
const releases = [];
|
|
1445
|
+
try {
|
|
1446
|
+
if (fs.existsSync(journalPath(plan.home, id))) {
|
|
1447
|
+
throw Object.assign(new Error('An unfinished Provider migration requires startup recovery'), { code: 'CONFLICT' });
|
|
1448
|
+
}
|
|
1449
|
+
const expected = new Map(plan.expected.map(item => [item.file, item.before]));
|
|
1450
|
+
for (const item of plan.changes)
|
|
1451
|
+
expected.set(item.file, item.before);
|
|
1452
|
+
const home = path.resolve(plan.home);
|
|
1453
|
+
for (const file of [...expected.keys()].sort()) {
|
|
1454
|
+
const relative = path.relative(home, file);
|
|
1455
|
+
if (!relative || relative.startsWith('..') || path.isAbsolute(relative))
|
|
1456
|
+
throw new Error('Unsafe Provider sync path');
|
|
1457
|
+
for (let current = path.resolve(file); current !== home; current = path.dirname(current)) {
|
|
1458
|
+
if (fs.existsSync(current) && fs.lstatSync(current).isSymbolicLink())
|
|
1459
|
+
throw new Error('Provider sync does not follow symlinks');
|
|
1460
|
+
}
|
|
1461
|
+
releases.push(acquireConfigMutationLock(file));
|
|
1462
|
+
const actual = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : null;
|
|
1463
|
+
if (actual !== expected.get(file)) {
|
|
1464
|
+
throw Object.assign(new Error('Configuration changed during Provider sync; retry after reviewing the current configuration'), { code: 'CONFLICT' });
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
return applyMigration(plan, id);
|
|
1468
|
+
}
|
|
1469
|
+
finally {
|
|
1470
|
+
for (const release of releases.reverse())
|
|
1471
|
+
release();
|
|
1472
|
+
releaseMigration();
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1418
1475
|
export function runProviderServiceTypeSchemaMigration(options = {}) {
|
|
1419
1476
|
const id = 'provider-service-type-v1';
|
|
1420
1477
|
const home = path.resolve(options.home || resolvePaths().root);
|