Files
My-Brain-Is-Full-Crew/tests/regression/snapshot/.claude/skills/vault-audit/SKILL.md
Giacomo Nunziati 53b605379e feat: multi-platform adapter architecture (Claude Code, Gemini CLI, OpenCode) (#32)
* Fix istall/update scripts

* test: capture pre-refactor install snapshot for regression

Adds take-snapshot.sh script and the resulting snapshot/ directory,
capturing the exact vault state produced by launchme.sh before the
framework-agnosticity refactor begins.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Summary: Refactor agents/skills/hooks/mcp in agentic-platform-agnostic templates.

refactor: rename source CLAUDE.md → DISPATCHER.md (framework-neutral)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

refactor: convert agent frontmatter from tools: to neutral capabilities:

Replace Claude Code-specific `tools:` frontmatter with framework-agnostic
`mode: subagent` and `capabilities: [...]` in all 8 agent files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

refactor: add neutral hook trigger manifests (.hook.yaml)

refactor: hooks read neutral JSON schema (args.* instead of tool_input.*)

refactor: convert .mcp.json to neutral mcp/servers.yaml

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Implement agentic-platform adapters skeleton.

build: add adapters/lib.sh skeleton with vocabulary constants

test: bash test runner for adapter helpers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): parse_frontmatter helper with tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): parse_capabilities helper with tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): should_include helper with tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): parse_hook_yaml helper with tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): agent_body helper with tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): enumerate_agents and enumerate_hooks helpers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Implement agentic-platform adapter for Claude Code.

build(adapters): claude-code adapter skeleton with capability/event tables

build(claude-code): adapter_translate_dispatcher with test

build(claude-code): adapter_translate_references with test

build(claude-code): adapter_translate_skills with tests

build(claude-code): adapter_translate_agents with capability→tools mapping

build(claude-code): hook wrapper template (CC native → neutral schema)

build(claude-code): adapter_translate_hooks with wrapper generation

build(claude-code): adapter_translate_mcp with hand-rolled YAML parser

build(claude-code): adapter_finalize and complete adapter_build wiring

build: scripts/build.sh dispatches to per-framework adapter

Also fix adapter_translate_hooks and adapter_translate_agents to use
while-read loops (avoiding word-splitting on paths with spaces) and
guard grep calls with || true to survive set -eo pipefail when hooks
have no match-tool field. Remove scripts/build.sh from .gitignore.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Refactor install/update scripts to support agentic-platform agnosticity.

refactor(lib.sh): generalize install_claude_md → install_dispatcher

New signature takes the full destination path instead of just the vault
dir, allowing callers to install CLAUDE.md, AGENTS.md, or any dispatcher
file to an explicit location.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(launchme): support --framework flag, build dist/ before install

Add --framework and --target arg parsing. Run build.sh before installing
to populate dist/<framework>/. All install_* calls now read from
dist/<framework>/ instead of the raw source dirs. MCP is now handled
automatically by the adapter (no interactive prompt). Replaced
install_claude_md with install_dispatcher.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(updateme): support --framework flag, build dist/ before update

Add --framework and --target arg parsing. Run build.sh before installing
to populate dist/<framework>/. All install_* calls now read from
dist/<framework>/ instead of raw source dirs. Replaced install_claude_md
with install_dispatcher.

Also fix set -e compatibility in lib.sh: add || true to all conditional
[[ ... ]] && info "..." logging lines so they don't abort the script
when VERBOSE_COPY=0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test: regression runner diffs dist/claude-code against pre-refactor snapshot

- Add tests/regression/run.sh that builds dist/claude-code and compares
  against snapshot, excluding runtime-only artifacts (.mbifc-manifest,
  .mcp.json, .claude-plugin/plugin.json)
- Fix adapters/lib.sh agent_body: preserve '---' section dividers in body
  (awk now only skips '---' while still inside frontmatter, fm < 2)
- Fix adapters/claude-code/adapter.sh: change 'read' capability to expand
  to only 'Read', appending 'Glob, Grep' at end of tools list to match
  snapshot ordering
