docrev 0.8.1 → 0.8.5

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 (306) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/PLAN-tables-and-postprocess.md +850 -0
  3. package/README.md +33 -0
  4. package/bin/rev.js +12 -131
  5. package/bin/rev.ts +145 -0
  6. package/dist/bin/rev.d.ts +9 -0
  7. package/dist/bin/rev.d.ts.map +1 -0
  8. package/dist/bin/rev.js +118 -0
  9. package/dist/bin/rev.js.map +1 -0
  10. package/dist/lib/annotations.d.ts +91 -0
  11. package/dist/lib/annotations.d.ts.map +1 -0
  12. package/dist/lib/annotations.js +554 -0
  13. package/dist/lib/annotations.js.map +1 -0
  14. package/dist/lib/build.d.ts +171 -0
  15. package/dist/lib/build.d.ts.map +1 -0
  16. package/dist/lib/build.js +755 -0
  17. package/dist/lib/build.js.map +1 -0
  18. package/dist/lib/citations.d.ts +34 -0
  19. package/dist/lib/citations.d.ts.map +1 -0
  20. package/dist/lib/citations.js +140 -0
  21. package/dist/lib/citations.js.map +1 -0
  22. package/dist/lib/commands/build.d.ts +13 -0
  23. package/dist/lib/commands/build.d.ts.map +1 -0
  24. package/dist/lib/commands/build.js +678 -0
  25. package/dist/lib/commands/build.js.map +1 -0
  26. package/dist/lib/commands/citations.d.ts +11 -0
  27. package/dist/lib/commands/citations.d.ts.map +1 -0
  28. package/dist/lib/commands/citations.js +428 -0
  29. package/dist/lib/commands/citations.js.map +1 -0
  30. package/dist/lib/commands/comments.d.ts +11 -0
  31. package/dist/lib/commands/comments.d.ts.map +1 -0
  32. package/dist/lib/commands/comments.js +883 -0
  33. package/dist/lib/commands/comments.js.map +1 -0
  34. package/dist/lib/commands/context.d.ts +35 -0
  35. package/dist/lib/commands/context.d.ts.map +1 -0
  36. package/dist/lib/commands/context.js +59 -0
  37. package/dist/lib/commands/context.js.map +1 -0
  38. package/dist/lib/commands/core.d.ts +11 -0
  39. package/dist/lib/commands/core.d.ts.map +1 -0
  40. package/dist/lib/commands/core.js +246 -0
  41. package/dist/lib/commands/core.js.map +1 -0
  42. package/dist/lib/commands/doi.d.ts +11 -0
  43. package/dist/lib/commands/doi.d.ts.map +1 -0
  44. package/dist/lib/commands/doi.js +373 -0
  45. package/dist/lib/commands/doi.js.map +1 -0
  46. package/dist/lib/commands/history.d.ts +11 -0
  47. package/dist/lib/commands/history.d.ts.map +1 -0
  48. package/dist/lib/commands/history.js +245 -0
  49. package/dist/lib/commands/history.js.map +1 -0
  50. package/dist/lib/commands/index.d.ts +28 -0
  51. package/dist/lib/commands/index.d.ts.map +1 -0
  52. package/dist/lib/commands/index.js +35 -0
  53. package/dist/lib/commands/index.js.map +1 -0
  54. package/dist/lib/commands/init.d.ts +11 -0
  55. package/dist/lib/commands/init.d.ts.map +1 -0
  56. package/dist/lib/commands/init.js +209 -0
  57. package/dist/lib/commands/init.js.map +1 -0
  58. package/dist/lib/commands/response.d.ts +11 -0
  59. package/dist/lib/commands/response.d.ts.map +1 -0
  60. package/dist/lib/commands/response.js +317 -0
  61. package/dist/lib/commands/response.js.map +1 -0
  62. package/dist/lib/commands/sections.d.ts +11 -0
  63. package/dist/lib/commands/sections.d.ts.map +1 -0
  64. package/dist/lib/commands/sections.js +1071 -0
  65. package/dist/lib/commands/sections.js.map +1 -0
  66. package/dist/lib/commands/utilities.d.ts +19 -0
  67. package/dist/lib/commands/utilities.d.ts.map +1 -0
  68. package/dist/lib/commands/utilities.js +2009 -0
  69. package/dist/lib/commands/utilities.js.map +1 -0
  70. package/dist/lib/comment-realign.d.ts +50 -0
  71. package/dist/lib/comment-realign.d.ts.map +1 -0
  72. package/dist/lib/comment-realign.js +372 -0
  73. package/dist/lib/comment-realign.js.map +1 -0
  74. package/dist/lib/config.d.ts +41 -0
  75. package/dist/lib/config.d.ts.map +1 -0
  76. package/dist/lib/config.js +76 -0
  77. package/dist/lib/config.js.map +1 -0
  78. package/dist/lib/crossref.d.ts +108 -0
  79. package/dist/lib/crossref.d.ts.map +1 -0
  80. package/dist/lib/crossref.js +597 -0
  81. package/dist/lib/crossref.js.map +1 -0
  82. package/dist/lib/dependencies.d.ts +30 -0
  83. package/dist/lib/dependencies.d.ts.map +1 -0
  84. package/dist/lib/dependencies.js +95 -0
  85. package/dist/lib/dependencies.js.map +1 -0
  86. package/dist/lib/doi-cache.d.ts +29 -0
  87. package/dist/lib/doi-cache.d.ts.map +1 -0
  88. package/dist/lib/doi-cache.js +104 -0
  89. package/dist/lib/doi-cache.js.map +1 -0
  90. package/dist/lib/doi.d.ts +65 -0
  91. package/dist/lib/doi.d.ts.map +1 -0
  92. package/dist/lib/doi.js +710 -0
  93. package/dist/lib/doi.js.map +1 -0
  94. package/dist/lib/equations.d.ts +61 -0
  95. package/dist/lib/equations.d.ts.map +1 -0
  96. package/dist/lib/equations.js +445 -0
  97. package/dist/lib/equations.js.map +1 -0
  98. package/dist/lib/errors.d.ts +60 -0
  99. package/dist/lib/errors.d.ts.map +1 -0
  100. package/dist/lib/errors.js +303 -0
  101. package/dist/lib/errors.js.map +1 -0
  102. package/dist/lib/format.d.ts +104 -0
  103. package/dist/lib/format.d.ts.map +1 -0
  104. package/dist/lib/format.js +416 -0
  105. package/dist/lib/format.js.map +1 -0
  106. package/dist/lib/git.d.ts +88 -0
  107. package/dist/lib/git.d.ts.map +1 -0
  108. package/dist/lib/git.js +304 -0
  109. package/dist/lib/git.js.map +1 -0
  110. package/dist/lib/grammar.d.ts +62 -0
  111. package/dist/lib/grammar.d.ts.map +1 -0
  112. package/dist/lib/grammar.js +244 -0
  113. package/dist/lib/grammar.js.map +1 -0
  114. package/dist/lib/image-registry.d.ts +68 -0
  115. package/dist/lib/image-registry.d.ts.map +1 -0
  116. package/dist/lib/image-registry.js +112 -0
  117. package/dist/lib/image-registry.js.map +1 -0
  118. package/dist/lib/import.d.ts +184 -0
  119. package/dist/lib/import.d.ts.map +1 -0
  120. package/dist/lib/import.js +1581 -0
  121. package/dist/lib/import.js.map +1 -0
  122. package/dist/lib/journals.d.ts +55 -0
  123. package/dist/lib/journals.d.ts.map +1 -0
  124. package/dist/lib/journals.js +417 -0
  125. package/dist/lib/journals.js.map +1 -0
  126. package/dist/lib/merge.d.ts +138 -0
  127. package/dist/lib/merge.d.ts.map +1 -0
  128. package/dist/lib/merge.js +603 -0
  129. package/dist/lib/merge.js.map +1 -0
  130. package/dist/lib/orcid.d.ts +36 -0
  131. package/dist/lib/orcid.d.ts.map +1 -0
  132. package/dist/lib/orcid.js +117 -0
  133. package/dist/lib/orcid.js.map +1 -0
  134. package/dist/lib/pdf-comments.d.ts +95 -0
  135. package/dist/lib/pdf-comments.d.ts.map +1 -0
  136. package/dist/lib/pdf-comments.js +192 -0
  137. package/dist/lib/pdf-comments.js.map +1 -0
  138. package/dist/lib/pdf-import.d.ts +118 -0
  139. package/dist/lib/pdf-import.d.ts.map +1 -0
  140. package/dist/lib/pdf-import.js +397 -0
  141. package/dist/lib/pdf-import.js.map +1 -0
  142. package/dist/lib/plugins.d.ts +76 -0
  143. package/dist/lib/plugins.d.ts.map +1 -0
  144. package/dist/lib/plugins.js +235 -0
  145. package/dist/lib/plugins.js.map +1 -0
  146. package/dist/lib/postprocess.d.ts +42 -0
  147. package/dist/lib/postprocess.d.ts.map +1 -0
  148. package/dist/lib/postprocess.js +138 -0
  149. package/dist/lib/postprocess.js.map +1 -0
  150. package/dist/lib/pptx-template.d.ts +59 -0
  151. package/dist/lib/pptx-template.d.ts.map +1 -0
  152. package/dist/lib/pptx-template.js +613 -0
  153. package/dist/lib/pptx-template.js.map +1 -0
  154. package/dist/lib/pptx-themes.d.ts +80 -0
  155. package/dist/lib/pptx-themes.d.ts.map +1 -0
  156. package/dist/lib/pptx-themes.js +818 -0
  157. package/dist/lib/pptx-themes.js.map +1 -0
  158. package/dist/lib/protect-restore.d.ts +137 -0
  159. package/dist/lib/protect-restore.d.ts.map +1 -0
  160. package/dist/lib/protect-restore.js +394 -0
  161. package/dist/lib/protect-restore.js.map +1 -0
  162. package/dist/lib/rate-limiter.d.ts +27 -0
  163. package/dist/lib/rate-limiter.d.ts.map +1 -0
  164. package/dist/lib/rate-limiter.js +79 -0
  165. package/dist/lib/rate-limiter.js.map +1 -0
  166. package/dist/lib/response.d.ts +41 -0
  167. package/dist/lib/response.d.ts.map +1 -0
  168. package/dist/lib/response.js +150 -0
  169. package/dist/lib/response.js.map +1 -0
  170. package/dist/lib/review.d.ts +35 -0
  171. package/dist/lib/review.d.ts.map +1 -0
  172. package/dist/lib/review.js +263 -0
  173. package/dist/lib/review.js.map +1 -0
  174. package/dist/lib/schema.d.ts +66 -0
  175. package/dist/lib/schema.d.ts.map +1 -0
  176. package/dist/lib/schema.js +339 -0
  177. package/dist/lib/schema.js.map +1 -0
  178. package/dist/lib/scientific-words.d.ts +6 -0
  179. package/dist/lib/scientific-words.d.ts.map +1 -0
  180. package/dist/lib/scientific-words.js +66 -0
  181. package/dist/lib/scientific-words.js.map +1 -0
  182. package/dist/lib/sections.d.ts +40 -0
  183. package/dist/lib/sections.d.ts.map +1 -0
  184. package/dist/lib/sections.js +288 -0
  185. package/dist/lib/sections.js.map +1 -0
  186. package/dist/lib/slides.d.ts +86 -0
  187. package/dist/lib/slides.d.ts.map +1 -0
  188. package/dist/lib/slides.js +676 -0
  189. package/dist/lib/slides.js.map +1 -0
  190. package/dist/lib/spelling.d.ts +76 -0
  191. package/dist/lib/spelling.d.ts.map +1 -0
  192. package/dist/lib/spelling.js +272 -0
  193. package/dist/lib/spelling.js.map +1 -0
  194. package/dist/lib/templates.d.ts +30 -0
  195. package/dist/lib/templates.d.ts.map +1 -0
  196. package/dist/lib/templates.js +504 -0
  197. package/dist/lib/templates.js.map +1 -0
  198. package/dist/lib/themes.d.ts +85 -0
  199. package/dist/lib/themes.d.ts.map +1 -0
  200. package/dist/lib/themes.js +652 -0
  201. package/dist/lib/themes.js.map +1 -0
  202. package/dist/lib/trackchanges.d.ts +51 -0
  203. package/dist/lib/trackchanges.d.ts.map +1 -0
  204. package/dist/lib/trackchanges.js +202 -0
  205. package/dist/lib/trackchanges.js.map +1 -0
  206. package/dist/lib/tui.d.ts +76 -0
  207. package/dist/lib/tui.d.ts.map +1 -0
  208. package/dist/lib/tui.js +377 -0
  209. package/dist/lib/tui.js.map +1 -0
  210. package/dist/lib/types.d.ts +447 -0
  211. package/dist/lib/types.d.ts.map +1 -0
  212. package/dist/lib/types.js +6 -0
  213. package/dist/lib/types.js.map +1 -0
  214. package/dist/lib/undo.d.ts +57 -0
  215. package/dist/lib/undo.d.ts.map +1 -0
  216. package/dist/lib/undo.js +185 -0
  217. package/dist/lib/undo.js.map +1 -0
  218. package/dist/lib/utils.d.ts +16 -0
  219. package/dist/lib/utils.d.ts.map +1 -0
  220. package/dist/lib/utils.js +40 -0
  221. package/dist/lib/utils.js.map +1 -0
  222. package/dist/lib/variables.d.ts +42 -0
  223. package/dist/lib/variables.d.ts.map +1 -0
  224. package/dist/lib/variables.js +141 -0
  225. package/dist/lib/variables.js.map +1 -0
  226. package/dist/lib/word.d.ts +80 -0
  227. package/dist/lib/word.d.ts.map +1 -0
  228. package/dist/lib/word.js +360 -0
  229. package/dist/lib/word.js.map +1 -0
  230. package/dist/lib/wordcomments.d.ts +51 -0
  231. package/dist/lib/wordcomments.d.ts.map +1 -0
  232. package/dist/lib/wordcomments.js +587 -0
  233. package/dist/lib/wordcomments.js.map +1 -0
  234. package/eslint.config.js +27 -0
  235. package/lib/annotations.ts +622 -0
  236. package/lib/apply-buildup-colors.py +88 -0
  237. package/lib/build.ts +1013 -0
  238. package/lib/{citations.js → citations.ts} +38 -27
  239. package/lib/commands/{build.js → build.ts} +80 -27
  240. package/lib/commands/{citations.js → citations.ts} +36 -18
  241. package/lib/commands/{comments.js → comments.ts} +187 -54
  242. package/lib/commands/{context.js → context.ts} +18 -8
  243. package/lib/commands/{core.js → core.ts} +34 -20
  244. package/lib/commands/{doi.js → doi.ts} +32 -16
  245. package/lib/commands/{history.js → history.ts} +25 -12
  246. package/lib/commands/{index.js → index.ts} +9 -5
  247. package/lib/commands/{init.js → init.ts} +20 -8
  248. package/lib/commands/{response.js → response.ts} +47 -20
  249. package/lib/commands/{sections.js → sections.ts} +273 -68
  250. package/lib/commands/{utilities.js → utilities.ts} +338 -158
  251. package/lib/{comment-realign.js → comment-realign.ts} +117 -45
  252. package/lib/config.ts +84 -0
  253. package/lib/{crossref.js → crossref.ts} +213 -138
  254. package/lib/dependencies.ts +106 -0
  255. package/lib/doi-cache.ts +115 -0
  256. package/lib/{doi.js → doi.ts} +115 -281
  257. package/lib/{equations.js → equations.ts} +60 -64
  258. package/lib/{errors.js → errors.ts} +56 -48
  259. package/lib/{format.js → format.ts} +137 -63
  260. package/lib/{git.js → git.ts} +66 -63
  261. package/lib/{grammar.js → grammar.ts} +45 -32
  262. package/lib/image-registry.ts +180 -0
  263. package/lib/import.ts +2060 -0
  264. package/lib/journals.ts +505 -0
  265. package/lib/{merge.js → merge.ts} +185 -135
  266. package/lib/{orcid.js → orcid.ts} +17 -22
  267. package/lib/{pdf-comments.js → pdf-comments.ts} +76 -18
  268. package/lib/{pdf-import.js → pdf-import.ts} +148 -70
  269. package/lib/{plugins.js → plugins.ts} +82 -39
  270. package/lib/postprocess.ts +188 -0
  271. package/lib/pptx-color-filter.lua +37 -0
  272. package/lib/pptx-template.ts +625 -0
  273. package/lib/pptx-themes/academic.pptx +0 -0
  274. package/lib/pptx-themes/corporate.pptx +0 -0
  275. package/lib/pptx-themes/dark.pptx +0 -0
  276. package/lib/pptx-themes/default.pptx +0 -0
  277. package/lib/pptx-themes/minimal.pptx +0 -0
  278. package/lib/pptx-themes/plant.pptx +0 -0
  279. package/lib/pptx-themes.ts +896 -0
  280. package/lib/protect-restore.ts +516 -0
  281. package/lib/rate-limiter.ts +94 -0
  282. package/lib/{response.js → response.ts} +36 -21
  283. package/lib/{review.js → review.ts} +53 -43
  284. package/lib/{schema.js → schema.ts} +70 -25
  285. package/lib/{sections.js → sections.ts} +71 -76
  286. package/lib/slides.ts +793 -0
  287. package/lib/{spelling.js → spelling.ts} +43 -59
  288. package/lib/{templates.js → templates.ts} +20 -17
  289. package/lib/themes.ts +742 -0
  290. package/lib/{trackchanges.js → trackchanges.ts} +52 -23
  291. package/lib/types.ts +509 -0
  292. package/lib/{undo.js → undo.ts} +75 -52
  293. package/lib/utils.ts +41 -0
  294. package/lib/{variables.js → variables.ts} +60 -54
  295. package/lib/word.ts +428 -0
  296. package/lib/{wordcomments.js → wordcomments.ts} +94 -40
  297. package/package.json +15 -5
  298. package/skill/REFERENCE.md +67 -0
  299. package/tsconfig.json +26 -0
  300. package/lib/annotations.js +0 -414
  301. package/lib/build.js +0 -639
  302. package/lib/config.js +0 -79
  303. package/lib/import.js +0 -1145
  304. package/lib/journals.js +0 -629
  305. package/lib/word.js +0 -225
  306. /package/lib/{scientific-words.js → scientific-words.ts} +0 -0
