opentasks 0.0.3 → 0.0.4

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 (298) hide show
  1. package/README.md +58 -1
  2. package/dist/cli.d.ts +1 -0
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +81 -1
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client/client.d.ts +20 -0
  7. package/dist/client/client.d.ts.map +1 -1
  8. package/dist/client/client.js +46 -5
  9. package/dist/client/client.js.map +1 -1
  10. package/dist/config/env.d.ts.map +1 -1
  11. package/dist/config/env.js +11 -0
  12. package/dist/config/env.js.map +1 -1
  13. package/dist/config/index.d.ts +1 -1
  14. package/dist/config/index.d.ts.map +1 -1
  15. package/dist/config/index.js.map +1 -1
  16. package/dist/config/schema.d.ts +76 -0
  17. package/dist/config/schema.d.ts.map +1 -1
  18. package/dist/config/schema.js +60 -0
  19. package/dist/config/schema.js.map +1 -1
  20. package/dist/core/init.d.ts +17 -0
  21. package/dist/core/init.d.ts.map +1 -0
  22. package/dist/core/init.js +54 -0
  23. package/dist/core/init.js.map +1 -0
  24. package/dist/daemon/entire-linker.d.ts +3 -0
  25. package/dist/daemon/entire-linker.d.ts.map +1 -1
  26. package/dist/daemon/entire-linker.js +29 -2
  27. package/dist/daemon/entire-linker.js.map +1 -1
  28. package/dist/daemon/factory.d.ts +3 -0
  29. package/dist/daemon/factory.d.ts.map +1 -1
  30. package/dist/daemon/factory.js +2 -1
  31. package/dist/daemon/factory.js.map +1 -1
  32. package/dist/daemon/lifecycle.d.ts.map +1 -1
  33. package/dist/daemon/lifecycle.js +34 -4
  34. package/dist/daemon/lifecycle.js.map +1 -1
  35. package/dist/daemon/location-state.d.ts +2 -1
  36. package/dist/daemon/location-state.d.ts.map +1 -1
  37. package/dist/daemon/location-state.js +19 -4
  38. package/dist/daemon/location-state.js.map +1 -1
  39. package/dist/daemon/methods/tools.d.ts +11 -1
  40. package/dist/daemon/methods/tools.d.ts.map +1 -1
  41. package/dist/daemon/methods/tools.js +40 -6
  42. package/dist/daemon/methods/tools.js.map +1 -1
  43. package/dist/entire/agent/agents/claude-code.d.ts +76 -0
  44. package/dist/entire/agent/agents/claude-code.d.ts.map +1 -0
  45. package/dist/entire/agent/agents/claude-code.js +759 -0
  46. package/dist/entire/agent/agents/claude-code.js.map +1 -0
  47. package/dist/entire/agent/agents/cursor.d.ts +35 -0
  48. package/dist/entire/agent/agents/cursor.d.ts.map +1 -0
  49. package/dist/entire/agent/agents/cursor.js +294 -0
  50. package/dist/entire/agent/agents/cursor.js.map +1 -0
  51. package/dist/entire/agent/agents/gemini-cli.d.ts +62 -0
  52. package/dist/entire/agent/agents/gemini-cli.d.ts.map +1 -0
  53. package/dist/entire/agent/agents/gemini-cli.js +462 -0
  54. package/dist/entire/agent/agents/gemini-cli.js.map +1 -0
  55. package/dist/entire/agent/agents/opencode.d.ts +100 -0
  56. package/dist/entire/agent/agents/opencode.d.ts.map +1 -0
  57. package/dist/entire/agent/agents/opencode.js +423 -0
  58. package/dist/entire/agent/agents/opencode.js.map +1 -0
  59. package/dist/entire/agent/registry.d.ts +54 -0
  60. package/dist/entire/agent/registry.d.ts.map +1 -0
  61. package/dist/entire/agent/registry.js +123 -0
  62. package/dist/entire/agent/registry.js.map +1 -0
  63. package/dist/entire/agent/session-types.d.ts +45 -0
  64. package/dist/entire/agent/session-types.d.ts.map +1 -0
  65. package/dist/entire/agent/session-types.js +50 -0
  66. package/dist/entire/agent/session-types.js.map +1 -0
  67. package/dist/entire/agent/types.d.ts +126 -0
  68. package/dist/entire/agent/types.d.ts.map +1 -0
  69. package/dist/entire/agent/types.js +39 -0
  70. package/dist/entire/agent/types.js.map +1 -0
  71. package/dist/entire/commands/clean.d.ts +30 -0
  72. package/dist/entire/commands/clean.d.ts.map +1 -0
  73. package/dist/entire/commands/clean.js +99 -0
  74. package/dist/entire/commands/clean.js.map +1 -0
  75. package/dist/entire/commands/disable.d.ts +23 -0
  76. package/dist/entire/commands/disable.d.ts.map +1 -0
  77. package/dist/entire/commands/disable.js +57 -0
  78. package/dist/entire/commands/disable.js.map +1 -0
  79. package/dist/entire/commands/doctor.d.ts +43 -0
  80. package/dist/entire/commands/doctor.d.ts.map +1 -0
  81. package/dist/entire/commands/doctor.js +97 -0
  82. package/dist/entire/commands/doctor.js.map +1 -0
  83. package/dist/entire/commands/enable.d.ts +29 -0
  84. package/dist/entire/commands/enable.d.ts.map +1 -0
  85. package/dist/entire/commands/enable.js +102 -0
  86. package/dist/entire/commands/enable.js.map +1 -0
  87. package/dist/entire/commands/explain.d.ts +68 -0
  88. package/dist/entire/commands/explain.d.ts.map +1 -0
  89. package/dist/entire/commands/explain.js +182 -0
  90. package/dist/entire/commands/explain.js.map +1 -0
  91. package/dist/entire/commands/reset.d.ts +23 -0
  92. package/dist/entire/commands/reset.d.ts.map +1 -0
  93. package/dist/entire/commands/reset.js +68 -0
  94. package/dist/entire/commands/reset.js.map +1 -0
  95. package/dist/entire/commands/resume.d.ts +42 -0
  96. package/dist/entire/commands/resume.d.ts.map +1 -0
  97. package/dist/entire/commands/resume.js +134 -0
  98. package/dist/entire/commands/resume.js.map +1 -0
  99. package/dist/entire/commands/rewind.d.ts +34 -0
  100. package/dist/entire/commands/rewind.d.ts.map +1 -0
  101. package/dist/entire/commands/rewind.js +155 -0
  102. package/dist/entire/commands/rewind.js.map +1 -0
  103. package/dist/entire/commands/status.d.ts +51 -0
  104. package/dist/entire/commands/status.d.ts.map +1 -0
  105. package/dist/entire/commands/status.js +94 -0
  106. package/dist/entire/commands/status.js.map +1 -0
  107. package/dist/entire/config.d.ts +40 -0
  108. package/dist/entire/config.d.ts.map +1 -0
  109. package/dist/entire/config.js +126 -0
  110. package/dist/entire/config.js.map +1 -0
  111. package/dist/entire/git-operations.d.ts +170 -0
  112. package/dist/entire/git-operations.d.ts.map +1 -0
  113. package/dist/entire/git-operations.js +395 -0
  114. package/dist/entire/git-operations.js.map +1 -0
  115. package/dist/entire/hooks/git-hooks.d.ts +22 -0
  116. package/dist/entire/hooks/git-hooks.d.ts.map +1 -0
  117. package/dist/entire/hooks/git-hooks.js +145 -0
  118. package/dist/entire/hooks/git-hooks.js.map +1 -0
  119. package/dist/entire/hooks/lifecycle.d.ts +21 -0
  120. package/dist/entire/hooks/lifecycle.d.ts.map +1 -0
  121. package/dist/entire/hooks/lifecycle.js +179 -0
  122. package/dist/entire/hooks/lifecycle.js.map +1 -0
  123. package/dist/entire/index.d.ts +68 -0
  124. package/dist/entire/index.d.ts.map +1 -0
  125. package/dist/entire/index.js +152 -0
  126. package/dist/entire/index.js.map +1 -0
  127. package/dist/entire/security/redaction.d.ts +35 -0
  128. package/dist/entire/security/redaction.d.ts.map +1 -0
  129. package/dist/entire/security/redaction.js +221 -0
  130. package/dist/entire/security/redaction.js.map +1 -0
  131. package/dist/entire/session/state-machine.d.ts +90 -0
  132. package/dist/entire/session/state-machine.d.ts.map +1 -0
  133. package/dist/entire/session/state-machine.js +347 -0
  134. package/dist/entire/session/state-machine.js.map +1 -0
  135. package/dist/entire/store/checkpoint-store.d.ts +47 -0
  136. package/dist/entire/store/checkpoint-store.d.ts.map +1 -0
  137. package/dist/entire/store/checkpoint-store.js +307 -0
  138. package/dist/entire/store/checkpoint-store.js.map +1 -0
  139. package/dist/entire/store/native-store.d.ts +14 -0
  140. package/dist/entire/store/native-store.d.ts.map +1 -0
  141. package/dist/entire/store/native-store.js +159 -0
  142. package/dist/entire/store/native-store.js.map +1 -0
  143. package/dist/entire/store/session-store.d.ts +28 -0
  144. package/dist/entire/store/session-store.d.ts.map +1 -0
  145. package/dist/entire/store/session-store.js +187 -0
  146. package/dist/entire/store/session-store.js.map +1 -0
  147. package/dist/entire/strategy/attribution.d.ts +39 -0
  148. package/dist/entire/strategy/attribution.d.ts.map +1 -0
  149. package/dist/entire/strategy/attribution.js +227 -0
  150. package/dist/entire/strategy/attribution.js.map +1 -0
  151. package/dist/entire/strategy/common.d.ts +57 -0
  152. package/dist/entire/strategy/common.d.ts.map +1 -0
  153. package/dist/entire/strategy/common.js +156 -0
  154. package/dist/entire/strategy/common.js.map +1 -0
  155. package/dist/entire/strategy/content-overlap.d.ts +33 -0
  156. package/dist/entire/strategy/content-overlap.d.ts.map +1 -0
  157. package/dist/entire/strategy/content-overlap.js +168 -0
  158. package/dist/entire/strategy/content-overlap.js.map +1 -0
  159. package/dist/entire/strategy/manual-commit.d.ts +31 -0
  160. package/dist/entire/strategy/manual-commit.d.ts.map +1 -0
  161. package/dist/entire/strategy/manual-commit.js +730 -0
  162. package/dist/entire/strategy/manual-commit.js.map +1 -0
  163. package/dist/entire/strategy/types.d.ts +163 -0
  164. package/dist/entire/strategy/types.d.ts.map +1 -0
  165. package/dist/entire/strategy/types.js +49 -0
  166. package/dist/entire/strategy/types.js.map +1 -0
  167. package/dist/entire/summarize/claude-generator.d.ts +25 -0
  168. package/dist/entire/summarize/claude-generator.d.ts.map +1 -0
  169. package/dist/entire/summarize/claude-generator.js +87 -0
  170. package/dist/entire/summarize/claude-generator.js.map +1 -0
  171. package/dist/entire/summarize/summarize.d.ts +52 -0
  172. package/dist/entire/summarize/summarize.d.ts.map +1 -0
  173. package/dist/entire/summarize/summarize.js +335 -0
  174. package/dist/entire/summarize/summarize.js.map +1 -0
  175. package/dist/entire/types.d.ts +288 -0
  176. package/dist/entire/types.d.ts.map +1 -0
  177. package/dist/entire/types.js +94 -0
  178. package/dist/entire/types.js.map +1 -0
  179. package/dist/entire/utils/chunk-files.d.ts +25 -0
  180. package/dist/entire/utils/chunk-files.d.ts.map +1 -0
  181. package/dist/entire/utils/chunk-files.js +47 -0
  182. package/dist/entire/utils/chunk-files.js.map +1 -0
  183. package/dist/entire/utils/commit-message.d.ts +11 -0
  184. package/dist/entire/utils/commit-message.d.ts.map +1 -0
  185. package/dist/entire/utils/commit-message.js +54 -0
  186. package/dist/entire/utils/commit-message.js.map +1 -0
  187. package/dist/entire/utils/detect-agent.d.ts +19 -0
  188. package/dist/entire/utils/detect-agent.d.ts.map +1 -0
  189. package/dist/entire/utils/detect-agent.js +34 -0
  190. package/dist/entire/utils/detect-agent.js.map +1 -0
  191. package/dist/entire/utils/hook-managers.d.ts +24 -0
  192. package/dist/entire/utils/hook-managers.d.ts.map +1 -0
  193. package/dist/entire/utils/hook-managers.js +87 -0
  194. package/dist/entire/utils/hook-managers.js.map +1 -0
  195. package/dist/entire/utils/ide-tags.d.ts +12 -0
  196. package/dist/entire/utils/ide-tags.d.ts.map +1 -0
  197. package/dist/entire/utils/ide-tags.js +30 -0
  198. package/dist/entire/utils/ide-tags.js.map +1 -0
  199. package/dist/entire/utils/paths.d.ts +32 -0
  200. package/dist/entire/utils/paths.d.ts.map +1 -0
  201. package/dist/entire/utils/paths.js +55 -0
  202. package/dist/entire/utils/paths.js.map +1 -0
  203. package/dist/entire/utils/preview-rewind.d.ts +23 -0
  204. package/dist/entire/utils/preview-rewind.d.ts.map +1 -0
  205. package/dist/entire/utils/preview-rewind.js +63 -0
  206. package/dist/entire/utils/preview-rewind.js.map +1 -0
  207. package/dist/entire/utils/rewind-conflict.d.ts +52 -0
  208. package/dist/entire/utils/rewind-conflict.d.ts.map +1 -0
  209. package/dist/entire/utils/rewind-conflict.js +79 -0
  210. package/dist/entire/utils/rewind-conflict.js.map +1 -0
  211. package/dist/entire/utils/shadow-branch.d.ts +44 -0
  212. package/dist/entire/utils/shadow-branch.d.ts.map +1 -0
  213. package/dist/entire/utils/shadow-branch.js +93 -0
  214. package/dist/entire/utils/shadow-branch.js.map +1 -0
  215. package/dist/entire/utils/string-utils.d.ts +24 -0
  216. package/dist/entire/utils/string-utils.d.ts.map +1 -0
  217. package/dist/entire/utils/string-utils.js +47 -0
  218. package/dist/entire/utils/string-utils.js.map +1 -0
  219. package/dist/entire/utils/todo-extract.d.ts +52 -0
  220. package/dist/entire/utils/todo-extract.d.ts.map +1 -0
  221. package/dist/entire/utils/todo-extract.js +167 -0
  222. package/dist/entire/utils/todo-extract.js.map +1 -0
  223. package/dist/entire/utils/trailers.d.ts +36 -0
  224. package/dist/entire/utils/trailers.d.ts.map +1 -0
  225. package/dist/entire/utils/trailers.js +149 -0
  226. package/dist/entire/utils/trailers.js.map +1 -0
  227. package/dist/entire/utils/transcript-parse.d.ts +57 -0
  228. package/dist/entire/utils/transcript-parse.d.ts.map +1 -0
  229. package/dist/entire/utils/transcript-parse.js +126 -0
  230. package/dist/entire/utils/transcript-parse.js.map +1 -0
  231. package/dist/entire/utils/transcript-timestamp.d.ts +22 -0
  232. package/dist/entire/utils/transcript-timestamp.d.ts.map +1 -0
  233. package/dist/entire/utils/transcript-timestamp.js +56 -0
  234. package/dist/entire/utils/transcript-timestamp.js.map +1 -0
  235. package/dist/entire/utils/tree-ops.d.ts +47 -0
  236. package/dist/entire/utils/tree-ops.d.ts.map +1 -0
  237. package/dist/entire/utils/tree-ops.js +145 -0
  238. package/dist/entire/utils/tree-ops.js.map +1 -0
  239. package/dist/entire/utils/tty.d.ts +25 -0
  240. package/dist/entire/utils/tty.d.ts.map +1 -0
  241. package/dist/entire/utils/tty.js +70 -0
  242. package/dist/entire/utils/tty.js.map +1 -0
  243. package/dist/entire/utils/validation.d.ts +31 -0
  244. package/dist/entire/utils/validation.d.ts.map +1 -0
  245. package/dist/entire/utils/validation.js +59 -0
  246. package/dist/entire/utils/validation.js.map +1 -0
  247. package/dist/entire/utils/worktree.d.ts +16 -0
  248. package/dist/entire/utils/worktree.d.ts.map +1 -0
  249. package/dist/entire/utils/worktree.js +50 -0
  250. package/dist/entire/utils/worktree.js.map +1 -0
  251. package/dist/index.d.ts +3 -0
  252. package/dist/index.d.ts.map +1 -1
  253. package/dist/index.js +6 -0
  254. package/dist/index.js.map +1 -1
  255. package/dist/providers/entire.d.ts +27 -2
  256. package/dist/providers/entire.d.ts.map +1 -1
  257. package/dist/providers/entire.js +13 -2
  258. package/dist/providers/entire.js.map +1 -1
  259. package/dist/providers/from-config.d.ts.map +1 -1
  260. package/dist/providers/from-config.js +23 -0
  261. package/dist/providers/from-config.js.map +1 -1
  262. package/dist/providers/global.d.ts +27 -0
  263. package/dist/providers/global.d.ts.map +1 -0
  264. package/dist/providers/global.js +242 -0
  265. package/dist/providers/global.js.map +1 -0
  266. package/dist/providers/index.d.ts +2 -1
  267. package/dist/providers/index.d.ts.map +1 -1
  268. package/dist/providers/index.js +3 -1
  269. package/dist/providers/index.js.map +1 -1
  270. package/dist/schema/edges.d.ts +5 -1
  271. package/dist/schema/edges.d.ts.map +1 -1
  272. package/dist/schema/index.d.ts +1 -1
  273. package/dist/schema/index.d.ts.map +1 -1
  274. package/dist/tracking/claude-task-reconstructor.d.ts +41 -0
  275. package/dist/tracking/claude-task-reconstructor.d.ts.map +1 -0
  276. package/dist/tracking/claude-task-reconstructor.js +91 -0
  277. package/dist/tracking/claude-task-reconstructor.js.map +1 -0
  278. package/dist/tracking/claude-tool-categorizer.d.ts +30 -0
  279. package/dist/tracking/claude-tool-categorizer.d.ts.map +1 -0
  280. package/dist/tracking/claude-tool-categorizer.js +98 -0
  281. package/dist/tracking/claude-tool-categorizer.js.map +1 -0
  282. package/dist/tracking/index.d.ts +19 -0
  283. package/dist/tracking/index.d.ts.map +1 -0
  284. package/dist/tracking/index.js +14 -0
  285. package/dist/tracking/index.js.map +1 -0
  286. package/dist/tracking/plan-mode-tracker.d.ts +20 -0
  287. package/dist/tracking/plan-mode-tracker.d.ts.map +1 -0
  288. package/dist/tracking/plan-mode-tracker.js +35 -0
  289. package/dist/tracking/plan-mode-tracker.js.map +1 -0
  290. package/dist/tracking/skill-tracker.d.ts +133 -0
  291. package/dist/tracking/skill-tracker.d.ts.map +1 -0
  292. package/dist/tracking/skill-tracker.js +130 -0
  293. package/dist/tracking/skill-tracker.js.map +1 -0
  294. package/dist/tracking/transcript-extractor.d.ts +45 -0
  295. package/dist/tracking/transcript-extractor.d.ts.map +1 -0
  296. package/dist/tracking/transcript-extractor.js +174 -0
  297. package/dist/tracking/transcript-extractor.js.map +1 -0
  298. package/package.json +2 -1
