@dsmm/dsmm 0.3.30 → 0.3.31

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.
@@ -1,4 +1,4 @@
1
- import { getTraceable, symbols } from "@deepseek-ai/cordis";
1
+ import { symbols } from "@deepseek-ai/cordis";
2
2
  import { createRequire } from "node:module";
3
3
  import { pathToFileURL } from "node:url";
4
4
  import { defineTool } from "@deepseek-ai/dsh-tools";
@@ -9,15 +9,13 @@ import { DsmmRolePolicy, roleToolName } from "./role-policy.js";
9
9
  import { roleProviderName } from "./role-providers.js";
10
10
  import { capturedRoleInvocation, invocationAgentOptions, invocationView, resolveRoleInvocation } from "./role-invocation.js";
11
11
  import { childOwnedSessionEvents } from "./session-scope.js";
12
- import { agentForScope, nativeAgentContext, scopeParentOf } from "./native-scope.js";
12
+ import { agentScopeService, nativeAgentContext, scopeParentOf } from "./native-scope.js";
13
13
  import { roleRouteRuntimeState } from "./role-routing.js";
14
14
  import { modelRouteFromCall } from "./role-llm.js";
15
15
  import { buildDsmmDelegationGuidance, buildDsmmTeamGuidance } from "./prompts.js";
16
16
  import { startNativeActivation, supportsNativeNames } from "./native-subagents.js";
17
17
  // Conditional Team tools stay in their native layer: copying a definition would discard its `when` registration.
18
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"];
19
- // Agent-owned policy realms survive a bundle reinstall; do not register another
20
- // delegation/tools layer on the same retained live Agent.
21
19
  const admittedRealms = new WeakMap();
22
20
  const callableDefinitions = new WeakMap();
23
21
  /** Keep native controls on the frozen startup substrate, not desired-save reconciliation. */
@@ -132,9 +130,9 @@ export function admittedCallableRoleInventory(agent, settings, policy, tools) {
132
130
  return targets.length === 0 ? [] : [{ ...registered.entry, targets }];
133
131
  });
134
132
  }
