@dsmm/dsmm 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -40
- package/cordis.patch.yml +0 -13
- package/docs/agent-presets.md +26 -14
- package/docs/compatibility.md +19 -73
- package/docs/deferred-native-approval-risk.md +8 -12
- package/docs/design.md +25 -254
- package/docs/lsp.md +2 -2
- package/docs/migration-from-ocmm.md +38 -51
- package/docs/model-routing.md +21 -21
- package/docs/native-permissions.md +17 -7
- package/docs/profiles.md +13 -9
- package/docs/releasing.md +34 -280
- package/docs/roadmap.md +23 -254
- package/docs/runtime-recovery.md +29 -91
- package/docs/safety-guards.md +19 -16
- package/docs/settings-status.md +23 -11
- package/docs/skill-sync.md +17 -17
- package/docs/web-fetch-fakeip.md +82 -0
- package/lib/child-capture.d.ts +12 -2
- package/lib/child-capture.js +22 -5
- package/lib/client/ChildrenPanel.d.ts +1 -4
- package/lib/client/ChildrenPanel.js +4 -16
- package/lib/client/DeploymentFields.d.ts +28 -0
- package/lib/client/DeploymentFields.js +68 -0
- package/lib/client/DeploymentPage.d.ts +17 -5
- package/lib/client/DeploymentPage.js +79 -112
- package/lib/client/NativeCommandEntries.d.ts +17 -0
- package/lib/client/NativeCommandEntries.js +68 -0
- package/lib/client/PermissionsPanel.d.ts +1 -1
- package/lib/client/PermissionsPanel.js +8 -8
- package/lib/client/ProfilesSection.js +7 -5
- package/lib/client/RoleToolView-data.d.ts +35 -0
- package/lib/client/RoleToolView-data.js +52 -0
- package/lib/client/RoleToolView-locales.d.ts +36 -0
- package/lib/client/RoleToolView-locales.js +20 -0
- package/lib/client/RoleToolView.d.ts +10 -0
- package/lib/client/RoleToolView.js +47 -0
- package/lib/client/SessionProfiles.js +39 -15
- package/lib/client/children-controller.d.ts +2 -8
- package/lib/client/children-controller.js +1 -26
- package/lib/client/children-locales.d.ts +27 -52
- package/lib/client/children-locales.js +8 -12
- package/lib/client/configuration-display.d.ts +5 -0
- package/lib/client/configuration-display.js +11 -0
- package/lib/client/controller.d.ts +1 -0
- package/lib/client/controller.js +20 -13
- package/lib/client/deployment-controller.d.ts +13 -1
- package/lib/client/deployment-controller.js +84 -24
- package/lib/client/deployment-data.d.ts +1 -0
- package/lib/client/deployment-data.js +4 -1
- package/lib/client/deployment-locales.d.ts +43 -0
- package/lib/client/deployment-locales.js +35 -9
- package/lib/client/deployment-modules.d.ts +9 -0
- package/lib/client/deployment-modules.js +24 -0
- package/lib/client/deployment-workspace.d.ts +48 -0
- package/lib/client/deployment-workspace.js +123 -0
- package/lib/client/index.js +11 -74
- package/lib/client/locales.d.ts +7 -0
- package/lib/client/locales.js +12 -6
- package/lib/client/permission-controller.d.ts +1 -0
- package/lib/client/permission-controller.js +3 -2
- package/lib/client/permission-locales.d.ts +25 -0
- package/lib/client/permission-locales.js +24 -4
- package/lib/client/session-labels.js +4 -3
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +9 -8
- package/lib/client.js +2713 -2361
- package/lib/commands.js +2 -0
- package/lib/config-file-store.d.ts +3 -0
- package/lib/config-file-store.js +4 -2
- package/lib/config-revision.d.ts +5 -0
- package/lib/config-revision.js +11 -0
- package/lib/core-permission-authority.js +11 -41
- package/lib/deployment-config.d.ts +9 -2
- package/lib/deployment-config.js +35 -8
- package/lib/deployment-permission-rules.js +19 -7
- package/lib/dsh-types.d.ts +1 -1
- package/lib/host-llm-startup.js +3 -3
- package/lib/host-llm.d.ts +9 -3
- package/lib/host-llm.js +48 -8
- package/lib/index.d.ts +16 -20
- package/lib/index.js +130 -416
- package/lib/lifetime.d.ts +4 -0
- package/lib/lifetime.js +22 -0
- package/lib/live-pi-ai-owner.d.ts +1 -0
- package/lib/live-pi-ai-owner.js +8 -4
- package/lib/mode.d.ts +3 -2
- package/lib/mode.js +28 -41
- package/lib/model-routing.d.ts +2 -8
- package/lib/model-routing.js +59 -175
- package/lib/native-admission.d.ts +56 -0
- package/lib/native-admission.js +313 -0
- package/lib/native-pi-ai-wire.d.ts +3 -1
- package/lib/native-pi-ai-wire.js +47 -13
- package/lib/permission-control.d.ts +0 -3
- package/lib/preset-registry.js +3 -2
- package/lib/preset-skills.d.ts +3 -12
- package/lib/preset-skills.js +28 -58
- package/lib/profile-diagnostics.d.ts +1 -1
- package/lib/profile-diagnostics.js +2 -2
- package/lib/profile-remote.js +61 -22
- package/lib/profile-rpc.d.ts +4 -3
- package/lib/profile-rpc.js +33 -37
- package/lib/profile-runtime.d.ts +31 -74
- package/lib/profile-runtime.js +224 -639
- package/lib/profile-store.d.ts +18 -6
- package/lib/profile-store.js +104 -62
- package/lib/profile-types.d.ts +18 -4
- package/lib/profiles.d.ts +3 -1
- package/lib/profiles.js +9 -7
- package/lib/prompt-content.d.ts +1 -0
- package/lib/prompt-content.js +4 -1
- package/lib/prompts.d.ts +2 -12
- package/lib/prompts.js +11 -66
- package/lib/role-control-remote.d.ts +1 -4
- package/lib/role-control-remote.js +8 -36
- package/lib/role-control-rpc.d.ts +10 -36
- package/lib/role-control-rpc.js +112 -269
- package/lib/role-control-types.d.ts +3 -26
- package/lib/role-control-types.js +3 -4
- package/lib/role-identity.d.ts +5 -0
- package/lib/role-identity.js +10 -0
- package/lib/role-invocation.d.ts +2 -2
- package/lib/role-llm-runtime.js +5 -11
- package/lib/role-policy.d.ts +19 -50
- package/lib/role-policy.js +136 -508
- package/lib/role-providers.d.ts +5 -8
- package/lib/role-providers.js +20 -86
- package/lib/role-routing.d.ts +1 -3
- package/lib/role-routing.js +24 -34
- package/lib/role-subagents.d.ts +5 -14
- package/lib/role-subagents.js +148 -106
- package/lib/runtime-integration.d.ts +5 -78
- package/lib/runtime-integration.js +11 -697
- package/lib/session-metadata.d.ts +13 -12
- package/lib/session-metadata.js +6 -31
- package/lib/session-scope.js +2 -1
- package/lib/settings.d.ts +5 -18
- package/lib/settings.js +19 -43
- package/lib/state.d.ts +3 -2
- package/lib/state.js +26 -10
- package/lib/status.d.ts +1 -9
- package/lib/status.js +3 -55
- package/lib/web-fetch-address-policy.d.ts +24 -0
- package/lib/web-fetch-address-policy.js +189 -0
- package/lib/web-fetch-fakeip.d.ts +25 -0
- package/lib/web-fetch-fakeip.js +107 -0
- package/package.json +113 -103
- package/docs/research/deepseek-v4-pro.md +0 -74
- package/docs/research/oh-dsh.md +0 -96
- package/lib/agent-registry.d.ts +0 -36
- package/lib/agent-registry.js +0 -75
- package/lib/child-admission.d.ts +0 -40
- package/lib/child-admission.js +0 -151
- package/lib/delivery-authority.d.ts +0 -83
- package/lib/delivery-authority.js +0 -397
- package/lib/native-child-evidence.d.ts +0 -40
- package/lib/native-child-evidence.js +0 -104
- package/lib/role-runs.d.ts +0 -138
- package/lib/role-runs.js +0 -335
- package/lib/session-persistence.d.ts +0 -36
- package/lib/session-persistence.js +0 -304
- package/lib/subagent-runtime.d.ts +0 -57
- package/lib/subagent-runtime.js +0 -257
- package/prompts/deepseek-flash.md +0 -11
- package/prompts/deepseek-v4-pro.md +0 -14
|
@@ -1,702 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return useValue ? value : void 0;
|
|
7
|
-
};
|
|
8
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
-
var _, done = false;
|
|
14
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
-
var context = {};
|
|
16
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
-
if (kind === "accessor") {
|
|
21
|
-
if (result === void 0) continue;
|
|
22
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
-
}
|
|
27
|
-
else if (_ = accept(result)) {
|
|
28
|
-
if (kind === "field") initializers.unshift(_);
|
|
29
|
-
else descriptor[key] = _;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
-
done = true;
|
|
34
|
-
};
|
|
35
|
-
import { Context, symbols } from "@deepseek-ai/cordis";
|
|
36
|
-
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
37
|
-
import { foldSubagentDescriptor, SubagentError, SubagentRuntime } from "@deepseek-ai/dsh-subagent";
|
|
38
|
-
import { Remote, RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
39
|
-
import { createChildAdmissionBinding, projectChildAdmissionEvidence } from "./child-admission.js";
|
|
40
|
-
import { scopeLifetime } from "./delivery-authority.js";
|
|
41
|
-
import { NativeChildEvidenceReader } from "./native-child-evidence.js";
|
|
42
|
-
import { DsmmProfileError } from "./profiles.js";
|
|
43
|
-
import { capturedOriginalRoleInvocation, capturedRoleInvocation, currentRoleInvocation, duringRoleInvocation, invocationAgentOptions, resolveRoleInvocation } from "./role-invocation.js";
|
|
44
|
-
import { roleFromProviderName } from "./role-providers.js";
|
|
45
|
-
import { modelRouteFromCall } from "./role-llm.js";
|
|
46
|
-
import { ROLE_CONTROL_HOST } from "./role-control-remote.js";
|
|
47
|
-
import { registerRoleControlRpc } from "./role-control-rpc.js";
|
|
48
|
-
import { RoleRunRegistry } from "./role-runs.js";
|
|
49
|
-
import { admittedCallableRoleInventory, roleInvocationObservation, roleRouteComparison } from "./role-subagents.js";
|
|
50
|
-
import { childOwnedSessionEvents, resolveSelectedAgentPreset } from "./session-scope.js";
|
|
51
|
-
import { buildDsmmAgentGuidance } from "./prompts.js";
|
|
52
|
-
import { DsmmSubagentRuntime } from "./subagent-runtime.js";
|
|
53
|
-
function original(value) { return (Reflect.get(value, symbols.original) ?? value); }
|
|
54
|
-
const runtimeScopes = new WeakMap();
|
|
55
|
-
// Exact native creation provenance survives bundle replacement with its resident Agent.
|
|
56
|
-
const nativeCreations = new WeakSet();
|
|
57
|
-
const nativeCreationRegistries = new WeakMap();
|
|
58
|
-
/** Captures retain DSMM identity; a live foreign registration cannot establish it by name. */
|
|
59
|
-
function agentOrigin(agent, source) {
|
|
60
|
-
const structural = agent;
|
|
61
|
-
const own = childOwnedSessionEvents(structural.session);
|
|
62
|
-
const selected = agent.ctx.get("agentPresets")?.composedPreset(agent.ctx) ?? resolveSelectedAgentPreset(structural.session);
|
|
63
|
-
if (selected?.startsWith("dsmm-") || own.some(event => event.type === "dsmm/role-policy") || capturedRoleInvocation(structural) !== undefined)
|
|
64
|
-
return "dsmm";
|
|
65
|
-
if (agent.session.header.origin === "subagent") {
|
|
66
|
-
if (nativeCreations.has(agent))
|
|
67
|
-
return "native";
|
|
68
|
-
const descriptor = foldSubagentDescriptor(own);
|
|
69
|
-
if (descriptor === undefined)
|
|
70
|
-
return undefined;
|
|
71
|
-
if (!descriptor.provider.startsWith("dsmm-role-"))
|
|
72
|
-
return "native";
|
|
73
|
-
if (source !== "startup" || agent.session.header.isSeeded !== false)
|
|
74
|
-
return "dsmm";
|
|
75
|
-
const registry = agent.ctx.get("subagents"), provider = registry?.getProvider(descriptor.provider);
|
|
76
|
-
if (provider === undefined)
|
|
77
|
-
return "dsmm";
|
|
78
|
-
const captured = registry !== undefined && hosts.get(original(registry))?.current?.policy.ownsProvider(provider) === true;
|
|
79
|
-
return captured ? "dsmm" : "native";
|
|
80
|
-
}
|
|
81
|
-
return own.some(event => event.type === "deepwork/mode" && event.data?.active === true) ? "dsmm" : "native";
|
|
1
|
+
import { capturedRoleInvocation } from "./role-invocation.js";
|
|
2
|
+
import { resolveSelectedAgentPreset } from "./session-scope.js";
|
|
3
|
+
export function assertSupportedHostStartup(options) {
|
|
4
|
+
if (options === null || typeof options !== "object" || Object.keys(options).length)
|
|
5
|
+
throw new Error("DSMM uses official native services; runtime replacement options are unsupported");
|
|
82
6
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (agent.session.header?.origin !== "subagent")
|
|
87
|
-
return false;
|
|
88
|
-
const fresh = source === "startup" && agent.session.header.isSeeded === false;
|
|
89
|
-
const origin = agentOrigin(agent, source);
|
|
90
|
-
// Native one-shot creation appends its descriptor after agent/created. Only
|
|
91
|
-
// fresh setup under an admitted ordinary parent can precede that evidence.
|
|
92
|
-
if (origin === "dsmm" || origin === undefined && !fresh)
|
|
93
|
-
return false;
|
|
94
|
-
const parent = agent.session.header.parentSession === undefined ? undefined : ctx.agents.get(SessionId(agent.session.header.parentSession));
|
|
95
|
-
if (parent === undefined || !ctx.agents.isOwnedBy(agent.id, parent) || controlledParent(parent))
|
|
96
|
-
return false;
|
|
97
|
-
if (fresh) {
|
|
98
|
-
nativeCreations.add(agent);
|
|
99
|
-
nativeCreationRegistries.set(agent, original(ctx.agents));
|
|
100
|
-
}
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
/** Limit DSMM's observers/guards to its own children without altering the native service or factories. */
|
|
104
|
-
export function managedAgentContext(ctx, controlledParent) {
|
|
105
|
-
const agents = ctx.agents;
|
|
106
|
-
const filteredAgents = new Proxy(agents, { get(target, key) {
|
|
107
|
-
if (key === "list")
|
|
108
|
-
return () => target.list().filter(agent => !nativeChild(ctx, agent, controlledParent));
|
|
109
|
-
const value = Reflect.get(target, key);
|
|
110
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
111
|
-
} });
|
|
112
|
-
return new Proxy(ctx, { get(target, key) {
|
|
113
|
-
if (key === "get")
|
|
114
|
-
return (name) => name === "agents" ? filteredAgents : target.get(name);
|
|
115
|
-
if (key === "on")
|
|
116
|
-
return (event, listener, options) => target.on(event, ((...args) => {
|
|
117
|
-
const agent = args[0]?.agent ?? (event === "system-prompt/assemble" ? args[1]?.scope : undefined);
|
|
118
|
-
if (event !== "tools/execute" && event !== "tools/post-execute" && agent !== undefined && agents.list().includes(agent) && nativeChild(ctx, agent, controlledParent, event === "agent/created" ? args[0]?.source : undefined)) {
|
|
119
|
-
const next = args.at(-1);
|
|
120
|
-
return typeof next === "function" ? next() : undefined;
|
|
121
|
-
}
|
|
122
|
-
return listener(...args);
|
|
123
|
-
}), options);
|
|
124
|
-
const value = Reflect.get(target, key);
|
|
125
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
126
|
-
} });
|
|
127
|
-
}
|
|
128
|
-
/** Enrollment consumes A's completed admissions while native creation retains its original serial owner. */
|
|
129
|
-
export function admittedAgentContext(ctx, runtime) {
|
|
130
|
-
const agents = ctx.get("agents");
|
|
131
|
-
const admitted = new Proxy(agents, { get(target, key) {
|
|
132
|
-
if (key === "list")
|
|
133
|
-
return () => target.list().filter(agent => runtime.hasAdmission(agent));
|
|
134
|
-
const value = Reflect.get(target, key);
|
|
135
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
136
|
-
} });
|
|
137
|
-
return new Proxy(ctx, { get(target, key) {
|
|
138
|
-
if (key === "get")
|
|
139
|
-
return (name) => name === "agents" ? admitted : target.get(name);
|
|
140
|
-
if (key === "on")
|
|
141
|
-
return (event, listener, options) => event === "agent/created"
|
|
142
|
-
? target.effect(() => runtime.observeAdmissions(async (agent) => { await listener({ agent }); }))
|
|
143
|
-
: target.on(event, listener, options);
|
|
144
|
-
const value = Reflect.get(target, key);
|
|
145
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
146
|
-
} });
|
|
7
|
+
export function classifyDsmmAgent(agent) {
|
|
8
|
+
const preset = agent.ctx.get("agentPresets")?.composedPreset(agent.ctx) ?? resolveSelectedAgentPreset(agent.session);
|
|
9
|
+
return preset?.startsWith("dsmm-") || capturedRoleInvocation(agent) ? "dsmm" : "native";
|
|
147
10
|
}
|
|
148
11
|
export function runtimeAdmissionView(ctx) {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const runtime = original(bound);
|
|
153
|
-
return runtime instanceof DsmmSubagentRuntime ? runtime.authority.view()
|
|
154
|
-
: { binding: "stock", deliveryFenceReady: false, restartRequired: true, reason: "explicit-composition-required" };
|
|
155
|
-
}
|
|
156
|
-
/** Capability projection only. Admission objects and A's CAS/maintenance methods remain untouched. */
|
|
157
|
-
export function publicProfileRuntime(runtime, ctx) {
|
|
158
|
-
const getter = Object.assign(((agent) => runtime.getSettings(agent)), runtime.getSettings, { subagentRuntime: () => runtimeAdmissionView(ctx) });
|
|
159
|
-
return new Proxy(runtime, { get(target, key) {
|
|
160
|
-
if (key === "getSettings")
|
|
161
|
-
return getter;
|
|
162
|
-
if (key === "getSession" || key === "selectSession")
|
|
163
|
-
return async (...args) => {
|
|
164
|
-
let result;
|
|
165
|
-
const call = async () => { result = await Reflect.apply(Reflect.get(target, key), target, args); };
|
|
166
|
-
await call();
|
|
167
|
-
return { ...result, subagentRuntime: runtimeAdmissionView(ctx) };
|
|
168
|
-
};
|
|
169
|
-
const value = Reflect.get(target, key);
|
|
170
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
171
|
-
} });
|
|
172
|
-
}
|
|
173
|
-
export function assertSupportedHostStartup(startup) {
|
|
174
|
-
if (startup === null || typeof startup !== "object" || Array.isArray(startup) || Reflect.ownKeys(startup).length !== 0) {
|
|
175
|
-
throw new DsmmProfileError("unavailable", "Host compatibility startup options are unsupported; existing data is not migrated.");
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
const hosts = new WeakMap();
|
|
179
|
-
/** Exact live descendants are revoked synchronously before any native holder starts draining. */
|
|
180
|
-
function revokeTree(registry, revoke, parent, reason) {
|
|
181
|
-
const pending = [parent], seen = new Set();
|
|
182
|
-
while (pending.length > 0) {
|
|
183
|
-
const current = pending.pop();
|
|
184
|
-
if (seen.has(current))
|
|
185
|
-
continue;
|
|
186
|
-
seen.add(current);
|
|
187
|
-
revoke(current, reason);
|
|
188
|
-
for (const child of registry.list())
|
|
189
|
-
if (child !== current && registry.isOwnedBy(child.id, current))
|
|
190
|
-
pending.push(child);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
const disabled = (reason) => ({ enabled: false, reason });
|
|
194
|
-
export async function integrateSubagentRuntime(ctx, settings, policy, getRuntime, startup = {}) {
|
|
195
|
-
assertSupportedHostStartup(startup);
|
|
196
|
-
const bound = ctx.get("subagents");
|
|
197
|
-
if (bound === undefined || !(original(bound) instanceof DsmmSubagentRuntime) || !settings.modules.deepwork.enabled)
|
|
198
|
-
return undefined;
|
|
199
|
-
return new Promise((resolve, reject) => {
|
|
200
|
-
const unavailable = () => new DsmmProfileError("unavailable", "Native integration startup lost its injection lifetime.");
|
|
201
|
-
let entered = false, retired = false;
|
|
202
|
-
const retire = () => { retired = true; reject(unavailable()); };
|
|
203
|
-
const fiber = ctx.inject(["subagents"], async (scope) => {
|
|
204
|
-
entered = true;
|
|
205
|
-
try {
|
|
206
|
-
if (retired)
|
|
207
|
-
throw unavailable();
|
|
208
|
-
const integration = await integrateManagedSubagentRuntime(scope, settings, policy, getRuntime);
|
|
209
|
-
if (retired)
|
|
210
|
-
throw unavailable();
|
|
211
|
-
resolve(integration);
|
|
212
|
-
}
|
|
213
|
-
catch (error) {
|
|
214
|
-
reject(error);
|
|
215
|
-
throw error;
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
if (fiber.uid === null || fiber.state === 5) {
|
|
219
|
-
retire();
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
scopeLifetime(fiber.ctx, "dsmm.integration: cancel injection startup", retire);
|
|
223
|
-
// Cordis can skip the callback entirely when a required implementation is withdrawn.
|
|
224
|
-
void fiber.await().then(() => { if (!entered)
|
|
225
|
-
retire(); }, reject);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
async function integrateManagedSubagentRuntime(ctx, settings, policy, getRuntime) {
|
|
229
|
-
const bound = ctx.get("subagents");
|
|
230
|
-
const native = bound === undefined ? undefined : original(bound);
|
|
231
|
-
if (!(native instanceof DsmmSubagentRuntime) || !settings.modules.deepwork.enabled)
|
|
232
|
-
return undefined;
|
|
233
|
-
const hostScope = runtimeScopes.get(native);
|
|
234
|
-
if (hostScope === undefined)
|
|
235
|
-
throw new DsmmProfileError("unavailable", "Managed admission requires the explicit Host-owned startup entry, not a separately constructed runtime.");
|
|
236
|
-
// Revocation outlives the entry's injection scope; this reference only enumerates exact native owners during teardown.
|
|
237
|
-
const teardownAgents = original(ctx.agents);
|
|
238
|
-
const revokeResidency = native.authority.revokeParent.bind(native.authority);
|
|
239
|
-
native.requireProviders(["spawn"]);
|
|
240
|
-
const lifetime = new AbortController();
|
|
241
|
-
scopeLifetime(ctx, "dsmm.integration: close startup preparation", () => lifetime.abort());
|
|
242
|
-
const history = ctx.get("sessionQuery");
|
|
243
|
-
if (history === undefined || typeof history.observeSession !== "function")
|
|
244
|
-
throw new DsmmProfileError("unavailable", "Managed child admission requires the actual public native session history service.");
|
|
245
|
-
let host = hosts.get(native);
|
|
246
|
-
if (host === undefined) {
|
|
247
|
-
const owner = {};
|
|
248
|
-
const current = () => { const value = host.current; if (value === undefined)
|
|
249
|
-
throw new SubagentError("Host role-run authority is not ready", "UNAUTHORIZED"); return value; };
|
|
250
|
-
const registry = new RoleRunRegistry(hostScope, {
|
|
251
|
-
currentEpoch(parent, requestedOwner) {
|
|
252
|
-
const ticket = current().bridge.authority.acquireParentTicket(parent);
|
|
253
|
-
if (requestedOwner !== owner || ticket.owner !== owner)
|
|
254
|
-
throw new SubagentError("Role-run owner is not the exact Host admission owner", "UNAUTHORIZED");
|
|
255
|
-
return ticket.parentEpoch;
|
|
256
|
-
},
|
|
257
|
-
canBackground(parent, invocation, epoch) {
|
|
258
|
-
const state = current(), admission = state.getSettings.admission(parent);
|
|
259
|
-
return admission.epoch === epoch && invocation.owner === owner && admission.settings.subagents.enableRunInBackground
|
|
260
|
-
&& invocation.capture.admission.settings.subagents.enableRunInBackground && parent.ctx.get("jobs") !== undefined
|
|
261
|
-
&& state.policy.targets(parent).includes(invocation.capture.invocation.target);
|
|
262
|
-
},
|
|
263
|
-
teardown: {
|
|
264
|
-
revokeParent: (agent, reason) => revokeTree(teardownAgents, revokeResidency, agent, reason),
|
|
265
|
-
async disposeRun(run) {
|
|
266
|
-
await run.dispose();
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
});
|
|
270
|
-
host = { owner, registry };
|
|
271
|
-
hosts.set(native, host);
|
|
272
|
-
}
|
|
273
|
-
const stable = host;
|
|
274
|
-
let completion;
|
|
275
|
-
let bridge;
|
|
276
|
-
const originalAdmissions = {
|
|
277
|
-
resolveOriginalChildEvidence: (...args) => {
|
|
278
|
-
const runtime = getRuntime();
|
|
279
|
-
if (runtime === undefined)
|
|
280
|
-
throw new DsmmProfileError("unavailable", "Original child admission is not initialized.");
|
|
281
|
-
return runtime.resolveOriginalChildEvidence(...args);
|
|
282
|
-
},
|
|
283
|
-
assertDelivery: policy.assertChildDelivery.bind(policy),
|
|
284
|
-
};
|
|
285
|
-
bridge = createChildAdmissionBinding({ ctx, owner: stable.owner, deliveryAuthority: native.authority,
|
|
286
|
-
nativeSubstrate: settings, nativeHistory: history,
|
|
287
|
-
collaborators: {
|
|
288
|
-
classifyParent: classifyDsmmAgent,
|
|
289
|
-
resolveOriginalChildEvidence: originalAdmissions.resolveOriginalChildEvidence,
|
|
290
|
-
childAdmission: { prepare: (...args) => completion.prepare(...args), validateRole: (...args) => completion.validateRole(...args) },
|
|
291
|
-
assertDelivery: originalAdmissions.assertDelivery,
|
|
292
|
-
}, });
|
|
293
|
-
completion = policy.configureAdmission({ nativeSubstrate: settings, resolveOriginalEvidence: bridge.resolveOriginalEvidence,
|
|
294
|
-
revokeParent: (agent, reason) => revokeTree(teardownAgents, revokeResidency, agent, reason) });
|
|
295
|
-
// Native non-DSMM direct children remain native. This branch is established
|
|
296
|
-
// from an actual public physical cut, never from a missing DSMM registration.
|
|
297
|
-
const nativeEvidence = new WeakSet();
|
|
298
|
-
const nativeResidencies = new Map();
|
|
299
|
-
ctx.on("agent/created", ({ agent }) => { nativeResidencies.delete(agent.id); }, { global: true });
|
|
300
|
-
ctx.on("agent/disposed", ({ agent }) => {
|
|
301
|
-
nativeResidencies.delete(agent.id);
|
|
302
|
-
if (nativeCreationRegistries.get(agent) === original(ctx.agents)) {
|
|
303
|
-
nativeCreations.delete(agent);
|
|
304
|
-
nativeCreationRegistries.delete(agent);
|
|
305
|
-
}
|
|
306
|
-
}, { global: true });
|
|
307
|
-
const isNativeEvidence = (evidence) => typeof evidence === "object" && evidence !== null && nativeEvidence.has(evidence);
|
|
308
|
-
const dsmmMarked = (events) => events.some(event => {
|
|
309
|
-
if (event.type === "dsmm/role-policy")
|
|
310
|
-
return true;
|
|
311
|
-
if (event.type === "deepwork/mode")
|
|
312
|
-
return event.data?.active === true;
|
|
313
|
-
if (event.type !== "agent-preset/selected")
|
|
314
|
-
return false;
|
|
315
|
-
const preset = event.data?.agentPreset;
|
|
316
|
-
return typeof preset === "string" && preset.startsWith("dsmm-");
|
|
317
|
-
});
|
|
318
|
-
const matchesNativeResidency = (evidence) => {
|
|
319
|
-
const registry = ctx.agents, resident = evidence.resident;
|
|
320
|
-
if (original(registry) !== evidence.registry || original(evidence.parent.ctx.agents) !== evidence.registry
|
|
321
|
-
|| registry.get(evidence.childId) !== resident || nativeResidencies.get(evidence.childId) !== evidence.residency)
|
|
322
|
-
return false;
|
|
323
|
-
const prefixed = evidence.provider.startsWith("dsmm-role-");
|
|
324
|
-
if (resident === undefined)
|
|
325
|
-
return !prefixed;
|
|
326
|
-
if (original(resident.ctx.agents) !== evidence.registry || resident.id !== evidence.childId || resident.session.id !== evidence.childId
|
|
327
|
-
|| !registry.isOwnedBy(evidence.childId, evidence.parent) || resident.session.header.parentSession !== evidence.parent.id
|
|
328
|
-
|| resident.session.header.origin !== "subagent" || prefixed && (!nativeCreations.has(resident) || nativeCreationRegistries.get(resident) !== evidence.registry)
|
|
329
|
-
|| classifyDsmmAgent(resident) !== "native")
|
|
330
|
-
return false;
|
|
331
|
-
const own = childOwnedSessionEvents(resident.session);
|
|
332
|
-
const descriptor = foldSubagentDescriptor(own);
|
|
333
|
-
return own.filter(event => event.type === "subagent/descriptor").length === 1 && descriptor?.mode === evidence.mode
|
|
334
|
-
&& descriptor.provider === evidence.provider && !dsmmMarked(own);
|
|
335
|
-
};
|
|
336
|
-
const proveNativeChild = async (ticket, childId, mode, signal) => {
|
|
337
|
-
signal.throwIfAborted();
|
|
338
|
-
native.authority.assertTicket(ticket);
|
|
339
|
-
if (policy.identity(ticket.parent).role !== undefined)
|
|
340
|
-
return undefined;
|
|
341
|
-
const currentHistory = ctx.get("sessionQuery");
|
|
342
|
-
if (currentHistory === undefined || original(currentHistory) !== original(history))
|
|
343
|
-
throw new SubagentError("Native child observation requires the exact public history service", "UNAUTHORIZED");
|
|
344
|
-
const observation = await history.observeSession(childId, { signal, projectionMode: "none" });
|
|
345
|
-
try {
|
|
346
|
-
signal.throwIfAborted();
|
|
347
|
-
native.authority.assertTicket(ticket);
|
|
348
|
-
const inherited = observation.inheritedEventCount, header = observation.header;
|
|
349
|
-
if (!Number.isSafeInteger(inherited) || inherited < 0 || inherited > observation.events.length)
|
|
350
|
-
throw new SubagentError("Native child observation has no valid own-event boundary", "UNAUTHORIZED");
|
|
351
|
-
const own = observation.events.slice(inherited), descriptor = foldSubagentDescriptor(own);
|
|
352
|
-
if (header.version !== 4 || header.id !== childId || header.parentSession !== ticket.parent.id || header.origin !== "subagent"
|
|
353
|
-
|| own.filter(event => event.type === "subagent/descriptor").length !== 1 || descriptor?.mode !== mode || dsmmMarked(own))
|
|
354
|
-
return undefined;
|
|
355
|
-
const registry = ctx.agents, resident = registry.get(childId), residency = nativeResidencies.get(childId) ?? {};
|
|
356
|
-
nativeResidencies.set(childId, residency);
|
|
357
|
-
const evidence = Object.freeze({ parent: ticket.parent, childId, registry: original(registry), resident, residency, provider: descriptor.provider, mode });
|
|
358
|
-
if (!matchesNativeResidency(evidence))
|
|
359
|
-
return undefined;
|
|
360
|
-
nativeEvidence.add(evidence);
|
|
361
|
-
return evidence;
|
|
362
|
-
}
|
|
363
|
-
finally {
|
|
364
|
-
observation[Symbol.dispose]();
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
const detachPolicy = native.authority.bindPolicy(ctx, stable.owner, {
|
|
368
|
-
isNativeEvidence,
|
|
369
|
-
classifyParent: parent => parent.session.header.origin === "subagent" ? classifyDsmmAgent(parent)
|
|
370
|
-
: policy.identity(parent).role === undefined ? "native" : "dsmm",
|
|
371
|
-
async resolveChildEvidence(ticket, childId, signal) {
|
|
372
|
-
const evidence = await proveNativeChild(ticket, childId, "continuable", signal);
|
|
373
|
-
if (evidence !== undefined)
|
|
374
|
-
return evidence;
|
|
375
|
-
return bridge.policy.resolveChildEvidence(ticket, childId, signal);
|
|
376
|
-
},
|
|
377
|
-
assertDelivery(ticket, childId, evidence) {
|
|
378
|
-
if (isNativeEvidence(evidence)) {
|
|
379
|
-
if (evidence.parent !== ticket.parent || evidence.childId !== childId || !matchesNativeResidency(evidence)
|
|
380
|
-
|| policy.identity(ticket.parent).role !== undefined)
|
|
381
|
-
throw new SubagentError("Native child delivery does not match this ordinary direct parent", "UNAUTHORIZED");
|
|
382
|
-
}
|
|
383
|
-
else
|
|
384
|
-
bridge.policy.assertDelivery(ticket, childId, evidence);
|
|
385
|
-
},
|
|
386
|
-
});
|
|
387
|
-
const getSettings = agent => {
|
|
388
|
-
const runtime = getRuntime();
|
|
389
|
-
if (runtime === undefined)
|
|
390
|
-
throw new DsmmProfileError("unavailable", "The actual Host admission is not initialized.");
|
|
391
|
-
return runtime.getSettings(agent);
|
|
392
|
-
};
|
|
393
|
-
getSettings.admission = agent => getRuntime().admission(agent);
|
|
394
|
-
stable.current = { bridge, policy, getSettings };
|
|
395
|
-
scopeLifetime(ctx, "dsmm.integration: release entry collaborators", () => { if (stable.current?.bridge === bridge)
|
|
396
|
-
stable.current = undefined; });
|
|
397
|
-
const managed = native;
|
|
398
|
-
let deliveryProvider = managed.getProvider("spawn"), providerEpoch = new AbortController();
|
|
399
|
-
const providerChanged = () => {
|
|
400
|
-
const current = managed.getProvider("spawn");
|
|
401
|
-
if (current === deliveryProvider)
|
|
402
|
-
return;
|
|
403
|
-
providerEpoch.abort();
|
|
404
|
-
providerEpoch = new AbortController();
|
|
405
|
-
deliveryProvider = current;
|
|
406
|
-
};
|
|
407
|
-
ctx.on("subagent/provider-added", providerChanged, { global: true });
|
|
408
|
-
ctx.on("subagent/provider-removed", providerChanged, { global: true });
|
|
409
|
-
managed.configureActivationPreflight(async (spec, start) => {
|
|
410
|
-
const provider = managed.getProvider(spec.provider);
|
|
411
|
-
const role = provider !== undefined && policy.ownsProvider(provider) ? roleFromProviderName(spec.provider) : undefined;
|
|
412
|
-
if (role === undefined)
|
|
413
|
-
return start(spec);
|
|
414
|
-
const parent = spec.request.parent, actor = parent;
|
|
415
|
-
policy.assertDelegation(actor, role);
|
|
416
|
-
const ticket = managed.authority.acquireParentTicket(parent);
|
|
417
|
-
const signal = AbortSignal.any([spec.signal, ticket.signal, lifetime.signal]);
|
|
418
|
-
const invocation = currentRoleInvocation(actor, role) ?? await resolveRoleInvocation(parent, role, ticket.admission.settings, signal, {}, spec.request.agentOptions);
|
|
419
|
-
signal.throwIfAborted();
|
|
420
|
-
managed.authority.assertTicket(ticket);
|
|
421
|
-
policy.assertDelegation(actor, role);
|
|
422
|
-
const ceiling = ticket.admission.settings.subagents.maxDepth;
|
|
423
|
-
if (spec.request.maxDepth !== undefined && ceiling !== undefined && spec.request.maxDepth > ceiling)
|
|
424
|
-
throw new SubagentError("Delegation exceeds parent depth ceiling", "UNAUTHORIZED");
|
|
425
|
-
const maxDepth = spec.request.maxDepth ?? managed.resolveMaxDepth(ceiling);
|
|
426
|
-
return duringRoleInvocation(actor, invocation, () => policy.duringDelegation(actor, role, () => start({ ...spec, signal,
|
|
427
|
-
request: { ...spec.request, maxDepth, agentOptions: invocationAgentOptions(invocation, spec.request.agentOptions) } }), undefined, maxDepth));
|
|
428
|
-
}, lifetime.signal);
|
|
429
|
-
const reader = new NativeChildEvidenceReader(ctx, ticket => managed.authority.assertTicket(ticket), history);
|
|
430
|
-
const background = (ticket) => !ticket.admission.settings.modules.deepwork.enabled ? disabled("module-off")
|
|
431
|
-
: !ticket.admission.settings.subagents.enableRunInBackground ? disabled("background-disabled")
|
|
432
|
-
: ticket.parent.ctx.get("jobs") === undefined ? disabled("jobs-unavailable") : { enabled: true };
|
|
433
|
-
const capabilities = (ticket) => ({
|
|
434
|
-
background: background(ticket),
|
|
435
|
-
prompt: !ticket.admission.settings.modules.deepwork.enabled ? disabled("module-off") : ctx.get("sessionQuery") !== undefined && ctx.get("sessionPersistence") !== undefined ? { enabled: true } : disabled("unavailable"),
|
|
436
|
-
interrupt: ticket.admission.settings.modules.deepwork.enabled ? { enabled: true } : disabled("module-off"),
|
|
437
|
-
images: ctx.get("attachments") !== undefined ? { enabled: true } : disabled("unavailable"), runtime: managed.authority.view(),
|
|
438
|
-
});
|
|
439
|
-
let startupCompletion;
|
|
440
|
-
return { bridge, owner: stable.owner, registry: stable.registry, runtime: managed,
|
|
441
|
-
async admitLlmRequest(agent, signal) {
|
|
442
|
-
signal.throwIfAborted();
|
|
443
|
-
await managed.authority.waitForPromotion(agent, signal);
|
|
444
|
-
const dsmmAgent = agent;
|
|
445
|
-
policy.assertModuleAdmission(dsmmAgent);
|
|
446
|
-
const identity = policy.identity(dsmmAgent);
|
|
447
|
-
if (identity.role === undefined)
|
|
448
|
-
return undefined;
|
|
449
|
-
const admission = getRuntime().admission(dsmmAgent);
|
|
450
|
-
const ticket = managed.authority.acquireParentTicket(agent);
|
|
451
|
-
if (ticket.owner !== stable.owner || ticket.admission !== admission || ticket.parentEpoch !== admission.epoch)
|
|
452
|
-
throw new SubagentError("LLM request does not own its exact Host admission", "UNAUTHORIZED");
|
|
453
|
-
const parent = identity.parent;
|
|
454
|
-
const parentTicket = parent === undefined ? undefined : managed.authority.acquireParentTicket(parent);
|
|
455
|
-
if (identity.child && parentTicket === undefined)
|
|
456
|
-
throw new SubagentError("LLM child has no admitted direct parent", "UNAUTHORIZED");
|
|
457
|
-
const provider = deliveryProvider;
|
|
458
|
-
const merged = AbortSignal.any([signal, lifetime.signal, providerEpoch.signal, ticket.signal, ...parentTicket === undefined ? [] : [parentTicket.signal]]);
|
|
459
|
-
const evidence = parentTicket === undefined ? undefined : await getRuntime().resolveOriginalChildEvidence(bridge.authority.acquireParentTicket(parentTicket.parent), agent.id, merged);
|
|
460
|
-
const assertCurrent = () => {
|
|
461
|
-
merged.throwIfAborted();
|
|
462
|
-
managed.authority.assertTicket(ticket);
|
|
463
|
-
if (provider === undefined || managed.getProvider("spawn") !== provider)
|
|
464
|
-
throw new SubagentError("LLM delivery provider was replaced", "UNAUTHORIZED");
|
|
465
|
-
if (stable.current?.bridge !== bridge || getRuntime().admission(dsmmAgent) !== admission)
|
|
466
|
-
throw new SubagentError("LLM admission was replaced", "UNAUTHORIZED");
|
|
467
|
-
policy.assertModuleAdmission(dsmmAgent);
|
|
468
|
-
const current = policy.identity(dsmmAgent);
|
|
469
|
-
if (current.role !== identity.role || current.epoch !== identity.epoch || current.parent !== identity.parent || current.child !== identity.child)
|
|
470
|
-
throw new SubagentError("LLM role identity changed", "UNAUTHORIZED");
|
|
471
|
-
if (parentTicket !== undefined && evidence !== undefined) {
|
|
472
|
-
managed.authority.assertTicket(parentTicket);
|
|
473
|
-
if (ctx.agents.get(parentTicket.parent.id) !== parentTicket.parent || !ctx.agents.isOwnedBy(agent.id, parentTicket.parent))
|
|
474
|
-
throw new SubagentError("LLM child ownership changed", "UNAUTHORIZED");
|
|
475
|
-
policy.assertChildExecution(bridge.authority.acquireParentTicket(parentTicket.parent), agent.id, evidence);
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
assertCurrent();
|
|
479
|
-
return Object.freeze({ agent, admission, capture: admission.childCapture ?? evidence ?? ticket, epoch: admission.epoch, signal: merged, assertCurrent });
|
|
480
|
-
},
|
|
481
|
-
dispose(nativeDrain) {
|
|
482
|
-
for (const parent of teardownAgents.roots())
|
|
483
|
-
revokeTree(teardownAgents, revokeResidency, parent, "host-dispose");
|
|
484
|
-
return nativeDrain();
|
|
485
|
-
},
|
|
486
|
-
onAdmissionGuardsInstalled() { lifetime.signal.throwIfAborted(); bridge.onAdmissionGuardsInstalled(); },
|
|
487
|
-
continueStartup(complete, callerSignal) {
|
|
488
|
-
if (startupCompletion !== undefined)
|
|
489
|
-
throw new DsmmProfileError("unavailable", "DW startup already has its Host continuation.");
|
|
490
|
-
const signal = AbortSignal.any([lifetime.signal, ...callerSignal === undefined ? [] : [callerSignal]]);
|
|
491
|
-
startupCompletion = (async () => {
|
|
492
|
-
await managed.waitUntilReady(signal);
|
|
493
|
-
signal.throwIfAborted();
|
|
494
|
-
await complete(signal);
|
|
495
|
-
signal.throwIfAborted();
|
|
496
|
-
})().catch(error => { lifetime.abort(error); detachPolicy(); throw error; });
|
|
497
|
-
return startupCompletion;
|
|
498
|
-
},
|
|
499
|
-
async ready() { await managed.waitUntilReady(lifetime.signal); await startupCompletion; lifetime.signal.throwIfAborted(); },
|
|
500
|
-
async revokeBeforeDispose(agent, dispose) {
|
|
501
|
-
revokeTree(teardownAgents, revokeResidency, agent, "holder-disposed");
|
|
502
|
-
const nativeDispose = async () => { await stable.registry.drainParent(agent, stable.owner, "holder-disposed"); await dispose(); };
|
|
503
|
-
await nativeDispose();
|
|
504
|
-
},
|
|
505
|
-
registerControls(scope) {
|
|
506
|
-
registerRoleControlRpc(scope, { runtime: managed, runs: stable.registry, capabilities,
|
|
507
|
-
projectRun(invocation) {
|
|
508
|
-
const childId = invocation.childId ?? (invocation.projection.childId === undefined ? undefined : SessionId(invocation.projection.childId));
|
|
509
|
-
const child = childId === undefined ? undefined : ctx.agents.get(childId);
|
|
510
|
-
if (child !== undefined && !ctx.agents.isOwnedBy(child.id, invocation.parent))
|
|
511
|
-
throw new SubagentError("Run projection requires its exact native holder owner", "UNAUTHORIZED");
|
|
512
|
-
return roleInvocationObservation(invocation.capture.invocation, invocation.projection.label, "one-shot", getSettings, child, { runId: invocation.runId, ...(invocation.childId === undefined ? {} : { childId: invocation.childId }) }).view;
|
|
513
|
-
},
|
|
514
|
-
async backgroundAvailability(ticket, invocation, signal) {
|
|
515
|
-
signal.throwIfAborted();
|
|
516
|
-
managed.authority.assertTicket(ticket);
|
|
517
|
-
return invocation.owner !== ticket.owner || invocation.parent !== ticket.parent ? disabled("unavailable")
|
|
518
|
-
: !invocation.capture.admission.settings.subagents.enableRunInBackground ? disabled("background-disabled")
|
|
519
|
-
: !policy.targets(ticket.parent).includes(invocation.capture.invocation.target) ? disabled("role-disabled") : background(ticket);
|
|
520
|
-
},
|
|
521
|
-
async observeChild(ticket, entry, signal) {
|
|
522
|
-
if (entry.mode !== "continuable") {
|
|
523
|
-
const unavailable = disabled(entry.mode === "one-shot" ? "one-shot" : "unknown-mode");
|
|
524
|
-
const child = ctx.agents.get(entry.id);
|
|
525
|
-
if (child === undefined || entry.mode !== "one-shot")
|
|
526
|
-
return { prompt: unavailable, interrupt: unavailable };
|
|
527
|
-
managed.authority.assertTicket(ticket);
|
|
528
|
-
if (!ctx.agents.isOwnedBy(entry.id, ticket.parent))
|
|
529
|
-
throw new SubagentError("Run observation requires its exact direct owner", "UNAUTHORIZED");
|
|
530
|
-
if (await proveNativeChild(ticket, entry.id, "one-shot", signal) !== undefined)
|
|
531
|
-
return { prompt: unavailable, interrupt: unavailable };
|
|
532
|
-
const admission = getRuntime().admission(child);
|
|
533
|
-
const invocation = observedOriginalInvocation(child, admission, entry.label, "one-shot");
|
|
534
|
-
return { prompt: unavailable, interrupt: unavailable, routeComparison: roleRouteComparison(child),
|
|
535
|
-
...(invocation === undefined ? {} : { invocation: invocation.view }),
|
|
536
|
-
...(admission.childCapture === undefined ? {} : { evidence: projectChildAdmissionEvidence(admission.childCapture, ticket.parentEpoch) }) };
|
|
537
|
-
}
|
|
538
|
-
const evidence = await managed.authority.resolveChildEvidence(ticket, entry.id, signal);
|
|
539
|
-
if (isNativeEvidence(evidence)) {
|
|
540
|
-
managed.authority.assertDelivery(ticket, entry.id, evidence);
|
|
541
|
-
return { prompt: { enabled: true }, interrupt: { enabled: true } };
|
|
542
|
-
}
|
|
543
|
-
let prompt = { enabled: true };
|
|
544
|
-
try {
|
|
545
|
-
managed.authority.assertDelivery(ticket, entry.id, evidence);
|
|
546
|
-
}
|
|
547
|
-
catch {
|
|
548
|
-
signal.throwIfAborted();
|
|
549
|
-
prompt = disabled("mode" in evidence ? "legacy-capability-denied" : "role-disabled");
|
|
550
|
-
}
|
|
551
|
-
if ("mode" in evidence)
|
|
552
|
-
return { evidence: projectChildAdmissionEvidence(evidence, ticket.parentEpoch), prompt, interrupt: prompt };
|
|
553
|
-
const mode = evidence.version === 3 ? evidence.delegationMode : "continuable";
|
|
554
|
-
if (mode === "one-shot")
|
|
555
|
-
prompt = disabled("one-shot");
|
|
556
|
-
const facts = await reader.read(ticket, entry.id, signal);
|
|
557
|
-
const observation = await history.observeSession(entry.id, { signal, projectionMode: "none" });
|
|
558
|
-
try {
|
|
559
|
-
signal.throwIfAborted();
|
|
560
|
-
managed.authority.assertTicket(ticket);
|
|
561
|
-
const resident = ctx.agents.get(entry.id);
|
|
562
|
-
const live = resident === undefined ? ownRoute(observation.events.slice(observation.inheritedEventCount)) : roleRouteComparison(resident).liveRoute;
|
|
563
|
-
const route = evidence.invocation.initialRoute;
|
|
564
|
-
return { evidence: projectChildAdmissionEvidence(evidence, ticket.parentEpoch), prompt, interrupt: prompt,
|
|
565
|
-
invocation: { role: evidence.role, label: facts.descriptor.label ?? entry.label ?? evidence.role, level: evidence.invocation.level,
|
|
566
|
-
routeSource: evidence.invocation.routeSource, route: live.status === "known" ? live.route : route, mode, childId: entry.id },
|
|
567
|
-
routeComparison: { childId: entry.id, initialRoute: { status: "known", source: "invocation-capture", route }, liveRoute: live } };
|
|
568
|
-
}
|
|
569
|
-
finally {
|
|
570
|
-
observation[Symbol.dispose]();
|
|
571
|
-
}
|
|
572
|
-
},
|
|
573
|
-
});
|
|
574
|
-
},
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
function ownRoute(events) {
|
|
578
|
-
let event;
|
|
579
|
-
for (let index = events.length - 1; index >= 0; index--)
|
|
580
|
-
if (events[index].type === "request/header") {
|
|
581
|
-
event = events[index];
|
|
582
|
-
break;
|
|
583
|
-
}
|
|
584
|
-
if (event === undefined)
|
|
585
|
-
return { status: "unknown", reason: "no-own-request-header" };
|
|
586
|
-
const route = event.data?.header?.config;
|
|
587
|
-
if (typeof route?.provider !== "string" || typeof route.model !== "string" || route.reasoningEffort !== undefined && typeof route.reasoningEffort !== "string")
|
|
588
|
-
return { status: "unknown", reason: "invalid-own-request-header" };
|
|
589
|
-
try {
|
|
590
|
-
return { status: "known", source: "own-native-request-header", route: modelRouteFromCall({ ...route, provider: route.provider, model: route.model }) };
|
|
591
|
-
}
|
|
592
|
-
catch {
|
|
593
|
-
return { status: "unknown", reason: "invalid-own-request-header" };
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
function observedOriginalInvocation(agent, admission, label, mode) {
|
|
597
|
-
const original = capturedOriginalRoleInvocation(agent), capture = admission.childCapture;
|
|
598
|
-
if (original === undefined || capture === undefined)
|
|
599
|
-
return undefined;
|
|
600
|
-
const live = roleRouteComparison(agent).liveRoute;
|
|
601
|
-
return { view: { role: capture.role, label: label ?? capture.role, level: original.level, routeSource: original.routeSource,
|
|
602
|
-
route: live.status === "known" ? live.route : original.initialRoute, mode, childId: agent.id },
|
|
603
|
-
routeKind: live.status === "known" ? "actual" : "initial" };
|
|
604
|
-
}
|
|
605
|
-
export function registerRuntimeGuidance(ctx, getSettings, policy) {
|
|
606
|
-
const installed = new WeakSet();
|
|
607
|
-
const install = ({ agent }) => {
|
|
608
|
-
if (installed.has(agent) || !(agent.ctx instanceof Context))
|
|
609
|
-
return;
|
|
610
|
-
const scope = agent.ctx;
|
|
611
|
-
const disposeGuidance = scope.get("systemPrompt")?.section({ name: "dsmm:admitted-guidance", order: 50, text() {
|
|
612
|
-
const settings = getSettings(agent), admission = getSettings.admission(agent), tools = scope.get("tools");
|
|
613
|
-
const schemas = tools?.schemas(agent).filter(schema => policy.toolDenial(agent, schema.name, tools) === undefined) ?? [];
|
|
614
|
-
const descriptor = foldSubagentDescriptor(childOwnedSessionEvents(agent.session));
|
|
615
|
-
const invocation = descriptor === undefined ? undefined : observedOriginalInvocation(agent, admission, descriptor.label, descriptor.mode);
|
|
616
|
-
const runtime = getSettings.subagentRuntime?.();
|
|
617
|
-
let childEvidence = admission.childCapture === undefined ? admission.childEvidence : undefined;
|
|
618
|
-
if (admission.childCapture !== undefined && agent.session.header?.parentSession !== undefined) {
|
|
619
|
-
const parent = scope.get("agents")?.get(SessionId(agent.session.header.parentSession));
|
|
620
|
-
const bound = scope.get("subagents");
|
|
621
|
-
if (parent !== undefined && bound !== undefined && original(bound) instanceof DsmmSubagentRuntime) {
|
|
622
|
-
try {
|
|
623
|
-
const ticket = original(bound).authority.acquireParentTicket(parent);
|
|
624
|
-
childEvidence = projectChildAdmissionEvidence(admission.childCapture, ticket.parentEpoch);
|
|
625
|
-
}
|
|
626
|
-
catch { /* A closing direct parent supplies no current display ticket. */ }
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
return buildDsmmAgentGuidance(settings, { scope: agent.session.header?.origin === "subagent" ? "child" : "root",
|
|
630
|
-
delegation: tools === undefined ? [] : admittedCallableRoleInventory(agent, settings, policy, tools), tools: schemas,
|
|
631
|
-
roleAvailability: admission.roleAvailability, runtimeAdmission: runtime,
|
|
632
|
-
...(invocation === undefined ? {} : { invocation }),
|
|
633
|
-
childEvidence,
|
|
634
|
-
capabilities: { nativeJobs: scope.get("jobs") !== undefined,
|
|
635
|
-
continuable: scope.get("subagents")?.getProvider("spawn")?.prepareContinuable !== undefined && scope.get("sessionPersistence") !== undefined,
|
|
636
|
-
managedChildDelivery: runtime?.binding === "dsmm" && runtime.deliveryFenceReady && scope.get("sessionQuery") !== undefined && scope.get("sessionPersistence") !== undefined },
|
|
637
|
-
});
|
|
638
|
-
} });
|
|
639
|
-
if (disposeGuidance !== undefined)
|
|
640
|
-
ctx.effect?.(() => disposeGuidance);
|
|
641
|
-
installed.add(agent);
|
|
642
|
-
};
|
|
643
|
-
ctx.on?.("agent/created", install, { global: true });
|
|
644
|
-
for (const agent of ctx.get?.("agents")?.list() ?? [])
|
|
645
|
-
install({ agent });
|
|
646
|
-
}
|
|
647
|
-
export function registerRoleControlContribution(ctx) {
|
|
648
|
-
ctx.inject(["typert"], scope => {
|
|
649
|
-
if (scope.typert.getPackage(ROLE_CONTROL_HOST.package, "host") === undefined)
|
|
650
|
-
scope.typert.register(ROLE_CONTROL_HOST);
|
|
651
|
-
new UnavailableRoleControls(scope);
|
|
652
|
-
});
|
|
12
|
+
const native = ctx.get("subagents"), admission = ctx.get("dsmmNativeAdmission"), ready = native !== undefined && admission?.isReady === true;
|
|
13
|
+
return { binding: native === undefined ? "unavailable" : "stock", deliveryFenceReady: ready,
|
|
14
|
+
restartRequired: !ready, ...ready ? {} : { reason: "authority-not-ready" } };
|
|
653
15
|
}
|
|
654
|
-
/** Core exposes a truthful refusal without requiring or impersonating a managed runtime. */
|
|
655
|
-
let UnavailableRoleControls = (() => {
|
|
656
|
-
let _classSuper = TypertRemoteService;
|
|
657
|
-
let _instanceExtraInitializers = [];
|
|
658
|
-
let _describe_decorators;
|
|
659
|
-
let _descendants_decorators;
|
|
660
|
-
let _background_decorators;
|
|
661
|
-
let _prompt_decorators;
|
|
662
|
-
let _interrupt_decorators;
|
|
663
|
-
return class UnavailableRoleControls extends _classSuper {
|
|
664
|
-
static {
|
|
665
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
666
|
-
_describe_decorators = [Remote];
|
|
667
|
-
_descendants_decorators = [Remote];
|
|
668
|
-
_background_decorators = [Remote];
|
|
669
|
-
_prompt_decorators = [Remote];
|
|
670
|
-
_interrupt_decorators = [Remote];
|
|
671
|
-
__esDecorate(this, null, _describe_decorators, { kind: "method", name: "describe", static: false, private: false, access: { has: obj => "describe" in obj, get: obj => obj.describe }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
672
|
-
__esDecorate(this, null, _descendants_decorators, { kind: "method", name: "descendants", static: false, private: false, access: { has: obj => "descendants" in obj, get: obj => obj.descendants }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
673
|
-
__esDecorate(this, null, _background_decorators, { kind: "method", name: "background", static: false, private: false, access: { has: obj => "background" in obj, get: obj => obj.background }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
674
|
-
__esDecorate(this, null, _prompt_decorators, { kind: "method", name: "prompt", static: false, private: false, access: { has: obj => "prompt" in obj, get: obj => obj.prompt }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
675
|
-
__esDecorate(this, null, _interrupt_decorators, { kind: "method", name: "interrupt", static: false, private: false, access: { has: obj => "interrupt" in obj, get: obj => obj.interrupt }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
676
|
-
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
677
|
-
}
|
|
678
|
-
constructor(ctx) {
|
|
679
|
-
super(ctx, "dsmmChildren");
|
|
680
|
-
__runInitializers(this, _instanceExtraInitializers);
|
|
681
|
-
}
|
|
682
|
-
refuse() {
|
|
683
|
-
const connection = this.ctx.get("connection"), invocation = this.ctx.invocation;
|
|
684
|
-
const code = connection === undefined || invocation?.peer !== connection.browserPeer ? "not-owned" : "unavailable";
|
|
685
|
-
throw new RemoteError("dsmm-children/refused", "The Host refused the child control operation.", { code, ...(code === "unavailable" ? { reason: "delivery-fence-unavailable" } : {}) });
|
|
686
|
-
}
|
|
687
|
-
describe(_sessionId) { return this.refuse(); }
|
|
688
|
-
descendants(_sessionId) { return this.refuse(); }
|
|
689
|
-
background(_sessionId, _request) { return this.refuse(); }
|
|
690
|
-
prompt(_sessionId, _request) { return this.refuse(); }
|
|
691
|
-
interrupt(_sessionId, _request) { return this.refuse(); }
|
|
692
|
-
};
|
|
693
|
-
})();
|
|
694
|
-
/** Explicit startup entry; it owns one PUBLIC subclass, never a live replacement. */
|
|
695
|
-
export const subagentRuntimePlugin = { name: "dsmm-subagent-runtime", inject: DsmmSubagentRuntime.inject, Config: SubagentRuntime.Config,
|
|
696
|
-
apply(ctx, config) {
|
|
697
|
-
const runtime = new DsmmSubagentRuntime(ctx, config, classifyDsmmAgent);
|
|
698
|
-
runtimeScopes.set(runtime, ctx);
|
|
699
|
-
} };
|
|
700
|
-
export * from "./subagent-runtime.js";
|
|
701
|
-
export default subagentRuntimePlugin;
|
|
702
16
|
//# sourceMappingURL=runtime-integration.js.map
|