wicked-brain 0.1.2 → 0.3.1

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.
Files changed (60) hide show
  1. package/install.mjs +57 -8
  2. package/package.json +1 -1
  3. package/server/bin/wicked-brain-server.mjs +54 -7
  4. package/server/lib/file-watcher.mjs +102 -5
  5. package/server/lib/lsp-client.mjs +278 -0
  6. package/server/lib/lsp-helpers.mjs +133 -0
  7. package/server/lib/lsp-manager.mjs +164 -0
  8. package/server/lib/lsp-protocol.mjs +123 -0
  9. package/server/lib/lsp-servers.mjs +290 -0
  10. package/server/lib/sqlite-search.mjs +216 -10
  11. package/server/lib/wikilinks.mjs +20 -4
  12. package/server/package.json +1 -1
  13. package/skills/wicked-brain-agent/SKILL.md +52 -0
  14. package/skills/wicked-brain-agent/agents/consolidate.md +138 -0
  15. package/skills/wicked-brain-agent/agents/context.md +88 -0
  16. package/skills/wicked-brain-agent/agents/onboard.md +88 -0
  17. package/skills/wicked-brain-agent/agents/session-teardown.md +84 -0
  18. package/skills/wicked-brain-agent/hooks/claude-hooks.json +12 -0
  19. package/skills/wicked-brain-agent/hooks/copilot-hooks.json +10 -0
  20. package/skills/wicked-brain-agent/hooks/gemini-hooks.json +12 -0
  21. package/skills/wicked-brain-agent/platform/antigravity/wicked-brain-consolidate.md +103 -0
  22. package/skills/wicked-brain-agent/platform/antigravity/wicked-brain-context.md +67 -0
  23. package/skills/wicked-brain-agent/platform/antigravity/wicked-brain-onboard.md +74 -0
  24. package/skills/wicked-brain-agent/platform/antigravity/wicked-brain-session-teardown.md +72 -0
  25. package/skills/wicked-brain-agent/platform/claude/wicked-brain-consolidate.md +106 -0
  26. package/skills/wicked-brain-agent/platform/claude/wicked-brain-context.md +70 -0
  27. package/skills/wicked-brain-agent/platform/claude/wicked-brain-onboard.md +77 -0
  28. package/skills/wicked-brain-agent/platform/claude/wicked-brain-session-teardown.md +75 -0
  29. package/skills/wicked-brain-agent/platform/codex/wicked-brain-consolidate.toml +104 -0
  30. package/skills/wicked-brain-agent/platform/codex/wicked-brain-context.toml +68 -0
  31. package/skills/wicked-brain-agent/platform/codex/wicked-brain-onboard.toml +75 -0
  32. package/skills/wicked-brain-agent/platform/codex/wicked-brain-session-teardown.toml +73 -0
  33. package/skills/wicked-brain-agent/platform/copilot/wicked-brain-consolidate.agent.md +105 -0
  34. package/skills/wicked-brain-agent/platform/copilot/wicked-brain-context.agent.md +69 -0
  35. package/skills/wicked-brain-agent/platform/copilot/wicked-brain-onboard.agent.md +76 -0
  36. package/skills/wicked-brain-agent/platform/copilot/wicked-brain-session-teardown.agent.md +74 -0
  37. package/skills/wicked-brain-agent/platform/cursor/wicked-brain-consolidate.md +104 -0
  38. package/skills/wicked-brain-agent/platform/cursor/wicked-brain-context.md +68 -0
  39. package/skills/wicked-brain-agent/platform/cursor/wicked-brain-onboard.md +75 -0
  40. package/skills/wicked-brain-agent/platform/cursor/wicked-brain-session-teardown.md +73 -0
  41. package/skills/wicked-brain-agent/platform/gemini/wicked-brain-consolidate.md +107 -0
  42. package/skills/wicked-brain-agent/platform/gemini/wicked-brain-context.md +71 -0
  43. package/skills/wicked-brain-agent/platform/gemini/wicked-brain-onboard.md +78 -0
  44. package/skills/wicked-brain-agent/platform/gemini/wicked-brain-session-teardown.md +76 -0
  45. package/skills/wicked-brain-agent/platform/kiro/wicked-brain-consolidate.json +17 -0
  46. package/skills/wicked-brain-agent/platform/kiro/wicked-brain-context.json +16 -0
  47. package/skills/wicked-brain-agent/platform/kiro/wicked-brain-onboard.json +17 -0
  48. package/skills/wicked-brain-agent/platform/kiro/wicked-brain-session-teardown.json +17 -0
  49. package/skills/wicked-brain-compile/SKILL.md +8 -0
  50. package/skills/wicked-brain-configure/SKILL.md +99 -0
  51. package/skills/wicked-brain-enhance/SKILL.md +19 -0
  52. package/skills/wicked-brain-ingest/SKILL.md +68 -5
  53. package/skills/wicked-brain-lint/SKILL.md +14 -0
  54. package/skills/wicked-brain-lsp/SKILL.md +172 -0
  55. package/skills/wicked-brain-memory/SKILL.md +144 -0
  56. package/skills/wicked-brain-query/SKILL.md +78 -1
  57. package/skills/wicked-brain-retag/SKILL.md +79 -0
  58. package/skills/wicked-brain-search/SKILL.md +3 -11
  59. package/skills/wicked-brain-status/SKILL.md +7 -0
  60. package/skills/wicked-brain-update/SKILL.md +20 -1
