@ai-ecoverse/slicc-kernel 1.196.2 → 1.196.4

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.
@@ -9215,7 +9215,7 @@ var init_version = __esm({
9215
9215
  "src/version.ts"() {
9216
9216
  "use strict";
9217
9217
  init_captured_globals();
9218
- KERNEL_VERSION = true ? "1.196.2" : "0.0.0-dev";
9218
+ KERNEL_VERSION = true ? "1.196.4" : "0.0.0-dev";
9219
9219
  OS_RELEASE = "6.0.0-slicc";
9220
9220
  }
9221
9221
  });
@@ -9214,7 +9214,7 @@ var init_version = __esm({
9214
9214
  "src/version.ts"() {
9215
9215
  "use strict";
9216
9216
  init_captured_globals();
9217
- KERNEL_VERSION = true ? "1.196.2" : "0.0.0-dev";
9217
+ KERNEL_VERSION = true ? "1.196.4" : "0.0.0-dev";
9218
9218
  OS_RELEASE = "6.0.0-slicc";
9219
9219
  }
9220
9220
  });
package/dist/node.js CHANGED
@@ -7732,7 +7732,7 @@ function satisfies(version, range2) {
7732
7732
  }
7733
7733
 
7734
7734
  // src/version.ts
7735
- var KERNEL_VERSION = true ? "1.196.2" : "0.0.0-dev";
7735
+ var KERNEL_VERSION = true ? "1.196.4" : "0.0.0-dev";
7736
7736
  var OS_RELEASE = "6.0.0-slicc";
7737
7737
  function procVersion() {
7738
7738
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -8059,8 +8059,20 @@ function winners(tier) {
8059
8059
  }
8060
8060
  return out;
8061
8061
  }
