@dsmm/dsmm 0.2.2 → 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 -42
- package/cordis.patch.yml +1 -0
- package/docs/agent-presets.md +26 -14
- package/docs/compatibility.md +20 -79
- 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 -240
- 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 +16 -2
- package/lib/child-capture.js +29 -10
- 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 +26 -51
- 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 +85 -25
- 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 +2716 -2364
- 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 +17 -21
- package/lib/index.js +131 -430
- 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/permission-rpc.js +3 -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 +39 -41
- 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 +106 -64
- 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 -265
- 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 -53
- package/lib/role-policy.js +136 -525
- package/lib/role-providers.d.ts +5 -8
- package/lib/role-providers.js +20 -126
- 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 +149 -97
- package/lib/runtime-integration.d.ts +5 -109
- package/lib/runtime-integration.js +11 -779
- package/lib/session-metadata.d.ts +13 -12
- package/lib/session-metadata.js +6 -31
- package/lib/session-scope.js +6 -2
- 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 +133 -113
- package/docs/research/deepseek-v4-pro.md +0 -74
- package/docs/research/oh-dsh.md +0 -96
- package/lib/child-admission.d.ts +0 -42
- package/lib/child-admission.js +0 -162
- package/lib/delivery-authority.d.ts +0 -68
- package/lib/delivery-authority.js +0 -260
- package/lib/legacy-child-policy.d.ts +0 -51
- package/lib/legacy-child-policy.js +0 -123
- package/lib/legacy-read-composition.d.ts +0 -20
- package/lib/legacy-read-composition.js +0 -144
- package/lib/legacy-read-contracts.d.ts +0 -157
- package/lib/legacy-read-contracts.js +0 -39
- package/lib/legacy-read-host.d.ts +0 -19
- package/lib/legacy-read-host.js +0 -67
- package/lib/legacy-read-integration.d.ts +0 -121
- package/lib/legacy-read-integration.js +0 -522
- package/lib/legacy-read-proxy.d.ts +0 -26
- package/lib/legacy-read-proxy.js +0 -237
- package/lib/native-child-evidence.d.ts +0 -42
- package/lib/native-child-evidence.js +0 -133
- package/lib/role-runs.d.ts +0 -135
- package/lib/role-runs.js +0 -304
- package/lib/session-persistence.d.ts +0 -35
- package/lib/session-persistence.js +0 -304
- package/lib/subagent-runtime.d.ts +0 -45
- package/lib/subagent-runtime.js +0 -131
- package/prompts/deepseek-flash.md +0 -11
- package/prompts/deepseek-v4-pro.md +0 -14
- package/scripts/cold-profile-composition.mjs +0 -329
- package/scripts/cold-profile-sources.mjs +0 -238
- package/scripts/migrate-cold-profile.mjs +0 -315
- package/scripts/repair-session-log.mjs +0 -476
- package/scripts/session-repair-native-verifier.mjs +0 -367
package/lib/role-runs.js
DELETED
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import { settleRun, SubagentError } from "@deepseek-ai/dsh-subagent";
|
|
2
|
-
import { scopeLifetime } from "./delivery-authority.js";
|
|
3
|
-
// Cancellation provenance belongs to each holder, not to a rejection's error code.
|
|
4
|
-
const cancelledDrains = new WeakSet();
|
|
5
|
-
function deferred() {
|
|
6
|
-
let resolve, reject;
|
|
7
|
-
const promise = new Promise((yes, no) => { resolve = yes; reject = no; });
|
|
8
|
-
// Holders remain observable even when a caller stops waiting after handoff.
|
|
9
|
-
void promise.catch(() => { });
|
|
10
|
-
return { promise, resolve, reject };
|
|
11
|
-
}
|
|
12
|
-
function terminalError(result) {
|
|
13
|
-
if (result.stopReason === "completed")
|
|
14
|
-
return undefined;
|
|
15
|
-
const partial = result.output.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
16
|
-
return new SubagentError(`subagent ${result.stopReason}${result.diagnostic === undefined ? "" : `: ${result.diagnostic}`}${partial === "" ? "" : `\nPartial output: ${partial}`}`, result.stopReason.toUpperCase());
|
|
17
|
-
}
|
|
18
|
-
/** One foreground call's real native run and its revocable caller-cancel relay. */
|
|
19
|
-
export class RoleRunHolder {
|
|
20
|
-
controller = new AbortController();
|
|
21
|
-
readyResult = deferred();
|
|
22
|
-
foregroundResult = deferred();
|
|
23
|
-
drainedResult = deferred();
|
|
24
|
-
currentState = "starting";
|
|
25
|
-
identity;
|
|
26
|
-
receipt;
|
|
27
|
-
outcome;
|
|
28
|
-
terminal = false;
|
|
29
|
-
finished = false;
|
|
30
|
-
registering = false;
|
|
31
|
-
committing = false;
|
|
32
|
-
detachParent = () => { };
|
|
33
|
-
callerRelay;
|
|
34
|
-
ready = this.readyResult.promise;
|
|
35
|
-
foreground = this.foregroundResult.promise;
|
|
36
|
-
/** Quiescence, preserving typed result and aggregate cleanup errors even in background. */
|
|
37
|
-
drained = this.drainedResult.promise;
|
|
38
|
-
request;
|
|
39
|
-
collaborators;
|
|
40
|
-
release;
|
|
41
|
-
constructor(request, collaborators, release) {
|
|
42
|
-
this.request = request;
|
|
43
|
-
this.collaborators = collaborators;
|
|
44
|
-
this.release = release;
|
|
45
|
-
this.callerRelay = () => {
|
|
46
|
-
// Native registration cannot fail after its synchronous starter returns.
|
|
47
|
-
// Contained registered-event reentrancy must not let the old caller kill
|
|
48
|
-
// work whose ownership has just committed to the native job.
|
|
49
|
-
if (!this.committing)
|
|
50
|
-
this.cancel(request.callerAbort.reason);
|
|
51
|
-
};
|
|
52
|
-
this.detachParent = scopeLifetime(request.parent.ctx, "dsmm.roleRun: exact parent lifetime", () => {
|
|
53
|
-
if (this.finished)
|
|
54
|
-
return;
|
|
55
|
-
collaborators.teardown.revokeParent(request.parent, "parent-disposed");
|
|
56
|
-
this.cancel(new SubagentError("DSMM run parent was disposed", "ABORTED"));
|
|
57
|
-
});
|
|
58
|
-
request.callerAbort.addEventListener("abort", this.callerRelay, { once: true });
|
|
59
|
-
if (request.callerAbort.aborted)
|
|
60
|
-
this.callerRelay();
|
|
61
|
-
void Promise.resolve().then(() => this.begin());
|
|
62
|
-
}
|
|
63
|
-
get state() { return this.currentState; }
|
|
64
|
-
get owner() { return this.request.owner; }
|
|
65
|
-
get sessionId() { return this.request.sessionId; }
|
|
66
|
-
get toolCallId() { return this.request.toolCallId; }
|
|
67
|
-
get invocation() { return this.identity; }
|
|
68
|
-
get holderSignal() { return this.controller.signal; }
|
|
69
|
-
cancel(reason) {
|
|
70
|
-
if (this.finished)
|
|
71
|
-
return;
|
|
72
|
-
if (!this.terminal)
|
|
73
|
-
this.currentState = "cancelled";
|
|
74
|
-
this.controller.abort(reason);
|
|
75
|
-
}
|
|
76
|
-
background(request) {
|
|
77
|
-
this.assertAddress(request);
|
|
78
|
-
this.assertAuthorization(request);
|
|
79
|
-
if (this.receipt !== undefined)
|
|
80
|
-
return { status: "already-background", receipt: this.receipt };
|
|
81
|
-
if (this.currentState === "cancelled")
|
|
82
|
-
return { status: "cancelled" };
|
|
83
|
-
if (this.terminal)
|
|
84
|
-
return { status: "already-settled" };
|
|
85
|
-
if (this.identity === undefined)
|
|
86
|
-
return { status: "starting" };
|
|
87
|
-
const jobs = this.request.jobs;
|
|
88
|
-
if (jobs === undefined)
|
|
89
|
-
throw new SubagentError("DSMM background requires native jobs and an owner controller", "UNSUPPORTED_CAPABILITY");
|
|
90
|
-
if (this.registering)
|
|
91
|
-
throw new SubagentError("DSMM background registration is already in progress", "UNAUTHORIZED");
|
|
92
|
-
this.registering = true;
|
|
93
|
-
try {
|
|
94
|
-
const jobId = jobs.start({ kind: "subagent", owner: this.request.parent.id, label: this.request.label, run: () => {
|
|
95
|
-
// This is the final, synchronous native-registration critical section.
|
|
96
|
-
this.assertAuthorization(request);
|
|
97
|
-
if (this.terminal || this.controller.signal.aborted)
|
|
98
|
-
throw new SubagentError("DSMM run is no longer transferable", "ABORTED");
|
|
99
|
-
this.committing = true;
|
|
100
|
-
return { cancel: (reason) => this.cancel(reason), done: this.outcome };
|
|
101
|
-
} });
|
|
102
|
-
this.receipt = Object.freeze({ kind: "background", jobId, invocation: this.identity });
|
|
103
|
-
this.request.callerAbort.removeEventListener("abort", this.callerRelay);
|
|
104
|
-
if (!this.controller.signal.aborted && !this.terminal)
|
|
105
|
-
this.currentState = "background";
|
|
106
|
-
this.foregroundResult.resolve(this.receipt);
|
|
107
|
-
return { status: "background", receipt: this.receipt };
|
|
108
|
-
}
|
|
109
|
-
finally {
|
|
110
|
-
this.committing = false;
|
|
111
|
-
this.registering = false;
|
|
112
|
-
// Preflight/authorization failure leaves cancellation and disposal owned
|
|
113
|
-
// by this foreground holder, including a caller abort during preflight.
|
|
114
|
-
if (this.receipt === undefined && this.request.callerAbort.aborted)
|
|
115
|
-
this.callerRelay();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
assertAddress(address) {
|
|
119
|
-
if (address.parent !== this.request.parent || address.owner !== this.request.owner
|
|
120
|
-
|| address.sessionId !== this.request.sessionId || address.toolCallId !== this.request.toolCallId
|
|
121
|
-
|| (this.identity !== undefined && address.runId !== this.identity.runId)) {
|
|
122
|
-
throw new SubagentError("DSMM run requires exact parent, owner and invocation", "UNAUTHORIZED");
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
assertAuthorization(request) {
|
|
126
|
-
const epoch = this.collaborators.currentEpoch(request.parent, request.owner);
|
|
127
|
-
if (epoch !== request.expectedAdmissionEpoch)
|
|
128
|
-
throw new SubagentError("DSMM run admission epoch changed", "UNAUTHORIZED");
|
|
129
|
-
if (this.identity !== undefined && !this.collaborators.canBackground(request.parent, this.identity, epoch)) {
|
|
130
|
-
throw new SubagentError("DSMM background capability is disabled", "UNSUPPORTED_CAPABILITY");
|
|
131
|
-
}
|
|
132
|
-
if (this.collaborators.currentEpoch(request.parent, request.owner) !== epoch) {
|
|
133
|
-
throw new SubagentError("DSMM run admission changed during authorization", "UNAUTHORIZED");
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
async begin() {
|
|
137
|
-
try {
|
|
138
|
-
if (this.controller.signal.aborted) {
|
|
139
|
-
// No native starter has been invoked, so this is holder-owned cancellation.
|
|
140
|
-
cancelledDrains.add(this.drained);
|
|
141
|
-
this.controller.signal.throwIfAborted();
|
|
142
|
-
}
|
|
143
|
-
if (this.collaborators.currentEpoch(this.request.parent, this.request.owner) !== this.request.admissionEpoch) {
|
|
144
|
-
throw new SubagentError("DSMM run admission changed before start", "UNAUTHORIZED");
|
|
145
|
-
}
|
|
146
|
-
const run = await this.request.start(this.controller.signal);
|
|
147
|
-
this.identity = Object.freeze({ parent: this.request.parent, owner: this.request.owner,
|
|
148
|
-
sessionId: this.request.sessionId, toolCallId: this.request.toolCallId, runId: run.id,
|
|
149
|
-
admissionEpoch: this.request.admissionEpoch, capture: this.request.capture, projection: this.request.projection,
|
|
150
|
-
mode: "one-shot", ...(run.localAgent === undefined ? {} : { childId: run.localAgent.id }) });
|
|
151
|
-
if (!this.controller.signal.aborted)
|
|
152
|
-
this.currentState = "running";
|
|
153
|
-
let execution;
|
|
154
|
-
let disposal;
|
|
155
|
-
// Only this read/observer consumes the original native result. Settlement
|
|
156
|
-
// borrows its cached promise and a single disposer, not a replacement run.
|
|
157
|
-
const result = run.result.then((value) => {
|
|
158
|
-
execution = { status: "fulfilled", value };
|
|
159
|
-
this.observed(value.stopReason === "aborted");
|
|
160
|
-
return value;
|
|
161
|
-
}, (reason) => {
|
|
162
|
-
execution = { status: "rejected", reason };
|
|
163
|
-
this.observed(this.controller.signal.aborted);
|
|
164
|
-
throw reason;
|
|
165
|
-
});
|
|
166
|
-
let disposed;
|
|
167
|
-
const dispose = () => disposed ??= Promise.resolve().then(() => {
|
|
168
|
-
if (run.localAgent !== undefined)
|
|
169
|
-
this.collaborators.teardown.revokeParent(run.localAgent, "run-disposed");
|
|
170
|
-
return this.collaborators.teardown.disposeRun(run);
|
|
171
|
-
}).then(() => { disposal = { status: "fulfilled", value: undefined }; }, (reason) => {
|
|
172
|
-
disposal = { status: "rejected", reason };
|
|
173
|
-
throw reason;
|
|
174
|
-
});
|
|
175
|
-
this.outcome = settleRun({ id: run.id, localAgent: run.localAgent, result, dispose });
|
|
176
|
-
this.readyResult.resolve(this.identity);
|
|
177
|
-
await this.outcome;
|
|
178
|
-
const failure = execution.status === "rejected" ? execution.reason : terminalError(execution.value);
|
|
179
|
-
const failed = execution.status === "rejected" || failure !== undefined;
|
|
180
|
-
if (execution.status === "fulfilled" && execution.value.stopReason === "aborted" && disposal.status === "fulfilled") {
|
|
181
|
-
cancelledDrains.add(this.drained);
|
|
182
|
-
}
|
|
183
|
-
if (failed && disposal.status === "rejected")
|
|
184
|
-
throw new AggregateError([failure, disposal.reason], "DSMM subagent result and disposal failed");
|
|
185
|
-
if (execution.status === "rejected")
|
|
186
|
-
throw execution.reason;
|
|
187
|
-
if (failure !== undefined)
|
|
188
|
-
throw failure;
|
|
189
|
-
if (disposal.status === "rejected")
|
|
190
|
-
throw disposal.reason;
|
|
191
|
-
this.foregroundResult.resolve({ kind: "foreground", runId: run.id, invocation: this.identity, output: execution.value.output });
|
|
192
|
-
this.drainedResult.resolve();
|
|
193
|
-
}
|
|
194
|
-
catch (error) {
|
|
195
|
-
this.observed(this.controller.signal.aborted);
|
|
196
|
-
this.readyResult.reject(error);
|
|
197
|
-
this.foregroundResult.reject(error);
|
|
198
|
-
this.drainedResult.reject(error);
|
|
199
|
-
}
|
|
200
|
-
finally {
|
|
201
|
-
this.finished = true;
|
|
202
|
-
this.request.callerAbort.removeEventListener("abort", this.callerRelay);
|
|
203
|
-
this.detachParent();
|
|
204
|
-
this.release();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
observed(cancelled) {
|
|
208
|
-
if (this.terminal)
|
|
209
|
-
return;
|
|
210
|
-
this.terminal = true;
|
|
211
|
-
this.currentState = cancelled || this.controller.signal.aborted ? "cancelled" : "settled";
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/** Current process-local calls only; native jobs remain the sole background registry. */
|
|
215
|
-
export class RoleRunRegistry {
|
|
216
|
-
calls = new Map();
|
|
217
|
-
closed = false;
|
|
218
|
-
collaborators;
|
|
219
|
-
/** ctx is the stable Host-owned scope, not a reinstalled profile entry. */
|
|
220
|
-
constructor(ctx, collaborators) {
|
|
221
|
-
this.collaborators = collaborators;
|
|
222
|
-
scopeLifetime(ctx, "dsmm.roleRuns: close Host admission", () => this.close("host-disposed"));
|
|
223
|
-
ctx.effect(() => () => this.drain(), "dsmm.roleRuns: drain native holders");
|
|
224
|
-
}
|
|
225
|
-
start(request) {
|
|
226
|
-
if (this.closed || request.sessionId !== request.parent.id)
|
|
227
|
-
throw new SubagentError("DSMM run requires a live exact session owner", "UNAUTHORIZED");
|
|
228
|
-
if (this.collaborators.currentEpoch(request.parent, request.owner) !== request.admissionEpoch) {
|
|
229
|
-
throw new SubagentError("DSMM run requires current admission", "UNAUTHORIZED");
|
|
230
|
-
}
|
|
231
|
-
let calls = this.calls.get(request.parent);
|
|
232
|
-
if (calls === undefined) {
|
|
233
|
-
calls = new Map();
|
|
234
|
-
this.calls.set(request.parent, calls);
|
|
235
|
-
}
|
|
236
|
-
if (calls.has(request.toolCallId))
|
|
237
|
-
throw new SubagentError("DSMM invocation is already held", "UNAUTHORIZED");
|
|
238
|
-
const entries = calls;
|
|
239
|
-
try {
|
|
240
|
-
const holder = new RoleRunHolder(request, this.collaborators, () => {
|
|
241
|
-
entries.delete(request.toolCallId);
|
|
242
|
-
if (entries.size === 0)
|
|
243
|
-
this.calls.delete(request.parent);
|
|
244
|
-
});
|
|
245
|
-
entries.set(request.toolCallId, holder);
|
|
246
|
-
return holder;
|
|
247
|
-
}
|
|
248
|
-
catch (error) {
|
|
249
|
-
if (entries.size === 0)
|
|
250
|
-
this.calls.delete(request.parent);
|
|
251
|
-
throw error;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
/** Host-only lookup; C3 must authorize operator/session/epoch before exposing a view. */
|
|
255
|
-
get(parent, owner, address) {
|
|
256
|
-
this.collaborators.currentEpoch(parent, owner);
|
|
257
|
-
const holder = this.calls.get(parent)?.get(address.toolCallId);
|
|
258
|
-
const identity = holder?.invocation;
|
|
259
|
-
return identity?.owner === owner && identity.sessionId === address.sessionId && identity.runId === address.runId ? holder : undefined;
|
|
260
|
-
}
|
|
261
|
-
/** Host-only active-call inventory, including starting calls without invented run ids. */
|
|
262
|
-
list(parent, owner) {
|
|
263
|
-
this.collaborators.currentEpoch(parent, owner);
|
|
264
|
-
return [...this.calls.get(parent)?.values() ?? []].filter((holder) => holder.owner === owner);
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Trusted parent teardown first revokes C1 authority, then awaits this before
|
|
268
|
-
* the original AgentHandle.dispose. Already-revoked tickets are not reacquired.
|
|
269
|
-
*/
|
|
270
|
-
async drainParent(parent, owner, reason) {
|
|
271
|
-
const holders = [...this.calls.get(parent)?.values() ?? []];
|
|
272
|
-
// Trusted teardown may have already revoked the C1 ticket. Match the exact
|
|
273
|
-
// held parent/entry owner, rather than reacquiring revoked admission.
|
|
274
|
-
if (holders.some((holder) => holder.owner !== owner))
|
|
275
|
-
throw new SubagentError("DSMM run drain requires exact owner", "UNAUTHORIZED");
|
|
276
|
-
if (holders.length === 0)
|
|
277
|
-
return;
|
|
278
|
-
this.collaborators.teardown.revokeParent(parent, reason);
|
|
279
|
-
for (const holder of holders)
|
|
280
|
-
holder.cancel(new SubagentError("DSMM run owner was disposed", "ABORTED"));
|
|
281
|
-
await this.awaitHolders(holders);
|
|
282
|
-
}
|
|
283
|
-
close(reason) {
|
|
284
|
-
this.closed = true;
|
|
285
|
-
for (const [parent, calls] of this.calls) {
|
|
286
|
-
this.collaborators.teardown.revokeParent(parent, reason);
|
|
287
|
-
for (const holder of calls.values())
|
|
288
|
-
holder.cancel(new SubagentError("DSMM run Host was disposed", "ABORTED"));
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async drain() {
|
|
292
|
-
await this.awaitHolders([...this.calls.values()].flatMap((calls) => [...calls.values()]));
|
|
293
|
-
}
|
|
294
|
-
async awaitHolders(holders) {
|
|
295
|
-
const results = await Promise.allSettled(holders.map((holder) => holder.drained));
|
|
296
|
-
// Native cancellation is successful teardown; infrastructure/cleanup faults
|
|
297
|
-
// remain errors and are never relabeled as ordinary cancellation.
|
|
298
|
-
const errors = results.flatMap((result, index) => result.status === "rejected"
|
|
299
|
-
&& !cancelledDrains.has(holders[index].drained) ? [result.reason] : []);
|
|
300
|
-
if (errors.length > 0)
|
|
301
|
-
throw new AggregateError(errors, "DSMM native run drain failed");
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
//# sourceMappingURL=role-runs.js.map
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Context, Service } from "@deepseek-ai/cordis";
|
|
2
|
-
import type { SessionHeader, SessionId } from "@deepseek-ai/dsh-session";
|
|
3
|
-
import { SessionPersistence } from "@deepseek-ai/dsh-session-persistence";
|
|
4
|
-
import type { SessionAccess, SessionHandle, SessionPersistenceCreateOptions, SessionPersistenceListOptions, SessionPersistenceOpenOptions, SessionPersistenceStatOptions } from "@deepseek-ai/dsh-session-persistence";
|
|
5
|
-
import type { Config } from "@deepseek-ai/dsh-session-persistence-jsonl";
|
|
6
|
-
export { DSMM_PERSISTENCE_COMPATIBILITY } from "./session-metadata.js";
|
|
7
|
-
export type { Config } from "@deepseek-ai/dsh-session-persistence-jsonl";
|
|
8
|
-
/**
|
|
9
|
-
* Drop-in native JSONL persistence companion for audited DSMM metadata.
|
|
10
|
-
* A separate root Context is intentional: a child service-isolation scope still
|
|
11
|
-
* shares the host event bus and would persist every live event twice.
|
|
12
|
-
*/
|
|
13
|
-
export default class DsmmSessionPersistence extends SessionPersistence {
|
|
14
|
-
readonly config: Config;
|
|
15
|
-
static Config: import("@deepseek-ai/schemastery").default<Config>;
|
|
16
|
-
readonly name = "dsmm-session-persistence";
|
|
17
|
-
private readonly inner;
|
|
18
|
-
private readonly ready;
|
|
19
|
-
private readonly handles;
|
|
20
|
-
private readonly writers;
|
|
21
|
-
private readonly acquisitions;
|
|
22
|
-
private readonly closeFailures;
|
|
23
|
-
private disposed;
|
|
24
|
-
constructor(ctx: Context, config: Config);
|
|
25
|
-
[Service.init](): Promise<void>;
|
|
26
|
-
create(header: SessionHeader, options?: SessionPersistenceCreateOptions): Promise<SessionHandle>;
|
|
27
|
-
open(id: SessionId, access: SessionAccess, options?: SessionPersistenceOpenOptions): Promise<SessionHandle>;
|
|
28
|
-
flush(): Promise<void>;
|
|
29
|
-
stat(id: SessionId, options?: SessionPersistenceStatOptions): Promise<import("@deepseek-ai/dsh-session-persistence").SessionPersistenceSnapshot | undefined>;
|
|
30
|
-
list(options?: SessionPersistenceListOptions): Promise<readonly import("@deepseek-ai/dsh-session-persistence").SessionPersistenceSnapshot[]>;
|
|
31
|
-
private acquire;
|
|
32
|
-
private warn;
|
|
33
|
-
private assertActive;
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=session-persistence.d.ts.map
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import { Context, Service } from "@deepseek-ai/cordis";
|
|
2
|
-
import { SessionHandleClosedError, SessionPersistence, SessionReadOnlyError, materializeAppendBatch } from "@deepseek-ai/dsh-session-persistence";
|
|
3
|
-
import JsonlSessionPersistence from "@deepseek-ai/dsh-session-persistence-jsonl";
|
|
4
|
-
import { isDeepStrictEqual } from "node:util";
|
|
5
|
-
import { annotateDsmmEvent, DSMM_PERSISTENCE_COMPATIBILITY } from "./session-metadata.js";
|
|
6
|
-
export { DSMM_PERSISTENCE_COMPATIBILITY } from "./session-metadata.js";
|
|
7
|
-
/** Host-owned live routing; the native handle remains the sole storage/lock owner. */
|
|
8
|
-
class DsmmSessionHandle {
|
|
9
|
-
native;
|
|
10
|
-
cursor;
|
|
11
|
-
warn;
|
|
12
|
-
released;
|
|
13
|
-
chain = Promise.resolve();
|
|
14
|
-
closing;
|
|
15
|
-
buffered = [];
|
|
16
|
-
timer;
|
|
17
|
-
paused = false;
|
|
18
|
-
failure;
|
|
19
|
-
routingFailure;
|
|
20
|
-
constructor(native, cursor, warn, released) {
|
|
21
|
-
this.native = native;
|
|
22
|
-
this.cursor = cursor;
|
|
23
|
-
this.warn = warn;
|
|
24
|
-
this.released = released;
|
|
25
|
-
}
|
|
26
|
-
get id() { return this.native.id; }
|
|
27
|
-
get header() { return this.native.header; }
|
|
28
|
-
get access() { return this.native.access; }
|
|
29
|
-
get inheritedEventCount() { return this.native.inheritedEventCount; }
|
|
30
|
-
async read(offset, length, options) {
|
|
31
|
-
this.assertOpen("read");
|
|
32
|
-
return this.native.read(offset, length, options);
|
|
33
|
-
}
|
|
34
|
-
async append(events, options) {
|
|
35
|
-
this.assertOpen("append");
|
|
36
|
-
options?.signal?.throwIfAborted();
|
|
37
|
-
const batch = materializeAppendBatch(events).map(annotateDsmmEvent);
|
|
38
|
-
await this.enqueue(async () => {
|
|
39
|
-
options?.signal?.throwIfAborted();
|
|
40
|
-
if (this.access !== "write")
|
|
41
|
-
throw new SessionReadOnlyError(this.id, "append");
|
|
42
|
-
if (this.paused)
|
|
43
|
-
throw this.failure;
|
|
44
|
-
// Live records preceding this explicit batch must commit first. Later live
|
|
45
|
-
// records cannot overtake a direct append waiting on the mutation chain.
|
|
46
|
-
await this.drain(batch[0]?.seq ?? Number.POSITIVE_INFINITY, options?.signal);
|
|
47
|
-
await this.native.append(batch, options);
|
|
48
|
-
this.cursor += batch.length;
|
|
49
|
-
this.scheduleDrain();
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async flush(options) {
|
|
53
|
-
this.assertOpen("flush");
|
|
54
|
-
await this.enqueue(async () => {
|
|
55
|
-
options?.signal?.throwIfAborted();
|
|
56
|
-
if (this.access !== "write")
|
|
57
|
-
throw new SessionReadOnlyError(this.id, "flush");
|
|
58
|
-
this.paused = false;
|
|
59
|
-
await this.drain(Number.POSITIVE_INFINITY, options?.signal);
|
|
60
|
-
await this.native.flush(options);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
enqueueLive(event) {
|
|
64
|
-
if (this.closing !== undefined)
|
|
65
|
-
return;
|
|
66
|
-
let owned;
|
|
67
|
-
try {
|
|
68
|
-
owned = annotateDsmmEvent(materializeAppendBatch([event])[0]);
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
this.routingFailure ??= error;
|
|
72
|
-
this.cancelTimer();
|
|
73
|
-
this.warn(this.id, error);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
this.buffered.push(owned);
|
|
77
|
-
this.scheduleDrain();
|
|
78
|
-
}
|
|
79
|
-
scheduleDrain() {
|
|
80
|
-
if (this.buffered.length === 0 || this.timer !== undefined || this.paused
|
|
81
|
-
|| this.routingFailure !== undefined || this.closing !== undefined)
|
|
82
|
-
return;
|
|
83
|
-
this.timer = setTimeout(() => {
|
|
84
|
-
this.timer = undefined;
|
|
85
|
-
const last = this.buffered.at(-1);
|
|
86
|
-
if (last === undefined)
|
|
87
|
-
return;
|
|
88
|
-
// Fence this queued operation to the prefix accepted now. Events published
|
|
89
|
-
// after a later direct append is queued belong behind that append.
|
|
90
|
-
const beforeSeq = last.seq + 1;
|
|
91
|
-
void this.enqueue(async () => {
|
|
92
|
-
if (!this.paused) {
|
|
93
|
-
await this.drain(beforeSeq);
|
|
94
|
-
this.scheduleDrain();
|
|
95
|
-
}
|
|
96
|
-
}).catch((error) => this.warn(this.id, error));
|
|
97
|
-
}, 200);
|
|
98
|
-
}
|
|
99
|
-
close() {
|
|
100
|
-
return this.closing ??= this.enqueue(async () => {
|
|
101
|
-
this.cancelTimer();
|
|
102
|
-
const errors = [];
|
|
103
|
-
try {
|
|
104
|
-
this.paused = false;
|
|
105
|
-
await this.drain();
|
|
106
|
-
if (this.access === "write")
|
|
107
|
-
await this.native.flush();
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
errors.push(error);
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
await this.native.close();
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
errors.push(error);
|
|
117
|
-
}
|
|
118
|
-
const failure = errors.length > 1 ? new AggregateError(errors, `session "${this.id}": close failed`)
|
|
119
|
-
: errors[0];
|
|
120
|
-
this.released(this, failure);
|
|
121
|
-
if (errors.length > 0)
|
|
122
|
-
throw failure;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
[Symbol.asyncDispose]() { return this.close(); }
|
|
126
|
-
enqueue(operation) {
|
|
127
|
-
const next = this.chain.then(operation);
|
|
128
|
-
// The caller observes rejection; this recovery only keeps later barriers usable.
|
|
129
|
-
this.chain = next.then(() => undefined, () => undefined);
|
|
130
|
-
return next;
|
|
131
|
-
}
|
|
132
|
-
async drain(beforeSeq = Number.POSITIVE_INFINITY, signal) {
|
|
133
|
-
this.cancelTimer();
|
|
134
|
-
if (this.routingFailure !== undefined)
|
|
135
|
-
throw this.routingFailure;
|
|
136
|
-
while (this.buffered.length > 0 && this.buffered[0].seq < beforeSeq) {
|
|
137
|
-
signal?.throwIfAborted();
|
|
138
|
-
const count = this.buffered.findIndex((event) => event.seq >= beforeSeq);
|
|
139
|
-
const batch = this.buffered.slice(0, count < 0 ? undefined : count);
|
|
140
|
-
try {
|
|
141
|
-
// An explicitly appended event may subsequently be published by the live
|
|
142
|
-
// store. Coalesce only byte-equivalent logical events, never conflicts.
|
|
143
|
-
let duplicateCount = 0;
|
|
144
|
-
while (duplicateCount < batch.length && batch[duplicateCount].seq < this.cursor)
|
|
145
|
-
duplicateCount++;
|
|
146
|
-
if (duplicateCount > 0) {
|
|
147
|
-
const existing = await this.native.read(batch[0].seq, duplicateCount, { signal });
|
|
148
|
-
if (!isDeepStrictEqual(existing.events, batch.slice(0, duplicateCount))) {
|
|
149
|
-
throw new Error(`session "${this.id}": live event conflicts with the persisted prefix`);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
const fresh = batch.slice(duplicateCount);
|
|
153
|
-
await this.native.append(fresh, { signal });
|
|
154
|
-
this.cursor += fresh.length;
|
|
155
|
-
this.buffered.splice(0, batch.length);
|
|
156
|
-
this.failure = undefined;
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
this.cancelTimer();
|
|
160
|
-
this.paused = true;
|
|
161
|
-
this.failure = error;
|
|
162
|
-
throw error;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
cancelTimer() {
|
|
167
|
-
if (this.timer !== undefined)
|
|
168
|
-
clearTimeout(this.timer);
|
|
169
|
-
this.timer = undefined;
|
|
170
|
-
}
|
|
171
|
-
assertOpen(operation) {
|
|
172
|
-
if (this.closing !== undefined)
|
|
173
|
-
throw new SessionHandleClosedError(this.id, operation);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Drop-in native JSONL persistence companion for audited DSMM metadata.
|
|
178
|
-
* A separate root Context is intentional: a child service-isolation scope still
|
|
179
|
-
* shares the host event bus and would persist every live event twice.
|
|
180
|
-
*/
|
|
181
|
-
export default class DsmmSessionPersistence extends SessionPersistence {
|
|
182
|
-
config;
|
|
183
|
-
static Config = JsonlSessionPersistence.Config;
|
|
184
|
-
name = "dsmm-session-persistence";
|
|
185
|
-
inner = new Context();
|
|
186
|
-
ready;
|
|
187
|
-
handles = new Set();
|
|
188
|
-
writers = new Map();
|
|
189
|
-
acquisitions = new Set();
|
|
190
|
-
closeFailures = new Map();
|
|
191
|
-
disposed = false;
|
|
192
|
-
constructor(ctx, config) {
|
|
193
|
-
super(ctx);
|
|
194
|
-
this.config = config;
|
|
195
|
-
Object.defineProperty(this, DSMM_PERSISTENCE_COMPATIBILITY, {
|
|
196
|
-
value: true, writable: false, configurable: false, enumerable: false
|
|
197
|
-
});
|
|
198
|
-
const nativeFiber = this.inner.plugin(JsonlSessionPersistence, config);
|
|
199
|
-
this.ready = nativeFiber.await().then(() => this.inner.sessionPersistence);
|
|
200
|
-
ctx.on("session/event", (session, event) => this.writers.get(session.id)?.enqueueLive(event));
|
|
201
|
-
ctx.on("session/flush", (session) => this.writers.get(session.id)?.flush());
|
|
202
|
-
ctx.on("session/disposed", (session) => {
|
|
203
|
-
const writer = this.writers.get(session.id);
|
|
204
|
-
if (writer !== undefined)
|
|
205
|
-
void writer.close().catch((error) => this.warn(session.id, error));
|
|
206
|
-
});
|
|
207
|
-
// One outer disposer enforces the ownership boundary: drain/close every
|
|
208
|
-
// adapter handle before disposing the still-live native storage Context.
|
|
209
|
-
ctx.effect(() => async () => {
|
|
210
|
-
this.disposed = true;
|
|
211
|
-
await Promise.allSettled([...this.acquisitions]);
|
|
212
|
-
const errors = [...this.closeFailures.values()];
|
|
213
|
-
for (const handle of [...this.handles]) {
|
|
214
|
-
try {
|
|
215
|
-
await handle.close();
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
errors.push(error);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
try {
|
|
222
|
-
await this.inner.fiber.dispose();
|
|
223
|
-
}
|
|
224
|
-
catch (error) {
|
|
225
|
-
errors.push(error);
|
|
226
|
-
}
|
|
227
|
-
if (errors.length > 0)
|
|
228
|
-
throw new AggregateError(errors, `${this.name} dispose failed`);
|
|
229
|
-
}, "dsmm-session-persistence ordered shutdown");
|
|
230
|
-
}
|
|
231
|
-
async [Service.init]() { await this.ready; }
|
|
232
|
-
create(header, options) {
|
|
233
|
-
return this.acquire(async (native) => native.create(header, options), false);
|
|
234
|
-
}
|
|
235
|
-
open(id, access, options) {
|
|
236
|
-
return this.acquire(async (native) => native.open(id, access, options), access === "write");
|
|
237
|
-
}
|
|
238
|
-
async flush() {
|
|
239
|
-
this.assertActive();
|
|
240
|
-
const errors = [];
|
|
241
|
-
for (const handle of [...this.writers.values()]) {
|
|
242
|
-
try {
|
|
243
|
-
await handle.flush();
|
|
244
|
-
}
|
|
245
|
-
catch (error) {
|
|
246
|
-
if (!(error instanceof SessionHandleClosedError))
|
|
247
|
-
errors.push(error);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
if (errors.length > 0)
|
|
251
|
-
throw new AggregateError(errors, `${this.name} flush failed`);
|
|
252
|
-
}
|
|
253
|
-
async stat(id, options) {
|
|
254
|
-
this.assertActive();
|
|
255
|
-
return (await this.ready).stat(id, options);
|
|
256
|
-
}
|
|
257
|
-
async list(options) {
|
|
258
|
-
this.assertActive();
|
|
259
|
-
return (await this.ready).list(options);
|
|
260
|
-
}
|
|
261
|
-
acquire(factory, existing) {
|
|
262
|
-
this.assertActive();
|
|
263
|
-
const operation = (async () => {
|
|
264
|
-
const native = await factory(await this.ready);
|
|
265
|
-
let cursor = 0;
|
|
266
|
-
try {
|
|
267
|
-
if (existing)
|
|
268
|
-
cursor = (await native.read()).events.length;
|
|
269
|
-
}
|
|
270
|
-
catch (error) {
|
|
271
|
-
try {
|
|
272
|
-
await native.close();
|
|
273
|
-
}
|
|
274
|
-
catch (closeError) {
|
|
275
|
-
throw new AggregateError([error, closeError], `session "${native.id}": open failed`);
|
|
276
|
-
}
|
|
277
|
-
throw error;
|
|
278
|
-
}
|
|
279
|
-
const handle = new DsmmSessionHandle(native, cursor, (id, error) => this.warn(id, error), (closed, error) => {
|
|
280
|
-
this.handles.delete(closed);
|
|
281
|
-
if (this.writers.get(closed.id) === closed)
|
|
282
|
-
this.writers.delete(closed.id);
|
|
283
|
-
if (error !== undefined)
|
|
284
|
-
this.closeFailures.set(closed.id, error);
|
|
285
|
-
});
|
|
286
|
-
this.handles.add(handle);
|
|
287
|
-
if (handle.access === "write")
|
|
288
|
-
this.writers.set(handle.id, handle);
|
|
289
|
-
return handle;
|
|
290
|
-
})();
|
|
291
|
-
this.acquisitions.add(operation);
|
|
292
|
-
void operation.then(() => this.acquisitions.delete(operation), () => this.acquisitions.delete(operation));
|
|
293
|
-
return operation;
|
|
294
|
-
}
|
|
295
|
-
warn(id, error) {
|
|
296
|
-
const errorClass = error instanceof Error && /^[A-Za-z][A-Za-z0-9]*Error$/u.test(error.name) ? error.name : "Error";
|
|
297
|
-
this.ctx.logger.warn("Deepwork session persistence failed", { sessionId: id, errorClass });
|
|
298
|
-
}
|
|
299
|
-
assertActive() {
|
|
300
|
-
if (this.disposed)
|
|
301
|
-
throw new Error("Deepwork session persistence is disposed");
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
//# sourceMappingURL=session-persistence.js.map
|