@dsmm/dsmm 0.3.14 → 0.3.16

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 (65) hide show
  1. package/README.md +83 -36
  2. package/docs/agent-presets.md +1 -1
  3. package/docs/compatibility.md +3 -3
  4. package/docs/deferred-native-approval-risk.md +1 -1
  5. package/docs/design.md +1 -1
  6. package/docs/lsp.md +1 -1
  7. package/docs/model-routing.md +13 -6
  8. package/docs/native-permissions.md +1 -1
  9. package/docs/profiles.md +3 -1
  10. package/docs/roadmap.md +2 -2
  11. package/docs/runtime-recovery.md +4 -4
  12. package/docs/safety-guards.md +1 -1
  13. package/docs/settings-status.md +4 -2
  14. package/docs/tui.md +53 -0
  15. package/dsh-plugin.json +41 -0
  16. package/lib/client/DeploymentFields.js +3 -1
  17. package/lib/client/DeploymentPage.js +4 -1
  18. package/lib/client/EditableChoice.js +5 -2
  19. package/lib/client/ProfileModelsDialog.d.ts +2 -1
  20. package/lib/client/ProfileModelsDialog.js +9 -5
  21. package/lib/client/ProfilesSection.js +1 -1
  22. package/lib/client/RoleToolView-locales.d.ts +1 -1
  23. package/lib/client/RoleToolView-locales.js +2 -2
  24. package/lib/client/SessionProfiles.js +8 -7
  25. package/lib/client/children-locales.d.ts +1 -1
  26. package/lib/client/controller.d.ts +13 -1
  27. package/lib/client/controller.js +114 -20
  28. package/lib/client/deployment-locales.d.ts +2 -0
  29. package/lib/client/deployment-locales.js +6 -3
  30. package/lib/client/deployment-modules.js +1 -1
  31. package/lib/client/index.js +22 -4
  32. package/lib/client/locales.d.ts +1 -0
  33. package/lib/client/locales.js +6 -4
  34. package/lib/client/session-labels.d.ts +1 -0
  35. package/lib/client/session-labels.js +3 -0
  36. package/lib/client/styles.d.ts +1 -1
  37. package/lib/client/styles.js +23 -13
  38. package/lib/client.js +226 -86
  39. package/lib/commands.d.ts +7 -3
  40. package/lib/commands.js +20 -11
  41. package/lib/host-llm.js +6 -1
  42. package/lib/index.d.ts +1 -1
  43. package/lib/index.js +2 -6
  44. package/lib/model-routing.js +43 -19
  45. package/lib/profile-diagnostics.js +1 -0
  46. package/lib/profile-runtime.js +1 -1
  47. package/lib/request-routing.d.ts +27 -0
  48. package/lib/request-routing.js +69 -0
  49. package/lib/role-llm-runtime.js +15 -2
  50. package/lib/role-routing.d.ts +4 -3
  51. package/lib/role-routing.js +17 -10
  52. package/lib/runtime-recovery.js +56 -16
  53. package/lib/settings.d.ts +3 -0
  54. package/lib/settings.js +9 -0
  55. package/lib/state.d.ts +2 -2
  56. package/lib/state.js +13 -4
  57. package/lib/status.d.ts +5 -0
  58. package/lib/status.js +18 -7
  59. package/lib/tui-actions.d.ts +21 -0
  60. package/lib/tui-actions.js +301 -0
  61. package/lib/tui-adapter.d.ts +25 -0
  62. package/lib/tui-adapter.js +422 -0
  63. package/lib/tui-types.d.ts +98 -0
  64. package/lib/tui-types.js +2 -0
  65. package/package.json +3 -1
