@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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
import { PermissionRulesRuntimeSync } from "./permission-rules.js";
|
|
4
|
+
import type { PermissionRulesBackend, PermissionRulesSaveAuthority, PermissionRulesSaveRequest, PermissionRuleSnapshot, PermissionRulesStatus } from "./permission-rules.js";
|
|
5
|
+
import type { DsmmDeploymentConfig } from "./deployment-config.js";
|
|
6
|
+
type NativeEntry = ReturnType<Context["loader"]["resolve"]>;
|
|
7
|
+
/** Structural projection of the SDK's public ConfigEditor.edit; the façade retains all other members. */
|
|
8
|
+
export interface PermissionConfigEditor {
|
|
9
|
+
edit(entry: NativeEntry, change: (current: Record<string, unknown>, inherited: Record<string, unknown>) => Record<string, unknown>): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
type NativeEdit = PermissionConfigEditor["edit"];
|
|
12
|
+
export interface DeploymentPermissionRulesOptions {
|
|
13
|
+
readonly deployment: Pick<DsmmDeploymentConfig, "nativeEntry" | "home" | "coordinateWrites" | "permissionSource" | "saveGlobal">;
|
|
14
|
+
/** Core readonly/effective-policy check; must not require idle or DW delivery readiness. */
|
|
15
|
+
readonly assertWritable: (root: Agent) => void;
|
|
16
|
+
/** Synchronous revocation of every pending/grant consumer in this owner. */
|
|
17
|
+
readonly revoke: () => void;
|
|
18
|
+
readonly notify: (snapshot: PermissionRuleSnapshot) => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/** Canonical Rules RPC writes the global layer; native overrides remain independently owned. */
|
|
21
|
+
export declare class DeploymentPermissionRules implements PermissionRulesBackend {
|
|
22
|
+
private readonly ctx;
|
|
23
|
+
private readonly options;
|
|
24
|
+
readonly runtime: PermissionRulesRuntimeSync;
|
|
25
|
+
readonly initial: PermissionRuleSnapshot;
|
|
26
|
+
private readonly lifetime;
|
|
27
|
+
private readonly operatorWrites;
|
|
28
|
+
private readonly nativeFiber;
|
|
29
|
+
private readonly registry;
|
|
30
|
+
private busy;
|
|
31
|
+
private refreshing?;
|
|
32
|
+
constructor(ctx: Context, options: DeploymentPermissionRulesOptions);
|
|
33
|
+
private snapshot;
|
|
34
|
+
assertWritable(root: Agent): void;
|
|
35
|
+
private check;
|
|
36
|
+
read(authority: PermissionRulesSaveAuthority): Promise<PermissionRuleSnapshot>;
|
|
37
|
+
save(request: PermissionRulesSaveRequest, authority: PermissionRulesSaveAuthority): Promise<{
|
|
38
|
+
snapshot: PermissionRuleSnapshot;
|
|
39
|
+
runtime: PermissionRulesStatus;
|
|
40
|
+
}>;
|
|
41
|
+
private readonly notify;
|
|
42
|
+
/** Host recovery re-reads storage and never revives a former signal or grant. */
|
|
43
|
+
reconcile(): Promise<void>;
|
|
44
|
+
/** Next actual consumption observes disk/native edits without requiring a UI save. */
|
|
45
|
+
private refresh;
|
|
46
|
+
private synchronize;
|
|
47
|
+
private transaction;
|
|
48
|
+
editNative(editor: PermissionConfigEditor, entry: NativeEntry, change: Parameters<NativeEdit>[1]): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/** Install in the owned Core fiber with the public `agents` service injected. */
|
|
51
|
+
export declare function installDeploymentPermissionRules(ctx: Context, options: DeploymentPermissionRulesOptions): DeploymentPermissionRules;
|
|
52
|
+
/** Scoped to the ordinary SettingsForms owner; never replaces a global instance or registry. */
|
|
53
|
+
export declare function permissionConfigEditorFacade<T extends PermissionConfigEditor>(editor: T): T;
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=deployment-permission-rules.d.ts.map
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { PermissionRefusal, permissionOriginal } from "./permission-control.js";
|
|
2
|
+
import { applyPermissionRulesSave, importPermissionRules, operatorPermissionRulesSource, parsePermissionRules, parsePermissionRulesSave, PermissionRulesRuntimeSync } from "./permission-rules.js";
|
|
3
|
+
import { copyJson, validateSparseConfig } from "./settings.js";
|
|
4
|
+
import { parseHostNativeCommands } from "./permission-native-command.js";
|
|
5
|
+
const entries = new WeakMap();
|
|
6
|
+
const claimed = new WeakSet();
|
|
7
|
+
const homes = new Map();
|
|
8
|
+
function imported(config, label, global) {
|
|
9
|
+
if (config.permissionControl?.rules === undefined)
|
|
10
|
+
return config;
|
|
11
|
+
const rules = parsePermissionRules(config.permissionControl.rules).map(rule => ({
|
|
12
|
+
...importPermissionRules([{ id: rule.id, action: rule.action, match: rule.match }], label, rule.revision)[0], revoked: rule.revoked
|
|
13
|
+
}));
|
|
14
|
+
return validateSparseConfig({ ...config, permissionControl: { ...config.permissionControl, rules } }, global);
|
|
15
|
+
}
|
|
16
|
+
/** Source checks complement in-process generation revocation; a serialized token is never authority. */
|
|
17
|
+
class SourceBoundRulesRuntime extends PermissionRulesRuntimeSync {
|
|
18
|
+
source;
|
|
19
|
+
refreshSource;
|
|
20
|
+
projection;
|
|
21
|
+
constructor(initial, revoke, source, refreshSource) {
|
|
22
|
+
super(initial, revoke);
|
|
23
|
+
this.source = source;
|
|
24
|
+
this.refreshSource = refreshSource;
|
|
25
|
+
}
|
|
26
|
+
async refresh() { await this.refreshSource(); return this.getPolicy(); }
|
|
27
|
+
status() {
|
|
28
|
+
const current = super.status();
|
|
29
|
+
let source;
|
|
30
|
+
try {
|
|
31
|
+
source = this.source();
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
if (current.state === "synced")
|
|
35
|
+
this.invalidate();
|
|
36
|
+
return Object.freeze({ ...super.status(), state: "unsynced" });
|
|
37
|
+
}
|
|
38
|
+
if (current.state === "synced" && current.savedRevision !== source.revision)
|
|
39
|
+
this.invalidate();
|
|
40
|
+
return Object.freeze({ ...super.status(), savedRevision: source.revision, restartRequired: source.policy.enabled !== current.mounted });
|
|
41
|
+
}
|
|
42
|
+
getPolicy() {
|
|
43
|
+
const policy = super.getPolicy();
|
|
44
|
+
try {
|
|
45
|
+
if (this.source().revision !== policy.revision)
|
|
46
|
+
throw new PermissionRefusal("stale");
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
this.invalidate();
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
if (this.projection?.snapshot !== policy)
|
|
53
|
+
this.projection = { snapshot: policy,
|
|
54
|
+
value: Object.freeze({ revision: policy.revision, policy: Object.freeze({ ...policy.policy, enabled: super.status().mounted }) }) };
|
|
55
|
+
return this.projection.value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Canonical Rules RPC writes the global layer; native overrides remain independently owned. */
|
|
59
|
+
export class DeploymentPermissionRules {
|
|
60
|
+
ctx;
|
|
61
|
+
options;
|
|
62
|
+
runtime;
|
|
63
|
+
initial;
|
|
64
|
+
lifetime = new AbortController();
|
|
65
|
+
operatorWrites = new WeakMap();
|
|
66
|
+
nativeFiber;
|
|
67
|
+
registry;
|
|
68
|
+
busy = false;
|
|
69
|
+
refreshing;
|
|
70
|
+
constructor(ctx, options) {
|
|
71
|
+
this.ctx = ctx;
|
|
72
|
+
this.options = options;
|
|
73
|
+
this.nativeFiber = options.deployment.nativeEntry?.fiber;
|
|
74
|
+
this.registry = permissionOriginal(ctx.agents);
|
|
75
|
+
this.initial = this.snapshot();
|
|
76
|
+
this.runtime = new SourceBoundRulesRuntime(this.initial, options.revoke, () => this.snapshot(), () => this.refresh());
|
|
77
|
+
const deployment = options.deployment, entry = deployment.nativeEntry;
|
|
78
|
+
if (entry !== undefined) {
|
|
79
|
+
if (entry.fiber?.ctx.root !== ctx.root)
|
|
80
|
+
throw new PermissionRefusal("not-owned");
|
|
81
|
+
if (entries.has(entry))
|
|
82
|
+
throw new PermissionRefusal("unavailable");
|
|
83
|
+
}
|
|
84
|
+
const homeKey = process.platform === "win32" ? deployment.home.toLowerCase() : deployment.home;
|
|
85
|
+
const family = homes.get(homeKey) ?? new Set();
|
|
86
|
+
if ([...family].some(owner => owner.busy || owner.runtime.status().state === "updating"))
|
|
87
|
+
throw new PermissionRefusal("unavailable");
|
|
88
|
+
const remove = deployment.coordinateWrites({ global: async (request, config, assertAuthority, write) => {
|
|
89
|
+
const operator = this.operatorWrites.get(request);
|
|
90
|
+
const rulesInput = request.edits.some(edit => edit.path[0] === "permissionControl" && (edit.path.length === 1 || edit.path[1] === "rules"));
|
|
91
|
+
const candidate = operator !== undefined || !rulesInput ? config : imported(config, "global-settings", true);
|
|
92
|
+
return this.transaction([...family], async () => { assertAuthority(); return write(candidate); });
|
|
93
|
+
} });
|
|
94
|
+
if (entry !== undefined) {
|
|
95
|
+
entries.set(entry, this);
|
|
96
|
+
claimed.add(entry);
|
|
97
|
+
}
|
|
98
|
+
family.add(this);
|
|
99
|
+
homes.set(homeKey, family);
|
|
100
|
+
ctx.effect(() => () => {
|
|
101
|
+
this.lifetime.abort();
|
|
102
|
+
remove();
|
|
103
|
+
family.delete(this);
|
|
104
|
+
if (family.size === 0)
|
|
105
|
+
homes.delete(homeKey);
|
|
106
|
+
if (entry !== undefined)
|
|
107
|
+
entries.delete(entry);
|
|
108
|
+
this.runtime.retire();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
snapshot() {
|
|
112
|
+
this.lifetime.signal.throwIfAborted();
|
|
113
|
+
if (this.options.deployment.nativeEntry?.fiber !== this.nativeFiber)
|
|
114
|
+
throw new PermissionRefusal("unavailable");
|
|
115
|
+
const source = this.options.deployment.permissionSource();
|
|
116
|
+
return Object.freeze({ revision: source.revision, policy: source.policy });
|
|
117
|
+
}
|
|
118
|
+
assertWritable(root) {
|
|
119
|
+
this.lifetime.signal.throwIfAborted();
|
|
120
|
+
const registry = this.ctx.agents;
|
|
121
|
+
if (permissionOriginal(registry) !== this.registry || registry.get(root.id) !== root || root.session.id !== root.id || root.session.header.origin === "subagent"
|
|
122
|
+
|| !registry.roots().includes(root) || registry.list().some(owner => owner !== root && registry.isOwnedBy(root.id, owner)))
|
|
123
|
+
throw new PermissionRefusal("not-owned");
|
|
124
|
+
this.options.assertWritable(root);
|
|
125
|
+
}
|
|
126
|
+
check(authority) {
|
|
127
|
+
authority.signal.throwIfAborted();
|
|
128
|
+
authority.assertCurrent();
|
|
129
|
+
this.assertWritable(authority.root);
|
|
130
|
+
}
|
|
131
|
+
async read(authority) {
|
|
132
|
+
this.check(authority);
|
|
133
|
+
await this.refresh();
|
|
134
|
+
this.check(authority);
|
|
135
|
+
const snapshot = this.snapshot();
|
|
136
|
+
if (this.runtime.status().state === "synced" && this.runtime.status().savedRevision !== snapshot.revision)
|
|
137
|
+
this.runtime.invalidate();
|
|
138
|
+
this.check(authority);
|
|
139
|
+
return snapshot;
|
|
140
|
+
}
|
|
141
|
+
async save(request, authority) {
|
|
142
|
+
this.check(authority);
|
|
143
|
+
request = parsePermissionRulesSave(request);
|
|
144
|
+
const source = this.options.deployment.permissionSource();
|
|
145
|
+
if (request.expectedRevision !== source.revision)
|
|
146
|
+
throw new PermissionRefusal("stale");
|
|
147
|
+
if (Object.keys(source.profile.permissionControl ?? {}).some(key => key !== "enabled")) {
|
|
148
|
+
const error = new PermissionRefusal("unavailable");
|
|
149
|
+
error.message = "Native profile overrides the global permission policy; edit or unset that native override first.";
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
const proposed = applyPermissionRulesSave({ revision: source.revision, policy: source.policy }, request, operatorPermissionRulesSource(authority));
|
|
153
|
+
const edits = Object.entries(request.changes ?? {}).map(([key, value]) => ({ op: "set", path: ["permissionControl", key], value }));
|
|
154
|
+
if (request.upsert !== undefined || request.revoke !== undefined)
|
|
155
|
+
edits.push({ op: "set", path: ["permissionControl", "rules"], value: proposed.rules });
|
|
156
|
+
const write = { expectedRevision: source.globalRevision, edits };
|
|
157
|
+
this.operatorWrites.set(write, authority);
|
|
158
|
+
try {
|
|
159
|
+
await this.options.deployment.saveGlobal(write, () => {
|
|
160
|
+
this.check(authority);
|
|
161
|
+
const current = this.options.deployment.permissionSource();
|
|
162
|
+
if (current.revision !== source.revision)
|
|
163
|
+
throw new PermissionRefusal("stale");
|
|
164
|
+
});
|
|
165
|
+
this.check(authority);
|
|
166
|
+
return { snapshot: this.snapshot(), runtime: this.runtime.status() };
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
this.operatorWrites.delete(write);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
notify = async (snapshot) => {
|
|
173
|
+
this.lifetime.signal.throwIfAborted();
|
|
174
|
+
await this.options.notify(snapshot);
|
|
175
|
+
this.lifetime.signal.throwIfAborted();
|
|
176
|
+
if (this.snapshot().revision !== snapshot.revision)
|
|
177
|
+
throw new PermissionRefusal("stale");
|
|
178
|
+
};
|
|
179
|
+
/** Host recovery re-reads storage and never revives a former signal or grant. */
|
|
180
|
+
async reconcile() {
|
|
181
|
+
if (this.busy)
|
|
182
|
+
throw new PermissionRefusal("stale");
|
|
183
|
+
if (this.runtime.status().state === "synced")
|
|
184
|
+
this.runtime.invalidate();
|
|
185
|
+
await this.runtime.recover(undefined, this.snapshot(), this.notify);
|
|
186
|
+
}
|
|
187
|
+
/** Next actual consumption observes disk/native edits without requiring a UI save. */
|
|
188
|
+
async refresh() {
|
|
189
|
+
this.lifetime.signal.throwIfAborted();
|
|
190
|
+
if (this.refreshing !== undefined)
|
|
191
|
+
return this.refreshing;
|
|
192
|
+
if (this.runtime.status().state === "synced")
|
|
193
|
+
return;
|
|
194
|
+
if (this.busy)
|
|
195
|
+
throw new PermissionRefusal("unavailable");
|
|
196
|
+
const refreshing = this.reconcile();
|
|
197
|
+
this.refreshing = refreshing;
|
|
198
|
+
try {
|
|
199
|
+
await refreshing;
|
|
200
|
+
this.lifetime.signal.throwIfAborted();
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
if (this.refreshing === refreshing)
|
|
204
|
+
this.refreshing = undefined;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async synchronize(updates, recovery) {
|
|
208
|
+
let rows;
|
|
209
|
+
try {
|
|
210
|
+
rows = [...updates].map(([owner, update]) => ({ owner, update, snapshot: owner.snapshot() }));
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
for (const owner of updates.keys())
|
|
214
|
+
owner.runtime.invalidate();
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
const acknowledged = Promise.all(rows.map(row => row.owner.notify(row.snapshot))).then(() => {
|
|
218
|
+
for (const row of rows)
|
|
219
|
+
if (row.owner.snapshot().revision !== row.snapshot.revision)
|
|
220
|
+
throw new PermissionRefusal("stale");
|
|
221
|
+
});
|
|
222
|
+
const settled = await Promise.allSettled([acknowledged, ...rows.map(({ owner, update, snapshot }) => recovery
|
|
223
|
+
? owner.runtime.recover(update, snapshot, () => acknowledged) : owner.runtime.commit(update, snapshot, () => acknowledged))]);
|
|
224
|
+
const failures = [...new Set(settled.flatMap(result => result.status === "rejected" ? [result.reason] : []))];
|
|
225
|
+
if (failures.length)
|
|
226
|
+
throw new AggregateError(failures, "Permission configuration is not synchronized.");
|
|
227
|
+
}
|
|
228
|
+
async transaction(participants, write) {
|
|
229
|
+
for (const participant of participants) {
|
|
230
|
+
if (participant.busy)
|
|
231
|
+
throw new PermissionRefusal("stale");
|
|
232
|
+
if (participant.runtime.status().state !== "synced" || participant.runtime.status().savedRevision !== participant.snapshot().revision)
|
|
233
|
+
await participant.reconcile();
|
|
234
|
+
}
|
|
235
|
+
const updates = new Map();
|
|
236
|
+
const locked = new Set();
|
|
237
|
+
try {
|
|
238
|
+
let result;
|
|
239
|
+
try {
|
|
240
|
+
for (const participant of participants) {
|
|
241
|
+
if (participant.busy)
|
|
242
|
+
throw new PermissionRefusal("stale");
|
|
243
|
+
participant.busy = true;
|
|
244
|
+
locked.add(participant);
|
|
245
|
+
updates.set(participant, participant.runtime.begin(participant.snapshot().revision));
|
|
246
|
+
}
|
|
247
|
+
result = await write();
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
try {
|
|
251
|
+
await this.synchronize(updates, true);
|
|
252
|
+
}
|
|
253
|
+
catch (recovery) {
|
|
254
|
+
throw new AggregateError([error, recovery], "Permission write and authoritative recovery failed.");
|
|
255
|
+
}
|
|
256
|
+
throw error;
|
|
257
|
+
}
|
|
258
|
+
await this.synchronize(updates, false);
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
finally {
|
|
262
|
+
for (const participant of locked)
|
|
263
|
+
participant.busy = false;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async editNative(editor, entry, change) {
|
|
267
|
+
await this.transaction([this], () => editor.edit(entry, (current, inherited) => {
|
|
268
|
+
const next = validateSparseConfig(change(current, inherited));
|
|
269
|
+
if (next.permissionControl?.nativeCommands !== undefined)
|
|
270
|
+
parseHostNativeCommands(next.permissionControl.nativeCommands);
|
|
271
|
+
if (JSON.stringify(next.permissionControl?.rules) === JSON.stringify(current.permissionControl && typeof current.permissionControl === "object" ? Reflect.get(current.permissionControl, "rules") : undefined))
|
|
272
|
+
return copyJson(next);
|
|
273
|
+
return copyJson(imported(next, "native-profile-settings", false));
|
|
274
|
+
}));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/** Install in the owned Core fiber with the public `agents` service injected. */
|
|
278
|
+
export function installDeploymentPermissionRules(ctx, options) {
|
|
279
|
+
return new DeploymentPermissionRules(ctx, options);
|
|
280
|
+
}
|
|
281
|
+
/** Scoped to the ordinary SettingsForms owner; never replaces a global instance or registry. */
|
|
282
|
+
export function permissionConfigEditorFacade(editor) {
|
|
283
|
+
const methods = new Map();
|
|
284
|
+
return new Proxy(editor, { get(target, key) {
|
|
285
|
+
if (key !== "edit") {
|
|
286
|
+
const value = Reflect.get(target, key, target);
|
|
287
|
+
if (typeof value !== "function")
|
|
288
|
+
return value;
|
|
289
|
+
const previous = methods.get(key);
|
|
290
|
+
if (previous?.original === value)
|
|
291
|
+
return previous.bound;
|
|
292
|
+
const bound = value.bind(target);
|
|
293
|
+
methods.set(key, { original: value, bound });
|
|
294
|
+
return bound;
|
|
295
|
+
}
|
|
296
|
+
return (entry, change) => {
|
|
297
|
+
const backend = entries.get(entry);
|
|
298
|
+
if (backend !== undefined)
|
|
299
|
+
return backend.editNative(target, entry, change);
|
|
300
|
+
if (claimed.has(entry))
|
|
301
|
+
return Promise.reject(new PermissionRefusal("unavailable"));
|
|
302
|
+
return target.edit(entry, change);
|
|
303
|
+
};
|
|
304
|
+
} });
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=deployment-permission-rules.js.map
|
package/lib/dsh-types.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface DshSessionHeader {
|
|
|
7
7
|
cwd?: string;
|
|
8
8
|
agentPreset?: string;
|
|
9
9
|
origin?: string;
|
|
10
|
+
parentSession?: string;
|
|
11
|
+
delegationDepth?: number;
|
|
10
12
|
}
|
|
11
13
|
export interface DshSession {
|
|
12
14
|
readonly id?: string;
|
|
@@ -46,14 +48,14 @@ export interface DshAgentCreatedFrame {
|
|
|
46
48
|
source: "startup" | "resume" | "clear" | "compact";
|
|
47
49
|
signal?: AbortSignal;
|
|
48
50
|
}
|
|
49
|
-
export
|
|
51
|
+
export type DshLlmCallConfig = {
|
|
50
52
|
provider: string;
|
|
51
53
|
model: string;
|
|
52
54
|
reasoningEffort?: string;
|
|
53
55
|
temperature?: number;
|
|
54
56
|
maxTokens?: number;
|
|
55
|
-
stop?:
|
|
56
|
-
}
|
|
57
|
+
stop?: string[];
|
|
58
|
+
};
|
|
57
59
|
export interface DshLlmFailure {
|
|
58
60
|
readonly message: string;
|
|
59
61
|
readonly code: string;
|
|
@@ -81,6 +83,9 @@ export interface DshResolvedModelInfo {
|
|
|
81
83
|
export interface DshLlmRuntime {
|
|
82
84
|
resolveModelInfo(provider: string, model: string, signal?: AbortSignal): Promise<DshResolvedModelInfo>;
|
|
83
85
|
resolveCallConfig?(config: DshLlmCallConfig, signal?: AbortSignal): Promise<DshLlmCallConfig>;
|
|
86
|
+
listProviders?(): readonly {
|
|
87
|
+
id: string;
|
|
88
|
+
}[];
|
|
84
89
|
}
|
|
85
90
|
export interface AgentRequestFrame {
|
|
86
91
|
agent: DshAgent;
|
|
@@ -252,11 +257,12 @@ export interface DshContext {
|
|
|
252
257
|
commands?: DshCommandsRegistry;
|
|
253
258
|
tools?: DshToolRuntime;
|
|
254
259
|
llm?: DshLlmRuntime;
|
|
260
|
+
dsmmRuntimeIntegration?: import("./runtime-integration.js").DsmmHostRuntimeIntegration;
|
|
255
261
|
get?<T = unknown>(name: string): T | undefined;
|
|
256
262
|
provide?(name: string, service: unknown): unknown;
|
|
257
263
|
plugin?(plugin: unknown, config?: unknown): PromiseLike<unknown>;
|
|
258
264
|
inject?(dependencies: string[], installer: (readyCtx: DshContext) => unknown): unknown;
|
|
259
|
-
effect?(callback: () =>
|
|
265
|
+
effect?(callback: () => () => void): unknown;
|
|
260
266
|
on?(event: "agent/request", listener: (frame: AgentRequestFrame, next: () => Promise<DshLlmCallConfig>) => Promise<DshLlmCallConfig>, options?: boolean | {
|
|
261
267
|
prepend?: boolean;
|
|
262
268
|
global?: boolean;
|
package/lib/guards.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { DsmmRolePolicy } from "./role-policy.js";
|
|
|
5
5
|
export declare const DSMM_GUARD_PREFIX = "[dsmm safety]";
|
|
6
6
|
export declare function truncateTextMiddle(text: string, maxBytes: number, toolName: string): string;
|
|
7
7
|
export declare function isSafetyScopeActive(exec: DshToolExecution, settings: DsmmSettings, controller: DeepworkModeController): boolean;
|
|
8
|
-
export declare function decidePreToolExecution(exec: DshToolExecution, settings: DsmmSettings, controller: DeepworkModeController): DshPreToolDecision | undefined;
|
|
8
|
+
export declare function decidePreToolExecution(exec: DshToolExecution, settings: DsmmSettings, controller: DeepworkModeController, nativeFullAccess?: boolean): DshPreToolDecision | undefined;
|
|
9
9
|
export declare function decidePostToolExecution(exec: DshToolExecution, result: Readonly<DshToolExecutionResult>, decision: DshPostToolDecision, settings: DsmmSettings, controller: DeepworkModeController): DshPostToolDecision;
|
|
10
10
|
export declare function registerSafetyGuards(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, rolePolicy?: DsmmRolePolicy): void;
|
|
11
11
|
//# sourceMappingURL=guards.d.ts.map
|
package/lib/guards.js
CHANGED
|
@@ -3,6 +3,9 @@ import { resolveSelectedAgentPreset } from "./session-scope.js";
|
|
|
3
3
|
import { validatePlanMutation } from "./plan-validation.js";
|
|
4
4
|
import { classifyKnownGitWrite, classifyShellDialectViolation } from "./shell-command.js";
|
|
5
5
|
import { resolveAdmittedDsmmRole } from "./role-policy.js";
|
|
6
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
7
|
+
import { nativeStandingFullAccess } from "./permission-native-access.js";
|
|
8
|
+
import { DsmmProfileError } from "./profiles.js";
|
|
6
9
|
export const DSMM_GUARD_PREFIX = "[dsmm safety]";
|
|
7
10
|
const STRUCTURED_TODO_PATTERN = /^\[[^\]]+\]\s+\[[^\]]+\]\s+to\s+.+\s+-\s+expect\s+.+/u;
|
|
8
11
|
function asRecord(value) {
|
|
@@ -198,9 +201,11 @@ function todoDisciplineDecision(exec, settings) {
|
|
|
198
201
|
reason: `${DSMM_GUARD_PREFIX} todo content must use "[WHERE] [HOW] to [WHY] - expect [RESULT]": ${malformed.content}`
|
|
199
202
|
};
|
|
200
203
|
}
|
|
201
|
-
export function decidePreToolExecution(exec, settings, controller) {
|
|
204
|
+
export function decidePreToolExecution(exec, settings, controller, nativeFullAccess = false) {
|
|
202
205
|
if (!isSafetyScopeActive(exec, settings, controller))
|
|
203
206
|
return undefined;
|
|
207
|
+
if (nativeFullAccess)
|
|
208
|
+
return settings.guards.gitWriteGuard === "deny" ? gitWriteDecision(exec, settings) : undefined;
|
|
204
209
|
if (settings.guards.shellCommandSafety) {
|
|
205
210
|
const shell = shellSafetyDecision(exec);
|
|
206
211
|
if (shell !== undefined)
|
|
@@ -242,18 +247,31 @@ export function decidePostToolExecution(exec, result, decision, settings, contro
|
|
|
242
247
|
};
|
|
243
248
|
}
|
|
244
249
|
export function registerSafetyGuards(ctx, controller, getSettings, rolePolicy) {
|
|
250
|
+
const truncationLimits = new WeakMap();
|
|
245
251
|
const tools = ctx.get?.("tools");
|
|
246
252
|
if (rolePolicy !== undefined && tools !== undefined) {
|
|
247
|
-
const guard = tools.guard((execution) => execution.agent === undefined ? undefined : rolePolicy.toolDenial(execution.agent, execution.name, tools));
|
|
253
|
+
const guard = tools.guard((execution) => execution.agent === undefined ? undefined : rolePolicy.toolDenial(execution.agent, execution.name, tools, execution));
|
|
248
254
|
ctx.effect?.(() => guard);
|
|
249
255
|
}
|
|
250
256
|
ctx.on?.("tools/pre-execute", async (exec, next) => {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
257
|
+
const execution = exec;
|
|
258
|
+
const full = Context.is(ctx) && nativeStandingFullAccess(ctx, exec.agent);
|
|
259
|
+
rolePolicy?.captureToolExecution(execution, full);
|
|
260
|
+
const denied = exec.agent === undefined ? undefined : full ? rolePolicy?.toolBlacklistDenial(exec.agent, exec.name, execution) : rolePolicy?.preToolDenial(exec.agent, exec.name, undefined, execution);
|
|
254
261
|
if (denied !== undefined)
|
|
255
262
|
return { kind: "deny", reason: denied };
|
|
256
|
-
|
|
263
|
+
let settings;
|
|
264
|
+
try {
|
|
265
|
+
settings = getSettings(exec.agent);
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
if (full && error instanceof DsmmProfileError && !["disposed", "not-owned", "cancelled"].includes(error.code))
|
|
269
|
+
return next();
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
const decision = decidePreToolExecution(exec, settings, controller, full);
|
|
273
|
+
if (!full && settings.modules.deepwork.enabled && settings.guards.toolOutputTruncation.enabled && isSafetyScopeActive(exec, settings, controller))
|
|
274
|
+
truncationLimits.set(exec, settings.guards.toolOutputTruncation.maxInlineBytes);
|
|
257
275
|
if (decision === undefined)
|
|
258
276
|
return next();
|
|
259
277
|
if (decision.kind === "deny")
|
|
@@ -262,9 +280,12 @@ export function registerSafetyGuards(ctx, controller, getSettings, rolePolicy) {
|
|
|
262
280
|
return downstream.kind === "allow" ? decision : downstream;
|
|
263
281
|
}, { prepend: true });
|
|
264
282
|
ctx.on?.("tools/post-execute", async (exec, result, next) => {
|
|
265
|
-
const settings = getSettings(exec.agent);
|
|
266
283
|
const decision = await next();
|
|
267
|
-
|
|
284
|
+
const limit = truncationLimits.get(exec);
|
|
285
|
+
if (limit === undefined || result.isError || decision.kind !== "accept" || "value" in decision)
|
|
286
|
+
return decision;
|
|
287
|
+
const text = allText(decision.content ?? result.content);
|
|
288
|
+
return text === undefined || utf8Bytes(text) <= limit ? decision : { ...decision, content: [{ type: "text", text: truncateTextMiddle(text, limit, exec.name) }] };
|
|
268
289
|
}, { prepend: true });
|
|
269
290
|
}
|
|
270
291
|
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import { AgentLoop } from "@deepseek-ai/dsh-agent-loop";
|
|
3
|
+
import type { Config as AgentLoopConfig } from "@deepseek-ai/dsh-agent-loop";
|
|
4
|
+
import { DsmmAwareLlmRuntime } from "./host-llm.js";
|
|
5
|
+
import type { DsmmLlmHostOwner } from "./host-llm.js";
|
|
6
|
+
import type { DsmmPiAiOwnerOptions, DsmmPiAiProviderOwner } from "./native-pi-ai-wire.js";
|
|
7
|
+
export interface DsmmLlmColdStartupOptions {
|
|
8
|
+
/** Original validated declarative AgentLoop config, including all configured Agents. */
|
|
9
|
+
readonly agentLoop: AgentLoopConfig;
|
|
10
|
+
readonly provider: DsmmPiAiOwnerOptions;
|
|
11
|
+
/** Install routing/admission guards and return their exact live request owner before constructing the loop. */
|
|
12
|
+
readonly establish?: (ctx: Context, providers: DsmmPiAiProviderOwner) => Promise<DsmmLlmHostOwner>;
|
|
13
|
+
}
|
|
14
|
+
export interface DsmmLlmColdStartup {
|
|
15
|
+
/** Append to profileContext.overlays before readProfilePatches; Settings recomposition must see this same layer. Provider handoff remains explicit in the stock provider row. */
|
|
16
|
+
readonly patches: readonly [{
|
|
17
|
+
readonly id: "agent-loop";
|
|
18
|
+
readonly disabled: true;
|
|
19
|
+
}, {
|
|
20
|
+
readonly insert: readonly [{
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly config: DsmmPiAiOwnerOptions["config"];
|
|
24
|
+
}];
|
|
25
|
+
}];
|
|
26
|
+
/** Pass to the public dsh-app-boot prepare callback, before the standard profile entries mount. */
|
|
27
|
+
prepare(ctx: Context): Promise<void>;
|
|
28
|
+
/** Call after boot settlement. Missing dependencies are a startup refusal, never an implicit stock fallback. */
|
|
29
|
+
assertReady(): {
|
|
30
|
+
readonly loop: AgentLoop;
|
|
31
|
+
readonly llm: DsmmAwareLlmRuntime;
|
|
32
|
+
readonly provider: DsmmPiAiProviderOwner;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Host-only cold composition. The profile must disable its original agent-loop
|
|
37
|
+
* row and remove only this owner's routes from llm-pi-ai before mounting entries.
|
|
38
|
+
* The standard MAIN, registries, persistence and other provider owners remain mounted.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createDsmmLlmColdStartup(options: DsmmLlmColdStartupOptions): DsmmLlmColdStartup;
|
|
41
|
+
//# sourceMappingURL=host-llm-startup.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Context, symbols } from "@deepseek-ai/cordis";
|
|
2
|
+
import { AgentLoop } from "@deepseek-ai/dsh-agent-loop";
|
|
3
|
+
import { DsmmAwareLlmRuntime } from "./host-llm.js";
|
|
4
|
+
import { createDsmmRoleLlmOwner } from "./role-llm-runtime.js";
|
|
5
|
+
/**
|
|
6
|
+
* Host-only cold composition. The profile must disable its original agent-loop
|
|
7
|
+
* row and remove only this owner's routes from llm-pi-ai before mounting entries.
|
|
8
|
+
* The standard MAIN, registries, persistence and other provider owners remain mounted.
|
|
9
|
+
*/
|
|
10
|
+
export function createDsmmLlmColdStartup(options) {
|
|
11
|
+
let host;
|
|
12
|
+
let failure;
|
|
13
|
+
let mounted;
|
|
14
|
+
let provider;
|
|
15
|
+
const dependencies = [...AgentLoop.inject, "dsmmProfileRuntime", "dsmmRuntimeIntegration", "sessionPersistence", "dsmmLlmProviderOwner"];
|
|
16
|
+
const builtin = "dsmm-llm-provider-owner";
|
|
17
|
+
return {
|
|
18
|
+
patches: [{ id: "agent-loop", disabled: true }, { insert: [{ id: options.provider.settingsNamespace, name: `cordis:${builtin}`, config: options.provider.config }] }],
|
|
19
|
+
async prepare(ctx) {
|
|
20
|
+
const loader = ctx.get("loader");
|
|
21
|
+
if (host !== undefined || ctx.get("agentLoop") !== undefined || loader === undefined || ctx.fiber.entry !== undefined || [...ctx.loader.entries()].length > 0)
|
|
22
|
+
throw new Error("DSMM LLM composition must be installed exactly once before the Loader tree mounts");
|
|
23
|
+
const profile = ctx.get("profileContext");
|
|
24
|
+
if (profile === null || typeof profile !== "object" || !("overlays" in profile) || !Array.isArray(profile.overlays)
|
|
25
|
+
|| !profile.overlays.some((patch) => patch !== null && typeof patch === "object" && "insert" in patch && Array.isArray(patch.insert)
|
|
26
|
+
&& patch.insert.some((entry) => entry !== null && typeof entry === "object" && "id" in entry && "name" in entry && entry.id === options.provider.settingsNamespace && entry.name === `cordis:${builtin}`))) {
|
|
27
|
+
throw new Error("DSMM LLM startup patches must be included in the authoritative profileContext.overlays before readProfilePatches");
|
|
28
|
+
}
|
|
29
|
+
host = ctx;
|
|
30
|
+
const { createDsmmPiAiProviderPlugin } = await import("./native-pi-ai-wire.js");
|
|
31
|
+
ctx.loader.builtins[builtin] = { default: createDsmmPiAiProviderPlugin(options.provider, owner => { provider = owner; }) };
|
|
32
|
+
ctx.inject(dependencies, async (scope) => {
|
|
33
|
+
try {
|
|
34
|
+
if (scope.get("agentLoop") !== undefined || provider === undefined)
|
|
35
|
+
throw new Error("DSMM LLM cold ownership was not established before AgentLoop");
|
|
36
|
+
const integration = scope.get("dsmmRuntimeIntegration");
|
|
37
|
+
if (integration?.runtime.authority.view().deliveryFenceReady !== true)
|
|
38
|
+
throw new Error("DSMM admission guards are not ready");
|
|
39
|
+
const original = scope.llm;
|
|
40
|
+
const stock = Reflect.get(original, symbols.original) ?? original;
|
|
41
|
+
const isolated = scope.isolate("llm");
|
|
42
|
+
const owner = await (options.establish ?? createDsmmRoleLlmOwner)(isolated, provider);
|
|
43
|
+
const llm = new DsmmAwareLlmRuntime(isolated, stock, owner);
|
|
44
|
+
const loop = new AgentLoop(isolated, options.agentLoop);
|
|
45
|
+
mounted = Object.freeze({ loop, llm, provider });
|
|
46
|
+
scope.effect(() => () => { mounted = undefined; });
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
failure = error;
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
assertReady() {
|
|
55
|
+
if (failure !== undefined)
|
|
56
|
+
throw failure;
|
|
57
|
+
if (mounted === undefined) {
|
|
58
|
+
const missing = dependencies.filter(key => host?.get(key) === undefined);
|
|
59
|
+
throw new Error(`DSMM LLM cold startup is not ready; missing dependencies: ${missing.join(", ") || "provider or admission establishment"}`);
|
|
60
|
+
}
|
|
61
|
+
return mounted;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=host-llm-startup.js.map
|