@mindfoldhq/trellis 0.3.9 → 0.4.0-beta.1

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
@@ -120,6 +120,140 @@ def _get_task_status(trellis_dir: Path) -> str:
120
120
  return f"Status: READY\nTask: {task_title}\nNext: Continue with implement or check"
121
121
 
122
122
 
123
+ def _load_trellis_config(trellis_dir: Path) -> tuple:
124
+ """Load Trellis config for session-start decisions.
125
+
126
+ Returns:
127
+ (is_mono, packages_dict, spec_scope, task_pkg, default_pkg)
128
+ """
129
+ scripts_dir = trellis_dir / "scripts"
130
+ if str(scripts_dir) not in sys.path:
131
+ sys.path.insert(0, str(scripts_dir))
132
+
133
+ try:
134
+ from common.config import get_default_package, get_packages, get_spec_scope, is_monorepo
135
+ from common.paths import get_current_task
136
+
137
+ repo_root = trellis_dir.parent
138
+ is_mono = is_monorepo(repo_root)
139
+ packages = get_packages(repo_root) or {}
140
+ scope = get_spec_scope(repo_root)
141
+
142
+ # Get active task's package
143
+ task_pkg = None
144
+ current = get_current_task(repo_root)
145
+ if current:
146
+ task_json = repo_root / current / "task.json"
147
+ if task_json.is_file():
148
+ try:
149
+ data = json.loads(task_json.read_text(encoding="utf-8"))
150
+ if isinstance(data, dict):
151
+ tp = data.get("package")
152
+ if isinstance(tp, str) and tp:
153
+ task_pkg = tp
154
+ except (json.JSONDecodeError, OSError):
155
+ pass
156
+
157
+ default_pkg = get_default_package(repo_root)
158
+ return is_mono, packages, scope, task_pkg, default_pkg
159
+ except Exception:
160
+ return False, {}, None, None, None
161
+
162
+
163
+ def _check_legacy_spec(trellis_dir: Path, is_mono: bool, packages: dict) -> str | None:
164
+ """Check for legacy spec directory structure in monorepo."""
165
+ if not is_mono or not packages:
166
+ return None
167
+
168
+ spec_dir = trellis_dir / "spec"
169
+ if not spec_dir.is_dir():
170
+ return None
171
+
172
+ has_legacy = False
173
+ for legacy_name in ("backend", "frontend"):
174
+ legacy_dir = spec_dir / legacy_name
175
+ if legacy_dir.is_dir() and (legacy_dir / "index.md").is_file():
176
+ has_legacy = True
177
+ break
178
+
179
+ if not has_legacy:
180
+ return None
181
+
182
+ missing = [
183
+ name for name in sorted(packages.keys())
184
+ if not (spec_dir / name).is_dir()
185
+ ]
186
+
187
+ if not missing:
188
+ return None
189
+
190
+ if len(missing) == len(packages):
191
+ return (
192
+ f"[!] Legacy spec structure detected: found `spec/backend/` or `spec/frontend/` "
193
+ f"but no package-scoped `spec/<package>/` directories.\n"
194
+ f"Monorepo packages: {', '.join(sorted(packages.keys()))}\n"
195
+ f"Please reorganize: `spec/backend/` -> `spec/<package>/backend/`"
196
+ )
197
+ return (
198
+ f"[!] Partial spec migration detected: packages {', '.join(missing)} "
199
+ f"still missing `spec/<pkg>/` directory.\n"
200
+ f"Please complete migration for all packages."
201
+ )
202
+
203
+
204
+ def _resolve_spec_scope(
205
+ is_mono: bool,
206
+ packages: dict,
207
+ scope,
208
+ task_pkg: str | None,
209
+ default_pkg: str | None,
210
+ ) -> set | None:
211
+ """Resolve which packages should have their specs injected."""
212
+ if not is_mono or not packages:
213
+ return None
214
+
215
+ if scope is None:
216
+ return None
217
+
218
+ if isinstance(scope, str) and scope == "active_task":
219
+ if task_pkg and task_pkg in packages:
220
+ return {task_pkg}
221
+ if default_pkg and default_pkg in packages:
222
+ return {default_pkg}
223
+ return None
224
+
225
+ if isinstance(scope, list):
226
+ valid = set()
227
+ for entry in scope:
228
+ if entry in packages:
229
+ valid.add(entry)
230
+ else:
231
+ print(
232
+ f"Warning: spec_scope contains unknown package: {entry}, ignoring",
233
+ file=sys.stderr,
234
+ )
235
+
236
+ if valid:
237
+ if task_pkg and task_pkg not in valid:
238
+ print(
239
+ f"Warning: active task package '{task_pkg}' is out of configured spec_scope",
240
+ file=sys.stderr,
241
+ )
242
+ return valid
243
+
244
+ print(
245
+ "Warning: all spec_scope entries invalid, falling back to task/default/full",
246
+ file=sys.stderr,
247
+ )
248
+ if task_pkg and task_pkg in packages:
249
+ return {task_pkg}
250
+ if default_pkg and default_pkg in packages:
251
+ return {default_pkg}
252
+ return None
253
+
254
+ return None
255
+
256
+
123
257
  def main():
