mpt-workflow 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,94 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.7.1] - 2026-11-25
11
+
12
+ ### Fixed
13
+
14
+ - CLI boolean flags are parsed strictly: `--apply false` / `--apply=false` no
15
+ longer delete, and a non-boolean value exits non-zero. `--key=value` is
16
+ supported.
17
+ - `gc --apply` reports deletion failures and exits non-zero instead of claiming
18
+ success.
19
+ - `next` surfaces blocking questions addressed to PLAN.
20
+ - `active_repo` is enforced for claim/complete/evidence/accept/reject.
21
+ - Agent-supplied message idempotency keys are namespaced by sender, so they
22
+ cannot suppress workflow notifications.
23
+ - `init --no-adopt` excludes generated `.mcp.json` / `.claude` files in repos.
24
+ - SessionStart now names the real tool `ask` instead of `question_ask`.
25
+
26
+ ## [0.7.0] - 2026-11-25
27
+
28
+ ### Fixed
29
+
30
+ - **Release pipeline.** `npm publish` is idempotent (a re-run skips an existing
31
+ version and still creates the GitHub release); prerelease tags use the `next`
32
+ dist-tag; the release gate now runs test typecheck, lint, coverage, version
33
+ sync and `npm pack --dry-run`; checkout no longer persists credentials and
34
+ publish uses `--ignore-scripts` so the npm token is not exposed to lifecycle
35
+ scripts.
36
+ - **Packaging/docs.** The lockfile uses the canonical npm registry, the npm
37
+ README is English and its cross-document links are absolute, and the
38
+ CONTRIBUTING/platform/support-scope docs match the actual Node/CI/platform
39
+ matrix. Tests are typechecked in CI.
40
+ - **Dashboard refresh.** Auto-refresh no longer steals focus; it aborts the
41
+ render if typing starts while requests are in flight, queues reloads instead
42
+ of dropping them, isolates doctor/events failures, and keeps the open
43
+ milestone/filters usable.
44
+ - **Dashboard feedback.** Write failures appear in a fixed toast (not a hidden
45
+ form or an off-screen banner); stale approvals are flagged and cannot be
46
+ approved; blocking messages are always merged into the list even past the
47
+ 100-message cap; repos can be activated from their card.
48
+ - **Dashboard access.** `localStorage` failures no longer blank the page;
49
+ question/message controls have labels and expanded states; low-contrast
50
+ muted/serious tokens were darkened; copied session commands are shell-quoted.
51
+ - **Acceptance gate.** `milestone_accept` now requires the latest evidence entry
52
+ to pass; an older success can no longer hide a newer failing command.
53
+ - **Commit scope and approvals.** The commit uses the accepted milestone's TODO
54
+ (not the next implementation milestone), `commit_request` stages the tree and
55
+ records a staged hash, `approve` refuses a stale worktree, and `commit`
56
+ re-checks the staged content. The dashboard marks stale approvals and disables
57
+ the approve button.
58
+ - **Concurrency.** Question-board writes, TODO transitions and evidence writes
59
+ take directory locks; config mutations reload the file before saving.
60
+ - **Parsing.** Bare `受验 SHA` values, `**改什么**` file lists and `**/` / `?`
61
+ globs are parsed correctly; the claim notification no longer collides after a
62
+ rework loop; status lines with annotations are replaced cleanly.
63
+ - `next` now offers the pending commit after acceptance instead of skipping to
64
+ the next milestone.
65
+ - **Permission boundary.** MCP seeds the session role from `WF_ROLE`/`WF_REPO`
66
+ and refuses state changes until `bootstrap`; `plan`/`todo` are repo-bound in
67
+ MCP and in the hooks; hooks fail closed on invalid roles, malformed config and
68
+ malformed hook input.
69
+ - Agent Bash `git commit` / `git push` (including `-C`, `-c`, `--git-dir`) and
70
+ `mpt-workflow approve|commit` are refused. `.claude/**`, `.mcp.json`,
71
+ `.workflow/runtime/**`, `.git/**` and the question board are denied to agent
72
+ roles, so the enforcement plane cannot be edited through the guarded path.
73
+ - Approval and message ids are validated before touching the filesystem; the
74
+ dashboard compares the exact `host:port` Origin and resolves symlinks before
75
+ repo/public-directory containment checks.
76
+ - `init` repairs stale MCP/hook CLI paths instead of leaving `doctor`'s
77
+ `stale-cli` warning unfixable.
78
+
79
+ ### Changed
80
+
81
+ - Tooling: Biome 2 now formats and lints `src/`, `tests/`, `scripts/` and the
82
+ JSON configs (`npm run lint` in CI). TypeScript is on 7.x; GitHub Actions
83
+ checkout/setup-node are on v7, upload-artifact on v7 and action-gh-release on
84
+ v3. `@types/node` stays on 22 and jsdom on 29 to match the advertised Node
85
+ >=22 runtime (jsdom 30+ needs Node 22.22.2); c8 stays on 10 (c8 12 needs Node
86
+ 22.12).
87
+ - Documented the support scope: Chinese-first runtime, dashboard and MCP tool
88
+ descriptions; Claude Code is the only supported client. Other MCP clients and
89
+ a full locale layer are demand-driven.
90
+
91
+ ### Added
92
+
93
+ - Runnable [examples](examples/) for a minimal repo, a multi-repo program with
94
+ the serial `active_repo` lock, and a Rust crate with `cargo test` evidence.
95
+ - [docs/troubleshooting.md](docs/troubleshooting.md) covering ACL/hooks,
96
+ blocking messages, commit refusals, evidence, dashboard access and `gc`.
97
+
10
98
  ## [0.6.0] - 2026-11-25