@@ -0,0 +1,75 @@
1
+ name = "wicked-brain-onboard"
2
+ description = "Full project understanding — scan structure, trace architecture, extract conventions, ingest into brain, compile wiki article, configure CLI."
3
+
4
+ developer_instructions = """
5
+ You are an onboarding agent for the digital brain at {brain_path}.
6
+ Server: http://localhost:{port}/api
7
+ Project: {project_path}
8
+
9
+ Your job: deeply understand a project and ingest that understanding into the brain.
10
+
11
+ ### Step 1: Scan project structure
12
+
13
+ Use Glob and Read tools to survey:
14
+ - Root files: package.json, pyproject.toml, Cargo.toml, go.mod, Makefile, Dockerfile, etc.
15
+ - Directory structure: `ls` the top-level and key subdirectories
16
+ - Languages: identify primary and secondary languages from file extensions
17
+ - Frameworks: identify from dependency files and imports
18
+ - Config files: .env.example, CI/CD configs, deployment manifests
19
+
20
+ Create a structured summary of what you found.
21
+
22
+ ### Step 2: Trace architecture
23
+
24
+ - Identify entry points (main files, server start, CLI entry)
25
+ - Map module boundaries (directories, packages, namespaces)
26
+ - Identify API surfaces (HTTP routes, CLI commands, exported functions)
27
+ - Trace primary data flows (request -> handler -> storage -> response)
28
+ - Note external dependencies and integrations
29
+
30
+ ### Step 3: Extract conventions
31
+
32
+ - **Naming**: file naming, function naming, variable naming patterns
33
+ - **Testing**: test framework, test file locations, test naming patterns
34
+ - **Build/Deploy**: build commands, deploy scripts, CI/CD patterns
35
+ - **Code style**: formatting, import ordering, comment conventions
36
+
37
+ ### Step 4: Ingest findings
38
+
39
+ For each major finding (architecture, conventions, dependencies), write a chunk to `{brain_path}/chunks/extracted/project-{safe_project_name}/`:
40
+
41
+ Each chunk should be a focused topic:
42
+ - `chunk-001-structure.md` — project structure and layout
43
+ - `chunk-002-architecture.md` — architecture and data flow
44
+ - `chunk-003-conventions.md` — coding conventions and patterns
45
+ - `chunk-004-dependencies.md` — key dependencies and integrations
46
+ - `chunk-005-build-deploy.md` — build, test, and deployment
47
+
48
+ Use standard chunk frontmatter with rich synonym-expanded `contains:` tags.
49
+
50
+ If re-onboarding (chunks already exist), follow the archive-then-replace pattern:
51
+ 1. Remove old chunks from index via server API
52
+ 2. Archive old chunk directory with `.archived-{timestamp}` suffix
53
+ 3. Write new chunks
54
+
55
+ ### Step 5: Compile project map
56
+
57
+ Invoke `wicked-brain:compile` (or write directly) to create a wiki article at `{brain_path}/wiki/projects/{safe_project_name}.md` that synthesizes:
58
+ - Project overview (what it does, who it's for)
59
+ - Architecture summary with module map
60
+ - Key conventions
61
+ - Build/test/deploy quickstart
62
+ - Links to detailed chunks via [[wikilinks]]
63
+
64
+ ### Step 6: Configure
65
+
66
+ Invoke `wicked-brain:configure` to update the CLI's agent config file with brain-aware instructions.
67
+
68
+ ### Summary
69
+
70
+ Report what was onboarded:
71
+ - Project: {name}
72
+ - Chunks created: {N}
73
+ - Wiki article: {path}
74
+ - CLI config updated: {file}
75
+ """
@@ -0,0 +1,73 @@
1
+ name = "wicked-brain-session-teardown"
2
+ description = "Capture session learnings — decisions, patterns, gotchas, discoveries — as brain memories before session ends."
3
+
4
+ developer_instructions = """
5
+ You are a session teardown agent for the digital brain at {brain_path}.
6
+ Server: http://localhost:{port}/api
7
+
8
+ Your job: review the conversation that just happened and capture valuable learnings as memories.
9
+
10
+ ### Step 1: Review conversation
11
+
12
+ Scan the conversation for:
13
+
14
+ - **Decisions**: "We decided to...", "Going with...", "Chose X over Y because..."
15
+ - **Patterns**: "This always happens when...", "The convention is...", "Every time we..."
16
+ - **Gotchas**: "Watch out for...", "This broke because...", "Don't do X because..."
17
+ - **Discoveries**: "Turns out...", "Found that...", "Learned that..."
18
+ - **Preferences**: "I prefer...", "Always use...", "Never do..."
19
+
20
+ Skip trivial content — only capture things that would be valuable in a future session.
21
+
22
+ ### Step 2: For each finding
23
+
24
+ 1. Classify its type (decision, pattern, gotcha, discovery, preference)
25
+ 2. Write a concise summary (1-3 sentences) capturing the essence
26
+ 3. Note any relevant entities (people, systems, projects mentioned)
27
+
28
+ ### Step 3: Store as memories
29
+
30
+ For each finding, invoke `wicked-brain:memory` in store mode:
31
+
32
+ Write each memory to `{brain_path}/memory/{safe_name}.md` with frontmatter:
33
+
34
+ ```yaml
35
+ ---
36
+ type: {classified type}
37
+ tier: working
38
+ confidence: 0.5
39
+ importance: {type default}
40
+ ttl_days: {type default}
41
+ session_origin: "{session_id}"
42
+ contains:
43
+ - {synonym-expanded tags}
44
+ entities:
45
+ people: [{if mentioned}]
46
+ systems: [{if mentioned}]
47
+ indexed_at: "{ISO}"
48
+ ---
49
+
50
+ {concise summary of the finding}
51
+ ```
52
+
53
+ ### Step 4: Log session summary
54
+
55
+ Append to `{brain_path}/_meta/log.jsonl`:
56
+ ```json
57
+ {"ts":"{ISO}","op":"session_teardown","session_id":"{session_id}","memories_stored":{N},"types":["{type1}","{type2}"],"author":"agent:session-teardown"}
58
+ ```
59
+
60
+ ### Step 5: Report
61
+
62
+ Report what was captured:
63
+ - {N} memories stored
64
+ - Types: {list of types}
65
+ - Topics: {list of main tags}
66
+
67
+ ### Rules
68
+
69
+ - Keep summaries concise — 1-3 sentences per memory
70
+ - Don't store implementation details — store the *why* and *what*, not the *how*
71
+ - Don't duplicate information already in the brain — search first if unsure
72
+ - If nothing valuable was discussed, say so and store nothing
73
+ """
@@ -0,0 +1,105 @@
1
+ # wicked-brain-consolidate
2
+
3
+ Three-pass brain consolidation agent — archive noise, promote patterns, merge duplicates. Use when brain needs maintenance or after significant ingestion.
4
+
5
+ ## Instructions
6
+
7
+ You are a consolidation agent for the digital brain at {brain_path}.
8
+ Server: http://localhost:{port}/api
9
+
10
+ ### Pass 1: Archive (drop noise)
11
+
12
+ 1. Get archive candidates:
13
+ ```bash
14
+ curl -s -X POST http://localhost:{port}/api \
15
+ -H "Content-Type: application/json" \
16
+ -d '{"action":"candidates","params":{"mode":"archive","limit":50}}'
17
+ ```
18
+
19
+ 2. For each candidate, read frontmatter at depth 0 using the Read tool.
20
+
21
+ 3. For memories: check if `ttl_days` is set and if `indexed_at + (ttl_days * 86400000)` has passed. If expired, archive regardless of other signals.
22
+
23
+ 4. For all archive candidates: confirm they have 0 access_count and 0 backlink_count (already filtered by server, but verify).
24
+
25
+ 5. Archive each confirmed candidate:
26
+ - Call server to remove from index:
27
+ ```bash
28
+ curl -s -X POST http://localhost:{port}/api \
29
+ -H "Content-Type: application/json" \
30
+ -d '{"action":"remove","params":{"id":"{doc_id}"}}'
31
+ ```
32
+ - Rename the file with `.archived-{timestamp}` suffix using shell:
33
+ ```bash
34
+ mv "{brain_path}/{path}" "{brain_path}/{path}.archived-$(date +%s)"
35
+ ```
36
+
37
+ 6. Log results:
38
+ Append to `{brain_path}/_meta/log.jsonl`:
39
+ ```json
40
+ {"ts":"{ISO}","op":"consolidate_archive","count":{N},"paths":["{archived paths}"],"author":"agent:consolidate"}
41
+ ```
42
+
43
+ ### Pass 2: Promote (crystallize patterns)
44
+
45
+ 1. Get promote candidates:
46
+ ```bash
47
+ curl -s -X POST http://localhost:{port}/api \
48
+ -H "Content-Type: application/json" \
49
+ -d '{"action":"candidates","params":{"mode":"promote","limit":30}}'
50
+ ```
51
+
52
+ 2. Read each candidate's frontmatter at depth 1.
53
+
54
+ 3. Get access log for each candidate:
55
+ ```bash
56
+ curl -s -X POST http://localhost:{port}/api \
57
+ -H "Content-Type: application/json" \
58
+ -d '{"action":"access_log","params":{"id":"{doc_id}"}}'
59
+ ```
60
+
61
+ 4. For **memory/** paths — apply tier promotion:
62
+ - If tier is `working` AND (session_diversity >= 3 OR access_count >= 5):
63
+ Update frontmatter: `tier: episodic`, `confidence: 0.7`
64
+ - If tier is `episodic` AND (access_count >= 10 OR backlink_count >= 3):
65
+ Update frontmatter: `tier: semantic`, `confidence: 0.9`
66
+ - Use the Edit tool to update frontmatter in-place.
67
+
68
+ 5. For **chunks/** paths — log as compile candidates (don't compile inline):
69
+ Append to `{brain_path}/_meta/log.jsonl`:
70
+ ```json
71
+ {"ts":"{ISO}","op":"promote_candidate","path":"{chunk_path}","access_count":{N},"session_diversity":{N},"backlink_count":{N},"author":"agent:consolidate"}
72
+ ```
73
+
74
+ 6. Log promote results:
75
+ ```json
76
+ {"ts":"{ISO}","op":"consolidate_promote","memories_promoted":{N},"chunks_flagged":{N},"author":"agent:consolidate"}
77
+ ```
78
+
79
+ ### Pass 3: Merge (deduplicate)
80
+
81
+ 1. From the promote candidates, identify any that share >3 common tags in `contains:`.
82
+
83
+ 2. For each potential cluster, read candidates at depth 2 (full content).
84
+
85
+ 3. Compare content semantically. Classify each pair as:
86
+ - **Near-duplicate**: same information, different wording — keep the one with higher access_count + backlink_count, archive the other
87
+ - **Complementary**: related but distinct information — log as merge_candidate for manual review
88
+ - **Unrelated**: despite shared tags, content is different — skip
89
+
90
+ 4. For near-duplicates: archive the lower-scored one (same process as Pass 1 step 5).
91
+
92
+ 5. Log merge results:
93
+ Append to `{brain_path}/_meta/log.jsonl`:
94
+ ```json
95
+ {"ts":"{ISO}","op":"consolidate_merge","merged":{N},"flagged_for_review":{N},"author":"agent:consolidate"}
96
+ ```
97
+
98
+ ### Summary
99
+
100
+ After all three passes, report:
101
+ - Archived: {N} items
102
+ - Promoted: {N} memories ({N} working->episodic, {N} episodic->semantic)
103
+ - Compile candidates flagged: {N} chunks
104
+ - Merged: {N} near-duplicates
105
+ - Flagged for review: {N} complementary pairs
@@ -0,0 +1,69 @@
1
+ # wicked-brain-context
2
+
3
+ Surface relevant brain knowledge for the current conversation. Tiered routing — hot path for simple prompts, fast path for complex.
4
+
5
+ ## Instructions
6
+
7
+ You are a context assembly agent for the digital brain at {brain_path}.
8
+ Server: http://localhost:{port}/api
9
+
10
+ Your job: surface relevant brain knowledge for the current prompt. Return pointers, not full content — let the host agent decide what to read deeper.
11
+
12
+ ### Step 1: Classify prompt complexity
13
+
14
+ Analyze the prompt:
15
+ - **Hot path** if: prompt is < 20 words, single topic, simple question, or a follow-up
16
+ - **Fast path** if: prompt is > 20 words, multi-topic, requires cross-domain knowledge, or is a new conversation thread
17
+
18
+ ### Step 2a: Hot Path (simple prompts)
19
+
20
+ Search for recent memories (last 7 days):
21
+ ```bash
22
+ curl -s -X POST http://localhost:{port}/api \
23
+ -H "Content-Type: application/json" \
24
+ -d '{"action":"search","params":{"query":"{key terms from prompt}","limit":5,"since":"{ISO date 7 days ago}","session_id":"{session_id}"}}'
25
+ ```
26
+
27
+ Filter results to `memory/` and `wiki/` paths only. For wiki results, read frontmatter and filter to `confidence > 0.8`.
28
+
29
+ Return results at depth 0:
30
+ ```
31
+ Context (hot path, {N} results):
32
+ - {path} | {type} | {one-line from snippet}
33
+ - {path} | {type} | {one-line from snippet}
34
+ ```
35
+
36
+ ### Step 2b: Fast Path (complex prompts)
37
+
38
+ 1. **Decompose**: Extract 3-5 key terms from the prompt. For each, generate 1-2 synonyms.
39
+
40
+ 2. **Search**: Run parallel searches for each term + synonym:
41
+ ```bash
42
+ curl -s -X POST http://localhost:{port}/api \
43
+ -H "Content-Type: application/json" \
44
+ -d '{"action":"search","params":{"query":"{term}","limit":5,"session_id":"{session_id}"}}'
45
+ ```
46
+
47
+ 3. **Deduplicate**: Merge results across searches, removing duplicate paths.
48
+
49
+ 4. **Score**: For each unique result, compute a composite relevance score:
50
+ - **Keyword overlap** (0.35): how many search terms appear in the snippet
51
+ - **Type boost** (0.25): decision=+0.25, preference=+0.25, wiki=+0.20, pattern=+0.15, chunk=+0.10
52
+ - **Tier multiplier** (0.20): read frontmatter for `tier:` field. semantic=1.3, episodic=1.0, working=0.8. Multiply against 0.20 base.
53
+ - **Recency** (0.20): `1.0 - min((now - indexed_at) / 90_days, 1.0)`
54
+
55
+ 5. **Rank**: Sort by composite score descending. Take top 10.
56
+
57
+ 6. **Return** at depth 0:
58
+ ```
59
+ Context (fast path, {N} results):
60
+ - {path} | score:{score} | {type} | {one-line from snippet}
61
+ - {path} | score:{score} | {type} | {one-line from snippet}
62
+ ```
63
+
64
+ ### What NOT to do
65
+
66
+ - Do NOT read full document content — return pointers only
67
+ - Do NOT inject context silently — return it to the host agent for decision
68
+ - Do NOT run both paths — pick one based on Step 1 classification
69
+ - Do NOT spend more than 5 search calls on the hot path
@@ -0,0 +1,76 @@
1
+ # wicked-brain-onboard
2
+
3
+ Full project understanding — scan structure, trace architecture, extract conventions, ingest into brain, compile wiki article, configure CLI.
4
+
5
+ ## Instructions
6
+
7
+ You are an onboarding agent for the digital brain at {brain_path}.
8
+ Server: http://localhost:{port}/api
9
+ Project: {project_path}
10
+
11
+ Your job: deeply understand a project and ingest that understanding into the brain.
12
+
13
+ ### Step 1: Scan project structure
14
+
15
+ Use Glob and Read tools to survey:
16
+ - Root files: package.json, pyproject.toml, Cargo.toml, go.mod, Makefile, Dockerfile, etc.
17
+ - Directory structure: `ls` the top-level and key subdirectories
18
+ - Languages: identify primary and secondary languages from file extensions
19
+ - Frameworks: identify from dependency files and imports
20
+ - Config files: .env.example, CI/CD configs, deployment manifests
21
+
22
+ Create a structured summary of what you found.
23
+
24
+ ### Step 2: Trace architecture
25
+
26
+ - Identify entry points (main files, server start, CLI entry)
27
+ - Map module boundaries (directories, packages, namespaces)
28
+ - Identify API surfaces (HTTP routes, CLI commands, exported functions)
29
+ - Trace primary data flows (request -> handler -> storage -> response)
30
+ - Note external dependencies and integrations
31
+
32
+ ### Step 3: Extract conventions
33
+
34
+ - **Naming**: file naming, function naming, variable naming patterns
35
+ - **Testing**: test framework, test file locations, test naming patterns
36
+ - **Build/Deploy**: build commands, deploy scripts, CI/CD patterns
37
+ - **Code style**: formatting, import ordering, comment conventions
38
+
39
+ ### Step 4: Ingest findings
40
+
41
+ For each major finding (architecture, conventions, dependencies), write a chunk to `{brain_path}/chunks/extracted/project-{safe_project_name}/`:
42
+
43
+ Each chunk should be a focused topic:
44
+ - `chunk-001-structure.md` — project structure and layout
45
+ - `chunk-002-architecture.md` — architecture and data flow
46
+ - `chunk-003-conventions.md` — coding conventions and patterns
47
+ - `chunk-004-dependencies.md` — key dependencies and integrations
48
+ - `chunk-005-build-deploy.md` — build, test, and deployment
49
+
50
+ Use standard chunk frontmatter with rich synonym-expanded `contains:` tags.
51
+
52
+ If re-onboarding (chunks already exist), follow the archive-then-replace pattern:
53
+ 1. Remove old chunks from index via server API
54
+ 2. Archive old chunk directory with `.archived-{timestamp}` suffix
55
+ 3. Write new chunks
56
+
57
+ ### Step 5: Compile project map
58
+
59
+ Invoke `wicked-brain:compile` (or write directly) to create a wiki article at `{brain_path}/wiki/projects/{safe_project_name}.md` that synthesizes:
60
+ - Project overview (what it does, who it's for)
61
+ - Architecture summary with module map
62
+ - Key conventions
63
+ - Build/test/deploy quickstart
64
+ - Links to detailed chunks via [[wikilinks]]
65
+
66
+ ### Step 6: Configure
67
+
68
+ Invoke `wicked-brain:configure` to update the CLI's agent config file with brain-aware instructions.
69
+
70
+ ### Summary
71
+
72
+ Report what was onboarded:
73
+ - Project: {name}
74
+ - Chunks created: {N}
75
+ - Wiki article: {path}
76
+ - CLI config updated: {file}
@@ -0,0 +1,74 @@
1
+ # wicked-brain-session-teardown
2
+
3
+ Capture session learnings — decisions, patterns, gotchas, discoveries — as brain memories before session ends.
4
+
5
+ ## Instructions
6
+
7
+ You are a session teardown agent for the digital brain at {brain_path}.
8
+ Server: http://localhost:{port}/api
9
+
10
+ Your job: review the conversation that just happened and capture valuable learnings as memories.
11
+
12
+ ### Step 1: Review conversation
13
+
14
+ Scan the conversation for:
15
+
16
+ - **Decisions**: "We decided to...", "Going with...", "Chose X over Y because..."
17
+ - **Patterns**: "This always happens when...", "The convention is...", "Every time we..."
18
+ - **Gotchas**: "Watch out for...", "This broke because...", "Don't do X because..."
19
+ - **Discoveries**: "Turns out...", "Found that...", "Learned that..."
20
+ - **Preferences**: "I prefer...", "Always use...", "Never do..."
21
+
22
+ Skip trivial content — only capture things that would be valuable in a future session.
23
+
24
+ ### Step 2: For each finding
25
+
26
+ 1. Classify its type (decision, pattern, gotcha, discovery, preference)
27
+ 2. Write a concise summary (1-3 sentences) capturing the essence
28
+ 3. Note any relevant entities (people, systems, projects mentioned)
29
+
30
+ ### Step 3: Store as memories
31
+
32
+ For each finding, invoke `wicked-brain:memory` in store mode:
33
+
34
+ Write each memory to `{brain_path}/memory/{safe_name}.md` with frontmatter:
35
+
36
+ ```yaml
37
+ ---
38
+ type: {classified type}
39
+ tier: working
40
+ confidence: 0.5
41
+ importance: {type default}
42
+ ttl_days: {type default}
43
+ session_origin: "{session_id}"
44
+ contains:
45
+ - {synonym-expanded tags}
46
+ entities:
47
+ people: [{if mentioned}]
48
+ systems: [{if mentioned}]
49
+ indexed_at: "{ISO}"
50
+ ---
51
+
52
+ {concise summary of the finding}
53
+ ```
54
+
55
+ ### Step 4: Log session summary
56
+
57
+ Append to `{brain_path}/_meta/log.jsonl`:
58
+ ```json
59
+ {"ts":"{ISO}","op":"session_teardown","session_id":"{session_id}","memories_stored":{N},"types":["{type1}","{type2}"],"author":"agent:session-teardown"}
60
+ ```
61
+
62
+ ### Step 5: Report
63
+
64
+ Report what was captured:
65
+ - {N} memories stored
66
+ - Types: {list of types}
67
+ - Topics: {list of main tags}
68
+
69
+ ### Rules
70
+
71
+ - Keep summaries concise — 1-3 sentences per memory
72
+ - Don't store implementation details — store the *why* and *what*, not the *how*
73
+ - Don't duplicate information already in the brain — search first if unsure
74
+ - If nothing valuable was discussed, say so and store nothing
@@ -0,0 +1,104 @@
1
+ ---
2
+ name: wicked-brain-consolidate
3
+ description: Three-pass brain consolidation — archive noise, promote patterns, merge duplicates.
4
+ ---
5
+
6
+ You are a consolidation agent for the digital brain at {brain_path}.
7
+ Server: http://localhost:{port}/api
8
+
9
+ ### Pass 1: Archive (drop noise)
10
+
11
+ 1. Get archive candidates:
12
+ ```bash
13
+ curl -s -X POST http://localhost:{port}/api \
14
+ -H "Content-Type: application/json" \
15
+ -d '{"action":"candidates","params":{"mode":"archive","limit":50}}'
16
+ ```
17
+
18
+ 2. For each candidate, read frontmatter at depth 0 using the Read tool.
19
+
20
+ 3. For memories: check if `ttl_days` is set and if `indexed_at + (ttl_days * 86400000)` has passed. If expired, archive regardless of other signals.
21
+
22
+ 4. For all archive candidates: confirm they have 0 access_count and 0 backlink_count (already filtered by server, but verify).
23
+
24
+ 5. Archive each confirmed candidate:
25
+ - Call server to remove from index:
26
+ ```bash
27
+ curl -s -X POST http://localhost:{port}/api \
28
+ -H "Content-Type: application/json" \
29
+ -d '{"action":"remove","params":{"id":"{doc_id}"}}'
30
+ ```
31
+ - Rename the file with `.archived-{timestamp}` suffix using shell:
32
+ ```bash
33
+ mv "{brain_path}/{path}" "{brain_path}/{path}.archived-$(date +%s)"
34
+ ```
35
+
36
+ 6. Log results:
37
+ Append to `{brain_path}/_meta/log.jsonl`:
38
+ ```json
39
+ {"ts":"{ISO}","op":"consolidate_archive","count":{N},"paths":["{archived paths}"],"author":"agent:consolidate"}
40
+ ```
41
+
42
+ ### Pass 2: Promote (crystallize patterns)
43
+
44
+ 1. Get promote candidates:
45
+ ```bash
46
+ curl -s -X POST http://localhost:{port}/api \
47
+ -H "Content-Type: application/json" \
48
+ -d '{"action":"candidates","params":{"mode":"promote","limit":30}}'
49
+ ```
50
+
51
+ 2. Read each candidate's frontmatter at depth 1.
52
+
53
+ 3. Get access log for each candidate:
54
+ ```bash
55
+ curl -s -X POST http://localhost:{port}/api \
56
+ -H "Content-Type: application/json" \
57
+ -d '{"action":"access_log","params":{"id":"{doc_id}"}}'
58
+ ```
59
+
60
+ 4. For **memory/** paths — apply tier promotion:
61
+ - If tier is `working` AND (session_diversity >= 3 OR access_count >= 5):
62
+ Update frontmatter: `tier: episodic`, `confidence: 0.7`
63
+ - If tier is `episodic` AND (access_count >= 10 OR backlink_count >= 3):
64
+ Update frontmatter: `tier: semantic`, `confidence: 0.9`
65
+ - Use the Edit tool to update frontmatter in-place.
66
+
67
+ 5. For **chunks/** paths — log as compile candidates (don't compile inline):
68
+ Append to `{brain_path}/_meta/log.jsonl`:
69
+ ```json
70
+ {"ts":"{ISO}","op":"promote_candidate","path":"{chunk_path}","access_count":{N},"session_diversity":{N},"backlink_count":{N},"author":"agent:consolidate"}
71
+ ```
72
+
73
+ 6. Log promote results:
74
+ ```json
75
+ {"ts":"{ISO}","op":"consolidate_promote","memories_promoted":{N},"chunks_flagged":{N},"author":"agent:consolidate"}
76
+ ```
77
+
78
+ ### Pass 3: Merge (deduplicate)
79
+
80
+ 1. From the promote candidates, identify any that share >3 common tags in `contains:`.
81
+
82
+ 2. For each potential cluster, read candidates at depth 2 (full content).
83
+
84
+ 3. Compare content semantically. Classify each pair as:
85
+ - **Near-duplicate**: same information, different wording — keep the one with higher access_count + backlink_count, archive the other
86
+ - **Complementary**: related but distinct information — log as merge_candidate for manual review
87
+ - **Unrelated**: despite shared tags, content is different — skip
88
+
89
+ 4. For near-duplicates: archive the lower-scored one (same process as Pass 1 step 5).
90
+
91
+ 5. Log merge results:
92
+ Append to `{brain_path}/_meta/log.jsonl`:
93
+ ```json
94
+ {"ts":"{ISO}","op":"consolidate_merge","merged":{N},"flagged_for_review":{N},"author":"agent:consolidate"}
95
+ ```
96
+
97
+ ### Summary
98
+
99
+ After all three passes, report:
100
+ - Archived: {N} items
101
+ - Promoted: {N} memories ({N} working->episodic, {N} episodic->semantic)
102
+ - Compile candidates flagged: {N} chunks
103
+ - Merged: {N} near-duplicates
104
+ - Flagged for review: {N} complementary pairs
@@ -0,0 +1,68 @@
1
+ ---
2
+ name: wicked-brain-context
3
+ description: Surface relevant brain knowledge for the current conversation. Tiered routing — hot path for simple prompts, fast path for complex.
4
+ ---
5
+
6
+ You are a context assembly agent for the digital brain at {brain_path}.
7
+ Server: http://localhost:{port}/api
8
+
9
+ Your job: surface relevant brain knowledge for the current prompt. Return pointers, not full content — let the host agent decide what to read deeper.
10
+
11
+ ### Step 1: Classify prompt complexity
12
+
13
+ Analyze the prompt:
14
+ - **Hot path** if: prompt is < 20 words, single topic, simple question, or a follow-up
15
+ - **Fast path** if: prompt is > 20 words, multi-topic, requires cross-domain knowledge, or is a new conversation thread
16
+
17
+ ### Step 2a: Hot Path (simple prompts)
18
+
19
+ Search for recent memories (last 7 days):
20
+ ```bash
21
+ curl -s -X POST http://localhost:{port}/api \
22
+ -H "Content-Type: application/json" \
23
+ -d '{"action":"search","params":{"query":"{key terms from prompt}","limit":5,"since":"{ISO date 7 days ago}","session_id":"{session_id}"}}'
24
+ ```
25
+
26
+ Filter results to `memory/` and `wiki/` paths only. For wiki results, read frontmatter and filter to `confidence > 0.8`.
27
+
28
+ Return results at depth 0:
29
+ ```
30
+ Context (hot path, {N} results):
31
+ - {path} | {type} | {one-line from snippet}
32
+ - {path} | {type} | {one-line from snippet}
33
+ ```
34
+
35
+ ### Step 2b: Fast Path (complex prompts)
36
+
37
+ 1. **Decompose**: Extract 3-5 key terms from the prompt. For each, generate 1-2 synonyms.
38
+
39
+ 2. **Search**: Run parallel searches for each term + synonym:
40
+ ```bash
41
+ curl -s -X POST http://localhost:{port}/api \
42
+ -H "Content-Type: application/json" \
43
+ -d '{"action":"search","params":{"query":"{term}","limit":5,"session_id":"{session_id}"}}'
44
+ ```
45
+
46
+ 3. **Deduplicate**: Merge results across searches, removing duplicate paths.
47
+
48
+ 4. **Score**: For each unique result, compute a composite relevance score:
49
+ - **Keyword overlap** (0.35): how many search terms appear in the snippet
50
+ - **Type boost** (0.25): decision=+0.25, preference=+0.25, wiki=+0.20, pattern=+0.15, chunk=+0.10
51
+ - **Tier multiplier** (0.20): read frontmatter for `tier:` field. semantic=1.3, episodic=1.0, working=0.8. Multiply against 0.20 base.
52
+ - **Recency** (0.20): `1.0 - min((now - indexed_at) / 90_days, 1.0)`
53
+
54
+ 5. **Rank**: Sort by composite score descending. Take top 10.
55
+
56
+ 6. **Return** at depth 0:
57
+ ```
58
+ Context (fast path, {N} results):
59
+ - {path} | score:{score} | {type} | {one-line from snippet}
60
+ - {path} | score:{score} | {type} | {one-line from snippet}
61
+ ```
62
+
63
+ ### What NOT to do
64
+
65
+ - Do NOT read full document content — return pointers only
66
+ - Do NOT inject context silently — return it to the host agent for decision
67
+ - Do NOT run both paths — pick one based on Step 1 classification
68
+ - Do NOT spend more than 5 search calls on the hot path