Add custom agent system with orchestration, templates, and broadened legal coverage (#21)

* Add standardized template for custom agent creation

New file: references/agent-template.md

This is a reference document that the Architect reads when generating
custom agents. It defines the exact structure every agent must follow:
YAML frontmatter format, required sections (Language, User Profile,
Inter-Agent Coordination, Core Responsibilities, Operational Rules),
placeholder tokens, and inline conventions (naming rules, tool
permissions, multilingual triggers).

The template is not an agent itself. It is a structural guide that
ensures custom agents are generated with the same quality and
consistency as the core 8.

* Add custom agent support to orchestration references

agents-registry.md:
- Added "Custom Agents" section with rules for how custom agents
  are added to the registry (naming, priority, creation flow)
- Custom agents always have lower priority than core 8
- Names must be lowercase with hyphens, no conflicts with core names

agents.md:
- Added "Custom Agents" section explaining what they are, how they
  coordinate with core agents, and how to create/edit/remove them

agent-orchestration.md:
- Added "Suggested new agent" signal format so agents can flag when
  the user needs functionality that no existing agent provides
- Added step in Dispatcher Decision Logic to check for this signal
- Added "Custom Agent Lifecycle" section covering creation, discovery,
  routing, chaining, maintenance, and deletion

* Add "Suggested new agent" capability to all 7 non-architect agents

Each agent now has a "When to suggest a new agent" subsection inside
its Inter-Agent Coordination block. When an agent detects that the
user needs functionality that no existing agent can handle, it
outputs a "Suggested new agent" section with:
- Need: what capability is missing
- Reason: why no existing agent covers it
- Suggested role: what the new agent would do

The dispatcher reads this and asks the user if they want the
Architect to create a custom agent for the detected need.

Agents are also told when NOT to suggest a new agent (existing
agent can handle it, one-off task, outside vault scope).

* Add full custom agent creation flow to the Architect

The Architect can now create, edit, and remove custom agents through
an extended conversational flow with the user.

Changes to the frontmatter:
- Added trigger phrases for custom agent creation in 6 languages
  ("create a new agent", "custom agent", "crea un nuovo agente", etc.)

New section "Custom Agent Creation" with:
- 5-phase conversation flow (Understanding, Capabilities, Output,
  Advanced, Confirmation) where the Architect asks one question at
  a time and adapts follow-ups based on user answers
- Agent file generation following references/agent-template.md
- Automatic updates to agents-registry.md and agents.md
- Management commands: edit, remove, list custom agents
- Validation rules: no name conflicts with core 8, minimal tool
  permissions by default, mandatory coordination sections
- Quality standards: Core Responsibilities must be detailed enough
  to produce a production-quality agent

Also added the "Suggested new agent" subsection (same as other agents).

* Update dispatcher routing to support custom agents

- Changed "The ONLY agents you may use are these 8" to acknowledge
  that custom agents created by the Architect are also valid
- Added row 9+ to the routing priority table for custom agents
  (always lower priority than core 8)
- Added section 9 "CUSTOM AGENTS" with routing logic: when no core
  agent matches, check agents-registry.md for custom agents
- Added check for "Suggested new agent" signals in the multi-agent
  routing decision flow (step 6)

* Add custom agents to README, CONTRIBUTING, and TERMS_OF_USE

README.md:
- Badge changed from "8 Agents" to "8+ Agents"
- Added custom agents as point 4 of "What makes this different",
  positioned right after the main pitch for maximum visibility
- Includes a table of real-life scenarios (budget tracking, journaling,
  paper reading, project monitoring, client deadline management)
- Links to Terms of Use for the responsibility disclaimer

CONTRIBUTING.md:
- Renamed "Propose a new crew member" to "Propose a new core crew
  member" with a note that users can create custom agents via Architect
- Added "Custom agents vs. core agents" section explaining the
  distinction between personal custom agents and project-shipped
  core agents

TERMS_OF_USE.md:
- Added new Section 9 "Custom Agents" with full disclaimer: custom
  agents are entirely the user's creation and responsibility, no
  warranty on their behavior, author accepts no liability
- Updated Section 7 (Limitation of Liability) to reference custom
  agents explicitly
- Renumbered sections 9-11 to 10-12

* Force the Architect to always run the full conversation before creating a custom agent

The Architect was generating custom agents immediately from a single
user message instead of going through the 5-phase conversation flow.

Added explicit blocking instructions at three points:
- Section intro: "NEVER create an agent in one shot"
- Before the conversation phases: "Do NOT generate the agent
  immediately, even if the request seems clear"
- Explicit rule: "You are NOT allowed to create the agent file
  until Phase 5"
- Reinforced one-question-per-message rule

* Force custom agent descriptions to use only the user's language

The Architect was copying the multilingual pattern from core agents
and adding translations in 6+ languages to custom agent descriptions.

Custom agents should have their description and trigger phrases
written exclusively in the language the user speaks. Reinforced
this rule in both the generation instructions and the validation
rules section.

* Force custom agent body to always be written in English

The frontmatter description uses the user's language (for trigger
matching), but the agent body (system prompt) must always be in
English for better LLM instruction-following performance. The agent
still responds in the user's language at runtime thanks to the
language matching rule.