11
99
 
12
100
  ### Added
@@ -147,7 +235,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
147
235
  timeline.
148
236
  - 16 tests.
149
237
 
150
- [Unreleased]: https://github.com/Ye-Yu-Mo/mpt-workflow/compare/v0.6.0...HEAD
238
+ [Unreleased]: https://github.com/Ye-Yu-Mo/mpt-workflow/compare/v0.7.1...HEAD
239
+ [0.7.1]: https://github.com/Ye-Yu-Mo/mpt-workflow/compare/v0.7.0...v0.7.1
240
+ [0.7.0]: https://github.com/Ye-Yu-Mo/mpt-workflow/compare/v0.6.0...v0.7.0
151
241
  [0.6.0]: https://github.com/Ye-Yu-Mo/mpt-workflow/compare/v0.5.0...v0.6.0
152
242
  [0.5.0]: https://github.com/Ye-Yu-Mo/mpt-workflow/compare/v0.4.0...v0.5.0
153
243
  [0.4.0]: https://github.com/Ye-Yu-Mo/mpt-workflow/compare/v0.3.0...v0.4.0
package/README.md CHANGED
@@ -3,18 +3,29 @@
3
3
  **A local MCP server, CLI and dashboard that turn a multi-agent, multi-repo
4
4
  PLAN → TODO → implement → accept → commit workflow into an enforceable state machine.**
5
5
 
6
- [中文](README.zh-CN.md)
6
+ [中文](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/README.zh-CN.md)
7
7
 