@@ -0,0 +1,730 @@
1
+ /**
2
+ * Manual Commit Strategy
3
+ *
4
+ * Core strategy implementation that orchestrates session tracking,
5
+ * checkpoint creation, condensation, and git hook integration.
6
+ *
7
+ * Data flow:
8
+ * 1. InitializeSession -> Creates SessionState, calculates initial attribution
9
+ * 2. SaveStep/SaveTaskStep -> Writes to shadow branch via CheckpointStore
10
+ * 3. PrepareCommitMsg -> Adds Entire-Checkpoint trailer to commit messages
11
+ * 4. PostCommit -> Condenses session data, handles carry-forward
12
+ * 5. PrePush -> Pushes metadata branch alongside user push
13
+ */
14
+ import * as fs from 'node:fs';
15
+ import * as path from 'node:path';
16
+ import { addTokenUsage, CHECKPOINTS_BRANCH, SHADOW_BRANCH_PREFIX, validateCheckpointID, } from '../types.js';
17
+ import { git, gitSafe, getHead, getCurrentBranch, getWorktreeRoot, getGitAuthor, getUntrackedFiles, refExists, pushBranch, hasUncommittedChanges, listBranches, showFile, lsTree, deleteBranch, updateRef, diffNameOnly, } from '../git-operations.js';
18
+ import { parseCheckpoint, formatShadowCommit, CheckpointTrailerKey, } from '../utils/trailers.js';
19
+ import { filesOverlapWithContent, stagedFilesOverlapWithContent, filesWithRemainingAgentChanges, } from './content-overlap.js';
20
+ import { STRATEGY_NAME_MANUAL_COMMIT, PROMPT_TRUNCATE_LENGTH, formatSubagentEndMessage, } from './types.js';
21
+ import { truncateRunes, collapseWhitespace } from '../utils/string-utils.js';
22
+ export function createManualCommitStrategy(config) {
23
+ const { sessionStore, checkpointStore, cwd } = config;
24
+ // ========================================================================
25
+ // Session State Helpers
26
+ // ========================================================================
27
+ async function loadSession(sessionID) {
28
+ return sessionStore.load(sessionID);
29
+ }
30
+ async function saveSession(state) {
31
+ await sessionStore.save(state);
32
+ }
33
+ async function clearSession(sessionID) {
34
+ await sessionStore.delete(sessionID);
35
+ }
36
+ async function listAllSessions() {
37
+ return sessionStore.list();
38
+ }
39
+ async function findSessionsForCommit(baseCommitSHA) {
40
+ const all = await listAllSessions();
41
+ return all.filter(s => s.baseCommit === baseCommitSHA);
42
+ }
43
+ function getShadowBranchName(baseCommit, worktreeID) {
44
+ return checkpointStore.getShadowBranchName(baseCommit, worktreeID);
45
+ }
46
+ // ========================================================================
47
+ // File Merging Helpers
48
+ // ========================================================================
49
+ function mergeFilesTouched(existing, ...fileLists) {
50
+ const seen = new Set(existing);
51
+ for (const list of fileLists) {
52
+ for (const f of list)
53
+ seen.add(f);
54
+ }
55
+ return Array.from(seen).sort();
56
+ }
57
+ function truncatePrompt(prompt) {
58
+ if (!prompt)
59
+ return '';
60
+ const cleaned = collapseWhitespace(prompt);
61
+ return truncateRunes(cleaned, PROMPT_TRUNCATE_LENGTH, '...');
62
+ }
63
+ // ========================================================================
64
+ // Strategy Implementation
65
+ // ========================================================================
66
+ const strategy = {
67
+ name: STRATEGY_NAME_MANUAL_COMMIT,
68
+ // ======================================================================
69
+ // PrepareCommitMsg - Add checkpoint trailer to commit messages
70
+ // ======================================================================
71
+ async prepareCommitMsg(commitMsgFile, source, _sha) {
72
+ // Read the current commit message
73
+ const commitMsg = fs.readFileSync(commitMsgFile, 'utf-8');
74
+ // Skip merge commits
75
+ if (source === 'merge')
76
+ return;
77
+ // Handle amend: preserve existing checkpoint trailer
78
+ if (source === 'commit') {
79
+ const [cpID, found] = parseCheckpoint(commitMsg);
80
+ if (found && cpID) {
81
+ // Trailer already present, nothing to do
82
+ return;
83
+ }
84
+ }
85
+ // Get current HEAD
86
+ const head = await getHead(cwd);
87
+ // Find active sessions for this commit
88
+ const sessions = await findSessionsForCommit(head);
89
+ if (sessions.length === 0)
90
+ return;
91
+ // Get staged files
92
+ const stagedOutput = await gitSafe(['diff', '--cached', '--name-only', '--diff-filter=ACMRD'], { cwd });
93
+ if (!stagedOutput)
94
+ return;
95
+ const stagedFiles = stagedOutput
96
+ .trim()
97
+ .split('\n')
98
+ .filter(f => f.length > 0);
99
+ if (stagedFiles.length === 0)
100
+ return;
101
+ // Check if any session has overlapping work
102
+ let hasOverlap = false;
103
+ let overlappingSession = null;
104
+ for (const state of sessions) {
105
+ if (state.stepCount === 0 || state.filesTouched.length === 0)
106
+ continue;
107
+ const shadowBranch = getShadowBranchName(state.baseCommit, state.worktreeID);
108
+ const exists = await refExists(`refs/heads/${shadowBranch}`, cwd);
109
+ if (!exists)
110
+ continue;
111
+ // Content-aware overlap check
112
+ const overlap = await stagedFilesOverlapWithContent(shadowBranch, stagedFiles, state.filesTouched, cwd);
113
+ if (overlap) {
114
+ hasOverlap = true;
115
+ overlappingSession = state;
116
+ break;
117
+ }
118
+ }
119
+ if (!hasOverlap || !overlappingSession)
120
+ return;
121
+ // Generate or reuse checkpoint ID
122
+ let cpID;
123
+ if (overlappingSession.lastCheckpointID && validateCheckpointID(overlappingSession.lastCheckpointID)) {
124
+ cpID = overlappingSession.lastCheckpointID;
125
+ }
126
+ else {
127
+ cpID = await checkpointStore.generateID();
128
+ }
129
+ // Inject trailer into commit message
130
+ const trailer = `${CheckpointTrailerKey}: ${cpID}`;
131
+ const injected = injectCheckpointTrailer(commitMsg, trailer);
132
+ fs.writeFileSync(commitMsgFile, injected, 'utf-8');
133
+ },
134
+ // ======================================================================
135
+ // PostCommit - Condense session data after commit
136
+ // ======================================================================
137
+ async postCommit() {
138
+ // Read HEAD commit message
139
+ const headHash = await getHead(cwd);
140
+ const commitMsg = await git(['log', '-1', '--format=%B', headHash], { cwd });
141
+ // Check for checkpoint trailer
142
+ const [cpID, found] = parseCheckpoint(commitMsg);
143
+ if (!found || !cpID)
144
+ return;
145
+ // Find sessions for the parent commit (our base)
146
+ const parentHash = await gitSafe(['rev-parse', `${headHash}^`], { cwd });
147
+ if (!parentHash)
148
+ return;
149
+ const sessions = await findSessionsForCommit(parentHash.trim());
150
+ if (sessions.length === 0)
151
+ return;
152
+ // Get files changed in this commit
153
+ const { added, modified, deleted } = await diffNameOnly(`${headHash}^`, headHash, cwd);
154
+ const committedFiles = new Set([...added, ...modified, ...deleted]);
155
+ // Process each session
156
+ for (const state of sessions) {
157
+ if (state.stepCount === 0 || state.filesTouched.length === 0)
158
+ continue;
159
+ const shadowBranch = getShadowBranchName(state.baseCommit, state.worktreeID);
160
+ const exists = await refExists(`refs/heads/${shadowBranch}`, cwd);
161
+ if (!exists)
162
+ continue;
163
+ // Check overlap with committed files
164
+ const overlap = await filesOverlapWithContent(shadowBranch, headHash, parentHash.trim(), state.filesTouched, cwd);
165
+ if (!overlap)
166
+ continue;
167
+ // Condense this session
168
+ try {
169
+ await condenseSession(state, cpID, committedFiles);
170
+ }
171
+ catch {
172
+ // Log but continue with other sessions
173
+ }
174
+ // Handle carry-forward for remaining files
175
+ const remaining = await filesWithRemainingAgentChanges(shadowBranch, headHash, state.filesTouched, committedFiles, cwd);
176
+ if (remaining.length === 0) {
177
+ // All files committed - clean up shadow branch
178
+ try {
179
+ await checkpointStore.deleteShadowBranch(shadowBranch);
180
+ }
181
+ catch {
182
+ // Best effort cleanup
183
+ }
184
+ // Update session for new base commit
185
+ state.baseCommit = headHash;
186
+ state.stepCount = 0;
187
+ state.filesTouched = [];
188
+ state.promptAttributions = [];
189
+ state.lastCheckpointID = cpID;
190
+ await saveSession(state);
191
+ }
192
+ else {
193
+ // Carry forward: update state for remaining files
194
+ state.baseCommit = headHash;
195
+ state.filesTouched = remaining;
196
+ state.stepCount = 0;
197
+ state.promptAttributions = [];
198
+ state.lastCheckpointID = cpID;
199
+ await saveSession(state);
200
+ }
201
+ }
202
+ },
203
+ // ======================================================================
204
+ // CommitMsg - Strip trailer if no user content (prevents empty commits)
205
+ // ======================================================================
206
+ async commitMsg(commitMsgFile) {
207
+ let content;
208
+ try {
209
+ content = fs.readFileSync(commitMsgFile, 'utf-8');
210
+ }
211
+ catch {
212
+ return; // Hook must be silent on failure
213
+ }
214
+ // Check if our trailer is present
215
+ const [, found] = parseCheckpoint(content);
216
+ if (!found)
217
+ return;
218
+ // Check if there's any user content (non-comment, non-trailer lines)
219
+ if (!hasUserContent(content)) {
220
+ // No user content - strip the trailer so git aborts the commit
221
+ const stripped = stripCheckpointTrailer(content);
222
+ try {
223
+ fs.writeFileSync(commitMsgFile, stripped, 'utf-8');
224
+ }
225
+ catch {
226
+ // Hook must be silent on failure
227
+ }
228
+ }
229
+ },
230
+ // ======================================================================
231
+ // PrePush - Push metadata branch alongside user push
232
+ // ======================================================================
233
+ async prePush(remote) {
234
+ const branchExists = await refExists(`refs/heads/${CHECKPOINTS_BRANCH}`, cwd);
235
+ if (!branchExists)
236
+ return;
237
+ try {
238
+ await pushBranch(remote, CHECKPOINTS_BRANCH, false, cwd);
239
+ }
240
+ catch {
241
+ // Non-fatal: metadata push failure shouldn't block user push
242
+ }
243
+ },
244
+ // ======================================================================
245
+ // SaveStep - Create session checkpoint on shadow branch
246
+ // ======================================================================
247
+ async saveStep(step) {
248
+ const sessionID = path.basename(step.metadataDir);
249
+ let state = await loadSession(sessionID);
250
+ // Initialize if needed
251
+ if (!state || !state.baseCommit) {
252
+ const head = await getHead(cwd);
253
+ const author = await getGitAuthor(cwd);
254
+ const untrackedFiles = await getUntrackedFiles(cwd);
255
+ const worktreeRoot = await getWorktreeRoot(cwd);
256
+ state = {
257
+ sessionID,
258
+ baseCommit: head,
259
+ attributionBaseCommit: head,
260
+ startedAt: new Date().toISOString(),
261
+ phase: 'active',
262
+ turnCheckpointIDs: [],
263
+ stepCount: 0,
264
+ checkpointTranscriptStart: 0,
265
+ untrackedFilesAtStart: untrackedFiles,
266
+ filesTouched: [],
267
+ agentType: step.agentType,
268
+ worktreePath: worktreeRoot,
269
+ };
270
+ await saveSession(state);
271
+ }
272
+ // Migrate shadow branch if HEAD changed (rebase/pull mid-session)
273
+ await migrateAndPersist(state);
274
+ // Write temporary checkpoint
275
+ const isFirstCheckpoint = state.stepCount === 0;
276
+ const result = await checkpointStore.writeTemporary({
277
+ sessionID,
278
+ baseCommit: state.baseCommit,
279
+ worktreeID: state.worktreeID,
280
+ modifiedFiles: step.modifiedFiles,
281
+ newFiles: step.newFiles,
282
+ deletedFiles: step.deletedFiles,
283
+ metadataDir: step.metadataDir,
284
+ metadataDirAbs: step.metadataDirAbs,
285
+ commitMessage: step.commitMessage,
286
+ authorName: step.authorName,
287
+ authorEmail: step.authorEmail,
288
+ isFirstCheckpoint,
289
+ });
290
+ if (result.skipped)
291
+ return;
292
+ // Update session state
293
+ state.stepCount++;
294
+ state.filesTouched = mergeFilesTouched(state.filesTouched, step.modifiedFiles, step.newFiles, step.deletedFiles);
295
+ if (state.stepCount === 1 && step.stepTranscriptIdentifier) {
296
+ state.transcriptIdentifierAtStart = step.stepTranscriptIdentifier;
297
+ }
298
+ if (step.tokenUsage) {
299
+ state.tokenUsage = state.tokenUsage
300
+ ? addTokenUsage(state.tokenUsage, step.tokenUsage)
301
+ : step.tokenUsage;
302
+ }
303
+ await saveSession(state);
304
+ },
305
+ // ======================================================================
306
+ // SaveTaskStep - Create task checkpoint on shadow branch
307
+ // ======================================================================
308
+ async saveTaskStep(step) {
309
+ let state = await loadSession(step.sessionID);
310
+ if (!state || !state.baseCommit) {
311
+ const head = await getHead(cwd);
312
+ const untrackedFiles = await getUntrackedFiles(cwd);
313
+ const worktreeRoot = await getWorktreeRoot(cwd);
314
+ state = {
315
+ sessionID: step.sessionID,
316
+ baseCommit: head,
317
+ attributionBaseCommit: head,
318
+ startedAt: new Date().toISOString(),
319
+ phase: 'active',
320
+ turnCheckpointIDs: [],
321
+ stepCount: 0,
322
+ checkpointTranscriptStart: 0,
323
+ untrackedFilesAtStart: untrackedFiles,
324
+ filesTouched: [],
325
+ agentType: step.agentType,
326
+ worktreePath: worktreeRoot,
327
+ };
328
+ await saveSession(state);
329
+ }
330
+ // Migrate shadow branch if HEAD changed (rebase/pull mid-session)
331
+ await migrateAndPersist(state);
332
+ // Generate commit message for task checkpoint
333
+ const shortToolUseID = step.toolUseID.length > 7 ? step.toolUseID.slice(0, 7) : step.toolUseID;
334
+ const messageSubject = formatSubagentEndMessage(step.subagentType, step.taskDescription, shortToolUseID);
335
+ const metadataDir = `.entire/metadata/${step.sessionID}/tasks/${step.toolUseID}`;
336
+ const commitMsg = formatShadowCommit(messageSubject, metadataDir, step.sessionID);
337
+ // Write temporary checkpoint
338
+ await checkpointStore.writeTemporary({
339
+ sessionID: step.sessionID,
340
+ baseCommit: state.baseCommit,
341
+ worktreeID: state.worktreeID,
342
+ modifiedFiles: step.modifiedFiles,
343
+ newFiles: step.newFiles,
344
+ deletedFiles: step.deletedFiles,
345
+ metadataDir,
346
+ metadataDirAbs: path.resolve(cwd ?? '.', metadataDir),
347
+ commitMessage: commitMsg,
348
+ authorName: step.authorName,
349
+ authorEmail: step.authorEmail,
350
+ isFirstCheckpoint: state.stepCount === 0,
351
+ });
352
+ // Update session state
353
+ state.filesTouched = mergeFilesTouched(state.filesTouched, step.modifiedFiles, step.newFiles, step.deletedFiles);
354
+ await saveSession(state);
355
+ },
356
+ // ======================================================================
357
+ // Rewind operations
358
+ // ======================================================================
359
+ async getRewindPoints(limit) {
360
+ const head = await getHead(cwd);
361
+ const sessions = await findSessionsForCommit(head);
362
+ const allPoints = [];
363
+ for (const state of sessions) {
364
+ const shadowBranch = getShadowBranchName(state.baseCommit, state.worktreeID);
365
+ const exists = await refExists(`refs/heads/${shadowBranch}`, cwd);
366
+ if (!exists)
367
+ continue;
368
+ // List temporary checkpoints
369
+ const temps = await checkpointStore.listTemporary();
370
+ for (const temp of temps) {
371
+ if (temp.baseCommit !== state.baseCommit)
372
+ continue;
373
+ allPoints.push({
374
+ id: temp.latestCommit,
375
+ message: `Checkpoint on ${shadowBranch}`,
376
+ date: new Date(temp.timestamp),
377
+ isTaskCheckpoint: false,
378
+ isLogsOnly: false,
379
+ agent: state.agentType,
380
+ sessionID: state.sessionID,
381
+ sessionPrompt: state.firstPrompt,
382
+ sessionCount: 1,
383
+ sessionIDs: [state.sessionID],
384
+ });
385
+ }
386
+ }
387
+ // Sort by date descending
388
+ allPoints.sort((a, b) => b.date.getTime() - a.date.getTime());
389
+ // Also add logs-only points from commit history
390
+ const logsOnlyPoints = await getLogsOnlyRewindPoints(limit);
391
+ const existingIDs = new Set(allPoints.map(p => p.id));
392
+ for (const p of logsOnlyPoints) {
393
+ if (!existingIDs.has(p.id)) {
394
+ allPoints.push(p);
395
+ }
396
+ }
397
+ // Re-sort and trim
398
+ allPoints.sort((a, b) => b.date.getTime() - a.date.getTime());
399
+ return allPoints.slice(0, limit);
400
+ },
401
+ async rewind(point) {
402
+ if (point.isLogsOnly) {
403
+ throw new Error('Use restoreLogsOnly for logs-only rewind points');
404
+ }
405
+ // Read checkpoint tree and restore files
406
+ const treeEntries = await lsTree(point.id, undefined, cwd);
407
+ const worktreeRoot = await getWorktreeRoot(cwd);
408
+ for (const entry of treeEntries) {
409
+ if (entry.name.startsWith('.entire/'))
410
+ continue;
411
+ try {
412
+ const content = await showFile(point.id, entry.name, cwd);
413
+ const absPath = path.join(worktreeRoot, entry.name);
414
+ const dir = path.dirname(absPath);
415
+ fs.mkdirSync(dir, { recursive: true });
416
+ const perm = entry.mode === '100755' ? 0o755 : 0o644;
417
+ fs.writeFileSync(absPath, content, { mode: perm });
418
+ }
419
+ catch {
420
+ // Skip files that can't be restored
421
+ }
422
+ }
423
+ },
424
+ async canRewind() {
425
+ const hasChanges = await hasUncommittedChanges(cwd);
426
+ if (hasChanges) {
427
+ return [
428
+ true,
429
+ 'Warning: You have uncommitted changes that will be overwritten by the rewind.',
430
+ ];
431
+ }
432
+ return [true, ''];
433
+ },
434
+ // ======================================================================
435
+ // Condensation
436
+ // ======================================================================
437
+ async condense(sessionID) {
438
+ const state = await loadSession(sessionID);
439
+ if (!state) {
440
+ throw new Error(`Session not found: ${sessionID}`);
441
+ }
442
+ const cpID = await checkpointStore.generateID();
443
+ const committedFiles = new Set(state.filesTouched);
444
+ return condenseSession(state, cpID, committedFiles);
445
+ },
446
+ // ======================================================================
447
+ // Validation & Cleanup
448
+ // ======================================================================
449
+ async validateRepository() {
450
+ const { validateRepository: validate } = await import('./common.js');
451
+ await validate(cwd);
452
+ },
453
+ async listOrphanedItems() {
454
+ const items = [];
455
+ // Find orphaned shadow branches
456
+ const allBranches = await listBranches(cwd);
457
+ for (const branch of allBranches) {
458
+ if (branch.startsWith(SHADOW_BRANCH_PREFIX) &&
459
+ branch !== CHECKPOINTS_BRANCH) {
460
+ items.push({
461
+ type: 'shadow-branch',
462
+ id: branch,
463
+ reason: 'shadow branch (should have been auto-cleaned)',
464
+ });
465
+ }
466
+ }
467
+ return items;
468
+ },
469
+ };
470
+ // ========================================================================
471
+ // Internal: Condensation
472
+ // ========================================================================
473
+ async function condenseSession(state, checkpointID, committedFiles) {
474
+ const author = await getGitAuthor(cwd);
475
+ const branch = await getCurrentBranch(cwd);
476
+ // Filter filesTouched to committed subset
477
+ const filesTouched = state.filesTouched.filter(f => committedFiles.has(f));
478
+ // Build transcript and prompts from shadow branch
479
+ let transcript = Buffer.alloc(0);
480
+ let prompts = [];
481
+ let context = Buffer.alloc(0);
482
+ const shadowBranch = getShadowBranchName(state.baseCommit, state.worktreeID);
483
+ const shadowExists = await refExists(`refs/heads/${shadowBranch}`, cwd);
484
+ if (shadowExists) {
485
+ // Read transcript from shadow branch metadata
486
+ try {
487
+ const metadataDir = `.entire/metadata/${state.sessionID}`;
488
+ const fullContent = await gitSafe(['show', `refs/heads/${shadowBranch}:${metadataDir}/full.jsonl`], { cwd });
489
+ if (fullContent) {
490
+ transcript = Buffer.from(fullContent, 'utf-8');
491
+ }
492
+ }
493
+ catch {
494
+ // Use empty transcript
495
+ }
496
+ // Read prompts
497
+ try {
498
+ const metadataDir = `.entire/metadata/${state.sessionID}`;
499
+ const promptContent = await gitSafe(['show', `refs/heads/${shadowBranch}:${metadataDir}/prompt.txt`], { cwd });
500
+ if (promptContent) {
501
+ prompts = promptContent
502
+ .split('\n---\n')
503
+ .filter(p => p.trim().length > 0);
504
+ }
505
+ }
506
+ catch {
507
+ // Use empty prompts
508
+ }
509
+ }
510
+ // If we have a live transcript path, try to read from there
511
+ if (transcript.length === 0 && state.transcriptPath) {
512
+ try {
513
+ transcript = fs.readFileSync(state.transcriptPath);
514
+ }
515
+ catch {
516
+ // Keep empty
517
+ }
518
+ }
519
+ // Generate context from prompts
520
+ if (prompts.length > 0) {
521
+ const contextLines = prompts.map((p, i) => `## Prompt ${i + 1}\n\n${p}`);
522
+ context = Buffer.from(contextLines.join('\n\n---\n\n'), 'utf-8');
523
+ }
524
+ // Write committed checkpoint
525
+ await checkpointStore.writeCommitted({
526
+ checkpointID,
527
+ sessionID: state.sessionID,
528
+ strategy: STRATEGY_NAME_MANUAL_COMMIT,
529
+ branch: branch ?? undefined,
530
+ transcript,
531
+ prompts,
532
+ context,
533
+ filesTouched,
534
+ checkpointsCount: state.stepCount,
535
+ authorName: author.name,
536
+ authorEmail: author.email,
537
+ agent: state.agentType,
538
+ turnID: state.turnID,
539
+ transcriptIdentifierAtStart: state.transcriptIdentifierAtStart,
540
+ checkpointTranscriptStart: state.checkpointTranscriptStart,
541
+ tokenUsage: state.tokenUsage,
542
+ });
543
+ return {
544
+ checkpointID,
545
+ sessionsCondensed: 1,
546
+ checkpointsCount: state.stepCount,
547
+ filesTouched,
548
+ tokenUsage: state.tokenUsage,
549
+ };
550
+ }
551
+ // ========================================================================
552
+ // Internal: Logs-only rewind points from commit history
553
+ // ========================================================================
554
+ async function getLogsOnlyRewindPoints(limit) {
555
+ const points = [];
556
+ // Check if checkpoints branch exists
557
+ const branchExists = await refExists(`refs/heads/${CHECKPOINTS_BRANCH}`, cwd);
558
+ if (!branchExists)
559
+ return points;
560
+ // Get committed checkpoints
561
+ const committed = await checkpointStore.listCommitted(limit);
562
+ if (committed.length === 0)
563
+ return points;
564
+ // Build map of checkpoint IDs
565
+ const cpMap = new Map();
566
+ for (const cp of committed) {
567
+ if (cp.checkpointID) {
568
+ cpMap.set(cp.checkpointID, cp);
569
+ }
570
+ }
571
+ // Walk commit history looking for checkpoint trailers
572
+ const head = await getHead(cwd);
573
+ const logOutput = await gitSafe([
574
+ 'log',
575
+ '--format=%H %s%n%b',
576
+ `--max-count=${limit * 2}`,
577
+ head,
578
+ ], { cwd });
579
+ if (!logOutput)
580
+ return points;
581
+ // Parse log output looking for checkpoint trailers
582
+ const commits = logOutput.split('\n\n').filter(c => c.trim().length > 0);
583
+ for (const commitBlock of commits) {
584
+ const lines = commitBlock.split('\n');
585
+ if (lines.length === 0)
586
+ continue;
587
+ const firstLine = lines[0];
588
+ const spaceIdx = firstLine.indexOf(' ');
589
+ if (spaceIdx < 0)
590
+ continue;
591
+ const sha = firstLine.slice(0, spaceIdx);
592
+ const message = firstLine.slice(spaceIdx + 1);
593
+ const body = lines.slice(1).join('\n');
594
+ const fullMessage = `${message}\n${body}`;
595
+ const [cpID, found] = parseCheckpoint(fullMessage);
596
+ if (!found || !cpID)
597
+ continue;
598
+ const cpInfo = cpMap.get(cpID);
599
+ if (!cpInfo)
600
+ continue;
601
+ points.push({
602
+ id: sha,
603
+ message,
604
+ date: new Date(),
605
+ isLogsOnly: true,
606
+ isTaskCheckpoint: false,
607
+ checkpointID: cpID,
608
+ sessionCount: cpInfo.sessions?.length ?? 1,
609
+ sessionIDs: [],
610
+ });
611
+ if (points.length >= limit)
612
+ break;
613
+ }
614
+ return points;
615
+ }
616
+ // ========================================================================
617
+ // Internal: Shadow branch migration
618
+ // ========================================================================
619
+ /**
620
+ * Check if HEAD has changed since the session started and migrate the
621
+ * shadow branch to the new base commit if needed.
622
+ *
623
+ * This handles the scenario where the agent performs a rebase, pull, or
624
+ * other git operation that changes HEAD mid-session. Without migration,
625
+ * checkpoints would be saved to an orphaned shadow branch.
626
+ */
627
+ async function migrateShadowBranchIfNeeded(state) {
628
+ if (!state.baseCommit)
629
+ return false;
630
+ const currentHead = await getHead(cwd);
631
+ if (state.baseCommit === currentHead)
632
+ return false;
633
+ const oldShadowBranch = getShadowBranchName(state.baseCommit, state.worktreeID);
634
+ const newShadowBranch = getShadowBranchName(currentHead, state.worktreeID);
635
+ // Guard: if both commits produce the same shadow branch name
636
+ // (same 7-char prefix), just update state
637
+ if (oldShadowBranch === newShadowBranch) {
638
+ state.baseCommit = currentHead;
639
+ return true;
640
+ }
641
+ const oldExists = await refExists(`refs/heads/${oldShadowBranch}`, cwd);
642
+ if (!oldExists) {
643
+ // Old shadow branch doesn't exist — just update baseCommit
644
+ state.baseCommit = currentHead;
645
+ return true;
646
+ }
647
+ // Old shadow branch exists — rename it to the new base
648
+ try {
649
+ // Read the current tip of the old branch
650
+ const oldTip = await git(['rev-parse', `refs/heads/${oldShadowBranch}`], { cwd });
651
+ // Create new branch pointing to same commit
652
+ await updateRef(`refs/heads/${newShadowBranch}`, oldTip.trim(), cwd);
653
+ // Delete old branch (best effort)
654
+ try {
655
+ await deleteBranch(oldShadowBranch, false, cwd);
656
+ }
657
+ catch {
658
+ // Non-fatal
659
+ }
660
+ }
661
+ catch {
662
+ // If rename fails, just update state
663
+ }
664
+ state.baseCommit = currentHead;
665
+ return true;
666
+ }
667
+ /**
668
+ * Check for HEAD changes, migrate shadow branch if needed, and persist.
669
+ */
670
+ async function migrateAndPersist(state) {
671
+ const migrated = await migrateShadowBranchIfNeeded(state);
672
+ if (migrated) {
673
+ await saveSession(state);
674
+ }
675
+ }
676
+ return strategy;
677
+ }
678
+ // ============================================================================
679
+ // Helpers
680
+ // ============================================================================
681
+ /**
682
+ * Inject a checkpoint trailer before any git comments in the commit message.
683
+ */
684
+ function injectCheckpointTrailer(message, trailer) {
685
+ const lines = message.split('\n');
686
+ // Find where git comments start (lines beginning with #)
687
+ let insertIndex = lines.length;
688
+ for (let i = 0; i < lines.length; i++) {
689
+ if (lines[i].startsWith('#')) {
690
+ insertIndex = i;
691
+ break;
692
+ }
693
+ }
694
+ // Insert trailer before comments, with a blank line separator
695
+ const before = lines.slice(0, insertIndex);
696
+ const after = lines.slice(insertIndex);
697
+ // Ensure there's a blank line before the trailer
698
+ while (before.length > 0 && before[before.length - 1].trim() === '') {
699
+ before.pop();
700
+ }
701
+ return [...before, '', trailer, '', ...after].join('\n');
702
+ }
703
+ /**
704
+ * Check if a commit message has any content besides comments and our trailer.
705
+ */
706
+ export function hasUserContent(message) {
707
+ const trailerPrefix = CheckpointTrailerKey + ':';
708
+ for (const line of message.split('\n')) {
709
+ const trimmed = line.trim();
710
+ if (!trimmed)
711
+ continue;
712
+ if (trimmed.startsWith('#'))
713
+ continue;
714
+ if (trimmed.startsWith(trailerPrefix))
715
+ continue;
716
+ return true;
717
+ }
718
+ return false;
719
+ }
720
+ /**
721
+ * Remove the Entire-Checkpoint trailer line from a commit message.
722
+ */
723
+ export function stripCheckpointTrailer(message) {
724
+ const trailerPrefix = CheckpointTrailerKey + ':';
725
+ return message
726
+ .split('\n')
727
+ .filter(line => !line.trim().startsWith(trailerPrefix))
728
+ .join('\n');
729
+ }
730
+ //# sourceMappingURL=manual-commit.js.map