@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,258 @@
1
+ import { lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
2
+ import { randomUUID } from "node:crypto";
3
+ import { isAbsolute, join, relative, sep } from "node:path";
4
+ import { DSMM_ROLES, DSMM_ROLE_IDS, renderAgentCordis, renderPresetMetadata } from "./roles.js";
5
+ import { isRoleEnabled } from "./settings.js";
6
+ import { enabledSkillNames } from "./skills.js";
7
+ export const DSMM_MANAGED_PRESET_MARKER = ".dsmm-managed-preset";
8
+ export const DSMM_MANAGED_PRESET_MARKER_VERSION = 1;
9
+ const LEGACY_MANAGED_PRESET_MARKER = "managed by dsmm\n";
10
+ const MANAGED_PRESET_FILES = ["agent.cordis.yml", "preset.yml", DSMM_MANAGED_PRESET_MARKER];
11
+ const DEFAULT_PRESET_FILESYSTEM = {
12
+ lstatSync(path) {
13
+ return lstatSync(path);
14
+ },
15
+ mkdirSync(path, options) {
16
+ mkdirSync(path, options);
17
+ },
18
+ readFileSync(path, encoding) {
19
+ return readFileSync(path, encoding);
20
+ },
21
+ readdirSync(path) {
22
+ return readdirSync(path);
23
+ },
24
+ realpathSync(path) {
25
+ return realpathSync(path);
26
+ },
27
+ renameSync(from, to) {
28
+ renameSync(from, to);
29
+ },
30
+ rmSync(path, options) {
31
+ rmSync(path, options);
32
+ },
33
+ writeFileSync(path, data, encoding) {
34
+ writeFileSync(path, data, encoding);
35
+ }
36
+ };
37
+ export function renderManagedPresetMarker(role) {
38
+ return `dsmm-managed-preset/v${DSMM_MANAGED_PRESET_MARKER_VERSION}\nrole=${role}\n`;
39
+ }
40
+ export function resolveManagedPresetRoot(settings, env = process.env) {
41
+ if (settings.presets.root !== undefined)
42
+ return settings.presets.root;
43
+ const dshHome = env.DSH_HOME;
44
+ return dshHome === undefined || dshHome.length === 0 ? undefined : join(dshHome, ".agent-presets");
45
+ }
46
+ export function materializeRolePresets(options) {
47
+ reconcileRolePresets({
48
+ ...options,
49
+ settings: {
50
+ ...options.settings,
51
+ presets: { ...options.settings.presets, materialize: true }
52
+ }
53
+ });
54
+ }
55
+ export function reconcileRolePresets({ root, settings, filesystem: filesystemOverride }) {
56
+ if (root.length === 0) {
57
+ throw new Error("dsmm preset materialization root must not be empty");
58
+ }
59
+ const filesystem = { ...DEFAULT_PRESET_FILESYSTEM, ...filesystemOverride };
60
+ const canonicalRoot = prepareManagedRoot(root, settings.presets.materialize, filesystem);
61
+ if (canonicalRoot === undefined)
62
+ return;
63
+ const knownDirectories = DSMM_ROLES.map((role) => {
64
+ const directory = join(root, role.id);
65
+ return {
66
+ role,
67
+ directory,
68
+ ownership: inspectKnownRoleDirectory(canonicalRoot, directory, role.id, filesystem)
69
+ };
70
+ });
71
+ for (const knownDirectory of knownDirectories) {
72
+ if (settings.presets.materialize && isRoleEnabled(settings, knownDirectory.role.id) && knownDirectory.ownership === "foreign") {
73
+ throw new Error(`dsmm preset directory is foreign and will not be claimed: ${knownDirectory.directory}`);
74
+ }
75
+ }
76
+ for (const knownDirectory of knownDirectories) {
77
+ if (settings.presets.materialize && isRoleEnabled(settings, knownDirectory.role.id)) {
78
+ if (knownDirectory.ownership === "absent") {
79
+ publishNewRoleDirectory(canonicalRoot, root, knownDirectory.role.id, settings, filesystem);
80
+ }
81
+ else {
82
+ updateOwnedRoleDirectory(canonicalRoot, knownDirectory, settings, filesystem);
83
+ }
84
+ continue;
85
+ }
86
+ if (knownDirectory.ownership === "current" || knownDirectory.ownership === "legacy") {
87
+ removeOwnedRoleDirectory(canonicalRoot, knownDirectory, filesystem);
88
+ }
89
+ }
90
+ }
91
+ function prepareManagedRoot(root, materialize, filesystem) {
92
+ const rootStatus = lstatIfExists(root, filesystem);
93
+ if (rootStatus === undefined) {
94
+ if (!materialize)
95
+ return undefined;
96
+ filesystem.mkdirSync(root, { recursive: true });
97
+ }
98
+ else {
99
+ assertDirectoryNotLinked(root, rootStatus, "preset root");
100
+ }
101
+ const verifiedRootStatus = lstatIfExists(root, filesystem);
102
+ if (verifiedRootStatus === undefined) {
103
+ throw new Error(`dsmm preset root disappeared after creation: ${root}`);
104
+ }
105
+ assertDirectoryNotLinked(root, verifiedRootStatus, "preset root");
106
+ return filesystem.realpathSync(root);
107
+ }
108
+ function inspectKnownRoleDirectory(canonicalRoot, directory, role, filesystem) {
109
+ const directoryStatus = lstatIfExists(directory, filesystem);
110
+ if (directoryStatus === undefined)
111
+ return "absent";
112
+ assertDirectoryNotLinked(directory, directoryStatus, `preset directory for ${role}`);
113
+ assertCanonicalChild(canonicalRoot, filesystem.realpathSync(directory), `preset directory for ${role}`);
114
+ const entryNames = filesystem.readdirSync(directory).sort();
115
+ if (!entryNames.includes(DSMM_MANAGED_PRESET_MARKER))
116
+ return "foreign";
117
+ const markerPath = join(directory, DSMM_MANAGED_PRESET_MARKER);
118
+ assertRegularUnlinkedFile(markerPath, `marker for ${role}`, filesystem);
119
+ const marker = filesystem.readFileSync(markerPath, "utf8");
120
+ const expectedMarker = renderManagedPresetMarker(role);
121
+ if (marker === expectedMarker) {
122
+ if (!hasExactManagedShape(entryNames)) {
123
+ throw new Error(`dsmm current managed preset directory has unexpected entries and will not be claimed: ${directory}`);
124
+ }
125
+ assertManagedFilesAreRegular(directory, role, filesystem);
126
+ return "current";
127
+ }
128
+ if (marker !== LEGACY_MANAGED_PRESET_MARKER)
129
+ return "foreign";
130
+ if (!hasExactManagedShape(entryNames))
131
+ return "foreign";
132
+ assertManagedFilesAreRegular(directory, role, filesystem);
133
+ return "legacy";
134
+ }
135
+ function hasExactManagedShape(entryNames) {
136
+ return entryNames.length === MANAGED_PRESET_FILES.length
137
+ && MANAGED_PRESET_FILES.every((name) => entryNames.includes(name));
138
+ }
139
+ function assertManagedFilesAreRegular(directory, role, filesystem) {
140
+ for (const fileName of MANAGED_PRESET_FILES) {
141
+ assertRegularUnlinkedFile(join(directory, fileName), `${fileName} for ${role}`, filesystem);
142
+ }
143
+ }
144
+ function updateOwnedRoleDirectory(canonicalRoot, knownDirectory, settings, filesystem) {
145
+ if (knownDirectory.ownership !== "current" && knownDirectory.ownership !== "legacy") {
146
+ throw new Error(`dsmm preset directory is not owned and cannot be updated: ${knownDirectory.directory}`);
147
+ }
148
+ const files = [
149
+ ["agent.cordis.yml", renderAgentCordis(knownDirectory.role, enabledSkillNames(settings), enabledRoles(settings))],
150
+ ["preset.yml", renderPresetMetadata(knownDirectory.role)],
151
+ [DSMM_MANAGED_PRESET_MARKER, renderManagedPresetMarker(knownDirectory.role.id)]
152
+ ];
153
+ for (const [fileName, content] of files) {
154
+ assertOwnershipUnchanged(canonicalRoot, knownDirectory, filesystem);
155
+ filesystem.writeFileSync(join(knownDirectory.directory, fileName), content, "utf8");
156
+ }
157
+ }
158
+ function removeOwnedRoleDirectory(canonicalRoot, knownDirectory, filesystem) {
159
+ if (knownDirectory.ownership !== "current" && knownDirectory.ownership !== "legacy")
160
+ return;
161
+ assertOwnershipUnchanged(canonicalRoot, knownDirectory, filesystem);
162
+ filesystem.rmSync(knownDirectory.directory, { recursive: true, force: false });
163
+ }
164
+ function assertOwnershipUnchanged(canonicalRoot, knownDirectory, filesystem) {
165
+ const ownership = inspectKnownRoleDirectory(canonicalRoot, knownDirectory.directory, knownDirectory.role.id, filesystem);
166
+ if (ownership !== knownDirectory.ownership) {
167
+ throw new Error(`dsmm preset ownership changed before mutation: ${knownDirectory.directory}`);
168
+ }
169
+ }
170
+ function publishNewRoleDirectory(canonicalRoot, root, role, settings, filesystem) {
171
+ const finalDirectory = join(root, role);
172
+ const temporaryDirectory = join(root, `.${role}.dsmm-${randomUUID()}`);
173
+ let temporaryDirectoryCreated = false;
174
+ try {
175
+ if (lstatIfExists(finalDirectory, filesystem) !== undefined) {
176
+ throw new Error(`dsmm preset directory appeared before publication and will not be replaced: ${finalDirectory}`);
177
+ }
178
+ filesystem.mkdirSync(temporaryDirectory);
179
+ temporaryDirectoryCreated = true;
180
+ const temporaryStatus = lstatIfExists(temporaryDirectory, filesystem);
181
+ if (temporaryStatus === undefined) {
182
+ throw new Error(`dsmm temporary preset directory disappeared after creation: ${temporaryDirectory}`);
183
+ }
184
+ assertDirectoryNotLinked(temporaryDirectory, temporaryStatus, `temporary preset directory for ${role}`);
185
+ assertCanonicalChild(canonicalRoot, filesystem.realpathSync(temporaryDirectory), `temporary preset directory for ${role}`);
186
+ filesystem.writeFileSync(join(temporaryDirectory, "agent.cordis.yml"), renderAgentCordis(findRole(role), enabledSkillNames(settings), enabledRoles(settings)), "utf8");
187
+ filesystem.writeFileSync(join(temporaryDirectory, "preset.yml"), renderPresetMetadata(findRole(role)), "utf8");
188
+ filesystem.writeFileSync(join(temporaryDirectory, DSMM_MANAGED_PRESET_MARKER), renderManagedPresetMarker(role), "utf8");
189
+ if (lstatIfExists(finalDirectory, filesystem) !== undefined) {
190
+ throw new Error(`dsmm preset directory appeared before publication and will not be replaced: ${finalDirectory}`);
191
+ }
192
+ filesystem.renameSync(temporaryDirectory, finalDirectory);
193
+ temporaryDirectoryCreated = false;
194
+ }
195
+ finally {
196
+ if (temporaryDirectoryCreated) {
197
+ removePrivateTemporaryDirectory(canonicalRoot, temporaryDirectory, role, filesystem);
198
+ }
199
+ }
200
+ }
201
+ function removePrivateTemporaryDirectory(canonicalRoot, temporaryDirectory, role, filesystem) {
202
+ const temporaryStatus = lstatIfExists(temporaryDirectory, filesystem);
203
+ if (temporaryStatus === undefined)
204
+ return;
205
+ assertDirectoryNotLinked(temporaryDirectory, temporaryStatus, `temporary preset directory for ${role}`);
206
+ assertCanonicalChild(canonicalRoot, filesystem.realpathSync(temporaryDirectory), `temporary preset directory for ${role}`);
207
+ filesystem.rmSync(temporaryDirectory, { recursive: true, force: false });
208
+ }
209
+ function findRole(roleId) {
210
+ const role = DSMM_ROLES.find((candidate) => candidate.id === roleId);
211
+ if (role === undefined)
212
+ throw new Error(`unknown dsmm role: ${roleId}`);
213
+ return role;
214
+ }
215
+ function enabledRoles(settings) {
216
+ return DSMM_ROLE_IDS.filter((id) => isRoleEnabled(settings, id));
217
+ }
218
+ function assertDirectoryNotLinked(path, status, label) {
219
+ if (status.isSymbolicLink()) {
220
+ throw new Error(`dsmm ${label} must not be a symbolic link or junction: ${path}`);
221
+ }
222
+ if (!status.isDirectory()) {
223
+ throw new Error(`dsmm ${label} must be a directory: ${path}`);
224
+ }
225
+ }
226
+ function assertRegularUnlinkedFile(path, label, filesystem) {
227
+ const status = filesystem.lstatSync(path);
228
+ if (status.isSymbolicLink()) {
229
+ throw new Error(`dsmm ${label} must not be a symbolic link: ${path}`);
230
+ }
231
+ if (!status.isFile()) {
232
+ throw new Error(`dsmm ${label} must be a regular file: ${path}`);
233
+ }
234
+ }
235
+ function assertCanonicalChild(canonicalRoot, canonicalChild, label) {
236
+ const childPath = relative(canonicalRoot, canonicalChild);
237
+ if (childPath.length === 0 || childPath === ".." || childPath.startsWith(`..${sep}`) || isAbsolute(childPath)) {
238
+ throw new Error(`dsmm ${label} escapes the canonical preset root: ${canonicalChild}`);
239
+ }
240
+ }
241
+ function lstatIfExists(path, filesystem) {
242
+ try {
243
+ const status = filesystem.lstatSync(path);
244
+ return status === undefined ? undefined : status;
245
+ }
246
+ catch (error) {
247
+ if (isMissingPathError(error))
248
+ return undefined;
249
+ throw error;
250
+ }
251
+ }
252
+ function isMissingPathError(error) {
253
+ return typeof error === "object"
254
+ && error !== null
255
+ && "code" in error
256
+ && error.code === "ENOENT";
257
+ }
258
+ //# sourceMappingURL=preset-materializer.js.map
@@ -0,0 +1,5 @@
1
+ import type { DshContext } from "./dsh-types.js";
2
+ import type { DsmmSettings } from "./settings.js";
3
+ /** Declare roles to DSH 0.2's native registry; directories are not discovery inputs. */
4
+ export declare function registerRolePresets(ctx: DshContext, getSettings: () => DsmmSettings): void;
5
+ //# sourceMappingURL=preset-registry.d.ts.map
@@ -0,0 +1,126 @@
1
+ import { getTraceable } from "@deepseek-ai/cordis";
2
+ import { DSMM_ROLES, DSMM_ROLE_IDS, rolePluginRows } from "./roles.js";
3
+ import { enabledSkillNames } from "./skills.js";
4
+ /** Declare roles to DSH 0.2's native registry; directories are not discovery inputs. */
5
+ export function registerRolePresets(ctx, getSettings) {
6
+ const install = async (readyCtx) => {
7
+ const registry = readyCtx.get?.("agentPresets")
8
+ ?? readyCtx.agentPresets;
9
+ if (registry === undefined)
10
+ throw new Error("dsmm requires the native DSH agentPresets registry");
11
+ const settings = getSettings();
12
+ const enabled = DSMM_ROLE_IDS.filter((id) => settings.roles[id]);
13
+ const active = DSMM_ROLES.filter((role) => enabled.includes(role.id));
14
+ const disposers = [];
15
+ try {
16
+ for (const role of active) {
17
+ disposers.push(await registry.register({
18
+ id: role.id,
19
+ name: role.name,
20
+ description: role.description,
21
+ order: role.order,
22
+ plugins: rolePluginRows(role, enabledSkillNames(settings), enabled)
23
+ }));
24
+ }
25
+ // A direct selection of a read-only preset must be restricted at the Agent
26
+ // scope: preset-local fs registrations cannot be filtered within their own layer.
27
+ // Blank Agents can switch presets without another agent/created event.
28
+ const states = new WeakMap();
29
+ const restrictedAgents = new Set();
30
+ const reconcile = (agent) => {
31
+ const selected = registry.composedPreset(agent.ctx);
32
+ const previous = states.get(agent);
33
+ if (previous !== undefined && previous.role === selected && (previous.pending || !isReadonlyRole(selected) || previous.disposeRestriction !== undefined))
34
+ return;
35
+ states.set(agent, { role: selected, pending: true });
36
+ previous?.disposeRestriction?.();
37
+ previous?.disposeGuard?.();
38
+ restrictedAgents.delete(agent);
39
+ if (!isReadonlyRole(selected)) {
40
+ states.set(agent, { role: selected });
41
+ return;
42
+ }
43
+ const raw = registry.serviceFor?.(agent, "tools");
44
+ // Cordis throws on an uninjected direct property read. Prefer the
45
+ // selected preset's raw service and trace it into this Agent scope;
46
+ // an unrelated Host tools service may coexist in another realm.
47
+ const tools = raw !== undefined ? getTraceable(agent.ctx, raw)
48
+ : agent.ctx.get?.("tools")
49
+ ?? (agent.ctx.get === undefined ? agent.ctx.tools : undefined);
50
+ try {
51
+ if (tools?.restrict === undefined || tools.guard === undefined)
52
+ throw new Error(`dsmm read-only role requires DSH tools guard/restrict: ${selected}`);
53
+ const disposeGuard = tools.guard((execution) => {
54
+ if (execution.agent !== agent || !isReadonlyRole(registry.composedPreset(agent.ctx)))
55
+ return undefined;
56
+ return ["write", "edit", "bash", "pwsh"].includes(execution.name) || execution.name.startsWith("dsmm_")
57
+ ? "dsmm read-only role does not permit mutation or delegation" : undefined;
58
+ });
59
+ states.set(agent, { role: selected, disposeGuard, pending: true });
60
+ restrictedAgents.add(agent);
61
+ const disposeRestriction = tools.restrict({ deny: ["write", "edit"] });
62
+ states.set(agent, { role: selected, disposeGuard, disposeRestriction });
63
+ }
64
+ catch (error) {
65
+ if (states.get(agent)?.disposeGuard === undefined)
66
+ states.delete(agent);
67
+ else
68
+ states.set(agent, { role: selected, disposeGuard: states.get(agent)?.disposeGuard });
69
+ throw error;
70
+ }
71
+ };
72
+ const onCreated = readyCtx.on?.("agent/created", ({ agent }) => reconcile(agent), { global: true });
73
+ const agents = readyCtx.get?.("agents")
74
+ ?? readyCtx.agents;
75
+ if (agents === undefined)
76
+ throw new Error("dsmm native preset restriction requires DSH Agent registry");
77
+ const onToolChange = readyCtx.on?.("tools/change", () => {
78
+ for (const agent of agents.list())
79
+ reconcile(agent);
80
+ }, { global: true });
81
+ const onSelection = readyCtx.on?.("agent-preset/selected", (sessionId) => {
82
+ const agent = agents.get(sessionId);
83
+ if (agent !== undefined)
84
+ reconcile(agent);
85
+ }, { global: true });
86
+ const onDisposed = readyCtx.on?.("agent/disposed", ({ agent }) => {
87
+ states.get(agent)?.disposeRestriction?.();
88
+ states.get(agent)?.disposeGuard?.();
89
+ states.delete(agent);
90
+ restrictedAgents.delete(agent);
91
+ }, { global: true });
92
+ readyCtx.effect?.(() => () => {
93
+ if (typeof onCreated === "function")
94
+ onCreated();
95
+ if (typeof onToolChange === "function")
96
+ onToolChange();
97
+ if (typeof onSelection === "function")
98
+ onSelection();
99
+ if (typeof onDisposed === "function")
100
+ onDisposed();
101
+ for (const agent of restrictedAgents) {
102
+ states.get(agent)?.disposeRestriction?.();
103
+ states.get(agent)?.disposeGuard?.();
104
+ }
105
+ restrictedAgents.clear();
106
+ for (const dispose of disposers.reverse())
107
+ void dispose();
108
+ });
109
+ }
110
+ catch (error) {
111
+ for (const dispose of disposers.reverse())
112
+ await dispose();
113
+ throw error;
114
+ }
115
+ };
116
+ if (ctx.inject !== undefined) {
117
+ ctx.inject(["agentPresets"], install);
118
+ }
119
+ else if (ctx.get?.("agentPresets") !== undefined || ctx.agentPresets !== undefined) {
120
+ void install(ctx).catch((error) => ctx.logger?.warn(`dsmm native preset registration failed: ${String(error)}`));
121
+ }
122
+ }
123
+ function isReadonlyRole(id) {
124
+ return DSMM_ROLES.some((role) => role.id === id && role.access === "read-only");
125
+ }
126
+ //# sourceMappingURL=preset-registry.js.map
@@ -0,0 +1,12 @@
1
+ import Schema from "@deepseek-ai/schemastery";
2
+ import type { DshContext } from "./dsh-types.js";
3
+ import type { DsmmSkillName } from "./skills.js";
4
+ export declare const name = "dsmm/preset-skills";
5
+ export declare const inject: readonly ["skills"];
6
+ export interface PresetSkillsConfig {
7
+ skills?: DsmmSkillName[];
8
+ }
9
+ export declare const Config: Schema<PresetSkillsConfig>;
10
+ export declare function apply(ctx: DshContext, config?: PresetSkillsConfig): void;
11
+ export default apply;
12
+ //# sourceMappingURL=preset-skills.d.ts.map
@@ -0,0 +1,28 @@
1
+ import Schema from "@deepseek-ai/schemastery";
2
+ import { DSMM_SKILL_NAMES, DSMM_ON_DEMAND_SKILL_NAMES, registerBundledSkills } from "./skills.js";
3
+ export const name = "dsmm/preset-skills";
4
+ export const inject = ["skills"];
5
+ const SKILL_NAME_SCHEMA = Schema.union([
6
+ Schema.const("brainstorming"),
7
+ Schema.const("writing-plans"),
8
+ Schema.const("requesting-code-review"),
9
+ Schema.const("receiving-code-review"),
10
+ Schema.const("subagent-driven-development"),
11
+ Schema.const("dispatching-parallel-agents"),
12
+ Schema.const("remove-ai-slops")
13
+ ]);
14
+ export const Config = Schema.object({
15
+ skills: Schema.array(SKILL_NAME_SCHEMA).default([...DSMM_SKILL_NAMES])
16
+ });
17
+ export function apply(ctx, config = {}) {
18
+ const skills = config.skills ?? DSMM_SKILL_NAMES;
19
+ const register = (registry) => registerBundledSkills(registry, [...skills, ...DSMM_ON_DEMAND_SKILL_NAMES]);
20
+ if (ctx.inject !== undefined) {
21
+ ctx.inject(["skills"], (readyCtx) => register(readyCtx.skills));
22
+ }
23
+ else if (Object.prototype.hasOwnProperty.call(ctx, "skills")) {
24
+ register(Object.getOwnPropertyDescriptor(ctx, "skills")?.value);
25
+ }
26
+ }
27
+ export default apply;
28
+ //# sourceMappingURL=preset-skills.js.map
@@ -0,0 +1,13 @@
1
+ import type { DshLlmCallConfig } from "./dsh-types.js";
2
+ import type { DsmmSettings } from "./settings.js";
3
+ export declare const BASE_DEEPWORK_PROMPT = "<dsmm-deepwork-mode>\n\nDEEPWORK MODE ENABLED!\n\nUse this workflow only while the `{{modeName}}` mode is active OR a DSMM-managed preset is selected. This is an opt-in boundary: outside both conditions, do not apply dsmm-specific gates, intent routing, or tool-discipline requirements. The default mode name is `deepwork` unless configured.\n\n## Intent routing\n\nDetermine whether the user requests an explanation, diagnosis, implementation, or open-ended design. State the outcome and evidence in the user's language; classify aloud only when it helps the user.\n\n## Workflow gates\n\n- A clear implementation request authorizes its stated scope. Do not require design reapproval or a separate approval loop for equivalent implementation decisions.\n- For complex business or behavior implementation, default to planner \u2192 plan-critic \u2192 implementation. Skip this sequence only for a bounded, simple, low-risk change or an explicit permitted user request. A task having multiple steps alone is not the criterion.\n- Escalate choices that change scope or acceptance, weaken safety/data guarantees, change a public API/protocol or permissions, or cause an irreversible effect. Preserve explicit user configuration.\n- Request implementation review when risk, uncertainty, or user requirements warrant it; reviewer is primary-lane self-review, while an Oracle is an externally configured cross-check. Do not run fixed review loops or manufacture an Oracle model.\n- For completed implementation, gather evidence from tests, diagnostics, and real surfaces before declaring done.\n- Keep scope exact. Do not add unrelated refactors, speculative abstractions, or surprise features.\n- The bundled workflow skill set is available in this mode: `brainstorming`, `writing-plans`, `subagent-driven-development`, `dispatching-parallel-agents`, `requesting-code-review`, `receiving-code-review`, and `remove-ai-slops`.\n- `workflow.policy=risk-based` uses the rules above. Explicit `workflow.policy=legacy` retains the configured `strictGates`, `reviewCap`, and `finalReviewPolicy` gates. Do not apply any DSMM policy outside active `{{modeName}}` mode or DSMM-managed preset scope.\n\n## Tool discipline\n\nUse repository tools for repository-specific claims. Prefer narrow reads and searches before broad exploration. Use external documentation for library, API, CLI, or cloud-service details.\n\n- Use the shell dialect available in the current DSH runtime. Keep commands short and inspectable; resolve exact paths before destructive actions and do not string-build cross-shell deletes.\n- No autonomous Git writes: implementing or fixing does not authorize a commit, and a commit does not authorize pushing, tagging, rebasing, or releasing.\n- Child tasks inherit the host's authority and depth limits. Delegate only through actually available DSH tools; preset files alone do not prove that a role is callable.\n\n- DSMM safety guards may enforce shell dialect, git-write approval, output-size, plan-format, question-label, and todo-discipline policy inside this mode; treat `[dsmm safety]` messages as binding policy feedback.\n\n</dsmm-deepwork-mode>";
4
+ export declare const DEEPSEEK_V4_PRO_OVERLAY = "<dsmm-deepseek-v4-pro-calibration>\n\nDeepSeek V4 Pro calibration is active.\n\n- Treat complex coding, architecture, migration, debugging, and review tasks as deliberate reasoning tasks.\n- First classify the task and identify the evidence needed.\n- Use tools before making repository-specific or API-specific claims.\n- Runtime reasoning effort is enforced by `agent/request`, not this prompt.\n- In `auto` calibration, explicit upstream reasoning effort is preserved; `strict` overrides it with computed policy.\n- Only adapter-advertised reasoning efforts are emitted; `max` is selected only for configured DSMM presets.\n- Keep final answers concise and do not expose private chain-of-thought.\n- When tool calls are enabled through the provider, preserve the provider-required reasoning/tool-call continuity.\n\n</dsmm-deepseek-v4-pro-calibration>";
5
+ export declare const DEEPSEEK_FLASH_OVERLAY = "<dsmm-deepseek-flash-calibration>\n\nDeepSeek-V41-Flash applies only to the verified deepseek-official/deepseek-flash or deepseek-account/deepseek-flash routes. The host catalog and explicit user model choice are authoritative.\n\n- Keep work outcome-first and avoid procedural review or approval loops.\n- Runtime reasoning effort is chosen by the adapter only from the resolved model's advertised efforts. If the catalog advertises no reasoning efforts, leave the request unchanged.\n- Auto preserves explicit upstream effort; strict overrides it only with an advertised effort.\n- Do not assume max, high, temperature, or another model's capabilities. Do not claim model heterogeneity when all child roles use the same route.\n- Maintain tool-call continuity required by the provider and never reveal private reasoning.\n\n</dsmm-deepseek-flash-calibration>";
6
+ export interface DeepworkPromptOptions {
7
+ route?: Pick<DshLlmCallConfig, "provider" | "model">;
8
+ selectedPreset?: string;
9
+ overrideSection?: string;
10
+ skillPrompt?: string;
11
+ }
12
+ export declare function buildDeepworkPrompt(settings: DsmmSettings, options?: DeepworkPromptOptions): string;
13
+ //# sourceMappingURL=prompts.d.ts.map
package/lib/prompts.js ADDED
@@ -0,0 +1,82 @@
1
+ import { desiredDeepseekEffort, isDeepseekFlashRoute, isDeepseekV4ProRoute } from "./model-routing.js";
2
+ export const BASE_DEEPWORK_PROMPT = `<dsmm-deepwork-mode>
3
+
4
+ DEEPWORK MODE ENABLED!
5
+
6
+ Use this workflow only while the \`{{modeName}}\` mode is active OR a DSMM-managed preset is selected. This is an opt-in boundary: outside both conditions, do not apply dsmm-specific gates, intent routing, or tool-discipline requirements. The default mode name is \`deepwork\` unless configured.
7
+
8
+ ## Intent routing
9
+
10
+ Determine whether the user requests an explanation, diagnosis, implementation, or open-ended design. State the outcome and evidence in the user's language; classify aloud only when it helps the user.
11
+
12
+ ## Workflow gates
13
+
14
+ - A clear implementation request authorizes its stated scope. Do not require design reapproval or a separate approval loop for equivalent implementation decisions.
15
+ - For complex business or behavior implementation, default to planner → plan-critic → implementation. Skip this sequence only for a bounded, simple, low-risk change or an explicit permitted user request. A task having multiple steps alone is not the criterion.
16
+ - Escalate choices that change scope or acceptance, weaken safety/data guarantees, change a public API/protocol or permissions, or cause an irreversible effect. Preserve explicit user configuration.
17
+ - Request implementation review when risk, uncertainty, or user requirements warrant it; reviewer is primary-lane self-review, while an Oracle is an externally configured cross-check. Do not run fixed review loops or manufacture an Oracle model.
18
+ - For completed implementation, gather evidence from tests, diagnostics, and real surfaces before declaring done.
19
+ - Keep scope exact. Do not add unrelated refactors, speculative abstractions, or surprise features.
20
+ - The bundled workflow skill set is available in this mode: \`brainstorming\`, \`writing-plans\`, \`subagent-driven-development\`, \`dispatching-parallel-agents\`, \`requesting-code-review\`, \`receiving-code-review\`, and \`remove-ai-slops\`.
21
+ - \`workflow.policy=risk-based\` uses the rules above. Explicit \`workflow.policy=legacy\` retains the configured \`strictGates\`, \`reviewCap\`, and \`finalReviewPolicy\` gates. Do not apply any DSMM policy outside active \`{{modeName}}\` mode or DSMM-managed preset scope.
22
+
23
+ ## Tool discipline
24
+
25
+ Use repository tools for repository-specific claims. Prefer narrow reads and searches before broad exploration. Use external documentation for library, API, CLI, or cloud-service details.
26
+
27
+ - Use the shell dialect available in the current DSH runtime. Keep commands short and inspectable; resolve exact paths before destructive actions and do not string-build cross-shell deletes.
28
+ - No autonomous Git writes: implementing or fixing does not authorize a commit, and a commit does not authorize pushing, tagging, rebasing, or releasing.
29
+ - Child tasks inherit the host's authority and depth limits. Delegate only through actually available DSH tools; preset files alone do not prove that a role is callable.
30
+
31
+ - DSMM safety guards may enforce shell dialect, git-write approval, output-size, plan-format, question-label, and todo-discipline policy inside this mode; treat \`[dsmm safety]\` messages as binding policy feedback.
32
+
33
+ </dsmm-deepwork-mode>`;
34
+ export const DEEPSEEK_V4_PRO_OVERLAY = `<dsmm-deepseek-v4-pro-calibration>
35
+
36
+ DeepSeek V4 Pro calibration is active.
37
+
38
+ - Treat complex coding, architecture, migration, debugging, and review tasks as deliberate reasoning tasks.
39
+ - First classify the task and identify the evidence needed.
40
+ - Use tools before making repository-specific or API-specific claims.
41
+ - Runtime reasoning effort is enforced by \`agent/request\`, not this prompt.
42
+ - In \`auto\` calibration, explicit upstream reasoning effort is preserved; \`strict\` overrides it with computed policy.
43
+ - Only adapter-advertised reasoning efforts are emitted; \`max\` is selected only for configured DSMM presets.
44
+ - Keep final answers concise and do not expose private chain-of-thought.
45
+ - When tool calls are enabled through the provider, preserve the provider-required reasoning/tool-call continuity.
46
+
47
+ </dsmm-deepseek-v4-pro-calibration>`;
48
+ export const DEEPSEEK_FLASH_OVERLAY = `<dsmm-deepseek-flash-calibration>
49
+
50
+ DeepSeek-V41-Flash applies only to the verified deepseek-official/deepseek-flash or deepseek-account/deepseek-flash routes. The host catalog and explicit user model choice are authoritative.
51
+
52
+ - Keep work outcome-first and avoid procedural review or approval loops.
53
+ - Runtime reasoning effort is chosen by the adapter only from the resolved model's advertised efforts. If the catalog advertises no reasoning efforts, leave the request unchanged.
54
+ - Auto preserves explicit upstream effort; strict overrides it only with an advertised effort.
55
+ - Do not assume max, high, temperature, or another model's capabilities. Do not claim model heterogeneity when all child roles use the same route.
56
+ - Maintain tool-call continuity required by the provider and never reveal private reasoning.
57
+
58
+ </dsmm-deepseek-flash-calibration>`;
59
+ export function buildDeepworkPrompt(settings, options = {}) {
60
+ const base = (options.overrideSection?.trim() || BASE_DEEPWORK_PROMPT).replaceAll("{{modeName}}", settings.modeName);
61
+ const workflowPolicy = settings.workflow.policy === "legacy" ? `<dsmm-workflow-policy>
62
+ policy: legacy
63
+ strictGates: ${String(settings.workflow.strictGates)}
64
+ reviewCap: ${String(settings.workflow.reviewCap)}
65
+ finalReviewPolicy: ${settings.workflow.finalReviewPolicy}
66
+ </dsmm-workflow-policy>` : `<dsmm-workflow-policy>policy: risk-based</dsmm-workflow-policy>`;
67
+ const route = options.route;
68
+ const model = route !== undefined && isDeepseekV4ProRoute(route) ? "v4-pro"
69
+ : route !== undefined && isDeepseekFlashRoute(route) ? "flash" : undefined;
70
+ const calibration = model === "flash" ? settings.deepseekFlashCalibration : settings.deepseekV4ProCalibration;
71
+ const calibrationPolicy = model === undefined ? "" : `<dsmm-deepseek-${model}-policy>
72
+ calibrationMode: ${calibration}
73
+ defaultReasoningEffort: ${model === "flash" ? settings.deepseekFlashDefaultReasoningEffort : settings.deepseekV4ProDefaultReasoningEffort}
74
+ maxReasoningPresets: ${(model === "flash" ? settings.deepseekFlashMaxReasoningPresets : settings.deepseekV4ProMaxReasoningPresets).join(", ")}
75
+ effectiveDesiredReasoningEffort: ${desiredDeepseekEffort(settings, options.selectedPreset, model)}
76
+ </dsmm-deepseek-${model}-policy>`;
77
+ const calibrated = model !== undefined && calibration !== "off"
78
+ ? `${base}\n\n${model === "flash" ? DEEPSEEK_FLASH_OVERLAY : DEEPSEEK_V4_PRO_OVERLAY}\n\n${calibrationPolicy}` : base;
79
+ const prompt = `${calibrated}\n\n${workflowPolicy}`;
80
+ return options.skillPrompt === undefined || options.skillPrompt === "" ? prompt : `${prompt}\n\n${options.skillPrompt}`;
81
+ }
82
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1,25 @@
1
+ import type { DshLlmFailure, DshSessionEvent } from "./dsh-types.js";
2
+ import type { DsmmRecoveryRoute, DsmmRuntimeRecoverySettings } from "./settings.js";
3
+ export type RecoveryFailureDecision = {
4
+ kind: "retryable";
5
+ matchedBy: "status" | "code";
6
+ } | {
7
+ kind: "ignored";
8
+ };
9
+ export interface DurableRecoveryWork {
10
+ incompleteTodo: boolean;
11
+ activeGoal: boolean;
12
+ }
13
+ interface FallbackRouteSelectionInput {
14
+ failedRoute: DsmmRecoveryRoute;
15
+ attemptedRoutes: readonly DsmmRecoveryRoute[];
16
+ fallbackRoutes: readonly DsmmRecoveryRoute[];
17
+ maxFallbackAttempts: number;
18
+ }
19
+ export declare function classifyRecoveryFailure(failure: DshLlmFailure, settings: DsmmRuntimeRecoverySettings): RecoveryFailureDecision;
20
+ export declare function isCurrentRecoveryStep(events: readonly DshSessionEvent[], turn: number, step: number): boolean;
21
+ export declare function foldAttemptedRecoveryRoutes(events: readonly DshSessionEvent[], turn: number, step: number): DsmmRecoveryRoute[];
22
+ export declare function foldDurableRecoveryWork(events: readonly DshSessionEvent[]): DurableRecoveryWork;
23
+ export declare function selectFallbackRoute({ failedRoute, attemptedRoutes, fallbackRoutes, maxFallbackAttempts }: FallbackRouteSelectionInput): DsmmRecoveryRoute | undefined;
24
+ export {};
25
+ //# sourceMappingURL=recovery-policy.d.ts.map