Skip to content
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Your coding agents already learn things every session, then forget them by the n

## Demo

![brainstack recall surfacing a past lesson inside a session](demo/demo.gif)
![brainstack: a prompt is auto-enriched with a past lesson, the lesson is traced to its source, and an agent's durable write is refused](demo/demo.gif)

The walkthrough above is generated from [`demo/demo.tape`](demo/demo.tape) against a fully synthetic brain built by [`demo/make_demo_brain.py`](demo/make_demo_brain.py) (placeholder names only, safe to publish). Regenerate it with `make demo` (requires [vhs](https://github.com/charmbracelet/vhs)).
Four beats: the per-prompt hook injects a past lesson before you ask; `recall trace` walks that lesson back to its provenance and originating session; a piped (non-human) `recall remember --reviewed` is refused while the default write lands staged for your review; `recall stats` shows the week's auto-recall ROI. Generated from [`demo/demo.tape`](demo/demo.tape) against a fully synthetic brain built by [`demo/make_demo_brain.py`](demo/make_demo_brain.py) (placeholder names only, safe to publish). Regenerate with `make demo` (requires [vhs](https://github.com/charmbracelet/vhs)).

## Why you can trust it

Expand Down
Binary file modified demo/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 54 additions & 25 deletions demo/demo.tape
Original file line number Diff line number Diff line change
@@ -1,43 +1,62 @@
# demo.tape - VHS recording script for the brainstack recall demo.
# demo.tape - VHS recording script for the brainstack demo.
#
# Regenerate with: make demo (requires vhs: brew install vhs)
#
# Four beats, one arc, against the README's own claims:
# 1. Proactive injection: the UserPromptSubmit hook enriches a prompt
# with a past lesson, before you ask ("it already knew").
# 2. Audit: `recall trace` walks that same lesson back to its provenance
# and originating session digest (the headline: memory you can audit).
# 3. Trust gate: a piped (non-TTY) `recall remember --reviewed` is
# REFUSED; the default write lands staged for human review.
# 4. ROI: `recall stats` over the synthetic week of telemetry.
#
# Everything shown comes from the fully synthetic brain built by
# demo/make_demo_brain.py (placeholders only: Acme, Alice). The hidden
# setup block isolates XDG config/cache and the runtime telemetry log so
# a recording NEVER reads or shows the recording machine's real brain,
# real config, or real usage stats.
#
# Beat 3 is `recall stats --since 7d` instead of a raw UserPromptSubmit
# hook render: the hook needs a RECALL_RUNTIME_CONFIG with auto-recall
# enabled plus a warm retriever inside a 3s timeout, which is too fragile
# to re-record deterministically. `--no-tools` keeps the stats beat from
# scanning the recording machine's real ~/.claude/projects transcripts.
# Beat 1 invokes the hook exactly the way Claude Code does (hooks.py with
# the event name + JSON on stdin). The demo runtime.toml raises
# auto_recall_timeout_ms to 20s because a fresh hook process loads the
# dense model from disk; the production default stays 3000ms. Recorded
# via the repo venv python so runtime deps (qdrant) resolve.
#
# Beat 3's refusal works inside a pty recording because the pipe (`echo |`)
# makes the hook-relevant fd, stdin, a non-TTY for that command, which is
# exactly how an agent or injected prompt would drive it.

Output demo/demo.gif

Set Shell bash
Set Width 1200
Set Height 640
Set Height 700
Set FontSize 18
Set TypingSpeed 60ms
Set TypingSpeed 55ms
Set Padding 16
Set Theme "Catppuccin Mocha"

# --- hidden setup: build the synthetic brain, isolate env, warm the index ---
# The brain lives under /tmp/brainstack-demo (not $PWD) so the doc paths
# recall prints on camera never contain the recording user's home directory.
# recall prints on camera never contain the recording user's real home
# directory. The rm makes re-recording idempotent: beat 3 writes a staged
# lesson, which would otherwise collide ("lesson already exists") on the
# next take.
Hide
Type `rm -rf /tmp/brainstack-demo`
Enter
Type `python3 demo/make_demo_brain.py /tmp/brainstack-demo/brain`
Enter
Sleep 3s
Type `export BRAIN_ROOT="/tmp/brainstack-demo/brain" XDG_CONFIG_HOME="/tmp/brainstack-demo/.config" XDG_CACHE_HOME="/tmp/brainstack-demo/.cache"`
Enter
Type `export RECALL_RUNTIME_CONFIG="$BRAIN_ROOT/runtime.toml" FASTEMBED_CACHE_PATH="${FASTEMBED_CACHE_PATH:-$HOME/.cache/fastembed}"`
Type `export RECALL_RUNTIME_CONFIG="$BRAIN_ROOT/runtime.toml" FASTEMBED_CACHE_PATH="${FASTEMBED_CACHE_PATH:-$HOME/.cache/fastembed}" PYTHONPATH="$PWD"`
Enter
Sleep 1s
# Warm the index so the first on-camera query is fast. First-ever run may
# also download embedding models into FASTEMBED_CACHE_PATH (one time).
# Warm the index so the on-camera hook call spends its budget on model
# load, not index build. First-ever run may also download embedding
# models into FASTEMBED_CACHE_PATH (one time).
Type `recall reindex`
Enter
Sleep 45s
Expand All @@ -46,26 +65,36 @@ Enter
Sleep 1s
Show

# --- beat 0: point recall at the demo brain ---
Type `export BRAIN_ROOT=/tmp/brainstack-demo/brain`
# --- beat 1: proactive injection (the hook fires before you ask) ---
Type `# every prompt you type runs brainstack's hook. watch it inject a past lesson:`
Enter
Sleep 1.5s
Type `echo '{"prompt": "my queue workers keep claiming the same job twice"}' | .venv/bin/python3 runtime/adapters/claude_code/hooks.py UserPromptSubmit`
Enter
Sleep 9s

# --- beat 1: semantic retrieval over the synthetic lessons ---
# --no-expand: LLM query expansion is fail-open and machine-dependent
# (up to a 20s provider timeout), which is dead air in a recording.
Type `recall query --no-expand "what did I learn about flaky integration tests"`
# --- beat 2: audit the memory it just injected ---
Type `# where did that lesson come from? trace it back to its source:`
Enter
Sleep 4s
Sleep 1.5s
Type `recall trace skip-locked`
Enter
Sleep 5s

# --- beat 2: staged dream candidates awaiting human triage ---
Type `recall pending`
# --- beat 3: durable memory is human-gated ---
Type `# agents cannot silently write durable memory. piped = not a human:`
Enter
Sleep 3s
Sleep 1.5s
Type `echo | recall remember "Acme analytics must use the read replica" --reviewed`
Enter
Sleep 4s
Type `recall remember "Acme analytics must use the read replica"`
Enter
Sleep 4s

# --- beat 3: auto-recall ROI over the last week ---
# --- beat 4: auto-recall ROI over the last week ---
Type `recall stats --since 7d --no-tools`
Enter
Sleep 3s
Sleep 4s

Sleep 2s
Sleep 2.5s
115 changes: 102 additions & 13 deletions demo/make_demo_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@

Creates:
TARGET_DIR/
memory/semantic/lessons/*.md 5 synthetic lessons (real frontmatter shape)
memory/semantic/lessons/*.md 6 synthetic lessons (real frontmatter shape;
the hero lesson carries full remember-style
provenance so `recall trace` shows a chain)
memory/semantic/digests/*.md 1 synthetic session digest the hero lesson's
session_id resolves to in `recall trace`
memory/candidates/*.json 2 staged dream candidates (real triage schema)
imports/*.md 1 synthetic imported note (the default config
indexes an imports tier; an empty collection
crashes embedded-qdrant hybrid queries)
PENDING_REVIEW.md summary consumed by `recall pending`
runtime.toml runtime config pointing stats at the demo log
runtime.toml runtime config: auto-recall enabled (for the
hook beat) + stats pointed at the demo log
runtime/logs/events.log.jsonl synthetic AutoRecall telemetry for `recall stats`

Every byte of content is synthetic. Placeholder org/person names only
Expand Down Expand Up @@ -43,10 +48,19 @@
pass


# The synthetic session the hero lesson traces back to. Appears in the
# lesson's frontmatter (session_id) and in the digest below, so
# `recall trace postgres-skip-locked-queue-claims` resolves the full chain:
# lesson -> provenance -> originating digest.
DEMO_SESSION_ID = "demo-2026-06-04-queue-double-claim"


# ---------------------------------------------------------------------------
# Synthetic lessons - frontmatter shape matches the auto-memory convention
# used by recall indexing and recall/remember.py (name / description / type /
# created + a short body with Why and How to apply).
# created + a short body with Why and How to apply). A lesson may carry
# `extra_fm` for provenance fields (the hero lesson uses the exact shape
# `recall remember --reviewed` writes).
# ---------------------------------------------------------------------------

LESSONS = [
Expand Down Expand Up @@ -167,6 +181,42 @@
"- Re-read all user-facing strings out loud; wrong copy is a bug too.\n"
),
},
{
# The demo's hero lesson: beat 1 auto-injects it, beat 2 traces it.
# Its frontmatter is exactly what `recall remember --reviewed` writes
# (source/created_by/provenance/reviewed_by) plus the session id, so
# `recall trace` can walk it back to the digest below.
"file": "postgres-skip-locked-queue-claims.md",
"name": "postgres-skip-locked-queue-claims",
"description": (
"Claim queue jobs with SELECT FOR UPDATE SKIP LOCKED; plain row "
"locks make workers double-claim or convoy behind each other"
),
"type": "feedback",
"created": "2026-06-04T15:12:00+00:00",
"extra_fm": {
"source": "recall-remember",
"created_by": "recall-remember",
"provenance": "human-cli",
"session_id": DEMO_SESSION_ID,
"reviewed_by": "human-cli",
},
"body": (
"Workers claiming jobs from a Postgres-backed queue must select with\n"
"`FOR UPDATE SKIP LOCKED`, not a bare `FOR UPDATE`.\n"
"\n"
"Why: with plain row locks, every idle worker queues behind the same hot row,\n"
"and a retried transaction can hand the same job to two workers. Alice spent a\n"
"day at Acme on 'duplicate welcome emails' that was exactly this.\n"
"\n"
"How to apply:\n"
"- `SELECT ... FROM jobs WHERE status = 'ready' ORDER BY id\n"
" FOR UPDATE SKIP LOCKED LIMIT 1` inside the claiming transaction.\n"
"- Mark the row taken in the same transaction; commit before starting the work.\n"
"- A worker that dies mid-job releases the lock on rollback, so the job is\n"
" re-claimable with no janitor process.\n"
),
},
]


Expand Down Expand Up @@ -300,18 +350,50 @@ def main() -> int:
d.mkdir(parents=True, exist_ok=True)

for lesson in LESSONS:
frontmatter = (
"---\n"
f"name: {lesson['name']}\n"
f"description: {lesson['description']}\n"
f"type: {lesson['type']}\n"
f"created: {lesson['created']}\n"
"---\n\n"
)
fm_lines = [
f"name: {lesson['name']}",
f"description: {lesson['description']}",
f"type: {lesson['type']}",
f"created: {lesson['created']}",
]
for key, value in lesson.get("extra_fm", {}).items():
fm_lines.append(f"{key}: {value}")
frontmatter = "---\n" + "\n".join(fm_lines) + "\n---\n\n"
(lessons_dir / lesson["file"]).write_text(
frontmatter + lesson["body"], encoding="utf-8"
)

# The digest the hero lesson's session_id resolves to. `recall trace`
# scans memory/semantic/digests/ for the session id (filename or head)
# and prints the match as "originating digest".
digests_dir = target / "memory" / "semantic" / "digests"
digests_dir.mkdir(parents=True, exist_ok=True)
(digests_dir / f"2026-06-04__queue-double-claim-hunt__{DEMO_SESSION_ID}.md").write_text(
"---\n"
f'session_id: "{DEMO_SESSION_ID}"\n'
"source: claude\n"
"started_at: 2026-06-04T13:05:00+00:00\n"
"ended_at: 2026-06-04T15:20:00+00:00\n"
"domain_tags: [postgres, queues, debugging]\n"
"outcome: completed\n"
"---\n"
"\n"
"# Queue double-claim hunt\n"
"\n"
"## What you did\n"
"\n"
"Alice traced duplicate welcome emails at Acme to two workers claiming the\n"
"same queue row. Reproduced with two psql sessions, fixed the claiming query\n"
"with FOR UPDATE SKIP LOCKED, and remembered the lesson at the CLI.\n"
"\n"
"## What was learned\n"
"\n"
"Bare FOR UPDATE makes idle workers convoy behind the same hot row, and a\n"
"retried transaction can hand one job to two workers. SKIP LOCKED gives each\n"
"worker its own row and dead workers release claims on rollback.\n",
encoding="utf-8",
)

cands = _candidates(now)
for c in cands:
(candidates_dir / f"{c['id']}.json").write_text(
Expand Down Expand Up @@ -340,14 +422,20 @@ def main() -> int:
_pending_review_md(now, cands), encoding="utf-8"
)

# Runtime config for `recall stats`: point the events log inside the
# Runtime config for the hook beat and `recall stats`: auto-recall is
# enabled with a generous timeout (the recording invokes the hook in a
# fresh process, so the dense model loads from disk inside the budget;
# the production default stays 3000ms). The events log lives inside the
# demo brain so a recording never reads the recording machine's real
# telemetry. Absolute path because RuntimeConfig only expanduser()s.
(target / "runtime.toml").write_text(
"# Synthetic runtime config for the demo. Use via:\n"
'# export RECALL_RUNTIME_CONFIG="$PWD/demo/brain/runtime.toml"\n'
"[tool.recall.runtime]\n"
f'log_dir = "{logs_dir}"\n',
f'log_dir = "{logs_dir}"\n'
"enable_auto_recall = true\n"
"auto_recall_timeout_ms = 20000\n"
"auto_recall_k = 3\n",
encoding="utf-8",
)

Expand All @@ -357,6 +445,7 @@ def main() -> int:

print(f"demo brain written to {target}")
print(f" lessons: {len(LESSONS)} in {lessons_dir}")
print(f" digests: 1 in {digests_dir}")
print(f" candidates: {len(cands)} staged in {candidates_dir}")
print(f" telemetry: {logs_dir / 'events.log.jsonl'}")
print('next: export BRAIN_ROOT="' + str(target) + '"')
Expand Down
Loading