The core design philosophy of DeepSeek Harness (DSH) is “everything is a plugin.” When handling complex tasks, the stability of a model’s tool invocations is often harder to control than the quality of content generation. dsh-behavior-enhancer is a behavior management plugin. It does not intervene with the content generated by the model; instead, it constrains how the model invokes tools (such as invocation discipline, failure convergence, and parallelism control) to improve execution stability for complex tasks. It has complementary responsibilities with dsh-token-optimizer: the former manages behavior, while the latter manages content.

Core Features

This plugin manages tool invocation behavior through four modules:

  • Behavior prompt: Registers a static behavior constraint section (read before write, validate before batching, converge immediately on failure, serialize same-type modifications). It is injected via systemPrompt.section(). This is a soft constraint, and enforced convergence is handled by subsequent modules.
  • Parallel convergence: Monitors tool execution status. If any tool fails (including command-level failures), it lowers the parallel pool cap to 1; after consecutive successes, it restores the user’s original value. Context pressure exceeding a threshold also triggers degradation, with recovery when it drops below 54% (hysteresis recovery). Serial state is persisted across processes.
  • Failure guard: When the same tool reaches the threshold for consecutive failures, it injects a prompt via agent.followup(), guiding the model to confirm the failure reason with the user rather than blindly retrying.
  • Post-write check: For write/edit tools, it performs lightweight syntax parsing after writing (using JSON.parse for JSON, and checking bracket pairing and indentation for YAML/code). On failure, it rolls back from a .bak snapshot and reports to the model. Snapshots are stored in ~/.dsh-memory/files/.

Installation and Configuration

Installation:

dsh plugin --profile web add @zoria-lind/dsh-behavior-enhancer

Configuration:

Enable the plugin in dsh.profile.bundles, and define the parameters for the four modules above in the configuration file. The postWriteCheck configuration section is enabled by default.

- id: behavior-enhancer
  name: '@zoria-lind/dsh-behavior-enhancer'
  config:
    behaviorPrompt:
      enabled: true
      order: -98
      text: |
        ## 工具调用行为纪律(本会话)
        - 先读后写
        - 批量操作前先验证
        - 失败立即收敛
        - 同类修改串行
    parallelConvergence:
      enabled: true
      recoveryThreshold: 3
      complexRatio: 0.6
      minParallel: 1
      defaultParallel: 10
    failureGuard:
      enabled: true
      maxFailures: 2
      followupMessage: '工具 {tool} 已连续失败 {count} 次。请停止重试,向用户说明失败原因并询问下一步。'
    postWriteCheck:
      enabled: true
      writeTools: ['write', 'edit']
      checkExtensions: ['json', 'yaml', 'yml', 'js', 'mjs', 'cjs', 'ts', 'tsx', 'jsx', 'py', 'ps1', 'sh', 'toml', 'xml']
      keepBackups: 5
      askThreshold: 3
      snapshotDir: '~/.dsh-memory/files'
      autoRollback: true

Development and Compatibility

  • Dependencies and runtime: Zero npm dependencies, no external services. Requires Node >= 18.
  • DSH version: Supports baseline DSH 0.1.5-rc.x and later versions. Older versions (≤0.1.4) are no longer supported.
  • Self-check: Run node test/smoke.mjs for a single-process full self-check.

Permissions and Boundaries

  • File permissions: Reads and writes the fixed directory ~/.dsh-memory/files/ to store snapshots. It does not modify Profile configuration or alter the DSH core.
  • Network and commands: No network requests and no execution of child processes.
  • Failure boundaries: All modules are fail-open (if a state file is corrupted, discard it and start over). The constraint section is a soft constraint; enforced convergence is guaranteed by two independent paths: the parallel pool and followup. The parsing in postWriteCheck is heuristic, and rollback restores the pre-write version.

This plugin provides foundational behavior stability assurance for the DSH plugin ecosystem by finely controlling invocation discipline and fault-tolerance mechanisms for tool calls.