@titan-design/brain 0.6.1 → 0.7.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.
@@ -0,0 +1,84 @@
1
+ # Validation Gates
2
+
3
+ Deterministic verification steps used across the planning and implementation lifecycle. Each gate is a CLI command or script — not agent judgment.
4
+
5
+ ## Implementation Verification Pipeline
6
+
7
+ Run in order. All must pass before commit.
8
+
9
+ | # | Gate | Command | Pass Criteria |
10
+ |---|------|---------|---------------|
11
+ | 1 | Typecheck | `{{TYPECHECK_CMD}}` | Exit code 0, no errors |
12
+ | 2 | Tests | `{{TEST_CMD}}` | Exit code 0, all tests pass |
13
+ | 3 | Lint | `{{LINT_CMD}}` | Exit code 0, no errors/warnings |
14
+ | 4 | Format | `npx prettier --check .` | Exit code 0 (fix: `npx prettier --write .`) |
15
+ | 5 | Build | `{{BUILD_CMD}}` | Exit code 0, no errors |
16
+
17
+ **Retry policy:** If any gate fails, fix and retry. Try at least twice before escalating.
18
+
19
+ ## Planning Phase Gates
20
+
21
+ ### Research Gate
22
+ - **Check:** `.plans/<planId>/research-brief.md` exists and is non-empty
23
+ - **Pass:** File has at least the 4 required sections (Existing Code, External Findings, Knowledge Gaps, Recommendations)
24
+ - **Command:** `test -s .plans/<planId>/research-brief.md && grep -c "^## " .plans/<planId>/research-brief.md`
25
+
26
+ ### Design Gate
27
+ - **Check:** All 3 artifacts exist
28
+ - **Pass:** `spec.md`, `design.md`, and `acceptance-criteria.md` all exist in `.plans/<planId>/`
29
+ - **Command:**
30
+ ```bash
31
+ for f in spec.md design.md acceptance-criteria.md; do
32
+ test -s ".plans/<planId>/$f" || echo "MISSING: $f"
33
+ done
34
+ ```
35
+
36
+ ### Critic Gate
37
+ - **Check:** Critic report exists with verdict
38
+ - **Pass:** `critic-report.md` exists and contains `## Verdict: READY`
39
+ - **Fail:** Contains `## Verdict: NEEDS REVISION` — route back to design agent
40
+ - **Command:** `grep "^## Verdict:" .plans/<planId>/critic-report.md`
41
+
42
+ ### Spec Test Gate
43
+ - **Check:** Tests are stashed
44
+ - **Pass:** `git stash list` contains an entry matching `spec-tests-<planId>`
45
+ - **Command:** `git stash list | grep "spec-tests-<planId>"`
46
+
47
+ ### Decompose Gate
48
+ - **Check:** PM tasks created and briefings exist
49
+ - **Pass:** `brain pm task list --project <PREFIX>` shows new tasks with matching planId metadata, and briefing files exist
50
+ - **Command:**
51
+ ```bash
52
+ ls .plans/<planId>/briefings/task-*.md | wc -l
53
+ brain pm task list --project <PREFIX> | grep "<planId>"
54
+ ```
55
+
56
+ ## Wave Gates
57
+
58
+ Between implementation waves, verify:
59
+
60
+ | Gate | Command | Purpose |
61
+ |------|---------|---------|
62
+ | All wave N tests pass | `{{TEST_CMD}}` | No regressions from parallel work |
63
+ | Typecheck clean | `{{TYPECHECK_CMD}}` | Type compatibility across wave outputs |
64
+ | Lint clean | `{{LINT_CMD}}` | Code quality maintained |
65
+ | No file ownership conflicts | `git diff --name-only <wave-start>..HEAD` | Verify no unexpected file overlaps |
66
+
67
+ ## Review Gates
68
+
69
+ After implementation, before merge:
70
+
71
+ | Gate | Command | Purpose |
72
+ |------|---------|---------|
73
+ | Risk assessment | `review-route.sh <PREFIX> <RISK> <VERDICT>` | Route review based on risk |
74
+ | MERGE threshold | Risk < `reviewThreshold` AND verdict PASS | Auto-merge eligible |
75
+ | HUMAN_REVIEW threshold | Risk >= `reviewThreshold` | Requires human review task |
76
+
77
+ ## Gate Failure Escalation
78
+
79
+ | Failure | Action |
80
+ |---------|--------|
81
+ | Implementation gate fails 2x | Agent reports diagnostics, orchestrator decides: resume, re-design, or escalate |
82
+ | Critic verdict NEEDS REVISION 3x | Escalate to human walkthrough |
83
+ | Wave gate fails | Identify which task's output broke it, resume that agent |
84
+ | Review NEEDS WORK | Dispatch fixup agent via `review-fixup.md` |
@@ -0,0 +1,48 @@
1
+ # Writing Plans
2
+
3
+ Agent-mode phase. Create a structured implementation plan from the approved design.
4
+
5
+ ---
6
+
7
+ ## Context
8
+
9
+ - Topic: `{{TASK_DESCRIPTION}}`
10
+ - Project: `{{PROJECT_PREFIX}}`
11
+ - Location: `{{REPO_PATH}}`
12
+ - Plan ID: `{{PLAN_ID}}`
13
+
14
+ ## Instructions
15
+
16
+ Create the plan directory at `.claude/plans/{{PLAN_ID}}/` with:
17
+
18
+ ### 1. plan.md (<200 lines)
19
+ - Goal (one sentence)
20
+ - Architecture (2-3 sentences)
21
+ - Dependency graph
22
+ - Wave plan (parallel groups)
23
+ - Task table (name, files, wave, depends-on)
24
+
25
+ ### 2. manifest.json
26
+ - planId, createdAt, goal
27
+ - tasks array: id, name, briefing path, wave, dependsOn, fileOwnership, status
28
+ - waves array: id, tasks, gate
29
+
30
+ ### 3. briefings/task-NN.md (per task)
31
+ - Exact file paths
32
+ - Complete code (not "add validation")
33
+ - Exact commands with expected output
34
+ - File ownership allowlist
35
+ - Success criteria (runnable commands)
36
+ - Under 50 lines of meaningful content
37
+
38
+ ## Rules
39
+
40
+ - DRY: no duplicated logic across tasks
41
+ - YAGNI: only what's needed for the current feature
42
+ - TDD: write failing test → implement → pass
43
+ - Frequent commits: one per logical step
44
+ - Bite-sized steps: each step is one action (2-5 minutes)
45
+
46
+ ## Output
47
+
48
+ The complete plan directory, ready for execution.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titan-design/brain",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "Developer second brain with hybrid RAG search",
6
6
  "license": "MIT",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "scripts": {
20
20
  "dev": "tsx src/cli.ts",
21
- "build": "tsup",
21
+ "build": "tsup && mkdir -p dist/templates && cp src/modules/workflow/templates/*.md dist/templates/",
22
22
  "test": "vitest run",
23
23
  "test:watch": "vitest",
24
24
  "test:unit": "vitest run --project unit",
@@ -30,7 +30,8 @@
30
30
  "format:check": "prettier --check \"src/**/*.ts\" \"__tests__/**/*.ts\"",
31
31
  "test:coverage": "vitest run --coverage",
32
32
  "postinstall": "node scripts/postinstall.js",
33
- "preuninstall": "node scripts/preuninstall.js"
33
+ "preuninstall": "node scripts/preuninstall.js",
34
+ "lint:staged": "lint-staged"
34
35
  },