124
258
  if should_skip_injection():
125
259
  sys.exit(0)
@@ -129,6 +263,10 @@ def main():
129
263
  trellis_dir = project_dir / ".trellis"
130
264
  iflow_dir = project_dir / ".iflow"
131
265
 
266
+ # Load config for scope filtering and legacy detection
267
+ is_mono, packages, scope_config, task_pkg, default_pkg = _load_trellis_config(trellis_dir)
268
+ allowed_pkgs = _resolve_spec_scope(is_mono, packages, scope_config, task_pkg, default_pkg)
269
+
132
270
  output = StringIO()
133
271
 
134
272
  output.write("""<session-context>
@@ -138,6 +276,11 @@ Read and follow all instructions below carefully.
138
276
 
139
277
  """)
140
278
 
279
+ # Legacy migration warning
280
+ legacy_warning = _check_legacy_spec(trellis_dir, is_mono, packages)
281
+ if legacy_warning:
282
+ output.write(f"<migration-warning>\n{legacy_warning}\n</migration-warning>\n\n")
283
+
141
284
  output.write("<current-state>\n")
142
285
  context_script = trellis_dir / "scripts" / "get_context.py"
143
286
  output.write(run_script(context_script))
@@ -157,13 +300,25 @@ Read and follow all instructions below carefully.
157
300
  for sub in sorted(spec_dir.iterdir()):
158
301
  if not sub.is_dir() or sub.name.startswith("."):
159
302
  continue
303
+
304
+ # Always include guides/ regardless of scope
305
+ if sub.name == "guides":
306
+ index_file = sub / "index.md"
307
+ if index_file.is_file():
308
+ output.write(f"## {sub.name}\n")
309
+ output.write(read_file(index_file))
310
+ output.write("\n\n")
311
+ continue
312
+
160
313
  index_file = sub / "index.md"
161
314
  if index_file.is_file():
162
315
  output.write(f"## {sub.name}\n")
163
316
  output.write(read_file(index_file))
164
317
  output.write("\n\n")
165
318
  else:
166
- # Check for nested package dirs (monorepo: spec/<pkg>/<layer>/index.md)
319
+ # Apply scope filter for monorepo packages
320
+ if allowed_pkgs is not None and sub.name not in allowed_pkgs:
321
+ continue
167
322
  for nested in sorted(sub.iterdir()):
168
323
  if not nested.is_dir():
169
324
  continue
@@ -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.
@@ -99,8 +99,8 @@ Description:
99
99
  | Command Type | Prefix | Example |
100
100
  |--------------|--------|---------|
101
101
  | Session Start | `start` | `start` |
102
- | Pre-development | `before-` | `before-frontend-dev` |
103
- | Check | `check-` | `check-frontend` |
102
+ | Pre-development | `before-` | `before-dev` |
103
+ | Check | `check-` | `check` |
104
104
  | Record | `record-` | `record-session` |
105
105
  | Generate | `generate-` | `generate-api-doc` |
106
106
  | Update | `update-` | `update-changelog` |
@@ -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,9 +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
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)
46
51
  ```
47
52
 
48
53
  > **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,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`).
