@workit-dev/pi 1.8.0 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/worker.js +72 -27
  2. package/dist/workit.js +479 -154
  3. package/package.json +1 -1
package/dist/workit.js CHANGED
@@ -3,7 +3,7 @@ import { randomUUID as randomUUID6 } from "node:crypto";
3
3
  import { fileURLToPath as fileURLToPath2 } from "node:url";
4
4
 
5
5
  // packages/workit-core/src/core.ts
6
- import { spawnSync as spawnSync21 } from "node:child_process";
6
+ import { spawnSync as spawnSync22 } from "node:child_process";
7
7
  import { existsSync as existsSync12, realpathSync as realpathSync8 } from "node:fs";
8
8
  import path34 from "node:path";
9
9
 
@@ -7883,15 +7883,14 @@ var gitContext = (workspaceRoot, paths = []) => {
7883
7883
  };
7884
7884
 
7885
7885
  // packages/workit-core/src/core/workspaces.ts
7886
- import { spawnSync as spawnSync5 } from "node:child_process";
7886
+ import { spawnSync as spawnSync6 } from "node:child_process";
7887
7887
  import { createHash as createHash3 } from "node:crypto";
7888
- import { existsSync as existsSync2, lstatSync as lstatSync2, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
7888
+ import { existsSync as existsSync2, lstatSync as lstatSync2, readFileSync as readFileSync4, realpathSync as realpathSync2 } from "node:fs";
7889
7889
  import path7 from "node:path";
7890
7890
 
7891
7891
  // packages/workit-core/src/core/remotes.ts
7892
- import { lstatSync, readFileSync as readFileSync2, realpathSync, statSync } from "node:fs";
7893
- import { spawnSync as spawnSync4 } from "node:child_process";
7894
- import os3 from "node:os";
7892
+ import { lstatSync, readFileSync as readFileSync3, realpathSync, statSync } from "node:fs";
7893
+ import { spawnSync as spawnSync5 } from "node:child_process";
7895
7894
  import path6 from "node:path";
7896
7895
 
7897
7896
  // packages/workit-core/src/git/rev.ts
@@ -8717,6 +8716,56 @@ function resolveSshHost(alias, sshConfig) {
8717
8716
  return { hostname: (hostname ?? alias).replace(/\.$/u, ""), port };
8718
8717
  }
8719
8718
 
8719
+ // packages/workit-core/src/core/account-home.ts
8720
+ import { spawnSync as spawnSync4 } from "node:child_process";
8721
+ import { readFileSync as readFileSync2 } from "node:fs";
8722
+ import os3 from "node:os";
8723
+ var WINDOWS = "C:\\Windows";
8724
+ var SYSTEM32 = `${WINDOWS}\\System32\\`;
8725
+ var PROFILES = "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\";
8726
+ var childEnv = (platform) => platform === "win32" ? { SystemRoot: WINDOWS } : {};
8727
+ var hostIo = {
8728
+ bun: Boolean(process.versions.bun),
8729
+ uid: process.getuid?.() ?? -1,
8730
+ userInfo: () => os3.userInfo().homedir,
8731
+ passwd: () => readFileSync2("/etc/passwd", "utf8"),
8732
+ run: (file, args) => {
8733
+ const done = spawnSync4(file, args, {
8734
+ encoding: "utf8",
8735
+ env: childEnv(process.platform),
8736
+ timeout: 3000,
8737
+ windowsHide: true
8738
+ });
8739
+ return done.status === 0 ? done.stdout : "";
8740
+ }
8741
+ };
8742
+ var field = (text, uid, at) => text.split(`
8743
+ `).filter((line) => !line.startsWith("#")).map((line) => line.split(":")).find((fields) => fields[2] === uid)?.[at];
8744
+ var profilePath = (raw) => {
8745
+ const value = raw.replaceAll(/%SystemDrive%/giu, WINDOWS.slice(0, 2)).replaceAll(/%SystemRoot%/giu, WINDOWS);
8746
+ return /^[A-Za-z]:\\/u.test(value) && !value.includes("%") ? value : null;
8747
+ };
8748
+ var accountHome = (platform = process.platform, io = hostIo) => {
8749
+ try {
8750
+ if (!io.bun)
8751
+ return io.userInfo() || null;
8752
+ if (platform === "win32") {
8753
+ const sid = /S-1-[\d-]+/u.exec(io.run(`${SYSTEM32}whoami.exe`, ["/user", "/fo", "csv"]));
8754
+ const key = sid && io.run(`${SYSTEM32}reg.exe`, ["query", PROFILES + sid[0], "/v", "ProfileImagePath"]);
8755
+ const raw = /ProfileImagePath\s+REG_\w+\s+(.+)/u.exec(key || "")?.[1]?.trim();
8756
+ return raw ? profilePath(raw) : null;
8757
+ }
8758
+ const uid = String(io.uid);
8759
+ let passwd = "";
8760
+ try {
8761
+ passwd = io.passwd();
8762
+ } catch {}
8763
+ return field(passwd, uid, 5) || (platform === "darwin" ? field(io.run("/usr/bin/id", ["-P"]), uid, 8) : field(io.run("/usr/bin/getent", ["passwd", uid]), uid, 5)) || null;
8764
+ } catch {
8765
+ return null;
8766
+ }
8767
+ };
8768
+
8720
8769
  // packages/workit-core/src/core/remotes.ts
8721
8770
  var FORGE_SCHEMES = new Set(["ssh", "git", "http", "https", "git+ssh", "ssh+git"]);
8722
8771
  var SSH_SCHEMES = new Set(["ssh", "git+ssh", "ssh+git"]);
@@ -8726,15 +8775,11 @@ var SSH_443 = {
8726
8775
  };
8727
8776
  var WINDOWS_DRIVE = /^[A-Za-z]:[\\/]/u;
8728
8777
  var SCP_LIKE = /^(?:[^@/\\]+@)?([^/\\:]+):(.+)$/u;
8729
- var accountHome = () => {
8730
- try {
8731
- return os3.userInfo().homedir;
8732
- } catch {
8733
- return os3.homedir();
8734
- }
8735
- };
8736
8778
  var sshSeam = {
8737
- read: () => readSshConfig(accountHome())
8779
+ read: () => {
8780
+ const home = accountHome();
8781
+ return home === null ? { text: "", home: "" } : readSshConfig(home);
8782
+ }
8738
8783
  };
8739
8784
  var forgeKey = (rawHost, repo, ssh) => {
8740
8785
  let host = rawHost.toLowerCase().replace(/\.$/u, "");
@@ -8781,7 +8826,7 @@ var gitDirAt = (at, depth = 0) => {
8781
8826
  return null;
8782
8827
  try {
8783
8828
  if (statSync(real).isFile()) {
8784
- const pointer = /^gitdir:\s*(.+?)\s*$/mu.exec(readFileSync2(real, "utf8"))?.[1];
8829
+ const pointer = /^gitdir:\s*(.+?)\s*$/mu.exec(readFileSync3(real, "utf8"))?.[1];
8785
8830
  if (!pointer)
8786
8831
  return null;
8787
8832
  const target = path6.isAbsolute(pointer) ? pointer : `${path6.dirname(real)}/${pointer}`;
@@ -8789,7 +8834,7 @@ var gitDirAt = (at, depth = 0) => {
8789
8834
  }
8790
8835
  let common;
8791
8836
  try {
8792
- common = readFileSync2(`${real}/commondir`, "utf8").trim();
8837
+ common = readFileSync3(`${real}/commondir`, "utf8").trim();
8793
8838
  } catch {}
8794
8839
  if (common !== undefined) {
8795
8840
  lstatSync(`${real}/HEAD`);
@@ -8893,7 +8938,7 @@ var checkoutRemotes = (cwd) => {
8893
8938
  const env = { ...process.env };
8894
8939
  for (const name of ["GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR", "GIT_INDEX_FILE"])
8895
8940
  delete env[name];
8896
- const git = (args) => spawnSync4("git", args, {
8941
+ const git = (args) => spawnSync5("git", args, {
8897
8942
  cwd,
8898
8943
  env,
8899
8944
  encoding: "utf8",
@@ -8944,6 +8989,8 @@ var userLevel = (scope, origin) => {
8944
8989
  return false;
8945
8990
  const file = realOrSelf(origin.slice("file:".length));
8946
8991
  const home = userGitSeam.home();
8992
+ if (home === null)
8993
+ return false;
8947
8994
  return [path6.join(home, ".gitconfig"), path6.join(home, ".config", "git", "config")].map(realOrSelf).includes(file);
8948
8995
  };
8949
8996
  var escapeRegex2 = (value) => value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
@@ -8954,7 +9001,7 @@ var transportOverride = (git, remote, vars) => {
8954
9001
  const execPath = vars.GIT_EXEC_PATH;
8955
9002
  if (execPath) {
8956
9003
  const { GIT_EXEC_PATH: _set, ...rest } = vars;
8957
- const own = spawnSync4("git", ["--exec-path"], {
9004
+ const own = spawnSync5("git", ["--exec-path"], {
8958
9005
  env: rest,
8959
9006
  encoding: "utf8"
8960
9007
  });
@@ -8990,7 +9037,7 @@ var pushTarget = (cwd, remote, replay = {}) => {
8990
9037
  delete env[name];
8991
9038
  if (!remote || remote.startsWith("-"))
8992
9039
  return Error(`push remote ${JSON.stringify(remote)} cannot be resolved`);
8993
- const git = (args) => spawnSync4("git", [...replay.config ?? [], ...args], {
9040
+ const git = (args) => spawnSync5("git", [...replay.config ?? [], ...args], {
8994
9041
  cwd,
8995
9042
  env,
8996
9043
  encoding: "utf8",
@@ -9222,7 +9269,7 @@ var readWorkspacesResult = (dir = configDir2()) => {
9222
9269
  const file = path7.join(dir, "workspaces.json");
9223
9270
  let raw;
9224
9271
  try {
9225
- raw = readFileSync3(file, "utf8");
9272
+ raw = readFileSync4(file, "utf8");
9226
9273
  } catch (error) {
9227
9274
  if (error.code === "ENOENT")
9228
9275
  return {
@@ -9343,7 +9390,7 @@ var probeCheckout = (cwd) => {
9343
9390
  for (const name of ["GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR", "GIT_INDEX_FILE"])
9344
9391
  delete env[name];
9345
9392
  const git = (args) => {
9346
- const run = spawnSync5("git", args, {
9393
+ const run = spawnSync6("git", args, {
9347
9394
  cwd,
9348
9395
  env,
9349
9396
  encoding: "utf8",
@@ -9540,7 +9587,7 @@ var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
9540
9587
  const file = path7.join(dir, "workspaces.json");
9541
9588
  let raw;
9542
9589
  try {
9543
- raw = readFileSync3(file, "utf8");
9590
+ raw = readFileSync4(file, "utf8");
9544
9591
  } catch (error) {
9545
9592
  if (error.code === "ENOENT")
9546
9593
  return null;
@@ -9616,7 +9663,7 @@ var modelSources = (cwd, dir) => {
9616
9663
  }
9617
9664
  } catch {}
9618
9665
  try {
9619
- const document = JSON.parse(readFileSync3(path7.join(dir ?? configDir2(), "workspaces.json"), "utf8"));
9666
+ const document = JSON.parse(readFileSync4(path7.join(dir ?? configDir2(), "workspaces.json"), "utf8"));
9620
9667
  if (document && typeof document === "object" && !Array.isArray(document))
9621
9668
  out.push({
9622
9669
  name: "global",
@@ -9682,11 +9729,11 @@ function workspaceDefaultTarget(cwd, globalDefault) {
9682
9729
  // packages/workit-core/src/core/vcs-config.ts
9683
9730
  import fs4 from "node:fs";
9684
9731
  import path8 from "node:path";
9685
- import { spawnSync as spawnSync7 } from "node:child_process";
9732
+ import { spawnSync as spawnSync8 } from "node:child_process";
9686
9733
 
9687
9734
  // packages/workit-core/src/core/release-tracks.ts
9688
9735
  import { createHash as createHash4 } from "node:crypto";
9689
- import { spawnSync as spawnSync6 } from "node:child_process";
9736
+ import { spawnSync as spawnSync7 } from "node:child_process";
9690
9737
  class ReleaseTrackError extends Error {
9691
9738
  }
9692
9739
  var KNOWN_FIELDS = new Set([
@@ -9971,7 +10018,7 @@ function resolveReleaseTrack(input) {
9971
10018
  return fallback(`${branch} has the same or unrelated fork points with ${[...new Set(newest.map((fork) => `${fork.ref} (${fork.track.name === IMPLICIT ? "workspace default" : fork.track.name})`))].join(" and ")}`);
9972
10019
  }
9973
10020
  var git2 = (cwd, args) => {
9974
- const run = spawnSync6("git", args, {
10021
+ const run = spawnSync7("git", args, {
9975
10022
  cwd,
9976
10023
  encoding: "utf8",
9977
10024
  timeout: 20000,
@@ -10120,7 +10167,7 @@ var remoteEndpoint = (remote) => {
10120
10167
  var configuredSshEndpoint = (host) => {
10121
10168
  if (host.startsWith("-"))
10122
10169
  return null;
10123
- const resolved = spawnSync7("ssh", ["-G", host], {
10170
+ const resolved = spawnSync8("ssh", ["-G", host], {
10124
10171
  encoding: "utf8",
10125
10172
  timeout: 5000,
10126
10173
  maxBuffer: 1024 * 1024,
@@ -10334,7 +10381,7 @@ function mergedPrStyle(limit = 6, cwd) {
10334
10381
  `).filter((l) => l.startsWith("## ")).map((l) => l.trim()),
10335
10382
  descriptionPreview: desc.slice(0, 600)
10336
10383
  });
10337
- const remoteResult = spawnSync7("git", ["remote", "get-url", "--push", "--all", "origin"], {
10384
+ const remoteResult = spawnSync8("git", ["remote", "get-url", "--push", "--all", "origin"], {
10338
10385
  cwd,
10339
10386
  encoding: "utf8"
10340
10387
  });
@@ -10350,7 +10397,7 @@ function mergedPrStyle(limit = 6, cwd) {
10350
10397
  if (!hostingApiHostMatches(remote, host))
10351
10398
  return { ok: false, error: "PR style target does not match the provider host" };
10352
10399
  if (provider === "gitlab") {
10353
- const run = (args) => spawnSync7("glab", ["api", ...args], {
10400
+ const run = (args) => spawnSync8("glab", ["api", ...args], {
10354
10401
  cwd,
10355
10402
  encoding: "utf8",
10356
10403
  env
@@ -10370,7 +10417,7 @@ function mergedPrStyle(limit = 6, cwd) {
10370
10417
  });
10371
10418
  }
10372
10419
  } else if (provider === "github") {
10373
- const r = spawnSync7("gh", [
10420
+ const r = spawnSync8("gh", [
10374
10421
  "pr",
10375
10422
  "list",
10376
10423
  "--repo",
@@ -10667,13 +10714,13 @@ var resolveStateDir = () => stateDir(process.env);
10667
10714
  var homePattern = new RegExp(`${escapeRegExp2(os4.homedir())}(?=[/\\\\]|$)|\\$HOME(?=[/\\\\]|$)`, "g");
10668
10715
 
10669
10716
  // packages/workit-core/src/store/paths.ts
10670
- import { spawnSync as spawnSync8 } from "node:child_process";
10717
+ import { spawnSync as spawnSync9 } from "node:child_process";
10671
10718
  import { createHash as createHash6 } from "node:crypto";
10672
10719
  import fs5 from "node:fs";
10673
10720
  import path9 from "node:path";
10674
10721
  var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
10675
10722
  var gitRun = (cwd, args) => {
10676
- const run = spawnSync8("git", args, {
10723
+ const run = spawnSync9("git", args, {
10677
10724
  cwd,
10678
10725
  encoding: "utf8",
10679
10726
  timeout: 20000,
@@ -12152,7 +12199,7 @@ var assetRoot = () => {
12152
12199
  };
12153
12200
 
12154
12201
  // packages/workit-core/src/core/store-lock.ts
12155
- import { spawnSync as spawnSync9 } from "node:child_process";
12202
+ import { spawnSync as spawnSync10 } from "node:child_process";
12156
12203
  import fs11 from "node:fs";
12157
12204
  import { hostname } from "node:os";
12158
12205
  var metadataLockSchema = object({
@@ -12203,7 +12250,7 @@ var readProcStat = (pid) => {
12203
12250
  };
12204
12251
  var psStart = (pid) => {
12205
12252
  try {
12206
- const run = spawnSync9("ps", ["-o", "lstart=", "-p", String(pid)], {
12253
+ const run = spawnSync10("ps", ["-o", "lstart=", "-p", String(pid)], {
12207
12254
  encoding: "utf8",
12208
12255
  timeout: 1000,
12209
12256
  env: { ...process.env, LC_ALL: "C" }
@@ -14211,11 +14258,11 @@ var workerBlocksTransition = (transition, state) => transition === "pause" ? fal
14211
14258
  // packages/workit-core/src/core/task-evaluation.ts
14212
14259
  import { createHash as createHash12 } from "node:crypto";
14213
14260
  import * as fs17 from "node:fs";
14214
- import { spawnSync as spawnSync14 } from "node:child_process";
14261
+ import { spawnSync as spawnSync15 } from "node:child_process";
14215
14262
  import path22 from "node:path";
14216
14263
 
14217
14264
  // packages/workit-core/src/check-config.ts
14218
- import { spawnSync as spawnSync10 } from "node:child_process";
14265
+ import { spawnSync as spawnSync11 } from "node:child_process";
14219
14266
  import fs14 from "node:fs";
14220
14267
  import path17 from "node:path";
14221
14268
  var SCRIPT_CHECKS = ["test", "lint", "typecheck", "check"];
@@ -14280,7 +14327,7 @@ function splitCommand(command) {
14280
14327
  return argv.length ? argv : new Error("empty command");
14281
14328
  }
14282
14329
  var git3 = (cwd, args) => {
14283
- const run = spawnSync10("git", args, {
14330
+ const run = spawnSync11("git", args, {
14284
14331
  cwd,
14285
14332
  encoding: "utf8",
14286
14333
  timeout: 20000,
@@ -14657,19 +14704,19 @@ import { existsSync as existsSync7 } from "node:fs";
14657
14704
  import path21 from "node:path";
14658
14705
 
14659
14706
  // packages/workit-core/src/ledger.ts
14660
- import { spawnSync as spawnSync13 } from "node:child_process";
14707
+ import { spawnSync as spawnSync14 } from "node:child_process";
14661
14708
  import { createHash as createHash11, randomBytes as randomBytes3 } from "node:crypto";
14662
14709
  import fs16 from "node:fs";
14663
14710
  import path20 from "node:path";
14664
14711
 
14665
14712
  // packages/workit-core/src/core/policy/bookkeeping.ts
14666
- import { spawnSync as spawnSync11 } from "node:child_process";
14713
+ import { spawnSync as spawnSync12 } from "node:child_process";
14667
14714
  var OID = /^[0-9a-f]{40,64}$/u;
14668
14715
  var safe = (value) => value.length > 0 && !value.startsWith("-");
14669
14716
  function replayTree(cwd, from, fromFork, toFork) {
14670
14717
  if (![from, fromFork, toFork].every(safe))
14671
14718
  return null;
14672
- const run = spawnSync11("git", ["merge-tree", "--write-tree", "--no-messages", `--merge-base=${fromFork}`, toFork, from], {
14719
+ const run = spawnSync12("git", ["merge-tree", "--write-tree", "--no-messages", `--merge-base=${fromFork}`, toFork, from], {
14673
14720
  cwd,
14674
14721
  encoding: "utf8",
14675
14722
  timeout: GIT_TIMEOUTS.worktree,
@@ -14740,11 +14787,11 @@ function bookkeepingPaths(cwd, input) {
14740
14787
  }
14741
14788
 
14742
14789
  // packages/workit-core/src/core/policy/lane.ts
14743
- import { existsSync as existsSync6, readFileSync as readFileSync6 } from "node:fs";
14790
+ import { existsSync as existsSync6, readFileSync as readFileSync7 } from "node:fs";
14744
14791
  import path18 from "node:path";
14745
14792
 
14746
14793
  // packages/workit-core/src/git/default-base.ts
14747
- import { spawnSync as spawnSync12 } from "node:child_process";
14794
+ import { spawnSync as spawnSync13 } from "node:child_process";
14748
14795
  var safeRef = (value) => value.length > 0 && !value.startsWith("-");
14749
14796
  var trackTrunk = (cwd) => {
14750
14797
  try {
@@ -14794,7 +14841,7 @@ var shorten = (table, full) => {
14794
14841
  return full;
14795
14842
  };
14796
14843
  function refTable(cwd) {
14797
- const run = spawnSync12("git", ["for-each-ref", "--format=%(refname)%00%(objecttype)%00%(*objecttype)%00%(symref)"], { cwd, encoding: "utf8", timeout: 20000, killSignal: "SIGKILL", windowsHide: true });
14844
+ const run = spawnSync13("git", ["for-each-ref", "--format=%(refname)%00%(objecttype)%00%(*objecttype)%00%(symref)"], { cwd, encoding: "utf8", timeout: 20000, killSignal: "SIGKILL", windowsHide: true });
14798
14845
  if (run.status !== 0)
14799
14846
  return null;
14800
14847
  const refs = new Map;
@@ -15395,7 +15442,7 @@ function computeLane(input) {
15395
15442
  }
15396
15443
  function untrackedStat(cwd, file) {
15397
15444
  try {
15398
- const bytes = readFileSync6(path18.join(cwd, file));
15445
+ const bytes = readFileSync7(path18.join(cwd, file));
15399
15446
  if (bytes.includes(0))
15400
15447
  return { path: file, added: 0, deleted: 0, binary: true };
15401
15448
  const text = bytes.toString("utf8");
@@ -15426,7 +15473,7 @@ function cosmeticFiles(cwd, fork, head) {
15426
15473
  let after = blobs.get(entry.newBlob);
15427
15474
  if (!after && head === null && ABSENT.test(entry.newBlob))
15428
15475
  try {
15429
- after = readFileSync6(path18.join(cwd, entry.path));
15476
+ after = readFileSync7(path18.join(cwd, entry.path));
15430
15477
  } catch {
15431
15478
  after = undefined;
15432
15479
  }
@@ -15658,7 +15705,7 @@ var err = (code, error, unblock) => ({
15658
15705
  ...unblock ? { unblock } : {}
15659
15706
  });
15660
15707
  var gitRun2 = (cwd, args, timeoutMs = GIT_TIMEOUTS.local) => {
15661
- const run = spawnSync13("git", args, {
15708
+ const run = spawnSync14("git", args, {
15662
15709
  cwd,
15663
15710
  encoding: "utf8",
15664
15711
  timeout: timeoutMs,
@@ -16995,7 +17042,7 @@ var compareCodeUnits2 = (left, right) => {
16995
17042
  return left.length - right.length;
16996
17043
  };
16997
17044
  var gitPaths = (root) => {
16998
- const result = spawnSync14("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
17045
+ const result = spawnSync15("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
16999
17046
  cwd: root,
17000
17047
  encoding: "buffer"
17001
17048
  });
@@ -17008,7 +17055,7 @@ var gitPaths = (root) => {
17008
17055
  };
17009
17056
  }
17010
17057
  const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path22.sep).join("/")) : [];
17011
- const stagedDeleted = spawnSync14("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
17058
+ const stagedDeleted = spawnSync15("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
17012
17059
  if (stagedDeleted.status !== 0) {
17013
17060
  const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
17014
17061
  if (!/not a git repository/i.test(stderr))
@@ -17139,7 +17186,7 @@ function captureCandidate(root, scope, environment = []) {
17139
17186
  const values = supplied.toSorted((left, right) => compareCodeUnits2(left.name, right.name)).map(({ name, value }) => ({ name, value, refs: [] }));
17140
17187
  if (values.some(({ value }) => value === null))
17141
17188
  completeness = "uncertain";
17142
- const headResult = spawnSync14("git", ["rev-parse", "HEAD"], { cwd: checkout, encoding: "utf8" });
17189
+ const headResult = spawnSync15("git", ["rev-parse", "HEAD"], { cwd: checkout, encoding: "utf8" });
17143
17190
  if (headResult.status !== 0 && !/not a git repository/i.test(headResult.stderr ?? ""))
17144
17191
  completeness = "uncertain";
17145
17192
  const head = headResult.status === 0 ? headResult.stdout.trim() : null;
@@ -17670,7 +17717,7 @@ function briefInspectResult(request, result) {
17670
17717
 
17671
17718
  // packages/workit-core/src/core/model-fallback.ts
17672
17719
  import { createHash as createHash13 } from "node:crypto";
17673
- import { mkdirSync as mkdirSync4, readFileSync as readFileSync8, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
17720
+ import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
17674
17721
  import path23 from "node:path";
17675
17722
  var LIMITS_FILE = "model-limits.json";
17676
17723
  var DEFAULT_LIMIT_WINDOW_MS = 5 * 3600000;
@@ -17697,7 +17744,7 @@ var empty = () => ({ exhausted: {}, seen: {}, redispatched: {} });
17697
17744
  var storePath = (stateDir) => path23.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
17698
17745
  var readStore = (stateDir) => {
17699
17746
  try {
17700
- const parsed = JSON.parse(readFileSync8(storePath(stateDir), "utf8"));
17747
+ const parsed = JSON.parse(readFileSync9(storePath(stateDir), "utf8"));
17701
17748
  const store = empty();
17702
17749
  for (const key of ["exhausted", "seen", "redispatched"])
17703
17750
  if (parsed[key] && typeof parsed[key] === "object")
@@ -18289,19 +18336,18 @@ var exportDigest = (bundle) => sha256({
18289
18336
  task: bundle.task
18290
18337
  });
18291
18338
  // packages/workit-core/src/core/route-intent.ts
18292
- import { spawnSync as spawnSync16 } from "node:child_process";
18339
+ import { spawnSync as spawnSync17 } from "node:child_process";
18293
18340
  import { existsSync as existsSync10 } from "node:fs";
18294
18341
  import path29 from "node:path";
18295
18342
 
18296
18343
  // packages/workit-core/src/hooks/raw-git.ts
18297
- import { spawnSync as spawnSync15 } from "node:child_process";
18344
+ import { spawnSync as spawnSync16 } from "node:child_process";
18298
18345
  import { createHash as createHash15 } from "node:crypto";
18299
18346
  import fs19 from "node:fs";
18300
- import os7 from "node:os";
18347
+ import os6 from "node:os";
18301
18348
  import path28 from "node:path";
18302
18349
 
18303
18350
  // packages/workit-core/src/autonomy.ts
18304
- import os6 from "node:os";
18305
18351
  import path26 from "node:path";
18306
18352
 
18307
18353
  // packages/workit-core/src/core/eval-world.ts
@@ -18314,15 +18360,21 @@ var inside2 = (dir, file) => {
18314
18360
  const rel = path24.relative(dir, file);
18315
18361
  return !rel.startsWith("..") && !path24.isAbsolute(rel);
18316
18362
  };
18317
- var evalWorldEntry = (cwd) => {
18363
+ var evalWorld = (cwd) => {
18318
18364
  const raw = process.env[EVAL_WORLD_ENV];
18319
18365
  if (!raw || !path24.isAbsolute(raw))
18320
18366
  return null;
18321
18367
  try {
18322
18368
  const world = realpathSync5(raw);
18323
- if (!inside2(realpathSync5(os5.tmpdir()), world) || !inside2(world, realpathSync5(cwd)) || !existsSync9(path24.join(world, EVAL_WORLD_MARKER)))
18324
- return null;
18325
- return loadWorkspacesFrom(path24.join(world, "config"))[0] ?? null;
18369
+ return inside2(realpathSync5(os5.tmpdir()), world) && inside2(world, realpathSync5(cwd)) && existsSync9(path24.join(world, EVAL_WORLD_MARKER)) ? world : null;
18370
+ } catch {
18371
+ return null;
18372
+ }
18373
+ };
18374
+ var evalWorldEntry = (cwd) => {
18375
+ const world = evalWorld(cwd);
18376
+ try {
18377
+ return world ? loadWorkspacesFrom(path24.join(world, "config"))[0] ?? null : null;
18326
18378
  } catch {
18327
18379
  return null;
18328
18380
  }
@@ -18396,15 +18448,22 @@ function writeFileAtomic(file, content, mode) {
18396
18448
  }
18397
18449
 
18398
18450
  // packages/workit-core/src/autonomy.ts
18399
- var accountHome2 = () => {
18400
- try {
18401
- return os6.userInfo().homedir;
18402
- } catch {
18403
- return os6.homedir();
18404
- }
18451
+ var grantsHome = { resolve: accountHome };
18452
+ var accountDir = () => {
18453
+ const home = grantsHome.resolve();
18454
+ return home === null ? null : configDir({ HOME: home });
18455
+ };
18456
+ var grantsDir = () => accountDir() ?? resolveConfigDir();
18457
+ var NO_ACCOUNT = "no OS account record answered (core/account-home.ts), so no grants are read: the D4 defaults apply";
18458
+ var entriesIn = (dir) => dir === null ? [] : loadWorkspacesFrom(dir);
18459
+ var resolveFrom = (cwd, name) => {
18460
+ const dir = accountDir();
18461
+ return dir === null ? null : resolveWorkspaceFrom(cwd, dir, name);
18462
+ };
18463
+ var shownGrantsDir = () => {
18464
+ const world = evalWorld(process.cwd());
18465
+ return world ? path26.join(world, "config") : accountDir();
18405
18466
  };
18406
- var grantsHome = { resolve: accountHome2 };
18407
- var grantsDir = () => configDir({ HOME: grantsHome.resolve() });
18408
18467
  var benchWorld = (cwd) => {
18409
18468
  const entry = evalWorldEntry(cwd);
18410
18469
  if (!entry)
@@ -18424,8 +18483,11 @@ var benchWorld = (cwd) => {
18424
18483
  };
18425
18484
  };
18426
18485
  var grantsOverride = () => {
18486
+ const shown = shownGrantsDir();
18487
+ if (shown === null)
18488
+ return NO_ACCOUNT;
18427
18489
  const configured = path26.resolve(resolveConfigDir());
18428
- return configured === path26.resolve(grantsDir()) ? null : `the config directory is redirected to ${configured} (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), but that override does not apply to grants: grants are read only from ${path26.join(grantsDir(), "workspaces.json")}, so the D4 defaults apply until grants are set there`;
18490
+ return configured === path26.resolve(shown) ? null : `the config directory is redirected to ${configured} (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), but that override does not apply to grants: grants are read only from ${path26.join(grantsDir(), "workspaces.json")}, so the D4 defaults apply until grants are set there`;
18429
18491
  };
18430
18492
  var GRANT_KINDS = ["push", "pr", "merge", "release", "rerun"];
18431
18493
  var DEFAULT_GRANTS = Object.freeze({
@@ -18551,7 +18613,7 @@ function capAt(named, where, by, why, main = false) {
18551
18613
  try {
18552
18614
  if (where instanceof Error)
18553
18615
  throw where;
18554
- folder = autonomyOf(typeof where === "string" ? resolveWorkspaceFrom(where, grantsDir()) : where.entry);
18616
+ folder = autonomyOf(typeof where === "string" ? resolveFrom(where) : where.entry);
18555
18617
  } catch (error) {
18556
18618
  none = error.message;
18557
18619
  }
@@ -18595,7 +18657,10 @@ function resolveAutonomy(cwd, target) {
18595
18657
  if (override)
18596
18658
  return { ...autonomyOf(null), note: override };
18597
18659
  const name = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
18598
- let autonomy = autonomyOf(resolveWorkspaceFrom(cwd, grantsDir(), name) ?? world);
18660
+ const real = resolveFrom(cwd, name);
18661
+ let autonomy = autonomyOf(real ?? world);
18662
+ if (!real && world)
18663
+ autonomy.world = evalWorld(cwd) ?? undefined;
18599
18664
  if (name)
18600
18665
  autonomy = capAt(autonomy, cwd, `WORKIT_WORKSPACE_NAME=${name}`, "a name never raises grants");
18601
18666
  const above = checkoutsAbove(cwd);
@@ -18604,7 +18669,7 @@ function resolveAutonomy(cwd, target) {
18604
18669
  return capAtRemotes(autonomy, cwd, target);
18605
18670
  }
18606
18671
  function capAtRemotes(autonomy, cwd, target) {
18607
- const claiming = loadWorkspacesFrom(grantsDir()).filter((entry) => entry.remotes?.length);
18672
+ const claiming = entriesIn(accountDir()).filter((entry) => entry.remotes?.length);
18608
18673
  if (claiming.length === 0)
18609
18674
  return autonomy;
18610
18675
  const remotes = target === undefined ? checkoutRemotes(cwd) : typeof target === "function" ? target() : target;
@@ -18619,15 +18684,15 @@ function capAtRemotes(autonomy, cwd, target) {
18619
18684
  }
18620
18685
  return capped;
18621
18686
  }
18622
- var grantsMatter = (kind) => !grantsOverride() && loadWorkspacesFrom(grantsDir()).some((entry) => {
18687
+ var grantsMatter = (kind) => !grantsOverride() && entriesIn(accountDir()).some((entry) => {
18623
18688
  const autonomy = autonomyOf(entry);
18624
18689
  return entry.remotes?.length || autonomy.grants[kind] === false || autonomy.configured.length > 0 && !autonomy.accountConfigured;
18625
18690
  });
18626
- var remotesClaimed = (dir = grantsDir()) => loadWorkspacesFrom(dir).some((entry) => entry.remotes?.length);
18627
- function targetClaims(target, dir = grantsDir()) {
18691
+ var remotesClaimed = (dir = accountDir()) => entriesIn(dir).some((entry) => entry.remotes?.length);
18692
+ function targetClaims(target, dir = accountDir()) {
18628
18693
  if (target instanceof Error)
18629
18694
  return target;
18630
- const claiming = loadWorkspacesFrom(dir).filter((entry) => entry.remotes?.length);
18695
+ const claiming = entriesIn(dir).filter((entry) => entry.remotes?.length);
18631
18696
  return target.remotes.flatMap((remote) => claiming.flatMap((entry) => {
18632
18697
  const pattern = entry.remotes.find((item) => remoteMatches(item, remote.key));
18633
18698
  return pattern ? [{ url: remote.url, workspace: entry.name, pattern }] : [];
@@ -18665,7 +18730,7 @@ function rawGrantDenial(cwd, kind, target) {
18665
18730
  const claims = targetClaims(lazy());
18666
18731
  if (claims instanceof Error)
18667
18732
  return { error: `${kind}: ${claims.message}`, unblock: "name a target workit can resolve" };
18668
- const entries = loadWorkspacesFrom(grantsDir());
18733
+ const entries = entriesIn(accountDir());
18669
18734
  const strict = claims.find(({ workspace: name }) => {
18670
18735
  const entry = entries.find((item) => item.name === name);
18671
18736
  return entry && autonomyOf(entry).grants[kind] === false;
@@ -19073,7 +19138,9 @@ var tokenize = (command, dialect) => {
19073
19138
  heredocs.push({ delimiter: text.replace(/^-/, ""), owner: current });
19074
19139
  else if (pending === "herestring")
19075
19140
  (current.stdin ??= []).push(text);
19076
- else if (pending !== "input") {
19141
+ else if (pending === "input")
19142
+ (current.inputs ??= []).push(text);
19143
+ else {
19077
19144
  const at = current.words.length;
19078
19145
  current.words.push(...MARKERS.test(word) ? expandBraces(word) : [word]);
19079
19146
  if (expanding || !posix && word.startsWith("@"))
@@ -19319,7 +19386,7 @@ var joinDir = (base, raw) => {
19319
19386
  const next = raw.replace(HERE, ".");
19320
19387
  if (base === undefined || /[$`*?]/.test(next) || next === "-")
19321
19388
  return;
19322
- const expanded = next === "~" || next.startsWith("~/") ? path28.join(os7.homedir(), next.slice(1)) : next;
19389
+ const expanded = next === "~" || next.startsWith("~/") ? path28.join(os6.homedir(), next.slice(1)) : next;
19323
19390
  return base === null || isAbsolute(expanded) ? expanded : path28.join(base, expanded);
19324
19391
  };
19325
19392
  var rebase = (base, inner) => inner === null ? base : inner === undefined ? undefined : joinDir(base, inner);
@@ -19721,7 +19788,7 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
19721
19788
  }
19722
19789
  if (CD.has(name)) {
19723
19790
  const target = cdTarget(words);
19724
- dir = target === null ? os7.homedir() : joinDir(dir, target);
19791
+ dir = target === null ? os6.homedir() : joinDir(dir, target);
19725
19792
  } else if (PUSHD.has(name)) {
19726
19793
  const target = cdTarget(words);
19727
19794
  stack.push(dir);
@@ -20264,7 +20331,7 @@ var gitConfig = (dir, invocation, cache) => {
20264
20331
  if (cached)
20265
20332
  return cached;
20266
20333
  const config = new Map;
20267
- const listed = spawnSync15("git", [...invocation.config ?? [], "config", "-z", "--list"], {
20334
+ const listed = spawnSync16("git", [...invocation.config ?? [], "config", "-z", "--list"], {
20268
20335
  cwd: dir,
20269
20336
  encoding: "utf8",
20270
20337
  timeout: 3000,
@@ -20437,7 +20504,7 @@ var refFacts = (repo, remote) => {
20437
20504
  tags: new Set,
20438
20505
  remoteHeads: new Set
20439
20506
  };
20440
- const listed = spawnSync15("git", ["for-each-ref", "--format=%(refname)", "refs/heads", "refs/tags", `refs/remotes/${remote}`], { cwd: repo.dir, encoding: "utf8", timeout: 5000 });
20507
+ const listed = spawnSync16("git", ["for-each-ref", "--format=%(refname)", "refs/heads", "refs/tags", `refs/remotes/${remote}`], { cwd: repo.dir, encoding: "utf8", timeout: 5000 });
20441
20508
  const remotePrefix = `refs/remotes/${remote}/`;
20442
20509
  for (const ref of (listed.stdout ?? "").split(`
20443
20510
  `)) {
@@ -20454,7 +20521,7 @@ var globBranches = (repo, glob) => {
20454
20521
  const source = glob.source.startsWith("refs/") ? glob.source : `refs/heads/${glob.source}`;
20455
20522
  const [sourcePrefix, sourceSuffix = ""] = source.split("*");
20456
20523
  const [destinationPrefix, destinationSuffix = ""] = glob.destination.split("*");
20457
- const listed = spawnSync15("git", [
20524
+ const listed = spawnSync16("git", [
20458
20525
  "for-each-ref",
20459
20526
  "--format=%(refname)",
20460
20527
  sourcePrefix.slice(0, sourcePrefix.lastIndexOf("/") + 1)
@@ -20531,7 +20598,7 @@ var tagRefusal = (action, facts, dir) => {
20531
20598
  return `workit: raw ${quote(`git push${action.allTags ? " --tags" : ""}`)} of ${tags.length ? `tag ${tags.join(", ")}` : "tags"} bypasses the release grant. Push a release tag with ${quote(`workit git push --release ${named}`)} (${shape} tags whose commit the production branch already has; a tag never moves), under the ${quote("release")} grant (if refused, ask the user to run ${quote("workit grant set <workspace> release=true")}).`;
20532
20599
  };
20533
20600
  var remoteHeads = (repo, remote) => {
20534
- const listed = spawnSync15("git", ["ls-remote", "--heads", remote], {
20601
+ const listed = spawnSync16("git", ["ls-remote", "--heads", remote], {
20535
20602
  cwd: repo.dir,
20536
20603
  encoding: "utf8",
20537
20604
  timeout: 3000,
@@ -20752,7 +20819,7 @@ var cdCommitCall = (input, command, target, repo) => {
20752
20819
  if (!messages.length)
20753
20820
  return null;
20754
20821
  if (!all) {
20755
- const staged = spawnSync15("git", ["diff", "--cached", "--quiet"], {
20822
+ const staged = spawnSync16("git", ["diff", "--cached", "--quiet"], {
20756
20823
  cwd: target,
20757
20824
  timeout: 5000
20758
20825
  });
@@ -20914,7 +20981,7 @@ function noteRawCommit(input, command, key) {
20914
20981
  } catch {}
20915
20982
  }
20916
20983
  var headCommit = (dir) => {
20917
- const run = spawnSync15("git", [
20984
+ const run = spawnSync16("git", [
20918
20985
  "log",
20919
20986
  "-1",
20920
20987
  "--format=%H%x1f%ct%x1f%s%x1f%(trailers:key=Workit-Session,valueonly,separator=%x2c)"
@@ -21138,7 +21205,7 @@ var targetsOf = (invocations) => invocations.flatMap((invocation) => invocation.
21138
21205
  branch,
21139
21206
  dir: invocation.dir
21140
21207
  })) : []);
21141
- var localBranchExists = (dir, branch) => spawnSync16("git", ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`], {
21208
+ var localBranchExists = (dir, branch) => spawnSync17("git", ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`], {
21142
21209
  cwd: dir,
21143
21210
  stdio: "ignore",
21144
21211
  timeout: 5000
@@ -23144,8 +23211,8 @@ class WorkitCore {
23144
23211
  }
23145
23212
  }
23146
23213
  // packages/workit-core/src/core/repo-context.ts
23147
- import { spawnSync as spawnSync17 } from "node:child_process";
23148
- import { existsSync as existsSync11, readFileSync as readFileSync9, readdirSync as readdirSync4 } from "node:fs";
23214
+ import { spawnSync as spawnSync18 } from "node:child_process";
23215
+ import { existsSync as existsSync11, readFileSync as readFileSync10, readdirSync as readdirSync4 } from "node:fs";
23149
23216
  import path30 from "node:path";
23150
23217
  var isSafeContextRange = (value) => value.length <= 4096 && (() => {
23151
23218
  try {
@@ -23173,7 +23240,7 @@ var invalidRange = (cwd) => ({
23173
23240
  cwd
23174
23241
  });
23175
23242
  var runGit = (cwd, args) => {
23176
- const result = spawnSync17("git", args, { cwd, encoding: "utf8" });
23243
+ const result = spawnSync18("git", args, { cwd, encoding: "utf8" });
23177
23244
  return {
23178
23245
  stdout: (result.stdout ?? "").trimEnd(),
23179
23246
  stderr: (result.stderr ?? "").trimEnd(),
@@ -23330,7 +23397,7 @@ var packageScripts = (cwd, keys) => {
23330
23397
  if (!existsSync11(pkgPath))
23331
23398
  return [];
23332
23399
  try {
23333
- const pkg = JSON.parse(readFileSync9(pkgPath, "utf8"));
23400
+ const pkg = JSON.parse(readFileSync10(pkgPath, "utf8"));
23334
23401
  return keys.filter((k) => pkg.scripts && typeof pkg.scripts[k] === "string").map((k) => `${k}: ${pkg.scripts?.[k]}`);
23335
23402
  } catch {
23336
23403
  return [];
@@ -23364,7 +23431,7 @@ var documentationFiles = (cwd) => {
23364
23431
  var readTrimmed2 = (file, maxLines) => {
23365
23432
  if (!existsSync11(file))
23366
23433
  return "";
23367
- const lines = readFileSync9(file, "utf8").split(`
23434
+ const lines = readFileSync10(file, "utf8").split(`
23368
23435
  `);
23369
23436
  return lines.slice(0, maxLines).join(`
23370
23437
  `);
@@ -23552,7 +23619,7 @@ function docsRefreshContext(root, range) {
23552
23619
  const pkgPath = path30.join(cwd, "package.json");
23553
23620
  if (existsSync11(pkgPath)) {
23554
23621
  try {
23555
- const pkg = JSON.parse(readFileSync9(pkgPath, "utf8"));
23622
+ const pkg = JSON.parse(readFileSync10(pkgPath, "utf8"));
23556
23623
  stdout += JSON.stringify({ name: pkg.name, version: pkg.version, scripts: pkg.scripts }, null, 2) + `
23557
23624
  `;
23558
23625
  } catch {}
@@ -23634,12 +23701,12 @@ function releaseNotesContext(root, rangeOrTag) {
23634
23701
  }
23635
23702
 
23636
23703
  // packages/workit-core/src/core/tracker-issues.ts
23637
- import { spawnSync as spawnSync19 } from "node:child_process";
23704
+ import { spawnSync as spawnSync20 } from "node:child_process";
23638
23705
 
23639
23706
  // packages/workit-core/src/core/pr-create.ts
23640
23707
  import fs20 from "node:fs";
23641
23708
  import path31 from "node:path";
23642
- import { spawnSync as spawnSync18 } from "node:child_process";
23709
+ import { spawnSync as spawnSync19 } from "node:child_process";
23643
23710
  // packages/workit-core/src/forge/pr-body.ts
23644
23711
  function parseGhIssue(value) {
23645
23712
  const m = /issues\/(\d+)/.exec(value);
@@ -23673,7 +23740,7 @@ function whichOnPath(tool) {
23673
23740
  }
23674
23741
  var hostingCliAvailable = (provider) => whichOnPath(provider === "gitlab" ? "glab" : "gh") !== null;
23675
23742
  var pushRemote = (cwd) => {
23676
- const result = spawnSync18("git", ["remote", "get-url", "--push", "--all", "origin"], {
23743
+ const result = spawnSync19("git", ["remote", "get-url", "--push", "--all", "origin"], {
23677
23744
  cwd,
23678
23745
  ...LOCAL
23679
23746
  });
@@ -23704,7 +23771,7 @@ var defaultCli = (bin, available) => {
23704
23771
  if (!available)
23705
23772
  return null;
23706
23773
  return (args, root) => {
23707
- const out = spawnSync19(bin, args, {
23774
+ const out = spawnSync20(bin, args, {
23708
23775
  cwd: root,
23709
23776
  encoding: "utf8",
23710
23777
  env: { ...process.env, PATH: process.env.PATH ?? "" }
@@ -23794,7 +23861,7 @@ var ASSET_ROOT = assetRoot();
23794
23861
  var resolveWorkspaceRoot = (explicit) => explicit || process.cwd();
23795
23862
 
23796
23863
  // packages/workit-core/src/core/youtrack-ytrack.ts
23797
- import { spawnSync as spawnSync20 } from "node:child_process";
23864
+ import { spawnSync as spawnSync21 } from "node:child_process";
23798
23865
 
23799
23866
  // packages/workit-core/src/forge/exec.ts
23800
23867
  import fs21 from "node:fs";
@@ -23832,7 +23899,7 @@ function ytrackRunner(env, host, timeoutMs = TIMEOUT_MS) {
23832
23899
  const exe = findYtrack(env);
23833
23900
  if (!exe)
23834
23901
  return { status: null, stdout: "", stderr: "", missing: true };
23835
- const result = spawnSync20(exe, args, {
23902
+ const result = spawnSync21(exe, args, {
23836
23903
  encoding: "utf8",
23837
23904
  env: { ...env, NO_COLOR: "1", ...host ? { YTRACK_HOST: host } : {} },
23838
23905
  timeout: timeoutMs,
@@ -24239,7 +24306,7 @@ function resolveInside(root, candidate) {
24239
24306
  }
24240
24307
  function run2(root, executable, args, env = {}) {
24241
24308
  const cwd = realpathSync8(root);
24242
- const result = spawnSync21(executable, args, {
24309
+ const result = spawnSync22(executable, args, {
24243
24310
  cwd,
24244
24311
  encoding: "utf8",
24245
24312
  env: { ...process.env, ...env }
@@ -24631,7 +24698,7 @@ var userOnlyWorkitCall = (command, dialect = "posix") => {
24631
24698
  };
24632
24699
  // packages/workit-core/src/core/heavy-rules.ts
24633
24700
  import fs24 from "node:fs";
24634
- import os8 from "node:os";
24701
+ import os7 from "node:os";
24635
24702
  import path36 from "node:path";
24636
24703
  var EMPTY2 = () => ({ deny: [], allow: [] });
24637
24704
  var readText3 = (file) => {
@@ -24689,7 +24756,7 @@ var projectDirs = (cwd) => {
24689
24756
  return dirs;
24690
24757
  }
24691
24758
  };
24692
- var homeOf = (env) => env.HOME || os8.homedir();
24759
+ var homeOf = (env) => env.HOME || os7.homedir();
24693
24760
  var CLAUDE_MANAGED = {
24694
24761
  linux: "/etc/claude-code/managed-settings.json",
24695
24762
  darwin: "/Library/Application Support/ClaudeCode/managed-settings.json",
@@ -25420,21 +25487,21 @@ var splitDenial = (plan) => ({
25420
25487
  unblock: plan.unblock
25421
25488
  });
25422
25489
  // packages/workit-core/src/hooks/write-gate.ts
25423
- import { existsSync as existsSync13, realpathSync as realpathSync9, statSync as statSync4 } from "node:fs";
25424
- import os10 from "node:os";
25490
+ import { existsSync as existsSync13, readdirSync as readdirSync5, readFileSync as readFileSync11, realpathSync as realpathSync9, statSync as statSync4 } from "node:fs";
25491
+ import os9 from "node:os";
25425
25492
  import path40 from "node:path";
25426
25493
 
25427
25494
  // packages/workit-core/src/core/live-session.ts
25428
- import { spawnSync as spawnSync22 } from "node:child_process";
25495
+ import { spawnSync as spawnSync23 } from "node:child_process";
25429
25496
  import { createHash as createHash17 } from "node:crypto";
25430
25497
  import fs27 from "node:fs";
25431
- import os9 from "node:os";
25498
+ import os8 from "node:os";
25432
25499
  import path39 from "node:path";
25433
25500
  var LIVE_SESSION_TTL_MS = 15 * 60000;
25434
25501
  var HEARTBEAT_EVERY_MS = 30000;
25435
25502
  var liveProbe = {
25436
25503
  platform: process.platform,
25437
- run: (args) => spawnSync22("ps", args, { encoding: "utf8", timeout: 2000 }).stdout ?? "",
25504
+ run: (args) => spawnSync23("ps", args, { encoding: "utf8", timeout: 2000 }).stdout ?? "",
25438
25505
  start: (pid) => processStartOf(pid)
25439
25506
  };
25440
25507
  var leadOf = (session) => session.split(":")[0].replace(/-w-.*$/su, "") || session;
@@ -25554,7 +25621,7 @@ var isLive = (marker, deps) => {
25554
25621
  const age = ageOf2(marker, deps.now ?? new Date);
25555
25622
  if (age > (deps.ttlMs ?? LIVE_SESSION_TTL_MS))
25556
25623
  return false;
25557
- if (marker.machine !== (deps.machine ?? os9.hostname()) || marker.pid === null)
25624
+ if (marker.machine !== (deps.machine ?? os8.hostname()) || marker.pid === null)
25558
25625
  return true;
25559
25626
  if (!(deps.alive ?? processAlive)(marker.pid))
25560
25627
  return false;
@@ -25583,7 +25650,7 @@ var liveConflict = (target, owner, deps = {}) => {
25583
25650
  const marker = readMarker(file);
25584
25651
  if (!marker || sameLead(marker, owner) || !isLive(marker, deps))
25585
25652
  return null;
25586
- if (sameOwner(marker, owner, deps.machine ?? os9.hostname()))
25653
+ if (sameOwner(marker, owner, deps.machine ?? os8.hostname()))
25587
25654
  return null;
25588
25655
  return { marker, file, ageMs: ageOf2(marker, deps.now ?? new Date), checkout };
25589
25656
  } catch {
@@ -25597,7 +25664,7 @@ var claimLiveSession = (target, owner, deps = {}) => {
25597
25664
  return;
25598
25665
  const file = markerFile2(checkout);
25599
25666
  const now = deps.now ?? new Date;
25600
- const machine = deps.machine ?? os9.hostname();
25667
+ const machine = deps.machine ?? os8.hostname();
25601
25668
  const current = readMarker(file);
25602
25669
  if (current) {
25603
25670
  const age = ageOf2(current, now);
@@ -25686,9 +25753,9 @@ var editsOf = (input) => {
25686
25753
  case "cp":
25687
25754
  case "ln":
25688
25755
  case "install": {
25689
- const target = args.indexOf("-t");
25690
- if (target >= 0)
25691
- return args[target + 1] ? [args[target + 1]] : null;
25756
+ const into = valueOf(args, /^(?:-t|--target-directory=?)(.*)$/s);
25757
+ if (into !== undefined)
25758
+ return [into];
25692
25759
  const last = operands(args).at(-1);
25693
25760
  return last ? [last] : null;
25694
25761
  }
@@ -25742,6 +25809,84 @@ var editsOf = (input) => {
25742
25809
  return [];
25743
25810
  }
25744
25811
  };
25812
+ var WRAPPERS2 = {
25813
+ sudo: "ugCDhpRrTtU",
25814
+ doas: "uC",
25815
+ env: "uCS",
25816
+ nice: "n",
25817
+ ionice: "cnp",
25818
+ timeout: "sk",
25819
+ stdbuf: "ioe",
25820
+ time: "fo",
25821
+ nohup: "",
25822
+ command: "",
25823
+ exec: "a",
25824
+ setsid: "",
25825
+ builtin: "",
25826
+ "!": "",
25827
+ npx: "p",
25828
+ bunx: "p"
25829
+ };
25830
+ var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php|tsx|ts-node)$/;
25831
+ var isConfigDir = (file) => configDirs().some((dir) => canonical3(dir) === canonical3(file));
25832
+ var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals)$/.test(path40.relative(canonical3(resolveStateDir()), canonical3(file)));
25833
+ var READ_CALLS = /^(?:print|log|info|warn|error|debug|puts|readdir(?:Sync)?|listdir|scandir|iterdir|glob|l?stat(?:Sync)?|exists(?:Sync)?|isdir|isfile|is_dir|is_file|access(?:Sync)?|realpath(?:Sync)?|dirname|basename|relative|str|repr|len)$/;
25834
+ var MUTATING_CALLS = /^(?:renames?(?:Sync)?|move|copy(?:2|file|tree|File)?(?:Sync)?|cp(?:Sync)?|rm(?:tree|dir|Sync|dirSync)?|unlink(?:Sync)?|remove(?:dirs)?|mkdirs?(?:Sync)?|makedirs|mkdtemp(?:Sync)?|(?:sym|hard)?link(?:Sync|_to)?|write\w*|append\w*|truncate(?:Sync)?|ch(?:mod|own)(?:Sync)?|touch|open(?:Sync)?|dump|save|extractall|unpack_archive|put_contents|mv|FileUtils)$/;
25835
+ var PATH_CALLS = /^(?:join|resolve|normalize|abspath|expanduser|expandvars|Path|PurePath|fspath)$/;
25836
+ var readsRoot = (text, at) => {
25837
+ let call;
25838
+ for (let index = at, depth = 0;index > 0 && call === undefined; index--) {
25839
+ const char = text[index - 1];
25840
+ if (char === ")")
25841
+ depth++;
25842
+ else if (char === "(" && depth-- === 0)
25843
+ call = /([\w$]+)\s*$/.exec(text.slice(0, index - 1))?.[1] ?? "";
25844
+ else if (depth <= 0 && /[;\n]/.test(char))
25845
+ break;
25846
+ }
25847
+ if (call !== undefined && READ_CALLS.test(call))
25848
+ return true;
25849
+ if (call !== undefined && !PATH_CALLS.test(call))
25850
+ return false;
25851
+ return ![...text.matchAll(/([\w$]+)\s*\(/g)].some(([, name]) => MUTATING_CALLS.test(name));
25852
+ };
25853
+ var inertEdit = (command) => command.split("|").every((part) => /^:?(?:se(?:t)?|sy(?:ntax)?|colo(?:rscheme)?)(?:\s|$)|^[/?][^/?]*[/?]?$|^\d+$/.test(part.trim()));
25854
+ var SCRIPT_OPTIONS = [
25855
+ [/^(?:(?:ba|z|k|da)?sh|source|\.)$/, /^(?:[-+][oO]|--(?:rcfile|init-file))$/],
25856
+ [/^python/, /^-[WXQ]$/],
25857
+ [
25858
+ /./,
25859
+ /^(?:-[rCI]|--(?:require|import|(?:experimental-)?loader|preload|input-type|conditions|title|cwd|tsconfig|project|env-file|config))$/
25860
+ ]
25861
+ ];
25862
+ var PRELOAD = /^(?:-r|--(?:require|import|(?:experimental-)?loader|preload|rcfile|init-file))$/;
25863
+ var scriptArgs = (verb, args) => {
25864
+ const takes = SCRIPT_OPTIONS.find(([family]) => family.test(verb))?.[1] ?? /^$/;
25865
+ const preloads = [];
25866
+ for (let at = 0;at < args.length; at++) {
25867
+ const [option, value] = args[at].split(/=(.*)/s);
25868
+ if (value !== undefined && PRELOAD.test(option))
25869
+ preloads.push(value);
25870
+ else if (/^-[mce]$|^--(?:eval|print)$/.test(option))
25871
+ break;
25872
+ else if (takes.test(option)) {
25873
+ if (PRELOAD.test(option))
25874
+ preloads.push(args[at + 1] ?? "");
25875
+ at++;
25876
+ } else if (!/^[-+]/.test(option) && option !== "run")
25877
+ return { named: args[at], preloads };
25878
+ }
25879
+ return { preloads };
25880
+ };
25881
+ var unwrapped = (words) => {
25882
+ let at = 0;
25883
+ for (let takes;(takes = WRAPPERS2[words[at]?.split(/[\\/]/).at(-1) ?? ""]) !== undefined; ) {
25884
+ at++;
25885
+ while (at < words.length && /^-|^\w+=|^\d[\w.]*$/.test(words[at]))
25886
+ at += words[at].length === 2 && words[at][0] === "-" && takes.includes(words[at][1]) ? 2 : 1;
25887
+ }
25888
+ return at ? words.slice(at) : null;
25889
+ };
25745
25890
  var shellScript2 = (words) => {
25746
25891
  if (!SCRIPT_SHELLS.has((words[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()))
25747
25892
  return null;
@@ -25986,9 +26131,8 @@ var gitOutputs = (args) => {
25986
26131
  const under = (file) => file === "." ? `${base}/${OPAQUE_TARGET}git` : /^[/~$]|^[A-Za-z]:[\\/]/.test(file) ? file : `${base}/${file}`;
25987
26132
  return files.length ? files.map(under) : null;
25988
26133
  };
25989
- var pathsIn = (text) => [
25990
- ...text.matchAll(/(?<![\w.~:/$-])(?:~\/|\/|[A-Za-z]:\/|\.\.(?:\/|$))[^\s'"`$),;:*?<>|\\[\]{}]*/g)
25991
- ].map((match) => match[0]);
26134
+ var PATHS = /(?<![\w.~:/$-])(?:~\/|\/|[A-Za-z]:\/|\.\.(?:\/|$))[^\s'"`$),;:*?<>|\\[\]{}]*/g;
26135
+ var pathsIn = (text) => [...text.matchAll(PATHS)].map((match) => match[0]);
25992
26136
  var linkSources = (args, at) => {
25993
26137
  const names = operands([...args]);
25994
26138
  const into = args.indexOf("-t");
@@ -26115,16 +26259,16 @@ var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
26115
26259
  var PUSHD2 = new Set(["pushd", "push-location"]);
26116
26260
  var POPD2 = new Set(["popd", "pop-location"]);
26117
26261
  var UNKNOWN_DIR = path40.resolve(path40.parse(process.cwd()).root, ".workit-unknown-dir");
26118
- var cdInto = (dir, words, strict = false, vars = new Map) => {
26262
+ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
26119
26263
  const lost = strict ? UNKNOWN_DIR : undefined;
26120
26264
  const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
26121
26265
  const named = found === undefined ? undefined : expandVars(found, vars);
26122
26266
  const target = named === undefined ? undefined : homeExpanded(named);
26123
- if (target === "-" || target && /^~|[$`*?]/.test(target))
26267
+ if (target === "-" || target && (globs ? /^~|[$`]/ : /^~|[$`*?]/).test(target))
26124
26268
  return lost;
26125
26269
  if (dir === undefined)
26126
26270
  return lost;
26127
- return target === undefined ? os10.homedir() : path40.resolve(dir, target);
26271
+ return target === undefined ? os9.homedir() : path40.resolve(dir, target);
26128
26272
  };
26129
26273
  var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
26130
26274
  var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
@@ -26143,7 +26287,8 @@ var assignmentsOf = (words) => {
26143
26287
  var commandWords = (words) => {
26144
26288
  let start = 0;
26145
26289
  while (start < words.length && COMPOUND.has(words[start]))
26146
- start++;
26290
+ if (words[start++] === "function")
26291
+ start++;
26147
26292
  return words.slice(start);
26148
26293
  };
26149
26294
  var REBINDS_ANY = new Set([
@@ -26295,7 +26440,8 @@ var expansions = (text, vars, loops) => {
26295
26440
  last = match.index + match[0].length;
26296
26441
  const value = vars.get(name);
26297
26442
  const values = loops.get(name) ?? (value === undefined ? null : [value]);
26298
- const applied = values?.map((item) => applyOperator(item, match[2] ?? ""));
26443
+ const fallback = /^:?[-=](.*)$/s.exec(match[2] ?? "")?.[1];
26444
+ const applied = values?.flatMap((item) => fallback === undefined ? [applyOperator(item, match[2] ?? "")] : item === "" ? expansions(fallback, vars, loops) : [item]);
26299
26445
  const fits = applied && results.length * applied.length <= MAX_EXPANSIONS2;
26300
26446
  results = fits && applied.every((item) => item !== null) ? results.flatMap((prefix) => applied.map((item) => prefix + literal + item)) : results.map((prefix) => prefix + literal + match[0]);
26301
26447
  }
@@ -26326,7 +26472,7 @@ var mktempPath = (value, dir) => {
26326
26472
  template = arg;
26327
26473
  }
26328
26474
  if (base === null && (temp || template === undefined))
26329
- base = os10.tmpdir();
26475
+ base = os9.tmpdir();
26330
26476
  const name = homeExpanded(template ?? "tmp.XXXXXXXXXX");
26331
26477
  if (path40.isAbsolute(name))
26332
26478
  return name;
@@ -26337,10 +26483,11 @@ var mktempPath = (value, dir) => {
26337
26483
  };
26338
26484
  var homeExpanded = (file) => {
26339
26485
  const match = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(file);
26340
- return match ? (process.env.HOME || os10.homedir()) + file.slice(match[0].length) : file;
26486
+ return match ? (process.env.HOME || os9.homedir()) + file.slice(match[0].length) : file;
26341
26487
  };
26342
26488
  var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherited = new Map) => {
26343
26489
  const targets = [];
26490
+ const written = new Map;
26344
26491
  let dir = cwd;
26345
26492
  let stack = [];
26346
26493
  const segments = segmentsOf(command, dialect);
@@ -26403,6 +26550,8 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26403
26550
  continue;
26404
26551
  }
26405
26552
  const body = commandWords(segment.words);
26553
+ const before = segments[segments.indexOf(segment) - 1];
26554
+ const feeder = before?.pipe ? before : undefined;
26406
26555
  const keywords = segment.words.length - body.length;
26407
26556
  for (const keyword of segment.words.slice(0, keywords))
26408
26557
  if (OPENS.has(keyword))
@@ -26456,7 +26605,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26456
26605
  }
26457
26606
  const plain = !segment.conditional;
26458
26607
  if (CD2.has(name)) {
26459
- dir = cdInto(dir, words, strict, vars);
26608
+ dir = cdInto(dir, words, Boolean(strict), vars, strict === "registry");
26460
26609
  moved(plain);
26461
26610
  continue;
26462
26611
  }
@@ -26467,7 +26616,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26467
26616
  }
26468
26617
  if (PUSHD2.has(name)) {
26469
26618
  stack.push(dir);
26470
- dir = cdInto(dir, words, strict, vars);
26619
+ dir = cdInto(dir, words, Boolean(strict), vars, strict === "registry");
26471
26620
  moved(plain);
26472
26621
  continue;
26473
26622
  }
@@ -26476,15 +26625,94 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26476
26625
  moved(plain);
26477
26626
  continue;
26478
26627
  }
26479
- const inner = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript2(words) : null) : null;
26628
+ const literal = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript2(words) : null) : null;
26629
+ const held = literal !== null && strict === "registry" ? expansions(literal, vars, loops) : [];
26630
+ const inner = held.length === 1 ? held[0] : literal;
26480
26631
  const unPwd = () => new Map([...vars].filter(([key]) => key !== "PWD"));
26481
26632
  if (inner !== null && dir !== undefined)
26482
26633
  for (const runIn of workitRunDir(dir, words, atAll))
26483
26634
  targets.push(...segmentTargets(runIn, inner, "posix", depth + 1, strict, runIn === dir ? vars : unPwd()));
26635
+ const bare = strict === "registry" && depth < 4 ? unwrapped(words) : null;
26636
+ if (bare?.length && dir !== undefined)
26637
+ targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord2).join(" "), "posix", depth + 1, strict, vars));
26638
+ if (strict === "registry" && dir !== undefined && depth < 4) {
26639
+ const run = words.slice(Math.max(0, words.findIndex((word) => !PREFIXES2.has(word))));
26640
+ const [verb = "", ...args] = run.map((word, index) => index ? word : (word.split(/[\\/]/).at(-1) ?? "").toLowerCase());
26641
+ const fed = segment.stdin?.join(`
26642
+ `);
26643
+ if (fed !== undefined)
26644
+ for (const file of segment.redirects)
26645
+ for (const into of atAll(file))
26646
+ written.set(into, fed);
26647
+ const read = (file) => atAll(file).flatMap((script) => {
26648
+ const made = written.get(script);
26649
+ if (made !== undefined)
26650
+ return [made];
26651
+ try {
26652
+ const stat = statSync4(script);
26653
+ const text = stat.isFile() && stat.size <= 262144 ? readFileSync11(script, "utf8") : "\x00";
26654
+ return text.includes("\x00") ? [] : [text];
26655
+ } catch {
26656
+ return [];
26657
+ }
26658
+ });
26659
+ const { named: operand, preloads } = scriptArgs(verb, args);
26660
+ const named = operand === "/dev/stdin" ? undefined : operand;
26661
+ const maker = feeder ? commandWords(feeder.words) : [];
26662
+ const [format = "", ...values] = maker.slice(1);
26663
+ let filled = 0;
26664
+ const printed = format.replace(/%[sbq]/g, () => values[filled++] ?? "");
26665
+ const piped = /^(?:echo|printf)$/.test(maker[0] ?? "") ? [[maker[0] === "printf" ? printed : format, ...values].join(`
26666
+ `).replaceAll("\\n", `
26667
+ `)] : maker[0] === "cat" ? [...feeder?.stdin ?? [], ...operands(maker.slice(1)).flatMap(read)] : [];
26668
+ const inputs = (segment.inputs ?? []).filter((file) => file !== "/dev/null");
26669
+ const shells = verb === "eval" ? [args.join(" ")] : verb === "trap" ? args.slice(0, 1) : verb === "alias" ? args.map((arg) => arg.replace(/^[^=]*=/, "")) : [];
26670
+ const others = [];
26671
+ if (SCRIPT_SHELLS.has(verb) || verb === "." || verb === "source") {
26672
+ if (named === undefined && shellScript2(run) === null)
26673
+ shells.push(...segment.stdin ?? [], ...inputs.flatMap(read), ...piped);
26674
+ else if (named !== undefined && shellScript2(run) === null)
26675
+ shells.push(...read(named));
26676
+ shells.push(...preloads.flatMap(read));
26677
+ } else if (INTERPRETERS.test(verb)) {
26678
+ const code = args.findIndex((arg) => /^-[a-zA-Z]*[ce]$|^--eval$/.test(arg));
26679
+ if (code >= 0)
26680
+ others.push(...expansions(args[code + 1] ?? "", vars, loops));
26681
+ others.push(...named === undefined ? [...segment.stdin ?? [], ...inputs.flatMap(read), ...piped] : read(named), ...preloads.flatMap(read));
26682
+ } else if (/[\\/]/.test(run[0] ?? ""))
26683
+ for (const text of read(run[0]))
26684
+ (/^#!.*\b(?:python|node|bun|deno|ruby|perl|php)/.test(text) ? others : shells).push(text);
26685
+ for (const script of shells)
26686
+ targets.push(...segmentTargets(dir, script, "posix", depth + 1, strict, vars));
26687
+ for (const raw of others) {
26688
+ const text = raw.replace(/^\s*(?:#(?!!)|\/\/|\/?\*).*$/gm, "");
26689
+ const joined = [
26690
+ ...text.matchAll(/(?:["'][^"'\s,*?[]+["']\s*[,/+]\s*)+["'][^"'\s,*?[]+["']/g)
26691
+ ].map(({ 0: literals, index }) => ({
26692
+ word: literals.replace(/["']\s*[,/+]\s*["']/g, "/").replace(/["']/g, ""),
26693
+ index
26694
+ }));
26695
+ const homes = /homedir\(|expanduser\(|Path\.home\(|['"]HOME['"]|env\.HOME|\$HOME|~/.test(text);
26696
+ const under = (word) => homes ? [path40.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
26697
+ const found = [
26698
+ ...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
26699
+ ...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
26700
+ ];
26701
+ for (const { file, index } of found)
26702
+ if (!isRoot(file) || !readsRoot(text, index))
26703
+ targets.push(file);
26704
+ }
26705
+ if (/^(?:n?vim?|ex|ed|emacs)$/.test(verb) && (segment.stdin || inputs.length > 0 || feeder || args.some((arg, index) => /^(?:-[a-zA-Z]*[se]|--(?:batch|eval|script))$/.test(arg) || /^(?:-c|--cmd)$/.test(arg) && !inertEdit(args[index + 1] ?? "") || arg.startsWith("+") && !inertEdit(arg.slice(1) || "1"))))
26706
+ for (const file of operands(args))
26707
+ targets.push(...atAll(file));
26708
+ if (verb === "cp" && args.some((arg) => /^-[a-zA-Z]*l|^--link$/.test(arg)))
26709
+ for (const file of operands(args).slice(0, -1))
26710
+ targets.push(...atAll(file));
26711
+ }
26484
26712
  if (strict && dir !== undefined) {
26485
26713
  const runIn = dir;
26486
26714
  for (const sub of depth < 4 ? segment.subs ?? [] : [])
26487
- targets.push(...segmentTargets(runIn, sub, dialect, depth + 1, true, vars));
26715
+ targets.push(...segmentTargets(runIn, sub, dialect, depth + 1, strict, vars));
26488
26716
  const expanding = new Set(segment.expands ?? []);
26489
26717
  const scriptOf = (index) => {
26490
26718
  const word = body[index];
@@ -26500,12 +26728,15 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26500
26728
  if (runner !== undefined && expanding.has(keywords + lead + ran) && unresolvedRefs(homeExpanded(runner)).length > 0)
26501
26729
  targets.push(unknownVarTarget(runner));
26502
26730
  const here = segment.unanalyzable ? DIR_TARGET : `${OPAQUE_TARGET}${encodeURIComponent(runner?.split(/[\\/]/).at(-1) ?? "a command")}`;
26731
+ const quiet = strict === "registry" && INTERPRETERS.test(runner?.split(/[\\/]/).at(-1) ?? "");
26503
26732
  for (const file of opaque ?? [])
26504
26733
  for (const resolved of atAll(file))
26505
- targets.push(file === "." ? path40.join(resolved, here) : resolved);
26734
+ if (!quiet || !isRoot(resolved))
26735
+ targets.push(file === "." ? path40.join(resolved, here) : resolved);
26506
26736
  const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
26507
- if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)))
26508
- targets.push(...linkSources(words.slice(ln + 1), at));
26737
+ const lnArgs = words.slice(ln + 1);
26738
+ if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)) && (strict !== "registry" || !lnArgs.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg))))
26739
+ targets.push(...linkSources(lnArgs, at));
26509
26740
  }
26510
26741
  for (const file of segment.redirects)
26511
26742
  if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file))
@@ -26540,11 +26771,14 @@ var workitCwd = (dir, args, resolve) => {
26540
26771
  };
26541
26772
  var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) => {
26542
26773
  try {
26774
+ const env = new Map(strict === "registry" ? [...command.matchAll(/\$\{?([A-Za-z_]\w*)/g)].filter((match) => !/^(?:OLD)?PWD$/.test(match[1])).map((match) => [match[1], process.env[match[1]] ?? ""]) : []);
26543
26775
  return [
26544
- ...segmentTargets(cwd, command, dialect, 0, strict),
26776
+ ...segmentTargets(cwd, command, dialect, 0, strict, env),
26545
26777
  ...gitMutationDirs(cwd, command, dialect).map((dir) => path40.join(dir, DIR_TARGET))
26546
26778
  ];
26547
- } catch {
26779
+ } catch (error) {
26780
+ if (strict === "registry")
26781
+ throw error;
26548
26782
  return [];
26549
26783
  }
26550
26784
  };
@@ -26602,12 +26836,79 @@ var claimAll = (owner, targets, deps) => {
26602
26836
  };
26603
26837
  var liveTargets = (cwd, paths) => paths?.length ? paths.map((file) => path40.resolve(cwd, file)) : [path40.join(cwd, DIR_TARGET)];
26604
26838
  var configDirs = () => [resolveConfigDir(), grantsDir()];
26839
+ var globbed = (cwd, target, state, configs) => {
26840
+ if (!/[*?[]/.test(target))
26841
+ return [];
26842
+ const raw = path40.resolve(cwd, target).split(path40.sep);
26843
+ const literal = raw.findIndex((part) => /[*?[]/.test(part));
26844
+ const pattern = [
26845
+ ...canonical3(raw.slice(0, literal).join(path40.sep) || path40.sep).replace(/[\\/]+$/, "").split(path40.sep),
26846
+ ...raw.slice(literal)
26847
+ ];
26848
+ const segment = (glob, name) => {
26849
+ try {
26850
+ return new RegExp(`^${glob.startsWith(".") ? "" : "(?!\\.)"}${glob.replace(/[.+^$(){}|\\]/g, "\\$&").replace(/\[!/g, "[^").replaceAll("*", ".*").replaceAll("?", ".")}$`, CASE_INSENSITIVE ? "i" : "").test(name);
26851
+ } catch {
26852
+ return false;
26853
+ }
26854
+ };
26855
+ const hit = (file, below) => {
26856
+ const parts = canonical3(file).split(path40.sep);
26857
+ return (below ? pattern.length >= parts.length : pattern.length === parts.length) && parts.every((part, index) => segment(pattern[index], part));
26858
+ };
26859
+ let roots = [];
26860
+ try {
26861
+ roots = readdirSync5(state).filter((name) => /^(?:issued|approvals$)/.test(name));
26862
+ } catch {}
26863
+ return [
26864
+ ...roots.map((name) => path40.join(state, name)).filter((root) => hit(root, true)),
26865
+ ...configs.flatMap((dir) => [dir, path40.join(dir, "workspaces.json")]).filter((file) => hit(file, false))
26866
+ ];
26867
+ };
26868
+ var guardedInodes = (state, configs) => {
26869
+ const seen = new Map;
26870
+ let budget = 2000;
26871
+ const add = (file, registry) => {
26872
+ if (budget-- <= 0)
26873
+ return;
26874
+ const stat = statSync4(file, { throwIfNoEntry: false });
26875
+ if (stat?.isFile())
26876
+ seen.set(`${stat.dev}:${stat.ino}`, registry);
26877
+ else if (stat?.isDirectory())
26878
+ for (const name of readdirSync5(file))
26879
+ add(path40.join(file, name), registry);
26880
+ };
26881
+ try {
26882
+ for (const dir of configs)
26883
+ add(path40.join(dir, "workspaces.json"), "grants");
26884
+ for (const name of readdirSync5(state))
26885
+ if (/^(?:issued|approvals$)/.test(name))
26886
+ add(path40.join(state, name), name === "approvals" ? "approvals" : "issued");
26887
+ } catch {}
26888
+ return seen;
26889
+ };
26890
+ var hardLinked = (file, state, configs, inodes) => {
26891
+ try {
26892
+ const stat = statSync4(file, { throwIfNoEntry: false });
26893
+ if (!stat?.isFile() || stat.nlink < 2 || !stat.ino)
26894
+ return;
26895
+ inodes.map ??= guardedInodes(state, configs);
26896
+ return inodes.map.get(`${stat.dev}:${stat.ino}`);
26897
+ } catch {
26898
+ return;
26899
+ }
26900
+ };
26605
26901
  var registryTarget = (cwd, targets) => {
26606
26902
  const state = resolveStateDir();
26607
26903
  const configs = configDirs();
26904
+ const inodes = {};
26608
26905
  for (const target of targets) {
26609
26906
  const file = homeExpanded(target);
26610
- const registry = underRegistry(state, cwd, file, process.platform, canonical3) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical3)) ? "grants" : null);
26907
+ const glob = globbed(cwd, file, state, configs)[0];
26908
+ const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
26909
+ if (viaGlob)
26910
+ return { file: target, registry: viaGlob.registry };
26911
+ const registry = hardLinked(path40.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical3) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical3)) ? "grants" : null);
26611
26912
  if (registry)
26612
26913
  return { file: target, registry };
26613
26914
  }
@@ -26629,7 +26930,7 @@ var underRegistry = (state, cwd, target, platform = process.platform, real = (fi
26629
26930
  };
26630
26931
  var underConfig = (dir, cwd, target, platform = process.platform, real = (file) => file) => {
26631
26932
  const parts = partsUnder(dir, cwd, target, platform, real);
26632
- return parts?.length === 1 && (parts[0] === "" || parts[0] === "workspaces.json");
26933
+ return parts?.length === 1 && ["", "workspaces.json", DIR_TARGET].includes(parts[0]);
26633
26934
  };
26634
26935
  var unquotedWindowsRegistry = (command, platform = process.platform) => {
26635
26936
  if (platform !== "win32" || !command.includes("\\"))
@@ -26637,8 +26938,21 @@ var unquotedWindowsRegistry = (command, platform = process.platform) => {
26637
26938
  const flat = (value) => value.replaceAll("\\", "/").toLowerCase();
26638
26939
  const text = flat(command);
26639
26940
  const state = flat(resolveStateDir());
26640
- const registry = text.includes(`${state}/issued`) ? "issued" : text.includes(`${state}/approvals`) ? "approvals" : configDirs().some((dir) => text.includes(`${flat(dir)}/workspaces.json`)) ? "grants" : null;
26641
- return registry && shellWrites(command).writes ? registry : null;
26941
+ const configs = configDirs().map(flat);
26942
+ const registry = text.includes(`${state}/issued`) ? "issued" : text.includes(`${state}/approvals`) ? "approvals" : configs.some((dir) => text.includes(dir)) ? "grants" : null;
26943
+ if (!registry)
26944
+ return null;
26945
+ const spans = command.replace(/[^\s'"|;&<>()]*\\[^\s'"|;&<>()]*/g, (word) => word.replaceAll("\\", "/"));
26946
+ const writes = shellWrites(spans);
26947
+ const moved = [
26948
+ "",
26949
+ ...[...spans.matchAll(/(?:^|[;&|(]\s*)(?:cd|pushd|chdir)\s+([^\s;&|)]+)/g)].map((match) => `${match[1]}/`)
26950
+ ];
26951
+ const named = (target) => moved.some((dir) => {
26952
+ const at = flat(/^(?:[a-z]:)?\//i.test(target) ? target : dir + target).replace(/\/\.?\//g, "/");
26953
+ return registry === "grants" ? configs.some((cfg) => [cfg, `${cfg}/`, `${cfg}/workspaces.json`].includes(at)) : at.includes(`${state}/${registry}`);
26954
+ });
26955
+ return writes.writes && (writes.targets === null || writes.targets.some(named)) ? registry : null;
26642
26956
  };
26643
26957
  var REGISTRY_DENY = {
26644
26958
  issued: {
@@ -26659,9 +26973,10 @@ var REGISTRY_DENY = {
26659
26973
  };
26660
26974
  var registryDeny = ({ file, registry }) => {
26661
26975
  const { label, what, unblock } = REGISTRY_DENY[registry];
26976
+ const named = path40.basename(file).startsWith(".workit-") ? path40.dirname(file) : file;
26662
26977
  return {
26663
26978
  kind: "deny",
26664
- reason: `workit ${label}: ${file} is under ${what}. ${unblock}`,
26979
+ reason: `workit ${label}: ${named} is under ${what}. ${unblock}`,
26665
26980
  unblock
26666
26981
  };
26667
26982
  };
@@ -26683,10 +26998,20 @@ function writeGate(cwd, paths, owner, deps) {
26683
26998
  function shellGate(cwd, command, owner, dialect = "posix", deps) {
26684
26999
  try {
26685
27000
  const windows = unquotedWindowsRegistry(command);
26686
- const forged = registryTarget(cwd, segmentTargets(cwd, command, dialect)) ?? (windows ? { file: `the ${windows} registry`, registry: windows } : null);
27001
+ const forged = registryTarget(cwd, shellMutationTargets(cwd, command, dialect, "registry")) ?? (windows ? { file: `the ${windows} registry`, registry: windows } : null);
26687
27002
  if (forged)
26688
27003
  return registryDeny(forged);
26689
- } catch {}
27004
+ } catch {
27005
+ const text = command.replaceAll("\\", "/").replace(/['"]/g, "").toLowerCase();
27006
+ if (/issued|approvals|workspaces\.json|\.config\/workit|state\/workit/.test(text) || [resolveStateDir(), ...configDirs()].some((dir) => text.includes(dir.replaceAll("\\", "/").toLowerCase()))) {
27007
+ const { unblock } = REGISTRY_DENY.grants;
27008
+ return {
27009
+ kind: "deny",
27010
+ reason: `workit registry guard: Workit could not analyse this command, which names a guarded path; split it into plain commands. ${unblock}`,
27011
+ unblock
27012
+ };
27013
+ }
27014
+ }
26690
27015
  const writes = shellWrites(command);
26691
27016
  let targets = [];
26692
27017
  if (owner)
@@ -26734,7 +27059,7 @@ function beforeWriteGate(cwd, paths) {
26734
27059
  }
26735
27060
  }
26736
27061
  // packages/workit-core/src/hooks/stop.ts
26737
- import { spawnSync as spawnSync23 } from "node:child_process";
27062
+ import { spawnSync as spawnSync24 } from "node:child_process";
26738
27063
 
26739
27064
  // packages/workit-core/src/ci-waiter.ts
26740
27065
  import fs28 from "node:fs";
@@ -26833,7 +27158,7 @@ var asksUser = (message) => {
26833
27158
  };
26834
27159
  var short = (sha) => (sha ?? "?").slice(0, 12);
26835
27160
  var gitList = (cwd, args) => {
26836
- const run = spawnSync23("git", args, {
27161
+ const run = spawnSync24("git", args, {
26837
27162
  cwd,
26838
27163
  encoding: "utf8",
26839
27164
  timeout: 3000,
@@ -27284,7 +27609,7 @@ import path44 from "node:path";
27284
27609
 
27285
27610
  // packages/workit-core/src/approvals/store.ts
27286
27611
  import { createHash as createHash18, randomBytes as randomBytes4 } from "node:crypto";
27287
- import { mkdirSync as mkdirSync6, readdirSync as readdirSync5, readFileSync as readFileSync10 } from "node:fs";
27612
+ import { mkdirSync as mkdirSync6, readdirSync as readdirSync6, readFileSync as readFileSync12 } from "node:fs";
27288
27613
  import path42 from "node:path";
27289
27614
  var REQUEST_TTL_MS = 30 * 60000;
27290
27615
  var GRANT_TTL_MS = 15 * 60000;
@@ -27303,7 +27628,7 @@ var fileOf = (part, id) => path42.join(dirOf(part), `${id}.json`);
27303
27628
  var askedFile = (session, toolUseId) => path42.join(dirOf("asked"), `${createHash18("sha256").update(`${session}\x00${toolUseId}`).digest("hex").slice(0, 32)}.json`);
27304
27629
  var readJson3 = (file) => {
27305
27630
  try {
27306
- const value = JSON.parse(readFileSync10(file, "utf8"));
27631
+ const value = JSON.parse(readFileSync12(file, "utf8"));
27307
27632
  return value !== null && typeof value === "object" ? value : null;
27308
27633
  } catch {
27309
27634
  return null;
@@ -28218,7 +28543,7 @@ function confineImplementerShell(input, command, dialect = "posix") {
28218
28543
  }
28219
28544
  var SCRATCH = ".workit-scratch";
28220
28545
  var SHELL_NAMES = /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/;
28221
- var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php)$/;
28546
+ var INTERPRETERS2 = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php)$/;
28222
28547
  var FED = /^(?:-|\/dev\/stdin|\/dev\/fd\/0|\/proc\/self\/fd\/0)$|^<\(/;
28223
28548
  var LEADS = /^(?:sudo|doas|env|command|builtin|exec|nohup|time|nice|timeout|stdbuf|xargs|busybox|!|\{|if|then|else|elif|do|while|until|\w+=.*|[-\d].*)$/s;
28224
28549
  var RUNS = /^(?:sh|bash|zsh|dash|ksh|mksh|ash|python[\d.]*|node|bun|deno|ruby|perl|php|eval|source|\.|workit)$/;
@@ -28335,7 +28660,7 @@ var judgeRefusal = (command, fed, depth = 0) => {
28335
28660
  }
28336
28661
  }
28337
28662
  }
28338
- if (INTERPRETERS.test(name) && !args.some((arg) => INLINE.test(arg))) {
28663
+ if (INTERPRETERS2.test(name) && !args.some((arg) => INLINE.test(arg))) {
28339
28664
  const operand = args.find((arg, index) => (arg === "-" || !arg.startsWith("-")) && !VALUED.test(args[index - 1] ?? ""));
28340
28665
  if (FED.test(operand ?? "") || operand === undefined && !/^(?:bun|deno)$/.test(name))
28341
28666
  return unseen;
@@ -28687,8 +29012,8 @@ var cdWorkitSplit = (command) => {
28687
29012
  };
28688
29013
 
28689
29014
  // packages/workit-core/src/hooks/model-limit.ts
28690
- import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync6, readSync, statSync as statSync5 } from "node:fs";
28691
- import os11 from "node:os";
29015
+ import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync7, readSync, statSync as statSync5 } from "node:fs";
29016
+ import os10 from "node:os";
28692
29017
  import path45 from "node:path";
28693
29018
  var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
28694
29019
  var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
@@ -28887,14 +29212,14 @@ var firstPrompt = (file) => {
28887
29212
  var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
28888
29213
  var listDir = (dir) => {
28889
29214
  try {
28890
- return readdirSync6(dir).map((name) => path45.join(dir, name));
29215
+ return readdirSync7(dir).map((name) => path45.join(dir, name));
28891
29216
  } catch {
28892
29217
  return [];
28893
29218
  }
28894
29219
  };
28895
29220
  var SCAN_MS = 30 * 60000;
28896
29221
  var scanClaudeTranscripts = (cwd, env, now = new Date) => {
28897
- const projects = path45.join(env.CLAUDE_CONFIG_DIR || path45.join(env.HOME || os11.homedir(), ".claude"), "projects");
29222
+ const projects = path45.join(env.CLAUDE_CONFIG_DIR || path45.join(env.HOME || os10.homedir(), ".claude"), "projects");
28898
29223
  const project = path45.join(projects, claudeProjectSlug(cwd));
28899
29224
  const notes = [];
28900
29225
  const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path45.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
@@ -29760,8 +30085,8 @@ var observeToolResult = (event, ctx) => {
29760
30085
  var skillPromptNudge = (prompt, ctx) => process.env.WORKIT_PI_WORKER_SESSION ? null : promptNudge(hookInput(ctx, { kind: "context.turn", prompt }), prompt);
29761
30086
 
29762
30087
  // packages/workit-pi/src/launches.ts
29763
- import { mkdirSync as mkdirSync7, readFileSync as readFileSync11, readdirSync as readdirSync7, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
29764
- import os12 from "node:os";
30088
+ import { mkdirSync as mkdirSync7, readFileSync as readFileSync13, readdirSync as readdirSync8, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
30089
+ import os11 from "node:os";
29765
30090
  import path47 from "node:path";
29766
30091
  var launchDir = (root) => {
29767
30092
  const location = resolveStore(root);
@@ -29777,7 +30102,7 @@ var recordLaunch = (root, attempt) => {
29777
30102
  writeFileSync6(fileFor(dir, attempt.workerId), JSON.stringify({
29778
30103
  ...attempt,
29779
30104
  pid: process.pid,
29780
- host: os12.hostname(),
30105
+ host: os11.hostname(),
29781
30106
  at: new Date().toISOString()
29782
30107
  }), { flag: "wx" });
29783
30108
  return true;
@@ -29791,7 +30116,7 @@ var clearLaunch = (root, workerId) => {
29791
30116
  rmSync3(fileFor(dir, workerId), { force: true });
29792
30117
  };
29793
30118
  var alive = (attempt) => {
29794
- if (attempt.host !== os12.hostname())
30119
+ if (attempt.host !== os11.hostname())
29795
30120
  return true;
29796
30121
  try {
29797
30122
  process.kill(attempt.pid, 0);
@@ -29806,14 +30131,14 @@ var abandonedLaunches = (root) => {
29806
30131
  return [];
29807
30132
  let names;
29808
30133
  try {
29809
- names = readdirSync7(dir);
30134
+ names = readdirSync8(dir);
29810
30135
  } catch {
29811
30136
  return [];
29812
30137
  }
29813
30138
  const found = [];
29814
30139
  for (const name of names) {
29815
30140
  try {
29816
- const attempt = JSON.parse(readFileSync11(path47.join(dir, name), "utf8"));
30141
+ const attempt = JSON.parse(readFileSync13(path47.join(dir, name), "utf8"));
29817
30142
  if (typeof attempt.workerId === "string" && typeof attempt.session === "string") {
29818
30143
  if (!alive(attempt))
29819
30144
  found.push(attempt);