@ai-ecoverse/slicc-kernel 1.196.51 → 1.196.53

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.
@@ -5338,7 +5338,7 @@ function satisfies(version, range2) {
5338
5338
  }
5339
5339
 
5340
5340
  // src/version.ts
5341
- var KERNEL_VERSION = true ? "1.196.51" : "0.0.0-dev";
5341
+ var KERNEL_VERSION = true ? "1.196.53" : "0.0.0-dev";
5342
5342
  var OS_RELEASE = "6.0.0-slicc";
5343
5343
  function procVersion() {
5344
5344
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -19087,6 +19087,21 @@ var SealedBroker = class {
19087
19087
  }
19088
19088
  };
19089
19089
 
19090
+ // src/sudo-argv.ts
19091
+ var SUDO_VECTOR_MAX = 4096;
19092
+ var SUDO_INPUT_BYTES = 1024 * 1024;
19093
+ function budgetAfterArgs(args) {
19094
+ if (!Array.isArray(args)) return void 0;
19095
+ let remaining = args.length > SUDO_VECTOR_MAX ? -1 : SUDO_INPUT_BYTES;
19096
+ for (const word of args) {
19097
+ if (typeof word !== "string") return void 0;
19098
+ if (word.includes("\0")) return "nul";
19099
+ if (remaining >= 0)
19100
+ remaining = word.length + 1 > remaining ? -1 : remaining - storedSize(word) - 1;
19101
+ }
19102
+ return remaining;
19103
+ }
19104
+
19090
19105
  // src/sudo-files.ts
19091
19106
  var HEADER_BYTES = 256;
