replicas-engine 0.1.149 → 0.1.151

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.
Files changed (2) hide show
  1. package/dist/src/index.js +118 -72
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -277,7 +277,7 @@ function parseReplicasConfigString(content, filename) {
277
277
  }
278
278
 
279
279
  // ../shared/src/engine/environment.ts
280
- var DAYTONA_SNAPSHOT_ID = "09-05-2026-royal-york-v1";
280
+ var DAYTONA_SNAPSHOT_ID = "10-05-2026-royal-york-v2";
281
281
 
282
282
  // ../shared/src/engine/types.ts
283
283
  var DEFAULT_CHAT_TITLES = {
@@ -1335,6 +1335,7 @@ function createDefaultDetails() {
1335
1335
  return {
1336
1336
  engineVersion: DAYTONA_SNAPSHOT_ID,
1337
1337
  globalWarmHookCompleted: { status: "n/a", details: null },
1338
+ environmentWarmHookCompleted: { status: "n/a", details: null },
1338
1339
  repositories: [],
1339
1340
  filesUploaded: [],
1340
1341
  envVarsSet: [],
@@ -1409,6 +1410,12 @@ var EnvironmentDetailsService = class {
1409
1410
  current.lastUpdatedAt = (/* @__PURE__ */ new Date()).toISOString();
1410
1411
  await writeDetails(current);
1411
1412
  }
1413
+ async setEnvironmentWarmHook(status, details) {
1414
+ const current = await readDetails();
1415
+ current.environmentWarmHookCompleted = { status, details: details ?? null };
1416
+ current.lastUpdatedAt = (/* @__PURE__ */ new Date()).toISOString();
1417
+ await writeDetails(current);
1418
+ }
1412
1419
  async setRepositoryWarmHook(repositoryName, status) {
1413
1420
  const current = await readDetails();
1414
1421
  current.repositories = upsertRepositoryStatus(current.repositories, [{
@@ -4447,6 +4454,9 @@ function sanitizeFilename2(name) {
4447
4454
  function globalFilename() {
4448
4455
  return "global.json";
4449
4456
  }
4457
+ function environmentFilename() {
4458
+ return "environment.json";
4459
+ }
4450
4460
  function repoFilename2(repoName) {
4451
4461
  return `repo-${sanitizeFilename2(repoName)}.json`;
4452
4462
  }
@@ -4466,6 +4476,16 @@ var WarmHookLogsService = class {
4466
4476
  ...entry
4467
4477
  };
4468
4478
  await writeFile9(join14(LOGS_DIR2, globalFilename()), `${JSON.stringify(log, null, 2)}
4479
+ `, "utf-8");
4480
+ }
4481
+ async saveEnvironmentHookLog(entry) {
4482
+ await this.ensureDir();
4483
+ const log = {
4484
+ hookType: "environment",
4485
+ hookName: "environment",
4486
+ ...entry
4487
+ };
4488
+ await writeFile9(join14(LOGS_DIR2, environmentFilename()), `${JSON.stringify(log, null, 2)}
4469
4489
  `, "utf-8");
4470
4490
  }
4471
4491
  async saveRepoHookLog(repoName, entry) {
@@ -4502,14 +4522,15 @@ var WarmHookLogsService = class {
4502
4522
  }
4503
4523
  logs.sort((a, b) => {
4504
4524
  if (a.hookType !== b.hookType) {
4505
- return a.hookType === "global" ? -1 : 1;
4525
+ const order = { global: 0, environment: 1, repository: 2 };
4526
+ return order[a.hookType] - order[b.hookType];
4506
4527
  }
4507
4528
  return a.hookName.localeCompare(b.hookName);
4508
4529
  });
4509
4530
  return logs;
4510
4531
  }
4511
4532
  async getFullOutput(hookType, hookName) {
4512
- const filename = hookType === "global" ? globalFilename() : repoFilename2(hookName);
4533
+ const filename = hookType === "global" ? globalFilename() : hookType === "environment" ? environmentFilename() : repoFilename2(hookName);
4513
4534
  try {
4514
4535
  const raw = await readFile10(join14(LOGS_DIR2, filename), "utf-8");
4515
4536
  const stored = JSON.parse(raw);
@@ -4599,87 +4620,109 @@ async function collectRepoWarmHooks() {
4599
4620
  }
4600
4621
  async function runWarmHooks(params) {
4601
4622
  const outputBlocks = [];
4602
- const orgHook = params.organizationWarmHook?.trim();
4603
- if (orgHook) {
4604
- const orgResult = await executeHookScript({
4605
- label: "org-warm-hook",
4623
+ const globalHook = (params.globalWarmHook ?? params.organizationWarmHook)?.trim();
4624
+ const environmentHook = params.environmentWarmHook?.trim();
4625
+ if (globalHook) {
4626
+ const globalResult = await executeHookScript({
4627
+ label: "global-warm-hook",
4606
4628
  cwd: gitService.getWorkspaceRoot(),
4607
- content: orgHook,
4629
+ content: globalHook,
4608
4630
  timeoutMs: params.timeoutMs
4609
4631
  });
4610
- outputBlocks.push(orgResult.output);
4611
- await environmentDetailsService.setGlobalWarmHook(orgResult.exitCode === 0 ? "yes" : "no", orgResult.output);
4632
+ outputBlocks.push(globalResult.output);
4633
+ await environmentDetailsService.setGlobalWarmHook(globalResult.exitCode === 0 ? "yes" : "no", globalResult.output);
4612
4634
  await warmHookLogsService.saveGlobalHookLog({
4613
- hookScript: orgHook,
4614
- output: orgResult.output,
4615
- exitCode: orgResult.exitCode,
4616
- timedOut: orgResult.timedOut,
4635
+ hookScript: globalHook,
4636
+ output: globalResult.output,
4637
+ exitCode: globalResult.exitCode,
4638
+ timedOut: globalResult.timedOut,
4617
4639
  executedAt: (/* @__PURE__ */ new Date()).toISOString()
4618
4640
  });
4619
- if (orgResult.exitCode !== 0) {
4641
+ if (globalResult.exitCode !== 0) {
4642
+ await environmentDetailsService.setEnvironmentWarmHook("n/a");
4620
4643
  return {
4621
- exitCode: orgResult.exitCode,
4644
+ exitCode: globalResult.exitCode,
4622
4645
  output: outputBlocks.join("\n\n"),
4623
- timedOut: orgResult.timedOut
4646
+ timedOut: globalResult.timedOut
4647
+ };
4648
+ }
4649
+ }
4650
+ if (environmentHook) {
4651
+ const envResult = await executeHookScript({
4652
+ label: "environment-warm-hook",
4653
+ cwd: gitService.getWorkspaceRoot(),
4654
+ content: environmentHook,
4655
+ timeoutMs: params.timeoutMs
4656
+ });
4657
+ outputBlocks.push(envResult.output);
4658
+ await environmentDetailsService.setEnvironmentWarmHook(envResult.exitCode === 0 ? "yes" : "no", envResult.output);
4659
+ await warmHookLogsService.saveEnvironmentHookLog({
4660
+ hookScript: environmentHook,
4661
+ output: envResult.output,
4662
+ exitCode: envResult.exitCode,
4663
+ timedOut: envResult.timedOut,
4664
+ executedAt: (/* @__PURE__ */ new Date()).toISOString()
4665
+ });
4666
+ if (envResult.exitCode !== 0) {
4667
+ return {
4668
+ exitCode: envResult.exitCode,
4669
+ output: outputBlocks.join("\n\n"),
4670
+ timedOut: envResult.timedOut
4624
4671
  };
4625
4672
  }
4626
4673
  } else {
4674
+ await environmentDetailsService.setEnvironmentWarmHook("n/a");
4675
+ }
4676
+ if (!globalHook) {
4627
4677
  await environmentDetailsService.setGlobalWarmHook("n/a");
4628
4678
  }
4629
- if (params.includeRepoHooks !== false) {
4630
- const repoHooks = await collectRepoWarmHooks();
4631
- const repoHookNames = new Set(repoHooks.map((repoHook) => repoHook.repoName));
4632
- const discoveredRepos = await gitService.listRepositories();
4633
- for (const repo of discoveredRepos) {
4634
- if (!repoHookNames.has(repo.name)) {
4635
- await environmentDetailsService.setRepositoryWarmHook(repo.name, "n/a");
4636
- }
4637
- }
4638
- for (const repoHook of repoHooks) {
4639
- const combinedScript = repoHook.commands.join("\n");
4640
- const repoOutputBlocks = [];
4641
- let repoFailed = false;
4642
- let repoTimedOut = false;
4643
- let repoExitCode = 0;
4644
- for (const command of repoHook.commands) {
4645
- const repoResult = await executeHookScript({
4646
- label: `repo-warm-hook:${repoHook.repoName}`,
4647
- cwd: repoHook.repoPath,
4648
- content: command,
4649
- timeoutMs: repoHook.timeoutMs
4650
- });
4651
- outputBlocks.push(repoResult.output);
4652
- repoOutputBlocks.push(repoResult.output);
4653
- await environmentDetailsService.setRepositoryWarmHook(
4654
- repoHook.repoName,
4655
- repoResult.exitCode === 0 ? "yes" : "no"
4656
- );
4657
- if (repoResult.exitCode !== 0) {
4658
- repoFailed = true;
4659
- repoTimedOut = repoResult.timedOut;
4660
- repoExitCode = repoResult.exitCode;
4661
- break;
4662
- }
4663
- }
4664
- await warmHookLogsService.saveRepoHookLog(repoHook.repoName, {
4665
- hookScript: combinedScript,
4666
- output: repoOutputBlocks.join("\n\n"),
4667
- exitCode: repoFailed ? repoExitCode : 0,
4668
- timedOut: repoTimedOut,
4669
- executedAt: (/* @__PURE__ */ new Date()).toISOString()
4679
+ const repoHooks = await collectRepoWarmHooks();
4680
+ const repoHookNames = new Set(repoHooks.map((repoHook) => repoHook.repoName));
4681
+ const discoveredRepos = await gitService.listRepositories();
4682
+ for (const repo of discoveredRepos) {
4683
+ if (!repoHookNames.has(repo.name)) {
4684
+ await environmentDetailsService.setRepositoryWarmHook(repo.name, "n/a");
4685
+ }
4686
+ }
4687
+ for (const repoHook of repoHooks) {
4688
+ const combinedScript = repoHook.commands.join("\n");
4689
+ const repoOutputBlocks = [];
4690
+ let repoFailed = false;
4691
+ let repoTimedOut = false;
4692
+ let repoExitCode = 0;
4693
+ for (const command of repoHook.commands) {
4694
+ const repoResult = await executeHookScript({
4695
+ label: `repo-warm-hook:${repoHook.repoName}`,
4696
+ cwd: repoHook.repoPath,
4697
+ content: command,
4698
+ timeoutMs: repoHook.timeoutMs
4670
4699
  });
4671
- if (repoFailed) {
4672
- return {
4673
- exitCode: repoExitCode,
4674
- output: outputBlocks.join("\n\n"),
4675
- timedOut: repoTimedOut
4676
- };
4700
+ outputBlocks.push(repoResult.output);
4701
+ repoOutputBlocks.push(repoResult.output);
4702
+ await environmentDetailsService.setRepositoryWarmHook(
4703
+ repoHook.repoName,
4704
+ repoResult.exitCode === 0 ? "yes" : "no"
4705
+ );
4706
+ if (repoResult.exitCode !== 0) {
4707
+ repoFailed = true;
4708
+ repoTimedOut = repoResult.timedOut;
4709
+ repoExitCode = repoResult.exitCode;
4710
+ break;
4677
4711
  }
4678
4712
  }
4679
- } else {
4680
- const repos = await gitService.listRepositories();
4681
- for (const repo of repos) {
4682
- await environmentDetailsService.setRepositoryWarmHook(repo.name, "n/a");
4713
+ await warmHookLogsService.saveRepoHookLog(repoHook.repoName, {
4714
+ hookScript: combinedScript,
4715
+ output: repoOutputBlocks.join("\n\n"),
4716
+ exitCode: repoFailed ? repoExitCode : 0,
4717
+ timedOut: repoTimedOut,
4718
+ executedAt: (/* @__PURE__ */ new Date()).toISOString()
4719
+ });
4720
+ if (repoFailed) {
4721
+ return {
4722
+ exitCode: repoExitCode,
4723
+ output: outputBlocks.join("\n\n"),
4724
+ timedOut: repoTimedOut
4725
+ };
4683
4726
  }
4684
4727
  }
4685
4728
  if (outputBlocks.length === 0) {
@@ -4970,8 +5013,9 @@ function createV1Routes(deps) {
4970
5013
  try {
4971
5014
  const body = await c.req.json();
4972
5015
  const result = await runWarmHooks({
5016
+ globalWarmHook: body.globalWarmHook,
5017
+ environmentWarmHook: body.environmentWarmHook,
4973
5018
  organizationWarmHook: body.organizationWarmHook,
4974
- includeRepoHooks: body.includeRepoHooks,
4975
5019
  timeoutMs: body.timeoutMs
4976
5020
  });
4977
5021
  return c.json({
@@ -5001,8 +5045,8 @@ function createV1Routes(deps) {
5001
5045
  try {
5002
5046
  const hookType = c.req.param("hookType");
5003
5047
  const hookName = c.req.param("hookName");
5004
- if (hookType !== "global" && hookType !== "repository") {
5005
- return c.json(jsonError("Invalid hookType", 'Must be "global" or "repository"'), 400);
5048
+ if (hookType !== "global" && hookType !== "environment" && hookType !== "repository") {
5049
+ return c.json(jsonError("Invalid hookType", 'Must be "global", "environment", or "repository"'), 400);
5006
5050
  }
5007
5051
  const output = await warmHookLogsService.getFullOutput(hookType, hookName);
5008
5052
  if (output === null) {
@@ -5355,7 +5399,9 @@ serve(
5355
5399
  if (!gitResult.success && gitResult.error) {
5356
5400
  console.warn(`Git initialization warning: ${gitResult.error}`);
5357
5401
  }
5358
- await replicasConfigService.initialize();
5402
+ if (!IS_WARMING_MODE) {
5403
+ await replicasConfigService.initialize();
5404
+ }
5359
5405
  await chatService.initialize();
5360
5406
  await previewService.initialize();
5361
5407
  engineReady = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.149",
3
+ "version": "0.1.151",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",