evolcore 0.0.48 → 0.0.49
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 +34 -0
- package/dist/agent-template/runtime.js +5 -2
- package/dist/agents/codex-runner.js +5 -1
- package/dist/aun/msg/p2p.js +2 -1
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +643 -273
- package/dist/cli/directory.js +6 -1
- package/dist/cli/index.js +7 -1
- package/dist/cli/managed-command-guard.js +2 -0
- package/dist/cli/model.js +20 -5
- package/dist/cli/quota.js +89 -0
- package/dist/cli/role.js +1 -0
- package/dist/cli/services-command.js +1 -0
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/config/config-field-policy.js +71 -1
- package/dist/config/config-manager.js +11 -1
- package/dist/config/providers-config.js +8 -4
- package/dist/config/providers-management.js +11 -3
- package/dist/config/resolved-config-op.js +3 -2
- package/dist/core/auth/delegation-authorization.js +33 -26
- package/dist/core/auth/operation-catalog.js +9 -0
- package/dist/core/command/cli-intent-parser.js +13 -0
- package/dist/core/command/command-handler.js +45 -2
- package/dist/core/command/menu-handler.js +6 -1
- package/dist/core/command/menu-protocol.js +24 -0
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/daemon-control.js +57 -1
- package/dist/core/daemon-lifecycle.js +16 -2
- package/dist/core/evolagent-registry.js +6 -2
- package/dist/core/ipc-registration.js +1 -0
- package/dist/core/message/aun-ipc-sender.js +118 -56
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +40 -1
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +92 -39
- package/dist/core/message/message-log.js +24 -0
- package/dist/core/message/message-queue.js +97 -15
- package/dist/core/message/response-engine.js +151 -18
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/pack-auth.js +3 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +106 -19
- package/dist/core/permission/services-path-acl.js +451 -0
- package/dist/core/permission/tool-policy.js +5 -1
- package/dist/core/relation/peer-identity.js +13 -0
- package/dist/core/task/task-recovery-service.js +1 -0
- package/dist/core/thread/topic-id.js +15 -0
- package/dist/directory/owner-directory-admission.js +11 -8
- package/dist/directory/owner-directory-cache.js +19 -0
- package/dist/directory/owner-directory-markdown.js +1 -1
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/message-renderer.js +28 -5
- package/dist/ecweb/runtime/supervisor.js +36 -8
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +20 -5
- package/dist/event-center/runtime.js +10 -7
- package/dist/index.js +4 -0
- package/dist/ipc.js +25 -1
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +3 -2
- package/dist/outputs/protocol.js +1 -0
- package/dist/outputs/service.js +2 -15
- package/dist/services/index.js +29 -5
- package/dist/services/ipc-operation.js +84 -0
- package/dist/services/pack-manager.js +1 -0
- package/dist/services/service-payload.js +13 -7
- package/dist/stats/budget.js +1 -1
- package/dist/stats/model-resolver.js +2 -2
- package/dist/stats/quota-query.js +95 -0
- package/dist/trigger/script-sandbox.js +12 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +100 -1
- package/dist/utils/npm-ops.js +43 -8
- package/dist/workbench/service.js +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -0
- package/kits/docs/evolcore/aid.md +25 -0
- package/kits/docs/evolcore/config.md +4 -1
- package/kits/docs/evolcore/directory.md +8 -9
- package/kits/docs/evolcore/msg.md +9 -0
- package/kits/docs/evolcore/provider.md +1 -1
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +3 -0
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/trigger.md +2 -0
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/agent-output-cards/SKILL.md +57 -0
- package/kits/skills/ec-provider/SKILL.md +57 -8
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/commands.md +1 -0
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/thread.md +1 -0
- package/kits/templates/system-fragments/venue.md +11 -0
- package/package.json +2 -2
- package/scripts/agent-template/inspect.mjs +46 -10
- package/scripts/agent-template/shared/common.mjs +9 -3
- package/scripts/agent-template/shared/team-schema.json +6 -4
- package/scripts/agent-template/shared/template-contract.mjs +60 -10
- package/scripts/agent-template/shared/template-package.mjs +182 -21
- package/scripts/agent-template/shared/template-runtime.mjs +35 -2
- package/scripts/agent-template/shared/template.mjs +2 -2
- package/scripts/agent-template/team-pack.mjs +46 -11
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
+
import { resolveMemberParameters } from './template-runtime.mjs';
|
|
3
4
|
|
|
4
5
|
export const TEAM_SCHEMA_VERSION = 1;
|
|
5
6
|
export const PACKAGE_SCHEMA_VERSION = 1;
|
|
@@ -21,7 +22,7 @@ const members = item => ({ type: 'object', minProperties: 1, propertyNames: { pa
|
|
|
21
22
|
const jobId = { ...string, pattern: '^job_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' };
|
|
22
23
|
const location = object({ aid, path: { ...string, pattern: '^/[^\\\\\\u0000]*$' } });
|
|
23
24
|
const metadata = object({
|
|
24
|
-
id: schema.properties.
|
|
25
|
+
id: schema.properties.id, name: { type: 'string', minLength: 1, maxLength: 64 },
|
|
25
26
|
version: schema.properties.version, description: schema.properties.description,
|
|
26
27
|
platforms: schema.properties.host.properties.platform,
|
|
27
28
|
}, ['id', 'name', 'version', 'platforms']);
|
|
@@ -32,7 +33,7 @@ const source = { oneOf: [
|
|
|
32
33
|
object({ kind: { const: 'remote' }, location,
|
|
33
34
|
download: object({ shareId: { ...string, pattern: '^[A-Za-z0-9]{10}$' } }, []), digest }, ['kind', 'location', 'digest']),
|
|
34
35
|
] };
|
|
35
|
-
const include = object({ baseagents: strings, triggers: strings, skills: strings, files: strings });
|
|
36
|
+
const include = object({ baseagents: strings, triggers: strings, skills: strings, files: strings, events: strings }, ['baseagents', 'triggers', 'skills', 'files']);
|
|
36
37
|
const provider = object({ provider: string, model: string, effort: { type: ['string', 'null'], minLength: 1 } }, ['provider', 'model']);
|
|
37
38
|
const selection = object({
|
|
38
39
|
target: object({ aid: { oneOf: [aid, { const: 'auto' }] }, project: string }),
|
|
@@ -44,7 +45,10 @@ const inputSchemas = {
|
|
|
44
45
|
object({ kind: { const: 'agent' }, aid }),
|
|
45
46
|
object({ kind: { const: 'directory' }, path: string }),
|
|
46
47
|
] } })) }),
|
|
47
|
-
build: object({ inspectionJobId: jobId, inventoryDigest: digest, metadata, members: members(object({ include
|
|
48
|
+
build: object({ inspectionJobId: jobId, inventoryDigest: digest, metadata, members: members(object({ include,
|
|
49
|
+
version: schema.properties.agents.items.properties.version,
|
|
50
|
+
update: schema.properties.agents.items.properties.update,
|
|
51
|
+
}, ['include'])) }),
|
|
48
52
|
push: object({ packageId: string, location, releasedFindings: strings }),
|
|
49
53
|
pull: object({ source }),
|
|
50
54
|
preview: object({ packageId: string, installMode: { enum: ['create', 'overwrite'] }, members: members(selection), issuer: aid }, ['packageId', 'installMode', 'members']),
|
|
@@ -57,7 +61,7 @@ const inputSchemas = {
|
|
|
57
61
|
export const readTemplateInputSchemas = () => structuredClone(inputSchemas);
|
|
58
62
|
export const packageSchema = object({
|
|
59
63
|
$schema_version: { const: PACKAGE_SCHEMA_VERSION },
|
|
60
|
-
id: schema.properties.
|
|
64
|
+
id: schema.properties.id, name: { type: 'string', minLength: 1, maxLength: 64 }, version: schema.properties.version,
|
|
61
65
|
description: schema.properties.description, publisher: { type: 'object' }, createdAt: { type: 'number', minimum: 0 },
|
|
62
66
|
compat: object({ platforms: schema.properties.host.properties.platform, evolcore: string, baseagents: strings, templateFeatures: strings }, ['platforms', 'evolcore', 'baseagents']),
|
|
63
67
|
externalAids: { ...strings, items: aid },
|
|
@@ -96,6 +100,15 @@ export function canonicalJson(value) {
|
|
|
96
100
|
}
|
|
97
101
|
export const contractDigest = value => 'sha256:' + createHash('sha256').update(canonicalJson(value)).digest('hex');
|
|
98
102
|
|
|
103
|
+
/** Explicit target build environment only; never reads the builder's daemon or environment. */
|
|
104
|
+
export function resolveTemplateAidDomain(team) {
|
|
105
|
+
const configured = team.host?.config?.aun?.defaultAidDomain;
|
|
106
|
+
const value = configured === undefined ? 'agentid.cn' : configured;
|
|
107
|
+
const errors = validateContractSchema(value, schema.properties.host.properties.config.properties.aun.properties.defaultAidDomain);
|
|
108
|
+
if (errors.length) throw contractError('INVALID_ARGUMENT', 'host.config.aun.defaultAidDomain: ' + errors.join('; '));
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
|
|
99
112
|
export function normalizeTeamSchema(local = {}) {
|
|
100
113
|
if (!record(local) || local.type !== 'object') throw new Error('team.schema.json must be a JSON Schema object');
|
|
101
114
|
const merge = (base, custom) => {
|
|
@@ -116,6 +129,21 @@ export function normalizeTeamSchema(local = {}) {
|
|
|
116
129
|
out.properties.$schema_version = structuredClone(schema.properties.$schema_version);
|
|
117
130
|
out.properties.version = structuredClone(schema.properties.version);
|
|
118
131
|
out.properties.host.properties.platform = structuredClone(schema.properties.host.properties.platform);
|
|
132
|
+
out.properties.name.readOnly = true;
|
|
133
|
+
out.properties.name['x-aliasOf'] = 'id';
|
|
134
|
+
// Old custom forms may constrain/require issuer; carry those constraints to its canonical location.
|
|
135
|
+
const legacyDomain = local.properties?.issuer;
|
|
136
|
+
if (record(legacyDomain) || local.required?.includes('issuer')) {
|
|
137
|
+
const domain = out.properties.host.properties.config.properties.aun;
|
|
138
|
+
if (record(legacyDomain)) domain.properties.defaultAidDomain = merge(domain.properties.defaultAidDomain, legacyDomain);
|
|
139
|
+
if (local.required?.includes('issuer')) {
|
|
140
|
+
out.properties.host.required = [...new Set([...(out.properties.host.required ?? []), 'config'])];
|
|
141
|
+
out.properties.host.properties.config.required = [...new Set([...(out.properties.host.properties.config.required ?? []), 'aun'])];
|
|
142
|
+
domain.required = [...new Set([...(domain.required ?? []), 'defaultAidDomain'])];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
delete out.properties.issuer;
|
|
146
|
+
out.required = out.required.filter(key => key !== 'issuer');
|
|
119
147
|
const member = out.properties.agents.items;
|
|
120
148
|
const original = local.properties?.agents?.items?.properties ?? {};
|
|
121
149
|
for (const key of ['name', 'description']) {
|
|
@@ -189,10 +217,13 @@ export function normalizeTeam(input, { fallbackName, packageInfo } = {}) {
|
|
|
189
217
|
const team = structuredClone(input);
|
|
190
218
|
const change = (field, message) => changes.push({ field, message });
|
|
191
219
|
if (legacy) { team.$schema_version = TEAM_SCHEMA_VERSION; change('$schema_version', 'Legacy declaration normalized to v1'); }
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
team.name = team.name.trim(); change('name', 'Trimmed identifier whitespace');
|
|
220
|
+
for (const key of ['id', 'name']) if (typeof team[key] === 'string' && team[key] !== team[key].trim()) {
|
|
221
|
+
team[key] = team[key].trim(); change(key, 'Trimmed identifier whitespace');
|
|
195
222
|
}
|
|
223
|
+
if (team.id === undefined && team.name === undefined && fallbackName) { team.name = fallbackName; change('name', 'Use template directory identifier'); }
|
|
224
|
+
if (team.id === undefined && team.name !== undefined) { team.id = team.name; change('id', 'Use compatible name identifier'); }
|
|
225
|
+
if (team.name === undefined && team.id !== undefined) { team.name = team.id; change('name', 'Preserve compatible name identifier'); }
|
|
226
|
+
if (team.id !== undefined && team.name !== undefined && team.id !== team.name) errors.push('team.id: conflicts with team.name');
|
|
196
227
|
if (legacy) {
|
|
197
228
|
const oldVersion = team.version;
|
|
198
229
|
if (oldVersion === undefined) team.version = '1.0.0';
|
|
@@ -207,9 +238,28 @@ export function normalizeTeam(input, { fallbackName, packageInfo } = {}) {
|
|
|
207
238
|
else if (typeof team.host.platform === 'string') { team.host.platform = [team.host.platform]; change('host.platform', 'Converted legacy platform string to list'); }
|
|
208
239
|
}
|
|
209
240
|
}
|
|
241
|
+
const aun = team.host?.config?.aun;
|
|
242
|
+
if (record(aun) && typeof aun.defaultAidDomain === 'string') {
|
|
243
|
+
const value = aun.defaultAidDomain.trim().toLowerCase();
|
|
244
|
+
if (value !== aun.defaultAidDomain) { aun.defaultAidDomain = value; change('host.config.aun.defaultAidDomain', 'Normalized AID domain'); }
|
|
245
|
+
}
|
|
246
|
+
if (own(team, 'issuer')) {
|
|
247
|
+
const issuer = typeof team.issuer === 'string' ? team.issuer.trim().toLowerCase() : team.issuer;
|
|
248
|
+
const domainRule = schema.properties.host.properties.config.properties.aun.properties.defaultAidDomain;
|
|
249
|
+
errors.push(...validateContractSchema(issuer, domainRule, 'team.issuer'));
|
|
250
|
+
if (aun?.defaultAidDomain !== undefined && aun.defaultAidDomain !== issuer) errors.push('team.issuer: conflicts with host.config.aun.defaultAidDomain');
|
|
251
|
+
if (record(team.host) && (team.host.config === undefined || record(team.host.config))
|
|
252
|
+
&& (team.host.config?.aun === undefined || record(team.host.config.aun))) {
|
|
253
|
+
team.host.config ??= {}; team.host.config.aun ??= {};
|
|
254
|
+
team.host.config.aun.defaultAidDomain ??= issuer;
|
|
255
|
+
}
|
|
256
|
+
delete team.issuer;
|
|
257
|
+
change('issuer', 'Use host.config.aun.defaultAidDomain');
|
|
258
|
+
}
|
|
210
259
|
if (Array.isArray(team.agents)) team.agents.forEach((agent, i) => {
|
|
211
260
|
if (!record(agent)) return;
|
|
212
261
|
const prefix = `agents[${i}]`;
|
|
262
|
+
try { resolveMemberParameters(agent); } catch (error) { errors.push(prefix + ': ' + error.message); }
|
|
213
263
|
if (agent.profile !== undefined && !record(agent.profile)) { errors.push(`${prefix}.profile: object required`); return; }
|
|
214
264
|
if (legacy && agent.profile === undefined) agent.profile = {};
|
|
215
265
|
if (!record(agent.profile)) return;
|
|
@@ -241,13 +291,13 @@ export function normalizeTeam(input, { fallbackName, packageInfo } = {}) {
|
|
|
241
291
|
if (Number.isInteger(team.personal_assistant) && team.personal_assistant >= team.agents.length) errors.push('personal_assistant: index outside agents');
|
|
242
292
|
}
|
|
243
293
|
if (packageInfo) {
|
|
244
|
-
if (team.
|
|
294
|
+
if (team.id !== packageInfo.id) errors.push('team.id: differs from PACKAGE.id');
|
|
245
295
|
if (team.version !== packageInfo.version || !versionPattern.test(packageInfo.version)) errors.push('team.version: differs from PACKAGE.version');
|
|
246
296
|
if (team.title !== undefined && team.title !== packageInfo.name) errors.push('team.title: differs from PACKAGE.name');
|
|
247
297
|
if (team.description !== undefined && team.description !== packageInfo.description) errors.push('team.description: differs from PACKAGE.description');
|
|
248
298
|
}
|
|
249
299
|
return { ...(errors.length ? {} : { team }), errors, changes,
|
|
250
|
-
metadata: { id: team.
|
|
300
|
+
metadata: { id: team.id, name: team.title ?? packageInfo?.name ?? team.id, version: team.version } };
|
|
251
301
|
}
|
|
252
302
|
|
|
253
303
|
/** Internal index; public declarations and manifests continue to use agents[]. */
|
|
@@ -300,7 +350,7 @@ export function validateBuildSelection(inventory, args) {
|
|
|
300
350
|
if (args.metadata.platforms.some(platform => !inventory.platforms.includes(platform))) throw contractError('INCOMPATIBLE', 'No common selected platform');
|
|
301
351
|
for (const key of keys) {
|
|
302
352
|
const member = inventory.members[key];
|
|
303
|
-
for (const [kind, chosen] of Object.entries(args.members[key].include)) if (chosen.some(item => !member.resources[kind].includes(item))) throw contractError('INVALID_ARGUMENT', 'Selection outside inventory', { memberKey: key, kind });
|
|
353
|
+
for (const [kind, chosen] of Object.entries(args.members[key].include)) if (chosen.some(item => !(member.resources[kind] ?? []).includes(item))) throw contractError('INVALID_ARGUMENT', 'Selection outside inventory', { memberKey: key, kind });
|
|
304
354
|
if (!args.members[key].include.baseagents.includes(member.defaultBaseagent)) throw contractError('INVALID_ARGUMENT', 'Default baseagent is required', { memberKey: key });
|
|
305
355
|
}
|
|
306
356
|
}
|
|
@@ -4,8 +4,12 @@ import path from 'node:path';
|
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
5
5
|
import { gzipSync, gunzipSync } from 'node:zlib';
|
|
6
6
|
import { loadTemplate } from './template.mjs';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { resolveTemplateAidDomain } from './template-contract.mjs';
|
|
8
|
+
import { AID_PATTERN, normalizeTeam, normalizeTeamSchema, validateContractSchema, readTeamSchema, packageSchema, contractDigest, canonicalJson, validateBuildSelection } from './template-contract.mjs';
|
|
9
|
+
import { BASEAGENTS, assertPublicTemplateConfig, resolveMemberParameters } from './template-runtime.mjs';
|
|
10
|
+
import { validatePackJson } from '../../../dist/event-center/validation.js';
|
|
11
|
+
import { PACK_RUNTIME_ENTRIES } from '../../../dist/core/pack-install.js';
|
|
12
|
+
import { assert, inside, readJson, regularPath, sha256, walkFiles } from './common.mjs';
|
|
9
13
|
|
|
10
14
|
export const PACKAGE_LIMITS = { file: 20 * 1024 * 1024, total: 200 * 1024 * 1024, entries: 20000 };
|
|
11
15
|
const record = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -34,6 +38,80 @@ export function excludedResource(name) {
|
|
|
34
38
|
|| /^\.env/.test(part) || /\.(?:pem|key|db(?:[-.].*)?)$/i.test(part));
|
|
35
39
|
}
|
|
36
40
|
|
|
41
|
+
/** References live in string literals and comments; bare property chains are not identities. */
|
|
42
|
+
function scriptReferenceText(text) {
|
|
43
|
+
const contexts = [{ quote: '', depth: 0, regexAllowed: true, parens: [], control: false }]; let out = '';
|
|
44
|
+
for (let i = 0; i < text.length; i++) {
|
|
45
|
+
const context = contexts.at(-1); const char = text[i]; const next = text[i + 1];
|
|
46
|
+
if (context.quote) {
|
|
47
|
+
if (char === '\\') { out += char + (next ?? ''); i++; }
|
|
48
|
+
else if (char === context.quote) { contexts.pop(); contexts.at(-1).regexAllowed = false; out += '\n'; }
|
|
49
|
+
else if (context.quote === '`' && char === '$' && next === '{') {
|
|
50
|
+
contexts.push({ quote: '', depth: 1, regexAllowed: true, parens: [], control: false }); out += '\n'; i++;
|
|
51
|
+
} else out += char;
|
|
52
|
+
} else if (char === '/' && next === '/') {
|
|
53
|
+
const end = text.indexOf('\n', i + 2);
|
|
54
|
+
out += '\n' + text.slice(i + 2, end < 0 ? text.length : end) + '\n'; i = end < 0 ? text.length : end;
|
|
55
|
+
} else if (char === '/' && next === '*') {
|
|
56
|
+
const end = text.indexOf('*/', i + 2);
|
|
57
|
+
out += '\n' + text.slice(i + 2, end < 0 ? text.length : end) + '\n'; i = end < 0 ? text.length : end + 1;
|
|
58
|
+
} else if (char === '/' && context.regexAllowed) {
|
|
59
|
+
let bracket = false; let end = i + 1;
|
|
60
|
+
for (; end < text.length && !/[\r\n]/.test(text[end]); end++) {
|
|
61
|
+
if (text[end] === '\\') end++;
|
|
62
|
+
else if (text[end] === '[') bracket = true;
|
|
63
|
+
else if (text[end] === ']') bracket = false;
|
|
64
|
+
else if (text[end] === '/' && !bracket) break;
|
|
65
|
+
}
|
|
66
|
+
if (text[end] === '/') { i = end; context.regexAllowed = false; }
|
|
67
|
+
} else if (['"', "'", '`'].includes(char)) {
|
|
68
|
+
contexts.push({ quote: char, depth: 0, regexAllowed: false }); out += '\n';
|
|
69
|
+
} else if (/[a-zA-Z0-9_$]/.test(char)) {
|
|
70
|
+
const start = i;
|
|
71
|
+
while (/[a-zA-Z0-9_$]/.test(text[i + 1] ?? '')) i++;
|
|
72
|
+
const word = text.slice(start, i + 1);
|
|
73
|
+
context.control = /^(?:if|while|for|with|switch|catch)$/.test(word);
|
|
74
|
+
context.regexAllowed = /^(?:return|throw|case|delete|void|typeof|new|in|instanceof|yield|await|else|do)$/.test(word);
|
|
75
|
+
} else if (!/\s/.test(char)) {
|
|
76
|
+
if (context.depth && char === '{') context.depth++;
|
|
77
|
+
else if (context.depth && char === '}' && --context.depth === 0) { contexts.pop(); out += '\n'; }
|
|
78
|
+
if (char === '(') context.parens.push(context.control);
|
|
79
|
+
context.regexAllowed = char === ')' ? context.parens.pop() === true : ![']', '}', '.'].includes(char);
|
|
80
|
+
context.control = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const aidPattern = new RegExp(AID_PATTERN);
|
|
87
|
+
function extractExternalAids(text, name) {
|
|
88
|
+
if (name === 'template/team.json') {
|
|
89
|
+
const team = JSON.parse(text);
|
|
90
|
+
for (const member of team.agents ?? []) {
|
|
91
|
+
delete member.update;
|
|
92
|
+
if (record(member.config)) delete member.config.update;
|
|
93
|
+
}
|
|
94
|
+
text = JSON.stringify(team);
|
|
95
|
+
}
|
|
96
|
+
let references = /\.(?:[cm]?[jt]s|jsx|tsx)$/i.test(name) ? scriptReferenceText(text) : text;
|
|
97
|
+
if (/\.(?:md|markdown|mdx)$/i.test(name)) {
|
|
98
|
+
references = references.replace(/^([ \t]*)(`{3,}|~{3,})[ \t]*(?:[cm]?[jt]s|javascript|typescript|jsx|tsx)\b[^\n]*\n([\s\S]*?)^\1\2[ \t]*\r?$/gim,
|
|
99
|
+
(_match, _indent, _fence, script) => '\n' + scriptReferenceText(script) + '\n');
|
|
100
|
+
}
|
|
101
|
+
references = references.replace(/<script\b[^>]*>([\s\S]*?)<\/script\s*>/gi,
|
|
102
|
+
(_match, script) => '\n' + scriptReferenceText(script) + '\n');
|
|
103
|
+
// Mask each URL/placeholder occurrence so an independent AID on the same line survives.
|
|
104
|
+
references = references.replace(/\{\{[\s\S]*?\}\}|[a-z][a-z0-9+.-]*:\/\/[^\s"'`<>]+/gi, '\n');
|
|
105
|
+
// Consume entire dotted tokens, including invalid JS identifier characters, before validation.
|
|
106
|
+
const candidates = [...references.matchAll(/(?<![a-zA-Z0-9_$.-])[a-zA-Z0-9_$-]+(?:\.[a-zA-Z0-9_$-]+){2,}(?![a-zA-Z0-9_$-]|\.[a-zA-Z0-9_$-])/g)];
|
|
107
|
+
return candidates.filter(match => {
|
|
108
|
+
const aid = match[0];
|
|
109
|
+
return aidPattern.test(aid) && /\.[a-z]{2,}$/.test(aid)
|
|
110
|
+
&& !/\.(?:[cm]?[jt]sx?|json|html|css)$/.test(aid) && !aid.startsWith('www.')
|
|
111
|
+
&& !/^\s*\(/.test(references.slice(match.index + aid.length));
|
|
112
|
+
}).map(match => match[0]);
|
|
113
|
+
}
|
|
114
|
+
|
|
37
115
|
/** Ordered USTAR+gzip, compatible with EvolCore archive(). */
|
|
38
116
|
export function encodePackageEntries(entries) {
|
|
39
117
|
check(entries instanceof Map && entries.size && entries.size <= PACKAGE_LIMITS.entries, 'Invalid package entries');
|
|
@@ -97,7 +175,8 @@ function portableFile(name, keys) {
|
|
|
97
175
|
const relative = rest.join('/');
|
|
98
176
|
return group === 'workspace' && !excludedResource(relative)
|
|
99
177
|
|| group === 'agents' && (relative.startsWith('personal/soul/') && relative.endsWith('.md') && !relative.endsWith('/00-GUIDE.md')
|
|
100
|
-
|| relative === 'personal/welcome.md' || relative.startsWith('triggers/') && !excludedResource(relative)
|
|
178
|
+
|| relative === 'personal/welcome.md' || relative.startsWith('triggers/') && !excludedResource(relative)
|
|
179
|
+
|| isPortableEventPackFile(relative) && !excludedResource(relative));
|
|
101
180
|
}
|
|
102
181
|
|
|
103
182
|
/** Validate all bytes before extracting; never trusts a MANIFEST path for filesystem access. */
|
|
@@ -107,7 +186,8 @@ export function inspectTemplatePackage(bytes, { digest } = {}) {
|
|
|
107
186
|
const entries = decodePackageEntries(bytes);
|
|
108
187
|
const read = name => { check(entries.has(name), 'Missing package entry: ' + name, 'INTEGRITY_FAILED'); return JSON.parse(entries.get(name).bytes.toString('utf8')); };
|
|
109
188
|
const metadata = read('PACKAGE.json'); const manifest = read('MANIFEST.json');
|
|
110
|
-
|
|
189
|
+
const metadataErrors = validateContractSchema(metadata, packageSchema);
|
|
190
|
+
check(!metadataErrors.length, 'Invalid package metadata: ' + metadataErrors.join('; '), 'INTEGRITY_FAILED');
|
|
111
191
|
check(Array.isArray(manifest) && manifest.length && entries.size === manifest.length + 2, 'Invalid manifest', 'INTEGRITY_FAILED');
|
|
112
192
|
const seen = new Set();
|
|
113
193
|
for (const entry of manifest) {
|
|
@@ -124,6 +204,8 @@ export function inspectTemplatePackage(bytes, { digest } = {}) {
|
|
|
124
204
|
check(!errors.length, errors.join('; '));
|
|
125
205
|
const keys = team.agents.map(agent => agent.key);
|
|
126
206
|
for (const { path: name } of manifest) check(portableFile(name, keys), 'Unsupported portable resource: ' + name);
|
|
207
|
+
validateEventPackEntries(new Map([...entries].filter(([name]) => name.startsWith('template/'))
|
|
208
|
+
.map(([name, entry]) => [name.slice('template/'.length), entry])), keys);
|
|
127
209
|
return { metadata, team, schema, entries, digest: actual, changes: normalized.changes,
|
|
128
210
|
resources: manifest.map(({ path: name, size }) => ({ path: name, size })) };
|
|
129
211
|
}
|
|
@@ -142,6 +224,7 @@ export function collectTemplateDirectory(templateDir, memberKey) {
|
|
|
142
224
|
const defaults = readOptional('.evolcore/agents/defaults.json');
|
|
143
225
|
const providers = readOptional('.evolcore/providers.json').providers ?? {};
|
|
144
226
|
const member = structuredClone(tpl.team.agents.find(agent => agent.key === memberKey));
|
|
227
|
+
Object.assign(member, resolveMemberParameters(member));
|
|
145
228
|
const source = { ...structuredClone(defaults), ...member.config,
|
|
146
229
|
baseagents: { ...defaults.baseagents, ...member.config?.baseagents } };
|
|
147
230
|
const config = {};
|
|
@@ -156,7 +239,8 @@ export function collectTemplateDirectory(templateDir, memberKey) {
|
|
|
156
239
|
for (const field of ['model', 'effort', 'params']) if (block[field] !== undefined) config.baseagents[name][field] = structuredClone(block[field]);
|
|
157
240
|
}
|
|
158
241
|
check(config.baseagents[config.active_baseagent], 'Default baseagent must have a binding: ' + memberKey);
|
|
159
|
-
for (const field of Object.keys(member.config ?? {})) if (!Object.hasOwn(config, field)
|
|
242
|
+
for (const field of Object.keys(member.config ?? {})) if (!Object.hasOwn(config, field)
|
|
243
|
+
&& !['version', 'update'].includes(field)) excluded.push('members/' + memberKey + '/config/' + field);
|
|
160
244
|
member.config = config;
|
|
161
245
|
const entries = new Map(); const snapshot = [];
|
|
162
246
|
for (const relative of tpl.files) {
|
|
@@ -168,22 +252,23 @@ export function collectTemplateDirectory(templateDir, memberKey) {
|
|
|
168
252
|
if (!portableFile(name, [memberKey])) { excluded.push(name); continue; }
|
|
169
253
|
entries.set(name, { bytes, mode: stat.mode & 0o777 });
|
|
170
254
|
}
|
|
171
|
-
const resources = { baseagents: Object.keys(config.baseagents).sort(), triggers: [], skills: [], files: [] };
|
|
255
|
+
const resources = { baseagents: Object.keys(config.baseagents).sort(), triggers: [], events: [], skills: [], files: [] };
|
|
172
256
|
for (const name of entries.keys()) {
|
|
173
257
|
if (name.startsWith('workspace/' + memberKey + '/')) resources.files.push(name.slice(('workspace/' + memberKey + '/').length));
|
|
174
258
|
if (name.startsWith('agents/' + memberKey + '/triggers/')) resources.triggers.push(name.split('/')[3]);
|
|
259
|
+
if (name.startsWith('agents/' + memberKey + '/events/')) resources.events.push(name.split('/')[3]);
|
|
175
260
|
if (name.startsWith('.evolcore/skills/')) resources.skills.push(name.split('/')[2]);
|
|
176
261
|
}
|
|
177
262
|
resources.skills.push(...Object.keys(member.skills ?? {}));
|
|
178
263
|
for (const kind of Object.keys(resources)) resources[kind] = [...new Set(resources[kind])].sort();
|
|
179
264
|
return { member, entries, excluded, platforms: [...tpl.team.host.platform].sort(),
|
|
180
|
-
sourceDigest: contractDigest({ snapshot, member, metadata: { name: tpl.team.
|
|
265
|
+
sourceDigest: contractDigest({ snapshot, member, metadata: { name: tpl.team.id, version: tpl.team.version } }), resources,
|
|
181
266
|
defaultBaseagent: config.active_baseagent, warnings: [] };
|
|
182
267
|
}
|
|
183
268
|
|
|
184
269
|
/** One pure package planner for both runtime-agent and directory collection adapters. */
|
|
185
270
|
export function buildTemplatePackage({ metadata, members, externalAids = [], publisher, createdAt, evolcoreRange = '>=0.0.43-test.8' }) {
|
|
186
|
-
const team = { $schema_version: 1, name: metadata.id, title: metadata.name, version: metadata.version,
|
|
271
|
+
const team = { $schema_version: 1, id: metadata.id, name: metadata.id, title: metadata.name, version: metadata.version,
|
|
187
272
|
...(metadata.description !== undefined ? { description: metadata.description } : {}), host: { platform: structuredClone(metadata.platforms) }, agents: [] };
|
|
188
273
|
const entries = new Map(); const excluded = []; const external = new Set(externalAids);
|
|
189
274
|
for (const [key, collected] of Object.entries(members)) {
|
|
@@ -191,7 +276,9 @@ export function buildTemplatePackage({ metadata, members, externalAids = [], pub
|
|
|
191
276
|
check(record(member) && record(include), 'Collected member and selection required');
|
|
192
277
|
check(include.baseagents.includes(member.config?.active_baseagent), 'Default baseagent is required: ' + key);
|
|
193
278
|
const chosen = structuredClone(member);
|
|
279
|
+
Object.assign(chosen, resolveMemberParameters(chosen));
|
|
194
280
|
assertPublicTemplateConfig(chosen.config);
|
|
281
|
+
for (const field of ['version', 'update']) delete chosen.config[field];
|
|
195
282
|
chosen.config.baseagents = Object.fromEntries(Object.entries(chosen.config.baseagents).filter(([name]) => include.baseagents.includes(name)));
|
|
196
283
|
chosen.skills = Object.fromEntries(Object.entries(chosen.skills ?? {}).filter(([name]) => include.skills.includes(name)));
|
|
197
284
|
team.agents.push({ ...chosen, key });
|
|
@@ -201,7 +288,8 @@ export function buildTemplatePackage({ metadata, members, externalAids = [], pub
|
|
|
201
288
|
check(portableFile(name, [key]), 'Unsupported collected resource: ' + name);
|
|
202
289
|
const selected = name.startsWith('workspace/') ? include.files.includes(name.slice(('workspace/' + key + '/').length))
|
|
203
290
|
: name.startsWith('.evolcore/skills/') ? include.skills.includes(name.split('/')[2])
|
|
204
|
-
: name.startsWith('agents/' + key + '/triggers/') ? include.triggers.includes(name.split('/')[3])
|
|
291
|
+
: name.startsWith('agents/' + key + '/triggers/') ? include.triggers.includes(name.split('/')[3])
|
|
292
|
+
: name.startsWith('agents/' + key + '/events/') ? (include.events ?? []).includes(name.split('/')[3]) : true;
|
|
205
293
|
if (!selected) { excluded.push(name); continue; }
|
|
206
294
|
const target = 'template/' + name;
|
|
207
295
|
if (entries.has(target)) check(entries.get(target).bytes.equals(entry.bytes) && entries.get(target).mode === entry.mode, 'Conflicting shared resource', 'SOURCE_CHANGED');
|
|
@@ -219,17 +307,19 @@ export function buildTemplatePackage({ metadata, members, externalAids = [], pub
|
|
|
219
307
|
memberReferences ||= /\{\{\s*members\./.test(line);
|
|
220
308
|
check(!/(?:sk-[A-Za-z0-9_-]{16,}|ghp_[A-Za-z0-9]{20,}|AKIA[A-Z0-9]{16}|-----BEGIN .*PRIVATE KEY|(?:API_KEY|TOKEN|SECRET|PASSWORD)\s*=\s*(?!\$\{)\S{8,})/i.test(line),
|
|
221
309
|
'Credential content in portable resource: ' + name, 'SCAN_BLOCKED');
|
|
222
|
-
for (const aid of line.match(/[a-z0-9][a-z0-9_-]*\.(?:[a-z0-9-]+\.)+[a-z]{2,}/gi) ?? []) {
|
|
223
|
-
if (!line.includes('://' + aid) && !aid.startsWith('www.') && !line.includes('{{' + aid + '}}') && !new RegExp('\\{\\{\\s*' + aid.replaceAll('.', '\\.') + '\\s*\\}\\}').test(line)) external.add(aid);
|
|
224
|
-
}
|
|
225
310
|
}
|
|
311
|
+
for (const aid of extractExternalAids(entry.bytes.toString('utf8'), name)) external.add(aid);
|
|
226
312
|
}
|
|
227
313
|
if (memberReferences && evolcoreRange === '>=0.0.43-test.8') evolcoreRange = '>=0.0.43-test.8 <0.0.43 || >=0.0.44';
|
|
314
|
+
const templateFeatures = [
|
|
315
|
+
...(memberReferences ? ['member-references-v1'] : []),
|
|
316
|
+
...([...entries.keys()].some(name => /^template\/agents\/[^/]+\/events\//.test(name)) ? ['event-packs-v1'] : []),
|
|
317
|
+
];
|
|
228
318
|
const info = { $schema_version: 1, id: metadata.id, name: metadata.name, version: metadata.version,
|
|
229
319
|
...(publisher !== undefined ? { publisher: structuredClone(publisher) } : {}), ...(createdAt !== undefined ? { createdAt } : {}),
|
|
230
320
|
...(metadata.description !== undefined ? { description: metadata.description } : {}),
|
|
231
321
|
compat: { platforms: structuredClone(metadata.platforms), evolcore: evolcoreRange,
|
|
232
|
-
...(
|
|
322
|
+
...(templateFeatures.length ? { templateFeatures } : {}),
|
|
233
323
|
baseagents: [...new Set(team.agents.flatMap(member => Object.keys(member.config.baseagents)))].sort() },
|
|
234
324
|
externalAids: [...external].sort() };
|
|
235
325
|
const manifest = [...entries].map(([name, entry]) => ({ path: name.slice('template/'.length), size: entry.bytes.length, sha256: packageDigest(entry.bytes).slice(7) }));
|
|
@@ -255,6 +345,7 @@ export function exportTemplatePackage(templateDir, { publisher, createdAt = Date
|
|
|
255
345
|
const providers = readOptional('.evolcore/providers.json').providers ?? {};
|
|
256
346
|
if (team.host.config !== undefined) { delete team.host.config; excluded.push('host.config'); }
|
|
257
347
|
for (const agent of team.agents) {
|
|
348
|
+
Object.assign(agent, resolveMemberParameters(agent));
|
|
258
349
|
const source = { ...structuredClone(defaults), ...agent.config,
|
|
259
350
|
baseagents: { ...defaults.baseagents, ...agent.config?.baseagents } };
|
|
260
351
|
const config = {};
|
|
@@ -269,7 +360,8 @@ export function exportTemplatePackage(templateDir, { publisher, createdAt = Date
|
|
|
269
360
|
for (const field of ['model', 'effort', 'params']) if (block[field] !== undefined) config.baseagents[name][field] = structuredClone(block[field]);
|
|
270
361
|
}
|
|
271
362
|
check(config.baseagents[config.active_baseagent], 'Default baseagent must have a binding: ' + agent.key);
|
|
272
|
-
for (const field of Object.keys(agent.config ?? {})) if (!Object.hasOwn(config, field)
|
|
363
|
+
for (const field of Object.keys(agent.config ?? {})) if (!Object.hasOwn(config, field)
|
|
364
|
+
&& !['version', 'update'].includes(field)) excluded.push('agents/' + agent.key + '/config/' + field);
|
|
273
365
|
agent.config = config;
|
|
274
366
|
assertPublicTemplateConfig(config);
|
|
275
367
|
}
|
|
@@ -294,18 +386,20 @@ export function exportTemplatePackage(templateDir, { publisher, createdAt = Date
|
|
|
294
386
|
memberReferences ||= /\{\{\s*members\./.test(line);
|
|
295
387
|
check(!/(?:sk-[A-Za-z0-9_-]{16,}|ghp_[A-Za-z0-9]{20,}|AKIA[A-Z0-9]{16}|-----BEGIN .*PRIVATE KEY|(?:API_KEY|TOKEN|SECRET|PASSWORD)\s*=\s*(?!\$\{)\S{8,})/i.test(line),
|
|
296
388
|
'Credential content in portable resource: ' + name, 'SENSITIVE_CONTENT');
|
|
297
|
-
for (const aid of line.match(/[a-z0-9][a-z0-9_-]*\.(?:[a-z0-9-]+\.)+[a-z]{2,}/gi) ?? []) {
|
|
298
|
-
if (!line.includes('://' + aid) && !aid.startsWith('www.') && !line.includes('{{' + aid + '}}') && !new RegExp('\\{\\{\\s*' + aid.replaceAll('.', '\\.') + '\\s*\\}\\}').test(line)) external.add(aid);
|
|
299
|
-
}
|
|
300
389
|
}
|
|
390
|
+
for (const aid of extractExternalAids(entry.bytes.toString('utf8'), name)) external.add(aid);
|
|
301
391
|
}
|
|
302
392
|
// Older readers normalize test builds to the final version. The upper bound
|
|
303
393
|
// makes those readers reject member references instead of leaving old AIDs.
|
|
304
394
|
if (memberReferences && evolcoreRange === '>=0.0.43') evolcoreRange = '>=0.0.43-test.8 <0.0.43 || >=0.0.44';
|
|
305
|
-
const
|
|
395
|
+
const templateFeatures = [
|
|
396
|
+
...(memberReferences ? ['member-references-v1'] : []),
|
|
397
|
+
...([...entries.keys()].some(name => /^template\/agents\/[^/]+\/events\//.test(name)) ? ['event-packs-v1'] : []),
|
|
398
|
+
];
|
|
399
|
+
const metadata = { $schema_version: 1, id: team.id, name: team.title ?? team.id, version: team.version,
|
|
306
400
|
...(team.description !== undefined ? { description: team.description } : {}), ...(publisher ? { publisher } : {}), createdAt,
|
|
307
401
|
compat: { platforms: team.host.platform, evolcore: evolcoreRange,
|
|
308
|
-
...(
|
|
402
|
+
...(templateFeatures.length ? { templateFeatures } : {}),
|
|
309
403
|
baseagents: [...new Set(team.agents.flatMap(agent => Object.keys(agent.config.baseagents)))] }, externalAids: [...external].sort() };
|
|
310
404
|
const manifest = [...entries].map(([name, entry]) => ({ path: name.slice('template/'.length), size: entry.bytes.length, sha256: packageDigest(entry.bytes).slice(7) }));
|
|
311
405
|
entries.set('PACKAGE.json', { bytes: json(metadata), mode: 0o644 });
|
|
@@ -360,8 +454,9 @@ export function attachBuildEnvironment(templateDir, sourceDir) {
|
|
|
360
454
|
check(!base.errors.length, 'Invalid build environment: ' + base.errors.join('; '));
|
|
361
455
|
const teamFile = path.join(templateDir, 'team.json');
|
|
362
456
|
const team = JSON.parse(fs.readFileSync(teamFile, 'utf8'));
|
|
363
|
-
|
|
364
|
-
|
|
457
|
+
team.host.config = structuredClone(base.tpl.team.host.config ?? {});
|
|
458
|
+
team.host.config.aun = { ...team.host.config.aun, defaultAidDomain: resolveTemplateAidDomain(base.tpl.team) };
|
|
459
|
+
delete team.issuer;
|
|
365
460
|
for (const name of ['providers.json', 'agents/defaults.json', '.env']) {
|
|
366
461
|
const source = path.join(base.tpl.root, '.evolcore', ...name.split('/'));
|
|
367
462
|
if (!fs.existsSync(source)) continue;
|
|
@@ -379,3 +474,69 @@ export function templateProviderSummary(templateDir) {
|
|
|
379
474
|
const providers = JSON.parse(fs.readFileSync(file, 'utf8')).providers ?? {};
|
|
380
475
|
return Object.entries(providers).map(([id, value]) => ({ id, name: value.name ?? id, services: Object.keys(value.services ?? {}) }));
|
|
381
476
|
}
|
|
477
|
+
|
|
478
|
+
const EVENT_PACK_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
479
|
+
const TEMPLATE_EVENT_BUS_PATTERN = /^\{\{\s*(?:members\.[a-z0-9][a-z0-9_-]{0,31}\.aid|(?:agent|owner|host)\.aid)\s*\}\}$/;
|
|
480
|
+
|
|
481
|
+
/** Share package definitions/assets, never runtime state, logs, backups or caches. */
|
|
482
|
+
export function isPortableEventPackResource(relative) {
|
|
483
|
+
return relative.split('/').every(part => part && part !== '..' && !part.startsWith('.')
|
|
484
|
+
&& !PACK_RUNTIME_ENTRIES.has(part) && !['node_modules', '__pycache__'].includes(part)
|
|
485
|
+
&& !part.endsWith('_') && !part.endsWith('~') && !/\.(?:bak|pyc)$/i.test(part));
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export function isPortableEventPackFile(relative) {
|
|
489
|
+
const [group, id, ...rest] = relative.split('/');
|
|
490
|
+
return group === 'events' && EVENT_PACK_NAME_PATTERN.test(id ?? '') && rest.length > 0
|
|
491
|
+
&& isPortableEventPackResource(rest.join('/'));
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** Reuse the runtime validator; only template bus references need a validation placeholder. */
|
|
495
|
+
export function validateEventPack(raw, files, { template = false, location = 'events' } = {}) {
|
|
496
|
+
const checked = structuredClone(raw);
|
|
497
|
+
if (template && checked && typeof checked === 'object') {
|
|
498
|
+
for (const kind of ['publish', 'subscribe']) if (Array.isArray(checked[kind])) {
|
|
499
|
+
for (const entry of checked[kind]) if (entry && TEMPLATE_EVENT_BUS_PATTERN.test(entry.bus)) entry.bus = sha256(entry.bus).slice(0, 16) + '.agentid.cn';
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
const result = validatePackJson(checked);
|
|
503
|
+
assert(result.ok, 'INVALID_ARGUMENT', location + '/pack.json: ' + result.errors.join('; '));
|
|
504
|
+
for (const entry of result.value.subscribe) {
|
|
505
|
+
assert(files.includes(entry.handler.script), 'INVALID_ARGUMENT', location + ': missing handler ' + entry.handler.script);
|
|
506
|
+
}
|
|
507
|
+
return raw;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** Read-only inventory: loading must not create logs or migrate source files. */
|
|
511
|
+
export function readEventPacks(eventsDir, { template = false } = {}) {
|
|
512
|
+
if (!fs.existsSync(eventsDir)) return [];
|
|
513
|
+
regularPath(eventsDir);
|
|
514
|
+
return fs.readdirSync(eventsDir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))
|
|
515
|
+
.filter(entry => !entry.name.startsWith('.') && !entry.name.startsWith('_'))
|
|
516
|
+
.flatMap(entry => {
|
|
517
|
+
assert(!entry.isSymbolicLink(), 'INVALID_ARGUMENT', 'Symbolic event pack: ' + entry.name);
|
|
518
|
+
if (!entry.isDirectory()) return [];
|
|
519
|
+
const dir = inside(eventsDir, entry.name);
|
|
520
|
+
if (fs.existsSync(path.join(dir, '.archived'))) return [];
|
|
521
|
+
assert(EVENT_PACK_NAME_PATTERN.test(entry.name), 'INVALID_ARGUMENT', 'Invalid event pack name: ' + entry.name);
|
|
522
|
+
const files = walkFiles(dir, relative => !isPortableEventPackResource(relative));
|
|
523
|
+
assert(files.includes('pack.json'), 'INVALID_ARGUMENT', 'Event pack missing pack.json: ' + entry.name);
|
|
524
|
+
const definition = validateEventPack(readJson(path.join(dir, 'pack.json')), files, { template, location: 'events/' + entry.name });
|
|
525
|
+
return [{ id: entry.name, dir, files, definition }];
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Validate the complete portable file set, including disabled packs and orphan assets. */
|
|
530
|
+
export function validateEventPackEntries(entries, keys) {
|
|
531
|
+
for (const key of keys) {
|
|
532
|
+
const prefix = 'agents/' + key + '/events/';
|
|
533
|
+
const ids = new Set([...entries.keys()].filter(name => name.startsWith(prefix)).map(name => name.slice(prefix.length).split('/')[0]));
|
|
534
|
+
for (const id of ids) {
|
|
535
|
+
const packPrefix = prefix + id + '/';
|
|
536
|
+
const entry = entries.get(packPrefix + 'pack.json');
|
|
537
|
+
assert(entry, 'INVALID_ARGUMENT', 'Event pack missing pack.json: ' + prefix + id);
|
|
538
|
+
const files = [...entries.keys()].filter(name => name.startsWith(packPrefix)).map(name => name.slice(packPrefix.length));
|
|
539
|
+
validateEventPack(JSON.parse(entry.bytes.toString('utf8')), files, { template: true, location: prefix + id });
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
@@ -1,8 +1,40 @@
|
|
|
1
1
|
/** Shared, pure template binding/rendering. No home discovery or runtime writes. */
|
|
2
2
|
export const BASEAGENTS = ['claude', 'codex', 'gemini', 'ecagent'];
|
|
3
|
+
export const MEMBER_PARAMETER_FIELDS = ['version', 'update'];
|
|
3
4
|
const record = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
4
5
|
const fail = message => { throw Object.assign(new Error(message), { code: 'INVALID_ARGUMENT' }); };
|
|
5
6
|
|
|
7
|
+
/** Author declarations only; never generates versions or grants update authority. */
|
|
8
|
+
export function resolveMemberParameters(member) {
|
|
9
|
+
if (!record(member)) fail('Member must be an object');
|
|
10
|
+
const out = {};
|
|
11
|
+
const prefix = 'Member ' + (member.key ?? '(unknown)') + '.';
|
|
12
|
+
if ([member, member.config].some(value => record(value) && Object.hasOwn(value, 'publisherAid'))) fail(prefix + 'publisherAid: use update.publisher');
|
|
13
|
+
for (const field of MEMBER_PARAMETER_FIELDS) {
|
|
14
|
+
const declarations = [member, member.config].filter(value => record(value) && Object.hasOwn(value, field));
|
|
15
|
+
for (const declaration of declarations) {
|
|
16
|
+
const value = declaration[field];
|
|
17
|
+
const valid = field === 'version'
|
|
18
|
+
? typeof value === 'string' && /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/.test(value)
|
|
19
|
+
: record(value) && Object.keys(value).every(key => ['mode', 'publisher'].includes(key))
|
|
20
|
+
&& ['auto', 'manual', 'disabled'].includes(value.mode);
|
|
21
|
+
if (!valid) fail(prefix + field + ': invalid declaration');
|
|
22
|
+
if (field === 'update' && Object.hasOwn(value, 'publisher')
|
|
23
|
+
&& (typeof value.publisher !== 'string' || !/^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?){2,}$/.test(value.publisher))) {
|
|
24
|
+
fail(prefix + 'update.publisher: invalid AID');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (declarations.length === 2) {
|
|
28
|
+
const equal = field === 'update'
|
|
29
|
+
? declarations[0][field].mode === declarations[1][field].mode && declarations[0][field].publisher === declarations[1][field].publisher
|
|
30
|
+
: declarations[0][field] === declarations[1][field];
|
|
31
|
+
if (!equal) fail(prefix + field + ': conflicts with config.' + field);
|
|
32
|
+
}
|
|
33
|
+
if (declarations.length) out[field] = structuredClone(declarations[0][field]);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
6
38
|
/** Connection credentials cannot be hidden in otherwise public nested configuration. */
|
|
7
39
|
export function assertPublicTemplateConfig(config) {
|
|
8
40
|
const visit = (value, location) => {
|
|
@@ -126,10 +158,11 @@ export function teamMemberVariables(members, ownerAid, hostAid) {
|
|
|
126
158
|
export function planMemberConfig({ member, vars, providers, defaults = {}, fallbackProviders = {}, selections = {}, allowMissing = false, modelCatalog, mode = 'create_prebuilt' }) {
|
|
127
159
|
if (!record(member) || !MEMBER_KEY.test(member.key) || !record(vars)) fail('Invalid member plan');
|
|
128
160
|
if (!['create_prebuilt', 'create_on_host', 'overlay_existing'].includes(mode)) fail('Invalid member plan mode');
|
|
161
|
+
const parameters = resolveMemberParameters(member);
|
|
129
162
|
const rendered = renderValue(member, vars);
|
|
130
163
|
if (mode !== 'create_prebuilt' && (!record(rendered.config) || Object.keys(rendered.config)
|
|
131
|
-
.some(key => !['chatmode', 'memory', 'active_baseagent', 'baseagents'].includes(key)))) fail('Unsupported live-host member configuration');
|
|
132
|
-
const binding = bindTemplateProviders(rendered.config
|
|
164
|
+
.some(key => !['chatmode', 'memory', 'active_baseagent', 'baseagents', 'version', 'update'].includes(key)))) fail('Unsupported live-host member configuration');
|
|
165
|
+
const binding = bindTemplateProviders({ ...rendered.config, ...parameters }, { providers, defaults, fallbackProviders, selections, allowMissing, modelCatalog });
|
|
133
166
|
return { key: member.key, profile: rendered.profile, skills: rendered.skills ?? {}, config: binding.config, providers: binding.refs };
|
|
134
167
|
}
|
|
135
168
|
|
|
@@ -30,7 +30,7 @@ export const HOME_ALLOWED = ['providers.json', 'agents', 'skills', '.env'];
|
|
|
30
30
|
const HOME_AGENTS_ALLOWED = ['defaults.json'];
|
|
31
31
|
|
|
32
32
|
/** 每个 agent 目录里允许出现的条目。配置文件不在其中——它由工具生成。 */
|
|
33
|
-
const AGENT_DIR_ALLOWED = ['personal', 'triggers'];
|
|
33
|
+
const AGENT_DIR_ALLOWED = ['personal', 'triggers', 'events'];
|
|
34
34
|
|
|
35
35
|
const KEY_RE = /^[a-z0-9][a-z0-9_-]{0,31}$/;
|
|
36
36
|
const NAME_RE = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
@@ -82,7 +82,7 @@ export function loadTemplate(dir) {
|
|
|
82
82
|
try { schema = normalizeTeamSchema(schema); } catch (err) { return { errors: [err.message] }; }
|
|
83
83
|
errors.push(...validateContractSchema(team, schema, 'team.json'));
|
|
84
84
|
|
|
85
|
-
const name = team.
|
|
85
|
+
const name = team.id;
|
|
86
86
|
const version = team.version;
|
|
87
87
|
if (typeof name !== 'string' || !NAME_RE.test(name)) errors.push(`team.json name must match ${NAME_RE}`);
|
|
88
88
|
const keys = team.agents.map(agent => agent.key);
|