@scalequality/cli 0.4.32 → 0.4.34

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.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "sdkVersion": "0.3.281",
3
- "sha256": "6cc91235fd87e2125e963bb23b062d003f129ef8593d841d654846d4d6ff0552",
4
- "sourceCommit": "5570a43b32111d0ca46a5417dcd54d78283277eb"
3
+ "sha256": "b2ccc4428dd29a54024fb75482ee6279b1a58a6b4d94508501ea7a72e900ac95",
4
+ "sourceCommit": "9a236ac040cb6760f2bdd944a18f6f133383aaf8"
5
5
  }
package/dist/connect.cjs CHANGED
@@ -4425,6 +4425,24 @@ function checkpointPartsOf(raw) {
4425
4425
  var run = (0, import_util.promisify)(import_child_process.execFile);
4426
4426
  var CHECKPOINT_BASE_HEADER = "ScaleQuality-Base:";
4427
4427
  var DIFF_CAPS = { perFileBytes: 200 * 1024, totalBytes: 2 * 1024 * 1024, maxFiles: 500 };
4428
+ var DIFF_EVENT_BYTES = 448 * 1024;
4429
+ function fitDiff(files, budget = DIFF_EVENT_BYTES) {
4430
+ const bytes = (f) => Buffer.byteLength(JSON.stringify(f)) + 1;
4431
+ const sizes = files.map(bytes);
4432
+ let total = sizes.reduce((a, b) => a + b, 2);
4433
+ if (total <= budget) return files;
4434
+ const out2 = [...files];
4435
+ const largest = out2.map((_, i) => i).filter((i) => out2[i].patch).sort((a, b) => sizes[b] - sizes[a]);
4436
+ for (const i of largest) {
4437
+ const { hunks: _h, ...rest } = out2[i];
4438
+ out2[i] = { ...rest, patch: "", truncated: true };
4439
+ const size2 = bytes(out2[i]);
4440
+ total -= sizes[i] - size2;
4441
+ sizes[i] = size2;
4442
+ if (total <= budget) break;
4443
+ }
4444
+ return out2;
4445
+ }
4428
4446
  async function git(args, opts) {
4429
4447
  const { stdout } = await run("git", args, {
4430
4448
  cwd: opts.cwd,
@@ -6785,6 +6803,8 @@ var CommandDecisions = class {
6785
6803
  });
6786
6804
  }
6787
6805
  };
6806
+ var MAX_CARD_COMMAND = 1e5;
6807
+ var TOO_LONG_FOR_A_CARD = (length, max) => `This command is ${length.toLocaleString("en-US")} characters, more than the ${max.toLocaleString("en-US")} an approval card takes, so it did not run. Write long content to files with the Write tool, then run a short command that uses them.`;
6788
6808
  var CommandApprovalError = class extends Error {
6789
6809
  constructor(status, code) {
6790
6810
  super(`command approval ${status ?? "unreachable"}${code ? ` ${code}` : ""}`);
@@ -6876,6 +6896,7 @@ var BrowserCommandGate = class {
6876
6896
  }
6877
6897
  async ask(command, opts) {
6878
6898
  const protection = opts.protection;
6899
+ if (command.length > MAX_CARD_COMMAND) return { allow: false, message: TOO_LONG_FOR_A_CARD(command.length, MAX_CARD_COMMAND) };
6879
6900
  if (!opts.edit && !protection && matchingRule(command, this.allRules())) return { allow: true };
6880
6901
  if (opts.signal?.aborted) return { allow: false, message: STOPPED };
6881
6902
  let approvalId;
@@ -6893,6 +6914,7 @@ var BrowserCommandGate = class {
6893
6914
  } catch (e) {
6894
6915
  this.o.log?.(`command approval could not be requested: ${e.message}`);
6895
6916
  const code = e instanceof CommandApprovalError ? e.code : null;
6917
+ if (e instanceof CommandApprovalError && e.status === 400 && command.length > 1e4) return { allow: false, message: TOO_LONG_FOR_A_CARD(command.length, 1e4) };
6896
6918
  if (protection && opts.edit) return { allow: false, message: PROTECTION_MESSAGES.editUnavailable(opts.edit.path) };
6897
6919
  if (protection && code !== "COMMAND_NOT_ALLOWED") return { allow: false, message: PROTECTION_MESSAGES.unavailable };
6898
6920
  return {
@@ -7858,6 +7880,10 @@ var HELLO_MS = 5e3;
7858
7880
  var MAX_TABS = 8;
7859
7881
  var MAX_INPUT = 64 * 1024;
7860
7882
  var MAX_TOKENS = 64;
7883
+ var MAX_PENDING = 1024 * 1024;
7884
+ var CATCH_UP_MS = 250;
7885
+ var PING_MS = 3e4;
7886
+ var STOP_WAIT_MS = 2e3;
7861
7887
  function loadPty() {
7862
7888
  try {
7863
7889
  const mod = require("@lydell/node-pty");
@@ -7902,10 +7928,13 @@ var TerminalHost = class {
7902
7928
  server = null;
7903
7929
  wss = null;
7904
7930
  port = null;
7931
+ beat = null;
7905
7932
  tokens = /* @__PURE__ */ new Set();
7906
7933
  tabs = /* @__PURE__ */ new Map();
7907
7934
  /** When the person last typed in any tab (the cloud counts it as activity, so the machine does not idle away). */
7908
7935
  lastInputAt = 0;
7936
+ /** When a shell last wrote: a long build or test run with no typing is still the person's work in progress. */
7937
+ lastOutputAt = 0;
7909
7938
  get open() {
7910
7939
  return this.tabs.size;
7911
7940
  }
@@ -7924,6 +7953,15 @@ var TerminalHost = class {
7924
7953
  const wss = new import_websocket_server.default({ server, maxPayload: 1024 * 1024, verifyClient: (info) => this.originAllowed(info.origin) });
7925
7954
  wss.on("connection", (socket) => this.accept(socket));
7926
7955
  this.wss = wss;
7956
+ this.beat = setInterval(() => {
7957
+ for (const client of wss.clients) {
7958
+ try {
7959
+ client.ping();
7960
+ } catch {
7961
+ }
7962
+ }
7963
+ }, this.o.pingMs ?? PING_MS);
7964
+ this.beat.unref?.();
7927
7965
  await new Promise((resolve8, reject) => {
7928
7966
  server.once("error", reject);
7929
7967
  server.listen(this.o.port, this.o.bind, () => {
@@ -8031,13 +8069,19 @@ var TerminalHost = class {
8031
8069
  socket.close(4500, "start");
8032
8070
  return null;
8033
8071
  }
8034
- const tab = { id, shell, pty, buffer: "", socket, detachTimer: null };
8072
+ const tab = { id, shell, pty, buffer: "", socket, detachTimer: null, behind: null };
8035
8073
  this.tabs.set(id, tab);
8036
8074
  pty.onData((d) => {
8037
8075
  try {
8038
8076
  tab.buffer = (tab.buffer + d).slice(-MAX_BUFFER);
8077
+ this.lastOutputAt = (this.o.now ?? Date.now)();
8039
8078
  const s = tab.socket;
8040
- if (s && s.readyState === s.OPEN) s.send(JSON.stringify({ t: "out", d }));
8079
+ if (!s || s.readyState !== s.OPEN || tab.behind) return;
8080
+ if (s.bufferedAmount > MAX_PENDING) {
8081
+ this.catchUp(tab, s);
8082
+ return;
8083
+ }
8084
+ s.send(JSON.stringify({ t: "out", d }));
8041
8085
  } catch (e) {
8042
8086
  this.o.log.warn("terminal output not sent", { error: e.message });
8043
8087
  }
@@ -8058,7 +8102,30 @@ var TerminalHost = class {
8058
8102
  send({ t: "ready", tab: id, shell, replay: "" });
8059
8103
  return tab;
8060
8104
  }
8105
+ /** A socket that fell behind: once it drains, the page's screen is reset and drawn again from the tab's own screen. */
8106
+ catchUp(tab, socket) {
8107
+ const check = () => {
8108
+ tab.behind = null;
8109
+ try {
8110
+ if (tab.socket !== socket || socket.readyState !== socket.OPEN) return;
8111
+ if (socket.bufferedAmount > MAX_PENDING / 4) {
8112
+ tab.behind = setTimeout(check, CATCH_UP_MS);
8113
+ tab.behind.unref?.();
8114
+ return;
8115
+ }
8116
+ socket.send(JSON.stringify({ t: "out", d: `\x1Bc${tab.buffer}` }));
8117
+ } catch (e) {
8118
+ this.o.log.warn("terminal output not sent", { error: e.message });
8119
+ }
8120
+ };
8121
+ tab.behind = setTimeout(check, CATCH_UP_MS);
8122
+ tab.behind.unref?.();
8123
+ }
8061
8124
  detach(tab) {
8125
+ if (tab.behind) {
8126
+ clearTimeout(tab.behind);
8127
+ tab.behind = null;
8128
+ }
8062
8129
  tab.socket = null;
8063
8130
  if (tab.detachTimer) clearTimeout(tab.detachTimer);
8064
8131
  tab.detachTimer = setTimeout(() => this.end(tab.id), DETACH_MS);
@@ -8070,6 +8137,7 @@ var TerminalHost = class {
8070
8137
  if (!tab) return;
8071
8138
  this.tabs.delete(id);
8072
8139
  if (tab.detachTimer) clearTimeout(tab.detachTimer);
8140
+ if (tab.behind) clearTimeout(tab.behind);
8073
8141
  try {
8074
8142
  tab.pty.kill();
8075
8143
  } catch {
@@ -8079,13 +8147,20 @@ var TerminalHost = class {
8079
8147
  /** Ends every shell and stops listening (the engine stops). */
8080
8148
  async stop() {
8081
8149
  for (const id of [...this.tabs.keys()]) this.end(id);
8150
+ if (this.beat) {
8151
+ clearInterval(this.beat);
8152
+ this.beat = null;
8153
+ }
8082
8154
  const server = this.server, wss = this.wss;
8083
8155
  this.server = null;
8084
8156
  this.wss = null;
8085
8157
  this.port = null;
8086
8158
  for (const client of wss?.clients ?? []) client.terminate();
8087
8159
  wss?.close();
8088
- if (server) await new Promise((resolve8) => server.close(() => resolve8()));
8160
+ if (!server) return;
8161
+ const closed = new Promise((resolve8) => server.close(() => resolve8()));
8162
+ server.closeAllConnections?.();
8163
+ await Promise.race([closed, new Promise((resolve8) => setTimeout(resolve8, STOP_WAIT_MS).unref?.())]);
8089
8164
  }
8090
8165
  };
8091
8166
 
@@ -9034,6 +9109,7 @@ function chromeCandidates(env = process.env, platform2 = process.platform) {
9034
9109
  }
9035
9110
  return [...own, "/usr/bin/chromium", "/usr/bin/chromium-browser", "/usr/bin/google-chrome", "/usr/bin/google-chrome-stable", "/snap/bin/chromium"];
9036
9111
  }
9112
+ var chromeSandboxArgs = (uid = process.getuid?.()) => uid === 0 ? ["--no-sandbox"] : [];
9037
9113
  function findChrome(candidates = chromeCandidates()) {
9038
9114
  return candidates.find((path) => (0, import_fs8.existsSync)(path)) ?? null;
9039
9115
  }
@@ -9044,7 +9120,7 @@ async function screenshotPage(chrome, url, target, size2) {
9044
9120
  (0, import_child_process3.execFile)(chrome, [
9045
9121
  "--headless=new",
9046
9122
  "--disable-gpu",
9047
- "--no-sandbox",
9123
+ ...chromeSandboxArgs(),
9048
9124
  "--disable-dev-shm-usage",
9049
9125
  "--hide-scrollbars",
9050
9126
  "--no-first-run",
@@ -13208,7 +13284,7 @@ async function checkDesign(chrome, folder, manifest, opts = {}) {
13208
13284
  const base = (profile) => [
13209
13285
  "--headless=new",
13210
13286
  "--disable-gpu",
13211
- "--no-sandbox",
13287
+ ...chromeSandboxArgs(),
13212
13288
  "--disable-dev-shm-usage",
13213
13289
  "--hide-scrollbars",
13214
13290
  "--no-first-run",
@@ -13509,7 +13585,16 @@ var EventSink = class {
13509
13585
  for (let i = 0; i < batch.length; i += max) {
13510
13586
  const part = batch.slice(i, i + max);
13511
13587
  this.chain = this.chain.then(
13512
- () => this.opts.post(part).catch((err) => {
13588
+ () => this.opts.post(part).catch(async (err) => {
13589
+ if (part.length > 1 && err.status === 400) {
13590
+ for (const e of part) {
13591
+ await this.opts.post([e]).catch((one) => {
13592
+ this.dropped += 1;
13593
+ this.opts.log?.("workspace event not delivered", { type: e.type, totalDropped: this.dropped, error: one.message });
13594
+ });
13595
+ }
13596
+ return;
13597
+ }
13513
13598
  this.dropped += part.length;
13514
13599
  this.opts.log?.("workspace events not delivered", { count: part.length, totalDropped: this.dropped, error: err.message });
13515
13600
  })
@@ -13877,7 +13962,7 @@ var SdkEventMapper = class {
13877
13962
  switch (m.type) {
13878
13963
  case "system":
13879
13964
  if (m.subtype === "init") {
13880
- if (typeof m.session_id === "string") this.cb.sessionId(m.session_id);
13965
+ if (typeof m.session_id === "string" && m.session_id) this.cb.sessionId(m.session_id);
13881
13966
  if (typeof m.model === "string" && m.model) this.model = m.model;
13882
13967
  } else if (m.subtype === "compact_boundary") {
13883
13968
  const meta = m.compact_metadata ?? {};
@@ -15359,6 +15444,7 @@ ${lines2.join("\n")}
15359
15444
  var WARM_IDLE_MS = 15 * 6e4;
15360
15445
  var TERMINAL_PULSE_MS = 4 * 6e4;
15361
15446
  var TERMINAL_IDLE_MS = 20 * 6e4;
15447
+ var TERMINAL_SHARE_WAIT_MS = 3e3;
15362
15448
  var TERMINAL_LOCAL_ENV = ["SSH_AUTH_SOCK", "EDITOR", "VISUAL", "PAGER", "LC_CTYPE"];
15363
15449
  function localLoginShell() {
15364
15450
  if (process.platform === "win32") return process.env.COMSPEC || "powershell.exe";
@@ -15588,6 +15674,8 @@ var WorkspaceEngine = class {
15588
15674
  orgPlugins = { entries: [], dirs: [] };
15589
15675
  /** The conversation's name was asked for (once, on its first turn). */
15590
15676
  titled = false;
15677
+ /** The first message, named once the model has started answering it (two calls at once slowed the first answer). */
15678
+ titleWaiting = null;
15591
15679
  /** The project environment's setup, once per open repository (cloud only), and why the last one failed. */
15592
15680
  envSetups = /* @__PURE__ */ new Map();
15593
15681
  envAbort = new AbortController();
@@ -16198,14 +16286,15 @@ var WorkspaceEngine = class {
16198
16286
  if (!await acl(["-m", `u:${uid}:rwx`, "-m", `d:u:${uid}:rwX`, root])) this.deps.log.warn("terminal: the workspace folder could not be shared with its user");
16199
16287
  this.terminalShared.add(root);
16200
16288
  }
16201
- for (const name of await (0, import_promises16.readdir)(root).catch(() => [])) {
16289
+ const sweep = Promise.all((await (0, import_promises16.readdir)(root).catch(() => [])).map(async (name) => {
16202
16290
  const path = (0, import_path17.join)(root, name);
16203
- if (this.terminalShared.has(path) || own.has(path) || [...own].some((d) => d.startsWith(path + import_path17.sep))) continue;
16291
+ if (this.terminalShared.has(path) || own.has(path) || [...own].some((d) => d.startsWith(path + import_path17.sep))) return;
16204
16292
  if (await acl(["-R", "-m", `u:${uid}:rwX`, "-m", `d:u:${uid}:rwX`, path])) this.terminalShared.add(path);
16205
- }
16293
+ }));
16294
+ await Promise.race([sweep, new Promise((r) => setTimeout(r, TERMINAL_SHARE_WAIT_MS).unref?.())]);
16206
16295
  }
16207
16296
  /**
16208
- * While a terminal is open on the person's computer, or typed into in the last minutes in the cloud, the session
16297
+ * While a terminal is open on the person's computer, or typed into (or writing) in the last minutes in the cloud, the session
16209
16298
  * is in use: a small event every few minutes keeps it from going idle (the cloud machine, so it does not stop
16210
16299
  * under the person's hands; the computer, so its shells live as long as they are open).
16211
16300
  */
@@ -16214,7 +16303,7 @@ var WorkspaceEngine = class {
16214
16303
  this.terminalPulse = setInterval(() => {
16215
16304
  const t = this.terminal;
16216
16305
  if (!t || !t.open) return;
16217
- if (!this.local && Date.now() - t.lastInputAt > TERMINAL_IDLE_MS) return;
16306
+ if (!this.local && Date.now() - Math.max(t.lastInputAt, t.lastOutputAt) > TERMINAL_IDLE_MS) return;
16218
16307
  this.emit({ type: "terminal_activity", data: { open: t.open } });
16219
16308
  }, TERMINAL_PULSE_MS);
16220
16309
  this.terminalPulse.unref?.();
@@ -16233,10 +16322,12 @@ var WorkspaceEngine = class {
16233
16322
  repo2 = [...this.repos.values()][0];
16234
16323
  }
16235
16324
  const denied = this.deps.privateDirs ?? [];
16236
- const path = typeof p.path === "string" ? p.path : "";
16325
+ const bases = [repo2?.fence ?? repo2?.root ?? this.deps.root];
16326
+ const asked = typeof p.path === "string" ? p.path : "";
16327
+ const path = kind === "read_file" && p.as !== "image" ? await insideRelative(asked, bases) : asked;
16237
16328
  const range = { from: typeof p.from === "number" ? p.from : void 0, to: typeof p.to === "number" ? p.to : void 0 };
16238
16329
  if (kind === "read_file" && p.as === "image") {
16239
- const rel = await insideRelative(path, [repo2?.root ?? this.deps.root]);
16330
+ const rel = await insideRelative(path, bases);
16240
16331
  const image = await this.fencedFiles(repo2, rel, (root, r) => readImageFile(root, r, denied));
16241
16332
  const { data, ...meta } = image;
16242
16333
  await this.deps.transport.reply(commandId, { ok: true, result: { ...repoFullName ? { repoFullName } : {}, ...this.redactor.deep(meta), data } }).catch((e) => this.deps.log.warn("file request not answered", { error: e.message }));
@@ -16505,6 +16596,12 @@ ${String(item.content)}` : String(item.content);
16505
16596
  * A short name for a new conversation, from its first message: one small request to the session's fast model on
16506
16597
  * the gateway (measured like every other). Anything that fails leaves the conversation as it was.
16507
16598
  */
16599
+ /** Names the conversation from its first message now (the model answered it, or the turn ended without an answer). */
16600
+ nameNow() {
16601
+ const content = this.titleWaiting;
16602
+ this.titleWaiting = null;
16603
+ if (content !== null) void this.nameConversation(content);
16604
+ }
16508
16605
  async nameConversation(content) {
16509
16606
  const runtime = this.boot?.runtime;
16510
16607
  const model = runtime?.titleModel || runtime?.fastModel || runtime?.primaryModel || this.boot?.model;
@@ -16679,7 +16776,7 @@ ${String(item.content)}` : String(item.content);
16679
16776
  if (files === "unavailable") this.error("REWIND_FAILED", { turnId });
16680
16777
  this.emit({ type: "rewind", data: { turnId, files, conversation, ...untouched.length ? { untouched } : {} } });
16681
16778
  await this.diffNow();
16682
- await this.saveCheckpoint().catch((e) => this.deps.log.warn("checkpoint failed", { error: this.redactor.text(e.message) }));
16779
+ await this.saveCheckpoint().catch((e) => this.deps.log.warn("checkpoint failed", this.whyFailed(e)));
16683
16780
  this.setState("READY", "REWOUND");
16684
16781
  await this.sink.flush();
16685
16782
  }
@@ -16977,6 +17074,9 @@ ${json}
16977
17074
  return out2;
16978
17075
  }
16979
17076
  /** Starts the setup of each open repository that has one and did not run it yet. */
17077
+ setupToStart() {
17078
+ return [...this.repos.values()].some((repo2) => !repo2.dormant && !this.envSetups.has(repo2.root) && !!this.environmentOf(repo2)?.setupCommand);
17079
+ }
16980
17080
  startEnvSetups() {
16981
17081
  for (const repo2 of this.repos.values()) {
16982
17082
  if (repo2.dormant || this.envSetups.has(repo2.root)) continue;
@@ -17067,7 +17167,7 @@ ${json}
17067
17167
  this.toolGate = saved;
17068
17168
  if (!compact) {
17069
17169
  await this.refreshSkills();
17070
- if (!this.local) await saved;
17170
+ if (!this.local && this.setupToStart()) await saved;
17071
17171
  this.startEnvSetups();
17072
17172
  await Promise.all(this.envSetups.values());
17073
17173
  }
@@ -17080,7 +17180,7 @@ ${json}
17080
17180
  const sdk = this.sdk;
17081
17181
  if (!compact && !this.sdkSessionId && !this.titled) {
17082
17182
  this.titled = true;
17083
- void this.nameConversation(String(payload.content));
17183
+ this.titleWaiting = String(payload.content);
17084
17184
  }
17085
17185
  const primary = boot.runtime.primaryModel || (!this.deps.transport.refreshRuntime && typeof payload.model === "string" && payload.model ? payload.model : boot.model);
17086
17186
  if (isReasoningLevel(payload.reasoning)) this.reasoningLevel = effectiveReasoning(payload.reasoning, this.reasoningCapability);
@@ -17283,6 +17383,7 @@ ${text3}`;
17283
17383
  }
17284
17384
  } finally {
17285
17385
  const stopped = ac.signal.aborted || live.interrupted;
17386
+ this.nameNow();
17286
17387
  await saved;
17287
17388
  live.timing.end(this.deps.log, stopped ? "stopped" : "failed");
17288
17389
  this.live = null;
@@ -17292,7 +17393,7 @@ ${text3}`;
17292
17393
  this.turnWatch = null;
17293
17394
  this.previousTrouble = stopped || !watch ? null : watch.errored ? "follows a request that ended with an error" : watch.lastExit !== null && watch.lastExit !== 0 ? "follows a failed verification" : null;
17294
17395
  await this.diffNow();
17295
- await this.saveCheckpoint().catch((e) => this.deps.log.warn("checkpoint failed", { error: this.redactor.text(e.message) }));
17396
+ await this.saveCheckpoint().catch((e) => this.deps.log.warn("checkpoint failed", this.whyFailed(e)));
17296
17397
  await this.saveDesignVersions();
17297
17398
  this.setState("READY", stopped ? "STOPPED" : void 0);
17298
17399
  await this.sink.flush();
@@ -17306,6 +17407,7 @@ ${text3}`;
17306
17407
  }
17307
17408
  /** What a frame of the main conversation says about the turn: its model calls, foreground work, and the messages it read. */
17308
17409
  observeFrame(live, f) {
17410
+ if ((f.type === "stream_event" || f.type === "assistant") && this.titleWaiting !== null) this.nameNow();
17309
17411
  if (f.type === "stream_event") {
17310
17412
  live.timing.modelEvent();
17311
17413
  const ev = f.event ?? {};
@@ -17662,7 +17764,7 @@ ${text3}`;
17662
17764
  for (const repo2 of [...this.repos.values()]) {
17663
17765
  if (repo2.dormant) continue;
17664
17766
  try {
17665
- const files = await repo2.tracker.diff();
17767
+ const files = fitDiff(await repo2.tracker.diff());
17666
17768
  const id = repo2.repoFullName ?? repo2.localId ?? null;
17667
17769
  const key = JSON.stringify([id, files]);
17668
17770
  if (key === repo2.lastDiff) continue;
@@ -17736,6 +17838,11 @@ ${patch}`;
17736
17838
  get busy() {
17737
17839
  return !!this.turnRunning;
17738
17840
  }
17841
+ /** A failed call as the log keeps it: the API's code and status with the message, never a credential. */
17842
+ whyFailed(e) {
17843
+ const t = e;
17844
+ return { error: this.redactor.text(String(t?.message ?? e)), ...typeof t?.code === "string" ? { code: t.code } : {}, ...typeof t?.status === "number" ? { status: t.status } : {} };
17845
+ }
17739
17846
  /**
17740
17847
  * Stops the engine. A clean stop (asked by the API, the person's Ctrl+C or
17741
17848
  * the computer's service) saves the change and says PAUSED, so the session
@@ -17755,9 +17862,13 @@ ${patch}`;
17755
17862
  const running = this.turnRunning;
17756
17863
  if (running) await Promise.race([running, new Promise((r) => setTimeout(r, 2e4))]);
17757
17864
  if (opts.checkpoint) {
17758
- await this.saveCheckpoint().catch((e) => {
17759
- this.deps.log.warn("checkpoint failed", { error: this.redactor.text(e.message) });
17760
- });
17865
+ for (let attempt = 1; ; attempt++) {
17866
+ const failed2 = await this.saveCheckpoint().then(() => null, (e) => e);
17867
+ if (!failed2) break;
17868
+ this.deps.log.warn("checkpoint failed", { ...this.whyFailed(failed2), attempt });
17869
+ if (attempt >= 3 || failed2.retryable !== true) break;
17870
+ await new Promise((r) => setTimeout(r, attempt * 1e3));
17871
+ }
17761
17872
  }
17762
17873
  if (reason === "shutdown" && this.state && this.state !== "FAILED") this.setState("PAUSED", pausedCode);
17763
17874
  await this.sink.flush();
@@ -17915,8 +18026,7 @@ ${patch}`;
17915
18026
  if (!repo2) return read(this.deps.root, path);
17916
18027
  if (!repo2.fence || !repo2.prefix) return read(repo2.root, path);
17917
18028
  const clean = path.replace(/^\/+/, "").replace(/\/+$/, "");
17918
- const rel = !clean || clean === "." ? "" : clean === repo2.prefix ? "" : clean.startsWith(`${repo2.prefix}/`) ? clean.slice(repo2.prefix.length + 1) : null;
17919
- if (rel === null) throw new FileRequestError("PATH_OUTSIDE_WORKSPACE");
18029
+ const rel = !clean || clean === "." ? "" : clean === repo2.prefix ? "" : clean.startsWith(`${repo2.prefix}/`) ? clean.slice(repo2.prefix.length + 1) : clean;
17920
18030
  const r = await read(repo2.fence, rel);
17921
18031
  const back = (p) => p ? `${repo2.prefix}/${p}` : repo2.prefix;
17922
18032
  return { ...r, path: back(r.path), ...r.entries ? { entries: r.entries.map((e) => ({ ...e, path: back(e.path) })) } : {} };
@@ -17943,8 +18053,9 @@ ${patch}`;
17943
18053
  }
17944
18054
  /**
17945
18055
  * The designs this turn checked, each kept as a version (Erik, 24/10/2026: the canvas's version menu opens earlier
17946
- * ones): the files of its folder, up to 1 MB each and 3 MB in all, with what the person asked. Only with an API that
17947
- * keeps them; a version that fails to save is only logged.
18056
+ * ones): the files of its folder and of its subfolders one level down (assets/), screens first, up to 4 MB each and
18057
+ * 6 MB in all, with what the person asked. A screen over 1 MB (an inlined picture) was left out before, and then the
18058
+ * whole version failed to open. Only with an API that keeps them; a version that fails to save is only logged.
17948
18059
  */
17949
18060
  async saveDesignVersions() {
17950
18061
  const transport = this.deps.transport;
@@ -17954,10 +18065,14 @@ ${patch}`;
17954
18065
  for (const [path, folder] of checked) {
17955
18066
  const files = [];
17956
18067
  let bytes = 0;
17957
- const names = (await (0, import_promises16.readdir)(folder, { withFileTypes: true }).catch(() => [])).filter((e) => e.isFile() && /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/.test(e.name)).map((e) => e.name).sort((a, b) => Number(b === "design.json") - Number(a === "design.json") || a.localeCompare(b)).slice(0, 60);
18068
+ const NAME2 = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
18069
+ const top = await (0, import_promises16.readdir)(folder, { withFileTypes: true }).catch(() => []);
18070
+ const nested = await Promise.all(top.filter((e) => e.isDirectory() && NAME2.test(e.name)).slice(0, 10).map(async (d) => (await (0, import_promises16.readdir)((0, import_path17.join)(folder, d.name), { withFileTypes: true }).catch(() => [])).filter((e) => e.isFile() && NAME2.test(e.name)).map((e) => `${d.name}/${e.name}`)));
18071
+ const rank = (n) => n === "design.json" ? 0 : n.includes("/") ? 2 : 1;
18072
+ const names = [...top.filter((e) => e.isFile() && NAME2.test(e.name)).map((e) => e.name), ...nested.flat()].sort((a, b) => rank(a) - rank(b) || a.localeCompare(b)).slice(0, 60);
17958
18073
  for (const name of names) {
17959
18074
  const st = await (0, import_promises16.stat)((0, import_path17.join)(folder, name)).catch(() => null);
17960
- if (!st || st.size > 1024 * 1024 || bytes + st.size > 3 * 1024 * 1024) continue;
18075
+ if (!st || st.size > 4 * 1024 * 1024 || bytes + st.size > 6 * 1024 * 1024) continue;
17961
18076
  const data = await (0, import_promises16.readFile)((0, import_path17.join)(folder, name)).catch(() => null);
17962
18077
  if (!data) continue;
17963
18078
  bytes += data.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalequality/cli",
3
- "version": "0.4.32",
3
+ "version": "0.4.34",
4
4
  "description": "ScaleQuality CLI. Connect your computer to the ScaleQuality AI Workspace (`scalequality login`), run its coding engine in any folder of your computer, and import your Claude Code and Codex conversations.",
5
5
  "type": "module",
6
6
  "bin": {