@dsmm/dsmm 0.3.30 → 0.3.32

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.
Files changed (48) hide show
  1. package/agent-presets/dsmm-oracle/agent.cordis.yml +2 -0
  2. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +2 -0
  3. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +2 -0
  4. package/agent-presets/dsmm-planner/agent.cordis.yml +1 -0
  5. package/agent-presets/dsmm-reviewer/agent.cordis.yml +2 -0
  6. package/docs/compatibility.md +2 -2
  7. package/dsh-plugin.json +1 -1
  8. package/lib/agent-prompt-scope.d.ts +3 -2
  9. package/lib/agent-prompt-scope.js +11 -16
  10. package/lib/core-permission-authority.js +4 -0
  11. package/lib/host-llm.d.ts +5 -0
  12. package/lib/host-llm.js +9 -0
  13. package/lib/index.js +13 -16
  14. package/lib/live-pi-ai-owner.d.ts +1 -0
  15. package/lib/live-pi-ai-owner.js +2 -1
  16. package/lib/mode.d.ts +3 -2
  17. package/lib/mode.js +8 -12
  18. package/lib/model-routing.js +2 -2
  19. package/lib/native-admission.d.ts +2 -0
  20. package/lib/native-admission.js +80 -24
  21. package/lib/native-pi-ai-wire.js +2 -2
  22. package/lib/native-scope.d.ts +3 -3
  23. package/lib/native-scope.js +5 -6
  24. package/lib/preset-skills.d.ts +3 -2
  25. package/lib/preset-skills.js +12 -14
  26. package/lib/resident-root.d.ts +10 -0
  27. package/lib/resident-root.js +151 -0
  28. package/lib/role-identity.d.ts +2 -2
  29. package/lib/role-identity.js +1 -5
  30. package/lib/role-llm-runtime.d.ts +12 -2
  31. package/lib/role-llm-runtime.js +28 -18
  32. package/lib/role-llm.d.ts +2 -0
  33. package/lib/role-llm.js +1 -0
  34. package/lib/role-policy.d.ts +2 -0
  35. package/lib/role-policy.js +10 -10
  36. package/lib/role-routing.d.ts +1 -1
  37. package/lib/role-routing.js +4 -3
  38. package/lib/role-subagents.d.ts +2 -2
  39. package/lib/role-subagents.js +43 -63
  40. package/package.json +1 -1
  41. package/prompts/source/agents/plan-critic.md +2 -0
  42. package/prompts/source/agents/planner.md +1 -0
  43. package/prompts/source/agents/reviewer.md +2 -0
  44. package/skills/avoid-ai-slop/SKILL.md +1 -1
  45. package/skills/brainstorming/SKILL.md +1 -1
  46. package/skills/receiving-code-review/SKILL.md +2 -2
  47. package/skills/requesting-code-review/SKILL.md +1 -1
  48. package/skills/writing-plans/SKILL.md +1 -1
@@ -26,6 +26,8 @@
26
26
 
27
27
  Evaluate existing evidence by material relevance; request missing or affected coverage instead of blanket reruns for unrelated code, dependency, or environment changes. Explicitly name any important behavior you considered but cannot judge, why, and the missing evidence; do not require a dedicated heading, list, or quota. The orchestrator coordinates global/heavy verification; don't duplicate it or waive required safety, release, pre-commit, or user checks.
28
28
 
29
+ Trace a local defect far enough to establish its impact and the smallest correction. Prefer a local fix when it restores the contract. Extend the investigation only as far as the changed behavior or a concrete risk warrants; assess independent defects in the diff on their own impact. Look for unnecessary complexity in the diff, such as an abstraction with no current consumer or a check that repeats an upstream guarantee. When complexity is the only issue, suggest a simpler alternative as non-blocking advice. Process rules about stopping your own unnecessary work do not require cleanup of the reviewed diff. If the change violates a requirement or creates a concrete safety risk, report that finding separately at its actual severity.
30
+
29
31
  Report material findings first with severity when useful, file path, concrete evidence, likely impact, and the smallest valid correction. Judge whether useful functionality is complete, interfaces are clear, and meaningful regression and real-surface evidence support the result. Review informs engineering judgment; it is not delivery authorization or a protocol gate. Repeat only the affected review for a newly identified or resolved blocker, a substantive correction, or relevant new evidence; repeated concerns or unchanged uncertainty do not justify another pass. Apply strict review only when the user explicitly requests it or a scoped, concrete high-risk condition warrants it.
30
32
 
31
33
  Use direct read/search tools first; a leaf read-only lookup may verify one finding but returns evidence, not delegated judgment. Never dispatch planner, reviewer, any Oracle profile, plan-critic, clarifier, coordinator, or an implementation agent.
@@ -26,6 +26,8 @@
26
26
 
27
27
  Evaluate existing evidence by material relevance; request missing or affected coverage instead of blanket reruns for unrelated code, dependency, or environment changes. Explicitly name any important behavior you considered but cannot judge, why, and the missing evidence; do not require a dedicated heading, list, or quota. The orchestrator coordinates global/heavy verification; don't duplicate it or waive required safety, release, pre-commit, or user checks.
