File size: 3,383 Bytes
a02272f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""Brain Instance scaffolding β€” directory structure + template files."""

from pathlib import Path

# ── Directory structure ────────────────────────────────────

BRAIN_DIRS = [
    "user",
    "projects",
    "agent-configs",
    "agents/claude",
    "agents/cursor",
    "agents/codex",
    "skills",
    "raw",
    "versions",
]

# ── Template content ──────────────────────────────────────

TEMPLATES: dict[str, str] = {
    "user/personality.md": """\
# Personality

<!-- Describe your communication style, tone preferences, and how you like AI agents to interact with you. -->
""",
    "user/preferences.md": """\
# Preferences

## Coding
<!-- Languages, frameworks, patterns you prefer. -->

## Architecture
<!-- Monolith vs microservices, state management, etc. -->

## Communication
<!-- Verbose vs concise, explanation depth, etc. -->
""",
    "user/workflows.md": """\
# Workflows

<!-- Describe your typical development workflows, review processes, deployment habits. -->
""",
    "skills/coding-style.md": """\
# Coding Style

<!-- Conventions, naming patterns, formatting rules you follow. -->
""",
    "skills/debugging.md": """\
# Debugging Workflow

<!-- Your typical debugging approach, tools, and patterns. -->
""",
    "agent-configs/.cursorrules": """\
# Cursor Agent Configuration

Look for the `.brain/` directory in this workspace.
If found, read `.brain/AGENT.md` for full protocol instructions.
Follow the Brain continuity protocol for all operations.
""",
    "agent-configs/CLAUDE.md": """\
# Claude Agent Configuration

Look for the `.brain/` directory in this workspace.
If found, read `.brain/AGENT.md` for full protocol instructions.
Follow the Brain continuity protocol for all operations.
""",
    "AGENT.md": """\
# Brain Protocol

This is a Brain Instance β€” a persistent cognition environment for AI-assisted development.

## For AI Agents

You are operating inside a Brain-managed environment.
Your responsibilities:

1. Read context from `user/` to understand preferences.
2. Read and update project memory in `projects/<project>/`.
3. Write your session logs to `agents/<your-name>/`.
4. Follow the continuity protocol: read handoff -> work -> update handoff.
5. Record architecture decisions in the project's `decisions.md`.
6. Update `tasks.md` as work progresses.

## Structure

- `user/` β€” persistent user identity and preferences
- `projects/` β€” per-project memory (context, architecture, tasks, handoffs)
- `agent-configs/` β€” agent discovery and protocol configuration
- `agents/` β€” per-agent operational logs and session history
- `skills/` β€” reusable workflow conventions
- `raw/` β€” imported unstructured context
- `versions/` β€” historical snapshots created by `brain sync`
""",
}


def scaffold_brain_instance(brain_path: Path) -> None:
    """Create a full Brain Instance directory structure with template files."""
    # Create directories
    for d in BRAIN_DIRS:
        (brain_path / d).mkdir(parents=True, exist_ok=True)

    # Write template files
    for rel_path, content in TEMPLATES.items():
        file_path = brain_path / rel_path
        file_path.parent.mkdir(parents=True, exist_ok=True)
        file_path.write_text(content, encoding="utf-8")