@dsmm/dsmm 0.3.26 → 0.3.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -8
- package/docs/agent-presets.md +7 -7
- package/docs/agent-teams.md +27 -0
- package/docs/compatibility.md +7 -7
- package/docs/lsp.md +10 -12
- package/docs/maintenance.md +29 -0
- package/docs/roadmap.md +25 -9
- package/docs/runtime-recovery.md +3 -3
- package/docs/testing.md +3 -1
- package/dsh-plugin.json +1 -1
- package/lib/client/NativeToolView-data.d.ts +8 -0
- package/lib/client/NativeToolView-data.js +19 -0
- package/lib/client/NativeToolView.d.ts +19 -0
- package/lib/client/NativeToolView.js +46 -0
- package/lib/client/RoleToolView-data.js +1 -1
- package/lib/client/RoleToolView-locales.d.ts +7 -0
- package/lib/client/RoleToolView-locales.js +6 -0
- package/lib/client/RoleToolView.js +2 -0
- package/lib/client/SessionProfiles.js +1 -1
- package/lib/client/children-locales.d.ts +4 -4
- package/lib/client/controller.js +20 -0
- package/lib/client/locales.d.ts +1 -0
- package/lib/client/locales.js +2 -0
- package/lib/client.js +350 -187
- package/lib/core-permission-authority.js +14 -4
- package/lib/mode.js +2 -2
- package/lib/native-admission.d.ts +5 -3
- package/lib/native-admission.js +218 -77
- package/lib/native-ownership.d.ts +3 -0
- package/lib/native-ownership.js +19 -0
- package/lib/native-subagents.d.ts +2 -1
- package/lib/native-subagents.js +4 -3
- package/lib/profile-runtime.d.ts +1 -1
- package/lib/prompts.d.ts +2 -0
- package/lib/prompts.js +14 -8
- package/lib/role-control-remote.js +19 -8
- package/lib/role-control-rpc.js +1 -1
- package/lib/role-control-types.d.ts +18 -5
- package/lib/role-identity.js +3 -19
- package/lib/role-invocation.d.ts +1 -1
- package/lib/role-policy.d.ts +11 -3
- package/lib/role-policy.js +61 -21
- package/lib/role-subagents.js +12 -5
- package/lib/session-metadata.d.ts +27 -1
- package/lib/session-metadata.js +46 -0
- package/lib/session-scope.d.ts +1 -1
- package/lib/session-scope.js +2 -2
- package/package.json +3 -1
- package/prompts/source/deepwork/general.md +19 -0
- package/prompts/source/shared/native-teams.md +11 -0
package/lib/native-subagents.js
CHANGED
|
@@ -22,9 +22,10 @@ export function promptNativeChild(runtime, request, signal) {
|
|
|
22
22
|
return runtime.prompt(prompt, signal);
|
|
23
23
|
}
|
|
24
24
|
/** Caller-side catalog and exact-parent checks remain authoritative for this interrupt. */
|
|
25
|
-
export function interruptNativeChild(runtime, childId,
|
|
25
|
+
export function interruptNativeChild(runtime, childId, caller) {
|
|
26
26
|
if (typeof runtime.rootOf !== "function")
|
|
27
|
-
return runtime.interruptByParent(childId,
|
|
28
|
-
|
|
27
|
+
return runtime.interruptByParent(childId, caller.id, "continuable");
|
|
28
|
+
runtime.interrupt(childId, { kind: "ancestor", agent: caller });
|
|
29
|
+
return { accepted: true };
|
|
29
30
|
}
|
|
30
31
|
//# sourceMappingURL=native-subagents.js.map
|
package/lib/profile-runtime.d.ts
CHANGED
|
@@ -76,7 +76,7 @@ export declare class DsmmProfileRuntime {
|
|
|
76
76
|
prepareHistory(profileId: string | null, signal: AbortSignal): Promise<PreparedHistoryProfile>;
|
|
77
77
|
prepareRoot(agent: DshAgent, signal: AbortSignal): Promise<AdmittedProfile>;
|
|
78
78
|
readChildIdentity(childId: string, parentId: string): Promise<ChildAdmissionIdentity | null>;
|
|
79
|
-
prepareChild(agent: DshAgent, parent: DsmmProfileAdmission, signal: AbortSignal, identity?: ChildAdmissionIdentity | null): Promise<AdmittedProfile>;
|
|
79
|
+
prepareChild(agent: DshAgent, parent: DsmmProfileAdmission, signal: AbortSignal, identity?: Pick<ChildAdmissionIdentity, "profileId"> | null): Promise<AdmittedProfile>;
|
|
80
80
|
private currentSelection;
|
|
81
81
|
private prepareActivation;
|
|
82
82
|
revalidateActivation(admission: DsmmProfileAdmission): Promise<void>;
|
package/lib/prompts.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export interface DsmmPromptObservation {
|
|
|
33
33
|
continuable?: boolean;
|
|
34
34
|
/** Existing exact live child delivery; never a cold-recovery claim. */
|
|
35
35
|
nativeChildDelivery?: boolean;
|
|
36
|
+
nativeTree?: boolean;
|
|
36
37
|
nativeBrowserPrompt?: {
|
|
37
38
|
surface: string;
|
|
38
39
|
};
|
|
@@ -40,6 +41,7 @@ export interface DsmmPromptObservation {
|
|
|
40
41
|
}
|
|
41
42
|
/** Render callable delegation and lifecycle observations without repeating Agent locale. */
|
|
42
43
|
export declare function buildDsmmDelegationGuidance(settings: DsmmSettings, observed: DsmmPromptObservation): string;
|
|
44
|
+
export declare function buildDsmmTeamGuidance(admittedNames: readonly string[]): string;
|
|
43
45
|
export declare function buildDsmmAgentGuidance(settings: DsmmSettings, observed: DsmmPromptObservation): string;
|
|
44
46
|
export declare function buildDeepworkPrompt(settings: DsmmSettings, options?: DeepworkPromptOptions): string;
|
|
45
47
|
//# sourceMappingURL=prompts.d.ts.map
|
package/lib/prompts.js
CHANGED
|
@@ -72,7 +72,7 @@ export function buildDsmmDelegationGuidance(settings, observed) {
|
|
|
72
72
|
background: backgroundEnabled && properties.run_in_background !== undefined,
|
|
73
73
|
forceBackground: settings.subagents.forceBackground && properties.run_in_background !== undefined }];
|
|
74
74
|
});
|
|
75
|
-
const controls = observed.tools.filter(tool => ["send_message", "interrupt_agent", "job_output", "job_list", "job_kill", "dsmm_children"].includes(tool.name));
|
|
75
|
+
const controls = observed.tools.filter(tool => ["send_message", "interrupt_agent", "list_agents", "wait_agent", "job_output", "job_list", "job_kill", "dsmm_children"].includes(tool.name));
|
|
76
76
|
const runtime = observed.runtimeAdmission === undefined ? undefined : {
|
|
77
77
|
binding: observed.runtimeAdmission.binding, deliveryFenceReady: observed.runtimeAdmission.deliveryFenceReady,
|
|
78
78
|
restartRequired: observed.runtimeAdmission.restartRequired,
|
|
@@ -85,6 +85,7 @@ export function buildDsmmDelegationGuidance(settings, observed) {
|
|
|
85
85
|
forceBackground: settings.subagents.forceBackground,
|
|
86
86
|
continuable: observed.capabilities?.continuable === true && ready,
|
|
87
87
|
nativeChildDelivery: liveDelivery,
|
|
88
|
+
nativeTree: ready && observed.capabilities?.nativeTree === true,
|
|
88
89
|
sendMessage: liveDelivery && controls.some(tool => tool.name === "send_message"),
|
|
89
90
|
childToParentReporting: observed.scope === "child" && controls.some(tool => tool.name === "send_message"),
|
|
90
91
|
browserPromptSurface: liveDelivery ? observed.capabilities?.nativeBrowserPrompt?.surface ?? null : null,
|
|
@@ -95,7 +96,7 @@ ${JSON.stringify({ scope: observed.scope, topology: settings.subagents.toolTopol
|
|
|
95
96
|
controls: controls.map(tool => ({ tool: tool.name, parameters: Object.keys(toolProperties(tool)) })),
|
|
96
97
|
...(observed.roleAvailability === undefined ? {} : { roleAvailability: observed.roleAvailability.map(row => ({ id: row.id, admitted: row.admitted, ...(row.reason === undefined ? {} : { reason: row.reason }) })) }) }, null, 2)}
|
|
97
98
|
</dsmm-admitted-delegation>
|
|
98
|
-
Only the listed callable entries and target enums are observed here. Role availability alone is not tool availability. Inspect their native schemas; do not invent suffix roles, fields or tools. Omitted level and normal retain the default route; low/high/max are selectable only for the listed configured target levels, not workflow rigor or a fixed reasoning effort. Each level is a complete provider/model selection or an effort-only override with exact native preflight. Route override is deployment opt-in and additionally requires an exposed route parameter: provider/model must be paired; changing models discards the previous effort; effort-only uses the selected model's exact supported effort. An explicit complete invocation route does not silently use role fallback.
|
|
99
|
+
Only the listed callable entries and target enums are observed here. Role availability alone is not tool availability. Inspect their native schemas; do not invent suffix roles, fields or tools. Omitted level and normal retain the default route; low/high/max are selectable only for the listed configured target levels, not workflow rigor or a fixed reasoning effort. Each level is a complete provider/model selection or an effort-only override with exact native preflight. Route override is deployment opt-in and additionally requires an exposed route parameter: provider/model must be paired; changing models discards the previous effort; effort-only uses the selected model's exact supported effort. An explicit complete invocation route does not silently use role fallback. Resident reuse retains its captured role, level and route policy; cold activation resolves the selected profile's current role route under the original ceilings. Layout/level never enlarge target, read-only, inherited tool, ownership or depth authority. The ordinary root native model picker remains authoritative. Missing required planning/review capability returns to the stage owner, not a bypass.
|
|
99
100
|
`];
|
|
100
101
|
if (observed.invocation !== undefined)
|
|
101
102
|
sections.push(`<dsmm-observed-invocation>\n${JSON.stringify(projectInvocation(observed.invocation), null, 2)}\n</dsmm-observed-invocation>\nThe routeKind labels this observation: initial is preflighted start, not a claim about the current fallback route; actual is supplied by observed native request/status. Level is resource selection, never added permissions or a smaller verification obligation.`);
|
|
@@ -103,22 +104,27 @@ Only the listed callable entries and target enums are observed here. Role availa
|
|
|
103
104
|
<dsmm-child-lifecycle-state>\n${JSON.stringify(lifecycle, null, 2)}\n</dsmm-child-lifecycle-state>
|
|
104
105
|
${settings.subagents.forceBackground ? "This Agent's captured deployment policy forces all admitted role/category calls into background parent delivery, whether run_in_background is omitted, true or false. This takes priority over enableRunInBackground." : backgroundEnabled ? "Background is enabled in this Agent's captured deployment policy; only tools that expose run_in_background may request it." : "Background is disabled in this Agent's captured policy; do not request it."}
|
|
105
106
|
${settings.subagents.forceBackground ? "Forced background calls choose native parent delivery before starting and return accepted child/message identity, not a completion or a job handle." : "Role calls wait for the native activation result by default. Explicit run_in_background:true chooses native parent delivery before starting and returns accepted child/message identity, not a completion or a job handle."} Running calls cannot transfer foreground/background ownership. Partial output with a non-completed stop reason is not success and must not be replayed automatically.
|
|
106
|
-
${lifecycle.sendMessage ? "Exposed send_message can address
|
|
107
|
+
${lifecycle.sendMessage ? `${lifecycle.nativeTree ? "Exposed send_message uses the actual sender and can address another member of the same native tree. Native list_agents discovers members; wait_agent waits for new input when exposed. Supported cold members can resume with their original ID without recreating absent creators, subject to verified native identity, current role/provider policy and persisted restriction ceilings." : "Exposed send_message follows the Host's exact live adjacency contract. Legacy continuation requires its exact live creator."} Running delivery reaches the nearest step; an idle member can accept a next turn. An inbox receipt means accepted, not executed/completed. Resident admissions remain immutable. Cold activation resolves current selected-profile content and role routing; messages, task ownership and historical approvals grant no authority.` : "No live child messaging tool is observed here; do not invent one or infer it from role metadata."}
|
|
107
108
|
${lifecycle.browserPromptSurface !== null ? `The actual native user surface ${lifecycle.browserPromptSurface} uses queue/steer for continuable children, with native attachment validation. Its operator/connection/session/epoch/lifetime gate precedes inbox acceptance. Do not impersonate an Agent sender. After acceptance do not automatically retry; an unknown disconnect outcome needs verification, not a guessed idempotency guarantee.` : "No operator-gated native user queue/steer surface is established here; do not announce an unconnected DSMM RPC."}
|
|
108
|
-
${controls.some(tool => tool.name === "interrupt_agent") ?
|
|
109
|
-
${lifecycle.childToParentReporting ? "Native
|
|
109
|
+
${controls.some(tool => tool.name === "interrupt_agent") ? `Exposed interrupt_agent requests cancellation${lifecycle.nativeTree ? " only for the caller's descendants, using ancestor authority" : " under the Host's direct-child authority"}; it is not proof of completion or a message-delivery fence.` : "No child interruption tool is observed here."}
|
|
110
|
+
${lifecycle.childToParentReporting ? "Native reporting preserves the actual sender and the Host's membership checks; reporting grants no delegation authority." : ""}
|
|
110
111
|
Official Registry, SubagentRuntime and JSONL services own execution, result delivery and persistence. DSMM execution guards require a trusted live admission; they do not claim to veto every native inbox acceptance. Owner teardown cancels owned work and surviving Agent guards remain fail-closed. Do not replace native services, recover permissions from logs, or change Host configuration automatically.
|
|
111
|
-
Native capacity/depth, provider support,
|
|
112
|
+
Native capacity/depth, provider support, captured permissions and cancellation remain mandatory. New delegation requires its exact live creator. Tree continuation keeps durable creator identity separate from the live root admission owner; root retirement revokes its owned work. No OpenCode task_id/resume/retry protocol is supplied.
|
|
112
113
|
</dsmm-child-lifecycle>`);
|
|
113
114
|
return sections.join("\n\n---\n\n");
|
|
114
115
|
}
|
|
116
|
+
export function buildDsmmTeamGuidance(admittedNames) {
|
|
117
|
+
const tools = admittedNames.filter(name => ["team_task_create", "team_task_list", "team_task_get", "team_task_update"].includes(name));
|
|
118
|
+
return tools.length === 0 ? "" : `<dsmm-native-teams>\nObserved native Team tools for this step: ${tools.join(", ")}.\n\n${asset("shared/native-teams.md")}\n</dsmm-native-teams>`;
|
|
119
|
+
}
|
|
115
120
|
export function buildDsmmAgentGuidance(settings, observed) {
|
|
116
121
|
return [buildDsmmLocaleGuidance(settings), buildDsmmDelegationGuidance(settings, observed)].join("\n\n---\n\n");
|
|
117
122
|
}
|
|
118
123
|
export function buildDeepworkPrompt(settings, options = {}) {
|
|
119
124
|
const role = SOURCE_ROLE_CATALOG.find((role) => role.id === (options.roleId === undefined ? options.selectedPreset : options.roleId));
|
|
120
|
-
const common = role === undefined ?
|
|
121
|
-
|
|
125
|
+
const common = role === undefined ? [asset("deepwork/general.md"), asset("shared/shell-safety.md")].join("\n\n---\n\n")
|
|
126
|
+
: [activation, asset("deepwork/default.md")].join("\n\n---\n\n");
|
|
127
|
+
const family = role === undefined ? "" : roleModelCalibration(role, options.route?.model ?? "");
|
|
122
128
|
const base = [options.overrideSection?.trim() || common, settings.skills["avoid-ai-slop"] ? readSharedPromptAsset("avoid-ai-slop.md") : "", family === "" ? "" : `<workflow-model-calibration>\nThe role prompt is authoritative for scope, permissions and output. Model calibration never grants tools or changes the native route.\n\n${family}\n</workflow-model-calibration>`].filter(Boolean).join("\n\n---\n\n").replaceAll("{{modeName}}", settings.modeName);
|
|
123
129
|
const workflowPolicy = settings.workflow.policy === "legacy" ? `<dsmm-workflow-policy>
|
|
124
130
|
policy: legacy
|
|
@@ -125,22 +125,33 @@ function observedActualRoute(value) {
|
|
|
125
125
|
return { status: "unknown", reason: row.reason };
|
|
126
126
|
}
|
|
127
127
|
function roleCall(value) {
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
fail();
|
|
128
|
+
const native = typeof value === "object" && value !== null && "kind" in value && value.kind === "native";
|
|
129
|
+
const commonKeys = ["parentSessionId", "parentAdmissionEpoch", "callId", "rootCallId", "childId", "initialRoute", "actualRoute", "phase", "delivery"];
|
|
130
|
+
const row = object(value, [...commonKeys, ...native ? ["kind", "toolName"] : ["role", "level", "routeSource"]], ["childAdmissionEpoch", "runId", "stopReason", ...native ? ["provider", "nativeName"] : ["kind"]]);
|
|
132
131
|
const childId = identity(row.childId), initialRoute = observedInitialRoute(row.initialRoute), actualRoute = observedActualRoute(row.actualRoute);
|
|
133
132
|
const phase = choice(row.phase, ROLE_CALL_PHASES), delivery = choice(row.delivery, ROLE_CALL_DELIVERIES);
|
|
134
133
|
const stopReason = Object.hasOwn(row, "stopReason") ? choice(row.stopReason, ROLE_CALL_STOP_REASONS) : undefined;
|
|
135
134
|
if (stopReason !== undefined && phase !== "settled")
|
|
136
135
|
fail();
|
|
137
|
-
|
|
136
|
+
const common = { parentSessionId: identity(row.parentSessionId), parentAdmissionEpoch: epoch(row.parentAdmissionEpoch),
|
|
138
137
|
...(Object.hasOwn(row, "childAdmissionEpoch") ? { childAdmissionEpoch: epoch(row.childAdmissionEpoch) } : {}),
|
|
139
138
|
callId: callIdentity(row.callId), rootCallId: callIdentity(row.rootCallId), childId,
|
|
140
|
-
...(Object.hasOwn(row, "runId") ? { runId: identity(row.runId) } : {}),
|
|
141
|
-
level: choice(row.level, ["normal", "low", "high", "max"]), routeSource: choice(row.routeSource, DSMM_ROUTE_SOURCES),
|
|
142
|
-
initialRoute, actualRoute, phase, delivery,
|
|
139
|
+
...(Object.hasOwn(row, "runId") ? { runId: identity(row.runId) } : {}), actualRoute, phase, delivery,
|
|
143
140
|
...(stopReason === undefined ? {} : { stopReason }) };
|
|
141
|
+
if (native) {
|
|
142
|
+
if (initialRoute.status !== "unknown")
|
|
143
|
+
fail();
|
|
144
|
+
return { ...common, kind: "native", toolName: callIdentity(row.toolName), initialRoute,
|
|
145
|
+
...(Object.hasOwn(row, "provider") ? { provider: callIdentity(row.provider) } : {}),
|
|
146
|
+
...(Object.hasOwn(row, "nativeName") ? { nativeName: callIdentity(row.nativeName) } : {}) };
|
|
147
|
+
}
|
|
148
|
+
if (Object.hasOwn(row, "kind") && row.kind !== "role")
|
|
149
|
+
fail();
|
|
150
|
+
const role = parseDsmmRoleId(row.role);
|
|
151
|
+
if (role === "dsmm-orchestrator")
|
|
152
|
+
fail();
|
|
153
|
+
return { ...common, ...(row.kind === "role" ? { kind: "role" } : {}), role,
|
|
154
|
+
level: choice(row.level, ["normal", "low", "high", "max"]), routeSource: choice(row.routeSource, DSMM_ROUTE_SOURCES), initialRoute };
|
|
144
155
|
}
|
|
145
156
|
function observationFrame(value) {
|
|
146
157
|
const row = object(value, ["type", "sessionId", "admissionEpoch"], ["calls", "call", "callId"]), sessionId = identity(row.sessionId), admissionEpoch = epoch(row.admissionEpoch);
|
package/lib/role-control-rpc.js
CHANGED
|
@@ -297,7 +297,7 @@ let DsmmChildrenHost = (() => {
|
|
|
297
297
|
if (!capabilities.interrupt.enabled)
|
|
298
298
|
throw new ControlRefusal("disabled", undefined, capabilities.interrupt.reason);
|
|
299
299
|
this.direct(scope, request.childSessionId);
|
|
300
|
-
return interruptNativeChild(this.ctx.get("subagents"), SessionId(request.childSessionId), scope.parent
|
|
300
|
+
return interruptNativeChild(this.ctx.get("subagents"), SessionId(request.childSessionId), scope.parent);
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
303
|
};
|
|
@@ -30,7 +30,7 @@ export type RoleCallActualRoute = {
|
|
|
30
30
|
readonly status: "unknown";
|
|
31
31
|
readonly reason: "no-own-request-header" | "invalid-own-request-header" | "not-observed";
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
interface CallObservationBase {
|
|
34
34
|
readonly parentSessionId: string;
|
|
35
35
|
readonly parentAdmissionEpoch: string;
|
|
36
36
|
readonly childAdmissionEpoch?: string;
|
|
@@ -38,15 +38,28 @@ export interface RoleCallObservation {
|
|
|
38
38
|
readonly rootCallId: string;
|
|
39
39
|
readonly childId: string;
|
|
40
40
|
readonly runId?: string;
|
|
41
|
-
readonly role: Exclude<import("./roles.js").DsmmRoleId, "dsmm-orchestrator">;
|
|
42
|
-
readonly level: DsmmInvocationLevel;
|
|
43
|
-
readonly routeSource: DsmmRouteSource;
|
|
44
|
-
readonly initialRoute: RoleCallInitialRoute;
|
|
45
41
|
readonly actualRoute: RoleCallActualRoute;
|
|
46
42
|
readonly phase: RoleCallPhase;
|
|
47
43
|
readonly delivery: RoleCallDelivery;
|
|
48
44
|
readonly stopReason?: RoleCallStopReason;
|
|
49
45
|
}
|
|
46
|
+
export interface RoleInvocationObservation extends CallObservationBase {
|
|
47
|
+
readonly kind?: "role";
|
|
48
|
+
readonly role: Exclude<import("./roles.js").DsmmRoleId, "dsmm-orchestrator">;
|
|
49
|
+
readonly level: DsmmInvocationLevel;
|
|
50
|
+
readonly routeSource: DsmmRouteSource;
|
|
51
|
+
readonly initialRoute: RoleCallInitialRoute;
|
|
52
|
+
}
|
|
53
|
+
export interface NativeCallObservation extends CallObservationBase {
|
|
54
|
+
readonly kind: "native";
|
|
55
|
+
readonly toolName: string;
|
|
56
|
+
readonly provider?: string;
|
|
57
|
+
readonly nativeName?: string;
|
|
58
|
+
readonly initialRoute: Extract<RoleCallInitialRoute, {
|
|
59
|
+
status: "unknown";
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
export type RoleCallObservation = RoleInvocationObservation | NativeCallObservation;
|
|
50
63
|
export type RoleCallObservationFrame = {
|
|
51
64
|
readonly type: "snapshot";
|
|
52
65
|
readonly sessionId: string;
|
package/lib/role-identity.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getTraceable } from "@deepseek-ai/cordis";
|
|
2
2
|
import { nativeAgentContext } from "./native-scope.js";
|
|
3
|
-
import { buildRoleIdentity
|
|
4
|
-
import { DSMM_ROLES
|
|
3
|
+
import { buildRoleIdentity } from "./prompt-content.js";
|
|
4
|
+
import { DSMM_ROLES } from "./roles.js";
|
|
5
5
|
/** The caller supplies the policy-admitted identity; only its Agent layer is changed. */
|
|
6
6
|
export function registerRoleHarnessIdentity(agent, role, child = false) {
|
|
7
7
|
const ctx = nativeAgentContext(agent);
|
|
@@ -9,28 +9,12 @@ export function registerRoleHarnessIdentity(agent, role, child = false) {
|
|
|
9
9
|
const definition = DSMM_ROLES.find(row => row.id === role);
|
|
10
10
|
const identity = prompt.section({ name: "harness:identity", order: prompt.getSectionOrder("HARNESS_IDENTITY"),
|
|
11
11
|
text: buildRoleIdentity(definition) });
|
|
12
|
-
let locale;
|
|
13
|
-
let neutralize;
|
|
14
12
|
try {
|
|
15
|
-
if (!child && !isDsmmRoleId(ctx.get("agentPresets")?.composedPreset(ctx))) {
|
|
16
|
-
locale = prompt.section({ name: "dsmm:locale-guidance", order: 48, interpolate: false, text: readPromptAsset("shared/locale.md") });
|
|
17
|
-
// The standard preset's model identity belongs to its persona, not harness:identity.
|
|
18
|
-
neutralize = ctx.on("system-prompt/assemble", async (_assembly, context, next) => {
|
|
19
|
-
const assembly = await next();
|
|
20
|
-
if (context.scope !== agent)
|
|
21
|
-
return assembly;
|
|
22
|
-
return { ...assembly, sections: assembly.sections.map(section => section.name === "deployment:persona-prefix" && section.interpolate !== false
|
|
23
|
-
? { ...section, text: section.text.replace("You are a coding agent powered by the {{model}} model.", "You are a coding agent.") }
|
|
24
|
-
: section) };
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
13
|
const persona = child ? prompt.section({ name: "deployment:persona-prefix", order: prompt.getSectionOrder("DEPLOYMENT_PERSONA_PREFIX"),
|
|
28
14
|
text: definition.persona }) : undefined;
|
|
29
|
-
return () => { persona?.();
|
|
15
|
+
return () => { persona?.(); identity(); };
|
|
30
16
|
}
|
|
31
17
|
catch (error) {
|
|
32
|
-
neutralize?.();
|
|
33
|
-
locale?.();
|
|
34
18
|
identity();
|
|
35
19
|
throw error;
|
|
36
20
|
}
|
package/lib/role-invocation.d.ts
CHANGED
|
@@ -29,8 +29,8 @@ export declare function capturedOriginalRoleInvocation(agent: DshAgent): ChildAd
|
|
|
29
29
|
export declare function resolveRoleInvocation(parent: Agent, target: DsmmRoleId, settings: DsmmSettings, signal: AbortSignal, options?: DsmmInvocationOptions, nativeOptions?: AgentOptions, parameterPolicy?: ResolvedModelParameterPolicy): Promise<ResolvedRoleInvocation>;
|
|
30
30
|
export declare function invocationAgentOptions(invocation: ResolvedRoleInvocation, options?: AgentOptions): AgentOptions;
|
|
31
31
|
export declare function invocationView(invocation: ResolvedRoleInvocation, label: string, mode: DsmmInvocationView["mode"], ids?: Pick<DsmmInvocationView, "runId" | "childId" | "jobId">): {
|
|
32
|
-
runId?: string | undefined;
|
|
33
32
|
childId?: string | undefined;
|
|
33
|
+
runId?: string | undefined;
|
|
34
34
|
jobId?: string | undefined;
|
|
35
35
|
role: "dsmm-orchestrator" | "dsmm-planner" | "dsmm-plan-critic" | "dsmm-builder" | "dsmm-reviewer" | "dsmm-oracle" | "dsmm-oracle-2nd" | "dsmm-creative" | "dsmm-code-search" | "dsmm-doc-search" | "dsmm-clarifier" | "dsmm-media-reader" | "dsmm-frontend" | "dsmm-hard-reasoning" | "dsmm-research" | "dsmm-quick" | "dsmm-coding" | "dsmm-normal-task" | "dsmm-complex" | "dsmm-deep" | "dsmm-documenting" | "dsmm-cross-cutting";
|
|
36
36
|
label: string;
|
package/lib/role-policy.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DsmmDelegationCeiling } from "./session-metadata.js";
|
|
1
2
|
import type { ToolRestriction, ToolRuntime, ToolExecution } from "@deepseek-ai/dsh-tools";
|
|
2
3
|
import type { DshAgent, DshContext } from "./dsh-types.js";
|
|
3
4
|
export { allowedRoleChildren } from "./roles.js";
|
|
@@ -10,6 +11,10 @@ export interface DsmmRoleIdentity {
|
|
|
10
11
|
readonly child: boolean;
|
|
11
12
|
readonly epoch: string;
|
|
12
13
|
readonly parent?: DshAgent;
|
|
14
|
+
readonly owner?: DshAgent;
|
|
15
|
+
readonly creatorId?: string;
|
|
16
|
+
readonly maxDepth?: number;
|
|
17
|
+
readonly targetCeiling?: readonly DsmmRoleId[];
|
|
13
18
|
readonly readOnly?: boolean;
|
|
14
19
|
readonly toolFilter?: ToolRestriction;
|
|
15
20
|
readonly preset?: string;
|
|
@@ -25,17 +30,20 @@ export declare function resolveAdmittedDsmmRole(agent: DshAgent, settings: DsmmS
|
|
|
25
30
|
export declare class DsmmRolePolicy {
|
|
26
31
|
private readonly ctx;
|
|
27
32
|
private readonly getSettings;
|
|
28
|
-
private readonly mode;
|
|
29
33
|
private readonly executions;
|
|
30
34
|
private readonly toolCalls;
|
|
31
|
-
constructor(ctx: DshContext, getSettings: DsmmSettingsGetter,
|
|
35
|
+
constructor(ctx: DshContext, getSettings: DsmmSettingsGetter, _mode: DeepworkModeController);
|
|
32
36
|
private agents;
|
|
33
37
|
assertLive(agent: DshAgent): void;
|
|
34
38
|
private selected;
|
|
35
39
|
validateRootRole(agent: DshAgent, admission: DsmmProfileAdmission): void;
|
|
36
40
|
bindChild(agent: DshAgent, parent: DshAgent, admission: DsmmProfileAdmission, invocation: ResolvedRoleInvocation, maximum: number | undefined, toolFilter: ToolRestriction, independentComposition?: boolean): void;
|
|
41
|
+
/** Cold identity is proven by native catalog/descriptor evidence before this binding. */
|
|
42
|
+
bindContinuedChild(agent: DshAgent, owner: DshAgent, admission: DsmmProfileAdmission, invocation: ResolvedRoleInvocation | undefined, ceiling: DsmmDelegationCeiling, maximum: number | undefined, independentComposition: boolean): void;
|
|
43
|
+
maximumDepth(agent: DshAgent, ...limits: Array<number | undefined>): number | undefined;
|
|
44
|
+
delegationCeiling(agent: DshAgent): Pick<DsmmDelegationCeiling, "readOnly" | "allow" | "deny" | "targets" | "maxDepth">;
|
|
37
45
|
/** Ordinary native inheritance captures ceilings without inventing a role invocation. */
|
|
38
|
-
bindInheritedChild(agent: DshAgent, parent: DshAgent, admission: DsmmProfileAdmission, continuation?: boolean): void;
|
|
46
|
+
bindInheritedChild(agent: DshAgent, parent: DshAgent, admission: DsmmProfileAdmission, continuation?: boolean, maximum?: number): void;
|
|
39
47
|
release(agent: DshAgent): void;
|
|
40
48
|
assertModuleAdmission(agent: DshAgent): void;
|
|
41
49
|
identity(agent: DshAgent): DsmmRoleIdentity;
|
package/lib/role-policy.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { nativeIsOwnedBy } from "./native-ownership.js";
|
|
1
|
+
import { nativeIsOwnedBy, nativeSameTree, nativeTreeRoot } from "./native-ownership.js";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
import { SubagentError, delegationDepthOf } from "@deepseek-ai/dsh-subagent";
|
|
4
4
|
import { Context, symbols } from "@deepseek-ai/cordis";
|
|
@@ -13,7 +13,7 @@ const liveIdentities = new WeakMap();
|
|
|
13
13
|
const toolIdentities = new WeakMap();
|
|
14
14
|
const controlledDefinitions = new WeakSet();
|
|
15
15
|
export const READONLY_ROLE_DENIED_TOOLS = ["write", "edit", "bash", "pwsh"];
|
|
16
|
-
const readTools = new Set(["read", "glob", "grep", "read_image", "web_search", "web_fetch", "skill", "load_skill", "structured_output", "send_message", "interrupt_agent", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"]);
|
|
16
|
+
const readTools = new Set(["read", "glob", "grep", "read_image", "web_search", "web_fetch", "skill", "load_skill", "structured_output", "send_message", "interrupt_agent", "list_agents", "wait_agent", "team_task_list", "team_task_get", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"]);
|
|
17
17
|
const readLsp = new Set(["status", "diagnostics", "goto_definition", "find_references", "find_symbol_related", "symbols", "prepare_rename"]);
|
|
18
18
|
export function roleToolName(role) { return role.replace(/-/gu, "_"); }
|
|
19
19
|
export function roleFromToolName(name) { return name === "explore" ? "dsmm-code-search" : DSMM_ROLES.find(row => roleToolName(row.id) === name)?.id; }
|
|
@@ -32,7 +32,7 @@ export function resolveAdmittedDsmmRole(agent, settings, active) {
|
|
|
32
32
|
if (!settings.modules.deepwork.enabled || !agent.ctx.get("dsmmNativeAdmission")?.owns(agent) || agent.session.header?.origin === "subagent")
|
|
33
33
|
return undefined;
|
|
34
34
|
const preset = agent.ctx.get("agentPresets")?.composedPreset(agent.ctx);
|
|
35
|
-
const role = isDsmmRoleId(preset) ? preset :
|
|
35
|
+
const role = isDsmmRoleId(preset) ? preset : undefined;
|
|
36
36
|
return role !== undefined && settings.roles[role] ? role : undefined;
|
|
37
37
|
}
|
|
38
38
|
return resolveEffectiveDsmmRole(agent, settings, active);
|
|
@@ -41,13 +41,11 @@ export function resolveAdmittedDsmmRole(agent, settings, active) {
|
|
|
41
41
|
export class DsmmRolePolicy {
|
|
42
42
|
ctx;
|
|
43
43
|
getSettings;
|
|
44
|
-
mode;
|
|
45
44
|
executions = new AsyncLocalStorage();
|
|
46
45
|
toolCalls = new WeakMap();
|
|
47
|
-
constructor(ctx, getSettings,
|
|
46
|
+
constructor(ctx, getSettings, _mode) {
|
|
48
47
|
this.ctx = ctx;
|
|
49
48
|
this.getSettings = getSettings;
|
|
50
|
-
this.mode = mode;
|
|
51
49
|
}
|
|
52
50
|
agents() { const agents = this.ctx.get?.("agents"); if (!agents)
|
|
53
51
|
throw new SubagentError("Native registry unavailable", "UNAUTHORIZED"); return agents; }
|
|
@@ -71,21 +69,58 @@ export class DsmmRolePolicy {
|
|
|
71
69
|
if (maximum !== undefined && delegationDepthOf(agent) > maximum)
|
|
72
70
|
throw new SubagentError("Delegation depth exceeded", "UNAUTHORIZED");
|
|
73
71
|
const upstream = this.identity(parent);
|
|
74
|
-
liveIdentities.set(agent, Object.freeze({ role: invocation.target, child: true, parent,
|
|
72
|
+
liveIdentities.set(agent, Object.freeze({ role: invocation.target, child: true, parent,
|
|
73
|
+
owner: nativeTreeRoot(this.agents(), agent) ?? parent, creatorId: parent.id, maxDepth: this.maximumDepth(parent, maximum),
|
|
74
|
+
preset: this.selected(agent), epoch: admission.epoch, independentComposition, targetCeiling: upstream.targetCeiling,
|
|
75
75
|
readOnly: this.readOnly(upstream) || DSMM_ROLES.find(row => row.id === invocation.target).access === "read-only",
|
|
76
76
|
toolFilter: inheritToolFilter(inheritToolFilter(upstream.toolFilter, toolFilter), this.visibleToolCeiling(parent)) }));
|
|
77
77
|
bindRoleInvocation(agent, invocation);
|
|
78
78
|
captureRoleRuntimePolicy(admission.settings, invocation.target, invocation.policy);
|
|
79
79
|
}
|
|
80
|
+
/** Cold identity is proven by native catalog/descriptor evidence before this binding. */
|
|
81
|
+
bindContinuedChild(agent, owner, admission, invocation, ceiling, maximum, independentComposition) {
|
|
82
|
+
this.assertLive(agent);
|
|
83
|
+
this.assertModuleAdmission(owner);
|
|
84
|
+
if (!nativeSameTree(this.agents(), agent, owner) || nativeTreeRoot(this.agents(), agent) !== owner
|
|
85
|
+
|| agent.id !== ceiling.childId || agent.session.header?.parentSession !== ceiling.creatorId
|
|
86
|
+
|| owner.id !== ceiling.rootId || (invocation?.target ?? null) !== ceiling.role)
|
|
87
|
+
throw new SubagentError("Cold child identity mismatch", "UNAUTHORIZED");
|
|
88
|
+
const maxDepth = this.maximumDepth(owner, maximum, ceiling.maxDepth ?? undefined);
|
|
89
|
+
if (maxDepth !== undefined && delegationDepthOf(agent) > maxDepth)
|
|
90
|
+
throw new SubagentError("Delegation depth exceeded", "UNAUTHORIZED");
|
|
91
|
+
const upstream = this.identity(owner);
|
|
92
|
+
liveIdentities.set(agent, Object.freeze({ role: ceiling.role ?? undefined, child: true, owner, creatorId: ceiling.creatorId,
|
|
93
|
+
preset: this.selected(agent), epoch: admission.epoch, independentComposition, maxDepth,
|
|
94
|
+
readOnly: ceiling.readOnly || this.readOnly(upstream) || DSMM_ROLES.find(row => row.id === ceiling.role)?.access === "read-only",
|
|
95
|
+
targetCeiling: Object.freeze(ceiling.targets.filter(target => upstream.targetCeiling === undefined || upstream.targetCeiling.includes(target))),
|
|
96
|
+
toolFilter: inheritToolFilter(inheritToolFilter(upstream.toolFilter, this.visibleToolCeiling(owner)), { ...(ceiling.allow === null ? {} : { allow: ceiling.allow }), deny: ceiling.deny }) }));
|
|
97
|
+
if (invocation !== undefined) {
|
|
98
|
+
bindRoleInvocation(agent, invocation);
|
|
99
|
+
captureRoleRuntimePolicy(admission.settings, invocation.target, invocation.policy);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
maximumDepth(agent, ...limits) {
|
|
103
|
+
const values = [this.identity(agent).maxDepth, ...limits].filter((value) => value !== undefined);
|
|
104
|
+
return values.length === 0 ? undefined : Math.min(...values);
|
|
105
|
+
}
|
|
106
|
+
delegationCeiling(agent) {
|
|
107
|
+
const identity = this.identity(agent);
|
|
108
|
+
return { readOnly: this.readOnly(identity), allow: identity.toolFilter?.allow ?? null, deny: identity.toolFilter?.deny ?? [],
|
|
109
|
+
targets: this.targets(agent), maxDepth: identity.maxDepth ?? null };
|
|
110
|
+
}
|
|
80
111
|
/** Ordinary native inheritance captures ceilings without inventing a role invocation. */
|
|
81
|
-
bindInheritedChild(agent, parent, admission, continuation = false) {
|
|
112
|
+
bindInheritedChild(agent, parent, admission, continuation = false, maximum) {
|
|
82
113
|
this.assertLive(agent);
|
|
83
114
|
this.assertModuleAdmission(parent);
|
|
84
115
|
const upstream = this.identity(parent), preset = this.selected(agent);
|
|
85
116
|
if (!continuation && (upstream.role !== undefined || preset?.startsWith("dsmm-")) || !nativeIsOwnedBy(this.agents(), agent.id, parent)
|
|
86
117
|
|| agent.session.header?.origin !== "subagent" || agent.session.header.parentSession !== parent.id)
|
|
87
118
|
throw new SubagentError("Ordinary inheritance requires its exact non-controlled parent", "UNAUTHORIZED");
|
|
88
|
-
|
|
119
|
+
const maxDepth = this.maximumDepth(parent, maximum);
|
|
120
|
+
if (maxDepth !== undefined && delegationDepthOf(agent) > maxDepth)
|
|
121
|
+
throw new SubagentError("Delegation depth exceeded", "UNAUTHORIZED");
|
|
122
|
+
liveIdentities.set(agent, Object.freeze({ child: true, parent, owner: nativeTreeRoot(this.agents(), agent) ?? parent,
|
|
123
|
+
creatorId: parent.id, maxDepth, preset, epoch: admission.epoch, targetCeiling: upstream.targetCeiling,
|
|
89
124
|
readOnly: this.readOnly(upstream), toolFilter: inheritToolFilter(upstream.toolFilter, this.visibleToolCeiling(parent)) }));
|
|
90
125
|
}
|
|
91
126
|
release(agent) { liveIdentities.delete(agent); toolIdentities.delete(agent); }
|
|
@@ -93,10 +128,13 @@ export class DsmmRolePolicy {
|
|
|
93
128
|
this.assertLive(agent);
|
|
94
129
|
const settings = this.getSettings(agent), identity = liveIdentities.get(agent), selected = this.selected(agent);
|
|
95
130
|
if (identity?.child) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
131
|
+
const owner = identity.owner ?? identity.parent;
|
|
132
|
+
this.assertLive(owner);
|
|
133
|
+
const tree = nativeTreeRoot(this.agents(), agent);
|
|
134
|
+
if ((tree === undefined ? !nativeIsOwnedBy(this.agents(), agent.id, owner) : tree !== owner)
|
|
135
|
+
|| agent.session.header?.parentSession !== identity.creatorId || selected !== identity.preset) {
|
|
99
136
|
throw new SubagentError("Child admission no longer matches composition", "UNAUTHORIZED");
|
|
137
|
+
}
|
|
100
138
|
}
|
|
101
139
|
else if (agent.session.header?.origin !== "subagent")
|
|
102
140
|
this.validateRootRole(agent, this.getSettings.admission(agent));
|
|
@@ -113,7 +151,7 @@ export class DsmmRolePolicy {
|
|
|
113
151
|
const parent = this.agents().list().find(row => row !== agent && nativeIsOwnedBy(this.agents(), agent.id, row));
|
|
114
152
|
if (!parent)
|
|
115
153
|
this.validateRootRole(agent, this.getSettings.admission(agent));
|
|
116
|
-
const role = parent ? undefined : isDsmmRoleId(selected)
|
|
154
|
+
const role = parent ? undefined : isDsmmRoleId(selected) && settings.modules.deepwork.enabled && settings.roles[selected] ? selected : undefined;
|
|
117
155
|
return Object.freeze({ role, child: parent !== undefined, parent, epoch: this.getSettings.admission(agent).epoch });
|
|
118
156
|
}
|
|
119
157
|
admit(agent) { return this.identity(agent); }
|
|
@@ -122,7 +160,8 @@ export class DsmmRolePolicy {
|
|
|
122
160
|
const identity = this.identity(agent), settings = this.getSettings(agent);
|
|
123
161
|
if (!settings.modules.deepwork.enabled || !identity.role || !settings.roles[identity.role])
|
|
124
162
|
return [];
|
|
125
|
-
return allowedRoleChildren(identity.role, identity.child).filter(role => settings.roles[role]
|
|
163
|
+
return allowedRoleChildren(identity.role, identity.child).filter(role => settings.roles[role]
|
|
164
|
+
&& (identity.targetCeiling === undefined || identity.targetCeiling.includes(role)) && (!this.readOnly(identity) || DSMM_ROLES.find(row => row.id === role).access === "read-only")
|
|
126
165
|
&& (identity.toolFilter?.allow === undefined || [roleToolName(role), DSMM_ROLES.find(row => row.id === role)?.kind === "category" ? "dsmm_category" : "dsmm_role"].some(name => identity.toolFilter.allow.includes(name)))
|
|
127
166
|
&& !identity.toolFilter?.deny?.includes(roleToolName(role)));
|
|
128
167
|
}
|
|
@@ -155,7 +194,7 @@ export class DsmmRolePolicy {
|
|
|
155
194
|
const agents = agent.ctx.get("agents"), tools = agent.ctx.get("agentPresets")?.serviceFor(agent, "tools") ?? agent.ctx.get("tools"), definition = tools?.get(execution.name, agent);
|
|
156
195
|
this.toolCalls.set(execution, { agent, context: agent.ctx, registry: Reflect.get(agents, symbols.original) ?? agents,
|
|
157
196
|
realm: tools === undefined ? undefined : Reflect.get(tools, symbols.original) ?? tools, scopeParent: scopeParentOf(agent),
|
|
158
|
-
|
|
197
|
+
owner: this.identity(agent).owner, parentSession: agent.session.header.parentSession,
|
|
159
198
|
name: execution.name, args: execution.arguments, callId: execution.callId, signal: execution.signal,
|
|
160
199
|
toolFilter: this.visibleToolCeiling(agent),
|
|
161
200
|
...(definition === undefined || !controlledDefinitions.has(definition) ? {} : { definition, body: definition.execute, argumentsJson: JSON.stringify(execution.arguments) }) });
|
|
@@ -185,10 +224,10 @@ export class DsmmRolePolicy {
|
|
|
185
224
|
return;
|
|
186
225
|
call.signal.throwIfAborted();
|
|
187
226
|
const agents = agent.ctx.get("agents"), tools = agent.ctx.get("agentPresets")?.serviceFor(agent, "tools") ?? agent.ctx.get("tools");
|
|
188
|
-
const
|
|
227
|
+
const owner = this.identity(agent).owner;
|
|
189
228
|
if (agent !== call.agent || agent.ctx !== call.context || (Reflect.get(agents, symbols.original) ?? agents) !== call.registry
|
|
190
229
|
|| (tools === undefined ? undefined : Reflect.get(tools, symbols.original) ?? tools) !== call.realm || scopeParentOf(agent) !== call.scopeParent
|
|
191
|
-
|| agent.session.header.parentSession !== call.parentSession ||
|
|
230
|
+
|| agent.session.header.parentSession !== call.parentSession || owner !== call.owner)
|
|
192
231
|
throw new SubagentError("Tool caller ownership changed", "UNAUTHORIZED");
|
|
193
232
|
if (call.definition && (execution.name !== call.name || execution.arguments !== call.args || execution.callId !== call.callId || JSON.stringify(execution.arguments) !== call.argumentsJson
|
|
194
233
|
|| call.definition.execute !== call.body || tools?.get(call.name, agent) !== call.definition))
|
|
@@ -210,11 +249,12 @@ export class DsmmRolePolicy {
|
|
|
210
249
|
const nativeOutput = name === "structured_output" && definition !== undefined && toolIdentities.get(agent)?.definitions.get(name) === definition;
|
|
211
250
|
if (identity.toolFilter?.allow !== undefined && !identity.toolFilter.allow.includes(name) && !nativeOutput || identity.toolFilter?.deny?.includes(name))
|
|
212
251
|
return "Tool exceeds inherited filter";
|
|
213
|
-
|
|
214
|
-
|
|
252
|
+
const lifetimeOwner = identity.owner ?? identity.parent;
|
|
253
|
+
if (identity.toolFilter && lifetimeOwner && name !== "structured_output") {
|
|
254
|
+
const parent = lifetimeOwner, parentTools = parent.ctx.get("agentPresets")?.serviceFor(parent, "tools") ?? parent.ctx.get("tools");
|
|
215
255
|
if (!parentTools?.get(name, parent))
|
|
216
|
-
return "
|
|
217
|
-
const denied = this.preToolDenial(
|
|
256
|
+
return "Admission owner no longer exposes this capability";
|
|
257
|
+
const denied = this.preToolDenial(lifetimeOwner, name, undefined, execution);
|
|
218
258
|
if (denied)
|
|
219
259
|
return denied;
|
|
220
260
|
}
|
package/lib/role-subagents.js
CHANGED
|
@@ -12,9 +12,10 @@ import { childOwnedSessionEvents } from "./session-scope.js";
|
|
|
12
12
|
import { agentForScope, nativeAgentContext, scopeParentOf } from "./native-scope.js";
|
|
13
13
|
import { roleRouteRuntimeState } from "./role-routing.js";
|
|
14
14
|
import { modelRouteFromCall } from "./role-llm.js";
|
|
15
|
-
import { buildDsmmDelegationGuidance } from "./prompts.js";
|
|
15
|
+
import { buildDsmmDelegationGuidance, buildDsmmTeamGuidance } from "./prompts.js";
|
|
16
16
|
import { startNativeActivation } from "./native-subagents.js";
|
|
17
|
-
|
|
17
|
+
// Conditional Team tools stay in their native layer: copying a definition would discard its `when` registration.
|
|
18
|
+
const hostControls = ["send_message", "interrupt_agent", "list_agents", "wait_agent", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"];
|
|
18
19
|
// Agent-owned policy realms survive a bundle reinstall; do not register another
|
|
19
20
|
// delegation/tools layer on the same retained live Agent.
|
|
20
21
|
const admittedRealms = new WeakMap();
|
|
@@ -192,7 +193,7 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ad
|
|
|
192
193
|
const capturedProvider = provider;
|
|
193
194
|
const parentComposition = parent.ctx.get?.("agentPresets")?.composedPreset(parent.ctx);
|
|
194
195
|
const request = { parent, ...(parentComposition === undefined ? {} : { agentPreset: parentComposition }), prompt: [{ type: "text", text: args.prompt }],
|
|
195
|
-
agentOptions: invocationAgentOptions(invocation), maxDepth: subagents.resolveMaxDepth(current.subagents.maxDepth) };
|
|
196
|
+
agentOptions: invocationAgentOptions(invocation), maxDepth: policy.maximumDepth(parent, subagents.resolveMaxDepth(current.subagents.maxDepth)) };
|
|
196
197
|
const assertCurrent = () => {
|
|
197
198
|
if (policy.assertDelegation(parent, role.id).epoch !== admitted.epoch)
|
|
198
199
|
throw new SubagentError("DSMM parent admission changed before delegation", "UNAUTHORIZED");
|
|
@@ -281,14 +282,20 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
|
|
|
281
282
|
if (context.scope !== agent && agentForScope(ctx, context.scope) !== agent)
|
|
282
283
|
return "";
|
|
283
284
|
const identity = policy.identity(agent), tools = states.get(agent)?.tools, settings = getSettings(agent);
|
|
285
|
+
const teams = agentCtx.get?.("agentTeams");
|
|
286
|
+
const toolSet = context.toolSet;
|
|
287
|
+
const teamGuidance = teams?.isEnabled(agent) && toolSet !== undefined
|
|
288
|
+
? buildDsmmTeamGuidance([...toolSet.view(agent).keys()]) : "";
|
|
284
289
|
if (identity.role === undefined)
|
|
285
|
-
return
|
|
290
|
+
return teamGuidance;
|
|
286
291
|
const captured = capturedRoleInvocation(agent);
|
|
287
|
-
|
|
292
|
+
const delegationGuidance = buildDsmmDelegationGuidance(settings, { scope: identity.child ? "child" : "root", tools: tools?.schemas(agent) ?? [],
|
|
288
293
|
delegation: tools === undefined ? [] : admittedCallableRoleInventory(agent, settings, policy, tools),
|
|
289
294
|
...(captured === undefined ? {} : { invocation: roleInvocationObservation(captured, DSMM_ROLES.find(role => role.id === captured.target).name, "continuable", getSettings, agent, { childId: agent.id }) }),
|
|
290
295
|
runtimeAdmission: getSettings.subagentRuntime?.(), capabilities: { continuable: true, nativeChildDelivery: true,
|
|
296
|
+
nativeTree: typeof agentCtx.get("subagents")?.rootOf === "function",
|
|
291
297
|
...(agentCtx.get("dsmmChildren") === undefined ? {} : { nativeBrowserPrompt: { surface: "conversation.dsmm-children" } }) } });
|
|
298
|
+
return [delegationGuidance, teamGuidance].filter(Boolean).join("\n\n");
|
|
292
299
|
} });
|
|
293
300
|
state.promptRealm = promptRealm;
|
|
294
301
|
}
|
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import type { DshSession, DshSessionEvent } from "./dsh-types.js";
|
|
2
2
|
import type { DsmmRolePolicyEventData } from "./dsh-events.js";
|
|
3
|
-
import type { DsmmModelRoute } from "./settings.js";
|
|
3
|
+
import type { DsmmInvocationLevel, DsmmModelRoute } from "./settings.js";
|
|
4
|
+
import type { DsmmRoleId } from "./roles.js";
|
|
5
|
+
interface DelegationCeilingRestrictions {
|
|
6
|
+
readonly version: 1;
|
|
7
|
+
readonly childId: string;
|
|
8
|
+
readonly creatorId: string;
|
|
9
|
+
readonly rootId: string;
|
|
10
|
+
readonly provider: string;
|
|
11
|
+
readonly profileId: string | null;
|
|
12
|
+
readonly readOnly: boolean;
|
|
13
|
+
readonly allow: readonly string[] | null;
|
|
14
|
+
readonly deny: readonly string[];
|
|
15
|
+
readonly targets: readonly DsmmRoleId[];
|
|
16
|
+
readonly maxDepth: number | null;
|
|
17
|
+
}
|
|
18
|
+
export type DsmmDelegationCeiling = DelegationCeilingRestrictions & ({
|
|
19
|
+
readonly role: DsmmRoleId;
|
|
20
|
+
readonly level: DsmmInvocationLevel;
|
|
21
|
+
} | {
|
|
22
|
+
readonly role: null;
|
|
23
|
+
readonly level: null;
|
|
24
|
+
});
|
|
4
25
|
export interface DsmmModelSelectionRecordData {
|
|
5
26
|
readonly version: 1;
|
|
6
27
|
readonly source: "dsmm-selection" | "activation-setup";
|
|
@@ -14,6 +35,7 @@ declare module "@deepseek-ai/dsh-session/types" {
|
|
|
14
35
|
};
|
|
15
36
|
"plugin:dsmm/role-policy": DsmmRolePolicyEventData;
|
|
16
37
|
"plugin:dsmm/model-selection": DsmmModelSelectionRecordData;
|
|
38
|
+
"plugin:dsmm/delegation-ceiling": DsmmDelegationCeiling;
|
|
17
39
|
}
|
|
18
40
|
}
|
|
19
41
|
/** Model-hidden observations use the official ignorable record boundary, never authorization. */
|
|
@@ -23,4 +45,8 @@ export declare function appendModelSelectionRecord(session: DshSession, data: Ds
|
|
|
23
45
|
export declare function readModelSelectionRecord(event: DshSessionEvent): (DsmmModelSelectionRecordData & {
|
|
24
46
|
recordSeq: number;
|
|
25
47
|
}) | undefined;
|
|
48
|
+
export declare function appendDelegationCeiling(session: DshSession, data: DsmmDelegationCeiling): void;
|
|
49
|
+
/** Only the child's own suffix can restrict a cold admission; fork seeds carry no identity. */
|
|
50
|
+
export declare function readDelegationCeiling(session: DshSession): DsmmDelegationCeiling | undefined;
|
|
51
|
+
export {};
|
|
26
52
|
//# sourceMappingURL=session-metadata.d.ts.map
|