@@ -103,6 +103,99 @@ meta_is_unedited_template() {
103103 [[ " $file_content " == " $template_content " ]]
104104}
105105
106+ default_readme_template () {
107+ cat << 'README '
108+ # Repo-local personas (`.personas/`)
109+
110+ This repository is set up for repo-local agent personas via `agent-persona`.
111+
112+ ## Repo-wide instructions (meta)
113+
114+ - `.personas/.shared/meta.AGENTS.md` is merged into every persona launched in this repo.
115+ - The default template created by `agent-persona init` is ignored until you edit it.
116+ - Disable meta merge: `agent-persona ... --no-meta` or `AGENT_PERSONA_META=0`
117+ - Merge position: `--meta-position top|bottom` (default: top)
118+
119+ ## Shared blocks
120+
121+ - Reusable instruction blocks live under `.personas/.shared/`.
122+ - Include them from any AGENTS/CLAUDE/GEMINI file:
123+
124+ ```md
125+ <!-- include {"file":"communication-discipline.md"} -->
126+ ```
127+
128+ ## Template variables
129+
130+ - Use `{{persona}}` in shared blocks or meta files to reference the current persona name.
131+ - Example: `.persona/{{persona}}/PLAN.md` expands to `.persona/my-agent/PLAN.md`
132+
133+ ## Add a persona
134+
135+ Create a folder and an `AGENTS.md`:
136+
137+ ```bash
138+ mkdir -p .personas/my-persona
139+ $EDITOR .personas/my-persona/AGENTS.md
140+ ```
141+
142+ Optional `persona.json` (defaults + MCP):
143+
144+ ```json
145+ {
146+ "defaults": {
147+ "codex": ["--full-auto"],
148+ "claude": ["--permission-mode", "bypassPermissions"]
149+ },
150+ "mcpServers": {
151+ "myserver": {
152+ "command": "my-mcp-server",
153+ "args": ["--flag"],
154+ "env": { "MY_ENV": "value" }
155+ }
156+ }
157+ }
158+ ```
159+
160+ ## Launch
161+
162+ ```bash
163+ agent-persona codex my-persona
164+ agent-persona claude my-persona
165+ agent-persona gemini my-persona
166+ ```
167+
168+ ## Notes
169+
170+ - On Linux, `agent-persona` prefers a bind-mount overlay via `unshare` (no on-disk changes).
171+ - If `unshare` isn't available, it falls back to swap-and-restore. If you hard-kill the tool, run `agent-persona recover`.
172+ README
173+ }
174+
175+ # Ensure README.md exists in the repo's persona directory
176+ ensure_persona_dir_readme () {
177+ local persona_dir=" $1 "
178+ local parent_dir readme_path
179+ parent_dir=" $( dirname " $persona_dir " ) "
180+ local parent_name
181+ parent_name=" $( basename " $parent_dir " ) "
182+
183+ # Only inject README for repo .persona/.personas directories (not user/system)
184+ if [[ " $parent_name " == " .persona" || " $parent_name " == " .personas" ]]; then
185+ # Skip if this is under $HOME/.local, $HOME/.personas, or system paths
186+ case " $parent_dir " in
187+ " $HOME /.local" * |" $HOME /.personas" * |" /usr/local/share" * |" /usr/share" * )
188+ return 0
189+ ;;
190+ esac
191+ readme_path=" $parent_dir /README.md"
192+ if [[ ! -f " $readme_path " ]]; then
193+ default_readme_template > " $readme_path "
194+ log " created $readme_path "
195+ fi
196+ fi
197+ }
198+
106199# --- MCP temp config (Claude) ---
107200mcp_config_file=" "
108201cleanup_mcp () { [[ -n " ${mcp_config_file:- } " && -f " $mcp_config_file " ]] && rm -f " $mcp_config_file " 2> /dev/null || true ; }
@@ -1754,73 +1847,7 @@ cmd_init() {
17541847 fi
17551848
17561849 if [[ ! -f " $personas_dir /README.md" ]]; then
1757- cat > " $personas_dir /README.md" << 'README '
1758- # Repo-local personas (`.personas/`)
1759-
1760- This repository is set up for repo-local agent personas via `agent-persona`.
1761-
1762- ## Repo-wide instructions (meta)
1763-
1764- - `.personas/.shared/meta.AGENTS.md` is merged into every persona launched in this repo.
1765- - The default template created by `agent-persona init` is ignored until you edit it.
1766- - Disable meta merge: `agent-persona ... --no-meta` or `AGENT_PERSONA_META=0`
1767- - Merge position: `--meta-position top|bottom` (default: top)
1768-
1769- ## Shared blocks
1770-
1771- - Reusable instruction blocks live under `.personas/.shared/`.
1772- - Include them from any AGENTS/CLAUDE/GEMINI file:
1773-
1774- ```md
1775- <!-- include {"file":"communication-discipline.md"} -->
1776- ```
1777-
1778- - Example blocks created by `agent-persona init`:
1779- - `.personas/.shared/agent-contract-posture.md`
1780- - `.personas/.shared/communication-discipline.md`
1781- - `.personas/.shared/knowledge-dilligence.md`
1782- - `.personas/.shared/continuity.md`
1783-
1784- ## Add a persona
1785-
1786- Create a folder and an `AGENTS.md`:
1787-
1788- ```bash
1789- mkdir -p .personas/my-persona
1790- $EDITOR .personas/my-persona/AGENTS.md
1791- ```
1792-
1793- Optional `persona.json` (defaults + MCP):
1794-
1795- ```json
1796- {
1797- "defaults": {
1798- "codex": ["--full-auto"],
1799- "claude": ["--permission-mode", "bypassPermissions"]
1800- },
1801- "mcpServers": {
1802- "myserver": {
1803- "command": "my-mcp-server",
1804- "args": ["--flag"],
1805- "env": { "MY_ENV": "value" }
1806- }
1807- }
1808- }
1809- ```
1810-
1811- ## Launch
1812-
1813- ```bash
1814- agent-persona codex my-persona
1815- agent-persona claude my-persona
1816- agent-persona gemini my-persona
1817- ```
1818-
1819- ## Notes
1820-
1821- - On Linux, `agent-persona` prefers a bind-mount overlay via `unshare` (no on-disk changes).
1822- - If `unshare` isn’t available, it falls back to swap-and-restore. If you hard-kill the tool, run `agent-persona recover`.
1823- README
1850+ default_readme_template > " $personas_dir /README.md"
18241851 info " - README.md (how .personas/ works)"
18251852 else
18261853 info " - README.md already exists"
@@ -2328,6 +2355,9 @@ cmd_print_overlay() {
23282355
23292356 [[ -n " $persona_dir " ]] || die " persona '$persona ' not found"
23302357
2358+ # Ensure README.md exists in repo persona directory
2359+ ensure_persona_dir_readme " $persona_dir "
2360+
23312361 # Resolve instruction file (tool-specific or fallback to AGENTS.md)
23322362 local persona_src
23332363 persona_src=" $( resolve_instruction_file " $persona_dir " " $overlay_name " ) "
@@ -2727,6 +2757,9 @@ log "persona source: $persona_src"
27272757# --- Normalize persona directory (handles file-vs-dir profiles) ---
27282758persona_dir=" $( get_persona_dir " $persona_src " " $profile_type " ) "
27292759
2760+ # --- Ensure README.md exists in repo persona directory ---
2761+ ensure_persona_dir_readme " $persona_dir "
2762+
27302763# --- Determine overlay filename (moved earlier for per-tool instruction support) ---
27312764overlay_name=" AGENTS.md"
27322765case " $tool " in
0 commit comments