@dsmm/dsmm 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -67
- package/agent-presets/dsmm-builder/agent.cordis.yml +10 -2015
- package/agent-presets/dsmm-clarifier/agent.cordis.yml +24 -343
- package/agent-presets/dsmm-code-search/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-coding/agent.cordis.yml +19 -438
- package/agent-presets/dsmm-complex/agent.cordis.yml +23 -1009
- package/agent-presets/dsmm-creative/agent.cordis.yml +25 -442
- package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +29 -1013
- package/agent-presets/dsmm-deep/agent.cordis.yml +24 -1008
- package/agent-presets/dsmm-doc-search/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-documenting/agent.cordis.yml +26 -439
- package/agent-presets/dsmm-frontend/agent.cordis.yml +21 -440
- package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +22 -441
- package/agent-presets/dsmm-media-reader/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-normal-task/agent.cordis.yml +19 -438
- package/agent-presets/dsmm-oracle/agent.cordis.yml +25 -340
- package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +25 -340
- package/agent-presets/dsmm-orchestrator/agent.cordis.yml +29 -2025
- package/agent-presets/dsmm-plan-critic/agent.cordis.yml +24 -341
- package/agent-presets/dsmm-planner/agent.cordis.yml +14 -344
- package/agent-presets/dsmm-quick/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-research/agent.cordis.yml +23 -8
- package/agent-presets/dsmm-reviewer/agent.cordis.yml +25 -340
- package/cordis.patch.yml +14 -0
- package/docs/agent-presets.md +36 -52
- package/docs/compatibility.md +47 -110
- package/docs/deferred-native-approval-risk.md +19 -0
- package/docs/design.md +2 -2
- package/docs/lsp.md +11 -21
- package/docs/migration-from-ocmm.md +2 -2
- package/docs/model-routing.md +84 -59
- package/docs/native-permissions.md +35 -0
- package/docs/profiles.md +40 -87
- package/docs/releasing.md +123 -2
- package/docs/roadmap.md +71 -17
- package/docs/settings-status.md +34 -169
- package/docs/skill-sync.md +52 -15
- package/lib/agent-registry.d.ts +36 -0
- package/lib/agent-registry.js +75 -0
- package/lib/child-admission-contract.d.ts +37 -0
- package/lib/child-admission-contract.js +2 -0
- package/lib/child-admission.d.ts +40 -0
- package/lib/child-admission.js +151 -0
- package/lib/child-capture.d.ts +85 -0
- package/lib/child-capture.js +205 -0
- package/lib/child-evidence.d.ts +17 -0
- package/lib/child-evidence.js +43 -0
- package/lib/client/ChildrenPanel.d.ts +43 -0
- package/lib/client/ChildrenPanel.js +82 -0
- package/lib/client/DeploymentPage.js +15 -8
- package/lib/client/EditableChoice.d.ts +17 -0
- package/lib/client/EditableChoice.js +49 -0
- package/lib/client/PermissionsPanel.d.ts +14 -0
- package/lib/client/PermissionsPanel.js +46 -0
- package/lib/client/ProfilesSection.js +30 -15
- package/lib/client/RoleAvailability.d.ts +7 -0
- package/lib/client/RoleAvailability.js +19 -0
- package/lib/client/SessionProfiles.js +27 -9
- package/lib/client/StructuredEditor.js +15 -7
- package/lib/client/children-controller.d.ts +98 -0
- package/lib/client/children-controller.js +296 -0
- package/lib/client/children-locales.d.ts +367 -0
- package/lib/client/children-locales.js +69 -0
- package/lib/client/controller.d.ts +6 -1
- package/lib/client/controller.js +14 -8
- package/lib/client/deployment-controller.js +1 -1
- package/lib/client/deployment-data.d.ts +2 -1
- package/lib/client/deployment-data.js +34 -5
- package/lib/client/deployment-locales.d.ts +4 -0
- package/lib/client/deployment-locales.js +11 -2
- package/lib/client/diagnostics.d.ts +14 -0
- package/lib/client/diagnostics.js +53 -0
- package/lib/client/index.d.ts +4 -0
- package/lib/client/index.js +96 -2
- package/lib/client/locales.d.ts +54 -0
- package/lib/client/locales.js +34 -16
- package/lib/client/permission-client.d.ts +16 -0
- package/lib/client/permission-client.js +38 -0
- package/lib/client/permission-controller.d.ts +62 -0
- package/lib/client/permission-controller.js +149 -0
- package/lib/client/permission-locales.d.ts +114 -0
- package/lib/client/permission-locales.js +75 -0
- package/lib/client/session-labels.js +4 -4
- package/lib/client/structured.js +19 -5
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +20 -0
- package/lib/client.js +5780 -1679
- package/lib/core-permission-authority.d.ts +18 -0
- package/lib/core-permission-authority.js +255 -0
- package/lib/core-permissions.d.ts +8 -0
- package/lib/core-permissions.js +33 -0
- package/lib/delivery-authority.d.ts +83 -0
- package/lib/delivery-authority.js +397 -0
- package/lib/deployment-config.d.ts +23 -0
- package/lib/deployment-config.js +61 -40
- package/lib/deployment-permission-rules.d.ts +55 -0
- package/lib/deployment-permission-rules.js +306 -0
- package/lib/dsh-types.d.ts +10 -4
- package/lib/guards.d.ts +1 -1
- package/lib/guards.js +29 -8
- package/lib/host-llm-startup.d.ts +41 -0
- package/lib/host-llm-startup.js +65 -0
- package/lib/host-llm.d.ts +92 -0
- package/lib/host-llm.js +325 -0
- package/lib/index.d.ts +15 -4
- package/lib/index.js +288 -48
- package/lib/live-pi-ai-owner.d.ts +18 -0
- package/lib/live-pi-ai-owner.js +144 -0
- package/lib/llm-runtime.d.ts +11 -0
- package/lib/llm-runtime.js +21 -0
- package/lib/managed-settings.d.ts +5 -0
- package/lib/managed-settings.js +14 -0
- package/lib/model-parameter-policy.d.ts +11 -0
- package/lib/model-parameter-policy.js +27 -0
- package/lib/model-routing.js +28 -17
- package/lib/modules.d.ts +13 -5
- package/lib/modules.js +17 -1
- package/lib/native-child-evidence.d.ts +40 -0
- package/lib/native-child-evidence.js +104 -0
- package/lib/native-pi-ai-wire.d.ts +37 -0
- package/lib/native-pi-ai-wire.js +261 -0
- package/lib/native-scope.js +1 -1
- package/lib/permission-bash.d.ts +6 -0
- package/lib/permission-bash.js +7 -0
- package/lib/permission-control.d.ts +73 -0
- package/lib/permission-control.js +205 -0
- package/lib/permission-controller.d.ts +68 -0
- package/lib/permission-controller.js +317 -0
- package/lib/permission-errors.d.ts +7 -0
- package/lib/permission-errors.js +21 -0
- package/lib/permission-fs-search.d.ts +5 -0
- package/lib/permission-fs-search.js +7 -0
- package/lib/permission-fs.d.ts +5 -0
- package/lib/permission-fs.js +7 -0
- package/lib/permission-native-access.d.ts +11 -0
- package/lib/permission-native-access.js +6 -0
- package/lib/permission-native-command.d.ts +10 -0
- package/lib/permission-native-command.js +93 -0
- package/lib/permission-native-rules.d.ts +75 -0
- package/lib/permission-native-rules.js +278 -0
- package/lib/permission-pwsh.d.ts +6 -0
- package/lib/permission-pwsh.js +7 -0
- package/lib/permission-remote.d.ts +26 -0
- package/lib/permission-remote.js +53 -0
- package/lib/permission-rpc.d.ts +29 -0
- package/lib/permission-rpc.js +152 -0
- package/lib/permission-rules.d.ts +115 -0
- package/lib/permission-rules.js +256 -0
- package/lib/permission-settings.d.ts +45 -0
- package/lib/permission-settings.js +48 -0
- package/lib/permission-shell.d.ts +38 -0
- package/lib/permission-shell.js +150 -0
- package/lib/permission-web.d.ts +5 -0
- package/lib/permission-web.js +7 -0
- package/lib/preset-registry.js +36 -25
- package/lib/profile-diagnostics.d.ts +45 -0
- package/lib/profile-diagnostics.js +148 -0
- package/lib/profile-locale.d.ts +3 -0
- package/lib/profile-locale.js +2 -0
- package/lib/profile-remote.d.ts +8 -0
- package/lib/profile-remote.js +163 -39
- package/lib/profile-rpc.d.ts +4 -3
- package/lib/profile-rpc.js +20 -16
- package/lib/profile-runtime.d.ts +40 -1
- package/lib/profile-runtime.js +368 -93
- package/lib/profile-store.d.ts +11 -0
- package/lib/profile-store.js +143 -11
- package/lib/profile-types.d.ts +70 -1
- package/lib/profile-types.js +1 -0
- package/lib/profiles.d.ts +16 -2
- package/lib/profiles.js +156 -79
- package/lib/prompt-content.js +1 -1
- package/lib/prompts.d.ts +37 -2
- package/lib/prompts.js +111 -9
- package/lib/recovery-policy.js +20 -7
- package/lib/role-control-remote.d.ts +38 -0
- package/lib/role-control-remote.js +211 -0
- package/lib/role-control-rpc.d.ts +51 -0
- package/lib/role-control-rpc.js +381 -0
- package/lib/role-control-types.d.ts +92 -0
- package/lib/role-control-types.js +8 -0
- package/lib/role-invocation.d.ts +47 -0
- package/lib/role-invocation.js +135 -0
- package/lib/role-llm-runtime.d.ts +17 -0
- package/lib/role-llm-runtime.js +62 -0
- package/lib/role-llm.d.ts +31 -0
- package/lib/role-llm.js +66 -0
- package/lib/role-policy.d.ts +46 -8
- package/lib/role-policy.js +421 -61
- package/lib/role-providers.d.ts +2 -2
- package/lib/role-providers.js +27 -72
- package/lib/role-routing.d.ts +11 -2
- package/lib/role-routing.js +42 -25
- package/lib/role-runs.d.ts +138 -0
- package/lib/role-runs.js +335 -0
- package/lib/role-subagents.d.ts +58 -3
- package/lib/role-subagents.js +179 -56
- package/lib/roles.d.ts +5 -6
- package/lib/roles.js +10 -39
- package/lib/route-json.d.ts +19 -0
- package/lib/route-json.js +129 -0
- package/lib/routing-policy.d.ts +2 -0
- package/lib/routing-policy.js +12 -2
- package/lib/runtime-integration.d.ts +81 -0
- package/lib/runtime-integration.js +702 -0
- package/lib/runtime-recovery.js +18 -8
- package/lib/session-persistence.d.ts +2 -1
- package/lib/session-persistence.js +1 -1
- package/lib/session-scope.js +4 -1
- package/lib/settings.d.ts +47 -13
- package/lib/settings.js +217 -82
- package/lib/skills.js +2 -2
- package/lib/status.d.ts +10 -1
- package/lib/status.js +11 -8
- package/lib/subagent-runtime.d.ts +57 -0
- package/lib/subagent-runtime.js +257 -0
- package/package.json +149 -89
- package/patches/subagent-runtime.yml +15 -0
- package/prompts/deepseek-flash.md +1 -1
- package/prompts/deepseek-v4-pro.md +2 -2
- package/prompts/deepwork.md +27 -18
- package/prompts/source/agents/clarifier.md +5 -3
- package/prompts/source/agents/orchestrator.md +18 -9
- package/prompts/source/agents/plan-critic.md +5 -1
- package/prompts/source/agents/planner.md +4 -2
- package/prompts/source/agents/reviewer.md +6 -0
- package/prompts/source/category/complex.md +4 -4
- package/prompts/source/category/creative.md +6 -4
- package/prompts/source/category/cross-cutting.md +10 -8
- package/prompts/source/category/deep.md +5 -3
- package/prompts/source/category/documenting.md +7 -1
- package/prompts/source/category/frontend.md +2 -2
- package/prompts/source/category/hard-reasoning.md +3 -3
- package/prompts/source/category/research.md +4 -2
- package/prompts/source/deepwork/claude-opus-5.md +2 -2
- package/prompts/source/deepwork/codex.md +1 -1
- package/prompts/source/deepwork/default.md +22 -15
- package/prompts/source/deepwork/gemini.md +23 -16
- package/prompts/source/deepwork/glm.md +21 -14
- package/prompts/source/deepwork/gpt.md +12 -6
- package/prompts/source/deepwork/planner.md +8 -5
- package/prompts/source/manifest.json +178 -63
- package/prompts/source/shared/dsh-host-contract.md +5 -3
- package/prompts/source/shared/locale.md +2 -2
- package/prompts/source/terminal/orchestrator.md +1 -1
- package/skills/ast-grep/SKILL.md +7 -4
- package/skills/brainstorming/SKILL.md +43 -22
- package/skills/coding-agent-sessions/SKILL.md +7 -4
- package/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +46 -46
- package/skills/coding-agent-sessions/scripts/tests/test_pi_family_scanners.py +130 -130
- package/skills/debugging/SKILL.md +14 -9
- package/skills/debugging/references/methodology/00-setup.md +14 -62
- package/skills/debugging/references/methodology/02-investigate.md +4 -4
- package/skills/debugging/references/methodology/03-flaky-triage.md +3 -3
- package/skills/debugging/references/methodology/04-hard-reasoning-escalation.md +2 -14
- package/skills/debugging/references/methodology/06-fix.md +6 -6
- package/skills/debugging/references/methodology/08-qa.md +5 -5
- package/skills/debugging/references/methodology/09-cleanup.md +15 -153
- package/skills/debugging/references/methodology/partial-runtime-evidence.md +3 -16
- package/skills/debugging/references/runtimes/bundled-js-binary.md +1 -16
- package/skills/debugging/references/runtimes/native-binary.md +9 -54
- package/skills/debugging/references/runtimes/node.md +4 -15
- package/skills/debugging/references/runtimes/python.md +3 -15
- package/skills/debugging/references/runtimes/rust.md +2 -18
- package/skills/debugging/references/tools/dap.md +1 -1
- package/skills/debugging/references/tools/ghidra.md +4 -15
- package/skills/debugging/references/tools/playwright-cli.md +3 -15
- package/skills/debugging/references/tools/pwntools.md +4 -16
- package/skills/dispatching-parallel-agents/SKILL.md +18 -16
- package/skills/frontend/SKILL.md +7 -4
- package/skills/frontend/references/design/react-dev-tooling-skill.md +1 -1
- package/skills/git-master/SKILL.md +7 -4
- package/skills/init-deep/SKILL.md +7 -4
- package/skills/receiving-code-review/SKILL.md +17 -12
- package/skills/remove-ai-slops/SKILL.md +39 -38
- package/skills/requesting-code-review/SKILL.md +19 -17
- package/skills/requesting-code-review/code-reviewer.md +13 -1
- package/skills/subagent-driven-development/SKILL.md +29 -26
- package/skills/subagent-driven-development/implementer-prompt.md +29 -11
- package/skills/subagent-driven-development/spec-reviewer-prompt.md +6 -1
- package/skills/using-git-worktrees/SKILL.md +7 -4
- package/skills/writing-plans/SKILL.md +29 -24
- package/skills/writing-plans/plan-document-reviewer-prompt.md +10 -1
- package/scripts/repair-session-log.mjs +0 -476
- package/scripts/session-repair-native-verifier.mjs +0 -367
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context } from "@deepseek-ai/cordis";
|
|
1
|
+
import { Context, symbols } from "@deepseek-ai/cordis";
|
|
2
2
|
import { registerDeepworkCommand, registerDsmmStatusCommand } from "./commands.js";
|
|
3
3
|
import { registerSafetyGuards } from "./guards.js";
|
|
4
4
|
import { registerDeepworkPrompt } from "./mode.js";
|
|
@@ -14,16 +14,22 @@ import { registerLspRuntime } from "./lsp.js";
|
|
|
14
14
|
import { createProfileRuntime } from "./profile-runtime.js";
|
|
15
15
|
import { DsmmProfilesHost, registerConfigRpc } from "./profile-rpc.js";
|
|
16
16
|
import { DSMM_CONFIG_SCHEMA, DSMM_NATIVE_CONFIG_SCHEMA, registerSettings } from "./settings.js";
|
|
17
|
-
import { DeepworkModeController } from "./state.js";
|
|
17
|
+
import { DeepworkModeController, isDeepworkActive } from "./state.js";
|
|
18
18
|
import DsmmSessionPersistence from "./session-persistence.js";
|
|
19
19
|
import { isAbsolute } from "node:path";
|
|
20
20
|
import { createHash, randomUUID } from "node:crypto";
|
|
21
21
|
import { DsmmProfileError } from "./profiles.js";
|
|
22
22
|
import { DsmmDeploymentConfig } from "./deployment-config.js";
|
|
23
23
|
import { agentForScope } from "./native-scope.js";
|
|
24
|
-
import {
|
|
24
|
+
import { resolveSelectedAgentPreset, sessionEvents } from "./session-scope.js";
|
|
25
|
+
import { projectDsmmModules } from "./modules.js";
|
|
26
|
+
import { scopeLifetime } from "./delivery-authority.js";
|
|
27
|
+
import { admittedAgentContext, assertSupportedHostStartup, classifyDsmmAgent, integrateSubagentRuntime, managedAgentContext, publicProfileRuntime, registerRoleControlContribution, registerRuntimeGuidance, runtimeAdmissionView } from "./runtime-integration.js";
|
|
28
|
+
import { createCorePermissionAuthority } from "./core-permission-authority.js";
|
|
29
|
+
import { nativeStandingFullAccess } from "./permission-native-access.js";
|
|
30
|
+
import { installCorePermissions } from "./core-permissions.js";
|
|
25
31
|
export const name = "dsmm";
|
|
26
|
-
export const inject = ["profileContext"];
|
|
32
|
+
export const inject = ["profileContext", "agents"];
|
|
27
33
|
// Direct public Config calls keep the complete plain flat ABI. Native Cordis
|
|
28
34
|
// consumes the same object's Standard Schema protocol for sparse volatile refs.
|
|
29
35
|
export const Config = new Proxy(DSMM_NATIVE_CONFIG_SCHEMA, {
|
|
@@ -48,16 +54,25 @@ export { resolveDshHome } from "./dsh-home.js";
|
|
|
48
54
|
export { DsmmDeploymentConfig, parseGlobalConfig, editGlobalConfig } from "./deployment-config.js";
|
|
49
55
|
export { DSMM_MODULE_DESCRIPTORS, deepworkEnabled, projectDeepworkModule } from "./modules.js";
|
|
50
56
|
export { DEEPWORK_MODE_EVENT, DeepworkModeController, hasOpenTurn, isDeepworkActive } from "./state.js";
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
export { DsmmNativeLlmRuntime } from "./llm-runtime.js";
|
|
58
|
+
/** The current Host composition does not accept compatibility adapters. */
|
|
59
|
+
export function createDsmmHostPlugin(startup) {
|
|
60
|
+
assertSupportedHostStartup(startup);
|
|
61
|
+
return { name, Config, inject,
|
|
62
|
+
apply(ctx, config = {}) { return apply(ctx, config, startup); } };
|
|
63
|
+
}
|
|
64
|
+
export function apply(ctx, config = {}, hostStartup = {}) {
|
|
65
|
+
assertSupportedHostStartup(hostStartup);
|
|
66
|
+
if (!Context.is(ctx)) {
|
|
67
|
+
return applyConfigured(ctx, config, undefined, undefined, hostStartup);
|
|
68
|
+
}
|
|
54
69
|
const deployment = new DsmmDeploymentConfig(ctx, config);
|
|
55
|
-
return deployment.readDesired().then((startup) => applyConfigured(ctx, config, deployment, startup));
|
|
70
|
+
return deployment.readDesired().then((startup) => applyConfigured(ctx, config, deployment, startup, hostStartup));
|
|
56
71
|
}
|
|
57
|
-
function applyConfigured(ctx, config, deployment, startup) {
|
|
72
|
+
function applyConfigured(ctx, config, deployment, startup, hostStartup = {}) {
|
|
58
73
|
// Volatile desired saves retain live realms. An ordinary Loader remount must
|
|
59
74
|
// not replace already-admitted Agent policy/skill realms, including busy Agents.
|
|
60
|
-
if (ctx
|
|
75
|
+
if (Context.is(ctx) && ctx.fiber.entry !== undefined) {
|
|
61
76
|
const native = ctx;
|
|
62
77
|
const owner = ctx.fiber.entry;
|
|
63
78
|
native.on("loader/patch-context", (entry, next) => {
|
|
@@ -74,33 +89,64 @@ function applyConfigured(ctx, config, deployment, startup) {
|
|
|
74
89
|
|| storage.compression !== undefined && !["zstd", "none"].includes(storage.compression)) {
|
|
75
90
|
throw new Error("Deepwork sessionPersistence must preserve an explicit absolute native root and compression");
|
|
76
91
|
}
|
|
77
|
-
if (!(ctx
|
|
92
|
+
if (!Context.is(ctx))
|
|
78
93
|
throw new Error("Deepwork sessionPersistence requires a native Cordis Context");
|
|
79
94
|
const native = ctx;
|
|
80
95
|
if (native.get("sessionPersistence") !== undefined)
|
|
81
96
|
throw new Error("Disable the exact existing JSONL entry at startup before enabling Deepwork sessionPersistence; live replacement is refused");
|
|
82
97
|
const fiber = native.plugin(DsmmSessionPersistence, storage);
|
|
83
|
-
return fiber.await().then(() => applyRuntime(ctx, config, deployment, startup));
|
|
98
|
+
return fiber.await().then(() => applyRuntime(ctx, config, deployment, startup, hostStartup));
|
|
84
99
|
}
|
|
85
|
-
return applyRuntime(ctx, config, deployment, startup);
|
|
100
|
+
return applyRuntime(ctx, config, deployment, startup, hostStartup);
|
|
86
101
|
}
|
|
87
|
-
function applyRuntime(ctx, config, deployment, startup) {
|
|
88
|
-
const
|
|
102
|
+
function applyRuntime(ctx, config, deployment, startup, hostStartup = {}) {
|
|
103
|
+
const native = Context.is(ctx) ? ctx : undefined;
|
|
104
|
+
const lifetime = new AbortController();
|
|
105
|
+
if (native !== undefined)
|
|
106
|
+
scopeLifetime(native, "dsmm: revoke Core startup and admission", () => lifetime.abort());
|
|
107
|
+
let permissionOwner;
|
|
108
|
+
const getMountedPermission = () => {
|
|
109
|
+
if (native === undefined || lifetime.signal.aborted)
|
|
110
|
+
return null;
|
|
111
|
+
const current = native.get("dsmmPermissionController");
|
|
112
|
+
if (current === undefined || (Reflect.get(current, symbols.original) ?? current) !== permissionOwner)
|
|
113
|
+
return null;
|
|
114
|
+
return current?.rules.status().mounted ?? null;
|
|
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);
|
|
89
135
|
let runtime;
|
|
90
136
|
let profileInitialization;
|
|
91
137
|
let requiresNativeProfiles = ctx.get !== undefined;
|
|
92
|
-
const requireProfileAdmission = () => {
|
|
93
|
-
if (requiresNativeProfiles && runtime === undefined) {
|
|
138
|
+
const requireProfileAdmission = (agent) => {
|
|
139
|
+
if (agent !== undefined && requiresNativeProfiles && runtime === undefined) {
|
|
94
140
|
throw new DsmmProfileError("unavailable", "Native Deepwork profile admission is not ready. No provider request or tool work is allowed.");
|
|
95
141
|
}
|
|
96
142
|
};
|
|
97
143
|
const getBoundSettings = (agent) => {
|
|
98
|
-
requireProfileAdmission();
|
|
144
|
+
requireProfileAdmission(agent);
|
|
99
145
|
return runtime?.getSettings(agent) ?? getSettings();
|
|
100
146
|
};
|
|
101
147
|
const deploymentAdmissions = new WeakMap();
|
|
102
148
|
getBoundSettings.admission = (agent) => {
|
|
103
|
-
requireProfileAdmission();
|
|
149
|
+
requireProfileAdmission(agent);
|
|
104
150
|
const nativeAdmission = runtime?.getSettings.admission?.(agent);
|
|
105
151
|
if (nativeAdmission !== undefined)
|
|
106
152
|
return nativeAdmission;
|
|
@@ -113,10 +159,21 @@ function applyRuntime(ctx, config, deployment, startup) {
|
|
|
113
159
|
return admission;
|
|
114
160
|
};
|
|
115
161
|
getBoundSettings.moduleStates = (agent) => {
|
|
116
|
-
requireProfileAdmission();
|
|
117
|
-
return runtime?.getSettings.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);
|
|
118
176
|
};
|
|
119
|
-
const rolePolicy = new DsmmRolePolicy(ctx, getBoundSettings, controller);
|
|
120
177
|
const getSettings = registerSettings(ctx, config, {
|
|
121
178
|
...(startup === undefined ? {} : { resolved: startup.settings }),
|
|
122
179
|
install(readyCtx, getReadySettings) {
|
|
@@ -125,7 +182,7 @@ function applyRuntime(ctx, config, deployment, startup) {
|
|
|
125
182
|
if (deployment !== undefined) {
|
|
126
183
|
readyCtx.provide?.("dsmmDeploymentConfig", deployment);
|
|
127
184
|
readyCtx.inject?.(["typert"], (rpcCtx) => {
|
|
128
|
-
registerConfigRpc(rpcCtx, deployment, getReadySettings(), () => runtime, startup?.sources);
|
|
185
|
+
registerConfigRpc(rpcCtx, deployment, getReadySettings(), () => runtime, startup?.sources, getMountedPermission);
|
|
129
186
|
});
|
|
130
187
|
}
|
|
131
188
|
const install = (installCtx, settingsGetter) => {
|
|
@@ -136,7 +193,11 @@ function applyRuntime(ctx, config, deployment, startup) {
|
|
|
136
193
|
const installCommands = (commandCtx) => {
|
|
137
194
|
if (startupMounted)
|
|
138
195
|
registerDeepworkCommand(commandCtx, controller, settingsGetter);
|
|
139
|
-
|
|
196
|
+
// Status projects live substrate readiness without replacing the exact
|
|
197
|
+
// immutable admission reference used by authority and providers.
|
|
198
|
+
const statusSettings = Object.assign(((agent) => settingsGetter(agent)), settingsGetter);
|
|
199
|
+
statusSettings.admission = agent => ({ ...getBoundSettings.admission(agent), subagentRuntime: getBoundSettings.subagentRuntime() });
|
|
200
|
+
registerDsmmStatusCommand(commandCtx, controller, statusSettings);
|
|
140
201
|
};
|
|
141
202
|
if (installCtx.get !== undefined && installCtx.inject !== undefined)
|
|
142
203
|
installCtx.inject(["commands"], installCommands);
|
|
@@ -144,7 +205,6 @@ function applyRuntime(ctx, config, deployment, startup) {
|
|
|
144
205
|
installCommands(installCtx);
|
|
145
206
|
if (!startupMounted)
|
|
146
207
|
return;
|
|
147
|
-
registerRoleProviders(installCtx, settingsGetter, getReadySettings, rolePolicy);
|
|
148
208
|
// Standing compositions are deployment-only and never replaced on a
|
|
149
209
|
// runtime profile selection. All routes are read from Agent bindings.
|
|
150
210
|
const settings = getReadySettings();
|
|
@@ -155,13 +215,18 @@ function applyRuntime(ctx, config, deployment, startup) {
|
|
|
155
215
|
if (readyCtx.get === undefined) {
|
|
156
216
|
registerRolePresets(readyCtx, getReadySettings);
|
|
157
217
|
install(readyCtx, getReadySettings);
|
|
218
|
+
if (startupMounted)
|
|
219
|
+
registerRoleProviders(readyCtx, getReadySettings, getReadySettings, rolePolicy);
|
|
158
220
|
return;
|
|
159
221
|
}
|
|
160
222
|
requiresNativeProfiles = true;
|
|
161
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);
|
|
162
228
|
if (startupMounted) {
|
|
163
|
-
await registerLspRuntime(profileCtx, getReadySettings().lsp, getBoundSettings);
|
|
164
|
-
await registerNativeSubagentControls(profileCtx);
|
|
229
|
+
await registerLspRuntime(profileCtx, { ...getReadySettings().lsp, enabled: false }, getBoundSettings);
|
|
165
230
|
}
|
|
166
231
|
// Standing definitions must exist before initialize audits retained
|
|
167
232
|
// Agents. A missing optional registry still installs later from this
|
|
@@ -169,33 +234,110 @@ function applyRuntime(ctx, config, deployment, startup) {
|
|
|
169
234
|
const presets = registerRolePresets(profileCtx, getReadySettings);
|
|
170
235
|
if (profileCtx.get?.("agentPresets") !== undefined)
|
|
171
236
|
await presets;
|
|
172
|
-
|
|
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,
|
|
173
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
|
+
},
|
|
174
273
|
subagentCapabilities: {
|
|
175
|
-
backgroundJobs: profileCtx.get?.("jobs") !== undefined
|
|
274
|
+
backgroundJobs: profileCtx.get?.("jobs") !== undefined,
|
|
176
275
|
continuable: profileCtx.get?.("sessionPersistence") !== undefined && profileCtx.get?.("sessionQuery") !== undefined
|
|
177
276
|
&& profileCtx.get?.("subagents")?.getProvider("spawn")?.prepareContinuable !== undefined
|
|
178
|
-
&& profileCtx.get?.("tools")?.get("send_message") !== undefined
|
|
179
277
|
} });
|
|
180
|
-
|
|
181
|
-
|
|
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
|
+
});
|
|
321
|
+
}
|
|
322
|
+
else
|
|
323
|
+
registerRoleControlContribution(hostCtx);
|
|
182
324
|
profileCtx.inject?.(["typert"], (rpcCtx) => {
|
|
183
|
-
new DsmmProfilesHost(rpcCtx,
|
|
325
|
+
new DsmmProfilesHost(rpcCtx, published);
|
|
184
326
|
});
|
|
185
|
-
install(profileCtx, runtime.getSettings);
|
|
186
|
-
const admitIdentity = (agent) => {
|
|
187
|
-
rolePolicy.assertModuleAdmission(agent);
|
|
188
|
-
rolePolicy.admit(agent);
|
|
189
|
-
};
|
|
190
|
-
profileCtx.on?.("agent/created", ({ agent }) => { admitIdentity(agent); }, { global: true });
|
|
191
|
-
for (const agent of profileCtx.get?.("agents")?.list() ?? [])
|
|
192
|
-
admitIdentity(agent);
|
|
193
|
-
if (startupMounted)
|
|
194
|
-
await registerHeadlessRoleTools(profileCtx, controller, runtime.getSettings, rolePolicy);
|
|
195
327
|
};
|
|
196
328
|
if (readyCtx.inject !== undefined) {
|
|
197
|
-
|
|
198
|
-
|
|
329
|
+
profileInitialization = new Promise((resolve, reject) => {
|
|
330
|
+
const fiber = readyCtx.inject(["profileContext"], async (profileCtx) => {
|
|
331
|
+
try {
|
|
332
|
+
await installProfiles(profileCtx);
|
|
333
|
+
resolve();
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
reject(error);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
scopeLifetime(fiber.ctx, "dsmm: cancel Core profile initialization", () => reject(new DsmmProfileError("unavailable", "Core profile initialization was disposed.")));
|
|
340
|
+
});
|
|
199
341
|
}
|
|
200
342
|
else
|
|
201
343
|
throw new Error("dsmm native profiles require asynchronous profileContext injection");
|
|
@@ -208,19 +350,117 @@ function applyRuntime(ctx, config, deployment, startup) {
|
|
|
208
350
|
if (ctx.get !== undefined) {
|
|
209
351
|
ctx.on?.("system-prompt/assemble", async (_assembly, options, next) => {
|
|
210
352
|
const agent = agentForScope(ctx, options.scope);
|
|
211
|
-
if (agent !== undefined)
|
|
353
|
+
if (agent !== undefined) {
|
|
354
|
+
await native?.get("dsmmRuntimeIntegration")?.runtime.authority.waitForPromotion(agent, options.signal);
|
|
212
355
|
rolePolicy.assertModuleAdmission(agent);
|
|
356
|
+
assertDwDelivery(agent);
|
|
357
|
+
}
|
|
213
358
|
return next();
|
|
214
359
|
}, { prepend: true, global: true });
|
|
215
360
|
ctx.on?.("agent/request", async (frame, next) => {
|
|
361
|
+
await native?.get("dsmmRuntimeIntegration")?.runtime.authority.waitForPromotion(frame.agent, frame.signal);
|
|
216
362
|
rolePolicy.assertModuleAdmission(frame.agent);
|
|
363
|
+
assertDwDelivery(frame.agent);
|
|
217
364
|
return next();
|
|
218
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 });
|
|
219
371
|
}
|
|
220
372
|
registerSafetyGuards(ctx, controller, getBoundSettings, ctx.get === undefined ? undefined : rolePolicy);
|
|
221
|
-
|
|
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
|
+
});
|
|
386
|
+
});
|
|
387
|
+
if (deployment !== undefined) {
|
|
388
|
+
const permissions = createCorePermissionAuthority(native, { getSettings: getBoundSettings, rolePolicy, signal: lifetime.signal });
|
|
389
|
+
native.inject(["tools"], scope => {
|
|
390
|
+
const installed = installCorePermissions(scope, deployment, permissions.authority, permissions.assertWritable);
|
|
391
|
+
const identity = Reflect.get(installed, symbols.original) ?? installed;
|
|
392
|
+
scopeLifetime(scope, "dsmm: release mounted permission projection", () => { if (permissionOwner === identity)
|
|
393
|
+
permissionOwner = undefined; }, () => { permissionOwner = identity; });
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
return Promise.resolve(profileInitialization).then(() => {
|
|
397
|
+
lifetime.signal.throwIfAborted();
|
|
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);
|
|
460
|
+
});
|
|
222
461
|
}
|
|
223
462
|
// Cordis Loader introspects this object's Config/inject; a bare function loses
|
|
224
463
|
// the exported schema and may pass null where required DSMM defaults belong.
|
|
225
|
-
|
|
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); } };
|
|
226
466
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { LlmAdapter, LlmRuntime } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import type { DsmmLlmGeneration, DsmmLlmCallConfig } from "./host-llm.js";
|
|
4
|
+
import type { DsmmLlmRouteResolver } from "./role-llm.js";
|
|
5
|
+
type RegistrationHandle = ReturnType<LlmRuntime["registerAdapter"]>;
|
|
6
|
+
/** Captures public registering-fiber provenance; the native runtime remains the sole registry. */
|
|
7
|
+
export declare class LivePiAiOwner implements DsmmLlmRouteResolver {
|
|
8
|
+
private readonly ctx;
|
|
9
|
+
private readonly native;
|
|
10
|
+
private readonly registrations;
|
|
11
|
+
constructor(ctx: Context, native: LlmRuntime);
|
|
12
|
+
requiresRaw(config: DsmmLlmCallConfig): boolean;
|
|
13
|
+
register(scope: Context, providers: readonly string[], adapter: LlmAdapter, handle: RegistrationHandle): RegistrationHandle;
|
|
14
|
+
generation(provider: string): DsmmLlmGeneration;
|
|
15
|
+
resolveRoute(input: Parameters<DsmmLlmRouteResolver["resolveRoute"]>[0], signal?: AbortSignal): Promise<import("./route-json.js").ModelRouteJson>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=live-pi-ai-owner.d.ts.map
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
2
|
+
import { LlmError } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import { Config } from "@deepseek-ai/dsh-llm-pi-ai";
|
|
4
|
+
import { InMemoryCredentialStore } from "@earendil-works/pi-ai";
|
|
5
|
+
import { brandString } from "@deepseek-ai/dsh-brand";
|
|
6
|
+
import { isDeepStrictEqual } from "node:util";
|
|
7
|
+
import { createDsmmPiAiProviderOwner } from "./native-pi-ai-wire.js";
|
|
8
|
+
import { snapshotDsmmCall } from "./host-llm.js";
|
|
9
|
+
import { DsmmMissingProviderError, modelRouteToCall } from "./role-llm.js";
|
|
10
|
+
import { normalizeModelRouteJson } from "./route-json.js";
|
|
11
|
+
const original = (value) => Reflect.get(value, symbols.original) ?? value;
|
|
12
|
+
/** Captures public registering-fiber provenance; the native runtime remains the sole registry. */
|
|
13
|
+
export class LivePiAiOwner {
|
|
14
|
+
ctx;
|
|
15
|
+
native;
|
|
16
|
+
registrations = new Map();
|
|
17
|
+
constructor(ctx, native) {
|
|
18
|
+
this.ctx = ctx;
|
|
19
|
+
this.native = native;
|
|
20
|
+
}
|
|
21
|
+
requiresRaw(config) {
|
|
22
|
+
return config.customParameters !== undefined || config.stop !== undefined
|
|
23
|
+
&& this.registrations.get(config.provider)?.scope.fiber.entry?.options.name === "@deepseek-ai/dsh-llm-pi-ai";
|
|
24
|
+
}
|
|
25
|
+
register(scope, providers, adapter, handle) {
|
|
26
|
+
const record = { scope, adapter, life: new AbortController(), generations: new Map(), providers: [...providers] };
|
|
27
|
+
const retire = () => {
|
|
28
|
+
for (const generation of record.generations.values())
|
|
29
|
+
generation.retire.abort(new LlmError("Provider generation retired", "INVALID_PREPARED_CALL"));
|
|
30
|
+
record.generations.clear();
|
|
31
|
+
};
|
|
32
|
+
const remove = () => {
|
|
33
|
+
retire();
|
|
34
|
+
record.life.abort();
|
|
35
|
+
for (const provider of record.providers)
|
|
36
|
+
if (this.registrations.get(provider) === record)
|
|
37
|
+
this.registrations.delete(provider);
|
|
38
|
+
};
|
|
39
|
+
for (const provider of providers)
|
|
40
|
+
this.registrations.set(provider, record);
|
|
41
|
+
scope.effect(() => remove);
|
|
42
|
+
scope.on("loader/volatile-update", retire, { prepend: true });
|
|
43
|
+
scope.on("loader/partial-dispose", entry => { if (entry === scope.fiber.entry)
|
|
44
|
+
retire(); }, { prepend: true, global: true });
|
|
45
|
+
scope.on("credentials/reference-updated", retire, { prepend: true, global: true });
|
|
46
|
+
const wrapped = Object.assign(() => { remove(); handle(); }, {
|
|
47
|
+
replace: (next) => {
|
|
48
|
+
// Native validation is atomic: a rejected replacement leaves the old routes registered.
|
|
49
|
+
retire();
|
|
50
|
+
handle.replace(next);
|
|
51
|
+
for (const provider of record.providers)
|
|
52
|
+
if (this.registrations.get(provider) === record)
|
|
53
|
+
this.registrations.delete(provider);
|
|
54
|
+
record.providers = [...next];
|
|
55
|
+
for (const provider of next)
|
|
56
|
+
this.registrations.set(provider, record);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
return wrapped;
|
|
60
|
+
}
|
|
61
|
+
generation(provider) {
|
|
62
|
+
const record = this.registrations.get(provider);
|
|
63
|
+
if (record === undefined)
|
|
64
|
+
throw new LlmError("Provider registration is not ready", "DSMM_PROVIDER_NOT_READY");
|
|
65
|
+
const { scope, adapter } = record;
|
|
66
|
+
if (scope.fiber.entry?.options.name !== "@deepseek-ai/dsh-llm-pi-ai")
|
|
67
|
+
throw new LlmError("This provider has no raw executor", "UNSUPPORTED_ROUTE_PARAMETERS");
|
|
68
|
+
const config = scope.fiber.config;
|
|
69
|
+
if (config === null || typeof config !== "object" || !("providers" in config) || config.providers === null || typeof config.providers !== "object"
|
|
70
|
+
|| !("get" in config.providers) || typeof config.providers.get !== "function")
|
|
71
|
+
throw new LlmError("Pi-AI live configuration is unavailable", "DSMM_PROVIDER_NOT_READY");
|
|
72
|
+
const ref = config.providers;
|
|
73
|
+
const current = ref.get()[provider];
|
|
74
|
+
if (current === undefined)
|
|
75
|
+
throw new LlmError("Pi-AI no longer declares this route", "DSMM_PROVIDER_NOT_READY");
|
|
76
|
+
const profile = structuredClone(current);
|
|
77
|
+
const cached = record.generations.get(provider);
|
|
78
|
+
if (cached !== undefined) {
|
|
79
|
+
try {
|
|
80
|
+
cached.value.assertCurrent();
|
|
81
|
+
return cached.value;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
cached.retire.abort();
|
|
85
|
+
record.generations.delete(provider);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const retire = new AbortController();
|
|
89
|
+
const credentials = scope.get("credentials");
|
|
90
|
+
const signal = AbortSignal.any([record.life.signal, retire.signal]);
|
|
91
|
+
const assertCurrent = () => {
|
|
92
|
+
signal.throwIfAborted();
|
|
93
|
+
if (this.registrations.get(provider) !== record || scope.fiber.state !== 2 || scope.fiber.entry?.fiber !== scope.fiber
|
|
94
|
+
|| scope.fiber.config !== config || !isDeepStrictEqual(ref.get()[provider], profile)
|
|
95
|
+
|| (credentials === undefined ? scope.get("credentials") !== undefined : scope.get("credentials") === undefined || original(scope.get("credentials")) !== original(credentials))) {
|
|
96
|
+
retire.abort(new LlmError("Provider configuration or owner changed", "INVALID_PREPARED_CALL"));
|
|
97
|
+
signal.throwIfAborted();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
assertCurrent();
|
|
101
|
+
const owner = createDsmmPiAiProviderOwner(this.ctx, {
|
|
102
|
+
config: { providers: { [provider]: structuredClone(profile) } },
|
|
103
|
+
settingsNamespace: scope.fiber.entry.options.id,
|
|
104
|
+
auth: { credentials: new InMemoryCredentialStore(), authContext: {
|
|
105
|
+
env: async () => { throw new LlmError("Raw requests require named credentials", "MISSING_CREDENTIAL"); }, fileExists: async () => false,
|
|
106
|
+
} },
|
|
107
|
+
async resolveApiKey(_provider, reference, requestSignal) {
|
|
108
|
+
assertCurrent();
|
|
109
|
+
requestSignal?.throwIfAborted();
|
|
110
|
+
if (credentials === undefined)
|
|
111
|
+
throw new LlmError("The credential service is unavailable", "MISSING_CREDENTIAL");
|
|
112
|
+
const key = await credentials.resolve(brandString(reference));
|
|
113
|
+
assertCurrent();
|
|
114
|
+
requestSignal?.throwIfAborted();
|
|
115
|
+
return key?.value;
|
|
116
|
+
},
|
|
117
|
+
}, { signal, adapter, assertCurrent });
|
|
118
|
+
const value = owner.generation(provider);
|
|
119
|
+
record.generations.set(provider, { value, retire });
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
async resolveRoute(input, signal) {
|
|
123
|
+
const route = normalizeModelRouteJson(input), call = snapshotDsmmCall(modelRouteToCall(route));
|
|
124
|
+
signal?.throwIfAborted();
|
|
125
|
+
if (!this.native.listProviders().some(row => row.id === route.provider))
|
|
126
|
+
throw new DsmmMissingProviderError();
|
|
127
|
+
if (!this.requiresRaw(call)) {
|
|
128
|
+
try {
|
|
129
|
+
await this.native.resolveCallConfig(call, signal);
|
|
130
|
+
return route;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (!(error instanceof LlmError) || !["UNSUPPORTED_REASONING_EFFORT", "UNSUPPORTED_OPTION"].includes(error.code))
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const generation = this.generation(route.provider);
|
|
138
|
+
await generation.prepareCall(route.provider, route.model, signal ?? generation.signal);
|
|
139
|
+
generation.assertCurrent();
|
|
140
|
+
signal?.throwIfAborted();
|
|
141
|
+
return route;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=live-pi-ai-owner.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { LlmRuntime } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import { DsmmAwareLlmRuntime } from "./host-llm.js";
|
|
4
|
+
/** The selected profile's sole native LLM registry, installed by cold source migration. */
|
|
5
|
+
export declare class DsmmNativeLlmRuntime extends DsmmAwareLlmRuntime {
|
|
6
|
+
private readonly providerOwner;
|
|
7
|
+
constructor(ctx: Context);
|
|
8
|
+
registerAdapter(...args: Parameters<LlmRuntime["registerAdapter"]>): import("@deepseek-ai/dsh-llm").AdapterRegistrationHandle;
|
|
9
|
+
}
|
|
10
|
+
export default DsmmNativeLlmRuntime;
|
|
11
|
+
//# sourceMappingURL=llm-runtime.d.ts.map
|