@dsmm/dsmm 0.0.0-stage → 0.1.0

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 (125) hide show
  1. package/LICENSE +103 -0
  2. package/README.md +67 -2
  3. package/agent-presets/dsmm-builder/agent.cordis.yml +210 -0
  4. package/agent-presets/dsmm-builder/preset.yml +3 -0
  5. package/agent-presets/dsmm-clarifier/agent.cordis.yml +34 -0
  6. package/agent-presets/dsmm-clarifier/preset.yml +3 -0
  7. package/agent-presets/dsmm-code-search/agent.cordis.yml +34 -0
  8. package/agent-presets/dsmm-code-search/preset.yml +3 -0
  9. package/agent-presets/dsmm-creative/agent.cordis.yml +31 -0
  10. package/agent-presets/dsmm-creative/preset.yml +3 -0
  11. package/agent-presets/dsmm-doc-search/agent.cordis.yml +34 -0
  12. package/agent-presets/dsmm-doc-search/preset.yml +3 -0
  13. package/agent-presets/dsmm-media-reader/agent.cordis.yml +34 -0
  14. package/agent-presets/dsmm-media-reader/preset.yml +3 -0
  15. package/agent-presets/dsmm-oracle/agent.cordis.yml +31 -0
  16. package/agent-presets/dsmm-oracle/preset.yml +3 -0
  17. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +31 -0
  18. package/agent-presets/dsmm-oracle-2nd/preset.yml +3 -0
  19. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +215 -0
  20. package/agent-presets/dsmm-orchestrator/preset.yml +3 -0
  21. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +33 -0
  22. package/agent-presets/dsmm-plan-critic/preset.yml +3 -0
  23. package/agent-presets/dsmm-planner/agent.cordis.yml +33 -0
  24. package/agent-presets/dsmm-planner/preset.yml +3 -0
  25. package/agent-presets/dsmm-reviewer/agent.cordis.yml +33 -0
  26. package/agent-presets/dsmm-reviewer/preset.yml +3 -0
  27. package/cordis.patch.yml +8 -0
  28. package/docs/agent-presets.md +17 -0
  29. package/docs/compatibility.md +46 -0
  30. package/docs/design.md +237 -0
  31. package/docs/lsp.md +40 -0
  32. package/docs/migration-from-ocmm.md +48 -0
  33. package/docs/model-routing.md +16 -0
  34. package/docs/releasing.md +50 -0
  35. package/docs/research/deepseek-v4-pro.md +74 -0
  36. package/docs/research/oh-dsh.md +96 -0
  37. package/docs/roadmap.md +207 -0
  38. package/docs/runtime-recovery.md +67 -0
  39. package/docs/safety-guards.md +55 -0
  40. package/docs/settings-status.md +51 -0
  41. package/docs/skill-sync.md +20 -0
  42. package/lib/commands.d.ts +13 -0
  43. package/lib/commands.js +55 -0
  44. package/lib/dsh-events.d.ts +13 -0
  45. package/lib/dsh-events.js +2 -0
  46. package/lib/dsh-types.d.ts +308 -0
  47. package/lib/dsh-types.js +2 -0
  48. package/lib/guards.d.ts +10 -0
  49. package/lib/guards.js +252 -0
  50. package/lib/index.d.ts +31 -0
  51. package/lib/index.js +54 -0
  52. package/lib/lsp.d.ts +30 -0
  53. package/lib/lsp.js +154 -0
  54. package/lib/mode.d.ts +6 -0
  55. package/lib/mode.js +62 -0
  56. package/lib/model-family.d.ts +6 -0
  57. package/lib/model-family.js +49 -0
  58. package/lib/model-routing.d.ts +11 -0
  59. package/lib/model-routing.js +103 -0
  60. package/lib/plan-validation.d.ts +3 -0
  61. package/lib/plan-validation.js +119 -0
  62. package/lib/preset-materializer.d.ts +36 -0
  63. package/lib/preset-materializer.js +258 -0
  64. package/lib/preset-registry.d.ts +5 -0
  65. package/lib/preset-registry.js +126 -0
  66. package/lib/preset-skills.d.ts +12 -0
  67. package/lib/preset-skills.js +28 -0
  68. package/lib/prompts.d.ts +13 -0
  69. package/lib/prompts.js +82 -0
  70. package/lib/recovery-policy.d.ts +25 -0
  71. package/lib/recovery-policy.js +252 -0
  72. package/lib/role-subagents.d.ts +6 -0
  73. package/lib/role-subagents.js +54 -0
  74. package/lib/roles.d.ts +28 -0
  75. package/lib/roles.js +239 -0
  76. package/lib/runtime-recovery.d.ts +5 -0
  77. package/lib/runtime-recovery.js +149 -0
  78. package/lib/session-scope.d.ts +4 -0
  79. package/lib/session-scope.js +17 -0
  80. package/lib/settings.d.ts +112 -0
  81. package/lib/settings.js +363 -0
  82. package/lib/shell-command.d.ts +18 -0
  83. package/lib/shell-command.js +492 -0
  84. package/lib/skills.d.ts +18 -0
  85. package/lib/skills.js +64 -0
  86. package/lib/state.d.ts +13 -0
  87. package/lib/state.js +64 -0
  88. package/lib/status.d.ts +46 -0
  89. package/lib/status.js +155 -0
  90. package/package.json +124 -4
  91. package/patches/agent-presets-root.example.cordis.patch.yml +14 -0
  92. package/patches/ocmm-lsp-mcp.example.cordis.patch.yml +15 -0
  93. package/prompts/deepseek-flash.md +11 -0
  94. package/prompts/deepseek-v4-pro.md +14 -0
  95. package/prompts/deepwork.md +32 -0
  96. package/skills/brainstorming/SKILL.md +15 -0
  97. package/skills/debugging/SKILL.md +12 -0
  98. package/skills/debugging/references/logging.md +91 -0
  99. package/skills/debugging/references/methodology/00-setup.md +108 -0
  100. package/skills/debugging/references/methodology/02-investigate.md +67 -0
  101. package/skills/debugging/references/methodology/03-flaky-triage.md +69 -0
  102. package/skills/debugging/references/methodology/04-hard-reasoning-escalation.md +83 -0
  103. package/skills/debugging/references/methodology/05-escalate.md +69 -0
  104. package/skills/debugging/references/methodology/06-fix.md +123 -0
  105. package/skills/debugging/references/methodology/08-qa.md +94 -0
  106. package/skills/debugging/references/methodology/09-cleanup.md +164 -0
  107. package/skills/debugging/references/methodology/partial-runtime-evidence.md +217 -0
  108. package/skills/debugging/references/runtimes/bundled-js-binary.md +415 -0
  109. package/skills/debugging/references/runtimes/go.md +252 -0
  110. package/skills/debugging/references/runtimes/native-binary.md +484 -0
  111. package/skills/debugging/references/runtimes/node.md +260 -0
  112. package/skills/debugging/references/runtimes/python.md +248 -0
  113. package/skills/debugging/references/runtimes/rust.md +234 -0
  114. package/skills/debugging/references/scripts/dap.mjs +533 -0
  115. package/skills/debugging/references/tools/dap.md +89 -0
  116. package/skills/debugging/references/tools/ghidra.md +212 -0
  117. package/skills/debugging/references/tools/playwright-cli.md +316 -0
  118. package/skills/debugging/references/tools/pwndbg.md +263 -0
  119. package/skills/debugging/references/tools/pwntools.md +265 -0
  120. package/skills/dispatching-parallel-agents/SKILL.md +14 -0
  121. package/skills/receiving-code-review/SKILL.md +13 -0
  122. package/skills/remove-ai-slops/SKILL.md +14 -0
  123. package/skills/requesting-code-review/SKILL.md +10 -0
  124. package/skills/subagent-driven-development/SKILL.md +13 -0
  125. package/skills/writing-plans/SKILL.md +14 -0
