@mindfoldhq/trellis 0.3.9 → 0.3.10-beta.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 (172) hide show
  1. package/dist/cli/index.js +2 -0
  2. package/dist/cli/index.js.map +1 -1
  3. package/dist/commands/init.d.ts +1 -0
  4. package/dist/commands/init.d.ts.map +1 -1
  5. package/dist/commands/init.js +203 -31
  6. package/dist/commands/init.js.map +1 -1
  7. package/dist/commands/update.d.ts.map +1 -1
  8. package/dist/commands/update.js +154 -6
  9. package/dist/commands/update.js.map +1 -1
  10. package/dist/configurators/workflow.d.ts +6 -2
  11. package/dist/configurators/workflow.d.ts.map +1 -1
  12. package/dist/configurators/workflow.js +88 -58
  13. package/dist/configurators/workflow.js.map +1 -1
  14. package/dist/migrations/index.d.ts +1 -0
  15. package/dist/migrations/index.d.ts.map +1 -1
  16. package/dist/migrations/index.js +2 -0
  17. package/dist/migrations/index.js.map +1 -1
  18. package/dist/migrations/manifests/0.4.0-beta.1.json +228 -0
  19. package/dist/templates/claude/agents/dispatch.md +1 -2
  20. package/dist/templates/claude/agents/implement.md +2 -3
  21. package/dist/templates/claude/commands/trellis/before-dev.md +29 -0
  22. package/dist/templates/claude/commands/trellis/check.md +25 -0
  23. package/dist/templates/claude/commands/trellis/create-command.md +2 -2
  24. package/dist/templates/claude/commands/trellis/onboard.md +13 -13
  25. package/dist/templates/claude/commands/trellis/parallel.md +1 -2
  26. package/dist/templates/claude/commands/trellis/record-session.md +1 -1
  27. package/dist/templates/claude/commands/trellis/start.md +8 -4
  28. package/dist/templates/claude/hooks/inject-subagent-context.py +21 -13
  29. package/dist/templates/claude/hooks/session-start.py +170 -2
  30. package/dist/templates/codex/skills/before-dev/SKILL.md +34 -0
  31. package/dist/templates/codex/skills/check/SKILL.md +30 -0
  32. package/dist/templates/codex/skills/create-command/SKILL.md +2 -2
  33. package/dist/templates/codex/skills/onboard/SKILL.md +11 -11
  34. package/dist/templates/codex/skills/record-session/SKILL.md +1 -1
  35. package/dist/templates/codex/skills/start/SKILL.md +8 -3
  36. package/dist/templates/cursor/commands/trellis-before-dev.md +29 -0
  37. package/dist/templates/cursor/commands/trellis-check.md +25 -0
  38. package/dist/templates/cursor/commands/trellis-create-command.md +2 -2
  39. package/dist/templates/cursor/commands/trellis-onboard.md +13 -13
  40. package/dist/templates/cursor/commands/trellis-record-session.md +1 -1
  41. package/dist/templates/cursor/commands/trellis-start.md +7 -16
  42. package/dist/templates/gemini/commands/trellis/before-dev.toml +33 -0
  43. package/dist/templates/gemini/commands/trellis/check.toml +29 -0
  44. package/dist/templates/gemini/commands/trellis/create-command.toml +2 -2
  45. package/dist/templates/gemini/commands/trellis/onboard.toml +2 -2
  46. package/dist/templates/gemini/commands/trellis/record-session.toml +1 -1
  47. package/dist/templates/gemini/commands/trellis/start.toml +9 -4
  48. package/dist/templates/iflow/agents/dispatch.md +1 -2
  49. package/dist/templates/iflow/agents/implement.md +2 -3
  50. package/dist/templates/iflow/commands/trellis/before-dev.md +29 -0
  51. package/dist/templates/iflow/commands/trellis/check.md +25 -0
  52. package/dist/templates/iflow/commands/trellis/create-command.md +2 -2
  53. package/dist/templates/iflow/commands/trellis/onboard.md +13 -13
  54. package/dist/templates/iflow/commands/trellis/parallel.md +1 -2
  55. package/dist/templates/iflow/commands/trellis/record-session.md +1 -1
  56. package/dist/templates/iflow/commands/trellis/start.md +8 -4
  57. package/dist/templates/iflow/hooks/inject-subagent-context.py +21 -13
  58. package/dist/templates/iflow/hooks/session-start.py +156 -1
  59. package/dist/templates/kilo/workflows/before-dev.md +29 -0
  60. package/dist/templates/kilo/workflows/check.md +25 -0
  61. package/dist/templates/kilo/workflows/create-command.md +2 -2
  62. package/dist/templates/kilo/workflows/onboard.md +13 -13
  63. package/dist/templates/kilo/workflows/parallel.md +1 -2
  64. package/dist/templates/kilo/workflows/record-session.md +1 -1
  65. package/dist/templates/kilo/workflows/start.md +8 -3
  66. package/dist/templates/kiro/skills/before-dev/SKILL.md +34 -0
  67. package/dist/templates/kiro/skills/check/SKILL.md +30 -0
  68. package/dist/templates/kiro/skills/create-command/SKILL.md +2 -2
  69. package/dist/templates/kiro/skills/onboard/SKILL.md +11 -11
  70. package/dist/templates/kiro/skills/record-session/SKILL.md +1 -1
  71. package/dist/templates/kiro/skills/start/SKILL.md +8 -3
  72. package/dist/templates/markdown/spec/backend/script-conventions.md +93 -0
  73. package/dist/templates/opencode/agents/dispatch.md +1 -2
  74. package/dist/templates/opencode/agents/implement.md +2 -2
  75. package/dist/templates/opencode/agents/research.md +1 -2
  76. package/dist/templates/opencode/commands/trellis/before-dev.md +29 -0
  77. package/dist/templates/opencode/commands/trellis/check.md +25 -0
  78. package/dist/templates/opencode/commands/trellis/create-command.md +2 -2
  79. package/dist/templates/opencode/commands/trellis/onboard.md +13 -13
  80. package/dist/templates/opencode/commands/trellis/parallel.md +1 -2
  81. package/dist/templates/opencode/commands/trellis/record-session.md +1 -1
  82. package/dist/templates/opencode/commands/trellis/start.md +8 -3
  83. package/dist/templates/opencode/plugin/inject-subagent-context.js +45 -18
  84. package/dist/templates/opencode/plugin/session-start.js +149 -1
  85. package/dist/templates/qoder/skills/before-dev/SKILL.md +34 -0
  86. package/dist/templates/qoder/skills/check/SKILL.md +30 -0
  87. package/dist/templates/qoder/skills/create-command/SKILL.md +2 -2
  88. package/dist/templates/qoder/skills/onboard/SKILL.md +13 -13
  89. package/dist/templates/qoder/skills/record-session/SKILL.md +1 -1
  90. package/dist/templates/qoder/skills/start/SKILL.md +8 -3
  91. package/dist/templates/trellis/config.yaml +20 -0
  92. package/dist/templates/trellis/index.d.ts +11 -0
  93. package/dist/templates/trellis/index.d.ts.map +1 -1
  94. package/dist/templates/trellis/index.js +22 -0
  95. package/dist/templates/trellis/index.js.map +1 -1
  96. package/dist/templates/trellis/scripts/add_session.py +52 -7
  97. package/dist/templates/trellis/scripts/common/cli_adapter.py +33 -45
  98. package/dist/templates/trellis/scripts/common/config.py +152 -0
  99. package/dist/templates/trellis/scripts/common/git.py +31 -0
  100. package/dist/templates/trellis/scripts/common/git_context.py +23 -586
  101. package/dist/templates/trellis/scripts/common/io.py +37 -0
  102. package/dist/templates/trellis/scripts/common/log.py +45 -0
  103. package/dist/templates/trellis/scripts/common/packages_context.py +233 -0
  104. package/dist/templates/trellis/scripts/common/paths.py +46 -0
  105. package/dist/templates/trellis/scripts/common/phase.py +50 -49
  106. package/dist/templates/trellis/scripts/common/registry.py +41 -72
  107. package/dist/templates/trellis/scripts/common/session_context.py +466 -0
  108. package/dist/templates/trellis/scripts/common/task_context.py +384 -0
  109. package/dist/templates/trellis/scripts/common/task_queue.py +27 -98
  110. package/dist/templates/trellis/scripts/common/task_store.py +534 -0
  111. package/dist/templates/trellis/scripts/common/task_utils.py +96 -6
  112. package/dist/templates/trellis/scripts/common/tasks.py +109 -0
  113. package/dist/templates/trellis/scripts/common/types.py +112 -0
  114. package/dist/templates/trellis/scripts/create_bootstrap.py +31 -26
  115. package/dist/templates/trellis/scripts/hooks/linear_sync.py +243 -0
  116. package/dist/templates/trellis/scripts/multi_agent/_bootstrap.py +17 -0
  117. package/dist/templates/trellis/scripts/multi_agent/cleanup.py +43 -48
  118. package/dist/templates/trellis/scripts/multi_agent/create_pr.py +336 -45
  119. package/dist/templates/trellis/scripts/multi_agent/plan.py +2 -26
  120. package/dist/templates/trellis/scripts/multi_agent/start.py +126 -57
  121. package/dist/templates/trellis/scripts/multi_agent/status.py +12 -753
  122. package/dist/templates/trellis/scripts/multi_agent/status_display.py +542 -0
  123. package/dist/templates/trellis/scripts/multi_agent/status_monitor.py +225 -0
  124. package/dist/templates/trellis/scripts/task.py +50 -975
  125. package/dist/templates/trellis/workflow.md +21 -34
  126. package/dist/types/migration.d.ts +3 -1
  127. package/dist/types/migration.d.ts.map +1 -1
  128. package/dist/utils/project-detector.d.ts +23 -0
  129. package/dist/utils/project-detector.d.ts.map +1 -1
  130. package/dist/utils/project-detector.js +364 -0
  131. package/dist/utils/project-detector.js.map +1 -1
  132. package/dist/utils/template-fetcher.d.ts +2 -2
  133. package/dist/utils/template-fetcher.d.ts.map +1 -1
  134. package/dist/utils/template-fetcher.js +5 -5
  135. package/dist/utils/template-fetcher.js.map +1 -1
  136. package/package.json +1 -1
  137. package/dist/templates/claude/commands/trellis/before-backend-dev.md +0 -13
  138. package/dist/templates/claude/commands/trellis/before-frontend-dev.md +0 -13
  139. package/dist/templates/claude/commands/trellis/check-backend.md +0 -13
  140. package/dist/templates/claude/commands/trellis/check-frontend.md +0 -13
  141. package/dist/templates/codex/skills/before-backend-dev/SKILL.md +0 -18
  142. package/dist/templates/codex/skills/before-frontend-dev/SKILL.md +0 -18
  143. package/dist/templates/codex/skills/check-backend/SKILL.md +0 -18
  144. package/dist/templates/codex/skills/check-frontend/SKILL.md +0 -18
  145. package/dist/templates/cursor/commands/trellis-before-backend-dev.md +0 -13
  146. package/dist/templates/cursor/commands/trellis-before-frontend-dev.md +0 -13
  147. package/dist/templates/cursor/commands/trellis-check-backend.md +0 -13
  148. package/dist/templates/cursor/commands/trellis-check-frontend.md +0 -13
  149. package/dist/templates/gemini/commands/trellis/before-backend-dev.toml +0 -17
  150. package/dist/templates/gemini/commands/trellis/before-frontend-dev.toml +0 -17
  151. package/dist/templates/gemini/commands/trellis/check-backend.toml +0 -17
  152. package/dist/templates/gemini/commands/trellis/check-frontend.toml +0 -17
  153. package/dist/templates/iflow/commands/trellis/before-backend-dev.md +0 -13
  154. package/dist/templates/iflow/commands/trellis/before-frontend-dev.md +0 -13
  155. package/dist/templates/iflow/commands/trellis/check-backend.md +0 -13
  156. package/dist/templates/iflow/commands/trellis/check-frontend.md +0 -13
  157. package/dist/templates/kilo/workflows/before-backend-dev.md +0 -13
  158. package/dist/templates/kilo/workflows/before-frontend-dev.md +0 -13
  159. package/dist/templates/kilo/workflows/check-backend.md +0 -13
  160. package/dist/templates/kilo/workflows/check-frontend.md +0 -13
  161. package/dist/templates/kiro/skills/before-backend-dev/SKILL.md +0 -18
  162. package/dist/templates/kiro/skills/before-frontend-dev/SKILL.md +0 -18
  163. package/dist/templates/kiro/skills/check-backend/SKILL.md +0 -18
  164. package/dist/templates/kiro/skills/check-frontend/SKILL.md +0 -18
  165. package/dist/templates/opencode/commands/trellis/before-backend-dev.md +0 -13
  166. package/dist/templates/opencode/commands/trellis/before-frontend-dev.md +0 -13
  167. package/dist/templates/opencode/commands/trellis/check-backend.md +0 -13
  168. package/dist/templates/opencode/commands/trellis/check-frontend.md +0 -13
  169. package/dist/templates/qoder/skills/before-backend-dev/SKILL.md +0 -18
  170. package/dist/templates/qoder/skills/before-frontend-dev/SKILL.md +0 -18
  171. package/dist/templates/qoder/skills/check-backend/SKILL.md +0 -18
  172. package/dist/templates/qoder/skills/check-frontend/SKILL.md +0 -18
