@mindfoldhq/trellis 0.3.8 → 0.3.10-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) 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.3.9.json +9 -0
  19. package/dist/migrations/manifests/0.4.0-beta.1.json +228 -0
  20. package/dist/templates/claude/agents/dispatch.md +1 -2
  21. package/dist/templates/claude/agents/implement.md +2 -3
  22. package/dist/templates/claude/commands/trellis/before-dev.md +29 -0
  23. package/dist/templates/claude/commands/trellis/check.md +25 -0
  24. package/dist/templates/claude/commands/trellis/create-command.md +2 -2
  25. package/dist/templates/claude/commands/trellis/onboard.md +13 -13
  26. package/dist/templates/claude/commands/trellis/parallel.md +1 -2
  27. package/dist/templates/claude/commands/trellis/record-session.md +1 -1
  28. package/dist/templates/claude/commands/trellis/start.md +8 -4
  29. package/dist/templates/claude/hooks/inject-subagent-context.py +21 -13
  30. package/dist/templates/claude/hooks/session-start.py +170 -2
  31. package/dist/templates/codex/skills/before-dev/SKILL.md +34 -0
  32. package/dist/templates/codex/skills/check/SKILL.md +30 -0
  33. package/dist/templates/codex/skills/create-command/SKILL.md +2 -2
  34. package/dist/templates/codex/skills/onboard/SKILL.md +11 -11
  35. package/dist/templates/codex/skills/record-session/SKILL.md +1 -1
  36. package/dist/templates/codex/skills/start/SKILL.md +8 -3
  37. package/dist/templates/cursor/commands/trellis-before-dev.md +29 -0
  38. package/dist/templates/cursor/commands/trellis-check.md +25 -0
  39. package/dist/templates/cursor/commands/trellis-create-command.md +2 -2
  40. package/dist/templates/cursor/commands/trellis-onboard.md +13 -13
  41. package/dist/templates/cursor/commands/trellis-record-session.md +1 -1
  42. package/dist/templates/cursor/commands/trellis-start.md +7 -16
  43. package/dist/templates/gemini/commands/trellis/before-dev.toml +33 -0
  44. package/dist/templates/gemini/commands/trellis/check.toml +29 -0
  45. package/dist/templates/gemini/commands/trellis/create-command.toml +2 -2
  46. package/dist/templates/gemini/commands/trellis/onboard.toml +2 -2
  47. package/dist/templates/gemini/commands/trellis/record-session.toml +1 -1
  48. package/dist/templates/gemini/commands/trellis/start.toml +9 -4
  49. package/dist/templates/iflow/agents/dispatch.md +1 -2
  50. package/dist/templates/iflow/agents/implement.md +2 -3
  51. package/dist/templates/iflow/commands/trellis/before-dev.md +29 -0
  52. package/dist/templates/iflow/commands/trellis/check.md +25 -0
  53. package/dist/templates/iflow/commands/trellis/create-command.md +2 -2
  54. package/dist/templates/iflow/commands/trellis/onboard.md +13 -13
  55. package/dist/templates/iflow/commands/trellis/parallel.md +1 -2
  56. package/dist/templates/iflow/commands/trellis/record-session.md +1 -1
  57. package/dist/templates/iflow/commands/trellis/start.md +8 -4
  58. package/dist/templates/iflow/hooks/inject-subagent-context.py +21 -13
  59. package/dist/templates/iflow/hooks/session-start.py +156 -1
  60. package/dist/templates/iflow/settings.json +2 -2
  61. package/dist/templates/kilo/workflows/before-dev.md +29 -0
  62. package/dist/templates/kilo/workflows/check.md +25 -0
  63. package/dist/templates/kilo/workflows/create-command.md +2 -2
  64. package/dist/templates/kilo/workflows/onboard.md +13 -13
  65. package/dist/templates/kilo/workflows/parallel.md +1 -2
  66. package/dist/templates/kilo/workflows/record-session.md +1 -1
  67. package/dist/templates/kilo/workflows/start.md +8 -3
  68. package/dist/templates/kiro/skills/before-dev/SKILL.md +34 -0
  69. package/dist/templates/kiro/skills/check/SKILL.md +30 -0
  70. package/dist/templates/kiro/skills/create-command/SKILL.md +2 -2
  71. package/dist/templates/kiro/skills/onboard/SKILL.md +11 -11
  72. package/dist/templates/kiro/skills/record-session/SKILL.md +1 -1
  73. package/dist/templates/kiro/skills/start/SKILL.md +8 -3
  74. package/dist/templates/markdown/spec/backend/script-conventions.md +93 -0
  75. package/dist/templates/opencode/agents/dispatch.md +1 -2
  76. package/dist/templates/opencode/agents/implement.md +2 -2
  77. package/dist/templates/opencode/agents/research.md +1 -2
  78. package/dist/templates/opencode/commands/trellis/before-dev.md +29 -0
  79. package/dist/templates/opencode/commands/trellis/check.md +25 -0
  80. package/dist/templates/opencode/commands/trellis/create-command.md +2 -2
  81. package/dist/templates/opencode/commands/trellis/onboard.md +13 -13
  82. package/dist/templates/opencode/commands/trellis/parallel.md +1 -2
  83. package/dist/templates/opencode/commands/trellis/record-session.md +1 -1
  84. package/dist/templates/opencode/commands/trellis/start.md +8 -3
  85. package/dist/templates/opencode/plugin/inject-subagent-context.js +45 -18
  86. package/dist/templates/opencode/plugin/session-start.js +149 -1
  87. package/dist/templates/qoder/skills/before-dev/SKILL.md +34 -0
  88. package/dist/templates/qoder/skills/check/SKILL.md +30 -0
  89. package/dist/templates/qoder/skills/create-command/SKILL.md +2 -2
  90. package/dist/templates/qoder/skills/onboard/SKILL.md +13 -13
  91. package/dist/templates/qoder/skills/record-session/SKILL.md +1 -1
  92. package/dist/templates/qoder/skills/start/SKILL.md +8 -3
  93. package/dist/templates/trellis/config.yaml +20 -0
  94. package/dist/templates/trellis/index.d.ts +11 -0
  95. package/dist/templates/trellis/index.d.ts.map +1 -1
  96. package/dist/templates/trellis/index.js +22 -0
  97. package/dist/templates/trellis/index.js.map +1 -1
  98. package/dist/templates/trellis/scripts/add_session.py +52 -7
  99. package/dist/templates/trellis/scripts/common/cli_adapter.py +33 -45
  100. package/dist/templates/trellis/scripts/common/config.py +152 -0
  101. package/dist/templates/trellis/scripts/common/git.py +31 -0
  102. package/dist/templates/trellis/scripts/common/git_context.py +23 -586
  103. package/dist/templates/trellis/scripts/common/io.py +37 -0
  104. package/dist/templates/trellis/scripts/common/log.py +45 -0
  105. package/dist/templates/trellis/scripts/common/packages_context.py +233 -0
  106. package/dist/templates/trellis/scripts/common/paths.py +46 -0
  107. package/dist/templates/trellis/scripts/common/phase.py +50 -49
  108. package/dist/templates/trellis/scripts/common/registry.py +41 -72
  109. package/dist/templates/trellis/scripts/common/session_context.py +466 -0
  110. package/dist/templates/trellis/scripts/common/task_context.py +384 -0
  111. package/dist/templates/trellis/scripts/common/task_queue.py +27 -98
  112. package/dist/templates/trellis/scripts/common/task_store.py +534 -0
  113. package/dist/templates/trellis/scripts/common/task_utils.py +96 -6
  114. package/dist/templates/trellis/scripts/common/tasks.py +109 -0
  115. package/dist/templates/trellis/scripts/common/types.py +112 -0
  116. package/dist/templates/trellis/scripts/create_bootstrap.py +31 -26
  117. package/dist/templates/trellis/scripts/hooks/linear_sync.py +243 -0
  118. package/dist/templates/trellis/scripts/multi_agent/_bootstrap.py +17 -0
  119. package/dist/templates/trellis/scripts/multi_agent/cleanup.py +43 -48
  120. package/dist/templates/trellis/scripts/multi_agent/create_pr.py +336 -45
  121. package/dist/templates/trellis/scripts/multi_agent/plan.py +2 -26
  122. package/dist/templates/trellis/scripts/multi_agent/start.py +126 -57
  123. package/dist/templates/trellis/scripts/multi_agent/status.py +12 -753
  124. package/dist/templates/trellis/scripts/multi_agent/status_display.py +542 -0
  125. package/dist/templates/trellis/scripts/multi_agent/status_monitor.py +225 -0
  126. package/dist/templates/trellis/scripts/task.py +50 -975
  127. package/dist/templates/trellis/workflow.md +21 -34
  128. package/dist/types/migration.d.ts +3 -1
  129. package/dist/types/migration.d.ts.map +1 -1
  130. package/dist/utils/project-detector.d.ts +23 -0
  131. package/dist/utils/project-detector.d.ts.map +1 -1
  132. package/dist/utils/project-detector.js +364 -0
  133. package/dist/utils/project-detector.js.map +1 -1
  134. package/dist/utils/template-fetcher.d.ts +2 -2
  135. package/dist/utils/template-fetcher.d.ts.map +1 -1
  136. package/dist/utils/template-fetcher.js +5 -5
  137. package/dist/utils/template-fetcher.js.map +1 -1
  138. package/package.json +1 -1
  139. package/dist/templates/claude/commands/trellis/before-backend-dev.md +0 -13
  140. package/dist/templates/claude/commands/trellis/before-frontend-dev.md +0 -13
  141. package/dist/templates/claude/commands/trellis/check-backend.md +0 -13
  142. package/dist/templates/claude/commands/trellis/check-frontend.md +0 -13
  143. package/dist/templates/codex/skills/before-backend-dev/SKILL.md +0 -18
  144. package/dist/templates/codex/skills/before-frontend-dev/SKILL.md +0 -18
  145. package/dist/templates/codex/skills/check-backend/SKILL.md +0 -18
  146. package/dist/templates/codex/skills/check-frontend/SKILL.md +0 -18
  147. package/dist/templates/cursor/commands/trellis-before-backend-dev.md +0 -13
  148. package/dist/templates/cursor/commands/trellis-before-frontend-dev.md +0 -13
  149. package/dist/templates/cursor/commands/trellis-check-backend.md +0 -13
  150. package/dist/templates/cursor/commands/trellis-check-frontend.md +0 -13
  151. package/dist/templates/gemini/commands/trellis/before-backend-dev.toml +0 -17
  152. package/dist/templates/gemini/commands/trellis/before-frontend-dev.toml +0 -17
  153. package/dist/templates/gemini/commands/trellis/check-backend.toml +0 -17
  154. package/dist/templates/gemini/commands/trellis/check-frontend.toml +0 -17
  155. package/dist/templates/iflow/commands/trellis/before-backend-dev.md +0 -13
  156. package/dist/templates/iflow/commands/trellis/before-frontend-dev.md +0 -13
  157. package/dist/templates/iflow/commands/trellis/check-backend.md +0 -13
  158. package/dist/templates/iflow/commands/trellis/check-frontend.md +0 -13
  159. package/dist/templates/kilo/workflows/before-backend-dev.md +0 -13
  160. package/dist/templates/kilo/workflows/before-frontend-dev.md +0 -13
  161. package/dist/templates/kilo/workflows/check-backend.md +0 -13
  162. package/dist/templates/kilo/workflows/check-frontend.md +0 -13
  163. package/dist/templates/kiro/skills/before-backend-dev/SKILL.md +0 -18
  164. package/dist/templates/kiro/skills/before-frontend-dev/SKILL.md +0 -18
  165. package/dist/templates/kiro/skills/check-backend/SKILL.md +0 -18
  166. package/dist/templates/kiro/skills/check-frontend/SKILL.md +0 -18
  167. package/dist/templates/opencode/commands/trellis/before-backend-dev.md +0 -13
  168. package/dist/templates/opencode/commands/trellis/before-frontend-dev.md +0 -13
  169. package/dist/templates/opencode/commands/trellis/check-backend.md +0 -13
  170. package/dist/templates/opencode/commands/trellis/check-frontend.md +0 -13
  171. package/dist/templates/qoder/skills/before-backend-dev/SKILL.md +0 -18
  172. package/dist/templates/qoder/skills/before-frontend-dev/SKILL.md +0 -18
  173. package/dist/templates/qoder/skills/check-backend/SKILL.md +0 -18
  174. package/dist/templates/qoder/skills/check-frontend/SKILL.md +0 -18
