cclaw-cli 0.5.4 → 0.5.6
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 +8 -11
- package/dist/artifact-linter.js +3 -13
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +12 -1
- package/dist/config.js +0 -19
- package/dist/content/contracts.js +7 -12
- package/dist/content/examples.js +31 -49
- package/dist/content/hooks.d.ts +4 -6
- package/dist/content/hooks.js +104 -523
- package/dist/content/learnings.js +55 -203
- package/dist/content/meta-skill.js +8 -11
- package/dist/content/next-command.js +3 -3
- package/dist/content/observe.d.ts +4 -7
- package/dist/content/observe.js +10 -48
- package/dist/content/session-hooks.js +8 -8
- package/dist/content/skills.js +9 -16
- package/dist/content/stage-schema.js +76 -120
- package/dist/content/templates.d.ts +1 -1
- package/dist/content/templates.js +25 -57
- package/dist/delegation.js +7 -7
- package/dist/doctor.js +16 -47
- package/dist/flow-state.js +1 -1
- package/dist/harness-adapters.js +1 -1
- package/dist/install.js +22 -48
- package/dist/policy.js +1 -4
- package/dist/runs.d.ts +9 -9
- package/dist/runs.js +107 -320
- package/dist/trace-matrix.js +8 -18
- package/dist/types.d.ts +0 -4
- package/package.json +1 -1
- package/dist/learnings-summarizer.d.ts +0 -25
- package/dist/learnings-summarizer.js +0 -201
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// ---------------------------------------------------------------------------
|
|
2
|
-
//
|
|
3
|
-
// Cclaw emits instructions only; agents use shell tools against JSONL on disk.
|
|
2
|
+
// Knowledge store content for /cc-learn and stage self-improvement prompts.
|
|
4
3
|
// ---------------------------------------------------------------------------
|
|
5
|
-
const
|
|
4
|
+
const KNOWLEDGE_PATH = ".cclaw/knowledge.md";
|
|
6
5
|
const LEARN_SKILL_NAME = "learnings";
|
|
7
|
-
const LEARN_SKILL_DESCRIPTION = "Project-scoped
|
|
6
|
+
const LEARN_SKILL_DESCRIPTION = "Project-scoped knowledge store: review and append rule/pattern/lesson entries in .cclaw/knowledge.md.";
|
|
8
7
|
export function learnSkillMarkdown() {
|
|
9
8
|
return `---
|
|
10
9
|
name: ${LEARN_SKILL_NAME}
|
|
@@ -15,251 +14,104 @@ description: "${LEARN_SKILL_DESCRIPTION}"
|
|
|
15
14
|
|
|
16
15
|
## Overview
|
|
17
16
|
|
|
18
|
-
This skill
|
|
17
|
+
This skill manages the append-only project knowledge file at \`${KNOWLEDGE_PATH}\`.
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
Use it to keep durable knowledge that should survive sessions:
|
|
20
|
+
- **rule**: hard constraint to follow every time
|
|
21
|
+
- **pattern**: repeatable way that works well in this project
|
|
22
|
+
- **lesson**: non-obvious outcome from a failure or trade-off
|
|
21
23
|
|
|
22
24
|
## HARD-GATE
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
Under \`/cc-learn\`, only modify the knowledge store (\`${KNOWLEDGE_PATH}\`) or an explicitly user-approved summary file. Do not modify application code here.
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
- Forbidden: using learnings maintenance as a pretext to touch unrelated code paths.
|
|
28
|
+
## Entry format (append-only)
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
| \`type\` | yes | One of: \`pattern\`, \`pitfall\`, \`preference\`, \`architecture\`, \`tool\`, \`operational\`. |
|
|
36
|
-
| \`key\` | yes | Stable **kebab-case** identifier for dedup and search (e.g. \`avoid-barrel-reexports-in-tests\`). |
|
|
37
|
-
| \`insight\` | yes | Single human-readable sentence (no multi-paragraph essays). |
|
|
38
|
-
| \`confidence\` | yes | Integer **1–10** (see scale in “Operational Self-Improvement” on stage skills). |
|
|
39
|
-
| \`source\` | yes | \`observed\` \| \`user-stated\` \| \`inferred\`. Drives decay rules. |
|
|
40
|
-
| \`files\` | no | \`string[]\` of repo-relative paths this insight touched (for staleness checks in prune). |
|
|
41
|
-
| \`branch\` | no | Branch name when recorded (optional context). |
|
|
42
|
-
| \`commit\` | no | Short SHA when recorded (optional context). |
|
|
43
|
-
|
|
44
|
-
**Minimal valid example (conceptual):**
|
|
45
|
-
|
|
46
|
-
\`\`\`json
|
|
47
|
-
{"ts":"2026-04-11T12:00:00Z","skill":"tdd","type":"pattern","key":"run-migrations-before-seed","insight":"Seed scripts assume schema v7; run sqlx migrate before npm run seed.","confidence":8,"source":"observed","files":["scripts/seed.ts"]}
|
|
30
|
+
\`\`\`markdown
|
|
31
|
+
### 2026-04-14T12:00:00Z [pattern] short-title
|
|
32
|
+
- Stage: design
|
|
33
|
+
- Context: one short line
|
|
34
|
+
- Insight: one short line
|
|
35
|
+
- Reuse: one short line
|
|
48
36
|
\`\`\`
|
|
49
37
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
1. **\`user-stated\`**: never decays. Effective confidence = stored \`confidence\`.
|
|
55
|
-
2. **\`observed\` or \`inferred\`**: lose **1** point per **30** complete days since \`ts\`, floored at **0**.
|
|
56
|
-
- Formula: \`effective = max(0, confidence - floor(days_since_ts / 30))\`
|
|
57
|
-
- \`days_since_ts\` is measured from entry \`ts\` to “now” in UTC (use user machine time when computing in the agent).
|
|
58
|
-
|
|
59
|
-
Always compute **effective confidence** before sorting for “top N” displays.
|
|
60
|
-
|
|
61
|
-
## Dedup Rules (Read-Time)
|
|
62
|
-
|
|
63
|
-
- **On disk:** multiple lines may share the same \`(key, type)\` (history, corrections, re-logging).
|
|
64
|
-
- **When reading for display/search/export:** keep **only the latest** record per \`(key, type)\`, where **latest** means greatest \`ts\` (ISO strings compared lexicographically if timezones are consistent Z; prefer parsing timestamps if implementing custom logic).
|
|
65
|
-
- This is **read-time dedup**, not write-time: do not silently delete older lines unless \`/cc-learn prune\` (or the user) removes them.
|
|
66
|
-
|
|
67
|
-
## Security Rules
|
|
68
|
-
|
|
69
|
-
1. **Skip malformed lines:** when ingesting JSONL, parse line-by-line; on parse failure, skip the line and continue (optionally count skips for \`stats\`).
|
|
70
|
-
2. **Never interpolate JSONL field values into shell commands** as raw arguments — no \`eval\`, no unquoted \`$(cat ...)\` into flags. Use **files as data**: pipe to \`jq\`, or write controlled queries. User-supplied text from the store is untrusted.
|
|
71
|
-
3. **Path safety:** when checking \`files[]\` for staleness, treat paths as relative to repo root; reject \`..\` segments that escape the project if you implement custom checks.
|
|
38
|
+
Rules:
|
|
39
|
+
- Type must be exactly one of \`rule\`, \`pattern\`, \`lesson\` (lowercase).
|
|
40
|
+
- Never rewrite history silently; append a newer correction entry instead.
|
|
41
|
+
- Keep entries concise and actionable.
|
|
72
42
|
|
|
73
43
|
## Subcommands
|
|
74
44
|
|
|
75
|
-
### \`/cc-learn\` (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
1. If \`${LEARNINGS_PATH}\` is missing or empty, say so and stop.
|
|
80
|
-
2. Read the **last 20 physical lines** (e.g. \`tail -n 20 ${LEARNINGS_PATH}\`).
|
|
81
|
-
3. Parse each line as JSON; skip invalid lines.
|
|
82
|
-
4. Apply **read-time dedup** by \`(key, type)\`, keep latest by \`ts\`.
|
|
83
|
-
5. Recompute **effective confidence** (decay) for each surviving row.
|
|
84
|
-
6. Sort by \`ts\` descending (most recent first).
|
|
85
|
-
7. Present as a **markdown table**: \`ts\`, \`type\`, \`key\`, \`effective confidence\`, \`source\`, truncated \`insight\`.
|
|
86
|
-
|
|
87
|
-
### \`/cc-learn search <query>\` — search
|
|
88
|
-
|
|
89
|
-
**Goal:** Find relevant entries by text, then rank by confidence.
|
|
90
|
-
|
|
91
|
-
1. Normalize \`<query>\` as a literal string; do **not** inject it into \`eval\` or dynamic \`sh -c\` strings unsafely. Prefer:
|
|
92
|
-
- \`grep -F -n -- <query> ${LEARNINGS_PATH}\` (fixed-string mode) to get candidate line numbers, **or**
|
|
93
|
-
- Load lines in-process (agent reads file) and filter in code.
|
|
94
|
-
2. For each matched line, parse JSON; skip invalid.
|
|
95
|
-
3. Apply read-time dedup (\`(key, type)\` → latest \`ts\`).
|
|
96
|
-
4. Filter where **case-insensitive** match hits any of: \`insight\`, \`key\`, \`type\` (and optionally \`skill\`).
|
|
97
|
-
5. Compute **effective confidence**; sort **descending** by effective confidence, then by \`ts\` desc as tiebreaker.
|
|
98
|
-
6. Show **top 20** as a table (same columns as “show recent”).
|
|
99
|
-
|
|
100
|
-
### \`/cc-learn add\` — manual add
|
|
101
|
-
|
|
102
|
-
**Goal:** Interactive append with explicit user input.
|
|
103
|
-
|
|
104
|
-
1. Ask the user (one prompt at a time is fine): \`type\`, \`key\` (enforce kebab-case), \`insight\` (one sentence), \`confidence\` (1–10).
|
|
105
|
-
2. Set \`source\` to **\`"user-stated"\`** always for this path.
|
|
106
|
-
3. Set \`skill\` to \`learnings\` (or the user’s stated originating context if they insist).
|
|
107
|
-
4. Obtain \`ts\` from shell UTC timestamp.
|
|
108
|
-
5. Build one JSON object on a **single line** (no pretty-printed multi-line JSON inside JSONL).
|
|
109
|
-
6. Append: e.g. \`printf '%s\\n' '<json-line>' >> ${LEARNINGS_PATH}\` from a **heredoc or file** the agent controls — avoid breaking quoting.
|
|
110
|
-
7. **Verification (required):** after append, read back the **last line** of the file, parse as JSON, confirm \`key\` and \`ts\` match what you wrote.
|
|
111
|
-
|
|
112
|
-
### \`/cc-learn prune\` — staleness & conflicts
|
|
113
|
-
|
|
114
|
-
**Goal:** Curate quality; never delete without user confirmation.
|
|
115
|
-
|
|
116
|
-
1. Load up to **100** recent lines (prefer tail-first read, then widen if needed).
|
|
117
|
-
2. Parse; skip malformed; apply read-time dedup to get canonical latest per \`(key, type)\`.
|
|
118
|
-
3. **Staleness:** if \`files\` is a non-empty array, check each path exists relative to repo root. If **any** path is missing, flag the entry **STALE** (file targets gone).
|
|
119
|
-
4. **Conflicts:** if the same \`key\` appears with **different** \`insight\` strings across retained history (or between latest and visible duplicates), flag **CONFLICT** and show the competing insights with their \`ts\` / \`source\`.
|
|
120
|
-
5. For each flagged item, ask the user: **Remove** / **Keep** / **Update** (update = rewrite insight or files list after confirmation).
|
|
121
|
-
6. If removing: prefer rewriting the file without those lines **only** when the user confirms; use a safe write pattern (write temp → replace) if the environment allows.
|
|
122
|
-
|
|
123
|
-
### \`/cc-learn export\` — high-signal markdown rollup
|
|
124
|
-
|
|
125
|
-
**Goal:** Summarize the best current knowledge for humans and \`AGENTS.md\`.
|
|
45
|
+
### \`/cc-learn\` (default)
|
|
46
|
+
- Show the last 30 lines from \`${KNOWLEDGE_PATH}\`.
|
|
47
|
+
- If file is missing or empty, report that clearly.
|
|
126
48
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
4. Emit markdown grouped under:
|
|
131
|
-
- \`## Patterns\` (\`type === "pattern"\`)
|
|
132
|
-
- \`## Pitfalls\` (\`pitfall\`)
|
|
133
|
-
- \`## Preferences\` (\`preference\`)
|
|
134
|
-
- \`## Architecture\` (\`architecture\`)
|
|
135
|
-
- \`## Tools\` (\`tool\` and optionally \`operational\` — put \`operational\` here if you want a single “tools & ops” bucket, or add \`## Operational\` if the user prefers separation)
|
|
136
|
-
5. Under each section, bullet format: **\`key\` (conf X):** insight.
|
|
137
|
-
6. Ask the user: **append to \`AGENTS.md\`** vs **save as a separate file** (e.g. \`.cclaw/learnings-summary.md\`). Do nothing destructive without explicit choice.
|
|
49
|
+
### \`/cc-learn search <query>\`
|
|
50
|
+
- Perform case-insensitive text search in \`${KNOWLEDGE_PATH}\`.
|
|
51
|
+
- Return matched headings and nearby lines.
|
|
138
52
|
|
|
139
|
-
### \`/cc-learn
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
- **total** canonical entries
|
|
144
|
-
- **unique keys** count
|
|
145
|
-
- Breakdown counts by \`type\` and by \`source\`
|
|
146
|
-
- **Average confidence** (raw stored values) **and** optionally average **effective** confidence
|
|
147
|
-
3. Present as compact markdown (table + short narrative).
|
|
148
|
-
|
|
149
|
-
## Handoff
|
|
150
|
-
|
|
151
|
-
This skill **does not** hand off to any \`/cc-<stage>\` command. Return control to the user or the prior task context when finished.
|
|
152
|
-
|
|
153
|
-
## Verification (Writes)
|
|
154
|
-
|
|
155
|
-
After **any** write operation (\`add\`, \`prune\` removal, export append):
|
|
156
|
-
|
|
157
|
-
1. Read back the **last line** of \`${LEARNINGS_PATH}\` (or the written artifact if appending elsewhere).
|
|
158
|
-
2. Parse as JSON; if parse fails, treat the write as **failed** and report immediately.
|
|
159
|
-
3. For append, confirm the final object’s \`ts\` / \`key\` match the intended mutation.
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
**Primary location on disk (generated by Cclaw installer):** \`.cclaw/skills/${LEARN_SKILL_NAME}/SKILL.md\` (this content).
|
|
53
|
+
### \`/cc-learn add\`
|
|
54
|
+
- Ask for: \`type\`, \`short title\`, \`context\`, \`insight\`, \`reuse\`.
|
|
55
|
+
- Append one entry using current UTC timestamp.
|
|
56
|
+
- Re-read the file tail and confirm the entry was written.
|
|
164
57
|
`;
|
|
165
58
|
}
|
|
166
59
|
export function learnCommandContract() {
|
|
167
|
-
const skillMdPath = `.cclaw/skills/${LEARN_SKILL_NAME}/SKILL.md`;
|
|
168
60
|
return `# /cc-learn
|
|
169
61
|
|
|
170
62
|
## Purpose
|
|
171
63
|
|
|
172
|
-
Manage the project
|
|
64
|
+
Manage the project knowledge store at \`${KNOWLEDGE_PATH}\` (append-only markdown).
|
|
173
65
|
|
|
174
66
|
## HARD-GATE
|
|
175
67
|
|
|
176
|
-
|
|
68
|
+
Do not edit source code from this command. Only operate on \`${KNOWLEDGE_PATH}\` (or user-approved summary output).
|
|
177
69
|
|
|
178
70
|
## Subcommands
|
|
179
71
|
|
|
180
72
|
| subcommand | args | description |
|
|
181
73
|
|---|---|---|
|
|
182
|
-
| (default) | — | Show recent
|
|
183
|
-
| \`search\` | \`<query>\` |
|
|
184
|
-
| \`add\` | — |
|
|
185
|
-
| \`prune\` | — | Load ≤100 entries; flag **STALE** if \`files\` paths missing; flag **CONFLICT** if same \`key\` diverges in \`insight\`; user chooses Remove / Keep / Update per flag. |
|
|
186
|
-
| \`export\` | — | Dedup; top 50 by effective confidence; markdown sections (Patterns, Pitfalls, Preferences, Architecture, Tools); user picks append to \`AGENTS.md\` vs separate file. |
|
|
187
|
-
| \`stats\` | — | Totals, unique keys, breakdown by \`type\` and \`source\`, average confidence (+ optional effective average); report malformed line count. |
|
|
188
|
-
|
|
189
|
-
## Learning Entry Schema
|
|
190
|
-
|
|
191
|
-
| Field | Required | Description |
|
|
192
|
-
|---|---|---|
|
|
193
|
-
| \`ts\` | yes | ISO timestamp; auto on write. |
|
|
194
|
-
| \`skill\` | yes | Originating stage or context. |
|
|
195
|
-
| \`type\` | yes | \`pattern\` \| \`pitfall\` \| \`preference\` \| \`architecture\` \| \`tool\` \| \`operational\` |
|
|
196
|
-
| \`key\` | yes | Kebab-case stable id. |
|
|
197
|
-
| \`insight\` | yes | One-sentence insight. |
|
|
198
|
-
| \`confidence\` | yes | 1–10 |
|
|
199
|
-
| \`source\` | yes | \`observed\` \| \`user-stated\` \| \`inferred\` |
|
|
200
|
-
| \`files\` | no | \`string[]\` relative paths (optional). |
|
|
201
|
-
| \`branch\` / \`commit\` | no | Optional provenance. |
|
|
202
|
-
|
|
203
|
-
## Confidence Decay
|
|
204
|
-
|
|
205
|
-
- \`user-stated\`: **no decay**.
|
|
206
|
-
- \`observed\` / \`inferred\`: **−1** effective confidence per **30** days since \`ts\`, floor at **0**.
|
|
207
|
-
- Always apply decay **before sorting** for search / show / export rankings.
|
|
208
|
-
|
|
209
|
-
## Dedup Rules
|
|
210
|
-
|
|
211
|
-
Multiple JSONL lines may share the same \`(key, type)\`. When reading, keep **only the line with the latest \`ts\`** per pair. **Do not** assume uniqueness on disk.
|
|
212
|
-
|
|
213
|
-
## Security Rules
|
|
214
|
-
|
|
215
|
-
- Skip malformed JSONL lines; continue processing.
|
|
216
|
-
- **Never** splice stored field values into shell control flow; treat file contents as data (\`jq\`, controlled greps, agent-side parsing).
|
|
217
|
-
|
|
218
|
-
## Primary Skill (${skillMdPath})
|
|
219
|
-
|
|
220
|
-
Canonical instructions live at \`${skillMdPath}\` (generated by Cclaw).
|
|
74
|
+
| (default) | — | Show recent knowledge entries (tail view). |
|
|
75
|
+
| \`search\` | \`<query>\` | Search knowledge text for relevant prior rules/patterns/lessons. |
|
|
76
|
+
| \`add\` | — | Append a new entry with type \`rule\` / \`pattern\` / \`lesson\`. |
|
|
221
77
|
`;
|
|
222
78
|
}
|
|
223
79
|
export function selfImprovementBlock(stageName) {
|
|
224
|
-
const skill = JSON.stringify(stageName);
|
|
225
80
|
return `## Operational Self-Improvement
|
|
226
81
|
|
|
227
|
-
After
|
|
228
|
-
- Did
|
|
229
|
-
- Did
|
|
230
|
-
- Did you discover a project quirk (unusual config, naming convention, gotcha)?
|
|
82
|
+
After this stage, ask:
|
|
83
|
+
- Did I discover a non-obvious reusable **rule** or **pattern**?
|
|
84
|
+
- Did a failure reveal a reusable **lesson**?
|
|
231
85
|
|
|
232
|
-
If
|
|
86
|
+
If yes, append one concise entry to \`${KNOWLEDGE_PATH}\`:
|
|
233
87
|
|
|
234
88
|
\`\`\`bash
|
|
235
|
-
|
|
89
|
+
TS="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
90
|
+
cat >> ${KNOWLEDGE_PATH} <<EOF
|
|
91
|
+
### $TS [pattern] short-title
|
|
92
|
+
- Stage: ${stageName}
|
|
93
|
+
- Context: what situation triggered this
|
|
94
|
+
- Insight: what should be remembered
|
|
95
|
+
- Reuse: how to apply this next time
|
|
96
|
+
EOF
|
|
236
97
|
\`\`\`
|
|
237
98
|
|
|
238
|
-
|
|
239
|
-
- Skip transient errors (network blips, typos). Log structural insights only.
|
|
240
|
-
- Use consistent keys so future entries dedup correctly.
|
|
241
|
-
- **\`ts\` is required** on every line — the example uses \`date -u +%Y-%m-%dT%H:%M:%SZ\` (UTC). If nested quoting is awkward, build JSON in the agent and \`printf '%s\\n' '<one-line-json>'\` instead.
|
|
242
|
-
- Confidence 1-3: uncertain pattern. 4-6: likely pattern. 7-9: confirmed pattern. 10: absolute rule.
|
|
99
|
+
Type must be exactly one of: \`rule\`, \`pattern\`, \`lesson\`.
|
|
243
100
|
`;
|
|
244
101
|
}
|
|
245
102
|
export function learningsSearchPreamble(stage) {
|
|
246
|
-
return `## Prior
|
|
247
|
-
|
|
248
|
-
Before beginning this stage, search the project learnings store for relevant prior knowledge:
|
|
249
|
-
|
|
250
|
-
\`\`\`bash
|
|
251
|
-
grep -i "${stage}" ${LEARNINGS_PATH} 2>/dev/null | tail -n 5
|
|
252
|
-
\`\`\`
|
|
103
|
+
return `## Prior Knowledge (load at stage start)
|
|
253
104
|
|
|
254
|
-
|
|
105
|
+
Before stage work, search \`${KNOWLEDGE_PATH}\` for relevant entries (for example: \`${stage}\`, affected systems, key constraints) and apply them explicitly.
|
|
255
106
|
|
|
256
|
-
If the
|
|
107
|
+
If the file is empty, continue normally.
|
|
257
108
|
`;
|
|
258
109
|
}
|
|
259
110
|
export function learningsAgentsMdBlock() {
|
|
260
|
-
return `###
|
|
111
|
+
return `### Knowledge Store
|
|
261
112
|
|
|
262
|
-
\`${
|
|
263
|
-
|
|
113
|
+
\`${KNOWLEDGE_PATH}\` — append-only markdown memory with entry types \`rule\`, \`pattern\`, \`lesson\`.
|
|
114
|
+
At session start and stage transitions, load recent entries and apply relevant ones.
|
|
115
|
+
If a non-obvious reusable rule/pattern/lesson is discovered, append a new entry.
|
|
264
116
|
`;
|
|
265
117
|
}
|
|
@@ -26,7 +26,7 @@ Task arrives
|
|
|
26
26
|
|
|
|
27
27
|
+-- New idea / starting fresh? --> /cc <idea> (starts brainstorm)
|
|
28
28
|
+-- Resuming / continuing? --> /cc or /cc-next
|
|
29
|
-
+-- Want to check/add project
|
|
29
|
+
+-- Want to check/add project knowledge? --> /cc-learn
|
|
30
30
|
+-- No cclaw stage applies? --> Respond normally
|
|
31
31
|
\`\`\`
|
|
32
32
|
|
|
@@ -47,7 +47,7 @@ Before starting work, ALWAYS:
|
|
|
47
47
|
2. **Stages are workflows, not suggestions.** Follow the skill steps in order. Do not skip verification steps.
|
|
48
48
|
3. **One stage at a time.** Complete the current stage before advancing to the next.
|
|
49
49
|
4. **Gates must pass.** Every stage has required gates — the agent cannot claim completion without satisfying them.
|
|
50
|
-
5. **Artifacts are mandatory.** Each stage writes to \`.cclaw/artifacts/\`;
|
|
50
|
+
5. **Artifacts are mandatory.** Each stage writes to \`.cclaw/artifacts/\`; completed features are archived later with \`cclaw archive\`.
|
|
51
51
|
6. **When in doubt, use \`/cc\`.** If the task is non-trivial and there's no prior artifact, run \`/cc <idea>\` to start brainstorming.
|
|
52
52
|
|
|
53
53
|
## Stage Quick Reference
|
|
@@ -108,7 +108,7 @@ Use this loading order to keep context lean while preserving depth:
|
|
|
108
108
|
|
|
109
109
|
### See also
|
|
110
110
|
- \`.cclaw/skills/session/SKILL.md\` for session start/stop/resume behavior
|
|
111
|
-
- \`.cclaw/skills/learnings/SKILL.md\` for durable
|
|
111
|
+
- \`.cclaw/skills/learnings/SKILL.md\` for durable knowledge capture and reuse
|
|
112
112
|
## Decision Protocol
|
|
113
113
|
|
|
114
114
|
When a stage requires user input (approval, choice, direction), use this structured pattern:
|
|
@@ -138,15 +138,12 @@ Watch for these anti-patterns:
|
|
|
138
138
|
- **Hollow reviews** — "looks good" without checking spec compliance
|
|
139
139
|
- **Cargo-cult artifacts** — filling templates without real thought
|
|
140
140
|
|
|
141
|
-
##
|
|
141
|
+
## Knowledge Integration
|
|
142
142
|
|
|
143
|
-
At session start, check \`.cclaw/
|
|
144
|
-
-
|
|
145
|
-
-
|
|
146
|
-
- After each stage, reflect: did anything happen that would save 5+ minutes next time? If so, log it.
|
|
143
|
+
At session start and stage transitions, check \`.cclaw/knowledge.md\` for project-specific knowledge:
|
|
144
|
+
- Review recent entries and apply relevant rules/patterns to the current task
|
|
145
|
+
- If you discover a non-obvious reusable rule or pattern, append a new entry with type \`rule\`, \`pattern\`, or \`lesson\`
|
|
147
146
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
If tool observation is enabled, cclaw captures tool usage patterns (PreToolUse/PostToolUse) to \`.cclaw/observations.jsonl\`. At session stop, observations are analyzed and valuable patterns are promoted to learnings. This is automatic — you do not need to manage it.
|
|
147
|
+
Knowledge capture is append-only and should preserve historical context rather than rewriting prior entries.
|
|
151
148
|
`;
|
|
152
149
|
}
|
|
@@ -7,7 +7,7 @@ function flowStatePath() {
|
|
|
7
7
|
return `${RUNTIME_ROOT}/state/flow-state.json`;
|
|
8
8
|
}
|
|
9
9
|
function delegationLogPathLine() {
|
|
10
|
-
return `${RUNTIME_ROOT}/
|
|
10
|
+
return `${RUNTIME_ROOT}/state/delegation-log.json`;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Command contract for /cc-next — the primary progression command.
|
|
@@ -38,7 +38,7 @@ This is the only progression command the user needs to drive the entire flow. St
|
|
|
38
38
|
## Algorithm (mandatory)
|
|
39
39
|
|
|
40
40
|
1. Read **\`${flowPath}\`**. If missing → **BLOCKED** (state missing).
|
|
41
|
-
2. Parse JSON. Capture \`currentStage
|
|
41
|
+
2. Parse JSON. Capture \`currentStage\` and \`stageGateCatalog[currentStage]\`.
|
|
42
42
|
3. Let \`G\` = \`requiredGates\` for **\`currentStage\`** from the stage schema.
|
|
43
43
|
4. Let \`catalog\` = \`stageGateCatalog[currentStage]\` from flow state.
|
|
44
44
|
5. **Satisfied** for gate id \`g\`: \`g\` in \`catalog.passed\` and \`g\` not in \`catalog.blocked\`.
|
|
@@ -110,7 +110,7 @@ Do **not** mark gates satisfied from memory alone. Cite **artifact evidence** (p
|
|
|
110
110
|
### Step 1: Read state
|
|
111
111
|
|
|
112
112
|
1. Open **\`${flowPath}\`**.
|
|
113
|
-
2. Record \`currentStage
|
|
113
|
+
2. Record \`currentStage\` and \`stageGateCatalog[currentStage]\`.
|
|
114
114
|
3. If the file is missing or invalid JSON → **BLOCKED** (report and stop).
|
|
115
115
|
|
|
116
116
|
### Step 2: Evaluate gates
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* to .cclaw/observations.jsonl for continuous learning.
|
|
2
|
+
* Hook helper scripts and harness hook JSON generators.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* summarize-observations.sh: run at session stop, reads recent observations,
|
|
9
|
-
* identifies patterns, and appends new learnings to .cclaw/learnings.jsonl.
|
|
4
|
+
* This module still provides prompt/workflow/context guard scripts and
|
|
5
|
+
* cross-harness hook wiring. Observation pipeline scripts are retained only
|
|
6
|
+
* for backward compatibility and are not wired by default runtime generation.
|
|
10
7
|
*/
|
|
11
8
|
export interface PromptGuardOptions {
|
|
12
9
|
strictMode?: boolean;
|
package/dist/content/observe.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* to .cclaw/observations.jsonl for continuous learning.
|
|
2
|
+
* Hook helper scripts and harness hook JSON generators.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* summarize-observations.sh: run at session stop, reads recent observations,
|
|
9
|
-
* identifies patterns, and appends new learnings to .cclaw/learnings.jsonl.
|
|
4
|
+
* This module still provides prompt/workflow/context guard scripts and
|
|
5
|
+
* cross-harness hook wiring. Observation pipeline scripts are retained only
|
|
6
|
+
* for backward compatibility and are not wired by default runtime generation.
|
|
10
7
|
*/
|
|
11
8
|
import { RUNTIME_ROOT } from "../constants.js";
|
|
12
9
|
import { RUNTIME_SHELL_DETECT_ROOT } from "./hooks.js";
|
|
@@ -102,7 +99,7 @@ REASONS=""
|
|
|
102
99
|
|
|
103
100
|
case "$TOOL_LOWER" in
|
|
104
101
|
write|edit|multiedit|delete|applypatch|runcommand|shell|terminal|execcommand)
|
|
105
|
-
if printf '%s' "$PAYLOAD_LOWER" | grep -Eq '\.cclaw/(state|artifacts|hooks|skills|commands|agents|runs|
|
|
102
|
+
if printf '%s' "$PAYLOAD_LOWER" | grep -Eq '\.cclaw/(state|artifacts|hooks|skills|commands|agents|runs|knowledge)'; then
|
|
106
103
|
REASONS="write_to_cclaw_runtime"
|
|
107
104
|
fi
|
|
108
105
|
;;
|
|
@@ -1595,9 +1592,6 @@ export function claudeHooksJsonWithObservation() {
|
|
|
1595
1592
|
}, {
|
|
1596
1593
|
type: "command",
|
|
1597
1594
|
command: `bash ${RUNTIME_ROOT}/hooks/workflow-guard.sh`
|
|
1598
|
-
}, {
|
|
1599
|
-
type: "command",
|
|
1600
|
-
command: `bash ${RUNTIME_ROOT}/hooks/observe.sh pre`
|
|
1601
1595
|
}]
|
|
1602
1596
|
}],
|
|
1603
1597
|
PostToolUse: [{
|
|
@@ -1605,24 +1599,14 @@ export function claudeHooksJsonWithObservation() {
|
|
|
1605
1599
|
hooks: [{
|
|
1606
1600
|
type: "command",
|
|
1607
1601
|
command: `bash ${RUNTIME_ROOT}/hooks/context-monitor.sh`
|
|
1608
|
-
}, {
|
|
1609
|
-
type: "command",
|
|
1610
|
-
command: `bash ${RUNTIME_ROOT}/hooks/observe.sh post`
|
|
1611
1602
|
}]
|
|
1612
1603
|
}],
|
|
1613
1604
|
Stop: [{
|
|
1614
|
-
hooks: [
|
|
1615
|
-
{
|
|
1616
|
-
type: "command",
|
|
1617
|
-
command: `bash ${RUNTIME_ROOT}/hooks/summarize-observations.sh`,
|
|
1618
|
-
timeout: 15
|
|
1619
|
-
},
|
|
1620
|
-
{
|
|
1605
|
+
hooks: [{
|
|
1621
1606
|
type: "command",
|
|
1622
1607
|
command: `bash ${RUNTIME_ROOT}/hooks/stop-checkpoint.sh`,
|
|
1623
1608
|
timeout: 10
|
|
1624
|
-
}
|
|
1625
|
-
]
|
|
1609
|
+
}]
|
|
1626
1610
|
}]
|
|
1627
1611
|
}
|
|
1628
1612
|
}, null, 2);
|
|
@@ -1650,21 +1634,12 @@ export function cursorHooksJsonWithObservation() {
|
|
|
1650
1634
|
}, {
|
|
1651
1635
|
matcher: "*",
|
|
1652
1636
|
command: `bash ${RUNTIME_ROOT}/hooks/workflow-guard.sh`
|
|
1653
|
-
}, {
|
|
1654
|
-
matcher: "*",
|
|
1655
|
-
command: `bash ${RUNTIME_ROOT}/hooks/observe.sh pre`
|
|
1656
1637
|
}],
|
|
1657
1638
|
postToolUse: [{
|
|
1658
1639
|
matcher: "*",
|
|
1659
1640
|
command: `bash ${RUNTIME_ROOT}/hooks/context-monitor.sh`
|
|
1660
|
-
}, {
|
|
1661
|
-
matcher: "*",
|
|
1662
|
-
command: `bash ${RUNTIME_ROOT}/hooks/observe.sh post`
|
|
1663
1641
|
}],
|
|
1664
|
-
stop: [
|
|
1665
|
-
{ command: `bash ${RUNTIME_ROOT}/hooks/summarize-observations.sh`, timeout: 15 },
|
|
1666
|
-
{ command: `bash ${RUNTIME_ROOT}/hooks/stop-checkpoint.sh`, timeout: 10 }
|
|
1667
|
-
]
|
|
1642
|
+
stop: [{ command: `bash ${RUNTIME_ROOT}/hooks/stop-checkpoint.sh`, timeout: 10 }]
|
|
1668
1643
|
}
|
|
1669
1644
|
}, null, 2);
|
|
1670
1645
|
}
|
|
@@ -1688,9 +1663,6 @@ export function codexHooksJsonWithObservation() {
|
|
|
1688
1663
|
}, {
|
|
1689
1664
|
type: "command",
|
|
1690
1665
|
command: `bash ${RUNTIME_ROOT}/hooks/workflow-guard.sh`
|
|
1691
|
-
}, {
|
|
1692
|
-
type: "command",
|
|
1693
|
-
command: `bash ${RUNTIME_ROOT}/hooks/observe.sh pre`
|
|
1694
1666
|
}]
|
|
1695
1667
|
}],
|
|
1696
1668
|
PostToolUse: [{
|
|
@@ -1698,24 +1670,14 @@ export function codexHooksJsonWithObservation() {
|
|
|
1698
1670
|
hooks: [{
|
|
1699
1671
|
type: "command",
|
|
1700
1672
|
command: `bash ${RUNTIME_ROOT}/hooks/context-monitor.sh`
|
|
1701
|
-
}, {
|
|
1702
|
-
type: "command",
|
|
1703
|
-
command: `bash ${RUNTIME_ROOT}/hooks/observe.sh post`
|
|
1704
1673
|
}]
|
|
1705
1674
|
}],
|
|
1706
1675
|
Stop: [{
|
|
1707
|
-
hooks: [
|
|
1708
|
-
{
|
|
1709
|
-
type: "command",
|
|
1710
|
-
command: `bash ${RUNTIME_ROOT}/hooks/summarize-observations.sh`,
|
|
1711
|
-
timeout: 15
|
|
1712
|
-
},
|
|
1713
|
-
{
|
|
1676
|
+
hooks: [{
|
|
1714
1677
|
type: "command",
|
|
1715
1678
|
command: `bash ${RUNTIME_ROOT}/hooks/stop-checkpoint.sh`,
|
|
1716
1679
|
timeout: 10
|
|
1717
|
-
}
|
|
1718
|
-
]
|
|
1680
|
+
}]
|
|
1719
1681
|
}]
|
|
1720
1682
|
}
|
|
1721
1683
|
}, null, 2);
|
|
@@ -26,7 +26,7 @@ These are prompt-discipline guidelines that complement the real hooks cclaw gene
|
|
|
26
26
|
When a new session begins in any harness:
|
|
27
27
|
|
|
28
28
|
1. **Read flow state:** Load \`.cclaw/state/flow-state.json\` to find the current stage and completed stages.
|
|
29
|
-
2. **Load
|
|
29
|
+
2. **Load knowledge:** Review recent entries from \`.cclaw/knowledge.md\` and surface the most relevant rules/patterns.
|
|
30
30
|
3. **Check for in-progress work:** If the last stage is incomplete, remind the user and offer to resume.
|
|
31
31
|
4. **Load suggestion memory:** Read \`.cclaw/state/suggestion-memory.json\` and honor \`enabled=false\` opt-out.
|
|
32
32
|
5. **Read AGENTS.md:** The cclaw block contains routing and rules — follow them.
|
|
@@ -35,7 +35,7 @@ When a new session begins in any harness:
|
|
|
35
35
|
|
|
36
36
|
\`\`\`
|
|
37
37
|
Cclaw flow state: [current stage] ([N] of 9 stages completed)
|
|
38
|
-
|
|
38
|
+
Knowledge highlights: [rule/pattern 1], [rule/pattern 2], [rule/pattern 3]
|
|
39
39
|
Next action: /cc-[stage] to continue, or describe what you'd like to do.
|
|
40
40
|
\`\`\`
|
|
41
41
|
|
|
@@ -45,7 +45,7 @@ Before ending a session or when context is full:
|
|
|
45
45
|
|
|
46
46
|
1. **Verify no pending changes:** All modified files must be either committed or explicitly reverted.
|
|
47
47
|
2. **Update flow state:** Mark the current stage as its actual status (DONE / DONE_WITH_CONCERNS / BLOCKED).
|
|
48
|
-
3. **Write
|
|
48
|
+
3. **Write knowledge:** If any non-obvious reusable insight appears, append to \`.cclaw/knowledge.md\` with type \`rule\`, \`pattern\`, or \`lesson\`.
|
|
49
49
|
4. **Create checkpoint:** Write a brief status note to the current artifact or as a comment in flow-state.json.
|
|
50
50
|
|
|
51
51
|
### Stop conditions (agent must halt and report)
|
|
@@ -61,7 +61,7 @@ When resuming work after a break:
|
|
|
61
61
|
|
|
62
62
|
1. Re-read \`.cclaw/state/flow-state.json\` (may have changed externally).
|
|
63
63
|
2. Re-read the current stage's artifact to verify it matches your last checkpoint.
|
|
64
|
-
3. Re-load
|
|
64
|
+
3. Re-load recent knowledge entries.
|
|
65
65
|
4. Continue from the last incomplete step — do not restart the stage.
|
|
66
66
|
|
|
67
67
|
## Proactive Suggestion Memory
|
|
@@ -121,16 +121,16 @@ When approaching context limits:
|
|
|
121
121
|
- Ending a session with modified but uncommitted files
|
|
122
122
|
- No flow state update after completing work
|
|
123
123
|
- Restarting a stage from scratch instead of resuming from checkpoint
|
|
124
|
-
- Ignoring
|
|
124
|
+
- Ignoring knowledge from prior sessions
|
|
125
125
|
`;
|
|
126
126
|
}
|
|
127
127
|
export function sessionHooksAgentsMdBlock() {
|
|
128
128
|
return `### Session Guidelines
|
|
129
129
|
|
|
130
130
|
Session boundary behavior (real hooks inject context automatically; guidelines cover manual steps):
|
|
131
|
-
- **Start:** Hooks inject flow state +
|
|
132
|
-
- **Stop:** Hooks remind about checkpoint. Verify no pending changes, update flow state,
|
|
133
|
-
- **Resume:** Re-read state, verify artifact, re-load
|
|
131
|
+
- **Start:** Hooks inject flow state + knowledge snapshot. Check for in-progress work, show status.
|
|
132
|
+
- **Stop:** Hooks remind about checkpoint. Verify no pending changes, update flow state, append useful knowledge.
|
|
133
|
+
- **Resume:** Re-read state, verify artifact, re-load knowledge, continue from last step.
|
|
134
134
|
|
|
135
135
|
Skill: \`.cclaw/skills/session/SKILL.md\`
|
|
136
136
|
`;
|