@@ -126,13 +126,13 @@ AI needs the same onboarding - but compressed into seconds at session start.
126
126
 
127
127
  ---
128
128
 
129
- ### /trellis:before-frontend-dev and /trellis:before-backend-dev - Inject Specialized Knowledge
129
+ ### /trellis:before-dev - Inject Specialized Knowledge
130
130
 
131
131
  **WHY IT EXISTS**:
132
132
  AI models have "pre-trained knowledge" - general patterns from millions of codebases. But YOUR project has specific conventions that differ from generic patterns.
133
133
 
134
134
  **WHAT IT ACTUALLY DOES**:
135
- 1. Reads `.trellis/spec/frontend/` or `.trellis/spec/backend/`
135
+ 1. Discovers spec layers via `get_context.py --mode packages` and reads relevant guidelines
136
136
  2. Loads project-specific patterns into AI's working context:
137
137
  - Component naming conventions
138
138
  - State management patterns
@@ -140,12 +140,12 @@ AI models have "pre-trained knowledge" - general patterns from millions of codeb
140
140
  - Error handling standards
141
141
 
142
142
  **WHY THIS MATTERS**:
143
- - Without before-*-dev: AI writes generic code that doesn't match project style.
144
- - With before-*-dev: AI writes code that looks like the rest of the codebase.
143
+ - Without before-dev: AI writes generic code that doesn't match project style.
144
+ - With before-dev: AI writes code that looks like the rest of the codebase.
145
145
 