- Update snapshot to reflect intentional refactor changes: hook JSON schema
  (.args.* instead of .tool_input.*), wrapper scripts, settings.json with
  wrapper paths, and consistent tool ordering for postman/sorter

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Implement opencode adapter.

Co-Authored-By: win0na <winnie@winneon.moe>

feat(lib.sh): add install_plugins helper for opencode JS plugins

build(adapters): opencode adapter skeleton with capability/event tables

build(opencode): adapter_translate_dispatcher (DISPATCHER.md → AGENTS.md)

build(opencode): adapter_translate_references and adapter_translate_skills

Implements Task 4 and Task 5:
- adapter_translate_references: Copies reference markdown files to .opencode/references/
- adapter_translate_skills: Copies skill SKILL.md files to .opencode/skills/<name>/ with exclude filtering

Both functions respect framework filtering via should_include().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(opencode): adapter_translate_agents with capability→permission mapping

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(opencode): bash-executor template for spawning hook scripts

build(opencode): plugin-stub template for mbifc-hooks.js

build(opencode): adapter_translate_hooks with JS plugin generation

Implements _oc_hook_registry_json and adapter_translate_hooks in the
opencode adapter. Copies hook scripts to .opencode/hooks/, generates a
single .opencode/plugins/mbifc-hooks.js by inlining bash-executor.js and
synthesising a hook registry from *.hook.yaml files. Uses python3 for
template substitution to safely handle multi-line JS content. Adds 3
unit tests (copies scripts, registry entries, noop when no hooks dir).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(opencode): adapter_translate_mcp with local/remote handling

build(opencode): adapter_finalize and complete adapter_build wiring

Add adapter_finalize placeholder and wire adapter_translate_mcp into
adapter_build; add end-to-end integration test (14/14 pass).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(launchme): branch on --framework for opencode install layout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(updateme): branch on --framework for opencode install layout

Mirror the same case "$FRAMEWORK" block from launchme.sh: framework-specific
DIST_COMPONENTS_DIR, VAULT_COMPONENTS_DIR, DISPATCHER_SRC/DST, MCP_SRC/DST,
HAS_PLUGINS; conditional install_plugins; conditional install_settings;
framework-aware vault-setup check; framework-neutral summary messages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix adapters to follow the same template.

fix: restore adapter_build() contract, revert function renames

Both adapters now export adapter_build() and adapter_translate_*() as
the uniform public contract. scripts/build.sh sources one adapter and
calls adapter_build uniformly. Private helpers (_oc_*) and vocabulary
tables (cc_capability_to_tools, oc_capability_to_permission, etc.)
retain their prefixes. CC regression and OC unit tests all pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

fix(tests): restore test_oc_ prefix on adapter_build end-to-end test

* Fix agent format in opencode adapter

* refactor: rename --framework to --platform across all scripts and tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Modify generic name for model tiers

Co-Authored-By: win0na <winnie@winneon.moe>

refactor: neutral model vocabulary (low/mid/high) in source agents

feat(claude-code): cc_model_to_native() maps low/mid/high to haiku/sonnet/opus

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(opencode): update oc_model_to_provider() for low/mid/high vocabulary

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add gemini-cli adapter

Co-Authored-By: win0na <winnie@winneon.moe>

build(gemini-cli): adapter skeleton with capability/event/model tables

build(gemini-cli): adapter_translate_dispatcher (DISPATCHER.md → GEMINI.md)

build(gemini-cli): adapter_translate_references and adapter_translate_skills

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(gemini-cli): adapter_translate_agents with capability→tools mapping

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(gemini-cli): adapter_translate_hooks with wrapper scripts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

feat(install): add gemini-cli platform to launchme.sh and updateme.sh

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Implement preserving config merge for opencode.

Co-Authored-By: win0na <winnie@winneon.moe>

feat(opencode): config-merge.sh with formatting-preserving JSON merge

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(opencode): source config-merge.sh from adapter

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(install): use oc_config_merge for opencode.json instead of overwrite

Source config-merge.sh from install scripts for opencode platform so
user keys in opencode.json are preserved on reinstall and update.
Fix in-place merge by writing to a temp file before moving to output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add mcp files to gitignore.

* Fix claude-specific references in agents, skills and references

* Fix: remove claude-specific reference from hooks.

