clawspec 1.0.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.
Files changed (71) hide show
  1. package/README.md +908 -0
  2. package/README.zh-CN.md +914 -0
  3. package/index.ts +3 -0
  4. package/openclaw.plugin.json +129 -0
  5. package/package.json +52 -0
  6. package/skills/openspec-apply-change.md +146 -0
  7. package/skills/openspec-explore.md +75 -0
  8. package/skills/openspec-propose.md +102 -0
  9. package/src/acp/client.ts +693 -0
  10. package/src/config.ts +220 -0
  11. package/src/control/keywords.ts +72 -0
  12. package/src/dependencies/acpx.ts +221 -0
  13. package/src/dependencies/openspec.ts +148 -0
  14. package/src/execution/session.ts +56 -0
  15. package/src/execution/state.ts +125 -0
  16. package/src/index.ts +179 -0
  17. package/src/memory/store.ts +118 -0
  18. package/src/openspec/cli.ts +279 -0
  19. package/src/openspec/tasks.ts +40 -0
  20. package/src/orchestrator/helpers.ts +312 -0
  21. package/src/orchestrator/service.ts +2971 -0
  22. package/src/planning/journal.ts +118 -0
  23. package/src/rollback/store.ts +173 -0
  24. package/src/state/locks.ts +133 -0
  25. package/src/state/store.ts +527 -0
  26. package/src/types.ts +301 -0
  27. package/src/utils/args.ts +88 -0
  28. package/src/utils/channel-key.ts +66 -0
  29. package/src/utils/env-path.ts +31 -0
  30. package/src/utils/fs.ts +218 -0
  31. package/src/utils/markdown.ts +136 -0
  32. package/src/utils/messages.ts +5 -0
  33. package/src/utils/paths.ts +127 -0
  34. package/src/utils/shell-command.ts +227 -0
  35. package/src/utils/slug.ts +50 -0
  36. package/src/watchers/manager.ts +3042 -0
  37. package/src/watchers/notifier.ts +69 -0
  38. package/src/worker/prompts.ts +484 -0
  39. package/src/worker/skills.ts +52 -0
  40. package/src/workspace/store.ts +140 -0
  41. package/test/acp-client.test.ts +234 -0
  42. package/test/acpx-dependency.test.ts +112 -0
  43. package/test/assistant-journal.test.ts +136 -0
  44. package/test/command-surface.test.ts +23 -0
  45. package/test/config.test.ts +77 -0
  46. package/test/detach-attach.test.ts +98 -0
  47. package/test/file-lock.test.ts +78 -0
  48. package/test/fs-utils.test.ts +22 -0
  49. package/test/helpers/harness.ts +241 -0
  50. package/test/helpers.test.ts +108 -0
  51. package/test/keywords.test.ts +80 -0
  52. package/test/notifier.test.ts +29 -0
  53. package/test/openspec-dependency.test.ts +67 -0
  54. package/test/pause-cancel.test.ts +55 -0
  55. package/test/planning-journal.test.ts +69 -0
  56. package/test/plugin-registration.test.ts +35 -0
  57. package/test/project-memory.test.ts +42 -0
  58. package/test/proposal.test.ts +24 -0
  59. package/test/queue-planning.test.ts +247 -0
  60. package/test/queue-work.test.ts +110 -0
  61. package/test/recovery.test.ts +576 -0
  62. package/test/service-archive.test.ts +82 -0
  63. package/test/shell-command.test.ts +48 -0
  64. package/test/state-store.test.ts +74 -0
  65. package/test/tasks-and-checkpoint.test.ts +60 -0
  66. package/test/use-project.test.ts +19 -0
  67. package/test/watcher-planning.test.ts +504 -0
  68. package/test/watcher-work.test.ts +1741 -0
  69. package/test/worker-command.test.ts +66 -0
  70. package/test/worker-skills.test.ts +12 -0
  71. package/tsconfig.json +25 -0
