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