toolkit/archive/reflect-v1/SKILL.md
Unified learning capture from conversation analysis. Extracts behavioral corrections AND knowledge learnings (solved problems, patterns, decisions). Dual-indexes into QMD + GraphRAG for future retrieval. Philosophy: "Correct once, never again. Solve once, never re-research." Use when: (1) User corrects behavior, (2) Problem solved after debugging, (3) Session ending or context compaction, (4) User requests /reflect, (5) Pattern discovered worth preserving.
npx skillsauth add stevengonsalvez/agents-in-a-box reflectInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
| Command | Action |
|---------|--------|
| /reflect | Full session analysis (behavioral + knowledge) |
| /reflect --behavioral | Only: corrections -> agent files |
| /reflect --knowledge | Only: solved problems -> knowledge docs |
| /reflect --review | Review pending low-confidence learnings |
| /reflect --status | Show metrics and KB stats |
| /reflect --consolidate | Merge orphaned worktree memories |
| /reflect --ingest-memories | Ingest project memory files into QMD + GraphRAG |
| /reflect on | Enable auto-reflection |
| /reflect off | Disable auto-reflection |
| /reflect [agent] | Focus on specific agent (behavioral only) |
If no flags and context is ambiguous, present interactive options:
What would you like to reflect on?
1. Full analysis (behavioral + knowledge)
2. Behavioral corrections only
3. Knowledge capture only
4. Review pending learnings
"Correct once, never again. Solve once, never re-research."
Two complementary loops:
These are internal modules (not user-visible commands):
| Module | Purpose |
|--------|---------|
| Signal Detection | Scan conversation for behavioral + knowledge signals |
| Entity Extraction | Extract entities + relationships for GraphRAG (from compound-docs logic) |
| Knowledge Doc Gen | Generate YAML+markdown learning notes |
| Agent Updates | Update agent config files with behavioral corrections |
| De-duplication | QMD similarity check against existing learnings |
| Indexing | learnings CLI: dual-index into QMD + GraphRAG |
Check and initialize state files, then scan the conversation for both signal types:
# Check for existing state
python scripts/state_manager.py init
# State directory is configurable via REFLECT_STATE_DIR env var
# Default: ~/.reflect/ (portable) or $HOME/{{TOOL_DIR}}/session/ (Claude Code)
State includes:
reflect-state.yaml - Toggle state, pending reviewsreflect-metrics.yaml - Aggregate metricslearnings.yaml - Log of all applied learningsUse the signal detector to identify corrections and preferences:
python scripts/signal_detector.py --input conversation.txt
| Confidence | Triggers | Examples | |------------|----------|----------| | HIGH | Explicit corrections | "never", "always", "wrong", "stop", "the rule is" | | MEDIUM | Approved approaches | "perfect", "exactly", accepted output | | LOW | Observations | Patterns that worked, not validated |
See signal_patterns.md for full detection rules.
Scan for solved problems, discovered patterns, decisions, and insights. See signal_patterns.md Knowledge Signal Patterns section for the full detection reference (HIGH/MEDIUM/LOW confidence with regex patterns).
HIGH confidence — explicit resolution: root cause identified, fix confirmed, explicit decisions, breakthrough moments ("turns out", "figured out", "the fix was").
MEDIUM confidence — implicit knowledge: debugging effort (time invested = value), docs-vs-reality gaps, environment/config gotchas, performance insights, integration issues, failed approaches, architecture insights.
LOW confidence — observations: implicit success ("seems to work"), library discoveries, security findings needing validation.
Structural signals (non-phrase): error→investigation→fix arcs, config changes that resolved issues, multiple approaches tried before settling on one.
Classify each signal by type (behavioral vs knowledge), scope, and learning type. See classification_rules.md for full tables covering:
Route each signal to the correct output:
| Signal characteristic | Route to | Why |
|-----------------------|----------|-----|
| Behavioral correction ("always do X", "never Y") | Agent file diff | Permanent rule change |
| Reusable fix, workaround, pattern, technique | Knowledge note | Needs semantic search for future discovery |
| Project-specific config, path, convention | .agents/MEMORY.md | Quick-reference, no search needed |
| Non-trivial debugging insight with error messages | Knowledge note | Others will search for those errors |
| Domain term, business rule | .agents/MEMORY.md | Project context |
| Recurring bug with generalizable fix | Knowledge note + possibly new skill | Broadest reuse |
Knowledge Note criteria (creates searchable docs/solutions/ + global index):
Memory-only criteria (.agents/MEMORY.md):
Before generating new content, check for duplicates:
# Query existing knowledge base for similar learnings
LEARNINGS_CLI="$LEARNINGS_HOME/cli/learnings"
if [[ -x "$LEARNINGS_CLI" ]]; then
"$LEARNINGS_CLI" query --collection learnings --json "{extracted key insight}"
fi
De-duplication Logic:
links: fieldAlso check project-local docs/solutions/ for existing documents on the same topic:
# Check local solutions
grep -rl "{key terms}" docs/solutions/ 2>/dev/null
Produce proposals for both behavioral and knowledge signals.
For behavioral signals, generate proposed agent file changes:
### Change N: Update [agent-name]
**Target**: `[file path]`
**Section**: [section name]
**Confidence**: [HIGH/MEDIUM/LOW]
**Rationale**: [why this change]
```diff
--- a/path/to/agent.md
+++ b/path/to/agent.md
@@ -82,6 +82,7 @@
## Section
* Existing rule
+* New rule from learning
#### Knowledge Proposals (Learning Notes)
Generate LEARNING notes in Zettelkasten format using the template in
[assets/learning_template.md](assets/learning_template.md). Key fields: `type`, `id`,
`scope`, `confidence`, `learning_type`, `key_insight`, `symptoms`, `source_episodes`.
See [note_templates.md](references/note_templates.md) for full templates and format details.
#### Entity Sidecar (`.entities.yaml`)
Generate an entity sidecar for each learning for GraphRAG indexing.
See [knowledge_format.md](references/knowledge_format.md) for entity types, relationship
types, extraction guidelines, and sidecar format.
#### Episode Note (Auto-created, No Approval Needed)
Auto-create an episode note using [assets/episode_template.md](assets/episode_template.md).
**Write to `$LEARNINGS_HOME/documents/episodes/{YYYY-MM-DD}/ep-{YYYYMMDD}-{hash6}.md`**
Do NOT write to `{{TOOL_DIR}}/reflections/` — that was a dead-end location.
Episodes go directly to the global knowledge base where they are searchable.
The episode must include required frontmatter fields (`title`, `category: session-reflections`,
`key_insight`) so it passes `get_all_documents()` frontmatter validation.
Index immediately for search:
```bash
LEARNINGS_CLI="$LEARNINGS_HOME/cli/learnings"
if [[ -x "$LEARNINGS_CLI" ]]; then
"$LEARNINGS_CLI" add "$LEARNINGS_HOME/documents/episodes/{date}/ep-{date}-{hash}.md"
fi
Project-scoped learnings are also saved to docs/solutions/{category}/ in the project,
alongside their entity sidecars.
Show: signal table (with type, confidence, source quote), proposed diffs (behavioral), proposed learning notes (knowledge), proposed new skills, and conflict check.
Use assets/reflection_template.md for the output format.
Review options: Y (all), N (discard), modify, 1,3 (selective), k2 (knowledge only),
all-knowledge, all-behavioral.
NEVER auto-apply without user approval.
git add on modified filesdocs/solutions/{category}/{filename}.mddocs/solutions/{category}/{filename}.entities.yaml# Add to knowledge base with dual indexing (QMD + GraphRAG)
LEARNINGS_CLI="$LEARNINGS_HOME/cli/learnings"
if [[ -x "$LEARNINGS_CLI" ]]; then
"$LEARNINGS_CLI" add docs/solutions/{category}/{filename}.md \
--entities docs/solutions/{category}/{filename}.entities.yaml
# This triggers: GraphRAG insert + qmd embed + git commit
fi
When approved learnings include project-specific items (not agent updates or new skills),
write them to .agents/MEMORY.md in the repo root:
.agents/MEMORY.md (create from template if it doesn't exist -- see Project Memory section).agents/MEMORY.md alongside other reflect changes in the commitDecision flow -- Agent File vs .agents/MEMORY.md:
| Signal | Target |
|--------|--------|
| Behavioral ("always do X") | Agent file |
| Project-specific architecture, gotcha, env quirk | .agents/MEMORY.md |
| Recurring bug with reusable fix | New skill |
| Domain term / business rule | .agents/MEMORY.md |
Commit all changes with a descriptive message:
reflect: add learnings from session [date]
Agent updates:
- [learning 1 summary]
Knowledge learnings:
- [learning 2 summary]
New skills:
- [skill-name]: [brief description]
Extracted: [N] signals ([H] high, [M] medium, [L] low confidence)
python scripts/metrics_updater.py --accepted 3 --rejected 1 --confidence high:2,medium:1
Also update $LEARNINGS_HOME/metrics.yaml with:
/reflect on
# Sets auto_reflect: true in state file
# Will trigger on PreCompact hook
/reflect off
# Sets auto_reflect: false in state file
/reflect --status
# Shows: toggle state, metrics, KB stats
# KB stats: total learnings, entities, episodes, by scope/type
/reflect --review
# Shows low-confidence learnings awaiting validation
# Allows promoting LOW -> MEDIUM/HIGH or discarding
/reflect --consolidate)Bulk-merge orphaned worktree memories into .agents/MEMORY.md.
See consolidate_workflow.md for the full 9-step workflow.
/reflect --ingest-memories)Harvest Claude Code's auto-memory files from {{HOME_TOOL_DIR}}/projects/*/memory/ into the
git-backed global knowledge base ($LEARNINGS_HOME) with QMD + GraphRAG indexing.
Memory files are ephemeral — Claude Code's dream cycles can prune them, and deleting a
project wipes its {{HOME_TOOL_DIR}}/projects/<slug>/memory/ directory entirely. This command
archives the originals into $LEARNINGS_HOME/documents/memories/{project}/ (git-tracked),
converts them to searchable knowledge learnings, and indexes into QMD + GraphRAG.
When to use: Periodically, or when you notice memory files accumulating across projects.
Run before deleting projects or cleaning up {{HOME_TOOL_DIR}}/projects/.
MEMORY_BASE="$HOME/{{TOOL_DIR}}/projects"
echo "=== Scanning project memory directories ==="
TOTAL=0
for dir in "$MEMORY_BASE"/*/memory/; do
[ -d "$dir" ] || continue
count=$(find "$dir" -name "*.md" -not -name "MEMORY.md" -type f 2>/dev/null | wc -l)
if [ "$count" -gt 0 ]; then
project=$(basename "$(dirname "$dir")")
echo " $project: $count files"
TOTAL=$((TOTAL + count))
fi
done
echo "Total: $TOTAL memory files"
For each .md file (excluding MEMORY.md index files):
name, description, type| Memory Type | Learning Type | Scope | Route |
|-------------|---------------|-------|-------|
| feedback | correction or pattern | universal (if general) or project | Knowledge note |
| user | preference | universal | Knowledge note (user profile) |
| project | decision or pattern | project | Knowledge note |
| reference | reference | project or domain | Knowledge note |
-Users-stevengonsalvez-d-git-shotclubhouse → shotclubhouse
For each memory file, check if it already exists in the knowledge base:
LEARNINGS_CLI="$LEARNINGS_HOME/cli/learnings"
# Check QMD first (fastest)
qmd query --collection learnings --json "{key_insight from memory}" 2>/dev/null
# Fall back to GraphRAG
if [[ -x "$LEARNINGS_CLI" ]]; then
"$LEARNINGS_CLI" search "{key terms}" --mode local --format json
fi
Skip if high-similarity match exists. Update if partial match found and memory has newer info.
For each non-duplicate memory, generate:
A. Learning note (using assets/learning_template.md):
id: lrn-mem-{project_slug}-{filename_slug}-{hash6}scope: Derived from content (universal for user/feedback, project for project/reference)confidence: HIGH for feedback (user explicitly stated), MEDIUM for project/referencelearning_type: Mapped from memory type (see table above)key_insight: The description field from frontmatter, or first substantive linetitle: The name field from frontmattertags: Include project name, memory type, and content-derived tagssymptoms: Extract "Why:" and "How to apply:" sections if presentContent sections:
B. Entity sidecar (.entities.yaml):
Extract entities from the memory content:
technologyconcepttoolpatternerrorInclude relationships:
solves or relates_to relationshipsrequires or relates_to relationshipsrelates_to relationships pointing to external resources## Memory Ingestion Plan
| # | Project | Memory File | Type | Action | Learning ID |
|---|---------|-------------|------|--------|-------------|
| 1 | shotclubhouse | feedback_tui_bulk_delete.md | feedback | NEW | lrn-mem-shot-tui-bulk-abc123 |
| 2 | github-io | user_stevie_tools.md | user | SKIP (exists) | — |
| 3 | github-io | feedback_no_emdashes.md | feedback | NEW | lrn-mem-ghio-emdash-def456 |
...
**New learnings**: N
**Skipped (duplicates)**: M
**Updated**: K
Proceed? [Y/n/select by number]
NEVER auto-index without user approval.
For each approved memory file, first archive the original, then index the learning.
A. Archive original memory files (preserves raw content in git):
LEARNINGS_HOME="${LEARNINGS_HOME:-$HOME/.learnings}"
# Decode project slug: -Users-stevengonsalvez-d-git-shotclubhouse → shotclubhouse
# Take the last meaningful segment after -d-git- or last path component
decode_project() {
local slug="$1"
echo "$slug" | sed 's/.*-d-git-//' | sed 's/.*-d-//' | sed 's/^-//'
}
PROJECT_NAME=$(decode_project "$PROJECT_SLUG")
ARCHIVE_DIR="$LEARNINGS_HOME/documents/memories/$PROJECT_NAME"
mkdir -p "$ARCHIVE_DIR"
# Copy original memory file with metadata header prepended
for memory_file in $APPROVED_FILES; do
BASENAME=$(basename "$memory_file")
# Prepend archive metadata to the copy
{
echo "<!-- archived: $(date -Iseconds) -->"
echo "<!-- source: $memory_file -->"
echo ""
cat "$memory_file"
} > "$ARCHIVE_DIR/$BASENAME"
done
The documents/memories/ directory structure:
$LEARNINGS_HOME/documents/memories/
├── shotclubhouse/
│ ├── feedback_tui_bulk_delete.md
│ ├── project_auth_migration.md
│ └── reference_supabase_config.md
├── stevengonsalvez-github-io/
│ ├── feedback_no_emdashes.md
│ ├── user_stevie_tools_and_opinions.md
│ └── project_blog_architecture.md
├── ai-coder-rules/
│ └── feedback_verify_before_claiming.md
└── _index.yaml # tracks all ingested files
B. Write structured learning notes (for QMD + GraphRAG):
LEARNINGS_CLI="$LEARNINGS_HOME/cli/learnings"
# Derive category from memory type
# feedback → "preferences", user → "user-profile", project → "architecture", reference → "references"
CATEGORY="memories"
mkdir -p "$LEARNINGS_HOME/documents/learnings/$CATEGORY"
# Write {learning_id}.md to $LEARNINGS_HOME/documents/learnings/$CATEGORY/
# Write {learning_id}.entities.yaml alongside it
C. Index into QMD + GraphRAG:
if [[ -x "$LEARNINGS_CLI" ]]; then
"$LEARNINGS_CLI" add "$LEARNINGS_HOME/documents/learnings/$CATEGORY/{learning_id}.md" \
--entities "$LEARNINGS_HOME/documents/learnings/$CATEGORY/{learning_id}.entities.yaml"
fi
D. Git commit the archive + learnings:
cd "$LEARNINGS_HOME"
git add "documents/memories/" "documents/learnings/$CATEGORY/" ".memory-ingest-log.yaml"
git commit -m "reflect: ingest $COUNT memories from $PROJECT_COUNT projects
Archived: $COUNT original memory files
Indexed: $INDEXED learnings into QMD + GraphRAG
Projects: $(echo $PROJECTS | tr ' ' ', ')"
After successful indexing, create a tracking file so already-ingested memories aren't reprocessed:
INGEST_LOG="$LEARNINGS_HOME/.memory-ingest-log.yaml"
# Append entry:
# - file: {full path}
# ingested_at: {ISO timestamp}
# learning_id: {learning_id}
On subsequent runs, check this log before processing each memory file.
## Memory Ingestion Complete
- **Scanned**: N projects, M memory files
- **Archived**: K files to $LEARNINGS_HOME/documents/memories/
- **Indexed**: K new learnings (QMD + GraphRAG)
- **Skipped**: J (already in KB or duplicate)
- **Updated**: L (merged newer info)
- **Git committed**: Yes (to $LEARNINGS_HOME local repo)
Archived originals:
- $LEARNINGS_HOME/documents/memories/{project}/*.md
Indexed learnings:
- QMD: K documents embedded
- GraphRAG: K documents + P entities + Q relationships
If $LEARNINGS_HOME has no git remote configured, warn:
⚠️ Your knowledge base ($LEARNINGS_HOME) has no git remote.
Archives are git-tracked locally but NOT backed up.
To add a remote: cd $LEARNINGS_HOME && git remote add origin <your-repo-url> && git push -u origin main
After ingestion, offer to flag memory files that have been successfully ingested:
The following memory files have been archived to $LEARNINGS_HOME
and indexed into QMD + GraphRAG. They are now searchable via /research
and will survive dream pruning or project deletion.
Would you like to keep the originals in {{HOME_TOOL_DIR}}/projects/? [Y/n]
Default: keep originals — Claude Code's auto-memory system still reads them for
context window injection. Only delete if the user explicitly requests cleanup.
Archived copies in $LEARNINGS_HOME/documents/memories/ are the durable backup.
| Scope | Location |
|-------|----------|
| Project memory | .agents/MEMORY.md (200 lines max) |
| Project knowledge | docs/solutions/{category}/{name}.md + .entities.yaml |
| Memory archive | $LEARNINGS_HOME/documents/memories/{project}/ (git-tracked originals) |
| Global knowledge | $LEARNINGS_HOME/documents/learnings/ (via learnings add) |
| Global episodes | $LEARNINGS_HOME/documents/episodes/ (via learnings add) |
| Global metrics | $LEARNINGS_HOME/metrics.yaml |
| Signal | Target | Immediately searchable? |
|--------|--------|------------------------|
| Behavioral corrections | Agent file | N/A (loaded as rules) |
| Reusable knowledge (fix, pattern, technique) | Knowledge note → docs/solutions/ + learnings add | YES |
| Session context & provenance | Episode → $LEARNINGS_HOME/documents/episodes/ + learnings add | YES |
| Project-specific gotchas | .agents/MEMORY.md + knowledge note | Partial (memory: context window, note: full search) |
| Recurring bugs | New skill OR knowledge note | YES |
| LOW confidence + project-specific | .agents/MEMORY.md only | No (context window only) |
git revertIf auto-reflection is enabled, PreCompact hook triggers reflection before handover.
At 70%+ context (Yellow status), reminders to run /reflect are injected.
Knowledge learnings captured here are automatically searchable via:
/research [keywords]
# Checks docs/solutions/ first, then $LEARNINGS_HOME via CLI
At workflow completion, /workflow suggests running /reflect to capture learnings.
PreCompact hook triggers auto-reflection. See hooks/README.md for setup.
This skill works with any LLM tool that supports:
# Knowledge base home (default: ~/.learnings/)
export LEARNINGS_HOME=/path/to/learnings
# Reflect state directory
export REFLECT_STATE_DIR=/path/to/state
# Default: ~/.reflect/ (portable) or $HOME/{{TOOL_DIR}}/session/ (Claude Code)
Unlike the previous agent-based approach, this skill executes directly without spawning subagents. The LLM reads SKILL.md and follows the workflow.
Commits are wrapped with availability checks - if not in a git repo, changes are still saved but not committed.
No signals detected:
/reflect --review to check pending items/reflect --knowledge to specifically look for knowledge signalsConflict warning:
Agent file not found:
/reflect --status to see available targetsDe-duplication false positive:
links: fieldKnowledge base CLI not found:
$LEARNINGS_HOME/cli/learnings exists and is executabledocs/solutions/reflect/
├── SKILL.md # This file
├── scripts/
│ ├── state_manager.py # State file CRUD
│ ├── signal_detector.py # Pattern matching (behavioral + knowledge)
│ ├── metrics_updater.py # Metrics aggregation
│ ├── output_generator.py # Reflection file & index generation
│ └── memory_discovery.sh # Project memory discovery & cleanup
├── hooks/
│ ├── precompact_reflect.py # PreCompact hook integration
│ ├── settings-snippet.json # Settings.json examples
│ └── README.md # Hook configuration guide
├── references/
│ ├── signal_patterns.md # Detection rules (behavioral + knowledge)
│ ├── agent_mappings.md # Target mappings for behavioral signals
│ ├── classification_rules.md # Signal type, scope, learning type rules
│ ├── knowledge_format.md # Entity types, relationships, sidecar format
│ ├── note_templates.md # Learning, episode, and change templates
│ ├── consolidate_workflow.md # /reflect --consolidate workflow
│ └── skill_template.md # Skill generation guidelines
└── assets/
├── reflection_template.md # Output template
├── learning_template.md # Knowledge learning note template
├── episode_template.md # Episode note template
└── learnings_schema.yaml # Schema definition
documentation
Report reflect drain spend over a time window — tokens split by cached (cache_read), uncached writes (cache_creation), and io (input+output), with a $ estimate, grouped by day / outcome / model / transcript. Reads the drainer's cost log and surfaces outlier runs and cache-reuse health (the 41.5M-token failure mode = low cache reuse + high cache writes). Use to answer "what is reflection costing me" for the last day / week.
development
Show fleet status — every claude session running on the host, merged across ainb + claude-peers broker + background jobs. Use when you need to enumerate sessions before composing an action, see which sessions have a peer registered (broker-routable) vs tmux-only, check the `summary` of each session, or pipe the list into jq for filtering. Default output: text table. Pass --format json for LLM consumption.
testing
Ordered multi-step prompts to fleet targets, ack-gated between steps via JSONL assistant-turn-end detection. Use for cycles like disconnect→reconnect→verify, or any flow where step N+1 requires step N to have completed first. The skill BLOCKS until each target's transcript shows the next assistant turn finishing OR per-step timeout fires (default 300s).
development
Center control panel — enumerate every claude session that is blocked waiting on something: a user answer (AskUserQuestion fired), an API error retry, an idle assistant turn-end with no follow-up, or an explicit WAITING: marker. Returns rich JSON with signal kind + context per session. Use this when you've stepped away from the fleet and want one place to see everything that wants your attention and answer it.