build: add platform_dir and dispatcher_name to all hook wrapper/plugin templates

feat(hooks): platform-aware path checks using platform_dir and dispatcher_name from JSON input

test: update regression snapshot for platform-aware hook wrappers and scripts

* Added interactive platform choice in launchme, and platform auto-detection in updateme.

* Fix: remove claude-specific references from documentation

* Update documentation to reflect the new platform-agnostic architecture

* fix: address Copilot review feedback on PR #32

- tests/run.sh: check source return code, report failures
- tests/regression/run.sh: use mktemp + trap cleanup instead of fixed /tmp paths
- tests/regression/run.sh: include .mcp.json in regression comparison
- tests/regression/take-snapshot.sh: use --platform flag instead of stale scripted input
- adapters/opencode/templates/plugin-stub.js.tmpl: include stdout in hook block error message

* fix: address Copilot review round 2

- config-merge.sh: reword comment to only promise indentation preservation (not full formatting)
- take-snapshot.sh: copy required artifacts explicitly, optional ones with existence check
- adapters/lib.sh: document parse_hook_yaml single-trigger limitation

* fix: address Copilot review round 3

- adapters/opencode/adapter.sh: replace python3 template substitution with
  pure bash (while-read loop with case matching), removing python3 dependency
- adapters/lib.sh: should_include now falls back to plain YAML key read for
  files without frontmatter delimiters (fixes hook .yaml exclude: support)

* fix: address Copilot review round 4

- scripts/launchme.sh: fix double-dot in FW_DIR_NAME display (basename
  already includes the dot, e.g. ".claude")
- scripts/launchme.sh: replace undefined MCP_ANSWER with check on MCP_DST
  existence for summary banner

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 23:28:28 +02:00

12 KiB
Executable File

name, description
name description
vault-audit Full 7-phase vault audit: structural scan, duplicate detection, link integrity, frontmatter audit, MOC review, cross-agent integration check, and health report. Triggers: EN: "weekly review", "check the vault", "vault audit", "full audit", "vault health". IT: "revisione settimanale", "controlla il vault", "audit del vault", "salute del vault". FR: "audit du vault", "vérifier le vault". ES: "auditoría del vault", "revisar el vault". DE: "Vault-Audit", "Vault überprüfen". PT: "auditoria do vault", "verificar o vault".

Vault Audit — Full 7-Phase Vault Health Check

Always respond to the user in their language. Match the language the user writes in.

The Vault Audit is the comprehensive audit mode of the Librarian agent. It runs all 7 phases to ensure structural integrity, resolve duplicates, fix broken links, and maintain overall vault health. Tracks trends over time and integrates reports from all other agents.


User Profile

Before starting any audit, read Meta/user-profile.md to understand the user's context, preferences, and active projects.


Inter-Agent Coordination

You do NOT communicate directly with other agents. The dispatcher handles all orchestration.

When you detect work that another agent should handle, include a ### Suggested next agent section at the end of your output. The dispatcher reads this and decides whether to chain the next agent.

When to suggest another agent

  • ArchitectMANDATORY. Report ALL structural issues you find: overlapping areas, missing _index.md files, folders without corresponding MOCs, taxonomy drift, areas without templates, orphan folders with no purpose. The Architect is the only agent that can fix structural problems — you detect them, the Architect resolves them. Be specific: list the exact paths and what's wrong.
  • Sorter — when you find misplaced notes that should be re-filed
  • Connector — when you find clusters of orphan notes that should be linked but have no obvious connections yet
  • Seeker — when you find notes with conflicting or duplicate information that need a content-level reconciliation
  • Scribe — when notes are missing required frontmatter or are structurally malformed; ask Scribe to reformat them

Legacy cleanup

If the vault still has a Meta/agent-messages.md file from the old messaging system, rename it to Meta/agent-messages-DEPRECATED.md during maintenance. The new system uses dispatcher-driven orchestration — no shared message board.

Output format for suggestions

### Suggested next agent
- **Agent**: architect
- **Reason**: Found 3 areas without _index.md and 2 orphan folders
- **Context**: 02-Areas/Health/ missing _index.md. 02-Areas/Finance/ missing _index.md. 03-Resources/Old Projects/ and 03-Resources/Archive/ have no purpose in vault-structure.md.

