@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.js CHANGED
@@ -834,6 +834,9 @@ var Hasher = class {
834
834
  await this.worker.terminate();
835
835
  }
836
836
  }
837
+ async yieldToEventLoop() {
838
+ await new Promise((resolve) => setImmediate(resolve));
839
+ }
837
840
  resolveAbsolutePath(record) {
838
841
  if (path.isAbsolute(record.display_path)) {
839
842
  return record.display_path;
@@ -904,6 +907,9 @@ var Hasher = class {
904
907
  const absPath = this.resolveAbsolutePath(record);
905
908
  const exists = await this.ensureExists(absPath, record);
906
909
  if (!exists) {
910
+ if (this.inlineMode) {
911
+ await this.yieldToEventLoop();
912
+ }
907
913
  continue;
908
914
  }
909
915
  try {
@@ -928,6 +934,9 @@ var Hasher = class {
928
934
  failures.push(record.id);
929
935
  }
930
936
  }
937
+ if (this.inlineMode) {
938
+ await this.yieldToEventLoop();
939
+ }
931
940
  }
932
941
  if (successes.length) {
933
942
  this.log.debug({ count: successes.length }, "Hashing succeeded");
@@ -1224,7 +1233,7 @@ async function publishSnapshot(rootPath, filesRepo, snapshotsRepo, syncClient, l
1224
1233
  }
1225
1234
 
1226
1235
  // src/service/InitialSync.ts
1227
- async function runInitialSyncPipeline(runtime) {
1236
+ async function runInitialSyncPipeline(runtime, options) {
1228
1237
  const inventoryLogger = runtime.logger.child({ scope: "inventory" });
1229
1238
  await runInventory({
1230
1239
  rootPath: runtime.config.rootPath,
@@ -1240,19 +1249,37 @@ async function runInitialSyncPipeline(runtime) {
1240
1249
  hashLogger.debug("Hasher processed batch");
1241
1250
  }
1242
1251
  }
1243
- const syncLogger = runtime.logger.child({ scope: "snapshot" });
1244
- const result = await publishSnapshot(
1245
- runtime.config.rootPath,
1246
- runtime.filesRepo,
1247
- runtime.snapshotsRepo,
1248
- runtime.clients.sync,
1249
- syncLogger,
1250
- {
1251
- maxAttempts: runtime.config.maxSnapshotAttempts,
1252
- uploadChunkSize: runtime.config.uploadChunkSize
1253
- }
1252
+ if (options?.blockUntilReady !== false) {
1253
+ const syncLogger = runtime.logger.child({ scope: "snapshot" });
1254
+ const result = await publishSnapshot(
1255
+ runtime.config.rootPath,
1256
+ runtime.filesRepo,
1257
+ runtime.snapshotsRepo,
1258
+ runtime.clients.sync,
1259
+ syncLogger,
1260
+ {
1261
+ maxAttempts: runtime.config.maxSnapshotAttempts,
1262
+ uploadChunkSize: runtime.config.uploadChunkSize
1263
+ }
1264
+ );
1265
+ return result;
1266
+ }
1267
+ const computation = computeSnapshot(runtime.filesRepo);
1268
+ const createdAt = Date.now();
1269
+ runtime.snapshotsRepo.insert(
1270
+ computation.snapshotHash,
1271
+ computation.filesCount,
1272
+ computation.totalSize,
1273
+ createdAt
1254
1274
  );
1255
- return result;
1275
+ runtime.outbox.enqueueSnapshot(runtime.config.rootId, 0);
1276
+ return {
1277
+ snapshotHash: computation.snapshotHash,
1278
+ filesCount: computation.filesCount,
1279
+ totalSize: computation.totalSize,
1280
+ status: "READY",
1281
+ createdAt
1282
+ };
1256
1283
  }
1257
1284
  async function createChokidarWatcher(options, usePolling) {
1258
1285
  const log = options.logger.child({
@@ -1716,7 +1743,9 @@ function awaitShutdownSignals() {
1716
1743
  async function runInitialSync(params) {
1717
1744
  const runtime = await bootstrap(params);
1718
1745
  try {
1719
- const result = await runInitialSyncPipeline(runtime);
1746
+ const result = await runInitialSyncPipeline(runtime, {
1747
+ blockUntilReady: true
1748
+ });
1720
1749
  runtime.logger.info(
1721
1750
  {
1722
1751
  snapshotHash: result.snapshotHash,
@@ -1740,7 +1769,9 @@ async function runService(params) {
1740
1769
  await runner.prepareWatcher(true);
1741
1770
  let initialCreatedAt;
1742
1771
  try {
1743
- const initial = await runInitialSyncPipeline(runtime);
1772
+ const initial = await runInitialSyncPipeline(runtime, {
1773
+ blockUntilReady: false
1774
+ });
1744
1775
  runtime.logger.info(
1745
1776
  {
1746
1777
  snapshotHash: initial.snapshotHash,