@dsmm/dsmm 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/README.md +26 -40
  2. package/cordis.patch.yml +9 -13
  3. package/docs/agent-presets.md +26 -14
  4. package/docs/compatibility.md +24 -68
  5. package/docs/deferred-native-approval-risk.md +8 -12
  6. package/docs/design.md +25 -254
  7. package/docs/lsp.md +2 -2
  8. package/docs/migration-from-ocmm.md +38 -51
  9. package/docs/model-routing.md +21 -21
  10. package/docs/native-permissions.md +17 -7
  11. package/docs/profiles.md +13 -9
  12. package/docs/releasing.md +25 -311
  13. package/docs/roadmap.md +52 -241
  14. package/docs/runtime-recovery.md +29 -91
  15. package/docs/safety-guards.md +19 -16
  16. package/docs/settings-status.md +23 -11
  17. package/docs/skill-sync.md +17 -17
  18. package/docs/web-fetch-fakeip.md +82 -0
  19. package/lib/child-capture.d.ts +12 -2
  20. package/lib/child-capture.js +22 -5
  21. package/lib/client/ChildPermissions.d.ts +43 -0
  22. package/lib/client/ChildPermissions.js +100 -0
  23. package/lib/client/ChildrenPanel.d.ts +5 -5
  24. package/lib/client/ChildrenPanel.js +6 -18
  25. package/lib/client/DeploymentFields.d.ts +32 -0
  26. package/lib/client/DeploymentFields.js +70 -0
  27. package/lib/client/DeploymentPage.d.ts +21 -6
  28. package/lib/client/DeploymentPage.js +80 -112
  29. package/lib/client/HistoryContinuation.d.ts +7 -0
  30. package/lib/client/HistoryContinuation.js +22 -0
  31. package/lib/client/NativeCommandEntries.d.ts +17 -0
  32. package/lib/client/NativeCommandEntries.js +68 -0
  33. package/lib/client/PermissionPanelEntry.d.ts +8 -0
  34. package/lib/client/PermissionPanelEntry.js +11 -0
  35. package/lib/client/PermissionsPanel.d.ts +3 -1
  36. package/lib/client/PermissionsPanel.js +10 -9
  37. package/lib/client/ProfilesSection.js +8 -6
  38. package/lib/client/RoleAvailability.js +1 -1
  39. package/lib/client/RoleToolView-data.d.ts +35 -0
  40. package/lib/client/RoleToolView-data.js +52 -0
  41. package/lib/client/RoleToolView-locales.d.ts +36 -0
  42. package/lib/client/RoleToolView-locales.js +20 -0
  43. package/lib/client/RoleToolView.d.ts +10 -0
  44. package/lib/client/RoleToolView.js +47 -0
  45. package/lib/client/SessionProfiles.js +51 -24
  46. package/lib/client/TemporaryPermissions.d.ts +21 -0
  47. package/lib/client/TemporaryPermissions.js +94 -0
  48. package/lib/client/children-controller.d.ts +2 -8
  49. package/lib/client/children-controller.js +1 -26
  50. package/lib/client/children-locales.d.ts +27 -52
  51. package/lib/client/children-locales.js +8 -12
  52. package/lib/client/configuration-display.d.ts +5 -0
  53. package/lib/client/configuration-display.js +11 -0
  54. package/lib/client/controller.d.ts +18 -0
  55. package/lib/client/controller.js +118 -28
  56. package/lib/client/deployment-controller.d.ts +13 -1
  57. package/lib/client/deployment-controller.js +84 -24
  58. package/lib/client/deployment-data.d.ts +1 -0
  59. package/lib/client/deployment-data.js +4 -1
  60. package/lib/client/deployment-locales.d.ts +43 -0
  61. package/lib/client/deployment-locales.js +45 -19
  62. package/lib/client/deployment-modules.d.ts +9 -0
  63. package/lib/client/deployment-modules.js +24 -0
  64. package/lib/client/deployment-workspace.d.ts +48 -0
  65. package/lib/client/deployment-workspace.js +123 -0
  66. package/lib/client/history-controller.d.ts +29 -0
  67. package/lib/client/history-controller.js +111 -0
  68. package/lib/client/history-entry.d.ts +11 -0
  69. package/lib/client/history-entry.js +106 -0
  70. package/lib/client/history-locales.d.ts +95 -0
  71. package/lib/client/history-locales.js +41 -0
  72. package/lib/client/index.js +26 -76
  73. package/lib/client/locales.d.ts +13 -0
  74. package/lib/client/locales.js +104 -86
  75. package/lib/client/permission-controller.d.ts +1 -0
  76. package/lib/client/permission-controller.js +3 -2
  77. package/lib/client/permission-locales.d.ts +51 -0
  78. package/lib/client/permission-locales.js +59 -19
  79. package/lib/client/session-labels.js +4 -3
  80. package/lib/client/styles.d.ts +1 -1
  81. package/lib/client/styles.js +9 -8
  82. package/lib/client/temporary-permission-client.d.ts +20 -0
  83. package/lib/client/temporary-permission-client.js +52 -0
  84. package/lib/client/temporary-permission-entry.d.ts +6 -0
  85. package/lib/client/temporary-permission-entry.js +56 -0
  86. package/lib/client.js +5691 -3439
  87. package/lib/commands.js +2 -0
  88. package/lib/config-file-store.d.ts +3 -0
  89. package/lib/config-file-store.js +4 -2
  90. package/lib/config-revision.d.ts +5 -0
  91. package/lib/config-revision.js +11 -0
  92. package/lib/core-permission-authority.js +11 -41
  93. package/lib/deployment-config.d.ts +9 -2
  94. package/lib/deployment-config.js +35 -8
  95. package/lib/deployment-permission-rules.js +19 -7
  96. package/lib/dsh-types.d.ts +1 -1
  97. package/lib/history-candidates.d.ts +30 -0
  98. package/lib/history-candidates.js +176 -0
  99. package/lib/history-codec.d.ts +11 -0
  100. package/lib/history-codec.js +102 -0
  101. package/lib/history-contract.d.ts +44 -0
  102. package/lib/history-contract.js +2 -0
  103. package/lib/history-controller.d.ts +42 -0
  104. package/lib/history-controller.js +329 -0
  105. package/lib/history-policy.d.ts +4 -0
  106. package/lib/history-policy.js +8 -0
  107. package/lib/history-remote.d.ts +28 -0
  108. package/lib/history-remote.js +17 -0
  109. package/lib/history-rpc.d.ts +24 -0
  110. package/lib/history-rpc.js +136 -0
  111. package/lib/history-support.d.ts +15 -0
  112. package/lib/history-support.js +21 -0
  113. package/lib/history-types.d.ts +67 -0
  114. package/lib/history-types.js +2 -0
  115. package/lib/host-llm-startup.js +3 -3
  116. package/lib/host-llm.d.ts +9 -3
  117. package/lib/host-llm.js +48 -8
  118. package/lib/index.d.ts +18 -20
  119. package/lib/index.js +147 -415
  120. package/lib/lifetime.d.ts +4 -0
  121. package/lib/lifetime.js +22 -0
  122. package/lib/live-pi-ai-owner.d.ts +1 -0
  123. package/lib/live-pi-ai-owner.js +8 -4
  124. package/lib/mode.d.ts +3 -2
  125. package/lib/mode.js +28 -41
  126. package/lib/model-routing.d.ts +2 -8
  127. package/lib/model-routing.js +59 -175
  128. package/lib/native-admission.d.ts +77 -0
  129. package/lib/native-admission.js +503 -0
  130. package/lib/native-pi-ai-wire.d.ts +3 -1
  131. package/lib/native-pi-ai-wire.js +47 -13
  132. package/lib/permission-child-control.d.ts +36 -0
  133. package/lib/permission-child-control.js +164 -0
  134. package/lib/permission-control.d.ts +2 -3
  135. package/lib/permission-control.js +7 -0
  136. package/lib/permission-controller.js +2 -2
  137. package/lib/permission-exec-argv.d.ts +32 -0
  138. package/lib/permission-exec-argv.js +171 -0
  139. package/lib/permission-fs-search.js +2 -1
  140. package/lib/permission-fs.js +2 -1
  141. package/lib/permission-native-rules.js +3 -3
  142. package/lib/permission-temporary-files.d.ts +19 -0
  143. package/lib/permission-temporary-files.js +248 -0
  144. package/lib/permission-temporary-grants.d.ts +106 -0
  145. package/lib/permission-temporary-grants.js +198 -0
  146. package/lib/permission-temporary-install.d.ts +25 -0
  147. package/lib/permission-temporary-install.js +86 -0
  148. package/lib/permission-temporary-remote.d.ts +19 -0
  149. package/lib/permission-temporary-remote.js +75 -0
  150. package/lib/permission-temporary-rpc.d.ts +37 -0
  151. package/lib/permission-temporary-rpc.js +154 -0
  152. package/lib/permission-temporary-types.d.ts +47 -0
  153. package/lib/permission-temporary-types.js +2 -0
  154. package/lib/permission-temporary-web.d.ts +11 -0
  155. package/lib/permission-temporary-web.js +154 -0
  156. package/lib/permission-web.js +2 -1
  157. package/lib/preset-registry.js +3 -2
  158. package/lib/preset-skills.d.ts +3 -12
  159. package/lib/preset-skills.js +28 -58
  160. package/lib/profile-diagnostics.d.ts +1 -1
  161. package/lib/profile-diagnostics.js +2 -2
  162. package/lib/profile-remote.js +61 -22
  163. package/lib/profile-rpc.d.ts +4 -3
  164. package/lib/profile-rpc.js +35 -37
  165. package/lib/profile-runtime.d.ts +42 -74
  166. package/lib/profile-runtime.js +314 -617
  167. package/lib/profile-store.d.ts +20 -8
  168. package/lib/profile-store.js +112 -63
  169. package/lib/profile-types.d.ts +19 -4
  170. package/lib/profiles.d.ts +3 -1
  171. package/lib/profiles.js +9 -7
  172. package/lib/prompt-content.d.ts +1 -0
  173. package/lib/prompt-content.js +4 -1
  174. package/lib/prompts.d.ts +2 -12
  175. package/lib/prompts.js +11 -66
  176. package/lib/role-control-remote.d.ts +1 -4
  177. package/lib/role-control-remote.js +8 -36
  178. package/lib/role-control-rpc.d.ts +10 -36
  179. package/lib/role-control-rpc.js +112 -269
  180. package/lib/role-control-types.d.ts +3 -26
  181. package/lib/role-control-types.js +3 -4
  182. package/lib/role-identity.d.ts +5 -0
  183. package/lib/role-identity.js +10 -0
  184. package/lib/role-invocation.d.ts +3 -3
  185. package/lib/role-invocation.js +2 -2
  186. package/lib/role-llm-runtime.js +5 -11
  187. package/lib/role-policy.d.ts +19 -50
  188. package/lib/role-policy.js +136 -508
  189. package/lib/role-providers.d.ts +5 -8
  190. package/lib/role-providers.js +20 -86
  191. package/lib/role-routing.d.ts +1 -3
  192. package/lib/role-routing.js +24 -34
  193. package/lib/role-subagents.d.ts +5 -14
  194. package/lib/role-subagents.js +163 -108
  195. package/lib/runtime-integration.d.ts +5 -78
  196. package/lib/runtime-integration.js +11 -697
  197. package/lib/session-metadata.d.ts +13 -12
  198. package/lib/session-metadata.js +6 -31
  199. package/lib/session-scope.js +2 -1
  200. package/lib/settings.d.ts +5 -18
  201. package/lib/settings.js +19 -43
  202. package/lib/skills.d.ts +1 -0
  203. package/lib/skills.js +5 -1
  204. package/lib/state.d.ts +3 -2
  205. package/lib/state.js +26 -10
  206. package/lib/status.d.ts +1 -9
  207. package/lib/status.js +3 -55
  208. package/lib/web-fetch-address-policy.d.ts +24 -0
  209. package/lib/web-fetch-address-policy.js +189 -0
  210. package/lib/web-fetch-fakeip.d.ts +25 -0
  211. package/lib/web-fetch-fakeip.js +107 -0
  212. package/package.json +124 -106
  213. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-gateway@0.2.1-rc.2.patch +13291 -0
  214. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-remotes@0.2.1-rc.2.patch +9133 -0
  215. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-client-ui-approval@0.2.1-rc.2.patch +156 -0
  216. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-subagent@0.2.1-rc.2.patch +3546 -0
  217. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-user-approval@0.2.1-rc.2.patch +431 -0
  218. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-web@0.2.1-rc.2.patch +119 -0
  219. package/patches/dsh-approval-settlement/README.md +41 -0
  220. package/patches/dsh-approval-settlement/metadata.json +10 -0
  221. package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-loop@0.2.1-rc.2.patch +383 -0
  222. package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-preset-registry@0.2.1-rc.2.patch +55 -0
  223. package/patches/dsh-session-activation/@deepseek-ai__dsh-api-session-controller@0.2.1-rc.2.patch +16673 -0
  224. package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-subagent@0.2.1-rc.2.patch +29 -0
  225. package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-workspace@0.2.1-rc.2.patch +196 -0
  226. package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence-jsonl@0.2.1-rc.2.patch +35 -0
  227. package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence@0.2.1-rc.2.patch +40 -0
  228. package/docs/research/deepseek-v4-pro.md +0 -74
  229. package/docs/research/oh-dsh.md +0 -96
  230. package/lib/agent-registry.d.ts +0 -36
  231. package/lib/agent-registry.js +0 -75
  232. package/lib/child-admission.d.ts +0 -40
  233. package/lib/child-admission.js +0 -151
  234. package/lib/delivery-authority.d.ts +0 -83
  235. package/lib/delivery-authority.js +0 -397
  236. package/lib/native-child-evidence.d.ts +0 -40
  237. package/lib/native-child-evidence.js +0 -104
  238. package/lib/role-runs.d.ts +0 -138
  239. package/lib/role-runs.js +0 -335
  240. package/lib/session-persistence.d.ts +0 -36
  241. package/lib/session-persistence.js +0 -304
  242. package/lib/subagent-runtime.d.ts +0 -57
  243. package/lib/subagent-runtime.js +0 -257
  244. package/prompts/deepseek-flash.md +0 -11
  245. package/prompts/deepseek-v4-pro.md +0 -14
