@dsmm/dsmm 0.2.0 → 0.3.0
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 +37 -67
- package/agent-presets/dsmm-builder/agent.cordis.yml +10 -2015
- package/agent-presets/dsmm-clarifier/agent.cordis.yml +24 -343
- package/agent-presets/dsmm-code-search/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-coding/agent.cordis.yml +19 -438
- package/agent-presets/dsmm-complex/agent.cordis.yml +23 -1009
- package/agent-presets/dsmm-creative/agent.cordis.yml +25 -442
- package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +29 -1013
- package/agent-presets/dsmm-deep/agent.cordis.yml +24 -1008
- package/agent-presets/dsmm-doc-search/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-documenting/agent.cordis.yml +26 -439
- package/agent-presets/dsmm-frontend/agent.cordis.yml +21 -440
- package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +22 -441
- package/agent-presets/dsmm-media-reader/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-normal-task/agent.cordis.yml +19 -438
- package/agent-presets/dsmm-oracle/agent.cordis.yml +25 -340
- package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +25 -340
- package/agent-presets/dsmm-orchestrator/agent.cordis.yml +29 -2025
- package/agent-presets/dsmm-plan-critic/agent.cordis.yml +24 -341
- package/agent-presets/dsmm-planner/agent.cordis.yml +14 -344
- package/agent-presets/dsmm-quick/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-research/agent.cordis.yml +23 -8
- package/agent-presets/dsmm-reviewer/agent.cordis.yml +25 -340
- package/cordis.patch.yml +14 -0
- package/docs/agent-presets.md +36 -52
- package/docs/compatibility.md +47 -110
- package/docs/deferred-native-approval-risk.md +19 -0
- package/docs/design.md +2 -2
- package/docs/lsp.md +11 -21
- package/docs/migration-from-ocmm.md +2 -2
- package/docs/model-routing.md +84 -59
- package/docs/native-permissions.md +35 -0
- package/docs/profiles.md +40 -87
- package/docs/releasing.md +123 -2
- package/docs/roadmap.md +71 -17
- package/docs/settings-status.md +34 -169
- package/docs/skill-sync.md +52 -15
- package/lib/agent-registry.d.ts +36 -0
- package/lib/agent-registry.js +75 -0
- package/lib/child-admission-contract.d.ts +37 -0
- package/lib/child-admission-contract.js +2 -0
- package/lib/child-admission.d.ts +40 -0
- package/lib/child-admission.js +151 -0
- package/lib/child-capture.d.ts +85 -0
- package/lib/child-capture.js +205 -0
- package/lib/child-evidence.d.ts +17 -0
- package/lib/child-evidence.js +43 -0
- package/lib/client/ChildrenPanel.d.ts +43 -0
- package/lib/client/ChildrenPanel.js +82 -0
- package/lib/client/DeploymentPage.js +15 -8
- package/lib/client/EditableChoice.d.ts +17 -0
- package/lib/client/EditableChoice.js +49 -0
- package/lib/client/PermissionsPanel.d.ts +14 -0
- package/lib/client/PermissionsPanel.js +46 -0
- package/lib/client/ProfilesSection.js +30 -15
- package/lib/client/RoleAvailability.d.ts +7 -0
- package/lib/client/RoleAvailability.js +19 -0
- package/lib/client/SessionProfiles.js +27 -9
- package/lib/client/StructuredEditor.js +15 -7
- package/lib/client/children-controller.d.ts +98 -0
- package/lib/client/children-controller.js +296 -0
- package/lib/client/children-locales.d.ts +367 -0
- package/lib/client/children-locales.js +69 -0
- package/lib/client/controller.d.ts +6 -1
- package/lib/client/controller.js +14 -8
- package/lib/client/deployment-controller.js +1 -1
- package/lib/client/deployment-data.d.ts +2 -1
- package/lib/client/deployment-data.js +34 -5
- package/lib/client/deployment-locales.d.ts +4 -0
- package/lib/client/deployment-locales.js +11 -2
- package/lib/client/diagnostics.d.ts +14 -0
- package/lib/client/diagnostics.js +53 -0
- package/lib/client/index.d.ts +4 -0
- package/lib/client/index.js +96 -2
- package/lib/client/locales.d.ts +54 -0
- package/lib/client/locales.js +34 -16
- package/lib/client/permission-client.d.ts +16 -0
- package/lib/client/permission-client.js +38 -0
- package/lib/client/permission-controller.d.ts +62 -0
- package/lib/client/permission-controller.js +149 -0
- package/lib/client/permission-locales.d.ts +114 -0
- package/lib/client/permission-locales.js +75 -0
- package/lib/client/session-labels.js +4 -4
- package/lib/client/structured.js +19 -5
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +20 -0
- package/lib/client.js +5780 -1679
- package/lib/core-permission-authority.d.ts +18 -0
- package/lib/core-permission-authority.js +255 -0
- package/lib/core-permissions.d.ts +8 -0
- package/lib/core-permissions.js +33 -0
- package/lib/delivery-authority.d.ts +83 -0
- package/lib/delivery-authority.js +397 -0
- package/lib/deployment-config.d.ts +23 -0
- package/lib/deployment-config.js +61 -40
- package/lib/deployment-permission-rules.d.ts +55 -0
- package/lib/deployment-permission-rules.js +306 -0
- package/lib/dsh-types.d.ts +10 -4
- package/lib/guards.d.ts +1 -1
- package/lib/guards.js +29 -8
- package/lib/host-llm-startup.d.ts +41 -0
- package/lib/host-llm-startup.js +65 -0
- package/lib/host-llm.d.ts +92 -0
- package/lib/host-llm.js +325 -0
- package/lib/index.d.ts +15 -4
- package/lib/index.js +288 -48
- package/lib/live-pi-ai-owner.d.ts +18 -0
- package/lib/live-pi-ai-owner.js +144 -0
- package/lib/llm-runtime.d.ts +11 -0
- package/lib/llm-runtime.js +21 -0
- package/lib/managed-settings.d.ts +5 -0
- package/lib/managed-settings.js +14 -0
- package/lib/model-parameter-policy.d.ts +11 -0
- package/lib/model-parameter-policy.js +27 -0
- package/lib/model-routing.js +28 -17
- package/lib/modules.d.ts +13 -5
- package/lib/modules.js +17 -1
- package/lib/native-child-evidence.d.ts +40 -0
- package/lib/native-child-evidence.js +104 -0
- package/lib/native-pi-ai-wire.d.ts +37 -0
- package/lib/native-pi-ai-wire.js +261 -0
- package/lib/native-scope.js +1 -1
- package/lib/permission-bash.d.ts +6 -0
- package/lib/permission-bash.js +7 -0
- package/lib/permission-control.d.ts +73 -0
- package/lib/permission-control.js +205 -0
- package/lib/permission-controller.d.ts +68 -0
- package/lib/permission-controller.js +317 -0
- package/lib/permission-errors.d.ts +7 -0
- package/lib/permission-errors.js +21 -0
- package/lib/permission-fs-search.d.ts +5 -0
- package/lib/permission-fs-search.js +7 -0
- package/lib/permission-fs.d.ts +5 -0
- package/lib/permission-fs.js +7 -0
- package/lib/permission-native-access.d.ts +11 -0
- package/lib/permission-native-access.js +6 -0
- package/lib/permission-native-command.d.ts +10 -0
- package/lib/permission-native-command.js +93 -0
- package/lib/permission-native-rules.d.ts +75 -0
- package/lib/permission-native-rules.js +278 -0
- package/lib/permission-pwsh.d.ts +6 -0
- package/lib/permission-pwsh.js +7 -0
- package/lib/permission-remote.d.ts +26 -0
- package/lib/permission-remote.js +53 -0
- package/lib/permission-rpc.d.ts +29 -0
- package/lib/permission-rpc.js +152 -0
- package/lib/permission-rules.d.ts +115 -0
- package/lib/permission-rules.js +256 -0
- package/lib/permission-settings.d.ts +45 -0
- package/lib/permission-settings.js +48 -0
- package/lib/permission-shell.d.ts +38 -0
- package/lib/permission-shell.js +150 -0
- package/lib/permission-web.d.ts +5 -0
- package/lib/permission-web.js +7 -0
- package/lib/preset-registry.js +36 -25
- package/lib/profile-diagnostics.d.ts +45 -0
- package/lib/profile-diagnostics.js +148 -0
- package/lib/profile-locale.d.ts +3 -0
- package/lib/profile-locale.js +2 -0
- package/lib/profile-remote.d.ts +8 -0
- package/lib/profile-remote.js +163 -39
- package/lib/profile-rpc.d.ts +4 -3
- package/lib/profile-rpc.js +20 -16
- package/lib/profile-runtime.d.ts +40 -1
- package/lib/profile-runtime.js +368 -93
- package/lib/profile-store.d.ts +11 -0
- package/lib/profile-store.js +143 -11
- package/lib/profile-types.d.ts +70 -1
- package/lib/profile-types.js +1 -0
- package/lib/profiles.d.ts +16 -2
- package/lib/profiles.js +156 -79
- package/lib/prompt-content.js +1 -1
- package/lib/prompts.d.ts +37 -2
- package/lib/prompts.js +111 -9
- package/lib/recovery-policy.js +20 -7
- package/lib/role-control-remote.d.ts +38 -0
- package/lib/role-control-remote.js +211 -0
- package/lib/role-control-rpc.d.ts +51 -0
- package/lib/role-control-rpc.js +381 -0
- package/lib/role-control-types.d.ts +92 -0
- package/lib/role-control-types.js +8 -0
- package/lib/role-invocation.d.ts +47 -0
- package/lib/role-invocation.js +135 -0
- package/lib/role-llm-runtime.d.ts +17 -0
- package/lib/role-llm-runtime.js +62 -0
- package/lib/role-llm.d.ts +31 -0
- package/lib/role-llm.js +66 -0
- package/lib/role-policy.d.ts +46 -8
- package/lib/role-policy.js +421 -61
- package/lib/role-providers.d.ts +2 -2
- package/lib/role-providers.js +27 -72
- package/lib/role-routing.d.ts +11 -2
- package/lib/role-routing.js +42 -25
- package/lib/role-runs.d.ts +138 -0
- package/lib/role-runs.js +335 -0
- package/lib/role-subagents.d.ts +58 -3
- package/lib/role-subagents.js +179 -56
- package/lib/roles.d.ts +5 -6
- package/lib/roles.js +10 -39
- package/lib/route-json.d.ts +19 -0
- package/lib/route-json.js +129 -0
- package/lib/routing-policy.d.ts +2 -0
- package/lib/routing-policy.js +12 -2
- package/lib/runtime-integration.d.ts +81 -0
- package/lib/runtime-integration.js +702 -0
- package/lib/runtime-recovery.js +18 -8
- package/lib/session-persistence.d.ts +2 -1
- package/lib/session-persistence.js +1 -1
- package/lib/session-scope.js +4 -1
- package/lib/settings.d.ts +47 -13
- package/lib/settings.js +217 -82
- package/lib/skills.js +2 -2
- package/lib/status.d.ts +10 -1
- package/lib/status.js +11 -8
- package/lib/subagent-runtime.d.ts +57 -0
- package/lib/subagent-runtime.js +257 -0
- package/package.json +149 -89
- package/patches/subagent-runtime.yml +15 -0
- package/prompts/deepseek-flash.md +1 -1
- package/prompts/deepseek-v4-pro.md +2 -2
- package/prompts/deepwork.md +27 -18
- package/prompts/source/agents/clarifier.md +5 -3
- package/prompts/source/agents/orchestrator.md +18 -9
- package/prompts/source/agents/plan-critic.md +5 -1
- package/prompts/source/agents/planner.md +4 -2
- package/prompts/source/agents/reviewer.md +6 -0
- package/prompts/source/category/complex.md +4 -4
- package/prompts/source/category/creative.md +6 -4
- package/prompts/source/category/cross-cutting.md +10 -8
- package/prompts/source/category/deep.md +5 -3
- package/prompts/source/category/documenting.md +7 -1
- package/prompts/source/category/frontend.md +2 -2
- package/prompts/source/category/hard-reasoning.md +3 -3
- package/prompts/source/category/research.md +4 -2
- package/prompts/source/deepwork/claude-opus-5.md +2 -2
- package/prompts/source/deepwork/codex.md +1 -1
- package/prompts/source/deepwork/default.md +22 -15
- package/prompts/source/deepwork/gemini.md +23 -16
- package/prompts/source/deepwork/glm.md +21 -14
- package/prompts/source/deepwork/gpt.md +12 -6
- package/prompts/source/deepwork/planner.md +8 -5
- package/prompts/source/manifest.json +178 -63
- package/prompts/source/shared/dsh-host-contract.md +5 -3
- package/prompts/source/shared/locale.md +2 -2
- package/prompts/source/terminal/orchestrator.md +1 -1
- package/skills/ast-grep/SKILL.md +7 -4
- package/skills/brainstorming/SKILL.md +43 -22
- package/skills/coding-agent-sessions/SKILL.md +7 -4
- package/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +46 -46
- package/skills/coding-agent-sessions/scripts/tests/test_pi_family_scanners.py +130 -130
- package/skills/debugging/SKILL.md +14 -9
- package/skills/debugging/references/methodology/00-setup.md +14 -62
- package/skills/debugging/references/methodology/02-investigate.md +4 -4
- package/skills/debugging/references/methodology/03-flaky-triage.md +3 -3
- package/skills/debugging/references/methodology/04-hard-reasoning-escalation.md +2 -14
- package/skills/debugging/references/methodology/06-fix.md +6 -6
- package/skills/debugging/references/methodology/08-qa.md +5 -5
- package/skills/debugging/references/methodology/09-cleanup.md +15 -153
- package/skills/debugging/references/methodology/partial-runtime-evidence.md +3 -16
- package/skills/debugging/references/runtimes/bundled-js-binary.md +1 -16
- package/skills/debugging/references/runtimes/native-binary.md +9 -54
- package/skills/debugging/references/runtimes/node.md +4 -15
- package/skills/debugging/references/runtimes/python.md +3 -15
- package/skills/debugging/references/runtimes/rust.md +2 -18
- package/skills/debugging/references/tools/dap.md +1 -1
- package/skills/debugging/references/tools/ghidra.md +4 -15
- package/skills/debugging/references/tools/playwright-cli.md +3 -15
- package/skills/debugging/references/tools/pwntools.md +4 -16
- package/skills/dispatching-parallel-agents/SKILL.md +18 -16
- package/skills/frontend/SKILL.md +7 -4
- package/skills/frontend/references/design/react-dev-tooling-skill.md +1 -1
- package/skills/git-master/SKILL.md +7 -4
- package/skills/init-deep/SKILL.md +7 -4
- package/skills/receiving-code-review/SKILL.md +17 -12
- package/skills/remove-ai-slops/SKILL.md +39 -38
- package/skills/requesting-code-review/SKILL.md +19 -17
- package/skills/requesting-code-review/code-reviewer.md +13 -1
- package/skills/subagent-driven-development/SKILL.md +29 -26
- package/skills/subagent-driven-development/implementer-prompt.md +29 -11
- package/skills/subagent-driven-development/spec-reviewer-prompt.md +6 -1
- package/skills/using-git-worktrees/SKILL.md +7 -4
- package/skills/writing-plans/SKILL.md +29 -24
- package/skills/writing-plans/plan-document-reviewer-prompt.md +10 -1
- package/scripts/repair-session-log.mjs +0 -476
- package/scripts/session-repair-native-verifier.mjs +0 -367
package/lib/role-policy.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import {
|
|
2
|
+
import { currentManagedCreation } from "./agent-registry.js";
|
|
3
|
+
import { delegationDepthOf, foldSubagentDescriptor, SubagentError } from "@deepseek-ai/dsh-subagent";
|
|
3
4
|
import { symbols } from "@deepseek-ai/cordis";
|
|
4
|
-
import { DSMM_ROLES, isDsmmRoleId } from "./roles.js";
|
|
5
|
+
import { DSMM_ROLE_IDS, DSMM_ROLES, allowedRoleChildren, isDsmmRoleId } from "./roles.js";
|
|
6
|
+
export { allowedRoleChildren } from "./roles.js";
|
|
7
|
+
import { copyJson, freezeSettings, isRootRoleEnabled } from "./settings.js";
|
|
8
|
+
import { admissionFromChildCapture, parseChildAdmissionCapture } from "./child-capture.js";
|
|
9
|
+
import { bindRoleInvocation, currentRoleInvocation, resolveRoleInvocation } from "./role-invocation.js";
|
|
10
|
+
import { captureRoleRuntimePolicy, resolveRoleRuntimePolicy } from "./routing-policy.js";
|
|
5
11
|
import { childOwnedSessionEvents, resolveEffectiveDsmmRole, resolveSelectedAgentPreset } from "./session-scope.js";
|
|
12
|
+
import { resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
13
|
+
import { modelRouteFromCall, projectModelRouteParameters } from "./role-llm.js";
|
|
14
|
+
import { DsmmProfileError } from "./profiles.js";
|
|
15
|
+
import { scopeParentOf } from "./native-scope.js";
|
|
6
16
|
const liveIdentities = new WeakMap();
|
|
7
17
|
const toolIdentities = new WeakMap();
|
|
8
|
-
|
|
18
|
+
const controlledDefinitions = new WeakSet();
|
|
19
|
+
export const READONLY_ROLE_DENIED_TOOLS = ["write", "edit", "bash", "pwsh"];
|
|
20
|
+
export function inheritToolFilter(parent, requested) {
|
|
9
21
|
if (parent === undefined && requested === undefined)
|
|
10
22
|
return undefined;
|
|
11
23
|
const allow = parent?.allow === undefined ? requested?.allow : requested?.allow === undefined ? parent.allow
|
|
@@ -23,10 +35,6 @@ export function resolveAdmittedDsmmRole(agent, settings, active) {
|
|
|
23
35
|
}
|
|
24
36
|
const readTools = new Set(["read", "glob", "grep", "read_image", "web_search", "web_fetch", "skill", "load_skill", "structured_output", "send_message", "interrupt_agent", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"]);
|
|
25
37
|
const readLsp = new Set(["status", "diagnostics", "goto_definition", "find_references", "find_symbol_related", "symbols", "prepare_rename"]);
|
|
26
|
-
export function allowedRoleChildren(role, child = false) {
|
|
27
|
-
const definition = DSMM_ROLES.find((row) => row.id === role);
|
|
28
|
-
return child && role === "dsmm-builder" ? definition.childBuilderAllowedChildren ?? [] : definition.allowedChildren;
|
|
29
|
-
}
|
|
30
38
|
export function roleToolName(role) { return role.replace(/-/gu, "_"); }
|
|
31
39
|
export function roleFromToolName(name) {
|
|
32
40
|
return name === "explore" ? "dsmm-code-search" : DSMM_ROLES.find((row) => roleToolName(row.id) === name)?.id;
|
|
@@ -41,13 +49,209 @@ export class DsmmRolePolicy {
|
|
|
41
49
|
getSettings;
|
|
42
50
|
mode;
|
|
43
51
|
calls = new AsyncLocalStorage();
|
|
52
|
+
executions = new AsyncLocalStorage();
|
|
53
|
+
toolCalls = new WeakMap();
|
|
44
54
|
providers = new WeakSet();
|
|
55
|
+
continuableCreations = new Map();
|
|
56
|
+
preparedInvocations = new WeakMap();
|
|
57
|
+
preparedCaptures = new WeakMap();
|
|
58
|
+
collaborators;
|
|
45
59
|
constructor(ctx, getSettings, mode) {
|
|
46
60
|
this.ctx = ctx;
|
|
47
61
|
this.getSettings = getSettings;
|
|
48
62
|
this.mode = mode;
|
|
63
|
+
ctx.effect?.(() => () => { for (const pending of this.continuableCreations.values())
|
|
64
|
+
pending.detach(); this.continuableCreations.clear(); });
|
|
49
65
|
}
|
|
50
66
|
captureProvider(provider) { this.providers.add(provider); }
|
|
67
|
+
ownsProvider(provider) { return this.providers.has(provider); }
|
|
68
|
+
revokeResidency(agent) { this.collaborators?.revokeParent(agent, "native-run-disposed"); }
|
|
69
|
+
configureAdmission(collaborators) {
|
|
70
|
+
this.collaborators = collaborators;
|
|
71
|
+
return { prepare: (agent, parent, ticket, signal) => this.prepareChildAdmission(agent, parent, ticket, signal),
|
|
72
|
+
validateRole: (agent, parent, candidate) => this.validatePreparedRole(agent, parent, candidate) };
|
|
73
|
+
}
|
|
74
|
+
validateRootRole(agent, admission) {
|
|
75
|
+
this.assertLive(agent);
|
|
76
|
+
this.assertPlannerRootAdmission(agent, admission.settings);
|
|
77
|
+
const selected = agent.ctx?.get?.("agentPresets")?.composedPreset(agent.ctx)
|
|
78
|
+
?? resolveSelectedAgentPreset(agent.session);
|
|
79
|
+
const implicit = !selected?.startsWith("dsmm-") && admission.settings.modules.deepwork.enabled && this.mode.active(agent, admission.settings.defaultActive) ? "dsmm-orchestrator" : undefined;
|
|
80
|
+
const role = selected?.startsWith("dsmm-") ? selected : implicit;
|
|
81
|
+
if (role !== undefined && (!isDsmmRoleId(role) || !admission.settings.modules.deepwork.enabled || !admission.settings.roles[role]
|
|
82
|
+
|| role === "dsmm-planner" && !isRootRoleEnabled(admission.settings, role))) {
|
|
83
|
+
throw new SubagentError("Standing DSMM root role is not admitted", "UNAUTHORIZED");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
recordContinuableCreation(childId, parent, role, invocation, expectedEpoch, signal) {
|
|
87
|
+
signal.throwIfAborted();
|
|
88
|
+
const admitted = this.assertDelegation(parent, role);
|
|
89
|
+
if (admitted.epoch !== expectedEpoch)
|
|
90
|
+
throw new SubagentError("Parent admission changed during continuable preflight", "UNAUTHORIZED");
|
|
91
|
+
const abort = () => { this.continuableCreations.delete(childId); };
|
|
92
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
93
|
+
this.continuableCreations.set(childId, { parent, role, epoch: admitted.epoch, invocation, detach: () => signal.removeEventListener("abort", abort) });
|
|
94
|
+
}
|
|
95
|
+
async prepareChildAdmission(agent, parent, ticket, signal) {
|
|
96
|
+
signal.throwIfAborted();
|
|
97
|
+
ticket.signal.throwIfAborted();
|
|
98
|
+
this.assertLive(agent);
|
|
99
|
+
this.assertLive(parent);
|
|
100
|
+
if (ticket.parent !== parent || this.getSettings.admission?.(parent) !== ticket.admission || ticket.parentEpoch !== ticket.admission.epoch)
|
|
101
|
+
throw new SubagentError("Child preparation requires the exact parent admission ticket", "UNAUTHORIZED");
|
|
102
|
+
const call = this.calls.getStore(), pending = this.continuableCreations.get(agent.id);
|
|
103
|
+
this.continuableCreations.delete(agent.id);
|
|
104
|
+
pending?.detach();
|
|
105
|
+
const descriptor = foldSubagentDescriptor(childOwnedSessionEvents(agent.session));
|
|
106
|
+
let invocation = call?.parent === parent ? currentRoleInvocation(parent, call.role) : pending?.parent === parent ? pending.invocation : undefined;
|
|
107
|
+
if (invocation === undefined && pending?.parent === parent) {
|
|
108
|
+
if (pending.epoch !== ticket.parentEpoch || descriptor?.mode !== "continuable")
|
|
109
|
+
throw new SubagentError("Fresh continuable identity or parent epoch changed", "UNAUTHORIZED");
|
|
110
|
+
const explicit = descriptor.agentProvider === undefined && descriptor.agentModel === undefined && descriptor.agentReasoningEffort === undefined ? undefined
|
|
111
|
+
: { provider: descriptor.agentProvider, model: descriptor.agentModel, reasoningEffort: descriptor.agentReasoningEffort };
|
|
112
|
+
invocation = await resolveRoleInvocation(parent, pending.role, ticket.admission.settings, signal, {}, explicit);
|
|
113
|
+
signal.throwIfAborted();
|
|
114
|
+
ticket.signal.throwIfAborted();
|
|
115
|
+
}
|
|
116
|
+
if (invocation === undefined) {
|
|
117
|
+
if (this.collaborators === undefined)
|
|
118
|
+
throw new SubagentError("Original child evidence resolver is unavailable", "UNAUTHORIZED");
|
|
119
|
+
const evidence = await this.collaborators.resolveOriginalEvidence(ticket, agent.id, signal);
|
|
120
|
+
signal.throwIfAborted();
|
|
121
|
+
ticket.signal.throwIfAborted();
|
|
122
|
+
if ("mode" in evidence || evidence.version !== 3)
|
|
123
|
+
throw new SubagentError("Only current child capture V3 is supported", "UNSUPPORTED_CAPABILITY");
|
|
124
|
+
return { evidence, admission: admissionFromChildCapture(evidence, this.collaborators.nativeSubstrate), creation: false };
|
|
125
|
+
}
|
|
126
|
+
if ((call?.parent === parent ? call.epoch : pending.epoch) !== ticket.parentEpoch)
|
|
127
|
+
throw new SubagentError("Child invocation parent epoch changed", "UNAUTHORIZED");
|
|
128
|
+
const settings = ticket.admission.settings, parentIdentity = this.identity(parent);
|
|
129
|
+
const filter = inheritToolFilter(parentIdentity.toolFilter, call?.toolFilter ?? (descriptor?.mode === "continuable" ? descriptor.toolFilter : undefined));
|
|
130
|
+
const runtimePolicyCapture = copyJson({ modules: { deepwork: settings.modules.deepwork }, roleRouting: settings.roleRouting,
|
|
131
|
+
runtimePolicy: settings.runtimePolicy, workflow: settings.workflow, guards: settings.guards, runtimeRecovery: settings.runtimeRecovery,
|
|
132
|
+
defaultActive: settings.defaultActive, deepseekV4ProCalibration: settings.deepseekV4ProCalibration,
|
|
133
|
+
deepseekV4ProDefaultReasoningEffort: settings.deepseekV4ProDefaultReasoningEffort, deepseekFlashCalibration: settings.deepseekFlashCalibration,
|
|
134
|
+
deepseekFlashDefaultReasoningEffort: settings.deepseekFlashDefaultReasoningEffort, skills: settings.skills,
|
|
135
|
+
subagents: { enableRunInBackground: settings.subagents.enableRunInBackground, backgroundMode: settings.subagents.backgroundMode } });
|
|
136
|
+
if (invocation.routeSource === "level" || invocation.routeSource === "invocation-route") {
|
|
137
|
+
const { reasoningEffort, ...route } = invocation.requestedPolicy?.primary ?? invocation.requestedRoute ?? invocation.initialRoute;
|
|
138
|
+
runtimePolicyCapture.roleRouting[invocation.target] = { ...runtimePolicyCapture.roleRouting[invocation.target],
|
|
139
|
+
primary: { ...route, ...(invocation.exactEffort && reasoningEffort !== undefined ? { reasoningEffort } : {}) },
|
|
140
|
+
fallbackRoutes: (invocation.requestedPolicy ?? invocation.policy).fallbackRoutes.map(route => ({ ...route })) };
|
|
141
|
+
}
|
|
142
|
+
const capture = parseChildAdmissionCapture({ version: 3, childSessionId: agent.id, parentSessionId: parent.id, role: invocation.target,
|
|
143
|
+
delegationMode: currentManagedCreation()?.delegationMode,
|
|
144
|
+
modelParameterPolicy: invocation.modelParameterPolicy ?? resolvedModelParameterPolicy(ticket.admission),
|
|
145
|
+
profilePin: ticket.admission.profile, originalAdmissionEpoch: ticket.parentEpoch,
|
|
146
|
+
invocation: { level: invocation.effectiveLevel, initialRoute: invocation.initialRoute, requestedRoute: invocation.requestedRoute ?? invocation.initialRoute,
|
|
147
|
+
effortSource: invocation.effortSource ?? (invocation.routeSource === "inherited" ? "native" : "dsmm-config"), routeSource: invocation.routeSource }, runtimePolicyCapture,
|
|
148
|
+
authorityCeiling: { roles: DSMM_ROLE_IDS.filter(id => settings.roles[id]), readOnly: this.readOnly(parentIdentity) || DSMM_ROLES.find(row => row.id === invocation.target).access === "read-only",
|
|
149
|
+
...(filter === undefined ? {} : { toolFilter: filter }), allowRouteOverride: settings.subagents.allowRouteOverride,
|
|
150
|
+
maxDepth: settings.subagents.maxDepth ?? call?.maxDepth ?? parent.ctx.get("subagents").resolveMaxDepth() },
|
|
151
|
+
...(settings.locale === undefined ? {} : { locale: settings.locale }), toolTopology: settings.subagents.toolTopology });
|
|
152
|
+
this.preparedInvocations.set(agent, invocation);
|
|
153
|
+
this.preparedCaptures.set(agent, capture);
|
|
154
|
+
return { evidence: capture, admission: admissionFromChildCapture(capture, this.collaborators?.nativeSubstrate ?? settings), creation: true };
|
|
155
|
+
}
|
|
156
|
+
/** Used at A's single awaited completion point; old original epochs remain valid facts. */
|
|
157
|
+
validatePreparedRole(agent, parent, candidate) {
|
|
158
|
+
this.assertLive(agent);
|
|
159
|
+
this.assertLive(parent);
|
|
160
|
+
if ("mode" in candidate.evidence || candidate.evidence.version !== 3)
|
|
161
|
+
throw new SubagentError("Only current child capture V3 is supported", "UNSUPPORTED_CAPABILITY");
|
|
162
|
+
const evidence = parseChildAdmissionCapture(candidate.evidence);
|
|
163
|
+
if (!candidate.creation && !candidate.retained && !("mode" in evidence) && evidence.version === 3 && evidence.delegationMode === "one-shot")
|
|
164
|
+
throw new SubagentError("One-shot child cannot acquire a new residency", "UNAUTHORIZED");
|
|
165
|
+
if (evidence.childSessionId !== agent.id || evidence.parentSessionId !== parent.id || agent.session.header.parentSession !== parent.id || !this.agents().isOwnedBy(agent.id, parent))
|
|
166
|
+
throw new SubagentError("Child evidence does not match exact native lineage", "UNAUTHORIZED");
|
|
167
|
+
this.assertDelegation(parent, evidence.role);
|
|
168
|
+
const descriptor = foldSubagentDescriptor(childOwnedSessionEvents(agent.session));
|
|
169
|
+
if (descriptor === undefined ? !candidate.creation || this.preparedInvocations.get(agent)?.target !== evidence.role
|
|
170
|
+
: descriptor.provider !== `dsmm-role-${evidence.role.slice(5)}` || !candidate.creation && descriptor.mode !== "continuable") {
|
|
171
|
+
throw new SubagentError("Native descriptor or trusted fresh invocation does not match the original role", "UNAUTHORIZED");
|
|
172
|
+
}
|
|
173
|
+
const original = candidate.admission;
|
|
174
|
+
if (!original.settings.modules.deepwork.enabled || !original.settings.roles[evidence.role])
|
|
175
|
+
throw new SubagentError("Original child role/module is disabled", "UNAUTHORIZED");
|
|
176
|
+
if (descriptor?.mode === "continuable") {
|
|
177
|
+
const route = evidence.invocation.initialRoute;
|
|
178
|
+
if (descriptor.agentProvider !== undefined && descriptor.agentProvider !== route.provider || descriptor.agentModel !== undefined && descriptor.agentModel !== route.model
|
|
179
|
+
|| descriptor.agentReasoningEffort !== undefined && descriptor.agentReasoningEffort !== route.reasoningEffort)
|
|
180
|
+
throw new SubagentError("Original route does not match native descriptor provenance", "UNAUTHORIZED");
|
|
181
|
+
}
|
|
182
|
+
const prior = liveIdentities.get(agent);
|
|
183
|
+
if (candidate.retained && prior !== undefined) {
|
|
184
|
+
if (prior.identity.parent !== parent || prior.identity.role !== evidence.role || prior.identity.epoch !== original.epoch || prior.admission !== original)
|
|
185
|
+
throw new SubagentError("Retained role identity or original admission reference cannot be replaced", "UNAUTHORIZED");
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
let invocation;
|
|
189
|
+
let filter;
|
|
190
|
+
let readOnly;
|
|
191
|
+
{
|
|
192
|
+
if (candidate.creation && JSON.stringify(this.preparedCaptures.get(agent)) !== JSON.stringify(evidence))
|
|
193
|
+
throw new SubagentError("Fresh capture does not match its trusted prepared invocation and ceiling", "UNAUTHORIZED");
|
|
194
|
+
if (original.epoch !== evidence.originalAdmissionEpoch || candidate.creation && this.getSettings.admission?.(parent).epoch !== evidence.originalAdmissionEpoch)
|
|
195
|
+
throw new SubagentError("Original capture or creation epoch does not match", "UNAUTHORIZED");
|
|
196
|
+
const depth = delegationDepthOf(agent);
|
|
197
|
+
if (depth > evidence.authorityCeiling.maxDepth)
|
|
198
|
+
throw new SubagentError("Original child depth ceiling is exceeded", "UNAUTHORIZED");
|
|
199
|
+
readOnly = evidence.authorityCeiling.readOnly;
|
|
200
|
+
if (!readOnly && DSMM_ROLES.find(row => row.id === evidence.role).access === "read-only")
|
|
201
|
+
throw new SubagentError("Original capture cannot weaken read-only role identity", "UNAUTHORIZED");
|
|
202
|
+
filter = evidence.authorityCeiling.toolFilter;
|
|
203
|
+
const nativeFilter = descriptor?.mode === "continuable" ? descriptor.toolFilter : undefined;
|
|
204
|
+
if (nativeFilter !== undefined && JSON.stringify(inheritToolFilter(filter, nativeFilter)) !== JSON.stringify(filter))
|
|
205
|
+
throw new SubagentError("Original capture exceeds native descriptor tool restriction", "UNAUTHORIZED");
|
|
206
|
+
const policy = resolveRoleRuntimePolicy(original.settings, evidence.role);
|
|
207
|
+
const level = evidence.invocation.level === "normal" ? undefined : original.settings.roleRouting[evidence.role]?.levels?.[evidence.invocation.level];
|
|
208
|
+
const modelParameterPolicy = resolvedModelParameterPolicy(original);
|
|
209
|
+
const fallbacks = policy.fallbackRoutes.map(route => modelRouteFromCall(projectModelRouteParameters(route, "dsmm-config", modelParameterPolicy.mode !== "native-defaults")));
|
|
210
|
+
invocation = freezeSettings({ target: evidence.role, effectiveLevel: evidence.invocation.level, routeSource: evidence.invocation.routeSource,
|
|
211
|
+
initialRoute: evidence.invocation.initialRoute, candidates: [evidence.invocation.initialRoute, ...fallbacks], modelParameterPolicy,
|
|
212
|
+
...(evidence.version === 1 ? {} : { requestedRoute: evidence.invocation.requestedRoute, effortSource: evidence.invocation.effortSource, requestedPolicy: policy }),
|
|
213
|
+
exactEffort: evidence.invocation.routeSource === "invocation-route" ? policy.primary?.reasoningEffort !== undefined
|
|
214
|
+
: evidence.invocation.routeSource === "level" && level?.reasoningEffort !== undefined,
|
|
215
|
+
policy: { ...policy, primary: evidence.invocation.initialRoute, fallbackRoutes: fallbacks } });
|
|
216
|
+
const fresh = this.preparedInvocations.get(agent);
|
|
217
|
+
if (candidate.creation && fresh !== undefined)
|
|
218
|
+
invocation = fresh;
|
|
219
|
+
}
|
|
220
|
+
const identity = Object.freeze({ role: evidence.role, child: true, parent, epoch: original.epoch, readOnly,
|
|
221
|
+
...(filter === undefined ? {} : { toolFilter: inheritToolFilter(undefined, filter) }) });
|
|
222
|
+
this.captureIdentity(agent, identity, original);
|
|
223
|
+
bindRoleInvocation(agent, invocation, evidence);
|
|
224
|
+
captureRoleRuntimePolicy(original.settings, evidence.role, invocation.policy);
|
|
225
|
+
const call = this.calls.getStore();
|
|
226
|
+
if (candidate.creation && call?.parent === parent && call.role === evidence.role)
|
|
227
|
+
call.admittedChild?.(agent);
|
|
228
|
+
this.preparedInvocations.delete(agent);
|
|
229
|
+
this.preparedCaptures.delete(agent);
|
|
230
|
+
}
|
|
231
|
+
assertChildDelivery(ticket, childId, raw) {
|
|
232
|
+
if (!("mode" in raw) && raw.version === 3 && raw.delegationMode === "one-shot")
|
|
233
|
+
throw new SubagentError("One-shot children cannot resume", "UNAUTHORIZED");
|
|
234
|
+
this.assertChildExecution(ticket, childId, raw);
|
|
235
|
+
}
|
|
236
|
+
assertChildExecution(ticket, childId, raw) {
|
|
237
|
+
ticket.signal.throwIfAborted();
|
|
238
|
+
this.assertLive(ticket.parent);
|
|
239
|
+
if (this.getSettings.admission?.(ticket.parent) !== ticket.admission || ticket.admission.epoch !== ticket.parentEpoch)
|
|
240
|
+
throw new SubagentError("Delivery parent admission changed", "UNAUTHORIZED");
|
|
241
|
+
if ("mode" in raw || raw.version !== 3)
|
|
242
|
+
throw new SubagentError("Only current child capture V3 is supported", "UNSUPPORTED_CAPABILITY");
|
|
243
|
+
const evidence = parseChildAdmissionCapture(raw);
|
|
244
|
+
if (evidence.childSessionId !== childId || evidence.parentSessionId !== ticket.parent.id)
|
|
245
|
+
throw new SubagentError("Delivery evidence is not this direct child", "UNAUTHORIZED");
|
|
246
|
+
this.assertDelegation(ticket.parent, evidence.role);
|
|
247
|
+
const depth = delegationDepthOf(ticket.parent) + 1;
|
|
248
|
+
const maximum = ticket.admission.settings.subagents.maxDepth ?? ticket.parent.ctx.get("subagents")?.resolveMaxDepth();
|
|
249
|
+
if (maximum !== undefined && depth > maximum || !("mode" in evidence) && depth > evidence.authorityCeiling.maxDepth)
|
|
250
|
+
throw new SubagentError("Delivery exceeds the original or current delegation depth ceiling", "UNAUTHORIZED");
|
|
251
|
+
if (!("mode" in evidence) && (!evidence.runtimePolicyCapture.modules.deepwork.enabled || !evidence.authorityCeiling.roles.includes(evidence.role)))
|
|
252
|
+
throw new SubagentError("Original child role is not permitted", "UNAUTHORIZED");
|
|
253
|
+
}
|
|
254
|
+
readOnly(identity) { return identity.readOnly === true || DSMM_ROLES.find(row => row.id === identity.role)?.access === "read-only"; }
|
|
51
255
|
agents() {
|
|
52
256
|
const registry = this.ctx.get?.("agents");
|
|
53
257
|
if (registry === undefined)
|
|
@@ -58,10 +262,28 @@ export class DsmmRolePolicy {
|
|
|
58
262
|
if (agent.id === undefined || this.agents().get(agent.id) !== agent)
|
|
59
263
|
throw new SubagentError("DSMM delegation requires the exact live Agent", "UNAUTHORIZED");
|
|
60
264
|
}
|
|
265
|
+
isAdmittedChild(agent) {
|
|
266
|
+
const admitted = liveIdentities.get(agent), identity = admitted?.identity;
|
|
267
|
+
return admitted?.admission !== undefined && identity?.child === true && identity.parent !== undefined
|
|
268
|
+
&& this.agents().get(identity.parent.id) === identity.parent && this.agents().isOwnedBy(agent.id, identity.parent);
|
|
269
|
+
}
|
|
270
|
+
assertPlannerRootAdmission(agent, settings) {
|
|
271
|
+
if (settings.presets.plannerRootEnabled)
|
|
272
|
+
return;
|
|
273
|
+
const selected = resolveSelectedAgentPreset(agent.session);
|
|
274
|
+
const composed = agent.ctx?.get?.("agentPresets")?.composedPreset(agent.ctx);
|
|
275
|
+
if (selected !== "dsmm-planner" && composed !== "dsmm-planner")
|
|
276
|
+
return;
|
|
277
|
+
// Origin metadata alone cannot exempt a Root from this admission boundary.
|
|
278
|
+
if (this.isAdmittedChild(agent))
|
|
279
|
+
return;
|
|
280
|
+
throw new SubagentError("Standing DSMM root role is not admitted", "UNAUTHORIZED");
|
|
281
|
+
}
|
|
61
282
|
/** Core fence runs before native prompt/body assembly or provider execution. */
|
|
62
283
|
assertModuleAdmission(agent) {
|
|
63
284
|
this.assertLive(agent);
|
|
64
285
|
const settings = this.getSettings(agent);
|
|
286
|
+
this.assertPlannerRootAdmission(agent, settings);
|
|
65
287
|
const selected = agent.ctx?.get?.("agentPresets")?.composedPreset(agent.ctx)
|
|
66
288
|
?? resolveSelectedAgentPreset(agent.session);
|
|
67
289
|
const descriptor = foldSubagentDescriptor(childOwnedSessionEvents(agent.session));
|
|
@@ -71,13 +293,20 @@ export class DsmmRolePolicy {
|
|
|
71
293
|
if (agent.session.header?.origin !== "subagent" && selected?.startsWith("dsmm-")
|
|
72
294
|
&& !isDsmmRoleId(selected))
|
|
73
295
|
throw new SubagentError("DSMM unknown standing root is not admitted", "UNAUTHORIZED");
|
|
74
|
-
const
|
|
75
|
-
|
|
296
|
+
const implicit = agent.session.header?.origin !== "subagent" && settings.modules.deepwork.enabled && this.mode.active(agent, settings.defaultActive) ? "dsmm-orchestrator" : undefined;
|
|
297
|
+
const role = providerRole ?? (isDsmmRoleId(selected) ? selected : implicit);
|
|
298
|
+
if (role !== undefined && (!settings.modules.deepwork.enabled || !isDsmmRoleId(role) || !settings.roles[role])) {
|
|
76
299
|
throw new SubagentError("Deepwork module or role is not admitted in this Agent; standing presets and child resume cannot enable it", "UNAUTHORIZED");
|
|
77
300
|
}
|
|
301
|
+
if (role === "dsmm-planner" && !isRootRoleEnabled(settings, role) && !this.isAdmittedChild(agent)) {
|
|
302
|
+
throw new SubagentError("Standing DSMM root role is not admitted", "UNAUTHORIZED");
|
|
303
|
+
}
|
|
78
304
|
}
|
|
79
305
|
identity(agent) {
|
|
80
306
|
this.assertLive(agent);
|
|
307
|
+
const execution = this.executions.getStore(), call = execution === undefined ? undefined : this.toolCalls.get(execution);
|
|
308
|
+
if (call?.active && call.agent === agent && call.identity !== undefined)
|
|
309
|
+
return call.identity;
|
|
81
310
|
const existing = liveIdentities.get(agent)?.identity;
|
|
82
311
|
if (existing?.child)
|
|
83
312
|
return existing;
|
|
@@ -88,31 +317,45 @@ export class DsmmRolePolicy {
|
|
|
88
317
|
return existing;
|
|
89
318
|
}
|
|
90
319
|
const settings = this.getSettings(agent);
|
|
320
|
+
this.assertPlannerRootAdmission(agent, settings);
|
|
91
321
|
const selected = agent.ctx?.get?.("agentPresets")?.composedPreset(agent.ctx);
|
|
92
|
-
const role = isDsmmRoleId(selected) ? selected : settings.modules.deepwork.enabled && agent.session.header?.origin !== "subagent" &&
|
|
322
|
+
const role = isDsmmRoleId(selected) ? selected : settings.modules.deepwork.enabled && agent.session.header?.origin !== "subagent" && this.mode.active(agent, settings.defaultActive) ? "dsmm-orchestrator" : undefined;
|
|
323
|
+
if (role === "dsmm-planner" && !isRootRoleEnabled(settings, role)) {
|
|
324
|
+
throw new SubagentError("Standing DSMM root role is not admitted", "UNAUTHORIZED");
|
|
325
|
+
}
|
|
93
326
|
return Object.freeze({ role, child: agent.session.header?.origin === "subagent", epoch: this.getSettings.admission?.(agent).epoch ?? "trusted-direct" });
|
|
94
327
|
}
|
|
95
328
|
targets(agent) {
|
|
329
|
+
const execution = this.executions.getStore(), call = execution === undefined ? undefined : this.toolCalls.get(execution);
|
|
330
|
+
if (call?.active && call.agent === agent && call.targets !== undefined)
|
|
331
|
+
return call.targets;
|
|
96
332
|
const identity = this.identity(agent);
|
|
97
333
|
const settings = this.getSettings(agent);
|
|
98
334
|
if (!settings.modules.deepwork.enabled || identity.role === undefined || !settings.roles[identity.role])
|
|
99
335
|
return [];
|
|
100
336
|
return allowedRoleChildren(identity.role, identity.child).filter((role) => settings.roles[role]
|
|
337
|
+
&& (!this.readOnly(identity) || DSMM_ROLES.find(row => row.id === role).access === "read-only")
|
|
101
338
|
&& (identity.toolFilter?.allow === undefined || identity.toolFilter.allow.includes(roleToolName(role)))
|
|
102
339
|
&& !identity.toolFilter?.deny?.includes(roleToolName(role)));
|
|
103
340
|
}
|
|
104
341
|
assertDelegation(parent, role) {
|
|
342
|
+
const execution = this.executions.getStore(), call = execution === undefined ? undefined : this.toolCalls.get(execution);
|
|
343
|
+
if (call?.active && call.agent === parent && call.target === role && call.identity !== undefined)
|
|
344
|
+
return { parent, role, epoch: call.identity.epoch };
|
|
105
345
|
const identity = this.identity(parent);
|
|
106
346
|
if (!this.targets(parent).includes(role))
|
|
107
347
|
throw new SubagentError(`DSMM ${identity.role ?? "unadmitted Agent"} cannot delegate ${role}`, "UNAUTHORIZED");
|
|
108
348
|
return { parent, role, epoch: identity.epoch };
|
|
109
349
|
}
|
|
110
|
-
duringDelegation(parent, role, operation, toolFilter) {
|
|
111
|
-
|
|
350
|
+
duringDelegation(parent, role, operation, toolFilter, maxDepth, admittedChild) {
|
|
351
|
+
const identity = this.assertDelegation(parent, role), outer = this.calls.getStore();
|
|
352
|
+
const upstream = outer?.parent === parent && outer.role === role && outer.epoch === identity.epoch ? outer.admittedChild : undefined;
|
|
353
|
+
const notify = admittedChild === undefined ? upstream : upstream === undefined ? admittedChild : (agent) => { upstream(agent); admittedChild(agent); };
|
|
354
|
+
return this.calls.run({ ...identity, toolFilter, maxDepth, admittedChild: notify }, operation);
|
|
112
355
|
}
|
|
113
356
|
prepareContinuable(parent, role, signal) {
|
|
114
357
|
signal.throwIfAborted();
|
|
115
|
-
this.assertDelegation(parent, role);
|
|
358
|
+
return this.assertDelegation(parent, role);
|
|
116
359
|
}
|
|
117
360
|
admit(agent) {
|
|
118
361
|
this.assertLive(agent);
|
|
@@ -130,44 +373,15 @@ export class DsmmRolePolicy {
|
|
|
130
373
|
}
|
|
131
374
|
if (parent === undefined)
|
|
132
375
|
return this.identity(agent);
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
const invocation = this.calls.getStore();
|
|
143
|
-
if (invocation === undefined || invocation.parent !== parent) {
|
|
144
|
-
// A native cold resume already has a descriptor, but only the actual live
|
|
145
|
-
// owner and its captured policy can authorize the new residency.
|
|
146
|
-
const own = agent.session.snapshotEvents().slice(agent.session.inheritedEventCount ?? 0);
|
|
147
|
-
const descriptor = foldSubagentDescriptor(own);
|
|
148
|
-
const candidate = descriptor?.mode === "continuable" ? `dsmm-${descriptor.provider.slice("dsmm-role-".length)}` : undefined;
|
|
149
|
-
if (!descriptor?.provider.startsWith("dsmm-role-") || !isDsmmRoleId(candidate))
|
|
150
|
-
throw new SubagentError("DSMM children require an admitted role provider; generic spawn cannot bypass delegation policy", "UNAUTHORIZED");
|
|
151
|
-
return this.bindChild(agent, parent, candidate, descriptor.mode === "continuable" ? descriptor.toolFilter : undefined);
|
|
152
|
-
}
|
|
153
|
-
if (this.getSettings.admission?.(parent).epoch !== undefined && this.getSettings.admission(parent).epoch !== invocation.epoch)
|
|
154
|
-
throw new SubagentError("DSMM parent admission changed during delegation", "UNAUTHORIZED");
|
|
155
|
-
return this.bindChild(agent, parent, invocation.role, invocation.toolFilter);
|
|
156
|
-
}
|
|
157
|
-
bindChild(agent, parent, role, toolFilter) {
|
|
158
|
-
const admitted = this.assertDelegation(parent, role);
|
|
159
|
-
if (this.getSettings.admission?.(agent).epoch !== this.getSettings.admission?.(parent).epoch)
|
|
160
|
-
throw new SubagentError("DSMM child must inherit its exact parent's admission", "UNAUTHORIZED");
|
|
161
|
-
const parentIdentity = this.identity(parent);
|
|
162
|
-
const inheritedFilter = inheritToolFilter(parentIdentity.toolFilter, toolFilter);
|
|
163
|
-
const identity = Object.freeze({ role, child: true, parent, epoch: admitted.epoch,
|
|
164
|
-
readOnly: parentIdentity.readOnly === true || DSMM_ROLES.find((row) => row.id === parentIdentity.role)?.access === "read-only"
|
|
165
|
-
|| DSMM_ROLES.find((row) => row.id === role)?.access === "read-only",
|
|
166
|
-
...(inheritedFilter === undefined ? {} : { toolFilter: inheritedFilter }) });
|
|
167
|
-
return this.captureIdentity(agent, identity);
|
|
168
|
-
}
|
|
169
|
-
captureIdentity(agent, identity) {
|
|
170
|
-
liveIdentities.set(agent, { identity, readEpoch: () => this.getSettings.admission?.(agent).epoch ?? "trusted-direct" });
|
|
376
|
+
const original = this.getSettings.admission?.(agent);
|
|
377
|
+
if (original?.childCapture !== undefined) {
|
|
378
|
+
this.validatePreparedRole(agent, parent, { evidence: original.childCapture, admission: original, creation: false, retained: false });
|
|
379
|
+
return liveIdentities.get(agent).identity;
|
|
380
|
+
}
|
|
381
|
+
throw new SubagentError("DSMM child requires the completed original role/capture admission; generic spawn cannot bypass delegation policy", "UNAUTHORIZED");
|
|
382
|
+
}
|
|
383
|
+
captureIdentity(agent, identity, admission) {
|
|
384
|
+
liveIdentities.set(agent, { identity, admission, readEpoch: () => this.getSettings.admission?.(agent).epoch ?? "trusted-direct" });
|
|
171
385
|
return identity;
|
|
172
386
|
}
|
|
173
387
|
captureTools(agent, tools, controlledNames = [], reset = false) {
|
|
@@ -175,25 +389,170 @@ export class DsmmRolePolicy {
|
|
|
175
389
|
const previous = toolIdentities.get(agent);
|
|
176
390
|
const definitions = previous === undefined || reset || previous.realm !== realm ? new Map() : previous.definitions;
|
|
177
391
|
for (const schema of tools.schemas(agent)) {
|
|
178
|
-
if (previous === undefined || reset || previous.realm !== realm || controlledNames.includes(schema.name))
|
|
179
|
-
|
|
392
|
+
if (previous === undefined || reset || previous.realm !== realm || controlledNames.includes(schema.name)) {
|
|
393
|
+
const definition = tools.get(schema.name, agent);
|
|
394
|
+
definitions.set(schema.name, definition);
|
|
395
|
+
if (controlledNames.includes(schema.name))
|
|
396
|
+
controlledDefinitions.add(definition);
|
|
397
|
+
}
|
|
180
398
|
}
|
|
181
399
|
toolIdentities.set(agent, { realm, definitions });
|
|
182
400
|
}
|
|
183
|
-
|
|
401
|
+
/** Existing exact role denials only; missing admission or capability proof is not a blacklist. */
|
|
402
|
+
toolBlacklistDenial(agent, name, execution) {
|
|
403
|
+
return this.executions.exit(() => this.blacklistDenial(agent, name, execution));
|
|
404
|
+
}
|
|
405
|
+
blacklistDenial(agent, name, execution) {
|
|
406
|
+
this.assertLive(agent);
|
|
407
|
+
const captured = liveIdentities.get(agent)?.identity;
|
|
408
|
+
if (captured?.toolFilter?.deny?.includes(name))
|
|
409
|
+
return "DSMM child native toolFilter does not permit this tool";
|
|
410
|
+
if (captured?.readOnly === true && READONLY_ROLE_DENIED_TOOLS.includes(name)
|
|
411
|
+
&& this.isAdmittedChild(agent))
|
|
412
|
+
return "DSMM read-only role does not permit this tool";
|
|
413
|
+
const definition = toolIdentities.get(agent)?.definitions.get(name);
|
|
414
|
+
const native = agent.ctx, tools = native.get("agentPresets")?.serviceFor(agent, "tools") ?? native.get("tools");
|
|
415
|
+
if (definition === undefined || tools?.get(name, agent) !== definition)
|
|
416
|
+
return undefined;
|
|
417
|
+
let identity, settings;
|
|
418
|
+
try {
|
|
419
|
+
identity = this.identity(agent);
|
|
420
|
+
settings = this.getSettings(agent);
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
if (error instanceof DsmmProfileError && !["disposed", "not-owned", "cancelled"].includes(error.code)
|
|
424
|
+
|| error instanceof SubagentError && error.code === "UNAUTHORIZED")
|
|
425
|
+
return undefined;
|
|
426
|
+
throw error;
|
|
427
|
+
}
|
|
428
|
+
if (identity.role === undefined)
|
|
429
|
+
return undefined;
|
|
430
|
+
if (!settings.modules.deepwork.enabled || !settings.roles[identity.role])
|
|
431
|
+
return "DSMM role is disabled in this Agent admission";
|
|
432
|
+
const args = execution?.arguments;
|
|
433
|
+
const target = roleFromToolName(name) ?? (name === "dsmm_role" ? args?.role : name === "dsmm_category" ? args?.category : undefined);
|
|
434
|
+
if (isDsmmRoleId(target) && controlledDefinitions.has(definition)
|
|
435
|
+
&& (!settings.roles[target] || !allowedRoleChildren(identity.role, identity.child).includes(target)))
|
|
436
|
+
return `DSMM delegation to ${target} is not permitted`;
|
|
437
|
+
if (this.readOnly(identity) && READONLY_ROLE_DENIED_TOOLS.includes(name))
|
|
438
|
+
return "DSMM read-only role does not permit this tool";
|
|
439
|
+
return undefined;
|
|
440
|
+
}
|
|
441
|
+
captureToolExecution(execution, full) {
|
|
442
|
+
const agent = execution.agent;
|
|
443
|
+
if (agent === undefined)
|
|
444
|
+
return;
|
|
445
|
+
this.assertLive(agent);
|
|
446
|
+
const native = agent.ctx, agents = native.get("agents");
|
|
447
|
+
const tools = native.get("agentPresets")?.serviceFor(agent, "tools") ?? native.get("tools");
|
|
448
|
+
const definition = tools?.get(execution.name, agent);
|
|
449
|
+
const owned = definition !== undefined && controlledDefinitions.has(definition);
|
|
450
|
+
const call = { active: false, agent, context: native, registry: Reflect.get(agents, symbols.original) ?? agents,
|
|
451
|
+
realm: tools === undefined ? undefined : Reflect.get(tools, symbols.original) ?? tools, scopeParent: scopeParentOf(agent),
|
|
452
|
+
parents: agents.list().filter(parent => parent !== agent && agents.isOwnedBy(agent.id, parent)), parentSession: agent.session.header.parentSession,
|
|
453
|
+
name: execution.name, args: execution.arguments, callId: execution.callId, signal: execution.signal,
|
|
454
|
+
...!owned ? {} : { definition, body: definition.execute, argumentsJson: JSON.stringify(execution.arguments) } };
|
|
455
|
+
this.toolCalls.set(execution, call);
|
|
456
|
+
if (!owned)
|
|
457
|
+
return;
|
|
458
|
+
this.executions.exit(() => {
|
|
459
|
+
try {
|
|
460
|
+
call.identity = this.identity(agent);
|
|
461
|
+
call.targets = this.targets(agent);
|
|
462
|
+
const args = execution.arguments;
|
|
463
|
+
const target = roleFromToolName(execution.name) ?? (execution.name === "dsmm_role" ? args?.role : execution.name === "dsmm_category" ? args?.category : undefined);
|
|
464
|
+
if (isDsmmRoleId(target))
|
|
465
|
+
call.target = target;
|
|
466
|
+
}
|
|
467
|
+
catch (error) {
|
|
468
|
+
if (!full || !(error instanceof DsmmProfileError || error instanceof SubagentError))
|
|
469
|
+
throw error;
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
assertToolExecution(execution) {
|
|
474
|
+
execution.signal.throwIfAborted();
|
|
475
|
+
if (execution.agent === undefined)
|
|
476
|
+
return;
|
|
477
|
+
this.assertLive(execution.agent);
|
|
478
|
+
const call = this.toolCalls.get(execution);
|
|
479
|
+
if (call === undefined)
|
|
480
|
+
return;
|
|
481
|
+
call.signal.throwIfAborted();
|
|
482
|
+
const agent = execution.agent, agents = agent.ctx.get("agents");
|
|
483
|
+
const tools = agent.ctx.get("agentPresets")?.serviceFor(agent, "tools") ?? agent.ctx.get("tools");
|
|
484
|
+
const parents = agents.list().filter(parent => parent !== agent && agents.isOwnedBy(agent.id, parent));
|
|
485
|
+
if (agent !== call.agent || agent.ctx !== call.context || (Reflect.get(agents, symbols.original) ?? agents) !== call.registry
|
|
486
|
+
|| (tools === undefined ? undefined : Reflect.get(tools, symbols.original) ?? tools) !== call.realm || scopeParentOf(agent) !== call.scopeParent
|
|
487
|
+
|| agent.session.header.parentSession !== call.parentSession || parents.length !== call.parents.length || parents.some(parent => !call.parents.includes(parent)))
|
|
488
|
+
throw new SubagentError("Native tool caller ownership changed", "UNAUTHORIZED");
|
|
489
|
+
if (call.definition === undefined)
|
|
490
|
+
return;
|
|
491
|
+
const current = tools?.get(call.name, agent);
|
|
492
|
+
if (execution.name !== call.name || execution.arguments !== call.args || execution.callId !== call.callId || JSON.stringify(execution.arguments) !== call.argumentsJson
|
|
493
|
+
|| call.definition.execute !== call.body || current !== undefined && current !== call.definition)
|
|
494
|
+
throw new SubagentError("Owned tool registration or invocation changed", "UNAUTHORIZED");
|
|
495
|
+
}
|
|
496
|
+
beforeToolDecision(operation) { return this.executions.exit(operation); }
|
|
497
|
+
async duringToolExecution(execution, operation) {
|
|
498
|
+
this.assertToolExecution(execution);
|
|
499
|
+
const call = this.toolCalls.get(execution);
|
|
500
|
+
if (call !== undefined)
|
|
501
|
+
call.active = true;
|
|
502
|
+
try {
|
|
503
|
+
return await this.executions.run(execution, operation);
|
|
504
|
+
}
|
|
505
|
+
finally {
|
|
506
|
+
if (call !== undefined)
|
|
507
|
+
call.active = false;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
toolDenial(agent, name, tools, execution) {
|
|
511
|
+
const scoped = this.executions.getStore();
|
|
512
|
+
const active = execution ?? (scoped !== undefined && this.toolCalls.get(scoped)?.active ? scoped : undefined);
|
|
513
|
+
if (active !== undefined && active.agent === agent && active.name === name) {
|
|
514
|
+
this.assertToolExecution(active);
|
|
515
|
+
return undefined;
|
|
516
|
+
}
|
|
517
|
+
if (tools === undefined)
|
|
518
|
+
return this.toolBlacklistDenial(agent, name);
|
|
519
|
+
return this.preToolDenial(agent, name, tools);
|
|
520
|
+
}
|
|
521
|
+
preToolDenial(agent, name, tools, execution) {
|
|
522
|
+
return this.executions.exit(() => this.permissionDenial(agent, name, tools, execution));
|
|
523
|
+
}
|
|
524
|
+
permissionDenial(agent, name, tools, execution) {
|
|
184
525
|
const identity = this.identity(agent);
|
|
185
526
|
const settings = this.getSettings(agent);
|
|
186
|
-
|
|
187
|
-
const
|
|
527
|
+
const native = agent.ctx, realm = tools ?? native.get("agentPresets")?.serviceFor(agent, "tools") ?? native.get("tools");
|
|
528
|
+
const definition = realm?.get(name, agent);
|
|
529
|
+
const owned = definition !== undefined && controlledDefinitions.has(definition);
|
|
530
|
+
const controlled = owned && (name === "dsmm_role" || name === "dsmm_category");
|
|
531
|
+
const target = owned ? roleFromToolName(name) : undefined;
|
|
188
532
|
const readonly = identity.readOnly || DSMM_ROLES.find((row) => row.id === identity.role)?.access === "read-only";
|
|
189
|
-
|
|
533
|
+
const checkedRealm = tools ?? (execution === undefined ? undefined : realm);
|
|
534
|
+
if (checkedRealm !== undefined && (readonly || target !== undefined || controlled)) {
|
|
190
535
|
const admitted = toolIdentities.get(agent);
|
|
191
|
-
if (admitted === undefined || admitted.realm !== (Reflect.get(
|
|
192
|
-
|| admitted.definitions.get(name) !==
|
|
536
|
+
if (admitted === undefined || admitted.realm !== (Reflect.get(checkedRealm, symbols.original) ?? checkedRealm)
|
|
537
|
+
|| admitted.definitions.get(name) !== checkedRealm.get(name, agent))
|
|
193
538
|
return "DSMM tool definition was not admitted in this exact Agent realm";
|
|
194
539
|
}
|
|
195
540
|
if (target !== undefined)
|
|
196
|
-
return
|
|
541
|
+
return DSMM_ROLES.find(row => row.id === target).kind !== "role" || settings.subagents.toolTopology !== "per-role" ? "DSMM obsolete per-target entry is not callable in this topology"
|
|
542
|
+
: this.targets(agent).includes(target) ? undefined : `DSMM delegation to ${target} is not permitted`;
|
|
543
|
+
if (controlled) {
|
|
544
|
+
const kind = name === "dsmm_role" ? "role" : "category";
|
|
545
|
+
if (name === "dsmm_role" && settings.subagents.toolTopology !== "parameterized" || !this.targets(agent).some(role => DSMM_ROLES.find(row => row.id === role).kind === kind))
|
|
546
|
+
return "DSMM merged delegation entry is not admitted";
|
|
547
|
+
// Native merged-entry restrictions and the per-target ceiling both apply.
|
|
548
|
+
if (identity.toolFilter?.allow !== undefined && !identity.toolFilter.allow.includes(name) || identity.toolFilter?.deny?.includes(name))
|
|
549
|
+
return "DSMM native filter does not permit this merged entry";
|
|
550
|
+
const args = execution?.arguments;
|
|
551
|
+
const target = kind === "role" ? args?.role : args?.category;
|
|
552
|
+
if (isDsmmRoleId(target) && !this.targets(agent).includes(target))
|
|
553
|
+
return `DSMM delegation to ${target} is not permitted`;
|
|
554
|
+
return undefined;
|
|
555
|
+
}
|
|
197
556
|
if (identity.toolFilter?.allow !== undefined && !identity.toolFilter.allow.includes(name) && name !== "structured_output"
|
|
198
557
|
|| identity.toolFilter?.deny?.includes(name))
|
|
199
558
|
return "DSMM child native toolFilter does not permit this tool";
|
|
@@ -212,10 +571,11 @@ export class DsmmRolePolicy {
|
|
|
212
571
|
if (native === undefined)
|
|
213
572
|
throw new Error("DSMM native role lifecycle requires an Agent context");
|
|
214
573
|
native.effect(() => async () => {
|
|
574
|
+
this.collaborators?.revokeParent?.(agent, "role-residency-disposed");
|
|
215
575
|
const agents = this.agents();
|
|
216
576
|
if (agents.get(agent.id) !== agent)
|
|
217
577
|
throw new Error("DSMM Agent was detached before continuable descendants drained");
|
|
218
|
-
await native.get("subagents")?.
|
|
578
|
+
await native.get("subagents")?.drainDescendants([agent]);
|
|
219
579
|
liveIdentities.delete(agent);
|
|
220
580
|
toolIdentities.delete(agent);
|
|
221
581
|
});
|
package/lib/role-providers.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SubagentProvider } from "@deepseek-ai/dsh-subagent";
|
|
2
2
|
import type { Agent, AgentOptions } from "@deepseek-ai/dsh-agent";
|
|
3
3
|
import type { DshContext } from "./dsh-types.js";
|
|
4
|
+
export { roleProviderName } from "./roles.js";
|
|
4
5
|
import type { DsmmRoleId } from "./roles.js";
|
|
5
6
|
import type { DsmmSettings, DsmmSettingsGetter } from "./settings.js";
|
|
6
7
|
import type { DsmmRolePolicy } from "./role-policy.js";
|
|
@@ -9,9 +10,8 @@ export interface DsmmSubagentRegistry {
|
|
|
9
10
|
registerProvider(provider: SubagentProvider): () => void;
|
|
10
11
|
resolveMaxDepth?(configured?: number): number | undefined;
|
|
11
12
|
}
|
|
12
|
-
export declare function roleProviderName(role: DsmmRoleId): string;
|
|
13
13
|
export declare function roleFromProviderName(provider: string): DsmmRoleId | undefined;
|
|
14
14
|
export declare function roleAgentOptions(parent: Agent, role: DsmmRoleId, settings: DsmmSettings, signal: AbortSignal, explicit?: AgentOptions): Promise<AgentOptions | undefined>;
|
|
15
|
-
/**
|
|
15
|
+
/** The native manager owns descriptors, capability admission and activations. */
|
|
16
16
|
export declare function registerRoleProviders(ctx: DshContext, getSettings: DsmmSettingsGetter, getDeploymentSettings?: DsmmSettingsGetter, policy?: DsmmRolePolicy): void;
|
|
17
17
|
//# sourceMappingURL=role-providers.d.ts.map
|