@dsmm/dsmm 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/README.md +26 -40
  2. package/cordis.patch.yml +0 -13
  3. package/docs/agent-presets.md +26 -14
  4. package/docs/compatibility.md +19 -73
  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 +34 -280
  13. package/docs/roadmap.md +23 -254
  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/ChildrenPanel.d.ts +1 -4
  22. package/lib/client/ChildrenPanel.js +4 -16
  23. package/lib/client/DeploymentFields.d.ts +28 -0
  24. package/lib/client/DeploymentFields.js +68 -0
  25. package/lib/client/DeploymentPage.d.ts +17 -5
  26. package/lib/client/DeploymentPage.js +79 -112
  27. package/lib/client/NativeCommandEntries.d.ts +17 -0
  28. package/lib/client/NativeCommandEntries.js +68 -0
  29. package/lib/client/PermissionsPanel.d.ts +1 -1
  30. package/lib/client/PermissionsPanel.js +8 -8
  31. package/lib/client/ProfilesSection.js +7 -5
  32. package/lib/client/RoleToolView-data.d.ts +35 -0
  33. package/lib/client/RoleToolView-data.js +52 -0
  34. package/lib/client/RoleToolView-locales.d.ts +36 -0
  35. package/lib/client/RoleToolView-locales.js +20 -0
  36. package/lib/client/RoleToolView.d.ts +10 -0
  37. package/lib/client/RoleToolView.js +47 -0
  38. package/lib/client/SessionProfiles.js +39 -15
  39. package/lib/client/children-controller.d.ts +2 -8
  40. package/lib/client/children-controller.js +1 -26
  41. package/lib/client/children-locales.d.ts +27 -52
  42. package/lib/client/children-locales.js +8 -12
  43. package/lib/client/configuration-display.d.ts +5 -0
  44. package/lib/client/configuration-display.js +11 -0
  45. package/lib/client/controller.d.ts +1 -0
  46. package/lib/client/controller.js +20 -13
  47. package/lib/client/deployment-controller.d.ts +13 -1
  48. package/lib/client/deployment-controller.js +84 -24
  49. package/lib/client/deployment-data.d.ts +1 -0
  50. package/lib/client/deployment-data.js +4 -1
  51. package/lib/client/deployment-locales.d.ts +43 -0
  52. package/lib/client/deployment-locales.js +35 -9
  53. package/lib/client/deployment-modules.d.ts +9 -0
  54. package/lib/client/deployment-modules.js +24 -0
  55. package/lib/client/deployment-workspace.d.ts +48 -0
  56. package/lib/client/deployment-workspace.js +123 -0
  57. package/lib/client/index.js +11 -74
  58. package/lib/client/locales.d.ts +7 -0
  59. package/lib/client/locales.js +12 -6
  60. package/lib/client/permission-controller.d.ts +1 -0
  61. package/lib/client/permission-controller.js +3 -2
  62. package/lib/client/permission-locales.d.ts +25 -0
  63. package/lib/client/permission-locales.js +24 -4
  64. package/lib/client/session-labels.js +4 -3
  65. package/lib/client/styles.d.ts +1 -1
  66. package/lib/client/styles.js +9 -8
  67. package/lib/client.js +2713 -2361
  68. package/lib/commands.js +2 -0
  69. package/lib/config-file-store.d.ts +3 -0
  70. package/lib/config-file-store.js +4 -2
  71. package/lib/config-revision.d.ts +5 -0
  72. package/lib/config-revision.js +11 -0
  73. package/lib/core-permission-authority.js +11 -41
  74. package/lib/deployment-config.d.ts +9 -2
  75. package/lib/deployment-config.js +35 -8
  76. package/lib/deployment-permission-rules.js +19 -7
  77. package/lib/dsh-types.d.ts +1 -1
  78. package/lib/host-llm-startup.js +3 -3
  79. package/lib/host-llm.d.ts +9 -3
  80. package/lib/host-llm.js +48 -8
  81. package/lib/index.d.ts +16 -20
  82. package/lib/index.js +130 -416
  83. package/lib/lifetime.d.ts +4 -0
  84. package/lib/lifetime.js +22 -0
  85. package/lib/live-pi-ai-owner.d.ts +1 -0
  86. package/lib/live-pi-ai-owner.js +8 -4
  87. package/lib/mode.d.ts +3 -2
  88. package/lib/mode.js +28 -41
  89. package/lib/model-routing.d.ts +2 -8
  90. package/lib/model-routing.js +59 -175
  91. package/lib/native-admission.d.ts +56 -0
  92. package/lib/native-admission.js +313 -0
  93. package/lib/native-pi-ai-wire.d.ts +3 -1
  94. package/lib/native-pi-ai-wire.js +47 -13
  95. package/lib/permission-control.d.ts +0 -3
  96. package/lib/preset-registry.js +3 -2
  97. package/lib/preset-skills.d.ts +3 -12
  98. package/lib/preset-skills.js +28 -58
  99. package/lib/profile-diagnostics.d.ts +1 -1
  100. package/lib/profile-diagnostics.js +2 -2
  101. package/lib/profile-remote.js +61 -22
  102. package/lib/profile-rpc.d.ts +4 -3
  103. package/lib/profile-rpc.js +33 -37
  104. package/lib/profile-runtime.d.ts +31 -74
  105. package/lib/profile-runtime.js +224 -639
  106. package/lib/profile-store.d.ts +18 -6
  107. package/lib/profile-store.js +104 -62
  108. package/lib/profile-types.d.ts +18 -4
  109. package/lib/profiles.d.ts +3 -1
  110. package/lib/profiles.js +9 -7
  111. package/lib/prompt-content.d.ts +1 -0
  112. package/lib/prompt-content.js +4 -1
  113. package/lib/prompts.d.ts +2 -12
  114. package/lib/prompts.js +11 -66
  115. package/lib/role-control-remote.d.ts +1 -4
  116. package/lib/role-control-remote.js +8 -36
  117. package/lib/role-control-rpc.d.ts +10 -36
  118. package/lib/role-control-rpc.js +112 -269
  119. package/lib/role-control-types.d.ts +3 -26
  120. package/lib/role-control-types.js +3 -4
  121. package/lib/role-identity.d.ts +5 -0
  122. package/lib/role-identity.js +10 -0
  123. package/lib/role-invocation.d.ts +2 -2
  124. package/lib/role-llm-runtime.js +5 -11
  125. package/lib/role-policy.d.ts +19 -50
  126. package/lib/role-policy.js +136 -508
  127. package/lib/role-providers.d.ts +5 -8
  128. package/lib/role-providers.js +20 -86
  129. package/lib/role-routing.d.ts +1 -3
  130. package/lib/role-routing.js +24 -34
  131. package/lib/role-subagents.d.ts +5 -14
  132. package/lib/role-subagents.js +148 -106
  133. package/lib/runtime-integration.d.ts +5 -78
  134. package/lib/runtime-integration.js +11 -697
  135. package/lib/session-metadata.d.ts +13 -12
  136. package/lib/session-metadata.js +6 -31
  137. package/lib/session-scope.js +2 -1
  138. package/lib/settings.d.ts +5 -18
  139. package/lib/settings.js +19 -43
  140. package/lib/state.d.ts +3 -2
  141. package/lib/state.js +26 -10
  142. package/lib/status.d.ts +1 -9
  143. package/lib/status.js +3 -55
  144. package/lib/web-fetch-address-policy.d.ts +24 -0
  145. package/lib/web-fetch-address-policy.js +189 -0
  146. package/lib/web-fetch-fakeip.d.ts +25 -0
  147. package/lib/web-fetch-fakeip.js +107 -0
  148. package/package.json +113 -103
  149. package/docs/research/deepseek-v4-pro.md +0 -74
  150. package/docs/research/oh-dsh.md +0 -96
  151. package/lib/agent-registry.d.ts +0 -36
  152. package/lib/agent-registry.js +0 -75
  153. package/lib/child-admission.d.ts +0 -40
  154. package/lib/child-admission.js +0 -151
  155. package/lib/delivery-authority.d.ts +0 -83
  156. package/lib/delivery-authority.js +0 -397
  157. package/lib/native-child-evidence.d.ts +0 -40
  158. package/lib/native-child-evidence.js +0 -104
  159. package/lib/role-runs.d.ts +0 -138
  160. package/lib/role-runs.js +0 -335
  161. package/lib/session-persistence.d.ts +0 -36
  162. package/lib/session-persistence.js +0 -304
  163. package/lib/subagent-runtime.d.ts +0 -57
  164. package/lib/subagent-runtime.js +0 -257
  165. package/prompts/deepseek-flash.md +0 -11
  166. 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";
