@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.cjs CHANGED
@@ -852,6 +852,9 @@ var Hasher = class {
852
852
  await this.worker.terminate();
853
853
  }
854
854
  }
855
+ async yieldToEventLoop() {
856
+ await new Promise((resolve) => setImmediate(resolve));
857
+ }
855
858
  resolveAbsolutePath(record) {
856
859
  if (path__default.default.isAbsolute(record.display_path)) {
857
860
  return record.display_path;
@@ -922,6 +925,9 @@ var Hasher = class {
922
925
  const absPath = this.resolveAbsolutePath(record);
923
926
  const exists = await this.ensureExists(absPath, record);
924
927
  if (!exists) {
928
+ if (this.inlineMode) {
929
+ await this.yieldToEventLoop();
930
+ }
925
931
  continue;
926
932
  }
927
933
  try {
@@ -946,6 +952,9 @@ var Hasher = class {
946
952
  failures.push(record.id);
947
953
  }
948
954
  }
955
+ if (this.inlineMode) {
956
+ await this.yieldToEventLoop();
957
+ }
949
958
  }
950
959
  if (successes.length) {
951
960
  this.log.debug({ count: successes.length }, "Hashing succeeded");
@@ -1708,7 +1717,7 @@ var ServiceRunner = class {
1708
1717
  }
1709
1718
  };
1710
1719
  var HASH_STATES = ["clean", "dirty", "hashing", "missing"];
1711
- function collectIndexingStatus(runtime, runner) {
1720
+ async function collectIndexingStatus(runtime, runner) {
1712
1721
  const byState = {};
1713
1722
  for (const state of HASH_STATES) {
1714
1723
  byState[state] = runtime.filesRepo.countByState(state);
@@ -1721,6 +1730,20 @@ function collectIndexingStatus(runtime, runner) {
1721
1730
  done: queue.countByStatus(qulite.JobStatus.Done),
1722
1731
  failed: queue.countByStatus(qulite.JobStatus.Failed)
1723
1732
  };
1733
+ const latestSnapshot = runtime.snapshotsRepo.getLatest() ?? null;
1734
+ let serverStatus = null;
1735
+ if (latestSnapshot) {
1736
+ try {
1737
+ serverStatus = await runtime.clients.sync.checkSnapshotStatus(
1738
+ latestSnapshot.snapshot_hash
1739
+ );
1740
+ } catch (error) {
1741
+ runtime.logger.warn(
1742
+ { err: error, snapshotHash: latestSnapshot.snapshot_hash },
1743
+ "Failed to fetch server snapshot status"
1744
+ );
1745
+ }
1746
+ }
1724
1747
  return {
1725
1748
  timestamp: Date.now(),
1726
1749
  root: {
@@ -1731,7 +1754,8 @@ function collectIndexingStatus(runtime, runner) {
1731
1754
  total,
1732
1755
  byState
1733
1756
  },
1734
- latestSnapshot: runtime.snapshotsRepo.getLatest() ?? null,
1757
+ latestSnapshot,
1758
+ serverStatus,
1735
1759
  queue: queueCounts,
1736
1760
  service: runner.getServiceStateSnapshot()
1737
1761
  };
@@ -1768,6 +1792,60 @@ function formatStatus(status) {
1768
1792
  lines.push(
1769
1793
  ` Created: ${new Date(status.latestSnapshot.created_at).toISOString()}`
1770
1794
  );
1795
+ if (status.serverStatus) {
1796
+ lines.push(` Server Status: ${status.serverStatus.status}`);
1797
+ if (status.serverStatus.status === "READY" && status.serverStatus.timing) {
1798
+ lines.push("");
1799
+ lines.push(" Indexing Performance:");
1800
+ const timing = status.serverStatus.timing;
1801
+ if (timing.pass1 !== void 0) {
1802
+ lines.push(
1803
+ ` Pass 1 (File Discovery): ${formatDuration(timing.pass1)}`
1804
+ );
1805
+ }
1806
+ if (timing.gap !== void 0) {
1807
+ lines.push(` Gap (Waiting): ${formatDuration(timing.gap)}`);
1808
+ }
1809
+ if (timing.pass2 !== void 0) {
1810
+ lines.push(
1811
+ ` Pass 2 (Cross-Reference): ${formatDuration(timing.pass2)}`
1812
+ );
1813
+ }
1814
+ if (timing.pass2db !== void 0) {
1815
+ lines.push(
1816
+ ` Pass 2 DB Operations: ${formatDuration(timing.pass2db)}`
1817
+ );
1818
+ }
1819
+ const totalTime = (timing.pass1 ?? 0) + (timing.gap ?? 0) + (timing.pass2 ?? 0);
1820
+ if (totalTime > 0) {
1821
+ lines.push(` Total Time: ${formatDuration(totalTime)}`);
1822
+ }
1823
+ lines.push("");
1824
+ lines.push(" Indexing Summary:");
1825
+ if (timing.total_files !== void 0) {
1826
+ lines.push(
1827
+ ` Files Indexed: ${timing.total_files.toLocaleString()}`
1828
+ );
1829
+ }
1830
+ if (timing.total_chunks !== void 0) {
1831
+ lines.push(
1832
+ ` Chunks Created: ${timing.total_chunks.toLocaleString()}`
1833
+ );
1834
+ }
1835
+ if (timing.total_classes !== void 0) {
1836
+ lines.push(
1837
+ ` Classes Found: ${timing.total_classes.toLocaleString()}`
1838
+ );
1839
+ }
1840
+ if (timing.total_methods !== void 0) {
1841
+ lines.push(
1842
+ ` Methods Found: ${timing.total_methods.toLocaleString()}`
1843
+ );
1844
+ }
1845
+ } else if (status.serverStatus.message) {
1846
+ lines.push(` Message: ${status.serverStatus.message}`);
1847
+ }
1848
+ }
1771
1849
  } else {
1772
1850
  lines.push("Latest Snapshot: None");
1773
1851
  }
@@ -1793,6 +1871,19 @@ function formatBytes(bytes) {
1793
1871
  const i = Math.floor(Math.log(bytes) / Math.log(k));
1794
1872
  return `${(bytes / Math.pow(k, i)).toFixed(2)} ${units[i]}`;
1795
1873
  }
1874
+ function formatDuration(seconds) {
1875
+ if (seconds < 1e-3) return "<1ms";
1876
+ if (seconds < 1) return `${(seconds * 1e3).toFixed(0)}ms`;
1877
+ if (seconds < 60) return `${seconds.toFixed(2)}s`;
1878
+ const minutes = Math.floor(seconds / 60);
1879
+ const remainingSeconds = seconds % 60;
1880
+ if (minutes < 60) {
1881
+ return `${minutes}m ${remainingSeconds.toFixed(1)}s`;
1882
+ }
1883
+ const hours = Math.floor(minutes / 60);
1884
+ const remainingMinutes = minutes % 60;
1885
+ return `${hours}h ${remainingMinutes}m ${remainingSeconds.toFixed(0)}s`;
1886
+ }
1796
1887
 
1797
1888
  // src/mcp/server.ts
1798
1889
  var SERVER_NAME = "coderule-scanner-mcp";
@@ -1845,7 +1936,7 @@ function createMcpServer({
1845
1936
  inputSchema: {}
1846
1937
  },
1847
1938
  async () => {
1848
- const status = collectIndexingStatus(runtime, runner);
1939
+ const status = await collectIndexingStatus(runtime, runner);
1849
1940
  const text = formatStatus(status);
1850
1941
  return {
1851
1942
  content: [{ type: "text", text }]
@@ -1870,7 +1961,9 @@ function createMcpServer({
1870
1961
  const deadline = Date.now() + runtime.config.maxQueryWaitMs;
1871
1962
  const latest = await waitForLocalSnapshot(deadline);
1872
1963
  if (!latest) {
1873
- const statusText = formatStatus(collectIndexingStatus(runtime, runner));
1964
+ const statusText = formatStatus(
1965
+ await collectIndexingStatus(runtime, runner)
1966
+ );
1874
1967
  const text = `We are not ready....
1875
1968
  ${statusText}`;
1876
1969
  return { content: [{ type: "text", text }] };
@@ -1880,7 +1973,9 @@ ${statusText}`;
1880
1973
  deadline
1881
1974
  );
1882
1975
  if (!readyHash) {
1883
- const statusText = formatStatus(collectIndexingStatus(runtime, runner));
1976
+ const statusText = formatStatus(
1977
+ await collectIndexingStatus(runtime, runner)
1978
+ );
1884
1979
  const text = `We are not ready....
1885
1980
  ${statusText}`;
1886
1981
  return { content: [{ type: "text", text }] };