@dsmm/dsmm 0.3.0 → 0.3.1
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 +26 -40
- package/cordis.patch.yml +0 -13
- package/docs/agent-presets.md +26 -14
- package/docs/compatibility.md +19 -73
- package/docs/deferred-native-approval-risk.md +8 -12
- package/docs/design.md +25 -254
- package/docs/lsp.md +2 -2
- package/docs/migration-from-ocmm.md +38 -51
- package/docs/model-routing.md +21 -21
- package/docs/native-permissions.md +17 -7
- package/docs/profiles.md +13 -9
- package/docs/releasing.md +34 -280
- package/docs/roadmap.md +23 -254
- package/docs/runtime-recovery.md +29 -91
- package/docs/safety-guards.md +19 -16
- package/docs/settings-status.md +23 -11
- package/docs/skill-sync.md +17 -17
- package/docs/web-fetch-fakeip.md +82 -0
- package/lib/child-capture.d.ts +12 -2
- package/lib/child-capture.js +22 -5
- package/lib/client/ChildrenPanel.d.ts +1 -4
- package/lib/client/ChildrenPanel.js +4 -16
- package/lib/client/DeploymentFields.d.ts +28 -0
- package/lib/client/DeploymentFields.js +68 -0
- package/lib/client/DeploymentPage.d.ts +17 -5
- package/lib/client/DeploymentPage.js +79 -112
- package/lib/client/NativeCommandEntries.d.ts +17 -0
- package/lib/client/NativeCommandEntries.js +68 -0
- package/lib/client/PermissionsPanel.d.ts +1 -1
- package/lib/client/PermissionsPanel.js +8 -8
- package/lib/client/ProfilesSection.js +7 -5
- package/lib/client/RoleToolView-data.d.ts +35 -0
- package/lib/client/RoleToolView-data.js +52 -0
- package/lib/client/RoleToolView-locales.d.ts +36 -0
- package/lib/client/RoleToolView-locales.js +20 -0
- package/lib/client/RoleToolView.d.ts +10 -0
- package/lib/client/RoleToolView.js +47 -0
- package/lib/client/SessionProfiles.js +39 -15
- package/lib/client/children-controller.d.ts +2 -8
- package/lib/client/children-controller.js +1 -26
- package/lib/client/children-locales.d.ts +27 -52
- package/lib/client/children-locales.js +8 -12
- package/lib/client/configuration-display.d.ts +5 -0
- package/lib/client/configuration-display.js +11 -0
- package/lib/client/controller.d.ts +1 -0
- package/lib/client/controller.js +20 -13
- package/lib/client/deployment-controller.d.ts +13 -1
- package/lib/client/deployment-controller.js +84 -24
- package/lib/client/deployment-data.d.ts +1 -0
- package/lib/client/deployment-data.js +4 -1
- package/lib/client/deployment-locales.d.ts +43 -0
- package/lib/client/deployment-locales.js +35 -9
- package/lib/client/deployment-modules.d.ts +9 -0
- package/lib/client/deployment-modules.js +24 -0
- package/lib/client/deployment-workspace.d.ts +48 -0
- package/lib/client/deployment-workspace.js +123 -0
- package/lib/client/index.js +11 -74
- package/lib/client/locales.d.ts +7 -0
- package/lib/client/locales.js +12 -6
- package/lib/client/permission-controller.d.ts +1 -0
- package/lib/client/permission-controller.js +3 -2
- package/lib/client/permission-locales.d.ts +25 -0
- package/lib/client/permission-locales.js +24 -4
- package/lib/client/session-labels.js +4 -3
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +9 -8
- package/lib/client.js +2713 -2361
- package/lib/commands.js +2 -0
- package/lib/config-file-store.d.ts +3 -0
- package/lib/config-file-store.js +4 -2
- package/lib/config-revision.d.ts +5 -0
- package/lib/config-revision.js +11 -0
- package/lib/core-permission-authority.js +11 -41
- package/lib/deployment-config.d.ts +9 -2
- package/lib/deployment-config.js +35 -8
- package/lib/deployment-permission-rules.js +19 -7
- package/lib/dsh-types.d.ts +1 -1
- package/lib/host-llm-startup.js +3 -3
- package/lib/host-llm.d.ts +9 -3
- package/lib/host-llm.js +48 -8
- package/lib/index.d.ts +16 -20
- package/lib/index.js +130 -416
- package/lib/lifetime.d.ts +4 -0
- package/lib/lifetime.js +22 -0
- package/lib/live-pi-ai-owner.d.ts +1 -0
- package/lib/live-pi-ai-owner.js +8 -4
- package/lib/mode.d.ts +3 -2
- package/lib/mode.js +28 -41
- package/lib/model-routing.d.ts +2 -8
- package/lib/model-routing.js +59 -175
- package/lib/native-admission.d.ts +56 -0
- package/lib/native-admission.js +313 -0
- package/lib/native-pi-ai-wire.d.ts +3 -1
- package/lib/native-pi-ai-wire.js +47 -13
- package/lib/permission-control.d.ts +0 -3
- package/lib/preset-registry.js +3 -2
- package/lib/preset-skills.d.ts +3 -12
- package/lib/preset-skills.js +28 -58
- package/lib/profile-diagnostics.d.ts +1 -1
- package/lib/profile-diagnostics.js +2 -2
- package/lib/profile-remote.js +61 -22
- package/lib/profile-rpc.d.ts +4 -3
- package/lib/profile-rpc.js +33 -37
- package/lib/profile-runtime.d.ts +31 -74
- package/lib/profile-runtime.js +224 -639
- package/lib/profile-store.d.ts +18 -6
- package/lib/profile-store.js +104 -62
- package/lib/profile-types.d.ts +18 -4
- package/lib/profiles.d.ts +3 -1
- package/lib/profiles.js +9 -7
- package/lib/prompt-content.d.ts +1 -0
- package/lib/prompt-content.js +4 -1
- package/lib/prompts.d.ts +2 -12
- package/lib/prompts.js +11 -66
- package/lib/role-control-remote.d.ts +1 -4
- package/lib/role-control-remote.js +8 -36
- package/lib/role-control-rpc.d.ts +10 -36
- package/lib/role-control-rpc.js +112 -269
- package/lib/role-control-types.d.ts +3 -26
- package/lib/role-control-types.js +3 -4
- package/lib/role-identity.d.ts +5 -0
- package/lib/role-identity.js +10 -0
- package/lib/role-invocation.d.ts +2 -2
- package/lib/role-llm-runtime.js +5 -11
- package/lib/role-policy.d.ts +19 -50
- package/lib/role-policy.js +136 -508
- package/lib/role-providers.d.ts +5 -8
- package/lib/role-providers.js +20 -86
- package/lib/role-routing.d.ts +1 -3
- package/lib/role-routing.js +24 -34
- package/lib/role-subagents.d.ts +5 -14
- package/lib/role-subagents.js +148 -106
- package/lib/runtime-integration.d.ts +5 -78
- package/lib/runtime-integration.js +11 -697
- package/lib/session-metadata.d.ts +13 -12
- package/lib/session-metadata.js +6 -31
- package/lib/session-scope.js +2 -1
- package/lib/settings.d.ts +5 -18
- package/lib/settings.js +19 -43
- package/lib/state.d.ts +3 -2
- package/lib/state.js +26 -10
- package/lib/status.d.ts +1 -9
- package/lib/status.js +3 -55
- package/lib/web-fetch-address-policy.d.ts +24 -0
- package/lib/web-fetch-address-policy.js +189 -0
- package/lib/web-fetch-fakeip.d.ts +25 -0
- package/lib/web-fetch-fakeip.js +107 -0
- package/package.json +113 -103
- package/docs/research/deepseek-v4-pro.md +0 -74
- package/docs/research/oh-dsh.md +0 -96
- package/lib/agent-registry.d.ts +0 -36
- package/lib/agent-registry.js +0 -75
- package/lib/child-admission.d.ts +0 -40
- package/lib/child-admission.js +0 -151
- package/lib/delivery-authority.d.ts +0 -83
- package/lib/delivery-authority.js +0 -397
- package/lib/native-child-evidence.d.ts +0 -40
- package/lib/native-child-evidence.js +0 -104
- package/lib/role-runs.d.ts +0 -138
- package/lib/role-runs.js +0 -335
- package/lib/session-persistence.d.ts +0 -36
- package/lib/session-persistence.js +0 -304
- package/lib/subagent-runtime.d.ts +0 -57
- package/lib/subagent-runtime.js +0 -257
- package/prompts/deepseek-flash.md +0 -11
- package/prompts/deepseek-v4-pro.md +0 -14
package/lib/role-subagents.js
CHANGED
|
@@ -3,21 +3,21 @@ 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";
|
|
7
6
|
import { DSMM_ROLES } from "./roles.js";
|
|
7
|
+
import { registerRoleHarnessIdentity } from "./role-identity.js";
|
|
8
8
|
import { isDsmmRoleId } from "./roles.js";
|
|
9
9
|
import { DsmmRolePolicy, roleToolName } from "./role-policy.js";
|
|
10
10
|
import { roleProviderName } from "./role-providers.js";
|
|
11
|
-
import {
|
|
11
|
+
import { capturedRoleInvocation, invocationAgentOptions, invocationView, resolveRoleInvocation } from "./role-invocation.js";
|
|
12
12
|
import { childOwnedSessionEvents } from "./session-scope.js";
|
|
13
13
|
import { agentForScope, nativeAgentContext, scopeParentOf } from "./native-scope.js";
|
|
14
14
|
import { roleRouteRuntimeState } from "./role-routing.js";
|
|
15
15
|
import { modelRouteFromCall } from "./role-llm.js";
|
|
16
|
-
import {
|
|
16
|
+
import { buildDsmmAgentGuidance, buildDsmmLocaleGuidance } from "./prompts.js";
|
|
17
17
|
const hostControls = ["send_message", "interrupt_agent", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"];
|
|
18
18
|
// Agent-owned policy realms survive a bundle reinstall; do not register another
|
|
19
19
|
// identity prompt/tools layer on the same retained live Agent.
|
|
20
|
-
const admittedRealms = new
|
|
20
|
+
const admittedRealms = new WeakMap();
|
|
21
21
|
const callableDefinitions = new WeakMap();
|
|
22
22
|
/** Keep native controls on the frozen startup substrate, not desired-save reconciliation. */
|
|
23
23
|
export async function registerNativeSubagentControls(ctx) {
|
|
@@ -37,11 +37,11 @@ export async function registerNativeSubagentControls(ctx) {
|
|
|
37
37
|
ctx.logger.warn("DSMM native subagent controls unavailable; continuable control requires the installed host substrate");
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
/**
|
|
40
|
+
/** Project the captured invocation without reapplying deployment defaults. */
|
|
41
41
|
export function roleInvocationView(invocation, label, mode, getSettings, child, ids = {}) {
|
|
42
42
|
return roleInvocationObservation(invocation, label, mode, getSettings, child, ids).view;
|
|
43
43
|
}
|
|
44
|
-
/**
|
|
44
|
+
/** Distinguish the captured route from an observed native request. */
|
|
45
45
|
export function roleInvocationObservation(invocation, label, mode, getSettings, child, ids = {}) {
|
|
46
46
|
const view = invocationView(invocation, label, mode, ids);
|
|
47
47
|
if (child === undefined)
|
|
@@ -75,10 +75,38 @@ function latestOwnRoleRoute(child) {
|
|
|
75
75
|
/** Both observations belong to this exact native Agent; no parent/settings/route-lock fallback. */
|
|
76
76
|
export function roleRouteComparison(child) {
|
|
77
77
|
const agent = child;
|
|
78
|
-
const invocation =
|
|
78
|
+
const invocation = capturedRoleInvocation(agent);
|
|
79
79
|
return { childId: child.id, initialRoute: invocation === undefined ? { status: "unknown", reason: "missing-invocation-capture" }
|
|
80
80
|
: { status: "known", source: "invocation-capture", route: Object.freeze({ ...invocation.initialRoute }) }, liveRoute: latestOwnRoleRoute(agent) };
|
|
81
81
|
}
|
|
82
|
+
function presentationFields(value) {
|
|
83
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
|
|
84
|
+
}
|
|
85
|
+
function roleTitle(role) {
|
|
86
|
+
return `${role.kind === "category" ? "Category" : "Role"}: ${role.name} (${role.id})`;
|
|
87
|
+
}
|
|
88
|
+
/** Presenters accept streaming/replayed input independently of strict execution validation. */
|
|
89
|
+
function installRolePresenters(definition, entry) {
|
|
90
|
+
const presentCall = args => {
|
|
91
|
+
const fields = presentationFields(args);
|
|
92
|
+
const target = entry.targetParameter === undefined ? entry.targets[0] : fields?.[entry.targetParameter];
|
|
93
|
+
const role = isDsmmRoleId(target) && entry.targets.includes(target) ? DSMM_ROLES.find(row => row.id === target && row.kind === entry.kind) : undefined;
|
|
94
|
+
return { card: "generic", title: role === undefined ? `Requested ${entry.kind}` : `Requested ${roleTitle(role)}`,
|
|
95
|
+
...(typeof fields?.description === "string" ? { rawInput: fields.description } : {}) };
|
|
96
|
+
};
|
|
97
|
+
// defineTool soft-validates complete args before its own presenter wrappers;
|
|
98
|
+
// the native definition's presenters also serve partial streams and old logs.
|
|
99
|
+
definition.presentCall = presentCall;
|
|
100
|
+
definition.presentResult = (args, result) => {
|
|
101
|
+
const meta = result.isError ? undefined : presentationFields(result.meta);
|
|
102
|
+
const role = meta === undefined ? undefined : DSMM_ROLES.find(row => row.id === meta.role && row.kind === entry.kind);
|
|
103
|
+
if (role !== undefined && typeof meta?.label === "string" && ["normal", "low", "high", "max"].includes(meta.level)
|
|
104
|
+
&& (meta.mode === "one-shot" || meta.mode === "continuable") && ["inherited", "primary", "level", "invocation-route"].includes(meta.routeSource)) {
|
|
105
|
+
return { card: "generic", title: `${roleTitle(role)} · ${meta.level}` };
|
|
106
|
+
}
|
|
107
|
+
return { card: "generic", title: presentCall(args).title };
|
|
108
|
+
};
|
|
109
|
+
}
|
|
82
110
|
/** Shared by runtime registration and the prompt assembler; empty groups have no callable entry. */
|
|
83
111
|
export function callableRoleInventory(settings, targets) {
|
|
84
112
|
const admitted = targets.filter(id => id !== "dsmm-orchestrator" && settings.roles[id]);
|
|
@@ -103,16 +131,16 @@ export function admittedCallableRoleInventory(agent, settings, policy, tools) {
|
|
|
103
131
|
return targets.length === 0 ? [] : [{ ...registered.entry, targets }];
|
|
104
132
|
});
|
|
105
133
|
}
|
|
106
|
-
function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy,
|
|
134
|
+
function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, admission) {
|
|
107
135
|
const settings = getSettings(agent);
|
|
108
136
|
const subagents = agentCtx.get("subagents");
|
|
109
137
|
if (subagents === undefined)
|
|
110
138
|
throw new Error("DSMM role tools require native subagents");
|
|
111
139
|
const background = settings.subagents.enableRunInBackground;
|
|
112
|
-
const continuable = settings.subagents.backgroundMode === "continuable";
|
|
113
140
|
const admittedProviders = new Map(entry.targets.map(target => [target, subagents.getProvider(roleProviderName(target))]));
|
|
141
|
+
const incomplete = new Map();
|
|
114
142
|
const definition = defineTool({
|
|
115
|
-
name: entry.name, description: `Delegate a bounded ${entry.kind} task through
|
|
143
|
+
name: entry.name, description: `Delegate a bounded ${entry.kind} task through native activation. Waits for the useful result by default.${background ? " Set run_in_background to receive an accepted child/message receipt; native completion notifies the parent." : " Background execution is disabled."}`,
|
|
116
144
|
parameters: { description: { type: "string", required: true }, prompt: { type: "string", required: true },
|
|
117
145
|
...(entry.targetParameter === undefined ? {} : { [entry.targetParameter]: { type: "string", enum: entry.targets, required: true } }),
|
|
118
146
|
level: { type: "string", enum: ["normal", "low", "high", "max"] },
|
|
@@ -127,8 +155,16 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ro
|
|
|
127
155
|
const route = invocation?.route;
|
|
128
156
|
const metadata = invocation === undefined ? "" : `${invocation.role} level=${invocation.level}${route === undefined ? "" : ` route=${route.provider}/${route.model}${route.reasoningEffort === undefined ? "" : ` effort=${route.reasoningEffort}`}`}`;
|
|
129
157
|
return result.kind === "foreground" ? [{ type: "text", text: metadata }, ...result.output ?? []]
|
|
130
|
-
: [{ type: "text", text: `${metadata}\
|
|
158
|
+
: [{ type: "text", text: `${metadata}\naccepted subagent ${result.subagentId}` }];
|
|
131
159
|
}, presentationMeta(_args, value) { return typeof value === "object" && value !== null && !Array.isArray(value) ? value.invocation ?? null : null; } },
|
|
160
|
+
finalizeContent(exec, result) {
|
|
161
|
+
const partial = incomplete.get(exec.token);
|
|
162
|
+
incomplete.delete(exec.token);
|
|
163
|
+
if (!partial || !result.isError || !["DSMM_INCOMPLETE", "ABORTED"].includes(result.error.info?.code ?? ""))
|
|
164
|
+
return;
|
|
165
|
+
return [...result.content, { type: "text", text: `Child outcome: ${partial.stopReason}. The following assistant output is partial, not a completed result.` }, ...partial.output,
|
|
166
|
+
...partial.diagnostic === undefined ? [] : [{ type: "text", text: `Provider diagnostic: ${partial.diagnostic}` }]];
|
|
167
|
+
},
|
|
132
168
|
async execute(args, exec) {
|
|
133
169
|
const fields = ["description", "prompt", "level", ...entry.targetParameter === undefined ? [] : [entry.targetParameter],
|
|
134
170
|
...settings.subagents.allowRouteOverride ? ["route"] : [], ...background ? ["run_in_background"] : []];
|
|
@@ -137,93 +173,91 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ro
|
|
|
137
173
|
const parent = exec.agent;
|
|
138
174
|
if (parent === undefined)
|
|
139
175
|
throw new SubagentError("DSMM delegation requires a calling Agent", "UNAUTHORIZED");
|
|
140
|
-
if (parent !== agent || tools.get(entry.name, parent)
|
|
176
|
+
if (parent !== agent || tools.get(entry.name, parent) !== definition || policy.toolDenial(agent, entry.name, tools) !== undefined)
|
|
141
177
|
throw new SubagentError("DSMM tool is not the exact admitted caller definition", "UNAUTHORIZED");
|
|
142
178
|
const target = entry.targetParameter === undefined ? entry.targets[0] : exec.arguments[entry.targetParameter];
|
|
143
179
|
if (!isDsmmRoleId(target) || !entry.targets.includes(target) || DSMM_ROLES.find(row => row.id === target).kind !== entry.kind)
|
|
144
180
|
throw new SubagentError("DSMM target is unknown, cross-kind or not admitted", "UNAUTHORIZED");
|
|
145
181
|
const role = DSMM_ROLES.find(row => row.id === target);
|
|
182
|
+
const label = `${role.id.slice("dsmm-".length).split("-").map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(" ")}: ${args.description}`;
|
|
146
183
|
const admitted = policy.assertDelegation(parent, role.id);
|
|
147
184
|
const current = getSettings(parent);
|
|
148
185
|
const provider = subagents.getProvider(roleProviderName(role.id));
|
|
149
186
|
if (provider === undefined || provider !== admittedProviders.get(role.id))
|
|
150
187
|
throw new SubagentError("DSMM exact admitted role provider is unavailable", "NO_PROVIDER");
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (provider.prepareContinuable === undefined)
|
|
165
|
-
throw new SubagentError("DSMM provider has no prepareContinuable capability", "UNSUPPORTED_CAPABILITY");
|
|
188
|
+
return admission.duringCall(parent, exec.signal, async (signal) => {
|
|
189
|
+
const invocation = await resolveRoleInvocation(parent, role.id, current, signal, { ...(args.level === undefined ? {} : { level: args.level }), ...(args.route === undefined ? {} : { route: args.route }) });
|
|
190
|
+
const capturedProvider = provider;
|
|
191
|
+
const request = { parent, agentPreset: role.id, prompt: [{ type: "text", text: args.prompt }],
|
|
192
|
+
agentOptions: invocationAgentOptions(invocation), maxDepth: subagents.resolveMaxDepth(current.subagents.maxDepth) };
|
|
193
|
+
const assertCurrent = () => {
|
|
194
|
+
if (policy.assertDelegation(parent, role.id).epoch !== admitted.epoch)
|
|
195
|
+
throw new SubagentError("DSMM parent admission changed before delegation", "UNAUTHORIZED");
|
|
196
|
+
if (subagents.getProvider(roleProviderName(role.id)) !== capturedProvider)
|
|
197
|
+
throw new SubagentError("DSMM exact provider changed before delegation", "NO_PROVIDER");
|
|
198
|
+
};
|
|
199
|
+
signal.throwIfAborted();
|
|
200
|
+
const requestedBackground = background && args.run_in_background === true;
|
|
166
201
|
assertCurrent();
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
throw new SubagentError("DSMM one-shot delegation requires the stable Host role-run registry", "UNSUPPORTED_CAPABILITY");
|
|
174
|
-
const admission = getSettings.admission?.(agent);
|
|
175
|
-
if (admission === undefined || admission.epoch !== admitted.epoch)
|
|
176
|
-
throw new SubagentError("DSMM one-shot capture requires the exact original parent admission", "UNAUTHORIZED");
|
|
177
|
-
const jobs = agentCtx.get("jobs");
|
|
178
|
-
if (requestedBackground && jobs === undefined)
|
|
179
|
-
throw new SubagentError("DSMM background jobs require the native jobs registry/controller", "UNSUPPORTED_CAPABILITY");
|
|
180
|
-
let child;
|
|
181
|
-
const projection = { ...invocationView(invocation, args.description, "one-shot"), get route() {
|
|
182
|
-
return roleInvocationView(invocation, args.description, "one-shot", getSettings, child).route;
|
|
202
|
+
const pending = await admission.reserve(exec, invocation, provider, request.maxDepth);
|
|
203
|
+
let activation;
|
|
204
|
+
let cancellation;
|
|
205
|
+
const cancel = () => { if (activation) {
|
|
206
|
+
cancellation ??= activation.dispose();
|
|
207
|
+
void cancellation.catch(() => { });
|
|
183
208
|
} };
|
|
184
|
-
const holder = roleRuns.registry.start({ parent, owner: roleRuns.owner, sessionId: parent.id, toolCallId: exec.callId,
|
|
185
|
-
admissionEpoch: admitted.epoch, capture: Object.freeze({ invocation, admission }), projection, label: args.description, callerAbort: exec.signal, jobs,
|
|
186
|
-
async start(signal) {
|
|
187
|
-
assertCurrent();
|
|
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;
|
|
190
|
-
if (child?.id !== undefined)
|
|
191
|
-
projection.childId = child.id;
|
|
192
|
-
return run;
|
|
193
|
-
} });
|
|
194
|
-
if (requestedBackground) {
|
|
195
209
|
try {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
|
|
210
|
+
activation = await subagents.startActivation({ childId: pending.childId, provider: provider.name, label, request, signal: pending.signal, delivery: requestedBackground ? "parent" : "caller" });
|
|
211
|
+
admission.track(activation);
|
|
212
|
+
pending.signal.addEventListener("abort", cancel, { once: true });
|
|
213
|
+
if (pending.signal.aborted) {
|
|
214
|
+
cancel();
|
|
215
|
+
await cancellation;
|
|
216
|
+
pending.signal.throwIfAborted();
|
|
217
|
+
}
|
|
218
|
+
const view = invocationView(invocation, args.description, "continuable", { childId: activation.childId });
|
|
219
|
+
if (requestedBackground)
|
|
220
|
+
return { kind: "continuable", subagentId: activation.childId, messageId: activation.messageId ?? null, invocation: { ...view } };
|
|
221
|
+
const result = await activation.result;
|
|
222
|
+
if (result.stopReason !== "completed")
|
|
223
|
+
incomplete.set(exec.token, result);
|
|
224
|
+
if (cancellation)
|
|
225
|
+
await cancellation;
|
|
226
|
+
pending.signal.throwIfAborted();
|
|
227
|
+
if (result.stopReason !== "completed")
|
|
228
|
+
throw new SubagentError(`Role activation ended: ${result.stopReason}`, "DSMM_INCOMPLETE");
|
|
229
|
+
return { kind: "foreground", output: result.output,
|
|
230
|
+
...(result.structured === undefined ? {} : { structured: result.structured }), invocation: { ...view } };
|
|
201
231
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (drain.status === "rejected" && drain.reason !== error)
|
|
206
|
-
throw new AggregateError([error, drain.reason], "DSMM background handoff was refused and its owned run drain rejected");
|
|
207
|
-
throw error;
|
|
232
|
+
finally {
|
|
233
|
+
pending.signal.removeEventListener("abort", cancel);
|
|
234
|
+
await pending.release();
|
|
208
235
|
}
|
|
209
|
-
}
|
|
210
|
-
const held = await holder.foreground;
|
|
211
|
-
if (held.kind === "background")
|
|
212
|
-
projection.jobId = held.jobId;
|
|
213
|
-
const { route, ...metadata } = projection;
|
|
214
|
-
const view = { ...metadata, ...(route === undefined ? {} : { route: { ...route } }) };
|
|
215
|
-
return held.kind === "foreground" ? { kind: held.kind, runId: held.runId, output: held.output, invocation: view }
|
|
216
|
-
: { kind: held.kind, runId: held.invocation.runId, jobId: held.jobId, invocation: view };
|
|
236
|
+
});
|
|
217
237
|
}
|
|
218
238
|
});
|
|
239
|
+
installRolePresenters(definition, entry);
|
|
219
240
|
callableDefinitions.set(definition, { entry: Object.freeze({ ...entry, targets: Object.freeze([...entry.targets]) }), providers: admittedProviders });
|
|
220
241
|
const dispose = tools.register(definition);
|
|
221
242
|
return () => { callableDefinitions.delete(definition); dispose(); };
|
|
222
243
|
}
|
|
223
244
|
/** Published name retained; all native/headless Agents consume one admitted policy. */
|
|
224
|
-
export async function registerHeadlessRoleTools(ctx, controller, getSettings, policy
|
|
245
|
+
export async function registerHeadlessRoleTools(ctx, controller, getSettings, policy, admission, onlyAgent) {
|
|
246
|
+
const refresh = admittedRealms.get(onlyAgent);
|
|
247
|
+
if (refresh) {
|
|
248
|
+
refresh();
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
225
251
|
const states = new WeakMap();
|
|
226
|
-
const
|
|
252
|
+
const reconcileIdentity = (agent, role = policy.identity(agent).role) => {
|
|
253
|
+
const state = states.get(agent);
|
|
254
|
+
if (state === undefined || state.identityRole === role)
|
|
255
|
+
return;
|
|
256
|
+
state.identityPrompt?.();
|
|
257
|
+
state.identityPrompt = role === undefined ? undefined : registerRoleHarnessIdentity(agent, role);
|
|
258
|
+
state.identityRole = role;
|
|
259
|
+
};
|
|
260
|
+
const reconcile = (agent) => {
|
|
227
261
|
const state = states.get(agent);
|
|
228
262
|
if (state === undefined)
|
|
229
263
|
return;
|
|
@@ -233,14 +267,28 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
|
|
|
233
267
|
if (tools === undefined)
|
|
234
268
|
throw new Error("DSMM role tools require native guard/restrict services");
|
|
235
269
|
const settings = getSettings(agent), identity = policy.identity(agent), targets = policy.targets(agent);
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
state.
|
|
241
|
-
|
|
242
|
-
state.
|
|
270
|
+
const prompt = agentCtx.get("agentPresets")?.serviceFor(agent, "systemPrompt") ?? agentCtx.get("systemPrompt");
|
|
271
|
+
const promptRealm = Reflect.get(prompt, symbols.original) ?? prompt;
|
|
272
|
+
if (state.promptRealm !== promptRealm) {
|
|
273
|
+
state.guidance?.();
|
|
274
|
+
state.identityPrompt?.();
|
|
275
|
+
state.identityRole = undefined;
|
|
276
|
+
state.guidance = getTraceable(agentCtx, prompt).section({ name: "dsmm:delegation-identity", order: 49, text(context) {
|
|
277
|
+
if (context.scope !== agent && agentForScope(ctx, context.scope) !== agent)
|
|
278
|
+
return "";
|
|
279
|
+
const identity = policy.identity(agent), tools = states.get(agent)?.tools, settings = getSettings(agent);
|
|
280
|
+
if (identity.role === undefined)
|
|
281
|
+
return settings.locale === undefined ? "" : buildDsmmLocaleGuidance(settings);
|
|
282
|
+
const captured = capturedRoleInvocation(agent);
|
|
283
|
+
return buildDsmmAgentGuidance(settings, { scope: identity.child ? "child" : "root", tools: tools?.schemas(agent) ?? [],
|
|
284
|
+
delegation: tools === undefined ? [] : admittedCallableRoleInventory(agent, settings, policy, tools),
|
|
285
|
+
...(captured === undefined ? {} : { invocation: roleInvocationObservation(captured, DSMM_ROLES.find(role => role.id === captured.target).name, "continuable", getSettings, agent, { childId: agent.id }) }),
|
|
286
|
+
runtimeAdmission: getSettings.subagentRuntime?.(), capabilities: { continuable: true, nativeChildDelivery: true,
|
|
287
|
+
...(agentCtx.get("dsmmChildren") === undefined ? {} : { nativeBrowserPrompt: { surface: "conversation.dsmm-children" } }) } });
|
|
288
|
+
} });
|
|
289
|
+
state.promptRealm = promptRealm;
|
|
243
290
|
}
|
|
291
|
+
reconcileIdentity(agent, identity.role);
|
|
244
292
|
const subagents = agentCtx.get("subagents");
|
|
245
293
|
const host = ctx.get?.("tools");
|
|
246
294
|
const names = [...hostControls, ...host?.schemas().map((row) => row.name).filter((name) => name.startsWith(`mcp__${settings.lsp.serverName}__`)) ?? []];
|
|
@@ -271,13 +319,13 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
|
|
|
271
319
|
}
|
|
272
320
|
const inventory = callableRoleInventory(settings, targets.filter(role => subagents?.getProvider(roleProviderName(role))?.capabilities.depthLimit === true));
|
|
273
321
|
for (const entry of inventory)
|
|
274
|
-
state.owned.push(registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy,
|
|
322
|
+
state.owned.push(registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, admission));
|
|
275
323
|
policy.captureTools(agent, tools, [...inventory.map(entry => entry.name), ...names], !sameRealm || !sameParent);
|
|
276
324
|
state.signature = signature;
|
|
277
325
|
state.hostDefinitions = definitions;
|
|
278
326
|
state.parentScope = parentScope;
|
|
279
327
|
};
|
|
280
|
-
const onCreated =
|
|
328
|
+
const onCreated = ({ agent }) => {
|
|
281
329
|
if (states.has(agent) || admittedRealms.has(agent))
|
|
282
330
|
return;
|
|
283
331
|
if (!getSettings(agent).modules.deepwork.enabled)
|
|
@@ -285,34 +333,28 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
|
|
|
285
333
|
const agentCtx = nativeAgentContext(agent);
|
|
286
334
|
policy.admit(agent);
|
|
287
335
|
states.set(agent, { owned: [], hostDefinitions: [] });
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const identity = policy.identity(agent);
|
|
291
|
-
const tools = states.get(agent)?.tools;
|
|
292
|
-
const inventory = tools === undefined ? [] : admittedCallableRoleInventory(agent, getSettings(agent), policy, tools);
|
|
293
|
-
return identity.role === undefined ? "" : `Native admitted role: ${identity.role}; ${identity.child ? "bounded child, not stage-owner" : "root"}. Admitted callable delegation: ${inventory.map(entry => `${entry.name}${entry.targetParameter === undefined ? "" : ` (${entry.targetParameter}: ${entry.targets.join(", ")})`}`).join("; ") || "none"}. level defaults to normal; low/high/max require this target's configured level. route is only available with admitted deployment opt-in. Role/host permissions remain in force when common is off. Read-only plans are complete Markdown for native review and authorized coordinator persistence, never planner writes.`;
|
|
294
|
-
} });
|
|
295
|
-
agentCtx.effect(() => () => {
|
|
336
|
+
const retire = () => {
|
|
337
|
+
stopIdentity();
|
|
296
338
|
const state = states.get(agent);
|
|
297
339
|
state?.restriction?.();
|
|
298
340
|
state?.guard?.();
|
|
299
|
-
state?.
|
|
341
|
+
state?.identityPrompt?.();
|
|
342
|
+
state?.guidance?.();
|
|
300
343
|
for (const dispose of state?.owned ?? [])
|
|
301
344
|
dispose();
|
|
302
345
|
states.delete(agent);
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
346
|
+
admittedRealms.delete(agent);
|
|
347
|
+
admission.lifetime.signal.removeEventListener("abort", retire);
|
|
348
|
+
};
|
|
349
|
+
admission.lifetime.signal.addEventListener("abort", retire, { once: true });
|
|
350
|
+
agentCtx.effect(() => retire);
|
|
351
|
+
reconcile(agent);
|
|
352
|
+
admittedRealms.set(agent, () => reconcile(agent));
|
|
307
353
|
};
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
return next();
|
|
314
|
-
}, { prepend: true, global: true });
|
|
315
|
-
for (const agent of ctx.get?.("agents")?.list() ?? [])
|
|
316
|
-
await onCreated({ agent });
|
|
354
|
+
// Native assembly collects sections before its waterfall. Admission/mode/preset
|
|
355
|
+
// changes must update the Agent layer before that collection begins.
|
|
356
|
+
const stopIdentity = controller.watch(agent => { if (agent === onlyAgent)
|
|
357
|
+
reconcile(agent); });
|
|
358
|
+
onCreated({ agent: onlyAgent });
|
|
317
359
|
}
|
|
318
360
|
//# sourceMappingURL=role-subagents.js.map
|
|
@@ -1,81 +1,8 @@
|
|
|
1
|
-
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
-
import type { Agent
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import type { ChildAdmissionEvidence } from "./child-capture.js";
|
|
7
|
-
import type { DshAgent, DshContext } from "./dsh-types.js";
|
|
8
|
-
import type { DsmmProfileRuntime } from "./profile-runtime.js";
|
|
9
|
-
import type { DsmmInvocationView, SubagentRuntimeAdmissionView } from "./profile-types.js";
|
|
10
|
-
import type { DsmmRolePolicy } from "./role-policy.js";
|
|
11
|
-
import { RoleRunRegistry } from "./role-runs.js";
|
|
12
|
-
import type { DsmmRoleRunCapture } from "./role-subagents.js";
|
|
13
|
-
import type { DsmmProfileAdmission, DsmmSettings, DsmmSettingsGetter } from "./settings.js";
|
|
14
|
-
import { DsmmSubagentRuntime } from "./subagent-runtime.js";
|
|
15
|
-
/** An unestablished child is never a native-identity proof for delivery or resumed work. */
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
import type { SubagentRuntimeAdmissionView } from "./profile-types.js";
|
|
4
|
+
export type DsmmHostStartupOptions = Readonly<Record<string, never>>;
|
|
5
|
+
export declare function assertSupportedHostStartup(options: DsmmHostStartupOptions): void;
|
|
16
6
|
export declare function classifyDsmmAgent(agent: Agent): "dsmm" | "native";
|
|
17
|
-
/** Limit DSMM's observers/guards to its own children without altering the native service or factories. */
|
|
18
|
-
export declare function managedAgentContext(ctx: Context, controlledParent: (agent: DshAgent) => boolean): DshContext;
|
|
19
|
-
/** Enrollment consumes A's completed admissions while native creation retains its original serial owner. */
|
|
20
|
-
export declare function admittedAgentContext(ctx: DshContext, runtime: DsmmProfileRuntime): DshContext;
|
|
21
7
|
export declare function runtimeAdmissionView(ctx: Context): SubagentRuntimeAdmissionView;
|
|
22
|
-
/** Capability projection only. Admission objects and A's CAS/maintenance methods remain untouched. */
|
|
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;
|
|
27
|
-
interface NativeDeliveryEvidence {
|
|
28
|
-
readonly parent: Agent;
|
|
29
|
-
readonly childId: SessionId;
|
|
30
|
-
readonly registry: AgentRegistry;
|
|
31
|
-
readonly resident: Agent | undefined;
|
|
32
|
-
readonly residency: object;
|
|
33
|
-
readonly provider: string;
|
|
34
|
-
readonly mode: "continuable" | "one-shot";
|
|
35
|
-
}
|
|
36
|
-
export declare function integrateSubagentRuntime(ctx: Context, settings: DsmmSettings, policy: DsmmRolePolicy, getRuntime: () => DsmmProfileRuntime | undefined, startup?: DsmmHostStartupOptions): Promise<{
|
|
37
|
-
bridge: {
|
|
38
|
-
authority: import("./child-admission-contract.js").DsmmChildAdmissionAuthority;
|
|
39
|
-
policy: import("./delivery-authority.js").DeliveryPolicyBinding<DsmmProfileAdmission, ChildAdmissionEvidence>;
|
|
40
|
-
childAdmission: ChildAdmissionCompletion;
|
|
41
|
-
readLegacy: import("./child-admission-contract.js").LegacyChildEvidenceReader;
|
|
42
|
-
resolveOriginalEvidence: (ticket: import("./child-admission-contract.js").ParentAdmissionTicket, id: string, signal: AbortSignal) => Promise<ChildAdmissionEvidence>;
|
|
43
|
-
bind(scope: Context): () => void;
|
|
44
|
-
onAdmissionGuardsInstalled(): void;
|
|
45
|
-
revokeBeforeDispose(parent: DshAgent, dispose: () => void | Promise<void>): Promise<void>;
|
|
46
|
-
};
|
|
47
|
-
owner: object;
|
|
48
|
-
registry: RoleRunRegistry<DsmmRoleRunCapture, DsmmInvocationView>;
|
|
49
|
-
runtime: DsmmSubagentRuntime<DsmmProfileAdmission, ChildAdmissionEvidence | NativeDeliveryEvidence>;
|
|
50
|
-
admitLlmRequest(agent: Agent, signal: AbortSignal): Promise<import("./host-llm.js").DsmmLlmAdmission | undefined>;
|
|
51
|
-
dispose(nativeDrain: () => Promise<void>): Promise<void>;
|
|
52
|
-
onAdmissionGuardsInstalled(): void;
|
|
53
|
-
continueStartup(complete: (signal: AbortSignal) => Promise<void>, callerSignal?: AbortSignal): Promise<void>;
|
|
54
|
-
ready(): Promise<void>;
|
|
55
|
-
revokeBeforeDispose(agent: Agent, dispose: () => void | Promise<void>): Promise<void>;
|
|
56
|
-
registerControls(scope: Context): void;
|
|
57
|
-
} | undefined>;
|
|
58
|
-
export declare function registerRuntimeGuidance(ctx: DshContext, getSettings: DsmmSettingsGetter, policy: DsmmRolePolicy): void;
|
|
59
|
-
export declare function registerRoleControlContribution(ctx: Context): void;
|
|
60
|
-
export type DsmmHostRuntimeIntegration = NonNullable<Awaited<ReturnType<typeof integrateSubagentRuntime>>>;
|
|
61
|
-
declare module "@deepseek-ai/cordis" {
|
|
62
|
-
interface Context {
|
|
63
|
-
dsmmRuntimeIntegration: DsmmHostRuntimeIntegration;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/** Explicit startup entry; it owns one PUBLIC subclass, never a live replacement. */
|
|
67
|
-
export declare const subagentRuntimePlugin: {
|
|
68
|
-
name: string;
|
|
69
|
-
inject: string[];
|
|
70
|
-
Config: import("@deepseek-ai/schemastery").default<Schemastery.ObjectS<NoInfer<{
|
|
71
|
-
maxDepth: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
72
|
-
maxActiveSubagents: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
73
|
-
}>>, Schemastery.ObjectT<NoInfer<{
|
|
74
|
-
maxDepth: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
75
|
-
maxActiveSubagents: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
76
|
-
}>>, "plain">;
|
|
77
|
-
apply(ctx: Context, config: ConstructorParameters<typeof SubagentRuntime>[1]): void;
|
|
78
|
-
};
|
|
79
|
-
export * from "./subagent-runtime.js";
|
|
80
|
-
export default subagentRuntimePlugin;
|
|
81
8
|
//# sourceMappingURL=runtime-integration.d.ts.map
|