dsh-gated-workflow: Agent Workflow State Machine Plugin with Program-Level Gating

Introduction

The design philosophy of DeepSeek Harness (DSH) is “everything is a plugin.” For agent developers, an Agent’s output often lacks control and auditability: it can plow through an entire task in one go, and you can only rubber-stamp it afterward; you say “give me a plan before you start,” and the next turn it forgets; what was supposed to be step-by-step execution turns into “run it all at once, then pray”; when something goes wrong and you want to trace accountability, all you have is a paragraph buried in the chat log.

dsh-gated-workflow is a plugin for the DSH desktop edition. It makes “session = workflow unit” a reality by combining a four-state state machine (Discussion → Implementation → Acceptance) with program-level gates, so that every step is decided by code rather than the model’s self-discipline. You can’t write files during Discussion, you can’t go beyond the declared scope during Implementation, and the ✓ in Acceptance can’t be stamped without evidence. On top of that, project overviews, decisions, constraints, and pitfalls are distilled into a two-layer handbook (Project Handbook + Session Handbook).

What Is This

  • Plugin Name: dsh-gated-workflow
  • Maintainer: InvisibleZero
  • Version: 0.9.4
  • License: MIT
  • Core Value: Not about making the AI do more work, but making the AI’s work controllable, auditable, and accountable.

It solves the problem of AI output that is uncontrollable and unauditable.

Core Features

Session as a Project Unit (Auto-Claiming)

Open any session and it automatically becomes a workflow node, with a status badge appearing in the input toolbar. Sessions are automatically attributed to the corresponding project (workspace) based on their working directory.

Four-State State Machine + Rework

Discussion ──▶ Implementation ──▶ Acceptance ──▶ Completed
   ▲          ▲          │
   └──────────┴──────────┘  Rework (roll back to a previous stage)
  • Rework is a conditional transition: during Implementation you can roll back to Discussion (the plan needs revision); during Acceptance you can roll back to Implementation (minor fixes) or Discussion (the plan was wrong).

Status Badge in the Session

The status capsule on the right side of the permission controls (e.g., “● Implementing”):

  • Click it → opens the node popup (Session Handbook / Project Handbook / Supplementary Notes / Timeline);
  • The → on the right → advance to the next state;
  • When rework is available, a ↩ appears → choose which stage to roll back to;
  • During Implementation, an “Implementing n/m” capsule also appears — click to see the check-off progress of the implementation order (AI-checked, read-only);
  • After a successful transition, the default input for the new state is filled into the input box (not auto-sent).

Operational Details A / B / C / D (Application-Level Global)

Settings → Gated Workflow:

  • A Common: Shared across all three states; read by every node;
  • B/C/D: Dedicated details + default input for Discussion / Implementation / Acceptance respectively;
  • Hard Rules (read-only, overridable): The “wrap-up” rule in Discussion, the “layered discipline” rule in Implementation, and the “acceptance tools & evidence requirements” rule in Acceptance (filing with ✓/?、no direct checking、round invalidation) are plugin-level hard rules and are not placed in the editable operational details; they are collapsed by default — click “Expand” to see the full text; clicking “Override Hard Rule” triggers a warning first, and the overridden value is marked;
  • Restore Factory Defaults: Resets A/B/C/D to their factory values and clears all hard-rule overrides;
  • Changes auto-save after 700 ms; there is no save button.

Node-Level Supplementary Notes

In the node popup, you can add a supplementary note to a specific session (Global / Discussion / Implementation / Acceptance). It is purely additive and does not override the global settings.

Context Injection by State

Injected via systemPrompt.context(), re-evaluated on every assembly and never written into the chat log. Mounted by layer (order 130–170), not as a single string:

State header (node / workflow / current state / stage boundary)          order=130  Hard layer
【Stage Hard Rules】                                                    order=140  Hard layer
Global Operational Detail A                                             order=145  Hard layer
Current state's B/C/D details                                           order=150  Hard layer
Node supplementary requirements                                         order=155  Soft layer (dropped first)
Project Handbook constraints / red lines (≤300 chars)                   order=160  Soft layer
Tag table (which tags can be selected when writing Project Handbook entries, ≤600 bytes)  order=162  Soft layer (not injected if empty)
Project Handbook path + guidance to "read via file tools when context is needed"  order=165  Soft layer
Session Handbook (full plan + unchecked list + checked item count)     order=170  Hard layer

