@dsmm/dsmm 0.3.26 → 0.3.28
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 +21 -8
- package/docs/agent-presets.md +7 -7
- package/docs/agent-teams.md +27 -0
- package/docs/compatibility.md +7 -7
- package/docs/lsp.md +10 -12
- package/docs/maintenance.md +29 -0
- package/docs/roadmap.md +25 -9
- package/docs/runtime-recovery.md +3 -3
- package/docs/testing.md +3 -1
- package/dsh-plugin.json +1 -1
- package/lib/client/NativeToolView-data.d.ts +8 -0
- package/lib/client/NativeToolView-data.js +19 -0
- package/lib/client/NativeToolView.d.ts +19 -0
- package/lib/client/NativeToolView.js +46 -0
- package/lib/client/RoleToolView-data.js +1 -1
- package/lib/client/RoleToolView-locales.d.ts +7 -0
- package/lib/client/RoleToolView-locales.js +6 -0
- package/lib/client/RoleToolView.js +2 -0
- package/lib/client/SessionProfiles.js +1 -1
- package/lib/client/children-locales.d.ts +4 -4
- package/lib/client/controller.js +20 -0
- package/lib/client/locales.d.ts +1 -0
- package/lib/client/locales.js +2 -0
- package/lib/client.js +350 -187
- package/lib/core-permission-authority.js +14 -4
- package/lib/mode.js +2 -2
- package/lib/native-admission.d.ts +5 -3
- package/lib/native-admission.js +218 -77
- package/lib/native-ownership.d.ts +3 -0
- package/lib/native-ownership.js +19 -0
- package/lib/native-subagents.d.ts +2 -1
- package/lib/native-subagents.js +4 -3
- package/lib/profile-runtime.d.ts +1 -1
- package/lib/prompts.d.ts +2 -0
- package/lib/prompts.js +14 -8
- package/lib/role-control-remote.js +19 -8
- package/lib/role-control-rpc.js +1 -1
- package/lib/role-control-types.d.ts +18 -5
- package/lib/role-identity.js +3 -19
- package/lib/role-invocation.d.ts +1 -1
- package/lib/role-policy.d.ts +11 -3
- package/lib/role-policy.js +61 -21
- package/lib/role-subagents.js +12 -5
- package/lib/session-metadata.d.ts +27 -1
- package/lib/session-metadata.js +46 -0
- package/lib/session-scope.d.ts +1 -1
- package/lib/session-scope.js +2 -2
- package/package.json +3 -1
- package/prompts/source/deepwork/general.md +19 -0
- package/prompts/source/shared/native-teams.md +11 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { nativeRoots, nativeIsOwnedBy } from "./native-ownership.js";
|
|
1
|
+
import { nativeRoots, nativeIsOwnedBy, nativeTreeRoot } from "./native-ownership.js";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { scopeLifetime } from "./lifetime.js";
|
|
4
4
|
import { PermissionRefusal, permissionOriginal } from "./permission-control.js";
|
|
@@ -24,13 +24,23 @@ export function createCorePermissionAuthority(ctx, options) {
|
|
|
24
24
|
throw new PermissionRefusal("cancelled");
|
|
25
25
|
return ctx.get("dsmmNativeAdmission");
|
|
26
26
|
};
|
|
27
|
-
/**
|
|
27
|
+
/** Tree admission has a live root owner; older registries retain direct-edge ancestry. */
|
|
28
28
|
const ancestry = (exec) => {
|
|
29
29
|
const agents = ctx.get("agents"), agent = exec.agent;
|
|
30
30
|
const realmAgents = agent?.ctx.get("agents");
|
|
31
31
|
if (agents === undefined || agent === undefined || agents.get(agent.id) !== agent
|
|
32
32
|
|| realmAgents === undefined || permissionOriginal(realmAgents) !== permissionOriginal(agents))
|
|
33
33
|
throw new PermissionRefusal("not-owned");
|
|
34
|
+
const root = nativeTreeRoot(agents, agent);
|
|
35
|
+
if (root !== undefined) {
|
|
36
|
+
const host = integration();
|
|
37
|
+
if (host?.owns(agent)) {
|
|
38
|
+
host.assert(agent);
|
|
39
|
+
if (agent !== root && rolePolicy.identity(agent).owner !== root)
|
|
40
|
+
throw new PermissionRefusal("not-owned");
|
|
41
|
+
}
|
|
42
|
+
return agent === root ? [root] : [agent, root];
|
|
43
|
+
}
|
|
34
44
|
const chain = [], seen = new Set(), residents = agents.list();
|
|
35
45
|
let current = agent;
|
|
36
46
|
while (true) {
|
|
@@ -84,7 +94,7 @@ export function createCorePermissionAuthority(ctx, options) {
|
|
|
84
94
|
const identity = native ? undefined : rolePolicy.identity(structural);
|
|
85
95
|
const tools = agent.ctx.get("tools"), approval = agent.ctx.get("approval");
|
|
86
96
|
if (tools === undefined || !native && (identity?.epoch !== admission.epoch
|
|
87
|
-
|| (parent === undefined ? agent !== root || identity.child : identity.parent !== parent.authority.agent || !identity.child)))
|
|
97
|
+
|| (parent === undefined ? agent !== root || identity.child : (identity.owner ?? identity.parent) !== parent.authority.agent || !identity.child)))
|
|
88
98
|
throw new PermissionRefusal("not-owned");
|
|
89
99
|
const nativePolicy = approval === undefined ? undefined : approval.overrideOf(agent.session) ?? approval.config.policy;
|
|
90
100
|
if (approval !== undefined && nativePolicy !== "ask" && nativePolicy !== "never")
|
|
@@ -97,7 +107,7 @@ export function createCorePermissionAuthority(ctx, options) {
|
|
|
97
107
|
const facts = [root, agent.ctx, parent?.authority.signal, permissionOriginal(ctx.get("dsmmCoreLlmOwner")),
|
|
98
108
|
permissionOriginal(ctx.get("dsmmProfileRuntime")), permissionOriginal(tools),
|
|
99
109
|
approval === undefined ? undefined : permissionOriginal(approval),
|
|
100
|
-
admission?.settings, native, captured, identity?.role, identity?.child, identity?.parent, identity?.epoch, identity?.readOnly,
|
|
110
|
+
admission?.settings, native, captured, identity?.role, identity?.child, identity?.owner ?? identity?.parent, identity?.creatorId, identity?.epoch, identity?.readOnly,
|
|
101
111
|
JSON.stringify(identity?.toolFilter)];
|
|
102
112
|
if (previous !== undefined && !previous.authority.signal.aborted && previous.integration === entry
|
|
103
113
|
&& previous.authority.owner === owner && previous.admission === admission && sameFacts(previous.facts, facts)) {
|
package/lib/mode.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getTraceable } from "@deepseek-ai/cordis";
|
|
2
2
|
import { agentForScope, nativeAgentContext } from "./native-scope.js";
|
|
3
3
|
import { buildDeepworkPrompt } from "./prompts.js";
|
|
4
|
-
import {
|
|
4
|
+
import { resolveAdmittedDsmmRole } from "./role-policy.js";
|
|
5
5
|
const bindings = new WeakMap();
|
|
6
6
|
function routeFromAgent(agent) {
|
|
7
7
|
const header = agent.session.requestHeader?.();
|
|
@@ -31,7 +31,7 @@ export function registerDeepworkPrompt(readyCtx, controller, getSettings, config
|
|
|
31
31
|
const settings = getSettings(agent);
|
|
32
32
|
if (!settings.modules.deepwork.enabled || !controller.active(agent, settings.defaultActive))
|
|
33
33
|
return "";
|
|
34
|
-
return buildDeepworkPrompt(settings, { route: routeFromAgent(agent),
|
|
34
|
+
return buildDeepworkPrompt(settings, { route: routeFromAgent(agent), roleId: resolveAdmittedDsmmRole(agent, settings, true) ?? null, overrideSection: config.section });
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
};
|
|
@@ -48,10 +48,10 @@ export declare class NativeAdmission {
|
|
|
48
48
|
private readonly ambiguousCallIds;
|
|
49
49
|
private readonly observedCallTokens;
|
|
50
50
|
private readonly observedCallChildren;
|
|
51
|
+
private readonly nativeToolObservations;
|
|
52
|
+
private readonly nativeToolExecution;
|
|
51
53
|
private readonly observedCallRuns;
|
|
52
54
|
private readonly callSubscribers;
|
|
53
|
-
private readonly providerScopes;
|
|
54
|
-
private readonly opaqueAgents;
|
|
55
55
|
private readonly admissionRoutes;
|
|
56
56
|
private readonly admissionRouteFailures;
|
|
57
57
|
private readonly setupSelectionCursors;
|
|
@@ -76,6 +76,9 @@ export declare class NativeAdmission {
|
|
|
76
76
|
private settleObservedActivation;
|
|
77
77
|
private bindObservedChild;
|
|
78
78
|
private observeCallRequestHeader;
|
|
79
|
+
private setObservedRoute;
|
|
80
|
+
private beginNativeToolObservation;
|
|
81
|
+
private finishNativeToolObservation;
|
|
79
82
|
private finishObservedTool;
|
|
80
83
|
private retireObservedParent;
|
|
81
84
|
observeRoleCalls(parent: Agent, admission: DsmmProfileAdmission, signal: AbortSignal, check: () => void): AsyncIterable<RoleCallObservationFrame>;
|
|
@@ -96,7 +99,6 @@ export declare class NativeAdmission {
|
|
|
96
99
|
assert(agent: Agent): DsmmProfileAdmission;
|
|
97
100
|
private assertBinding;
|
|
98
101
|
private residentTree;
|
|
99
|
-
private observeProviders;
|
|
100
102
|
blankReason(agent: Agent, allowQueued?: boolean): SessionActionUnavailableReason | undefined;
|
|
101
103
|
/** Reserved by runMaintenance; newly queued input belongs to the accepted choice. */
|
|
102
104
|
beginBlank(agent: Agent, signal: AbortSignal, assertAuthority: () => void): Promise<{
|
package/lib/native-admission.js
CHANGED
|
@@ -9,7 +9,8 @@ import { invocationView } from "./role-invocation.js";
|
|
|
9
9
|
import { scopeLifetime } from "./lifetime.js";
|
|
10
10
|
import { sessionEvents, childOwnedSessionEvents } from "./session-scope.js";
|
|
11
11
|
import { scopeParentOf, scopeOf } from "./native-scope.js";
|
|
12
|
-
import { bindNativeParent, nativeIsOwnedBy, nativeRoots } from "./native-ownership.js";
|
|
12
|
+
import { bindNativeParent, nativeIsOwnedBy, nativeRoots, nativeTreeRoot } from "./native-ownership.js";
|
|
13
|
+
import { appendDelegationCeiling, readDelegationCeiling } from "./session-metadata.js";
|
|
13
14
|
import { listNativeChildren } from "./native-subagents.js";
|
|
14
15
|
import { DsmmProfileError } from "./profiles.js";
|
|
15
16
|
import { roleProviderName } from "./roles.js";
|
|
@@ -89,10 +90,10 @@ export class NativeAdmission {
|
|
|
89
90
|
ambiguousCallIds = new WeakMap();
|
|
90
91
|
observedCallTokens = new Map();
|
|
91
92
|
observedCallChildren = new Map();
|
|
93
|
+
nativeToolObservations = new Map();
|
|
94
|
+
nativeToolExecution = new AsyncLocalStorage();
|
|
92
95
|
observedCallRuns = new Map();
|
|
93
96
|
callSubscribers = new Set();
|
|
94
|
-
providerScopes = new Map();
|
|
95
|
-
opaqueAgents = new WeakSet();
|
|
96
97
|
admissionRoutes = new WeakMap();
|
|
97
98
|
admissionRouteFailures = new WeakMap();
|
|
98
99
|
setupSelectionCursors = new WeakMap();
|
|
@@ -112,6 +113,7 @@ export class NativeAdmission {
|
|
|
112
113
|
this.observedCallTokens.clear();
|
|
113
114
|
this.observedCallChildren.clear();
|
|
114
115
|
this.observedCallRuns.clear();
|
|
116
|
+
this.nativeToolObservations.clear();
|
|
115
117
|
for (const agent of this.agents)
|
|
116
118
|
agent.cancel({ kind: "disposed" });
|
|
117
119
|
});
|
|
@@ -122,21 +124,6 @@ export class NativeAdmission {
|
|
|
122
124
|
if (errors.length)
|
|
123
125
|
throw new AggregateError(errors, "Native activation teardown failed");
|
|
124
126
|
});
|
|
125
|
-
const observeProviders = () => { if (!this.lifetime.signal.aborted)
|
|
126
|
-
this.observeProviders(); };
|
|
127
|
-
ctx.on("subagent/provider-added", observeProviders, { global: true });
|
|
128
|
-
ctx.on("subagent/provider-removed", observeProviders, { global: true });
|
|
129
|
-
ctx.on("internal/plugin", observeProviders, { global: true });
|
|
130
|
-
ctx.on("internal/status", observeProviders, { global: true });
|
|
131
|
-
ctx.on("internal/service", name => {
|
|
132
|
-
// A Service registers in super(), before subclass fields are initialized.
|
|
133
|
-
if (name === "subagents" || name === "agents")
|
|
134
|
-
queueMicrotask(observeProviders);
|
|
135
|
-
}, { global: true });
|
|
136
|
-
// Existing Agents may have unpublished starts from before this observer.
|
|
137
|
-
for (const agent of ctx.agents.list())
|
|
138
|
-
this.opaqueAgents.add(agent);
|
|
139
|
-
observeProviders();
|
|
140
127
|
ctx.on("subagent/start", info => { this.admitPublishedChild(info); this.startObservedActivation(info); }, { global: true });
|
|
141
128
|
ctx.on("subagent/end", info => { this.endObservedActivation(info); }, { global: true });
|
|
142
129
|
ctx.on("session/created", session => {
|
|
@@ -192,15 +179,14 @@ export class NativeAdmission {
|
|
|
192
179
|
ctx.on("agent/pre-step", async (frame, next) => { await this.guardExecution(frame.agent); return next(); }, { global: true, prepend: true });
|
|
193
180
|
ctx.on("agent/request", async (frame, next) => { await this.guardExecution(frame.agent); return next(); }, { global: true, prepend: true });
|
|
194
181
|
ctx.on("tools/execute", async (exec, next) => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return policy.duringToolExecution(exec, next);
|
|
182
|
+
const native = exec.agent && await this.guardExecution(exec.agent) === "native";
|
|
183
|
+
return this.nativeToolExecution.run(exec.token, () => native ? next() : policy.duringToolExecution(exec, next));
|
|
198
184
|
}, { global: true, prepend: true });
|
|
199
185
|
ctx.on("tools/pre-execute", async (exec, next) => {
|
|
200
186
|
if (exec.agent) {
|
|
201
187
|
this.trackExecution(exec);
|
|
202
|
-
|
|
203
|
-
|
|
188
|
+
await this.guardExecution(exec.agent);
|
|
189
|
+
this.beginNativeToolObservation(exec);
|
|
204
190
|
}
|
|
205
191
|
return next();
|
|
206
192
|
}, { global: true, prepend: true });
|
|
@@ -248,14 +234,18 @@ export class NativeAdmission {
|
|
|
248
234
|
...(route.reasoningEffort === undefined ? {} : { reasoningEffort: route.reasoningEffort }) });
|
|
249
235
|
}
|
|
250
236
|
observedCall(record) {
|
|
251
|
-
|
|
237
|
+
const common = { parentSessionId: record.parent.id, parentAdmissionEpoch: record.parentAdmission.epoch,
|
|
252
238
|
...(record.childAdmission === undefined ? {} : { childAdmissionEpoch: record.childAdmission.epoch }),
|
|
253
239
|
callId: record.callId, rootCallId: record.rootCallId, childId: record.childId,
|
|
254
|
-
...(record.runId === undefined ? {} : { runId: record.runId }),
|
|
255
|
-
level: record.invocation.effectiveLevel, routeSource: record.invocation.routeSource,
|
|
256
|
-
initialRoute: Object.freeze({ status: "known", source: "invocation-capture", route: this.observationRoute(record.invocation.initialRoute) }),
|
|
240
|
+
...(record.runId === undefined ? {} : { runId: record.runId }),
|
|
257
241
|
actualRoute: record.actualRoute, phase: record.phase, delivery: record.delivery,
|
|
258
|
-
...(record.stopReason === undefined ? {} : { stopReason: record.stopReason }) }
|
|
242
|
+
...(record.stopReason === undefined ? {} : { stopReason: record.stopReason }) };
|
|
243
|
+
return record.kind === "native"
|
|
244
|
+
? Object.freeze({ ...common, kind: "native", toolName: record.toolName, provider: record.provider,
|
|
245
|
+
...(record.nativeName === undefined ? {} : { nativeName: record.nativeName }),
|
|
246
|
+
initialRoute: Object.freeze({ status: "unknown", reason: "missing-invocation-capture" }) })
|
|
247
|
+
: Object.freeze({ ...common, role: record.role, level: record.invocation.effectiveLevel, routeSource: record.invocation.routeSource,
|
|
248
|
+
initialRoute: Object.freeze({ status: "known", source: "invocation-capture", route: this.observationRoute(record.invocation.initialRoute) }) });
|
|
259
249
|
}
|
|
260
250
|
publishObservedCall(record) {
|
|
261
251
|
if (this.observedCalls.get(record.parent)?.get(record.callId) !== record || this.ambiguousCallIds.get(record.parent)?.has(record.callId))
|
|
@@ -314,12 +304,17 @@ export class NativeAdmission {
|
|
|
314
304
|
this.lifetime.signal.throwIfAborted();
|
|
315
305
|
waiting.signal?.throwIfAborted();
|
|
316
306
|
const parent = info.parentSessionId === undefined ? undefined : this.ctx.agents.get(info.parentSessionId);
|
|
317
|
-
if (parent === undefined)
|
|
318
|
-
throw new SubagentError("Child requires its exact live creator", "UNAUTHORIZED");
|
|
319
307
|
const pending = this.pending.get(child.id);
|
|
320
308
|
if (pending && (pending.parent !== parent || pending.provider.name !== info.provider))
|
|
321
309
|
throw new SubagentError("Published child differs from its pending invocation", "UNAUTHORIZED");
|
|
322
|
-
|
|
310
|
+
if (parent !== undefined)
|
|
311
|
+
bindNativeParent(this.ctx.agents, child, parent);
|
|
312
|
+
else {
|
|
313
|
+
const ceiling = readDelegationCeiling(child.session);
|
|
314
|
+
if (waiting.source !== "resume" || ceiling === undefined || ceiling.creatorId !== info.parentSessionId
|
|
315
|
+
|| ceiling.provider !== info.provider)
|
|
316
|
+
throw new SubagentError("Child requires its verified creator evidence", "UNAUTHORIZED");
|
|
317
|
+
}
|
|
323
318
|
await this.created(child, waiting.source, waiting.signal);
|
|
324
319
|
};
|
|
325
320
|
void admission().then(waiting.resolve, error => {
|
|
@@ -329,6 +324,15 @@ export class NativeAdmission {
|
|
|
329
324
|
});
|
|
330
325
|
}
|
|
331
326
|
startObservedActivation(info) {
|
|
327
|
+
const child = this.ctx.agents.get(info.id), token = this.nativeToolExecution.getStore();
|
|
328
|
+
const pending = token === undefined ? undefined : this.nativeToolObservations.get(token);
|
|
329
|
+
const parentId = info.parentSessionId;
|
|
330
|
+
if (info.local && child !== undefined && pending !== undefined && pending.admission === this.get(pending.parent)
|
|
331
|
+
&& (parentId === undefined || parentId === pending.parent.id)
|
|
332
|
+
&& child.session.header.origin === "subagent" && child.session.header.parentSession === pending.parent.id
|
|
333
|
+
&& nativeIsOwnedBy(this.ctx.agents, child.id, pending.parent) && !pending.activations.has(info.id)) {
|
|
334
|
+
pending.activations.set(info.id, { info, child, childAdmission: this.get(child) });
|
|
335
|
+
}
|
|
332
336
|
const record = this.observedCallChildren.get(info.id);
|
|
333
337
|
if (record === undefined || info.provider !== record.provider || !info.local || record.phase === "settled")
|
|
334
338
|
return;
|
|
@@ -340,8 +344,16 @@ export class NativeAdmission {
|
|
|
340
344
|
this.publishObservedCall(record);
|
|
341
345
|
}
|
|
342
346
|
endObservedActivation(info) {
|
|
347
|
+
const parentId = info.parentSessionId;
|
|
348
|
+
for (const pending of this.nativeToolObservations.values()) {
|
|
349
|
+
const evidence = pending.activations.get(info.id);
|
|
350
|
+
if (evidence?.info.runId === info.runId && evidence.info.provider === info.provider && info.local
|
|
351
|
+
&& (parentId === undefined || parentId === pending.parent.id))
|
|
352
|
+
evidence.end = info;
|
|
353
|
+
}
|
|
343
354
|
const record = this.observedCallRuns.get(info.runId);
|
|
344
|
-
if (record === undefined || record.childId !== info.id || record.provider !== info.provider || !info.local
|
|
355
|
+
if (record === undefined || record.childId !== info.id || record.provider !== info.provider || !info.local
|
|
356
|
+
|| parentId !== undefined && parentId !== record.parent.id)
|
|
345
357
|
return;
|
|
346
358
|
this.settleObservedActivation(record, info.stopReason);
|
|
347
359
|
}
|
|
@@ -369,9 +381,19 @@ export class NativeAdmission {
|
|
|
369
381
|
}
|
|
370
382
|
observeCallRequestHeader(session, value) {
|
|
371
383
|
const record = this.observedCallChildren.get(session.id), child = this.ctx.agents.get(session.id);
|
|
384
|
+
for (const pending of this.nativeToolObservations.values()) {
|
|
385
|
+
const evidence = pending.activations.get(session.id);
|
|
386
|
+
if (evidence !== undefined && evidence.end === undefined && evidence.child === child && child.session === session
|
|
387
|
+
&& pending.admission === this.get(pending.parent))
|
|
388
|
+
evidence.header = { config: value };
|
|
389
|
+
}
|
|
372
390
|
if (record === undefined || child === undefined || child !== record.child || child.session !== session
|
|
373
391
|
|| record.parentAdmission !== this.get(record.parent) || record.childAdmission !== this.get(child) || record.phase === "settled")
|
|
374
392
|
return;
|
|
393
|
+
this.setObservedRoute(record, value);
|
|
394
|
+
this.publishObservedCall(record);
|
|
395
|
+
}
|
|
396
|
+
setObservedRoute(record, value) {
|
|
375
397
|
const config = typeof value === "object" && value !== null ? value : undefined;
|
|
376
398
|
if (typeof config?.provider !== "string" || typeof config.model !== "string"
|
|
377
399
|
|| config.reasoningEffort !== undefined && typeof config.reasoningEffort !== "string") {
|
|
@@ -387,9 +409,84 @@ export class NativeAdmission {
|
|
|
387
409
|
record.actualRoute = Object.freeze({ status: "unknown", reason: "invalid-own-request-header" });
|
|
388
410
|
}
|
|
389
411
|
}
|
|
390
|
-
|
|
412
|
+
}
|
|
413
|
+
beginNativeToolObservation(exec) {
|
|
414
|
+
const parent = exec.agent, admission = parent && this.get(parent);
|
|
415
|
+
if (parent === undefined || admission === undefined)
|
|
416
|
+
return;
|
|
417
|
+
const tools = this.ctx.get("agentPresets")?.serviceFor(parent, "tools") ?? parent.ctx.tools;
|
|
418
|
+
const definition = tools.get(exec.name, parent), schema = definition?.output.schema;
|
|
419
|
+
const identity = schema?.properties?.name !== undefined ? "name" : "subagentId";
|
|
420
|
+
if (definition === undefined || schema?.type !== "object" || schema.additionalProperties !== false
|
|
421
|
+
|| schema.properties?.kind?.const !== "activation" || schema.properties[identity]?.type !== "string"
|
|
422
|
+
|| !schema.required?.includes("kind") || !schema.required.includes(identity)
|
|
423
|
+
|| Object.keys(schema.properties).length !== 2)
|
|
424
|
+
return;
|
|
425
|
+
this.nativeToolObservations.set(exec.token, { parent, admission, definition, execute: definition.execute, activations: new Map() });
|
|
426
|
+
}
|
|
427
|
+
async finishNativeToolObservation(exec, result, pending) {
|
|
428
|
+
try {
|
|
429
|
+
if (pending.activations.size === 0 || result.isError || typeof result.value !== "object" || result.value === null || Array.isArray(result.value)
|
|
430
|
+
|| result.value.kind !== "activation")
|
|
431
|
+
return;
|
|
432
|
+
const nativeName = typeof result.value.name === "string" && result.value.name.length > 0 ? result.value.name : undefined;
|
|
433
|
+
const runtime = this.ctx.get("subagents");
|
|
434
|
+
const childId = nativeName === undefined
|
|
435
|
+
? typeof result.value.subagentId === "string" && result.value.subagentId.length > 0 ? SessionId(result.value.subagentId) : undefined
|
|
436
|
+
: await runtime?.resolveName?.(pending.parent, nativeName, this.lifetime.signal);
|
|
437
|
+
const tools = this.ctx.get("agentPresets")?.serviceFor(pending.parent, "tools") ?? pending.parent.ctx.tools;
|
|
438
|
+
const evidence = childId === undefined ? undefined : pending.activations.get(childId);
|
|
439
|
+
if (this.nativeToolObservations.get(exec.token) !== pending || this.lifetime.signal.aborted
|
|
440
|
+
|| this.get(pending.parent) !== pending.admission || this.ctx.agents.get(pending.parent.id) !== pending.parent
|
|
441
|
+
|| exec.agent !== pending.parent || tools.get(exec.name, pending.parent) !== pending.definition
|
|
442
|
+
|| pending.definition.execute !== pending.execute || evidence === undefined || childId === undefined)
|
|
443
|
+
return;
|
|
444
|
+
if (evidence.end === undefined && (this.ctx.agents.get(childId) !== evidence.child
|
|
445
|
+
|| !nativeIsOwnedBy(this.ctx.agents, childId, pending.parent)))
|
|
446
|
+
return;
|
|
447
|
+
const record = { kind: "native", parent: pending.parent, parentAdmission: pending.admission,
|
|
448
|
+
token: exec.token, callId: String(exec.callId), rootCallId: String(exec.rootCallId), childId,
|
|
449
|
+
toolName: exec.name, provider: evidence.info.provider, ...(nativeName === undefined ? {} : { nativeName }),
|
|
450
|
+
child: evidence.child, childAdmission: this.get(evidence.child) ?? evidence.childAdmission,
|
|
451
|
+
runId: evidence.info.runId, phase: "active", delivery: "parent", actualRoute: { status: "unknown", reason: "no-own-request-header" } };
|
|
452
|
+
if (evidence.header !== undefined)
|
|
453
|
+
this.setObservedRoute(record, evidence.header.config);
|
|
454
|
+
const calls = this.callsFor(pending.parent);
|
|
455
|
+
let ambiguous = this.ambiguousCallIds.get(pending.parent);
|
|
456
|
+
if (ambiguous === undefined) {
|
|
457
|
+
ambiguous = new Set();
|
|
458
|
+
this.ambiguousCallIds.set(pending.parent, ambiguous);
|
|
459
|
+
}
|
|
460
|
+
const duplicate = calls.has(record.callId) || ambiguous.has(record.callId);
|
|
461
|
+
this.recordsFor(pending.parent).add(record);
|
|
462
|
+
if (duplicate) {
|
|
463
|
+
ambiguous.add(record.callId);
|
|
464
|
+
calls.delete(record.callId);
|
|
465
|
+
this.publishObservedRemoval(pending.parent, pending.admission, record.callId);
|
|
466
|
+
}
|
|
467
|
+
else
|
|
468
|
+
calls.set(record.callId, record);
|
|
469
|
+
if (evidence.end !== undefined)
|
|
470
|
+
this.settleObservedActivation(record, evidence.end.stopReason);
|
|
471
|
+
else {
|
|
472
|
+
this.observedCallChildren.set(childId, record);
|
|
473
|
+
this.observedCallRuns.set(evidence.info.runId, record);
|
|
474
|
+
this.publishObservedCall(record);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
catch (error) {
|
|
478
|
+
if (!this.lifetime.signal.aborted)
|
|
479
|
+
this.ctx.logger.debug("Native call observation unavailable: %s", error instanceof Error ? error.message : String(error));
|
|
480
|
+
}
|
|
481
|
+
finally {
|
|
482
|
+
if (this.nativeToolObservations.get(exec.token) === pending)
|
|
483
|
+
this.nativeToolObservations.delete(exec.token);
|
|
484
|
+
}
|
|
391
485
|
}
|
|
392
486
|
finishObservedTool(exec, result) {
|
|
487
|
+
const native = this.nativeToolObservations.get(exec.token);
|
|
488
|
+
if (native !== undefined)
|
|
489
|
+
void this.finishNativeToolObservation(exec, result, native);
|
|
393
490
|
const record = this.observedCallTokens.get(exec.token);
|
|
394
491
|
if (record === undefined)
|
|
395
492
|
return;
|
|
@@ -400,6 +497,9 @@ export class NativeAdmission {
|
|
|
400
497
|
}
|
|
401
498
|
}
|
|
402
499
|
retireObservedParent(parent) {
|
|
500
|
+
for (const [token, pending] of this.nativeToolObservations)
|
|
501
|
+
if (pending.parent === parent)
|
|
502
|
+
this.nativeToolObservations.delete(token);
|
|
403
503
|
for (const record of this.observedCallRecords.get(parent) ?? []) {
|
|
404
504
|
this.observedCallTokens.delete(record.token);
|
|
405
505
|
if (this.observedCallChildren.get(record.childId) === record)
|
|
@@ -540,15 +640,23 @@ export class NativeAdmission {
|
|
|
540
640
|
throw new SubagentError("Native admission dependencies changed", "UNAUTHORIZED");
|
|
541
641
|
if (live.preset !== agent.ctx.get("agentPresets")?.composedPreset(agent.ctx) || live.scopeParent !== scopeParentOf(agent))
|
|
542
642
|
throw new SubagentError("Preset composition changed; create a new session", "UNAUTHORIZED");
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
this.
|
|
643
|
+
const owner = live.owner ?? live.parent;
|
|
644
|
+
if (owner) {
|
|
645
|
+
const root = nativeTreeRoot(this.ctx.agents, agent);
|
|
646
|
+
if (this.ctx.agents.get(owner.id) !== owner || (root === undefined ? !nativeIsOwnedBy(this.ctx.agents, agent.id, owner) : root !== owner)
|
|
647
|
+
|| agent.session.header.parentSession !== live.creatorId)
|
|
648
|
+
throw new SubagentError("Admission owner changed", "UNAUTHORIZED");
|
|
649
|
+
this.assertBinding(owner, maintenanceRoot);
|
|
650
|
+
}
|
|
547
651
|
this.policy.assertModuleAdmission(agent);
|
|
548
652
|
return live.admission;
|
|
549
653
|
}
|
|
550
654
|
residentTree(agent) {
|
|
551
|
-
const
|
|
655
|
+
const residents = this.ctx.agents.list();
|
|
656
|
+
if (nativeTreeRoot(this.ctx.agents, agent) === agent) {
|
|
657
|
+
return [agent, ...residents.filter(member => member !== agent && nativeTreeRoot(this.ctx.agents, member) === agent).sort((a, b) => a.id.localeCompare(b.id))];
|
|
658
|
+
}
|
|
659
|
+
const tree = [agent];
|
|
552
660
|
for (let index = 0; index < tree.length; index++) {
|
|
553
661
|
for (const child of residents.filter(child => nativeIsOwnedBy(this.ctx.agents, child.id, tree[index])).sort((a, b) => a.id.localeCompare(b.id))) {
|
|
554
662
|
if (tree.includes(child))
|
|
@@ -558,31 +666,6 @@ export class NativeAdmission {
|
|
|
558
666
|
}
|
|
559
667
|
return tree;
|
|
560
668
|
}
|
|
561
|
-
observeProviders() {
|
|
562
|
-
const scopes = new Set([this.ctx, this.ctx.root]);
|
|
563
|
-
for (const plugin of this.ctx.registry.values())
|
|
564
|
-
for (const fiber of plugin.fibers)
|
|
565
|
-
scopes.add(fiber.ctx);
|
|
566
|
-
const registry = original(this.ctx.agents), current = new Map();
|
|
567
|
-
for (const scope of scopes) {
|
|
568
|
-
const agents = scope.get("agents", false), runtime = scope.get("subagents", false);
|
|
569
|
-
if (agents === undefined || original(agents) !== registry || runtime === undefined || current.has(original(runtime)))
|
|
570
|
-
continue;
|
|
571
|
-
// Hosts without provider enumeration cannot prove that external starts are absent.
|
|
572
|
-
current.set(original(runtime), typeof runtime.list !== "function"
|
|
573
|
-
|| runtime.list().some(name => runtime.getProvider(name)?.prepareContinuable === undefined));
|
|
574
|
-
}
|
|
575
|
-
// Any native service sharing this registry may accept these exact parents,
|
|
576
|
-
// including isolated services the Agent's own context does not resolve.
|
|
577
|
-
// Removal and late start/end cannot prove unpublished external starts ended.
|
|
578
|
-
if ([...this.providerScopes.values(), ...current.values()].some(Boolean)) {
|
|
579
|
-
for (const agent of this.ctx.agents.list())
|
|
580
|
-
this.opaqueAgents.add(agent);
|
|
581
|
-
}
|
|
582
|
-
this.providerScopes.clear();
|
|
583
|
-
for (const [runtime, opaque] of current)
|
|
584
|
-
this.providerScopes.set(runtime, opaque);
|
|
585
|
-
}
|
|
586
669
|
blankReason(agent, allowQueued = false) {
|
|
587
670
|
if (!this.isReady || this.failedInstallations.has(agent) || this.ctx.agents.get(agent.id) !== agent || !nativeRoots(this.ctx.agents).includes(agent) || this.dependencies(agent).some(value => value === undefined))
|
|
588
671
|
return "runtime-unavailable";
|
|
@@ -592,12 +675,8 @@ export class NativeAdmission {
|
|
|
592
675
|
if (this.selecting.has(agent) && !allowQueued)
|
|
593
676
|
return "busy";
|
|
594
677
|
try {
|
|
595
|
-
this.observeProviders();
|
|
596
678
|
for (const member of this.residentTree(agent)) {
|
|
597
679
|
this.assertBinding(member, allowQueued ? agent : undefined);
|
|
598
|
-
const runtime = member.ctx.get("subagents");
|
|
599
|
-
if (runtime === undefined || !this.providerScopes.has(original(runtime)) || this.opaqueAgents.has(member))
|
|
600
|
-
return "runtime-unavailable";
|
|
601
680
|
if (this.dependencies(member).some(value => value === undefined))
|
|
602
681
|
return "runtime-unavailable";
|
|
603
682
|
if (member.status !== "idle" || hasOpenTurn(sessionEvents(member.session)) || (this.calls.get(member) ?? 0) !== 0
|
|
@@ -788,7 +867,7 @@ export class NativeAdmission {
|
|
|
788
867
|
ambiguous.add(callId);
|
|
789
868
|
calls.delete(callId);
|
|
790
869
|
}
|
|
791
|
-
const observation = { parent, parentAdmission, token: exec.token, callId, rootCallId, childId, invocation, role,
|
|
870
|
+
const observation = { kind: "role", parent, parentAdmission, token: exec.token, callId, rootCallId, childId, invocation, role,
|
|
792
871
|
label, provider: provider.name, delivery, phase: "reserved", actualRoute: Object.freeze({ status: "unknown", reason: "not-observed" }) };
|
|
793
872
|
const pending = Object.freeze({ childId, parent, parentAdmission, callId: exec.callId, invocation, admission, provider, expectedPreset, presetScope, signal, maxDepth, toolFilter, observation });
|
|
794
873
|
this.recordsFor(parent).add(observation);
|
|
@@ -881,7 +960,10 @@ export class NativeAdmission {
|
|
|
881
960
|
if (existing)
|
|
882
961
|
return existing;
|
|
883
962
|
this.agentLifetimes.get(agent)?.abort();
|
|
884
|
-
const children = new Set([...this.agents].filter(child =>
|
|
963
|
+
const children = new Set([...this.agents].filter(child => {
|
|
964
|
+
const live = this.live.get(child);
|
|
965
|
+
return (live?.owner ?? live?.parent) === agent;
|
|
966
|
+
}));
|
|
885
967
|
for (const child of children)
|
|
886
968
|
child.cancel({ kind: "disposed" });
|
|
887
969
|
const receipts = [...this.activations].filter(activation => [...children].some(child => child.id === activation.childId));
|
|
@@ -929,7 +1011,6 @@ export class NativeAdmission {
|
|
|
929
1011
|
throw new SubagentError("Role creation requires its first pending call", "UNAUTHORIZED");
|
|
930
1012
|
if (!this.isReady || !this.install)
|
|
931
1013
|
throw new SubagentError("DSMM admission is initializing", "UNAUTHORIZED");
|
|
932
|
-
this.observeProviders();
|
|
933
1014
|
let signal = AbortSignal.any([...creationSignal ? [creationSignal] : [], this.lifetime.signal]);
|
|
934
1015
|
signal.throwIfAborted();
|
|
935
1016
|
const parents = this.ctx.agents.list().filter(parent => parent !== agent && nativeIsOwnedBy(this.ctx.agents, agent.id, parent));
|
|
@@ -950,10 +1031,19 @@ export class NativeAdmission {
|
|
|
950
1031
|
throw new SubagentError("Role continuation requires an admitted parent", "UNAUTHORIZED");
|
|
951
1032
|
return;
|
|
952
1033
|
}
|
|
953
|
-
|
|
954
|
-
|
|
1034
|
+
const ceiling = source === "resume" ? readDelegationCeiling(agent.session) : undefined;
|
|
1035
|
+
const root = nativeTreeRoot(this.ctx.agents, agent);
|
|
1036
|
+
const owner = parent ? root ?? parent : ceiling !== undefined && root !== agent ? root : undefined;
|
|
1037
|
+
if (ceiling !== undefined && (root?.id !== ceiling.rootId || agent.id !== ceiling.childId
|
|
1038
|
+
|| agent.session.header.parentSession !== ceiling.creatorId || descriptor?.provider !== ceiling.provider
|
|
1039
|
+
|| (roleFromProviderName(descriptor.provider) ?? null) !== ceiling.role))
|
|
1040
|
+
throw new SubagentError("Delegation ceiling identity mismatch", "UNAUTHORIZED");
|
|
1041
|
+
if (!parent && !owner && (!nativeRoots(this.ctx.agents).includes(agent) || agent.session.header.origin === "subagent" || descriptor !== undefined))
|
|
1042
|
+
throw new SubagentError("Child requires its native creator or ceiling", "UNAUTHORIZED");
|
|
1043
|
+
if (owner)
|
|
1044
|
+
this.assert(owner);
|
|
955
1045
|
this.agentLifetimes.set(agent, new AbortController());
|
|
956
|
-
signal = AbortSignal.any([signal, this.agentLifetimes.get(agent).signal, ...
|
|
1046
|
+
signal = AbortSignal.any([signal, this.agentLifetimes.get(agent).signal, ...owner ? [this.agentLifetimes.get(owner).signal] : []]);
|
|
957
1047
|
scopeLifetime(agent.ctx, "dsmm: retire exact Agent work", () => { void this.retireAgent(agent).catch(() => { }); });
|
|
958
1048
|
agent.ctx.effect(() => async () => {
|
|
959
1049
|
try {
|
|
@@ -971,18 +1061,56 @@ export class NativeAdmission {
|
|
|
971
1061
|
});
|
|
972
1062
|
const dependencies = this.dependencies(agent);
|
|
973
1063
|
const parentAdmission = parent ? this.assert(parent) : undefined;
|
|
1064
|
+
const ownerAdmission = owner ? this.assert(owner) : undefined;
|
|
974
1065
|
const check = () => {
|
|
975
1066
|
signal.throwIfAborted();
|
|
976
1067
|
this.agentLifetimes.get(agent).signal.throwIfAborted();
|
|
977
1068
|
if (!this.isReady || this.ctx.agents.get(agent.id) !== agent || this.ctx.get("sessions")?.get(agent.id) !== agent.session
|
|
978
1069
|
|| scopeOf(agent.ctx) !== agent || original(agent.ctx.get("agents")) !== original(this.ctx.agents)
|
|
979
1070
|
|| this.dependencies(agent).some((value, index) => value !== dependencies[index]) || scopeParentOf(agent) !== presetScope || preset !== agent.ctx.get("agentPresets")?.composedPreset(agent.ctx)
|
|
980
|
-
||
|
|
1071
|
+
|| owner && (this.assert(owner) !== ownerAdmission || (root === undefined ? !nativeIsOwnedBy(this.ctx.agents, agent.id, owner) : nativeTreeRoot(this.ctx.agents, agent) !== owner))
|
|
1072
|
+
|| pending && parent && (this.assert(parent) !== parentAdmission || !nativeIsOwnedBy(this.ctx.agents, agent.id, parent)))
|
|
981
1073
|
throw new SubagentError("Activation owner changed", "UNAUTHORIZED");
|
|
982
1074
|
};
|
|
983
1075
|
let continuation, independent = false, continuationProvider;
|
|
984
1076
|
let admission;
|
|
985
|
-
if (
|
|
1077
|
+
if (ceiling !== undefined) {
|
|
1078
|
+
if (!owner || descriptor?.mode !== "continuable" || agent.session.header.origin !== "subagent")
|
|
1079
|
+
throw new SubagentError("Cold child is not continuable", "NOT_RESUMABLE");
|
|
1080
|
+
const subagents = this.ctx.get("subagents");
|
|
1081
|
+
const rows = await subagents.listDescendants(owner.id, signal);
|
|
1082
|
+
check();
|
|
1083
|
+
const row = rows.find(row => row.id === agent.id);
|
|
1084
|
+
if (!row || row.kind === "diagnostic" || row.parentId !== ceiling.creatorId || row.mode !== "continuable")
|
|
1085
|
+
throw new SubagentError("Native child catalog mismatch", "UNAUTHORIZED");
|
|
1086
|
+
const metadata = { childSessionId: ceiling.childId, parentSessionId: ceiling.creatorId, role: ceiling.role,
|
|
1087
|
+
profileId: ceiling.profileId, level: ceiling.level };
|
|
1088
|
+
const previous = await this.profiles.readChildIdentity(agent.id, ceiling.creatorId);
|
|
1089
|
+
if (previous && (previous.role !== metadata.role || previous.profileId !== metadata.profileId || previous.level !== metadata.level))
|
|
1090
|
+
throw new SubagentError("Child selection identity conflict", "UNAUTHORIZED");
|
|
1091
|
+
const ownPreset = own.find(event => event.type === "agent-preset/selected" || event.type === "subagent/descriptor");
|
|
1092
|
+
independent = ownPreset?.type === "agent-preset/selected";
|
|
1093
|
+
if (!independent && (preset !== owner.ctx.get("agentPresets")?.composedPreset(owner.ctx) || presetScope !== scopeParentOf(owner)))
|
|
1094
|
+
throw new SubagentError("Inherited composition changed", "UNAUTHORIZED");
|
|
1095
|
+
continuationProvider = ceiling.role === null ? subagents.getProvider(ceiling.provider) : this.providers.get(roleProviderName(ceiling.role));
|
|
1096
|
+
const currentProvider = continuationProvider && subagents.getProvider(continuationProvider.name);
|
|
1097
|
+
if (!continuationProvider || !currentProvider || original(currentProvider) !== original(continuationProvider))
|
|
1098
|
+
throw new SubagentError("Native provider is unavailable", "UNAUTHORIZED");
|
|
1099
|
+
admission = await this.profiles.prepareChild(agent, ownerAdmission, signal, { profileId: ceiling.profileId });
|
|
1100
|
+
check();
|
|
1101
|
+
if (ceiling.role !== null) {
|
|
1102
|
+
if (!admission.settings.modules.deepwork.enabled || !admission.settings.roles[ceiling.role])
|
|
1103
|
+
throw new SubagentError("Role is disabled", "UNAUTHORIZED");
|
|
1104
|
+
this.policy.assertDelegation(owner, ceiling.role);
|
|
1105
|
+
const manual = latestNativeModelSelection(agent)?.route;
|
|
1106
|
+
continuation = await resolveRoleInvocation(owner, ceiling.role, admission.settings, signal, { level: ceiling.level }, manual === undefined ? undefined : { provider: manual.provider, model: manual.model,
|
|
1107
|
+
...(manual.reasoningEffort === undefined ? {} : { reasoningEffort: ReasoningEffortId(manual.reasoningEffort) }) }, resolvedModelParameterPolicy(admission));
|
|
1108
|
+
check();
|
|
1109
|
+
}
|
|
1110
|
+
else if (isDsmmRoleId(preset))
|
|
1111
|
+
throw new SubagentError("Native continuation cannot acquire a DSMM role", "UNAUTHORIZED");
|
|
1112
|
+
}
|
|
1113
|
+
else if (parent) {
|
|
986
1114
|
const parentAdmission = this.assert(parent), controlled = this.policy.identity(parent).role !== undefined;
|
|
987
1115
|
if (agent.session.header.parentSession !== parent.id || agent.session.header.origin !== "subagent")
|
|
988
1116
|
throw new SubagentError("Invalid native child header", "UNAUTHORIZED");
|
|
@@ -1058,10 +1186,22 @@ export class NativeAdmission {
|
|
|
1058
1186
|
try {
|
|
1059
1187
|
if (pending)
|
|
1060
1188
|
this.policy.bindChild(agent, parent, admission, pending.invocation, pending.maxDepth, pending.toolFilter);
|
|
1189
|
+
else if (ceiling)
|
|
1190
|
+
this.policy.bindContinuedChild(agent, owner, admission, continuation, ceiling, ceiling.role === null ? admission.settings.subagents.maxDepth : this.ctx.get("subagents").resolveMaxDepth(admission.settings.subagents.maxDepth), independent);
|
|
1061
1191
|
else if (continuation)
|
|
1062
1192
|
this.policy.bindChild(agent, parent, admission, continuation, this.ctx.get("subagents").resolveMaxDepth(admission.settings.subagents.maxDepth), this.policy.visibleToolCeiling(parent), independent);
|
|
1063
1193
|
else if (parent)
|
|
1064
|
-
this.policy.bindInheritedChild(agent, parent, admission, source === "resume");
|
|
1194
|
+
this.policy.bindInheritedChild(agent, parent, admission, source === "resume", admission.settings.subagents.maxDepth);
|
|
1195
|
+
if (parent && root && source !== "resume" && descriptor) {
|
|
1196
|
+
const provider = this.ctx.get("subagents").getProvider(descriptor.provider);
|
|
1197
|
+
if (!provider)
|
|
1198
|
+
throw new SubagentError("Native provider is unavailable", "UNAUTHORIZED");
|
|
1199
|
+
if (!pending)
|
|
1200
|
+
continuationProvider = provider;
|
|
1201
|
+
appendDelegationCeiling(agent.session, { version: 1, childId: agent.id, creatorId: parent.id, rootId: root.id,
|
|
1202
|
+
provider: descriptor.provider, ...(pending ? { role: pending.invocation.target, level: pending.invocation.effectiveLevel } : { role: null, level: null }),
|
|
1203
|
+
profileId: admission.profile?.id ?? null, ...this.policy.delegationCeiling(agent) });
|
|
1204
|
+
}
|
|
1065
1205
|
await this.install(agent, this.getter(agent));
|
|
1066
1206
|
check();
|
|
1067
1207
|
await this.profiles.revalidateActivation(admission);
|
|
@@ -1089,7 +1229,8 @@ export class NativeAdmission {
|
|
|
1089
1229
|
check();
|
|
1090
1230
|
this.profiles.publish(agent, admission);
|
|
1091
1231
|
const published = this.profiles.admission(agent);
|
|
1092
|
-
this.live.set(agent, Object.freeze({ admission: published, preset, scopeParent: scopeParentOf(agent), parent,
|
|
1232
|
+
this.live.set(agent, Object.freeze({ admission: published, preset, scopeParent: scopeParentOf(agent), parent, owner, creatorId: agent.session.header.parentSession,
|
|
1233
|
+
invocation: pending?.invocation ?? continuation, dependencies, provider: pending?.provider ?? continuationProvider }));
|
|
1093
1234
|
if (pending) {
|
|
1094
1235
|
this.bindObservedChild(pending.observation, agent, published);
|
|
1095
1236
|
this.pending.delete(agent.id);
|
|
@@ -9,6 +9,9 @@ export interface NativeOwnershipRegistry<A extends OwnershipAgent> {
|
|
|
9
9
|
}
|
|
10
10
|
/** Root membership is native runtime evidence, never durable session lineage. */
|
|
11
11
|
export declare function nativeRoots<A extends OwnershipAgent>(registry: NativeOwnershipRegistry<A>): A[];
|
|
12
|
+
/** A tree root is authority only while both exact objects remain registered. */
|
|
13
|
+
export declare function nativeTreeRoot<A extends OwnershipAgent>(registry: NativeOwnershipRegistry<A>, agent: A): A | undefined;
|
|
14
|
+
export declare function nativeSameTree<A extends OwnershipAgent>(registry: NativeOwnershipRegistry<A>, left: A, right: A): boolean;
|
|
12
15
|
/** New runtimes require an authenticated creation edge in addition to native tree residency. */
|
|
13
16
|
export declare function nativeIsOwnedBy<A extends OwnershipAgent>(registry: NativeOwnershipRegistry<A> | undefined, childId: string, parent: A): boolean;
|
|
14
17
|
/** Call only after authenticating the native start's direct creator, not from a session header. */
|
package/lib/native-ownership.js
CHANGED
|
@@ -22,6 +22,25 @@ export function nativeRoots(registry) {
|
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
/** A tree root is authority only while both exact objects remain registered. */
|
|
26
|
+
export function nativeTreeRoot(registry, agent) {
|
|
27
|
+
if (agent.id === undefined || registry.get(agent.id) !== agent)
|
|
28
|
+
return undefined;
|
|
29
|
+
try {
|
|
30
|
+
const root = runtimeOf(agent)?.rootOf(agent);
|
|
31
|
+
if (root?.id === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
const live = registry.get(root.id);
|
|
34
|
+
return live === root && runtimeOf(live)?.rootOf(live) === live ? live : undefined;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function nativeSameTree(registry, left, right) {
|
|
41
|
+
const root = nativeTreeRoot(registry, left);
|
|
42
|
+
return root !== undefined && nativeTreeRoot(registry, right) === root;
|
|
43
|
+
}
|
|
25
44
|
/** New runtimes require an authenticated creation edge in addition to native tree residency. */
|
|
26
45
|
export function nativeIsOwnedBy(registry, childId, parent) {
|
|
27
46
|
if (registry === undefined)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
1
2
|
import type { SessionId } from "@deepseek-ai/dsh-session";
|
|
2
3
|
import type { SubagentActivation, SubagentCatalogEntry, SubagentDescendantListEntry, SubagentInterruptReceipt, SubagentPromptReceipt, SubagentPromptRequest, SubagentRuntime } from "@deepseek-ai/dsh-subagent";
|
|
3
4
|
type ActivationSpec = Parameters<SubagentRuntime["startActivation"]>[0];
|
|
@@ -15,6 +16,6 @@ export declare function listNativeChildren(runtime: ChildDiscovery, parentId: Se
|
|
|
15
16
|
/** Transport an already-authorized direct-child prompt through the Host's control contract. */
|
|
16
17
|
export declare function promptNativeChild(runtime: SubagentRuntime, request: SubagentPromptRequest, signal: AbortSignal): Promise<SubagentPromptReceipt>;
|
|
17
18
|
/** Caller-side catalog and exact-parent checks remain authoritative for this interrupt. */
|
|
18
|
-
export declare function interruptNativeChild(runtime: SubagentRuntime, childId: SessionId,
|
|
19
|
+
export declare function interruptNativeChild(runtime: SubagentRuntime, childId: SessionId, caller: Agent): SubagentInterruptReceipt;
|
|
19
20
|
export {};
|
|
20
21
|
//# sourceMappingURL=native-subagents.d.ts.map
|