8062
- async function scanCommands(fs, modules, binsFrom = Number.POSITIVE_INFINITY, kernel = KERNEL_VERSION, refused5, global = /* @__PURE__ */ new Set()) {
8062
+ function providerInputs(inputs, tier, global) {
8063
+ for (const { pkg, name: name2, commands } of tier) {
8064
+ const root = pkg.slice(0, -(name2.length + 1));
8065
+ for (const command of commands) {
8066
+ const paths = inputs.get(command.name) ?? /* @__PURE__ */ new Set();
8067
+ paths.add(`${pkg}/package.json`);
8068
+ if (global.has(root)) paths.add(`${root.slice(0, root.lastIndexOf("/"))}/package.json`);
8069
+ inputs.set(command.name, paths);
8070
+ }
8071
+ }
8072
+ }
8073
+ async function scanCommands(fs, modules, binsFrom = Number.POSITIVE_INFINITY, kernel = KERNEL_VERSION, refused5, global = /* @__PURE__ */ new Set(), provenance = false) {
8063
8074
  const found = /* @__PURE__ */ new Map();
8075
+ const inputs = /* @__PURE__ */ new Map();
8064
8076
  const physical2 = physicalResolver(fs);
8065
8077
  const tiers = (typeof modules === "string" ? [modules] : modules).map(
8066
8078
  (tier) => typeof tier === "string" ? [tier] : tier
@@ -8073,11 +8085,20 @@ async function scanCommands(fs, modules, binsFrom = Number.POSITIVE_INFINITY, ke
8073
8085
  const dependencies = [];
8074
8086
  for (const [index2, roots] of tiers.entries()) {
8075
8087
  const tier = await tierPackages(fs, physical2, roots, index2 >= binsFrom, kernel, global);
8088
+ if (provenance) providerInputs(inputs, tier, global);
8076
8089
  if (refused5) refused5.push(...tier.flatMap((entry) => entry.commands.filter((c) => c.refused)));
8077
8090
  await take(tier.filter((entry) => !entry.dependency));
8078
8091
  dependencies.push(tier.filter((entry) => entry.dependency));
8079
8092
  }
8080
8093
  for (const tier of dependencies) await take(tier);
8094
+ if (provenance) {
8095
+ const shared2 = /* @__PURE__ */ new Map();
8096
+ for (const command of [...found.values(), ...refused5 ?? []]) {
8097
+ const paths = shared2.get(command.name) ?? [...inputs.get(command.name)];
8098
+ shared2.set(command.name, paths);
8099
+ command.manifests = paths;
8100
+ }
8101
+ }
8081
8102
  if (!found.has("sh") && found.has("bash")) {
8082
8103
  found.set("sh", { ...found.get("bash"), name: "sh", argv0: "sh" });
8083
8104
  }
@@ -8141,7 +8162,7 @@ function binfmtEntry(pkg, key, value2) {
8141
8162
  return { name: key, pkg, command: value2, preserveArgv0: false };
8142
8163
  }
8143
8164
  async function scanBinfmts(fs, modules, warn = () => {
8144
- }) {
8165
+ }, declarations) {
8145
8166
  const found = /* @__PURE__ */ new Map();
8146
8167
  for (const pkg of await packagesIn(fs, modules)) {
8147
8168
  let manifest;
@@ -8155,6 +8176,7 @@ async function scanBinfmts(fs, modules, warn = () => {
8155
8176
  for (const [key, value2] of Object.entries(declared2)) {
8156
8177
  const rule2 = binfmtEntry(pkg, key, value2);
8157
8178
  if (!rule2) continue;
8179
+ declarations?.push(rule2);
8158
8180
  const had = found.get(key);
8159
8181
  if (had === void 0) found.set(key, rule2);
8160
8182
  else if (had.command !== rule2.command)
@@ -8165,6 +8187,19 @@ async function scanBinfmts(fs, modules, warn = () => {
8165
8187
  }
8166
8188
  return [...found.values()];
8167
8189
  }
8190
+ function binfmtInputs(declarations, path, head) {
8191
+ const name2 = path.slice(path.lastIndexOf("/") + 1);
8192
+ const keys2 = new Set(
8193
+ declarations.filter(
8194
+ (rule2) => rule2.magic ? head && magicMatches(rule2, head) : name2.length > rule2.name.length && name2.endsWith(rule2.name)
8195
+ ).map((rule2) => rule2.name)
8196
+ );
8197
+ return [
8198
+ ...new Set(
8199
+ declarations.filter((rule2) => keys2.has(rule2.name)).map((rule2) => `${rule2.pkg}/package.json`)
8200
+ )
8201
+ ];
8202
+ }
8168
8203
  function binfmtFor(rules, path, head) {
8169
8204
  const magic = head && rules.find((rule2) => magicMatches(rule2, head));
8170
8205
  if (magic) return magic;
@@ -18942,8 +18977,9 @@ var SudoReads = class {
18942
18977
  reads = /* @__PURE__ */ new Map();
18943
18978
  names = /* @__PURE__ */ new Map();
18944
18979
  documents = /* @__PURE__ */ new Map();
18945
- manifestFiles = /* @__PURE__ */ new Map();
18946
- observed = /* @__PURE__ */ new Set();
18980
+ texts = /* @__PURE__ */ new Map();
18981
+ relevant = /* @__PURE__ */ new Set();
18982
+ verified = /* @__PURE__ */ new Set();
18947
18983
  interpreters = [];
18948
18984
  chainSha256;
18949
18985
  operandsFromEnd = /* @__PURE__ */ new Map();
@@ -18960,6 +18996,26 @@ var SudoReads = class {
18960
18996
  }
18961
18997
  return read;
18962
18998
  }
18999
+ resetSelection() {
19000
+ this.relevant.clear();
19001
+ this.interpreters.length = 0;
19002
+ delete this.chainSha256;
19003
+ this.operandsFromEnd.clear();
19004
+ }
19005
+ include(paths) {
19006
+ for (const path of paths ?? []) if (this.verified.has(path)) this.relevant.add(path);
19007
+ }
19008
+ async digest(path) {
19009
+ const real = await this.access.real(path);
19010
+ this.saw(path, real);
19011
+ return (await this.bytes(real))?.hash;
19012
+ }
19013
+ async text(path) {
19014
+ const real = await this.access.real(path);
19015
+ this.saw(path, real);
19016
+ const result = await this.document(real, (at) => this.raw(at)).catch(() => void 0);
19017
+ return result?.text;
19018
+ }
18963
19019
  raw(real) {
18964
19020
  const saved = this.snapshots.get(real);
18965
19021
  return saved ? Promise.resolve(saved) : this.access.read(real);
@@ -18976,19 +19032,19 @@ var SudoReads = class {
18976
19032
  const real = await this.access.real(path);
18977
19033
  this.saw(path, real);
18978
19034
  const { text, read } = await this.document(real, raw2);
18979
- this.observed.add(path);
18980
19035
  await verify(real, read.hash);
19036
+ this.verified.add(path);
18981
19037
  return text;
18982
19038
  }
18983
19039
  document(real, raw2) {
18984
- let found = this.manifestFiles.get(real);
19040
+ let found = this.texts.get(real);
18985
19041
  if (!found) {
18986
19042
  const saved = this.snapshots.get(real);
18987
19043
  found = (saved ? Promise.resolve(saved) : raw2(real)).then(async (data) => {
18988
19044
  const bytes = new Uint8Array(data);
18989
19045
  return { text: new TextDecoder().decode(bytes), read: await fingerprint(bytes) };
18990
19046
  });
18991
- this.manifestFiles.set(real, found);
19047
+ this.texts.set(real, found);
18992
19048
  const earlier = this.reads.get(real);
18993
19049
  this.reads.set(
18994
19050
  real,
@@ -19015,7 +19071,7 @@ var SudoReads = class {
19015
19071
  *inputs(paths) {
19016
19072
  const primary = new Set(paths);
19017
19073
  yield* primary;
19018
- for (const path of this.observed) if (!primary.has(path)) yield path;
19074
+ for (const path of this.relevant) if (!primary.has(path)) yield path;
19019
19075
  }
19020
19076
  async bind(paths) {
19021
19077
  const hashes = {};
@@ -19125,7 +19181,7 @@ var SUDOERS_D = "/etc/sudoers.d";
19125
19181
  var NAME3 = /^[a-z_][a-z0-9_.-]*$/;
19126
19182
  var WORD = String.raw`(?:'[^']*'|"(?:[^"\\]|\\[\s\S])*"|\\[\s\S]|[^\s'"\\])+`;
19127
19183
  var KERNEL_FORM = new RegExp(
19128
- String.raw`^(NOPASSWD\s+)?(\S+)\s+(?:\(([^()]*)\)\s+)?(?:Cwd\s+(${WORD})\s+)?(?:Stdin\s+(\S+)\s+)?(?:RouteSha256\s+([a-f0-9]{64})\s+)?((?:Sha256\s+${WORD}\s+)*)Cmnd(?:\s+(.*))?$`
19184
+ String.raw`^(NOPASSWD\s+)?(\S+)\s+(?:\(([^()]*)\)\s+)?(?:Cwd\s+(${WORD})\s+)?(?:Stdin\s+(\S+)\s+)?(?:ChainSha256\s+([a-f0-9]{64})\s+)?(?:RouteSha256\s+([a-f0-9]{64})\s+)?((?:Sha256\s+${WORD}\s+)*)Cmnd(?:\s+(.*))?$`
19129
19185
  );
19130
19186
  var SHA256_CLAUSE = new RegExp(String.raw`Sha256\s+(${WORD})`, "g");
19131
19187
  var HEX2 = /^[0-9a-f]{64}$/;
@@ -19137,7 +19193,7 @@ var PLAIN = /^[A-Za-z0-9_@%+=:,./-]+$/;
19137
19193
  var CONTROL2 = /[\p{Cc}\u2028\u2029]/u;
19138
19194
  var CONTROLS = /[\p{Cc}\u2028\u2029]/gu;
19139
19195
  var SHOWN_MAX = 60;
19140
- var KERNEL_SYNTAX = "[NOPASSWD] <user|%group|ALL> [(<target>)] [Cwd <dir>] [Stdin none] [RouteSha256 <sha256>] [Sha256 <file>=<sha256>\u2026] Cmnd <command\u2026|*>";
19196
+ var KERNEL_SYNTAX = "[NOPASSWD] <user|%group|ALL> [(<target>)] [Cwd <dir>] [Stdin none] [ChainSha256 <sha256>] [RouteSha256 <sha256>] [Sha256 none|<file>=<sha256>\u2026] Cmnd <command\u2026|*>";
19141
19197
  var SUDOERS_SYNTAX = "<user|%group|ALL> ALL=[(<target>[,<target>\u2026])] [NOPASSWD:] <command\u2026|ALL>";
19142
19198
  var EXPECTED = `expected '${KERNEL_SYNTAX}' or '${SUDOERS_SYNTAX}'`;
19143
19199
  var TIMESTAMP_TIMEOUT = 5;
@@ -19305,6 +19361,7 @@ function commandOf2(text, after) {
19305
19361
  return args.length === 0 ? { path } : { path, args };
19306
19362
  }
19307
19363
  function sha256Of(clauses) {
19364
+ if (/^Sha256\s+none\s*$/.test(clauses)) return {};
19308
19365
  const files = {};
19309
19366
  for (const [, word = ""] of clauses.matchAll(SHA256_CLAUSE)) {
19310
19367
  const [text = ""] = splitWords(word) ?? [];
@@ -19318,9 +19375,11 @@ function sha256Of(clauses) {
19318
19375
  }
19319
19376
  return files;
19320
19377
  }
19321
- function sha256Text(files, routeSha256) {
19378
+ function sha256Text(files, routeSha256, chainSha256) {
19379
+ const chain2 = chainSha256 ? `ChainSha256 ${chainSha256} ` : "";
19380
+ if (!Object.keys(files).length) return `${chain2}Sha256 none `;
19322
19381
  const route2 = routeSha256 ? `RouteSha256 ${routeSha256} ` : "";
19323
- return route2 + Object.entries(files).map(([path, hex4]) => `Sha256 ${quoteWord(`${path}=${hex4}`)} `).join("");
19382
+ return chain2 + route2 + Object.entries(files).map(([path, hex4]) => `Sha256 ${quoteWord(`${path}=${hex4}`)} `).join("");
19324
19383
  }
19325
19384
  function targetError(list) {
19326
19385
  if (list.includes(",")) {
@@ -19329,16 +19388,28 @@ function targetError(list) {
19329
19388
  return `expected one user name or ALL in (\u2026), not ${shown(`(${list})`)}`;
19330
19389
  }
19331
19390
  function kernelRules(m) {
19332
- const [, nopasswd, who = "", target = "root", dir, stdin, routeSha256, sums = "", rest2 = ""] = m;
19391
+ const [
19392
+ ,
19393
+ nopasswd,
19394
+ who = "",
19395
+ target = "root",
19396
+ dir,
19397
+ stdin,
19398
+ chainSha256,
19399
+ routeSha256,
19400
+ sums = "",
19401
+ rest2 = ""
19402
+ ] = m;
19333
19403
  const bad = whoError(who);
19334
19404
  if (bad !== void 0) return bad;
19335
19405
  if (target !== "ALL" && !NAME3.test(target)) return targetError(target);
19336
19406
  const cwd = dir === void 0 ? void 0 : cwdOf(dir);
19337
19407
  if (cwd === "") return `Cwd expects one absolute directory, not ${shown(dir)}`;
19338
19408
  if (stdin !== void 0 && stdin !== "none") return `Stdin takes none, not ${shown(stdin)}`;
19339
- if (routeSha256 && !sums) return "RouteSha256 requires Sha256";
19340
19409
  const sha2564 = sha256Of(sums);
19341
19410
  if (typeof sha2564 === "string") return sha2564;
19411
+ if (routeSha256 && !Object.keys(sha2564).length) return "RouteSha256 requires Sha256";
19412
+ if (chainSha256 && !sums) return "ChainSha256 requires Sha256";
19342
19413
  const rule2 = {
19343
19414
  nopasswd: !!nopasswd,
19344
19415
  who,
@@ -19346,7 +19417,8 @@ function kernelRules(m) {
19346
19417
  ...cwd !== void 0 ? { cwd } : {},
19347
19418
  ...stdin === "none" ? { stdin: "none" } : {},
19348
19419
  ...sums === "" ? {} : { sha256: sha2564 },
19349
- ...routeSha256 ? { routeSha256 } : {}
19420
+ ...routeSha256 ? { routeSha256 } : {},
19421
+ ...chainSha256 ? { chainSha256 } : {}
19350
19422
  };
19351
19423
  const text = rest2.trim();
19352
19424
  if (text === "*") return [{ ...rule2, cmnd: "*" }];
@@ -20102,8 +20174,21 @@ function changedFile(approved, now) {
20102
20174
  const files = /* @__PURE__ */ new Set([...Object.keys(approved), ...Object.keys(now)]);
20103
20175
  return [...files].find((file) => approved[file] !== now[file]);
20104
20176
  }
20105
- function pinned(rule2, hashes, routeSha256) {
20106
- return rule2.sha256 === void 0 || rule2.routeSha256 === routeSha256 && changedFile(rule2.sha256, hashes) === void 0;
20177
+ function pinned(rule2, hashes, proof) {
20178
+ return rule2.sha256 === void 0 || rule2.routeSha256 === proof.routeSha256 && (rule2.chainSha256 === void 0 || rule2.chainSha256 === proof.chainSha256) && changedFile(rule2.sha256, hashes) === void 0;
20179
+ }
20180
+ function changedManifests(rules, bound3) {
20181
+ const changed2 = /* @__PURE__ */ new Set();
20182
+ for (const { sha256: hashes } of rules) {
20183
+ if (!hashes) continue;
20184
+ for (const [asked, real] of Object.entries(bound3.routes)) {
20185
+ if (asked.endsWith("/package.json") && hashes[real] !== bound3.hashes[real]) changed2.add(real);
20186
+ }
20187
+ for (const path of Object.keys(hashes)) {
20188
+ if (path.endsWith("/package.json") && !Object.hasOwn(bound3.hashes, path)) changed2.add(path);
20189
+ }
20190
+ }
20191
+ return changed2.size ? { changedManifests: [...changed2].sort() } : {};
20107
20192
  }
20108
20193
  function proofOf({ routeSha256, chainSha256 }) {
20109
20194
  return { ...routeSha256 ? { routeSha256 } : {}, ...chainSha256 ? { chainSha256 } : {} };
@@ -20324,10 +20409,12 @@ function described(rule2, writable3) {
20324
20409
  const cmnd = rule2.cmnd === "*" ? "ALL" : commandText(rule2.cmnd);
20325
20410
  const cwd = rule2.cwd === void 0 ? "" : `CWD=${quoteWord(rule2.cwd)} `;
20326
20411
  const stdin = rule2.stdin === void 0 ? "" : "STDIN=none ";
20412
+ const chain2 = rule2.chainSha256 ? `CHAIN_SHA256=${rule2.chainSha256} ` : "";
20413
+ const empty = rule2.sha256 && !Object.keys(rule2.sha256).length ? "SHA256=none " : "";
20327
20414
  const sums = Object.entries(rule2.sha256 ?? {}).map(([path, hex4]) => `SHA256=${quoteWord(path)}:${hex4} `).join("");
20328
20415
  const route2 = rule2.routeSha256 ? `ROUTE_SHA256=${rule2.routeSha256} ` : "";
20329
20416
  const flag = writable3 ? " # user-writable command" : "";
20330
- return ` (${rule2.target}) ${cwd}${stdin}${route2}${sums}${rule2.nopasswd ? "NOPASSWD: " : ""}${cmnd}${flag}`;
20417
+ return ` (${rule2.target}) ${cwd}${stdin}${chain2}${route2}${empty}${sums}${rule2.nopasswd ? "NOPASSWD: " : ""}${cmnd}${flag}`;
20331
20418
  }
20332
20419
  var Sudo = class {
20333
20420
  o;
@@ -20578,10 +20665,11 @@ var Sudo = class {
20578
20665
  const bound3 = files && await reads.bind([path, asked, ...files]);
20579
20666
  return bound3 && !Object.values(bound3.hashes).includes("") && (bound3.routes[asked] ?? path) === path ? bound3 : void 0;
20580
20667
  }
20581
- async writable(rule2, pid) {
20668
+ async writable(rule2, pid, reads) {
20582
20669
  if (rule2.cmnd === "*") return false;
20583
20670
  const { path } = rule2.cmnd;
20584
- const bound3 = await this.bound(path, "/", path, pid);
20671
+ reads.resetSelection();
20672
+ const bound3 = await this.bound(path, "/", path, pid, reads);
20585
20673
  if (bound3) return Object.keys(bound3.hashes).length > 0;
20586
20674
  return !await this.trusted(await this.existing(path));
20587
20675
  }
@@ -20719,7 +20807,7 @@ ${SCRIPT_HELP}
20719
20807
  const { rules } = await this.policyRules({ cred, pid: 0, stdin: r.stdin });
20720
20808
  const applies = await this.applies(self, cred);
20721
20809
  return rules.some(
20722
- (rule2) => applies(rule2.who) && (rule2.target === "ALL" || rule2.target === target.name) && (rule2.cwd === void 0 || rule2.cwd === r.cwd) && stdinMatches(rule2, r.stdin) && commandMatches(rule2.cmnd, argv) && pinned(rule2, r.bound, r.routeSha256)
20810
+ (rule2) => applies(rule2.who) && (rule2.target === "ALL" || rule2.target === target.name) && (rule2.cwd === void 0 || rule2.cwd === r.cwd) && stdinMatches(rule2, r.stdin) && commandMatches(rule2.cmnd, argv) && pinned(rule2, r.bound, r)
20723
20811
  );
20724
20812
  }
20725
20813
  async command(s, root, mine, call) {
@@ -20739,9 +20827,10 @@ ${SCRIPT_HELP}
20739
20827
  if (!located || !bound3) return failed2("ENOENT", `sudo: ${word}: command not found`);
20740
20828
  const { path, asked } = located;
20741
20829
  const argv = [path, ...args];
20742
- const matching = mine.filter(
20743
- (rule2) => (rule2.target === "ALL" || rule2.target === target.name) && (rule2.cwd === void 0 || rule2.cwd === cwd) && stdinMatches(rule2, caller.stdin) && commandMatches(rule2.cmnd, argv) && pinned(rule2, bound3.hashes, bound3.routeSha256)
20830
+ const applicable = mine.filter(
20831
+ (rule2) => (rule2.target === "ALL" || rule2.target === target.name) && (rule2.cwd === void 0 || rule2.cwd === cwd) && stdinMatches(rule2, caller.stdin) && commandMatches(rule2.cmnd, argv)
20744
20832
  );
20833
+ const matching = applicable.filter((rule2) => pinned(rule2, bound3.hashes, bound3));
20745
20834
  const grant = () => this.grant(self, target, cred, parsed3.command, path, cwd, call.term, bound3, s.kept, asked);
20746
20835
  if (root || matching.some((rule2) => rule2.nopasswd)) return grant();
20747
20836
  const quoted = argv.map(quoteWord).join(" ");
@@ -20764,6 +20853,10 @@ ${SCRIPT_HELP}
20764
20853
  path,
20765
20854
  cwd,
20766
20855
  bound: bound3.hashes,
20856
+ ...changedManifests(
20857
+ applicable.filter((rule2) => !matching.includes(rule2)),
20858
+ bound3
20859
+ ),
20767
20860
  ...proof
20768
20861
  });
20769
20862
  if ("error" in answer2) return answer2;
@@ -20852,7 +20945,8 @@ ${SCRIPT_HELP}
20852
20945
  return failed2("EPERM", `User ${self.name} is not allowed to run sudo on ${host}.`);
20853
20946
  }
20854
20947
  const shown2 = [];
20855
- for (const rule2 of rules) shown2.push(described(rule2, await this.writable(rule2, pid)));
20948
+ const reads = this.reads();
20949
+ for (const rule2 of rules) shown2.push(described(rule2, await this.writable(rule2, pid, reads)));
20856
20950
  const lines3 = shown2.join("\n");
20857
20951
  const params = defaults2.flatMap((d) => d.params).join(", ");
20858
20952
  const matching = params === "" ? "" : `Matching Defaults entries for ${self.name} on ${host}:
@@ -20892,6 +20986,7 @@ ${lines3}
20892
20986
  stdin: caller.stdin,
20893
20987
  rootOnly: asked.validate ? {} : await this.rootOnly(cwd, argv.slice(1)),
20894
20988
  ...userWritable(asked.bound),
20989
+ ...asked.changedManifests ? { changedManifests: asked.changedManifests } : {},
20895
20990
  ...proofOf(asked),
20896
20991
  ...asked.validate ? { validate: true } : {},
20897
20992
  timestamp: true
@@ -20912,12 +21007,7 @@ ${lines3}
20912
21007
  requester.removeEventListener("abort", withdraw);
20913
21008
  }
20914
21009
  }
20915
- async remember(self, target, {
20916
- cwd,
20917
- argv,
20918
- bound: bound3,
20919
- routeSha256
20920
- }) {
21010
+ async remember(self, target, { cwd, argv, bound: bound3, routeSha256, chainSha256 }) {
20921
21011
  const { fs } = this.o;
20922
21012
  const path = `${SUDOERS_D}/${self.name}`;
20923
21013
  if (!NAME3.test(self.name)) return false;
@@ -20928,7 +21018,7 @@ ${lines3}
20928
21018
  if (st && !await this.trusted(path)) return false;
20929
21019
  const old = st ? await fs.readFile(path) : "";
20930
21020
  const words3 = recordedCommand(argv);
20931
- const line = `NOPASSWD ${self.name} (${target.name}) Cwd ${quoteWord(cwd)} Stdin none ${sha256Text(bound3, routeSha256)}Cmnd ${words3}
21021
+ const line = `NOPASSWD ${self.name} (${target.name}) Cwd ${quoteWord(cwd)} Stdin none ${sha256Text(bound3, routeSha256, chainSha256)}Cmnd ${words3}
20932
21022
  `;
20933
21023
  const text = old === "" || old.endsWith("\n") ? `${old}${line}` : `${old}
20934
21024
  ${line}`;
@@ -37255,6 +37345,7 @@ function refusing(command) {
37255
37345
  argv0: command.name,
37256
37346
  args: [`${command.name}: ${command.refused}`],
37257
37347
  refused: command.refused,
37348
+ ...command.manifests ? { manifests: command.manifests } : {},
37258
37349
  shows: command.script ?? command.wasm,
37259
37350
  origin: {
37260
37351
  abi: command.abi,
@@ -37834,7 +37925,8 @@ function expandDefaults(defaults2, env) {
37834
37925
  }
37835
37926
  return out;
37836
37927
  }
37837
- function targetOf(command) {
37928
+ function targetOf(command, reads) {
37929
+ reads?.include(command.manifests);
37838
37930
  return {
37839
37931
  abi: command.abi,
37840
37932
  command: command.name,
@@ -37918,6 +38010,7 @@ var CatalogCache = class {
37918
38010
  commands = /* @__PURE__ */ new Map();
37919
38011
  own = /* @__PURE__ */ new Map();
37920
38012
  rules = /* @__PURE__ */ new Map();
38013
+ declarations = /* @__PURE__ */ new Map();
37921
38014
  fs;
37922
38015
  };
37923
38016
  var Launcher = class {
@@ -38344,7 +38437,8 @@ var Launcher = class {
38344
38437
  tiers.length - appended2.length,
38345
38438
  void 0,
38346
38439
  refused5,
38347
- await this.globalRoots(scope)
38440
+ await this.globalRoots(scope),
38441
+ reads !== void 0
38348
38442
  );
38349
38443
  this.refusedOf.set(commands, refused5.map(refusing));
38350
38444
  return commands;
@@ -38406,11 +38500,18 @@ var Launcher = class {
38406
38500
  return found;
38407
38501
  }
38408
38502
  async scanInterpreters(scope, reads) {
38409
- return scanBinfmts(this.scanFs(reads), await this.roots(scope), (message3) => {
38410
- if (this.warned.has(message3)) return;
38411
- this.warned.add(message3);
38412
- console.warn(message3);
38413
- });
38503
+ const declarations = reads && [];
38504
+ if (declarations) this.catalogOf(reads).declarations.set(scope, declarations);
38505
+ return scanBinfmts(
38506
+ this.scanFs(reads),
38507
+ await this.roots(scope),
38508
+ (message3) => {
38509
+ if (this.warned.has(message3)) return;
38510
+ this.warned.add(message3);
38511
+ console.warn(message3);
38512
+ },
38513
+ declarations
38514
+ );
38414
38515
  }
38415
38516
  async tiers(scope = "", appended2) {
38416
38517
  const system = [
@@ -38517,7 +38618,7 @@ var Launcher = class {
38517
38618
  async resolve(file, argv0, cwd, scope = "", reads) {
38518
38619
  if (!file.includes("/") || COMMAND2.test(file)) {
38519
38620
  const command = await this.commandAt(file, scope, reads);
38520
- return command && !command.script ? targetOf(command) : void 0;
38621
+ return command && !command.script ? targetOf(command, reads) : void 0;
38521
38622
  }
38522
38623
  const path = this.fs.resolvePath(cwd, file);
38523
38624
  const glue = await this.followCommand(path, reads);
@@ -38530,12 +38631,12 @@ var Launcher = class {
38530
38631
  return target && byPath ? { ...target, argv0: path } : target;
38531
38632
  }
38532
38633
  const own = await this.ownOrRefused(glue, baseName3(file), scope, reads);
38533
- if (own) return own.script ? void 0 : { ...targetOf(own), ...asked };
38634
+ if (own) return own.script ? void 0 : { ...targetOf(own, reads), ...asked };
38534
38635
  const head = await this.head(glue, reads);
38535
38636
  if (!head) return void 0;
38536
38637
  if (isWasm(head)) {
38537
38638
  const owner2 = await this.wasmOwner(glue, baseName3(file).replace(/\.wasm$/, ""), scope, reads);
38538
- if (owner2) return { ...targetOf(owner2), ...asked };
38639
+ if (owner2) return { ...targetOf(owner2, reads), ...asked };
38539
38640
  return {
38540
38641
  abi: "wasi",
38541
38642
  glue,
@@ -38553,9 +38654,9 @@ var Launcher = class {
38553
38654
  const owner = await this.glueOwner(glue, baseName3(file), scope, reads);
38554
38655
  if (!owner) {
38555
38656
  const shim = await this.shimOwner(glue, baseName3(file), scope, reads);
38556
- return shim && { ...targetOf(shim), ...asked, shim: glue };
38657
+ return shim && { ...targetOf(shim, reads), ...asked, shim: glue };
38557
38658
  }
38558
- return { ...targetOf(owner), ...asked, ...owner.glue === glue ? {} : { copy: glue } };
38659
+ return { ...targetOf(owner, reads), ...asked, ...owner.glue === glue ? {} : { copy: glue } };
38559
38660
  }
38560
38661
  async ownOrRefused(path, name2, scope, reads) {
38561
38662
  return await this.commandAt(path, scope, reads) ?? await this.refusedAt(path, name2, scope, reads);
@@ -38578,22 +38679,23 @@ var Launcher = class {
38578
38679
  }
38579
38680
  const stem = name2.replace(/\.wasm$/, "");
38580
38681
  const named = owners.find((c) => c.name === name2) ?? owners.find((c) => c.name === stem);
38581
- return named ?? owners[0] ?? await this.refusedCopy(real, name2, refused5);
38682
+ return named ?? owners[0] ?? await this.refusedCopy(real, name2, refused5, reads);
38582
38683
  }
38583
- async refusedCopy(real, name2, refused5) {
38684
+ async refusedCopy(real, name2, refused5, reads) {
38584
38685
  const dir = real.slice(0, real.lastIndexOf("/"));
38585
38686
  for (const c of refused5) {
38586
38687
  const origin = c.origin;
38587
38688
  if (origin.abi !== "emscripten" || origin.script || c.name !== name2) continue;
38588
38689
  const own = await physicalPathAsync(this.base, origin.glue).catch(() => origin.glue);
38589
- if (own.slice(0, own.lastIndexOf("/")) === dir && await this.sameFile(real, own)) return c;
38690
+ if (own.slice(0, own.lastIndexOf("/")) === dir && await this.sameFile(real, own, reads))
38691
+ return c;
38590
38692
  }
38591
38693
  return void 0;
38592
38694
  }
38593
38695
  async shimOwner(script, name2, scope, reads) {
38594
38696
  const command = (await this.commands(scope, reads)).get(name2);
38595
38697
  if (!command || command.script || command.origin?.script) return void 0;
38596
- const target = await this.shimTarget(script);
38698
+ const target = await this.shimTarget(script, reads);
38597
38699
  if (target === void 0) return void 0;
38598
38700
  const pkg = await this.installedPackage(await physicalPathAsync(this.base, target), scope);
38599
38701
  if (!pkg) return void 0;
@@ -38601,10 +38703,10 @@ var Launcher = class {
38601
38703
  const own = await physicalPathAsync(this.base, glue).catch(() => void 0);
38602
38704
  return own?.startsWith(`${pkg}/`) ? command : void 0;
38603
38705
  }
38604
- async shimTarget(script) {
38706
+ async shimTarget(script, reads) {
38605
38707
  const st = await this.base.stat(script).catch(() => void 0);
38606
38708
  if (!st?.isFile || st.size > SHIM_MAX) return void 0;
38607
- const text = await this.base.readFile(script).catch(() => "");
38709
+ const text = reads ? await reads.text(script) ?? "" : await this.base.readFile(script).catch(() => "");
38608
38710
  const marker = [...text.matchAll(SHIM_MARKER)].at(-1)?.[1];
38609
38711
  if (marker === void 0) return void 0;
38610
38712
  let target;
@@ -38637,12 +38739,16 @@ var Launcher = class {
38637
38739
  if (c.abi !== "emscripten" || c.script || c.name !== leaf) continue;
38638
38740
  const own = await physicalPathAsync(this.base, c.glue).catch(() => c.glue);
38639
38741
  if (own.slice(0, own.lastIndexOf("/")) !== dir) continue;
38640
- if (await this.sameFile(glue, own)) return c;
38742
+ if (await this.sameFile(glue, own, reads)) return c;
38641
38743
  }
38642
38744
  return void 0;
38643
38745
  }
38644
38746
  sameFiles = /* @__PURE__ */ new Map();
38645
- async sameFile(a, b) {
38747
+ async sameFile(a, b, reads) {
38748
+ if (reads) {
38749
+ const [left, right] = await Promise.all([reads.digest(a), reads.digest(b)]);
38750
+ return left !== void 0 && left === right;
38751
+ }
38646
38752
  const [x, y] = await Promise.all([this.base.stat(a), this.base.stat(b)]).catch(() => []);
38647
38753
  if (!x?.isFile || !y?.isFile || x.size !== y.size) return false;
38648
38754
  const stamp = [x, y].map((st) => `${st.size}:${st.mtime.getTime()}:${st.ino}`).join("|");
@@ -38681,7 +38787,9 @@ var Launcher = class {
38681
38787
  const direct = !file.includes("/") || COMMAND2.test(file);
38682
38788
  const at = direct ? file : await this.followCommand(this.fs.resolvePath(cwd, file), reads);
38683
38789
  const command = await this.commandAt(at, scope, reads);
38684
- return command?.script ? command : void 0;
38790
+ if (!command?.script) return void 0;
38791
+ reads?.include(command.manifests);
38792
+ return command;
38685
38793
  }
38686
38794
  async mayRead(reader, path, reads) {
38687
38795
  if (!reader || !this.dac) return true;
@@ -38689,7 +38797,10 @@ var Launcher = class {
38689
38797
  }
38690
38798
  async binfmtOf(path, head, scope, reader, reads) {
38691
38799
  const shown2 = await this.mayRead(reader, path, reads) ? head : void 0;
38692
- return binfmtFor(await this.interpreters(scope, reads), path, shown2);
38800
+ const rules = await this.interpreters(scope, reads);
38801
+ if (reads)
38802
+ reads.include(binfmtInputs(this.catalogOf(reads).declarations.get(scope) ?? [], path, shown2));
38803
+ return binfmtFor(rules, path, shown2);
38693
38804
  }
38694
38805
  async interpreterWords(head, script, who) {
38695
38806
  const bang = shebang(head);
@@ -38795,7 +38906,9 @@ var Launcher = class {
38795
38906
  if (direct) {
38796
38907
  const shim = direct.shim ? { sources: [direct.shim], asked: direct.asked ? { [direct.shim]: direct.asked } : {} } : {};
38797
38908
  const args = [...direct.prefix ?? [], ...argv.slice(1)];
38798
- return { planned: { target: direct, args, ...shim } };
38909
+ const planned = { target: direct, args, ...shim };
38910
+ await this.stampDirect(reads, planned);
38911
+ return { planned };
38799
38912
  }
38800
38913
  const command = await this.scriptCommand(file, cwd, scope, reads);
38801
38914
  if (catalogOnly && !command) return {};
@@ -38803,14 +38916,17 @@ var Launcher = class {
38803
38916
  const given = typeof argv0 === "string" ? { argv0 } : {};
38804
38917
  const who = { scope, reader, reads, pid, ...given };
38805
38918
  const script = await this.interpreted(file, argv, cwd, who, command);
38806
- if (reads && script)
38807
- reads.chainSha256 = await sha2562(
38808
- new TextEncoder().encode(
38809
- JSON.stringify([reads.interpreters, script.binfmts, script.target])
38810
- )
38811
- );
38919
+ if (reads && script) await this.stampChain(reads, script);
38812
38920
  return { planned: script && { ...script, script: true }, ...examined };
38813
38921
  }
38922
+ async stampDirect(reads, plan) {
38923
+ if (reads && plan.target.command) await this.stampChain(reads, plan);
38924
+ }
38925
+ async stampChain(reads, plan) {
38926
+ reads.chainSha256 = await sha2562(
38927
+ new TextEncoder().encode(JSON.stringify([reads.interpreters, plan.binfmts, plan.target]))
38928
+ );
38929
+ }
38814
38930
  async mayExec(cred, req, { planned, examined }, reads) {
38815
38931
  const { dac } = this;
38816
38932
  if (!dac) return;
@@ -38871,12 +38987,18 @@ var Launcher = class {
38871
38987
  });
38872
38988
  await this.mayExec(cred, { ...req, file, pid: ppid }, plan, reads).catch(refused5);
38873
38989
  if (plan.planned) return reads ? { ...plan.planned, reads } : plan.planned;
38874
- if (grant?.files) {
38990
+ if (grant?.files) await this.checkFailedPlan(file, req, scope, grant);
38991
+ if (catalogOnly) throw new SpawnError("ENOENT");
38992
+ throw new SpawnError(await this.unrunnable(file, req.cwd, scope, cred));
38993
+ }
38994
+ async checkFailedPlan(file, req, scope, grant) {
38995
+ const reads = this.sudoer.reads();
38996
+ const { planned } = await this.plan(file, req.argv, req.cwd, scope, { reads });
38997
+ if (!planned) {
38875
38998
  const gone = await this.sudoer.missingBacking(grant.files.hashes) ?? file;
38876
38999
  throw new ChangedError(changedText(gone), gone);
38877
39000
  }
38878
- if (catalogOnly) throw new SpawnError("ENOENT");
38879
- throw new SpawnError(await this.unrunnable(file, req.cwd, scope, cred));
39001
+ await this.unchanged({ ...planned, reads }, file, req.cwd, grant);
38880
39002
  }
38881
39003
  async enterable(g, cwd) {
38882
39004
  if (!g) return;
@@ -41117,6 +41239,7 @@ var Launcher = class {
41117
41239
  const name2 = system ?? path.slice(slash + 1);
41118
41240
  const command = scope === void 0 ? void 0 : (await this.commands(scope, reads)).get(name2);
41119
41241
  const owner = scope ? scopes.owners?.get(scope) : void 0;
41242
+ reads?.include(command?.manifests);
41120
41243
  const target = command && (command.shows ?? command.script ?? command.wasm);
41121
41244
  return target === void 0 ? void 0 : { path: target, ...owner ? { owner } : {} };
41122
41245
  }