evolcore 0.0.43-test.6 → 0.0.43-test.7
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 +48 -0
- package/bin/ecmsg.js +171 -54
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/codex/app-server-client.js +22 -0
- package/dist/agents/codex-runner.js +69 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/channels/aun.js +234 -21
- package/dist/cli/agent-create.js +2 -2
- package/dist/cli/daemon-commands.js +6 -66
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +35 -2
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/restart-monitor.js +45 -47
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +0 -7
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/schema-migration.js +6 -1
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +104 -10
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +60 -130
- package/dist/core/channel-loader.js +10 -1
- package/dist/core/channel-runtime.js +4 -3
- package/dist/core/command/agent-control.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +53 -11
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +338 -0
- package/dist/core/command/menu-catalog.js +8 -0
- package/dist/core/command/menu-handler.js +198 -84
- package/dist/core/command/menu-protocol.js +60 -11
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +8 -5
- package/dist/core/daemon-lifecycle.js +132 -73
- package/dist/core/handoff/runtime.js +3 -3
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +46 -7
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +147 -17
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +4 -0
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/response-engine.js +157 -54
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +43 -5
- package/dist/core/ownership/owner-resolver.js +7 -0
- package/dist/core/permission/ec-command-parser.js +3 -2
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +2 -3
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/directory/owner-directory-admission.js +40 -53
- package/dist/directory/owner-directory-cache.js +89 -113
- package/dist/directory/owner-directory-query-operation.js +8 -10
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +6 -2
- package/dist/ecweb/runtime/supervisor.js +19 -4
- package/dist/event-center/admission-materializer.js +114 -0
- package/dist/event-center/bus-gate.js +136 -0
- package/dist/event-center/bus-host.js +290 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +100 -0
- package/dist/event-center/client-factory.js +50 -0
- package/dist/event-center/daemon.js +45 -0
- package/dist/event-center/directory-source.js +53 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +63 -0
- package/dist/event-center/ipc-operation.js +308 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +202 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +238 -0
- package/dist/event-center/runtime.js +641 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +35 -0
- package/dist/event-center/validation.js +413 -0
- package/dist/index.js +285 -99
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +5 -1
- package/dist/proxy/service-supervisor.js +13 -4
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +458 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +204 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +95 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +18 -0
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +24 -10
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/process-introspect.js +45 -9
- package/dist/utils/startup-trace.js +74 -37
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +7 -14
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +2 -0
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/event-center.md +207 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +3 -2
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +15 -3
- package/kits/docs/evolcore/provider.md +3 -1
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +277 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/eck_manifest.json +26 -0
- package/kits/rules/02-navigation.md +10 -1
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/reply.md +0 -5
- package/kits/templates/system-fragments/thread.md +10 -8
- package/package.json +3 -5
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -7,32 +7,32 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { logger } from '../utils/logger.js';
|
|
9
9
|
import { PluginHandle } from './plugin-lifecycle.js';
|
|
10
|
-
/**
|
|
11
|
-
* 有界并发 map:保持输入顺序返回结果。
|
|
12
|
-
*
|
|
13
|
-
* 不用 Promise.all 是因为这里的任务会拉起外部进程,全量并发会让它们同时抢 CPU;
|
|
14
|
-
* 也不需要通用工具库——只有这一处用。
|
|
15
|
-
*/
|
|
16
|
-
async function mapWithConcurrency(items, limit, fn) {
|
|
17
|
-
const results = new Array(items.length);
|
|
18
|
-
let cursor = 0;
|
|
19
|
-
const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
20
|
-
while (true) {
|
|
21
|
-
const index = cursor++;
|
|
22
|
-
if (index >= items.length)
|
|
23
|
-
return;
|
|
24
|
-
results[index] = await fn(items[index], index);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
const outcomes = await Promise.allSettled(workers);
|
|
28
|
-
const failed = outcomes.find((outcome) => outcome.status === 'rejected');
|
|
29
|
-
if (failed)
|
|
30
|
-
throw failed.reason;
|
|
31
|
-
return results;
|
|
32
|
-
}
|
|
33
10
|
/** Agent Loader — produces one runner per (EvolAgent × baseagent). */
|
|
34
11
|
export class AgentLoader {
|
|
35
12
|
plugins = new Map();
|
|
13
|
+
creationSlots = new Map();
|
|
14
|
+
enabledBaseagents(agent) {
|
|
15
|
+
return [...this.plugins].filter(([, plugin]) => plugin.isEnabled(agent)).map(([name]) => name);
|
|
16
|
+
}
|
|
17
|
+
async withCreationSlot(backend, create) {
|
|
18
|
+
let slots = this.creationSlots.get(backend);
|
|
19
|
+
if (!slots)
|
|
20
|
+
this.creationSlots.set(backend, slots = { active: 0, waiting: [] });
|
|
21
|
+
if (slots.active < 4)
|
|
22
|
+
slots.active++;
|
|
23
|
+
else
|
|
24
|
+
await new Promise(resolve => slots.waiting.push(resolve));
|
|
25
|
+
try {
|
|
26
|
+
return await create();
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
const next = slots.waiting.shift();
|
|
30
|
+
if (next)
|
|
31
|
+
next();
|
|
32
|
+
else
|
|
33
|
+
slots.active--;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
36
|
register(plugin) {
|
|
37
37
|
if (this.plugins.has(plugin.name)) {
|
|
38
38
|
throw new Error(`Agent plugin '${plugin.name}' already registered`);
|
|
@@ -41,129 +41,56 @@ export class AgentLoader {
|
|
|
41
41
|
logger.debug(`Registered agent plugin: ${plugin.name}`);
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
* Each successful (agent, plugin) pair yields one runner instance.
|
|
44
|
+
* Create each Agent's selected backend. Other backends are created on demand.
|
|
46
45
|
*/
|
|
47
|
-
async createAll(registry, callbacks, creationErrors, onAgentCreated, shouldCreateAgent = () => true, onActiveCreated, startupPriority) {
|
|
48
|
-
const
|
|
49
|
-
const allAgents = registry.runnableAgents();
|
|
50
|
-
// A slow CLI consumes only its backend's slots. Keeping one bounded lane
|
|
51
|
-
// per plugin prevents four pending Codex probes from starving Claude or
|
|
52
|
-
// ecagent Agents later in registry order. Active work precedes standby
|
|
53
|
-
// work within each lane, without a barrier between different backends.
|
|
46
|
+
async createAll(registry, callbacks, creationErrors, onAgentCreated, shouldCreateAgent = () => true, onActiveCreated, startupPriority, onAgentStarting, preloadAids, prepareAgent) {
|
|
47
|
+
const allAgents = registry.runnableAgents().filter(agent => !preloadAids || preloadAids.has(agent.aid));
|
|
54
48
|
const created = allAgents.map(() => []);
|
|
55
|
-
const startedAt = allAgents.map(() => Date.now());
|
|
56
|
-
const activeResolvers = [];
|
|
57
|
-
const activeReady = allAgents.map(() => new Promise(resolve => activeResolvers.push(resolve)));
|
|
58
49
|
const agentsByBackend = new Map();
|
|
59
50
|
allAgents.forEach((agent, index) => {
|
|
60
51
|
const indices = agentsByBackend.get(agent.baseagent) ?? [];
|
|
61
52
|
indices.push(index);
|
|
62
53
|
agentsByBackend.set(agent.baseagent, indices);
|
|
63
54
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
return shouldCreateAgent()
|
|
87
|
-
? await this.createForAgent(agent, callbacks, creationErrors, name => name === backend) : [];
|
|
88
|
-
}
|
|
89
|
-
finally {
|
|
90
|
-
const next = waitingCreations.shift();
|
|
91
|
-
if (next)
|
|
92
|
-
next();
|
|
93
|
-
else
|
|
94
|
-
activeCreations--;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const standbyTasks = [];
|
|
98
|
-
try {
|
|
99
|
-
for (const priority of startupPriority ? [true, false] : [true]) {
|
|
100
|
-
// Wait outside bounded lanes: deferred Agents cannot occupy capacity
|
|
101
|
-
// needed to publish a recovering Agent's active or standby runner.
|
|
102
|
-
const groupIndices = allAgents.map((_, index) => index).filter(index => !startupPriority || startupPriority.aids.has(allAgents[index].aid) === priority);
|
|
103
|
-
if (!groupIndices.length)
|
|
104
|
-
continue;
|
|
105
|
-
if (!priority)
|
|
106
|
-
await startupPriority.waitForDeferred();
|
|
107
|
-
const activeIndices = groupIndices.filter(index => allAgents[index].baseagent === backend);
|
|
108
|
-
try {
|
|
109
|
-
await mapWithConcurrency(activeIndices, 4, async (index) => {
|
|
110
|
-
const agent = allAgents[index];
|
|
111
|
-
startedAt[index] = Date.now();
|
|
112
|
-
try {
|
|
113
|
-
const active = await create(agent);
|
|
114
|
-
created[index].push(...active);
|
|
115
|
-
await onActiveCreated?.(agent, active, { startedAtMs: startedAt[index], completedAtMs: Date.now() });
|
|
116
|
-
await completeBackend(index);
|
|
117
|
-
}
|
|
118
|
-
finally {
|
|
119
|
-
activeResolvers[index]();
|
|
120
|
-
}
|
|
55
|
+
// Independent bounded lanes keep a slow backend from holding other Agents.
|
|
56
|
+
// Deferred groups wait outside those lanes, so waiting consumes no capacity.
|
|
57
|
+
const outcomes = await Promise.allSettled([...agentsByBackend.values()].map(async (indices) => {
|
|
58
|
+
for (const priority of startupPriority ? [true, false] : [true]) {
|
|
59
|
+
const group = indices.filter(index => !startupPriority || startupPriority.aids.has(allAgents[index].aid) === priority);
|
|
60
|
+
if (!group.length)
|
|
61
|
+
continue;
|
|
62
|
+
if (!priority)
|
|
63
|
+
await startupPriority.waitForDeferred();
|
|
64
|
+
// Classification waits must not occupy creation slots. createForAgent
|
|
65
|
+
// bounds actual process work to four per backend, including demand loads.
|
|
66
|
+
const prepared = await Promise.allSettled(group.map(async (index) => {
|
|
67
|
+
const agent = allAgents[index];
|
|
68
|
+
if (prepareAgent && !await prepareAgent(agent))
|
|
69
|
+
return;
|
|
70
|
+
const startedAtMs = Date.now();
|
|
71
|
+
if (shouldCreateAgent()) {
|
|
72
|
+
onAgentStarting?.(agent);
|
|
73
|
+
created[index] = await this.createForAgent(agent, callbacks, creationErrors, backend => backend === agent.baseagent, () => {
|
|
74
|
+
if (!shouldCreateAgent())
|
|
75
|
+
throw new Error('Agent startup cancelled');
|
|
121
76
|
});
|
|
122
77
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const agent = allAgents[index];
|
|
131
|
-
if (agent.baseagent === backend)
|
|
132
|
-
return;
|
|
133
|
-
// The same Agent's active publication configures task callbacks before
|
|
134
|
-
// standby publication; other Agents' active lanes remain independent.
|
|
135
|
-
await activeReady[index];
|
|
136
|
-
created[index].push(...await create(agent));
|
|
137
|
-
await completeBackend(index);
|
|
138
|
-
}).then(() => { });
|
|
139
|
-
standbyTasks.push(standby);
|
|
140
|
-
// Observe immediately, then propagate after every lane task settles.
|
|
141
|
-
void standby.catch(() => { });
|
|
142
|
-
if (!startupPriority)
|
|
143
|
-
await standby;
|
|
144
|
-
}
|
|
145
|
-
const standbyOutcomes = await Promise.allSettled(standbyTasks);
|
|
146
|
-
const failure = standbyOutcomes.find((outcome) => outcome.status === 'rejected');
|
|
147
|
-
if (failure)
|
|
148
|
-
throw failure.reason;
|
|
149
|
-
}
|
|
150
|
-
finally {
|
|
151
|
-
// A callback failure can retire this lane before its deferred group.
|
|
152
|
-
// Other backends must still be able to settle their standby waits.
|
|
153
|
-
for (const index of agentsByBackend.get(backend) ?? [])
|
|
154
|
-
activeResolvers[index]();
|
|
155
|
-
await Promise.allSettled(standbyTasks);
|
|
78
|
+
const timing = { startedAtMs, completedAtMs: Date.now() };
|
|
79
|
+
await onActiveCreated?.(agent, created[index], timing);
|
|
80
|
+
await onAgentCreated?.(agent, created[index], timing);
|
|
81
|
+
}));
|
|
82
|
+
const failed = prepared.find((outcome) => outcome.status === 'rejected');
|
|
83
|
+
if (failed)
|
|
84
|
+
throw failed.reason;
|
|
156
85
|
}
|
|
157
86
|
}));
|
|
158
87
|
const failed = outcomes.find((outcome) => outcome.status === 'rejected');
|
|
159
88
|
if (failed)
|
|
160
89
|
throw failed.reason;
|
|
161
|
-
|
|
162
|
-
instances.push(...agentInstances);
|
|
163
|
-
return instances;
|
|
90
|
+
return created.flat();
|
|
164
91
|
}
|
|
165
92
|
/** Create runners for one EvolAgent, used by runtime hot-load. */
|
|
166
|
-
async createForAgent(agent, callbacks, creationErrors, selectPlugin = () => true) {
|
|
93
|
+
async createForAgent(agent, callbacks, creationErrors, selectPlugin = () => true, onCreating) {
|
|
167
94
|
const instances = [];
|
|
168
95
|
for (const [pluginName, plugin] of this.plugins) {
|
|
169
96
|
if (!selectPlugin(pluginName))
|
|
@@ -175,7 +102,10 @@ export class AgentLoader {
|
|
|
175
102
|
let teardown;
|
|
176
103
|
const lifecycle = new PluginHandle(`${agent.name}::${pluginName}`, () => teardown?.());
|
|
177
104
|
try {
|
|
178
|
-
const instance = await
|
|
105
|
+
const instance = await this.withCreationSlot(pluginName, async () => {
|
|
106
|
+
onCreating?.();
|
|
107
|
+
return await plugin.createAgent(agent, callbacks, lifecycle);
|
|
108
|
+
});
|
|
179
109
|
if (!instance) {
|
|
180
110
|
await lifecycle.dispose();
|
|
181
111
|
logger.debug(`Plugin '${pluginName}' returned null for agent '${agent.name}', skipping`);
|
|
@@ -294,7 +294,9 @@ export class ChannelLoader {
|
|
|
294
294
|
throw error;
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
|
-
async connectAll(instances, { concurrency = 3, intervalMs = 50, beforeConnect, shouldConnect, onConnected, onFailed, connect } = {}) {
|
|
297
|
+
async connectAll(instances, { concurrency = 3, intervalMs = 50, beforeConnect, shouldConnect, onConnected, onFailed, connect, sharedAdmission = false } = {}) {
|
|
298
|
+
if (sharedAdmission && !connect)
|
|
299
|
+
throw new Error('Shared connection admission requires a connect callback');
|
|
298
300
|
const connected = [];
|
|
299
301
|
const failed = [];
|
|
300
302
|
const inflight = new Set();
|
|
@@ -345,6 +347,13 @@ export class ChannelLoader {
|
|
|
345
347
|
}
|
|
346
348
|
return;
|
|
347
349
|
}
|
|
350
|
+
if (sharedAdmission) {
|
|
351
|
+
// Do not hide ready priority work behind a second FIFO whose slots
|
|
352
|
+
// include time spent waiting in the actual shared admission queue.
|
|
353
|
+
if (shouldConnect?.(inst) !== false)
|
|
354
|
+
startConnection(inst);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
348
357
|
const dispatch = dispatchTail.then(async () => {
|
|
349
358
|
while (inflight.size >= Math.max(1, concurrency))
|
|
350
359
|
await Promise.race(inflight);
|
|
@@ -28,14 +28,15 @@ export function createAgentStorageClientResolver(channelInstances) {
|
|
|
28
28
|
return client?.aid === targetAid ? client : undefined;
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
export function bindStartupChannelsToAgents(channelInstances, agentRegistry, agentInstances) {
|
|
31
|
+
export function bindStartupChannelsToAgents(channelInstances, agentRegistry, agentInstances, onDemandAids) {
|
|
32
32
|
for (const instance of channelInstances) {
|
|
33
33
|
const agent = agentRegistry.resolveByChannel(instance.adapter.channelKey);
|
|
34
|
-
if (!agent || agent.status === 'error')
|
|
34
|
+
if (!agent || agent.status === 'error' || agent.status === 'disabled')
|
|
35
35
|
continue;
|
|
36
36
|
agent.channels.set(instance.adapter.channelKey, instance.adapter);
|
|
37
37
|
const hasRunner = agentInstances.some(runner => runner.evolagentName === agent.aid);
|
|
38
|
-
|
|
38
|
+
// Agent admission is separate from whether its backend is already loaded.
|
|
39
|
+
if (agent.status === 'stopped' && (hasRunner || onDemandAids?.has(agent.aid)))
|
|
39
40
|
agent.status = 'running';
|
|
40
41
|
}
|
|
41
42
|
}
|
|
@@ -146,7 +146,7 @@ async function execOneShotCreate(a, peerId, service, subject) {
|
|
|
146
146
|
}
|
|
147
147
|
if (a.chatmode !== undefined && (!a.chatmode || typeof a.chatmode !== 'object' || Array.isArray(a.chatmode)
|
|
148
148
|
|| Object.entries(a.chatmode).some(([key, value]) => !['private', 'group', 'nothuman'].includes(key)
|
|
149
|
-
|| !(key === 'group' ? ['proactive'] : ['interactive', 'proactive'
|
|
149
|
+
|| !(key === 'group' ? ['proactive'] : ['interactive', 'proactive']).includes(value)))) {
|
|
150
150
|
return { error: 'chatmode 必须包含有效的 private/group/nothuman 模式', code: 'INVALID_ARGS' };
|
|
151
151
|
}
|
|
152
152
|
let avatarUrl;
|
|
@@ -4,7 +4,7 @@ import { readAunPeerKind } from '../relation/peer-identity.js';
|
|
|
4
4
|
import { listStaticAgentOwners } from '../../config/peer-role-resolver.js';
|
|
5
5
|
import { authorizeOperation } from '../auth/auth-gateway.js';
|
|
6
6
|
import { auditCommandAuthorization } from '../auth/authorization-audit.js';
|
|
7
|
-
import { DataRootError } from './
|
|
7
|
+
import { DataRootError } from './team-workspace-store.js';
|
|
8
8
|
const ROOT_TTL_MS = 10 * 60_000;
|
|
9
9
|
const OPERATIONS = {
|
|
10
10
|
root: 'file.root.storage', list: 'file.storage.list', query: 'file.storage.query',
|
|
@@ -1,42 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { formatPeerKey, parsePeerKey, readAunPeerKind } from '../relation/peer-identity.js';
|
|
1
|
+
import { mutateConfig, routeFieldPath, } from '../../config/config-manager.js';
|
|
3
2
|
/** Both command entry points authorize the operation before calling this writer. */
|
|
4
|
-
export function writeChatmodeConfig(target, value
|
|
3
|
+
export function writeChatmodeConfig(target, value) {
|
|
5
4
|
const route = routeFieldPath(`chatmode.${target.field}`, target.scope);
|
|
6
5
|
mutateConfig(route.target, target.sel, config => {
|
|
7
|
-
if (route.target === ConfigTarget.Relation && value === 'paactive') {
|
|
8
|
-
const denied = () => new ConfigError('NOT_APPLICABLE', 'paactive 仅支持已确认的 AUN 私聊关系');
|
|
9
|
-
if (target.field !== 'private' || !target.sel.self || !target.sel.peerKey)
|
|
10
|
-
throw denied();
|
|
11
|
-
let peer;
|
|
12
|
-
try {
|
|
13
|
-
peer = parsePeerKey(target.sel.peerKey);
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
throw denied();
|
|
17
|
-
}
|
|
18
|
-
if (peer.channelType !== 'aun')
|
|
19
|
-
throw denied();
|
|
20
|
-
// Request args select a relation, but cannot supply its kind. Only use
|
|
21
|
-
// authenticated routing when it names this exact Agent and conversation.
|
|
22
|
-
let routeKind;
|
|
23
|
-
if (!subject.fromControlChannel && subject.selfAid === target.sel.self
|
|
24
|
-
&& subject.channelType === 'aun' && subject.conversationId === peer.channelId
|
|
25
|
-
&& (!subject.peerKey || subject.peerKey === formatPeerKey('aun', peer.channelId))) {
|
|
26
|
-
if (subject.chatType === 'group' || subject.menuTransportChatType === 'group') {
|
|
27
|
-
routeKind = 'group';
|
|
28
|
-
}
|
|
29
|
-
else if (subject.chatType === 'private' && subject.actorId === peer.channelId) {
|
|
30
|
-
routeKind = 'private';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const resolution = readAunPeerKind(target.sel.self, peer.channelId, {
|
|
34
|
-
routeKind, relation: config,
|
|
35
|
-
});
|
|
36
|
-
if (resolution.kind !== 'private')
|
|
37
|
-
throw denied();
|
|
38
|
-
config.targetKind = 'private';
|
|
39
|
-
}
|
|
40
6
|
const block = config.chatmode && typeof config.chatmode === 'object' && !Array.isArray(config.chatmode)
|
|
41
7
|
? { ...config.chatmode }
|
|
42
8
|
: {};
|
|
@@ -15,7 +15,6 @@ import { logger } from '../../utils/logger.js';
|
|
|
15
15
|
import { resolvePeerRoleDetail, roleToSessionIdentity } from '../../config/peer-role-resolver.js';
|
|
16
16
|
import { ThreadService } from '../thread/thread-service.js';
|
|
17
17
|
import { isManagementRole } from '../../config/builtin-roles.js';
|
|
18
|
-
import { resolveAgentLifecycle } from '../../config/lifecycle.js';
|
|
19
18
|
import { formatPeerKey } from '../relation/peer-identity.js';
|
|
20
19
|
import { sameGroupAid } from '../../aun/group/index.js';
|
|
21
20
|
import crypto from 'crypto';
|
|
@@ -57,9 +56,10 @@ import { constrainRuntimePermissionMode, resolveRuntimePermissionMode, validateR
|
|
|
57
56
|
import { parsePeerKey } from '../relation/peer-identity.js';
|
|
58
57
|
import { isQuickCommand } from './slash-gate.js';
|
|
59
58
|
import { handleSlashCommand } from './slash-handler.js';
|
|
60
|
-
import {
|
|
59
|
+
import { resolveChatMode } from '../message/peer-mode.js';
|
|
61
60
|
import { execMenuAction as menuExecMenuAction, execMenuForEcweb as menuExecMenuForEcweb, execMenuForControl as menuExecMenuForControl, execMenuQuery as menuExecMenuQuery, execMenuUpdate as menuExecMenuUpdate, getMenuItems as menuGetMenuItems, getSubMenuItems as menuGetSubMenuItems, buildTopicForkSourcePayload, } from './menu-handler.js';
|
|
62
61
|
import { getMenuCatalog, execMenuValueBatch, validateMenuValueBatchArgs } from './menu-catalog.js';
|
|
62
|
+
import { execMenuQueryBatch } from './menu-query-batch.js';
|
|
63
63
|
import { resolveCurrentSessionLoopTarget, sessionLoopError } from '../session/session-idle-monitor.js';
|
|
64
64
|
export { isProcessLevelOwner } from './menu-handler.js';
|
|
65
65
|
const CLI_EXEC_TIMEOUT_MS = 15_000;
|
|
@@ -106,6 +106,7 @@ export class CommandHandler {
|
|
|
106
106
|
legacySingleRunnerMode;
|
|
107
107
|
primaryRunnerKey;
|
|
108
108
|
agentRegistry;
|
|
109
|
+
teamWorkspaceManagementService;
|
|
109
110
|
memoryConsolidationLauncher;
|
|
110
111
|
/** /skill refresh 的 daemon 侧入口:重建指定 agent 的技能索引 */
|
|
111
112
|
skillIndexRefresher;
|
|
@@ -234,8 +235,38 @@ export class CommandHandler {
|
|
|
234
235
|
logger.error(`[RunnerLookup] unavailable channel=${channel ?? '<none>'} baseagent=${requestedBaseagent || '<missing>'} keys=${[...this.agentMap.keys()].join(',')}`);
|
|
235
236
|
throw new BaseagentRunnerUnavailableError('<unknown>', requestedBaseagent || '<missing>', []);
|
|
236
237
|
}
|
|
238
|
+
runnerReadiness;
|
|
239
|
+
configuredBaseagents;
|
|
240
|
+
setRunnerReadiness(ensure, available) {
|
|
241
|
+
this.runnerReadiness = ensure;
|
|
242
|
+
this.configuredBaseagents = available;
|
|
243
|
+
}
|
|
244
|
+
/** Commands that use backend state load it; activity probes keep using getAgent. */
|
|
245
|
+
async ensureAgent(channel, baseagent, selfAid) {
|
|
246
|
+
const owner = selfAid ? this.agentRegistry?.get(selfAid) : channel ? this.agentRegistry?.resolveByChannel(channel) : undefined;
|
|
247
|
+
if (owner && baseagent && this.runnerReadiness) {
|
|
248
|
+
await this.runnerReadiness(owner.aid, baseagent);
|
|
249
|
+
const runner = this.agentMap.get(`${owner.aid}::${baseagent}`);
|
|
250
|
+
if (runner)
|
|
251
|
+
return runner;
|
|
252
|
+
}
|
|
253
|
+
return this.getAgent(channel, baseagent);
|
|
254
|
+
}
|
|
255
|
+
getLoadedAgent(channel, baseagent) {
|
|
256
|
+
const owner = this.agentRegistry?.resolveByChannel(channel);
|
|
257
|
+
if (owner && this.configuredBaseagents) {
|
|
258
|
+
const runner = this.agentMap.get(`${owner.aid}::${baseagent}`);
|
|
259
|
+
if (runner)
|
|
260
|
+
return runner;
|
|
261
|
+
const available = this.configuredBaseagents(owner.aid);
|
|
262
|
+
if (available.includes(baseagent))
|
|
263
|
+
return undefined;
|
|
264
|
+
throw new BaseagentRunnerUnavailableError(owner.aid, baseagent, available);
|
|
265
|
+
}
|
|
266
|
+
return this.getAgent(channel, baseagent);
|
|
267
|
+
}
|
|
237
268
|
getAvailableBaseagentsForOwner(evolName) {
|
|
238
|
-
return loadedBaseagentIds(this.agentMap.keys(), evolName);
|
|
269
|
+
return this.configuredBaseagents?.(evolName) ?? loadedBaseagentIds(this.agentMap.keys(), evolName);
|
|
239
270
|
}
|
|
240
271
|
/** Return the stable temporary root for a managed session, if available. */
|
|
241
272
|
getManagedSessionTempDir(session) {
|
|
@@ -255,10 +286,12 @@ export class CommandHandler {
|
|
|
255
286
|
getAvailableBaseagents(channel) {
|
|
256
287
|
const owner = this.agentRegistry?.resolveByChannel(channel);
|
|
257
288
|
if (!owner) {
|
|
258
|
-
return
|
|
289
|
+
return this.configuredBaseagents && this.agentRegistry
|
|
290
|
+
? [...new Set(this.agentRegistry.list().flatMap(agent => this.configuredBaseagents(agent.aid)))]
|
|
291
|
+
: loadedBaseagentIds(this.agentMap.keys());
|
|
259
292
|
}
|
|
260
293
|
const evolName = owner.name || '<unknown>';
|
|
261
|
-
return
|
|
294
|
+
return this.getAvailableBaseagentsForOwner(evolName);
|
|
262
295
|
}
|
|
263
296
|
/** Extract the baseagent component from `primaryRunnerKey` (e.g. `aid::claude` → `claude`). */
|
|
264
297
|
parseDefaultBaseagent() {
|
|
@@ -285,6 +318,14 @@ export class CommandHandler {
|
|
|
285
318
|
setAgentRegistry(registry) {
|
|
286
319
|
this.agentRegistry = registry;
|
|
287
320
|
}
|
|
321
|
+
setTeamWorkspaceManagementService(service) {
|
|
322
|
+
this.teamWorkspaceManagementService = service;
|
|
323
|
+
}
|
|
324
|
+
/** 事件中心(menu events)。字段名避开既有的进程内 `eventBus`。 */
|
|
325
|
+
eventCenter;
|
|
326
|
+
setEventCenter(registry) {
|
|
327
|
+
this.eventCenter = registry;
|
|
328
|
+
}
|
|
288
329
|
/** Inject the Core-owned agent application facade after runtime hooks exist. */
|
|
289
330
|
setAgentApplicationService(service) {
|
|
290
331
|
this.agentApplicationService = service;
|
|
@@ -1105,6 +1146,12 @@ export class CommandHandler {
|
|
|
1105
1146
|
execQuery: async (cmd, resolvedChannelId, queryArgs, context) => this.execMenuQuery(cmd, channel, resolvedChannelId, context.subject.actorId, queryArgs, context.subject.chatType, context.subject.fromControlChannel, context.subject.identity, context.subject, channelScope === 'control' ? 'control' : 'menu', resolvedChannelId === channelId ? transportReplyContext : undefined),
|
|
1106
1147
|
});
|
|
1107
1148
|
}
|
|
1149
|
+
async execMenuQueryBatch(channel, channelId, subject, args, channelScope = 'agent', transportReplyContext) {
|
|
1150
|
+
return execMenuQueryBatch({
|
|
1151
|
+
subject, channelType: this.resolveChannelType(channel), channelScope, channelId, args,
|
|
1152
|
+
execQuery: (cmd, resolvedChannelId, queryArgs, querySubject) => this.execMenuQuery(cmd, channel, resolvedChannelId, querySubject.actorId, queryArgs, querySubject.chatType, querySubject.fromControlChannel, querySubject.identity, querySubject, channelScope === 'control' ? 'control' : 'menu', resolvedChannelId === channelId ? transportReplyContext : undefined),
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1108
1155
|
/** 动态子菜单:根据 cmd 路径返回选项列表(供 menu.query + cmd 使用) */
|
|
1109
1156
|
async getSubMenuItems(cmd, channel, channelId, userId, args, overrideIdentity, explicitChatType, fromControlChannel = false, authSubject, source = 'menu', transportReplyContext) {
|
|
1110
1157
|
return await menuGetSubMenuItems.call(this, cmd, channel, channelId, userId, args, overrideIdentity, explicitChatType, fromControlChannel, authSubject, source, transportReplyContext);
|
|
@@ -1832,10 +1879,7 @@ export class CommandHandler {
|
|
|
1832
1879
|
if (meta?.replyContext?.replyInThread)
|
|
1833
1880
|
ctx.replyInThread = meta.replyContext.replyInThread;
|
|
1834
1881
|
const taskId = this.sessionManager.getActiveTaskId(session.id);
|
|
1835
|
-
const
|
|
1836
|
-
? meta.turnState.active.recoveryContext?.chatmode
|
|
1837
|
-
: undefined;
|
|
1838
|
-
const chatmode = isChatMode(taskChatmode) ? taskChatmode : this.resolveEffectiveChatmodeForSession(session);
|
|
1882
|
+
const chatmode = this.resolveEffectiveChatmodeForSession(session);
|
|
1839
1883
|
const encrypted = this.sessionManager.getSessionEncrypt(session.id);
|
|
1840
1884
|
// 诊断日志:记录 task_id 解析结果
|
|
1841
1885
|
logger.info(`[CommandHandler] buildCtlReplyContext: sessionId=${session.id} taskId=${taskId ?? 'none'} chatmode=${chatmode} threadId=${ctx.threadId ?? 'none'} replyTo=${ctx.replyToMessageId ?? 'none'} inThread=${ctx.replyInThread ?? false}`);
|
|
@@ -1866,8 +1910,6 @@ export class CommandHandler {
|
|
|
1866
1910
|
chatType: session.chatType,
|
|
1867
1911
|
peerType,
|
|
1868
1912
|
channelType,
|
|
1869
|
-
lifecycle: resolveAgentLifecycle(this.getOwningAgent(session.channel)?.config ?? {}),
|
|
1870
|
-
sessionType: session.sessionType ?? session.metadata?.sessionType ?? 'main',
|
|
1871
1913
|
});
|
|
1872
1914
|
}
|
|
1873
1915
|
catch {
|
|
@@ -5,8 +5,8 @@ import { isValidAid } from '../../aun/aid/validation.js';
|
|
|
5
5
|
import { isStaticAgentOwner } from '../../config/peer-role-resolver.js';
|
|
6
6
|
import { agentDir, agentRelationSharedDir } from '../../paths.js';
|
|
7
7
|
import { formatPeerKey, readAunPeerKind } from '../relation/peer-identity.js';
|
|
8
|
-
import { DataRootError,
|
|
9
|
-
export { DataRootError } from './
|
|
8
|
+
import { DataRootError, teamWorkspaceStore } from './team-workspace-store.js';
|
|
9
|
+
export { DataRootError } from './team-workspace-store.js';
|
|
10
10
|
const DEFAULT_ROOT_TTL_MS = 10 * 60 * 1000;
|
|
11
11
|
const TOKEN_PREFIX = 'dr1';
|
|
12
12
|
function base64Url(value) {
|
|
@@ -31,7 +31,7 @@ export class DataRootResolver {
|
|
|
31
31
|
isOwner;
|
|
32
32
|
resolveAgentPath;
|
|
33
33
|
resolveRelationSharedPath;
|
|
34
|
-
|
|
34
|
+
teamStore;
|
|
35
35
|
constructor(options = {}) {
|
|
36
36
|
this.secret = options.secret ?? crypto.randomBytes(32);
|
|
37
37
|
if (this.secret.length < 32)
|
|
@@ -41,7 +41,7 @@ export class DataRootResolver {
|
|
|
41
41
|
this.isOwner = options.isOwner ?? isStaticAgentOwner;
|
|
42
42
|
this.resolveAgentPath = options.resolveAgentPath ?? agentDir;
|
|
43
43
|
this.resolveRelationSharedPath = options.resolveRelationSharedPath ?? agentRelationSharedDir;
|
|
44
|
-
this.
|
|
44
|
+
this.teamStore = options.teamStore ?? teamWorkspaceStore;
|
|
45
45
|
}
|
|
46
46
|
issueAgentRoot(subject) {
|
|
47
47
|
const targetAid = this.targetAid(subject);
|
|
@@ -74,18 +74,18 @@ export class DataRootResolver {
|
|
|
74
74
|
const rootPath = this.canonicalRoot(this.resolveRelationSharedPath(targetAid, peerKey), agentRoot);
|
|
75
75
|
return this.issueDescriptor({ scope: 'relation', targetAid, principalId, peerAid, peerKey }, rootPath);
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
issueTeamWorkspaceRoot(subject) {
|
|
78
78
|
const targetAid = this.targetAid(subject);
|
|
79
79
|
this.assertPrivateAun(subject);
|
|
80
80
|
const principalId = authenticatedPrincipal(subject);
|
|
81
81
|
if (subject.role !== 'owner' || !this.isOwner(targetAid, principalId)) {
|
|
82
|
-
throw new DataRootError('ROOT_FORBIDDEN', '
|
|
82
|
+
throw new DataRootError('ROOT_FORBIDDEN', 'Team workspace root requires Agent owner permission');
|
|
83
83
|
}
|
|
84
|
-
const state = this.
|
|
84
|
+
const state = this.teamStore.require(targetAid);
|
|
85
85
|
if (state.ownerAid !== principalId) {
|
|
86
|
-
throw new DataRootError('ROOT_FORBIDDEN', '
|
|
86
|
+
throw new DataRootError('ROOT_FORBIDDEN', 'Team workspace is bound to another owner');
|
|
87
87
|
}
|
|
88
|
-
return this.issueDescriptor({ scope: '
|
|
88
|
+
return this.issueDescriptor({ scope: 'team', targetAid, principalId, workspaceId: state.workspaceId }, this.teamStore.root(state));
|
|
89
89
|
}
|
|
90
90
|
resolveRoot(rootId, subject) {
|
|
91
91
|
const claims = this.verifyToken(rootId);
|
|
@@ -120,17 +120,17 @@ export class DataRootResolver {
|
|
|
120
120
|
else {
|
|
121
121
|
this.assertPrivateAun(subject);
|
|
122
122
|
if (!claims.workspaceId)
|
|
123
|
-
throw new DataRootError('ROOT_SCOPE_MISMATCH', '
|
|
123
|
+
throw new DataRootError('ROOT_SCOPE_MISMATCH', 'Team workspace root claims are invalid');
|
|
124
124
|
if (subject.role !== 'owner' || !this.isOwner(targetAid, principalId)) {
|
|
125
|
-
throw new DataRootError('ROOT_FORBIDDEN', '
|
|
125
|
+
throw new DataRootError('ROOT_FORBIDDEN', 'Team workspace root requires Agent owner permission');
|
|
126
126
|
}
|
|
127
|
-
workspaceState = this.
|
|
127
|
+
workspaceState = this.teamStore.require(targetAid);
|
|
128
128
|
if (workspaceState.ownerAid !== principalId || workspaceState.workspaceId !== claims.workspaceId) {
|
|
129
|
-
throw new DataRootError('ROOT_SCOPE_MISMATCH', '
|
|
129
|
+
throw new DataRootError('ROOT_SCOPE_MISMATCH', 'Team workspace binding changed; request a new root');
|
|
130
130
|
}
|
|
131
|
-
rootPath = this.
|
|
131
|
+
rootPath = this.teamStore.root(workspaceState);
|
|
132
132
|
}
|
|
133
|
-
const revision = this.
|
|
133
|
+
const revision = this.descriptorRevision(claims.scope, targetAid, rootPath);
|
|
134
134
|
if (revision !== claims.revision) {
|
|
135
135
|
throw new DataRootError('ROOT_SCOPE_MISMATCH', 'Root identity changed; request a new root');
|
|
136
136
|
}
|
|
@@ -148,11 +148,11 @@ export class DataRootResolver {
|
|
|
148
148
|
resolvePath(rootId, subject, input, expectType) {
|
|
149
149
|
const root = this.resolveRoot(rootId, subject);
|
|
150
150
|
const raw = String(input ?? '').trim();
|
|
151
|
-
if (root.scope === '
|
|
152
|
-
const state = this.
|
|
151
|
+
if (root.scope === 'team') {
|
|
152
|
+
const state = this.teamStore.require(root.targetAid);
|
|
153
153
|
if (state.workspaceId !== root.workspaceId)
|
|
154
|
-
throw new DataRootError('ROOT_SCOPE_MISMATCH', '
|
|
155
|
-
const resolved = this.
|
|
154
|
+
throw new DataRootError('ROOT_SCOPE_MISMATCH', 'Team workspace binding changed; request a new root');
|
|
155
|
+
const resolved = this.teamStore.resolvePath(state, raw);
|
|
156
156
|
if (expectType === 'file' && !resolved.stat.isFile()) {
|
|
157
157
|
throw new DataRootError('NOT_SUPPORTED', 'Path is not a regular file');
|
|
158
158
|
}
|
|
@@ -201,7 +201,7 @@ export class DataRootResolver {
|
|
|
201
201
|
const claims = {
|
|
202
202
|
v: 1,
|
|
203
203
|
...base,
|
|
204
|
-
revision: this.
|
|
204
|
+
revision: this.descriptorRevision(base.scope, base.targetAid, rootPath),
|
|
205
205
|
issuedAt,
|
|
206
206
|
expiresAt: issuedAt + this.ttlMs,
|
|
207
207
|
nonce: crypto.randomBytes(12).toString('base64url'),
|
|
@@ -217,7 +217,7 @@ export class DataRootResolver {
|
|
|
217
217
|
? '$AGENTS_DIR/<targetAid>'
|
|
218
218
|
: claims.scope === 'relation'
|
|
219
219
|
? '$AGENTS_DIR/<targetAid>/relations/<peerKey>/shared'
|
|
220
|
-
: '$
|
|
220
|
+
: '$AGENTS_DIR/<targetAid>/workspace',
|
|
221
221
|
revision: `sha256:${claims.revision}`,
|
|
222
222
|
expiresAt: claims.expiresAt,
|
|
223
223
|
readOnly: true,
|
|
@@ -256,11 +256,11 @@ export class DataRootResolver {
|
|
|
256
256
|
throw new DataRootError('INVALID_ROOT_ID', 'Invalid data rootId payload');
|
|
257
257
|
}
|
|
258
258
|
if (claims.v !== 1
|
|
259
|
-
|| (claims.scope !== 'agent' && claims.scope !== 'relation' && claims.scope !== '
|
|
259
|
+
|| (claims.scope !== 'agent' && claims.scope !== 'relation' && claims.scope !== 'team')
|
|
260
260
|
|| typeof claims.targetAid !== 'string'
|
|
261
261
|
|| typeof claims.principalId !== 'string'
|
|
262
262
|
|| typeof claims.revision !== 'string'
|
|
263
|
-
|| (claims.scope === '
|
|
263
|
+
|| (claims.scope === 'team' && typeof claims.workspaceId !== 'string')
|
|
264
264
|
|| !Number.isFinite(claims.expiresAt)) {
|
|
265
265
|
throw new DataRootError('INVALID_ROOT_ID', 'Invalid data rootId claims');
|
|
266
266
|
}
|
|
@@ -292,6 +292,15 @@ export class DataRootResolver {
|
|
|
292
292
|
.update(JSON.stringify({ rootPath, dev: stat.dev, ino: stat.ino, birthtimeMs: stat.birthtimeMs }))
|
|
293
293
|
.digest('hex');
|
|
294
294
|
}
|
|
295
|
+
descriptorRevision(scope, targetAid, rootPath) {
|
|
296
|
+
const workspaceRevision = this.rootRevision(rootPath);
|
|
297
|
+
if (scope !== 'team')
|
|
298
|
+
return workspaceRevision;
|
|
299
|
+
const outputRoot = this.teamStore.outputRoot(this.teamStore.require(targetAid));
|
|
300
|
+
if (!outputRoot)
|
|
301
|
+
return workspaceRevision;
|
|
302
|
+
return crypto.createHash('sha256').update(`${workspaceRevision}:${this.rootRevision(outputRoot)}`).digest('hex');
|
|
303
|
+
}
|
|
295
304
|
targetAid(subject) {
|
|
296
305
|
const targetAid = String(subject.selfAid ?? '').trim();
|
|
297
306
|
if (!isValidAid(targetAid))
|