@dsmm/dsmm 0.3.0 → 0.3.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 +26 -40
- package/cordis.patch.yml +9 -13
- package/docs/agent-presets.md +26 -14
- package/docs/compatibility.md +24 -68
- package/docs/deferred-native-approval-risk.md +8 -12
- package/docs/design.md +25 -254
- package/docs/lsp.md +2 -2
- package/docs/migration-from-ocmm.md +38 -51
- package/docs/model-routing.md +21 -21
- package/docs/native-permissions.md +17 -7
- package/docs/profiles.md +13 -9
- package/docs/releasing.md +25 -311
- package/docs/roadmap.md +52 -241
- package/docs/runtime-recovery.md +29 -91
- package/docs/safety-guards.md +19 -16
- package/docs/settings-status.md +23 -11
- package/docs/skill-sync.md +17 -17
- package/docs/web-fetch-fakeip.md +82 -0
- package/lib/child-capture.d.ts +12 -2
- package/lib/child-capture.js +22 -5
- package/lib/client/ChildPermissions.d.ts +43 -0
- package/lib/client/ChildPermissions.js +100 -0
- package/lib/client/ChildrenPanel.d.ts +5 -5
- package/lib/client/ChildrenPanel.js +6 -18
- package/lib/client/DeploymentFields.d.ts +32 -0
- package/lib/client/DeploymentFields.js +70 -0
- package/lib/client/DeploymentPage.d.ts +21 -6
- package/lib/client/DeploymentPage.js +80 -112
- package/lib/client/HistoryContinuation.d.ts +7 -0
- package/lib/client/HistoryContinuation.js +22 -0
- package/lib/client/NativeCommandEntries.d.ts +17 -0
- package/lib/client/NativeCommandEntries.js +68 -0
- package/lib/client/PermissionPanelEntry.d.ts +8 -0
- package/lib/client/PermissionPanelEntry.js +11 -0
- package/lib/client/PermissionsPanel.d.ts +3 -1
- package/lib/client/PermissionsPanel.js +10 -9
- package/lib/client/ProfilesSection.js +8 -6
- package/lib/client/RoleAvailability.js +1 -1
- package/lib/client/RoleToolView-data.d.ts +35 -0
- package/lib/client/RoleToolView-data.js +52 -0
- package/lib/client/RoleToolView-locales.d.ts +36 -0
- package/lib/client/RoleToolView-locales.js +20 -0
- package/lib/client/RoleToolView.d.ts +10 -0
- package/lib/client/RoleToolView.js +47 -0
- package/lib/client/SessionProfiles.js +51 -24
- package/lib/client/TemporaryPermissions.d.ts +21 -0
- package/lib/client/TemporaryPermissions.js +94 -0
- package/lib/client/children-controller.d.ts +2 -8
- package/lib/client/children-controller.js +1 -26
- package/lib/client/children-locales.d.ts +27 -52
- package/lib/client/children-locales.js +8 -12
- package/lib/client/configuration-display.d.ts +5 -0
- package/lib/client/configuration-display.js +11 -0
- package/lib/client/controller.d.ts +18 -0
- package/lib/client/controller.js +118 -28
- package/lib/client/deployment-controller.d.ts +13 -1
- package/lib/client/deployment-controller.js +84 -24
- package/lib/client/deployment-data.d.ts +1 -0
- package/lib/client/deployment-data.js +4 -1
- package/lib/client/deployment-locales.d.ts +43 -0
- package/lib/client/deployment-locales.js +45 -19
- package/lib/client/deployment-modules.d.ts +9 -0
- package/lib/client/deployment-modules.js +24 -0
- package/lib/client/deployment-workspace.d.ts +48 -0
- package/lib/client/deployment-workspace.js +123 -0
- package/lib/client/history-controller.d.ts +29 -0
- package/lib/client/history-controller.js +111 -0
- package/lib/client/history-entry.d.ts +11 -0
- package/lib/client/history-entry.js +106 -0
- package/lib/client/history-locales.d.ts +95 -0
- package/lib/client/history-locales.js +41 -0
- package/lib/client/index.js +26 -76
- package/lib/client/locales.d.ts +13 -0
- package/lib/client/locales.js +104 -86
- package/lib/client/permission-controller.d.ts +1 -0
- package/lib/client/permission-controller.js +3 -2
- package/lib/client/permission-locales.d.ts +51 -0
- package/lib/client/permission-locales.js +59 -19
- package/lib/client/session-labels.js +4 -3
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +9 -8
- package/lib/client/temporary-permission-client.d.ts +20 -0
- package/lib/client/temporary-permission-client.js +52 -0
- package/lib/client/temporary-permission-entry.d.ts +6 -0
- package/lib/client/temporary-permission-entry.js +56 -0
- package/lib/client.js +5691 -3439
- package/lib/commands.js +2 -0
- package/lib/config-file-store.d.ts +3 -0
- package/lib/config-file-store.js +4 -2
- package/lib/config-revision.d.ts +5 -0
- package/lib/config-revision.js +11 -0
- package/lib/core-permission-authority.js +11 -41
- package/lib/deployment-config.d.ts +9 -2
- package/lib/deployment-config.js +35 -8
- package/lib/deployment-permission-rules.js +19 -7
- package/lib/dsh-types.d.ts +1 -1
- package/lib/history-candidates.d.ts +30 -0
- package/lib/history-candidates.js +176 -0
- package/lib/history-codec.d.ts +11 -0
- package/lib/history-codec.js +102 -0
- package/lib/history-contract.d.ts +44 -0
- package/lib/history-contract.js +2 -0
- package/lib/history-controller.d.ts +42 -0
- package/lib/history-controller.js +329 -0
- package/lib/history-policy.d.ts +4 -0
- package/lib/history-policy.js +8 -0
- package/lib/history-remote.d.ts +28 -0
- package/lib/history-remote.js +17 -0
- package/lib/history-rpc.d.ts +24 -0
- package/lib/history-rpc.js +136 -0
- package/lib/history-support.d.ts +15 -0
- package/lib/history-support.js +21 -0
- package/lib/history-types.d.ts +67 -0
- package/lib/history-types.js +2 -0
- package/lib/host-llm-startup.js +3 -3
- package/lib/host-llm.d.ts +9 -3
- package/lib/host-llm.js +48 -8
- package/lib/index.d.ts +18 -20
- package/lib/index.js +147 -415
- package/lib/lifetime.d.ts +4 -0
- package/lib/lifetime.js +22 -0
- package/lib/live-pi-ai-owner.d.ts +1 -0
- package/lib/live-pi-ai-owner.js +8 -4
- package/lib/mode.d.ts +3 -2
- package/lib/mode.js +28 -41
- package/lib/model-routing.d.ts +2 -8
- package/lib/model-routing.js +59 -175
- package/lib/native-admission.d.ts +77 -0
- package/lib/native-admission.js +503 -0
- package/lib/native-pi-ai-wire.d.ts +3 -1
- package/lib/native-pi-ai-wire.js +47 -13
- package/lib/permission-child-control.d.ts +36 -0
- package/lib/permission-child-control.js +164 -0
- package/lib/permission-control.d.ts +2 -3
- package/lib/permission-control.js +7 -0
- package/lib/permission-controller.js +2 -2
- package/lib/permission-exec-argv.d.ts +32 -0
- package/lib/permission-exec-argv.js +171 -0
- package/lib/permission-fs-search.js +2 -1
- package/lib/permission-fs.js +2 -1
- package/lib/permission-native-rules.js +3 -3
- package/lib/permission-temporary-files.d.ts +19 -0
- package/lib/permission-temporary-files.js +248 -0
- package/lib/permission-temporary-grants.d.ts +106 -0
- package/lib/permission-temporary-grants.js +198 -0
- package/lib/permission-temporary-install.d.ts +25 -0
- package/lib/permission-temporary-install.js +86 -0
- package/lib/permission-temporary-remote.d.ts +19 -0
- package/lib/permission-temporary-remote.js +75 -0
- package/lib/permission-temporary-rpc.d.ts +37 -0
- package/lib/permission-temporary-rpc.js +154 -0
- package/lib/permission-temporary-types.d.ts +47 -0
- package/lib/permission-temporary-types.js +2 -0
- package/lib/permission-temporary-web.d.ts +11 -0
- package/lib/permission-temporary-web.js +154 -0
- package/lib/permission-web.js +2 -1
- package/lib/preset-registry.js +3 -2
- package/lib/preset-skills.d.ts +3 -12
- package/lib/preset-skills.js +28 -58
- package/lib/profile-diagnostics.d.ts +1 -1
- package/lib/profile-diagnostics.js +2 -2
- package/lib/profile-remote.js +61 -22
- package/lib/profile-rpc.d.ts +4 -3
- package/lib/profile-rpc.js +35 -37
- package/lib/profile-runtime.d.ts +42 -74
- package/lib/profile-runtime.js +314 -617
- package/lib/profile-store.d.ts +20 -8
- package/lib/profile-store.js +112 -63
- package/lib/profile-types.d.ts +19 -4
- package/lib/profiles.d.ts +3 -1
- package/lib/profiles.js +9 -7
- package/lib/prompt-content.d.ts +1 -0
- package/lib/prompt-content.js +4 -1
- package/lib/prompts.d.ts +2 -12
- package/lib/prompts.js +11 -66
- package/lib/role-control-remote.d.ts +1 -4
- package/lib/role-control-remote.js +8 -36
- package/lib/role-control-rpc.d.ts +10 -36
- package/lib/role-control-rpc.js +112 -269
- package/lib/role-control-types.d.ts +3 -26
- package/lib/role-control-types.js +3 -4
- package/lib/role-identity.d.ts +5 -0
- package/lib/role-identity.js +10 -0
- package/lib/role-invocation.d.ts +3 -3
- package/lib/role-invocation.js +2 -2
- package/lib/role-llm-runtime.js +5 -11
- package/lib/role-policy.d.ts +19 -50
- package/lib/role-policy.js +136 -508
- package/lib/role-providers.d.ts +5 -8
- package/lib/role-providers.js +20 -86
- package/lib/role-routing.d.ts +1 -3
- package/lib/role-routing.js +24 -34
- package/lib/role-subagents.d.ts +5 -14
- package/lib/role-subagents.js +163 -108
- package/lib/runtime-integration.d.ts +5 -78
- package/lib/runtime-integration.js +11 -697
- package/lib/session-metadata.d.ts +13 -12
- package/lib/session-metadata.js +6 -31
- package/lib/session-scope.js +2 -1
- package/lib/settings.d.ts +5 -18
- package/lib/settings.js +19 -43
- package/lib/skills.d.ts +1 -0
- package/lib/skills.js +5 -1
- package/lib/state.d.ts +3 -2
- package/lib/state.js +26 -10
- package/lib/status.d.ts +1 -9
- package/lib/status.js +3 -55
- package/lib/web-fetch-address-policy.d.ts +24 -0
- package/lib/web-fetch-address-policy.js +189 -0
- package/lib/web-fetch-fakeip.d.ts +25 -0
- package/lib/web-fetch-fakeip.js +107 -0
- package/package.json +124 -106
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-gateway@0.2.1-rc.2.patch +13291 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-remotes@0.2.1-rc.2.patch +9133 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-client-ui-approval@0.2.1-rc.2.patch +156 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-subagent@0.2.1-rc.2.patch +3546 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-user-approval@0.2.1-rc.2.patch +431 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-web@0.2.1-rc.2.patch +119 -0
- package/patches/dsh-approval-settlement/README.md +41 -0
- package/patches/dsh-approval-settlement/metadata.json +10 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-loop@0.2.1-rc.2.patch +383 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-preset-registry@0.2.1-rc.2.patch +55 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-api-session-controller@0.2.1-rc.2.patch +16673 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-subagent@0.2.1-rc.2.patch +29 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-workspace@0.2.1-rc.2.patch +196 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence-jsonl@0.2.1-rc.2.patch +35 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence@0.2.1-rc.2.patch +40 -0
- package/docs/research/deepseek-v4-pro.md +0 -74
- package/docs/research/oh-dsh.md +0 -96
- package/lib/agent-registry.d.ts +0 -36
- package/lib/agent-registry.js +0 -75
- package/lib/child-admission.d.ts +0 -40
- package/lib/child-admission.js +0 -151
- package/lib/delivery-authority.d.ts +0 -83
- package/lib/delivery-authority.js +0 -397
- package/lib/native-child-evidence.d.ts +0 -40
- package/lib/native-child-evidence.js +0 -104
- package/lib/role-runs.d.ts +0 -138
- package/lib/role-runs.js +0 -335
- package/lib/session-persistence.d.ts +0 -36
- package/lib/session-persistence.js +0 -304
- package/lib/subagent-runtime.d.ts +0 -57
- package/lib/subagent-runtime.js +0 -257
- package/prompts/deepseek-flash.md +0 -11
- package/prompts/deepseek-v4-pro.md +0 -14
package/lib/index.js
CHANGED
|
@@ -4,463 +4,195 @@ import { registerSafetyGuards } from "./guards.js";
|
|
|
4
4
|
import { registerDeepworkPrompt } from "./mode.js";
|
|
5
5
|
import { registerAgentSkills } from "./preset-skills.js";
|
|
6
6
|
import { registerModelRouting } from "./model-routing.js";
|
|
7
|
-
import { registerRuntimeRecovery } from "./runtime-recovery.js";
|
|
8
|
-
import { reconcileRolePresets, resolveManagedPresetRoot } from "./preset-materializer.js";
|
|
9
7
|
import { registerHeadlessRoleTools, registerNativeSubagentControls } from "./role-subagents.js";
|
|
10
8
|
import { registerRolePresets } from "./preset-registry.js";
|
|
11
9
|
import { registerRoleProviders } from "./role-providers.js";
|
|
12
10
|
import { DsmmRolePolicy } from "./role-policy.js";
|
|
13
|
-
import { registerLspRuntime } from "./lsp.js";
|
|
14
11
|
import { createProfileRuntime } from "./profile-runtime.js";
|
|
15
12
|
import { DsmmProfilesHost, registerConfigRpc } from "./profile-rpc.js";
|
|
16
|
-
import { DSMM_CONFIG_SCHEMA, DSMM_NATIVE_CONFIG_SCHEMA
|
|
17
|
-
import { DeepworkModeController
|
|
18
|
-
import DsmmSessionPersistence from "./session-persistence.js";
|
|
19
|
-
import { isAbsolute } from "node:path";
|
|
20
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
21
|
-
import { DsmmProfileError } from "./profiles.js";
|
|
13
|
+
import { DSMM_CONFIG_SCHEMA, DSMM_NATIVE_CONFIG_SCHEMA } from "./settings.js";
|
|
14
|
+
import { DeepworkModeController } from "./state.js";
|
|
22
15
|
import { DsmmDeploymentConfig } from "./deployment-config.js";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import { scopeLifetime } from "./delivery-authority.js";
|
|
27
|
-
import { admittedAgentContext, assertSupportedHostStartup, classifyDsmmAgent, integrateSubagentRuntime, managedAgentContext, publicProfileRuntime, registerRoleControlContribution, registerRuntimeGuidance, runtimeAdmissionView } from "./runtime-integration.js";
|
|
16
|
+
import { NativeAdmission } from "./native-admission.js";
|
|
17
|
+
import { scopeLifetime } from "./lifetime.js";
|
|
18
|
+
import { runtimeAdmissionView, assertSupportedHostStartup } from "./runtime-integration.js";
|
|
28
19
|
import { createCorePermissionAuthority } from "./core-permission-authority.js";
|
|
29
|
-
import { nativeStandingFullAccess } from "./permission-native-access.js";
|
|
30
20
|
import { installCorePermissions } from "./core-permissions.js";
|
|
21
|
+
import { registerRoleControlRpc } from "./role-control-rpc.js";
|
|
22
|
+
import { nativeStandingFullAccess } from "./permission-native-access.js";
|
|
23
|
+
import { DsmmProfileError } from "./profiles.js";
|
|
24
|
+
import { registerLspRuntime } from "./lsp.js";
|
|
25
|
+
import { DsmmHistoryCandidates } from "./history-candidates.js";
|
|
26
|
+
import { registerHistoryContinuationRpc } from "./history-rpc.js";
|
|
27
|
+
import { requireHistoryAdmission } from "./history-support.js";
|
|
28
|
+
import { installTemporaryPermissions } from "./permission-temporary-install.js";
|
|
31
29
|
export const name = "dsmm";
|
|
32
30
|
export const inject = ["profileContext", "agents"];
|
|
33
|
-
|
|
34
|
-
// consumes the same object's Standard Schema protocol for sparse volatile refs.
|
|
35
|
-
export const Config = new Proxy(DSMM_NATIVE_CONFIG_SCHEMA, {
|
|
36
|
-
apply(_target, _receiver, args) { return DSMM_CONFIG_SCHEMA(args[0] ?? {}); }
|
|
37
|
-
});
|
|
31
|
+
export const Config = new Proxy(DSMM_NATIVE_CONFIG_SCHEMA, { apply(_target, _receiver, args) { return DSMM_CONFIG_SCHEMA(args[0] ?? {}); } });
|
|
38
32
|
export { DSMM_ROLE_IDS, DSMM_ROLES, isDsmmRoleId, renderAgentCordis, renderPresetMetadata } from "./roles.js";
|
|
39
33
|
export { DSMM_MANAGED_PRESET_MARKER, materializeRolePresets, reconcileRolePresets, resolveManagedPresetRoot } from "./preset-materializer.js";
|
|
40
34
|
export { DSMM_GUARD_PREFIX, decidePostToolExecution, decidePreToolExecution, isSafetyScopeActive, registerSafetyGuards, truncateTextMiddle } from "./guards.js";
|
|
41
35
|
export { DEFAULT_DSMM_LSP_SETTINGS, DSMM_LSP_SERVER_NAME, DSMM_LSP_TOOL_NAMES, parseLspSmokeCommand, publicLspToolName, renderLspMcpPatch, resolveLspSettings, toDshMcpClientConfig } from "./lsp.js";
|
|
42
36
|
export { classifyModelFamily } from "./model-family.js";
|
|
43
|
-
export {
|
|
44
|
-
export { classifyRecoveryFailure, foldAttemptedRecoveryRoutes, foldDurableRecoveryWork, selectFallbackRoute } from "./recovery-policy.js";
|
|
45
|
-
export { registerRuntimeRecovery } from "./runtime-recovery.js";
|
|
37
|
+
export { registerModelRouting } from "./model-routing.js";
|
|
46
38
|
export { childOwnedSessionEvents, resolveEffectiveDsmmRole, resolveSelectedAgentPreset } from "./session-scope.js";
|
|
47
39
|
export { roleFromProviderName, roleProviderName, registerRoleProviders } from "./role-providers.js";
|
|
48
40
|
export { effectiveRoleFallbackRoutes } from "./role-routing.js";
|
|
49
41
|
export { DSMM_STATUS_COMMAND, registerDsmmStatusCommand } from "./commands.js";
|
|
50
42
|
export { DSMM_STATUS_VERSION, createDsmmStatusSnapshot, formatDsmmStatus } from "./status.js";
|
|
51
|
-
export { DSMM_SKILL_NAMES, DEFAULT_DSMM_SETTINGS, MVP_SKILL_NAMES, isRoleEnabled, resolveConfig, resolveRoleRouting, registerSettings } from "./settings.js";
|
|
43
|
+
export { DSMM_SKILL_NAMES, DSMM_SETTINGS_SCHEMA, DEFAULT_DSMM_SETTINGS, MVP_SKILL_NAMES, deploymentEditorSchema, isRoleEnabled, resolveConfig, resolveDeployment, resolveRoleRouting, registerSettings, validateNativeConfig } from "./settings.js";
|
|
52
44
|
export { createProfileRuntime, DsmmProfileRuntime } from "./profile-runtime.js";
|
|
53
45
|
export { resolveDshHome } from "./dsh-home.js";
|
|
54
46
|
export { DsmmDeploymentConfig, parseGlobalConfig, editGlobalConfig } from "./deployment-config.js";
|
|
55
47
|
export { DSMM_MODULE_DESCRIPTORS, deepworkEnabled, projectDeepworkModule } from "./modules.js";
|
|
56
48
|
export { DEEPWORK_MODE_EVENT, DeepworkModeController, hasOpenTurn, isDeepworkActive } from "./state.js";
|
|
57
49
|
export { DsmmNativeLlmRuntime } from "./llm-runtime.js";
|
|
58
|
-
|
|
50
|
+
export { registerRuntimeRecovery } from "./runtime-recovery.js";
|
|
51
|
+
export { classifyRecoveryFailure, foldAttemptedRecoveryRoutes, foldDurableRecoveryWork, selectFallbackRoute } from "./recovery-policy.js";
|
|
52
|
+
export { DSMM_HISTORY_HOST_CONFIG } from "./history-support.js";
|
|
53
|
+
export { HISTORY_REMOTE } from "./history-remote.js";
|
|
59
54
|
export function createDsmmHostPlugin(startup) {
|
|
60
55
|
assertSupportedHostStartup(startup);
|
|
61
|
-
return { name, Config, inject,
|
|
62
|
-
apply(ctx, config = {}) { return apply(ctx, config, startup); } };
|
|
56
|
+
return { name, Config, inject, apply(ctx, config = {}) { return apply(ctx, config, startup); } };
|
|
63
57
|
}
|
|
64
|
-
export function apply(
|
|
65
|
-
assertSupportedHostStartup(
|
|
66
|
-
if (!Context.is(
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
export async function apply(input, config = {}, startupOptions = {}) {
|
|
59
|
+
assertSupportedHostStartup(startupOptions);
|
|
60
|
+
if (!Context.is(input))
|
|
61
|
+
throw new Error("DSMM requires the native Cordis Host");
|
|
62
|
+
const ctx = input;
|
|
63
|
+
requireHistoryAdmission(ctx);
|
|
69
64
|
const deployment = new DsmmDeploymentConfig(ctx, config);
|
|
70
|
-
return deployment.readDesired().then((startup) => applyConfigured(ctx, config, deployment, startup, hostStartup));
|
|
71
|
-
}
|
|
72
|
-
function applyConfigured(ctx, config, deployment, startup, hostStartup = {}) {
|
|
73
|
-
// Volatile desired saves retain live realms. An ordinary Loader remount must
|
|
74
|
-
// not replace already-admitted Agent policy/skill realms, including busy Agents.
|
|
75
|
-
if (Context.is(ctx) && ctx.fiber.entry !== undefined) {
|
|
76
|
-
const native = ctx;
|
|
77
|
-
const owner = ctx.fiber.entry;
|
|
78
|
-
native.on("loader/patch-context", (entry, next) => {
|
|
79
|
-
if (entry === owner && (native.get("agents")?.list().length ?? 0) > 0) {
|
|
80
|
-
throw new Error("dsmm deployment Config requires restart while Agents are admitted; runtime mode/profile changes use idle maintenance instead");
|
|
81
|
-
}
|
|
82
|
-
next();
|
|
83
|
-
}, { global: true });
|
|
84
|
-
}
|
|
85
|
-
const storage = config.sessionPersistence;
|
|
86
|
-
if (storage !== undefined) {
|
|
87
|
-
if (storage === null || typeof storage !== "object" || typeof storage.root !== "string" || !isAbsolute(storage.root)
|
|
88
|
-
|| Object.keys(storage).some((key) => !["root", "compression"].includes(key))
|
|
89
|
-
|| storage.compression !== undefined && !["zstd", "none"].includes(storage.compression)) {
|
|
90
|
-
throw new Error("Deepwork sessionPersistence must preserve an explicit absolute native root and compression");
|
|
91
|
-
}
|
|
92
|
-
if (!Context.is(ctx))
|
|
93
|
-
throw new Error("Deepwork sessionPersistence requires a native Cordis Context");
|
|
94
|
-
const native = ctx;
|
|
95
|
-
if (native.get("sessionPersistence") !== undefined)
|
|
96
|
-
throw new Error("Disable the exact existing JSONL entry at startup before enabling Deepwork sessionPersistence; live replacement is refused");
|
|
97
|
-
const fiber = native.plugin(DsmmSessionPersistence, storage);
|
|
98
|
-
return fiber.await().then(() => applyRuntime(ctx, config, deployment, startup, hostStartup));
|
|
99
|
-
}
|
|
100
|
-
return applyRuntime(ctx, config, deployment, startup, hostStartup);
|
|
101
|
-
}
|
|
102
|
-
function applyRuntime(ctx, config, deployment, startup, hostStartup = {}) {
|
|
103
|
-
const native = Context.is(ctx) ? ctx : undefined;
|
|
104
65
|
const lifetime = new AbortController();
|
|
105
|
-
|
|
106
|
-
|
|
66
|
+
scopeLifetime(ctx, "dsmm: retire Core", () => lifetime.abort());
|
|
67
|
+
// Install a startup execution fence before asynchronous configuration reads.
|
|
68
|
+
let admission;
|
|
69
|
+
const assert = (agent) => { lifetime.signal.throwIfAborted(); if (!admission)
|
|
70
|
+
throw new Error("DSMM initialization is incomplete"); return admission.assert(agent); };
|
|
71
|
+
ctx.on("agent/created", () => { lifetime.signal.throwIfAborted(); if (!admission?.isReady)
|
|
72
|
+
throw new Error("DSMM initialization is incomplete"); }, { global: true, prepend: true });
|
|
73
|
+
ctx.on("agent/pre-step", async (frame, next) => { await admission?.ensure(frame.agent); assert(frame.agent); return next(); }, { global: true, prepend: true });
|
|
74
|
+
ctx.on("agent/request", async (frame, next) => { await admission?.ensure(frame.agent); assert(frame.agent); return next(); }, { global: true, prepend: true });
|
|
75
|
+
ctx.on("tools/pre-execute", async (exec, next) => { if (exec.agent) {
|
|
76
|
+
await admission?.ensure(exec.agent);
|
|
77
|
+
assert(exec.agent);
|
|
78
|
+
} return next(); }, { global: true, prepend: true });
|
|
79
|
+
const startup = await deployment.readDesired();
|
|
80
|
+
lifetime.signal.throwIfAborted();
|
|
81
|
+
const getSettings = agent => agent === undefined ? startup.settings : admission.configuration(agent).settings;
|
|
82
|
+
getSettings.admission = agent => agent === undefined ? profiles.admission() : admission.configuration(agent);
|
|
83
|
+
getSettings.subagentRuntime = () => runtimeAdmissionView(ctx);
|
|
84
|
+
const controller = new DeepworkModeController(ctx, agent => getSettings(agent).modules.deepwork.enabled, () => admission?.isReady === true && ctx.get("subagents") !== undefined && ctx.get("agentPresets") !== undefined);
|
|
85
|
+
const policy = new DsmmRolePolicy(ctx, getSettings, controller);
|
|
107
86
|
let permissionOwner;
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
return null;
|
|
111
|
-
const current = native.get("dsmmPermissionController");
|
|
112
|
-
if (current === undefined || (Reflect.get(current, symbols.original) ?? current) !== permissionOwner)
|
|
87
|
+
const mountedPermission = () => {
|
|
88
|
+
if (lifetime.signal.aborted)
|
|
113
89
|
return null;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let rootAdmissionsInitialized = false;
|
|
117
|
-
const completedRootAdmissions = new WeakSet();
|
|
118
|
-
let rolePolicy;
|
|
119
|
-
const controlledParent = (agent) => {
|
|
120
|
-
if (classifyDsmmAgent(agent) === "dsmm")
|
|
121
|
-
return true;
|
|
122
|
-
if (agent.session.header?.origin === "subagent")
|
|
123
|
-
return false;
|
|
124
|
-
// A pending parent admission cannot establish native-child eligibility.
|
|
125
|
-
if (!rootAdmissionsInitialized && !completedRootAdmissions.has(agent))
|
|
126
|
-
return true;
|
|
127
|
-
const settings = getBoundSettings(agent);
|
|
128
|
-
return settings.modules.deepwork.enabled && isDeepworkActive(sessionEvents(agent.session), settings.defaultActive, resolveSelectedAgentPreset(agent.session));
|
|
129
|
-
};
|
|
130
|
-
if (native !== undefined) {
|
|
131
|
-
ctx = managedAgentContext(native, controlledParent);
|
|
132
|
-
}
|
|
133
|
-
const validatingRootModule = new WeakMap();
|
|
134
|
-
const controller = new DeepworkModeController(ctx, (agent) => validatingRootModule.get(agent) ?? getBoundSettings(agent).modules.deepwork.enabled);
|
|
135
|
-
let runtime;
|
|
136
|
-
let profileInitialization;
|
|
137
|
-
let requiresNativeProfiles = ctx.get !== undefined;
|
|
138
|
-
const requireProfileAdmission = (agent) => {
|
|
139
|
-
if (agent !== undefined && requiresNativeProfiles && runtime === undefined) {
|
|
140
|
-
throw new DsmmProfileError("unavailable", "Native Deepwork profile admission is not ready. No provider request or tool work is allowed.");
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
const getBoundSettings = (agent) => {
|
|
144
|
-
requireProfileAdmission(agent);
|
|
145
|
-
return runtime?.getSettings(agent) ?? getSettings();
|
|
146
|
-
};
|
|
147
|
-
const deploymentAdmissions = new WeakMap();
|
|
148
|
-
getBoundSettings.admission = (agent) => {
|
|
149
|
-
requireProfileAdmission(agent);
|
|
150
|
-
const nativeAdmission = runtime?.getSettings.admission?.(agent);
|
|
151
|
-
if (nativeAdmission !== undefined)
|
|
152
|
-
return nativeAdmission;
|
|
153
|
-
const settings = getSettings();
|
|
154
|
-
let admission = deploymentAdmissions.get(settings);
|
|
155
|
-
if (admission === undefined) {
|
|
156
|
-
admission = Object.freeze({ settings, profile: null, scope: "deployment-baseline", epoch: createHash("sha256").update(randomUUID()).digest("hex") });
|
|
157
|
-
deploymentAdmissions.set(settings, admission);
|
|
158
|
-
}
|
|
159
|
-
return admission;
|
|
160
|
-
};
|
|
161
|
-
getBoundSettings.moduleStates = (agent) => {
|
|
162
|
-
requireProfileAdmission(agent);
|
|
163
|
-
return runtime?.getSettings.moduleStates?.(agent) ?? projectDsmmModules(getSettings(), startup, getBoundSettings.admission(agent), false, getMountedPermission);
|
|
164
|
-
};
|
|
165
|
-
getBoundSettings.subagentRuntime = () => native === undefined
|
|
166
|
-
? { binding: "unavailable", deliveryFenceReady: false, restartRequired: true, reason: "explicit-composition-required" }
|
|
167
|
-
: runtimeAdmissionView(native);
|
|
168
|
-
rolePolicy = new DsmmRolePolicy(ctx, getBoundSettings, controller);
|
|
169
|
-
const assertDwDelivery = (agent) => {
|
|
170
|
-
if (rolePolicy.identity(agent).role === undefined)
|
|
171
|
-
return;
|
|
172
|
-
const integration = native?.get("dsmmRuntimeIntegration");
|
|
173
|
-
if (integration === undefined || !integration.runtime.authority.view().deliveryFenceReady)
|
|
174
|
-
throw new DsmmProfileError("unavailable", "Deepwork execution requires its live delivery fence.");
|
|
175
|
-
return integration.bridge.authority.acquireParentTicket(agent);
|
|
90
|
+
const current = ctx.get("dsmmPermissionController");
|
|
91
|
+
return current && (Reflect.get(current, symbols.original) ?? current) === permissionOwner ? current.rules.status().mounted : null;
|
|
176
92
|
};
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
registerDsmmStatusCommand(commandCtx, controller, statusSettings);
|
|
201
|
-
};
|
|
202
|
-
if (installCtx.get !== undefined && installCtx.inject !== undefined)
|
|
203
|
-
installCtx.inject(["commands"], installCommands);
|
|
204
|
-
else
|
|
205
|
-
installCommands(installCtx);
|
|
206
|
-
if (!startupMounted)
|
|
93
|
+
const profiles = await createProfileRuntime(ctx, startup.settings, { startup, readDesired: () => deployment.readDesired(), modeController: controller,
|
|
94
|
+
runtimeView: () => runtimeAdmissionView(ctx), getMountedPermission: mountedPermission });
|
|
95
|
+
lifetime.signal.throwIfAborted();
|
|
96
|
+
admission = new NativeAdmission(ctx, profiles, policy);
|
|
97
|
+
ctx.provide("dsmmNativeAdmission", admission);
|
|
98
|
+
ctx.provide("dsmmProfileRuntime", profiles);
|
|
99
|
+
ctx.provide("dsmmDeploymentConfig", deployment);
|
|
100
|
+
ctx.provide("dsmmCoreLlmOwner", { async admit(frame) {
|
|
101
|
+
const captured = assert(frame.agent), full = nativeStandingFullAccess(ctx, frame.agent);
|
|
102
|
+
const permissions = ctx.get("dsmmPermissionController");
|
|
103
|
+
if (!full && captured.settings.permissionControl.enabled && permissions === undefined)
|
|
104
|
+
throw new DsmmProfileError("unavailable", "Core permission authority is not ready.");
|
|
105
|
+
if (!full)
|
|
106
|
+
await permissions?.rules.refresh();
|
|
107
|
+
const permissionIdentity = permissions === undefined ? undefined : Reflect.get(permissions, symbols.original) ?? permissions;
|
|
108
|
+
const permissionRevision = full ? undefined : permissions?.rules.getPolicy().revision;
|
|
109
|
+
const permissionSignal = full ? undefined : permissions?.rules.signal;
|
|
110
|
+
const signal = AbortSignal.any([frame.signal, lifetime.signal, ...permissionSignal === undefined ? [] : [permissionSignal]]);
|
|
111
|
+
const assertCurrent = () => {
|
|
112
|
+
signal.throwIfAborted();
|
|
113
|
+
if (assert(frame.agent) !== captured)
|
|
114
|
+
throw new DsmmProfileError("not-owned", "Native admission changed.");
|
|
115
|
+
if (full)
|
|
207
116
|
return;
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (root !== undefined)
|
|
213
|
-
reconcileRolePresets({ root, settings });
|
|
214
|
-
};
|
|
215
|
-
if (readyCtx.get === undefined) {
|
|
216
|
-
registerRolePresets(readyCtx, getReadySettings);
|
|
217
|
-
install(readyCtx, getReadySettings);
|
|
218
|
-
if (startupMounted)
|
|
219
|
-
registerRoleProviders(readyCtx, getReadySettings, getReadySettings, rolePolicy);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
requiresNativeProfiles = true;
|
|
223
|
-
const installProfiles = async (profileCtx) => {
|
|
224
|
-
if (native === undefined)
|
|
225
|
-
throw new Error("dsmm native profiles require the actual Cordis Host scope");
|
|
226
|
-
const hostCtx = profileCtx;
|
|
227
|
-
profileCtx = managedAgentContext(hostCtx, controlledParent);
|
|
228
|
-
if (startupMounted) {
|
|
229
|
-
await registerLspRuntime(profileCtx, { ...getReadySettings().lsp, enabled: false }, getBoundSettings);
|
|
230
|
-
}
|
|
231
|
-
// Standing definitions must exist before initialize audits retained
|
|
232
|
-
// Agents. A missing optional registry still installs later from this
|
|
233
|
-
// same frozen startup getter, without blocking unrelated Hosts.
|
|
234
|
-
const presets = registerRolePresets(profileCtx, getReadySettings);
|
|
235
|
-
if (profileCtx.get?.("agentPresets") !== undefined)
|
|
236
|
-
await presets;
|
|
237
|
-
const integration = await integrateSubagentRuntime(hostCtx, getReadySettings(), rolePolicy, () => runtime, hostStartup);
|
|
238
|
-
lifetime.signal.throwIfAborted();
|
|
239
|
-
if (startupMounted && hostCtx.get("subagents") !== undefined) {
|
|
240
|
-
// The actual registry exists now. Alias registration is synchronous and
|
|
241
|
-
// does not wait on a policy-ready provider, avoiding a startup cycle.
|
|
242
|
-
registerRoleProviders({ get: hostCtx.get.bind(hostCtx), effect: callback => hostCtx.effect(() => callback() ?? (() => { })) }, getBoundSettings, getReadySettings, rolePolicy);
|
|
243
|
-
}
|
|
244
|
-
const retainedChildren = profileCtx.get("agents").list().filter(agent => agent.session.header?.origin === "subagent");
|
|
245
|
-
const manager = await createProfileRuntime(profileCtx, getReadySettings(), { modeController: controller,
|
|
246
|
-
getMountedPermission, deferRetainedChildren: integration !== undefined,
|
|
247
|
-
...(startup === undefined ? {} : { startup }), ...(deployment === undefined ? {} : { readDesired: () => deployment.readDesired() }),
|
|
248
|
-
...(integration === undefined ? {} : { childAuthority: integration.bridge.authority, childAuthorityOwner: integration.owner,
|
|
249
|
-
childAdmission: integration.bridge.childAdmission, childCapturePersistence: "durable" }),
|
|
250
|
-
validateRootRole: (agent, admission) => {
|
|
251
|
-
// Candidate identity validation precedes publication. Its mode check
|
|
252
|
-
// must not recursively demand the not-yet-bound live admission.
|
|
253
|
-
validatingRootModule.set(agent, admission.settings.modules.deepwork.enabled);
|
|
254
|
-
try {
|
|
255
|
-
rolePolicy.validateRootRole(agent, admission);
|
|
256
|
-
}
|
|
257
|
-
finally {
|
|
258
|
-
validatingRootModule.delete(agent);
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
onAdmissionGuardsInstalled: async (initializing) => {
|
|
262
|
-
runtime = initializing;
|
|
263
|
-
integration?.onAdmissionGuardsInstalled();
|
|
264
|
-
// Native descendants are filtered from their direct parent's actual
|
|
265
|
-
// admission, including a preselected named profile, not startup mode.
|
|
266
|
-
for (const root of hostCtx.agents.roots()) {
|
|
267
|
-
const agent = root;
|
|
268
|
-
await initializing.completeAdmission(agent, undefined, startup);
|
|
269
|
-
completedRootAdmissions.add(agent);
|
|
270
|
-
}
|
|
271
|
-
rootAdmissionsInitialized = true;
|
|
272
|
-
},
|
|
273
|
-
subagentCapabilities: {
|
|
274
|
-
backgroundJobs: profileCtx.get?.("jobs") !== undefined,
|
|
275
|
-
continuable: profileCtx.get?.("sessionPersistence") !== undefined && profileCtx.get?.("sessionQuery") !== undefined
|
|
276
|
-
&& profileCtx.get?.("subagents")?.getProvider("spawn")?.prepareContinuable !== undefined
|
|
277
|
-
} });
|
|
278
|
-
runtime = manager;
|
|
279
|
-
lifetime.signal.throwIfAborted();
|
|
280
|
-
// Retained controlled children enroll only after their awaited admission
|
|
281
|
-
// in the Core-dependent continuation; ordinary Core startup stays independent.
|
|
282
|
-
const admittedCtx = admittedAgentContext(profileCtx, manager);
|
|
283
|
-
install(admittedCtx, getBoundSettings);
|
|
284
|
-
registerRuntimeGuidance(admittedCtx, getBoundSettings, rolePolicy);
|
|
285
|
-
const published = publicProfileRuntime(manager, hostCtx);
|
|
286
|
-
profileCtx.provide?.("dsmmProfileRuntime", published);
|
|
287
|
-
if (integration !== undefined) {
|
|
288
|
-
hostCtx.provide("dsmmRuntimeIntegration", integration);
|
|
289
|
-
hostCtx.inject(["dsmmCoreLlmOwner"], async (continuationCtx) => {
|
|
290
|
-
const continuation = new AbortController();
|
|
291
|
-
scopeLifetime(continuationCtx, "dsmm: cancel DW startup continuation", () => continuation.abort());
|
|
292
|
-
return integration.continueStartup(async (signal) => {
|
|
293
|
-
const visited = new Set();
|
|
294
|
-
const admit = async (agent) => {
|
|
295
|
-
signal.throwIfAborted();
|
|
296
|
-
lifetime.signal.throwIfAborted();
|
|
297
|
-
if (visited.has(agent))
|
|
298
|
-
return;
|
|
299
|
-
visited.add(agent);
|
|
300
|
-
const parent = hostCtx.agents.list().find(parent => parent !== agent && hostCtx.agents.isOwnedBy(agent.id, parent));
|
|
301
|
-
if (parent !== undefined)
|
|
302
|
-
await admit(parent);
|
|
303
|
-
if (parent !== undefined && classifyDsmmAgent(agent) === "native" && !controlledParent(parent))
|
|
304
|
-
return;
|
|
305
|
-
await manager.completeAdmission(agent, signal, startup);
|
|
306
|
-
};
|
|
307
|
-
for (const agent of retainedChildren)
|
|
308
|
-
if (hostCtx.agents.get(agent.id) === agent)
|
|
309
|
-
await admit(agent);
|
|
310
|
-
signal.throwIfAborted();
|
|
311
|
-
lifetime.signal.throwIfAborted();
|
|
312
|
-
await registerNativeSubagentControls(profileCtx);
|
|
313
|
-
signal.throwIfAborted();
|
|
314
|
-
lifetime.signal.throwIfAborted();
|
|
315
|
-
await registerHeadlessRoleTools(admittedAgentContext(profileCtx, manager), controller, getBoundSettings, rolePolicy, integration);
|
|
316
|
-
signal.throwIfAborted();
|
|
317
|
-
lifetime.signal.throwIfAborted();
|
|
318
|
-
hostCtx.inject(["typert", "subagents"], scope => integration.registerControls(scope));
|
|
319
|
-
}, AbortSignal.any([lifetime.signal, continuation.signal]));
|
|
320
|
-
});
|
|
117
|
+
const current = ctx.get("dsmmPermissionController");
|
|
118
|
+
if ((current === undefined ? undefined : Reflect.get(current, symbols.original) ?? current) !== permissionIdentity
|
|
119
|
+
|| current?.rules.getPolicy().revision !== permissionRevision || current?.rules.signal !== permissionSignal) {
|
|
120
|
+
throw new DsmmProfileError("not-owned", "Core permission authority changed.");
|
|
321
121
|
}
|
|
322
|
-
else
|
|
323
|
-
registerRoleControlContribution(hostCtx);
|
|
324
|
-
profileCtx.inject?.(["typert"], (rpcCtx) => {
|
|
325
|
-
new DsmmProfilesHost(rpcCtx, published);
|
|
326
|
-
});
|
|
327
122
|
};
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
123
|
+
assertCurrent();
|
|
124
|
+
return Object.freeze({ agent: frame.agent, admission: captured, capture: captured, epoch: captured.epoch, signal, assertCurrent });
|
|
125
|
+
} });
|
|
126
|
+
const nativeAdmission = admission;
|
|
127
|
+
if (startup.settings.modules.deepwork.enabled) {
|
|
128
|
+
const presets = ctx.inject(["agentPresets"], async (scope) => {
|
|
129
|
+
await registerRolePresets(scope, () => startup.settings);
|
|
130
|
+
const providers = scope.inject(["subagents"], async (runtimeScope) => {
|
|
131
|
+
registerRoleProviders(runtimeScope, () => startup.settings, nativeAdmission);
|
|
132
|
+
await registerNativeSubagentControls(runtimeScope);
|
|
133
|
+
});
|
|
134
|
+
if (scope.get("subagents") !== undefined)
|
|
135
|
+
await providers.await();
|
|
136
|
+
});
|
|
137
|
+
if (ctx.get("agentPresets") !== undefined)
|
|
138
|
+
await presets.await();
|
|
139
|
+
}
|
|
140
|
+
if (startup.settings.modules.deepwork.enabled)
|
|
141
|
+
await registerLspRuntime(ctx, startup.settings.lsp, getSettings);
|
|
142
|
+
lifetime.signal.throwIfAborted();
|
|
143
|
+
const installed = new WeakSet();
|
|
144
|
+
admission.activate(async (agent, candidate, phase) => {
|
|
145
|
+
candidate.subagentRuntime = () => runtimeAdmissionView(ctx);
|
|
146
|
+
const scope = agent.ctx;
|
|
147
|
+
if (startup.settings.modules.deepwork.enabled) {
|
|
148
|
+
registerAgentSkills(scope, controller, candidate, agent, admission.lifetime.signal, () => !nativeAdmission.isSelecting(agent));
|
|
149
|
+
registerDeepworkPrompt(scope, controller, candidate, { section: startup.profile.section ?? startup.global.section }, agent, admission.lifetime.signal);
|
|
344
150
|
}
|
|
151
|
+
if (installed.has(agent)) {
|
|
152
|
+
if (phase !== "history-setup" && startup.settings.modules.deepwork.enabled && ctx.get("subagents") !== undefined)
|
|
153
|
+
await registerHeadlessRoleTools(scope, controller, candidate, policy, nativeAdmission, agent);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
registerModelRouting(scope, controller, candidate);
|
|
157
|
+
registerSafetyGuards(scope, controller, candidate, policy);
|
|
158
|
+
if (startup.settings.modules.deepwork.enabled) {
|
|
159
|
+
if (phase !== "history-setup" && ctx.get("subagents") !== undefined)
|
|
160
|
+
await registerHeadlessRoleTools(scope, controller, candidate, policy, nativeAdmission, agent);
|
|
161
|
+
}
|
|
162
|
+
installed.add(agent);
|
|
345
163
|
});
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
rolePolicy.assertModuleAdmission(agent);
|
|
356
|
-
assertDwDelivery(agent);
|
|
357
|
-
}
|
|
358
|
-
return next();
|
|
359
|
-
}, { prepend: true, global: true });
|
|
360
|
-
ctx.on?.("agent/request", async (frame, next) => {
|
|
361
|
-
await native?.get("dsmmRuntimeIntegration")?.runtime.authority.waitForPromotion(frame.agent, frame.signal);
|
|
362
|
-
rolePolicy.assertModuleAdmission(frame.agent);
|
|
363
|
-
assertDwDelivery(frame.agent);
|
|
364
|
-
return next();
|
|
365
|
-
}, { prepend: true, global: true });
|
|
366
|
-
ctx.on?.("tools/execute", async (exec, next) => {
|
|
367
|
-
if (exec.agent === undefined)
|
|
368
|
-
return next();
|
|
369
|
-
return rolePolicy.duringToolExecution(exec, next);
|
|
370
|
-
}, { global: true });
|
|
371
|
-
}
|
|
372
|
-
registerSafetyGuards(ctx, controller, getBoundSettings, ctx.get === undefined ? undefined : rolePolicy);
|
|
373
|
-
if (native === undefined)
|
|
374
|
-
return profileInitialization;
|
|
375
|
-
native.inject(["tools"], scope => {
|
|
376
|
-
managedAgentContext(scope, controlledParent).on("tools/pre-execute", (exec, next) => rolePolicy.beforeToolDecision(async () => {
|
|
377
|
-
if (exec.agent !== undefined && !nativeStandingFullAccess(scope, exec.agent)) {
|
|
378
|
-
rolePolicy.assertModuleAdmission(exec.agent);
|
|
379
|
-
assertDwDelivery(exec.agent);
|
|
380
|
-
}
|
|
381
|
-
return next();
|
|
382
|
-
}), { prepend: true, global: true });
|
|
383
|
-
managedAgentContext(scope, controlledParent).get("tools").guard(exec => {
|
|
384
|
-
rolePolicy.assertToolExecution(exec);
|
|
385
|
-
});
|
|
164
|
+
ctx.inject(["commands"], scope => {
|
|
165
|
+
registerDsmmStatusCommand(scope, controller, getSettings);
|
|
166
|
+
if (startup.settings.modules.deepwork.enabled)
|
|
167
|
+
registerDeepworkCommand(scope, controller, getSettings);
|
|
168
|
+
});
|
|
169
|
+
ctx.inject(["typert"], scope => { registerConfigRpc(scope, deployment, startup.settings, () => profiles, startup.sources, mountedPermission); new DsmmProfilesHost(scope, profiles); registerRoleControlRpc(scope, nativeAdmission); });
|
|
170
|
+
const permissions = createCorePermissionAuthority(ctx, { getSettings, rolePolicy: policy, signal: lifetime.signal });
|
|
171
|
+
const history = ctx.inject(["typert", "agentLoop", "sessionController", "sessionPersistence", "agentPresets"], function mountHistoryContinuation(scope) {
|
|
172
|
+
registerHistoryContinuationRpc(scope, new DsmmHistoryCandidates(scope, profiles, deployment, nativeAdmission), nativeAdmission);
|
|
386
173
|
});
|
|
387
|
-
if (
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
174
|
+
if (["typert", "agentLoop", "sessionController", "sessionPersistence", "agentPresets"].every(key => ctx.get(key)))
|
|
175
|
+
await history.await();
|
|
176
|
+
const installPermissions = () => ctx.inject(["tools", ...(ctx.fiber.entry === undefined ? [] : ["settings"])], scope => {
|
|
177
|
+
const installed = installCorePermissions(scope, deployment, permissions.authority, permissions.assertWritable);
|
|
178
|
+
scope.inject(["approval", "typertGateway", "typert", "subagents"], temporaryScope => {
|
|
179
|
+
if (typeof temporaryScope.approval.settlement !== "function" || typeof temporaryScope.typertGateway.registerApprovalPermits !== "function")
|
|
180
|
+
return;
|
|
181
|
+
const temporary = installTemporaryPermissions(temporaryScope, { core: permissions, roles: policy, rules: installed.rules });
|
|
182
|
+
temporaryScope.effect(() => () => temporary.dispose(), "dsmm: temporary permissions");
|
|
394
183
|
});
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
const owner = { async admit(frame) {
|
|
399
|
-
const agent = frame.agent;
|
|
400
|
-
frame.signal.throwIfAborted();
|
|
401
|
-
lifetime.signal.throwIfAborted();
|
|
402
|
-
if (frame.agent.session.header.origin === "subagent" && classifyDsmmAgent(frame.agent) === "native") {
|
|
403
|
-
const registry = native.agents;
|
|
404
|
-
const parents = registry.list().filter(parent => parent !== frame.agent && registry.isOwnedBy(frame.agent.id, parent));
|
|
405
|
-
if (registry.get(frame.agent.id) !== frame.agent || parents.length !== 1
|
|
406
|
-
|| frame.agent.session.header.parentSession !== parents[0].id)
|
|
407
|
-
throw new DsmmProfileError("not-owned", "The native child lost its physical owner.");
|
|
408
|
-
if (!controlledParent(parents[0]))
|
|
409
|
-
return undefined;
|
|
410
|
-
}
|
|
411
|
-
rolePolicy.assertModuleAdmission(agent);
|
|
412
|
-
const admission = getBoundSettings.admission(agent);
|
|
413
|
-
const permissions = native.get("dsmmPermissionController");
|
|
414
|
-
const full = nativeStandingFullAccess(native, frame.agent);
|
|
415
|
-
if (!full && admission.settings.permissionControl.enabled && permissions === undefined)
|
|
416
|
-
throw new DsmmProfileError("unavailable", "Core permission authority is not ready.");
|
|
417
|
-
if (!full)
|
|
418
|
-
await permissions?.rules.refresh();
|
|
419
|
-
frame.signal.throwIfAborted();
|
|
420
|
-
lifetime.signal.throwIfAborted();
|
|
421
|
-
const permissionIdentity = permissions === undefined ? undefined : Reflect.get(permissions, symbols.original) ?? permissions;
|
|
422
|
-
const permissionRevision = full ? undefined : permissions?.rules.getPolicy().revision;
|
|
423
|
-
const permissionSignal = full ? undefined : permissions?.rules.signal;
|
|
424
|
-
const bindPermission = (captured) => {
|
|
425
|
-
if (full)
|
|
426
|
-
return captured;
|
|
427
|
-
const signal = AbortSignal.any([captured.signal, ...permissionSignal === undefined ? [] : [permissionSignal]]);
|
|
428
|
-
const assertCurrent = () => {
|
|
429
|
-
signal.throwIfAborted();
|
|
430
|
-
captured.assertCurrent();
|
|
431
|
-
const current = native.get("dsmmPermissionController");
|
|
432
|
-
if ((current === undefined ? undefined : Reflect.get(current, symbols.original) ?? current) !== permissionIdentity
|
|
433
|
-
|| current?.rules.getPolicy().revision !== permissionRevision
|
|
434
|
-
|| current?.rules.signal !== permissionSignal)
|
|
435
|
-
throw new DsmmProfileError("not-owned", "LLM permission revision changed.");
|
|
436
|
-
};
|
|
437
|
-
assertCurrent();
|
|
438
|
-
return Object.freeze({ ...captured, signal, assertCurrent });
|
|
439
|
-
};
|
|
440
|
-
if (rolePolicy.identity(agent).role !== undefined) {
|
|
441
|
-
const integration = native.get("dsmmRuntimeIntegration");
|
|
442
|
-
if (integration?.runtime.authority.view().deliveryFenceReady !== true)
|
|
443
|
-
throw new DsmmProfileError("unavailable", "Deepwork requests require the live delivery fence.");
|
|
444
|
-
const admitted = await integration.admitLlmRequest(frame.agent, frame.signal);
|
|
445
|
-
if (admitted === undefined)
|
|
446
|
-
throw new DsmmProfileError("not-owned", "Deepwork request lost its role admission.");
|
|
447
|
-
return bindPermission(admitted);
|
|
448
|
-
}
|
|
449
|
-
const signal = AbortSignal.any([frame.signal, lifetime.signal]);
|
|
450
|
-
const assertCurrent = () => {
|
|
451
|
-
signal.throwIfAborted();
|
|
452
|
-
rolePolicy.assertModuleAdmission(agent);
|
|
453
|
-
if (native.get("dsmmCoreLlmOwner") !== owner || getBoundSettings.admission(agent) !== admission)
|
|
454
|
-
throw new DsmmProfileError("not-owned", "Core LLM admission changed.");
|
|
455
|
-
};
|
|
456
|
-
assertCurrent();
|
|
457
|
-
return bindPermission(Object.freeze({ agent: frame.agent, admission, capture: admission, epoch: admission.epoch, signal, assertCurrent }));
|
|
458
|
-
} };
|
|
459
|
-
native.provide("dsmmCoreLlmOwner", owner);
|
|
184
|
+
const identity = Reflect.get(installed, symbols.original) ?? installed;
|
|
185
|
+
scopeLifetime(scope, "dsmm: release permission projection", () => { if (permissionOwner === identity)
|
|
186
|
+
permissionOwner = undefined; }, () => { permissionOwner = identity; });
|
|
460
187
|
});
|
|
188
|
+
if (ctx.fiber.entry === undefined || ctx.fiber.state === 2)
|
|
189
|
+
installPermissions();
|
|
190
|
+
else {
|
|
191
|
+
const owner = ctx.fiber.ctx;
|
|
192
|
+
const detach = ctx.on("internal/status", fiber => { if (fiber.ctx !== owner || fiber.state !== 2)
|
|
193
|
+
return; detach(); if (!lifetime.signal.aborted)
|
|
194
|
+
installPermissions(); }, { global: true });
|
|
195
|
+
}
|
|
461
196
|
}
|
|
462
|
-
|
|
463
|
-
// the exported schema and may pass null where required DSMM defaults belong.
|
|
464
|
-
// Method-form apply keeps Cordis on its awaited callback, not constructor, path.
|
|
465
|
-
export default { name, inject, Config, apply(ctx, config = {}) { return apply(ctx, config); } };
|
|
197
|
+
export default { name, inject, Config, apply };
|
|
466
198
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
/** Revoke synchronously when an owning scope begins unloading, before async cleanup. */
|
|
3
|
+
export declare function scopeLifetime(scope: Context, label: string, revoke: () => void, install?: () => void): () => void;
|
|
4
|
+
//# sourceMappingURL=lifetime.d.ts.map
|