@holistics/cli-core 2.5.7 → 2.5.8

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/commands.js +148 -58
  2. package/package.json +1 -1
package/dist/commands.js CHANGED
@@ -24022,7 +24022,7 @@ var require_dist4 = __commonJS((exports2) => {
24022
24022
  exports2.default = deferred;
24023
24023
  });
24024
24024
  // package.json
24025
- var version = "2.5.7";
24025
+ var version = "2.5.8";
24026
24026
 
24027
24027
  // ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/error.js
24028
24028
  class CommanderError extends Error {
@@ -155377,6 +155377,30 @@ async function releaseLock(repoPath) {
155377
155377
  async function writeState(repoPath, state) {
155378
155378
  await writeStateJson(repoPath, "state.json", state);
155379
155379
  }
155380
+ function startingState(resolvedPath, mode, projectId, startedAt, pid = process.pid) {
155381
+ return {
155382
+ mode,
155383
+ pid,
155384
+ project_id: projectId,
155385
+ repo_path: resolvedPath,
155386
+ started_at: startedAt,
155387
+ last_cycle_at: null,
155388
+ dirty_count: 0,
155389
+ last_error: null,
155390
+ conflicts: [],
155391
+ blocked: null,
155392
+ oversized: [],
155393
+ declined: null,
155394
+ pending_input: null,
155395
+ asking: null
155396
+ };
155397
+ }
155398
+ async function recordSpawned(repoPath, mode, projectId, pid) {
155399
+ const resolvedPath = path13.resolve(repoPath);
155400
+ if ((await readState(resolvedPath))?.pid === pid)
155401
+ return;
155402
+ await writeState(resolvedPath, startingState(resolvedPath, mode, projectId, new Date().toISOString(), pid));
155403
+ }
155380
155404
  async function recordPendingInput(repoPath, mode, projectId, pending) {
155381
155405
  const resolvedPath = path13.resolve(repoPath);
155382
155406
  const state = {
@@ -155570,6 +155594,9 @@ class GitRepo {
155570
155594
  };
155571
155595
  return new GitRepo(dir, { env, signal: signal2 });
155572
155596
  }
155597
+ withSignal(signal2) {
155598
+ return new GitRepo(this.repoPath, { env: this.env, signal: signal2 });
155599
+ }
155573
155600
  spawnEnv() {
155574
155601
  if (!this.env)
155575
155602
  return;
@@ -166188,6 +166215,58 @@ function startSessionLoop(runCycle, intervalMs) {
166188
166215
  };
166189
166216
  }
166190
166217
 
166218
+ // src/commands/code_sync/lib/engine/cycle_deadline.ts
166219
+ var NO_DEADLINE = { paused: (wait) => wait() };
166220
+ function formatDuration2(ms6) {
166221
+ if (ms6 >= 60000)
166222
+ return `${Math.round(ms6 / 60000)} min`;
166223
+ return `${Math.round(ms6 / 1000)} s`;
166224
+ }
166225
+ function startCycleDeadline({ timeoutMs, graceMs }, onStuck) {
166226
+ const controller = new AbortController;
166227
+ let timer = null;
166228
+ let settled = false;
166229
+ const disarm = () => {
166230
+ if (timer) {
166231
+ clearTimeout(timer);
166232
+ timer = null;
166233
+ }
166234
+ };
166235
+ const arm = () => {
166236
+ if (settled)
166237
+ return;
166238
+ if (!controller.signal.aborted) {
166239
+ timer = setTimeout(() => {
166240
+ timer = null;
166241
+ controller.abort(new Error(`The sync cycle ran for over ${formatDuration2(timeoutMs)} and was cancelled; the next one starts afresh`));
166242
+ arm();
166243
+ }, timeoutMs);
166244
+ } else {
166245
+ timer = setTimeout(() => {
166246
+ timer = null;
166247
+ settled = true;
166248
+ onStuck();
166249
+ }, graceMs);
166250
+ }
166251
+ };
166252
+ arm();
166253
+ return {
166254
+ signal: controller.signal,
166255
+ paused: async (wait) => {
166256
+ disarm();
166257
+ try {
166258
+ return await wait();
166259
+ } finally {
166260
+ arm();
166261
+ }
166262
+ },
166263
+ clear: () => {
166264
+ settled = true;
166265
+ disarm();
166266
+ }
166267
+ };
166268
+ }
166269
+
166191
166270
  // src/commands/code_sync/lib/engine/session_engine.ts
166192
166271
  var DEFAULT_SESSION_INTERVAL_MS = parseInt(process.env.CODE_SYNC_INTERVAL || "3000");
166193
166272
  function checkBranch(ctx, localBranch, cloudBranch) {
@@ -166391,9 +166470,20 @@ function rebind(ctx, branch, out) {
166391
166470
  ctx.loggedOversized = [];
166392
166471
  out(fmt.cyan(`⟲ Syncing '${branch}' from now on`));
166393
166472
  }
166473
+ function heartbeatOf(ctx, result, error) {
166474
+ return {
166475
+ last_cycle_at: new Date().toISOString(),
166476
+ conflicts: result?.conflicts ?? [],
166477
+ dirty_count: ctx.pending ?? 0,
166478
+ last_error: error,
166479
+ blocked: ctx.blocked ?? null,
166480
+ oversized: ctx.loggedOversized ?? [],
166481
+ declined: ctx.declined ?? null
166482
+ };
166483
+ }
166394
166484
  async function runSessionCycle(ctx, engine = { shutdown: () => {
166395
166485
  ctx.stopped = true;
166396
- } }) {
166486
+ } }, deadline = NO_DEADLINE) {
166397
166487
  if (ctx.stopped)
166398
166488
  return null;
166399
166489
  let result = null;
@@ -166415,7 +166505,8 @@ async function runSessionCycle(ctx, engine = { shutdown: () => {
166415
166505
  if (!ctx.onBranchInput) {
166416
166506
  fatal = branchStopMessage(check.pending, ctx.mode);
166417
166507
  } else if (!ctx.stopped) {
166418
- const resumeOn = await ctx.onBranchInput(check.pending, engine);
166508
+ const ask = ctx.onBranchInput;
166509
+ const resumeOn = await deadline.paused(() => ask(check.pending, engine));
166419
166510
  if (resumeOn === null)
166420
166511
  engine.shutdown();
166421
166512
  else if (!ctx.stopped)
@@ -166443,26 +166534,20 @@ async function runSessionCycle(ctx, engine = { shutdown: () => {
166443
166534
  }
166444
166535
  if (ctx.stopped)
166445
166536
  return result;
166446
- if (ctx.onCycle) {
166447
- await ctx.onCycle({
166448
- last_cycle_at: new Date().toISOString(),
166449
- conflicts: result?.conflicts ?? [],
166450
- dirty_count: ctx.pending ?? 0,
166451
- last_error: error,
166452
- blocked: ctx.blocked ?? null,
166453
- oversized: ctx.loggedOversized ?? [],
166454
- declined: ctx.declined ?? null
166455
- });
166456
- }
166537
+ await ctx.onCycle?.(heartbeatOf(ctx, result, error));
166457
166538
  if (fatal && !ctx.stopped) {
166458
166539
  engine.shutdown();
166459
166540
  await ctx.onFatal?.(fatal);
166460
166541
  }
166461
166542
  return result;
166462
166543
  }
166544
+ var DEFAULT_CYCLE_TIMEOUT_MS = parseInt(process.env.CODE_SYNC_CYCLE_TIMEOUT_MS || String(10 * 60000));
166545
+ var DEFAULT_CYCLE_GRACE_MS = 2 * 60000;
166463
166546
  var MAX_IMMEDIATE_ROUNDS = 3;
166464
166547
  function startSessionEngine(ctx, options2 = {}) {
166465
166548
  const intervalMs = options2.intervalMs ?? DEFAULT_SESSION_INTERVAL_MS;
166549
+ const timeoutMs = options2.cycleTimeoutMs ?? DEFAULT_CYCLE_TIMEOUT_MS;
166550
+ const graceMs = options2.cycleGraceMs ?? DEFAULT_CYCLE_GRACE_MS;
166466
166551
  let lastErrored = false;
166467
166552
  let rounds = 0;
166468
166553
  let loop = null;
@@ -166472,9 +166557,29 @@ function startSessionEngine(ctx, options2 = {}) {
166472
166557
  loop?.stop();
166473
166558
  }
166474
166559
  };
166560
+ const stuck = async () => {
166561
+ if (ctx.stopped)
166562
+ return;
166563
+ const message = withRestart(`A sync cycle ran for over ${formatDuration2(timeoutMs + graceMs)} and did not stop when cancelled, ` + "so the session has stopped.", ctx.mode ?? "foreground");
166564
+ engine.shutdown();
166565
+ logWithTime(fmt.red(`✗ ${message}`));
166566
+ await ctx.onCycle?.(heartbeatOf(ctx, null, message));
166567
+ await ctx.onFatal?.(message);
166568
+ };
166475
166569
  loop = startSessionLoop(async () => {
166476
166570
  ctx.immediateRound = rounds > 0;
166477
- const result = await runSessionCycle(ctx, engine);
166571
+ const deadline = startCycleDeadline({ timeoutMs, graceMs }, () => {
166572
+ stuck().catch((err) => logWithTime(fmt.red(`✗ Failed to stop the session: ${err?.message ?? String(err)}`)));
166573
+ });
166574
+ const sessionRepo = ctx.repo;
166575
+ ctx.repo = sessionRepo.withSignal(deadline.signal);
166576
+ let result;
166577
+ try {
166578
+ result = await runSessionCycle(ctx, engine, deadline);
166579
+ } finally {
166580
+ ctx.repo = sessionRepo;
166581
+ deadline.clear();
166582
+ }
166478
166583
  if (ctx.stopped) {
166479
166584
  loop?.stop();
166480
166585
  return;
@@ -166559,6 +166664,17 @@ import { createHash } from "crypto";
166559
166664
  import fs22 from "fs/promises";
166560
166665
  import { existsSync as existsSync2 } from "fs";
166561
166666
  import path18 from "path";
166667
+
166668
+ // src/commands/code_sync/lib/bun.ts
166669
+ var BUN_STANDALONE_ROOTS = ["/$bunfs/", "B:/~BUN/", "B:\\~BUN\\"];
166670
+ function isBunStandaloneEntry(entryPath) {
166671
+ if (!entryPath)
166672
+ return false;
166673
+ const lowerEntry = entryPath.toLowerCase();
166674
+ return BUN_STANDALONE_ROOTS.some((root2) => lowerEntry.startsWith(root2.toLowerCase()));
166675
+ }
166676
+
166677
+ // src/commands/code_sync/lib/branch_wip/hooks.ts
166562
166678
  var HOOKS_FILE = "hooks.json";
166563
166679
  var BLOCK_BEGIN = "# >>> holistics sync >>>";
166564
166680
  var BLOCK_END = "# <<< holistics sync <<<";
@@ -166568,24 +166684,20 @@ function shellQuote2(s3) {
166568
166684
  }
166569
166685
  function selfCommand() {
166570
166686
  const script = process.argv[1];
166571
- if (script && script !== process.execPath && existsSync2(script))
166687
+ if (script && script !== process.execPath && !isBunStandaloneEntry(script) && existsSync2(script)) {
166572
166688
  return [process.execPath, path18.resolve(script)];
166689
+ }
166573
166690
  return existsSync2(process.execPath) ? [process.execPath] : null;
166574
166691
  }
166575
166692
  function runCli(self2, args) {
166576
- const fallback = [
166577
- "command -v holistics >/dev/null 2>&1; then",
166693
+ const lines = [
166694
+ " if command -v holistics >/dev/null 2>&1; then",
166578
166695
  ` holistics sync ${args} || true`
166579
166696
  ];
166580
- if (!self2)
166581
- return [` if ${fallback[0]}`, fallback[1], " fi"];
166582
- return [
166583
- ` if [ -x ${shellQuote2(self2[0])} ]; then`,
166584
- ` ${self2.map(shellQuote2).join(" ")} sync ${args} || true`,
166585
- ` elif ${fallback[0]}`,
166586
- fallback[1],
166587
- " fi"
166588
- ];
166697
+ if (self2) {
166698
+ lines.push(` elif [ -x ${shellQuote2(self2[0])} ]; then`, ` ${self2.map(shellQuote2).join(" ")} sync ${args} || true`);
166699
+ }
166700
+ return [...lines, " fi"];
166589
166701
  }
166590
166702
  var HEADER = [
166591
166703
  BLOCK_BEGIN,
@@ -167014,13 +167126,6 @@ import { spawn as spawn2 } from "child_process";
167014
167126
  import fs24 from "fs";
167015
167127
  import path20 from "path";
167016
167128
  var CHILD_ENV_FLAG = "HOLISTICS_SYNC_CHILD";
167017
- var BUN_STANDALONE_ROOTS = ["/$bunfs/", "B:/~BUN/", "B:\\~BUN\\"];
167018
- function isBunStandaloneEntry(entryPath) {
167019
- if (!entryPath)
167020
- return false;
167021
- const lowerEntry = entryPath.toLowerCase();
167022
- return BUN_STANDALONE_ROOTS.some((root2) => lowerEntry.startsWith(root2.toLowerCase()));
167023
- }
167024
167129
  function buildBackgroundSpawnArgs(resolvedPath, entryPath) {
167025
167130
  const childCommand = ["sync", "start", resolvedPath];
167026
167131
  return isBunStandaloneEntry(entryPath) ? childCommand : [entryPath, ...childCommand];
@@ -167037,16 +167142,16 @@ async function spawnBackgroundSync(repoPath) {
167037
167142
  }
167038
167143
  log(fmt.bold("Holistics Code Sync"));
167039
167144
  separator();
167040
- let failure = null;
167145
+ let preflight;
167041
167146
  try {
167042
- await runSyncPreflight(resolvedPath, "background");
167147
+ preflight = await runSyncPreflight(resolvedPath, "background");
167043
167148
  } catch (error) {
167044
- failure = { error };
167149
+ preflight = { error };
167045
167150
  }
167046
167151
  await releaseLock(resolvedPath);
167047
- if (failure) {
167152
+ if ("error" in preflight) {
167048
167153
  log(fmt.red("Please fix the error, then run `holistics sync start --background` again"));
167049
- await logErr(failure.error);
167154
+ await logErr(preflight.error);
167050
167155
  process.exit(1);
167051
167156
  }
167052
167157
  const entryPath = process.argv[1];
@@ -167065,6 +167170,9 @@ async function spawnBackgroundSync(repoPath) {
167065
167170
  });
167066
167171
  child.unref();
167067
167172
  fs24.closeSync(fd3);
167173
+ if (child.pid !== undefined) {
167174
+ await recordSpawned(resolvedPath, "background", preflight.project.id, child.pid);
167175
+ }
167068
167176
  log(fmt.green(`✓ Background sync started (pid ${child.pid})`));
167069
167177
  log(fmt.dim(` Log: ${logFile}`));
167070
167178
  log(fmt.dim(" Status: holistics sync status"));
@@ -167081,24 +167189,6 @@ function claimExit(exit) {
167081
167189
  exit.exiting = true;
167082
167190
  return true;
167083
167191
  }
167084
- function startingState(resolvedPath, mode, projectId, startedAt) {
167085
- return {
167086
- mode,
167087
- pid: process.pid,
167088
- project_id: projectId,
167089
- repo_path: resolvedPath,
167090
- started_at: startedAt,
167091
- last_cycle_at: null,
167092
- dirty_count: 0,
167093
- last_error: null,
167094
- conflicts: [],
167095
- blocked: null,
167096
- oversized: [],
167097
- declined: null,
167098
- pending_input: null,
167099
- asking: null
167100
- };
167101
- }
167102
167192
  function buildHeartbeatWriter(resolvedPath, mode, projectId, clock) {
167103
167193
  return async (heartbeat) => {
167104
167194
  if (!clock.fresh && heartbeat.last_error === null)
@@ -167865,7 +167955,7 @@ See documentation at: https://docs.holistics.io/docs/cli`);
167865
167955
  command12.commands.forEach((subCommand) => addDocumentationHelp(subCommand));
167866
167956
  }
167867
167957
  function registerCommands(program3) {
167868
- program3.version(version);
167958
+ program3.name("holistics").version(version);
167869
167959
  program3.addCommand(auth_default).addCommand(dbt_default).addCommand(aml_default).addCommand(mcp_default).addCommand(query_default).addCommand(sync_default).addCommand(legacy_default, { hidden: true });
167870
167960
  addDocumentationHelp(program3);
167871
167961
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@holistics/cli-core",
3
3
  "type": "module",
4
- "version": "2.5.7",
4
+ "version": "2.5.8",
5
5
  "bin": {
6
6
  "holistics": "./bin/holistics.js"
7
7
  },