* Add confirmation prompt before overwriting existing installation

launchme.sh:
- Detects if .claude/ or CLAUDE.md already exist in the vault
- Shows the user what will be overwritten
- Asks for explicit confirmation before proceeding
- Clarifies that custom agents and vault notes are never touched

updateme.sh:
- Asks for confirmation before overwriting core files
- Same clarification about custom agents being preserved

* Deprecate removed files instead of leaving orphans in the vault

When a file is removed from the repo (agents, references, or skills),
the updater now renames it with a "-DEPRECATED" suffix and prepends
a "DEPRECATED DO NOT USE" header instead of silently leaving it.

updateme.sh:
- Core agents in .claude/agents/ that no longer exist in the repo
  get renamed to {name}-DEPRECATED.md with deprecation header
  (custom agents are never touched)
- References in .claude/references/ that no longer exist in the repo
  get the same treatment
- The entire .claude/skills/ directory (removed from the project)
  gets renamed to .claude/skills-DEPRECATED/ with deprecation headers
  on each SKILL.md
- Summary now reports deprecated file count

launchme.sh:
- Added confirmation prompt before overwriting existing installation
- Skills generation and copying kept intact (generate-skills.py runs
  first, then copies to .claude/skills/)

* Add first-run setup section to custom agent template and creation flow

Custom agents now have a "First Run Setup" section that defines what
the agent must do the very first time it is invoked: what questions
to ask the user, what config files or folders to create, and how to
detect that it has already been set up.

agent-template.md:
- New "First Run Setup" section between Core Responsibilities and
  Operational Rules, with subsections for detection, questions to
  ask, what to create, and post-setup behavior

architect.md:
- New Phase 4 "First Run Setup" in the conversational flow where
  the Architect asks the user what the agent should do on first run
- Previous Phase 4 (Advanced) becomes Phase 5
- Previous Phase 5 (Confirmation) becomes Phase 6
- Updated blocking rules to reference Phase 6

* Redesign README header and broaden legal disclaimers for custom agents

Improve README header visual hierarchy: centered title, prominent Discord
CTA, metadata badges moved to secondary row. Replace two custom agent
examples with funnier, gender-neutral ones. Rewrite TERMS_OF_USE Section 3
from "Health and Wellness Agents" to "Custom Agents and Advice-Generating
Output" covering health, legal, financial, and all regulated domains.

* Fix reference paths in architect to use .claude/references/ prefix

The agent runs inside the vault where references live under
.claude/references/, not under references/ (which is the repo layout).

* Fix reference paths in agent-template to use .claude/references/ prefix

* Add core-manifest to protect custom agents from deprecation

launchme.sh and updateme.sh now write .core-manifest listing which agent
files were installed as core. The deprecation loop checks this manifest
before touching any file, so custom agents are never deprecated.

* Skip agent deprecation if target DEPRECATED file already exists

* Include skill count in updateme.sh summary condition and message

* Fix agents-registry.md paths in CLAUDE.md to use .claude/references/ prefix

* Add edit/remove/list trigger phrases to custom agent routing

* Deprecate stale core agents on reinstall before copying new ones

On reinstall (EXISTING=1), read the old .core-manifest and deprecate
any agent that is no longer shipped in the repo, before writing the
new manifest. Prevents stale core agents from lingering in the vault.

* Fix custom agent description: triggers are in user's language, not multilingual

* Fix updateme.sh: deprecate stale agents before rewriting manifest

The manifest was being truncated and rewritten before the deprecation
loop ran, so removed core agents were no longer in the manifest and
got skipped as "custom". Now: read old manifest -> deprecate -> copy
new agents -> rewrite manifest.

* Fix grep exit code handling when removing last entry from manifest

* Fix nested fenced code blocks in agent-template using tildes

* Add core-manifest for references to protect user-created reference docs

Same pattern as agents: launchme/updateme write a .core-manifest in
.claude/references/ listing installed core files. The deprecation loop
only touches files in the manifest, leaving user-created references
untouched.

* Move deprecated files to .claude/deprecated/ to prevent auto-discovery

Deprecated agents kept in .claude/agents/ could still be auto-discovered
by Claude Code via their frontmatter. Moving them to .claude/deprecated/
ensures they are completely invisible to the dispatcher while still
preserved for user reference.

* Harden updateme.sh from Copilot review feedback

