chatroom-cli 1.62.0 → 1.63.0

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/index.js CHANGED
@@ -81713,6 +81713,7 @@ var FULL_DIFF_MAX_BYTES = 500000, COMMITS_PER_PAGE = 20;
81713
81713
  // src/infrastructure/git/run-command.ts
81714
81714
  import { spawn as spawn5 } from "node:child_process";
81715
81715
  function runCommandSpawn(command, args2, cwd, options) {
81716
+ const successExitCodes = options?.successExitCodes ?? [0];
81716
81717
  return new Promise((resolve4) => {
81717
81718
  const child = spawn5(command, args2, {
81718
81719
  cwd,
@@ -81738,7 +81739,7 @@ function runCommandSpawn(command, args2, cwd, options) {
81738
81739
  child.on("close", (code2) => {
81739
81740
  if (timer)
81740
81741
  clearTimeout(timer);
81741
- if (code2 === 0)
81742
+ if (successExitCodes.includes(code2 ?? -1))
81742
81743
  resolve4({ stdout, stderr });
81743
81744
  else {
81744
81745
  resolve4({
@@ -81790,6 +81791,91 @@ function isPermissionDenied(message) {
81790
81791
  function isEmptyRepo(stderr) {
81791
81792
  return stderr.includes("does not have any commits yet") || stderr.includes("no commits yet") || stderr.includes("ambiguous argument 'HEAD'") || stderr.includes("unknown revision or path");
81792
81793
  }
81794
+ async function listUntrackedFiles(workingDir) {
81795
+ const result = await runGit(["ls-files", "--others", "--exclude-standard"], workingDir);
81796
+ if ("error" in result)
81797
+ return [];
81798
+ return result.stdout.split(`
81799
+ `).map((line) => line.trim()).filter(Boolean);
81800
+ }
81801
+ async function getUntrackedFileDiff(workingDir, filePath) {
81802
+ const result = await runGit(["diff", "--no-index", "--", NULL_DEVICE, filePath], workingDir, {
81803
+ successExitCodes: [0, 1]
81804
+ });
81805
+ if ("error" in result)
81806
+ return "";
81807
+ return result.stdout;
81808
+ }
81809
+ function countDiffInsertions(diff8) {
81810
+ let count3 = 0;
81811
+ for (const line of diff8.split(`
81812
+ `)) {
81813
+ if (line.startsWith("+") && !line.startsWith("+++"))
81814
+ count3++;
81815
+ }
81816
+ return count3;
81817
+ }
81818
+ function mergeDiffStatWithUntracked(base, untrackedDiffs) {
81819
+ const untrackedInsertions = untrackedDiffs.reduce((sum2, diff8) => sum2 + countDiffInsertions(diff8), 0);
81820
+ return {
81821
+ filesChanged: base.filesChanged + untrackedDiffs.length,
81822
+ insertions: base.insertions + untrackedInsertions,
81823
+ deletions: base.deletions
81824
+ };
81825
+ }
81826
+ async function appendUntrackedDiffs(workingDir, trackedDiff) {
81827
+ const untrackedPaths = await listUntrackedFiles(workingDir);
81828
+ if (untrackedPaths.length === 0)
81829
+ return trackedDiff;
81830
+ const parts2 = [];
81831
+ if (trackedDiff.trim())
81832
+ parts2.push(trackedDiff.trimEnd());
81833
+ for (const filePath of untrackedPaths) {
81834
+ const fileDiff = await getUntrackedFileDiff(workingDir, filePath);
81835
+ if (fileDiff.trim())
81836
+ parts2.push(fileDiff.trimEnd());
81837
+ }
81838
+ if (parts2.length === 0)
81839
+ return trackedDiff;
81840
+ return `${parts2.join(`
81841
+ `)}
81842
+ `;
81843
+ }
81844
+ async function getUntrackedDiffs(workingDir) {
81845
+ const untrackedPaths = await listUntrackedFiles(workingDir);
81846
+ const diffs = [];
81847
+ for (const filePath of untrackedPaths) {
81848
+ const fileDiff = await getUntrackedFileDiff(workingDir, filePath);
81849
+ if (fileDiff.trim())
81850
+ diffs.push(fileDiff);
81851
+ }
81852
+ return diffs;
81853
+ }
81854
+ function truncateDiffContent(raw) {
81855
+ const byteLength2 = Buffer.byteLength(raw, "utf8");
81856
+ if (byteLength2 > FULL_DIFF_MAX_BYTES) {
81857
+ const truncated = Buffer.from(raw, "utf8").subarray(0, FULL_DIFF_MAX_BYTES).toString("utf8");
81858
+ return { status: "truncated", content: truncated, truncated: true };
81859
+ }
81860
+ return { status: "available", content: raw, truncated: false };
81861
+ }
81862
+ async function runTrackedHeadDiff(workingDir, args2, options) {
81863
+ const result = await runGit(args2, workingDir, options);
81864
+ if ("error" in result) {
81865
+ const errMsg = result.error.message;
81866
+ if (isEmptyRepo(errMsg))
81867
+ return { status: "empty_repo" };
81868
+ const classified = classifyError(errMsg);
81869
+ if (classified.status === "not_found")
81870
+ return { status: "not_found" };
81871
+ if (classified.status === "error")
81872
+ return { status: "error", message: classified.message };
81873
+ return { status: "not_found" };
81874
+ }
81875
+ if (isEmptyRepo(result.stderr))
81876
+ return { status: "empty_repo" };
81877
+ return { status: "ok", stdout: result.stdout };
81878
+ }
81793
81879
  function classifyError(errMessage) {
81794
81880
  if (isGitNotInstalled(errMessage)) {
81795
81881
  return { status: "error", message: "git is not installed or not in PATH" };
@@ -81840,59 +81926,41 @@ function parseDiffStatLine(statLine) {
81840
81926
  };
81841
81927
  }
81842
81928
  async function getDiffStat(workingDir) {
81843
- const result = await runGit(["diff", "HEAD", "--stat"], workingDir);
81844
- if ("error" in result) {
81845
- const errMsg = result.error.message;
81846
- if (isEmptyRepo(result.error.message)) {
81847
- return { status: "no_commits" };
81848
- }
81849
- const classified = classifyError(errMsg);
81850
- if (classified.status === "not_found")
81851
- return { status: "not_found" };
81852
- return classified;
81853
- }
81854
- const output = result.stdout;
81855
- const stderr = result.stderr;
81856
- if (isEmptyRepo(stderr)) {
81857
- return { status: "no_commits" };
81929
+ const tracked = await runTrackedHeadDiff(workingDir, ["diff", "HEAD", "--stat"]);
81930
+ if (tracked.status === "not_found")
81931
+ return { status: "not_found" };
81932
+ if (tracked.status === "error")
81933
+ return { status: "error", message: tracked.message };
81934
+ let baseStat = { filesChanged: 0, insertions: 0, deletions: 0 };
81935
+ const hadEmptyRepo = tracked.status === "empty_repo";
81936
+ if (tracked.status === "ok" && tracked.stdout.trim()) {
81937
+ const lines = tracked.stdout.trim().split(`
81938
+ `);
81939
+ baseStat = parseDiffStatLine(lines[lines.length - 1] ?? "");
81858
81940
  }
81859
- if (!output.trim()) {
81860
- return {
81861
- status: "available",
81862
- diffStat: { filesChanged: 0, insertions: 0, deletions: 0 }
81863
- };
81941
+ const untrackedDiffs = await getUntrackedDiffs(workingDir);
81942
+ if (untrackedDiffs.length === 0) {
81943
+ if (hadEmptyRepo)
81944
+ return { status: "no_commits" };
81945
+ return { status: "available", diffStat: baseStat };
81864
81946
  }
81865
- const lines = output.trim().split(`
81866
- `);
81867
- const summaryLine = lines[lines.length - 1] ?? "";
81868
- const diffStat = parseDiffStatLine(summaryLine);
81869
- return { status: "available", diffStat };
81947
+ return { status: "available", diffStat: mergeDiffStatWithUntracked(baseStat, untrackedDiffs) };
81870
81948
  }
81871
81949
  async function getFullDiff(workingDir) {
81872
- const result = await runGit(["diff", "HEAD"], workingDir, {
81950
+ const tracked = await runTrackedHeadDiff(workingDir, ["diff", "HEAD"], {
81873
81951
  maxBuffer: FULL_DIFF_MAX_BYTES + 64 * 1024
81874
81952
  });
81875
- if ("error" in result) {
81876
- const errMsg = result.error.message;
81877
- if (isEmptyRepo(errMsg)) {
81878
- return { status: "no_commits" };
81879
- }
81880
- const classified = classifyError(errMsg);
81881
- if (classified.status === "not_found")
81882
- return { status: "not_found" };
81883
- return classified;
81884
- }
81885
- const stderr = result.stderr;
81886
- if (isEmptyRepo(stderr)) {
81887
- return { status: "no_commits" };
81888
- }
81889
- const raw = result.stdout;
81890
- const byteLength2 = Buffer.byteLength(raw, "utf8");
81891
- if (byteLength2 > FULL_DIFF_MAX_BYTES) {
81892
- const truncated = Buffer.from(raw, "utf8").subarray(0, FULL_DIFF_MAX_BYTES).toString("utf8");
81893
- return { status: "truncated", content: truncated, truncated: true };
81953
+ if (tracked.status === "not_found")
81954
+ return { status: "not_found" };
81955
+ if (tracked.status === "error")
81956
+ return { status: "error", message: tracked.message };
81957
+ const trackedDiff = tracked.status === "ok" ? tracked.stdout : "";
81958
+ const hadEmptyRepo = tracked.status === "empty_repo";
81959
+ const content = await appendUntrackedDiffs(workingDir, trackedDiff);
81960
+ if (!content.trim()) {
81961
+ return hadEmptyRepo ? { status: "no_commits" } : { status: "available", content: "", truncated: false };
81894
81962
  }
81895
- return { status: "available", content: raw, truncated: false };
81963
+ return truncateDiffContent(content);
81896
81964
  }
81897
81965
  async function getPRDiffByNumber(cwd, prNumber) {
81898
81966
  const repoSlug = await getOriginRepoSlug(cwd);
@@ -81904,12 +81972,7 @@ async function getPRDiffByNumber(cwd, prNumber) {
81904
81972
  if (!raw.trim()) {
81905
81973
  return { status: "available", content: "", truncated: false };
81906
81974
  }
81907
- const byteLength2 = Buffer.byteLength(raw, "utf8");
81908
- if (byteLength2 > FULL_DIFF_MAX_BYTES) {
81909
- const truncated = Buffer.from(raw, "utf8").subarray(0, FULL_DIFF_MAX_BYTES).toString("utf8");
81910
- return { status: "truncated", content: truncated, truncated: true };
81911
- }
81912
- return { status: "available", content: raw, truncated: false };
81975
+ return truncateDiffContent(raw);
81913
81976
  }
81914
81977
  async function getRecentCommits(workingDir, count3 = 20, skip = 0) {
81915
81978
  const format4 = "%H%x1f%h%x1f%s%x1f%b%x1f%an%x1f%aI%x1e";
@@ -82230,8 +82293,10 @@ async function getCommitStatusChecks(cwd, ref) {
82230
82293
  return null;
82231
82294
  }
82232
82295
  }
82296
+ var NULL_DEVICE;
82233
82297
  var init_git_reader = __esm(() => {
82234
82298
  init_run_command();
82299
+ NULL_DEVICE = process.platform === "win32" ? "NUL" : "/dev/null";
82235
82300
  });
82236
82301
 
82237
82302
  // src/infrastructure/git/git-writer.ts
@@ -107936,4 +108001,4 @@ program2.hook("preAction", async (_thisCommand, actionCommand) => {
107936
108001
  });
107937
108002
  program2.parse();
107938
108003
 
107939
- //# debugId=397B148D091FEB8464756E2164756E21
108004
+ //# debugId=FFC06E9C93DB92D864756E2164756E21