@dsmm/dsmm 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cordis.patch.yml +9 -0
- package/docs/compatibility.md +10 -0
- package/docs/releasing.md +25 -65
- package/docs/roadmap.md +44 -2
- package/lib/client/ChildPermissions.d.ts +43 -0
- package/lib/client/ChildPermissions.js +100 -0
- package/lib/client/ChildrenPanel.d.ts +4 -1
- package/lib/client/ChildrenPanel.js +3 -3
- package/lib/client/DeploymentFields.d.ts +6 -2
- package/lib/client/DeploymentFields.js +8 -6
- package/lib/client/DeploymentPage.d.ts +4 -1
- package/lib/client/DeploymentPage.js +5 -4
- package/lib/client/HistoryContinuation.d.ts +7 -0
- package/lib/client/HistoryContinuation.js +22 -0
- package/lib/client/PermissionPanelEntry.d.ts +8 -0
- package/lib/client/PermissionPanelEntry.js +11 -0
- package/lib/client/PermissionsPanel.d.ts +3 -1
- package/lib/client/PermissionsPanel.js +3 -2
- package/lib/client/ProfilesSection.js +3 -3
- package/lib/client/RoleAvailability.js +1 -1
- package/lib/client/SessionProfiles.js +21 -18
- package/lib/client/TemporaryPermissions.d.ts +21 -0
- package/lib/client/TemporaryPermissions.js +94 -0
- package/lib/client/children-locales.d.ts +4 -4
- package/lib/client/controller.d.ts +17 -0
- package/lib/client/controller.js +101 -18
- package/lib/client/deployment-locales.js +26 -26
- package/lib/client/history-controller.d.ts +29 -0
- package/lib/client/history-controller.js +111 -0
- package/lib/client/history-entry.d.ts +11 -0
- package/lib/client/history-entry.js +106 -0
- package/lib/client/history-locales.d.ts +95 -0
- package/lib/client/history-locales.js +41 -0
- package/lib/client/index.js +16 -3
- package/lib/client/locales.d.ts +6 -0
- package/lib/client/locales.js +104 -92
- package/lib/client/permission-locales.d.ts +26 -0
- package/lib/client/permission-locales.js +55 -35
- package/lib/client/temporary-permission-client.d.ts +20 -0
- package/lib/client/temporary-permission-client.js +52 -0
- package/lib/client/temporary-permission-entry.d.ts +6 -0
- package/lib/client/temporary-permission-entry.js +56 -0
- package/lib/client.js +3881 -1981
- package/lib/history-candidates.d.ts +30 -0
- package/lib/history-candidates.js +176 -0
- package/lib/history-codec.d.ts +11 -0
- package/lib/history-codec.js +102 -0
- package/lib/history-contract.d.ts +44 -0
- package/lib/history-contract.js +2 -0
- package/lib/history-controller.d.ts +42 -0
- package/lib/history-controller.js +329 -0
- package/lib/history-policy.d.ts +4 -0
- package/lib/history-policy.js +8 -0
- package/lib/history-remote.d.ts +28 -0
- package/lib/history-remote.js +17 -0
- package/lib/history-rpc.d.ts +24 -0
- package/lib/history-rpc.js +136 -0
- package/lib/history-support.d.ts +15 -0
- package/lib/history-support.js +21 -0
- package/lib/history-types.d.ts +67 -0
- package/lib/history-types.js +2 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +24 -6
- package/lib/native-admission.d.ts +21 -0
- package/lib/native-admission.js +206 -16
- package/lib/permission-child-control.d.ts +36 -0
- package/lib/permission-child-control.js +164 -0
- package/lib/permission-control.d.ts +2 -0
- package/lib/permission-control.js +7 -0
- package/lib/permission-controller.js +2 -2
- package/lib/permission-exec-argv.d.ts +32 -0
- package/lib/permission-exec-argv.js +171 -0
- package/lib/permission-fs-search.js +2 -1
- package/lib/permission-fs.js +2 -1
- package/lib/permission-native-rules.js +3 -3
- package/lib/permission-temporary-files.d.ts +19 -0
- package/lib/permission-temporary-files.js +248 -0
- package/lib/permission-temporary-grants.d.ts +106 -0
- package/lib/permission-temporary-grants.js +198 -0
- package/lib/permission-temporary-install.d.ts +25 -0
- package/lib/permission-temporary-install.js +86 -0
- package/lib/permission-temporary-remote.d.ts +19 -0
- package/lib/permission-temporary-remote.js +75 -0
- package/lib/permission-temporary-rpc.d.ts +37 -0
- package/lib/permission-temporary-rpc.js +154 -0
- package/lib/permission-temporary-types.d.ts +47 -0
- package/lib/permission-temporary-types.js +2 -0
- package/lib/permission-temporary-web.d.ts +11 -0
- package/lib/permission-temporary-web.js +154 -0
- package/lib/permission-web.js +2 -1
- package/lib/preset-skills.d.ts +1 -1
- package/lib/preset-skills.js +2 -2
- package/lib/profile-rpc.js +2 -0
- package/lib/profile-runtime.d.ts +12 -1
- package/lib/profile-runtime.js +122 -10
- package/lib/profile-store.d.ts +2 -2
- package/lib/profile-store.js +8 -1
- package/lib/profile-types.d.ts +1 -0
- package/lib/role-invocation.d.ts +1 -1
- package/lib/role-invocation.js +2 -2
- package/lib/role-subagents.js +16 -3
- package/lib/skills.d.ts +1 -0
- package/lib/skills.js +5 -1
- package/package.json +41 -33
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-gateway@0.2.1-rc.2.patch +13291 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-remotes@0.2.1-rc.2.patch +9133 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-client-ui-approval@0.2.1-rc.2.patch +156 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-subagent@0.2.1-rc.2.patch +3546 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-user-approval@0.2.1-rc.2.patch +431 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-web@0.2.1-rc.2.patch +119 -0
- package/patches/dsh-approval-settlement/README.md +41 -0
- package/patches/dsh-approval-settlement/metadata.json +10 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-loop@0.2.1-rc.2.patch +383 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-preset-registry@0.2.1-rc.2.patch +55 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-api-session-controller@0.2.1-rc.2.patch +16673 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-subagent@0.2.1-rc.2.patch +29 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-workspace@0.2.1-rc.2.patch +196 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence-jsonl@0.2.1-rc.2.patch +35 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence@0.2.1-rc.2.patch +40 -0
package/lib/index.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ export type { DsmmLlmAdmission, DsmmLlmCallConfig, DsmmLlmHostOwner, DsmmLlmGene
|
|
|
38
38
|
export { registerRuntimeRecovery } from "./runtime-recovery.js";
|
|
39
39
|
export { classifyRecoveryFailure, foldAttemptedRecoveryRoutes, foldDurableRecoveryWork, selectFallbackRoute } from "./recovery-policy.js";
|
|
40
40
|
export type { DurableRecoveryWork, RecoveryFailureDecision } from "./recovery-policy.js";
|
|
41
|
+
export { DSMM_HISTORY_HOST_CONFIG } from "./history-support.js";
|
|
42
|
+
export { HISTORY_REMOTE } from "./history-remote.js";
|
|
41
43
|
export declare function createDsmmHostPlugin(startup: DsmmHostStartupOptions): {
|
|
42
44
|
name: string;
|
|
43
45
|
Config: import("@deepseek-ai/schemastery").default<import("./settings.js").DsmmPluginConfig>;
|
package/lib/index.js
CHANGED
|
@@ -22,6 +22,10 @@ import { registerRoleControlRpc } from "./role-control-rpc.js";
|
|
|
22
22
|
import { nativeStandingFullAccess } from "./permission-native-access.js";
|
|
23
23
|
import { DsmmProfileError } from "./profiles.js";
|
|
24
24
|
import { registerLspRuntime } from "./lsp.js";
|
|
25
|
+
import { DsmmHistoryCandidates } from "./history-candidates.js";
|
|
26
|
+
import { registerHistoryContinuationRpc } from "./history-rpc.js";
|
|
27
|
+
import { requireHistoryAdmission } from "./history-support.js";
|
|
28
|
+
import { installTemporaryPermissions } from "./permission-temporary-install.js";
|
|
25
29
|
export const name = "dsmm";
|
|
26
30
|
export const inject = ["profileContext", "agents"];
|
|
27
31
|
export const Config = new Proxy(DSMM_NATIVE_CONFIG_SCHEMA, { apply(_target, _receiver, args) { return DSMM_CONFIG_SCHEMA(args[0] ?? {}); } });
|
|
@@ -45,6 +49,8 @@ export { DEEPWORK_MODE_EVENT, DeepworkModeController, hasOpenTurn, isDeepworkAct
|
|
|
45
49
|
export { DsmmNativeLlmRuntime } from "./llm-runtime.js";
|
|
46
50
|
export { registerRuntimeRecovery } from "./runtime-recovery.js";
|
|
47
51
|
export { classifyRecoveryFailure, foldAttemptedRecoveryRoutes, foldDurableRecoveryWork, selectFallbackRoute } from "./recovery-policy.js";
|
|
52
|
+
export { DSMM_HISTORY_HOST_CONFIG } from "./history-support.js";
|
|
53
|
+
export { HISTORY_REMOTE } from "./history-remote.js";
|
|
48
54
|
export function createDsmmHostPlugin(startup) {
|
|
49
55
|
assertSupportedHostStartup(startup);
|
|
50
56
|
return { name, Config, inject, apply(ctx, config = {}) { return apply(ctx, config, startup); } };
|
|
@@ -54,6 +60,7 @@ export async function apply(input, config = {}, startupOptions = {}) {
|
|
|
54
60
|
if (!Context.is(input))
|
|
55
61
|
throw new Error("DSMM requires the native Cordis Host");
|
|
56
62
|
const ctx = input;
|
|
63
|
+
requireHistoryAdmission(ctx);
|
|
57
64
|
const deployment = new DsmmDeploymentConfig(ctx, config);
|
|
58
65
|
const lifetime = new AbortController();
|
|
59
66
|
scopeLifetime(ctx, "dsmm: retire Core", () => lifetime.abort());
|
|
@@ -134,22 +141,22 @@ export async function apply(input, config = {}, startupOptions = {}) {
|
|
|
134
141
|
await registerLspRuntime(ctx, startup.settings.lsp, getSettings);
|
|
135
142
|
lifetime.signal.throwIfAborted();
|
|
136
143
|
const installed = new WeakSet();
|
|
137
|
-
admission.activate(async (agent, candidate) => {
|
|
144
|
+
admission.activate(async (agent, candidate, phase) => {
|
|
138
145
|
candidate.subagentRuntime = () => runtimeAdmissionView(ctx);
|
|
139
146
|
const scope = agent.ctx;
|
|
140
|
-
if (
|
|
141
|
-
registerAgentSkills(scope, controller, candidate, agent, admission.lifetime.signal);
|
|
147
|
+
if (startup.settings.modules.deepwork.enabled) {
|
|
148
|
+
registerAgentSkills(scope, controller, candidate, agent, admission.lifetime.signal, () => !nativeAdmission.isSelecting(agent));
|
|
142
149
|
registerDeepworkPrompt(scope, controller, candidate, { section: startup.profile.section ?? startup.global.section }, agent, admission.lifetime.signal);
|
|
143
150
|
}
|
|
144
151
|
if (installed.has(agent)) {
|
|
145
|
-
if (
|
|
152
|
+
if (phase !== "history-setup" && startup.settings.modules.deepwork.enabled && ctx.get("subagents") !== undefined)
|
|
146
153
|
await registerHeadlessRoleTools(scope, controller, candidate, policy, nativeAdmission, agent);
|
|
147
154
|
return;
|
|
148
155
|
}
|
|
149
156
|
registerModelRouting(scope, controller, candidate);
|
|
150
157
|
registerSafetyGuards(scope, controller, candidate, policy);
|
|
151
|
-
if (
|
|
152
|
-
if (ctx.get("subagents") !== undefined)
|
|
158
|
+
if (startup.settings.modules.deepwork.enabled) {
|
|
159
|
+
if (phase !== "history-setup" && ctx.get("subagents") !== undefined)
|
|
153
160
|
await registerHeadlessRoleTools(scope, controller, candidate, policy, nativeAdmission, agent);
|
|
154
161
|
}
|
|
155
162
|
installed.add(agent);
|
|
@@ -161,8 +168,19 @@ export async function apply(input, config = {}, startupOptions = {}) {
|
|
|
161
168
|
});
|
|
162
169
|
ctx.inject(["typert"], scope => { registerConfigRpc(scope, deployment, startup.settings, () => profiles, startup.sources, mountedPermission); new DsmmProfilesHost(scope, profiles); registerRoleControlRpc(scope, nativeAdmission); });
|
|
163
170
|
const permissions = createCorePermissionAuthority(ctx, { getSettings, rolePolicy: policy, signal: lifetime.signal });
|
|
171
|
+
const history = ctx.inject(["typert", "agentLoop", "sessionController", "sessionPersistence", "agentPresets"], function mountHistoryContinuation(scope) {
|
|
172
|
+
registerHistoryContinuationRpc(scope, new DsmmHistoryCandidates(scope, profiles, deployment, nativeAdmission), nativeAdmission);
|
|
173
|
+
});
|
|
174
|
+
if (["typert", "agentLoop", "sessionController", "sessionPersistence", "agentPresets"].every(key => ctx.get(key)))
|
|
175
|
+
await history.await();
|
|
164
176
|
const installPermissions = () => ctx.inject(["tools", ...(ctx.fiber.entry === undefined ? [] : ["settings"])], scope => {
|
|
165
177
|
const installed = installCorePermissions(scope, deployment, permissions.authority, permissions.assertWritable);
|
|
178
|
+
scope.inject(["approval", "typertGateway", "typert", "subagents"], temporaryScope => {
|
|
179
|
+
if (typeof temporaryScope.approval.settlement !== "function" || typeof temporaryScope.typertGateway.registerApprovalPermits !== "function")
|
|
180
|
+
return;
|
|
181
|
+
const temporary = installTemporaryPermissions(temporaryScope, { core: permissions, roles: policy, rules: installed.rules });
|
|
182
|
+
temporaryScope.effect(() => () => temporary.dispose(), "dsmm: temporary permissions");
|
|
183
|
+
});
|
|
166
184
|
const identity = Reflect.get(installed, symbols.original) ?? installed;
|
|
167
185
|
scopeLifetime(scope, "dsmm: release permission projection", () => { if (permissionOwner === identity)
|
|
168
186
|
permissionOwner = undefined; }, () => { permissionOwner = identity; });
|
|
@@ -7,6 +7,7 @@ import type { DsmmProfileRuntime } from "./profile-runtime.js";
|
|
|
7
7
|
import type { DsmmProfileAdmission } from "./settings.js";
|
|
8
8
|
import type { ResolvedRoleInvocation } from "./role-invocation.js";
|
|
9
9
|
import type { DsmmRolePolicy } from "./role-policy.js";
|
|
10
|
+
import type { SessionActionUnavailableReason } from "./profile-types.js";
|
|
10
11
|
declare module "@deepseek-ai/cordis" {
|
|
11
12
|
interface Context {
|
|
12
13
|
dsmmNativeAdmission: NativeAdmission;
|
|
@@ -21,6 +22,7 @@ export declare class NativeAdmission {
|
|
|
21
22
|
private readonly pending;
|
|
22
23
|
private readonly live;
|
|
23
24
|
private readonly candidates;
|
|
25
|
+
private readonly historyPrepared;
|
|
24
26
|
private readonly agents;
|
|
25
27
|
private readonly activations;
|
|
26
28
|
private readonly activities;
|
|
@@ -29,16 +31,35 @@ export declare class NativeAdmission {
|
|
|
29
31
|
private readonly guardedTools;
|
|
30
32
|
private readonly agentLifetimes;
|
|
31
33
|
private readonly retirements;
|
|
34
|
+
private readonly installing;
|
|
35
|
+
private readonly selecting;
|
|
36
|
+
private readonly failedInstallations;
|
|
37
|
+
private readonly blankUpdates;
|
|
38
|
+
private readonly getters;
|
|
39
|
+
private readonly executions;
|
|
32
40
|
private ready;
|
|
33
41
|
private install?;
|
|
34
42
|
constructor(ctx: Context, profiles: DsmmProfileRuntime, policy: DsmmRolePolicy);
|
|
35
43
|
activate(install: NonNullable<NativeAdmission["install"]>): void;
|
|
36
44
|
get isReady(): boolean;
|
|
45
|
+
/** Install the current configuration before publication, without enrolling a historical Agent as blank. */
|
|
46
|
+
prepareHistory(agent: Agent, admission: DsmmProfileAdmission, signal: AbortSignal): Promise<void>;
|
|
47
|
+
isSelecting(agent: Agent): boolean;
|
|
37
48
|
get(agent: Agent): DsmmProfileAdmission | undefined;
|
|
38
49
|
configuration(agent: Agent): DsmmProfileAdmission;
|
|
50
|
+
private getter;
|
|
51
|
+
private dependencies;
|
|
39
52
|
invocation(agent: Agent): ResolvedRoleInvocation | undefined;
|
|
40
53
|
ensure(agent: Agent): Promise<DsmmProfileAdmission>;
|
|
41
54
|
assert(agent: Agent): DsmmProfileAdmission;
|
|
55
|
+
blankReason(agent: Agent, allowQueued?: boolean): SessionActionUnavailableReason | undefined;
|
|
56
|
+
/** Reserved by runMaintenance; newly queued input belongs to the accepted choice. */
|
|
57
|
+
beginBlank(agent: Agent, signal: AbortSignal, assertAuthority: () => void): {
|
|
58
|
+
assertCurrent(): void;
|
|
59
|
+
prepare(admission: DsmmProfileAdmission, describe: () => void): Promise<void>;
|
|
60
|
+
committed(): void;
|
|
61
|
+
close(): Promise<void>;
|
|
62
|
+
};
|
|
42
63
|
reserve(exec: Readonly<ToolExecution>, invocation: ResolvedRoleInvocation, provider: SubagentProvider, maxDepth?: number): Promise<{
|
|
43
64
|
childId: SessionId;
|
|
44
65
|
release(): Promise<void>;
|
package/lib/native-admission.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
3
|
import { getTraceable, symbols } from "@deepseek-ai/cordis";
|
|
3
4
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
4
5
|
import { SubagentError, delegationDepthOf } from "@deepseek-ai/dsh-subagent";
|
|
@@ -6,6 +7,10 @@ import { freezeSettings } from "./settings.js";
|
|
|
6
7
|
import { scopeLifetime } from "./lifetime.js";
|
|
7
8
|
import { sessionEvents } from "./session-scope.js";
|
|
8
9
|
import { scopeParentOf } from "./native-scope.js";
|
|
10
|
+
import { DsmmProfileError } from "./profiles.js";
|
|
11
|
+
import { roleProviderName } from "./roles.js";
|
|
12
|
+
import { resolveRoleInvocation } from "./role-invocation.js";
|
|
13
|
+
import { resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
9
14
|
/** Short-lived creation correlations and exact live bindings, never an execution queue. */
|
|
10
15
|
export class NativeAdmission {
|
|
11
16
|
ctx;
|
|
@@ -15,6 +20,7 @@ export class NativeAdmission {
|
|
|
15
20
|
pending = new Map();
|
|
16
21
|
live = new WeakMap();
|
|
17
22
|
candidates = new WeakMap();
|
|
23
|
+
historyPrepared = new WeakMap();
|
|
18
24
|
agents = new Set();
|
|
19
25
|
activations = new Set();
|
|
20
26
|
activities = new Map();
|
|
@@ -23,6 +29,12 @@ export class NativeAdmission {
|
|
|
23
29
|
guardedTools = new WeakMap();
|
|
24
30
|
agentLifetimes = new WeakMap();
|
|
25
31
|
retirements = new WeakMap();
|
|
32
|
+
installing = new AsyncLocalStorage();
|
|
33
|
+
selecting = new WeakSet();
|
|
34
|
+
failedInstallations = new WeakSet();
|
|
35
|
+
blankUpdates = new WeakMap();
|
|
36
|
+
getters = new WeakMap();
|
|
37
|
+
executions = new WeakMap();
|
|
26
38
|
ready = false;
|
|
27
39
|
install;
|
|
28
40
|
constructor(ctx, profiles, policy) {
|
|
@@ -59,6 +71,17 @@ export class NativeAdmission {
|
|
|
59
71
|
ctx.on("agent/request", async (frame, next) => { await this.ensure(frame.agent); return next(); }, { global: true, prepend: true });
|
|
60
72
|
ctx.on("tools/execute", async (exec, next) => { if (exec.agent)
|
|
61
73
|
await this.ensure(exec.agent); return policy.duringToolExecution(exec, next); }, { global: true, prepend: true });
|
|
74
|
+
ctx.on("tools/pre-execute", async (exec, next) => {
|
|
75
|
+
if (exec.agent) {
|
|
76
|
+
const active = this.executions.get(exec.agent) ?? new Set();
|
|
77
|
+
active.add(exec.token);
|
|
78
|
+
this.executions.set(exec.agent, active);
|
|
79
|
+
await this.ensure(exec.agent);
|
|
80
|
+
}
|
|
81
|
+
return next();
|
|
82
|
+
}, { global: true, prepend: true });
|
|
83
|
+
ctx.on("tools/result", exec => { if (exec.agent)
|
|
84
|
+
this.executions.get(exec.agent)?.delete(exec.token); }, { global: true });
|
|
62
85
|
ctx.on("agent-preset/selected", id => {
|
|
63
86
|
const agent = ctx.agents.get(id);
|
|
64
87
|
if (!agent || !this.live.has(agent))
|
|
@@ -70,15 +93,63 @@ export class NativeAdmission {
|
|
|
70
93
|
}
|
|
71
94
|
activate(install) { this.lifetime.signal.throwIfAborted(); this.install = install; this.ready = true; }
|
|
72
95
|
get isReady() { return this.ready && !this.lifetime.signal.aborted; }
|
|
96
|
+
/** Install the current configuration before publication, without enrolling a historical Agent as blank. */
|
|
97
|
+
async prepareHistory(agent, admission, signal) {
|
|
98
|
+
const check = () => {
|
|
99
|
+
signal.throwIfAborted();
|
|
100
|
+
this.lifetime.signal.throwIfAborted();
|
|
101
|
+
if (!this.isReady || !this.install || this.ctx.agents.get(agent.id) !== undefined || agent.session.header.origin === "subagent"
|
|
102
|
+
|| this.ctx.get("dsmmHistoryContinuation")?.admissionForCreated(agent) !== admission)
|
|
103
|
+
throw new SubagentError("Exact unpublished history candidate required", "UNAUTHORIZED");
|
|
104
|
+
};
|
|
105
|
+
check();
|
|
106
|
+
const prepared = { admission, preset: agent.ctx.get("agentPresets")?.composedPreset(agent.ctx), scopeParent: scopeParentOf(agent), dependencies: this.dependencies(agent) };
|
|
107
|
+
if (prepared.dependencies.some(value => value === undefined))
|
|
108
|
+
throw new SubagentError("History composition is unavailable", "UNAUTHORIZED");
|
|
109
|
+
this.candidates.set(agent, admission);
|
|
110
|
+
scopeLifetime(agent.ctx, "dsmm: release unpublished history configuration", () => { this.historyPrepared.delete(agent); this.candidates.delete(agent); });
|
|
111
|
+
this.guardTools(agent);
|
|
112
|
+
await this.install(agent, this.getter(agent), "history-setup");
|
|
113
|
+
check();
|
|
114
|
+
if (prepared.dependencies.some((value, index) => value !== this.dependencies(agent)[index]) || prepared.scopeParent !== scopeParentOf(agent))
|
|
115
|
+
throw new SubagentError("History composition changed during setup", "UNAUTHORIZED");
|
|
116
|
+
this.historyPrepared.set(agent, prepared);
|
|
117
|
+
}
|
|
118
|
+
isSelecting(agent) { return this.selecting.has(agent); }
|
|
73
119
|
get(agent) { return this.live.get(agent)?.admission; }
|
|
74
|
-
configuration(agent) {
|
|
75
|
-
|
|
120
|
+
configuration(agent) {
|
|
121
|
+
const preview = this.installing.getStore();
|
|
122
|
+
const value = preview?.agent === agent ? preview.admission : this.candidates.get(agent) ?? this.get(agent);
|
|
123
|
+
if (!value)
|
|
124
|
+
throw new SubagentError("No trusted live admission", "UNAUTHORIZED");
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
getter(agent) {
|
|
128
|
+
let getter = this.getters.get(agent);
|
|
129
|
+
if (getter === undefined) {
|
|
130
|
+
getter = () => this.configuration(agent).settings;
|
|
131
|
+
getter.admission = () => this.configuration(agent);
|
|
132
|
+
this.getters.set(agent, getter);
|
|
133
|
+
}
|
|
134
|
+
return getter;
|
|
135
|
+
}
|
|
136
|
+
dependencies(agent) {
|
|
137
|
+
const presets = agent.ctx.get("agentPresets");
|
|
138
|
+
return [presets, agent.ctx.get("subagents"), agent.ctx.get("llm"),
|
|
139
|
+
presets?.serviceFor(agent, "tools") ?? agent.ctx.get("tools"),
|
|
140
|
+
presets?.serviceFor(agent, "systemPrompt") ?? agent.ctx.get("systemPrompt"),
|
|
141
|
+
presets?.serviceFor(agent, "skills") ?? agent.ctx.get("skills")].map(service => service === undefined ? undefined : original(service));
|
|
142
|
+
}
|
|
76
143
|
invocation(agent) { return this.live.get(agent)?.invocation; }
|
|
77
144
|
async ensure(agent) { await this.rebindings.get(agent); return this.assert(agent); }
|
|
78
145
|
assert(agent) {
|
|
79
146
|
this.lifetime.signal.throwIfAborted();
|
|
80
147
|
this.agentLifetimes.get(agent)?.signal.throwIfAborted();
|
|
81
148
|
const live = this.live.get(agent);
|
|
149
|
+
if (this.failedInstallations.has(agent))
|
|
150
|
+
throw new SubagentError("Session configuration restoration failed; create a new session", "UNAUTHORIZED");
|
|
151
|
+
if (this.selecting.has(agent))
|
|
152
|
+
throw new SubagentError("Session configuration maintenance is in progress", "UNAUTHORIZED");
|
|
82
153
|
if (!this.ready || !live || this.ctx.agents.get(agent.id) !== agent)
|
|
83
154
|
throw new SubagentError("No trusted live admission; create a new session", "UNAUTHORIZED");
|
|
84
155
|
if (live.preset !== agent.ctx.get("agentPresets")?.composedPreset(agent.ctx) || live.scopeParent !== scopeParentOf(agent))
|
|
@@ -90,6 +161,112 @@ export class NativeAdmission {
|
|
|
90
161
|
this.policy.assertModuleAdmission(agent);
|
|
91
162
|
return live.admission;
|
|
92
163
|
}
|
|
164
|
+
blankReason(agent, allowQueued = false) {
|
|
165
|
+
if (!this.isReady || this.failedInstallations.has(agent) || this.ctx.agents.get(agent.id) !== agent || !this.ctx.agents.roots().includes(agent) || this.dependencies(agent).some(value => value === undefined))
|
|
166
|
+
return "runtime-unavailable";
|
|
167
|
+
const live = this.live.get(agent);
|
|
168
|
+
if (!live || live.parent || agent.session.header.origin === "subagent" || agent.session.header.isSeeded
|
|
169
|
+
|| sessionEvents(agent.session).some(event => ["turn/start", "step/start", "request/header", "assistant/message", "tool/call"].includes(event.type)))
|
|
170
|
+
return "new-session-required";
|
|
171
|
+
if (agent.status !== "idle" || (this.calls.get(agent) ?? 0) !== 0 || (this.executions.get(agent)?.size ?? 0) !== 0 || [...this.pending.values()].some(row => row.parent === agent)
|
|
172
|
+
|| this.ctx.agents.list().some(child => this.ctx.agents.isOwnedBy(child.id, agent))
|
|
173
|
+
|| this.selecting.has(agent) && !allowQueued
|
|
174
|
+
|| !allowQueued && (agent.inbox.nextTurn.length !== 0 || agent.inbox.nextStep.length !== 0))
|
|
175
|
+
return "busy";
|
|
176
|
+
if (agent.runMaintenance === undefined)
|
|
177
|
+
return "maintenance";
|
|
178
|
+
if (live.preset !== agent.ctx.get("agentPresets")?.composedPreset(agent.ctx) || live.scopeParent !== scopeParentOf(agent)
|
|
179
|
+
|| this.agentLifetimes.get(agent)?.signal.aborted)
|
|
180
|
+
return "runtime-unavailable";
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
/** Reserved by runMaintenance; newly queued input belongs to the accepted choice. */
|
|
184
|
+
beginBlank(agent, signal, assertAuthority) {
|
|
185
|
+
const reason = this.blankReason(agent);
|
|
186
|
+
if (reason !== undefined)
|
|
187
|
+
throw new DsmmProfileError(reason === "busy" ? "busy" : "unavailable", "Only an unstarted live session can select its configuration.");
|
|
188
|
+
const previous = this.live.get(agent);
|
|
189
|
+
this.assert(agent);
|
|
190
|
+
const captured = this.dependencies(agent);
|
|
191
|
+
const preparationSignal = AbortSignal.any([signal, this.lifetime.signal, this.agentLifetimes.get(agent).signal]);
|
|
192
|
+
this.selecting.add(agent);
|
|
193
|
+
let finish;
|
|
194
|
+
const completion = new Promise(resolve => { finish = resolve; });
|
|
195
|
+
this.blankUpdates.set(agent, completion);
|
|
196
|
+
let prepared = false, committed = false;
|
|
197
|
+
let publication;
|
|
198
|
+
let providers = new Map();
|
|
199
|
+
const assertCurrent = () => {
|
|
200
|
+
assertAuthority();
|
|
201
|
+
preparationSignal.throwIfAborted();
|
|
202
|
+
if (this.live.get(agent) !== previous || this.blankReason(agent, true) !== undefined || this.dependencies(agent).some((value, index) => value !== captured[index])) {
|
|
203
|
+
throw new DsmmProfileError("conflict", "The session owner or composition changed before configuration commit.");
|
|
204
|
+
}
|
|
205
|
+
for (const [name, expected] of providers) {
|
|
206
|
+
const current = agent.ctx.get("subagents")?.getProvider(name);
|
|
207
|
+
if (current === undefined || original(current) !== original(expected) || current.capabilities.depthLimit !== true) {
|
|
208
|
+
throw new DsmmProfileError("conflict", "A required native provider changed before configuration commit.");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
const install = (admission) => this.installing.run({ agent, admission }, () => this.install(agent, this.getter(agent)));
|
|
213
|
+
return {
|
|
214
|
+
assertCurrent,
|
|
215
|
+
prepare: async (admission, describe) => {
|
|
216
|
+
assertCurrent();
|
|
217
|
+
this.policy.validateRootRole(agent, admission);
|
|
218
|
+
await this.installing.run({ agent, admission }, async () => {
|
|
219
|
+
const targets = this.policy.targets(agent);
|
|
220
|
+
providers = new Map([...targets.map(roleProviderName), ...targets.length === 0 ? [] : ["spawn"]].map(name => {
|
|
221
|
+
const provider = agent.ctx.get("subagents")?.getProvider(name);
|
|
222
|
+
if (provider?.capabilities.depthLimit !== true)
|
|
223
|
+
throw new DsmmProfileError("activation", "An enabled role has no admitted native provider.");
|
|
224
|
+
return [name, provider];
|
|
225
|
+
}));
|
|
226
|
+
for (const role of targets) {
|
|
227
|
+
const preset = await agent.ctx.get("agentPresets").resolve(role);
|
|
228
|
+
assertCurrent();
|
|
229
|
+
if (preset.broken !== undefined)
|
|
230
|
+
throw new DsmmProfileError("activation", "An enabled role preset is unavailable.", role);
|
|
231
|
+
const routing = admission.settings.roleRouting[role];
|
|
232
|
+
if (routing?.primary !== undefined || routing?.fallbackRoutes !== undefined) {
|
|
233
|
+
await resolveRoleInvocation(agent, role, admission.settings, preparationSignal, {}, undefined, resolvedModelParameterPolicy(admission));
|
|
234
|
+
assertCurrent();
|
|
235
|
+
}
|
|
236
|
+
for (const level of ["low", "high", "max"])
|
|
237
|
+
if (routing?.levels?.[level] !== undefined) {
|
|
238
|
+
await resolveRoleInvocation(agent, role, admission.settings, preparationSignal, { level }, undefined, resolvedModelParameterPolicy(admission));
|
|
239
|
+
assertCurrent();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
assertCurrent();
|
|
244
|
+
prepared = true;
|
|
245
|
+
await install(admission);
|
|
246
|
+
assertCurrent();
|
|
247
|
+
this.installing.run({ agent, admission }, describe);
|
|
248
|
+
publication = Object.freeze({ ...previous, admission });
|
|
249
|
+
},
|
|
250
|
+
committed: () => { this.live.set(agent, publication); committed = true; },
|
|
251
|
+
close: async () => {
|
|
252
|
+
try {
|
|
253
|
+
if (prepared && !committed && this.ctx.agents.get(agent.id) === agent && !this.lifetime.signal.aborted)
|
|
254
|
+
await install(previous.admission);
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
this.failedInstallations.add(agent);
|
|
258
|
+
const refusal = new DsmmProfileError("activation", "Session configuration restoration failed. Execution is disabled; create a new session.");
|
|
259
|
+
refusal.cause = error;
|
|
260
|
+
throw refusal;
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
this.selecting.delete(agent);
|
|
264
|
+
this.blankUpdates.delete(agent);
|
|
265
|
+
finish();
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}
|
|
93
270
|
async reserve(exec, invocation, provider, maxDepth) {
|
|
94
271
|
const parent = exec.agent;
|
|
95
272
|
if (!parent)
|
|
@@ -199,19 +376,22 @@ export class NativeAdmission {
|
|
|
199
376
|
return settled;
|
|
200
377
|
}
|
|
201
378
|
async rebindBlank(agent) {
|
|
202
|
-
|
|
379
|
+
await this.blankUpdates.get(agent);
|
|
203
380
|
this.lifetime.signal.throwIfAborted();
|
|
381
|
+
const previous = this.live.get(agent);
|
|
382
|
+
if (previous === undefined)
|
|
383
|
+
throw new SubagentError("The blank Agent owner was retired", "UNAUTHORIZED");
|
|
204
384
|
if (previous.preset === agent.ctx.get("agentPresets")?.composedPreset(agent.ctx) && previous.scopeParent === scopeParentOf(agent))
|
|
205
385
|
return;
|
|
386
|
+
if (this.selecting.has(agent))
|
|
387
|
+
throw new SubagentError("Session configuration maintenance owns the blank composition", "UNAUTHORIZED");
|
|
206
388
|
if (previous.parent || (this.calls.get(agent) ?? 0) !== 0 || [...this.pending.values()].some(row => row.parent === agent)
|
|
207
389
|
|| this.ctx.agents.list().some(child => this.ctx.agents.isOwnedBy(child.id, agent)) || sessionEvents(agent.session).some(event => event.type === "turn/start"))
|
|
208
390
|
throw new SubagentError("Preset change requires a new session", "UNAUTHORIZED");
|
|
209
391
|
this.policy.validateRootRole(agent, previous.admission);
|
|
210
392
|
const preset = agent.ctx.get("agentPresets")?.composedPreset(agent.ctx), scopeParent = scopeParentOf(agent);
|
|
211
|
-
const getter = () => previous.admission.settings;
|
|
212
|
-
getter.admission = () => previous.admission;
|
|
213
393
|
this.guardTools(agent);
|
|
214
|
-
await this.install(agent, getter);
|
|
394
|
+
await this.install(agent, this.getter(agent));
|
|
215
395
|
this.lifetime.signal.throwIfAborted();
|
|
216
396
|
this.agentLifetimes.get(agent).signal.throwIfAborted();
|
|
217
397
|
if (this.ctx.agents.get(agent.id) !== agent || this.live.get(agent) !== previous || scopeParentOf(agent) !== scopeParent)
|
|
@@ -254,13 +434,24 @@ export class NativeAdmission {
|
|
|
254
434
|
else {
|
|
255
435
|
if (agent.session.header.origin === "subagent" || pending)
|
|
256
436
|
throw new SubagentError("Missing exact parent", "UNAUTHORIZED");
|
|
257
|
-
|
|
258
|
-
if (
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
437
|
+
const history = source === "resume" ? this.ctx.get("dsmmHistoryContinuation")?.admissionForCreated(agent) : undefined;
|
|
438
|
+
if (source === "resume") {
|
|
439
|
+
const prepared = this.historyPrepared.get(agent);
|
|
440
|
+
if (!history || prepared?.admission !== history || prepared.preset !== preset || prepared.scopeParent !== presetScope
|
|
441
|
+
|| prepared.dependencies.some((value, index) => value !== this.dependencies(agent)[index]))
|
|
442
|
+
throw new SubagentError("History resume requires its exact prepared candidate", "UNAUTHORIZED");
|
|
443
|
+
admission = history;
|
|
444
|
+
this.policy.validateRootRole(agent, admission);
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
// A resume may have opened the native log, but cannot recover DSMM authorization.
|
|
448
|
+
if ((source !== "startup" || agent.session.header.isSeeded) && (preset?.startsWith("dsmm-") || sessionEvents(agent.session).some(event => ["deepwork/mode", "dsmm/role-policy"].includes(event.type))))
|
|
449
|
+
throw new SubagentError("DSMM cold recovery is unavailable", "UNAUTHORIZED");
|
|
450
|
+
admission = await this.profiles.prepareRoot(agent, signal);
|
|
451
|
+
this.policy.validateRootRole(agent, admission);
|
|
452
|
+
if ((source !== "startup" || agent.session.header.isSeeded) && admission.settings.defaultActive)
|
|
453
|
+
throw new SubagentError("Historical sessions are not automatically admitted to Deepwork", "UNAUTHORIZED");
|
|
454
|
+
}
|
|
264
455
|
}
|
|
265
456
|
this.agentLifetimes.set(agent, new AbortController());
|
|
266
457
|
scopeLifetime(agent.ctx, "dsmm: retire exact Agent work", () => { void this.retireAgent(agent).catch(() => { }); });
|
|
@@ -282,9 +473,7 @@ export class NativeAdmission {
|
|
|
282
473
|
try {
|
|
283
474
|
if (pending)
|
|
284
475
|
this.policy.bindChild(agent, parent, admission, pending.invocation, pending.maxDepth, pending.toolFilter);
|
|
285
|
-
|
|
286
|
-
getter.admission = () => admission;
|
|
287
|
-
await this.install(agent, getter);
|
|
476
|
+
await this.install(agent, this.getter(agent));
|
|
288
477
|
signal.throwIfAborted();
|
|
289
478
|
this.agentLifetimes.get(agent).signal.throwIfAborted();
|
|
290
479
|
if (pending)
|
|
@@ -306,6 +495,7 @@ export class NativeAdmission {
|
|
|
306
495
|
}
|
|
307
496
|
finally {
|
|
308
497
|
this.candidates.delete(agent);
|
|
498
|
+
this.historyPrepared.delete(agent);
|
|
309
499
|
}
|
|
310
500
|
}
|
|
311
501
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
import type { TemporaryPermissionGrants } from "./permission-temporary-grants.js";
|
|
4
|
+
import type { ChildPermissionView } from "./permission-temporary-types.js";
|
|
5
|
+
interface ChildScope {
|
|
6
|
+
readonly role?: string;
|
|
7
|
+
readonly readOnly: boolean;
|
|
8
|
+
check(): void;
|
|
9
|
+
}
|
|
10
|
+
export interface ChildPermissionOptions {
|
|
11
|
+
capture(parent: Agent, child: Agent): ChildScope;
|
|
12
|
+
refresh(): Promise<unknown>;
|
|
13
|
+
}
|
|
14
|
+
/** A live operator policy transition, separate from the immutable native creation fact. */
|
|
15
|
+
export declare class ChildPermissionControl {
|
|
16
|
+
private readonly ctx;
|
|
17
|
+
private readonly grants;
|
|
18
|
+
private readonly options;
|
|
19
|
+
private readonly operators;
|
|
20
|
+
private readonly transitions;
|
|
21
|
+
private readonly lifetime;
|
|
22
|
+
constructor(ctx: Context, grants: TemporaryPermissionGrants, options: ChildPermissionOptions);
|
|
23
|
+
private live;
|
|
24
|
+
private operator;
|
|
25
|
+
assertEnabled(child: Agent): void;
|
|
26
|
+
authorizeChild(_peer: object, child: Agent): {
|
|
27
|
+
assertCurrent(): void;
|
|
28
|
+
};
|
|
29
|
+
describe(parent: Agent, child: Agent): ChildPermissionView;
|
|
30
|
+
private change;
|
|
31
|
+
enable(parent: Agent, child: Agent, checkOperator: () => void): Promise<ChildPermissionView>;
|
|
32
|
+
revoke(parent: Agent, child: Agent, checkOperator: () => void): Promise<ChildPermissionView>;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=permission-child-control.d.ts.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { SubagentRuntime } from "@deepseek-ai/dsh-subagent";
|
|
2
|
+
import { ApprovalService } from "@deepseek-ai/dsh-user-approval";
|
|
3
|
+
import { SessionSeq } from "@deepseek-ai/dsh-session";
|
|
4
|
+
import { PermissionRefusal, permissionApprovalAdapter, permissionOriginal } from "./permission-control.js";
|
|
5
|
+
function latestPolicy(agent) {
|
|
6
|
+
for (let seq = agent.session.seq - 1; seq >= 0; seq--) {
|
|
7
|
+
const event = agent.session.eventAt(SessionSeq(seq));
|
|
8
|
+
if (event?.type === "approval/policy")
|
|
9
|
+
return event;
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
/** A live operator policy transition, separate from the immutable native creation fact. */
|
|
14
|
+
export class ChildPermissionControl {
|
|
15
|
+
ctx;
|
|
16
|
+
grants;
|
|
17
|
+
options;
|
|
18
|
+
operators = new Map();
|
|
19
|
+
transitions = new WeakMap();
|
|
20
|
+
lifetime = new AbortController();
|
|
21
|
+
constructor(ctx, grants, options) {
|
|
22
|
+
this.ctx = ctx;
|
|
23
|
+
this.grants = grants;
|
|
24
|
+
this.options = options;
|
|
25
|
+
const guard = ctx.on("approval/request", permissionApprovalAdapter(ctx, (request, next) => {
|
|
26
|
+
const agent = request.agent, agents = ctx.get("agents");
|
|
27
|
+
if (agents?.roots().includes(agent) && agent.session.header.origin !== "subagent")
|
|
28
|
+
return next();
|
|
29
|
+
try {
|
|
30
|
+
this.assertEnabled(agent);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return Promise.resolve("unavailable");
|
|
34
|
+
}
|
|
35
|
+
return next();
|
|
36
|
+
}), { prepend: true, global: true });
|
|
37
|
+
const disposed = ctx.on("agent/disposed", ({ agent }) => {
|
|
38
|
+
for (const [child, authority] of this.operators)
|
|
39
|
+
if (child === agent || authority.parent === agent) {
|
|
40
|
+
this.grants.revokeAgent(child);
|
|
41
|
+
this.transitions.set(child, {});
|
|
42
|
+
this.operators.delete(child);
|
|
43
|
+
}
|
|
44
|
+
}, { global: true });
|
|
45
|
+
ctx.effect(() => () => { this.lifetime.abort(); guard(); disposed(); for (const child of this.operators.keys())
|
|
46
|
+
this.grants.revokeAgent(child); this.operators.clear(); });
|
|
47
|
+
}
|
|
48
|
+
live(parent, child) {
|
|
49
|
+
this.lifetime.signal.throwIfAborted();
|
|
50
|
+
const agents = this.ctx.get("agents"), runtime = this.ctx.get("subagents"), approval = child.ctx.get("approval");
|
|
51
|
+
if (!agents || !runtime || !approval || agents.get(parent.id) !== parent || agents.get(child.id) !== child || !agents.roots().includes(parent)
|
|
52
|
+
|| !agents.isOwnedBy(child.id, parent) || child.session.header.parentSession !== parent.id || child.session.id !== child.id
|
|
53
|
+
|| Object.getPrototypeOf(permissionOriginal(runtime)) !== SubagentRuntime.prototype || Reflect.get(permissionOriginal(runtime), "creationApprovalOf") !== SubagentRuntime.prototype.creationApprovalOf
|
|
54
|
+
|| Object.getPrototypeOf(permissionOriginal(approval)) !== ApprovalService.prototype || Reflect.get(permissionOriginal(approval), "setPolicy") !== ApprovalService.prototype.setPolicy)
|
|
55
|
+
throw new PermissionRefusal("not-owned");
|
|
56
|
+
const origin = runtime.creationApprovalOf(child);
|
|
57
|
+
if (!origin || origin.parent !== parent || origin.child !== child)
|
|
58
|
+
throw new PermissionRefusal("unavailable");
|
|
59
|
+
return { origin, approval };
|
|
60
|
+
}
|
|
61
|
+
operator(child, authority) {
|
|
62
|
+
const live = this.live(authority.parent, child);
|
|
63
|
+
if (live.origin !== authority.origin || permissionOriginal(live.approval) !== permissionOriginal(authority.approval)
|
|
64
|
+
|| child.session !== authority.session || latestPolicy(child) !== authority.record
|
|
65
|
+
|| authority.approval.overrideOf(child.session) !== (authority.enabled ? "ask" : "never"))
|
|
66
|
+
throw new PermissionRefusal("stale");
|
|
67
|
+
}
|
|
68
|
+
assertEnabled(child) {
|
|
69
|
+
const authority = this.operators.get(child);
|
|
70
|
+
if (!authority?.enabled)
|
|
71
|
+
throw new PermissionRefusal("denied");
|
|
72
|
+
this.operator(child, authority);
|
|
73
|
+
authority.scope.check();
|
|
74
|
+
}
|
|
75
|
+
authorizeChild(_peer, child) {
|
|
76
|
+
this.assertEnabled(child);
|
|
77
|
+
const authority = this.operators.get(child);
|
|
78
|
+
return { assertCurrent: () => { if (this.operators.get(child) !== authority)
|
|
79
|
+
throw new PermissionRefusal("stale"); this.assertEnabled(child); } };
|
|
80
|
+
}
|
|
81
|
+
describe(parent, child) {
|
|
82
|
+
const value = { parentSessionId: parent.id, childSessionId: child.id, project: child.session.header.cwd ?? "",
|
|
83
|
+
state: "unavailable", canEnable: false, canRevoke: this.operators.has(child) || this.grants.list(child).length > 0 };
|
|
84
|
+
try {
|
|
85
|
+
const { origin } = this.live(parent, child), authority = this.operators.get(child), scope = this.options.capture(parent, child);
|
|
86
|
+
scope.check();
|
|
87
|
+
if (authority) {
|
|
88
|
+
this.operator(child, authority);
|
|
89
|
+
if (authority.enabled)
|
|
90
|
+
authority.scope.check();
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
origin.assertCurrent(parent, child);
|
|
94
|
+
return { ...value, state: authority?.enabled ? "enabled" : "disabled", canEnable: true, readOnly: scope.readOnly, ...(scope.role ? { role: scope.role } : {}) };
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
change(child, operation) {
|
|
101
|
+
if (child.status === "running") {
|
|
102
|
+
operation();
|
|
103
|
+
return Promise.resolve();
|
|
104
|
+
}
|
|
105
|
+
if (child.status !== "idle")
|
|
106
|
+
throw new PermissionRefusal("unavailable");
|
|
107
|
+
return child.runMaintenance(async (signal) => { signal.throwIfAborted(); operation(); });
|
|
108
|
+
}
|
|
109
|
+
async enable(parent, child, checkOperator) {
|
|
110
|
+
checkOperator();
|
|
111
|
+
const initial = this.live(parent, child), previous = this.operators.get(child), transition = {};
|
|
112
|
+
if (previous)
|
|
113
|
+
this.operator(child, previous);
|
|
114
|
+
else
|
|
115
|
+
initial.origin.assertCurrent(parent, child);
|
|
116
|
+
this.transitions.set(child, transition);
|
|
117
|
+
await this.options.refresh();
|
|
118
|
+
const scope = this.options.capture(parent, child);
|
|
119
|
+
await this.change(child, () => {
|
|
120
|
+
checkOperator();
|
|
121
|
+
scope.check();
|
|
122
|
+
const current = this.live(parent, child);
|
|
123
|
+
if (this.transitions.get(child) !== transition || current.origin !== initial.origin || permissionOriginal(current.approval) !== permissionOriginal(initial.approval)
|
|
124
|
+
|| !this.ctx.get("typertGateway")?.hasLiveClient())
|
|
125
|
+
throw new PermissionRefusal("unavailable");
|
|
126
|
+
if (previous)
|
|
127
|
+
this.operator(child, previous);
|
|
128
|
+
else
|
|
129
|
+
current.origin.assertCurrent(parent, child);
|
|
130
|
+
current.approval.setPolicy(child, "ask");
|
|
131
|
+
this.operators.set(child, { parent, origin: current.origin, scope, approval: current.approval, session: child.session, record: latestPolicy(child), enabled: true });
|
|
132
|
+
});
|
|
133
|
+
return this.describe(parent, child);
|
|
134
|
+
}
|
|
135
|
+
async revoke(parent, child, checkOperator) {
|
|
136
|
+
checkOperator();
|
|
137
|
+
this.grants.revokeAgent(child);
|
|
138
|
+
this.transitions.set(child, {});
|
|
139
|
+
const previous = this.operators.get(child);
|
|
140
|
+
if (!previous)
|
|
141
|
+
return this.describe(parent, child);
|
|
142
|
+
const enabled = previous.enabled;
|
|
143
|
+
previous.enabled = false;
|
|
144
|
+
try {
|
|
145
|
+
await this.change(child, () => {
|
|
146
|
+
checkOperator();
|
|
147
|
+
const live = this.live(parent, child);
|
|
148
|
+
if (previous.parent !== parent || live.origin !== previous.origin || child.session !== previous.session || latestPolicy(child) !== previous.record
|
|
149
|
+
|| permissionOriginal(live.approval) !== permissionOriginal(previous.approval)
|
|
150
|
+
|| live.approval.overrideOf(child.session) !== (enabled ? "ask" : "never"))
|
|
151
|
+
throw new PermissionRefusal("stale");
|
|
152
|
+
live.approval.setPolicy(child, "never");
|
|
153
|
+
previous.record = latestPolicy(child);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return { ...this.describe(parent, child), state: "unavailable", canEnable: false };
|
|
158
|
+
}
|
|
159
|
+
return this.describe(parent, child);
|
|
160
|
+
}
|
|
161
|
+
dispose() { this.lifetime.abort(); for (const child of this.operators.keys())
|
|
162
|
+
this.grants.revokeAgent(child); this.operators.clear(); }
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=permission-child-control.js.map
|