@@ -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
- 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,28 @@ 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) };
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
- if (draft !== undefined)
205
- this.publishRevision(draft, assertLock);
206
- const pointer = { version: 1, id: request.id, revision: draft?.revision ?? null };
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
- this.atomicReplace(join(this.stateDir, ".selection.json"), bytes, () => {
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
- 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
- };
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
- 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 };
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
- if (immutable.revision !== pointer.revision)
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 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
- }
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)
@@ -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
- validateProfileRevision(envelope.revision, "revision");
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 first = operation();
504
- const second = operation();
517
+ const result = operation();
505
518
  this.validateRoot(false);
506
519
  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;
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
- // rename is the transaction commit. No fallible work follows it.
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, digest, boundedOption, locked, atomicReplace };
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: digest(bytes) };
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 || tree.children?.length !== 3)
790
- throw new DsmmProfileError("corrupt-selection", "The selected profile pointer must contain exactly three unique fields in valid JSON.");
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
- if (Object.keys(record).length !== 3 || !["version", "id", "revision"].every((key) => Object.hasOwn(record, key)) || record.version !== 1)
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: 1, id: null, revision: null };
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
- validateProfileRevision(record.revision, "revision");
807
- return { version: 1, id: record.id, revision: record.revision };
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 || tree.children?.length !== 5)
830
- throw new DsmmProfileError("corrupt-selection", "The session choice must contain exactly five unique fields in valid JSON.");
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
- if (Object.keys(record).length !== 5 || !["version", "sessionId", "id", "revision", "epoch"].every((key) => Object.hasOwn(record, key)) || record.version !== 1 || record.sessionId !== sessionId) {
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
- validateProfileRevision(record.epoch, "admissionEpoch");
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) {
@@ -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,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
- /** Optional for older Hosts; explicit session intent always beats defaults. */
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" | "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>;
@@ -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 [`You are ${role.name} (role ID: ${role.id}).`, readPromptAsset("shared/locale.md"), body, readPromptAsset("shared/dsh-host-contract.md"), readPromptAsset(role.terminalArtifact.replace("prompts/source/", ""))].filter(Boolean).join("\n\n---\n\n");
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