146
146
  ---
147
147
 
148
- ### /trellis:check-frontend and /trellis:check-backend - Combat Context Drift
148
+ ### /trellis:check - Combat Context Drift
149
149
 
150
150
  **WHY IT EXISTS**:
151
151
  AI context window has limited capacity. As conversation progresses, guidelines injected at session start become less influential. This causes "context drift."
@@ -211,9 +211,9 @@ All the context AI built during this session will be lost when session ends. The
211
211
 
212
212
  **[1/8] /trellis:start** - AI needs project context before touching code
213
213
  **[2/8] python3 ./.trellis/scripts/task.py create "Fix bug" --slug fix-bug** - Track work for future reference
214
- **[3/8] /trellis:before-frontend-dev** - Inject project-specific frontend knowledge
214
+ **[3/8] /trellis:before-dev** - Inject project-specific development guidelines
215
215
  **[4/8] Investigate and fix the bug** - Actual development work
216
- **[5/8] /trellis:check-frontend** - Re-verify code against guidelines
216
+ **[5/8] /trellis:check** - Re-verify code against guidelines
217
217
  **[6/8] /trellis:finish-work** - Holistic cross-layer review
218
218
  **[7/8] Human tests and commits** - Human validates before code enters repo
219
219
  **[8/8] /trellis:record-session** - Persist memory for future sessions
@@ -228,9 +228,9 @@ All the context AI built during this session will be lost when session ends. The
228
228
  ### Example 3: Code Review Fixes
229
229
 
230
230
  **[1/6] /trellis:start** - Resume context from previous session
231
- **[2/6] /trellis:before-backend-dev** - Re-inject guidelines before fixes
231
+ **[2/6] /trellis:before-dev** - Re-inject guidelines before fixes
232
232
  **[3/6] Fix each CR issue** - Address feedback with guidelines in context
233
- **[4/6] /trellis:check-backend** - Verify fixes didn't introduce new issues
233
+ **[4/6] /trellis:check** - Verify fixes did not introduce new issues
234
234
  **[5/6] /trellis:finish-work** - Document lessons from CR
