Introduction¶
DeepSeek Harness (DSH) assigns Agent presets to new sessions based on global settings or user selection by default. In multi-workspace scenarios, developers often want sessions in the same directory to automatically use different preset configurations, avoiding the need to manually switch presets every time a session is created. DSH does not natively support automatic preset selection by path, so a plugin extension is required.
This article introduces the @local/dsh-preset-workspace-hook plugin, which automatically selects an Agent preset for new sessions based on the workspace directory in DSH.
What It Is¶
@local/dsh-preset-workspace-hook is a DSH client plugin maintained by hluica. It works by maintaining a mapping of “workspace condition → Agent preset.” When a new session is created, the first matching condition triggers a preset switch; if no condition matches, DSH’s original behavior is preserved. The plugin supports two execution modes: aggressive (rewriting before session creation) and fallback (switching after Agent creation).
Core Features¶
Settings Page¶
Settings → Workspace Preset Switcher (located right after the official “Agent Presets” page).
- Config File: Displays
$DSH_HOME/dsh-preset-workspace-hook/config.json(defaults to~/.dsh/dsh-preset-workspace-hook/config.json) and the currently active execution mode. - Enable Auto-Switching: When disabled, all conditions are retained but no session preset is modified, and the pre-creation wrapper is no longer installed.
- Execution Mode:
- Prefer Aggressive Mode: Attempts pre-creation rewriting first; if the current DSH cannot install the wrapper, it automatically falls back to the fallback mode. The status line displays “Installed / Unavailable (reason) / Awaiting service.”
- Fallback Mode Only: Does not install any wrapper; relies solely on public events and methods.
- Conditions: Each condition includes a match type (exact / prefix / suffix / glob / regex), a match target (directory name / full path), a pattern, regex flags (shown only for regex), and a resulting preset. Conditions are evaluated top to bottom; the first match takes effect.
- Current DSH Workspace Query: Read-only. Click “Query Current Workspace” to compute based on the currently edited conditions. Displays the workspace title, full path, directory name, matched condition, and resulting preset.
- Available Agent Presets: Read-only. Lists all built-in and custom presets, marking defaults and unavailable items.
Configuration File¶
The default configuration file is located at $DSH_HOME/dsh-preset-workspace-hook/config.json:
{
"version": 1,
"enabled": true,
"mode": "aggressive",
"conditions": [
{
"id": "cond-example",
"match": "prefix",
"target": "path",
"pattern": "/Users/me/work/",
"presetId": "standard"
}
]
}
| Field | Value | Description |
|---|---|---|
version |
1 |
Only version 1 is supported |
enabled |
boolean | Global toggle |
mode |
aggressive / fallback |
Execution mode; defaults to aggressive |
conditions[].match |
exact / prefix / suffix / glob / regex |
Match type |
conditions[].target |
name / path |
Match directory name or full path |
conditions[].pattern |
string | Match pattern |
conditions[].flags |
string | Optional, only used with regex |
conditions[].presetId |
string | Resulting preset on match |
Matching semantics:
- Paths normalize
\to/and strip trailing/; non-regex modes are case-sensitive. Regex uses the configured flags. - Glob patterns support
*(does not cross/),**(crosses/;**/also matches zero directory levels), and?(a single non-/character). All other characters match literally. Use regex for character classes, grouping, or alternation. namerefers to the last directory segment of the full path.
Execution Modes¶
The plugin offers two optional execution modes:
- Prefer Aggressive Mode (default): Wraps
sessionController.createwhen the session creation request enters the Host, rewritingagentPresetbefore DSH resolves it, so the new session uses the target preset from the header onward. - Fallback Mode Only: Does not wrap the Host service; instead, uses the public
agentPresets.selectmethod to switch the preset of a blank session after Agent creation is complete and before the first turn begins.
Both modes share the same condition and preset mapping. Switching execution modes does not require a restart.
Environment Variable Override¶
In addition to the settings page and the mode field in config.json, you can set an environment variable before launching DSH:
DSH_PRESET_WORKSPACE_HOOK_MODE=fallback
Environment variables take precedence over the configuration file, making them suitable for troubleshooting upgrades or verifying the fallback path; DSH_PRESET_WORKSPACE_HOOK_MODE=aggressive can force aggressive mode in the opposite direction. Invalid environment variable values are ignored.
Installation and Activation¶
The plugin is installed via the directory page. The installation command is auto-generated by DSH:
dsh plugin add https://www.skillhub.cn/plugins/hluica/dsh-preset-workspace-hook
After installation, enable the “Workspace Preset Switcher” feature in the DSH settings page to begin configuring conditions and preset mappings.
Typical Usage¶
Suppose a user needs different Agent presets in different directories:
- Enable “Workspace Preset Switcher” on the settings page.
- Select “Prefer Aggressive Mode” under “Execution Mode” (default).
- Add a condition: match path prefix
/Users/me/work/frontend/, use thefrontendpreset. - Add a condition: match path prefix
/Users/me/work/backend/, use thebackendpreset. - Click “Save” to write the configuration to the Host.
When the user creates a new session in /Users/me/work/frontend/, DSH automatically uses the frontend preset; in /Users/me/work/backend/, it uses the backend preset.
Applicable Scenarios and Notes¶
Applicable Scenarios¶
- Multi-workspace projects: The same developer uses different Agent presets in different directories.
- Automated workflows: Automatically apply the correct preset when creating sessions in scripts or CI/CD pipelines.
- Team collaboration: Share preset mapping rules via the configuration file.
Important Notes¶
- The plugin runs with the current DSH process permissions. Review the source code and license before installation.
- Only handles regular top-level sessions; forks, sub-sessions, and sessions with existing turns will not have their presets switched.
- The aggressive mode only covers creation/reuse via
sessionController.create; the fallback mode covers Agent creation for all blank top-level sessions. - Presets referenced in conditions must be available in the current DSH instance. If a preset is deleted or fails to activate, session creation will not fail due to this plugin, but the switch will not occur for that session.
- The configuration is read only by the local current process. Multi-process or external edits rely on mtime caching and take effect on the next session creation/query.
Troubleshooting¶
| Symptom | Resolution |
|---|---|
| No entry on the settings page | Confirm the bundle is enabled and refresh the page; check dsh.client and settings.section registration. |
| Status shows “Awaiting sessionController service” | The Host’s sessionController has not yet been mounted; this typically occurs during early startup. Refresh the settings page later or check /health. |
| Status shows “Aggressive mode unavailable, using fallback mode” | The current DSH’s sessionController.create cannot be wrapped; switch to “Fallback Mode Only” to eliminate ambiguity, or check the version contract. |
| New sessions still use the original preset | Check whether the workspace path matches a condition (use “Query Current Workspace” on the settings page), whether the target preset is available, and whether the global toggle is disabled; check GET /health. |
| Changes have no effect | Was “Save” clicked on the settings page? Are there parsing errors in the config file? Is an environment variable forcing a different mode? |
| Preset list is empty/unavailable | The current DSH does not provide agentPresets, or preset activation failed; check the official “Agent Presets” page and Host logs. |
| Config file corrupted | The settings page will display an error; fix or delete config.json and reload. Saving will overwrite the corrupted file with the page content. |
Summary¶
@local/dsh-preset-workspace-hook provides DSH with the ability to automatically select Agent presets based on workspace paths, supporting flexible condition matching and two execution modes. It is suitable for developers who need to automatically apply preset configurations in multi-workspace scenarios. The plugin is maintained by hluica and is licensed under the MIT License.
More information and source code: GitHub