clawpowers 1.0.0 → 1.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/README.md +8 -2
- package/docs/demo/clawpowers-demo.cast +197 -0
- package/docs/demo/clawpowers-demo.gif +0 -0
- package/docs/launch-images/post1-hero-lobster.jpg +0 -0
- package/docs/launch-images/post2-dashboard.jpg +0 -0
- package/docs/launch-images/post3-superpowers.jpg +0 -0
- package/docs/launch-images/post4-before-after.jpg +0 -0
- package/docs/launch-images/post5-install-now.jpg +0 -0
- package/docs/launch-posts.md +76 -0
- package/package.json +3 -2
- package/skills/cross-project-knowledge/SKILL.md +345 -0
- package/skills/formal-verification-lite/SKILL.md +441 -0
- package/skills/meta-skill-evolution/SKILL.md +325 -0
- package/skills/self-healing-code/SKILL.md +369 -0
- package/skills/systematic-debugging/SKILL.md +76 -0
- package/skills/test-driven-development/SKILL.md +117 -0
- package/skills/using-clawpowers/SKILL.md +17 -5
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cross-project-knowledge
|
|
3
|
+
description: Persistent knowledge base across all projects. Extract patterns after every fix or architecture decision; search before starting any task. Work on Project B benefits from everything learned on Projects A, C, D.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
requires:
|
|
6
|
+
tools: [bash, node]
|
|
7
|
+
runtime: true
|
|
8
|
+
metrics:
|
|
9
|
+
tracks: [patterns_stored, patterns_retrieved, cross_project_hits, success_count_increments, search_latency_ms]
|
|
10
|
+
improves: [search_relevance, pattern_categorization_accuracy, retrieval_recall]
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Cross-Project Knowledge
|
|
14
|
+
|
|
15
|
+
## When to Use
|
|
16
|
+
|
|
17
|
+
**Store a pattern after:**
|
|
18
|
+
- Successfully fixing a bug (store the root cause + fix)
|
|
19
|
+
- Making a significant architecture decision (store the decision + rationale)
|
|
20
|
+
- Discovering a performance optimization
|
|
21
|
+
- Completing a security fix or identifying a security pattern
|
|
22
|
+
- Writing a test strategy that proved effective
|
|
23
|
+
|
|
24
|
+
**Search before:**
|
|
25
|
+
- Starting any new task (30-second search to avoid re-solving known problems)
|
|
26
|
+
- Encountering an error message you haven't seen in this project
|
|
27
|
+
- Designing a new component or API
|
|
28
|
+
- Choosing between two implementation approaches
|
|
29
|
+
|
|
30
|
+
**Skip when:**
|
|
31
|
+
- The task is purely mechanical (rename a file, update a config value)
|
|
32
|
+
- The runtime directory `~/.clawpowers/` doesn't exist (no persistence available)
|
|
33
|
+
- The pattern is too project-specific to generalize (e.g., a business rule for one client)
|
|
34
|
+
|
|
35
|
+
**Decision tree:**
|
|
36
|
+
```
|
|
37
|
+
Starting a new task?
|
|
38
|
+
└── Yes → Search knowledge base first (30 seconds)
|
|
39
|
+
├── Hit found → apply known solution, update success_count
|
|
40
|
+
└── No hit → proceed with fresh investigation
|
|
41
|
+
└── After solving: store the pattern
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Core Methodology
|
|
45
|
+
|
|
46
|
+
### Knowledge Base Structure
|
|
47
|
+
|
|
48
|
+
All patterns live in `~/.clawpowers/memory/patterns.jsonl`. Each line is a JSON record:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"pattern_id": "bp-2024-auth-jwt-expiry",
|
|
53
|
+
"category": "bug-fix",
|
|
54
|
+
"description": "JWT tokens accepted after expiry when clock skew > 0",
|
|
55
|
+
"context": "Node.js + jsonwebtoken library, any project using JWT auth",
|
|
56
|
+
"solution": "Add clockTolerance: 0 to verify() options, or explicitly check exp claim",
|
|
57
|
+
"code_example": "jwt.verify(token, secret, { clockTolerance: 0 })",
|
|
58
|
+
"projects_used_in": ["auth-service", "api-gateway"],
|
|
59
|
+
"success_count": 3,
|
|
60
|
+
"tags": ["jwt", "auth", "expiry", "clock-skew"],
|
|
61
|
+
"created_at": "2024-03-15T10:00:00Z",
|
|
62
|
+
"last_used": "2024-11-02T14:30:00Z"
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Categories:**
|
|
67
|
+
- `bug-fix` — root cause + fix for a recurring class of bug
|
|
68
|
+
- `architecture` — structural patterns, component boundaries, integration decisions
|
|
69
|
+
- `performance` — optimizations with measured impact
|
|
70
|
+
- `security` — vulnerability patterns and mitigations
|
|
71
|
+
- `testing` — test strategies, fixture patterns, effective test designs
|
|
72
|
+
|
|
73
|
+
### Step 1: Search Before Starting
|
|
74
|
+
|
|
75
|
+
Before any non-trivial task, run a 30-second search:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Text search by keyword
|
|
79
|
+
PATTERNS_FILE=~/.clawpowers/memory/patterns.jsonl
|
|
80
|
+
|
|
81
|
+
search_patterns() {
|
|
82
|
+
local query="$1"
|
|
83
|
+
local category="$2" # optional filter
|
|
84
|
+
|
|
85
|
+
if [[ ! -f "$PATTERNS_FILE" ]]; then
|
|
86
|
+
echo "No knowledge base found. Initialize with: mkdir -p ~/.clawpowers/memory && touch ~/.clawpowers/memory/patterns.jsonl"
|
|
87
|
+
return
|
|
88
|
+
fi
|
|
89
|
+
|
|
90
|
+
node - <<EOF
|
|
91
|
+
const fs = require('fs');
|
|
92
|
+
const query = '${query}'.toLowerCase();
|
|
93
|
+
const category = '${category}';
|
|
94
|
+
const lines = fs.readFileSync(process.env.HOME + '/.clawpowers/memory/patterns.jsonl', 'utf8')
|
|
95
|
+
.trim().split('\n').filter(Boolean).map(l => JSON.parse(l));
|
|
96
|
+
|
|
97
|
+
const results = lines.filter(p => {
|
|
98
|
+
const matchCat = !category || p.category === category;
|
|
99
|
+
const text = [p.description, p.context, p.solution, ...(p.tags||[])].join(' ').toLowerCase();
|
|
100
|
+
const matchQuery = query.split(' ').every(word => text.includes(word));
|
|
101
|
+
return matchCat && matchQuery;
|
|
102
|
+
}).sort((a, b) => b.success_count - a.success_count);
|
|
103
|
+
|
|
104
|
+
if (results.length === 0) {
|
|
105
|
+
console.log('No matching patterns found.');
|
|
106
|
+
} else {
|
|
107
|
+
results.slice(0, 5).forEach((p, i) => {
|
|
108
|
+
console.log(\`[\${i+1}] [\${p.category}] \${p.description}\`);
|
|
109
|
+
console.log(\` Solution: \${p.solution}\`);
|
|
110
|
+
if (p.code_example) console.log(\` Example: \${p.code_example}\`);
|
|
111
|
+
console.log(\` Used in: \${(p.projects_used_in||[]).join(', ')} | Success count: \${p.success_count}\`);
|
|
112
|
+
console.log('');
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
EOF
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
# Usage examples:
|
|
119
|
+
search_patterns "jwt expiry"
|
|
120
|
+
search_patterns "connection pool" "bug-fix"
|
|
121
|
+
search_patterns "react infinite render" "bug-fix"
|
|
122
|
+
search_patterns "database index" "performance"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**What to do with search results:**
|
|
126
|
+
- **Hit with high success_count (≥3):** Apply the documented solution directly. Update `success_count` and `last_used`.
|
|
127
|
+
- **Hit with low success_count (1-2):** Use as a starting hypothesis, not a guaranteed fix. Verify it applies.
|
|
128
|
+
- **No hit:** Proceed with fresh investigation. After solving, store the pattern.
|
|
129
|
+
|
|
130
|
+
### Step 2: Store a Pattern After Solving
|
|
131
|
+
|
|
132
|
+
After fixing a bug, making an architecture decision, or discovering a useful pattern:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
store_pattern() {
|
|
136
|
+
local category="$1" # bug-fix|architecture|performance|security|testing
|
|
137
|
+
local description="$2" # what problem this solves (1 sentence)
|
|
138
|
+
local context="$3" # when/where this pattern applies
|
|
139
|
+
local solution="$4" # the fix or decision
|
|
140
|
+
local code_example="$5" # optional code snippet
|
|
141
|
+
local tags="$6" # comma-separated keywords
|
|
142
|
+
|
|
143
|
+
local pattern_id="${category:0:2}-$(date +%Y%m%d)-$(echo "$description" | tr ' ' '-' | tr '[:upper:]' '[:lower:]' | cut -c1-30)"
|
|
144
|
+
local project=$(basename $(git rev-parse --show-toplevel 2>/dev/null) 2>/dev/null || echo "unknown")
|
|
145
|
+
|
|
146
|
+
mkdir -p ~/.clawpowers/memory
|
|
147
|
+
|
|
148
|
+
# Build JSON record
|
|
149
|
+
node - <<EOF >> "$PATTERNS_FILE"
|
|
150
|
+
console.log(JSON.stringify({
|
|
151
|
+
pattern_id: '$pattern_id',
|
|
152
|
+
category: '$category',
|
|
153
|
+
description: '$description',
|
|
154
|
+
context: '$context',
|
|
155
|
+
solution: '$solution',
|
|
156
|
+
code_example: '$code_example',
|
|
157
|
+
projects_used_in: ['$project'],
|
|
158
|
+
success_count: 1,
|
|
159
|
+
tags: '$tags'.split(',').map(t=>t.trim()).filter(Boolean),
|
|
160
|
+
created_at: new Date().toISOString(),
|
|
161
|
+
last_used: new Date().toISOString()
|
|
162
|
+
}));
|
|
163
|
+
EOF
|
|
164
|
+
echo "Pattern stored: $pattern_id"
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Store after these events (mandatory):**
|
|
169
|
+
|
|
170
|
+
| Event | Category | What to store |
|
|
171
|
+
|-------|---------|--------------|
|
|
172
|
+
| Bug fixed | `bug-fix` | Root cause + exact fix + how to detect this bug |
|
|
173
|
+
| Architecture decision made | `architecture` | Decision + alternatives considered + rationale |
|
|
174
|
+
| Performance improvement measured | `performance` | Optimization + measured delta (e.g., "50% latency reduction") |
|
|
175
|
+
| Security issue found/fixed | `security` | Vulnerability pattern + mitigation |
|
|
176
|
+
| Test strategy validated | `testing` | Test approach + what it caught that unit tests missed |
|
|
177
|
+
|
|
178
|
+
**Example stores:**
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# After fixing a React infinite re-render
|
|
182
|
+
store_pattern "bug-fix" \
|
|
183
|
+
"useEffect with object dependency causes infinite re-render" \
|
|
184
|
+
"React functional components, useEffect with object/array deps" \
|
|
185
|
+
"Memoize the object with useMemo or extract stable primitive values as deps" \
|
|
186
|
+
"const stableRef = useMemo(() => ({ id: user.id }), [user.id])" \
|
|
187
|
+
"react,useEffect,infinite-render,memoization"
|
|
188
|
+
|
|
189
|
+
# After an architecture decision
|
|
190
|
+
store_pattern "architecture" \
|
|
191
|
+
"Event sourcing for audit log instead of mutable records" \
|
|
192
|
+
"Any service requiring immutable audit trail, compliance requirements" \
|
|
193
|
+
"Append-only event log; derive current state by replaying events; never update in-place" \
|
|
194
|
+
"" \
|
|
195
|
+
"event-sourcing,audit-log,cqrs,immutable"
|
|
196
|
+
|
|
197
|
+
# After a performance fix
|
|
198
|
+
store_pattern "performance" \
|
|
199
|
+
"N+1 query on user.posts relation reduced latency from 800ms to 45ms" \
|
|
200
|
+
"ORM with lazy loading, list views fetching related records" \
|
|
201
|
+
"Use eager loading: User.includes(:posts) or SQL JOIN instead of per-row query" \
|
|
202
|
+
"User.includes(:posts).where(...)" \
|
|
203
|
+
"n+1,orm,eager-loading,sql,latency"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Step 3: Update on Reuse
|
|
207
|
+
|
|
208
|
+
When a retrieved pattern successfully solves a new problem, increment its signal:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
update_pattern_success() {
|
|
212
|
+
local pattern_id="$1"
|
|
213
|
+
local project=$(basename $(git rev-parse --show-toplevel 2>/dev/null) 2>/dev/null || echo "unknown")
|
|
214
|
+
|
|
215
|
+
node - <<EOF > /tmp/patterns-updated.jsonl
|
|
216
|
+
const fs = require('fs');
|
|
217
|
+
const lines = fs.readFileSync(process.env.HOME + '/.clawpowers/memory/patterns.jsonl', 'utf8')
|
|
218
|
+
.trim().split('\n').filter(Boolean).map(l => JSON.parse(l));
|
|
219
|
+
const now = new Date().toISOString();
|
|
220
|
+
const updated = lines.map(p => {
|
|
221
|
+
if (p.pattern_id === '$pattern_id') {
|
|
222
|
+
const projects = Array.from(new Set([...(p.projects_used_in||[]), '$project']));
|
|
223
|
+
return { ...p, success_count: (p.success_count||0) + 1, last_used: now, projects_used_in: projects };
|
|
224
|
+
}
|
|
225
|
+
return p;
|
|
226
|
+
});
|
|
227
|
+
updated.forEach(p => console.log(JSON.stringify(p)));
|
|
228
|
+
EOF
|
|
229
|
+
mv /tmp/patterns-updated.jsonl "$PATTERNS_FILE"
|
|
230
|
+
echo "Updated success_count for $pattern_id"
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Step 4: Periodic Knowledge Base Maintenance
|
|
235
|
+
|
|
236
|
+
Every 100 patterns or monthly, prune and consolidate:
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
# Knowledge base health report
|
|
240
|
+
node - <<'EOF'
|
|
241
|
+
const fs = require('fs');
|
|
242
|
+
const lines = fs.readFileSync(process.env.HOME + '/.clawpowers/memory/patterns.jsonl', 'utf8')
|
|
243
|
+
.trim().split('\n').filter(Boolean).map(l => JSON.parse(l));
|
|
244
|
+
|
|
245
|
+
// Count by category
|
|
246
|
+
const byCat = {};
|
|
247
|
+
lines.forEach(p => { byCat[p.category] = (byCat[p.category]||0) + 1; });
|
|
248
|
+
|
|
249
|
+
// High-value patterns (success_count ≥ 3)
|
|
250
|
+
const highValue = lines.filter(p => p.success_count >= 3).length;
|
|
251
|
+
|
|
252
|
+
// Stale patterns (not used in 6 months)
|
|
253
|
+
const sixMonthsAgo = new Date(Date.now() - 6*30*24*60*60*1000).toISOString();
|
|
254
|
+
const stale = lines.filter(p => (p.last_used||p.created_at) < sixMonthsAgo).length;
|
|
255
|
+
|
|
256
|
+
console.log('Knowledge Base Health:');
|
|
257
|
+
console.log(' Total patterns:', lines.length);
|
|
258
|
+
console.log(' By category:', JSON.stringify(byCat));
|
|
259
|
+
console.log(' High-value (≥3 successes):', highValue);
|
|
260
|
+
console.log(' Stale (>6 months unused):', stale);
|
|
261
|
+
console.log(' Cross-project patterns (≥2 projects):', lines.filter(p => (p.projects_used_in||[]).length >= 2).length);
|
|
262
|
+
EOF
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Step 5: Cross-Project Knowledge Transfer
|
|
266
|
+
|
|
267
|
+
When starting a project in a domain you've worked in before:
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
# Before starting on a new auth service
|
|
271
|
+
search_patterns "auth jwt token" "security"
|
|
272
|
+
search_patterns "auth session" "architecture"
|
|
273
|
+
search_patterns "auth rate limit" "security"
|
|
274
|
+
|
|
275
|
+
# Before debugging a Node.js memory issue
|
|
276
|
+
search_patterns "memory leak node" "bug-fix"
|
|
277
|
+
search_patterns "garbage collection" "performance"
|
|
278
|
+
search_patterns "heap snapshot" "bug-fix"
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**The power:** An agent working on `project-d` that has seen the JWT clock skew bug on `project-a` will solve it in seconds on `project-d` — not hours.
|
|
282
|
+
|
|
283
|
+
## ClawPowers Enhancement
|
|
284
|
+
|
|
285
|
+
When `~/.clawpowers/` runtime is initialized:
|
|
286
|
+
|
|
287
|
+
**Full pipeline integration:**
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
# At the start of any task
|
|
291
|
+
bash runtime/persistence/store.sh set "knowledge:current-task:search-done" "false"
|
|
292
|
+
|
|
293
|
+
# Search step (always first)
|
|
294
|
+
RESULTS=$(node -e "/* search logic above */" 2>/dev/null)
|
|
295
|
+
bash runtime/persistence/store.sh set "knowledge:current-task:search-done" "true"
|
|
296
|
+
bash runtime/persistence/store.sh set "knowledge:current-task:search-results" "$RESULTS"
|
|
297
|
+
|
|
298
|
+
# After task completion — store if new pattern discovered
|
|
299
|
+
if [[ "$NEW_PATTERN_FOUND" == "true" ]]; then
|
|
300
|
+
store_pattern "$CATEGORY" "$DESCRIPTION" "$CONTEXT" "$SOLUTION" "$CODE_EXAMPLE" "$TAGS"
|
|
301
|
+
fi
|
|
302
|
+
|
|
303
|
+
# Record metrics
|
|
304
|
+
bash runtime/metrics/collector.sh record \
|
|
305
|
+
--skill cross-project-knowledge \
|
|
306
|
+
--outcome success \
|
|
307
|
+
--notes "search: $SEARCH_HITS hits, stored: $STORED_PATTERNS new patterns"
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Analyze knowledge base effectiveness:**
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
bash runtime/feedback/analyze.sh --filter cross-project-knowledge
|
|
314
|
+
# Reports: search hit rate, most-used patterns, cross-project transfer count,
|
|
315
|
+
# average time saved vs. fresh investigation
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
**Export / import for team sharing:**
|
|
319
|
+
```bash
|
|
320
|
+
# Export your knowledge base (redact sensitive data)
|
|
321
|
+
cat ~/.clawpowers/memory/patterns.jsonl | \
|
|
322
|
+
node -e "
|
|
323
|
+
const lines = require('fs').readFileSync('/dev/stdin','utf8').trim().split('\n').map(JSON.parse);
|
|
324
|
+
// Keep only high-value, generic patterns
|
|
325
|
+
const shareable = lines.filter(p => p.success_count >= 2 && !p.tags?.includes('internal'));
|
|
326
|
+
shareable.forEach(p => console.log(JSON.stringify(p)));
|
|
327
|
+
" > shared-patterns.jsonl
|
|
328
|
+
|
|
329
|
+
# Import from a teammate's export
|
|
330
|
+
cat shared-patterns.jsonl >> ~/.clawpowers/memory/patterns.jsonl
|
|
331
|
+
echo "Imported $(wc -l < shared-patterns.jsonl) patterns"
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
## Anti-Patterns
|
|
335
|
+
|
|
336
|
+
| Anti-Pattern | Why It Fails | Correct Approach |
|
|
337
|
+
|-------------|-------------|-----------------|
|
|
338
|
+
| Skip pre-task search | Re-solve known problems; waste time | Always search first, even if you think you know the answer |
|
|
339
|
+
| Store patterns too specifically | Pattern only matches one exact situation | Generalize: describe the class of problem, not the instance |
|
|
340
|
+
| Store without code_example | Pattern is hard to apply without template | Always include a minimal code example |
|
|
341
|
+
| Forget to update success_count | High-value patterns look the same as single-use | Update every time a pattern is successfully applied |
|
|
342
|
+
| Store negative results ("this didn't work") | Pollutes the knowledge base with noise | Only store successful patterns; capture failures in debugging logs |
|
|
343
|
+
| Never prune stale patterns | Old patterns may suggest deprecated approaches | Monthly maintenance pass; archive patterns unused for 6+ months |
|
|
344
|
+
| Search with overly broad terms | Too many irrelevant hits; signal buried | Search with 2-3 specific keywords from the error or domain |
|
|
345
|
+
| Treat cross-project patterns as gospel | Context differs; blind application fails | Use as a strong starting hypothesis, then verify it fits |
|