@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/worker.js CHANGED
@@ -6755,13 +6755,12 @@ var COMMIT_PRESETS = [
6755
6755
  ];
6756
6756
 
6757
6757
  // packages/workit-core/src/core/workspaces.ts
6758
- import { spawnSync as spawnSync3 } from "node:child_process";
6759
- import { existsSync, lstatSync as lstatSync2, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "node:fs";
6758
+ import { spawnSync as spawnSync4 } from "node:child_process";
6759
+ import { existsSync, lstatSync as lstatSync2, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
6760
6760
  import path6 from "node:path";
6761
6761
 
6762
6762
  // packages/workit-core/src/core/remotes.ts
6763
- import { lstatSync, readFileSync, realpathSync, statSync } from "node:fs";
6764
- import os3 from "node:os";
6763
+ import { lstatSync, readFileSync as readFileSync2, realpathSync, statSync } from "node:fs";
6765
6764
  import path5 from "node:path";
6766
6765
 
6767
6766
  // packages/workit-core/src/git/rev.ts
@@ -7097,6 +7096,56 @@ function resolveSshHost(alias, sshConfig) {
7097
7096
  return { hostname: (hostname ?? alias).replace(/\.$/u, ""), port };
7098
7097
  }
7099
7098
 
7099
+ // packages/workit-core/src/core/account-home.ts
7100
+ import { spawnSync as spawnSync3 } from "node:child_process";
7101
+ import { readFileSync } from "node:fs";
7102
+ import os3 from "node:os";
7103
+ var WINDOWS = "C:\\Windows";
7104
+ var SYSTEM32 = `${WINDOWS}\\System32\\`;
7105
+ var PROFILES = "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\";
7106
+ var childEnv = (platform) => platform === "win32" ? { SystemRoot: WINDOWS } : {};
7107
+ var hostIo = {
7108
+ bun: Boolean(process.versions.bun),
7109
+ uid: process.getuid?.() ?? -1,
7110
+ userInfo: () => os3.userInfo().homedir,
7111
+ passwd: () => readFileSync("/etc/passwd", "utf8"),
7112
+ run: (file, args) => {
7113
+ const done = spawnSync3(file, args, {
7114
+ encoding: "utf8",
7115
+ env: childEnv(process.platform),
7116
+ timeout: 3000,
7117
+ windowsHide: true
7118
+ });
7119
+ return done.status === 0 ? done.stdout : "";
7120
+ }
7121
+ };
7122
+ var field = (text, uid, at) => text.split(`
7123
+ `).filter((line) => !line.startsWith("#")).map((line) => line.split(":")).find((fields) => fields[2] === uid)?.[at];
7124
+ var profilePath = (raw) => {
7125
+ const value = raw.replaceAll(/%SystemDrive%/giu, WINDOWS.slice(0, 2)).replaceAll(/%SystemRoot%/giu, WINDOWS);
7126
+ return /^[A-Za-z]:\\/u.test(value) && !value.includes("%") ? value : null;
7127
+ };
7128
+ var accountHome = (platform = process.platform, io = hostIo) => {
7129
+ try {
7130
+ if (!io.bun)
7131
+ return io.userInfo() || null;
7132
+ if (platform === "win32") {
7133
+ const sid = /S-1-[\d-]+/u.exec(io.run(`${SYSTEM32}whoami.exe`, ["/user", "/fo", "csv"]));
7134
+ const key = sid && io.run(`${SYSTEM32}reg.exe`, ["query", PROFILES + sid[0], "/v", "ProfileImagePath"]);
7135
+ const raw = /ProfileImagePath\s+REG_\w+\s+(.+)/u.exec(key || "")?.[1]?.trim();
7136
+ return raw ? profilePath(raw) : null;
7137
+ }
7138
+ const uid = String(io.uid);
7139
+ let passwd = "";
7140
+ try {
7141
+ passwd = io.passwd();
7142
+ } catch {}
7143
+ 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;
7144
+ } catch {
7145
+ return null;
7146
+ }
7147
+ };
7148
+
7100
7149
  // packages/workit-core/src/core/remotes.ts
7101
7150
  var FORGE_SCHEMES = new Set(["ssh", "git", "http", "https", "git+ssh", "ssh+git"]);
7102
7151
  var SSH_SCHEMES = new Set(["ssh", "git+ssh", "ssh+git"]);
@@ -7106,15 +7155,11 @@ var SSH_443 = {
7106
7155
  };
7107
7156
  var WINDOWS_DRIVE = /^[A-Za-z]:[\\/]/u;
7108
7157
  var SCP_LIKE = /^(?:[^@/\\]+@)?([^/\\:]+):(.+)$/u;
7109
- var accountHome = () => {
7110
- try {
7111
- return os3.userInfo().homedir;
7112
- } catch {
7113
- return os3.homedir();
7114
- }
7115
- };
7116
7158
  var sshSeam = {
7117
- read: () => readSshConfig(accountHome())
7159
+ read: () => {
7160
+ const home = accountHome();
7161
+ return home === null ? { text: "", home: "" } : readSshConfig(home);
7162
+ }
7118
7163
  };
7119
7164
  var forgeKey = (rawHost, repo, ssh) => {
7120
7165
  let host = rawHost.toLowerCase().replace(/\.$/u, "");
@@ -7161,7 +7206,7 @@ var gitDirAt = (at, depth = 0) => {
7161
7206
  return null;
7162
7207
  try {
7163
7208
  if (statSync(real).isFile()) {
7164
- const pointer = /^gitdir:\s*(.+?)\s*$/mu.exec(readFileSync(real, "utf8"))?.[1];
7209
+ const pointer = /^gitdir:\s*(.+?)\s*$/mu.exec(readFileSync2(real, "utf8"))?.[1];
7165
7210
  if (!pointer)
7166
7211
  return null;
7167
7212
  const target = path5.isAbsolute(pointer) ? pointer : `${path5.dirname(real)}/${pointer}`;
@@ -7169,7 +7214,7 @@ var gitDirAt = (at, depth = 0) => {
7169
7214
  }
7170
7215
  let common;
7171
7216
  try {
7172
- common = readFileSync(`${real}/commondir`, "utf8").trim();
7217
+ common = readFileSync2(`${real}/commondir`, "utf8").trim();
7173
7218
  } catch {}
7174
7219
  if (common !== undefined) {
7175
7220
  lstatSync(`${real}/HEAD`);
@@ -7502,7 +7547,7 @@ var probeCheckout = (cwd) => {
7502
7547
  for (const name of ["GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR", "GIT_INDEX_FILE"])
7503
7548
  delete env[name];
7504
7549
  const git = (args) => {
7505
- const run = spawnSync3("git", args, {
7550
+ const run = spawnSync4("git", args, {
7506
7551
  cwd,
7507
7552
  env,
7508
7553
  encoding: "utf8",
@@ -7656,7 +7701,7 @@ var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
7656
7701
  const file = path6.join(dir, "workspaces.json");
7657
7702
  let raw;
7658
7703
  try {
7659
- raw = readFileSync2(file, "utf8");
7704
+ raw = readFileSync3(file, "utf8");
7660
7705
  } catch (error) {
7661
7706
  if (error.code === "ENOENT")
7662
7707
  return null;
@@ -7700,7 +7745,7 @@ var modelSources = (cwd, dir) => {
7700
7745
  }
7701
7746
  } catch {}
7702
7747
  try {
7703
- const document = JSON.parse(readFileSync2(path6.join(dir ?? configDir2(), "workspaces.json"), "utf8"));
7748
+ const document = JSON.parse(readFileSync3(path6.join(dir ?? configDir2(), "workspaces.json"), "utf8"));
7704
7749
  if (document && typeof document === "object" && !Array.isArray(document))
7705
7750
  out.push({
7706
7751
  name: "global",
@@ -7788,12 +7833,12 @@ var resolveStateDir = () => stateDir(process.env);
7788
7833
  var homePattern = new RegExp(`${escapeRegExp(os4.homedir())}(?=[/\\\\]|$)|\\$HOME(?=[/\\\\]|$)`, "g");
7789
7834
 
7790
7835
  // packages/workit-core/src/store/paths.ts
7791
- import { spawnSync as spawnSync4 } from "node:child_process";
7836
+ import { spawnSync as spawnSync5 } from "node:child_process";
7792
7837
  import fs4 from "node:fs";
7793
7838
  import path7 from "node:path";
7794
7839
  var NOT_A_REPO = /not a git repository \(or any (of the parent directories|parent up to)/u;
7795
7840
  var gitRun = (cwd, args) => {
7796
- const run = spawnSync4("git", args, {
7841
+ const run = spawnSync5("git", args, {
7797
7842
  cwd,
7798
7843
  encoding: "utf8",
7799
7844
  timeout: 20000,
@@ -8002,7 +8047,7 @@ var assetRoot = () => {
8002
8047
  };
8003
8048
 
8004
8049
  // packages/workit-core/src/core/store-lock.ts
8005
- import { spawnSync as spawnSync5 } from "node:child_process";
8050
+ import { spawnSync as spawnSync6 } from "node:child_process";
8006
8051
  import fs5 from "node:fs";
8007
8052
  var metadataLockSchema = object({
8008
8053
  pid: number2().int().nonnegative().safe(),
@@ -8027,7 +8072,7 @@ var readProcStat = (pid) => {
8027
8072
  };
8028
8073
  var psStart = (pid) => {
8029
8074
  try {
8030
- const run = spawnSync5("ps", ["-o", "lstart=", "-p", String(pid)], {
8075
+ const run = spawnSync6("ps", ["-o", "lstart=", "-p", String(pid)], {
8031
8076
  encoding: "utf8",
8032
8077
  timeout: 1000,
8033
8078
  env: { ...process.env, LC_ALL: "C" }
@@ -8114,7 +8159,7 @@ var PM_RUN = new Set(["run", "run-script"]);
8114
8159
  var PYTHON_RUNNERS = new Set(["uv", "poetry", "pipenv", "pdm", "hatch", "rye"]);
8115
8160
 
8116
8161
  // packages/workit-core/src/ledger.ts
8117
- import { spawnSync as spawnSync6 } from "node:child_process";
8162
+ import { spawnSync as spawnSync7 } from "node:child_process";
8118
8163
  import { createHash as createHash3, randomBytes } from "node:crypto";
8119
8164
  import fs7 from "node:fs";
8120
8165
  import path10 from "node:path";
@@ -8280,7 +8325,7 @@ var err = (code, error, unblock) => ({
8280
8325
  ...unblock ? { unblock } : {}
8281
8326
  });
8282
8327
  var gitRun2 = (cwd, args, timeoutMs = GIT_TIMEOUTS.local) => {
8283
- const run = spawnSync6("git", args, {
8328
+ const run = spawnSync7("git", args, {
8284
8329
  cwd,
8285
8330
  encoding: "utf8",
8286
8331
  timeout: timeoutMs,
@@ -8598,7 +8643,7 @@ var OBSERVED_ONLY = new Set([
8598
8643
  ]);
8599
8644
 
8600
8645
  // packages/workit-core/src/core/model-fallback.ts
8601
- import { mkdirSync, readFileSync as readFileSync3, renameSync, writeFileSync } from "node:fs";
8646
+ import { mkdirSync, readFileSync as readFileSync4, renameSync, writeFileSync } from "node:fs";
8602
8647
  import path11 from "node:path";
8603
8648
  var LIMITS_FILE = "model-limits.json";
8604
8649
  var DEFAULT_LIMIT_WINDOW_MS = 5 * 3600000;
@@ -8625,7 +8670,7 @@ var empty = () => ({ exhausted: {}, seen: {}, redispatched: {} });
8625
8670
  var storePath = (stateDir) => path11.join(stateDir ?? resolveStateDir(), LIMITS_FILE);
8626
8671
  var readStore = (stateDir) => {
8627
8672
  try {
8628
- const parsed = JSON.parse(readFileSync3(storePath(stateDir), "utf8"));
8673
+ const parsed = JSON.parse(readFileSync4(storePath(stateDir), "utf8"));
8629
8674
  const store = empty();
8630
8675
  for (const key of ["exhausted", "seen", "redispatched"])
8631
8676
  if (parsed[key] && typeof parsed[key] === "object")
@@ -9598,11 +9643,11 @@ var PI_DESCRIPTOR = {
9598
9643
  import path13 from "node:path";
9599
9644
 
9600
9645
  // packages/workit-core/src/core/live-session.ts
9601
- import { spawnSync as spawnSync7 } from "node:child_process";
9646
+ import { spawnSync as spawnSync8 } from "node:child_process";
9602
9647
  var LIVE_SESSION_TTL_MS = 15 * 60000;
9603
9648
  var liveProbe = {
9604
9649
  platform: process.platform,
9605
- run: (args) => spawnSync7("ps", args, { encoding: "utf8", timeout: 2000 }).stdout ?? "",
9650
+ run: (args) => spawnSync8("ps", args, { encoding: "utf8", timeout: 2000 }).stdout ?? "",
9606
9651
  start: (pid) => processStartOf(pid)
9607
9652
  };
9608
9653
  var PIDS = new Map;