@@ -0,0 +1,542 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Multi-Agent Pipeline: Status display and formatting.
4
+
5
+ Provides:
6
+ cmd_help - Show help text
7
+ cmd_list - List worktrees and agents
8
+ cmd_summary - Summary of all tasks with agent status
9
+ cmd_detail - Detailed single-agent status
10
+ cmd_registry - Dump agent registry
11
+
12
+ Also exports shared utilities used by status_monitor:
13
+ is_running, find_agent, get_registry_file, calc_elapsed, count_modified_files
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import json
19
+ import os
20
+ import subprocess
21
+ from datetime import datetime
22
+ from pathlib import Path
23
+
24
+ from common.cli_adapter import get_cli_adapter
25
+ from common.io import read_json
26
+ from common.log import Colors
27
+ from common.developer import ensure_developer
28
+ from common.paths import (
29
+ get_repo_root,
30
+ get_tasks_dir,
31
+ )
32
+ from common.phase import get_phase_info
33
+ from common.task_queue import format_task_stats, get_task_stats
34
+ from common.tasks import iter_active_tasks
35
+ from common.worktree import get_agents_dir
36
+
37
+
38
+ # =============================================================================
39
+ # Shared Utilities
40
+ # =============================================================================
41
+
42
+ def is_running(pid: int | str | None) -> bool:
43
+ """Check if PID is running."""
44
+ if not pid:
45
+ return False
46
+ try:
47
+ pid_int = int(pid)
48
+ os.kill(pid_int, 0)
49
+ return True
50
+ except (ProcessLookupError, ValueError, PermissionError, TypeError):
51
+ return False
52
+
53
+
54
+ def status_color(status: str) -> str:
55
+ """Get status color."""
56
+ colors = {
57
+ "completed": Colors.GREEN,
58
+ "in_progress": Colors.BLUE,
59
+ "planning": Colors.YELLOW,
60
+ }
61
+ return colors.get(status, Colors.DIM)
62
+
63
+
64
+ def get_registry_file(repo_root: Path) -> Path | None:
65
+ """Get registry file path."""
66
+ agents_dir = get_agents_dir(repo_root)
67
+ if agents_dir:
68
+ return agents_dir / "registry.json"
69
+ return None
70
+
71
+
72
+ def find_agent(search: str, repo_root: Path) -> dict | None:
73
+ """Find agent by task name or ID."""
74
+ registry_file = get_registry_file(repo_root)
75
+ if not registry_file or not registry_file.is_file():
76
+ return None
77
+
78
+ data = read_json(registry_file)
79
+ if not data:
80
+ return None
81
+
82
+ for agent in data.get("agents", []):
83
+ # Exact ID match
84
+ if agent.get("id") == search:
85
+ return agent
86
+ # Partial match on task_dir
87
+ task_dir = agent.get("task_dir", "")
88
+ if search in task_dir:
89
+ return agent
90
+
91
+ return None
92
+
93
+
94
+ def calc_elapsed(started: str | None) -> str:
95
+ """Calculate elapsed time from ISO timestamp."""
96
+ if not started:
97
+ return "N/A"
98
+
99
+ try:
100
+ # Parse ISO format
101
+ if "+" in started:
102
+ started = started.split("+")[0]
103
+ if "T" in started:
104
+ start_dt = datetime.fromisoformat(started)
105
+ else:
106
+ return "N/A"
107
+
108
+ now = datetime.now()
109
+ elapsed = (now - start_dt).total_seconds()
110
+
111
+ if elapsed < 60:
112
+ return f"{int(elapsed)}s"
113
+ elif elapsed < 3600:
114
+ mins = int(elapsed // 60)
115
+ secs = int(elapsed % 60)
116
+ return f"{mins}m {secs}s"
117
+ else:
118
+ hours = int(elapsed // 3600)
119
+ mins = int((elapsed % 3600) // 60)
120
+ return f"{hours}h {mins}m"
121
+ except (ValueError, TypeError):
122
+ return "N/A"
123
+
124
+
125
+ def count_modified_files(worktree: str) -> int:
126
+ """Count modified files in worktree."""
127
+ if not Path(worktree).is_dir():
128
+ return 0
129
+
130
+ try:
131
+ result = subprocess.run(
132
+ ["git", "status", "--short"],
133
+ cwd=worktree,
134
+ capture_output=True,
135
+ text=True,
136
+ encoding="utf-8",
137
+ errors="replace",
138
+ )
139
+ return len([line for line in result.stdout.splitlines() if line.strip()])
140
+ except Exception:
141
+ return 0
142
+
143
+
144
+ # =============================================================================
145
+ # Commands
146
+ # =============================================================================
147
+
148
+ def cmd_help() -> int:
149
+ """Show help."""
150
+ print("""Multi-Agent Pipeline: Status Monitor
151
+
152
+ Usage:
153
+ python3 status.py Show summary of all tasks
154
+ python3 status.py -a <assignee> Filter tasks by assignee
155
+ python3 status.py --list List all worktrees and agents
156
+ python3 status.py --detail <task> Detailed task status
157
+ python3 status.py --progress <task> Quick progress view with recent activity
158
+ python3 status.py --watch <task> Watch agent log in real-time
159
+ python3 status.py --log <task> Show recent log entries
160
+ python3 status.py --registry Show agent registry
161
+
162
+ Examples:
163
+ python3 status.py -a taosu
164
+ python3 status.py --detail my-task
165
+ python3 status.py --progress my-task
166
+ python3 status.py --watch 01-16-worktree-support
167
+ python3 status.py --log worktree-support
168
+ """)
169
+ return 0
170
+
171
+
172
+ def cmd_list(repo_root: Path) -> int:
173
+ """List worktrees and agents."""
174
+ print(f"{Colors.BLUE}=== Git Worktrees ==={Colors.NC}")
175
+ print()
176
+
177
+ subprocess.run(["git", "worktree", "list"], cwd=repo_root)
178
+ print()
179
+
180
+ print(f"{Colors.BLUE}=== Registered Agents ==={Colors.NC}")
181
+ print()
182
+
183
+ registry_file = get_registry_file(repo_root)
184
+ if not registry_file or not registry_file.is_file():
185
+ print(" (no registry found)")
186
+ return 0
187
+
188
+ data = read_json(registry_file)
189
+ if not data or not data.get("agents"):
190
+ print(" (no agents registered)")
191
+ return 0
192
+
193
+ for agent in data["agents"]:
194
+ agent_id = agent.get("id", "?")
195
+ pid = agent.get("pid")
196
+ wt = agent.get("worktree_path", "?")
197
+ started = agent.get("started_at", "?")
198
+
199
+ if is_running(pid):
200
+ status_icon = f"{Colors.GREEN}●{Colors.NC}"
201
+ else:
202
+ status_icon = f"{Colors.RED}○{Colors.NC}"
203
+
204
+ print(f" {status_icon} {agent_id} (PID: {pid})")
205
+ print(f" {Colors.DIM}Worktree: {wt}{Colors.NC}")
206
+ print(f" {Colors.DIM}Started: {started}{Colors.NC}")
207
+ print()
208
+
209
+ return 0
210
+
211
+
212
+ def cmd_summary(repo_root: Path, filter_assignee: str | None = None) -> int:
213
+ """Show summary of all tasks."""
214
+ # Import lazily to avoid circular import at module level
215
+ from .status_monitor import get_last_tool, get_last_message
216
+
217
+ ensure_developer(repo_root)
218
+
219
+ tasks_dir = get_tasks_dir(repo_root)
220
+ if not tasks_dir.is_dir():
221
+ print("No tasks directory found")
222
+ return 0
223
+
224
+ registry_file = get_registry_file(repo_root)
225
+
226
+ # Count running agents
227
+ running_count = 0
228
+ total_agents = 0
229
+
230
+ if registry_file and registry_file.is_file():
231
+ data = read_json(registry_file)
232
+ if data:
233
+ agents = data.get("agents", [])
234
+ total_agents = len(agents)
235
+ for agent in agents:
236
+ if is_running(agent.get("pid")):
237
+ running_count += 1
238
+
239
+ # Task queue stats
240
+ task_stats = get_task_stats(repo_root)
241
+
242
+ print(f"{Colors.BLUE}=== Multi-Agent Status ==={Colors.NC}")
243
+ print(
244
+ f" Agents: {Colors.GREEN}{running_count}{Colors.NC} running / {total_agents} registered"
245
+ )
246
+ print(f" Tasks: {format_task_stats(task_stats)}")
247
+ print()
248
+
249
+ # Process tasks
250
+ running_tasks = []
251
+ stopped_tasks = []
252
+ regular_tasks = []
253
+
254
+ registry_data = (
255
+ read_json(registry_file)
256
+ if registry_file and registry_file.is_file()
257
+ else None
258
+ )
259
+
260
+ for t in iter_active_tasks(tasks_dir):
261
+ name = t.dir_name
262
+ status = t.status
263
+ assignee = t.assignee or "unassigned"
264
+ priority = t.priority
265
+
266
+ # Filter by assignee
267
+ if filter_assignee and assignee != filter_assignee:
268
+ continue
269
+
270
+ # Check agent status
271
+ agent_info = None
272
+ if registry_data:
273
+ for agent in registry_data.get("agents", []):
274
+ if name in agent.get("task_dir", ""):
275
+ agent_info = agent
276
+ break
277
+
278
+ if agent_info:
279
+ pid = agent_info.get("pid")
280
+ worktree = agent_info.get("worktree_path", "")
281
+ started = agent_info.get("started_at")
282
+ agent_platform = agent_info.get("platform", "claude")
283
+
284
+ if is_running(pid):
285
+ # Running agent
286
+ task_dir_rel = agent_info.get("task_dir", "")
287
+ worktree_task_json = Path(worktree) / task_dir_rel / "task.json"
288
+ phase_source = t.directory / "task.json"
289
+ if worktree_task_json.is_file():
290
+ phase_source = worktree_task_json
291
+
292
+ phase_info_str = get_phase_info(phase_source)
293
+ elapsed = calc_elapsed(started)
294
+ modified = count_modified_files(worktree)
295
+
296
+ worktree_data = read_json(phase_source)
297
+ branch = worktree_data.get("branch", "N/A") if worktree_data else "N/A"
298
+
299
+ log_file = Path(worktree) / ".agent-log"
300
+ last_tool = get_last_tool(log_file, platform=agent_platform)
301
+
302
+ running_tasks.append(
303
+ {
304
+ "name": name,
305
+ "priority": priority,
306
+ "assignee": assignee,
307
+ "phase_info": phase_info_str,
308
+ "elapsed": elapsed,
309
+ "branch": branch,
310
+ "modified": modified,
311
+ "last_tool": last_tool,
312
+ "pid": pid,
313
+ }
314
+ )
315
+ else:
316
+ # Stopped agent
317
+ task_dir_rel = agent_info.get("task_dir", "")
318
+ worktree_task_json = Path(worktree) / task_dir_rel / "task.json"
319
+ worktree_status = "unknown"
320
+
321
+ if worktree_task_json.is_file():
322
+ wt_data = read_json(worktree_task_json)
323
+ if wt_data:
324
+ worktree_status = wt_data.get("status", "unknown")
325
+
326
+ session_id_file = Path(worktree) / ".session-id"
327
+ log_file = Path(worktree) / ".agent-log"
328
+
329
+ stopped_tasks.append(
330
+ {
331
+ "name": name,
332
+ "worktree": worktree,
333
+ "status": worktree_status,
334
+ "session_id_file": session_id_file,
335
+ "log_file": log_file,
336
+ "platform": agent_info.get("platform", "claude"),
337
+ }
338
+ )
339
+ else:
340
+ # Regular task
341
+ regular_tasks.append(
342
+ {
343
+ "name": name,
344
+ "status": status,
345
+ "priority": priority,
346
+ "assignee": assignee,
347
+ }
348
+ )
349
+
350
+ # Output running agents
351
+ if running_tasks:
352
+ print(f"{Colors.CYAN}Running Agents:{Colors.NC}")
353
+ for t in running_tasks:
354
+ priority_color = (
355
+ Colors.RED
356
+ if t["priority"] == "P0"
357
+ else (Colors.YELLOW if t["priority"] == "P1" else Colors.BLUE)
358
+ )
359
+ print(
360
+ f"{Colors.GREEN}▶{Colors.NC} {Colors.CYAN}{t['name']}{Colors.NC} {Colors.GREEN}[running]{Colors.NC} {priority_color}[{t['priority']}]{Colors.NC} @{t['assignee']}"
361
+ )
362
+ print(f" Phase: {t['phase_info']}")
363
+ print(f" Elapsed: {t['elapsed']}")
364
+ print(f" Branch: {Colors.DIM}{t['branch']}{Colors.NC}")
365
+ print(f" Modified: {t['modified']} file(s)")
366
+ if t["last_tool"]:
367
+ print(f" Activity: {Colors.YELLOW}{t['last_tool']}{Colors.NC}")
368
+ print(f" PID: {Colors.DIM}{t['pid']}{Colors.NC}")
369
+ print()
370
+
371
+ # Output stopped agents
372
+ if stopped_tasks:
373
+ print(f"{Colors.RED}Stopped Agents:{Colors.NC}")
374
+ for t in stopped_tasks:
375
+ if t["status"] == "completed":
376
+ print(
377
+ f"{Colors.GREEN}✓{Colors.NC} {t['name']} {Colors.GREEN}[completed]{Colors.NC}"
378
+ )
379
+ else:
380
+ if t["session_id_file"].is_file():
381
+ session_id = (
382
+ t["session_id_file"].read_text(encoding="utf-8").strip()
383
+ )
384
+ last_msg = get_last_message(t["log_file"], 150, platform=t.get("platform", "claude"))
385
+ print(
386
+ f"{Colors.RED}○{Colors.NC} {t['name']} {Colors.RED}[stopped]{Colors.NC}"
387
+ )
388
+ if last_msg:
389
+ print(f'{Colors.DIM}"{last_msg}"{Colors.NC}')
390
+ # Use CLI adapter for platform-specific resume command
391
+ adapter = get_cli_adapter(t.get("platform", "claude"))
392
+ resume_cmd = adapter.get_resume_command_str(session_id, cwd=t["worktree"])
393
+ print(f"{Colors.YELLOW}{resume_cmd}{Colors.NC}")
394
+ else:
395
+ print(
396
+ f"{Colors.RED}○{Colors.NC} {t['name']} {Colors.RED}[stopped]{Colors.NC} {Colors.DIM}(no session-id){Colors.NC}"
397
+ )
398
+ print()
399
+
400
+ # Separator
401
+ if (running_tasks or stopped_tasks) and regular_tasks:
402
+ print(f"{Colors.DIM}───────────────────────────────────────{Colors.NC}")
403
+ print()
404
+
405
+ # Output regular tasks grouped by assignee
406
+ if regular_tasks:
407
+ # Sort by assignee, priority, status
408
+ regular_tasks.sort(
409
+ key=lambda x: (
410
+ x["assignee"],
411
+ {"P0": 0, "P1": 1, "P2": 2, "P3": 3}.get(x["priority"], 2),
412
+ {"in_progress": 0, "planning": 1, "completed": 2}.get(x["status"], 1),
413
+ )
414
+ )
415
+
416
+ current_assignee = None
417
+ for t in regular_tasks:
418
+ if t["assignee"] != current_assignee:
419
+ if current_assignee is not None:
420
+ print()
421
+ print(f"{Colors.CYAN}@{t['assignee']}:{Colors.NC}")
422
+ current_assignee = t["assignee"]
423
+
424
+ color = status_color(t["status"])
425
+ priority_color = (
426
+ Colors.RED
427
+ if t["priority"] == "P0"
428
+ else (Colors.YELLOW if t["priority"] == "P1" else Colors.BLUE)
429
+ )
430
+ print(
431
+ f" {color}●{Colors.NC} {t['name']} ({t['status']}) {priority_color}[{t['priority']}]{Colors.NC}"
432
+ )
433
+
434
+ if running_tasks:
435
+ print()
436
+ print(f"{Colors.DIM}─────────────────────────────────────{Colors.NC}")
437
+ print(f"{Colors.DIM}Use --progress <name> for quick activity view{Colors.NC}")
438
+ print(f"{Colors.DIM}Use --detail <name> for more info{Colors.NC}")
439
+
440
+ print()
441
+ return 0
442
+
443
+
444
+ def cmd_detail(target: str, repo_root: Path) -> int:
445
+ """Show detailed task status."""
446
+ agent = find_agent(target, repo_root)
447
+ if not agent:
448
+ print(f"Agent not found: {target}")
449
+ return 1
450
+
451
+ agent_id = agent.get("id", "?")
452
+ pid = agent.get("pid")
453
+ worktree = agent.get("worktree_path", "?")
454
+ task_dir = agent.get("task_dir", "?")
455
+ started = agent.get("started_at", "?")
456
+ platform = agent.get("platform", "claude")
457
+
458
+ # Check for session-id
459
+ session_id = ""
460
+ session_id_file = Path(worktree) / ".session-id"
461
+ if session_id_file.is_file():
462
+ session_id = session_id_file.read_text(encoding="utf-8").strip()
463
+
464
+ print(f"{Colors.BLUE}=== Agent Detail: {agent_id} ==={Colors.NC}")
465
+ print()
466
+ print(f" ID: {agent_id}")
467
+ print(f" PID: {pid}")
468
+ print(f" Session: {session_id or 'N/A'}")
469
+ print(f" Worktree: {worktree}")
470
+ print(f" Task Dir: {task_dir}")
471
+ print(f" Started: {started}")
472
+ print()
473
+
474
+ # Status
475
+ if is_running(pid):
476
+ print(f" Status: {Colors.GREEN}Running{Colors.NC}")
477
+ else:
478
+ print(f" Status: {Colors.RED}Stopped{Colors.NC}")
479
+ if session_id:
480
+ print()
481
+ # Use CLI adapter for platform-specific resume command
482
+ adapter = get_cli_adapter(platform)
483
+ resume_cmd = adapter.get_resume_command_str(session_id, cwd=worktree)
484
+ print(f" {Colors.YELLOW}Resume:{Colors.NC} {resume_cmd}")
485
+
486
+ # Task info
487
+ task_json = repo_root / task_dir / "task.json"
488
+ if task_json.is_file():
489
+ print()
490
+ print(f"{Colors.BLUE}=== Task Info ==={Colors.NC}")
491
+ print()
492
+ data = read_json(task_json)
493
+ if data:
494
+ print(f" Status: {data.get('status', 'unknown')}")
495
+ print(f" Branch: {data.get('branch', 'N/A')}")
496
+ print(f" Base Branch: {data.get('base_branch', 'N/A')}")
497
+
498
+ # Git changes
499
+ if Path(worktree).is_dir():
500
+ print()
501
+ print(f"{Colors.BLUE}=== Git Changes ==={Colors.NC}")
502
+ print()
503
+
504
+ result = subprocess.run(
505
+ ["git", "status", "--short"],
506
+ cwd=worktree,
507
+ capture_output=True,
508
+ text=True,
509
+ encoding="utf-8",
510
+ errors="replace",
511
+ )
512
+ changes = result.stdout.strip()
513
+ if changes:
514
+ for line in changes.splitlines()[:10]:
515
+ print(f" {line}")
516
+ total = len(changes.splitlines())
517
+ if total > 10:
518
+ print(f" ... and {total - 10} more")
519
+ else:
520
+ print(" (no changes)")
521
+
522
+ print()
523
+ return 0
524
+
525
+
526
+ def cmd_registry(repo_root: Path) -> int:
527
+ """Show agent registry."""
528
+ registry_file = get_registry_file(repo_root)
529
+
530
+ print(f"{Colors.BLUE}=== Agent Registry ==={Colors.NC}")
531
+ print()
532
+ print(f"File: {registry_file}")
533
+ print()
534
+
535
+ if registry_file and registry_file.is_file():
536
+ data = read_json(registry_file)
537
+ if data:
538
+ print(json.dumps(data, indent=2))
539
+ else:
540
+ print("(registry not found)")
541
+
542
+ return 0