@@ -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";
@@ -16,20 +16,27 @@ export interface LoadedSessionProfileSelection extends LoadedProfileSelection {
16
16
  }
17
17
  export declare const MAX_SESSION_PROFILE_CHOICES = 1024;
18
18
  export interface SessionProfileCommit<T> {
19
- /** Fallible synchronous preparation before the final fence/rename; never publication. */
20
- prepare?(selection: LoadedSessionProfileSelection, prepared: T): void;
19
+ /** Fallible installation preparation before the final fence/rename; never publication. */
20
+ prepare?(selection: LoadedSessionProfileSelection, prepared: T): void | Promise<void>;
21
21
  /** Trusted native liveness/cancellation fence; invoked immediately before rename. */
22
22
  assertCurrent(): void;
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
- save(request: ProfileSaveRequest): Promise<ProfileReadResult>;
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>): Promise<{
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): 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
- digest: typeof digest;
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;
@@ -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
- async save(request) {
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
- return this.readResult({ bytes, content: request.content, revision: digest(bytes), document, ...(warnings.length ? { warnings } : {}) });
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
- validateProfileRevision(epoch, "admissionEpoch");
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,35 @@ export class ProfileStore {
165
173
  commit.assertCurrent();
166
174
  validateDirectories(directory, true, false, this.identities);
167
175
  fence();
168
- if (draft !== undefined)
169
- this.publishRevision(draft, assertLock);
170
- const pointer = { version: 1, sessionId: request.sessionId, id: request.id, revision: draft?.revision ?? null, epoch };
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: draft?.revision ?? null, selectionRevision: digest(bytes), document: draft?.document ?? null, content: draft?.content ?? null, ...warningFields(draft) };
174
- commit.prepare?.(selection, prepared);
175
- this.atomicReplace(target, bytes, fence, assertLock);
181
+ selectedId: request.id, appliedRevision: revision, selectionRevision: "unavailable", document: draft?.document ?? null, content: draft?.content ?? null, ...source, ...warningFields(draft) };
182
+ try {
183
+ await commit.prepare?.(selection, prepared);
184
+ }
185
+ catch (error) {
186
+ if (error instanceof DsmmProfileError)
187
+ throw error;
188
+ throw new DsmmProfileError("activation", "The candidate installation could not be prepared; the previous session selection was retained.");
189
+ }
190
+ const owned = this.atomicReplace(target, bytes, fence, assertLock);
176
191
  commit.committed(selection, prepared);
