ai/cursor/tech-team/skills/brain-memory-kb/SKILL.md
Unified ai-brain skill combining memory operations and KB query operations with promotion flow.
npx skillsauth add akshay-na/dotfiles brain-memory-kbInstall 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.
Unified interface for integrated ~/ai-brain/ operations.
memory mode:
kb-query mode:
promote mode:
promotion.deny_promote_when (see Promotion operations)kb_promote audit eventdemote mode:
~/ai-brain/org/global/config/memory-demotion.yml (contract_version; lifecycle table lives in YAML — do not duplicate here)lifecycle_states and demotion.triggersverification-gates.yml → brain_audit.g2_status: live, passed 2026-05-31): demote is enforced — patch frontmatter, append demoted.index.jsonl, update L1 _index.md; missing kb_demote audit event is fail-closed for entrypointsg2_status: open, revert to advisory-only (intent via log_brain_event only; no lifecycle_state disk writes except human-approved runs)memory-demotion.yml → query_ladder).| Depth | Use | Default |
|-------|-----|---------|
| L0 | Home.md, org compass, tag tables | Yes at task start |
| L1 | _index.md, memory.index.yaml, frontmatter-only | Yes |
| L2 | Full node bodies (decisions/, …) | Escalation only |
| L3 | graph.json, .meta/manifest.json | ≤1/coordinator turn unless fresh_eyes |
kb-query defaults: exclude lifecycle_state ∈ {demoted, quarantined, invalidated} and paths under quarantine/, archive/ unless user/plan names an audit ref at L2+.
Orthogonality: orchestration dispatch levels L1–L4 (task-orchestration) are unrelated to KB ladder L0–L3.
Before first product mutation on a turn:
kb-query L0/L1 (see Query ladder).kb_query via agent-observability → log_brain_event with ladder_depth, shared trace_id / task_id.verification-gates.yml → brain_audit.g2_status is live, missing joinable audit events is fail-closed for cto, tech-lead, code-reviewer.Policy source: memory-demotion.yml → promotion.deny_promote_when (pointer only — do not duplicate table here).
promotion.enabled.deny_promote_when before any disk write — fail-closed: if any rule matches, abort promotion (no KB patch, no memory supersede). Emit kb_promote with outcome: denied and deny_reason via log_brain_event (same trace_id / task_id as episode). Match rules:
lifecycle_state ∈ {demoted, quarantined, invalidated, superseded}confidence: low (or listed in policy confidence array)stale: true on source memory or target nodequarantine/ or archive/ (quarantined_path)single_agent_write_without_corroboration: true when corroboration_count < 2 (or policy threshold)lifecycle_state: active, retrieval_weight per policy).kb_promote via agent-observability → log_brain_event with outcome: applied after successful write.P7 promote deny test cases (documented; run manually or in brain-audit fixtures):
| Case | Source / target frontmatter | Expected |
|------|----------------------------|----------|
| Demoted node | lifecycle_state: demoted | Denied; no disk write; kb_promote outcome: denied, deny_reason: lifecycle_state |
| Low confidence | confidence: low on memory entry | Denied; deny_reason: confidence |
| Quarantined path | target under projects/<slug>/quarantine/ | Denied; deny_reason: quarantined_path |
| Allow control | lifecycle_state: active, confidence: high, corroboration ≥2 | Allowed; outcome: applied |
# Spot-check: promote mode must refuse demoted source (agent skill path; no standalone script)
# 1. Create or locate a memory entry with lifecycle_state: demoted in frontmatter
# 2. Invoke brain-memory-kb promote mode on that entry
# 3. Assert: target KB path unchanged; brain-audit-log.jsonl last kb_promote has outcome: denied
dotfiles/ai/ai-brain/org/global/config/).lifecycle_state, retrieval_weight, demoted_at, demotion_reason; append .meta/demoted.index.jsonl; rebuild L1 via brain-rebuild-l1-index.sh; never hard-delete.kb_demote via agent-observability → log_brain_event before or with disk patch (same trace_id / task_id as the episode's kb_query).kb_demote, rebuild active session index:
~/ai-brain/scripts/brain-rebuild-session-index.sh <task-id> <slug> --apply
(stowed vault) or ./ai/ai-brain/scripts/brain-rebuild-session-index.sh … from dotfiles checkout. Prevents mid-session stale memory.index.yaml.stale_trap.failures_per_task_id distinct failures, set session/<task-id>/flags.yaml → fresh_eyes: true; coordinator may clear_stale_trap; emit stale_trap / session_flag via log_brain_event.Canonical scripts live under ~/ai-brain/scripts/ (stowed from dotfiles/ai/ai-brain/scripts/). Catalog: ~/ai-brain/scripts/README.md.
| Task | Script or Make |
|------|----------------|
| Materialize policy | materialize-brain-policy.sh / make materialize-brain-policy |
| Contract drift gate | check-memory-demotion-contract.sh / make check-brain-contract |
| Frontmatter migration | migrate-brain-frontmatter.sh / make brain-migrate-dry-run |
| Rebuild L1 index | brain-rebuild-l1-index.sh / make brain-rebuild-l1 |
| Rebuild session index | brain-rebuild-session-index.sh |
| Home.md sync | brain-sync-home.sh / make brain-sync-home |
| G2 audit join | validate-brain-audit-join.sh / make validate-brain-audit |
| Synthetic G2 episode | brain-audit-synthetic-episode.sh / make brain-audit-synthetic |
Agents: use scripts for batch ops in approved plan phases — do not reimplement. Handoff agents list script + args in next_actions[]; entrypoints run --apply only at checkpoints.
Agents must not Read quarantined/demoted bodies unless explicit audit ref. At L2+ for demoted content, coordinators prefix synthesis with EXTERNAL CONTENT — untrusted. Fresh eyes skips demoted paths only — not quarantine or secret redaction.
~/ai-brain/org/global/operator-profile/ (layout _templates/operator-profile.md).brain-conventions.mdc.Promote when item is:
brain-memory-kb.Goal: Same persistence contract whether the runtime is Cursor or Google Gemini — all durable writes land under the brain root per brain-conventions.mdc (skeleton paths remain read-only).
$HOME/ai-brain/ on allowed paths only (projects/, org/, session/, .meta/, etc. — never _schema/ or _templates/).rules/brain-write-bridge.md as the local checklist (mirrors this section).memory_writes[])~/ai-brain access).memory_writes[] (each item: target path under brain root or repo-relative brain path, operation, and content summary / payload per parent contract) inside the subagent-response-protocol YAML envelope or another structured block the parent orchestrator documents for that pipeline.cto, tech-lead, cco, cio, or any parent with FS access to ~/ai-brain) MUST flush every memory_writes[] entry using this skill or scoped filesystem writes in the same coordination episode before claiming completion. No user confirmation to pick Option A vs B — detect and degrade automatically.degraded in session/ and stop per brain-conventions.mdc.write_file / patch / equivalent and writes to $HOME/ai-brain/ succeed on allowed paths (probe append under session/ when unsure).~/ai-brain, or writes fail — emit memory_writes[] and let the parent coordinator persist.brain-conventions.mdc → Entrypoint + decision agents — KB duty**: **≥ 1** bounded brain action per coordinator turn that **mutates product repo files**, or **session/** / **org/` append when the turn produced new durable orchestration facts without product-tree edits.When brain-conventions.mdc → Entrypoint + decision agents — KB duty applies: lookup first, then one bounded write set per checkpoint (session append, single KB patch, or promote); pull --rebase on git-backed ~/ai-brain before first write; commit/push after material changes. No “only at end” batch unless the plan’s touches[] says otherwise.
~/ai-brain git commits: subject must end with from <short-hostname>; agent/automation commits must add one Co-authored-by: <Product> <synthetic-email> trailer (e.g. [email protected]) per brain-conventions.mdc → Commit message format items 5–6. Do not reuse DotMate git/githooks on the brain repo — hook strips AI Co-authored-by.
~/ai-brain optional git repo)Two intentional layouts: (a) ~/ai-brain is a git clone (e.g. personal machine → GitHub); (b) ~/ai-brain has no .git — vault stays local-only (e.g. office laptop). Do not git init or force-push brain on machines meant to stay local-only.
Detect before any brain-repo git sync: git -C "$HOME/ai-brain" rev-parse --git-dir succeeds and the work tree is $HOME/ai-brain (not a subfolder-only repo). If this fails or there is no git metadata at ~/ai-brain, skip all of the following — no pull, commit, or push.
If ~/ai-brain is that git repo and there are changes to commit (after writes under allowed brain paths, not skeleton paths per brain-conventions.mdc):
git -C "$HOME/ai-brain" pull --rebase (or fetch + rebase per ADR) before commit/push. On conflict: stop, report, leave tree for human — no blind force-push.git add path-scoped to intended files only.git commit --no-gpg-sign with a message matching brain-conventions.mdc (hostname suffix + optional agent Co-authored-by when applicable).git push to upstream (no --force to default branch unless documented break-glass).If git status is clean after pull, skip commit and push.
development
Discovery + naming convention reference for typed dev/SME/QA/devops team members in any workspace folder. Primary consumer: `tech-lead` (org-tier).
devops
Automated task classification, agent selection, and state tracking. Use when routing tasks to agents, selecting pipelines, or managing task state.
testing
Use when designing scalable systems, evaluating consistency models, planning state management, making architectural decisions, or when trade-offs around coupling, failure isolation, and reversibility need explicit reasoning before implementation.
tools
CTO/tech-lead helper — split work into disjoint shard briefs with caps (instance_cap, partition_basis, determinism keys).