@workit-dev/pi 1.5.1 → 1.6.1

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.
package/dist/workit.js CHANGED
@@ -1,11 +1,11 @@
1
1
  // packages/workit-pi/extensions/workit.ts
2
- import { randomUUID as randomUUID5 } from "node:crypto";
2
+ 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
6
  import { spawnSync as spawnSync21 } from "node:child_process";
7
7
  import { existsSync as existsSync11, realpathSync as realpathSync8 } from "node:fs";
8
- import path32 from "node:path";
8
+ import path33 from "node:path";
9
9
 
10
10
  // packages/workit-core/src/core/task-contract.ts
11
11
  import { createHash, randomUUID } from "node:crypto";
@@ -18257,18 +18257,18 @@ var exportDigest = (bundle) => sha256({
18257
18257
  // packages/workit-core/src/core/route-intent.ts
18258
18258
  import { spawnSync as spawnSync16 } from "node:child_process";
18259
18259
  import { existsSync as existsSync9 } from "node:fs";
18260
- import path27 from "node:path";
18260
+ import path28 from "node:path";
18261
18261
 
18262
18262
  // packages/workit-core/src/hooks/raw-git.ts
18263
18263
  import { spawnSync as spawnSync15 } from "node:child_process";
18264
18264
  import { createHash as createHash15 } from "node:crypto";
18265
18265
  import fs18 from "node:fs";
18266
18266
  import os7 from "node:os";
18267
- import path26 from "node:path";
18267
+ import path27 from "node:path";
18268
18268
 
18269
18269
  // packages/workit-core/src/autonomy.ts
18270
18270
  import os6 from "node:os";
18271
- import path24 from "node:path";
18271
+ import path25 from "node:path";
18272
18272
 
18273
18273
  // packages/workit-core/src/core/eval-world.ts
18274
18274
  import { existsSync as existsSync8, realpathSync as realpathSync5 } from "node:fs";
@@ -18294,6 +18294,73 @@ var evalWorldEntry = (cwd) => {
18294
18294
  }
18295
18295
  };
18296
18296
 
18297
+ // packages/workit-core/src/core/safe-write.ts
18298
+ import { randomUUID as randomUUID4 } from "node:crypto";
18299
+ import {
18300
+ closeSync as closeSync2,
18301
+ fchmodSync,
18302
+ fsyncSync,
18303
+ lstatSync as lstatSync5,
18304
+ mkdirSync as mkdirSync4,
18305
+ openSync as openSync2,
18306
+ renameSync as renameSync3,
18307
+ unlinkSync,
18308
+ writeFileSync as writeFileSync4
18309
+ } from "node:fs";
18310
+ import path24 from "node:path";
18311
+ function writeFileAtomic(file, content, mode) {
18312
+ const absolute = path24.resolve(file);
18313
+ let parent = path24.dirname(absolute);
18314
+ const root = path24.parse(parent).root;
18315
+ for (;; ) {
18316
+ try {
18317
+ if (lstatSync5(parent).isSymbolicLink())
18318
+ throw new Error(`symlinked write path: ${parent}`);
18319
+ } catch (error) {
18320
+ if (error.code !== "ENOENT")
18321
+ throw error;
18322
+ }
18323
+ const next = path24.dirname(parent);
18324
+ if (parent === root || next === parent)
18325
+ break;
18326
+ parent = next;
18327
+ }
18328
+ const directory = path24.dirname(absolute);
18329
+ mkdirSync4(directory, { recursive: true });
18330
+ let existing = null;
18331
+ try {
18332
+ existing = lstatSync5(absolute);
18333
+ } catch (error) {
18334
+ if (error.code !== "ENOENT")
18335
+ throw error;
18336
+ }
18337
+ if (existing?.isSymbolicLink() || existing && !existing.isFile()) {
18338
+ throw new Error(`refusing to replace non-regular file: ${absolute}`);
18339
+ }
18340
+ const temporary = `${absolute}.${randomUUID4()}.tmp`;
18341
+ let fd;
18342
+ try {
18343
+ fd = openSync2(temporary, "wx", mode ?? 438);
18344
+ writeFileSync4(fd, content, "utf8");
18345
+ if (existing)
18346
+ fchmodSync(fd, existing.mode & 511);
18347
+ fsyncSync(fd);
18348
+ closeSync2(fd);
18349
+ fd = undefined;
18350
+ renameSync3(temporary, absolute);
18351
+ } catch (error) {
18352
+ if (fd !== undefined) {
18353
+ try {
18354
+ closeSync2(fd);
18355
+ } catch {}
18356
+ }
18357
+ try {
18358
+ unlinkSync(temporary);
18359
+ } catch {}
18360
+ throw error;
18361
+ }
18362
+ }
18363
+
18297
18364
  // packages/workit-core/src/autonomy.ts
18298
18365
  var accountHome2 = () => {
18299
18366
  try {
@@ -18323,8 +18390,8 @@ var benchWorld = (cwd) => {
18323
18390
  };
18324
18391
  };
18325
18392
  var grantsOverride = () => {
18326
- const configured = path24.resolve(resolveConfigDir());
18327
- return configured === path24.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 ${path24.join(grantsDir(), "workspaces.json")}, so the D4 defaults apply until grants are set there`;
18393
+ const configured = path25.resolve(resolveConfigDir());
18394
+ return configured === path25.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 ${path25.join(grantsDir(), "workspaces.json")}, so the D4 defaults apply until grants are set there`;
18328
18395
  };
18329
18396
  var GRANT_KINDS = ["push", "pr", "merge", "release", "rerun"];
18330
18397
  var DEFAULT_GRANTS = Object.freeze({
@@ -18582,7 +18649,7 @@ var raises = (kind, current, next) => {
18582
18649
  // packages/workit-core/src/hooks/session-marker.ts
18583
18650
  import { createHash as createHash14 } from "node:crypto";
18584
18651
  import fs17 from "node:fs";
18585
- import path25 from "node:path";
18652
+ import path26 from "node:path";
18586
18653
  var sessionMarkerFile = (input, session, store) => {
18587
18654
  let dir = store;
18588
18655
  if (dir === undefined) {
@@ -18592,7 +18659,7 @@ var sessionMarkerFile = (input, session, store) => {
18592
18659
  dir = location.dir;
18593
18660
  }
18594
18661
  const name = createHash14("sha256").update(`${input.host}\x00${session}`).digest("hex").slice(0, 32);
18595
- return path25.join(dir, "hooks", `skills-${name}.json`);
18662
+ return path26.join(dir, "hooks", `skills-${name}.json`);
18596
18663
  };
18597
18664
  var list2 = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
18598
18665
  var EMPTY = {
@@ -18627,7 +18694,7 @@ var parseMarker = (text) => {
18627
18694
  };
18628
18695
  var readSessionMarker = (file) => parseMarker(readRaw(file));
18629
18696
  var writeAtomic = (file, marker) => {
18630
- fs17.mkdirSync(path25.dirname(file), { recursive: true });
18697
+ fs17.mkdirSync(path26.dirname(file), { recursive: true });
18631
18698
  const temp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
18632
18699
  try {
18633
18700
  fs17.writeFileSync(temp, JSON.stringify(marker));
@@ -19212,14 +19279,14 @@ var GIT_CONFIG_ENV = /^(?:GIT_(?:CONFIG\w*|DIR|COMMON_DIR|WORK_TREE|SSH|SSH_COMM
19212
19279
  var ASSIGNMENT = /^([A-Za-z_]\w*)=([\s\S]*)$/;
19213
19280
  var MAX_DEPTH = 4;
19214
19281
  var MAX_EXPANSIONS = 16;
19215
- var isAbsolute = (value) => path26.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\");
19282
+ var isAbsolute = (value) => path27.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\");
19216
19283
  var HERE = /^(?:\$PWD|\$\{PWD\}|\$\(\s*pwd\s*\)|`pwd`|\$\(\s*git\s+rev-parse\s+--show-toplevel\s*\))(?=$|[\\/])/;
19217
19284
  var joinDir = (base, raw) => {
19218
19285
  const next = raw.replace(HERE, ".");
19219
19286
  if (base === undefined || /[$`*?]/.test(next) || next === "-")
19220
19287
  return;
19221
- const expanded = next === "~" || next.startsWith("~/") ? path26.join(os7.homedir(), next.slice(1)) : next;
19222
- return base === null || isAbsolute(expanded) ? expanded : path26.join(base, expanded);
19288
+ const expanded = next === "~" || next.startsWith("~/") ? path27.join(os7.homedir(), next.slice(1)) : next;
19289
+ return base === null || isAbsolute(expanded) ? expanded : path27.join(base, expanded);
19223
19290
  };
19224
19291
  var rebase = (base, inner) => inner === null ? base : inner === undefined ? undefined : joinDir(base, inner);
19225
19292
  var cdTarget = (words) => {
@@ -20141,17 +20208,17 @@ var headSha2 = (repo) => {
20141
20208
  if (!git || git.reftable)
20142
20209
  return null;
20143
20210
  try {
20144
- const head = fs18.readFileSync(path26.join(git.gitDir, "HEAD"), "utf8").trim();
20211
+ const head = fs18.readFileSync(path27.join(git.gitDir, "HEAD"), "utf8").trim();
20145
20212
  if (/^[0-9a-f]{40,64}$/.test(head))
20146
20213
  return head;
20147
20214
  const ref = /^ref: (refs\/.+)$/.exec(head)?.[1];
20148
20215
  if (!ref)
20149
20216
  return null;
20150
- const common = path26.dirname(repo.location.dir);
20217
+ const common = path27.dirname(repo.location.dir);
20151
20218
  try {
20152
- return fs18.readFileSync(path26.join(common, ref), "utf8").trim() || null;
20219
+ return fs18.readFileSync(path27.join(common, ref), "utf8").trim() || null;
20153
20220
  } catch {}
20154
- const packed = fs18.readFileSync(path26.join(common, "packed-refs"), "utf8");
20221
+ const packed = fs18.readFileSync(path27.join(common, "packed-refs"), "utf8");
20155
20222
  return new RegExp(`^([0-9a-f]{40,64}) ${ref.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`, "m").exec(packed)?.[1] ?? null;
20156
20223
  } catch {
20157
20224
  return null;
@@ -20244,7 +20311,7 @@ var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
20244
20311
  const sub = invocation.args[0];
20245
20312
  if (invocation.tool !== "git" || invocation.dir === undefined || !sub || sub.startsWith("-") || GIT_COMMANDS.has(sub) || depth >= MAX_DEPTH)
20246
20313
  return [invocation];
20247
- const dir = path26.resolve(root, invocation.dir ?? ".");
20314
+ const dir = path27.resolve(root, invocation.dir ?? ".");
20248
20315
  if (!fs18.existsSync(dir))
20249
20316
  return [invocation];
20250
20317
  const config = gitConfig(dir, invocation, cache);
@@ -20267,11 +20334,11 @@ var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
20267
20334
  var normalizedUrl = (url, dir) => {
20268
20335
  const trimmed = url.trim();
20269
20336
  if (/^file:\/\//i.test(trimmed))
20270
- return path26.resolve(dir, trimmed.slice(7)).replace(/\/+$/, "").replace(/\.git$/, "");
20337
+ return path27.resolve(dir, trimmed.slice(7)).replace(/\/+$/, "").replace(/\.git$/, "");
20271
20338
  const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(trimmed);
20272
20339
  const scp = !scheme && /^(?:[^@/\\]+@)?[^/\\:]{2,}:/.test(trimmed);
20273
20340
  if (!scheme && !scp)
20274
- return path26.resolve(dir, trimmed).replace(/\/+$/, "").replace(/\.git$/, "");
20341
+ return path27.resolve(dir, trimmed).replace(/\/+$/, "").replace(/\.git$/, "");
20275
20342
  const value = scheme ? trimmed.slice(scheme[0].length).replace(/^[^@/]*@/, "").replace(/^([^/:]+):\d+(?=\/)/, "$1") : trimmed.replace(/^[^@/]*@/, "").replace(":", "/");
20276
20343
  return value.toLowerCase().replace(/\/{2,}/g, "/").replace(/^www\./, "").replace(/\/+$/, "").replace(/\.git$/, "");
20277
20344
  };
@@ -20499,7 +20566,7 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
20499
20566
  const out = [];
20500
20567
  const repos = new Map;
20501
20568
  const repoFor = (relative) => {
20502
- const dir = path26.resolve(cwd, relative ?? ".");
20569
+ const dir = path27.resolve(cwd, relative ?? ".");
20503
20570
  if (!repos.has(dir)) {
20504
20571
  const repo = repoAt(dir);
20505
20572
  const workit = repo !== null && isWorkitWorkspace(repo);
@@ -20519,7 +20586,10 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
20519
20586
  continue;
20520
20587
  const action = rawAction(invocation);
20521
20588
  const at = !action ? null : repoFor(invocation.dir) ?? (all && invocation.tool !== "git" && explicitRepo(invocation.tool === "gh", "repo" in action && action.repo || "", invocation.env ?? {}) ? {
20522
- repo: { dir: path26.resolve(cwd, invocation.dir ?? "."), branch: null },
20589
+ repo: {
20590
+ dir: path27.resolve(cwd, invocation.dir ?? "."),
20591
+ branch: null
20592
+ },
20523
20593
  workit: false
20524
20594
  } : null);
20525
20595
  if (action && at)
@@ -20566,6 +20636,109 @@ var pkillSelfMatch = (command, dialect) => {
20566
20636
  }
20567
20637
  return null;
20568
20638
  };
20639
+ var policyDeclared = () => {
20640
+ try {
20641
+ return !!readConfigTyped().config?.branchPolicy?.protected?.length;
20642
+ } catch {
20643
+ return false;
20644
+ }
20645
+ };
20646
+ var word = (text) => /^[\w./@%+:,=-]+$/u.test(text) ? text : shellQuote(text);
20647
+ var HEREDOC = /^cat <<(['"])(\w+)\1\n([\s\S]*)\n\2\n?$/u;
20648
+ var messageOf = (segment, index) => {
20649
+ const text = segment.words[index];
20650
+ if (text === undefined)
20651
+ return null;
20652
+ if (!segment.expands?.includes(index))
20653
+ return text;
20654
+ const sub = segment.subs?.find((each) => text === `$(${each})`);
20655
+ const match = sub === undefined ? null : HEREDOC.exec(sub);
20656
+ if (!match || match[3].split(`
20657
+ `).includes(match[2]))
20658
+ return null;
20659
+ return match[3].replace(/\n+$/u, "");
20660
+ };
20661
+ var cdCommitCall = (input, command, target, repo) => {
20662
+ const { top, git, dir: store } = repo.location;
20663
+ if (!top || !git || git.gitDir === path27.dirname(store) || repoAt(input.cwd)?.location.top === top)
20664
+ return null;
20665
+ const bare = command.replaceAll(/'[^']*'|"(?:[^"\\]|\\.)*"/gu, "").replaceAll("&&", "");
20666
+ if (/[;|&<>`$()\n\\]/u.test(bare))
20667
+ return null;
20668
+ const [cd, ...rest] = segmentsOf(command);
20669
+ const commit = rest.at(-1);
20670
+ if (cd?.words[0] !== "cd" || cd.words.length !== 2 || cd.expands?.length || !commit)
20671
+ return null;
20672
+ if (path27.resolve(input.cwd, cd.words[1]) !== target)
20673
+ return null;
20674
+ if (rest.some((each) => each.redirects.length || each.stdin?.length || each.group))
20675
+ return null;
20676
+ const adds = rest.slice(0, -1);
20677
+ if (!adds.length || commit.words[0] !== "git" || commit.words[1] !== "commit")
20678
+ return null;
20679
+ const paths = [];
20680
+ let all = false;
20681
+ for (const add of adds) {
20682
+ const [tool, verb, ...args] = add.words;
20683
+ if (tool !== "git" || verb !== "add" || add.expands?.length || add.subs?.length)
20684
+ return null;
20685
+ const named = args.filter((arg) => !["-A", "--all", "--"].includes(arg));
20686
+ if (named.some((arg) => arg.startsWith("-") || /[*?[\]]/u.test(arg)))
20687
+ return null;
20688
+ if (!named.length && !args.some((arg) => arg === "-A" || arg === "--all"))
20689
+ return null;
20690
+ if (named.length)
20691
+ paths.push(...named);
20692
+ else
20693
+ all = true;
20694
+ }
20695
+ const messages = [];
20696
+ let allowEmpty = false;
20697
+ for (let index = 2;index < commit.words.length; index++) {
20698
+ const arg = commit.words[index];
20699
+ let message = null;
20700
+ if (arg === "--allow-empty") {
20701
+ allowEmpty = true;
20702
+ continue;
20703
+ }
20704
+ if (arg === "-m" || arg === "--message")
20705
+ message = messageOf(commit, ++index);
20706
+ else if (!commit.expands?.includes(index) && /^(?:-m|--message=)./u.test(arg))
20707
+ message = arg.replace(/^(?:-m|--message=)/u, "");
20708
+ if (!message || message.startsWith("-"))
20709
+ return null;
20710
+ messages.push(message);
20711
+ }
20712
+ if (!messages.length)
20713
+ return null;
20714
+ if (!all) {
20715
+ const staged = spawnSync15("git", ["diff", "--cached", "--quiet"], {
20716
+ cwd: target,
20717
+ timeout: 5000
20718
+ });
20719
+ if (staged.status !== 0)
20720
+ return null;
20721
+ }
20722
+ return [
20723
+ `workit git --cwd ${word(target)} commit`,
20724
+ ...messages.map((message) => `-m ${shellQuote(message)}`),
20725
+ ...allowEmpty ? ["--allow-empty"] : [],
20726
+ all ? "--all" : `-- ${[...new Set(paths)].map(word).join(" ")}`
20727
+ ].join(" ");
20728
+ };
20729
+ var commitRefusal = (input, command, dialect, { action, repo, invocation, workit }) => {
20730
+ if (action.kind !== "commit" || !(workit || policyDeclared()))
20731
+ return null;
20732
+ const switches = workitInvocations(command, dialect).length > 0 || rawInvocations(command, dialect).some((raw) => ["switch", "checkout", "worktree"].includes(raw.args[0] ?? ""));
20733
+ let guarded = false;
20734
+ try {
20735
+ guarded = !!repo.branch && resolveBranchPolicyFor(repo.dir).protected.has(repo.branch.toLowerCase());
20736
+ } catch {}
20737
+ if (guarded && !switches)
20738
+ return `workit: raw ${quote("git commit")} on ${repo.branch}, a protected branch. Branch first: ${quote("workit git branch --kind feature --slug <slug>")} (uncommitted changes come along), then ${quote("workit git commit -m '<msg>' -- <paths>")}.`;
20739
+ const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path27.resolve(input.cwd, invocation.dir), repo);
20740
+ return call && `workit: no ${quote("cd … &&")} chain; run ${quote(call)}.`;
20741
+ };
20569
20742
  function rawGitPre(input, command, options = {}) {
20570
20743
  try {
20571
20744
  const dialect = dialectOf(input);
@@ -20581,6 +20754,11 @@ function rawGitPre(input, command, options = {}) {
20581
20754
  if (refused)
20582
20755
  return deny(refused);
20583
20756
  }
20757
+ for (const found of located) {
20758
+ const refused = commitRefusal(input, command, dialect, found);
20759
+ if (refused)
20760
+ return deny(refused);
20761
+ }
20584
20762
  for (const { action, repo, invocation, workit } of located) {
20585
20763
  if (!workit)
20586
20764
  continue;
@@ -20656,9 +20834,9 @@ var grantRefusal = (action, repo, invocation, cache) => {
20656
20834
  return null;
20657
20835
  };
20658
20836
  var localTag = (repo, name) => {
20659
- const common = path26.dirname(repo.location.dir);
20837
+ const common = path27.dirname(repo.location.dir);
20660
20838
  try {
20661
- return fs18.existsSync(path26.join(common, "refs/tags", name)) || fs18.readFileSync(path26.join(common, "packed-refs"), "utf8").includes(` refs/tags/${name}
20839
+ return fs18.existsSync(path27.join(common, "refs/tags", name)) || fs18.readFileSync(path27.join(common, "packed-refs"), "utf8").includes(` refs/tags/${name}
20662
20840
  `);
20663
20841
  } catch {
20664
20842
  return false;
@@ -20678,7 +20856,7 @@ var analysisDenial = (error) => ({
20678
20856
  });
20679
20857
  var NEXT_COMMAND = "next";
20680
20858
  var MARKER_TTL_SECONDS = 3600;
20681
- var markerFile = (repo, session, key) => path26.join(repo.location.dir, "hooks", `commit-${createHash15("sha256").update(`${session}\x00${key}`).digest("hex").slice(0, 32)}.json`);
20859
+ var markerFile = (repo, session, key) => path27.join(repo.location.dir, "hooks", `commit-${createHash15("sha256").update(`${session}\x00${key}`).digest("hex").slice(0, 32)}.json`);
20682
20860
  var callKey = (toolUseId, command) => toolUseId ?? `cmd:${createHash15("sha256").update(command).digest("hex")}`;
20683
20861
  function noteRawCommit(input, command, key) {
20684
20862
  try {
@@ -20689,7 +20867,7 @@ function noteRawCommit(input, command, key) {
20689
20867
  if (action.kind !== "commit")
20690
20868
  continue;
20691
20869
  const file = markerFile(repo, input.session.id, key);
20692
- fs18.mkdirSync(path26.dirname(file), { recursive: true });
20870
+ fs18.mkdirSync(path27.dirname(file), { recursive: true });
20693
20871
  fs18.writeFileSync(file, `${JSON.stringify({ head: headSha2(repo), at })}
20694
20872
  `);
20695
20873
  }
@@ -20930,7 +21108,7 @@ var judgedDir = (root, dir) => {
20930
21108
  return null;
20931
21109
  if (dir === null)
20932
21110
  return root;
20933
- const resolved = path27.resolve(root, dir);
21111
+ const resolved = path28.resolve(root, dir);
20934
21112
  return existsSync9(resolved) && inWorkitWorkspace(resolved) ? resolved : null;
20935
21113
  };
20936
21114
  var shellBranchPolicyViolation = (root, command, dialect = "posix") => {
@@ -22928,7 +23106,7 @@ class WorkitCore {
22928
23106
  // packages/workit-core/src/core/repo-context.ts
22929
23107
  import { spawnSync as spawnSync17 } from "node:child_process";
22930
23108
  import { existsSync as existsSync10, readFileSync as readFileSync8, readdirSync as readdirSync3 } from "node:fs";
22931
- import path28 from "node:path";
23109
+ import path29 from "node:path";
22932
23110
  var isSafeContextRange = (value) => value.length <= 4096 && (() => {
22933
23111
  try {
22934
23112
  gitRevisionParts(value);
@@ -23072,13 +23250,13 @@ var findPrTemplate = (cwd) => {
23072
23250
  for (const rel of PR_TEMPLATE_FILES) {
23073
23251
  const parts = rel.split("/");
23074
23252
  const base = parts[parts.length - 1];
23075
- const dir = parts.length > 1 ? path28.join(cwd, ...parts.slice(0, -1)) : cwd;
23253
+ const dir = parts.length > 1 ? path29.join(cwd, ...parts.slice(0, -1)) : cwd;
23076
23254
  const actual = probeCaseInsensitive(dir, base);
23077
23255
  if (actual)
23078
23256
  return [...parts.slice(0, -1), actual].join("/");
23079
23257
  }
23080
23258
  for (const rel of PR_TEMPLATE_DIRS) {
23081
- const only = singleMarkdown(path28.join(cwd, ...rel.split("/")));
23259
+ const only = singleMarkdown(path29.join(cwd, ...rel.split("/")));
23082
23260
  if (only)
23083
23261
  return `${rel}/${only}`;
23084
23262
  }
@@ -23108,7 +23286,7 @@ var diffStatForRange = (cwd, range) => {
23108
23286
  return runGit(cwd, ["diff", "--stat", "--"]).stdout;
23109
23287
  };
23110
23288
  var packageScripts = (cwd, keys) => {
23111
- const pkgPath = path28.join(cwd, "package.json");
23289
+ const pkgPath = path29.join(cwd, "package.json");
23112
23290
  if (!existsSync10(pkgPath))
23113
23291
  return [];
23114
23292
  try {
@@ -23134,9 +23312,9 @@ var documentationFiles = (cwd) => {
23134
23312
  if (entry.isDirectory()) {
23135
23313
  if (excluded.has(entry.name))
23136
23314
  continue;
23137
- walk(path28.join(dir, entry.name), depth + 1);
23315
+ walk(path29.join(dir, entry.name), depth + 1);
23138
23316
  } else if (entry.isFile() && (entry.name === "README.md" || entry.name.endsWith(".md"))) {
23139
- matches.push("./" + path28.relative(cwd, path28.join(dir, entry.name)).replaceAll("\\", "/"));
23317
+ matches.push("./" + path29.relative(cwd, path29.join(dir, entry.name)).replaceAll("\\", "/"));
23140
23318
  }
23141
23319
  }
23142
23320
  };
@@ -23152,7 +23330,7 @@ var readTrimmed2 = (file, maxLines) => {
23152
23330
  `);
23153
23331
  };
23154
23332
  function prReadyContext(root, range) {
23155
- const cwd = path28.resolve(repoRoot(root));
23333
+ const cwd = path29.resolve(repoRoot(root));
23156
23334
  if (range !== undefined && !isResolvableContextRange(cwd, range))
23157
23335
  return invalidRange(cwd);
23158
23336
  let stdout = "";
@@ -23210,7 +23388,7 @@ ${status.stderr}` : "");
23210
23388
  stdout += `template_path: ${template}
23211
23389
 
23212
23390
  `;
23213
- stdout += readTrimmed2(path28.join(cwd, template), 220);
23391
+ stdout += readTrimmed2(path29.join(cwd, template), 220);
23214
23392
  } else {
23215
23393
  stdout += `template_path: none
23216
23394
 
@@ -23220,7 +23398,7 @@ ${status.stderr}` : "");
23220
23398
  stdout += `
23221
23399
  `;
23222
23400
  stdout += printSection("Recent Validation Signals");
23223
- if (existsSync10(path28.join(cwd, "package.json"))) {
23401
+ if (existsSync10(path29.join(cwd, "package.json"))) {
23224
23402
  stdout += `package.json detected. Common scripts:
23225
23403
  `;
23226
23404
  const found = packageScripts(cwd, ["lint", "format:check", "test", "build"]);
@@ -23229,7 +23407,7 @@ ${status.stderr}` : "");
23229
23407
  `) + `
23230
23408
  `;
23231
23409
  }
23232
- if (existsSync10(path28.join(cwd, "Cargo.toml")) || existsSync10(path28.join(cwd, "src-tauri/Cargo.toml"))) {
23410
+ if (existsSync10(path29.join(cwd, "Cargo.toml")) || existsSync10(path29.join(cwd, "src-tauri/Cargo.toml"))) {
23233
23411
  stdout += `Rust project detected.
23234
23412
  `;
23235
23413
  }
@@ -23262,7 +23440,7 @@ var CHANGELOG_RULES = `- Use an [Unreleased] section.
23262
23440
  - Apply with the host-native editor, preserving the repository changelog conventions.
23263
23441
  - If Unreleased already has duplicate category headings, normalize_only first.`;
23264
23442
  function changelogContext(root, range) {
23265
- const cwd = path28.resolve(repoRoot(root));
23443
+ const cwd = path29.resolve(repoRoot(root));
23266
23444
  if (range !== undefined && !isResolvableContextRange(cwd, range))
23267
23445
  return invalidRange(cwd);
23268
23446
  const resolvedRange = rangeArgOrDefault(range, cwd);
@@ -23280,7 +23458,7 @@ function changelogContext(root, range) {
23280
23458
  stdout += CHANGELOG_RULES + `
23281
23459
  `;
23282
23460
  stdout += printSection("Existing CHANGELOG.md");
23283
- const changelogPath = path28.join(cwd, "CHANGELOG.md");
23461
+ const changelogPath = path29.join(cwd, "CHANGELOG.md");
23284
23462
  if (existsSync10(changelogPath)) {
23285
23463
  stdout += readTrimmed2(changelogPath, 260) + `
23286
23464
  `;
@@ -23300,7 +23478,7 @@ function changelogContext(root, range) {
23300
23478
  return { stdout, stderr: "", exitCode: 0, cwd };
23301
23479
  }
23302
23480
  function docsRefreshContext(root, range) {
23303
- const cwd = path28.resolve(repoRoot(root));
23481
+ const cwd = path29.resolve(repoRoot(root));
23304
23482
  if (range !== undefined && !isResolvableContextRange(cwd, range))
23305
23483
  return invalidRange(cwd);
23306
23484
  const resolvedRange = rangeArgOrDefault(range, cwd);
@@ -23322,7 +23500,7 @@ function docsRefreshContext(root, range) {
23322
23500
  `) + `
23323
23501
  `;
23324
23502
  stdout += printSection("README Preview");
23325
- const readme = path28.join(cwd, "README.md");
23503
+ const readme = path29.join(cwd, "README.md");
23326
23504
  if (existsSync10(readme)) {
23327
23505
  stdout += readTrimmed2(readme, 220) + `
23328
23506
  `;
@@ -23331,7 +23509,7 @@ function docsRefreshContext(root, range) {
23331
23509
  `;
23332
23510
  }
23333
23511
  stdout += printSection("Package Scripts");
23334
- const pkgPath = path28.join(cwd, "package.json");
23512
+ const pkgPath = path29.join(cwd, "package.json");
23335
23513
  if (existsSync10(pkgPath)) {
23336
23514
  try {
23337
23515
  const pkg = JSON.parse(readFileSync8(pkgPath, "utf8"));
@@ -23345,7 +23523,7 @@ function docsRefreshContext(root, range) {
23345
23523
  return { stdout, stderr: "", exitCode: 0, cwd };
23346
23524
  }
23347
23525
  function releaseNotesContext(root, rangeOrTag) {
23348
- const cwd = path28.resolve(repoRoot(root));
23526
+ const cwd = path29.resolve(repoRoot(root));
23349
23527
  if (!rangeOrTag) {
23350
23528
  return {
23351
23529
  stdout: "",
@@ -23388,7 +23566,7 @@ function releaseNotesContext(root, rangeOrTag) {
23388
23566
  `;
23389
23567
  stdout += printSection("Existing Release Files");
23390
23568
  for (const rel of ["CHANGELOG.md", "RELEASE_NOTES.md", ".github/releases.md"]) {
23391
- if (existsSync10(path28.join(cwd, rel)))
23569
+ if (existsSync10(path29.join(cwd, rel)))
23392
23570
  stdout += rel + `
23393
23571
  `;
23394
23572
  }
@@ -23420,7 +23598,7 @@ import { spawnSync as spawnSync19 } from "node:child_process";
23420
23598
 
23421
23599
  // packages/workit-core/src/core/pr-create.ts
23422
23600
  import fs19 from "node:fs";
23423
- import path29 from "node:path";
23601
+ import path30 from "node:path";
23424
23602
  import { spawnSync as spawnSync18 } from "node:child_process";
23425
23603
  // packages/workit-core/src/forge/pr-body.ts
23426
23604
  function parseGhIssue(value) {
@@ -23440,11 +23618,11 @@ var LOCAL = bounded(20000);
23440
23618
  var NETWORK = bounded(60000);
23441
23619
  function whichOnPath(tool) {
23442
23620
  const names = process.platform === "win32" ? [tool, `${tool}.exe`, `${tool}.cmd`] : [tool];
23443
- for (const dir of (process.env.PATH ?? "").split(path29.delimiter)) {
23621
+ for (const dir of (process.env.PATH ?? "").split(path30.delimiter)) {
23444
23622
  if (!dir)
23445
23623
  continue;
23446
23624
  for (const name of names) {
23447
- const candidate = path29.join(dir, name);
23625
+ const candidate = path30.join(dir, name);
23448
23626
  try {
23449
23627
  fs19.accessSync(candidate, fs19.constants.X_OK);
23450
23628
  return candidate;
@@ -23565,7 +23743,7 @@ var fetchGitLabIssueBody = async (ref, root, deps = {}) => {
23565
23743
 
23566
23744
  // packages/workit-core/src/core/youtrack.ts
23567
23745
  import fs21 from "node:fs";
23568
- import path31 from "node:path";
23746
+ import path32 from "node:path";
23569
23747
 
23570
23748
  // packages/workit-core/src/core/templates.ts
23571
23749
  var repoRoot2 = assetRoot();
@@ -23580,7 +23758,7 @@ import { spawnSync as spawnSync20 } from "node:child_process";
23580
23758
 
23581
23759
  // packages/workit-core/src/forge/exec.ts
23582
23760
  import fs20 from "node:fs";
23583
- import path30 from "node:path";
23761
+ import path31 from "node:path";
23584
23762
 
23585
23763
  // packages/workit-core/src/forge/redact.ts
23586
23764
  var KEY = String.raw`[A-Za-z0-9_.-]*?(?:token|secret|password|passwd|pwd|api[_-]?key|access[_-]?key|account[_-]?key|private[_-]?key|client[_-]?secret|credentials?|authorization|cookie|signature)[A-Za-z0-9_.-]*`;
@@ -23591,11 +23769,11 @@ var ANSI = new RegExp(String.raw`\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007]*\
23591
23769
  // packages/workit-core/src/forge/exec.ts
23592
23770
  var MAX_BUFFER2 = 64 * 1024 * 1024;
23593
23771
  function findExecutable(bin, env) {
23594
- const dirs = (env.PATH ?? env.Path ?? "").split(path30.delimiter).filter(Boolean);
23772
+ const dirs = (env.PATH ?? env.Path ?? "").split(path31.delimiter).filter(Boolean);
23595
23773
  const exts = process.platform === "win32" ? [".exe"] : [""];
23596
23774
  for (const dir of dirs)
23597
23775
  for (const ext of exts) {
23598
- const candidate = path30.join(dir, `${bin}${ext}`);
23776
+ const candidate = path31.join(dir, `${bin}${ext}`);
23599
23777
  try {
23600
23778
  const stat = fs20.statSync(candidate);
23601
23779
  if (stat.isFile())
@@ -23638,7 +23816,7 @@ var YTRACK_MISSING = "ytrack is not on PATH: Workit reaches YouTrack only throug
23638
23816
 
23639
23817
  // packages/workit-core/src/core/youtrack.ts
23640
23818
  var ISSUE_RE = /^[A-Z]+-\d+$/;
23641
- var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ?? path31.join(resolveConfigDir(), "youtrack.json");
23819
+ var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ?? path32.join(resolveConfigDir(), "youtrack.json");
23642
23820
  var readYouTrackContextConfig = () => {
23643
23821
  const cfgPath = youTrackReadOnlyConfigPath();
23644
23822
  if (!fs21.existsSync(cfgPath))
@@ -24006,15 +24184,15 @@ function resolveGitRevision(root, value) {
24006
24184
  }
24007
24185
  function resolveInside(root, candidate) {
24008
24186
  const base = realpathSync8(root);
24009
- const target = path32.resolve(base, candidate);
24010
- if (target !== base && !target.startsWith(base + path32.sep)) {
24187
+ const target = path33.resolve(base, candidate);
24188
+ if (target !== base && !target.startsWith(base + path33.sep)) {
24011
24189
  throw new Error("path must stay inside repository root");
24012
24190
  }
24013
24191
  let ancestor = target;
24014
24192
  while (!existsSync11(ancestor))
24015
- ancestor = path32.dirname(ancestor);
24193
+ ancestor = path33.dirname(ancestor);
24016
24194
  const canonicalAncestor = realpathSync8(ancestor);
24017
- if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base + path32.sep)) {
24195
+ if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base + path33.sep)) {
24018
24196
  throw new Error("path must stay inside repository root");
24019
24197
  }
24020
24198
  return target;
@@ -24060,7 +24238,7 @@ var capabilitiesFor = (descriptor, observed = {}) => descriptor.capabilities.map
24060
24238
  // packages/workit-core/src/hooks/context.ts
24061
24239
  import { createHash as createHash16 } from "node:crypto";
24062
24240
  import fs22 from "node:fs";
24063
- import path33 from "node:path";
24241
+ import path34 from "node:path";
24064
24242
  var MIGRATION_PENDING_NOTE = "workit migration pending — run `workit task status`";
24065
24243
  var migrationPending = (result) => !result.ok && result.code === "needs_input" && (result.error ?? "").startsWith(MIGRATION_PENDING);
24066
24244
  var boundTo = (entry, session) => entry.sessions.some((item) => item.host === session.host && item.handle === session.handle);
@@ -24148,7 +24326,7 @@ function entryCompactContext(store, entry, session, context) {
24148
24326
  current: () => recentSignal(store.root)
24149
24327
  };
24150
24328
  const observed = task?.data.evidence.some(isObservedCheck) ?? false;
24151
- const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [path33.resolve(store.root, ref.path)] : []));
24329
+ const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [path34.resolve(store.root, ref.path)] : []));
24152
24330
  const observedFiles = filesKey(files);
24153
24331
  const compact = compactContext(store, context, entry?.id ?? null, freshness, origin && { origin: origin.origin, taskId: origin.entry.id });
24154
24332
  if (!compact.ok || !compact.data)
@@ -24207,17 +24385,17 @@ ${options.addendum}` : ""}
24207
24385
  </workit-contract>`;
24208
24386
  };
24209
24387
  var checkoutAt = (cwd) => {
24210
- for (let dir = path33.resolve(cwd);; dir = path33.dirname(dir)) {
24211
- const dotGit = path33.join(dir, ".git");
24388
+ for (let dir = path34.resolve(cwd);; dir = path34.dirname(dir)) {
24389
+ const dotGit = path34.join(dir, ".git");
24212
24390
  if (fs22.existsSync(dotGit)) {
24213
- const admin = fs22.statSync(dotGit).isFile() ? path33.resolve(dir, /^gitdir:\s*(.+)$/mu.exec(fs22.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "") : dotGit;
24214
- const head = fs22.readFileSync(path33.join(admin, "HEAD"), "utf8").trim();
24391
+ const admin = fs22.statSync(dotGit).isFile() ? path34.resolve(dir, /^gitdir:\s*(.+)$/mu.exec(fs22.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "") : dotGit;
24392
+ const head = fs22.readFileSync(path34.join(admin, "HEAD"), "utf8").trim();
24215
24393
  return {
24216
24394
  root: dir,
24217
24395
  branch: /^ref: refs\/heads\/(.+)$/u.exec(head)?.[1] ?? null
24218
24396
  };
24219
24397
  }
24220
- if (path33.dirname(dir) === dir)
24398
+ if (path34.dirname(dir) === dir)
24221
24399
  return null;
24222
24400
  }
24223
24401
  };
@@ -24228,7 +24406,7 @@ var whereLine = (cwd) => {
24228
24406
  return null;
24229
24407
  const allowed = branchPolicySnapshotFor(cwd).namePolicy.allowed;
24230
24408
  const kinds = allowed.some((pattern) => pattern.source === "^.*$") ? "any" : allowedKinds(allowed).join(", ") || "see `workit help git`";
24231
- const place = checkout.root === path33.resolve(cwd) ? "" : ` in ${checkout.root}`;
24409
+ const place = checkout.root === path34.resolve(cwd) ? "" : ` in ${checkout.root}`;
24232
24410
  return `cwd ${cwd}${place} on ${checkout.branch ?? "detached HEAD"}; branch kinds: ${kinds}`;
24233
24411
  } catch {
24234
24412
  return null;
@@ -24255,14 +24433,14 @@ var turnMarker = (input) => {
24255
24433
  if (location instanceof Error)
24256
24434
  return null;
24257
24435
  const session = [input.host, input.session.id, input.session.agentId ?? ""].join("\x00");
24258
- return path33.join(location.dir, "hooks", `turn-${digestOf(session).slice(0, 32)}.json`);
24436
+ return path34.join(location.dir, "hooks", `turn-${digestOf(session).slice(0, 32)}.json`);
24259
24437
  } catch {
24260
24438
  return null;
24261
24439
  }
24262
24440
  };
24263
24441
  var writeTurnDigest = (file, digest) => {
24264
24442
  try {
24265
- fs22.mkdirSync(path33.dirname(file), { recursive: true });
24443
+ fs22.mkdirSync(path34.dirname(file), { recursive: true });
24266
24444
  fs22.writeFileSync(file, `${JSON.stringify({ digest })}
24267
24445
  `);
24268
24446
  } catch {}
@@ -24277,7 +24455,7 @@ var pruneTurnDigests = (dir, now) => {
24277
24455
  for (const name of fs22.readdirSync(dir)) {
24278
24456
  if (!name.startsWith("turn-"))
24279
24457
  continue;
24280
- const file = path33.join(dir, name);
24458
+ const file = path34.join(dir, name);
24281
24459
  try {
24282
24460
  if (now - fs22.statSync(file).mtimeMs > TURN_TTL_MS)
24283
24461
  fs22.rmSync(file, { force: true });
@@ -24307,7 +24485,7 @@ var seedTurnContext = (input, descriptor, text = turnContextText(input, descript
24307
24485
  const file = turnMarker(input);
24308
24486
  if (!file)
24309
24487
  return;
24310
- pruneTurnDigests(path33.dirname(file), Date.now());
24488
+ pruneTurnDigests(path34.dirname(file), Date.now());
24311
24489
  if (text)
24312
24490
  writeTurnDigest(file, digestOf(text));
24313
24491
  else
@@ -24348,7 +24526,8 @@ var WORKIT_USER_ONLY = [
24348
24526
  ["release", "notes", "approve"],
24349
24527
  ["grant", "set"],
24350
24528
  ["grant", "raise"],
24351
- ["ledger", "void"]
24529
+ ["ledger", "void"],
24530
+ ["approve"]
24352
24531
  ];
24353
24532
  var ALLOWED = new Set(WORKIT_ALLOWED_VERBS);
24354
24533
  var hasWordsInOrder = (words, needle) => {
@@ -24413,7 +24592,7 @@ var userOnlyWorkitCall = (command, dialect = "posix") => {
24413
24592
  // packages/workit-core/src/core/heavy-rules.ts
24414
24593
  import fs23 from "node:fs";
24415
24594
  import os8 from "node:os";
24416
- import path34 from "node:path";
24595
+ import path35 from "node:path";
24417
24596
  var EMPTY2 = () => ({ deny: [], allow: [] });
24418
24597
  var readText3 = (file) => {
24419
24598
  try {
@@ -24454,19 +24633,19 @@ function parseJsonc(text) {
24454
24633
  return JSON.parse(out.replace(/,(\s*[}\]])/gu, "$1"));
24455
24634
  }
24456
24635
  function gitTop(cwd) {
24457
- for (let dir = path34.resolve(cwd);; dir = path34.dirname(dir)) {
24458
- if (fs23.existsSync(path34.join(dir, ".git")))
24636
+ for (let dir = path35.resolve(cwd);; dir = path35.dirname(dir)) {
24637
+ if (fs23.existsSync(path35.join(dir, ".git")))
24459
24638
  return dir;
24460
- if (path34.dirname(dir) === dir)
24639
+ if (path35.dirname(dir) === dir)
24461
24640
  return null;
24462
24641
  }
24463
24642
  }
24464
24643
  var projectDirs = (cwd) => {
24465
24644
  const top = gitTop(cwd);
24466
24645
  const dirs = [];
24467
- for (let dir = path34.resolve(cwd);; dir = path34.dirname(dir)) {
24646
+ for (let dir = path35.resolve(cwd);; dir = path35.dirname(dir)) {
24468
24647
  dirs.push(dir);
24469
- if (!top || dir === top || path34.dirname(dir) === dir)
24648
+ if (!top || dir === top || path35.dirname(dir) === dir)
24470
24649
  return dirs;
24471
24650
  }
24472
24651
  };
@@ -24478,12 +24657,12 @@ var CLAUDE_MANAGED = {
24478
24657
  };
24479
24658
  function claudeSettingsFiles(cwd, env, platform = process.platform) {
24480
24659
  const project = env.CLAUDE_PROJECT_DIR || gitTop(cwd) || cwd;
24481
- const user = env.CLAUDE_CONFIG_DIR || path34.join(homeOf(env), ".claude");
24660
+ const user = env.CLAUDE_CONFIG_DIR || path35.join(homeOf(env), ".claude");
24482
24661
  return [
24483
24662
  ...CLAUDE_MANAGED[platform] ? [CLAUDE_MANAGED[platform]] : [],
24484
- path34.join(user, "settings.json"),
24485
- path34.join(project, ".claude", "settings.json"),
24486
- path34.join(project, ".claude", "settings.local.json")
24663
+ path35.join(user, "settings.json"),
24664
+ path35.join(project, ".claude", "settings.json"),
24665
+ path35.join(project, ".claude", "settings.local.json")
24487
24666
  ];
24488
24667
  }
24489
24668
  var bashPattern = (entry) => {
@@ -24573,10 +24752,10 @@ var opencodeConfig = (value, rules) => {
24573
24752
  function opencodeRules(cwd, env = process.env) {
24574
24753
  const rules = EMPTY2();
24575
24754
  try {
24576
- const config = env.XDG_CONFIG_HOME || path34.join(homeOf(env), ".config");
24755
+ const config = env.XDG_CONFIG_HOME || path35.join(homeOf(env), ".config");
24577
24756
  const files = [
24578
- ...OPENCODE_NAMES.map((name) => path34.join(config, "opencode", name)),
24579
- ...projectDirs(cwd).flatMap((dir) => OPENCODE_NAMES.flatMap((name) => [path34.join(dir, name), path34.join(dir, ".opencode", name)])),
24757
+ ...OPENCODE_NAMES.map((name) => path35.join(config, "opencode", name)),
24758
+ ...projectDirs(cwd).flatMap((dir) => OPENCODE_NAMES.flatMap((name) => [path35.join(dir, name), path35.join(dir, ".opencode", name)])),
24580
24759
  ...env.OPENCODE_CONFIG ? [env.OPENCODE_CONFIG] : []
24581
24760
  ];
24582
24761
  for (const file of files) {
@@ -24620,9 +24799,9 @@ var codexRule = (body) => {
24620
24799
  function codexRules(cwd, env = process.env) {
24621
24800
  const rules = EMPTY2();
24622
24801
  try {
24623
- const home = env.CODEX_HOME || path34.join(homeOf(env), ".codex");
24802
+ const home = env.CODEX_HOME || path35.join(homeOf(env), ".codex");
24624
24803
  const top = gitTop(cwd) ?? cwd;
24625
- for (const dir of [path34.join(home, "rules"), path34.join(top, ".codex", "rules")]) {
24804
+ for (const dir of [path35.join(home, "rules"), path35.join(top, ".codex", "rules")]) {
24626
24805
  let files;
24627
24806
  try {
24628
24807
  files = fs23.readdirSync(dir).filter((name) => name.endsWith(".rules"));
@@ -24632,7 +24811,7 @@ function codexRules(cwd, env = process.env) {
24632
24811
  return "unreadable";
24633
24812
  }
24634
24813
  for (const name of files) {
24635
- const text = readText3(path34.join(dir, name)) ?? "";
24814
+ const text = readText3(path35.join(dir, name)) ?? "";
24636
24815
  for (const part of text.split(/\bprefix_rule\s*\(/u).slice(1)) {
24637
24816
  const rule = codexRule(part);
24638
24817
  if (!rule)
@@ -24651,8 +24830,8 @@ function cursorRules(cwd, env = process.env) {
24651
24830
  try {
24652
24831
  const top = gitTop(cwd) ?? cwd;
24653
24832
  for (const file of [
24654
- path34.join(homeOf(env), ".cursor", "cli-config.json"),
24655
- path34.join(top, ".cursor", "cli.json")
24833
+ path35.join(homeOf(env), ".cursor", "cli-config.json"),
24834
+ path35.join(top, ".cursor", "cli.json")
24656
24835
  ]) {
24657
24836
  const text = readText3(file);
24658
24837
  if (text === null)
@@ -24727,10 +24906,10 @@ function wrapAllowed(read, words, command, options = {}) {
24727
24906
 
24728
24907
  // packages/workit-core/src/core/heavy.ts
24729
24908
  import fs24 from "node:fs";
24730
- import path35 from "node:path";
24909
+ import path36 from "node:path";
24731
24910
  var stateDir2 = (env, platform = process.platform) => stateDir(env, platform);
24732
24911
  var HEAVY_COMMANDS_FILE = "heavy-commands.json";
24733
- var heavyCommandsFile = (env) => path35.join(stateDir2(env), HEAVY_COMMANDS_FILE);
24912
+ var heavyCommandsFile = (env) => path36.join(stateDir2(env), HEAVY_COMMANDS_FILE);
24734
24913
  var HEAVY_SCRIPT = /^(?:test|tests|t|tst|unit|integration|e2e|coverage|cov|lint|eslint|typecheck|type-check|types|tsc|check|verify|validate|build|compile|bundle|ci|sonar|cypress|playwright|jest|vitest|mocha|bench|benchmark|all)(?:$|[:_.-])/iu;
24735
24914
  var INFO_FLAGS = new Set(["--version", "-v", "-V", "--help", "-h", "help", "version"]);
24736
24915
  var WATCH_FLAG = /^(?:--watch(?:All)?(?:=.*)?|-w|--serve)$/u;
@@ -25005,7 +25184,7 @@ function machinePatterns(env) {
25005
25184
  return isRecord5(value) ? stringList(value.patterns) : [];
25006
25185
  }
25007
25186
  function repoPatterns(cwd) {
25008
- return repoHeavyCommands(gitTop(cwd) ?? path35.resolve(cwd));
25187
+ return repoHeavyCommands(gitTop(cwd) ?? path36.resolve(cwd));
25009
25188
  }
25010
25189
  function heavyLines(lines, options) {
25011
25190
  const found = [];
@@ -25083,12 +25262,12 @@ function heavyPlan(command, options) {
25083
25262
  }
25084
25263
  function workitOnPath2(env = process.env) {
25085
25264
  const names = process.platform === "win32" ? ["workit.exe", "workit.cmd", "workit"] : ["workit"];
25086
- for (const dir of (env.PATH ?? "").split(path35.delimiter))
25265
+ for (const dir of (env.PATH ?? "").split(path36.delimiter))
25087
25266
  for (const name of names) {
25088
25267
  if (!dir)
25089
25268
  continue;
25090
25269
  try {
25091
- fs24.accessSync(path35.join(dir, name), fs24.constants.X_OK);
25270
+ fs24.accessSync(path36.join(dir, name), fs24.constants.X_OK);
25092
25271
  return true;
25093
25272
  } catch {}
25094
25273
  }
@@ -25106,7 +25285,7 @@ function leaseRewrite(command) {
25106
25285
 
25107
25286
  // packages/workit-core/src/core/heavy-words.ts
25108
25287
  import fs25 from "node:fs";
25109
- import path36 from "node:path";
25288
+ import path37 from "node:path";
25110
25289
  var HEAVY_WORDS = new Set(("npm npx pnpm pnpx yarn bun bunx deno corepack make gmake docker podman nerdctl " + "python python3 py uv poetry pdm pipenv hatch rye bundle rake nx " + "jest vitest mocha ava tap karma jasmine nyc c8 tsc vue-tsc svelte-check eslint stylelint " + "tslint webpack webpack-cli rollup parcel tsup vite next nuxt nuxi astro ng react-scripts " + "playwright cypress wdio testcafe turbo lerna sonar-scanner sonarless sonarless-mcp go " + "golangci-lint gotestsum staticcheck cargo mvn mvnw gradle gradlew ant sbt bazel bazelisk " + "buck2 dotnet msbuild pytest py.test tox nox mypy pyright pylint coverage maturin pip pip3 " + "rspec rails phpunit pest phpstan psalm composer mix swift xcodebuild flutter dart pod cmake " + "ninja meson ctest scons docker-compose buildah earthly").split(" "));
25111
25290
  var wordsOf = (command) => command.split(/[\s;&|()<>`'"]+/u).map((word) => (word.split(/[\\/]/u).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd|bat)$/u, "")).filter(Boolean);
25112
25291
  var stateDir3 = (env) => stateDir(env);
@@ -25119,15 +25298,15 @@ var readJson2 = (file) => {
25119
25298
  };
25120
25299
  var patternWords = (cwd, env) => {
25121
25300
  const patterns = [];
25122
- const machine = readJson2(path36.join(stateDir3(env), "heavy-commands.json"));
25301
+ const machine = readJson2(path37.join(stateDir3(env), "heavy-commands.json"));
25123
25302
  if (Array.isArray(machine?.patterns))
25124
25303
  patterns.push(...machine.patterns);
25125
- for (let dir = path36.resolve(cwd);; dir = path36.dirname(dir)) {
25126
- if (fs25.existsSync(path36.join(dir, ".git"))) {
25304
+ for (let dir = path37.resolve(cwd);; dir = path37.dirname(dir)) {
25305
+ if (fs25.existsSync(path37.join(dir, ".git"))) {
25127
25306
  patterns.push(...repoHeavyCommands(dir));
25128
25307
  break;
25129
25308
  }
25130
- if (path36.dirname(dir) === dir)
25309
+ if (path37.dirname(dir) === dir)
25131
25310
  break;
25132
25311
  }
25133
25312
  const words = new Set;
@@ -25203,14 +25382,14 @@ var splitDenial = (plan) => ({
25203
25382
  // packages/workit-core/src/hooks/write-gate.ts
25204
25383
  import { existsSync as existsSync12, realpathSync as realpathSync9, statSync as statSync3 } from "node:fs";
25205
25384
  import os10 from "node:os";
25206
- import path38 from "node:path";
25385
+ import path39 from "node:path";
25207
25386
 
25208
25387
  // packages/workit-core/src/core/live-session.ts
25209
25388
  import { spawnSync as spawnSync22 } from "node:child_process";
25210
25389
  import { createHash as createHash17 } from "node:crypto";
25211
25390
  import fs26 from "node:fs";
25212
25391
  import os9 from "node:os";
25213
- import path37 from "node:path";
25392
+ import path38 from "node:path";
25214
25393
  var LIVE_SESSION_TTL_MS = 15 * 60000;
25215
25394
  var HEARTBEAT_EVERY_MS = 30000;
25216
25395
  var liveProbe = {
@@ -25284,15 +25463,15 @@ var liveOwner = (input, transport, env = process.env) => {
25284
25463
  };
25285
25464
  };
25286
25465
  var checkoutOf = (target) => {
25287
- let dir = path37.resolve(target);
25288
- while (!fs26.existsSync(dir) && path37.dirname(dir) !== dir)
25289
- dir = path37.dirname(dir);
25466
+ let dir = path38.resolve(target);
25467
+ while (!fs26.existsSync(dir) && path38.dirname(dir) !== dir)
25468
+ dir = path38.dirname(dir);
25290
25469
  if (fs26.existsSync(dir) && !fs26.statSync(dir).isDirectory())
25291
- dir = path37.dirname(dir);
25292
- const parts = dir.split(path37.sep);
25470
+ dir = path38.dirname(dir);
25471
+ const parts = dir.split(path38.sep);
25293
25472
  const dotGit = parts.lastIndexOf(".git");
25294
25473
  if (dotGit > 0)
25295
- dir = parts.slice(0, dotGit).join(path37.sep) || path37.sep;
25474
+ dir = parts.slice(0, dotGit).join(path38.sep) || path38.sep;
25296
25475
  const location = resolveStore(dir);
25297
25476
  if (location instanceof Error || !location.shared || !location.top)
25298
25477
  return null;
@@ -25302,9 +25481,9 @@ var checkoutOf = (target) => {
25302
25481
  } catch {}
25303
25482
  return top;
25304
25483
  };
25305
- var markerFile2 = (top) => path37.join(resolveStateDir(), "live-sessions", `${createHash17("sha256").update(checkoutKey(top)).digest("hex").slice(0, 32)}.json`);
25484
+ var markerFile2 = (top) => path38.join(resolveStateDir(), "live-sessions", `${createHash17("sha256").update(checkoutKey(top)).digest("hex").slice(0, 32)}.json`);
25306
25485
  var checkoutKey = (top, platform = process.platform) => {
25307
- let key = path37.resolve(top);
25486
+ let key = path38.resolve(top);
25308
25487
  try {
25309
25488
  key = fs26.realpathSync.native(key);
25310
25489
  } catch {}
@@ -25399,7 +25578,7 @@ var claimLiveSession = (target, owner, deps = {}) => {
25399
25578
  checkout,
25400
25579
  heartbeatAt: now.toISOString()
25401
25580
  };
25402
- fs26.mkdirSync(path37.dirname(file), { recursive: true });
25581
+ fs26.mkdirSync(path38.dirname(file), { recursive: true });
25403
25582
  const temp = `${file}.${process.pid}.tmp`;
25404
25583
  fs26.writeFileSync(temp, JSON.stringify(marker));
25405
25584
  fs26.renameSync(temp, file);
@@ -25411,22 +25590,22 @@ var NONE3 = { kind: "none" };
25411
25590
  var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "win32";
25412
25591
  var canonical3 = (file) => {
25413
25592
  let rest = "";
25414
- for (let dir = path38.resolve(file);; dir = path38.dirname(dir)) {
25593
+ for (let dir = path39.resolve(file);; dir = path39.dirname(dir)) {
25415
25594
  try {
25416
- return path38.join(realpathSync9.native(dir), rest);
25595
+ return path39.join(realpathSync9.native(dir), rest);
25417
25596
  } catch {
25418
- if (path38.dirname(dir) === dir)
25419
- return path38.resolve(file);
25420
- rest = rest ? path38.join(path38.basename(dir), rest) : path38.basename(dir);
25597
+ if (path39.dirname(dir) === dir)
25598
+ return path39.resolve(file);
25599
+ rest = rest ? path39.join(path39.basename(dir), rest) : path39.basename(dir);
25421
25600
  }
25422
25601
  }
25423
25602
  };
25424
25603
  var exempt = (cwd, root, file, plans) => {
25425
25604
  const fold = (value) => CASE_INSENSITIVE ? value.toLowerCase() : value;
25426
- const relative = path38.relative(fold(canonical3(root)), fold(canonical3(path38.resolve(cwd, file))));
25427
- if (relative.startsWith("..") || path38.isAbsolute(relative))
25605
+ const relative = path39.relative(fold(canonical3(root)), fold(canonical3(path39.resolve(cwd, file))));
25606
+ if (relative.startsWith("..") || path39.isAbsolute(relative))
25428
25607
  return true;
25429
- const posix = relative.split(path38.sep).join("/");
25608
+ const posix = relative.split(path39.sep).join("/");
25430
25609
  const segments = posix.split("/");
25431
25610
  return /\.mdx?$/i.test(posix) || segments[0] === "docs" || segments.includes("plans") || [...plans].some((plan) => fold(plan) === posix);
25432
25611
  };
@@ -25777,10 +25956,10 @@ var linkSources = (args, at) => {
25777
25956
  const sources = names.filter((name, index) => into >= 0 ? name !== dest : index < names.length - 1 || names.length === 1);
25778
25957
  const target = dest === undefined ? null : at(dest);
25779
25958
  const symbolic = args.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg));
25780
- const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target : path38.dirname(target);
25959
+ const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target : path39.dirname(target);
25781
25960
  return sources.flatMap((source) => {
25782
- if (symbolic && base !== null && !path38.isAbsolute(homeExpanded(source)))
25783
- return [path38.resolve(base, source)];
25961
+ if (symbolic && base !== null && !path39.isAbsolute(homeExpanded(source)))
25962
+ return [path39.resolve(base, source)];
25784
25963
  const resolved = at(source);
25785
25964
  return resolved ? [resolved] : [];
25786
25965
  });
@@ -25809,7 +25988,7 @@ var shellWrites = (command, depth = 0) => {
25809
25988
  return { writes: true, targets: unknown ? null : targets };
25810
25989
  };
25811
25990
  var cache3 = new Map;
25812
- var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path38.resolve(root, file)) ?? "-").join("\x00");
25991
+ var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path39.resolve(root, file)) ?? "-").join("\x00");
25813
25992
  var gateFor = (cwd) => {
25814
25993
  const store = new TaskStore(cwd);
25815
25994
  const listed = store.listTaskIndex();
@@ -25889,13 +26068,13 @@ var gitMutationDirs = (cwd, command, dialect) => {
25889
26068
  return [];
25890
26069
  if (sub === "stash" && ["list", "show"].includes(rest[0] ?? ""))
25891
26070
  return [];
25892
- return [path38.resolve(cwd, invocation.dir ?? ".")];
26071
+ return [path39.resolve(cwd, invocation.dir ?? ".")];
25893
26072
  });
25894
26073
  };
25895
26074
  var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
25896
26075
  var PUSHD2 = new Set(["pushd", "push-location"]);
25897
26076
  var POPD2 = new Set(["popd", "pop-location"]);
25898
- var UNKNOWN_DIR = path38.resolve(path38.parse(process.cwd()).root, ".workit-unknown-dir");
26077
+ var UNKNOWN_DIR = path39.resolve(path39.parse(process.cwd()).root, ".workit-unknown-dir");
25899
26078
  var cdInto = (dir, words, strict = false, vars = new Map) => {
25900
26079
  const lost = strict ? UNKNOWN_DIR : undefined;
25901
26080
  const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
@@ -25905,7 +26084,7 @@ var cdInto = (dir, words, strict = false, vars = new Map) => {
25905
26084
  return lost;
25906
26085
  if (dir === undefined)
25907
26086
  return lost;
25908
- return target === undefined ? os10.homedir() : path38.resolve(dir, target);
26087
+ return target === undefined ? os10.homedir() : path39.resolve(dir, target);
25909
26088
  };
25910
26089
  var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
25911
26090
  var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
@@ -26039,7 +26218,7 @@ var untrustedVars = (segments) => {
26039
26218
  }
26040
26219
  return { all, names };
26041
26220
  };
26042
- var UNKNOWN_VAR = path38.resolve(path38.parse(process.cwd()).root, ".workit-unknown-var");
26221
+ var UNKNOWN_VAR = path39.resolve(path39.parse(process.cwd()).root, ".workit-unknown-var");
26043
26222
  var REFERENCE = /\$\{(\w+)[^}]*\}|\$(\w+)|\$\([^)]*\)?|`[^`]*`?/g;
26044
26223
  var unresolvedRefs = (text) => [
26045
26224
  ...new Set([...text.matchAll(REFERENCE)].map((match) => {
@@ -26049,7 +26228,7 @@ var unresolvedRefs = (text) => [
26049
26228
  ];
26050
26229
  var unknownVarTarget = (text) => {
26051
26230
  const refs = unresolvedRefs(text);
26052
- return path38.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
26231
+ return path39.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
26053
26232
  };
26054
26233
  var applyOperator = (value, operator) => {
26055
26234
  if (operator === "")
@@ -26109,12 +26288,12 @@ var mktempPath = (value, dir) => {
26109
26288
  if (base === null && (temp || template === undefined))
26110
26289
  base = os10.tmpdir();
26111
26290
  const name = homeExpanded(template ?? "tmp.XXXXXXXXXX");
26112
- if (path38.isAbsolute(name))
26291
+ if (path39.isAbsolute(name))
26113
26292
  return name;
26114
26293
  const from = base === null ? dir : homeExpanded(base);
26115
- if (from === undefined || !path38.isAbsolute(from) && dir === undefined)
26294
+ if (from === undefined || !path39.isAbsolute(from) && dir === undefined)
26116
26295
  return null;
26117
- return path38.resolve(dir ?? from, from, name);
26296
+ return path39.resolve(dir ?? from, from, name);
26118
26297
  };
26119
26298
  var homeExpanded = (file) => {
26120
26299
  const match = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(file);
@@ -26134,9 +26313,9 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26134
26313
  const home = homeExpanded(text);
26135
26314
  if (strict && unresolvedRefs(home).length > 0)
26136
26315
  return [unknownVarTarget(home)];
26137
- if (path38.isAbsolute(home))
26316
+ if (path39.isAbsolute(home))
26138
26317
  return [home];
26139
- return base === undefined ? [] : [path38.resolve(base, home)];
26318
+ return base === undefined ? [] : [path39.resolve(base, home)];
26140
26319
  });
26141
26320
  const at = (file) => {
26142
26321
  const all = atAll(file);
@@ -26169,7 +26348,12 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26169
26348
  };
26170
26349
  for (const segment of segments) {
26171
26350
  if (segment.group === "open") {
26172
- groups.push({ dir, stack: [...stack], vars: new Map(vars), loops: new Map(loops) });
26351
+ groups.push({
26352
+ dir,
26353
+ stack: [...stack],
26354
+ vars: new Map(vars),
26355
+ loops: new Map(loops)
26356
+ });
26173
26357
  continue;
26174
26358
  }
26175
26359
  if (segment.group === "close") {
@@ -26278,7 +26462,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26278
26462
  const here = segment.unanalyzable ? DIR_TARGET : `${OPAQUE_TARGET}${encodeURIComponent(runner?.split(/[\\/]/).at(-1) ?? "a command")}`;
26279
26463
  for (const file of opaque ?? [])
26280
26464
  for (const resolved of atAll(file))
26281
- targets.push(file === "." ? path38.join(resolved, here) : resolved);
26465
+ targets.push(file === "." ? path39.join(resolved, here) : resolved);
26282
26466
  const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
26283
26467
  if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)))
26284
26468
  targets.push(...linkSources(words.slice(ln + 1), at));
@@ -26289,7 +26473,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26289
26473
  const edits = editsOf(body);
26290
26474
  if (edits === null) {
26291
26475
  if (dir !== undefined)
26292
- targets.push(path38.join(dir, DIR_TARGET));
26476
+ targets.push(path39.join(dir, DIR_TARGET));
26293
26477
  } else
26294
26478
  for (const file of edits)
26295
26479
  targets.push(...atAll(file));
@@ -26297,7 +26481,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26297
26481
  for (const invocation of workitInvocations(body.map(quoteWord2).join(" "), "posix")) {
26298
26482
  const { at: runsIn, args } = workitCwd(dir, invocation, atAll);
26299
26483
  if (args[0] === "git" && MUTATING_WORKIT_GIT.has(args[1] ?? "") && !inert(args.slice(2), ""))
26300
- targets.push(...runsIn.map((runs) => path38.join(runs, DIR_TARGET)));
26484
+ targets.push(...runsIn.map((runs) => path39.join(runs, DIR_TARGET)));
26301
26485
  }
26302
26486
  }
26303
26487
  return targets;
@@ -26318,7 +26502,7 @@ var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) =>
26318
26502
  try {
26319
26503
  return [
26320
26504
  ...segmentTargets(cwd, command, dialect, 0, strict),
26321
- ...gitMutationDirs(cwd, command, dialect).map((dir) => path38.join(dir, DIR_TARGET))
26505
+ ...gitMutationDirs(cwd, command, dialect).map((dir) => path39.join(dir, DIR_TARGET))
26322
26506
  ];
26323
26507
  } catch {
26324
26508
  return [];
@@ -26355,7 +26539,7 @@ var liveDeny = ({ marker, checkout, ageMs, file }) => {
26355
26539
  var guarded = (targets) => {
26356
26540
  const seen = new Set;
26357
26541
  return targets.filter((target) => {
26358
- const dir = path38.dirname(target);
26542
+ const dir = path39.dirname(target);
26359
26543
  if (seen.has(dir))
26360
26544
  return false;
26361
26545
  seen.add(dir);
@@ -26376,40 +26560,61 @@ var claimAll = (owner, targets, deps) => {
26376
26560
  for (const target of guarded(targets))
26377
26561
  claimLiveSession(target, owner, deps);
26378
26562
  };
26379
- var liveTargets = (cwd, paths) => paths?.length ? paths.map((file) => path38.resolve(cwd, file)) : [path38.join(cwd, DIR_TARGET)];
26380
- var issuedTarget = (cwd, targets) => {
26563
+ var liveTargets = (cwd, paths) => paths?.length ? paths.map((file) => path39.resolve(cwd, file)) : [path39.join(cwd, DIR_TARGET)];
26564
+ var registryTarget = (cwd, targets) => {
26381
26565
  const state = resolveStateDir();
26382
- const found = targets.find((target) => underIssued(state, cwd, homeExpanded(target), process.platform, canonical3));
26383
- return found ?? null;
26566
+ for (const target of targets) {
26567
+ const registry = underRegistry(state, cwd, homeExpanded(target), process.platform, canonical3);
26568
+ if (registry)
26569
+ return { file: target, registry };
26570
+ }
26571
+ return null;
26384
26572
  };
26385
- var underIssued = (state, cwd, target, platform = process.platform, real = (file) => file) => {
26573
+ var underRegistry = (state, cwd, target, platform = process.platform, real = (file) => file) => {
26386
26574
  const win = platform === "win32";
26387
- const p = win ? path38.win32 : path38.posix;
26575
+ const p = win ? path39.win32 : path39.posix;
26388
26576
  const fold = (value) => win || platform === "darwin" ? value.toLowerCase() : value;
26389
26577
  const named = win ? target.replace(/^\/([a-zA-Z])(?=\/|$)/, "$1:") : target;
26390
26578
  const relative = p.relative(fold(real(p.resolve(state))), fold(real(p.resolve(cwd, named))));
26391
26579
  if (relative.startsWith("..") || p.isAbsolute(relative))
26392
- return false;
26393
- return relative.split(p.sep)[0].startsWith("issued");
26580
+ return null;
26581
+ const first = relative.split(p.sep)[0];
26582
+ if (first.startsWith("issued"))
26583
+ return "issued";
26584
+ return first === "approvals" ? "approvals" : null;
26394
26585
  };
26395
- var unquotedWindowsIssued = (command) => {
26586
+ var unquotedWindowsRegistry = (command) => {
26396
26587
  if (process.platform !== "win32" || !command.includes("\\"))
26397
- return false;
26588
+ return null;
26398
26589
  const flat = (value) => value.replaceAll("\\", "/").toLowerCase();
26399
- return flat(command).includes(`${flat(resolveStateDir())}/issued`) && shellWrites(command).writes;
26590
+ const text = flat(command);
26591
+ const state = flat(resolveStateDir());
26592
+ const registry = text.includes(`${state}/issued`) ? "issued" : text.includes(`${state}/approvals`) ? "approvals" : null;
26593
+ return registry && shellWrites(command).writes ? registry : null;
26594
+ };
26595
+ var REGISTRY_DENY = {
26596
+ issued: {
26597
+ label: "issued-registry guard",
26598
+ unblock: "Issued ids and tokens are written only by Workit's SubagentStart hook. Run the verifier or reviewer agent so the host issues its own session; never edit the issued registries by hand."
26599
+ },
26600
+ approvals: {
26601
+ label: "approvals guard",
26602
+ unblock: "Approval requests and the user's yes are written only by Workit: run `workit approve <id>` as its own call so the host asks the user, or ask the user to run it in their own terminal; never edit the approvals registry by hand."
26603
+ }
26400
26604
  };
26401
- var issuedDeny = (file) => {
26402
- const unblock = "Issued ids and tokens are written only by Workit's SubagentStart hook. Run the verifier or reviewer agent so the host issues its own session; never edit the issued registries by hand.";
26605
+ var registryDeny = ({ file, registry }) => {
26606
+ const { label, unblock } = REGISTRY_DENY[registry];
26607
+ const what = registry === "issued" ? "issued-session state" : "host-approval state";
26403
26608
  return {
26404
26609
  kind: "deny",
26405
- reason: `workit issued-registry guard: ${file} is under Workit's issued-session state. ${unblock}`,
26610
+ reason: `workit ${label}: ${file} is under Workit's ${what}. ${unblock}`,
26406
26611
  unblock
26407
26612
  };
26408
26613
  };
26409
26614
  function writeGate(cwd, paths, owner, deps) {
26410
- const forged = paths?.length ? issuedTarget(cwd, paths) : null;
26615
+ const forged = paths?.length ? registryTarget(cwd, paths) : null;
26411
26616
  if (forged)
26412
- return issuedDeny(forged);
26617
+ return registryDeny(forged);
26413
26618
  if (!owner)
26414
26619
  return beforeWriteGate(cwd, paths);
26415
26620
  const targets = liveTargets(cwd, paths);
@@ -26423,9 +26628,10 @@ function writeGate(cwd, paths, owner, deps) {
26423
26628
  }
26424
26629
  function shellGate(cwd, command, owner, dialect = "posix", deps) {
26425
26630
  try {
26426
- const forged = issuedTarget(cwd, segmentTargets(cwd, command, dialect)) ?? (unquotedWindowsIssued(command) ? "the issued registry" : null);
26631
+ const windows = unquotedWindowsRegistry(command);
26632
+ const forged = registryTarget(cwd, segmentTargets(cwd, command, dialect)) ?? (windows ? { file: `the ${windows} registry`, registry: windows } : null);
26427
26633
  if (forged)
26428
- return issuedDeny(forged);
26634
+ return registryDeny(forged);
26429
26635
  } catch {}
26430
26636
  const writes = shellWrites(command);
26431
26637
  let targets = [];
@@ -26478,10 +26684,10 @@ import { spawnSync as spawnSync23 } from "node:child_process";
26478
26684
 
26479
26685
  // packages/workit-core/src/ci-waiter.ts
26480
26686
  import fs27 from "node:fs";
26481
- import path39 from "node:path";
26687
+ import path40 from "node:path";
26482
26688
  var waiterFile = (cwd, pr) => {
26483
26689
  const common = gitCommonDir(cwd);
26484
- return common ? path39.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
26690
+ return common ? path40.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
26485
26691
  };
26486
26692
  var pidAlive2 = (pid) => {
26487
26693
  if (!Number.isSafeInteger(pid) || pid <= 0)
@@ -27020,7 +27226,179 @@ var writePaths = (input) => {
27020
27226
  };
27021
27227
  // packages/workit-core/src/hooks/standing.ts
27022
27228
  import fs29 from "node:fs";
27229
+ import path43 from "node:path";
27230
+
27231
+ // packages/workit-core/src/approvals/store.ts
27232
+ import { createHash as createHash18, randomBytes as randomBytes4 } from "node:crypto";
27233
+ import { mkdirSync as mkdirSync5, readdirSync as readdirSync4, readFileSync as readFileSync9 } from "node:fs";
27023
27234
  import path41 from "node:path";
27235
+ var REQUEST_TTL_MS = 30 * 60000;
27236
+ var GRANT_TTL_MS = 15 * 60000;
27237
+ var ID_PATTERN = /^ap_[a-z2-7]{8}$/u;
27238
+ var isApprovalId = (word) => ID_PATTERN.test(word);
27239
+ var approvalHash = (fields) => createHash18("sha256").update(canonicalJson({
27240
+ kind: fields.kind,
27241
+ action: fields.action,
27242
+ target: fields.target,
27243
+ effect: fields.effect,
27244
+ subject: fields.subject
27245
+ })).digest("hex");
27246
+ var approvalsDir = () => path41.join(resolveStateDir(), "approvals");
27247
+ var dirOf = (part) => path41.join(approvalsDir(), part);
27248
+ var fileOf = (part, id) => path41.join(dirOf(part), `${id}.json`);
27249
+ var askedFile = (session, toolUseId) => path41.join(dirOf("asked"), `${createHash18("sha256").update(`${session}\x00${toolUseId}`).digest("hex").slice(0, 32)}.json`);
27250
+ var readJson3 = (file) => {
27251
+ try {
27252
+ const value = JSON.parse(readFileSync9(file, "utf8"));
27253
+ return value !== null && typeof value === "object" ? value : null;
27254
+ } catch {
27255
+ return null;
27256
+ }
27257
+ };
27258
+ var write = (file, value) => {
27259
+ mkdirSync5(path41.dirname(file), { recursive: true });
27260
+ writeFileAtomic(file, `${JSON.stringify(value, null, 2)}
27261
+ `);
27262
+ };
27263
+ var live = (expires, now) => Date.parse(expires) > now.getTime();
27264
+ var later = (now, ms) => new Date(now.getTime() + ms).toISOString();
27265
+ var readApprovalRequest = (id) => {
27266
+ if (!isApprovalId(id))
27267
+ return null;
27268
+ const request = readJson3(fileOf("requests", id));
27269
+ if (!request || request.id !== id)
27270
+ return null;
27271
+ try {
27272
+ return approvalHash(request) === request.hash ? request : null;
27273
+ } catch {
27274
+ return null;
27275
+ }
27276
+ };
27277
+ var liveApprovalRequest = (id, now = new Date) => {
27278
+ const request = readApprovalRequest(id);
27279
+ if (!request)
27280
+ return { ok: false, reason: `${id}: no such approval request` };
27281
+ if (!live(request.expires, now))
27282
+ return {
27283
+ ok: false,
27284
+ reason: `${id}: the request expired at ${request.expires}`
27285
+ };
27286
+ if (readJson3(fileOf("consumed", id)))
27287
+ return { ok: false, reason: `${id}: already approved and used` };
27288
+ if (readJson3(fileOf("rejected", id)))
27289
+ return {
27290
+ ok: false,
27291
+ reason: `${id}: the user rejected it or chose to edit its subject`
27292
+ };
27293
+ return { ok: true, request };
27294
+ };
27295
+ var subjectLine = (subject) => Object.entries(subject).map(([key, value]) => `${key}: ${typeof value === "string" ? value : JSON.stringify(value)}`).join("; ");
27296
+ var renderApprovalRequest = (request) => [
27297
+ `${request.id} (${request.kind}): ${request.action}`,
27298
+ ` target: ${Object.entries(request.target).map(([key, value]) => `${key} ${value}`).join(", ")}`,
27299
+ ` effect: ${request.effect}`,
27300
+ ` subject: ${subjectLine(request.subject)}`,
27301
+ ` hash: ${request.hash.slice(0, 12)} expires: ${request.expires}`
27302
+ ].join(`
27303
+ `);
27304
+ var recordApprovalAsked = (input, now = new Date) => {
27305
+ const hashes = {};
27306
+ for (const id of input.ids) {
27307
+ const found = liveApprovalRequest(id, now);
27308
+ if (found.ok)
27309
+ hashes[id] = found.request.hash;
27310
+ }
27311
+ const ids = Object.keys(hashes);
27312
+ if (ids.length === 0)
27313
+ return null;
27314
+ const asked = {
27315
+ toolUseId: input.toolUseId,
27316
+ session: input.session,
27317
+ host: input.host,
27318
+ ids,
27319
+ hashes,
27320
+ at: now.toISOString()
27321
+ };
27322
+ write(askedFile(input.session, input.toolUseId), asked);
27323
+ return asked;
27324
+ };
27325
+ var readApprovalAsked = (session, toolUseId) => {
27326
+ const asked = readJson3(askedFile(session, toolUseId));
27327
+ return asked && asked.session === session && asked.toolUseId === toolUseId ? asked : null;
27328
+ };
27329
+ var recordApprovalGrant = (input, options = {}) => {
27330
+ const now = options.now ?? new Date;
27331
+ const found = liveApprovalRequest(input.id, now);
27332
+ if (!found.ok)
27333
+ return found;
27334
+ if (input.via === "host") {
27335
+ const asked = input.session && input.toolUseId ? readApprovalAsked(input.session, input.toolUseId) : null;
27336
+ if (!asked || asked.hashes[input.id] !== found.request.hash)
27337
+ return {
27338
+ ok: false,
27339
+ reason: `${input.id}: no host ask showed this request on that call`
27340
+ };
27341
+ }
27342
+ const grant = {
27343
+ id: input.id,
27344
+ hash: found.request.hash,
27345
+ host: input.host,
27346
+ session: input.session,
27347
+ toolUseId: input.toolUseId,
27348
+ at: now.toISOString(),
27349
+ expires: later(now, options.ttlMs ?? GRANT_TTL_MS),
27350
+ via: input.via,
27351
+ observer: input.via === "host" ? "host_hook" : null
27352
+ };
27353
+ write(fileOf("grants", input.id), grant);
27354
+ return { ok: true, grant };
27355
+ };
27356
+ var recordApprovalRejected = (input, now = new Date) => {
27357
+ if (!readApprovalRequest(input.id))
27358
+ return;
27359
+ write(fileOf("rejected", input.id), { ...input, at: now.toISOString() });
27360
+ };
27361
+
27362
+ // packages/workit-core/src/approvals/call.ts
27363
+ var isWorkitWord2 = (word) => /^(?:.*[\\/])?workit(?:-cli)?$/u.test(word);
27364
+ var verbIndex = (words, start) => {
27365
+ let at = start;
27366
+ for (;; ) {
27367
+ const word = words[at];
27368
+ if (word === "--json")
27369
+ at += 1;
27370
+ else if (word === "--cwd" || word === "--session")
27371
+ at += 2;
27372
+ else if (word?.startsWith("--cwd="))
27373
+ at += 1;
27374
+ else
27375
+ return at;
27376
+ }
27377
+ };
27378
+ var approveCallIn = (command, dialect = "posix") => {
27379
+ const segments = segmentsOf(command, dialect);
27380
+ for (const segment of segments) {
27381
+ if (segment.unanalyzable)
27382
+ continue;
27383
+ const start = segment.words.findIndex(isWorkitWord2);
27384
+ if (start < 0)
27385
+ continue;
27386
+ const at = verbIndex(segment.words, start + 1);
27387
+ if (segment.words[at] !== "approve")
27388
+ continue;
27389
+ const args = segment.words.slice(at + 1);
27390
+ const ids = args.filter(isApprovalId);
27391
+ const plain = segments.length === 1 && start === 0 && segment.words[0] === "workit" && at === 1 && !segment.redirects.length && !segment.subs?.length && !segment.stdin?.length && !segment.expands?.length && !segment.group;
27392
+ if (plain)
27393
+ return ids.length > 0 && ids.length === args.length ? { plain: true, ids } : null;
27394
+ return {
27395
+ plain: false,
27396
+ fix: `workit approve ${ids.length ? ids.join(" ") : "<id>…"}`
27397
+ };
27398
+ }
27399
+ return null;
27400
+ };
27401
+ var approveCallDeny = (fix) => `Run \`${fix}\` as its own call: no chain, pipe, substitution, leading cd, env prefix or redirect around it, so the host can show the request and record the user's answer.`;
27024
27402
 
27025
27403
  // packages/workit-core/src/hooks/hosts/claude-code.ts
27026
27404
  var CLAUDE_CODE_DESCRIPTOR = {
@@ -27063,7 +27441,11 @@ var CLAUDE_CODE_DESCRIPTOR = {
27063
27441
  maxConcurrency: "undocumented",
27064
27442
  agentPrefix: "workit:"
27065
27443
  },
27066
- provenance: { sessionId: "native", agentIdOnTool: "native", postToolObserve: "native" },
27444
+ provenance: {
27445
+ sessionId: "native",
27446
+ agentIdOnTool: "native",
27447
+ postToolObserve: "native"
27448
+ },
27067
27449
  interaction: { questions: "undocumented", writeBoundary: "partial" },
27068
27450
  stopControl: "native",
27069
27451
  shellAvailable: "native",
@@ -27125,6 +27507,7 @@ var CONTEXT_EVENTS = new Set([
27125
27507
  "PreToolUse",
27126
27508
  "PostToolUse"
27127
27509
  ]);
27510
+ var ASKING_MODES = new Set(["default", "acceptEdits", "plan"]);
27128
27511
 
27129
27512
  // packages/workit-core/src/hooks/hosts/codex.ts
27130
27513
  var CODEX_DESCRIPTOR = {
@@ -27490,42 +27873,42 @@ function neededChecks(lane, configured) {
27490
27873
  }
27491
27874
 
27492
27875
  // packages/workit-core/src/hooks/worktree-confine.ts
27493
- import { createHash as createHash18 } from "node:crypto";
27876
+ import { createHash as createHash19 } from "node:crypto";
27494
27877
  import fs28 from "node:fs";
27495
- import path40 from "node:path";
27878
+ import path42 from "node:path";
27496
27879
  var FANOUT_TOKEN_FILE = "workit-fanout-token";
27497
27880
  var NONE5 = { kind: "none" };
27498
27881
  var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
27499
27882
  var canonical4 = (file) => {
27500
27883
  let rest = "";
27501
- for (let dir = path40.resolve(file);; dir = path40.dirname(dir)) {
27884
+ for (let dir = path42.resolve(file);; dir = path42.dirname(dir)) {
27502
27885
  try {
27503
- return path40.join(fs28.realpathSync.native(dir), rest);
27886
+ return path42.join(fs28.realpathSync.native(dir), rest);
27504
27887
  } catch {
27505
- if (path40.dirname(dir) === dir)
27506
- return path40.resolve(file);
27507
- rest = rest ? path40.join(path40.basename(dir), rest) : path40.basename(dir);
27888
+ if (path42.dirname(dir) === dir)
27889
+ return path42.resolve(file);
27890
+ rest = rest ? path42.join(path42.basename(dir), rest) : path42.basename(dir);
27508
27891
  }
27509
27892
  }
27510
27893
  };
27511
27894
  var within = (child, parent) => {
27512
27895
  const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
27513
- const relative = path40.relative(fold(parent), fold(child));
27514
- return relative === "" || !relative.startsWith("..") && !path40.isAbsolute(relative);
27896
+ const relative = path42.relative(fold(parent), fold(child));
27897
+ return relative === "" || !relative.startsWith("..") && !path42.isAbsolute(relative);
27515
27898
  };
27516
27899
  var checkoutOf2 = (file) => {
27517
- for (let dir = canonical4(file);; dir = path40.dirname(dir)) {
27518
- const dotGit = path40.join(dir, ".git");
27900
+ for (let dir = canonical4(file);; dir = path42.dirname(dir)) {
27901
+ const dotGit = path42.join(dir, ".git");
27519
27902
  if (fs28.existsSync(dotGit)) {
27520
27903
  if (!fs28.statSync(dotGit).isFile())
27521
27904
  return { root: dir, workit: false };
27522
27905
  const admin = /^gitdir:\s*(.+)$/mu.exec(fs28.readFileSync(dotGit, "utf8"))?.[1]?.trim();
27523
27906
  return {
27524
27907
  root: dir,
27525
- workit: Boolean(admin) && fs28.existsSync(path40.join(path40.resolve(dir, admin), FANOUT_TOKEN_FILE))
27908
+ workit: Boolean(admin) && fs28.existsSync(path42.join(path42.resolve(dir, admin), FANOUT_TOKEN_FILE))
27526
27909
  };
27527
27910
  }
27528
- if (path40.dirname(dir) === dir)
27911
+ if (path42.dirname(dir) === dir)
27529
27912
  return null;
27530
27913
  }
27531
27914
  };
@@ -27537,8 +27920,8 @@ var workitWorktreeOf = (file) => {
27537
27920
  return null;
27538
27921
  }
27539
27922
  };
27540
- var bindingDir = () => path40.join(resolveStateDir(), "worktree-bind");
27541
- var bindingFile = (session, agentId) => path40.join(bindingDir(), `${createHash18("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
27923
+ var bindingDir = () => path42.join(resolveStateDir(), "worktree-bind");
27924
+ var bindingFile = (session, agentId) => path42.join(bindingDir(), `${createHash19("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
27542
27925
  var readBinding = (file) => {
27543
27926
  try {
27544
27927
  const value = JSON.parse(fs28.readFileSync(file, "utf8"));
@@ -27563,7 +27946,7 @@ var bind = (input, worktree) => {
27563
27946
  agentId,
27564
27947
  at: new Date().toISOString()
27565
27948
  };
27566
- fs28.mkdirSync(path40.dirname(file), { recursive: true });
27949
+ fs28.mkdirSync(path42.dirname(file), { recursive: true });
27567
27950
  fs28.writeFileSync(file, JSON.stringify(binding));
27568
27951
  try {
27569
27952
  if (inWorkitWorkspace(input.cwd))
@@ -27582,31 +27965,31 @@ var hostIsolated = (cwd, agentId) => {
27582
27965
  const checkout = checkoutOf2(cwd);
27583
27966
  if (!checkout)
27584
27967
  return false;
27585
- const dotGit = path40.join(checkout.root, ".git");
27968
+ const dotGit = path42.join(checkout.root, ".git");
27586
27969
  if (!fs28.statSync(dotGit).isFile())
27587
27970
  return false;
27588
27971
  const admin = /^gitdir:\s*(.+)$/mu.exec(fs28.readFileSync(dotGit, "utf8"))?.[1]?.trim();
27589
27972
  if (!admin)
27590
27973
  return false;
27591
- const adminDir = path40.resolve(checkout.root, admin);
27592
- const back = fs28.readFileSync(path40.join(adminDir, "gitdir"), "utf8").trim();
27593
- if (path40.relative(canonical4(path40.resolve(adminDir, back)), canonical4(dotGit)) !== "")
27974
+ const adminDir = path42.resolve(checkout.root, admin);
27975
+ const back = fs28.readFileSync(path42.join(adminDir, "gitdir"), "utf8").trim();
27976
+ if (path42.relative(canonical4(path42.resolve(adminDir, back)), canonical4(dotGit)) !== "")
27594
27977
  return false;
27595
- const common = path40.join(adminDir, "commondir");
27596
- const gitDir = fs28.existsSync(common) ? path40.resolve(adminDir, fs28.readFileSync(common, "utf8").trim()) : adminDir;
27597
- const expected = path40.join(path40.dirname(canonical4(gitDir)), ".claude", "worktrees", `agent-${agentId}`);
27598
- return path40.relative(canonical4(expected), checkout.root) === "";
27978
+ const common = path42.join(adminDir, "commondir");
27979
+ const gitDir = fs28.existsSync(common) ? path42.resolve(adminDir, fs28.readFileSync(common, "utf8").trim()) : adminDir;
27980
+ const expected = path42.join(path42.dirname(canonical4(gitDir)), ".claude", "worktrees", `agent-${agentId}`);
27981
+ return path42.relative(canonical4(expected), checkout.root) === "";
27599
27982
  } catch {
27600
27983
  return false;
27601
27984
  }
27602
27985
  };
27603
27986
  var runnerAt = (target) => {
27604
- const base = path40.basename(target);
27987
+ const base = path42.basename(target);
27605
27988
  return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
27606
27989
  };
27607
27990
  var shown = (target) => {
27608
- const named = /^\.workit-(?:live-target$|runs-)/.test(path40.basename(target)) ? path40.dirname(target) : target;
27609
- return path40.sep === "\\" ? named.replaceAll("/", "\\") : named;
27991
+ const named = /^\.workit-(?:live-target$|runs-)/.test(path42.basename(target)) ? path42.dirname(target) : target;
27992
+ return path42.sep === "\\" ? named.replaceAll("/", "\\") : named;
27610
27993
  };
27611
27994
  var unboundDeny = (input, target) => {
27612
27995
  const unblock = "Work only in the worktree your brief names, which the lead made with `workit fanout worktree create <slice>`: edit files under it and run one verb per call against it (`workit git --cwd <worktree> commit -m … -- <paths>`, `workit check --cwd <worktree> <name>`). If your brief names no worktree, stop and report that to the lead.";
@@ -27645,7 +28028,7 @@ var literalForm = (command, refs) => {
27645
28028
  };
27646
28029
  var unknownVarDeny = (input, worktree, targets, command) => {
27647
28030
  const refs = [
27648
- ...new Set(targets.flatMap((target) => path40.relative(UNKNOWN_VAR, path40.resolve(target)).split(path40.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
28031
+ ...new Set(targets.flatMap((target) => path42.relative(UNKNOWN_VAR, path42.resolve(target)).split(path42.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
27649
28032
  ];
27650
28033
  let text = command ?? "";
27651
28034
  const first = [];
@@ -27674,10 +28057,10 @@ function confineImplementer(input, targets, command) {
27674
28057
  try {
27675
28058
  if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
27676
28059
  return NONE5;
27677
- const unresolved = targets.filter((target) => within(path40.resolve(target), UNKNOWN_VAR));
28060
+ const unresolved = targets.filter((target) => within(path42.resolve(target), UNKNOWN_VAR));
27678
28061
  if (unresolved.length > 0)
27679
28062
  return unknownVarDeny(input, boundWorktree(input), unresolved, command);
27680
- if (targets.some((target) => within(path40.resolve(target), UNKNOWN_DIR)))
28063
+ if (targets.some((target) => within(path42.resolve(target), UNKNOWN_DIR)))
27681
28064
  return unknownDirDeny(input, boundWorktree(input));
27682
28065
  const bindings = canonical4(bindingDir());
27683
28066
  const judged = targets.map((named) => ({ named, real: canonical4(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
@@ -27787,16 +28170,16 @@ var RUNS = /^(?:sh|bash|zsh|dash|ksh|mksh|ash|python[\d.]*|node|bun|deno|ruby|pe
27787
28170
  var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print|test|version|help)$|^-[hvV]$/;
27788
28171
  var VALUED = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
27789
28172
  var commonDir = (root) => {
27790
- const dotGit = path40.join(root, ".git");
28173
+ const dotGit = path42.join(root, ".git");
27791
28174
  if (!fs28.statSync(dotGit).isFile())
27792
28175
  return canonical4(dotGit);
27793
- const admin = path40.resolve(root, /^gitdir:\s*(.+)$/mu.exec(fs28.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "");
27794
- const common = path40.join(admin, "commondir");
27795
- return canonical4(fs28.existsSync(common) ? path40.resolve(admin, fs28.readFileSync(common, "utf8").trim()) : admin);
28176
+ const admin = path42.resolve(root, /^gitdir:\s*(.+)$/mu.exec(fs28.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "");
28177
+ const common = path42.join(admin, "commondir");
28178
+ return canonical4(fs28.existsSync(common) ? path42.resolve(admin, fs28.readFileSync(common, "utf8").trim()) : admin);
27796
28179
  };
27797
28180
  var inScratch = (real, repo) => {
27798
28181
  const checkout = checkoutOf2(real);
27799
- return checkout !== null && within(real, path40.join(checkout.root, SCRATCH)) && (repo === null || commonDir(checkout.root) === repo);
28182
+ return checkout !== null && within(real, path42.join(checkout.root, SCRATCH)) && (repo === null || commonDir(checkout.root) === repo);
27800
28183
  };
27801
28184
  var JUDGE_VERBS = {
27802
28185
  check: true,
@@ -27825,7 +28208,7 @@ var judgeVerbRefused = (args) => {
27825
28208
  var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
27826
28209
  var CLI_ENTRY = /(?:^|[=\\/])(?:workit(?:\.(?:exe|cmd|[cm]?js))?|@workit-dev\/cli(?:@\S*)?)$|(?:workit-cli|@workit-dev[\\/]cli)[\\/](?:src[\\/](?:index|main)|dist[\\/]index)\.[cm]?[jt]sx?$/;
27827
28210
  var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
27828
- const name = path40.basename(words[0] ?? "").toLowerCase();
28211
+ const name = path42.basename(words[0] ?? "").toLowerCase();
27829
28212
  if (name === "alias")
27830
28213
  return words.flatMap((word) => {
27831
28214
  const set = /^([\w-]+)=(.*)$/s.exec(word);
@@ -27855,11 +28238,11 @@ var judgeRefusal = (command, fed, depth = 0) => {
27855
28238
  return why;
27856
28239
  }
27857
28240
  const { words } = segment;
27858
- const runs = (word = "") => RUNS.test(path40.basename(word).toLowerCase());
28241
+ const runs = (word = "") => RUNS.test(path42.basename(word).toLowerCase());
27859
28242
  let at = 0;
27860
28243
  while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
27861
28244
  at++;
27862
- const name = path40.basename(words[at] ?? "").toLowerCase();
28245
+ const name = path42.basename(words[at] ?? "").toLowerCase();
27863
28246
  const args = words.slice(at + 1);
27864
28247
  const unseen = `\`${words.join(" ").slice(0, 80)}\` runs a script Workit cannot read (piped, on stdin, a process substitution or eval): write the case to a file in ${SCRATCH} and dispatch it from a test instead`;
27865
28248
  if (/^(?:cd|chdir|pushd|popd)$/.test(name))
@@ -27937,7 +28320,7 @@ var substitutingHeredoc = (command) => {
27937
28320
  var judgeDeny = (input, what) => {
27938
28321
  const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
27939
28322
  const root = checkoutOf2(input.cwd)?.root;
27940
- const scratch = root ? path40.join(root, SCRATCH) : `${SCRATCH}/ at the root of the checkout you judge`;
28323
+ const scratch = root ? path42.join(root, SCRATCH) : `${SCRATCH}/ at the root of the checkout you judge`;
27941
28324
  const unblock = `Write only under ${scratch} (mkdir -p it): put a generated case in a file there with a quoted heredoc (<<'EOF') and never run it in the shell. Reads, \`workit check\` and \`workit ledger verdict|finding\` stay allowed; a change the candidate needs is a finding, not an edit.`;
27942
28325
  return {
27943
28326
  kind: "deny",
@@ -27952,7 +28335,7 @@ function confineJudge(input, targets) {
27952
28335
  const judged = checkoutOf2(input.cwd);
27953
28336
  const repo = judged ? commonDir(judged.root) : null;
27954
28337
  for (const target of targets) {
27955
- const resolved = path40.resolve(target);
28338
+ const resolved = path42.resolve(target);
27956
28339
  if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
27957
28340
  return judgeDeny(input, "it writes to a path Workit cannot resolve (a variable, a command substitution or `cd -`): spell the path out");
27958
28341
  if (inScratch(canonical4(target), repo))
@@ -27983,7 +28366,7 @@ function confineJudgeShell(input, command, dialect = "posix") {
27983
28366
  let git = [];
27984
28367
  try {
27985
28368
  git = rawInvocations(command, dialect).flatMap(({ tool, dir, args }) => tool === "git" && (args[0] === "push" || leadOwnedGit(args)) ? [
27986
- path40.join(dir === undefined ? UNKNOWN_DIR : path40.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
28369
+ path42.join(dir === undefined ? UNKNOWN_DIR : path42.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
27987
28370
  ] : []);
27988
28371
  } catch {}
27989
28372
  return confineJudge(input, [
@@ -28028,7 +28411,7 @@ var judgeChecksLine = (cwd) => {
28028
28411
 
28029
28412
  // packages/workit-core/src/hooks/standing.ts
28030
28413
  var readPlans = (store) => {
28031
- const dir = path41.join(store, "fanouts");
28414
+ const dir = path43.join(store, "fanouts");
28032
28415
  let names;
28033
28416
  try {
28034
28417
  names = fs29.readdirSync(dir).filter((name) => name.endsWith(".json"));
@@ -28038,7 +28421,7 @@ var readPlans = (store) => {
28038
28421
  const plans = [];
28039
28422
  for (const name of names) {
28040
28423
  try {
28041
- const raw = JSON.parse(fs29.readFileSync(path41.join(dir, name), "utf8"));
28424
+ const raw = JSON.parse(fs29.readFileSync(path43.join(dir, name), "utf8"));
28042
28425
  if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
28043
28426
  continue;
28044
28427
  const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
@@ -28238,9 +28621,9 @@ var cdWorkitSplit = (command) => {
28238
28621
  };
28239
28622
 
28240
28623
  // packages/workit-core/src/hooks/model-limit.ts
28241
- import { closeSync as closeSync2, openSync as openSync2, readdirSync as readdirSync4, readSync, statSync as statSync4 } from "node:fs";
28624
+ import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync5, readSync, statSync as statSync4 } from "node:fs";
28242
28625
  import os11 from "node:os";
28243
- import path42 from "node:path";
28626
+ import path44 from "node:path";
28244
28627
  var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
28245
28628
  var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
28246
28629
  var TIME_WORD = String.raw`(?:\d|(?:in|at|on|later|tomorrow|soon)\b|(?:${[...WEEKDAYS, ...MONTHS].join("|")})[a-z]*\b)`;
@@ -28379,21 +28762,21 @@ var TAIL_BYTES2 = 16384;
28379
28762
  var tail = (file, size) => {
28380
28763
  const length = Math.min(size, TAIL_BYTES2);
28381
28764
  const buffer = Buffer.alloc(length);
28382
- const fd = openSync2(file, "r");
28765
+ const fd = openSync3(file, "r");
28383
28766
  try {
28384
28767
  readSync(fd, buffer, 0, length, size - length);
28385
28768
  } finally {
28386
- closeSync2(fd);
28769
+ closeSync3(fd);
28387
28770
  }
28388
28771
  return buffer.toString("utf8");
28389
28772
  };
28390
28773
  var start = (file) => {
28391
28774
  const buffer = Buffer.alloc(TAIL_BYTES2);
28392
- const fd = openSync2(file, "r");
28775
+ const fd = openSync3(file, "r");
28393
28776
  try {
28394
28777
  return buffer.subarray(0, readSync(fd, buffer, 0, TAIL_BYTES2, 0)).toString("utf8");
28395
28778
  } finally {
28396
- closeSync2(fd);
28779
+ closeSync3(fd);
28397
28780
  }
28398
28781
  };
28399
28782
  var parse5 = (line) => {
@@ -28438,17 +28821,17 @@ var firstPrompt = (file) => {
28438
28821
  var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
28439
28822
  var listDir = (dir) => {
28440
28823
  try {
28441
- return readdirSync4(dir).map((name) => path42.join(dir, name));
28824
+ return readdirSync5(dir).map((name) => path44.join(dir, name));
28442
28825
  } catch {
28443
28826
  return [];
28444
28827
  }
28445
28828
  };
28446
28829
  var SCAN_MS = 30 * 60000;
28447
28830
  var scanClaudeTranscripts = (cwd, env, now = new Date) => {
28448
- const projects = path42.join(env.CLAUDE_CONFIG_DIR || path42.join(env.HOME || os11.homedir(), ".claude"), "projects");
28449
- const project = path42.join(projects, claudeProjectSlug(cwd));
28831
+ const projects = path44.join(env.CLAUDE_CONFIG_DIR || path44.join(env.HOME || os11.homedir(), ".claude"), "projects");
28832
+ const project = path44.join(projects, claudeProjectSlug(cwd));
28450
28833
  const notes = [];
28451
- const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path42.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
28834
+ const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path44.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
28452
28835
  for (const { file, worker } of files)
28453
28836
  try {
28454
28837
  const stat = statSync4(file);
@@ -28463,7 +28846,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
28463
28846
  if (!seen)
28464
28847
  continue;
28465
28848
  notes.push(worker ? redispatchNote(seen, {
28466
- label: `worker ${path42.basename(file, ".jsonl")}`,
28849
+ label: `worker ${path44.basename(file, ".jsonl")}`,
28467
28850
  prompt: firstPrompt(file)
28468
28851
  }, now) : `Workit: this session hit a usage limit (${seen.reason}); ${seen.key} is marked exhausted until ${shortTime(seen.until)}. Claude Code runs only Anthropic models: Workit cannot switch this session, so continue on another host or after the reset.`);
28469
28852
  } catch {}
@@ -28600,7 +28983,11 @@ var usageLimitOnStop = (input, agentId, text) => {
28600
28983
  return;
28601
28984
  if (!firstSighting(`subagent-stop:${input.session.id}:${agentId ?? ""}`))
28602
28985
  return;
28603
- recordUsageLimit(text, { cwd: input.cwd, host: input.host, model: input.model ?? null });
28986
+ recordUsageLimit(text, {
28987
+ cwd: input.cwd,
28988
+ host: input.host,
28989
+ model: input.model ?? null
28990
+ });
28604
28991
  } catch {}
28605
28992
  };
28606
28993
  var subagentSession = (session, agentId) => [session, agentId].filter((part) => Boolean(part)).join(":").replace(/[^A-Za-z0-9_.:@/+-]/g, "-").slice(0, 128);
@@ -28696,9 +29083,6 @@ function decide(input, deps) {
28696
29083
  const postTool = usable2(descriptor.events["shell.post"].support);
28697
29084
  if (!postTool)
28698
29085
  settlePendingCommit(input);
28699
- const raw = canDeny ? rawGitPre(input, event.command, { nudge: false }) : NONE6;
28700
- if (raw.kind === "deny")
28701
- return raw;
28702
29086
  const userOnly = userOnlyWorkitCall(event.command, event.dialect);
28703
29087
  if (userOnly) {
28704
29088
  if (input.host === "claude_code")
@@ -28719,6 +29103,9 @@ function decide(input, deps) {
28719
29103
  if (confined.kind === "deny")
28720
29104
  return confined;
28721
29105
  }
29106
+ const raw = canDeny ? rawGitPre(input, event.command, { nudge: false }) : NONE6;
29107
+ if (raw.kind === "deny")
29108
+ return raw;
28722
29109
  const owner = role === "judge" ? null : liveOwner(input, descriptor.transport);
28723
29110
  const gate = usable2(descriptor.events["write.pre"].support) ? shellGate(input.cwd, event.command, owner, event.dialect) : NONE6;
28724
29111
  if (gate.kind === "deny")
@@ -28781,7 +29168,11 @@ function decide(input, deps) {
28781
29168
  trackJudge(input, event.agentId, true);
28782
29169
  seedStanding({
28783
29170
  ...input,
28784
- session: { ...input.session, agentId: event.agentId, agentType: event.agentType }
29171
+ session: {
29172
+ ...input.session,
29173
+ agentId: event.agentId,
29174
+ agentType: event.agentType
29175
+ }
28785
29176
  });
28786
29177
  deps.budget?.start(input, event.agentId, event.agentType);
28787
29178
  return {
@@ -28841,12 +29232,12 @@ var modelKey = (model) => {
28841
29232
  };
28842
29233
 
28843
29234
  // packages/workit-core/src/hooks/budget-signal.ts
28844
- import { createHash as createHash19 } from "node:crypto";
29235
+ import { createHash as createHash20 } from "node:crypto";
28845
29236
  import fs30 from "node:fs";
28846
- import path43 from "node:path";
28847
- var hash2 = (text) => createHash19("sha256").update(text).digest("hex").slice(0, 32);
28848
- var budgetDir = (store) => path43.join(store, "budget");
28849
- var agentBase = (store, session, agentId) => path43.join(budgetDir(store), hash2(`${session}\x00${agentId ?? ""}`));
29237
+ import path45 from "node:path";
29238
+ var hash2 = (text) => createHash20("sha256").update(text).digest("hex").slice(0, 32);
29239
+ var budgetDir = (store) => path45.join(store, "budget");
29240
+ var agentBase = (store, session, agentId) => path45.join(budgetDir(store), hash2(`${session}\x00${agentId ?? ""}`));
28850
29241
  var spawnBudget = (prompt) => {
28851
29242
  const found = /^TIMEBOX:[^\n]*?\b(\d+)\s+tool calls\b/mu.exec(prompt);
28852
29243
  const n = found ? Number(found[1]) : NaN;
@@ -28866,8 +29257,8 @@ var startBudget = (store, session, agentId, n) => {
28866
29257
  const cutoff = Date.now() - 604800000;
28867
29258
  for (const name of fs30.readdirSync(dir))
28868
29259
  try {
28869
- if (fs30.statSync(path43.join(dir, name)).mtimeMs < cutoff)
28870
- fs30.rmSync(path43.join(dir, name));
29260
+ if (fs30.statSync(path45.join(dir, name)).mtimeMs < cutoff)
29261
+ fs30.rmSync(path45.join(dir, name));
28871
29262
  } catch {}
28872
29263
  const base = agentBase(store, session, agentId);
28873
29264
  fs30.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
@@ -29006,11 +29397,11 @@ var unfinishedTaskOffer2 = (ctx) => {
29006
29397
  };
29007
29398
 
29008
29399
  // packages/workit-core/src/hooks/repeat-failure.ts
29009
- import { createHash as createHash20 } from "node:crypto";
29400
+ import { createHash as createHash21 } from "node:crypto";
29010
29401
  var SAME_CALL_FAILED = "Same call failed twice:";
29011
29402
  var MAX_SESSIONS = 256;
29012
29403
  var stable = (value) => JSON.stringify(value, (_key, entry) => entry && typeof entry === "object" && !Array.isArray(entry) ? Object.fromEntries(Object.entries(entry).toSorted(([a], [b]) => a.localeCompare(b))) : entry) ?? "null";
29013
- var hashOf = (call) => createHash20("sha256").update(call).digest("hex").slice(0, 32);
29404
+ var hashOf = (call) => createHash21("sha256").update(call).digest("hex").slice(0, 32);
29014
29405
  var record2 = (memo, sessionId, call, failed, next) => {
29015
29406
  const previous = memo.get(sessionId);
29016
29407
  memo.delete(sessionId);
@@ -29141,6 +29532,68 @@ var hookInput = (ctx, event) => ({
29141
29532
  transcriptPath: null,
29142
29533
  event
29143
29534
  });
29535
+ var APPROVE = "Approve once";
29536
+ var REJECT = "Reject";
29537
+ var EDIT = "Edit";
29538
+ var approveInDialog = async (ids, event, ctx) => {
29539
+ try {
29540
+ const session = hookInput(ctx, { kind: "context.turn" }).session.id || null;
29541
+ const found = ids.map((id) => liveApprovalRequest(id));
29542
+ const shown = found.map((item) => item.ok ? renderApprovalRequest(item.request) : item.reason);
29543
+ const live = found.flatMap((item) => item.ok ? [item.request.id] : []);
29544
+ if (live.length === 0)
29545
+ return { block: true, reason: `Nothing to approve: ${shown.join("; ")}` };
29546
+ const choice = await ctx.ui.select(`Workit asks you to approve:
29547
+ ${shown.join(`
29548
+ `)}`, [
29549
+ APPROVE,
29550
+ REJECT,
29551
+ EDIT
29552
+ ]);
29553
+ if (choice === APPROVE) {
29554
+ const toolUseId = event.toolCallId ?? `pi-${Date.now()}`;
29555
+ recordApprovalAsked({
29556
+ toolUseId,
29557
+ session: session ?? "",
29558
+ host: "pi",
29559
+ ids: live
29560
+ });
29561
+ const recorded = live.filter((id) => recordApprovalGrant({
29562
+ id,
29563
+ host: "pi",
29564
+ session: session ?? "",
29565
+ toolUseId,
29566
+ via: "host"
29567
+ }).ok);
29568
+ return {
29569
+ block: true,
29570
+ reason: `The user approved ${recorded.join(" ")} in Pi's dialog: recorded, one use each, for 15 minutes. Run the refused verb again; do not run workit approve again.`
29571
+ };
29572
+ }
29573
+ if (choice === REJECT || choice === EDIT) {
29574
+ for (const id of live)
29575
+ recordApprovalRejected({
29576
+ id,
29577
+ host: "pi",
29578
+ session,
29579
+ edit: choice === EDIT
29580
+ });
29581
+ return {
29582
+ block: true,
29583
+ reason: choice === EDIT ? `The user chose Edit for ${live.join(" ")}: change what the request names, then run the verb again; it writes a new request.` : `The user rejected ${live.join(" ")}. Do not retry it; report that the action was not approved.`
29584
+ };
29585
+ }
29586
+ return {
29587
+ block: true,
29588
+ reason: `The user dismissed the approval dialog for ${live.join(" ")}: nothing was recorded.`
29589
+ };
29590
+ } catch (error) {
29591
+ return {
29592
+ block: true,
29593
+ reason: `Workit could not record the approval: ${String(error)}`
29594
+ };
29595
+ }
29596
+ };
29144
29597
  var enforceToolPolicy = (event, ctx) => {
29145
29598
  const gate = (hookEvent) => {
29146
29599
  const decision = handleHook(hookInput(ctx, hookEvent), {
@@ -29153,7 +29606,16 @@ var enforceToolPolicy = (event, ctx) => {
29153
29606
  };
29154
29607
  if (event.toolName === "bash") {
29155
29608
  const command = event.input?.command;
29156
- return typeof command === "string" ? gate({ kind: "shell.pre", command, toolUseId: event.toolCallId ?? null }) : undefined;
29609
+ const approve = typeof command === "string" ? approveCallIn(command) : null;
29610
+ if (approve && !approve.plain)
29611
+ return { block: true, reason: approveCallDeny(approve.fix) };
29612
+ if (approve?.plain && ctx.mode === "tui" && ctx.hasUI)
29613
+ return approveInDialog(approve.ids, event, ctx);
29614
+ return typeof command === "string" ? gate({
29615
+ kind: "shell.pre",
29616
+ command,
29617
+ toolUseId: event.toolCallId ?? null
29618
+ }) : undefined;
29157
29619
  }
29158
29620
  if (event.toolName === "read") {
29159
29621
  const file = event.input?.path;
@@ -29198,9 +29660,11 @@ var observeToolResult = (event, ctx) => {
29198
29660
  const role = named === "implementer" ? "implementer" : named ? "judge" : null;
29199
29661
  const nudge = process.env.WORKIT_PI_WORKER_SESSION ? rawGitPre(post, command, { nudge: roleSteering(role, false).nudges }) : shellNudge(post, command);
29200
29662
  const extra = [nudge.kind === "context" ? nudge.text : null, repeated].filter((text) => text !== null);
29201
- return extra.length > 0 ? { content: [...event.content, { type: "text", text: extra.join(`
29663
+ return extra.length > 0 ? {
29664
+ content: [...event.content, { type: "text", text: extra.join(`
29202
29665
 
29203
- `) }] } : undefined;
29666
+ `) }]
29667
+ } : undefined;
29204
29668
  } catch {
29205
29669
  return;
29206
29670
  }
@@ -29208,21 +29672,21 @@ var observeToolResult = (event, ctx) => {
29208
29672
  var skillPromptNudge = (prompt, ctx) => process.env.WORKIT_PI_WORKER_SESSION ? null : promptNudge(hookInput(ctx, { kind: "context.turn", prompt }), prompt);
29209
29673
 
29210
29674
  // packages/workit-pi/src/launches.ts
29211
- import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, readdirSync as readdirSync5, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "node:fs";
29675
+ import { mkdirSync as mkdirSync6, readFileSync as readFileSync10, readdirSync as readdirSync6, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "node:fs";
29212
29676
  import os12 from "node:os";
29213
- import path44 from "node:path";
29677
+ import path46 from "node:path";
29214
29678
  var launchDir = (root) => {
29215
29679
  const location = resolveStore(root);
29216
- return location instanceof Error ? null : path44.join(location.dir, "pi-launches");
29680
+ return location instanceof Error ? null : path46.join(location.dir, "pi-launches");
29217
29681
  };
29218
- var fileFor = (dir, workerId) => path44.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
29682
+ var fileFor = (dir, workerId) => path46.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
29219
29683
  var recordLaunch = (root, attempt) => {
29220
29684
  const dir = launchDir(root);
29221
29685
  if (!dir)
29222
29686
  return false;
29223
29687
  try {
29224
- mkdirSync4(dir, { recursive: true });
29225
- writeFileSync4(fileFor(dir, attempt.workerId), JSON.stringify({
29688
+ mkdirSync6(dir, { recursive: true });
29689
+ writeFileSync5(fileFor(dir, attempt.workerId), JSON.stringify({
29226
29690
  ...attempt,
29227
29691
  pid: process.pid,
29228
29692
  host: os12.hostname(),
@@ -29254,14 +29718,14 @@ var abandonedLaunches = (root) => {
29254
29718
  return [];
29255
29719
  let names;
29256
29720
  try {
29257
- names = readdirSync5(dir);
29721
+ names = readdirSync6(dir);
29258
29722
  } catch {
29259
29723
  return [];
29260
29724
  }
29261
29725
  const found = [];
29262
29726
  for (const name of names) {
29263
29727
  try {
29264
- const attempt = JSON.parse(readFileSync9(path44.join(dir, name), "utf8"));
29728
+ const attempt = JSON.parse(readFileSync10(path46.join(dir, name), "utf8"));
29265
29729
  if (typeof attempt.workerId === "string" && typeof attempt.session === "string") {
29266
29730
  if (!alive(attempt))
29267
29731
  found.push(attempt);
@@ -29273,22 +29737,22 @@ var abandonedLaunches = (root) => {
29273
29737
  var cancelHint = (workerId) => `cancel it first: workit_worker {"action":"cancel","workerId":"${workerId}","reason":"launch outcome unknown"} (CLI: workit worker cancel --payload '{"workerId":"${workerId}","reason":"launch outcome unknown"}')`;
29274
29738
 
29275
29739
  // packages/workit-core/src/core/cli-locate.ts
29276
- import { closeSync as closeSync3, existsSync as existsSync13, openSync as openSync3, readSync as readSync2 } from "node:fs";
29277
- import path45 from "node:path";
29740
+ import { closeSync as closeSync4, existsSync as existsSync13, openSync as openSync4, readSync as readSync2 } from "node:fs";
29741
+ import path47 from "node:path";
29278
29742
  var LAUNCHER_MARKER = "workit-owned-launcher";
29279
29743
  var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
29280
29744
  var installRoot = (env, platform = process.platform) => {
29281
29745
  if (env.WORKIT_INSTALL_ROOT)
29282
29746
  return env.WORKIT_INSTALL_ROOT;
29283
29747
  const data = dataDir(env, platform);
29284
- return platform === "win32" ? path45.join(data, "install") : data;
29748
+ return platform === "win32" ? path47.join(data, "install") : data;
29285
29749
  };
29286
- var ownedLauncherPath = (env, platform = process.platform) => path45.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
29287
- var ownedCurrentEntry = (env, platform = process.platform) => path45.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
29750
+ var ownedLauncherPath = (env, platform = process.platform) => path47.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
29751
+ var ownedCurrentEntry = (env, platform = process.platform) => path47.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
29288
29752
  var head = (file) => {
29289
29753
  let fd;
29290
29754
  try {
29291
- fd = openSync3(file, "r");
29755
+ fd = openSync4(file, "r");
29292
29756
  const buffer = Buffer.alloc(256);
29293
29757
  const read = readSync2(fd, buffer, 0, buffer.length, 0);
29294
29758
  return buffer.subarray(0, read).toString("utf8");
@@ -29296,7 +29760,7 @@ var head = (file) => {
29296
29760
  return "";
29297
29761
  } finally {
29298
29762
  if (fd !== undefined)
29299
- closeSync3(fd);
29763
+ closeSync4(fd);
29300
29764
  }
29301
29765
  };
29302
29766
  var locateWorkitCli = (options = {}) => {
@@ -29311,7 +29775,7 @@ var locateWorkitCli = (options = {}) => {
29311
29775
  source: "owned-launcher",
29312
29776
  command: launcher,
29313
29777
  args: [],
29314
- binDir: path45.dirname(launcher)
29778
+ binDir: path47.dirname(launcher)
29315
29779
  };
29316
29780
  const current = ownedCurrentEntry(env, platform);
29317
29781
  if (exists(current))
@@ -29340,7 +29804,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
29340
29804
  if (located.binDir) {
29341
29805
  const key = pathKey(env);
29342
29806
  const delimiter = platform === "win32" ? ";" : ":";
29343
- const same = (dir) => platform === "win32" ? path45.win32.normalize(dir).toLowerCase() === path45.win32.normalize(located.binDir).toLowerCase() : path45.posix.normalize(dir) === path45.posix.normalize(located.binDir);
29807
+ const same = (dir) => platform === "win32" ? path47.win32.normalize(dir).toLowerCase() === path47.win32.normalize(located.binDir).toLowerCase() : path47.posix.normalize(dir) === path47.posix.normalize(located.binDir);
29344
29808
  const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
29345
29809
  patch[key] = [located.binDir, ...rest].join(delimiter);
29346
29810
  }
@@ -29358,7 +29822,7 @@ var useOwnedCliInPi = (env = process.env) => useOwnedWorkitCli({ env });
29358
29822
 
29359
29823
  // packages/workit-pi/src/worker.ts
29360
29824
  import { spawn as nodeSpawn } from "node:child_process";
29361
- import { randomUUID as randomUUID4 } from "node:crypto";
29825
+ import { randomUUID as randomUUID5 } from "node:crypto";
29362
29826
 
29363
29827
  // packages/workit-pi/src/worker-protocol.ts
29364
29828
  var MAX_WORKER_LINE_BYTES = 64 * 1024;
@@ -29486,10 +29950,10 @@ function launchWorker(assignment, options) {
29486
29950
  const nested = Boolean(process.env.WORKIT_PI_WORKER_ID || options.env?.WORKIT_PI_WORKER_ID);
29487
29951
  const taskId = options.taskId ?? null;
29488
29952
  const workerId = options.workerId ?? null;
29489
- const sessionId = options.sessionId ?? "pi-worker-" + randomUUID4();
29953
+ const sessionId = options.sessionId ?? "pi-worker-" + randomUUID5();
29490
29954
  const spec = workerCommand2({ ...options.runtime, sessionId }, assignment);
29491
29955
  const handle = {
29492
- id: randomUUID4(),
29956
+ id: randomUUID5(),
29493
29957
  taskId,
29494
29958
  workerId,
29495
29959
  sessionId,
@@ -30067,7 +30531,7 @@ function extension(pi) {
30067
30531
  workerId: worker.id,
30068
30532
  expectedRevision: task.revision,
30069
30533
  expectedWorkspaceRevision: workspace.revision,
30070
- sessionId: `pi-worker-${worker.id}-${randomUUID5().slice(0, 8)}`
30534
+ sessionId: `pi-worker-${worker.id}-${randomUUID6().slice(0, 8)}`
30071
30535
  };
30072
30536
  const childContext = {
30073
30537
  ...piContext(ctx),