@@ -0,0 +1,301 @@
1
+ import { createUserMessage } from "@deepseek-ai/dsh-llm";
2
+ import { createDsmmStatusSnapshot, formatDsmmStatus } from "./status.js";
3
+ import { handleDsmmStatusCommand, parseDeepworkCommandInput } from "./commands.js";
4
+ export const DSMM_TUI_COMPONENT_ID = "com.hugefiver.dsmm";
5
+ export const DSMM_TUI_CONTRIBUTIONS = Object.freeze({
6
+ manage: `${DSMM_TUI_COMPONENT_ID}.manage`
7
+ });
8
+ const DIALOG_TIMEOUT_MS = 30_000;
9
+ const INHERIT = "inherit";
10
+ const BOOLEAN_VALUES = Object.freeze([
11
+ { id: INHERIT, label: "Inherit" },
12
+ { id: "true", label: "Enabled", value: true },
13
+ { id: "false", label: "Disabled", value: false }
14
+ ]);
15
+ const GLOBAL_FIELDS = Object.freeze([
16
+ { id: "root-model-policy", label: "Root model policy", path: ["rootModelPolicy"], values: [
17
+ { id: INHERIT, label: "Inherit" }, { id: "native", label: "Native", value: "native" }, { id: "configured", label: "Configured", value: "configured" }
18
+ ] },
19
+ { id: "default-active", label: "Deepwork default", path: ["defaultActive"], values: BOOLEAN_VALUES },
20
+ { id: "locale", label: "Locale", path: ["locale"], values: [
21
+ { id: INHERIT, label: "Inherit" }, ...["en", "zh-Hans", "zh-Hant", "ja", "ko", "de", "fr", "es", "pt-BR", "ru"].map(value => ({ id: value, label: value, value }))
22
+ ] },
23
+ { id: "workflow-policy", label: "Workflow policy", path: ["workflow", "policy"], values: [
24
+ { id: INHERIT, label: "Inherit" }, { id: "risk-based", label: "Risk based", value: "risk-based" }, { id: "legacy", label: "Legacy", value: "legacy" }
25
+ ] },
26
+ { id: "tool-topology", label: "Subagent tool topology", path: ["subagents", "toolTopology"], values: [
27
+ { id: INHERIT, label: "Inherit" }, { id: "per-role", label: "Per role", value: "per-role" }, { id: "parameterized", label: "Parameterized", value: "parameterized" }
28
+ ] },
29
+ { id: "deepwork-module", label: "Deepwork module", path: ["modules", "deepwork", "enabled"], values: BOOLEAN_VALUES, restart: true }
30
+ ]);
31
+ async function handleManagedDeepwork(deps, invocation, authority) {
32
+ let committed = false;
33
+ try {
34
+ const parsed = parseDeepworkCommandInput(invocation.rawInput);
35
+ const settings = deps.getSettings(invocation.agent);
36
+ if (parsed.action === "on" && deps.getSettings.subagentRuntime !== undefined && !deps.getSettings.subagentRuntime().deliveryFenceReady) {
37
+ return error("Deepwork runtime is unavailable; check native runtime settings and restart status.");
38
+ }
39
+ if (parsed.action === "on" && !settings.modules.deepwork.enabled) {
40
+ return error("Deepwork module is not admitted in this session; mode cannot enable it.");
41
+ }
42
+ const expectedModeRevision = deps.controller.describe(invocation.agent, settings.defaultActive).revision;
43
+ const target = sessionIdentity(invocation);
44
+ const action = parsed.action === "on" ? "enable" : "disable";
45
+ const detail = parsed.message === "" ? "" : ` and steer one message (${bounded(parsed.message, 120)})`;
46
+ const confirmed = await authority.confirm("Confirm Deepwork action", `${action} Deepwork for session ${target}${detail}; mode revision ${expectedModeRevision}.`, action === "enable" ? "Enable" : "Disable");
47
+ if (confirmed !== true)
48
+ return error("Deepwork action cancelled; no change was started.");
49
+ authority.assertCurrent();
50
+ if (deps.controller.describe(invocation.agent, settings.defaultActive).revision !== expectedModeRevision) {
51
+ return error("Deepwork mode changed; run the command again to confirm the current revision.");
52
+ }
53
+ let committedRevision;
54
+ const outcome = await deps.controller.select(invocation.agent, parsed.action === "on", settings.defaultActive, () => authority.assertCurrent(), revision => { committed = true; committedRevision = revision; });
55
+ committed ||= outcome === "committed";
56
+ if (parsed.action === "on" && parsed.message !== "") {
57
+ try {
58
+ authority.assertCurrent();
59
+ const steerRevision = committed ? committedRevision : expectedModeRevision;
60
+ if (steerRevision === undefined || deps.controller.describe(invocation.agent, settings.defaultActive).revision !== steerRevision) {
61
+ return committed
62
+ ? success("Deepwork mode was committed, but the mode changed before the requested steer; no automatic retry was attempted.")
63
+ : error("Deepwork mode changed before the requested steer; run the command again.");
64
+ }
65
+ await invocation.agent.steer?.(createUserMessage({ content: [{ type: "text", text: parsed.message }], source: { kind: "user" } }));
66
+ }
67
+ catch {
68
+ return committed
69
+ ? success("Deepwork mode was committed, but the requested steer was not confirmed; no automatic retry was attempted.")
70
+ : error("The steer was refused before any confirmed mode change.");
71
+ }
72
+ }
73
+ return parsed.action === "on" ? success("Entering deepwork mode.") : success("Leaving deepwork mode.");
74
+ }
75
+ catch (cause) {
76
+ return committed
77
+ ? success("Deepwork mode was committed, but the remaining action did not complete; no automatic retry was attempted.")
78
+ : actionError(cause);
79
+ }
80
+ }
81
+ export function createDsmmManagementCommandDefinition(deps) {
82
+ return {
83
+ name: "dsmm",
84
+ description: "Manage DSMM status, Deepwork and simple configuration",
85
+ input: { hint: "[status [json]|deepwork [off|message]|config|profiles]" },
86
+ handler: invocation => handleManagement(deps, invocation)
87
+ };
88
+ }
89
+ async function handleManagement(deps, invocation) {
90
+ const input = invocation.rawInput.trim();
91
+ const match = /^(\S+)(?:\s+([\s\S]*))?$/u.exec(input);
92
+ const subcommand = match?.[1] ?? "";
93
+ const argument = match?.[2] ?? "";
94
+ if (!["", "status", "deepwork", "config", "profiles"].includes(subcommand)
95
+ || (subcommand === "status" && argument !== "" && argument !== "json")
96
+ || (["config", "profiles"].includes(subcommand) && argument !== "")) {
97
+ return error("Usage: /dsmm [status [json]|deepwork [off|message]|config|profiles]");
98
+ }
99
+ let authority;
100
+ try {
101
+ authority = deps.begin(invocation, DSMM_TUI_CONTRIBUTIONS.manage, subcommand !== "status");
102
+ let action = subcommand;
103
+ if (action === "") {
104
+ const selected = await authority.select("DSMM", [
105
+ { id: "status", label: "Status", description: "Show desired and admitted state" },
106
+ { id: "deepwork", label: "Deepwork", description: "Enable Deepwork for this session" },
107
+ { id: "config", label: "Global configuration", description: "Edit a limited shared scalar" },
108
+ { id: "profiles", label: "Named profiles", description: "Browse or select an existing profile" }
109
+ ]);
110
+ if (selected === undefined)
111
+ return error("DSMM menu cancelled.");
112
+ action = selected;
113
+ }
114
+ authority.assertCurrent();
115
+ if (action === "status") {
116
+ if (argument === "json")
117
+ return handleDsmmStatusCommand(deps.controller, deps.getSettings, { ...invocation, rawInput: "json" });
118
+ return await managementStatus(deps, invocation, authority);
119
+ }
120
+ if (action === "deepwork")
121
+ return await handleManagedDeepwork(deps, { ...invocation, rawInput: argument }, authority);
122
+ if (action === "config")
123
+ return await manageGlobal(deps, authority);
124
+ if (action === "profiles")
125
+ return await manageProfiles(deps, invocation, authority);
126
+ return error("The selected DSMM action is not available.");
127
+ }
128
+ catch (cause) {
129
+ return actionError(cause);
130
+ }
131
+ finally {
132
+ authority?.close();
133
+ }
134
+ }
135
+ async function managementStatus(deps, invocation, authority) {
136
+ const settings = deps.getSettings(invocation.agent);
137
+ const admission = deps.getSettings.admission?.(invocation.agent);
138
+ const snapshot = createDsmmStatusSnapshot({ agent: invocation.agent, settings, admission,
139
+ modules: deps.getSettings.moduleStates?.(invocation.agent), modeActive: deps.controller.active(invocation.agent, settings.defaultActive) });
140
+ const desired = await deps.deployment.readDesired();
141
+ authority.assertCurrent();
142
+ return success([
143
+ formatDsmmStatus(snapshot),
144
+ "",
145
+ "Desired deployment (future admission)",
146
+ `Root model policy: ${desired.settings.rootModelPolicy}`,
147
+ `Default active: ${desired.settings.defaultActive}`,
148
+ `Locale: ${desired.settings.locale ?? "inherit"}`,
149
+ `Workflow policy: ${desired.settings.workflow.policy}`,
150
+ `Tool topology: ${desired.settings.subagents.toolTopology}`,
151
+ `Deepwork module desired: ${desired.settings.modules.deepwork.enabled}`,
152
+ `Revisions: global=${desired.globalRevision}; native=${desired.nativeRevision}`
153
+ ].join("\n"));
154
+ }
155
+ async function manageGlobal(deps, authority) {
156
+ const snapshot = await deps.deployment.readGlobal();
157
+ authority.assertCurrent();
158
+ const fieldId = await authority.select("Global DSMM field", GLOBAL_FIELDS.map(field => ({ id: field.id, label: field.label,
159
+ description: `${displayValue(getPath(snapshot.config, field.path))}${field.restart ? "; restart may be required" : ""}` })));
160
+ if (fieldId === undefined)
161
+ return error("Global configuration action cancelled.");
162
+ const field = GLOBAL_FIELDS.find(candidate => candidate.id === fieldId);
163
+ if (field === undefined)
164
+ return error("The selected Global field is no longer available.");
165
+ authority.assertCurrent();
166
+ const valueId = await authority.select(`Set ${field.label}`, field.values.map(value => ({ id: value.id, label: value.label })));
167
+ if (valueId === undefined)
168
+ return error("Global configuration action cancelled.");
169
+ const selected = field.values.find(value => value.id === valueId);
170
+ if (selected === undefined)
171
+ return error("The selected Global value is no longer available.");
172
+ authority.assertCurrent();
173
+ const before = displayValue(getPath(snapshot.config, field.path));
174
+ const after = selected.id === INHERIT ? "inherit" : displayValue(selected.value);
175
+ const message = `Change shared Global ${field.path.join(".")} from ${before} to ${after}, requested by session ${authorityIdentity(authority)} at revision ${snapshot.revision}. Existing admissions are unchanged.${field.restart ? " A Host restart may be required." : ""}`;
176
+ if (await authority.confirm("Confirm Global DSMM change", message, "Save") !== true)
177
+ return error("Global configuration action cancelled; no write was started.");
178
+ authority.assertCurrent();
179
+ const edit = selected.id === INHERIT
180
+ ? { op: "unset", path: [...field.path] }
181
+ : { op: "set", path: [...field.path], value: selected.value };
182
+ const saved = await deps.deployment.saveGlobal({ expectedRevision: snapshot.revision, edits: [edit] }, () => authority.assertCurrent());
183
+ return success(`Saved Global ${field.path.join(".")}=${after}; desired revision is ${saved.revision}.${saved.refreshRequired ? " Refresh is required before another edit." : ""}`);
184
+ }
185
+ async function manageProfiles(deps, invocation, authority) {
186
+ const operation = await authority.select("Named profiles", [
187
+ { id: "browse", label: "Browse", description: "Show saved profile IDs, diagnostics and revisions" },
188
+ { id: "future", label: "Select future default", description: "Set or clear the default for new sessions" },
189
+ { id: "session", label: "Apply to current session", description: "Pin a profile or the deployment baseline" }
190
+ ]);
191
+ if (operation === undefined)
192
+ return error("Named profile action cancelled.");
193
+ authority.assertCurrent();
194
+ const inventory = await deps.profiles.describe();
195
+ authority.assertCurrent();
196
+ if (operation === "browse")
197
+ return success(formatProfileInventory(inventory));
198
+ const target = await chooseProfile(authority, inventory);
199
+ if (target === undefined)
200
+ return error("Named profile action cancelled.");
201
+ authority.assertCurrent();
202
+ const id = target === null ? null : target.id;
203
+ const revision = target === null ? undefined : target.revision ?? undefined;
204
+ if (target !== null && revision === undefined)
205
+ return error("The selected profile has no valid revision and cannot be applied.");
206
+ if (operation === "future") {
207
+ const message = `Change the future Global named-profile default to ${id ?? "deployment baseline"}, requested by session ${authorityIdentity(authority)}; selection revision ${inventory.selectionRevision}${revision === undefined ? "" : `; profile revision ${revision}`}. Current sessions are unchanged.`;
208
+ if (await authority.confirm("Confirm future profile default", message, "Select") !== true)
209
+ return error("Named profile action cancelled; no selection was started.");
210
+ authority.assertCurrent();
211
+ const selected = await deps.profiles.select({ id, expectedSelectionRevision: inventory.selectionRevision,
212
+ ...(revision === undefined ? {} : { expectedRevision: revision }) }, () => authority.assertCurrent());
213
+ return success(`Future named-profile default is ${selected.selectedId ?? "deployment baseline"}; current sessions were not changed.${selected.refreshRequired ? " The commit succeeded, but refresh is required before another profile action." : ""}`);
214
+ }
215
+ const session = await deps.profiles.getSession(invocation.agent);
216
+ authority.assertCurrent();
217
+ const message = `Apply ${id ?? "deployment baseline"} to live root session ${session.sessionId}; admission ${session.admissionEpoch}; selection revision ${session.selection.selectionRevision}${revision === undefined ? "" : `; profile revision ${revision}`}.`;
218
+ if (await authority.confirm("Confirm session profile", message, "Apply") !== true)
219
+ return error("Session profile action cancelled; no maintenance was started.");
220
+ authority.assertCurrent();
221
+ const selected = await deps.profiles.selectSession({ sessionId: session.sessionId, id,
222
+ expectedSelectionRevision: session.selection.selectionRevision, expectedAdmissionEpoch: session.admissionEpoch,
223
+ ...(revision === undefined ? {} : { expectedRevision: revision }) }, invocation.agent, authority.signal, () => authority.assertCurrent());
224
+ const refreshRequired = selected.refreshRequired === true || selected.selection.refreshRequired === true;
225
+ return success(`Session ${selected.sessionId} now admits ${selected.admittedSelection?.selectedId ?? "deployment baseline"}; admission epoch ${selected.admissionEpoch}.${refreshRequired ? " The commit succeeded, but refresh is required before another profile action." : ""}`);
226
+ }
227
+ async function chooseProfile(authority, inventory) {
228
+ const available = inventory.profiles.filter(profile => profile.error === undefined && typeof profile.revision === "string");
229
+ const pageSize = 96;
230
+ let page = 0;
231
+ while (true) {
232
+ const start = page * pageSize;
233
+ const rows = available.slice(start, start + pageSize);
234
+ const options = [
235
+ { id: "baseline", label: "Deployment baseline", description: "Clear the named-profile selection" },
236
+ ...rows.map((profile, index) => ({ id: `profile:${start + index}`, label: bounded(profile.label?.trim() || profile.id, 120), description: `${profile.id}; revision ${profile.revision}` })),
237
+ ...(page > 0 ? [{ id: "previous", label: "Previous page" }] : []),
238
+ ...(start + pageSize < available.length ? [{ id: "next", label: "Next page" }] : [])
239
+ ];
240
+ const answer = await authority.select("Choose a saved profile", options);
241
+ if (answer === undefined)
242
+ return undefined;
243
+ authority.assertCurrent();
244
+ if (answer === "baseline")
245
+ return null;
246
+ if (answer === "previous") {
247
+ page--;
248
+ continue;
249
+ }
250
+ if (answer === "next") {
251
+ page++;
252
+ continue;
253
+ }
254
+ const match = /^profile:(\d+)$/u.exec(answer);
255
+ if (match === null)
256
+ return undefined;
257
+ const selected = available[Number(match[1])];
258
+ if (selected !== undefined)
259
+ return selected;
260
+ }
261
+ }
262
+ function formatProfileInventory(snapshot) {
263
+ const rows = snapshot.profiles.map(profile => `${profile.id} | ${bounded(profile.label?.trim() || "unlabelled", 80)} | ${profile.error?.code ?? profile.revision ?? "unavailable"}`);
264
+ return [
265
+ `Future default: ${snapshot.selectedId ?? "deployment baseline"}`,
266
+ `Selection revision: ${snapshot.selectionRevision}`,
267
+ `Store: ${snapshot.origin ?? "unknown"}; ${snapshot.readOnly ? "read-only" : "writable"}`,
268
+ ...(rows.length === 0 ? ["No saved named profiles."] : rows)
269
+ ].join("\n");
270
+ }
271
+ function getPath(value, path) {
272
+ let current = value;
273
+ for (const key of path) {
274
+ if (current === null || typeof current !== "object" || Array.isArray(current))
275
+ return undefined;
276
+ current = Reflect.get(current, key);
277
+ }
278
+ return current;
279
+ }
280
+ function displayValue(value) {
281
+ return value === undefined ? "inherit" : typeof value === "string" || typeof value === "boolean" ? String(value) : "configured";
282
+ }
283
+ function sessionIdentity(invocation) {
284
+ return bounded(invocation.agent.id ?? invocation.agent.session.id ?? "unknown", 80);
285
+ }
286
+ function authorityIdentity(authority) {
287
+ return bounded(authority.agent.id ?? authority.agent.session.id ?? "unknown", 80);
288
+ }
289
+ function bounded(value, limit) {
290
+ const clean = value.replace(/[\u0000-\u001F\u007F]/gu, " ").replace(/\s+/gu, " ").trim();
291
+ return clean.length <= limit ? clean : `${clean.slice(0, Math.max(0, limit - 1))}…`;
292
+ }
293
+ function success(text) { return { kind: "success", text }; }
294
+ function error(text) { return { kind: "error", text }; }
295
+ function actionError(cause) {
296
+ if (cause instanceof Error && cause.name === "AbortError")
297
+ return error("DSMM action cancelled; no new write was started.");
298
+ return error(cause instanceof Error ? bounded(cause.message, 400) : "The Host refused the DSMM action.");
299
+ }
300
+ export { DIALOG_TIMEOUT_MS };
301
+ //# sourceMappingURL=tui-actions.js.map
@@ -0,0 +1,25 @@
1
+ import type { DshContext } from "./dsh-types.js";
2
+ import type { DsmmSettingsGetter } from "./settings.js";
3
+ import type { DeepworkModeController } from "./state.js";
4
+ import type { DsmmProfileRuntime } from "./profile-runtime.js";
5
+ import type { DsmmDeploymentConfig } from "./deployment-config.js";
6
+ import type { TuiSettingsSection } from "./tui-types.js";
7
+ export interface DsmmTuiAdapterOptions {
8
+ controller: DeepworkModeController;
9
+ getSettings: DsmmSettingsGetter;
10
+ profiles: DsmmProfileRuntime;
11
+ deployment: DsmmDeploymentConfig;
12
+ clock?: DsmmTuiClock;
13
+ }
14
+ export interface DsmmTuiClock {
15
+ setTimeout(callback: () => void, delayMs: number): unknown;
16
+ clearTimeout(handle: unknown): void;
17
+ }
18
+ export interface DsmmTuiAdapterHandle {
19
+ readonly managed: boolean;
20
+ settled(): Promise<void>;
21
+ dispose(): void;
22
+ }
23
+ export declare function createDsmmTuiSettingsSection(namespace: string): TuiSettingsSection;
24
+ export declare function registerDsmmTuiAdapter(ctx: DshContext, options: DsmmTuiAdapterOptions): DsmmTuiAdapterHandle;
25
+ //# sourceMappingURL=tui-adapter.d.ts.map