@chorus-aidlc/chorus-openclaw-plugin 0.3.1 → 0.5.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/README.md +218 -218
- package/dist/commands.d.ts +5 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +147 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +38 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +57 -0
- package/dist/config.js.map +1 -0
- package/dist/event-router.d.ts +55 -0
- package/dist/event-router.d.ts.map +1 -0
- package/dist/event-router.js +157 -0
- package/dist/event-router.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-client.d.ts +37 -0
- package/dist/mcp-client.d.ts.map +1 -0
- package/dist/mcp-client.js +137 -0
- package/dist/mcp-client.js.map +1 -0
- package/dist/mcp-registration.d.ts +25 -0
- package/dist/mcp-registration.d.ts.map +1 -0
- package/dist/mcp-registration.js +93 -0
- package/dist/mcp-registration.js.map +1 -0
- package/dist/sse-listener.d.ts +37 -0
- package/dist/sse-listener.d.ts.map +1 -0
- package/dist/sse-listener.js +152 -0
- package/dist/sse-listener.js.map +1 -0
- package/dist/wake.d.ts +67 -0
- package/dist/wake.d.ts.map +1 -0
- package/dist/wake.js +234 -0
- package/dist/wake.js.map +1 -0
- package/openclaw.plugin.json +14 -12
- package/package.json +24 -5
- package/skills/brainstorm/SKILL.md +163 -0
- package/skills/chorus/SKILL.md +413 -0
- package/skills/develop/SKILL.md +434 -0
- package/skills/idea/SKILL.md +293 -0
- package/skills/openspec-aware/SKILL.md +425 -0
- package/skills/proposal/SKILL.md +397 -0
- package/skills/proposal-reviewer/SKILL.md +117 -0
- package/skills/quick-dev/SKILL.md +198 -0
- package/skills/review/SKILL.md +354 -0
- package/skills/task-reviewer/SKILL.md +113 -0
- package/skills/yolo/SKILL.md +498 -0
- package/src/commands.ts +147 -57
- package/src/config.ts +23 -10
- package/src/event-router.ts +46 -54
- package/src/index.ts +56 -83
- package/src/mcp-client.ts +17 -0
- package/src/mcp-registration.ts +142 -0
- package/src/openclaw-sdk.d.ts +95 -0
- package/src/wake.ts +310 -0
- package/src/tools/admin-tools.ts +0 -117
- package/src/tools/common-tools.ts +0 -546
- package/src/tools/dev-tools.ts +0 -97
- package/src/tools/pm-tools.ts +0 -390
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: openspec-aware
|
|
3
|
+
description: Opt-in OpenSpec-mode authoring for Chorus PM workflows on OpenClaw. Runs inline three-check detection for the local `openspec` CLI, scaffolds `openspec/changes/<slug>/` on disk, and mirrors Markdown files into Chorus document drafts via the `chorus-api.sh` wrapper. Required reading for the proposal, develop, and yolo skills whenever the user has the `openspec` CLI installed.
|
|
4
|
+
license: AGPL-3.0
|
|
5
|
+
metadata:
|
|
6
|
+
author: chorus
|
|
7
|
+
version: "0.9.0"
|
|
8
|
+
category: project-management
|
|
9
|
+
mcp_server: chorus
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# OpenSpec-aware Authoring (OpenClaw plugin)
|
|
13
|
+
|
|
14
|
+
This skill is a **shared sub-procedure** invoked by the Chorus stage skills (proposal, develop, yolo) whenever the user wants spec-driven authoring through the [OpenSpec CLI](https://github.com/Fission-AI/OpenSpec). It is opt-in:
|
|
15
|
+
|
|
16
|
+
- Activates when **all three** signals hold (see §1): `CHORUS_OPENSPEC_MODE` is not `off`, an `openspec/` directory exists at the project root, and the `openspec` CLI is on `PATH`.
|
|
17
|
+
- Otherwise the calling skill falls back to its existing free-form behavior.
|
|
18
|
+
|
|
19
|
+
> **Tool namespace:** Chorus MCP tools are exposed under a `chorus__` prefix on OpenClaw (e.g. `chorus__chorus_pm_create_proposal`). Bare names are used in prose for readability — prepend `chorus__` when invoking the MCP tools directly. **Document-mirror calls do NOT go through the MCP harness at all** — they go through the `chorus-api.sh` wrapper (see §2 Rule 1), which talks to the Chorus MCP endpoint over HTTP using your API key, independent of the `chorus__` namespacing.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## §1. Detection — run inline, every time (no SessionStart hook on OpenClaw)
|
|
24
|
+
|
|
25
|
+
> **OpenClaw difference:** the Claude Code plugin precomputes `CHORUS_OPENSPEC_ACTIVE` once in a SessionStart hook and injects it into context. **OpenClaw does not run that hook.** You MUST compute activeness yourself, inline, the moment you reach this skill from a stage skill. Do not look for an injected `CHORUS_OPENSPEC_ACTIVE` value — it will not exist on OpenClaw.
|
|
26
|
+
|
|
27
|
+
Compute the value with the **three checks**. `CHORUS_OPENSPEC_ACTIVE` is `1` only when **all three** hold:
|
|
28
|
+
|
|
29
|
+
1. `CHORUS_OPENSPEC_MODE` is **not** set to `off` (explicit opt-out wins).
|
|
30
|
+
2. The project root contains an `openspec/` directory (i.e. someone ran `openspec init` here).
|
|
31
|
+
3. The `openspec` CLI is on `PATH`.
|
|
32
|
+
|
|
33
|
+
Both signals (2) and (3) are required because the OpenSpec authoring path needs the working directory **and** the CLI — having one without the other leaves the workflow unrunnable. If signal (2) holds but (3) does not, surface a hint to the user — "OpenSpec repo detected — install with: `npm i -g @fission-ai/openspec`" — rather than silently choosing free-form.
|
|
34
|
+
|
|
35
|
+
### Inline detection block (run this)
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Run the three checks directly. PROJECT_DIR is your project root
|
|
39
|
+
# (OpenClaw does not export CLAUDE_PROJECT_DIR — default to $PWD).
|
|
40
|
+
PROJECT_DIR="${PWD}"
|
|
41
|
+
if [ "${CHORUS_OPENSPEC_MODE:-}" = "off" ]; then
|
|
42
|
+
CHORUS_OPENSPEC_ACTIVE=0
|
|
43
|
+
elif [ ! -d "${PROJECT_DIR}/openspec" ]; then
|
|
44
|
+
CHORUS_OPENSPEC_ACTIVE=0
|
|
45
|
+
elif ! openspec --version >/dev/null 2>&1; then
|
|
46
|
+
CHORUS_OPENSPEC_ACTIVE=0 # consider surfacing the install hint to the user
|
|
47
|
+
else
|
|
48
|
+
CHORUS_OPENSPEC_ACTIVE=1
|
|
49
|
+
fi
|
|
50
|
+
echo "CHORUS_OPENSPEC_ACTIVE=$CHORUS_OPENSPEC_ACTIVE"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Branch on the result:
|
|
54
|
+
|
|
55
|
+
- `CHORUS_OPENSPEC_ACTIVE=1` → follow §3 (OpenSpec authoring).
|
|
56
|
+
- `CHORUS_OPENSPEC_ACTIVE=0` → return to the calling skill's free-form path. **Do not** scaffold `openspec/changes/`. **Do not** add the slug line to the proposal description.
|
|
57
|
+
|
|
58
|
+
Run this detection inline whenever proposal / develop / yolo reference this skill. There is no host-injected value to read on OpenClaw; recomputing the three checks is the contract.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## §2. ⛔ Two non-negotiable rules
|
|
63
|
+
|
|
64
|
+
Both are enforced at review time. Both have caused incidents in past releases.
|
|
65
|
+
|
|
66
|
+
### Rule 1 — Mirror via the wrapper, never re-type document content from agent output
|
|
67
|
+
|
|
68
|
+
Document/draft mirror calls (`chorus_pm_add_document_draft`, `chorus_pm_update_document_draft`, `chorus_pm_update_document`) **MUST** go through:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
chorus-api.sh mcp-tool <tool_name> "$PAYLOAD"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
with `$PAYLOAD` built using `json_encode_file` (defined in §3.4). Calling these tools directly from the agent's MCP harness with a hand-typed `content` field is a **protocol violation** for OpenSpec mode and will fail review. Reasons:
|
|
75
|
+
|
|
76
|
+
1. **Token cost.** Re-typing a multi-thousand-line markdown body through the LLM burns input + output tokens for every draft. The wrapper streams bytes through `jq -Rs '.'` — content never enters LLM context. A typical 3-doc proposal mirror via the script costs roughly zero content-tokens; via direct MCP it routinely costs 20k+.
|
|
77
|
+
2. **Byte-equality.** `jq -Rs '.'` is a byte-faithful encoder: backslashes, quotes, newlines, code-fence content, zero-width chars all survive. LLM re-emission has a non-zero failure rate on long markdown — table alignment drifts, fence escapes get "fixed", long URLs wrap. The byte-equality guarantee (modulo trailing `\n`) holds **only** on the wrapper path.
|
|
78
|
+
3. **Single source of truth.** With the wrapper, the local `openspec/changes/<slug>/*.md` is authoritative and Chorus is a mirror. With agent re-typing, authority splits between local file and whatever the LLM happened to output — a future diff cannot tell which one is correct.
|
|
79
|
+
|
|
80
|
+
> **`chorus-api.sh` availability on OpenClaw.** This wrapper is the document-mirror transport. It must be reachable as `chorus-api.sh` on `PATH` (the Chorus standalone skill bundle ships it; if you installed via that bundle it is already on `PATH`). If it is **not** on `PATH` in your OpenClaw environment, do one of:
|
|
81
|
+
> - call it by its absolute path (e.g. `"$HOME/.chorus/bin/chorus-api.sh" mcp-tool ...`), or
|
|
82
|
+
> - reproduce its single behavior inline — POST a JSON-RPC `tools/call` for `<tool_name>` with arguments `$PAYLOAD` to `"$CHORUS_URL/api/mcp"` with header `Authorization: Bearer $CHORUS_API_KEY` using `curl`, capturing the raw body for the §6 halt-on-error check.
|
|
83
|
+
>
|
|
84
|
+
> The wrapper requires `CHORUS_URL` and `CHORUS_API_KEY` in the environment (same values as your plugin config `chorusUrl` / `apiKey`). Export them before the first call if they are not already set. What you must NOT do is re-type the document body through the model — the wrapper-only rule stands regardless of how you invoke the wrapper.
|
|
85
|
+
|
|
86
|
+
### Rule 2 — Halt on error via `chorus_check_response`
|
|
87
|
+
|
|
88
|
+
Every wrapper call must check three signals: wrapper exit code, `"error":` in body, empty body. Bare `RC=$?` is **insufficient** — the wrapper exits 0 on HTTP 401 (auth failure) with empty body, so a single-signal check silently misses the most common runtime failure. See §6 for the helper definition.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## §3. OpenSpec mode authoring
|
|
93
|
+
|
|
94
|
+
### 3.1 Pick a slug
|
|
95
|
+
|
|
96
|
+
`openspec/changes/<slug>/` is the local change folder. The slug must be:
|
|
97
|
+
|
|
98
|
+
- kebab-case (`add-export-csv`, not `addExportCsv` or `add_export_csv`),
|
|
99
|
+
- derived from the source Idea title,
|
|
100
|
+
- unique within `openspec/changes/`.
|
|
101
|
+
|
|
102
|
+
Record it for later steps:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
SLUG="add-export-csv"
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 3.2 Scaffold the change folder
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
openspec new change "$SLUG" --description "<one-line idea summary>"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
This creates `openspec/changes/$SLUG/` with `README.md` and `.openspec.yaml`. Then author by hand:
|
|
115
|
+
|
|
116
|
+
| Local file | Purpose | Mirror as `Document.type` |
|
|
117
|
+
|---|---|---|
|
|
118
|
+
| `proposal.md` | Why + What Changes + Capabilities + Impact | `prd` |
|
|
119
|
+
| `design.md` | Architecture, contracts, risks | `tech_design` |
|
|
120
|
+
| `specs/<capability>/spec.md` | Delta spec (`## ADDED Requirements` + Scenarios) | `spec` (one draft per capability) |
|
|
121
|
+
| `tasks.md` | OpenSpec tasks list | _(not mirrored — Chorus task drafts are source of truth)_ |
|
|
122
|
+
|
|
123
|
+
Use `openspec instructions <artifact> --change "$SLUG"` (artifacts: `proposal`, `specs`, `design`, `tasks`) for templates.
|
|
124
|
+
|
|
125
|
+
### 3.3 Spec file shape (verified against `openspec instructions specs`)
|
|
126
|
+
|
|
127
|
+
A delta spec lists one or more block headers — `## ADDED Requirements`, `## MODIFIED Requirements`, `## REMOVED Requirements`, `## RENAMED Requirements` — and within each, `### Requirement:` entries. Mix freely in the same file; only include the blocks you actually need.
|
|
128
|
+
|
|
129
|
+
#### `## ADDED Requirements`
|
|
130
|
+
|
|
131
|
+
Append a brand-new Requirement to the long-term spec.
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
## ADDED Requirements
|
|
135
|
+
|
|
136
|
+
### Requirement: <name>
|
|
137
|
+
<requirement text — use SHALL / MUST for normative behavior>
|
|
138
|
+
|
|
139
|
+
#### Scenario: <name>
|
|
140
|
+
- **WHEN** <condition>
|
|
141
|
+
- **THEN** <expected outcome>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### `## MODIFIED Requirements`
|
|
145
|
+
|
|
146
|
+
**Whole-block replacement, not merge.** Whatever you write here completely replaces the existing same-named Requirement in the long-term spec — title, description, and *all* scenarios. Half-writing it deletes the rest.
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
## MODIFIED Requirements
|
|
150
|
+
|
|
151
|
+
### Requirement: <existing name>
|
|
152
|
+
<full updated requirement text>
|
|
153
|
+
|
|
154
|
+
#### Scenario: <name>
|
|
155
|
+
- **WHEN** <condition>
|
|
156
|
+
- **THEN** <expected outcome>
|
|
157
|
+
|
|
158
|
+
#### Scenario: <other name>
|
|
159
|
+
- **WHEN** <condition>
|
|
160
|
+
- **THEN** <expected outcome>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Always include every scenario you want the post-archive spec to have, even ones that were already present and unchanged.
|
|
164
|
+
|
|
165
|
+
#### `## REMOVED Requirements`
|
|
166
|
+
|
|
167
|
+
Delete a Requirement from the long-term spec. The block under the heading is just the requirement name(s) you're removing — no scenarios needed.
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
## REMOVED Requirements
|
|
171
|
+
|
|
172
|
+
### Requirement: <existing name>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### `## RENAMED Requirements`
|
|
176
|
+
|
|
177
|
+
Rename a Requirement's title. Body and scenarios are preserved as-is in the long-term spec; use `MODIFIED` instead if you need to change anything besides the title.
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
## RENAMED Requirements
|
|
181
|
+
|
|
182
|
+
### Requirement: <old name> -> <new name>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Critical formatting rules (verified):**
|
|
186
|
+
|
|
187
|
+
- Scenarios MUST use **exactly 4 hashtags** (`#### Scenario:`). 3 hashtags or a bullet list silently fail validation.
|
|
188
|
+
- Every `### Requirement:` under `ADDED` or `MODIFIED` MUST have at least one `#### Scenario:`.
|
|
189
|
+
- `MODIFIED` blocks MUST include the **full updated content** — they overwrite, not patch.
|
|
190
|
+
- Use `SHALL` / `MUST` for normative requirements; avoid `should` / `may`.
|
|
191
|
+
- The merge into `openspec/specs/<capability>/spec.md` happens at `openspec archive` time (§3.9), not at proposal time. While the proposal is in flight, Chorus only sees the delta file as one `spec` Document — there is no half-merged state for the skill to reason about.
|
|
192
|
+
|
|
193
|
+
Optional:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
openspec validate "$SLUG"
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 3.4 Helper: `json_encode_file`
|
|
200
|
+
|
|
201
|
+
Define once at the top of the authoring session. With `jq` available it streams the file into a JSON string; the fallback matches `chorus-api.sh`'s own escaping when `jq` is missing.
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
json_encode_file() {
|
|
205
|
+
local _path="$1"
|
|
206
|
+
if command -v jq >/dev/null 2>&1; then
|
|
207
|
+
jq -Rs '.' < "$_path"
|
|
208
|
+
else
|
|
209
|
+
local _content
|
|
210
|
+
_content=$(cat "$_path")
|
|
211
|
+
_content=${_content//\\/\\\\}
|
|
212
|
+
_content=${_content//\"/\\\"}
|
|
213
|
+
_content=${_content//$'\n'/\\n}
|
|
214
|
+
printf '"%s"' "$_content"
|
|
215
|
+
fi
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Round-trip: the Chorus backend appends a single `\n` to draft content on write, so server `content` is **byte-equal modulo a trailing newline**. Reviewers diffing local file vs server should ignore that one byte.
|
|
220
|
+
|
|
221
|
+
### 3.5 Create the proposal container with the slug provenance line
|
|
222
|
+
|
|
223
|
+
Use the regular `chorus_pm_create_proposal` MCP tool (no wrapper required for this single call — the description is short, the LLM-emitted version is fine). The description **must** carry exactly one line:
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
OpenSpec change slug: <slug>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
- on its own line (no other text on that line),
|
|
230
|
+
- literal prefix `OpenSpec change slug: ` (capital O, capital S, single space after colon),
|
|
231
|
+
- no trailing punctuation,
|
|
232
|
+
- value matches the slug passed to `openspec new change`.
|
|
233
|
+
|
|
234
|
+
This line is machine-grep-able by future runs of this skill and by the §3.9 archive trigger.
|
|
235
|
+
|
|
236
|
+
### 3.6 Mirror each document draft via the wrapper
|
|
237
|
+
|
|
238
|
+
> **Rule 1 reminder:** these calls go through `chorus-api.sh`, not direct MCP. The agent must not retype the document body.
|
|
239
|
+
|
|
240
|
+
Ensure `CHORUS_URL` and `CHORUS_API_KEY` are exported (Rule 1 note). Define the halt-on-error helper from §6 once at the top, then run one call per file:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
# PRD draft
|
|
244
|
+
CONTENT=$(json_encode_file "openspec/changes/$SLUG/proposal.md")
|
|
245
|
+
PAYLOAD=$(cat <<JSON
|
|
246
|
+
{
|
|
247
|
+
"proposalUuid": "$PROPOSAL_UUID",
|
|
248
|
+
"type": "prd",
|
|
249
|
+
"title": "PRD: $HUMAN_TITLE",
|
|
250
|
+
"content": $CONTENT
|
|
251
|
+
}
|
|
252
|
+
JSON
|
|
253
|
+
)
|
|
254
|
+
RESULT=$(chorus-api.sh mcp-tool chorus_pm_add_document_draft "$PAYLOAD")
|
|
255
|
+
RC=$?
|
|
256
|
+
chorus_check_response "chorus_pm_add_document_draft (prd)" "$RC" "$RESULT"
|
|
257
|
+
PRD_DRAFT_UUID=$(printf '%s' "$RESULT" | grep -o '"draftUuid"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*"\([^"]*\)"$/\1/')
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Repeat with `type: "tech_design"` for `design.md`, and one call per capability with `type: "spec"` for each `specs/<capability>/spec.md`. Do **not** mirror `tasks.md` — Chorus task drafts (created via the `chorus_pm_add_task_draft` MCP tool, no wrapper needed) are the source of truth for tasks.
|
|
261
|
+
|
|
262
|
+
> Why parsing uses `printf '%s' "$RESULT" | grep` not `echo "$RESULT" | jq`: `echo` interprets backslash sequences inside the captured JSON, turning embedded `\n` into a real newline. `jq` then aborts with `Invalid string: control characters from U+0000 through U+001F must be escaped`. `printf '%s'` emits the captured bytes verbatim. Same pattern applies to all wrapper-result parsing in this skill.
|
|
263
|
+
|
|
264
|
+
### 3.7 Editing a draft after the first mirror
|
|
265
|
+
|
|
266
|
+
Local file changes propagate via `chorus_pm_update_document_draft` — same wrapper, same `json_encode_file`, same halt check.
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
CONTENT=$(json_encode_file "openspec/changes/$SLUG/proposal.md")
|
|
270
|
+
PAYLOAD=$(cat <<JSON
|
|
271
|
+
{
|
|
272
|
+
"proposalUuid": "$PROPOSAL_UUID",
|
|
273
|
+
"draftUuid": "$PRD_DRAFT_UUID",
|
|
274
|
+
"content": $CONTENT
|
|
275
|
+
}
|
|
276
|
+
JSON
|
|
277
|
+
)
|
|
278
|
+
RESULT=$(chorus-api.sh mcp-tool chorus_pm_update_document_draft "$PAYLOAD")
|
|
279
|
+
RC=$?
|
|
280
|
+
chorus_check_response "chorus_pm_update_document_draft" "$RC" "$RESULT"
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### 3.8 Editing a Document after proposal approval
|
|
284
|
+
|
|
285
|
+
Once the proposal is approved, drafts materialize into Documents with their own UUIDs. To keep `openspec/changes/$SLUG/` and the Chorus Document in sync, mirror file edits via `chorus_pm_update_document`:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
CONTENT=$(json_encode_file "openspec/changes/$SLUG/specs/<capability>/spec.md")
|
|
289
|
+
PAYLOAD=$(cat <<JSON
|
|
290
|
+
{
|
|
291
|
+
"documentUuid": "$SPEC_DOCUMENT_UUID",
|
|
292
|
+
"content": $CONTENT
|
|
293
|
+
}
|
|
294
|
+
JSON
|
|
295
|
+
)
|
|
296
|
+
RESULT=$(chorus-api.sh mcp-tool chorus_pm_update_document "$PAYLOAD")
|
|
297
|
+
RC=$?
|
|
298
|
+
chorus_check_response "chorus_pm_update_document" "$RC" "$RESULT"
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
To re-derive `$SPEC_DOCUMENT_UUID` from a fresh shell, look it up via `chorus_get_documents` for the proposal's project and match by `title` + `type`. Re-derive `$SLUG` by grepping the proposal's `description` for `^OpenSpec change slug: `.
|
|
302
|
+
|
|
303
|
+
### 3.9 Archive after the last task is verified
|
|
304
|
+
|
|
305
|
+
> **OpenClaw difference:** the Claude Code plugin has a PostToolUse hook (`bin/on-post-verify-task.sh`) that fires after `chorus_admin_verify_task` and injects an `openspec archive <slug>` reminder. **OpenClaw has no such hook.** You (the agent) must detect the trigger yourself: after each `chorus_admin_verify_task`, check whether the just-verified task was the **LAST** task of its OpenSpec-mode idea (every Task across every approved Proposal of that idea is now `done`/`closed`, and the proposal `description` carries an `OpenSpec change slug: <slug>` line). If so, run the archive flow below. If not, do nothing.
|
|
306
|
+
|
|
307
|
+
When the trigger holds, you perform the archive:
|
|
308
|
+
|
|
309
|
+
1. **Run archive locally.** Use `--yes` for non-interactive mode. Do NOT pass `--skip-specs` (defeats the mirror-back) or `--no-validate` (lets malformed deltas corrupt cumulative specs).
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
openspec archive "$SLUG" --yes
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
This moves `openspec/changes/$SLUG/` under `openspec/changes/archive/<date>-<slug>/` and emits/updates `openspec/specs/<capability>/spec.md` for each capability. (Run `openspec archive --help` against your installed version to confirm the current flag set — flags can drift between releases.)
|
|
316
|
+
|
|
317
|
+
2. **Mirror each updated `openspec/specs/<capability>/spec.md` back** to the matching post-approval Chorus Document (§3.8 contract). `chorus_get_documents` only supports `projectUuid` + `type` server-side filters; filter by title client-side. One `chorus_pm_update_document` call per capability.
|
|
318
|
+
|
|
319
|
+
3. **Halt on any error** from `openspec archive` or `chorus_pm_update_document`. Print stderr verbatim, post a comment on the proposal recording the failure (`chorus_add_comment` with `targetType: "proposal"`, `targetUuid: <proposalUuid>`), then stop. No retry. Matches §6 "no silent errors." (Comment on the proposal, not the idea: the failure is in archiving proposal-derived specs, and proposals can be `inputType: "document"` with no idea attached.)
|
|
320
|
+
|
|
321
|
+
4. **Confirm success.** List `openspec/specs/<capability>/spec.md` files and verify they round-trip byte-equal (modulo trailing newline) with their Chorus Document counterparts.
|
|
322
|
+
|
|
323
|
+
**Strict opt-in:** if the verified task is not the last of its idea, OR the proposal description carries no `OpenSpec change slug: <slug>` line, OR the local shell has no `openspec` CLI, do nothing — no archive. Existing free-form behavior is preserved.
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## §4. Fallback authoring (no openspec)
|
|
328
|
+
|
|
329
|
+
When the §1 detection puts the agent in fallback mode (`CHORUS_OPENSPEC_ACTIVE=0`), this skill is a **no-op**. Return to the calling skill's free-form path:
|
|
330
|
+
|
|
331
|
+
- No `openspec/changes/` folder is created or referenced.
|
|
332
|
+
- No `OpenSpec change slug: …` line is added to the proposal description.
|
|
333
|
+
- Document drafts are authored via direct MCP `chorus_pm_add_document_draft` calls with inline `content` — same as before this skill existed.
|
|
334
|
+
- Rule 1 (wrapper-only mirror) does not apply — there is no local file source of truth.
|
|
335
|
+
- The §3.9 archive flow does nothing (no slug → no archive).
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## §5. Document type mapping (reference table)
|
|
340
|
+
|
|
341
|
+
| Local file | Chorus `Document.type` | Mirrored? |
|
|
342
|
+
|---|---|---|
|
|
343
|
+
| `openspec/changes/<slug>/proposal.md` | `prd` | yes |
|
|
344
|
+
| `openspec/changes/<slug>/design.md` | `tech_design` | yes |
|
|
345
|
+
| `openspec/changes/<slug>/specs/<capability>/spec.md` | `spec` | yes (one draft per capability) |
|
|
346
|
+
| `openspec/changes/<slug>/tasks.md` | _(not mapped)_ | **no** — Chorus task drafts are source of truth |
|
|
347
|
+
|
|
348
|
+
`prd`, `tech_design`, `spec` are pre-existing valid `Document.type` values — no schema change required.
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## §6. Failure visibility — the `chorus_check_response` helper
|
|
353
|
+
|
|
354
|
+
There is a known wrapper edge case: when the server returns HTTP 4xx (e.g. 401 from a bad `CHORUS_API_KEY`), `chorus-api.sh mcp-tool` captures the JSON-RPC error body internally, pipes it through a `.result.content[]?` jq filter that produces no output when `.result` is absent, and exits 0 with empty stdout. A bare `RC=$?` check would not halt on this — the most common runtime failure mode would be invisible. (If you reproduced the wrapper inline via `curl` per the Rule 1 note, the same three-signal check still applies to the raw HTTP body.)
|
|
355
|
+
|
|
356
|
+
Define this helper **once** at the top of the authoring session and use it after every wrapper call:
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
chorus_check_response() {
|
|
360
|
+
local _tool="$1"
|
|
361
|
+
local _rc="$2"
|
|
362
|
+
local _body="$3"
|
|
363
|
+
local _has_error=0
|
|
364
|
+
local _is_empty=0
|
|
365
|
+
|
|
366
|
+
local _trimmed
|
|
367
|
+
_trimmed=$(printf '%s' "$_body" | tr -d ' \t\n\r')
|
|
368
|
+
[ -z "$_trimmed" ] && _is_empty=1
|
|
369
|
+
|
|
370
|
+
if [ "$_is_empty" -eq 0 ]; then
|
|
371
|
+
if command -v jq >/dev/null 2>&1; then
|
|
372
|
+
if printf '%s' "$_body" | jq -e 'try ([.. | objects | has("error")] | any) catch false' >/dev/null 2>&1; then
|
|
373
|
+
_has_error=1
|
|
374
|
+
fi
|
|
375
|
+
else
|
|
376
|
+
printf '%s' "$_body" | grep -qE '"error"[[:space:]]*:' && _has_error=1
|
|
377
|
+
fi
|
|
378
|
+
fi
|
|
379
|
+
|
|
380
|
+
if [ "$_rc" -ne 0 ] || [ "$_has_error" -eq 1 ] || [ "$_is_empty" -eq 1 ]; then
|
|
381
|
+
echo "ERROR: $_tool failed (exit=$_rc, error_in_body=$_has_error, empty_body=$_is_empty)" >&2
|
|
382
|
+
echo "Output: $_body" >&2
|
|
383
|
+
[ "$_rc" -ne 0 ] && exit "$_rc" || exit 1
|
|
384
|
+
fi
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
**Anti-patterns** — do **not**:
|
|
389
|
+
|
|
390
|
+
- Collapse to `|| true`.
|
|
391
|
+
- Redirect stderr to `/dev/null`.
|
|
392
|
+
- Bury the wrapper call inside a pipeline (masks `$?`).
|
|
393
|
+
- Skip capturing `$RESULT` into a variable; the helper needs the body.
|
|
394
|
+
- Use only `if [ "$RC" -ne 0 ]; then ...` — that misses the HTTP-error path.
|
|
395
|
+
|
|
396
|
+
**Minimal call site shape:**
|
|
397
|
+
|
|
398
|
+
```bash
|
|
399
|
+
RESULT=$(chorus-api.sh mcp-tool <tool_name> "$PAYLOAD")
|
|
400
|
+
RC=$?
|
|
401
|
+
chorus_check_response "<tool_name>" "$RC" "$RESULT"
|
|
402
|
+
# ...if we reach here, the call succeeded; parse RESULT and continue.
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
This is project-wide policy: no silent errors.
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
## §7. Quick reference checklist
|
|
410
|
+
|
|
411
|
+
When invoked from a stage skill (proposal / develop / yolo):
|
|
412
|
+
|
|
413
|
+
1. **Run the §1 inline three-check detection yourself** (no SessionStart hook on OpenClaw). Compute `CHORUS_OPENSPEC_ACTIVE` from: `CHORUS_OPENSPEC_MODE != off` + `openspec/` dir present + `openspec` CLI on PATH.
|
|
414
|
+
2. If `CHORUS_OPENSPEC_ACTIVE=0` → return to caller's free-form path (§4).
|
|
415
|
+
3. Otherwise:
|
|
416
|
+
a. Pick `$SLUG` (§3.1).
|
|
417
|
+
b. `openspec new change "$SLUG"` (§3.2).
|
|
418
|
+
c. Author `proposal.md`, `design.md`, `specs/<capability>/spec.md` (§3.2–§3.3). Mix `ADDED` / `MODIFIED` / `REMOVED` / `RENAMED` blocks as needed; remember `MODIFIED` overwrites the whole Requirement.
|
|
419
|
+
d. Optional: `openspec validate "$SLUG"`.
|
|
420
|
+
e. `chorus_pm_create_proposal` (direct MCP) with the `OpenSpec change slug: $SLUG` line in description (§3.5).
|
|
421
|
+
f. Export `CHORUS_URL` / `CHORUS_API_KEY`; define `json_encode_file`, `chorus_check_response` helpers; confirm `chorus-api.sh` is reachable (Rule 1 note).
|
|
422
|
+
g. For each row in §5 with "yes" — mirror via `chorus-api.sh mcp-tool chorus_pm_add_document_draft` (§3.6). Record each `$DRAFT_UUID`.
|
|
423
|
+
h. On any failed `chorus_check_response` — halt, surface the error, do NOT proceed.
|
|
424
|
+
4. Edits before approval → §3.7. Edits after approval → §3.8.
|
|
425
|
+
5. Last task verified → detect the trigger yourself (no hook) → run §3.9 archive flow.
|