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
@@ -0,0 +1,345 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Resume a handoff document by reading all sections and outputting
4
+ * a structured briefing to stdout.
5
+ *
6
+ * Usage:
7
+ * bun .aiwcli/_shared/scripts/resume_handoff.ts <handoff_folder_or_index>
8
+ * bun .aiwcli/_shared/scripts/resume_handoff.ts --context <context_id>
9
+ *
10
+ * If no args, auto-discovers the active context and finds the latest handoff.
11
+ *
12
+ * Outputs structured markdown to stdout in priority order,
13
+ * ready to be consumed by the /handoff-resume command template.
14
+ */
15
+ import * as fs from "node:fs";
16
+ import * as path from "node:path";
17
+
18
+ import {
19
+ findLatestHandoff,
20
+ readHandoffSections,
21
+ getHandoffTimestamp,
22
+ getHandoffPlanReference,
23
+ } from "../lib-ts/handoff/handoff-reader.js";
24
+ import { getProjectRoot } from "../lib-ts/base/constants.js";
25
+ import { findActiveContextId } from "../lib-ts/context/context-store.js";
26
+ import { getGitStatusShort } from "../lib-ts/base/git-state.js";
27
+ import { eprint } from "../lib-ts/base/utils.js";
28
+
29
+ // ---------------------------------------------------------------------------
30
+ // Helpers
31
+ // ---------------------------------------------------------------------------
32
+
33
+ function formatRelativeAge(date: Date): string {
34
+ const now = new Date();
35
+ const diffMs = now.getTime() - date.getTime();
36
+ const diffMin = Math.floor(diffMs / 60_000);
37
+ const diffHours = Math.floor(diffMin / 60);
38
+ const diffDays = Math.floor(diffHours / 24);
39
+
40
+ if (diffDays === 0) {
41
+ if (diffHours === 0) {
42
+ return diffMin <= 1 ? "just now" : `${diffMin} minutes ago`;
43
+ }
44
+ return diffHours === 1 ? "1 hour ago" : `${diffHours} hours ago`;
45
+ }
46
+ if (diffDays === 1) return "yesterday";
47
+ return `${diffDays} days ago`;
48
+ }
49
+
50
+ /**
51
+ * Count plan completion from plan.md content.
52
+ * Returns [completed, total] or null if no checkboxes found.
53
+ */
54
+ function countPlanProgress(planContent: string): [number, number] | null {
55
+ const checked = (planContent.match(/\[x\]/gi) ?? []).length;
56
+ const unchecked = (planContent.match(/\[ \]/g) ?? []).length;
57
+ const total = checked + unchecked;
58
+ if (total === 0) return null;
59
+ return [checked, total];
60
+ }
61
+
62
+ /**
63
+ * Strip the leading H1 title line from section content if present.
64
+ * Handoff section files typically start with "# Title\n\n..."
65
+ */
66
+ function stripTitle(content: string): string {
67
+ const lines = content.split(/\r?\n/);
68
+ if (lines[0]?.startsWith("# ")) {
69
+ // Remove title and leading blank lines
70
+ let i = 1;
71
+ while (i < lines.length && lines[i]!.trim() === "") i++;
72
+ return lines.slice(i).join("\n").trim();
73
+ }
74
+ return content.trim();
75
+ }
76
+
77
+ // ---------------------------------------------------------------------------
78
+ // Resolution
79
+ // ---------------------------------------------------------------------------
80
+
81
+ function resolveHandoffFolder(args: string[]): [string, string | null] {
82
+ const projectRoot = getProjectRoot(process.cwd());
83
+
84
+ // --context <id>
85
+ const ctxIdx = args.indexOf("--context");
86
+ if (ctxIdx !== -1 && args[ctxIdx + 1]) {
87
+ const contextId = args[ctxIdx + 1]!;
88
+ const folder = findLatestHandoff(contextId, projectRoot);
89
+ if (!folder) {
90
+ eprint(`No handoff folders found for context: ${contextId}`);
91
+ process.exit(1);
92
+ }
93
+ return [folder, contextId];
94
+ }
95
+
96
+ // Direct path argument
97
+ if (args.length > 0 && !args[0]!.startsWith("--")) {
98
+ let target = args[0]!;
99
+
100
+ // If it's a file (e.g., index.md), use the parent folder
101
+ try {
102
+ const stat = fs.statSync(target);
103
+ if (stat.isFile()) {
104
+ target = path.dirname(target);
105
+ }
106
+ } catch {
107
+ eprint(`Path not found: ${target}`);
108
+ process.exit(1);
109
+ }
110
+
111
+ // Verify it looks like a handoff folder (has index.md)
112
+ if (!fs.existsSync(path.join(target, "index.md"))) {
113
+ eprint(`Not a handoff folder (no index.md): ${target}`);
114
+ process.exit(1);
115
+ }
116
+
117
+ return [target, null];
118
+ }
119
+
120
+ // Auto-discover active context
121
+ const discoveredId = findActiveContextId(projectRoot);
122
+ if (discoveredId) {
123
+ const folder = findLatestHandoff(discoveredId, projectRoot);
124
+ if (!folder) {
125
+ eprint(`No handoff folders found for context: ${discoveredId} (auto-discovered)`);
126
+ process.exit(1);
127
+ }
128
+ return [folder, discoveredId];
129
+ }
130
+
131
+ eprint(
132
+ "No active context found.\n\n" +
133
+ "Usage: bun resume_handoff.ts <handoff_folder_or_index>\n" +
134
+ " bun resume_handoff.ts --context <context_id>",
135
+ );
136
+ process.exit(1);
137
+ return ["", null]; // unreachable
138
+ }
139
+
140
+ // ---------------------------------------------------------------------------
141
+ // Main
142
+ // ---------------------------------------------------------------------------
143
+
144
+ function main(): void {
145
+ const args = process.argv.slice(2);
146
+ const [handoffFolder, contextId] = resolveHandoffFolder(args);
147
+ const projectRoot = getProjectRoot(process.cwd());
148
+
149
+ // Staleness check
150
+ const timestamp = getHandoffTimestamp(handoffFolder);
151
+ let ageStr = "unknown age";
152
+ let staleWarning = "";
153
+ if (timestamp) {
154
+ ageStr = formatRelativeAge(timestamp);
155
+ const diffDays = Math.floor((Date.now() - timestamp.getTime()) / 86_400_000);
156
+ if (diffDays > 7) {
157
+ staleWarning = `\n> **WARNING:** This handoff is ${diffDays} days old. Git state may have diverged significantly.\n`;
158
+ }
159
+ }
160
+
161
+ // Read all sections
162
+ const sections = readHandoffSections(handoffFolder);
163
+
164
+ // Plan status
165
+ let planStatus = "No plan document";
166
+ const resolvedContextId = contextId ?? extractContextIdFromIndex(sections.index);
167
+ if (sections.plan) {
168
+ const progress = countPlanProgress(sections.plan);
169
+ if (progress) {
170
+ const [done, total] = progress;
171
+ const pct = Math.round((done / total) * 100);
172
+ planStatus = `${done}/${total} complete (${pct}%)`;
173
+ } else {
174
+ planStatus = "Plan present (no checkboxes)";
175
+ }
176
+ } else if (resolvedContextId) {
177
+ // Check for plan reference in context state
178
+ const planRef = getHandoffPlanReference(handoffFolder, resolvedContextId, projectRoot);
179
+ if (planRef) {
180
+ try {
181
+ const planContent = fs.readFileSync(planRef, "utf-8");
182
+ const progress = countPlanProgress(planContent);
183
+ if (progress) {
184
+ const [done, total] = progress;
185
+ const pct = Math.round((done / total) * 100);
186
+ planStatus = `${done}/${total} complete (${pct}%) — from ${path.basename(planRef)}`;
187
+ } else {
188
+ planStatus = `Plan at ${planRef} (no checkboxes)`;
189
+ }
190
+ } catch {
191
+ planStatus = `Plan referenced at ${planRef} (unreadable)`;
192
+ }
193
+ }
194
+ }
195
+
196
+ // Git delta
197
+ const currentGit = getGitStatusShort(projectRoot);
198
+
199
+ // Build output
200
+ const out: string[] = [];
201
+
202
+ out.push(`## Session Resumed from Handoff`);
203
+ out.push("");
204
+ out.push(`**Source:** \`${path.basename(handoffFolder)}\` (${ageStr})`);
205
+ if (resolvedContextId) out.push(`**Context:** ${resolvedContextId}`);
206
+ out.push(`**Plan Status:** ${planStatus}`);
207
+ if (staleWarning) out.push(staleWarning);
208
+ out.push("");
209
+ out.push("---");
210
+ out.push("");
211
+
212
+ // Priority 1: Dead Ends
213
+ out.push("### Dead Ends — Do Not Retry");
214
+ out.push("");
215
+ if (sections.deadEnds) {
216
+ const content = stripTitle(sections.deadEnds);
217
+ if (content && content !== "(No content for this section)") {
218
+ out.push(content);
219
+ } else {
220
+ out.push("(No dead ends recorded)");
221
+ }
222
+ } else {
223
+ out.push("(No dead-ends.md found)");
224
+ }
225
+ out.push("");
226
+
227
+ // Priority 2: Pending
228
+ out.push("### Pending Items");
229
+ out.push("");
230
+ if (sections.pending) {
231
+ const content = stripTitle(sections.pending);
232
+ if (content && content !== "(No content for this section)") {
233
+ out.push(content);
234
+ } else {
235
+ out.push("(No pending items)");
236
+ }
237
+ } else {
238
+ out.push("(No pending.md found)");
239
+ }
240
+ out.push("");
241
+
242
+ // Priority 3: Plan remaining items (from plan.md in handoff)
243
+ if (sections.plan) {
244
+ const planContent = stripTitle(sections.plan);
245
+ // Extract unchecked items
246
+ const remaining = planContent
247
+ .split(/\r?\n/)
248
+ .filter(line => /\[ \]/.test(line))
249
+ .map(line => line.trim());
250
+ if (remaining.length > 0) {
251
+ out.push("### Plan — Remaining Items");
252
+ out.push("");
253
+ for (const item of remaining) {
254
+ out.push(item);
255
+ }
256
+ out.push("");
257
+ }
258
+ }
259
+
260
+ // Priority 4: Decisions
261
+ out.push("### Settled Decisions");
262
+ out.push("");
263
+ if (sections.decisions) {
264
+ const content = stripTitle(sections.decisions);
265
+ if (content && content !== "(No content for this section)") {
266
+ out.push(content);
267
+ } else {
268
+ out.push("(No decisions recorded)");
269
+ }
270
+ } else {
271
+ out.push("(No decisions.md found)");
272
+ }
273
+ out.push("");
274
+
275
+ // Priority 5: Git Delta
276
+ out.push("### Git Delta Since Handoff");
277
+ out.push("");
278
+ out.push("**Current git status:**");
279
+ out.push("```");
280
+ out.push(currentGit);
281
+ out.push("```");
282
+ out.push("");
283
+
284
+ // Priority 6: Completed Work
285
+ out.push("### Completed Work");
286
+ out.push("");
287
+ if (sections.completedWork) {
288
+ const content = stripTitle(sections.completedWork);
289
+ if (content && content !== "(No content for this section)") {
290
+ out.push(content);
291
+ } else {
292
+ out.push("(No completed work recorded)");
293
+ }
294
+ } else {
295
+ out.push("(No completed-work.md found)");
296
+ }
297
+ out.push("");
298
+
299
+ // Priority 7: Context
300
+ out.push("### Context Notes");
301
+ out.push("");
302
+ if (sections.context) {
303
+ const content = stripTitle(sections.context);
304
+ if (content && content !== "(No content for this section)") {
305
+ out.push(content);
306
+ } else {
307
+ out.push("None");
308
+ }
309
+ } else {
310
+ out.push("None");
311
+ }
312
+ out.push("");
313
+
314
+ // Footer
315
+ out.push("---");
316
+ out.push("");
317
+ out.push("**Create ISC tasks** from the pending items and remaining plan items above using TaskCreate. Each task should be ~8 words, state a desired end-state (not an action), and be binary testable.");
318
+
319
+ console.log(out.join("\n"));
320
+ }
321
+
322
+ /**
323
+ * Try to extract context_id from index.md frontmatter.
324
+ */
325
+ function extractContextIdFromIndex(indexContent: string | null): string | null {
326
+ if (!indexContent) return null;
327
+ if (!indexContent.startsWith("---")) return null;
328
+
329
+ const parts = indexContent.split("---", 3);
330
+ if (parts.length < 3) return null;
331
+
332
+ for (const line of parts[1]!.trim().split(/\r?\n/)) {
333
+ const colonIdx = line.indexOf(":");
334
+ if (colonIdx !== -1) {
335
+ const key = line.slice(0, colonIdx).trim();
336
+ if (key === "context_id") {
337
+ return line.slice(colonIdx + 1).trim();
338
+ }
339
+ }
340
+ }
341
+
342
+ return null;
343
+ }
344
+
345
+ main();
@@ -40,7 +40,7 @@ function parseFrontmatter(content: string): [Record<string, string>, string] {
40
40
  if (content.startsWith("---")) {
41
41
  const parts = content.split("---", 3);
42
42
  if (parts.length >= 3) {
43
- for (const line of parts[1]!.trim().split("\n")) {
43
+ for (const line of parts[1]!.trim().split(/\r?\n/)) {
44
44
  const colonIdx = line.indexOf(":");
45
45
  if (colonIdx !== -1) {
46
46
  const key = line.slice(0, colonIdx).trim();
@@ -60,7 +60,7 @@ function parseHandoffSections(content: string): Record<string, string> {
60
60
  let currentSection: string | null = null;
61
61
  const currentContent: string[] = [];
62
62
 
63
- for (const line of content.split("\n")) {
63
+ for (const line of content.split(/\r?\n/)) {
64
64
  const marker = line.trim().match(/<!-- SECTION:\s*(\S+)\s*-->/);
65
65
  if (marker) {
66
66
  if (currentSection) {
@@ -125,7 +125,7 @@ function generateIndex(
125
125
  const summary = (sections["summary"] ?? "").trim();
126
126
  if (summary) {
127
127
  const summaryText = summary
128
- .split("\n")
128
+ .split(/\r?\n/)
129
129
  .filter(l => !l.trim().startsWith("##"))
130
130
  .join("\n")
131
131
  .trim();