@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/profile-store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Stats } from "node:fs";
|
|
1
|
+
import type { Stats, BigIntStats } from "node:fs";
|
|
2
2
|
import type { ProfileReadResult, ProfileSaveRequest, ProfileSelectRequest, ProfileSelectionState, ProfileSnapshot, SessionProfileSelectRequest } from "./profile-types.js";
|
|
3
3
|
import type { DsmmProfileDocument } from "./profiles.js";
|
|
4
4
|
import type { ProfileDiagnostic } from "./profile-diagnostics.js";
|
|
@@ -23,13 +23,20 @@ export interface SessionProfileCommit<T> {
|
|
|
23
23
|
/** Synchronous publication after durable commit. Must not throw or await. */
|
|
24
24
|
committed(selection: LoadedSessionProfileSelection, prepared: T): void;
|
|
25
25
|
}
|
|
26
|
+
export interface ProfileCommit<T> {
|
|
27
|
+
prepare(selection: LoadedProfileSelection, prepared: T): void;
|
|
28
|
+
committed(selection: LoadedProfileSelection, prepared: T): void;
|
|
29
|
+
}
|
|
26
30
|
export interface ProfileStoreOptions {
|
|
27
31
|
lockTimeoutMs?: number;
|
|
28
32
|
lockPollMs?: number;
|
|
29
33
|
/** Narrow test seam for a failed atomic replacement; never delete the old target. */
|
|
30
34
|
rename?: (source: string, destination: string) => void;
|
|
35
|
+
/** Optional observation seam, after rename and synchronous admission publication. */
|
|
36
|
+
observe?: (path: string) => void;
|
|
31
37
|
}
|
|
32
38
|
interface ProfileFile {
|
|
39
|
+
identity: BigIntStats;
|
|
33
40
|
bytes: Buffer;
|
|
34
41
|
content: string;
|
|
35
42
|
revision: string;
|
|
@@ -47,6 +54,7 @@ export declare class ProfileStore {
|
|
|
47
54
|
private readonly timeoutMs;
|
|
48
55
|
private readonly pollMs;
|
|
49
56
|
private readonly rename;
|
|
57
|
+
private readonly observe?;
|
|
50
58
|
private rootIdentity?;
|
|
51
59
|
readonly origin: ProfileStoreMetadata["origin"];
|
|
52
60
|
private readonly hostProfile?;
|
|
@@ -56,14 +64,15 @@ export declare class ProfileStore {
|
|
|
56
64
|
static fromLegacy(legacyDir: string, options?: ProfileStoreOptions): ProfileStore;
|
|
57
65
|
describe(): Promise<ProfileSnapshot & ProfileStoreMetadata>;
|
|
58
66
|
read(id: string): Promise<ProfileReadResult>;
|
|
59
|
-
|
|
67
|
+
/** The optional fence belongs to the trusted server caller, never the saved document. */
|
|
68
|
+
save(request: ProfileSaveRequest, assertCurrent?: () => void): Promise<ProfileReadResult>;
|
|
60
69
|
loadSelection(): Promise<LoadedProfileSelection>;
|
|
61
70
|
loadSessionSelection(sessionId: string): Promise<LoadedSessionProfileSelection>;
|
|
62
71
|
selectSession<T>(request: SessionProfileSelectRequest, epoch: string, validateCandidate: (document: DsmmProfileDocument | null) => T | Promise<T>, commit: SessionProfileCommit<T>): Promise<{
|
|
63
72
|
selection: LoadedSessionProfileSelection;
|
|
64
73
|
prepared: T;
|
|
65
74
|
}>;
|
|
66
|
-
select<T = undefined>(request: ProfileSelectRequest, validateCandidate?: (document: DsmmProfileDocument | null) => T | Promise<T
|
|
75
|
+
select<T = undefined>(request: ProfileSelectRequest, validateCandidate?: (document: DsmmProfileDocument | null) => T | Promise<T>, commit?: ProfileCommit<T>, assertCurrent?: () => void): Promise<{
|
|
67
76
|
selection: LoadedProfileSelection;
|
|
68
77
|
prepared: T;
|
|
69
78
|
}>;
|
|
@@ -92,7 +101,7 @@ export declare class ProfileStore {
|
|
|
92
101
|
private locked;
|
|
93
102
|
}
|
|
94
103
|
declare function locked<T>(directory: string, lockName: string, validateRoot: (create: boolean) => void, timeoutMs: number, pollMs: number, operation: (assertLock: () => void) => T | Promise<T>): Promise<T>;
|
|
95
|
-
declare function atomicReplace(target: string, bytes: Buffer, beforeRename: (temporary: string) => void, assertAuthority: () => void, rename: (source: string, destination: string) => void, assertCurrent?: () => void):
|
|
104
|
+
declare function atomicReplace(target: string, bytes: Buffer, beforeRename: (temporary: string) => void, assertAuthority: () => void, rename: (source: string, destination: string) => void, assertCurrent?: () => void): BigIntStats;
|
|
96
105
|
declare function trustedHome(home: string): string;
|
|
97
106
|
/** @internal Shared only by the fixed config file adapter; not a wire-path storage API. */
|
|
98
107
|
export declare const profileStoreFilePrimitives: {
|
|
@@ -100,13 +109,16 @@ export declare const profileStoreFilePrimitives: {
|
|
|
100
109
|
validateDirectories: typeof validateDirectories;
|
|
101
110
|
status: typeof status;
|
|
102
111
|
regularFile: typeof regularFile;
|
|
103
|
-
|
|
112
|
+
observeCommitted: typeof observeCommitted;
|
|
104
113
|
boundedOption: typeof boundedOption;
|
|
105
114
|
locked: typeof locked;
|
|
106
115
|
atomicReplace: typeof atomicReplace;
|
|
107
116
|
};
|
|
117
|
+
declare function observeCommitted(path: string, owned: BigIntStats, observe?: (path: string) => void): {
|
|
118
|
+
revision: string;
|
|
119
|
+
refreshRequired?: true;
|
|
120
|
+
};
|
|
108
121
|
declare function boundedOption(value: number | undefined, fallback: number, minimum: number, maximum: number): number;
|
|
109
|
-
declare function digest(bytes: Buffer): string;
|
|
110
122
|
declare function status(path: string): Stats | undefined;
|
|
111
123
|
declare function validateDirectories(directory: string, create: boolean, allowMissing?: boolean, identities?: DirectoryIdentities): boolean;
|
|
112
124
|
declare function regularFile(path: string, maximum: number): ProfileFile;
|
package/lib/profile-store.js
CHANGED
|
@@ -6,6 +6,8 @@ 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
8
|
import { parseChildAdmissionCapture } from "./child-capture.js";
|
|
9
|
+
import { isProfileReference } from "./config-revision.js";
|
|
10
|
+
import { validateAdmissionEpoch } from "./profiles.js";
|
|
9
11
|
export const MAX_SESSION_PROFILE_CHOICES = 1024;
|
|
10
12
|
const trustedLayout = Symbol("trusted profile storage layout");
|
|
11
13
|
const LEGACY_WRITE_RESTRICTION = "Legacy profiles are read-only. Explicitly import them before saving or changing selections.";
|
|
@@ -16,6 +18,7 @@ export class ProfileStore {
|
|
|
16
18
|
timeoutMs;
|
|
17
19
|
pollMs;
|
|
18
20
|
rename;
|
|
21
|
+
observe;
|
|
19
22
|
rootIdentity;
|
|
20
23
|
origin;
|
|
21
24
|
hostProfile;
|
|
@@ -32,6 +35,7 @@ export class ProfileStore {
|
|
|
32
35
|
this.timeoutMs = boundedOption(options.lockTimeoutMs, 2000, 0, 30000);
|
|
33
36
|
this.pollMs = boundedOption(options.lockPollMs, 25, 1, 1000);
|
|
34
37
|
this.rename = options.rename ?? renameSync;
|
|
38
|
+
this.observe = options.observe;
|
|
35
39
|
}
|
|
36
40
|
static fromCentral(home, canonicalHostProfile, actualEntryId, options = {}) {
|
|
37
41
|
const root = trustedHome(home);
|
|
@@ -80,7 +84,7 @@ export class ProfileStore {
|
|
|
80
84
|
});
|
|
81
85
|
try {
|
|
82
86
|
const selected = this.selection();
|
|
83
|
-
return { ...this.metadata(), profiles, selectedId: selected.selectedId, appliedRevision: selected.appliedRevision, selectionRevision: selected.selectionRevision, ...(selected.warnings === undefined ? {} : { selectedWarnings: selected.warnings }) };
|
|
87
|
+
return { ...this.metadata(), profiles, selectedId: selected.selectedId, appliedRevision: selected.appliedRevision, selectionRevision: selected.selectionRevision, ...(selected.sourceRevision === undefined ? {} : { sourceRevision: selected.sourceRevision }), ...(selected.warnings === undefined ? {} : { selectedWarnings: selected.warnings }) };
|
|
84
88
|
}
|
|
85
89
|
catch (error) {
|
|
86
90
|
// An error is not a successful fallback to the baseline.
|
|
@@ -92,14 +96,17 @@ export class ProfileStore {
|
|
|
92
96
|
validateProfileId(id);
|
|
93
97
|
return this.readOperation(() => this.readResult(this.draft(id, this.inventory())));
|
|
94
98
|
}
|
|
95
|
-
|
|
99
|
+
/** The optional fence belongs to the trusted server caller, never the saved document. */
|
|
100
|
+
async save(request, assertCurrent) {
|
|
96
101
|
this.assertWritable();
|
|
102
|
+
assertCurrent?.();
|
|
97
103
|
validateProfileId(request.id);
|
|
98
104
|
const document = parseProfileDocument(request.content, request.id);
|
|
99
105
|
const warnings = validateProfileDocument(request.content, request.id).diagnostics;
|
|
100
106
|
if (request.expectedRevision !== null)
|
|
101
107
|
validateProfileRevision(request.expectedRevision);
|
|
102
108
|
return this.locked((assertLock) => {
|
|
109
|
+
assertCurrent?.();
|
|
103
110
|
const entries = this.inventory();
|
|
104
111
|
const name = this.draftName(request.id, entries);
|
|
105
112
|
const current = name === undefined ? undefined : this.draft(request.id, entries);
|
|
@@ -109,13 +116,14 @@ export class ProfileStore {
|
|
|
109
116
|
throw new DsmmProfileError("limit", "At most 128 Deepwork profiles are supported.");
|
|
110
117
|
const bytes = Buffer.from(request.content, "utf8");
|
|
111
118
|
const target = join(this.profileDir, `${request.id}.jsonc`);
|
|
112
|
-
this.atomicReplace(target, bytes, () => {
|
|
119
|
+
const owned = this.atomicReplace(target, bytes, () => {
|
|
113
120
|
const latestNames = this.inventory();
|
|
114
121
|
const latest = this.draftName(request.id, latestNames) === undefined ? null : this.draft(request.id, latestNames).revision;
|
|
115
122
|
if (latest !== request.expectedRevision)
|
|
116
123
|
conflict("The profile was edited externally during save. Reload it before saving.");
|
|
117
|
-
}, assertLock);
|
|
118
|
-
|
|
124
|
+
}, assertLock, assertCurrent);
|
|
125
|
+
const observed = observeCommitted(target, owned, this.observe);
|
|
126
|
+
return { ...this.readResult({ content: request.content, revision: observed.revision, document, ...(warnings.length ? { warnings } : {}) }), ...observed };
|
|
119
127
|
});
|
|
120
128
|
}
|
|
121
129
|
async loadSelection() {
|
|
@@ -129,7 +137,7 @@ export class ProfileStore {
|
|
|
129
137
|
this.assertWritable();
|
|
130
138
|
validateSessionProfileId(request.sessionId);
|
|
131
139
|
validateSelectionRequest(request);
|
|
132
|
-
|
|
140
|
+
validateAdmissionEpoch(epoch);
|
|
133
141
|
return this.locked(async (assertLock) => {
|
|
134
142
|
commit.assertCurrent();
|
|
135
143
|
if (this.sessionSelection(request.sessionId).selectionRevision !== request.expectedSelectionRevision)
|
|
@@ -165,22 +173,28 @@ export class ProfileStore {
|
|
|
165
173
|
commit.assertCurrent();
|
|
166
174
|
validateDirectories(directory, true, false, this.identities);
|
|
167
175
|
fence();
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const pointer = { version:
|
|
176
|
+
const revision = draft === undefined ? null : this.publishRevision(draft, assertLock);
|
|
177
|
+
const source = draft === undefined ? {} : { sourceRevision: draft.revision };
|
|
178
|
+
const pointer = { version: 2, sessionId: request.sessionId, id: request.id, revision, epoch, ...source };
|
|
171
179
|
const bytes = Buffer.from(`${JSON.stringify(pointer)}\n`, "utf8");
|
|
172
180
|
const selection = { sessionId: request.sessionId, admissionEpoch: epoch,
|
|
173
|
-
selectedId: request.id, appliedRevision:
|
|
181
|
+
selectedId: request.id, appliedRevision: revision, selectionRevision: "unavailable", document: draft?.document ?? null, content: draft?.content ?? null, ...source, ...warningFields(draft) };
|
|
174
182
|
commit.prepare?.(selection, prepared);
|
|
175
|
-
this.atomicReplace(target, bytes, fence, assertLock);
|
|
183
|
+
const owned = this.atomicReplace(target, bytes, fence, assertLock);
|
|
176
184
|
commit.committed(selection, prepared);
|
|
185
|
+
const observed = observeCommitted(target, owned, this.observe);
|
|
186
|
+
selection.selectionRevision = observed.revision;
|
|
187
|
+
if (observed.refreshRequired)
|
|
188
|
+
selection.refreshRequired = true;
|
|
177
189
|
return { selection, prepared };
|
|
178
190
|
});
|
|
179
191
|
}
|
|
180
|
-
async select(request, validateCandidate) {
|
|
192
|
+
async select(request, validateCandidate, commit, assertCurrent) {
|
|
181
193
|
this.assertWritable();
|
|
194
|
+
assertCurrent?.();
|
|
182
195
|
validateSelectionRequest(request);
|
|
183
196
|
return this.locked(async (assertLock) => {
|
|
197
|
+
assertCurrent?.();
|
|
184
198
|
const current = this.selection();
|
|
185
199
|
if (current.selectionRevision !== request.expectedSelectionRevision)
|
|
186
200
|
conflict("The selected profile changed. Refresh before selecting again.");
|
|
@@ -197,24 +211,30 @@ export class ProfileStore {
|
|
|
197
211
|
throw new DsmmProfileError("activation", "The candidate profile could not be activated; the previous selection was retained.");
|
|
198
212
|
}
|
|
199
213
|
// The audit may await native work. Recheck security and CAS afterwards.
|
|
214
|
+
assertCurrent?.();
|
|
200
215
|
assertLock();
|
|
201
216
|
this.assertSelectionRevision(request.expectedSelectionRevision);
|
|
202
217
|
if (draft !== undefined && this.draft(request.id, this.inventory()).revision !== draft.revision)
|
|
203
218
|
conflict("The draft changed during activation. Reload and select again.");
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const pointer = { version:
|
|
219
|
+
const revision = draft === undefined ? null : this.publishRevision(draft, assertLock);
|
|
220
|
+
const source = draft === undefined ? {} : { sourceRevision: draft.revision };
|
|
221
|
+
const pointer = { version: 2, id: request.id, revision, ...source };
|
|
207
222
|
const bytes = Buffer.from(`${JSON.stringify(pointer)}\n`, "utf8");
|
|
208
223
|
this.validateState(true);
|
|
209
|
-
|
|
224
|
+
const selection = { selectedId: request.id, appliedRevision: revision, selectionRevision: "unavailable", document: draft?.document ?? null, content: draft?.content ?? null, ...source, ...warningFields(draft) };
|
|
225
|
+
commit?.prepare(selection, prepared);
|
|
226
|
+
const target = join(this.stateDir, ".selection.json");
|
|
227
|
+
const owned = this.atomicReplace(target, bytes, () => {
|
|
210
228
|
this.assertSelectionRevision(request.expectedSelectionRevision);
|
|
211
229
|
if (draft !== undefined && this.draft(request.id, this.inventory()).revision !== draft.revision)
|
|
212
230
|
conflict("The draft changed during selection. Reload and select again.");
|
|
213
|
-
}, assertLock);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
231
|
+
}, assertLock, assertCurrent);
|
|
232
|
+
commit?.committed(selection, prepared);
|
|
233
|
+
const observed = observeCommitted(target, owned, this.observe);
|
|
234
|
+
selection.selectionRevision = observed.revision;
|
|
235
|
+
if (observed.refreshRequired)
|
|
236
|
+
selection.refreshRequired = true;
|
|
237
|
+
return { selection, prepared };
|
|
218
238
|
});
|
|
219
239
|
}
|
|
220
240
|
readResult(draft) {
|
|
@@ -266,12 +286,11 @@ export class ProfileStore {
|
|
|
266
286
|
return { selectedId: null, appliedRevision: null, selectionRevision: file.revision, document: null, content: null };
|
|
267
287
|
validateDirectories(join(this.profileDir, ".revisions"), false);
|
|
268
288
|
const immutable = regularFile(join(this.profileDir, ".revisions", `${pointer.revision}.jsonc`), MAX_PROFILE_BYTES);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return { selectedId: pointer.id, appliedRevision: pointer.revision, selectionRevision: file.revision, ...validatedProfile(immutable.content, pointer.id), content: immutable.content };
|
|
289
|
+
assertPointerVersion(path, file);
|
|
290
|
+
return { selectedId: pointer.id, appliedRevision: pointer.revision, selectionRevision: file.revision, ...(pointer.sourceRevision === undefined ? {} : { sourceRevision: pointer.sourceRevision }), ...validatedProfile(immutable.content, pointer.id), content: immutable.content };
|
|
272
291
|
}
|
|
273
292
|
catch (error) {
|
|
274
|
-
if (error instanceof DsmmProfileError && error.code === "unsafe-path")
|
|
293
|
+
if (error instanceof DsmmProfileError && (error.code === "unsafe-path" || error.code === "conflict"))
|
|
275
294
|
throw error;
|
|
276
295
|
if (error instanceof DsmmProfileError && error.reason !== undefined)
|
|
277
296
|
throw new DsmmProfileError("corrupt-selection", error.message, error.field, error.reason, error.location);
|
|
@@ -301,13 +320,12 @@ export class ProfileStore {
|
|
|
301
320
|
return { ...absent, admissionEpoch: pointer.epoch, selectionRevision: file.revision };
|
|
302
321
|
validateDirectories(join(this.profileDir, ".revisions"), false);
|
|
303
322
|
const immutable = regularFile(join(this.profileDir, ".revisions", `${pointer.revision}.jsonc`), MAX_PROFILE_BYTES);
|
|
304
|
-
|
|
305
|
-
throw new DsmmProfileError("corrupt-selection", "The session's immutable profile revision failed SHA256 verification.");
|
|
323
|
+
assertPointerVersion(path, file);
|
|
306
324
|
return { sessionId, admissionEpoch: pointer.epoch, selectedId: pointer.id, appliedRevision: pointer.revision,
|
|
307
|
-
selectionRevision: file.revision, ...validatedProfile(immutable.content, pointer.id), content: immutable.content };
|
|
325
|
+
selectionRevision: file.revision, ...(pointer.sourceRevision === undefined ? {} : { sourceRevision: pointer.sourceRevision }), ...validatedProfile(immutable.content, pointer.id), content: immutable.content };
|
|
308
326
|
}
|
|
309
327
|
catch (error) {
|
|
310
|
-
if (error instanceof DsmmProfileError && error.code === "unsafe-path")
|
|
328
|
+
if (error instanceof DsmmProfileError && (error.code === "unsafe-path" || error.code === "conflict"))
|
|
311
329
|
throw error;
|
|
312
330
|
if (error instanceof DsmmProfileError && error.reason !== undefined)
|
|
313
331
|
throw new DsmmProfileError("corrupt-selection", error.message, error.field, error.reason, error.location);
|
|
@@ -322,13 +340,8 @@ export class ProfileStore {
|
|
|
322
340
|
assertLock();
|
|
323
341
|
const directory = join(this.profileDir, ".revisions");
|
|
324
342
|
validateDirectories(directory, true);
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
const existing = regularFile(path, MAX_PROFILE_BYTES);
|
|
328
|
-
if (existing.revision !== draft.revision || !existing.bytes.equals(draft.bytes))
|
|
329
|
-
throw new DsmmProfileError("corrupt-selection", "An immutable profile revision has been altered; no selection was committed.");
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
343
|
+
const revision = `snapshot-v1-${randomUUID()}`;
|
|
344
|
+
const path = join(directory, `${revision}.jsonc`);
|
|
332
345
|
if (boundedEntries(directory, MAX_PROFILE_REVISIONS).length >= MAX_PROFILE_REVISIONS)
|
|
333
346
|
throw new DsmmProfileError("limit", "The immutable revision inventory is full; no selection was committed.");
|
|
334
347
|
let fd;
|
|
@@ -349,12 +362,13 @@ export class ProfileStore {
|
|
|
349
362
|
unlinkSync(path);
|
|
350
363
|
throw error;
|
|
351
364
|
}
|
|
365
|
+
return revision;
|
|
352
366
|
}
|
|
353
|
-
atomicReplace(target, bytes, beforeRename, assertLock) {
|
|
354
|
-
atomicReplace(target, bytes, beforeRename, () => {
|
|
367
|
+
atomicReplace(target, bytes, beforeRename, assertLock, assertCurrent) {
|
|
368
|
+
return atomicReplace(target, bytes, beforeRename, () => {
|
|
355
369
|
assertLock();
|
|
356
370
|
validateDirectories(dirname(target), false, false, this.identities);
|
|
357
|
-
}, this.rename);
|
|
371
|
+
}, this.rename, assertCurrent);
|
|
358
372
|
}
|
|
359
373
|
validateRoot(create) {
|
|
360
374
|
if (this.hostProfile !== undefined)
|
|
@@ -384,8 +398,8 @@ export class ProfileStore {
|
|
|
384
398
|
async createChildAdmission(input, assertCurrent) {
|
|
385
399
|
this.assertWritable();
|
|
386
400
|
const capture = parseChildAdmissionCapture(input);
|
|
387
|
-
if (capture.version !==
|
|
388
|
-
throw new DsmmProfileError("validation", "New child admissions require capture
|
|
401
|
+
if (capture.version !== 3)
|
|
402
|
+
throw new DsmmProfileError("validation", "New child admissions require capture v3.");
|
|
389
403
|
const revision = digest(Buffer.from(JSON.stringify(capture), "utf8"));
|
|
390
404
|
const bytes = Buffer.from(`${JSON.stringify({ version: 1, revision, capture })}\n`, "utf8");
|
|
391
405
|
if (bytes.length > MAX_PROFILE_BYTES)
|
|
@@ -484,7 +498,7 @@ export class ProfileStore {
|
|
|
484
498
|
const envelope = JSON.parse(file.content);
|
|
485
499
|
if (envelope === null || typeof envelope !== "object" || Array.isArray(envelope) || Object.keys(envelope).length !== 3 || envelope.version !== 1 || !Object.hasOwn(envelope, "revision") || !Object.hasOwn(envelope, "capture"))
|
|
486
500
|
throw new Error("Invalid capture envelope");
|
|
487
|
-
|
|
501
|
+
validateAdmissionEpoch(envelope.revision, "revision");
|
|
488
502
|
if (digest(Buffer.from(JSON.stringify(envelope.capture), "utf8")) !== envelope.revision)
|
|
489
503
|
throw new Error("Capture integrity mismatch");
|
|
490
504
|
const capture = parseChildAdmissionCapture(envelope.capture);
|
|
@@ -500,14 +514,10 @@ export class ProfileStore {
|
|
|
500
514
|
if (this.origin === "explicit")
|
|
501
515
|
return this.locked(operation);
|
|
502
516
|
try {
|
|
503
|
-
const
|
|
504
|
-
const second = operation();
|
|
517
|
+
const result = operation();
|
|
505
518
|
this.validateRoot(false);
|
|
506
519
|
this.validateState(false);
|
|
507
|
-
|
|
508
|
-
throw new DsmmProfileError(this.origin === "legacy" ? "corrupt-selection" : "conflict", "Profile storage changed during the read. No selection was admitted; retry after it is stable.");
|
|
509
|
-
}
|
|
510
|
-
return second;
|
|
520
|
+
return result;
|
|
511
521
|
}
|
|
512
522
|
catch (error) {
|
|
513
523
|
if (error instanceof DsmmProfileError)
|
|
@@ -596,6 +606,7 @@ function atomicReplace(target, bytes, beforeRename, assertAuthority, rename, ass
|
|
|
596
606
|
fd = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
|
|
597
607
|
created = true;
|
|
598
608
|
owned = fstatSync(fd);
|
|
609
|
+
const ownedIdentity = fstatSync(fd, { bigint: true });
|
|
599
610
|
assertRegular(owned);
|
|
600
611
|
writeAll(fd, bytes);
|
|
601
612
|
fsyncSync(fd);
|
|
@@ -612,7 +623,7 @@ function atomicReplace(target, bytes, beforeRename, assertAuthority, rename, ass
|
|
|
612
623
|
assertCurrent?.();
|
|
613
624
|
rename(temporary, target);
|
|
614
625
|
created = false;
|
|
615
|
-
|
|
626
|
+
return ownedIdentity;
|
|
616
627
|
}
|
|
617
628
|
finally {
|
|
618
629
|
if (fd !== undefined)
|
|
@@ -641,7 +652,26 @@ function trustedHome(home) {
|
|
|
641
652
|
return root;
|
|
642
653
|
}
|
|
643
654
|
/** @internal Shared only by the fixed config file adapter; not a wire-path storage API. */
|
|
644
|
-
export const profileStoreFilePrimitives = { trustedHome, validateDirectories, status, regularFile,
|
|
655
|
+
export const profileStoreFilePrimitives = { trustedHome, validateDirectories, status, regularFile, observeCommitted, boundedOption, locked, atomicReplace };
|
|
656
|
+
function statRevision(stat) { return `stat-v1-${stat.mtimeNs}-${stat.ctimeNs}`; }
|
|
657
|
+
function assertPointerVersion(path, file) {
|
|
658
|
+
if (observeCommitted(path, file.identity).revision !== file.revision)
|
|
659
|
+
conflict("The selection version changed while reading its snapshot.");
|
|
660
|
+
}
|
|
661
|
+
function observeCommitted(path, owned, observe) {
|
|
662
|
+
try {
|
|
663
|
+
observe?.(path);
|
|
664
|
+
validateDirectories(dirname(path), false);
|
|
665
|
+
const named = lstatSync(path, { bigint: true });
|
|
666
|
+
assertRegular(named);
|
|
667
|
+
if (named.dev !== owned.dev || named.ino !== owned.ino)
|
|
668
|
+
throw new Error("Committed target was replaced");
|
|
669
|
+
return { revision: statRevision(named) };
|
|
670
|
+
}
|
|
671
|
+
catch {
|
|
672
|
+
return { revision: "unavailable", refreshRequired: true };
|
|
673
|
+
}
|
|
674
|
+
}
|
|
645
675
|
function boundedOption(value, fallback, minimum, maximum) {
|
|
646
676
|
if (value === undefined)
|
|
647
677
|
return fallback;
|
|
@@ -703,7 +733,7 @@ function validateDirectories(directory, create, allowMissing = false, identities
|
|
|
703
733
|
return true;
|
|
704
734
|
}
|
|
705
735
|
function assertRegular(found) {
|
|
706
|
-
if (found.isSymbolicLink() || !found.isFile() || found.nlink !== 1)
|
|
736
|
+
if (found.isSymbolicLink() || !found.isFile() || (found.nlink !== 1 && found.nlink !== 1n))
|
|
707
737
|
throw new DsmmProfileError("unsafe-path", "Profile files and lock files must be regular, unlinked files, not symlinks, junctions, directories or hard links.");
|
|
708
738
|
}
|
|
709
739
|
function sameFile(first, second) {
|
|
@@ -721,6 +751,7 @@ function regularFile(path, maximum) {
|
|
|
721
751
|
try {
|
|
722
752
|
validateDirectories(dirname(path), false);
|
|
723
753
|
const opened = fstatSync(fd);
|
|
754
|
+
const openedVersion = fstatSync(fd, { bigint: true });
|
|
724
755
|
assertRegular(opened);
|
|
725
756
|
if (!sameFile(before, opened))
|
|
726
757
|
conflict("The profile file changed while it was opened. Retry the operation.");
|
|
@@ -735,13 +766,17 @@ function regularFile(path, maximum) {
|
|
|
735
766
|
if (size > maximum)
|
|
736
767
|
throw new DsmmProfileError("limit", "Profile storage contains an oversized file.");
|
|
737
768
|
const after = fstatSync(fd);
|
|
769
|
+
const afterVersion = fstatSync(fd, { bigint: true });
|
|
738
770
|
const named = status(path);
|
|
771
|
+
const namedVersion = lstatSync(path, { bigint: true });
|
|
739
772
|
validateDirectories(dirname(path), false);
|
|
740
773
|
assertRegular(after);
|
|
741
774
|
if (named !== undefined)
|
|
742
775
|
assertRegular(named);
|
|
743
776
|
if (named === undefined || !sameFile(opened, named) || opened.size !== after.size || opened.mtimeMs !== after.mtimeMs || opened.ctimeMs !== after.ctimeMs)
|
|
744
777
|
conflict("The profile file was edited while being read. Retry the operation.");
|
|
778
|
+
if (statRevision(openedVersion) !== statRevision(afterVersion) || statRevision(afterVersion) !== statRevision(namedVersion) || afterVersion.ino !== namedVersion.ino || afterVersion.dev !== namedVersion.dev)
|
|
779
|
+
conflict("The file version changed while being read.");
|
|
745
780
|
const bytes = buffer.subarray(0, size);
|
|
746
781
|
let content;
|
|
747
782
|
try {
|
|
@@ -750,7 +785,7 @@ function regularFile(path, maximum) {
|
|
|
750
785
|
catch {
|
|
751
786
|
throw new DsmmProfileError("validation", "Profile files must contain valid UTF-8 text.", "content");
|
|
752
787
|
}
|
|
753
|
-
return { bytes, content, revision:
|
|
788
|
+
return { bytes, content, revision: statRevision(afterVersion), identity: afterVersion };
|
|
754
789
|
}
|
|
755
790
|
finally {
|
|
756
791
|
closeSync(fd);
|
|
@@ -786,8 +821,8 @@ function writeAll(fd, bytes) {
|
|
|
786
821
|
function parseSelectionPointer(content) {
|
|
787
822
|
const errors = [];
|
|
788
823
|
const tree = parseTree(content, errors, { disallowComments: true, allowTrailingComma: false, allowEmptyContent: false });
|
|
789
|
-
if (tree?.type !== "object" || errors.length > 0
|
|
790
|
-
throw new DsmmProfileError("corrupt-selection", "The selected profile pointer must contain
|
|
824
|
+
if (tree?.type !== "object" || errors.length > 0)
|
|
825
|
+
throw new DsmmProfileError("corrupt-selection", "The selected profile pointer must contain unique fields in valid JSON.");
|
|
791
826
|
let input;
|
|
792
827
|
try {
|
|
793
828
|
input = JSON.parse(content);
|
|
@@ -798,13 +833,19 @@ function parseSelectionPointer(content) {
|
|
|
798
833
|
if (typeof input !== "object" || input === null || Array.isArray(input))
|
|
799
834
|
throw new DsmmProfileError("corrupt-selection", "The selected profile pointer must be a versioned object.");
|
|
800
835
|
const record = input;
|
|
801
|
-
|
|
836
|
+
const allowed = ["version", "id", "revision", ...record.version === 2 ? ["sourceRevision"] : []];
|
|
837
|
+
if (tree.children?.length !== Object.keys(record).length || !["version", "id", "revision"].every((key) => Object.hasOwn(record, key)) || Object.keys(record).some(key => !allowed.includes(key)) || (record.version !== 1 && record.version !== 2))
|
|
802
838
|
throw new DsmmProfileError("corrupt-selection", "The selected profile pointer has an unsupported shape or version.");
|
|
803
|
-
if (record.id === null && record.revision === null)
|
|
804
|
-
return { version:
|
|
839
|
+
if (record.id === null && record.revision === null && !Object.hasOwn(record, "sourceRevision"))
|
|
840
|
+
return { version: record.version, id: null, revision: null };
|
|
805
841
|
validateProfileId(record.id);
|
|
806
|
-
|
|
807
|
-
|
|
842
|
+
if (!isProfileReference(record.revision))
|
|
843
|
+
throw new DsmmProfileError("corrupt-selection", "Invalid snapshot reference.");
|
|
844
|
+
if (record.version === 1)
|
|
845
|
+
validateAdmissionEpoch(record.revision, "revision");
|
|
846
|
+
if (Object.hasOwn(record, "sourceRevision"))
|
|
847
|
+
validateProfileRevision(record.sourceRevision, "sourceRevision");
|
|
848
|
+
return { version: record.version, id: record.id, revision: record.revision, ...(typeof record.sourceRevision === "string" ? { sourceRevision: record.sourceRevision } : {}) };
|
|
808
849
|
}
|
|
809
850
|
export function validateSessionProfileId(id) {
|
|
810
851
|
if (typeof id !== "string" || id.length < 1 || id.length > 256 || /[\u0000-\u001f\u007f]/u.test(id) || Buffer.from(id, "utf8").toString("utf8") !== id) {
|
|
@@ -826,14 +867,15 @@ function validateSelectionRequest(request) {
|
|
|
826
867
|
function parseSessionSelectionPointer(content, sessionId) {
|
|
827
868
|
const errors = [];
|
|
828
869
|
const tree = parseTree(content, errors, { disallowComments: true, allowTrailingComma: false, allowEmptyContent: false });
|
|
829
|
-
if (tree?.type !== "object" || errors.length > 0
|
|
830
|
-
throw new DsmmProfileError("corrupt-selection", "The session choice must contain
|
|
870
|
+
if (tree?.type !== "object" || errors.length > 0)
|
|
871
|
+
throw new DsmmProfileError("corrupt-selection", "The session choice must contain unique fields in valid JSON.");
|
|
831
872
|
const record = JSON.parse(content);
|
|
832
|
-
|
|
873
|
+
const allowed = ["version", "sessionId", "id", "revision", "epoch", ...record.version === 2 ? ["sourceRevision"] : []];
|
|
874
|
+
if (tree.children?.length !== Object.keys(record).length || Object.keys(record).some(key => !allowed.includes(key)) || !["version", "sessionId", "id", "revision", "epoch"].every((key) => Object.hasOwn(record, key)) || record.sessionId !== sessionId) {
|
|
833
875
|
throw new DsmmProfileError("corrupt-selection", "The session choice identity, shape or version is invalid.");
|
|
834
876
|
}
|
|
835
|
-
|
|
836
|
-
const selection = parseSelectionPointer(JSON.stringify({ version: record.version, id: record.id, revision: record.revision }));
|
|
877
|
+
validateAdmissionEpoch(record.epoch);
|
|
878
|
+
const selection = parseSelectionPointer(JSON.stringify({ version: record.version, id: record.id, revision: record.revision, ...Object.hasOwn(record, "sourceRevision") ? { sourceRevision: record.sourceRevision } : {} }));
|
|
837
879
|
return { ...selection, sessionId, epoch: record.epoch };
|
|
838
880
|
}
|
|
839
881
|
function conflict(message) {
|
package/lib/profile-types.d.ts
CHANGED
|
@@ -42,10 +42,11 @@ export interface DsmmInvocationView {
|
|
|
42
42
|
routeComparison?: DsmmRoleRouteComparison;
|
|
43
43
|
}
|
|
44
44
|
export interface SubagentRuntimeAdmissionView {
|
|
45
|
-
binding: "stock" | "
|
|
45
|
+
binding: "stock" | "unavailable";
|
|
46
|
+
/** Native execution admission readiness; not an inbox-acceptance veto. */
|
|
46
47
|
deliveryFenceReady: boolean;
|
|
47
48
|
restartRequired: boolean;
|
|
48
|
-
reason?: "
|
|
49
|
+
reason?: "authority-not-ready";
|
|
49
50
|
}
|
|
50
51
|
export interface DsmmRoleAvailabilityState {
|
|
51
52
|
id: DsmmRoleId;
|
|
@@ -107,6 +108,8 @@ export interface DeploymentEditorSnapshot {
|
|
|
107
108
|
startupSources?: Record<string, string>;
|
|
108
109
|
defaults: Record<string, unknown>;
|
|
109
110
|
schema: DeploymentSchemaNode;
|
|
111
|
+
nativeSchema?: DeploymentSchemaNode;
|
|
112
|
+
subagentRuntime?: SubagentRuntimeAdmissionView;
|
|
110
113
|
nextRoot: DeploymentAdmissionView | null;
|
|
111
114
|
modules: DsmmModuleState[];
|
|
112
115
|
}
|
|
@@ -127,6 +130,8 @@ export interface ProfileSummary {
|
|
|
127
130
|
error?: ProfileErrorInfo;
|
|
128
131
|
}
|
|
129
132
|
export interface ProfileSelectionState {
|
|
133
|
+
sourceRevision?: string;
|
|
134
|
+
refreshRequired?: true;
|
|
130
135
|
selectedId: string | null;
|
|
131
136
|
appliedRevision: string | null;
|
|
132
137
|
selectionRevision: string;
|
|
@@ -143,6 +148,7 @@ export interface ProfileSnapshot extends ProfileSelectionState {
|
|
|
143
148
|
writeRestriction?: string;
|
|
144
149
|
}
|
|
145
150
|
export interface ProfileReadResult {
|
|
151
|
+
refreshRequired?: true;
|
|
146
152
|
warnings?: ProfileDiagnostic[];
|
|
147
153
|
id: string;
|
|
148
154
|
label?: string;
|
|
@@ -177,13 +183,15 @@ export interface DsmmRoleRuntimeState {
|
|
|
177
183
|
switches: number;
|
|
178
184
|
totalDelayMs: number;
|
|
179
185
|
}
|
|
186
|
+
export type SessionActionUnavailableReason = "busy" | "maintenance" | "module-off" | "runtime-unavailable" | "model-unconfigured" | "model-service-unavailable" | "new-session-required";
|
|
180
187
|
export interface SessionProfileSnapshot {
|
|
188
|
+
refreshRequired?: true;
|
|
181
189
|
warnings?: ProfileDiagnostic[];
|
|
182
190
|
roles?: DsmmRoleAvailabilityState[];
|
|
183
191
|
subagentRuntime?: SubagentRuntimeAdmissionView;
|
|
184
192
|
sessionId: string;
|
|
185
193
|
globalDefault: ProfileSelectionState;
|
|
186
|
-
/** Current
|
|
194
|
+
/** Current selection state: the authority for session-selection CAS. */
|
|
187
195
|
selection: ProfileSelectionState;
|
|
188
196
|
/** Exact live admission, for display only; may differ from the future global default. */
|
|
189
197
|
admittedSelection?: ProfileSelectionState;
|
|
@@ -191,10 +199,16 @@ export interface SessionProfileSnapshot {
|
|
|
191
199
|
admissionEpoch: string;
|
|
192
200
|
switchAllowed: boolean;
|
|
193
201
|
switchUnavailableReason?: "busy" | "maintenance" | "disposed" | "not-owned" | "unavailable";
|
|
202
|
+
canSelectModel: boolean;
|
|
203
|
+
selectModelUnavailableReason?: SessionActionUnavailableReason;
|
|
204
|
+
canToggleMode: boolean;
|
|
205
|
+
toggleModeUnavailableReason?: SessionActionUnavailableReason;
|
|
206
|
+
canApplyOverlay: boolean;
|
|
207
|
+
applyOverlayUnavailableReason?: SessionActionUnavailableReason;
|
|
194
208
|
rolePolicy?: DsmmRoleRuntimeState;
|
|
195
209
|
/** Declared profile primary for the current ordinary root role, not an applied native selection. */
|
|
196
210
|
profileModel?: DsmmModelRoute;
|
|
197
|
-
/**
|
|
211
|
+
/** Explicit session intent always beats defaults. */
|
|
198
212
|
deepwork?: SessionDeepworkState;
|
|
199
213
|
/** Safe captured module admission; not a read of the current global editor. */
|
|
200
214
|
modules?: DsmmModuleState[];
|
package/lib/profiles.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const MAX_PROFILE_BYTES: number;
|
|
|
6
6
|
export declare const MAX_PROFILE_COUNT = 128;
|
|
7
7
|
export declare const MAX_PROFILE_DIRECTORY_ENTRIES = 1024;
|
|
8
8
|
export declare const MAX_PROFILE_REVISIONS = 1024;
|
|
9
|
-
export type DsmmProfileOverlay = Pick<DsmmPluginConfig, "modelParameters" | "defaultActive" | "roleRouting" | "runtimePolicy" | "workflow" | "guards" | "runtimeRecovery" | "roles" | "locale"
|
|
9
|
+
export type DsmmProfileOverlay = Pick<DsmmPluginConfig, "modelParameters" | "defaultActive" | "roleRouting" | "runtimePolicy" | "workflow" | "guards" | "runtimeRecovery" | "roles" | "locale"> & {
|
|
10
10
|
subagents?: Pick<NonNullable<DsmmPluginConfig["subagents"]>, "toolTopology">;
|
|
11
11
|
};
|
|
12
12
|
export interface DsmmProfileDocument {
|
|
@@ -26,6 +26,8 @@ export declare class DsmmProfileError extends Error {
|
|
|
26
26
|
export declare function profileErrorInfo(error: unknown, fallback?: ProfileErrorCode): ProfileErrorInfo;
|
|
27
27
|
export declare function validateProfileId(id: unknown): asserts id is string;
|
|
28
28
|
export declare function validateProfileRevision(revision: unknown, field?: string): asserts revision is string;
|
|
29
|
+
export { isConfigRevision, isProfileReference } from "./config-revision.js";
|
|
30
|
+
export declare function validateAdmissionEpoch(value: unknown, field?: string): asserts value is string;
|
|
29
31
|
export declare function parseProfileDocument(content: string, expectedId?: string): DsmmProfileDocument;
|
|
30
32
|
export declare function validateProfileDocument(content: string, expectedId?: string): {
|
|
31
33
|
document?: DsmmProfileDocument;
|
package/lib/profiles.js
CHANGED
|
@@ -36,10 +36,16 @@ export function validateProfileId(id) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
export function validateProfileRevision(revision, field = "expectedRevision") {
|
|
39
|
-
if (
|
|
40
|
-
invalid(field, "must be a
|
|
39
|
+
if (!isConfigRevision(revision))
|
|
40
|
+
invalid(field, "must be a configuration version");
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
export { isConfigRevision, isProfileReference } from "./config-revision.js";
|
|
43
|
+
import { isConfigRevision } from "./config-revision.js";
|
|
44
|
+
export function validateAdmissionEpoch(value, field = "admissionEpoch") {
|
|
45
|
+
if (typeof value !== "string" || !/^[a-f0-9]{64}$/u.test(value))
|
|
46
|
+
invalid(field, "must be an admission identity");
|
|
47
|
+
}
|
|
48
|
+
const OVERLAY_FIELDS = ["modelParameters", "defaultActive", "roleRouting", "runtimePolicy", "workflow", "guards", "runtimeRecovery", "roles", "locale", "subagents"];
|
|
43
49
|
export function parseProfileDocument(content, expectedId) {
|
|
44
50
|
const result = validateProfileDocument(content, expectedId);
|
|
45
51
|
const error = result.diagnostics.find(item => item.severity === "error");
|
|
@@ -106,10 +112,6 @@ export function validateProfileOverlay(input) {
|
|
|
106
112
|
keys(parameters, ["passthrough"], field);
|
|
107
113
|
optional(parameters, "passthrough", bool, field);
|
|
108
114
|
}, "settings");
|
|
109
|
-
for (const prefix of ["deepseekV4Pro", "deepseekFlash"]) {
|
|
110
|
-
optional(overlay, `${prefix}Calibration`, (value, field) => enumeration(value, ["off", "auto", "strict"], field), "settings");
|
|
111
|
-
optional(overlay, `${prefix}DefaultReasoningEffort`, (value, field) => enumeration(value, ["off", "low", "high"], field), "settings");
|
|
112
|
-
}
|
|
113
115
|
optional(overlay, "roleRouting", roleRouting, "settings");
|
|
114
116
|
optional(overlay, "runtimePolicy", runtimePolicy, "settings");
|
|
115
117
|
optional(overlay, "workflow", workflow, "settings");
|
package/lib/prompt-content.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface SourceRoleContent {
|
|
|
17
17
|
terminalArtifact: string;
|
|
18
18
|
}
|
|
19
19
|
export declare const SOURCE_ROLE_CATALOG: readonly SourceRoleContent[];
|
|
20
|
+
export declare function buildRoleIdentity(role: Pick<SourceRoleContent, "name" | "id">): string;
|
|
20
21
|
export declare function splitCategory(text: string): {
|
|
21
22
|
base: string;
|
|
22
23
|
calibrations: Map<string, string>;
|
package/lib/prompt-content.js
CHANGED
|
@@ -14,6 +14,9 @@ export function readPromptAsset(path) {
|
|
|
14
14
|
return text;
|
|
15
15
|
}
|
|
16
16
|
export const SOURCE_ROLE_CATALOG = JSON.parse(readPromptAsset("catalog.json"));
|
|
17
|
+
export function buildRoleIdentity(role) {
|
|
18
|
+
return `You are ${role.name} (role ID: ${role.id}).`;
|
|
19
|
+
}
|
|
17
20
|
export function splitCategory(text) {
|
|
18
21
|
const calibrations = new Map();
|
|
19
22
|
const base = text.replace(/\r?\n?<model-calibration model="([^"]+)">\r?\n([\s\S]*?)\r?\n<\/model-calibration>\r?\n?/gu, (_block, model, calibration) => { calibrations.set(model, calibration.trim()); return "\n"; }).trim();
|
|
@@ -22,6 +25,6 @@ export function splitCategory(text) {
|
|
|
22
25
|
export function buildRolePersona(role) {
|
|
23
26
|
const source = role.promptArtifact === null ? role.description : readPromptAsset(role.promptArtifact.replace("prompts/source/", ""));
|
|
24
27
|
const body = role.kind === "category" ? splitCategory(source).base : source;
|
|
25
|
-
return [
|
|
28
|
+
return [buildRoleIdentity(role), readPromptAsset("shared/locale.md"), body, readPromptAsset("shared/dsh-host-contract.md"), readPromptAsset(role.terminalArtifact.replace("prompts/source/", ""))].filter(Boolean).join("\n\n---\n\n");
|
|
26
29
|
}
|
|
27
30
|
//# sourceMappingURL=prompt-content.js.map
|