@mrsf/cli 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -90,7 +90,7 @@ mrsf validate --strict
90
90
 
91
91
  ### `mrsf add <document>`
92
92
 
93
- Add a review comment to a document's sidecar file. Creates the sidecar if it doesn't exist. Automatically populates `selected_text` from the document when a line is specified, and stamps the current git commit.
93
+ Add a review comment to a document's sidecar file. Creates the sidecar if it doesn't exist. Automatically populates `selected_text` from the document when a line is specified, and stamps the current git commit. When `--author` is omitted, MRSF uses `user.name` from the repository-local `.git/config`; global Git identity is not used.
94
94
 
95
95
  ```bash
96
96
  # Add a line comment
@@ -124,7 +124,7 @@ mrsf add docs/api.md \
124
124
 
125
125
  | Option | Description |
126
126
  |---|---|
127
- | `-a, --author <name>` | Comment author (required) |
127
+ | `-a, --author <name>` | Comment author; overrides repository-local Git `user.name` |
128
128
  | `-t, --text <text>` | Comment body (required) |
129
129
  | `-l, --line <n>` | Line number (1-based) |
130
130
  | `--end-line <n>` | End line (inclusive) |
@@ -7,7 +7,7 @@ import { discoverSidecar, findWorkspaceRoot } from "../lib/discovery.js";
7
7
  import { parseSidecar, readDocumentLines } from "../lib/parser.js";
8
8
  import { writeSidecar } from "../lib/writer.js";
9
9
  import { addComment, populateSelectedText } from "../lib/comments.js";
10
- import { findRepoRoot } from "../lib/git.js";
10
+ import { findRepoRoot, getGitUserName } from "../lib/git.js";
11
11
  function collectOptionValues(value, previous) {
12
12
  previous.push(value);
13
13
  return previous;
@@ -52,7 +52,7 @@ export function registerAdd(program) {
52
52
  program
53
53
  .command("add <document>")
54
54
  .description("Add a review comment to a document's sidecar")
55
- .requiredOption("-a, --author <name>", "Comment author")
55
+ .option("-a, --author <name>", "Comment author (defaults to repository-local Git user.name)")
56
56
  .requiredOption("-t, --text <text>", "Comment text")
57
57
  .option("-l, --line <n>", "Line number (1-based)")
58
58
  .option("--end-line <n>", "End line (inclusive)")
@@ -84,9 +84,17 @@ export function registerAdd(program) {
84
84
  comments: [],
85
85
  };
86
86
  }
87
- const repoRoot = await findRepoRoot(cwd);
87
+ const repoRoot = await findRepoRoot(path.dirname(docPath));
88
+ const author = opts.author?.trim()
89
+ || (repoRoot ? await getGitUserName(repoRoot) : null);
90
+ if (!author) {
91
+ console.error(chalk.red("Comment author is required. Pass --author or configure "
92
+ + "repository-local Git identity with: "
93
+ + "git config --local user.name \"Your Name\""));
94
+ process.exit(1);
95
+ }
88
96
  const comment = await addComment(doc, {
89
- author: opts.author,
97
+ author,
90
98
  text: opts.text,
91
99
  line: opts.line ? parseInt(opts.line, 10) : undefined,
92
100
  end_line: opts.endLine ? parseInt(opts.endLine, 10) : undefined,
package/dist/index.cjs CHANGED
@@ -221,6 +221,7 @@ __export(index_exports, {
221
221
  getCurrentCommit: () => getCurrentCommit2,
222
222
  getDiff: () => getDiff2,
223
223
  getFileAtCommit: () => getFileAtCommit2,
224
+ getGitUserName: () => getGitUserName2,
224
225
  getLineShift: () => getLineShift4,
225
226
  getStagedFiles: () => getStagedFiles2,
226
227
  getThreads: () => getThreads2,
@@ -1352,6 +1353,20 @@ async function findRepoRoot(cwd) {
1352
1353
  return null;
1353
1354
  }
1354
1355
  }
1356
+ async function getGitUserName(repoRoot) {
1357
+ if (!await isGitAvailable()) return null;
1358
+ try {
1359
+ const { stdout } = await execFile(
1360
+ "git",
1361
+ ["config", "--local", "--get", "user.name"],
1362
+ { cwd: repoRoot, timeout: GIT_TIMEOUT }
1363
+ );
1364
+ const name = stdout.trim();
1365
+ return name || null;
1366
+ } catch {
1367
+ return null;
1368
+ }
1369
+ }
1355
1370
  async function getCurrentCommit(repoRoot) {
1356
1371
  if (!await isGitAvailable()) return null;
1357
1372
  try {
@@ -3255,6 +3270,7 @@ var fuzzySearch2 = fuzzySearch;
3255
3270
  var combinedScore2 = combinedScore;
3256
3271
  var isGitAvailable2 = isGitAvailable;
3257
3272
  var findRepoRoot3 = findRepoRoot;
3273
+ var getGitUserName2 = getGitUserName;
3258
3274
  var getCurrentCommit2 = getCurrentCommit;
3259
3275
  var resolveCommit2 = resolveCommit;
3260
3276
  var isStale2 = isStale;
@@ -3315,6 +3331,7 @@ var newCommentId2 = newCommentId;
3315
3331
  getCurrentCommit,
3316
3332
  getDiff,
3317
3333
  getFileAtCommit,
3334
+ getGitUserName,
3318
3335
  getLineShift,
3319
3336
  getStagedFiles,
3320
3337
  getThreads,