@workit-dev/pi 2.16.1 → 2.17.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
|
@@ -8435,6 +8435,9 @@ function resolveRef(cwd, ref) {
|
|
|
8435
8435
|
function originHeadRef(cwd) {
|
|
8436
8436
|
return line(git(cwd, ["symbolic-ref", "-q", "--short", "refs/remotes/origin/HEAD"]));
|
|
8437
8437
|
}
|
|
8438
|
+
function worktreeTop(cwd) {
|
|
8439
|
+
return gitDirs(cwd)?.top ?? null;
|
|
8440
|
+
}
|
|
8438
8441
|
function ownChangeDrift(cwd, range) {
|
|
8439
8442
|
const before = diffRaw(cwd, range.fromFork, range.from);
|
|
8440
8443
|
const after = diffRaw(cwd, range.toFork, range.to);
|
|
@@ -11114,10 +11117,12 @@ function judgeBranch(cwd) {
|
|
|
11114
11117
|
const branch = currentBranch(cwd);
|
|
11115
11118
|
return branch && !isProtectedTarget(cwd, branch) ? branch : null;
|
|
11116
11119
|
}
|
|
11120
|
+
var shellQuote = (value) => /^[\w@%+=:,./-]+$/u.test(value) ? value : `'${value.replaceAll("'", `'\\''`)}'`;
|
|
11117
11121
|
function verdictCommand(options) {
|
|
11118
11122
|
const kind = options.judge === "verifier" ? "<live|unit>" : options.judge === "reviewer" ? "review" : "<live|unit|review>";
|
|
11119
11123
|
return [
|
|
11120
11124
|
"workit ledger verdict <verified|failed|blocked>",
|
|
11125
|
+
options.cwd ? `--cwd ${shellQuote(options.cwd)}` : null,
|
|
11121
11126
|
`--kind ${kind}`,
|
|
11122
11127
|
`--branch ${options.branch ?? "<branch>"}`,
|
|
11123
11128
|
options.session ? `--session ${options.session}` : null,
|
|
@@ -20693,9 +20698,9 @@ var autocorrected = (name, config) => {
|
|
|
20693
20698
|
}
|
|
20694
20699
|
return tie ? null : best;
|
|
20695
20700
|
};
|
|
20696
|
-
var
|
|
20701
|
+
var shellQuote2 = (word) => `'${word.replaceAll("'", "'\\''")}'`;
|
|
20697
20702
|
var positional = (script, args) => {
|
|
20698
|
-
const word = (arg) => /^[\w./@+:=-]+$/.test(arg) ? arg :
|
|
20703
|
+
const word = (arg) => /^[\w./@+:=-]+$/.test(arg) ? arg : shellQuote2(arg);
|
|
20699
20704
|
return script.replace(/\$\{?([1-9])\}?/g, (_, n) => word(args[Number(n) - 1] ?? "")).replace(/\$\{?[@*]\}?/g, args.map(word).join(" "));
|
|
20700
20705
|
};
|
|
20701
20706
|
var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
|
|
@@ -20712,7 +20717,7 @@ var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
|
|
|
20712
20717
|
return corrected ? [{ ...invocation, args: [corrected, ...invocation.args.slice(1)] }] : [invocation];
|
|
20713
20718
|
}
|
|
20714
20719
|
const rest = invocation.args.slice(1);
|
|
20715
|
-
const expanded = alias.startsWith("!") ? rawInvocations([positional(alias.slice(1), rest), ...rest.map(
|
|
20720
|
+
const expanded = alias.startsWith("!") ? rawInvocations([positional(alias.slice(1), rest), ...rest.map(shellQuote2)].join(" ")).map((inner) => ({
|
|
20716
20721
|
...inner,
|
|
20717
20722
|
dir: rebase(invocation.dir, inner.dir),
|
|
20718
20723
|
...inner.tool === "git" && (invocation.config || inner.config) ? { config: [...invocation.config ?? [], ...inner.config ?? []] } : {},
|
|
@@ -21039,7 +21044,7 @@ var policyDeclared = () => {
|
|
|
21039
21044
|
return false;
|
|
21040
21045
|
}
|
|
21041
21046
|
};
|
|
21042
|
-
var word = (text) => /^[\w./@%+:,=-]+$/u.test(text) ? text :
|
|
21047
|
+
var word = (text) => /^[\w./@%+:,=-]+$/u.test(text) ? text : shellQuote2(text);
|
|
21043
21048
|
var HEREDOC = /^cat <<(['"])(\w+)\1\n([\s\S]*)\n\2\n?$/u;
|
|
21044
21049
|
var messageOf = (segment, index) => {
|
|
21045
21050
|
const text = segment.words[index];
|
|
@@ -21123,7 +21128,7 @@ var cdCommitCall = (input, command, target, repo) => {
|
|
|
21123
21128
|
}
|
|
21124
21129
|
return [
|
|
21125
21130
|
`workit git --cwd ${word(target)} commit`,
|
|
21126
|
-
...messages.map((message) => `-m ${
|
|
21131
|
+
...messages.map((message) => `-m ${shellQuote2(message)}`),
|
|
21127
21132
|
...allowEmpty ? ["--allow-empty"] : [],
|
|
21128
21133
|
all ? "--all" : `-- ${[...new Set(paths)].map(word).join(" ")}`
|
|
21129
21134
|
].join(" ");
|
|
@@ -24983,6 +24988,7 @@ var workitBypassFlag = (command, dialect = "posix") => {
|
|
|
24983
24988
|
}
|
|
24984
24989
|
return null;
|
|
24985
24990
|
};
|
|
24991
|
+
var helpOnly = (call, needle) => call.length > needle.length && needle.every((word, index) => call[index] === word) && call.slice(needle.length).every((word) => word === "--help" || word === "-h");
|
|
24986
24992
|
var userOnlyWorkitCall = (command, dialect = "posix") => {
|
|
24987
24993
|
if (!mayRunUserOnly(command))
|
|
24988
24994
|
return null;
|
|
@@ -25009,7 +25015,7 @@ var userOnlyWorkitCall = (command, dialect = "posix") => {
|
|
|
25009
25015
|
}
|
|
25010
25016
|
const call = args.slice(at);
|
|
25011
25017
|
const found = WORKIT_USER_ONLY.find((needle) => call[0] === needle[0] && hasWordsInOrder(call, needle));
|
|
25012
|
-
if (found)
|
|
25018
|
+
if (found && !helpOnly(call, found))
|
|
25013
25019
|
return [...found];
|
|
25014
25020
|
}
|
|
25015
25021
|
return null;
|
|
@@ -28558,6 +28564,8 @@ var cwdOf = (globals) => {
|
|
|
28558
28564
|
return cwd;
|
|
28559
28565
|
};
|
|
28560
28566
|
var inlineCallCwd = (call, base) => call.cwd ? path46.resolve(base, call.cwd) : base;
|
|
28567
|
+
var isReadFilter = (segment) => (segment.words[0] === "tail" || segment.words[0] === "head") && segment.words.slice(1).every((word) => /^(?:-[nc]|-[nc]?\d+|\+?\d+)$/u.test(word)) && !segment.redirects.length && !segment.subs?.length && !segment.stdin?.length && !segment.inputs?.length && !segment.expands?.length && !segment.group && !segment.unanalyzable;
|
|
28568
|
+
var onlyFiltersAfter = (segments) => segments[0]?.pipe === true && segments.slice(1).every((segment, index, rest) => isReadFilter(segment) && (index === rest.length - 1 ? !segment.pipe : segment.pipe));
|
|
28561
28569
|
var inlineCallIn = (command, dialect = "posix") => {
|
|
28562
28570
|
if (!/\bworkit\b/u.test(command))
|
|
28563
28571
|
return null;
|
|
@@ -28576,7 +28584,7 @@ var inlineCallIn = (command, dialect = "posix") => {
|
|
|
28576
28584
|
const call = words.slice(at);
|
|
28577
28585
|
if (!asked(call))
|
|
28578
28586
|
continue;
|
|
28579
|
-
const plain = segments.length === 1 && start === 0 && words[0] === "workit" && !segment.redirects.length && !segment.subs?.length && !segment.stdin?.length && !segment.expands?.length && !segment.group;
|
|
28587
|
+
const plain = (segments.length === 1 || segment === segments[0] && onlyFiltersAfter(segments)) && start === 0 && words[0] === "workit" && !segment.redirects.length && !segment.subs?.length && !segment.stdin?.length && !segment.expands?.length && !segment.group;
|
|
28580
28588
|
if (plain)
|
|
28581
28589
|
return {
|
|
28582
28590
|
plain: true,
|
|
@@ -30170,6 +30178,10 @@ var cdWorkitSplit = (command) => {
|
|
|
30170
30178
|
return null;
|
|
30171
30179
|
};
|
|
30172
30180
|
|
|
30181
|
+
// packages/workit-core/src/hooks/spawn-gate.ts
|
|
30182
|
+
import fs31 from "node:fs";
|
|
30183
|
+
import path50 from "node:path";
|
|
30184
|
+
|
|
30173
30185
|
// packages/workit-core/src/hooks/model-limit.ts
|
|
30174
30186
|
import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync7, readSync, statSync as statSync5 } from "node:fs";
|
|
30175
30187
|
import os11 from "node:os";
|
|
@@ -30493,20 +30505,37 @@ var agentModelDecision = (cwd, tool, options = {}) => {
|
|
|
30493
30505
|
|
|
30494
30506
|
// packages/workit-core/src/hooks/spawn-gate.ts
|
|
30495
30507
|
var MADE_WORKTREE = /^WORKTREE:[ \t]*(?!not made yet)\S(?![^\n]*not made yet)/mu;
|
|
30496
|
-
var
|
|
30497
|
-
|
|
30508
|
+
var namesMade = (word) => {
|
|
30509
|
+
try {
|
|
30510
|
+
const stat = fs31.statSync(word);
|
|
30511
|
+
if (stat.isFile())
|
|
30512
|
+
return stat.size < 1e6 && MADE_WORKTREE.test(fs31.readFileSync(word, "utf8"));
|
|
30513
|
+
const dotGit = path50.join(word, ".git");
|
|
30514
|
+
const link = fs31.statSync(dotGit);
|
|
30515
|
+
const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(fs31.readFileSync(dotGit, "utf8"));
|
|
30516
|
+
return !!admin && fs31.existsSync(path50.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
|
|
30517
|
+
} catch {
|
|
30518
|
+
return false;
|
|
30519
|
+
}
|
|
30520
|
+
};
|
|
30521
|
+
var namesWorktree = (prompt) => MADE_WORKTREE.test(prompt) || (prompt.match(/(?<![\w.~])(?:[a-z]:[\\/]|\/)[^\s'"`<>|;,()]+/giu) ?? []).some((word) => namesMade(word.replace(/[.:]+$/u, "")));
|
|
30522
|
+
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";
|
|
30498
30523
|
var gate = (descriptor, tool) => {
|
|
30499
30524
|
const type = typeof tool.subagent_type === "string" ? tool.subagent_type : "";
|
|
30500
30525
|
const implementer = workitRole(descriptor, type) === "implementer";
|
|
30501
|
-
if (implementer && (typeof tool.prompt !== "string" || !
|
|
30526
|
+
if (implementer && (typeof tool.prompt !== "string" || !namesWorktree(tool.prompt))) {
|
|
30527
|
+
const slice = sliceWord(tool);
|
|
30528
|
+
const unblock = `workit fanout worktree create ${slice}`;
|
|
30502
30529
|
return {
|
|
30503
30530
|
kind: "deny",
|
|
30504
30531
|
decision: {
|
|
30505
30532
|
kind: "deny",
|
|
30506
|
-
reason: `workit spawn gate:
|
|
30507
|
-
|
|
30533
|
+
reason: `workit spawn gate: this ${type} prompt names no worktree Workit made.
|
|
30534
|
+
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.`,
|
|
30535
|
+
unblock
|
|
30508
30536
|
}
|
|
30509
30537
|
};
|
|
30538
|
+
}
|
|
30510
30539
|
if (tool.isolation === undefined)
|
|
30511
30540
|
return { kind: "run", input: tool, change: { dropped: [], reasons: [], notes: [] } };
|
|
30512
30541
|
const { isolation: _dropped, ...input } = tool;
|
|
@@ -30529,9 +30558,9 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
|
|
|
30529
30558
|
};
|
|
30530
30559
|
|
|
30531
30560
|
// packages/workit-core/src/hooks/server-gate.ts
|
|
30532
|
-
import
|
|
30533
|
-
import
|
|
30534
|
-
var procNoticeFile = (env, session) =>
|
|
30561
|
+
import fs32 from "node:fs";
|
|
30562
|
+
import path51 from "node:path";
|
|
30563
|
+
var procNoticeFile = (env, session) => path51.join(stateDir(env), "procs", "notices", `${session.replace(/[^A-Za-z0-9_.@+-]/gu, "-").slice(0, 120) || "none"}.json`);
|
|
30535
30564
|
var mb = (bytes) => `${Math.round(Number(bytes) / 1048576)} MB`;
|
|
30536
30565
|
function takeProcNotice(session, env = process.env) {
|
|
30537
30566
|
if (!session)
|
|
@@ -30539,12 +30568,12 @@ function takeProcNotice(session, env = process.env) {
|
|
|
30539
30568
|
const file = procNoticeFile(env, session);
|
|
30540
30569
|
const taken = `${file}.${process.pid}.taken`;
|
|
30541
30570
|
try {
|
|
30542
|
-
|
|
30571
|
+
fs32.renameSync(file, taken);
|
|
30543
30572
|
} catch {
|
|
30544
30573
|
return null;
|
|
30545
30574
|
}
|
|
30546
30575
|
try {
|
|
30547
|
-
const { notices } = JSON.parse(
|
|
30576
|
+
const { notices } = JSON.parse(fs32.readFileSync(taken, "utf8"));
|
|
30548
30577
|
const lines = (Array.isArray(notices) ? notices : []).flatMap((notice) => {
|
|
30549
30578
|
if (!notice || typeof notice !== "object")
|
|
30550
30579
|
return [];
|
|
@@ -30561,29 +30590,29 @@ function takeProcNotice(session, env = process.env) {
|
|
|
30561
30590
|
return null;
|
|
30562
30591
|
} finally {
|
|
30563
30592
|
try {
|
|
30564
|
-
|
|
30593
|
+
fs32.rmSync(taken, { force: true });
|
|
30565
30594
|
} catch {}
|
|
30566
30595
|
}
|
|
30567
30596
|
}
|
|
30568
30597
|
|
|
30569
30598
|
// packages/workit-core/src/hooks/teardown.ts
|
|
30570
30599
|
import { spawn } from "node:child_process";
|
|
30571
|
-
import
|
|
30572
|
-
import
|
|
30600
|
+
import fs33 from "node:fs";
|
|
30601
|
+
import path53 from "node:path";
|
|
30573
30602
|
|
|
30574
30603
|
// packages/workit-core/src/core/cli-locate.ts
|
|
30575
30604
|
import { closeSync as closeSync5, existsSync as existsSync17, openSync as openSync5, readSync as readSync2 } from "node:fs";
|
|
30576
|
-
import
|
|
30605
|
+
import path52 from "node:path";
|
|
30577
30606
|
var LAUNCHER_MARKER = "workit-owned-launcher";
|
|
30578
30607
|
var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
|
|
30579
30608
|
var installRoot = (env, platform = process.platform) => {
|
|
30580
30609
|
if (env.WORKIT_INSTALL_ROOT)
|
|
30581
30610
|
return env.WORKIT_INSTALL_ROOT;
|
|
30582
30611
|
const data = dataDir(env, platform);
|
|
30583
|
-
return platform === "win32" ?
|
|
30612
|
+
return platform === "win32" ? path52.join(data, "install") : data;
|
|
30584
30613
|
};
|
|
30585
|
-
var ownedLauncherPath = (env, platform = process.platform) =>
|
|
30586
|
-
var ownedCurrentEntry = (env, platform = process.platform) =>
|
|
30614
|
+
var ownedLauncherPath = (env, platform = process.platform) => path52.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
|
|
30615
|
+
var ownedCurrentEntry = (env, platform = process.platform) => path52.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
|
|
30587
30616
|
var head = (file) => {
|
|
30588
30617
|
let fd;
|
|
30589
30618
|
try {
|
|
@@ -30610,7 +30639,7 @@ var locateWorkitCli = (options = {}) => {
|
|
|
30610
30639
|
source: "owned-launcher",
|
|
30611
30640
|
command: launcher,
|
|
30612
30641
|
args: [],
|
|
30613
|
-
binDir:
|
|
30642
|
+
binDir: path52.dirname(launcher)
|
|
30614
30643
|
};
|
|
30615
30644
|
const current = ownedCurrentEntry(env, platform);
|
|
30616
30645
|
if (exists(current))
|
|
@@ -30639,7 +30668,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
|
|
|
30639
30668
|
if (located.binDir) {
|
|
30640
30669
|
const key = pathKey(env);
|
|
30641
30670
|
const delimiter = platform === "win32" ? ";" : ":";
|
|
30642
|
-
const same = (dir) => platform === "win32" ?
|
|
30671
|
+
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);
|
|
30643
30672
|
const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
|
|
30644
30673
|
patch[key] = [located.binDir, ...rest].join(delimiter);
|
|
30645
30674
|
}
|
|
@@ -30663,9 +30692,9 @@ var ENDS = {
|
|
|
30663
30692
|
};
|
|
30664
30693
|
var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
|
|
30665
30694
|
var HOST_SESSION_VARS2 = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
|
|
30666
|
-
var teardownDir = (env) =>
|
|
30667
|
-
var teardownLog = (env) =>
|
|
30668
|
-
var reapStamp = (env) =>
|
|
30695
|
+
var teardownDir = (env) => path53.join(stateDir(env), "procs");
|
|
30696
|
+
var teardownLog = (env) => path53.join(teardownDir(env), "teardown.log");
|
|
30697
|
+
var reapStamp = (env) => path53.join(teardownDir(env), "reap-at-start.stamp");
|
|
30669
30698
|
function spawnDetached(request) {
|
|
30670
30699
|
try {
|
|
30671
30700
|
const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
|
|
@@ -30692,13 +30721,13 @@ var teardownDeps = {
|
|
|
30692
30721
|
var openLog = (env, args) => {
|
|
30693
30722
|
try {
|
|
30694
30723
|
const file = teardownLog(env);
|
|
30695
|
-
|
|
30724
|
+
fs33.mkdirSync(path53.dirname(file), { recursive: true });
|
|
30696
30725
|
let size = 0;
|
|
30697
30726
|
try {
|
|
30698
|
-
size =
|
|
30727
|
+
size = fs33.statSync(file).size;
|
|
30699
30728
|
} catch {}
|
|
30700
|
-
const fd =
|
|
30701
|
-
|
|
30729
|
+
const fd = fs33.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
|
|
30730
|
+
fs33.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
|
|
30702
30731
|
`);
|
|
30703
30732
|
return fd;
|
|
30704
30733
|
} catch {
|
|
@@ -30710,7 +30739,7 @@ function runCli(args, env) {
|
|
|
30710
30739
|
try {
|
|
30711
30740
|
const cli = locateWorkitCli({ env });
|
|
30712
30741
|
const cwd = teardownDir(env);
|
|
30713
|
-
|
|
30742
|
+
fs33.mkdirSync(cwd, { recursive: true });
|
|
30714
30743
|
log = openLog(env, args);
|
|
30715
30744
|
const started = teardownDeps.spawn({
|
|
30716
30745
|
command: cli.command,
|
|
@@ -30720,7 +30749,7 @@ function runCli(args, env) {
|
|
|
30720
30749
|
log
|
|
30721
30750
|
});
|
|
30722
30751
|
if (!started && log !== null)
|
|
30723
|
-
|
|
30752
|
+
fs33.writeSync(log, ` not started
|
|
30724
30753
|
`);
|
|
30725
30754
|
return started;
|
|
30726
30755
|
} catch {
|
|
@@ -30728,7 +30757,7 @@ function runCli(args, env) {
|
|
|
30728
30757
|
} finally {
|
|
30729
30758
|
if (log !== null)
|
|
30730
30759
|
try {
|
|
30731
|
-
|
|
30760
|
+
fs33.closeSync(log);
|
|
30732
30761
|
} catch {}
|
|
30733
30762
|
}
|
|
30734
30763
|
}
|
|
@@ -30747,24 +30776,24 @@ function endSession(end, env = process.env) {
|
|
|
30747
30776
|
var claim2 = (file, now) => {
|
|
30748
30777
|
for (let attempt = 0;attempt < 2; attempt += 1)
|
|
30749
30778
|
try {
|
|
30750
|
-
|
|
30779
|
+
fs33.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
|
|
30751
30780
|
return true;
|
|
30752
30781
|
} catch (error) {
|
|
30753
30782
|
if (error.code !== "EEXIST")
|
|
30754
30783
|
return false;
|
|
30755
30784
|
let held = Number.NaN;
|
|
30756
30785
|
try {
|
|
30757
|
-
held = Number(
|
|
30786
|
+
held = Number(fs33.readFileSync(file, "utf8"));
|
|
30758
30787
|
} catch {}
|
|
30759
30788
|
if (now - held < REAP_INTERVAL_MS)
|
|
30760
30789
|
return false;
|
|
30761
|
-
|
|
30790
|
+
fs33.rmSync(file, { force: true });
|
|
30762
30791
|
}
|
|
30763
30792
|
return false;
|
|
30764
30793
|
};
|
|
30765
30794
|
var fresh = (stamp, now) => {
|
|
30766
30795
|
try {
|
|
30767
|
-
const last = Number(
|
|
30796
|
+
const last = Number(fs33.readFileSync(stamp, "utf8"));
|
|
30768
30797
|
return now - last < REAP_INTERVAL_MS && last <= now;
|
|
30769
30798
|
} catch {
|
|
30770
30799
|
return false;
|
|
@@ -30777,7 +30806,7 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
30777
30806
|
try {
|
|
30778
30807
|
if (fresh(stamp, now))
|
|
30779
30808
|
return false;
|
|
30780
|
-
|
|
30809
|
+
fs33.mkdirSync(path53.dirname(stamp), { recursive: true });
|
|
30781
30810
|
if (!claim2(lock, now))
|
|
30782
30811
|
return false;
|
|
30783
30812
|
} catch {
|
|
@@ -30790,12 +30819,12 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
30790
30819
|
started = runCli(["stop", "--orphans", "--reason", "session-start"], env);
|
|
30791
30820
|
if (started) {
|
|
30792
30821
|
const temp = `${stamp}.${process.pid}`;
|
|
30793
|
-
|
|
30794
|
-
|
|
30822
|
+
fs33.writeFileSync(temp, String(now), { mode: 384 });
|
|
30823
|
+
fs33.renameSync(temp, stamp);
|
|
30795
30824
|
}
|
|
30796
30825
|
} catch {} finally {
|
|
30797
30826
|
try {
|
|
30798
|
-
|
|
30827
|
+
fs33.rmSync(lock, { force: true });
|
|
30799
30828
|
} catch {}
|
|
30800
30829
|
}
|
|
30801
30830
|
return started;
|
|
@@ -31336,14 +31365,15 @@ ${subagentStartText({ ...input, cwd: "" }, descriptor, event)}`;
|
|
|
31336
31365
|
const judge = event.agentType.endsWith("reviewer") ? "reviewer" : "verifier";
|
|
31337
31366
|
const pick = judge === "verifier" ? ", --kind live when you drove the real surface" : "";
|
|
31338
31367
|
const branch = judgeBranch(cwd);
|
|
31368
|
+
const at = currentBranch(cwd) === null ? null : worktreeTop(cwd) ?? null;
|
|
31339
31369
|
const checks = judgeChecksLine(cwd);
|
|
31340
31370
|
const checksText = checks ? ` ${checks}` : "";
|
|
31341
31371
|
if (descriptor.host === "codex_cli" || descriptor.host === "codex_desktop")
|
|
31342
|
-
return `${readOnly} Its shell already acts as its own Workit session, so the ledger tells its verdicts apart from the author's. Record the verdict with exactly this command (pick the result${pick}, name the candidate branch if it differs, say what you ran): \`${verdictCommand({ branch, judge })}\`.${JUDGE_CWD} Add no session or token option to it, and never set WORKIT_SESSION_ID by hand.${checksText}`;
|
|
31372
|
+
return `${readOnly} Its shell already acts as its own Workit session, so the ledger tells its verdicts apart from the author's. Record the verdict with exactly this command (pick the result${pick}, name the candidate branch if it differs, say what you ran): \`${verdictCommand({ branch, judge, cwd: at })}\`.${JUDGE_CWD} Add no session or token option to it, and never set WORKIT_SESSION_ID by hand.${checksText}`;
|
|
31343
31373
|
const token = session ? recordIssuedSession(cwd, session, own) : null;
|
|
31344
31374
|
if (session && !token)
|
|
31345
31375
|
return `${readOnly} ${own} was already issued to an earlier subagent, so no token is handed out again and a verdict under it would be refused (unbound_session). Record no verdict as ${own}: spawn a fresh verifier or reviewer, which gets its own session and token.`;
|
|
31346
|
-
const line = verdictCommand({ branch, judge, session: own, token });
|
|
31376
|
+
const line = verdictCommand({ branch, judge, session: own, token, cwd: at });
|
|
31347
31377
|
return `${readOnly} Its own Workit session is ${own}, so the ledger tells its verdicts apart from the author's. Record the verdict with exactly this command (pick the result${pick}, name the candidate branch if it differs, say what you ran): \`${line}\`.${JUDGE_CWD}${token ? " The token is this subagent's alone: never write it into a report, a file or a commit. --token needs a workit CLI at least as new as this plugin; if the CLI answers that --token is an unknown option, update the workit CLI (workit upgrade --cli) and record again." : ""}${checksText}`;
|
|
31348
31378
|
};
|
|
31349
31379
|
var PRE_TOOL = new Set(["shell.pre", "write.pre", "tool.pre"]);
|
|
@@ -31444,12 +31474,12 @@ function decide(input, deps) {
|
|
|
31444
31474
|
if (input.host === "claude_code")
|
|
31445
31475
|
return {
|
|
31446
31476
|
kind: "ask",
|
|
31447
|
-
reason: `Only the user runs \`workit ${userOnly.join(" ")}\`: the user decides this call.`
|
|
31477
|
+
reason: `Only the user runs \`workit ${userOnly.join(" ")}\`: the user decides this call (its help: \`workit help ${userOnly.join(" ")}\`).`
|
|
31448
31478
|
};
|
|
31449
31479
|
if (canDeny && ["cursor", "codex_cli", "codex_desktop", "pi"].includes(input.host))
|
|
31450
31480
|
return {
|
|
31451
31481
|
kind: "deny",
|
|
31452
|
-
reason: `Only the user runs \`workit ${userOnly.join(" ")}\`: run it in your own terminal.`,
|
|
31482
|
+
reason: `Only the user runs \`workit ${userOnly.join(" ")}\`: run it in your own terminal (its help: \`workit help ${userOnly.join(" ")}\`).`,
|
|
31453
31483
|
unblock: null
|
|
31454
31484
|
};
|
|
31455
31485
|
}
|
|
@@ -31591,11 +31621,11 @@ var modelKey = (model) => {
|
|
|
31591
31621
|
|
|
31592
31622
|
// packages/workit-core/src/hooks/budget-signal.ts
|
|
31593
31623
|
import { createHash as createHash23 } from "node:crypto";
|
|
31594
|
-
import
|
|
31595
|
-
import
|
|
31624
|
+
import fs34 from "node:fs";
|
|
31625
|
+
import path54 from "node:path";
|
|
31596
31626
|
var hash2 = (text) => createHash23("sha256").update(text).digest("hex").slice(0, 32);
|
|
31597
|
-
var budgetDir = (store) =>
|
|
31598
|
-
var agentBase = (store, session, agentId) =>
|
|
31627
|
+
var budgetDir = (store) => path54.join(store, "budget");
|
|
31628
|
+
var agentBase = (store, session, agentId) => path54.join(budgetDir(store), hash2(`${session}\x00${agentId ?? ""}`));
|
|
31599
31629
|
var spawnBudget = (prompt) => {
|
|
31600
31630
|
const found = /^TIMEBOX:[^\n]*?\b(\d+)\s+tool calls\b/mu.exec(prompt);
|
|
31601
31631
|
const n = found ? Number(found[1]) : NaN;
|
|
@@ -31603,7 +31633,7 @@ var spawnBudget = (prompt) => {
|
|
|
31603
31633
|
};
|
|
31604
31634
|
var readBudget = (file) => {
|
|
31605
31635
|
try {
|
|
31606
|
-
const { limit, told } = JSON.parse(
|
|
31636
|
+
const { limit, told } = JSON.parse(fs34.readFileSync(file, "utf8"));
|
|
31607
31637
|
return typeof limit === "number" && limit > 0 ? { limit, told: Number(told) || 0 } : null;
|
|
31608
31638
|
} catch {
|
|
31609
31639
|
return null;
|
|
@@ -31611,16 +31641,16 @@ var readBudget = (file) => {
|
|
|
31611
31641
|
};
|
|
31612
31642
|
var startBudget = (store, session, agentId, n) => {
|
|
31613
31643
|
const dir = budgetDir(store);
|
|
31614
|
-
|
|
31644
|
+
fs34.mkdirSync(dir, { recursive: true });
|
|
31615
31645
|
const cutoff = Date.now() - 604800000;
|
|
31616
|
-
for (const name of
|
|
31646
|
+
for (const name of fs34.readdirSync(dir))
|
|
31617
31647
|
try {
|
|
31618
|
-
if (
|
|
31619
|
-
|
|
31648
|
+
if (fs34.statSync(path54.join(dir, name)).mtimeMs < cutoff)
|
|
31649
|
+
fs34.rmSync(path54.join(dir, name));
|
|
31620
31650
|
} catch {}
|
|
31621
31651
|
const base = agentBase(store, session, agentId);
|
|
31622
|
-
|
|
31623
|
-
|
|
31652
|
+
fs34.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
|
|
31653
|
+
fs34.rmSync(`${base}.calls`, { force: true });
|
|
31624
31654
|
};
|
|
31625
31655
|
var bindBudget = (cwd, session, agentId, prompt) => {
|
|
31626
31656
|
try {
|
|
@@ -31643,8 +31673,8 @@ var tickBudget = (cwd, session, agentId) => {
|
|
|
31643
31673
|
const budget = readBudget(`${base}.json`);
|
|
31644
31674
|
if (!budget)
|
|
31645
31675
|
return false;
|
|
31646
|
-
|
|
31647
|
-
return
|
|
31676
|
+
fs34.appendFileSync(`${base}.calls`, ".");
|
|
31677
|
+
return fs34.statSync(`${base}.calls`).size >= budget.limit * (budget.told + 1);
|
|
31648
31678
|
} catch {
|
|
31649
31679
|
return false;
|
|
31650
31680
|
}
|
|
@@ -31656,14 +31686,14 @@ var reachedOf = (cwd, session, agentId) => {
|
|
|
31656
31686
|
const budget = base && readBudget(`${base}.json`);
|
|
31657
31687
|
if (!budget)
|
|
31658
31688
|
return null;
|
|
31659
|
-
return { base, budget, reached: Math.floor(
|
|
31689
|
+
return { base, budget, reached: Math.floor(fs34.statSync(`${base}.calls`).size / budget.limit) };
|
|
31660
31690
|
};
|
|
31661
31691
|
var budgetLine = (cwd, session, agentId) => {
|
|
31662
31692
|
try {
|
|
31663
31693
|
const at = reachedOf(cwd, session, agentId);
|
|
31664
31694
|
if (!at || at.reached <= at.budget.told)
|
|
31665
31695
|
return null;
|
|
31666
|
-
|
|
31696
|
+
fs34.writeFileSync(`${at.base}.json`, JSON.stringify({ ...at.budget, told: at.reached }));
|
|
31667
31697
|
return lineFor(at.budget.limit * at.reached);
|
|
31668
31698
|
} catch {
|
|
31669
31699
|
return null;
|
|
@@ -32071,12 +32101,12 @@ var skillPromptNudge = (prompt, ctx) => process.env.WORKIT_PI_WORKER_SESSION ? n
|
|
|
32071
32101
|
// packages/workit-pi/src/launches.ts
|
|
32072
32102
|
import { mkdirSync as mkdirSync7, readFileSync as readFileSync16, readdirSync as readdirSync8, rmSync as rmSync4, writeFileSync as writeFileSync6 } from "node:fs";
|
|
32073
32103
|
import os12 from "node:os";
|
|
32074
|
-
import
|
|
32104
|
+
import path55 from "node:path";
|
|
32075
32105
|
var launchDir = (root) => {
|
|
32076
32106
|
const location = resolveStore(root);
|
|
32077
|
-
return location instanceof Error ? null :
|
|
32107
|
+
return location instanceof Error ? null : path55.join(location.dir, "pi-launches");
|
|
32078
32108
|
};
|
|
32079
|
-
var fileFor = (dir, workerId) =>
|
|
32109
|
+
var fileFor = (dir, workerId) => path55.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
|
|
32080
32110
|
var recordLaunch = (root, attempt) => {
|
|
32081
32111
|
const dir = launchDir(root);
|
|
32082
32112
|
if (!dir)
|
|
@@ -32122,7 +32152,7 @@ var abandonedLaunches = (root) => {
|
|
|
32122
32152
|
const found = [];
|
|
32123
32153
|
for (const name of names) {
|
|
32124
32154
|
try {
|
|
32125
|
-
const attempt = JSON.parse(readFileSync16(
|
|
32155
|
+
const attempt = JSON.parse(readFileSync16(path55.join(dir, name), "utf8"));
|
|
32126
32156
|
if (typeof attempt.workerId === "string" && typeof attempt.session === "string") {
|
|
32127
32157
|
if (!alive(attempt))
|
|
32128
32158
|
found.push(attempt);
|
package/package.json
CHANGED
|
@@ -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. **
|
|
24
|
-
|
|
25
|
-
Never hand-edit it; change the plan or
|
|
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
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
(
|
|
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
|
|
@@ -31,7 +31,7 @@ denial, a review comment that needs a product decision, a required update
|
|
|
31
31
|
that repeats because the base keeps moving, or after 3 failed fix attempts on
|
|
32
32
|
the same check. Fix round and recheck both failed: the decider agent (read the `workit-fanout` skill's SKILL.md and follow it).
|
|
33
33
|
|
|
34
|
-
1. **Open.** Last before the PR, if `workit grant show` has `changelog: update|create`:
|
|
34
|
+
1. **Open.** Last before the PR, if `workit grant show` has `changelog: update|create`: pass the Unreleased entry as `workit pr create … --changelog "<Section>: <entry>"` (it commits and pushes it); with `docs: when-user-facing` fix only docs the diff made false (`references/changelog.md`).
|
|
35
35
|
Full local check (`workit check ci` when `.workit/checks.json` has a `ci` group), push once: `workit git push`, then `workit pr template` and fill the template it prints: every heading, each `<!-- -->` replaced (Workit's: `references/pr-body.md`).
|
|
36
36
|
`workit pr create --title "<title>" --body-file <f|->` refuses a body that leaves a repo template (or `prTemplate: workit`) unfilled; add `--issue <#n|ID>` (`--refs`: no close; `workit pr edit`).
|
|
37
37
|
YouTrack issue work: `workit youtrack …` (`--help`; the `ytrack` skill for the rest). A draft that needs the user's yes (YouTrack text, release notes, a PR body they asked to review): paste it whole in chat before asking, never only its path, and again after every edit (the verb prints the diff and the new text).
|
|
@@ -17,19 +17,23 @@ belongs to). Otherwise:
|
|
|
17
17
|
do, not with internals: "Added: `workit pr create --no-changelog <reason>`
|
|
18
18
|
skips the changelog check with a recorded reason", not "refactor gate
|
|
19
19
|
module".
|
|
20
|
-
2.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
2. Open the PR with the entry in the same call:
|
|
21
|
+
`workit pr create … --changelog "<Section>: <entry>"` (sections: Added,
|
|
22
|
+
Changed, Deprecated, Removed, Fixed, Security). It merges the bullet into
|
|
23
|
+
`## [Unreleased]` of the right file (creating a missing Keep a Changelog
|
|
24
|
+
file), commits it with a subject commitlint accepts, pushes and opens the
|
|
25
|
+
PR. Never clobber CHANGELOG.md: never rewrite, reorder or delete an
|
|
25
26
|
existing entry, and never hand-edit released sections.
|
|
26
|
-
3.
|
|
27
|
-
|
|
27
|
+
3. With no PR to open yet, apply it alone with
|
|
28
|
+
`workit changelog apply --entries '{"Added": ["…"]}'` (`--path <file>` when
|
|
29
|
+
it is not the root CHANGELOG.md), then commit it
|
|
30
|
+
(`workit git commit -m "<message>" -- <file>`) with the change and push.
|
|
28
31
|
|
|
29
32
|
`workit pr create` refuses a user-facing PR without a new Unreleased bullet
|
|
30
|
-
(`changelog_required`)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
(`changelog_required`); its `Retry as:` line is your call plus
|
|
34
|
+
`--changelog "<Section>: <what users can now do>"`: fill in the entry and run
|
|
35
|
+
it. When the PR truly needs no entry, pass `--no-changelog "<why>"`: the
|
|
36
|
+
reason is written into the PR body.
|
|
33
37
|
|
|
34
38
|
## Docs (`docs: when-user-facing`)
|
|
35
39
|
|