|
| 1 | +# Discover Inputs Protocol |
| 2 | + |
| 3 | +**Objective:** Intelligently load project files (whole or sharded) based on the workflow's Input Files configuration. |
| 4 | + |
| 5 | +**Prerequisite:** Only execute this protocol if the workflow defines an Input Files section. If no input file patterns are configured, skip this entirely. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Step 1: Parse Input File Patterns |
| 10 | + |
| 11 | +- Read the Input Files table from the workflow configuration. |
| 12 | +- For each input group (prd, architecture, epics, ux, etc.), note the **load strategy** if specified. |
| 13 | + |
| 14 | +## Step 2: Load Files Using Smart Strategies |
| 15 | + |
| 16 | +For each pattern in the Input Files table, work through the following substeps in order: |
| 17 | + |
| 18 | +### 2a: Try Sharded Documents First |
| 19 | + |
| 20 | +If a sharded pattern exists for this input, determine the load strategy (defaults to **FULL_LOAD** if not specified), then apply the matching strategy: |
| 21 | + |
| 22 | +#### FULL_LOAD Strategy |
| 23 | + |
| 24 | +Load ALL files in the sharded directory. Use this for PRD, Architecture, UX, brownfield docs, or whenever the full picture is needed. |
| 25 | + |
| 26 | +1. Use the glob pattern to find ALL `.md` files (e.g., `{planning_artifacts}/*architecture*/*.md`). |
| 27 | +2. Load EVERY matching file completely. |
| 28 | +3. Concatenate content in logical order: `index.md` first if it exists, then alphabetical. |
| 29 | +4. Store the combined result in a variable named `{pattern_name_content}` (e.g., `{architecture_content}`). |
| 30 | + |
| 31 | +#### SELECTIVE_LOAD Strategy |
| 32 | + |
| 33 | +Load a specific shard using a template variable. Example: used for epics with `{{epic_num}}`. |
| 34 | + |
| 35 | +1. Check for template variables in the sharded pattern (e.g., `{{epic_num}}`). |
| 36 | +2. If the variable is undefined, ask the user for the value OR infer it from context. |
| 37 | +3. Resolve the template to a specific file path. |
| 38 | +4. Load that specific file. |
| 39 | +5. Store in variable: `{pattern_name_content}`. |
| 40 | + |
| 41 | +#### INDEX_GUIDED Strategy |
| 42 | + |
| 43 | +Load index.md, analyze the structure and description of each doc in the index, then intelligently load relevant docs. |
| 44 | + |
| 45 | +**DO NOT BE LAZY** -- use best judgment to load documents that might have relevant information, even if there is only a 5% chance of relevance. |
| 46 | + |
| 47 | +1. Load `index.md` from the sharded directory. |
| 48 | +2. Parse the table of contents, links, and section headers. |
| 49 | +3. Analyze the workflow's purpose and objective. |
| 50 | +4. Identify which linked/referenced documents are likely relevant. |
| 51 | + - *Example:* If the workflow is about authentication and the index shows "Auth Overview", "Payment Setup", "Deployment" -- load the auth docs, consider deployment docs, skip payment. |
| 52 | +5. Load all identified relevant documents. |
| 53 | +6. Store combined content in variable: `{pattern_name_content}`. |
| 54 | + |
| 55 | +**When in doubt, LOAD IT** -- context is valuable, and being thorough is better than missing critical info. |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +After applying the matching strategy, mark the pattern as **RESOLVED** and move to the next pattern. |
| 60 | + |
| 61 | +### 2b: Try Whole Document if No Sharded Found |
| 62 | + |
| 63 | +If no sharded matches were found OR no sharded pattern exists for this input: |
| 64 | + |
| 65 | +1. Attempt a glob match on the "whole" pattern (e.g., `{planning_artifacts}/*prd*.md`). |
| 66 | +2. If matches are found, load ALL matching files completely (no offset/limit). |
| 67 | +3. Store content in variable: `{pattern_name_content}` (e.g., `{prd_content}`). |
| 68 | +4. Mark pattern as **RESOLVED** and move to the next pattern. |
| 69 | + |
| 70 | +### 2c: Handle Not Found |
| 71 | + |
| 72 | +If no matches were found for either sharded or whole patterns: |
| 73 | + |
| 74 | +1. Set `{pattern_name_content}` to empty string. |
| 75 | +2. Note in session: "No {pattern_name} files found" -- this is not an error, just unavailable. Offer the user a chance to provide the file. |
| 76 | + |
| 77 | +## Step 3: Report Discovery Results |
| 78 | + |
| 79 | +List all loaded content variables with file counts. Example: |
| 80 | + |
| 81 | +``` |
| 82 | +OK Loaded {prd_content} from 5 sharded files: prd/index.md, prd/requirements.md, ... |
| 83 | +OK Loaded {architecture_content} from 1 file: Architecture.md |
| 84 | +OK Loaded {epics_content} from selective load: epics/epic-3.md |
| 85 | +-- No ux_design files found |
| 86 | +``` |
| 87 | + |
| 88 | +This gives the workflow transparency into what context is available. |
0 commit comments