Address multiple issues raised during PR code review:

- Skip deprecation entirely when .core-manifest is missing, preventing
  accidental deprecation of custom agents/references on first update
- Preserve user's "## Custom Agents" sections in agents-registry.md and
  agents.md during reference updates (merge strategy instead of overwrite)
- Update confirmation message to accurately reflect what is preserved

* Preserve custom agent content during install and update

- launchme.sh: skip overwriting agents-registry.md and agents.md on
  reinstall to preserve custom agent entries
- updateme.sh: extract and re-insert custom table rows from the
  registry table plus custom sections, preventing data loss when
  updating from upstream
- Require manifest before deprecating to avoid false positives

* Update wardrobe-coach example phrase in README

* Use robust string matching and printf for user-mutable refs

- Replace grep -qw with bash substring match for filename detection
- Replace echo with printf '%s\n' to prevent content mangling

* Enforce step-by-step conversation in Architect and fix registry row reinsertion

- Add HARD CONSTRAINT blocks to both onboarding and custom agent creation
  flows, forcing the use of AskUserQuestion for each question to prevent
  the Architect from skipping phases or bundling questions
- Replace hard-coded "| postman |" match in updateme.sh with generic
  last-table-row detection to avoid breaking custom row reinsertion if
  core agents are renamed or reordered

* Improve input handling in launchme.sh and updateme.sh for non-interactive shells

* Extract 13 skills from agents and update full documentation

Architecture change: complex multi-step flows (onboarding, email triage,
transcription, etc.) are now skills that run in the main conversation
context instead of agent subprocesses. This fixes the state/context loss
that caused agents to skip phases during multi-turn conversations.

Skills created (13):
- Architect: /onboarding, /create-agent, /manage-agent, /defrag
- Postman: /email-triage, /meeting-prep, /weekly-agenda, /deadline-radar
- Transcriber: /transcribe
- Librarian: /vault-audit, /deep-clean, /tag-garden
- Sorter: /inbox-triage

Agent changes:
- architect.md: -70% (1554 → 473 lines)
- transcriber.md: -72% (530 → 147 lines)
- postman.md: -42%, librarian.md: -37%, sorter.md: -11%
- All agents: explicit post-it create-if-not-exists

Scripts:
- launchme.sh/updateme.sh: copy skills/ directly, remove generate-skills.py

