@coderule/mcp 1.6.0 → 1.6.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/index.cjs CHANGED
@@ -848,6 +848,9 @@ var Hasher = class {
848
848
  await this.worker.terminate();
849
849
  }
850
850
  }
851
+ async yieldToEventLoop() {
852
+ await new Promise((resolve) => setImmediate(resolve));
853
+ }
851
854
  resolveAbsolutePath(record) {
852
855
  if (path__default.default.isAbsolute(record.display_path)) {
853
856
  return record.display_path;
@@ -918,6 +921,9 @@ var Hasher = class {
918
921
  const absPath = this.resolveAbsolutePath(record);
919
922
  const exists = await this.ensureExists(absPath, record);
920
923
  if (!exists) {
924
+ if (this.inlineMode) {
925
+ await this.yieldToEventLoop();
926
+ }
921
927
  continue;
922
928
  }
923
929
  try {
@@ -942,6 +948,9 @@ var Hasher = class {
942
948
  failures.push(record.id);
943
949
  }
944
950
  }
951
+ if (this.inlineMode) {
952
+ await this.yieldToEventLoop();
953
+ }
945
954
  }
946
955
  if (successes.length) {
947
956
  this.log.debug({ count: successes.length }, "Hashing succeeded");
@@ -1238,7 +1247,7 @@ async function publishSnapshot(rootPath, filesRepo, snapshotsRepo, syncClient, l
1238
1247
  }
1239
1248
 
1240
1249
  // src/service/InitialSync.ts
1241
- async function runInitialSyncPipeline(runtime) {
1250
+ async function runInitialSyncPipeline(runtime, options) {
1242
1251
  const inventoryLogger = runtime.logger.child({ scope: "inventory" });
1243
1252
  await runInventory({
1244
1253
  rootPath: runtime.config.rootPath,
@@ -1254,19 +1263,37 @@ async function runInitialSyncPipeline(runtime) {
1254
1263
  hashLogger.debug("Hasher processed batch");
1255
1264
  }
1256
1265
  }
1257
- const syncLogger = runtime.logger.child({ scope: "snapshot" });
1258
- const result = await publishSnapshot(
1259
- runtime.config.rootPath,
1260
- runtime.filesRepo,
1261
- runtime.snapshotsRepo,
1262
- runtime.clients.sync,
1263
- syncLogger,
1264
- {
1265
- maxAttempts: runtime.config.maxSnapshotAttempts,
1266
- uploadChunkSize: runtime.config.uploadChunkSize
1267
- }
1266
+ if (options?.blockUntilReady !== false) {
1267
+ const syncLogger = runtime.logger.child({ scope: "snapshot" });
1268
+ const result = await publishSnapshot(
1269
+ runtime.config.rootPath,
1270
+ runtime.filesRepo,
1271
+ runtime.snapshotsRepo,
1272
+ runtime.clients.sync,
1273
+ syncLogger,
1274
+ {
1275
+ maxAttempts: runtime.config.maxSnapshotAttempts,
1276
+ uploadChunkSize: runtime.config.uploadChunkSize
1277
+ }
1278
+ );
1279
+ return result;
1280
+ }
1281
+ const computation = computeSnapshot(runtime.filesRepo);
1282
+ const createdAt = Date.now();
1283
+ runtime.snapshotsRepo.insert(
1284
+ computation.snapshotHash,
1285
+ computation.filesCount,
1286
+ computation.totalSize,
1287
+ createdAt
1268
1288
  );
1269
- return result;
1289
+ runtime.outbox.enqueueSnapshot(runtime.config.rootId, 0);
1290
+ return {
1291
+ snapshotHash: computation.snapshotHash,
1292
+ filesCount: computation.filesCount,
1293
+ totalSize: computation.totalSize,
1294
+ status: "READY",
1295
+ createdAt
1296
+ };
1270
1297
  }
1271
1298
  async function createChokidarWatcher(options, usePolling) {
1272
1299
  const log = options.logger.child({
@@ -1730,7 +1757,9 @@ function awaitShutdownSignals() {
1730
1757
  async function runInitialSync(params) {
1731
1758
  const runtime = await bootstrap(params);
1732
1759
  try {
1733
- const result = await runInitialSyncPipeline(runtime);
1760
+ const result = await runInitialSyncPipeline(runtime, {
1761
+ blockUntilReady: true
1762
+ });
1734
1763
  runtime.logger.info(
1735
1764
  {
1736
1765
  snapshotHash: result.snapshotHash,
@@ -1754,7 +1783,9 @@ async function runService(params) {
1754
1783
  await runner.prepareWatcher(true);
1755
1784
  let initialCreatedAt;
1756
1785
  try {
1757
- const initial = await runInitialSyncPipeline(runtime);
1786
+ const initial = await runInitialSyncPipeline(runtime, {
1787
+ blockUntilReady: false
1788
+ });
1758
1789
  runtime.logger.info(
1759
1790
  {
1760
1791
  snapshotHash: initial.snapshotHash,