@dsmm/dsmm 0.3.11 → 0.3.12
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 +1 -1
- package/docs/agent-presets.md +4 -4
- package/docs/compatibility.md +10 -4
- package/docs/deferred-native-approval-risk.md +1 -1
- package/docs/design.md +15 -5
- package/docs/lsp.md +1 -1
- package/docs/model-routing.md +6 -6
- package/docs/native-permissions.md +1 -1
- package/docs/profiles.md +36 -5
- package/docs/roadmap.md +3 -3
- package/docs/runtime-recovery.md +5 -5
- package/docs/safety-guards.md +1 -1
- package/docs/settings-status.md +3 -3
- package/lib/child-capture.d.ts +9 -0
- package/lib/child-capture.js +24 -1
- package/lib/client/ProfilesSection.js +65 -13
- package/lib/client/RoleToolView-data.d.ts +4 -4
- package/lib/client/RoleToolView-data.js +3 -1
- package/lib/client/RoleToolView-locales.d.ts +7 -4
- package/lib/client/RoleToolView-locales.js +10 -6
- package/lib/client/RoleToolView.js +20 -5
- package/lib/client/SessionProfiles.d.ts +5 -1
- package/lib/client/SessionProfiles.js +13 -9
- package/lib/client/StructuredEditor.d.ts +32 -0
- package/lib/client/StructuredEditor.js +75 -23
- package/lib/client/controller.d.ts +10 -0
- package/lib/client/controller.js +44 -14
- package/lib/client/locales.d.ts +36 -0
- package/lib/client/locales.js +47 -17
- package/lib/client/session-labels.js +4 -1
- package/lib/client/structured.d.ts +4 -0
- package/lib/client/structured.js +16 -1
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +19 -1
- package/lib/client.js +762 -303
- package/lib/host-llm.js +3 -3
- package/lib/index.js +1 -1
- package/lib/model-routing.d.ts +3 -2
- package/lib/model-routing.js +28 -7
- package/lib/native-admission.d.ts +2 -0
- package/lib/native-admission.js +106 -34
- package/lib/profile-runtime.d.ts +11 -0
- package/lib/profile-runtime.js +48 -13
- package/lib/profile-store.d.ts +4 -1
- package/lib/profile-store.js +37 -14
- package/lib/role-control-rpc.js +18 -5
- package/lib/role-llm-runtime.js +10 -1
- package/lib/role-policy.d.ts +4 -3
- package/lib/role-policy.js +6 -6
- package/lib/role-providers.js +1 -0
- package/lib/runtime-recovery.d.ts +2 -2
- package/lib/runtime-recovery.js +7 -4
- package/package.json +1 -1
package/lib/profile-store.js
CHANGED
|
@@ -5,7 +5,7 @@ import { parseTree } from "jsonc-parser";
|
|
|
5
5
|
import { ABSENT_PROFILE_SELECTION_REVISION } from "./profile-types.js";
|
|
6
6
|
import { DsmmProfileError, MAX_PROFILE_BYTES, MAX_PROFILE_COUNT, MAX_PROFILE_DIRECTORY_ENTRIES, MAX_PROFILE_REVISIONS, parseProfileDocument, validateProfileDocument, profileErrorInfo, validateProfileId, validateProfileRevision } from "./profiles.js";
|
|
7
7
|
import { inspectJsonDocument } from "./profile-diagnostics.js";
|
|
8
|
-
import { parseChildAdmissionCapture } from "./child-capture.js";
|
|
8
|
+
import { parseChildAdmissionCapture, parseChildAdmissionIdentity } from "./child-capture.js";
|
|
9
9
|
import { isProfileReference } from "./config-revision.js";
|
|
10
10
|
import { validateAdmissionEpoch } from "./profiles.js";
|
|
11
11
|
export const MAX_SESSION_PROFILE_CHOICES = 1024;
|
|
@@ -83,8 +83,9 @@ export class ProfileStore {
|
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
try {
|
|
86
|
-
const selected = this.selection();
|
|
87
|
-
|
|
86
|
+
const selected = this.selection(true);
|
|
87
|
+
const current = selected.selectedId === null ? undefined : this.draft(selected.selectedId, entries);
|
|
88
|
+
return { ...this.metadata(), profiles, selectedId: selected.selectedId, appliedRevision: selected.appliedRevision, selectionRevision: selected.selectionRevision, ...(selected.sourceRevision === undefined ? {} : { sourceRevision: selected.sourceRevision }), ...(current?.warnings === undefined ? {} : { selectedWarnings: current.warnings }) };
|
|
88
89
|
}
|
|
89
90
|
catch (error) {
|
|
90
91
|
// An error is not a successful fallback to the baseline.
|
|
@@ -129,6 +130,13 @@ export class ProfileStore {
|
|
|
129
130
|
async loadSelection() {
|
|
130
131
|
return this.readOperation(() => this.selection());
|
|
131
132
|
}
|
|
133
|
+
async loadSelectionIdentity() {
|
|
134
|
+
return this.readOperation(() => this.selection(true));
|
|
135
|
+
}
|
|
136
|
+
async loadSessionSelectionIdentity(sessionId) {
|
|
137
|
+
validateSessionProfileId(sessionId);
|
|
138
|
+
return this.readOperation(() => this.sessionSelection(sessionId, undefined, true));
|
|
139
|
+
}
|
|
132
140
|
async loadSessionSelection(sessionId) {
|
|
133
141
|
validateSessionProfileId(sessionId);
|
|
134
142
|
return this.readOperation(() => this.sessionSelection(sessionId));
|
|
@@ -140,7 +148,7 @@ export class ProfileStore {
|
|
|
140
148
|
validateAdmissionEpoch(epoch);
|
|
141
149
|
return this.locked(async (assertLock) => {
|
|
142
150
|
commit.assertCurrent();
|
|
143
|
-
if (this.sessionSelection(request.sessionId).selectionRevision !== request.expectedSelectionRevision)
|
|
151
|
+
if (this.sessionSelection(request.sessionId, undefined, true).selectionRevision !== request.expectedSelectionRevision)
|
|
144
152
|
conflict("The session profile changed. Refresh before selecting again.");
|
|
145
153
|
const draft = request.id === null ? undefined : this.draft(request.id, this.inventory());
|
|
146
154
|
if (draft !== undefined && draft.revision !== request.expectedRevision)
|
|
@@ -158,7 +166,7 @@ export class ProfileStore {
|
|
|
158
166
|
const target = join(directory, `${sessionChoiceKey(request.sessionId)}.json`);
|
|
159
167
|
const fence = (temporary) => {
|
|
160
168
|
commit.assertCurrent();
|
|
161
|
-
if (this.sessionSelection(request.sessionId, temporary).selectionRevision !== request.expectedSelectionRevision)
|
|
169
|
+
if (this.sessionSelection(request.sessionId, temporary, true).selectionRevision !== request.expectedSelectionRevision)
|
|
162
170
|
conflict("The session selection was edited externally. Refresh before selecting again.");
|
|
163
171
|
if (draft !== undefined && this.draft(request.id, this.inventory()).revision !== draft.revision)
|
|
164
172
|
conflict("The draft changed during activation. Reload and select again.");
|
|
@@ -202,7 +210,7 @@ export class ProfileStore {
|
|
|
202
210
|
validateSelectionRequest(request);
|
|
203
211
|
return this.locked(async (assertLock) => {
|
|
204
212
|
assertCurrent?.();
|
|
205
|
-
const current = this.selection();
|
|
213
|
+
const current = this.selection(true);
|
|
206
214
|
if (current.selectionRevision !== request.expectedSelectionRevision)
|
|
207
215
|
conflict("The selected profile changed. Refresh before selecting again.");
|
|
208
216
|
const draft = request.id === null ? undefined : this.draft(request.id, this.inventory());
|
|
@@ -277,7 +285,7 @@ export class ProfileStore {
|
|
|
277
285
|
const file = regularFile(join(this.profileDir, name), MAX_PROFILE_BYTES);
|
|
278
286
|
return { ...file, ...validatedProfile(file.content, id) };
|
|
279
287
|
}
|
|
280
|
-
selection() {
|
|
288
|
+
selection(identityOnly = false) {
|
|
281
289
|
this.validateRoot(false);
|
|
282
290
|
this.validateState(false);
|
|
283
291
|
const path = join(this.stateDir, ".selection.json");
|
|
@@ -289,6 +297,11 @@ export class ProfileStore {
|
|
|
289
297
|
try {
|
|
290
298
|
const file = regularFile(path, 1024);
|
|
291
299
|
const pointer = parseSelectionPointer(file.content);
|
|
300
|
+
if (identityOnly) {
|
|
301
|
+
assertPointerVersion(path, file);
|
|
302
|
+
return { selectedId: pointer.id, appliedRevision: pointer.revision, selectionRevision: file.revision,
|
|
303
|
+
...(pointer.sourceRevision === undefined ? {} : { sourceRevision: pointer.sourceRevision }), document: null, content: null };
|
|
304
|
+
}
|
|
292
305
|
if (pointer.id === null)
|
|
293
306
|
return { selectedId: null, appliedRevision: null, selectionRevision: file.revision, document: null, content: null };
|
|
294
307
|
validateDirectories(join(this.profileDir, ".revisions"), false);
|
|
@@ -304,7 +317,7 @@ export class ProfileStore {
|
|
|
304
317
|
throw new DsmmProfileError("corrupt-selection", "The selected profile pointer or immutable revision is missing or invalid. Repair it explicitly; the baseline was not silently selected.");
|
|
305
318
|
}
|
|
306
319
|
}
|
|
307
|
-
sessionSelection(sessionId, temporary) {
|
|
320
|
+
sessionSelection(sessionId, temporary, identityOnly = false) {
|
|
308
321
|
this.validateRoot(false);
|
|
309
322
|
this.validateState(false);
|
|
310
323
|
const absent = { sessionId, admissionEpoch: null, selectedId: null, appliedRevision: null,
|
|
@@ -323,6 +336,11 @@ export class ProfileStore {
|
|
|
323
336
|
try {
|
|
324
337
|
const file = regularFile(path, 2048);
|
|
325
338
|
const pointer = parseSessionSelectionPointer(file.content, sessionId);
|
|
339
|
+
if (identityOnly) {
|
|
340
|
+
assertPointerVersion(path, file);
|
|
341
|
+
return { ...absent, admissionEpoch: pointer.epoch, selectedId: pointer.id, appliedRevision: pointer.revision,
|
|
342
|
+
selectionRevision: file.revision, ...(pointer.sourceRevision === undefined ? {} : { sourceRevision: pointer.sourceRevision }) };
|
|
343
|
+
}
|
|
326
344
|
if (pointer.id === null)
|
|
327
345
|
return { ...absent, admissionEpoch: pointer.epoch, selectionRevision: file.revision };
|
|
328
346
|
validateDirectories(join(this.profileDir, ".revisions"), false);
|
|
@@ -340,7 +358,7 @@ export class ProfileStore {
|
|
|
340
358
|
}
|
|
341
359
|
}
|
|
342
360
|
assertSelectionRevision(expected) {
|
|
343
|
-
if (this.selection().selectionRevision !== expected)
|
|
361
|
+
if (this.selection(true).selectionRevision !== expected)
|
|
344
362
|
conflict("The selection was edited externally. Refresh before selecting again.");
|
|
345
363
|
}
|
|
346
364
|
publishRevision(draft, assertLock) {
|
|
@@ -420,7 +438,7 @@ export class ProfileStore {
|
|
|
420
438
|
this.validateState(true);
|
|
421
439
|
validateDirectories(directory, true, false, this.identities);
|
|
422
440
|
const path = join(directory, `${sessionChoiceKey(capture.childSessionId)}.json`);
|
|
423
|
-
const existing = this.childAdmission(capture.childSessionId, capture.parentSessionId);
|
|
441
|
+
const existing = this.childAdmission(capture.childSessionId, capture.parentSessionId, parseChildAdmissionCapture);
|
|
424
442
|
if (existing !== null) {
|
|
425
443
|
if (JSON.stringify(existing) !== JSON.stringify(capture))
|
|
426
444
|
conflict("An immutable child admission already exists; it cannot be overwritten.");
|
|
@@ -464,7 +482,12 @@ export class ProfileStore {
|
|
|
464
482
|
async readChildAdmission(childId, parentId) {
|
|
465
483
|
validateSessionProfileId(childId);
|
|
466
484
|
validateSessionProfileId(parentId);
|
|
467
|
-
return this.readOperation(() => this.childAdmission(childId, parentId));
|
|
485
|
+
return this.readOperation(() => this.childAdmission(childId, parentId, parseChildAdmissionCapture));
|
|
486
|
+
}
|
|
487
|
+
async readChildIdentity(childId, parentId) {
|
|
488
|
+
validateSessionProfileId(childId);
|
|
489
|
+
validateSessionProfileId(parentId);
|
|
490
|
+
return this.readOperation(() => this.childAdmission(childId, parentId, parseChildAdmissionIdentity));
|
|
468
491
|
}
|
|
469
492
|
/** Only a trusted native session-deleted handler may call this; drain never does. */
|
|
470
493
|
async deleteChildAdmission(childId, parentId) {
|
|
@@ -472,7 +495,7 @@ export class ProfileStore {
|
|
|
472
495
|
validateSessionProfileId(childId);
|
|
473
496
|
validateSessionProfileId(parentId);
|
|
474
497
|
await this.locked(assertLock => {
|
|
475
|
-
const capture = this.childAdmission(childId, parentId);
|
|
498
|
+
const capture = this.childAdmission(childId, parentId, parseChildAdmissionCapture);
|
|
476
499
|
if (capture === null)
|
|
477
500
|
return;
|
|
478
501
|
const path = join(this.stateDir, ".children", "v1", `${sessionChoiceKey(childId)}.json`);
|
|
@@ -483,7 +506,7 @@ export class ProfileStore {
|
|
|
483
506
|
unlinkSync(path);
|
|
484
507
|
});
|
|
485
508
|
}
|
|
486
|
-
childAdmission(childId, parentId) {
|
|
509
|
+
childAdmission(childId, parentId, parse) {
|
|
487
510
|
this.validateRoot(false);
|
|
488
511
|
this.validateState(false);
|
|
489
512
|
const directory = join(this.stateDir, ".children", "v1");
|
|
@@ -508,7 +531,7 @@ export class ProfileStore {
|
|
|
508
531
|
validateAdmissionEpoch(envelope.revision, "revision");
|
|
509
532
|
if (digest(Buffer.from(JSON.stringify(envelope.capture), "utf8")) !== envelope.revision)
|
|
510
533
|
throw new Error("Capture integrity mismatch");
|
|
511
|
-
const capture =
|
|
534
|
+
const capture = parse(envelope.capture);
|
|
512
535
|
if (capture.childSessionId !== childId || capture.parentSessionId !== parentId)
|
|
513
536
|
throw new Error("Child capture identity mismatch");
|
|
514
537
|
return capture;
|
package/lib/role-control-rpc.js
CHANGED
|
@@ -154,10 +154,10 @@ let DsmmChildrenHost = (() => {
|
|
|
154
154
|
const child = this.ctx.get("agents")?.get(entry.id), direct = parentId === scope.parent.id;
|
|
155
155
|
const live = child && this.admission.get(child), invocation = child && this.admission.invocation(child);
|
|
156
156
|
const available = this.capabilities(scope);
|
|
157
|
-
const reason = !direct ? "not-direct-child" : entry.mode !== "continuable" ? entry.mode === "one-shot" ? "one-shot" : "unknown-mode" :
|
|
158
|
-
const control = reason !== undefined ? disabled(reason) : !this.ctx.get("agents")?.isOwnedBy(child.id, scope.parent) ? disabled("not-direct-child") : available.prompt;
|
|
157
|
+
const reason = !direct ? "not-direct-child" : entry.mode !== "continuable" ? entry.mode === "one-shot" ? "one-shot" : "unknown-mode" : child && !live ? "evidence-unavailable" : undefined;
|
|
158
|
+
const control = reason !== undefined ? disabled(reason) : child && !this.ctx.get("agents")?.isOwnedBy(child.id, scope.parent) ? disabled("not-direct-child") : available.prompt;
|
|
159
159
|
return { id: entry.id, parentSessionId: parentId, mode: entry.mode === "external" ? "unknown" : entry.mode, activity: child?.status === "running" ? "running" : "inactive",
|
|
160
|
-
readonly: !control.enabled, controls: { prompt: control, interrupt: control }, ...(entry.label === undefined ? {} : { label: boundedLabel(entry.label) }),
|
|
160
|
+
readonly: !control.enabled, controls: { prompt: control, interrupt: child ? control : disabled("evidence-unavailable") }, ...(entry.label === undefined ? {} : { label: boundedLabel(entry.label) }),
|
|
161
161
|
...(invocation === undefined ? {} : { invocation: invocationView(invocation, boundedLabel(entry.label ?? invocation.target), "continuable", { childId: entry.id }) }),
|
|
162
162
|
...(child === undefined ? {} : { routeComparison: roleRouteComparison(child) }) };
|
|
163
163
|
}
|
|
@@ -197,8 +197,21 @@ let DsmmChildrenHost = (() => {
|
|
|
197
197
|
throw new ControlRefusal("disabled", undefined, capabilities.prompt.reason);
|
|
198
198
|
if (request.content.some(part => part.type === "image") && !capabilities.images.enabled)
|
|
199
199
|
throw new ControlRefusal("disabled", "content", capabilities.images.reason);
|
|
200
|
-
this.
|
|
201
|
-
|
|
200
|
+
const rows = await this.ctx.get("subagents").listChildren(scope.parent.id, scope.signal);
|
|
201
|
+
scope.check();
|
|
202
|
+
const row = rows.find(row => row.id === request.childSessionId);
|
|
203
|
+
if (!row)
|
|
204
|
+
throw new ControlRefusal("not-owned", "childSessionId");
|
|
205
|
+
if (row.mode !== "continuable")
|
|
206
|
+
throw new ControlRefusal("not-resumable", "childSessionId");
|
|
207
|
+
if (this.ctx.get("agents")?.get(SessionId(request.childSessionId)))
|
|
208
|
+
this.direct(scope, request.childSessionId);
|
|
209
|
+
return this.admission.duringCall(scope.parent, scope.signal, async (signal) => {
|
|
210
|
+
scope.check();
|
|
211
|
+
const receipt = await this.ctx.get("subagents").prompt(request, signal);
|
|
212
|
+
scope.check();
|
|
213
|
+
return receipt;
|
|
214
|
+
});
|
|
202
215
|
});
|
|
203
216
|
}
|
|
204
217
|
interrupt(sessionId, input) {
|
package/lib/role-llm-runtime.js
CHANGED
|
@@ -2,6 +2,7 @@ import { LlmError } from "@deepseek-ai/dsh-llm";
|
|
|
2
2
|
import { captureDsmmEffortSource, requiresDsmmCallAdmission, snapshotDsmmCall } from "./host-llm.js";
|
|
3
3
|
import { resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
4
4
|
import { modelRouteFromCall, projectModelRouteParameters } from "./role-llm.js";
|
|
5
|
+
import { prepareDsmmRequest } from "./model-routing.js";
|
|
5
6
|
/** Connect the cold Host LLM owner to the existing exact Agent/role admission authority. */
|
|
6
7
|
export function createDsmmRoleLlmOwner(ctx, providers) {
|
|
7
8
|
const nativeFallback = async (frame, proposal) => {
|
|
@@ -29,10 +30,18 @@ export function createDsmmRoleLlmOwner(ctx, providers) {
|
|
|
29
30
|
if (original !== admission.admission)
|
|
30
31
|
throw new Error("LLM policy does not own the exact admission");
|
|
31
32
|
const policy = resolvedModelParameterPolicy(original);
|
|
33
|
+
admission.assertCurrent();
|
|
34
|
+
frame.signal.throwIfAborted();
|
|
35
|
+
const routed = await prepareDsmmRequest(frame, proposal, admission.assertCurrent);
|
|
36
|
+
admission.assertCurrent();
|
|
37
|
+
frame.signal.throwIfAborted();
|
|
32
38
|
const effortSource = captureDsmmEffortSource(frame.agent);
|
|
33
|
-
const config = snapshotDsmmCall(projectModelRouteParameters(modelRouteFromCall(
|
|
39
|
+
const config = snapshotDsmmCall(projectModelRouteParameters(modelRouteFromCall(routed), effortSource, policy.mode !== "native-defaults"));
|
|
34
40
|
admission.assertCurrent();
|
|
35
41
|
if (policy.mode !== "passthrough") {
|
|
42
|
+
await ctx.get("llm").resolveCallConfig(config, frame.signal);
|
|
43
|
+
admission.assertCurrent();
|
|
44
|
+
frame.signal.throwIfAborted();
|
|
36
45
|
return { kind: "stock", admission, config, effortSource };
|
|
37
46
|
}
|
|
38
47
|
if (!requiresDsmmCallAdmission(config, providers)) {
|
package/lib/role-policy.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface DsmmRoleIdentity {
|
|
|
13
13
|
readonly readOnly?: boolean;
|
|
14
14
|
readonly toolFilter?: ToolRestriction;
|
|
15
15
|
readonly preset?: string;
|
|
16
|
+
readonly independentComposition?: boolean;
|
|
16
17
|
}
|
|
17
18
|
export declare const READONLY_ROLE_DENIED_TOOLS: readonly ["write", "edit", "bash", "pwsh"];
|
|
18
19
|
export declare function roleToolName(role: DsmmRoleId): string;
|
|
@@ -32,9 +33,9 @@ export declare class DsmmRolePolicy {
|
|
|
32
33
|
assertLive(agent: DshAgent): void;
|
|
33
34
|
private selected;
|
|
34
35
|
validateRootRole(agent: DshAgent, admission: DsmmProfileAdmission): void;
|
|
35
|
-
bindChild(agent: DshAgent, parent: DshAgent, admission: DsmmProfileAdmission, invocation: ResolvedRoleInvocation, maximum: number | undefined, toolFilter: ToolRestriction): void;
|
|
36
|
+
bindChild(agent: DshAgent, parent: DshAgent, admission: DsmmProfileAdmission, invocation: ResolvedRoleInvocation, maximum: number | undefined, toolFilter: ToolRestriction, independentComposition?: boolean): void;
|
|
36
37
|
/** Ordinary native inheritance captures ceilings without inventing a role invocation. */
|
|
37
|
-
bindInheritedChild(agent: DshAgent, parent: DshAgent, admission: DsmmProfileAdmission): void;
|
|
38
|
+
bindInheritedChild(agent: DshAgent, parent: DshAgent, admission: DsmmProfileAdmission, continuation?: boolean): void;
|
|
38
39
|
release(agent: DshAgent): void;
|
|
39
40
|
assertModuleAdmission(agent: DshAgent): void;
|
|
40
41
|
identity(agent: DshAgent): DsmmRoleIdentity;
|
|
@@ -50,7 +51,7 @@ export declare class DsmmRolePolicy {
|
|
|
50
51
|
toolBlacklistDenial(agent: DshAgent, name: string, execution?: Readonly<ToolExecution>): string | undefined;
|
|
51
52
|
captureToolExecution(execution: Readonly<ToolExecution>, _full: boolean): void;
|
|
52
53
|
/** Visible native names are a narrowing ceiling, never permission to execute a definition. */
|
|
53
|
-
|
|
54
|
+
visibleToolCeiling(agent: DshAgent): ToolRestriction;
|
|
54
55
|
delegationToolFilter(execution: Readonly<ToolExecution>): ToolRestriction;
|
|
55
56
|
assertToolExecution(execution: Readonly<ToolExecution>): void;
|
|
56
57
|
beforeToolDecision<T>(operation: () => T): T;
|
package/lib/role-policy.js
CHANGED
|
@@ -61,27 +61,27 @@ export class DsmmRolePolicy {
|
|
|
61
61
|
if (selected?.startsWith("dsmm-") && (!isDsmmRoleId(selected) || !isRootRoleEnabled(admission.settings, selected)))
|
|
62
62
|
throw new SubagentError("Preset is not eligible as a root", "UNAUTHORIZED");
|
|
63
63
|
}
|
|
64
|
-
bindChild(agent, parent, admission, invocation, maximum, toolFilter) {
|
|
64
|
+
bindChild(agent, parent, admission, invocation, maximum, toolFilter, independentComposition = false) {
|
|
65
65
|
this.assertLive(agent);
|
|
66
66
|
this.assertLive(parent);
|
|
67
67
|
this.assertDelegation(parent, invocation.target);
|
|
68
|
-
if (!this.agents().isOwnedBy(agent.id, parent) || agent.session.header?.parentSession !== parent.id || this.selected(agent) !== this.selected(parent))
|
|
68
|
+
if (!this.agents().isOwnedBy(agent.id, parent) || agent.session.header?.parentSession !== parent.id || !independentComposition && this.selected(agent) !== this.selected(parent))
|
|
69
69
|
throw new SubagentError("Child lineage or composition mismatch", "UNAUTHORIZED");
|
|
70
70
|
if (maximum !== undefined && delegationDepthOf(agent) > maximum)
|
|
71
71
|
throw new SubagentError("Delegation depth exceeded", "UNAUTHORIZED");
|
|
72
72
|
const upstream = this.identity(parent);
|
|
73
|
-
liveIdentities.set(agent, Object.freeze({ role: invocation.target, child: true, parent, preset: this.selected(agent), epoch: admission.epoch,
|
|
73
|
+
liveIdentities.set(agent, Object.freeze({ role: invocation.target, child: true, parent, preset: this.selected(agent), epoch: admission.epoch, independentComposition,
|
|
74
74
|
readOnly: this.readOnly(upstream) || DSMM_ROLES.find(row => row.id === invocation.target).access === "read-only",
|
|
75
75
|
toolFilter: inheritToolFilter(inheritToolFilter(upstream.toolFilter, toolFilter), this.visibleToolCeiling(parent)) }));
|
|
76
76
|
bindRoleInvocation(agent, invocation);
|
|
77
77
|
captureRoleRuntimePolicy(admission.settings, invocation.target, invocation.policy);
|
|
78
78
|
}
|
|
79
79
|
/** Ordinary native inheritance captures ceilings without inventing a role invocation. */
|
|
80
|
-
bindInheritedChild(agent, parent, admission) {
|
|
80
|
+
bindInheritedChild(agent, parent, admission, continuation = false) {
|
|
81
81
|
this.assertLive(agent);
|
|
82
82
|
this.assertModuleAdmission(parent);
|
|
83
83
|
const upstream = this.identity(parent), preset = this.selected(agent);
|
|
84
|
-
if (upstream.role !== undefined || preset?.startsWith("dsmm-") || !this.agents().isOwnedBy(agent.id, parent)
|
|
84
|
+
if (!continuation && (upstream.role !== undefined || preset?.startsWith("dsmm-")) || !this.agents().isOwnedBy(agent.id, parent)
|
|
85
85
|
|| agent.session.header?.origin !== "subagent" || agent.session.header.parentSession !== parent.id)
|
|
86
86
|
throw new SubagentError("Ordinary inheritance requires its exact non-controlled parent", "UNAUTHORIZED");
|
|
87
87
|
liveIdentities.set(agent, Object.freeze({ child: true, parent, preset, epoch: admission.epoch,
|
|
@@ -94,7 +94,7 @@ export class DsmmRolePolicy {
|
|
|
94
94
|
if (identity?.child) {
|
|
95
95
|
this.assertLive(identity.parent);
|
|
96
96
|
if (!this.agents().isOwnedBy(agent.id, identity.parent) || selected !== identity.preset
|
|
97
|
-
|| identity.role !== undefined && selected !== this.selected(identity.parent))
|
|
97
|
+
|| identity.role !== undefined && !identity.independentComposition && selected !== this.selected(identity.parent))
|
|
98
98
|
throw new SubagentError("Child admission no longer matches composition", "UNAUTHORIZED");
|
|
99
99
|
}
|
|
100
100
|
else if (agent.session.header?.origin !== "subagent")
|
package/lib/role-providers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DshContext } from "./dsh-types.js";
|
|
1
|
+
import type { AgentRequestFrame, DshLlmCallConfig, DshContext } from "./dsh-types.js";
|
|
2
2
|
import type { DsmmSettingsGetter } from "./settings.js";
|
|
3
3
|
import type { DeepworkModeController } from "./state.js";
|
|
4
|
-
export declare function registerRuntimeRecovery(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter): void;
|
|
4
|
+
export declare function registerRuntimeRecovery(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, bindRequest?: (prepare: (frame: AgentRequestFrame, proposal: DshLlmCallConfig) => Promise<DshLlmCallConfig>) => void): void;
|
|
5
5
|
//# sourceMappingURL=runtime-recovery.d.ts.map
|
package/lib/runtime-recovery.js
CHANGED
|
@@ -60,7 +60,7 @@ function positiveNoOutput(frame, attempt, consumed = false) {
|
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
export function registerRuntimeRecovery(ctx, controller, getSettings) {
|
|
63
|
+
export function registerRuntimeRecovery(ctx, controller, getSettings, bindRequest) {
|
|
64
64
|
if (installedContexts.has(ctx) || ctx.on === undefined)
|
|
65
65
|
return;
|
|
66
66
|
installedContexts.add(ctx);
|
|
@@ -154,8 +154,7 @@ export function registerRuntimeRecovery(ctx, controller, getSettings) {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
}, { prepend: true });
|
|
157
|
-
|
|
158
|
-
const downstream = await next();
|
|
157
|
+
const prepareRequest = async (frame, downstream) => {
|
|
159
158
|
if (!active || !live(frame.agent))
|
|
160
159
|
return downstream;
|
|
161
160
|
const pending = pendingByAgent.get(frame.agent);
|
|
@@ -192,7 +191,11 @@ export function registerRuntimeRecovery(ctx, controller, getSettings) {
|
|
|
192
191
|
lock.route = { ...pending.route };
|
|
193
192
|
recordAdmittedRecoveryRoute(frame, pending.route);
|
|
194
193
|
return applyModelRoute(downstream, pending.route);
|
|
195
|
-
}
|
|
194
|
+
};
|
|
195
|
+
if (bindRequest)
|
|
196
|
+
bindRequest(prepareRequest);
|
|
197
|
+
else
|
|
198
|
+
disposeRequest = ctx.on("agent/request", async (frame, next) => prepareRequest(frame, await next()), { prepend: true });
|
|
196
199
|
disposeRequestError = ctx.on("agent/request-error", async (frame, next) => {
|
|
197
200
|
if (!active || !live(frame.agent) || frame.signal.aborted)
|
|
198
201
|
return undefined;
|