@dsmm/dsmm 0.2.2 → 0.3.0
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 +8 -10
- package/cordis.patch.yml +14 -0
- package/docs/agent-presets.md +4 -4
- package/docs/compatibility.md +19 -24
- package/docs/deferred-native-approval-risk.md +2 -2
- package/docs/model-routing.md +3 -3
- package/docs/profiles.md +1 -1
- package/docs/releasing.md +46 -6
- package/docs/settings-status.md +2 -2
- package/lib/agent-registry.d.ts +36 -0
- package/lib/agent-registry.js +75 -0
- package/lib/child-admission.d.ts +0 -2
- package/lib/child-admission.js +13 -24
- package/lib/child-capture.d.ts +5 -1
- package/lib/child-capture.js +7 -5
- package/lib/client/children-locales.d.ts +13 -13
- package/lib/client/deployment-controller.js +1 -1
- package/lib/client.js +3 -3
- package/lib/delivery-authority.d.ts +18 -3
- package/lib/delivery-authority.js +149 -12
- package/lib/index.d.ts +2 -2
- package/lib/index.js +13 -26
- package/lib/native-child-evidence.d.ts +1 -3
- package/lib/native-child-evidence.js +0 -29
- package/lib/permission-rpc.js +3 -3
- package/lib/profile-rpc.js +6 -4
- package/lib/profile-store.js +2 -2
- package/lib/role-control-rpc.js +12 -8
- package/lib/role-invocation.d.ts +1 -1
- package/lib/role-policy.d.ts +1 -4
- package/lib/role-policy.js +24 -41
- package/lib/role-providers.d.ts +1 -1
- package/lib/role-providers.js +15 -55
- package/lib/role-runs.d.ts +17 -14
- package/lib/role-runs.js +45 -14
- package/lib/role-subagents.js +16 -6
- package/lib/runtime-integration.d.ts +4 -35
- package/lib/runtime-integration.js +38 -120
- package/lib/session-persistence.d.ts +2 -1
- package/lib/session-persistence.js +1 -1
- package/lib/session-scope.js +4 -1
- package/lib/subagent-runtime.d.ts +19 -7
- package/lib/subagent-runtime.js +141 -15
- package/package.json +110 -100
- package/lib/legacy-child-policy.d.ts +0 -51
- package/lib/legacy-child-policy.js +0 -123
- package/lib/legacy-read-composition.d.ts +0 -20
- package/lib/legacy-read-composition.js +0 -144
- package/lib/legacy-read-contracts.d.ts +0 -157
- package/lib/legacy-read-contracts.js +0 -39
- package/lib/legacy-read-host.d.ts +0 -19
- package/lib/legacy-read-host.js +0 -67
- package/lib/legacy-read-integration.d.ts +0 -121
- package/lib/legacy-read-integration.js +0 -522
- package/lib/legacy-read-proxy.d.ts +0 -26
- package/lib/legacy-read-proxy.js +0 -237
- package/scripts/cold-profile-composition.mjs +0 -329
- package/scripts/cold-profile-sources.mjs +0 -238
- package/scripts/migrate-cold-profile.mjs +0 -315
- package/scripts/repair-session-log.mjs +0 -476
- package/scripts/session-repair-native-verifier.mjs +0 -367
package/lib/role-providers.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { SubagentError } from "@deepseek-ai/dsh-subagent";
|
|
2
2
|
import { DSMM_ROLE_IDS, roleProviderName } from "./roles.js";
|
|
3
3
|
export { roleProviderName } from "./roles.js";
|
|
4
|
-
import { currentRoleInvocation,
|
|
4
|
+
import { currentRoleInvocation, invocationAgentOptions, resolveRoleInvocation } from "./role-invocation.js";
|
|
5
|
+
import { currentManagedCreation } from "./agent-registry.js";
|
|
5
6
|
export function roleFromProviderName(provider) {
|
|
6
7
|
return DSMM_ROLE_IDS.find((role) => role !== "dsmm-orchestrator" && roleProviderName(role) === provider);
|
|
7
8
|
}
|
|
8
|
-
const NO_CAPABILITIES = Object.freeze({ agentOptions: false, outputSchema: false, depthLimit: false,
|
|
9
|
+
const NO_CAPABILITIES = Object.freeze({ agentOptions: false, outputSchema: false, depthLimit: false, agentPreset: false });
|
|
9
10
|
function supportedSpawn(provider) {
|
|
10
|
-
return provider !== undefined && provider.name === "spawn" && typeof provider.
|
|
11
|
+
return provider !== undefined && provider.name === "spawn" && typeof provider.prepareContinuable === "function"
|
|
11
12
|
&& provider.inheritsParentContext === false && provider.agentRouteDefaults === undefined;
|
|
12
13
|
}
|
|
13
14
|
export async function roleAgentOptions(parent, role, settings, signal, explicit) {
|
|
14
15
|
const invocation = currentRoleInvocation(parent, role) ?? await resolveRoleInvocation(parent, role, settings, signal, {}, explicit);
|
|
15
16
|
return invocationAgentOptions(invocation, explicit);
|
|
16
17
|
}
|
|
17
|
-
/**
|
|
18
|
+
/** The native manager owns descriptors, capability admission and activations. */
|
|
18
19
|
export function registerRoleProviders(ctx, getSettings, getDeploymentSettings = getSettings, policy) {
|
|
19
20
|
const installed = new WeakSet();
|
|
20
21
|
const install = (readyCtx) => {
|
|
@@ -38,15 +39,18 @@ export function registerRoleProviders(ctx, getSettings, getDeploymentSettings =
|
|
|
38
39
|
inheritsParentContext: false,
|
|
39
40
|
get prepareContinuable() {
|
|
40
41
|
const spawn = registry.getProvider("spawn");
|
|
41
|
-
if (!supportedSpawn(spawn) || spawn.prepareContinuable === undefined)
|
|
42
|
-
return undefined;
|
|
43
42
|
return async (request) => {
|
|
43
|
+
if (!supportedSpawn(spawn) || spawn.prepareContinuable === undefined)
|
|
44
|
+
throw new SubagentError("DSMM requires a local spawn provider", "UNSUPPORTED_CAPABILITY");
|
|
44
45
|
if (!active || registry.getProvider("spawn") !== spawn)
|
|
45
46
|
throw new SubagentError("DSMM native continuable provider changed", "NO_PROVIDER");
|
|
46
47
|
const admitted = getSettings(request.parent);
|
|
47
48
|
if (!admitted.modules.deepwork.enabled || !admitted.roles[role])
|
|
48
49
|
throw new SubagentError("DSMM module or role is disabled", "UNAUTHORIZED");
|
|
49
|
-
|
|
50
|
+
const operation = currentManagedCreation();
|
|
51
|
+
if (operation?.kind !== "fresh" || operation.parent !== request.parent || operation.childId !== request.sessionId)
|
|
52
|
+
throw new SubagentError("DSMM role requires its managed creation operation", "UNAUTHORIZED");
|
|
53
|
+
if (operation.delegationMode === "continuable" && (!admitted.subagents.enableRunInBackground || admitted.subagents.backgroundMode !== "continuable"))
|
|
50
54
|
throw new SubagentError("DSMM continuable delegation requires explicit admitted opt-in", "UNAUTHORIZED");
|
|
51
55
|
const preparing = policy?.prepareContinuable(request.parent, role, request.signal);
|
|
52
56
|
const invocation = currentRoleInvocation(request.parent, role);
|
|
@@ -55,55 +59,11 @@ export function registerRoleProviders(ctx, getSettings, getDeploymentSettings =
|
|
|
55
59
|
throw new SubagentError("DSMM continuable provider changed during preflight", "NO_PROVIDER");
|
|
56
60
|
if (preparing !== undefined)
|
|
57
61
|
policy.recordContinuableCreation(request.sessionId, request.parent, role, invocation, preparing.epoch, request.signal);
|
|
58
|
-
|
|
62
|
+
const prepared = await spawn.prepareContinuable(request);
|
|
63
|
+
if (prepared.seed !== undefined)
|
|
64
|
+
throw new SubagentError("DSMM spawn cannot inherit parent history", "UNSUPPORTED_CAPABILITY");
|
|
65
|
+
return prepared;
|
|
59
66
|
};
|
|
60
|
-
},
|
|
61
|
-
async start(request) {
|
|
62
|
-
if (!active)
|
|
63
|
-
throw new Error("dsmm role provider is disposed");
|
|
64
|
-
const spawn = registry.getProvider("spawn");
|
|
65
|
-
if (!supportedSpawn(spawn))
|
|
66
|
-
throw new Error("dsmm role provider requires the supported native spawn capabilities");
|
|
67
|
-
if (request.descriptor.mode !== "one-shot" || request.descriptor.provider !== roleProviderName(role))
|
|
68
|
-
throw new SubagentError("DSMM alias requires its exact native descriptor", "UNAUTHORIZED");
|
|
69
|
-
const admission = policy?.assertDelegation(request.parent, role);
|
|
70
|
-
for (const [key, value] of Object.entries({ agentOptions: request.agentOptions, outputSchema: request.outputSchema, depthLimit: request.maxDepth, toolFilter: request.toolFilter, persona: request.persona })) {
|
|
71
|
-
if (value !== undefined && !spawn.capabilities[key])
|
|
72
|
-
throw new SubagentError(`DSMM spawn does not support ${key}`, "UNSUPPORTED_CAPABILITY");
|
|
73
|
-
}
|
|
74
|
-
const parentSettings = getSettings(request.parent);
|
|
75
|
-
if (!parentSettings.modules.deepwork.enabled || !parentSettings.roles[role])
|
|
76
|
-
throw new Error("dsmm role provider is disabled by deployment configuration");
|
|
77
|
-
const invocation = currentRoleInvocation(request.parent, role)
|
|
78
|
-
?? await resolveRoleInvocation(request.parent, role, parentSettings, request.signal, {}, request.agentOptions);
|
|
79
|
-
const agentOptions = invocationAgentOptions(invocation, request.agentOptions);
|
|
80
|
-
request.signal.throwIfAborted();
|
|
81
|
-
if (!active || registry.getProvider("spawn") !== spawn)
|
|
82
|
-
throw new Error("dsmm role spawn provider changed during route validation; retry delegation");
|
|
83
|
-
if (admission !== undefined && policy.assertDelegation(request.parent, role).epoch !== admission.epoch)
|
|
84
|
-
throw new SubagentError("DSMM parent admission changed during route preflight", "UNAUTHORIZED");
|
|
85
|
-
// Preserve the native descriptor, authority filters and lifecycle;
|
|
86
|
-
// this alias owns only profile-derived route defaults and preflight.
|
|
87
|
-
const routed = agentOptions === request.agentOptions ? request : { ...request, agentOptions };
|
|
88
|
-
const ceiling = parentSettings.subagents.maxDepth;
|
|
89
|
-
if (request.maxDepth !== undefined && ceiling !== undefined && request.maxDepth > ceiling)
|
|
90
|
-
throw new SubagentError("DSMM request exceeds the admitted parent depth ceiling", "UNAUTHORIZED");
|
|
91
|
-
const maxDepth = request.maxDepth ?? registry.resolveMaxDepth?.(ceiling);
|
|
92
|
-
if (maxDepth !== undefined && !spawn.capabilities.depthLimit)
|
|
93
|
-
throw new SubagentError("DSMM spawn cannot enforce the native depth limit", "UNSUPPORTED_CAPABILITY");
|
|
94
|
-
const resolved = maxDepth === undefined ? routed : { ...routed, maxDepth };
|
|
95
|
-
if (resolved.agentOptions !== undefined && !spawn.capabilities.agentOptions)
|
|
96
|
-
throw new SubagentError("DSMM spawn cannot accept the configured or selected child route", "UNSUPPORTED_CAPABILITY");
|
|
97
|
-
let admittedChild;
|
|
98
|
-
const run = await duringRoleInvocation(request.parent, invocation, () => policy === undefined ? spawn.start(resolved)
|
|
99
|
-
: policy.duringDelegation(request.parent, role, () => spawn.start(resolved), request.toolFilter, maxDepth, agent => { admittedChild = agent; }));
|
|
100
|
-
// Public holder boundary: revoke this exact residency before opaque native teardown.
|
|
101
|
-
return policy === undefined ? run : { ...run, dispose() {
|
|
102
|
-
const child = run.localAgent ?? admittedChild;
|
|
103
|
-
if (child !== undefined)
|
|
104
|
-
policy.revokeResidency(child);
|
|
105
|
-
return run.dispose();
|
|
106
|
-
} };
|
|
107
67
|
}
|
|
108
68
|
});
|
|
109
69
|
const provider = registry.getProvider(roleProviderName(role));
|
package/lib/role-runs.d.ts
CHANGED
|
@@ -2,14 +2,20 @@ import type { Context } from "@deepseek-ai/cordis";
|
|
|
2
2
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
3
|
import type { ContentBlock, ToolCallId } from "@deepseek-ai/dsh-llm";
|
|
4
4
|
import type { SessionId } from "@deepseek-ai/dsh-session";
|
|
5
|
-
import type {
|
|
5
|
+
import type { SubagentActivation } from "@deepseek-ai/dsh-subagent";
|
|
6
|
+
import type { JobRegistry } from "@deepseek-ai/dsh-jobs";
|
|
7
|
+
declare module "@deepseek-ai/dsh-jobs/view" {
|
|
8
|
+
interface JobKindMap {
|
|
9
|
+
subagent: "subagent";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
6
12
|
export type RoleRunState = "starting" | "running" | "background" | "settled" | "cancelled";
|
|
7
|
-
export type RoleRunJobId = ReturnType<
|
|
13
|
+
export type RoleRunJobId = ReturnType<JobRegistry["start"]>;
|
|
8
14
|
export interface RoleRunAddress {
|
|
9
15
|
readonly sessionId: SessionId;
|
|
10
16
|
readonly toolCallId: ToolCallId;
|
|
11
|
-
/**
|
|
12
|
-
readonly runId:
|
|
17
|
+
/** Public role-run address is the activation childId, never lifecycle-event runId. */
|
|
18
|
+
readonly runId: SubagentActivation["childId"];
|
|
13
19
|
}
|
|
14
20
|
/** Host-only identity. Capture/projection are the borrowed original admitted objects. */
|
|
15
21
|
export interface RoleRunInvocation<C = unknown, P = unknown> extends RoleRunAddress {
|
|
@@ -23,7 +29,7 @@ export interface RoleRunInvocation<C = unknown, P = unknown> extends RoleRunAddr
|
|
|
23
29
|
}
|
|
24
30
|
export interface RoleRunForeground<C = unknown, P = unknown> {
|
|
25
31
|
readonly kind: "foreground";
|
|
26
|
-
readonly runId:
|
|
32
|
+
readonly runId: SubagentActivation["childId"];
|
|
27
33
|
readonly invocation: RoleRunInvocation<C, P>;
|
|
28
34
|
readonly output: readonly ContentBlock[];
|
|
29
35
|
}
|
|
@@ -46,12 +52,8 @@ export interface RoleRunBackgroundRequest extends RoleRunAddress {
|
|
|
46
52
|
export interface RoleRunTeardown {
|
|
47
53
|
/** Supply the stable Host authority's revokeParent, never an epoch-only abort. */
|
|
48
54
|
revokeParent(agent: Agent, reason: string): void;
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
* callback owns MUST also be authority-revoked before their original disposal.
|
|
52
|
-
* The holder revokes the public localAgent before calling this collaborator.
|
|
53
|
-
*/
|
|
54
|
-
disposeRun(run: SubagentRun): Promise<void>;
|
|
55
|
+
/** Invoke the exact activation disposer, whose runtime boundary revokes its tree. */
|
|
56
|
+
disposeRun(run: SubagentActivation): Promise<void>;
|
|
55
57
|
}
|
|
56
58
|
export interface RoleRunCollaborators<C = unknown, P = unknown> {
|
|
57
59
|
/** Synchronous exact-parent/entry-owner check plus the current stable epoch. */
|
|
@@ -70,9 +72,9 @@ export interface RoleRunStart<C = unknown, P = unknown> {
|
|
|
70
72
|
readonly projection: P;
|
|
71
73
|
readonly label: string;
|
|
72
74
|
readonly callerAbort: AbortSignal;
|
|
73
|
-
readonly jobs?:
|
|
74
|
-
/** Call native
|
|
75
|
-
start(signal: AbortSignal): Promise<
|
|
75
|
+
readonly jobs?: JobRegistry;
|
|
76
|
+
/** Call native startActivation exactly once, forwarding this holder signal. */
|
|
77
|
+
start(signal: AbortSignal): Promise<SubagentActivation>;
|
|
76
78
|
}
|
|
77
79
|
/** One foreground call's real native run and its revocable caller-cancel relay. */
|
|
78
80
|
export declare class RoleRunHolder<C = unknown, P = unknown> {
|
|
@@ -84,6 +86,7 @@ export declare class RoleRunHolder<C = unknown, P = unknown> {
|
|
|
84
86
|
private identity?;
|
|
85
87
|
private receipt?;
|
|
86
88
|
private outcome?;
|
|
89
|
+
private disposeActivation?;
|
|
87
90
|
private terminal;
|
|
88
91
|
private finished;
|
|
89
92
|
private registering;
|
package/lib/role-runs.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SubagentError } from "@deepseek-ai/dsh-subagent";
|
|
2
2
|
import { scopeLifetime } from "./delivery-authority.js";
|
|
3
|
+
import { isManagedCancellation } from "./agent-registry.js";
|
|
3
4
|
// Cancellation provenance belongs to each holder, not to a rejection's error code.
|
|
4
5
|
const cancelledDrains = new WeakSet();
|
|
5
6
|
function deferred() {
|
|
@@ -15,6 +16,9 @@ function terminalError(result) {
|
|
|
15
16
|
const partial = result.output.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
16
17
|
return new SubagentError(`subagent ${result.stopReason}${result.diagnostic === undefined ? "" : `: ${result.diagnostic}`}${partial === "" ? "" : `\nPartial output: ${partial}`}`, result.stopReason.toUpperCase());
|
|
17
18
|
}
|
|
19
|
+
function outcomeFailure(error) {
|
|
20
|
+
return error instanceof AggregateError ? [String(error), ...error.errors.map(outcomeFailure)].join("; ") : String(error);
|
|
21
|
+
}
|
|
18
22
|
/** One foreground call's real native run and its revocable caller-cancel relay. */
|
|
19
23
|
export class RoleRunHolder {
|
|
20
24
|
controller = new AbortController();
|
|
@@ -25,6 +29,7 @@ export class RoleRunHolder {
|
|
|
25
29
|
identity;
|
|
26
30
|
receipt;
|
|
27
31
|
outcome;
|
|
32
|
+
disposeActivation;
|
|
28
33
|
terminal = false;
|
|
29
34
|
finished = false;
|
|
30
35
|
registering = false;
|
|
@@ -72,6 +77,7 @@ export class RoleRunHolder {
|
|
|
72
77
|
if (!this.terminal)
|
|
73
78
|
this.currentState = "cancelled";
|
|
74
79
|
this.controller.abort(reason);
|
|
80
|
+
void this.disposeActivation?.().catch(() => { });
|
|
75
81
|
}
|
|
76
82
|
background(request) {
|
|
77
83
|
this.assertAddress(request);
|
|
@@ -145,9 +151,9 @@ export class RoleRunHolder {
|
|
|
145
151
|
}
|
|
146
152
|
const run = await this.request.start(this.controller.signal);
|
|
147
153
|
this.identity = Object.freeze({ parent: this.request.parent, owner: this.request.owner,
|
|
148
|
-
sessionId: this.request.sessionId, toolCallId: this.request.toolCallId, runId: run.
|
|
154
|
+
sessionId: this.request.sessionId, toolCallId: this.request.toolCallId, runId: run.childId,
|
|
149
155
|
admissionEpoch: this.request.admissionEpoch, capture: this.request.capture, projection: this.request.projection,
|
|
150
|
-
mode: "one-shot",
|
|
156
|
+
mode: "one-shot", childId: run.childId });
|
|
151
157
|
if (!this.controller.signal.aborted)
|
|
152
158
|
this.currentState = "running";
|
|
153
159
|
let execution;
|
|
@@ -164,17 +170,40 @@ export class RoleRunHolder {
|
|
|
164
170
|
throw reason;
|
|
165
171
|
});
|
|
166
172
|
let disposed;
|
|
167
|
-
const dispose = () =>
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
173
|
+
const dispose = () => {
|
|
174
|
+
if (disposed !== undefined)
|
|
175
|
+
return disposed;
|
|
176
|
+
try {
|
|
177
|
+
disposed = this.collaborators.teardown.disposeRun(run);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
disposed = Promise.reject(error);
|
|
181
|
+
}
|
|
182
|
+
return disposed = disposed.then(() => { disposal = { status: "fulfilled", value: undefined }; }, (reason) => {
|
|
183
|
+
disposal = { status: "rejected", reason };
|
|
184
|
+
throw reason;
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
this.disposeActivation = dispose;
|
|
188
|
+
if (this.controller.signal.aborted)
|
|
189
|
+
void dispose().catch(() => { });
|
|
190
|
+
const settlement = (async () => {
|
|
191
|
+
await Promise.allSettled([result]);
|
|
192
|
+
await Promise.allSettled([dispose()]);
|
|
193
|
+
})();
|
|
194
|
+
this.outcome = settlement.then(() => {
|
|
195
|
+
const value = execution.status === "fulfilled" ? execution.value : undefined;
|
|
196
|
+
const failures = [execution, disposal].flatMap(result => result.status === "rejected" ? [outcomeFailure(result.reason)] : []);
|
|
197
|
+
return { status: disposal.status === "rejected" || execution.status === "rejected" ? "failed"
|
|
198
|
+
: value?.stopReason === "aborted" ? "killed" : value?.stopReason === "completed" ? "completed" : "failed",
|
|
199
|
+
...(value === undefined ? {} : { result: value.output.filter(block => block.type === "text").map(block => block.text).join("") }),
|
|
200
|
+
detail: failures.length ? failures.join("; ") : value?.diagnostic ?? value?.stopReason };
|
|
174
201
|
});
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
202
|
+
if (this.controller.signal.aborted)
|
|
203
|
+
this.readyResult.reject(this.controller.signal.reason);
|
|
204
|
+
else
|
|
205
|
+
this.readyResult.resolve(this.identity);
|
|
206
|
+
await settlement;
|
|
178
207
|
const failure = execution.status === "rejected" ? execution.reason : terminalError(execution.value);
|
|
179
208
|
const failed = execution.status === "rejected" || failure !== undefined;
|
|
180
209
|
if (execution.status === "fulfilled" && execution.value.stopReason === "aborted" && disposal.status === "fulfilled") {
|
|
@@ -188,10 +217,12 @@ export class RoleRunHolder {
|
|
|
188
217
|
throw failure;
|
|
189
218
|
if (disposal.status === "rejected")
|
|
190
219
|
throw disposal.reason;
|
|
191
|
-
this.foregroundResult.resolve({ kind: "foreground", runId: run.
|
|
220
|
+
this.foregroundResult.resolve({ kind: "foreground", runId: run.childId, invocation: this.identity, output: execution.value.output });
|
|
192
221
|
this.drainedResult.resolve();
|
|
193
222
|
}
|
|
194
223
|
catch (error) {
|
|
224
|
+
if (isManagedCancellation(error))
|
|
225
|
+
cancelledDrains.add(this.drained);
|
|
195
226
|
this.observed(this.controller.signal.aborted);
|
|
196
227
|
this.readyResult.reject(error);
|
|
197
228
|
this.foregroundResult.reject(error);
|
package/lib/role-subagents.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
5
5
|
import { SubagentError } from "@deepseek-ai/dsh-subagent";
|
|
6
|
+
import { PERSONA_PREFIX_SECTION } from "@deepseek-ai/dsh-persona";
|
|
6
7
|
import { DSMM_ROLES } from "./roles.js";
|
|
7
8
|
import { isDsmmRoleId } from "./roles.js";
|
|
8
9
|
import { DsmmRolePolicy, roleToolName } from "./role-policy.js";
|
|
@@ -12,6 +13,7 @@ import { childOwnedSessionEvents } from "./session-scope.js";
|
|
|
12
13
|
import { agentForScope, nativeAgentContext, scopeParentOf } from "./native-scope.js";
|
|
13
14
|
import { roleRouteRuntimeState } from "./role-routing.js";
|
|
14
15
|
import { modelRouteFromCall } from "./role-llm.js";
|
|
16
|
+
import { duringActivationOwnership } from "./agent-registry.js";
|
|
15
17
|
const hostControls = ["send_message", "interrupt_agent", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"];
|
|
16
18
|
// Agent-owned policy realms survive a bundle reinstall; do not register another
|
|
17
19
|
// identity prompt/tools layer on the same retained live Agent.
|
|
@@ -149,7 +151,7 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ro
|
|
|
149
151
|
const invocation = await resolveRoleInvocation(parent, role.id, current, exec.signal, { ...(args.level === undefined ? {} : { level: args.level }), ...(args.route === undefined ? {} : { route: args.route }) });
|
|
150
152
|
const capturedProvider = provider;
|
|
151
153
|
const request = { parent, label: args.description, prompt: [{ type: "text", text: args.prompt }],
|
|
152
|
-
|
|
154
|
+
agentOptions: invocationAgentOptions(invocation), maxDepth: subagents.resolveMaxDepth(current.subagents.maxDepth) };
|
|
153
155
|
const assertCurrent = () => {
|
|
154
156
|
if (policy.assertDelegation(parent, role.id).epoch !== admitted.epoch)
|
|
155
157
|
throw new SubagentError("DSMM parent admission changed before delegation", "UNAUTHORIZED");
|
|
@@ -162,8 +164,8 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ro
|
|
|
162
164
|
if (provider.prepareContinuable === undefined)
|
|
163
165
|
throw new SubagentError("DSMM provider has no prepareContinuable capability", "UNSUPPORTED_CAPABILITY");
|
|
164
166
|
assertCurrent();
|
|
165
|
-
const child = await duringRoleInvocation(agent, invocation, () => policy.duringDelegation(parent, role.id, () => subagents.
|
|
166
|
-
request, signal: exec.signal }),
|
|
167
|
+
const child = await duringRoleInvocation(agent, invocation, () => policy.duringDelegation(parent, role.id, () => subagents.startActivation({ provider: provider.name, label: args.description,
|
|
168
|
+
request, signal: exec.signal, delivery: "parent" }), undefined, request.maxDepth));
|
|
167
169
|
return { kind: "continuable", subagentId: child.childId, invocation: { ...invocationView(invocation, args.description, "continuable", { childId: child.childId }) } };
|
|
168
170
|
}
|
|
169
171
|
assertCurrent();
|
|
@@ -183,9 +185,8 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ro
|
|
|
183
185
|
admissionEpoch: admitted.epoch, capture: Object.freeze({ invocation, admission }), projection, label: args.description, callerAbort: exec.signal, jobs,
|
|
184
186
|
async start(signal) {
|
|
185
187
|
assertCurrent();
|
|
186
|
-
const run = await duringRoleInvocation(agent, invocation, () => policy.duringDelegation(agent, role.id, () => subagents.
|
|
187
|
-
projection.runId = run.
|
|
188
|
-
child ??= run.localAgent;
|
|
188
|
+
const run = await duringRoleInvocation(agent, invocation, () => policy.duringDelegation(agent, role.id, () => duringActivationOwnership(signal, () => subagents.startActivation({ provider: provider.name, label: args.description, request, signal, delivery: "caller" })), undefined, request.maxDepth, agent => { child = agent; }));
|
|
189
|
+
projection.runId = run.childId;
|
|
189
190
|
if (child?.id !== undefined)
|
|
190
191
|
projection.childId = child.id;
|
|
191
192
|
return run;
|
|
@@ -232,6 +233,14 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
|
|
|
232
233
|
if (tools === undefined)
|
|
233
234
|
throw new Error("DSMM role tools require native guard/restrict services");
|
|
234
235
|
const settings = getSettings(agent), identity = policy.identity(agent), targets = policy.targets(agent);
|
|
236
|
+
const personaRole = identity.child ? identity.role : undefined;
|
|
237
|
+
if (state.personaRole !== personaRole) {
|
|
238
|
+
state.persona?.();
|
|
239
|
+
const prompt = agentCtx.get("systemPrompt");
|
|
240
|
+
state.persona = personaRole === undefined ? undefined : prompt.section({ name: PERSONA_PREFIX_SECTION,
|
|
241
|
+
order: prompt.getSectionOrder("DEPLOYMENT_PERSONA_PREFIX"), text: DSMM_ROLES.find(role => role.id === personaRole).persona });
|
|
242
|
+
state.personaRole = personaRole;
|
|
243
|
+
}
|
|
235
244
|
const subagents = agentCtx.get("subagents");
|
|
236
245
|
const host = ctx.get?.("tools");
|
|
237
246
|
const names = [...hostControls, ...host?.schemas().map((row) => row.name).filter((name) => name.startsWith(`mcp__${settings.lsp.serverName}__`)) ?? []];
|
|
@@ -287,6 +296,7 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
|
|
|
287
296
|
const state = states.get(agent);
|
|
288
297
|
state?.restriction?.();
|
|
289
298
|
state?.guard?.();
|
|
299
|
+
state?.persona?.();
|
|
290
300
|
for (const dispose of state?.owned ?? [])
|
|
291
301
|
dispose();
|
|
292
302
|
states.delete(agent);
|
|
@@ -5,8 +5,6 @@ import { SubagentRuntime } from "@deepseek-ai/dsh-subagent";
|
|
|
5
5
|
import type { ChildAdmissionCompletion } from "./child-admission-contract.js";
|
|
6
6
|
import type { ChildAdmissionEvidence } from "./child-capture.js";
|
|
7
7
|
import type { DshAgent, DshContext } from "./dsh-types.js";
|
|
8
|
-
import type { LegacyCapabilityCollaborators } from "./legacy-child-policy.js";
|
|
9
|
-
import type { LegacyReadIntegrationChild, LegacyReadTrustedStartup } from "./legacy-read-integration.js";
|
|
10
8
|
import type { DsmmProfileRuntime } from "./profile-runtime.js";
|
|
11
9
|
import type { DsmmInvocationView, SubagentRuntimeAdmissionView } from "./profile-types.js";
|
|
12
10
|
import type { DsmmRolePolicy } from "./role-policy.js";
|
|
@@ -22,17 +20,10 @@ export declare function managedAgentContext(ctx: Context, controlledParent: (age
|
|
|
22
20
|
export declare function admittedAgentContext(ctx: DshContext, runtime: DsmmProfileRuntime): DshContext;
|
|
23
21
|
export declare function runtimeAdmissionView(ctx: Context): SubagentRuntimeAdmissionView;
|
|
24
22
|
/** Capability projection only. Admission objects and A's CAS/maintenance methods remain untouched. */
|
|
25
|
-
export declare function publicProfileRuntime(runtime: DsmmProfileRuntime, ctx: Context
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export interface DsmmHostStartupOptions {
|
|
30
|
-
/** Experimental, cold-only read composition. Disabled in the default MAIN. */
|
|
31
|
-
readonly experimentalLegacyRead?: {
|
|
32
|
-
readonly startup: LegacyReadTrustedStartup;
|
|
33
|
-
readonly classifyChildReport?: LegacyCapabilityCollaborators["classifyTool"];
|
|
34
|
-
};
|
|
35
|
-
}
|
|
23
|
+
export declare function publicProfileRuntime(runtime: DsmmProfileRuntime, ctx: Context): DsmmProfileRuntime;
|
|
24
|
+
/** No optional compatibility composition is supported by the current Host. */
|
|
25
|
+
export type DsmmHostStartupOptions = Readonly<Record<string, never>>;
|
|
26
|
+
export declare function assertSupportedHostStartup(startup: DsmmHostStartupOptions): void;
|
|
36
27
|
interface NativeDeliveryEvidence {
|
|
37
28
|
readonly parent: Agent;
|
|
38
29
|
readonly childId: SessionId;
|
|
@@ -56,29 +47,7 @@ export declare function integrateSubagentRuntime(ctx: Context, settings: DsmmSet
|
|
|
56
47
|
owner: object;
|
|
57
48
|
registry: RoleRunRegistry<DsmmRoleRunCapture, DsmmInvocationView>;
|
|
58
49
|
runtime: DsmmSubagentRuntime<DsmmProfileAdmission, ChildAdmissionEvidence | NativeDeliveryEvidence>;
|
|
59
|
-
legacyRead: {
|
|
60
|
-
core: import("./legacy-read-integration.js").LegacyReadCoreConsumption | undefined;
|
|
61
|
-
host: {
|
|
62
|
-
composition: import("./legacy-read-composition.js").LegacyReadComposition;
|
|
63
|
-
attachChild(parent: Agent, child: Agent, evidence: import("./child-capture.js").LegacyChildEvidence, definition: import("@deepseek-ai/dsh-tools").ToolDefinition): import("./legacy-read-proxy.js").LegacyReadProxy;
|
|
64
|
-
releaseAfterChildDispose(child: Agent): Promise<void>;
|
|
65
|
-
publishCheckedGeneration(): void;
|
|
66
|
-
dispose(nativeDrain: () => Promise<void>): Promise<void>;
|
|
67
|
-
};
|
|
68
|
-
legacyCapabilities: LegacyCapabilityCollaborators;
|
|
69
|
-
classifyLegacyTool: (name: string, tools: import("@deepseek-ai/dsh-tools").ToolRuntime, child: Agent) => import("./legacy-child-policy.js").LegacyToolCapability | undefined;
|
|
70
|
-
view(): import("./legacy-read-integration.js").LegacyReadIntegrationView;
|
|
71
|
-
attachChild(parent: Agent, child: Agent, signal: AbortSignal): Promise<LegacyReadIntegrationChild>;
|
|
72
|
-
publishCheckedGeneration(): void;
|
|
73
|
-
change(reason: string, mutate: () => void | Promise<void>): Promise<void>;
|
|
74
|
-
removeProxy(child: Agent): Promise<void>;
|
|
75
|
-
revokeChildBeforeDispose(child: Agent, nativeDispose: () => void | Promise<void>): Promise<void>;
|
|
76
|
-
whenChildRetired(child: Agent): Promise<void>;
|
|
77
|
-
dispose(nativeDrain: () => Promise<void>): Promise<void>;
|
|
78
|
-
} | undefined;
|
|
79
50
|
admitLlmRequest(agent: Agent, signal: AbortSignal): Promise<import("./host-llm.js").DsmmLlmAdmission | undefined>;
|
|
80
|
-
afterChildAdmission(agent: Agent, signal?: AbortSignal): Promise<void>;
|
|
81
|
-
changeConfiguration(reason: string, mutate: () => void | Promise<void>): Promise<void>;
|
|
82
51
|
dispose(nativeDrain: () => Promise<void>): Promise<void>;
|
|
83
52
|
onAdmissionGuardsInstalled(): void;
|
|
84
53
|
continueStartup(complete: (signal: AbortSignal) => Promise<void>, callerSignal?: AbortSignal): Promise<void>;
|