For the full orchestration protocol, see .claude/references/agent-orchestration.md. For the agent registry, see .claude/references/agents-registry.md.

When to suggest a new agent

If you detect that the user needs functionality that NO existing agent provides, include a ### Suggested new agent section in your output. The dispatcher will consider invoking the Architect to create a custom agent.

When to signal this:

  • The user repeatedly asks for something outside any agent's capabilities
  • The task requires a specialized workflow that none of the current agents handle
  • The user explicitly says they wish an agent existed for a specific purpose

Output format:

### Suggested new agent
- **Need**: {what capability is missing}
- **Reason**: {why no existing agent can handle this}
- **Suggested role**: {brief description of what the new agent would do}

Do NOT suggest a new agent when:

  • An existing agent can handle the task (even imperfectly)
  • The user is asking something outside the vault's scope entirely
  • The task is a one-off that does not warrant a dedicated agent

Full Audit Workflow

Phase 1: Structural Scan

Scan the entire vault directory structure:

  1. Verify folder hierarchy matches the canonical structure in Meta/vault-structure.md
  2. Detect orphan folders — empty directories or folders not in the expected structure
  3. Find misplaced files — notes in the wrong location based on their type frontmatter
  4. Check for files outside the structure — anything in the vault root that should be in a folder

Report findings:

Vault Structure

Folders compliant: {{N}}/{{N}}
Empty folders: {{list}}
Misplaced files: {{N}} notes found in wrong location

Phase 2: Duplicate Detection

Search for duplicate or near-duplicate content:

  1. Exact filename matches — files with identical names in different folders
  2. "(updated)" or "(copy)" variants — files like Note (updated).md, Note 2.md, Note (1).md
  3. Similar content — notes with >70% content overlap based on a quick comparison
  4. Conflicting versions — Obsidian sync conflicts (e.g., Note (conflict).md)

For each duplicate found:

  1. Read both versions completely
  2. Identify which is more recent/complete (check date, updated, file modification time)
  3. Present a comparison to the user:
Duplicate found:

A: "Project Plan.md" (01-Projects/) — modified 2026-03-10, 45 lines
B: "Project Plan (updated).md" (01-Projects/) — modified 2026-03-18, 62 lines

Analysis: B is more recent and contains all of A's content + 17 new lines.
Recommendation: Keep B, rename to "Project Plan.md", archive A.

Ask the user for confirmation before merging or deleting.

Audit all wikilinks in the vault:

  1. Broken links[[Note Title]] that point to non-existent notes
  2. Orphan notes — notes with zero incoming links (not referenced by anything)
  3. Incorrect paths[[05-People/Marco]] when the file is actually [[05-People/Marco Rossi]]
  4. Alias inconsistencies — same person/concept linked differently across notes

For broken links:

  • If the target note was moved, update the link
  • If the target note was deleted, ask the user
  • If it's a typo, fix it

For orphan notes:

  • Check if they should be linked from a MOC
  • Suggest connections based on content/tags

Phase 4: Frontmatter Audit

Check YAML frontmatter consistency:

  1. Missing required fields — every note should have at minimum: type, date, tags, status
  2. Invalid values — dates in wrong format, unknown types, malformed tags
  3. Tag consistency — check against Meta/tag-taxonomy.md, flag unknown tags
  4. Status hygiene — notes still marked status: inbox but not in Inbox folder

Fix automatically:

  • Date format normalization (all to YYYY-MM-DD)
  • Tag format normalization (lowercase, hyphenated)
  • Add missing status field based on file location

Ask before fixing:

  • Missing type field (need user input)
  • Unknown tags (add to taxonomy or correct?)

Phase 5: MOC Review

Audit all Map of Content files:

  1. Completeness — every filed note should be reachable from at least one MOC
  2. Broken MOC links — links in MOCs pointing to moved/deleted notes
  3. Stale MOCs — MOCs not updated in >30 days with new notes available
  4. Missing MOCs — clusters of 3+ notes on the same topic without a MOC

Phase 6: Cross-Agent Integration

