본문으로 건너뛰기
S

dsh-question-shield

skyskyskyl/dsh-question-shield

Keeps exploratory questions read-only and blocks unsolicited file creation without busting Prompt Cache.

설치

dsh plugin --profile web add github:skyskyskyl/dsh-question-shield

README

dsh-question-shield

English | 简体中文

Stop your coding agent from refactoring your repo when you're just thinking out loud — and stop it from spawning random helper files you never asked for.


Before vs. After

1. Casual Question -> Accidental Refactor

# Before
you> Would it be better to make handleRequest() async?

agent> Great idea! Making it async right now...
  [edit] src/server.ts (+48 -31)
  [edit] src/router.ts (+22 -14)
  [edit] tests/server.test.ts (+39 -19)
# You only wanted to discuss trade-offs. Now you're running `git checkout .`.
# After (with dsh-question-shield)
you> Would it be better to make handleRequest() async?

agent> Trade-offs to consider before changing handleRequest():
  - Pros: non-blocking I/O under concurrent load, cleaner error propagation.
  - Cons: viral async coloring across 3 callers in router.ts.
  Want me to go ahead and refactor it?
# Zero files touched until you say the word.

2. Bug Fix -> Unsolicited File Sprawl

# Before
you> Fix the timeout bug in src/client.ts

agent> Fixed! Also created a few helper files for you:
  [edit] src/client.ts (+4 -2)
  [write] scripts/verify_timeout_tmp.mjs (NEW)
  [write] TIMEOUT_FIX_NOTES.md (NEW)
# After
you> Fix the timeout bug in src/client.ts

agent>
  [edit] src/client.ts (+4 -2)
  [blocked] write scripts/verify_timeout_tmp.mjs
    [Question Shield] Blocked unsolicited file creation: "scripts/verify_timeout_tmp.mjs".
    The user did not ask to create a new file. Please edit existing files instead, or ask first.

Why it happens

In Speech Act Theory, "Would it be better to refactor this?" and "是不是改成异步会更好?" are Information-seeking / Polar Questions, not Directives. Coding agents trained to be eagerly helpful often collapse that distinction and treat every hypothetical question as an implicit order to start editing files.

dsh-question-shield restores that boundary locally using bilingual regex heuristics, a per-turn read-only lock, and a pre-execution file-creation guard. No extra LLM calls, and no system-prompt edits that bust your Prompt Cache.

(Never thought my linguistics knowledge would actually come in handy here lmao.)


Installation

Install from GitHub into a DSH profile

dsh plugin --profile default add github:skyskyskyl/dsh-question-shield

Note (pnpm >= 10): Git installs run prepare to compile TypeScript. If pnpm blocks the build script on first install, allow dsh-question-shield in your profile's pnpm-workspace.yaml (allowBuilds: { dsh-question-shield: true }) and re-run dsh plugin add.

Or load locally via --patch

git clone https://github.com/skyskyskyl/dsh-question-shield.git
cd dsh-question-shield
pnpm install && pnpm run build

Create a patch file question-shield.patch.yml:

- insert:
    - id: question-shield
      name: /absolute/path/to/dsh-question-shield/lib/index.js

Run DeepSeek Harness with the overlay:

dsh --patch ./question-shield.patch.yml

Configuration

All options are optional with sensible defaults. Override them in your profile's cordis.patch.yml:

- insert:
    - id: question-shield
      name: dsh-question-shield
      config:
        enableQuestionShield: true
        strictReadOnlyOnQuestion: true
        guardUnsolicitedFileCreate: true
        allowCreatePatterns:
          - "**/*.test.ts"
          - "tmp/**"
        customQuestionPatterns:
          - "\\bbrainstorm\\b"
        customDirectivePatterns:
          - "\\bship it\\b"
OptionTypeDefaultDescription
enableQuestionShieldbooleantrueDetect exploratory questions (EN/ZH) and inject a read-only reminder.
strictReadOnlyOnQuestionbooleantrueHard-block file mutation tools during a detected question turn.
guardUnsolicitedFileCreatebooleantrueBlock creating non-existent files unless explicitly requested or named by the user.
allowCreatePatternsstring[][]Glob whitelist (*, **, ?) for paths allowed to be created freely.
customQuestionPatternsstring[][]Extra regex patterns (case-insensitive) treated as exploratory question cues.
customDirectivePatternsstring[][]Extra regex patterns (case-insensitive) that override question detection as directives.

How it works

  1. agent/pre-step hook:
    • Inspects incoming source.kind === 'user' messages in Chinese, English, or mixed text.
    • Distinguishes exploratory questions (是不是..., Would it be better..., ?/?) from polite commands (能不能现在帮我把...改成...?, Can you please refactor...).
    • Appends a short [Question Shield] notice at the end of the current turn's messages without touching the system prompt prefix, so Prompt Cache stays warm.
    • Tracks per-agent turn state in a WeakMap<Agent, TurnState> so follow-up tool steps stay guarded and new directive turns immediately unlock.
  2. tools/pre-execute hook:
    • Intercepts built-in DSH file mutation tools (write, edit, apply_patch, and non-view str_replace_editor commands).
    • During a question turn with strictReadOnlyOnQuestion: true, denies mutations and tells the model to explain trade-offs first.
    • During normal turns with guardUnsolicitedFileCreate: true, checks if the target path does not yet exist on disk; unless the user asked to create a file, directly named the file, or the path matches allowCreatePatterns, the creation is denied.

Development

pnpm install
pnpm run typecheck
pnpm run build
pnpm test

License

MIT

관련 플러그인