192
+ const observed = observeCommitted(target, owned, this.observe);
193
+ selection.selectionRevision = observed.revision;
194
+ if (observed.refreshRequired)
195
+ selection.refreshRequired = true;
177
196
  return { selection, prepared };
178
197
  });
179
198
  }
180
- async select(request, validateCandidate) {
199
+ async select(request, validateCandidate, commit, assertCurrent) {
181
200
  this.assertWritable();
201
+ assertCurrent?.();
182
202
  validateSelectionRequest(request);
183
203
  return this.locked(async (assertLock) => {
204
+ assertCurrent?.();
184
205
  const current = this.selection();
185
206
  if (current.selectionRevision !== request.expectedSelectionRevision)
186
207
  conflict("The selected profile changed. Refresh before selecting again.");
@@ -197,24 +218,30 @@ export class ProfileStore {
197
218
  throw new DsmmProfileError("activation", "The candidate profile could not be activated; the previous selection was retained.");
198
219
  }
199
220
  // The audit may await native work. Recheck security and CAS afterwards.
221
+ assertCurrent?.();
200
222
  assertLock();
201
223
  this.assertSelectionRevision(request.expectedSelectionRevision);
202
224
  if (draft !== undefined && this.draft(request.id, this.inventory()).revision !== draft.revision)
203
225
  conflict("The draft changed during activation. Reload and select again.");
204
- if (draft !== undefined)
205
- this.publishRevision(draft, assertLock);
206
- const pointer = { version: 1, id: request.id, revision: draft?.revision ?? null };
226
+ const revision = draft === undefined ? null : this.publishRevision(draft, assertLock);
227
+ const source = draft === undefined ? {} : { sourceRevision: draft.revision };
228
+ const pointer = { version: 2, id: request.id, revision, ...source };
207
229
  const bytes = Buffer.from(`${JSON.stringify(pointer)}\n`, "utf8");
208
230
  this.validateState(true);
209
- this.atomicReplace(join(this.stateDir, ".selection.json"), bytes, () => {
231
+ const selection = { selectedId: request.id, appliedRevision: revision, selectionRevision: "unavailable", document: draft?.document ?? null, content: draft?.content ?? null, ...source, ...warningFields(draft) };
232
+ commit?.prepare(selection, prepared);
233
+ const target = join(this.stateDir, ".selection.json");
234
+ const owned = this.atomicReplace(target, bytes, () => {
210
235
  this.assertSelectionRevision(request.expectedSelectionRevision);
211
236
  if (draft !== undefined && this.draft(request.id, this.inventory()).revision !== draft.revision)
212
237
  conflict("The draft changed during selection. Reload and select again.");
213
- }, assertLock);
214
- return {
215
- selection: { selectedId: request.id, appliedRevision: draft?.revision ?? null, selectionRevision: digest(bytes), document: draft?.document ?? null, content: draft?.content ?? null, ...warningFields(draft) },
216
- prepared
217
- };
238
+ }, assertLock, assertCurrent);
239
+ commit?.committed(selection, prepared);
240
+ const observed = observeCommitted(target, owned, this.observe);
241
+ selection.selectionRevision = observed.revision;
242
+ if (observed.refreshRequired)
243
+ selection.refreshRequired = true;
244
+ return { selection, prepared };
218
245
  });
219
246
  }
220
247
  readResult(draft) {
@@ -266,12 +293,11 @@ export class ProfileStore {
266
293
  return { selectedId: null, appliedRevision: null, selectionRevision: file.revision, document: null, content: null };
267
294
  validateDirectories(join(this.profileDir, ".revisions"), false);
268
295
  const immutable = regularFile(join(this.profileDir, ".revisions", `${pointer.revision}.jsonc`), MAX_PROFILE_BYTES);
269
- if (immutable.revision !== pointer.revision)
270
- throw new DsmmProfileError("corrupt-selection", "The selected immutable profile revision failed its SHA256 verification.");
271
- return { selectedId: pointer.id, appliedRevision: pointer.revision, selectionRevision: file.revision, ...validatedProfile(immutable.content, pointer.id), content: immutable.content };
296
+ assertPointerVersion(path, file);
297
+ 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
298
  }
273
299
  catch (error) {
274
- if (error instanceof DsmmProfileError && error.code === "unsafe-path")
300
+ if (error instanceof DsmmProfileError && (error.code === "unsafe-path" || error.code === "conflict"))
275
301
  throw error;
276
302
  if (error instanceof DsmmProfileError && error.reason !== undefined)
277
303
  throw new DsmmProfileError("corrupt-selection", error.message, error.field, error.reason, error.location);
@@ -301,13 +327,12 @@ export class ProfileStore {
301
327
  return { ...absent, admissionEpoch: pointer.epoch, selectionRevision: file.revision };
302
328
  validateDirectories(join(this.profileDir, ".revisions"), false);
303
329
  const immutable = regularFile(join(this.profileDir, ".revisions", `${pointer.revision}.jsonc`), MAX_PROFILE_BYTES);
304
- if (immutable.revision !== pointer.revision)
305
- throw new DsmmProfileError("corrupt-selection", "The session's immutable profile revision failed SHA256 verification.");
330
+ assertPointerVersion(path, file);
306
331
  return { sessionId, admissionEpoch: pointer.epoch, selectedId: pointer.id, appliedRevision: pointer.revision,
307
- selectionRevision: file.revision, ...validatedProfile(immutable.content, pointer.id), content: immutable.content };
332
+ selectionRevision: file.revision, ...(pointer.sourceRevision === undefined ? {} : { sourceRevision: pointer.sourceRevision }), ...validatedProfile(immutable.content, pointer.id), content: immutable.content };
308
333
  }
309
334
  catch (error) {
310
- if (error instanceof DsmmProfileError && error.code === "unsafe-path")
335
+ if (error instanceof DsmmProfileError && (error.code === "unsafe-path" || error.code === "conflict"))
311
336
  throw error;
312
337
  if (error instanceof DsmmProfileError && error.reason !== undefined)
313
338
  throw new DsmmProfileError("corrupt-selection", error.message, error.field, error.reason, error.location);
@@ -322,13 +347,8 @@ export class ProfileStore {
322
347
  assertLock();
323
348
  const directory = join(this.profileDir, ".revisions");
324
349
  validateDirectories(directory, true);
325
- const path = join(directory, `${draft.revision}.jsonc`);
326
- if (status(path) !== undefined) {
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
- }
350
+ const revision = `snapshot-v1-${randomUUID()}`;
351
+ const path = join(directory, `${revision}.jsonc`);
332
352
  if (boundedEntries(directory, MAX_PROFILE_REVISIONS).length >= MAX_PROFILE_REVISIONS)
333
353
  throw new DsmmProfileError("limit", "The immutable revision inventory is full; no selection was committed.");
334
354
  let fd;
@@ -349,12 +369,13 @@ export class ProfileStore {
349
369
  unlinkSync(path);
350
370
  throw error;
351
371
  }
372
+ return revision;
352
373
  }
353
- atomicReplace(target, bytes, beforeRename, assertLock) {
354
- atomicReplace(target, bytes, beforeRename, () => {
374
+ atomicReplace(target, bytes, beforeRename, assertLock, assertCurrent) {
375
+ return atomicReplace(target, bytes, beforeRename, () => {
355
376
  assertLock();
356
377
  validateDirectories(dirname(target), false, false, this.identities);
357
- }, this.rename);
378
+ }, this.rename, assertCurrent);
358
379
  }
359
380
  validateRoot(create) {
360
381
  if (this.hostProfile !== undefined)
@@ -484,7 +505,7 @@ export class ProfileStore {
484
505
  const envelope = JSON.parse(file.content);
485
506
  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
507
  throw new Error("Invalid capture envelope");
487
- validateProfileRevision(envelope.revision, "revision");
508
+ validateAdmissionEpoch(envelope.revision, "revision");
488
509
  if (digest(Buffer.from(JSON.stringify(envelope.capture), "utf8")) !== envelope.revision)
489
510
  throw new Error("Capture integrity mismatch");
490
511
  const capture = parseChildAdmissionCapture(envelope.capture);
@@ -500,14 +521,10 @@ export class ProfileStore {
500
521
  if (this.origin === "explicit")
501
522
  return this.locked(operation);
502
523
  try {
503
- const first = operation();
504
- const second = operation();
524
+ const result = operation();
505
525
  this.validateRoot(false);
506
526
  this.validateState(false);
507
- if (JSON.stringify(first) !== JSON.stringify(second)) {
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;
527
+ return result;
511
528
  }
512
529
  catch (error) {
513
530
  if (error instanceof DsmmProfileError)
@@ -596,6 +613,7 @@ function atomicReplace(target, bytes, beforeRename, assertAuthority, rename, ass
596
613
  fd = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
597
614
  created = true;
598
615
  owned = fstatSync(fd);
616
+ const ownedIdentity = fstatSync(fd, { bigint: true });
599
617
  assertRegular(owned);
600
618
  writeAll(fd, bytes);
601
619
  fsyncSync(fd);
@@ -612,7 +630,7 @@ function atomicReplace(target, bytes, beforeRename, assertAuthority, rename, ass
612
630
  assertCurrent?.();
613
631
  rename(temporary, target);
614
632
  created = false;
615
- // rename is the transaction commit. No fallible work follows it.
633
+ return ownedIdentity;
616
634
  }
617
635
  finally {
618
636
  if (fd !== undefined)
@@ -641,7 +659,26 @@ function trustedHome(home) {
641
659
  return root;
642
660
  }
643
661
  /** @internal Shared only by the fixed config file adapter; not a wire-path storage API. */
644
- export const profileStoreFilePrimitives = { trustedHome, validateDirectories, status, regularFile, digest, boundedOption, locked, atomicReplace };
662
+ export const profileStoreFilePrimitives = { trustedHome, validateDirectories, status, regularFile, observeCommitted, boundedOption, locked, atomicReplace };
663
+ function statRevision(stat) { return `stat-v1-${stat.mtimeNs}-${stat.ctimeNs}`; }
664
+ function assertPointerVersion(path, file) {
665
+ if (observeCommitted(path, file.identity).revision !== file.revision)
666
+ conflict("The selection version changed while reading its snapshot.");
667
+ }
668
+ function observeCommitted(path, owned, observe) {
669
+ try {
670
+ observe?.(path);
671
+ validateDirectories(dirname(path), false);
672
+ const named = lstatSync(path, { bigint: true });
673
+ assertRegular(named);
674
+ if (named.dev !== owned.dev || named.ino !== owned.ino)
675
+ throw new Error("Committed target was replaced");
676
+ return { revision: statRevision(named) };
677
+ }
678
+ catch {
679
+ return { revision: "unavailable", refreshRequired: true };
680
+ }
681
+ }
645
682
  function boundedOption(value, fallback, minimum, maximum) {
646
683
  if (value === undefined)
647
684
  return fallback;
@@ -703,7 +740,7 @@ function validateDirectories(directory, create, allowMissing = false, identities
703
740
  return true;
704
741
  }
705
742
  function assertRegular(found) {
706
- if (found.isSymbolicLink() || !found.isFile() || found.nlink !== 1)
743
+ if (found.isSymbolicLink() || !found.isFile() || (found.nlink !== 1 && found.nlink !== 1n))
707
744
  throw new DsmmProfileError("unsafe-path", "Profile files and lock files must be regular, unlinked files, not symlinks, junctions, directories or hard links.");
708
745
  }
709
746
  function sameFile(first, second) {
@@ -721,6 +758,7 @@ function regularFile(path, maximum) {
721
758
  try {
722
759
  validateDirectories(dirname(path), false);
723
760
  const opened = fstatSync(fd);
761
+ const openedVersion = fstatSync(fd, { bigint: true });
724
762
  assertRegular(opened);
725
763
  if (!sameFile(before, opened))
726
764
  conflict("The profile file changed while it was opened. Retry the operation.");
@@ -735,13 +773,17 @@ function regularFile(path, maximum) {
735
773
  if (size > maximum)
736
774
  throw new DsmmProfileError("limit", "Profile storage contains an oversized file.");
737
775
  const after = fstatSync(fd);
776
+ const afterVersion = fstatSync(fd, { bigint: true });
738
777
  const named = status(path);
778
+ const namedVersion = lstatSync(path, { bigint: true });
739
779
  validateDirectories(dirname(path), false);
740
780
  assertRegular(after);
741
781
  if (named !== undefined)
742
782
  assertRegular(named);
743
783
  if (named === undefined || !sameFile(opened, named) || opened.size !== after.size || opened.mtimeMs !== after.mtimeMs || opened.ctimeMs !== after.ctimeMs)
744
784
  conflict("The profile file was edited while being read. Retry the operation.");
785
+ if (statRevision(openedVersion) !== statRevision(afterVersion) || statRevision(afterVersion) !== statRevision(namedVersion) || afterVersion.ino !== namedVersion.ino || afterVersion.dev !== namedVersion.dev)
786
+ conflict("The file version changed while being read.");
745
787
  const bytes = buffer.subarray(0, size);
746
788
  let content;
747
789
  try {
@@ -750,7 +792,7 @@ function regularFile(path, maximum) {
750
792
  catch {
751
793
  throw new DsmmProfileError("validation", "Profile files must contain valid UTF-8 text.", "content");
752
794
  }
753
- return { bytes, content, revision: digest(bytes) };
795
+ return { bytes, content, revision: statRevision(afterVersion), identity: afterVersion };
754
796
  }
755
797
  finally {
756
798
  closeSync(fd);
@@ -786,8 +828,8 @@ function writeAll(fd, bytes) {
786
828
  function parseSelectionPointer(content) {
787
829
  const errors = [];
788
830
  const tree = parseTree(content, errors, { disallowComments: true, allowTrailingComma: false, allowEmptyContent: false });
789
- if (tree?.type !== "object" || errors.length > 0 || tree.children?.length !== 3)
790
- throw new DsmmProfileError("corrupt-selection", "The selected profile pointer must contain exactly three unique fields in valid JSON.");
831
+ if (tree?.type !== "object" || errors.length > 0)
832
+ throw new DsmmProfileError("corrupt-selection", "The selected profile pointer must contain unique fields in valid JSON.");
791
833
  let input;
792
834
  try {
793
835
  input = JSON.parse(content);
@@ -798,13 +840,19 @@ function parseSelectionPointer(content) {
798
840
  if (typeof input !== "object" || input === null || Array.isArray(input))
799
841
  throw new DsmmProfileError("corrupt-selection", "The selected profile pointer must be a versioned object.");
800
842
  const record = input;
801
- if (Object.keys(record).length !== 3 || !["version", "id", "revision"].every((key) => Object.hasOwn(record, key)) || record.version !== 1)
843
+ const allowed = ["version", "id", "revision", ...record.version === 2 ? ["sourceRevision"] : []];
844
+ 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
845
  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: 1, id: null, revision: null };
846
+ if (record.id === null && record.revision === null && !Object.hasOwn(record, "sourceRevision"))
847
+ return { version: record.version, id: null, revision: null };
805
848
  validateProfileId(record.id);
806
- validateProfileRevision(record.revision, "revision");
807
- return { version: 1, id: record.id, revision: record.revision };
849
+ if (!isProfileReference(record.revision))
850
+ throw new DsmmProfileError("corrupt-selection", "Invalid snapshot reference.");
851
+ if (record.version === 1)
852
+ validateAdmissionEpoch(record.revision, "revision");
853
+ if (Object.hasOwn(record, "sourceRevision"))
854
+ validateProfileRevision(record.sourceRevision, "sourceRevision");
855
+ return { version: record.version, id: record.id, revision: record.revision, ...(typeof record.sourceRevision === "string" ? { sourceRevision: record.sourceRevision } : {}) };
808
856
  }
809
857
  export function validateSessionProfileId(id) {
810
858
  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 +874,15 @@ function validateSelectionRequest(request) {
826
874
  function parseSessionSelectionPointer(content, sessionId) {
827
875
  const errors = [];
828
876
  const tree = parseTree(content, errors, { disallowComments: true, allowTrailingComma: false, allowEmptyContent: false });
829
- if (tree?.type !== "object" || errors.length > 0 || tree.children?.length !== 5)
830
- throw new DsmmProfileError("corrupt-selection", "The session choice must contain exactly five unique fields in valid JSON.");
877
+ if (tree?.type !== "object" || errors.length > 0)
878
+ throw new DsmmProfileError("corrupt-selection", "The session choice must contain unique fields in valid JSON.");
831
879
  const record = JSON.parse(content);
832
- if (Object.keys(record).length !== 5 || !["version", "sessionId", "id", "revision", "epoch"].every((key) => Object.hasOwn(record, key)) || record.version !== 1 || record.sessionId !== sessionId) {
880
+ const allowed = ["version", "sessionId", "id", "revision", "epoch", ...record.version === 2 ? ["sourceRevision"] : []];
881
+ 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
882
  throw new DsmmProfileError("corrupt-selection", "The session choice identity, shape or version is invalid.");
834
883
  }
835
- validateProfileRevision(record.epoch, "admissionEpoch");
836
- const selection = parseSelectionPointer(JSON.stringify({ version: record.version, id: record.id, revision: record.revision }));
884
+ validateAdmissionEpoch(record.epoch);
885
+ const selection = parseSelectionPointer(JSON.stringify({ version: record.version, id: record.id, revision: record.revision, ...Object.hasOwn(record, "sourceRevision") ? { sourceRevision: record.sourceRevision } : {} }));
837
886
  return { ...selection, sessionId, epoch: record.epoch };
838
887
  }
839
888
  function conflict(message) {
@@ -42,10 +42,11 @@ export interface DsmmInvocationView {
42
42
  routeComparison?: DsmmRoleRouteComparison;
43
43
  }
44
44
  export interface SubagentRuntimeAdmissionView {
45
- binding: "stock" | "dsmm" | "unavailable";
45
+ binding: "stock" | "unavailable";
46
+ /** Native execution admission readiness; not an inbox-acceptance veto. */
46
47
  deliveryFenceReady: boolean;
47
48
  restartRequired: boolean;
48
- reason?: "explicit-composition-required" | "duplicate-provider" | "authority-not-ready";
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 sidecar state: the authority for session-selection CAS. */
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,17 @@ 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
+ /** Host-authoritative blank-session choice; never started-session hot Apply. */
207
+ canApplyOverlay: boolean;
208
+ applyOverlayUnavailableReason?: SessionActionUnavailableReason;
194
209
  rolePolicy?: DsmmRoleRuntimeState;
195
210
  /** Declared profile primary for the current ordinary root role, not an applied native selection. */
196
211
  profileModel?: DsmmModelRoute;
197
- /** Optional for older Hosts; explicit session intent always beats defaults. */
212
+ /** Explicit session intent always beats defaults. */
198
213
  deepwork?: SessionDeepworkState;
199
214
  /** Safe captured module admission; not a read of the current global editor. */
200
215
  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" | "deepseekV4ProCalibration" | "deepseekV4ProDefaultReasoningEffort" | "deepseekFlashCalibration" | "deepseekFlashDefaultReasoningEffort"> & {
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 (typeof revision !== "string" || !/^[a-f0-9]{64}$/u.test(revision))
40
- invalid(field, "must be a SHA256 file revision");
39
+ if (!isConfigRevision(revision))
40
+ invalid(field, "must be a configuration version");
41
41
  }
42
- const OVERLAY_FIELDS = ["modelParameters", "defaultActive", "roleRouting", "runtimePolicy", "workflow", "guards", "runtimeRecovery", "roles", "locale", "subagents", "deepseekV4ProCalibration", "deepseekV4ProDefaultReasoningEffort", "deepseekFlashCalibration", "deepseekFlashDefaultReasoningEffort"];
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");
@@ -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>;