dsh-new-workdir: One-click to claim an independent working directory and start a clean session

Introduction

When working on multiple unrelated tasks in DSH, a common practice is to share a single workspace directory. Files generated by Agents, temporary scripts, and intermediate artifacts tend to pile up in the same directory tree. Consequently, subsequent tasks can easily read residual data from previous ones, and it becomes difficult to distinguish at a glance in the sidebar “which folder am I actually working in this time.” Manually creating a new folder each time, registering the workspace in DSH, and starting a new session involves multiple steps and is prone to omission.

dsh-new-workdir is a community plugin maintained by miqian-nomad, categorized under admin-security. It condenses the process of “acquiring a new timestamped directory under a specified root → registering it as a DSH workspace → opening a clean session” into a single click. The directory acts as a sandbox boundary, ensuring that artifacts from different tasks do not contaminate each other by default. Implementation-wise, it does not modify the official DSH source code; instead, it utilizes slot registration, the official Remote API, a loopback HTTP endpoint, and performs an optional wrapper on uiWorkspace.startSession on the client side.

What is this

In one sentence: It creates a timestamped working directory under a configured root with one click, registers it as a DSH workspace, and launches a new session within it.

Core Features

Entry Points

Entry Location Description
Folder+Plus “New Directory” Right of the input box (Left of the model selector) Runs the complete flow with one click, suitable for daily use.
“New Directory Session” Left list on the settings page Performs the same action, and allows configuration of the root directory, number of created items, recent directories, and optional directory names.
New Conversation / ⌘N / Ctrl+Alt+N Top of the sidebar (Official entry) Taken over by default: If no workspace ID exists, it claims a new directory before starting a session.
⊕ on Workspace Row Right side of the sidebar workspace row Maintains official semantics: Starts another session in the current directory (may reuse an existing empty session in that directory).

The top “New Conversation” and the inline ⊕ look similar but have different semantics: The former means “Give me a new place”; the latter means “Open another session right in this directory.”

Flow after clicking

The server and client collaborate roughly in the following order:

POST /api/new-workdir/mkdir          host creates directory under root
GET  /api/new-workdir/state            queries root; switches directly if a reusable empty directory session exists
ctx.workspaces.create({ path })        Official Remote: Register workspace
ctx.sessions.create({ workspaceId })   Official Remote: Create new session
ctx.uiWorkspace.openSession(id)        Switch to that session
POST /api/new-workdir/prune            Prunes confirmed empty directories on disk as needed

The directory name format is YYYY-MM-DD-HH-MM-SS, with an optional suffix -custom-label; the workspace title is displayed as YYYY-MM-DD HH:MM:SS to facilitate recognition in the sidebar.

Rapid clicking does not pile up directories infinitely: It only reuses the one “just created within this page session and not yet sent messages”. After refreshing the page, the in-memory state clears, and clicking again will create a new one. If a custom name is filled in the settings panel, a new directory is forced.

Handling failures: If sessions.create fails, it retries once; if it still fails, it rolls back the workspace registration, deletes the empty directory, and logs a line to new-workdir.err.log. Each step is fail-soft, and the reason will be echoed on the button or in the settings panel.

Takeover of Official “New Session” (Optional)

DSH’s session.new (Top of sidebar / ⌘N) eventually calls uiWorkspace.startSession(). The plugin claims a new directory first when there is no workspace ID; calls with a workspace ID (inline ⊕, workspace selector) still follow official logic.

By setting bridgeNewSession: false (or window.__dshNewWorkdirBridge = false), this layer of wrapping can be turned off, and the official “New Conversation” returns to staying in the current workspace. After turning it off, the plugin’s own two entries (input box chip, settings page card) remain available.

Taking over startSession also affects parameter-less call sites like “New Task” in the task panel; if you need to absolutely avoid side effects on other entries, it is recommended to turn off bridgeNewSession and use only the plugin’s own entries.

