@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,5 +1,7 @@
1
1
  import { isProfileId } from "../profile-remote.js";
2
2
  import { safeIssue } from "./diagnostics.js";
3
+ import { isConfigRevision } from "../config-revision.js";
4
+ import { writableSelectionVersion } from "./configuration-display.js";
3
5
  import { editStructuredPath, moveFallback } from "./structured.js";
4
6
  function modelSelectionWatermark(window) {
5
7
  let watermark = -1;
@@ -19,19 +21,27 @@ const NEW_EDITOR = "";
19
21
  export const NEW_PROFILE_CONTENT = '{\n "version": 1,\n "id": "new-profile",\n "label": "New profile",\n "settings": {\n // Runtime overlay only. Omitted fields inherit the deployment baseline.\n "defaultActive": true\n }\n}\n';
20
22
  /** A valid external CAS conflict is reconcilable; corruption is never reset implicitly. */
21
23
  export function canReconcileSelection(snapshot) {
22
- return snapshot !== null && (snapshot.selectionRevision === "absent" || /^[a-f0-9]{64}$/u.test(snapshot.selectionRevision))
24
+ return snapshot !== null && !snapshot.refreshRequired && writableSelectionVersion(snapshot.selectionRevision)
23
25
  && (snapshot.selectionError === undefined || snapshot.selectionError.code === "conflict");
24
26
  }
25
27
  /** Stable native Store seat, with no filesystem or transport authority. */
26
28
  export class ProfilesController {
27
29
  remote;
28
30
  current = { snapshot: null, editor: null, dirty: false, busy: null, issue: null, notice: null, pendingEditor: null,
29
- catalog: null, catalogBusy: false, catalogUnavailable: true, currentSessionId: null, session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null, invalidFields: [], editorEpoch: 0, validationEpoch: 0 };
31
+ catalog: null, catalogBusy: false, catalogUnavailable: true, currentSessionId: null, sessionViewEpoch: 0, sessionUnconfirmed: false, session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null, invalidFields: [], editorEpoch: 0, validationEpoch: 0 };
30
32
  accepted = null;
31
33
  listeners = new Set();
32
34
  generation = 0;
33
35
  disposed = false;
34
36
  sessionGeneration = 0;
37
+ pendingSessionSelections = new Set();
38
+ connection = null;
39
+ connectionBaseline;
40
+ connectionBound = false;
41
+ stopConnection = null;
42
+ composerBlocks = null;
43
+ composerReason = null;
44
+ composerBlock = null;
35
45
  catalogGeneration = 0;
36
46
  catalogRemote = null;
37
47
  modelSelectorGeneration = 0;
@@ -67,7 +77,7 @@ export class ProfilesController {
67
77
  editPath: (path, value) => this.editPath(path, value), moveFallback: (role, from, to) => this.editFallbackOrder(role, from, to),
68
78
  editRoute: (path, provider, model) => this.editRoute(path, provider, model),
69
79
  refreshCatalog: () => this.refreshCatalog(), refreshSession: () => this.refreshSession(),
70
- chooseSessionProfile: (id) => { if (!this.disposed && this.current.sessionBusy === null && this.current.busy === null && !this.current.dirty)
80
+ chooseSessionProfile: (id) => { if (!this.disposed && this.connectionCurrent() && !this.current.sessionUnconfirmed && this.current.sessionBusy === null && this.current.busy === null && !this.current.dirty && this.current.pendingEditor === null && this.current.invalidFields.length === 0)
71
81
  this.publish({ sessionChoice: id, sessionNotice: null }); },
72
82
  applySession: (options) => this.selectSession(false, options), resetSession: () => this.selectSession(true),
73
83
  setDeepwork: (active) => this.setDeepwork(active), useSessionProfileModel: () => this.selectSession(false, { useProfileModel: true }, true),
@@ -84,7 +94,66 @@ export class ProfilesController {
84
94
  constructor(remote) {
85
95
  this.remote = remote;
86
96
  }
87
- dispose() { this.disposed = true; this.generation += 1; this.sessionGeneration += 1; this.catalogGeneration += 1; this.modelSelectorGeneration += 1; this.modelSelectionGeneration += 1; this.stopModelSelection?.(); this.stopModelEvents?.(); this.stopModelInteraction?.(); this.stopModelSelection = null; this.stopModelEvents = null; this.stopModelInteraction = null; this.modelSelectionSource = null; this.modelEvents = null; this.modelInteraction = null; this.catalogRemote = null; this.modelSelector = null; this.listeners.clear(); }
97
+ dispose() { this.releaseComposerBlock(); this.stopConnection?.(); this.disposed = true; this.generation += 1; this.sessionGeneration += 1; this.catalogGeneration += 1; this.modelSelectorGeneration += 1; this.modelSelectionGeneration += 1; this.stopModelSelection?.(); this.stopModelEvents?.(); this.stopModelInteraction?.(); this.stopModelSelection = null; this.stopModelEvents = null; this.stopModelInteraction = null; this.modelSelectionSource = null; this.modelEvents = null; this.modelInteraction = null; this.catalogRemote = null; this.modelSelector = null; this.listeners.clear(); }
98
+ bindConnection(source) {
99
+ if (this.disposed)
100
+ return;
101
+ const replacement = this.connectionBound && (source !== this.connection || source?.getSnapshot() !== this.connectionBaseline);
102
+ this.stopConnection?.();
103
+ this.connection = source;
104
+ this.connectionBound = true;
105
+ this.connectionBaseline = source?.getSnapshot();
106
+ const invalidate = () => {
107
+ this.connectionBaseline = source?.getSnapshot();
108
+ this.generation += 1;
109
+ this.sessionGeneration += 1;
110
+ this.modelSelectorGeneration += 1;
111
+ this.publish({ session: null, sessionBusy: null, sessionNotice: null, sessionUnconfirmed: this.current.currentSessionId !== null,
112
+ sessionViewEpoch: this.current.sessionViewEpoch + 1, busy: null, issue: { kind: "transport", code: "unavailable" } });
113
+ };
114
+ if (replacement || source === null || this.connectionBaseline === undefined)
115
+ invalidate();
116
+ this.stopConnection = source?.subscribe(() => {
117
+ invalidate();
118
+ if (this.connectionCurrent()) {
119
+ void this.refresh();
120
+ void this.refreshSession();
121
+ }
122
+ }) ?? null;
123
+ }
124
+ connectionCurrent() {
125
+ return !this.connectionBound || this.connectionBaseline !== undefined && this.connection?.getSnapshot() === this.connectionBaseline;
126
+ }
127
+ attachComposerBlocks(blocks, reason) {
128
+ if (this.disposed)
129
+ return;
130
+ this.releaseComposerBlock();
131
+ this.composerBlocks = blocks;
132
+ this.composerReason = reason ?? null;
133
+ this.syncComposerBlock();
134
+ }
135
+ releaseComposerBlock() {
136
+ const held = this.composerBlock;
137
+ this.composerBlock = null;
138
+ // Native blocks have no owner token. Only release the exact object and
139
+ // store we installed into an empty seat; never forget or clear another owner.
140
+ if (held !== null && this.composerBlocks?.storeFor(held.id) === held.store && held.store.getSnapshot() === held.block)
141
+ this.composerBlocks.set(held.id, undefined);
142
+ }
143
+ syncComposerBlock() {
144
+ const { currentSessionId, sessionBusy, sessionUnconfirmed, session } = this.current;
145
+ const wanted = currentSessionId !== null && (sessionBusy === "apply" || sessionBusy === "reset" || sessionUnconfirmed || session?.refreshRequired || session?.selection.refreshRequired);
146
+ if (!wanted || this.composerBlock?.id !== currentSessionId)
147
+ this.releaseComposerBlock();
148
+ if (!wanted || this.composerBlock !== null || this.composerBlocks === null || this.composerReason === null)
149
+ return;
150
+ const id = currentSessionId, store = this.composerBlocks.storeFor(id);
151
+ if (store.getSnapshot() !== undefined)
152
+ return;
153
+ const block = { reason: this.composerReason() };
154
+ this.composerBlock = { id, store, block };
155
+ this.composerBlocks.set(id, block);
156
+ }
88
157
  attachModelSelector(remote) {
89
158
  if (this.disposed)
90
159
  return;
@@ -164,7 +233,7 @@ export class ProfilesController {
164
233
  this.attachModelEventSource(null, null);
165
234
  if (id !== this.modelInteractionSessionId)
166
235
  this.attachModelInteractionSource(null, null);
167
- this.publish({ currentSessionId: id, session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null });
236
+ this.publish({ currentSessionId: id, sessionViewEpoch: this.current.sessionViewEpoch + 1, sessionUnconfirmed: id !== null && this.pendingSessionSelections.has(id), session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null });
168
237
  if (id !== null)
169
238
  void this.refreshSession();
170
239
  }
@@ -193,18 +262,18 @@ export class ProfilesController {
193
262
  }
194
263
  async refreshSession(preserveFeedback = false) {
195
264
  const id = this.current.currentSessionId;
196
- if (this.disposed || id === null || this.current.sessionBusy !== null)
265
+ if (this.disposed || !this.connectionCurrent() || id === null || this.current.sessionBusy !== null)
197
266
  return;
198
267
  this.modeRefreshPending = false;
199
268
  const generation = ++this.sessionGeneration;
200
- const live = () => !this.disposed && generation === this.sessionGeneration && id === this.current.currentSessionId;
269
+ const live = () => !this.disposed && this.connectionCurrent() && generation === this.sessionGeneration && id === this.current.currentSessionId;
201
270
  this.publish({ sessionBusy: "read", ...(preserveFeedback ? {} : { sessionIssue: null, sessionNotice: null }) });
202
271
  try {
203
272
  const session = await this.unwrap(this.remote.describeSession(id));
204
273
  if (session.sessionId !== id)
205
274
  throw { kind: "assembly", code: "unavailable" };
206
275
  if (live())
207
- this.publish({ session, sessionChoice: session.selection.selectedId });
276
+ this.publish({ session, sessionChoice: (session.admittedSelection ?? session.selection).selectedId, sessionUnconfirmed: this.pendingSessionSelections.has(id) });
208
277
  }
209
278
  catch (error) {
210
279
  if (live())
@@ -219,13 +288,15 @@ export class ProfilesController {
219
288
  }
220
289
  async setDeepwork(active) {
221
290
  const { currentSessionId: id, session } = this.current;
222
- if (this.disposed || id === null || session?.deepwork === undefined || session.deepwork.locked || !session.switchAllowed
291
+ if (this.disposed || !this.connectionCurrent() || this.current.sessionUnconfirmed || id === null || session?.deepwork === undefined || session.refreshRequired || session.selection.refreshRequired || session.deepwork.locked || session.canToggleMode !== true
223
292
  || this.current.sessionBusy !== null || this.current.busy !== null || this.remote.selectMode === undefined)
224
293
  return;
225
294
  const generation = ++this.sessionGeneration;
226
- const live = () => !this.disposed && generation === this.sessionGeneration && id === this.current.currentSessionId;
295
+ const live = () => !this.disposed && this.connectionCurrent() && generation === this.sessionGeneration && id === this.current.currentSessionId;
227
296
  this.publish({ sessionBusy: "mode", sessionIssue: null, sessionNotice: null });
228
297
  try {
298
+ if (!live())
299
+ return;
229
300
  const accepted = await this.unwrap(this.remote.selectMode(id, { sessionId: id, active,
230
301
  expectedModeRevision: session.deepwork.revision, expectedAdmissionEpoch: session.admissionEpoch }));
231
302
  if (accepted.sessionId !== id || accepted.deepwork?.active !== active || !accepted.deepwork.explicit)
@@ -246,12 +317,13 @@ export class ProfilesController {
246
317
  }
247
318
  async selectSession(reset, options, modelOnly = false) {
248
319
  const { currentSessionId: id, session, sessionChoice, snapshot } = this.current;
249
- if (this.disposed || id === null || session === null || !session.switchAllowed || this.current.sessionBusy !== null
250
- || this.current.busy !== null || this.current.dirty || this.current.pendingEditor !== null)
320
+ if (this.disposed || !this.connectionCurrent() || this.current.sessionUnconfirmed || id === null || session === null || session.refreshRequired || session.selection.refreshRequired || !writableSelectionVersion(session.selection.selectionRevision)
321
+ || (modelOnly ? session.canSelectModel !== true : session.canApplyOverlay !== true || session.applyOverlayUnavailableReason === "new-session-required") || this.current.sessionBusy !== null
322
+ || this.current.busy !== null || this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null)
251
323
  return;
252
324
  const selectedId = reset ? null : sessionChoice;
253
- const revision = snapshot?.profiles.find((profile) => profile.id === selectedId)?.revision;
254
- if (!modelOnly && selectedId !== null && revision == null)
325
+ const profile = snapshot?.profiles.find((profile) => profile.id === selectedId), revision = profile?.revision;
326
+ if (!modelOnly && selectedId !== null && (!isConfigRevision(revision) || profile?.error !== undefined))
255
327
  return;
256
328
  const generation = ++this.sessionGeneration;
257
329
  const useProfileModel = !reset && options?.useProfileModel === true;
@@ -263,23 +335,32 @@ export class ProfilesController {
263
335
  const modeWatermark = eventSource === null ? -1 : modeIntentWatermark(eventSource.getSnapshot());
264
336
  const interaction = this.modelInteraction, interactionGeneration = this.modelInteractionGeneration;
265
337
  const pendingNativeChoice = interaction?.getSnapshot().status === "selecting";
266
- const live = () => !this.disposed && generation === this.sessionGeneration && id === this.current.currentSessionId;
338
+ const live = () => !this.disposed && this.connectionCurrent() && generation === this.sessionGeneration && id === this.current.currentSessionId;
267
339
  const selectorLive = () => live() && selector !== null && selector === this.modelSelector && selectorGeneration === this.modelSelectorGeneration;
340
+ if (!modelOnly)
341
+ this.pendingSessionSelections.add(id);
268
342
  this.publish({ sessionBusy: reset ? "reset" : "apply", sessionIssue: null, sessionNotice: null });
269
343
  try {
344
+ if (!live())
345
+ return;
270
346
  const accepted = await this.unwrap(modelOnly ? this.remote.describeSession(id) : this.remote.selectSession(id, {
271
347
  sessionId: id, id: selectedId, ...(selectedId === null ? {} : { expectedRevision: revision }),
272
348
  expectedSelectionRevision: session.selection.selectionRevision, expectedAdmissionEpoch: session.admissionEpoch,
273
349
  }));
274
350
  if (accepted.sessionId !== id)
275
351
  throw { kind: "assembly", code: "unavailable" };
276
- if (modelOnly && (accepted.admissionEpoch !== session.admissionEpoch || accepted.deepwork?.revision !== session.deepwork?.revision || !accepted.switchAllowed))
352
+ if (modelOnly && (accepted.admissionEpoch !== session.admissionEpoch || accepted.deepwork?.revision !== session.deepwork?.revision))
277
353
  throw { kind: "domain", code: "conflict" };
278
354
  if (!live())
279
355
  return;
280
- this.publish({ session: accepted, sessionChoice: accepted.selection.selectedId, sessionNotice: useProfileModel ? null : reset ? "reset" : "applied" });
281
- if (!useProfileModel || !live())
356
+ this.publish({ session: accepted, sessionChoice: (accepted.admittedSelection ?? accepted.selection).selectedId,
357
+ sessionNotice: useProfileModel || accepted.refreshRequired || accepted.selection.refreshRequired ? null : reset ? "reset" : "applied" });
358
+ if (!useProfileModel || accepted.refreshRequired || accepted.selection.refreshRequired || !live())
282
359
  return;
360
+ if (accepted.canSelectModel !== true || !writableSelectionVersion(accepted.selection.selectionRevision)) {
361
+ this.publish({ sessionIssue: { kind: "assembly", code: accepted.selectModelUnavailableReason ?? "unavailable", source: "profile-model" } });
362
+ return;
363
+ }
283
364
  if (accepted.profileModel === undefined) {
284
365
  this.publish({ sessionIssue: { kind: "assembly", code: "model-unconfigured", source: "profile-model" } });
285
366
  return;
@@ -327,20 +408,29 @@ export class ProfilesController {
327
408
  }
328
409
  }
329
410
  catch (error) {
330
- if (live())
331
- this.publish({ sessionIssue: this.issue(error) });
411
+ if (live()) {
412
+ const issue = this.issue(error);
413
+ this.publish({ sessionIssue: issue, sessionUnconfirmed: !modelOnly && (issue.kind !== "domain" || issue.code === "cancelled") });
414
+ }
332
415
  }
333
416
  finally {
417
+ if (!modelOnly)
418
+ this.pendingSessionSelections.delete(id);
334
419
  if (live()) {
335
420
  this.publish({ sessionBusy: null });
336
421
  this.refreshObservedMode();
337
422
  }
423
+ else if (!modelOnly && !this.disposed && this.connectionCurrent() && id === this.current.currentSessionId) {
424
+ this.modeRefreshPending = true;
425
+ this.refreshObservedMode();
426
+ }
338
427
  }
339
428
  }
340
429
  publish(patch) {
341
430
  if (this.disposed)
342
431
  return;
343
432
  this.current = { ...this.current, ...patch };
433
+ this.syncComposerBlock();
344
434
  for (const listener of this.listeners)
345
435
  listener();
346
436
  }
@@ -366,10 +456,10 @@ export class ProfilesController {
366
456
  return { kind: "assembly", code: "unavailable" };
367
457
  }
368
458
  async perform(busy, operation) {
369
- if (this.disposed || this.current.busy !== null || this.current.sessionBusy === "apply" || this.current.sessionBusy === "reset" || this.current.pendingEditor !== null)
459
+ if (this.disposed || !this.connectionCurrent() || this.current.busy !== null || this.current.sessionBusy === "apply" || this.current.sessionBusy === "reset" || this.current.pendingEditor !== null)
370
460
  return;
371
461
  const generation = ++this.generation;
372
- const live = () => !this.disposed && generation === this.generation;
462
+ const live = () => !this.disposed && this.connectionCurrent() && generation === this.generation;
373
463
  this.publish({ busy, issue: null, notice: null });
374
464
  try {
375
465
  await operation(live);
@@ -452,13 +542,13 @@ export class ProfilesController {
452
542
  }
453
543
  editContent(content) {
454
544
  const editor = this.current.editor;
455
- if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null)
545
+ if (editor === null || editor.refreshRequired || this.current.busy !== null || this.current.pendingEditor !== null)
456
546
  return;
457
547
  this.publish({ editor: { ...editor, content }, dirty: this.accepted === null || this.accepted.content !== content || this.accepted.id !== editor.id, issue: null, notice: null });
458
548
  }
459
549
  editPath(path, value) {
460
550
  const editor = this.current.editor;
461
- if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null)
551
+ if (editor === null || editor.refreshRequired || this.current.busy !== null || this.current.pendingEditor !== null)
462
552
  return;
463
553
  const content = editStructuredPath(editor.content, path, value);
464
554
  if (content === null) {
@@ -469,7 +559,7 @@ export class ProfilesController {
469
559
  }
470
560
  editRoute(path, provider, model) {
471
561
  const editor = this.current.editor;
472
- if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null)
562
+ if (editor === null || editor.refreshRequired || this.current.busy !== null || this.current.pendingEditor !== null)
473
563
  return;
474
564
  let content = editor.content;
475
565
  for (const [key, value] of [["provider", provider], ["model", model], ["reasoningEffort", undefined]]) {
@@ -483,7 +573,7 @@ export class ProfilesController {
483
573
  }
484
574
  editFallbackOrder(role, from, to) {
485
575
  const editor = this.current.editor;
486
- if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null)
576
+ if (editor === null || editor.refreshRequired || this.current.busy !== null || this.current.pendingEditor !== null)
487
577
  return;
488
578
  const content = moveFallback(editor.content, role, from, to);
489
579
  if (content !== null)
@@ -491,7 +581,7 @@ export class ProfilesController {
491
581
  }
492
582
  async save() {
493
583
  const editor = this.current.editor;
494
- if (editor === null || !this.current.dirty || this.current.snapshot === null || this.current.busy !== null || this.current.pendingEditor !== null || this.current.invalidFields.length > 0)
584
+ if (editor === null || editor.refreshRequired || editor.revision !== null && !isConfigRevision(editor.revision) || !this.current.dirty || this.current.snapshot === null || this.current.busy !== null || this.current.pendingEditor !== null || this.current.invalidFields.length > 0)
495
585
  return;
496
586
  if (!isProfileId(editor.id)) {
497
587
  this.publish({ issue: { kind: "domain", code: "validation", field: "id" }, notice: null, validationEpoch: this.current.validationEpoch + 1 });
@@ -512,7 +602,7 @@ export class ProfilesController {
512
602
  }
513
603
  async apply() {
514
604
  const { editor, snapshot, dirty } = this.current;
515
- if (editor?.revision == null || !canReconcileSelection(snapshot) || dirty)
605
+ if (editor?.refreshRequired || !isConfigRevision(editor?.revision) || !canReconcileSelection(snapshot) || dirty)
516
606
  return;
517
607
  await this.perform("apply", async (live) => {
518
608
  const accepted = await this.unwrap(this.remote.select({ id: editor.id, expectedRevision: editor.revision, expectedSelectionRevision: snapshot.selectionRevision }));
@@ -2,7 +2,7 @@ import type { ConfigFormSnapshot, ConfigForm } from "@deepseek-ai/dsh-client-ui-
2
2
  import type { ConnectionGenerationState } from "@deepseek-ai/dsh-client-connection/client";
3
3
  import type { DsmmConfigRemote } from "../profile-remote.js";
4
4
  import type { DeploymentEditorSnapshot, SessionProfileSnapshot } from "../profile-types.js";
5
- export type DeploymentIssue = "unavailable" | "not-owned" | "conflict" | "validation" | "transport";
5
+ export type DeploymentIssue = "unavailable" | "not-owned" | "conflict" | "validation" | "transport" | "unconfirmed";
6
6
  export interface DeploymentView {
7
7
  snapshot: DeploymentEditorSnapshot | null;
8
8
  draft: Record<string, unknown>;
@@ -11,6 +11,12 @@ export interface DeploymentView {
11
11
  issue: DeploymentIssue | null;
12
12
  saved: boolean;
13
13
  session: SessionProfileSnapshot | null;
14
+ raw: Readonly<Record<string, {
15
+ text: string;
16
+ invalid: boolean;
17
+ }>>;
18
+ invalidFields: readonly string[];
19
+ refreshRequired: boolean;
14
20
  }
15
21
  export interface NativePageForm {
16
22
  state: ConfigFormSnapshot<Record<string, unknown>>;
@@ -31,6 +37,7 @@ export declare class DeploymentController {
31
37
  private connection;
32
38
  private connectionBaseline;
33
39
  private stopConnection;
40
+ private children;
34
41
  constructor(remote: DsmmConfigRemote, layer: "global" | "profile", rowNamespace?: string | null);
35
42
  readonly getSnapshot: () => DeploymentView;
36
43
  readonly subscribe: (listener: () => void) => (() => void);
@@ -42,6 +49,11 @@ export declare class DeploymentController {
42
49
  private publish;
43
50
  attachForm(form: NativePageForm | null): void;
44
51
  setInvalid(path: string, invalid: boolean): void;
52
+ setRaw(path: string, text: string, invalid: boolean): void;
53
+ clearRaw(prefix: string): void;
54
+ canEdit(): boolean;
55
+ canSave(): boolean;
56
+ pendingPaths(): readonly string[];
45
57
  canWriteProfile(snapshot?: DeploymentEditorSnapshot | null): boolean;
46
58
  edit(path: readonly string[], value: unknown): void;
47
59
  refresh(discard?: boolean): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { equal, editLayer, layerDiff, mergeLayer, record, validateEditorValue } from "./deployment-data.js";
1
+ import { equal, editLayer, layerDiff, mergeLayer, record, scopeSchema, validateEditorValue } from "./deployment-data.js";
2
2
  class Refusal extends Error {
3
3
  code;
4
4
  constructor(code) {
@@ -6,6 +6,32 @@ class Refusal extends Error {
6
6
  this.code = code;
7
7
  }
8
8
  }
9
+ /** Native wire shape only; schema semantics remain independently validated. */
10
+ function isNativeJson(value, active = new Set()) {
11
+ if (value === null || typeof value === "string" || typeof value === "boolean")
12
+ return true;
13
+ if (typeof value === "number")
14
+ return Number.isFinite(value);
15
+ if (typeof value !== "object" || active.has(value) || Object.getOwnPropertySymbols(value).length > 0)
16
+ return false;
17
+ const array = Array.isArray(value), prototype = Object.getPrototypeOf(value);
18
+ if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null)
19
+ return false;
20
+ active.add(value);
21
+ const properties = Object.getOwnPropertyDescriptors(value);
22
+ const valid = Object.entries(properties).every(([key, descriptor]) => array && key === "length" || descriptor.enumerable
23
+ && Object.hasOwn(descriptor, "value") && (!array || /^(0|[1-9][0-9]*)$/u.test(key) && Number(key) < value.length)
24
+ && isNativeJson(descriptor.value, active));
25
+ active.delete(value);
26
+ return valid && (!array || Object.keys(properties).length === value.length + 1);
27
+ }
28
+ function nativePathEdit(edit) {
29
+ if (edit.op === "unset")
30
+ return edit;
31
+ if (!isNativeJson(edit.value))
32
+ throw new Refusal("validation");
33
+ return { op: "set", path: edit.path, value: edit.value };
34
+ }
9
35
  async function unwrap(promise) {
10
36
  const result = await promise;
11
37
  if (result.ok)
@@ -21,7 +47,7 @@ export class DeploymentController {
21
47
  remote;
22
48
  layer;
23
49
  rowNamespace;
24
- state = { snapshot: null, draft: {}, dirty: false, busy: false, issue: null, saved: false, session: null };
50
+ state = { snapshot: null, draft: {}, dirty: false, busy: false, issue: null, saved: false, session: null, raw: {}, invalidFields: [], refreshRequired: false };
25
51
  listeners = new Set();
26
52
  generation = 0;
27
53
  disposed = false;
@@ -31,6 +57,7 @@ export class DeploymentController {
31
57
  connection = null;
32
58
  connectionBaseline;
33
59
  stopConnection = null;
60
+ children = new Set();
34
61
  constructor(remote, layer, rowNamespace = null) {
35
62
  this.remote = remote;
36
63
  this.layer = layer;
@@ -42,6 +69,8 @@ export class DeploymentController {
42
69
  bindConnection(source) {
43
70
  this.stopConnection?.();
44
71
  this.connection = source;
72
+ for (const child of this.children)
73
+ child.bindConnection(source);
45
74
  this.stopConnection = source.subscribe(() => {
46
75
  if (this.disposed)
47
76
  return;
@@ -53,6 +82,7 @@ export class DeploymentController {
53
82
  const controller = new DeploymentController(this.remote, "profile", namespace);
54
83
  if (this.connection !== null)
55
84
  controller.bindConnection(this.connection);
85
+ this.children.add(controller);
56
86
  return controller;
57
87
  }
58
88
  currentConnection() { return this.connection === null || this.connection.getSnapshot() !== undefined && this.connection.getSnapshot() === this.connectionBaseline; }
@@ -72,8 +102,26 @@ export class DeploymentController {
72
102
  this.invalid.add(path);
73
103
  else
74
104
  this.invalid.delete(path);
75
- this.publish({ dirty: this.invalid.size > 0 || !equal(this.baseline, this.state.draft), saved: false });
105
+ this.publish({ invalidFields: [...this.invalid], dirty: this.invalid.size > 0 || !equal(this.baseline, this.state.draft), saved: false });
106
+ }
107
+ setRaw(path, text, invalid) {
108
+ if (!this.canEdit())
109
+ return;
110
+ this.publish({ raw: { ...this.state.raw, [path]: { text, invalid } } });
111
+ this.setInvalid(path, invalid);
76
112
  }
113
+ clearRaw(prefix) {
114
+ if (!this.canEdit())
115
+ return;
116
+ const raw = Object.fromEntries(Object.entries(this.state.raw).filter(([path]) => path !== prefix && !path.startsWith(`${prefix}.`)));
117
+ for (const path of [...this.invalid])
118
+ if (path === prefix || path.startsWith(`${prefix}.`))
119
+ this.invalid.delete(path);
120
+ this.publish({ raw, invalidFields: [...this.invalid], dirty: this.invalid.size > 0 || !equal(this.baseline, this.state.draft) });
121
+ }
122
+ canEdit() { return !this.disposed && !this.state.busy && !this.state.refreshRequired && this.state.snapshot !== null && this.state.snapshot.globalRevision !== "unavailable" && (this.layer === "global" || this.state.snapshot.nativeRevision !== "unavailable") && this.currentConnection() && (this.state.issue === null || this.state.issue === "validation") && (this.layer === "global" || this.canWriteProfile()); }
123
+ canSave() { return this.canEdit() && this.state.issue === null && this.state.dirty && this.invalid.size === 0; }
124
+ pendingPaths() { return [...new Set([...layerDiff(this.baseline, this.state.draft).map(edit => edit.path.join(".")), ...this.invalid])]; }
77
125
  canWriteProfile(snapshot = this.state.snapshot) {
78
126
  const native = this.form?.state;
79
127
  return this.currentConnection() && snapshot !== null && this.rowNamespace !== null && this.rowNamespace === snapshot.namespace
@@ -82,7 +130,7 @@ export class DeploymentController {
82
130
  && equal(native.base ?? null, snapshot.nativeForm.base) && equal(native.user ?? null, snapshot.nativeForm.user);
83
131
  }
84
132
  edit(path, value) {
85
- if (this.state.busy || this.disposed || this.state.snapshot === null || !this.currentConnection() || this.state.issue === "not-owned" || this.layer === "profile" && !this.canWriteProfile())
133
+ if (!this.canEdit())
86
134
  return;
87
135
  const draft = editLayer(this.state.draft, path, value);
88
136
  this.publish({ draft, dirty: this.invalid.size > 0 || !equal(this.baseline, draft), issue: null, saved: false });
@@ -99,6 +147,8 @@ export class DeploymentController {
99
147
  const snapshot = await unwrap(this.remote.describeSettings());
100
148
  if (this.disposed || generation !== this.generation)
101
149
  return;
150
+ if (snapshot.globalRevision === "unavailable" || this.layer === "profile" && snapshot.nativeRevision === "unavailable")
151
+ throw new Refusal("unavailable");
102
152
  const old = this.state.snapshot;
103
153
  if (old !== null && (old.entryId !== snapshot.entryId || old.hostProfileKey !== snapshot.hostProfileKey))
104
154
  throw new Refusal("unavailable");
@@ -110,7 +160,7 @@ export class DeploymentController {
110
160
  this.invalid.clear();
111
161
  this.connectionBaseline = connection;
112
162
  this.baseline = this.layer === "global" ? snapshot.global : record(snapshot.nativeForm?.user) ? snapshot.nativeForm.user : {};
113
- this.publish({ snapshot, draft: structuredClone(this.baseline), dirty: false, issue: null });
163
+ this.publish({ snapshot, draft: structuredClone(this.baseline), raw: {}, invalidFields: [], dirty: false, issue: null, refreshRequired: false });
114
164
  }
115
165
  }
116
166
  catch (error) {
@@ -124,22 +174,20 @@ export class DeploymentController {
124
174
  }
125
175
  async save() {
126
176
  const { snapshot, draft, dirty, busy, issue } = this.state;
127
- if (this.disposed || snapshot === null || !dirty || busy || issue !== null || !this.currentConnection() || this.invalid.size > 0 || this.layer === "profile" && !this.canWriteProfile())
177
+ if (!this.canSave() || snapshot === null || !dirty || busy || issue !== null)
178
+ return;
179
+ if (snapshot.globalRevision === "unavailable" || this.layer === "profile" && snapshot.nativeRevision === "unavailable") {
180
+ this.publish({ issue: "unavailable" });
128
181
  return;
129
- const schema = this.layer === "global" ? snapshot.schema : { ...snapshot.schema, fields: Object.fromEntries(Object.entries(snapshot.schema.fields ?? {}).filter(([key]) => key !== "modules")) };
130
- const editable = { ...draft };
131
- if (this.layer === "profile") {
132
- if (!equal(editable.sessionPersistence, this.baseline.sessionPersistence)) {
133
- this.publish({ issue: "validation" });
134
- return;
135
- }
136
- delete editable.sessionPersistence;
137
182
  }
183
+ const selectedSchema = scopeSchema(snapshot, this.layer);
184
+ const schema = { ...selectedSchema, fields: Object.fromEntries(Object.entries(selectedSchema.fields ?? {}).filter(([key]) => key !== (this.layer === "global" ? "runtime" : "modules"))) };
185
+ const mergedSchema = { ...snapshot.schema, fields: { ...snapshot.schema.fields, ...snapshot.nativeSchema?.fields } };
186
+ const editable = { ...draft };
138
187
  const lower = this.layer === "global" ? snapshot.defaults : mergeLayer(mergeLayer(snapshot.defaults, snapshot.global), snapshot.nativeForm?.base ?? {});
139
188
  const candidate = mergeLayer(lower, editable);
140
189
  const merged = (this.layer === "global" ? mergeLayer(candidate, snapshot.profile) : candidate);
141
- delete merged.sessionPersistence;
142
- if (!validateEditorValue(editable, schema, true) || !validateEditorValue(merged, snapshot.schema)) {
190
+ if (!validateEditorValue(editable, schema, true) || !validateEditorValue(merged, mergedSchema)) {
143
191
  this.publish({ issue: "validation" });
144
192
  return;
145
193
  }
@@ -156,28 +204,40 @@ export class DeploymentController {
156
204
  return;
157
205
  if (current.entryId !== snapshot.entryId || current.hostProfileKey !== snapshot.hostProfileKey || current.globalRevision !== snapshot.globalRevision)
158
206
  throw new Refusal("conflict");
159
- if (this.layer === "global")
160
- await unwrap(this.remote.save({ expectedRevision: snapshot.globalRevision, edits }));
207
+ let acceptedRefreshRequired = false;
208
+ if (this.layer === "global") {
209
+ const accepted = await unwrap(this.remote.save({ expectedRevision: snapshot.globalRevision, edits }));
210
+ acceptedRefreshRequired = accepted.refreshRequired === true || accepted.revision === "unavailable";
211
+ }
161
212
  else {
162
213
  if (current.nativeRevision !== snapshot.nativeRevision || !this.canWriteProfile(current))
163
214
  throw new Refusal("conflict");
164
215
  const form = this.form;
165
- if (!await form.mutate(edits, snapshot.nativeFormRevision))
166
- throw new Refusal("conflict");
216
+ if (!await form.mutate(edits.map(nativePathEdit), snapshot.nativeFormRevision))
217
+ throw new Refusal("unconfirmed");
167
218
  }
168
219
  if (this.disposed || generation !== this.generation)
169
220
  return;
170
221
  this.baseline = structuredClone(draft);
171
- this.publish({ dirty: false, saved: true, issue: null });
222
+ this.invalid.clear();
223
+ this.publish({ dirty: false, saved: true, issue: null, raw: {}, invalidFields: [], refreshRequired: true });
172
224
  // A successful durable save remains successful even if the follow-up read fails.
225
+ if (acceptedRefreshRequired)
226
+ return;
173
227
  try {
174
228
  const next = await unwrap(this.remote.describeSettings());
175
- if (!this.disposed && generation === this.generation)
176
- this.publish({ snapshot: next });
229
+ if (!this.disposed && generation === this.generation) {
230
+ if (next.entryId !== snapshot.entryId || next.hostProfileKey !== snapshot.hostProfileKey || next.globalRevision === "unavailable" || this.layer === "profile" && next.nativeRevision === "unavailable")
231
+ this.publish({ refreshRequired: true });
232
+ else {
233
+ this.baseline = structuredClone(this.layer === "global" ? next.global : record(next.nativeForm?.user) ? next.nativeForm.user : {});
234
+ this.publish({ snapshot: next, draft: structuredClone(this.baseline), refreshRequired: false });
235
+ }
236
+ }
177
237
  }
178
238
  catch {
179
239
  if (!this.disposed && generation === this.generation)
180
- this.publish({ issue: "unavailable" });
240
+ this.publish({ refreshRequired: true });
181
241
  }
182
242
  }
183
243
  catch (error) {
@@ -1,6 +1,7 @@
1
1
  import type { DeploymentAdmissionView, DeploymentEditorSnapshot, DeploymentSchemaNode } from "../profile-types.js";
2
2
  import type { DeploymentPathEdit } from "../deployment-config.js";
3
3
  export declare function record(value: unknown): value is Record<string, unknown>;
4
+ export declare function scopeSchema(snapshot: DeploymentEditorSnapshot, layer: "global" | "profile"): DeploymentSchemaNode;
4
5
  export declare function at(value: unknown, path: readonly string[]): unknown;
5
6
  export declare function equal(a: unknown, b: unknown): boolean;
6
7
  export declare function mergeLayer(base: unknown, override: unknown): unknown;
@@ -3,6 +3,9 @@ import { copyRouteJson, normalizeModelRouteJson } from "../route-json.js";
3
3
  export function record(value) {
4
4
  return value !== null && typeof value === "object" && !Array.isArray(value);
5
5
  }
6
+ export function scopeSchema(snapshot, layer) {
7
+ return layer === "profile" ? snapshot.nativeSchema ?? snapshot.schema : snapshot.schema;
8
+ }
6
9
  export function at(value, path) {
7
10
  return path.reduce((node, key) => record(node) && Object.hasOwn(node, key) ? node[key] : undefined, value);
8
11
  }
@@ -115,7 +118,7 @@ export function enumValues(schema) {
115
118
  ? schema.alternatives.map(node => node.value) : null;
116
119
  }
117
120
  export function visibleDeploymentPath(path) {
118
- return path[0] !== "lsp" && (path[0] !== "permissionControl" || path.length === 1 || path.length === 2 && path[1] === "enabled");
121
+ return !["lsp", "modeName", "section"].includes(path[0]);
119
122
  }
120
123
  /** Only visible Host-projected inspector layers, never raw sparse editor input. */
121
124
  export function inspectorPaths(snapshot, admitted) {