235
235
  **[6/6] Human commits, then /trellis:record-session** - Preserve CR lessons
236
236
 
@@ -238,16 +238,16 @@ All the context AI built during this session will be lost when session ends. The
238
238
 
239
239
  **[1/5] /trellis:start** - Clear baseline before major changes
240
240
  **[2/5] Plan phases** - Break into verifiable chunks
241
- **[3/5] Execute phase by phase with /check-* after each** - Incremental verification
241
+ **[3/5] Execute phase by phase with /trellis:check after each** - Incremental verification
242
242
  **[4/5] /trellis:finish-work** - Check if new patterns should be documented
243
243
  **[5/5] Record with multiple commit hashes** - Link all commits to one feature
244
244
 
245
245
  ### Example 5: Debug Session
246
246
 
247
247
  **[1/6] /trellis:start** - See if this bug was investigated before
248
- **[2/6] /trellis:before-backend-dev** - Guidelines might document known gotchas
248
+ **[2/6] /trellis:before-dev** - Guidelines might document known gotchas
249
249
  **[3/6] Investigation** - Actual debugging work
250
- **[4/6] /trellis:check-backend** - Verify debug changes don't break other things
250
+ **[4/6] /trellis:check** - Verify debug changes do not break other things
251
251
  **[5/6] /trellis:finish-work** - Debug findings might need documentation
252
252
  **[6/6] Human commits, then /trellis:record-session** - Debug knowledge is valuable
253
253
 
@@ -256,7 +256,7 @@ All the context AI built during this session will be lost when session ends. The
256
256
  ## KEY RULES TO EMPHASIZE
257
257
 
258
258
  1. **AI NEVER commits** - Human tests and approves. AI prepares, human validates.
259
- 2. **Guidelines before code** - /before-*-dev commands inject project knowledge.
259
+ 2. **Guidelines before code** - /before-dev command injects project knowledge.
260
260
  3. **Check after code** - /check-* commands catch context drift.
261
261
  4. **Record everything** - /trellis:record-session persists memory.
262
262
 
@@ -41,8 +41,7 @@ python3 ./.trellis/scripts/get_context.py
41
41
  ### Step 3: Read Project Guidelines `[AI]`
42
42
 
43
43
  ```bash
44
- cat .trellis/spec/frontend/index.md # Frontend guidelines index
45
- cat .trellis/spec/backend/index.md # Backend guidelines index
44
+ python3 ./.trellis/scripts/get_context.py --mode packages # Discover available spec layers
46
45
  cat .trellis/spec/guides/index.md # Thinking guides
47
46
  ```
48
47
 
@@ -31,7 +31,7 @@ python3 ./.trellis/scripts/add_session.py \
31
31
  --summary "Brief summary of what was done"
32
32
 
33
33
  # Method 2: Pass detailed content via stdin
34
- cat << 'EOF' | python3 ./.trellis/scripts/add_session.py --title "Title" --commit "hash"
34
+ cat << 'EOF' | python3 ./.trellis/scripts/add_session.py --stdin --title "Title" --commit "hash"
35
35
  | Feature | Description |
36
36
  |---------|-------------|
37
37
  | New API | Added user authentication endpoint |
@@ -40,10 +40,14 @@ This shows: developer identity, git status, current task (if any), active tasks.
40
40
  ### Step 3: Read Guidelines Index
41
41
 
42
42
  ```bash
43
- cat .trellis/spec/frontend/index.md # Frontend guidelines
44
- cat .trellis/spec/backend/index.md # Backend guidelines
45
- cat .trellis/spec/guides/index.md # Thinking guides
46
- cat .trellis/spec/unit-test/index.md # Testing guidelines
43
+ python3 ./.trellis/scripts/get_context.py --mode packages
44
+ ```
45
+
46
+ This shows available packages and their spec layers. Read the relevant spec indexes:
47
+
48
+ ```bash
49
+ cat .trellis/spec/<package>/<layer>/index.md # Package-specific guidelines
50
+ cat .trellis/spec/guides/index.md # Thinking guides (always read)
47
51
  ```
48
52
 
49
53
  > **Important**: The index files are navigation — they list the actual guideline files (e.g., `error-handling.md`, `conventions.md`, `mock-strategies.md`).
@@ -339,8 +339,7 @@ def get_check_context(repo_root: str, task_dir: str) -> str:
339
339
  check_files = [
340
340
  (".claude/commands/trellis/finish-work.md", "Finish work checklist"),
341
341
  (".claude/commands/trellis/check-cross-layer.md", "Cross-layer check spec"),
342
- (".claude/commands/trellis/check-backend.md", "Backend check spec"),
343
- (".claude/commands/trellis/check-frontend.md", "Frontend check spec"),
342
+ (".claude/commands/trellis/check.md", "Code quality check spec"),
344
343
  ]
345
344
  for file_path, description in check_files:
346
345
  content = read_file_content(repo_root, file_path)
@@ -432,8 +431,7 @@ def get_debug_context(repo_root: str, task_dir: str) -> str:
432
431
  context_parts.append(f"=== {file_path} (Dev spec) ===\n{content}")
433
432
 
434
433
  check_files = [
435
- (".claude/commands/trellis/check-backend.md", "Backend check spec"),
436
- (".claude/commands/trellis/check-frontend.md", "Frontend check spec"),
434
+ (".claude/commands/trellis/check.md", "Code quality check spec"),
437
435
  (".claude/commands/trellis/check-cross-layer.md", "Cross-layer check spec"),
438
436
  ]
439
437
  for file_path, description in check_files:
@@ -603,24 +601,34 @@ def get_research_context(repo_root: str, task_dir: str | None) -> str:
603
601
  """
604
602
  context_parts = []
605
603
 
606
- # 1. Project structure overview (uses constants for paths)
604
+ # 1. Project structure overview (dynamically discover spec directories)
607
605
  spec_path = f"{DIR_WORKFLOW}/{DIR_SPEC}"
606
+ spec_root = Path(repo_root) / DIR_WORKFLOW / DIR_SPEC
607
+
608
+ # Build spec tree dynamically
609
+ tree_lines = [f"{spec_path}/"]
610
+ if spec_root.is_dir():
611
+ pkg_dirs = sorted(d for d in spec_root.iterdir() if d.is_dir())
612
+ for i, pkg_dir in enumerate(pkg_dirs):
613
+ is_last = i == len(pkg_dirs) - 1
614
+ prefix = "└── " if is_last else "├── "
615
+ layers = sorted(d.name for d in pkg_dir.iterdir() if d.is_dir())
616
+ layer_info = f" ({', '.join(layers)})" if layers else ""
617
+ tree_lines.append(f"{prefix}{pkg_dir.name}/{layer_info}")
618
+
619
+ spec_tree = "\n".join(tree_lines)
620
+
608
621
  project_structure = f"""## Project Spec Directory Structure
609
622
 
610
623
  ```
611
- {spec_path}/
612
- ├── shared/ # Cross-project common specs (TypeScript, code quality, git)
613
- ├── frontend/ # Frontend standards
614
- ├── backend/ # Backend standards
615
- └── guides/ # Thinking guides (cross-layer, code reuse, etc.)
616
-
617
- {DIR_WORKFLOW}/big-question/ # Known issues and pitfalls
624
+ {spec_tree}
618
625
  ```
619
626
 
627
+ To get structured package info, run: `python3 ./{DIR_WORKFLOW}/scripts/get_context.py --mode packages`
628
+
620
629
  ## Search Tips
621
630
 
622
631
  - Spec files: `{spec_path}/**/*.md`
623
- - Known issues: `{DIR_WORKFLOW}/big-question/`
624
632
  - Code search: Use Glob and Grep tools
625
633
  - Tech solutions: Use mcp__exa__web_search_exa or mcp__exa__get_code_context_exa"""
626
634
 
@@ -119,6 +119,151 @@ def _get_task_status(trellis_dir: Path) -> str:
119
119
  return f"Status: READY\nTask: {task_title}\nNext: Continue with implement or check"
120
120
 
121
121
 
122
+ def _load_trellis_config(trellis_dir: Path) -> tuple:
123
+ """Load Trellis config for session-start decisions.
124
+
125
+ Returns:
126
+ (is_mono, packages_dict, spec_scope, task_pkg, default_pkg)
127
+ """
128
+ scripts_dir = trellis_dir / "scripts"
129
+ if str(scripts_dir) not in sys.path:
130
+ sys.path.insert(0, str(scripts_dir))
131
+
132
+ try:
133
+ from common.config import get_default_package, get_packages, get_spec_scope, is_monorepo
134
+ from common.paths import get_current_task
135
+
136
+ repo_root = trellis_dir.parent
137
+ is_mono = is_monorepo(repo_root)
138
+ packages = get_packages(repo_root) or {}
139
+ scope = get_spec_scope(repo_root)
140
+
141
+ # Get active task's package
142
+ task_pkg = None
143
+ current = get_current_task(repo_root)
144
+ if current:
145
+ task_json = repo_root / current / "task.json"
146
+ if task_json.is_file():
147
+ try:
148
+ data = json.loads(task_json.read_text(encoding="utf-8"))
149
+ if isinstance(data, dict):
150
+ tp = data.get("package")
151
+ if isinstance(tp, str) and tp:
152
+ task_pkg = tp
153
+ except (json.JSONDecodeError, OSError):
154
+ pass
155
+
156
+ default_pkg = get_default_package(repo_root)
157
+ return is_mono, packages, scope, task_pkg, default_pkg
158
+ except Exception:
159
+ return False, {}, None, None, None
160
+
161
+
162
+ def _check_legacy_spec(trellis_dir: Path, is_mono: bool, packages: dict) -> str | None:
163
+ """Check for legacy spec directory structure in monorepo.
164
+
165
+ Returns warning message if legacy structure detected, None otherwise.
166
+ """
167
+ if not is_mono or not packages:
168
+ return None
169
+
170
+ spec_dir = trellis_dir / "spec"
171
+ if not spec_dir.is_dir():
172
+ return None
173
+
174
+ # Check for legacy flat spec dirs (spec/backend/, spec/frontend/ with index.md)
175
+ has_legacy = False
176
+ for legacy_name in ("backend", "frontend"):
177
+ legacy_dir = spec_dir / legacy_name
178
+ if legacy_dir.is_dir() and (legacy_dir / "index.md").is_file():
179
+ has_legacy = True
180
+ break
181
+
182
+ if not has_legacy:
183
+ return None
184
+
185
+ # Check which packages are missing spec/<pkg>/ directory
186
+ missing = [
187
+ name for name in sorted(packages.keys())
188
+ if not (spec_dir / name).is_dir()
189
+ ]
190
+
191
+ if not missing:
192
+ return None # All packages have spec dirs
193
+
194
+ if len(missing) == len(packages):
195
+ return (
196
+ f"[!] Legacy spec structure detected: found `spec/backend/` or `spec/frontend/` "
197
+ f"but no package-scoped `spec/<package>/` directories.\n"
198
+ f"Monorepo packages: {', '.join(sorted(packages.keys()))}\n"
199
+ f"Please reorganize: `spec/backend/` -> `spec/<package>/backend/`"
200
+ )
201
+ return (
202
+ f"[!] Partial spec migration detected: packages {', '.join(missing)} "
203
+ f"still missing `spec/<pkg>/` directory.\n"
204
+ f"Please complete migration for all packages."
205
+ )
206
+
207
+
208
+ def _resolve_spec_scope(
209
+ is_mono: bool,
210
+ packages: dict,
211
+ scope,
212
+ task_pkg: str | None,
213
+ default_pkg: str | None,
214
+ ) -> set | None:
215
+ """Resolve which packages should have their specs injected.
216
+
217
+ Returns:
218
+ Set of package names to include, or None for full scan.
219
+ """
220
+ if not is_mono or not packages:
221
+ return None # Single-repo: full scan
222
+
223
+ if scope is None:
224
+ return None # No scope configured: full scan
225
+
226
+ if isinstance(scope, str) and scope == "active_task":
227
+ if task_pkg and task_pkg in packages:
228
+ return {task_pkg}
229
+ if default_pkg and default_pkg in packages:
230
+ return {default_pkg}
231
+ return None # Fallback to full scan
232
+
233
+ if isinstance(scope, list):
234
+ valid = set()
235
+ for entry in scope:
236
+ if entry in packages:
237
+ valid.add(entry)
238
+ else:
239
+ print(
240
+ f"Warning: spec_scope contains unknown package: {entry}, ignoring",
241
+ file=sys.stderr,
242
+ )
243
+
244
+ if valid:
245
+ # Warn if active task is out of scope
246
+ if task_pkg and task_pkg not in valid:
247
+ print(
248
+ f"Warning: active task package '{task_pkg}' is out of configured spec_scope",
249
+ file=sys.stderr,
250
+ )
251
+ return valid
252
+
253
+ # All entries invalid: fallback chain
254
+ print(
255
+ "Warning: all spec_scope entries invalid, falling back to task/default/full",
256
+ file=sys.stderr,
257
+ )
258
+ if task_pkg and task_pkg in packages:
259
+ return {task_pkg}
260
+ if default_pkg and default_pkg in packages:
261
+ return {default_pkg}
262
+ return None # Full scan
263
+
264
+ return None # Unknown scope type: full scan
265
+
266
+
122
267
  def main():
123
268
  if should_skip_injection():
124
269
  sys.exit(0)
@@ -127,6 +272,10 @@ def main():
127
272
  trellis_dir = project_dir / ".trellis"
128
273
  claude_dir = project_dir / ".claude"
129
274
 
275
+ # Load config for scope filtering and legacy detection
276
+ is_mono, packages, scope_config, task_pkg, default_pkg = _load_trellis_config(trellis_dir)
277
+ allowed_pkgs = _resolve_spec_scope(is_mono, packages, scope_config, task_pkg, default_pkg)
278
+
130
279
  output = StringIO()
131
280
 
132
281
  output.write("""<session-context>