135
- function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, admission) {
133
+ function registerRoleTool(agent, ctx, tools, entry, getSettings, policy, admission) {
136
134
  const settings = getSettings(agent);
137
- const subagents = agentCtx.get("subagents");
135
+ const subagents = ctx.get("subagents");
138
136
  if (subagents === undefined)
139
137
  throw new Error("DSMM role tools require native subagents");
140
138
  const named = supportsNativeNames(subagents);
@@ -222,7 +220,7 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ad
222
220
  pending.signal.throwIfAborted();
223
221
  }
224
222
  try {
225
- const child = agentCtx.agents.get(activation.childId);
223
+ const child = ctx.get("agents").get(activation.childId);
226
224
  if (child === undefined)
227
225
  throw new SubagentError("Native role activation has no live child", "UNAUTHORIZED");
228
226
  await admission.ensure(child);
@@ -260,32 +258,30 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ad
260
258
  return () => { callableDefinitions.delete(definition); dispose(); };
261
259
  }
262
260
  /** Published name retained; all native/headless Agents consume one admitted policy. */
263
- export async function registerHeadlessRoleTools(ctx, controller, getSettings, policy, admission, onlyAgent) {
264
- const refresh = admittedRealms.get(onlyAgent);
261
+ export function registerHeadlessRoleTools(ctx, controller, getSettings, policy, admission, agent) {
262
+ const refresh = admittedRealms.get(ctx);
265
263
  if (refresh) {
266
264
  refresh();
267
265
  return;
268
266
  }
269
- const states = new WeakMap();
270
- const reconcile = (agent) => {
271
- const state = states.get(agent);
272
- if (state === undefined)
273
- return;
274
- const agentCtx = nativeAgentContext(agent);
275
- const raw = agentCtx.get("agentPresets")?.serviceFor({ ctx: agentCtx }, "tools");
276
- const tools = raw === undefined ? agentCtx.get("tools") : getTraceable(agentCtx, raw);
267
+ if (!getSettings(agent).modules.deepwork.enabled)
268
+ return;
269
+ policy.admit(agent);
270
+ const state = { owned: [], hostDefinitions: [], providers: [] };
271
+ const reconcile = () => {
272
+ const tools = agentScopeService(ctx, "tools");
277
273
  if (tools === undefined)
278
274
  throw new Error("DSMM role tools require native guard/restrict services");
279
275
  const settings = getSettings(agent), identity = policy.identity(agent), targets = policy.targets(agent);
280
- const prompt = agentCtx.get("agentPresets")?.serviceFor(agent, "systemPrompt") ?? agentCtx.get("systemPrompt");
276
+ const prompt = agentScopeService(ctx, "systemPrompt");
281
277
  const promptRealm = Reflect.get(prompt, symbols.original) ?? prompt;
282
278
  if (state.promptRealm !== promptRealm) {
283
279
  state.guidance?.();
284
- state.guidance = getTraceable(agentCtx, prompt).section({ name: "dsmm:delegation", order: 49, text(context) {
285
- if (context.scope !== agent && agentForScope(ctx, context.scope) !== agent)
280
+ state.guidance = prompt.section({ name: "dsmm:delegation", order: 49, text(context) {
281
+ if (context.scope !== agent)
286
282
  return "";
287
- const identity = policy.identity(agent), tools = states.get(agent)?.tools, settings = getSettings(agent);
288
- const teams = agentCtx.get?.("agentTeams");
283
+ const identity = policy.identity(agent), tools = state.tools, settings = getSettings(agent);
284
+ const teams = ctx.get?.("agentTeams");
289
285
  const toolSet = context.toolSet;
290
286
  const teamGuidance = teams?.isEnabled(agent) && toolSet !== undefined
291
287
  ? buildDsmmTeamGuidance([...toolSet.view(agent).keys()]) : "";
@@ -296,14 +292,14 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
296
292
  delegation: tools === undefined ? [] : admittedCallableRoleInventory(agent, settings, policy, tools),
297
293
  ...(captured === undefined ? {} : { invocation: roleInvocationObservation(captured, DSMM_ROLES.find(role => role.id === captured.target).name, "continuable", getSettings, agent, { childId: agent.id }) }),
298
294
  runtimeAdmission: getSettings.subagentRuntime?.(), capabilities: { continuable: true, nativeChildDelivery: true,
299
- nativeTree: typeof agentCtx.get("subagents")?.rootOf === "function",
300
- ...(agentCtx.get("dsmmChildren") === undefined ? {} : { nativeBrowserPrompt: { surface: "conversation.dsmm-children" } }) } });
295
+ nativeTree: typeof ctx.get("subagents")?.rootOf === "function",
296
+ ...(ctx.get("dsmmChildren") === undefined ? {} : { nativeBrowserPrompt: { surface: "conversation.dsmm-children" } }) } });
301
297
  return [delegationGuidance, teamGuidance].filter(Boolean).join("\n\n");
302
298
  } });
303
299
  state.promptRealm = promptRealm;
304
300
  }
305
- const subagents = agentCtx.get("subagents");
306
- const host = ctx.get?.("tools");
301
+ const subagents = ctx.get("subagents");
302
+ const host = ctx.get("tools");
307
303
  const names = [...hostControls, ...host?.schemas().map((row) => row.name).filter((name) => name.startsWith(`mcp__${settings.lsp.serverName}__`)) ?? []];
308
304
  const definitions = names.map((name) => host?.get(name));
309
305
  const providers = targets.map(role => {
@@ -338,48 +334,32 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
338
334
  }
339
335
  const inventory = callableRoleInventory(settings, targets.filter(role => subagents?.getProvider(roleProviderName(role))?.capabilities.depthLimit === true));
340
336
  for (const entry of inventory)
341
- state.owned.push(registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, admission));
337
+ state.owned.push(registerRoleTool(agent, ctx, tools, entry, getSettings, policy, admission));
342
338
  policy.captureTools(agent, tools, [...inventory.map(entry => entry.name), ...names], !sameRealm || !sameParent);
343
339
  state.signature = signature;
344
340
  state.providers = providers;
345
341
  state.hostDefinitions = definitions;
346
342
  state.parentScope = parentScope;
347
343
  };
348
- const onCreated = ({ agent }) => {
349
- if (states.has(agent) || admittedRealms.has(agent))
350
- return;
351
- if (!getSettings(agent).modules.deepwork.enabled)
352
- return;
353
- const agentCtx = nativeAgentContext(agent);
354
- policy.admit(agent);
355
- states.set(agent, { owned: [], hostDefinitions: [], providers: [] });
356
- const retire = () => {
357
- stopIdentity();
358
- const state = states.get(agent);
359
- state?.restriction?.();
360
- state?.guard?.();
361
- state?.guidance?.();
362
- for (const dispose of state?.owned ?? [])
363
- dispose();
364
- states.delete(agent);
365
- admittedRealms.delete(agent);
366
- admission.lifetime.signal.removeEventListener("abort", retire);
367
- };
368
- admission.lifetime.signal.addEventListener("abort", retire, { once: true });
369
- agentCtx.effect(() => retire);
370
- try {
371
- reconcile(agent);
372
- }
373
- catch (error) {
374
- retire();
375
- throw error;
376
- }
377
- admittedRealms.set(agent, () => reconcile(agent));
378
- };
379
- // Native assembly collects sections before its waterfall. Admission/mode/preset
380
- // changes must update the Agent layer before that collection begins.
381
- const stopIdentity = controller.watch(agent => { if (agent === onlyAgent)
382
- reconcile(agent); });
383
- onCreated({ agent: onlyAgent });
344
+ // Native assembly collects sections before its waterfall. Update the Agent layer before collection.
345
+ const stopIdentity = controller.watch(changed => { if (changed === agent)
346
+ reconcile(); });
347
+ const retire = ctx.effect(() => () => {
348
+ stopIdentity();
349
+ state.restriction?.();
350
+ state.guard?.();
351
+ state.guidance?.();
352
+ for (const dispose of state.owned)
353
+ dispose();
354
+ admittedRealms.delete(ctx);
355
+ });
356
+ try {
357
+ reconcile();
358
+ admittedRealms.set(ctx, reconcile);
359
+ }
360
+ catch (error) {
361
+ retire();
362
+ throw error;
363
+ }
384
364
  }
385
365
  //# sourceMappingURL=role-subagents.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsmm/dsmm",
3
- "version": "0.3.30",
3
+ "version": "0.3.31",
4
4
  "description": "Native Deepwork roles, routing, profiles, and permission controls for DeepSeek Harness.",
5
5
  "author": "Hugefiver",
6
6
  "license": "LicenseRef-AAAPL",