19092
19107
  async function fingerprint(bytes) {
@@ -19322,6 +19337,8 @@ var PLAIN = /^[A-Za-z0-9_@%+=:,./-]+$/;
19322
19337
  var CONTROL2 = /[\p{Cc}\u2028\u2029]/u;
19323
19338
  var CONTROLS = /[\p{Cc}\u2028\u2029]/gu;
19324
19339
  var SHOWN_MAX = 60;
19340
+ var DISPLAY_BYTES = 4096;
19341
+ var encoder9 = new TextEncoder();
19325
19342
  var KERNEL_SYNTAX = "[NOPASSWD] <user|%group|ALL> [(<target>)] [Cwd <dir>] [Stdin none] [ChainSha256 <sha256>] [RouteSha256 <sha256>] [Sha256 none|<file>=<sha256>\u2026] Cmnd <command\u2026|*>";
19326
19343
  var SUDOERS_SYNTAX = "<user|%group|ALL> ALL=[(<target>[,<target>\u2026])] [NOPASSWD:] <command\u2026|ALL>";
19327
19344
  var EXPECTED = `expected '${KERNEL_SYNTAX}' or '${SUDOERS_SYNTAX}'`;
@@ -19372,6 +19389,36 @@ function shellQuote(word) {
19372
19389
  function quoteWord(word) {
19373
19390
  return shellQuote(hasControl2(word) ? withoutControl(word) : word);
19374
19391
  }
19392
+ function clip(text, bytes, marker = "\u2026") {
19393
+ const { read } = encoder9.encodeInto(text, new Uint8Array(bytes - encoder9.encode(marker).length));
19394
+ return text.slice(0, read) + marker;
19395
+ }
19396
+ function limitText(text, bytes) {
19397
+ return encoder9.encode(text.slice(0, bytes + 1)).length > bytes ? clip(text, bytes) : text;
19398
+ }
19399
+ function auditField(value2, bytes = 256) {
19400
+ return limitText(quoteWord(value2.slice(0, bytes + 1)), bytes);
19401
+ }
19402
+ async function commandDisplay(prefix, argv, suffix = "", fullArgv = argv) {
19403
+ const before = limitText(prefix, 2048);
19404
+ const after = limitText(suffix, 512);
19405
+ const limit = DISPLAY_BYTES - encoder9.encode(before + after).length;
19406
+ let room = limit;
19407
+ let text = "";
19408
+ for (const [i, arg] of argv.entries()) {
19409
+ const part = (i ? " " : "") + quoteWord(arg.slice(0, room + 1));
19410
+ room -= encoder9.encode(part).length;
19411
+ if (room < 0) {
19412
+ const marker = `\u2026 [sha256=${await argvDigest(fullArgv)}]`;
19413
+ return before + clip(text + part, limit, marker) + after;
19414
+ }
19415
+ text += part;
19416
+ }
19417
+ return before + text + after;
19418
+ }
19419
+ function wordDisplay(argv, suffix) {
19420
+ return commandDisplay("sudo: ", argv.slice(0, 1), suffix, argv);
19421
+ }
19375
19422
  function addPart(word, part) {
19376
19423
  const last = word.length - 1;
19377
19424
  if (part === null) {
@@ -20303,11 +20350,14 @@ function stdinMatches(rule2, stdin) {
20303
20350
  function recordable(cwd, argv) {
20304
20351
  return !hasControl2(cwd) && !argv.some(hasControl2);
20305
20352
  }
20306
- function changedText(word) {
20307
- return `sudo: ${quoteWord(word)} changed since it was approved`;
20353
+ function changedText(argv) {
20354
+ return wordDisplay(argv, " changed since it was approved");
20355
+ }
20356
+ function requestedText(argv, hint = "") {
20357
+ return wordDisplay(argv, " changed since it was requested" + hint);
20308
20358
  }
20309
- function requestedText(word) {
20310
- return `sudo: ${quoteWord(word)} changed since it was requested`;
20359
+ function auditPrefix(user, tty, cwd, target, kind) {
20360
+ return `sudo: ${auditField(user)} : TTY=${auditField(tty)} ; PWD=${auditField(cwd, 768)} ; USER=${auditField(target)} ; ${kind} ; COMMAND=`;
20311
20361
  }
20312
20362
  function changedFile(approved, now) {
20313
20363
  const files = /* @__PURE__ */ new Set([...Object.keys(approved), ...Object.keys(now)]);
@@ -20345,16 +20395,15 @@ function stampOf(files) {
20345
20395
  }
20346
20396
  var REPLAY_ID = /^[!-~]{1,256}$/;
20347
20397
  var REPLAY_TAGS_MAX = 64;
20348
- var REPLAY_ARGV_MAX = 4096;
20349
20398
  var REPLAY_BYTES_MAX = 1024 * 1024;
20350
20399
  var NOT_A_REQUEST = "sudo: that isn't a sudo request this kernel can run";
20351
20400
  function strings2(value2, max) {
20352
20401
  return Array.isArray(value2) && value2.length <= max && value2.every((s) => typeof s === "string");
20353
20402
  }
20354
20403
  function words(value2) {
20355
- if (!strings2(value2, REPLAY_ARGV_MAX) || value2.length === 0) return false;
20356
- const bytes = value2.reduce((n, s) => n + s.length + 1, 0);
20357
- return bytes <= REPLAY_BYTES_MAX && !value2.some((s) => s.includes("\0"));
20404
+ if (!Array.isArray(value2) || value2.length === 0 || value2.length > SUDO_VECTOR_MAX) return false;
20405
+ const remaining = budgetAfterArgs(value2);
20406
+ return typeof remaining === "number" && remaining >= 0;
20358
20407
  }
20359
20408
  var FACT_OVERHEAD = 66;
20360
20409
  function factsFit(files) {
@@ -20849,8 +20898,9 @@ var Sudo = class {
20849
20898
  const st = await fs.stat(path);
20850
20899
  return st.isFile && (st.mode & 73) !== 0 ? path : void 0;
20851
20900
  }
20852
- async locate(word, cwd, reads, target) {
20901
+ async locate(argv, cwd, reads, target) {
20853
20902
  const fs = this.o.planFs?.(reads) ?? this.o.fs;
20903
+ const [word = ""] = argv;
20854
20904
  const candidates = word.includes("/") ? [askedPath(cwd, word)] : SECURE_PATH.split(":").map((dir) => `${dir}/${word}`);
20855
20905
  const cred = credOf(target);
20856
20906
  let denial;
@@ -20860,9 +20910,10 @@ var Sudo = class {
20860
20910
  if (path !== void 0) return { path, asked };
20861
20911
  } catch (err) {
20862
20912
  const code = err.code;
20863
- if (code === "EACCES") denial = failed2(code, `sudo: ${word}: Permission denied`);
20913
+ if (code === "EACCES")
20914
+ denial = failed2(code, await wordDisplay(argv, ": Permission denied"));
20864
20915
  else if (code === "ELOOP")
20865
- return failed2(code, `sudo: ${word}: Too many levels of symbolic links`);
20916
+ return failed2(code, await wordDisplay(argv, ": Too many levels of symbolic links"));
20866
20917
  }
20867
20918
  }
20868
20919
  return denial;
@@ -20933,12 +20984,16 @@ ${SCRIPT_HELP}
20933
20984
  const target = await this.lookup(r.target);
20934
20985
  if (!target) return failed2("ENOENT", `sudo: unknown user ${r.target}`);
20935
20986
  const cred = credOf(self);
20936
- const [word = "", ...args] = r.argv;
20987
+ const args = r.argv.slice(1);
20937
20988
  const argv = [r.path, ...args];
20938
20989
  const rules = await this.replayRules(self, target, r, argv);
20939
- const denied2 = () => failed2(
20990
+ const denied2 = async () => failed2(
20940
20991
  "EACCES",
20941
- `sudo: ${self.name} may no longer ask to run ${r.argv.map(quoteWord).join(" ")} as ${target.name}`
20992
+ await commandDisplay(
20993
+ `sudo: ${self.name} may no longer ask to run `,
20994
+ r.argv,
20995
+ ` as ${target.name}`
20996
+ )
20942
20997
  );
20943
20998
  if (rules?.length === 0) return denied2();
20944
20999
  if (await this.canonical(r.cwd) !== r.cwd) {
@@ -20951,23 +21006,23 @@ ${SCRIPT_HELP}
20951
21006
  );
20952
21007
  }
20953
21008
  const reads = this.reads();
20954
- const located = await this.locate(word, r.cwd, reads, target);
21009
+ const located = await this.locate(r.argv, r.cwd, reads, target);
20955
21010
  if (located && "error" in located) return located;
20956
21011
  if (!located) {
20957
21012
  const gone = await this.missingBacking(r.bound, r.path);
20958
- return gone ? failed2("EPERM", requestedText(word)) : failed2("ENOENT", `sudo: ${word}: command not found`);
21013
+ return gone ? failed2("EPERM", await requestedText(r.argv)) : failed2("ENOENT", await wordDisplay(r.argv, ": command not found"));
20959
21014
  }
20960
21015
  const { path, asked } = located;
20961
- if (path !== r.path) return failed2("EPERM", requestedText(word));
21016
+ if (path !== r.path) return failed2("EPERM", await requestedText(r.argv));
20962
21017
  const bound3 = await this.bound(path, r.cwd, asked, void 0, reads);
20963
- if (!bound3) return failed2("EPERM", requestedText(word));
21018
+ if (!bound3) return failed2("EPERM", await requestedText(r.argv));
20964
21019
  const changed2 = changedDecision(r.bound, r, bound3, path);
20965
21020
  if (changed2 !== void 0) {
20966
21021
  const missing7 = ["chainSha256", "routeSha256"].filter(
20967
21022
  (key) => bound3[key] !== void 0 && r[key] === void 0
20968
21023
  );
20969
21024
  const hint = missing7.length && changedFile(r.bound, bound3.hashes) === void 0 ? `; the saved request lacks ${missing7.join(" and ")}; pass back the whole request from approve unchanged` : "";
20970
- return failed2("EPERM", requestedText(word) + hint);
21025
+ return failed2("EPERM", await requestedText(r.argv, hint));
20971
21026
  }
20972
21027
  if (bound3.writableEnvPath && rules && !rules.some((rule2) => pinned(rule2, bound3.hashes, bound3)))
20973
21028
  return denied2();
@@ -20987,7 +21042,10 @@ ${SCRIPT_HELP}
20987
21042
  asked
20988
21043
  );
20989
21044
  (this.o.warn ?? console.warn)(
20990
- `sudo: ${self.name} : TTY=unknown ; PWD=${quoteWord(r.cwd)} ; USER=${target.name} ; REPLAY=${r.id} ; COMMAND=${argv.map(quoteWord).join(" ")}`
21045
+ await commandDisplay(
21046
+ auditPrefix(self.name, "unknown", r.cwd, target.name, `REPLAY=${auditField(r.id)}`),
21047
+ argv
21048
+ )
20991
21049
  );
20992
21050
  return { grant, caller: self, target, tags: r.tags };
20993
21051
  }
@@ -21003,10 +21061,14 @@ ${SCRIPT_HELP}
21003
21061
  async command(s, root, mine, call) {
21004
21062
  const { caller, self, target, parsed: parsed3 } = s;
21005
21063
  const { cred } = caller;
21006
- const [word = "", ...args] = parsed3.command;
21007
- const notAllowed = () => failed2(
21064
+ const args = parsed3.command.slice(1);
21065
+ const notAllowed = async () => failed2(
21008
21066
  "EPERM",
21009
- `sudo: ${self.name} is not allowed to run ${parsed3.command.map(quoteWord).join(" ")} as ${target.name}`
21067
+ await commandDisplay(
21068
+ `sudo: ${self.name} is not allowed to run `,
21069
+ parsed3.command,
21070
+ ` as ${target.name}`
21071
+ )
21010
21072
  );
21011
21073
  if (!root && mine.length === 0) return notAllowed();
21012
21074
  const cwd = await this.canonical(call.cwd, cred);
@@ -21017,10 +21079,11 @@ ${SCRIPT_HELP}
21017
21079
  );
21018
21080
  }
21019
21081
  const reads = this.reads();
21020
- const located = await this.locate(word, cwd, reads, target);
21082
+ const located = await this.locate(parsed3.command, cwd, reads, target);
21021
21083
  if (located && "error" in located) return located;
21022
21084
  const bound3 = located && await this.bound(located.path, cwd, located.asked, caller.pid, reads);
21023
- if (!located || !bound3) return failed2("ENOENT", `sudo: ${word}: command not found`);
21085
+ if (!located || !bound3)
21086
+ return failed2("ENOENT", await wordDisplay(parsed3.command, ": command not found"));
21024
21087
  const { path, asked } = located;
21025
21088
  const argv = [path, ...args];
21026
21089
  const applicable = mine.filter(
@@ -21032,7 +21095,7 @@ ${SCRIPT_HELP}
21032
21095
  if (matching.length === 0) return notAllowed();
21033
21096
  if (!parsed3.reset && this.timestamps.current(s.owner, s.policy, stampOf(bound3))) {
21034
21097
  this.timestamps.stamp(s.owner, s.policy, stampOf(bound3));
21035
- this.logged(s, cwd, argv);
21098
+ await this.logged(s, cwd, argv);
21036
21099
  return grant();
21037
21100
  }
21038
21101
  if (parsed3.nonInteractive) return failed2("EPERM", "sudo: a password is required");
@@ -21053,11 +21116,11 @@ ${SCRIPT_HELP}
21053
21116
  if (await this.canonical(call.cwd, cred) !== cwd || !await this.reachable(cred, cwd)) {
21054
21117
  return failed2("EACCES", `sudo: ${call.cwd} changed while the request waited`);
21055
21118
  }
21056
- if (await this.moved(bound3)) return failed2("EPERM", changedText(word));
21119
+ if (await this.moved(bound3)) return failed2("EPERM", await changedText(parsed3.command));
21057
21120
  if (answer2.answer === "once" && !answer2.person) return grant();
21058
21121
  const now = await this.bound(path, cwd, asked, caller.pid);
21059
21122
  if (!now || changedDecision(bound3.hashes, bound3, now, path) !== void 0)
21060
- return failed2("EPERM", changedText(word));
21123
+ return failed2("EPERM", await changedText(parsed3.command));
21061
21124
  const shown2 = recordable(cwd, [...parsed3.command, ...Object.keys(bound3.hashes)]);
21062
21125
  const result = answer2.answer === "once" ? grant() : await this.always(
21063
21126
  self,
@@ -21103,13 +21166,12 @@ ${SCRIPT_HELP}
21103
21166
  stamped(s, answer2, bound3 = {}) {
21104
21167
  if (answer2.person && !s.parsed.reset) this.timestamps.stamp(s.owner, s.policy, bound3);
21105
21168
  }
21106
- logged(s, cwd, argv) {
21169
+ async logged(s, cwd, argv) {
21107
21170
  const { caller, self, target, owner, policy } = s;
21108
21171
  const type = policy.type === "tty" && !owner.terminal ? "ppid" : policy.type;
21109
21172
  const tty = owner.terminal?.tty ?? caller.tty ?? "unknown";
21110
- const command = argv.map(quoteWord).join(" ");
21111
21173
  (this.o.warn ?? console.warn)(
21112
- `sudo: ${self.name} : TTY=${tty} ; PWD=${quoteWord(cwd)} ; USER=${target.name} ; TIMESTAMP=${type} ; COMMAND=${command}`
21174
+ await commandDisplay(auditPrefix(self.name, tty, cwd, target.name, `TIMESTAMP=${type}`), argv)
21113
21175
  );
21114
21176
  }
21115
21177
  async always(self, target, line, shown2, grant) {
@@ -24995,10 +25057,10 @@ var ANY_PLACEHOLDER = /fnox_proxy_[0-9a-f]{24}/g;
24995
25057
  var REQUEST_LINE2 = /^([!#$%&'*+.^_`|~0-9A-Za-z-]+) ([\x21-\x7e]+) HTTP\/1\.[01]$/;
24996
25058
  var HEADER_LINE = /^([!#$%&'*+.^_`|~0-9A-Za-z-]+):[ \t]*(.*?)[ \t]*$/;
24997
25059
  var BASIC2 = /^(Basic[ \t]+)([A-Za-z0-9+/]+={0,2})$/i;
24998
- var encoder9 = new TextEncoder();
25060
+ var encoder10 = new TextEncoder();
24999
25061
  function binary(text) {
25000
25062
  let out = "";
25001
- for (const b of encoder9.encode(text)) out += String.fromCharCode(b);
25063
+ for (const b of encoder10.encode(text)) out += String.fromCharCode(b);
25002
25064
  return out;
25003
25065
  }
25004
25066
  function sniffHttp1(start2) {
@@ -25042,7 +25104,7 @@ function replaced(text, values) {
25042
25104
  function usable2(values) {
25043
25105
  const out = {};
25044
25106
  for (const [ph, value2] of Object.entries(values ?? {}))
25045
- if (encoder9.encode(value2).length >= MIN_VALUE) out[ph] = value2;
25107
+ if (encoder10.encode(value2).length >= MIN_VALUE) out[ph] = value2;
25046
25108
  return out;
25047
25109
  }
25048
25110
  async function substituteHead(head, ask) {
@@ -25106,7 +25168,7 @@ function prepFails(prepared) {
25106
25168
  }
25107
25169
 
25108
25170
  // src/kernel/net/sealed-scram.ts
25109
- var encoder10 = new TextEncoder();
25171
+ var encoder11 = new TextEncoder();
25110
25172
  function base64Bytes(text) {
25111
25173
  try {
25112
25174
  return Uint8Array.from(atob(text), (c) => c.charCodeAt(0));
@@ -25178,7 +25240,7 @@ async function hmac(key, data) {
25178
25240
  return new Uint8Array(await crypto.subtle.sign("HMAC", k, data));
25179
25241
  }
25180
25242
  async function scramKeys(password, x) {
25181
- const base = await crypto.subtle.importKey("raw", encoder10.encode(password), "PBKDF2", false, [
25243
+ const base = await crypto.subtle.importKey("raw", encoder11.encode(password), "PBKDF2", false, [
25182
25244
  "deriveBits"
25183
25245
  ]);
25184
25246
  const salted = new Uint8Array(
@@ -25193,14 +25255,14 @@ async function scramKeys(password, x) {
25193
25255
  256
25194
25256
  )
25195
25257
  );
25196
- const clientKey = await hmac(salted, encoder10.encode("Client Key"));
25258
+ const clientKey = await hmac(salted, encoder11.encode("Client Key"));
25197
25259
  const stored = new Uint8Array(
25198
25260
  await crypto.subtle.digest("SHA-256", clientKey)
25199
25261
  );
25200
- const auth = encoder10.encode(`${x.clientFirstBare},${x.serverFirst},${x.clientFinalBare}`);
25262
+ const auth = encoder11.encode(`${x.clientFirstBare},${x.serverFirst},${x.clientFinalBare}`);
25201
25263
  const signature = await hmac(stored, auth);
25202
25264
  const proof = clientKey.map((b, i) => b ^ signature[i]);
25203
- const serverKey = await hmac(salted, encoder10.encode("Server Key"));
25265
+ const serverKey = await hmac(salted, encoder11.encode("Server Key"));
25204
25266
  const serverSignature = await hmac(serverKey, auth);
25205
25267
  for (const k of [salted, clientKey, stored, signature, serverKey]) k.fill(0);
25206
25268
  return { proof, serverSignature };
@@ -28700,20 +28762,6 @@ var PATH_FLAGS = PATH_ONLY | 65536 | 131072;
28700
28762
  var KEYBOARD = /* @__PURE__ */ new Set([SIG.INT, SIG.QUIT, SIG.TSTP]);
28701
28763
  var STUCK_ESCAPES = /* @__PURE__ */ new Set([SIG.INT, SIG.TERM, SIG.QUIT, SIG.HUP]);
28702
28764
  var DEFAULT_UMASK2 = 18;
28703
- var SUDO_VECTOR_MAX = 4096;
28704
- var SUDO_INPUT_BYTES = 1024 * 1024;
28705
- function budgetAfterArgs(args) {
28706
- if (!Array.isArray(args)) throw new KernelError("EINVAL");
28707
- if (args.length > SUDO_VECTOR_MAX) return -1;
28708
- let remaining = SUDO_INPUT_BYTES;
28709
- for (const word of args) {
28710
- if (typeof word !== "string") throw new KernelError("EINVAL");
28711
- if (word.length + 1 > remaining) return -1;
28712
- remaining -= storedSize(word) + 1;
28713
- if (remaining < 0) return -1;
28714
- }
28715
- return remaining;
28716
- }
28717
28765
  function sudoVariables(value2, term, budget) {
28718
28766
  const input = typeof value2 === "object" && value2 !== null ? value2 : {};
28719
28767
  const env = /* @__PURE__ */ Object.create(null);
@@ -30802,6 +30850,9 @@ var WasmProcess = class _WasmProcess {
30802
30850
  const { sudo } = this.options;
30803
30851
  if (!sudo) throw new KernelError("ENOSYS");
30804
30852
  const budget = budgetAfterArgs(req.args);
30853
+ if (budget === "nul")
30854
+ return { errno: "EINVAL", error: "sudo: an argument contains a NUL character" };
30855
+ if (budget === void 0) throw new KernelError("EINVAL");
30805
30856
  if (budget < 0) return { errno: "E2BIG", error: "sudo: the submitted arguments are too large" };
30806
30857
  const term = typeof req.term === "string" ? req.term : void 0;
30807
30858
  const submitted = sudoVariables(req.env, term, budget);
@@ -30835,8 +30886,7 @@ var WasmProcess = class _WasmProcess {
30835
30886
  })
30836
30887
  };
30837
30888
  } catch (err) {
30838
- if (err instanceof ChangedError)
30839
- return { error: changedText(argv[0] ?? asked), errno: err.code };
30889
+ if (err instanceof ChangedError) return { error: await changedText(argv), errno: err.code };
30840
30890
  throw err;
30841
30891
  }
30842
30892
  }
@@ -36385,7 +36435,7 @@ var OpfsFs = class {
36385
36435
  if (!missing5(err)) throw err;
36386
36436
  });
36387
36437
  }
36388
- async commitPrivateCopy(from, to, root, intent, copies, emptyBackup) {
36438
+ async commitPrivateCopy(from, to, root, intent, copies, emptyBackup, lock) {
36389
36439
  const { ino, ...owner } = root;
36390
36440
  const entries = await this.meta.get([from, to]);
36391
36441
  let mark = entries[0];
@@ -36398,7 +36448,7 @@ var OpfsFs = class {
36398
36448
  mark
36399
36449
  );
36400
36450
  }
36401
- if (!emptyBackup) await this.releaseSource(intent, from, to, mark.ino);
36451
+ if (!emptyBackup) await this.releaseSource(intent, from, to, mark.ino, lock);
36402
36452
  this.movePending(from, to);
36403
36453
  await this.restamp(to, copies);
36404
36454
  this.changed(from, to);
@@ -36490,13 +36540,18 @@ var OpfsFs = class {
36490
36540
  if (signal) await this.locks.request(key, { signal }, remove);
36491
36541
  else await this.locks.request(key, remove);
36492
36542
  }
36493
- async duplicate(handle, parent, name2, copies, rest2) {
36494
- if (handle.kind === "file") return this.copyBytes(handle, parent, name2, { copies }, rest2);
36495
- await copies.manifest?.record(await copiedEntry(handle, rest2));
36543
+ async duplicate(handle, parent, name2, copies, rest2, vacantOnly = false) {
36544
+ if (handle.kind === "file")
36545
+ return this.copyBytes(handle, parent, name2, { copies, vacantOnly }, rest2);
36546
+ if (vacantOnly && await this.handleExists(parent, name2)) throw fsError("EEXIST", name2);
36496
36547
  const dir = await this.io(parent.getDirectoryHandle(name2, { create: true }));
36497
36548
  this.others++;
36549
+ await this.duplicateContents(handle, dir, copies, rest2, vacantOnly);
36550
+ }
36551
+ async duplicateContents(handle, dir, copies, rest2, vacantOnly = false) {
36552
+ await copies.manifest?.record(await copiedEntry(handle, rest2));
36498
36553
  for await (const child2 of handle.values())
36499
- await this.duplicate(child2, dir, child2.name, copies, rest2 + "/" + child2.name);
36554
+ await this.duplicate(child2, dir, child2.name, copies, rest2 + "/" + child2.name, vacantOnly);
36500
36555
  }
36501
36556
  hiddenBackups = /* @__PURE__ */ new Set();
36502
36557
  pendingSources = /* @__PURE__ */ new Map();
@@ -36638,6 +36693,49 @@ var OpfsFs = class {
36638
36693
  }
36639
36694
  await this.dropSwapIntent(intent, backup);
36640
36695
  }
36696
+ async vacantLegacyGeneration(from, to, generation) {
36697
+ const [mark, ...parents2] = await (this.meta.fresh ?? this.meta.get).call(this.meta, [
36698
+ from,
36699
+ ...prefixes(parentOf11(to))
36700
+ ]);
36701
+ return mark?.vacated === true && mark.ino === generation && !mark.copyCommit && !parents2.some((p) => p?.vacated || p?.link !== void 0) && (await this.meta.under(to)).length === 0;
36702
+ }
36703
+ async resumeVacantLegacy(intent, rename, generation) {
36704
+ const { from, to, root } = rename;
36705
+ const stage = /^\..+\.[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
36706
+ if (!root || rename.replace || stage.test(baseOf4(from)) || stage.test(baseOf4(to))) return false;
36707
+ const source = await this.swapEntry(from), parent = await this.swapEntry(parentOf11(to));
36708
+ if (source?.kind !== "directory" || parent?.kind !== "directory") return false;
36709
+ const name2 = baseOf4(to);
36710
+ const target = await this.locked(to, async () => {
36711
+ if (!await this.vacantLegacyGeneration(from, to, generation) || await this.handleExists(parent, name2))
36712
+ return void 0;
36713
+ return parent.getDirectoryHandle(name2, { create: true });
36714
+ });
36715
+ if (!target) return false;
36716
+ for await (const _ of target.keys()) return false;
36717
+ const copies = new Copies(this.meta, intent);
36718
+ await this.meta.remove([manifestRoot(intent)]);
36719
+ try {
36720
+ await this.duplicateContents(source, target, copies, "", true);
36721
+ } catch (err) {
36722
+ if (err.code === "EEXIST") return false;
36723
+ throw err;
36724
+ }
36725
+ await copies.manifest?.flush();
36726
+ if (!await this.vacantLegacyGeneration(from, to, generation) || (await this.root.resolve(source))?.join("/") !== from.slice(1) || (await this.root.resolve(target))?.join("/") !== to.slice(1))
36727
+ return false;
36728
+ await this.commitPrivateCopy(
36729
+ from,
36730
+ to,
36731
+ { ...root, ino: generation },
36732
+ intent,
36733
+ copies,
36734
+ void 0,
36735
+ rename.lock
36736
+ );
36737
+ return true;
36738
+ }
36641
36739
  async resumeCopiedTree(intent, rename) {
36642
36740
  const { from, to, root } = rename;
36643
36741
  const [mark, placed] = await this.meta.get([from, to]);
@@ -36646,16 +36744,16 @@ var OpfsFs = class {
36646
36744
  return this.releaseSource(intent, from, commit.to, mark.ino, rename.lock);
36647
36745
  }
36648
36746
  if (mark?.vacated && mark.ino !== void 0 && mark.ino !== root?.ino) {
36649
- if (!mark.copyCommit)
36650
- return this.releaseSource(
36651
- intent,
36652
- from,
36653
- to,
36654
- mark.ino,
36655
- rename.lock,
36656
- !root || placed?.ino !== root.ino
36657
- );
36658
- return this.retireIntent(intent);
36747
+ if (mark.copyCommit) return this.retireIntent(intent);
36748
+ if (!placed && await this.resumeVacantLegacy(intent, rename, mark.ino)) return;
36749
+ return this.releaseSource(
36750
+ intent,
36751
+ from,
36752
+ to,
36753
+ mark.ino,
36754
+ rename.lock,
36755
+ !root || placed?.ino !== root.ino
36756
+ );
36659
36757
  }
36660
36758
  const left = await this.real(from);
36661
36759
  await this.meta.remove([manifestRoot(intent)]);
@@ -36922,6 +37020,7 @@ var OpfsFs = class {
36922
37020
  async copyBytes(handle, dir, name2, options, rest2) {
36923
37021
  const file = await this.io(handle.getFile());
36924
37022
  await options.copies?.manifest?.record(await copiedEntry(handle, rest2, file));
37023
+ if (options.vacantOnly && await this.handleExists(dir, name2)) throw fsError("EEXIST", name2);
36925
37024
  const made2 = await this.io(dir.getFileHandle(name2, { create: true }));
36926
37025
  const writable3 = await this.io(made2.createWritable());
36927
37026
  try {
@@ -39221,7 +39320,7 @@ var LAYOUT = [
39221
39320
  var IN_TREE = /* @__PURE__ */ new Set([SUDO_PATH, VISUDO_PATH, CRONTAB_PATH, SEALED_BIN]);
39222
39321
  var LOAD_SAMPLE_MS = 5e3;
39223
39322
  var LOAD_WINDOWS_MS = [6e4, 3e5, 9e5];
39224
- var encoder11 = new TextEncoder();
39323
+ var encoder12 = new TextEncoder();
39225
39324
  var USERS_MODES = ["off", "report", "enforce"];
39226
39325
  function usersMode(mode = "off") {
39227
39326
  if (USERS_MODES.includes(mode)) return mode;
@@ -43048,7 +43147,7 @@ var Launcher = class {
43048
43147
  account,
43049
43148
  options.session
43050
43149
  );
43051
- const report = (message3) => options.onData(encoder11.encode(`${message3}\r
43150
+ const report = (message3) => options.onData(encoder12.encode(`${message3}\r
43052
43151
  `));
43053
43152
  const handle = await this.launch(planned, {
43054
43153
  ...reserved2,
@@ -43096,7 +43195,7 @@ var Launcher = class {
43096
43195
  };
43097
43196
  const stdout = collect3(out, options.onStdout);
43098
43197
  const stderr = collect3(err, options.onStderr);
43099
- const report = (message3) => stderr(encoder11.encode(`${message3}
43198
+ const report = (message3) => stderr(encoder12.encode(`${message3}
43100
43199
  `));
43101
43200
  if (!planned) {
43102
43201
  const directory2 = !missingFile && await this.directory(file, this.fs.resolvePath(cwd, file));
@@ -43137,21 +43236,20 @@ var Launcher = class {
43137
43236
  this.resetCatalogs();
43138
43237
  const req = { file: grant.file, argv: grant.argv, env: grant.env, cwd: grant.cwd };
43139
43238
  const ctx = { ppid: 0, cred: grant.cred, scope: "", grant };
43140
- const word = grant.argv[0] ?? grant.asked;
43141
- const requested = (err2) => {
43142
- if (err2 instanceof ChangedError) throw sudoFailure(err2.code, requestedText(word));
43239
+ const requested = async (err2) => {
43240
+ if (err2 instanceof ChangedError) throw sudoFailure(err2.code, await requestedText(grant.argv));
43143
43241
  throw err2;
43144
43242
  };
43145
- const planned = await this.planOne(req, ctx).catch((err2) => {
43146
- if (err2 instanceof ChangedError) requested(err2);
43243
+ const planned = await this.planOne(req, ctx).catch(async (err2) => {
43244
+ if (err2 instanceof ChangedError) return requested(err2);
43147
43245
  const code = sudoCause(err2);
43148
- if (code === "ENOENT") throw sudoFailure(code, `sudo: ${quoteWord(word)}: command not found`);
43149
- throw sudoFailure(code, `sudo: ${quoteWord(word)}: ${ERRNO_TEXT[code] ?? code}`);
43246
+ const reason = code === "ENOENT" ? "command not found" : ERRNO_TEXT[code] ?? code;
43247
+ throw sudoFailure(code, await wordDisplay(grant.argv, ": " + reason));
43150
43248
  });
43151
43249
  const pin = await this.unchanged(planned, grant.file, grant.cwd, grant).catch(requested);
43152
43250
  const fds = await this.sudoOutputs(options, caller, this.stackFor(tags, tagged.tagBase));
43153
43251
  const err = fds.get(2).file;
43154
- const report = (message3) => void Promise.resolve(err.write?.(encoder11.encode(`${message3}
43252
+ const report = (message3) => void Promise.resolve(err.write?.(encoder12.encode(`${message3}
43155
43253
  `))).catch(() => void 0);
43156
43254
  const replan = () => this.planOne(req, ctx);
43157
43255
  const recheck = this.approvedChain(planned, grant.file, grant.cwd, grant);
@@ -46777,7 +46875,7 @@ function dialStream(port, onClose) {
46777
46875
 
46778
46876
  // src/client/loopback-fetch.ts
46779
46877
  var OWN_HEADERS2 = /* @__PURE__ */ new Set(["host", "connection", "content-length", "transfer-encoding"]);
46780
- var encoder12 = new TextEncoder();
46878
+ var encoder13 = new TextEncoder();
46781
46879
  var latin13 = new TextDecoder("latin1");
46782
46880
  var ByteSource = class {
46783
46881
  buffered = new Uint8Array(0);
@@ -46795,7 +46893,7 @@ var ByteSource = class {
46795
46893
  return true;
46796
46894
  }
46797
46895
  async until(marker) {
46798
- const needle = encoder12.encode(marker);
46896
+ const needle = encoder13.encode(marker);
46799
46897
  for (; ; ) {
46800
46898
  const at = indexOf(this.buffered, needle);
46801
46899
  if (at >= 0) return this.take(at + needle.length);
@@ -46903,7 +47001,7 @@ async function requestBytes(request2) {
46903
47001
  });
46904
47002
  if (body) lines3.push(`Content-Length: ${body.length}`);
46905
47003
  lines3.push("Connection: close", "", "");
46906
- const head = encoder12.encode(lines3.join("\r\n"));
47004
+ const head = encoder13.encode(lines3.join("\r\n"));
46907
47005
  const out = new Uint8Array(head.length + (body?.length ?? 0));
46908
47006
  out.set(head);
46909
47007
  if (body) out.set(body, head.length);
@@ -46957,8 +47055,8 @@ var KernelCallError = class extends Error {
46957
47055
  this.code = code;
46958
47056
  }
46959
47057
  };
46960
- var encoder13 = new TextEncoder();
46961
- var bytesOf6 = (data) => typeof data === "string" ? encoder13.encode(data) : data;
47058
+ var encoder14 = new TextEncoder();
47059
+ var bytesOf6 = (data) => typeof data === "string" ? encoder14.encode(data) : data;
46962
47060
  var UNAVAILABLE = {
46963
47061
  manualRedirects: false,
46964
47062
  encodedBodies: false,
@@ -48256,7 +48354,7 @@ function shellFor(client2, driver, options, mountPoint) {
48256
48354
  }
48257
48355
  };
48258
48356
  async function start2(run2, input) {
48259
- const encoder14 = new TextEncoder();
48357
+ const encoder15 = new TextEncoder();
48260
48358
  driver.invalidate();
48261
48359
  try {
48262
48360
  run2.process = await client2.spawn([...shell, input.source], {
@@ -48270,7 +48368,7 @@ function shellFor(client2, driver, options, mountPoint) {
48270
48368
  });
48271
48369
  } catch (err) {
48272
48370
  const code = err.code;
48273
- run2.output("stderr", encoder14.encode(`${err instanceof Error ? err.message : String(err)}
48371
+ run2.output("stderr", encoder15.encode(`${err instanceof Error ? err.message : String(err)}
48274
48372
  `));
48275
48373
  run2.exit(code === "ENOENT" ? 127 : 126);
48276
48374
  return;
@@ -48294,7 +48392,7 @@ function shellFor(client2, driver, options, mountPoint) {
48294
48392
  async (err) => {
48295
48393
  run2.output(
48296
48394
  "stderr",
48297
- encoder14.encode(`${err instanceof Error ? err.message : String(err)}
48395
+ encoder15.encode(`${err instanceof Error ? err.message : String(err)}
48298
48396
  `)
48299
48397
  );
48300
48398
  run2.exit(-1);