@@ -0,0 +1,883 @@
1
+ /**
2
+ * Comment commands: comments, resolve, next, prev, first, last, todo, accept, reject, reply
3
+ *
4
+ * Commands for viewing, navigating, and managing reviewer comments and track changes.
5
+ */
6
+ import { chalk, fs, path, fmt, findFiles, getComments, setCommentStatus, getTrackChanges, applyDecision, cleanupOrphanedMarkers, interactiveCommentReview,
7
+ // tuiCommentReview, // TUI module not yet migrated
8
+ getUserName, exitWithError, getAnnotationSuggestions, requireFile, } from './context.js';
9
+ /**
10
+ * Add a reply after a comment
11
+ * @param text - Full document text
12
+ * @param comment - Comment object with position and match
13
+ * @param author - Reply author name
14
+ * @param message - Reply message
15
+ * @returns Updated text
16
+ */
17
+ function addReply(text, comment, author, message) {
18
+ const replyAnnotation = `{>>${author}: ${message}<<}`;
19
+ const insertPos = comment.position + comment.match.length;
20
+ return text.slice(0, insertPos) + ' ' + replyAnnotation + text.slice(insertPos);
21
+ }
22
+ /**
23
+ * Helper to find section file by name (deterministic priority)
24
+ */
25
+ function findSectionFile(section) {
26
+ const allMd = findFiles('.md');
27
+ const sectionLower = section.toLowerCase();
28
+ // 1. Exact filename match
29
+ const exactFile = allMd.find(f => f === section || f === `${section}.md`);
30
+ if (exactFile)
31
+ return [exactFile];
32
+ // 2. Filename contains (partial match)
33
+ const filenameMatch = allMd.filter(f => f.toLowerCase().replace(/\.md$/, '').includes(sectionLower));
34
+ if (filenameMatch.length === 1)
35
+ return filenameMatch;
36
+ if (filenameMatch.length > 1) {
37
+ console.log(chalk.yellow(` Multiple files match "${section}": ${filenameMatch.join(', ')}`));
38
+ console.log(chalk.dim(` Using first match: ${filenameMatch[0]}`));
39
+ return [filenameMatch[0]];
40
+ }
41
+ // 3. Exact header match
42
+ for (const f of allMd) {
43
+ try {
44
+ const text = fs.readFileSync(f, 'utf-8');
45
+ const headerMatch = text.match(/^#\s+(.+)$/m);
46
+ if (headerMatch && headerMatch[1].toLowerCase().trim() === sectionLower) {
47
+ return [f];
48
+ }
49
+ }
50
+ catch {
51
+ // Skip unreadable files silently - not critical for section matching
52
+ }
53
+ }
54
+ // 4. Header contains (partial match)
55
+ const headerMatches = [];
56
+ for (const f of allMd) {
57
+ try {
58
+ const text = fs.readFileSync(f, 'utf-8');
59
+ const headerMatch = text.match(/^#\s+(.+)$/m);
60
+ if (headerMatch && headerMatch[1].toLowerCase().includes(sectionLower)) {
61
+ headerMatches.push(f);
62
+ }
63
+ }
64
+ catch {
65
+ // Skip unreadable files silently - not critical for section matching
66
+ }
67
+ }
68
+ if (headerMatches.length === 1)
69
+ return headerMatches;
70
+ if (headerMatches.length > 1) {
71
+ console.log(chalk.yellow(` Multiple files match "${section}": ${headerMatches.join(', ')}`));
72
+ console.log(chalk.dim(` Using first match: ${headerMatches[0]}`));
73
+ return [headerMatches[0]];
74
+ }
75
+ // No match - return original (will fail later with file not found)
76
+ return [section];
77
+ }
78
+ /**
79
+ * Register comment commands with the program
80
+ */
81
+ export function register(program) {
82
+ // ==========================================================================
83
+ // COMMENTS command - List all comments
84
+ // ==========================================================================
85
+ program
86
+ .command('comments')
87
+ .alias('c')
88
+ .description('List all comments in the document')
89
+ .argument('<file>', 'Markdown file')
90
+ .option('-p, --pending', 'Show only pending (unresolved) comments')
91
+ .option('-r, --resolved', 'Show only resolved comments')
92
+ .option('-a, --author <name>', 'Filter by author name (case-insensitive)')
93
+ .option('-e, --export <csvFile>', 'Export comments to CSV file')
94
+ .option('-i, --interactive', 'Interactive review mode (reply, resolve, skip)')
95
+ .option('-t, --tui', 'Visual TUI mode for comment review')
96
+ .action(async (file, options) => {
97
+ requireFile(file, 'Markdown file');
98
+ const text = fs.readFileSync(file, 'utf-8');
99
+ // TUI review mode
100
+ if (options.tui) {
101
+ console.error(chalk.yellow('TUI mode is temporarily unavailable (module migration in progress)'));
102
+ console.error(chalk.dim('Use --interactive mode instead: rev comments --interactive ' + file));
103
+ process.exit(1);
104
+ // TODO: Re-enable when tui.ts is migrated
105
+ // let author = options.author || getUserName();
106
+ // if (!author) {
107
+ // exitWithError('No user name set for replies', getAnnotationSuggestions('no_author'));
108
+ // }
109
+ //
110
+ // const result = await tuiCommentReview(text, {
111
+ // author,
112
+ // addReply: (txt: string, comment: Comment, auth: string, msg: string) => {
113
+ // const replyAnnotation = `{>>${auth}: ${msg}<<}`;
114
+ // const insertPos = comment.position + comment.match.length;
115
+ // return txt.slice(0, insertPos) + ' ' + replyAnnotation + txt.slice(insertPos);
116
+ // },
117
+ // setStatus: setCommentStatus,
118
+ // });
119
+ //
120
+ // if (result.resolved > 0 || result.replied > 0) {
121
+ // fs.writeFileSync(file, result.text, 'utf-8');
122
+ // console.log(fmt.status('success', `Changes saved to ${file}`));
123
+ // }
124
+ // return;
125
+ }
126
+ // Interactive review mode
127
+ if (options.interactive) {
128
+ let author = options.author || getUserName();
129
+ if (!author) {
130
+ exitWithError('No user name set for replies', getAnnotationSuggestions('no_author'));
131
+ }
132
+ const result = await interactiveCommentReview(text, {
133
+ author,
134
+ addReply: (txt, comment, auth, msg) => {
135
+ const replyAnnotation = `{>>${auth}: ${msg}<<}`;
136
+ const insertPos = comment.position + comment.match.length;
137
+ return txt.slice(0, insertPos) + ' ' + replyAnnotation + txt.slice(insertPos);
138
+ },
139
+ setCommentStatus,
140
+ });
141
+ if (result.resolved > 0 || result.replied > 0) {
142
+ fs.writeFileSync(file, result.text, 'utf-8');
143
+ console.log(fmt.status('success', `Changes saved to ${file}`));
144
+ }
145
+ return;
146
+ }
147
+ let comments = getComments(text, {
148
+ pendingOnly: options.pending,
149
+ resolvedOnly: options.resolved,
150
+ });
151
+ // Filter by author if specified
152
+ if (options.author) {
153
+ const authorFilter = options.author.toLowerCase();
154
+ comments = comments.filter(c => c.author && c.author.toLowerCase().includes(authorFilter));
155
+ }
156
+ // CSV export mode
157
+ if (options.export) {
158
+ const csvEscape = (str) => {
159
+ if (!str)
160
+ return '';
161
+ str = String(str);
162
+ if (str.includes(',') || str.includes('"') || str.includes('\n')) {
163
+ return '"' + str.replace(/"/g, '""') + '"';
164
+ }
165
+ return str;
166
+ };
167
+ const header = ['number', 'author', 'comment', 'context', 'status', 'file', 'line'];
168
+ const rows = comments.map((c, i) => [
169
+ i + 1,
170
+ csvEscape(c.author || ''),
171
+ csvEscape(c.content),
172
+ csvEscape(c.before ? c.before.trim() : ''),
173
+ c.resolved ? 'resolved' : 'pending',
174
+ path.basename(file),
175
+ c.line,
176
+ ].join(','));
177
+ const csv = [header.join(','), ...rows].join('\n');
178
+ fs.writeFileSync(options.export, csv, 'utf-8');
179
+ console.log(fmt.status('success', `Exported ${comments.length} comments to ${options.export}`));
180
+ return;
181
+ }
182
+ if (comments.length === 0) {
183
+ if (options.pending) {
184
+ console.log(fmt.status('success', 'No pending comments'));
185
+ }
186
+ else if (options.resolved) {
187
+ console.log(fmt.status('info', 'No resolved comments'));
188
+ }
189
+ else {
190
+ console.log(fmt.status('info', 'No comments found'));
191
+ }
192
+ return;
193
+ }
194
+ let filter = options.pending ? ' (pending)' : options.resolved ? ' (resolved)' : '';
195
+ if (options.author)
196
+ filter += ` by "${options.author}"`;
197
+ console.log(fmt.header(`Comments in ${path.basename(file)}${filter}`));
198
+ console.log();
199
+ for (let i = 0; i < comments.length; i++) {
200
+ const c = comments[i];
201
+ const statusIcon = c.resolved ? chalk.green('✓') : chalk.yellow('○');
202
+ const authorLabel = c.author ? chalk.blue(`[${c.author}]`) : chalk.dim('[Anonymous]');
203
+ const preview = c.content.length > 60 ? c.content.slice(0, 60) + '...' : c.content;
204
+ console.log(` ${chalk.bold(`#${i + 1}`)} ${statusIcon} ${authorLabel} ${chalk.dim(`L${c.line}`)}`);
205
+ console.log(` ${preview}`);
206
+ if (c.before) {
207
+ console.log(chalk.dim(` "${c.before.trim().slice(-40)}..."`));
208
+ }
209
+ console.log();
210
+ }
211
+ // Summary
212
+ const allComments = getComments(text);
213
+ const pending = allComments.filter((c) => !c.resolved).length;
214
+ const resolved = allComments.filter((c) => c.resolved).length;
215
+ console.log(chalk.dim(` Total: ${allComments.length} | Pending: ${pending} | Resolved: ${resolved}`));
216
+ });
217
+ // ==========================================================================
218
+ // RESOLVE command - Mark comments as resolved/pending
219
+ // ==========================================================================
220
+ program
221
+ .command('resolve')
222
+ .alias('r')
223
+ .description('Mark comments as resolved or pending')
224
+ .argument('<file>', 'Markdown file')
225
+ .option('-n, --number <n>', 'Comment number to toggle', parseInt)
226
+ .option('-a, --all', 'Mark all comments as resolved')
227
+ .option('-u, --unresolve', 'Mark as pending (unresolve)')
228
+ .option('--dry-run', 'Preview without saving')
229
+ .action((file, options) => {
230
+ requireFile(file, 'Markdown file');
231
+ let text = fs.readFileSync(file, 'utf-8');
232
+ const comments = getComments(text);
233
+ if (comments.length === 0) {
234
+ console.log(fmt.status('info', 'No comments found'));
235
+ console.log(chalk.dim(getAnnotationSuggestions('no_comments').join('\n ')));
236
+ return;
237
+ }
238
+ const resolveStatus = !options.unresolve;
239
+ if (options.all) {
240
+ // Mark all comments
241
+ let count = 0;
242
+ for (const comment of comments) {
243
+ if (comment.resolved !== resolveStatus) {
244
+ text = setCommentStatus(text, comment, resolveStatus);
245
+ count++;
246
+ }
247
+ }
248
+ if (options.dryRun) {
249
+ console.log(fmt.status('info', `Would mark ${count} comment(s) as ${resolveStatus ? 'resolved' : 'pending'}`));
250
+ }
251
+ else {
252
+ fs.writeFileSync(file, text, 'utf-8');
253
+ console.log(fmt.status('success', `Marked ${count} comment(s) as ${resolveStatus ? 'resolved' : 'pending'}`));
254
+ }
255
+ return;
256
+ }
257
+ if (options.number !== undefined) {
258
+ const idx = options.number - 1;
259
+ if (idx < 0 || idx >= comments.length) {
260
+ exitWithError(`Invalid comment number ${options.number}. File has ${comments.length} comment(s)`, getAnnotationSuggestions('invalid_number'));
261
+ }
262
+ const comment = comments[idx];
263
+ text = setCommentStatus(text, comment, resolveStatus);
264
+ if (options.dryRun) {
265
+ console.log(fmt.status('info', `Would mark comment #${options.number} as ${resolveStatus ? 'resolved' : 'pending'}`));
266
+ }
267
+ else {
268
+ fs.writeFileSync(file, text, 'utf-8');
269
+ console.log(fmt.status('success', `Comment #${options.number} marked as ${resolveStatus ? 'resolved' : 'pending'}`));
270
+ }
271
+ return;
272
+ }
273
+ // No options: show current status
274
+ console.log(fmt.header(`Comment Status in ${path.basename(file)}`));
275
+ console.log();
276
+ for (let i = 0; i < comments.length; i++) {
277
+ const c = comments[i];
278
+ const statusIcon = c.resolved ? chalk.green('✓') : chalk.yellow('○');
279
+ const preview = c.content.length > 50 ? c.content.slice(0, 50) + '...' : c.content;
280
+ console.log(` ${statusIcon} #${i + 1} ${preview}`);
281
+ }
282
+ console.log();
283
+ const pending = comments.filter((c) => !c.resolved).length;
284
+ const resolved = comments.filter((c) => c.resolved).length;
285
+ console.log(chalk.dim(` Pending: ${pending} | Resolved: ${resolved}`));
286
+ console.log();
287
+ console.log(chalk.dim(' Usage: rev resolve <file> -n <number> Mark specific comment'));
288
+ console.log(chalk.dim(' rev resolve <file> -a Mark all as resolved'));
289
+ console.log(chalk.dim(' rev resolve <file> -n 1 -u Unresolve comment #1'));
290
+ });
291
+ // ==========================================================================
292
+ // NEXT command - Show next pending comment
293
+ // ==========================================================================
294
+ program
295
+ .command('next')
296
+ .alias('n')
297
+ .description('Show next pending comment')
298
+ .argument('[file]', 'Specific file (default: all markdown files)')
299
+ .option('-n, --number <n>', 'Skip to nth pending comment', parseInt)
300
+ .action((file, options) => {
301
+ const files = file ? [file] : findFiles('.md');
302
+ if (files.length === 0) {
303
+ console.log(fmt.status('info', 'No markdown files found.'));
304
+ return;
305
+ }
306
+ // Collect all pending comments across files
307
+ const allPending = [];
308
+ for (const f of files) {
309
+ if (!fs.existsSync(f))
310
+ continue;
311
+ const text = fs.readFileSync(f, 'utf-8');
312
+ const allComments = getComments(text);
313
+ const pending = getComments(text, { pendingOnly: true });
314
+ for (const c of pending) {
315
+ const idx = allComments.findIndex(x => x.position === c.position) + 1;
316
+ allPending.push({ ...c, file: f, number: idx });
317
+ }
318
+ }
319
+ if (allPending.length === 0) {
320
+ console.log(fmt.status('success', 'No pending comments!'));
321
+ return;
322
+ }
323
+ // Get the nth pending comment (default: 1st)
324
+ const targetIdx = (options.number || 1) - 1;
325
+ if (targetIdx < 0 || targetIdx >= allPending.length) {
326
+ console.error(chalk.red(`Invalid number. Only ${allPending.length} pending comment(s).`));
327
+ process.exit(1);
328
+ }
329
+ const c = allPending[targetIdx];
330
+ const position = targetIdx + 1;
331
+ console.log(fmt.header(`Comment ${position}/${allPending.length}`));
332
+ console.log();
333
+ console.log(` ${chalk.cyan(c.file)}:${c.line} ${chalk.dim(`#${c.number}`)}`);
334
+ console.log();
335
+ if (c.author)
336
+ console.log(` ${chalk.blue(c.author)}`);
337
+ console.log(` ${c.content}`);
338
+ if (c.before) {
339
+ console.log();
340
+ console.log(chalk.dim(` Context: "${c.before.trim().slice(-60)}"`));
341
+ }
342
+ console.log();
343
+ console.log(chalk.dim(` rev reply ${c.file} -n ${c.number} -m "..."`));
344
+ console.log(chalk.dim(` rev resolve ${c.file} -n ${c.number}`));
345
+ if (position < allPending.length) {
346
+ console.log(chalk.dim(` rev next -n ${position + 1}`));
347
+ }
348
+ });
349
+ // ==========================================================================
350
+ // PREV command - Show previous/last pending comment
351
+ // ==========================================================================
352
+ program
353
+ .command('prev')
354
+ .alias('p')
355
+ .description('Show previous pending comment')
356
+ .argument('[file]', 'Specific file (default: all markdown files)')
357
+ .option('-n, --number <n>', 'Skip to nth pending comment from end', parseInt)
358
+ .action((file, options) => {
359
+ const files = file ? [file] : findFiles('.md');
360
+ if (files.length === 0) {
361
+ console.log(fmt.status('info', 'No markdown files found.'));
362
+ return;
363
+ }
364
+ // Collect all pending comments across files
365
+ const allPending = [];
366
+ for (const f of files) {
367
+ if (!fs.existsSync(f))
368
+ continue;
369
+ const text = fs.readFileSync(f, 'utf-8');
370
+ const allComments = getComments(text);
371
+ const pending = getComments(text, { pendingOnly: true });
372
+ for (const c of pending) {
373
+ const idx = allComments.findIndex(x => x.position === c.position) + 1;
374
+ allPending.push({ ...c, file: f, number: idx });
375
+ }
376
+ }
377
+ if (allPending.length === 0) {
378
+ console.log(fmt.status('success', 'No pending comments!'));
379
+ return;
380
+ }
381
+ // Get the nth pending comment from end (default: last)
382
+ const fromEnd = options.number || 1;
383
+ const targetIdx = allPending.length - fromEnd;
384
+ if (targetIdx < 0 || targetIdx >= allPending.length) {
385
+ console.error(chalk.red(`Invalid number. Only ${allPending.length} pending comment(s).`));
386
+ process.exit(1);
387
+ }
388
+ const c = allPending[targetIdx];
389
+ const position = targetIdx + 1;
390
+ console.log(fmt.header(`Comment ${position}/${allPending.length}`));
391
+ console.log();
392
+ console.log(` ${chalk.cyan(c.file)}:${c.line} ${chalk.dim(`#${c.number}`)}`);
393
+ console.log();
394
+ if (c.author)
395
+ console.log(` ${chalk.blue(c.author)}`);
396
+ console.log(` ${c.content}`);
397
+ if (c.before) {
398
+ console.log();
399
+ console.log(chalk.dim(` Context: "${c.before.trim().slice(-60)}"`));
400
+ }
401
+ console.log();
402
+ console.log(chalk.dim(` rev reply ${c.file} -n ${c.number} -m "..."`));
403
+ console.log(chalk.dim(` rev resolve ${c.file} -n ${c.number}`));
404
+ if (position > 1) {
405
+ console.log(chalk.dim(` rev next -n ${position - 1}`));
406
+ }
407
+ if (position < allPending.length) {
408
+ console.log(chalk.dim(` rev next -n ${position + 1}`));
409
+ }
410
+ });
411
+ // ==========================================================================
412
+ // FIRST command - Show first comment
413
+ // ==========================================================================
414
+ program
415
+ .command('first')
416
+ .description('Show first comment')
417
+ .argument('[section]', 'Specific file or section name (default: all markdown files)')
418
+ .action((section) => {
419
+ const files = section ? findSectionFile(section) : findFiles('.md');
420
+ if (files.length === 0) {
421
+ console.log(fmt.status('info', 'No markdown files found.'));
422
+ return;
423
+ }
424
+ // Find first comment across files
425
+ for (const f of files) {
426
+ if (!fs.existsSync(f))
427
+ continue;
428
+ const text = fs.readFileSync(f, 'utf-8');
429
+ const comments = getComments(text);
430
+ if (comments.length > 0) {
431
+ const c = comments[0];
432
+ const statusIcon = c.resolved ? chalk.green('✓') : chalk.yellow('○');
433
+ console.log(fmt.header(`Comment 1/${comments.length}`));
434
+ console.log();
435
+ console.log(` ${chalk.cyan(f)}:${c.line} #1 ${statusIcon}`);
436
+ console.log();
437
+ if (c.author)
438
+ console.log(` ${chalk.blue(c.author)}`);
439
+ console.log(` ${c.content}`);
440
+ if (c.before) {
441
+ console.log();
442
+ console.log(chalk.dim(` Context: "${c.before.trim().slice(-60)}"`));
443
+ }
444
+ console.log();
445
+ console.log(chalk.dim(` rev reply ${f} -n 1 -m "..."`));
446
+ console.log(chalk.dim(` rev resolve ${f} -n 1`));
447
+ return;
448
+ }
449
+ }
450
+ console.log(fmt.status('info', 'No comments found.'));
451
+ });
452
+ // ==========================================================================
453
+ // LAST command - Show last comment
454
+ // ==========================================================================
455
+ program
456
+ .command('last')
457
+ .description('Show last comment')
458
+ .argument('[section]', 'Specific file or section name (default: all markdown files)')
459
+ .action((section) => {
460
+ const files = section ? findSectionFile(section) : findFiles('.md').reverse();
461
+ if (files.length === 0) {
462
+ console.log(fmt.status('info', 'No markdown files found.'));
463
+ return;
464
+ }
465
+ // Find last comment across files (reverse order)
466
+ for (const f of files) {
467
+ if (!fs.existsSync(f))
468
+ continue;
469
+ const text = fs.readFileSync(f, 'utf-8');
470
+ const comments = getComments(text);
471
+ if (comments.length > 0) {
472
+ const c = comments[comments.length - 1];
473
+ const idx = comments.length;
474
+ const statusIcon = c.resolved ? chalk.green('✓') : chalk.yellow('○');
475
+ console.log(fmt.header(`Comment ${idx}/${comments.length}`));
476
+ console.log();
477
+ console.log(` ${chalk.cyan(f)}:${c.line} #${idx} ${statusIcon}`);
478
+ console.log();
479
+ if (c.author)
480
+ console.log(` ${chalk.blue(c.author)}`);
481
+ console.log(` ${c.content}`);
482
+ if (c.before) {
483
+ console.log();
484
+ console.log(chalk.dim(` Context: "${c.before.trim().slice(-60)}"`));
485
+ }
486
+ console.log();
487
+ console.log(chalk.dim(` rev reply ${f} -n ${idx} -m "..."`));
488
+ console.log(chalk.dim(` rev resolve ${f} -n ${idx}`));
489
+ return;
490
+ }
491
+ }
492
+ console.log(fmt.status('info', 'No comments found.'));
493
+ });
494
+ // ==========================================================================
495
+ // TODO command - List pending comments as checklist
496
+ // ==========================================================================
497
+ program
498
+ .command('todo')
499
+ .alias('t')
500
+ .description('List all pending comments as a checklist')
501
+ .argument('[file]', 'Specific file (default: all markdown files)')
502
+ .option('--by-author', 'Group by author')
503
+ .action((file, options) => {
504
+ const files = file ? [file] : findFiles('.md');
505
+ if (files.length === 0) {
506
+ console.log(fmt.status('info', 'No markdown files found.'));
507
+ return;
508
+ }
509
+ // Collect all pending comments
510
+ const todos = [];
511
+ for (const f of files) {
512
+ if (!fs.existsSync(f))
513
+ continue;
514
+ const text = fs.readFileSync(f, 'utf-8');
515
+ const allComments = getComments(text);
516
+ const pending = allComments.filter(c => !c.resolved);
517
+ for (const c of pending) {
518
+ const idx = allComments.findIndex(x => x.position === c.position) + 1;
519
+ todos.push({
520
+ file: f,
521
+ number: idx,
522
+ line: c.line,
523
+ author: c.author || 'Anonymous',
524
+ content: c.content,
525
+ });
526
+ }
527
+ }
528
+ if (todos.length === 0) {
529
+ console.log(fmt.status('success', 'No pending comments!'));
530
+ return;
531
+ }
532
+ console.log(fmt.header(`Todo (${todos.length} pending)`));
533
+ console.log();
534
+ if (options.byAuthor) {
535
+ // Group by author
536
+ const byAuthor = {};
537
+ for (const t of todos) {
538
+ if (!byAuthor[t.author])
539
+ byAuthor[t.author] = [];
540
+ byAuthor[t.author].push(t);
541
+ }
542
+ for (const [author, items] of Object.entries(byAuthor)) {
543
+ console.log(` ${chalk.blue(author)} (${items.length})`);
544
+ for (const t of items) {
545
+ const preview = t.content.length > 50 ? t.content.slice(0, 50) + '...' : t.content;
546
+ console.log(` ${chalk.yellow('○')} ${chalk.dim(`${t.file}:${t.line}`)} ${preview}`);
547
+ }
548
+ console.log();
549
+ }
550
+ }
551
+ else {
552
+ // List by file
553
+ let currentFile = null;
554
+ for (const t of todos) {
555
+ if (t.file !== currentFile) {
556
+ if (currentFile)
557
+ console.log();
558
+ console.log(` ${chalk.cyan(t.file)}`);
559
+ currentFile = t.file;
560
+ }
561
+ const preview = t.content.length > 50 ? t.content.slice(0, 50) + '...' : t.content;
562
+ const authorTag = t.author !== 'Anonymous' ? chalk.dim(`[${t.author}] `) : '';
563
+ console.log(` ${chalk.yellow('○')} #${t.number} ${authorTag}${preview}`);
564
+ }
565
+ }
566
+ console.log();
567
+ });
568
+ // ==========================================================================
569
+ // ACCEPT command - Accept track changes
570
+ // ==========================================================================
571
+ program
572
+ .command('accept')
573
+ .alias('a')
574
+ .description('Accept track changes')
575
+ .argument('<file>', 'Markdown file')
576
+ .option('-n, --number <n>', 'Accept specific change by number', parseInt)
577
+ .option('-a, --all', 'Accept all changes')
578
+ .option('--dry-run', 'Preview without saving')
579
+ .action((file, options) => {
580
+ if (!fs.existsSync(file)) {
581
+ console.error(chalk.red(`Error: File not found: ${file}`));
582
+ process.exit(1);
583
+ }
584
+ let text = fs.readFileSync(file, 'utf-8');
585
+ const changes = getTrackChanges(text);
586
+ if (changes.length === 0) {
587
+ console.log(fmt.status('info', 'No track changes found.'));
588
+ return;
589
+ }
590
+ if (options.all) {
591
+ // Accept all changes - process in reverse to preserve positions
592
+ const sorted = [...changes].sort((a, b) => b.position - a.position);
593
+ for (const change of sorted) {
594
+ text = applyDecision(text, change, true);
595
+ }
596
+ // Clean up any orphaned CriticMarkup markers that result from interleaved track changes
597
+ text = cleanupOrphanedMarkers(text);
598
+ if (!options.dryRun) {
599
+ fs.writeFileSync(file, text, 'utf-8');
600
+ console.log(fmt.status('success', `Accepted ${changes.length} change(s)`));
601
+ }
602
+ else {
603
+ console.log(fmt.status('info', `Would accept ${changes.length} change(s)`));
604
+ }
605
+ return;
606
+ }
607
+ if (options.number !== undefined) {
608
+ const idx = options.number - 1;
609
+ if (idx < 0 || idx >= changes.length) {
610
+ console.error(chalk.red(`Invalid change number. File has ${changes.length} changes.`));
611
+ process.exit(1);
612
+ }
613
+ const change = changes[idx];
614
+ text = applyDecision(text, change, true);
615
+ if (!options.dryRun) {
616
+ fs.writeFileSync(file, text, 'utf-8');
617
+ console.log(fmt.status('success', `Accepted change #${options.number}`));
618
+ }
619
+ else {
620
+ console.log(fmt.status('info', `Would accept change #${options.number}`));
621
+ }
622
+ return;
623
+ }
624
+ // No options: show changes
625
+ console.log(fmt.header(`Track Changes in ${path.basename(file)}`));
626
+ console.log();
627
+ for (let i = 0; i < changes.length; i++) {
628
+ const c = changes[i];
629
+ let desc;
630
+ if (c.type === 'insert') {
631
+ desc = chalk.green(`+++ "${c.content.slice(0, 40)}${c.content.length > 40 ? '...' : ''}"`);
632
+ }
633
+ else if (c.type === 'delete') {
634
+ desc = chalk.red(`--- "${c.content.slice(0, 40)}${c.content.length > 40 ? '...' : ''}"`);
635
+ }
636
+ else if (c.type === 'substitute') {
637
+ desc = chalk.yellow(`~~~ "${c.content.slice(0, 20)}" → "${(c.replacement || '').slice(0, 20)}"`);
638
+ }
639
+ else {
640
+ desc = chalk.dim('???');
641
+ }
642
+ console.log(` #${i + 1} ${chalk.dim(`L${c.line}`)} ${desc}`);
643
+ }
644
+ console.log();
645
+ console.log(chalk.dim(` rev accept ${file} -n <number> Accept specific change`));
646
+ console.log(chalk.dim(` rev accept ${file} -a Accept all changes`));
647
+ });
648
+ // ==========================================================================
649
+ // REJECT command - Reject track changes
650
+ // ==========================================================================
651
+ program
652
+ .command('reject')
653
+ .alias('x')
654
+ .description('Reject track changes')
655
+ .argument('<file>', 'Markdown file')
656
+ .option('-n, --number <n>', 'Reject specific change by number', parseInt)
657
+ .option('-a, --all', 'Reject all changes')
658
+ .option('--dry-run', 'Preview without saving')
659
+ .action((file, options) => {
660
+ if (!fs.existsSync(file)) {
661
+ console.error(chalk.red(`Error: File not found: ${file}`));
662
+ process.exit(1);
663
+ }
664
+ let text = fs.readFileSync(file, 'utf-8');
665
+ const changes = getTrackChanges(text);
666
+ if (changes.length === 0) {
667
+ console.log(fmt.status('info', 'No track changes found.'));
668
+ return;
669
+ }
670
+ if (options.all) {
671
+ // Reject all changes - process in reverse to preserve positions
672
+ const sorted = [...changes].sort((a, b) => b.position - a.position);
673
+ for (const change of sorted) {
674
+ text = applyDecision(text, change, false);
675
+ }
676
+ if (!options.dryRun) {
677
+ fs.writeFileSync(file, text, 'utf-8');
678
+ console.log(fmt.status('success', `Rejected ${changes.length} change(s)`));
679
+ }
680
+ else {
681
+ console.log(fmt.status('info', `Would reject ${changes.length} change(s)`));
682
+ }
683
+ return;
684
+ }
685
+ if (options.number !== undefined) {
686
+ const idx = options.number - 1;
687
+ if (idx < 0 || idx >= changes.length) {
688
+ console.error(chalk.red(`Invalid change number. File has ${changes.length} changes.`));
689
+ process.exit(1);
690
+ }
691
+ const change = changes[idx];
692
+ text = applyDecision(text, change, false);
693
+ if (!options.dryRun) {
694
+ fs.writeFileSync(file, text, 'utf-8');
695
+ console.log(fmt.status('success', `Rejected change #${options.number}`));
696
+ }
697
+ else {
698
+ console.log(fmt.status('info', `Would reject change #${options.number}`));
699
+ }
700
+ return;
701
+ }
702
+ // No options: show changes (same as accept)
703
+ console.log(fmt.header(`Track Changes in ${path.basename(file)}`));
704
+ console.log();
705
+ for (let i = 0; i < changes.length; i++) {
706
+ const c = changes[i];
707
+ let desc;
708
+ if (c.type === 'insert') {
709
+ desc = chalk.green(`+++ "${c.content.slice(0, 40)}${c.content.length > 40 ? '...' : ''}"`);
710
+ }
711
+ else if (c.type === 'delete') {
712
+ desc = chalk.red(`--- "${c.content.slice(0, 40)}${c.content.length > 40 ? '...' : ''}"`);
713
+ }
714
+ else if (c.type === 'substitute') {
715
+ desc = chalk.yellow(`~~~ "${c.content.slice(0, 20)}" → "${(c.replacement || '').slice(0, 20)}"`);
716
+ }
717
+ else {
718
+ desc = chalk.dim('???');
719
+ }
720
+ console.log(` #${i + 1} ${chalk.dim(`L${c.line}`)} ${desc}`);
721
+ }
722
+ console.log();
723
+ console.log(chalk.dim(` rev reject ${file} -n <number> Reject specific change`));
724
+ console.log(chalk.dim(` rev reject ${file} -a Reject all changes`));
725
+ });
726
+ // ==========================================================================
727
+ // REPLY command - Reply to comments
728
+ // ==========================================================================
729
+ program
730
+ .command('reply')
731
+ .description('Reply to reviewer comments interactively')
732
+ .argument('<file>', 'Markdown file with comments')
733
+ .option('-m, --message <text>', 'Reply message (non-interactive)')
734
+ .option('-n, --number <n>', 'Reply to specific comment number', parseInt)
735
+ .option('-a, --author <name>', 'Override author name')
736
+ .option('--all', 'Reply to all pending comments with the same message (requires -m)')
737
+ .option('--dry-run', 'Preview without saving')
738
+ .action(async (file, options) => {
739
+ if (!fs.existsSync(file)) {
740
+ console.error(chalk.red(`File not found: ${file}`));
741
+ process.exit(1);
742
+ }
743
+ // Get author name
744
+ let author = options.author || getUserName();
745
+ if (!author) {
746
+ console.error(chalk.yellow('No user name set.'));
747
+ console.error(chalk.dim('Set with: rev config user "Your Name"'));
748
+ console.error(chalk.dim('Or use: rev reply <file> --author "Your Name"'));
749
+ process.exit(1);
750
+ }
751
+ const text = fs.readFileSync(file, 'utf-8');
752
+ const comments = getComments(text, { pendingOnly: true });
753
+ if (comments.length === 0) {
754
+ console.log(chalk.green('No pending comments found in this file.'));
755
+ return;
756
+ }
757
+ // Batch reply mode: reply to all pending comments
758
+ if (options.all) {
759
+ if (!options.message) {
760
+ console.error(chalk.red('Batch reply requires a message (-m "your reply")'));
761
+ console.error(chalk.dim('Example: rev reply file.md --all -m "Addressed"'));
762
+ process.exit(1);
763
+ }
764
+ let result = text;
765
+ let count = 0;
766
+ // Process in reverse order to maintain positions
767
+ const sortedComments = [...comments].sort((a, b) => b.position - a.position);
768
+ for (const comment of sortedComments) {
769
+ result = addReply(result, comment, author, options.message);
770
+ count++;
771
+ }
772
+ if (options.dryRun) {
773
+ console.log(fmt.status('info', `Would add reply to ${count} pending comment(s)`));
774
+ }
775
+ else {
776
+ fs.writeFileSync(file, result, 'utf-8');
777
+ console.log(chalk.green(`Reply added to ${count} pending comment(s)`));
778
+ }
779
+ return;
780
+ }
781
+ // Non-interactive mode: reply to specific comment
782
+ if (options.message && options.number !== undefined) {
783
+ const allComments = getComments(text); // Get all comments for numbering
784
+ const idx = options.number - 1;
785
+ if (idx < 0 || idx >= allComments.length) {
786
+ console.error(chalk.red(`Invalid comment number. File has ${allComments.length} comments.`));
787
+ process.exit(1);
788
+ }
789
+ const result = addReply(text, allComments[idx], author, options.message);
790
+ if (options.dryRun) {
791
+ console.log(fmt.status('info', `Would add reply to comment #${options.number}`));
792
+ }
793
+ else {
794
+ fs.writeFileSync(file, result, 'utf-8');
795
+ console.log(chalk.green(`Reply added to comment #${options.number}`));
796
+ }
797
+ return;
798
+ }
799
+ // Interactive mode
800
+ console.log(chalk.cyan(`\nComments in ${path.basename(file)} (replying as ${chalk.bold(author)}):\n`));
801
+ const rl = (await import('readline')).createInterface({
802
+ input: process.stdin,
803
+ output: process.stdout,
804
+ });
805
+ const askQuestion = (prompt) => new Promise((resolve) => rl.question(prompt, resolve));
806
+ let result = text;
807
+ let repliesAdded = 0;
808
+ for (let i = 0; i < comments.length; i++) {
809
+ const c = comments[i];
810
+ const authorLabel = c.author ? chalk.blue(`[${c.author}]`) : chalk.dim('[Anonymous]');
811
+ const preview = c.content.length > 100 ? c.content.slice(0, 100) + '...' : c.content;
812
+ console.log(`\n${chalk.bold(`#${i + 1}`)} ${authorLabel}`);
813
+ console.log(chalk.dim(` Line ${c.line}: "${c.before?.trim().slice(-30) || ''}..."`));
814
+ console.log(` ${preview}`);
815
+ const answer = await askQuestion(chalk.cyan('\n Reply (or Enter to skip, q to quit): '));
816
+ if (answer.toLowerCase() === 'q') {
817
+ break;
818
+ }
819
+ if (answer.trim()) {
820
+ result = addReply(result, c, author, answer.trim());
821
+ repliesAdded++;
822
+ console.log(chalk.green(' ✓ Reply added'));
823
+ }
824
+ }
825
+ rl.close();
826
+ if (repliesAdded > 0) {
827
+ fs.writeFileSync(file, result, 'utf-8');
828
+ console.log(chalk.green(`\nAdded ${repliesAdded} reply(ies) to ${file}`));
829
+ }
830
+ else {
831
+ console.log(chalk.dim('\nNo replies added.'));
832
+ }
833
+ });
834
+ // ==========================================================================
835
+ // REPLY-DOC command - Generate reply template document from comments
836
+ // ==========================================================================
837
+ program
838
+ .command('reply-doc')
839
+ .alias('rd')
840
+ .description('Generate a reply template document from comments')
841
+ .argument('<file>', 'Markdown file with comments')
842
+ .option('-o, --output <file>', 'Output file (default: <input>_reply.md)')
843
+ .option('--no-context', 'Exclude commented text context')
844
+ .option('--force', 'Overwrite existing output file')
845
+ .action(async (file, options) => {
846
+ requireFile(file, 'Markdown file');
847
+ const text = fs.readFileSync(file, 'utf-8');
848
+ const comments = getComments(text);
849
+ if (comments.length === 0) {
850
+ console.log(fmt.status('info', 'No comments found in file.'));
851
+ return;
852
+ }
853
+ // Determine output filename
854
+ const baseName = path.basename(file, '.md');
855
+ const dirName = path.dirname(file);
856
+ const outputFile = options.output || path.join(dirName, `${baseName}_reply.md`);
857
+ // Check if output exists
858
+ if (fs.existsSync(outputFile) && !options.force) {
859
+ console.log(fmt.status('error', `Output file already exists: ${outputFile}`));
860
+ console.log(chalk.dim(' Use --force to overwrite'));
861
+ process.exit(1);
862
+ }
863
+ // Generate reply template
864
+ const sectionName = baseName.charAt(0).toUpperCase() + baseName.slice(1);
865
+ let output = `# ${sectionName} - Response to Reviewer Comments\n\n`;
866
+ comments.forEach((c, i) => {
867
+ const authorName = c.author || 'Anonymous';
868
+ output += `## Comment ${i + 1} (${authorName})\n`;
869
+ output += `> "${c.content}"\n\n`;
870
+ if (options.context !== false && c.before) {
871
+ const context = c.before.trim().slice(-80);
872
+ if (context) {
873
+ output += `*Context: "...${context}"*\n\n`;
874
+ }
875
+ }
876
+ output += `**Response:** \n\n`;
877
+ });
878
+ fs.writeFileSync(outputFile, output, 'utf-8');
879
+ console.log(fmt.status('success', `Generated reply template: ${outputFile}`));
880
+ console.log(chalk.dim(` ${comments.length} comment(s) extracted`));
881
+ });
882
+ }
883
+ //# sourceMappingURL=comments.js.map