@workit-dev/pi 2.16.2 → 2.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/workit.js CHANGED
@@ -25938,6 +25938,14 @@ var heavyDenial = (original, plan) => ({
25938
25938
  reason: plan.server ? `dev_server: \`${original.trim()}\` starts a dev server (${plan.reason}), which never returns. Start it in the background, owned by this session; run exactly: ${plan.command}` : `heavy_command: \`${original.trim()}\` is heavy (${plan.reason}) and must run under the machine-wide heavy-check lease, so parallel agents cannot exhaust this machine's memory and CPU. Run exactly: ${plan.command}`,
25939
25939
  unblock: plan.command
25940
25940
  });
25941
+ var retryDenial = (gate, what, retry) => ({
25942
+ kind: "deny",
25943
+ reason: `workit ${gate}: ${what}.
25944
+ Retry as: ${retry}
25945
+ Why: Claude Code auto mode refuses a call whose input a hook changed.`,
25946
+ unblock: retry
25947
+ });
25948
+ var autoRouteDenial = (plan) => plan.server ? retryDenial("dev-server", "a dev server never returns, so start it in the background, owned by this session", plan.command) : retryDenial("heavy", "this heavy command runs under the machine-wide heavy-check lease", plan.command);
25941
25949
  var splitDenial = (plan) => ({
25942
25950
  kind: "deny",
25943
25951
  reason: plan.reason,
@@ -30093,7 +30101,7 @@ var standingDelta = (input) => {
30093
30101
  };
30094
30102
  var sinceStart = new Map;
30095
30103
  // packages/workit-core/src/hooks/cwd-normalize.ts
30096
- var DIR = String.raw`[A-Za-z0-9_./@%+:,=-]+|'[^'$${"`"}\\\n]*'|"[^"$${"`"}\\!\n]*"`;
30104
+ var DIR = String.raw`(?:[A-Za-z0-9_./@%+:,=-]|(?<=[A-Za-z0-9])~)+|'[^'$${"`"}\n]*'|"(?:[^"$${"`"}\\!\n]|\\(?=[^"$${"`"}\\!\n]))*"`;
30097
30105
  var COMPOUND2 = new RegExp(String.raw`^\s*cd\s+(${DIR})\s*&&\s*(workit(?:\s[\s\S]*)?)$`, "u");
30098
30106
  var GLOBALS_FIRST = new RegExp(String.raw`^(\s*workit)((?:\s+(?:--json|--cwd(?:=|\s+)(?:${DIR})))+)\s+([a-z][a-z-]*)(?=\s|$)`, "u");
30099
30107
  var VERB_FIRST = /^((?:--json\s+)*)([a-z][a-z-]*)(?=\s|$)/u;
@@ -30178,6 +30186,10 @@ var cdWorkitSplit = (command) => {
30178
30186
  return null;
30179
30187
  };
30180
30188
 
30189
+ // packages/workit-core/src/hooks/spawn-gate.ts
30190
+ import fs31 from "node:fs";
30191
+ import path50 from "node:path";
30192
+
30181
30193
  // packages/workit-core/src/hooks/model-limit.ts
30182
30194
  import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync7, readSync, statSync as statSync5 } from "node:fs";
30183
30195
  import os11 from "node:os";
@@ -30501,20 +30513,37 @@ var agentModelDecision = (cwd, tool, options = {}) => {
30501
30513
 
30502
30514
  // packages/workit-core/src/hooks/spawn-gate.ts
30503
30515
  var MADE_WORKTREE = /^WORKTREE:[ \t]*(?!not made yet)\S(?![^\n]*not made yet)/mu;
30504
- var UNBLOCK = "workit fanout worktree create <slice>";
30505
- var BRIEF = "workit fanout brief <slice>";
30516
+ var namesMade = (word) => {
30517
+ try {
30518
+ const stat = fs31.statSync(word);
30519
+ if (stat.isFile())
30520
+ return stat.size < 1e6 && MADE_WORKTREE.test(fs31.readFileSync(word, "utf8"));
30521
+ const dotGit = path50.join(word, ".git");
30522
+ const link = fs31.statSync(dotGit);
30523
+ const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(fs31.readFileSync(dotGit, "utf8"));
30524
+ return !!admin && fs31.existsSync(path50.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
30525
+ } catch {
30526
+ return false;
30527
+ }
30528
+ };
30529
+ var namesWorktree = (prompt) => MADE_WORKTREE.test(prompt) || (prompt.match(/(?<![\w.~])(?:[a-z]:[\\/]|\/)[^\s'"`<>|;,()]+/giu) ?? []).some((word) => namesMade(word.replace(/[.:]+$/u, "")));
30530
+ var sliceWord = (tool) => (/(?:\bfanout brief|\bworktree create|\bWORKER:) +([a-z0-9][\w.-]*)/iu.exec(String(tool.prompt))?.[1] ?? String(tool.description ?? "")).toLowerCase().replace(/[^a-z0-9._-]+/gu, "-").replace(/^[-._]+|-+$/gu, "").slice(0, 40) || "slice";
30506
30531
  var gate = (descriptor, tool) => {
30507
30532
  const type = typeof tool.subagent_type === "string" ? tool.subagent_type : "";
30508
30533
  const implementer = workitRole(descriptor, type) === "implementer";
30509
- if (implementer && (typeof tool.prompt !== "string" || !MADE_WORKTREE.test(tool.prompt)))
30534
+ if (implementer && (typeof tool.prompt !== "string" || !namesWorktree(tool.prompt))) {
30535
+ const slice = sliceWord(tool);
30536
+ const unblock = `workit fanout worktree create ${slice}`;
30510
30537
  return {
30511
30538
  kind: "deny",
30512
30539
  decision: {
30513
30540
  kind: "deny",
30514
- reason: `workit spawn gate: a ${type} spawn needs a Workit brief with a WORKTREE line, and this prompt has none. Even for one slice: run \`${UNBLOCK}\`, then \`${BRIEF}\`, and spawn again with its text as the prompt and the Agent args its SPAWN line names (a slice no plan registers needs \`workit fanout plan <plan.json>\` first).`,
30515
- unblock: UNBLOCK
30541
+ reason: `workit spawn gate: this ${type} prompt names no worktree Workit made.
30542
+ Retry as: ${unblock} (or --name <plan> for a planned slice), then spawn again with the WORKTREE line it prints as the prompt's first line.`,
30543
+ unblock
30516
30544
  }
30517
30545
  };
30546
+ }
30518
30547
  if (tool.isolation === undefined)
30519
30548
  return { kind: "run", input: tool, change: { dropped: [], reasons: [], notes: [] } };
30520
30549
  const { isolation: _dropped, ...input } = tool;
@@ -30537,9 +30566,9 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
30537
30566
  };
30538
30567
 
30539
30568
  // packages/workit-core/src/hooks/server-gate.ts
30540
- import fs31 from "node:fs";
30541
- import path50 from "node:path";
30542
- var procNoticeFile = (env, session) => path50.join(stateDir(env), "procs", "notices", `${session.replace(/[^A-Za-z0-9_.@+-]/gu, "-").slice(0, 120) || "none"}.json`);
30569
+ import fs32 from "node:fs";
30570
+ import path51 from "node:path";
30571
+ var procNoticeFile = (env, session) => path51.join(stateDir(env), "procs", "notices", `${session.replace(/[^A-Za-z0-9_.@+-]/gu, "-").slice(0, 120) || "none"}.json`);
30543
30572
  var mb = (bytes) => `${Math.round(Number(bytes) / 1048576)} MB`;
30544
30573
  function takeProcNotice(session, env = process.env) {
30545
30574
  if (!session)
@@ -30547,12 +30576,12 @@ function takeProcNotice(session, env = process.env) {
30547
30576
  const file = procNoticeFile(env, session);
30548
30577
  const taken = `${file}.${process.pid}.taken`;
30549
30578
  try {
30550
- fs31.renameSync(file, taken);
30579
+ fs32.renameSync(file, taken);
30551
30580
  } catch {
30552
30581
  return null;
30553
30582
  }
30554
30583
  try {
30555
- const { notices } = JSON.parse(fs31.readFileSync(taken, "utf8"));
30584
+ const { notices } = JSON.parse(fs32.readFileSync(taken, "utf8"));
30556
30585
  const lines = (Array.isArray(notices) ? notices : []).flatMap((notice) => {
30557
30586
  if (!notice || typeof notice !== "object")
30558
30587
  return [];
@@ -30569,29 +30598,29 @@ function takeProcNotice(session, env = process.env) {
30569
30598
  return null;
30570
30599
  } finally {
30571
30600
  try {
30572
- fs31.rmSync(taken, { force: true });
30601
+ fs32.rmSync(taken, { force: true });
30573
30602
  } catch {}
30574
30603
  }
30575
30604
  }
30576
30605
 
30577
30606
  // packages/workit-core/src/hooks/teardown.ts
30578
30607
  import { spawn } from "node:child_process";
30579
- import fs32 from "node:fs";
30580
- import path52 from "node:path";
30608
+ import fs33 from "node:fs";
30609
+ import path53 from "node:path";
30581
30610
 
30582
30611
  // packages/workit-core/src/core/cli-locate.ts
30583
30612
  import { closeSync as closeSync5, existsSync as existsSync17, openSync as openSync5, readSync as readSync2 } from "node:fs";
30584
- import path51 from "node:path";
30613
+ import path52 from "node:path";
30585
30614
  var LAUNCHER_MARKER = "workit-owned-launcher";
30586
30615
  var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
30587
30616
  var installRoot = (env, platform = process.platform) => {
30588
30617
  if (env.WORKIT_INSTALL_ROOT)
30589
30618
  return env.WORKIT_INSTALL_ROOT;
30590
30619
  const data = dataDir(env, platform);
30591
- return platform === "win32" ? path51.join(data, "install") : data;
30620
+ return platform === "win32" ? path52.join(data, "install") : data;
30592
30621
  };
30593
- var ownedLauncherPath = (env, platform = process.platform) => path51.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
30594
- var ownedCurrentEntry = (env, platform = process.platform) => path51.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
30622
+ var ownedLauncherPath = (env, platform = process.platform) => path52.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
30623
+ var ownedCurrentEntry = (env, platform = process.platform) => path52.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
30595
30624
  var head = (file) => {
30596
30625
  let fd;
30597
30626
  try {
@@ -30618,7 +30647,7 @@ var locateWorkitCli = (options = {}) => {
30618
30647
  source: "owned-launcher",
30619
30648
  command: launcher,
30620
30649
  args: [],
30621
- binDir: path51.dirname(launcher)
30650
+ binDir: path52.dirname(launcher)
30622
30651
  };
30623
30652
  const current = ownedCurrentEntry(env, platform);
30624
30653
  if (exists(current))
@@ -30647,7 +30676,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
30647
30676
  if (located.binDir) {
30648
30677
  const key = pathKey(env);
30649
30678
  const delimiter = platform === "win32" ? ";" : ":";
30650
- const same = (dir) => platform === "win32" ? path51.win32.normalize(dir).toLowerCase() === path51.win32.normalize(located.binDir).toLowerCase() : path51.posix.normalize(dir) === path51.posix.normalize(located.binDir);
30679
+ const same = (dir) => platform === "win32" ? path52.win32.normalize(dir).toLowerCase() === path52.win32.normalize(located.binDir).toLowerCase() : path52.posix.normalize(dir) === path52.posix.normalize(located.binDir);
30651
30680
  const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
30652
30681
  patch[key] = [located.binDir, ...rest].join(delimiter);
30653
30682
  }
@@ -30671,9 +30700,9 @@ var ENDS = {
30671
30700
  };
30672
30701
  var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
30673
30702
  var HOST_SESSION_VARS2 = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
30674
- var teardownDir = (env) => path52.join(stateDir(env), "procs");
30675
- var teardownLog = (env) => path52.join(teardownDir(env), "teardown.log");
30676
- var reapStamp = (env) => path52.join(teardownDir(env), "reap-at-start.stamp");
30703
+ var teardownDir = (env) => path53.join(stateDir(env), "procs");
30704
+ var teardownLog = (env) => path53.join(teardownDir(env), "teardown.log");
30705
+ var reapStamp = (env) => path53.join(teardownDir(env), "reap-at-start.stamp");
30677
30706
  function spawnDetached(request) {
30678
30707
  try {
30679
30708
  const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
@@ -30700,13 +30729,13 @@ var teardownDeps = {
30700
30729
  var openLog = (env, args) => {
30701
30730
  try {
30702
30731
  const file = teardownLog(env);
30703
- fs32.mkdirSync(path52.dirname(file), { recursive: true });
30732
+ fs33.mkdirSync(path53.dirname(file), { recursive: true });
30704
30733
  let size = 0;
30705
30734
  try {
30706
- size = fs32.statSync(file).size;
30735
+ size = fs33.statSync(file).size;
30707
30736
  } catch {}
30708
- const fd = fs32.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
30709
- fs32.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
30737
+ const fd = fs33.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
30738
+ fs33.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
30710
30739
  `);
30711
30740
  return fd;
30712
30741
  } catch {
@@ -30718,7 +30747,7 @@ function runCli(args, env) {
30718
30747
  try {
30719
30748
  const cli = locateWorkitCli({ env });
30720
30749
  const cwd = teardownDir(env);
30721
- fs32.mkdirSync(cwd, { recursive: true });
30750
+ fs33.mkdirSync(cwd, { recursive: true });
30722
30751
  log = openLog(env, args);
30723
30752
  const started = teardownDeps.spawn({
30724
30753
  command: cli.command,
@@ -30728,7 +30757,7 @@ function runCli(args, env) {
30728
30757
  log
30729
30758
  });
30730
30759
  if (!started && log !== null)
30731
- fs32.writeSync(log, ` not started
30760
+ fs33.writeSync(log, ` not started
30732
30761
  `);
30733
30762
  return started;
30734
30763
  } catch {
@@ -30736,7 +30765,7 @@ function runCli(args, env) {
30736
30765
  } finally {
30737
30766
  if (log !== null)
30738
30767
  try {
30739
- fs32.closeSync(log);
30768
+ fs33.closeSync(log);
30740
30769
  } catch {}
30741
30770
  }
30742
30771
  }
@@ -30755,24 +30784,24 @@ function endSession(end, env = process.env) {
30755
30784
  var claim2 = (file, now) => {
30756
30785
  for (let attempt = 0;attempt < 2; attempt += 1)
30757
30786
  try {
30758
- fs32.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
30787
+ fs33.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
30759
30788
  return true;
30760
30789
  } catch (error) {
30761
30790
  if (error.code !== "EEXIST")
30762
30791
  return false;
30763
30792
  let held = Number.NaN;
30764
30793
  try {
30765
- held = Number(fs32.readFileSync(file, "utf8"));
30794
+ held = Number(fs33.readFileSync(file, "utf8"));
30766
30795
  } catch {}
30767
30796
  if (now - held < REAP_INTERVAL_MS)
30768
30797
  return false;
30769
- fs32.rmSync(file, { force: true });
30798
+ fs33.rmSync(file, { force: true });
30770
30799
  }
30771
30800
  return false;
30772
30801
  };
30773
30802
  var fresh = (stamp, now) => {
30774
30803
  try {
30775
- const last = Number(fs32.readFileSync(stamp, "utf8"));
30804
+ const last = Number(fs33.readFileSync(stamp, "utf8"));
30776
30805
  return now - last < REAP_INTERVAL_MS && last <= now;
30777
30806
  } catch {
30778
30807
  return false;
@@ -30785,7 +30814,7 @@ function reapAtStart(_cwd, env = process.env) {
30785
30814
  try {
30786
30815
  if (fresh(stamp, now))
30787
30816
  return false;
30788
- fs32.mkdirSync(path52.dirname(stamp), { recursive: true });
30817
+ fs33.mkdirSync(path53.dirname(stamp), { recursive: true });
30789
30818
  if (!claim2(lock, now))
30790
30819
  return false;
30791
30820
  } catch {
@@ -30798,12 +30827,12 @@ function reapAtStart(_cwd, env = process.env) {
30798
30827
  started = runCli(["stop", "--orphans", "--reason", "session-start"], env);
30799
30828
  if (started) {
30800
30829
  const temp = `${stamp}.${process.pid}`;
30801
- fs32.writeFileSync(temp, String(now), { mode: 384 });
30802
- fs32.renameSync(temp, stamp);
30830
+ fs33.writeFileSync(temp, String(now), { mode: 384 });
30831
+ fs33.renameSync(temp, stamp);
30803
30832
  }
30804
30833
  } catch {} finally {
30805
30834
  try {
30806
- fs32.rmSync(lock, { force: true });
30835
+ fs33.rmSync(lock, { force: true });
30807
30836
  } catch {}
30808
30837
  }
30809
30838
  return started;
@@ -31406,6 +31435,7 @@ function decide(input, deps) {
31406
31435
  return withContextLine(text ? { kind: "context", text } : NONE6, promptNudge(input, event.prompt));
31407
31436
  }
31408
31437
  case "shell.pre": {
31438
+ const auto = input.host === "claude_code" && input.permissionMode === "auto";
31409
31439
  const npx = npxWorkit(event.command);
31410
31440
  if (npx && workitOnPath2()) {
31411
31441
  const canDeny = usable2(descriptor.shellPolicy.deny);
@@ -31417,6 +31447,8 @@ function decide(input, deps) {
31417
31447
  const plain = decide({ ...input, event: { ...event, command: npx } }, deps);
31418
31448
  if (plain.kind !== "none" && plain.kind !== "context")
31419
31449
  return plain;
31450
+ if (auto && canDeny)
31451
+ return retryDenial("npx", "workit is on PATH, so run it directly", npx);
31420
31452
  if (usable2(descriptor.shellPolicy.rewrite))
31421
31453
  return {
31422
31454
  kind: "rewrite",
@@ -31485,8 +31517,10 @@ function decide(input, deps) {
31485
31517
  const rewrites = usable2(descriptor.shellPolicy.rewrite);
31486
31518
  if (plan.kind === "rewrite" && !rewrites && canDeny)
31487
31519
  return heavyDenial(event.command, plan);
31520
+ if (plan.kind === "rewrite" && auto && canDeny)
31521
+ return autoRouteDenial(plan);
31488
31522
  const lease = plan.kind === "rewrite" && rewrites ? plan : null;
31489
- const cwdCommand = !lease && rewrites && input.host === "claude_code" ? cwdRewrite(event.command) ?? verbFirst(event.command) : null;
31523
+ const cwdCommand = !lease && rewrites && input.host === "claude_code" ? cwdRewrite(event.command) ?? (auto ? null : verbFirst(event.command)) : null;
31490
31524
  const aside = plan.kind === "passthrough" ? plan.note : null;
31491
31525
  noteRawCommit(input, event.command, postTool ? callKey(event.toolUseId, event.command) : NEXT_COMMAND);
31492
31526
  const bypass = !lease && input.host === "claude_code" ? workitBypassFlag(event.command, event.dialect) : null;
@@ -31507,8 +31541,11 @@ function decide(input, deps) {
31507
31541
  });
31508
31542
  const nudge = canDeny ? rawGitPre(input, event.command, { nudge: nudges }) : NONE6;
31509
31543
  const nudged = withContextLine(withContextLine(nudge, aside), shipNudge(input, event.command));
31510
- if (!lease)
31511
- return cwdCommand && nudged.kind !== "deny" ? rewritten(nudged.kind === "context" ? nudged.text : null) : nudged;
31544
+ if (!lease) {
31545
+ if (!cwdCommand || nudged.kind === "deny")
31546
+ return nudged;
31547
+ return auto ? retryDenial("cwd", "run one verb per call with --cwd", cwdCommand) : rewritten(nudged.kind === "context" ? nudged.text : null);
31548
+ }
31512
31549
  return rewritten([rewriteNote(lease), nudged.kind === "context" ? nudged.text : null].filter(Boolean).join(`
31513
31550
  `));
31514
31551
  }
@@ -31600,11 +31637,11 @@ var modelKey = (model) => {
31600
31637
 
31601
31638
  // packages/workit-core/src/hooks/budget-signal.ts
31602
31639
  import { createHash as createHash23 } from "node:crypto";
31603
- import fs33 from "node:fs";
31604
- import path53 from "node:path";
31640
+ import fs34 from "node:fs";
31641
+ import path54 from "node:path";
31605
31642
  var hash2 = (text) => createHash23("sha256").update(text).digest("hex").slice(0, 32);
31606
- var budgetDir = (store) => path53.join(store, "budget");
31607
- var agentBase = (store, session, agentId) => path53.join(budgetDir(store), hash2(`${session}\x00${agentId ?? ""}`));
31643
+ var budgetDir = (store) => path54.join(store, "budget");
31644
+ var agentBase = (store, session, agentId) => path54.join(budgetDir(store), hash2(`${session}\x00${agentId ?? ""}`));
31608
31645
  var spawnBudget = (prompt) => {
31609
31646
  const found = /^TIMEBOX:[^\n]*?\b(\d+)\s+tool calls\b/mu.exec(prompt);
31610
31647
  const n = found ? Number(found[1]) : NaN;
@@ -31612,7 +31649,7 @@ var spawnBudget = (prompt) => {
31612
31649
  };
31613
31650
  var readBudget = (file) => {
31614
31651
  try {
31615
- const { limit, told } = JSON.parse(fs33.readFileSync(file, "utf8"));
31652
+ const { limit, told } = JSON.parse(fs34.readFileSync(file, "utf8"));
31616
31653
  return typeof limit === "number" && limit > 0 ? { limit, told: Number(told) || 0 } : null;
31617
31654
  } catch {
31618
31655
  return null;
@@ -31620,16 +31657,16 @@ var readBudget = (file) => {
31620
31657
  };
31621
31658
  var startBudget = (store, session, agentId, n) => {
31622
31659
  const dir = budgetDir(store);
31623
- fs33.mkdirSync(dir, { recursive: true });
31660
+ fs34.mkdirSync(dir, { recursive: true });
31624
31661
  const cutoff = Date.now() - 604800000;
31625
- for (const name of fs33.readdirSync(dir))
31662
+ for (const name of fs34.readdirSync(dir))
31626
31663
  try {
31627
- if (fs33.statSync(path53.join(dir, name)).mtimeMs < cutoff)
31628
- fs33.rmSync(path53.join(dir, name));
31664
+ if (fs34.statSync(path54.join(dir, name)).mtimeMs < cutoff)
31665
+ fs34.rmSync(path54.join(dir, name));
31629
31666
  } catch {}
31630
31667
  const base = agentBase(store, session, agentId);
31631
- fs33.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
31632
- fs33.rmSync(`${base}.calls`, { force: true });
31668
+ fs34.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
31669
+ fs34.rmSync(`${base}.calls`, { force: true });
31633
31670
  };
31634
31671
  var bindBudget = (cwd, session, agentId, prompt) => {
31635
31672
  try {
@@ -31652,8 +31689,8 @@ var tickBudget = (cwd, session, agentId) => {
31652
31689
  const budget = readBudget(`${base}.json`);
31653
31690
  if (!budget)
31654
31691
  return false;
31655
- fs33.appendFileSync(`${base}.calls`, ".");
31656
- return fs33.statSync(`${base}.calls`).size >= budget.limit * (budget.told + 1);
31692
+ fs34.appendFileSync(`${base}.calls`, ".");
31693
+ return fs34.statSync(`${base}.calls`).size >= budget.limit * (budget.told + 1);
31657
31694
  } catch {
31658
31695
  return false;
31659
31696
  }
@@ -31665,14 +31702,14 @@ var reachedOf = (cwd, session, agentId) => {
31665
31702
  const budget = base && readBudget(`${base}.json`);
31666
31703
  if (!budget)
31667
31704
  return null;
31668
- return { base, budget, reached: Math.floor(fs33.statSync(`${base}.calls`).size / budget.limit) };
31705
+ return { base, budget, reached: Math.floor(fs34.statSync(`${base}.calls`).size / budget.limit) };
31669
31706
  };
31670
31707
  var budgetLine = (cwd, session, agentId) => {
31671
31708
  try {
31672
31709
  const at = reachedOf(cwd, session, agentId);
31673
31710
  if (!at || at.reached <= at.budget.told)
31674
31711
  return null;
31675
- fs33.writeFileSync(`${at.base}.json`, JSON.stringify({ ...at.budget, told: at.reached }));
31712
+ fs34.writeFileSync(`${at.base}.json`, JSON.stringify({ ...at.budget, told: at.reached }));
31676
31713
  return lineFor(at.budget.limit * at.reached);
31677
31714
  } catch {
31678
31715
  return null;
@@ -32080,12 +32117,12 @@ var skillPromptNudge = (prompt, ctx) => process.env.WORKIT_PI_WORKER_SESSION ? n
32080
32117
  // packages/workit-pi/src/launches.ts
32081
32118
  import { mkdirSync as mkdirSync7, readFileSync as readFileSync16, readdirSync as readdirSync8, rmSync as rmSync4, writeFileSync as writeFileSync6 } from "node:fs";
32082
32119
  import os12 from "node:os";
32083
- import path54 from "node:path";
32120
+ import path55 from "node:path";
32084
32121
  var launchDir = (root) => {
32085
32122
  const location = resolveStore(root);
32086
- return location instanceof Error ? null : path54.join(location.dir, "pi-launches");
32123
+ return location instanceof Error ? null : path55.join(location.dir, "pi-launches");
32087
32124
  };
32088
- var fileFor = (dir, workerId) => path54.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
32125
+ var fileFor = (dir, workerId) => path55.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
32089
32126
  var recordLaunch = (root, attempt) => {
32090
32127
  const dir = launchDir(root);
32091
32128
  if (!dir)
@@ -32131,7 +32168,7 @@ var abandonedLaunches = (root) => {
32131
32168
  const found = [];
32132
32169
  for (const name of names) {
32133
32170
  try {
32134
- const attempt = JSON.parse(readFileSync16(path54.join(dir, name), "utf8"));
32171
+ const attempt = JSON.parse(readFileSync16(path55.join(dir, name), "utf8"));
32135
32172
  if (typeof attempt.workerId === "string" && typeof attempt.session === "string") {
32136
32173
  if (!alive(attempt))
32137
32174
  found.push(attempt);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/pi",
3
- "version": "2.16.2",
3
+ "version": "2.17.1",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",
@@ -20,16 +20,15 @@ units of ~100+ lines each. Coupled work stays with one owner. Workit never spawn
20
20
  PR (`references/orchestration.md`).
21
21
  2. **Record standing orders** (`workit ledger standing add "<order>"`): every
22
22
  user directive all workers share. Directives decay across resumes.
23
- 3. **Brief each worker verbatim**: `workit fanout worktree create <slice>`
24
- (every host), then `workit fanout brief <slice>` (WORKTREE, SCRATCH, rules).
25
- Never hand-edit it; change the plan or the standing orders and render again.
23
+ 3. **Make the worktrees**: `workit fanout worktree create <slice>…` (every host; `--name <plan.json>`
24
+ registers the file) prints per slice its `WORKTREE:` line and the exact spawn, whose prompt points
25
+ the worker at `workit fanout brief <slice> --name <plan>`. Never hand-edit it; change the plan or
26
+ the standing orders. One unplanned slice needs no plan (`--branch <b>` optional).
26
27
  4. **Spawn in a rolling window**, in the background, each in its own worktree:
27
- keep 4-6 in flight and refill from `spawnable` in `workit fanout status` as
28
- each one finishes. Assign before spawn (OpenCode: `workit worker assign`); each prompt carries
29
- the brief, or a pointer: its `WORKER`, `TIER`, `TIMEBOX` and `WORKTREE` lines plus "run `workit fanout brief <slice>` and follow it"
30
- (budget and model hooks read those lines), so batched OpenCode launches each bind their worker.
31
- Model: the brief's `model:` and `effort:` lines (`workit models show`), else TIER (`references/orchestration.md`).
32
- Claude Code: the `implementer` agent; its spawn hook drops `isolation` and refuses a prompt without a WORKTREE line.
28
+ keep 4-6 in flight and refill from `spawnable` in `workit fanout status`.
29
+ Assign before spawn (OpenCode: `workit worker assign`); each prompt is the printed one
30
+ (budget and model hooks read its WORKTREE, WORKER, TIER and TIMEBOX lines), so batched OpenCode launches each bind their worker.
31
+ Claude Code: copy the printed `SPAWN:` args (a model only when the TIER differs from the agent file); the hook drops `isolation` and refuses a prompt naming no Workit worktree with a `Retry as:`.
33
32
  5. **Judge liveness by side effects only:** `workit fanout status` (head age,
34
33
  PR, CI, verdict, landed; STUCK past the TIMEBOX). Stop a stuck worker and
35
34
  observe that it exited (a timeout is not proof); stop a finished one when its
@@ -103,6 +103,27 @@ is the slice's STUCK threshold in `workit fanout status`. `"fanIn":
103
103
  }
104
104
  ```
105
105
 
106
+ ## Worktrees and the spawn they print
107
+
108
+ `workit fanout worktree create a b c` makes each slice's worktree and prints,
109
+ per slice, `WORKTREE: <path>` and the spawn that carries it. Its prompt starts
110
+ with that WORKTREE line, then `WORKER`, `TIER`, `TIMEBOX` and
111
+ "Run `workit fanout brief <slice> --name <plan>` and follow it exactly.";
112
+ Claude Code's `SPAWN:` line names `model` only when the TIER differs from the
113
+ `implementer` agent file. `--name` takes the plan's name or its file (`--plan`
114
+ is the same flag): a file is registered in that call, and a name no plan has
115
+ registers the one file in `workit dir plans` that starts with it. The plan
116
+ check refuses a slice branch the workspace branch policy refuses and names the
117
+ allowed one.
118
+
119
+ One unplanned slice: `workit fanout worktree create fix-login [--branch
120
+ fix/login] [--base <b>] [--tier <t>]` (no plan holds it) records a one-slice plan named after it
121
+ (the lead's prompt states the task) and prints the same lines; two or more
122
+ slices need a plan file. Claude Code's spawn gate passes a
123
+ `workit:implementer` prompt that names a Workit-made worktree as a WORKTREE
124
+ line, as its path, or as a brief file holding a WORKTREE line; otherwise its
125
+ deny is two lines ending in that ad-hoc command as `Retry as:`.
126
+
106
127
  ## Identity and git rules per host
107
128
 
108
129
  `workit fanout brief` renders the identity line, the model lines and RULES 1