Hard layers are never trimmed (if the combined size exceeds 8000 bytes, an error is thrown directly rather than silently dropping a rule). Soft layers are dropped by priority from low to high; which layer was dropped, how many bytes each layer consumed, and the remaining budget are all recorded in the event log.

Two-Layer Handbook + Implementation Checklist (AI Self-Maintained)

All handbooks are flat files under .workflow/ in the workspace root:

<your-workspace>/.workflow/
  Project-Handbook.md          ← Project overview / decision log / constraints / pitfalls & guardrails / tag table (one per workspace, persists across sessions)
  Session-Handbook-<node_id>.md ← Plan (bottom-up 4 layers) + implementation order (one per session, AI checks off)
  • During Discussion, the confirmed plan is written into the Session Handbook under “Goal & Acceptance → Data Layer → Domain Layer → Interface Layer → Presentation Layer”; each layer specifies its completion criteria and inter-layer contracts;
  • During Implementation, work proceeds continuously along the “implementation order”: after completing each layer, self-check against that layer’s criteria, use workflow_check to write evidence into the checklist, then move directly to the next layer; the AI only stops to ask a human when the plan has gaps / self-check fails and can’t be self-repaired / work exceeds the plan scope / an irreversible operation is needed / external resources are required;
  • The Project Handbook is written back by each session at wrap-up and serves as shared memory across sessions;
  • If .gitignore exists, a line .workflow/ is automatically appended.

State Timeline

Each state transition is logged (timestamp + from state + to state). In the node popup, you can review how the session progressed step by step to its current state.

Program-Level Constraints: Gate + Tool Gateway

The state machine is a hard constraint, so it doesn’t rely on prompts — it’s enforced through two DSH mechanisms:

  • Write Operation Guard (tools.guard): Evaluated before tool dispatch; if it returns a reason, the call is rejected and the reason is sent back to the model as an error result; during Discussion, host write tools like write / edit / pwsh are blocked;
  • Tool Gateway: The 5 base tools are no longer natively registered; the model only sees workflow_tool_call / workflow_tool_add. The catalog (5 base entries + workspace-specific aliases) is injected into the system prompt.
State Host Write Tools Base Tools via Gateway
Discussion Rejected Available; workflow_check and acceptance-related tools rejected by catalog stage rules
Implementation Allowed All available
Acceptance Allowed All available; workflow_verify_report / workflow_verify_check only usable during Acceptance
Completed Allowed All available (rework requires a reason)

Base tools (names in the catalog):

workflow_advance { to, reason? }        // Request only, no switch: validates prerequisites then waits for you to click "Approve"
workflow_manual  { target, action, section?, content?, tags?, entry?, from?, to? }
  // read / replace_section (Session Handbook "Plan", Project Handbook "Tag Table")
  // append_entry / update_entry / remove_entry (Project Handbook, one entry at a time, tags required)
  // rename_tag { from, to }: merge or rename a tag, cascading updates to all entries referencing it
workflow_check   { item, done, evidence? }  // Check off an existing item in "Implementation Order"; checking requires evidence (how verified + result)
workflow_verify_report { item, result, summary, anchors, command?, findings? }  // Acceptance filing; anchors must be within the working directory
workflow_verify_check  { item, done=false }  // Can only uncheck; checking can only be done via report

Handbook Writes Are Gated

  • Session Handbook “Plan” ≤1200 chars, entire handbook ≤2000 chars (measured in characters; check-off evidence | Self-check: … is not counted);
  • Project Handbook “Constraints / Red Lines” ≤300 chars;
  • Project Handbook entries must carry tags (- [tag1|tag2] body); new tags are auto-registered in “## Tag Table” (max 30 entries; when full, use rename_tag to merge — merging does not consume quota);
  • Writes exceeding 200 KB / 64 KB are also rejected.

