dsh-protect-generated-files: Intercepting Agent Adversaries Modifying Lockfiles and Generated Code

Preface

In DeepSeek Harness (DSH), when having agents modify code, there is a common class of operations that “look like they were fixed, but fall apart on the next build or install”: directly changing version numbers in pnpm-lock.yaml, fixing typos in user.pb.go, or “correcting” types in the Prisma-generated client. These changes are often overwritten the next time pnpm install or protoc runs; worse still, the lockfile becomes inconsistent with package.json, and debugging it can eat up most of a day.

Relying on prompts alone is hard to consistently constrain this kind of behavior. The community plugin dsh-protect-generated-files (maintainer acus9345, category admin-security) refuses write / edit calls that target lockfiles and generated files at the tool-call layer, and intercepts attempts to modify files in place via the shell; when refusing, it tells the model which source file should be changed and which regeneration command should be run. Below we introduce its detection logic, installation steps, and configuration highlights.

What Is This

dsh-protect-generated-files is a plugin for DeepSeek Harness: it prevents agents from hand-editing lockfiles and generated code, and tells them how to follow the correct regeneration flow. Source code and documentation are on GitHub, and the directory page is on SkillHub. The license is MIT; the current version in package.json is 0.2.3. The DSH ecosystem emphasizes “everything is a plugin”; the community directory is an independent site with no official affiliation with DeepSeek / High-Flyer.

Core Functions

Intercepting Edit-Type Tool Calls

The plugin refuses write and edit calls targeting protected paths. The refusal message is not merely a bare “no” — it explains why the file should not be hand-edited and offers the alternative approach. The example in the README looks like:

dsh-protect-generated-files blocked this edit to db/query.sql.go: its header says it is
generated (`// Code generated by sqlc. DO NOT EDIT.`). A hand edit will be overwritten
the next time it is regenerated, or leave it out of sync with its source.
Instead: edit the SQL queries/schema and run `sqlc generate`.

Intercepting In-Place File Modification via Shell

Besides file tools, the plugin also monitors behavior that rewrites protected files directly through the shell, such as sed -i, perl -pi, > file, tee file. When DSH executes commands via PowerShell on Windows, it also monitors Set-Content, Add-Content, Out-File, Tee-Object. The config item guardShell defaults to true, and shellTools defaults to including bash and pwsh.

Three Kinds of “Treated as Generated/Locked” Detection

  1. Identify lockfiles by filename
    Including but not limited to: package-lock.json, pnpm-lock.yaml, yarn.lock, bun.lock / bun.lockb, deno.lock, Cargo.lock, go.sum, poetry.lock, uv.lock, pdm.lock, Pipfile.lock, Gemfile.lock, composer.lock, mix.lock, pubspec.lock, Podfile.lock, flake.lock, gradle.lockfile, packages.lock.json, conan.lock. Each kind of lockfile comes with a hint for the corresponding package manager, e.g. changing dependencies via cargo add / cargo update -p <crate>.

  2. Known output paths
    Protobuf outputs (e.g. *.pb.go, *_pb2.py), Dart build_runner outputs, .Designer.cs, minified artifacts and source maps, as well as files under node_modules/, __generated__/, .venv/, site-packages/. Build output directories (dist/, target/, .next/, vendor/, etc.) count only when they sit at the same level as the project manifest (e.g. package.json, Cargo.toml, go.mod), to avoid false positives on source directories named target.

  3. File header declarations
    Before reading a file, it reads the first headerLines lines (default 15), matching comments like Code generated ... DO NOT EDIT, @generated, DO NOT EDIT, auto-generated, This file was generated, <auto-generated> or Generated by <tool>. If the header notes the file is editable (e.g. edit freely, safe to edit), or carries a conditional DO NOT EDIT without ..., it is not treated as generated. “Generated by hand”, “generated by ChatGPT” etc. do not count. Header comments only take effect for existing files; the rules based on name and path also cover new files (a hand-written lockfile should likewise never appear).

If the header comment points to a tool the plugin already recognizes, the hint names the tool and the regeneration method, covering protoc/buf, Prisma, GraphQL Codegen, OpenAPI generators, sqlc, go generate, Drizzle, Alembic, etc.

Allowing When a Hand Edit Is Truly Needed

Merging lockfile conflicts, or making a one-line hotfix to vendored code while waiting on upstream, are situations that still occur. The model can retry with the exact same call to confirm, and that attempt will pass. If you want human approval, set mode to ask. If a directory looks like generated output but is actually hand-maintained, add it to ignore.

Installation and Activation

The official installation command (taking the web profile as an example — the browser UI used by dsh web):

dsh plugin --profile web add dsh-protect-generated-files

If running DSH via scripts or CI, replace --profile web with headless; editor integrations use acp. Each profile maintains an independent plugin list, so add it for every profile you use. After installation, it takes effect on the next tool call. Removal:

dsh plugin --profile web remove dsh-protect-generated-files

When testing plugin changes locally, the README gives the path of building a tarball from a clone and then installing it (requires git clone and npm pack on your own); for everyday use, the above dsh plugin add is sufficient.

Configuration

You can open dsh-protect-generated-files under the Plugins sidebar in DSH, modify it, and click Save; it takes effect on the next tool call, with no restart required.

You can also append a fragment in ~/.dsh/profiles/<profile>/cordis.patch.yml, or the global ~/.dsh/cordis.patch.yml (unwritten keys keep their defaults):

- id: protect-generated-files
  config:
    mode: deny                    # or ask: prompts for approval
    extraGlobs:                   # custom generated paths and hints for the model
      'src/api/client/**': 'edit openapi.yaml and run `npm run gen:api`'
    ignore: ['vendor/**']         # never treated as generated
    defaultGlobs: true            # when false, only lockfiles, header comments and extraGlobs
    headerLines: 15
    guardShell: true
    allowIdenticalRetry: true     # when false, no retry with same args after a refusal
    shellTools: [bash, pwsh]

The README recommends prioritizing extraGlobs, spelling out the regeneration script to avoid the model guessing.

Use Cases and Caveats

Suitable for teams and individuals that frequently have agents modify dependencies, run code generation, or touch multi-language lockfiles in DSH: uniformly block hand-editing of generated artifacts at the agent layer, and steer operations toward “change the source + regenerate”.

Before installing, please review the source code and MIT license of the GitHub repository yourself. The plugin runs with the permissions of the current dsh process, consistent with DSH’s own permission boundary; do not assume, without review, that it covers all the custom generated paths in your repository — uncovered parts should be added via extraGlobs.

Conclusion

dsh-protect-generated-files turns “don’t hand-edit lockfiles and generated code” from a prompt convention into a tool-layer interception, and provides actionable regeneration guidance when refusing. When needed, you can reach the documentation from the SkillHub directory page, or directly consult the GitHub repository for installation and configuration details.

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

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

Xiaoye