Docs updated:
- README.md: new Skills section, mermaid diagrams, routing
- getting-started.md, examples.md: skill references
- docs/agents/*.md: capability tables with skill vs agent routing
- references/agents.md, agent-orchestration.md, agents-registry.md,
  agent-template.md: skill registry, skill-first routing protocol
This commit is contained in:
Gnekt
2026-03-25 12:00:00 +01:00
committed by GitHub
parent 1df4afb6dd
commit 1ee2dc415f
42 changed files with 6025 additions and 2316 deletions

View File

@@ -1,124 +0,0 @@
#!/usr/bin/env python3
"""
Generate skills/ from agents/ — single source of truth stays in agents/*.md.
Each agent becomes a skill at skills/{name}/SKILL.md with:
- tools: → allowed-tools:
- disallowedTools: → (dropped if allowed-tools is set)
- model: → model:
- description: → description:
+ context: fork → run in isolated subagent (like a real subagent)
Usage: python3 scripts/generate-skills.py
"""
import os, re, sys
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
AGENTS_DIR = os.path.join(ROOT, "agents")
SKILLS_DIR = os.environ.get("SKILLS_DIR", os.path.join(ROOT, "skills"))
def parse_agent(path: str):
"""Return (frontmatter_dict, body_str) from an agent .md file."""
with open(path, encoding="utf-8") as f:
text = f.read()
# Split on the two --- delimiters
m = re.match(r"^---\n(.*?\n)---\n(.*)", text, re.DOTALL)
if not m:
return None, text
raw_fm = m.group(1)
body = m.group(2)
# Simple YAML-ish parser for the flat fields we care about
fm = {}
current_key = None
current_val = ""
for line in raw_fm.split("\n"):
# New key
key_match = re.match(r"^(\w[\w-]*):\s*(.*)", line)
if key_match:
if current_key:
fm[current_key] = current_val.strip()
current_key = key_match.group(1)
val = key_match.group(2)
if val == ">":
current_val = ""
else:
current_val = val
elif current_key and line.startswith(" "):
current_val += " " + line.strip()
if current_key:
fm[current_key] = current_val.strip()
return fm, body
def build_skill_frontmatter(fm: dict) -> str:
"""Convert agent frontmatter to skill frontmatter."""
lines = ["---"]
name = fm.get("name", "unknown")
lines.append(f"name: {name}")
if "description" in fm:
desc = fm["description"]
lines.append("description: >")
# Wrap description at ~90 chars, indent with exactly 2 spaces
words = desc.split()
line = ""
for w in words:
if line and len(line) + len(w) + 1 > 88:
lines.append(" " + line)
line = w
else:
line = line + " " + w if line else w
if line:
lines.append(" " + line)
# Skills only support: name, description, argument-hint, compatibility,
# disable-model-invocation, license, metadata, user-invocable.
# No tool restrictions, model override, or fork context.
lines.append("---")
return "\n".join(lines)
def main():
if not os.path.isdir(AGENTS_DIR):
print(f"Error: {AGENTS_DIR} not found", file=sys.stderr)
sys.exit(1)
count = 0
for fname in sorted(os.listdir(AGENTS_DIR)):
if not fname.endswith(".md"):
continue
agent_path = os.path.join(AGENTS_DIR, fname)
fm, body = parse_agent(agent_path)
if fm is None:
print(f" ! Skipped {fname} (no frontmatter)")
continue
name = fm.get("name", fname.replace(".md", ""))
skill_dir = os.path.join(SKILLS_DIR, name)
os.makedirs(skill_dir, exist_ok=True)
skill_content = build_skill_frontmatter(fm) + "\n" + body
skill_path = os.path.join(skill_dir, "SKILL.md")
with open(skill_path, "w", encoding="utf-8") as f:
f.write(skill_content)
print(f"{name}/SKILL.md")
count += 1
print(f"\n Generated {count} skills in skills/")
if __name__ == "__main__":
main()

View File

@@ -50,56 +50,111 @@ echo -e " ${DIM}${VAULT_DIR}${NC}"
echo ""
echo -e " ${BOLD}y)${NC} Yes, install here"
echo -e " ${BOLD}n)${NC} No, let me type the correct path"
read -r -p " > " CONFIRM
if ! read -r -p " > " CONFIRM 2>/dev/null; then CONFIRM=""; fi
if [[ "$CONFIRM" =~ ^[Nn]$ ]]; then
echo ""
echo -e "${BOLD}Enter the full path to your Obsidian vault:${NC}"
read -r -p " > " VAULT_DIR
if ! read -r -p " > " VAULT_DIR 2>/dev/null; then die "Cannot read input — are you running in a non-interactive shell?"; fi
VAULT_DIR="${VAULT_DIR/#\~/$HOME}"
[[ -d "$VAULT_DIR" ]] || die "Directory not found: $VAULT_DIR"
fi
# ── Copy agents ─────────────────────────────────────────────────────────────
# ── Check for existing installation ───────────────────────────────────────
echo ""
EXISTING=0
if [[ -d "$VAULT_DIR/.claude" ]]; then EXISTING=1; fi
if [[ -f "$VAULT_DIR/CLAUDE.md" ]]; then EXISTING=1; fi
if [[ $EXISTING -eq 1 ]]; then
warn "An existing installation was detected:"
[[ -d "$VAULT_DIR/.claude" ]] && warn " .claude/ directory exists"
[[ -f "$VAULT_DIR/CLAUDE.md" ]] && warn " CLAUDE.md exists"
echo ""
echo -e " ${BOLD}The installer needs to overwrite these files.${NC}"
echo -e " ${DIM}Custom agents in .claude/agents/ will NOT be deleted.${NC}"
echo -e " ${DIM}Your vault notes are never touched.${NC}"
echo ""
echo -e " ${BOLD}c)${NC} Continue (overwrite core files, keep custom agents)"
echo -e " ${BOLD}q)${NC} Quit"
if ! read -r -p " > " OVERWRITE_ANSWER 2>/dev/null; then OVERWRITE_ANSWER=""; fi
if [[ ! "$OVERWRITE_ANSWER" =~ ^[Cc]$ ]]; then
echo ""
info "Installation cancelled."
echo ""
exit 0
fi
fi
# ── Deprecate stale core agents on reinstall ─────────────────────────────
echo ""
info "Creating .claude/agents/ in vault..."
mkdir -p "$VAULT_DIR/.claude/agents"
OLD_MANIFEST="$VAULT_DIR/.claude/agents/.core-manifest"
if [[ $EXISTING -eq 1 && -f "$OLD_MANIFEST" ]]; then
while IFS= read -r old_name; do
[[ -z "$old_name" ]] && continue
[[ -f "$REPO_DIR/agents/$old_name" ]] && continue
vault_file="$VAULT_DIR/.claude/agents/$old_name"
[[ -f "$vault_file" ]] || continue
deprecated_name="${old_name%.md}-DEPRECATED.md"
mkdir -p "$VAULT_DIR/.claude/deprecated"
[[ -f "$VAULT_DIR/.claude/deprecated/$deprecated_name" ]] && continue
mv "$vault_file" "$VAULT_DIR/.claude/deprecated/$deprecated_name"
{ echo "########"; echo "DEPRECATED DO NOT USE"; echo "########"; echo ""; cat "$VAULT_DIR/.claude/deprecated/$deprecated_name"; } > "$VAULT_DIR/.claude/deprecated/$deprecated_name.tmp"
mv "$VAULT_DIR/.claude/deprecated/$deprecated_name.tmp" "$VAULT_DIR/.claude/deprecated/$deprecated_name"
warn "Deprecated stale agent: $old_name -> deprecated/$deprecated_name"
done < "$OLD_MANIFEST"
fi
# ── Copy agents ─────────────────────────────────────────────────────────────
info "Creating .claude/agents/ in vault..."
AGENT_COUNT=0
: > "$VAULT_DIR/.claude/agents/.core-manifest"
for agent in "$REPO_DIR/agents/"*.md; do
cp "$agent" "$VAULT_DIR/.claude/agents/"
basename "$agent" >> "$VAULT_DIR/.claude/agents/.core-manifest"
AGENT_COUNT=$((AGENT_COUNT + 1))
done
success "Copied $AGENT_COUNT agents"
# ── Create Meta/states/ for agent post-its ──────────────────────────────────
mkdir -p "$VAULT_DIR/Meta/states"
info "Created Meta/states/ (agent post-it directory)"
# ── Copy references ─────────────────────────────────────────────────────────
info "Creating .claude/references/ in vault..."
mkdir -p "$VAULT_DIR/.claude/references"
cp "$REPO_DIR/references/"*.md "$VAULT_DIR/.claude/references/"
# User-mutable references (modified by Architect when creating custom agents)
USER_MUTABLE_REFS="agents-registry.md agents.md"
: > "$VAULT_DIR/.claude/references/.core-manifest"
for ref in "$REPO_DIR/references/"*.md; do
ref_name="$(basename "$ref")"
# On reinstall, preserve user-mutable reference files
if [[ $EXISTING -eq 1 && -f "$VAULT_DIR/.claude/references/$ref_name" ]]; then
if [[ " $USER_MUTABLE_REFS " == *" $ref_name "* ]]; then
warn "Preserving existing $ref_name (run updateme.sh to merge upstream changes)"
echo "$ref_name" >> "$VAULT_DIR/.claude/references/.core-manifest"
continue
fi
fi
cp "$ref" "$VAULT_DIR/.claude/references/"
echo "$ref_name" >> "$VAULT_DIR/.claude/references/.core-manifest"
done
success "Copied references"
# ── Generate and copy skills (for Cowork/Desktop) ───────────────────────────
# ── Copy skills ──────────────────────────────────────────────────────────────
SKILL_COUNT=0
if command -v python3 >/dev/null 2>&1 && [[ -f "$REPO_DIR/scripts/generate-skills.py" ]]; then
info "Generating skills from agents..."
SKILLS_TMP="$(mktemp -d)"
SKILLS_DIR="$SKILLS_TMP" python3 "$REPO_DIR/scripts/generate-skills.py" >/dev/null 2>&1 || true
if [[ -d "$SKILLS_TMP" ]] && ls "$SKILLS_TMP"/*/SKILL.md >/dev/null 2>&1; then
info "Creating .claude/skills/ in vault..."
for skill_dir in "$SKILLS_TMP/"*/; do
skill_name="$(basename "$skill_dir")"
mkdir -p "$VAULT_DIR/.claude/skills/$skill_name"
cp "$skill_dir"* "$VAULT_DIR/.claude/skills/$skill_name/" 2>/dev/null || true
SKILL_COUNT=$((SKILL_COUNT + 1))
done
success "Copied $SKILL_COUNT skills"
fi
rm -rf "$SKILLS_TMP"
else
warn "python3 not found — skipped skills generation (Cowork/Desktop won't have skills)"
warn "Install Python 3 and re-run this script to enable Cowork/Desktop support"
if [[ -d "$REPO_DIR/skills" ]]; then
for skill_dir in "$REPO_DIR/skills/"*/; do
[[ -f "$skill_dir/SKILL.md" ]] || continue
skill_name="$(basename "$skill_dir")"
mkdir -p "$VAULT_DIR/.claude/skills/$skill_name"
cp "$skill_dir"SKILL.md "$VAULT_DIR/.claude/skills/$skill_name/"
SKILL_COUNT=$((SKILL_COUNT + 1))
done
success "Copied $SKILL_COUNT skills"
fi
# ── Copy CLAUDE.md ───────────────────────────────────────────────────────────
@@ -116,7 +171,7 @@ echo -e " ${DIM}You can always add this later.${NC}"
echo ""
echo -e " ${BOLD}y)${NC} Yes, set up Gmail + Calendar"
echo -e " ${BOLD}n)${NC} No, skip for now"
read -r -p " > " MCP_ANSWER
if ! read -r -p " > " MCP_ANSWER 2>/dev/null; then MCP_ANSWER=""; fi
if [[ "$MCP_ANSWER" =~ ^[Yy]$ ]]; then
if [[ -f "$VAULT_DIR/.mcp.json" ]]; then
@@ -137,8 +192,8 @@ echo -e " Your vault is ready. Here's what was installed:"
echo ""
echo -e " ${VAULT_DIR}/"
echo -e " ├── .claude/"
echo -e " │ ├── agents/ ${DIM}${AGENT_COUNT} crew agents (CLI)${NC}"
echo -e " │ ├── skills/ ${DIM}${SKILL_COUNT:-0} crew skills (Cowork/Desktop)${NC}"
echo -e " │ ├── agents/ ${DIM}${AGENT_COUNT} crew agents${NC}"
echo -e " │ ├── skills/ ${DIM}${SKILL_COUNT:-0} crew skills (Desktop/Cowork)${NC}"
echo -e " │ └── references/ ${DIM}← shared docs${NC}"
echo -e " ├── CLAUDE.md ${DIM}← project instructions${NC}"
if [[ "$MCP_ANSWER" =~ ^[Yy]$ ]]; then