35
36
  "dependencies": {
36
37
  "@commander-js/extra-typings": "^13.1.0",
@@ -55,6 +56,7 @@
55
56
  "@types/turndown": "^5.0.6",
56
57
  "@vitest/coverage-v8": "^3.2.4",
57
58
  "eslint": "^9.20.0",
59
+ "lint-staged": "^16.3.2",
58
60
  "prettier": "^3.8.1",
59
61
  "tsup": "^8.3.6",
60
62
  "tsx": "^4.19.2",
@@ -66,6 +68,12 @@
66
68
  "access": "public",
67
69
  "provenance": true
68
70
  },
71
+ "lint-staged": {
72
+ "*.ts": [
73
+ "eslint --fix --no-error-on-unmatched-pattern",
74
+ "prettier --write"
75
+ ]
76
+ },
69
77
  "engines": {
70
78
  "node": ">=22"
71
79
  }
package/skill/SKILL.md CHANGED
@@ -16,39 +16,54 @@ A CLI for managing a developer second brain with hybrid BM25 + vector search, LL
16
16
  - User wants to capture a quick thought or link
17
17
  - User asks about extracted memories or facts
18
18
 
19
+ ## Prerequisites
20
+
21
+ Brain CLI requires **Node 22+**. If using nvm, run `nvm use 22` first.
22
+
19
23
  ## Commands
