aiwcli 0.10.3 → 0.11.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 (191) hide show
  1. package/bin/run.js +1 -1
  2. package/dist/commands/clear.js +28 -131
  3. package/dist/commands/init/index.js +3 -3
  4. package/dist/lib/gitignore-manager.d.ts +32 -0
  5. package/dist/lib/gitignore-manager.js +141 -2
  6. package/dist/templates/CLAUDE.md +8 -8
  7. package/dist/templates/_shared/.claude/commands/handoff-resume.md +64 -0
  8. package/dist/templates/_shared/.claude/commands/handoff.md +16 -10
  9. package/dist/templates/_shared/.claude/settings.json +7 -7
  10. package/dist/templates/_shared/hooks-ts/_utils/git-state.ts +2 -0
  11. package/dist/templates/_shared/hooks-ts/archive_plan.ts +159 -0
  12. package/dist/templates/_shared/hooks-ts/context_monitor.ts +147 -0
  13. package/dist/templates/_shared/hooks-ts/file-suggestion.ts +130 -0
  14. package/dist/templates/_shared/hooks-ts/pre_compact.ts +49 -0
  15. package/dist/templates/_shared/hooks-ts/session_end.ts +107 -0
  16. package/dist/templates/_shared/hooks-ts/session_start.ts +144 -0
  17. package/dist/templates/_shared/hooks-ts/task_create_capture.ts +48 -0
  18. package/dist/templates/_shared/hooks-ts/task_update_capture.ts +74 -0
  19. package/dist/templates/_shared/hooks-ts/user_prompt_submit.ts +83 -0
  20. package/dist/templates/_shared/lib-ts/CLAUDE.md +318 -0
  21. package/dist/templates/_shared/lib-ts/base/atomic-write.ts +12 -12
  22. package/dist/templates/_shared/lib-ts/base/constants.ts +22 -15
  23. package/dist/templates/_shared/lib-ts/base/git-state.ts +1 -1
  24. package/dist/templates/_shared/lib-ts/base/hook-utils.ts +129 -50
  25. package/dist/templates/_shared/lib-ts/base/inference.ts +28 -21
  26. package/dist/templates/_shared/lib-ts/base/logger.ts +15 -2
  27. package/dist/templates/_shared/lib-ts/base/state-io.ts +9 -7
  28. package/dist/templates/_shared/lib-ts/base/stop-words.ts +131 -131
  29. package/dist/templates/_shared/lib-ts/base/subprocess-utils.ts +142 -0
  30. package/dist/templates/_shared/lib-ts/base/utils.ts +69 -69
  31. package/dist/templates/_shared/lib-ts/context/context-formatter.ts +30 -24
  32. package/dist/templates/_shared/lib-ts/context/context-selector.ts +50 -32
  33. package/dist/templates/_shared/lib-ts/context/context-store.ts +76 -48
  34. package/dist/templates/_shared/lib-ts/context/plan-manager.ts +43 -23
  35. package/dist/templates/_shared/lib-ts/context/task-tracker.ts +10 -6
  36. package/dist/templates/_shared/lib-ts/handoff/document-generator.ts +11 -10
  37. package/dist/templates/_shared/lib-ts/handoff/handoff-reader.ts +158 -0
  38. package/dist/templates/_shared/lib-ts/templates/formatters.ts +6 -4
  39. package/dist/templates/_shared/lib-ts/types.ts +68 -55
  40. package/dist/templates/_shared/scripts/resolve_context.ts +24 -0
  41. package/dist/templates/_shared/scripts/resume_handoff.ts +345 -0
  42. package/dist/templates/_shared/scripts/save_handoff.ts +3 -3
  43. package/dist/templates/_shared/scripts/status_line.ts +687 -0
  44. package/dist/templates/cc-native/.claude/settings.json +175 -185
  45. package/dist/templates/cc-native/TEMPLATE-SCHEMA.md +15 -17
  46. package/dist/templates/cc-native/_cc-native/agents/CLAUDE.md +0 -2
  47. package/dist/templates/cc-native/_cc-native/hooks/CLAUDE.md +109 -135
  48. package/dist/templates/cc-native/_cc-native/hooks/add_plan_context.ts +119 -0
  49. package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.ts +1027 -0
  50. package/dist/templates/cc-native/_cc-native/hooks/plan_questions_early.ts +61 -0
  51. package/dist/templates/cc-native/_cc-native/lib-ts/aggregate-agents.ts +156 -0
  52. package/dist/templates/cc-native/_cc-native/lib-ts/artifacts.ts +792 -0
  53. package/dist/templates/cc-native/_cc-native/lib-ts/cc-native-state.ts +199 -0
  54. package/dist/templates/cc-native/_cc-native/lib-ts/cli-output-parser.ts +144 -0
  55. package/dist/templates/cc-native/_cc-native/lib-ts/config.ts +57 -0
  56. package/dist/templates/cc-native/_cc-native/lib-ts/constants.ts +83 -0
  57. package/dist/templates/cc-native/_cc-native/lib-ts/corroboration.ts +115 -0
  58. package/dist/templates/cc-native/_cc-native/lib-ts/debug.ts +80 -0
  59. package/dist/templates/cc-native/_cc-native/lib-ts/index.ts +120 -0
  60. package/dist/templates/cc-native/_cc-native/lib-ts/json-parser.ts +168 -0
  61. package/dist/templates/cc-native/_cc-native/lib-ts/nul +3 -0
  62. package/dist/templates/cc-native/_cc-native/lib-ts/orchestrator.ts +250 -0
  63. package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/agent.ts +275 -0
  64. package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/codex.ts +130 -0
  65. package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/gemini.ts +107 -0
  66. package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/index.ts +10 -0
  67. package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/types.ts +23 -0
  68. package/dist/templates/cc-native/_cc-native/lib-ts/state.ts +240 -0
  69. package/dist/templates/cc-native/_cc-native/lib-ts/tsconfig.json +18 -0
  70. package/dist/templates/cc-native/_cc-native/lib-ts/types.ts +385 -0
  71. package/dist/templates/cc-native/_cc-native/lib-ts/verdict.ts +72 -0
  72. package/dist/templates/cc-native/_cc-native/plan-review.config.json +14 -1
  73. package/oclif.manifest.json +1 -1
  74. package/package.json +2 -2
  75. package/dist/templates/_shared/hooks/__init__.py +0 -16
  76. package/dist/templates/_shared/hooks/__pycache__/__init__.cpython-313.pyc +0 -0
  77. package/dist/templates/_shared/hooks/__pycache__/archive_plan.cpython-313.pyc +0 -0
  78. package/dist/templates/_shared/hooks/__pycache__/context_enforcer.cpython-313.pyc +0 -0
  79. package/dist/templates/_shared/hooks/__pycache__/context_monitor.cpython-313.pyc +0 -0
  80. package/dist/templates/_shared/hooks/__pycache__/file-suggestion.cpython-313.pyc +0 -0
  81. package/dist/templates/_shared/hooks/__pycache__/pre_compact.cpython-313.pyc +0 -0
  82. package/dist/templates/_shared/hooks/__pycache__/session_end.cpython-313.pyc +0 -0
  83. package/dist/templates/_shared/hooks/__pycache__/session_start.cpython-313.pyc +0 -0
  84. package/dist/templates/_shared/hooks/__pycache__/task_create_atomicity.cpython-313.pyc +0 -0
  85. package/dist/templates/_shared/hooks/__pycache__/task_create_capture.cpython-313.pyc +0 -0
  86. package/dist/templates/_shared/hooks/__pycache__/task_update_capture.cpython-313.pyc +0 -0
  87. package/dist/templates/_shared/hooks/__pycache__/user_prompt_submit.cpython-313.pyc +0 -0
  88. package/dist/templates/_shared/hooks/archive_plan.py +0 -177
  89. package/dist/templates/_shared/hooks/context_monitor.py +0 -270
  90. package/dist/templates/_shared/hooks/file-suggestion.py +0 -215
  91. package/dist/templates/_shared/hooks/pre_compact.py +0 -104
  92. package/dist/templates/_shared/hooks/session_end.py +0 -173
  93. package/dist/templates/_shared/hooks/session_start.py +0 -206
  94. package/dist/templates/_shared/hooks/task_create_capture.py +0 -108
  95. package/dist/templates/_shared/hooks/task_update_capture.py +0 -145
  96. package/dist/templates/_shared/hooks/user_prompt_submit.py +0 -139
  97. package/dist/templates/_shared/lib/__init__.py +0 -1
  98. package/dist/templates/_shared/lib/__pycache__/__init__.cpython-313.pyc +0 -0
  99. package/dist/templates/_shared/lib/base/__init__.py +0 -65
  100. package/dist/templates/_shared/lib/base/__pycache__/__init__.cpython-313.pyc +0 -0
  101. package/dist/templates/_shared/lib/base/__pycache__/atomic_write.cpython-313.pyc +0 -0
  102. package/dist/templates/_shared/lib/base/__pycache__/constants.cpython-313.pyc +0 -0
  103. package/dist/templates/_shared/lib/base/__pycache__/hook_utils.cpython-313.pyc +0 -0
  104. package/dist/templates/_shared/lib/base/__pycache__/inference.cpython-313.pyc +0 -0
  105. package/dist/templates/_shared/lib/base/__pycache__/logger.cpython-313.pyc +0 -0
  106. package/dist/templates/_shared/lib/base/__pycache__/stop_words.cpython-313.pyc +0 -0
  107. package/dist/templates/_shared/lib/base/__pycache__/subprocess_utils.cpython-313.pyc +0 -0
  108. package/dist/templates/_shared/lib/base/__pycache__/utils.cpython-313.pyc +0 -0
  109. package/dist/templates/_shared/lib/base/atomic_write.py +0 -180
  110. package/dist/templates/_shared/lib/base/constants.py +0 -358
  111. package/dist/templates/_shared/lib/base/hook_utils.py +0 -339
  112. package/dist/templates/_shared/lib/base/inference.py +0 -307
  113. package/dist/templates/_shared/lib/base/logger.py +0 -305
  114. package/dist/templates/_shared/lib/base/stop_words.py +0 -221
  115. package/dist/templates/_shared/lib/base/subprocess_utils.py +0 -46
  116. package/dist/templates/_shared/lib/base/utils.py +0 -263
  117. package/dist/templates/_shared/lib/context/__init__.py +0 -102
  118. package/dist/templates/_shared/lib/context/__pycache__/__init__.cpython-313.pyc +0 -0
  119. package/dist/templates/_shared/lib/context/__pycache__/cache.cpython-313.pyc +0 -0
  120. package/dist/templates/_shared/lib/context/__pycache__/context_extractor.cpython-313.pyc +0 -0
  121. package/dist/templates/_shared/lib/context/__pycache__/context_formatter.cpython-313.pyc +0 -0
  122. package/dist/templates/_shared/lib/context/__pycache__/context_manager.cpython-313.pyc +0 -0
  123. package/dist/templates/_shared/lib/context/__pycache__/context_selector.cpython-313.pyc +0 -0
  124. package/dist/templates/_shared/lib/context/__pycache__/context_store.cpython-313.pyc +0 -0
  125. package/dist/templates/_shared/lib/context/__pycache__/discovery.cpython-313.pyc +0 -0
  126. package/dist/templates/_shared/lib/context/__pycache__/event_log.cpython-313.pyc +0 -0
  127. package/dist/templates/_shared/lib/context/__pycache__/plan_archive.cpython-313.pyc +0 -0
  128. package/dist/templates/_shared/lib/context/__pycache__/plan_manager.cpython-313.pyc +0 -0
  129. package/dist/templates/_shared/lib/context/__pycache__/task_sync.cpython-313.pyc +0 -0
  130. package/dist/templates/_shared/lib/context/__pycache__/task_tracker.cpython-313.pyc +0 -0
  131. package/dist/templates/_shared/lib/context/context_formatter.py +0 -317
  132. package/dist/templates/_shared/lib/context/context_selector.py +0 -508
  133. package/dist/templates/_shared/lib/context/context_store.py +0 -653
  134. package/dist/templates/_shared/lib/context/plan_manager.py +0 -303
  135. package/dist/templates/_shared/lib/context/task_tracker.py +0 -188
  136. package/dist/templates/_shared/lib/handoff/__init__.py +0 -22
  137. package/dist/templates/_shared/lib/handoff/__pycache__/__init__.cpython-313.pyc +0 -0
  138. package/dist/templates/_shared/lib/handoff/__pycache__/document_generator.cpython-313.pyc +0 -0
  139. package/dist/templates/_shared/lib/handoff/document_generator.py +0 -278
  140. package/dist/templates/_shared/lib/templates/README.md +0 -206
  141. package/dist/templates/_shared/lib/templates/__init__.py +0 -36
  142. package/dist/templates/_shared/lib/templates/__pycache__/__init__.cpython-313.pyc +0 -0
  143. package/dist/templates/_shared/lib/templates/__pycache__/formatters.cpython-313.pyc +0 -0
  144. package/dist/templates/_shared/lib/templates/__pycache__/persona_questions.cpython-313.pyc +0 -0
  145. package/dist/templates/_shared/lib/templates/__pycache__/plan_context.cpython-313.pyc +0 -0
  146. package/dist/templates/_shared/lib/templates/formatters.py +0 -146
  147. package/dist/templates/_shared/lib/templates/plan_context.py +0 -73
  148. package/dist/templates/_shared/scripts/__pycache__/save_handoff.cpython-313.pyc +0 -0
  149. package/dist/templates/_shared/scripts/__pycache__/status_line.cpython-313.pyc +0 -0
  150. package/dist/templates/_shared/scripts/save_handoff.py +0 -357
  151. package/dist/templates/_shared/scripts/status_line.py +0 -716
  152. package/dist/templates/cc-native/.claude/commands/cc-native/fresh-perspective.md +0 -8
  153. package/dist/templates/cc-native/.windsurf/workflows/cc-native/fresh-perspective.md +0 -8
  154. package/dist/templates/cc-native/MIGRATION.md +0 -86
  155. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/add_plan_context.cpython-313.pyc +0 -0
  156. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/cc-native-plan-review.cpython-313.pyc +0 -0
  157. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/mark_questions_asked.cpython-313.pyc +0 -0
  158. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/plan_accepted.cpython-313.pyc +0 -0
  159. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/plan_questions_early.cpython-313.pyc +0 -0
  160. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/suggest-fresh-perspective.cpython-313.pyc +0 -0
  161. package/dist/templates/cc-native/_cc-native/hooks/add_plan_context.py +0 -130
  162. package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.py +0 -954
  163. package/dist/templates/cc-native/_cc-native/hooks/plan_questions_early.py +0 -81
  164. package/dist/templates/cc-native/_cc-native/hooks/suggest-fresh-perspective.py +0 -340
  165. package/dist/templates/cc-native/_cc-native/lib/CLAUDE.md +0 -265
  166. package/dist/templates/cc-native/_cc-native/lib/__init__.py +0 -53
  167. package/dist/templates/cc-native/_cc-native/lib/__pycache__/__init__.cpython-313.pyc +0 -0
  168. package/dist/templates/cc-native/_cc-native/lib/__pycache__/atomic_write.cpython-313.pyc +0 -0
  169. package/dist/templates/cc-native/_cc-native/lib/__pycache__/constants.cpython-313.pyc +0 -0
  170. package/dist/templates/cc-native/_cc-native/lib/__pycache__/debug.cpython-313.pyc +0 -0
  171. package/dist/templates/cc-native/_cc-native/lib/__pycache__/orchestrator.cpython-313.pyc +0 -0
  172. package/dist/templates/cc-native/_cc-native/lib/__pycache__/state.cpython-313.pyc +0 -0
  173. package/dist/templates/cc-native/_cc-native/lib/__pycache__/utils.cpython-313.pyc +0 -0
  174. package/dist/templates/cc-native/_cc-native/lib/constants.py +0 -45
  175. package/dist/templates/cc-native/_cc-native/lib/debug.py +0 -139
  176. package/dist/templates/cc-native/_cc-native/lib/orchestrator.py +0 -362
  177. package/dist/templates/cc-native/_cc-native/lib/reviewers/__init__.py +0 -28
  178. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/__init__.cpython-313.pyc +0 -0
  179. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/agent.cpython-313.pyc +0 -0
  180. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/base.cpython-313.pyc +0 -0
  181. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/codex.cpython-313.pyc +0 -0
  182. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/gemini.cpython-313.pyc +0 -0
  183. package/dist/templates/cc-native/_cc-native/lib/reviewers/agent.py +0 -215
  184. package/dist/templates/cc-native/_cc-native/lib/reviewers/base.py +0 -88
  185. package/dist/templates/cc-native/_cc-native/lib/reviewers/codex.py +0 -124
  186. package/dist/templates/cc-native/_cc-native/lib/reviewers/gemini.py +0 -108
  187. package/dist/templates/cc-native/_cc-native/lib/state.py +0 -268
  188. package/dist/templates/cc-native/_cc-native/lib/utils.py +0 -1071
  189. package/dist/templates/cc-native/_cc-native/scripts/__pycache__/aggregate_agents.cpython-313.pyc +0 -0
  190. package/dist/templates/cc-native/_cc-native/scripts/aggregate_agents.py +0 -168
  191. package/dist/templates/cc-native/_cc-native/workflows/fresh-perspective.md +0 -134
