@mrsf/cli 0.2.1 → 0.2.2

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.
package/dist/bin.js CHANGED
File without changes
package/dist/index.d.ts CHANGED
@@ -14,5 +14,5 @@ export { exactMatch, normalizedMatch, fuzzySearch, combinedScore, } from "./lib/
14
14
  export { isGitAvailable, findRepoRoot, getCurrentCommit, isStale, getDiff, getLineShift, getFileAtCommit, getStagedFiles, detectRenames, parseDiffHunks, } from "./lib/git.js";
15
15
  export { reanchorComment, reanchorDocument, applyReanchorResults, reanchorFile, } from "./lib/reanchor.js";
16
16
  export { addComment, populateSelectedText, resolveComment, unresolveComment, removeComment, filterComments, getThreads, summarize, } from "./lib/comments.js";
17
- export type { CommentSummary } from "./lib/comments.js";
17
+ export type { CommentSummary, RemoveCommentOptions } from "./lib/comments.js";
18
18
  //# sourceMappingURL=index.d.ts.map
@@ -23,10 +23,23 @@ export declare function resolveComment(doc: MrsfDocument, commentId: string, cas
23
23
  * Unresolve a comment by id.
24
24
  */
25
25
  export declare function unresolveComment(doc: MrsfDocument, commentId: string): boolean;
26
+ export interface RemoveCommentOptions {
27
+ /**
28
+ * When true, also delete all direct replies instead of promoting them.
29
+ * Default: false (promote replies per §9.1).
30
+ */
31
+ cascade?: boolean;
32
+ }
26
33
  /**
27
- * Remove a comment by id. Returns true if found and removed.
34
+ * Remove a comment by id. Per §9.1, direct replies are promoted:
35
+ * their anchor fields are inherited from the parent (when absent),
36
+ * and their `reply_to` is re-pointed to the parent's parent (or cleared).
37
+ *
38
+ * If `cascade` is true, direct replies are removed along with the parent.
39
+ *
40
+ * Returns true if the comment was found and removed.
28
41
  */
29
- export declare function removeComment(doc: MrsfDocument, commentId: string): boolean;
42
+ export declare function removeComment(doc: MrsfDocument, commentId: string, opts?: RemoveCommentOptions): boolean;
30
43
  /**
31
44
  * Filter comments based on criteria.
32
45
  */
@@ -122,14 +122,58 @@ export function unresolveComment(doc, commentId) {
122
122
  // ---------------------------------------------------------------------------
123
123
  // Remove
124
124
  // ---------------------------------------------------------------------------
125
+ /** Anchor fields that a reply may inherit from its parent on deletion. */
126
+ const ANCHOR_FIELDS = [
127
+ "line",
128
+ "end_line",
129
+ "start_column",
130
+ "end_column",
131
+ "selected_text",
132
+ "selected_text_hash",
133
+ "anchored_text",
134
+ "commit",
135
+ ];
125
136
  /**
126
- * Remove a comment by id. Returns true if found and removed.
137
+ * Remove a comment by id. Per §9.1, direct replies are promoted:
138
+ * their anchor fields are inherited from the parent (when absent),
139
+ * and their `reply_to` is re-pointed to the parent's parent (or cleared).
140
+ *
141
+ * If `cascade` is true, direct replies are removed along with the parent.
142
+ *
143
+ * Returns true if the comment was found and removed.
127
144
  */
128
- export function removeComment(doc, commentId) {
129
- const idx = doc.comments.findIndex((c) => c.id === commentId);
130
- if (idx === -1)
145
+ export function removeComment(doc, commentId, opts) {
146
+ const comment = doc.comments.find((c) => c.id === commentId);
147
+ if (!comment)
131
148
  return false;
132
- doc.comments.splice(idx, 1);
149
+ if (opts?.cascade) {
150
+ // Remove direct replies first
151
+ doc.comments = doc.comments.filter((c) => c.id === commentId || c.reply_to !== commentId);
152
+ }
153
+ else {
154
+ // Promote direct replies (§9.1)
155
+ for (const c of doc.comments) {
156
+ if (c.reply_to !== commentId)
157
+ continue;
158
+ // Copy missing anchor fields from the parent
159
+ for (const field of ANCHOR_FIELDS) {
160
+ if (c[field] == null && comment[field] != null) {
161
+ c[field] = comment[field];
162
+ }
163
+ }
164
+ // Re-point reply_to to grandparent (or clear if parent was root)
165
+ if (comment.reply_to) {
166
+ c.reply_to = comment.reply_to;
167
+ }
168
+ else {
169
+ delete c.reply_to;
170
+ }
171
+ }
172
+ }
173
+ // Remove the parent comment itself
174
+ const idx = doc.comments.findIndex((c) => c.id === commentId);
175
+ if (idx !== -1)
176
+ doc.comments.splice(idx, 1);
133
177
  return true;
134
178
  }
135
179
  // ---------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrsf/cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "CLI and library for the Markdown Review Sidecar Format (MRSF)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",