dsh-archived-purge: Purge archived sessions and local files in one go

Introduction

The built-in “Archive” feature in DSH only hides sessions from the sidebar: the session log directory, projection cache entries in session_projcache, workspace accounting, and archive marks remain on disk, and there is no bulk deletion entry. To reclaim space, one can only manually find the path for each session and delete it.

The plugin introduced below, dsh-archived-purge (maintainer 5D-artist, category admin-security, license MIT, current version 1.1.0), adds a page in “Settings → Archive Cleanup”: it lists all archived sessions grouped by workspace, supports select all and individual selection, and deletes the selected sessions and their local storage in one go upon confirmation. It performs deletion only and does not change the archiving behavior itself.

Installation

The official installation command is as follows; simply execute it:

dsh plugin --profile desktop add github:5D-artist/dsh-archived-purge

Desktop can also add the plugin by filling in the repository address in “Settings → Plugins → Add Plugin”:

https://github.com/5D-artist/dsh-archived-purge

After installation, refresh the page (the Host usually hotloads, but the browser bundle needs to be reloaded).

Usage Steps

According to the flow in the README, no manual file preparation is required before deletion:

  1. Open “Settings → Archive Cleanup”. The page lists all archived sessions grouped by workspace, displaying the title, last activity time, and occupied volume.
  2. Click “Select All” at the top or check individual rows to see the selected count and total volume in real-time.
  3. Click “Delete Selected”, choose whether to perform a deep cleanup in the popup, and confirm.

Deletion is irreversible. The list will not automatically clean anything; only the selected items after confirmation will be deleted.

Deletion Scope

Item Delete? Description
Session log directory ✅ <DSH_HOME>/sessions/--<cwd>--/<session-id>/
Projection cache entries ✅ <DSH_HOME>/storages/session_projcache/sessions/<session-id>.json
Workspace accounting ✅ Public API Workspace.detachSession
Global archive collection ✅ workspaceRegistry.unarchiveSession
Subagent session logs ✅ Only descendants with origin: 'subagent'
Attachments attachments/v1/objects/ ⚙️ Optional Deleted only when no remaining log references exist
Request graph thumbnail cache ⚙️ Optional cache/attachments/request-images/, can be rebuilt
Workspace files produced by this batch of sessions ⚙️ Manually selected Only recognizes paths marked write / edit / present
Normal sessions forked out ❌ Cascades only based on subagent lineage

Deep Cleanup and Orphan Attachments

Deep cleanup is an optional step added in version 1.1.0. In the deletion dialog, you can check “Unreferenced attachments” and “Request graph thumbnail cache”, and individually check the workspace files produced by this batch of sessions. Attachment storage is content-addressed and immutable; the plugin implements “read then delete”: first read all remaining logs to collect sha256 summaries, then delete the objects; after deleting a single session, the objects it exclusively owns naturally become orphans. The three rules are: do not delete if the read is incomplete, keep new objects within 10 minutes, and never touch index files outside of logs.

Regarding workspace files: only explicitly listed targets write / edit / present in the logs are listed, they must be located within the session cwd, and DSH_HOME, the plugin’s own directory, .git / node_modules are excluded. The server performs a re-scan and verification, and they are not checked by default.

There is also a separate entry “Clean Up Orphan Attachments”: it can be executed without deleting sessions, performing a dry-run to report numbers first, then confirming execution.

Safety Rails and Failure Feedback

  • Running rejection: Uses the Host’s workspace/session-activity waterfall check, rather than “considered running if in memory”. Archiving only hides the session; recently used archived sessions may still reside in ctx.sessions.
  • Batch pre-check: If any target (including subagent descendants) is still running, the entire batch will not be deleted, and the type of work (Chat / Task / Subagent / Scheduled task) will be specified.
  • Delayed accounting for resident sessions: Files can be deleted immediately, but sessions in memory cannot be immediately removed from workspace accounting; otherwise, they will fall into the sidebar “Ungrouped”. Accounting and archive marks are retained until the next startup, finalized by finalizePending(). The page will only prompt: “N sessions’ accounting will be automatically recycled on the next startup.”
  • Entry and path validation: sessionId must match ^[A-Za-z0-9][A-Za-z0-9_-]{0,199}$. POST validates CORS, and the path to be deleted must fall within sessions/ or the projection cache root.
  • No registry rewriting: Both archive collection and workspace accounting are modified via public service methods.
  • Readable failure: When rejected or failed, list sessions and reasons individually, rather than just popping up a single HTTP 400.

Status code conventions for the delete interface: 400 is only used for illegal JSON, 403 only for cross-origin, 405 / 415 for method and Content-Type; “Failed to delete” is a business result, expressed using 200 + ok: false + message.

Host Routes

Method Path Description
GET /plugins/archived-purge/state Archive list (title, workspace, volume, last activity, active / activity / resident)
POST /plugins/archived-purge/delete Delete selected sessions, optional deep cleanup
POST /plugins/archived-purge/scan Read-only dry-run: how many attachments released, cache size, output list
POST /plugins/archived-purge/gc Orphan attachment sweep, only deletes if dryRun: false
POST /plugins/archived-purge/client-error Client mount failure report

Compatibility and Known Limitations

Tested environment: DSH 0.2.1-rc.5 (Desktop, Windows). Requires Host services webServer, workspaceRegistry, sessions, sessionPersistence; storage layout corresponds to DSH 0.2.x v4 session logs, workspace.json schema v2, session_projcache single-record files, attachments/v1/objects. Only Web client (dsh.client.platform = web).

Known limitations:

  • Can only delete sessions in the archive collection; active sessions must be archived first.
  • Attachment GC is a full scan; the more sessions, the longer the time consumed.
  • Attachment objects within the 10-minute grace period will not be reclaimed.
  • Accounting for resident sessions is reclaimed on the next startup (DSH does not have a public interface allowing third-party plugins to evict sessions from ctx.sessions).
  • Workspace artifacts only recognize explicit paths marked write / edit / present; files produced by commands like pwsh / ffmpeg are not in the list.
  • The archive time is not a persistent field; the list uses the last activity time for sorting.

Use Cases and Notes

Suitable for developers with long-term accumulated sessions, full disk space occupied by archived logs, and a need for batch recycling. The plugin performs real deletion of local files and executes with the permissions of the current DSH process. Before installation, check the source code and license (MIT), and confirm that the target DSH version satisfies engines.dsh (>=0.2.1-rc.0).

Source code and maintenance instructions are at https://github.com/5D-artist/dsh-archived-purge; the community directory page is at https://www.skillhub.cn/plugins/5D-artist/dsh-archived-purge. This directory is an independent site and has no official affiliation with DeepSeek / Huafan.

羽毛球分组比赛记分
小程序二维码

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

Xiaoye