28
28
 
29
+ Trace a local defect far enough to establish its impact and the smallest correction. Prefer a local fix when it restores the contract. Extend the investigation only as far as the changed behavior or a concrete risk warrants; assess independent defects in the diff on their own impact. Look for unnecessary complexity in the diff, such as an abstraction with no current consumer or a check that repeats an upstream guarantee. When complexity is the only issue, suggest a simpler alternative as non-blocking advice. Process rules about stopping your own unnecessary work do not require cleanup of the reviewed diff. If the change violates a requirement or creates a concrete safety risk, report that finding separately at its actual severity.
30
+
29
31
  Report material findings first with severity when useful, file path, concrete evidence, likely impact, and the smallest valid correction. Judge whether useful functionality is complete, interfaces are clear, and meaningful regression and real-surface evidence support the result. Review informs engineering judgment; it is not delivery authorization or a protocol gate. Repeat only the affected review for a newly identified or resolved blocker, a substantive correction, or relevant new evidence; repeated concerns or unchanged uncertainty do not justify another pass. Apply strict review only when the user explicitly requests it or a scoped, concrete high-risk condition warrants it.
30
32
 
31
33
  Use direct read/search tools first; a leaf read-only lookup may verify one finding but returns evidence, not delegated judgment. Never dispatch planner, reviewer, any Oracle profile, plan-critic, clarifier, coordinator, or an implementation agent.
@@ -30,6 +30,8 @@
30
30
 
31
31
  Treat as blockers only issues that contradict an explicit requirement or constraint, omit a necessary prerequisite, preserve a known failing regression, create a concrete security/data-loss/compatibility/release/runtime risk, or conflict with an external API, provider, protocol, platform, packaging, or release contract. Recommend the smallest useful correction without expanding scope.
32
32
 
33
+ For a missing required safeguard, cite the governing requirement and the gap. For an additional safeguard, treat its absence as a blocker only when a concrete failure path escapes existing controls. If the plan makes valid work wait for redundant validation or approval, recommend removing that gate while retaining the actual boundary check. Hypothetical future uses and optional hardening do not hold up implementation.
34
+
33
35
  Everything else is a non-blocking note and does not delay implementation. Give current findings and supporting evidence as clear prose rather than protocol fields or approval tokens. Every substantive blocker must be corrected, rebutted with concrete evidence, or escalated for clarification; it cannot be relabeled advisory and ignored. Critique informs judgment and does not authorize implementation or delivery.
34
36
 
35
37
  Do not require another review merely because the plan changed. Revisit only affected claims and dependent risks when a blocker is newly identified or resolved, or relevant new evidence or another substantive input could change the prior conclusion. Wording changes, repeated concerns, and unchanged uncertainty are not progress; stop and return an unresolved blocker rather than continuing a no-progress loop. Do not require hashes, a fixed receipt or verdict format, a fixed iteration count, or an open-ended loop. Do not object to preference, optional polish, or a merely better approach.
@@ -19,6 +19,7 @@
19
19
  - Read, search, and analyze. Return a complete Markdown product plan when durable coordination is useful or requested; the authorized coordinator persists it if an artifact is needed. This native planner is read-only, including plan files: do not use shell, write/edit or a child proxy to persist one. Non-product coordination and reports stay in conversation unless explicitly requested as deliverables. Do not edit source, tests, configuration, or product documentation.
20
20
  - Reserve `docs/superpowers/specs/` and `docs/superpowers/plans/` for final product requirements to be delivered. Each artifact describes one final deliverable, not development decisions, rejected alternatives, assumption rationale/cost, or change history. Changed requirements use separate plans. Non-product tasks, regardless of complexity, use conversation coordination or a task-owned temporary plan outside those directories.
21
21
  - Plan around the ideal end state, dependencies, interfaces, material risks, wave goals, and useful outcome evidence. Record decisions an implementer cannot safely infer: necessary paths and names, interface signatures and types, requirement-fixed values, and decisive test assertions or observable results. Do not transcribe implementation bodies already determined by those decisions. Treat steps and ordering as informed guidance that execution may adjust as evidence changes, not as a hard script.
22
+ - Choose the simplest design that delivers the approved behavior and preserves contracts outside the authorized change. Validate at trust boundaries and reuse an established guarantee for as long as it holds. Add an abstraction, retry, fallback, lock, or approval step only when a current requirement or concrete failure path needs it; keep independent work moving.
22
23
  - Plan verification around valid requirements, functionality, and external interfaces, including material input classes and failure conditions implied by the approved behavior and local contracts. Attach plausible regression coverage to the owning task; when an important behavior remains unjudged, state why and what evidence is missing without imposing a fixed review-focus heading, list, or quota. Do not expand scope from speculation or add descriptive-text locks. Requirement changes update tests; removed components lose their dedicated tests rather than gaining absence tests. Git commits bound compatibility: interim uncommitted behavior need not be preserved, but existing committed contracts and API/security/data/permission/irreversible-action authorization remain binding.