View File

@@ -45,10 +45,67 @@ echo -e "${BOLD}║ My Brain Is Full - Crew :: Update ║${NC}"
echo -e "${BOLD}╚══════════════════════════════════════════╝${NC}"
echo ""
# ── Update agents ───────────────────────────────────────────────────────────
# ── Confirm overwrite ────────────────────────────────────────────────────
echo -e "${BOLD}This will overwrite core agent files, references, and CLAUDE.md.${NC}"
echo -e " ${DIM}Custom agent files in .claude/agents/ will not be deleted or overwritten.${NC}"
echo -e " ${DIM}Custom agent entries in registry/directory will be preserved during update.${NC}"
echo -e " ${DIM}Your vault notes are never touched.${NC}"
echo ""
echo -e " ${BOLD}c)${NC} Continue"
echo -e " ${BOLD}q)${NC} Quit"
if ! read -r -p " > " UPDATE_ANSWER 2>/dev/null; then UPDATE_ANSWER=""; fi
if [[ ! "$UPDATE_ANSWER" =~ ^[Cc]$ ]]; then
echo ""
info "Update cancelled."
echo ""
exit 0
fi
echo ""
# ── Deprecate removed core agents ─────────────────────────────────────────
# Read the OLD manifest first (before rewriting it) so we know which files
# were previously installed as core. Agents removed from the repo will still
# be in the old manifest and can be correctly deprecated.
MANIFEST="$VAULT_DIR/.claude/agents/.core-manifest"
DEPRECATED_COUNT=0
for vault_agent in "$VAULT_DIR/.claude/agents/"*.md; do
[[ -f "$vault_agent" ]] || continue
name="$(basename "$vault_agent")"
# Skip if it still exists in repo
[[ -f "$REPO_DIR/agents/$name" ]] && continue
# Skip if already deprecated
[[ "$name" == *"-DEPRECATED"* ]] && continue
# Require manifest to distinguish core from custom agents
if [[ ! -f "$MANIFEST" ]]; then
continue
fi
# Skip custom agents: only deprecate if listed in the manifest
if ! grep -qxF "$name" "$MANIFEST"; then
continue
fi
deprecated_name="${name%.md}-DEPRECATED.md"
mkdir -p "$VAULT_DIR/.claude/deprecated"
# Skip if already deprecated in a previous run
[[ -f "$VAULT_DIR/.claude/deprecated/$deprecated_name" ]] && continue
mv "$vault_agent" "$VAULT_DIR/.claude/deprecated/$deprecated_name"
# Prepend deprecation header
{ echo "########"; echo "DEPRECATED DO NOT USE"; echo "########"; echo ""; cat "$VAULT_DIR/.claude/deprecated/$deprecated_name"; } > "$VAULT_DIR/.claude/deprecated/$deprecated_name.tmp"
mv "$VAULT_DIR/.claude/deprecated/$deprecated_name.tmp" "$VAULT_DIR/.claude/deprecated/$deprecated_name"
warn "Deprecated agent: $name -> deprecated/$deprecated_name"
DEPRECATED_COUNT=$((DEPRECATED_COUNT + 1))
# Remove deprecated agent from manifest
if [[ -f "$MANIFEST" ]]; then
grep -vxF "$name" "$MANIFEST" > "$MANIFEST.tmp" || true
mv "$MANIFEST.tmp" "$MANIFEST"
fi
done
# ── Update agents and rewrite manifest ────────────────────────────────────
AGENT_COUNT=0
: > "$VAULT_DIR/.claude/agents/.core-manifest"
for agent in "$REPO_DIR/agents/"*.md; do
name="$(basename "$agent")"
basename "$agent" >> "$VAULT_DIR/.claude/agents/.core-manifest"
if [[ -f "$VAULT_DIR/.claude/agents/$name" ]]; then
if ! diff -q "$agent" "$VAULT_DIR/.claude/agents/$name" >/dev/null 2>&1; then
cp "$agent" "$VAULT_DIR/.claude/agents/"
@@ -62,43 +119,122 @@ for agent in "$REPO_DIR/agents/"*.md; do
fi
done
# ── Update references ───────────────────────────────────────────────────────
# ── Deprecate removed references ──────────────────────────────────────────
# Read the old manifest before rewriting, same logic as agents.
REF_MANIFEST="$VAULT_DIR/.claude/references/.core-manifest"
for vault_ref in "$VAULT_DIR/.claude/references/"*.md; do
[[ -f "$vault_ref" ]] || continue
name="$(basename "$vault_ref")"
[[ -f "$REPO_DIR/references/$name" ]] && continue
[[ "$name" == *"-DEPRECATED"* ]] && continue
# Require manifest to distinguish core from user-created references
if [[ ! -f "$REF_MANIFEST" ]]; then
continue
fi
# Skip user-created references: only deprecate if listed in the manifest
if ! grep -qxF "$name" "$REF_MANIFEST"; then
continue
fi
deprecated_name="${name%.md}-DEPRECATED.md"
mkdir -p "$VAULT_DIR/.claude/deprecated"
[[ -f "$VAULT_DIR/.claude/deprecated/$deprecated_name" ]] && continue
mv "$vault_ref" "$VAULT_DIR/.claude/deprecated/$deprecated_name"
{ echo "########"; echo "DEPRECATED DO NOT USE"; echo "########"; echo ""; cat "$VAULT_DIR/.claude/deprecated/$deprecated_name"; } > "$VAULT_DIR/.claude/deprecated/$deprecated_name.tmp"
mv "$VAULT_DIR/.claude/deprecated/$deprecated_name.tmp" "$VAULT_DIR/.claude/deprecated/$deprecated_name"
warn "Deprecated reference: $name -> deprecated/$deprecated_name"
DEPRECATED_COUNT=$((DEPRECATED_COUNT + 1))
done
# ── Update references and rewrite manifest ────────────────────────────────
# Files the Architect modifies with user content (custom agent rows/sections).
# These need special merge logic to preserve the "## Custom Agents" section.
USER_MUTABLE_REFS="agents-registry.md agents.md"
# ── Ensure Meta/states/ exists (agent post-its) ─────────────────────────────
mkdir -p "$VAULT_DIR/Meta/states"
REF_COUNT=0
mkdir -p "$VAULT_DIR/.claude/references"
: > "$VAULT_DIR/.claude/references/.core-manifest"
for ref in "$REPO_DIR/references/"*.md; do
name="$(basename "$ref")"
if ! diff -q "$ref" "$VAULT_DIR/.claude/references/$name" >/dev/null 2>&1; then
cp "$ref" "$VAULT_DIR/.claude/references/"
basename "$ref" >> "$VAULT_DIR/.claude/references/.core-manifest"
vault_copy="$VAULT_DIR/.claude/references/$name"
# For user-mutable files: preserve custom agent content
if [[ " $USER_MUTABLE_REFS " == *" $name "* ]] && [[ -f "$vault_copy" ]]; then
# Extract user's custom section (from "## Custom Agents" to end of file)
custom_section=""
if grep -qn "^## Custom Agents" "$vault_copy"; then
custom_line=$(grep -n "^## Custom Agents" "$vault_copy" | head -1 | cut -d: -f1)
custom_section=$(tail -n +"$custom_line" "$vault_copy")
fi
# For agents-registry.md: also extract custom rows from the Registry table
# Custom rows are table lines whose agent name is NOT a core agent
custom_table_rows=""
if [[ "$name" == "agents-registry.md" ]]; then
CORE_NAMES="architect scribe sorter seeker connector librarian transcriber postman"
while IFS= read -r row; do
# Extract agent name from first column: | name | ...
agent_name=$(echo "$row" | awk -F'|' '{gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}')
if [[ -n "$agent_name" ]] && ! echo "$CORE_NAMES" | grep -qw "$agent_name"; then
custom_table_rows="${custom_table_rows}${row}"$'\n'
fi
done < <(grep "^|" "$vault_copy" | grep -v "^|[[:space:]]*Name[[:space:]]*|" | grep -v "^|[-[:space:]]*|")
fi
# Copy the new repo version
if ! diff -q "$ref" "$vault_copy" >/dev/null 2>&1; then
cp "$ref" "$vault_copy"
# Re-insert custom table rows into the registry table (after the last table row)
if [[ -n "$custom_table_rows" ]]; then
# Find the last table row (any line starting with |) — avoids hard-coding a specific agent name
last_table_line=$(grep -n "^|" "$vault_copy" | tail -1 | cut -d: -f1)
if [[ -n "$last_table_line" ]]; then
{ head -n "$last_table_line" "$vault_copy"; printf "%s" "$custom_table_rows"; tail -n +"$((last_table_line + 1))" "$vault_copy"; } > "$vault_copy.tmp"
mv "$vault_copy.tmp" "$vault_copy"
fi
fi
# Re-append preserved custom section (replace the repo's empty custom section)
if [[ -n "$custom_section" ]]; then
repo_custom_line=$(grep -n "^## Custom Agents" "$vault_copy" | head -1 | cut -d: -f1)
if [[ -n "$repo_custom_line" ]]; then
head -n "$((repo_custom_line - 1))" "$vault_copy" > "$vault_copy.tmp"
printf '%s\n' "$custom_section" >> "$vault_copy.tmp"
mv "$vault_copy.tmp" "$vault_copy"
fi
fi
info "Updated reference: $name (preserved custom content)"
REF_COUNT=$((REF_COUNT + 1))
fi
continue
fi
if [[ ! -f "$vault_copy" ]] || ! diff -q "$ref" "$vault_copy" >/dev/null 2>&1; then
cp "$ref" "$vault_copy"
info "Updated reference: $name"
REF_COUNT=$((REF_COUNT + 1))
fi
done
# ── Regenerate and update skills ───────────────────────────────────────────
# ── Update skills ────────────────────────────────────────────────────────────
SKILL_COUNT=0
if command -v python3 >/dev/null 2>&1 && [[ -f "$REPO_DIR/scripts/generate-skills.py" ]]; then
SKILLS_TMP="$(mktemp -d)"
SKILLS_DIR="$SKILLS_TMP" python3 "$REPO_DIR/scripts/generate-skills.py" >/dev/null 2>&1 || true
if [[ -d "$SKILLS_TMP" ]] && ls "$SKILLS_TMP"/*/SKILL.md >/dev/null 2>&1; then
for skill_dir in "$SKILLS_TMP/"*/; do
skill_name="$(basename "$skill_dir")"
src="$skill_dir/SKILL.md"
dst="$VAULT_DIR/.claude/skills/$skill_name/SKILL.md"
if [[ -f "$src" ]]; then
if [[ ! -f "$dst" ]] || ! diff -q "$src" "$dst" >/dev/null 2>&1; then
mkdir -p "$VAULT_DIR/.claude/skills/$skill_name"
cp "$src" "$dst"
info "Updated skill: $skill_name"
SKILL_COUNT=$((SKILL_COUNT + 1))
fi
fi
done
fi
rm -rf "$SKILLS_TMP"
else
warn "python3 not found — skipped skills update"
if [[ -d "$REPO_DIR/skills" ]]; then
for skill_dir in "$REPO_DIR/skills/"*/; do
[[ -f "$skill_dir/SKILL.md" ]] || continue
skill_name="$(basename "$skill_dir")"
src="$skill_dir/SKILL.md"
dst="$VAULT_DIR/.claude/skills/$skill_name/SKILL.md"
if [[ ! -f "$dst" ]] || ! diff -q "$src" "$dst" >/dev/null 2>&1; then
mkdir -p "$VAULT_DIR/.claude/skills/$skill_name"
cp "$src" "$dst"
info "Updated skill: $skill_name"
SKILL_COUNT=$((SKILL_COUNT + 1))
fi
done
fi
# ── Update CLAUDE.md ──────────────────────────────────────────────────────
@@ -113,10 +249,13 @@ fi
# ── Summary ─────────────────────────────────────────────────────────────────
echo ""
if [[ $AGENT_COUNT -eq 0 && $REF_COUNT -eq 0 && $SKILL_COUNT -eq 0 && -z "$CLAUDE_MD_UPDATED" ]]; then
if [[ $AGENT_COUNT -eq 0 && $REF_COUNT -eq 0 && $SKILL_COUNT -eq 0 && $DEPRECATED_COUNT -eq 0 && -z "$CLAUDE_MD_UPDATED" ]]; then
success "Everything is already up to date!"
else
success "Updated $AGENT_COUNT agent(s), $SKILL_COUNT skill(s), and $REF_COUNT reference(s)"
if [[ $DEPRECATED_COUNT -gt 0 ]]; then
warn "Deprecated $DEPRECATED_COUNT file(s) no longer in the project"
fi
fi
echo ""
echo -e " ${DIM}Restart Claude Code to pick up the changes.${NC}"