@dsmm/dsmm 0.3.13 → 0.3.15
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/README.md +77 -36
- package/docs/agent-presets.md +1 -1
- package/docs/compatibility.md +2 -2
- package/docs/deferred-native-approval-risk.md +4 -4
- package/docs/design.md +1 -1
- package/docs/lsp.md +1 -1
- package/docs/model-routing.md +1 -1
- package/docs/native-permissions.md +12 -2
- package/docs/profiles.md +14 -5
- package/docs/roadmap.md +67 -30
- package/docs/runtime-recovery.md +1 -1
- package/docs/safety-guards.md +1 -1
- package/docs/settings-status.md +1 -1
- package/lib/client/DeploymentFields.js +3 -1
- package/lib/client/DeploymentPage.js +34 -2
- package/lib/client/EditableChoice.js +5 -2
- package/lib/client/PermissionsPanel.js +1 -1
- package/lib/client/ProfileModelsDialog.d.ts +4 -2
- package/lib/client/ProfileModelsDialog.js +46 -7
- package/lib/client/ProfilesSection.js +47 -17
- package/lib/client/RoleToolView-locales.d.ts +1 -1
- package/lib/client/RoleToolView-locales.js +2 -2
- package/lib/client/SessionProfiles.js +24 -6
- package/lib/client/children-locales.d.ts +1 -1
- package/lib/client/controller.d.ts +23 -1
- package/lib/client/controller.js +289 -8
- package/lib/client/deployment-locales.d.ts +2 -0
- package/lib/client/deployment-locales.js +3 -1
- package/lib/client/index.js +10 -2
- package/lib/client/locales.d.ts +8 -0
- package/lib/client/locales.js +16 -6
- package/lib/client/profile-blank.d.ts +43 -0
- package/lib/client/profile-blank.js +19 -0
- package/lib/client/session-labels.d.ts +1 -0
- package/lib/client/session-labels.js +3 -0
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +27 -12
- package/lib/client.js +714 -234
- package/lib/command-approval.d.ts +2 -0
- package/lib/command-approval.js +4 -1
- package/lib/index.js +2 -1
- package/lib/native-admission.d.ts +10 -3
- package/lib/native-admission.js +129 -28
- package/lib/profile-runtime.js +3 -5
- package/package.json +1 -1
|
@@ -32,6 +32,7 @@ export declare class CommandApprovals {
|
|
|
32
32
|
private memory;
|
|
33
33
|
private invocations;
|
|
34
34
|
private readonly retiredAgents;
|
|
35
|
+
private readonly agentGenerations;
|
|
35
36
|
private generation;
|
|
36
37
|
private readonly lifetime;
|
|
37
38
|
constructor(ctx: Context);
|
|
@@ -43,6 +44,7 @@ export declare class CommandApprovals {
|
|
|
43
44
|
guard(exec: Readonly<ToolExecution>): string | undefined;
|
|
44
45
|
finish(exec: Readonly<ToolExecution>): void;
|
|
45
46
|
invalidate(): void;
|
|
47
|
+
clearAgent(agent: Agent): void;
|
|
46
48
|
revokeAgent(agent: Agent): void;
|
|
47
49
|
retire(): void;
|
|
48
50
|
}
|
package/lib/command-approval.js
CHANGED
|
@@ -8,6 +8,7 @@ export class CommandApprovals {
|
|
|
8
8
|
memory = new WeakMap();
|
|
9
9
|
invocations = new WeakMap();
|
|
10
10
|
retiredAgents = new WeakSet();
|
|
11
|
+
agentGenerations = new WeakMap();
|
|
11
12
|
generation = {};
|
|
12
13
|
lifetime = new AbortController();
|
|
13
14
|
constructor(ctx) {
|
|
@@ -29,6 +30,7 @@ export class CommandApprovals {
|
|
|
29
30
|
const session = agent.session, workspace = session.header.cwd, context = agent.ctx, token = exec.token, args = exec.arguments;
|
|
30
31
|
const values = structuredClone(args), name = exec.name, callId = exec.callId;
|
|
31
32
|
const owner = scope.owner ?? this, realm = scope.realm ?? context, generation = this.generation;
|
|
33
|
+
const agentGeneration = this.agentGenerations.get(agent);
|
|
32
34
|
const signal = AbortSignal.any([exec.signal, this.lifetime.signal]);
|
|
33
35
|
const rules = contributions.map(rule => ({ ...rule, semantics: structuredClone(rule.semantics) }));
|
|
34
36
|
let approved = false;
|
|
@@ -55,7 +57,7 @@ export class CommandApprovals {
|
|
|
55
57
|
};
|
|
56
58
|
const sourceCurrent = () => {
|
|
57
59
|
try {
|
|
58
|
-
return generation === this.generation && (scope.sourceCurrent === undefined || scope.sourceCurrent() === scope.source);
|
|
60
|
+
return generation === this.generation && agentGeneration === this.agentGenerations.get(agent) && (scope.sourceCurrent === undefined || scope.sourceCurrent() === scope.source);
|
|
59
61
|
}
|
|
60
62
|
catch {
|
|
61
63
|
return false;
|
|
@@ -142,6 +144,7 @@ export class CommandApprovals {
|
|
|
142
144
|
}
|
|
143
145
|
finish(exec) { this.invocations.delete(exec); }
|
|
144
146
|
invalidate() { this.generation = {}; this.memory = new WeakMap(); }
|
|
147
|
+
clearAgent(agent) { this.agentGenerations.set(agent, {}); this.memory.delete(agent); }
|
|
145
148
|
revokeAgent(agent) { this.retiredAgents.add(agent); this.memory.delete(agent); }
|
|
146
149
|
retire() { this.lifetime.abort(); this.invalidate(); }
|
|
147
150
|
}
|
package/lib/index.js
CHANGED
|
@@ -79,7 +79,8 @@ export async function apply(input, config = {}, startupOptions = {}) {
|
|
|
79
79
|
const profiles = await createProfileRuntime(ctx, startup.settings, { startup, readDesired: () => deployment.readDesired(), modeController: controller,
|
|
80
80
|
runtimeView: () => runtimeAdmissionView(ctx), getMountedPermission: mountedPermission });
|
|
81
81
|
lifetime.signal.throwIfAborted();
|
|
82
|
-
admission = new NativeAdmission(ctx, profiles, policy)
|
|
82
|
+
admission = new NativeAdmission(ctx, profiles, policy, agents => { for (const agent of agents)
|
|
83
|
+
commandApprovals.clearAgent(agent); });
|
|
83
84
|
ctx.provide("dsmmNativeAdmission", admission);
|
|
84
85
|
ctx.provide("dsmmProfileRuntime", profiles);
|
|
85
86
|
ctx.provide("dsmmDeploymentConfig", deployment);
|
|
@@ -18,6 +18,7 @@ export declare class NativeAdmission {
|
|
|
18
18
|
readonly ctx: Context;
|
|
19
19
|
readonly profiles: DsmmProfileRuntime;
|
|
20
20
|
readonly policy: DsmmRolePolicy;
|
|
21
|
+
private readonly configurationCommitted;
|
|
21
22
|
readonly lifetime: AbortController;
|
|
22
23
|
private readonly pending;
|
|
23
24
|
private readonly providers;
|
|
@@ -38,9 +39,11 @@ export declare class NativeAdmission {
|
|
|
38
39
|
private readonly blankUpdates;
|
|
39
40
|
private readonly getters;
|
|
40
41
|
private readonly executions;
|
|
42
|
+
private readonly providerScopes;
|
|
43
|
+
private readonly opaqueAgents;
|
|
41
44
|
private ready;
|
|
42
45
|
private install?;
|
|
43
|
-
constructor(ctx: Context, profiles: DsmmProfileRuntime, policy: DsmmRolePolicy);
|
|
46
|
+
constructor(ctx: Context, profiles: DsmmProfileRuntime, policy: DsmmRolePolicy, configurationCommitted?: (agents: readonly Agent[]) => void);
|
|
44
47
|
activate(install: NonNullable<NativeAdmission["install"]>): void;
|
|
45
48
|
get isReady(): boolean;
|
|
46
49
|
/** Exact process-local capture, retained after retirement so stale objects never become native. */
|
|
@@ -54,14 +57,18 @@ export declare class NativeAdmission {
|
|
|
54
57
|
invocation(agent: Agent): ResolvedRoleInvocation | undefined;
|
|
55
58
|
ensure(agent: Agent): Promise<DsmmProfileAdmission>;
|
|
56
59
|
assert(agent: Agent): DsmmProfileAdmission;
|
|
60
|
+
private assertBinding;
|
|
61
|
+
private residentTree;
|
|
62
|
+
private observeProviders;
|
|
57
63
|
blankReason(agent: Agent, allowQueued?: boolean): SessionActionUnavailableReason | undefined;
|
|
58
64
|
/** Reserved by runMaintenance; newly queued input belongs to the accepted choice. */
|
|
59
|
-
beginBlank(agent: Agent, signal: AbortSignal, assertAuthority: () => void): {
|
|
65
|
+
beginBlank(agent: Agent, signal: AbortSignal, assertAuthority: () => void): Promise<{
|
|
60
66
|
assertCurrent(): void;
|
|
61
67
|
prepare(admission: DsmmProfileAdmission, describe: () => void): Promise<void>;
|
|
62
68
|
committed(): void;
|
|
63
69
|
close(): Promise<void>;
|
|
64
|
-
}
|
|
70
|
+
}>;
|
|
71
|
+
private trackExecution;
|
|
65
72
|
reserve(exec: Readonly<ToolExecution>, invocation: ResolvedRoleInvocation, provider: SubagentProvider, maxDepth?: number): Promise<{
|
|
66
73
|
childId: SessionId;
|
|
67
74
|
release(): Promise<void>;
|
package/lib/native-admission.js
CHANGED
|
@@ -15,11 +15,13 @@ import { resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
|
15
15
|
import { roleFromProviderName } from "./role-providers.js";
|
|
16
16
|
import { isDsmmRoleId } from "./roles.js";
|
|
17
17
|
import { latestNativeModelSelection } from "./role-routing.js";
|
|
18
|
+
import { hasOpenTurn } from "./state.js";
|
|
18
19
|
/** Short-lived creation correlations and exact live bindings, never an execution queue. */
|
|
19
20
|
export class NativeAdmission {
|
|
20
21
|
ctx;
|
|
21
22
|
profiles;
|
|
22
23
|
policy;
|
|
24
|
+
configurationCommitted;
|
|
23
25
|
lifetime = new AbortController();
|
|
24
26
|
pending = new Map();
|
|
25
27
|
providers = new Map();
|
|
@@ -40,12 +42,15 @@ export class NativeAdmission {
|
|
|
40
42
|
blankUpdates = new WeakMap();
|
|
41
43
|
getters = new WeakMap();
|
|
42
44
|
executions = new WeakMap();
|
|
45
|
+
providerScopes = new Map();
|
|
46
|
+
opaqueAgents = new WeakSet();
|
|
43
47
|
ready = false;
|
|
44
48
|
install;
|
|
45
|
-
constructor(ctx, profiles, policy) {
|
|
49
|
+
constructor(ctx, profiles, policy, configurationCommitted = () => { }) {
|
|
46
50
|
this.ctx = ctx;
|
|
47
51
|
this.profiles = profiles;
|
|
48
52
|
this.policy = policy;
|
|
53
|
+
this.configurationCommitted = configurationCommitted;
|
|
49
54
|
scopeLifetime(ctx, "dsmm: close admission before owner teardown", () => {
|
|
50
55
|
this.lifetime.abort();
|
|
51
56
|
this.pending.clear();
|
|
@@ -59,6 +64,21 @@ export class NativeAdmission {
|
|
|
59
64
|
if (errors.length)
|
|
60
65
|
throw new AggregateError(errors, "Native activation teardown failed");
|
|
61
66
|
});
|
|
67
|
+
const observeProviders = () => { if (!this.lifetime.signal.aborted)
|
|
68
|
+
this.observeProviders(); };
|
|
69
|
+
ctx.on("subagent/provider-added", observeProviders, { global: true });
|
|
70
|
+
ctx.on("subagent/provider-removed", observeProviders, { global: true });
|
|
71
|
+
ctx.on("internal/plugin", observeProviders, { global: true });
|
|
72
|
+
ctx.on("internal/status", observeProviders, { global: true });
|
|
73
|
+
ctx.on("internal/service", name => {
|
|
74
|
+
// A Service registers in super(), before subclass fields are initialized.
|
|
75
|
+
if (name === "subagents" || name === "agents")
|
|
76
|
+
queueMicrotask(observeProviders);
|
|
77
|
+
}, { global: true });
|
|
78
|
+
// Existing Agents may have unpublished starts from before this observer.
|
|
79
|
+
for (const agent of ctx.agents.list())
|
|
80
|
+
this.opaqueAgents.add(agent);
|
|
81
|
+
observeProviders();
|
|
62
82
|
ctx.on("agent/created", async (frame) => { await this.created(frame.agent, frame.source, frame.signal); }, { global: true, prepend: true });
|
|
63
83
|
ctx.on("agent/disposed", ({ agent }) => {
|
|
64
84
|
void this.retireAgent(agent).catch(() => { });
|
|
@@ -81,11 +101,9 @@ export class NativeAdmission {
|
|
|
81
101
|
}, { global: true, prepend: true });
|
|
82
102
|
ctx.on("tools/pre-execute", async (exec, next) => {
|
|
83
103
|
if (exec.agent) {
|
|
104
|
+
this.trackExecution(exec);
|
|
84
105
|
if (await this.guardExecution(exec.agent) === "native")
|
|
85
106
|
return next();
|
|
86
|
-
const active = this.executions.get(exec.agent) ?? new Set();
|
|
87
|
-
active.add(exec.token);
|
|
88
|
-
this.executions.set(exec.agent, active);
|
|
89
107
|
}
|
|
90
108
|
return next();
|
|
91
109
|
}, { global: true, prepend: true });
|
|
@@ -112,8 +130,14 @@ export class NativeAdmission {
|
|
|
112
130
|
/** Exact process-local capture, retained after retirement so stale objects never become native. */
|
|
113
131
|
owns(agent) { return this.agentLifetimes.has(agent); }
|
|
114
132
|
async guardExecution(agent) {
|
|
115
|
-
if (!this.owns(agent))
|
|
133
|
+
if (!this.owns(agent)) {
|
|
134
|
+
const registry = agent.ctx.get("agents");
|
|
135
|
+
if (registry && original(registry) === original(this.ctx.agents) && scopeOf(agent.ctx) === agent && registry.get(agent.id) !== agent
|
|
136
|
+
|| this.ctx.agents.list().some(parent => this.owns(parent) && this.ctx.agents.isOwnedBy(agent.id, parent))) {
|
|
137
|
+
throw new SubagentError("Native child admission is incomplete", "UNAUTHORIZED");
|
|
138
|
+
}
|
|
116
139
|
return "native";
|
|
140
|
+
}
|
|
117
141
|
await this.ensure(agent);
|
|
118
142
|
return "dsmm";
|
|
119
143
|
}
|
|
@@ -145,12 +169,15 @@ export class NativeAdmission {
|
|
|
145
169
|
invocation(agent) { return this.live.get(agent)?.invocation; }
|
|
146
170
|
async ensure(agent) { await this.rebindings.get(agent); return this.assert(agent); }
|
|
147
171
|
assert(agent) {
|
|
172
|
+
return this.assertBinding(agent);
|
|
173
|
+
}
|
|
174
|
+
assertBinding(agent, maintenanceRoot) {
|
|
148
175
|
this.lifetime.signal.throwIfAborted();
|
|
149
176
|
this.agentLifetimes.get(agent)?.signal.throwIfAborted();
|
|
150
177
|
const live = this.live.get(agent);
|
|
151
178
|
if (this.failedInstallations.has(agent))
|
|
152
179
|
throw new SubagentError("Session configuration restoration failed; create a new session", "UNAUTHORIZED");
|
|
153
|
-
if (this.selecting.has(agent))
|
|
180
|
+
if (this.selecting.has(agent) && agent !== maintenanceRoot)
|
|
154
181
|
throw new SubagentError("Session configuration maintenance is in progress", "UNAUTHORIZED");
|
|
155
182
|
if (!this.isReady || !live || this.ctx.agents.get(agent.id) !== agent)
|
|
156
183
|
throw new SubagentError("No trusted live admission; create a new session", "UNAUTHORIZED");
|
|
@@ -164,49 +191,112 @@ export class NativeAdmission {
|
|
|
164
191
|
if (live.parent && (this.ctx.agents.get(live.parent.id) !== live.parent || !this.ctx.agents.isOwnedBy(agent.id, live.parent)))
|
|
165
192
|
throw new SubagentError("Parent residency changed", "UNAUTHORIZED");
|
|
166
193
|
if (live.parent)
|
|
167
|
-
this.
|
|
194
|
+
this.assertBinding(live.parent, maintenanceRoot);
|
|
168
195
|
this.policy.assertModuleAdmission(agent);
|
|
169
196
|
return live.admission;
|
|
170
197
|
}
|
|
198
|
+
residentTree(agent) {
|
|
199
|
+
const tree = [agent], residents = this.ctx.agents.list();
|
|
200
|
+
for (let index = 0; index < tree.length; index++) {
|
|
201
|
+
for (const child of residents.filter(child => this.ctx.agents.isOwnedBy(child.id, tree[index])).sort((a, b) => a.id.localeCompare(b.id))) {
|
|
202
|
+
if (tree.includes(child))
|
|
203
|
+
throw new SubagentError("Invalid native ownership tree", "UNAUTHORIZED");
|
|
204
|
+
tree.push(child);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return tree;
|
|
208
|
+
}
|
|
209
|
+
observeProviders() {
|
|
210
|
+
const scopes = new Set([this.ctx, this.ctx.root]);
|
|
211
|
+
for (const plugin of this.ctx.registry.values())
|
|
212
|
+
for (const fiber of plugin.fibers)
|
|
213
|
+
scopes.add(fiber.ctx);
|
|
214
|
+
const registry = original(this.ctx.agents), current = new Map();
|
|
215
|
+
for (const scope of scopes) {
|
|
216
|
+
const agents = scope.get("agents", false), runtime = scope.get("subagents", false);
|
|
217
|
+
if (agents === undefined || original(agents) !== registry || runtime === undefined || current.has(original(runtime)))
|
|
218
|
+
continue;
|
|
219
|
+
current.set(original(runtime), runtime.list().some(name => runtime.getProvider(name)?.prepareContinuable === undefined));
|
|
220
|
+
}
|
|
221
|
+
// Any native service sharing this registry may accept these exact parents,
|
|
222
|
+
// including isolated services the Agent's own context does not resolve.
|
|
223
|
+
// Removal and late start/end cannot prove unpublished external starts ended.
|
|
224
|
+
if ([...this.providerScopes.values(), ...current.values()].some(Boolean)) {
|
|
225
|
+
for (const agent of this.ctx.agents.list())
|
|
226
|
+
this.opaqueAgents.add(agent);
|
|
227
|
+
}
|
|
228
|
+
this.providerScopes.clear();
|
|
229
|
+
for (const [runtime, opaque] of current)
|
|
230
|
+
this.providerScopes.set(runtime, opaque);
|
|
231
|
+
}
|
|
171
232
|
blankReason(agent, allowQueued = false) {
|
|
172
233
|
if (!this.isReady || this.failedInstallations.has(agent) || this.ctx.agents.get(agent.id) !== agent || !this.ctx.agents.roots().includes(agent) || this.dependencies(agent).some(value => value === undefined))
|
|
173
234
|
return "runtime-unavailable";
|
|
174
235
|
const live = this.live.get(agent);
|
|
175
|
-
if (!live || live.parent || agent.session.header.origin === "subagent"
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (agent.status !== "idle" || (this.calls.get(agent) ?? 0) !== 0 || (this.executions.get(agent)?.size ?? 0) !== 0 || [...this.pending.values()].some(row => row.parent === agent)
|
|
179
|
-
|| this.ctx.agents.list().some(child => this.ctx.agents.isOwnedBy(child.id, agent))
|
|
180
|
-
|| this.selecting.has(agent) && !allowQueued
|
|
181
|
-
|| !allowQueued && (agent.inbox.nextTurn.length !== 0 || agent.inbox.nextStep.length !== 0))
|
|
236
|
+
if (!live || live.parent || agent.session.header.origin === "subagent")
|
|
237
|
+
return "runtime-unavailable";
|
|
238
|
+
if (this.selecting.has(agent) && !allowQueued)
|
|
182
239
|
return "busy";
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
240
|
+
try {
|
|
241
|
+
this.observeProviders();
|
|
242
|
+
for (const member of this.residentTree(agent)) {
|
|
243
|
+
this.assertBinding(member, allowQueued ? agent : undefined);
|
|
244
|
+
const runtime = member.ctx.get("subagents");
|
|
245
|
+
if (runtime === undefined || !this.providerScopes.has(original(runtime)) || this.opaqueAgents.has(member))
|
|
246
|
+
return "runtime-unavailable";
|
|
247
|
+
if (this.dependencies(member).some(value => value === undefined))
|
|
248
|
+
return "runtime-unavailable";
|
|
249
|
+
if (member.status !== "idle" || hasOpenTurn(sessionEvents(member.session)) || (this.calls.get(member) ?? 0) !== 0
|
|
250
|
+
|| (this.executions.get(member)?.size ?? 0) !== 0 || [...this.pending.values()].some(row => row.parent === member)
|
|
251
|
+
|| !allowQueued && (member.inbox.nextTurn.length !== 0 || member.inbox.nextStep.length !== 0))
|
|
252
|
+
return "busy";
|
|
253
|
+
if (member.runMaintenance === undefined)
|
|
254
|
+
return "maintenance";
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
187
258
|
return "runtime-unavailable";
|
|
259
|
+
}
|
|
188
260
|
return undefined;
|
|
189
261
|
}
|
|
190
262
|
/** Reserved by runMaintenance; newly queued input belongs to the accepted choice. */
|
|
191
|
-
beginBlank(agent, signal, assertAuthority) {
|
|
263
|
+
async beginBlank(agent, signal, assertAuthority) {
|
|
192
264
|
const reason = this.blankReason(agent);
|
|
193
265
|
if (reason !== undefined)
|
|
194
|
-
throw new DsmmProfileError(reason === "busy" ? "busy" : "unavailable", "
|
|
266
|
+
throw new DsmmProfileError(reason === "busy" ? "busy" : "unavailable", "A trusted quiescent native session subtree is required.");
|
|
195
267
|
const previous = this.live.get(agent);
|
|
196
268
|
this.assert(agent);
|
|
197
269
|
const captured = this.dependencies(agent);
|
|
270
|
+
const tree = this.residentTree(agent), bindings = tree.map(member => this.live.get(member));
|
|
198
271
|
const preparationSignal = AbortSignal.any([signal, this.lifetime.signal, this.agentLifetimes.get(agent).signal]);
|
|
199
272
|
this.selecting.add(agent);
|
|
200
273
|
let finish;
|
|
201
274
|
const completion = new Promise(resolve => { finish = resolve; });
|
|
202
275
|
this.blankUpdates.set(agent, completion);
|
|
276
|
+
const reservations = [], maintenanceSignals = [];
|
|
277
|
+
try {
|
|
278
|
+
for (const child of tree.slice(1)) {
|
|
279
|
+
reservations.push(child.runMaintenance(childSignal => { maintenanceSignals.push(childSignal); return completion; }));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
this.selecting.delete(agent);
|
|
284
|
+
this.blankUpdates.delete(agent);
|
|
285
|
+
finish();
|
|
286
|
+
await Promise.allSettled(reservations);
|
|
287
|
+
throw new DsmmProfileError("maintenance", "A resident descendant refused configuration maintenance.");
|
|
288
|
+
}
|
|
203
289
|
let prepared = false, committed = false;
|
|
204
290
|
let publication;
|
|
205
291
|
let providers = new Map();
|
|
206
292
|
const assertCurrent = () => {
|
|
207
293
|
assertAuthority();
|
|
208
294
|
preparationSignal.throwIfAborted();
|
|
209
|
-
|
|
295
|
+
for (const childSignal of maintenanceSignals)
|
|
296
|
+
childSignal.throwIfAborted();
|
|
297
|
+
const currentTree = this.residentTree(agent);
|
|
298
|
+
if (this.live.get(agent) !== previous || this.blankReason(agent, true) !== undefined || this.dependencies(agent).some((value, index) => value !== captured[index])
|
|
299
|
+
|| currentTree.length !== tree.length || currentTree.some((member, index) => member !== tree[index] || this.live.get(member) !== bindings[index])) {
|
|
210
300
|
throw new DsmmProfileError("conflict", "The session owner or composition changed before configuration commit.");
|
|
211
301
|
}
|
|
212
302
|
for (const [name, expected] of providers) {
|
|
@@ -250,7 +340,7 @@ export class NativeAdmission {
|
|
|
250
340
|
this.installing.run({ agent, admission }, describe);
|
|
251
341
|
publication = Object.freeze({ ...previous, admission });
|
|
252
342
|
},
|
|
253
|
-
committed: () => { this.live.set(agent, publication); committed = true; },
|
|
343
|
+
committed: () => { this.live.set(agent, publication); committed = true; this.configurationCommitted(tree); },
|
|
254
344
|
close: async () => {
|
|
255
345
|
try {
|
|
256
346
|
if (prepared && !committed && this.ctx.agents.get(agent.id) === agent && !this.lifetime.signal.aborted)
|
|
@@ -266,10 +356,18 @@ export class NativeAdmission {
|
|
|
266
356
|
this.selecting.delete(agent);
|
|
267
357
|
this.blankUpdates.delete(agent);
|
|
268
358
|
finish();
|
|
359
|
+
await Promise.allSettled(reservations);
|
|
269
360
|
}
|
|
270
361
|
},
|
|
271
362
|
};
|
|
272
363
|
}
|
|
364
|
+
trackExecution(exec) {
|
|
365
|
+
if (!exec.agent || !this.owns(exec.agent))
|
|
366
|
+
return;
|
|
367
|
+
const active = this.executions.get(exec.agent) ?? new Set();
|
|
368
|
+
active.add(exec.token);
|
|
369
|
+
this.executions.set(exec.agent, active);
|
|
370
|
+
}
|
|
273
371
|
async reserve(exec, invocation, provider, maxDepth) {
|
|
274
372
|
const parent = exec.agent;
|
|
275
373
|
if (!parent)
|
|
@@ -416,6 +514,7 @@ export class NativeAdmission {
|
|
|
416
514
|
throw new SubagentError("Role creation requires its first pending call", "UNAUTHORIZED");
|
|
417
515
|
if (!this.isReady || !this.install)
|
|
418
516
|
throw new SubagentError("DSMM admission is initializing", "UNAUTHORIZED");
|
|
517
|
+
this.observeProviders();
|
|
419
518
|
let signal = AbortSignal.any([...creationSignal ? [creationSignal] : [], this.lifetime.signal]);
|
|
420
519
|
signal.throwIfAborted();
|
|
421
520
|
const parents = this.ctx.agents.list().filter(parent => parent !== agent && this.ctx.agents.isOwnedBy(agent.id, parent));
|
|
@@ -535,12 +634,6 @@ export class NativeAdmission {
|
|
|
535
634
|
await this.ensure(agent); return next(); }, { prepend: true });
|
|
536
635
|
agent.ctx.on("agent/request", async (frame, next) => { if (frame.agent === agent)
|
|
537
636
|
await this.ensure(agent); return next(); }, { prepend: true });
|
|
538
|
-
agent.ctx.on("tools/pre-execute", async (exec, next) => { if (exec.agent === agent) {
|
|
539
|
-
await this.ensure(agent);
|
|
540
|
-
const denial = this.policy.preToolDenial(agent, exec.name, undefined, exec);
|
|
541
|
-
if (denial)
|
|
542
|
-
return { kind: "deny", reason: denial };
|
|
543
|
-
} return next(); }, { prepend: true });
|
|
544
637
|
this.guardTools(agent);
|
|
545
638
|
try {
|
|
546
639
|
if (pending)
|
|
@@ -557,6 +650,14 @@ export class NativeAdmission {
|
|
|
557
650
|
this.check(pending);
|
|
558
651
|
if (continuationProvider && this.ctx.get("subagents").getProvider(continuationProvider.name) !== continuationProvider)
|
|
559
652
|
throw new SubagentError("Role provider changed", "UNAUTHORIZED");
|
|
653
|
+
// Occupancy precedes the installed guards' async policy and approval work.
|
|
654
|
+
agent.ctx.on("tools/pre-execute", async (exec, next) => { if (exec.agent === agent) {
|
|
655
|
+
this.trackExecution(exec);
|
|
656
|
+
await this.ensure(agent);
|
|
657
|
+
const denial = this.policy.preToolDenial(agent, exec.name, undefined, exec);
|
|
658
|
+
if (denial)
|
|
659
|
+
return { kind: "deny", reason: denial };
|
|
660
|
+
} return next(); }, { prepend: true });
|
|
560
661
|
this.profiles.publish(agent, admission);
|
|
561
662
|
const published = this.profiles.admission(agent);
|
|
562
663
|
this.live.set(agent, Object.freeze({ admission: published, preset, scopeParent: scopeParentOf(agent), parent, invocation: pending?.invocation ?? continuation, dependencies, provider: pending?.provider ?? continuationProvider }));
|
package/lib/profile-runtime.js
CHANGED
|
@@ -257,8 +257,6 @@ export class DsmmProfileRuntime {
|
|
|
257
257
|
}
|
|
258
258
|
async selectSession(request, agent, signal, authority) {
|
|
259
259
|
this.assertRoot(agent);
|
|
260
|
-
if (this.historyAdmissions.has(this.admission(agent)))
|
|
261
|
-
throw new DsmmProfileError("unavailable", "A continued historical Agent is not a blank configuration target.");
|
|
262
260
|
if (request.sessionId !== agent.id)
|
|
263
261
|
throw new DsmmProfileError("not-owned", "The native session does not match the captured Agent.");
|
|
264
262
|
const previous = this.admission(agent);
|
|
@@ -274,13 +272,13 @@ export class DsmmProfileRuntime {
|
|
|
274
272
|
};
|
|
275
273
|
check();
|
|
276
274
|
if (owner?.beginBlank === undefined || agent.runMaintenance === undefined)
|
|
277
|
-
throw new DsmmProfileError("unavailable", "Native
|
|
275
|
+
throw new DsmmProfileError("unavailable", "Native session configuration maintenance is unavailable.");
|
|
278
276
|
if (agent.status === "running")
|
|
279
277
|
throw new DsmmProfileError("busy", "Wait for the session to become idle.");
|
|
280
278
|
try {
|
|
281
279
|
return await agent.runMaintenance(async (maintenanceSignal) => {
|
|
282
280
|
check(maintenanceSignal);
|
|
283
|
-
const transaction = owner.beginBlank(agent, signal === undefined ? maintenanceSignal : AbortSignal.any([maintenanceSignal, signal]), () => check(maintenanceSignal));
|
|
281
|
+
const transaction = await owner.beginBlank(agent, signal === undefined ? maintenanceSignal : AbortSignal.any([maintenanceSignal, signal]), () => check(maintenanceSignal));
|
|
284
282
|
const assertCurrent = () => transaction.assertCurrent();
|
|
285
283
|
let next, response;
|
|
286
284
|
try {
|
|
@@ -478,7 +476,7 @@ export class DsmmProfileRuntime {
|
|
|
478
476
|
const toggleModeUnavailableReason = agent.status === "running" || hasOpenTurn(sessionEvents(agent.session)) ? "busy"
|
|
479
477
|
: agent.runMaintenance === undefined ? "maintenance" : !mode.active && (!this.baseline.modules.deepwork.enabled || !admission.settings.modules.deepwork.enabled) ? "module-off"
|
|
480
478
|
: mode.locked || !mode.active && !ready ? "runtime-unavailable" : undefined;
|
|
481
|
-
const applyOverlayUnavailableReason = this.
|
|
479
|
+
const applyOverlayUnavailableReason = this.store.readOnly ? "runtime-unavailable" : owner?.blankReason?.(agent, inMaintenance) ?? (owner?.blankReason === undefined ? "runtime-unavailable" : undefined);
|
|
482
480
|
return { canSelectModel: selectModelUnavailableReason === undefined, ...(selectModelUnavailableReason === undefined ? {} : { selectModelUnavailableReason }),
|
|
483
481
|
canToggleMode: toggleModeUnavailableReason === undefined, ...(toggleModeUnavailableReason === undefined ? {} : { toggleModeUnavailableReason }),
|
|
484
482
|
canApplyOverlay: applyOverlayUnavailableReason === undefined, ...(applyOverlayUnavailableReason === undefined ? {} : { applyOverlayUnavailableReason }) };
|