23
24
  - Return unresolved software design choices that affect implementation to the orchestrator for `brainstorming`; use `writing-plans` techniques proportionally rather than imposing ceremony.
24
25
  - Use direct tools first. A leaf read-only `code-search`, `doc-search`, or equivalent lookup is allowed only to resolve a named fact. If evidence leaves a genuinely difficult decision, report the blocker to the orchestrator for optional `hard-reasoning`; strict or high-risk conditions alone do not qualify.
@@ -26,6 +26,8 @@
26
26
 
27
27
  Evaluate existing evidence by material relevance; request missing or affected coverage instead of blanket reruns for unrelated code, dependency, or environment changes. Explicitly name any important behavior you considered but cannot judge, why, and the missing evidence; do not require a dedicated heading, list, or quota. The orchestrator coordinates global/heavy verification; don't duplicate it or waive required safety, release, pre-commit, or user checks.
28
28
 
29
+ Trace a local defect far enough to establish its impact and the smallest correction. Prefer a local fix when it restores the contract. Extend the investigation only as far as the changed behavior or a concrete risk warrants; assess independent defects in the diff on their own impact. Look for unnecessary complexity in the diff, such as an abstraction with no current consumer or a check that repeats an upstream guarantee. When complexity is the only issue, suggest a simpler alternative as non-blocking advice. Process rules about stopping your own unnecessary work do not require cleanup of the reviewed diff. If the change violates a requirement or creates a concrete safety risk, report that finding separately at its actual severity.
30
+
29
31
  Report material findings first with severity when useful, file path, concrete evidence, likely impact, and the smallest valid correction. Judge whether useful functionality is complete, interfaces are clear, and meaningful regression and real-surface evidence support the result. Review informs engineering judgment; it is not delivery authorization or a protocol gate. Repeat only the affected review for a newly identified or resolved blocker, a substantive correction, or relevant new evidence; repeated concerns or unchanged uncertainty do not justify another pass. Apply strict review only when the user explicitly requests it or a scoped, concrete high-risk condition warrants it.
30
32
 
31
33
  Use direct read/search tools first; a leaf read-only lookup may verify one finding but returns evidence, not delegated judgment. Never dispatch planner, reviewer, any Oracle profile, plan-critic, clarifier, coordinator, or an implementation agent.
@@ -2,7 +2,7 @@
2
2
 
3
3
  **DSMM supports DSH `>=0.2.1-rc.2 <0.2.2-0 || >=0.2.2-rc.1 <0.3.0` and Node.js 22 or later.** Install DSMM into a DSH profile. The CLI's profile resolver supplies DSH, Cordis, Schemastery and Pi SDK modules from the running DSH installation. The release tarball declares no host SDK dependencies or peers, so package managers neither install them for DSMM nor keep the previous version's SDKs to satisfy DSMM peer references. A linked development checkout retains its host peer declarations.
4
4
 
5
- After upgrading a profile, let its package manager update the lockfile and restart DSH. An explicitly installed or independently required profile-local DSH package can still shadow the host; review its owner before removing it. Do not force-enable an incompatible provider or change the native HTTP selection to work around a version mismatch.
5
+ When upgrading from DSMM 0.3.30 or earlier, let the profile package manager update the lockfile, restart DSH once and reopen the original conversation. Subsequent replacements between Cores that support resident root handoff can continue the same open root conversation without a Host restart; changes to other startup-only Host services may still require one. An explicitly installed or independently required profile-local DSH package can still shadow the host; review its owner before removing it. Do not force-enable an incompatible provider or change the native HTTP selection to work around a version mismatch.
6
6
 
7
7
  ## Supported integration
8
8
 
@@ -48,7 +48,7 @@ DSMM runs identically on 0.2.1 and 0.2.2 Hosts except where 0.2.2 changed public
48
48
 
49
49
  DSMM runs against the unpatched native DSH packages: it installs no Host-side patches and injects no bootstrap flags. Historical support is limited to the existing native reader and validated continuation paths, with no blanket guarantee for historical package versions or additional behavior repair or migration. Native-readable records remain available through history surfaces. Supported persisted DSMM sessions resume with a fresh admission built from the current deployment; persisted mode choices remain user intent, while old delegation authority never survives.
50
50
 
