@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.
- package/docs/compatibility.md +2 -2
- package/dsh-plugin.json +1 -1
- package/lib/agent-prompt-scope.d.ts +3 -2
- package/lib/agent-prompt-scope.js +11 -16
- package/lib/core-permission-authority.js +4 -0
- package/lib/host-llm.d.ts +5 -0
- package/lib/host-llm.js +9 -0
- package/lib/index.js +13 -16
- package/lib/live-pi-ai-owner.d.ts +1 -0
- package/lib/live-pi-ai-owner.js +2 -1
- package/lib/mode.d.ts +3 -2
- package/lib/mode.js +8 -12
- package/lib/model-routing.js +2 -2
- package/lib/native-admission.d.ts +2 -0
- package/lib/native-admission.js +80 -24
- package/lib/native-pi-ai-wire.js +2 -2
- package/lib/native-scope.d.ts +3 -3
- package/lib/native-scope.js +5 -6
- package/lib/preset-skills.d.ts +3 -2
- package/lib/preset-skills.js +12 -14
- package/lib/resident-root.d.ts +10 -0
- package/lib/resident-root.js +151 -0
- package/lib/role-identity.d.ts +2 -2
- package/lib/role-identity.js +1 -5
- package/lib/role-llm-runtime.d.ts +12 -2
- package/lib/role-llm-runtime.js +28 -18
- package/lib/role-llm.d.ts +2 -0
- package/lib/role-llm.js +1 -0
- package/lib/role-policy.d.ts +2 -0
- package/lib/role-policy.js +10 -10
- package/lib/role-routing.d.ts +1 -1
- package/lib/role-routing.js +4 -3
- package/lib/role-subagents.d.ts +2 -2
- package/lib/role-subagents.js +43 -63
- package/package.json +1 -1
package/docs/compatibility.md
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
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:
|
|
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 {
|
|
1
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
2
2
|
import { buildDsmmLocaleGuidance } from "./locale-guidance.js";
|
|
3
|
-
import {
|
|
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
|
|
7
|
-
|
|
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 =
|
|
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 =
|
|
27
|
-
if (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(
|
|
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
|
-
|
|
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(
|
|
56
|
-
|
|
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
|
|
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
|
-
|
|
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,
|
|
146
|
-
registerDeepworkPrompt(scope, controller, candidate, { section: startup.profile.section ?? startup.global.section }, agent
|
|
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(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
154
|
-
|
|
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;
|
package/lib/live-pi-ai-owner.js
CHANGED
|
@@ -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 {
|
|
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(
|
|
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 {
|
|
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(
|
|
8
|
-
const refresh = bindings.get(
|
|
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
|
|
15
|
+
const registry = agentScopeService(ctx, "systemPrompt");
|
|
18
16
|
if (!registry)
|
|
19
17
|
throw new Error("Deepwork requires the native system prompt service");
|
|
20
|
-
dispose =
|
|
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
|
|
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(
|
|
48
|
-
|
|
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
|
package/lib/model-routing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LlmError } from "@deepseek-ai/dsh-llm";
|
|
2
|
-
import {
|
|
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")
|
|
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;
|
package/lib/native-admission.js
CHANGED
|
@@ -7,6 +7,7 @@ import { SubagentError, delegationDepthOf, foldSubagentDescriptor } from "@deeps
|
|
|
7
7
|
import { freezeSettings } from "./settings.js";
|
|
8
8
|
import { invocationView } from "./role-invocation.js";
|
|
9
9
|
import { scopeLifetime } from "./lifetime.js";
|
|
10
|
+
import { assertResidentRootCurrent, captureResidentTool, guardResidentRealm, markResidentAgent, publishResidentAgent, restoreResidentRoot } from "./resident-root.js";
|
|
10
11
|
import { sessionEvents, childOwnedSessionEvents } from "./session-scope.js";
|
|
11
12
|
import { scopeParentOf, scopeOf } from "./native-scope.js";
|
|
12
13
|
import { bindNativeParent, nativeIsOwnedBy, nativeRoots, nativeTreeRoot } from "./native-ownership.js";
|
|
@@ -98,6 +99,7 @@ export class NativeAdmission {
|
|
|
98
99
|
admissionRouteFailures = new WeakMap();
|
|
99
100
|
setupSelectionCursors = new WeakMap();
|
|
100
101
|
ready = false;
|
|
102
|
+
scopes = new Map();
|
|
101
103
|
install;
|
|
102
104
|
admissionModelSelection;
|
|
103
105
|
constructor(ctx, profiles, policy, configurationCommitted = () => { }) {
|
|
@@ -119,6 +121,8 @@ export class NativeAdmission {
|
|
|
119
121
|
});
|
|
120
122
|
ctx.effect(() => async () => {
|
|
121
123
|
const results = await Promise.allSettled([...this.activations].map(activation => activation.dispose()));
|
|
124
|
+
const scopes = await Promise.allSettled([...this.scopes.values()].map(scope => scope.fiber.dispose()));
|
|
125
|
+
results.push(...scopes);
|
|
122
126
|
await Promise.allSettled(this.activities.keys());
|
|
123
127
|
const errors = results.flatMap(result => result.status === "rejected" ? [result.reason] : []);
|
|
124
128
|
if (errors.length)
|
|
@@ -180,10 +184,21 @@ export class NativeAdmission {
|
|
|
180
184
|
ctx.on("agent/request", async (frame, next) => { await this.guardExecution(frame.agent); return next(); }, { global: true, prepend: true });
|
|
181
185
|
ctx.on("tools/execute", async (exec, next) => {
|
|
182
186
|
const native = exec.agent && await this.guardExecution(exec.agent) === "native";
|
|
183
|
-
|
|
187
|
+
if (native)
|
|
188
|
+
return this.nativeToolExecution.run(exec.token, next);
|
|
189
|
+
const caller = exec.signal;
|
|
190
|
+
if (exec.agent)
|
|
191
|
+
exec.signal = AbortSignal.any([caller, this.lifetime.signal, this.agentLifetimes.get(exec.agent).signal]);
|
|
192
|
+
try {
|
|
193
|
+
return await this.nativeToolExecution.run(exec.token, () => policy.duringToolExecution(exec, next));
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
exec.signal = caller;
|
|
197
|
+
}
|
|
184
198
|
}, { global: true, prepend: true });
|
|
185
199
|
ctx.on("tools/pre-execute", async (exec, next) => {
|
|
186
200
|
if (exec.agent) {
|
|
201
|
+
captureResidentTool(exec.agent, this, exec.token);
|
|
187
202
|
this.trackExecution(exec);
|
|
188
203
|
await this.guardExecution(exec.agent);
|
|
189
204
|
this.beginNativeToolObservation(exec);
|
|
@@ -209,6 +224,30 @@ export class NativeAdmission {
|
|
|
209
224
|
this.install = install;
|
|
210
225
|
this.ready = true;
|
|
211
226
|
}
|
|
227
|
+
async restoreResidentRoots() {
|
|
228
|
+
if (this.ctx.fiber.state === 1) {
|
|
229
|
+
// Own services become visible on ACTIVE, after the apply callback returns.
|
|
230
|
+
// Claim idle roots' native maintenance slots in that same status dispatch.
|
|
231
|
+
const detach = this.ctx.on("internal/status", fiber => {
|
|
232
|
+
if (fiber.ctx !== this.ctx.fiber.ctx || fiber.state !== 2)
|
|
233
|
+
return;
|
|
234
|
+
detach();
|
|
235
|
+
return this.restoreResidentRoots();
|
|
236
|
+
}, { global: true });
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (!this.isReady)
|
|
240
|
+
throw new SubagentError("DSMM owner is not ready for resident admission", "UNAUTHORIZED");
|
|
241
|
+
await Promise.all(nativeRoots(this.ctx.agents).map(async (agent) => {
|
|
242
|
+
try {
|
|
243
|
+
await restoreResidentRoot(agent, this, signal => this.created(agent, "startup", signal, true));
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
if (!this.lifetime.signal.aborted)
|
|
247
|
+
this.ctx.logger.warn("Resident root %s remains revoked: %s", agent.id, error);
|
|
248
|
+
}
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
212
251
|
/** Bind asynchronous metadata preparation; later lifecycle callbacks only install its immutable result. */
|
|
213
252
|
bindAdmissionModelSelection(hook) {
|
|
214
253
|
this.admissionModelSelection = hook;
|
|
@@ -577,6 +616,7 @@ export class NativeAdmission {
|
|
|
577
616
|
/** Exact process-local capture, retained after retirement so stale objects never become native. */
|
|
578
617
|
owns(agent) { return this.agentLifetimes.has(agent); }
|
|
579
618
|
async guardExecution(agent) {
|
|
619
|
+
assertResidentRootCurrent(agent, this);
|
|
580
620
|
await this.awaitingPublication.get(agent)?.promise;
|
|
581
621
|
if (!this.owns(agent)) {
|
|
582
622
|
const registry = agent.ctx.get("agents");
|
|
@@ -741,7 +781,7 @@ export class NativeAdmission {
|
|
|
741
781
|
}
|
|
742
782
|
}
|
|
743
783
|
};
|
|
744
|
-
const install = (admission) => this.installing.run({ agent, admission }, () => this.install(agent, this.getter(agent)));
|
|
784
|
+
const install = (admission) => this.installing.run({ agent, admission }, () => this.install(agent, this.getter(agent), this.scopes.get(agent)));
|
|
745
785
|
return {
|
|
746
786
|
assertCurrent,
|
|
747
787
|
prepare: async (admission, describe) => {
|
|
@@ -935,7 +975,7 @@ export class NativeAdmission {
|
|
|
935
975
|
if (this.lifetime.signal.aborted)
|
|
936
976
|
void activation.dispose().catch(error => this.ctx.logger.error(error));
|
|
937
977
|
}
|
|
938
|
-
guardTools(agent) {
|
|
978
|
+
guardTools(agent, scope) {
|
|
939
979
|
const tools = agent.ctx.get("agentPresets")?.serviceFor(agent, "tools") ?? agent.ctx.get("tools");
|
|
940
980
|
if (!tools)
|
|
941
981
|
return;
|
|
@@ -944,7 +984,7 @@ export class NativeAdmission {
|
|
|
944
984
|
return;
|
|
945
985
|
installed.add(identity);
|
|
946
986
|
this.guardedTools.set(agent, installed);
|
|
947
|
-
getTraceable(
|
|
987
|
+
getTraceable(scope, tools).guard(exec => {
|
|
948
988
|
if (exec.agent !== agent)
|
|
949
989
|
return;
|
|
950
990
|
this.assert(agent);
|
|
@@ -988,20 +1028,23 @@ export class NativeAdmission {
|
|
|
988
1028
|
return;
|
|
989
1029
|
if (this.selecting.has(agent))
|
|
990
1030
|
throw new SubagentError("Session configuration maintenance owns the blank composition", "UNAUTHORIZED");
|
|
991
|
-
if (previous.parent || (this.calls.get(agent) ?? 0) !== 0 || [...this.pending.values()].some(row => row.parent === agent)
|
|
1031
|
+
if (previous.parent || previous.owner || (this.calls.get(agent) ?? 0) !== 0 || [...this.pending.values()].some(row => row.parent === agent)
|
|
992
1032
|
|| this.ctx.agents.list().some(child => nativeIsOwnedBy(this.ctx.agents, child.id, agent)) || sessionEvents(agent.session).some(event => event.type === "turn/start"))
|
|
993
1033
|
throw new SubagentError("Preset change requires a new session", "UNAUTHORIZED");
|
|
994
1034
|
this.policy.validateRootRole(agent, previous.admission);
|
|
995
1035
|
const preset = agent.ctx.get("agentPresets")?.composedPreset(agent.ctx), scopeParent = scopeParentOf(agent);
|
|
996
|
-
this.
|
|
997
|
-
|
|
1036
|
+
const scope = this.scopes.get(agent);
|
|
1037
|
+
guardResidentRealm(agent);
|
|
1038
|
+
this.guardTools(agent, scope);
|
|
1039
|
+
await this.install(agent, this.getter(agent), scope);
|
|
998
1040
|
this.lifetime.signal.throwIfAborted();
|
|
999
1041
|
this.agentLifetimes.get(agent).signal.throwIfAborted();
|
|
1000
1042
|
if (!this.isReady || this.ctx.agents.get(agent.id) !== agent || this.live.get(agent) !== previous || scopeParentOf(agent) !== scopeParent)
|
|
1001
1043
|
throw new SubagentError("Composition changed during blank admission", "UNAUTHORIZED");
|
|
1002
1044
|
this.live.set(agent, Object.freeze({ ...previous, preset, scopeParent, dependencies: this.dependencies(agent) }));
|
|
1045
|
+
publishResidentAgent(agent, this);
|
|
1003
1046
|
}
|
|
1004
|
-
async created(agent, source, creationSignal) {
|
|
1047
|
+
async created(agent, source, creationSignal, restoring = false) {
|
|
1005
1048
|
if (this.owns(agent)) {
|
|
1006
1049
|
this.assert(agent);
|
|
1007
1050
|
return;
|
|
@@ -1040,16 +1083,26 @@ export class NativeAdmission {
|
|
|
1040
1083
|
throw new SubagentError("Delegation ceiling identity mismatch", "UNAUTHORIZED");
|
|
1041
1084
|
if (!parent && !owner && (!nativeRoots(this.ctx.agents).includes(agent) || agent.session.header.origin === "subagent" || descriptor !== undefined))
|
|
1042
1085
|
throw new SubagentError("Child requires its native creator or ceiling", "UNAUTHORIZED");
|
|
1086
|
+
const isRoot = !owner && !parent;
|
|
1087
|
+
if (restoring && !isRoot)
|
|
1088
|
+
throw new SubagentError("Resident root ownership changed", "UNAUTHORIZED");
|
|
1043
1089
|
if (owner)
|
|
1044
1090
|
this.assert(owner);
|
|
1091
|
+
if (restoring)
|
|
1092
|
+
guardResidentRealm(agent);
|
|
1093
|
+
else
|
|
1094
|
+
markResidentAgent(agent, this, isRoot);
|
|
1095
|
+
const scope = agent.ctx.plugin(function dsmmAgentGeneration() { }).ctx;
|
|
1096
|
+
this.scopes.set(agent, scope);
|
|
1045
1097
|
this.agentLifetimes.set(agent, new AbortController());
|
|
1046
1098
|
signal = AbortSignal.any([signal, this.agentLifetimes.get(agent).signal, ...owner ? [this.agentLifetimes.get(owner).signal] : []]);
|
|
1047
|
-
scopeLifetime(
|
|
1048
|
-
|
|
1099
|
+
scopeLifetime(scope, "dsmm: retire exact Agent work", () => { void this.retireAgent(agent).catch(() => { }); });
|
|
1100
|
+
scope.effect(() => async () => {
|
|
1049
1101
|
try {
|
|
1050
1102
|
await this.retireAgent(agent);
|
|
1051
1103
|
}
|
|
1052
1104
|
finally {
|
|
1105
|
+
this.scopes.delete(agent);
|
|
1053
1106
|
this.live.delete(agent);
|
|
1054
1107
|
this.candidates.delete(agent);
|
|
1055
1108
|
this.admissionRoutes.delete(agent);
|
|
@@ -1068,6 +1121,7 @@ export class NativeAdmission {
|
|
|
1068
1121
|
if (!this.isReady || this.ctx.agents.get(agent.id) !== agent || this.ctx.get("sessions")?.get(agent.id) !== agent.session
|
|
1069
1122
|
|| scopeOf(agent.ctx) !== agent || original(agent.ctx.get("agents")) !== original(this.ctx.agents)
|
|
1070
1123
|
|| this.dependencies(agent).some((value, index) => value !== dependencies[index]) || scopeParentOf(agent) !== presetScope || preset !== agent.ctx.get("agentPresets")?.composedPreset(agent.ctx)
|
|
1124
|
+
|| isRoot && !nativeRoots(this.ctx.agents).includes(agent)
|
|
1071
1125
|
|| owner && (this.assert(owner) !== ownerAdmission || (root === undefined ? !nativeIsOwnedBy(this.ctx.agents, agent.id, owner) : nativeTreeRoot(this.ctx.agents, agent) !== owner))
|
|
1072
1126
|
|| pending && parent && (this.assert(parent) !== parentAdmission || !nativeIsOwnedBy(this.ctx.agents, agent.id, parent)))
|
|
1073
1127
|
throw new SubagentError("Activation owner changed", "UNAUTHORIZED");
|
|
@@ -1177,12 +1231,7 @@ export class NativeAdmission {
|
|
|
1177
1231
|
}
|
|
1178
1232
|
this.candidates.set(agent, admission);
|
|
1179
1233
|
this.agents.add(agent);
|
|
1180
|
-
|
|
1181
|
-
agent.ctx.on("agent/pre-step", async (frame, next) => { if (frame.agent === agent)
|
|
1182
|
-
await this.ensure(agent); return next(); }, { prepend: true });
|
|
1183
|
-
agent.ctx.on("agent/request", async (frame, next) => { if (frame.agent === agent)
|
|
1184
|
-
await this.ensure(agent); return next(); }, { prepend: true });
|
|
1185
|
-
this.guardTools(agent);
|
|
1234
|
+
this.guardTools(agent, scope);
|
|
1186
1235
|
try {
|
|
1187
1236
|
if (pending)
|
|
1188
1237
|
this.policy.bindChild(agent, parent, admission, pending.invocation, pending.maxDepth, pending.toolFilter);
|
|
@@ -1202,7 +1251,7 @@ export class NativeAdmission {
|
|
|
1202
1251
|
provider: descriptor.provider, ...(pending ? { role: pending.invocation.target, level: pending.invocation.effectiveLevel } : { role: null, level: null }),
|
|
1203
1252
|
profileId: admission.profile?.id ?? null, ...this.policy.delegationCeiling(agent) });
|
|
1204
1253
|
}
|
|
1205
|
-
await this.install(agent, this.getter(agent));
|
|
1254
|
+
await this.install(agent, this.getter(agent), scope);
|
|
1206
1255
|
check();
|
|
1207
1256
|
await this.profiles.revalidateActivation(admission);
|
|
1208
1257
|
check();
|
|
@@ -1211,13 +1260,17 @@ export class NativeAdmission {
|
|
|
1211
1260
|
if (continuationProvider && this.ctx.get("subagents").getProvider(continuationProvider.name) !== continuationProvider)
|
|
1212
1261
|
throw new SubagentError("Role provider changed", "UNAUTHORIZED");
|
|
1213
1262
|
// Occupancy precedes the installed guards' async policy and approval work.
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1263
|
+
scope.on("tools/pre-execute", async (exec, next) => {
|
|
1264
|
+
if (exec.agent === agent) {
|
|
1265
|
+
captureResidentTool(agent, this, exec.token);
|
|
1266
|
+
this.trackExecution(exec);
|
|
1267
|
+
await this.ensure(agent);
|
|
1268
|
+
const denial = this.policy.preToolDenial(agent, exec.name, undefined, exec);
|
|
1269
|
+
if (denial)
|
|
1270
|
+
return { kind: "deny", reason: denial };
|
|
1271
|
+
}
|
|
1272
|
+
return next();
|
|
1273
|
+
}, { prepend: true });
|
|
1221
1274
|
const routeCandidate = await this.admissionModelSelection?.(agent, {
|
|
1222
1275
|
settings: admission.settings, epoch: admission.epoch, admission, signal, assertCurrent: check,
|
|
1223
1276
|
});
|
|
@@ -1231,15 +1284,18 @@ export class NativeAdmission {
|
|
|
1231
1284
|
const published = this.profiles.admission(agent);
|
|
1232
1285
|
this.live.set(agent, Object.freeze({ admission: published, preset, scopeParent: scopeParentOf(agent), parent, owner, creatorId: agent.session.header.parentSession,
|
|
1233
1286
|
invocation: pending?.invocation ?? continuation, dependencies, provider: pending?.provider ?? continuationProvider }));
|
|
1287
|
+
publishResidentAgent(agent, this);
|
|
1234
1288
|
if (pending) {
|
|
1235
1289
|
this.bindObservedChild(pending.observation, agent, published);
|
|
1236
1290
|
this.pending.delete(agent.id);
|
|
1237
1291
|
}
|
|
1238
1292
|
}
|
|
1239
1293
|
catch (error) {
|
|
1294
|
+
this.failedInstallations.add(agent);
|
|
1240
1295
|
this.admissionRoutes.delete(agent);
|
|
1241
1296
|
this.admissionRouteFailures.delete(agent);
|
|
1242
1297
|
this.policy.release(agent);
|
|
1298
|
+
await scope.fiber.dispose();
|
|
1243
1299
|
throw error;
|
|
1244
1300
|
}
|
|
1245
1301
|
finally {
|