@dsmm/dsmm 0.2.2 → 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 -42
- package/cordis.patch.yml +1 -0
- package/docs/agent-presets.md +26 -14
- package/docs/compatibility.md +20 -79
- 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 -240
- 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 +16 -2
- package/lib/child-capture.js +29 -10
- 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 +26 -51
- 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 +85 -25
- 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 +2716 -2364
- 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 +17 -21
- package/lib/index.js +131 -430
- 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/permission-rpc.js +3 -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 +39 -41
- 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 +106 -64
- 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 -265
- 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 -53
- package/lib/role-policy.js +136 -525
- package/lib/role-providers.d.ts +5 -8
- package/lib/role-providers.js +20 -126
- 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 +149 -97
- package/lib/runtime-integration.d.ts +5 -109
- package/lib/runtime-integration.js +11 -779
- package/lib/session-metadata.d.ts +13 -12
- package/lib/session-metadata.js +6 -31
- package/lib/session-scope.js +6 -2
- 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 +133 -113
- package/docs/research/deepseek-v4-pro.md +0 -74
- package/docs/research/oh-dsh.md +0 -96
- package/lib/child-admission.d.ts +0 -42
- package/lib/child-admission.js +0 -162
- package/lib/delivery-authority.d.ts +0 -68
- package/lib/delivery-authority.js +0 -260
- 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/lib/native-child-evidence.d.ts +0 -42
- package/lib/native-child-evidence.js +0 -133
- package/lib/role-runs.d.ts +0 -135
- package/lib/role-runs.js +0 -304
- package/lib/session-persistence.d.ts +0 -35
- package/lib/session-persistence.js +0 -304
- package/lib/subagent-runtime.d.ts +0 -45
- package/lib/subagent-runtime.js +0 -131
- package/prompts/deepseek-flash.md +0 -11
- package/prompts/deepseek-v4-pro.md +0 -14
- 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-subagents.js
CHANGED
|
@@ -4,18 +4,20 @@ import { pathToFileURL } from "node:url";
|
|
|
4
4
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
5
5
|
import { SubagentError } from "@deepseek-ai/dsh-subagent";
|
|
6
6
|
import { DSMM_ROLES } from "./roles.js";
|
|
7
|
+
import { registerRoleHarnessIdentity } from "./role-identity.js";
|
|
7
8
|
import { isDsmmRoleId } from "./roles.js";
|
|
8
9
|
import { DsmmRolePolicy, roleToolName } from "./role-policy.js";
|
|
9
10
|
import { roleProviderName } from "./role-providers.js";
|
|
10
|
-
import {
|
|
11
|
+
import { capturedRoleInvocation, invocationAgentOptions, invocationView, resolveRoleInvocation } from "./role-invocation.js";
|
|
11
12
|
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 { buildDsmmAgentGuidance, buildDsmmLocaleGuidance } from "./prompts.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.
|
|
18
|
-
const admittedRealms = new
|
|
20
|
+
const admittedRealms = new WeakMap();
|
|
19
21
|
const callableDefinitions = new WeakMap();
|
|
20
22
|
/** Keep native controls on the frozen startup substrate, not desired-save reconciliation. */
|
|
21
23
|
export async function registerNativeSubagentControls(ctx) {
|
|
@@ -35,11 +37,11 @@ export async function registerNativeSubagentControls(ctx) {
|
|
|
35
37
|
ctx.logger.warn("DSMM native subagent controls unavailable; continuable control requires the installed host substrate");
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
|
-
/**
|
|
40
|
+
/** Project the captured invocation without reapplying deployment defaults. */
|
|
39
41
|
export function roleInvocationView(invocation, label, mode, getSettings, child, ids = {}) {
|
|
40
42
|
return roleInvocationObservation(invocation, label, mode, getSettings, child, ids).view;
|
|
41
43
|
}
|
|
42
|
-
/**
|
|
44
|
+
/** Distinguish the captured route from an observed native request. */
|
|
43
45
|
export function roleInvocationObservation(invocation, label, mode, getSettings, child, ids = {}) {
|
|
44
46
|
const view = invocationView(invocation, label, mode, ids);
|
|
45
47
|
if (child === undefined)
|
|
@@ -73,10 +75,38 @@ function latestOwnRoleRoute(child) {
|
|
|
73
75
|
/** Both observations belong to this exact native Agent; no parent/settings/route-lock fallback. */
|
|
74
76
|
export function roleRouteComparison(child) {
|
|
75
77
|
const agent = child;
|
|
76
|
-
const invocation =
|
|
78
|
+
const invocation = capturedRoleInvocation(agent);
|
|
77
79
|
return { childId: child.id, initialRoute: invocation === undefined ? { status: "unknown", reason: "missing-invocation-capture" }
|
|
78
80
|
: { status: "known", source: "invocation-capture", route: Object.freeze({ ...invocation.initialRoute }) }, liveRoute: latestOwnRoleRoute(agent) };
|
|
79
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
|
+
}
|
|
80
110
|
/** Shared by runtime registration and the prompt assembler; empty groups have no callable entry. */
|
|
81
111
|
export function callableRoleInventory(settings, targets) {
|
|
82
112
|
const admitted = targets.filter(id => id !== "dsmm-orchestrator" && settings.roles[id]);
|
|
@@ -101,16 +131,16 @@ export function admittedCallableRoleInventory(agent, settings, policy, tools) {
|
|
|
101
131
|
return targets.length === 0 ? [] : [{ ...registered.entry, targets }];
|
|
102
132
|
});
|
|
103
133
|
}
|
|
104
|
-
function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy,
|
|
134
|
+
function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, admission) {
|
|
105
135
|
const settings = getSettings(agent);
|
|
106
136
|
const subagents = agentCtx.get("subagents");
|
|
107
137
|
if (subagents === undefined)
|
|
108
138
|
throw new Error("DSMM role tools require native subagents");
|
|
109
139
|
const background = settings.subagents.enableRunInBackground;
|
|
110
|
-
const continuable = settings.subagents.backgroundMode === "continuable";
|
|
111
140
|
const admittedProviders = new Map(entry.targets.map(target => [target, subagents.getProvider(roleProviderName(target))]));
|
|
141
|
+
const incomplete = new Map();
|
|
112
142
|
const definition = defineTool({
|
|
113
|
-
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."}`,
|
|
114
144
|
parameters: { description: { type: "string", required: true }, prompt: { type: "string", required: true },
|
|
115
145
|
...(entry.targetParameter === undefined ? {} : { [entry.targetParameter]: { type: "string", enum: entry.targets, required: true } }),
|
|
116
146
|
level: { type: "string", enum: ["normal", "low", "high", "max"] },
|
|
@@ -125,8 +155,16 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ro
|
|
|
125
155
|
const route = invocation?.route;
|
|
126
156
|
const metadata = invocation === undefined ? "" : `${invocation.role} level=${invocation.level}${route === undefined ? "" : ` route=${route.provider}/${route.model}${route.reasoningEffort === undefined ? "" : ` effort=${route.reasoningEffort}`}`}`;
|
|
127
157
|
return result.kind === "foreground" ? [{ type: "text", text: metadata }, ...result.output ?? []]
|
|
128
|
-
: [{ type: "text", text: `${metadata}\
|
|
158
|
+
: [{ type: "text", text: `${metadata}\naccepted subagent ${result.subagentId}` }];
|
|
129
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
|
+
},
|
|
130
168
|
async execute(args, exec) {
|
|
131
169
|
const fields = ["description", "prompt", "level", ...entry.targetParameter === undefined ? [] : [entry.targetParameter],
|
|
132
170
|
...settings.subagents.allowRouteOverride ? ["route"] : [], ...background ? ["run_in_background"] : []];
|
|
@@ -135,94 +173,91 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ro
|
|
|
135
173
|
const parent = exec.agent;
|
|
136
174
|
if (parent === undefined)
|
|
137
175
|
throw new SubagentError("DSMM delegation requires a calling Agent", "UNAUTHORIZED");
|
|
138
|
-
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)
|
|
139
177
|
throw new SubagentError("DSMM tool is not the exact admitted caller definition", "UNAUTHORIZED");
|
|
140
178
|
const target = entry.targetParameter === undefined ? entry.targets[0] : exec.arguments[entry.targetParameter];
|
|
141
179
|
if (!isDsmmRoleId(target) || !entry.targets.includes(target) || DSMM_ROLES.find(row => row.id === target).kind !== entry.kind)
|
|
142
180
|
throw new SubagentError("DSMM target is unknown, cross-kind or not admitted", "UNAUTHORIZED");
|
|
143
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}`;
|
|
144
183
|
const admitted = policy.assertDelegation(parent, role.id);
|
|
145
184
|
const current = getSettings(parent);
|
|
146
185
|
const provider = subagents.getProvider(roleProviderName(role.id));
|
|
147
186
|
if (provider === undefined || provider !== admittedProviders.get(role.id))
|
|
148
187
|
throw new SubagentError("DSMM exact admitted role provider is unavailable", "NO_PROVIDER");
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (provider.prepareContinuable === undefined)
|
|
163
|
-
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;
|
|
164
201
|
assertCurrent();
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
throw new SubagentError("DSMM one-shot delegation requires the stable Host role-run registry", "UNSUPPORTED_CAPABILITY");
|
|
172
|
-
const admission = getSettings.admission?.(agent);
|
|
173
|
-
if (admission === undefined || admission.epoch !== admitted.epoch)
|
|
174
|
-
throw new SubagentError("DSMM one-shot capture requires the exact original parent admission", "UNAUTHORIZED");
|
|
175
|
-
const jobs = agentCtx.get("jobs");
|
|
176
|
-
if (requestedBackground && jobs === undefined)
|
|
177
|
-
throw new SubagentError("DSMM background jobs require the native jobs registry/controller", "UNSUPPORTED_CAPABILITY");
|
|
178
|
-
let child;
|
|
179
|
-
const projection = { ...invocationView(invocation, args.description, "one-shot"), get route() {
|
|
180
|
-
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(() => { });
|
|
181
208
|
} };
|
|
182
|
-
const holder = roleRuns.registry.start({ parent, owner: roleRuns.owner, sessionId: parent.id, toolCallId: exec.callId,
|
|
183
|
-
admissionEpoch: admitted.epoch, capture: Object.freeze({ invocation, admission }), projection, label: args.description, callerAbort: exec.signal, jobs,
|
|
184
|
-
async start(signal) {
|
|
185
|
-
assertCurrent();
|
|
186
|
-
const run = await duringRoleInvocation(agent, invocation, () => policy.duringDelegation(agent, role.id, () => subagents.start(provider.name, { ...request, signal }), request.toolFilter, request.maxDepth, agent => { child = agent; }));
|
|
187
|
-
projection.runId = run.id;
|
|
188
|
-
child ??= run.localAgent;
|
|
189
|
-
if (child?.id !== undefined)
|
|
190
|
-
projection.childId = child.id;
|
|
191
|
-
return run;
|
|
192
|
-
} });
|
|
193
|
-
if (requestedBackground) {
|
|
194
209
|
try {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (
|
|
199
|
-
|
|
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 } };
|
|
200
231
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (drain.status === "rejected" && drain.reason !== error)
|
|
205
|
-
throw new AggregateError([error, drain.reason], "DSMM background handoff was refused and its owned run drain rejected");
|
|
206
|
-
throw error;
|
|
232
|
+
finally {
|
|
233
|
+
pending.signal.removeEventListener("abort", cancel);
|
|
234
|
+
await pending.release();
|
|
207
235
|
}
|
|
208
|
-
}
|
|
209
|
-
const held = await holder.foreground;
|
|
210
|
-
if (held.kind === "background")
|
|
211
|
-
projection.jobId = held.jobId;
|
|
212
|
-
const { route, ...metadata } = projection;
|
|
213
|
-
const view = { ...metadata, ...(route === undefined ? {} : { route: { ...route } }) };
|
|
214
|
-
return held.kind === "foreground" ? { kind: held.kind, runId: held.runId, output: held.output, invocation: view }
|
|
215
|
-
: { kind: held.kind, runId: held.invocation.runId, jobId: held.jobId, invocation: view };
|
|
236
|
+
});
|
|
216
237
|
}
|
|
217
238
|
});
|
|
239
|
+
installRolePresenters(definition, entry);
|
|
218
240
|
callableDefinitions.set(definition, { entry: Object.freeze({ ...entry, targets: Object.freeze([...entry.targets]) }), providers: admittedProviders });
|
|
219
241
|
const dispose = tools.register(definition);
|
|
220
242
|
return () => { callableDefinitions.delete(definition); dispose(); };
|
|
221
243
|
}
|
|
222
244
|
/** Published name retained; all native/headless Agents consume one admitted policy. */
|
|
223
|
-
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
|
+
}
|
|
224
251
|
const states = new WeakMap();
|
|
225
|
-
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) => {
|
|
226
261
|
const state = states.get(agent);
|
|
227
262
|
if (state === undefined)
|
|
228
263
|
return;
|
|
@@ -232,6 +267,28 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
|
|
|
232
267
|
if (tools === undefined)
|
|
233
268
|
throw new Error("DSMM role tools require native guard/restrict services");
|
|
234
269
|
const settings = getSettings(agent), identity = policy.identity(agent), targets = policy.targets(agent);
|
|
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;
|
|
290
|
+
}
|
|
291
|
+
reconcileIdentity(agent, identity.role);
|
|
235
292
|
const subagents = agentCtx.get("subagents");
|
|
236
293
|
const host = ctx.get?.("tools");
|
|
237
294
|
const names = [...hostControls, ...host?.schemas().map((row) => row.name).filter((name) => name.startsWith(`mcp__${settings.lsp.serverName}__`)) ?? []];
|
|
@@ -262,13 +319,13 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
|
|
|
262
319
|
}
|
|
263
320
|
const inventory = callableRoleInventory(settings, targets.filter(role => subagents?.getProvider(roleProviderName(role))?.capabilities.depthLimit === true));
|
|
264
321
|
for (const entry of inventory)
|
|
265
|
-
state.owned.push(registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy,
|
|
322
|
+
state.owned.push(registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, admission));
|
|
266
323
|
policy.captureTools(agent, tools, [...inventory.map(entry => entry.name), ...names], !sameRealm || !sameParent);
|
|
267
324
|
state.signature = signature;
|
|
268
325
|
state.hostDefinitions = definitions;
|
|
269
326
|
state.parentScope = parentScope;
|
|
270
327
|
};
|
|
271
|
-
const onCreated =
|
|
328
|
+
const onCreated = ({ agent }) => {
|
|
272
329
|
if (states.has(agent) || admittedRealms.has(agent))
|
|
273
330
|
return;
|
|
274
331
|
if (!getSettings(agent).modules.deepwork.enabled)
|
|
@@ -276,33 +333,28 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
|
|
|
276
333
|
const agentCtx = nativeAgentContext(agent);
|
|
277
334
|
policy.admit(agent);
|
|
278
335
|
states.set(agent, { owned: [], hostDefinitions: [] });
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const identity = policy.identity(agent);
|
|
282
|
-
const tools = states.get(agent)?.tools;
|
|
283
|
-
const inventory = tools === undefined ? [] : admittedCallableRoleInventory(agent, getSettings(agent), policy, tools);
|
|
284
|
-
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.`;
|
|
285
|
-
} });
|
|
286
|
-
agentCtx.effect(() => () => {
|
|
336
|
+
const retire = () => {
|
|
337
|
+
stopIdentity();
|
|
287
338
|
const state = states.get(agent);
|
|
288
339
|
state?.restriction?.();
|
|
289
340
|
state?.guard?.();
|
|
341
|
+
state?.identityPrompt?.();
|
|
342
|
+
state?.guidance?.();
|
|
290
343
|
for (const dispose of state?.owned ?? [])
|
|
291
344
|
dispose();
|
|
292
345
|
states.delete(agent);
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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));
|
|
297
353
|
};
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
return next();
|
|
304
|
-
}, { prepend: true, global: true });
|
|
305
|
-
for (const agent of ctx.get?.("agents")?.list() ?? [])
|
|
306
|
-
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 });
|
|
307
359
|
}
|
|
308
360
|
//# sourceMappingURL=role-subagents.js.map
|
|
@@ -1,112 +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 { LegacyCapabilityCollaborators } from "./legacy-child-policy.js";
|
|
9
|
-
import type { LegacyReadIntegrationChild, LegacyReadTrustedStartup } from "./legacy-read-integration.js";
|
|
10
|
-
import type { DsmmProfileRuntime } from "./profile-runtime.js";
|
|
11
|
-
import type { DsmmInvocationView, SubagentRuntimeAdmissionView } from "./profile-types.js";
|
|
12
|
-
import type { DsmmRolePolicy } from "./role-policy.js";
|
|
13
|
-
import { RoleRunRegistry } from "./role-runs.js";
|
|
14
|
-
import type { DsmmRoleRunCapture } from "./role-subagents.js";
|
|
15
|
-
import type { DsmmProfileAdmission, DsmmSettings, DsmmSettingsGetter } from "./settings.js";
|
|
16
|
-
import { DsmmSubagentRuntime } from "./subagent-runtime.js";
|
|
17
|
-
/** 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;
|
|
18
6
|
export declare function classifyDsmmAgent(agent: Agent): "dsmm" | "native";
|
|
19
|
-
/** Limit DSMM's observers/guards to its own children without altering the native service or factories. */
|
|
20
|
-
export declare function managedAgentContext(ctx: Context, controlledParent: (agent: DshAgent) => boolean): DshContext;
|
|
21
|
-
/** Enrollment consumes A's completed admissions while native creation retains its original serial owner. */
|
|
22
|
-
export declare function admittedAgentContext(ctx: DshContext, runtime: DsmmProfileRuntime): DshContext;
|
|
23
7
|
export declare function runtimeAdmissionView(ctx: Context): SubagentRuntimeAdmissionView;
|
|
24
|
-
/** Capability projection only. Admission objects and A's CAS/maintenance methods remain untouched. */
|
|
25
|
-
export declare function publicProfileRuntime(runtime: DsmmProfileRuntime, ctx: Context, integration?: {
|
|
26
|
-
changeConfiguration(reason: string, mutate: () => Promise<void>): Promise<void>;
|
|
27
|
-
}): DsmmProfileRuntime;
|
|
28
|
-
/** Actual programmatic Host collaborators; never profile, YAML or RPC input. */
|
|
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
|
-
}
|
|
36
|
-
interface NativeDeliveryEvidence {
|
|
37
|
-
readonly parent: Agent;
|
|
38
|
-
readonly childId: SessionId;
|
|
39
|
-
readonly registry: AgentRegistry;
|
|
40
|
-
readonly resident: Agent | undefined;
|
|
41
|
-
readonly residency: object;
|
|
42
|
-
readonly provider: string;
|
|
43
|
-
readonly mode: "continuable" | "one-shot";
|
|
44
|
-
}
|
|
45
|
-
export declare function integrateSubagentRuntime(ctx: Context, settings: DsmmSettings, policy: DsmmRolePolicy, getRuntime: () => DsmmProfileRuntime | undefined, startup?: DsmmHostStartupOptions): Promise<{
|
|
46
|
-
bridge: {
|
|
47
|
-
authority: import("./child-admission-contract.js").DsmmChildAdmissionAuthority;
|
|
48
|
-
policy: import("./delivery-authority.js").DeliveryPolicyBinding<DsmmProfileAdmission, ChildAdmissionEvidence>;
|
|
49
|
-
childAdmission: ChildAdmissionCompletion;
|
|
50
|
-
readLegacy: import("./child-admission-contract.js").LegacyChildEvidenceReader;
|
|
51
|
-
resolveOriginalEvidence: (ticket: import("./child-admission-contract.js").ParentAdmissionTicket, id: string, signal: AbortSignal) => Promise<ChildAdmissionEvidence>;
|
|
52
|
-
bind(scope: Context): () => void;
|
|
53
|
-
onAdmissionGuardsInstalled(): void;
|
|
54
|
-
revokeBeforeDispose(parent: DshAgent, dispose: () => void | Promise<void>): Promise<void>;
|
|
55
|
-
};
|
|
56
|
-
owner: object;
|
|
57
|
-
registry: RoleRunRegistry<DsmmRoleRunCapture, DsmmInvocationView>;
|
|
58
|
-
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
|
-
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
|
-
dispose(nativeDrain: () => Promise<void>): Promise<void>;
|
|
83
|
-
onAdmissionGuardsInstalled(): void;
|
|
84
|
-
continueStartup(complete: (signal: AbortSignal) => Promise<void>, callerSignal?: AbortSignal): Promise<void>;
|
|
85
|
-
ready(): Promise<void>;
|
|
86
|
-
revokeBeforeDispose(agent: Agent, dispose: () => void | Promise<void>): Promise<void>;
|
|
87
|
-
registerControls(scope: Context): void;
|
|
88
|
-
} | undefined>;
|
|
89
|
-
export declare function registerRuntimeGuidance(ctx: DshContext, getSettings: DsmmSettingsGetter, policy: DsmmRolePolicy): void;
|
|
90
|
-
export declare function registerRoleControlContribution(ctx: Context): void;
|
|
91
|
-
export type DsmmHostRuntimeIntegration = NonNullable<Awaited<ReturnType<typeof integrateSubagentRuntime>>>;
|
|
92
|
-
declare module "@deepseek-ai/cordis" {
|
|
93
|
-
interface Context {
|
|
94
|
-
dsmmRuntimeIntegration: DsmmHostRuntimeIntegration;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/** Explicit startup entry; it owns one PUBLIC subclass, never a live replacement. */
|
|
98
|
-
export declare const subagentRuntimePlugin: {
|
|
99
|
-
name: string;
|
|
100
|
-
inject: string[];
|
|
101
|
-
Config: import("@deepseek-ai/schemastery").default<Schemastery.ObjectS<NoInfer<{
|
|
102
|
-
maxDepth: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
103
|
-
maxActiveSubagents: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
104
|
-
}>>, Schemastery.ObjectT<NoInfer<{
|
|
105
|
-
maxDepth: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
106
|
-
maxActiveSubagents: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
107
|
-
}>>, "plain">;
|
|
108
|
-
apply(ctx: Context, config: ConstructorParameters<typeof SubagentRuntime>[1]): void;
|
|
109
|
-
};
|
|
110
|
-
export * from "./subagent-runtime.js";
|
|
111
|
-
export default subagentRuntimePlugin;
|
|
112
8
|
//# sourceMappingURL=runtime-integration.d.ts.map
|