51
- Root and native continuable-child activations load current DSMM prompts/skills/roles and the selected profile ID's latest valid content. Explicit baseline and global-default sources remain distinct. Old immutable revisions and runtime captures are not required for a valid native DSMM descriptor. Missing identity or conflicting/unsafe selection metadata refuses; missing or invalid current named content does not fall back. Parent ownership, catalog/own descriptor, provider, independent composition, readonly/filter/depth and cancellation boundaries are validated before publication. Resident Agents do not hot-switch. Settled one-shot children stay non-resumable.
51
+ Root and native continuable-child activations load current DSMM prompts/skills/roles and the selected profile ID's latest valid content. Explicit baseline and global-default sources remain distinct. Old immutable revisions and runtime captures are not required for a valid native DSMM descriptor. Missing identity or conflicting/unsafe selection metadata refuses; missing or invalid current named content does not fall back. Parent ownership, catalog/own descriptor, provider, independent composition, readonly/filter/depth and cancellation boundaries are validated before publication. Saving a profile does not hot-switch resident Agents. When the Core itself is replaced, a participating root retains its native history and receives a fresh admission for its next turn. Old tool calls and approvals do not transfer. Resident children are not adopted by the replacement Core; settled one-shot children stay non-resumable.
52
52
 
53
53
  DSH `0.2.1-rc.2` still checks image capabilities against historical `agent.options` before request routing in affected root model-switch and cold-child flows. Text requests can use a current available route while images fail because the historical model is missing or lacks image support. DSH exposes no public atomic route/options update for that preflight; DSMM leaves the refusal intact and does not modify readonly options or fake capabilities. Resolution requires a public route-aware preflight or supported pre-activation options hook. Recheck both root and child scenarios during each authorized DSH upgrade.
54
54
 
package/dsh-plugin.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifestVersion": "0.15",
4
4
  "id": "com.hugefiver.dsmm",
5
5
  "name": "DSMM",
