evolcore 0.0.40 → 0.0.41-test.1
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 +94 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +197 -197
- package/dist/agents/codex-runner.js +535 -259
- package/dist/agents/ecagent-runner.js +31 -12
- package/dist/agents/gemini-runner.js +27 -7
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -13
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +72 -11
- package/dist/aun/msg/p2p.js +32 -7
- package/dist/aun/service-proxy.js +36 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +367 -24
- package/dist/channels/daemon.js +39 -5
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +85 -41
- package/dist/cli/daemon-commands.js +678 -688
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +48 -4
- package/dist/cli/managed-command-guard.js +4 -0
- package/dist/cli/model.js +40 -40
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/role.js +85 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +8 -1
- package/dist/config/boot-log.js +38 -1
- package/dist/config/config-field-policy.js +5 -32
- package/dist/config/config-manager.js +46 -39
- package/dist/config/config-operation-service.js +8 -11
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +89 -595
- package/dist/config/peer-role-resolver.js +15 -11
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +686 -25
- package/dist/config-store.js +79 -3
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +3 -1
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +82 -6
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +37 -9
- package/dist/core/auth/delegation-authorization.js +3 -1
- package/dist/core/auth/operation-authorizer.js +15 -0
- package/dist/core/auth/operation-catalog.js +39 -6
- package/dist/core/command/agent-control.js +94 -19
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +105 -145
- package/dist/core/command/connect-menu.js +31 -2
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +6 -6
- package/dist/core/command/menu-handler.js +87 -163
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +148 -30
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +157 -352
- package/dist/core/daemon-control.js +8 -14
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/evolagent-registry.js +4 -4
- package/dist/core/evolagent.js +2 -2
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/ipc-registration.js +24 -3
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +190 -190
- package/dist/core/memory/consolidation.js +316 -29
- package/dist/core/memory/forget-log.js +96 -0
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +44 -39
- package/dist/core/message/aun-ipc-sender.js +34 -7
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +11 -4
- package/dist/core/message/message-admission.js +97 -8
- package/dist/core/message/message-bridge.js +71 -24
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +387 -144
- package/dist/core/model/catalog-service.js +4 -2
- package/dist/core/model/config-scope.js +24 -64
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +37 -47
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +25 -23
- package/dist/core/permission/ec-command-parser.js +138 -5
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +42 -10
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +168 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +6 -1
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +79 -17
- package/dist/ipc.js +189 -17
- package/dist/paths.js +4 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +485 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +16 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +5 -3
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +18 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +16 -0
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +36 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +21 -8
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +23 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +260 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +3 -7
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-trigger/SKILL.md +13 -5
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/memory.md +4 -4
- package/package.json +7 -3
- package/dist/stats/billing.js +0 -215
|
@@ -50,7 +50,6 @@ const DEFAULTS_EXACT_PATHS = new Set([
|
|
|
50
50
|
]);
|
|
51
51
|
const BASEAGENT_COMMON_FIELDS = new Set([
|
|
52
52
|
'provider',
|
|
53
|
-
'providerServiceType',
|
|
54
53
|
'model',
|
|
55
54
|
'auxiliaryModel',
|
|
56
55
|
'auxiliaryEffort',
|
|
@@ -166,7 +165,31 @@ function targetFor(file) {
|
|
|
166
165
|
return file === 'daemon' ? ConfigTarget.Process : ConfigTarget.Defaults;
|
|
167
166
|
}
|
|
168
167
|
function readSettingsFile(file) {
|
|
169
|
-
return read(targetFor(file), undefined, { cache: false
|
|
168
|
+
return read(targetFor(file), undefined, { cache: false });
|
|
169
|
+
}
|
|
170
|
+
function hideBaseagentConnectionFields(config) {
|
|
171
|
+
if (!config)
|
|
172
|
+
return null;
|
|
173
|
+
const safeConfig = clone(config);
|
|
174
|
+
const stripConnectionFields = (value) => {
|
|
175
|
+
if (Array.isArray(value)) {
|
|
176
|
+
value.forEach(stripConnectionFields);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (!isRecord(value))
|
|
180
|
+
return;
|
|
181
|
+
for (const field of Object.keys(value)) {
|
|
182
|
+
const normalizedField = field.replace(/[_-]/gu, '').toLowerCase();
|
|
183
|
+
if (['apikey', 'baseurl', 'headers', 'queryparams'].includes(normalizedField)) {
|
|
184
|
+
delete value[field];
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
stripConnectionFields(value[field]);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
stripConnectionFields(safeConfig);
|
|
192
|
+
return safeConfig;
|
|
170
193
|
}
|
|
171
194
|
export function readBasicSettings() {
|
|
172
195
|
const rawDaemon = readSettingsFile('daemon');
|
|
@@ -179,7 +202,7 @@ export function readBasicSettings() {
|
|
|
179
202
|
return {
|
|
180
203
|
ok: true,
|
|
181
204
|
daemon,
|
|
182
|
-
defaults: rawDefaults,
|
|
205
|
+
defaults: hideBaseagentConnectionFields(rawDefaults),
|
|
183
206
|
revisions: {
|
|
184
207
|
daemon: settingsRevision(rawDaemon ?? { $schema_version: 8 }),
|
|
185
208
|
defaults: settingsRevision(rawDefaults ?? { $schema_version: 5 }),
|
|
@@ -367,18 +390,6 @@ function assertFallbackModels(value, fieldPath) {
|
|
|
367
390
|
}
|
|
368
391
|
});
|
|
369
392
|
}
|
|
370
|
-
function assertHttpUrl(value, fieldPath) {
|
|
371
|
-
const raw = assertString(value, fieldPath, { max: 2048 }).trim();
|
|
372
|
-
let parsed;
|
|
373
|
-
try {
|
|
374
|
-
parsed = new URL(raw);
|
|
375
|
-
}
|
|
376
|
-
catch {
|
|
377
|
-
throw makeError(`${fieldPath} must be a valid URL`, 'INVALID_SETTINGS_VALUE');
|
|
378
|
-
}
|
|
379
|
-
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
|
|
380
|
-
throw makeError(`${fieldPath} must use http or https`, 'INVALID_SETTINGS_VALUE');
|
|
381
|
-
}
|
|
382
393
|
function validateDaemonValue(fieldPath, value) {
|
|
383
394
|
if (BOOLEAN_PATHS.has(fieldPath))
|
|
384
395
|
return assertBoolean(value, fieldPath);
|
|
@@ -410,7 +421,7 @@ function validateDaemonValue(fieldPath, value) {
|
|
|
410
421
|
throw makeError(`Unsupported daemon settings path: ${fieldPath}`, 'INVALID_SETTINGS_PATH');
|
|
411
422
|
}
|
|
412
423
|
function validateBaseagentValue(baseagent, field, fieldPath, value) {
|
|
413
|
-
if (field === 'provider'
|
|
424
|
+
if (field === 'provider') {
|
|
414
425
|
const provider = assertString(value, fieldPath, { max: 256 });
|
|
415
426
|
if (!/^[A-Za-z0-9_-]+$/u.test(provider) || PROHIBITED_PATH_SEGMENTS.has(provider))
|
|
416
427
|
throw makeError(`${fieldPath} is invalid`, 'INVALID_SETTINGS_VALUE');
|
|
@@ -418,10 +429,8 @@ function validateBaseagentValue(baseagent, field, fieldPath, value) {
|
|
|
418
429
|
}
|
|
419
430
|
if (BASEAGENT_BOOLEAN_FIELDS.has(field))
|
|
420
431
|
return assertBoolean(value, fieldPath);
|
|
421
|
-
if (field === 'model' || field === 'auxiliaryModel' || field === '
|
|
422
|
-
|
|
423
|
-
if (field === 'apiKey' && ['<redacted>', '******'].includes(stringValue))
|
|
424
|
-
throw makeError(`${fieldPath} must contain a replacement secret, not the redacted placeholder`, 'INVALID_SETTINGS_VALUE');
|
|
432
|
+
if (field === 'model' || field === 'auxiliaryModel' || field === 'pathToClaudeCodeExecutable' || field === 'cliPath' || field === 'project' || field === 'location') {
|
|
433
|
+
assertString(value, fieldPath, { max: 4096 });
|
|
425
434
|
return;
|
|
426
435
|
}
|
|
427
436
|
if (field === 'effort' || field === 'auxiliaryEffort') {
|
|
@@ -430,12 +439,6 @@ function validateBaseagentValue(baseagent, field, fieldPath, value) {
|
|
|
430
439
|
throw makeError(`${fieldPath} is invalid`, 'INVALID_SETTINGS_VALUE');
|
|
431
440
|
return;
|
|
432
441
|
}
|
|
433
|
-
if (field === 'baseUrl')
|
|
434
|
-
return assertHttpUrl(value, fieldPath);
|
|
435
|
-
if (field === 'headers')
|
|
436
|
-
return assertStringMap(value, fieldPath, true);
|
|
437
|
-
if (field === 'queryParams')
|
|
438
|
-
return assertStringMap(value, fieldPath, false);
|
|
439
442
|
if (field === 'fallback')
|
|
440
443
|
return assertFallbackModels(value, fieldPath);
|
|
441
444
|
if (field === 'approvalsReviewer') {
|
|
@@ -465,8 +468,10 @@ function validateDefaultsValue(fieldPath, value) {
|
|
|
465
468
|
throw makeError('Invalid service selection', 'INVALID_SETTINGS_VALUE');
|
|
466
469
|
if (Object.keys(selection).some(field => !['provider', 'model', 'effort', 'fallback'].includes(field)))
|
|
467
470
|
throw makeError('Invalid service selection field', 'INVALID_SETTINGS_VALUE');
|
|
468
|
-
|
|
469
|
-
|
|
471
|
+
if (selection.provider !== undefined)
|
|
472
|
+
validateBaseagentValue('', 'provider', `Services.${serviceType}.provider`, selection.provider);
|
|
473
|
+
if (selection.model !== undefined)
|
|
474
|
+
assertString(selection.model, `Services.${serviceType}.model`);
|
|
470
475
|
if (selection.effort !== undefined)
|
|
471
476
|
validateBaseagentValue('', 'effort', `Services.${serviceType}.effort`, selection.effort);
|
|
472
477
|
if (selection.fallback !== undefined)
|
|
@@ -674,18 +679,6 @@ export async function handleBasicSettingsService(input) {
|
|
|
674
679
|
if (input.method === 'GET' && pathname === '/api/basic-settings') {
|
|
675
680
|
return response(200, { success: true, data: readBasicSettings() });
|
|
676
681
|
}
|
|
677
|
-
if (input.method === 'GET' && pathname === '/api/basic-settings/secret') {
|
|
678
|
-
const file = typeof query.file === 'string' ? query.file : 'defaults';
|
|
679
|
-
const fieldPath = typeof query.path === 'string' ? query.path : '';
|
|
680
|
-
if (file !== 'defaults' || !/^baseagents\.(claude|codex|gemini|ecagent)\.apiKey$/u.test(fieldPath)) {
|
|
681
|
-
throw makeError('Only Base Agent apiKey fields can be revealed', 'INVALID_SECRET_PATH');
|
|
682
|
-
}
|
|
683
|
-
const config = readSettingsFile('defaults');
|
|
684
|
-
const value = fieldPath.split('.').reduce((current, segment) => isRecord(current) ? current[segment] : undefined, config);
|
|
685
|
-
if (typeof value !== 'string' || !value.trim())
|
|
686
|
-
return response(404, { success: false, code: 'SECRET_NOT_CONFIGURED', error: 'API Key is not configured' });
|
|
687
|
-
return response(200, { success: true, data: { file, path: fieldPath, value } });
|
|
688
|
-
}
|
|
689
682
|
if (input.method === 'PATCH' && pathname === '/api/basic-settings') {
|
|
690
683
|
const result = await mutateBasicSettings(requestBody(input.body));
|
|
691
684
|
if (!result.ok)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { isValidAid } from '../aun/aid/validation.js';
|
|
2
|
+
import { resolvePeerDisplayLabel } from '../config/contact-book.js';
|
|
3
|
+
import { resolvePeerRoleDetail } from '../config/peer-role-resolver.js';
|
|
4
|
+
import { resolveChatMode } from '../core/message/peer-mode.js';
|
|
5
|
+
import { resolvePermissionMode } from '../core/model/config-scope.js';
|
|
6
|
+
import { formatPeerKey } from '../core/relation/peer-identity.js';
|
|
7
|
+
const REQUEST_FIELDS = new Set([
|
|
8
|
+
'selfAid', 'channelType', 'channelKey', 'chatType', 'actorId',
|
|
9
|
+
'conversationId', 'peerType', 'sessionId', 'displayQueries',
|
|
10
|
+
]);
|
|
11
|
+
class MessageContextRequestError extends Error {
|
|
12
|
+
code = 'INVALID_REQUEST';
|
|
13
|
+
}
|
|
14
|
+
function requestString(request, field, required = false, maxLength = 512) {
|
|
15
|
+
const value = request[field];
|
|
16
|
+
if (value === undefined) {
|
|
17
|
+
if (required)
|
|
18
|
+
throw new MessageContextRequestError(`${field} is required`);
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (typeof value !== 'string' || value.length > maxLength || /[\u0000-\u001f]/.test(value)) {
|
|
22
|
+
throw new MessageContextRequestError(`${field} must be a string of at most ${maxLength} characters without control characters`);
|
|
23
|
+
}
|
|
24
|
+
const normalized = value.trim();
|
|
25
|
+
if (required && !normalized)
|
|
26
|
+
throw new MessageContextRequestError(`${field} is required`);
|
|
27
|
+
return normalized || undefined;
|
|
28
|
+
}
|
|
29
|
+
function requestIdentity(request) {
|
|
30
|
+
const selfAid = requestString(request, 'selfAid', true);
|
|
31
|
+
if (!isValidAid(selfAid))
|
|
32
|
+
throw new MessageContextRequestError('selfAid must be a valid AID');
|
|
33
|
+
const channelType = requestString(request, 'channelType', true, 64).toLowerCase();
|
|
34
|
+
if (!/^[a-z][a-z0-9_-]*$/.test(channelType))
|
|
35
|
+
throw new MessageContextRequestError('channelType is invalid');
|
|
36
|
+
return {
|
|
37
|
+
selfAid,
|
|
38
|
+
channelType,
|
|
39
|
+
channelKey: requestString(request, 'channelKey') || channelType,
|
|
40
|
+
actorId: requestString(request, 'actorId', true),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function displayLabels(value) {
|
|
44
|
+
if (value === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
if (!Array.isArray(value) || value.length > 1000) {
|
|
47
|
+
throw new MessageContextRequestError('displayQueries must be an array of at most 1000 items');
|
|
48
|
+
}
|
|
49
|
+
return value.map(raw => {
|
|
50
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
51
|
+
return null;
|
|
52
|
+
try {
|
|
53
|
+
const identity = requestIdentity(raw);
|
|
54
|
+
return resolvePeerDisplayLabel(identity.selfAid, identity.channelType, identity.actorId, identity.channelKey) ?? null;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export function createEcwebMessageContextProvider(sessionManager) {
|
|
62
|
+
return async (request) => {
|
|
63
|
+
for (const field of Object.keys(request)) {
|
|
64
|
+
if (!REQUEST_FIELDS.has(field))
|
|
65
|
+
throw new MessageContextRequestError(`Unsupported message context field: ${field}`);
|
|
66
|
+
}
|
|
67
|
+
const peerLabels = displayLabels(request.displayQueries);
|
|
68
|
+
const hasContext = [...REQUEST_FIELDS].some(field => field !== 'displayQueries' && Object.prototype.hasOwnProperty.call(request, field));
|
|
69
|
+
if (!hasContext) {
|
|
70
|
+
if (peerLabels)
|
|
71
|
+
return { peerLabels };
|
|
72
|
+
throw new MessageContextRequestError('message context fields are required');
|
|
73
|
+
}
|
|
74
|
+
const identity = requestIdentity(request);
|
|
75
|
+
const chatType = requestString(request, 'chatType', true, 16);
|
|
76
|
+
if (chatType !== 'private' && chatType !== 'group')
|
|
77
|
+
throw new MessageContextRequestError('chatType must be private or group');
|
|
78
|
+
const conversationId = requestString(request, 'conversationId', true);
|
|
79
|
+
const peerType = requestString(request, 'peerType', false, 128);
|
|
80
|
+
const sessionId = requestString(request, 'sessionId', false, 256);
|
|
81
|
+
if (sessionId && !/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(sessionId)) {
|
|
82
|
+
throw new MessageContextRequestError('sessionId must be an EvolCore session identifier');
|
|
83
|
+
}
|
|
84
|
+
const peerKey = formatPeerKey(identity.channelType, conversationId);
|
|
85
|
+
const detail = resolvePeerRoleDetail({ ...identity, chatType, conversationId, peerType });
|
|
86
|
+
const role = detail.effectiveRole || 'none';
|
|
87
|
+
const result = {
|
|
88
|
+
role,
|
|
89
|
+
roleSource: detail.source,
|
|
90
|
+
permissionMode: resolvePermissionMode({ self: identity.selfAid, peerKey, role }),
|
|
91
|
+
chatMode: resolveChatMode({ self: identity.selfAid, peerKey, role, chatType, peerType }),
|
|
92
|
+
...(peerLabels ? { peerLabels } : {}),
|
|
93
|
+
};
|
|
94
|
+
if (sessionId) {
|
|
95
|
+
const session = await sessionManager.getSessionById(sessionId);
|
|
96
|
+
if (session?.selfAID === identity.selfAid
|
|
97
|
+
&& session.channelType === identity.channelType
|
|
98
|
+
&& session.channelId === conversationId
|
|
99
|
+
&& session.agentSessionId && session.projectPath && session.baseagent) {
|
|
100
|
+
try {
|
|
101
|
+
const fileInfo = sessionManager.getSessionFileInfo(session.projectPath, session.agentSessionId, session.baseagent, session.selfAID);
|
|
102
|
+
if (Number.isFinite(fileInfo.turns) && fileInfo.turns > 0)
|
|
103
|
+
result.turns = fileInfo.turns;
|
|
104
|
+
}
|
|
105
|
+
catch { }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
};
|
|
110
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { EcagentSessionFileAdapter } from './core/session/adapters/ecagent-sessi
|
|
|
16
16
|
import { loadDefaults, loadAllAgents, migrateIdentitiesIfNeeded, loadDaemonConfig, initializeEckSnapshotsConfig } from './config-store.js';
|
|
17
17
|
import { inspectClaudeSandboxDependencies, formatClaudeSandboxDependencies } from './core/permission/sandbox-runtime.js';
|
|
18
18
|
import { migrateRelationSharedDirectories } from './core/relation/shared-data.js';
|
|
19
|
-
import { DEFAULT_ECWEB_PORT, ecwebService } from './config/daemon-services.js';
|
|
19
|
+
import { DEFAULT_ECWEB_PORT, ecwebService, serviceRuntimeMode } from './config/daemon-services.js';
|
|
20
20
|
import { ConfigTarget, onConfigWrite } from './config/config-manager.js';
|
|
21
21
|
import { expirePendingContactRequests } from './config/contact-request-service.js';
|
|
22
22
|
import { synchronizeOwnershipContactsSync } from './config/contact-book-store.js';
|
|
@@ -45,6 +45,8 @@ import { readFastaunVersion, readInstalledEvolcoreVersion, reportEvolcoreStartup
|
|
|
45
45
|
import { recoverAllRoleMutationsSync } from './core/command/role-menu.js';
|
|
46
46
|
import { HandoffRuntime } from './core/handoff/runtime.js';
|
|
47
47
|
import { startDaemonControlAid } from './core/daemon-control.js';
|
|
48
|
+
import { createDelegationAuthorizer } from './core/auth/delegation-authorization.js';
|
|
49
|
+
import { registerProxyIpcExecutor } from './proxy/ipc-service.js';
|
|
48
50
|
import { ownerResolver, getDaemonOwners, getPrimaryOwner } from './core/ownership/owner-resolver.js';
|
|
49
51
|
import { cleanupStartupHandoffs, recoverStartupHandoffs, resumePendingSessions, createDaemonShutdown, daemonConversationTotalExecutionMs, daemonConversationWatchdogMs, daemonIdleTimeoutMs, } from './core/daemon-lifecycle.js';
|
|
50
52
|
import { BootstrapService, createBootstrapCompletionHandler, createBootstrapOwnerBoundHandler } from './core/bootstrap-service.js';
|
|
@@ -55,10 +57,11 @@ import { AgentApplicationService } from './core/agent-application-service.js';
|
|
|
55
57
|
import { EventBus } from './core/event-bus.js';
|
|
56
58
|
import { detectAvailableBaseagents, runBindBootstrapDaemon } from './core/daemon-bootstrap.js';
|
|
57
59
|
import { migrateLegacyConsolidationBatches } from './core/memory/consolidation-context.js';
|
|
58
|
-
import { ConsolidationQueue, consolidationBlockedReason, createConsolidationFeedbackSender, createConsolidationSessionFinalizer, registerConsolidationSessionEvents, registerRelationConsolidationEvents, } from './core/memory/consolidation.js';
|
|
60
|
+
import { ConsolidationQueue, consolidationBlockedReason, createConsolidationFeedbackSender, createConsolidationSessionFinalizer, registerConsolidationSessionEvents, healMemoryIndexes, recoverRelationPendingNotes, registerRelationConsolidationEvents, } from './core/memory/consolidation.js';
|
|
59
61
|
import { RelationIdleMonitor, relationInboundFromLog } from './core/memory/relation-idle-monitor.js';
|
|
60
62
|
import { RelationSweepRunner } from './core/memory/relation-sweep.js';
|
|
61
63
|
import { setInboundLogListener } from './core/message/message-log.js';
|
|
64
|
+
import { setPendingNoteListener } from './core/memory/memory-writer.js';
|
|
62
65
|
import { StatsCollector } from './utils/stats.js';
|
|
63
66
|
import { AidStatsCollector } from './utils/stats.js';
|
|
64
67
|
import { initializeStatsPersistence } from './stats/writer.js';
|
|
@@ -216,15 +219,32 @@ async function main() {
|
|
|
216
219
|
// otherwise starts one and keeps it alive for the daemon's lifetime.
|
|
217
220
|
let ecwebSupervisor = null;
|
|
218
221
|
const ecwebConfig = ecwebService(daemonCfg.services);
|
|
219
|
-
|
|
222
|
+
{
|
|
220
223
|
ecwebSupervisor = createEcwebSupervisor({
|
|
221
|
-
port: ecwebConfig
|
|
224
|
+
port: ecwebConfig?.port ?? DEFAULT_ECWEB_PORT,
|
|
225
|
+
enabled: ecwebConfig?.enabled === true,
|
|
226
|
+
runtimeMode: ecwebConfig ? serviceRuntimeMode(ecwebConfig) : 'managed',
|
|
227
|
+
restart: ecwebConfig?.runtime?.restart,
|
|
222
228
|
logger,
|
|
223
229
|
});
|
|
224
|
-
// ECWeb is optional and has its own health checks/restart loop. Starting
|
|
225
|
-
// it must not hold up the daemon's agent/IPC initialization or ready
|
|
226
|
-
// signal; status will report it as starting until the first healthy probe.
|
|
227
230
|
onShutdown(() => ecwebSupervisor?.stop());
|
|
231
|
+
const removeEcwebConfigListener = onConfigWrite(({ target }) => {
|
|
232
|
+
if (target !== ConfigTarget.Process || !ecwebSupervisor)
|
|
233
|
+
return;
|
|
234
|
+
try {
|
|
235
|
+
const service = ecwebService(loadDaemonConfig().services);
|
|
236
|
+
void ecwebSupervisor.configure({
|
|
237
|
+
enabled: service?.enabled === true,
|
|
238
|
+
port: service?.port ?? DEFAULT_ECWEB_PORT,
|
|
239
|
+
runtimeMode: service ? serviceRuntimeMode(service) : 'managed',
|
|
240
|
+
restart: service?.runtime?.restart,
|
|
241
|
+
}).catch((error) => logger.warn(`ECWeb 配置热应用失败: ${error?.message || error}`));
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
logger.warn(`ECWeb 配置热应用失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
onShutdown(removeEcwebConfigListener);
|
|
228
248
|
void ecwebSupervisor.start().catch((error) => {
|
|
229
249
|
logger.warn(`ECWeb supervisor 启动失败(不影响 daemon 主流程): ${error?.message || error}`);
|
|
230
250
|
});
|
|
@@ -428,13 +448,13 @@ async function main() {
|
|
|
428
448
|
dedupPath: daemonMessageDedupPath(),
|
|
429
449
|
});
|
|
430
450
|
// 设置中断回调(精确中断正在处理的 agent)
|
|
431
|
-
messageQueue.setInterruptCallback(async (sessionKey, baseagent, evolagentName, reason = 'new_message', timeout, strict) => {
|
|
451
|
+
messageQueue.setInterruptCallback(async (sessionKey, baseagent, evolagentName, reason = 'new_message', timeout, strict, target) => {
|
|
432
452
|
void baseagent;
|
|
433
453
|
void evolagentName;
|
|
434
454
|
if (timeout)
|
|
435
|
-
await responseEngine.timeoutSession(sessionKey, timeout);
|
|
455
|
+
await responseEngine.timeoutSession(sessionKey, timeout, target);
|
|
436
456
|
else
|
|
437
|
-
await responseEngine.interruptSession(sessionKey, reason, strict);
|
|
457
|
+
await responseEngine.interruptSession(sessionKey, reason, strict, undefined, target);
|
|
438
458
|
});
|
|
439
459
|
messageQueue.setEventBus(eventBus);
|
|
440
460
|
// Restore persisted input before Trigger schedulers start. Trigger-owned work
|
|
@@ -480,7 +500,8 @@ async function main() {
|
|
|
480
500
|
const consolidationQueue = new ConsolidationQueue(daemonChannel);
|
|
481
501
|
const enqueueConsolidation = (params) => consolidationQueue.enqueue(params);
|
|
482
502
|
cmdHandler.setMemoryConsolidationLauncher(enqueueConsolidation);
|
|
483
|
-
//
|
|
503
|
+
// 关系级记忆整理:入站 / 写 note 推后计时,空闲 / 兜底到期跑该关系的整理链(notes → generalize → promote)。
|
|
504
|
+
// 画像与关系层遗忘是时间驱动的,由定时检查逐关系拉起(见 registerConsolidationCheckExecutor)。
|
|
484
505
|
const relationIdleMonitor = new RelationIdleMonitor({
|
|
485
506
|
statePath: path.join(paths.dataDir, 'relation-idle-state.json'),
|
|
486
507
|
getTiming: aid => agentRegistry.get(aid)?.config?.memory,
|
|
@@ -501,22 +522,31 @@ async function main() {
|
|
|
501
522
|
await ownerResolver.refresh(aid);
|
|
502
523
|
return getPrimaryOwner(aid);
|
|
503
524
|
},
|
|
504
|
-
onSweepFinished: ({ selfAid, peerKey, touchedPeerKeys }) => {
|
|
505
|
-
relationIdleMonitor.onSweepFinished(selfAid, peerKey);
|
|
506
|
-
//
|
|
525
|
+
onSweepFinished: ({ selfAid, peerKey, deferred, failed, touchedPeerKeys }) => {
|
|
526
|
+
relationIdleMonitor.onSweepFinished(selfAid, peerKey, { deferred, failed });
|
|
527
|
+
// 群链按发言人写入过的关系:它们不一定有自己的入站,记为一次活动,进入各自的空闲 / 兜底计时
|
|
507
528
|
for (const touched of touchedPeerKeys)
|
|
508
|
-
relationIdleMonitor.
|
|
529
|
+
relationIdleMonitor.recordActivity({ selfAid, peerKey: touched });
|
|
509
530
|
},
|
|
510
531
|
});
|
|
511
532
|
consolidationQueue.setLaunchFailedListener(params => relationSweeps.onLaunchFailed(params));
|
|
512
533
|
relationIdleMonitor.load();
|
|
534
|
+
// 整理会话不跨进程存活:上次退出时没收尾的 processing/ 归还 pending/;有 note 却没有时钟的关系补登
|
|
535
|
+
for (const { selfAid, peerKey, oldestNoteAt } of recoverRelationPendingNotes()) {
|
|
536
|
+
relationIdleMonitor.seedPending(selfAid, peerKey, oldestNoteAt);
|
|
537
|
+
}
|
|
538
|
+
// 索引自愈:MEMORY.md 缺失或指向已删文件的就重建(主会话注入的就是这份索引)。不阻塞启动。
|
|
539
|
+
void healMemoryIndexes({ indexMaxBytes: aid => agentRegistry.get(aid)?.config?.memory?.indexMaxBytes })
|
|
540
|
+
.catch(error => logger.warn(`[Memory] 索引自愈失败: ${error?.message}`));
|
|
513
541
|
setInboundLogListener((chatDir, entry) => {
|
|
514
542
|
const inbound = relationInboundFromLog(chatDir, entry);
|
|
515
543
|
if (inbound)
|
|
516
|
-
relationIdleMonitor.
|
|
544
|
+
relationIdleMonitor.recordActivity(inbound);
|
|
517
545
|
});
|
|
546
|
+
setPendingNoteListener((selfAid, peerKey) => relationIdleMonitor.recordActivity({ selfAid, peerKey }));
|
|
518
547
|
onShutdown(() => {
|
|
519
548
|
setInboundLogListener(undefined);
|
|
549
|
+
setPendingNoteListener(undefined);
|
|
520
550
|
relationIdleMonitor.stop();
|
|
521
551
|
});
|
|
522
552
|
const triggerControlToken = crypto.randomBytes(32).toString('base64url');
|
|
@@ -729,6 +759,13 @@ async function main() {
|
|
|
729
759
|
pending: messageQueue.getQueueLengthByAgent(queueAgentName),
|
|
730
760
|
processing: messageQueue.getProcessingCountByAgent(queueAgentName),
|
|
731
761
|
},
|
|
762
|
+
activity: {
|
|
763
|
+
received: usage.received,
|
|
764
|
+
sent: usage.sent,
|
|
765
|
+
errors: usage.errors,
|
|
766
|
+
interrupts: usage.interrupts,
|
|
767
|
+
completed: usage.completed,
|
|
768
|
+
},
|
|
732
769
|
usage: { calls: usage.modelCalls, tokens: usage.tokens, cost: usage.cost },
|
|
733
770
|
};
|
|
734
771
|
}),
|
|
@@ -757,6 +794,17 @@ async function main() {
|
|
|
757
794
|
return triggerSchedulers.statusSummary(from, Date.now());
|
|
758
795
|
},
|
|
759
796
|
getStatusSnapshot,
|
|
797
|
+
getServiceProxySnapshot: () => ({
|
|
798
|
+
source: 'daemon-config',
|
|
799
|
+
items: (daemonCfg.services ?? []).filter(service => !!service.proxy || service.name === 'ecweb').map(service => ({
|
|
800
|
+
name: service.name,
|
|
801
|
+
serviceEnabled: service.enabled === true,
|
|
802
|
+
proxyEnabled: service.proxy?.enabled === true,
|
|
803
|
+
source: service.proxy?.source ?? null,
|
|
804
|
+
serviceType: service.proxy?.serviceType ?? null,
|
|
805
|
+
visibility: service.proxy?.visibility ?? null,
|
|
806
|
+
})),
|
|
807
|
+
}),
|
|
760
808
|
}), async (argv, sessionId, delegationToken, delegationCommandHash) => {
|
|
761
809
|
const delegation = agentDelegationRegistry.validate(delegationToken, sessionId, delegationCommandHash);
|
|
762
810
|
if (!delegation.ok)
|
|
@@ -880,7 +928,8 @@ async function main() {
|
|
|
880
928
|
agentApplicationService,
|
|
881
929
|
agentInitializationService,
|
|
882
930
|
enqueueConsolidation,
|
|
883
|
-
|
|
931
|
+
getRelationRoute: (selfAid, peerKey) => relationIdleMonitor.routeOf(selfAid, peerKey),
|
|
932
|
+
isConsolidationPending: params => consolidationQueue.isPendingOrActive(params),
|
|
884
933
|
completeAgentBootstrap,
|
|
885
934
|
contactBinds: {
|
|
886
935
|
dingtalk: { register: registerPendingDingtalkContactBind, isChannelReady: isContactBindChannelReady },
|
|
@@ -948,6 +997,19 @@ async function main() {
|
|
|
948
997
|
bindService,
|
|
949
998
|
diagService,
|
|
950
999
|
getProcessOwners: getDaemonOwners,
|
|
1000
|
+
ecwebSupervisor,
|
|
1001
|
+
onServiceProxyManager: manager => {
|
|
1002
|
+
const authorizeManagedOperation = createDelegationAuthorizer({
|
|
1003
|
+
agentDelegationRegistry,
|
|
1004
|
+
sessionManager,
|
|
1005
|
+
getProcessOwners: getDaemonOwners,
|
|
1006
|
+
});
|
|
1007
|
+
registerProxyIpcExecutor(ipcServer, {
|
|
1008
|
+
manager,
|
|
1009
|
+
authorizeManagedOperation,
|
|
1010
|
+
getSession: sessionId => sessionManager.getSessionById(sessionId),
|
|
1011
|
+
});
|
|
1012
|
+
},
|
|
951
1013
|
});
|
|
952
1014
|
// 统一 channel:health 跨通道通知(仅 auth_error)
|
|
953
1015
|
registerChannelHealthNotifications({ eventBus, channelInstances, agentRegistry });
|