@workit-dev/pi 1.5.1 → 1.6.0

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,7 @@ 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: { dir: path27.resolve(cwd, invocation.dir ?? "."), branch: null },
20523
20590
  workit: false
20524
20591
  } : null);
20525
20592
  if (action && at)
@@ -20656,9 +20723,9 @@ var grantRefusal = (action, repo, invocation, cache) => {
20656
20723
  return null;
20657
20724
  };
20658
20725
  var localTag = (repo, name) => {
20659
- const common = path26.dirname(repo.location.dir);
20726
+ const common = path27.dirname(repo.location.dir);
20660
20727
  try {
20661
- return fs18.existsSync(path26.join(common, "refs/tags", name)) || fs18.readFileSync(path26.join(common, "packed-refs"), "utf8").includes(` refs/tags/${name}
20728
+ return fs18.existsSync(path27.join(common, "refs/tags", name)) || fs18.readFileSync(path27.join(common, "packed-refs"), "utf8").includes(` refs/tags/${name}
20662
20729
  `);
20663
20730
  } catch {
20664
20731
  return false;
@@ -20678,7 +20745,7 @@ var analysisDenial = (error) => ({
20678
20745
  });
20679
20746
  var NEXT_COMMAND = "next";
20680
20747
  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`);
20748
+ 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
20749
  var callKey = (toolUseId, command) => toolUseId ?? `cmd:${createHash15("sha256").update(command).digest("hex")}`;
20683
20750
  function noteRawCommit(input, command, key) {
20684
20751
  try {
@@ -20689,7 +20756,7 @@ function noteRawCommit(input, command, key) {
20689
20756
  if (action.kind !== "commit")
20690
20757
  continue;
20691
20758
  const file = markerFile(repo, input.session.id, key);
20692
- fs18.mkdirSync(path26.dirname(file), { recursive: true });
20759
+ fs18.mkdirSync(path27.dirname(file), { recursive: true });
20693
20760
  fs18.writeFileSync(file, `${JSON.stringify({ head: headSha2(repo), at })}
20694
20761
  `);
20695
20762
  }
@@ -20930,7 +20997,7 @@ var judgedDir = (root, dir) => {
20930
20997
  return null;
20931
20998
  if (dir === null)
20932
20999
  return root;
20933
- const resolved = path27.resolve(root, dir);
21000
+ const resolved = path28.resolve(root, dir);
20934
21001
  return existsSync9(resolved) && inWorkitWorkspace(resolved) ? resolved : null;
20935
21002
  };
20936
21003
  var shellBranchPolicyViolation = (root, command, dialect = "posix") => {
@@ -22928,7 +22995,7 @@ class WorkitCore {
22928
22995
  // packages/workit-core/src/core/repo-context.ts
22929
22996
  import { spawnSync as spawnSync17 } from "node:child_process";
22930
22997
  import { existsSync as existsSync10, readFileSync as readFileSync8, readdirSync as readdirSync3 } from "node:fs";
22931
- import path28 from "node:path";
22998
+ import path29 from "node:path";
22932
22999
  var isSafeContextRange = (value) => value.length <= 4096 && (() => {
22933
23000
  try {
22934
23001
  gitRevisionParts(value);
@@ -23072,13 +23139,13 @@ var findPrTemplate = (cwd) => {
23072
23139
  for (const rel of PR_TEMPLATE_FILES) {
23073
23140
  const parts = rel.split("/");
23074
23141
  const base = parts[parts.length - 1];
23075
- const dir = parts.length > 1 ? path28.join(cwd, ...parts.slice(0, -1)) : cwd;
23142
+ const dir = parts.length > 1 ? path29.join(cwd, ...parts.slice(0, -1)) : cwd;
23076
23143
  const actual = probeCaseInsensitive(dir, base);
23077
23144
  if (actual)
23078
23145
  return [...parts.slice(0, -1), actual].join("/");
23079
23146
  }
23080
23147
  for (const rel of PR_TEMPLATE_DIRS) {
23081
- const only = singleMarkdown(path28.join(cwd, ...rel.split("/")));
23148
+ const only = singleMarkdown(path29.join(cwd, ...rel.split("/")));
23082
23149
  if (only)
23083
23150
  return `${rel}/${only}`;
23084
23151
  }
@@ -23108,7 +23175,7 @@ var diffStatForRange = (cwd, range) => {
23108
23175
  return runGit(cwd, ["diff", "--stat", "--"]).stdout;
23109
23176
  };
23110
23177
  var packageScripts = (cwd, keys) => {
23111
- const pkgPath = path28.join(cwd, "package.json");
23178
+ const pkgPath = path29.join(cwd, "package.json");
23112
23179
  if (!existsSync10(pkgPath))
23113
23180
  return [];
23114
23181
  try {
@@ -23134,9 +23201,9 @@ var documentationFiles = (cwd) => {
23134
23201
  if (entry.isDirectory()) {
23135
23202
  if (excluded.has(entry.name))
23136
23203
  continue;
23137
- walk(path28.join(dir, entry.name), depth + 1);
23204
+ walk(path29.join(dir, entry.name), depth + 1);
23138
23205
  } else if (entry.isFile() && (entry.name === "README.md" || entry.name.endsWith(".md"))) {
23139
- matches.push("./" + path28.relative(cwd, path28.join(dir, entry.name)).replaceAll("\\", "/"));
23206
+ matches.push("./" + path29.relative(cwd, path29.join(dir, entry.name)).replaceAll("\\", "/"));
23140
23207
  }
23141
23208
  }
23142
23209
  };
@@ -23152,7 +23219,7 @@ var readTrimmed2 = (file, maxLines) => {
23152
23219
  `);
23153
23220
  };
23154
23221
  function prReadyContext(root, range) {
23155
- const cwd = path28.resolve(repoRoot(root));
23222
+ const cwd = path29.resolve(repoRoot(root));
23156
23223
  if (range !== undefined && !isResolvableContextRange(cwd, range))
23157
23224
  return invalidRange(cwd);
23158
23225
  let stdout = "";
@@ -23210,7 +23277,7 @@ ${status.stderr}` : "");
23210
23277
  stdout += `template_path: ${template}
23211
23278
 
23212
23279
  `;
23213
- stdout += readTrimmed2(path28.join(cwd, template), 220);
23280
+ stdout += readTrimmed2(path29.join(cwd, template), 220);
23214
23281
  } else {
23215
23282
  stdout += `template_path: none
23216
23283
 
@@ -23220,7 +23287,7 @@ ${status.stderr}` : "");
23220
23287
  stdout += `
23221
23288
  `;
23222
23289
  stdout += printSection("Recent Validation Signals");
23223
- if (existsSync10(path28.join(cwd, "package.json"))) {
23290
+ if (existsSync10(path29.join(cwd, "package.json"))) {
23224
23291
  stdout += `package.json detected. Common scripts:
23225
23292
  `;
23226
23293
  const found = packageScripts(cwd, ["lint", "format:check", "test", "build"]);
@@ -23229,7 +23296,7 @@ ${status.stderr}` : "");
23229
23296
  `) + `
23230
23297
  `;
23231
23298
  }
23232
- if (existsSync10(path28.join(cwd, "Cargo.toml")) || existsSync10(path28.join(cwd, "src-tauri/Cargo.toml"))) {
23299
+ if (existsSync10(path29.join(cwd, "Cargo.toml")) || existsSync10(path29.join(cwd, "src-tauri/Cargo.toml"))) {
23233
23300
  stdout += `Rust project detected.
23234
23301
  `;
23235
23302
  }
@@ -23262,7 +23329,7 @@ var CHANGELOG_RULES = `- Use an [Unreleased] section.
23262
23329
  - Apply with the host-native editor, preserving the repository changelog conventions.
23263
23330
  - If Unreleased already has duplicate category headings, normalize_only first.`;
23264
23331
  function changelogContext(root, range) {
23265
- const cwd = path28.resolve(repoRoot(root));
23332
+ const cwd = path29.resolve(repoRoot(root));
23266
23333
  if (range !== undefined && !isResolvableContextRange(cwd, range))
23267
23334
  return invalidRange(cwd);
23268
23335
  const resolvedRange = rangeArgOrDefault(range, cwd);
@@ -23280,7 +23347,7 @@ function changelogContext(root, range) {
23280
23347
  stdout += CHANGELOG_RULES + `
23281
23348
  `;
23282
23349
  stdout += printSection("Existing CHANGELOG.md");
23283
- const changelogPath = path28.join(cwd, "CHANGELOG.md");
23350
+ const changelogPath = path29.join(cwd, "CHANGELOG.md");
23284
23351
  if (existsSync10(changelogPath)) {
23285
23352
  stdout += readTrimmed2(changelogPath, 260) + `
23286
23353
  `;
@@ -23300,7 +23367,7 @@ function changelogContext(root, range) {
23300
23367
  return { stdout, stderr: "", exitCode: 0, cwd };
23301
23368
  }
23302
23369
  function docsRefreshContext(root, range) {
23303
- const cwd = path28.resolve(repoRoot(root));
23370
+ const cwd = path29.resolve(repoRoot(root));
23304
23371
  if (range !== undefined && !isResolvableContextRange(cwd, range))
23305
23372
  return invalidRange(cwd);
23306
23373
  const resolvedRange = rangeArgOrDefault(range, cwd);
@@ -23322,7 +23389,7 @@ function docsRefreshContext(root, range) {
23322
23389
  `) + `
23323
23390
  `;
23324
23391
  stdout += printSection("README Preview");
23325
- const readme = path28.join(cwd, "README.md");
23392
+ const readme = path29.join(cwd, "README.md");
23326
23393
  if (existsSync10(readme)) {
23327
23394
  stdout += readTrimmed2(readme, 220) + `
23328
23395
  `;
@@ -23331,7 +23398,7 @@ function docsRefreshContext(root, range) {
23331
23398
  `;
23332
23399
  }
23333
23400
  stdout += printSection("Package Scripts");
23334
- const pkgPath = path28.join(cwd, "package.json");
23401
+ const pkgPath = path29.join(cwd, "package.json");
23335
23402
  if (existsSync10(pkgPath)) {
23336
23403
  try {
23337
23404
  const pkg = JSON.parse(readFileSync8(pkgPath, "utf8"));
@@ -23345,7 +23412,7 @@ function docsRefreshContext(root, range) {
23345
23412
  return { stdout, stderr: "", exitCode: 0, cwd };
23346
23413
  }
23347
23414
  function releaseNotesContext(root, rangeOrTag) {
23348
- const cwd = path28.resolve(repoRoot(root));
23415
+ const cwd = path29.resolve(repoRoot(root));
23349
23416
  if (!rangeOrTag) {
23350
23417
  return {
23351
23418
  stdout: "",
@@ -23388,7 +23455,7 @@ function releaseNotesContext(root, rangeOrTag) {
23388
23455
  `;
23389
23456
  stdout += printSection("Existing Release Files");
23390
23457
  for (const rel of ["CHANGELOG.md", "RELEASE_NOTES.md", ".github/releases.md"]) {
23391
- if (existsSync10(path28.join(cwd, rel)))
23458
+ if (existsSync10(path29.join(cwd, rel)))
23392
23459
  stdout += rel + `
23393
23460
  `;
23394
23461
  }
@@ -23420,7 +23487,7 @@ import { spawnSync as spawnSync19 } from "node:child_process";
23420
23487
 
23421
23488
  // packages/workit-core/src/core/pr-create.ts
23422
23489
  import fs19 from "node:fs";
23423
- import path29 from "node:path";
23490
+ import path30 from "node:path";
23424
23491
  import { spawnSync as spawnSync18 } from "node:child_process";
23425
23492
  // packages/workit-core/src/forge/pr-body.ts
23426
23493
  function parseGhIssue(value) {
@@ -23440,11 +23507,11 @@ var LOCAL = bounded(20000);
23440
23507
  var NETWORK = bounded(60000);
23441
23508
  function whichOnPath(tool) {
23442
23509
  const names = process.platform === "win32" ? [tool, `${tool}.exe`, `${tool}.cmd`] : [tool];
23443
- for (const dir of (process.env.PATH ?? "").split(path29.delimiter)) {
23510
+ for (const dir of (process.env.PATH ?? "").split(path30.delimiter)) {
23444
23511
  if (!dir)
23445
23512
  continue;
23446
23513
  for (const name of names) {
23447
- const candidate = path29.join(dir, name);
23514
+ const candidate = path30.join(dir, name);
23448
23515
  try {
23449
23516
  fs19.accessSync(candidate, fs19.constants.X_OK);
23450
23517
  return candidate;
@@ -23565,7 +23632,7 @@ var fetchGitLabIssueBody = async (ref, root, deps = {}) => {
23565
23632
 
23566
23633
  // packages/workit-core/src/core/youtrack.ts
23567
23634
  import fs21 from "node:fs";
23568
- import path31 from "node:path";
23635
+ import path32 from "node:path";
23569
23636
 
23570
23637
  // packages/workit-core/src/core/templates.ts
23571
23638
  var repoRoot2 = assetRoot();
@@ -23580,7 +23647,7 @@ import { spawnSync as spawnSync20 } from "node:child_process";
23580
23647
 
23581
23648
  // packages/workit-core/src/forge/exec.ts
23582
23649
  import fs20 from "node:fs";
23583
- import path30 from "node:path";
23650
+ import path31 from "node:path";
23584
23651
 
23585
23652
  // packages/workit-core/src/forge/redact.ts
23586
23653
  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 +23658,11 @@ var ANSI = new RegExp(String.raw`\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007]*\
23591
23658
  // packages/workit-core/src/forge/exec.ts
23592
23659
  var MAX_BUFFER2 = 64 * 1024 * 1024;
23593
23660
  function findExecutable(bin, env) {
23594
- const dirs = (env.PATH ?? env.Path ?? "").split(path30.delimiter).filter(Boolean);
23661
+ const dirs = (env.PATH ?? env.Path ?? "").split(path31.delimiter).filter(Boolean);
23595
23662
  const exts = process.platform === "win32" ? [".exe"] : [""];
23596
23663
  for (const dir of dirs)
23597
23664
  for (const ext of exts) {
23598
- const candidate = path30.join(dir, `${bin}${ext}`);
23665
+ const candidate = path31.join(dir, `${bin}${ext}`);
23599
23666
  try {
23600
23667
  const stat = fs20.statSync(candidate);
23601
23668
  if (stat.isFile())
@@ -23638,7 +23705,7 @@ var YTRACK_MISSING = "ytrack is not on PATH: Workit reaches YouTrack only throug
23638
23705
 
23639
23706
  // packages/workit-core/src/core/youtrack.ts
23640
23707
  var ISSUE_RE = /^[A-Z]+-\d+$/;
23641
- var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ?? path31.join(resolveConfigDir(), "youtrack.json");
23708
+ var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ?? path32.join(resolveConfigDir(), "youtrack.json");
23642
23709
  var readYouTrackContextConfig = () => {
23643
23710
  const cfgPath = youTrackReadOnlyConfigPath();
23644
23711
  if (!fs21.existsSync(cfgPath))
@@ -24006,15 +24073,15 @@ function resolveGitRevision(root, value) {
24006
24073
  }
24007
24074
  function resolveInside(root, candidate) {
24008
24075
  const base = realpathSync8(root);
24009
- const target = path32.resolve(base, candidate);
24010
- if (target !== base && !target.startsWith(base + path32.sep)) {
24076
+ const target = path33.resolve(base, candidate);
24077
+ if (target !== base && !target.startsWith(base + path33.sep)) {
24011
24078
  throw new Error("path must stay inside repository root");
24012
24079
  }
24013
24080
  let ancestor = target;
24014
24081
  while (!existsSync11(ancestor))
24015
- ancestor = path32.dirname(ancestor);
24082
+ ancestor = path33.dirname(ancestor);
24016
24083
  const canonicalAncestor = realpathSync8(ancestor);
24017
- if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base + path32.sep)) {
24084
+ if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base + path33.sep)) {
24018
24085
  throw new Error("path must stay inside repository root");
24019
24086
  }
24020
24087
  return target;
@@ -24060,7 +24127,7 @@ var capabilitiesFor = (descriptor, observed = {}) => descriptor.capabilities.map
24060
24127
  // packages/workit-core/src/hooks/context.ts
24061
24128
  import { createHash as createHash16 } from "node:crypto";
24062
24129
  import fs22 from "node:fs";
24063
- import path33 from "node:path";
24130
+ import path34 from "node:path";
24064
24131
  var MIGRATION_PENDING_NOTE = "workit migration pending — run `workit task status`";
24065
24132
  var migrationPending = (result) => !result.ok && result.code === "needs_input" && (result.error ?? "").startsWith(MIGRATION_PENDING);
24066
24133
  var boundTo = (entry, session) => entry.sessions.some((item) => item.host === session.host && item.handle === session.handle);
@@ -24148,7 +24215,7 @@ function entryCompactContext(store, entry, session, context) {
24148
24215
  current: () => recentSignal(store.root)
24149
24216
  };
24150
24217
  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)] : []));
24218
+ const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [path34.resolve(store.root, ref.path)] : []));
24152
24219
  const observedFiles = filesKey(files);
24153
24220
  const compact = compactContext(store, context, entry?.id ?? null, freshness, origin && { origin: origin.origin, taskId: origin.entry.id });
24154
24221
  if (!compact.ok || !compact.data)
@@ -24207,17 +24274,17 @@ ${options.addendum}` : ""}
24207
24274
  </workit-contract>`;
24208
24275
  };
24209
24276
  var checkoutAt = (cwd) => {
24210
- for (let dir = path33.resolve(cwd);; dir = path33.dirname(dir)) {
24211
- const dotGit = path33.join(dir, ".git");
24277
+ for (let dir = path34.resolve(cwd);; dir = path34.dirname(dir)) {
24278
+ const dotGit = path34.join(dir, ".git");
24212
24279
  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();
24280
+ const admin = fs22.statSync(dotGit).isFile() ? path34.resolve(dir, /^gitdir:\s*(.+)$/mu.exec(fs22.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "") : dotGit;
24281
+ const head = fs22.readFileSync(path34.join(admin, "HEAD"), "utf8").trim();
24215
24282
  return {
24216
24283
  root: dir,
24217
24284
  branch: /^ref: refs\/heads\/(.+)$/u.exec(head)?.[1] ?? null
24218
24285
  };
24219
24286
  }
24220
- if (path33.dirname(dir) === dir)
24287
+ if (path34.dirname(dir) === dir)
24221
24288
  return null;
24222
24289
  }
24223
24290
  };
@@ -24228,7 +24295,7 @@ var whereLine = (cwd) => {
24228
24295
  return null;
24229
24296
  const allowed = branchPolicySnapshotFor(cwd).namePolicy.allowed;
24230
24297
  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}`;
24298
+ const place = checkout.root === path34.resolve(cwd) ? "" : ` in ${checkout.root}`;
24232
24299
  return `cwd ${cwd}${place} on ${checkout.branch ?? "detached HEAD"}; branch kinds: ${kinds}`;
24233
24300
  } catch {
24234
24301
  return null;
@@ -24255,14 +24322,14 @@ var turnMarker = (input) => {
24255
24322
  if (location instanceof Error)
24256
24323
  return null;
24257
24324
  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`);
24325
+ return path34.join(location.dir, "hooks", `turn-${digestOf(session).slice(0, 32)}.json`);
24259
24326
  } catch {
24260
24327
  return null;
24261
24328
  }
24262
24329
  };
24263
24330
  var writeTurnDigest = (file, digest) => {
24264
24331
  try {
24265
- fs22.mkdirSync(path33.dirname(file), { recursive: true });
24332
+ fs22.mkdirSync(path34.dirname(file), { recursive: true });
24266
24333
  fs22.writeFileSync(file, `${JSON.stringify({ digest })}
24267
24334
  `);
24268
24335
  } catch {}
@@ -24277,7 +24344,7 @@ var pruneTurnDigests = (dir, now) => {
24277
24344
  for (const name of fs22.readdirSync(dir)) {
24278
24345
  if (!name.startsWith("turn-"))
24279
24346
  continue;
24280
- const file = path33.join(dir, name);
24347
+ const file = path34.join(dir, name);
24281
24348
  try {
24282
24349
  if (now - fs22.statSync(file).mtimeMs > TURN_TTL_MS)
24283
24350
  fs22.rmSync(file, { force: true });
@@ -24307,7 +24374,7 @@ var seedTurnContext = (input, descriptor, text = turnContextText(input, descript
24307
24374
  const file = turnMarker(input);
24308
24375
  if (!file)
24309
24376
  return;
24310
- pruneTurnDigests(path33.dirname(file), Date.now());
24377
+ pruneTurnDigests(path34.dirname(file), Date.now());
24311
24378
  if (text)
24312
24379
  writeTurnDigest(file, digestOf(text));
24313
24380
  else
@@ -24348,7 +24415,8 @@ var WORKIT_USER_ONLY = [
24348
24415
  ["release", "notes", "approve"],
24349
24416
  ["grant", "set"],
24350
24417
  ["grant", "raise"],
24351
- ["ledger", "void"]
24418
+ ["ledger", "void"],
24419
+ ["approve"]
24352
24420
  ];
24353
24421
  var ALLOWED = new Set(WORKIT_ALLOWED_VERBS);
24354
24422
  var hasWordsInOrder = (words, needle) => {
@@ -24413,7 +24481,7 @@ var userOnlyWorkitCall = (command, dialect = "posix") => {
24413
24481
  // packages/workit-core/src/core/heavy-rules.ts
24414
24482
  import fs23 from "node:fs";
24415
24483
  import os8 from "node:os";
24416
- import path34 from "node:path";
24484
+ import path35 from "node:path";
24417
24485
  var EMPTY2 = () => ({ deny: [], allow: [] });
24418
24486
  var readText3 = (file) => {
24419
24487
  try {
@@ -24454,19 +24522,19 @@ function parseJsonc(text) {
24454
24522
  return JSON.parse(out.replace(/,(\s*[}\]])/gu, "$1"));
24455
24523
  }
24456
24524
  function gitTop(cwd) {
24457
- for (let dir = path34.resolve(cwd);; dir = path34.dirname(dir)) {
24458
- if (fs23.existsSync(path34.join(dir, ".git")))
24525
+ for (let dir = path35.resolve(cwd);; dir = path35.dirname(dir)) {
24526
+ if (fs23.existsSync(path35.join(dir, ".git")))
24459
24527
  return dir;
24460
- if (path34.dirname(dir) === dir)
24528
+ if (path35.dirname(dir) === dir)
24461
24529
  return null;
24462
24530
  }
24463
24531
  }
24464
24532
  var projectDirs = (cwd) => {
24465
24533
  const top = gitTop(cwd);
24466
24534
  const dirs = [];
24467
- for (let dir = path34.resolve(cwd);; dir = path34.dirname(dir)) {
24535
+ for (let dir = path35.resolve(cwd);; dir = path35.dirname(dir)) {
24468
24536
  dirs.push(dir);
24469
- if (!top || dir === top || path34.dirname(dir) === dir)
24537
+ if (!top || dir === top || path35.dirname(dir) === dir)
24470
24538
  return dirs;
24471
24539
  }
24472
24540
  };
@@ -24478,12 +24546,12 @@ var CLAUDE_MANAGED = {
24478
24546
  };
24479
24547
  function claudeSettingsFiles(cwd, env, platform = process.platform) {
24480
24548
  const project = env.CLAUDE_PROJECT_DIR || gitTop(cwd) || cwd;
24481
- const user = env.CLAUDE_CONFIG_DIR || path34.join(homeOf(env), ".claude");
24549
+ const user = env.CLAUDE_CONFIG_DIR || path35.join(homeOf(env), ".claude");
24482
24550
  return [
24483
24551
  ...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")
24552
+ path35.join(user, "settings.json"),
24553
+ path35.join(project, ".claude", "settings.json"),
24554
+ path35.join(project, ".claude", "settings.local.json")
24487
24555
  ];
24488
24556
  }
24489
24557
  var bashPattern = (entry) => {
@@ -24573,10 +24641,10 @@ var opencodeConfig = (value, rules) => {
24573
24641
  function opencodeRules(cwd, env = process.env) {
24574
24642
  const rules = EMPTY2();
24575
24643
  try {
24576
- const config = env.XDG_CONFIG_HOME || path34.join(homeOf(env), ".config");
24644
+ const config = env.XDG_CONFIG_HOME || path35.join(homeOf(env), ".config");
24577
24645
  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)])),
24646
+ ...OPENCODE_NAMES.map((name) => path35.join(config, "opencode", name)),
24647
+ ...projectDirs(cwd).flatMap((dir) => OPENCODE_NAMES.flatMap((name) => [path35.join(dir, name), path35.join(dir, ".opencode", name)])),
24580
24648
  ...env.OPENCODE_CONFIG ? [env.OPENCODE_CONFIG] : []
24581
24649
  ];
24582
24650
  for (const file of files) {
@@ -24620,9 +24688,9 @@ var codexRule = (body) => {
24620
24688
  function codexRules(cwd, env = process.env) {
24621
24689
  const rules = EMPTY2();
24622
24690
  try {
24623
- const home = env.CODEX_HOME || path34.join(homeOf(env), ".codex");
24691
+ const home = env.CODEX_HOME || path35.join(homeOf(env), ".codex");
24624
24692
  const top = gitTop(cwd) ?? cwd;
24625
- for (const dir of [path34.join(home, "rules"), path34.join(top, ".codex", "rules")]) {
24693
+ for (const dir of [path35.join(home, "rules"), path35.join(top, ".codex", "rules")]) {
24626
24694
  let files;
24627
24695
  try {
24628
24696
  files = fs23.readdirSync(dir).filter((name) => name.endsWith(".rules"));
@@ -24632,7 +24700,7 @@ function codexRules(cwd, env = process.env) {
24632
24700
  return "unreadable";
24633
24701
  }
24634
24702
  for (const name of files) {
24635
- const text = readText3(path34.join(dir, name)) ?? "";
24703
+ const text = readText3(path35.join(dir, name)) ?? "";
24636
24704
  for (const part of text.split(/\bprefix_rule\s*\(/u).slice(1)) {
24637
24705
  const rule = codexRule(part);
24638
24706
  if (!rule)
@@ -24651,8 +24719,8 @@ function cursorRules(cwd, env = process.env) {
24651
24719
  try {
24652
24720
  const top = gitTop(cwd) ?? cwd;
24653
24721
  for (const file of [
24654
- path34.join(homeOf(env), ".cursor", "cli-config.json"),
24655
- path34.join(top, ".cursor", "cli.json")
24722
+ path35.join(homeOf(env), ".cursor", "cli-config.json"),
24723
+ path35.join(top, ".cursor", "cli.json")
24656
24724
  ]) {
24657
24725
  const text = readText3(file);
24658
24726
  if (text === null)
@@ -24727,10 +24795,10 @@ function wrapAllowed(read, words, command, options = {}) {
24727
24795
 
24728
24796
  // packages/workit-core/src/core/heavy.ts
24729
24797
  import fs24 from "node:fs";
24730
- import path35 from "node:path";
24798
+ import path36 from "node:path";
24731
24799
  var stateDir2 = (env, platform = process.platform) => stateDir(env, platform);
24732
24800
  var HEAVY_COMMANDS_FILE = "heavy-commands.json";
24733
- var heavyCommandsFile = (env) => path35.join(stateDir2(env), HEAVY_COMMANDS_FILE);
24801
+ var heavyCommandsFile = (env) => path36.join(stateDir2(env), HEAVY_COMMANDS_FILE);
24734
24802
  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
24803
  var INFO_FLAGS = new Set(["--version", "-v", "-V", "--help", "-h", "help", "version"]);
24736
24804
  var WATCH_FLAG = /^(?:--watch(?:All)?(?:=.*)?|-w|--serve)$/u;
@@ -25005,7 +25073,7 @@ function machinePatterns(env) {
25005
25073
  return isRecord5(value) ? stringList(value.patterns) : [];
25006
25074
  }
25007
25075
  function repoPatterns(cwd) {
25008
- return repoHeavyCommands(gitTop(cwd) ?? path35.resolve(cwd));
25076
+ return repoHeavyCommands(gitTop(cwd) ?? path36.resolve(cwd));
25009
25077
  }
25010
25078
  function heavyLines(lines, options) {
25011
25079
  const found = [];
@@ -25083,12 +25151,12 @@ function heavyPlan(command, options) {
25083
25151
  }
25084
25152
  function workitOnPath2(env = process.env) {
25085
25153
  const names = process.platform === "win32" ? ["workit.exe", "workit.cmd", "workit"] : ["workit"];
25086
- for (const dir of (env.PATH ?? "").split(path35.delimiter))
25154
+ for (const dir of (env.PATH ?? "").split(path36.delimiter))
25087
25155
  for (const name of names) {
25088
25156
  if (!dir)
25089
25157
  continue;
25090
25158
  try {
25091
- fs24.accessSync(path35.join(dir, name), fs24.constants.X_OK);
25159
+ fs24.accessSync(path36.join(dir, name), fs24.constants.X_OK);
25092
25160
  return true;
25093
25161
  } catch {}
25094
25162
  }
@@ -25106,7 +25174,7 @@ function leaseRewrite(command) {
25106
25174
 
25107
25175
  // packages/workit-core/src/core/heavy-words.ts
25108
25176
  import fs25 from "node:fs";
25109
- import path36 from "node:path";
25177
+ import path37 from "node:path";
25110
25178
  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
25179
  var wordsOf = (command) => command.split(/[\s;&|()<>`'"]+/u).map((word) => (word.split(/[\\/]/u).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd|bat)$/u, "")).filter(Boolean);
25112
25180
  var stateDir3 = (env) => stateDir(env);
@@ -25119,15 +25187,15 @@ var readJson2 = (file) => {
25119
25187
  };
25120
25188
  var patternWords = (cwd, env) => {
25121
25189
  const patterns = [];
25122
- const machine = readJson2(path36.join(stateDir3(env), "heavy-commands.json"));
25190
+ const machine = readJson2(path37.join(stateDir3(env), "heavy-commands.json"));
25123
25191
  if (Array.isArray(machine?.patterns))
25124
25192
  patterns.push(...machine.patterns);
25125
- for (let dir = path36.resolve(cwd);; dir = path36.dirname(dir)) {
25126
- if (fs25.existsSync(path36.join(dir, ".git"))) {
25193
+ for (let dir = path37.resolve(cwd);; dir = path37.dirname(dir)) {
25194
+ if (fs25.existsSync(path37.join(dir, ".git"))) {
25127
25195
  patterns.push(...repoHeavyCommands(dir));
25128
25196
  break;
25129
25197
  }
25130
- if (path36.dirname(dir) === dir)
25198
+ if (path37.dirname(dir) === dir)
25131
25199
  break;
25132
25200
  }
25133
25201
  const words = new Set;
@@ -25203,14 +25271,14 @@ var splitDenial = (plan) => ({
25203
25271
  // packages/workit-core/src/hooks/write-gate.ts
25204
25272
  import { existsSync as existsSync12, realpathSync as realpathSync9, statSync as statSync3 } from "node:fs";
25205
25273
  import os10 from "node:os";
25206
- import path38 from "node:path";
25274
+ import path39 from "node:path";
25207
25275
 
25208
25276
  // packages/workit-core/src/core/live-session.ts
25209
25277
  import { spawnSync as spawnSync22 } from "node:child_process";
25210
25278
  import { createHash as createHash17 } from "node:crypto";
25211
25279
  import fs26 from "node:fs";
25212
25280
  import os9 from "node:os";
25213
- import path37 from "node:path";
25281
+ import path38 from "node:path";
25214
25282
  var LIVE_SESSION_TTL_MS = 15 * 60000;
25215
25283
  var HEARTBEAT_EVERY_MS = 30000;
25216
25284
  var liveProbe = {
@@ -25284,15 +25352,15 @@ var liveOwner = (input, transport, env = process.env) => {
25284
25352
  };
25285
25353
  };
25286
25354
  var checkoutOf = (target) => {
25287
- let dir = path37.resolve(target);
25288
- while (!fs26.existsSync(dir) && path37.dirname(dir) !== dir)
25289
- dir = path37.dirname(dir);
25355
+ let dir = path38.resolve(target);
25356
+ while (!fs26.existsSync(dir) && path38.dirname(dir) !== dir)
25357
+ dir = path38.dirname(dir);
25290
25358
  if (fs26.existsSync(dir) && !fs26.statSync(dir).isDirectory())
25291
- dir = path37.dirname(dir);
25292
- const parts = dir.split(path37.sep);
25359
+ dir = path38.dirname(dir);
25360
+ const parts = dir.split(path38.sep);
25293
25361
  const dotGit = parts.lastIndexOf(".git");
25294
25362
  if (dotGit > 0)
25295
- dir = parts.slice(0, dotGit).join(path37.sep) || path37.sep;
25363
+ dir = parts.slice(0, dotGit).join(path38.sep) || path38.sep;
25296
25364
  const location = resolveStore(dir);
25297
25365
  if (location instanceof Error || !location.shared || !location.top)
25298
25366
  return null;
@@ -25302,9 +25370,9 @@ var checkoutOf = (target) => {
25302
25370
  } catch {}
25303
25371
  return top;
25304
25372
  };
25305
- var markerFile2 = (top) => path37.join(resolveStateDir(), "live-sessions", `${createHash17("sha256").update(checkoutKey(top)).digest("hex").slice(0, 32)}.json`);
25373
+ var markerFile2 = (top) => path38.join(resolveStateDir(), "live-sessions", `${createHash17("sha256").update(checkoutKey(top)).digest("hex").slice(0, 32)}.json`);
25306
25374
  var checkoutKey = (top, platform = process.platform) => {
25307
- let key = path37.resolve(top);
25375
+ let key = path38.resolve(top);
25308
25376
  try {
25309
25377
  key = fs26.realpathSync.native(key);
25310
25378
  } catch {}
@@ -25399,7 +25467,7 @@ var claimLiveSession = (target, owner, deps = {}) => {
25399
25467
  checkout,
25400
25468
  heartbeatAt: now.toISOString()
25401
25469
  };
25402
- fs26.mkdirSync(path37.dirname(file), { recursive: true });
25470
+ fs26.mkdirSync(path38.dirname(file), { recursive: true });
25403
25471
  const temp = `${file}.${process.pid}.tmp`;
25404
25472
  fs26.writeFileSync(temp, JSON.stringify(marker));
25405
25473
  fs26.renameSync(temp, file);
@@ -25411,22 +25479,22 @@ var NONE3 = { kind: "none" };
25411
25479
  var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "win32";
25412
25480
  var canonical3 = (file) => {
25413
25481
  let rest = "";
25414
- for (let dir = path38.resolve(file);; dir = path38.dirname(dir)) {
25482
+ for (let dir = path39.resolve(file);; dir = path39.dirname(dir)) {
25415
25483
  try {
25416
- return path38.join(realpathSync9.native(dir), rest);
25484
+ return path39.join(realpathSync9.native(dir), rest);
25417
25485
  } catch {
25418
- if (path38.dirname(dir) === dir)
25419
- return path38.resolve(file);
25420
- rest = rest ? path38.join(path38.basename(dir), rest) : path38.basename(dir);
25486
+ if (path39.dirname(dir) === dir)
25487
+ return path39.resolve(file);
25488
+ rest = rest ? path39.join(path39.basename(dir), rest) : path39.basename(dir);
25421
25489
  }
25422
25490
  }
25423
25491
  };
25424
25492
  var exempt = (cwd, root, file, plans) => {
25425
25493
  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))
25494
+ const relative = path39.relative(fold(canonical3(root)), fold(canonical3(path39.resolve(cwd, file))));
25495
+ if (relative.startsWith("..") || path39.isAbsolute(relative))
25428
25496
  return true;
25429
- const posix = relative.split(path38.sep).join("/");
25497
+ const posix = relative.split(path39.sep).join("/");
25430
25498
  const segments = posix.split("/");
25431
25499
  return /\.mdx?$/i.test(posix) || segments[0] === "docs" || segments.includes("plans") || [...plans].some((plan) => fold(plan) === posix);
25432
25500
  };
@@ -25777,10 +25845,10 @@ var linkSources = (args, at) => {
25777
25845
  const sources = names.filter((name, index) => into >= 0 ? name !== dest : index < names.length - 1 || names.length === 1);
25778
25846
  const target = dest === undefined ? null : at(dest);
25779
25847
  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);
25848
+ const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target : path39.dirname(target);
25781
25849
  return sources.flatMap((source) => {
25782
- if (symbolic && base !== null && !path38.isAbsolute(homeExpanded(source)))
25783
- return [path38.resolve(base, source)];
25850
+ if (symbolic && base !== null && !path39.isAbsolute(homeExpanded(source)))
25851
+ return [path39.resolve(base, source)];
25784
25852
  const resolved = at(source);
25785
25853
  return resolved ? [resolved] : [];
25786
25854
  });
@@ -25809,7 +25877,7 @@ var shellWrites = (command, depth = 0) => {
25809
25877
  return { writes: true, targets: unknown ? null : targets };
25810
25878
  };
25811
25879
  var cache3 = new Map;
25812
- var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path38.resolve(root, file)) ?? "-").join("\x00");
25880
+ var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path39.resolve(root, file)) ?? "-").join("\x00");
25813
25881
  var gateFor = (cwd) => {
25814
25882
  const store = new TaskStore(cwd);
25815
25883
  const listed = store.listTaskIndex();
@@ -25889,13 +25957,13 @@ var gitMutationDirs = (cwd, command, dialect) => {
25889
25957
  return [];
25890
25958
  if (sub === "stash" && ["list", "show"].includes(rest[0] ?? ""))
25891
25959
  return [];
25892
- return [path38.resolve(cwd, invocation.dir ?? ".")];
25960
+ return [path39.resolve(cwd, invocation.dir ?? ".")];
25893
25961
  });
25894
25962
  };
25895
25963
  var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
25896
25964
  var PUSHD2 = new Set(["pushd", "push-location"]);
25897
25965
  var POPD2 = new Set(["popd", "pop-location"]);
25898
- var UNKNOWN_DIR = path38.resolve(path38.parse(process.cwd()).root, ".workit-unknown-dir");
25966
+ var UNKNOWN_DIR = path39.resolve(path39.parse(process.cwd()).root, ".workit-unknown-dir");
25899
25967
  var cdInto = (dir, words, strict = false, vars = new Map) => {
25900
25968
  const lost = strict ? UNKNOWN_DIR : undefined;
25901
25969
  const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
@@ -25905,7 +25973,7 @@ var cdInto = (dir, words, strict = false, vars = new Map) => {
25905
25973
  return lost;
25906
25974
  if (dir === undefined)
25907
25975
  return lost;
25908
- return target === undefined ? os10.homedir() : path38.resolve(dir, target);
25976
+ return target === undefined ? os10.homedir() : path39.resolve(dir, target);
25909
25977
  };
25910
25978
  var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
25911
25979
  var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
@@ -26039,7 +26107,7 @@ var untrustedVars = (segments) => {
26039
26107
  }
26040
26108
  return { all, names };
26041
26109
  };
26042
- var UNKNOWN_VAR = path38.resolve(path38.parse(process.cwd()).root, ".workit-unknown-var");
26110
+ var UNKNOWN_VAR = path39.resolve(path39.parse(process.cwd()).root, ".workit-unknown-var");
26043
26111
  var REFERENCE = /\$\{(\w+)[^}]*\}|\$(\w+)|\$\([^)]*\)?|`[^`]*`?/g;
26044
26112
  var unresolvedRefs = (text) => [
26045
26113
  ...new Set([...text.matchAll(REFERENCE)].map((match) => {
@@ -26049,7 +26117,7 @@ var unresolvedRefs = (text) => [
26049
26117
  ];
26050
26118
  var unknownVarTarget = (text) => {
26051
26119
  const refs = unresolvedRefs(text);
26052
- return path38.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
26120
+ return path39.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
26053
26121
  };
26054
26122
  var applyOperator = (value, operator) => {
26055
26123
  if (operator === "")
@@ -26109,12 +26177,12 @@ var mktempPath = (value, dir) => {
26109
26177
  if (base === null && (temp || template === undefined))
26110
26178
  base = os10.tmpdir();
26111
26179
  const name = homeExpanded(template ?? "tmp.XXXXXXXXXX");
26112
- if (path38.isAbsolute(name))
26180
+ if (path39.isAbsolute(name))
26113
26181
  return name;
26114
26182
  const from = base === null ? dir : homeExpanded(base);
26115
- if (from === undefined || !path38.isAbsolute(from) && dir === undefined)
26183
+ if (from === undefined || !path39.isAbsolute(from) && dir === undefined)
26116
26184
  return null;
26117
- return path38.resolve(dir ?? from, from, name);
26185
+ return path39.resolve(dir ?? from, from, name);
26118
26186
  };
26119
26187
  var homeExpanded = (file) => {
26120
26188
  const match = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(file);
@@ -26134,9 +26202,9 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26134
26202
  const home = homeExpanded(text);
26135
26203
  if (strict && unresolvedRefs(home).length > 0)
26136
26204
  return [unknownVarTarget(home)];
26137
- if (path38.isAbsolute(home))
26205
+ if (path39.isAbsolute(home))
26138
26206
  return [home];
26139
- return base === undefined ? [] : [path38.resolve(base, home)];
26207
+ return base === undefined ? [] : [path39.resolve(base, home)];
26140
26208
  });
26141
26209
  const at = (file) => {
26142
26210
  const all = atAll(file);
@@ -26169,7 +26237,12 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26169
26237
  };
26170
26238
  for (const segment of segments) {
26171
26239
  if (segment.group === "open") {
26172
- groups.push({ dir, stack: [...stack], vars: new Map(vars), loops: new Map(loops) });
26240
+ groups.push({
26241
+ dir,
26242
+ stack: [...stack],
26243
+ vars: new Map(vars),
26244
+ loops: new Map(loops)
26245
+ });
26173
26246
  continue;
26174
26247
  }
26175
26248
  if (segment.group === "close") {
@@ -26278,7 +26351,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26278
26351
  const here = segment.unanalyzable ? DIR_TARGET : `${OPAQUE_TARGET}${encodeURIComponent(runner?.split(/[\\/]/).at(-1) ?? "a command")}`;
26279
26352
  for (const file of opaque ?? [])
26280
26353
  for (const resolved of atAll(file))
26281
- targets.push(file === "." ? path38.join(resolved, here) : resolved);
26354
+ targets.push(file === "." ? path39.join(resolved, here) : resolved);
26282
26355
  const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
26283
26356
  if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)))
26284
26357
  targets.push(...linkSources(words.slice(ln + 1), at));
@@ -26289,7 +26362,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26289
26362
  const edits = editsOf(body);
26290
26363
  if (edits === null) {
26291
26364
  if (dir !== undefined)
26292
- targets.push(path38.join(dir, DIR_TARGET));
26365
+ targets.push(path39.join(dir, DIR_TARGET));
26293
26366
  } else
26294
26367
  for (const file of edits)
26295
26368
  targets.push(...atAll(file));
@@ -26297,7 +26370,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
26297
26370
  for (const invocation of workitInvocations(body.map(quoteWord2).join(" "), "posix")) {
26298
26371
  const { at: runsIn, args } = workitCwd(dir, invocation, atAll);
26299
26372
  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)));
26373
+ targets.push(...runsIn.map((runs) => path39.join(runs, DIR_TARGET)));
26301
26374
  }
26302
26375
  }
26303
26376
  return targets;
@@ -26318,7 +26391,7 @@ var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) =>
26318
26391
  try {
26319
26392
  return [
26320
26393
  ...segmentTargets(cwd, command, dialect, 0, strict),
26321
- ...gitMutationDirs(cwd, command, dialect).map((dir) => path38.join(dir, DIR_TARGET))
26394
+ ...gitMutationDirs(cwd, command, dialect).map((dir) => path39.join(dir, DIR_TARGET))
26322
26395
  ];
26323
26396
  } catch {
26324
26397
  return [];
@@ -26355,7 +26428,7 @@ var liveDeny = ({ marker, checkout, ageMs, file }) => {
26355
26428
  var guarded = (targets) => {
26356
26429
  const seen = new Set;
26357
26430
  return targets.filter((target) => {
26358
- const dir = path38.dirname(target);
26431
+ const dir = path39.dirname(target);
26359
26432
  if (seen.has(dir))
26360
26433
  return false;
26361
26434
  seen.add(dir);
@@ -26376,40 +26449,61 @@ var claimAll = (owner, targets, deps) => {
26376
26449
  for (const target of guarded(targets))
26377
26450
  claimLiveSession(target, owner, deps);
26378
26451
  };
26379
- var liveTargets = (cwd, paths) => paths?.length ? paths.map((file) => path38.resolve(cwd, file)) : [path38.join(cwd, DIR_TARGET)];
26380
- var issuedTarget = (cwd, targets) => {
26452
+ var liveTargets = (cwd, paths) => paths?.length ? paths.map((file) => path39.resolve(cwd, file)) : [path39.join(cwd, DIR_TARGET)];
26453
+ var registryTarget = (cwd, targets) => {
26381
26454
  const state = resolveStateDir();
26382
- const found = targets.find((target) => underIssued(state, cwd, homeExpanded(target), process.platform, canonical3));
26383
- return found ?? null;
26455
+ for (const target of targets) {
26456
+ const registry = underRegistry(state, cwd, homeExpanded(target), process.platform, canonical3);
26457
+ if (registry)
26458
+ return { file: target, registry };
26459
+ }
26460
+ return null;
26384
26461
  };
26385
- var underIssued = (state, cwd, target, platform = process.platform, real = (file) => file) => {
26462
+ var underRegistry = (state, cwd, target, platform = process.platform, real = (file) => file) => {
26386
26463
  const win = platform === "win32";
26387
- const p = win ? path38.win32 : path38.posix;
26464
+ const p = win ? path39.win32 : path39.posix;
26388
26465
  const fold = (value) => win || platform === "darwin" ? value.toLowerCase() : value;
26389
26466
  const named = win ? target.replace(/^\/([a-zA-Z])(?=\/|$)/, "$1:") : target;
26390
26467
  const relative = p.relative(fold(real(p.resolve(state))), fold(real(p.resolve(cwd, named))));
26391
26468
  if (relative.startsWith("..") || p.isAbsolute(relative))
26392
- return false;
26393
- return relative.split(p.sep)[0].startsWith("issued");
26469
+ return null;
26470
+ const first = relative.split(p.sep)[0];
26471
+ if (first.startsWith("issued"))
26472
+ return "issued";
26473
+ return first === "approvals" ? "approvals" : null;
26394
26474
  };
26395
- var unquotedWindowsIssued = (command) => {
26475
+ var unquotedWindowsRegistry = (command) => {
26396
26476
  if (process.platform !== "win32" || !command.includes("\\"))
26397
- return false;
26477
+ return null;
26398
26478
  const flat = (value) => value.replaceAll("\\", "/").toLowerCase();
26399
- return flat(command).includes(`${flat(resolveStateDir())}/issued`) && shellWrites(command).writes;
26479
+ const text = flat(command);
26480
+ const state = flat(resolveStateDir());
26481
+ const registry = text.includes(`${state}/issued`) ? "issued" : text.includes(`${state}/approvals`) ? "approvals" : null;
26482
+ return registry && shellWrites(command).writes ? registry : null;
26483
+ };
26484
+ var REGISTRY_DENY = {
26485
+ issued: {
26486
+ label: "issued-registry guard",
26487
+ 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."
26488
+ },
26489
+ approvals: {
26490
+ label: "approvals guard",
26491
+ 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."
26492
+ }
26400
26493
  };
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.";
26494
+ var registryDeny = ({ file, registry }) => {
26495
+ const { label, unblock } = REGISTRY_DENY[registry];
26496
+ const what = registry === "issued" ? "issued-session state" : "host-approval state";
26403
26497
  return {
26404
26498
  kind: "deny",
26405
- reason: `workit issued-registry guard: ${file} is under Workit's issued-session state. ${unblock}`,
26499
+ reason: `workit ${label}: ${file} is under Workit's ${what}. ${unblock}`,
26406
26500
  unblock
26407
26501
  };
26408
26502
  };
26409
26503
  function writeGate(cwd, paths, owner, deps) {
26410
- const forged = paths?.length ? issuedTarget(cwd, paths) : null;
26504
+ const forged = paths?.length ? registryTarget(cwd, paths) : null;
26411
26505
  if (forged)
26412
- return issuedDeny(forged);
26506
+ return registryDeny(forged);
26413
26507
  if (!owner)
26414
26508
  return beforeWriteGate(cwd, paths);
26415
26509
  const targets = liveTargets(cwd, paths);
@@ -26423,9 +26517,10 @@ function writeGate(cwd, paths, owner, deps) {
26423
26517
  }
26424
26518
  function shellGate(cwd, command, owner, dialect = "posix", deps) {
26425
26519
  try {
26426
- const forged = issuedTarget(cwd, segmentTargets(cwd, command, dialect)) ?? (unquotedWindowsIssued(command) ? "the issued registry" : null);
26520
+ const windows = unquotedWindowsRegistry(command);
26521
+ const forged = registryTarget(cwd, segmentTargets(cwd, command, dialect)) ?? (windows ? { file: `the ${windows} registry`, registry: windows } : null);
26427
26522
  if (forged)
26428
- return issuedDeny(forged);
26523
+ return registryDeny(forged);
26429
26524
  } catch {}
26430
26525
  const writes = shellWrites(command);
26431
26526
  let targets = [];
@@ -26478,10 +26573,10 @@ import { spawnSync as spawnSync23 } from "node:child_process";
26478
26573
 
26479
26574
  // packages/workit-core/src/ci-waiter.ts
26480
26575
  import fs27 from "node:fs";
26481
- import path39 from "node:path";
26576
+ import path40 from "node:path";
26482
26577
  var waiterFile = (cwd, pr) => {
26483
26578
  const common = gitCommonDir(cwd);
26484
- return common ? path39.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
26579
+ return common ? path40.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
26485
26580
  };
26486
26581
  var pidAlive2 = (pid) => {
26487
26582
  if (!Number.isSafeInteger(pid) || pid <= 0)
@@ -27020,7 +27115,179 @@ var writePaths = (input) => {
27020
27115
  };
27021
27116
  // packages/workit-core/src/hooks/standing.ts
27022
27117
  import fs29 from "node:fs";
27118
+ import path43 from "node:path";
27119
+
27120
+ // packages/workit-core/src/approvals/store.ts
27121
+ import { createHash as createHash18, randomBytes as randomBytes4 } from "node:crypto";
27122
+ import { mkdirSync as mkdirSync5, readdirSync as readdirSync4, readFileSync as readFileSync9 } from "node:fs";
27023
27123
  import path41 from "node:path";
27124
+ var REQUEST_TTL_MS = 30 * 60000;
27125
+ var GRANT_TTL_MS = 15 * 60000;
27126
+ var ID_PATTERN = /^ap_[a-z2-7]{8}$/u;
27127
+ var isApprovalId = (word) => ID_PATTERN.test(word);
27128
+ var approvalHash = (fields) => createHash18("sha256").update(canonicalJson({
27129
+ kind: fields.kind,
27130
+ action: fields.action,
27131
+ target: fields.target,
27132
+ effect: fields.effect,
27133
+ subject: fields.subject
27134
+ })).digest("hex");
27135
+ var approvalsDir = () => path41.join(resolveStateDir(), "approvals");
27136
+ var dirOf = (part) => path41.join(approvalsDir(), part);
27137
+ var fileOf = (part, id) => path41.join(dirOf(part), `${id}.json`);
27138
+ var askedFile = (session, toolUseId) => path41.join(dirOf("asked"), `${createHash18("sha256").update(`${session}\x00${toolUseId}`).digest("hex").slice(0, 32)}.json`);
27139
+ var readJson3 = (file) => {
27140
+ try {
27141
+ const value = JSON.parse(readFileSync9(file, "utf8"));
27142
+ return value !== null && typeof value === "object" ? value : null;
27143
+ } catch {
27144
+ return null;
27145
+ }
27146
+ };
27147
+ var write = (file, value) => {
27148
+ mkdirSync5(path41.dirname(file), { recursive: true });
27149
+ writeFileAtomic(file, `${JSON.stringify(value, null, 2)}
27150
+ `);
27151
+ };
27152
+ var live = (expires, now) => Date.parse(expires) > now.getTime();
27153
+ var later = (now, ms) => new Date(now.getTime() + ms).toISOString();
27154
+ var readApprovalRequest = (id) => {
27155
+ if (!isApprovalId(id))
27156
+ return null;
27157
+ const request = readJson3(fileOf("requests", id));
27158
+ if (!request || request.id !== id)
27159
+ return null;
27160
+ try {
27161
+ return approvalHash(request) === request.hash ? request : null;
27162
+ } catch {
27163
+ return null;
27164
+ }
27165
+ };
27166
+ var liveApprovalRequest = (id, now = new Date) => {
27167
+ const request = readApprovalRequest(id);
27168
+ if (!request)
27169
+ return { ok: false, reason: `${id}: no such approval request` };
27170
+ if (!live(request.expires, now))
27171
+ return {
27172
+ ok: false,
27173
+ reason: `${id}: the request expired at ${request.expires}`
27174
+ };
27175
+ if (readJson3(fileOf("consumed", id)))
27176
+ return { ok: false, reason: `${id}: already approved and used` };
27177
+ if (readJson3(fileOf("rejected", id)))
27178
+ return {
27179
+ ok: false,
27180
+ reason: `${id}: the user rejected it or chose to edit its subject`
27181
+ };
27182
+ return { ok: true, request };
27183
+ };
27184
+ var subjectLine = (subject) => Object.entries(subject).map(([key, value]) => `${key}: ${typeof value === "string" ? value : JSON.stringify(value)}`).join("; ");
27185
+ var renderApprovalRequest = (request) => [
27186
+ `${request.id} (${request.kind}): ${request.action}`,
27187
+ ` target: ${Object.entries(request.target).map(([key, value]) => `${key} ${value}`).join(", ")}`,
27188
+ ` effect: ${request.effect}`,
27189
+ ` subject: ${subjectLine(request.subject)}`,
27190
+ ` hash: ${request.hash.slice(0, 12)} expires: ${request.expires}`
27191
+ ].join(`
27192
+ `);
27193
+ var recordApprovalAsked = (input, now = new Date) => {
27194
+ const hashes = {};
27195
+ for (const id of input.ids) {
27196
+ const found = liveApprovalRequest(id, now);
27197
+ if (found.ok)
27198
+ hashes[id] = found.request.hash;
27199
+ }
27200
+ const ids = Object.keys(hashes);
27201
+ if (ids.length === 0)
27202
+ return null;
27203
+ const asked = {
27204
+ toolUseId: input.toolUseId,
27205
+ session: input.session,
27206
+ host: input.host,
27207
+ ids,
27208
+ hashes,
27209
+ at: now.toISOString()
27210
+ };
27211
+ write(askedFile(input.session, input.toolUseId), asked);
27212
+ return asked;
27213
+ };
27214
+ var readApprovalAsked = (session, toolUseId) => {
27215
+ const asked = readJson3(askedFile(session, toolUseId));
27216
+ return asked && asked.session === session && asked.toolUseId === toolUseId ? asked : null;
27217
+ };
27218
+ var recordApprovalGrant = (input, options = {}) => {
27219
+ const now = options.now ?? new Date;
27220
+ const found = liveApprovalRequest(input.id, now);
27221
+ if (!found.ok)
27222
+ return found;
27223
+ if (input.via === "host") {
27224
+ const asked = input.session && input.toolUseId ? readApprovalAsked(input.session, input.toolUseId) : null;
27225
+ if (!asked || asked.hashes[input.id] !== found.request.hash)
27226
+ return {
27227
+ ok: false,
27228
+ reason: `${input.id}: no host ask showed this request on that call`
27229
+ };
27230
+ }
27231
+ const grant = {
27232
+ id: input.id,
27233
+ hash: found.request.hash,
27234
+ host: input.host,
27235
+ session: input.session,
27236
+ toolUseId: input.toolUseId,
27237
+ at: now.toISOString(),
27238
+ expires: later(now, options.ttlMs ?? GRANT_TTL_MS),
27239
+ via: input.via,
27240
+ observer: input.via === "host" ? "host_hook" : null
27241
+ };
27242
+ write(fileOf("grants", input.id), grant);
27243
+ return { ok: true, grant };
27244
+ };
27245
+ var recordApprovalRejected = (input, now = new Date) => {
27246
+ if (!readApprovalRequest(input.id))
27247
+ return;
27248
+ write(fileOf("rejected", input.id), { ...input, at: now.toISOString() });
27249
+ };
27250
+
27251
+ // packages/workit-core/src/approvals/call.ts
27252
+ var isWorkitWord2 = (word) => /^(?:.*[\\/])?workit(?:-cli)?$/u.test(word);
27253
+ var verbIndex = (words, start) => {
27254
+ let at = start;
27255
+ for (;; ) {
27256
+ const word = words[at];
27257
+ if (word === "--json")
27258
+ at += 1;
27259
+ else if (word === "--cwd" || word === "--session")
27260
+ at += 2;
27261
+ else if (word?.startsWith("--cwd="))
27262
+ at += 1;
27263
+ else
27264
+ return at;
27265
+ }
27266
+ };
27267
+ var approveCallIn = (command, dialect = "posix") => {
27268
+ const segments = segmentsOf(command, dialect);
27269
+ for (const segment of segments) {
27270
+ if (segment.unanalyzable)
27271
+ continue;
27272
+ const start = segment.words.findIndex(isWorkitWord2);
27273
+ if (start < 0)
27274
+ continue;
27275
+ const at = verbIndex(segment.words, start + 1);
27276
+ if (segment.words[at] !== "approve")
27277
+ continue;
27278
+ const args = segment.words.slice(at + 1);
27279
+ const ids = args.filter(isApprovalId);
27280
+ 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;
27281
+ if (plain)
27282
+ return ids.length > 0 && ids.length === args.length ? { plain: true, ids } : null;
27283
+ return {
27284
+ plain: false,
27285
+ fix: `workit approve ${ids.length ? ids.join(" ") : "<id>…"}`
27286
+ };
27287
+ }
27288
+ return null;
27289
+ };
27290
+ 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
27291
 
27025
27292
  // packages/workit-core/src/hooks/hosts/claude-code.ts
27026
27293
  var CLAUDE_CODE_DESCRIPTOR = {
@@ -27063,7 +27330,11 @@ var CLAUDE_CODE_DESCRIPTOR = {
27063
27330
  maxConcurrency: "undocumented",
27064
27331
  agentPrefix: "workit:"
27065
27332
  },
27066
- provenance: { sessionId: "native", agentIdOnTool: "native", postToolObserve: "native" },
27333
+ provenance: {
27334
+ sessionId: "native",
27335
+ agentIdOnTool: "native",
27336
+ postToolObserve: "native"
27337
+ },
27067
27338
  interaction: { questions: "undocumented", writeBoundary: "partial" },
27068
27339
  stopControl: "native",
27069
27340
  shellAvailable: "native",
@@ -27125,6 +27396,7 @@ var CONTEXT_EVENTS = new Set([
27125
27396
  "PreToolUse",
27126
27397
  "PostToolUse"
27127
27398
  ]);
27399
+ var ASKING_MODES = new Set(["default", "acceptEdits", "plan"]);
27128
27400
 
27129
27401
  // packages/workit-core/src/hooks/hosts/codex.ts
27130
27402
  var CODEX_DESCRIPTOR = {
@@ -27490,42 +27762,42 @@ function neededChecks(lane, configured) {
27490
27762
  }
27491
27763
 
27492
27764
  // packages/workit-core/src/hooks/worktree-confine.ts
27493
- import { createHash as createHash18 } from "node:crypto";
27765
+ import { createHash as createHash19 } from "node:crypto";
27494
27766
  import fs28 from "node:fs";
27495
- import path40 from "node:path";
27767
+ import path42 from "node:path";
27496
27768
  var FANOUT_TOKEN_FILE = "workit-fanout-token";
27497
27769
  var NONE5 = { kind: "none" };
27498
27770
  var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
27499
27771
  var canonical4 = (file) => {
27500
27772
  let rest = "";
27501
- for (let dir = path40.resolve(file);; dir = path40.dirname(dir)) {
27773
+ for (let dir = path42.resolve(file);; dir = path42.dirname(dir)) {
27502
27774
  try {
27503
- return path40.join(fs28.realpathSync.native(dir), rest);
27775
+ return path42.join(fs28.realpathSync.native(dir), rest);
27504
27776
  } catch {
27505
- if (path40.dirname(dir) === dir)
27506
- return path40.resolve(file);
27507
- rest = rest ? path40.join(path40.basename(dir), rest) : path40.basename(dir);
27777
+ if (path42.dirname(dir) === dir)
27778
+ return path42.resolve(file);
27779
+ rest = rest ? path42.join(path42.basename(dir), rest) : path42.basename(dir);
27508
27780
  }
27509
27781
  }
27510
27782
  };
27511
27783
  var within = (child, parent) => {
27512
27784
  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);
27785
+ const relative = path42.relative(fold(parent), fold(child));
27786
+ return relative === "" || !relative.startsWith("..") && !path42.isAbsolute(relative);
27515
27787
  };
27516
27788
  var checkoutOf2 = (file) => {
27517
- for (let dir = canonical4(file);; dir = path40.dirname(dir)) {
27518
- const dotGit = path40.join(dir, ".git");
27789
+ for (let dir = canonical4(file);; dir = path42.dirname(dir)) {
27790
+ const dotGit = path42.join(dir, ".git");
27519
27791
  if (fs28.existsSync(dotGit)) {
27520
27792
  if (!fs28.statSync(dotGit).isFile())
27521
27793
  return { root: dir, workit: false };
27522
27794
  const admin = /^gitdir:\s*(.+)$/mu.exec(fs28.readFileSync(dotGit, "utf8"))?.[1]?.trim();
27523
27795
  return {
27524
27796
  root: dir,
27525
- workit: Boolean(admin) && fs28.existsSync(path40.join(path40.resolve(dir, admin), FANOUT_TOKEN_FILE))
27797
+ workit: Boolean(admin) && fs28.existsSync(path42.join(path42.resolve(dir, admin), FANOUT_TOKEN_FILE))
27526
27798
  };
27527
27799
  }
27528
- if (path40.dirname(dir) === dir)
27800
+ if (path42.dirname(dir) === dir)
27529
27801
  return null;
27530
27802
  }
27531
27803
  };
@@ -27537,8 +27809,8 @@ var workitWorktreeOf = (file) => {
27537
27809
  return null;
27538
27810
  }
27539
27811
  };
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`);
27812
+ var bindingDir = () => path42.join(resolveStateDir(), "worktree-bind");
27813
+ var bindingFile = (session, agentId) => path42.join(bindingDir(), `${createHash19("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
27542
27814
  var readBinding = (file) => {
27543
27815
  try {
27544
27816
  const value = JSON.parse(fs28.readFileSync(file, "utf8"));
@@ -27563,7 +27835,7 @@ var bind = (input, worktree) => {
27563
27835
  agentId,
27564
27836
  at: new Date().toISOString()
27565
27837
  };
27566
- fs28.mkdirSync(path40.dirname(file), { recursive: true });
27838
+ fs28.mkdirSync(path42.dirname(file), { recursive: true });
27567
27839
  fs28.writeFileSync(file, JSON.stringify(binding));
27568
27840
  try {
27569
27841
  if (inWorkitWorkspace(input.cwd))
@@ -27582,31 +27854,31 @@ var hostIsolated = (cwd, agentId) => {
27582
27854
  const checkout = checkoutOf2(cwd);
27583
27855
  if (!checkout)
27584
27856
  return false;
27585
- const dotGit = path40.join(checkout.root, ".git");
27857
+ const dotGit = path42.join(checkout.root, ".git");
27586
27858
  if (!fs28.statSync(dotGit).isFile())
27587
27859
  return false;
27588
27860
  const admin = /^gitdir:\s*(.+)$/mu.exec(fs28.readFileSync(dotGit, "utf8"))?.[1]?.trim();
27589
27861
  if (!admin)
27590
27862
  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)) !== "")
27863
+ const adminDir = path42.resolve(checkout.root, admin);
27864
+ const back = fs28.readFileSync(path42.join(adminDir, "gitdir"), "utf8").trim();
27865
+ if (path42.relative(canonical4(path42.resolve(adminDir, back)), canonical4(dotGit)) !== "")
27594
27866
  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) === "";
27867
+ const common = path42.join(adminDir, "commondir");
27868
+ const gitDir = fs28.existsSync(common) ? path42.resolve(adminDir, fs28.readFileSync(common, "utf8").trim()) : adminDir;
27869
+ const expected = path42.join(path42.dirname(canonical4(gitDir)), ".claude", "worktrees", `agent-${agentId}`);
27870
+ return path42.relative(canonical4(expected), checkout.root) === "";
27599
27871
  } catch {
27600
27872
  return false;
27601
27873
  }
27602
27874
  };
27603
27875
  var runnerAt = (target) => {
27604
- const base = path40.basename(target);
27876
+ const base = path42.basename(target);
27605
27877
  return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
27606
27878
  };
27607
27879
  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;
27880
+ const named = /^\.workit-(?:live-target$|runs-)/.test(path42.basename(target)) ? path42.dirname(target) : target;
27881
+ return path42.sep === "\\" ? named.replaceAll("/", "\\") : named;
27610
27882
  };
27611
27883
  var unboundDeny = (input, target) => {
27612
27884
  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 +27917,7 @@ var literalForm = (command, refs) => {
27645
27917
  };
27646
27918
  var unknownVarDeny = (input, worktree, targets, command) => {
27647
27919
  const refs = [
27648
- ...new Set(targets.flatMap((target) => path40.relative(UNKNOWN_VAR, path40.resolve(target)).split(path40.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
27920
+ ...new Set(targets.flatMap((target) => path42.relative(UNKNOWN_VAR, path42.resolve(target)).split(path42.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
27649
27921
  ];
27650
27922
  let text = command ?? "";
27651
27923
  const first = [];
@@ -27674,10 +27946,10 @@ function confineImplementer(input, targets, command) {
27674
27946
  try {
27675
27947
  if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
27676
27948
  return NONE5;
27677
- const unresolved = targets.filter((target) => within(path40.resolve(target), UNKNOWN_VAR));
27949
+ const unresolved = targets.filter((target) => within(path42.resolve(target), UNKNOWN_VAR));
27678
27950
  if (unresolved.length > 0)
27679
27951
  return unknownVarDeny(input, boundWorktree(input), unresolved, command);
27680
- if (targets.some((target) => within(path40.resolve(target), UNKNOWN_DIR)))
27952
+ if (targets.some((target) => within(path42.resolve(target), UNKNOWN_DIR)))
27681
27953
  return unknownDirDeny(input, boundWorktree(input));
27682
27954
  const bindings = canonical4(bindingDir());
27683
27955
  const judged = targets.map((named) => ({ named, real: canonical4(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
@@ -27787,16 +28059,16 @@ var RUNS = /^(?:sh|bash|zsh|dash|ksh|mksh|ash|python[\d.]*|node|bun|deno|ruby|pe
27787
28059
  var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print|test|version|help)$|^-[hvV]$/;
27788
28060
  var VALUED = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
27789
28061
  var commonDir = (root) => {
27790
- const dotGit = path40.join(root, ".git");
28062
+ const dotGit = path42.join(root, ".git");
27791
28063
  if (!fs28.statSync(dotGit).isFile())
27792
28064
  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);
28065
+ const admin = path42.resolve(root, /^gitdir:\s*(.+)$/mu.exec(fs28.readFileSync(dotGit, "utf8"))?.[1]?.trim() ?? "");
28066
+ const common = path42.join(admin, "commondir");
28067
+ return canonical4(fs28.existsSync(common) ? path42.resolve(admin, fs28.readFileSync(common, "utf8").trim()) : admin);
27796
28068
  };
27797
28069
  var inScratch = (real, repo) => {
27798
28070
  const checkout = checkoutOf2(real);
27799
- return checkout !== null && within(real, path40.join(checkout.root, SCRATCH)) && (repo === null || commonDir(checkout.root) === repo);
28071
+ return checkout !== null && within(real, path42.join(checkout.root, SCRATCH)) && (repo === null || commonDir(checkout.root) === repo);
27800
28072
  };
27801
28073
  var JUDGE_VERBS = {
27802
28074
  check: true,
@@ -27825,7 +28097,7 @@ var judgeVerbRefused = (args) => {
27825
28097
  var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
27826
28098
  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
28099
  var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
27828
- const name = path40.basename(words[0] ?? "").toLowerCase();
28100
+ const name = path42.basename(words[0] ?? "").toLowerCase();
27829
28101
  if (name === "alias")
27830
28102
  return words.flatMap((word) => {
27831
28103
  const set = /^([\w-]+)=(.*)$/s.exec(word);
@@ -27855,11 +28127,11 @@ var judgeRefusal = (command, fed, depth = 0) => {
27855
28127
  return why;
27856
28128
  }
27857
28129
  const { words } = segment;
27858
- const runs = (word = "") => RUNS.test(path40.basename(word).toLowerCase());
28130
+ const runs = (word = "") => RUNS.test(path42.basename(word).toLowerCase());
27859
28131
  let at = 0;
27860
28132
  while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
27861
28133
  at++;
27862
- const name = path40.basename(words[at] ?? "").toLowerCase();
28134
+ const name = path42.basename(words[at] ?? "").toLowerCase();
27863
28135
  const args = words.slice(at + 1);
27864
28136
  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
28137
  if (/^(?:cd|chdir|pushd|popd)$/.test(name))
@@ -27937,7 +28209,7 @@ var substitutingHeredoc = (command) => {
27937
28209
  var judgeDeny = (input, what) => {
27938
28210
  const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
27939
28211
  const root = checkoutOf2(input.cwd)?.root;
27940
- const scratch = root ? path40.join(root, SCRATCH) : `${SCRATCH}/ at the root of the checkout you judge`;
28212
+ const scratch = root ? path42.join(root, SCRATCH) : `${SCRATCH}/ at the root of the checkout you judge`;
27941
28213
  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
28214
  return {
27943
28215
  kind: "deny",
@@ -27952,7 +28224,7 @@ function confineJudge(input, targets) {
27952
28224
  const judged = checkoutOf2(input.cwd);
27953
28225
  const repo = judged ? commonDir(judged.root) : null;
27954
28226
  for (const target of targets) {
27955
- const resolved = path40.resolve(target);
28227
+ const resolved = path42.resolve(target);
27956
28228
  if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
27957
28229
  return judgeDeny(input, "it writes to a path Workit cannot resolve (a variable, a command substitution or `cd -`): spell the path out");
27958
28230
  if (inScratch(canonical4(target), repo))
@@ -27983,7 +28255,7 @@ function confineJudgeShell(input, command, dialect = "posix") {
27983
28255
  let git = [];
27984
28256
  try {
27985
28257
  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`)
28258
+ path42.join(dir === undefined ? UNKNOWN_DIR : path42.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
27987
28259
  ] : []);
27988
28260
  } catch {}
27989
28261
  return confineJudge(input, [
@@ -28028,7 +28300,7 @@ var judgeChecksLine = (cwd) => {
28028
28300
 
28029
28301
  // packages/workit-core/src/hooks/standing.ts
28030
28302
  var readPlans = (store) => {
28031
- const dir = path41.join(store, "fanouts");
28303
+ const dir = path43.join(store, "fanouts");
28032
28304
  let names;
28033
28305
  try {
28034
28306
  names = fs29.readdirSync(dir).filter((name) => name.endsWith(".json"));
@@ -28038,7 +28310,7 @@ var readPlans = (store) => {
28038
28310
  const plans = [];
28039
28311
  for (const name of names) {
28040
28312
  try {
28041
- const raw = JSON.parse(fs29.readFileSync(path41.join(dir, name), "utf8"));
28313
+ const raw = JSON.parse(fs29.readFileSync(path43.join(dir, name), "utf8"));
28042
28314
  if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
28043
28315
  continue;
28044
28316
  const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
@@ -28238,9 +28510,9 @@ var cdWorkitSplit = (command) => {
28238
28510
  };
28239
28511
 
28240
28512
  // 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";
28513
+ import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync5, readSync, statSync as statSync4 } from "node:fs";
28242
28514
  import os11 from "node:os";
28243
- import path42 from "node:path";
28515
+ import path44 from "node:path";
28244
28516
  var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
28245
28517
  var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
28246
28518
  var TIME_WORD = String.raw`(?:\d|(?:in|at|on|later|tomorrow|soon)\b|(?:${[...WEEKDAYS, ...MONTHS].join("|")})[a-z]*\b)`;
@@ -28379,21 +28651,21 @@ var TAIL_BYTES2 = 16384;
28379
28651
  var tail = (file, size) => {
28380
28652
  const length = Math.min(size, TAIL_BYTES2);
28381
28653
  const buffer = Buffer.alloc(length);
28382
- const fd = openSync2(file, "r");
28654
+ const fd = openSync3(file, "r");
28383
28655
  try {
28384
28656
  readSync(fd, buffer, 0, length, size - length);
28385
28657
  } finally {
28386
- closeSync2(fd);
28658
+ closeSync3(fd);
28387
28659
  }
28388
28660
  return buffer.toString("utf8");
28389
28661
  };
28390
28662
  var start = (file) => {
28391
28663
  const buffer = Buffer.alloc(TAIL_BYTES2);
28392
- const fd = openSync2(file, "r");
28664
+ const fd = openSync3(file, "r");
28393
28665
  try {
28394
28666
  return buffer.subarray(0, readSync(fd, buffer, 0, TAIL_BYTES2, 0)).toString("utf8");
28395
28667
  } finally {
28396
- closeSync2(fd);
28668
+ closeSync3(fd);
28397
28669
  }
28398
28670
  };
28399
28671
  var parse5 = (line) => {
@@ -28438,17 +28710,17 @@ var firstPrompt = (file) => {
28438
28710
  var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
28439
28711
  var listDir = (dir) => {
28440
28712
  try {
28441
- return readdirSync4(dir).map((name) => path42.join(dir, name));
28713
+ return readdirSync5(dir).map((name) => path44.join(dir, name));
28442
28714
  } catch {
28443
28715
  return [];
28444
28716
  }
28445
28717
  };
28446
28718
  var SCAN_MS = 30 * 60000;
28447
28719
  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));
28720
+ const projects = path44.join(env.CLAUDE_CONFIG_DIR || path44.join(env.HOME || os11.homedir(), ".claude"), "projects");
28721
+ const project = path44.join(projects, claudeProjectSlug(cwd));
28450
28722
  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 })));
28723
+ 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
28724
  for (const { file, worker } of files)
28453
28725
  try {
28454
28726
  const stat = statSync4(file);
@@ -28463,7 +28735,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
28463
28735
  if (!seen)
28464
28736
  continue;
28465
28737
  notes.push(worker ? redispatchNote(seen, {
28466
- label: `worker ${path42.basename(file, ".jsonl")}`,
28738
+ label: `worker ${path44.basename(file, ".jsonl")}`,
28467
28739
  prompt: firstPrompt(file)
28468
28740
  }, 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
28741
  } catch {}
@@ -28841,12 +29113,12 @@ var modelKey = (model) => {
28841
29113
  };
28842
29114
 
28843
29115
  // packages/workit-core/src/hooks/budget-signal.ts
28844
- import { createHash as createHash19 } from "node:crypto";
29116
+ import { createHash as createHash20 } from "node:crypto";
28845
29117
  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 ?? ""}`));
29118
+ import path45 from "node:path";
29119
+ var hash2 = (text) => createHash20("sha256").update(text).digest("hex").slice(0, 32);
29120
+ var budgetDir = (store) => path45.join(store, "budget");
29121
+ var agentBase = (store, session, agentId) => path45.join(budgetDir(store), hash2(`${session}\x00${agentId ?? ""}`));
28850
29122
  var spawnBudget = (prompt) => {
28851
29123
  const found = /^TIMEBOX:[^\n]*?\b(\d+)\s+tool calls\b/mu.exec(prompt);
28852
29124
  const n = found ? Number(found[1]) : NaN;
@@ -28866,8 +29138,8 @@ var startBudget = (store, session, agentId, n) => {
28866
29138
  const cutoff = Date.now() - 604800000;
28867
29139
  for (const name of fs30.readdirSync(dir))
28868
29140
  try {
28869
- if (fs30.statSync(path43.join(dir, name)).mtimeMs < cutoff)
28870
- fs30.rmSync(path43.join(dir, name));
29141
+ if (fs30.statSync(path45.join(dir, name)).mtimeMs < cutoff)
29142
+ fs30.rmSync(path45.join(dir, name));
28871
29143
  } catch {}
28872
29144
  const base = agentBase(store, session, agentId);
28873
29145
  fs30.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
@@ -29006,11 +29278,11 @@ var unfinishedTaskOffer2 = (ctx) => {
29006
29278
  };
29007
29279
 
29008
29280
  // packages/workit-core/src/hooks/repeat-failure.ts
29009
- import { createHash as createHash20 } from "node:crypto";
29281
+ import { createHash as createHash21 } from "node:crypto";
29010
29282
  var SAME_CALL_FAILED = "Same call failed twice:";
29011
29283
  var MAX_SESSIONS = 256;
29012
29284
  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);
29285
+ var hashOf = (call) => createHash21("sha256").update(call).digest("hex").slice(0, 32);
29014
29286
  var record2 = (memo, sessionId, call, failed, next) => {
29015
29287
  const previous = memo.get(sessionId);
29016
29288
  memo.delete(sessionId);
@@ -29141,6 +29413,68 @@ var hookInput = (ctx, event) => ({
29141
29413
  transcriptPath: null,
29142
29414
  event
29143
29415
  });
29416
+ var APPROVE = "Approve once";
29417
+ var REJECT = "Reject";
29418
+ var EDIT = "Edit";
29419
+ var approveInDialog = async (ids, event, ctx) => {
29420
+ try {
29421
+ const session = hookInput(ctx, { kind: "context.turn" }).session.id || null;
29422
+ const found = ids.map((id) => liveApprovalRequest(id));
29423
+ const shown = found.map((item) => item.ok ? renderApprovalRequest(item.request) : item.reason);
29424
+ const live = found.flatMap((item) => item.ok ? [item.request.id] : []);
29425
+ if (live.length === 0)
29426
+ return { block: true, reason: `Nothing to approve: ${shown.join("; ")}` };
29427
+ const choice = await ctx.ui.select(`Workit asks you to approve:
29428
+ ${shown.join(`
29429
+ `)}`, [
29430
+ APPROVE,
29431
+ REJECT,
29432
+ EDIT
29433
+ ]);
29434
+ if (choice === APPROVE) {
29435
+ const toolUseId = event.toolCallId ?? `pi-${Date.now()}`;
29436
+ recordApprovalAsked({
29437
+ toolUseId,
29438
+ session: session ?? "",
29439
+ host: "pi",
29440
+ ids: live
29441
+ });
29442
+ const recorded = live.filter((id) => recordApprovalGrant({
29443
+ id,
29444
+ host: "pi",
29445
+ session: session ?? "",
29446
+ toolUseId,
29447
+ via: "host"
29448
+ }).ok);
29449
+ return {
29450
+ block: true,
29451
+ 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.`
29452
+ };
29453
+ }
29454
+ if (choice === REJECT || choice === EDIT) {
29455
+ for (const id of live)
29456
+ recordApprovalRejected({
29457
+ id,
29458
+ host: "pi",
29459
+ session,
29460
+ edit: choice === EDIT
29461
+ });
29462
+ return {
29463
+ block: true,
29464
+ 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.`
29465
+ };
29466
+ }
29467
+ return {
29468
+ block: true,
29469
+ reason: `The user dismissed the approval dialog for ${live.join(" ")}: nothing was recorded.`
29470
+ };
29471
+ } catch (error) {
29472
+ return {
29473
+ block: true,
29474
+ reason: `Workit could not record the approval: ${String(error)}`
29475
+ };
29476
+ }
29477
+ };
29144
29478
  var enforceToolPolicy = (event, ctx) => {
29145
29479
  const gate = (hookEvent) => {
29146
29480
  const decision = handleHook(hookInput(ctx, hookEvent), {
@@ -29153,7 +29487,16 @@ var enforceToolPolicy = (event, ctx) => {
29153
29487
  };
29154
29488
  if (event.toolName === "bash") {
29155
29489
  const command = event.input?.command;
29156
- return typeof command === "string" ? gate({ kind: "shell.pre", command, toolUseId: event.toolCallId ?? null }) : undefined;
29490
+ const approve = typeof command === "string" ? approveCallIn(command) : null;
29491
+ if (approve && !approve.plain)
29492
+ return { block: true, reason: approveCallDeny(approve.fix) };
29493
+ if (approve?.plain && ctx.mode === "tui" && ctx.hasUI)
29494
+ return approveInDialog(approve.ids, event, ctx);
29495
+ return typeof command === "string" ? gate({
29496
+ kind: "shell.pre",
29497
+ command,
29498
+ toolUseId: event.toolCallId ?? null
29499
+ }) : undefined;
29157
29500
  }
29158
29501
  if (event.toolName === "read") {
29159
29502
  const file = event.input?.path;
@@ -29198,9 +29541,11 @@ var observeToolResult = (event, ctx) => {
29198
29541
  const role = named === "implementer" ? "implementer" : named ? "judge" : null;
29199
29542
  const nudge = process.env.WORKIT_PI_WORKER_SESSION ? rawGitPre(post, command, { nudge: roleSteering(role, false).nudges }) : shellNudge(post, command);
29200
29543
  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(`
29544
+ return extra.length > 0 ? {
29545
+ content: [...event.content, { type: "text", text: extra.join(`
29202
29546
 
29203
- `) }] } : undefined;
29547
+ `) }]
29548
+ } : undefined;
29204
29549
  } catch {
29205
29550
  return;
29206
29551
  }
@@ -29208,21 +29553,21 @@ var observeToolResult = (event, ctx) => {
29208
29553
  var skillPromptNudge = (prompt, ctx) => process.env.WORKIT_PI_WORKER_SESSION ? null : promptNudge(hookInput(ctx, { kind: "context.turn", prompt }), prompt);
29209
29554
 
29210
29555
  // 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";
29556
+ import { mkdirSync as mkdirSync6, readFileSync as readFileSync10, readdirSync as readdirSync6, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "node:fs";
29212
29557
  import os12 from "node:os";
29213
- import path44 from "node:path";
29558
+ import path46 from "node:path";
29214
29559
  var launchDir = (root) => {
29215
29560
  const location = resolveStore(root);
29216
- return location instanceof Error ? null : path44.join(location.dir, "pi-launches");
29561
+ return location instanceof Error ? null : path46.join(location.dir, "pi-launches");
29217
29562
  };
29218
- var fileFor = (dir, workerId) => path44.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
29563
+ var fileFor = (dir, workerId) => path46.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
29219
29564
  var recordLaunch = (root, attempt) => {
29220
29565
  const dir = launchDir(root);
29221
29566
  if (!dir)
29222
29567
  return false;
29223
29568
  try {
29224
- mkdirSync4(dir, { recursive: true });
29225
- writeFileSync4(fileFor(dir, attempt.workerId), JSON.stringify({
29569
+ mkdirSync6(dir, { recursive: true });
29570
+ writeFileSync5(fileFor(dir, attempt.workerId), JSON.stringify({
29226
29571
  ...attempt,
29227
29572
  pid: process.pid,
29228
29573
  host: os12.hostname(),
@@ -29254,14 +29599,14 @@ var abandonedLaunches = (root) => {
29254
29599
  return [];
29255
29600
  let names;
29256
29601
  try {
29257
- names = readdirSync5(dir);
29602
+ names = readdirSync6(dir);
29258
29603
  } catch {
29259
29604
  return [];
29260
29605
  }
29261
29606
  const found = [];
29262
29607
  for (const name of names) {
29263
29608
  try {
29264
- const attempt = JSON.parse(readFileSync9(path44.join(dir, name), "utf8"));
29609
+ const attempt = JSON.parse(readFileSync10(path46.join(dir, name), "utf8"));
29265
29610
  if (typeof attempt.workerId === "string" && typeof attempt.session === "string") {
29266
29611
  if (!alive(attempt))
29267
29612
  found.push(attempt);
@@ -29273,22 +29618,22 @@ var abandonedLaunches = (root) => {
29273
29618
  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
29619
 
29275
29620
  // 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";
29621
+ import { closeSync as closeSync4, existsSync as existsSync13, openSync as openSync4, readSync as readSync2 } from "node:fs";
29622
+ import path47 from "node:path";
29278
29623
  var LAUNCHER_MARKER = "workit-owned-launcher";
29279
29624
  var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
29280
29625
  var installRoot = (env, platform = process.platform) => {
29281
29626
  if (env.WORKIT_INSTALL_ROOT)
29282
29627
  return env.WORKIT_INSTALL_ROOT;
29283
29628
  const data = dataDir(env, platform);
29284
- return platform === "win32" ? path45.join(data, "install") : data;
29629
+ return platform === "win32" ? path47.join(data, "install") : data;
29285
29630
  };
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");
29631
+ var ownedLauncherPath = (env, platform = process.platform) => path47.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
29632
+ var ownedCurrentEntry = (env, platform = process.platform) => path47.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
29288
29633
  var head = (file) => {
29289
29634
  let fd;
29290
29635
  try {
29291
- fd = openSync3(file, "r");
29636
+ fd = openSync4(file, "r");
29292
29637
  const buffer = Buffer.alloc(256);
29293
29638
  const read = readSync2(fd, buffer, 0, buffer.length, 0);
29294
29639
  return buffer.subarray(0, read).toString("utf8");
@@ -29296,7 +29641,7 @@ var head = (file) => {
29296
29641
  return "";
29297
29642
  } finally {
29298
29643
  if (fd !== undefined)
29299
- closeSync3(fd);
29644
+ closeSync4(fd);
29300
29645
  }
29301
29646
  };
29302
29647
  var locateWorkitCli = (options = {}) => {
@@ -29311,7 +29656,7 @@ var locateWorkitCli = (options = {}) => {
29311
29656
  source: "owned-launcher",
29312
29657
  command: launcher,
29313
29658
  args: [],
29314
- binDir: path45.dirname(launcher)
29659
+ binDir: path47.dirname(launcher)
29315
29660
  };
29316
29661
  const current = ownedCurrentEntry(env, platform);
29317
29662
  if (exists(current))
@@ -29340,7 +29685,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
29340
29685
  if (located.binDir) {
29341
29686
  const key = pathKey(env);
29342
29687
  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);
29688
+ 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
29689
  const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
29345
29690
  patch[key] = [located.binDir, ...rest].join(delimiter);
29346
29691
  }
@@ -29358,7 +29703,7 @@ var useOwnedCliInPi = (env = process.env) => useOwnedWorkitCli({ env });
29358
29703
 
29359
29704
  // packages/workit-pi/src/worker.ts
29360
29705
  import { spawn as nodeSpawn } from "node:child_process";
29361
- import { randomUUID as randomUUID4 } from "node:crypto";
29706
+ import { randomUUID as randomUUID5 } from "node:crypto";
29362
29707
 
29363
29708
  // packages/workit-pi/src/worker-protocol.ts
29364
29709
  var MAX_WORKER_LINE_BYTES = 64 * 1024;
@@ -29486,10 +29831,10 @@ function launchWorker(assignment, options) {
29486
29831
  const nested = Boolean(process.env.WORKIT_PI_WORKER_ID || options.env?.WORKIT_PI_WORKER_ID);
29487
29832
  const taskId = options.taskId ?? null;
29488
29833
  const workerId = options.workerId ?? null;
29489
- const sessionId = options.sessionId ?? "pi-worker-" + randomUUID4();
29834
+ const sessionId = options.sessionId ?? "pi-worker-" + randomUUID5();
29490
29835
  const spec = workerCommand2({ ...options.runtime, sessionId }, assignment);
29491
29836
  const handle = {
29492
- id: randomUUID4(),
29837
+ id: randomUUID5(),
29493
29838
  taskId,
29494
29839
  workerId,
29495
29840
  sessionId,
@@ -30067,7 +30412,7 @@ function extension(pi) {
30067
30412
  workerId: worker.id,
30068
30413
  expectedRevision: task.revision,
30069
30414
  expectedWorkspaceRevision: workspace.revision,
30070
- sessionId: `pi-worker-${worker.id}-${randomUUID5().slice(0, 8)}`
30415
+ sessionId: `pi-worker-${worker.id}-${randomUUID6().slice(0, 8)}`
30071
30416
  };
30072
30417
  const childContext = {
30073
30418
  ...piContext(ctx),