|
| 1 | +--- |
| 2 | +name: discover-system |
| 3 | +description: Use when onboarding an existing codebase or project into SysProM for the first time — bootstraps a new document by exploring the system and populating it with discovered intent, concepts, capabilities, elements, decisions, invariants, and relationships |
| 4 | +user-invocable: true |
| 5 | +allowed-tools: Bash(spm *), Read, Glob, Grep, Agent |
| 6 | +--- |
| 7 | + |
| 8 | +# Discover System |
| 9 | + |
| 10 | +Bootstrap a SysProM document from an existing codebase. Explores the system systematically, extracts provenance information, and populates a new document with discovered nodes and relationships. |
| 11 | + |
| 12 | +## When to Use |
| 13 | + |
| 14 | +- Starting SysProM on a project that already has code, docs, and history |
| 15 | +- Onboarding to an unfamiliar codebase and want structured understanding |
| 16 | +- Creating provenance documentation retrospectively |
| 17 | + |
| 18 | +## Process |
| 19 | + |
| 20 | +```dot |
| 21 | +digraph discover { |
| 22 | + rankdir=TB; |
| 23 | + init [label="1. Init empty document" shape=box]; |
| 24 | + explore [label="2. Explore system\n(parallel subagents)" shape=box]; |
| 25 | + review [label="3. Review discoveries\nwith user" shape=diamond]; |
| 26 | + populate [label="4. Populate nodes\nvia spm CLI" shape=box]; |
| 27 | + relate [label="5. Add relationships" shape=box]; |
| 28 | + validate [label="6. Validate & sync" shape=box]; |
| 29 | +
|
| 30 | + init -> explore -> review; |
| 31 | + review -> populate [label="approved"]; |
| 32 | + review -> explore [label="gaps found"]; |
| 33 | + populate -> relate -> validate; |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +### Step 1: Initialise |
| 38 | + |
| 39 | +Create an empty SysProM document in the project root. |
| 40 | + |
| 41 | +```bash |
| 42 | +spm init --path .spm.json --format json --title "<Project Name>" --author "<Author>" |
| 43 | +``` |
| 44 | + |
| 45 | +### Step 2: Explore (dispatch parallel subagents) |
| 46 | + |
| 47 | +Launch exploration subagents to discover each node type. Each subagent searches the codebase and returns a structured summary — it does NOT write to the document. |
| 48 | + |
| 49 | +**Dispatch these in parallel:** |
| 50 | + |
| 51 | +| Subagent | What to find | Where to look | |
| 52 | +|----------|-------------|---------------| |
| 53 | +| Intent | Project purpose, goals, mission | README, CLAUDE.md, AGENTS.md, docs/, package.json description, repo description | |
| 54 | +| Concepts | Domain models, key abstractions, bounded contexts | src/ type definitions, interfaces, schemas, domain models, glossaries | |
| 55 | +| Capabilities | Features, APIs, services, what the system can do | Route handlers, exported functions, CLI commands, public API surface | |
| 56 | +| Elements | Modules, packages, key files, infrastructure | Directory structure, package.json workspaces, build config, Dockerfiles | |
| 57 | +| Decisions | Architectural choices, technology selections, trade-offs | ADRs (docs/adr/, docs/decisions/), commit messages, config file choices (tsconfig, eslint, framework config), CLAUDE.md conventions | |
| 58 | +| Invariants | Rules that must always hold, constraints, policies | Lint rules, type constraints, test assertions, CI checks, validation schemas, CLAUDE.md rules | |
| 59 | + |
| 60 | +**Subagent prompt template:** |
| 61 | + |
| 62 | +> You are exploring a codebase to discover [NODE TYPE] for a SysProM provenance document. Search thoroughly using Glob, Grep, and Read. Return a structured list of discoveries in this format: |
| 63 | +> |
| 64 | +> For each discovery: |
| 65 | +> - **Suggested ID**: [TYPE_PREFIX][N] (e.g. I1, CN3, CP5, EL12, D7, INV4) |
| 66 | +> - **Name**: Short descriptive name |
| 67 | +> - **Description**: What it is and why it matters |
| 68 | +> - **Evidence**: File path and line or source where you found it |
| 69 | +> - [Type-specific fields: options/selected/rationale for decisions, conditions for invariants, etc.] |
| 70 | +> |
| 71 | +> Be thorough but avoid duplicates. Group related items. Aim for the right level of granularity — not every file is an element, not every function is a capability. |
| 72 | +
|
| 73 | +### Step 3: Review with user |
| 74 | + |
| 75 | +Present a summary table of all discoveries, grouped by type. Ask the user to: |
| 76 | + |
| 77 | +- Confirm, reject, or modify each discovery |
| 78 | +- Identify gaps ("what about the caching layer?") |
| 79 | +- Adjust granularity ("these three should be one capability") |
| 80 | +- Add context the code doesn't reveal ("we chose X because...") |
| 81 | + |
| 82 | +**Do not proceed to population without user approval.** |
| 83 | + |
| 84 | +### Step 4: Populate nodes |
| 85 | + |
| 86 | +For each approved discovery, create the node via the CLI: |
| 87 | + |
| 88 | +```bash |
| 89 | +# Intent |
| 90 | +spm add intent --name "<name>" --description "<description>" |
| 91 | + |
| 92 | +# Concepts |
| 93 | +spm add concept --name "<name>" --description "<description>" |
| 94 | + |
| 95 | +# Capabilities |
| 96 | +spm add capability --name "<name>" --description "<description>" |
| 97 | + |
| 98 | +# Elements |
| 99 | +spm add element --name "<name>" --description "<description>" |
| 100 | + |
| 101 | +# Decisions (with options and rationale) |
| 102 | +spm add decision --name "<name>" --context "<context>" \ |
| 103 | + --option "OPT-A:<description>" --option "OPT-B:<description>" \ |
| 104 | + --selected OPT-A --rationale "<rationale>" |
| 105 | + |
| 106 | +# Invariants |
| 107 | +spm add invariant --name "<name>" --description "<description>" |
| 108 | +``` |
| 109 | + |
| 110 | +### Step 5: Add relationships |
| 111 | + |
| 112 | +Connect nodes with typed relationships based on what the exploration revealed: |
| 113 | + |
| 114 | +```bash |
| 115 | +spm update add-rel <from> <type> <to> |
| 116 | +``` |
| 117 | + |
| 118 | +Common relationship types to look for: |
| 119 | + |
| 120 | +| Pattern | Relationship | |
| 121 | +|---------|-------------| |
| 122 | +| Intent → Concept | `refines` | |
| 123 | +| Concept → Capability | `refines` | |
| 124 | +| Capability → Element | `realises` | |
| 125 | +| Element → Element | `depends_on` | |
| 126 | +| Decision → Element | `affects` | |
| 127 | +| Decision → Invariant | `must_preserve` | |
| 128 | +| Invariant → Capability | `constrains` | |
| 129 | + |
| 130 | +### Step 6: Validate and sync |
| 131 | + |
| 132 | +```bash |
| 133 | +spm validate |
| 134 | +spm json2md .spm.json .spm |
| 135 | +``` |
| 136 | + |
| 137 | +Review any validation warnings and fix before finishing. |
| 138 | + |
| 139 | +## Granularity Guide |
| 140 | + |
| 141 | +| Too coarse | Right level | Too fine | |
| 142 | +|-----------|------------|---------| |
| 143 | +| "The backend" | "Authentication service" | "validatePassword function" | |
| 144 | +| "We use TypeScript" | "Strict TypeScript with no `any`" (invariant) | "tsconfig.json line 4" | |
| 145 | +| "The API" | "REST API for user management" | "GET /users/:id endpoint" | |
| 146 | + |
| 147 | +Aim for nodes that a developer would recognise as meaningful architectural units. |
| 148 | + |
| 149 | +## Common Mistakes |
| 150 | + |
| 151 | +- **Populating without review** — Always present discoveries to the user first. Code exploration misses context that humans know. |
| 152 | +- **Too many elements** — Not every file is an element. Focus on modules, packages, and architectural boundaries. |
| 153 | +- **Missing decisions** — The most valuable nodes are often decisions, which are hardest to discover from code alone. Ask the user about choices that shaped the system. |
| 154 | +- **Forgetting relationships** — A graph without edges is just a list. Relationships capture the structure that makes SysProM useful. |
0 commit comments