@dsmm/dsmm 0.2.0 → 0.2.2
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 +38 -66
- 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/docs/agent-presets.md +36 -52
- package/docs/compatibility.md +50 -108
- 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 +83 -2
- package/docs/roadmap.md +71 -17
- package/docs/settings-status.md +34 -169
- package/docs/skill-sync.md +52 -15
- package/lib/child-admission-contract.d.ts +37 -0
- package/lib/child-admission-contract.js +2 -0
- package/lib/child-admission.d.ts +42 -0
- package/lib/child-admission.js +162 -0
- package/lib/child-capture.d.ts +81 -0
- package/lib/child-capture.js +203 -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-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 +68 -0
- package/lib/delivery-authority.js +260 -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 +300 -47
- package/lib/legacy-child-policy.d.ts +51 -0
- package/lib/legacy-child-policy.js +123 -0
- package/lib/legacy-read-composition.d.ts +20 -0
- package/lib/legacy-read-composition.js +144 -0
- package/lib/legacy-read-contracts.d.ts +157 -0
- package/lib/legacy-read-contracts.js +39 -0
- package/lib/legacy-read-host.d.ts +19 -0
- package/lib/legacy-read-host.js +67 -0
- package/lib/legacy-read-integration.d.ts +121 -0
- package/lib/legacy-read-integration.js +522 -0
- package/lib/legacy-read-proxy.d.ts +26 -0
- package/lib/legacy-read-proxy.js +237 -0
- 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 +42 -0
- package/lib/native-child-evidence.js +133 -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 +14 -12
- 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 +377 -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 +49 -8
- package/lib/role-policy.js +437 -60
- package/lib/role-providers.d.ts +1 -1
- package/lib/role-providers.js +30 -35
- package/lib/role-routing.d.ts +11 -2
- package/lib/role-routing.js +42 -25
- package/lib/role-runs.d.ts +135 -0
- package/lib/role-runs.js +304 -0
- package/lib/role-subagents.d.ts +58 -3
- package/lib/role-subagents.js +169 -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 +112 -0
- package/lib/runtime-integration.js +784 -0
- package/lib/runtime-recovery.js +18 -8
- 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 +45 -0
- package/lib/subagent-runtime.js +131 -0
- package/package.json +106 -56
- 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/scripts/cold-profile-composition.mjs +329 -0
- package/scripts/cold-profile-sources.mjs +238 -0
- package/scripts/migrate-cold-profile.mjs +315 -0
- 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/lib/role-policy.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import { foldSubagentDescriptor, SubagentError } from "@deepseek-ai/dsh-subagent";
|
|
2
|
+
import { delegationDepthOf, foldSubagentDescriptor, SubagentError } from "@deepseek-ai/dsh-subagent";
|
|
3
3
|
import { symbols } from "@deepseek-ai/cordis";
|
|
4
|
-
import { DSMM_ROLES, isDsmmRoleId } from "./roles.js";
|
|
4
|
+
import { DSMM_ROLE_IDS, DSMM_ROLES, allowedRoleChildren, isDsmmRoleId } from "./roles.js";
|
|
5
|
+
export { allowedRoleChildren } from "./roles.js";
|
|
6
|
+
import { copyJson, freezeSettings, isRootRoleEnabled } from "./settings.js";
|
|
7
|
+
import { admissionFromChildCapture, parseChildAdmissionCapture, parseLegacyChildEvidence } from "./child-capture.js";
|
|
8
|
+
import { createConservativeLegacyAdmission } from "./legacy-child-policy.js";
|
|
9
|
+
export { createConservativeLegacyAdmission as conservativeLegacyAdmission } from "./legacy-child-policy.js";
|
|
10
|
+
import { bindRoleInvocation, currentRoleInvocation, resolveRoleInvocation } from "./role-invocation.js";
|
|
11
|
+
import { captureRoleRuntimePolicy, resolveRoleRuntimePolicy } from "./routing-policy.js";
|
|
5
12
|
import { childOwnedSessionEvents, resolveEffectiveDsmmRole, resolveSelectedAgentPreset } from "./session-scope.js";
|
|
13
|
+
import { resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
14
|
+
import { modelRouteFromCall, projectModelRouteParameters } from "./role-llm.js";
|
|
15
|
+
import { DsmmProfileError } from "./profiles.js";
|
|
16
|
+
import { scopeParentOf } from "./native-scope.js";
|
|
6
17
|
const liveIdentities = new WeakMap();
|
|
7
18
|
const toolIdentities = new WeakMap();
|
|
8
|
-
|
|
19
|
+
const controlledDefinitions = new WeakSet();
|
|
20
|
+
export const READONLY_ROLE_DENIED_TOOLS = ["write", "edit", "bash", "pwsh"];
|
|
21
|
+
export function inheritToolFilter(parent, requested) {
|
|
9
22
|
if (parent === undefined && requested === undefined)
|
|
10
23
|
return undefined;
|
|
11
24
|
const allow = parent?.allow === undefined ? requested?.allow : requested?.allow === undefined ? parent.allow
|
|
@@ -23,10 +36,6 @@ export function resolveAdmittedDsmmRole(agent, settings, active) {
|
|
|
23
36
|
}
|
|
24
37
|
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
38
|
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
39
|
export function roleToolName(role) { return role.replace(/-/gu, "_"); }
|
|
31
40
|
export function roleFromToolName(name) {
|
|
32
41
|
return name === "explore" ? "dsmm-code-search" : DSMM_ROLES.find((row) => roleToolName(row.id) === name)?.id;
|
|
@@ -41,13 +50,206 @@ export class DsmmRolePolicy {
|
|
|
41
50
|
getSettings;
|
|
42
51
|
mode;
|
|
43
52
|
calls = new AsyncLocalStorage();
|
|
53
|
+
executions = new AsyncLocalStorage();
|
|
54
|
+
toolCalls = new WeakMap();
|
|
44
55
|
providers = new WeakSet();
|
|
56
|
+
continuableCreations = new Map();
|
|
57
|
+
preparedInvocations = new WeakMap();
|
|
58
|
+
preparedCaptures = new WeakMap();
|
|
59
|
+
collaborators;
|
|
45
60
|
constructor(ctx, getSettings, mode) {
|
|
46
61
|
this.ctx = ctx;
|
|
47
62
|
this.getSettings = getSettings;
|
|
48
63
|
this.mode = mode;
|
|
64
|
+
ctx.effect?.(() => () => { for (const pending of this.continuableCreations.values())
|
|
65
|
+
pending.detach(); this.continuableCreations.clear(); });
|
|
49
66
|
}
|
|
50
67
|
captureProvider(provider) { this.providers.add(provider); }
|
|
68
|
+
ownsProvider(provider) { return this.providers.has(provider); }
|
|
69
|
+
revokeResidency(agent) { this.collaborators?.revokeParent(agent, "native-run-disposed"); }
|
|
70
|
+
configureAdmission(collaborators) {
|
|
71
|
+
this.collaborators = collaborators;
|
|
72
|
+
return { prepare: (agent, parent, ticket, signal) => this.prepareChildAdmission(agent, parent, ticket, signal),
|
|
73
|
+
validateRole: (agent, parent, candidate) => this.validatePreparedRole(agent, parent, candidate) };
|
|
74
|
+
}
|
|
75
|
+
validateRootRole(agent, admission) {
|
|
76
|
+
this.assertLive(agent);
|
|
77
|
+
this.assertPlannerRootAdmission(agent, admission.settings);
|
|
78
|
+
const selected = agent.ctx?.get?.("agentPresets")?.composedPreset(agent.ctx)
|
|
79
|
+
?? resolveSelectedAgentPreset(agent.session);
|
|
80
|
+
const implicit = !selected?.startsWith("dsmm-") && admission.settings.modules.deepwork.enabled && this.mode.active(agent, admission.settings.defaultActive) ? "dsmm-orchestrator" : undefined;
|
|
81
|
+
const role = selected?.startsWith("dsmm-") ? selected : implicit;
|
|
82
|
+
if (role !== undefined && (!isDsmmRoleId(role) || !admission.settings.modules.deepwork.enabled || !admission.settings.roles[role]
|
|
83
|
+
|| role === "dsmm-planner" && !isRootRoleEnabled(admission.settings, role))) {
|
|
84
|
+
throw new SubagentError("Standing DSMM root role is not admitted", "UNAUTHORIZED");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
recordContinuableCreation(childId, parent, role, invocation, expectedEpoch, signal) {
|
|
88
|
+
signal.throwIfAborted();
|
|
89
|
+
const admitted = this.assertDelegation(parent, role);
|
|
90
|
+
if (admitted.epoch !== expectedEpoch)
|
|
91
|
+
throw new SubagentError("Parent admission changed during continuable preflight", "UNAUTHORIZED");
|
|
92
|
+
const abort = () => { this.continuableCreations.delete(childId); };
|
|
93
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
94
|
+
this.continuableCreations.set(childId, { parent, role, epoch: admitted.epoch, invocation, detach: () => signal.removeEventListener("abort", abort) });
|
|
95
|
+
}
|
|
96
|
+
async prepareChildAdmission(agent, parent, ticket, signal) {
|
|
97
|
+
signal.throwIfAborted();
|
|
98
|
+
ticket.signal.throwIfAborted();
|
|
99
|
+
this.assertLive(agent);
|
|
100
|
+
this.assertLive(parent);
|
|
101
|
+
if (ticket.parent !== parent || this.getSettings.admission?.(parent) !== ticket.admission || ticket.parentEpoch !== ticket.admission.epoch)
|
|
102
|
+
throw new SubagentError("Child preparation requires the exact parent admission ticket", "UNAUTHORIZED");
|
|
103
|
+
const call = this.calls.getStore(), pending = this.continuableCreations.get(agent.id);
|
|
104
|
+
this.continuableCreations.delete(agent.id);
|
|
105
|
+
pending?.detach();
|
|
106
|
+
const descriptor = foldSubagentDescriptor(childOwnedSessionEvents(agent.session));
|
|
107
|
+
let invocation = call?.parent === parent ? currentRoleInvocation(parent, call.role) : pending?.parent === parent ? pending.invocation : undefined;
|
|
108
|
+
if (invocation === undefined && pending?.parent === parent) {
|
|
109
|
+
if (pending.epoch !== ticket.parentEpoch || descriptor?.mode !== "continuable")
|
|
110
|
+
throw new SubagentError("Fresh continuable identity or parent epoch changed", "UNAUTHORIZED");
|
|
111
|
+
const explicit = descriptor.agentProvider === undefined && descriptor.agentModel === undefined && descriptor.agentReasoningEffort === undefined ? undefined
|
|
112
|
+
: { provider: descriptor.agentProvider, model: descriptor.agentModel, reasoningEffort: descriptor.agentReasoningEffort };
|
|
113
|
+
invocation = await resolveRoleInvocation(parent, pending.role, ticket.admission.settings, signal, {}, explicit);
|
|
114
|
+
signal.throwIfAborted();
|
|
115
|
+
ticket.signal.throwIfAborted();
|
|
116
|
+
}
|
|
117
|
+
if (invocation === undefined) {
|
|
118
|
+
if (this.collaborators === undefined)
|
|
119
|
+
throw new SubagentError("Original child evidence resolver is unavailable", "UNAUTHORIZED");
|
|
120
|
+
const evidence = await this.collaborators.resolveOriginalEvidence(ticket, agent.id, signal);
|
|
121
|
+
signal.throwIfAborted();
|
|
122
|
+
ticket.signal.throwIfAborted();
|
|
123
|
+
return { evidence, admission: "mode" in evidence ? createConservativeLegacyAdmission(evidence, ticket.admission, this.collaborators.nativeSubstrate)
|
|
124
|
+
: 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: 2, childSessionId: agent.id, parentSessionId: parent.id, role: invocation.target,
|
|
143
|
+
modelParameterPolicy: invocation.modelParameterPolicy ?? resolvedModelParameterPolicy(ticket.admission),
|
|
144
|
+
profilePin: ticket.admission.profile, originalAdmissionEpoch: ticket.parentEpoch,
|
|
145
|
+
invocation: { level: invocation.effectiveLevel, initialRoute: invocation.initialRoute, requestedRoute: invocation.requestedRoute ?? invocation.initialRoute,
|
|
146
|
+
effortSource: invocation.effortSource ?? (invocation.routeSource === "inherited" ? "native" : "dsmm-config"), routeSource: invocation.routeSource }, runtimePolicyCapture,
|
|
147
|
+
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",
|
|
148
|
+
...(filter === undefined ? {} : { toolFilter: filter }), allowRouteOverride: settings.subagents.allowRouteOverride,
|
|
149
|
+
maxDepth: settings.subagents.maxDepth ?? call?.maxDepth ?? parent.ctx.get("subagents").resolveMaxDepth() },
|
|
150
|
+
...(settings.locale === undefined ? {} : { locale: settings.locale }), toolTopology: settings.subagents.toolTopology });
|
|
151
|
+
this.preparedInvocations.set(agent, invocation);
|
|
152
|
+
this.preparedCaptures.set(agent, capture);
|
|
153
|
+
return { evidence: capture, admission: admissionFromChildCapture(capture, this.collaborators?.nativeSubstrate ?? settings), creation: true };
|
|
154
|
+
}
|
|
155
|
+
/** Used at A's single awaited completion point; old original epochs remain valid facts. */
|
|
156
|
+
validatePreparedRole(agent, parent, candidate) {
|
|
157
|
+
this.assertLive(agent);
|
|
158
|
+
this.assertLive(parent);
|
|
159
|
+
const evidence = "mode" in candidate.evidence ? parseLegacyChildEvidence(candidate.evidence) : parseChildAdmissionCapture(candidate.evidence);
|
|
160
|
+
if (evidence.childSessionId !== agent.id || evidence.parentSessionId !== parent.id || agent.session.header.parentSession !== parent.id || !this.agents().isOwnedBy(agent.id, parent))
|
|
161
|
+
throw new SubagentError("Child evidence does not match exact native lineage", "UNAUTHORIZED");
|
|
162
|
+
this.assertDelegation(parent, evidence.role);
|
|
163
|
+
const descriptor = foldSubagentDescriptor(childOwnedSessionEvents(agent.session));
|
|
164
|
+
if (descriptor === undefined ? !candidate.creation || this.preparedInvocations.get(agent)?.target !== evidence.role
|
|
165
|
+
: descriptor.provider !== `dsmm-role-${evidence.role.slice(5)}` || !candidate.creation && descriptor.mode !== "continuable") {
|
|
166
|
+
throw new SubagentError("Native descriptor or trusted fresh invocation does not match the original role", "UNAUTHORIZED");
|
|
167
|
+
}
|
|
168
|
+
const original = candidate.admission;
|
|
169
|
+
if (!original.settings.modules.deepwork.enabled || !original.settings.roles[evidence.role])
|
|
170
|
+
throw new SubagentError("Original child role/module is disabled", "UNAUTHORIZED");
|
|
171
|
+
if (descriptor?.mode === "continuable") {
|
|
172
|
+
const route = "mode" in evidence ? evidence.route : evidence.invocation.initialRoute;
|
|
173
|
+
if (descriptor.agentProvider !== undefined && descriptor.agentProvider !== route.provider || descriptor.agentModel !== undefined && descriptor.agentModel !== route.model
|
|
174
|
+
|| descriptor.agentReasoningEffort !== undefined && descriptor.agentReasoningEffort !== route.reasoningEffort)
|
|
175
|
+
throw new SubagentError("Original route does not match native descriptor provenance", "UNAUTHORIZED");
|
|
176
|
+
}
|
|
177
|
+
const prior = liveIdentities.get(agent);
|
|
178
|
+
if (candidate.retained && prior !== undefined) {
|
|
179
|
+
if (prior.identity.parent !== parent || prior.identity.role !== evidence.role || prior.identity.epoch !== original.epoch || prior.admission !== original)
|
|
180
|
+
throw new SubagentError("Retained role identity or original admission reference cannot be replaced", "UNAUTHORIZED");
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
let invocation;
|
|
184
|
+
let filter;
|
|
185
|
+
let readOnly;
|
|
186
|
+
if ("mode" in evidence) {
|
|
187
|
+
if (evidence.depth !== delegationDepthOf(agent))
|
|
188
|
+
throw new SubagentError("Legacy depth evidence does not match its physical native lineage", "UNAUTHORIZED");
|
|
189
|
+
const safe = evidence.toolFilter?.allow?.filter(name => readonlyRoleTool(name, original.settings) && !["interrupt_agent", "job_kill"].includes(name)) ?? [];
|
|
190
|
+
filter = inheritToolFilter({ allow: safe }, evidence.toolFilter);
|
|
191
|
+
readOnly = true;
|
|
192
|
+
invocation = freezeSettings({ target: evidence.role, effectiveLevel: "normal", routeSource: "inherited", initialRoute: evidence.route,
|
|
193
|
+
candidates: [evidence.route], exactEffort: evidence.route.reasoningEffort !== undefined, modelParameterPolicy: resolvedModelParameterPolicy(original), effortSource: "native",
|
|
194
|
+
policy: { ...resolveRoleRuntimePolicy(original.settings, evidence.role), primary: evidence.route, fallbackRoutes: [] } });
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
if (candidate.creation && JSON.stringify(this.preparedCaptures.get(agent)) !== JSON.stringify(evidence))
|
|
198
|
+
throw new SubagentError("Fresh capture does not match its trusted prepared invocation and ceiling", "UNAUTHORIZED");
|
|
199
|
+
if (original.epoch !== evidence.originalAdmissionEpoch || candidate.creation && this.getSettings.admission?.(parent).epoch !== evidence.originalAdmissionEpoch)
|
|
200
|
+
throw new SubagentError("Original capture or creation epoch does not match", "UNAUTHORIZED");
|
|
201
|
+
const depth = delegationDepthOf(agent);
|
|
202
|
+
if (depth > evidence.authorityCeiling.maxDepth)
|
|
203
|
+
throw new SubagentError("Original child depth ceiling is exceeded", "UNAUTHORIZED");
|
|
204
|
+
readOnly = evidence.authorityCeiling.readOnly;
|
|
205
|
+
if (!readOnly && DSMM_ROLES.find(row => row.id === evidence.role).access === "read-only")
|
|
206
|
+
throw new SubagentError("Original capture cannot weaken read-only role identity", "UNAUTHORIZED");
|
|
207
|
+
filter = evidence.authorityCeiling.toolFilter;
|
|
208
|
+
const nativeFilter = descriptor?.mode === "continuable" ? descriptor.toolFilter : undefined;
|
|
209
|
+
if (nativeFilter !== undefined && JSON.stringify(inheritToolFilter(filter, nativeFilter)) !== JSON.stringify(filter))
|
|
210
|
+
throw new SubagentError("Original capture exceeds native descriptor tool restriction", "UNAUTHORIZED");
|
|
211
|
+
const policy = resolveRoleRuntimePolicy(original.settings, evidence.role);
|
|
212
|
+
const level = evidence.invocation.level === "normal" ? undefined : original.settings.roleRouting[evidence.role]?.levels?.[evidence.invocation.level];
|
|
213
|
+
const modelParameterPolicy = resolvedModelParameterPolicy(original);
|
|
214
|
+
const fallbacks = policy.fallbackRoutes.map(route => modelRouteFromCall(projectModelRouteParameters(route, "dsmm-config", modelParameterPolicy.mode !== "native-defaults")));
|
|
215
|
+
invocation = freezeSettings({ target: evidence.role, effectiveLevel: evidence.invocation.level, routeSource: evidence.invocation.routeSource,
|
|
216
|
+
initialRoute: evidence.invocation.initialRoute, candidates: [evidence.invocation.initialRoute, ...fallbacks], modelParameterPolicy,
|
|
217
|
+
...(evidence.version === 1 ? {} : { requestedRoute: evidence.invocation.requestedRoute, effortSource: evidence.invocation.effortSource, requestedPolicy: policy }),
|
|
218
|
+
exactEffort: evidence.invocation.routeSource === "invocation-route" ? policy.primary?.reasoningEffort !== undefined
|
|
219
|
+
: evidence.invocation.routeSource === "level" && level?.reasoningEffort !== undefined,
|
|
220
|
+
policy: { ...policy, primary: evidence.invocation.initialRoute, fallbackRoutes: fallbacks } });
|
|
221
|
+
const fresh = this.preparedInvocations.get(agent);
|
|
222
|
+
if (candidate.creation && fresh !== undefined)
|
|
223
|
+
invocation = fresh;
|
|
224
|
+
}
|
|
225
|
+
const identity = Object.freeze({ role: evidence.role, child: true, parent, epoch: original.epoch, readOnly,
|
|
226
|
+
...(filter === undefined ? {} : { toolFilter: inheritToolFilter(undefined, filter) }) });
|
|
227
|
+
this.captureIdentity(agent, identity, original);
|
|
228
|
+
bindRoleInvocation(agent, invocation, "mode" in evidence ? undefined : evidence);
|
|
229
|
+
captureRoleRuntimePolicy(original.settings, evidence.role, invocation.policy);
|
|
230
|
+
const call = this.calls.getStore();
|
|
231
|
+
if (candidate.creation && call?.parent === parent && call.role === evidence.role)
|
|
232
|
+
call.admittedChild?.(agent);
|
|
233
|
+
this.preparedInvocations.delete(agent);
|
|
234
|
+
this.preparedCaptures.delete(agent);
|
|
235
|
+
}
|
|
236
|
+
assertChildDelivery(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
|
+
const evidence = "mode" in raw ? parseLegacyChildEvidence(raw) : parseChildAdmissionCapture(raw);
|
|
242
|
+
if (evidence.childSessionId !== childId || evidence.parentSessionId !== ticket.parent.id)
|
|
243
|
+
throw new SubagentError("Delivery evidence is not this direct child", "UNAUTHORIZED");
|
|
244
|
+
this.assertDelegation(ticket.parent, evidence.role);
|
|
245
|
+
const depth = delegationDepthOf(ticket.parent) + 1;
|
|
246
|
+
const maximum = ticket.admission.settings.subagents.maxDepth ?? ticket.parent.ctx.get("subagents")?.resolveMaxDepth();
|
|
247
|
+
if (maximum !== undefined && depth > maximum || !("mode" in evidence) && depth > evidence.authorityCeiling.maxDepth)
|
|
248
|
+
throw new SubagentError("Delivery exceeds the original or current delegation depth ceiling", "UNAUTHORIZED");
|
|
249
|
+
if (!("mode" in evidence) && (!evidence.runtimePolicyCapture.modules.deepwork.enabled || !evidence.authorityCeiling.roles.includes(evidence.role)))
|
|
250
|
+
throw new SubagentError("Original child role is not permitted", "UNAUTHORIZED");
|
|
251
|
+
}
|
|
252
|
+
readOnly(identity) { return identity.readOnly === true || DSMM_ROLES.find(row => row.id === identity.role)?.access === "read-only"; }
|
|
51
253
|
agents() {
|
|
52
254
|
const registry = this.ctx.get?.("agents");
|
|
53
255
|
if (registry === undefined)
|
|
@@ -58,10 +260,28 @@ export class DsmmRolePolicy {
|
|
|
58
260
|
if (agent.id === undefined || this.agents().get(agent.id) !== agent)
|
|
59
261
|
throw new SubagentError("DSMM delegation requires the exact live Agent", "UNAUTHORIZED");
|
|
60
262
|
}
|
|
263
|
+
isAdmittedChild(agent) {
|
|
264
|
+
const admitted = liveIdentities.get(agent), identity = admitted?.identity;
|
|
265
|
+
return admitted?.admission !== undefined && identity?.child === true && identity.parent !== undefined
|
|
266
|
+
&& this.agents().get(identity.parent.id) === identity.parent && this.agents().isOwnedBy(agent.id, identity.parent);
|
|
267
|
+
}
|
|
268
|
+
assertPlannerRootAdmission(agent, settings) {
|
|
269
|
+
if (settings.presets.plannerRootEnabled)
|
|
270
|
+
return;
|
|
271
|
+
const selected = resolveSelectedAgentPreset(agent.session);
|
|
272
|
+
const composed = agent.ctx?.get?.("agentPresets")?.composedPreset(agent.ctx);
|
|
273
|
+
if (selected !== "dsmm-planner" && composed !== "dsmm-planner")
|
|
274
|
+
return;
|
|
275
|
+
// Origin metadata alone cannot exempt a Root from this admission boundary.
|
|
276
|
+
if (this.isAdmittedChild(agent))
|
|
277
|
+
return;
|
|
278
|
+
throw new SubagentError("Standing DSMM root role is not admitted", "UNAUTHORIZED");
|
|
279
|
+
}
|
|
61
280
|
/** Core fence runs before native prompt/body assembly or provider execution. */
|
|
62
281
|
assertModuleAdmission(agent) {
|
|
63
282
|
this.assertLive(agent);
|
|
64
283
|
const settings = this.getSettings(agent);
|
|
284
|
+
this.assertPlannerRootAdmission(agent, settings);
|
|
65
285
|
const selected = agent.ctx?.get?.("agentPresets")?.composedPreset(agent.ctx)
|
|
66
286
|
?? resolveSelectedAgentPreset(agent.session);
|
|
67
287
|
const descriptor = foldSubagentDescriptor(childOwnedSessionEvents(agent.session));
|
|
@@ -71,13 +291,20 @@ export class DsmmRolePolicy {
|
|
|
71
291
|
if (agent.session.header?.origin !== "subagent" && selected?.startsWith("dsmm-")
|
|
72
292
|
&& !isDsmmRoleId(selected))
|
|
73
293
|
throw new SubagentError("DSMM unknown standing root is not admitted", "UNAUTHORIZED");
|
|
74
|
-
const
|
|
75
|
-
|
|
294
|
+
const implicit = agent.session.header?.origin !== "subagent" && settings.modules.deepwork.enabled && this.mode.active(agent, settings.defaultActive) ? "dsmm-orchestrator" : undefined;
|
|
295
|
+
const role = providerRole ?? (isDsmmRoleId(selected) ? selected : implicit);
|
|
296
|
+
if (role !== undefined && (!settings.modules.deepwork.enabled || !isDsmmRoleId(role) || !settings.roles[role])) {
|
|
76
297
|
throw new SubagentError("Deepwork module or role is not admitted in this Agent; standing presets and child resume cannot enable it", "UNAUTHORIZED");
|
|
77
298
|
}
|
|
299
|
+
if (role === "dsmm-planner" && !isRootRoleEnabled(settings, role) && !this.isAdmittedChild(agent)) {
|
|
300
|
+
throw new SubagentError("Standing DSMM root role is not admitted", "UNAUTHORIZED");
|
|
301
|
+
}
|
|
78
302
|
}
|
|
79
303
|
identity(agent) {
|
|
80
304
|
this.assertLive(agent);
|
|
305
|
+
const execution = this.executions.getStore(), call = execution === undefined ? undefined : this.toolCalls.get(execution);
|
|
306
|
+
if (call?.active && call.agent === agent && call.identity !== undefined)
|
|
307
|
+
return call.identity;
|
|
81
308
|
const existing = liveIdentities.get(agent)?.identity;
|
|
82
309
|
if (existing?.child)
|
|
83
310
|
return existing;
|
|
@@ -88,31 +315,45 @@ export class DsmmRolePolicy {
|
|
|
88
315
|
return existing;
|
|
89
316
|
}
|
|
90
317
|
const settings = this.getSettings(agent);
|
|
318
|
+
this.assertPlannerRootAdmission(agent, settings);
|
|
91
319
|
const selected = agent.ctx?.get?.("agentPresets")?.composedPreset(agent.ctx);
|
|
92
|
-
const role = isDsmmRoleId(selected) ? selected : settings.modules.deepwork.enabled && agent.session.header?.origin !== "subagent" &&
|
|
320
|
+
const role = isDsmmRoleId(selected) ? selected : settings.modules.deepwork.enabled && agent.session.header?.origin !== "subagent" && this.mode.active(agent, settings.defaultActive) ? "dsmm-orchestrator" : undefined;
|
|
321
|
+
if (role === "dsmm-planner" && !isRootRoleEnabled(settings, role)) {
|
|
322
|
+
throw new SubagentError("Standing DSMM root role is not admitted", "UNAUTHORIZED");
|
|
323
|
+
}
|
|
93
324
|
return Object.freeze({ role, child: agent.session.header?.origin === "subagent", epoch: this.getSettings.admission?.(agent).epoch ?? "trusted-direct" });
|
|
94
325
|
}
|
|
95
326
|
targets(agent) {
|
|
327
|
+
const execution = this.executions.getStore(), call = execution === undefined ? undefined : this.toolCalls.get(execution);
|
|
328
|
+
if (call?.active && call.agent === agent && call.targets !== undefined)
|
|
329
|
+
return call.targets;
|
|
96
330
|
const identity = this.identity(agent);
|
|
97
331
|
const settings = this.getSettings(agent);
|
|
98
332
|
if (!settings.modules.deepwork.enabled || identity.role === undefined || !settings.roles[identity.role])
|
|
99
333
|
return [];
|
|
100
334
|
return allowedRoleChildren(identity.role, identity.child).filter((role) => settings.roles[role]
|
|
335
|
+
&& (!this.readOnly(identity) || DSMM_ROLES.find(row => row.id === role).access === "read-only")
|
|
101
336
|
&& (identity.toolFilter?.allow === undefined || identity.toolFilter.allow.includes(roleToolName(role)))
|
|
102
337
|
&& !identity.toolFilter?.deny?.includes(roleToolName(role)));
|
|
103
338
|
}
|
|
104
339
|
assertDelegation(parent, role) {
|
|
340
|
+
const execution = this.executions.getStore(), call = execution === undefined ? undefined : this.toolCalls.get(execution);
|
|
341
|
+
if (call?.active && call.agent === parent && call.target === role && call.identity !== undefined)
|
|
342
|
+
return { parent, role, epoch: call.identity.epoch };
|
|
105
343
|
const identity = this.identity(parent);
|
|
106
344
|
if (!this.targets(parent).includes(role))
|
|
107
345
|
throw new SubagentError(`DSMM ${identity.role ?? "unadmitted Agent"} cannot delegate ${role}`, "UNAUTHORIZED");
|
|
108
346
|
return { parent, role, epoch: identity.epoch };
|
|
109
347
|
}
|
|
110
|
-
duringDelegation(parent, role, operation, toolFilter) {
|
|
111
|
-
|
|
348
|
+
duringDelegation(parent, role, operation, toolFilter, maxDepth, admittedChild) {
|
|
349
|
+
const identity = this.assertDelegation(parent, role), outer = this.calls.getStore();
|
|
350
|
+
const upstream = outer?.parent === parent && outer.role === role && outer.epoch === identity.epoch ? outer.admittedChild : undefined;
|
|
351
|
+
const notify = admittedChild === undefined ? upstream : upstream === undefined ? admittedChild : (agent) => { upstream(agent); admittedChild(agent); };
|
|
352
|
+
return this.calls.run({ ...identity, toolFilter, maxDepth, admittedChild: notify }, operation);
|
|
112
353
|
}
|
|
113
354
|
prepareContinuable(parent, role, signal) {
|
|
114
355
|
signal.throwIfAborted();
|
|
115
|
-
this.assertDelegation(parent, role);
|
|
356
|
+
return this.assertDelegation(parent, role);
|
|
116
357
|
}
|
|
117
358
|
admit(agent) {
|
|
118
359
|
this.assertLive(agent);
|
|
@@ -130,44 +371,15 @@ export class DsmmRolePolicy {
|
|
|
130
371
|
}
|
|
131
372
|
if (parent === undefined)
|
|
132
373
|
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" });
|
|
374
|
+
const original = this.getSettings.admission?.(agent);
|
|
375
|
+
if (original?.childCapture !== undefined) {
|
|
376
|
+
this.validatePreparedRole(agent, parent, { evidence: original.childCapture, admission: original, creation: false, retained: false });
|
|
377
|
+
return liveIdentities.get(agent).identity;
|
|
378
|
+
}
|
|
379
|
+
throw new SubagentError("DSMM child requires the completed original role/capture admission; generic spawn cannot bypass delegation policy", "UNAUTHORIZED");
|
|
380
|
+
}
|
|
381
|
+
captureIdentity(agent, identity, admission) {
|
|
382
|
+
liveIdentities.set(agent, { identity, admission, readEpoch: () => this.getSettings.admission?.(agent).epoch ?? "trusted-direct" });
|
|
171
383
|
return identity;
|
|
172
384
|
}
|
|
173
385
|
captureTools(agent, tools, controlledNames = [], reset = false) {
|
|
@@ -175,28 +387,192 @@ export class DsmmRolePolicy {
|
|
|
175
387
|
const previous = toolIdentities.get(agent);
|
|
176
388
|
const definitions = previous === undefined || reset || previous.realm !== realm ? new Map() : previous.definitions;
|
|
177
389
|
for (const schema of tools.schemas(agent)) {
|
|
178
|
-
if (previous === undefined || reset || previous.realm !== realm || controlledNames.includes(schema.name))
|
|
179
|
-
|
|
390
|
+
if (previous === undefined || reset || previous.realm !== realm || controlledNames.includes(schema.name)) {
|
|
391
|
+
const definition = tools.get(schema.name, agent);
|
|
392
|
+
definitions.set(schema.name, definition);
|
|
393
|
+
if (controlledNames.includes(schema.name))
|
|
394
|
+
controlledDefinitions.add(definition);
|
|
395
|
+
}
|
|
180
396
|
}
|
|
181
397
|
toolIdentities.set(agent, { realm, definitions });
|
|
182
398
|
}
|
|
183
|
-
|
|
399
|
+
/** Existing exact role denials only; missing admission or capability proof is not a blacklist. */
|
|
400
|
+
toolBlacklistDenial(agent, name, execution) {
|
|
401
|
+
return this.executions.exit(() => this.blacklistDenial(agent, name, execution));
|
|
402
|
+
}
|
|
403
|
+
blacklistDenial(agent, name, execution) {
|
|
404
|
+
this.assertLive(agent);
|
|
405
|
+
const captured = liveIdentities.get(agent)?.identity;
|
|
406
|
+
if (captured?.toolFilter?.deny?.includes(name))
|
|
407
|
+
return "DSMM child native toolFilter does not permit this tool";
|
|
408
|
+
if (captured?.readOnly === true && READONLY_ROLE_DENIED_TOOLS.includes(name)
|
|
409
|
+
&& this.isAdmittedChild(agent))
|
|
410
|
+
return "DSMM read-only role does not permit this tool";
|
|
411
|
+
const definition = toolIdentities.get(agent)?.definitions.get(name);
|
|
412
|
+
const native = agent.ctx, tools = native.get("agentPresets")?.serviceFor(agent, "tools") ?? native.get("tools");
|
|
413
|
+
if (definition === undefined || tools?.get(name, agent) !== definition)
|
|
414
|
+
return undefined;
|
|
415
|
+
let identity, settings;
|
|
416
|
+
try {
|
|
417
|
+
identity = this.identity(agent);
|
|
418
|
+
settings = this.getSettings(agent);
|
|
419
|
+
}
|
|
420
|
+
catch (error) {
|
|
421
|
+
if (error instanceof DsmmProfileError && !["disposed", "not-owned", "cancelled"].includes(error.code)
|
|
422
|
+
|| error instanceof SubagentError && error.code === "UNAUTHORIZED")
|
|
423
|
+
return undefined;
|
|
424
|
+
throw error;
|
|
425
|
+
}
|
|
426
|
+
if (identity.role === undefined)
|
|
427
|
+
return undefined;
|
|
428
|
+
if (!settings.modules.deepwork.enabled || !settings.roles[identity.role])
|
|
429
|
+
return "DSMM role is disabled in this Agent admission";
|
|
430
|
+
const args = execution?.arguments;
|
|
431
|
+
const target = roleFromToolName(name) ?? (name === "dsmm_role" ? args?.role : name === "dsmm_category" ? args?.category : undefined);
|
|
432
|
+
if (isDsmmRoleId(target) && controlledDefinitions.has(definition)
|
|
433
|
+
&& (!settings.roles[target] || !allowedRoleChildren(identity.role, identity.child).includes(target)))
|
|
434
|
+
return `DSMM delegation to ${target} is not permitted`;
|
|
435
|
+
if (this.readOnly(identity) && READONLY_ROLE_DENIED_TOOLS.includes(name))
|
|
436
|
+
return "DSMM read-only role does not permit this tool";
|
|
437
|
+
return undefined;
|
|
438
|
+
}
|
|
439
|
+
captureToolExecution(execution, full) {
|
|
440
|
+
const agent = execution.agent;
|
|
441
|
+
if (agent === undefined)
|
|
442
|
+
return;
|
|
443
|
+
this.assertLive(agent);
|
|
444
|
+
const native = agent.ctx, agents = native.get("agents");
|
|
445
|
+
const tools = native.get("agentPresets")?.serviceFor(agent, "tools") ?? native.get("tools");
|
|
446
|
+
const definition = tools?.get(execution.name, agent);
|
|
447
|
+
const owned = definition !== undefined && controlledDefinitions.has(definition);
|
|
448
|
+
const call = { active: false, agent, context: native, registry: Reflect.get(agents, symbols.original) ?? agents,
|
|
449
|
+
realm: tools === undefined ? undefined : Reflect.get(tools, symbols.original) ?? tools, scopeParent: scopeParentOf(agent),
|
|
450
|
+
parents: agents.list().filter(parent => parent !== agent && agents.isOwnedBy(agent.id, parent)), parentSession: agent.session.header.parentSession,
|
|
451
|
+
name: execution.name, args: execution.arguments, callId: execution.callId, signal: execution.signal,
|
|
452
|
+
...!owned ? {} : { definition, body: definition.execute, argumentsJson: JSON.stringify(execution.arguments) } };
|
|
453
|
+
this.toolCalls.set(execution, call);
|
|
454
|
+
if (!owned)
|
|
455
|
+
return;
|
|
456
|
+
this.executions.exit(() => {
|
|
457
|
+
try {
|
|
458
|
+
call.identity = this.identity(agent);
|
|
459
|
+
call.targets = this.targets(agent);
|
|
460
|
+
const args = execution.arguments;
|
|
461
|
+
const target = roleFromToolName(execution.name) ?? (execution.name === "dsmm_role" ? args?.role : execution.name === "dsmm_category" ? args?.category : undefined);
|
|
462
|
+
if (isDsmmRoleId(target))
|
|
463
|
+
call.target = target;
|
|
464
|
+
}
|
|
465
|
+
catch (error) {
|
|
466
|
+
if (!full || !(error instanceof DsmmProfileError || error instanceof SubagentError))
|
|
467
|
+
throw error;
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
assertToolExecution(execution) {
|
|
472
|
+
execution.signal.throwIfAborted();
|
|
473
|
+
if (execution.agent === undefined)
|
|
474
|
+
return;
|
|
475
|
+
this.assertLive(execution.agent);
|
|
476
|
+
const call = this.toolCalls.get(execution);
|
|
477
|
+
if (call === undefined)
|
|
478
|
+
return;
|
|
479
|
+
call.signal.throwIfAborted();
|
|
480
|
+
const agent = execution.agent, agents = agent.ctx.get("agents");
|
|
481
|
+
const tools = agent.ctx.get("agentPresets")?.serviceFor(agent, "tools") ?? agent.ctx.get("tools");
|
|
482
|
+
const parents = agents.list().filter(parent => parent !== agent && agents.isOwnedBy(agent.id, parent));
|
|
483
|
+
if (agent !== call.agent || agent.ctx !== call.context || (Reflect.get(agents, symbols.original) ?? agents) !== call.registry
|
|
484
|
+
|| (tools === undefined ? undefined : Reflect.get(tools, symbols.original) ?? tools) !== call.realm || scopeParentOf(agent) !== call.scopeParent
|
|
485
|
+
|| agent.session.header.parentSession !== call.parentSession || parents.length !== call.parents.length || parents.some(parent => !call.parents.includes(parent)))
|
|
486
|
+
throw new SubagentError("Native tool caller ownership changed", "UNAUTHORIZED");
|
|
487
|
+
if (call.definition === undefined)
|
|
488
|
+
return;
|
|
489
|
+
const current = tools?.get(call.name, agent);
|
|
490
|
+
if (execution.name !== call.name || execution.arguments !== call.args || execution.callId !== call.callId || JSON.stringify(execution.arguments) !== call.argumentsJson
|
|
491
|
+
|| call.definition.execute !== call.body || current !== undefined && current !== call.definition)
|
|
492
|
+
throw new SubagentError("Owned tool registration or invocation changed", "UNAUTHORIZED");
|
|
493
|
+
}
|
|
494
|
+
beforeToolDecision(operation) { return this.executions.exit(operation); }
|
|
495
|
+
async duringToolExecution(execution, operation) {
|
|
496
|
+
this.assertToolExecution(execution);
|
|
497
|
+
const call = this.toolCalls.get(execution);
|
|
498
|
+
if (call !== undefined)
|
|
499
|
+
call.active = true;
|
|
500
|
+
try {
|
|
501
|
+
return await this.executions.run(execution, operation);
|
|
502
|
+
}
|
|
503
|
+
finally {
|
|
504
|
+
if (call !== undefined)
|
|
505
|
+
call.active = false;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
toolDenial(agent, name, tools, execution) {
|
|
509
|
+
const scoped = this.executions.getStore();
|
|
510
|
+
const active = execution ?? (scoped !== undefined && this.toolCalls.get(scoped)?.active ? scoped : undefined);
|
|
511
|
+
if (active !== undefined && active.agent === agent && active.name === name) {
|
|
512
|
+
this.assertToolExecution(active);
|
|
513
|
+
return undefined;
|
|
514
|
+
}
|
|
515
|
+
if (tools === undefined)
|
|
516
|
+
return this.toolBlacklistDenial(agent, name);
|
|
517
|
+
return this.preToolDenial(agent, name, tools);
|
|
518
|
+
}
|
|
519
|
+
preToolDenial(agent, name, tools, execution) {
|
|
520
|
+
return this.executions.exit(() => this.permissionDenial(agent, name, tools, execution));
|
|
521
|
+
}
|
|
522
|
+
permissionDenial(agent, name, tools, execution) {
|
|
184
523
|
const identity = this.identity(agent);
|
|
185
524
|
const settings = this.getSettings(agent);
|
|
186
|
-
|
|
187
|
-
const
|
|
525
|
+
const native = agent.ctx, realm = tools ?? native.get("agentPresets")?.serviceFor(agent, "tools") ?? native.get("tools");
|
|
526
|
+
const definition = realm?.get(name, agent);
|
|
527
|
+
const owned = definition !== undefined && controlledDefinitions.has(definition);
|
|
528
|
+
const controlled = owned && (name === "dsmm_role" || name === "dsmm_category");
|
|
529
|
+
const target = owned ? roleFromToolName(name) : undefined;
|
|
188
530
|
const readonly = identity.readOnly || DSMM_ROLES.find((row) => row.id === identity.role)?.access === "read-only";
|
|
189
|
-
|
|
531
|
+
const checkedRealm = tools ?? (execution === undefined ? undefined : realm);
|
|
532
|
+
if (checkedRealm !== undefined && (readonly || target !== undefined || controlled)) {
|
|
190
533
|
const admitted = toolIdentities.get(agent);
|
|
191
|
-
if (admitted === undefined || admitted.realm !== (Reflect.get(
|
|
192
|
-
|| admitted.definitions.get(name) !==
|
|
534
|
+
if (admitted === undefined || admitted.realm !== (Reflect.get(checkedRealm, symbols.original) ?? checkedRealm)
|
|
535
|
+
|| admitted.definitions.get(name) !== checkedRealm.get(name, agent))
|
|
193
536
|
return "DSMM tool definition was not admitted in this exact Agent realm";
|
|
194
537
|
}
|
|
195
538
|
if (target !== undefined)
|
|
196
|
-
return
|
|
539
|
+
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"
|
|
540
|
+
: this.targets(agent).includes(target) ? undefined : `DSMM delegation to ${target} is not permitted`;
|
|
541
|
+
if (controlled) {
|
|
542
|
+
const kind = name === "dsmm_role" ? "role" : "category";
|
|
543
|
+
if (name === "dsmm_role" && settings.subagents.toolTopology !== "parameterized" || !this.targets(agent).some(role => DSMM_ROLES.find(row => row.id === role).kind === kind))
|
|
544
|
+
return "DSMM merged delegation entry is not admitted";
|
|
545
|
+
// Native merged-entry restrictions and the per-target ceiling both apply.
|
|
546
|
+
if (identity.toolFilter?.allow !== undefined && !identity.toolFilter.allow.includes(name) || identity.toolFilter?.deny?.includes(name))
|
|
547
|
+
return "DSMM native filter does not permit this merged entry";
|
|
548
|
+
const args = execution?.arguments;
|
|
549
|
+
const target = kind === "role" ? args?.role : args?.category;
|
|
550
|
+
if (isDsmmRoleId(target) && !this.targets(agent).includes(target))
|
|
551
|
+
return `DSMM delegation to ${target} is not permitted`;
|
|
552
|
+
return undefined;
|
|
553
|
+
}
|
|
197
554
|
if (identity.toolFilter?.allow !== undefined && !identity.toolFilter.allow.includes(name) && name !== "structured_output"
|
|
198
555
|
|| identity.toolFilter?.deny?.includes(name))
|
|
199
556
|
return "DSMM child native toolFilter does not permit this tool";
|
|
557
|
+
if (name === "send_message" && liveIdentities.get(agent)?.admission?.childEvidence?.mode === "legacy-conservative") {
|
|
558
|
+
const realm = tools ?? agent.ctx.get("tools"), parent = identity.parent;
|
|
559
|
+
const capability = realm === undefined ? undefined : this.collaborators?.classifyLegacyTool?.(name, realm, agent);
|
|
560
|
+
if (parent === undefined || realm === undefined || capability?.kind !== "child-report" || realm.get(name, agent) !== capability.definition)
|
|
561
|
+
return "DSMM legacy report requires its audited native capability";
|
|
562
|
+
try {
|
|
563
|
+
this.assertLive(parent);
|
|
564
|
+
this.assertDelegation(parent, identity.role);
|
|
565
|
+
if (execution !== undefined) {
|
|
566
|
+
capability.assertArguments(execution.arguments);
|
|
567
|
+
const args = execution.arguments;
|
|
568
|
+
if (args === null || typeof args !== "object" || args.agent_id !== parent.id)
|
|
569
|
+
return "DSMM legacy report destination must be this exact direct parent";
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
catch {
|
|
573
|
+
return "DSMM legacy report arguments or current parent authority are not admitted";
|
|
574
|
+
}
|
|
575
|
+
}
|
|
200
576
|
if (readonly && !readonlyRoleTool(name, settings))
|
|
201
577
|
return "DSMM read-only role does not permit this tool";
|
|
202
578
|
if (identity.role === undefined)
|
|
@@ -212,6 +588,7 @@ export class DsmmRolePolicy {
|
|
|
212
588
|
if (native === undefined)
|
|
213
589
|
throw new Error("DSMM native role lifecycle requires an Agent context");
|
|
214
590
|
native.effect(() => async () => {
|
|
591
|
+
this.collaborators?.revokeParent?.(agent, "role-residency-disposed");
|
|
215
592
|
const agents = this.agents();
|
|
216
593
|
if (agents.get(agent.id) !== agent)
|
|
217
594
|
throw new Error("DSMM Agent was detached before continuable descendants drained");
|
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,7 +10,6 @@ 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
|
/** Only the native outer start owns descriptors, capability admission and returned runs. */
|