@@ -1,317 +0,0 @@
1
- """Formatting module for context display output.
2
-
3
- Consolidates output formatting previously in discovery.py and context_enforcer.py (both now deleted).
4
- All functions accept a ContextState (from context_store.py) with fields:
5
- id, summary, mode, last_active, plan_path, handoff_path,
6
- tasks[], last_session, session_ids, status, method, tags
7
- """
8
- from datetime import datetime
9
- from pathlib import Path
10
- from typing import Optional, Tuple
11
-
12
- from ..base.utils import parse_iso_timestamp
13
-
14
- MAX_PLAN_INLINE_CHARS = 30_000
15
-
16
-
17
- def _read_plan_content(plan_path: str) -> Tuple[Optional[str], bool, int]:
18
- """Read plan content from disk for inline injection.
19
- Returns (content, truncated, total_chars) or (None, False, 0) on error."""
20
- try:
21
- pf = Path(plan_path)
22
- if not pf.exists():
23
- return None, False, 0
24
- content = pf.read_text(encoding="utf-8")
25
- total = len(content)
26
- if total > MAX_PLAN_INLINE_CHARS:
27
- return content[:MAX_PLAN_INLINE_CHARS], True, total
28
- return content, False, total
29
- except Exception:
30
- return None, False, 0
31
-
32
- MODE_DISPLAY_MAP = {
33
- "idle": "",
34
- "has_plan": "[Plan Ready]",
35
- "has_handoff": "[Handoff Ready]",
36
- "active": "[Active]",
37
- }
38
-
39
-
40
- def get_mode_display(mode: str) -> str:
41
- """Get bracketed display string for mode, or empty for idle."""
42
- return MODE_DISPLAY_MAP.get(mode, "")
43
-
44
-
45
- def format_relative_time(iso_timestamp: Optional[str]) -> str:
46
- """Format ISO timestamp as '2 hours ago', 'yesterday', etc."""
47
- if not iso_timestamp:
48
- return "unknown"
49
- dt = parse_iso_timestamp(iso_timestamp)
50
- if not dt:
51
- return iso_timestamp[:16]
52
- now = datetime.now()
53
- if dt.tzinfo is not None:
54
- try:
55
- dt = dt.replace(tzinfo=None)
56
- except Exception:
57
- return iso_timestamp[:16]
58
- diff = now - dt
59
- if diff.days == 0:
60
- hours = diff.seconds // 3600
61
- if hours == 0:
62
- minutes = diff.seconds // 60
63
- if minutes == 0:
64
- return "just now"
65
- return "1 minute ago" if minutes == 1 else f"{minutes} minutes ago"
66
- return "1 hour ago" if hours == 1 else f"{hours} hours ago"
67
- if diff.days == 1:
68
- return "yesterday"
69
- if diff.days < 7:
70
- return f"{diff.days} days ago"
71
- return dt.strftime("%Y-%m-%d")
72
-
73
-
74
- # ── Internal helpers ───────────────────────────────────────────────
75
-
76
- def _task_attr(task, key: str, default: str = "") -> str:
77
- """Extract attribute from a task (dict or object)."""
78
- return task.get(key, default) if isinstance(task, dict) else getattr(task, key, default)
79
-
80
-
81
- def _build_restore_sections(ctx, project_root: Path = None, inline_plan: bool = False) -> str:
82
- """Build restore sections from last_session, tasks, and plan_path.
83
-
84
- Args:
85
- inline_plan: If True, read and inline plan file content (for compact restore
86
- where plan is NOT auto-pasted). If False, just reference the path (for
87
- clear restore where Claude Code auto-pastes the plan).
88
- """
89
- sections = []
90
- last_session = getattr(ctx, "last_session", None) or {}
91
-
92
- if last_session:
93
- saved_at = last_session.get("saved_at", "")
94
- if saved_at:
95
- reason = last_session.get("save_reason", "")
96
- reason_display = reason.replace("_", " ") if reason else "unknown"
97
- sections.append(f"**Last session ended:** {format_relative_time(saved_at)} ({reason_display})")
98
-
99
- tasks = getattr(ctx, "tasks", None) or []
100
- if tasks:
101
- buckets = {"completed": [], "in_progress": [], "pending": [], "blocked": []}
102
- for t in tasks:
103
- s = _task_attr(t, "status", "pending")
104
- if s in buckets:
105
- buckets[s].append(_task_attr(t, "subject"))
106
- if any(buckets.values()):
107
- sections.extend(["", f"### Previous Work ({len(tasks)} tasks)", ""])
108
- marks = {"completed": "[x]", "in_progress": "[~]", "pending": "[ ]", "blocked": "[!]"}
109
- for status, mark in marks.items():
110
- for subj in buckets[status]:
111
- sections.append(f"- {mark} {subj}")
112
-
113
- plan_path = getattr(ctx, "plan_path", None)
114
- if plan_path:
115
- if inline_plan:
116
- content, truncated, total_chars = _read_plan_content(plan_path)
117
- if content:
118
- header = f"Plan loaded from: `{plan_path}`"
119
- if truncated:
120
- header += f" (truncated, {total_chars} chars total)"
121
- sections.extend(["", "### Plan", header, "", content])
122
- if truncated:
123
- sections.append(f"\n*Plan truncated at {MAX_PLAN_INLINE_CHARS} characters. Full plan at: `{plan_path}`*")
124
- else:
125
- sections.extend(["", "### Plan", f"*Plan file not found at `{plan_path}`.*"])
126
- else:
127
- sections.extend(["", "### Plan", f"Read the plan at: `{plan_path}`"])
128
-
129
- git_state = last_session.get("git_state", {}) if last_session else {}
130
- if git_state:
131
- branch = git_state.get("branch", "unknown")
132
- uncommitted = git_state.get("uncommitted_files", [])
133
- last_commit = git_state.get("last_commit_short", "")
134
- unc_str = ", ".join(uncommitted[:5]) if uncommitted else "none"
135
- if len(uncommitted) > 5:
136
- unc_str += f" (+{len(uncommitted) - 5} more)"
137
- sections.extend(["", "### Git State", f"Branch: {branch} | Uncommitted: {unc_str}"])
138
- if last_commit:
139
- sections.append(f"Last commit: {last_commit}")
140
-
141
- return "\n".join(sections)
142
-
143
-
144
- def _mode_label(ctx) -> str:
145
- """Get unbracketed mode label for inline display, defaulting to 'Active'."""
146
- d = get_mode_display(getattr(ctx, "mode", "idle"))
147
- return d.strip("[]") if d else "Active"
148
-
149
-
150
- def _resume_block(ctx, project_root, mode_text, instructions):
151
- """Common pattern: resume header + restore + instructions."""
152
- lines = [f"## Resuming Context: {ctx.id}", "", f"**Summary:** {ctx.summary}", f"**Mode:** {mode_text}"]
153
- restore = _build_restore_sections(ctx, project_root, inline_plan=True)
154
- if restore:
155
- lines.append(restore)
156
- lines.extend(["", "---", "", "**Instructions:**"])
157
- lines.extend(instructions)
158
- return "\n".join(lines)
159
-
160
-
161
- # ── Public formatters ──────────────────────────────────────────────
162
-
163
- def format_handoff_continuation(ctx, project_root: Path = None) -> str:
164
- """Format output when resuming a context with a pending handoff."""
165
- handoff_path = getattr(ctx, "handoff_path", None) or ""
166
- lines = [
167
- f"## Resuming Context: {ctx.id} (Handoff Available)", "",
168
- f"**Summary:** {ctx.summary}",
169
- f"**Mode:** Implementing (handoff from previous session)", "",
170
- ]
171
- try:
172
- hf = Path(handoff_path)
173
- if hf.exists():
174
- lines.extend(["### Previous Session Handoff", "", hf.read_text(encoding="utf-8"), ""])
175
- else:
176
- lines.extend([f"*Handoff document not found at `{handoff_path}`*", ""])
177
- except Exception as e:
178
- lines.extend([f"*Handoff document at `{handoff_path}` could not be read: {e}*", ""])
179
- restore = _build_restore_sections(ctx, project_root, inline_plan=True)
180
- if restore:
181
- lines.append(restore)
182
- lines.extend(["", "---", "", "**Instructions:**",
183
- "1. Review the handoff document above - especially dead ends",
184
- "2. Check the plan file for remaining tasks",
185
- "3. Continue implementation from where the previous session left off"])
186
- return "\n".join(lines)
187
-
188
-
189
- def format_plan_continuation(ctx, project_root: Path = None) -> str:
190
- """Format output for pending plan implementation (mode=has_plan)."""
191
- return _resume_block(ctx, project_root, "Pending Implementation", [
192
- "1. Review the plan and previous work above",
193
- "2. Continue from where the previous session left off"])
194
-
195
-
196
- def format_active_continuation(ctx, project_root: Path = None) -> str:
197
- """Format output for ongoing implementation (mode=active)."""
198
- return _resume_block(ctx, project_root, "Implementing", [
199
- "1. Review the plan and previous work above",
200
- "2. Continue from where the previous session left off"])
201
-
202
-
203
- def format_context_list(contexts: list) -> str:
204
- """Format list of contexts for display."""
205
- if not contexts:
206
- return "No active contexts found."
207
- lines = ["## Active Contexts\n"]
208
- for i, ctx in enumerate(contexts, 1):
209
- time_str = format_relative_time(ctx.last_active)
210
- md = get_mode_display(getattr(ctx, "mode", "idle"))
211
- si = f" {md}" if md else ""
212
- lines.append(f"**{i}. {ctx.id}**{si}")
213
- lines.append(f" {ctx.summary}")
214
- if ctx.method:
215
- lines.append(f" Method: {ctx.method} | Last active: {time_str}")
216
- else:
217
- lines.append(f" Last active: {time_str}")
218
- lines.append("")
219
- return "\n".join(lines)
220
-
221
-
222
- def format_context_created(ctx) -> str:
223
- """Format notification for a newly created context."""
224
- return "\n".join([
225
- f"## Context Created: {ctx.id}", "", f"**Summary:** {ctx.summary}", "",
226
- "A new context has been created for this work.",
227
- "Tasks created with TaskCreate will be persisted to this context."])
228
-
229
-
230
- def format_active_context_reminder(ctx, project_root: Path = None, include_restore: bool = False) -> str:
231
- """Format system reminder: lightweight (per-prompt) or rich (first-bind restore)."""
232
- time_str = format_relative_time(ctx.last_active)
233
- label = _mode_label(ctx)
234
- if include_restore:
235
- lines = [f"## Resuming Context: {ctx.id}", "", f"**Summary:** {ctx.summary}", f"**Mode:** {label}"]
236
- restore = _build_restore_sections(ctx, project_root, inline_plan=True)
237
- if restore:
238
- lines.append(restore)
239
- lines.extend(["", "---", "", "**Instructions:**",
240
- "1. Review the previous work above",
241
- "2. Continue from where the previous session left off"])
242
- else:
243
- lines = [
244
- f"## Active Context: {ctx.id}", "", f"**Summary:** {ctx.summary}",
245
- f"**Mode:** {label}", f"**Last Active:** {time_str}", "",
246
- f'All work belongs to context "{ctx.id}".',
247
- "Tasks created with TaskCreate will be persisted to this context."]
248
- return "\n".join(lines)
249
-
250
-
251
- # ── Picker / command feedback ──────────────────────────────────────
252
-
253
- def format_context_picker_stderr(contexts: list) -> str:
254
- """Format the boxed picker shown on stderr when blocking for selection."""
255
- lines = ["",
256
- "+----------------------------------------------------------------+",
257
- "| CONTEXT SELECTION REQUIRED |",
258
- "+----------------------------------------------------------------+"]
259
- selectable_count = 0
260
- for i, ctx in enumerate(contexts, 1):
261
- time_str = format_relative_time(ctx.last_active)
262
- mode = getattr(ctx, "mode", "idle")
263
- is_selectable = mode == "active" or getattr(ctx, "handoff_path", None)
264
- if is_selectable:
265
- selectable_count += 1
266
- status = ""
267
- if getattr(ctx, "handoff_path", None):
268
- status = " [Handoff Ready]"
269
- elif get_mode_display(mode):
270
- status = f" {get_mode_display(mode)}"
271
- summary = ctx.summary[:45] + "..." if len(ctx.summary) > 48 else ctx.summary
272
- sel_tag = " [selectable]" if is_selectable else " [end only]"
273
- lines.append(f"| ^{i} {ctx.id}{status}{sel_tag}")
274
- lines.append(f"| {summary}")
275
- lines.append(f"| [{time_str}]")
276
- lines.append("|")
277
- lines.extend([
278
- "+----------------------------------------------------------------+",
279
- "| Usage: |",
280
- "| ^S<N> - Select context by number |",
281
- "| ^E<N> - End/complete context by number |",
282
- "| ^S:query - Select by ID match (race-safe) |",
283
- "| ^E:query - End by ID match (race-safe) |",
284
- "| ^E<N>+ - End context N and all after |",
285
- "| ^E* - End ALL contexts |",
286
- "| ^E1E2S3 - End #1 and #2, select #3 |",
287
- "| ^E:fooS:bar - End 'foo...', select 'bar...' |",
288
- "| ^0 work description - Create new context (10+ chars) |",
289
- "+----------------------------------------------------------------+"])
290
- if selectable_count == 0:
291
- lines.extend([
292
- "| NOTE: No selectable contexts. |",
293
- "| Use ^E<N> to end old contexts, then ^0 to create new. |",
294
- "+----------------------------------------------------------------+"])
295
- lines.append("")
296
- return "\n".join(lines)
297
-
298
-
299
- def format_command_feedback(ended_contexts: list, selected_context=None) -> str:
300
- """Format feedback about caret command operations performed."""
301
- lines = []
302
- if ended_contexts:
303
- lines.extend(["## Contexts Ended", ""])
304
- for ctx in ended_contexts:
305
- s = ctx.summary[:50] + "..." if len(ctx.summary) > 50 else ctx.summary
306
- lines.append(f"- **{ctx.id}**: {s}")
307
- lines.append("")
308
- if selected_context:
309
- label = _mode_label(selected_context)
310
- time_str = format_relative_time(selected_context.last_active)
311
- lines.extend([
312
- f"## Active Context: {selected_context.id}", "",
313
- f"**Summary:** {selected_context.summary}",
314
- f"**Mode:** {label}", f"**Last Active:** {time_str}", "",
315
- f'All work belongs to context "{selected_context.id}".',
316
- "Tasks created with TaskCreate will be persisted to this context."])
317
- return "\n".join(lines)