@workit-dev/pi 1.5.0 → 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/worker.js +10 -1
- package/dist/workit.js +628 -294
- package/package.json +1 -1
package/dist/workit.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// packages/workit-pi/extensions/workit.ts
|
|
2
|
-
import { randomUUID as
|
|
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
|
|
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";
|
|
@@ -16474,12 +16474,11 @@ function checkVerdictsOnce(cwd, branch, ledgerRows) {
|
|
|
16474
16474
|
}
|
|
16475
16475
|
return reasons;
|
|
16476
16476
|
};
|
|
16477
|
-
const
|
|
16477
|
+
const voided = verdictVoids(rows, { chained: true });
|
|
16478
|
+
const retired = new Set(voided.keys());
|
|
16478
16479
|
for (const row of rows)
|
|
16479
|
-
if (row.type === "verdict" && row.supersedes && !row.supersedeIgnored && trustReasons(cwd, row).length === 0)
|
|
16480
|
+
if (row.type === "verdict" && row.supersedes && !row.supersedeIgnored && !voided.has(row.id) && trustReasons(cwd, row).length === 0)
|
|
16480
16481
|
retired.add(row.supersedes);
|
|
16481
|
-
for (const id of verdictVoids(rows, { chained: true }).keys())
|
|
16482
|
-
retired.add(id);
|
|
16483
16482
|
const byKind = new Map;
|
|
16484
16483
|
for (const row of rows.toSorted(byRank))
|
|
16485
16484
|
if (isLiveVerdict(row, retired) && scope(row)) {
|
|
@@ -18258,18 +18257,18 @@ var exportDigest = (bundle) => sha256({
|
|
|
18258
18257
|
// packages/workit-core/src/core/route-intent.ts
|
|
18259
18258
|
import { spawnSync as spawnSync16 } from "node:child_process";
|
|
18260
18259
|
import { existsSync as existsSync9 } from "node:fs";
|
|
18261
|
-
import
|
|
18260
|
+
import path28 from "node:path";
|
|
18262
18261
|
|
|
18263
18262
|
// packages/workit-core/src/hooks/raw-git.ts
|
|
18264
18263
|
import { spawnSync as spawnSync15 } from "node:child_process";
|
|
18265
18264
|
import { createHash as createHash15 } from "node:crypto";
|
|
18266
18265
|
import fs18 from "node:fs";
|
|
18267
18266
|
import os7 from "node:os";
|
|
18268
|
-
import
|
|
18267
|
+
import path27 from "node:path";
|
|
18269
18268
|
|
|
18270
18269
|
// packages/workit-core/src/autonomy.ts
|
|
18271
18270
|
import os6 from "node:os";
|
|
18272
|
-
import
|
|
18271
|
+
import path25 from "node:path";
|
|
18273
18272
|
|
|
18274
18273
|
// packages/workit-core/src/core/eval-world.ts
|
|
18275
18274
|
import { existsSync as existsSync8, realpathSync as realpathSync5 } from "node:fs";
|
|
@@ -18295,6 +18294,73 @@ var evalWorldEntry = (cwd) => {
|
|
|
18295
18294
|
}
|
|
18296
18295
|
};
|
|
18297
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
|
+
|
|
18298
18364
|
// packages/workit-core/src/autonomy.ts
|
|
18299
18365
|
var accountHome2 = () => {
|
|
18300
18366
|
try {
|
|
@@ -18324,8 +18390,8 @@ var benchWorld = (cwd) => {
|
|
|
18324
18390
|
};
|
|
18325
18391
|
};
|
|
18326
18392
|
var grantsOverride = () => {
|
|
18327
|
-
const configured =
|
|
18328
|
-
return configured ===
|
|
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`;
|
|
18329
18395
|
};
|
|
18330
18396
|
var GRANT_KINDS = ["push", "pr", "merge", "release", "rerun"];
|
|
18331
18397
|
var DEFAULT_GRANTS = Object.freeze({
|
|
@@ -18583,7 +18649,7 @@ var raises = (kind, current, next) => {
|
|
|
18583
18649
|
// packages/workit-core/src/hooks/session-marker.ts
|
|
18584
18650
|
import { createHash as createHash14 } from "node:crypto";
|
|
18585
18651
|
import fs17 from "node:fs";
|
|
18586
|
-
import
|
|
18652
|
+
import path26 from "node:path";
|
|
18587
18653
|
var sessionMarkerFile = (input, session, store) => {
|
|
18588
18654
|
let dir = store;
|
|
18589
18655
|
if (dir === undefined) {
|
|
@@ -18593,7 +18659,7 @@ var sessionMarkerFile = (input, session, store) => {
|
|
|
18593
18659
|
dir = location.dir;
|
|
18594
18660
|
}
|
|
18595
18661
|
const name = createHash14("sha256").update(`${input.host}\x00${session}`).digest("hex").slice(0, 32);
|
|
18596
|
-
return
|
|
18662
|
+
return path26.join(dir, "hooks", `skills-${name}.json`);
|
|
18597
18663
|
};
|
|
18598
18664
|
var list2 = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
18599
18665
|
var EMPTY = {
|
|
@@ -18628,7 +18694,7 @@ var parseMarker = (text) => {
|
|
|
18628
18694
|
};
|
|
18629
18695
|
var readSessionMarker = (file) => parseMarker(readRaw(file));
|
|
18630
18696
|
var writeAtomic = (file, marker) => {
|
|
18631
|
-
fs17.mkdirSync(
|
|
18697
|
+
fs17.mkdirSync(path26.dirname(file), { recursive: true });
|
|
18632
18698
|
const temp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18633
18699
|
try {
|
|
18634
18700
|
fs17.writeFileSync(temp, JSON.stringify(marker));
|
|
@@ -19213,14 +19279,14 @@ var GIT_CONFIG_ENV = /^(?:GIT_(?:CONFIG\w*|DIR|COMMON_DIR|WORK_TREE|SSH|SSH_COMM
|
|
|
19213
19279
|
var ASSIGNMENT = /^([A-Za-z_]\w*)=([\s\S]*)$/;
|
|
19214
19280
|
var MAX_DEPTH = 4;
|
|
19215
19281
|
var MAX_EXPANSIONS = 16;
|
|
19216
|
-
var isAbsolute = (value) =>
|
|
19282
|
+
var isAbsolute = (value) => path27.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\");
|
|
19217
19283
|
var HERE = /^(?:\$PWD|\$\{PWD\}|\$\(\s*pwd\s*\)|`pwd`|\$\(\s*git\s+rev-parse\s+--show-toplevel\s*\))(?=$|[\\/])/;
|
|
19218
19284
|
var joinDir = (base, raw) => {
|
|
19219
19285
|
const next = raw.replace(HERE, ".");
|
|
19220
19286
|
if (base === undefined || /[$`*?]/.test(next) || next === "-")
|
|
19221
19287
|
return;
|
|
19222
|
-
const expanded = next === "~" || next.startsWith("~/") ?
|
|
19223
|
-
return base === null || isAbsolute(expanded) ? 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);
|
|
19224
19290
|
};
|
|
19225
19291
|
var rebase = (base, inner) => inner === null ? base : inner === undefined ? undefined : joinDir(base, inner);
|
|
19226
19292
|
var cdTarget = (words) => {
|
|
@@ -20142,17 +20208,17 @@ var headSha2 = (repo) => {
|
|
|
20142
20208
|
if (!git || git.reftable)
|
|
20143
20209
|
return null;
|
|
20144
20210
|
try {
|
|
20145
|
-
const head = fs18.readFileSync(
|
|
20211
|
+
const head = fs18.readFileSync(path27.join(git.gitDir, "HEAD"), "utf8").trim();
|
|
20146
20212
|
if (/^[0-9a-f]{40,64}$/.test(head))
|
|
20147
20213
|
return head;
|
|
20148
20214
|
const ref = /^ref: (refs\/.+)$/.exec(head)?.[1];
|
|
20149
20215
|
if (!ref)
|
|
20150
20216
|
return null;
|
|
20151
|
-
const common =
|
|
20217
|
+
const common = path27.dirname(repo.location.dir);
|
|
20152
20218
|
try {
|
|
20153
|
-
return fs18.readFileSync(
|
|
20219
|
+
return fs18.readFileSync(path27.join(common, ref), "utf8").trim() || null;
|
|
20154
20220
|
} catch {}
|
|
20155
|
-
const packed = fs18.readFileSync(
|
|
20221
|
+
const packed = fs18.readFileSync(path27.join(common, "packed-refs"), "utf8");
|
|
20156
20222
|
return new RegExp(`^([0-9a-f]{40,64}) ${ref.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`, "m").exec(packed)?.[1] ?? null;
|
|
20157
20223
|
} catch {
|
|
20158
20224
|
return null;
|
|
@@ -20245,7 +20311,7 @@ var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
|
|
|
20245
20311
|
const sub = invocation.args[0];
|
|
20246
20312
|
if (invocation.tool !== "git" || invocation.dir === undefined || !sub || sub.startsWith("-") || GIT_COMMANDS.has(sub) || depth >= MAX_DEPTH)
|
|
20247
20313
|
return [invocation];
|
|
20248
|
-
const dir =
|
|
20314
|
+
const dir = path27.resolve(root, invocation.dir ?? ".");
|
|
20249
20315
|
if (!fs18.existsSync(dir))
|
|
20250
20316
|
return [invocation];
|
|
20251
20317
|
const config = gitConfig(dir, invocation, cache);
|
|
@@ -20268,11 +20334,11 @@ var expandGitAliases = (root, invocation, cache = new Map, depth = 0) => {
|
|
|
20268
20334
|
var normalizedUrl = (url, dir) => {
|
|
20269
20335
|
const trimmed = url.trim();
|
|
20270
20336
|
if (/^file:\/\//i.test(trimmed))
|
|
20271
|
-
return
|
|
20337
|
+
return path27.resolve(dir, trimmed.slice(7)).replace(/\/+$/, "").replace(/\.git$/, "");
|
|
20272
20338
|
const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(trimmed);
|
|
20273
20339
|
const scp = !scheme && /^(?:[^@/\\]+@)?[^/\\:]{2,}:/.test(trimmed);
|
|
20274
20340
|
if (!scheme && !scp)
|
|
20275
|
-
return
|
|
20341
|
+
return path27.resolve(dir, trimmed).replace(/\/+$/, "").replace(/\.git$/, "");
|
|
20276
20342
|
const value = scheme ? trimmed.slice(scheme[0].length).replace(/^[^@/]*@/, "").replace(/^([^/:]+):\d+(?=\/)/, "$1") : trimmed.replace(/^[^@/]*@/, "").replace(":", "/");
|
|
20277
20343
|
return value.toLowerCase().replace(/\/{2,}/g, "/").replace(/^www\./, "").replace(/\/+$/, "").replace(/\.git$/, "");
|
|
20278
20344
|
};
|
|
@@ -20500,7 +20566,7 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
|
|
|
20500
20566
|
const out = [];
|
|
20501
20567
|
const repos = new Map;
|
|
20502
20568
|
const repoFor = (relative) => {
|
|
20503
|
-
const dir =
|
|
20569
|
+
const dir = path27.resolve(cwd, relative ?? ".");
|
|
20504
20570
|
if (!repos.has(dir)) {
|
|
20505
20571
|
const repo = repoAt(dir);
|
|
20506
20572
|
const workit = repo !== null && isWorkitWorkspace(repo);
|
|
@@ -20520,7 +20586,7 @@ var actionsIn = (cwd, command, dialect, cache = new Map, all = false) => {
|
|
|
20520
20586
|
continue;
|
|
20521
20587
|
const action = rawAction(invocation);
|
|
20522
20588
|
const at = !action ? null : repoFor(invocation.dir) ?? (all && invocation.tool !== "git" && explicitRepo(invocation.tool === "gh", "repo" in action && action.repo || "", invocation.env ?? {}) ? {
|
|
20523
|
-
repo: { dir:
|
|
20589
|
+
repo: { dir: path27.resolve(cwd, invocation.dir ?? "."), branch: null },
|
|
20524
20590
|
workit: false
|
|
20525
20591
|
} : null);
|
|
20526
20592
|
if (action && at)
|
|
@@ -20657,9 +20723,9 @@ var grantRefusal = (action, repo, invocation, cache) => {
|
|
|
20657
20723
|
return null;
|
|
20658
20724
|
};
|
|
20659
20725
|
var localTag = (repo, name) => {
|
|
20660
|
-
const common =
|
|
20726
|
+
const common = path27.dirname(repo.location.dir);
|
|
20661
20727
|
try {
|
|
20662
|
-
return fs18.existsSync(
|
|
20728
|
+
return fs18.existsSync(path27.join(common, "refs/tags", name)) || fs18.readFileSync(path27.join(common, "packed-refs"), "utf8").includes(` refs/tags/${name}
|
|
20663
20729
|
`);
|
|
20664
20730
|
} catch {
|
|
20665
20731
|
return false;
|
|
@@ -20679,7 +20745,7 @@ var analysisDenial = (error) => ({
|
|
|
20679
20745
|
});
|
|
20680
20746
|
var NEXT_COMMAND = "next";
|
|
20681
20747
|
var MARKER_TTL_SECONDS = 3600;
|
|
20682
|
-
var markerFile = (repo, session, key) =>
|
|
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`);
|
|
20683
20749
|
var callKey = (toolUseId, command) => toolUseId ?? `cmd:${createHash15("sha256").update(command).digest("hex")}`;
|
|
20684
20750
|
function noteRawCommit(input, command, key) {
|
|
20685
20751
|
try {
|
|
@@ -20690,7 +20756,7 @@ function noteRawCommit(input, command, key) {
|
|
|
20690
20756
|
if (action.kind !== "commit")
|
|
20691
20757
|
continue;
|
|
20692
20758
|
const file = markerFile(repo, input.session.id, key);
|
|
20693
|
-
fs18.mkdirSync(
|
|
20759
|
+
fs18.mkdirSync(path27.dirname(file), { recursive: true });
|
|
20694
20760
|
fs18.writeFileSync(file, `${JSON.stringify({ head: headSha2(repo), at })}
|
|
20695
20761
|
`);
|
|
20696
20762
|
}
|
|
@@ -20931,7 +20997,7 @@ var judgedDir = (root, dir) => {
|
|
|
20931
20997
|
return null;
|
|
20932
20998
|
if (dir === null)
|
|
20933
20999
|
return root;
|
|
20934
|
-
const resolved =
|
|
21000
|
+
const resolved = path28.resolve(root, dir);
|
|
20935
21001
|
return existsSync9(resolved) && inWorkitWorkspace(resolved) ? resolved : null;
|
|
20936
21002
|
};
|
|
20937
21003
|
var shellBranchPolicyViolation = (root, command, dialect = "posix") => {
|
|
@@ -22929,7 +22995,7 @@ class WorkitCore {
|
|
|
22929
22995
|
// packages/workit-core/src/core/repo-context.ts
|
|
22930
22996
|
import { spawnSync as spawnSync17 } from "node:child_process";
|
|
22931
22997
|
import { existsSync as existsSync10, readFileSync as readFileSync8, readdirSync as readdirSync3 } from "node:fs";
|
|
22932
|
-
import
|
|
22998
|
+
import path29 from "node:path";
|
|
22933
22999
|
var isSafeContextRange = (value) => value.length <= 4096 && (() => {
|
|
22934
23000
|
try {
|
|
22935
23001
|
gitRevisionParts(value);
|
|
@@ -23073,13 +23139,13 @@ var findPrTemplate = (cwd) => {
|
|
|
23073
23139
|
for (const rel of PR_TEMPLATE_FILES) {
|
|
23074
23140
|
const parts = rel.split("/");
|
|
23075
23141
|
const base = parts[parts.length - 1];
|
|
23076
|
-
const dir = parts.length > 1 ?
|
|
23142
|
+
const dir = parts.length > 1 ? path29.join(cwd, ...parts.slice(0, -1)) : cwd;
|
|
23077
23143
|
const actual = probeCaseInsensitive(dir, base);
|
|
23078
23144
|
if (actual)
|
|
23079
23145
|
return [...parts.slice(0, -1), actual].join("/");
|
|
23080
23146
|
}
|
|
23081
23147
|
for (const rel of PR_TEMPLATE_DIRS) {
|
|
23082
|
-
const only = singleMarkdown(
|
|
23148
|
+
const only = singleMarkdown(path29.join(cwd, ...rel.split("/")));
|
|
23083
23149
|
if (only)
|
|
23084
23150
|
return `${rel}/${only}`;
|
|
23085
23151
|
}
|
|
@@ -23109,7 +23175,7 @@ var diffStatForRange = (cwd, range) => {
|
|
|
23109
23175
|
return runGit(cwd, ["diff", "--stat", "--"]).stdout;
|
|
23110
23176
|
};
|
|
23111
23177
|
var packageScripts = (cwd, keys) => {
|
|
23112
|
-
const pkgPath =
|
|
23178
|
+
const pkgPath = path29.join(cwd, "package.json");
|
|
23113
23179
|
if (!existsSync10(pkgPath))
|
|
23114
23180
|
return [];
|
|
23115
23181
|
try {
|
|
@@ -23135,9 +23201,9 @@ var documentationFiles = (cwd) => {
|
|
|
23135
23201
|
if (entry.isDirectory()) {
|
|
23136
23202
|
if (excluded.has(entry.name))
|
|
23137
23203
|
continue;
|
|
23138
|
-
walk(
|
|
23204
|
+
walk(path29.join(dir, entry.name), depth + 1);
|
|
23139
23205
|
} else if (entry.isFile() && (entry.name === "README.md" || entry.name.endsWith(".md"))) {
|
|
23140
|
-
matches.push("./" +
|
|
23206
|
+
matches.push("./" + path29.relative(cwd, path29.join(dir, entry.name)).replaceAll("\\", "/"));
|
|
23141
23207
|
}
|
|
23142
23208
|
}
|
|
23143
23209
|
};
|
|
@@ -23153,7 +23219,7 @@ var readTrimmed2 = (file, maxLines) => {
|
|
|
23153
23219
|
`);
|
|
23154
23220
|
};
|
|
23155
23221
|
function prReadyContext(root, range) {
|
|
23156
|
-
const cwd =
|
|
23222
|
+
const cwd = path29.resolve(repoRoot(root));
|
|
23157
23223
|
if (range !== undefined && !isResolvableContextRange(cwd, range))
|
|
23158
23224
|
return invalidRange(cwd);
|
|
23159
23225
|
let stdout = "";
|
|
@@ -23211,7 +23277,7 @@ ${status.stderr}` : "");
|
|
|
23211
23277
|
stdout += `template_path: ${template}
|
|
23212
23278
|
|
|
23213
23279
|
`;
|
|
23214
|
-
stdout += readTrimmed2(
|
|
23280
|
+
stdout += readTrimmed2(path29.join(cwd, template), 220);
|
|
23215
23281
|
} else {
|
|
23216
23282
|
stdout += `template_path: none
|
|
23217
23283
|
|
|
@@ -23221,7 +23287,7 @@ ${status.stderr}` : "");
|
|
|
23221
23287
|
stdout += `
|
|
23222
23288
|
`;
|
|
23223
23289
|
stdout += printSection("Recent Validation Signals");
|
|
23224
|
-
if (existsSync10(
|
|
23290
|
+
if (existsSync10(path29.join(cwd, "package.json"))) {
|
|
23225
23291
|
stdout += `package.json detected. Common scripts:
|
|
23226
23292
|
`;
|
|
23227
23293
|
const found = packageScripts(cwd, ["lint", "format:check", "test", "build"]);
|
|
@@ -23230,7 +23296,7 @@ ${status.stderr}` : "");
|
|
|
23230
23296
|
`) + `
|
|
23231
23297
|
`;
|
|
23232
23298
|
}
|
|
23233
|
-
if (existsSync10(
|
|
23299
|
+
if (existsSync10(path29.join(cwd, "Cargo.toml")) || existsSync10(path29.join(cwd, "src-tauri/Cargo.toml"))) {
|
|
23234
23300
|
stdout += `Rust project detected.
|
|
23235
23301
|
`;
|
|
23236
23302
|
}
|
|
@@ -23263,7 +23329,7 @@ var CHANGELOG_RULES = `- Use an [Unreleased] section.
|
|
|
23263
23329
|
- Apply with the host-native editor, preserving the repository changelog conventions.
|
|
23264
23330
|
- If Unreleased already has duplicate category headings, normalize_only first.`;
|
|
23265
23331
|
function changelogContext(root, range) {
|
|
23266
|
-
const cwd =
|
|
23332
|
+
const cwd = path29.resolve(repoRoot(root));
|
|
23267
23333
|
if (range !== undefined && !isResolvableContextRange(cwd, range))
|
|
23268
23334
|
return invalidRange(cwd);
|
|
23269
23335
|
const resolvedRange = rangeArgOrDefault(range, cwd);
|
|
@@ -23281,7 +23347,7 @@ function changelogContext(root, range) {
|
|
|
23281
23347
|
stdout += CHANGELOG_RULES + `
|
|
23282
23348
|
`;
|
|
23283
23349
|
stdout += printSection("Existing CHANGELOG.md");
|
|
23284
|
-
const changelogPath =
|
|
23350
|
+
const changelogPath = path29.join(cwd, "CHANGELOG.md");
|
|
23285
23351
|
if (existsSync10(changelogPath)) {
|
|
23286
23352
|
stdout += readTrimmed2(changelogPath, 260) + `
|
|
23287
23353
|
`;
|
|
@@ -23301,7 +23367,7 @@ function changelogContext(root, range) {
|
|
|
23301
23367
|
return { stdout, stderr: "", exitCode: 0, cwd };
|
|
23302
23368
|
}
|
|
23303
23369
|
function docsRefreshContext(root, range) {
|
|
23304
|
-
const cwd =
|
|
23370
|
+
const cwd = path29.resolve(repoRoot(root));
|
|
23305
23371
|
if (range !== undefined && !isResolvableContextRange(cwd, range))
|
|
23306
23372
|
return invalidRange(cwd);
|
|
23307
23373
|
const resolvedRange = rangeArgOrDefault(range, cwd);
|
|
@@ -23323,7 +23389,7 @@ function docsRefreshContext(root, range) {
|
|
|
23323
23389
|
`) + `
|
|
23324
23390
|
`;
|
|
23325
23391
|
stdout += printSection("README Preview");
|
|
23326
|
-
const readme =
|
|
23392
|
+
const readme = path29.join(cwd, "README.md");
|
|
23327
23393
|
if (existsSync10(readme)) {
|
|
23328
23394
|
stdout += readTrimmed2(readme, 220) + `
|
|
23329
23395
|
`;
|
|
@@ -23332,7 +23398,7 @@ function docsRefreshContext(root, range) {
|
|
|
23332
23398
|
`;
|
|
23333
23399
|
}
|
|
23334
23400
|
stdout += printSection("Package Scripts");
|
|
23335
|
-
const pkgPath =
|
|
23401
|
+
const pkgPath = path29.join(cwd, "package.json");
|
|
23336
23402
|
if (existsSync10(pkgPath)) {
|
|
23337
23403
|
try {
|
|
23338
23404
|
const pkg = JSON.parse(readFileSync8(pkgPath, "utf8"));
|
|
@@ -23346,7 +23412,7 @@ function docsRefreshContext(root, range) {
|
|
|
23346
23412
|
return { stdout, stderr: "", exitCode: 0, cwd };
|
|
23347
23413
|
}
|
|
23348
23414
|
function releaseNotesContext(root, rangeOrTag) {
|
|
23349
|
-
const cwd =
|
|
23415
|
+
const cwd = path29.resolve(repoRoot(root));
|
|
23350
23416
|
if (!rangeOrTag) {
|
|
23351
23417
|
return {
|
|
23352
23418
|
stdout: "",
|
|
@@ -23389,7 +23455,7 @@ function releaseNotesContext(root, rangeOrTag) {
|
|
|
23389
23455
|
`;
|
|
23390
23456
|
stdout += printSection("Existing Release Files");
|
|
23391
23457
|
for (const rel of ["CHANGELOG.md", "RELEASE_NOTES.md", ".github/releases.md"]) {
|
|
23392
|
-
if (existsSync10(
|
|
23458
|
+
if (existsSync10(path29.join(cwd, rel)))
|
|
23393
23459
|
stdout += rel + `
|
|
23394
23460
|
`;
|
|
23395
23461
|
}
|
|
@@ -23421,7 +23487,7 @@ import { spawnSync as spawnSync19 } from "node:child_process";
|
|
|
23421
23487
|
|
|
23422
23488
|
// packages/workit-core/src/core/pr-create.ts
|
|
23423
23489
|
import fs19 from "node:fs";
|
|
23424
|
-
import
|
|
23490
|
+
import path30 from "node:path";
|
|
23425
23491
|
import { spawnSync as spawnSync18 } from "node:child_process";
|
|
23426
23492
|
// packages/workit-core/src/forge/pr-body.ts
|
|
23427
23493
|
function parseGhIssue(value) {
|
|
@@ -23441,11 +23507,11 @@ var LOCAL = bounded(20000);
|
|
|
23441
23507
|
var NETWORK = bounded(60000);
|
|
23442
23508
|
function whichOnPath(tool) {
|
|
23443
23509
|
const names = process.platform === "win32" ? [tool, `${tool}.exe`, `${tool}.cmd`] : [tool];
|
|
23444
|
-
for (const dir of (process.env.PATH ?? "").split(
|
|
23510
|
+
for (const dir of (process.env.PATH ?? "").split(path30.delimiter)) {
|
|
23445
23511
|
if (!dir)
|
|
23446
23512
|
continue;
|
|
23447
23513
|
for (const name of names) {
|
|
23448
|
-
const candidate =
|
|
23514
|
+
const candidate = path30.join(dir, name);
|
|
23449
23515
|
try {
|
|
23450
23516
|
fs19.accessSync(candidate, fs19.constants.X_OK);
|
|
23451
23517
|
return candidate;
|
|
@@ -23566,7 +23632,7 @@ var fetchGitLabIssueBody = async (ref, root, deps = {}) => {
|
|
|
23566
23632
|
|
|
23567
23633
|
// packages/workit-core/src/core/youtrack.ts
|
|
23568
23634
|
import fs21 from "node:fs";
|
|
23569
|
-
import
|
|
23635
|
+
import path32 from "node:path";
|
|
23570
23636
|
|
|
23571
23637
|
// packages/workit-core/src/core/templates.ts
|
|
23572
23638
|
var repoRoot2 = assetRoot();
|
|
@@ -23581,7 +23647,7 @@ import { spawnSync as spawnSync20 } from "node:child_process";
|
|
|
23581
23647
|
|
|
23582
23648
|
// packages/workit-core/src/forge/exec.ts
|
|
23583
23649
|
import fs20 from "node:fs";
|
|
23584
|
-
import
|
|
23650
|
+
import path31 from "node:path";
|
|
23585
23651
|
|
|
23586
23652
|
// packages/workit-core/src/forge/redact.ts
|
|
23587
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_.-]*`;
|
|
@@ -23592,11 +23658,11 @@ var ANSI = new RegExp(String.raw`\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007]*\
|
|
|
23592
23658
|
// packages/workit-core/src/forge/exec.ts
|
|
23593
23659
|
var MAX_BUFFER2 = 64 * 1024 * 1024;
|
|
23594
23660
|
function findExecutable(bin, env) {
|
|
23595
|
-
const dirs = (env.PATH ?? env.Path ?? "").split(
|
|
23661
|
+
const dirs = (env.PATH ?? env.Path ?? "").split(path31.delimiter).filter(Boolean);
|
|
23596
23662
|
const exts = process.platform === "win32" ? [".exe"] : [""];
|
|
23597
23663
|
for (const dir of dirs)
|
|
23598
23664
|
for (const ext of exts) {
|
|
23599
|
-
const candidate =
|
|
23665
|
+
const candidate = path31.join(dir, `${bin}${ext}`);
|
|
23600
23666
|
try {
|
|
23601
23667
|
const stat = fs20.statSync(candidate);
|
|
23602
23668
|
if (stat.isFile())
|
|
@@ -23639,7 +23705,7 @@ var YTRACK_MISSING = "ytrack is not on PATH: Workit reaches YouTrack only throug
|
|
|
23639
23705
|
|
|
23640
23706
|
// packages/workit-core/src/core/youtrack.ts
|
|
23641
23707
|
var ISSUE_RE = /^[A-Z]+-\d+$/;
|
|
23642
|
-
var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ??
|
|
23708
|
+
var youTrackReadOnlyConfigPath = () => process.env.WORKIT_YOUTRACK_CONFIG ?? path32.join(resolveConfigDir(), "youtrack.json");
|
|
23643
23709
|
var readYouTrackContextConfig = () => {
|
|
23644
23710
|
const cfgPath = youTrackReadOnlyConfigPath();
|
|
23645
23711
|
if (!fs21.existsSync(cfgPath))
|
|
@@ -24007,15 +24073,15 @@ function resolveGitRevision(root, value) {
|
|
|
24007
24073
|
}
|
|
24008
24074
|
function resolveInside(root, candidate) {
|
|
24009
24075
|
const base = realpathSync8(root);
|
|
24010
|
-
const target =
|
|
24011
|
-
if (target !== base && !target.startsWith(base +
|
|
24076
|
+
const target = path33.resolve(base, candidate);
|
|
24077
|
+
if (target !== base && !target.startsWith(base + path33.sep)) {
|
|
24012
24078
|
throw new Error("path must stay inside repository root");
|
|
24013
24079
|
}
|
|
24014
24080
|
let ancestor = target;
|
|
24015
24081
|
while (!existsSync11(ancestor))
|
|
24016
|
-
ancestor =
|
|
24082
|
+
ancestor = path33.dirname(ancestor);
|
|
24017
24083
|
const canonicalAncestor = realpathSync8(ancestor);
|
|
24018
|
-
if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base +
|
|
24084
|
+
if (canonicalAncestor !== base && !canonicalAncestor.startsWith(base + path33.sep)) {
|
|
24019
24085
|
throw new Error("path must stay inside repository root");
|
|
24020
24086
|
}
|
|
24021
24087
|
return target;
|
|
@@ -24061,7 +24127,7 @@ var capabilitiesFor = (descriptor, observed = {}) => descriptor.capabilities.map
|
|
|
24061
24127
|
// packages/workit-core/src/hooks/context.ts
|
|
24062
24128
|
import { createHash as createHash16 } from "node:crypto";
|
|
24063
24129
|
import fs22 from "node:fs";
|
|
24064
|
-
import
|
|
24130
|
+
import path34 from "node:path";
|
|
24065
24131
|
var MIGRATION_PENDING_NOTE = "workit migration pending — run `workit task status`";
|
|
24066
24132
|
var migrationPending = (result) => !result.ok && result.code === "needs_input" && (result.error ?? "").startsWith(MIGRATION_PENDING);
|
|
24067
24133
|
var boundTo = (entry, session) => entry.sessions.some((item) => item.host === session.host && item.handle === session.handle);
|
|
@@ -24149,7 +24215,7 @@ function entryCompactContext(store, entry, session, context) {
|
|
|
24149
24215
|
current: () => recentSignal(store.root)
|
|
24150
24216
|
};
|
|
24151
24217
|
const observed = task?.data.evidence.some(isObservedCheck) ?? false;
|
|
24152
|
-
const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [
|
|
24218
|
+
const files = (task?.data.decisions ?? []).flatMap((decision) => decision.data.binding.contentRefs.flatMap((ref) => ref.kind === "file" ? [path34.resolve(store.root, ref.path)] : []));
|
|
24153
24219
|
const observedFiles = filesKey(files);
|
|
24154
24220
|
const compact = compactContext(store, context, entry?.id ?? null, freshness, origin && { origin: origin.origin, taskId: origin.entry.id });
|
|
24155
24221
|
if (!compact.ok || !compact.data)
|
|
@@ -24208,17 +24274,17 @@ ${options.addendum}` : ""}
|
|
|
24208
24274
|
</workit-contract>`;
|
|
24209
24275
|
};
|
|
24210
24276
|
var checkoutAt = (cwd) => {
|
|
24211
|
-
for (let dir =
|
|
24212
|
-
const dotGit =
|
|
24277
|
+
for (let dir = path34.resolve(cwd);; dir = path34.dirname(dir)) {
|
|
24278
|
+
const dotGit = path34.join(dir, ".git");
|
|
24213
24279
|
if (fs22.existsSync(dotGit)) {
|
|
24214
|
-
const admin = fs22.statSync(dotGit).isFile() ?
|
|
24215
|
-
const head = fs22.readFileSync(
|
|
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();
|
|
24216
24282
|
return {
|
|
24217
24283
|
root: dir,
|
|
24218
24284
|
branch: /^ref: refs\/heads\/(.+)$/u.exec(head)?.[1] ?? null
|
|
24219
24285
|
};
|
|
24220
24286
|
}
|
|
24221
|
-
if (
|
|
24287
|
+
if (path34.dirname(dir) === dir)
|
|
24222
24288
|
return null;
|
|
24223
24289
|
}
|
|
24224
24290
|
};
|
|
@@ -24229,7 +24295,7 @@ var whereLine = (cwd) => {
|
|
|
24229
24295
|
return null;
|
|
24230
24296
|
const allowed = branchPolicySnapshotFor(cwd).namePolicy.allowed;
|
|
24231
24297
|
const kinds = allowed.some((pattern) => pattern.source === "^.*$") ? "any" : allowedKinds(allowed).join(", ") || "see `workit help git`";
|
|
24232
|
-
const place = checkout.root ===
|
|
24298
|
+
const place = checkout.root === path34.resolve(cwd) ? "" : ` in ${checkout.root}`;
|
|
24233
24299
|
return `cwd ${cwd}${place} on ${checkout.branch ?? "detached HEAD"}; branch kinds: ${kinds}`;
|
|
24234
24300
|
} catch {
|
|
24235
24301
|
return null;
|
|
@@ -24256,14 +24322,14 @@ var turnMarker = (input) => {
|
|
|
24256
24322
|
if (location instanceof Error)
|
|
24257
24323
|
return null;
|
|
24258
24324
|
const session = [input.host, input.session.id, input.session.agentId ?? ""].join("\x00");
|
|
24259
|
-
return
|
|
24325
|
+
return path34.join(location.dir, "hooks", `turn-${digestOf(session).slice(0, 32)}.json`);
|
|
24260
24326
|
} catch {
|
|
24261
24327
|
return null;
|
|
24262
24328
|
}
|
|
24263
24329
|
};
|
|
24264
24330
|
var writeTurnDigest = (file, digest) => {
|
|
24265
24331
|
try {
|
|
24266
|
-
fs22.mkdirSync(
|
|
24332
|
+
fs22.mkdirSync(path34.dirname(file), { recursive: true });
|
|
24267
24333
|
fs22.writeFileSync(file, `${JSON.stringify({ digest })}
|
|
24268
24334
|
`);
|
|
24269
24335
|
} catch {}
|
|
@@ -24278,7 +24344,7 @@ var pruneTurnDigests = (dir, now) => {
|
|
|
24278
24344
|
for (const name of fs22.readdirSync(dir)) {
|
|
24279
24345
|
if (!name.startsWith("turn-"))
|
|
24280
24346
|
continue;
|
|
24281
|
-
const file =
|
|
24347
|
+
const file = path34.join(dir, name);
|
|
24282
24348
|
try {
|
|
24283
24349
|
if (now - fs22.statSync(file).mtimeMs > TURN_TTL_MS)
|
|
24284
24350
|
fs22.rmSync(file, { force: true });
|
|
@@ -24308,7 +24374,7 @@ var seedTurnContext = (input, descriptor, text = turnContextText(input, descript
|
|
|
24308
24374
|
const file = turnMarker(input);
|
|
24309
24375
|
if (!file)
|
|
24310
24376
|
return;
|
|
24311
|
-
pruneTurnDigests(
|
|
24377
|
+
pruneTurnDigests(path34.dirname(file), Date.now());
|
|
24312
24378
|
if (text)
|
|
24313
24379
|
writeTurnDigest(file, digestOf(text));
|
|
24314
24380
|
else
|
|
@@ -24349,7 +24415,8 @@ var WORKIT_USER_ONLY = [
|
|
|
24349
24415
|
["release", "notes", "approve"],
|
|
24350
24416
|
["grant", "set"],
|
|
24351
24417
|
["grant", "raise"],
|
|
24352
|
-
["ledger", "void"]
|
|
24418
|
+
["ledger", "void"],
|
|
24419
|
+
["approve"]
|
|
24353
24420
|
];
|
|
24354
24421
|
var ALLOWED = new Set(WORKIT_ALLOWED_VERBS);
|
|
24355
24422
|
var hasWordsInOrder = (words, needle) => {
|
|
@@ -24414,7 +24481,7 @@ var userOnlyWorkitCall = (command, dialect = "posix") => {
|
|
|
24414
24481
|
// packages/workit-core/src/core/heavy-rules.ts
|
|
24415
24482
|
import fs23 from "node:fs";
|
|
24416
24483
|
import os8 from "node:os";
|
|
24417
|
-
import
|
|
24484
|
+
import path35 from "node:path";
|
|
24418
24485
|
var EMPTY2 = () => ({ deny: [], allow: [] });
|
|
24419
24486
|
var readText3 = (file) => {
|
|
24420
24487
|
try {
|
|
@@ -24455,19 +24522,19 @@ function parseJsonc(text) {
|
|
|
24455
24522
|
return JSON.parse(out.replace(/,(\s*[}\]])/gu, "$1"));
|
|
24456
24523
|
}
|
|
24457
24524
|
function gitTop(cwd) {
|
|
24458
|
-
for (let dir =
|
|
24459
|
-
if (fs23.existsSync(
|
|
24525
|
+
for (let dir = path35.resolve(cwd);; dir = path35.dirname(dir)) {
|
|
24526
|
+
if (fs23.existsSync(path35.join(dir, ".git")))
|
|
24460
24527
|
return dir;
|
|
24461
|
-
if (
|
|
24528
|
+
if (path35.dirname(dir) === dir)
|
|
24462
24529
|
return null;
|
|
24463
24530
|
}
|
|
24464
24531
|
}
|
|
24465
24532
|
var projectDirs = (cwd) => {
|
|
24466
24533
|
const top = gitTop(cwd);
|
|
24467
24534
|
const dirs = [];
|
|
24468
|
-
for (let dir =
|
|
24535
|
+
for (let dir = path35.resolve(cwd);; dir = path35.dirname(dir)) {
|
|
24469
24536
|
dirs.push(dir);
|
|
24470
|
-
if (!top || dir === top ||
|
|
24537
|
+
if (!top || dir === top || path35.dirname(dir) === dir)
|
|
24471
24538
|
return dirs;
|
|
24472
24539
|
}
|
|
24473
24540
|
};
|
|
@@ -24479,12 +24546,12 @@ var CLAUDE_MANAGED = {
|
|
|
24479
24546
|
};
|
|
24480
24547
|
function claudeSettingsFiles(cwd, env, platform = process.platform) {
|
|
24481
24548
|
const project = env.CLAUDE_PROJECT_DIR || gitTop(cwd) || cwd;
|
|
24482
|
-
const user = env.CLAUDE_CONFIG_DIR ||
|
|
24549
|
+
const user = env.CLAUDE_CONFIG_DIR || path35.join(homeOf(env), ".claude");
|
|
24483
24550
|
return [
|
|
24484
24551
|
...CLAUDE_MANAGED[platform] ? [CLAUDE_MANAGED[platform]] : [],
|
|
24485
|
-
|
|
24486
|
-
|
|
24487
|
-
|
|
24552
|
+
path35.join(user, "settings.json"),
|
|
24553
|
+
path35.join(project, ".claude", "settings.json"),
|
|
24554
|
+
path35.join(project, ".claude", "settings.local.json")
|
|
24488
24555
|
];
|
|
24489
24556
|
}
|
|
24490
24557
|
var bashPattern = (entry) => {
|
|
@@ -24574,10 +24641,10 @@ var opencodeConfig = (value, rules) => {
|
|
|
24574
24641
|
function opencodeRules(cwd, env = process.env) {
|
|
24575
24642
|
const rules = EMPTY2();
|
|
24576
24643
|
try {
|
|
24577
|
-
const config = env.XDG_CONFIG_HOME ||
|
|
24644
|
+
const config = env.XDG_CONFIG_HOME || path35.join(homeOf(env), ".config");
|
|
24578
24645
|
const files = [
|
|
24579
|
-
...OPENCODE_NAMES.map((name) =>
|
|
24580
|
-
...projectDirs(cwd).flatMap((dir) => OPENCODE_NAMES.flatMap((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)])),
|
|
24581
24648
|
...env.OPENCODE_CONFIG ? [env.OPENCODE_CONFIG] : []
|
|
24582
24649
|
];
|
|
24583
24650
|
for (const file of files) {
|
|
@@ -24621,9 +24688,9 @@ var codexRule = (body) => {
|
|
|
24621
24688
|
function codexRules(cwd, env = process.env) {
|
|
24622
24689
|
const rules = EMPTY2();
|
|
24623
24690
|
try {
|
|
24624
|
-
const home = env.CODEX_HOME ||
|
|
24691
|
+
const home = env.CODEX_HOME || path35.join(homeOf(env), ".codex");
|
|
24625
24692
|
const top = gitTop(cwd) ?? cwd;
|
|
24626
|
-
for (const dir of [
|
|
24693
|
+
for (const dir of [path35.join(home, "rules"), path35.join(top, ".codex", "rules")]) {
|
|
24627
24694
|
let files;
|
|
24628
24695
|
try {
|
|
24629
24696
|
files = fs23.readdirSync(dir).filter((name) => name.endsWith(".rules"));
|
|
@@ -24633,7 +24700,7 @@ function codexRules(cwd, env = process.env) {
|
|
|
24633
24700
|
return "unreadable";
|
|
24634
24701
|
}
|
|
24635
24702
|
for (const name of files) {
|
|
24636
|
-
const text = readText3(
|
|
24703
|
+
const text = readText3(path35.join(dir, name)) ?? "";
|
|
24637
24704
|
for (const part of text.split(/\bprefix_rule\s*\(/u).slice(1)) {
|
|
24638
24705
|
const rule = codexRule(part);
|
|
24639
24706
|
if (!rule)
|
|
@@ -24652,8 +24719,8 @@ function cursorRules(cwd, env = process.env) {
|
|
|
24652
24719
|
try {
|
|
24653
24720
|
const top = gitTop(cwd) ?? cwd;
|
|
24654
24721
|
for (const file of [
|
|
24655
|
-
|
|
24656
|
-
|
|
24722
|
+
path35.join(homeOf(env), ".cursor", "cli-config.json"),
|
|
24723
|
+
path35.join(top, ".cursor", "cli.json")
|
|
24657
24724
|
]) {
|
|
24658
24725
|
const text = readText3(file);
|
|
24659
24726
|
if (text === null)
|
|
@@ -24728,10 +24795,10 @@ function wrapAllowed(read, words, command, options = {}) {
|
|
|
24728
24795
|
|
|
24729
24796
|
// packages/workit-core/src/core/heavy.ts
|
|
24730
24797
|
import fs24 from "node:fs";
|
|
24731
|
-
import
|
|
24798
|
+
import path36 from "node:path";
|
|
24732
24799
|
var stateDir2 = (env, platform = process.platform) => stateDir(env, platform);
|
|
24733
24800
|
var HEAVY_COMMANDS_FILE = "heavy-commands.json";
|
|
24734
|
-
var heavyCommandsFile = (env) =>
|
|
24801
|
+
var heavyCommandsFile = (env) => path36.join(stateDir2(env), HEAVY_COMMANDS_FILE);
|
|
24735
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;
|
|
24736
24803
|
var INFO_FLAGS = new Set(["--version", "-v", "-V", "--help", "-h", "help", "version"]);
|
|
24737
24804
|
var WATCH_FLAG = /^(?:--watch(?:All)?(?:=.*)?|-w|--serve)$/u;
|
|
@@ -25006,7 +25073,7 @@ function machinePatterns(env) {
|
|
|
25006
25073
|
return isRecord5(value) ? stringList(value.patterns) : [];
|
|
25007
25074
|
}
|
|
25008
25075
|
function repoPatterns(cwd) {
|
|
25009
|
-
return repoHeavyCommands(gitTop(cwd) ??
|
|
25076
|
+
return repoHeavyCommands(gitTop(cwd) ?? path36.resolve(cwd));
|
|
25010
25077
|
}
|
|
25011
25078
|
function heavyLines(lines, options) {
|
|
25012
25079
|
const found = [];
|
|
@@ -25084,12 +25151,12 @@ function heavyPlan(command, options) {
|
|
|
25084
25151
|
}
|
|
25085
25152
|
function workitOnPath2(env = process.env) {
|
|
25086
25153
|
const names = process.platform === "win32" ? ["workit.exe", "workit.cmd", "workit"] : ["workit"];
|
|
25087
|
-
for (const dir of (env.PATH ?? "").split(
|
|
25154
|
+
for (const dir of (env.PATH ?? "").split(path36.delimiter))
|
|
25088
25155
|
for (const name of names) {
|
|
25089
25156
|
if (!dir)
|
|
25090
25157
|
continue;
|
|
25091
25158
|
try {
|
|
25092
|
-
fs24.accessSync(
|
|
25159
|
+
fs24.accessSync(path36.join(dir, name), fs24.constants.X_OK);
|
|
25093
25160
|
return true;
|
|
25094
25161
|
} catch {}
|
|
25095
25162
|
}
|
|
@@ -25107,7 +25174,7 @@ function leaseRewrite(command) {
|
|
|
25107
25174
|
|
|
25108
25175
|
// packages/workit-core/src/core/heavy-words.ts
|
|
25109
25176
|
import fs25 from "node:fs";
|
|
25110
|
-
import
|
|
25177
|
+
import path37 from "node:path";
|
|
25111
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(" "));
|
|
25112
25179
|
var wordsOf = (command) => command.split(/[\s;&|()<>`'"]+/u).map((word) => (word.split(/[\\/]/u).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd|bat)$/u, "")).filter(Boolean);
|
|
25113
25180
|
var stateDir3 = (env) => stateDir(env);
|
|
@@ -25120,15 +25187,15 @@ var readJson2 = (file) => {
|
|
|
25120
25187
|
};
|
|
25121
25188
|
var patternWords = (cwd, env) => {
|
|
25122
25189
|
const patterns = [];
|
|
25123
|
-
const machine = readJson2(
|
|
25190
|
+
const machine = readJson2(path37.join(stateDir3(env), "heavy-commands.json"));
|
|
25124
25191
|
if (Array.isArray(machine?.patterns))
|
|
25125
25192
|
patterns.push(...machine.patterns);
|
|
25126
|
-
for (let dir =
|
|
25127
|
-
if (fs25.existsSync(
|
|
25193
|
+
for (let dir = path37.resolve(cwd);; dir = path37.dirname(dir)) {
|
|
25194
|
+
if (fs25.existsSync(path37.join(dir, ".git"))) {
|
|
25128
25195
|
patterns.push(...repoHeavyCommands(dir));
|
|
25129
25196
|
break;
|
|
25130
25197
|
}
|
|
25131
|
-
if (
|
|
25198
|
+
if (path37.dirname(dir) === dir)
|
|
25132
25199
|
break;
|
|
25133
25200
|
}
|
|
25134
25201
|
const words = new Set;
|
|
@@ -25204,14 +25271,14 @@ var splitDenial = (plan) => ({
|
|
|
25204
25271
|
// packages/workit-core/src/hooks/write-gate.ts
|
|
25205
25272
|
import { existsSync as existsSync12, realpathSync as realpathSync9, statSync as statSync3 } from "node:fs";
|
|
25206
25273
|
import os10 from "node:os";
|
|
25207
|
-
import
|
|
25274
|
+
import path39 from "node:path";
|
|
25208
25275
|
|
|
25209
25276
|
// packages/workit-core/src/core/live-session.ts
|
|
25210
25277
|
import { spawnSync as spawnSync22 } from "node:child_process";
|
|
25211
25278
|
import { createHash as createHash17 } from "node:crypto";
|
|
25212
25279
|
import fs26 from "node:fs";
|
|
25213
25280
|
import os9 from "node:os";
|
|
25214
|
-
import
|
|
25281
|
+
import path38 from "node:path";
|
|
25215
25282
|
var LIVE_SESSION_TTL_MS = 15 * 60000;
|
|
25216
25283
|
var HEARTBEAT_EVERY_MS = 30000;
|
|
25217
25284
|
var liveProbe = {
|
|
@@ -25285,15 +25352,15 @@ var liveOwner = (input, transport, env = process.env) => {
|
|
|
25285
25352
|
};
|
|
25286
25353
|
};
|
|
25287
25354
|
var checkoutOf = (target) => {
|
|
25288
|
-
let dir =
|
|
25289
|
-
while (!fs26.existsSync(dir) &&
|
|
25290
|
-
dir =
|
|
25355
|
+
let dir = path38.resolve(target);
|
|
25356
|
+
while (!fs26.existsSync(dir) && path38.dirname(dir) !== dir)
|
|
25357
|
+
dir = path38.dirname(dir);
|
|
25291
25358
|
if (fs26.existsSync(dir) && !fs26.statSync(dir).isDirectory())
|
|
25292
|
-
dir =
|
|
25293
|
-
const parts = dir.split(
|
|
25359
|
+
dir = path38.dirname(dir);
|
|
25360
|
+
const parts = dir.split(path38.sep);
|
|
25294
25361
|
const dotGit = parts.lastIndexOf(".git");
|
|
25295
25362
|
if (dotGit > 0)
|
|
25296
|
-
dir = parts.slice(0, dotGit).join(
|
|
25363
|
+
dir = parts.slice(0, dotGit).join(path38.sep) || path38.sep;
|
|
25297
25364
|
const location = resolveStore(dir);
|
|
25298
25365
|
if (location instanceof Error || !location.shared || !location.top)
|
|
25299
25366
|
return null;
|
|
@@ -25303,9 +25370,9 @@ var checkoutOf = (target) => {
|
|
|
25303
25370
|
} catch {}
|
|
25304
25371
|
return top;
|
|
25305
25372
|
};
|
|
25306
|
-
var markerFile2 = (top) =>
|
|
25373
|
+
var markerFile2 = (top) => path38.join(resolveStateDir(), "live-sessions", `${createHash17("sha256").update(checkoutKey(top)).digest("hex").slice(0, 32)}.json`);
|
|
25307
25374
|
var checkoutKey = (top, platform = process.platform) => {
|
|
25308
|
-
let key =
|
|
25375
|
+
let key = path38.resolve(top);
|
|
25309
25376
|
try {
|
|
25310
25377
|
key = fs26.realpathSync.native(key);
|
|
25311
25378
|
} catch {}
|
|
@@ -25400,7 +25467,7 @@ var claimLiveSession = (target, owner, deps = {}) => {
|
|
|
25400
25467
|
checkout,
|
|
25401
25468
|
heartbeatAt: now.toISOString()
|
|
25402
25469
|
};
|
|
25403
|
-
fs26.mkdirSync(
|
|
25470
|
+
fs26.mkdirSync(path38.dirname(file), { recursive: true });
|
|
25404
25471
|
const temp = `${file}.${process.pid}.tmp`;
|
|
25405
25472
|
fs26.writeFileSync(temp, JSON.stringify(marker));
|
|
25406
25473
|
fs26.renameSync(temp, file);
|
|
@@ -25412,22 +25479,22 @@ var NONE3 = { kind: "none" };
|
|
|
25412
25479
|
var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "win32";
|
|
25413
25480
|
var canonical3 = (file) => {
|
|
25414
25481
|
let rest = "";
|
|
25415
|
-
for (let dir =
|
|
25482
|
+
for (let dir = path39.resolve(file);; dir = path39.dirname(dir)) {
|
|
25416
25483
|
try {
|
|
25417
|
-
return
|
|
25484
|
+
return path39.join(realpathSync9.native(dir), rest);
|
|
25418
25485
|
} catch {
|
|
25419
|
-
if (
|
|
25420
|
-
return
|
|
25421
|
-
rest = rest ?
|
|
25486
|
+
if (path39.dirname(dir) === dir)
|
|
25487
|
+
return path39.resolve(file);
|
|
25488
|
+
rest = rest ? path39.join(path39.basename(dir), rest) : path39.basename(dir);
|
|
25422
25489
|
}
|
|
25423
25490
|
}
|
|
25424
25491
|
};
|
|
25425
25492
|
var exempt = (cwd, root, file, plans) => {
|
|
25426
25493
|
const fold = (value) => CASE_INSENSITIVE ? value.toLowerCase() : value;
|
|
25427
|
-
const relative =
|
|
25428
|
-
if (relative.startsWith("..") ||
|
|
25494
|
+
const relative = path39.relative(fold(canonical3(root)), fold(canonical3(path39.resolve(cwd, file))));
|
|
25495
|
+
if (relative.startsWith("..") || path39.isAbsolute(relative))
|
|
25429
25496
|
return true;
|
|
25430
|
-
const posix = relative.split(
|
|
25497
|
+
const posix = relative.split(path39.sep).join("/");
|
|
25431
25498
|
const segments = posix.split("/");
|
|
25432
25499
|
return /\.mdx?$/i.test(posix) || segments[0] === "docs" || segments.includes("plans") || [...plans].some((plan) => fold(plan) === posix);
|
|
25433
25500
|
};
|
|
@@ -25778,10 +25845,10 @@ var linkSources = (args, at) => {
|
|
|
25778
25845
|
const sources = names.filter((name, index) => into >= 0 ? name !== dest : index < names.length - 1 || names.length === 1);
|
|
25779
25846
|
const target = dest === undefined ? null : at(dest);
|
|
25780
25847
|
const symbolic = args.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg));
|
|
25781
|
-
const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target :
|
|
25848
|
+
const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target : path39.dirname(target);
|
|
25782
25849
|
return sources.flatMap((source) => {
|
|
25783
|
-
if (symbolic && base !== null && !
|
|
25784
|
-
return [
|
|
25850
|
+
if (symbolic && base !== null && !path39.isAbsolute(homeExpanded(source)))
|
|
25851
|
+
return [path39.resolve(base, source)];
|
|
25785
25852
|
const resolved = at(source);
|
|
25786
25853
|
return resolved ? [resolved] : [];
|
|
25787
25854
|
});
|
|
@@ -25810,7 +25877,7 @@ var shellWrites = (command, depth = 0) => {
|
|
|
25810
25877
|
return { writes: true, targets: unknown ? null : targets };
|
|
25811
25878
|
};
|
|
25812
25879
|
var cache3 = new Map;
|
|
25813
|
-
var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(
|
|
25880
|
+
var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path39.resolve(root, file)) ?? "-").join("\x00");
|
|
25814
25881
|
var gateFor = (cwd) => {
|
|
25815
25882
|
const store = new TaskStore(cwd);
|
|
25816
25883
|
const listed = store.listTaskIndex();
|
|
@@ -25890,13 +25957,13 @@ var gitMutationDirs = (cwd, command, dialect) => {
|
|
|
25890
25957
|
return [];
|
|
25891
25958
|
if (sub === "stash" && ["list", "show"].includes(rest[0] ?? ""))
|
|
25892
25959
|
return [];
|
|
25893
|
-
return [
|
|
25960
|
+
return [path39.resolve(cwd, invocation.dir ?? ".")];
|
|
25894
25961
|
});
|
|
25895
25962
|
};
|
|
25896
25963
|
var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
|
|
25897
25964
|
var PUSHD2 = new Set(["pushd", "push-location"]);
|
|
25898
25965
|
var POPD2 = new Set(["popd", "pop-location"]);
|
|
25899
|
-
var UNKNOWN_DIR =
|
|
25966
|
+
var UNKNOWN_DIR = path39.resolve(path39.parse(process.cwd()).root, ".workit-unknown-dir");
|
|
25900
25967
|
var cdInto = (dir, words, strict = false, vars = new Map) => {
|
|
25901
25968
|
const lost = strict ? UNKNOWN_DIR : undefined;
|
|
25902
25969
|
const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
|
|
@@ -25906,7 +25973,7 @@ var cdInto = (dir, words, strict = false, vars = new Map) => {
|
|
|
25906
25973
|
return lost;
|
|
25907
25974
|
if (dir === undefined)
|
|
25908
25975
|
return lost;
|
|
25909
|
-
return target === undefined ? os10.homedir() :
|
|
25976
|
+
return target === undefined ? os10.homedir() : path39.resolve(dir, target);
|
|
25910
25977
|
};
|
|
25911
25978
|
var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
25912
25979
|
var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
|
|
@@ -26040,7 +26107,7 @@ var untrustedVars = (segments) => {
|
|
|
26040
26107
|
}
|
|
26041
26108
|
return { all, names };
|
|
26042
26109
|
};
|
|
26043
|
-
var UNKNOWN_VAR =
|
|
26110
|
+
var UNKNOWN_VAR = path39.resolve(path39.parse(process.cwd()).root, ".workit-unknown-var");
|
|
26044
26111
|
var REFERENCE = /\$\{(\w+)[^}]*\}|\$(\w+)|\$\([^)]*\)?|`[^`]*`?/g;
|
|
26045
26112
|
var unresolvedRefs = (text) => [
|
|
26046
26113
|
...new Set([...text.matchAll(REFERENCE)].map((match) => {
|
|
@@ -26050,7 +26117,7 @@ var unresolvedRefs = (text) => [
|
|
|
26050
26117
|
];
|
|
26051
26118
|
var unknownVarTarget = (text) => {
|
|
26052
26119
|
const refs = unresolvedRefs(text);
|
|
26053
|
-
return
|
|
26120
|
+
return path39.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
|
|
26054
26121
|
};
|
|
26055
26122
|
var applyOperator = (value, operator) => {
|
|
26056
26123
|
if (operator === "")
|
|
@@ -26110,12 +26177,12 @@ var mktempPath = (value, dir) => {
|
|
|
26110
26177
|
if (base === null && (temp || template === undefined))
|
|
26111
26178
|
base = os10.tmpdir();
|
|
26112
26179
|
const name = homeExpanded(template ?? "tmp.XXXXXXXXXX");
|
|
26113
|
-
if (
|
|
26180
|
+
if (path39.isAbsolute(name))
|
|
26114
26181
|
return name;
|
|
26115
26182
|
const from = base === null ? dir : homeExpanded(base);
|
|
26116
|
-
if (from === undefined || !
|
|
26183
|
+
if (from === undefined || !path39.isAbsolute(from) && dir === undefined)
|
|
26117
26184
|
return null;
|
|
26118
|
-
return
|
|
26185
|
+
return path39.resolve(dir ?? from, from, name);
|
|
26119
26186
|
};
|
|
26120
26187
|
var homeExpanded = (file) => {
|
|
26121
26188
|
const match = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(file);
|
|
@@ -26135,9 +26202,9 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
26135
26202
|
const home = homeExpanded(text);
|
|
26136
26203
|
if (strict && unresolvedRefs(home).length > 0)
|
|
26137
26204
|
return [unknownVarTarget(home)];
|
|
26138
|
-
if (
|
|
26205
|
+
if (path39.isAbsolute(home))
|
|
26139
26206
|
return [home];
|
|
26140
|
-
return base === undefined ? [] : [
|
|
26207
|
+
return base === undefined ? [] : [path39.resolve(base, home)];
|
|
26141
26208
|
});
|
|
26142
26209
|
const at = (file) => {
|
|
26143
26210
|
const all = atAll(file);
|
|
@@ -26170,7 +26237,12 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
26170
26237
|
};
|
|
26171
26238
|
for (const segment of segments) {
|
|
26172
26239
|
if (segment.group === "open") {
|
|
26173
|
-
groups.push({
|
|
26240
|
+
groups.push({
|
|
26241
|
+
dir,
|
|
26242
|
+
stack: [...stack],
|
|
26243
|
+
vars: new Map(vars),
|
|
26244
|
+
loops: new Map(loops)
|
|
26245
|
+
});
|
|
26174
26246
|
continue;
|
|
26175
26247
|
}
|
|
26176
26248
|
if (segment.group === "close") {
|
|
@@ -26279,7 +26351,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
26279
26351
|
const here = segment.unanalyzable ? DIR_TARGET : `${OPAQUE_TARGET}${encodeURIComponent(runner?.split(/[\\/]/).at(-1) ?? "a command")}`;
|
|
26280
26352
|
for (const file of opaque ?? [])
|
|
26281
26353
|
for (const resolved of atAll(file))
|
|
26282
|
-
targets.push(file === "." ?
|
|
26354
|
+
targets.push(file === "." ? path39.join(resolved, here) : resolved);
|
|
26283
26355
|
const ln = words.findIndex((word) => /^ln$/i.test(word.split(/[\\/]/).at(-1) ?? ""));
|
|
26284
26356
|
if (ln >= 0 && words.slice(0, ln).every((word) => PREFIXES2.has(word)))
|
|
26285
26357
|
targets.push(...linkSources(words.slice(ln + 1), at));
|
|
@@ -26290,7 +26362,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
26290
26362
|
const edits = editsOf(body);
|
|
26291
26363
|
if (edits === null) {
|
|
26292
26364
|
if (dir !== undefined)
|
|
26293
|
-
targets.push(
|
|
26365
|
+
targets.push(path39.join(dir, DIR_TARGET));
|
|
26294
26366
|
} else
|
|
26295
26367
|
for (const file of edits)
|
|
26296
26368
|
targets.push(...atAll(file));
|
|
@@ -26298,7 +26370,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
26298
26370
|
for (const invocation of workitInvocations(body.map(quoteWord2).join(" "), "posix")) {
|
|
26299
26371
|
const { at: runsIn, args } = workitCwd(dir, invocation, atAll);
|
|
26300
26372
|
if (args[0] === "git" && MUTATING_WORKIT_GIT.has(args[1] ?? "") && !inert(args.slice(2), ""))
|
|
26301
|
-
targets.push(...runsIn.map((runs) =>
|
|
26373
|
+
targets.push(...runsIn.map((runs) => path39.join(runs, DIR_TARGET)));
|
|
26302
26374
|
}
|
|
26303
26375
|
}
|
|
26304
26376
|
return targets;
|
|
@@ -26319,7 +26391,7 @@ var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) =>
|
|
|
26319
26391
|
try {
|
|
26320
26392
|
return [
|
|
26321
26393
|
...segmentTargets(cwd, command, dialect, 0, strict),
|
|
26322
|
-
...gitMutationDirs(cwd, command, dialect).map((dir) =>
|
|
26394
|
+
...gitMutationDirs(cwd, command, dialect).map((dir) => path39.join(dir, DIR_TARGET))
|
|
26323
26395
|
];
|
|
26324
26396
|
} catch {
|
|
26325
26397
|
return [];
|
|
@@ -26356,7 +26428,7 @@ var liveDeny = ({ marker, checkout, ageMs, file }) => {
|
|
|
26356
26428
|
var guarded = (targets) => {
|
|
26357
26429
|
const seen = new Set;
|
|
26358
26430
|
return targets.filter((target) => {
|
|
26359
|
-
const dir =
|
|
26431
|
+
const dir = path39.dirname(target);
|
|
26360
26432
|
if (seen.has(dir))
|
|
26361
26433
|
return false;
|
|
26362
26434
|
seen.add(dir);
|
|
@@ -26377,40 +26449,61 @@ var claimAll = (owner, targets, deps) => {
|
|
|
26377
26449
|
for (const target of guarded(targets))
|
|
26378
26450
|
claimLiveSession(target, owner, deps);
|
|
26379
26451
|
};
|
|
26380
|
-
var liveTargets = (cwd, paths) => paths?.length ? paths.map((file) =>
|
|
26381
|
-
var
|
|
26452
|
+
var liveTargets = (cwd, paths) => paths?.length ? paths.map((file) => path39.resolve(cwd, file)) : [path39.join(cwd, DIR_TARGET)];
|
|
26453
|
+
var registryTarget = (cwd, targets) => {
|
|
26382
26454
|
const state = resolveStateDir();
|
|
26383
|
-
const
|
|
26384
|
-
|
|
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;
|
|
26385
26461
|
};
|
|
26386
|
-
var
|
|
26462
|
+
var underRegistry = (state, cwd, target, platform = process.platform, real = (file) => file) => {
|
|
26387
26463
|
const win = platform === "win32";
|
|
26388
|
-
const p = win ?
|
|
26464
|
+
const p = win ? path39.win32 : path39.posix;
|
|
26389
26465
|
const fold = (value) => win || platform === "darwin" ? value.toLowerCase() : value;
|
|
26390
26466
|
const named = win ? target.replace(/^\/([a-zA-Z])(?=\/|$)/, "$1:") : target;
|
|
26391
26467
|
const relative = p.relative(fold(real(p.resolve(state))), fold(real(p.resolve(cwd, named))));
|
|
26392
26468
|
if (relative.startsWith("..") || p.isAbsolute(relative))
|
|
26393
|
-
return
|
|
26394
|
-
|
|
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;
|
|
26395
26474
|
};
|
|
26396
|
-
var
|
|
26475
|
+
var unquotedWindowsRegistry = (command) => {
|
|
26397
26476
|
if (process.platform !== "win32" || !command.includes("\\"))
|
|
26398
|
-
return
|
|
26477
|
+
return null;
|
|
26399
26478
|
const flat = (value) => value.replaceAll("\\", "/").toLowerCase();
|
|
26400
|
-
|
|
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
|
+
}
|
|
26401
26493
|
};
|
|
26402
|
-
var
|
|
26403
|
-
const
|
|
26494
|
+
var registryDeny = ({ file, registry }) => {
|
|
26495
|
+
const { label, unblock } = REGISTRY_DENY[registry];
|
|
26496
|
+
const what = registry === "issued" ? "issued-session state" : "host-approval state";
|
|
26404
26497
|
return {
|
|
26405
26498
|
kind: "deny",
|
|
26406
|
-
reason: `workit
|
|
26499
|
+
reason: `workit ${label}: ${file} is under Workit's ${what}. ${unblock}`,
|
|
26407
26500
|
unblock
|
|
26408
26501
|
};
|
|
26409
26502
|
};
|
|
26410
26503
|
function writeGate(cwd, paths, owner, deps) {
|
|
26411
|
-
const forged = paths?.length ?
|
|
26504
|
+
const forged = paths?.length ? registryTarget(cwd, paths) : null;
|
|
26412
26505
|
if (forged)
|
|
26413
|
-
return
|
|
26506
|
+
return registryDeny(forged);
|
|
26414
26507
|
if (!owner)
|
|
26415
26508
|
return beforeWriteGate(cwd, paths);
|
|
26416
26509
|
const targets = liveTargets(cwd, paths);
|
|
@@ -26424,9 +26517,10 @@ function writeGate(cwd, paths, owner, deps) {
|
|
|
26424
26517
|
}
|
|
26425
26518
|
function shellGate(cwd, command, owner, dialect = "posix", deps) {
|
|
26426
26519
|
try {
|
|
26427
|
-
const
|
|
26520
|
+
const windows = unquotedWindowsRegistry(command);
|
|
26521
|
+
const forged = registryTarget(cwd, segmentTargets(cwd, command, dialect)) ?? (windows ? { file: `the ${windows} registry`, registry: windows } : null);
|
|
26428
26522
|
if (forged)
|
|
26429
|
-
return
|
|
26523
|
+
return registryDeny(forged);
|
|
26430
26524
|
} catch {}
|
|
26431
26525
|
const writes = shellWrites(command);
|
|
26432
26526
|
let targets = [];
|
|
@@ -26479,10 +26573,10 @@ import { spawnSync as spawnSync23 } from "node:child_process";
|
|
|
26479
26573
|
|
|
26480
26574
|
// packages/workit-core/src/ci-waiter.ts
|
|
26481
26575
|
import fs27 from "node:fs";
|
|
26482
|
-
import
|
|
26576
|
+
import path40 from "node:path";
|
|
26483
26577
|
var waiterFile = (cwd, pr) => {
|
|
26484
26578
|
const common = gitCommonDir(cwd);
|
|
26485
|
-
return common ?
|
|
26579
|
+
return common ? path40.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
|
|
26486
26580
|
};
|
|
26487
26581
|
var pidAlive2 = (pid) => {
|
|
26488
26582
|
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
@@ -26821,40 +26915,37 @@ var SKILL_HOST = {
|
|
|
26821
26915
|
};
|
|
26822
26916
|
var PROMPT_INTENTS = [
|
|
26823
26917
|
[
|
|
26824
|
-
"
|
|
26825
|
-
/\b(flaky|regressed|(
|
|
26826
|
-
],
|
|
26827
|
-
[
|
|
26828
|
-
"workit-continue",
|
|
26829
|
-
/\b(pick up where|where (?:were|did) we|resume (?:the|this|my|our|work|where)|hand ?off)\b/i
|
|
26918
|
+
"debug",
|
|
26919
|
+
/\b(flaky|regressed|(is|introduced) a regression|regression (in|after|since|from)|(is|are|got|looks) broken|debug (this|it|the|why)|fix (the|this|a) bug)\b/i
|
|
26830
26920
|
],
|
|
26831
26921
|
[
|
|
26832
|
-
"
|
|
26833
|
-
/\b(
|
|
26922
|
+
"continue",
|
|
26923
|
+
/\b(pick up where|where (were|did) we|resume (the|this|my|our|work|where)|hand ?off)\b/i
|
|
26834
26924
|
],
|
|
26835
26925
|
[
|
|
26836
|
-
"
|
|
26837
|
-
/\b(
|
|
26926
|
+
"review",
|
|
26927
|
+
/\b(blast radius|code review|review (the|this|my|PR|pr|#\d+|branch|diff|changes))\b/i
|
|
26838
26928
|
],
|
|
26839
|
-
["workit-bdd", /\b(BDD|TDD|acceptance criteria|Given\/When\/Then)(?![\w/])/],
|
|
26840
|
-
["workit-test-audit", /\b(test audit|audit the tests|tautolog\w*|weak tests)\b/i],
|
|
26841
|
-
["workit-deslop", /\b(deslop|slop|dead code)\b/i],
|
|
26842
26929
|
[
|
|
26843
|
-
"
|
|
26844
|
-
/\b(
|
|
26930
|
+
"ship",
|
|
26931
|
+
/\b(ship (it|this|the)|babysit|open (a|the) (PR|pr|MR|mr)(?=\s*$|\s+(for|to|on|with|and|against|into|from|after|once)\b|[.!,;])|merge (the|this|my) (PR|pr|MR|mr|branch)|(get|until|make) CI (is )?green)\b/i
|
|
26845
26932
|
],
|
|
26846
|
-
["
|
|
26847
|
-
["
|
|
26848
|
-
["
|
|
26933
|
+
["bdd", /\b(BDD|TDD|acceptance criteria|Given\/When\/Then)(?![\w/])/],
|
|
26934
|
+
["test-audit", /\b(test audit|audit the tests|tautolog\w*|weak tests)\b/i],
|
|
26935
|
+
["deslop", /\b(deslop|slop|dead code)\b/i],
|
|
26936
|
+
["fanout", /\b(fan( |-)?out|parallelize|parallel agents|agent swarm|swarm of agents)\b/i],
|
|
26937
|
+
["verify-app", /\b(verify the app|smoke test|prove it works)\b/i],
|
|
26938
|
+
["retro", /\b((a|the) retro(?![-\w]|\.\w)|retrospective)/i],
|
|
26939
|
+
["architecture", /\b(deepen (the )?modules|architecture (review|pass|audit))\b/i],
|
|
26849
26940
|
[
|
|
26850
|
-
"
|
|
26851
|
-
/\b(brainstorm\w*|grill me|should we|let'?s plan|plan (
|
|
26941
|
+
"shape",
|
|
26942
|
+
/\b(brainstorm\w*|grill me|should we|let'?s plan|plan (out|how|the|a|for)|(write|draft) (a|the) spec)\b/i
|
|
26852
26943
|
],
|
|
26853
26944
|
[
|
|
26854
|
-
"
|
|
26855
|
-
/\b(implement (
|
|
26945
|
+
"implement",
|
|
26946
|
+
/\b(implement (the|this|a|it)|add (a|the) feature|build (a|an|the) (new )?(feature|command|verb|page|endpoint|component|cli|tool))\b/i
|
|
26856
26947
|
]
|
|
26857
|
-
];
|
|
26948
|
+
].map(([name, pattern]) => [`workit-${name}`, pattern]);
|
|
26858
26949
|
var workitSkillOf = (name) => {
|
|
26859
26950
|
const bare = name.trim().replace(/^\//, "").toLowerCase();
|
|
26860
26951
|
const alias = WORKIT_SKILL_ALIASES[bare];
|
|
@@ -26863,10 +26954,13 @@ var workitSkillOf = (name) => {
|
|
|
26863
26954
|
const skill = bare.replace(/^workit:/, "workit-");
|
|
26864
26955
|
return WORKIT_METHOD_SKILLS.includes(skill) ? skill : null;
|
|
26865
26956
|
};
|
|
26957
|
+
var QUOTED = /```[\s\S]*?```|["`“][^"`”\n]*["`”]|\B'[^'\n]*'\B/g;
|
|
26958
|
+
var COMPLAINT = /\b(why \w+ you|you keep|stop \w+ing)\b.*?(?=\b(and|but)\b|[?.,;\n]|$)/gi;
|
|
26866
26959
|
var promptTrigger = (prompt) => {
|
|
26867
|
-
|
|
26960
|
+
let asking = false;
|
|
26961
|
+
const text = prompt.slice(0, 4000).replace(QUOTED, " ").replace(COMPLAINT, (clause) => (asking ||= /ask|quest/i.test(clause), " "));
|
|
26868
26962
|
for (const [skill, pattern] of PROMPT_INTENTS) {
|
|
26869
|
-
const match = pattern.exec(text);
|
|
26963
|
+
const match = !(asking && skill === "workit-shape") && pattern.exec(text);
|
|
26870
26964
|
if (match)
|
|
26871
26965
|
return { skill, trigger: match[1] ?? match[0] };
|
|
26872
26966
|
}
|
|
@@ -26884,24 +26978,12 @@ var loadedSkills = (cwd, session) => {
|
|
|
26884
26978
|
};
|
|
26885
26979
|
var SKILL_FILE = /(?:^|[\\/])(workit-[a-z-]+)[\\/]SKILL\.md$/;
|
|
26886
26980
|
var skillFileIn = (file) => SKILL_FILE.exec(file)?.[1] ?? null;
|
|
26887
|
-
var READERS = new Set(
|
|
26888
|
-
"cat",
|
|
26889
|
-
"sed",
|
|
26890
|
-
"head",
|
|
26891
|
-
"tail",
|
|
26892
|
-
"less",
|
|
26893
|
-
"more",
|
|
26894
|
-
"bat",
|
|
26895
|
-
"nl",
|
|
26896
|
-
"get-content",
|
|
26897
|
-
"gc",
|
|
26898
|
-
"type"
|
|
26899
|
-
]);
|
|
26981
|
+
var READERS = new Set("cat sed head tail less more bat nl get-content gc type".split(" "));
|
|
26900
26982
|
var skillReadIn = (command, dialect = "posix") => {
|
|
26901
26983
|
for (const { words } of segmentsOf(command, dialect)) {
|
|
26902
26984
|
if (!READERS.has((words[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()))
|
|
26903
26985
|
continue;
|
|
26904
|
-
if (words.some((word) => /^(
|
|
26986
|
+
if (words.some((word) => /^(-i(\.\w+)?|--in-place(=.*)?)$/.test(word)))
|
|
26905
26987
|
continue;
|
|
26906
26988
|
for (const word of words.slice(1)) {
|
|
26907
26989
|
const skill = skillFileIn(word);
|
|
@@ -26948,9 +27030,9 @@ var nudgeOnce = (input, session, skill, line) => {
|
|
|
26948
27030
|
writeSessionMarker(file, { ...marker, nudged: [...marker.nudged, skill] });
|
|
26949
27031
|
return line;
|
|
26950
27032
|
};
|
|
26951
|
-
var nudgeText = (input, skill, why) =>
|
|
27033
|
+
var nudgeText = (input, skill, why) => `Workit: ${why} looks like ${skill} work${USER_INVOKED.has(skill) ? `, which the user starts; offer it (/${skill.replace(/^workit-/, "wk-")}) rather than loading it.` : `; if it is, ${skillLoadWording(SKILL_HOST[input.host], skill)} first.`}`;
|
|
26952
27034
|
var promptLoads = (prompt) => /^\s*\/(?:skill:)?([\w:-]+)/.exec(prompt)?.[1] ?? /^\s*<skill name="([\w:-]+)"/.exec(prompt)?.[1] ?? /^\s*Load the (workit-[a-z-]+) skill with the skill tool\b/.exec(prompt)?.[1] ?? null;
|
|
26953
|
-
var relayedMessage = (prompt) => /^\s*(
|
|
27035
|
+
var relayedMessage = (prompt) => /^\s*(Another Claude session sent a message\b|<agent-message\s+from=|\[SYSTEM NOTIFICATION\b|<task-notification>)/.test(prompt);
|
|
26954
27036
|
function promptNudge(input, prompt) {
|
|
26955
27037
|
try {
|
|
26956
27038
|
const session = input.session.id;
|
|
@@ -26969,7 +27051,7 @@ function promptNudge(input, prompt) {
|
|
|
26969
27051
|
return null;
|
|
26970
27052
|
}
|
|
26971
27053
|
}
|
|
26972
|
-
var WORKIT_DELIVERY = /^(
|
|
27054
|
+
var WORKIT_DELIVERY = /^(pr (create|merge)|ci wait|git push)\b/;
|
|
26973
27055
|
var runsWorkitDelivery = (command, dialect) => workitInvocations(command, dialect).some((args) => !args.some((arg) => arg === "--help" || arg === "-h" || arg === "--dry-run") && WORKIT_DELIVERY.test(args.join(" ")));
|
|
26974
27056
|
var isDeliveryCommand = (cwd, command, dialect = "posix") => rawDelivery(cwd, command, dialect) || runsWorkitDelivery(command, dialect) && inWorkitWorkspace(cwd);
|
|
26975
27057
|
function shipNudge(input, command) {
|
|
@@ -27033,7 +27115,179 @@ var writePaths = (input) => {
|
|
|
27033
27115
|
};
|
|
27034
27116
|
// packages/workit-core/src/hooks/standing.ts
|
|
27035
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";
|
|
27036
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.`;
|
|
27037
27291
|
|
|
27038
27292
|
// packages/workit-core/src/hooks/hosts/claude-code.ts
|
|
27039
27293
|
var CLAUDE_CODE_DESCRIPTOR = {
|
|
@@ -27076,7 +27330,11 @@ var CLAUDE_CODE_DESCRIPTOR = {
|
|
|
27076
27330
|
maxConcurrency: "undocumented",
|
|
27077
27331
|
agentPrefix: "workit:"
|
|
27078
27332
|
},
|
|
27079
|
-
provenance: {
|
|
27333
|
+
provenance: {
|
|
27334
|
+
sessionId: "native",
|
|
27335
|
+
agentIdOnTool: "native",
|
|
27336
|
+
postToolObserve: "native"
|
|
27337
|
+
},
|
|
27080
27338
|
interaction: { questions: "undocumented", writeBoundary: "partial" },
|
|
27081
27339
|
stopControl: "native",
|
|
27082
27340
|
shellAvailable: "native",
|
|
@@ -27138,6 +27396,7 @@ var CONTEXT_EVENTS = new Set([
|
|
|
27138
27396
|
"PreToolUse",
|
|
27139
27397
|
"PostToolUse"
|
|
27140
27398
|
]);
|
|
27399
|
+
var ASKING_MODES = new Set(["default", "acceptEdits", "plan"]);
|
|
27141
27400
|
|
|
27142
27401
|
// packages/workit-core/src/hooks/hosts/codex.ts
|
|
27143
27402
|
var CODEX_DESCRIPTOR = {
|
|
@@ -27503,42 +27762,42 @@ function neededChecks(lane, configured) {
|
|
|
27503
27762
|
}
|
|
27504
27763
|
|
|
27505
27764
|
// packages/workit-core/src/hooks/worktree-confine.ts
|
|
27506
|
-
import { createHash as
|
|
27765
|
+
import { createHash as createHash19 } from "node:crypto";
|
|
27507
27766
|
import fs28 from "node:fs";
|
|
27508
|
-
import
|
|
27767
|
+
import path42 from "node:path";
|
|
27509
27768
|
var FANOUT_TOKEN_FILE = "workit-fanout-token";
|
|
27510
27769
|
var NONE5 = { kind: "none" };
|
|
27511
27770
|
var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
|
|
27512
27771
|
var canonical4 = (file) => {
|
|
27513
27772
|
let rest = "";
|
|
27514
|
-
for (let dir =
|
|
27773
|
+
for (let dir = path42.resolve(file);; dir = path42.dirname(dir)) {
|
|
27515
27774
|
try {
|
|
27516
|
-
return
|
|
27775
|
+
return path42.join(fs28.realpathSync.native(dir), rest);
|
|
27517
27776
|
} catch {
|
|
27518
|
-
if (
|
|
27519
|
-
return
|
|
27520
|
-
rest = rest ?
|
|
27777
|
+
if (path42.dirname(dir) === dir)
|
|
27778
|
+
return path42.resolve(file);
|
|
27779
|
+
rest = rest ? path42.join(path42.basename(dir), rest) : path42.basename(dir);
|
|
27521
27780
|
}
|
|
27522
27781
|
}
|
|
27523
27782
|
};
|
|
27524
27783
|
var within = (child, parent) => {
|
|
27525
27784
|
const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
|
|
27526
|
-
const relative =
|
|
27527
|
-
return relative === "" || !relative.startsWith("..") && !
|
|
27785
|
+
const relative = path42.relative(fold(parent), fold(child));
|
|
27786
|
+
return relative === "" || !relative.startsWith("..") && !path42.isAbsolute(relative);
|
|
27528
27787
|
};
|
|
27529
27788
|
var checkoutOf2 = (file) => {
|
|
27530
|
-
for (let dir = canonical4(file);; dir =
|
|
27531
|
-
const dotGit =
|
|
27789
|
+
for (let dir = canonical4(file);; dir = path42.dirname(dir)) {
|
|
27790
|
+
const dotGit = path42.join(dir, ".git");
|
|
27532
27791
|
if (fs28.existsSync(dotGit)) {
|
|
27533
27792
|
if (!fs28.statSync(dotGit).isFile())
|
|
27534
27793
|
return { root: dir, workit: false };
|
|
27535
27794
|
const admin = /^gitdir:\s*(.+)$/mu.exec(fs28.readFileSync(dotGit, "utf8"))?.[1]?.trim();
|
|
27536
27795
|
return {
|
|
27537
27796
|
root: dir,
|
|
27538
|
-
workit: Boolean(admin) && fs28.existsSync(
|
|
27797
|
+
workit: Boolean(admin) && fs28.existsSync(path42.join(path42.resolve(dir, admin), FANOUT_TOKEN_FILE))
|
|
27539
27798
|
};
|
|
27540
27799
|
}
|
|
27541
|
-
if (
|
|
27800
|
+
if (path42.dirname(dir) === dir)
|
|
27542
27801
|
return null;
|
|
27543
27802
|
}
|
|
27544
27803
|
};
|
|
@@ -27550,8 +27809,8 @@ var workitWorktreeOf = (file) => {
|
|
|
27550
27809
|
return null;
|
|
27551
27810
|
}
|
|
27552
27811
|
};
|
|
27553
|
-
var bindingDir = () =>
|
|
27554
|
-
var bindingFile = (session, agentId) =>
|
|
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`);
|
|
27555
27814
|
var readBinding = (file) => {
|
|
27556
27815
|
try {
|
|
27557
27816
|
const value = JSON.parse(fs28.readFileSync(file, "utf8"));
|
|
@@ -27576,7 +27835,7 @@ var bind = (input, worktree) => {
|
|
|
27576
27835
|
agentId,
|
|
27577
27836
|
at: new Date().toISOString()
|
|
27578
27837
|
};
|
|
27579
|
-
fs28.mkdirSync(
|
|
27838
|
+
fs28.mkdirSync(path42.dirname(file), { recursive: true });
|
|
27580
27839
|
fs28.writeFileSync(file, JSON.stringify(binding));
|
|
27581
27840
|
try {
|
|
27582
27841
|
if (inWorkitWorkspace(input.cwd))
|
|
@@ -27595,31 +27854,31 @@ var hostIsolated = (cwd, agentId) => {
|
|
|
27595
27854
|
const checkout = checkoutOf2(cwd);
|
|
27596
27855
|
if (!checkout)
|
|
27597
27856
|
return false;
|
|
27598
|
-
const dotGit =
|
|
27857
|
+
const dotGit = path42.join(checkout.root, ".git");
|
|
27599
27858
|
if (!fs28.statSync(dotGit).isFile())
|
|
27600
27859
|
return false;
|
|
27601
27860
|
const admin = /^gitdir:\s*(.+)$/mu.exec(fs28.readFileSync(dotGit, "utf8"))?.[1]?.trim();
|
|
27602
27861
|
if (!admin)
|
|
27603
27862
|
return false;
|
|
27604
|
-
const adminDir =
|
|
27605
|
-
const back = fs28.readFileSync(
|
|
27606
|
-
if (
|
|
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)) !== "")
|
|
27607
27866
|
return false;
|
|
27608
|
-
const common =
|
|
27609
|
-
const gitDir = fs28.existsSync(common) ?
|
|
27610
|
-
const expected =
|
|
27611
|
-
return
|
|
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) === "";
|
|
27612
27871
|
} catch {
|
|
27613
27872
|
return false;
|
|
27614
27873
|
}
|
|
27615
27874
|
};
|
|
27616
27875
|
var runnerAt = (target) => {
|
|
27617
|
-
const base =
|
|
27876
|
+
const base = path42.basename(target);
|
|
27618
27877
|
return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
|
|
27619
27878
|
};
|
|
27620
27879
|
var shown = (target) => {
|
|
27621
|
-
const named = /^\.workit-(?:live-target$|runs-)/.test(
|
|
27622
|
-
return
|
|
27880
|
+
const named = /^\.workit-(?:live-target$|runs-)/.test(path42.basename(target)) ? path42.dirname(target) : target;
|
|
27881
|
+
return path42.sep === "\\" ? named.replaceAll("/", "\\") : named;
|
|
27623
27882
|
};
|
|
27624
27883
|
var unboundDeny = (input, target) => {
|
|
27625
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.";
|
|
@@ -27658,7 +27917,7 @@ var literalForm = (command, refs) => {
|
|
|
27658
27917
|
};
|
|
27659
27918
|
var unknownVarDeny = (input, worktree, targets, command) => {
|
|
27660
27919
|
const refs = [
|
|
27661
|
-
...new Set(targets.flatMap((target) =>
|
|
27920
|
+
...new Set(targets.flatMap((target) => path42.relative(UNKNOWN_VAR, path42.resolve(target)).split(path42.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
|
|
27662
27921
|
];
|
|
27663
27922
|
let text = command ?? "";
|
|
27664
27923
|
const first = [];
|
|
@@ -27687,10 +27946,10 @@ function confineImplementer(input, targets, command) {
|
|
|
27687
27946
|
try {
|
|
27688
27947
|
if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
|
|
27689
27948
|
return NONE5;
|
|
27690
|
-
const unresolved = targets.filter((target) => within(
|
|
27949
|
+
const unresolved = targets.filter((target) => within(path42.resolve(target), UNKNOWN_VAR));
|
|
27691
27950
|
if (unresolved.length > 0)
|
|
27692
27951
|
return unknownVarDeny(input, boundWorktree(input), unresolved, command);
|
|
27693
|
-
if (targets.some((target) => within(
|
|
27952
|
+
if (targets.some((target) => within(path42.resolve(target), UNKNOWN_DIR)))
|
|
27694
27953
|
return unknownDirDeny(input, boundWorktree(input));
|
|
27695
27954
|
const bindings = canonical4(bindingDir());
|
|
27696
27955
|
const judged = targets.map((named) => ({ named, real: canonical4(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
|
|
@@ -27800,16 +28059,16 @@ var RUNS = /^(?:sh|bash|zsh|dash|ksh|mksh|ash|python[\d.]*|node|bun|deno|ruby|pe
|
|
|
27800
28059
|
var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print|test|version|help)$|^-[hvV]$/;
|
|
27801
28060
|
var VALUED = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
|
|
27802
28061
|
var commonDir = (root) => {
|
|
27803
|
-
const dotGit =
|
|
28062
|
+
const dotGit = path42.join(root, ".git");
|
|
27804
28063
|
if (!fs28.statSync(dotGit).isFile())
|
|
27805
28064
|
return canonical4(dotGit);
|
|
27806
|
-
const admin =
|
|
27807
|
-
const common =
|
|
27808
|
-
return canonical4(fs28.existsSync(common) ?
|
|
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);
|
|
27809
28068
|
};
|
|
27810
28069
|
var inScratch = (real, repo) => {
|
|
27811
28070
|
const checkout = checkoutOf2(real);
|
|
27812
|
-
return checkout !== null && within(real,
|
|
28071
|
+
return checkout !== null && within(real, path42.join(checkout.root, SCRATCH)) && (repo === null || commonDir(checkout.root) === repo);
|
|
27813
28072
|
};
|
|
27814
28073
|
var JUDGE_VERBS = {
|
|
27815
28074
|
check: true,
|
|
@@ -27838,7 +28097,7 @@ var judgeVerbRefused = (args) => {
|
|
|
27838
28097
|
var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
|
|
27839
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?$/;
|
|
27840
28099
|
var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
|
|
27841
|
-
const name =
|
|
28100
|
+
const name = path42.basename(words[0] ?? "").toLowerCase();
|
|
27842
28101
|
if (name === "alias")
|
|
27843
28102
|
return words.flatMap((word) => {
|
|
27844
28103
|
const set = /^([\w-]+)=(.*)$/s.exec(word);
|
|
@@ -27868,11 +28127,11 @@ var judgeRefusal = (command, fed, depth = 0) => {
|
|
|
27868
28127
|
return why;
|
|
27869
28128
|
}
|
|
27870
28129
|
const { words } = segment;
|
|
27871
|
-
const runs = (word = "") => RUNS.test(
|
|
28130
|
+
const runs = (word = "") => RUNS.test(path42.basename(word).toLowerCase());
|
|
27872
28131
|
let at = 0;
|
|
27873
28132
|
while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
|
|
27874
28133
|
at++;
|
|
27875
|
-
const name =
|
|
28134
|
+
const name = path42.basename(words[at] ?? "").toLowerCase();
|
|
27876
28135
|
const args = words.slice(at + 1);
|
|
27877
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`;
|
|
27878
28137
|
if (/^(?:cd|chdir|pushd|popd)$/.test(name))
|
|
@@ -27950,7 +28209,7 @@ var substitutingHeredoc = (command) => {
|
|
|
27950
28209
|
var judgeDeny = (input, what) => {
|
|
27951
28210
|
const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
|
|
27952
28211
|
const root = checkoutOf2(input.cwd)?.root;
|
|
27953
|
-
const scratch = root ?
|
|
28212
|
+
const scratch = root ? path42.join(root, SCRATCH) : `${SCRATCH}/ at the root of the checkout you judge`;
|
|
27954
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.`;
|
|
27955
28214
|
return {
|
|
27956
28215
|
kind: "deny",
|
|
@@ -27965,7 +28224,7 @@ function confineJudge(input, targets) {
|
|
|
27965
28224
|
const judged = checkoutOf2(input.cwd);
|
|
27966
28225
|
const repo = judged ? commonDir(judged.root) : null;
|
|
27967
28226
|
for (const target of targets) {
|
|
27968
|
-
const resolved =
|
|
28227
|
+
const resolved = path42.resolve(target);
|
|
27969
28228
|
if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
|
|
27970
28229
|
return judgeDeny(input, "it writes to a path Workit cannot resolve (a variable, a command substitution or `cd -`): spell the path out");
|
|
27971
28230
|
if (inScratch(canonical4(target), repo))
|
|
@@ -27996,7 +28255,7 @@ function confineJudgeShell(input, command, dialect = "posix") {
|
|
|
27996
28255
|
let git = [];
|
|
27997
28256
|
try {
|
|
27998
28257
|
git = rawInvocations(command, dialect).flatMap(({ tool, dir, args }) => tool === "git" && (args[0] === "push" || leadOwnedGit(args)) ? [
|
|
27999
|
-
|
|
28258
|
+
path42.join(dir === undefined ? UNKNOWN_DIR : path42.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
|
|
28000
28259
|
] : []);
|
|
28001
28260
|
} catch {}
|
|
28002
28261
|
return confineJudge(input, [
|
|
@@ -28041,7 +28300,7 @@ var judgeChecksLine = (cwd) => {
|
|
|
28041
28300
|
|
|
28042
28301
|
// packages/workit-core/src/hooks/standing.ts
|
|
28043
28302
|
var readPlans = (store) => {
|
|
28044
|
-
const dir =
|
|
28303
|
+
const dir = path43.join(store, "fanouts");
|
|
28045
28304
|
let names;
|
|
28046
28305
|
try {
|
|
28047
28306
|
names = fs29.readdirSync(dir).filter((name) => name.endsWith(".json"));
|
|
@@ -28051,7 +28310,7 @@ var readPlans = (store) => {
|
|
|
28051
28310
|
const plans = [];
|
|
28052
28311
|
for (const name of names) {
|
|
28053
28312
|
try {
|
|
28054
|
-
const raw = JSON.parse(fs29.readFileSync(
|
|
28313
|
+
const raw = JSON.parse(fs29.readFileSync(path43.join(dir, name), "utf8"));
|
|
28055
28314
|
if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
|
|
28056
28315
|
continue;
|
|
28057
28316
|
const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
|
|
@@ -28194,7 +28453,7 @@ var cwdRewrite = (command) => {
|
|
|
28194
28453
|
const rest = match?.[2];
|
|
28195
28454
|
if (!dir || !rest || dir.startsWith("-"))
|
|
28196
28455
|
return null;
|
|
28197
|
-
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "").replaceAll(/'[^']*'|"(
|
|
28456
|
+
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "").replaceAll(/'[^']*'|"([^"\\]|\\.)*"/gu, "")))
|
|
28198
28457
|
return null;
|
|
28199
28458
|
const segments = segmentsOf(rest);
|
|
28200
28459
|
const [head, ...filters] = segments;
|
|
@@ -28207,8 +28466,10 @@ var cwdRewrite = (command) => {
|
|
|
28207
28466
|
if (!filters.every((s) => FILTERS.has(s.words[0] ?? "") && stdinOnly(s.words)))
|
|
28208
28467
|
return null;
|
|
28209
28468
|
const at = head.words.indexOf("--cwd");
|
|
28210
|
-
if (at >= 0)
|
|
28211
|
-
|
|
28469
|
+
if (at >= 0) {
|
|
28470
|
+
const bare = dir.replace(/^(['"])(.*)\1$/u, "$2");
|
|
28471
|
+
return bare[0] === "/" && head.words[at + 1] === bare ? rest : null;
|
|
28472
|
+
}
|
|
28212
28473
|
if (head.words.some((w) => w.startsWith("--cwd=")))
|
|
28213
28474
|
return null;
|
|
28214
28475
|
const args = rest.slice("workit".length).trimStart();
|
|
@@ -28228,7 +28489,7 @@ var verbFirst = (command) => {
|
|
|
28228
28489
|
return null;
|
|
28229
28490
|
return `${lead} ${verb}${globals}${command.slice(whole.length)}`;
|
|
28230
28491
|
};
|
|
28231
|
-
var MUTATING_GIT2 = /^git(
|
|
28492
|
+
var MUTATING_GIT2 = /^git( -\S+| -[Cc] \S+)* (commit|push|add|switch|checkout|merge|rebase|reset|cherry-pick|revert|branch .*(-[dDmM]|--delete|--move)\b|tag (?!-l\b|--list)|stash(?! (list|show)\b))/u;
|
|
28232
28493
|
var cdWorkitSplit = (command) => {
|
|
28233
28494
|
const match = COMPOUND2.exec(command);
|
|
28234
28495
|
const dir = match?.[1];
|
|
@@ -28249,9 +28510,9 @@ var cdWorkitSplit = (command) => {
|
|
|
28249
28510
|
};
|
|
28250
28511
|
|
|
28251
28512
|
// packages/workit-core/src/hooks/model-limit.ts
|
|
28252
|
-
import { closeSync as
|
|
28513
|
+
import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync5, readSync, statSync as statSync4 } from "node:fs";
|
|
28253
28514
|
import os11 from "node:os";
|
|
28254
|
-
import
|
|
28515
|
+
import path44 from "node:path";
|
|
28255
28516
|
var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
28256
28517
|
var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
28257
28518
|
var TIME_WORD = String.raw`(?:\d|(?:in|at|on|later|tomorrow|soon)\b|(?:${[...WEEKDAYS, ...MONTHS].join("|")})[a-z]*\b)`;
|
|
@@ -28390,21 +28651,21 @@ var TAIL_BYTES2 = 16384;
|
|
|
28390
28651
|
var tail = (file, size) => {
|
|
28391
28652
|
const length = Math.min(size, TAIL_BYTES2);
|
|
28392
28653
|
const buffer = Buffer.alloc(length);
|
|
28393
|
-
const fd =
|
|
28654
|
+
const fd = openSync3(file, "r");
|
|
28394
28655
|
try {
|
|
28395
28656
|
readSync(fd, buffer, 0, length, size - length);
|
|
28396
28657
|
} finally {
|
|
28397
|
-
|
|
28658
|
+
closeSync3(fd);
|
|
28398
28659
|
}
|
|
28399
28660
|
return buffer.toString("utf8");
|
|
28400
28661
|
};
|
|
28401
28662
|
var start = (file) => {
|
|
28402
28663
|
const buffer = Buffer.alloc(TAIL_BYTES2);
|
|
28403
|
-
const fd =
|
|
28664
|
+
const fd = openSync3(file, "r");
|
|
28404
28665
|
try {
|
|
28405
28666
|
return buffer.subarray(0, readSync(fd, buffer, 0, TAIL_BYTES2, 0)).toString("utf8");
|
|
28406
28667
|
} finally {
|
|
28407
|
-
|
|
28668
|
+
closeSync3(fd);
|
|
28408
28669
|
}
|
|
28409
28670
|
};
|
|
28410
28671
|
var parse5 = (line) => {
|
|
@@ -28449,17 +28710,17 @@ var firstPrompt = (file) => {
|
|
|
28449
28710
|
var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
|
|
28450
28711
|
var listDir = (dir) => {
|
|
28451
28712
|
try {
|
|
28452
|
-
return
|
|
28713
|
+
return readdirSync5(dir).map((name) => path44.join(dir, name));
|
|
28453
28714
|
} catch {
|
|
28454
28715
|
return [];
|
|
28455
28716
|
}
|
|
28456
28717
|
};
|
|
28457
28718
|
var SCAN_MS = 30 * 60000;
|
|
28458
28719
|
var scanClaudeTranscripts = (cwd, env, now = new Date) => {
|
|
28459
|
-
const projects =
|
|
28460
|
-
const project =
|
|
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));
|
|
28461
28722
|
const notes = [];
|
|
28462
|
-
const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(
|
|
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 })));
|
|
28463
28724
|
for (const { file, worker } of files)
|
|
28464
28725
|
try {
|
|
28465
28726
|
const stat = statSync4(file);
|
|
@@ -28474,7 +28735,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
|
|
|
28474
28735
|
if (!seen)
|
|
28475
28736
|
continue;
|
|
28476
28737
|
notes.push(worker ? redispatchNote(seen, {
|
|
28477
|
-
label: `worker ${
|
|
28738
|
+
label: `worker ${path44.basename(file, ".jsonl")}`,
|
|
28478
28739
|
prompt: firstPrompt(file)
|
|
28479
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.`);
|
|
28480
28741
|
} catch {}
|
|
@@ -28852,12 +29113,12 @@ var modelKey = (model) => {
|
|
|
28852
29113
|
};
|
|
28853
29114
|
|
|
28854
29115
|
// packages/workit-core/src/hooks/budget-signal.ts
|
|
28855
|
-
import { createHash as
|
|
29116
|
+
import { createHash as createHash20 } from "node:crypto";
|
|
28856
29117
|
import fs30 from "node:fs";
|
|
28857
|
-
import
|
|
28858
|
-
var hash2 = (text) =>
|
|
28859
|
-
var budgetDir = (store) =>
|
|
28860
|
-
var agentBase = (store, session, 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 ?? ""}`));
|
|
28861
29122
|
var spawnBudget = (prompt) => {
|
|
28862
29123
|
const found = /^TIMEBOX:[^\n]*?\b(\d+)\s+tool calls\b/mu.exec(prompt);
|
|
28863
29124
|
const n = found ? Number(found[1]) : NaN;
|
|
@@ -28877,8 +29138,8 @@ var startBudget = (store, session, agentId, n) => {
|
|
|
28877
29138
|
const cutoff = Date.now() - 604800000;
|
|
28878
29139
|
for (const name of fs30.readdirSync(dir))
|
|
28879
29140
|
try {
|
|
28880
|
-
if (fs30.statSync(
|
|
28881
|
-
fs30.rmSync(
|
|
29141
|
+
if (fs30.statSync(path45.join(dir, name)).mtimeMs < cutoff)
|
|
29142
|
+
fs30.rmSync(path45.join(dir, name));
|
|
28882
29143
|
} catch {}
|
|
28883
29144
|
const base = agentBase(store, session, agentId);
|
|
28884
29145
|
fs30.writeFileSync(`${base}.json`, JSON.stringify({ limit: n, told: 0 }));
|
|
@@ -29017,11 +29278,11 @@ var unfinishedTaskOffer2 = (ctx) => {
|
|
|
29017
29278
|
};
|
|
29018
29279
|
|
|
29019
29280
|
// packages/workit-core/src/hooks/repeat-failure.ts
|
|
29020
|
-
import { createHash as
|
|
29281
|
+
import { createHash as createHash21 } from "node:crypto";
|
|
29021
29282
|
var SAME_CALL_FAILED = "Same call failed twice:";
|
|
29022
29283
|
var MAX_SESSIONS = 256;
|
|
29023
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";
|
|
29024
|
-
var hashOf = (call) =>
|
|
29285
|
+
var hashOf = (call) => createHash21("sha256").update(call).digest("hex").slice(0, 32);
|
|
29025
29286
|
var record2 = (memo, sessionId, call, failed, next) => {
|
|
29026
29287
|
const previous = memo.get(sessionId);
|
|
29027
29288
|
memo.delete(sessionId);
|
|
@@ -29152,6 +29413,68 @@ var hookInput = (ctx, event) => ({
|
|
|
29152
29413
|
transcriptPath: null,
|
|
29153
29414
|
event
|
|
29154
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
|
+
};
|
|
29155
29478
|
var enforceToolPolicy = (event, ctx) => {
|
|
29156
29479
|
const gate = (hookEvent) => {
|
|
29157
29480
|
const decision = handleHook(hookInput(ctx, hookEvent), {
|
|
@@ -29164,7 +29487,16 @@ var enforceToolPolicy = (event, ctx) => {
|
|
|
29164
29487
|
};
|
|
29165
29488
|
if (event.toolName === "bash") {
|
|
29166
29489
|
const command = event.input?.command;
|
|
29167
|
-
|
|
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;
|
|
29168
29500
|
}
|
|
29169
29501
|
if (event.toolName === "read") {
|
|
29170
29502
|
const file = event.input?.path;
|
|
@@ -29209,9 +29541,11 @@ var observeToolResult = (event, ctx) => {
|
|
|
29209
29541
|
const role = named === "implementer" ? "implementer" : named ? "judge" : null;
|
|
29210
29542
|
const nudge = process.env.WORKIT_PI_WORKER_SESSION ? rawGitPre(post, command, { nudge: roleSteering(role, false).nudges }) : shellNudge(post, command);
|
|
29211
29543
|
const extra = [nudge.kind === "context" ? nudge.text : null, repeated].filter((text) => text !== null);
|
|
29212
|
-
return extra.length > 0 ? {
|
|
29544
|
+
return extra.length > 0 ? {
|
|
29545
|
+
content: [...event.content, { type: "text", text: extra.join(`
|
|
29213
29546
|
|
|
29214
|
-
`) }]
|
|
29547
|
+
`) }]
|
|
29548
|
+
} : undefined;
|
|
29215
29549
|
} catch {
|
|
29216
29550
|
return;
|
|
29217
29551
|
}
|
|
@@ -29219,21 +29553,21 @@ var observeToolResult = (event, ctx) => {
|
|
|
29219
29553
|
var skillPromptNudge = (prompt, ctx) => process.env.WORKIT_PI_WORKER_SESSION ? null : promptNudge(hookInput(ctx, { kind: "context.turn", prompt }), prompt);
|
|
29220
29554
|
|
|
29221
29555
|
// packages/workit-pi/src/launches.ts
|
|
29222
|
-
import { mkdirSync as
|
|
29556
|
+
import { mkdirSync as mkdirSync6, readFileSync as readFileSync10, readdirSync as readdirSync6, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "node:fs";
|
|
29223
29557
|
import os12 from "node:os";
|
|
29224
|
-
import
|
|
29558
|
+
import path46 from "node:path";
|
|
29225
29559
|
var launchDir = (root) => {
|
|
29226
29560
|
const location = resolveStore(root);
|
|
29227
|
-
return location instanceof Error ? null :
|
|
29561
|
+
return location instanceof Error ? null : path46.join(location.dir, "pi-launches");
|
|
29228
29562
|
};
|
|
29229
|
-
var fileFor = (dir, workerId) =>
|
|
29563
|
+
var fileFor = (dir, workerId) => path46.join(dir, `${workerId.replace(/[^A-Za-z0-9-]/g, "_")}.json`);
|
|
29230
29564
|
var recordLaunch = (root, attempt) => {
|
|
29231
29565
|
const dir = launchDir(root);
|
|
29232
29566
|
if (!dir)
|
|
29233
29567
|
return false;
|
|
29234
29568
|
try {
|
|
29235
|
-
|
|
29236
|
-
|
|
29569
|
+
mkdirSync6(dir, { recursive: true });
|
|
29570
|
+
writeFileSync5(fileFor(dir, attempt.workerId), JSON.stringify({
|
|
29237
29571
|
...attempt,
|
|
29238
29572
|
pid: process.pid,
|
|
29239
29573
|
host: os12.hostname(),
|
|
@@ -29265,14 +29599,14 @@ var abandonedLaunches = (root) => {
|
|
|
29265
29599
|
return [];
|
|
29266
29600
|
let names;
|
|
29267
29601
|
try {
|
|
29268
|
-
names =
|
|
29602
|
+
names = readdirSync6(dir);
|
|
29269
29603
|
} catch {
|
|
29270
29604
|
return [];
|
|
29271
29605
|
}
|
|
29272
29606
|
const found = [];
|
|
29273
29607
|
for (const name of names) {
|
|
29274
29608
|
try {
|
|
29275
|
-
const attempt = JSON.parse(
|
|
29609
|
+
const attempt = JSON.parse(readFileSync10(path46.join(dir, name), "utf8"));
|
|
29276
29610
|
if (typeof attempt.workerId === "string" && typeof attempt.session === "string") {
|
|
29277
29611
|
if (!alive(attempt))
|
|
29278
29612
|
found.push(attempt);
|
|
@@ -29284,22 +29618,22 @@ var abandonedLaunches = (root) => {
|
|
|
29284
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"}')`;
|
|
29285
29619
|
|
|
29286
29620
|
// packages/workit-core/src/core/cli-locate.ts
|
|
29287
|
-
import { closeSync as
|
|
29288
|
-
import
|
|
29621
|
+
import { closeSync as closeSync4, existsSync as existsSync13, openSync as openSync4, readSync as readSync2 } from "node:fs";
|
|
29622
|
+
import path47 from "node:path";
|
|
29289
29623
|
var LAUNCHER_MARKER = "workit-owned-launcher";
|
|
29290
29624
|
var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
|
|
29291
29625
|
var installRoot = (env, platform = process.platform) => {
|
|
29292
29626
|
if (env.WORKIT_INSTALL_ROOT)
|
|
29293
29627
|
return env.WORKIT_INSTALL_ROOT;
|
|
29294
29628
|
const data = dataDir(env, platform);
|
|
29295
|
-
return platform === "win32" ?
|
|
29629
|
+
return platform === "win32" ? path47.join(data, "install") : data;
|
|
29296
29630
|
};
|
|
29297
|
-
var ownedLauncherPath = (env, platform = process.platform) =>
|
|
29298
|
-
var ownedCurrentEntry = (env, platform = process.platform) =>
|
|
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");
|
|
29299
29633
|
var head = (file) => {
|
|
29300
29634
|
let fd;
|
|
29301
29635
|
try {
|
|
29302
|
-
fd =
|
|
29636
|
+
fd = openSync4(file, "r");
|
|
29303
29637
|
const buffer = Buffer.alloc(256);
|
|
29304
29638
|
const read = readSync2(fd, buffer, 0, buffer.length, 0);
|
|
29305
29639
|
return buffer.subarray(0, read).toString("utf8");
|
|
@@ -29307,7 +29641,7 @@ var head = (file) => {
|
|
|
29307
29641
|
return "";
|
|
29308
29642
|
} finally {
|
|
29309
29643
|
if (fd !== undefined)
|
|
29310
|
-
|
|
29644
|
+
closeSync4(fd);
|
|
29311
29645
|
}
|
|
29312
29646
|
};
|
|
29313
29647
|
var locateWorkitCli = (options = {}) => {
|
|
@@ -29322,7 +29656,7 @@ var locateWorkitCli = (options = {}) => {
|
|
|
29322
29656
|
source: "owned-launcher",
|
|
29323
29657
|
command: launcher,
|
|
29324
29658
|
args: [],
|
|
29325
|
-
binDir:
|
|
29659
|
+
binDir: path47.dirname(launcher)
|
|
29326
29660
|
};
|
|
29327
29661
|
const current = ownedCurrentEntry(env, platform);
|
|
29328
29662
|
if (exists(current))
|
|
@@ -29351,7 +29685,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
|
|
|
29351
29685
|
if (located.binDir) {
|
|
29352
29686
|
const key = pathKey(env);
|
|
29353
29687
|
const delimiter = platform === "win32" ? ";" : ":";
|
|
29354
|
-
const same = (dir) => platform === "win32" ?
|
|
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);
|
|
29355
29689
|
const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
|
|
29356
29690
|
patch[key] = [located.binDir, ...rest].join(delimiter);
|
|
29357
29691
|
}
|
|
@@ -29369,7 +29703,7 @@ var useOwnedCliInPi = (env = process.env) => useOwnedWorkitCli({ env });
|
|
|
29369
29703
|
|
|
29370
29704
|
// packages/workit-pi/src/worker.ts
|
|
29371
29705
|
import { spawn as nodeSpawn } from "node:child_process";
|
|
29372
|
-
import { randomUUID as
|
|
29706
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
29373
29707
|
|
|
29374
29708
|
// packages/workit-pi/src/worker-protocol.ts
|
|
29375
29709
|
var MAX_WORKER_LINE_BYTES = 64 * 1024;
|
|
@@ -29497,10 +29831,10 @@ function launchWorker(assignment, options) {
|
|
|
29497
29831
|
const nested = Boolean(process.env.WORKIT_PI_WORKER_ID || options.env?.WORKIT_PI_WORKER_ID);
|
|
29498
29832
|
const taskId = options.taskId ?? null;
|
|
29499
29833
|
const workerId = options.workerId ?? null;
|
|
29500
|
-
const sessionId = options.sessionId ?? "pi-worker-" +
|
|
29834
|
+
const sessionId = options.sessionId ?? "pi-worker-" + randomUUID5();
|
|
29501
29835
|
const spec = workerCommand2({ ...options.runtime, sessionId }, assignment);
|
|
29502
29836
|
const handle = {
|
|
29503
|
-
id:
|
|
29837
|
+
id: randomUUID5(),
|
|
29504
29838
|
taskId,
|
|
29505
29839
|
workerId,
|
|
29506
29840
|
sessionId,
|
|
@@ -30078,7 +30412,7 @@ function extension(pi) {
|
|
|
30078
30412
|
workerId: worker.id,
|
|
30079
30413
|
expectedRevision: task.revision,
|
|
30080
30414
|
expectedWorkspaceRevision: workspace.revision,
|
|
30081
|
-
sessionId: `pi-worker-${worker.id}-${
|
|
30415
|
+
sessionId: `pi-worker-${worker.id}-${randomUUID6().slice(0, 8)}`
|
|
30082
30416
|
};
|
|
30083
30417
|
const childContext = {
|
|
30084
30418
|
...piContext(ctx),
|