Acceptance Evidence: Viewable & Exportable

The node popup has a new “Acceptance” tab. Each of the seven items displays its re-run command / exit code / findings / most recent checker run. The “Export Acceptance Report” button in the tab writes the evidence chain + state timeline as a markdown file into .workflow/ (can go into git, can be archived).

State Transition Authority Stays with the Human

When the model calls workflow_tool_call({ name: "workflow_advance", args: { to: ... } }), it is only a “request” — after prerequisite validation passes, the badge area shows Requested → Implementing [Approve] [Reject]. The actual transition only happens after you click Approve (timeline records by: agent-request; manual clicks record by: human). A request expires after 5 minutes if unhandled, preventing zombie buttons.

Installation & Activation

# 1. Navigate to your DSH profile (default name is "desktop")
cd ~/.dsh/profiles/desktop

# 2. Install (use DSH's bundled pnpm, or system pnpm)
pnpm add github:InvisibleZero/dsh-gated-workflow#main

Then confirm that in the package.json under that directory, the dsh.profile.bundles array includes "dsh-gated-workflow" (pnpm won’t add this automatically — you need to add it manually):

{
  "dsh": {
    "profile": {
      "bundles": [
        "@deepseek-ai/dsh-base",
        "@deepseek-ai/dsh-web-app",
        "dsh-gated-workflow"
      ]
    }
  }
}
# 1. Build dist first (plugin entry points are dist/host.js and dist/client-bundle.js)
cd <repo-directory>
pnpm install --node-linker=hoisted
pnpm build

# 2. Link into the profile
cd ~/.dsh/profiles/desktop
pnpm add link:<absolute-path-to-repo>

Similarly, add "dsh-gated-workflow" to dsh.profile.bundles.

How Changes Take Effect After Installation

What Changed How to Apply
Host side (dist/host.js, routes, injection logic) Toggle the plugin off then on in the plugin page, or restart DSH
Client side (dist/client-bundle.js, UI) Hard refresh the page with Ctrl+Shift+R
Only changed text in settings Takes effect immediately

Typical Usage

Enabling Gated Workflow Mode

  1. Settings → Agent Presets → Add a “Gated Workflow Mode” preset under “Custom”.
  2. Open a session, switch the mode to “Gated Workflow Mode,” and the plugin takes over the session: the status badge “● Discussion” appears in the input toolbar.

Advancing States & Rework

  • In the “● Implementing” state, the → on the right will request advancing to “Acceptance,” provided the prerequisites are met (e.g., plan written into the handbook, implementation order checked off).
  • If rework is needed, click ↩ to roll back to the previous stage (e.g., from “Acceptance” back to “Implementation” for fixes).

Writing to Session & Project Handbooks

  • During Discussion, use workflow_manual to write the plan into the Session Handbook’s “Plan” section (≤1200 chars).
  • During the Acceptance stage, use workflow_verify_report to file the acceptance result with anchors and commands; the evidence chain is recorded under .workflow/.

Exporting the Acceptance Report

  • In the node popup’s “Acceptance” tab, click “Export Acceptance Report” to write the evidence chain and state timeline as a markdown file into .workflow/, ready for git and archiving.

Applicable Scenarios & Caveats

  • Applicable Scenarios: AI workflows requiring strong control, auditability, and accountability, such as code generation, document writing, multi-step experimental design, etc.
  • Caveat: The plugin runs with the current DSH process’s permissions. Review the source code and license (MIT) before installing.
  • Ecosystem Context: DSH’s philosophy is “everything is a plugin”; the community catalog is an independent site with no official affiliation to DeepSeek / High-Flyer.

Closing

dsh-gated-workflow uses a four-state state machine and program-level gates to make every step of the AI’s output controllable, auditable, and accountable. It doesn’t aim to make the AI do more work — it puts control in human hands and lets the AI work within clear rules and persistent memory. See the plugin catalog page and the GitHub repository for more details.

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

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

Xiaoye