8
8
  [![CI](https://github.com/Ye-Yu-Mo/mpt-workflow/actions/workflows/ci.yml/badge.svg)](https://github.com/Ye-Yu-Mo/mpt-workflow/actions/workflows/ci.yml)
9
9
  [![npm](https://img.shields.io/npm/v/mpt-workflow.svg)](https://www.npmjs.com/package/mpt-workflow)
10
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
10
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/LICENSE)
11
11
  [![Node](https://img.shields.io/badge/node-%3E%3D22-brightgreen.svg)](package.json)
12
12
 
13
- > Status: pre-1.0. See [ROADMAP.md](ROADMAP.md) for the current release and
13
+ > Status: pre-1.0. See [ROADMAP.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/ROADMAP.md) for the current release and
14
14
  > next steps.
15
15
 
16
16
  ---
17
17
 
18
+ ## Try it in 60 seconds
19
+
20
+ ```bash
21
+ npx mpt-workflow demo
22
+ # prints a disposable workspace; then run the printed command:
23
+ npx mpt-workflow web --root <printed path> --port 7788
24
+ ```
25
+
26
+ The demo creates everything under `$TMPDIR`; nothing outside it is touched.
27
+ Larger, checked-in workspaces live in [examples/](https://github.com/Ye-Yu-Mo/mpt-workflow/tree/main/examples/).
28
+
18
29
  ## Why
19
30
 
20
31
  Running several Claude Code sessions against several git repos looks fine until
@@ -76,9 +87,24 @@ Three principles:
76
87
  - Node.js **22+** (Node 20 reached end-of-life in April 2026)
77
88
  - git
78
89
  - macOS, Linux, or WSL2. Native Windows is not supported yet — see
79
- [docs/platform-support.md](docs/platform-support.md).
80
- - [Claude Code](https://claude.com/claude-code) (for the MCP server and hooks;
81
- the CLI and dashboard work without it)
90
+ [docs/platform-support.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/docs/platform-support.md).
91
+ - [Claude Code](https://claude.com/claude-code) — the supported MCP client and
92
+ hook host. Other MCP stdio clients can connect, but hook-based enforcement is
93
+ Claude Code-specific.
94
+
95
+ ## Language and clients
96
+
97
+ This project is **Chinese-first**: CLI output, the dashboard, MCP tool
98
+ descriptions and server instructions are Chinese. The English README is for
99
+ discovery. We do not ship half-translations; a full locale layer is a
100
+ demand-driven, post-1.0 option.
101
+
102
+ **Claude Code is the supported client.** It provides the `PreToolUse` /
103
+ `SessionStart` hooks that enforce the role ACL and commit gate. Other MCP stdio
104
+ clients are not documented yet: without those hooks, only the MCP tools and the
105
+ git pre-commit hook enforce anything. See
106
+ [docs/support-scope.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/docs/support-scope.md) for the reasoning and what would
107
+ change it.
82
108
 
83
109
  ## Install
84
110
 
@@ -127,6 +153,17 @@ mpt-workflow web --root /path/to/workspace --port 7788
127
153
 
128
154
  Every command also works as `npx mpt-workflow <command>`.
129
155
 
156
+ ## Examples
157
+
158
+ | Example | Shows |
159
+ |---|---|
160
+ | [examples/minimal](https://github.com/Ye-Yu-Mo/mpt-workflow/tree/main/examples/minimal/) | One repo, two milestones, a question board |
161
+ | [examples/multi-repo](https://github.com/Ye-Yu-Mo/mpt-workflow/tree/main/examples/multi-repo/) | Serial `active_repo` lock and umbrella contract docs |
162
+ | [examples/rust](https://github.com/Ye-Yu-Mo/mpt-workflow/tree/main/examples/rust/) | `cargo test` evidence and the Cargo ACL entries |
163
+
164
+ They are parsed by `tests/examples.test.ts`, so the checked-in Markdown cannot
165
+ silently rot.
166
+
130
167
  Want to see it work first? `mpt-workflow demo` builds a throwaway workspace,
131
168
  adopts it, prints status and sends a message. Nothing outside `$TMPDIR` is
132
169
  touched. From a source checkout, `./scripts/demo.sh` does the same.
@@ -185,14 +222,17 @@ based on derived state.
185
222
  agent: commit_request(message="feat: ...")
186
223
  → scope check, returns a one-shot approval id
187
224
  user: approve in the dashboard, or `mpt-workflow approve ap-xxx`
188
- agent: commit(approval="ap-xxx")
225
+ agent: commit(approval="ap-xxx") (MCP tool)
189
226
  → refuses if the working tree changed since approval
190
227
  → local git commit only; push is always manual
191
228
  ```
192
229
 
193
230
  The approval is a **guardrail against mistakes**, not an authorization system:
194
231
  the server runs as your OS user. It exists so a human sees the diff before it
195
- lands. `git push` is blocked for agents by the hook.
232
+ lands. `commit_request` stages the tree to bind the approval to exactly that
233
+ content; the MCP `commit` re-checks the staged hash. Agent Bash calls to
234
+ `git commit` / `git push` (and `mpt-workflow approve|commit`) are refused by the
235
+ hook; commits go through the MCP tool, and the human pushes.
196
236
 
197
237
  ## Messaging and notifications
198
238
 
@@ -239,14 +279,17 @@ mpt-workflow watch --role main
239
279
  adopt the recommendation, or copy a relay message
240
280
  - message panel with read/ack and **未读 / blocking / 全部** filters
241
281
  - pending commit approvals with a **diff review** (file list, stat, unified
242
- diff) before you approve
282
+ diff) before you approve; a changed worktree is flagged and approval is
283
+ disabled
243
284
  - copyable agent session command (`WF_ROLE=… WF_REPO=… claude`) for each next
244
- action
285
+ action, and a **设为 active** control on each repo card
245
286
  - environment checks and an event timeline
287
+ - inline write errors (a fixed toast), so a failed ack/answer/approve is visible
246
288
 
247
289
  The dashboard auto-refreshes every 15 seconds, but **pauses while you are
248
290
  typing or reviewing a milestone**, preserves drafts and the open milestone
249
- detail, and shows a retry banner if the API fails.
291
+ detail, restores focus after a refresh, and shows a retry banner if the API
292
+ fails.
250
293
 
251
294
  The only write actions are: answer/close a question, approve a commit, ack a
252
295
  message, switch the active repo.
@@ -302,7 +345,7 @@ as "no milestones", not an error.
302
345
 
303
346
  ## Safety model
304
347
 
305
- Read [SECURITY.md](SECURITY.md) before running this on a shared machine.
348
+ Read [SECURITY.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/SECURITY.md) before running this on a shared machine.
306
349
 
307
350
  - `evidence_run` executes arbitrary shell commands **as your user**, by design.
308
351
  It has the same trust level as your terminal.
@@ -319,7 +362,7 @@ src/core/ parsing, state machine, ACL, git, evidence, approvals, messages
319
362
  src/mcp/ MCP server (25 tools)
320
363
  src/web/ HTTP API + single-page dashboard
321
364
  src/cli.ts init / status / doctor / web / mcp / hook / inbox / send ...
322
- tests/ node:test suites (44 tests, incl. a real MCP stdio round-trip)
365
+ tests/ node:test suites (72 tests, incl. real examples + MCP stdio)
323
366
  docs/ architecture and requirement notes
324
367
  ```
325
368
 
@@ -327,13 +370,17 @@ docs/ architecture and requirement notes
327
370
 
328
371
  ```bash
329
372
  npm run typecheck # tsc --noEmit
330
- npm test # runs the 44 tests via tsx
373
+ npm run typecheck:tests # typecheck the test suite too
374
+ npm run lint # Biome: formatting + lint
375
+ npm run format # Biome: write safe fixes
376
+ npm test # runs the 72 tests via tsx
331
377
  npm run build # tsc + copies the dashboard assets into dist/
332
378
  ```
333
379
 
334
- See [CONTRIBUTING.md](CONTRIBUTING.md) for the full workflow, and
335
- [docs/architecture.md](docs/architecture.md) for the design rationale.
380
+ See [CONTRIBUTING.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/CONTRIBUTING.md) for the full workflow, and
381
+ [docs/architecture.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/docs/architecture.md) for the design rationale.
382
+ Stuck? See [docs/troubleshooting.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/docs/troubleshooting.md).
336
383
 
337
384
  ## License
338
385
 
339
- [MIT](LICENSE)
386
+ [MIT](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/LICENSE)
package/README.zh-CN.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # mpt-workflow
2
2
 
3
- [English](README.md)
3
+ [English](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/README.md)
4
4
 
5
- > 状态:pre-1.0。当前版本与下一步见 [ROADMAP.md](ROADMAP.md)。
5
+ > 状态:pre-1.0。当前版本与下一步见 [ROADMAP.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/ROADMAP.md)。
6
6
 
7
7
  多 agent、多仓开发的**流程状态机**:一个本地 MCP server + 一个只读看板。
8
8
 
@@ -43,6 +43,9 @@ mpt-workflow web --root /path/to/workspace --port 7788
43
43
 
44
44
  源码 checkout 也可以用 `./scripts/demo.sh` 走同样的流程。
45
45
 
46
+ 更多可复制的工作区见 [examples/](https://github.com/Ye-Yu-Mo/mpt-workflow/tree/main/examples/)(minimal / multi-repo / rust);
47
+ 遇到问题先看 [docs/troubleshooting.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/docs/troubleshooting.md)。
48
+
46
49
  `init` 会做这些事(全部幂等,已存在的文件不覆盖):
47
50
 
48
51
  | 产物 | 作用 |
@@ -161,7 +164,8 @@ agent: commit(approval="ap-xxx")
161
164
  → 只做本地 git commit,永不 push
162
165
  ```
163
166
 
164
- - `git push` 一律由用户手工执行;agent 调 Bash 会被 hook 拒绝。
167
+ - Bash 的 `git commit` / `git push` 以及 `mpt-workflow approve|commit` 都会被 hook 拒绝;
168
+ agent 只能走 MCP `commit`,push 由用户手工执行。
165
169
  - 审批是**防误操作**,不是防恶意:同机同用户,agent 理论上能绕过。
166
170
  真正的护栏是 hook + 你 review diff 的习惯。
167
171
 
@@ -208,6 +212,8 @@ agent: commit(approval="ap-xxx")
208
212
  - 顶部:程序进度(hero number)、阻塞问题、进行中的 M、待批准提交、脏工作区。
209
213
  - 左:仓库卡片(里程碑轨道、当前 M、证据)+ 问题收件箱。
210
214
  - 右:下一步、待批准提交、环境体检、时间线。
215
+ - 待批准提交可先看 diff;工作区变化会标记并禁用批准。
216
+ - 自动刷新不会抢输入焦点;写失败用固定 toast 提示;仓库卡片可直接“设为 active”。
211
217
 
212
218
  唯一写操作:回答问题、关闭问题、批准提交、切换 active repo。
213
219
 
@@ -224,6 +230,17 @@ mpt-workflow gc --apply --evidence-days 90 # 同时删除 90 天前的完整
224
230
  证据默认保留,只有显式 `--evidence-days` 才清理(TODO 里仍有截断副本)。
225
231
  `--older-than N` 可以改已处理状态的阈值。
226
232
 
233
+ ## 语言与客户端
234
+
235
+ 本项目**中文优先**:CLI 输出、看板、MCP 工具描述和 server instructions 都是中文;
236
+ 英文 README 用于发现项目。我们不做“只翻译一半”的 UI;完整 locale 层是 1.0 之后
237
+ 按需求决定的事情。
238
+
239
+ **当前只支持 Claude Code**:它提供 `PreToolUse` / `SessionStart` hook,是角色 ACL
240
+ 和提交门禁真正的执行边界。其他 MCP stdio 客户端可以连上,但不在支持范围内;没有
241
+ 这些 hook 时,只有 MCP 工具和 git pre-commit 还有约束力。详见
242
+ [docs/support-scope.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/docs/support-scope.md)。
243
+
227
244
  ## 与现有文档系统的关系
228
245
 
229
246
  - **保留**:伞仓 `docs/` 的调研事实、契约文档、MS-N 快照、`milestone/SKILL.md`。
@@ -232,7 +249,7 @@ mpt-workflow gc --apply --evidence-days 90 # 同时删除 90 天前的完整
232
249
 
233
250
  ## 与设计稿 v0.1 的差异
234
251
 
235
- [docs/design-notes-v0.1.md](docs/design-notes-v0.1.md) 是原始需求稿。实现时有意改了几处,原因见各自条目:
252
+ [docs/design-notes-v0.1.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/docs/design-notes-v0.1.md) 是原始需求稿。实现时有意改了几处,原因见各自条目:
236
253
 
237
254
  | 设计稿 | 这里 | 原因 |
238
255
  |---|---|---|
@@ -258,7 +275,9 @@ mpt-workflow gc --apply --evidence-days 90 # 同时删除 90 天前的完整
258
275
 
259
276
  ```bash
260
277
  npm run typecheck
261
- npm test # 44 个测试(含 MCP stdio 与看板端到端)
278
+ npm run lint # Biome:格式 + lint
279
+ npm run format # Biome:写入安全修复
280
+ npm test # 72 个测试(含示例、MCP stdio 与看板端到端)
262
281
  npm run build
263
282
  ```
264
283
 
@@ -274,12 +293,12 @@ tests/ node:test
274
293
 
275
294
  ## 参与贡献
276
295
 
277
- - 开发环境、测试、加一个 MCP 工具的步骤:[CONTRIBUTING.md](CONTRIBUTING.md)
278
- - 安全模型与漏洞报告:[SECURITY.md](SECURITY.md)
279
- - 行为准则:[CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)
280
- - 变更记录:[CHANGELOG.md](CHANGELOG.md)
281
- - 架构与设计取舍:[docs/architecture.md](docs/architecture.md)
296
+ - 开发环境、测试、加一个 MCP 工具的步骤:[CONTRIBUTING.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/CONTRIBUTING.md)
297
+ - 安全模型与漏洞报告:[SECURITY.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/SECURITY.md)
298
+ - 行为准则:[CODE_OF_CONDUCT.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/CODE_OF_CONDUCT.md)
299
+ - 变更记录:[CHANGELOG.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/CHANGELOG.md)
300
+ - 架构与设计取舍:[docs/architecture.md](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/docs/architecture.md)
282
301
 
283
302
  ## 许可证
284
303
 
285
- [MIT](LICENSE)
304
+ [MIT](https://github.com/Ye-Yu-Mo/mpt-workflow/blob/main/LICENSE)
package/dist/cli.js CHANGED
@@ -1,18 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
  import path from 'node:path';
3
3
  import process from 'node:process';
4
- import { init, formatInitResult } from './core/init.js';
4
+ import { describeAcl } from './core/acl.js';
5
+ import { findRoot } from './core/config.js';
5
6
  import { createDemoWorkspace } from './core/demo.js';
6
- import { runGc, formatGcReport } from './core/gc.js';
7
+ import { formatGcReport, runGc } from './core/gc.js';
8
+ import { readRoleLease, runPreCommit, runPretool, runSessionStart, setRoleLease, } from './core/hooks.js';
9
+ import { formatInitResult, init } from './core/init.js';
10
+ import { formatMessage } from './core/messages.js';
11
+ import { updateQuestion } from './core/questions.js';
12
+ import { withLock } from './core/state.js';
13
+ import { isRole } from './core/types.js';
7
14
  import { Workflow } from './core/workflow.js';
8
- import { VERSION } from './version.js';
9
- import { findRoot } from './core/config.js';
10
- import { runPretool, runSessionStart, runPreCommit, setRoleLease, readRoleLease } from './core/hooks.js';
11
15
  import { runMcpServer } from './mcp/server.js';
16
+ import { VERSION } from './version.js';
12
17
  import { startWebServer } from './web/server.js';
13
- import { describeAcl } from './core/acl.js';
14
- import { updateQuestion } from './core/questions.js';
15
- import { formatMessage } from './core/messages.js';
16
18
  function usage() {
17
19
  return `mpt-workflow — 多 agent / 多仓工作流状态机
18
20
 
@@ -53,19 +55,27 @@ function usage() {
53
55
  function parseArgs(argv) {
54
56
  const positional = [];
55
57
  const flags = {};
58
+ const set = (key, value) => {
59
+ const cur = flags[key];
60
+ if (cur === undefined)
61
+ flags[key] = value;
62
+ else if (Array.isArray(cur))
63
+ cur.push(value);
64
+ else
65
+ flags[key] = [String(cur), value];
66
+ };
56
67
  for (let i = 0; i < argv.length; i++) {
57
68
  const a = argv[i];
58
69
  if (a.startsWith('--')) {
70
+ const eq = a.indexOf('=');
71
+ if (eq !== -1) {
72
+ set(a.slice(2, eq), a.slice(eq + 1));
73
+ continue;
74
+ }
59
75
  const key = a.slice(2);
60
76
  const next = argv[i + 1];
61
77
  if (next !== undefined && !next.startsWith('--')) {
62
- const cur = flags[key];
63
- if (cur === undefined)
64
- flags[key] = next;
65
- else if (Array.isArray(cur))
66
- cur.push(next);
67
- else
68
- flags[key] = [String(cur), next];
78
+ set(key, next);
69
79
  i++;
70
80
  }
71
81
  else {
@@ -78,6 +88,21 @@ function parseArgs(argv) {
78
88
  }
79
89
  return { positional, flags };
80
90
  }
91
+ function boolFlag(flags, name, fallback = false) {
92
+ const v = flags[name];
93
+ if (v === undefined)
94
+ return fallback;
95
+ if (v === true)
96
+ return true;
97
+ if (typeof v === 'string') {
98
+ const s = v.toLowerCase();
99
+ if (['true', '1', 'yes', 'on'].includes(s))
100
+ return true;
101
+ if (['false', '0', 'no', 'off'].includes(s))
102
+ return false;
103
+ }
104
+ throw new Error(`--${name} 只接受布尔值(true/false)`);
105
+ }
81
106
  function resolveWorkflow(flags) {
82
107
  const rootArg = typeof flags.root === 'string' ? flags.root : undefined;
83
108
  const start = rootArg ? path.resolve(rootArg) : process.cwd();
@@ -109,7 +134,11 @@ function printStatus(wf, json) {
109
134
  const m = r.currentMilestone;
110
135
  console.log(`${r.id.padEnd(20)} ${String(done).padStart(2)}/${r.milestones.length} M ` +
111
136
  `[${r.git.branch}@${r.git.shortHead}${r.git.dirty ? ', dirty' : ''}] ` +
112
- (m ? `当前 ${m.id} ${m.status}` : r.milestones.length === 0 ? '无 M(缺 PLAN)' : '全部完成'));
137
+ (m
138
+ ? `当前 ${m.id} ${m.status}`
139
+ : r.milestones.length === 0
140
+ ? '无 M(缺 PLAN)'
141
+ : '全部完成'));
113
142
  for (const mm of r.milestones) {
114
143
  console.log(` ${mm.id} ${mm.status.padEnd(12)} ${mm.title}` +
115
144
  (mm.evidence.length ? ` 证据=${mm.evidence.length}` : ''));
@@ -172,15 +201,15 @@ async function main() {
172
201
  root,
173
202
  program: typeof flags.program === 'string' ? flags.program : undefined,
174
203
  repos,
175
- adopt: flags['no-adopt'] ? false : true,
176
- installHooks: Boolean(flags['install-hooks']),
204
+ adopt: !boolFlag(flags, 'no-adopt'),
205
+ installHooks: boolFlag(flags, 'install-hooks'),
177
206
  });
178
207
  console.log(formatInitResult(res));
179
208
  return;
180
209
  }
181
210
  case 'status': {
182
211
  const wf = resolveWorkflow(flags);
183
- printStatus(wf, Boolean(flags.json));
212
+ printStatus(wf, boolFlag(flags, 'json'));
184
213
  return;
185
214
  }
186
215
  case 'next': {
@@ -218,20 +247,22 @@ async function main() {
218
247
  const report = runGc(wf.root, {
219
248
  olderThanDays: numberFlag('older-than', 30),
220
249
  evidenceDays: numberFlag('evidence-days', 0),
221
- apply: Boolean(flags.apply),
250
+ apply: boolFlag(flags, 'apply'),
222
251
  });
223
- if (flags.json)
252
+ if (boolFlag(flags, 'json'))
224
253
  console.log(JSON.stringify(report, null, 2));
225
254
  else
226
255
  console.log(formatGcReport(report));
256
+ if (report.failed.length)
257
+ process.exitCode = 1;
227
258
  return;
228
259
  }
229
260
  case 'questions': {
230
261
  const wf = resolveWorkflow(flags);
231
262
  let qs = wf.allQuestions();
232
- if (!flags.all)
263
+ if (!boolFlag(flags, 'all'))
233
264
  qs = qs.filter((q) => q.status !== 'closed' && q.status !== 'canceled');
234
- if (flags.json) {
265
+ if (boolFlag(flags, 'json')) {
235
266
  console.log(JSON.stringify(qs, null, 2));
236
267
  return;
237
268
  }
@@ -252,11 +283,11 @@ async function main() {
252
283
  const q = wf.findQuestion(id);
253
284
  if (!q)
254
285
  throw new Error(`找不到 ${id}`);
255
- updateQuestion(q.file, id, {
286
+ withLock(wf.root, 'questions', () => updateQuestion(q.file, id, {
256
287
  status: 'answered',
257
288
  answer,
258
289
  resolution: typeof flags.resolution === 'string' ? flags.resolution : undefined,
259
- });
290
+ }));
260
291
  console.log(`已回答 ${id}。记得回写 PLAN/TODO。`);
261
292
  return;
262
293
  }
@@ -269,11 +300,11 @@ async function main() {
269
300
  wf.msgs.promoteQueued(target);
270
301
  wf.msgs.expireDue();
271
302
  const list = wf.msgs.forActor(target, {
272
- unreadOnly: Boolean(flags.unread),
273
- includeAcked: Boolean(flags.all),
303
+ unreadOnly: boolFlag(flags, 'unread'),
304
+ includeAcked: boolFlag(flags, 'all'),
274
305
  limit: typeof flags.limit === 'string' ? Number(flags.limit) : undefined,
275
306
  });
276
- if (flags.json) {
307
+ if (boolFlag(flags, 'json')) {
277
308
  console.log(JSON.stringify({ unread: wf.msgs.unreadCount(target), messages: list }, null, 2));
278
309
  return;
279
310
  }
@@ -310,11 +341,13 @@ async function main() {
310
341
  const wf = resolveWorkflow(flags);
311
342
  const lease = readRoleLease(wf.root);
312
343
  const fromRole = (flags.from || lease?.role || 'user');
313
- const fromRepo = flags['from-repo'] || (fromRole === 'plan' || fromRole === 'todo' ? lease?.repo : undefined);
344
+ const fromRepo = flags['from-repo'] ||
345
+ (fromRole === 'plan' || fromRole === 'todo' ? lease?.repo : undefined);
314
346
  if (!flags.to)
315
347
  throw new Error('用法: mpt-workflow send --to <main|plan|todo|user> --subject TEXT');
316
348
  const toRole = String(flags.to);
317
- const toRepo = flags['to-repo'] || (toRole === 'plan' || toRole === 'todo' ? lease?.repo : undefined);
349
+ const toRepo = flags['to-repo'] ||
350
+ (toRole === 'plan' || toRole === 'todo' ? lease?.repo : undefined);
318
351
  let refs = {};
319
352
  if (typeof flags.refs === 'string') {
320
353
  try {
@@ -331,7 +364,7 @@ async function main() {
331
364
  subject: String(flags.subject || '(no subject)'),
332
365
  body: typeof flags.body === 'string' ? flags.body : '',
333
366
  refs,
334
- blocking: Boolean(flags.blocking),
367
+ blocking: boolFlag(flags, 'blocking'),
335
368
  idempotency_key: typeof flags['idempotency-key'] === 'string' ? flags['idempotency-key'] : undefined,
336
369
  });
337
370
  console.log(`${duplicate ? '已存在' : '已发送'} ${message.id} → ${toRole}${toRepo ? '@' + toRepo : ''} [${message.status}]`);
@@ -454,7 +487,10 @@ async function main() {
454
487
  return;
455
488
  }
456
489
  case 'acl': {
457
- const role = (positional[1] || 'todo');
490
+ const role = positional[1] || 'todo';
491
+ if (!isRole(role)) {
492
+ throw new Error('用法: mpt-workflow acl <main|plan|todo|user>');
493
+ }
458
494
  console.log(describeAcl(role));
459
495
  return;
460
496
  }