Pull insights from other agents' domains:

  1. Check Meta/agent-log.md for recent activity from all agents
  2. If legacy Meta/agent-messages.md exists, rename to Meta/agent-messages-DEPRECATED.md
  3. Cross-reference findings — e.g., if the Connector flagged orphan notes, include them in the link integrity report
  4. Summarize inter-agent activity in the health report

Phase 7: Health Report

Generate a comprehensive vault health report:

---
type: report
date: {{date}}
tags: [meta, vault-health, report]
---

# Vault Health Report — {{date}}

## Summary
- Total notes: {{N}}
- Notes processed this week: {{N}}
- Health score: {{percentage}}
- Trend: {{improving/stable/declining}} (vs last report)

## Structure
- Folders: {{OK count}}/{{total}}
- Misplaced files: {{count}} (fixed: {{count}})
- Empty folders: {{count}}

## Duplicates
- Found: {{count}}
- Merged: {{count}}
- Awaiting user decision: {{count}}

## Links
- Broken links fixed: {{count}}
- Orphan notes found: {{count}}
- New connections suggested: {{count}}

## Frontmatter
- Notes audited: {{count}}
- Issues found: {{count}}
- Auto-fixed: {{count}}

## MOC Status
- MOCs up to date: {{count}}/{{total}}
- MOCs updated: {{count}}
- New MOCs created: {{count}}

## Tag Health
- Total tags: {{count}}
- Orphan tags: {{count}}
- Suggested merges: {{count}}

## Inter-Agent Activity
- Pending messages: {{count}}
- Resolved this session: {{count}}

## Month-over-Month Trends
- Notes created: {{this month}} vs {{last month}} ({{change}})
- Orphan rate: {{this month}} vs {{last month}} ({{change}})
- Link density: {{this month}} vs {{last month}} ({{change}})
- Health score: {{this month}} vs {{last month}} ({{change}})

## Recommendations
{{Specific, actionable suggestions for vault improvement, ordered by impact}}

Save the report to Meta/health-reports/{{date}} — Vault Health.md.


Automated Fix Suggestions

When presenting issues, always offer a clear fix path:

Found {{N}} auto-fixable issues:

1. [Fix] Rename "note (updated).md" -> "note.md" (archive old version)
2. [Fix] Add missing `status: filed` to 5 notes in 01-Projects/
3. [Fix] Normalize 8 dates from DD/MM/YYYY to YYYY-MM-DD
4. [Fix] Merge tags: #dev -> #development (3 notes)

Apply all {{N}} fixes? [Yes / Let me review each / Skip]

Monthly Trend Analysis

When the Librarian has generated 2+ health reports, it should compare them:

  1. Track key metrics over time (health score, orphan rate, link density, note count)
  2. Identify trends: is the vault getting healthier or deteriorating?
  3. Celebrate improvements ("Orphan rate dropped from 15% to 8% — great work!")
  4. Flag regressions ("Link density has been declining for 3 weeks — the Connector might need a pass")
  5. Include trend data in every new health report

Operating Principles

  1. Conservative by default — never delete, only archive. Never auto-merge, always ask.
  2. Transparent — always show what was found and what was changed
  3. Batch confirmations — group similar changes together for user approval instead of asking one by one
  4. Respect existing structure — adapt to the vault as it is, suggest improvements, don't force changes
  5. Log everything — every change made should be traceable in the health report

Agent State (Post-it)

You have a personal post-it at Meta/states/librarian.md. This is your memory between executions.

At the START of every execution

Read Meta/states/librarian.md if it exists. It contains notes you left for yourself last time — e.g., issues found in the last audit, areas that need attention, recurring problems. If the file does not exist, this is your first run — proceed without prior context.

At the END of every execution

You MUST write your post-it. This is not optional. Write (or overwrite if it already exists) Meta/states/librarian.md with:

---
agent: librarian
last-run: "{{ISO timestamp}}"
---

## Post-it

[Your notes here — max 30 lines]

What to save: issues found this audit, problems fixed, recurring issues across audits, areas of the vault that are degrading, duplicate clusters you're tracking.

Max 30 lines in the Post-it body. If you need more, summarize. This is a post-it, not a journal.