@imix-js/taproot 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +88 -0
  2. package/dist/adapters/index.d.ts +20 -0
  3. package/dist/adapters/index.js +452 -0
  4. package/dist/adapters/index.js.map +1 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +40 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/commands/acceptance-check.d.ts +26 -0
  9. package/dist/commands/acceptance-check.js +213 -0
  10. package/dist/commands/acceptance-check.js.map +1 -0
  11. package/dist/commands/check-orphans.d.ts +8 -0
  12. package/dist/commands/check-orphans.js +157 -0
  13. package/dist/commands/check-orphans.js.map +1 -0
  14. package/dist/commands/commithook.d.ts +15 -0
  15. package/dist/commands/commithook.js +389 -0
  16. package/dist/commands/commithook.js.map +1 -0
  17. package/dist/commands/coverage.d.ts +41 -0
  18. package/dist/commands/coverage.js +390 -0
  19. package/dist/commands/coverage.js.map +1 -0
  20. package/dist/commands/dod.d.ts +13 -0
  21. package/dist/commands/dod.js +141 -0
  22. package/dist/commands/dod.js.map +1 -0
  23. package/dist/commands/init.d.ts +14 -0
  24. package/dist/commands/init.js +378 -0
  25. package/dist/commands/init.js.map +1 -0
  26. package/dist/commands/link-commits.d.ts +12 -0
  27. package/dist/commands/link-commits.js +126 -0
  28. package/dist/commands/link-commits.js.map +1 -0
  29. package/dist/commands/overview.d.ts +6 -0
  30. package/dist/commands/overview.js +192 -0
  31. package/dist/commands/overview.js.map +1 -0
  32. package/dist/commands/plan.d.ts +23 -0
  33. package/dist/commands/plan.js +167 -0
  34. package/dist/commands/plan.js.map +1 -0
  35. package/dist/commands/sync-check.d.ts +8 -0
  36. package/dist/commands/sync-check.js +118 -0
  37. package/dist/commands/sync-check.js.map +1 -0
  38. package/dist/commands/update.d.ts +7 -0
  39. package/dist/commands/update.js +309 -0
  40. package/dist/commands/update.js.map +1 -0
  41. package/dist/commands/validate-format.d.ts +8 -0
  42. package/dist/commands/validate-format.js +93 -0
  43. package/dist/commands/validate-format.js.map +1 -0
  44. package/dist/commands/validate-structure.d.ts +8 -0
  45. package/dist/commands/validate-structure.js +29 -0
  46. package/dist/commands/validate-structure.js.map +1 -0
  47. package/dist/core/config.d.ts +6 -0
  48. package/dist/core/config.js +86 -0
  49. package/dist/core/config.js.map +1 -0
  50. package/dist/core/configuration.d.ts +7 -0
  51. package/dist/core/configuration.js +112 -0
  52. package/dist/core/configuration.js.map +1 -0
  53. package/dist/core/dod-runner.d.ts +20 -0
  54. package/dist/core/dod-runner.js +233 -0
  55. package/dist/core/dod-runner.js.map +1 -0
  56. package/dist/core/dor-runner.d.ts +18 -0
  57. package/dist/core/dor-runner.js +156 -0
  58. package/dist/core/dor-runner.js.map +1 -0
  59. package/dist/core/fs-walker.d.ts +5 -0
  60. package/dist/core/fs-walker.js +74 -0
  61. package/dist/core/fs-walker.js.map +1 -0
  62. package/dist/core/git.d.ts +24 -0
  63. package/dist/core/git.js +76 -0
  64. package/dist/core/git.js.map +1 -0
  65. package/dist/core/impl-reader.d.ts +8 -0
  66. package/dist/core/impl-reader.js +39 -0
  67. package/dist/core/impl-reader.js.map +1 -0
  68. package/dist/core/language.d.ts +39 -0
  69. package/dist/core/language.js +159 -0
  70. package/dist/core/language.js.map +1 -0
  71. package/dist/core/markdown-parser.d.ts +3 -0
  72. package/dist/core/markdown-parser.js +37 -0
  73. package/dist/core/markdown-parser.js.map +1 -0
  74. package/dist/core/reporter.d.ts +3 -0
  75. package/dist/core/reporter.js +33 -0
  76. package/dist/core/reporter.js.map +1 -0
  77. package/dist/templates/index.d.ts +4 -0
  78. package/dist/templates/index.js +126 -0
  79. package/dist/templates/index.js.map +1 -0
  80. package/dist/validators/format-rules.d.ts +10 -0
  81. package/dist/validators/format-rules.js +238 -0
  82. package/dist/validators/format-rules.js.map +1 -0
  83. package/dist/validators/structure-rules.d.ts +10 -0
  84. package/dist/validators/structure-rules.js +94 -0
  85. package/dist/validators/structure-rules.js.map +1 -0
  86. package/dist/validators/types.d.ts +68 -0
  87. package/dist/validators/types.js +2 -0
  88. package/dist/validators/types.js.map +1 -0
  89. package/docs/agents.md +88 -0
  90. package/docs/architecture.md +53 -0
  91. package/docs/cli.md +226 -0
  92. package/docs/concepts.md +268 -0
  93. package/docs/configuration.md +255 -0
  94. package/docs/demo.svg +111 -0
  95. package/docs/patterns.md +118 -0
  96. package/docs/security.md +95 -0
  97. package/docs/workflows.md +151 -0
  98. package/languages/de.json +20 -0
  99. package/languages/en.json +20 -0
  100. package/languages/es.json +20 -0
  101. package/languages/fr.json +20 -0
  102. package/languages/ja.json +20 -0
  103. package/languages/pt.json +20 -0
  104. package/package.json +54 -0
  105. package/skills/analyse-change.md +101 -0
  106. package/skills/behaviour.md +179 -0
  107. package/skills/bug.md +70 -0
  108. package/skills/commit.md +99 -0
  109. package/skills/decompose.md +101 -0
  110. package/skills/discover.md +392 -0
  111. package/skills/grill-me.md +65 -0
  112. package/skills/guide.md +118 -0
  113. package/skills/implement.md +149 -0
  114. package/skills/ineed.md +147 -0
  115. package/skills/intent.md +104 -0
  116. package/skills/plan.md +63 -0
  117. package/skills/promote.md +69 -0
  118. package/skills/refine.md +78 -0
  119. package/skills/research.md +122 -0
  120. package/skills/review-all.md +92 -0
  121. package/skills/review.md +80 -0
  122. package/skills/status.md +103 -0
  123. package/skills/sweep.md +89 -0
  124. package/skills/trace.md +151 -0
