evolcore 0.0.45 → 0.0.47
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 +113 -0
- package/bin/ecmsg.js +33 -23
- package/dist/ability/application-service.js +1 -2
- package/dist/ability/package.js +28 -0
- package/dist/agent-template/jobs.js +158 -36
- package/dist/agent-template/runtime.js +401 -34
- package/dist/agent-template/service.js +764 -369
- package/dist/agent-template/tool-runner.js +35 -17
- package/dist/agent-template/types.js +7 -4
- package/dist/agents/baseagent.js +10 -9
- package/dist/agents/claude-runner.js +22 -6
- package/dist/agents/codex/app-server-client.js +34 -27
- package/dist/agents/codex/diagnostics.js +18 -1
- package/dist/agents/codex-runner.js +3 -1
- package/dist/agents/ecagent-runner.js +3 -1
- package/dist/agents/gemini-runner.js +2 -1
- package/dist/aun/group/fs-download.js +1 -1
- package/dist/aun/menu/client.js +142 -182
- package/dist/aun/rpc/client.js +33 -17
- package/dist/aun/service-proxy.js +6 -23
- package/dist/channels/aun.js +675 -120
- package/dist/channels/daemon.js +1 -1
- package/dist/cli/agent-create.js +37 -10
- package/dist/cli/agent-template.js +105 -84
- package/dist/cli/agent.js +31 -18
- package/dist/cli/daemon-commands.js +42 -56
- package/dist/cli/daemon-lifecycle-client.js +55 -19
- package/dist/cli/directory.js +12 -4
- package/dist/cli/ecmsg-gateway.js +5 -2
- package/dist/cli/events-command.js +2 -1
- package/dist/cli/init-channel.js +2 -2
- package/dist/cli/init.js +57 -21
- package/dist/cli/integrity-command.js +2 -0
- package/dist/cli/managed-command-guard.js +20 -1
- package/dist/cli/menu-client.js +7 -5
- package/dist/cli/restart-monitor.js +135 -46
- package/dist/cli/services-command.js +28 -5
- package/dist/cli/task-context.js +83 -15
- package/dist/cli/upgrade-command.js +4 -2
- package/dist/config/config-field-policy.js +24 -0
- package/dist/config/config-manager.js +49 -19
- package/dist/config/peer-book-store.js +167 -127
- package/dist/config/peer-role-resolver.js +24 -4
- package/dist/config/provider-identity-migration.js +158 -6
- package/dist/config/provider-identity.js +10 -4
- package/dist/config/provider-ipc-service.js +10 -2
- package/dist/config/provider-local-sync.js +2 -2
- package/dist/config/providers-config.js +95 -10
- package/dist/config/providers-import.js +4 -6
- package/dist/config/providers.js +14 -3
- package/dist/config/role-store.js +1 -1
- package/dist/config/schema-migration.js +123 -16
- package/dist/config/schema-registry.js +6 -2
- package/dist/config-store.js +9 -1
- package/dist/core/agent-application-service.js +56 -29
- package/dist/core/agent-create-status.js +3 -1
- package/dist/core/agent-creation-claim.js +1 -0
- package/dist/core/agent-ipc-registration.js +2 -2
- package/dist/core/agent-reload-coordinator.js +38 -1
- package/dist/core/agent-runtime.js +91 -43
- package/dist/core/auth/agent-delegation.js +13 -3
- package/dist/core/auth/delegation-diagnostics.js +56 -15
- package/dist/core/auth/operation-authorizer.js +2 -2
- package/dist/core/auth/operation-catalog.js +3 -3
- package/dist/core/bootstrap-service.js +3 -0
- package/dist/core/capability/capability-manager.js +3 -1
- package/dist/core/channel-loader.js +29 -3
- package/dist/core/channel-runtime.js +1 -1
- package/dist/core/command/agent-control.js +6 -5
- package/dist/core/command/agent-template-menu.js +32 -97
- package/dist/core/command/eventcenter-menu.js +61 -13
- package/dist/core/command/menu-catalog.js +11 -4
- package/dist/core/command/menu-handler.js +39 -12
- package/dist/core/command/menu-protocol.js +8 -16
- package/dist/core/command/skill-slash.js +6 -2
- package/dist/core/command/slash-handler.js +4 -6
- package/dist/core/command/team-workspace-bootstrap.js +1 -2
- package/dist/core/command/team-workspace-management-store.js +83 -0
- package/dist/core/command/team-workspace-management.js +1 -2
- package/dist/core/command/team-workspace-team.js +26 -3
- package/dist/core/daemon-bootstrap.js +11 -9
- package/dist/core/daemon-control.js +4 -7
- package/dist/core/daemon-lifecycle.js +189 -143
- package/dist/core/evolagent-registry.js +50 -2
- package/dist/core/evolagent.js +2 -1
- package/dist/core/file-integrity/read.js +9 -16
- package/dist/core/file-integrity/store.js +94 -34
- package/dist/core/handoff/dispatcher.js +33 -7
- package/dist/core/handoff/runtime.js +8 -0
- package/dist/core/host-snapshot.js +9 -4
- package/dist/core/inference/text-inference.js +12 -2
- package/dist/core/initialization/service.js +22 -4
- package/dist/core/invoke/invoke-service.js +24 -3
- package/dist/core/ipc-registration.js +7 -3
- package/dist/core/memory/consolidation.js +6 -6
- package/dist/core/message/aun-ipc-sender.js +109 -7
- package/dist/core/message/contact-admission.js +6 -2
- package/dist/core/message/message-bridge.js +13 -0
- package/dist/core/message/message-queue.js +131 -30
- package/dist/core/message/pending-hints.js +8 -0
- package/dist/core/message/response-engine.js +48 -2
- package/dist/core/message/send-routing.js +3 -12
- package/dist/core/model/catalog-service.js +13 -0
- package/dist/core/model/model-catalog.js +57 -18
- package/dist/core/ownership/owner-resolver.js +27 -10
- package/dist/core/pack-auth.js +163 -31
- package/dist/core/pack-install.js +42 -1
- package/dist/{services/ledger.js → core/pack-ledger.js} +17 -6
- package/dist/core/permission/ec-command-parser.js +3 -1
- package/dist/core/permission/shell-environment.js +23 -0
- package/dist/core/rate-window.js +6 -1
- package/dist/core/relation/peer-identity.js +5 -1
- package/dist/core/relation/same-owner-proof.js +2 -1
- package/dist/core/session/adapters/claude-session-file-adapter.js +1 -1
- package/dist/core/session/session-file-health.js +36 -7
- package/dist/core/session/session-idle-monitor.js +0 -1
- package/dist/core/session/session-manager.js +14 -0
- package/dist/core/session/session-title.js +26 -6
- package/dist/core/skill/index-generator.js +3 -4
- package/dist/core/task/task-image-resources.js +1 -1
- package/dist/core/thread/thread-service.js +0 -1
- package/dist/core/thread/topic-id.js +8 -0
- package/dist/directory/owner-directory-admission.js +17 -0
- package/dist/directory/owner-directory-cache.js +3 -1
- package/dist/directory/owner-directory-markdown.js +145 -23
- package/dist/directory/owner-directory-policy.js +23 -0
- package/dist/directory/owner-directory-query-operation.js +20 -6
- package/dist/directory/owner-directory-search.js +47 -0
- package/dist/eck/message-renderer.js +171 -32
- package/dist/ecweb/basic-settings-service.js +7 -3
- package/dist/ecweb/providers-service.js +17 -10
- package/dist/ecweb/runtime/lifecycle.js +65 -16
- package/dist/ecweb/runtime/supervisor.js +79 -50
- package/dist/event-center/admission-materializer.js +1 -1
- package/dist/event-center/bus-gate.js +48 -4
- package/dist/event-center/bus-host.js +3 -3
- package/dist/event-center/center-config.js +57 -28
- package/dist/event-center/dispatcher.js +8 -0
- package/dist/event-center/event-log.js +69 -27
- package/dist/event-center/index-generator.js +6 -1
- package/dist/event-center/ipc-operation.js +66 -25
- package/dist/event-center/pack-loader.js +12 -55
- package/dist/event-center/pack-manager.js +5 -3
- package/dist/event-center/registry.js +48 -52
- package/dist/event-center/runtime.js +219 -81
- package/dist/event-center/script-runner.js +18 -7
- package/dist/event-center/types.js +9 -1
- package/dist/event-center/validation.js +33 -4
- package/dist/index.js +132 -75
- package/dist/ipc.js +35 -8
- package/dist/product.js +1 -0
- package/dist/proxy/manager.js +52 -11
- package/dist/proxy/service-supervisor.js +265 -67
- package/dist/services/dispatcher.js +26 -3
- package/dist/services/idempotency.js +128 -0
- package/dist/services/identity.js +3 -27
- package/dist/services/index-generator.js +5 -1
- package/dist/services/index.js +244 -45
- package/dist/services/ipc-operation.js +164 -20
- package/dist/services/pack-manager.js +37 -9
- package/dist/services/router.js +100 -31
- package/dist/services/script-runner.js +15 -4
- package/dist/services/service-payload.js +50 -2
- package/dist/services/validation.js +107 -3
- package/dist/trigger/scheduler.js +18 -4
- package/dist/trigger/script-sandbox.js +39 -2
- package/dist/trigger/state.js +7 -0
- package/dist/utils/aid-bind.js +155 -18
- package/dist/utils/atomic-write.js +3 -3
- package/dist/utils/cross-platform.js +59 -16
- package/dist/utils/error-utils.js +26 -1
- package/dist/utils/instance-registry.js +94 -35
- package/dist/utils/process-introspect.js +187 -27
- package/dist/utils/project-path.js +47 -3
- package/dist/utils/upgrade-jobs.js +4 -4
- package/dist/utils/windows-shell-trust.js +174 -68
- package/kits/docs/context-assembly.md +3 -3
- package/kits/docs/evolcore/agent.md +28 -10
- package/kits/docs/evolcore/aid.md +3 -1
- package/kits/docs/evolcore/config.md +22 -0
- package/kits/docs/evolcore/directory.md +46 -12
- package/kits/docs/evolcore/event-center.md +6 -6
- package/kits/docs/evolcore/group-collaboration.md +1 -1
- package/kits/docs/evolcore/menu-client.md +7 -5
- package/kits/docs/evolcore/menu-protocol.md +5 -3
- package/kits/docs/evolcore/msg.md +10 -3
- package/kits/docs/evolcore/provider.md +17 -5
- package/kits/docs/evolcore/services.md +145 -12
- package/kits/docs/evolcore/thread-chain.md +17 -9
- package/kits/docs/prompt-loading-architecture.md +4 -4
- package/kits/eck_message_manifest.json +46 -3
- package/kits/rules/04-relation.md +10 -2
- package/kits/rules/06-channel.md +2 -1
- package/kits/schemas/providers.schema.2.json +1 -0
- package/kits/skills/ec-group/SKILL.md +4 -0
- package/kits/skills/ec-skill/scripts/cli.mjs +1 -1
- package/kits/skills/ec-skill/scripts/skill.mjs +13 -2
- package/kits/skills/thread-ops/SKILL.md +8 -5
- package/kits/templates/message-fragments/group-batch-item.md +3 -0
- package/kits/templates/message-fragments/group-batch.md +1 -0
- package/kits/templates/message-fragments/item-group.md +4 -0
- package/kits/templates/message-fragments/item-private.md +4 -0
- package/kits/templates/message-fragments/thread-context.md +1 -1
- package/kits/templates/system-fragments/commands.md +5 -5
- package/kits/templates/system-fragments/managed-runtime.md +1 -1
- package/kits/templates/system-fragments/relation.md +11 -7
- package/package.json +3 -2
- package/scripts/agent-template/index.mjs +9 -4
- package/scripts/agent-template/inspect.mjs +16 -9
- package/scripts/agent-template/shared/plan.mjs +3 -33
- package/scripts/agent-template/shared/template-contract.mjs +186 -3
- package/scripts/agent-template/shared/template-package.mjs +119 -10
- package/scripts/agent-template/shared/template-runtime.mjs +49 -6
- package/scripts/agent-template/shared/template.mjs +5 -5
- package/scripts/agent-template/team-pack.mjs +245 -0
- package/scripts/agent-template/team-preview.mjs +111 -0
- package/scripts/aid-batch/identity-batch.mjs +143 -0
- package/dist/ability/versions.js +0 -32
- package/dist/aun/model-headers.js +0 -17
- package/dist/channels/builtin-plugins.js +0 -19
- package/dist/core/command/team-workspace-initializer.js +0 -2
- package/dist/core/command/team-workspace-job-store.js +0 -88
- package/dist/core/command/team-workspace-management-service.js +0 -2
- package/dist/core/contact-bind-registry.js +0 -27
- package/dist/event-center/ledger.js +0 -52
- package/dist/services/reply.js +0 -55
- package/kits/templates/message-fragments/item.md +0 -3
- package/scripts/agent-template/pack.mjs +0 -169
|
@@ -6,9 +6,11 @@ import { resolvePaths } from '../paths.js';
|
|
|
6
6
|
import { acquireConfigMutationLock, ConfigError } from './config-manager.js';
|
|
7
7
|
import { firstConfiguredOwner } from './owner-config.js';
|
|
8
8
|
import { currentVersion, loadSchema } from './schema-registry.js';
|
|
9
|
-
import { planProviderIdentityMigration } from './provider-identity-migration.js';
|
|
9
|
+
import { planProviderIdentityMigration, validateProviderIdentityMigrationPlan } from './provider-identity-migration.js';
|
|
10
10
|
import { providerIdentity } from './provider-identity.js';
|
|
11
11
|
import { snapshot } from './snapshot.js';
|
|
12
|
+
import { logger } from '../utils/logger.js';
|
|
13
|
+
import { atomicReplaceFile } from '../utils/atomic-write.js';
|
|
12
14
|
const MIGRATION_KIND = {
|
|
13
15
|
'auxiliary-model-v1': 'auxiliary-model',
|
|
14
16
|
'agent-only-model-v1': 'agent-only-model',
|
|
@@ -42,20 +44,24 @@ function hasOwn(value, field) {
|
|
|
42
44
|
return Object.prototype.hasOwnProperty.call(value, field);
|
|
43
45
|
}
|
|
44
46
|
let startupReadCache = null;
|
|
47
|
+
let startupRelationFiles = null;
|
|
45
48
|
/**
|
|
46
49
|
* 在这个作用域内共享配置读取结果。
|
|
47
50
|
*
|
|
48
51
|
* 只能包住「只读规划」阶段:一旦有迁移落盘,缓存里的内容就过期了。
|
|
49
|
-
*
|
|
52
|
+
* 配置文本与关系文件列表共用作用域,结束后自动失效。
|
|
50
53
|
*/
|
|
51
54
|
export async function withMigrationReadCache(run) {
|
|
52
55
|
const previous = startupReadCache;
|
|
56
|
+
const previousRelations = startupRelationFiles;
|
|
53
57
|
startupReadCache = new Map();
|
|
58
|
+
startupRelationFiles = new Map();
|
|
54
59
|
try {
|
|
55
60
|
return await run();
|
|
56
61
|
}
|
|
57
62
|
finally {
|
|
58
63
|
startupReadCache = previous;
|
|
64
|
+
startupRelationFiles = previousRelations;
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
/**
|
|
@@ -68,6 +74,7 @@ export async function withMigrationReadCache(run) {
|
|
|
68
74
|
*/
|
|
69
75
|
export function invalidateMigrationReadCache() {
|
|
70
76
|
startupReadCache?.clear();
|
|
77
|
+
startupRelationFiles?.clear();
|
|
71
78
|
}
|
|
72
79
|
function readJson(file) {
|
|
73
80
|
if (startupReadCache) {
|
|
@@ -374,6 +381,9 @@ function migrateConfig(input, file, parentContext) {
|
|
|
374
381
|
};
|
|
375
382
|
}
|
|
376
383
|
function walkRelationConfigs(dir) {
|
|
384
|
+
const cached = startupRelationFiles?.get(dir);
|
|
385
|
+
if (cached)
|
|
386
|
+
return cached;
|
|
377
387
|
if (!fs.existsSync(dir))
|
|
378
388
|
return [];
|
|
379
389
|
const files = [];
|
|
@@ -386,6 +396,7 @@ function walkRelationConfigs(dir) {
|
|
|
386
396
|
else if (entry.isFile() && entry.name === 'config.json')
|
|
387
397
|
files.push(full);
|
|
388
398
|
}
|
|
399
|
+
startupRelationFiles?.set(dir, files);
|
|
389
400
|
return files;
|
|
390
401
|
}
|
|
391
402
|
function planConfigFile(file, parentContext, changes, summary) {
|
|
@@ -525,10 +536,55 @@ function acquireLock(home, id) {
|
|
|
525
536
|
}
|
|
526
537
|
function atomicWrite(file, content) {
|
|
527
538
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
528
|
-
const
|
|
539
|
+
const exists = fs.existsSync(file);
|
|
540
|
+
const mode = exists ? fs.statSync(file).mode & 0o777 : 0o600;
|
|
541
|
+
const windows = process.platform === 'win32';
|
|
542
|
+
const readonly = windows && exists && (mode & 0o200) === 0;
|
|
529
543
|
const temp = `${file}.schema-migration-${process.pid}-${crypto.randomBytes(6).toString('hex')}.tmp`;
|
|
530
|
-
|
|
531
|
-
|
|
544
|
+
let restoreReadonly = false;
|
|
545
|
+
let failure;
|
|
546
|
+
let failed = false;
|
|
547
|
+
try {
|
|
548
|
+
// A Windows readonly temporary file cannot be safely cleaned up on failure.
|
|
549
|
+
fs.writeFileSync(temp, content, { mode: windows ? mode | 0o200 : mode, flag: 'wx' });
|
|
550
|
+
if (readonly) {
|
|
551
|
+
fs.chmodSync(file, mode | 0o200);
|
|
552
|
+
restoreReadonly = true;
|
|
553
|
+
}
|
|
554
|
+
// Migration journals restore complete files; never truncate the live file
|
|
555
|
+
// as a fallback when Windows refuses to replace its directory entry.
|
|
556
|
+
atomicReplaceFile(temp, file, { allowInPlaceFallback: false });
|
|
557
|
+
}
|
|
558
|
+
catch (error) {
|
|
559
|
+
failed = true;
|
|
560
|
+
failure = error;
|
|
561
|
+
}
|
|
562
|
+
finally {
|
|
563
|
+
if (restoreReadonly) {
|
|
564
|
+
try {
|
|
565
|
+
fs.chmodSync(file, mode);
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
failure = failed ? migrationRecoveryFailure(failure, error, 'Restoring readonly attribute failed') : error;
|
|
569
|
+
failed = true;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
try {
|
|
573
|
+
fs.rmSync(temp, { force: true });
|
|
574
|
+
}
|
|
575
|
+
catch (error) {
|
|
576
|
+
logger.warn(`[config] Could not remove migration temporary file ${temp}: ${error}`);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
if (failed)
|
|
580
|
+
throw failure;
|
|
581
|
+
}
|
|
582
|
+
function migrationRecoveryFailure(original, recovery, step) {
|
|
583
|
+
const detail = (error) => error instanceof Error ? error.message : String(error);
|
|
584
|
+
const error = new AggregateError([original, recovery], `${detail(original)}; ${step}: ${detail(recovery)}`, {
|
|
585
|
+
cause: original,
|
|
586
|
+
});
|
|
587
|
+
return Object.assign(error, isRecord(original) && typeof original.code === 'string' ? { code: original.code } : {});
|
|
532
588
|
}
|
|
533
589
|
function journalPath(home, id) {
|
|
534
590
|
return path.join(home, 'data', `${id}-migration.json`);
|
|
@@ -538,7 +594,11 @@ function writeJournal(plan, state, id) {
|
|
|
538
594
|
schemaVersion: 1,
|
|
539
595
|
state,
|
|
540
596
|
home: plan.home,
|
|
541
|
-
changes: plan.changes
|
|
597
|
+
changes: plan.changes.map(item => ({
|
|
598
|
+
...item,
|
|
599
|
+
...(process.platform === 'win32' && item.before !== null
|
|
600
|
+
? { mode: fs.statSync(item.file).mode & 0o777 } : {}),
|
|
601
|
+
})),
|
|
542
602
|
};
|
|
543
603
|
atomicWrite(journalPath(plan.home, id), jsonText(journal));
|
|
544
604
|
}
|
|
@@ -563,7 +623,8 @@ function readJournal(home, id) {
|
|
|
563
623
|
const changes = [];
|
|
564
624
|
for (const item of raw.changes) {
|
|
565
625
|
if (!isRecord(item) || typeof item.file !== 'string' || typeof item.after !== 'string'
|
|
566
|
-
|| (item.before !== null && typeof item.before !== 'string')
|
|
626
|
+
|| (item.before !== null && typeof item.before !== 'string')
|
|
627
|
+
|| (item.mode !== undefined && (!Number.isInteger(item.mode) || Number(item.mode) < 0 || Number(item.mode) > 0o777))) {
|
|
567
628
|
throw new Error(`Migration journal contains an unsafe change: ${file}`);
|
|
568
629
|
}
|
|
569
630
|
const target = path.resolve(item.file);
|
|
@@ -575,6 +636,7 @@ function readJournal(home, id) {
|
|
|
575
636
|
kind: MIGRATION_KIND[id],
|
|
576
637
|
before: item.before,
|
|
577
638
|
after: item.after,
|
|
639
|
+
...(typeof item.mode === 'number' ? { mode: item.mode } : {}),
|
|
578
640
|
});
|
|
579
641
|
}
|
|
580
642
|
return {
|
|
@@ -592,8 +654,27 @@ function recoverJournal(home, id) {
|
|
|
592
654
|
for (const item of [...journal.changes].reverse()) {
|
|
593
655
|
if (item.before === null)
|
|
594
656
|
fs.rmSync(item.file, { force: true });
|
|
595
|
-
else
|
|
596
|
-
|
|
657
|
+
else {
|
|
658
|
+
// A failed first replacement may leave the original already intact.
|
|
659
|
+
// Replacing it again can repeat the same Windows access error forever.
|
|
660
|
+
let current;
|
|
661
|
+
try {
|
|
662
|
+
current = fs.readFileSync(item.file, 'utf8');
|
|
663
|
+
}
|
|
664
|
+
catch (error) {
|
|
665
|
+
if (!isRecord(error) || error.code !== 'ENOENT')
|
|
666
|
+
throw error;
|
|
667
|
+
current = null;
|
|
668
|
+
}
|
|
669
|
+
if (current !== item.before)
|
|
670
|
+
atomicWrite(item.file, item.before);
|
|
671
|
+
// Also restore readonly after a crash between chmod and replacement,
|
|
672
|
+
// including when the original bytes were never changed.
|
|
673
|
+
if (process.platform === 'win32' && item.mode !== undefined
|
|
674
|
+
&& (fs.statSync(item.file).mode & 0o200) !== (item.mode & 0o200)) {
|
|
675
|
+
fs.chmodSync(item.file, item.mode);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
597
678
|
}
|
|
598
679
|
}
|
|
599
680
|
fs.rmSync(journalPath(home, id), { force: true });
|
|
@@ -633,7 +714,12 @@ function applyMigration(plan, id) {
|
|
|
633
714
|
fs.rmSync(journalPath(plan.home, id), { force: true });
|
|
634
715
|
}
|
|
635
716
|
catch (error) {
|
|
636
|
-
|
|
717
|
+
try {
|
|
718
|
+
recoverJournal(plan.home, id);
|
|
719
|
+
}
|
|
720
|
+
catch (recovery) {
|
|
721
|
+
throw migrationRecoveryFailure(error, recovery, 'Migration rollback failed');
|
|
722
|
+
}
|
|
637
723
|
throw error;
|
|
638
724
|
}
|
|
639
725
|
return backup;
|
|
@@ -1303,16 +1389,17 @@ function planAgentModelProviderMigration(home) {
|
|
|
1303
1389
|
value.$schema_version = AGENT_CONFIG_RESTAMP.to;
|
|
1304
1390
|
}
|
|
1305
1391
|
summary.gatewayFieldsRemoved += removed.length;
|
|
1306
|
-
|
|
1307
|
-
if (nextText === entry.text)
|
|
1392
|
+
if (isDeepStrictEqual(value, entry.value))
|
|
1308
1393
|
continue;
|
|
1394
|
+
const nextText = jsonText(value);
|
|
1309
1395
|
changes.push({ file, kind: 'agent-only-model', before: entry.text, after: nextText });
|
|
1310
1396
|
details.push({ file: path.relative(home, file), removed });
|
|
1311
1397
|
summary.filesChanged += 1;
|
|
1312
1398
|
}
|
|
1313
1399
|
if (Object.keys(providers).length > 0) {
|
|
1314
|
-
const
|
|
1315
|
-
if (
|
|
1400
|
+
const nextRegistry = { $schema_version: 1, ...providerRegistry, providers };
|
|
1401
|
+
if (!isDeepStrictEqual(nextRegistry, providerRegistry)) {
|
|
1402
|
+
const nextText = jsonText(nextRegistry);
|
|
1316
1403
|
changes.push({ file: providersFile, kind: 'agent-only-model', before: providersBefore, after: nextText });
|
|
1317
1404
|
details.push({ file: 'providers.json', removed: [] });
|
|
1318
1405
|
summary.filesChanged += 1;
|
|
@@ -1420,7 +1507,14 @@ export function runProviderIdentitySchemaMigration(options = {}) {
|
|
|
1420
1507
|
try {
|
|
1421
1508
|
assertDaemonStopped(home);
|
|
1422
1509
|
recoverJournal(home, id);
|
|
1423
|
-
|
|
1510
|
+
let plan;
|
|
1511
|
+
try {
|
|
1512
|
+
plan = planProviderIdentityMigration(home, undefined, { cleanupAliases: true });
|
|
1513
|
+
}
|
|
1514
|
+
catch (error) {
|
|
1515
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
1516
|
+
throw new ConfigError('PROVIDER_IDENTITY_PLAN_FAILED', `Provider identity migration planning failed: ${detail}`, { cause: error });
|
|
1517
|
+
}
|
|
1424
1518
|
const backup = options.apply ? commitProviderSyncMigration(plan, true) : null;
|
|
1425
1519
|
return { ok: true, mode: options.apply ? 'applied' : 'dry-run',
|
|
1426
1520
|
home, changedFiles: plan.changes.length, backup, summary: plan.summary, pending: plan.pending };
|
|
@@ -1435,7 +1529,19 @@ export async function ensureProviderIdentityMigrationOnStartup() {
|
|
|
1435
1529
|
return result.changedFiles === 0 && result.pending.length === 0 ? null : result;
|
|
1436
1530
|
}
|
|
1437
1531
|
catch (error) {
|
|
1438
|
-
|
|
1532
|
+
if (!(error instanceof ConfigError) || error.code !== 'PROVIDER_IDENTITY_PLAN_FAILED') {
|
|
1533
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
1534
|
+
throw new ConfigError('PROVIDER_IDENTITY_MIGRATION_FAILED', `Automatic Provider identity migration failed: ${detail}`, { cause: error });
|
|
1535
|
+
}
|
|
1536
|
+
const cause = isRecord(error.data) ? error.data.cause : error;
|
|
1537
|
+
const code = isRecord(cause) && typeof cause.code === 'string'
|
|
1538
|
+
? cause.code : 'PROVIDER_IDENTITY_PLAN_FAILED';
|
|
1539
|
+
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
1540
|
+
const message = `[config] Automatic Provider identity migration skipped [${code}]: ${detail}; `
|
|
1541
|
+
+ 'continuing startup with existing configuration';
|
|
1542
|
+
logger.warn(message);
|
|
1543
|
+
console.error(`⚠ ${message}`);
|
|
1544
|
+
return null;
|
|
1439
1545
|
}
|
|
1440
1546
|
}
|
|
1441
1547
|
export function commitProviderSyncMigration(plan, migrationLocked = false) {
|
|
@@ -1464,6 +1570,7 @@ export function commitProviderSyncMigration(plan, migrationLocked = false) {
|
|
|
1464
1570
|
throw Object.assign(new Error('Configuration changed during Provider sync; retry after reviewing the current configuration'), { code: 'CONFLICT' });
|
|
1465
1571
|
}
|
|
1466
1572
|
}
|
|
1573
|
+
validateProviderIdentityMigrationPlan(plan);
|
|
1467
1574
|
return applyMigration(plan, id);
|
|
1468
1575
|
}
|
|
1469
1576
|
finally {
|
|
@@ -12,13 +12,17 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import fs from 'fs';
|
|
14
14
|
import path from 'path';
|
|
15
|
-
import
|
|
15
|
+
import { createRequire } from 'node:module';
|
|
16
16
|
import { kitsSchemasDir } from '../paths.js';
|
|
17
17
|
import { createErrorCapturingReader, fileCache } from '../core/daemon-file-cache.js';
|
|
18
18
|
let _ajv = null;
|
|
19
|
+
const requireSchemaDependency = createRequire(import.meta.url);
|
|
19
20
|
function ajv() {
|
|
20
21
|
if (!_ajv) {
|
|
21
|
-
|
|
22
|
+
// Version/metadata readers do not compile schemas. Keep the synchronous
|
|
23
|
+
// validator contract without loading Ajv into every lifecycle client.
|
|
24
|
+
const AjvConstructor = requireSchemaDependency('ajv');
|
|
25
|
+
_ajv = new AjvConstructor({ allErrors: true, strict: false, useDefaults: false });
|
|
22
26
|
}
|
|
23
27
|
return _ajv;
|
|
24
28
|
}
|
package/dist/config-store.js
CHANGED
|
@@ -32,6 +32,7 @@ import { parseStableSemver } from './utils/stable-semver.js';
|
|
|
32
32
|
import { isSupportedBaseagent } from './agents/baseagent.js';
|
|
33
33
|
import { normalizeDaemonServices } from './config/daemon-services.js';
|
|
34
34
|
import { currentVersion } from './config/schema-registry.js';
|
|
35
|
+
import { assertProjectPathReference } from './utils/project-path.js';
|
|
35
36
|
import { assertOwnerConfigRecord } from './config/owner-config.js';
|
|
36
37
|
const SERVICE_METADATA_SENSITIVE_KEY = /(?:^|[_-])(endpoint|url|uri|token|access[_-]?token|authorization|cookie|secret|password|private[_-]?key|key|cert|certificate)(?:$|[_-])/i;
|
|
37
38
|
function assertLocalServiceEndpoint(value, fieldPath) {
|
|
@@ -354,10 +355,15 @@ export function loadDefaults() {
|
|
|
354
355
|
if (typeof raw.$schema_version !== 'number') {
|
|
355
356
|
logger.warn(`[config] ${p}: missing $schema_version, treating as ${CONFIG_SCHEMA_VERSION}`);
|
|
356
357
|
}
|
|
357
|
-
|
|
358
|
+
// Like Provider connection references, project paths stay literal until used.
|
|
359
|
+
// Other fields retain the legacy expansion behavior for compatibility.
|
|
360
|
+
const { projects, ...rest } = stripLegacyAunGatewayConfig(raw, p, message => logger.warn(message));
|
|
361
|
+
return { ...expandEnvRefs(rest), ...(projects === undefined ? {} : { projects }) };
|
|
358
362
|
}
|
|
359
363
|
export function saveDefaults(value) {
|
|
360
364
|
assertNoLegacyAunGatewayConfig(value, resolvePaths().defaultsConfig);
|
|
365
|
+
if (typeof value.projects?.defaultPath === 'string')
|
|
366
|
+
assertProjectPathReference(value.projects.defaultPath);
|
|
361
367
|
backupDefaults(resolvePaths().defaultsConfig);
|
|
362
368
|
atomicWriteJson(resolvePaths().defaultsConfig, stripLegacyAunGatewayConfig(value, resolvePaths().defaultsConfig, message => logger.warn(message)));
|
|
363
369
|
}
|
|
@@ -392,6 +398,8 @@ function backupDefaults(filePath) {
|
|
|
392
398
|
export function saveDefaultsSafe(patch) {
|
|
393
399
|
const p = resolvePaths().defaultsConfig;
|
|
394
400
|
assertNoLegacyAunGatewayConfig(patch, p);
|
|
401
|
+
if (typeof patch.projects?.defaultPath === 'string')
|
|
402
|
+
assertProjectPathReference(patch.projects.defaultPath);
|
|
395
403
|
let existing = null;
|
|
396
404
|
try {
|
|
397
405
|
existing = atomicReadJson(p);
|
|
@@ -44,6 +44,21 @@ function errorFrom(error, fallback = 'agent operation failed') {
|
|
|
44
44
|
...(busyCount === undefined ? {} : { busyCount }),
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
+
/** Only ENOENT permits orphan cleanup; unreadable or invalid configs remain errors. */
|
|
48
|
+
function assertAgentConfigMissing(aid) {
|
|
49
|
+
const file = path.join(resolvePaths().agentsDir, aid, 'config.json');
|
|
50
|
+
for (const candidate of [file, `${file}_`]) {
|
|
51
|
+
try {
|
|
52
|
+
fs.readFileSync(candidate);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error.code === 'ENOENT')
|
|
56
|
+
continue;
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
throw Object.assign(new Error(`Agent "${aid}" configuration exists; retry the operation`), { code: 'CONFLICT' });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
47
62
|
/**
|
|
48
63
|
* Core-owned agent application facade. It contains no role resolution: callers
|
|
49
64
|
* must authorize the operation before invoking it. External CLI callers use
|
|
@@ -267,13 +282,14 @@ export class AgentApplicationService {
|
|
|
267
282
|
async enable(aid, force = false) {
|
|
268
283
|
return await this.setEnabled(aid, true, force);
|
|
269
284
|
}
|
|
270
|
-
async disable(aid, force = false) {
|
|
271
|
-
return await this.setEnabled(aid, false, force);
|
|
285
|
+
async disable(aid, force = false, guard) {
|
|
286
|
+
return await this.setEnabled(aid, false, force, guard);
|
|
272
287
|
}
|
|
273
|
-
async setEnabled(aid, enabled, force) {
|
|
288
|
+
async setEnabled(aid, enabled, force, guard) {
|
|
274
289
|
let config;
|
|
275
290
|
try {
|
|
276
291
|
await this.deps.beforeAgentOperation?.(aid);
|
|
292
|
+
guard?.();
|
|
277
293
|
if (enabled)
|
|
278
294
|
assertAgentAidAvailable(aid);
|
|
279
295
|
config = loadAgent(aid);
|
|
@@ -281,10 +297,35 @@ export class AgentApplicationService {
|
|
|
281
297
|
catch (error) {
|
|
282
298
|
return errorFrom(error, 'failed to read agent config');
|
|
283
299
|
}
|
|
284
|
-
if (!config)
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
300
|
+
if (!config) {
|
|
301
|
+
try {
|
|
302
|
+
assertAgentConfigMissing(aid);
|
|
303
|
+
if (enabled || !this.deps.registry.get(aid)) {
|
|
304
|
+
return { ok: false, error: `Agent "${aid}" not found`, code: 'NOT_FOUND' };
|
|
305
|
+
}
|
|
306
|
+
await this.initialization?.cancel(aid);
|
|
307
|
+
await this.deps.unload(aid, {
|
|
308
|
+
force,
|
|
309
|
+
prepare: async () => {
|
|
310
|
+
guard?.();
|
|
311
|
+
assertAgentConfigMissing(aid);
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
return { ok: true, aid, enabled: false, reloaded: true, configMissing: true };
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
return errorFrom(error, 'failed to unload orphaned agent');
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (!enabled) {
|
|
321
|
+
try {
|
|
322
|
+
await this.initialization?.cancel(aid);
|
|
323
|
+
guard?.();
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
return errorFrom(error, 'agent changed before disable');
|
|
327
|
+
}
|
|
328
|
+
}
|
|
288
329
|
const previousEnabled = config.enabled;
|
|
289
330
|
try {
|
|
290
331
|
if (enabled) {
|
|
@@ -307,6 +348,7 @@ export class AgentApplicationService {
|
|
|
307
348
|
else
|
|
308
349
|
config.enabled = previousEnabled;
|
|
309
350
|
try {
|
|
351
|
+
guard?.();
|
|
310
352
|
saveAgent(config);
|
|
311
353
|
}
|
|
312
354
|
catch (error) {
|
|
@@ -322,28 +364,13 @@ export class AgentApplicationService {
|
|
|
322
364
|
async delete(aid, purge = false) {
|
|
323
365
|
try {
|
|
324
366
|
await this.deps.beforeAgentOperation?.(aid);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const configPath = path.join(agentDir, 'config.json');
|
|
333
|
-
if (!fs.existsSync(configPath))
|
|
334
|
-
return { ok: false, error: `Agent "${aid}" not found`, code: 'NOT_FOUND' };
|
|
335
|
-
try {
|
|
336
|
-
await removeAgentFiles(aid, purge);
|
|
337
|
-
notifyConfigWrite(ConfigTarget.Agent, { self: aid });
|
|
338
|
-
let stopped = false;
|
|
339
|
-
try {
|
|
340
|
-
const result = await this.resync();
|
|
341
|
-
if (result.ok)
|
|
342
|
-
stopped = result.results.some(item => item.includes(aid));
|
|
343
|
-
}
|
|
344
|
-
catch (error) {
|
|
345
|
-
logger.warn(`[agent-service] resync after delete ${aid} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
346
|
-
}
|
|
367
|
+
await this.initialization?.cancel(aid);
|
|
368
|
+
const stopped = await this.deps.unload(aid, {
|
|
369
|
+
prepare: async () => {
|
|
370
|
+
await removeAgentFiles(aid, purge);
|
|
371
|
+
notifyConfigWrite(ConfigTarget.Agent, { self: aid });
|
|
372
|
+
},
|
|
373
|
+
});
|
|
347
374
|
return { ok: true, aid, purged: purge, stopped };
|
|
348
375
|
}
|
|
349
376
|
catch (error) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Agent 创建状态、初始化进度投影与删除后的磁盘清理。 */
|
|
2
2
|
import fs from 'fs';
|
|
3
|
+
import { templateInstallationGate } from '../agent-template/jobs.js';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import { randomUUID } from 'node:crypto';
|
|
5
6
|
import { creationOwnershipBinding } from './ownership/owner-resolver.js';
|
|
@@ -163,7 +164,8 @@ export function initializationCreateProgress(record, lifecycle, configOperationI
|
|
|
163
164
|
if (!record || record.mode !== 'one_shot')
|
|
164
165
|
return undefined;
|
|
165
166
|
const targetChanged = record.status === 'complete' && lifecycle === 'active' && configOperationId !== record.operationId;
|
|
166
|
-
const ready = record.status === 'complete' && lifecycle === 'active' && record.ownerConfirmed === true && !targetChanged
|
|
167
|
+
const ready = record.status === 'complete' && lifecycle === 'active' && record.ownerConfirmed === true && !targetChanged
|
|
168
|
+
&& !templateInstallationGate(record.plan.aid, record.teamJobId).blocked;
|
|
167
169
|
const failed = record.status === 'failed' || record.status === 'cancelled' || targetChanged;
|
|
168
170
|
// The SDK may need Owner consensus to publish the first valid agent.md. Keep
|
|
169
171
|
// that wait on the existing card-upload row until the profile is verified.
|
|
@@ -138,6 +138,7 @@ function claimAgentCreationLocked(request) {
|
|
|
138
138
|
...(request.ownerAid ? { ownerAid: request.ownerAid } : {}),
|
|
139
139
|
...(request.clientRequestId ? { clientRequestId: request.clientRequestId } : {}),
|
|
140
140
|
...(request.fingerprint ? { fingerprint: request.fingerprint } : {}),
|
|
141
|
+
...(request.teamJobId ? { teamJobId: request.teamJobId } : {}),
|
|
141
142
|
pid: process.pid,
|
|
142
143
|
host: os.hostname(),
|
|
143
144
|
startedAt: now,
|
|
@@ -44,7 +44,7 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
44
44
|
try {
|
|
45
45
|
const { parseTemplateCommand } = await import('../cli/agent-template.js');
|
|
46
46
|
const parsed = parseTemplateCommand(argv.slice(2));
|
|
47
|
-
templateOperation = 'agent.template.' + (parsed.action
|
|
47
|
+
templateOperation = 'agent.template.' + (parsed.action);
|
|
48
48
|
}
|
|
49
49
|
catch (error) {
|
|
50
50
|
return fail(error.code ?? 'INVALID_ARGUMENT', error.message);
|
|
@@ -144,7 +144,7 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
144
144
|
try {
|
|
145
145
|
const { executeTemplateCommand } = await import('../cli/agent-template.js');
|
|
146
146
|
const result = await executeTemplateCommand(delegation.grant.actorId, argv.slice(2));
|
|
147
|
-
return
|
|
147
|
+
return { ok: true, result };
|
|
148
148
|
}
|
|
149
149
|
catch (error) {
|
|
150
150
|
return fail(error.code ?? 'INVALID_ARGUMENT', error.message);
|
|
@@ -12,12 +12,43 @@ export class AgentReloadBusyError extends Error {
|
|
|
12
12
|
export class AgentReloadCoordinator {
|
|
13
13
|
deps;
|
|
14
14
|
inFlight = new Map();
|
|
15
|
+
held = new Map();
|
|
15
16
|
constructor(deps) {
|
|
16
17
|
this.deps = deps;
|
|
17
18
|
}
|
|
18
19
|
busyCount(aid) {
|
|
19
20
|
return Math.max(0, this.deps.getBusyCount(aid));
|
|
20
21
|
}
|
|
22
|
+
/** Reserve immediately, without waiting behind a running mutation or runner load. */
|
|
23
|
+
async acquireForMutation(aid, token) {
|
|
24
|
+
if (!token || this.held.has(aid) || this.inFlight.has(aid))
|
|
25
|
+
throw new AgentReloadBusyError(aid, 1);
|
|
26
|
+
this.held.set(aid, token);
|
|
27
|
+
let release = undefined;
|
|
28
|
+
try {
|
|
29
|
+
release = await this.deps.acquireWorkGate?.(aid, token);
|
|
30
|
+
const busy = this.busyCount(aid);
|
|
31
|
+
if (busy)
|
|
32
|
+
throw new AgentReloadBusyError(aid, busy);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
try {
|
|
36
|
+
await release?.();
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
if (this.held.get(aid) === token)
|
|
40
|
+
this.held.delete(aid);
|
|
41
|
+
}
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
return async () => {
|
|
45
|
+
if (this.held.get(aid) !== token)
|
|
46
|
+
return;
|
|
47
|
+
await release?.();
|
|
48
|
+
if (this.held.get(aid) === token)
|
|
49
|
+
this.held.delete(aid);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
21
52
|
runExclusive(aid, operation, options = {}) {
|
|
22
53
|
return this.runRunnerOperation(aid, async () => {
|
|
23
54
|
const releaseWorkGate = await this.deps.acquireWorkGate?.(aid);
|
|
@@ -36,8 +67,14 @@ export class AgentReloadCoordinator {
|
|
|
36
67
|
}
|
|
37
68
|
/** Serialize runner creation with mutations, without rejecting the task that requested it as busy. */
|
|
38
69
|
runRunnerOperation(aid, operation) {
|
|
70
|
+
if (this.held.has(aid))
|
|
71
|
+
return Promise.reject(new AgentReloadBusyError(aid, 1));
|
|
39
72
|
const previous = this.inFlight.get(aid) ?? Promise.resolve();
|
|
40
|
-
const pending = previous.catch(() => undefined).then(
|
|
73
|
+
const pending = previous.catch(() => undefined).then(() => {
|
|
74
|
+
if (this.held.has(aid))
|
|
75
|
+
throw new AgentReloadBusyError(aid, 1);
|
|
76
|
+
return operation();
|
|
77
|
+
});
|
|
41
78
|
this.inFlight.set(aid, pending);
|
|
42
79
|
return pending.finally(() => {
|
|
43
80
|
if (this.inFlight.get(aid) === pending)
|