evolcore 0.0.41-test.0 → 0.0.41-test.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +88 -49
- package/dist/agents/claude-runner.js +177 -92
- package/dist/agents/codex-runner.js +146 -71
- package/dist/agents/ecagent-runner.js +1 -1
- package/dist/agents/gemini-runner.js +1 -1
- package/dist/aun/aid/agentmd.js +98 -11
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +26 -2
- package/dist/aun/aid/identity.js +91 -0
- package/dist/aun/aid/index.js +1 -1
- package/dist/aun/aid/managed-operation.js +1 -1
- package/dist/aun/aid/ownership-operation.js +23 -22
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -21
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/menu/client.js +27 -0
- package/dist/aun/msg/managed-operation.js +68 -7
- package/dist/aun/msg/p2p.js +8 -8
- package/dist/aun/service-proxy.js +53 -12
- package/dist/channels/aun.js +633 -32
- package/dist/channels/daemon.js +15 -1
- package/dist/cli/agent-command.js +5 -2
- package/dist/cli/agent-create.js +991 -233
- package/dist/cli/agent.js +49 -10
- package/dist/cli/aid-bind-command.js +48 -19
- package/dist/cli/aun-commands.js +48 -36
- package/dist/cli/daemon-commands.js +679 -697
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +72 -5
- package/dist/cli/init-channel.js +1 -1
- package/dist/cli/init.js +75 -1
- package/dist/cli/managed-command-guard.js +17 -1
- package/dist/cli/model.js +40 -40
- package/dist/cli/provider-command.js +57 -0
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +4 -2
- package/dist/cli/role.js +85 -0
- package/dist/cli/stats.js +10 -3
- package/dist/cli/task-context.js +19 -0
- package/dist/config/access-policy.js +7 -2
- package/dist/config/boot-log.js +39 -1
- package/dist/config/config-field-policy.js +17 -39
- package/dist/config/config-manager.js +183 -44
- package/dist/config/config-operation-service.js +5 -19
- 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 +88 -594
- package/dist/config/owner-config.js +2 -2
- package/dist/config/peer-role-resolver.js +15 -12
- package/dist/config/provider-ipc-service.js +132 -0
- package/dist/config/provider-menu-request.js +58 -0
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/providers-management.js +78 -5
- package/dist/config/resolved-config-op.js +11 -1
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +1000 -25
- package/dist/config-store.js +89 -4
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +4 -1
- package/dist/core/agent-application-service.js +60 -11
- package/dist/core/agent-create-status.js +203 -0
- package/dist/core/agent-creation-claim.js +177 -0
- package/dist/core/agent-ipc-registration.js +39 -18
- package/dist/core/agent-runtime.js +194 -24
- package/dist/core/auth/agent-delegation.js +6 -3
- package/dist/core/auth/auth-gateway.js +67 -2
- package/dist/core/auth/authorization-audit.js +58 -11
- package/dist/core/auth/delegation-authorization.js +5 -2
- package/dist/core/auth/operation-authorizer.js +43 -6
- package/dist/core/auth/operation-catalog.js +45 -7
- package/dist/core/channel-loader.js +2 -0
- package/dist/core/command/agent-control.js +260 -21
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +8 -3
- package/dist/core/command/command-handler.js +112 -154
- package/dist/core/command/connect-menu.js +11 -3
- 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 +10 -6
- package/dist/core/command/menu-handler.js +106 -73
- package/dist/core/command/menu-protocol.js +15 -1
- package/dist/core/command/provider-menu.js +46 -0
- package/dist/core/command/role-menu.js +147 -30
- package/dist/core/command/slash-handler.js +125 -255
- package/dist/core/daemon-control.js +26 -27
- package/dist/core/event-catalog.js +10 -0
- package/dist/core/evolagent-registry.js +7 -5
- package/dist/core/evolagent.js +10 -8
- package/dist/core/file-integrity/store.js +11 -0
- package/dist/core/handoff/ipc-registration.js +3 -0
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/initialization/service.js +491 -0
- package/dist/core/ipc-registration.js +40 -24
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +96 -1
- package/dist/core/memory/consolidation-trigger.js +208 -191
- package/dist/core/memory/consolidation.js +333 -35
- 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 +55 -45
- package/dist/core/message/aun-ipc-sender.js +81 -69
- package/dist/core/message/im-renderer.js +25 -4
- package/dist/core/message/message-admission.js +89 -4
- package/dist/core/message/message-bridge.js +66 -21
- package/dist/core/message/response-engine.js +108 -35
- package/dist/core/model/catalog-service.js +5 -3
- package/dist/core/model/config-scope.js +29 -71
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +30 -41
- 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 +772 -158
- package/dist/core/permission/approval-gateway.js +103 -403
- package/dist/core/permission/ec-command-parser.js +62 -6
- package/dist/core/permission/index.js +1 -0
- package/dist/core/permission/permission-result.js +78 -0
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +21 -46
- 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 +1 -1
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +20 -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 +43 -8
- 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/init-menu.js +32 -0
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +93 -19
- package/dist/ipc.js +247 -29
- package/dist/paths.js +7 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +484 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/trigger/authorization.js +27 -17
- package/dist/trigger/feedback.js +2 -3
- package/dist/trigger/ipc-service.js +105 -78
- package/dist/trigger/local-files.js +2 -1
- package/dist/trigger/manager.js +5 -3
- package/dist/trigger/scheduler.js +88 -6
- package/dist/utils/atomic-write.js +28 -0
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +26 -2
- package/dist/utils/logger.js +92 -6
- package/dist/utils/package-version-info.js +4 -2
- package/dist/utils/welcome.js +1 -1
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/aun/SDK.md +4 -1
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +1 -0
- package/kits/docs/evolcore/agent.md +8 -1
- package/kits/docs/evolcore/aid.md +67 -17
- package/kits/docs/evolcore/config.md +28 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/fs.md +11 -0
- package/kits/docs/evolcore/group.md +1 -1
- 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 +4 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +4 -7
- package/kits/docs/evolcore/provider.md +50 -0
- package/kits/docs/identity/AID_PROFILE_SPEC.md +52 -17
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/rules/01-overview.md +3 -0
- package/kits/rules/04-relation.md +1 -1
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +8 -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 +277 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ec-agent-create/SKILL.md +3 -0
- package/kits/skills/ec-identity/SKILL.md +2 -2
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-skill/scripts/skill.mjs +6 -0
- 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/skills/thread-ops/SKILL.md +5 -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/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/memory.md +4 -4
- package/kits/templates/system-fragments/venue.md +1 -1
- package/package.json +7 -3
- package/dist/core/message/create-status.js +0 -96
package/dist/config-store.js
CHANGED
|
@@ -24,7 +24,7 @@ import { checkAgentDir, isValidAid } from './aun/aid/validation.js';
|
|
|
24
24
|
import { normalizeAidDomain } from './aun/aid/domain.js';
|
|
25
25
|
import { isValidChannelName } from './core/channel-loader.js';
|
|
26
26
|
import { CONFIG_SCHEMA_VERSION } from './types.js';
|
|
27
|
-
import { ConfigTarget, assertNoLegacyAunGatewayConfig, read as cfgRead, normalizeProcessConfigCompat, stripLegacyAunGatewayConfig, write as cfgWrite, } from './config/config-manager.js';
|
|
27
|
+
import { ConfigTarget, assertAgentAidAvailable, assertControlAidAvailable, assertNoLegacyAunGatewayConfig, read as cfgRead, normalizeProcessConfigCompat, stripLegacyAunGatewayConfig, write as cfgWrite, } from './config/config-manager.js';
|
|
28
28
|
import { expandVars, buildEnvResolver } from './config/merge.js';
|
|
29
29
|
import { isAgentLifecycle } from './config/lifecycle.js';
|
|
30
30
|
import { logger } from './utils/logger.js';
|
|
@@ -99,6 +99,7 @@ export function isEckSnapshotsEnabled() {
|
|
|
99
99
|
export function saveDaemonConfig(value) {
|
|
100
100
|
const configPath = resolvePaths().daemonConfig;
|
|
101
101
|
assertNoLegacyAunGatewayConfig(value, configPath);
|
|
102
|
+
assertControlAidAvailable(value.aid);
|
|
102
103
|
const current = atomicReadJson(configPath);
|
|
103
104
|
// A legacy default is irrelevant while an existing control AID is retained.
|
|
104
105
|
// Validate the field when it is created or changed, but do not make unrelated
|
|
@@ -112,6 +113,81 @@ export function saveDaemonConfig(value) {
|
|
|
112
113
|
}
|
|
113
114
|
catch { /* best-effort */ }
|
|
114
115
|
}
|
|
116
|
+
function validateServiceManagementFields(service, index) {
|
|
117
|
+
const prefix = `daemon.json.services[${service.name ?? index}]`;
|
|
118
|
+
const runtime = service.runtime;
|
|
119
|
+
if (runtime !== undefined) {
|
|
120
|
+
if (!runtime || typeof runtime !== 'object' || Array.isArray(runtime))
|
|
121
|
+
throw new Error(`${prefix}.runtime must be an object`);
|
|
122
|
+
const unknown = Object.keys(runtime).filter(key => !['mode', 'command', 'stopTimeoutMs', 'restart'].includes(key));
|
|
123
|
+
if (unknown.length)
|
|
124
|
+
throw new Error(`${prefix}.runtime contains unsupported fields: ${unknown.join(', ')}`);
|
|
125
|
+
if (runtime.mode !== undefined && !['managed', 'external'].includes(runtime.mode)) {
|
|
126
|
+
throw new Error(`${prefix}.runtime.mode must be managed or external`);
|
|
127
|
+
}
|
|
128
|
+
if (service.name === 'ecweb' && runtime.command !== undefined) {
|
|
129
|
+
throw new Error('daemon.json.services[ecweb].runtime.command is managed by the internal ECWeb adapter');
|
|
130
|
+
}
|
|
131
|
+
if (runtime.command !== undefined) {
|
|
132
|
+
const command = runtime.command;
|
|
133
|
+
if (!command || typeof command !== 'object' || Array.isArray(command)
|
|
134
|
+
|| Object.keys(command).some(key => !['file', 'args', 'cwd'].includes(key))) {
|
|
135
|
+
throw new Error(`${prefix}.runtime.command must contain only file, args, and cwd`);
|
|
136
|
+
}
|
|
137
|
+
if (typeof command.file !== 'string' || !path.isAbsolute(command.file) || command.file.length > 2048) {
|
|
138
|
+
throw new Error(`${prefix}.runtime.command.file must be an absolute executable path`);
|
|
139
|
+
}
|
|
140
|
+
if (command.cwd !== undefined && (typeof command.cwd !== 'string' || !path.isAbsolute(command.cwd) || command.cwd.length > 2048)) {
|
|
141
|
+
throw new Error(`${prefix}.runtime.command.cwd must be an absolute path`);
|
|
142
|
+
}
|
|
143
|
+
if (command.args !== undefined && (!Array.isArray(command.args) || command.args.length > 128
|
|
144
|
+
|| command.args.some((arg) => typeof arg !== 'string' || arg.length > 8192))) {
|
|
145
|
+
throw new Error(`${prefix}.runtime.command.args must be at most 128 strings`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (runtime.mode === 'managed' && service.name !== 'ecweb' && !runtime.command) {
|
|
149
|
+
throw new Error(`${prefix}.runtime.command is required for managed services`);
|
|
150
|
+
}
|
|
151
|
+
if (runtime.stopTimeoutMs !== undefined
|
|
152
|
+
&& (!Number.isInteger(runtime.stopTimeoutMs) || runtime.stopTimeoutMs < 100 || runtime.stopTimeoutMs > 120000)) {
|
|
153
|
+
throw new Error(`${prefix}.runtime.stopTimeoutMs must be 100-120000`);
|
|
154
|
+
}
|
|
155
|
+
if (runtime.restart !== undefined) {
|
|
156
|
+
const restart = runtime.restart;
|
|
157
|
+
const restartFields = ['enabled', 'backoffMs'];
|
|
158
|
+
if (!restart || typeof restart !== 'object' || Array.isArray(restart)
|
|
159
|
+
|| Object.keys(restart).some(key => !restartFields.includes(key))) {
|
|
160
|
+
throw new Error(`${prefix}.runtime.restart contains unsupported fields`);
|
|
161
|
+
}
|
|
162
|
+
if (restart.enabled !== undefined && typeof restart.enabled !== 'boolean') {
|
|
163
|
+
throw new Error(`${prefix}.runtime.restart.enabled must be a boolean`);
|
|
164
|
+
}
|
|
165
|
+
if (restart.backoffMs !== undefined
|
|
166
|
+
&& (!Number.isInteger(restart.backoffMs) || restart.backoffMs < 1 || restart.backoffMs > 3600000)) {
|
|
167
|
+
throw new Error(`${prefix}.runtime.restart.backoffMs must be 1-3600000`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const health = service.health;
|
|
172
|
+
if (health !== undefined) {
|
|
173
|
+
const fields = ['type', 'path', 'timeoutMs', 'failureThreshold', 'startupTimeoutMs'];
|
|
174
|
+
if (!health || typeof health !== 'object' || Array.isArray(health)
|
|
175
|
+
|| Object.keys(health).some(key => !fields.includes(key)))
|
|
176
|
+
throw new Error(`${prefix}.health contains unsupported fields`);
|
|
177
|
+
if (health.type !== undefined && !['http', 'tcp'].includes(health.type))
|
|
178
|
+
throw new Error(`${prefix}.health.type is invalid`);
|
|
179
|
+
if (health.path !== undefined && (typeof health.path !== 'string' || !health.path.startsWith('/') || health.path.length > 1024)) {
|
|
180
|
+
throw new Error(`${prefix}.health.path must be an absolute URL path`);
|
|
181
|
+
}
|
|
182
|
+
for (const field of ['timeoutMs', 'failureThreshold', 'startupTimeoutMs']) {
|
|
183
|
+
const number = health[field];
|
|
184
|
+
const max = field === 'failureThreshold' ? 100 : 300000;
|
|
185
|
+
if (number !== undefined && (!Number.isInteger(number) || number < 1 || number > max)) {
|
|
186
|
+
throw new Error(`${prefix}.health.${field} must be 1-${max}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
115
191
|
function validateDaemonConfig(value, validateAidDomain) {
|
|
116
192
|
assertOwnerConfigRecord(value, 'daemon.json', isValidAid);
|
|
117
193
|
if (value.upgrade !== undefined) {
|
|
@@ -180,7 +256,7 @@ function validateDaemonConfig(value, validateAidDomain) {
|
|
|
180
256
|
throw new Error(`daemon.json.services[${index}] must be an object`);
|
|
181
257
|
}
|
|
182
258
|
const service = rawService;
|
|
183
|
-
const unknownServiceFields = Object.keys(service).filter((key) => !['name', 'enabled', 'port', 'proxy'].includes(key));
|
|
259
|
+
const unknownServiceFields = Object.keys(service).filter((key) => !['name', 'enabled', 'port', 'runtime', 'health', 'proxy'].includes(key));
|
|
184
260
|
if (unknownServiceFields.length > 0) {
|
|
185
261
|
throw new Error(`daemon.json.services[${index}] contains unsupported fields: ${unknownServiceFields.join(', ')}`);
|
|
186
262
|
}
|
|
@@ -197,6 +273,7 @@ function validateDaemonConfig(value, validateAidDomain) {
|
|
|
197
273
|
if (service.port !== undefined && (!Number.isInteger(service.port) || service.port < 1 || service.port > 65535)) {
|
|
198
274
|
throw new Error(`daemon.json.services[${service.name}].port must be an integer from 1 to 65535`);
|
|
199
275
|
}
|
|
276
|
+
validateServiceManagementFields(service, index);
|
|
200
277
|
if (service.proxy !== undefined) {
|
|
201
278
|
if (!service.proxy || typeof service.proxy !== 'object' || Array.isArray(service.proxy)) {
|
|
202
279
|
throw new Error(`daemon.json.services[${service.name}].proxy must be an object`);
|
|
@@ -373,12 +450,12 @@ export function autoMigrateIfNeeded() {
|
|
|
373
450
|
: `[migrate] daemon.json schema version -> ${daemonSchemaVersion}`);
|
|
374
451
|
}
|
|
375
452
|
/**
|
|
376
|
-
* @deprecated Use ConfigManager.read(ConfigTarget.Agent, { self: aid }, {
|
|
453
|
+
* @deprecated Use ConfigManager.read(ConfigTarget.Agent, { self: aid }, { cache: true }) instead.
|
|
377
454
|
* This wrapper exists for backward compatibility. All logic (aid validation, path cleaning, env expansion)
|
|
378
455
|
* is now handled by ConfigManager.
|
|
379
456
|
*/
|
|
380
457
|
export function loadAgent(aid) {
|
|
381
|
-
return cfgRead(ConfigTarget.Agent, { self: aid }, {
|
|
458
|
+
return cfgRead(ConfigTarget.Agent, { self: aid }, { cache: true });
|
|
382
459
|
}
|
|
383
460
|
/**
|
|
384
461
|
* @deprecated Use ConfigManager.write(ConfigTarget.Agent, value, { self: value.aid }) instead.
|
|
@@ -492,6 +569,14 @@ export function validateAgentConfig(cfg) {
|
|
|
492
569
|
const errs = [];
|
|
493
570
|
if (!cfg.aid || !isValidAid(cfg.aid))
|
|
494
571
|
errs.push(`invalid aid: ${cfg.aid}`);
|
|
572
|
+
else {
|
|
573
|
+
try {
|
|
574
|
+
assertAgentAidAvailable(cfg.aid);
|
|
575
|
+
}
|
|
576
|
+
catch (error) {
|
|
577
|
+
errs.push(`CONTROL_AID_RESERVED: ${error instanceof Error ? error.message : String(error)}`);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
495
580
|
if (cfg.active_baseagent !== undefined && !isSupportedBaseagent(cfg.active_baseagent)) {
|
|
496
581
|
errs.push(`unsupported active_baseagent: ${cfg.active_baseagent} (choose claude/codex/gemini/ecagent)`);
|
|
497
582
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export function ecwebHomeId(root) {
|
|
4
|
+
const resolved = path.resolve(root);
|
|
5
|
+
const canonical = process.platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
6
|
+
return crypto.createHash('sha256').update(canonical).digest('hex');
|
|
7
|
+
}
|
|
8
|
+
export function parseEcwebInstanceRecord(value, root, file) {
|
|
9
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
10
|
+
return null;
|
|
11
|
+
const record = value;
|
|
12
|
+
if (!Number.isSafeInteger(record.pid) || record.pid <= 0)
|
|
13
|
+
return null;
|
|
14
|
+
const port = record.port === undefined ? 42705 : record.port;
|
|
15
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
16
|
+
return null;
|
|
17
|
+
if (file && !new RegExp(`^(?:ecweb|watch-web)-${record.pid}\\.json$`).test(path.basename(file)))
|
|
18
|
+
return null;
|
|
19
|
+
if (record.startedAt !== undefined && (typeof record.startedAt !== 'number' || !Number.isFinite(record.startedAt) || record.startedAt <= 0))
|
|
20
|
+
return null;
|
|
21
|
+
if (record.schemaVersion !== undefined) {
|
|
22
|
+
if (record.schemaVersion !== 1 || record.service !== 'ecweb' || record.homeId !== ecwebHomeId(root)
|
|
23
|
+
|| record.port === undefined || record.startedAt === undefined
|
|
24
|
+
|| typeof record.instanceId !== 'string' || !/^[A-Za-z0-9-]{1,128}$/.test(record.instanceId))
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return { ...record, pid: record.pid, port: port };
|
|
28
|
+
}
|
|
29
|
+
export function matchesEcwebInstanceHealth(value, record) {
|
|
30
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
31
|
+
return false;
|
|
32
|
+
const health = value;
|
|
33
|
+
if (health.ok !== true || health.service !== 'ecweb' || health.processAlive === false)
|
|
34
|
+
return false;
|
|
35
|
+
if (!record)
|
|
36
|
+
return true;
|
|
37
|
+
if (health.pid !== undefined && health.pid !== record.pid)
|
|
38
|
+
return false;
|
|
39
|
+
return record.schemaVersion === undefined
|
|
40
|
+
|| (health.processAlive === true && health.pid === record.pid && health.instanceId === record.instanceId && health.homeId === record.homeId);
|
|
41
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export const ECWEB_SERVICE_PROTOCOL = Object.freeze({
|
|
2
2
|
name: 'evolcore.ecweb',
|
|
3
3
|
major: 1,
|
|
4
|
-
minor:
|
|
4
|
+
minor: 4,
|
|
5
5
|
capabilities: Object.freeze([
|
|
6
6
|
'daemon.status',
|
|
7
7
|
'agent.directory',
|
|
8
8
|
'aun.directory',
|
|
9
9
|
'menu.execute',
|
|
10
10
|
'provider.management',
|
|
11
|
+
'initialization',
|
|
11
12
|
'basic-settings',
|
|
12
13
|
'model.catalog',
|
|
13
14
|
'baseagent.snapshot',
|
|
@@ -15,6 +16,8 @@ export const ECWEB_SERVICE_PROTOCOL = Object.freeze({
|
|
|
15
16
|
'monitor.subscription',
|
|
16
17
|
'remote-auth',
|
|
17
18
|
'trigger.history',
|
|
19
|
+
'message.context',
|
|
20
|
+
'session.runnerTasks',
|
|
18
21
|
]),
|
|
19
22
|
});
|
|
20
23
|
export function validateEcwebClientProtocolRequirements(value) {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { initializationSummary } from '../cli/agent-create.js';
|
|
1
|
+
import { initializationSummary, readInitialization } from '../cli/agent-create.js';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { agentMdPath, resolvePaths, } from '../paths.js';
|
|
5
5
|
import { loadAgent, saveAgent, } from '../config-store.js';
|
|
6
|
-
import { ConfigTarget, ensureFile as cfgEnsure, initConfigManager, read as cfgRead, write as cfgWrite, } from '../config/config-manager.js';
|
|
6
|
+
import { ConfigTarget, assertAgentAidAvailable, assertAgentModelConfigured, ensureFile as cfgEnsure, initConfigManager, notifyConfigWrite, read as cfgRead, write as cfgWrite, } from '../config/config-manager.js';
|
|
7
7
|
import { executeResolvedConfigCommand, } from '../config/config-operation-service.js';
|
|
8
8
|
import { resolveConfigCommand } from '../config/resolved-config-op.js';
|
|
9
9
|
import { AgentReloadBusyError } from './agent-reload-coordinator.js';
|
|
10
10
|
import { logger } from '../utils/logger.js';
|
|
11
|
+
import { initializationCreateProgress, initializationOwnership, removeAgentFiles } from './agent-create-status.js';
|
|
11
12
|
function toPosix(value) {
|
|
12
13
|
if (!value)
|
|
13
14
|
return null;
|
|
@@ -68,8 +69,33 @@ export class AgentApplicationService {
|
|
|
68
69
|
async show(aid) {
|
|
69
70
|
const info = this.info(aid);
|
|
70
71
|
const agent = this.deps.registry.get(aid);
|
|
71
|
-
if (!info || !agent)
|
|
72
|
+
if (!info || !agent) {
|
|
73
|
+
try {
|
|
74
|
+
const record = readInitialization(aid);
|
|
75
|
+
if (record?.mode === 'one_shot') {
|
|
76
|
+
const config = loadAgent(aid);
|
|
77
|
+
const initialization = initializationSummary(aid);
|
|
78
|
+
const lifecycle = config?.lifecycle ?? null;
|
|
79
|
+
const progress = initializationCreateProgress(record, lifecycle, config?.initialization?.operationId);
|
|
80
|
+
const agentDir = path.join(resolvePaths().agentsDir, aid);
|
|
81
|
+
return {
|
|
82
|
+
ok: true, aid, status: record.status === 'failed' ? 'error' : 'stopped', lifecycle,
|
|
83
|
+
identity: { name: record.plan.name, description: record.plan.description },
|
|
84
|
+
config: { baseagent: record.plan.baseagent, model: record.plan.model ?? null, effort: record.plan.effort ?? null, chatmode: record.plan.chatmode ?? null, channels: [] },
|
|
85
|
+
connection: null, sessions: { active: 0, last_activity: null },
|
|
86
|
+
paths: { config: toPosix(path.join(agentDir, 'config.json')), agent_md: toPosix(agentMdPath(aid)), project: null, data: toPosix(path.join(agentDir, 'data')) },
|
|
87
|
+
mode: 'one_shot', creationId: record.creationId, operationId: record.operationId, clientRequestId: record.clientRequestId,
|
|
88
|
+
initialization: { ...initialization, complete: progress?.status === 'ready', ownerAid: record.plan.ownerAid,
|
|
89
|
+
retryable: progress?.retryable ?? false, nextStep: progress?.nextStep ?? null },
|
|
90
|
+
createProgress: progress, ownership: initializationOwnership(record), usable: false,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
return errorFrom(error);
|
|
96
|
+
}
|
|
72
97
|
return { ok: false, error: `Agent "${aid}" not found`, code: 'NOT_FOUND' };
|
|
98
|
+
}
|
|
73
99
|
const aidState = (this.deps.aunAids?.() ?? []).find(state => (state.aid === aid || state.agentName === aid));
|
|
74
100
|
const stats = (this.deps.aunAidStats?.() ?? []).find(snapshot => snapshot.aid === aid);
|
|
75
101
|
const connection = aidState
|
|
@@ -94,6 +120,22 @@ export class AgentApplicationService {
|
|
|
94
120
|
const lifecycle = config?.lifecycle ?? null;
|
|
95
121
|
const initialization = initializationSummary(aid);
|
|
96
122
|
const initializationState = initialization && this.initialization?.status(aid);
|
|
123
|
+
let oneShot = {};
|
|
124
|
+
try {
|
|
125
|
+
const record = readInitialization(aid);
|
|
126
|
+
if (record?.mode === 'one_shot') {
|
|
127
|
+
const progress = initializationCreateProgress(record, lifecycle, config?.initialization?.operationId);
|
|
128
|
+
oneShot = { mode: 'one_shot', creationId: record.creationId, operationId: record.operationId, clientRequestId: record.clientRequestId,
|
|
129
|
+
initialization: { ...initialization, complete: progress?.status === 'ready', ownerAid: record.plan.ownerAid,
|
|
130
|
+
retryable: progress?.retryable ?? false, nextStep: progress?.nextStep ?? null },
|
|
131
|
+
createProgress: progress, ownership: initializationOwnership(record),
|
|
132
|
+
usable: progress?.status === 'ready' && initializationState?.usable === true,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
return errorFrom(error);
|
|
138
|
+
}
|
|
97
139
|
return {
|
|
98
140
|
ok: true,
|
|
99
141
|
aid,
|
|
@@ -114,6 +156,7 @@ export class AgentApplicationService {
|
|
|
114
156
|
? initializationState.usable
|
|
115
157
|
: initialization.complete === true && lifecycle === 'active' && connection?.status === 'connected',
|
|
116
158
|
} : {}),
|
|
159
|
+
...oneShot,
|
|
117
160
|
sessions: {
|
|
118
161
|
active: info.activeSessions ?? 0,
|
|
119
162
|
last_activity: info.lastActivity ? new Date(info.lastActivity).toISOString() : null,
|
|
@@ -127,10 +170,17 @@ export class AgentApplicationService {
|
|
|
127
170
|
};
|
|
128
171
|
}
|
|
129
172
|
async create(options) {
|
|
173
|
+
try {
|
|
174
|
+
assertAgentAidAvailable(options.aid);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
return errorFrom(error);
|
|
178
|
+
}
|
|
130
179
|
return await this.deps.create(options);
|
|
131
180
|
}
|
|
132
181
|
async load(aid) {
|
|
133
182
|
try {
|
|
183
|
+
assertAgentAidAvailable(aid);
|
|
134
184
|
await this.deps.hotLoad(aid);
|
|
135
185
|
return { ok: true, aid };
|
|
136
186
|
}
|
|
@@ -146,6 +196,7 @@ export class AgentApplicationService {
|
|
|
146
196
|
}
|
|
147
197
|
return { ok: true, results: await this.deps.resync() };
|
|
148
198
|
}
|
|
199
|
+
assertAgentAidAvailable(aid);
|
|
149
200
|
await this.deps.reload(aid, options);
|
|
150
201
|
return { ok: true };
|
|
151
202
|
}
|
|
@@ -217,6 +268,8 @@ export class AgentApplicationService {
|
|
|
217
268
|
async setEnabled(aid, enabled, force) {
|
|
218
269
|
let config;
|
|
219
270
|
try {
|
|
271
|
+
if (enabled)
|
|
272
|
+
assertAgentAidAvailable(aid);
|
|
220
273
|
config = loadAgent(aid);
|
|
221
274
|
}
|
|
222
275
|
catch (error) {
|
|
@@ -228,6 +281,8 @@ export class AgentApplicationService {
|
|
|
228
281
|
await this.initialization?.cancel(aid);
|
|
229
282
|
const previousEnabled = config.enabled;
|
|
230
283
|
try {
|
|
284
|
+
if (enabled)
|
|
285
|
+
assertAgentModelConfigured(aid);
|
|
231
286
|
config.enabled = enabled;
|
|
232
287
|
saveAgent(config);
|
|
233
288
|
}
|
|
@@ -261,14 +316,8 @@ export class AgentApplicationService {
|
|
|
261
316
|
if (!fs.existsSync(configPath))
|
|
262
317
|
return { ok: false, error: `Agent "${aid}" not found`, code: 'NOT_FOUND' };
|
|
263
318
|
try {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
fs.unlinkSync(configPath);
|
|
269
|
-
const { removeCreateStatus } = await import('./message/create-status.js');
|
|
270
|
-
removeCreateStatus(agentDir);
|
|
271
|
-
}
|
|
319
|
+
await removeAgentFiles(aid, purge);
|
|
320
|
+
notifyConfigWrite(ConfigTarget.Agent, { self: aid });
|
|
272
321
|
let stopped = false;
|
|
273
322
|
try {
|
|
274
323
|
const result = await this.resync();
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/** Agent 创建状态、初始化进度投影与删除后的磁盘清理。 */
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { creationOwnershipBinding } from './ownership/owner-resolver.js';
|
|
6
|
+
import { readAgentCreationClaim, removeAgentCreationClaim, updateAgentCreationClaim } from './agent-creation-claim.js';
|
|
7
|
+
import { resolvePaths } from '../paths.js';
|
|
8
|
+
import { removeRegisteredFile } from './file-integrity/store.js';
|
|
9
|
+
const FILE = 'create-status.json';
|
|
10
|
+
export function readCreateStatus(agentDir) {
|
|
11
|
+
try {
|
|
12
|
+
const raw = fs.readFileSync(path.join(agentDir, FILE), 'utf-8');
|
|
13
|
+
return JSON.parse(raw);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** 删除构建进度文件(agent 删除时清理)。非 purge 删除只移除 config.json,
|
|
20
|
+
* 故需显式清理本文件,避免目录残留陈旧进度。 */
|
|
21
|
+
export function removeCreateStatus(agentDir) {
|
|
22
|
+
try {
|
|
23
|
+
fs.rmSync(path.join(agentDir, FILE), { force: true });
|
|
24
|
+
}
|
|
25
|
+
catch { /* ignore */ }
|
|
26
|
+
}
|
|
27
|
+
/** 构建进度写入器。每次状态变更原子落盘(写临时文件 + rename)。 */
|
|
28
|
+
export class CreateStatusWriter {
|
|
29
|
+
agentDir;
|
|
30
|
+
status;
|
|
31
|
+
creationId;
|
|
32
|
+
constructor(agentDir, aid, context) {
|
|
33
|
+
this.agentDir = agentDir;
|
|
34
|
+
this.creationId = context?.creationId ?? randomUUID();
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
this.status = { aid, creationId: this.creationId, ...context, status: 'in_progress', currentPhase: null, steps: [], error: null, startedAt: now, updatedAt: now };
|
|
37
|
+
fs.mkdirSync(agentDir, { recursive: true });
|
|
38
|
+
this.flush(true);
|
|
39
|
+
}
|
|
40
|
+
begin(phase) {
|
|
41
|
+
this.status.currentPhase = phase;
|
|
42
|
+
this.status.steps.push({ phase, state: 'in_progress', ts: Date.now() });
|
|
43
|
+
this.flush();
|
|
44
|
+
}
|
|
45
|
+
done(phase, detail) { this.mark(phase, 'done', detail); }
|
|
46
|
+
warn(phase, detail) { this.mark(phase, 'warn', detail); }
|
|
47
|
+
/** Immutable correlation; a later CLI bind/transfer must not replace it. */
|
|
48
|
+
setOwnershipBinding(binding) {
|
|
49
|
+
const expected = creationOwnershipBinding({
|
|
50
|
+
operation: binding.operation, operation_id: binding.operationId,
|
|
51
|
+
sub_aid: binding.subjectAid, owner_aid: binding.ownerAid,
|
|
52
|
+
base_relation_version: binding.baseRelationVersion, target_relation_version: binding.targetRelationVersion,
|
|
53
|
+
status: 'pending',
|
|
54
|
+
}, this.status.aid, this.status.ownerAid ?? '');
|
|
55
|
+
if (!this.status.requesterAid || binding.source !== 'agent_create' || !expected) {
|
|
56
|
+
throw new Error('Creation Ownership binding does not match the creation request');
|
|
57
|
+
}
|
|
58
|
+
if (this.status.ownershipBinding) {
|
|
59
|
+
if (this.status.ownershipBinding.operationId !== binding.operationId) {
|
|
60
|
+
throw new Error('Creation Ownership binding is already recorded');
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (this.status.status !== 'in_progress')
|
|
65
|
+
throw new Error('Agent creation has already finished');
|
|
66
|
+
this.status.ownershipBinding = expected;
|
|
67
|
+
this.flush();
|
|
68
|
+
}
|
|
69
|
+
async finishReady() {
|
|
70
|
+
this.status.status = 'ready';
|
|
71
|
+
this.status.currentPhase = null;
|
|
72
|
+
this.flush();
|
|
73
|
+
await updateAgentCreationClaim(this.status.aid, this.creationId, { status: 'ready' });
|
|
74
|
+
}
|
|
75
|
+
async finishFailed(phase, error) {
|
|
76
|
+
this.mark(phase, 'failed', error);
|
|
77
|
+
this.status.status = 'failed';
|
|
78
|
+
this.status.error = error;
|
|
79
|
+
this.status.currentPhase = null;
|
|
80
|
+
this.flush();
|
|
81
|
+
await updateAgentCreationClaim(this.status.aid, this.creationId, { status: 'failed' });
|
|
82
|
+
}
|
|
83
|
+
mark(phase, state, detail) {
|
|
84
|
+
const step = [...this.status.steps].reverse().find(s => s.phase === phase);
|
|
85
|
+
if (step) {
|
|
86
|
+
step.state = state;
|
|
87
|
+
if (detail)
|
|
88
|
+
step.detail = detail;
|
|
89
|
+
step.ts = Date.now();
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.status.steps.push({ phase, state, detail, ts: Date.now() });
|
|
93
|
+
}
|
|
94
|
+
this.flush();
|
|
95
|
+
}
|
|
96
|
+
flush(initial = false) {
|
|
97
|
+
// A failed worker or a deleted Agent must not overwrite a newer creation.
|
|
98
|
+
if (!initial && readCreateStatus(this.agentDir)?.creationId !== this.creationId) {
|
|
99
|
+
throw new Error('Agent creation record was removed or replaced');
|
|
100
|
+
}
|
|
101
|
+
this.status.updatedAt = Date.now();
|
|
102
|
+
const file = path.join(this.agentDir, FILE);
|
|
103
|
+
const tmp = `${file}.tmp`;
|
|
104
|
+
fs.writeFileSync(tmp, JSON.stringify(this.status, null, 2));
|
|
105
|
+
fs.renameSync(tmp, file);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Shared disk cleanup for CLI and daemon deletion after initialization stops. */
|
|
109
|
+
export async function removeAgentFiles(aid, purge) {
|
|
110
|
+
const agentsDir = path.resolve(resolvePaths().agentsDir);
|
|
111
|
+
const agentDir = path.resolve(agentsDir, aid);
|
|
112
|
+
if (path.dirname(agentDir) !== agentsDir)
|
|
113
|
+
throw new Error('Invalid Agent directory');
|
|
114
|
+
const configPath = path.join(agentDir, 'config.json');
|
|
115
|
+
removeRegisteredFile(configPath);
|
|
116
|
+
for (const suffix of ['_', '__'])
|
|
117
|
+
fs.rmSync(configPath + suffix, { force: true });
|
|
118
|
+
if (purge) {
|
|
119
|
+
fs.rmSync(agentDir, { recursive: true, force: true });
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
removeCreateStatus(agentDir);
|
|
123
|
+
// Preserve initialization receipts; only a legacy attempt is reusable.
|
|
124
|
+
const claim = readAgentCreationClaim(aid);
|
|
125
|
+
if (claim?.mode === 'legacy')
|
|
126
|
+
await removeAgentCreationClaim(aid, claim.creationId);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const PHASES = {
|
|
130
|
+
planned: 'validating', registering_aid: 'registering_aid', config_saved: 'config_saved',
|
|
131
|
+
persona_saved: 'config_saved', publishing_agentmd: 'uploading_agentmd',
|
|
132
|
+
verifying_agentmd: 'uploading_agentmd', uploading_agentmd: 'uploading_agentmd',
|
|
133
|
+
uploading_avatar: 'uploading_avatar', hot_loading: 'hot_loading',
|
|
134
|
+
binding_owner: 'hot_loading', ownerpending: 'hot_loading',
|
|
135
|
+
activating: 'applying_config', active: 'applying_config', complete: 'applying_config',
|
|
136
|
+
};
|
|
137
|
+
const STEP_ORDER = [
|
|
138
|
+
'validating', 'registering_aid', 'config_saved', 'uploading_agentmd',
|
|
139
|
+
'uploading_avatar', 'hot_loading', 'applying_config',
|
|
140
|
+
];
|
|
141
|
+
/** Reconstruct completed rows from durable checkpoints, without another progress journal. */
|
|
142
|
+
function progressSteps(record, phase, ready, failed) {
|
|
143
|
+
const current = STEP_ORDER.indexOf(phase);
|
|
144
|
+
const avatarRequested = !!(record.plan.avatarFile || record.plan.avatarUrl);
|
|
145
|
+
const checkpointDone = {
|
|
146
|
+
validating: record.phase !== 'planned',
|
|
147
|
+
registering_aid: record.aidRegistered === true || record.configSaved === true, config_saved: record.configSaved,
|
|
148
|
+
uploading_agentmd: record.verified, uploading_avatar: record.avatarUploaded,
|
|
149
|
+
hot_loading: record.hotLoaded === true && record.ownerConfirmed === true, applying_config: ready,
|
|
150
|
+
};
|
|
151
|
+
return STEP_ORDER.flatMap((step, index) => {
|
|
152
|
+
if (step === 'uploading_avatar' && !avatarRequested)
|
|
153
|
+
return [];
|
|
154
|
+
const active = index === current && !ready && (failed || checkpointDone[step] !== true);
|
|
155
|
+
const done = ready || checkpointDone[step] === true;
|
|
156
|
+
if (!active && !done)
|
|
157
|
+
return [];
|
|
158
|
+
return [{ phase: step, state: active ? failed ? 'failed' : 'in_progress' : 'done',
|
|
159
|
+
...(active ? { detail: record.phase } : {}), ts: record.updatedAt }];
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/** A read-only compatibility view. The initialization journal is the only authority. */
|
|
163
|
+
export function initializationCreateProgress(record, lifecycle, configOperationId) {
|
|
164
|
+
if (!record || record.mode !== 'one_shot')
|
|
165
|
+
return undefined;
|
|
166
|
+
const targetChanged = record.status === 'complete' && lifecycle === 'active' && configOperationId !== record.operationId;
|
|
167
|
+
const ready = record.status === 'complete' && lifecycle === 'active' && record.ownerConfirmed === true && !targetChanged;
|
|
168
|
+
const failed = record.status === 'failed' || record.status === 'cancelled' || targetChanged;
|
|
169
|
+
// The SDK may need Owner consensus to publish the first valid agent.md. Keep
|
|
170
|
+
// that wait on the existing card-upload row until the profile is verified.
|
|
171
|
+
const waitingForInitialCard = (record.phase === 'binding_owner' || record.phase === 'ownerpending')
|
|
172
|
+
&& record.verified !== true;
|
|
173
|
+
const phase = waitingForInitialCard ? 'uploading_agentmd' : PHASES[record.phase] ?? 'validating';
|
|
174
|
+
const code = targetChanged ? 'INITIALIZE_TARGET_CHANGED' : record.status === 'cancelled' ? 'INITIALIZE_CANCELLED' : record.code ?? null;
|
|
175
|
+
return {
|
|
176
|
+
aid: record.plan.aid, creationId: record.creationId, requesterAid: record.requesterAid,
|
|
177
|
+
ownerAid: record.plan.ownerAid,
|
|
178
|
+
...(record.ownershipBinding ? { ownershipBinding: record.ownershipBinding } : {}),
|
|
179
|
+
status: ready ? 'ready' : failed ? 'failed' : 'in_progress',
|
|
180
|
+
currentPhase: ready || failed ? null : phase, initializationPhase: record.phase,
|
|
181
|
+
steps: progressSteps(record, phase, ready, failed),
|
|
182
|
+
error: targetChanged ? 'Initialization target no longer matches the completed operation' : failed ? record.error ?? code : record.error ?? null, code,
|
|
183
|
+
retryable: !targetChanged && record.status === 'failed' && record.bindAttempt?.state !== 'unknown' && code !== 'INITIALIZE_STATE_INVALID',
|
|
184
|
+
nextStep: ready || targetChanged || record.status === 'cancelled' ? null
|
|
185
|
+
: record.bindAttempt?.state === 'unknown' ? 'await_owner_consensus'
|
|
186
|
+
: record.phase === 'ownerpending' ? 'await_owner'
|
|
187
|
+
: record.status === 'failed' ? 'resume' : null,
|
|
188
|
+
startedAt: record.startedAt, updatedAt: record.updatedAt,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export function initializationOwnership(record) {
|
|
192
|
+
const consensus = record.ownerConsensus;
|
|
193
|
+
return {
|
|
194
|
+
ownerAid: consensus?.ownerAid ?? null,
|
|
195
|
+
consensusStatus: consensus?.consensusStatus ?? (consensus?.status === 'confirmed' ? 'consensus' : consensus?.status ?? 'unbound'),
|
|
196
|
+
...(consensus?.consensusStatus !== undefined ? { gateStatus: consensus.status } : {}),
|
|
197
|
+
checkedAt: consensus?.checkedAt ?? null,
|
|
198
|
+
...(consensus?.relationVersion !== undefined ? { relationVersion: consensus.relationVersion } : {}),
|
|
199
|
+
...(consensus?.lock !== undefined ? { lock: consensus.lock } : {}),
|
|
200
|
+
...(consensus?.code !== undefined ? { code: consensus.code } : {}),
|
|
201
|
+
...(consensus?.retryable !== undefined ? { retryable: consensus.retryable } : {}),
|
|
202
|
+
};
|
|
203
|
+
}
|