dsh-tool-archive: Deterministic tar Archiving and Secure Unpacking for Agents

Introduction

In DeepSeek Harness (DSH), models can read and write files, pack directories, and unpack archives via tools. While “unpacking an archive” in a Shell is often just a single line command, for the invoked process, tar member names can be ../../.ssh/authorized_keys, absolute paths, symlinks, or hard links pointing outside the tree—any of which could turn “unpacking” into “writing files to arbitrary paths on the local machine.”

The community plugin dsh-tool-archive (maintained by yuehancn, GitHub: yuehancn/dsh-tool-archive) provides a zero-external-dependency tar reading and writing implementation within the DSH process. When packing, it produces reproducible hashes and manifests; before unpacking, it allows read-only inspection of the manifest; during unpacking, it performs unified validation on paths and member types. It also supports verification without unpacking or by comparing against directories/digests. Directory page: SkillHub - dsh-tool-archive.

What is this

dsh-tool-archive is an archive toolbox plugin for DeepSeek Harness (Category: Model Inference). Instead of calling the system tar, it implements ustar writing and reading of various dialects internally, registering four tools with the Harness: archive_status, archive_pack, archive_unpack, and archive_verify.

Since tar lacks a central index and member names, sizes, and types are scattered across 512-byte block headers, “what’s in the package” usually requires traversing the archive rather than querying a table. This plugin is also designed to support listing contents and reporting formats and constraints without extracting to disk.

What the four tools do

Tool Function
archive_status Reports which tar format is written, which member types are rejected, path conditions, and output destinations
archive_pack Packs a directory into a tar, returning a SHA-256 manifest of each file and a digest of the entire tree
archive_unpack Lists contents or unpacks; rejects absolute paths, .., symlinks, hard links, device nodes, etc.
archive_verify Verifies without unpacking: compares directories against directories, digests against digests

Determinism: Same content tree → Same digest

If uid/gid/mtime, traversal order, etc., are directly included in the hash, the same directory on different machines or with different readdir orders will produce different archives. Manifest comparison would then be unable to distinguish between “content changed” and “just a different environment.”

This plugin adopts fixed rules when packing: members are sorted by path; uid/gid are fixed to 0; file modes are 0644, directories 0755; treeDigest performs SHA-256 on “type + path + size + content hash”. The README explains: the digest and archive bytes for the same content should be consistent across different machines; treeDigest describes the content, so changing permissions will not alter the digest, facilitating cross-machine comparison.

Path Validation and Security Boundaries

All member names that touch the file system are processed via resolveWithin / resolveEntry. Rejected cases include: absolute paths, .. components (including those embedded in the middle), empty after normalization, empty path components, containing NUL, symlinks/hard links, device/FIFO files, unknown type flags, header checksum mismatches, etc.

The implementation emphasizes: before path.resolve, only the last segment of the path is retained to prevent absolute paths on Windows from overwriting the output directory via the second argument; cyclic normalization to a fixed point is required for paths like ././.; names that normalize to safe paths like ./a.txt are allowed.

When unpacking, strict defaults to true: if any member is rejected, the entire operation writes nothing to disk. Reading is more lenient than writing (compatible with various old ustar header layouts), but names too long to fit in pure ustar will cause an error—it does not truncate or use GNU long-name / PAX extensions.

Enabling and Configuration

The quick start in the documentation enables the plugin via a Cordis plugin entry and provides a config field example (installation methods depend on your DSH version and SkillHub / repository instructions; do not construct commands not found in the documentation based solely on the repository name):

- id: tool-archive
  name: dsh-tool-archive
  config:
    workDir: C:/work/project
    archiveDir: C:/work/project/archive-output
    extractDir: C:/work/project/archive-extract

package.json requires dsh >= 0.2.0-rc.2, with peer dependencies @deepseek-ai/cordis ~4.0.4 and @deepseek-ai/dsh-tools >= 0.2.0-rc.2; the plugin version is 1.0.0, licensed under MIT.

Common configuration items (see README for default values):

Key Default Description
workDir . Base path for relative path resolution
archiveDir archive-output Directory for archive reading and writing
extractDir archive-extract Root directory for unpacking
exclude node_modules/.git/.DS_Store/Thumbs.db Skip based on the last segment name
maxFileBytes 0 Single file limit; 0 means unlimited
maxEntries 20000 Warns if exceeded
maxTotalBytes 2 GiB Limit for total unpacked size and memory reading
maxNameBytes 1000 Maximum byte limit for member names
hash true Calculate SHA-256 when packing
noOverwrite false Whether to reject overwriting during unpacking
status/pack/unpack/verify true Enable or disable the four tools respectively

Typical Usage

Given the plugin is registered, the invocation methods are as follows (paths are relative to workDir / configured archive directories, subject to the context in your environment):

// Pack
await archive_pack({ source: "src" })
// → { file, bytes, files, directories, contentBytes, overheadPercent,
//     format: "ustar", treeDigest, manifest: [...], skipped: [] }

// Inspect contents without writing to disk
await archive_unpack({ file: "pack.tar", listOnly: true })

// Unpack (dangerous members will be rejected; strict defaults to true, no writes if any rejection occurs)
await archive_unpack({ file: "pack.tar", dest: "run-1" })

// Verify
await archive_verify({ file: "pack.tar", against: "src" })
// → { ok: true, treeDigest, unchanged: 5, added: [], removed: [], changed: [] }

Run plugin tests locally:

node _test/run-all.mjs

The README claims a total of 636 assertions across four test suites.

Use Cases and Limitations

Suitable for: Scenarios where you need to pack project directories into tars with comparable digests within the DSH workflow, audit manifests before unpacking, perform zip-slip protection against untrusted tars, or verify against source directories.

Important Notes:

  • The plugin runs under the current DSH process privileges; read the source code and MIT license before enabling it to ensure path and limit configurations comply with your security policy.
  • No compression, output is pure .tar; does not resolve symlinks and hard links (intentionally rejected); does not support GNU long-name / PAX, making it unsuitable for packing extremely deep paths.
  • When unpacking on case-insensitive file systems, if the archive contains two names differing only by case, they may overwrite each other; the plugin detects and warns during the planExtraction phase.

The DSH ecosystem emphasizes “everything is a plugin”; community directories like SkillHub are independent sites with no official affiliation with DeepSeek / High-Flyer.

Conclusion

dsh-tool-archive consolidates “packing, manifesting, controlled unpacking, and verification” into a single set of deterministic tar and path guard logic, making it suitable as a default toolbox for model-side archive operations. For further information, please visit the SkillHub Directory Page and the GitHub Repository.

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

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

Xiaoye