package/skills/bug.md ADDED
@@ -0,0 +1,70 @@
1
+ # Skill: bug
2
+
3
+ ## Description
4
+
5
+ Diagnose a defect through structured root cause analysis (5-Why) and delegate to the right fix skill. Invoked directly with a symptom, or handed off from `/tr-ineed` when bug-shaped language is detected.
6
+
7
+ ## Inputs
8
+
9
+ - `symptom` (required): Description of the observed defect — what happened, what was expected, reproduction steps if known.
10
+ - `handoff` (optional): Set to `true` when called by `/tr-ineed` — skips reproduction confirmation.
11
+
12
+ ## Steps
13
+
14
+ 1. **Check for hand-off.** If `handoff` is `true` (invoked from `/tr-ineed`), skip to step 3. Otherwise, proceed to step 2.
15
+
16
+ 2. **Confirm reproducibility.** Ask the actor: "Can you reproduce this consistently? If so, what are the minimal steps?" If the actor cannot reproduce it after clarification (environment details, inputs, frequency, logs), suspend with: "Cannot confirm reproduction — add a failing test case and re-run `/tr-bug` once it's consistent." Stop.
17
+
18
+ 3. **5-Why root cause dialogue.** Ask one "Why?" at a time, building on each answer:
19
+
20
+ - "Why did this happen?" → actor identifies the immediate cause
21
+ - "Why did that happen?" → second-order cause
22
+ - Continue until a root cause category can be assigned — **stop as soon as the category is clear.** Do not ask beyond category identification.
23
+ - If no category is clear after 5 iterations, ask directly: "Which of these best describes the root cause: (a) implementation gap — code doesn't match spec, (b) spec gap — spec doesn't cover this case, (c) missing test — behaviour works but has no regression test, (d) external cause — outside the codebase?"
24
+
25
+ > 💡 Git history is a useful shortcut: `git log --oneline -- <file>` or `git bisect` can answer "when did this start breaking?" and short-circuit the dialogue for suspected regressions. Suggest this before lengthy analysis.
26
+
27
+ 4. **Classify the root cause.** Assign one category:
28
+ - **Implementation gap** — code does not match spec
29
+ - **Spec gap** — spec does not cover this scenario
30
+ - **Missing test** — behaviour works but has no test catching this regression
31
+ - **External cause** — dependency, environment, or configuration outside the hierarchy
32
+ - If categories overlap, use this priority: **Spec gap > Implementation gap > Missing test**
33
+
34
+ 5. **Locate the implicated artifact.** Use reverse lookup:
35
+ - Scan all `impl.md` files in `taproot/` for `## Source Files` entries matching the files involved in the root cause
36
+ - If a match is found: that impl.md is implicated
37
+ - If no match: read `taproot/OVERVIEW.md` to identify the closest matching behaviour, then ask the actor: "Is `<path>` the right impl to target?"
38
+ - If the failing behaviour has no impl.md or usecase.md at all: "This behaviour isn't in the hierarchy yet." Delegate to `/tr-ineed` to place it, then return to step 6.
39
+
40
+ 6. **Propose fix approach.** Present a concrete fix hypothesis matched to the root cause type. Ask: "Does this fix approach look right?" Wait for confirmation.
41
+
42
+ 7. **Delegate.**
43
+ - **Spec gap** → `/tr-refine <usecase-path>`
44
+ - **Implementation gap** or **Missing test** →
45
+ - If the impl.md state is `complete`: present — "I'll mark `<impl-path>` as `needs-rework` before proceeding. Confirm?" — update `**State:**` to `needs-rework` on confirmation
46
+ - Then: `/tr-implement <impl-path>`
47
+ - **Multiple root causes** (two independent causes found): list both, ask "Which should we fix first?", note the deferred one in the impl.md, proceed with the chosen one
48
+ - **External cause**: present proposed note ("I'll add this finding to `<impl-path>` ## Notes: [text]"), wait for confirmation, write on confirm
49
+
50
+ > 💡 If this session is getting long, consider running `/compact` or starting a fresh context before the next task.
51
+
52
+ **What's next?**
53
+ Delegated to `/tr-refine` or `/tr-implement` above.
54
+
55
+ ## Output
56
+
57
+ - Root cause identified and classified
58
+ - Implicated impl.md or usecase.md named
59
+ - Fix approach confirmed by actor
60
+ - Delegated to `/tr-implement` or `/tr-refine`
61
+
62
+ ## CLI Dependencies
63
+
64
+ - `taproot overview` (for OVERVIEW.md fallback in step 5)
65
+
66
+ ## Notes
67
+
68
+ - The 5-Why is a dialogue, not an interrogation. Stop asking as soon as the category is clear — over-asking produces over-engineered root causes.
69
+ - When the root cause is a spec gap, fix the spec first before touching code. Implementing against a wrong spec produces wrong code.
70
+ - tr-ineed hand-off: `/tr-ineed` should detect bug-shaped language ("it's broken", "wrong output", "this crashes") and call `/tr-bug` with `handoff: true`. Until tr-ineed is updated, actors invoke `/tr-bug` directly.
@@ -0,0 +1,99 @@
1
+ # Skill: commit
2
+
3
+ ## Description
4
+
5
+ Execute the full commit procedure: classify the commit type, run the appropriate gate proactively, resolve all conditions before staging, and commit. Handles implementation, declaration, requirement, and plain commits. Invoke this skill whenever you are about to commit, or when the user says "commit", "let's commit", "commit that", or similar.
6
+
7
+ ## Inputs
8
+
9
+ - None required. The skill reads `git status` to determine what is staged or changed.
10
+
11
+ ## Steps
12
+
13
+ 1. Run `git status` to identify all staged and unstaged changes in scope. If nothing is staged and nothing has changed, report "Nothing to commit — working tree is clean." and stop.
14
+
15
+ 2. Classify the commit type based on what is staged (or will be staged):
16
+ - **Implementation commit** — staged files include source files tracked by an `impl.md`
17
+ - **Declaration commit** — staged files include a new `impl.md` only (no matched source files)
18
+ - **Requirement commit** — staged files include `taproot/` hierarchy files only (`intent.md`, `usecase.md`)
19
+ - **Plain commit** — none of the above
20
+
21
+ To identify impl.md ownership, run `grep -rl "<filename>" taproot/` for each candidate source file.
22
+
23
+ 3. If nothing is staged yet, announce: "Nothing staged yet. Here's what's changed: [list]. Should I stage these and proceed with the commit?" Wait for confirmation before proceeding.
24
+
25
+ 4. Read `.taproot/settings.yaml` to identify all configured `definitionOfDone` and `definitionOfReady` conditions. If the file does not exist or has no `definitionOfDone`/`definitionOfReady` sections, note: "No user-configured conditions — baseline hook checks only." and proceed to the appropriate sub-flow below.
26
+
27
+ 5. Execute the sub-flow matching the commit type:
28
+
29
+ ### Implementation commit
30
+
31
+ 1. Count how many `impl.md` files require DoD resolution. If N > 3, announce: "This commit affects N impl.md files — resolving DoD for each will be significant work." List all affected paths and offer:
32
+ - **[A] Proceed systematically** — resolve one impl.md at a time with progress updates
33
+ - **[B] Split the commit** — stage only one impl.md's source files now, defer the rest
34
+ - **[C] Show me what conditions need resolving** — run `taproot dod` on each and report before deciding
35
+
36
+ Wait for the user's choice before proceeding.
37
+
38
+ 2. For each `impl.md` that owns a staged source file:
39
+ a. Run `taproot dod <impl-path>` and review the output
40
+ b. For each `✗` condition marked "Agent check required": read the referenced spec, reason through compliance, then run:
41
+ ```
42
+ taproot dod <impl-path> --resolve "<exact-condition-name>" --note "<reasoning>"
43
+ ```
44
+ **One condition per invocation.** Do not pass multiple `--resolve` flags.
45
+ c. Re-run `taproot dod <impl-path>` after each resolution to check remaining failures
46
+ d. Repeat until all conditions pass. If a condition remains `✗` after its `--resolve` invocation, stop immediately: "Cannot resolve `<condition>` — it requires: `<correction hint>`." Wait for the user to intervene.
47
+
48
+ 3. If a `check:` condition requires action you cannot take (e.g. failing tests), report: "Cannot commit — `<condition>` is unresolved and requires: `<correction hint>`." Stop and wait.
49
+
50
+ 4. Stage source files + all matched impl.md files and commit with a concise one-line message.
51
+
52
+ ### Declaration commit
53
+
54
+ 1. Verify parent `usecase.md` is in `specified`, `implemented`, or `complete` state. If it is in `draft` or `proposed` state, report: "Cannot declare implementation — parent `usecase.md` is in `<state>` state. Run `/tr-refine <usecase-path>` to complete the spec first." Stop.
55
+
56
+ 2. Read `.taproot/settings.yaml` `definitionOfReady` entries. For each `check-if-affected-by` or `check:` condition, write an entry directly into `## DoR Resolutions` in the impl.md. There is no `taproot dor` CLI — write entries by hand:
57
+ ```
58
+ condition: <name> | note: <reasoning> | resolved: <date>
59
+ ```
60
+
61
+ 3. Stage the new impl.md and commit.
62
+
63
+ ### Requirement commit
64
+
65
+ 1. Run `taproot validate-format --path <path>` and `taproot validate-structure`. Fix any errors before proceeding.
66
+
67
+ 2. For each staged `intent.md`, verify:
68
+ - `## Goal` starts with a verb (e.g. "Enable", "Allow", "Ensure", "Provide")
69
+ - Goal does not name implementation technology (REST, SQL, API, PostgreSQL, etc.)
70
+ - `## Stakeholders` section is present and non-empty
71
+ - `## Success Criteria` section is present with at least one measurable criterion
72
+
73
+ 3. For each staged `usecase.md`, verify:
74
+ - `## Acceptance Criteria` is present with at least one `**AC-1:**` Given/When/Then entry
75
+ - `## Actor` names a human, external system, or service — not an implementation mechanism
76
+ - `## Postconditions` is present and non-empty
77
+
78
+ 4. Fix any violations before staging — the hook enforces these checks and will block the commit if they fail.
79
+
80
+ 5. Stage the hierarchy files and commit.
81
+
82
+ ### Plain commit
83
+
84
+ 1. Stage source files and commit — no taproot gate runs.
85
+
86
+ ---
87
+
88
+ 6. After committing, run `taproot link-commits --path <taproot-root>` if any impl.md files were staged, to update their `## Commits` sections.
89
+
90
+ ## Output
91
+
92
+ A clean commit where the pre-commit hook passes on the first attempt. All conditions resolved with written rationale before staging.
93
+
94
+ ## CLI Dependencies
95
+
96
+ - `taproot dod`
97
+ - `taproot validate-format`
98
+ - `taproot validate-structure`
99
+ - `taproot link-commits`
@@ -0,0 +1,101 @@
1
+ # Skill: decompose
2
+
3
+ ## Description
4
+
5
+ Break an intent down into the set of behaviours (UseCases) needed to fulfill it. Produces a proposed behaviour list tied to each success criterion, then creates the approved `usecase.md` files.
6
+
7
+ ## Inputs
8
+
9
+ - `path` (required): Path to the intent folder containing `intent.md`.
10
+
11
+ ## Steps
12
+
13
+ 1. Read `<path>/intent.md`. Understand:
14
+ - The goal statement
15
+ - Each success criterion (these are the primary drivers of decomposition)
16
+ - Constraints
17
+ - Any existing notes about expected scope
18
+
19
+ 2. Read any existing behaviour folders under `<path>/`. Note what is already specified to avoid duplicating it.
20
+
21
+ 3. For each success criterion, ask: "What observable system behaviour, when implemented and working, would satisfy this criterion?" Generate candidate behaviours bottom-up from criteria.
22
+
23
+ 4. Add behaviours top-down from the goal: what interaction sequences does an actor need to complete in order for the goal to be considered achieved?
24
+
25
+ 5. Cross-check: for every candidate behaviour, identify which success criterion it serves. If a behaviour doesn't serve any criterion, it is gold-plating — flag it. If a criterion has no behaviour, it is a gap — flag it.
26
+
27
+ 6. Identify dependencies between candidate behaviours (e.g., "verify-email must exist before choose-plan is reachable").
28
+
29
+ 7. Present the proposed decomposition to the user:
30
+
31
+ ```
32
+ Proposed behaviours for: <intent-title>
33
+
34
+ 1. register-account
35
+ → Satisfies: "Users can create an account with email and password"
36
+ → Actor: New user
37
+ → Depends on: none
38
+
39
+ 2. verify-email
40
+ → Satisfies: "Email verification is required before access"
41
+ → Actor: System (async), then User (clicking link)
42
+ → Depends on: register-account
43
+
44
+ 3. choose-plan
45
+ → Satisfies: "Users select a subscription plan before access"
46
+ → Actor: User after email verification
47
+ → Depends on: verify-email
48
+
49
+ Gap: Success criterion "Support <5 second load time" has no behaviour —
50
+ this is a non-functional requirement. Recommend adding it as a constraint
51
+ rather than a behaviour, or creating a behaviour for a specific slow operation.
52
+ ```
53
+
54
+ 8. Ask: "Which of these should I create? You can say 'all', list specific numbers, or say 'none' to just use this as a planning reference."
55
+
56
+ 9. For each approved behaviour, present a preview of the proposed `usecase.md` before delegating:
57
+
58
+ ```
59
+ Proposed: taproot/<intent-slug>/<behaviour-slug>/usecase.md — <behaviour name>
60
+
61
+ Actor: <actor>
62
+ Satisfies: <success criterion>
63
+ Depends on: <dependency or "none">
64
+
65
+ [Y] Create it [E] Edit description before creating [S] Skip [Q] Quit
66
+
67
+ ```
68
+
69
+ - **[Y]**: run `/taproot:behaviour <path> "<description>"` to create the `usecase.md`
70
+ - **[E]**: apply corrections to the description, re-present the preview, then create on next [Y]
71
+ - **[S]**: skip — note "Skipped `taproot/<intent-slug>/<behaviour-slug>/`" and move to the next
72
+ - **[Q]**: stop immediately; list what was created, skipped, and remaining
73
+
74
+ If the user says "just go" or "do all", acknowledge once and create the remaining behaviours without pausing.
75
+
76
+ 10. After all approved behaviours are created, run `taproot validate-structure --path <taproot-root>`.
77
+
78
+ 11. Run `taproot coverage --path <path>` to show the new state.
79
+
80
+ 12. Present next steps:
81
+
82
+ > 💡 If this session is getting long, consider running `/compact` or starting a fresh context before the next task.
83
+
84
+ **What's next?**
85
+ [A] `/tr-implement taproot/<intent-slug>/<first-behaviour-slug>/` — start building the first behaviour
86
+ [B] `/tr-review taproot/<intent-slug>/<behaviour-slug>/usecase.md` — stress-test a behaviour spec first
87
+
88
+ ## Output
89
+
90
+ A proposed list of behaviours with criterion traceability, then `usecase.md` files for each approved behaviour.
91
+
92
+ ## CLI Dependencies
93
+
94
+ - `taproot validate-structure`
95
+ - `taproot coverage`
96
+
97
+ ## Notes
98
+
99
+ - Target 3–7 behaviours per intent. Fewer may mean the intent is actually just one behaviour; more may mean the intent is too broad and should be split.
100
+ - Non-functional requirements (performance, security, availability) should generally be expressed as constraints in the intent, not as behaviours — unless there is a specific actor interaction that enforces them (e.g., "rate-limit login attempts" is a behaviour; "system must handle 10,000 concurrent users" is a constraint).
101
+ - If the intent has sub-intents (other `intent.md` folders nested under it), handle those first — their behaviours may overlap with what this decomposition would propose.
@@ -0,0 +1,392 @@
1
+ # Skill: discover
2
+
3
+ ## Description
4
+
5
+ Reverse-engineer an existing project into a taproot hierarchy — from source code, existing requirements artifacts (PRDs, stories, ADRs), or both. Interviews the user to surface business intents and behaviours. Heavily interactive.
6
+
7
+ ## Inputs
8
+
9
+ - `scope` (optional): A subdirectory or area to focus discovery on. Defaults to the whole project.
10
+ - `depth` (optional): `intents-only` (stop after intent documents), `behaviours` (intent + usecase), `full` (intent + usecase + impl). Defaults to `full`.
11
+
12
+ ## Steps
13
+
14
+ ### Phase 0 — Check for Existing Session
15
+
16
+ 1. Before doing anything else, check for `.taproot/sessions/discovery-status.md`.
17
+
18
+ - **If found**: read it and present a resume prompt:
19
+ > "I found an in-progress discovery session (last updated: [date], phase: [phase]).
20
+ >
21
+ > - **Resume** from where we left off
22
+ > - **Restart** from the beginning (status file will be overwritten)
23
+ > - **Abandon** without changes"
24
+
25
+ If resuming: skip to the phase indicated in the status file, treating all items marked `[x]` as already complete. Re-read the Notes section for context carried from the prior session.
26
+
27
+ - **If not found**: create it now with Phase set to `0.5` and proceed.
28
+
29
+ Save the status file after every confirmed intent, behaviour, and implementation — not just at the end.
30
+
31
+ **Stopping early:** at any point the user can say "stop" or "pause". Before ending the session, update the status file with the current phase and progress, then write a session summary:
32
+ ```
33
+ Session ended.
34
+ Written (<n>): <list of written paths>
35
+ Skipped (<n>): <list of skipped paths>
36
+ Remaining (<n>): <list of remaining paths not yet reached>
37
+ Resume: run /tr-discover and choose Resume.
38
+ ```
39
+
40
+ **Auto-proceed:** if the user says "just go", "do all", or invokes with `--auto`, acknowledge once ("Auto-proceeding through remaining items — say 'stop' at any time to pause.") then write all remaining documents without pausing for confirmation. Still report each path as it is written. At the end, show the same completion summary.
41
+
42
+ ### Phase 0.5 — Detect Requirements Artifacts
43
+
44
+ 2. Scan the project for existing requirements artifacts using naming heuristics. Look for folders or files whose names suggest structured requirements — including but not limited to: `prd`, `requirements`, `specs`, `stories`, `epics`, `architecture`, `adr`, `design`, `rfcs`, `briefs`, `tickets`. Apply common-sense filtering: `requirements.txt` (Python deps), image files, and folders whose contents are test spec files (e.g. Jest/Mocha `.spec.ts`) are not requirements artifacts.
45
+
46
+ If candidates are found:
47
+ - Read them to understand their structure and content
48
+ - If the format or originating tool is unfamiliar, research it (web search or README inspection) before drawing conclusions
49
+ - Record what was found in the status file Notes section
50
+
51
+ 3. Based on what was found, ask the developer how to proceed — **but only if there is something to ask**:
52
+
53
+ - **No artifacts found, source code present**: proceed silently to Phase 1 — no prompt needed
54
+ - **Artifacts found, no source code**:
55
+ > "I found what looks like requirements in `<path>` — [brief description of structure, e.g. 'stories organised by epic' or 'a single PRD markdown file']. No source code detected.
56
+ >
57
+ > Should I import these as specified behaviours? (They'll be marked `status: specified` with no implementation records until code exists.)
58
+ >
59
+ > [Y] Import as specs [N] Cancel"
60
+ - **Both source code and requirements artifacts found**:
61
+ > "I found source code and requirements in `<path>` — [brief description]. If they conflict, which takes precedence?
62
+ >
63
+ > [S] Source wins — requirements are hints only; source is authoritative
64
+ > [R] Requirements win — requirements are the spec; source fills in the impl
65
+ > [C] Case-by-case — ask me each time there's a conflict"
66
+
67
+ Record the developer's choice in the status file. This choice applies for the entire session.
68
+
69
+ ### Phase 1 — Orient
70
+
71
+ 4. Read the project root for orientation materials in this order (skip if not found):
72
+ - `README.md` / `README.rst` / `README.txt`
73
+ - `package.json`, `Cargo.toml`, `pyproject.toml`, `go.mod`, or other manifest files (name + description + scripts)
74
+ - `ARCHITECTURE.md`, `DESIGN.md`, `docs/` directory listing
75
+ - Existing `taproot/` directory (note any intents already documented to avoid duplication)
76
+ - Any requirements artifacts found in Phase 0.5 — use these as supplementary context for intent hypotheses
77
+
78
+ 5. Scan the top-level structure: list directories, identify entry points (`main.*`, `index.*`, `cli.*`, `server.*`, `app.*`), note the primary language and framework.
79
+
80
+ 6. Present a one-paragraph orientation to the user:
81
+ > "I can see this is a [language/framework] project that [what it does based on README/manifest/requirements]. Before I propose any structure, I want to make sure I understand the **business goals** rather than the technical structure. The folder layout reflects how it was built, not why — and those are often different things."
82
+
83
+ Then ask the first discovery question:
84
+ > "In one or two sentences: what problem does this software solve, and who uses it?"
85
+
86
+ Wait for the user's answer before continuing.
87
+
88
+ ### Phase 2 — Surface Intents (interactive, one at a time)
89
+
90
+ 7. Based on the user's answer, the codebase scan, and any requirements artifacts, form a hypothesis about the top-level business intents. An intent is a **business goal** — not a module, not a command, not a feature flag. Good intents start with verbs: "Enable users to…", "Allow operators to…", "Provide developers with…".
91
+
92
+ Common traps to avoid:
93
+ - Don't create an intent per CLI command (those are often all part of one intent)
94
+ - Don't create an intent per file or module (technical decomposition ≠ business intent)
95
+ - Don't create an intent for infrastructure concerns (logging, config loading) unless they are externally visible
96
+ - Don't trust requirements artifacts blindly — validate against source code (or ask the developer) before writing
97
+
98
+ 8. For each hypothesised intent (present them one at a time, not all at once):
99
+
100
+ a. State the candidate intent:
101
+ > "I think one intent might be: **[goal statement]**. This would cover [what code/features/requirements I think belong here]."
102
+
103
+ b. Ask a probing question about it — pick the most relevant one:
104
+ - "Is this something users directly ask for, or is it a means to an end for a larger goal?"
105
+ - "Who is the primary stakeholder for this — an end user, an operator, or a developer integrating this tool?"
106
+ - "If this intent was removed from the product, who would notice and what would they lose?"
107
+ - "Is [A] and [B] really one intent, or do they serve different stakeholders with different success criteria?"
108
+ - "What does success look like for this intent — how would you know it's working well?"
109
+
110
+ c. Refine based on the user's answer. Accept, split, merge, or discard the intent. Only proceed to document confirmed intents.
111
+
112
+ d. For each confirmed intent, determine:
113
+ - `slug`: kebab-case identifier
114
+ - `title`: human-readable title
115
+ - `goal`: one sentence, starts with a verb
116
+ - `stakeholders`: who cares about this (with their perspective)
117
+ - `success criteria`: 1–3 measurable outcomes
118
+ - `constraints`: known limitations, non-goals, or boundaries
119
+ - `status`: `active`
120
+
121
+ e. Present the proposed `intent.md` to the user before writing:
122
+
123
+ ```
124
+ Proposed: taproot/<slug>/intent.md — <title>
125
+
126
+ <full proposed content>
127
+
128
+ [Y] Write it [E] Edit before writing [S] Skip [Q] Quit session
129
+ ```
130
+
131
+ - **[Y]**: write the file, report the path written, proceed to the next intent
132
+ - **[E]**: apply the developer's corrections, re-present the updated proposal with the same menu
133
+ - **[S]**: skip — do not write; note "Skipped `taproot/<slug>/intent.md`" and move on
134
+ - **[Q]**: stop the session immediately and write the session summary (see Phase 0)
135
+
136
+ f. Update `.taproot/sessions/discovery-status.md`: mark this intent `[x]` in Phase 2, set Phase to `2`, update Last updated.
137
+
138
+ 9. After all intents are confirmed and written, show a summary:
139
+ > "Confirmed [N] intents: [list]. Do any of these feel wrong, or is there a significant area of the system we haven't covered?"
140
+
141
+ Incorporate any corrections before moving to Phase 3. Update status file: set Phase to `3`.
142
+
143
+ ### Phase 3 — Discover Behaviours (per intent, interactive)
144
+
145
+ *Skip this phase if `depth` is `intents-only`.*
146
+
147
+ 10. For each confirmed intent, work through it one at a time:
148
+
149
+ a. Read the relevant source files and/or requirements artifacts — identify the entry points, public APIs, user-facing interactions, or specified requirements that belong to this intent.
150
+
151
+ b. Propose use cases — observable system behaviours from the actor's perspective. A use case is a specific interaction with a clear trigger, flow, and outcome. Name them from the actor's perspective: "User resets password", not "Password reset endpoint".
152
+
153
+ When both source and requirements are present and conflict:
154
+ - If **source wins**: derive the behaviour from code; note in the usecase if the requirements described something different
155
+ - If **requirements win**: derive the behaviour from the requirements; note in the usecase if the source diverges
156
+ - If **case-by-case**: surface the conflict to the developer before proposing the behaviour
157
+
158
+ c. For each proposed use case, ask:
159
+ - "Does this behaviour have any important alternate flows or error conditions I should know about?"
160
+ - "Is this one behaviour or two? [e.g., if the happy path and the error recovery feel like distinct things]"
161
+
162
+ d. Confirm the use case structure with the user, then determine:
163
+ - `actor`: who initiates this (User, Operator, System, External service)
164
+ - `preconditions`: what must be true before this can happen
165
+ - `main flow`: numbered steps describing what happens
166
+ - `alternate flows`: edge cases handled
167
+ - `error conditions`: how the system responds to failures
168
+ - `postconditions`: what's true after the flow completes
169
+
170
+ e. Present the proposed `usecase.md` to the user before writing:
171
+
172
+ ```
173
+ Proposed: taproot/<intent-slug>/<behaviour-slug>/usecase.md — <behaviour name>
174
+
175
+ <full proposed content>
176
+
177
+ [Y] Write it [E] Edit before writing [S] Skip [Q] Quit session
178
+ ```
179
+
180
+ Apply Y/E/S/Q as described in step 8e above.
181
+
182
+ f. Update status file: mark this behaviour `[x]` under its intent in Phase 3, update Last updated.
183
+
184
+ 11. After all behaviours for an intent are written:
185
+ > "I've documented [N] behaviours for [intent]. Anything missing — behaviours the code or requirements describe that we didn't capture?"
186
+
187
+ ### Phase 4 — Link Implementations (per behaviour)
188
+
189
+ *Skip this phase if `depth` is `intents-only` or `behaviours`.*
190
+ *Skip this phase entirely if operating in requirements-only mode (no source code found in Phase 0.5).*
191
+
192
+ 12. For each confirmed behaviour, identify the implementation:
193
+
194
+ a. Find the source files that implement it — be specific, not just the module.
195
+
196
+ b. Find relevant tests — look for test files that exercise this behaviour's main flow, alternate flows, and error conditions.
197
+
198
+ c. Identify any relevant commits if git history is available: `git log --oneline -- <relevant files> | head -20`
199
+
200
+ d. Ask the user one question before writing:
201
+ > "Is the implementation of [behaviour] complete and tested, or are there known gaps?"
202
+
203
+ If there are gaps, note them in the `impl.md` Notes section and set Status to `in-progress`. Otherwise `complete`.
204
+
205
+ e. Determine the implementation slug (derive from the primary approach: `rest-api`, `cli`, `background-job`, `library`, etc.).
206
+
207
+ f. Present the proposed `impl.md` to the user before writing:
208
+
209
+ ```
210
+ Proposed: taproot/<intent-slug>/<behaviour-slug>/<impl-slug>/impl.md — <behaviour name>
211
+
212
+ <full proposed content>
213
+
214
+ [Y] Write it [E] Edit before writing [S] Skip [Q] Quit session
215
+ ```
216
+
217
+ Apply Y/E/S/Q as described in step 8e above.
218
+
219
+ g. Update status file: mark this impl `[x]` under its behaviour in Phase 4, update Last updated.
220
+
221
+ 13. After each intent's implementations are written, run:
222
+ ```
223
+ taproot validate-structure
224
+ taproot validate-format
225
+ ```
226
+ Fix any validation errors before moving to the next intent. Update status file: set Phase to `4` when starting this phase.
227
+
228
+ ### Phase 5 — Wrap Up
229
+
230
+ 14. Run `taproot coverage` and present the results.
231
+
232
+ 15. Run `taproot check-orphans` to verify nothing is structurally broken.
233
+
234
+ 16. Update status file: set Phase to `complete`, update Last updated.
235
+
236
+ 17. Present a closing summary:
237
+ > "Discovery complete. Documented [N] intents, [N] behaviours, [N] implementations."
238
+ > *(If requirements-only: "Documented [N] intents, [N] behaviours — marked `specified`, ready for implementation.")*
239
+
240
+ > 💡 If this session is getting long, consider running `/compact` or starting a fresh context before the next task.
241
+
242
+ **What's next?**
243
+ [A] `/tr-status` — see coverage gaps and health report
244
+ [B] `/tr-plan` — surface the next behaviour to implement
245
+ [C] `/tr-ineed` — capture requirements that surfaced during discovery but weren't formalised
246
+
247
+ ## Output
248
+
249
+ - `.taproot/sessions/discovery-status.md` — session state, updated continuously
250
+ - `taproot/<intent-slug>/intent.md` for each confirmed intent
251
+ - `taproot/<intent-slug>/<behaviour-slug>/usecase.md` for each confirmed behaviour
252
+ - Marked `status: specified` when derived from requirements with no source code
253
+ - Marked `status: implemented` when source code exists and impl.md is written
254
+ - `taproot/<intent-slug>/<behaviour-slug>/<impl-slug>/impl.md` for each implementation (skipped in requirements-only mode)
255
+
256
+ ## CLI Dependencies
257
+
258
+ - `taproot validate-structure`
259
+ - `taproot validate-format`
260
+ - `taproot coverage`
261
+ - `taproot check-orphans`
262
+
263
+ ## Document Formats
264
+
265
+ ### discovery-status.md
266
+
267
+ ```markdown
268
+ # Discovery Status
269
+
270
+ <!-- Managed by /tr-discover — do not edit Phase 2/3/4 checklists manually -->
271
+
272
+ ## Session
273
+ - **Started:** <YYYY-MM-DD>
274
+ - **Last updated:** <YYYY-MM-DD>
275
+ - **Phase:** 0.5 | 1 | 2 | 3 | 4 | 5 | complete
276
+ - **Scope:** whole project | <subdirectory>
277
+ - **Depth:** full | behaviours | intents-only
278
+ - **Conflict resolution:** source-wins | requirements-win | case-by-case | not-applicable
279
+
280
+ ## Notes
281
+ <!-- Free-form context to carry between sessions: key decisions, open questions, things to revisit -->
282
+ <!-- Also records: what requirements artifacts were found and what tool/format they use -->
283
+
284
+ ## Phase 2 — Intents
285
+ <!-- [x] = intent.md written; [ ] = proposed but not yet confirmed -->
286
+
287
+ ## Phase 3 — Behaviours
288
+ <!-- One subsection per intent; [x] = usecase.md written -->
289
+
290
+ ## Phase 4 — Implementations
291
+ <!-- One subsection per intent/behaviour path; [x] = impl.md written -->
292
+ ```
293
+
294
+ ### intent.md
295
+
296
+ ```markdown
297
+ # Intent: <Title>
298
+
299
+ ## Goal
300
+ <One sentence starting with a verb. What business outcome does this enable?>
301
+
302
+ ## Stakeholders
303
+ - **<Role>**: <their perspective and what they gain>
304
+
305
+ ## Success Criteria
306
+ - <Measurable outcome — observable, not technical>
307
+
308
+ ## Constraints
309
+ - <Known non-goals, boundaries, or limitations>
310
+
311
+ ## Status
312
+ - **State:** active
313
+ - **Created:** <YYYY-MM-DD>
314
+ ```
315
+
316
+ ### usecase.md
317
+
318
+ ```markdown
319
+ # UseCase: <Title>
320
+
321
+ ## Actor
322
+ <Who initiates this interaction>
323
+
324
+ ## Preconditions
325
+ - <What must be true before this can happen>
326
+
327
+ ## Main Flow
328
+ 1. <Step — from the actor's perspective>
329
+ 2. <Step>
330
+
331
+ ## Alternate Flows
332
+ - **<Trigger>**: <what happens instead>
333
+
334
+ ## Error Conditions
335
+ - **<Error>**: <how the system responds>
336
+
337
+ ## Postconditions
338
+ - <What is true after the flow completes>
339
+
340
+ ## Diagram
341
+ <!-- Optional: add a Mermaid diagram for complex flows. Omit if the prose is clear enough. -->
342
+ ```mermaid
343
+ sequenceDiagram
344
+ Actor->>System: <trigger>
345
+ System-->>Actor: <response>
346
+ ```
347
+
348
+ ## Status
349
+ - **State:** active | specified
350
+ - **Created:** <YYYY-MM-DD>
351
+ ```
352
+
353
+ ### impl.md
354
+
355
+ ```markdown
356
+ # Implementation: <Title>
357
+
358
+ ## Behaviour
359
+ ../usecase.md
360
+
361
+ ## Design Decisions
362
+ - <Non-obvious choice and why it was made>
363
+
364
+ ## Source Files
365
+ - `<path/to/file>` — <what this file does for this behaviour>
366
+
367
+ ## Commits
368
+ - (run `taproot link-commits` to populate)
369
+
370
+ ## Tests
371
+ - `<path/to/test>` — <which scenarios this covers>
372
+
373
+ ## Status
374
+ - **State:** complete | in-progress
375
+ - **Created:** <YYYY-MM-DD>
376
+ - **Last verified:** <YYYY-MM-DD>
377
+
378
+ ## Notes
379
+ <Known gaps, technical debt, or deferred error conditions>
380
+ ```
381
+
382
+ ## Notes
383
+
384
+ - Discovery is a conversation, not a scan. The code tells you *what* exists; requirements artifacts tell you *what was intended*; the user tells you *why* it matters. All three are inputs — only the user's confirmation produces output.
385
+ - Requirements artifacts are hints, not truth. They may be stale, aspirational, or simply wrong. Always validate against source code where it exists; surface discrepancies to the developer rather than silently resolving them.
386
+ - Resist the urge to map modules to intents 1:1. A single intent often spans many files; a single file often serves multiple intents.
387
+ - When unsure whether something deserves its own intent vs. being a behaviour under another intent, ask: "Would a non-technical stakeholder describe these as separate goals, or as one goal with multiple steps?"
388
+ - Existing code may have dead code, vestigial features, or undocumented behaviours. Ask the user before documenting anything that looks unused.
389
+ - If the project already has partial taproot coverage, read the existing docs first and only discover what's missing.
390
+ - Save the status file eagerly — after every write, not just at phase boundaries. A session interrupted mid-phase should resume at the last confirmed item, not the start of the phase.
391
+ - The Notes section of the status file is the memory of the session. Use it to capture decisions, open questions, and anything the user said that isn't captured in a document yet — including what requirements tool was found and how it structures its artifacts.
392
+ - Never hardcode knowledge of a specific requirements tool. If you encounter an unfamiliar format, read a sample, check the README, or do a web search — then reason from evidence.