mit einem Klick
refactor
// Plan vault restructuring from config changes. Compares config.yaml against derivation.md, identifies dimension shifts, shows restructuring plan, executes on approval. Triggers on "/refactor", "restructure vault".
// Plan vault restructuring from config changes. Compares config.yaml against derivation.md, identifies dimension shifts, shows restructuring plan, executes on approval. Triggers on "/refactor", "restructure vault".
| name | refactor |
| description | Plan vault restructuring from config changes. Compares config.yaml against derivation.md, identifies dimension shifts, shows restructuring plan, executes on approval. Triggers on "/refactor", "restructure vault". |
| version | 1.0 |
| generated_from | arscontexta-v1.6 |
| user-invocable | true |
| context | fork |
| allowed-tools | Read, Write, Edit, Grep, Glob, Bash |
| argument-hint | [dimension|--dry-run] — focus on specific dimension or preview without approval prompt |
Read these files to configure domain-specific behavior:
ops/derivation-manifest.md — vocabulary mapping, dimension positions, platform hints
vocabulary.notes for the notes folder namevocabulary.note / vocabulary.note_plural for note type referencesvocabulary.topic_map / vocabulary.topic_map_plural for MOC referencesvocabulary.inbox for the inbox folder nameops/config.yaml — current live configuration (the "after" state)
ops/derivation.md — original derivation record (the "before" state)
If these files don't exist, report error: "Cannot refactor without both ops/config.yaml and ops/derivation.md. These files establish the baseline and current configuration."
INVARIANT: /refactor never executes without approval. The plan is always shown first.
Target: $ARGUMENTS
Parse immediately:
--dry-run: show plan without asking for approvalExecute these phases:
START NOW. Reference below defines the workflow.
Configuration changes cascade.
Changing a dimension is not just editing a value in config.yaml. Each dimension affects multiple artifacts — skills, templates, context file sections, hooks, MOC structure. Changing organization from "flat" to "hierarchical" means restructuring the notes directory, updating MOC templates, adjusting navigation references in the context file, and regenerating skills that reference folder structure.
/refactor makes these cascades visible and manages them. Without it, dimension changes create drift: config says one thing, artifacts say another. With it, every change is planned, approved, and validated.
The relationship to /architect: /architect RECOMMENDS changes. /refactor IMPLEMENTS them. /architect analyzes health and friction to propose dimension shifts. When those proposals are approved, /refactor ensures every affected artifact is updated consistently.
Compare each dimension in ops/config.yaml against the same dimension in ops/derivation.md:
Step 1: Read both files
Read ops/config.yaml and ops/derivation.md fully. Extract the position for each of the 8 dimensions from both.
Step 2: Build comparison table
| Dimension | Derivation Value | Config Value | Changed? | Drift Type |
|---|---|---|---|---|
| granularity | [val] | [val] | [yes/no] | [aligned/misaligned] |
| organization | [val] | [val] | [yes/no] | [aligned/misaligned] |
| linking | [val] | [val] | [yes/no] | [aligned/misaligned] |
| processing | [val] | [val] | [yes/no] | [aligned/misaligned] |
| navigation | [val] | [val] | [yes/no] | [aligned/misaligned] |
| maintenance | [val] | [val] | [yes/no] | [aligned/misaligned] |
| schema | [val] | [val] | [yes/no] | [aligned/misaligned] |
| automation | [val] | [val] | [yes/no] | [aligned/misaligned] |
Step 3: Check feature flags
Also compare feature flags between derivation and config:
| Feature | Derivation | Config | Changed? |
|---|---|---|---|
| semantic_search | [on/off] | [on/off] | [yes/no] |
| processing_pipeline | [on/off] | [on/off] | [yes/no] |
| self_space | [on/off] | [on/off] | [yes/no] |
| session_capture | [on/off] | [on/off] | [yes/no] |
| parallel_workers | [on/off] | [on/off] | [yes/no] |
Step 4: Early exit if no changes
If no changes detected:
--=={ refactor }==--
No configuration drift detected between config.yaml and derivation.md.
All dimensions and features match the original derivation.
If you want to explore changes, run /architect for recommendations
or edit ops/config.yaml directly, then run /refactor again.
For each changed dimension, determine ALL affected artifacts. This is the cascade analysis.
| Change | Affected Artifacts | What Changes |
|---|---|---|
| Granularity shift | Note templates, extraction depth in /reduce, processing skills, context file "Note Design" section | Template body length guidance, extraction granularity settings, composability test thresholds |
| Organization shift | Folder structure, MOC hierarchy, context file "Folder Architecture" section, hub MOC | Directory layout, MOC tier count, navigation references |
| Linking shift | Semantic search config, /reflect connection density expectations, context file "Connection Finding" section | Search tool availability, link threshold values, discovery layer instructions |
| Processing shift | /reduce depth settings, /reflect pass count, pipeline skills, context file "Processing Pipeline" section, config.yaml processing.depth | Extraction thoroughness, connection evaluation depth, chaining mode |
| Navigation shift | MOC tier structure, hub MOC, context file "MOC" section, note Topics footers | Number of MOC tiers, hub content, navigation instructions |
| Maintenance shift | /health threshold values, condition-based trigger settings, context file maintenance instructions | Check frequency conditions, stale note thresholds, reweave trigger conditions |
| Schema shift | Templates (_schema blocks), validation rules, /validate skill, query scripts, context file "YAML" section | Required fields, enum values, validation patterns |
| Automation shift | Hooks (session orient, write validation, inbox processing), skill activation, config.yaml automation section | Which hooks are active, automation level references |
For each affected artifact, specify:
Artifact: [file path]
Section: [specific section within the file, if applicable]
Current: [what it says now — quote relevant content]
Proposed: [what it should say after refactoring]
Risk: [low | medium | high]
Reversible: [yes | no — with explanation]
Content impact: [does this affect existing notes? how many?]
Some changes affect only infrastructure (skills, templates, context file). Others affect existing content (notes, MOCs):
| Change Type | Content Impact | Action Required |
|---|---|---|
| Template field addition | New notes get field, old notes don't | Add field to old notes (schema migration) |
| Template field removal | Old notes have unused field | Remove field from old notes (optional) |
| Folder restructure | Notes must move | Move files, update all wiki links |
| MOC tier change | MOC hierarchy restructured | Merge/split MOCs, update Topics footers |
| Enum value change | Old notes have invalid values | Update values in affected notes |
For content-impacting changes:
grep -rl '[old value]' {vocabulary.notes}/*.md | wc -lRead ${CLAUDE_PLUGIN_ROOT}/reference/interaction-constraints.md and check:
Hard blocks: Would the new configuration create a combination that WILL fail?
Soft warns: What friction points does the new configuration create?
Cascade effects: Does changing dimension X create pressure on dimension Y?
Present the complete restructuring plan:
--=={ refactor }==--
Detected [N] dimension changes:
[dimension]: [old] -> [new]
Affects:
- [artifact 1]: [specific change]
- [artifact 2]: [specific change]
Content impact: [N] existing {vocabulary.note_plural} need [what]
Risk: [low/medium/high]
[dimension]: [old] -> [new]
Affects:
- [artifact 1]: [specific change]
- [artifact 2]: [specific change]
Content impact: none
Risk: [low/medium/high]
Interaction constraints:
- [Hard block | Soft warn | Clean]: [description]
Unchanged (preserved as-is):
- [list artifacts not affected by changes]
Estimated implementation time: ~[N] minutes
Validation: Will run kernel validation after restructuring.
If --dry-run: Stop here. Do not ask for approval.
Otherwise: Ask: "Proceed with restructuring? (yes / no / adjust)"
Handle responses:
| Response | Action |
|---|---|
| "yes" | Execute Phase 4 |
| "no" | Exit without changes |
| "adjust" | Ask what to change, revise plan, re-present |
Execute changes in strict order to prevent intermediate inconsistency:
Before making changes, record the current state for rollback reference:
# Log what is about to change
DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "## $DATE: /refactor — [dimensions changed]" >> ops/changelog.md
echo "" >> ops/changelog.md
echo "Changes planned:" >> ops/changelog.md
echo "[list of changes]" >> ops/changelog.md
For each skill affected by the dimension changes:
${CLAUDE_PLUGIN_ROOT}/reference/ for the latest skill generation approachSkills most commonly affected by dimension changes:
| Dimension Change | Skills to Regenerate |
|---|---|
| Granularity | /reduce, /verify, /validate |
| Processing | /reduce, /reflect, /reweave, /verify, /ralph, /pipeline |
| Linking | /reflect, /reweave |
| Navigation | /reflect (MOC update logic) |
| Schema | /validate, /verify |
| Automation | /ralph, /pipeline (chaining mode) |
| Maintenance | /health |
Edit only the sections affected by changed dimensions. Do NOT rewrite the entire context file.
For each affected section:
For schema changes:
_schema blocks with new required fields, enum values, constraintsIf automation level changed:
After all changes are applied:
Update ops/derivation.md with:
Update ops/derivation-manifest.md to sync machine-readable config
Update ops/config.yaml to confirm it matches derivation (should already match since config triggered the refactor)
If Phase 2 identified content-impacting changes:
Schema migration: Add/remove/rename fields across notes
# Example: add a new required field to all notes
for f in {vocabulary.notes}/*.md; do
grep -q '^new_field:' "$f" || sed -i '' '/^description:/a\
new_field: [default value]' "$f"
done
Folder migration: Move files to new locations
# Use git mv to preserve history
git mv "old/path/file.md" "new/path/file.md"
Link updates: Update all wiki links affected by renames
# Use rename script if available
ops/scripts/rename-note.sh "old name" "new name"
MOC restructuring: Merge/split MOCs as needed
Run kernel validation to confirm nothing broke:
| Check | How | Pass Criterion |
|---|---|---|
| Wiki link resolution | Scan for all [[X]] and verify X.md exists | Zero dangling links |
| Schema compliance | Check all notes against template _schema blocks | All required fields present, enum values valid |
| MOC hierarchy | Verify hub links to domain MOCs, domains link to topics | All tiers connected |
| Session orient | Simulate session start — can the context file be loaded? | No file-not-found errors |
| Three-space boundaries | Check notes vs ops vs self boundaries | No content in wrong space |
| Vocabulary consistency | Check that skills and context file use updated vocabulary | No stale universal terms |
| Skill integrity | Verify regenerated skills have valid frontmatter and structure | All skills parseable |
--=={ refactor complete }==--
Restructuring applied:
[dimension]: [old] -> [new] — [N] artifacts updated
[dimension]: [old] -> [new] — [N] artifacts updated
Content migration:
[N] {vocabulary.note_plural} updated with new schema fields
[N] wiki links updated
[N] {vocabulary.topic_map_plural} restructured
Kernel validation: [N]/[N] checks PASS
[Any warnings or issues]
Derivation updated: ops/derivation.md
Changelog updated: ops/changelog.md
If any validation checks fail:
WARNING: [N] validation checks failed:
- [check name]: [specific failure]
Recommended action: [specific fix]
Rollback guidance: [how to revert if needed]
Cannot refactor without both files. Report error and suggest creating them:
Cannot run /refactor: [missing file] not found.
- ops/config.yaml is the live configuration
- ops/derivation.md is the original design baseline
Both are required to detect dimension shifts.
Run /setup to create a new system, or manually create the missing file.
If $ARGUMENTS names a specific dimension:
Report clean state and exit (see Phase 1 early exit).
If an interaction constraint hard block is detected:
HARD BLOCK: The proposed configuration [dimension X = val, dimension Y = val]
creates a combination that will fail because [reason from interaction-constraints.md].
Recommended: Either change [dimension X] back to [safe value] or also change
[dimension Y] to [compensating value].
Cannot proceed with current configuration. Adjust and re-run /refactor.
Do NOT proceed with restructuring when a hard block is active.
For large migrations:
Feature flag changes (semantic_search, self_space, etc.) may require:
Handle each feature flag change specifically:
| Flag | On -> Off | Off -> On |
|---|---|---|
| semantic_search | Remove search references from skills, update context file | Add search config, update skills with search integration |
| self_space | Archive self/ contents, remove self/ references | Create self/ structure, generate identity files |
| session_capture | INVARIANT — cannot disable | Already on (invariant) |
| parallel_workers | Update /ralph to serial-only mode | Verify tmux available, update /ralph for parallel mode |
Use universal vocabulary. Refactoring still works but vocabulary transformation is skipped.
Scaffold a complete knowledge system. Detects platform, conducts conversation, derives configuration, generates everything. Validates against 15 kernel primitives. Triggers on "/setup", "/setup --advanced", "set up my knowledge system", "create my vault".
Interactive knowledge graph analysis. Routes natural language questions to graph scripts, interprets results in domain vocabulary, and suggests concrete actions. Triggers on "/graph", "/graph health", "/graph triangles", "find synthesis opportunities", "graph analysis".
Research a topic and grow your knowledge graph. Uses Exa deep researcher, web search, or basic search to investigate topics, files results with full provenance, and chains to processing pipeline. Triggers on "/learn", "/learn [topic]", "research this", "find out about".
Surface the most valuable next action by combining task stack, queue state, inbox pressure, health, and goals. Recommends one specific action with rationale. Triggers on "/next", "what should I do", "what's next".
End-to-end source processing -- seed, reduce, process all claims through reflect/reweave/verify, archive. The full pipeline in one command. Triggers on "/pipeline", "/pipeline [file]", "process this end to end", "full pipeline".
Queue processing with fresh context per phase. Processes N tasks from the queue, spawning isolated subagents to prevent context contamination. Supports serial, parallel, batch filter, and dry run modes. Triggers on "/ralph", "/ralph N", "process queue", "run pipeline tasks".