Multi-root and Cleanup

In cordis.patch.yml, you can configure root (default root) and roots (additional roots). Directory creation defaults to root; when cleaning up empty directories, it scans every root in the list. If you only change root without writing the old root into roots, directories under the old root remain DSH workspaces but will not be scanned by this plugin’s cleanup.

POST /api/new-workdir/prune only rmdirs empty directories, and requires: The path falls under the configured root after resolve / realpath, the directory name matches the plugin’s timestamp format, readdir is empty, and it is not in the keep list. The client will not initiate a cleanup request when it cannot obtain a workspace/session snapshot, avoiding accidental deletion.

Installation and Enablement

The web profile is managed by the CLI. It is recommended to pin the version by tag:

dsh plugin --profile web add github:miqian-nomad/dsh-new-workdir#v0.4.1

For local development, you can link to the source directory:

dsh plugin --profile web add link:D:/dsh-plugins/dsh-new-workdir

After installation, open the “New Directory Session” settings page and change root to your local working directory root path (the D:/work-harness in the README is just an example).

Desktop profile is not directly installed via dsh plugin; you need to create a junction in ~/.dsh/profiles/desktop/node_modules, register the plugin name in package.json dependencies and dsh.profile.bundles, then restart the desktop client or dsh web. See the repository README for specific commands.

Typical Usage

Configuration Example

Plugin package cordis.patch.yml snippet (Injected via Cordis patch after installation, do not duplicate insert loaders with the same id in the profile’s cordis.patch.yml):

- insert:
    - id: new-workdir
      name: dsh-new-workdir
      config:
        enabled: true          # When false, mkdir returns 403, keeping only read-only display
        root: D:/work-harness  # Main root
        roots:                 # Optional additional roots
          - D:/work-sandbox
          - E:/tmp/workdirs
        # recent: 8            # Number of recent directories to display per root

Fallback order when root is not written: DSH_WORKDIRS environment variable → ~/.dsh/workdirs (No longer hardcoded D:/work-harness since 0.4.0).

Loopback Interface (Same Origin)

The client only requests the following on the DSH webServer:

  • GET /api/new-workdir/state — Query enabled status, root list, counts, and recent directories.
  • POST /api/new-workdir/mkdir — Requires header x-dsh-plugin: new-workdir, body optional name, root.
  • POST /api/new-workdir/prune — Clean up empty directories, body optional paths, keep, sweep.
  • POST /api/new-workdir/log — Client reports logs.

Runtime log: ~/.dsh/logs/new-workdir.log; Error log: new-workdir.err.log.

Scenarios and Notes

Suitable for: DSH users who want “one directory per task”, distinguish workspaces by timestamps in the sidebar, and reduce cross-contamination of Agent artifacts; users who need to partition tasks across multiple disks or multiple root directories.

Security and Permissions: The plugin runs under the DSH process privileges and will create and delete (empty only) directories under the configured roots. You should read the source code and MIT license before installing; the repository README provides descriptions on deletion boundaries, no subprocess execution, loopback-only networking, etc., and has passed the @jieai/dsh-plugin-vet static scan (README records the verdict as clean). enabled: false can disable mkdir/prune with one click, retaining only the read-only status display.

Ecosystem Note: The DSH community plugin directory (such as SkillHub) is an independent site with no official affiliation with DeepSeek / High-Flyer; installation commands are subject to the repository README. Do not concatenate undocumented CLI parameters based on the plugin name yourself.

Conclusion

dsh-new-workdir bundles “New Directory + New Workspace + New Session” into a single operation and uses directory boundaries to isolate task artifacts; you can turn off the takeover of the official “New Conversation” when needed and use only its own entries. See the GitHub README for further configuration and security details.

  • Directory Page: https://www.skillhub.cn/plugins/miqian-nomad/dsh-new-workdir
  • GitHub: https://github.com/miqian-nomad/dsh-new-workdir
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye