Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .brain/BRAIN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# `.brain/` — agent workflow rules

This repo has a per-project second brain at `.brain/`. Hooks in
`.claude/settings.json` drive it automatically. Your job during a session:
keep the brain useful for the *next* session.

## At session start (already automatic)

The `SessionStart` hook runs `.brain/scripts/assemble-context.sh`, which
generates `.brain/_CONTEXT.md` and injects it into context. It contains:
- Pointers to CKIS (`_MEMORY.md`, `_overview.md`, architecture spec)
- Last 3 session summaries
- Open decisions and bugs
- Top of `GRAPH_REPORT.md` (if Graphify has run)

You don't need to read `_CONTEXT.md` again — it's already in context.

## During the session — what's auto-captured

The `PostToolUse` hook runs `.brain/scripts/log-tool-event.sh` after every
Bash call and silently appends one line to `.brain/sessions/_active.md`
**only** for these objectively important events:

- `npm run build` / `npm test` / `npm run lint` → success or failure (with last
~8 lines of output on failure, so the error is preserved next session)
- `git commit` → SHA + message + diffstat

The `UserPromptSubmit` hook runs `.brain/scripts/log-compact.sh` on every user
prompt but only acts on `/compact` commands — everything else is ignored. When
detected, it writes a timestamp breadcrumb to `.brain/.compact-triggers`.

Everything else (file edits, reads, other shell commands, regular prompts) is
**not logged** — that would be noise. The Stop hook merges `_active.md` into
the final session log under `## Iterations`. This means: every build, every
test, every commit you make in a session is permanently in the brain —
searchable, visible to the next session, and impossible to lose to a `/clear`.

When `/compact` runs, the Stop hook extracts the full summary from the session
JSONL transcript and writes it to `.brain/sessions/compacts/<timestamp>-compact.md`.
The session file gets a `## Compactions` section with a pointer and a 200-char
excerpt — the full summary is never auto-inlined to keep `_CONTEXT.md` lean.

## During the session

When the work warrants it, write to:

- **`.brain/decisions/YYYY-MM-DD-<slug>.md`** — for any decision Eduardo
makes about Korvex Web (architecture, dependency, deploy, scope). Use the
CKIS decision-log format. See `.brain/decisions/README.md`.
- **`.brain/bugs/YYYY-MM-DD-<slug>.md`** — when a bug is found *and* fixed,
capture the lesson (root cause, why it happened, how to prevent it). The
patch lives in the commit; this file is for the *why*.

Important decisions also get a one-line cross-post to
`~/Documents/Second Brain/00-inbox/_MEMORY.md` Open Decisions.

## Before ending the session

The Stop hook fills in the objective metadata automatically:
- Iterations (every build/test/lint/commit, with timestamps)
- Commits made, files changed, duration, branch state

Your only job is the **narrative `## Summary`** — and only when it adds
value. If the session was a routine commit-and-iterate cycle, the iteration
log already tells the story. Fill in the Summary when:

- A non-obvious decision was made mid-session
- A bug had a *why* worth remembering (root cause, not patch)
- Something is unfinished and the next session needs to know

Format: 2–4 bullets max. What was done · What was decided · What's next.
Skip it if the iteration log + commits speak for themselves.

## CKIS bridge — when to escalate

| Situation | Goes to |
| --- | --- |
| Routine code change, bug fix, refactor | Just commit. No brain entry needed. |
| Decision about *this* project | `.brain/decisions/` |
| Bug worth a postmortem | `.brain/bugs/` |
| Strategic / cross-project / personal | CKIS `_MEMORY.md` + `02-projects/korvex/_overview.md` |
| Pattern reusable across projects | CKIS `03-knowledge/permanent-notes/` |

When in doubt: project decision → `.brain/`. Strategic → CKIS.

## Hard rules

- Never modify `.brain/_CONTEXT.md` by hand — it's regenerated each session.
- Never delete files in `.brain/decisions/` or `.brain/bugs/` — supersede instead.
- `.brain/sessions/` is gitignored (personal); `decisions/` and `bugs/` are committed.
- Graphify rebuilds `.brain/graph/` on every commit (post-commit hook). Don't edit it.
52 changes: 52 additions & 0 deletions .brain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
type: brain-readme
project: korvex-web
created: 2026-05-03
modified: 2026-05-03
tags: [brain, ckis-bridge]
---

# `.brain/` — Per-project second brain

Project-level memory layer for Claude Code sessions. Bridges this repo to the
global CKIS vault at `~/Documents/Second Brain/`.

## What lives here

| Path | Purpose | Committed? |
| ---------------- | ------------------------------------------------ | --------------- |
| `_CONTEXT.md` | Auto-assembled session start context | No (regenerable) |
| `decisions/` | Decision logs (CKIS format — see skill card) | **Yes** |
| `bugs/` | Bug → fix narratives | **Yes** |
| `sessions/` | Per-session summaries written by Stop hook | No (personal) |
| `graph/` | Graphify output (`graph.json`, `GRAPH_REPORT.md`, vault/) | No (regenerable) |
| `scripts/` | Hooks + assembler scripts | **Yes** |
| `config.sh` | Per-project config (CKIS paths, project slug) | **Yes** |

