@mindfoldhq/trellis 0.4.0-beta.8 → 0.4.0-beta.9
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 +10 -5
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +33 -9
- package/dist/commands/init.js.map +1 -1
- package/dist/configurators/codex.d.ts.map +1 -1
- package/dist/configurators/codex.js +2 -1
- package/dist/configurators/codex.js.map +1 -1
- package/dist/configurators/copilot.d.ts +9 -0
- package/dist/configurators/copilot.d.ts.map +1 -0
- package/dist/configurators/copilot.js +34 -0
- package/dist/configurators/copilot.js.map +1 -0
- package/dist/configurators/index.d.ts.map +1 -1
- package/dist/configurators/index.js +32 -1
- package/dist/configurators/index.js.map +1 -1
- package/dist/configurators/windsurf.d.ts +8 -0
- package/dist/configurators/windsurf.d.ts.map +1 -0
- package/dist/configurators/windsurf.js +18 -0
- package/dist/configurators/windsurf.js.map +1 -0
- package/dist/migrations/manifests/0.4.0-beta.9.json +9 -0
- package/dist/templates/claude/hooks/inject-subagent-context.py +8 -1
- package/dist/templates/claude/hooks/ralph-loop.py +8 -1
- package/dist/templates/claude/hooks/session-start.py +31 -7
- package/dist/templates/claude/hooks/statusline.py +211 -0
- package/dist/templates/claude/settings.json +4 -0
- package/dist/templates/codex/hooks/session-start.py +31 -7
- package/dist/templates/codex/hooks.json +1 -1
- package/dist/templates/copilot/hooks/session-start.py +218 -0
- package/dist/templates/copilot/hooks.json +11 -0
- package/dist/templates/copilot/index.d.ts +23 -0
- package/dist/templates/copilot/index.d.ts.map +1 -0
- package/dist/templates/copilot/index.js +54 -0
- package/dist/templates/copilot/index.js.map +1 -0
- package/dist/templates/copilot/prompts/before-dev.prompt.md +33 -0
- package/dist/templates/copilot/prompts/brainstorm.prompt.md +491 -0
- package/dist/templates/copilot/prompts/break-loop.prompt.md +129 -0
- package/dist/templates/copilot/prompts/check-cross-layer.prompt.md +157 -0
- package/dist/templates/copilot/prompts/check.prompt.md +29 -0
- package/dist/templates/copilot/prompts/create-command.prompt.md +116 -0
- package/dist/templates/copilot/prompts/finish-work.prompt.md +157 -0
- package/dist/templates/copilot/prompts/integrate-skill.prompt.md +223 -0
- package/dist/templates/copilot/prompts/onboard.prompt.md +362 -0
- package/dist/templates/copilot/prompts/parallel.prompt.md +196 -0
- package/dist/templates/copilot/prompts/record-session.prompt.md +66 -0
- package/dist/templates/copilot/prompts/start.prompt.md +397 -0
- package/dist/templates/copilot/prompts/update-spec.prompt.md +358 -0
- package/dist/templates/extract.d.ts +18 -0
- package/dist/templates/extract.d.ts.map +1 -1
- package/dist/templates/extract.js +32 -0
- package/dist/templates/extract.js.map +1 -1
- package/dist/templates/iflow/hooks/inject-subagent-context.py +8 -1
- package/dist/templates/iflow/hooks/ralph-loop.py +8 -1
- package/dist/templates/iflow/hooks/session-start.py +31 -7
- package/dist/templates/markdown/spec/backend/directory-structure.md +1 -1
- package/dist/templates/opencode/agents/dispatch.md +20 -19
- package/dist/templates/opencode/lib/trellis-context.js +42 -2
- package/dist/templates/opencode/plugins/session-start.js +7 -27
- package/dist/templates/trellis/scripts/add_session.py +6 -1
- package/dist/templates/trellis/scripts/common/__init__.py +2 -0
- package/dist/templates/trellis/scripts/common/cli_adapter.py +87 -9
- package/dist/templates/trellis/scripts/common/paths.py +57 -6
- package/dist/templates/trellis/scripts/common/task_store.py +6 -4
- package/dist/templates/trellis/scripts/common/task_utils.py +14 -8
- package/dist/templates/trellis/scripts/multi_agent/start.py +9 -5
- package/dist/templates/trellis/scripts/task.py +1 -1
- package/dist/templates/windsurf/index.d.ts +21 -0
- package/dist/templates/windsurf/index.d.ts.map +1 -0
- package/dist/templates/windsurf/index.js +44 -0
- package/dist/templates/windsurf/index.js.map +1 -0
- package/dist/templates/windsurf/workflows/trellis-before-dev.md +31 -0
- package/dist/templates/windsurf/workflows/trellis-brainstorm.md +491 -0
- package/dist/templates/windsurf/workflows/trellis-break-loop.md +111 -0
- package/dist/templates/windsurf/workflows/trellis-check-cross-layer.md +157 -0
- package/dist/templates/windsurf/workflows/trellis-check.md +27 -0
- package/dist/templates/windsurf/workflows/trellis-create-command.md +154 -0
- package/dist/templates/windsurf/workflows/trellis-finish-work.md +147 -0
- package/dist/templates/windsurf/workflows/trellis-integrate-skill.md +220 -0
- package/dist/templates/windsurf/workflows/trellis-onboard.md +362 -0
- package/dist/templates/windsurf/workflows/trellis-record-session.md +66 -0
- package/dist/templates/windsurf/workflows/trellis-start.md +373 -0
- package/dist/templates/windsurf/workflows/trellis-update-spec.md +358 -0
- package/dist/types/ai-tools.d.ts +5 -3
- package/dist/types/ai-tools.d.ts.map +1 -1
- package/dist/types/ai-tools.js +21 -1
- package/dist/types/ai-tools.js.map +1 -1
- package/dist/utils/template-fetcher.d.ts +17 -4
- package/dist/utils/template-fetcher.d.ts.map +1 -1
- package/dist/utils/template-fetcher.js +94 -12
- package/dist/utils/template-fetcher.js.map +1 -1
- package/package.json +1 -1
|
@@ -65,23 +65,47 @@ def run_script(script_path: Path) -> str:
|
|
|
65
65
|
return "No context available"
|
|
66
66
|
|
|
67
67
|
|
|
68
|
+
def _normalize_task_ref(task_ref: str) -> str:
|
|
69
|
+
normalized = task_ref.strip()
|
|
70
|
+
if not normalized:
|
|
71
|
+
return ""
|
|
72
|
+
|
|
73
|
+
path_obj = Path(normalized)
|
|
74
|
+
if path_obj.is_absolute():
|
|
75
|
+
return str(path_obj)
|
|
76
|
+
|
|
77
|
+
normalized = normalized.replace("\\", "/")
|
|
78
|
+
while normalized.startswith("./"):
|
|
79
|
+
normalized = normalized[2:]
|
|
80
|
+
|
|
81
|
+
if normalized.startswith("tasks/"):
|
|
82
|
+
return f".trellis/{normalized}"
|
|
83
|
+
|
|
84
|
+
return normalized
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _resolve_task_dir(trellis_dir: Path, task_ref: str) -> Path:
|
|
88
|
+
normalized = _normalize_task_ref(task_ref)
|
|
89
|
+
path_obj = Path(normalized)
|
|
90
|
+
if path_obj.is_absolute():
|
|
91
|
+
return path_obj
|
|
92
|
+
if normalized.startswith(".trellis/"):
|
|
93
|
+
return trellis_dir.parent / path_obj
|
|
94
|
+
return trellis_dir / "tasks" / path_obj
|
|
95
|
+
|
|
96
|
+
|
|
68
97
|
def _get_task_status(trellis_dir: Path) -> str:
|
|
69
98
|
"""Check current task status and return structured status string."""
|
|
70
99
|
current_task_file = trellis_dir / ".current-task"
|
|
71
100
|
if not current_task_file.is_file():
|
|
72
101
|
return "Status: NO ACTIVE TASK\nNext: Describe what you want to work on"
|
|
73
102
|
|
|
74
|
-
task_ref = current_task_file.read_text(encoding="utf-8").strip()
|
|
103
|
+
task_ref = _normalize_task_ref(current_task_file.read_text(encoding="utf-8").strip())
|
|
75
104
|
if not task_ref:
|
|
76
105
|
return "Status: NO ACTIVE TASK\nNext: Describe what you want to work on"
|
|
77
106
|
|
|
78
107
|
# Resolve task directory
|
|
79
|
-
|
|
80
|
-
task_dir = Path(task_ref)
|
|
81
|
-
elif task_ref.startswith(".trellis/"):
|
|
82
|
-
task_dir = trellis_dir.parent / task_ref
|
|
83
|
-
else:
|
|
84
|
-
task_dir = trellis_dir / "tasks" / task_ref
|
|
108
|
+
task_dir = _resolve_task_dir(trellis_dir, task_ref)
|
|
85
109
|
if not task_dir.is_dir():
|
|
86
110
|
return f"Status: STALE POINTER\nTask: {task_ref}\nNext: Task directory not found. Run: python3 ./.trellis/scripts/task.py finish"
|
|
87
111
|
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Trellis StatusLine — project-level status display for Claude Code.
|
|
5
|
+
|
|
6
|
+
Reads Claude Code session JSON from stdin + Trellis task data from filesystem.
|
|
7
|
+
Outputs 1-2 lines:
|
|
8
|
+
With active task: [P1] Task title (status) + info line
|
|
9
|
+
Without task: info line only
|
|
10
|
+
Info line: model · ctx% · branch · duration · developer · tasks · rate limits
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import re
|
|
16
|
+
import subprocess
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _read_text(path: Path) -> str:
|
|
22
|
+
try:
|
|
23
|
+
return path.read_text(encoding="utf-8").strip()
|
|
24
|
+
except (FileNotFoundError, PermissionError, OSError):
|
|
25
|
+
return ""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _read_json(path: Path) -> dict:
|
|
29
|
+
text = _read_text(path)
|
|
30
|
+
if not text:
|
|
31
|
+
return {}
|
|
32
|
+
try:
|
|
33
|
+
return json.loads(text)
|
|
34
|
+
except (json.JSONDecodeError, ValueError):
|
|
35
|
+
return {}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _normalize_task_ref(task_ref: str) -> str:
|
|
39
|
+
normalized = task_ref.strip()
|
|
40
|
+
if not normalized:
|
|
41
|
+
return ""
|
|
42
|
+
|
|
43
|
+
path_obj = Path(normalized)
|
|
44
|
+
if path_obj.is_absolute():
|
|
45
|
+
return str(path_obj)
|
|
46
|
+
|
|
47
|
+
normalized = normalized.replace("\\", "/")
|
|
48
|
+
while normalized.startswith("./"):
|
|
49
|
+
normalized = normalized[2:]
|
|
50
|
+
|
|
51
|
+
if normalized.startswith("tasks/"):
|
|
52
|
+
return f".trellis/{normalized}"
|
|
53
|
+
|
|
54
|
+
return normalized
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _resolve_task_dir(trellis_dir: Path, task_ref: str) -> Path:
|
|
58
|
+
normalized = _normalize_task_ref(task_ref)
|
|
59
|
+
path_obj = Path(normalized)
|
|
60
|
+
if path_obj.is_absolute():
|
|
61
|
+
return path_obj
|
|
62
|
+
if normalized.startswith(".trellis/"):
|
|
63
|
+
return trellis_dir.parent / path_obj
|
|
64
|
+
return trellis_dir / "tasks" / path_obj
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _find_trellis_dir() -> Path | None:
|
|
68
|
+
"""Walk up from cwd to find .trellis/ directory."""
|
|
69
|
+
current = Path.cwd()
|
|
70
|
+
for parent in [current, *current.parents]:
|
|
71
|
+
candidate = parent / ".trellis"
|
|
72
|
+
if candidate.is_dir():
|
|
73
|
+
return candidate
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _get_current_task(trellis_dir: Path) -> dict | None:
|
|
78
|
+
"""Load current task info. Returns dict with title/status/priority or None."""
|
|
79
|
+
task_ref = _normalize_task_ref(_read_text(trellis_dir / ".current-task"))
|
|
80
|
+
if not task_ref:
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
# Resolve task directory
|
|
84
|
+
task_path = _resolve_task_dir(trellis_dir, task_ref)
|
|
85
|
+
task_data = _read_json(task_path / "task.json")
|
|
86
|
+
if not task_data:
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
"title": task_data.get("title") or task_data.get("name") or "unknown",
|
|
91
|
+
"status": task_data.get("status", "unknown"),
|
|
92
|
+
"priority": task_data.get("priority", "P2"),
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _count_active_tasks(trellis_dir: Path) -> int:
|
|
97
|
+
"""Count non-archived task directories with valid task.json."""
|
|
98
|
+
tasks_dir = trellis_dir / "tasks"
|
|
99
|
+
if not tasks_dir.is_dir():
|
|
100
|
+
return 0
|
|
101
|
+
count = 0
|
|
102
|
+
for d in tasks_dir.iterdir():
|
|
103
|
+
if d.is_dir() and d.name != "archive" and (d / "task.json").is_file():
|
|
104
|
+
count += 1
|
|
105
|
+
return count
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _get_developer(trellis_dir: Path) -> str:
|
|
109
|
+
content = _read_text(trellis_dir / ".developer")
|
|
110
|
+
if not content:
|
|
111
|
+
return "unknown"
|
|
112
|
+
for line in content.splitlines():
|
|
113
|
+
if line.startswith("name="):
|
|
114
|
+
return line[5:].strip()
|
|
115
|
+
return content.splitlines()[0].strip() or "unknown"
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _get_git_branch() -> str:
|
|
119
|
+
try:
|
|
120
|
+
result = subprocess.run(
|
|
121
|
+
["git", "branch", "--show-current"],
|
|
122
|
+
capture_output=True, text=True, timeout=3,
|
|
123
|
+
)
|
|
124
|
+
return result.stdout.strip() if result.returncode == 0 else ""
|
|
125
|
+
except (FileNotFoundError, subprocess.TimeoutExpired):
|
|
126
|
+
return ""
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _format_ctx_size(size: int) -> str:
|
|
130
|
+
if size >= 1_000_000:
|
|
131
|
+
return f"{size // 1_000_000}M"
|
|
132
|
+
if size >= 1_000:
|
|
133
|
+
return f"{size // 1_000}K"
|
|
134
|
+
return str(size)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _format_duration(ms: int) -> str:
|
|
138
|
+
secs = ms // 1000
|
|
139
|
+
hours, remainder = divmod(secs, 3600)
|
|
140
|
+
mins = remainder // 60
|
|
141
|
+
if hours > 0:
|
|
142
|
+
return f"{hours}h{mins}m"
|
|
143
|
+
return f"{mins}m"
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def main() -> None:
|
|
147
|
+
# Read Claude Code session JSON from stdin
|
|
148
|
+
try:
|
|
149
|
+
cc_data = json.loads(sys.stdin.read())
|
|
150
|
+
except (json.JSONDecodeError, ValueError):
|
|
151
|
+
cc_data = {}
|
|
152
|
+
|
|
153
|
+
trellis_dir = _find_trellis_dir()
|
|
154
|
+
SEP = " \033[90m·\033[0m "
|
|
155
|
+
|
|
156
|
+
# --- Trellis data ---
|
|
157
|
+
task = _get_current_task(trellis_dir) if trellis_dir else None
|
|
158
|
+
dev = _get_developer(trellis_dir) if trellis_dir else ""
|
|
159
|
+
task_count = _count_active_tasks(trellis_dir) if trellis_dir else 0
|
|
160
|
+
|
|
161
|
+
# --- CC session data ---
|
|
162
|
+
model = cc_data.get("model", {}).get("display_name", "?")
|
|
163
|
+
ctx_pct = int(cc_data.get("context_window", {}).get("used_percentage") or 0)
|
|
164
|
+
ctx_size = _format_ctx_size(cc_data.get("context_window", {}).get("context_window_size") or 0)
|
|
165
|
+
duration = _format_duration(cc_data.get("cost", {}).get("total_duration_ms") or 0)
|
|
166
|
+
branch = _get_git_branch()
|
|
167
|
+
|
|
168
|
+
# Avoid "Opus 4.6 (1M context) (1M)"
|
|
169
|
+
if re.search(r"\d+[KMG]\b", model, re.IGNORECASE):
|
|
170
|
+
model_label = model
|
|
171
|
+
else:
|
|
172
|
+
model_label = f"{model} ({ctx_size})"
|
|
173
|
+
|
|
174
|
+
# Context % with color
|
|
175
|
+
if ctx_pct >= 90:
|
|
176
|
+
ctx_color = "\033[31m"
|
|
177
|
+
elif ctx_pct >= 70:
|
|
178
|
+
ctx_color = "\033[33m"
|
|
179
|
+
else:
|
|
180
|
+
ctx_color = "\033[32m"
|
|
181
|
+
|
|
182
|
+
# Build info line: model · ctx · branch · duration · dev · tasks [· rate limits]
|
|
183
|
+
parts = [
|
|
184
|
+
model_label,
|
|
185
|
+
f"ctx {ctx_color}{ctx_pct}%\033[0m",
|
|
186
|
+
]
|
|
187
|
+
if branch:
|
|
188
|
+
parts.append(f"\033[35m{branch}\033[0m")
|
|
189
|
+
parts.append(duration)
|
|
190
|
+
if dev:
|
|
191
|
+
parts.append(f"\033[32m{dev}\033[0m")
|
|
192
|
+
if task_count:
|
|
193
|
+
parts.append(f"{task_count} task(s)")
|
|
194
|
+
|
|
195
|
+
five_hr = cc_data.get("rate_limits", {}).get("five_hour", {}).get("used_percentage")
|
|
196
|
+
if five_hr is not None:
|
|
197
|
+
parts.append(f"5h {int(five_hr)}%")
|
|
198
|
+
seven_day = cc_data.get("rate_limits", {}).get("seven_day", {}).get("used_percentage")
|
|
199
|
+
if seven_day is not None:
|
|
200
|
+
parts.append(f"7d {int(seven_day)}%")
|
|
201
|
+
|
|
202
|
+
info_line = SEP.join(parts)
|
|
203
|
+
|
|
204
|
+
# Output: task line (only if active) + info line
|
|
205
|
+
if task:
|
|
206
|
+
print(f"\033[36m[{task['priority']}]\033[0m {task['title']} \033[33m({task['status']})\033[0m")
|
|
207
|
+
print(info_line)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
if __name__ == "__main__":
|
|
211
|
+
main()
|
|
@@ -51,21 +51,45 @@ def run_script(script_path: Path) -> str:
|
|
|
51
51
|
return "No context available"
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
def _normalize_task_ref(task_ref: str) -> str:
|
|
55
|
+
normalized = task_ref.strip()
|
|
56
|
+
if not normalized:
|
|
57
|
+
return ""
|
|
58
|
+
|
|
59
|
+
path_obj = Path(normalized)
|
|
60
|
+
if path_obj.is_absolute():
|
|
61
|
+
return str(path_obj)
|
|
62
|
+
|
|
63
|
+
normalized = normalized.replace("\\", "/")
|
|
64
|
+
while normalized.startswith("./"):
|
|
65
|
+
normalized = normalized[2:]
|
|
66
|
+
|
|
67
|
+
if normalized.startswith("tasks/"):
|
|
68
|
+
return f".trellis/{normalized}"
|
|
69
|
+
|
|
70
|
+
return normalized
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _resolve_task_dir(trellis_dir: Path, task_ref: str) -> Path:
|
|
74
|
+
normalized = _normalize_task_ref(task_ref)
|
|
75
|
+
path_obj = Path(normalized)
|
|
76
|
+
if path_obj.is_absolute():
|
|
77
|
+
return path_obj
|
|
78
|
+
if normalized.startswith(".trellis/"):
|
|
79
|
+
return trellis_dir.parent / path_obj
|
|
80
|
+
return trellis_dir / "tasks" / path_obj
|
|
81
|
+
|
|
82
|
+
|
|
54
83
|
def _get_task_status(trellis_dir: Path) -> str:
|
|
55
84
|
current_task_file = trellis_dir / ".current-task"
|
|
56
85
|
if not current_task_file.is_file():
|
|
57
86
|
return "Status: NO ACTIVE TASK\nNext: Describe what you want to work on"
|
|
58
87
|
|
|
59
|
-
task_ref = current_task_file.read_text(encoding="utf-8").strip()
|
|
88
|
+
task_ref = _normalize_task_ref(current_task_file.read_text(encoding="utf-8").strip())
|
|
60
89
|
if not task_ref:
|
|
61
90
|
return "Status: NO ACTIVE TASK\nNext: Describe what you want to work on"
|
|
62
91
|
|
|
63
|
-
|
|
64
|
-
task_dir = Path(task_ref)
|
|
65
|
-
elif task_ref.startswith(".trellis/"):
|
|
66
|
-
task_dir = trellis_dir.parent / task_ref
|
|
67
|
-
else:
|
|
68
|
-
task_dir = trellis_dir / "tasks" / task_ref
|
|
92
|
+
task_dir = _resolve_task_dir(trellis_dir, task_ref)
|
|
69
93
|
if not task_dir.is_dir():
|
|
70
94
|
return f"Status: STALE POINTER\nTask: {task_ref}\nNext: Task directory not found. Run: python3 ./.trellis/scripts/task.py finish"
|
|
71
95
|
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Copilot Session Start Hook - Inject Trellis context into VS Code Copilot sessions.
|
|
5
|
+
|
|
6
|
+
Output format follows Copilot hook protocol:
|
|
7
|
+
stdout JSON → { hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: "..." } }
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
import warnings
|
|
17
|
+
from io import StringIO
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
warnings.filterwarnings("ignore")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def should_skip_injection() -> bool:
|
|
24
|
+
return os.environ.get("COPILOT_NON_INTERACTIVE") == "1"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def read_file(path: Path, fallback: str = "") -> str:
|
|
28
|
+
try:
|
|
29
|
+
return path.read_text(encoding="utf-8")
|
|
30
|
+
except (FileNotFoundError, PermissionError):
|
|
31
|
+
return fallback
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def run_script(script_path: Path) -> str:
|
|
35
|
+
try:
|
|
36
|
+
env = os.environ.copy()
|
|
37
|
+
env["PYTHONIOENCODING"] = "utf-8"
|
|
38
|
+
cmd = [sys.executable, "-W", "ignore", str(script_path)]
|
|
39
|
+
result = subprocess.run(
|
|
40
|
+
cmd,
|
|
41
|
+
capture_output=True,
|
|
42
|
+
text=True,
|
|
43
|
+
encoding="utf-8",
|
|
44
|
+
errors="replace",
|
|
45
|
+
timeout=5,
|
|
46
|
+
cwd=str(script_path.parent.parent.parent),
|
|
47
|
+
env=env,
|
|
48
|
+
)
|
|
49
|
+
return result.stdout if result.returncode == 0 else "No context available"
|
|
50
|
+
except (subprocess.TimeoutExpired, FileNotFoundError, PermissionError):
|
|
51
|
+
return "No context available"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _normalize_task_ref(task_ref: str) -> str:
|
|
55
|
+
normalized = task_ref.strip()
|
|
56
|
+
if not normalized:
|
|
57
|
+
return ""
|
|
58
|
+
|
|
59
|
+
path_obj = Path(normalized)
|
|
60
|
+
if path_obj.is_absolute():
|
|
61
|
+
return str(path_obj)
|
|
62
|
+
|
|
63
|
+
normalized = normalized.replace("\\", "/")
|
|
64
|
+
while normalized.startswith("./"):
|
|
65
|
+
normalized = normalized[2:]
|
|
66
|
+
|
|
67
|
+
if normalized.startswith("tasks/"):
|
|
68
|
+
return f".trellis/{normalized}"
|
|
69
|
+
|
|
70
|
+
return normalized
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _resolve_task_dir(trellis_dir: Path, task_ref: str) -> Path:
|
|
74
|
+
normalized = _normalize_task_ref(task_ref)
|
|
75
|
+
path_obj = Path(normalized)
|
|
76
|
+
if path_obj.is_absolute():
|
|
77
|
+
return path_obj
|
|
78
|
+
if normalized.startswith(".trellis/"):
|
|
79
|
+
return trellis_dir.parent / path_obj
|
|
80
|
+
return trellis_dir / "tasks" / path_obj
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _get_task_status(trellis_dir: Path) -> str:
|
|
84
|
+
current_task_file = trellis_dir / ".current-task"
|
|
85
|
+
if not current_task_file.is_file():
|
|
86
|
+
return "Status: NO ACTIVE TASK\nNext: Describe what you want to work on"
|
|
87
|
+
|
|
88
|
+
task_ref = _normalize_task_ref(current_task_file.read_text(encoding="utf-8").strip())
|
|
89
|
+
if not task_ref:
|
|
90
|
+
return "Status: NO ACTIVE TASK\nNext: Describe what you want to work on"
|
|
91
|
+
|
|
92
|
+
task_dir = _resolve_task_dir(trellis_dir, task_ref)
|
|
93
|
+
if not task_dir.is_dir():
|
|
94
|
+
return f"Status: STALE POINTER\nTask: {task_ref}\nNext: Task directory not found. Run: python3 ./.trellis/scripts/task.py finish"
|
|
95
|
+
|
|
96
|
+
task_json_path = task_dir / "task.json"
|
|
97
|
+
task_data: dict = {}
|
|
98
|
+
if task_json_path.is_file():
|
|
99
|
+
try:
|
|
100
|
+
task_data = json.loads(task_json_path.read_text(encoding="utf-8"))
|
|
101
|
+
except (json.JSONDecodeError, PermissionError):
|
|
102
|
+
pass
|
|
103
|
+
|
|
104
|
+
task_title = task_data.get("title", task_ref)
|
|
105
|
+
task_status = task_data.get("status", "unknown")
|
|
106
|
+
|
|
107
|
+
if task_status == "completed":
|
|
108
|
+
return f"Status: COMPLETED\nTask: {task_title}\nNext: Archive with `python3 ./.trellis/scripts/task.py archive {task_dir.name}` or start a new task"
|
|
109
|
+
|
|
110
|
+
has_context = False
|
|
111
|
+
for jsonl_name in ("implement.jsonl", "check.jsonl", "spec.jsonl"):
|
|
112
|
+
jsonl_path = task_dir / jsonl_name
|
|
113
|
+
if jsonl_path.is_file() and jsonl_path.stat().st_size > 0:
|
|
114
|
+
has_context = True
|
|
115
|
+
break
|
|
116
|
+
|
|
117
|
+
has_prd = (task_dir / "prd.md").is_file()
|
|
118
|
+
|
|
119
|
+
if not has_prd:
|
|
120
|
+
return f"Status: NOT READY\nTask: {task_title}\nMissing: prd.md not created\nNext: Write PRD, then research → init-context → start"
|
|
121
|
+
|
|
122
|
+
if not has_context:
|
|
123
|
+
return f"Status: NOT READY\nTask: {task_title}\nMissing: Context not configured (no jsonl files)\nNext: Complete Phase 2 (research → init-context → start) before implementing"
|
|
124
|
+
|
|
125
|
+
return f"Status: READY\nTask: {task_title}\nNext: Continue with implement or check"
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def main() -> None:
|
|
129
|
+
if should_skip_injection():
|
|
130
|
+
sys.exit(0)
|
|
131
|
+
|
|
132
|
+
# Read hook input from stdin
|
|
133
|
+
try:
|
|
134
|
+
hook_input = json.loads(sys.stdin.read())
|
|
135
|
+
project_dir = Path(hook_input.get("cwd", ".")).resolve()
|
|
136
|
+
except (json.JSONDecodeError, KeyError):
|
|
137
|
+
project_dir = Path(".").resolve()
|
|
138
|
+
|
|
139
|
+
trellis_dir = project_dir / ".trellis"
|
|
140
|
+
|
|
141
|
+
output = StringIO()
|
|
142
|
+
|
|
143
|
+
output.write("""<session-context>
|
|
144
|
+
You are starting a new session in a Trellis-managed project.
|
|
145
|
+
Read and follow all instructions below carefully.
|
|
146
|
+
</session-context>
|
|
147
|
+
|
|
148
|
+
""")
|
|
149
|
+
|
|
150
|
+
output.write("<current-state>\n")
|
|
151
|
+
context_script = trellis_dir / "scripts" / "get_context.py"
|
|
152
|
+
output.write(run_script(context_script))
|
|
153
|
+
output.write("\n</current-state>\n\n")
|
|
154
|
+
|
|
155
|
+
output.write("<workflow>\n")
|
|
156
|
+
workflow_content = read_file(trellis_dir / "workflow.md", "No workflow.md found")
|
|
157
|
+
output.write(workflow_content)
|
|
158
|
+
output.write("\n</workflow>\n\n")
|
|
159
|
+
|
|
160
|
+
output.write("<guidelines>\n")
|
|
161
|
+
output.write("**Note**: The guidelines below are index files — they list available guideline documents and their locations.\n")
|
|
162
|
+
output.write("During actual development, you MUST read the specific guideline files listed in each index's Pre-Development Checklist.\n\n")
|
|
163
|
+
|
|
164
|
+
spec_dir = trellis_dir / "spec"
|
|
165
|
+
if spec_dir.is_dir():
|
|
166
|
+
for sub in sorted(spec_dir.iterdir()):
|
|
167
|
+
if not sub.is_dir() or sub.name.startswith("."):
|
|
168
|
+
continue
|
|
169
|
+
|
|
170
|
+
if sub.name == "guides":
|
|
171
|
+
index_file = sub / "index.md"
|
|
172
|
+
if index_file.is_file():
|
|
173
|
+
output.write(f"## {sub.name}\n")
|
|
174
|
+
output.write(read_file(index_file))
|
|
175
|
+
output.write("\n\n")
|
|
176
|
+
continue
|
|
177
|
+
|
|
178
|
+
index_file = sub / "index.md"
|
|
179
|
+
if index_file.is_file():
|
|
180
|
+
output.write(f"## {sub.name}\n")
|
|
181
|
+
output.write(read_file(index_file))
|
|
182
|
+
output.write("\n\n")
|
|
183
|
+
else:
|
|
184
|
+
for nested in sorted(sub.iterdir()):
|
|
185
|
+
if not nested.is_dir():
|
|
186
|
+
continue
|
|
187
|
+
nested_index = nested / "index.md"
|
|
188
|
+
if nested_index.is_file():
|
|
189
|
+
output.write(f"## {sub.name}/{nested.name}\n")
|
|
190
|
+
output.write(read_file(nested_index))
|
|
191
|
+
output.write("\n\n")
|
|
192
|
+
|
|
193
|
+
output.write("</guidelines>\n\n")
|
|
194
|
+
|
|
195
|
+
task_status = _get_task_status(trellis_dir)
|
|
196
|
+
output.write(f"<task-status>\n{task_status}\n</task-status>\n\n")
|
|
197
|
+
|
|
198
|
+
output.write("""<ready>
|
|
199
|
+
Context loaded. Steps 1-3 (workflow, context, guidelines) are already injected above — do NOT re-read them.
|
|
200
|
+
Start from Step 4. Wait for user's first message, then follow the workflow to handle their request.
|
|
201
|
+
If there is an active task, ask whether to continue it.
|
|
202
|
+
</ready>""")
|
|
203
|
+
|
|
204
|
+
context = output.getvalue()
|
|
205
|
+
result = {
|
|
206
|
+
"suppressOutput": True,
|
|
207
|
+
"systemMessage": f"Trellis context injected ({len(context)} chars)",
|
|
208
|
+
"hookSpecificOutput": {
|
|
209
|
+
"hookEventName": "SessionStart",
|
|
210
|
+
"additionalContext": context,
|
|
211
|
+
},
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
print(json.dumps(result, ensure_ascii=False), flush=True)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
if __name__ == "__main__":
|
|
218
|
+
main()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copilot templates
|
|
3
|
+
*
|
|
4
|
+
* These are GENERIC templates for user projects.
|
|
5
|
+
*
|
|
6
|
+
* Directory structure:
|
|
7
|
+
* copilot/
|
|
8
|
+
* ├── prompts/ # Slash-command prompts → .github/prompts/*.prompt.md
|
|
9
|
+
* ├── hooks/ # Hook scripts → .github/copilot/hooks/
|
|
10
|
+
* └── hooks.json # Hooks config → .github/hooks/trellis.json
|
|
11
|
+
*/
|
|
12
|
+
export interface HookTemplate {
|
|
13
|
+
name: string;
|
|
14
|
+
content: string;
|
|
15
|
+
}
|
|
16
|
+
export interface PromptTemplate {
|
|
17
|
+
name: string;
|
|
18
|
+
content: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function getAllHooks(): HookTemplate[];
|
|
21
|
+
export declare function getHooksConfig(): string;
|
|
22
|
+
export declare function getAllPrompts(): PromptTemplate[];
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/templates/copilot/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAqBH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,WAAW,IAAI,YAAY,EAAE,CAW5C;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,aAAa,IAAI,cAAc,EAAE,CAchD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copilot templates
|
|
3
|
+
*
|
|
4
|
+
* These are GENERIC templates for user projects.
|
|
5
|
+
*
|
|
6
|
+
* Directory structure:
|
|
7
|
+
* copilot/
|
|
8
|
+
* ├── prompts/ # Slash-command prompts → .github/prompts/*.prompt.md
|
|
9
|
+
* ├── hooks/ # Hook scripts → .github/copilot/hooks/
|
|
10
|
+
* └── hooks.json # Hooks config → .github/hooks/trellis.json
|
|
11
|
+
*/
|
|
12
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = dirname(__filename);
|
|
17
|
+
function readTemplate(relativePath) {
|
|
18
|
+
return readFileSync(join(__dirname, relativePath), "utf-8");
|
|
19
|
+
}
|
|
20
|
+
function listFiles(dir) {
|
|
21
|
+
try {
|
|
22
|
+
return readdirSync(join(__dirname, dir)).sort();
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function getAllHooks() {
|
|
29
|
+
const hooks = [];
|
|
30
|
+
for (const file of listFiles("hooks")) {
|
|
31
|
+
if (!file.endsWith(".py")) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
hooks.push({ name: file, content: readTemplate(`hooks/${file}`) });
|
|
35
|
+
}
|
|
36
|
+
return hooks;
|
|
37
|
+
}
|
|
38
|
+
export function getHooksConfig() {
|
|
39
|
+
return readTemplate("hooks.json");
|
|
40
|
+
}
|
|
41
|
+
export function getAllPrompts() {
|
|
42
|
+
const prompts = [];
|
|
43
|
+
for (const file of listFiles("prompts")) {
|
|
44
|
+
if (!file.endsWith(".prompt.md")) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
prompts.push({
|
|
48
|
+
name: file.slice(0, -".prompt.md".length),
|
|
49
|
+
content: readTemplate(`prompts/${file}`),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return prompts;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/templates/copilot/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,SAAS,YAAY,CAAC,YAAoB;IACxC,OAAO,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,SAAS,CAAC,GAAW;IAC5B,IAAI,CAAC;QACH,OAAO,WAAW,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAYD,MAAM,UAAU,WAAW;IACzB,MAAM,KAAK,GAAmB,EAAE,CAAC;IAEjC,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,SAAS;QACX,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,YAAY,CAAC,YAAY,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,MAAM,OAAO,GAAqB,EAAE,CAAC;IAErC,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;YACjC,SAAS;QACX,CAAC;QACD,OAAO,CAAC,IAAI,CAAC;YACX,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC;YACzC,OAAO,EAAE,YAAY,CAAC,WAAW,IAAI,EAAE,CAAC;SACzC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|