@@ -502,6 +502,99 @@ parser.add_argument(
502
502
 
503
503
  ---
504
504
 
505
+ ## Parsing Structured Command Output
506
+
507
+ ### CRITICAL: Preserve Semantic Whitespace
508
+
509
+ Many CLI tools encode status information in leading/trailing whitespace characters. **Never blindly `.strip()` before parsing.**
510
+
511
+ **Example — `git submodule status` output format**:
512
+
513
+ ```
514
+ abc1234 path/to/submodule (v1.0) ← space prefix = initialized
515
+ -def5678 path/to/other (v2.0) ← minus prefix = not initialized
516
+ +ghi9012 path/to/modified (v3.0) ← plus prefix = modified (out of sync)
517
+ ```
518
+
519
+ ```python
520
+ # BAD — .strip() removes the leading space that means "initialized"
521
+ status_line = status_out.strip()
522
+ prefix = status_line[0] # Reads commit hash char, not status prefix!
523
+
524
+ # GOOD — parse the raw line, then strip individual fields
525
+ raw_line = status_out.rstrip("\n") # Only remove trailing newline
526
+ if not raw_line:
527
+ continue
528
+ prefix = raw_line[0] # ' ', '-', or '+'
529
+ rest = raw_line[1:].strip() # Now safe to strip the rest
530
+ commit_hash = rest.split()[0]
531
+ ```
532
+
533
+ **General rule**: When a command's output uses positional formatting (columns, prefixes, fixed-width fields), parse the structure first, then clean up individual values.
534
+
535
+ **Other commands with semantic whitespace**:
536
+ - `git status --porcelain` — two-char status prefix (`XY`)
537
+ - `git diff --name-status` — tab-separated with status prefix
538
+ - `docker ps --format` — column-aligned output
539
+
540
+ ---
541
+
542
+ ## Monorepo Config API (`common/config.py`)
543
+
544
+ ### Config Functions
545
+
546
+ | Function | Return | Purpose |
547
+ |----------|--------|---------|
548
+ | `is_monorepo(repo_root)` | `bool` | Whether `packages:` exists in config.yaml |
549
+ | `get_packages(repo_root)` | `dict[str, dict] \| None` | All packages from config.yaml (`{name: {path, type?}}`) |
550
+ | `get_default_package(repo_root)` | `str \| None` | The `default_package` from config.yaml |
551
+ | `get_submodule_packages(repo_root)` | `dict[str, str]` | Packages with `type: submodule` (`{name: path}`) |
552
+ | `get_spec_base(package, repo_root)` | `str` | `"spec"` (single-repo) or `"spec/<package>"` (monorepo) |
553
+ | `validate_package(package, repo_root)` | `bool` | Whether package exists in config (always `True` for single-repo) |
554
+ | `resolve_package(task_pkg, repo_root)` | `str \| None` | Resolve package: task → default → None |
555
+ | `get_spec_scope(repo_root)` | `str \| list \| None` | The `session.spec_scope` config value |
556
+ | `get_hooks(event, repo_root)` | `list[str]` | Hook commands for lifecycle event |
557
+
558
+ ### Config.yaml Schema
559
+
560
+ ```yaml
561
+ # Auto-detected monorepo packages (written by trellis init)
562
+ packages:
563
+ cli:
564
+ path: packages/cli
565
+ docs-site:
566
+ path: docs-site
567
+ type: submodule # optional, marks git submodule
568
+ default_package: cli # first non-submodule package
569
+
570
+ # Session behavior
571
+ session:
572
+ spec_scope: active_task # or ["cli", "docs-site"] or omit for full scan
573
+
574
+ # Update behavior
575
+ update:
576
+ skip:
577
+ - .claude/commands/trellis/my-custom.md
578
+
579
+ # Lifecycle hooks
580
+ hooks:
581
+ after_create:
582
+ - "python3 .trellis/scripts/hooks/my_hook.py create"
583
+ ```
584
+
585
+ ### Worktree Submodule Initialization
586
+
587
+ When `start.py` creates a worktree for a task, it calls `_init_submodules_for_task()`:
588
+
589
+ 1. Read `packages` from config.yaml via `get_packages()`
590
+ 2. Resolve target package from task data or `default_package`
591
+ 3. Check if the package is a submodule via `get_submodule_packages()`
592
+ 4. Run `git submodule status <path>` in the worktree
593
+ 5. Parse the status prefix (see "Parsing Structured Command Output" above)
594
+ 6. If uninitialized (`-` prefix): run `git submodule update --init <path>`
595
+
596
+ ---
597
+
505
598
  ## Error Handling
506
599
 
507
600
  ### Exit Codes