@scalequality/cli 0.4.32 → 0.4.33

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": "9df603c14a8411fc0bd67b9845763888a736d40d91718e584e5cfcc692c0aaf1",
4
+ "sourceCommit": "ef04cd0080b6e3a35119bf03ac6128cd671b0f5d"
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,9 @@ 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 STOP_WAIT_MS = 2e3;
7861
7886
  function loadPty() {
7862
7887
  try {
7863
7888
  const mod = require("@lydell/node-pty");
@@ -7906,6 +7931,8 @@ var TerminalHost = class {
7906
7931
  tabs = /* @__PURE__ */ new Map();
7907
7932
  /** When the person last typed in any tab (the cloud counts it as activity, so the machine does not idle away). */
7908
7933
  lastInputAt = 0;
7934
+ /** When a shell last wrote: a long build or test run with no typing is still the person's work in progress. */
7935
+ lastOutputAt = 0;
7909
7936
  get open() {
7910
7937
  return this.tabs.size;
7911
7938
  }
@@ -8031,13 +8058,19 @@ var TerminalHost = class {
8031
8058
  socket.close(4500, "start");
8032
8059
  return null;
8033
8060
  }
8034
- const tab = { id, shell, pty, buffer: "", socket, detachTimer: null };
8061
+ const tab = { id, shell, pty, buffer: "", socket, detachTimer: null, behind: null };
8035
8062
  this.tabs.set(id, tab);
8036
8063
  pty.onData((d) => {
8037
8064
  try {
8038
8065
  tab.buffer = (tab.buffer + d).slice(-MAX_BUFFER);
8066
+ this.lastOutputAt = (this.o.now ?? Date.now)();
8039
8067
  const s = tab.socket;
8040
- if (s && s.readyState === s.OPEN) s.send(JSON.stringify({ t: "out", d }));
8068
+ if (!s || s.readyState !== s.OPEN || tab.behind) return;
8069
+ if (s.bufferedAmount > MAX_PENDING) {
8070
+ this.catchUp(tab, s);
8071
+ return;
8072
+ }
8073
+ s.send(JSON.stringify({ t: "out", d }));
8041
8074
  } catch (e) {
8042
8075
  this.o.log.warn("terminal output not sent", { error: e.message });
8043
8076
  }
@@ -8058,7 +8091,30 @@ var TerminalHost = class {
8058
8091
  send({ t: "ready", tab: id, shell, replay: "" });
8059
8092
  return tab;
8060
8093
  }
8094
+ /** A socket that fell behind: once it drains, the page's screen is reset and drawn again from the tab's own screen. */
8095
+ catchUp(tab, socket) {
8096
+ const check = () => {
8097
+ tab.behind = null;
8098
+ try {
8099
+ if (tab.socket !== socket || socket.readyState !== socket.OPEN) return;
8100
+ if (socket.bufferedAmount > MAX_PENDING / 4) {
8101
+ tab.behind = setTimeout(check, CATCH_UP_MS);
8102
+ tab.behind.unref?.();
8103
+ return;
8104
+ }
8105
+ socket.send(JSON.stringify({ t: "out", d: `\x1Bc${tab.buffer}` }));
8106
+ } catch (e) {
8107
+ this.o.log.warn("terminal output not sent", { error: e.message });
8108
+ }
8109
+ };
8110
+ tab.behind = setTimeout(check, CATCH_UP_MS);
8111
+ tab.behind.unref?.();
8112
+ }
8061
8113
  detach(tab) {
8114
+ if (tab.behind) {
8115
+ clearTimeout(tab.behind);
8116
+ tab.behind = null;
8117
+ }
8062
8118
  tab.socket = null;
8063
8119
  if (tab.detachTimer) clearTimeout(tab.detachTimer);
8064
8120
  tab.detachTimer = setTimeout(() => this.end(tab.id), DETACH_MS);
@@ -8070,6 +8126,7 @@ var TerminalHost = class {
8070
8126
  if (!tab) return;
8071
8127
  this.tabs.delete(id);
8072
8128
  if (tab.detachTimer) clearTimeout(tab.detachTimer);
8129
+ if (tab.behind) clearTimeout(tab.behind);
8073
8130
  try {
8074
8131
  tab.pty.kill();
8075
8132
  } catch {
@@ -8085,7 +8142,10 @@ var TerminalHost = class {
8085
8142
  this.port = null;
8086
8143
  for (const client of wss?.clients ?? []) client.terminate();
8087
8144
  wss?.close();
8088
- if (server) await new Promise((resolve8) => server.close(() => resolve8()));
8145
+ if (!server) return;
8146
+ const closed = new Promise((resolve8) => server.close(() => resolve8()));
8147
+ server.closeAllConnections?.();
8148
+ await Promise.race([closed, new Promise((resolve8) => setTimeout(resolve8, STOP_WAIT_MS).unref?.())]);
8089
8149
  }
8090
8150
  };
8091
8151
 
@@ -9034,6 +9094,7 @@ function chromeCandidates(env = process.env, platform2 = process.platform) {
9034
9094
  }
9035
9095
  return [...own, "/usr/bin/chromium", "/usr/bin/chromium-browser", "/usr/bin/google-chrome", "/usr/bin/google-chrome-stable", "/snap/bin/chromium"];
9036
9096
  }
9097
+ var chromeSandboxArgs = (uid = process.getuid?.()) => uid === 0 ? ["--no-sandbox"] : [];
9037
9098
  function findChrome(candidates = chromeCandidates()) {
9038
9099
  return candidates.find((path) => (0, import_fs8.existsSync)(path)) ?? null;
9039
9100
  }
@@ -9044,7 +9105,7 @@ async function screenshotPage(chrome, url, target, size2) {
9044
9105
  (0, import_child_process3.execFile)(chrome, [
9045
9106
  "--headless=new",
9046
9107
  "--disable-gpu",
9047
- "--no-sandbox",
9108
+ ...chromeSandboxArgs(),
9048
9109
  "--disable-dev-shm-usage",
9049
9110
  "--hide-scrollbars",
9050
9111
  "--no-first-run",
@@ -13208,7 +13269,7 @@ async function checkDesign(chrome, folder, manifest, opts = {}) {
13208
13269
  const base = (profile) => [
13209
13270
  "--headless=new",
13210
13271
  "--disable-gpu",
13211
- "--no-sandbox",
13272
+ ...chromeSandboxArgs(),
13212
13273
  "--disable-dev-shm-usage",
13213
13274
  "--hide-scrollbars",
13214
13275
  "--no-first-run",
@@ -13509,7 +13570,16 @@ var EventSink = class {
13509
13570
  for (let i = 0; i < batch.length; i += max) {
13510
13571
  const part = batch.slice(i, i + max);
13511
13572
  this.chain = this.chain.then(
13512
- () => this.opts.post(part).catch((err) => {
13573
+ () => this.opts.post(part).catch(async (err) => {
13574
+ if (part.length > 1 && err.status === 400) {
13575
+ for (const e of part) {
13576
+ await this.opts.post([e]).catch((one) => {
13577
+ this.dropped += 1;
13578
+ this.opts.log?.("workspace event not delivered", { type: e.type, totalDropped: this.dropped, error: one.message });
13579
+ });
13580
+ }
13581
+ return;
13582
+ }
13513
13583
  this.dropped += part.length;
13514
13584
  this.opts.log?.("workspace events not delivered", { count: part.length, totalDropped: this.dropped, error: err.message });
13515
13585
  })
@@ -13877,7 +13947,7 @@ var SdkEventMapper = class {
13877
13947
  switch (m.type) {
13878
13948
  case "system":
13879
13949
  if (m.subtype === "init") {
13880
- if (typeof m.session_id === "string") this.cb.sessionId(m.session_id);
13950
+ if (typeof m.session_id === "string" && m.session_id) this.cb.sessionId(m.session_id);
13881
13951
  if (typeof m.model === "string" && m.model) this.model = m.model;
13882
13952
  } else if (m.subtype === "compact_boundary") {
13883
13953
  const meta = m.compact_metadata ?? {};
@@ -15359,6 +15429,7 @@ ${lines2.join("\n")}
15359
15429
  var WARM_IDLE_MS = 15 * 6e4;
15360
15430
  var TERMINAL_PULSE_MS = 4 * 6e4;
15361
15431
  var TERMINAL_IDLE_MS = 20 * 6e4;
15432
+ var TERMINAL_SHARE_WAIT_MS = 3e3;
15362
15433
  var TERMINAL_LOCAL_ENV = ["SSH_AUTH_SOCK", "EDITOR", "VISUAL", "PAGER", "LC_CTYPE"];
15363
15434
  function localLoginShell() {
15364
15435
  if (process.platform === "win32") return process.env.COMSPEC || "powershell.exe";
@@ -15588,6 +15659,8 @@ var WorkspaceEngine = class {
15588
15659
  orgPlugins = { entries: [], dirs: [] };
15589
15660
  /** The conversation's name was asked for (once, on its first turn). */
15590
15661
  titled = false;
15662
+ /** The first message, named once the model has started answering it (two calls at once slowed the first answer). */
15663
+ titleWaiting = null;
15591
15664
  /** The project environment's setup, once per open repository (cloud only), and why the last one failed. */
15592
15665
  envSetups = /* @__PURE__ */ new Map();
15593
15666
  envAbort = new AbortController();
@@ -16198,14 +16271,15 @@ var WorkspaceEngine = class {
16198
16271
  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
16272
  this.terminalShared.add(root);
16200
16273
  }
16201
- for (const name of await (0, import_promises16.readdir)(root).catch(() => [])) {
16274
+ const sweep = Promise.all((await (0, import_promises16.readdir)(root).catch(() => [])).map(async (name) => {
16202
16275
  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;
16276
+ if (this.terminalShared.has(path) || own.has(path) || [...own].some((d) => d.startsWith(path + import_path17.sep))) return;
16204
16277
  if (await acl(["-R", "-m", `u:${uid}:rwX`, "-m", `d:u:${uid}:rwX`, path])) this.terminalShared.add(path);
16205
- }
16278
+ }));
16279
+ await Promise.race([sweep, new Promise((r) => setTimeout(r, TERMINAL_SHARE_WAIT_MS).unref?.())]);
16206
16280
  }
16207
16281
  /**
16208
- * While a terminal is open on the person's computer, or typed into in the last minutes in the cloud, the session
16282
+ * 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
16283
  * is in use: a small event every few minutes keeps it from going idle (the cloud machine, so it does not stop
16210
16284
  * under the person's hands; the computer, so its shells live as long as they are open).
16211
16285
  */
@@ -16214,7 +16288,7 @@ var WorkspaceEngine = class {
16214
16288
  this.terminalPulse = setInterval(() => {
16215
16289
  const t = this.terminal;
16216
16290
  if (!t || !t.open) return;
16217
- if (!this.local && Date.now() - t.lastInputAt > TERMINAL_IDLE_MS) return;
16291
+ if (!this.local && Date.now() - Math.max(t.lastInputAt, t.lastOutputAt) > TERMINAL_IDLE_MS) return;
16218
16292
  this.emit({ type: "terminal_activity", data: { open: t.open } });
16219
16293
  }, TERMINAL_PULSE_MS);
16220
16294
  this.terminalPulse.unref?.();
@@ -16233,10 +16307,12 @@ var WorkspaceEngine = class {
16233
16307
  repo2 = [...this.repos.values()][0];
16234
16308
  }
16235
16309
  const denied = this.deps.privateDirs ?? [];
16236
- const path = typeof p.path === "string" ? p.path : "";
16310
+ const bases = [repo2?.fence ?? repo2?.root ?? this.deps.root];
16311
+ const asked = typeof p.path === "string" ? p.path : "";
16312
+ const path = kind === "read_file" && p.as !== "image" ? await insideRelative(asked, bases) : asked;
16237
16313
  const range = { from: typeof p.from === "number" ? p.from : void 0, to: typeof p.to === "number" ? p.to : void 0 };
16238
16314
  if (kind === "read_file" && p.as === "image") {
16239
- const rel = await insideRelative(path, [repo2?.root ?? this.deps.root]);
16315
+ const rel = await insideRelative(path, bases);
16240
16316
  const image = await this.fencedFiles(repo2, rel, (root, r) => readImageFile(root, r, denied));
16241
16317
  const { data, ...meta } = image;
16242
16318
  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 +16581,12 @@ ${String(item.content)}` : String(item.content);
16505
16581
  * A short name for a new conversation, from its first message: one small request to the session's fast model on
16506
16582
  * the gateway (measured like every other). Anything that fails leaves the conversation as it was.
16507
16583
  */
16584
+ /** Names the conversation from its first message now (the model answered it, or the turn ended without an answer). */
16585
+ nameNow() {
16586
+ const content = this.titleWaiting;
16587
+ this.titleWaiting = null;
16588
+ if (content !== null) void this.nameConversation(content);
16589
+ }
16508
16590
  async nameConversation(content) {
16509
16591
  const runtime = this.boot?.runtime;
16510
16592
  const model = runtime?.titleModel || runtime?.fastModel || runtime?.primaryModel || this.boot?.model;
@@ -16679,7 +16761,7 @@ ${String(item.content)}` : String(item.content);
16679
16761
  if (files === "unavailable") this.error("REWIND_FAILED", { turnId });
16680
16762
  this.emit({ type: "rewind", data: { turnId, files, conversation, ...untouched.length ? { untouched } : {} } });
16681
16763
  await this.diffNow();
16682
- await this.saveCheckpoint().catch((e) => this.deps.log.warn("checkpoint failed", { error: this.redactor.text(e.message) }));
16764
+ await this.saveCheckpoint().catch((e) => this.deps.log.warn("checkpoint failed", this.whyFailed(e)));
16683
16765
  this.setState("READY", "REWOUND");
16684
16766
  await this.sink.flush();
16685
16767
  }
@@ -16977,6 +17059,9 @@ ${json}
16977
17059
  return out2;
16978
17060
  }
16979
17061
  /** Starts the setup of each open repository that has one and did not run it yet. */
17062
+ setupToStart() {
17063
+ return [...this.repos.values()].some((repo2) => !repo2.dormant && !this.envSetups.has(repo2.root) && !!this.environmentOf(repo2)?.setupCommand);
17064
+ }
16980
17065
  startEnvSetups() {
16981
17066
  for (const repo2 of this.repos.values()) {
16982
17067
  if (repo2.dormant || this.envSetups.has(repo2.root)) continue;
@@ -17067,7 +17152,7 @@ ${json}
17067
17152
  this.toolGate = saved;
17068
17153
  if (!compact) {
17069
17154
  await this.refreshSkills();
17070
- if (!this.local) await saved;
17155
+ if (!this.local && this.setupToStart()) await saved;
17071
17156
  this.startEnvSetups();
17072
17157
  await Promise.all(this.envSetups.values());
17073
17158
  }
@@ -17080,7 +17165,7 @@ ${json}
17080
17165
  const sdk = this.sdk;
17081
17166
  if (!compact && !this.sdkSessionId && !this.titled) {
17082
17167
  this.titled = true;
17083
- void this.nameConversation(String(payload.content));
17168
+ this.titleWaiting = String(payload.content);
17084
17169
  }
17085
17170
  const primary = boot.runtime.primaryModel || (!this.deps.transport.refreshRuntime && typeof payload.model === "string" && payload.model ? payload.model : boot.model);
17086
17171
  if (isReasoningLevel(payload.reasoning)) this.reasoningLevel = effectiveReasoning(payload.reasoning, this.reasoningCapability);
@@ -17283,6 +17368,7 @@ ${text3}`;
17283
17368
  }
17284
17369
  } finally {
17285
17370
  const stopped = ac.signal.aborted || live.interrupted;
17371
+ this.nameNow();
17286
17372
  await saved;
17287
17373
  live.timing.end(this.deps.log, stopped ? "stopped" : "failed");
17288
17374
  this.live = null;
@@ -17292,7 +17378,7 @@ ${text3}`;
17292
17378
  this.turnWatch = null;
17293
17379
  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
17380
  await this.diffNow();
17295
- await this.saveCheckpoint().catch((e) => this.deps.log.warn("checkpoint failed", { error: this.redactor.text(e.message) }));
17381
+ await this.saveCheckpoint().catch((e) => this.deps.log.warn("checkpoint failed", this.whyFailed(e)));
17296
17382
  await this.saveDesignVersions();
17297
17383
  this.setState("READY", stopped ? "STOPPED" : void 0);
17298
17384
  await this.sink.flush();
@@ -17306,6 +17392,7 @@ ${text3}`;
17306
17392
  }
17307
17393
  /** What a frame of the main conversation says about the turn: its model calls, foreground work, and the messages it read. */
17308
17394
  observeFrame(live, f) {
17395
+ if ((f.type === "stream_event" || f.type === "assistant") && this.titleWaiting !== null) this.nameNow();
17309
17396
  if (f.type === "stream_event") {
17310
17397
  live.timing.modelEvent();
17311
17398
  const ev = f.event ?? {};
@@ -17662,7 +17749,7 @@ ${text3}`;
17662
17749
  for (const repo2 of [...this.repos.values()]) {
17663
17750
  if (repo2.dormant) continue;
17664
17751
  try {
17665
- const files = await repo2.tracker.diff();
17752
+ const files = fitDiff(await repo2.tracker.diff());
17666
17753
  const id = repo2.repoFullName ?? repo2.localId ?? null;
17667
17754
  const key = JSON.stringify([id, files]);
17668
17755
  if (key === repo2.lastDiff) continue;
@@ -17736,6 +17823,11 @@ ${patch}`;
17736
17823
  get busy() {
17737
17824
  return !!this.turnRunning;
17738
17825
  }
17826
+ /** A failed call as the log keeps it: the API's code and status with the message, never a credential. */
17827
+ whyFailed(e) {
17828
+ const t = e;
17829
+ return { error: this.redactor.text(String(t?.message ?? e)), ...typeof t?.code === "string" ? { code: t.code } : {}, ...typeof t?.status === "number" ? { status: t.status } : {} };
17830
+ }
17739
17831
  /**
17740
17832
  * Stops the engine. A clean stop (asked by the API, the person's Ctrl+C or
17741
17833
  * the computer's service) saves the change and says PAUSED, so the session
@@ -17755,9 +17847,13 @@ ${patch}`;
17755
17847
  const running = this.turnRunning;
17756
17848
  if (running) await Promise.race([running, new Promise((r) => setTimeout(r, 2e4))]);
17757
17849
  if (opts.checkpoint) {
17758
- await this.saveCheckpoint().catch((e) => {
17759
- this.deps.log.warn("checkpoint failed", { error: this.redactor.text(e.message) });
17760
- });
17850
+ for (let attempt = 1; ; attempt++) {
17851
+ const failed2 = await this.saveCheckpoint().then(() => null, (e) => e);
17852
+ if (!failed2) break;
17853
+ this.deps.log.warn("checkpoint failed", { ...this.whyFailed(failed2), attempt });
17854
+ if (attempt >= 3 || failed2.retryable !== true) break;
17855
+ await new Promise((r) => setTimeout(r, attempt * 1e3));
17856
+ }
17761
17857
  }
17762
17858
  if (reason === "shutdown" && this.state && this.state !== "FAILED") this.setState("PAUSED", pausedCode);
17763
17859
  await this.sink.flush();
@@ -17915,8 +18011,7 @@ ${patch}`;
17915
18011
  if (!repo2) return read(this.deps.root, path);
17916
18012
  if (!repo2.fence || !repo2.prefix) return read(repo2.root, path);
17917
18013
  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");
18014
+ const rel = !clean || clean === "." ? "" : clean === repo2.prefix ? "" : clean.startsWith(`${repo2.prefix}/`) ? clean.slice(repo2.prefix.length + 1) : clean;
17920
18015
  const r = await read(repo2.fence, rel);
17921
18016
  const back = (p) => p ? `${repo2.prefix}/${p}` : repo2.prefix;
17922
18017
  return { ...r, path: back(r.path), ...r.entries ? { entries: r.entries.map((e) => ({ ...e, path: back(e.path) })) } : {} };
@@ -17943,8 +18038,9 @@ ${patch}`;
17943
18038
  }
17944
18039
  /**
17945
18040
  * 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.
18041
+ * ones): the files of its folder and of its subfolders one level down (assets/), screens first, up to 4 MB each and
18042
+ * 6 MB in all, with what the person asked. A screen over 1 MB (an inlined picture) was left out before, and then the
18043
+ * whole version failed to open. Only with an API that keeps them; a version that fails to save is only logged.
17948
18044
  */
17949
18045
  async saveDesignVersions() {
17950
18046
  const transport = this.deps.transport;
@@ -17954,10 +18050,14 @@ ${patch}`;
17954
18050
  for (const [path, folder] of checked) {
17955
18051
  const files = [];
17956
18052
  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);
18053
+ const NAME2 = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
18054
+ const top = await (0, import_promises16.readdir)(folder, { withFileTypes: true }).catch(() => []);
18055
+ 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}`)));
18056
+ const rank = (n) => n === "design.json" ? 0 : n.includes("/") ? 2 : 1;
18057
+ 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
18058
  for (const name of names) {
17959
18059
  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;
18060
+ if (!st || st.size > 4 * 1024 * 1024 || bytes + st.size > 6 * 1024 * 1024) continue;
17961
18061
  const data = await (0, import_promises16.readFile)((0, import_path17.join)(folder, name)).catch(() => null);
17962
18062
  if (!data) continue;
17963
18063
  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.33",
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": {