## How it works

1. **SessionStart hook** runs `scripts/assemble-context.sh`:
- Concatenates latest 3 session summaries + open decisions + active bugs
- Pulls god-nodes section from `graph/GRAPH_REPORT.md` if Graphify has run
- Adds pointers to CKIS `_MEMORY.md` and project `_overview.md`
- Writes the result to `_CONTEXT.md` and emits it as session context.

2. **Stop hook** runs `scripts/log-session.sh`:
- Records git diff, commits, branch, duration vs. session start.
- Creates `sessions/YYYY-MM-DD-HHMM-session.md` with a "Summary" section to fill in.

3. **Graphify** rebuilds `graph/` automatically on every git commit
(via `graphify hook install`) and is symlinked from the CKIS vault under
`02-projects/korvex/graph/` so the graph view shows up alongside the
curated overview.

## Bridge to CKIS

- Strategic / cross-project state → `~/Documents/Second Brain/00-inbox/_MEMORY.md`
- Project overview (curated) → `~/Documents/Second Brain/02-projects/korvex/_overview.md`
- Architecture spec → `~/Documents/Second Brain/03-knowledge/permanent-notes/per-project-second-brain.md`

## See also

- `00-system/ckis/06-decision-execution-and-review-protocol.md` — decision-log format
- `.claude/skills/ckis-decision-log/` — skill that writes here
30 changes: 30 additions & 0 deletions .brain/bugs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
type: index
created: 2026-05-03
tags: [bugs, brain]
---

# Bugs

Bug → fix narratives for `korvex-web`. Capture the *why*, not just the patch
(the patch is in the commit; this folder is for the lesson).

## File naming

`YYYY-MM-DD-<slug>.md`.

## Required frontmatter

```yaml
---
type: bug
project: korvex
status: open | fixed | wontfix
date: YYYY-MM-DD
severity: low | medium | high
related-commits: [<sha>, ...]
tags: [bug, korvex]
---
```

Bugs with `status: open` are surfaced in `_CONTEXT.md` at session start.
29 changes: 29 additions & 0 deletions .brain/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Per-project .brain/ configuration
# Sourced by every script in .brain/scripts/.

# Project identity
PROJECT_SLUG="streamnet-cli"
PROJECT_NAME="StreamNet CLI"

# CKIS vault paths (absolute — adjust per machine if vault relocates)
CKIS_VAULT="$HOME/Documents/Second Brain"
CKIS_MEMORY="$CKIS_VAULT/00-inbox/_MEMORY.md"
CKIS_PROJECT_OVERVIEW="$CKIS_VAULT/02-projects/$PROJECT_SLUG/_overview.md"
CKIS_ARCHITECTURE_NOTE="$CKIS_VAULT/03-knowledge/permanent-notes/per-project-second-brain.md"

# Brain paths (relative to repo root)
BRAIN_DIR=".brain"
SESSIONS_DIR="$BRAIN_DIR/sessions"
DECISIONS_DIR="$BRAIN_DIR/decisions"
BUGS_DIR="$BRAIN_DIR/bugs"
GRAPH_DIR="$BRAIN_DIR/graph"
CONTEXT_FILE="$BRAIN_DIR/_CONTEXT.md"
SESSION_STATE="$BRAIN_DIR/.session-state"

# How many recent session summaries to inline in _CONTEXT.md
RECENT_SESSIONS_LIMIT=3

# Dev Brain vault (Obsidian — code graph + wiki layer, separate from CKIS)
DEV_BRAIN_VAULT="$HOME/Documents/Dev Brain"
# Rebuild --obsidian vault every N commits (expensive: one .md per node)
OBSIDIAN_GRAPH_CADENCE=10
32 changes: 32 additions & 0 deletions .brain/decisions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
type: index
created: 2026-05-03
tags: [decisions, brain]
---

# Decisions

Decision logs for `korvex-web`. CKIS format — see
`~/Documents/Second Brain/00-system/ckis/06-decision-execution-and-review-protocol.md`.

## File naming

`YYYY-MM-DD-<slug>.md` — one decision per file.

## Required frontmatter

```yaml
---
type: decision
project: korvex
status: proposed | adopted | superseded
date: YYYY-MM-DD
reversal-cost: low | medium | high
review-by: YYYY-MM-DD or empty
tags: [decision, korvex]
---
```

Decisions with `status: proposed` are surfaced in `_CONTEXT.md` at session start
and in CKIS `_MEMORY.md` Open Decisions. Important decisions are cross-posted
to `_MEMORY.md` as one-line entries pointing back here.
Empty file added .brain/graph/.gitkeep
Empty file.
Loading
Loading