evolcore 0.0.41-test.1 → 0.0.41-test.2
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 +49 -36
- package/dist/agents/baseagent.js +68 -6
- package/dist/agents/codex-runner.js +62 -43
- package/dist/aun/aid/agentmd.js +98 -11
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +26 -2
- package/dist/aun/aid/identity.js +91 -0
- package/dist/aun/aid/index.js +1 -1
- package/dist/aun/aid/managed-operation.js +1 -1
- package/dist/aun/aid/ownership-operation.js +23 -22
- package/dist/aun/menu/client.js +27 -0
- package/dist/aun/msg/p2p.js +3 -8
- package/dist/aun/service-proxy.js +17 -0
- package/dist/channels/aun.js +321 -34
- package/dist/cli/agent-command.js +5 -2
- package/dist/cli/agent-create.js +991 -233
- package/dist/cli/agent.js +49 -10
- package/dist/cli/aid-bind-command.js +48 -19
- package/dist/cli/aun-commands.js +44 -16
- package/dist/cli/daemon-commands.js +1 -0
- package/dist/cli/index.js +24 -1
- package/dist/cli/init-channel.js +1 -1
- package/dist/cli/init.js +75 -1
- package/dist/cli/managed-command-guard.js +13 -1
- package/dist/cli/provider-command.js +57 -0
- package/dist/cli/restart-monitor.js +4 -2
- package/dist/cli/stats.js +10 -3
- package/dist/cli/task-context.js +19 -0
- package/dist/config/boot-log.js +3 -2
- package/dist/config/config-field-policy.js +12 -7
- package/dist/config/config-manager.js +138 -6
- package/dist/config/owner-config.js +2 -2
- package/dist/config/peer-role-resolver.js +2 -1
- package/dist/config/provider-ipc-service.js +132 -0
- package/dist/config/provider-menu-request.js +58 -0
- package/dist/config/providers-management.js +78 -5
- package/dist/config/resolved-config-op.js +8 -1
- package/dist/config/schema-migration.js +322 -8
- package/dist/config-store.js +10 -1
- package/dist/contracts/ecweb-service-protocol.js +2 -1
- package/dist/core/agent-application-service.js +60 -11
- package/dist/core/agent-create-status.js +203 -0
- package/dist/core/agent-creation-claim.js +177 -0
- package/dist/core/agent-ipc-registration.js +39 -18
- package/dist/core/agent-runtime.js +193 -23
- package/dist/core/auth/agent-delegation.js +4 -2
- package/dist/core/auth/auth-gateway.js +66 -1
- package/dist/core/auth/authorization-audit.js +41 -5
- package/dist/core/auth/delegation-authorization.js +2 -1
- package/dist/core/auth/operation-authorizer.js +28 -6
- package/dist/core/auth/operation-catalog.js +14 -1
- package/dist/core/channel-loader.js +2 -0
- package/dist/core/command/agent-control.js +257 -14
- package/dist/core/command/cli-intent-parser.js +6 -2
- package/dist/core/command/command-handler.js +64 -55
- package/dist/core/command/memory-slash.js +1 -1
- package/dist/core/command/menu-catalog.js +5 -0
- package/dist/core/command/menu-handler.js +64 -18
- package/dist/core/command/menu-protocol.js +15 -1
- package/dist/core/command/provider-menu.js +46 -0
- package/dist/core/command/slash-handler.js +2 -1
- package/dist/core/daemon-control.js +18 -13
- package/dist/core/event-catalog.js +10 -0
- package/dist/core/evolagent-registry.js +3 -1
- package/dist/core/evolagent.js +8 -6
- package/dist/core/file-integrity/store.js +11 -0
- package/dist/core/handoff/ipc-registration.js +3 -0
- package/dist/core/initialization/service.js +491 -0
- package/dist/core/ipc-registration.js +34 -22
- package/dist/core/memory/consolidation-ops-records.js +95 -0
- package/dist/core/memory/consolidation-trigger.js +19 -2
- package/dist/core/memory/consolidation.js +19 -8
- package/dist/core/memory/memory-admin.js +1 -1
- package/dist/core/memory/relation-sweep.js +11 -6
- package/dist/core/message/aun-ipc-sender.js +73 -67
- package/dist/core/message/im-renderer.js +18 -0
- package/dist/core/message/message-bridge.js +35 -3
- package/dist/core/message/response-engine.js +32 -28
- package/dist/core/model/catalog-service.js +1 -1
- package/dist/core/model/config-scope.js +5 -7
- package/dist/core/ownership/owner-resolver.js +755 -143
- package/dist/core/permission/approval-gateway.js +103 -403
- package/dist/core/permission/ec-command-parser.js +32 -4
- package/dist/core/permission/index.js +1 -0
- package/dist/core/permission/permission-result.js +78 -0
- package/dist/core/permission/tool-policy.js +7 -43
- package/dist/core/system-session/memory.js +37 -7
- package/dist/directory/owner-directory-cache.js +2 -2
- package/dist/ecweb/init-menu.js +32 -0
- package/dist/index.js +17 -5
- package/dist/ipc.js +85 -25
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +6 -7
- package/dist/trigger/authorization.js +27 -17
- package/dist/trigger/feedback.js +2 -3
- package/dist/trigger/ipc-service.js +105 -78
- package/dist/trigger/local-files.js +2 -1
- package/dist/trigger/manager.js +5 -3
- package/dist/trigger/scheduler.js +88 -6
- package/dist/utils/atomic-write.js +28 -0
- package/dist/utils/error-utils.js +24 -0
- package/dist/utils/logger.js +68 -1
- package/dist/utils/welcome.js +1 -1
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/aun/SDK.md +4 -1
- package/kits/docs/evolcore/INDEX.md +1 -0
- package/kits/docs/evolcore/agent.md +8 -1
- package/kits/docs/evolcore/aid.md +67 -17
- package/kits/docs/evolcore/config.md +11 -1
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/provider.md +50 -0
- package/kits/docs/identity/AID_PROFILE_SPEC.md +52 -17
- package/kits/rules/01-overview.md +3 -0
- package/kits/rules/04-relation.md +1 -1
- package/kits/schemas/_meta.json +2 -2
- package/kits/schemas/agent-config.schema.16.json +3 -3
- package/kits/schemas/relation-config.schema.11.json +17 -0
- package/kits/skills/.switches.json +8 -0
- package/kits/skills/ec-agent-create/SKILL.md +3 -0
- package/kits/skills/ec-identity/SKILL.md +2 -2
- package/kits/skills/ec-skill/scripts/skill.mjs +6 -0
- package/kits/skills/ec-trigger/SKILL.md +5 -13
- package/kits/skills/thread-ops/SKILL.md +5 -0
- package/kits/templates/system-fragments/venue.md +1 -1
- package/package.json +3 -3
- package/dist/core/memory/forget-log.js +0 -96
- package/dist/core/message/create-status.js +0 -96
|
@@ -1,10 +1,78 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path, { posix } from 'node:path';
|
|
3
4
|
import { resolvePaths } from '../paths.js';
|
|
4
5
|
import { ConfigTarget, mutateConfig } from './config-manager.js';
|
|
6
|
+
import { atomicReadJson } from '../utils/atomic-write.js';
|
|
5
7
|
import { readProvidersFile, validateProvidersFile } from './providers.js';
|
|
6
8
|
import { providerEnvironmentVariable, providerNameFromBaseUrlIfStatic, resolveProviderService, resolveProviderServiceForBaseagent } from './providers-config.js';
|
|
7
9
|
export const PROVIDER_SECRET_MASK = '<redacted>';
|
|
10
|
+
function providerReferences(providerId, providerFile) {
|
|
11
|
+
const root = path.dirname(path.resolve(providerFile));
|
|
12
|
+
const agentsDir = path.join(root, 'agents');
|
|
13
|
+
const candidates = [path.join(agentsDir, 'defaults.json')];
|
|
14
|
+
const directories = (directory) => {
|
|
15
|
+
try {
|
|
16
|
+
return fs.readdirSync(directory, { withFileTypes: true }).filter(entry => entry.isDirectory() || entry.isSymbolicLink());
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error.code === 'ENOENT')
|
|
20
|
+
return [];
|
|
21
|
+
throw Object.assign(new Error('Cannot verify Provider reference directories'), {
|
|
22
|
+
code: 'CONFLICT', statusCode: 409,
|
|
23
|
+
data: { kind: 'reference_check_failed', file: path.relative(root, directory).replace(/\\/g, '/') },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
for (const agent of directories(agentsDir)) {
|
|
28
|
+
candidates.push(path.join(agentsDir, agent.name, 'config.json'));
|
|
29
|
+
for (const relation of directories(path.join(agentsDir, agent.name, 'relations'))) {
|
|
30
|
+
candidates.push(path.join(agentsDir, agent.name, 'relations', relation.name, 'config.json'));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const references = [];
|
|
34
|
+
const visit = (value, fieldPath, file) => {
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
value.forEach((item, index) => visit(item, fieldPath + '[' + index + ']', file));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!value || typeof value !== 'object')
|
|
40
|
+
return;
|
|
41
|
+
for (const [key, child] of Object.entries(value)) {
|
|
42
|
+
const childPath = fieldPath + '.' + key;
|
|
43
|
+
if (key === 'provider' && child === providerId)
|
|
44
|
+
references.push({ file, path: childPath });
|
|
45
|
+
visit(child, childPath, file);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
for (const file of candidates) {
|
|
49
|
+
try {
|
|
50
|
+
const value = atomicReadJson(file);
|
|
51
|
+
if (value === null && !fs.existsSync(file))
|
|
52
|
+
continue;
|
|
53
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
54
|
+
throw new Error();
|
|
55
|
+
for (const field of ['baseagents', 'agents', 'Services', 'decision_model']) {
|
|
56
|
+
visit(value[field], field, path.relative(root, file).replace(/\\/g, '/'));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
throw Object.assign(new Error('Cannot verify Provider references; repair the configuration before deleting'), {
|
|
61
|
+
code: 'CONFLICT', statusCode: 409,
|
|
62
|
+
data: { kind: 'reference_check_failed', file: path.relative(root, file).replace(/\\/g, '/') },
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return references;
|
|
67
|
+
}
|
|
68
|
+
function assertProviderUnreferenced(providerId, file) {
|
|
69
|
+
const references = providerReferences(providerId, file);
|
|
70
|
+
if (references.length) {
|
|
71
|
+
throw Object.assign(new Error('Provider is still referenced'), {
|
|
72
|
+
code: 'CONFLICT', statusCode: 409, data: { kind: 'provider_referenced', providerId, references },
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
8
76
|
function revisionValue(value) {
|
|
9
77
|
if (Array.isArray(value))
|
|
10
78
|
return value.map(revisionValue);
|
|
@@ -85,9 +153,13 @@ export async function updateProvider(input, file = resolvePaths().providersConfi
|
|
|
85
153
|
const result = mutateConfig(ConfigTarget.Providers, { providerFile: file }, config => {
|
|
86
154
|
const current = config;
|
|
87
155
|
if (providersRevision(current) !== input.revision) {
|
|
88
|
-
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { statusCode: 409 });
|
|
156
|
+
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
157
|
+
}
|
|
158
|
+
if (!Object.hasOwn(current.providers, input.providerId)) {
|
|
159
|
+
throw Object.assign(new Error(`Provider not found: ${input.providerId}`), { code: 'NOT_FOUND', statusCode: 404 });
|
|
89
160
|
}
|
|
90
161
|
if (input.remove) {
|
|
162
|
+
assertProviderUnreferenced(input.providerId, file);
|
|
91
163
|
current.nextId = nextProviderSequence(current);
|
|
92
164
|
delete current.providers[input.providerId];
|
|
93
165
|
}
|
|
@@ -178,7 +250,7 @@ export async function createProvider(input, file = resolvePaths().providersConfi
|
|
|
178
250
|
const result = mutateConfig(ConfigTarget.Providers, { providerFile: file }, config => {
|
|
179
251
|
const current = config;
|
|
180
252
|
if (providersRevision(current) !== input.revision) {
|
|
181
|
-
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { statusCode: 409 });
|
|
253
|
+
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
182
254
|
}
|
|
183
255
|
const sequence = nextProviderSequence(current);
|
|
184
256
|
const providerId = `provider-${sequence}`;
|
|
@@ -270,7 +342,7 @@ export async function saveProviderChanges(input, file = resolvePaths().providers
|
|
|
270
342
|
const result = mutateConfig(ConfigTarget.Providers, { providerFile: file }, config => {
|
|
271
343
|
const current = config;
|
|
272
344
|
if (providersRevision(current) !== input.revision) {
|
|
273
|
-
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { statusCode: 409 });
|
|
345
|
+
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
274
346
|
}
|
|
275
347
|
const providerIds = {};
|
|
276
348
|
const originalIds = new Set(Object.keys(current.providers));
|
|
@@ -281,6 +353,7 @@ export async function saveProviderChanges(input, file = resolvePaths().providers
|
|
|
281
353
|
throw new Error(change.create ? 'Provider already exists' : 'Provider not found');
|
|
282
354
|
}
|
|
283
355
|
if (change.remove) {
|
|
356
|
+
assertProviderUnreferenced(change.providerId, file);
|
|
284
357
|
delete current.providers[change.providerId];
|
|
285
358
|
continue;
|
|
286
359
|
}
|
|
@@ -307,7 +380,7 @@ export async function importOrMergeBaseagentProvider(input, file = resolvePaths(
|
|
|
307
380
|
const result = mutateConfig(ConfigTarget.Providers, { providerFile: file }, config => {
|
|
308
381
|
const current = config;
|
|
309
382
|
if (providersRevision(current) !== input.revision) {
|
|
310
|
-
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { statusCode: 409 });
|
|
383
|
+
throw Object.assign(new Error('Providers changed after loading; reload before saving'), { code: 'CONFLICT', statusCode: 409, data: { kind: 'revision_conflict' } });
|
|
311
384
|
}
|
|
312
385
|
const importedHost = providerHostname(imported.common.baseUrl);
|
|
313
386
|
const match = importedHost
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { normalizeCliArgv } from '../cli/cli-argv.js';
|
|
2
2
|
import { parseConfigSelector } from '../cli/config-selector.js';
|
|
3
3
|
import { parseConfigFieldValue, resolveConfigFieldRule, } from './config-field-policy.js';
|
|
4
|
+
import { isAgentOnlyBaseagentField } from './config-field-policy.js';
|
|
4
5
|
import { ConfigError, routeFieldPath } from './config-manager.js';
|
|
5
6
|
import { isValidAid } from '../aun/aid/validation.js';
|
|
6
7
|
const SELECTOR_OPTIONS = {
|
|
@@ -132,6 +133,9 @@ function resolveFieldCommand(argv, subcommand, options = {}) {
|
|
|
132
133
|
};
|
|
133
134
|
}
|
|
134
135
|
const fieldRule = resolveConfigFieldRule(field, selector.scope);
|
|
136
|
+
if (selector.scope === 'relation' && subcommand !== 'get' && isAgentOnlyBaseagentField(field)) {
|
|
137
|
+
return { ok: false, code: 'SCOPE_MISMATCH', reason: `${field} 只支持 Agent scope,请移除 --peer 后操作` };
|
|
138
|
+
}
|
|
135
139
|
if (subcommand !== 'get' && fieldRule.class === 'safe-readonly-object') {
|
|
136
140
|
return {
|
|
137
141
|
ok: false,
|
|
@@ -148,7 +152,10 @@ function resolveFieldCommand(argv, subcommand, options = {}) {
|
|
|
148
152
|
? subcommand === 'get' ? 'config.read' : 'config.write'
|
|
149
153
|
: `config.${subcommand}`;
|
|
150
154
|
let route;
|
|
151
|
-
const
|
|
155
|
+
const relationAgentRead = subcommand === 'get'
|
|
156
|
+
&& selector.scope === 'relation'
|
|
157
|
+
&& isAgentOnlyBaseagentField(field);
|
|
158
|
+
const routeRequired = subcommand !== 'get' || (!isManagementOperation && !relationAgentRead);
|
|
152
159
|
try {
|
|
153
160
|
route = routeFieldPath(field, selector.scope);
|
|
154
161
|
}
|
|
@@ -3,12 +3,15 @@ import fs from 'fs';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { resolvePaths } from '../paths.js';
|
|
5
5
|
import { ConfigError } from './config-manager.js';
|
|
6
|
+
import { firstConfiguredOwner } from './owner-config.js';
|
|
7
|
+
import { resolveLegacyBaseagentModelSelection } from '../agents/baseagent.js';
|
|
6
8
|
const MIGRATION_KIND = {
|
|
7
9
|
'auxiliary-model-v1': 'auxiliary-model',
|
|
8
10
|
'agent-only-model-v1': 'agent-only-model',
|
|
9
11
|
'agent-model-provider-v1': 'agent-only-model',
|
|
10
12
|
'provider-service-type-v1': 'provider-service-type',
|
|
11
13
|
'relation-config-v11-v1': 'agent-only-model',
|
|
14
|
+
'legacy-model-selection-v1': 'agent-only-model',
|
|
12
15
|
};
|
|
13
16
|
const SUPPORTED_BASEAGENTS = new Set(['claude', 'codex', 'gemini', 'ecagent']);
|
|
14
17
|
const BASEAGENT_ALIASES = new Map([
|
|
@@ -54,6 +57,65 @@ function baseagentSource(value) {
|
|
|
54
57
|
? value.agents
|
|
55
58
|
: undefined;
|
|
56
59
|
}
|
|
60
|
+
function firstOwnerAid(agent) {
|
|
61
|
+
const owner = firstConfiguredOwner(agent);
|
|
62
|
+
if (owner && validAid(owner))
|
|
63
|
+
return owner;
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Read only the configured owner's legacy relation selections. Relation
|
|
68
|
+
* values from every other peer are deliberately ignored: after this
|
|
69
|
+
* migration model/effort are Agent-owned and there is no deterministic
|
|
70
|
+
* precedence among ordinary relations.
|
|
71
|
+
*/
|
|
72
|
+
function ownerRelationSelections(relationsDir, ownerAid, fallbackBaseagent) {
|
|
73
|
+
const selections = new Map();
|
|
74
|
+
if (!ownerAid)
|
|
75
|
+
return selections;
|
|
76
|
+
const ownerDirNames = new Set([`aun#${ownerAid}`, `aun#${encodeURIComponent(ownerAid)}`]);
|
|
77
|
+
for (const relationFile of walkRelationConfigs(relationsDir)) {
|
|
78
|
+
if (!ownerDirNames.has(path.basename(path.dirname(relationFile))))
|
|
79
|
+
continue;
|
|
80
|
+
let relation;
|
|
81
|
+
try {
|
|
82
|
+
relation = readJson(relationFile).value;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (!isRecord(relation))
|
|
88
|
+
continue;
|
|
89
|
+
const active = canonicalBaseagent(relation.active_baseagent) || fallbackBaseagent;
|
|
90
|
+
// Older relation files could hold a flat model/effort pair. Attribute it
|
|
91
|
+
// to that relation's active backend, while still ignoring non-owner peers.
|
|
92
|
+
if (active && (typeof relation.model === 'string' || typeof relation.effort === 'string' || typeof relation.reasoning === 'string')) {
|
|
93
|
+
const selection = {};
|
|
94
|
+
if (typeof relation.model === 'string' && relation.model.trim())
|
|
95
|
+
selection.model = relation.model.trim();
|
|
96
|
+
const effort = typeof relation.effort === 'string' ? relation.effort : relation.reasoning;
|
|
97
|
+
if (typeof effort === 'string' && effort.trim())
|
|
98
|
+
selection.effort = effort.trim();
|
|
99
|
+
if (selection.model !== undefined || selection.effort !== undefined)
|
|
100
|
+
selections.set(active, selection);
|
|
101
|
+
}
|
|
102
|
+
const source = baseagentSource(relation) ?? {};
|
|
103
|
+
for (const [rawName, rawBlock] of Object.entries(source)) {
|
|
104
|
+
const name = canonicalBaseagent(rawName);
|
|
105
|
+
if (!name || !isRecord(rawBlock))
|
|
106
|
+
continue;
|
|
107
|
+
const selection = {};
|
|
108
|
+
if (typeof rawBlock.model === 'string' && rawBlock.model.trim())
|
|
109
|
+
selection.model = rawBlock.model.trim();
|
|
110
|
+
const effort = typeof rawBlock.effort === 'string' ? rawBlock.effort : rawBlock.reasoning;
|
|
111
|
+
if (typeof effort === 'string' && effort.trim())
|
|
112
|
+
selection.effort = effort.trim();
|
|
113
|
+
if (selection.model !== undefined || selection.effort !== undefined)
|
|
114
|
+
selections.set(name, selection);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return selections;
|
|
118
|
+
}
|
|
57
119
|
function baseagentNames(value) {
|
|
58
120
|
const source = baseagentSource(value);
|
|
59
121
|
if (!source)
|
|
@@ -568,9 +630,124 @@ export async function ensureAuxiliaryModelMigrationOnStartup() {
|
|
|
568
630
|
throw new ConfigError('AUXILIARY_MODEL_MIGRATION_FAILED', `Automatic Session Renew auxiliary-model schema migration failed: ${detail}`, { cause: error });
|
|
569
631
|
}
|
|
570
632
|
}
|
|
571
|
-
// ──
|
|
633
|
+
// ── Preserve pre-upgrade runner selections once, before removing legacy relation settings. ──
|
|
634
|
+
export function runLegacyModelSelectionMigration(options = {}) {
|
|
635
|
+
const home = path.resolve(options.home || resolvePaths().root);
|
|
636
|
+
const id = 'legacy-model-selection-v1';
|
|
637
|
+
const release = acquireLock(home, id);
|
|
638
|
+
try {
|
|
639
|
+
assertDaemonStopped(home);
|
|
640
|
+
recoverJournal(home, id);
|
|
641
|
+
const markerFile = path.join(home, 'data', `${id}-completed.json`);
|
|
642
|
+
if (fs.existsSync(markerFile)) {
|
|
643
|
+
const marker = readJson(markerFile).value;
|
|
644
|
+
if (!isRecord(marker) || marker.schemaVersion !== 1)
|
|
645
|
+
throw new Error(`Invalid model migration marker: ${markerFile}`);
|
|
646
|
+
return { mode: options.apply ? 'applied' : 'dry-run', changedFiles: 0, restoredModels: 0, backup: null };
|
|
647
|
+
}
|
|
648
|
+
const changes = [];
|
|
649
|
+
const selections = [];
|
|
650
|
+
let restoredModels = 0;
|
|
651
|
+
const agentsRoot = path.join(home, 'agents');
|
|
652
|
+
const defaultsFile = path.join(agentsRoot, 'defaults.json');
|
|
653
|
+
const defaults = fs.existsSync(defaultsFile) ? readJson(defaultsFile).value : {};
|
|
654
|
+
if (!isRecord(defaults))
|
|
655
|
+
throw new Error(`${defaultsFile}: defaults configuration must be an object`);
|
|
656
|
+
const inheritedBlocks = baseagentSource(defaults) ?? {};
|
|
657
|
+
const entries = fs.existsSync(agentsRoot) ? fs.readdirSync(agentsRoot, { withFileTypes: true }) : [];
|
|
658
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
659
|
+
if (!entry.isDirectory() || !validAid(entry.name))
|
|
660
|
+
continue;
|
|
661
|
+
const file = path.join(agentsRoot, entry.name, 'config.json');
|
|
662
|
+
if (!fs.existsSync(file))
|
|
663
|
+
continue;
|
|
664
|
+
let parsed;
|
|
665
|
+
try {
|
|
666
|
+
parsed = readJson(file);
|
|
667
|
+
}
|
|
668
|
+
catch {
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
if (!isRecord(parsed.value))
|
|
672
|
+
continue;
|
|
673
|
+
const agent = parsed.value;
|
|
674
|
+
const baseagent = canonicalBaseagent(agent.active_baseagent) || canonicalBaseagent(defaults.active_baseagent);
|
|
675
|
+
if (!baseagent)
|
|
676
|
+
continue;
|
|
677
|
+
const blocks = baseagentSource(agent) ?? {};
|
|
678
|
+
const ownerSelections = ownerRelationSelections(path.join(agentsRoot, entry.name, 'relations'), firstOwnerAid(agent), baseagent);
|
|
679
|
+
// Process every configured backend, not only the currently active one.
|
|
680
|
+
// This preserves an Owner's explicit override even when the Agent later
|
|
681
|
+
// switches active_baseagent.
|
|
682
|
+
const backends = new Set([baseagent]);
|
|
683
|
+
for (const rawName of Object.keys(blocks)) {
|
|
684
|
+
const name = canonicalBaseagent(rawName);
|
|
685
|
+
if (name)
|
|
686
|
+
backends.add(name);
|
|
687
|
+
}
|
|
688
|
+
for (const name of ownerSelections.keys())
|
|
689
|
+
backends.add(name);
|
|
690
|
+
let nextBlocks = { ...blocks };
|
|
691
|
+
for (const backend of backends) {
|
|
692
|
+
const block = isRecord(blocks[backend]) ? blocks[backend] : {};
|
|
693
|
+
const inherited = isRecord(inheritedBlocks[backend]) ? inheritedBlocks[backend] : {};
|
|
694
|
+
const ownerSelection = ownerSelections.get(backend);
|
|
695
|
+
const nextBlock = { ...block };
|
|
696
|
+
const migrated = { aid: entry.name, baseagent: backend };
|
|
697
|
+
// Owner relation values win field-by-field over an existing Agent
|
|
698
|
+
// value. A missing Owner field leaves the Agent value untouched.
|
|
699
|
+
if (ownerSelection?.model !== undefined && ownerSelection.model !== block.model) {
|
|
700
|
+
nextBlock.model = ownerSelection.model;
|
|
701
|
+
migrated.model = ownerSelection.model;
|
|
702
|
+
migrated.modelSource = 'owner-relation';
|
|
703
|
+
}
|
|
704
|
+
if (ownerSelection?.effort !== undefined && ownerSelection.effort !== block.effort) {
|
|
705
|
+
nextBlock.effort = ownerSelection.effort;
|
|
706
|
+
migrated.effort = ownerSelection.effort;
|
|
707
|
+
migrated.effortSource = 'owner-relation';
|
|
708
|
+
}
|
|
709
|
+
// Preserve the runner's historical selection when no Agent/defaults
|
|
710
|
+
// model exists and the Owner relation did not provide one. This is a
|
|
711
|
+
// one-time compatibility fallback; other relation values are ignored.
|
|
712
|
+
const hasAgentModel = typeof block.model === 'string' && block.model.trim().length > 0;
|
|
713
|
+
const hasDefaultModel = typeof inherited.model === 'string' && inherited.model.trim().length > 0;
|
|
714
|
+
if (backend === baseagent && !hasAgentModel && !hasDefaultModel && ownerSelection?.model === undefined) {
|
|
715
|
+
const legacy = resolveLegacyBaseagentModelSelection(backend);
|
|
716
|
+
if (legacy) {
|
|
717
|
+
nextBlock.model = legacy.model;
|
|
718
|
+
migrated.model = legacy.model;
|
|
719
|
+
migrated.modelSource = legacy.source;
|
|
720
|
+
if (!block.effort && ownerSelection?.effort === undefined && legacy.effort) {
|
|
721
|
+
nextBlock.effort = legacy.effort;
|
|
722
|
+
migrated.effort = legacy.effort;
|
|
723
|
+
migrated.effortSource = legacy.source;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
if (Object.keys(migrated).length > 2) {
|
|
728
|
+
nextBlocks = { ...nextBlocks, [backend]: nextBlock };
|
|
729
|
+
selections.push(migrated);
|
|
730
|
+
if (migrated.model !== undefined)
|
|
731
|
+
restoredModels += 1;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (JSON.stringify(nextBlocks) !== JSON.stringify(blocks)) {
|
|
735
|
+
const next = { ...agent, baseagents: nextBlocks };
|
|
736
|
+
changes.push({ file, kind: 'agent-only-model', before: parsed.text, after: jsonText(next) });
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
changes.push({ file: markerFile, kind: 'agent-only-model', before: null,
|
|
740
|
+
after: jsonText({ schemaVersion: 1, completedAt: new Date().toISOString(), selections }) });
|
|
741
|
+
const backup = options.apply ? applyMigration({ home, changes, summary: { restoredModels } }, id) : null;
|
|
742
|
+
return { mode: options.apply ? 'applied' : 'dry-run', changedFiles: changes.length, restoredModels, backup };
|
|
743
|
+
}
|
|
744
|
+
finally {
|
|
745
|
+
release();
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
// ── Remove relation model fields while preserving defaults and Agent selections. ──
|
|
572
749
|
/** 关系层不再承载的模型字段(与 config-manager 合并时的剥离规则一致)。 */
|
|
573
|
-
const RELATION_MODEL_FIELDS = ['
|
|
750
|
+
const RELATION_MODEL_FIELDS = ['active_baseagent', 'model', 'models'];
|
|
574
751
|
/** 剥离后内容与新版本 schema 等价的直接前驱版本(relation v10 已撤销、从未发布)。 */
|
|
575
752
|
const RELATION_RESTAMP = { from: 9, to: 11 };
|
|
576
753
|
const DEFAULTS_RESTAMP = { from: 6, to: 5 };
|
|
@@ -587,6 +764,28 @@ function stripOwnFields(value, fields) {
|
|
|
587
764
|
function stripRelationModelFields(input) {
|
|
588
765
|
const value = { ...input };
|
|
589
766
|
const removed = stripOwnFields(value, RELATION_MODEL_FIELDS);
|
|
767
|
+
if (isRecord(value.baseagents)) {
|
|
768
|
+
const baseagents = {};
|
|
769
|
+
for (const [baseagent, rawBlock] of Object.entries(value.baseagents)) {
|
|
770
|
+
if (!isRecord(rawBlock)) {
|
|
771
|
+
baseagents[baseagent] = rawBlock;
|
|
772
|
+
continue;
|
|
773
|
+
}
|
|
774
|
+
const block = { ...rawBlock };
|
|
775
|
+
for (const field of ['model', 'effort', 'reasoning']) {
|
|
776
|
+
if (!hasOwn(block, field))
|
|
777
|
+
continue;
|
|
778
|
+
delete block[field];
|
|
779
|
+
removed.push(`baseagents.${baseagent}.${field}`);
|
|
780
|
+
}
|
|
781
|
+
if (Object.keys(block).length > 0)
|
|
782
|
+
baseagents[baseagent] = block;
|
|
783
|
+
}
|
|
784
|
+
if (Object.keys(baseagents).length > 0)
|
|
785
|
+
value.baseagents = baseagents;
|
|
786
|
+
else
|
|
787
|
+
delete value.baseagents;
|
|
788
|
+
}
|
|
590
789
|
if (removed.length > 0 && value.$schema_version === RELATION_RESTAMP.from)
|
|
591
790
|
value.$schema_version = RELATION_RESTAMP.to;
|
|
592
791
|
return { value, removed };
|
|
@@ -626,6 +825,10 @@ function planAgentOnlyModelMigration(home) {
|
|
|
626
825
|
filesChanged: 0,
|
|
627
826
|
relationFilesChanged: 0,
|
|
628
827
|
defaultsFieldsRemoved: 0,
|
|
828
|
+
defaultsBaseagentsAdded: 0,
|
|
829
|
+
ownerModelsPromoted: 0,
|
|
830
|
+
ownerEffortsPromoted: 0,
|
|
831
|
+
legacyModelsRestored: 0,
|
|
629
832
|
};
|
|
630
833
|
const agentsRoot = path.join(home, 'agents');
|
|
631
834
|
if (!fs.existsSync(agentsRoot))
|
|
@@ -653,19 +856,130 @@ function planAgentOnlyModelMigration(home) {
|
|
|
653
856
|
const defaultsFile = path.join(agentsRoot, 'defaults.json');
|
|
654
857
|
if (fs.existsSync(defaultsFile))
|
|
655
858
|
summary.defaultsFieldsRemoved += plan(defaultsFile, stripDefaultsModelFields).length;
|
|
859
|
+
const pendingDefaults = changes.find(change => change.file === defaultsFile);
|
|
860
|
+
const defaultsRaw = pendingDefaults
|
|
861
|
+
? JSON.parse(pendingDefaults.after)
|
|
862
|
+
: fs.existsSync(defaultsFile) ? readJson(defaultsFile).value : {};
|
|
863
|
+
if (!isRecord(defaultsRaw))
|
|
864
|
+
throw new Error(`${defaultsFile}: defaults configuration must be an object`);
|
|
865
|
+
const inheritedBlocks = baseagentSource(defaultsRaw) ?? {};
|
|
656
866
|
const agentEntries = fs.readdirSync(agentsRoot, { withFileTypes: true })
|
|
657
867
|
.sort((left, right) => left.name.localeCompare(right.name));
|
|
868
|
+
const declaredBaseagents = new Set();
|
|
658
869
|
for (const entry of agentEntries) {
|
|
659
870
|
if (!entry.isDirectory() || !validAid(entry.name))
|
|
660
871
|
continue;
|
|
872
|
+
const agentFile = path.join(agentsRoot, entry.name, 'config.json');
|
|
873
|
+
if (fs.existsSync(agentFile)) {
|
|
874
|
+
summary.configsScanned += 1;
|
|
875
|
+
try {
|
|
876
|
+
const parsed = readJson(agentFile);
|
|
877
|
+
const agent = parsed.value;
|
|
878
|
+
if (isRecord(agent)) {
|
|
879
|
+
const active = canonicalBaseagent(agent.active_baseagent);
|
|
880
|
+
if (active)
|
|
881
|
+
declaredBaseagents.add(active);
|
|
882
|
+
for (const name of baseagentNames(agent)) {
|
|
883
|
+
const canonical = canonicalBaseagent(name);
|
|
884
|
+
if (canonical)
|
|
885
|
+
declaredBaseagents.add(canonical);
|
|
886
|
+
}
|
|
887
|
+
const selected = active || canonicalBaseagent(defaultsRaw.active_baseagent);
|
|
888
|
+
if (selected) {
|
|
889
|
+
const ownerSelections = ownerRelationSelections(path.join(agentsRoot, entry.name, 'relations'), firstOwnerAid(agent), selected);
|
|
890
|
+
const sourceBlocks = baseagentSource(agent) ?? {};
|
|
891
|
+
const nextBlocks = { ...sourceBlocks };
|
|
892
|
+
const backends = new Set([selected]);
|
|
893
|
+
for (const rawName of Object.keys(sourceBlocks)) {
|
|
894
|
+
const name = canonicalBaseagent(rawName);
|
|
895
|
+
if (name)
|
|
896
|
+
backends.add(name);
|
|
897
|
+
}
|
|
898
|
+
for (const name of ownerSelections.keys())
|
|
899
|
+
backends.add(name);
|
|
900
|
+
const migrated = [];
|
|
901
|
+
for (const backend of backends) {
|
|
902
|
+
const block = isRecord(sourceBlocks[backend]) ? sourceBlocks[backend] : {};
|
|
903
|
+
const inherited = isRecord(inheritedBlocks[backend]) ? inheritedBlocks[backend] : {};
|
|
904
|
+
const owner = ownerSelections.get(backend);
|
|
905
|
+
const next = { ...block };
|
|
906
|
+
if (owner?.model !== undefined && owner.model !== block.model) {
|
|
907
|
+
next.model = owner.model;
|
|
908
|
+
migrated.push(`baseagents.${backend}.model from owner relation`);
|
|
909
|
+
summary.ownerModelsPromoted += 1;
|
|
910
|
+
}
|
|
911
|
+
if (owner?.effort !== undefined && owner.effort !== block.effort) {
|
|
912
|
+
next.effort = owner.effort;
|
|
913
|
+
migrated.push(`baseagents.${backend}.effort from owner relation`);
|
|
914
|
+
summary.ownerEffortsPromoted += 1;
|
|
915
|
+
}
|
|
916
|
+
const hasAgentModel = typeof block.model === 'string' && block.model.trim().length > 0;
|
|
917
|
+
const hasDefaultModel = typeof inherited.model === 'string' && inherited.model.trim().length > 0;
|
|
918
|
+
if (backend === selected && !hasAgentModel && !hasDefaultModel && owner?.model === undefined) {
|
|
919
|
+
const legacy = resolveLegacyBaseagentModelSelection(backend);
|
|
920
|
+
if (legacy) {
|
|
921
|
+
next.model = legacy.model;
|
|
922
|
+
migrated.push(`baseagents.${backend}.model from ${legacy.source}`);
|
|
923
|
+
summary.legacyModelsRestored += 1;
|
|
924
|
+
if (!block.effort && owner?.effort === undefined && legacy.effort) {
|
|
925
|
+
next.effort = legacy.effort;
|
|
926
|
+
migrated.push(`baseagents.${backend}.effort from ${legacy.source}`);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
if (Object.keys(next).length > 0)
|
|
931
|
+
nextBlocks[backend] = next;
|
|
932
|
+
}
|
|
933
|
+
if (migrated.length > 0) {
|
|
934
|
+
changes.push({ file: agentFile, kind: 'agent-only-model', before: parsed.text,
|
|
935
|
+
after: jsonText({ ...agent, baseagents: nextBlocks }) });
|
|
936
|
+
details.push({ file: path.relative(home, agentFile), removed: [], migrated });
|
|
937
|
+
summary.filesChanged += 1;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
catch {
|
|
943
|
+
// Do not replace unreadable Agent configuration with invented defaults.
|
|
944
|
+
}
|
|
945
|
+
}
|
|
661
946
|
for (const relationFile of walkRelationConfigs(path.join(agentsRoot, entry.name, 'relations'))) {
|
|
662
947
|
if (plan(relationFile, stripRelationModelFields).length > 0)
|
|
663
948
|
summary.relationFilesChanged += 1;
|
|
664
949
|
}
|
|
665
950
|
}
|
|
951
|
+
if (declaredBaseagents.size > 0) {
|
|
952
|
+
const pendingDefaults = changes.find(change => change.file === defaultsFile);
|
|
953
|
+
const original = fs.existsSync(defaultsFile) ? readJson(defaultsFile) : undefined;
|
|
954
|
+
const defaults = pendingDefaults ? JSON.parse(pendingDefaults.after) : original?.value;
|
|
955
|
+
if (defaults !== undefined && !isRecord(defaults)) {
|
|
956
|
+
throw new Error(`${defaultsFile}: defaults configuration must be an object`);
|
|
957
|
+
}
|
|
958
|
+
const value = defaults ? { ...defaults } : { $schema_version: 5 };
|
|
959
|
+
if (value.baseagents !== undefined && !isRecord(value.baseagents)) {
|
|
960
|
+
throw new Error(`${defaultsFile}: baseagents must be an object`);
|
|
961
|
+
}
|
|
962
|
+
const blocks = { ...(isRecord(value.baseagents) ? value.baseagents : {}) };
|
|
963
|
+
for (const name of [...declaredBaseagents].sort()) {
|
|
964
|
+
if (hasOwn(blocks, name))
|
|
965
|
+
continue;
|
|
966
|
+
blocks[name] = {};
|
|
967
|
+
summary.defaultsBaseagentsAdded += 1;
|
|
968
|
+
}
|
|
969
|
+
if (summary.defaultsBaseagentsAdded > 0) {
|
|
970
|
+
value.baseagents = blocks;
|
|
971
|
+
if (pendingDefaults)
|
|
972
|
+
pendingDefaults.after = jsonText(value);
|
|
973
|
+
else {
|
|
974
|
+
changes.push({ file: defaultsFile, kind: 'agent-only-model', before: original?.text ?? null, after: jsonText(value) });
|
|
975
|
+
details.push({ file: path.relative(home, defaultsFile), removed: [] });
|
|
976
|
+
summary.filesChanged += 1;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
666
980
|
return { home, changes, summary, details };
|
|
667
981
|
}
|
|
668
|
-
/**
|
|
982
|
+
/** Remove relation model parameters and register missing backend names in defaults. */
|
|
669
983
|
export function runAgentOnlyModelSchemaMigration(options = {}) {
|
|
670
984
|
const id = 'agent-only-model-v1';
|
|
671
985
|
const home = path.resolve(options.home || resolvePaths().root);
|
|
@@ -721,8 +1035,8 @@ const AGENT_BASEAGENT_REMOVED_FIELDS = [
|
|
|
721
1035
|
* response_modes(旧响应模式块)与 dispatch(旧广播开关)在现行实现里都没有消费者。
|
|
722
1036
|
*/
|
|
723
1037
|
const AGENT_TOP_REMOVED_FIELDS = ['model', 'models', 'decision_model', 'response_modes', 'dispatch'];
|
|
724
|
-
/**
|
|
725
|
-
const
|
|
1038
|
+
/** 剥离后内容与新版本 schema 等价的直接前驱版本。 */
|
|
1039
|
+
const AGENT_CONFIG_RESTAMP = { from: 13, to: 16 };
|
|
726
1040
|
const DEFAULTS_SCHEMA_TARGET = 5;
|
|
727
1041
|
/** 指认 provider 时各 baseagent 使用的服务类型。 */
|
|
728
1042
|
const BASEAGENT_SERVICE_TYPES = {
|
|
@@ -977,9 +1291,9 @@ function planAgentModelProviderMigration(home) {
|
|
|
977
1291
|
if (isDefaults) {
|
|
978
1292
|
value.$schema_version = DEFAULTS_SCHEMA_TARGET;
|
|
979
1293
|
}
|
|
980
|
-
else if (typeof value.$schema_version === 'number' && value.$schema_version <
|
|
981
|
-
//
|
|
982
|
-
value.$schema_version =
|
|
1294
|
+
else if (typeof value.$schema_version === 'number' && value.$schema_version < AGENT_CONFIG_RESTAMP.to) {
|
|
1295
|
+
// Model/provider migration preserves the v16 admission fields unchanged.
|
|
1296
|
+
value.$schema_version = AGENT_CONFIG_RESTAMP.to;
|
|
983
1297
|
}
|
|
984
1298
|
summary.gatewayFieldsRemoved += removed.length;
|
|
985
1299
|
const nextText = jsonText(value);
|
package/dist/config-store.js
CHANGED
|
@@ -24,7 +24,7 @@ import { checkAgentDir, isValidAid } from './aun/aid/validation.js';
|
|
|
24
24
|
import { normalizeAidDomain } from './aun/aid/domain.js';
|
|
25
25
|
import { isValidChannelName } from './core/channel-loader.js';
|
|
26
26
|
import { CONFIG_SCHEMA_VERSION } from './types.js';
|
|
27
|
-
import { ConfigTarget, assertNoLegacyAunGatewayConfig, read as cfgRead, normalizeProcessConfigCompat, stripLegacyAunGatewayConfig, write as cfgWrite, } from './config/config-manager.js';
|
|
27
|
+
import { ConfigTarget, assertAgentAidAvailable, assertControlAidAvailable, assertNoLegacyAunGatewayConfig, read as cfgRead, normalizeProcessConfigCompat, stripLegacyAunGatewayConfig, write as cfgWrite, } from './config/config-manager.js';
|
|
28
28
|
import { expandVars, buildEnvResolver } from './config/merge.js';
|
|
29
29
|
import { isAgentLifecycle } from './config/lifecycle.js';
|
|
30
30
|
import { logger } from './utils/logger.js';
|
|
@@ -99,6 +99,7 @@ export function isEckSnapshotsEnabled() {
|
|
|
99
99
|
export function saveDaemonConfig(value) {
|
|
100
100
|
const configPath = resolvePaths().daemonConfig;
|
|
101
101
|
assertNoLegacyAunGatewayConfig(value, configPath);
|
|
102
|
+
assertControlAidAvailable(value.aid);
|
|
102
103
|
const current = atomicReadJson(configPath);
|
|
103
104
|
// A legacy default is irrelevant while an existing control AID is retained.
|
|
104
105
|
// Validate the field when it is created or changed, but do not make unrelated
|
|
@@ -568,6 +569,14 @@ export function validateAgentConfig(cfg) {
|
|
|
568
569
|
const errs = [];
|
|
569
570
|
if (!cfg.aid || !isValidAid(cfg.aid))
|
|
570
571
|
errs.push(`invalid aid: ${cfg.aid}`);
|
|
572
|
+
else {
|
|
573
|
+
try {
|
|
574
|
+
assertAgentAidAvailable(cfg.aid);
|
|
575
|
+
}
|
|
576
|
+
catch (error) {
|
|
577
|
+
errs.push(`CONTROL_AID_RESERVED: ${error instanceof Error ? error.message : String(error)}`);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
571
580
|
if (cfg.active_baseagent !== undefined && !isSupportedBaseagent(cfg.active_baseagent)) {
|
|
572
581
|
errs.push(`unsupported active_baseagent: ${cfg.active_baseagent} (choose claude/codex/gemini/ecagent)`);
|
|
573
582
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export const ECWEB_SERVICE_PROTOCOL = Object.freeze({
|
|
2
2
|
name: 'evolcore.ecweb',
|
|
3
3
|
major: 1,
|
|
4
|
-
minor:
|
|
4
|
+
minor: 4,
|
|
5
5
|
capabilities: Object.freeze([
|
|
6
6
|
'daemon.status',
|
|
7
7
|
'agent.directory',
|
|
8
8
|
'aun.directory',
|
|
9
9
|
'menu.execute',
|
|
10
10
|
'provider.management',
|
|
11
|
+
'initialization',
|
|
11
12
|
'basic-settings',
|
|
12
13
|
'model.catalog',
|
|
13
14
|
'baseagent.snapshot',
|