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
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
5
|
+
import { agentConfig, agentDataDir, agentDir, aidLocalDir, resolveRoot } from '../paths.js';
|
|
6
|
+
import { atomicReplaceJson, withFileLock } from '../utils/atomic-write.js';
|
|
7
|
+
import { isProcessRunning } from '../utils/cross-platform.js';
|
|
8
|
+
export function agentCreationClaimPath(aid) {
|
|
9
|
+
return path.join(agentDataDir(aid), 'creation-claim.json');
|
|
10
|
+
}
|
|
11
|
+
/** Outside the Agent directory so purge cannot remove an active mutex. */
|
|
12
|
+
export function agentCreationMutationLockPath(aid) {
|
|
13
|
+
return path.join(resolveRoot(), 'data', 'agent-creation-locks', `${createHash('sha256').update(aid).digest('hex')}.lock`);
|
|
14
|
+
}
|
|
15
|
+
function readRaw(file) {
|
|
16
|
+
try {
|
|
17
|
+
const value = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
18
|
+
if (!value || value.version !== 1 || typeof value.aid !== 'string'
|
|
19
|
+
|| typeof value.mode !== 'string' || !['legacy', 'supplied', 'one_shot'].includes(value.mode)
|
|
20
|
+
|| !['in_progress', 'failed', 'ready'].includes(value.status)
|
|
21
|
+
|| typeof value.creationId !== 'string' || !value.creationId)
|
|
22
|
+
return null;
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function readAgentCreationClaim(aid) {
|
|
30
|
+
const file = agentCreationClaimPath(aid);
|
|
31
|
+
if (!fs.existsSync(file))
|
|
32
|
+
return null;
|
|
33
|
+
return readRaw(file);
|
|
34
|
+
}
|
|
35
|
+
function writeNew(file, claim) {
|
|
36
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
37
|
+
const temporary = `${file}.${process.pid}.${randomUUID()}.claim`;
|
|
38
|
+
try {
|
|
39
|
+
const fd = fs.openSync(temporary, 'wx', 0o600);
|
|
40
|
+
try {
|
|
41
|
+
fs.writeFileSync(fd, JSON.stringify(claim, null, 2) + '\n', 'utf8');
|
|
42
|
+
fs.fsyncSync(fd);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
fs.closeSync(fd);
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
fs.linkSync(temporary, file);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error.code === 'EEXIST')
|
|
53
|
+
return false;
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
fs.rmSync(temporary, { force: true });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function canRecoverOrphanedLegacyClaim(request, claim) {
|
|
62
|
+
if (claim.aid !== request.aid || claim.mode !== 'legacy' || claim.status !== 'in_progress'
|
|
63
|
+
|| claim.host !== os.hostname() || !request.requesterAid || !request.ownerAid
|
|
64
|
+
|| claim.requesterAid !== request.requesterAid || claim.ownerAid !== request.ownerAid
|
|
65
|
+
|| !Number.isSafeInteger(claim.pid) || claim.pid <= 0 || isProcessRunning(claim.pid))
|
|
66
|
+
return false;
|
|
67
|
+
// A partial identity or durable progress means creation may already have effects.
|
|
68
|
+
return [
|
|
69
|
+
agentConfig(request.aid),
|
|
70
|
+
path.join(agentDir(request.aid), 'create-status.json'),
|
|
71
|
+
path.join(agentDataDir(request.aid), 'initialization.json'),
|
|
72
|
+
aidLocalDir(request.aid),
|
|
73
|
+
].every(file => {
|
|
74
|
+
try {
|
|
75
|
+
fs.lstatSync(file);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return error.code === 'ENOENT';
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async function reclaimLegacyClaim(file, existing) {
|
|
84
|
+
const current = readRaw(file);
|
|
85
|
+
if (!current || current.mode !== 'legacy' || current.creationId !== existing.creationId
|
|
86
|
+
|| current.status !== existing.status) {
|
|
87
|
+
return { claimed: false, claim: current ?? existing };
|
|
88
|
+
}
|
|
89
|
+
const next = {
|
|
90
|
+
...current,
|
|
91
|
+
creationId: randomUUID(),
|
|
92
|
+
status: 'in_progress',
|
|
93
|
+
pid: process.pid,
|
|
94
|
+
host: os.hostname(),
|
|
95
|
+
startedAt: Date.now(),
|
|
96
|
+
updatedAt: Date.now(),
|
|
97
|
+
};
|
|
98
|
+
await atomicReplaceJson(file, next);
|
|
99
|
+
return { claimed: true, claim: next };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Atomically admit a new AID or observe its existing reservation. Matching
|
|
103
|
+
* initializers can complete journal publication with the reserved IDs.
|
|
104
|
+
* Legacy retries use the async API below to serialize failed-claim updates.
|
|
105
|
+
*/
|
|
106
|
+
export function claimAgentCreation(request) {
|
|
107
|
+
return claimAgentCreationLocked(request);
|
|
108
|
+
}
|
|
109
|
+
/** Creator entry points may also reconcile an abandoned legacy reservation with no creation output. */
|
|
110
|
+
export async function claimAgentCreationAsync(request, options = {}) {
|
|
111
|
+
const initial = claimAgentCreationLocked(request);
|
|
112
|
+
if (initial.claimed || request.mode !== 'legacy' || initial.claim.mode !== 'legacy'
|
|
113
|
+
|| (initial.claim.status !== 'failed'
|
|
114
|
+
&& !(options.recoverOrphanedLegacy && canRecoverOrphanedLegacyClaim(request, initial.claim))))
|
|
115
|
+
return initial;
|
|
116
|
+
return withFileLock(agentCreationMutationLockPath(request.aid), async () => {
|
|
117
|
+
const file = agentCreationClaimPath(request.aid);
|
|
118
|
+
const current = readRaw(file);
|
|
119
|
+
if (!current || current.mode !== 'legacy'
|
|
120
|
+
|| (current.status !== 'failed'
|
|
121
|
+
&& !(options.recoverOrphanedLegacy && canRecoverOrphanedLegacyClaim(request, current)))) {
|
|
122
|
+
return { claimed: false, claim: current ?? initial.claim };
|
|
123
|
+
}
|
|
124
|
+
return reclaimLegacyClaim(file, current);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function claimAgentCreationLocked(request) {
|
|
128
|
+
const now = Date.now();
|
|
129
|
+
const claim = {
|
|
130
|
+
version: 1,
|
|
131
|
+
aid: request.aid,
|
|
132
|
+
mode: request.mode,
|
|
133
|
+
status: 'in_progress',
|
|
134
|
+
creationId: request.creationId ?? randomUUID(),
|
|
135
|
+
...(request.operationId ? { operationId: request.operationId } : {}),
|
|
136
|
+
...(request.actor ? { actor: request.actor } : {}),
|
|
137
|
+
...(request.requesterAid ? { requesterAid: request.requesterAid } : {}),
|
|
138
|
+
...(request.ownerAid ? { ownerAid: request.ownerAid } : {}),
|
|
139
|
+
...(request.clientRequestId ? { clientRequestId: request.clientRequestId } : {}),
|
|
140
|
+
...(request.fingerprint ? { fingerprint: request.fingerprint } : {}),
|
|
141
|
+
pid: process.pid,
|
|
142
|
+
host: os.hostname(),
|
|
143
|
+
startedAt: now,
|
|
144
|
+
updatedAt: now,
|
|
145
|
+
};
|
|
146
|
+
const file = agentCreationClaimPath(request.aid);
|
|
147
|
+
if (writeNew(file, claim))
|
|
148
|
+
return { claimed: true, claim };
|
|
149
|
+
const existing = readRaw(file);
|
|
150
|
+
if (!existing) {
|
|
151
|
+
// A malformed claim is fail-closed. Do not replace it after another
|
|
152
|
+
// process has observed the same path, because that would reopen the race.
|
|
153
|
+
throw Object.assign(new Error('Agent creation claim is invalid'), { code: 'INITIALIZE_STATE_INVALID' });
|
|
154
|
+
}
|
|
155
|
+
return { claimed: false, claim: existing };
|
|
156
|
+
}
|
|
157
|
+
export function updateAgentCreationClaim(aid, identity, patch) {
|
|
158
|
+
return withFileLock(agentCreationMutationLockPath(aid), async () => {
|
|
159
|
+
const file = agentCreationClaimPath(aid);
|
|
160
|
+
const current = readRaw(file);
|
|
161
|
+
if (!current || (current.creationId !== identity && current.operationId !== identity))
|
|
162
|
+
return;
|
|
163
|
+
const next = { ...current, ...patch, updatedAt: patch.updatedAt ?? Date.now() };
|
|
164
|
+
await atomicReplaceJson(file, next);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
export function removeAgentCreationClaim(aid, creationId) {
|
|
168
|
+
return withFileLock(agentCreationMutationLockPath(aid), async () => {
|
|
169
|
+
const file = agentCreationClaimPath(aid);
|
|
170
|
+
if (creationId) {
|
|
171
|
+
const current = readRaw(file);
|
|
172
|
+
if (!current || current.creationId !== creationId)
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
fs.rmSync(file, { force: true });
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { parseAgentWelcomeArgs, parseInitializationArgs, resolveAgentCreateMode, resolveInitializationPlan, readInitializationPersona, } from '../cli/agent-create.js';
|
|
4
|
-
import { trustedExecutionIdentityInput } from './auth/agent-delegation.js';
|
|
4
|
+
import { hasTrustedFullAccessDelegation, trustedExecutionIdentityInput } from './auth/agent-delegation.js';
|
|
5
5
|
import { authorizeFreshOperation as authorizeOperation, buildAuthSubject } from './auth/auth-gateway.js';
|
|
6
6
|
import { getDaemonOwners } from './ownership/owner-resolver.js';
|
|
7
7
|
import { authorizationDenialData } from './auth/authorization-denial.js';
|
|
@@ -137,17 +137,26 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
137
137
|
const result = await execAgentOptions({ options: 'all' }, agentApplicationService);
|
|
138
138
|
if ('error' in result)
|
|
139
139
|
return fail(result.code, result.error);
|
|
140
|
-
const agents = Array.isArray(result.data?.agents) ? result.data.agents.map((agent) =>
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
140
|
+
const agents = Array.isArray(result.data?.agents) ? result.data.agents.map((agent) => {
|
|
141
|
+
return {
|
|
142
|
+
aid: agent.aid,
|
|
143
|
+
name: agent.name,
|
|
144
|
+
personalName: agent.personalName ?? null,
|
|
145
|
+
status: agent.status,
|
|
146
|
+
channels: Array.isArray(agent.channels) ? agent.channels : [],
|
|
147
|
+
projectPath: null,
|
|
148
|
+
baseagent: agent.baseagent ?? null,
|
|
149
|
+
model: agent.model ?? null,
|
|
150
|
+
lastActivity: agent.lastActivity ?? null,
|
|
151
|
+
...(agent.mode === 'one_shot' ? {
|
|
152
|
+
mode: agent.mode,
|
|
153
|
+
lifecycle: agent.lifecycle,
|
|
154
|
+
initialization: agent.initialization,
|
|
155
|
+
createProgress: agent.createProgress,
|
|
156
|
+
ownership: agent.ownership,
|
|
157
|
+
} : {}),
|
|
158
|
+
};
|
|
159
|
+
}) : [];
|
|
151
160
|
return { ok: true, result: { ok: true, agents, redacted: true } };
|
|
152
161
|
}
|
|
153
162
|
if (operation === 'agent.show') {
|
|
@@ -258,10 +267,6 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
258
267
|
try {
|
|
259
268
|
const parsed = parseInitializationArgs(argv.slice(1));
|
|
260
269
|
const actor = delegation.grant.actorId;
|
|
261
|
-
if (parsed.resume) {
|
|
262
|
-
agentInitializationService.resume(parsed.aid, actor);
|
|
263
|
-
return { ok: true, result: await agentInitializationService.wait(parsed.aid, parsed.wait) };
|
|
264
|
-
}
|
|
265
270
|
const createPermission = await authorizeOperation({
|
|
266
271
|
source: 'agent-tool', subject,
|
|
267
272
|
intent: { operation: 'agent.create', scope: 'control', source: 'agent-tool', args: { aid: parsed.aid } },
|
|
@@ -269,6 +274,13 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
269
274
|
});
|
|
270
275
|
if (!createPermission.allow)
|
|
271
276
|
return fail(createPermission.code, createPermission.reason);
|
|
277
|
+
if (parsed.resume) {
|
|
278
|
+
if (parsed.clientRequestId === undefined)
|
|
279
|
+
agentInitializationService.resume(parsed.aid, actor);
|
|
280
|
+
else
|
|
281
|
+
agentInitializationService.resume(parsed.aid, actor, parsed.clientRequestId);
|
|
282
|
+
return { ok: true, result: await agentInitializationService.wait(parsed.aid, parsed.wait) };
|
|
283
|
+
}
|
|
272
284
|
if (!argv.includes('--owner'))
|
|
273
285
|
return fail('INITIALIZE_OWNER_MISMATCH', 'Explicit --owner is required');
|
|
274
286
|
const plan = resolveInitializationPlan(argv.slice(1), {
|
|
@@ -289,7 +301,8 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
289
301
|
.filter((root) => !!root && path.isAbsolute(root))
|
|
290
302
|
.map(root => fs.realpathSync(root));
|
|
291
303
|
const real = fs.realpathSync(candidate);
|
|
292
|
-
if (!roots.some(root => isSameOrDescendant(real, root))
|
|
304
|
+
if (!roots.some(root => isSameOrDescendant(real, root))
|
|
305
|
+
|| (!hasTrustedFullAccessDelegation(delegation.grant) && (isHClassPath(real) || isLClassPath(real)))) {
|
|
293
306
|
return fail('AVATAR_INVALID', '--avatar-file must be a current project/TMPDIR file or authorized relation attachment');
|
|
294
307
|
}
|
|
295
308
|
plan.avatarFile = real;
|
|
@@ -305,6 +318,13 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
305
318
|
const aid = argv[2] && !argv[2].startsWith('--') ? argv[2] : undefined;
|
|
306
319
|
if (!aid)
|
|
307
320
|
return fail('INVALID_ARGS', 'ec agent new requires an AID');
|
|
321
|
+
const { assertAgentAidAvailable } = await import('../config/config-manager.js');
|
|
322
|
+
try {
|
|
323
|
+
assertAgentAidAvailable(aid);
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
return fail('CONTROL_AID_RESERVED', error.message);
|
|
327
|
+
}
|
|
308
328
|
const { agentCreateNonInteractive, resolveAgentCreatePlan, validateAgentCreatePlan, parseAgentOwnerArgs, parseAgentTags } = await import('../cli/agent-create.js');
|
|
309
329
|
let ownerOptions;
|
|
310
330
|
try {
|
|
@@ -367,7 +387,8 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
367
387
|
.filter((root) => !!root && path.isAbsolute(root))
|
|
368
388
|
.map(root => fs.realpathSync(root));
|
|
369
389
|
const real = fs.realpathSync(candidate);
|
|
370
|
-
if (!roots.some(root => isSameOrDescendant(real, root))
|
|
390
|
+
if (!roots.some(root => isSameOrDescendant(real, root))
|
|
391
|
+
|| (!hasTrustedFullAccessDelegation(delegation.grant) && (isHClassPath(real) || isLClassPath(real)))) {
|
|
371
392
|
return fail('AVATAR_INVALID', '--avatar-file must be a current project/TMPDIR file or authorized relation attachment');
|
|
372
393
|
}
|
|
373
394
|
createOptions.avatarFile = real;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
1
3
|
import { buildReloadHooks } from './channel-loader.js';
|
|
2
4
|
import { AgentReloadBusyError, AgentReloadCoordinator } from './agent-reload-coordinator.js';
|
|
3
5
|
import { detectDuplicates } from './evolagent-registry.js';
|
|
4
6
|
import { createRunnerReloadTransaction, disposeAgentInstances } from './runner-reload-transaction.js';
|
|
5
|
-
import { ConfigTarget, read as readConfig } from '../config/config-manager.js';
|
|
7
|
+
import { ConfigTarget, assertAgentAidAvailable, read as readConfig } from '../config/config-manager.js';
|
|
6
8
|
import { invalidateKitCache } from '../eck/kit-renderer.js';
|
|
7
9
|
import { logger } from '../utils/logger.js';
|
|
8
10
|
import fs from 'fs';
|
|
9
11
|
import path from 'path';
|
|
10
12
|
import { resolvePaths } from '../paths.js';
|
|
11
|
-
import { ownerResolver
|
|
12
|
-
import { AgentInitializationService, readInitialization } from '../cli/agent-create.js';
|
|
13
|
+
import { ownerResolver } from './ownership/owner-resolver.js';
|
|
14
|
+
import { AgentInitializationService, InitializationStateError, initializationErrorCode, readInitialization } from '../cli/agent-create.js';
|
|
15
|
+
import { getAidStore, loadClient } from '../aun/aid/store.js';
|
|
16
|
+
import { isValidAid } from '../aun/aid/validation.js';
|
|
13
17
|
export function loadStartupAgentRegistry(agentRegistry) {
|
|
14
18
|
agentRegistry.loadAll();
|
|
15
19
|
const agentInfos = agentRegistry.list();
|
|
@@ -211,35 +215,81 @@ export function createAgentReloadRuntime({ agentRegistry, agentLoader, sessionMa
|
|
|
211
215
|
});
|
|
212
216
|
return { reloadHooks, reloadCoordinator };
|
|
213
217
|
}
|
|
218
|
+
/** A strict authoritative observation for the initialization completion gate. */
|
|
219
|
+
export async function checkInitializationOwner(aid, expectedOwnerAid, expectedRelationVersion) {
|
|
220
|
+
const view = await ownerResolver.refresh(aid, { force: true, allowTransient: false });
|
|
221
|
+
const checkedAt = view.refreshFailure ? undefined : view.checkedAt;
|
|
222
|
+
const consensus = view.consensus;
|
|
223
|
+
const relationVersion = consensus?.relation_version;
|
|
224
|
+
const lock = consensus?.lock;
|
|
225
|
+
const details = view.refreshFailure
|
|
226
|
+
? { consensusStatus: 'unavailable',
|
|
227
|
+
code: initializationErrorCode(view.refreshFailure, 'INITIALIZE_OWNER_CHECK_FAILED'),
|
|
228
|
+
retryable: view.refreshFailure.kind === 'transient' }
|
|
229
|
+
: {
|
|
230
|
+
consensusStatus: view.consensusStatus,
|
|
231
|
+
...(typeof relationVersion === 'number' && Number.isSafeInteger(relationVersion) && relationVersion >= 0 ? { relationVersion } : {}),
|
|
232
|
+
...(lock === 'locked' || lock === 'unlocked' ? { lock } : {}),
|
|
233
|
+
...(consensus?.code !== undefined ? { code: initializationErrorCode(consensus, 'INITIALIZE_OWNER_CHECK_FAILED') } : {}),
|
|
234
|
+
...(typeof consensus?.retryable === 'boolean' ? { retryable: consensus.retryable } : {}),
|
|
235
|
+
};
|
|
236
|
+
if (view.consensusStatus === 'consensus' && view.authorizationStatus === 'verified'
|
|
237
|
+
&& (expectedRelationVersion === undefined || view.consensus?.relation_version === expectedRelationVersion)
|
|
238
|
+
&& checkedAt !== undefined)
|
|
239
|
+
return {
|
|
240
|
+
status: view.ownerAid === expectedOwnerAid ? 'confirmed' : 'conflict',
|
|
241
|
+
ownerAid: view.ownerAid, checkedAt, ...details,
|
|
242
|
+
};
|
|
243
|
+
return { status: 'pending', ...(checkedAt !== undefined ? { checkedAt } : {}), ...details };
|
|
244
|
+
}
|
|
214
245
|
export function createAgentInitializationRuntime({ agentRegistry, agentMap, channelInstances, hotLoad, activate, }) {
|
|
215
246
|
const isConnected = (aid) => channelInstances.some(instance => instance.channelType === 'aun'
|
|
216
247
|
&& instance.channel.getAidState?.()?.aid === aid
|
|
217
248
|
&& instance.channel.getAidState?.()?.status === 'connected');
|
|
218
249
|
return new AgentInitializationService({
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
250
|
+
ownershipBeforePublication: true,
|
|
251
|
+
register: async (aid, _ownerAid, mode) => {
|
|
252
|
+
assertAgentAidAvailable(aid);
|
|
253
|
+
const { aidCreate, aidCreateIdentityOnly } = await import('../aun/aid/identity.js');
|
|
254
|
+
const { assertAgentIdentityReusable } = await import('../aun/aid/agentmd.js');
|
|
255
|
+
const created = mode === 'one_shot'
|
|
256
|
+
? await aidCreateIdentityOnly(aid)
|
|
257
|
+
: await aidCreate(aid, { type: 'agent' });
|
|
258
|
+
try {
|
|
259
|
+
if (created.alreadyExisted)
|
|
260
|
+
await assertAgentIdentityReusable(aid, { store: created.store });
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
try {
|
|
264
|
+
await created.client.close();
|
|
265
|
+
}
|
|
266
|
+
finally {
|
|
267
|
+
created.store.close();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
225
270
|
},
|
|
226
271
|
bindOwner: async (aid, ownerAid) => {
|
|
227
|
-
|
|
272
|
+
// Keep the exact SDK task returned by this invocation. The
|
|
273
|
+
// initialization service validates and persists its operation ID beside
|
|
274
|
+
// the creation receipt; it must never reconstruct a task from snapshot().
|
|
275
|
+
return readInitialization(aid)?.mode === 'one_shot'
|
|
276
|
+
? await bindInitializationOwner(aid, ownerAid)
|
|
277
|
+
: await ownerResolver.bind(aid, ownerAid);
|
|
228
278
|
},
|
|
229
279
|
ownerBindActive: (aid, ownerAid) => {
|
|
230
280
|
const task = ownerResolver.snapshot(aid).task;
|
|
231
281
|
return task?.operation === 'bind' && task.owner_aid === ownerAid
|
|
232
282
|
&& (task.status === 'pending' || task.status === 'completed');
|
|
233
283
|
},
|
|
234
|
-
checkOwner:
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
284
|
+
checkOwner: (aid, ownerAid) => isConnected(aid)
|
|
285
|
+
? checkInitializationOwner(aid, ownerAid, readInitialization(aid)?.mode === 'one_shot' ? 1 : undefined)
|
|
286
|
+
: checkBootstrapInitializationOwner(aid, ownerAid),
|
|
287
|
+
publish: async (aid, content, ownerAid) => {
|
|
288
|
+
const { agentmdPut, agentmdPutInitializationProfile } = await import('../aun/aid/agentmd.js');
|
|
289
|
+
if (ownerAid)
|
|
290
|
+
await agentmdPutInitializationProfile(content, { aid, ownerAid });
|
|
291
|
+
else
|
|
292
|
+
await agentmdPut(content, { aid });
|
|
243
293
|
},
|
|
244
294
|
fetch: async (aid) => {
|
|
245
295
|
const { agentmdGet } = await import('../aun/aid/agentmd.js');
|
|
@@ -271,16 +321,26 @@ export function recoverIncompleteAgentInitializations(service, agentsDir = resol
|
|
|
271
321
|
continue;
|
|
272
322
|
try {
|
|
273
323
|
const record = readInitialization(entry.name);
|
|
274
|
-
if (record?.status === 'in_progress')
|
|
275
|
-
service.resume(entry.name, record.actor);
|
|
324
|
+
if (record?.status === 'in_progress') {
|
|
325
|
+
service.resume(entry.name, record.actor, record.mode === 'one_shot' ? record.clientRequestId : undefined);
|
|
326
|
+
}
|
|
276
327
|
}
|
|
277
|
-
catch {
|
|
278
|
-
|
|
328
|
+
catch (error) {
|
|
329
|
+
const code = error?.code;
|
|
330
|
+
logger.warn(`[Initialization] Recovery requires review for an incomplete operation ${JSON.stringify({
|
|
331
|
+
aid: entry.name,
|
|
332
|
+
errorCode: typeof code === 'string' && /^[A-Z][A-Z0-9_]{0,63}$/.test(code)
|
|
333
|
+
? code : 'INITIALIZE_RECOVERY_FAILED',
|
|
334
|
+
...(error instanceof InitializationStateError ? {
|
|
335
|
+
validationFailure: error.validationFailure, ...error.fingerprintDiagnostic,
|
|
336
|
+
} : {}),
|
|
337
|
+
})}`);
|
|
279
338
|
}
|
|
280
339
|
}
|
|
281
340
|
}
|
|
282
341
|
export function createAgentRuntimeOperations({ agentRegistry, agentLoader, sessionManager, agentMap, permissionGateway, processor, channelLoader, channelInstances, registerChannelInstance, markChannelConnected, aidStatsCollector, handoffRuntime, triggerSchedulers, ensureTriggerSchedulerStarted, startTriggerScheduler, reloadCoordinator, unregisterRuntimeChannel, messageQueue, setAgentRuntimeState, setAgentRuntimeError, }) {
|
|
283
342
|
const hotLoad = async (aid) => {
|
|
343
|
+
assertAgentAidAvailable(aid);
|
|
284
344
|
handoffRuntime.pauseAgent(aid);
|
|
285
345
|
let resumed = false;
|
|
286
346
|
try {
|
|
@@ -357,7 +417,7 @@ export function createAgentRuntimeOperations({ agentRegistry, agentLoader, sessi
|
|
|
357
417
|
if (!diskCfg || diskCfg.enabled === false) {
|
|
358
418
|
try {
|
|
359
419
|
const offlined = await reloadCoordinator.runExclusive(aid, async () => {
|
|
360
|
-
const latestDiskCfg = readConfig(ConfigTarget.Agent, { self: aid }, { cache: false
|
|
420
|
+
const latestDiskCfg = readConfig(ConfigTarget.Agent, { self: aid }, { cache: false });
|
|
361
421
|
if (latestDiskCfg && latestDiskCfg.enabled !== false)
|
|
362
422
|
return false;
|
|
363
423
|
const runtimeAgent = agentRegistry.get(aid);
|
|
@@ -450,3 +510,113 @@ export function createAgentRuntimeOperations({ agentRegistry, agentLoader, sessi
|
|
|
450
510
|
};
|
|
451
511
|
return { hotLoad, resync };
|
|
452
512
|
}
|
|
513
|
+
// fastaun 0.5.28 start()/capture() only read and verify documents. All writes
|
|
514
|
+
// and notifications occur in execute(), which converts transport failures to
|
|
515
|
+
// an error task with its original operation_id. Only this audited artifact
|
|
516
|
+
// therefore proves that a raw ECONNRESET rejection preceded submission.
|
|
517
|
+
// A different SDK version or workflow must fall back to unknown until its
|
|
518
|
+
// boundary is reviewed, even when another version reuses this workflow file.
|
|
519
|
+
const AUDITED_SDK_VERSION = '0.5.28';
|
|
520
|
+
const AUDITED_WORKFLOW_SHA256 = 'cd736d1fcce0812013ba7d7c2148f86c8f3d3d2d39e451e52a0f9cc2a4d4fb51';
|
|
521
|
+
export function initializationBindPreflightFailure(error) {
|
|
522
|
+
if (!(error instanceof Error) || error.code !== 'ECONNRESET')
|
|
523
|
+
return false;
|
|
524
|
+
try {
|
|
525
|
+
const entry = import.meta.resolve('@agentunion/fastaun');
|
|
526
|
+
const manifest = JSON.parse(readFileSync(new URL('../package.json', entry), 'utf8'));
|
|
527
|
+
if (manifest.version !== AUDITED_SDK_VERSION)
|
|
528
|
+
return false;
|
|
529
|
+
const workflow = new URL('ownership-workflow.js', entry);
|
|
530
|
+
return createHash('sha256').update(readFileSync(workflow)).digest('hex') === AUDITED_WORKFLOW_SHA256;
|
|
531
|
+
}
|
|
532
|
+
catch {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/** Initial binding precedes the daemon channel; use an independent short slot. */
|
|
537
|
+
async function withInitializationClient(aid, action) {
|
|
538
|
+
let store;
|
|
539
|
+
let client;
|
|
540
|
+
let actionStarted = false;
|
|
541
|
+
try {
|
|
542
|
+
store = await getAidStore({ slotId: 'evolcore-initialization' });
|
|
543
|
+
client = await loadClient(store, aid);
|
|
544
|
+
if (client.currentAid?.aid !== aid || !client.currentAid.isCertValid() || !client.currentAid.isPrivateKeyValid()) {
|
|
545
|
+
throw Object.assign(new Error('Initialization identity is unavailable'), { code: 'INITIALIZE_IDENTITY_UNAVAILABLE' });
|
|
546
|
+
}
|
|
547
|
+
await client.connect({ connection_kind: 'short', short_ttl_ms: 120_000,
|
|
548
|
+
background_sync: false, auto_reconnect: false, connect_timeout: 10, call_timeout: 30 });
|
|
549
|
+
// An entered bind can have remote effects. Its adapter may only mark an
|
|
550
|
+
// audited read-only preflight as not started; all other failures stay unknown.
|
|
551
|
+
actionStarted = true;
|
|
552
|
+
return await action(client);
|
|
553
|
+
}
|
|
554
|
+
catch (error) {
|
|
555
|
+
if (!actionStarted) {
|
|
556
|
+
const original = error instanceof Error ? error : new Error(String(error));
|
|
557
|
+
throw Object.assign(new Error(original.message), {
|
|
558
|
+
code: 'INITIALIZE_BIND_NOT_STARTED',
|
|
559
|
+
cause: error,
|
|
560
|
+
causeCode: error?.code,
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
throw error;
|
|
564
|
+
}
|
|
565
|
+
finally {
|
|
566
|
+
// A close failure must not discard the exact task already returned by bind.
|
|
567
|
+
try {
|
|
568
|
+
await client?.close();
|
|
569
|
+
}
|
|
570
|
+
catch { /* preserve operation result */ }
|
|
571
|
+
try {
|
|
572
|
+
store?.close();
|
|
573
|
+
}
|
|
574
|
+
catch { /* preserve operation result */ }
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
export async function bindInitializationOwner(aid, ownerAid) {
|
|
578
|
+
return withInitializationClient(aid, async (client) => {
|
|
579
|
+
try {
|
|
580
|
+
return await client.bindOwneraid(ownerAid);
|
|
581
|
+
}
|
|
582
|
+
catch (error) {
|
|
583
|
+
if (initializationBindPreflightFailure(error)) {
|
|
584
|
+
throw Object.assign(new Error('Owner binding preparation failed before submission'), {
|
|
585
|
+
code: 'INITIALIZE_BIND_NOT_STARTED', cause: error,
|
|
586
|
+
causeCode: initializationErrorCode(error, 'INITIALIZE_BIND_FAILED'),
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
throw error;
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
/** Each bootstrap observation has a new SDK client and no cached consensus. */
|
|
594
|
+
export async function checkBootstrapInitializationOwner(aid, ownerAid) {
|
|
595
|
+
try {
|
|
596
|
+
return await withInitializationClient(aid, async (client) => {
|
|
597
|
+
const view = await client.checkOwnershipConsensus(aid);
|
|
598
|
+
const checkedAt = Date.now();
|
|
599
|
+
const details = {
|
|
600
|
+
...(['consensus', 'released', 'unbound', 'single_sided', 'invalid', 'unavailable', 'not_applicable'].includes(view.status)
|
|
601
|
+
? { consensusStatus: view.status } : {}),
|
|
602
|
+
...(Number.isSafeInteger(view.relation_version) && view.relation_version >= 0 ? { relationVersion: view.relation_version } : {}),
|
|
603
|
+
...(['locked', 'unlocked'].includes(view.lock) ? { lock: view.lock } : {}),
|
|
604
|
+
...(view.code ? { code: initializationErrorCode(view, 'INITIALIZE_OWNER_CHECK_FAILED') } : {}),
|
|
605
|
+
...(typeof view.retryable === 'boolean' ? { retryable: view.retryable } : {}),
|
|
606
|
+
};
|
|
607
|
+
if (view.status === 'consensus' && view.sub_aid === aid && view.lock === 'locked'
|
|
608
|
+
&& view.relation_version === 1 && typeof view.owner_aid === 'string' && isValidAid(view.owner_aid) && view.owner_aid !== aid) {
|
|
609
|
+
return { status: view.owner_aid === ownerAid ? 'confirmed' : 'conflict', ownerAid: view.owner_aid, checkedAt, ...details };
|
|
610
|
+
}
|
|
611
|
+
return { status: 'pending', checkedAt, ...details };
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
catch (error) {
|
|
615
|
+
// An unavailable observation never confirms a relation or replays bind.
|
|
616
|
+
const codeSource = error?.code === 'INITIALIZE_BIND_NOT_STARTED'
|
|
617
|
+
? { code: error.causeCode }
|
|
618
|
+
: error;
|
|
619
|
+
return { status: 'pending', consensusStatus: 'unavailable',
|
|
620
|
+
code: initializationErrorCode(codeSource, 'INITIALIZE_OWNER_CHECK_FAILED'), retryable: true };
|
|
621
|
+
}
|
|
622
|
+
}
|
|
@@ -443,7 +443,9 @@ export async function authorizeDelegatedAunMsgSend(registry, input) {
|
|
|
443
443
|
catch {
|
|
444
444
|
return { ok: false, code: 'INVALID_DELEGATION', reason: 'Delegation relation key is invalid' };
|
|
445
445
|
}
|
|
446
|
-
await refreshOwnershipForAuthorization(grant.selfAid, {
|
|
446
|
+
await refreshOwnershipForAuthorization(grant.selfAid, {
|
|
447
|
+
allowTransient: true, includeDaemon: hasTrustedFullAccessDelegation(grant),
|
|
448
|
+
});
|
|
447
449
|
const builtSubject = buildAuthSubject({
|
|
448
450
|
selfAid: grant.selfAid,
|
|
449
451
|
actorId: grant.actorId,
|
|
@@ -493,10 +495,11 @@ export async function authorizeDelegatedAunMsgSend(registry, input) {
|
|
|
493
495
|
export function trustedExecutionIdentityInput(grant) {
|
|
494
496
|
return grant.executionIdentity && isValidFullAccessExecutionIdentity(grant.executionIdentity)
|
|
495
497
|
? {
|
|
498
|
+
sessionId: grant.sessionId,
|
|
496
499
|
trustedProcessRole: 'fullaccess-run',
|
|
497
500
|
trustedFullAccessAuthorization: grant.executionIdentity,
|
|
498
501
|
}
|
|
499
|
-
: {};
|
|
502
|
+
: { sessionId: grant.sessionId };
|
|
500
503
|
}
|
|
501
504
|
export function hasTrustedFullAccessDelegation(grant) {
|
|
502
505
|
return !!grant.executionIdentity && isValidFullAccessExecutionIdentity(grant.executionIdentity);
|
|
@@ -532,7 +535,7 @@ function approvedCommandBindingKey(sessionTokenHash, sessionId, approvalId) {
|
|
|
532
535
|
function isDelegationCommandHash(value) {
|
|
533
536
|
return /^[a-f0-9]{64}$/.test(value);
|
|
534
537
|
}
|
|
535
|
-
function delegationFailureDetailCode(cause) {
|
|
538
|
+
export function delegationFailureDetailCode(cause) {
|
|
536
539
|
switch (cause) {
|
|
537
540
|
case 'missing_token': return 'DELEGATION_TOKEN_MISSING';
|
|
538
541
|
case 'unknown_token': return 'DELEGATION_TOKEN_UNKNOWN';
|