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
package/dist/channels/daemon.js
CHANGED
|
@@ -48,7 +48,7 @@ export class DaemonChannel {
|
|
|
48
48
|
// 启动前跑一次 expire 扫描(成本低,只读少量小文件)
|
|
49
49
|
this.runExpireCleanupSafely();
|
|
50
50
|
const runId = ctx.runId;
|
|
51
|
-
const pendingId = ctx.attemptId ?? runId;
|
|
51
|
+
const pendingId = ctx.deliveryId ?? ctx.attemptId ?? runId;
|
|
52
52
|
const messageId = pendingId;
|
|
53
53
|
const startedAt = Date.now();
|
|
54
54
|
const remainingExecutionMs = typeof ctx.executionDeadlineAt === 'number'
|
package/dist/cli/agent-create.js
CHANGED
|
@@ -27,6 +27,7 @@ import { getCatalog, getProviderCatalog, resolveCatalogModel, catalogEfforts, as
|
|
|
27
27
|
import { resolveProviderId, resolveProviderServiceForBaseagent } from '../config/providers.js';
|
|
28
28
|
import { claimAgentCreation, claimAgentCreationAsync, readAgentCreationClaim, updateAgentCreationClaim } from '../core/agent-creation-claim.js';
|
|
29
29
|
import { initializationRuntimePlan } from '../config/providers-config.js';
|
|
30
|
+
import { templateInstallationGate, TEMPLATE_JOB_ID } from '../agent-template/jobs.js';
|
|
30
31
|
/** Select the creation lifecycle independently of --non-interactive. */
|
|
31
32
|
export function resolveAgentCreateMode(args) {
|
|
32
33
|
if (args.includes('--initialize') && args.includes('--bootstrap')) {
|
|
@@ -311,8 +312,8 @@ export async function agentCreateInteractive(opts = {}) {
|
|
|
311
312
|
try {
|
|
312
313
|
suggestedProjectPath = deriveAgentProjectPath(agentProjectRootFromDefaults(loadDefaults(), p.root), aid);
|
|
313
314
|
}
|
|
314
|
-
catch {
|
|
315
|
-
|
|
315
|
+
catch (error) {
|
|
316
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
316
317
|
}
|
|
317
318
|
const projectInput = (await ask(`Project path [${suggestedProjectPath}]: `)).trim();
|
|
318
319
|
const projectPath = projectInput || suggestedProjectPath;
|
|
@@ -920,8 +921,11 @@ export function readInitialization(aid) {
|
|
|
920
921
|
if (!record || typeof record !== 'object' || Array.isArray(record)) {
|
|
921
922
|
throw new InitializationStateError('invalid_record');
|
|
922
923
|
}
|
|
923
|
-
if (record.version !== 1 && record.version !== 2)
|
|
924
|
+
if (record.version !== 1 && record.version !== 2 && record.version !== 3)
|
|
924
925
|
throw new InitializationStateError('unsupported_version');
|
|
926
|
+
if (record.version === 3 ? !TEMPLATE_JOB_ID.test(record.teamJobId ?? '') : record.teamJobId !== undefined) {
|
|
927
|
+
throw new InitializationStateError('invalid_record');
|
|
928
|
+
}
|
|
925
929
|
if (!record.plan || typeof record.plan !== 'object' || Array.isArray(record.plan)) {
|
|
926
930
|
throw new InitializationStateError('invalid_plan');
|
|
927
931
|
}
|
|
@@ -983,7 +987,7 @@ export function saveInitialization(record) {
|
|
|
983
987
|
const file = initializationPath(record.plan.aid);
|
|
984
988
|
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
985
989
|
record.updatedAt = Date.now();
|
|
986
|
-
if (record.version
|
|
990
|
+
if (record.version !== 1) {
|
|
987
991
|
// The Windows EPERM fallback keeps a complete hot backup before updating
|
|
988
992
|
// this small journal in place. Core reads it synchronously on this event
|
|
989
993
|
// loop, so a local reader cannot observe a partial checkpoint.
|
|
@@ -1049,12 +1053,14 @@ export function initializationSummary(aid) {
|
|
|
1049
1053
|
if (!r)
|
|
1050
1054
|
return undefined;
|
|
1051
1055
|
const mode = recordMode(r);
|
|
1056
|
+
const team = templateInstallationGate(aid, r.teamJobId);
|
|
1052
1057
|
return {
|
|
1053
1058
|
mode, operationId: r.operationId, fingerprint: r.fingerprint,
|
|
1054
1059
|
...(r.creationId ? { creationId: r.creationId } : {}),
|
|
1055
1060
|
...(r.clientRequestId ? { clientRequestId: r.clientRequestId } : {}),
|
|
1056
1061
|
...(r.requesterAid ? { requesterAid: r.requesterAid } : {}),
|
|
1057
|
-
status: r.status, phase: r.phase, complete: r.status === 'complete',
|
|
1062
|
+
status: r.status, phase: r.phase, complete: r.status === 'complete' && !team.blocked,
|
|
1063
|
+
...(r.teamJobId ? { teamJobId: r.teamJobId, teamPending: team.blocked } : {}),
|
|
1058
1064
|
code: r.code ?? null, error: r.error ?? null,
|
|
1059
1065
|
retryable: r.status === 'failed' && r.bindAttempt?.state !== 'unknown',
|
|
1060
1066
|
nextStep: r.status === 'complete' || r.status === 'cancelled' ? null
|
|
@@ -1084,6 +1090,8 @@ export function initializationSummary(aid) {
|
|
|
1084
1090
|
export function initializationBlocksTasks(config) {
|
|
1085
1091
|
try {
|
|
1086
1092
|
const r = readInitialization(config.aid);
|
|
1093
|
+
if (templateInstallationGate(config.aid, r?.teamJobId).blocked)
|
|
1094
|
+
return true;
|
|
1087
1095
|
if (!r && config.initialization === undefined)
|
|
1088
1096
|
return false;
|
|
1089
1097
|
return !r || config.initialization?.operationId !== r.operationId
|
|
@@ -1359,7 +1367,8 @@ export class AgentInitializationService {
|
|
|
1359
1367
|
// accepted request remains recoverable if its project or model catalog
|
|
1360
1368
|
// changes while the caller is waiting for the lost receipt.
|
|
1361
1369
|
validateInitializationPlan(plan);
|
|
1362
|
-
if (fs.existsSync(agentConfig(plan.aid)) || fs.existsSync(aidLocalDir(plan.aid))
|
|
1370
|
+
if (fs.existsSync(agentConfig(plan.aid)) || fs.existsSync(aidLocalDir(plan.aid))
|
|
1371
|
+
&& !this.deps.preparedIdentity?.(plan.aid, plan.ownerAid)) {
|
|
1363
1372
|
failure('INITIALIZE_TARGET_EXISTS');
|
|
1364
1373
|
}
|
|
1365
1374
|
if (dryRun) {
|
|
@@ -1368,7 +1377,8 @@ export class AgentInitializationService {
|
|
|
1368
1377
|
}
|
|
1369
1378
|
const now = Date.now();
|
|
1370
1379
|
const r = {
|
|
1371
|
-
version: 2,
|
|
1380
|
+
version: templateInstallationGate(plan.aid).jobId ? 3 : 2,
|
|
1381
|
+
...(templateInstallationGate(plan.aid).jobId ? { teamJobId: templateInstallationGate(plan.aid).jobId } : {}),
|
|
1372
1382
|
mode: 'one_shot',
|
|
1373
1383
|
operationId: `init-${randomBytes(12).toString('hex')}`,
|
|
1374
1384
|
creationId: randomUUID(),
|
|
@@ -1391,10 +1401,12 @@ export class AgentInitializationService {
|
|
|
1391
1401
|
const claim = claimAgentCreation({
|
|
1392
1402
|
aid: plan.aid, mode: 'one_shot', creationId: r.creationId, operationId: r.operationId,
|
|
1393
1403
|
actor, requesterAid: actor, ownerAid: plan.ownerAid, clientRequestId, fingerprint,
|
|
1404
|
+
...(r.teamJobId ? { teamJobId: r.teamJobId } : {}),
|
|
1394
1405
|
});
|
|
1395
1406
|
if (!claim.claimed) {
|
|
1396
1407
|
if (claim.claim.mode === 'one_shot' && claim.claim.actor === actor
|
|
1397
|
-
&& claim.claim.clientRequestId === clientRequestId && claim.claim.fingerprint === fingerprint
|
|
1408
|
+
&& claim.claim.clientRequestId === clientRequestId && claim.claim.fingerprint === fingerprint
|
|
1409
|
+
&& claim.claim.teamJobId === r.teamJobId) {
|
|
1398
1410
|
if (claim.claim.status !== 'in_progress' || !UUID_V4.test(claim.claim.creationId)
|
|
1399
1411
|
|| !claim.claim.operationId || !/^init-[a-f0-9]{24}$/.test(claim.claim.operationId)) {
|
|
1400
1412
|
failure('INITIALIZE_STATE_INVALID', 'The accepted creation receipt is incomplete');
|
|
@@ -1471,6 +1483,8 @@ export class AgentInitializationService {
|
|
|
1471
1483
|
const record = readInitialization(aid);
|
|
1472
1484
|
if (!record || this.running.has(aid))
|
|
1473
1485
|
return;
|
|
1486
|
+
if (record.teamJobId)
|
|
1487
|
+
return; // The durable parent owns all team recovery.
|
|
1474
1488
|
const waitingForOwner = record.status === 'in_progress' && record.phase === 'ownerpending';
|
|
1475
1489
|
// Records written before ownerBindSubmitted existed could fail by resubmitting the bind
|
|
1476
1490
|
// while SDK ownership events invalidated the consensus cache. Retry them once the
|
|
@@ -1577,6 +1591,11 @@ export class AgentInitializationService {
|
|
|
1577
1591
|
}
|
|
1578
1592
|
check(r) {
|
|
1579
1593
|
assertAgentAidAvailable(r.plan.aid);
|
|
1594
|
+
if (r.teamJobId) {
|
|
1595
|
+
const gate = templateInstallationGate(r.plan.aid, r.teamJobId);
|
|
1596
|
+
if (gate.blocked && !gate.executing)
|
|
1597
|
+
failure('TEAM_PAUSED');
|
|
1598
|
+
}
|
|
1580
1599
|
if (this.deps.authorize && !this.deps.authorize(r.actor))
|
|
1581
1600
|
failure('NOT_ALLOWED');
|
|
1582
1601
|
const current = readInitialization(r.plan.aid);
|
|
@@ -1584,7 +1603,7 @@ export class AgentInitializationService {
|
|
|
1584
1603
|
failure('INITIALIZE_CANCELLED');
|
|
1585
1604
|
if (current.fingerprint !== r.fingerprint || current.creationId !== r.creationId
|
|
1586
1605
|
|| current.clientRequestId !== r.clientRequestId || current.actor !== r.actor
|
|
1587
|
-
|| (current.version
|
|
1606
|
+
|| (current.version !== 1 && initializationFingerprintV2(r.plan) !== current.fingerprint)) {
|
|
1588
1607
|
failure('INITIALIZE_STATE_INVALID');
|
|
1589
1608
|
}
|
|
1590
1609
|
// An exact binding is write-once. A stale worker must never replace a
|
|
@@ -1940,12 +1959,20 @@ export class AgentInitializationService {
|
|
|
1940
1959
|
saveInitialization(r);
|
|
1941
1960
|
}
|
|
1942
1961
|
this.phase(r, 'activating');
|
|
1962
|
+
const teamGate = templateInstallationGate(p.aid, r.teamJobId);
|
|
1963
|
+
if (r.teamJobId && !teamGate.activating && teamGate.blocked) {
|
|
1964
|
+
r.phase = 'team_prepared';
|
|
1965
|
+
saveInitialization(r);
|
|
1966
|
+
return;
|
|
1967
|
+
}
|
|
1943
1968
|
if (p.persona !== undefined && fs.readFileSync(path.join(agentSoulDir(p.aid), SOUL_PERSONA_FILE), 'utf8') !== p.persona) {
|
|
1944
1969
|
failure('INITIALIZE_PLAN_CONFLICT');
|
|
1945
1970
|
}
|
|
1946
1971
|
r.activationPrepared = true;
|
|
1947
1972
|
saveInitialization(r);
|
|
1948
|
-
const result =
|
|
1973
|
+
const result = r.teamJobId
|
|
1974
|
+
? await (this.deps.activatePrepared ?? (() => failure('TEAM_ACTIVATION_UNAVAILABLE')))(p.aid)
|
|
1975
|
+
: await this.deps.activate(p.aid);
|
|
1949
1976
|
this.check(r);
|
|
1950
1977
|
if (!result.ok)
|
|
1951
1978
|
failure(result.code ?? 'INITIALIZE_WELCOME_UNAVAILABLE');
|
|
@@ -1,89 +1,108 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import {
|
|
3
|
+
import { queryDaemon, wantsHelp } from './help.js';
|
|
4
4
|
import { runManagedAgentOperation } from './agent.js';
|
|
5
5
|
import { resolvePaths } from '../paths.js';
|
|
6
6
|
import { MAIN_CLI_BIN, SESSION_ID_ENV } from '../product.js';
|
|
7
7
|
import { getDaemonOwners, refreshOwnershipForAuthorization } from '../core/ownership/owner-resolver.js';
|
|
8
8
|
import { getAgentTemplateService } from '../agent-template/service.js';
|
|
9
|
-
import {
|
|
10
|
-
|
|
9
|
+
import { templateError, TEMPLATE_ACTIONS } from '../agent-template/types.js';
|
|
10
|
+
const templateContract = await import(new URL('../../scripts/agent-template/shared/template-contract.mjs', import.meta.url).href);
|
|
11
11
|
export function parseTemplateCommand(argv) {
|
|
12
12
|
const action = argv[0];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
if (!TEMPLATE_ACTIONS.includes(action))
|
|
14
|
+
throw templateError('INVALID_ARGUMENT', 'Unknown template action');
|
|
15
|
+
const jsonAction = ['inspect', 'build', 'push', 'pull', 'preview'].includes(action);
|
|
16
|
+
const controls = ['resume', 'cancel'].includes(action);
|
|
17
|
+
const asynchronous = !['status', 'capabilities'].includes(action);
|
|
18
|
+
const flags = new Map();
|
|
19
|
+
const positionals = [];
|
|
20
|
+
const allowed = new Set(['--format', ...(asynchronous ? ['--wait'] : []),
|
|
21
|
+
'--request-id', ...(jsonAction ? ['--input-file'] : []),
|
|
22
|
+
...(action === 'deploy' ? ['--preview-id', '--plan-digest'] : [])]);
|
|
23
|
+
for (let i = 1; i < argv.length; i++) {
|
|
24
|
+
const token = argv[i];
|
|
25
|
+
if (!token.startsWith('--')) {
|
|
26
|
+
positionals.push(token);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (!allowed.has(token) || flags.has(token) || !argv[i + 1] || argv[i + 1].startsWith('--')) {
|
|
30
|
+
throw templateError('INVALID_ARGUMENT', 'Invalid template option: ' + token);
|
|
31
|
+
}
|
|
32
|
+
flags.set(token, argv[++i]);
|
|
23
33
|
}
|
|
34
|
+
if (flags.has('--format') && flags.get('--format') !== 'json')
|
|
35
|
+
throw templateError('INVALID_ARGUMENT', '--format must be json');
|
|
24
36
|
let args;
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
if (jsonAction) {
|
|
38
|
+
if (!flags.has('--input-file') || positionals.length)
|
|
39
|
+
throw templateError('INVALID_ARGUMENT', '--input-file is required');
|
|
40
|
+
args = JSON.parse(fs.readFileSync(flags.get('--input-file'), 'utf8'));
|
|
41
|
+
}
|
|
42
|
+
else if (action === 'deploy') {
|
|
43
|
+
if (positionals.length)
|
|
44
|
+
throw templateError('INVALID_ARGUMENT', 'deploy accepts --preview-id and --plan-digest');
|
|
45
|
+
args = { previewId: flags.get('--preview-id'), planDigest: flags.get('--plan-digest') };
|
|
46
|
+
}
|
|
47
|
+
else if (action === 'status') {
|
|
48
|
+
if (positionals.length > 1 || (!!positionals.length === flags.has('--request-id'))) {
|
|
49
|
+
throw templateError('INVALID_ARGUMENT', 'Use status JOB_ID or status --request-id ORIGINAL');
|
|
50
|
+
}
|
|
51
|
+
args = positionals.length ? { jobId: positionals[0] } : { requestId: flags.get('--request-id') };
|
|
52
|
+
}
|
|
53
|
+
else if (controls) {
|
|
54
|
+
if (positionals.length !== 1)
|
|
55
|
+
throw templateError('INVALID_ARGUMENT', 'Job ID required');
|
|
56
|
+
args = { jobId: positionals[0] };
|
|
36
57
|
}
|
|
37
|
-
else
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
args = { location: { aid: target?.slice(0, separator), path: target?.slice(separator + 1) },
|
|
42
|
-
download: { shareId: value('--share-id') }, digest: value('--digest'), targetAid: value('--agent'),
|
|
43
|
-
...(value('--targets-json') ? { targets: json('--targets-json', {}) } : {}) };
|
|
58
|
+
else {
|
|
59
|
+
if (positionals.length || flags.has('--request-id'))
|
|
60
|
+
throw templateError('INVALID_ARGUMENT', 'capabilities accepts no business arguments');
|
|
61
|
+
args = {};
|
|
44
62
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
return
|
|
63
|
+
const requestId = action === 'status' ? randomUUID() : flags.get('--request-id') ?? randomUUID();
|
|
64
|
+
args = templateContract.normalizeTemplateRequest({ requestId, action, args }).args;
|
|
65
|
+
const wait = Number(flags.get('--wait') ?? 0);
|
|
66
|
+
if (!Number.isInteger(wait) || wait < 0 || wait > 300)
|
|
67
|
+
throw templateError('INVALID_ARGUMENT', '--wait must be 0..300 seconds');
|
|
68
|
+
return { action, args, requestId, wait };
|
|
69
|
+
}
|
|
70
|
+
export function templateExitCode(response, waited = false) {
|
|
71
|
+
if (response.transportError)
|
|
72
|
+
return 1;
|
|
73
|
+
if (response.error)
|
|
74
|
+
return response.error.code === 'INVALID_ARGUMENT' ? 2 : 1;
|
|
75
|
+
const status = response.data?.status;
|
|
76
|
+
if (['failed', 'cancelled'].includes(status))
|
|
77
|
+
return 1;
|
|
78
|
+
if (status === 'paused' || waited && ['running', 'queued', 'cancelling'].includes(status))
|
|
79
|
+
return 3;
|
|
80
|
+
return 0;
|
|
63
81
|
}
|
|
64
82
|
export async function executeTemplateCommand(actor, argv) {
|
|
65
83
|
const parsed = parseTemplateCommand(argv);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
try {
|
|
85
|
+
const service = getAgentTemplateService();
|
|
86
|
+
let data = await service.action(actor, parsed.requestId, parsed.action, parsed.args);
|
|
87
|
+
if (data.jobId && parsed.wait && ['queued', 'running', 'cancelling'].includes(data.status)) {
|
|
88
|
+
let timer;
|
|
89
|
+
try {
|
|
90
|
+
await Promise.race([service.wait(data.jobId), new Promise(resolve => { timer = setTimeout(resolve, parsed.wait * 1000); })]);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
if (timer)
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
}
|
|
96
|
+
data = await service.query(actor, { jobId: data.jobId });
|
|
78
97
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return {
|
|
98
|
+
return { requestId: parsed.requestId, data };
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return { requestId: parsed.requestId, error: {
|
|
102
|
+
code: error.code ?? 'TEMPLATE_FAILED', message: error.message, retryable: false, ...(error.details ? { details: error.details } : {})
|
|
103
|
+
} };
|
|
83
104
|
}
|
|
84
|
-
return { ok: true, data };
|
|
85
105
|
}
|
|
86
|
-
/** Called only after IPC has authenticated the standalone host control token. */
|
|
87
106
|
export async function executeHostTemplateCommand(argv) {
|
|
88
107
|
await refreshOwnershipForAuthorization(undefined, { force: true, allowTransient: false, source: 'agent-template-cli' });
|
|
89
108
|
const actor = getDaemonOwners()[0];
|
|
@@ -93,32 +112,34 @@ export async function executeHostTemplateCommand(argv) {
|
|
|
93
112
|
}
|
|
94
113
|
export async function cmdAgentTemplate(args) {
|
|
95
114
|
if (!args.length || wantsHelp(args)) {
|
|
96
|
-
console.log(
|
|
97
|
-
+ 'build: --
|
|
98
|
-
+ '
|
|
99
|
-
+ '
|
|
100
|
-
+ '
|
|
101
|
-
+ 'All commands: --format json --request-id ID --wait 0..300 (default 60). status JOB_ID recovers a task.');
|
|
115
|
+
console.log(MAIN_CLI_BIN + ' agent template <inspect|build|push|pull|preview|deploy|status|resume|cancel|capabilities>\n'
|
|
116
|
+
+ 'inspect/build/push/pull/preview: --input-file FILE\n'
|
|
117
|
+
+ 'deploy: --preview-id ID --plan-digest DIGEST\n'
|
|
118
|
+
+ 'status JOB_ID | status --request-id ORIGINAL; resume/cancel JOB_ID\n'
|
|
119
|
+
+ 'Asynchronous/control: --request-id ID --wait 0..300 (default 0). --format json');
|
|
102
120
|
return;
|
|
103
121
|
}
|
|
122
|
+
let parsed;
|
|
104
123
|
try {
|
|
105
|
-
parseTemplateCommand(args);
|
|
124
|
+
parsed = parseTemplateCommand(args);
|
|
125
|
+
const frozenArgs = ['status', 'capabilities'].includes(parsed.action) || args.includes('--request-id') ? args : [...args, '--request-id', parsed.requestId];
|
|
106
126
|
let result;
|
|
107
|
-
if (process.env[SESSION_ID_ENV])
|
|
108
|
-
|
|
127
|
+
if (process.env[SESSION_ID_ENV]) {
|
|
128
|
+
const managed = await runManagedAgentOperation(['template', ...frozenArgs], 310_000);
|
|
129
|
+
result = managed.result ?? managed;
|
|
130
|
+
}
|
|
109
131
|
else {
|
|
110
132
|
const controlToken = fs.readFileSync(resolvePaths().controlToken, 'utf8').trim();
|
|
111
|
-
const { response, transportError } = await queryDaemon(resolvePaths().socket, { type: 'agent-template.op', controlToken, argv:
|
|
112
|
-
|
|
113
|
-
throw new Error(transportError ? JSON.stringify(transportError) : 'Daemon unavailable');
|
|
114
|
-
result = response;
|
|
133
|
+
const { response, transportError } = await queryDaemon(resolvePaths().socket, { type: 'agent-template.op', controlToken, argv: frozenArgs }, 310_000);
|
|
134
|
+
result = response ?? { requestId: parsed.requestId, transportError: transportError ?? { message: 'Daemon unavailable' } };
|
|
115
135
|
}
|
|
116
136
|
console.log(JSON.stringify(result, null, 2));
|
|
117
|
-
|
|
118
|
-
process.exitCode = 1;
|
|
137
|
+
process.exitCode = templateExitCode(result, parsed.wait > 0);
|
|
119
138
|
}
|
|
120
139
|
catch (error) {
|
|
121
|
-
console.error(JSON.stringify({
|
|
122
|
-
|
|
140
|
+
console.error(JSON.stringify({ requestId: parsed?.requestId, error: {
|
|
141
|
+
code: error.code ?? 'INVALID_ARGUMENT', message: error.message, retryable: false
|
|
142
|
+
} }));
|
|
143
|
+
process.exitCode = error.code === 'INVALID_ARGUMENT' || !parsed ? 2 : 1;
|
|
123
144
|
}
|
|
124
145
|
}
|
package/dist/cli/agent.js
CHANGED
|
@@ -8,7 +8,7 @@ import { assertAgentAidAvailable, assertAgentModelConfigured, resolveEffective,
|
|
|
8
8
|
import { resolveRuntimeBaseagentModelSelection } from '../agents/baseagent.js';
|
|
9
9
|
import { resolveConfigCommand } from '../config/resolved-config-op.js';
|
|
10
10
|
import { executeResolvedConfigCommandAsync } from '../config/config-operation-service.js';
|
|
11
|
-
import { ipcQuery, IpcTransportError } from '../ipc.js';
|
|
11
|
+
import { ipcQuery, ipcHostQuery, IpcTransportError } from '../ipc.js';
|
|
12
12
|
import { daemonUnavailableMessage, queryDaemon } from './help.js';
|
|
13
13
|
import { CONFIG_SCHEMA_VERSION } from '../types.js';
|
|
14
14
|
import { ensureInitialRoleRegistry } from '../config/role-service.js';
|
|
@@ -365,6 +365,23 @@ export async function agentReload(aid, options = {}) {
|
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
// ==================== agentEnable / agentDisable ====================
|
|
368
|
+
/** Online host mutations use the same application service as Menu and managed CLI. */
|
|
369
|
+
async function hostAgentLifecycle(action, aid, options) {
|
|
370
|
+
try {
|
|
371
|
+
const result = await ipcHostQuery(resolvePaths().socket, {
|
|
372
|
+
type: 'evolagent.lifecycle', action, aid, ...options,
|
|
373
|
+
}, AGENT_RELOAD_TIMEOUT_MS, { throwOnError: true });
|
|
374
|
+
return result ?? { ok: false, code: 'IPC_INVALID_RESPONSE', error: 'daemon IPC returned no lifecycle result' };
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
// A timed-out mutation may already have happened. Only an absent daemon
|
|
378
|
+
// permits the offline disk implementation; never retry an unknown outcome.
|
|
379
|
+
if (error instanceof IpcTransportError && ['ENOENT', 'ECONNREFUSED'].includes(error.code))
|
|
380
|
+
return undefined;
|
|
381
|
+
return { ok: false, code: error instanceof IpcTransportError ? `IPC_${error.code}` : 'IPC_FAILED',
|
|
382
|
+
error: error instanceof Error ? error.message : String(error) };
|
|
383
|
+
}
|
|
384
|
+
}
|
|
368
385
|
export async function agentEnable(aid, options = {}) {
|
|
369
386
|
return agentSetEnabled(aid, true, options);
|
|
370
387
|
}
|
|
@@ -372,6 +389,9 @@ export async function agentDisable(aid, options = {}) {
|
|
|
372
389
|
return agentSetEnabled(aid, false, options);
|
|
373
390
|
}
|
|
374
391
|
async function agentSetEnabled(aid, enabled, options = {}) {
|
|
392
|
+
const online = await hostAgentLifecycle(enabled ? 'enable' : 'disable', aid, options);
|
|
393
|
+
if (online)
|
|
394
|
+
return online;
|
|
375
395
|
if (enabled) {
|
|
376
396
|
try {
|
|
377
397
|
assertAgentAidAvailable(aid);
|
|
@@ -665,26 +685,19 @@ export async function agentChannelUpsert(opts) {
|
|
|
665
685
|
}
|
|
666
686
|
// ==================== agentDelete ====================
|
|
667
687
|
export async function agentDelete(aid, purge = false) {
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
if (!
|
|
672
|
-
return { ok: false, error:
|
|
673
|
-
}
|
|
674
|
-
// Try to stop via IPC first
|
|
675
|
-
let stopped = false;
|
|
688
|
+
const online = await hostAgentLifecycle('delete', aid, { purge });
|
|
689
|
+
if (online)
|
|
690
|
+
return online;
|
|
691
|
+
if (!isValidAid(aid))
|
|
692
|
+
return { ok: false, code: 'INVALID_ARGS', error: 'Invalid Agent AID' };
|
|
676
693
|
try {
|
|
677
|
-
|
|
678
|
-
stopped
|
|
694
|
+
await removeAgentFiles(aid, purge);
|
|
695
|
+
return { ok: true, aid, purged: purge, stopped: false };
|
|
679
696
|
}
|
|
680
|
-
catch {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
try {
|
|
684
|
-
await ipcQuery(p.socket, { type: 'evolagent.resync' });
|
|
697
|
+
catch (error) {
|
|
698
|
+
return { ok: false, code: error.code,
|
|
699
|
+
error: error instanceof Error ? error.message : String(error) };
|
|
685
700
|
}
|
|
686
|
-
catch { }
|
|
687
|
-
return { ok: true, aid, purged: purge, stopped };
|
|
688
701
|
}
|
|
689
702
|
// ==================== agentRename ====================
|
|
690
703
|
export async function agentRename(aid, name) {
|