package/README.md ADDED
@@ -0,0 +1,908 @@
1
+ # ClawSpec
2
+
3
+ [Chinese (Simplified)](./README.zh-CN.md)
4
+
5
+ ClawSpec is an OpenClaw plugin that embeds an OpenSpec workflow directly into chat. It splits project control and execution on purpose:
6
+
7
+ - `/clawspec ...` manages workspace, project, change, and recovery state.
8
+ - `cs-*` chat keywords trigger work inside the active conversation.
9
+ - `cs-plan` runs planning sync in the visible chat turn.
10
+ - `cs-work` runs implementation in the background through a watcher and ACP worker, then reports short progress updates back into chat.
11
+
12
+ The result is an OpenSpec workflow that stays chat-native without hiding long-running implementation work inside the main session.
13
+
14
+ ## At A Glance
15
+
16
+ - Workspace is remembered per chat channel.
17
+ - One active project is tracked per chat channel.
18
+ - One unfinished change is enforced per repo across channels.
19
+ - Discussion messages are recorded into a planning journal while context is attached.
20
+ - `cs-plan` refreshes `proposal.md`, `design.md`, `specs`, and `tasks.md` without implementing code.
21
+ - `cs-work` turns `tasks.md` into background execution, with watcher-driven progress and restart handling.
22
+ - A running ACP worker can survive a gateway restart; ClawSpec will try to reattach to the live session before starting a replacement worker.
23
+ - `/clawspec cancel` restores tracked files from snapshots instead of doing a blanket Git reset.
24
+ - `/clawspec archive` validates and archives the finished OpenSpec change, then clears the active change from chat context.
25
+
26
+ ## Why The Surface Is Split
27
+
28
+ ClawSpec uses two different control surfaces because they solve different problems:
29
+
30
+ | Surface | Examples | What it does | Why it exists |
31
+ | --- | --- | --- | --- |
32
+ | Slash command | `/clawspec use`, `/clawspec proposal`, `/clawspec status` | Direct plugin control, file system setup, state inspection | Fast, deterministic, no agent turn required |
33
+ | Chat keyword | `cs-plan`, `cs-work`, `cs-pause` | Injects workflow context into the current conversation or queues background execution | Keeps planning visible in chat and lets normal chat remain the primary UX |
34
+
35
+ In practice:
36
+
37
+ - Use `/clawspec ...` to set up and manage the project.
38
+ - Use `cs-plan` when you want the current visible agent turn to refresh planning artifacts.
39
+ - Use `cs-work` when you want the watcher to start background implementation.
40
+
41
+ ## Architecture
42
+
43
+ ```mermaid
44
+ flowchart TD
45
+ BOOT[clawspec.bootstrap service]
46
+ BOOT --> DEPS[ensure openspec + acpx]
47
+ BOOT --> STORES[state + memory + workspace stores]
48
+
49
+ U[User In Chat] --> CMD[/clawspec command/]
50
+ U --> KEY[cs-* keyword]
51
+ U --> MSG[ordinary discussion]
52
+
53
+ CMD --> SVC[ClawSpec service]
54
+ KEY --> HOOK[before_prompt_build hook]
55
+ MSG --> INBOUND[message_received hook]
56
+
57
+ INBOUND --> JOURNAL[planning-journal.jsonl]
58
+ HOOK --> SVC
59
+ SVC --> STATE[plugin state store]
60
+ SVC --> WS[workspace store]
61
+ SVC --> MEM[project memory store]
62
+ SVC --> OSCLI[OpenSpec CLI]
63
+
64
+ SVC -->|cs-plan| MAIN[visible chat agent]
65
+ MAIN -->|skills + planning prompt| ARTIFACTS[proposal/design/specs/tasks]
66
+
67
+ SVC -->|cs-work| CTRL[execution-control.json]
68
+ CTRL --> WATCHER[watcher manager]
69
+ WATCHER --> ACPCLIENT[AcpWorkerClient]
70
+ ACPCLIENT --> ACPCLI[direct acpx CLI session]
71
+ ACPCLI --> PROGRESS[worker-progress.jsonl]
72
+ ACPCLI --> RESULT[execution-result.json]
73
+ WATCHER --> NOTIFY[chat progress notifier]
74
+ NOTIFY --> U
75
+
76
+ JOURNAL --> MAIN
77
+ ARTIFACTS --> ACPCLI
78
+ RESULT --> STATE
79
+ PROGRESS --> STATE
80
+ ```
81
+
82
+ ## Current System Architecture
83
+
84
+ ClawSpec is split into six runtime layers.
85
+
86
+ | Layer | Main pieces | Responsibility |
87
+ | --- | --- | --- |
88
+ | Bootstrap | `clawspec.bootstrap`, `ensureOpenSpecCli`, `ensureAcpxCli` | Initializes stores, verifies dependencies, and starts the watcher manager |
89
+ | Control plane | `/clawspec` command, `clawspec-projects`, plugin hooks | Receives user intent, routes commands, and attaches the right chat context |
90
+ | Planning plane | `message_received`, `before_prompt_build`, visible main agent turn | Records requirement discussion and runs `cs-plan` directly in the visible chat |
91
+ | Execution plane | `WatcherManager`, `ExecutionWatcher`, `AcpWorkerClient` | Arms work, starts the background worker, and monitors progress/result files |
92
+ | Recovery plane | startup recovery, restart backoff, session adoption | Re-attaches to live workers after gateway restart or re-arms failed work safely |
93
+ | Persistence plane | OpenClaw state files + repo-local `.openclaw/clawspec` files | Stores project state, journals, progress, rollback baselines, and execution results |
94
+
95
+ Important architectural choices:
96
+
97
+ - Planning is visible. `cs-plan` runs in the main chat turn and does not use a hidden subagent.
98
+ - Implementation is durable. `cs-work` is handed off to a watcher-managed background worker.
99
+ - Worker transport is direct. ClawSpec talks to `acpx` through its own `AcpWorkerClient`, rather than depending on a hidden planning thread.
100
+ - Progress is file-backed. The worker writes progress and result files so the watcher can recover after gateway restarts.
101
+ - Repo safety is explicit. Cancel uses snapshot restore for tracked files instead of blanket repository reset.
102
+
103
+ ## Implementation Strategy
104
+
105
+ ### 1. Bootstrap and dependency discovery
106
+
107
+ When the plugin service starts, it:
108
+
109
+ - initializes the project, memory, and workspace stores
110
+ - ensures `openspec` is available from plugin-local install or `PATH`
111
+ - ensures `acpx` is available from plugin-local install, the OpenClaw builtin ACPX extension, or `PATH`
112
+ - constructs `OpenSpecClient`, `AcpWorkerClient`, `ClawSpecNotifier`, `WatcherManager`, and `ClawSpecService`
113
+
114
+ This means the plugin can bootstrap its own local toolchain on a fresh gateway host without requiring a manually prepared dev environment.
115
+
116
+ ### 2. Command routing and prompt injection
117
+
118
+ ClawSpec uses three hook paths:
119
+
120
+ - `message_received` records planning discussion into the journal when the project is attached
121
+ - `before_prompt_build` injects project, planning, or execution context into the visible chat turn
122
+ - `agent_end` reconciles the end of visible planning turns
123
+
124
+ The `/clawspec` slash command is used for deterministic operations such as workspace selection, project selection, change creation, pause, continue, archive, and cancel.
125
+
126
+ ### 3. Visible planning flow
127
+
128
+ Planning has two modes:
129
+
130
+ - ordinary attached discussion, which only records requirements
131
+ - `cs-plan`, which runs a deliberate planning sync in the visible chat
132
+
133
+ During `cs-plan`, ClawSpec injects:
134
+
135
+ - the active repo and change
136
+ - the planning journal
137
+ - imported OpenSpec skill text from `skills/`
138
+ - strict rules that prevent code implementation or silent change switching
139
+
140
+ The main chat agent then refreshes `proposal.md`, `specs`, `design.md`, and `tasks.md` in the current visible turn.
141
+
142
+ ### 4. Background implementation flow
143
+
144
+ `cs-work` does not implement inside the visible chat turn. Instead it:
145
+
146
+ - verifies that planning is clean enough to execute
147
+ - writes `execution-control.json`
148
+ - arms the watcher for the active channel/project
149
+ - lets the watcher start a direct `acpx` session for the worker
150
+
151
+ The worker reads:
152
+
153
+ - repo-local control files
154
+ - planning artifacts
155
+ - `openspec instructions apply --json`
156
+
157
+ It then works task by task, updates `tasks.md`, writes `execution-result.json`, and appends compact structured events to `worker-progress.jsonl`.
158
+
159
+ ### 5. Progress reporting and replay
160
+
161
+ The watcher is responsible for user-facing progress updates:
162
+
163
+ - it tails `worker-progress.jsonl`
164
+ - translates worker events into short chat updates
165
+ - keeps project task counts and heartbeat state in sync
166
+ - replays missed progress from the last saved offset before sending the final completion message
167
+ - reports startup milestones separately from task milestones, so "worker connected" and "loading context" can appear before the first task starts
168
+
169
+ You should now expect early implementation updates in two layers:
170
+
171
+ - watcher-level status such as "starting worker" and "ACP worker connected"
172
+ - worker-written status such as "Preparing <task>: loading context", "Loaded proposal.md", and "Context ready..."
173
+
174
+ That replay step is important because it prevents the user from missing late task updates if the gateway or watcher was temporarily behind.
175
+
176
+ ### 6. Recovery, restart, and bounded retries
177
+
178
+ On gateway restart, the watcher manager:
179
+
180
+ - scans active projects
181
+ - adopts a still-running worker session if it is alive
182
+ - otherwise re-arms the project for planning or implementation
183
+ - preserves task progress and the worker progress offset
184
+
185
+ Automatic restart recovery is intentionally limited to projects that were actively armed, running, planning, or blocked by a recoverable ACP/runtime failure. A `ready` or `idle` project that is simply waiting for `cs-plan` or `cs-work` is not auto-started.
186
+
187
+ On worker failure, ClawSpec:
188
+
189
+ - distinguishes recoverable ACP failures from real blockers
190
+ - retries recoverable failures with bounded backoff
191
+ - stops retrying after the configured cap and marks the project as `blocked`
192
+
193
+ This keeps `cs-work` resilient without leaving silent zombie work behind.
194
+
195
+ ## What Runs Where
196
+
197
+ | Action | Runtime | Visible to user | Writes |
198
+ | --- | --- | --- | --- |
199
+ | `/clawspec workspace` | Plugin command handler | Immediate command reply | Workspace state |
200
+ | `/clawspec use` | Plugin command handler + `openspec init` if needed | Immediate command reply | Workspace/project selection, OpenSpec init |
201
+ | `/clawspec proposal` | Plugin command handler + `openspec new change` | Immediate command reply | Change scaffold, snapshots, fresh planning state |
202
+ | Ordinary discussion | Main chat agent + prompt injection | Yes | Planning journal, no artifact rewrite |
203
+ | `cs-plan` | Main chat agent in the current visible turn | Yes | Planning artifacts, planning journal snapshot |
204
+ | `cs-work` | Watcher + ACP worker | Progress updates only | Code changes, `tasks.md`, watcher support files |
205
+ | `/clawspec continue` | Plugin decides whether to re-arm planning or implementation | Immediate reply, then either visible planning or background work | Execution state |
206
+
207
+ ## Requirements
208
+
209
+ - A recent OpenClaw build with plugin hooks and ACP runtime support.
210
+ - Node.js `>= 24` on the gateway host.
211
+ - `npm` available on the gateway host if OpenSpec must be bootstrapped automatically.
212
+ - An OpenClaw agent profile that can run shell commands and edit files for visible planning turns.
213
+ - ACP backend `acpx` enabled for background implementation.
214
+
215
+ ClawSpec depends on these OpenClaw hook points:
216
+
217
+ - `message_received`
218
+ - `before_prompt_build`
219
+ - `agent_end`
220
+
221
+ If your host disables plugin hooks globally, keyword-based workflow will not work correctly.
222
+
223
+ ## Installation
224
+
225
+ ### 1. Install the plugin
226
+
227
+ Recommended public install after publishing to npm:
228
+
229
+ ```powershell
230
+ openclaw plugins install clawspec@latest
231
+ ```
232
+
233
+ `@latest` always resolves to the newest published ClawSpec release on npm.
234
+
235
+ Current OpenClaw builds do not accept raw GitHub URLs as ordinary plugin install specs. A GitHub repo by itself is not enough for `openclaw plugins install`; the standard public path is an npm package spec such as `clawspec@latest`.
236
+
237
+ If you want an unreleased commit before npm publish, clone the repository and install from the local checkout or a downloaded `.tgz` archive instead.
238
+
239
+ ### 2. Enable ACP and ACPX in OpenClaw
240
+
241
+ Example `~/.openclaw/openclaw.json`:
242
+
243
+ ```json
244
+ {
245
+ "acp": {
246
+ "enabled": true,
247
+ "backend": "acpx",
248
+ "defaultAgent": "codex"
249
+ },
250
+ "plugins": {
251
+ "entries": {
252
+ "acpx": {
253
+ "enabled": true,
254
+ "config": {
255
+ "permissionMode": "approve-all",
256
+ "expectedVersion": "any"
257
+ }
258
+ },
259
+ "clawspec": {
260
+ "enabled": true,
261
+ "config": {
262
+ "defaultWorkspace": "~/clawspec/workspace",
263
+ "workerAgentId": "codex",
264
+ "openSpecTimeoutMs": 120000,
265
+ "watcherPollIntervalMs": 4000
266
+ }
267
+ }
268
+ }
269
+ }
270
+ }
271
+ ```
272
+
273
+ Important notes:
274
+
275
+ - Recent OpenClaw builds often bundle `acpx` under the host install. ClawSpec checks that builtin copy before falling back to `acpx` on `PATH` or a plugin-local install.
276
+ - If your OpenClaw build does not bundle `acpx`, install or load it separately before relying on `cs-work`.
277
+ - ClawSpec itself does not ship its own ACP runtime backend.
278
+ - When ACPX is unavailable, the watcher now reports a short recovery hint in chat telling the user to enable `plugins.entries.acpx` and backend `acpx`.
279
+ - `acp.defaultAgent` is the OpenClaw ACP default. ClawSpec background workers use `plugins.entries.clawspec.config.workerAgentId` by default.
280
+ - For ClawSpec worker selection, precedence is: `/clawspec worker <agent-id>` for the current channel/project, then `clawspec.config.workerAgentId`, then the built-in ClawSpec fallback.
281
+ - In other words, ClawSpec does not currently inherit `acp.defaultAgent` automatically. If you want both to use the same agent, set both values explicitly.
282
+
283
+ ### 2.5. Choose the default worker agent
284
+
285
+ ClawSpec can run background work with different ACP agents such as `codex` or `claude`, but there are two separate defaults to understand:
286
+
287
+ - `acp.defaultAgent`: the OpenClaw ACP default used by the host ACP system
288
+ - `plugins.entries.clawspec.config.workerAgentId`: the ClawSpec default used by `cs-work`
289
+
290
+ Recommended if you want both layers aligned:
291
+
292
+ ```json
293
+ {
294
+ "acp": {
295
+ "enabled": true,
296
+ "backend": "acpx",
297
+ "defaultAgent": "claude"
298
+ },
299
+ "plugins": {
300
+ "entries": {
301
+ "clawspec": {
302
+ "enabled": true,
303
+ "config": {
304
+ "workerAgentId": "claude"
305
+ }
306
+ }
307
+ }
308
+ }
309
+ }
310
+ ```
311
+
312
+ Useful runtime commands:
313
+
314
+ - `/clawspec worker` shows the current worker agent for this channel/project and the configured default
315
+ - `/clawspec worker codex` switches the current channel/project to `codex`
316
+ - `/clawspec worker claude` switches the current channel/project to `claude`
317
+ - `/clawspec worker status` shows the live worker state, runtime transport state, startup phase, startup wait, and current session info
318
+
319
+ Notes:
320
+
321
+ - `/clawspec worker <agent-id>` is persisted at the current channel/project scope
322
+ - the chosen agent must exist in your OpenClaw agent list or ACP allowlist
323
+ - if you want a global default, set `workerAgentId` in OpenClaw config
324
+ - if you want a one-off override for the active project conversation, use `/clawspec worker <agent-id>`
325
+
326
+ ### 2.6. ClawSpec plugin config reference
327
+
328
+ Common `plugins.entries.clawspec.config` fields:
329
+
330
+ | Key | Purpose | Notes |
331
+ | --- | --- | --- |
332
+ | `defaultWorkspace` | Default base directory used by `/clawspec workspace` and `/clawspec use` | Channel-specific workspace selection overrides this after first use |
333
+ | `workerAgentId` | Default ACP agent used by background workers | Can be overridden per channel/project with `/clawspec worker <agent-id>` |
334
+ | `openSpecTimeoutMs` | Timeout for each OpenSpec CLI invocation | Increase this if your repo or host is slow |
335
+ | `watcherPollIntervalMs` | Background watcher recovery poll interval | Controls how quickly recovery scans and replay checks run |
336
+ | `archiveDirName` | Directory name under `.openclaw/clawspec/` for archived bundles | Keep the default unless you need a different archive layout |
337
+ | `allowedChannels` | Optional allowlist of channel ids allowed to use ClawSpec | Useful when only selected channels should expose the workflow |
338
+
339
+ Backward-compatibility keys still accepted but currently treated as no-ops:
340
+
341
+ - `maxAutoContinueTurns`
342
+ - `maxNoProgressTurns`
343
+ - `workerBackendId`
344
+ - `workerWaitTimeoutMs`
345
+ - `subagentLane`
346
+
347
+ ### 3. Restart the gateway
348
+
349
+ ```powershell
350
+ openclaw gateway restart
351
+ openclaw gateway status
352
+ ```
353
+
354
+ ### 4. Understand tool bootstrap behavior
355
+
356
+ On startup ClawSpec checks for `openspec` in this order:
357
+
358
+ 1. Plugin-local binary under `node_modules/.bin`
359
+ 2. `openspec` on `PATH`
360
+ 3. If missing, it may run:
361
+
362
+ ```powershell
363
+ npm install --omit=dev --no-save @fission-ai/openspec
364
+ ```
365
+
366
+ That means the gateway host may need network access and a working `npm` if `openspec` is not already available.
367
+
368
+ On startup ClawSpec checks for `acpx` in this order:
369
+
370
+ 1. Plugin-local binary under `node_modules/.bin`
371
+ 2. The ACPX binary bundled with the current OpenClaw install
372
+ 3. `acpx` on `PATH`
373
+ 4. If none of those satisfy the worker runtime requirement, it may run:
374
+
375
+ ```powershell
376
+ npm install --omit=dev --no-save acpx@0.3.1
377
+ ```
378
+
379
+ That fallback install can take a while on the first run. If OpenClaw already bundles ACPX, ClawSpec should now reuse it instead of reinstalling another copy.
380
+
381
+ ### 4.5. CI and release automation
382
+
383
+ This repository now includes two GitHub Actions workflows:
384
+
385
+ - `.github/workflows/ci.yml`
386
+ Runs on `push` to `main`, `pull_request`, and manual dispatch.
387
+ Uses a three-platform matrix: `ubuntu-latest`, `windows-latest`, `macos-latest`.
388
+ Runs `npm ci`, `npm run check`, and `npm test`.
389
+ - `.github/workflows/release.yml`
390
+ Runs on tag pushes that match `v*`.
391
+ Verifies the tag matches `package.json` version, runs install/check/test/pack, publishes to npm, then creates a GitHub Release.
392
+
393
+ Release notes:
394
+
395
+ - The release workflow expects tags in the form `vX.Y.Z`.
396
+ - The tag must match the `package.json` version exactly.
397
+ - npm publishing requires either npm trusted publishing or an `NPM_TOKEN` repository secret.
398
+ - GitHub Release creation uses the default GitHub Actions token and does not require an extra manual token.
399
+
400
+ Typical release flow:
401
+
402
+ ```powershell
403
+ # 1. bump package.json version
404
+ git add package.json package-lock.json
405
+ git commit -m "chore: release vX.Y.Z"
406
+ git push origin main
407
+
408
+ # 2. create and push a matching tag
409
+ git tag vX.Y.Z
410
+ git push origin vX.Y.Z
411
+ ```
412
+
413
+ ## Quick Start
414
+
415
+ ```text
416
+ /clawspec workspace "<workspace-path>"
417
+ /clawspec use "demo-app"
418
+ /clawspec proposal add-login-flow "Build login and session handling"
419
+ Describe the requirement in chat
420
+ cs-plan
421
+ cs-work
422
+ /clawspec status
423
+ /clawspec archive
424
+ ```
425
+
426
+ What happens:
427
+
428
+ 1. `/clawspec workspace` selects the workspace for this chat channel.
429
+ 2. `/clawspec use` selects or creates a repo folder under that workspace and runs `openspec init` if needed.
430
+ 3. `/clawspec proposal` creates the OpenSpec change scaffold and snapshot baseline.
431
+ 4. Ordinary chat discussion appends requirement notes to the planning journal.
432
+ 5. `cs-plan` refreshes planning artifacts in the visible chat turn.
433
+ 6. `cs-work` arms the watcher and starts background implementation.
434
+ 7. Watcher progress updates appear back in the same chat.
435
+ 8. `/clawspec archive` validates and archives the completed change.
436
+
437
+ ## Recommended First Run
438
+
439
+ This is the normal happy-path flow for a first-time user.
440
+
441
+ ### 1. Bind a workspace and select a project
442
+
443
+ ```text
444
+ /clawspec workspace "D:\clawspec\workspace"
445
+ /clawspec use "demo-app"
446
+ ```
447
+
448
+ Expected result:
449
+
450
+ - ClawSpec remembers the workspace for the current chat channel.
451
+ - The project directory is created if it does not exist.
452
+ - `openspec init` runs automatically the first time a repo is selected.
453
+
454
+ ### 2. Create a change before discussing requirements
455
+
456
+ ```text
457
+ /clawspec proposal add-login-flow "Build login and session handling"
458
+ ```
459
+
460
+ Expected result:
461
+
462
+ - OpenSpec creates `openspec/changes/add-login-flow/`
463
+ - ClawSpec takes a rollback snapshot baseline
464
+ - The chat enters the active change context for `add-login-flow`
465
+
466
+ ### 3. Describe the requirement in normal chat
467
+
468
+ Example:
469
+
470
+ ```text
471
+ Use email + password login.
472
+ Add refresh token support.
473
+ Expire access tokens after 15 minutes.
474
+ ```
475
+
476
+ Expected result:
477
+
478
+ - Your discussion is appended to the planning journal while the chat is attached.
479
+ - ClawSpec does not rewrite artifacts yet.
480
+ - ClawSpec does not start coding yet.
481
+
482
+ ### 4. Run visible planning sync
483
+
484
+ ```text
485
+ cs-plan
486
+ ```
487
+
488
+ Expected result:
489
+
490
+ - The current visible chat turn refreshes `proposal.md`, `design.md`, `specs`, and `tasks.md`
491
+ - You should see planning progress in the main chat
492
+ - The final message should clearly tell you to run `cs-work`
493
+
494
+ ### 5. Start background implementation
495
+
496
+ ```text
497
+ cs-work
498
+ ```
499
+
500
+ Expected result:
501
+
502
+ - ClawSpec arms the watcher
503
+ - The watcher starts the ACP worker through `acpx`
504
+ - Short progress updates begin to appear in chat as tasks start and finish
505
+
506
+ ### 6. Check progress or temporarily leave project mode
507
+
508
+ Useful commands:
509
+
510
+ ```text
511
+ /clawspec worker status
512
+ /clawspec status
513
+ cs-detach
514
+ cs-attach
515
+ ```
516
+
517
+ Use `cs-detach` when you want to keep the worker running but stop normal chat from being recorded into the planning journal. Use `cs-attach` when you want to continue discussing this change.
518
+
519
+ ### 7. Finish the change
520
+
521
+ If implementation completes cleanly:
522
+
523
+ ```text
524
+ /clawspec archive
525
+ ```
526
+
527
+ If you want to add more requirements before archive:
528
+
529
+ ```text
530
+ Describe the new requirement in chat
531
+ cs-plan
532
+ cs-work
533
+ ```
534
+
535
+ That loop is the normal operating model:
536
+
537
+ 1. discuss
538
+ 2. `cs-plan`
539
+ 3. `cs-work`
540
+ 4. archive when done
541
+
542
+ ## Slash Commands
543
+
544
+ | Command | When to use | What it does |
545
+ | --- | --- | --- |
546
+ | `/clawspec workspace [path]` | Before selecting a project, or when switching to another base workspace | Shows the current workspace for this chat channel, or updates it when a path is provided |
547
+ | `/clawspec use <project-name>` | When starting or resuming work in a repo | Selects or creates the project directory under the current workspace and runs `openspec init` if needed |
548
+ | `/clawspec proposal <change-name> [description]` | Before structured planning starts | Creates the OpenSpec change scaffold, prepares rollback state, and makes that change active |
549
+ | `/clawspec worker` | When you want to inspect the current worker agent selection | Shows the current per-channel/project worker agent and the plugin default |
550
+ | `/clawspec worker <agent-id>` | When you want this project conversation to use another ACP worker, such as `codex` or `claude` | Overrides the worker agent for the current channel/project context |
551
+ | `/clawspec worker status` | During background work or recovery debugging | Shows configured worker agent, runtime transport state, startup phase, startup wait, live session state, pid, heartbeat, and next action |
552
+ | `/clawspec attach` | When ordinary chat should go back to recording requirements for the active change | Reattaches the current conversation to ClawSpec context so planning notes are journaled again |
553
+ | `/clawspec detach` | When background work should continue but ordinary chat should stop affecting the project | Detaches ordinary chat from ClawSpec prompt injection and planning journal capture |
554
+ | `/clawspec deattach` | Only for backward compatibility with older habits | Legacy alias for `/clawspec detach` |
555
+ | `/clawspec continue` | After a pause, blocker resolution, or restart recovery | Resumes planning or implementation based on the current project phase |
556
+ | `/clawspec pause` | When you want the worker to stop at a safe boundary | Requests a cooperative pause for the current execution |
557
+ | `/clawspec status` | Any time you want a reconciled project snapshot | Renders current workspace, project, change, lifecycle, task counts, journal status, and next step |
558
+ | `/clawspec archive` | After all tasks are complete and you want to close the change | Validates and archives the finished OpenSpec change, then clears active change state |
559
+ | `/clawspec cancel` | When you want to abandon the active change | Restores tracked files from snapshots, removes the change, stops execution state, and clears the active change |
560
+
561
+ Auxiliary host CLI:
562
+
563
+ | Command | When to use | What it does |
564
+ | --- | --- | --- |
565
+ | `clawspec-projects` | On the gateway host when you want to inspect saved workspace roots | Lists remembered ClawSpec workspaces from plugin state |
566
+
567
+ ## Chat Keywords
568
+
569
+ Send these as normal chat messages in the active conversation.
570
+
571
+ | Keyword | Purpose |
572
+ | --- | --- |
573
+ | `cs-plan` | Runs visible planning sync in the current chat turn. Use this after you discuss or change requirements. |
574
+ | `cs-work` | Starts background implementation for pending tasks. Use this only after planning is clean. |
575
+ | `cs-attach` | Reattaches ordinary chat to project mode so requirement discussion is journaled again. |
576
+ | `cs-detach` | Detaches ordinary chat from project mode while letting watcher updates continue. |
577
+ | `cs-deattach` | Legacy alias for `cs-detach`. |
578
+ | `cs-pause` | Requests a cooperative pause for the background worker. |
579
+ | `cs-continue` | Resumes planning or implementation, depending on the current blocked or paused state. |
580
+ | `cs-status` | Shows current project status in chat. |
581
+ | `cs-cancel` | Cancels the active change from chat without using the slash command. |
582
+
583
+ ## End-To-End Workflow
584
+
585
+ ```mermaid
586
+ sequenceDiagram
587
+ actor User
588
+ participant Chat as OpenClaw Chat
589
+ participant Plugin as ClawSpec Plugin
590
+ participant Main as Visible Chat Agent
591
+ participant Watcher as Watcher Manager
592
+ participant Worker as ACP Worker
593
+ participant OpenSpec as OpenSpec CLI
594
+
595
+ User->>Plugin: /clawspec workspace + /clawspec use
596
+ Plugin->>OpenSpec: openspec init (if needed)
597
+ Plugin-->>User: Project selected
598
+
599
+ User->>Plugin: /clawspec proposal add-change
600
+ Plugin->>OpenSpec: openspec new change
601
+ Plugin-->>User: Proposal ready
602
+
603
+ User->>Chat: ordinary requirement discussion
604
+ Chat->>Plugin: message_received
605
+ Plugin->>Plugin: append planning journal
606
+
607
+ User->>Chat: cs-plan
608
+ Chat->>Plugin: before_prompt_build
609
+ Plugin->>Main: inject planning sync context + OpenSpec skills
610
+ Main->>OpenSpec: status + instructions + artifact refresh
611
+ Main-->>User: visible planning updates
612
+ Plugin->>Plugin: write planning snapshot
613
+
614
+ User->>Chat: cs-work
615
+ Chat->>Plugin: before_prompt_build
616
+ Plugin->>Watcher: arm implementation
617
+ Watcher->>Worker: start ACP session
618
+ Worker->>OpenSpec: apply instructions
619
+ Worker->>Watcher: progress/result files
620
+ Watcher-->>User: short progress cards
621
+
622
+ User->>Plugin: /clawspec archive
623
+ Plugin->>OpenSpec: validate + archive
624
+ Plugin-->>User: Archive complete
625
+ ```
626
+
627
+ ## Attached vs Detached Chat
628
+
629
+ ClawSpec keeps a `contextMode` per chat channel:
630
+
631
+ | Mode | Effect |
632
+ | --- | --- |
633
+ | `attached` | Ordinary chat gets ClawSpec prompt injection and planning messages are journaled |
634
+ | `detached` | Ordinary chat behaves normally; background watcher updates can still appear |
635
+
636
+ Use detached mode when you want background implementation to keep running but you do not want normal conversation to pollute the planning journal.
637
+
638
+ ## Planning Journal And Dirty State
639
+
640
+ ClawSpec keeps a repo-local planning journal at:
641
+
642
+ ```text
643
+ <repo>/.openclaw/clawspec/planning-journal.jsonl
644
+ ```
645
+
646
+ Journal behavior:
647
+
648
+ - User requirement messages are appended while the active change is attached.
649
+ - Substantive assistant replies can also be appended.
650
+ - Passive workflow control messages are filtered out.
651
+ - Commands and `cs-*` keywords are not journaled as planning content.
652
+ - A planning snapshot is written after successful `cs-plan`.
653
+ - If new discussion arrives after the last snapshot, the journal becomes `dirty`.
654
+
655
+ This is why `cs-work` may refuse to start and ask for `cs-plan` first: the implementation should not run against stale planning artifacts.
656
+
657
+ ## Visible Planning
658
+
659
+ `cs-plan` does not use the background ACP worker. It runs in the current visible chat turn by injecting:
660
+
661
+ - the active change context
662
+ - the planning journal
663
+ - imported OpenSpec skill text from the bundled `skills/` directory
664
+
665
+ Imported skill mapping:
666
+
667
+ | Mode | Skills |
668
+ | --- | --- |
669
+ | Ordinary planning discussion | `openspec-explore`, `openspec-propose` |
670
+ | `cs-plan` planning sync | `openspec-explore`, `openspec-propose` |
671
+ | `cs-work` implementation | `openspec-apply-change` |
672
+
673
+ Planning prompt guardrails intentionally prevent the main chat agent from:
674
+
675
+ - starting planning sync without an explicit `cs-plan`
676
+ - implementing code during ordinary planning discussion
677
+ - switching to another OpenSpec change silently
678
+ - scanning sibling change directories unnecessarily
679
+
680
+ ## Background Implementation
681
+
682
+ `cs-work` does three things:
683
+
684
+ 1. Runs `openspec status` and `openspec instructions apply --json`
685
+ 2. Writes `execution-control.json` and arms the watcher
686
+ 3. Lets the watcher start an ACP worker session through `acpx`
687
+
688
+ The watcher then:
689
+
690
+ - posts a short startup message
691
+ - posts a short `"ACP worker connected"` message
692
+ - streams progress from `worker-progress.jsonl`
693
+ - reconciles `execution-result.json`
694
+ - replays missed progress before the final completion message if the watcher had fallen behind
695
+ - updates project state
696
+ - restarts recoverable ACP failures with bounded backoff
697
+ - surfaces ACPX availability problems in a short actionable format
698
+
699
+ ## Recovery And Restart Model
700
+
701
+ ClawSpec is designed so background work is recoverable:
702
+
703
+ - gateway start: watcher manager scans active projects and first tries to adopt any still-running ACP worker session
704
+ - adopted live session: if the worker is still alive, ClawSpec keeps the existing ACP session, resumes watching its progress files, and does not require you to rerun `cs-work`
705
+ - dead session on restart: if the old worker is gone, ClawSpec re-arms recoverable work and starts a replacement worker when needed
706
+ - gateway stop: active background sessions are closed and resumable state is preserved
707
+ - ACP worker crash: watcher retries recoverable failures with backoff
708
+ - max restart cap: after 10 ACP restart attempts, the project becomes `blocked`
709
+
710
+ This makes `cs-work` much more resilient than trying to keep the entire implementation inside a single visible chat turn.
711
+
712
+ ## Lifecycle Model
713
+
714
+ The real implementation tracks both `status` and `phase`. The simplified diagram below is the easiest way to reason about it:
715
+
716
+ ```mermaid
717
+ stateDiagram-v2
718
+ [*] --> Idle
719
+ Idle --> Ready: /clawspec proposal
720
+ Ready --> Planning: cs-plan
721
+ Planning --> Ready: planning sync finished
722
+ Ready --> Armed: cs-work
723
+ Armed --> Running: watcher starts ACP worker
724
+ Running --> Paused: /clawspec pause
725
+ Running --> Blocked: blocker / ACPX unavailable / retry cap
726
+ Running --> Done: tasks complete
727
+ Paused --> Armed: /clawspec continue
728
+ Blocked --> Ready: fix planning issue + cs-plan
729
+ Blocked --> Armed: fix implementation issue + cs-work
730
+ Done --> Archived: /clawspec archive
731
+ Ready --> Cancelled: /clawspec cancel
732
+ Paused --> Cancelled: /clawspec cancel
733
+ Blocked --> Cancelled: /clawspec cancel
734
+ ```
735
+
736
+ ## Files And Storage
737
+
738
+ Global OpenClaw plugin state:
739
+
740
+ ```text
741
+ <openclaw-state-dir>/clawspec/
742
+ active-projects.json
743
+ project-memory.json
744
+ workspace-state.json
745
+ projects/
746
+ <projectId>.json
747
+ ```
748
+
749
+ Repo-local runtime state:
750
+
751
+ ```text
752
+ <repo>/.openclaw/clawspec/
753
+ state.json
754
+ execution-control.json
755
+ execution-result.json
756
+ worker-progress.jsonl
757
+ progress.md
758
+ changed-files.md
759
+ decision-log.md
760
+ latest-summary.md
761
+ planning-journal.jsonl
762
+ planning-journal.snapshot.json
763
+ rollback-manifest.json
764
+ snapshots/
765
+ <change-name>/
766
+ baseline/
767
+ archives/
768
+ <projectId>/
769
+ ```
770
+
771
+ OpenSpec change artifacts still live in the normal OpenSpec location:
772
+
773
+ ```text
774
+ <repo>/openspec/changes/<change-name>/
775
+ .openspec.yaml
776
+ proposal.md
777
+ design.md
778
+ tasks.md
779
+ specs/
780
+ ```
781
+
782
+ ## Operational Boundaries
783
+
784
+ - Workspace is remembered per chat channel.
785
+ - One active project is tracked per chat channel.
786
+ - One unfinished change is enforced per repo across channels.
787
+ - `tasks.md` remains the task source of truth.
788
+ - OpenSpec remains the canonical source for workflow semantics.
789
+ - ClawSpec never does a blanket `git reset --hard` during cancel.
790
+ - Detached mode stops prompt injection and journaling, but not watcher notifications.
791
+
792
+ ## Troubleshooting
793
+
794
+ ### `cs-work` says planning is required
795
+
796
+ Cause:
797
+
798
+ - planning journal is dirty
799
+ - planning artifacts are missing or stale
800
+ - OpenSpec apply state is still blocked
801
+
802
+ What to do:
803
+
804
+ 1. keep discussing requirements if needed
805
+ 2. run `cs-plan`
806
+ 3. run `cs-work` again
807
+
808
+ ### Worker looks connected but has not started the task yet
809
+
810
+ This usually means the ACP worker is already alive and is still digesting the implementation prompt or reading planning artifacts.
811
+
812
+ What to check:
813
+
814
+ 1. watcher messages such as "ACP worker connected..."
815
+ 2. worker-written status messages such as "Preparing <task>: loading context"
816
+ 3. `/clawspec worker status`, especially `startup phase` and `startup wait`
817
+
818
+ If you already see "Context ready for ..." then the worker has finished loading planning artifacts and is about to move into implementation. That phase can still take a little time before the first `task_start`.
819
+
820
+ ### Watcher says ACPX is unavailable
821
+
822
+ Cause:
823
+
824
+ - `acp.enabled` is false
825
+ - `acp.backend` is not `acpx`
826
+ - `plugins.entries.acpx.enabled` is false
827
+ - your OpenClaw build does not bundle `acpx` and it was never installed/loaded
828
+
829
+ What to do:
830
+
831
+ 1. enable ACP
832
+ 2. set backend to `acpx`
833
+ 3. enable `plugins.entries.acpx`
834
+ 4. if your host does not bundle ACPX, install/load it first
835
+ 5. rerun `cs-work` or `/clawspec continue`
836
+
837
+ ### Ordinary chat is polluting the planning journal
838
+
839
+ Use:
840
+
841
+ ```text
842
+ cs-detach
843
+ ```
844
+
845
+ or:
846
+
847
+ ```text
848
+ /clawspec detach
849
+ ```
850
+
851
+ Then reattach later with `cs-attach` or `/clawspec attach`.
852
+
853
+ ### `/clawspec use` says there is already an unfinished change
854
+
855
+ That is expected. ClawSpec prevents you from silently orphaning an active change in the same repo.
856
+
857
+ Use one of:
858
+
859
+ - `/clawspec continue`
860
+ - `/clawspec cancel`
861
+ - `/clawspec archive`
862
+
863
+ ### Cancel did not revert the whole repo
864
+
865
+ That is by design. Cancel restores tracked files from the ClawSpec snapshot baseline for the active change. It is intentionally narrower than a blanket Git restore.
866
+
867
+ ## Development And Validation
868
+
869
+ Useful checks while editing the plugin:
870
+
871
+ ```powershell
872
+ node --experimental-strip-types -e "import('./src/index.ts')"
873
+ node --experimental-strip-types --test test/watcher-work.test.ts
874
+ ```
875
+
876
+ Useful manual validation flow:
877
+
878
+ ```text
879
+ /clawspec workspace "<workspace-path>"
880
+ /clawspec use "demo-app"
881
+ /clawspec proposal add-something "Build something"
882
+ Discuss requirements in chat
883
+ cs-plan
884
+ cs-work
885
+ cs-status
886
+ /clawspec worker status
887
+ /clawspec pause
888
+ /clawspec continue
889
+ /clawspec archive
890
+ ```
891
+
892
+ Typical values for `<workspace-path>`:
893
+
894
+ - macOS: `~/clawspec/workspace`
895
+ - Linux: `~/clawspec/workspace`
896
+ - Windows: `D:\clawspec\workspace`
897
+
898
+ ## Implementation Summary
899
+
900
+ ClawSpec is intentionally not "just more prompts." It is a small orchestration layer that combines:
901
+
902
+ - OpenClaw hooks for visible chat control
903
+ - OpenSpec CLI for canonical workflow semantics
904
+ - a planning journal and snapshots for change tracking
905
+ - a watcher manager for durable background work
906
+ - ACP worker execution for long-running implementation
907
+
908
+ That split is the reason the plugin can keep planning conversational while still making implementation durable and resumable.