mpt-workflow 0.0.0-stage → 0.4.0

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 ADDED
@@ -0,0 +1,127 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.4.0] - 2026-11-25
11
+
12
+ ### Changed
13
+
14
+ - **Package identity.** The npm package is now `mpt-workflow`; the previous
15
+ name `workflow-mcp` is taken by an unrelated package. Binaries are
16
+ `mpt-workflow` and `mpt` (the generic `wf` alias was dropped). The package is
17
+ no longer `private` and ships a `files` allowlist plus `prepublishOnly`.
18
+ - `committed` is now derived from git instead of being an unmaintained status:
19
+ an accepted milestone whose TODO record is clean counts as committed.
20
+
21
+ ### Fixed
22
+
23
+ - **Data safety.** Mutating reads now use `readTextRequired`; a permission or
24
+ I/O error throws instead of silently returning an empty string that would
25
+ overwrite the user's TODO or questions file.
26
+ - **Commit scope.** `commit_request` and `commit` now refuse changes outside the
27
+ current TODO's declared file list, not just ACL violations.
28
+ - **Evidence placement.** New evidence is inserted into `## 证据记录` rather
29
+ than appended to EOF, so evidence recorded after an acceptance (a rework loop)
30
+ is still parsed.
31
+ - **Dashboard.** Loopback `Host` and same-origin checks close cross-site writes;
32
+ path containment uses `within()`; `/api/files` is limited to workflow
33
+ documents.
34
+ - **Evidence timeout.** Commands run in their own process group, so a timeout
35
+ kills the whole tree instead of leaving orphaned test processes.
36
+ - **Locks.** `withLock` retries briefly instead of failing immediately when
37
+ another session holds the lock.
38
+ - **Pre-commit hook.** Workflow-managed files (`TODO-*.md`,
39
+ `docs/agent-questions.md`, `.mcp.json`, `.claude/**`) are exempt from the
40
+ backstop, so a todo session can commit the milestone it just completed while
41
+ out-of-scope source files are still rejected.
42
+ - **Dev-mode init.** `init` warns (and skips hook installation) when
43
+ `dist/cli.js` does not exist, instead of writing hooks that point at a
44
+ missing file.
45
+
46
+ ### Added
47
+
48
+ - Coverage gate (`npm run test:coverage`, 70% lines/functions/statements, 60%
49
+ branches) and a CI artifact.
50
+ - CodeQL analysis and a tag-driven release workflow with npm provenance.
51
+ - [docs/platform-support.md](docs/platform-support.md) (macOS / Linux / WSL2)
52
+ and [docs/releasing.md](docs/releasing.md).
53
+
54
+ ## [0.3.0] - 2026-11-25
55
+
56
+ ### Added
57
+
58
+ - Protocol-level test that spawns the real MCP server over stdio, lists tools,
59
+ calls `status` and checks role gating on the wire.
60
+
61
+ ### Changed
62
+
63
+ - Require Node.js 22+ (Node 20 reached end-of-life in April 2026). CI now runs
64
+ Node 22 and 24.
65
+ - Upgrade `zod` to v4. The MCP SDK supports both v3 and v4; the full suite,
66
+ including the stdio protocol test, passes on v4.
67
+
68
+ ## [0.2.0] - 2026-11-25
69
+
70
+ ### Added
71
+
72
+ - **Agent messaging.** Persistent, addressed messages between `main`,
73
+ `plan@repo`, `todo@repo`, `user` and `system`, stored as one JSON file per
74
+ message plus an append-only audit log under `.workflow/runtime/messages/`.
75
+ - Message lifecycle `queued → unread → read → acked`, with `expired` and
76
+ `escalated` outcomes. Offline recipients see `queued` until their next
77
+ `bootstrap`/`inbox`.
78
+ - **Automatic notifications** for `ask`/`answer`/`close`,
79
+ `milestone_claim/complete/accept/reject`, `commit_request`, `commit` and
80
+ `phase_activate`.
81
+ - **Blocking messages** gate `milestone_claim/complete/accept/reject` until
82
+ acknowledged; answering a question acks the blocker for its addressee.
83
+ Stale blockers expire after 45 minutes and escalate to `user` and `main`.
84
+ - New MCP tools: `send_message`, `inbox`, `read_message`, `ack_message`,
85
+ `wait_message`, `broadcast`, `presence`, `escalate`.
86
+ - New CLI commands: `inbox`, `read`, `ack`, `send`, `wait`, `watch`, `escalate`,
87
+ `presence`.
88
+ - SessionStart hook now injects unread and blocking messages.
89
+ - Dashboard: unread-messages tile and a message panel with read/ack; question
90
+ answering now notifies the asker.
91
+ - `docs/architecture.md` and `docs/requirements-messaging.md`.
92
+
93
+ ### Changed
94
+
95
+ - `status` and `next` surface unread/blocking messages and prioritise blockers.
96
+ - `bootstrap` registers presence and returns an unread summary.
97
+ - The dashboard web test now starts its own server on an ephemeral port, so it
98
+ runs in CI without a pre-started process.
99
+
100
+ ### Fixed
101
+
102
+ - Empty repositories are reported as "no milestones" instead of "all done".
103
+ - Scope checks ignore workflow-managed files (`TODO-*.md`,
104
+ `docs/agent-questions.md`, `.mcp.json`, `.claude/**`).
105
+
106
+ ## [0.1.0] - 2026-11-24
107
+
108
+ ### Added
109
+
110
+ - Initial release: MCP server, CLI and local dashboard for a multi-agent,
111
+ multi-repo PLAN → TODO → accept → commit workflow.
112
+ - Markdown-derived state for `PLAN.md`, `TODO-Mn.md` and
113
+ `docs/agent-questions.md`; `init --adopt` for existing workspaces.
114
+ - Role model (`main`, `plan`, `todo`, `user`) with path ACLs enforced by
115
+ `PreToolUse` hooks and a git `pre-commit` scope check.
116
+ - 17 MCP tools covering status, questions, milestone transitions, server-side
117
+ evidence (`evidence_run`), scope checks and commit approvals.
118
+ - One-shot commit approvals bound to the working-tree hash; agents cannot push.
119
+ - Dashboard with milestone tracks, question inbox, approvals, doctor and
120
+ timeline.
121
+ - 16 tests.
122
+
123
+ [Unreleased]: https://github.com/Ye-Yu-Mo/mpt-workflow/compare/v0.4.0...HEAD
124
+ [0.4.0]: https://github.com/Ye-Yu-Mo/mpt-workflow/compare/v0.3.0...v0.4.0
125
+ [0.3.0]: https://github.com/Ye-Yu-Mo/mpt-workflow/compare/v0.2.0...v0.3.0
126
+ [0.2.0]: https://github.com/Ye-Yu-Mo/mpt-workflow/compare/v0.1.0...v0.2.0
127
+ [0.1.0]: https://github.com/Ye-Yu-Mo/mpt-workflow/releases/tag/v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ye-Yu-Mo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,307 @@
1
- # Temporary Holding Version
1
+ # mpt-workflow
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **A local MCP server, CLI and dashboard that turn a multi-agent, multi-repo
4
+ PLAN → TODO → implement → accept → commit workflow into an enforceable state machine.**
5
+
6
+ [中文](README.zh-CN.md)
7
+
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
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
10
+ [![Node](https://img.shields.io/badge/node-%3E%3D22-brightgreen.svg)](package.json)
11
+
12
+ > Status: pre-1.0. 0.4.0 is prepared; see [ROADMAP.md](ROADMAP.md).
13
+
14
+ ---
15
+
16
+ ## Why
17
+
18
+ Running several Claude Code sessions against several git repos looks fine until
19
+ it doesn't:
20
+
21
+ - **Nobody knows where the work stands.** A new session has to be told "you are
22
+ the PLAN agent for `my-service`, M3 is accepted, M4 has no TODO yet".
23
+ - **Roles are advisory.** The PLAN agent is told not to edit source. Nothing
24
+ stops it.
25
+ - **The human is the message bus.** You copy a question from the TODO session
26
+ into the PLAN session, then copy the answer back.
27
+ - **"It passes" is unverifiable.** Evidence is typed into a document by the same
28
+ agent that wrote the code.
29
+ - **Commits happen mid-thought.** You wanted to review the diff first.
30
+
31
+ This tool keeps the workflow in Markdown (so it stays reviewable), and adds a
32
+ state layer on top: derived status, role-scoped writes, server-executed
33
+ evidence, one-shot commit approvals, and persistent messaging between agents.
34
+
35
+ ## How it works
36
+
37
+ ```
38
+ ┌─────────────────────────────────────────┐
39
+ PLAN.md / TODO-Mn.md │ mpt-workflow │
40
+ docs/agent-questions │ parse → derive state → gate → notify │
41
+ .workflow/program.yaml │ │ │
42
+ └────────┼────────────┼───────────┼────────┘
43
+ │ │ │
44
+ MCP tools PreToolUse pre-commit
45
+ (Claude) hooks hooks
46
+ │ │ │
47
+ ┌────▼────────────▼───────────▼────┐
48
+ │ Claude Code sessions by role │
49
+ │ main · plan@repo · todo@repo │
50
+ └───────────────┬──────────────────┘
51
+ │
52
+ ┌────────▼─────────┐
53
+ │ localhost:7788 │
54
+ │ dashboard (user) │
55
+ └──────────────────┘
56
+ ```
57
+
58
+ Three principles:
59
+
60
+ 1. **Markdown is the source of truth.** `PLAN.md`, `TODO-Mn.md`,
61
+ `docs/agent-questions.md`, `.workflow/program.yaml` are human-readable and
62
+ git-reviewable. The tool derives state from them; it never invents a second
63
+ database of record.
64
+ 2. **The MCP server is not the enforcement boundary.** Agents edit files with
65
+ `Edit`/`Write`, which never touches MCP. Real enforcement is a
66
+ `PreToolUse` hook (blocks out-of-role writes and `git push`) plus a
67
+ `pre-commit` hook (scope check).
68
+ 3. **The human approves, the machine remembers.** Commits use a one-shot
69
+ approval bound to the exact working-tree hash; messages and status survive
70
+ restarts and new sessions.
71
+
72
+ ## Requirements
73
+
74
+ - Node.js **22+** (Node 20 reached end-of-life in April 2026)
75
+ - git
76
+ - macOS, Linux, or WSL2. Native Windows is not supported yet — see
77
+ [docs/platform-support.md](docs/platform-support.md).
78
+ - [Claude Code](https://claude.com/claude-code) (for the MCP server and hooks;
79
+ the CLI and dashboard work without it)
80
+
81
+ ## Install
82
+
83
+ Source install (the package is not published to npm yet):
84
+
85
+ ```bash
86
+ git clone git@github.com:Ye-Yu-Mo/mpt-workflow.git
87
+ cd mpt-workflow
88
+ npm install
89
+ npm run build
90
+ node dist/cli.js --help
91
+ ```
92
+
93
+ Optionally put it on your `PATH`:
94
+
95
+ ```bash
96
+ npm link # provides `mpt-workflow` and `mpt`
97
+ ```
98
+
99
+ The npm package name is **`mpt-workflow`**. `workflow-mcp` is already taken by
100
+ an unrelated package, so do not install or run that name.
101
+
102
+ ## Quick start
103
+
104
+ ```bash
105
+ # Adopt an existing multi-repo workspace (idempotent; never overwrites files)
106
+ node dist/cli.js init --root /path/to/workspace
107
+
108
+ # Add the enforcement hooks (recommended)
109
+ node dist/cli.js init --root /path/to/workspace --install-hooks
110
+
111
+ # See where things stand
112
+ node dist/cli.js status --root /path/to/workspace
113
+ node dist/cli.js next
114
+
115
+ # Open the dashboard
116
+ node dist/cli.js web --root /path/to/workspace --port 7788
117
+ ```
118
+
119
+ After the first npm release the same commands work as
120
+ `npx mpt-workflow <command>`.
121
+
122
+ Want to see it work first? `./scripts/demo.sh` builds a throwaway workspace,
123
+ adopts it, prints status and sends a message. Nothing outside `$TMPDIR` is touched.
124
+
125
+ `init` writes:
126
+
127
+ | Path | Purpose |
128
+ |---|---|
129
+ | `.workflow/program.yaml` | program, repos, phases, active repo, contracts — **tracked in git** |
130
+ | `.workflow/.gitignore` | keeps `runtime/` out of git |
131
+ | `<root>/.mcp.json`, `<repo>/.mcp.json` | registers the MCP server (excluded via `.git/info/exclude`) |
132
+ | `<repo>/docs/agent-questions.md` | created only if missing |
133
+ | `.claude/settings.json` | only with `--install-hooks` |
134
+ | `.git/hooks/pre-commit` | only with `--install-hooks` |
135
+
136
+ ## Roles
137
+
138
+ | Role | Address | May write | Must not write |
139
+ |---|---|---|---|
140
+ | `main` | `main` | umbrella docs, decisions, `PLAN.md`/`TODO-*.md` | source code, tests, manifests |
141
+ | `plan` | `plan@repo` | repo `PLAN.md`, `TODO-*.md`, `docs/**`, `MS-*/**` | source, manifests, other repos |
142
+ | `todo` | `todo@repo` | anything in the bound repo | `PLAN.md`, `TODO-*.md`, umbrella |
143
+ | `user` | `user` | everything (final authority) | — |
144
+
145
+ Declare the role per session. **Use environment variables when sessions run
146
+ concurrently** — the on-disk lease is machine-wide:
147
+
148
+ ```bash
149
+ WF_ROLE=plan WF_REPO=my-service claude
150
+ WF_ROLE=todo WF_REPO=my-service claude
151
+ WF_ROLE=main claude
152
+ ```
153
+
154
+ Or call `bootstrap(role="plan", repo="my-service")` as the first tool in the
155
+ session.
156
+
157
+ ## The daily loop
158
+
159
+ ```
160
+ plan writes TODO-M3.md (plain Write)
161
+ todo milestone_claim(M3)
162
+ todo ... code ...
163
+ todo evidence_run("cargo test --workspace --locked")
164
+ todo milestone_complete(M3) → plan gets a message
165
+ plan milestone_accept(M3) → main and user get a message
166
+ user reviews the diff in the dashboard, clicks Approve
167
+ agent commit_request → commit (local only, never pushes)
168
+ ```
169
+
170
+ Every transition is idempotent and recorded. `next` tells each role what to do
171
+ based on derived state.
172
+
173
+ ## Commit safety
174
+
175
+ ```
176
+ agent: commit_request(message="feat: ...")
177
+ → scope check, returns a one-shot approval id
178
+ user: approve in the dashboard, or `mpt-workflow approve ap-xxx`
179
+ agent: commit(approval="ap-xxx")
180
+ → refuses if the working tree changed since approval
181
+ → local git commit only; push is always manual
182
+ ```
183
+
184
+ The approval is a **guardrail against mistakes**, not an authorization system:
185
+ the server runs as your OS user. It exists so a human sees the diff before it
186
+ lands. `git push` is blocked for agents by the hook.
187
+
188
+ ## Messaging and notifications
189
+
190
+ Agents don't need a human relay anymore. Events and messages are persisted,
191
+ queryable and acknowledged:
192
+
193
+ | Event | From → To |
194
+ |---|---|
195
+ | `ask` / `answer` / `close` | question participants |
196
+ | `milestone_claim` / `complete` | `todo@repo → plan@repo` |
197
+ | `milestone_accept` | `plan@repo → main, user` |
198
+ | `milestone_reject` | `plan@repo → todo@repo` |
199
+ | `commit_request` | any → `user` |
200
+ | `commit` | any → `main, user` |
201
+ | `phase_activate` | `main → all plan/todo` |
202
+
203
+ ```bash
204
+ mpt-workflow inbox --role plan --repo my-service --unread
205
+ mpt-workflow read msg-...
206
+ mpt-workflow ack msg-... --note "handled"
207
+ mpt-workflow wait --role plan --repo my-service --timeout 60000
208
+ mpt-workflow watch --role main
209
+ ```
210
+
211
+ - **At-least-once.** A message is a file on disk; a failed wake-up never loses it.
212
+ Offline recipients see `queued`, promoted to `unread` on their next
213
+ `bootstrap`/`inbox`.
214
+ - **Blocking** messages prevent `milestone_claim/complete/accept/reject` until
215
+ acknowledged, and are surfaced first by `next` and by the SessionStart hook.
216
+ - **Expiry.** Blocking messages expire after 45 minutes by default and escalate
217
+ to `user` and `main`.
218
+ - **Send ACL.** `todo@repo → plan@same-repo`; `todo → main` only for `alert`;
219
+ `plan → main`; `plan → todo@same-repo`; `plan → user` only for `alert`;
220
+ `main`, `user` and `system` are unrestricted. Cross-repo traffic goes through
221
+ `main`.
222
+
223
+ ## Dashboard
224
+
225
+ `mpt-workflow web` serves a single-page, local-only dashboard:
226
+
227
+ - program progress, blocking issues, unread messages, in-flight milestones
228
+ - repo cards with a milestone track, evidence and current state
229
+ - question inbox — answer inline (writes back to Markdown, notifies the asker)
230
+ - message panel with read/ack
231
+ - pending commit approvals with a one-click approve
232
+ - environment checks and an event timeline
233
+
234
+ The only write actions are: answer/close a question, approve a commit, ack a
235
+ message, switch the active repo.
236
+
237
+ ## MCP tools
238
+
239
+ | Tool | Roles | Purpose |
240
+ |---|---|---|
241
+ | `bootstrap` | all | declare role, get ACL + unread summary |
242
+ | `status` / `next` / `doctor` | all | state, recommended action, environment checks |
243
+ | `questions` | all | list questions |
244
+ | `ask` / `answer` / `close` | by addressee | question lifecycle |
245
+ | `milestone_claim` / `milestone_complete` | todo, main | start / finish implementation |
246
+ | `evidence_run` | todo, plan, main | execute a command, record exit code + tree oid + output |
247
+ | `milestone_accept` / `milestone_reject` | plan, main | accept with evidence / reject with reason |
248
+ | `scope_check` | all | diff vs declared files and role ACL |
249
+ | `commit_request` / `commit` | all | request approval, commit with it |
250
+ | `phase_activate` | main, user | serial repo lock |
251
+ | `send_message` / `inbox` / `read_message` / `ack_message` | all (ACL) | targeted messages |
252
+ | `wait_message` | all | long-poll for the next message |
253
+ | `broadcast` / `presence` / `escalate` | main / all / all | broadcast, presence, escalation |
254
+
255
+ ## What it reads
256
+
257
+ The parser is deliberately forgiving so existing repos can be adopted without a
258
+ rewrite:
259
+
260
+ - **Milestones** from a `PLAN.md` table (`| M1 | name | ... |`) or headings
261
+ (`### M1 — name`), unioned with `TODO-M*.md` files.
262
+ - **Status** from YAML front matter (`status: implementing`) or a Chinese/English
263
+ marker (`状态:已验收`, `**已验收(...)**`).
264
+ - **Allowed files** from the `**影响文件**` list in each TODO.
265
+ - **Questions** from `## Q-001 [open] to: main` blocks.
266
+ - **Evidence** from a `## 证据记录` section.
267
+
268
+ Empty or missing files degrade gracefully: a repo without a `PLAN.md` shows up
269
+ as "no milestones", not an error.
270
+
271
+ ## Safety model
272
+
273
+ Read [SECURITY.md](SECURITY.md) before running this on a shared machine.
274
+
275
+ - `evidence_run` executes arbitrary shell commands **as your user**, by design.
276
+ It has the same trust level as your terminal.
277
+ - The dashboard binds `127.0.0.1` only and has no authentication.
278
+ - Hooks are guardrails, not a sandbox; `git commit --no-verify` and
279
+ `WF_ALLOW_COMMIT=1` bypass the scope check.
280
+ - Bash-path ACLs only inspect obvious redirects. Use the pre-commit hook as the
281
+ backstop.
282
+
283
+ ## Repository layout
284
+
285
+ ```
286
+ src/core/ parsing, state machine, ACL, git, evidence, approvals, messages
287
+ src/mcp/ MCP server (25 tools)
288
+ src/web/ HTTP API + single-page dashboard
289
+ src/cli.ts init / status / doctor / web / mcp / hook / inbox / send ...
290
+ tests/ node:test suites (37 tests, incl. a real MCP stdio round-trip)
291
+ docs/ architecture and requirement notes
292
+ ```
293
+
294
+ ## Development
295
+
296
+ ```bash
297
+ npm run typecheck # tsc --noEmit
298
+ npm test # runs the 37 tests via tsx
299
+ npm run build # tsc + copies the dashboard assets into dist/
300
+ ```
301
+
302
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the full workflow, and
303
+ [docs/architecture.md](docs/architecture.md) for the design rationale.
304
+
305
+ ## License
306
+
307
+ [MIT](LICENSE)