@alori/cli 0.1.5 → 0.1.6

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/lib/sync.mjs +40 -5
  2. package/package.json +1 -1
package/lib/sync.mjs CHANGED
@@ -276,6 +276,20 @@ const stageWords = {
276
276
  preview: "Updating the preview",
277
277
  };
278
278
 
279
+ /** How often a long stage says it's still going. */
280
+ const stillEveryMs = 15_000;
281
+
282
+ function secondsSince(start) {
283
+ const seconds = Math.round((Date.now() - start) / 1000);
284
+ return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${String(seconds % 60).padStart(2, "0")}s`;
285
+ }
286
+
287
+ function sizeOf(bytes) {
288
+ if (bytes < 1024) return `${bytes} B`;
289
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
290
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
291
+ }
292
+
279
293
  export async function push(dir, message) {
280
294
  const state = readState(dir);
281
295
  if (!state) fail("This folder wasn't pulled from Alori. Run: alori pull <folder>");
@@ -290,8 +304,13 @@ export async function push(dir, message) {
290
304
  return;
291
305
  }
292
306
  const files = changed.map((path) => ({ path, content: readFileSync(join(dir, path), "utf8") }));
293
- console.log(`Sending ${changed.length} changed and ${deleted.length} removed file${changed.length + deleted.length === 1 ? "" : "s"}…`);
294
- const sent = await call("/code/push", { method: "POST", body: { baseVersion: state.version, message: message ?? "", files, deletedPaths: deleted } });
307
+ const started = Date.now();
308
+ const body = { baseVersion: state.version, message: message ?? "", files, deletedPaths: deleted };
309
+ console.log(`${me.app}: pushing on top of version ${state.version}${message ? ` — "${message}"` : ""}`);
310
+ for (const file of files) console.log(` ${state.hashes[file.path] ? "changed" : "new "} ${file.path} (${sizeOf(Buffer.byteLength(file.content))})`);
311
+ for (const path of deleted) console.log(` removed ${path}`);
312
+ console.log(`Sending ${changed.length} changed and ${deleted.length} removed file${changed.length + deleted.length === 1 ? "" : "s"} (${sizeOf(Buffer.byteLength(JSON.stringify(body)))})…`);
313
+ const sent = await call("/code/push", { method: "POST", body });
295
314
  if (!sent.ok) {
296
315
  const error = sent.body?.error;
297
316
  if (error === "conflicts") fail(`Someone saved changes to these files since your pull:\n${sent.body.paths.map((path) => ` ${path}`).join("\n")}\nRun alori pull, merge, then push again.`);
@@ -303,18 +322,33 @@ export async function push(dir, message) {
303
322
  failOn(sent);
304
323
  }
305
324
  const pushId = sent.body.pushId;
325
+ console.log(`Sent in ${secondsSince(started)}. Alori is building it (push ${pushId}).`);
306
326
  let shown = "";
327
+ let shownAt = Date.now();
328
+ let nudgedAt = Date.now();
329
+ /** Closes the stage on screen with how long it took. */
330
+ const endStage = () => {
331
+ if (shown) console.log(` ✓ ${shown} (${secondsSince(shownAt)})`);
332
+ };
307
333
  for (;;) {
308
334
  await sleep(2000);
309
335
  const answer = await call(`/code/push?id=${encodeURIComponent(pushId)}`);
310
336
  if (!answer.ok) failOn(answer);
311
337
  const pushed = answer.body;
312
338
  // A push deploys from its first moment; the build machine names a stage once it takes the job.
313
- const line = pushed.stage ? (stageWords[pushed.stage] ?? "Building") : "Waiting for a build machine";
314
- if (line !== shown && (pushed.status === "queued" || pushed.status === "deploying")) {
339
+ const line = pushed.stage ? (stageWords[pushed.stage] ?? `Building (${pushed.stage})`) : "Waiting for a build machine";
340
+ const building = pushed.status === "queued" || pushed.status === "deploying";
341
+ if (building && line !== shown) {
342
+ endStage();
315
343
  console.log(`${line}…`);
316
344
  shown = line;
345
+ shownAt = nudgedAt = Date.now();
346
+ } else if (building && Date.now() - nudgedAt >= stillEveryMs) {
347
+ // Some stages take minutes: say it's still going, so a quiet terminal never looks stuck.
348
+ console.log(` …still ${line.charAt(0).toLowerCase()}${line.slice(1)} (${secondsSince(shownAt)}, ${secondsSince(started)} in all)`);
349
+ nudgedAt = Date.now();
317
350
  }
351
+ if (!building) endStage();
318
352
  if (pushed.status === "saved") {
319
353
  // The snapshot moves to what was just saved: only what was sent counts as Alori's now.
320
354
  const hashes = { ...state.hashes };
@@ -322,10 +356,11 @@ export async function push(dir, message) {
322
356
  for (const path of deleted) delete hashes[path];
323
357
  // Others saved too between the pull and this save: this folder lacks their changes, so the next push pulls first.
324
358
  writeState(dir, { ...state, version: pushed.version, hashes, ...(pushed.behind ? { needsPull: true } : {}) });
325
- console.log(`Saved as version ${pushed.version}. It's in the preview: publish it in Alori when you're ready.`);
359
+ console.log(`Saved as version ${pushed.version} in ${secondsSince(started)}. It's in the preview: publish it in Alori when you're ready.`);
326
360
  if (pushed.behind) console.log("Someone else saved changes since your pull too. Run alori pull to bring them here.");
327
361
  return;
328
362
  }
363
+ if (pushed.status === "refused" || pushed.status === "failed") console.log(`Stopped after ${secondsSince(started)}.`);
329
364
  if (pushed.status === "refused") fail(`Someone saved changes to the same files while this built: ${pushed.conflicts.join(", ")}\nNothing was saved. Run alori pull, merge, then push again.`);
330
365
  if (pushed.status === "failed") fail(`The build failed, so nothing was saved:\n${pushed.error ?? ""}`);
331
366
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alori/cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Build your Alori app with your own Claude Code: pull its code, change it, push it back.",
5
5
  "type": "module",
6
6
  "bin": {