6
- "version": "0.3.30",
6
+ "version": "0.3.32",
7
7
  "facets": {
8
8
  "host": {
9
9
  "entry": "lib/index.js",
@@ -1,6 +1,7 @@
1
- import type { DshAgent, DshContext } from "./dsh-types.js";
1
+ import { type Context } from "@deepseek-ai/cordis";
2
+ import type { DshAgent } from "./dsh-types.js";
2
3
  import type { DsmmSettingsGetter } from "./settings.js";
3
4
  import type { DsmmRolePolicy } from "./role-policy.js";
4
5
  import type { DeepworkModeController } from "./state.js";
5
- export declare function registerAgentPromptScope(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, policy: DsmmRolePolicy, agent: DshAgent, signal: AbortSignal): void;
6
+ export declare function registerAgentPromptScope(ctx: Context, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, policy: DsmmRolePolicy, agent: DshAgent): void;
6
7
  //# sourceMappingURL=agent-prompt-scope.d.ts.map
@@ -1,21 +1,19 @@
1
- import { getTraceable, symbols } from "@deepseek-ai/cordis";
1
+ import { symbols } from "@deepseek-ai/cordis";
2
2
  import { buildDsmmLocaleGuidance } from "./locale-guidance.js";
3
- import { agentForScope, nativeAgentContext } from "./native-scope.js";
3
+ import { agentScopeService } from "./native-scope.js";
4
4
  import { registerRoleHarnessIdentity } from "./role-identity.js";
5
5
  const agentPrompts = new WeakMap();
6
- export function registerAgentPromptScope(ctx, controller, getSettings, policy, agent, signal) {
7
- signal.throwIfAborted();
8
- const existing = agentPrompts.get(agent);
6
+ export function registerAgentPromptScope(ctx, controller, getSettings, policy, agent) {
7
+ const existing = agentPrompts.get(ctx);
9
8
  if (existing !== undefined) {
10
9
  existing.reconcile();
11
10
  return;
12
11
  }
13
- const agentCtx = nativeAgentContext(agent);
14
12
  let retired = false;
15
13
  const state = { reconcile() {
16
14
  if (retired)
17
15
  return;
18
- const prompt = agentCtx.get("agentPresets")?.serviceFor({ ctx: agentCtx }, "systemPrompt") ?? agentCtx.get("systemPrompt");
16
+ const prompt = agentScopeService(ctx, "systemPrompt");
19
17
  const realm = Reflect.get(prompt, symbols.original) ?? prompt;
20
18
  if (state.promptRealm !== realm) {
21
19
  state.identity?.();
@@ -23,8 +21,8 @@ export function registerAgentPromptScope(ctx, controller, getSettings, policy, a
23
21
  state.identity = undefined;
24
22
  state.role = undefined;
25
23
  state.child = undefined;
26
- state.locale = getTraceable(agentCtx, prompt).section({ name: "dsmm:locale", order: 49, text(context) {
27
- if (context.scope !== agent && agentForScope(ctx, context.scope) !== agent)
24
+ state.locale = prompt.section({ name: "dsmm:locale", order: 49, text(context) {
25
+ if (context.scope !== agent)
28
26
  return "";
29
27
  const settings = getSettings(agent);
30
28
  return settings.locale === undefined ? "" : buildDsmmLocaleGuidance(settings);
@@ -35,7 +33,7 @@ export function registerAgentPromptScope(ctx, controller, getSettings, policy, a
35
33
  if (state.role === identity.role && state.child === identity.child)
36
34
  return;
37
35
  state.identity?.();
38
- state.identity = identity.role === undefined ? undefined : registerRoleHarnessIdentity(agent, identity.role, identity.child);
36
+ state.identity = identity.role === undefined ? undefined : registerRoleHarnessIdentity(prompt, identity.role, identity.child);
39
37
  state.role = identity.role;
40
38
  state.child = identity.child;
41
39
  } };
@@ -43,18 +41,15 @@ export function registerAgentPromptScope(ctx, controller, getSettings, policy, a
43
41
  if (retired)
44
42
  return;
45
43
  retired = true;
46
- signal.removeEventListener("abort", retire);
47
44
  state.stopMode?.();
48
45
  state.identity?.();
49
46
  state.locale?.();
50
- if (agentPrompts.get(agent) === state)
51
- agentPrompts.delete(agent);
47
+ agentPrompts.delete(ctx);
52
48
  };
53
49
  state.stopMode = controller.watch(changed => { if (changed === agent)
54
50
  state.reconcile(); });
55
- agentPrompts.set(agent, state);
56
- signal.addEventListener("abort", retire, { once: true });
57
- agentCtx.effect(() => retire);
51
+ agentPrompts.set(ctx, state);
52
+ ctx.effect(() => retire);
58
53
  try {
59
54
  state.reconcile();
60
55
  }
@@ -4,6 +4,7 @@ import { scopeLifetime } from "./lifetime.js";
4
4
  import { PermissionRefusal, permissionOriginal } from "./permission-control.js";
5
5
  import { DSMM_DISPATCHER_ROLE, DSMM_ROLES, isRootRole } from "./roles.js";
6
6
  import { capturedRoleInvocation } from "./role-invocation.js";
7
+ import { assertResidentRootCurrent } from "./resident-root.js";
7
8
  function sameFacts(a, b) {
8
9
  return a.length === b.length && a.every((value, index) => value === b[index]);
9
10
  }
@@ -60,6 +61,7 @@ export function createCorePermissionAuthority(ctx, options) {
60
61
  }
61
62
  };
62
63
  const coreDomain = (agent) => {
64
+ assertResidentRootCurrent(agent, integration());
63
65
  const core = ctx.get("dsmmCoreLlmOwner"), profiles = ctx.get("dsmmProfileRuntime");
64
66
  const ownerCore = coreOwner.get("dsmmCoreLlmOwner"), realmCore = agent.ctx.get("dsmmCoreLlmOwner");
65
67
  if (core === undefined || ownerCore === undefined || realmCore === undefined || profiles === undefined
@@ -170,6 +172,8 @@ export function createCorePermissionAuthority(ctx, options) {
170
172
  current,
171
173
  captureIntegrity(exec) {
172
174
  const chain = ancestry(exec), realms = chain.map(agent => agent.ctx);
175
+ for (const agent of chain)
176
+ assertResidentRootCurrent(agent, integration());
173
177
  const signals = chain.map(agent => {
174
178
  let signal = physicalLifetimes.get(agent);
175
179
  if (signal === undefined) {
package/lib/host-llm.d.ts CHANGED
@@ -57,10 +57,14 @@ export declare function snapshotDsmmCall(config: DsmmLlmCallConfig): DsmmLlmCall
57
57
  export declare function preparedConfigMatches(request: GenerateOptions, config: DsmmLlmCallConfig): boolean;
58
58
  /** Consumption is synchronous, including rejected dispatches and streams never iterated. */
59
59
  export declare function singleUsePreparedStream(dispatch: PreparedLlmCall["stream"]): PreparedLlmCall["stream"];
60
+ declare const requestOwnerRuntime: unique symbol;
61
+ /** The marker selects the request preparation hook; admission still checks the exact owner. */
62
+ export declare function isDsmmAwareLlmRuntime(value: unknown): boolean;
60
63
  /** Native execution service; an optional stock collaborator supports explicit isolated hosts. */
61
64
  export declare class DsmmAwareLlmRuntime extends LlmRuntime {
62
65
  readonly stock: LlmRuntime | undefined;
63
66
  private readonly requestOwner;
67
+ readonly [requestOwnerRuntime] = true;
64
68
  private readonly calls;
65
69
  private readonly admitted;
66
70
  private readonly preparedRequests;
@@ -95,4 +99,5 @@ export declare class DsmmAwareLlmRuntime extends LlmRuntime {
95
99
  imageRequestPricing(...args: Parameters<LlmRuntime["imageRequestPricing"]>): import("@deepseek-ai/dsh-llm").LlmImageRequestPricing | undefined;
96
100
  fileRequestText(...args: Parameters<LlmRuntime["fileRequestText"]>): string;
97
101
  }
102
+ export {};
98
103
  //# sourceMappingURL=host-llm.d.ts.map
package/lib/host-llm.js CHANGED
@@ -5,6 +5,7 @@ import { isDeepStrictEqual } from "node:util";
5
5
  import { copyRouteJson } from "./route-json.js";
6
6
  import { modelRouteFromCall } from "./role-llm.js";
7
7
  import { classifyDsmmAgent } from "./runtime-integration.js";
8
+ import { assertResidentRootCurrent } from "./resident-root.js";
8
9
  import { latestNativeModelSelection } from "./role-routing.js";
9
10
  import { capturedRoleInvocation } from "./role-invocation.js";
10
11
  export function captureDsmmEffortSource(agent) {
@@ -66,10 +67,16 @@ export function singleUsePreparedStream(dispatch) {
66
67
  return dispatch(request);
67
68
  };
68
69
  }
70
+ const requestOwnerRuntime = Symbol.for("@dsmm/dsmm/request-owner-runtime");
71
+ /** The marker selects the request preparation hook; admission still checks the exact owner. */
72
+ export function isDsmmAwareLlmRuntime(value) {
73
+ return value instanceof LlmRuntime && Reflect.get(value, requestOwnerRuntime) === true;
74
+ }
69
75
  /** Native execution service; an optional stock collaborator supports explicit isolated hosts. */
70
76
  export class DsmmAwareLlmRuntime extends LlmRuntime {
71
77
  stock;
72
78
  requestOwner;
79
+ [requestOwnerRuntime] = true;
73
80
  calls = new WeakMap();
74
81
  admitted = new WeakSet();
75
82
  preparedRequests = new WeakSet();
@@ -176,6 +183,8 @@ export class DsmmAwareLlmRuntime extends LlmRuntime {
176
183
  && (fallback ? isDeepStrictEqual(config, native.config) : proposal === native.config);
177
184
  if (requiresDsmmCallAdmission(config, classifier, classified ? undefined : agent))
178
185
  throw new LlmError("Enhanced requests require their exact Host proposal", "INVALID_PREPARED_CALL");
186
+ if (agent !== undefined)
187
+ assertResidentRootCurrent(agent, this.ctx.get("dsmmNativeAdmission"));
179
188
  return config;
180
189
  }
181
190
  async prepareCall(proposal, signal, configure) {
package/lib/index.js CHANGED
@@ -4,6 +4,7 @@ import { hasShellGuardConstraint, registerSafetyGuards } from "./guards.js";
4
4
  import { registerDeepworkPrompt } from "./mode.js";
5
5
  import { registerAgentSkills } from "./preset-skills.js";
6
6
  import { prepareAdmissionModelRoute, registerModelRouting } from "./model-routing.js";
7
+ import { bindCoreLlmAdmission } from "./role-llm-runtime.js";
7
8
  import { registerHeadlessRoleTools, registerNativeSubagentControls } from "./role-subagents.js";
8
9
  import { registerRolePresets } from "./preset-registry.js";
9
10
  import { registerRoleProviders } from "./role-providers.js";
@@ -112,7 +113,7 @@ export async function apply(input, config = {}, startupOptions = {}) {
112
113
  }
113
114
  };
114
115
  assertCurrent();
115
- return Object.freeze({ agent: frame.agent, admission: captured, capture: captured, epoch: captured.epoch, signal, assertCurrent });
116
+ return bindCoreLlmAdmission(frame, { agent: frame.agent, admission: captured, capture: captured, epoch: captured.epoch, signal, assertCurrent });
116
117
  } });
117
118
  const nativeAdmission = admission;
118
119
  if (startup.settings.modules.deepwork.enabled) {
@@ -137,26 +138,21 @@ export async function apply(input, config = {}, startupOptions = {}) {
137
138
  await registerLspRuntime(ctx, startup.settings.lsp, getSettings);
138
139
  lifetime.signal.throwIfAborted();
139
140
  const installed = new WeakSet();
140
- admission.activate(async (agent, candidate) => {
141
+ admission.activate(async (agent, candidate, scope) => {
141
142
  candidate.subagentRuntime = () => runtimeAdmissionView(ctx);
142
- const scope = agent.ctx;
143
- registerAgentPromptScope(ctx, controller, candidate, policy, agent, nativeAdmission.lifetime.signal);
143
+ registerAgentPromptScope(scope, controller, candidate, policy, agent);
144
144
  if (startup.settings.modules.deepwork.enabled) {
145
- registerAgentSkills(scope, controller, candidate, agent, admission.lifetime.signal, () => !nativeAdmission.isSelecting(agent));
146
- registerDeepworkPrompt(scope, controller, candidate, { section: startup.profile.section ?? startup.global.section }, agent, admission.lifetime.signal);
145
+ registerAgentSkills(scope, controller, candidate, agent, () => !nativeAdmission.isSelecting(agent));
146
+ registerDeepworkPrompt(scope, controller, candidate, { section: startup.profile.section ?? startup.global.section }, agent);
147
147
  }
148
- if (installed.has(agent)) {
149
- if (startup.settings.modules.deepwork.enabled && ctx.get("subagents") !== undefined)
150
- await registerHeadlessRoleTools(scope, controller, candidate, policy, nativeAdmission, agent);
151
- return;
148
+ if (!installed.has(scope)) {
149
+ registerModelRouting(scope, controller, candidate, agent);
150
+ registerSafetyGuards(scope, controller, candidate, policy, commandApprovals);
151
+ installed.add(scope);
152
152
  }
153
- registerModelRouting(scope, controller, candidate, agent);
154
- registerSafetyGuards(scope, controller, candidate, policy, commandApprovals);
155
- if (startup.settings.modules.deepwork.enabled) {
156
- if (ctx.get("subagents") !== undefined)
157
- await registerHeadlessRoleTools(scope, controller, candidate, policy, nativeAdmission, agent);
153
+ if (startup.settings.modules.deepwork.enabled && scope.get("subagents") !== undefined) {
154
+ registerHeadlessRoleTools(scope, controller, candidate, policy, nativeAdmission, agent);
158
155
  }
159
- installed.add(agent);
160
156
  });
161
157
  registerDsmmTuiAdapter(ctx, { controller, getSettings, profiles, deployment });
162
158
  ctx.inject(["typert"], scope => { registerConfigRpc(scope, deployment, startup.settings, () => profiles, startup.sources, mountedPermission); new DsmmProfilesHost(scope, profiles); registerRoleControlRpc(scope, nativeAdmission); });
@@ -175,6 +171,7 @@ export async function apply(input, config = {}, startupOptions = {}) {
175
171
  return; detach(); if (!lifetime.signal.aborted)
176
172
  installPermissions(); }, { global: true });
177
173
  }
174
+ await admission.restoreResidentRoots();
178
175
  }
179
176
  export default { name, inject, Config, apply };
180
177
  //# sourceMappingURL=index.js.map
@@ -6,6 +6,7 @@ type RegistrationHandle = ReturnType<LlmRuntime["registerAdapter"]>;
6
6
  /** Captures public registering-fiber provenance; the native runtime remains the sole registry. */
7
7
  export declare class LivePiAiOwner implements DsmmLlmRouteResolver {
8
8
  private readonly native;
9
+ readonly isMissingProviderError: (error: unknown) => boolean;
9
10
  private readonly registrations;
10
11
  constructor(_ctx: Context, native: LlmRuntime);
11
12
  supportsNativeStop(provider: string): boolean;
@@ -6,7 +6,7 @@ import { brandString } from "@deepseek-ai/dsh-brand";
6
6
  import { isDeepStrictEqual } from "node:util";
7
7
  import { createDsmmPiAiProviderOwner } from "./native-pi-ai-wire.js";
8
8
  import { snapshotDsmmCall } from "./host-llm.js";
9
- import { DsmmMissingProviderError, modelRouteToCall } from "./role-llm.js";
9
+ import { DsmmMissingProviderError, isMissingProviderError, modelRouteToCall } from "./role-llm.js";
10
10
  import { normalizeModelRouteJson } from "./route-json.js";
11
11
  const original = (value) => Reflect.get(value, symbols.original) ?? value;
12
12
  const providerConfig = (scope) => {
@@ -16,6 +16,7 @@ const providerConfig = (scope) => {
16
16
  /** Captures public registering-fiber provenance; the native runtime remains the sole registry. */
17
17
  export class LivePiAiOwner {
18
18
  native;
19
+ isMissingProviderError = isMissingProviderError;
19
20
  registrations = new Map();
20
21
  constructor(_ctx, native) {
21
22
  this.native = native;
package/lib/mode.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import type { DshAgent, DshContext } from "./dsh-types.js";
1
+ import type { Context } from "@deepseek-ai/cordis";
2
+ import type { DshAgent } from "./dsh-types.js";
2
3
  import type { Config } from "./index.js";
3
4
  import type { DsmmSettingsGetter } from "./settings.js";
4
5
  import type { DeepworkModeController } from "./state.js";
5
6
  /** The admission installer owns scope selection; assembly reads the immutable Agent configuration. */
6
- export declare function registerDeepworkPrompt(readyCtx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, config: Config, agent: DshAgent, lifetime: AbortSignal): void;
7
+ export declare function registerDeepworkPrompt(ctx: Context, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, config: Config, agent: DshAgent): void;
7
8
  //# sourceMappingURL=mode.d.ts.map
package/lib/mode.js CHANGED
@@ -1,28 +1,26 @@
1
- import { getTraceable } from "@deepseek-ai/cordis";
2
- import { agentForScope, nativeAgentContext } from "./native-scope.js";
1
+ import { agentScopeService } from "./native-scope.js";
3
2
  import { buildDeepworkPrompt } from "./prompts.js";
4
3
  import { resolveAdmittedDsmmRole } from "./role-policy.js";
5
4
  const bindings = new WeakMap();
6
5
  /** The admission installer owns scope selection; assembly reads the immutable Agent configuration. */
7
- export function registerDeepworkPrompt(readyCtx, controller, getSettings, config, agent, lifetime) {
8
- const refresh = bindings.get(agent);
6
+ export function registerDeepworkPrompt(ctx, controller, getSettings, config, agent) {
7
+ const refresh = bindings.get(ctx);
9
8
  if (refresh) {
10
9
  refresh();
11
10
  return;
12
11
  }
13
- const ctx = nativeAgentContext(agent);
14
12
  let dispose;
15
13
  const reconcile = () => {
16
14
  dispose?.();
17
- const registry = ctx.get("agentPresets")?.serviceFor(agent, "systemPrompt") ?? ctx.get("systemPrompt");
15
+ const registry = agentScopeService(ctx, "systemPrompt");
18
16
  if (!registry)
19
17
  throw new Error("Deepwork requires the native system prompt service");
20
- dispose = getTraceable(ctx, registry).section({ name: "dsmm:deepwork", order: getSettings(agent).promptOrder, interpolate: false, text: "" });
18
+ dispose = registry.section({ name: "dsmm:deepwork", order: getSettings(agent).promptOrder, interpolate: false, text: "" });
21
19
  };
22
20
  // Native selection writes this step's variables on the return path of the waterfall.
23
21
  const stopAssembly = ctx.on("system-prompt/assemble", async (_assembly, context, next) => {
24
22
  const assembled = await next();
25
- if (context.scope !== agent && agentForScope(readyCtx, context.scope) !== agent)
23
+ if (context.scope !== agent)
26
24
  return assembled;
27
25
  if (context.signal?.aborted || getSettings.subagentRuntime?.().deliveryFenceReady === false)
28
26
  return assembled;
@@ -44,10 +42,8 @@ export function registerDeepworkPrompt(readyCtx, controller, getSettings, config
44
42
  }
45
43
  return assembled;
46
44
  }, { prepend: true });
47
- bindings.set(agent, reconcile);
48
- const retire = () => { stopAssembly(); dispose?.(); bindings.delete(agent); lifetime.removeEventListener("abort", retire); };
49
- lifetime.addEventListener("abort", retire, { once: true });
50
- ctx.effect(() => retire);
45
+ bindings.set(ctx, reconcile);
46
+ ctx.effect(() => () => { stopAssembly(); dispose?.(); bindings.delete(ctx); });
51
47
  reconcile();
52
48
  }
53
49
  //# sourceMappingURL=mode.js.map
@@ -1,5 +1,5 @@
1
1
  import { LlmError } from "@deepseek-ai/dsh-llm";
2
- import { DsmmAwareLlmRuntime } from "./host-llm.js";
2
+ import { isDsmmAwareLlmRuntime } from "./host-llm.js";
3
3
  import { applyModelRoute, clearRoleRouteLock, currentRolePolicyState, currentRoleRouteLock, effectiveRoleFallbackRoutes, establishRolePolicy, hostModelSelection, latestModelSelectionSeq, latestNativeModelSelection, liveRolePolicyIdentity, nativeModelSelectionWasAccepted, orderedModelRoutes, persistedRoleRoute, pinRoleRoute, restoreRolePolicyAndLock, roleRouteLock, selectInitialModelRoute, selectInitialModelRouteChoice, selectModelRouteForNextStep, sameExactModelRoute, sameModelRoute, takeAdmittedRecoveryRoute } from "./role-routing.js";
4
4
  import { childOwnedSessionEvents, sessionEvents } from "./session-scope.js";
5
5
  import { isCurrentRecoveryStep } from "./recovery-policy.js";
@@ -27,7 +27,7 @@ export function registerModelRouting(ctx, controller, getSettings, agent) {
27
27
  const assembledSelections = new WeakMap();
28
28
  let dispose, disposeAgent, disposeAssembly, disposeFence;
29
29
  try {
30
- const owned = agent !== undefined && readyCtx.get?.("llm") instanceof DsmmAwareLlmRuntime;
30
+ const owned = agent !== undefined && isDsmmAwareLlmRuntime(readyCtx.get?.("llm"));
31
31
  let recovery;
32
32
  registerRuntimeRecovery(readyCtx, controller, getSettings, prepare => { recovery = prepare; });
33
33
  disposeAssembly = readyCtx.on("system-prompt/assemble", async (_assembly, context, next) => {
@@ -56,10 +56,12 @@ export declare class NativeAdmission {
56
56
  private readonly admissionRouteFailures;
57
57
  private readonly setupSelectionCursors;
58
58
  private ready;
59
+ private readonly scopes;
59
60
  private install?;
60
61
  private admissionModelSelection?;
61
62
  constructor(ctx: Context, profiles: DsmmProfileRuntime, policy: DsmmRolePolicy, configurationCommitted?: (agents: readonly Agent[]) => void);
62
63
  activate(install: NonNullable<NativeAdmission["install"]>): void;
64
+ restoreResidentRoots(): Promise<void>;
63
65
  /** Bind asynchronous metadata preparation; later lifecycle callbacks only install its immutable result. */
64
66
  bindAdmissionModelSelection(hook: (agent: Agent, info: DsmmAdmissionRouteInfo) => Promise<DsmmPreparedAdmissionRoute | undefined>): void;
65
67
  private callsFor;