20
24
 
21
25
  Use `--json` flag on all commands when processing output programmatically.
22
26
 
23
- | Command | Purpose | Example |
24
- |---------|---------|---------|
25
- | `brain search "<query>" --json` | Hybrid search (BM25 + vector) | `brain search "authentication patterns" --json --limit 5` |
26
- | `brain search "<query>" --memories --json` | Search notes + extracted memories | `brain search "auth" --memories --json` |
27
- | `brain search "<query>" --rerank --json` | Search with cross-encoder reranking | `brain search "auth" --rerank --json` |
28
- | `brain search "<query>" --expand --json` | Search with graph-connected notes | `brain search "auth" --json --expand` |
29
- | `brain add <file>` | Add a note from file | `brain add ~/draft.md --type research --tier slow` |
30
- | `brain add --title "X" --type note` | Add from stdin | `echo "content" \| brain add --title "My Note" --type note` |
31
- | `brain quick "thought"` | Zero-friction capture to inbox | `brain quick "look into WebSockets vs SSE"` |
32
- | `brain inbox --json` | View inbox items | `brain inbox --status pending --json` |
33
- | `brain extract --all` | Extract memories from all notes | Requires Ollama running locally |
34
- | `brain extract --note <id>` | Extract memories from one note | `brain extract --note my-note-id` |
35
- | `brain memories list --json` | List active memories | `brain memories list --container default --json` |
36
- | `brain memories history <id>` | Show memory version chain | `brain memories history mem-abc123` |
37
- | `brain memories stats` | Memory count + expiry sweep | Shows active count, runs auto-forget |
38
- | `brain context <id> --json` | Note context (relations + memories) | `brain context my-note --json` |
39
- | `brain profile --format json` | Agent context profile | `brain profile --container default --format json` |
40
- | `brain status --json` | Database stats | Shows note count, embeddings, staleness |
41
- | `brain stale --json` | Notes needing review | `brain stale --tier slow --json` |
42
- | `brain index` | Re-index all notes | Only run when user asks -- this is slow |
43
- | `brain graph <note-id> --json` | Show note relations | `brain graph my-note --json` |
44
- | `brain doctor --json` | System health checks | Shows DB, embedder, LLM, inbox, stale status |
45
- | `brain doctor --fix` | Auto-repair issues | Pulls missing models, resets failed inbox |
46
- | `brain config get` | Show config | `brain config get` |
27
+ | Command | Purpose | Example |
28
+ | ------------------------------------------ | ----------------------------------- | ----------------------------------------------------------- |
29
+ | `brain search "<query>" --json` | Hybrid search (BM25 + vector) | `brain search "authentication patterns" --json --limit 5` |
30
+ | `brain search "<query>" --memories --json` | Search notes + extracted memories | `brain search "auth" --memories --json` |
31
+ | `brain search "<query>" --rerank --json` | Search with cross-encoder reranking | `brain search "auth" --rerank --json` |
32
+ | `brain search "<query>" --expand --json` | Search with graph-connected notes | `brain search "auth" --json --expand` |
33
+ | `brain add <file>` | Add a note from file | `brain add ~/draft.md --type research --tier slow` |
34
+ | `brain add --title "X" --type note` | Add from stdin | `echo "content" \| brain add --title "My Note" --type note` |
35
+ | `brain quick "thought"` | Zero-friction capture to inbox | `brain quick "look into WebSockets vs SSE"` |
36
+ | `brain inbox --json` | View inbox items | `brain inbox --status pending --json` |
37
+ | `brain extract --all` | Extract memories from all notes | Requires Ollama running locally |
38
+ | `brain extract --note <id>` | Extract memories from one note | `brain extract --note my-note-id` |
39
+ | `brain memories list --json` | List active memories | `brain memories list --container default --json` |
40
+ | `brain memories history <id>` | Show memory version chain | `brain memories history mem-abc123` |
41
+ | `brain memories stats` | Memory count + expiry sweep | Shows active count, runs auto-forget |
42
+ | `brain context <id> --json` | Note context (relations + memories) | `brain context my-note --json` |
43
+ | `brain profile --format json` | Agent context profile | `brain profile --container default --format json` |
44
+ | `brain status --json` | Database stats | Shows note count, embeddings, staleness |
45
+ | `brain stale --json` | Notes needing review | `brain stale --tier slow --json` |
46
+ | `brain index` | Re-index all notes | Only run when user asks -- this is slow |
47
+ | `brain graph <note-id> --json` | Show note relations | `brain graph my-note --json` |
48
+ | `brain doctor --json` | System health checks | Shows DB, embedder, LLM, inbox, stale status |
49
+ | `brain doctor --fix` | Auto-repair issues | Pulls missing models, resets failed inbox |
50
+ | `brain config get` | Show config | `brain config get` |
47
51
 
