🎉 init: 小龙的工作空间

This commit is contained in:
大海
2026-06-06 10:40:48 +08:00
commit a188ee1426
3201 changed files with 231817 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
---
name: code-explorer
description: Search and explore codebases with CodeGraph. Symbol lookup, caller/callee analysis, impact analysis, BFS graph traversal.
metadata: { "openclaw": { "emoji": "🔍" } }
---
# Code Explorer — CodeGraph Knowledge Graph
Query codebases through a pre-indexed SQLite knowledge graph with FTS5 full-text search and BFS graph traversal.
## When to Use
- **"Where is X defined?"** → `search`
- **"Who calls X?"** → `callers`
- **"What does X call?"** → `callees`
- **"What's the impact of changing X?"** → `impact`
- **"How does the codebase handle auth?"** → `search` + `callers`
- **Before grep/glob** — CodeGraph is faster and more structured
## Setup
```bash
# Index a codebase (only needed once, or after major changes)
node src/codegraph/index.js index <project_dir>
# Force re-index
node src/codegraph/index.js index . --force
# Check index stats
node src/codegraph/index.js stats
```
## Commands
### Search symbols
```bash
node src/codegraph/index.js search "function_name"
node src/codegraph/index.js search "auth" --limit 10
```
### Caller/callee analysis
```bash
node src/codegraph/index.js callers "login"
node src/codegraph/index.js callees "main"
```
### Impact analysis (BFS traversal)
```bash
node src/codegraph/index.js impact "AuthService"
```
### Deep exploration (search + BFS context)
```bash
node src/codegraph/index.js explore "how to send HTTP requests"
```
## Languages Supported
JavaScript/TypeScript, Python, Rust, Go, Java, Ruby, Shell, C/C++
Extraction via regex grammars (8 languages, 8+ node types: function/class/method/struct/enum/import/export)
## Database
SQLite at `.codegraph/codegraph.db` with:
- `nodes` — symbols (name, kind, signature, location)
- `edges` — relationships (calls, imports, extends, implements)
- `files` — file metadata with hash-based incremental sync
- `nodes_fts` — FTS5 full-text search index
## Integration Pattern
```
Query codebase → codegraph search → symbol list → codegraph callers → call graph
codegraph impact → affected files
```
## File Path
- `src/codegraph/index.js` — main entry (index, search, callers, callees, impact, explore)
- `src/codegraph/schema.sql` — SQLite schema
+84
View File
@@ -0,0 +1,84 @@
---
name: compression
description: Compress tool outputs, logs, and JSON arrays before they enter LLM context. Saves 60-95% tokens.
metadata: { "openclaw": { "emoji": "📦" } }
---
# Compression — Context-Aware Output Compression
Compress large tool outputs before they consume LLM context. Content-type-aware: JSON arrays, build logs, search results, git diffs each get optimal compression.
## When to Use
- Tool output > 500 chars → compress before reading
- JSON arrays > 10 items → SmartCrusher
- Build/CI logs > 50 lines → template dedup
- Search/grep results > 30 lines → file dedup
- Git diffs with lock files → noise filter
- Need to retrieve original compressed data → CCR store
## Tools
### `ctx_compress` — one-stop compression
```bash
# Auto-detect type, compress stdin
cat huge_output.json | node src/compression/ctx-compress.js
# Specify type, bias
cat build.log | node src/compression/ctx-compress.js --type log --json
# Force JSON mode with query context for relevance
cat results.json | node src/compression/ctx-compress.js --type json --query "error timeout" --json
# Retrieve original from CCR store
node src/compression/ctx-compress.js --retrieve <ccr_hash>
```
### `smart-crusher` — direct JSON compression
```bash
node src/compression/smart-crusher.js --bias 0.7 --query "search terms" < input.json
```
### Content type detection
```bash
cat unknown_output.txt | node src/compression/detector.js
```
## Compression Strategies
| Content Type | Strategy | Savings |
|-------------|----------|:-------:|
| JSON array | lossless:csv or smart sample | 50-90% |
| Build log | template dedup | 90-99% |
| Search results | file dedup | 80-95% |
| Git diff | noise filter (lock files etc) | 30-70% |
## Key Feature: CCR (Compress-Cache-Retrieve)
Compressed output includes `<<ccr:HASH N_rows_offloaded>>` markers. If LLM needs original data, retrieve it:
```bash
node src/compression/ctx-compress.js --retrieve <hash>
```
## Integration Pattern
```
large_tool_output → ctx_compress → compressed → LLM context
<<ccr:abc123>>
LLM needs more? → ctx_compress --retrieve abc123
```
## File Paths
- `src/compression/ctx-compress.js` — main entry
- `src/compression/smart-crusher.js` — JSON compression engine
- `src/compression/detector.js` — content type detection
- `src/compression/ccr-store.js` — reversible storage
- `src/compression/ccr-backends.js` — SQLite/Redis persistence
- `src/compression/byte-surgery.js` — cache-safe byte replacement
+56
View File
@@ -0,0 +1,56 @@
---
name: security-check
description: Pre-execution risk assessment for tool calls. Checks file sensitivity, blast radius, irreversibility before running dangerous commands.
metadata: { "openclaw": { "emoji": "🛡️" } }
---
# Security Check — Tool Risk Assessment
Run risk assessment before executing potentially dangerous operations. Four-factor weighted scoring adapted from ECC.
## When to Use
- **Before Bash/exec** — always check risk
- **Before Write/Edit** — check file sensitivity
- **Before git push --force / rm -rf** — mandatory check
- **Before database DROP/TRUNCATE** — mandatory check
- **Before chmod/chown** — check blast radius
## Tool
```bash
# JSON input mode (preferred)
node src/security/risk-scorer.js '{"tool":"Bash","command":"rm -rf /tmp/build"}'
# Simple mode
node src/security/risk-scorer.js Write .env.production
```
## Risk Levels
| Score | Action | Meaning |
|:-----:|:------:|---------|
| < 0.35 | **ALLOW** | Safe operation |
| 0.35-0.60 | **REVIEW** | Review input before executing |
| 0.60-0.85 | **CONFIRM** | Ask user for confirmation |
| ≥ 0.85 | **BLOCK** | Refuse to execute |
## Four Factors
1. **Base tool risk** — Bash=0.20, Write=0.15, Read=0.02
2. **File sensitivity** — .env +0.25, /etc/ +0.20, SSH keys +0.25
3. **Blast radius** — rm -rf +0.35, curl-to-shell +0.25, SQL DROP +0.30
4. **Irreversibility** — git push --force +0.45, hard reset +0.35
## Integration Pattern
```
Before exec/write → risk-scorer → ALLOW → execute
→ REVIEW → show risk factors
→ CONFIRM → ask user
→ BLOCK → refuse, explain why
```
## File Path
- `src/security/risk-scorer.js` — scoring engine
+84
View File
@@ -0,0 +1,84 @@
---
name: self-evolution
description: Post-task reflection, pattern extraction, skill generation, memory update. Continuous self-improvement loop.
metadata: { "openclaw": { "emoji": "🧬" } }
---
# Self-Evolution — Continuous Improvement Loop
After every completed task, run the evolution cycle. Each task makes the system stronger.
## Evolution Cycle (9 Steps)
### 1. Record Successes
What worked? Why? Can we replicate it?
`/reflections/YYYY-MM-DD-<task>.md`
### 2. Record Failures
What broke? Root cause? Fix applied?
→ same reflection file
### 3. Generate New Skill
Does this task create a reusable capability? If yes:
`/skills/<skill-name>.md` (YAML frontmatter + usage guide)
### 4. Update Memory
Write today's key events to daily log.
`memory/daily/YYYY-MM-DD.md`
### 5. Update Best Practices
Extract reusable patterns that worked.
`/patterns/design-patterns.md` (problem → solution → anti-pattern)
### 6. Update Prompt Templates
Did we create a useful prompt format? Template it.
`/patterns/prompt-templates.md`
### 7. Update Tool Strategy
Did we learn about tool selection/sequencing?
`/playbooks/` or pattern file
### 8. Update CodeGraph
Re-index the workspace to capture new code.
```bash
node src/codegraph/index.js index . --force
```
### 9. Update Compression Rules
Did we discover new content type → compression strategy mappings?
→ update `src/compression/detector.js` signal weights
## Directory Structure
```
workspace/
├── reflections/ ← 每次任务的反思 (YYYY-MM-DD-<task>.md)
├── patterns/ ← 可复用设计模式
├── playbooks/ ← 常用任务的操作手册
├── skills/ ← 能力技能文件
└── memory/ ← 长期记忆系统
```
## Integration with Existing Systems
- **Dream Cycle** (cron 4:00) → 自动整合 reflections/ 到 memory/
- **Memory Search** → 可检索过往反思
- **CodeGraph** → 索引所有演化产物
## Quality Gate
After each evolution cycle, verify:
- [ ] reflections/ 有本次任务的反思文件
- [ ] 如果产生了新模式 → patterns/ 已更新
- [ ] 如果产生了新能力 → skills/ 已创建
- [ ] memory/daily/ 已写入今日总结
- [ ] 所有新代码可独立运行