@mindfoldhq/trellis 0.3.5 → 0.3.7
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.
- package/README.md +17 -4
- package/dist/cli/index.js +1 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +243 -49
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/update.d.ts +12 -0
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +92 -2
- package/dist/commands/update.js.map +1 -1
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +3 -1
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/manifests/0.3.6.json +9 -0
- package/dist/migrations/manifests/0.3.7.json +9 -0
- package/dist/templates/claude/commands/trellis/brainstorm.md +13 -0
- package/dist/templates/claude/commands/trellis/record-session.md +4 -1
- package/dist/templates/claude/commands/trellis/start.md +20 -4
- package/dist/templates/claude/hooks/inject-subagent-context.py +1 -1
- package/dist/templates/claude/hooks/session-start.py +86 -23
- package/dist/templates/claude/settings.json +10 -0
- package/dist/templates/codex/skills/brainstorm/SKILL.md +13 -0
- package/dist/templates/codex/skills/record-session/SKILL.md +4 -1
- package/dist/templates/codex/skills/start/SKILL.md +20 -4
- package/dist/templates/cursor/commands/trellis-brainstorm.md +13 -0
- package/dist/templates/cursor/commands/trellis-record-session.md +4 -1
- package/dist/templates/cursor/commands/trellis-start.md +20 -4
- package/dist/templates/gemini/commands/trellis/brainstorm.toml +15 -0
- package/dist/templates/gemini/commands/trellis/record-session.toml +4 -1
- package/dist/templates/gemini/commands/trellis/start.toml +60 -3
- package/dist/templates/iflow/commands/trellis/brainstorm.md +13 -0
- package/dist/templates/iflow/commands/trellis/record-session.md +4 -1
- package/dist/templates/iflow/commands/trellis/start.md +20 -4
- package/dist/templates/iflow/hooks/inject-subagent-context.py +1 -1
- package/dist/templates/iflow/hooks/session-start.py +86 -23
- package/dist/templates/kilo/workflows/brainstorm.md +13 -0
- package/dist/templates/kilo/workflows/record-session.md +4 -1
- package/dist/templates/kilo/workflows/start.md +64 -3
- package/dist/templates/kiro/skills/brainstorm/SKILL.md +13 -0
- package/dist/templates/kiro/skills/record-session/SKILL.md +4 -1
- package/dist/templates/kiro/skills/start/SKILL.md +20 -4
- package/dist/templates/markdown/spec/backend/directory-structure.md +292 -0
- package/dist/templates/markdown/spec/backend/script-conventions.md +220 -38
- package/dist/templates/opencode/commands/trellis/brainstorm.md +13 -0
- package/dist/templates/opencode/commands/trellis/record-session.md +4 -1
- package/dist/templates/opencode/commands/trellis/start.md +9 -1
- package/dist/templates/opencode/plugin/session-start.js +149 -16
- package/dist/templates/qoder/skills/brainstorm/SKILL.md +13 -0
- package/dist/templates/qoder/skills/record-session/SKILL.md +4 -1
- package/dist/templates/qoder/skills/start/SKILL.md +60 -3
- package/dist/templates/trellis/config.yaml +18 -0
- package/dist/templates/trellis/index.d.ts.map +1 -1
- package/dist/templates/trellis/index.js.map +1 -1
- package/dist/templates/trellis/scripts/common/config.py +20 -0
- package/dist/templates/trellis/scripts/common/git_context.py +160 -12
- package/dist/templates/trellis/scripts/common/task_queue.py +4 -0
- package/dist/templates/trellis/scripts/common/worktree.py +78 -11
- package/dist/templates/trellis/scripts/create_bootstrap.py +3 -0
- package/dist/templates/trellis/scripts/task.py +312 -17
- package/dist/utils/template-fetcher.d.ts +60 -7
- package/dist/utils/template-fetcher.d.ts.map +1 -1
- package/dist/utils/template-fetcher.js +183 -14
- package/dist/utils/template-fetcher.js.map +1 -1
- package/package.json +7 -9
|
@@ -23,8 +23,11 @@ All workflow scripts are written in **Python 3.10+** for cross-platform compatib
|
|
|
23
23
|
│ ├── task_utils.py # Task helper functions
|
|
24
24
|
│ ├── phase.py # Multi-agent phase tracking
|
|
25
25
|
│ ├── registry.py # Agent registry management
|
|
26
|
-
│ ├──
|
|
26
|
+
│ ├── config.py # Config reader (config.yaml, hooks)
|
|
27
|
+
│ ├── worktree.py # Git worktree utilities + YAML parser
|
|
27
28
|
│ └── git_context.py # Git/session context
|
|
29
|
+
├── hooks/ # Lifecycle hook scripts (project-specific)
|
|
30
|
+
│ └── linear_sync.py # Example: sync tasks to Linear
|
|
28
31
|
├── multi_agent/ # Multi-agent pipeline scripts
|
|
29
32
|
│ ├── __init__.py
|
|
30
33
|
│ ├── start.py # Start worktree agent
|
|
@@ -81,10 +84,19 @@ Task Management Script.
|
|
|
81
84
|
|
|
82
85
|
Usage:
|
|
83
86
|
python3 task.py create "<title>" [--slug <name>]
|
|
84
|
-
python3 task.py
|
|
87
|
+
python3 task.py init-context <dir> <dev_type>
|
|
88
|
+
python3 task.py add-context <dir> <file> <reason>
|
|
89
|
+
python3 task.py validate <dir>
|
|
90
|
+
python3 task.py list-context <dir>
|
|
85
91
|
python3 task.py start <dir>
|
|
86
92
|
python3 task.py finish
|
|
93
|
+
python3 task.py set-branch <dir> <branch>
|
|
94
|
+
python3 task.py set-base-branch <dir> <branch>
|
|
95
|
+
python3 task.py set-scope <dir> <scope>
|
|
96
|
+
python3 task.py create-pr [dir] [--dry-run]
|
|
87
97
|
python3 task.py archive <task-name>
|
|
98
|
+
python3 task.py list [--mine] [--status <status>]
|
|
99
|
+
python3 task.py list-archive [YYYY-MM]
|
|
88
100
|
"""
|
|
89
101
|
|
|
90
102
|
from __future__ import annotations
|
|
@@ -202,11 +214,13 @@ def run_command(
|
|
|
202
214
|
|
|
203
215
|
## Cross-Platform Compatibility
|
|
204
216
|
|
|
205
|
-
### CRITICAL: Windows stdout
|
|
217
|
+
### CRITICAL: Windows stdio Encoding (stdout + stdin)
|
|
206
218
|
|
|
207
|
-
On Windows, Python's stdout
|
|
219
|
+
On Windows, Python's stdout AND stdin default to the system code page (e.g., GBK/CP936 in China, CP1252 in Western locales). This causes:
|
|
220
|
+
- `UnicodeEncodeError` when **printing** non-ASCII characters (stdout)
|
|
221
|
+
- `UnicodeDecodeError` when **reading piped** UTF-8 content (stdin), e.g. Chinese text via `cat << EOF | python3 script.py`
|
|
208
222
|
|
|
209
|
-
**The Problem Chain**:
|
|
223
|
+
**The Problem Chain (stdout)**:
|
|
210
224
|
|
|
211
225
|
```
|
|
212
226
|
Windows code page = GBK (936)
|
|
@@ -220,60 +234,64 @@ json.dumps(ensure_ascii=False) → print()
|
|
|
220
234
|
GBK cannot encode \ufffd → UnicodeEncodeError: 'gbk' codec can't encode character
|
|
221
235
|
```
|
|
222
236
|
|
|
223
|
-
**
|
|
224
|
-
|
|
225
|
-
---
|
|
237
|
+
**The Problem Chain (stdin)**:
|
|
226
238
|
|
|
227
|
-
|
|
239
|
+
```
|
|
240
|
+
AI agent pipes UTF-8 content via heredoc: cat << 'EOF' | python3 add_session.py ...
|
|
241
|
+
↓
|
|
242
|
+
Python stdin defaults to GBK encoding (PowerShell default code page)
|
|
243
|
+
↓
|
|
244
|
+
sys.stdin.read() decodes bytes as GBK, not UTF-8
|
|
245
|
+
↓
|
|
246
|
+
Chinese text garbled or UnicodeDecodeError
|
|
247
|
+
```
|
|
228
248
|
|
|
229
|
-
|
|
230
|
-
import sys
|
|
249
|
+
**Root Cause**: Even if you set `PYTHONIOENCODING` in subprocess calls, the **parent process's stdio** still uses the system code page.
|
|
231
250
|
|
|
232
|
-
|
|
233
|
-
if sys.platform == "win32":
|
|
234
|
-
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
235
|
-
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
|
|
236
|
-
```
|
|
251
|
+
---
|
|
237
252
|
|
|
238
|
-
|
|
253
|
+
#### GOOD: Centralize encoding fix in `common/__init__.py`
|
|
239
254
|
|
|
240
|
-
|
|
255
|
+
All stdio encoding is handled in one place. Scripts that `from common import ...` automatically get the fix:
|
|
241
256
|
|
|
242
257
|
```python
|
|
243
258
|
# common/__init__.py
|
|
259
|
+
import io
|
|
244
260
|
import sys
|
|
245
261
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
262
|
+
def _configure_stream(stream):
|
|
263
|
+
"""Configure a stream for UTF-8 encoding on Windows."""
|
|
264
|
+
if hasattr(stream, "reconfigure"):
|
|
265
|
+
stream.reconfigure(encoding="utf-8", errors="replace")
|
|
266
|
+
return stream
|
|
267
|
+
elif hasattr(stream, "detach"):
|
|
268
|
+
return io.TextIOWrapper(stream.detach(), encoding="utf-8", errors="replace")
|
|
269
|
+
return stream
|
|
249
270
|
|
|
250
|
-
|
|
271
|
+
if sys.platform == "win32":
|
|
272
|
+
sys.stdout = _configure_stream(sys.stdout)
|
|
273
|
+
sys.stderr = _configure_stream(sys.stderr)
|
|
274
|
+
sys.stdin = _configure_stream(sys.stdin) # Don't forget stdin!
|
|
251
275
|
```
|
|
252
276
|
|
|
253
277
|
---
|
|
254
278
|
|
|
255
|
-
####
|
|
279
|
+
#### DON'T: Inline encoding code in individual scripts
|
|
256
280
|
|
|
257
281
|
```python
|
|
258
|
-
# BAD -
|
|
282
|
+
# BAD - Duplicated in every script, easy to forget stdin
|
|
259
283
|
import sys
|
|
260
|
-
import io
|
|
261
|
-
|
|
262
284
|
if sys.platform == "win32":
|
|
263
|
-
sys.stdout
|
|
285
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
286
|
+
# Forgot stdin! Piped Chinese text will break.
|
|
264
287
|
```
|
|
265
288
|
|
|
266
|
-
**Why this
|
|
289
|
+
**Why this is bad**:
|
|
290
|
+
1. **Easy to forget streams**: stdout was fixed but stdin was missed in multiple scripts, causing real user bugs
|
|
291
|
+
2. **Duplicated code**: Same logic copy-pasted across `add_session.py`, `git_context.py`, etc.
|
|
292
|
+
3. **Inconsistent coverage**: Some scripts fix stdout only, others fix stdout+stderr, none fixed stdin
|
|
267
293
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
2. **Loses original stdout properties**: The new wrapper may not preserve all attributes of the original `sys.stdout` (like `isatty()`, line buffering behavior).
|
|
271
|
-
|
|
272
|
-
3. **Race condition with buffering**: If any output was buffered before the replacement, it may still be encoded with the old encoding.
|
|
273
|
-
|
|
274
|
-
4. **Not idempotent**: Calling this multiple times creates nested wrappers, while `reconfigure()` is safe to call multiple times.
|
|
275
|
-
|
|
276
|
-
**Real-world failure case**: Users reported that `io.TextIOWrapper` did not fix the `UnicodeEncodeError` on Windows, while `sys.stdout.reconfigure()` worked immediately.
|
|
294
|
+
**Real-world failure**: Users on Windows reported garbled Chinese text when using `cat << EOF | python3 add_session.py`. Root cause: stdin was never reconfigured to UTF-8.
|
|
277
295
|
|
|
278
296
|
---
|
|
279
297
|
|
|
@@ -281,7 +299,8 @@ if sys.platform == "win32":
|
|
|
281
299
|
|
|
282
300
|
| Method | Works? | Reason |
|
|
283
301
|
|--------|--------|--------|
|
|
284
|
-
| `
|
|
302
|
+
| `common/__init__.py` centralized fix | ✅ Yes | All streams, all scripts, one place |
|
|
303
|
+
| `sys.stdout.reconfigure(encoding="utf-8")` | ⚠️ Partial | Only stdout; easy to forget stdin/stderr |
|
|
285
304
|
| `io.TextIOWrapper(sys.stdout.buffer, ...)` | ❌ No | Creates wrapper, doesn't fix underlying encoding |
|
|
286
305
|
| `PYTHONIOENCODING=utf-8` env var | ⚠️ Partial | Only works if set **before** Python starts |
|
|
287
306
|
|
|
@@ -320,6 +339,169 @@ path = ".trellis/scripts/task.py"
|
|
|
320
339
|
|
|
321
340
|
---
|
|
322
341
|
|
|
342
|
+
## Task Lifecycle Hooks
|
|
343
|
+
|
|
344
|
+
### Scope / Trigger
|
|
345
|
+
|
|
346
|
+
Task lifecycle events (`after_create`, `after_start`, `after_finish`, `after_archive`) execute user-defined shell commands configured in `config.yaml`.
|
|
347
|
+
|
|
348
|
+
### Signatures
|
|
349
|
+
|
|
350
|
+
```python
|
|
351
|
+
# config.py — read hook commands from config
|
|
352
|
+
def get_hooks(event: str, repo_root: Path | None = None) -> list[str]
|
|
353
|
+
|
|
354
|
+
# task.py — execute hooks (never blocks main operation)
|
|
355
|
+
def _run_hooks(event: str, task_json_path: Path, repo_root: Path) -> None
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Contracts
|
|
359
|
+
|
|
360
|
+
**Config format** (`config.yaml`):
|
|
361
|
+
```yaml
|
|
362
|
+
hooks:
|
|
363
|
+
after_create:
|
|
364
|
+
- "python3 .trellis/scripts/hooks/my_hook.py create"
|
|
365
|
+
after_start:
|
|
366
|
+
- "python3 .trellis/scripts/hooks/my_hook.py start"
|
|
367
|
+
after_archive:
|
|
368
|
+
- "python3 .trellis/scripts/hooks/my_hook.py archive"
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
**Environment variables passed to hooks**:
|
|
372
|
+
|
|
373
|
+
| Key | Type | Description |
|
|
374
|
+
|-----|------|-------------|
|
|
375
|
+
| `TASK_JSON_PATH` | Absolute path string | Path to the task's `task.json` |
|
|
376
|
+
|
|
377
|
+
- `cwd` is set to `repo_root`
|
|
378
|
+
- Hooks inherit the parent process environment + `TASK_JSON_PATH`
|
|
379
|
+
|
|
380
|
+
### Subprocess Execution
|
|
381
|
+
|
|
382
|
+
```python
|
|
383
|
+
import os
|
|
384
|
+
import subprocess
|
|
385
|
+
|
|
386
|
+
env = {**os.environ, "TASK_JSON_PATH": str(task_json_path)}
|
|
387
|
+
|
|
388
|
+
result = subprocess.run(
|
|
389
|
+
cmd,
|
|
390
|
+
shell=True,
|
|
391
|
+
cwd=repo_root,
|
|
392
|
+
env=env,
|
|
393
|
+
capture_output=True,
|
|
394
|
+
text=True,
|
|
395
|
+
encoding="utf-8", # REQUIRED: cross-platform
|
|
396
|
+
errors="replace", # REQUIRED: cross-platform
|
|
397
|
+
)
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Validation & Error Matrix
|
|
401
|
+
|
|
402
|
+
| Condition | Behavior |
|
|
403
|
+
|-----------|----------|
|
|
404
|
+
| No `hooks` key in config | No-op (empty list) |
|
|
405
|
+
| `hooks` is not a dict | No-op (empty list) |
|
|
406
|
+
| Event key missing | No-op (empty list) |
|
|
407
|
+
| Hook command exits non-zero | `[WARN]` to stderr, continues to next hook |
|
|
408
|
+
| Hook command throws exception | `[WARN]` to stderr, continues to next hook |
|
|
409
|
+
| `linearis` not installed | Hook fails with warning, task operation succeeds |
|
|
410
|
+
|
|
411
|
+
### Wrong vs Correct
|
|
412
|
+
|
|
413
|
+
#### Wrong — blocking on hook failure
|
|
414
|
+
```python
|
|
415
|
+
result = subprocess.run(cmd, shell=True, check=True) # Raises on failure!
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
#### Correct — warn and continue
|
|
419
|
+
```python
|
|
420
|
+
try:
|
|
421
|
+
result = subprocess.run(cmd, shell=True, ...)
|
|
422
|
+
if result.returncode != 0:
|
|
423
|
+
print(f"[WARN] Hook failed: {cmd}", file=sys.stderr)
|
|
424
|
+
except Exception as e:
|
|
425
|
+
print(f"[WARN] Hook error: {cmd} — {e}", file=sys.stderr)
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### Hook Script Pattern
|
|
429
|
+
|
|
430
|
+
Hook scripts that need project-specific config (API keys, user IDs) should:
|
|
431
|
+
1. Store config in a **gitignored** local file (e.g., `.trellis/hooks.local.json`)
|
|
432
|
+
2. Read config at startup, fail with clear message if missing
|
|
433
|
+
3. Keep the script itself committable (no hardcoded secrets)
|
|
434
|
+
|
|
435
|
+
```python
|
|
436
|
+
# .trellis/scripts/hooks/my_hook.py — committable, no secrets
|
|
437
|
+
CONFIG = _load_config() # reads from .trellis/hooks.local.json (gitignored)
|
|
438
|
+
TEAM = CONFIG.get("linear", {}).get("team", "")
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## Auto-Commit Pattern
|
|
444
|
+
|
|
445
|
+
Scripts that modify `.trellis/` tracked files should auto-commit their changes to keep the workspace clean. Use a `--no-commit` flag for opt-out.
|
|
446
|
+
|
|
447
|
+
### Convention: Auto-Commit After Mutation
|
|
448
|
+
|
|
449
|
+
```python
|
|
450
|
+
def _auto_commit(scope: str, message: str, repo_root: Path) -> None:
|
|
451
|
+
"""Stage and commit changes in a specific .trellis/ subdirectory."""
|
|
452
|
+
subprocess.run(["git", "add", "-A", scope], cwd=repo_root, capture_output=True)
|
|
453
|
+
# Check if there are staged changes
|
|
454
|
+
result = subprocess.run(
|
|
455
|
+
["git", "diff", "--cached", "--quiet", "--", scope],
|
|
456
|
+
cwd=repo_root,
|
|
457
|
+
)
|
|
458
|
+
if result.returncode == 0:
|
|
459
|
+
print("[OK] No changes to commit.", file=sys.stderr)
|
|
460
|
+
return
|
|
461
|
+
commit_result = subprocess.run(
|
|
462
|
+
["git", "commit", "-m", message],
|
|
463
|
+
cwd=repo_root, capture_output=True, text=True,
|
|
464
|
+
)
|
|
465
|
+
if commit_result.returncode == 0:
|
|
466
|
+
print(f"[OK] Auto-committed: {message}", file=sys.stderr)
|
|
467
|
+
else:
|
|
468
|
+
print(f"[WARN] Auto-commit failed: {commit_result.stderr.strip()}", file=sys.stderr)
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
**Scripts using this pattern**:
|
|
472
|
+
- `add_session.py` — commits `.trellis/workspace` + `.trellis/tasks` after recording a session
|
|
473
|
+
- `task.py archive` — commits `.trellis/tasks` after archiving a task
|
|
474
|
+
|
|
475
|
+
**Always add `--no-commit` flag** for scripts that auto-commit, so users can opt out.
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
## CLI Mode Extension Pattern
|
|
480
|
+
|
|
481
|
+
### Design Decision: `--mode` for Context-Dependent Output
|
|
482
|
+
|
|
483
|
+
When a script needs different output for different use cases, use `--mode` (not separate scripts or additional flags).
|
|
484
|
+
|
|
485
|
+
**Example**: `get_context.py` serves two modes:
|
|
486
|
+
- `--mode default` — full session context (DEVELOPER, GIT STATUS, RECENT COMMITS, CURRENT TASK, ACTIVE TASKS, MY TASKS, JOURNAL, PATHS)
|
|
487
|
+
- `--mode record` — focused output for record-session (MY ACTIVE TASKS first with emphasis, GIT STATUS, RECENT COMMITS, CURRENT TASK)
|
|
488
|
+
|
|
489
|
+
```python
|
|
490
|
+
parser.add_argument(
|
|
491
|
+
"--mode", "-m",
|
|
492
|
+
choices=["default", "record"],
|
|
493
|
+
default="default",
|
|
494
|
+
help="Output mode: default (full context) or record (for record-session)",
|
|
495
|
+
)
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
**When to add a new mode** (not a new script):
|
|
499
|
+
- Output is a subset/reordering of the same data
|
|
500
|
+
- The underlying data sources are shared
|
|
501
|
+
- The difference is in presentation, not in data fetching
|
|
502
|
+
|
|
503
|
+
---
|
|
504
|
+
|
|
323
505
|
## Error Handling
|
|
324
506
|
|
|
325
507
|
### Exit Codes
|
|
@@ -387,6 +387,19 @@ Here's my understanding of the complete requirements:
|
|
|
387
387
|
Does this look correct? If yes, I'll proceed with implementation.
|
|
388
388
|
```
|
|
389
389
|
|
|
390
|
+
### Subtask Decomposition (Complex Tasks)
|
|
391
|
+
|
|
392
|
+
For complex tasks with multiple independent work items, create subtasks:
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
# Create child tasks
|
|
396
|
+
CHILD1=$(python3 ./.trellis/scripts/task.py create "Child task 1" --slug child1 --parent "$TASK_DIR")
|
|
397
|
+
CHILD2=$(python3 ./.trellis/scripts/task.py create "Child task 2" --slug child2 --parent "$TASK_DIR")
|
|
398
|
+
|
|
399
|
+
# Or link existing tasks
|
|
400
|
+
python3 ./.trellis/scripts/task.py add-subtask "$TASK_DIR" "$CHILD_DIR"
|
|
401
|
+
```
|
|
402
|
+
|
|
390
403
|
---
|
|
391
404
|
|
|
392
405
|
## PRD Target Structure (final)
|
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
python3 ./.trellis/scripts/get_context.py --mode record
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
[!]
|
|
15
|
+
[!] Archive tasks whose work is **actually done** — judge by work status, not the `status` field in task.json:
|
|
16
|
+
- Code committed? → Archive it (don't wait for PR)
|
|
17
|
+
- All acceptance criteria met? → Archive it
|
|
18
|
+
- Don't skip archiving just because `status` still says `planning` or `in_progress`
|
|
16
19
|
|
|
17
20
|
```bash
|
|
18
21
|
python3 ./.trellis/scripts/task.py archive <task-name>
|
|
@@ -45,6 +45,10 @@ cat .trellis/spec/backend/index.md # Backend guidelines
|
|
|
45
45
|
cat .trellis/spec/guides/index.md # Thinking guides
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
> **Important**: The index files are navigation — they list the actual guideline files (e.g., `error-handling.md`, `conventions.md`, `mock-strategies.md`).
|
|
49
|
+
> At this step, just read the indexes to understand what's available.
|
|
50
|
+
> When you start actual development, you MUST go back and read the specific guideline files relevant to your task, as listed in the index's Pre-Development Checklist.
|
|
51
|
+
|
|
48
52
|
### Step 4: Report and Ask
|
|
49
53
|
|
|
50
54
|
Report what you learned and ask: "What would you like to work on?"
|
|
@@ -82,7 +86,7 @@ For questions or trivial fixes, work directly:
|
|
|
82
86
|
|
|
83
87
|
## Complex Task - Brainstorm First
|
|
84
88
|
|
|
85
|
-
For complex or vague tasks,
|
|
89
|
+
For complex or vague tasks, **automatically start the brainstorm process** — do NOT skip directly to implementation.
|
|
86
90
|
|
|
87
91
|
See `/trellis:brainstorm` for the full process. Summary:
|
|
88
92
|
|
|
@@ -93,6 +97,10 @@ See `/trellis:brainstorm` for the full process. Summary:
|
|
|
93
97
|
5. **Confirm final requirements** - Get explicit approval
|
|
94
98
|
6. **Proceed to Task Workflow** - With clear requirements in PRD
|
|
95
99
|
|
|
100
|
+
> **Subtask Decomposition**: If brainstorm reveals multiple independent work items,
|
|
101
|
+
> consider creating subtasks using `--parent` flag or `add-subtask` command.
|
|
102
|
+
> See `/trellis:brainstorm` Step 8 for details.
|
|
103
|
+
|
|
96
104
|
---
|
|
97
105
|
|
|
98
106
|
## Task Workflow (Development Tasks)
|
|
@@ -10,10 +10,97 @@
|
|
|
10
10
|
* - Otherwise, this plugin handles injection
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { existsSync } from "fs"
|
|
13
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "fs"
|
|
14
14
|
import { join } from "path"
|
|
15
15
|
import { TrellisContext, contextCollector, debugLog } from "../lib/trellis-context.js"
|
|
16
16
|
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Check current task status and return structured status string.
|
|
20
|
+
* JavaScript equivalent of _get_task_status in Claude's session-start.py.
|
|
21
|
+
*/
|
|
22
|
+
function getTaskStatus(directory) {
|
|
23
|
+
const trellisDir = join(directory, ".trellis")
|
|
24
|
+
const currentTaskFile = join(trellisDir, ".current-task")
|
|
25
|
+
|
|
26
|
+
if (!existsSync(currentTaskFile)) {
|
|
27
|
+
return "Status: NO ACTIVE TASK\nNext: Describe what you want to work on"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let taskRef
|
|
31
|
+
try {
|
|
32
|
+
taskRef = readFileSync(currentTaskFile, "utf-8").trim()
|
|
33
|
+
} catch {
|
|
34
|
+
return "Status: NO ACTIVE TASK\nNext: Describe what you want to work on"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!taskRef) {
|
|
38
|
+
return "Status: NO ACTIVE TASK\nNext: Describe what you want to work on"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Resolve task directory
|
|
42
|
+
let taskDir
|
|
43
|
+
if (taskRef.startsWith("/")) {
|
|
44
|
+
taskDir = taskRef
|
|
45
|
+
} else if (taskRef.startsWith(".trellis/")) {
|
|
46
|
+
taskDir = join(directory, taskRef)
|
|
47
|
+
} else {
|
|
48
|
+
taskDir = join(trellisDir, "tasks", taskRef)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!existsSync(taskDir)) {
|
|
52
|
+
return `Status: STALE POINTER\nTask: ${taskRef}\nNext: Task directory not found. Run: python3 ./.trellis/scripts/task.py finish`
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Read task.json
|
|
56
|
+
let taskData = {}
|
|
57
|
+
const taskJsonPath = join(taskDir, "task.json")
|
|
58
|
+
if (existsSync(taskJsonPath)) {
|
|
59
|
+
try {
|
|
60
|
+
taskData = JSON.parse(readFileSync(taskJsonPath, "utf-8"))
|
|
61
|
+
} catch {
|
|
62
|
+
// Ignore parse errors
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const taskTitle = taskData.title || taskRef
|
|
67
|
+
const taskStatus = taskData.status || "unknown"
|
|
68
|
+
|
|
69
|
+
if (taskStatus === "completed") {
|
|
70
|
+
const dirName = taskDir.split("/").pop()
|
|
71
|
+
return `Status: COMPLETED\nTask: ${taskTitle}\nNext: Archive with \`python3 ./.trellis/scripts/task.py archive ${dirName}\` or start a new task`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Check if context is configured (jsonl files exist and non-empty)
|
|
75
|
+
let hasContext = false
|
|
76
|
+
for (const jsonlName of ["implement.jsonl", "check.jsonl", "spec.jsonl"]) {
|
|
77
|
+
const jsonlPath = join(taskDir, jsonlName)
|
|
78
|
+
if (existsSync(jsonlPath)) {
|
|
79
|
+
try {
|
|
80
|
+
const st = statSync(jsonlPath)
|
|
81
|
+
if (st.size > 0) {
|
|
82
|
+
hasContext = true
|
|
83
|
+
break
|
|
84
|
+
}
|
|
85
|
+
} catch {
|
|
86
|
+
// Ignore stat errors
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const hasPrd = existsSync(join(taskDir, "prd.md"))
|
|
92
|
+
|
|
93
|
+
if (!hasPrd) {
|
|
94
|
+
return `Status: NOT READY\nTask: ${taskTitle}\nMissing: prd.md not created\nNext: Write PRD, then research → init-context → start`
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!hasContext) {
|
|
98
|
+
return `Status: NOT READY\nTask: ${taskTitle}\nMissing: Context not configured (no jsonl files)\nNext: Complete Phase 2 (research → init-context → start) before implementing`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return `Status: READY\nTask: ${taskTitle}\nNext: Continue with implement or check`
|
|
102
|
+
}
|
|
103
|
+
|
|
17
104
|
/**
|
|
18
105
|
* Build session context for injection
|
|
19
106
|
*/
|
|
@@ -50,20 +137,60 @@ Read and follow all instructions below carefully.
|
|
|
50
137
|
parts.push("</workflow>")
|
|
51
138
|
}
|
|
52
139
|
|
|
53
|
-
// 4. Guidelines Index
|
|
140
|
+
// 4. Guidelines Index (dynamic discovery, matching Claude's session-start.py)
|
|
54
141
|
parts.push("<guidelines>")
|
|
55
|
-
|
|
56
|
-
parts.push("
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
142
|
+
parts.push("**Note**: The guidelines below are index files — they list available guideline documents and their locations.")
|
|
143
|
+
parts.push("During actual development, you MUST read the specific guideline files listed in each index's Pre-Development Checklist.\n")
|
|
144
|
+
|
|
145
|
+
const specDir = join(directory, ".trellis", "spec")
|
|
146
|
+
if (existsSync(specDir)) {
|
|
147
|
+
try {
|
|
148
|
+
const subs = readdirSync(specDir).filter(name => {
|
|
149
|
+
if (name.startsWith(".")) return false
|
|
150
|
+
try {
|
|
151
|
+
return statSync(join(specDir, name)).isDirectory()
|
|
152
|
+
} catch {
|
|
153
|
+
return false
|
|
154
|
+
}
|
|
155
|
+
}).sort()
|
|
156
|
+
|
|
157
|
+
for (const sub of subs) {
|
|
158
|
+
const indexFile = join(specDir, sub, "index.md")
|
|
159
|
+
if (existsSync(indexFile)) {
|
|
160
|
+
// Flat spec dir: spec/<layer>/index.md
|
|
161
|
+
const content = ctx.readFile(indexFile)
|
|
162
|
+
if (content) {
|
|
163
|
+
parts.push(`## ${sub}\n${content}\n`)
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
// Nested package dirs (monorepo): spec/<pkg>/<layer>/index.md
|
|
167
|
+
try {
|
|
168
|
+
const nested = readdirSync(join(specDir, sub)).filter(name => {
|
|
169
|
+
try {
|
|
170
|
+
return statSync(join(specDir, sub, name)).isDirectory()
|
|
171
|
+
} catch {
|
|
172
|
+
return false
|
|
173
|
+
}
|
|
174
|
+
}).sort()
|
|
175
|
+
|
|
176
|
+
for (const layer of nested) {
|
|
177
|
+
const nestedIndex = join(specDir, sub, layer, "index.md")
|
|
178
|
+
if (existsSync(nestedIndex)) {
|
|
179
|
+
const content = ctx.readFile(nestedIndex)
|
|
180
|
+
if (content) {
|
|
181
|
+
parts.push(`## ${sub}/${layer}\n${content}\n`)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} catch {
|
|
186
|
+
// Ignore directory read errors
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
} catch {
|
|
191
|
+
// Ignore spec directory read errors
|
|
192
|
+
}
|
|
193
|
+
}
|
|
67
194
|
|
|
68
195
|
parts.push("</guidelines>")
|
|
69
196
|
|
|
@@ -78,9 +205,15 @@ Read and follow all instructions below carefully.
|
|
|
78
205
|
parts.push("</instructions>")
|
|
79
206
|
}
|
|
80
207
|
|
|
81
|
-
// 6.
|
|
208
|
+
// 6. Task status (R2: check task state for session resume)
|
|
209
|
+
const taskStatus = getTaskStatus(directory)
|
|
210
|
+
parts.push(`<task-status>\n${taskStatus}\n</task-status>`)
|
|
211
|
+
|
|
212
|
+
// 7. Final directive (R3: active, not passive)
|
|
82
213
|
parts.push(`<ready>
|
|
83
|
-
Context loaded.
|
|
214
|
+
Context loaded. Steps 1-3 (workflow, context, guidelines) are already injected above — do NOT re-read them.
|
|
215
|
+
Start from Step 4. Wait for user's first message, then follow <instructions> to handle their request.
|
|
216
|
+
If there is an active task, ask whether to continue it.
|
|
84
217
|
</ready>`)
|
|
85
218
|
|
|
86
219
|
return parts.join("\n\n")
|
|
@@ -392,6 +392,19 @@ Here's my understanding of the complete requirements:
|
|
|
392
392
|
Does this look correct? If yes, I'll proceed with implementation.
|
|
393
393
|
```
|
|
394
394
|
|
|
395
|
+
### Subtask Decomposition (Complex Tasks)
|
|
396
|
+
|
|
397
|
+
For complex tasks with multiple independent work items, create subtasks:
|
|
398
|
+
|
|
399
|
+
```bash
|
|
400
|
+
# Create child tasks
|
|
401
|
+
CHILD1=$(python3 ./.trellis/scripts/task.py create "Child task 1" --slug child1 --parent "$TASK_DIR")
|
|
402
|
+
CHILD2=$(python3 ./.trellis/scripts/task.py create "Child task 2" --slug child2 --parent "$TASK_DIR")
|
|
403
|
+
|
|
404
|
+
# Or link existing tasks
|
|
405
|
+
python3 ./.trellis/scripts/task.py add-subtask "$TASK_DIR" "$CHILD_DIR"
|
|
406
|
+
```
|
|
407
|
+
|
|
395
408
|
---
|
|
396
409
|
|
|
397
410
|
## PRD Target Structure (final)
|
|
@@ -17,7 +17,10 @@ description: "Record work progress after human has tested and committed code"
|
|
|
17
17
|
python3 ./.trellis/scripts/get_context.py --mode record
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
[!]
|
|
20
|
+
[!] Archive tasks whose work is **actually done** — judge by work status, not the `status` field in task.json:
|
|
21
|
+
- Code committed? → Archive it (don't wait for PR)
|
|
22
|
+
- All acceptance criteria met? → Archive it
|
|
23
|
+
- Don't skip archiving just because `status` still says `planning` or `in_progress`
|
|
21
24
|
|
|
22
25
|
```bash
|
|
23
26
|
python3 ./.trellis/scripts/task.py archive <task-name>
|