@@ -136,6 +285,11 @@ Read and follow all instructions below carefully.
136
285
 
137
286
  """)
138
287
 
288
+ # Legacy migration warning
289
+ legacy_warning = _check_legacy_spec(trellis_dir, is_mono, packages)
290
+ if legacy_warning:
291
+ output.write(f"<migration-warning>\n{legacy_warning}\n</migration-warning>\n\n")
292
+
139
293
  output.write("<current-state>\n")
140
294
  context_script = trellis_dir / "scripts" / "get_context.py"
141
295
  output.write(run_script(context_script))
@@ -155,13 +309,27 @@ Read and follow all instructions below carefully.
155
309
  for sub in sorted(spec_dir.iterdir()):
156
310
  if not sub.is_dir() or sub.name.startswith("."):
157
311
  continue
312
+
313
+ # Always include guides/ regardless of scope
314
+ if sub.name == "guides":
315
+ index_file = sub / "index.md"
316
+ if index_file.is_file():
317
+ output.write(f"## {sub.name}\n")
318
+ output.write(read_file(index_file))
319
+ output.write("\n\n")
320
+ continue
321
+
158
322
  index_file = sub / "index.md"
159
323
  if index_file.is_file():
324
+ # Flat spec dir (single-repo layer like spec/backend/)
160
325
  output.write(f"## {sub.name}\n")
161
326
  output.write(read_file(index_file))
162
327
  output.write("\n\n")
163
328
  else:
164
- # Check for nested package dirs (monorepo: spec/<pkg>/<layer>/index.md)
329
+ # Nested package dirs (monorepo: spec/<pkg>/<layer>/index.md)
330
+ # Apply scope filter
331
+ if allowed_pkgs is not None and sub.name not in allowed_pkgs:
332
+ continue
165
333
  for nested in sorted(sub.iterdir()):
166
334
  if not nested.is_dir():
167
335
  continue
@@ -180,7 +348,7 @@ Read and follow all instructions below carefully.
180
348
  output.write(start_md)
181
349
  output.write("\n</instructions>\n\n")
182
350
 
183
- # R2: Check task status and inject structured tag
351
+ # Check task status and inject structured tag
184
352
  task_status = _get_task_status(trellis_dir)
185
353
  output.write(f"<task-status>\n{task_status}\n</task-status>\n\n")
186
354
 
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: before-dev
3
+ description: "Read the relevant development guidelines before starting your task."
4
+ ---
5
+
6
+ Read the relevant development guidelines before starting your task.
7
+
8
+ Execute these steps:
9
+
10
+ 1. **Discover packages and their spec layers**:
11
+ ```bash
12
+ python3 ./.trellis/scripts/get_context.py --mode packages
13
+ ```
14
+
15
+ 2. **Identify which specs apply** to your task based on:
16
+ - Which package you're modifying (e.g., `cli/`, `docs-site/`)
17
+ - What type of work (backend, frontend, unit-test, docs, etc.)
18
+
19
+ 3. **Read the spec index** for each relevant module:
20
+ ```bash
21
+ cat .trellis/spec/<package>/<layer>/index.md
22
+ ```
23
+ Follow the **"Pre-Development Checklist"** section in the index.
24
+
25
+ 4. **Read the specific guideline files** listed in the Pre-Development Checklist that are relevant to your task. The index is NOT the goal — it points you to the actual guideline files (e.g., `error-handling.md`, `conventions.md`, `mock-strategies.md`). Read those files to understand the coding standards and patterns.
26
+
27
+ 5. **Always read shared guides**:
28
+ ```bash
29
+ cat .trellis/spec/guides/index.md
30
+ ```
31
+
32
+ 6. Understand the coding standards and patterns you need to follow, then proceed with your development plan.
33
+
34
+ This step is **mandatory** before writing any code.
@@ -0,0 +1,30 @@
1
+ ---
2
+ name: check
3
+ description: "Check if the code you just wrote follows the development guidelines."
4
+ ---
5
+
6
+ Check if the code you just wrote follows the development guidelines.
7
+
8
+ Execute these steps:
9
+
10
+ 1. **Identify changed files**:
11
+ ```bash
12
+ git diff --name-only HEAD
13
+ ```
14
+
15
+ 2. **Determine which spec modules apply** based on the changed file paths:
16
+ ```bash
17
+ python3 ./.trellis/scripts/get_context.py --mode packages
18
+ ```
19
+
20
+ 3. **Read the spec index** for each relevant module:
21
+ ```bash
22
+ cat .trellis/spec/<package>/<layer>/index.md
23
+ ```
24
+ Follow the **"Quality Check"** section in the index.
25
+
26
+ 4. **Read the specific guideline files** referenced in the Quality Check section (e.g., `quality-guidelines.md`, `conventions.md`). The index is NOT the goal — it points you to the actual guideline files. Read those files and review your code against them.
27
+
28
+ 5. **Run lint and typecheck** for the affected package.
29
+
30
+ 6. **Report any violations** and fix them if found.
@@ -93,8 +93,8 @@ Description:
93
93
  | Skill Type | Prefix | Example |
94
94
  |------------|--------|---------|
95
95
  | Session Start | `start` | `start` |
96
- | Pre-development | `before-` | `before-frontend-dev` |
97
- | Check | `check-` | `check-frontend` |
96
+ | Pre-development | `before-` | `before-dev` |
97
+ | Check | `check-` | `check` |
98
98
  | Record | `record-` | `record-session` |
99
99
  | Generate | `generate-` | `generate-api-doc` |
100
100
  | Update | `update-` | `update-changelog` |
@@ -131,13 +131,13 @@ AI needs the same onboarding - but compressed into seconds at session start.
131
131
 
132
132
  ---
133
133
 
134
- ### $before-frontend-dev and $before-backend-dev - Inject Specialized Knowledge
134
+ ### $before-dev - Inject Specialized Knowledge
135
135
 
136
136
  **WHY IT EXISTS**:
137
137
  AI models have "pre-trained knowledge" - general patterns from millions of codebases. But YOUR project has specific conventions that differ from generic patterns.
138
138
 
139
139
  **WHAT IT ACTUALLY DOES**:
140
- 1. Reads `.trellis/spec/frontend/` or `.trellis/spec/backend/`
140
+ 1. Discovers spec layers via `get_context.py --mode packages` and reads relevant guidelines
141
141
  2. Loads project-specific patterns into AI's working context:
142
142
  - Component naming conventions
143
143
  - State management patterns
@@ -145,12 +145,12 @@ AI models have "pre-trained knowledge" - general patterns from millions of codeb
145
145
  - Error handling standards
146
146
 
147
147
  **WHY THIS MATTERS**:
148
- - Without before-*-dev: AI writes generic code that doesn't match project style.
149
- - With before-*-dev: AI writes code that looks like the rest of the codebase.
148
+ - Without before-dev: AI writes generic code that doesn't match project style.
149
+ - With before-dev: AI writes code that looks like the rest of the codebase.
150
150
 
151
151
  ---
152
152
 
153
- ### $check-frontend and $check-backend - Combat Context Drift
153
+ ### $check - Combat Context Drift
154
154
 
155
155
  **WHY IT EXISTS**:
156
156
  AI context window has limited capacity. As conversation progresses, guidelines injected at session start become less influential. This causes "context drift."
@@ -216,9 +216,9 @@ All the context AI built during this session will be lost when session ends. The
216
216
 
217
217
  **[1/8] $start** - AI needs project context before touching code
218
218
  **[2/8] python3 ./.trellis/scripts/task.py create "Fix bug" --slug fix-bug** - Track work for future reference
219
- **[3/8] $before-frontend-dev** - Inject project-specific frontend knowledge
219
+ **[3/8] $before-dev** - Inject project-specific development guidelines
220
220
  **[4/8] Investigate and fix the bug** - Actual development work
221
- **[5/8] $check-frontend** - Re-verify code against guidelines
221
+ **[5/8] $check** - Re-verify code against guidelines
222
222
  **[6/8] $finish-work** - Holistic cross-layer review
223
223
  **[7/8] Human tests and commits** - Human validates before code enters repo
224
224
  **[8/8] $record-session** - Persist memory for future sessions
@@ -233,9 +233,9 @@ All the context AI built during this session will be lost when session ends. The
233
233
  ### Example 3: Code Review Fixes
234
234
 
235
235
  **[1/6] $start** - Resume context from previous session
236
- **[2/6] $before-backend-dev** - Re-inject guidelines before fixes
236
+ **[2/6] $before-dev** - Re-inject guidelines before fixes
237
237
  **[3/6] Fix each CR issue** - Address feedback with guidelines in context
238
- **[4/6] $check-backend** - Verify fixes didn't introduce new issues
238
+ **[4/6] $check** - Verify fixes did not introduce new issues
239
239
  **[5/6] $finish-work** - Document lessons from CR
240
240
  **[6/6] Human commits, then $record-session** - Preserve CR lessons
241
241
 
@@ -250,9 +250,9 @@ All the context AI built during this session will be lost when session ends. The
250
250
  ### Example 5: Debug Session
251
251
 
252
252
  **[1/6] $start** - See if this bug was investigated before
253
- **[2/6] $before-backend-dev** - Guidelines might document known gotchas
253
+ **[2/6] $before-dev** - Guidelines might document known gotchas
254
254
  **[3/6] Investigation** - Actual debugging work
255
- **[4/6] $check-backend** - Verify debug changes don't break other things
255
+ **[4/6] $check** - Verify debug changes do not break other things
256
256
  **[5/6] $finish-work** - Debug findings might need documentation
257
257
  **[6/6] Human commits, then $record-session** - Debug knowledge is valuable
258
258
 
@@ -36,7 +36,7 @@ python3 ./.trellis/scripts/add_session.py \
36
36
  --summary "Brief summary of what was done"
37
37
 
38
38
  # Method 2: Pass detailed content via stdin
39
- cat << 'EOF' | python3 ./.trellis/scripts/add_session.py --title "Title" --commit "hash"
39
+ cat << 'EOF' | python3 ./.trellis/scripts/add_session.py --stdin --title "Title" --commit "hash"
40
40
  | Feature | Description |
41
41
  |---------|-------------|
42
42
  | New API | Added user authentication endpoint |
@@ -45,9 +45,14 @@ This shows: developer identity, git status, current task (if any), active tasks.
45
45
  ### Step 3: Read Guidelines Index
46
46
 
47
47
  ```bash
48
- cat .trellis/spec/frontend/index.md # Frontend guidelines
49
- cat .trellis/spec/backend/index.md # Backend guidelines
50
- cat .trellis/spec/guides/index.md # Thinking guides
48
+ python3 ./.trellis/scripts/get_context.py --mode packages
49
+ ```
50
+
51
+ This shows available packages and their spec layers. Read the relevant spec indexes:
52
+
53
+ ```bash
54
+ cat .trellis/spec/<package>/<layer>/index.md # Package-specific guidelines
55
+ cat .trellis/spec/guides/index.md # Thinking guides (always read)
51
56
  ```
52
57
 
53
58
  > **Important**: The index files are navigation — they list the actual guideline files (e.g., `error-handling.md`, `conventions.md`, `mock-strategies.md`).
@@ -0,0 +1,29 @@
1
+ Read the relevant development guidelines before starting your task.
2
+
3
+ Execute these steps:
4
+
5
+ 1. **Discover packages and their spec layers**:
6
+ ```bash
7
+ python3 ./.trellis/scripts/get_context.py --mode packages
8
+ ```
9
+
10
+ 2. **Identify which specs apply** to your task based on:
11
+ - Which package you're modifying (e.g., `cli/`, `docs-site/`)
12
+ - What type of work (backend, frontend, unit-test, docs, etc.)
13
+
14
+ 3. **Read the spec index** for each relevant module:
15
+ ```bash
16
+ cat .trellis/spec/<package>/<layer>/index.md
17
+ ```
18
+ Follow the **"Pre-Development Checklist"** section in the index.
19
+
20
+ 4. **Read the specific guideline files** listed in the Pre-Development Checklist that are relevant to your task. The index is NOT the goal — it points you to the actual guideline files (e.g., `error-handling.md`, `conventions.md`, `mock-strategies.md`). Read those files to understand the coding standards and patterns.
21
+
22
+ 5. **Always read shared guides**:
23
+ ```bash
24
+ cat .trellis/spec/guides/index.md
25
+ ```
26
+
27
+ 6. Understand the coding standards and patterns you need to follow, then proceed with your development plan.
28
+
29
+ This step is **mandatory** before writing any code.
@@ -0,0 +1,25 @@
1
+ Check if the code you just wrote follows the development guidelines.
2
+
3
+ Execute these steps:
4
+
5
+ 1. **Identify changed files**:
6
+ ```bash
7
+ git diff --name-only HEAD
8
+ ```
9
+
10
+ 2. **Determine which spec modules apply** based on the changed file paths:
11
+ ```bash
12
+ python3 ./.trellis/scripts/get_context.py --mode packages
13
+ ```
14
+
15
+ 3. **Read the spec index** for each relevant module:
16
+ ```bash
17
+ cat .trellis/spec/<package>/<layer>/index.md
18
+ ```
19
+ Follow the **"Quality Check"** section in the index.
20
+
21
+ 4. **Read the specific guideline files** referenced in the Quality Check section (e.g., `quality-guidelines.md`, `conventions.md`). The index is NOT the goal — it points you to the actual guideline files. Read those files and review your code against them.
22
+
23
+ 5. **Run lint and typecheck** for the affected package.
24
+
25
+ 6. **Report any violations** and fix them if found.
@@ -101,8 +101,8 @@ Description:
101
101
  | Command Type | Prefix | Example |
102
102
  |--------------|--------|---------|
103
103
  | Session Start | `start` | `start` |
104
- | Pre-development | `before-` | `before-frontend-dev` |
105
- | Check | `check-` | `check-frontend` |
104
+ | Pre-development | `before-` | `before-dev` |
105
+ | Check | `check-` | `check` |
106
106
  | Record | `record-` | `record-session` |
107
107
  | Generate | `generate-` | `generate-api-doc` |
108
108
  | Update | `update-` | `update-changelog` |