cclaw-cli 0.1.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/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +101 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.js +70 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.js +50 -0
- package/dist/content/agents.d.ts +39 -0
- package/dist/content/agents.js +244 -0
- package/dist/content/autoplan.d.ts +7 -0
- package/dist/content/autoplan.js +297 -0
- package/dist/content/contracts.d.ts +2 -0
- package/dist/content/contracts.js +50 -0
- package/dist/content/examples.d.ts +2 -0
- package/dist/content/examples.js +327 -0
- package/dist/content/hooks.d.ts +16 -0
- package/dist/content/hooks.js +753 -0
- package/dist/content/learnings.d.ts +5 -0
- package/dist/content/learnings.js +265 -0
- package/dist/content/meta-skill.d.ts +10 -0
- package/dist/content/meta-skill.js +137 -0
- package/dist/content/observe.d.ts +21 -0
- package/dist/content/observe.js +1110 -0
- package/dist/content/session-hooks.d.ts +7 -0
- package/dist/content/session-hooks.js +137 -0
- package/dist/content/skills.d.ts +3 -0
- package/dist/content/skills.js +257 -0
- package/dist/content/stage-schema.d.ts +78 -0
- package/dist/content/stage-schema.js +1453 -0
- package/dist/content/subagents.d.ts +13 -0
- package/dist/content/subagents.js +616 -0
- package/dist/content/templates.d.ts +3 -0
- package/dist/content/templates.js +272 -0
- package/dist/content/utility-skills.d.ts +12 -0
- package/dist/content/utility-skills.js +467 -0
- package/dist/doctor.d.ts +7 -0
- package/dist/doctor.js +610 -0
- package/dist/flow-state.d.ts +19 -0
- package/dist/flow-state.js +41 -0
- package/dist/fs-utils.d.ts +5 -0
- package/dist/fs-utils.js +28 -0
- package/dist/gitignore.d.ts +3 -0
- package/dist/gitignore.js +43 -0
- package/dist/harness-adapters.d.ts +12 -0
- package/dist/harness-adapters.js +175 -0
- package/dist/install.d.ts +9 -0
- package/dist/install.js +562 -0
- package/dist/learnings-summarizer.d.ts +25 -0
- package/dist/learnings-summarizer.js +201 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.js +6 -0
- package/dist/policy.d.ts +6 -0
- package/dist/policy.js +179 -0
- package/dist/runs.d.ts +18 -0
- package/dist/runs.js +446 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.js +12 -0
- package/package.json +47 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function learnSkillMarkdown(): string;
|
|
2
|
+
export declare function learnCommandContract(): string;
|
|
3
|
+
export declare function selfImprovementBlock(stageName: string): string;
|
|
4
|
+
export declare function learningsSearchPreamble(stage: string): string;
|
|
5
|
+
export declare function learningsAgentsMdBlock(): string;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Learnings — markdown for /cc-learn skill, command contract, and AGENTS.md
|
|
3
|
+
// Cclaw emits instructions only; agents use shell tools against JSONL on disk.
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
const LEARNINGS_PATH = ".cclaw/learnings.jsonl";
|
|
6
|
+
const LEARN_SKILL_NAME = "learnings";
|
|
7
|
+
const LEARN_SKILL_DESCRIPTION = "Project-scoped learnings store: read, search, add, prune, export, and stats for .cclaw/learnings.jsonl via shell tools (never edits application code).";
|
|
8
|
+
export function learnSkillMarkdown() {
|
|
9
|
+
return `---
|
|
10
|
+
name: ${LEARN_SKILL_NAME}
|
|
11
|
+
description: "${LEARN_SKILL_DESCRIPTION}"
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# ${LEARN_SKILL_NAME}
|
|
15
|
+
|
|
16
|
+
## Overview
|
|
17
|
+
|
|
18
|
+
This skill governs **${LEARNINGS_PATH}** — a project-scoped knowledge base that compounds over time. Each line is one JSON object (JSONL). Cclaw generates these instructions; **you** (the agent) perform reads and writes using shell tools (\`cat\`, \`tail\`, \`grep\`, \`jq\`, etc.) in the user's workspace.
|
|
19
|
+
|
|
20
|
+
Treat learnings as durable project memory: patterns, pitfalls, preferences, architecture notes, tool quirks, and operational shortcuts that save real time on future sessions.
|
|
21
|
+
|
|
22
|
+
## HARD-GATE
|
|
23
|
+
|
|
24
|
+
**Never modify production or application source code from this skill.** Commands under \`/cc-learn\` manage the **knowledge store only** (\`${LEARNINGS_PATH}\`, optional exports). Do not refactor, fix bugs, or change configs "while you are here" unless the user explicitly asked for that work outside \`/cc-learn\`.
|
|
25
|
+
|
|
26
|
+
- Allowed: read/write **${LEARNINGS_PATH}**, generate markdown summaries for the user, optional append to \`AGENTS.md\` when the user approves.
|
|
27
|
+
- Forbidden: using learnings maintenance as a pretext to touch unrelated code paths.
|
|
28
|
+
|
|
29
|
+
## Learning Entry Schema
|
|
30
|
+
|
|
31
|
+
| Field | Required | Description |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| \`ts\` | yes (on write) | ISO-8601 UTC timestamp. **Auto-inject** on every append; never rely on the model to invent wall-clock time — use the shell (\`date -u +%Y-%m-%dT%H:%M:%SZ\`) or equivalent and embed in JSON. |
|
|
34
|
+
| \`skill\` | yes | Originating Cclaw stage or context (e.g. \`brainstorm\`, \`scope\`, \`learnings\`). |
|
|
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":"build","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"]}
|
|
48
|
+
\`\`\`
|
|
49
|
+
|
|
50
|
+
## Confidence Decay Rules
|
|
51
|
+
|
|
52
|
+
Decay applies **when searching, ranking, or presenting** entries — not necessarily when rewriting the file.
|
|
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.
|
|
72
|
+
|
|
73
|
+
## Subcommands
|
|
74
|
+
|
|
75
|
+
### \`/cc-learn\` (no arguments) — show recent
|
|
76
|
+
|
|
77
|
+
**Goal:** Give a quick, deduped view of the latest activity.
|
|
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\`.
|
|
126
|
+
|
|
127
|
+
1. Parse full file or a bounded read if huge; skip malformed.
|
|
128
|
+
2. Read-time dedup by \`(key, type)\`.
|
|
129
|
+
3. Compute effective confidence; take **top 50** by effective confidence (tiebreak: newer \`ts\`).
|
|
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.
|
|
138
|
+
|
|
139
|
+
### \`/cc-learn stats\` — inventory
|
|
140
|
+
|
|
141
|
+
1. Parse all lines; count **skipped malformed** separately.
|
|
142
|
+
2. After read-time dedup (canonical latest per \`(key, type)\`):
|
|
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).
|
|
164
|
+
`;
|
|
165
|
+
}
|
|
166
|
+
export function learnCommandContract() {
|
|
167
|
+
const skillMdPath = `.cclaw/skills/${LEARN_SKILL_NAME}/SKILL.md`;
|
|
168
|
+
return `# /cc-learn
|
|
169
|
+
|
|
170
|
+
## Purpose
|
|
171
|
+
|
|
172
|
+
Manage the project learnings JSONL store at \`${LEARNINGS_PATH}\`: inspect recent entries, search, manually append, prune stale or conflicting records, export a high-confidence markdown digest, and print aggregate stats. This command is **knowledge-store only** — it is not an excuse to edit application code.
|
|
173
|
+
|
|
174
|
+
## HARD-GATE
|
|
175
|
+
|
|
176
|
+
Never modify production or application source code while executing \`/cc-learn\`. Only touch \`${LEARNINGS_PATH}\` (and user-approved summary targets like \`AGENTS.md\` or \`.cclaw/learnings-summary.md\`).
|
|
177
|
+
|
|
178
|
+
## Subcommands
|
|
179
|
+
|
|
180
|
+
| subcommand | args | description |
|
|
181
|
+
|---|---|---|
|
|
182
|
+
| (default) | — | Show recent: tail 20 lines, dedup by \`(key,type)\` latest \`ts\`, apply decay for display, table output. |
|
|
183
|
+
| \`search\` | \`<query>\` | \`grep -F\` or in-agent scan for \`<query>\` across \`insight\` / \`key\` / \`type\`; dedup; decay; top 20 by effective confidence. |
|
|
184
|
+
| \`add\` | — | Prompt user for \`type\`, \`key\`, \`insight\`, \`confidence\`; set \`source: "user-stated"\`; inject \`ts\`; append one JSON line; verify by reading last line. |
|
|
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).
|
|
221
|
+
`;
|
|
222
|
+
}
|
|
223
|
+
export function selfImprovementBlock(stageName) {
|
|
224
|
+
const skill = JSON.stringify(stageName);
|
|
225
|
+
return `## Operational Self-Improvement
|
|
226
|
+
|
|
227
|
+
After completing this stage, reflect briefly:
|
|
228
|
+
- Did any command fail unexpectedly?
|
|
229
|
+
- Did you backtrack or retry something that a hint would have prevented?
|
|
230
|
+
- Did you discover a project quirk (unusual config, naming convention, gotcha)?
|
|
231
|
+
|
|
232
|
+
If an insight would save **5+ minutes next time**, log it:
|
|
233
|
+
|
|
234
|
+
\`\`\`bash
|
|
235
|
+
echo '{"skill":${skill},"type":"operational","key":"[kebab-case-key]","insight":"[one sentence]","confidence":7,"source":"observed","ts":"'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"}' >> .cclaw/learnings.jsonl
|
|
236
|
+
\`\`\`
|
|
237
|
+
|
|
238
|
+
Guidelines:
|
|
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.
|
|
243
|
+
`;
|
|
244
|
+
}
|
|
245
|
+
export function learningsSearchPreamble(stage) {
|
|
246
|
+
return `## Prior Learnings (load at stage start)
|
|
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
|
+
\`\`\`
|
|
253
|
+
|
|
254
|
+
If learnings are found, incorporate them into your analysis. When a finding matches a past learning, note: **"Prior learning applied: [key] (confidence N/10)"**.
|
|
255
|
+
|
|
256
|
+
If the store is empty or the file does not exist, skip this step silently.
|
|
257
|
+
`;
|
|
258
|
+
}
|
|
259
|
+
export function learningsAgentsMdBlock() {
|
|
260
|
+
return `### Learnings Store
|
|
261
|
+
|
|
262
|
+
\`${LEARNINGS_PATH}\` — JSONL knowledge base. At session start: \`tail -n 20 ${LEARNINGS_PATH}\` → parse → dedup by \`(key,type)\` → decay → show top 3.
|
|
263
|
+
After each stage: follow "Operational Self-Improvement" block. Manage: \`/cc-learn\` (show | search | add | prune | export | stats).
|
|
264
|
+
`;
|
|
265
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* using-cclaw meta-skill — injected at SessionStart via hooks.
|
|
3
|
+
*
|
|
4
|
+
* Like agent-skills' using-agent-skills, this teaches the agent HOW to use
|
|
5
|
+
* cclaw: skill discovery flowchart, activation rules, skill behaviors.
|
|
6
|
+
* The full text is injected by session-start.sh so the agent always has
|
|
7
|
+
* routing context without needing to read files first.
|
|
8
|
+
*/
|
|
9
|
+
export declare const META_SKILL_NAME = "using-cclaw";
|
|
10
|
+
export declare function usingCclawSkillMarkdown(): string;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* using-cclaw meta-skill — injected at SessionStart via hooks.
|
|
3
|
+
*
|
|
4
|
+
* Like agent-skills' using-agent-skills, this teaches the agent HOW to use
|
|
5
|
+
* cclaw: skill discovery flowchart, activation rules, skill behaviors.
|
|
6
|
+
* The full text is injected by session-start.sh so the agent always has
|
|
7
|
+
* routing context without needing to read files first.
|
|
8
|
+
*/
|
|
9
|
+
export const META_SKILL_NAME = "using-cclaw";
|
|
10
|
+
export function usingCclawSkillMarkdown() {
|
|
11
|
+
return `---
|
|
12
|
+
name: using-cclaw
|
|
13
|
+
description: "Meta-skill: discovers and activates the right cclaw stage for the current task. Injected at every session start. This is the routing brain — follow the flowchart before starting any work."
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# Using Cclaw
|
|
17
|
+
|
|
18
|
+
This meta-skill helps you discover and apply the right cclaw stage for the current task. It is injected at every session start so you always have routing context.
|
|
19
|
+
|
|
20
|
+
## Skill Discovery Flowchart
|
|
21
|
+
|
|
22
|
+
When a task arrives, identify the development phase and invoke the matching command:
|
|
23
|
+
|
|
24
|
+
\`\`\`
|
|
25
|
+
Task arrives
|
|
26
|
+
|
|
|
27
|
+
+-- Vague idea / needs exploration? --> /cc-brainstorm
|
|
28
|
+
+-- Need to shape scope / challenge premises? --> /cc-scope
|
|
29
|
+
+-- Have scope, need architecture / design lock? --> /cc-design
|
|
30
|
+
+-- Have design, need formal specification? --> /cc-spec
|
|
31
|
+
+-- Have spec, need task breakdown / plan? --> /cc-plan
|
|
32
|
+
+-- Have plan, need to write tests first? --> /cc-test
|
|
33
|
+
+-- Have failing tests, need implementation? --> /cc-build
|
|
34
|
+
+-- Have implementation, need review? --> /cc-review
|
|
35
|
+
+-- Reviewed and approved, need to ship? --> /cc-ship
|
|
36
|
+
|
|
|
37
|
+
+-- Cross-cutting:
|
|
38
|
+
| +-- Want to check/add project learnings? --> /cc-learn
|
|
39
|
+
| +-- Want full brainstorm-to-plan in one shot? --> /cc-autoplan
|
|
40
|
+
|
|
|
41
|
+
+-- No cclaw stage applies? --> Respond normally
|
|
42
|
+
\`\`\`
|
|
43
|
+
|
|
44
|
+
## Flow State Check
|
|
45
|
+
|
|
46
|
+
Before starting work, ALWAYS:
|
|
47
|
+
|
|
48
|
+
1. Read \`.cclaw/state/flow-state.json\` for the current stage.
|
|
49
|
+
2. If a stage is active, invoke the matching \`/cc-*\` command.
|
|
50
|
+
3. If no stage applies (e.g. simple question, unrelated task), respond normally.
|
|
51
|
+
|
|
52
|
+
## Activation Rules
|
|
53
|
+
|
|
54
|
+
1. **Check for an applicable stage before starting work.** Stages encode processes that prevent common mistakes.
|
|
55
|
+
2. **Stages are workflows, not suggestions.** Follow the skill steps in order. Do not skip verification steps.
|
|
56
|
+
3. **One stage at a time.** Complete the current stage before advancing to the next.
|
|
57
|
+
4. **Gates must pass.** Every stage has required gates — the agent cannot claim completion without satisfying them.
|
|
58
|
+
5. **Artifacts are mandatory.** Each stage writes to \`.cclaw/artifacts/\` and keeps the active run copy in \`.cclaw/runs/<activeRunId>/artifacts/\` — this is the evidence trail.
|
|
59
|
+
6. **When in doubt, start with brainstorm.** If the task is non-trivial and there's no prior artifact, begin with \`/cc-brainstorm\`.
|
|
60
|
+
|
|
61
|
+
## Stage Quick Reference
|
|
62
|
+
|
|
63
|
+
| Stage | Command | HARD-GATE | Artifact |
|
|
64
|
+
|-------|---------|-----------|----------|
|
|
65
|
+
| Brainstorm | \`/cc-brainstorm\` | No implementation planning | \`01-brainstorm.md\` |
|
|
66
|
+
| Scope | \`/cc-scope\` | Challenge premises first | \`02-scope.md\` |
|
|
67
|
+
| Design | \`/cc-design\` | Search before building | \`03-design.md\` |
|
|
68
|
+
| Spec | \`/cc-spec\` | Observable + testable criteria | \`04-spec.md\` |
|
|
69
|
+
| Plan | \`/cc-plan\` | One task = one purpose | \`05-plan.md\` |
|
|
70
|
+
| Test | \`/cc-test\` | RED tests fail first | \`06-tdd.md\` |
|
|
71
|
+
| Build | \`/cc-build\` | Minimal code to pass RED | \`06-tdd.md\` (shared with test) |
|
|
72
|
+
| Review | \`/cc-review\` | Two-layer review | \`07-review.md\` |
|
|
73
|
+
| Ship | \`/cc-ship\` | All tests green on merge | \`08-ship.md\` |
|
|
74
|
+
|
|
75
|
+
## Skill Loading
|
|
76
|
+
|
|
77
|
+
Each \`/cc-*\` command loads:
|
|
78
|
+
1. **\`.cclaw/skills/<stage>/SKILL.md\`** — the full procedural guide (read this first and follow it)
|
|
79
|
+
2. **\`.cclaw/commands/<stage>.md\`** — thin orchestrator (entry/exit summary, gates, anchors)
|
|
80
|
+
|
|
81
|
+
Skills contain: checklist, examples, cognitive patterns, interaction protocol, gates, evidence requirements, verification, cross-stage traceability, anti-patterns, and self-improvement prompts.
|
|
82
|
+
|
|
83
|
+
## Contextual Skills (auto-activated, no commands needed)
|
|
84
|
+
|
|
85
|
+
These skills live in \`.cclaw/skills/\` but have no slash commands. They activate automatically based on context:
|
|
86
|
+
|
|
87
|
+
| Skill | Folder | Activates when... |
|
|
88
|
+
|-------|--------|-------------------|
|
|
89
|
+
| Security Review | \`security/\` | During review/ship stages; when code handles auth, user input, secrets, or external data |
|
|
90
|
+
| Debugging | \`debugging/\` | When tests fail unexpectedly; runtime errors; behavior doesn't match spec |
|
|
91
|
+
| Performance | \`performance/\` | During review; when code is perf-sensitive (DB queries, rendering, bundle size) |
|
|
92
|
+
| CI/CD | \`ci-cd/\` | During ship; when pipeline config or deployment is involved |
|
|
93
|
+
| Documentation | \`docs/\` | During ship; when adding public APIs, architecture changes, or breaking changes |
|
|
94
|
+
|
|
95
|
+
**Activation rule:** When a contextual skill applies, read its SKILL.md and follow it as a supplementary lens alongside the current stage. Do not skip the stage workflow — the contextual skill adds depth, not a detour.
|
|
96
|
+
|
|
97
|
+
## Decision Protocol
|
|
98
|
+
|
|
99
|
+
When a stage requires user input (approval, choice, direction), use this structured pattern:
|
|
100
|
+
|
|
101
|
+
1. **State the decision** in one sentence.
|
|
102
|
+
2. **Present options** as labeled choices (A, B, C...) with:
|
|
103
|
+
- One-line description of each option
|
|
104
|
+
- Trade-off or consequence
|
|
105
|
+
- Mark one as **(recommended)** with brief why
|
|
106
|
+
3. **Use the harness ask-user tool** when available:
|
|
107
|
+
- Claude Code: \`AskUserQuestion\` tool
|
|
108
|
+
- Cursor: \`AskQuestion\` tool with options array
|
|
109
|
+
- Codex/OpenCode: numbered list in message (no native ask tool)
|
|
110
|
+
4. **Wait for response.** Do not proceed until the user picks.
|
|
111
|
+
5. **Commit to the choice.** Once decided, do not re-argue.
|
|
112
|
+
|
|
113
|
+
### When to use structured asks vs conversational
|
|
114
|
+
- **Structured (tool):** Architecture choices, scope decisions, approval gates, mode selection, scope boundary issues
|
|
115
|
+
- **Conversational:** Clarifying questions, yes/no confirmations, "anything else?"
|
|
116
|
+
|
|
117
|
+
## Failure Modes
|
|
118
|
+
|
|
119
|
+
Watch for these anti-patterns:
|
|
120
|
+
- **Skipping stages** — jumping from brainstorm to build without design/spec/plan
|
|
121
|
+
- **Ignoring gates** — claiming completion without evidence
|
|
122
|
+
- **Premature implementation** — writing code before RED tests exist
|
|
123
|
+
- **Hollow reviews** — "looks good" without checking spec compliance
|
|
124
|
+
- **Cargo-cult artifacts** — filling templates without real thought
|
|
125
|
+
|
|
126
|
+
## Learnings Integration
|
|
127
|
+
|
|
128
|
+
At session start, check \`.cclaw/learnings.jsonl\` for project-specific knowledge:
|
|
129
|
+
- Run \`tail -n 20 .cclaw/learnings.jsonl\` and surface the top 3 highest-confidence entries
|
|
130
|
+
- Apply relevant learnings to the current task
|
|
131
|
+
- After each stage, reflect: did anything happen that would save 5+ minutes next time? If so, log it.
|
|
132
|
+
|
|
133
|
+
## Observation Hooks
|
|
134
|
+
|
|
135
|
+
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.
|
|
136
|
+
`;
|
|
137
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool observation system — captures PreToolUse/PostToolUse events
|
|
3
|
+
* to .cclaw/observations.jsonl for continuous learning.
|
|
4
|
+
*
|
|
5
|
+
* observe.sh: reads hook JSON from stdin, extracts tool name + truncated I/O,
|
|
6
|
+
* appends a JSONL line to .cclaw/observations.jsonl.
|
|
7
|
+
*
|
|
8
|
+
* summarize-observations.sh: run at session stop, reads recent observations,
|
|
9
|
+
* identifies patterns, and appends new learnings to .cclaw/learnings.jsonl.
|
|
10
|
+
*/
|
|
11
|
+
export declare function promptGuardScript(): string;
|
|
12
|
+
export declare function observeScript(): string;
|
|
13
|
+
export declare function contextMonitorScript(): string;
|
|
14
|
+
export declare function summarizeObservationsRuntimeModule(): string;
|
|
15
|
+
export declare function summarizeObservationsScript(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Updated hooks.json generators with PreToolUse/PostToolUse observation.
|
|
18
|
+
*/
|
|
19
|
+
export declare function claudeHooksJsonWithObservation(): string;
|
|
20
|
+
export declare function cursorHooksJsonWithObservation(): string;
|
|
21
|
+
export declare function codexHooksJsonWithObservation(): string;
|