48
52
  ## Search Filters
49
53
 
54
+ Filter results by metadata fields — all filters are optional and combinable:
55
+
50
56
  ```bash
51
- brain search "query" --tier slow --tags "typescript,patterns" --confidence high --since 2025-01-01 --json
57
+ brain search "query" --tier slow # Filter by note tier
58
+ brain search "query" --category research # Filter by category
59
+ brain search "query" --tags "typescript,patterns" # Filter by tags
60
+ brain search "query" --confidence high # Filter by confidence level
61
+ brain search "query" --type decision # Filter by note type
62
+ brain search "query" --since 2025-01-01 # Filter by date
63
+ brain search "query" --module pm # Filter by module
64
+ brain search "query" --expand # Include graph-connected notes
65
+ brain search "query" --rerank # Cross-encoder reranking
66
+ brain search "query" --memories # Include extracted memories
52
67
  ```
53
68
 
54
69
  ## Note Conventions
@@ -56,15 +71,28 @@ brain search "query" --tier slow --tags "typescript,patterns" --confidence high
56
71
  **Types:** `note`, `decision`, `pattern`, `research`, `meeting`, `session-log`, `guide`
57
72
 
58
73
  **Tiers:**
74
+
59
75
  - `slow` -- permanent knowledge (notes, decisions, patterns, research). Has review intervals.
60
76
  - `fast` -- ephemeral (meetings, session logs). Has expiry dates. Auto-archived.
61
77
 
62
78
  **Key frontmatter fields:** `title`, `type`, `tier`, `tags`, `summary`, `confidence` (high/medium/low/speculative), `status` (current/outdated/deprecated/draft), `review-interval`, `related`
63
79
 
80
+ ## Knowledge Graph
81
+
82
+ Notes can be linked via the `related` frontmatter field. Use `brain graph` to traverse and `--expand` in search to include connected notes.
83
+
84
+ ```bash
85
+ brain graph <note-id> --depth 2 --json # Traverse 2-hop connections
86
+ brain search "query" --expand --json # Search with graph expansion
87
+ ```
88
+
89
+ After adding or updating `related` fields in frontmatter, run `brain index` to rebuild connections.
90
+
64
91
  ## Rules
65
92
 
66
93
  - Always use `--json` when you need to parse output
67
94
  - Search before claiming information isn't in the knowledge base
68
95
  - Do NOT run `brain index` unless the user explicitly asks -- it processes all files and is slow
96
+ - DO run `brain index` after bulk frontmatter changes (e.g., adding `related` fields) -- graph connections won't update until re-indexed
69
97
  - When adding notes, include frontmatter with at minimum: title, type, tier
70
98
  - Present search results with score, file path, and excerpt