@coderule/mcp 1.6.1 → 1.6.3

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/mcp-cli.js CHANGED
@@ -837,6 +837,9 @@ var Hasher = class {
837
837
  await this.worker.terminate();
838
838
  }
839
839
  }
840
+ async yieldToEventLoop() {
841
+ await new Promise((resolve) => setImmediate(resolve));
842
+ }
840
843
  resolveAbsolutePath(record) {
841
844
  if (path.isAbsolute(record.display_path)) {
842
845
  return record.display_path;
@@ -907,6 +910,9 @@ var Hasher = class {
907
910
  const absPath = this.resolveAbsolutePath(record);
908
911
  const exists = await this.ensureExists(absPath, record);
909
912
  if (!exists) {
913
+ if (this.inlineMode) {
914
+ await this.yieldToEventLoop();
915
+ }
910
916
  continue;
911
917
  }
912
918
  try {
@@ -931,6 +937,9 @@ var Hasher = class {
931
937
  failures.push(record.id);
932
938
  }
933
939
  }
940
+ if (this.inlineMode) {
941
+ await this.yieldToEventLoop();
942
+ }
934
943
  }
935
944
  if (successes.length) {
936
945
  this.log.debug({ count: successes.length }, "Hashing succeeded");
@@ -1693,7 +1702,7 @@ var ServiceRunner = class {
1693
1702
  }
1694
1703
  };
1695
1704
  var HASH_STATES = ["clean", "dirty", "hashing", "missing"];
1696
- function collectIndexingStatus(runtime, runner) {
1705
+ async function collectIndexingStatus(runtime, runner) {
1697
1706
  const byState = {};
1698
1707
  for (const state of HASH_STATES) {
1699
1708
  byState[state] = runtime.filesRepo.countByState(state);
@@ -1706,6 +1715,20 @@ function collectIndexingStatus(runtime, runner) {
1706
1715
  done: queue.countByStatus(JobStatus.Done),
1707
1716
  failed: queue.countByStatus(JobStatus.Failed)
1708
1717
  };
1718
+ const latestSnapshot = runtime.snapshotsRepo.getLatest() ?? null;
1719
+ let serverStatus = null;
1720
+ if (latestSnapshot) {
1721
+ try {
1722
+ serverStatus = await runtime.clients.sync.checkSnapshotStatus(
1723
+ latestSnapshot.snapshot_hash
1724
+ );
1725
+ } catch (error) {
1726
+ runtime.logger.warn(
1727
+ { err: error, snapshotHash: latestSnapshot.snapshot_hash },
1728
+ "Failed to fetch server snapshot status"
1729
+ );
1730
+ }
1731
+ }
1709
1732
  return {
1710
1733
  timestamp: Date.now(),
1711
1734
  root: {
@@ -1716,7 +1739,8 @@ function collectIndexingStatus(runtime, runner) {
1716
1739
  total,
1717
1740
  byState
1718
1741
  },
1719
- latestSnapshot: runtime.snapshotsRepo.getLatest() ?? null,
1742
+ latestSnapshot,
1743
+ serverStatus,
1720
1744
  queue: queueCounts,
1721
1745
  service: runner.getServiceStateSnapshot()
1722
1746
  };
@@ -1753,6 +1777,60 @@ function formatStatus(status) {
1753
1777
  lines.push(
1754
1778
  ` Created: ${new Date(status.latestSnapshot.created_at).toISOString()}`
1755
1779
  );
1780
+ if (status.serverStatus) {
1781
+ lines.push(` Server Status: ${status.serverStatus.status}`);
1782
+ if (status.serverStatus.status === "READY" && status.serverStatus.timing) {
1783
+ lines.push("");
1784
+ lines.push(" Indexing Performance:");
1785
+ const timing = status.serverStatus.timing;
1786
+ if (timing.pass1 !== void 0) {
1787
+ lines.push(
1788
+ ` Pass 1 (File Discovery): ${formatDuration(timing.pass1)}`
1789
+ );
1790
+ }
1791
+ if (timing.gap !== void 0) {
1792
+ lines.push(` Gap (Waiting): ${formatDuration(timing.gap)}`);
1793
+ }
1794
+ if (timing.pass2 !== void 0) {
1795
+ lines.push(
1796
+ ` Pass 2 (Cross-Reference): ${formatDuration(timing.pass2)}`
1797
+ );
1798
+ }
1799
+ if (timing.pass2db !== void 0) {
1800
+ lines.push(
1801
+ ` Pass 2 DB Operations: ${formatDuration(timing.pass2db)}`
1802
+ );
1803
+ }
1804
+ const totalTime = (timing.pass1 ?? 0) + (timing.gap ?? 0) + (timing.pass2 ?? 0);
1805
+ if (totalTime > 0) {
1806
+ lines.push(` Total Time: ${formatDuration(totalTime)}`);
1807
+ }
1808
+ lines.push("");
1809
+ lines.push(" Indexing Summary:");
1810
+ if (timing.total_files !== void 0) {
1811
+ lines.push(
1812
+ ` Files Indexed: ${timing.total_files.toLocaleString()}`
1813
+ );
1814
+ }
1815
+ if (timing.total_chunks !== void 0) {
1816
+ lines.push(
1817
+ ` Chunks Created: ${timing.total_chunks.toLocaleString()}`
1818
+ );
1819
+ }
1820
+ if (timing.total_classes !== void 0) {
1821
+ lines.push(
1822
+ ` Classes Found: ${timing.total_classes.toLocaleString()}`
1823
+ );
1824
+ }
1825
+ if (timing.total_methods !== void 0) {
1826
+ lines.push(
1827
+ ` Methods Found: ${timing.total_methods.toLocaleString()}`
1828
+ );
1829
+ }
1830
+ } else if (status.serverStatus.message) {
1831
+ lines.push(` Message: ${status.serverStatus.message}`);
1832
+ }
1833
+ }
1756
1834
  } else {
1757
1835
  lines.push("Latest Snapshot: None");
1758
1836
  }
@@ -1778,6 +1856,19 @@ function formatBytes(bytes) {
1778
1856
  const i = Math.floor(Math.log(bytes) / Math.log(k));
1779
1857
  return `${(bytes / Math.pow(k, i)).toFixed(2)} ${units[i]}`;
1780
1858
  }
1859
+ function formatDuration(seconds) {
1860
+ if (seconds < 1e-3) return "<1ms";
1861
+ if (seconds < 1) return `${(seconds * 1e3).toFixed(0)}ms`;
1862
+ if (seconds < 60) return `${seconds.toFixed(2)}s`;
1863
+ const minutes = Math.floor(seconds / 60);
1864
+ const remainingSeconds = seconds % 60;
1865
+ if (minutes < 60) {
1866
+ return `${minutes}m ${remainingSeconds.toFixed(1)}s`;
1867
+ }
1868
+ const hours = Math.floor(minutes / 60);
1869
+ const remainingMinutes = minutes % 60;
1870
+ return `${hours}h ${remainingMinutes}m ${remainingSeconds.toFixed(0)}s`;
1871
+ }
1781
1872
 
1782
1873
  // src/mcp/server.ts
1783
1874
  var SERVER_NAME = "coderule-scanner-mcp";
@@ -1830,7 +1921,7 @@ function createMcpServer({
1830
1921
  inputSchema: {}
1831
1922
  },
1832
1923
  async () => {
1833
- const status = collectIndexingStatus(runtime, runner);
1924
+ const status = await collectIndexingStatus(runtime, runner);
1834
1925
  const text = formatStatus(status);
1835
1926
  return {
1836
1927
  content: [{ type: "text", text }]
@@ -1855,7 +1946,9 @@ function createMcpServer({
1855
1946
  const deadline = Date.now() + runtime.config.maxQueryWaitMs;
1856
1947
  const latest = await waitForLocalSnapshot(deadline);
1857
1948
  if (!latest) {
1858
- const statusText = formatStatus(collectIndexingStatus(runtime, runner));
1949
+ const statusText = formatStatus(
1950
+ await collectIndexingStatus(runtime, runner)
1951
+ );
1859
1952
  const text = `We are not ready....
1860
1953
  ${statusText}`;
1861
1954
  return { content: [{ type: "text", text }] };
@@ -1865,7 +1958,9 @@ ${statusText}`;
1865
1958
  deadline
1866
1959
  );
1867
1960
  if (!readyHash) {
1868
- const statusText = formatStatus(collectIndexingStatus(runtime, runner));
1961
+ const statusText = formatStatus(
1962
+ await collectIndexingStatus(runtime, runner)
1963
+ );
1869
1964
  const text = `We are not ready....
1870
1965
  ${statusText}`;
1871
1966
  return { content: [{ type: "text", text }] };