dsh-auto-observe: Allowing files accessed by bash to pass read-before-write checks

Preface

When running agents to modify code in DeepSeek Harness (DSH), the filesystem observation policy dsh-fs-observation-policy requires the model to read before modifying. An observation is only registered as “observed” via the read tool (including segmented reading), successful write/edit, or reading images. If you use bash to view files via sed -n, awk, cat, python3 - <<PY, etc., it will not be registered.

Models are often more accustomed to using bash when inspecting code. The actual session log cited in the README shows 1186 bash calls versus 114 read calls, where 4 edits were rejected. All rejections occurred on files where “the model had only used bash to view them previously, and the read count was 0.” The content was actually viewed, but the viewing channel didn’t count, leading to repeated occurrences of:

Error: cannot modify "…/index.vue": file has not been read — read the file, then retry

Every time, one has to read again and retry, causing many invalid back-and-forths in long sessions. Below is an introduction to the community plugin @ruaibeite/dsh-auto-observe (maintainer: ruaibeite, SkillHub Category: Memory), which supplements observation records under this constraint to reduce FS_NOT_OBSERVED rejections.

What is this

@ruaibeite/dsh-auto-observe is a DSH host plugin (mounted via cordis.patch.yml) that places a listener before the waterfall for fs/edit-intent / fs/write-intent. When an edit target has no observation record in the policy ledger, and the agent has never used the read tool to read that file, the plugin uses ctx.fs.stat to obtain the real version and emits fs/observed following the practice of the read tool. This prevents the policy from rejecting modifications on the grounds of “unread.”

If dsh-fs-observation-policy is not installed, this plugin merely adds a stat call without changing write semantics. It is often used in combination with @deepseek-ai/dsh-fs-local, @deepseek-ai/dsh-fs-observation-policy, and @deepseek-ai/dsh-tool-fs.

Where the error comes from

The policy requires reading before modifying. The observation registration channels compared with bash exploration are as follows:

Channel Registers Observation?
read tool (including offset/limit) Yes
Successful write / edit Yes
Reading images Yes
bash: sed -n, awk, cat, python3 - <<PY, etc. No

The rejected cases listed in the README all fit the pattern of “read count was 0 before failure, but the file had been read multiple times via bash.”

Core Mechanism

The listener must be registered with prepend: the policy-side listener does not call next(), so if this plugin is placed behind it, it will never be reached. The rules are summarized in three points:

  1. Simultaneously monitor fs/observed to maintain a mirror ledger isomorphic to the policy’s (session object → targetKey). If the target already has a record → do not intervene; pass it back to the waterfall directly. Therefore, the FS_STALE_VERSION protection for when “the file was modified after you read it” is preserved as-is.
  2. When the target has no record, perform a stat to get the real version and emit fs/observed: existing becomes {kind:'present', version}, non-existent becomes {kind:'absent'}. The policy treats this as “just read” and returns a normal version guard.
  3. If it is not a regular file, if session attribution cannot be obtained (actor.agent.session is missing), or if stat throws an error, do not intervene; pass it back as-is.

Costs and Switches

The observation recorded by the plugin is the actual version of the file at this moment, not an assertion that “the model has seen the content”—what is relaxed is the policy’s interpretation of “read.” The model might only know the path exists and has not viewed the body content via read.

  • edit (anchor replacement) is enabled by default: Replacement still requires a verbatim match with the current content; the stale CAS baseline will not be overwritten by this plugin (see point 1 above).
  • write (full file overwrite) is disabled by default: Blind overwriting lacks the fallback of verbatim matching; enabling it requires explicit configuration writes: true, and you must understand that you are giving up the “read before write” layer of protection.
  • Each intervention logs a line by default (related to the log switch) to avoid silent security relaxations.

Contract tests cover the edits, writes, and log switches as well as the prepend registration position.

Known Boundaries

The mirror ledger starts recording from when this plugin is loaded. The normal installation path restarts the Harness, clearing the memory ledger alongside the policy. If the plugin is hot-enabled after some files have already been read, the old records are not in the mirror. The plugin might backfill the current version for these targets, effectively relaxing the staleness check for this instance; restarting the Harness will return to a state consistent with the policy.

Installation and Activation

The plugin runs with the permissions of the current DSH process; please review the GitHub repository source code and MIT license before installing.

Run in the repository directory:

./install.sh                  # Installs to desktop profile (default)
PROFILE_NAME=web ./install.sh # Installs to another profile

Host plugins do not hot-reload like client plugins; you must restart the Harness after installation. To confirm if it is mounted:

dsh --profile desktop --dump-config | grep -A3 fs-auto-observe

The package.json specifies the runtime environment as Node >=20, and the current release version is 0.1.0.

Typical Usage and Verification

This plugin has no standalone CLI “usage example”: after activation, if an agent initiates an edit-intent after exploring only via bash and without calling read, it should no longer be rejected due to FS_NOT_OBSERVED (provided the policy is installed and session attribution is normal).

The repository provides zero-dependency contract tests that replicate the waterfall and policy logic. You can verify locally the baseline rejection, allowing after plugin installation, zero stat when a record exists, and using the old version for CAS in stale scenarios:

node test/contract.mjs

Use Cases and Notes

Suitable for: Harness development scenarios where dsh-fs-observation-policy is already enabled in DSH, and the agent often reads files via bash, leading to occasional “modification rejected because unread” errors.

Not suitable for or requires caution: Teams relying on “must read before write” for full-file overwrite safety should not open writes: true without understanding the risks.

The DSH ecosystem is “everything is a plugin”; the SkillHub plugin directory is a community site and has no official affiliation with DeepSeek / High-Flyer.

Conclusion

dsh-auto-observe targets the gap between “viewed via bash but not registered via read” and the observation policy. While preserving version guards and edit verbatim matching, it reduces repetitive reads and rejection back-and-forths. For further information, visit the directory page skillhub.cn/plugins/ruaibeite/dsh-auto-observe and source code github.com/ruaibeite/dsh-auto-observe.

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

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

Xiaoye