@dsmm/dsmm 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -42
- package/cordis.patch.yml +1 -0
- package/docs/agent-presets.md +26 -14
- package/docs/compatibility.md +20 -79
- package/docs/deferred-native-approval-risk.md +8 -12
- package/docs/design.md +25 -254
- package/docs/lsp.md +2 -2
- package/docs/migration-from-ocmm.md +38 -51
- package/docs/model-routing.md +21 -21
- package/docs/native-permissions.md +17 -7
- package/docs/profiles.md +13 -9
- package/docs/releasing.md +34 -240
- package/docs/roadmap.md +23 -254
- package/docs/runtime-recovery.md +29 -91
- package/docs/safety-guards.md +19 -16
- package/docs/settings-status.md +23 -11
- package/docs/skill-sync.md +17 -17
- package/docs/web-fetch-fakeip.md +82 -0
- package/lib/child-capture.d.ts +16 -2
- package/lib/child-capture.js +29 -10
- package/lib/client/ChildrenPanel.d.ts +1 -4
- package/lib/client/ChildrenPanel.js +4 -16
- package/lib/client/DeploymentFields.d.ts +28 -0
- package/lib/client/DeploymentFields.js +68 -0
- package/lib/client/DeploymentPage.d.ts +17 -5
- package/lib/client/DeploymentPage.js +79 -112
- package/lib/client/NativeCommandEntries.d.ts +17 -0
- package/lib/client/NativeCommandEntries.js +68 -0
- package/lib/client/PermissionsPanel.d.ts +1 -1
- package/lib/client/PermissionsPanel.js +8 -8
- package/lib/client/ProfilesSection.js +7 -5
- package/lib/client/RoleToolView-data.d.ts +35 -0
- package/lib/client/RoleToolView-data.js +52 -0
- package/lib/client/RoleToolView-locales.d.ts +36 -0
- package/lib/client/RoleToolView-locales.js +20 -0
- package/lib/client/RoleToolView.d.ts +10 -0
- package/lib/client/RoleToolView.js +47 -0
- package/lib/client/SessionProfiles.js +39 -15
- package/lib/client/children-controller.d.ts +2 -8
- package/lib/client/children-controller.js +1 -26
- package/lib/client/children-locales.d.ts +26 -51
- package/lib/client/children-locales.js +8 -12
- package/lib/client/configuration-display.d.ts +5 -0
- package/lib/client/configuration-display.js +11 -0
- package/lib/client/controller.d.ts +1 -0
- package/lib/client/controller.js +20 -13
- package/lib/client/deployment-controller.d.ts +13 -1
- package/lib/client/deployment-controller.js +85 -25
- package/lib/client/deployment-data.d.ts +1 -0
- package/lib/client/deployment-data.js +4 -1
- package/lib/client/deployment-locales.d.ts +43 -0
- package/lib/client/deployment-locales.js +35 -9
- package/lib/client/deployment-modules.d.ts +9 -0
- package/lib/client/deployment-modules.js +24 -0
- package/lib/client/deployment-workspace.d.ts +48 -0
- package/lib/client/deployment-workspace.js +123 -0
- package/lib/client/index.js +11 -74
- package/lib/client/locales.d.ts +7 -0
- package/lib/client/locales.js +12 -6
- package/lib/client/permission-controller.d.ts +1 -0
- package/lib/client/permission-controller.js +3 -2
- package/lib/client/permission-locales.d.ts +25 -0
- package/lib/client/permission-locales.js +24 -4
- package/lib/client/session-labels.js +4 -3
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +9 -8
- package/lib/client.js +2716 -2364
- package/lib/commands.js +2 -0
- package/lib/config-file-store.d.ts +3 -0
- package/lib/config-file-store.js +4 -2
- package/lib/config-revision.d.ts +5 -0
- package/lib/config-revision.js +11 -0
- package/lib/core-permission-authority.js +11 -41
- package/lib/deployment-config.d.ts +9 -2
- package/lib/deployment-config.js +35 -8
- package/lib/deployment-permission-rules.js +19 -7
- package/lib/dsh-types.d.ts +1 -1
- package/lib/host-llm-startup.js +3 -3
- package/lib/host-llm.d.ts +9 -3
- package/lib/host-llm.js +48 -8
- package/lib/index.d.ts +17 -21
- package/lib/index.js +131 -430
- package/lib/lifetime.d.ts +4 -0
- package/lib/lifetime.js +22 -0
- package/lib/live-pi-ai-owner.d.ts +1 -0
- package/lib/live-pi-ai-owner.js +8 -4
- package/lib/mode.d.ts +3 -2
- package/lib/mode.js +28 -41
- package/lib/model-routing.d.ts +2 -8
- package/lib/model-routing.js +59 -175
- package/lib/native-admission.d.ts +56 -0
- package/lib/native-admission.js +313 -0
- package/lib/native-pi-ai-wire.d.ts +3 -1
- package/lib/native-pi-ai-wire.js +47 -13
- package/lib/permission-control.d.ts +0 -3
- package/lib/permission-rpc.js +3 -3
- package/lib/preset-registry.js +3 -2
- package/lib/preset-skills.d.ts +3 -12
- package/lib/preset-skills.js +28 -58
- package/lib/profile-diagnostics.d.ts +1 -1
- package/lib/profile-diagnostics.js +2 -2
- package/lib/profile-remote.js +61 -22
- package/lib/profile-rpc.d.ts +4 -3
- package/lib/profile-rpc.js +39 -41
- package/lib/profile-runtime.d.ts +31 -74
- package/lib/profile-runtime.js +224 -639
- package/lib/profile-store.d.ts +18 -6
- package/lib/profile-store.js +106 -64
- package/lib/profile-types.d.ts +18 -4
- package/lib/profiles.d.ts +3 -1
- package/lib/profiles.js +9 -7
- package/lib/prompt-content.d.ts +1 -0
- package/lib/prompt-content.js +4 -1
- package/lib/prompts.d.ts +2 -12
- package/lib/prompts.js +11 -66
- package/lib/role-control-remote.d.ts +1 -4
- package/lib/role-control-remote.js +8 -36
- package/lib/role-control-rpc.d.ts +10 -36
- package/lib/role-control-rpc.js +112 -265
- package/lib/role-control-types.d.ts +3 -26
- package/lib/role-control-types.js +3 -4
- package/lib/role-identity.d.ts +5 -0
- package/lib/role-identity.js +10 -0
- package/lib/role-invocation.d.ts +2 -2
- package/lib/role-llm-runtime.js +5 -11
- package/lib/role-policy.d.ts +19 -53
- package/lib/role-policy.js +136 -525
- package/lib/role-providers.d.ts +5 -8
- package/lib/role-providers.js +20 -126
- package/lib/role-routing.d.ts +1 -3
- package/lib/role-routing.js +24 -34
- package/lib/role-subagents.d.ts +5 -14
- package/lib/role-subagents.js +149 -97
- package/lib/runtime-integration.d.ts +5 -109
- package/lib/runtime-integration.js +11 -779
- package/lib/session-metadata.d.ts +13 -12
- package/lib/session-metadata.js +6 -31
- package/lib/session-scope.js +6 -2
- package/lib/settings.d.ts +5 -18
- package/lib/settings.js +19 -43
- package/lib/state.d.ts +3 -2
- package/lib/state.js +26 -10
- package/lib/status.d.ts +1 -9
- package/lib/status.js +3 -55
- package/lib/web-fetch-address-policy.d.ts +24 -0
- package/lib/web-fetch-address-policy.js +189 -0
- package/lib/web-fetch-fakeip.d.ts +25 -0
- package/lib/web-fetch-fakeip.js +107 -0
- package/package.json +133 -113
- package/docs/research/deepseek-v4-pro.md +0 -74
- package/docs/research/oh-dsh.md +0 -96
- package/lib/child-admission.d.ts +0 -42
- package/lib/child-admission.js +0 -162
- package/lib/delivery-authority.d.ts +0 -68
- package/lib/delivery-authority.js +0 -260
- package/lib/legacy-child-policy.d.ts +0 -51
- package/lib/legacy-child-policy.js +0 -123
- package/lib/legacy-read-composition.d.ts +0 -20
- package/lib/legacy-read-composition.js +0 -144
- package/lib/legacy-read-contracts.d.ts +0 -157
- package/lib/legacy-read-contracts.js +0 -39
- package/lib/legacy-read-host.d.ts +0 -19
- package/lib/legacy-read-host.js +0 -67
- package/lib/legacy-read-integration.d.ts +0 -121
- package/lib/legacy-read-integration.js +0 -522
- package/lib/legacy-read-proxy.d.ts +0 -26
- package/lib/legacy-read-proxy.js +0 -237
- package/lib/native-child-evidence.d.ts +0 -42
- package/lib/native-child-evidence.js +0 -133
- package/lib/role-runs.d.ts +0 -135
- package/lib/role-runs.js +0 -304
- package/lib/session-persistence.d.ts +0 -35
- package/lib/session-persistence.js +0 -304
- package/lib/subagent-runtime.d.ts +0 -45
- package/lib/subagent-runtime.js +0 -131
- package/prompts/deepseek-flash.md +0 -11
- package/prompts/deepseek-v4-pro.md +0 -14
- package/scripts/cold-profile-composition.mjs +0 -329
- package/scripts/cold-profile-sources.mjs +0 -238
- package/scripts/migrate-cold-profile.mjs +0 -315
- package/scripts/repair-session-log.mjs +0 -476
- package/scripts/session-repair-native-verifier.mjs +0 -367
package/lib/role-providers.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import type { SubagentProvider } from "@deepseek-ai/dsh-subagent";
|
|
2
|
-
import type {
|
|
3
|
-
import type { DshContext } from "./dsh-types.js";
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
4
3
|
export { roleProviderName } from "./roles.js";
|
|
5
4
|
import type { DsmmRoleId } from "./roles.js";
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
5
|
+
import type { DsmmSettingsGetter } from "./settings.js";
|
|
6
|
+
import type { NativeAdmission } from "./native-admission.js";
|
|
8
7
|
export interface DsmmSubagentRegistry {
|
|
9
8
|
getProvider(name: string): SubagentProvider | undefined;
|
|
10
9
|
registerProvider(provider: SubagentProvider): () => void;
|
|
11
10
|
resolveMaxDepth?(configured?: number): number | undefined;
|
|
12
11
|
}
|
|
13
|
-
export declare function roleFromProviderName(
|
|
14
|
-
export declare function
|
|
15
|
-
/** Only the native outer start owns descriptors, capability admission and returned runs. */
|
|
16
|
-
export declare function registerRoleProviders(ctx: DshContext, getSettings: DsmmSettingsGetter, getDeploymentSettings?: DsmmSettingsGetter, policy?: DsmmRolePolicy): void;
|
|
12
|
+
export declare function roleFromProviderName(name: string): DsmmRoleId | undefined;
|
|
13
|
+
export declare function registerRoleProviders(ctx: Context, getSettings: DsmmSettingsGetter, admission: NativeAdmission): void;
|
|
17
14
|
//# sourceMappingURL=role-providers.d.ts.map
|
package/lib/role-providers.js
CHANGED
|
@@ -1,132 +1,26 @@
|
|
|
1
1
|
import { SubagentError } from "@deepseek-ai/dsh-subagent";
|
|
2
2
|
import { DSMM_ROLE_IDS, roleProviderName } from "./roles.js";
|
|
3
3
|
export { roleProviderName } from "./roles.js";
|
|
4
|
-
|
|
5
|
-
export function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const registry = readyCtx.get?.("subagents")
|
|
22
|
-
?? (readyCtx.get === undefined ? readyCtx.subagents : undefined);
|
|
23
|
-
if (registry === undefined || installed.has(registry))
|
|
24
|
-
return;
|
|
25
|
-
const disposers = [];
|
|
26
|
-
installed.add(registry);
|
|
27
|
-
try {
|
|
28
|
-
const settings = getDeploymentSettings();
|
|
29
|
-
if (!settings.modules.deepwork.enabled)
|
|
30
|
-
return;
|
|
31
|
-
for (const role of DSMM_ROLE_IDS) {
|
|
32
|
-
if (role === "dsmm-orchestrator" || !settings.roles[role])
|
|
33
|
-
continue;
|
|
34
|
-
let active = true;
|
|
35
|
-
const dispose = registry.registerProvider({
|
|
36
|
-
name: roleProviderName(role),
|
|
37
|
-
get capabilities() { const spawn = registry.getProvider("spawn"); return supportedSpawn(spawn) ? spawn.capabilities : NO_CAPABILITIES; },
|
|
38
|
-
inheritsParentContext: false,
|
|
39
|
-
get prepareContinuable() {
|
|
40
|
-
const spawn = registry.getProvider("spawn");
|
|
41
|
-
if (!supportedSpawn(spawn) || spawn.prepareContinuable === undefined)
|
|
42
|
-
return undefined;
|
|
43
|
-
return async (request) => {
|
|
44
|
-
if (!active || registry.getProvider("spawn") !== spawn)
|
|
45
|
-
throw new SubagentError("DSMM native continuable provider changed", "NO_PROVIDER");
|
|
46
|
-
const admitted = getSettings(request.parent);
|
|
47
|
-
if (!admitted.modules.deepwork.enabled || !admitted.roles[role])
|
|
48
|
-
throw new SubagentError("DSMM module or role is disabled", "UNAUTHORIZED");
|
|
49
|
-
if (!admitted.subagents.enableRunInBackground || admitted.subagents.backgroundMode !== "continuable")
|
|
50
|
-
throw new SubagentError("DSMM continuable delegation requires explicit admitted opt-in", "UNAUTHORIZED");
|
|
51
|
-
const preparing = policy?.prepareContinuable(request.parent, role, request.signal);
|
|
52
|
-
const invocation = currentRoleInvocation(request.parent, role);
|
|
53
|
-
request.signal.throwIfAborted();
|
|
54
|
-
if (!active || registry.getProvider("spawn") !== spawn)
|
|
55
|
-
throw new SubagentError("DSMM continuable provider changed during preflight", "NO_PROVIDER");
|
|
56
|
-
if (preparing !== undefined)
|
|
57
|
-
policy.recordContinuableCreation(request.sessionId, request.parent, role, invocation, preparing.epoch, request.signal);
|
|
58
|
-
return spawn.prepareContinuable(request);
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
async start(request) {
|
|
62
|
-
if (!active)
|
|
63
|
-
throw new Error("dsmm role provider is disposed");
|
|
64
|
-
const spawn = registry.getProvider("spawn");
|
|
65
|
-
if (!supportedSpawn(spawn))
|
|
66
|
-
throw new Error("dsmm role provider requires the supported native spawn capabilities");
|
|
67
|
-
if (request.descriptor.mode !== "one-shot" || request.descriptor.provider !== roleProviderName(role))
|
|
68
|
-
throw new SubagentError("DSMM alias requires its exact native descriptor", "UNAUTHORIZED");
|
|
69
|
-
const admission = policy?.assertDelegation(request.parent, role);
|
|
70
|
-
for (const [key, value] of Object.entries({ agentOptions: request.agentOptions, outputSchema: request.outputSchema, depthLimit: request.maxDepth, toolFilter: request.toolFilter, persona: request.persona })) {
|
|
71
|
-
if (value !== undefined && !spawn.capabilities[key])
|
|
72
|
-
throw new SubagentError(`DSMM spawn does not support ${key}`, "UNSUPPORTED_CAPABILITY");
|
|
73
|
-
}
|
|
74
|
-
const parentSettings = getSettings(request.parent);
|
|
75
|
-
if (!parentSettings.modules.deepwork.enabled || !parentSettings.roles[role])
|
|
76
|
-
throw new Error("dsmm role provider is disabled by deployment configuration");
|
|
77
|
-
const invocation = currentRoleInvocation(request.parent, role)
|
|
78
|
-
?? await resolveRoleInvocation(request.parent, role, parentSettings, request.signal, {}, request.agentOptions);
|
|
79
|
-
const agentOptions = invocationAgentOptions(invocation, request.agentOptions);
|
|
80
|
-
request.signal.throwIfAborted();
|
|
81
|
-
if (!active || registry.getProvider("spawn") !== spawn)
|
|
82
|
-
throw new Error("dsmm role spawn provider changed during route validation; retry delegation");
|
|
83
|
-
if (admission !== undefined && policy.assertDelegation(request.parent, role).epoch !== admission.epoch)
|
|
84
|
-
throw new SubagentError("DSMM parent admission changed during route preflight", "UNAUTHORIZED");
|
|
85
|
-
// Preserve the native descriptor, authority filters and lifecycle;
|
|
86
|
-
// this alias owns only profile-derived route defaults and preflight.
|
|
87
|
-
const routed = agentOptions === request.agentOptions ? request : { ...request, agentOptions };
|
|
88
|
-
const ceiling = parentSettings.subagents.maxDepth;
|
|
89
|
-
if (request.maxDepth !== undefined && ceiling !== undefined && request.maxDepth > ceiling)
|
|
90
|
-
throw new SubagentError("DSMM request exceeds the admitted parent depth ceiling", "UNAUTHORIZED");
|
|
91
|
-
const maxDepth = request.maxDepth ?? registry.resolveMaxDepth?.(ceiling);
|
|
92
|
-
if (maxDepth !== undefined && !spawn.capabilities.depthLimit)
|
|
93
|
-
throw new SubagentError("DSMM spawn cannot enforce the native depth limit", "UNSUPPORTED_CAPABILITY");
|
|
94
|
-
const resolved = maxDepth === undefined ? routed : { ...routed, maxDepth };
|
|
95
|
-
if (resolved.agentOptions !== undefined && !spawn.capabilities.agentOptions)
|
|
96
|
-
throw new SubagentError("DSMM spawn cannot accept the configured or selected child route", "UNSUPPORTED_CAPABILITY");
|
|
97
|
-
let admittedChild;
|
|
98
|
-
const run = await duringRoleInvocation(request.parent, invocation, () => policy === undefined ? spawn.start(resolved)
|
|
99
|
-
: policy.duringDelegation(request.parent, role, () => spawn.start(resolved), request.toolFilter, maxDepth, agent => { admittedChild = agent; }));
|
|
100
|
-
// Public holder boundary: revoke this exact residency before opaque native teardown.
|
|
101
|
-
return policy === undefined ? run : { ...run, dispose() {
|
|
102
|
-
const child = run.localAgent ?? admittedChild;
|
|
103
|
-
if (child !== undefined)
|
|
104
|
-
policy.revokeResidency(child);
|
|
105
|
-
return run.dispose();
|
|
106
|
-
} };
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
const provider = registry.getProvider(roleProviderName(role));
|
|
110
|
-
if (provider !== undefined)
|
|
111
|
-
policy?.captureProvider(provider);
|
|
112
|
-
disposers.push(() => { active = false; dispose(); });
|
|
4
|
+
export function roleFromProviderName(name) { return DSMM_ROLE_IDS.find(role => role !== "dsmm-orchestrator" && roleProviderName(role) === name); }
|
|
5
|
+
export function registerRoleProviders(ctx, getSettings, admission) {
|
|
6
|
+
const registry = ctx.subagents;
|
|
7
|
+
for (const role of DSMM_ROLE_IDS.filter(role => role !== "dsmm-orchestrator" && getSettings().roles[role])) {
|
|
8
|
+
const provider = {
|
|
9
|
+
name: roleProviderName(role), inheritsParentContext: false,
|
|
10
|
+
get capabilities() { return registry.getProvider("spawn")?.capabilities ?? { agentOptions: false, agentPreset: false, outputSchema: false, depthLimit: false }; },
|
|
11
|
+
async prepareContinuable(request) {
|
|
12
|
+
admission.prepare(request, provider);
|
|
13
|
+
const spawn = registry.getProvider("spawn");
|
|
14
|
+
if (!spawn?.prepareContinuable || spawn.inheritsParentContext !== false || spawn.agentRouteDefaults !== undefined)
|
|
15
|
+
throw new SubagentError("Independent native spawn provider required", "UNSUPPORTED_CAPABILITY");
|
|
16
|
+
const prepared = await spawn.prepareContinuable(request);
|
|
17
|
+
admission.prepare(request, provider);
|
|
18
|
+
if (registry.getProvider("spawn") !== spawn || prepared.seed !== undefined)
|
|
19
|
+
throw new SubagentError("Independent spawn seed changed", "UNAUTHORIZED");
|
|
20
|
+
return prepared;
|
|
113
21
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
installed.delete(registry);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
for (const dispose of disposers.reverse())
|
|
122
|
-
dispose();
|
|
123
|
-
installed.delete(registry);
|
|
124
|
-
throw error;
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
if (ctx.inject !== undefined)
|
|
128
|
-
ctx.inject(["subagents"], install);
|
|
129
|
-
else
|
|
130
|
-
install(ctx);
|
|
22
|
+
};
|
|
23
|
+
registry.registerProvider(provider);
|
|
24
|
+
}
|
|
131
25
|
}
|
|
132
26
|
//# sourceMappingURL=role-providers.js.map
|
package/lib/role-routing.d.ts
CHANGED
|
@@ -43,11 +43,9 @@ export declare function pinRoleRoute(agent: DshAgent, identity: string, route: D
|
|
|
43
43
|
}): RoleRouteLock;
|
|
44
44
|
export declare function clearRoleRouteLock(agent: DshAgent): void;
|
|
45
45
|
export declare function roleRouteRuntimeState(agent: DshAgent, settings: DsmmSettings, role: DsmmRoleId | undefined, epoch?: string): DsmmRoleRuntimeState;
|
|
46
|
-
export declare function rolePolicyIdentity(settings: DsmmSettings, role: DsmmRoleId | undefined, epoch?: string): string | undefined;
|
|
47
|
-
/** Durable profile choice is not permission to retain a former process's route lock. */
|
|
48
46
|
export declare function liveRolePolicyIdentity(agent: DshAgent, settings: DsmmSettings, role: DsmmRoleId | undefined, epoch?: string): string | undefined;
|
|
49
47
|
/** Native custom events are model-hidden log facts, retained across surface compaction. */
|
|
50
|
-
export declare function establishRolePolicy(frame: AgentRequestFrame, settings: DsmmSettings, role: DsmmRoleId | undefined,
|
|
48
|
+
export declare function establishRolePolicy(frame: AgentRequestFrame, settings: DsmmSettings, role: DsmmRoleId | undefined, _ctx?: DshContext, epoch?: string): Promise<string | undefined>;
|
|
51
49
|
export declare function recordAdmittedRecoveryRoute(frame: AgentRequestFrame, route: DsmmModelRoute): void;
|
|
52
50
|
export declare function takeAdmittedRecoveryRoute(frame: AgentRequestFrame): DsmmModelRoute | undefined;
|
|
53
51
|
export declare function effectiveRoleFallbackRoutes(settings: DsmmSettings, role: DsmmRoleId | undefined): readonly DsmmModelRoute[];
|
package/lib/role-routing.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
3
|
import { LlmError } from "@deepseek-ai/dsh-llm";
|
|
3
|
-
import {
|
|
4
|
+
import { appendRolePolicyRecord } from "./session-metadata.js";
|
|
4
5
|
import { isDsmmRoleId } from "./roles.js";
|
|
5
6
|
import { isCurrentRecoveryStep } from "./recovery-policy.js";
|
|
6
7
|
import { childOwnedSessionEvents, sessionEvents } from "./session-scope.js";
|
|
@@ -9,7 +10,7 @@ import { canonicalModelRouteJson, normalizeModelRouteJson, sameModelRouteJson }
|
|
|
9
10
|
import { DsmmMissingProviderError, modelRouteFromHeader, modelRouteToCall } from "./role-llm.js";
|
|
10
11
|
const admittedRecoveryRoutes = new WeakMap();
|
|
11
12
|
const routeLocks = new WeakMap();
|
|
12
|
-
const
|
|
13
|
+
const agentPolicies = new WeakMap();
|
|
13
14
|
export const DSMM_ROLE_POLICY_EVENT = "dsmm/role-policy";
|
|
14
15
|
/** Native user selection is authority; inherited headers/default configs are not. */
|
|
15
16
|
export function latestNativeModelSelection(agent) {
|
|
@@ -99,35 +100,24 @@ export function roleRouteRuntimeState(agent, settings, role, epoch) {
|
|
|
99
100
|
...(lock === undefined ? {} : { route: { ...lock.route } }), retries: lock?.retries ?? 0,
|
|
100
101
|
rateLimitFailures: lock?.rateLimits ?? 0, switches: lock?.switches ?? 0, totalDelayMs: lock?.totalDelayMs ?? 0 };
|
|
101
102
|
}
|
|
102
|
-
export function
|
|
103
|
-
if (role === undefined)
|
|
103
|
+
export function liveRolePolicyIdentity(agent, settings, role, epoch) {
|
|
104
|
+
if (role === undefined) {
|
|
105
|
+
agentPolicies.delete(agent);
|
|
104
106
|
return undefined;
|
|
107
|
+
}
|
|
105
108
|
const policy = settings.roleRouting[role];
|
|
106
109
|
const resolved = resolveRoleRuntimePolicy(settings, role);
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}) : resolved.fallbackRoutes;
|
|
117
|
-
return createHash("sha256").update(JSON.stringify({
|
|
118
|
-
version: 2, role, epoch: epoch ?? null, primary: policy?.primary === undefined ? null : canonicalRoute(policy.primary),
|
|
119
|
-
fallbackSource: resolved.fallbackSource, fallbackRoutes: identityFallbacks.map(canonicalRoute),
|
|
120
|
-
strategy: resolved.strategy, rateLimit: resolved.rateLimit
|
|
121
|
-
})).digest("hex");
|
|
122
|
-
}
|
|
123
|
-
/** Durable profile choice is not permission to retain a former process's route lock. */
|
|
124
|
-
export function liveRolePolicyIdentity(agent, settings, role, epoch) {
|
|
125
|
-
let entry = agentEntries.get(agent);
|
|
126
|
-
if (entry === undefined) {
|
|
127
|
-
entry = randomUUID();
|
|
128
|
-
agentEntries.set(agent, entry);
|
|
110
|
+
const fields = { role, epoch, primary: policy?.primary, levels: policy?.levels,
|
|
111
|
+
fallbackSource: resolved.fallbackSource, fallbackRoutes: resolved.fallbackRoutes,
|
|
112
|
+
strategy: resolved.strategy, rateLimit: resolved.rateLimit, modelParameters: settings.modelParameters,
|
|
113
|
+
recovery: { enabled: settings.runtimeRecovery.enabled, retryOnStatusCodes: settings.runtimeRecovery.retryOnStatusCodes,
|
|
114
|
+
retryOnCodes: settings.runtimeRecovery.retryOnCodes, maxFallbackAttempts: settings.runtimeRecovery.maxFallbackAttempts } };
|
|
115
|
+
let observed = agentPolicies.get(agent);
|
|
116
|
+
if (observed === undefined || !isDeepStrictEqual(observed.fields, fields)) {
|
|
117
|
+
observed = { fields: structuredClone(fields), identity: randomBytes(32).toString("hex") };
|
|
118
|
+
agentPolicies.set(agent, observed);
|
|
129
119
|
}
|
|
130
|
-
return
|
|
120
|
+
return observed.identity;
|
|
131
121
|
}
|
|
132
122
|
function canonicalRoute(route) {
|
|
133
123
|
if (Object.keys(route).every(key => ["provider", "model", "reasoningEffort"].includes(key))) {
|
|
@@ -156,7 +146,7 @@ function readPolicyMarker(event) {
|
|
|
156
146
|
return { role: data.role, policy: data.policy };
|
|
157
147
|
}
|
|
158
148
|
/** Native custom events are model-hidden log facts, retained across surface compaction. */
|
|
159
|
-
export async function establishRolePolicy(frame, settings, role,
|
|
149
|
+
export async function establishRolePolicy(frame, settings, role, _ctx, epoch) {
|
|
160
150
|
const identity = liveRolePolicyIdentity(frame.agent, settings, role, epoch);
|
|
161
151
|
const declared = role !== undefined && (Object.keys(settings.roleRouting[role] ?? {}).length > 0 || settings.runtimeRecovery.fallbackRoutes.length > 0);
|
|
162
152
|
if (frame.signal.aborted)
|
|
@@ -173,14 +163,12 @@ export async function establishRolePolicy(frame, settings, role, ctx, epoch) {
|
|
|
173
163
|
return identity;
|
|
174
164
|
if (identity === undefined || role === undefined || !declared) {
|
|
175
165
|
if (latest !== undefined && latest.policy !== null) {
|
|
176
|
-
|
|
177
|
-
await frame.agent.session.append(DSMM_ROLE_POLICY_EVENT, { version: 1, role: latest.role, policy: null });
|
|
166
|
+
appendRolePolicyRecord(frame.agent.session, { version: 1, role: latest.role, policy: null });
|
|
178
167
|
}
|
|
179
168
|
return identity;
|
|
180
169
|
}
|
|
181
170
|
if (latest?.role !== role || latest.policy !== identity) {
|
|
182
|
-
|
|
183
|
-
await frame.agent.session.append(DSMM_ROLE_POLICY_EVENT, { version: 1, role, policy: identity });
|
|
171
|
+
appendRolePolicyRecord(frame.agent.session, { version: 1, role, policy: identity });
|
|
184
172
|
}
|
|
185
173
|
return identity;
|
|
186
174
|
}
|
|
@@ -203,12 +191,14 @@ export function sameModelRoute(left, right) {
|
|
|
203
191
|
}
|
|
204
192
|
/** Accepted post-policy route changes are durable host/recovery ownership, not a new primary request. */
|
|
205
193
|
export function persistedRoleRoute(frame, primary, fallbacks = [], identity) {
|
|
194
|
+
const currentIdentity = agentPolicies.get(frame.agent)?.identity;
|
|
206
195
|
const events = policyEvents(frame);
|
|
207
196
|
let matchingPolicy = false;
|
|
208
197
|
let selected;
|
|
209
198
|
for (const event of events) {
|
|
210
199
|
if (isPresetBoundary(frame, event) || event.type === DSMM_ROLE_POLICY_EVENT) {
|
|
211
|
-
|
|
200
|
+
const marker = event.type === DSMM_ROLE_POLICY_EVENT ? readPolicyMarker(event) : undefined;
|
|
201
|
+
matchingPolicy = identity !== undefined && identity === currentIdentity && marker?.policy === identity;
|
|
212
202
|
selected = undefined;
|
|
213
203
|
continue;
|
|
214
204
|
}
|
package/lib/role-subagents.d.ts
CHANGED
|
@@ -4,16 +4,16 @@ import type { ToolRuntime } from "@deepseek-ai/dsh-tools";
|
|
|
4
4
|
import type { DshAgent, DshContext } from "./dsh-types.js";
|
|
5
5
|
import type { DsmmRoleId } from "./roles.js";
|
|
6
6
|
import { DsmmRolePolicy } from "./role-policy.js";
|
|
7
|
-
import type { DsmmSettings, DsmmSettingsGetter,
|
|
7
|
+
import type { DsmmSettings, DsmmSettingsGetter, DsmmModelRoute } from "./settings.js";
|
|
8
8
|
import type { DeepworkModeController } from "./state.js";
|
|
9
9
|
import type { DsmmInvocationView } from "./profile-types.js";
|
|
10
10
|
import type { ResolvedRoleInvocation } from "./role-invocation.js";
|
|
11
|
-
import type {
|
|
11
|
+
import type { NativeAdmission } from "./native-admission.js";
|
|
12
12
|
/** Keep native controls on the frozen startup substrate, not desired-save reconciliation. */
|
|
13
13
|
export declare function registerNativeSubagentControls(ctx: Context): Promise<void>;
|
|
14
|
-
/**
|
|
14
|
+
/** Project the captured invocation without reapplying deployment defaults. */
|
|
15
15
|
export declare function roleInvocationView(invocation: ResolvedRoleInvocation, label: string, mode: DsmmInvocationView["mode"], getSettings: DsmmSettingsGetter, child?: DshAgent, ids?: Pick<DsmmInvocationView, "runId" | "childId" | "jobId">): DsmmInvocationView;
|
|
16
|
-
/**
|
|
16
|
+
/** Distinguish the captured route from an observed native request. */
|
|
17
17
|
export declare function roleInvocationObservation(invocation: ResolvedRoleInvocation, label: string, mode: DsmmInvocationView["mode"], getSettings: DsmmSettingsGetter, child?: DshAgent, ids?: Pick<DsmmInvocationView, "runId" | "childId" | "jobId">): {
|
|
18
18
|
view: DsmmInvocationView;
|
|
19
19
|
routeKind: "initial" | "actual";
|
|
@@ -41,15 +41,6 @@ export interface DsmmRoleRouteComparison {
|
|
|
41
41
|
}
|
|
42
42
|
/** Both observations belong to this exact native Agent; no parent/settings/route-lock fallback. */
|
|
43
43
|
export declare function roleRouteComparison(child: Agent): DsmmRoleRouteComparison;
|
|
44
|
-
export interface DsmmRoleRunCapture {
|
|
45
|
-
readonly invocation: ResolvedRoleInvocation;
|
|
46
|
-
readonly admission: DsmmProfileAdmission;
|
|
47
|
-
}
|
|
48
|
-
/** Created on the parent's stable Host scope, never per profile entry or tool call. */
|
|
49
|
-
export interface DsmmRoleRunsBinding {
|
|
50
|
-
readonly registry: RoleRunRegistry<DsmmRoleRunCapture, DsmmInvocationView>;
|
|
51
|
-
readonly owner: object;
|
|
52
|
-
}
|
|
53
44
|
export interface DsmmCallableEntry {
|
|
54
45
|
name: string;
|
|
55
46
|
kind: "role" | "category";
|
|
@@ -61,5 +52,5 @@ export declare function callableRoleInventory(settings: DsmmSettings, targets: r
|
|
|
61
52
|
/** Exact currently exposed definitions, suitable for E's runtime guidance and safe capability views. */
|
|
62
53
|
export declare function admittedCallableRoleInventory(agent: DshAgent, settings: DsmmSettings, policy: DsmmRolePolicy, tools: ToolRuntime): readonly DsmmCallableEntry[];
|
|
63
54
|
/** Published name retained; all native/headless Agents consume one admitted policy. */
|
|
64
|
-
export declare function registerHeadlessRoleTools(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, policy
|
|
55
|
+
export declare function registerHeadlessRoleTools(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, policy: DsmmRolePolicy, admission: NativeAdmission, onlyAgent: DshAgent): Promise<void>;
|
|
65
56
|
//# sourceMappingURL=role-subagents.d.ts.map
|