dsh-workflow-zcode
English | 中文
English
A DeepSeek Harness (DSH) plugin that runs ZCode .dwf.ts dynamic workflows: a TypeScript orchestration script fans work out across named, persistent subagents, executes workspace commands inside the host's sandboxed subprocess service, and records every run in a local SQLite journal. The plugin also ships a ZCode-style sidebar panel for observing and controlling runs.
What it actually does
- Compiles and type-checks workflows. A
.dwf.ts file (body + optional front matter declaring arguments) is compiled against a virtual facade, type-checked with TypeScript, and lowered into host calls before execution.
- Persistent named actors.
agent(name, persona) creates a named subagent whose session survives later asks, so context accumulates. await actor.ask<T>(text) returns schema-validated JSON when T is a local interface.
- Sandboxed execution. The workflow body runs in a separate child process with a
node:vm scope. Workspace helpers (world.run, files.*, git.*) are read-oriented and go through the host's subprocess/sandbox services; the plugin does not spawn a shell on its own.
- Durable journal. Runs, actors, nodes, artifacts and events are stored in SQLite at
~/.dsh/zcode-workflow/runs.db (configurable). A failed or cancelled run can be resumed: completed nodes replay from the journal without another model call, and recorded subagent sessions are reattached.
- Real concurrency control.
maxConcurrency caps simultaneous subagent turns (default 13); maxTotalAgents caps the lifetime number of subagents (default 200). Both are per run and can be changed from the panel.
- Pre-execution confirmation gate. When
confirmExecution is 'ask' (default) and the Host exposes userQuestions, compiling/resuming a workflow previews phases, actors, commands and source before asking to: allow once, allow all workflows in the current session, decline, or submit revision feedback (persisted per session in SQLite and revocable from the sidebar panel).
- Optional subagent model.
subagentModel follows the calling session by default, or pins a provider/model.
- Bulk cleanup of finished runs (0.2.4).
pruneRuns reclaims old finished runs — journal rows and artifact snapshots — while never touching a run that is still live. It reports by default and deletes only when asked.
What's new in 0.2.4
pruneRuns on the zcodeWorkflow service. Bulk removal of old finished runs, with a dryRun default of true. See the service contract below.
- One artifact store, one set of path rules. The publisher (which writes snapshots) and the pruner (which deletes them) now share
src/engine/storage.mjs, so they cannot disagree about which directory a run owns. The publisher refuses a run id that would name a directory outside the snapshot root.
- The service version is now
0.2.4. Consumers that pin the contract version should update.
Tools
| Tool |
Purpose |
run_zcode_workflow |
Run a workflow from an inline script or a saved path. Supports args, name, max_total_agents, max_concurrency, subagent_model and dry_run. |
list_zcode_workflows |
List .dwf.ts files visible from the session (project .zcode/workflows and the global ZCode workflow directory), with their declared arguments. |
resume_zcode_workflow |
Resume a failed or cancelled run, reusing completed nodes and recorded subagent sessions. |
Service contract (for other plugins)
The plugin registers a Cordis service named zcodeWorkflow (version 0.2.4). It is an optional capability, not a dependency for the plugin itself: the sidebar, journal and tools work without any consumer. Other plugins (notably dsh-mcp-bridge) discover it with ctx.get('zcodeWorkflow') and never import this package.
| Method |
Purpose |
listRuns({ sessionId?, cwd?, status?, limit? }) |
Compact run rows (status, phase, node counts, spent tokens), scoped when a session or cwd is given. |
getRun({ runId, sessionId, includeScript?, includeTrace?, maxNodes?, maxEvents? }) |
One run's phase, bounded nodes, actors (with subagent sessionId), artifact metadata, error. Script/trace are opt-in. |
progress({ sessionId, limit? }) |
Compact active runs for dsh_wait_session / dsh_get_session summaries. |
cancelRun({ runId, sessionId }) |
Abort exactly one live run; the parent session is untouched. |
resumeRun({ runId, sessionId, allowRehydrate?, maxConcurrency?, subagentModel? }) |
Resume a failed/cancelled run (reuses journal nodes and actor sessions). |
configureRun({ runId, sessionId, maxConcurrency?, subagentModel? }) |
Update plan/caps only. Never starts a run. Completed runs are immutable. |
deleteRun({ runId, sessionId }) |
Remove one settled run and its journal rows. |
pruneRuns({ dryRun?, olderThanMs?, statuses?, maxDelete?, sessionId? }) |
Bulk-remove old finished runs (journal rows + artifact snapshots). See below. |
getSessionPolicy({ sessionId }) / setSessionPolicy({ sessionId, autoApprove }) |
Read/write the workflow auto-execution policy. |
All control methods require the owning sessionId; a run whose parentSessionId differs answers WORKFLOW_FORBIDDEN. Failures carry a stable WORKFLOW_* code. The service is unregistered automatically when the plugin fiber unloads.
pruneRuns — reclaiming old finished runs (0.2.4)
A workflow journal only grows: every run keeps its script, node rows, trace and published artifacts forever. On a machine that runs workflows daily that becomes gigabytes under ~/.dsh/zcode-workflow with no way to reclaim them. pruneRuns is the reclaim, and it is deliberately conservative.
const { dryRun, matchedCount, deletedCount, skippedActiveCount, runs, freedBytes } =
await zcodeWorkflow.pruneRuns({ dryRun: true, olderThanMs: 30 * 24 * 3600 * 1000 })
| Option |
Default |
Meaning |
dryRun |
true |
Report what would be removed; delete nothing. Set false to actually remove. |
olderThanMs |
— |
Only runs whose terminal-state time is older than this many milliseconds. |
statuses |
all finished |
Only these statuses. A non-terminal status is rejected, never silently ignored. |
maxDelete |
no cap |
Maximum number of runs one call may remove. |
sessionId |
all sessions |
Only runs owned by this session. |
The response is { dryRun, matchedCount, deletedCount, skippedActiveCount, runs, skippedRuns?, freedBytes? }. Each entry of runs is { runId, status, sessionId, createdAt, updatedAt, spentTokens, artifactBytes, deleted? }.
Safety rules, in order of importance:
- Only finished runs are removed.
pending and running runs are skipped and counted in skippedActiveCount — they are somebody's live work. A run the host still holds an open controller for is skipped even if its row says completed.
- The default call deletes nothing.
dryRun defaults to true.
- A caller cannot widen the scope by accident.
statuses naming a non-terminal status raises WORKFLOW_BAD_REQUEST instead of being silently dropped.
- Deletion is bounded and deterministic.
maxDelete caps the count, and the oldest runs go first.
- Disk cleanup happens before the row is deleted. If a run's snapshot directory cannot be removed — because the path cannot be proved to be inside the artifact root, or because the disk refused — the journal row is kept, so the run stays visible and the cleanup can be retried instead of leaving orphaned bytes behind.
- Nothing outside the artifact root is ever deleted. A run's snapshots live in exactly one directory,
<artifact root>/<sanitised run id>. Before removal, both the root and the target are resolved through their symlinks and the target must be strictly inside the root.
olderThanMs is measured against the run's terminal-state time (updatedAt), not its creation time.
Sidebar panel
The plugin registers a right-column Workflow tab and a sidebar entry. The panel shows the live run trace: phases and nodes, subagent roster, token usage, artifacts, and run lineage. It supports:
- session / working-directory / all scope filtering (session scope by default);
⚙ 配置 to change maxConcurrency and the subagent model;
↻ 续跑 for failed or cancelled runs;
■ 停止运行 for a live run;
- opening a subagent's own transcript (when the host exposes session navigation).
Requirements
- Node.js >= 22 (
node:sqlite is used for the journal).
- DeepSeek Harness >= 0.2.1-rc.2 < 0.3.0.
- The host must expose the DSH services the plugin uses:
subprocess, agents, sandbox/sandboxPolicy, sessions, workingDirectory, connection (for the panel routes) and slots (client side).
- No other plugin is required.
zcodeWorkflow is provided for consumers; @local/dsh-mcp-bridge may consume it when both are installed.
Install
dsh plugin add dsh-workflow-zcode
Then restart DSH so the host bundle and the client module are loaded, and open Workflow in the right column.
Configuration
All keys are optional; the defaults are shown.
runToolName: run_zcode_workflow
listToolName: list_zcode_workflows
resumeToolName: resume_zcode_workflow
typeCheck: true
confirmExecution: 'ask' # 'ask' | 'never'
maxTotalAgents: 200
maxConcurrency: 13
subagentModel: '' # '' or 'session' follows the calling session
journalFile: '' # '' -> ~/.dsh/zcode-workflow/runs.db
globalWorkflowDir: '' # '' -> ~/.zcode/workflows
projectWorkflowDir: '' # '' -> .zcode/workflows
snapshotDir: '' # '' -> <the journal's directory>/artifacts
snapshotDir is where a run's published artifacts are copied. It is also the deletion boundary for pruneRuns: nothing outside it is ever removed. Leaving it empty keeps it next to the journal file, which is the default ~/.dsh/zcode-workflow/artifacts.
Privacy
The plugin writes only to its local journal (and optionally the configured snapshot directory). It contains no telemetry and makes no network requests of its own; model traffic goes through DSH's Agent service.
Development
node --test test/*.test.mjs
node scripts/prepare-publish.mjs --name dsh-workflow-zcode \
--repository https://github.com/google-q-dot/dsh-workflow-zcode --pack
License
MIT © qiaozhao
中文
这是一个 DeepSeek Harness(DSH)插件,用来运行 ZCode 的 .dwf.ts 动态工作流:TypeScript 编排脚本把任务分发给具名、可续聊的多个子代理,通过宿主的沙箱子进程服务执行工作区命令,并把每次运行记录到本地 SQLite 运行日志。插件同时提供 ZCode 风格的右侧栏面板,用于观察和控制运行。
实际能力
- 编译与类型检查:
.dwf.ts(脚本正文 + 可选 front matter 声明参数)会针对虚拟 facade 编译、用 TypeScript 做类型检查,再降级为宿主调用后执行。
- 持久具名 Actor:
agent(name, persona) 创建具名子代理,会话会持续保留,后续 ask 能继承上下文;await actor.ask<T>(text) 在 T 为本地 interface 时返回经 JSON Schema 校验的对象。
- 沙箱执行:工作流正文在独立子进程 +
node:vm 作用域中运行;world.run、files.*、git.* 等只读/受限能力通过宿主的 subprocess 与 sandbox 服务执行,插件自身不另起 shell。
- 持久运行日志:run、actor、node、artifact 与事件写入 SQLite(默认
~/.dsh/zcode-workflow/runs.db,可配置)。失败或取消的运行可以续跑:已完成的节点直接从日志回放、不再调用模型,记录过的子代理会话会被重新接上。
- 真实并发控制:
maxConcurrency 限制同时进行的子代理轮次(默认 13);maxTotalAgents 限制整个 run 创建的代理总数(默认 200)。两者都是 per-run 设置,并可在面板中修改。
- 执行前确认门禁:默认
confirmExecution: 'ask' 且宿主提供 userQuestions 服务时,编译/续跑前会先展示阶段、子代理、命令、参数与源码预览,供用户选择「允许这一次」「允许本 Session 自动执行」「拒绝执行」或「填写修改意见退回重写」(会话级自动执行持久化于 SQLite,并可在右侧栏面板一键关闭)。
- 可选子代理模型:默认跟随发起会话的模型,也可以固定为某个
provider/model。
- 批量清理已结束的运行(0.2.4):
pruneRuns 可回收旧的已结束运行(journal 行与产物快照),且绝不碰还在进行中的运行。默认只报告不删除,需要显式要求才真正执行。
0.2.4 更新内容
zcodeWorkflow 服务新增 pruneRuns。 批量删除旧的已结束运行,dryRun 默认为 true。详见下方服务契约。
- 产物存储只有一套路径规则。 写入快照的 publisher 与删除快照的 pruner 现在共用
src/engine/storage.mjs,不会对「某个 run 拥有哪个目录」产生分歧;publisher 会拒绝无法落在快照根目录内的 run id。
- 服务版本升到
0.2.4。 固定了契约版本的消费方需要同步更新。
工具
| 工具 |
用途 |
run_zcode_workflow |
用内联 script 或已保存的 path 运行工作流;支持 args、name、max_total_agents、max_concurrency、subagent_model 与 dry_run。 |
list_zcode_workflows |
列出当前会话可见的 .dwf.ts(项目 .zcode/workflows 与全局 ZCode 工作流目录),并返回声明的参数。 |
resume_zcode_workflow |
续跑失败或取消的运行,复用已完成节点与已记录的子代理会话。 |
服务契约(供其他插件使用)