@@ -0,0 +1,308 @@
1
+ export interface SettingsScope<T> {
2
+ get(): T;
3
+ watch?(callback: (next: T, prev: T) => void | Promise<void>): () => void;
4
+ }
5
+ export interface DshSettingsRegistry {
6
+ register<T>(namespace: string, schema: unknown, options: {
7
+ base: Partial<T>;
8
+ applies?: "live" | "restart";
9
+ }): SettingsScope<T>;
10
+ }
11
+ export interface DshSessionEvent {
12
+ type: string;
13
+ data?: unknown;
14
+ }
15
+ export interface DshSessionHeader {
16
+ cwd?: string;
17
+ agentPreset?: string;
18
+ origin?: string;
19
+ }
20
+ export interface DshSession {
21
+ events?: readonly DshSessionEvent[];
22
+ snapshotEvents?(): readonly DshSessionEvent[];
23
+ header?: DshSessionHeader;
24
+ requestHeader?(): DshEpochHeader | undefined;
25
+ append(type: "deepwork/mode", payload: {
26
+ active: boolean;
27
+ }): unknown | Promise<unknown>;
28
+ }
29
+ export interface DshAgent {
30
+ session: DshSession;
31
+ options?: {
32
+ provider?: string;
33
+ model?: string;
34
+ };
35
+ steer?(message: unknown): unknown | Promise<unknown>;
36
+ inject?(message: unknown): unknown | Promise<unknown>;
37
+ }
38
+ export interface DshLlmCallConfig {
39
+ provider: string;
40
+ model: string;
41
+ reasoningEffort?: string;
42
+ temperature?: number;
43
+ maxTokens?: number;
44
+ stop?: unknown;
45
+ [key: string]: unknown;
46
+ }
47
+ export interface DshLlmFailure {
48
+ readonly message: string;
49
+ readonly code: string;
50
+ readonly status?: number;
51
+ readonly providerRetryAfterMs?: number;
52
+ readonly requestId?: unknown;
53
+ }
54
+ export interface DshEpochHeader {
55
+ config: DshLlmCallConfig;
56
+ [key: string]: unknown;
57
+ }
58
+ export interface DshReasoningEffortInfo {
59
+ id: string;
60
+ name: string;
61
+ [key: string]: unknown;
62
+ }
63
+ export interface DshModelReasoningInfo {
64
+ efforts: readonly DshReasoningEffortInfo[];
65
+ defaultEffort?: string;
66
+ [key: string]: unknown;
67
+ }
68
+ export interface DshResolvedModelInfo {
69
+ provider: string;
70
+ id: string;
71
+ name: string;
72
+ reasoning?: DshModelReasoningInfo;
73
+ [key: string]: unknown;
74
+ }
75
+ export interface DshLlmRuntime {
76
+ resolveModelInfo(provider: string, model: string, signal?: AbortSignal): Promise<DshResolvedModelInfo>;
77
+ }
78
+ export interface AgentRequestFrame {
79
+ agent: DshAgent;
80
+ turn: number;
81
+ step: number;
82
+ signal: AbortSignal;
83
+ }
84
+ export interface AgentRequestErrorFrame {
85
+ agent: DshAgent;
86
+ turn: number;
87
+ step: number;
88
+ provider: string;
89
+ failure: DshLlmFailure;
90
+ retryPolicy: unknown;
91
+ signal: AbortSignal;
92
+ }
93
+ export type DshRequestErrorAction = {
94
+ kind: "retry";
95
+ } | undefined;
96
+ export interface AgentTurnStoppingFrame {
97
+ agent: DshAgent;
98
+ turn: number;
99
+ signal: AbortSignal;
100
+ }
101
+ export interface DshStepBoundaryEventData {
102
+ turn: number;
103
+ step: number;
104
+ }
105
+ export interface DshRequestHeaderEventData {
106
+ header: DshEpochHeader;
107
+ reason: "initial" | "resume" | "change" | "series";
108
+ }
109
+ export interface DshTodoItem {
110
+ content: string;
111
+ status: "pending" | "in_progress" | "completed";
112
+ }
113
+ export interface DshTodoWriteEventData {
114
+ todos: DshTodoItem[];
115
+ }
116
+ export interface DshGoalSnapshot {
117
+ id: string;
118
+ revision: number;
119
+ objective: string;
120
+ phase: "active" | "paused" | "blocked" | "complete";
121
+ blockedReason?: {
122
+ code: string;
123
+ message: string;
124
+ };
125
+ maxGoalRounds: number;
126
+ }
127
+ export type DshGoalChangeEventData = {
128
+ kind: "goal/change";
129
+ version: 1;
130
+ operation: "create" | "edit" | "pause" | "resume" | "complete" | "block";
131
+ goal: DshGoalSnapshot;
132
+ roundsStarted: number;
133
+ createdAt: number;
134
+ updatedAt: number;
135
+ } | {
136
+ kind: "goal/change";
137
+ version: 1;
138
+ operation: "clear";
139
+ cleared: {
140
+ id: string;
141
+ revision: number;
142
+ };
143
+ clearedAt: number;
144
+ };
145
+ export interface DshSystemPromptContext {
146
+ agent?: DshAgent;
147
+ [key: string]: unknown;
148
+ }
149
+ export interface DshSystemPromptSection {
150
+ name: string;
151
+ order: number;
152
+ interpolate?: boolean;
153
+ text(context: DshSystemPromptContext): string;
154
+ }
155
+ export interface DshSystemPromptRegistry {
156
+ section(section: DshSystemPromptSection): unknown;
157
+ }
158
+ export interface DshPromptAssembly {
159
+ sections: Array<{
160
+ name: string;
161
+ text: string;
162
+ interpolate?: boolean;
163
+ }>;
164
+ contexts: unknown[];
165
+ tools: unknown[];
166
+ variables: Record<string, string | undefined>;
167
+ }
168
+ export interface DshCommandInvocation {
169
+ agent: DshAgent;
170
+ rawInput: string;
171
+ attachments?: readonly unknown[];
172
+ signal?: AbortSignal;
173
+ }
174
+ export interface DshCommandResult {
175
+ kind: "success" | "error";
176
+ text?: string;
177
+ }
178
+ export interface DshCommandsRegistry {
179
+ register(command: {
180
+ name: string;
181
+ description: string;
182
+ input?: {
183
+ hint: string;
184
+ images?: boolean;
185
+ };
186
+ handler(invocation: DshCommandInvocation): DshCommandResult | Promise<DshCommandResult>;
187
+ }): unknown;
188
+ }
189
+ export interface DshSkillRegistration {
190
+ name: string;
191
+ description: string;
192
+ content: string;
193
+ source?: "bundled" | "runtime" | string;
194
+ provider?: string;
195
+ resourceBase?: {
196
+ kind: "directory";
197
+ path: string;
198
+ } | {
199
+ kind: "opaque";
200
+ description: string;
201
+ };
202
+ invocation?: {
203
+ modelInvocable: boolean;
204
+ userInvocable: boolean;
205
+ };
206
+ }
207
+ export interface DshSkillRegistry {
208
+ register(skill: DshSkillRegistration): unknown;
209
+ }
210
+ export interface DshContentBlock {
211
+ type: string;
212
+ text?: string;
213
+ [key: string]: unknown;
214
+ }
215
+ export interface DshToolExecution {
216
+ callId?: unknown;
217
+ rootCallId?: unknown;
218
+ name: string;
219
+ arguments: unknown;
220
+ agent?: DshAgent;
221
+ parent?: unknown;
222
+ signal?: AbortSignal;
223
+ }
224
+ export type DshPreToolDecision = {
225
+ kind: "allow";
226
+ } | {
227
+ kind: "deny";
228
+ reason: string;
229
+ } | {
230
+ kind: "ask";
231
+ reason?: string;
232
+ } | {
233
+ kind: "cancel";
234
+ };
235
+ export type DshPostToolDecision = {
236
+ kind: "accept";
237
+ content?: DshContentBlock[];
238
+ value?: never;
239
+ additionalContexts?: unknown[];
240
+ } | {
241
+ kind: "accept";
242
+ value: unknown;
243
+ content?: never;
244
+ additionalContexts?: unknown[];
245
+ } | {
246
+ kind: "block";
247
+ feedback: DshContentBlock[];
248
+ additionalContexts?: unknown[];
249
+ };
250
+ export interface DshToolExecutionResult {
251
+ isError: boolean;
252
+ content: DshContentBlock[];
253
+ value?: unknown;
254
+ error?: unknown;
255
+ additionalContexts?: unknown[];
256
+ }
257
+ export interface DshToolRuntime {
258
+ guard?(guard: (execution: Readonly<DshToolExecution>) => string | undefined): () => void;
259
+ get?(name: string): unknown;
260
+ }
261
+ export type DshEventListener = (...args: any[]) => any;
262
+ export interface DshInjectedServices {
263
+ settings?: DshSettingsRegistry;
264
+ skills?: DshSkillRegistry;
265
+ commands?: DshCommandsRegistry;
266
+ tools?: DshToolRuntime;
267
+ llm?: DshLlmRuntime;
268
+ [key: string]: unknown;
269
+ }
270
+ export interface PreStepFrame {
271
+ agent: DshAgent;
272
+ signal: AbortSignal;
273
+ }
274
+ export interface PreStepDecision {
275
+ kind: string;
276
+ messages?: readonly unknown[];
277
+ [key: string]: unknown;
278
+ }
279
+ export interface DshContext {
280
+ settings?: DshSettingsRegistry;
281
+ systemPrompt?: DshSystemPromptRegistry;
282
+ skills?: DshSkillRegistry;
283
+ commands?: DshCommandsRegistry;
284
+ tools?: DshToolRuntime;
285
+ llm?: DshLlmRuntime;
286
+ get?<T = unknown>(name: string): T | undefined;
287
+ plugin?(plugin: unknown, config?: unknown): PromiseLike<unknown>;
288
+ inject?(dependencies: string[], installer: (readyCtx: DshContext) => unknown): unknown;
289
+ effect?(callback: () => void | (() => void)): unknown;
290
+ on?(event: "agent/request", listener: (frame: AgentRequestFrame, next: () => Promise<DshLlmCallConfig>) => Promise<DshLlmCallConfig>, options?: boolean | {
291
+ prepend?: boolean;
292
+ global?: boolean;
293
+ }): unknown;
294
+ on?(event: "agent/request-error", listener: (frame: AgentRequestErrorFrame, next: () => Promise<DshRequestErrorAction>) => Promise<DshRequestErrorAction>, options?: boolean | {
295
+ prepend?: boolean;
296
+ global?: boolean;
297
+ }): unknown;
298
+ on?(event: "agent/turn-stopping", listener: (frame: AgentTurnStoppingFrame) => void | Promise<void>, options?: boolean | {
299
+ prepend?: boolean;
300
+ global?: boolean;
301
+ }): unknown;
302
+ on?(event: "agent/pre-step", listener: (frame: PreStepFrame, next: () => Promise<PreStepDecision>) => Promise<PreStepDecision>, options?: unknown): unknown;
303
+ on?(event: string, listener: DshEventListener, options?: unknown): unknown;
304
+ logger?: {
305
+ warn(message: string, ...args: unknown[]): void;
306
+ };
307
+ }
308
+ //# sourceMappingURL=dsh-types.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=dsh-types.js.map
@@ -0,0 +1,10 @@
1
+ import type { DshContext, DshPostToolDecision, DshPreToolDecision, DshToolExecution, DshToolExecutionResult } from "./dsh-types.js";
2
+ import type { DsmmSettings } from "./settings.js";
3
+ import type { DeepworkModeController } from "./state.js";
4
+ export declare const DSMM_GUARD_PREFIX = "[dsmm safety]";
5
+ export declare function truncateTextMiddle(text: string, maxBytes: number, toolName: string): string;
6
+ export declare function isSafetyScopeActive(exec: DshToolExecution, settings: DsmmSettings, controller: DeepworkModeController): boolean;
7
+ export declare function decidePreToolExecution(exec: DshToolExecution, settings: DsmmSettings, controller: DeepworkModeController): DshPreToolDecision | undefined;
8
+ export declare function decidePostToolExecution(exec: DshToolExecution, result: Readonly<DshToolExecutionResult>, decision: DshPostToolDecision, settings: DsmmSettings, controller: DeepworkModeController): DshPostToolDecision;
9
+ export declare function registerSafetyGuards(ctx: DshContext, controller: DeepworkModeController, getSettings: () => DsmmSettings): void;
10
+ //# sourceMappingURL=guards.d.ts.map
package/lib/guards.js ADDED
@@ -0,0 +1,252 @@
1
+ import { isDsmmRoleId } from "./roles.js";
2
+ import { resolveSelectedAgentPreset } from "./session-scope.js";
3
+ import { validatePlanMutation } from "./plan-validation.js";
4
+ import { classifyKnownGitWrite, classifyShellDialectViolation } from "./shell-command.js";
5
+ export const DSMM_GUARD_PREFIX = "[dsmm safety]";
6
+ const STRUCTURED_TODO_PATTERN = /^\[[^\]]+\]\s+\[[^\]]+\]\s+to\s+.+\s+-\s+expect\s+.+/u;
7
+ function asRecord(value) {
8
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
9
+ }
10
+ function stringField(value, keys) {
11
+ const record = asRecord(value);
12
+ if (record === undefined)
13
+ return undefined;
14
+ for (const key of keys) {
15
+ if (typeof record[key] === "string")
16
+ return record[key];
17
+ }
18
+ return undefined;
19
+ }
20
+ function toolName(exec) {
21
+ return exec.name.toLowerCase();
22
+ }
23
+ function commandText(exec) {
24
+ return stringField(exec.arguments, ["command", "cmd", "script"]);
25
+ }
26
+ function allText(content) {
27
+ let text = "";
28
+ for (const block of content) {
29
+ if (block.type !== "text" || typeof block.text !== "string")
30
+ return undefined;
31
+ text += block.text;
32
+ }
33
+ return text;
34
+ }
35
+ function utf8Bytes(text) {
36
+ return Buffer.byteLength(text, "utf8");
37
+ }
38
+ function takeUtf8Start(text, maxBytes) {
39
+ let used = 0;
40
+ let output = "";
41
+ for (const char of text) {
42
+ const size = utf8Bytes(char);
43
+ if (used + size > maxBytes)
44
+ break;
45
+ used += size;
46
+ output += char;
47
+ }
48
+ return output;
49
+ }
50
+ function takeUtf8End(text, maxBytes) {
51
+ let used = 0;
52
+ const output = [];
53
+ const chars = Array.from(text);
54
+ for (let index = chars.length - 1; index >= 0; index -= 1) {
55
+ const char = chars[index];
56
+ const size = utf8Bytes(char);
57
+ if (used + size > maxBytes)
58
+ break;
59
+ used += size;
60
+ output.push(char);
61
+ }
62
+ return output.reverse().join("");
63
+ }
64
+ export function truncateTextMiddle(text, maxBytes, toolName) {
65
+ if (utf8Bytes(text) <= maxBytes)
66
+ return text;
67
+ const shortNotice = `${DSMM_GUARD_PREFIX} truncated ${toolName} output.`;
68
+ const notice = `\n\n${DSMM_GUARD_PREFIX} truncated ${toolName} output...\n\n`;
69
+ if (maxBytes <= utf8Bytes(notice) + 10)
70
+ return takeUtf8Start(shortNotice, maxBytes);
71
+ const budget = maxBytes - utf8Bytes(notice);
72
+ const head = Math.ceil(budget / 2);
73
+ const tail = Math.floor(budget / 2);
74
+ return `${takeUtf8Start(text, head)}${notice}${takeUtf8End(text, tail)}`;
75
+ }
76
+ export function isSafetyScopeActive(exec, settings, controller) {
77
+ if (settings.guards.scope === "off")
78
+ return false;
79
+ if (settings.guards.scope === "always")
80
+ return true;
81
+ if (controller.active(exec.agent, settings.defaultActive))
82
+ return true;
83
+ return isDsmmRoleId(resolveSelectedAgentPreset(exec.agent?.session));
84
+ }
85
+ function shellDialect(exec) {
86
+ const name = toolName(exec);
87
+ if (name === "bash" || name === "sh" || name === "zsh")
88
+ return "posix";
89
+ if (name === "pwsh" || name === "powershell")
90
+ return "powershell";
91
+ return undefined;
92
+ }
93
+ function shellSafetyDecision(exec) {
94
+ const dialect = shellDialect(exec);
95
+ const command = commandText(exec);
96
+ if (dialect === undefined || command === undefined)
97
+ return undefined;
98
+ const violation = classifyShellDialectViolation(command, dialect);
99
+ if (violation === undefined)
100
+ return undefined;
101
+ return shellDialectViolationDecision(violation);
102
+ }
103
+ function shellDialectViolationDecision(violation) {
104
+ if (violation === "powershell-export") {
105
+ return {
106
+ kind: "deny",
107
+ reason: `${DSMM_GUARD_PREFIX} PowerShell command appears to use POSIX shell syntax (\`export\`). Use \`$env:NAME = "value"; command\` instead.`
108
+ };
109
+ }
110
+ if (violation === "powershell-source") {
111
+ return {
112
+ kind: "deny",
113
+ reason: `${DSMM_GUARD_PREFIX} PowerShell command uses POSIX \`source\`. Use dot-sourcing with a .ps1 file instead.`
114
+ };
115
+ }
116
+ if (violation === "powershell-dev-null") {
117
+ return {
118
+ kind: "deny",
119
+ reason: `${DSMM_GUARD_PREFIX} PowerShell command uses POSIX null redirection (/dev/null). Use \`*> $null\` or omit redirection.`
120
+ };
121
+ }
122
+ return {
123
+ kind: "deny",
124
+ reason: `${DSMM_GUARD_PREFIX} bash command appears to use PowerShell syntax (\`$env:\`). Use POSIX environment syntax for bash.`
125
+ };
126
+ }
127
+ function gitWriteDecision(exec, settings) {
128
+ if (settings.guards.gitWriteGuard === "off")
129
+ return undefined;
130
+ const command = commandText(exec);
131
+ const dialect = shellDialect(exec);
132
+ const operation = command === undefined || dialect === undefined ? undefined : classifyKnownGitWrite(command, dialect);
133
+ if (operation === undefined)
134
+ return undefined;
135
+ if (settings.guards.gitWriteGuard === "deny") {
136
+ return {
137
+ kind: "deny",
138
+ reason: `${DSMM_GUARD_PREFIX} git write command is disabled by dsmm settings: git ${operation}`
139
+ };
140
+ }
141
+ return {
142
+ kind: "ask",
143
+ reason: `${DSMM_GUARD_PREFIX} git write command requires explicit user approval before running: git ${operation}`
144
+ };
145
+ }
146
+ function questionLabelDecision(exec, settings) {
147
+ if (!settings.guards.questionLabelHelper.enabled || toolName(exec) !== "ask_user_question")
148
+ return undefined;
149
+ const questions = asRecord(exec.arguments)?.questions;
150
+ if (!Array.isArray(questions))
151
+ return undefined;
152
+ const limit = settings.guards.questionLabelHelper.maxLabelChars;
153
+ for (const question of questions) {
154
+ const options = asRecord(question)?.options;
155
+ if (!Array.isArray(options))
156
+ continue;
157
+ for (const option of options) {
158
+ const label = asRecord(option)?.label;
159
+ if (typeof label !== "string" || label.length <= limit)
160
+ continue;
161
+ return {
162
+ kind: "deny",
163
+ reason: `${DSMM_GUARD_PREFIX} question option label exceeds ${String(limit)} characters: ${label}`
164
+ };
165
+ }
166
+ }
167
+ return undefined;
168
+ }
169
+ function todoDisciplineDecision(exec, settings) {
170
+ if (toolName(exec) !== "todo_write")
171
+ return undefined;
172
+ const todos = asRecord(exec.arguments)?.todos;
173
+ if (!Array.isArray(todos))
174
+ return undefined;
175
+ const todoRecords = todos.map(asRecord);
176
+ const unfinished = todoRecords.some((todo) => todo?.status !== "completed");
177
+ if (unfinished) {
178
+ const active = todoRecords.filter((todo) => todo?.status === "in_progress").length;
179
+ if (active === 0) {
180
+ return {
181
+ kind: "deny",
182
+ reason: `${DSMM_GUARD_PREFIX} todo list must keep at least one in_progress item while unfinished work remains; parallel work follows the host todo policy.`
183
+ };
184
+ }
185
+ }
186
+ if (settings.workflow.policy !== "legacy")
187
+ return undefined;
188
+ const malformed = todoRecords.find((todo) => typeof todo?.content === "string" && !STRUCTURED_TODO_PATTERN.test(todo.content));
189
+ if (typeof malformed?.content !== "string")
190
+ return undefined;
191
+ return {
192
+ kind: "deny",
193
+ reason: `${DSMM_GUARD_PREFIX} todo content must use "[WHERE] [HOW] to [WHY] - expect [RESULT]": ${malformed.content}`
194
+ };
195
+ }
196
+ export function decidePreToolExecution(exec, settings, controller) {
197
+ if (!isSafetyScopeActive(exec, settings, controller))
198
+ return undefined;
199
+ if (settings.guards.shellCommandSafety) {
200
+ const shell = shellSafetyDecision(exec);
201
+ if (shell !== undefined)
202
+ return shell;
203
+ }
204
+ const git = gitWriteDecision(exec, settings);
205
+ if (git !== undefined)
206
+ return git;
207
+ if (settings.guards.planFormatValidation) {
208
+ const plan = validatePlanMutation(exec);
209
+ if (plan !== undefined)
210
+ return plan;
211
+ }
212
+ const question = questionLabelDecision(exec, settings);
213
+ if (question !== undefined)
214
+ return question;
215
+ if (settings.guards.todoDisciplineHelper) {
216
+ const todo = todoDisciplineDecision(exec, settings);
217
+ if (todo !== undefined)
218
+ return todo;
219
+ }
220
+ return undefined;
221
+ }
222
+ export function decidePostToolExecution(exec, result, decision, settings, controller) {
223
+ const truncation = settings.guards.toolOutputTruncation;
224
+ if (!truncation.enabled || !isSafetyScopeActive(exec, settings, controller))
225
+ return decision;
226
+ if (result.isError || decision.kind !== "accept" || "value" in decision)
227
+ return decision;
228
+ const content = decision.content ?? result.content;
229
+ const text = allText(content);
230
+ if (text === undefined || utf8Bytes(text) <= truncation.maxInlineBytes)
231
+ return decision;
232
+ return {
233
+ ...decision,
234
+ content: [{ type: "text", text: truncateTextMiddle(text, truncation.maxInlineBytes, exec.name) }]
235
+ };
236
+ }
237
+ export function registerSafetyGuards(ctx, controller, getSettings) {
238
+ ctx.on?.("tools/pre-execute", async (exec, next) => {
239
+ const decision = decidePreToolExecution(exec, getSettings(), controller);
240
+ if (decision === undefined)
241
+ return next();
242
+ if (decision.kind === "deny")
243
+ return decision;
244
+ const downstream = await next();
245
+ return downstream.kind === "allow" ? decision : downstream;
246
+ }, { prepend: true });
247
+ ctx.on?.("tools/post-execute", async (exec, result, next) => {
248
+ const decision = await next();
249
+ return decidePostToolExecution(exec, result, decision, getSettings(), controller);
250
+ }, { prepend: true });
251
+ }
252
+ //# sourceMappingURL=guards.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { DshContext } from "./dsh-types.js";
2
+ import type { DsmmPluginConfig } from "./settings.js";
3
+ export declare const name = "dsmm";
4
+ export declare const inject: readonly [];
5
+ export type Config = DsmmPluginConfig;
6
+ export declare const Config: import("@deepseek-ai/schemastery").default<DsmmPluginConfig>;
7
+ export type { DeepworkSessionEventMap } from "./dsh-events.js";
8
+ export type { DsmmRoleDefinition, DsmmRoleId } from "./roles.js";
9
+ export { DSMM_ROLE_IDS, DSMM_ROLES, isDsmmRoleId, renderAgentCordis, renderPresetMetadata } from "./roles.js";
10
+ export { DSMM_MANAGED_PRESET_MARKER, materializeRolePresets, reconcileRolePresets, resolveManagedPresetRoot } from "./preset-materializer.js";
11
+ export { DSMM_GUARD_PREFIX, decidePostToolExecution, decidePreToolExecution, isSafetyScopeActive, registerSafetyGuards, truncateTextMiddle } from "./guards.js";
12
+ export { DEFAULT_DSMM_LSP_SETTINGS, DSMM_LSP_SERVER_NAME, DSMM_LSP_TOOL_NAMES, parseLspSmokeCommand, publicLspToolName, renderLspMcpPatch, resolveLspSettings, toDshMcpClientConfig } from "./lsp.js";
13
+ export type { DshMcpStdioConfig, DsmmLspSettings, DsmmLspToolName } from "./lsp.js";
14
+ export { classifyModelFamily } from "./model-family.js";
15
+ export type { DsmmModelFamily } from "./model-family.js";
16
+ export { desiredDeepseekEffort, isDeepseekV4ProRoute, registerModelRouting, selectAdvertisedEffort } from "./model-routing.js";
17
+ export type { DeepseekReasoningEffort } from "./model-routing.js";
18
+ export { classifyRecoveryFailure, foldAttemptedRecoveryRoutes, foldDurableRecoveryWork, selectFallbackRoute } from "./recovery-policy.js";
19
+ export type { DurableRecoveryWork, RecoveryFailureDecision } from "./recovery-policy.js";
20
+ export { registerRuntimeRecovery } from "./runtime-recovery.js";
21
+ export { resolveSelectedAgentPreset } from "./session-scope.js";
22
+ export { DSMM_STATUS_COMMAND, registerDsmmStatusCommand } from "./commands.js";
23
+ export { DSMM_STATUS_VERSION, createDsmmStatusSnapshot, formatDsmmStatus } from "./status.js";
24
+ export type { DsmmStatusSnapshot } from "./status.js";
25
+ export type { AgentRequestErrorFrame, AgentRequestFrame, AgentTurnStoppingFrame, DshEpochHeader, DshGoalChangeEventData, DshGoalSnapshot, DshLlmCallConfig, DshLlmFailure, DshModelReasoningInfo, DshReasoningEffortInfo, DshRequestErrorAction, DshRequestHeaderEventData, DshResolvedModelInfo, DshStepBoundaryEventData, DshTodoItem, DshTodoWriteEventData } from "./dsh-types.js";
26
+ export { DSMM_SKILL_NAMES, DEFAULT_DSMM_SETTINGS, MVP_SKILL_NAMES, isRoleEnabled, resolveConfig, registerSettings } from "./settings.js";
27
+ export type { DeepseekCalibration, DeepseekDefaultReasoningEffort, DsmmFinalReviewPolicy, DsmmGitWritePolicy, DsmmGuardScope, DsmmGuardSettings, DsmmPluginConfig, DsmmRecoveryRoute, DsmmRuntimeRecoverySettings, DsmmSettings, DsmmSkillName, DsmmWorkflowSettings, MvpSkillName } from "./settings.js";
28
+ export { DEEPWORK_MODE_EVENT, DeepworkModeController, hasOpenTurn, isDeepworkActive } from "./state.js";
29
+ export declare function apply(ctx: DshContext, config?: Config): void;
30
+ export default apply;
31
+ //# sourceMappingURL=index.d.ts.map
package/lib/index.js ADDED
@@ -0,0 +1,54 @@
1
+ import { registerDeepworkCommand, registerDsmmStatusCommand } from "./commands.js";
2
+ import { registerSafetyGuards } from "./guards.js";
3
+ import { registerDeepworkPrompt } from "./mode.js";
4
+ import { registerModelRouting } from "./model-routing.js";
5
+ import { registerRuntimeRecovery } from "./runtime-recovery.js";
6
+ import { reconcileRolePresets, resolveManagedPresetRoot } from "./preset-materializer.js";
7
+ import { registerHeadlessRoleTools } from "./role-subagents.js";
8
+ import { registerRolePresets } from "./preset-registry.js";
9
+ import { DSMM_CONFIG_SCHEMA, registerSettings } from "./settings.js";
10
+ import { DeepworkModeController } from "./state.js";
11
+ export const name = "dsmm";
12
+ export const inject = [];
13
+ export const Config = DSMM_CONFIG_SCHEMA;
14
+ export { DSMM_ROLE_IDS, DSMM_ROLES, isDsmmRoleId, renderAgentCordis, renderPresetMetadata } from "./roles.js";
15
+ export { DSMM_MANAGED_PRESET_MARKER, materializeRolePresets, reconcileRolePresets, resolveManagedPresetRoot } from "./preset-materializer.js";
16
+ export { DSMM_GUARD_PREFIX, decidePostToolExecution, decidePreToolExecution, isSafetyScopeActive, registerSafetyGuards, truncateTextMiddle } from "./guards.js";
17
+ export { DEFAULT_DSMM_LSP_SETTINGS, DSMM_LSP_SERVER_NAME, DSMM_LSP_TOOL_NAMES, parseLspSmokeCommand, publicLspToolName, renderLspMcpPatch, resolveLspSettings, toDshMcpClientConfig } from "./lsp.js";
18
+ export { classifyModelFamily } from "./model-family.js";
19
+ export { desiredDeepseekEffort, isDeepseekV4ProRoute, registerModelRouting, selectAdvertisedEffort } from "./model-routing.js";
20
+ export { classifyRecoveryFailure, foldAttemptedRecoveryRoutes, foldDurableRecoveryWork, selectFallbackRoute } from "./recovery-policy.js";
21
+ export { registerRuntimeRecovery } from "./runtime-recovery.js";
22
+ export { resolveSelectedAgentPreset } from "./session-scope.js";
23
+ export { DSMM_STATUS_COMMAND, registerDsmmStatusCommand } from "./commands.js";
24
+ export { DSMM_STATUS_VERSION, createDsmmStatusSnapshot, formatDsmmStatus } from "./status.js";
25
+ export { DSMM_SKILL_NAMES, DEFAULT_DSMM_SETTINGS, MVP_SKILL_NAMES, isRoleEnabled, resolveConfig, registerSettings } from "./settings.js";
26
+ export { DEEPWORK_MODE_EVENT, DeepworkModeController, hasOpenTurn, isDeepworkActive } from "./state.js";
27
+ export function apply(ctx, config = {}) {
28
+ const controller = new DeepworkModeController(ctx);
29
+ const getSettings = registerSettings(ctx, config, {
30
+ install(readyCtx, getReadySettings) {
31
+ registerDeepworkPrompt(readyCtx, controller, getReadySettings, config);
32
+ const installCommands = (commandCtx) => {
33
+ registerDeepworkCommand(commandCtx, controller, getReadySettings);
34
+ registerDsmmStatusCommand(commandCtx, controller, getReadySettings);
35
+ };
36
+ if (readyCtx.get !== undefined && readyCtx.inject !== undefined)
37
+ readyCtx.inject(["commands"], installCommands);
38
+ else
39
+ installCommands(readyCtx);
40
+ registerRolePresets(readyCtx, getReadySettings);
41
+ const settings = getReadySettings();
42
+ const root = resolveManagedPresetRoot(settings);
43
+ if (root === undefined)
44
+ return;
45
+ reconcileRolePresets({ root, settings });
46
+ }
47
+ });
48
+ registerRuntimeRecovery(ctx, controller, getSettings);
49
+ registerModelRouting(ctx, controller, getSettings);
50
+ registerHeadlessRoleTools(ctx, controller, getSettings);
51
+ registerSafetyGuards(ctx, controller, getSettings);
52
+ }
53
+ export default apply;
54
+ //# sourceMappingURL=index.js.map
package/lib/lsp.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ export declare const DSMM_LSP_SERVER_NAME = "dsmm_lsp";
2
+ export declare const DSMM_LSP_TOOL_NAMES: readonly ["status", "diagnostics", "goto_definition", "find_references", "find_symbol_related", "symbols", "prepare_rename", "rename", "format"];
3
+ export type DsmmLspToolName = (typeof DSMM_LSP_TOOL_NAMES)[number];
4
+ export interface DsmmLspSettings {
5
+ enabled: boolean;
6
+ serverName: string;
7
+ command: string;
8
+ args: string[];
9
+ cwd: string;
10
+ env: Record<string, string>;
11
+ toolCallTimeoutMs: number;
12
+ failOnStartupError: boolean;
13
+ }
14
+ export interface DshMcpStdioConfig {
15
+ transport: "stdio";
16
+ serverName: string;
17
+ command: string;
18
+ args: string[];
19
+ env: Record<string, string>;
20
+ cwd: string;
21
+ toolCallTimeoutMs: number;
22
+ failOnStartupError: boolean;
23
+ }
24
+ export declare const DEFAULT_DSMM_LSP_SETTINGS: DsmmLspSettings;
25
+ export declare function resolveLspSettings(input?: Partial<DsmmLspSettings>): DsmmLspSettings;
26
+ export declare function toDshMcpClientConfig(input?: Partial<DsmmLspSettings>): DshMcpStdioConfig;
27
+ export declare function publicLspToolName(rawName: DsmmLspToolName, serverName?: string): string;
28
+ export declare function renderLspMcpPatch(input?: Partial<DsmmLspSettings>): string;
29
+ export declare function parseLspSmokeCommand(raw: string | undefined, fallback: readonly string[]): string[];
30
+ //# sourceMappingURL=lsp.d.ts.map