@workit-dev/codex 2.27.7 → 2.27.9
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
userHome2,
|
|
3
4
|
configDir2,
|
|
4
5
|
stateDir3,
|
|
5
6
|
folderSlug2,
|
|
@@ -6272,13 +6273,14 @@ var below = (parent, child) => {
|
|
|
6272
6273
|
const rel = path8.relative(parent, child);
|
|
6273
6274
|
return rel !== "" && !rel.startsWith("..") && !path8.isAbsolute(rel);
|
|
6274
6275
|
};
|
|
6276
|
+
var insideTempDir = (dir, tempDir = os4.tmpdir()) => below(canonical2(tempDir), canonical2(dir));
|
|
6275
6277
|
var TEST_RUN_REFUSALS = "folder-store-refusals.log";
|
|
6276
6278
|
var testRunFolderRefusal = (folder, hasStray, env = process.env, tempDir = os4.tmpdir()) => {
|
|
6277
6279
|
if (env.WORKIT_TEST_RUN === undefined || !hasStray)
|
|
6278
6280
|
return null;
|
|
6279
6281
|
const real = canonical2(folder);
|
|
6280
6282
|
const tmp = canonical2(tempDir);
|
|
6281
|
-
if (
|
|
6283
|
+
if (insideTempDir(folder, tempDir))
|
|
6282
6284
|
return null;
|
|
6283
6285
|
return `workit test run (WORKIT_TEST_RUN): refusing to move ${path8.join(real, ".workit")} into the run's throwaway state dir; a test must work in a fresh dir inside ${tmp}, never the temp dir itself, a parent of it or a folder outside it (#892)`;
|
|
6284
6286
|
};
|
|
@@ -10839,8 +10841,58 @@ var STAMPING_HOSTS = new Set([
|
|
|
10839
10841
|
var ISSUED_PER_LEAD = 64;
|
|
10840
10842
|
var ISSUED_SESSIONS_MARKER = "workit-issued-sessions/3";
|
|
10841
10843
|
var hash = (value) => createHash8("sha256").update(value).digest("hex").slice(0, 32);
|
|
10842
|
-
var
|
|
10843
|
-
var
|
|
10844
|
+
var PIN_FILE = "issued-registry";
|
|
10845
|
+
var pinFiles = new Map;
|
|
10846
|
+
var pinFile = (cwd) => {
|
|
10847
|
+
if (cwd === undefined)
|
|
10848
|
+
return null;
|
|
10849
|
+
const key = path16.resolve(cwd);
|
|
10850
|
+
const known = pinFiles.get(key);
|
|
10851
|
+
if (known !== undefined)
|
|
10852
|
+
return known;
|
|
10853
|
+
try {
|
|
10854
|
+
const location = resolveStore(key);
|
|
10855
|
+
if (location instanceof Error)
|
|
10856
|
+
return null;
|
|
10857
|
+
const file = location.shared ? path16.join(location.dir, "ledger", PIN_FILE) : null;
|
|
10858
|
+
pinFiles.set(key, file);
|
|
10859
|
+
return file;
|
|
10860
|
+
} catch {
|
|
10861
|
+
return null;
|
|
10862
|
+
}
|
|
10863
|
+
};
|
|
10864
|
+
var pinnedStateDir = (cwd) => {
|
|
10865
|
+
const file = pinFile(cwd);
|
|
10866
|
+
if (file === null)
|
|
10867
|
+
return null;
|
|
10868
|
+
try {
|
|
10869
|
+
const pinned = fs12.readFileSync(file, "utf8").trim();
|
|
10870
|
+
return path16.isAbsolute(pinned) ? pinned : null;
|
|
10871
|
+
} catch {
|
|
10872
|
+
return null;
|
|
10873
|
+
}
|
|
10874
|
+
};
|
|
10875
|
+
var registryDir = (cwd) => pinnedStateDir(cwd) ?? resolveStateDir();
|
|
10876
|
+
var testRunSkipsPin = (file) => process.env.WORKIT_TEST_RUN !== undefined && !insideTempDir(path16.dirname(path16.dirname(path16.dirname(file))));
|
|
10877
|
+
function pinIssuedRegistry(cwd) {
|
|
10878
|
+
const file = pinFile(cwd);
|
|
10879
|
+
if (file === null)
|
|
10880
|
+
return;
|
|
10881
|
+
const state = path16.resolve(resolveStateDir());
|
|
10882
|
+
if (pinnedStateDir(cwd) === state)
|
|
10883
|
+
return;
|
|
10884
|
+
if (testRunSkipsPin(file))
|
|
10885
|
+
return;
|
|
10886
|
+
try {
|
|
10887
|
+
fs12.mkdirSync(path16.dirname(file), { recursive: true });
|
|
10888
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
10889
|
+
fs12.writeFileSync(temp, `${state}
|
|
10890
|
+
`, { mode: 420 });
|
|
10891
|
+
fs12.renameSync(temp, file);
|
|
10892
|
+
} catch {}
|
|
10893
|
+
}
|
|
10894
|
+
var userIssuedRoot = (cwd) => path16.join(registryDir(cwd), "issued");
|
|
10895
|
+
var userTokenRoot = (cwd) => path16.join(registryDir(cwd), "issued-tokens");
|
|
10844
10896
|
function migrateRepoIssued(cwd) {
|
|
10845
10897
|
if (cwd === undefined)
|
|
10846
10898
|
return;
|
|
@@ -10860,7 +10912,7 @@ function migrateRepoIssued(cwd) {
|
|
|
10860
10912
|
const from = path16.join(old, lead);
|
|
10861
10913
|
if (!fs12.statSync(from).isDirectory())
|
|
10862
10914
|
continue;
|
|
10863
|
-
const to = path16.join(userIssuedRoot(), lead);
|
|
10915
|
+
const to = path16.join(userIssuedRoot(cwd), lead);
|
|
10864
10916
|
fs12.mkdirSync(to, { recursive: true, mode: 448 });
|
|
10865
10917
|
for (const id of fs12.readdirSync(from)) {
|
|
10866
10918
|
try {
|
|
@@ -10892,13 +10944,15 @@ var tokenHash = (token) => createHash8("sha256").update(token).digest("hex");
|
|
|
10892
10944
|
function recordIssuedSession(cwd, lead, issued) {
|
|
10893
10945
|
const token = randomBytes2(18).toString("hex");
|
|
10894
10946
|
try {
|
|
10947
|
+
pinIssuedRegistry(cwd);
|
|
10895
10948
|
migrateRepoIssued(cwd);
|
|
10896
10949
|
const own = hash(issued);
|
|
10897
|
-
const
|
|
10950
|
+
const state = resolveStateDir();
|
|
10951
|
+
const tokens = path16.join(state, "issued-tokens", hash(lead));
|
|
10898
10952
|
fs12.mkdirSync(tokens, { recursive: true, mode: 448 });
|
|
10899
10953
|
fs12.writeFileSync(path16.join(tokens, own), `${tokenHash(token)}
|
|
10900
10954
|
`, { mode: 384, flag: "wx" });
|
|
10901
|
-
const dir = path16.join(
|
|
10955
|
+
const dir = path16.join(state, "issued", hash(lead));
|
|
10902
10956
|
fs12.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
10903
10957
|
fs12.writeFileSync(path16.join(dir, own), `${ISSUED_SESSIONS_MARKER}
|
|
10904
10958
|
`, { mode: 384 });
|
|
@@ -10943,17 +10997,17 @@ var issuedRecord = (cwd, claimed) => {
|
|
|
10943
10997
|
return null;
|
|
10944
10998
|
migrateRepoIssued(cwd);
|
|
10945
10999
|
try {
|
|
10946
|
-
return fs12.readFileSync(path16.join(userIssuedRoot(), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
|
|
11000
|
+
return fs12.readFileSync(path16.join(userIssuedRoot(cwd), hash(claimed.slice(0, cut)), hash(claimed)), "utf8");
|
|
10947
11001
|
} catch {
|
|
10948
11002
|
return null;
|
|
10949
11003
|
}
|
|
10950
11004
|
};
|
|
10951
11005
|
var TOKEN_HASH = /^([0-9a-f]{64})$/mu;
|
|
10952
|
-
var issuedToken = (claimed) => {
|
|
11006
|
+
var issuedToken = (cwd, claimed) => {
|
|
10953
11007
|
const cut = claimed.lastIndexOf(":");
|
|
10954
11008
|
if (cut <= 0)
|
|
10955
11009
|
return { stored: null, leadBound: false };
|
|
10956
|
-
const dir = path16.join(userTokenRoot(), hash(claimed.slice(0, cut)));
|
|
11010
|
+
const dir = path16.join(userTokenRoot(cwd), hash(claimed.slice(0, cut)));
|
|
10957
11011
|
try {
|
|
10958
11012
|
const text = fs12.readFileSync(path16.join(dir, hash(claimed)), "utf8");
|
|
10959
11013
|
return { stored: TOKEN_HASH.exec(text)?.[1] ?? null, leadBound: true };
|
|
@@ -10963,7 +11017,7 @@ var issuedToken = (claimed) => {
|
|
|
10963
11017
|
};
|
|
10964
11018
|
function issuedBinding(cwd, claimed) {
|
|
10965
11019
|
const record = issuedRecord(cwd, claimed);
|
|
10966
|
-
const { stored, leadBound } = issuedToken(claimed);
|
|
11020
|
+
const { stored, leadBound } = issuedToken(cwd, claimed);
|
|
10967
11021
|
if (stored)
|
|
10968
11022
|
return "token";
|
|
10969
11023
|
if (record === null)
|
|
@@ -17517,7 +17571,7 @@ var splitDenial = (plan) => ({
|
|
|
17517
17571
|
// packages/workit-core/src/hooks/write-gate.ts
|
|
17518
17572
|
import {
|
|
17519
17573
|
existsSync as existsSync12,
|
|
17520
|
-
readdirSync as
|
|
17574
|
+
readdirSync as readdirSync4,
|
|
17521
17575
|
readFileSync as readFileSync10,
|
|
17522
17576
|
readlinkSync as readlinkSync3,
|
|
17523
17577
|
realpathSync as realpathSync8,
|
|
@@ -17525,7 +17579,7 @@ import {
|
|
|
17525
17579
|
} from "node:fs";
|
|
17526
17580
|
import { builtinModules } from "node:module";
|
|
17527
17581
|
import os9 from "node:os";
|
|
17528
|
-
import
|
|
17582
|
+
import path31 from "node:path";
|
|
17529
17583
|
|
|
17530
17584
|
// packages/workit-core/src/core/live-session.ts
|
|
17531
17585
|
import { spawnSync as spawnSync15 } from "node:child_process";
|
|
@@ -17728,6 +17782,41 @@ var claimLiveSession = (target, owner, deps = {}) => {
|
|
|
17728
17782
|
} catch {}
|
|
17729
17783
|
};
|
|
17730
17784
|
|
|
17785
|
+
// packages/workit-core/src/hooks/path-glob.ts
|
|
17786
|
+
import { readdirSync as readdirSync3 } from "node:fs";
|
|
17787
|
+
import path30 from "node:path";
|
|
17788
|
+
var GLOB2 = /[*?[]/u;
|
|
17789
|
+
var globPattern = (glob, dots = false) => {
|
|
17790
|
+
try {
|
|
17791
|
+
return new RegExp(`^${dots || glob.startsWith(".") ? "" : "(?!\\.)"}${glob.replace(/[.+^$(){}|\\]/gu, "\\$&").replace(/\[!/gu, "[^").replaceAll("*", ".*").replaceAll("?", ".")}$`, "u");
|
|
17792
|
+
} catch {
|
|
17793
|
+
return null;
|
|
17794
|
+
}
|
|
17795
|
+
};
|
|
17796
|
+
var expandGlob = (file, limit = 64) => {
|
|
17797
|
+
if (!GLOB2.test(file))
|
|
17798
|
+
return [file];
|
|
17799
|
+
const { root } = path30.parse(file);
|
|
17800
|
+
let found = [root];
|
|
17801
|
+
for (const part of file.slice(root.length).split(/[\\/]/u).filter(Boolean)) {
|
|
17802
|
+
if (!GLOB2.test(part)) {
|
|
17803
|
+
found = found.map((dir) => path30.join(dir, part));
|
|
17804
|
+
continue;
|
|
17805
|
+
}
|
|
17806
|
+
const pattern = globPattern(part);
|
|
17807
|
+
if (pattern === null)
|
|
17808
|
+
return [file];
|
|
17809
|
+
found = found.flatMap((dir) => {
|
|
17810
|
+
try {
|
|
17811
|
+
return readdirSync3(dir).filter((name) => pattern.test(name)).map((name) => path30.join(dir, name));
|
|
17812
|
+
} catch {
|
|
17813
|
+
return [];
|
|
17814
|
+
}
|
|
17815
|
+
}).slice(0, limit);
|
|
17816
|
+
}
|
|
17817
|
+
return found.length > 0 ? found : [file];
|
|
17818
|
+
};
|
|
17819
|
+
|
|
17731
17820
|
// packages/workit-core/src/hooks/windows-reads.ts
|
|
17732
17821
|
var READ_CMDLETS = new Set([
|
|
17733
17822
|
"foreach-object",
|
|
@@ -18045,44 +18134,44 @@ var CASE_INSENSITIVE = process.platform === "darwin" || process.platform === "wi
|
|
|
18045
18134
|
var linkTarget = (file) => {
|
|
18046
18135
|
try {
|
|
18047
18136
|
const to = readlinkSync3(file);
|
|
18048
|
-
let from =
|
|
18137
|
+
let from = path31.dirname(file);
|
|
18049
18138
|
try {
|
|
18050
18139
|
from = realpathSync8.native(from);
|
|
18051
18140
|
} catch {}
|
|
18052
|
-
return
|
|
18141
|
+
return path31.resolve(from, to);
|
|
18053
18142
|
} catch {
|
|
18054
18143
|
return null;
|
|
18055
18144
|
}
|
|
18056
18145
|
};
|
|
18057
18146
|
var realPath = (file, dangling = true) => {
|
|
18058
|
-
let dir =
|
|
18147
|
+
let dir = path31.resolve(file);
|
|
18059
18148
|
let rest = "";
|
|
18060
18149
|
for (let hops = 0;; ) {
|
|
18061
18150
|
try {
|
|
18062
|
-
return
|
|
18151
|
+
return path31.join(realpathSync8.native(dir), rest);
|
|
18063
18152
|
} catch {
|
|
18064
18153
|
const link = dangling ? linkTarget(dir) : null;
|
|
18065
18154
|
if (link !== null) {
|
|
18066
18155
|
if (++hops > 40)
|
|
18067
18156
|
return null;
|
|
18068
|
-
dir =
|
|
18157
|
+
dir = path31.join(link, rest);
|
|
18069
18158
|
rest = "";
|
|
18070
|
-
} else if (
|
|
18071
|
-
return
|
|
18159
|
+
} else if (path31.dirname(dir) === dir)
|
|
18160
|
+
return path31.resolve(file);
|
|
18072
18161
|
else {
|
|
18073
|
-
rest = rest ?
|
|
18074
|
-
dir =
|
|
18162
|
+
rest = rest ? path31.join(path31.basename(dir), rest) : path31.basename(dir);
|
|
18163
|
+
dir = path31.dirname(dir);
|
|
18075
18164
|
}
|
|
18076
18165
|
}
|
|
18077
18166
|
}
|
|
18078
18167
|
};
|
|
18079
|
-
var canonical5 = (file, dangling = true) => realPath(file, dangling) ??
|
|
18168
|
+
var canonical5 = (file, dangling = true) => realPath(file, dangling) ?? path31.resolve(file);
|
|
18080
18169
|
var exempt = (cwd, root, file, plans) => {
|
|
18081
18170
|
const fold = (value) => CASE_INSENSITIVE ? value.toLowerCase() : value;
|
|
18082
|
-
const relative =
|
|
18083
|
-
if (relative.startsWith("..") ||
|
|
18171
|
+
const relative = path31.relative(fold(canonical5(root, false)), fold(canonical5(path31.resolve(cwd, file), false)));
|
|
18172
|
+
if (relative.startsWith("..") || path31.isAbsolute(relative))
|
|
18084
18173
|
return true;
|
|
18085
|
-
const posix = relative.split(
|
|
18174
|
+
const posix = relative.split(path31.sep).join("/");
|
|
18086
18175
|
const segments = posix.split("/");
|
|
18087
18176
|
return /\.mdx?$/i.test(posix) || segments[0] === "docs" || segments.includes("plans") || [...plans].some((plan) => fold(plan) === posix);
|
|
18088
18177
|
};
|
|
@@ -18162,7 +18251,7 @@ var editsOf = (input) => {
|
|
|
18162
18251
|
return [into];
|
|
18163
18252
|
const files = operands(args);
|
|
18164
18253
|
if (name === "ln" && files.length === 1)
|
|
18165
|
-
return [
|
|
18254
|
+
return [path31.basename(files[0])];
|
|
18166
18255
|
return files.length ? [files.at(-1)] : null;
|
|
18167
18256
|
}
|
|
18168
18257
|
case "mklink": {
|
|
@@ -18224,6 +18313,35 @@ var editsOf = (input) => {
|
|
|
18224
18313
|
return [];
|
|
18225
18314
|
}
|
|
18226
18315
|
};
|
|
18316
|
+
var removalsOf = (input) => {
|
|
18317
|
+
const [verb = "", ...args] = pastLead(input);
|
|
18318
|
+
const name = (verb.split(/[\\/]/).at(-1) ?? "").toLowerCase();
|
|
18319
|
+
const files = operands(args);
|
|
18320
|
+
if (/^(?:rm|rmdir|rd|unlink|shred|remove-item|ri|del|erase)$/.test(name))
|
|
18321
|
+
return { files };
|
|
18322
|
+
if (/^(?:mv|move-item|mi|move)$/.test(name)) {
|
|
18323
|
+
const into = valueOf(args, /^(?:-[a-zA-Z]*t|--target-directory=?)(.*)$/s);
|
|
18324
|
+
return {
|
|
18325
|
+
files: into === undefined ? files.slice(0, -1) : files.filter((file) => file !== into)
|
|
18326
|
+
};
|
|
18327
|
+
}
|
|
18328
|
+
if (name === "rsync" && args.some((arg) => /^--del(?:ete|$)/.test(arg)))
|
|
18329
|
+
return { files: files.slice(-1) };
|
|
18330
|
+
const removes = args.some((arg, at) => arg === "-delete" || /^-(?:exec|execdir|ok|okdir)$/.test(arg) && /^(?:rm|rmdir|unlink|shred|mv|truncate|cp|dd|tee|sh|bash|dash|zsh)$/.test(commandName2(args[at + 1] ?? "")));
|
|
18331
|
+
if (name !== "find" || !removes)
|
|
18332
|
+
return { files: [] };
|
|
18333
|
+
const end = args.findIndex((arg) => /^[-(!]/.test(arg));
|
|
18334
|
+
const roots = end === 0 ? ["."] : args.slice(0, end);
|
|
18335
|
+
const tests = [];
|
|
18336
|
+
for (const [at, arg] of args.entries()) {
|
|
18337
|
+
const kind = /^-(i?)(?:name|path|wholename|regex)$/.exec(arg);
|
|
18338
|
+
const value = args[at + 1];
|
|
18339
|
+
if (kind && value !== undefined)
|
|
18340
|
+
tests.push([`${arg.replace(/^-i?/, "").replace("wholename", "path")}${kind[1]}`, value]);
|
|
18341
|
+
}
|
|
18342
|
+
const negated = args.some((arg) => arg === "!" || arg === "-not");
|
|
18343
|
+
return { files: roots, find: { roots, tests: negated ? [] : tests } };
|
|
18344
|
+
};
|
|
18227
18345
|
var WRAPPERS3 = {
|
|
18228
18346
|
sudo: "ugCDhpRrTtU",
|
|
18229
18347
|
doas: "uC",
|
|
@@ -18247,7 +18365,7 @@ var WRAPPERS3 = {
|
|
|
18247
18365
|
var INTERPRETERS = /^(?:python[\d.]*|node|bun|deno|ruby|perl|php|tsx|ts-node)$/;
|
|
18248
18366
|
var INLINE_CODE = /^-[a-zA-Z]*[cep]$|^--(?:eval|print)(?:=|$)/;
|
|
18249
18367
|
var isConfigDir = (file) => configDirs().some((dir) => canonical5(dir) === canonical5(file));
|
|
18250
|
-
var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals|verdicts|agent-stamps)$/.test(
|
|
18368
|
+
var isRoot = (file) => isConfigDir(file) || /^(?:issued[^\\/]*|approvals|verdicts|agent-stamps)$/.test(path31.relative(canonical5(resolveStateDir()), canonical5(file)));
|
|
18251
18369
|
var READ_CALLS = /^(?:print|log|info|warn|error|debug|puts|readdir(?:Sync)?|listdir|scandir|iterdir|glob|l?stat(?:Sync)?|exists(?:Sync)?|isdir|isfile|is_dir|is_file|access(?:Sync)?|realpath(?:Sync)?|dirname|basename|relative|str|repr|len)$/;
|
|
18252
18370
|
var MUTATING_CALLS = /^(?:renames?(?:Sync)?|move(?:_into)?|copy(?:2|file|tree|File|_into)?(?:Sync)?|cp(?:Sync)?|rm(?:tree|dir|Sync|dirSync)?|unlink(?:Sync)?|remove(?:dirs)?|mkdirs?(?:Sync)?|makedirs|mkdtemp(?:Sync)?|(?:sym|hard)?link(?:Sync|_to)?|write\w*|append\w*|f?truncate(?:Sync)?|ch(?:mod|own)(?:Sync)?|touch|open(?:Sync)?|dump|save|extractall|unpack_archive|put_contents|mv|FileUtils)$/;
|
|
18253
18371
|
var SPAWNS = /getattr|Reflect|getOwnPropertyDescriptor|FileIO|\.copy\s*\((?!\s*\))|utime|ch(?:mod|own)|\.delete\s*\(\s*\)|(?:PYTHON|NODE_)\w*\+?=|-r\b|--(?:require|import|env-file|[\w-]*loader)|\b(?:exec\w*|eval|(?:unlink|rename|remove)\w*)\b|\]\s*\(/;
|
|
@@ -18772,10 +18890,10 @@ var linkSources = (args, at) => {
|
|
|
18772
18890
|
const sources = names.filter((name, index) => into >= 0 ? name !== dest : index < names.length - 1 || names.length === 1);
|
|
18773
18891
|
const target = dest === undefined ? null : at(dest);
|
|
18774
18892
|
const symbolic = args.some((arg) => /^-[a-zA-Z]*s|^--symbolic$/.test(arg));
|
|
18775
|
-
const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target :
|
|
18893
|
+
const base = target === null ? null : into >= 0 || sources.length > 1 || existsSync12(target) || /[\\/]$/.test(dest ?? "") ? target : path31.dirname(target);
|
|
18776
18894
|
return sources.flatMap((source) => {
|
|
18777
|
-
if (symbolic && base !== null && !
|
|
18778
|
-
return [
|
|
18895
|
+
if (symbolic && base !== null && !path31.isAbsolute(homeExpanded(source)))
|
|
18896
|
+
return [path31.resolve(base, source)];
|
|
18779
18897
|
const resolved = at(source);
|
|
18780
18898
|
return resolved ? [resolved] : [];
|
|
18781
18899
|
});
|
|
@@ -18820,7 +18938,7 @@ var linkReach = (verb, args, at, atAll) => {
|
|
|
18820
18938
|
const dir = match ? match[1] ?? args[index + 1] : undefined;
|
|
18821
18939
|
if (!dir)
|
|
18822
18940
|
return [];
|
|
18823
|
-
return [...atAll(dir), ...dest && !
|
|
18941
|
+
return [...atAll(dir), ...dest && !path31.isAbsolute(dir) ? atAll(path31.join(dest, dir)) : []];
|
|
18824
18942
|
});
|
|
18825
18943
|
}
|
|
18826
18944
|
if (verb === "mklink")
|
|
@@ -18856,7 +18974,7 @@ var shellWrites = (command, depth = 0) => {
|
|
|
18856
18974
|
return { writes: true, targets: unknown ? null : targets };
|
|
18857
18975
|
};
|
|
18858
18976
|
var cache2 = new Map;
|
|
18859
|
-
var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(
|
|
18977
|
+
var planKeyOf = (root, plans) => [...plans].map((file) => fileSignature(path31.resolve(root, file)) ?? "-").join("\x00");
|
|
18860
18978
|
var gateFor = (cwd) => {
|
|
18861
18979
|
const store = new TaskReader(cwd);
|
|
18862
18980
|
const listed = store.listTaskIndex();
|
|
@@ -18919,7 +19037,7 @@ var DIR_TARGET = ".workit-live-target";
|
|
|
18919
19037
|
var PLACEHOLDERS = new WeakMap;
|
|
18920
19038
|
var collecting = null;
|
|
18921
19039
|
var placeholderIn = (dir, name) => {
|
|
18922
|
-
const target =
|
|
19040
|
+
const target = path31.join(dir, name);
|
|
18923
19041
|
collecting?.add(target);
|
|
18924
19042
|
return target;
|
|
18925
19043
|
};
|
|
@@ -18947,6 +19065,7 @@ var inlineWhy = (targets) => REASONS.get(targets);
|
|
|
18947
19065
|
var OPAQUE_TARGET = ".workit-runs-";
|
|
18948
19066
|
var UNRESOLVED_TARGET = ".workit-unresolved-target";
|
|
18949
19067
|
var LINK_SOURCE = ".workit-link-source";
|
|
19068
|
+
var REMOVED_SOURCE = ".workit-removed-source";
|
|
18950
19069
|
var OVERRIDE = "WORKIT_LIVE_SESSION=override";
|
|
18951
19070
|
var inert = (args, sub) => args.some((arg) => arg === "--help" || arg === "-h" || arg === "--dry-run" || DRY_N.has(sub) && /^-[a-zA-Z]*n[a-zA-Z]*$/.test(arg) && !arg.startsWith("--"));
|
|
18952
19071
|
var gitMutationDirs = (cwd, command, dialect) => {
|
|
@@ -18966,13 +19085,13 @@ var gitMutationDirs = (cwd, command, dialect) => {
|
|
|
18966
19085
|
return [];
|
|
18967
19086
|
if (sub === "stash" && ["list", "show"].includes(rest[0] ?? ""))
|
|
18968
19087
|
return [];
|
|
18969
|
-
return [
|
|
19088
|
+
return [path31.resolve(cwd, invocation.dir ?? ".")];
|
|
18970
19089
|
});
|
|
18971
19090
|
};
|
|
18972
19091
|
var CD2 = new Set(["cd", "chdir", "set-location", "sl"]);
|
|
18973
19092
|
var PUSHD2 = new Set(["pushd", "push-location"]);
|
|
18974
19093
|
var POPD2 = new Set(["popd", "pop-location"]);
|
|
18975
|
-
var UNKNOWN_DIR =
|
|
19094
|
+
var UNKNOWN_DIR = path31.resolve(path31.parse(process.cwd()).root, ".workit-unknown-dir");
|
|
18976
19095
|
var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
|
|
18977
19096
|
const lost = strict ? UNKNOWN_DIR : undefined;
|
|
18978
19097
|
const found = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
|
|
@@ -18982,7 +19101,7 @@ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
|
|
|
18982
19101
|
return lost;
|
|
18983
19102
|
if (dir === undefined)
|
|
18984
19103
|
return lost;
|
|
18985
|
-
return target === undefined ? os9.homedir() :
|
|
19104
|
+
return target === undefined ? os9.homedir() : path31.resolve(dir, target);
|
|
18986
19105
|
};
|
|
18987
19106
|
var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
18988
19107
|
var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
|
|
@@ -19130,7 +19249,7 @@ var untrustedVars = (segments) => {
|
|
|
19130
19249
|
}
|
|
19131
19250
|
return { all, names };
|
|
19132
19251
|
};
|
|
19133
|
-
var UNKNOWN_VAR =
|
|
19252
|
+
var UNKNOWN_VAR = path31.resolve(path31.parse(process.cwd()).root, ".workit-unknown-var");
|
|
19134
19253
|
var REFERENCE = /\$\{(\w+)[^}]*\}|\$(\w+)|\$\([^)]*\)?|`[^`]*`?/g;
|
|
19135
19254
|
var unresolvedRefs = (text) => [
|
|
19136
19255
|
...new Set([...text.matchAll(REFERENCE)].map((match) => {
|
|
@@ -19140,7 +19259,7 @@ var unresolvedRefs = (text) => [
|
|
|
19140
19259
|
];
|
|
19141
19260
|
var unknownVarTarget = (text) => {
|
|
19142
19261
|
const refs = unresolvedRefs(text);
|
|
19143
|
-
return
|
|
19262
|
+
return path31.join(UNKNOWN_VAR, (refs.length > 0 ? refs : [text]).map(encodeURIComponent).join("+"));
|
|
19144
19263
|
};
|
|
19145
19264
|
var applyOperator = (value, operator) => {
|
|
19146
19265
|
if (operator === "")
|
|
@@ -19201,12 +19320,12 @@ var mktempPath = (value, dir) => {
|
|
|
19201
19320
|
if (base === null && (temp || template === undefined))
|
|
19202
19321
|
base = os9.tmpdir();
|
|
19203
19322
|
const name = homeExpanded(template ?? "tmp.XXXXXXXXXX");
|
|
19204
|
-
if (
|
|
19323
|
+
if (path31.isAbsolute(name))
|
|
19205
19324
|
return name;
|
|
19206
19325
|
const from = base === null ? dir : homeExpanded(base);
|
|
19207
|
-
if (from === undefined || !
|
|
19326
|
+
if (from === undefined || !path31.isAbsolute(from) && dir === undefined)
|
|
19208
19327
|
return null;
|
|
19209
|
-
return
|
|
19328
|
+
return path31.resolve(dir ?? from, from, name);
|
|
19210
19329
|
};
|
|
19211
19330
|
var homeExpanded = (file) => {
|
|
19212
19331
|
const match = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(file);
|
|
@@ -19230,7 +19349,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
19230
19349
|
const home = homeExpanded(text);
|
|
19231
19350
|
if (strict && unresolvedRefs(home).length > 0)
|
|
19232
19351
|
return [unknownVarTarget(home)];
|
|
19233
|
-
if (
|
|
19352
|
+
if (path31.isAbsolute(home))
|
|
19234
19353
|
return [home];
|
|
19235
19354
|
return base === undefined ? [] : [resolvedUnder(base, home)];
|
|
19236
19355
|
});
|
|
@@ -19301,7 +19420,8 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
19301
19420
|
if (loop >= 0) {
|
|
19302
19421
|
const [name = "", keyword, ...items] = segment.words.slice(loop + 1);
|
|
19303
19422
|
const expanding = new Set(segment.expands ?? []);
|
|
19304
|
-
const
|
|
19423
|
+
const globbedItem = (item) => strict === "registry" && dir !== undefined && /[*?[]/.test(item) ? expandGlob(path31.resolve(dir, homeExpanded(item))) : null;
|
|
19424
|
+
const list = items.flatMap((item, index) => globbedItem(item) ?? (expanding.has(loop + 3 + index) ? listWords(item) : [listWord(homeExpanded(item))]));
|
|
19305
19425
|
vars.delete(name);
|
|
19306
19426
|
if (keyword === "in" && list.length <= MAX_EXPANSIONS2 && !list.includes(null) && !untrusted.all && !untrusted.names.has(name))
|
|
19307
19427
|
loops.set(name, list);
|
|
@@ -19440,7 +19560,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
19440
19560
|
index
|
|
19441
19561
|
}));
|
|
19442
19562
|
const homes = /homedir\(|expanduser\(|Path\.home\(|['"]HOME['"]|env\.HOME|\$HOME|~/.test(text);
|
|
19443
|
-
const under = (word) => homes ? [
|
|
19563
|
+
const under = (word) => homes ? [path31.join(homeExpanded("~"), word.replace(/^~/, ""))] : [];
|
|
19444
19564
|
const found = [
|
|
19445
19565
|
...[...text.matchAll(PATHS)].flatMap(({ 0: word, index }) => [...atAll(word), ...under(word)].map((file) => ({ file, index }))),
|
|
19446
19566
|
...joined.flatMap(({ word, index }) => under(word).map((file) => ({ file, index })))
|
|
@@ -19448,7 +19568,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
19448
19568
|
for (const { file, index } of found) {
|
|
19449
19569
|
const use = isRoot(file) ? rootUse(text, index) : "takes";
|
|
19450
19570
|
if (use !== "reads")
|
|
19451
|
-
targets.push(use === "builds" ?
|
|
19571
|
+
targets.push(use === "builds" ? path31.join(file, UNRESOLVED_TARGET) : file);
|
|
19452
19572
|
}
|
|
19453
19573
|
}
|
|
19454
19574
|
if (/^(?:n?vim?|ex|ed|emacs)$/.test(verb) && (segment.stdin || inputs.length > 0 || feeder || args.some((arg, index) => /^(?:-[a-zA-Z]*[se]|--(?:batch|eval|script))$/.test(arg) || /^(?:-c|--cmd)$/.test(arg) && !inertEdit(args[index + 1] ?? "") || arg.startsWith("+") && !inertEdit(arg.slice(1) || "1"))))
|
|
@@ -19458,7 +19578,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
19458
19578
|
`);
|
|
19459
19579
|
for (const [linker = "", ...rest] of fedRuns(words, feed))
|
|
19460
19580
|
for (const source of linkReach(commandName2(linker), rest, at, atAll))
|
|
19461
|
-
targets.push(
|
|
19581
|
+
targets.push(path31.join(source, LINK_SOURCE));
|
|
19462
19582
|
}
|
|
19463
19583
|
if (strict && dir !== undefined) {
|
|
19464
19584
|
const runIn = dir;
|
|
@@ -19485,7 +19605,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
19485
19605
|
for (const file of opaque ?? [])
|
|
19486
19606
|
for (const resolved of atAll(file))
|
|
19487
19607
|
if (!quiet || !isRoot(resolved))
|
|
19488
|
-
targets.push(file === "." ? placeholderIn(resolved, here) :
|
|
19608
|
+
targets.push(file === "." ? placeholderIn(resolved, here) : path31.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path31.dirname(resolved), path31.basename(resolved)) : resolved);
|
|
19489
19609
|
const [shell = "", ...shellArgs] = pastLead(words);
|
|
19490
19610
|
const verb = (shell.split(/[\\/]/).at(-1) ?? "").toLowerCase();
|
|
19491
19611
|
const named = (SCRIPT_SHELLS.has(verb) || verb === "source" || verb === ".") && shellScript3([verb, ...shellArgs]) === null ? scriptArgs(verb, shellArgs).named ?? "" : null;
|
|
@@ -19506,6 +19626,12 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
19506
19626
|
if (dir !== undefined)
|
|
19507
19627
|
targets.push(placeholderIn(dir, DIR_TARGET));
|
|
19508
19628
|
}
|
|
19629
|
+
if (strict === "registry") {
|
|
19630
|
+
const { files: gone, find } = removalsOf(body);
|
|
19631
|
+
for (const root of gone)
|
|
19632
|
+
for (const file of atAll(root))
|
|
19633
|
+
targets.push(path31.join(file, find ? `${REMOVED_SOURCE}~${encodeURIComponent(JSON.stringify({ root, tests: find.tests }))}` : REMOVED_SOURCE));
|
|
19634
|
+
}
|
|
19509
19635
|
for (const file of [...segment.redirects, ...edits ?? []])
|
|
19510
19636
|
if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file) && !(dialect === "powershell" && /^(?:\$null|nul)$/i.test(file)))
|
|
19511
19637
|
targets.push(...atAll(file));
|
|
@@ -19532,7 +19658,10 @@ var workitCwd = (dir, args, resolve) => {
|
|
|
19532
19658
|
};
|
|
19533
19659
|
var shellMutationTargets = (cwd, command, dialect = "posix", strict = false) => {
|
|
19534
19660
|
try {
|
|
19535
|
-
const env = new Map(strict === "registry" ? [
|
|
19661
|
+
const env = new Map(strict === "registry" ? [
|
|
19662
|
+
...[...command.matchAll(/\$\{?([A-Za-z_]\w*)/g)].filter((match) => !/^(?:OLD)?PWD$/.test(match[1])).map((match) => [match[1], process.env[match[1]] ?? ""]),
|
|
19663
|
+
["PWD", cwd]
|
|
19664
|
+
] : []);
|
|
19536
19665
|
return recording(() => [
|
|
19537
19666
|
...segmentTargets(cwd, command, dialect, 0, strict, env),
|
|
19538
19667
|
...gitMutationDirs(cwd, command, dialect).map((dir) => placeholderIn(dir, DIR_TARGET))
|
|
@@ -19574,7 +19703,7 @@ var liveDeny = ({ marker, checkout, ageMs, file }) => {
|
|
|
19574
19703
|
var guarded = (targets) => {
|
|
19575
19704
|
const seen = new Set;
|
|
19576
19705
|
return targets.filter((target) => {
|
|
19577
|
-
const dir =
|
|
19706
|
+
const dir = path31.dirname(target);
|
|
19578
19707
|
if (seen.has(dir))
|
|
19579
19708
|
return false;
|
|
19580
19709
|
seen.add(dir);
|
|
@@ -19595,17 +19724,17 @@ var claimAll = (owner, targets, deps) => {
|
|
|
19595
19724
|
for (const target of guarded(targets))
|
|
19596
19725
|
claimLiveSession(target, owner, deps);
|
|
19597
19726
|
};
|
|
19598
|
-
var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ?
|
|
19727
|
+
var resolvedUnder = (dir, file) => !/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(file) ? path31.resolve(dir, file) : path31.isAbsolute(file) ? file : `${dir}${path31.sep}${file}`;
|
|
19599
19728
|
var liveTargets = (cwd, paths) => recording(() => paths?.length ? paths.map((file) => resolvedUnder(cwd, file)) : [placeholderIn(cwd, DIR_TARGET)]);
|
|
19600
19729
|
var CONFIG_FILES = ["workspaces.json", SEAL_FILE];
|
|
19601
19730
|
var configDirs = () => [resolveConfigDir(), grantsDir()];
|
|
19602
19731
|
var globbed = (cwd, target, state, configs) => {
|
|
19603
19732
|
if (!/[*?[]/.test(target))
|
|
19604
19733
|
return [];
|
|
19605
|
-
const raw =
|
|
19734
|
+
const raw = path31.resolve(cwd, target).split(path31.sep);
|
|
19606
19735
|
const literal = raw.findIndex((part) => /[*?[]/.test(part));
|
|
19607
19736
|
const pattern = [
|
|
19608
|
-
...canonical5(raw.slice(0, literal).join(
|
|
19737
|
+
...canonical5(raw.slice(0, literal).join(path31.sep) || path31.sep).replace(/[\\/]+$/, "").split(path31.sep),
|
|
19609
19738
|
...raw.slice(literal)
|
|
19610
19739
|
];
|
|
19611
19740
|
const segment = (glob, name) => {
|
|
@@ -19616,16 +19745,16 @@ var globbed = (cwd, target, state, configs) => {
|
|
|
19616
19745
|
}
|
|
19617
19746
|
};
|
|
19618
19747
|
const hit = (file, below) => {
|
|
19619
|
-
const parts = canonical5(file).split(
|
|
19748
|
+
const parts = canonical5(file).split(path31.sep);
|
|
19620
19749
|
return (below ? pattern.length >= parts.length : pattern.length === parts.length) && parts.every((part, index) => segment(pattern[index], part));
|
|
19621
19750
|
};
|
|
19622
19751
|
let roots = [];
|
|
19623
19752
|
try {
|
|
19624
|
-
roots =
|
|
19753
|
+
roots = readdirSync4(state).filter((name) => /^(?:issued|approvals$|verdicts$|agent-stamps$)/.test(name));
|
|
19625
19754
|
} catch {}
|
|
19626
19755
|
return [
|
|
19627
|
-
...roots.map((name) =>
|
|
19628
|
-
...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) =>
|
|
19756
|
+
...roots.map((name) => path31.join(state, name)).filter((root) => hit(root, true)),
|
|
19757
|
+
...configs.flatMap((dir) => [dir, ...CONFIG_FILES.map((name) => path31.join(dir, name))]).filter((file) => hit(file, false))
|
|
19629
19758
|
];
|
|
19630
19759
|
};
|
|
19631
19760
|
var guardedInodes = (state, configs) => {
|
|
@@ -19638,18 +19767,18 @@ var guardedInodes = (state, configs) => {
|
|
|
19638
19767
|
if (stat?.isFile())
|
|
19639
19768
|
seen.set(`${stat.dev}:${stat.ino}`, registry);
|
|
19640
19769
|
else if (stat?.isDirectory())
|
|
19641
|
-
for (const name of
|
|
19642
|
-
add(
|
|
19770
|
+
for (const name of readdirSync4(file))
|
|
19771
|
+
add(path31.join(file, name), registry);
|
|
19643
19772
|
};
|
|
19644
19773
|
try {
|
|
19645
19774
|
for (const dir of configs)
|
|
19646
19775
|
for (const name of CONFIG_FILES)
|
|
19647
|
-
add(
|
|
19648
|
-
for (const name of
|
|
19776
|
+
add(path31.join(dir, name), "grants");
|
|
19777
|
+
for (const name of readdirSync4(state))
|
|
19649
19778
|
if (/^(?:issued|approvals$|verdicts$|agent-stamps$)/.test(name))
|
|
19650
|
-
add(
|
|
19651
|
-
for (const slug of
|
|
19652
|
-
add(
|
|
19779
|
+
add(path31.join(state, name), name === "approvals" ? "approvals" : name === "verdicts" || name === "agent-stamps" ? "ledger" : "issued");
|
|
19780
|
+
for (const slug of readdirSync4(path31.join(state, "folders")))
|
|
19781
|
+
add(path31.join(state, "folders", slug, "ledger"), "ledger");
|
|
19653
19782
|
} catch {}
|
|
19654
19783
|
return seen;
|
|
19655
19784
|
};
|
|
@@ -19666,19 +19795,87 @@ var hardLinked = (file, state, configs, inodes) => {
|
|
|
19666
19795
|
};
|
|
19667
19796
|
var inRepoLedger = (file) => [...file.matchAll(/[\\/]workit[\\/]ledger(?=[\\/]|$)/g)].some(({ index }) => {
|
|
19668
19797
|
const gitDir = file.slice(0, index);
|
|
19669
|
-
return /(?:^|[\\/])\.git$/.test(gitDir) || existsSync12(
|
|
19798
|
+
return /(?:^|[\\/])\.git$/.test(gitDir) || existsSync12(path31.join(gitDir, "HEAD")) && existsSync12(path31.join(gitDir, "objects"));
|
|
19670
19799
|
});
|
|
19671
19800
|
var holdsGuarded = (cwd, source, state, configs) => {
|
|
19672
19801
|
const real = canonical5(source);
|
|
19673
19802
|
const below = (parent, child) => {
|
|
19674
|
-
const rel =
|
|
19675
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
19803
|
+
const rel = path31.relative(parent, child);
|
|
19804
|
+
return rel === "" || !rel.startsWith("..") && !path31.isAbsolute(rel);
|
|
19676
19805
|
};
|
|
19677
19806
|
const holds = (file) => below(real, canonical5(file));
|
|
19678
|
-
const inState =
|
|
19679
|
-
const ledgers = ["ledger", "workit/ledger", ".git/workit/ledger"].map((rel) =>
|
|
19807
|
+
const inState = path31.relative(canonical5(state), real).split(path31.sep);
|
|
19808
|
+
const ledgers = ["ledger", "workit/ledger", ".git/workit/ledger"].map((rel) => path31.join(real, rel)).filter((dir) => existsSync12(dir) && inRepoLedger(dir));
|
|
19680
19809
|
const own = ledgerPath(cwd);
|
|
19681
|
-
return holds(state) || below(canonical5(state), real) && inState[0] === "folders" && inState.length <= 2 || configs.some(holds) || ledgers.length > 0 || own.ok && existsSync12(own.value) && holds(
|
|
19810
|
+
return holds(state) || below(canonical5(state), real) && inState[0] === "folders" && inState.length <= 2 || configs.some(holds) || ledgers.length > 0 || own.ok && existsSync12(own.value) && holds(path31.dirname(own.value));
|
|
19811
|
+
};
|
|
19812
|
+
var removesLedger = (cwd, source, state, configs) => {
|
|
19813
|
+
const real = canonical5(source);
|
|
19814
|
+
if (/(?:^|[\\/])\.git(?:[\\/]workit)?$/i.test(real) || inRepoLedger(real))
|
|
19815
|
+
return true;
|
|
19816
|
+
const own = ledgerPath(cwd);
|
|
19817
|
+
if (own.ok) {
|
|
19818
|
+
const rel = path31.relative(real, canonical5(path31.dirname(own.value)));
|
|
19819
|
+
if (rel === "" || !rel.startsWith("..") && !path31.isAbsolute(rel))
|
|
19820
|
+
return true;
|
|
19821
|
+
}
|
|
19822
|
+
return holdsGuarded(cwd, source, state, configs);
|
|
19823
|
+
};
|
|
19824
|
+
var findTests = (marker) => {
|
|
19825
|
+
try {
|
|
19826
|
+
return JSON.parse(decodeURIComponent(marker.slice(REMOVED_SOURCE.length + 1)));
|
|
19827
|
+
} catch {
|
|
19828
|
+
return null;
|
|
19829
|
+
}
|
|
19830
|
+
};
|
|
19831
|
+
var findReachesLedger = (cwd, root, find) => {
|
|
19832
|
+
if (find === null)
|
|
19833
|
+
return true;
|
|
19834
|
+
const real = canonical5(root);
|
|
19835
|
+
const own = ledgerPath(cwd);
|
|
19836
|
+
const ledgers = [
|
|
19837
|
+
...own.ok ? [canonical5(path31.dirname(own.value))] : [],
|
|
19838
|
+
...[".git/workit/ledger", "workit/ledger", "ledger"].map((rel) => path31.join(real, rel)).filter((dir) => existsSync12(dir) && inRepoLedger(dir))
|
|
19839
|
+
];
|
|
19840
|
+
const under = (parent, child) => {
|
|
19841
|
+
const rel = path31.relative(parent, child);
|
|
19842
|
+
return rel === "" || !rel.startsWith("..") && !path31.isAbsolute(rel);
|
|
19843
|
+
};
|
|
19844
|
+
const patterns = find.tests.map(([kind, pattern]) => {
|
|
19845
|
+
const fold = kind.endsWith("i");
|
|
19846
|
+
const glob = globPattern(pattern, true);
|
|
19847
|
+
let test = /(?:)/;
|
|
19848
|
+
try {
|
|
19849
|
+
test = kind.startsWith("regex") ? new RegExp(`^${pattern}$`, fold ? "i" : "") : glob ? new RegExp(glob.source, fold ? "iu" : "u") : test;
|
|
19850
|
+
} catch {}
|
|
19851
|
+
return { kind, test };
|
|
19852
|
+
});
|
|
19853
|
+
const matches = (entry) => patterns.length === 0 || patterns.some(({ kind, test }) => test.test(kind.startsWith("name") ? path31.basename(entry) : path31.join(find.root, path31.relative(real, entry)).replaceAll("\\", "/")));
|
|
19854
|
+
for (const ledger of ledgers) {
|
|
19855
|
+
if (!existsSync12(ledger) || !under(real, ledger) && !under(ledger, real))
|
|
19856
|
+
continue;
|
|
19857
|
+
const entries = [];
|
|
19858
|
+
for (let dir = ledger;under(real, dir) && dir !== real; dir = path31.dirname(dir))
|
|
19859
|
+
entries.push(dir);
|
|
19860
|
+
const walk = (dir) => {
|
|
19861
|
+
for (const item of readdirSync4(dir, { withFileTypes: true })) {
|
|
19862
|
+
if (entries.length > 500)
|
|
19863
|
+
return;
|
|
19864
|
+
const file = path31.join(dir, item.name);
|
|
19865
|
+
entries.push(file);
|
|
19866
|
+
if (item.isDirectory())
|
|
19867
|
+
walk(file);
|
|
19868
|
+
}
|
|
19869
|
+
};
|
|
19870
|
+
try {
|
|
19871
|
+
walk(ledger);
|
|
19872
|
+
} catch {
|
|
19873
|
+
return true;
|
|
19874
|
+
}
|
|
19875
|
+
if (entries.some((entry) => under(real, entry) && matches(entry)))
|
|
19876
|
+
return true;
|
|
19877
|
+
}
|
|
19878
|
+
return false;
|
|
19682
19879
|
};
|
|
19683
19880
|
var registryTarget = (cwd, targets) => {
|
|
19684
19881
|
const state = resolveStateDir();
|
|
@@ -19686,20 +19883,28 @@ var registryTarget = (cwd, targets) => {
|
|
|
19686
19883
|
const inodes = {};
|
|
19687
19884
|
for (const target of targets) {
|
|
19688
19885
|
const file = homeExpanded(target);
|
|
19689
|
-
if (
|
|
19690
|
-
const
|
|
19886
|
+
if (path31.basename(file).startsWith(REMOVED_SOURCE)) {
|
|
19887
|
+
const marker = path31.basename(file);
|
|
19888
|
+
const source = path31.dirname(path31.resolve(cwd, file));
|
|
19889
|
+
const find = marker === REMOVED_SOURCE ? null : findTests(marker);
|
|
19890
|
+
if (expandGlob(source).some((gone) => find ? findReachesLedger(cwd, gone, find) : removesLedger(cwd, gone, state, configs)))
|
|
19891
|
+
return { file: path31.join(source, REMOVED_SOURCE), registry: "removes" };
|
|
19892
|
+
continue;
|
|
19893
|
+
}
|
|
19894
|
+
if (path31.basename(file) === LINK_SOURCE) {
|
|
19895
|
+
const source = path31.dirname(path31.resolve(cwd, file));
|
|
19691
19896
|
const reached = registryTarget(cwd, [source])?.registry ?? (holdsGuarded(cwd, source, state, configs) ? "holds" : null);
|
|
19692
19897
|
if (reached)
|
|
19693
19898
|
return { file: target, registry: reached };
|
|
19694
19899
|
continue;
|
|
19695
19900
|
}
|
|
19696
|
-
if (realPath(
|
|
19901
|
+
if (realPath(path31.resolve(cwd, file)) === null)
|
|
19697
19902
|
return { file: target, registry: "link" };
|
|
19698
19903
|
const glob = globbed(cwd, file, state, configs)[0];
|
|
19699
19904
|
const viaGlob = glob === undefined ? null : registryTarget(cwd, [glob]);
|
|
19700
19905
|
if (viaGlob)
|
|
19701
19906
|
return { file: target, registry: viaGlob.registry };
|
|
19702
|
-
const registry = hardLinked(
|
|
19907
|
+
const registry = hardLinked(path31.resolve(cwd, file), state, configs, inodes) ?? underRegistry(state, cwd, file, process.platform, canonical5) ?? (inRepoLedger(canonical5(path31.resolve(cwd, file))) ? "ledger" : null) ?? (configs.some((dir) => underConfig(dir, cwd, file, process.platform, canonical5)) ? "grants" : null);
|
|
19703
19908
|
if (registry)
|
|
19704
19909
|
return { file: target, registry };
|
|
19705
19910
|
}
|
|
@@ -19707,7 +19912,7 @@ var registryTarget = (cwd, targets) => {
|
|
|
19707
19912
|
};
|
|
19708
19913
|
var partsUnder = (dir, cwd, target, platform, real) => {
|
|
19709
19914
|
const win = platform === "win32";
|
|
19710
|
-
const p = win ?
|
|
19915
|
+
const p = win ? path31.win32 : path31.posix;
|
|
19711
19916
|
const fold = (value) => win || platform === "darwin" ? value.toLowerCase() : value;
|
|
19712
19917
|
const named = win ? target.replace(/^\/([a-zA-Z])(?=\/|$)/, "$1:") : target;
|
|
19713
19918
|
const relative = p.relative(fold(real(p.resolve(dir))), fold(real(p.resolve(cwd, named))));
|
|
@@ -19760,6 +19965,11 @@ var REGISTRY_DENY = {
|
|
|
19760
19965
|
what: "a symlink chain Workit could not resolve (over 40 links), which may reach a guarded path",
|
|
19761
19966
|
unblock: "Write to the file's real path."
|
|
19762
19967
|
},
|
|
19968
|
+
removes: {
|
|
19969
|
+
label: "ledger guard",
|
|
19970
|
+
what: "a Workit ledger, the git dir that holds one or Workit's state",
|
|
19971
|
+
unblock: "Never remove or move `.git`, `.git/workit` or a dir that holds a Workit ledger: the ledger keeps the session's verdicts and pins. Remove the files you made by name."
|
|
19972
|
+
},
|
|
19763
19973
|
holds: {
|
|
19764
19974
|
label: "registry guard",
|
|
19765
19975
|
what: "Workit's state, its config or a repository ledger",
|
|
@@ -19788,19 +19998,25 @@ var REGISTRY_DENY = {
|
|
|
19788
19998
|
};
|
|
19789
19999
|
var registryDeny = ({ file, registry }) => {
|
|
19790
20000
|
const { label, what, unblock } = REGISTRY_DENY[registry];
|
|
19791
|
-
if (
|
|
20001
|
+
if (path31.basename(file) === LINK_SOURCE)
|
|
19792
20002
|
return {
|
|
19793
20003
|
kind: "deny",
|
|
19794
|
-
reason: `workit ${label}: this command links or mounts ${
|
|
20004
|
+
reason: `workit ${label}: this command links or mounts ${path31.dirname(file)}, which is or holds ${what}. ${LINK_UNBLOCK}`,
|
|
19795
20005
|
unblock: LINK_UNBLOCK
|
|
19796
20006
|
};
|
|
19797
|
-
if (
|
|
20007
|
+
if (path31.basename(file) === REMOVED_SOURCE)
|
|
20008
|
+
return {
|
|
20009
|
+
kind: "deny",
|
|
20010
|
+
reason: `workit ${label}: this command removes or moves ${path31.dirname(file)}, which is or holds ${what}. ${unblock}`,
|
|
20011
|
+
unblock
|
|
20012
|
+
};
|
|
20013
|
+
if (path31.basename(file) === UNRESOLVED_TARGET)
|
|
19798
20014
|
return {
|
|
19799
20015
|
kind: "deny",
|
|
19800
20016
|
reason: `workit ${label}: Workit could not resolve the file this command's script writes, which it builds from a path under ${what}. ${unblock}`,
|
|
19801
20017
|
unblock
|
|
19802
20018
|
};
|
|
19803
|
-
const named =
|
|
20019
|
+
const named = path31.basename(file).startsWith(".workit-") ? path31.dirname(file) : file;
|
|
19804
20020
|
return {
|
|
19805
20021
|
kind: "deny",
|
|
19806
20022
|
reason: `workit ${label}: ${named} is under ${what}. ${unblock}`,
|
|
@@ -19891,10 +20107,10 @@ import { spawnSync as spawnSync16 } from "node:child_process";
|
|
|
19891
20107
|
|
|
19892
20108
|
// packages/workit-core/src/ci-waiter.ts
|
|
19893
20109
|
import fs21 from "node:fs";
|
|
19894
|
-
import
|
|
20110
|
+
import path32 from "node:path";
|
|
19895
20111
|
var waiterFile = (cwd, pr) => {
|
|
19896
20112
|
const common = gitCommonDir(cwd);
|
|
19897
|
-
return common ?
|
|
20113
|
+
return common ? path32.join(common, "workit", "ci-waits", `pr-${pr}.json`) : null;
|
|
19898
20114
|
};
|
|
19899
20115
|
var pidAlive2 = (pid) => {
|
|
19900
20116
|
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
@@ -19966,11 +20182,11 @@ function currentJudgment(cwd) {
|
|
|
19966
20182
|
}
|
|
19967
20183
|
|
|
19968
20184
|
// packages/workit-core/src/core/verdict-set.ts
|
|
19969
|
-
import
|
|
20185
|
+
import path33 from "node:path";
|
|
19970
20186
|
var SET_TTL_MS = 7 * 86400000;
|
|
19971
20187
|
var SET_ROW = "verdict.set";
|
|
19972
20188
|
var SET_VOID = "verdict.set.voided";
|
|
19973
|
-
var setStorePath = () =>
|
|
20189
|
+
var setStorePath = () => path33.join(resolveStateDir(), "verdicts", "sets", "ledger.jsonl");
|
|
19974
20190
|
var distrusted = (cwd, id, rows, type) => rows.some((row) => row.type === type && row.id === id && trustReasons(cwd, row).length > 0);
|
|
19975
20191
|
function gateStands(cwd, gate, rows, now = Date.now()) {
|
|
19976
20192
|
const id = typeof gate.verdictId === "string" ? gate.verdictId : null;
|
|
@@ -20421,12 +20637,12 @@ ${line}` };
|
|
|
20421
20637
|
};
|
|
20422
20638
|
// packages/workit-core/src/hooks/hosts/fields.ts
|
|
20423
20639
|
import { existsSync as existsSync13, realpathSync as realpathSync9, statSync as statSync4 } from "node:fs";
|
|
20424
|
-
import
|
|
20640
|
+
import path34 from "node:path";
|
|
20425
20641
|
var isRecord7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
20426
20642
|
var nonEmpty2 = (value) => typeof value === "string" && value.trim() !== "";
|
|
20427
20643
|
var optionalText = (value) => typeof value === "string" ? value : null;
|
|
20428
20644
|
var existingDirectory = (value) => {
|
|
20429
|
-
if (!nonEmpty2(value) || !
|
|
20645
|
+
if (!nonEmpty2(value) || !path34.isAbsolute(value) || !existsSync13(value))
|
|
20430
20646
|
return null;
|
|
20431
20647
|
try {
|
|
20432
20648
|
return statSync4(value).isDirectory() ? realpathSync9(value) : null;
|
|
@@ -20494,7 +20710,7 @@ var writeTargets = (input) => {
|
|
|
20494
20710
|
};
|
|
20495
20711
|
// packages/workit-core/src/hooks/standing.ts
|
|
20496
20712
|
import fs23 from "node:fs";
|
|
20497
|
-
import
|
|
20713
|
+
import path36 from "node:path";
|
|
20498
20714
|
|
|
20499
20715
|
// packages/workit-core/src/approvals/store.ts
|
|
20500
20716
|
var REQUEST_TTL_MS = 30 * 60000;
|
|
@@ -21202,35 +21418,35 @@ function neededChecks(lane, configured) {
|
|
|
21202
21418
|
import { createHash as createHash16 } from "node:crypto";
|
|
21203
21419
|
import fs22 from "node:fs";
|
|
21204
21420
|
import os10 from "node:os";
|
|
21205
|
-
import
|
|
21421
|
+
import path35 from "node:path";
|
|
21206
21422
|
var FANOUT_TOKEN_FILE = "workit-fanout-token";
|
|
21207
21423
|
var NONE5 = { kind: "none" };
|
|
21208
21424
|
var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
|
|
21209
21425
|
var realOf = (file) => {
|
|
21210
21426
|
let rest = "";
|
|
21211
|
-
for (let dir = file;; dir =
|
|
21427
|
+
for (let dir = file;; dir = path35.dirname(dir)) {
|
|
21212
21428
|
try {
|
|
21213
|
-
return
|
|
21429
|
+
return path35.join(fs22.realpathSync.native(dir), rest);
|
|
21214
21430
|
} catch {
|
|
21215
|
-
if (
|
|
21431
|
+
if (path35.dirname(dir) === dir)
|
|
21216
21432
|
return file;
|
|
21217
|
-
rest = rest ?
|
|
21433
|
+
rest = rest ? path35.join(path35.basename(dir), rest) : path35.basename(dir);
|
|
21218
21434
|
}
|
|
21219
21435
|
}
|
|
21220
21436
|
};
|
|
21221
21437
|
var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
|
|
21222
|
-
const start =
|
|
21223
|
-
const { root } =
|
|
21438
|
+
const start = path35.isAbsolute(file) ? file : `${process.cwd()}${path35.sep}${file}`;
|
|
21439
|
+
const { root } = path35.parse(start);
|
|
21224
21440
|
let at = root;
|
|
21225
21441
|
let missing = false;
|
|
21226
21442
|
for (const part of start.slice(root.length).split(/[\\/]+/)) {
|
|
21227
21443
|
if (part === "" || part === ".")
|
|
21228
21444
|
continue;
|
|
21229
21445
|
if (part === "..") {
|
|
21230
|
-
at =
|
|
21446
|
+
at = path35.dirname(at);
|
|
21231
21447
|
continue;
|
|
21232
21448
|
}
|
|
21233
|
-
const next =
|
|
21449
|
+
const next = path35.join(at, part);
|
|
21234
21450
|
let link = null;
|
|
21235
21451
|
if (!missing)
|
|
21236
21452
|
try {
|
|
@@ -21242,25 +21458,25 @@ var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
|
|
|
21242
21458
|
at = next;
|
|
21243
21459
|
hops.chain = 40;
|
|
21244
21460
|
} else if (hops.chain-- > 0 && hops.total-- > 0)
|
|
21245
|
-
at = canonical6(
|
|
21461
|
+
at = canonical6(path35.isAbsolute(link) ? link : `${at}${path35.sep}${link}`, hops);
|
|
21246
21462
|
else
|
|
21247
|
-
return
|
|
21463
|
+
return path35.resolve(file);
|
|
21248
21464
|
}
|
|
21249
21465
|
return realOf(at);
|
|
21250
21466
|
};
|
|
21251
21467
|
var within = (child, parent) => {
|
|
21252
21468
|
const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
|
|
21253
|
-
const relative =
|
|
21254
|
-
return relative === "" || !relative.startsWith("..") && !
|
|
21469
|
+
const relative = path35.relative(fold(parent), fold(child));
|
|
21470
|
+
return relative === "" || !relative.startsWith("..") && !path35.isAbsolute(relative);
|
|
21255
21471
|
};
|
|
21256
21472
|
var checkoutOf2 = (file) => {
|
|
21257
|
-
for (let dir = canonical6(file);; dir =
|
|
21258
|
-
const dotGit =
|
|
21473
|
+
for (let dir = canonical6(file);; dir = path35.dirname(dir)) {
|
|
21474
|
+
const dotGit = path35.join(dir, ".git");
|
|
21259
21475
|
if (fs22.existsSync(dotGit)) {
|
|
21260
21476
|
const admin = fs22.statSync(dotGit).isFile() ? gitDirsAt(dir, null, false)?.[0] : undefined;
|
|
21261
|
-
return { root: dir, workit: !!admin && fs22.existsSync(
|
|
21477
|
+
return { root: dir, workit: !!admin && fs22.existsSync(path35.join(admin, FANOUT_TOKEN_FILE)) };
|
|
21262
21478
|
}
|
|
21263
|
-
if (
|
|
21479
|
+
if (path35.dirname(dir) === dir)
|
|
21264
21480
|
return null;
|
|
21265
21481
|
}
|
|
21266
21482
|
};
|
|
@@ -21272,8 +21488,8 @@ var workitWorktreeOf = (file) => {
|
|
|
21272
21488
|
return null;
|
|
21273
21489
|
}
|
|
21274
21490
|
};
|
|
21275
|
-
var bindingDir = () =>
|
|
21276
|
-
var bindingFile = (session, agentId) =>
|
|
21491
|
+
var bindingDir = () => path35.join(resolveStateDir(), "worktree-bind");
|
|
21492
|
+
var bindingFile = (session, agentId) => path35.join(bindingDir(), `${createHash16("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
|
|
21277
21493
|
var readBinding = (file) => {
|
|
21278
21494
|
try {
|
|
21279
21495
|
const value = JSON.parse(fs22.readFileSync(file, "utf8"));
|
|
@@ -21298,7 +21514,7 @@ var bind = (input, worktree) => {
|
|
|
21298
21514
|
agentId,
|
|
21299
21515
|
at: new Date().toISOString()
|
|
21300
21516
|
};
|
|
21301
|
-
fs22.mkdirSync(
|
|
21517
|
+
fs22.mkdirSync(path35.dirname(file), { recursive: true });
|
|
21302
21518
|
fs22.writeFileSync(file, JSON.stringify(binding));
|
|
21303
21519
|
try {
|
|
21304
21520
|
if (inWorkitWorkspace(input.cwd))
|
|
@@ -21317,26 +21533,26 @@ var hostIsolated = (cwd, agentId) => {
|
|
|
21317
21533
|
const checkout = checkoutOf2(cwd);
|
|
21318
21534
|
if (!checkout)
|
|
21319
21535
|
return false;
|
|
21320
|
-
const dotGit =
|
|
21536
|
+
const dotGit = path35.join(checkout.root, ".git");
|
|
21321
21537
|
if (!fs22.statSync(dotGit).isFile())
|
|
21322
21538
|
return false;
|
|
21323
21539
|
const [adminDir, gitDir] = gitDirsAt(checkout.root, null, false) ?? [];
|
|
21324
|
-
const back = fs22.readFileSync(
|
|
21325
|
-
if (
|
|
21540
|
+
const back = fs22.readFileSync(path35.join(adminDir, "gitdir"), "utf8").trim();
|
|
21541
|
+
if (path35.relative(canonical6(path35.resolve(adminDir, back)), canonical6(dotGit)) !== "")
|
|
21326
21542
|
return false;
|
|
21327
|
-
const expected =
|
|
21328
|
-
return
|
|
21543
|
+
const expected = path35.join(path35.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
|
|
21544
|
+
return path35.relative(canonical6(expected), checkout.root) === "";
|
|
21329
21545
|
} catch {
|
|
21330
21546
|
return false;
|
|
21331
21547
|
}
|
|
21332
21548
|
};
|
|
21333
21549
|
var runnerAt = (target) => {
|
|
21334
|
-
const base =
|
|
21550
|
+
const base = path35.basename(target);
|
|
21335
21551
|
return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
|
|
21336
21552
|
};
|
|
21337
21553
|
var shown = (target) => {
|
|
21338
|
-
const named = /^\.workit-(?:live-target$|runs-)/.test(
|
|
21339
|
-
return
|
|
21554
|
+
const named = /^\.workit-(?:live-target$|runs-)/.test(path35.basename(target)) ? path35.dirname(target) : target;
|
|
21555
|
+
return path35.sep === "\\" ? named.replaceAll("/", "\\") : named;
|
|
21340
21556
|
};
|
|
21341
21557
|
var runFrom = (dir, command) => `cd ${dir} && ${command.replace(/^\s*cd\s+\S+\s*(?:&&|;)\s*/, "")}`;
|
|
21342
21558
|
var deny2 = (what, unblock) => ({
|
|
@@ -21352,7 +21568,7 @@ var outsideDeny = (input, worktree, target, command) => {
|
|
|
21352
21568
|
};
|
|
21353
21569
|
var unknownDirDeny = (input, worktree) => deny2(`workit worktree confinement: implementer ${input.session.agentId} writes after a directory change Workit cannot resolve (\`cd -\`, \`cd "$X"\`, \`popd\`)`, `Why: write by absolute path, \`git -C ${worktree ?? "<worktree>"}\` or \`workit <verb> --cwd\`.`);
|
|
21354
21570
|
var refsOf = (targets) => [
|
|
21355
|
-
...new Set(targets.flatMap((target) =>
|
|
21571
|
+
...new Set(targets.flatMap((target) => path35.relative(UNKNOWN_VAR, path35.resolve(target)).split(path35.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
|
|
21356
21572
|
];
|
|
21357
21573
|
var literalForm = (command, refs) => {
|
|
21358
21574
|
let text = command;
|
|
@@ -21385,10 +21601,10 @@ function confineImplementer(input, targets, command) {
|
|
|
21385
21601
|
try {
|
|
21386
21602
|
if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
|
|
21387
21603
|
return NONE5;
|
|
21388
|
-
const unresolved = targets.filter((target) => within(
|
|
21604
|
+
const unresolved = targets.filter((target) => within(path35.resolve(target), UNKNOWN_VAR));
|
|
21389
21605
|
if (unresolved.length > 0)
|
|
21390
21606
|
return unknownVarDeny(input, unresolved, command);
|
|
21391
|
-
if (targets.some((target) => within(
|
|
21607
|
+
if (targets.some((target) => within(path35.resolve(target), UNKNOWN_DIR)))
|
|
21392
21608
|
return unknownDirDeny(input, boundWorktree(input));
|
|
21393
21609
|
const bindings = canonical6(bindingDir());
|
|
21394
21610
|
const judged = targets.map((named) => ({ named, real: canonical6(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
|
|
@@ -21495,10 +21711,10 @@ var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print)(?:=|$)|^--(?:test|version|he
|
|
|
21495
21711
|
var VALUED2 = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
|
|
21496
21712
|
var commonDir = (root) => gitDirsAt(root, null, false)?.[1] ?? "";
|
|
21497
21713
|
var inScratch = (real, repo) => {
|
|
21498
|
-
for (let dir = real;
|
|
21499
|
-
if (
|
|
21714
|
+
for (let dir = real;path35.dirname(dir) !== dir; dir = path35.dirname(dir)) {
|
|
21715
|
+
if (path35.basename(dir) !== SCRATCH)
|
|
21500
21716
|
continue;
|
|
21501
|
-
const root =
|
|
21717
|
+
const root = path35.dirname(dir);
|
|
21502
21718
|
const checkout = checkoutOf2(root);
|
|
21503
21719
|
if (checkout?.root === root && (repo === null || checkout.workit || commonDir(root) === repo))
|
|
21504
21720
|
return true;
|
|
@@ -21508,7 +21724,7 @@ var inScratch = (real, repo) => {
|
|
|
21508
21724
|
var inGitDir = (real) => real.split(/[\\/]/).includes(".git");
|
|
21509
21725
|
var SAFE_KEY = /^(?:core\.(?:repositoryformatversion|filemode|bare|logallrefupdates|ignorecase|precomposeunicode|symlinks)|user\..*|init\.defaultbranch|commit\.gpgsign|extensions\.(?:objectformat|refstorage)|branch\..*\.(?:remote|merge)|remote\..*\.fetch)$/;
|
|
21510
21726
|
var literalIn = (value, repo, checkout = false) => {
|
|
21511
|
-
if (/[$`]/.test(value) || !
|
|
21727
|
+
if (/[$`]/.test(value) || !path35.isAbsolute(value))
|
|
21512
21728
|
return false;
|
|
21513
21729
|
const real = canonical6(value);
|
|
21514
21730
|
const root = checkout ? checkoutOf2(real)?.root : undefined;
|
|
@@ -21529,8 +21745,8 @@ var configEntries = (text) => {
|
|
|
21529
21745
|
return entries;
|
|
21530
21746
|
};
|
|
21531
21747
|
function gitDirsAt(dir, repo, scan = true) {
|
|
21532
|
-
for (let at = dir;; at =
|
|
21533
|
-
const dotGit =
|
|
21748
|
+
for (let at = dir;; at = path35.dirname(at)) {
|
|
21749
|
+
const dotGit = path35.join(at, ".git");
|
|
21534
21750
|
let gitDir = null;
|
|
21535
21751
|
try {
|
|
21536
21752
|
if (fs22.statSync(dotGit).isDirectory())
|
|
@@ -21539,19 +21755,19 @@ function gitDirsAt(dir, repo, scan = true) {
|
|
|
21539
21755
|
const named = /^gitdir:\s*(.+?)\s*$/mu.exec(fs22.readFileSync(dotGit, "utf8"))?.[1];
|
|
21540
21756
|
if (!named)
|
|
21541
21757
|
return null;
|
|
21542
|
-
gitDir = canonical6(
|
|
21758
|
+
gitDir = canonical6(path35.resolve(at, named));
|
|
21543
21759
|
}
|
|
21544
21760
|
} catch (error) {
|
|
21545
21761
|
if (error.code !== "ENOENT")
|
|
21546
21762
|
return null;
|
|
21547
|
-
if (["HEAD", "objects", "refs"].every((name) => fs22.existsSync(
|
|
21763
|
+
if (["HEAD", "objects", "refs"].every((name) => fs22.existsSync(path35.join(at, name))))
|
|
21548
21764
|
gitDir = canonical6(at);
|
|
21549
21765
|
}
|
|
21550
21766
|
if (gitDir !== null) {
|
|
21551
|
-
const common =
|
|
21552
|
-
const shared = fs22.existsSync(common) ? canonical6(
|
|
21767
|
+
const common = path35.join(gitDir, "commondir");
|
|
21768
|
+
const shared = fs22.existsSync(common) ? canonical6(path35.resolve(gitDir, fs22.readFileSync(common, "utf8").trim())) : gitDir;
|
|
21553
21769
|
const dirs = [gitDir, shared];
|
|
21554
|
-
for (const config of scan ? new Set([
|
|
21770
|
+
for (const config of scan ? new Set([path35.join(gitDir, "config"), path35.join(shared, "config")]) : []) {
|
|
21555
21771
|
let text = "";
|
|
21556
21772
|
try {
|
|
21557
21773
|
text = fs22.readFileSync(config, "utf8");
|
|
@@ -21560,14 +21776,14 @@ function gitDirsAt(dir, repo, scan = true) {
|
|
|
21560
21776
|
}
|
|
21561
21777
|
for (const [key, value] of configEntries(text)) {
|
|
21562
21778
|
if (key === "core.worktree")
|
|
21563
|
-
dirs.push(canonical6(
|
|
21779
|
+
dirs.push(canonical6(path35.resolve(gitDir, value)));
|
|
21564
21780
|
else if (/^remote\..*\.url$/.test(key) ? !literalIn(value, repo, true) : !SAFE_KEY.test(key))
|
|
21565
21781
|
return null;
|
|
21566
21782
|
}
|
|
21567
21783
|
}
|
|
21568
21784
|
return dirs;
|
|
21569
21785
|
}
|
|
21570
|
-
if (
|
|
21786
|
+
if (path35.dirname(at) === at)
|
|
21571
21787
|
return [];
|
|
21572
21788
|
}
|
|
21573
21789
|
}
|
|
@@ -21707,10 +21923,10 @@ var gitKind = (args, local = () => true) => {
|
|
|
21707
21923
|
return GIT_VERBS[verb].startsWith("+") ? "write" : "read";
|
|
21708
21924
|
};
|
|
21709
21925
|
var remoteIn = (dir, name, repo) => {
|
|
21710
|
-
const shared =
|
|
21926
|
+
const shared = path35.isAbsolute(dir) ? gitDirsAt(canonical6(dir), repo, false)?.[1] : undefined;
|
|
21711
21927
|
if (!shared)
|
|
21712
21928
|
return false;
|
|
21713
|
-
const url = configEntries(fs22.readFileSync(
|
|
21929
|
+
const url = configEntries(fs22.readFileSync(path35.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
|
|
21714
21930
|
return url !== undefined && literalIn(url, repo, true);
|
|
21715
21931
|
};
|
|
21716
21932
|
var judgeEnvAllowed = (word) => {
|
|
@@ -21739,7 +21955,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
21739
21955
|
at = after;
|
|
21740
21956
|
}
|
|
21741
21957
|
}
|
|
21742
|
-
const name =
|
|
21958
|
+
const name = path35.basename(words[at] ?? "");
|
|
21743
21959
|
let start = words.findIndex((word) => /(?:^|[\\/])git(?:\.exe)?(?:=|$)/.test(word));
|
|
21744
21960
|
if (start > at) {
|
|
21745
21961
|
if (/^(?:grep|egrep|rg|echo|printf|ls|wc|head|tail|cat|which|type|test|\[|cd|mkdir)$/.test(name) || name === "command" && /^-[vV]$/.test(words[at + 1] ?? ""))
|
|
@@ -21750,7 +21966,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
21750
21966
|
if (start >= 0 && words[start].includes("="))
|
|
21751
21967
|
why = "git is redefined";
|
|
21752
21968
|
const run = words[start] ?? "";
|
|
21753
|
-
if (run.includes("/") && (!
|
|
21969
|
+
if (run.includes("/") && (!path35.isAbsolute(run) || literalIn(run, repo, true)))
|
|
21754
21970
|
why ??= `\`${run}\` is not the system git`;
|
|
21755
21971
|
if (segment.expands?.includes(at) && name !== "[" || /\{[^}]*,/.test(words[at] ?? ""))
|
|
21756
21972
|
why = "the command's name is expanded by the shell";
|
|
@@ -21775,13 +21991,13 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
21775
21991
|
const args = words[index] === "--version" ? ["version"] : words.slice(index);
|
|
21776
21992
|
if (!why && start >= 0) {
|
|
21777
21993
|
const local = (source, remote) => remote && /^[\w-][\w.-]*$/.test(source) ? remoteIn(dir, source, repo) : literalIn(source, repo, true);
|
|
21778
|
-
const runsIn =
|
|
21994
|
+
const runsIn = path35.isAbsolute(dir) ? dir : cwd && path35.resolve(cwd, dir);
|
|
21779
21995
|
const home = runsIn && checkoutOf2(runsIn);
|
|
21780
21996
|
const fetches = args[0] === "fetch" && plainFetch(args.slice(1)) && home && (home.workit || commonDir(home.root) === repo) && !words.some((word) => /^--[gw]/.test(word));
|
|
21781
21997
|
if (!fetches && !gitKind(args, local))
|
|
21782
21998
|
why = `\`git ${args.slice(0, 2).join(" ")}\` is not allowed`;
|
|
21783
21999
|
}
|
|
21784
|
-
const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(
|
|
22000
|
+
const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path35.basename(word)));
|
|
21785
22001
|
const scripts = [
|
|
21786
22002
|
...words.filter((_, after) => shell >= 0 && after > shell && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(words[after - 1])),
|
|
21787
22003
|
...shell < 0 ? [] : segment.stdin ?? []
|
|
@@ -21826,7 +22042,7 @@ var judgeVerbRefused = (args) => {
|
|
|
21826
22042
|
var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
|
|
21827
22043
|
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?$/;
|
|
21828
22044
|
var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
|
|
21829
|
-
const name =
|
|
22045
|
+
const name = path35.basename(words[0] ?? "").toLowerCase();
|
|
21830
22046
|
if (name === "alias")
|
|
21831
22047
|
return words.flatMap((word) => {
|
|
21832
22048
|
const set = /^([\w-]+)=(.*)$/s.exec(word);
|
|
@@ -21855,11 +22071,11 @@ var judgeRefusal = (command, fed, depth = 0) => {
|
|
|
21855
22071
|
return why;
|
|
21856
22072
|
}
|
|
21857
22073
|
const { words } = segment;
|
|
21858
|
-
const runs = (word = "") => RUNS.test(
|
|
22074
|
+
const runs = (word = "") => RUNS.test(path35.basename(word).toLowerCase());
|
|
21859
22075
|
let at = 0;
|
|
21860
22076
|
while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
|
|
21861
22077
|
at++;
|
|
21862
|
-
const name =
|
|
22078
|
+
const name = path35.basename(words[at] ?? "").toLowerCase();
|
|
21863
22079
|
const args = words.slice(at + 1);
|
|
21864
22080
|
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`;
|
|
21865
22081
|
if (/^(?:cd|chdir|pushd|popd)$/.test(name))
|
|
@@ -21941,10 +22157,10 @@ var judgeDeny = (input, what, target, retry, why = "write only there (mkdir -p i
|
|
|
21941
22157
|
const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
|
|
21942
22158
|
const root = checkoutOf2(input.cwd)?.root;
|
|
21943
22159
|
const candidate = target ? checkoutOf2(target)?.root : undefined;
|
|
21944
|
-
const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ?
|
|
21945
|
-
const scratch = root ? `${
|
|
21946
|
-
const call = root ? retry?.((other ??
|
|
21947
|
-
const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ?
|
|
22160
|
+
const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path35.join(candidate, SCRATCH) : undefined;
|
|
22161
|
+
const scratch = root ? `${path35.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
|
|
22162
|
+
const call = root ? retry?.((other ?? path35.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
|
|
22163
|
+
const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ? path35.join(root, SCRATCH) : SCRATCH))}`;
|
|
21948
22164
|
return {
|
|
21949
22165
|
kind: "deny",
|
|
21950
22166
|
reason: `workit scratch confinement: ${role} ${input.session.agentId} may write only in its scratch dir ${scratch}, and ${what}.
|
|
@@ -21954,9 +22170,9 @@ ${unblock}`,
|
|
|
21954
22170
|
};
|
|
21955
22171
|
var movedInto = (command, cwd, target, dir) => {
|
|
21956
22172
|
for (const { words, redirects } of segmentsOf(command))
|
|
21957
|
-
for (const word of [...redirects, ...
|
|
21958
|
-
if (
|
|
21959
|
-
const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${
|
|
22173
|
+
for (const word of [...redirects, ...path35.basename(words[0] ?? "") === "tee" ? words : []])
|
|
22174
|
+
if (path35.resolve(cwd, word) === path35.resolve(cwd, target)) {
|
|
22175
|
+
const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path35.basename(word)}`);
|
|
21960
22176
|
return moved === command ? null : moved;
|
|
21961
22177
|
}
|
|
21962
22178
|
return null;
|
|
@@ -21968,19 +22184,19 @@ function confineJudge(input, targets, placeholders = placeholdersOf(targets), co
|
|
|
21968
22184
|
const judged = checkoutOf2(input.cwd);
|
|
21969
22185
|
const repo = judged ? commonDir(judged.root) : null;
|
|
21970
22186
|
const scratch = (real) => inScratch(real, repo) || [os10.tmpdir(), "/tmp"].some((dir) => {
|
|
21971
|
-
const [host, , session] =
|
|
22187
|
+
const [host, , session] = path35.relative(canonical6(dir), real).split(path35.sep);
|
|
21972
22188
|
return /^claude-\d+$/.test(host) && session === input.session.id;
|
|
21973
22189
|
});
|
|
21974
22190
|
for (const target of targets) {
|
|
21975
|
-
const resolved =
|
|
22191
|
+
const resolved = path35.resolve(target);
|
|
21976
22192
|
if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
|
|
21977
22193
|
return judgeDeny(input, "it writes to a path Workit cannot resolve", undefined, () => {
|
|
21978
22194
|
const literal = command && literalForm(command, refsOf([target]));
|
|
21979
22195
|
return literal === command ? null : literal;
|
|
21980
22196
|
});
|
|
21981
22197
|
const real = canonical6(target);
|
|
21982
|
-
const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(
|
|
21983
|
-
const gitDirs = runsGit ? gitDirsAt(
|
|
22198
|
+
const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path35.basename(target));
|
|
22199
|
+
const gitDirs = runsGit ? gitDirsAt(path35.dirname(real), repo) : [];
|
|
21984
22200
|
if (gitDirs === null)
|
|
21985
22201
|
return judgeDeny(input, `git in ${shown(target)} uses a git dir or config Workit cannot check`);
|
|
21986
22202
|
if (runsGit ? gitDirs.length > 0 ? gitDirs.every(scratch) : scratch(real) : scratch(real) && !inGitDir(real))
|
|
@@ -22048,7 +22264,7 @@ function confineJudgeShell(input, command, dialect = "posix") {
|
|
|
22048
22264
|
let git = [];
|
|
22049
22265
|
try {
|
|
22050
22266
|
git = rawInvocations(command, dialect).flatMap(({ tool, dir, args }) => tool === "git" && (args[0] === "push" || leadOwnedGit(args) || gitKind(args) === "write" && !/^(?:init|clone)$/.test(args[0]) && !(args[0] === "fetch" && plainFetch(args.slice(1)))) ? [
|
|
22051
|
-
|
|
22267
|
+
path35.join(dir === undefined ? UNKNOWN_DIR : path35.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
|
|
22052
22268
|
] : []);
|
|
22053
22269
|
} catch {}
|
|
22054
22270
|
const lists = [
|
|
@@ -22093,7 +22309,7 @@ var judgeChecksLine = (cwd) => {
|
|
|
22093
22309
|
|
|
22094
22310
|
// packages/workit-core/src/hooks/standing.ts
|
|
22095
22311
|
var readPlans = (store) => {
|
|
22096
|
-
const dir =
|
|
22312
|
+
const dir = path36.join(store, "fanouts");
|
|
22097
22313
|
let names;
|
|
22098
22314
|
try {
|
|
22099
22315
|
names = fs23.readdirSync(dir).filter((name) => name.endsWith(".json"));
|
|
@@ -22103,7 +22319,7 @@ var readPlans = (store) => {
|
|
|
22103
22319
|
const plans = [];
|
|
22104
22320
|
for (const name of names) {
|
|
22105
22321
|
try {
|
|
22106
|
-
const raw = JSON.parse(fs23.readFileSync(
|
|
22322
|
+
const raw = JSON.parse(fs23.readFileSync(path36.join(dir, name), "utf8"));
|
|
22107
22323
|
if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
|
|
22108
22324
|
continue;
|
|
22109
22325
|
const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
|
|
@@ -22313,12 +22529,12 @@ var cdWorkitSplit = (command) => {
|
|
|
22313
22529
|
|
|
22314
22530
|
// packages/workit-core/src/hooks/spawn-gate.ts
|
|
22315
22531
|
import fs24 from "node:fs";
|
|
22316
|
-
import
|
|
22532
|
+
import path38 from "node:path";
|
|
22317
22533
|
|
|
22318
22534
|
// packages/workit-core/src/hooks/model-limit.ts
|
|
22319
|
-
import { closeSync as closeSync3, openSync as openSync3, readdirSync as
|
|
22535
|
+
import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync5, readSync, statSync as statSync5 } from "node:fs";
|
|
22320
22536
|
import os11 from "node:os";
|
|
22321
|
-
import
|
|
22537
|
+
import path37 from "node:path";
|
|
22322
22538
|
var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
22323
22539
|
var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
22324
22540
|
var TIME_WORD = String.raw`(?:\d|(?:in|at|on|later|tomorrow|soon)\b|(?:${[...WEEKDAYS, ...MONTHS].join("|")})[a-z]*\b)`;
|
|
@@ -22516,17 +22732,17 @@ var firstPrompt = (file) => {
|
|
|
22516
22732
|
var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
|
|
22517
22733
|
var listDir = (dir) => {
|
|
22518
22734
|
try {
|
|
22519
|
-
return
|
|
22735
|
+
return readdirSync5(dir).map((name) => path37.join(dir, name));
|
|
22520
22736
|
} catch {
|
|
22521
22737
|
return [];
|
|
22522
22738
|
}
|
|
22523
22739
|
};
|
|
22524
22740
|
var SCAN_MS = 30 * 60000;
|
|
22525
22741
|
var scanClaudeTranscripts = (cwd, env, now = new Date) => {
|
|
22526
|
-
const projects =
|
|
22527
|
-
const project =
|
|
22742
|
+
const projects = path37.join(env.CLAUDE_CONFIG_DIR || path37.join(env.HOME || os11.homedir(), ".claude"), "projects");
|
|
22743
|
+
const project = path37.join(projects, claudeProjectSlug(cwd));
|
|
22528
22744
|
const notes = [];
|
|
22529
|
-
const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(
|
|
22745
|
+
const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path37.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
|
|
22530
22746
|
for (const { file, worker } of files)
|
|
22531
22747
|
try {
|
|
22532
22748
|
const stat = statSync5(file);
|
|
@@ -22541,7 +22757,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
|
|
|
22541
22757
|
if (!seen)
|
|
22542
22758
|
continue;
|
|
22543
22759
|
notes.push(worker ? redispatchNote(seen, {
|
|
22544
|
-
label: `worker ${
|
|
22760
|
+
label: `worker ${path37.basename(file, ".jsonl")}`,
|
|
22545
22761
|
prompt: firstPrompt(file)
|
|
22546
22762
|
}, 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.`);
|
|
22547
22763
|
} catch {}
|
|
@@ -22643,10 +22859,10 @@ var namesMade = (word) => {
|
|
|
22643
22859
|
const stat = fs24.statSync(word);
|
|
22644
22860
|
if (stat.isFile())
|
|
22645
22861
|
return stat.size < 1e6 && MADE_WORKTREE.test(fs24.readFileSync(word, "utf8"));
|
|
22646
|
-
const dotGit =
|
|
22862
|
+
const dotGit = path38.join(word, ".git");
|
|
22647
22863
|
const link = fs24.statSync(dotGit);
|
|
22648
22864
|
const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(fs24.readFileSync(dotGit, "utf8"));
|
|
22649
|
-
return !!admin && fs24.existsSync(
|
|
22865
|
+
return !!admin && fs24.existsSync(path38.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
|
|
22650
22866
|
} catch {
|
|
22651
22867
|
return false;
|
|
22652
22868
|
}
|
|
@@ -22693,7 +22909,7 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
|
|
|
22693
22909
|
// packages/workit-core/src/hooks/teardown.ts
|
|
22694
22910
|
import { spawn } from "node:child_process";
|
|
22695
22911
|
import fs25 from "node:fs";
|
|
22696
|
-
import
|
|
22912
|
+
import path39 from "node:path";
|
|
22697
22913
|
var REAP_INTERVAL_MS = 10 * 60000;
|
|
22698
22914
|
var LOG_MAX_BYTES = 1 << 20;
|
|
22699
22915
|
var ENDS = {
|
|
@@ -22704,9 +22920,9 @@ var ENDS = {
|
|
|
22704
22920
|
};
|
|
22705
22921
|
var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
|
|
22706
22922
|
var HOST_SESSION_VARS = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
|
|
22707
|
-
var teardownDir = (env) =>
|
|
22708
|
-
var teardownLog = (env) =>
|
|
22709
|
-
var reapStamp = (env) =>
|
|
22923
|
+
var teardownDir = (env) => path39.join(stateDir3(env), "procs");
|
|
22924
|
+
var teardownLog = (env) => path39.join(teardownDir(env), "teardown.log");
|
|
22925
|
+
var reapStamp = (env) => path39.join(teardownDir(env), "reap-at-start.stamp");
|
|
22710
22926
|
function spawnDetached(request) {
|
|
22711
22927
|
try {
|
|
22712
22928
|
const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
|
|
@@ -22733,7 +22949,7 @@ var teardownDeps = {
|
|
|
22733
22949
|
var openLog = (env, args) => {
|
|
22734
22950
|
try {
|
|
22735
22951
|
const file = teardownLog(env);
|
|
22736
|
-
fs25.mkdirSync(
|
|
22952
|
+
fs25.mkdirSync(path39.dirname(file), { recursive: true });
|
|
22737
22953
|
let size = 0;
|
|
22738
22954
|
try {
|
|
22739
22955
|
size = fs25.statSync(file).size;
|
|
@@ -22818,7 +23034,7 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
22818
23034
|
try {
|
|
22819
23035
|
if (fresh(stamp, now))
|
|
22820
23036
|
return false;
|
|
22821
|
-
fs25.mkdirSync(
|
|
23037
|
+
fs25.mkdirSync(path39.dirname(stamp), { recursive: true });
|
|
22822
23038
|
if (!claim2(lock, now))
|
|
22823
23039
|
return false;
|
|
22824
23040
|
} catch {
|
|
@@ -23510,11 +23726,11 @@ Retry as: ${retry}`,
|
|
|
23510
23726
|
// packages/workit-core/src/agent-stamp.ts
|
|
23511
23727
|
import { createHash as createHash17, randomBytes as randomBytes4 } from "node:crypto";
|
|
23512
23728
|
import fs26 from "node:fs";
|
|
23513
|
-
import
|
|
23729
|
+
import path40 from "node:path";
|
|
23514
23730
|
var STAMP_TTL_MS = 120000;
|
|
23515
23731
|
var AGENT_ID = /^[\w-]{1,64}$/u;
|
|
23516
23732
|
var hash2 = (text) => createHash17("sha256").update(text).digest("hex").slice(0, 32);
|
|
23517
|
-
var stampDir = (env, session) =>
|
|
23733
|
+
var stampDir = (env, session) => path40.join(stateDir3(env), "agent-stamps", hash2(session));
|
|
23518
23734
|
var workitCalls2 = (command, dialect = "posix") => {
|
|
23519
23735
|
const calls = [];
|
|
23520
23736
|
try {
|
|
@@ -23539,9 +23755,9 @@ var noteAgentStamps = (env, session, agentId, command, options = {}) => {
|
|
|
23539
23755
|
fs26.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
23540
23756
|
const now = Date.now();
|
|
23541
23757
|
for (const name of fs26.readdirSync(dir))
|
|
23542
|
-
if (now - fs26.statSync(
|
|
23543
|
-
fs26.rmSync(
|
|
23544
|
-
calls.forEach((argv, index) => fs26.writeFileSync(
|
|
23758
|
+
if (now - fs26.statSync(path40.join(dir, name)).mtimeMs > STAMP_TTL_MS)
|
|
23759
|
+
fs26.rmSync(path40.join(dir, name), { force: true });
|
|
23760
|
+
calls.forEach((argv, index) => fs26.writeFileSync(path40.join(dir, `${hash2(argv.join("\x00"))}.${agentId ?? ""}.${call}-${index}`), ""));
|
|
23545
23761
|
} catch {}
|
|
23546
23762
|
};
|
|
23547
23763
|
var callTag = (toolUseId) => hash2(toolUseId).slice(0, 8);
|
|
@@ -23553,18 +23769,479 @@ var dropAgentStamps = (env, session, toolUseId, command) => {
|
|
|
23553
23769
|
const tag = `.${callTag(toolUseId)}-`;
|
|
23554
23770
|
for (const name of fs26.readdirSync(dir))
|
|
23555
23771
|
if (name.includes(tag))
|
|
23556
|
-
fs26.rmSync(
|
|
23772
|
+
fs26.rmSync(path40.join(dir, name), { force: true });
|
|
23557
23773
|
} catch {}
|
|
23558
23774
|
};
|
|
23559
23775
|
|
|
23776
|
+
// packages/workit-core/src/hooks/hook-entry.ts
|
|
23777
|
+
import { existsSync as existsSync14, readFileSync as readFileSync11, realpathSync as realpathSync10 } from "node:fs";
|
|
23778
|
+
import path41 from "node:path";
|
|
23779
|
+
var ENTRY_NAMES = /^(?:workit-hook(?:-[\w-]+)?\.(?:m?js|ts)|cursor-session-start\.js|workit-(?:codex|cursor)-hook|workit-cursor-session-start)(?:\.(?:cmd|ps1|exe))?$/iu;
|
|
23780
|
+
var PACKAGE_ENTRIES = {
|
|
23781
|
+
"claude-code": /^(?:bin\/workit-hook\.mjs|src\/(?:run|hook)\.ts|dist\/workit-hook\.js)$/u,
|
|
23782
|
+
codex: /^(?:hooks\/(?:launcher|workit-hook)\.ts|dist\/workit-hook(?:-[\w-]+)?\.js)$/u,
|
|
23783
|
+
cursor: /^(?:hooks\/(?:launch|launch-runtime)\.mjs|hooks\/(?:workit-hook|session-start|subagent-start)\.ts|dist\/(?:workit-hook|cursor-session-start)\.js)$/u,
|
|
23784
|
+
core: /^src\/hooks\/run\.ts$/u
|
|
23785
|
+
};
|
|
23786
|
+
var RUNNERS = new Set([
|
|
23787
|
+
"node",
|
|
23788
|
+
"nodejs",
|
|
23789
|
+
"bun",
|
|
23790
|
+
"deno",
|
|
23791
|
+
"tsx",
|
|
23792
|
+
"ts-node",
|
|
23793
|
+
"sh",
|
|
23794
|
+
"bash",
|
|
23795
|
+
"zsh",
|
|
23796
|
+
"dash",
|
|
23797
|
+
"ksh",
|
|
23798
|
+
"fish",
|
|
23799
|
+
"source",
|
|
23800
|
+
"."
|
|
23801
|
+
]);
|
|
23802
|
+
var PACKAGE_RUNNERS2 = new Set(["npx", "bunx", "pnpx"]);
|
|
23803
|
+
var NO_RUN = new Set([
|
|
23804
|
+
"build",
|
|
23805
|
+
"test",
|
|
23806
|
+
"fmt",
|
|
23807
|
+
"lint",
|
|
23808
|
+
"check",
|
|
23809
|
+
"doc",
|
|
23810
|
+
"info",
|
|
23811
|
+
"install",
|
|
23812
|
+
"add",
|
|
23813
|
+
"pm"
|
|
23814
|
+
]);
|
|
23815
|
+
var MORE_WRAPPERS = new Set(["strace", "ltrace", "watch", "unshare", "firejail", "xargs", "&"]);
|
|
23816
|
+
var baseName3 = (word) => (word.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "").toLowerCase();
|
|
23817
|
+
var packageAt = (dir) => {
|
|
23818
|
+
try {
|
|
23819
|
+
const name = JSON.parse(readFileSync11(path41.join(dir, "package.json"), "utf8")).name;
|
|
23820
|
+
const short = /^@workit-dev\/(claude-code|codex|cursor|core)$/u.exec(String(name))?.[1];
|
|
23821
|
+
if (short)
|
|
23822
|
+
return short;
|
|
23823
|
+
} catch {}
|
|
23824
|
+
for (const [manifest, short] of [
|
|
23825
|
+
[".claude-plugin", "claude-code"],
|
|
23826
|
+
[".codex-plugin", "codex"],
|
|
23827
|
+
[".cursor-plugin", "cursor"]
|
|
23828
|
+
]) {
|
|
23829
|
+
try {
|
|
23830
|
+
const name = JSON.parse(readFileSync11(path41.join(dir, manifest, "plugin.json"), "utf8")).name;
|
|
23831
|
+
if (name === "workit")
|
|
23832
|
+
return short;
|
|
23833
|
+
} catch {}
|
|
23834
|
+
}
|
|
23835
|
+
return null;
|
|
23836
|
+
};
|
|
23837
|
+
var entryByPath = (file) => {
|
|
23838
|
+
let dir = path41.dirname(file);
|
|
23839
|
+
for (let depth = 0;depth < 4; depth += 1, dir = path41.dirname(dir)) {
|
|
23840
|
+
const short = packageAt(dir);
|
|
23841
|
+
if (short)
|
|
23842
|
+
return PACKAGE_ENTRIES[short]?.test(path41.relative(dir, file).split(path41.sep).join("/")) ?? false;
|
|
23843
|
+
if (existsSync14(path41.join(dir, "package.json")))
|
|
23844
|
+
return false;
|
|
23845
|
+
}
|
|
23846
|
+
return false;
|
|
23847
|
+
};
|
|
23848
|
+
var literalSub = (match, inner) => {
|
|
23849
|
+
try {
|
|
23850
|
+
const [only, ...rest] = segmentsOf(inner);
|
|
23851
|
+
const [verb = "", ...args] = only?.words ?? [];
|
|
23852
|
+
const last = args.findLast((arg) => !arg.startsWith("-"));
|
|
23853
|
+
return rest.length === 0 && /^(?:echo|printf|ls|realpath|readlink)$/u.test(baseName3(verb)) && last ? last : match;
|
|
23854
|
+
} catch {
|
|
23855
|
+
return match;
|
|
23856
|
+
}
|
|
23857
|
+
};
|
|
23858
|
+
var expand = (word, vars) => word.replace(/\$\(([^()]*)\)|`([^`]*)`/gu, (match, sub, tick) => literalSub(match, sub ?? tick ?? "")).replace(/\$\{(\w+)\}|\$(\w+)/gu, (match, braced, bare) => {
|
|
23859
|
+
const name = braced ?? bare ?? "";
|
|
23860
|
+
return vars.get(name) ?? process.env[name] ?? match;
|
|
23861
|
+
}).replace(/^~(?=[\\/]|$)/u, userHome2(process.env));
|
|
23862
|
+
var entryNamed = (word, scan) => {
|
|
23863
|
+
if (!word)
|
|
23864
|
+
return null;
|
|
23865
|
+
const text = expand(word, scan.vars);
|
|
23866
|
+
if (ENTRY_NAMES.test(baseName3(text)))
|
|
23867
|
+
return text;
|
|
23868
|
+
const fd = /^\/(?:dev|proc\/self)\/fd\/(\d+)$/u.exec(text)?.[1];
|
|
23869
|
+
if (fd !== undefined && scan.fds.has(fd))
|
|
23870
|
+
return text;
|
|
23871
|
+
if (scan.dir === null && !path41.isAbsolute(text))
|
|
23872
|
+
return null;
|
|
23873
|
+
for (const file of expandGlob(path41.resolve(scan.dir ?? "/", text))) {
|
|
23874
|
+
if (scan.links.has(file) || entryByPath(file))
|
|
23875
|
+
return text;
|
|
23876
|
+
let real;
|
|
23877
|
+
try {
|
|
23878
|
+
real = realpathSync10(file);
|
|
23879
|
+
} catch {
|
|
23880
|
+
continue;
|
|
23881
|
+
}
|
|
23882
|
+
if (ENTRY_NAMES.test(baseName3(real)) || entryByPath(real))
|
|
23883
|
+
return text;
|
|
23884
|
+
}
|
|
23885
|
+
return null;
|
|
23886
|
+
};
|
|
23887
|
+
var noteLink = (words, scan) => {
|
|
23888
|
+
if (!/^(?:ln|cp|install)$/u.test(baseName3(words[0] ?? "")) || scan.dir === null)
|
|
23889
|
+
return;
|
|
23890
|
+
const names = words.slice(1).filter((word) => !word.startsWith("-"));
|
|
23891
|
+
const dest = names.at(-1);
|
|
23892
|
+
if (dest === undefined || names.length < 2)
|
|
23893
|
+
return;
|
|
23894
|
+
for (const source of names.slice(0, -1).filter((name) => entryNamed(name, scan))) {
|
|
23895
|
+
const to = path41.resolve(scan.dir, expand(dest, scan.vars));
|
|
23896
|
+
scan.links.add(to);
|
|
23897
|
+
scan.links.add(path41.join(to, path41.basename(source)));
|
|
23898
|
+
}
|
|
23899
|
+
};
|
|
23900
|
+
var runsEntry = (words, inputs, scan) => {
|
|
23901
|
+
const named = (word) => entryNamed(word, scan);
|
|
23902
|
+
let at = 0;
|
|
23903
|
+
while (at < words.length) {
|
|
23904
|
+
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
23905
|
+
at += 1;
|
|
23906
|
+
const word = words[at];
|
|
23907
|
+
if (word === undefined)
|
|
23908
|
+
return null;
|
|
23909
|
+
const entry = named(word);
|
|
23910
|
+
if (entry)
|
|
23911
|
+
return entry;
|
|
23912
|
+
const name = baseName3(word);
|
|
23913
|
+
const split = name === "env" ? words.findIndex((w) => /^(?:-\w*S|--split-string)/u.test(w)) : -1;
|
|
23914
|
+
if (split > at) {
|
|
23915
|
+
const line = /^(?:-\w*S|--split-string=?)(.*)$/su.exec(words[split] ?? "")?.[1] || words[split + 1];
|
|
23916
|
+
const rest = words.slice(split + (line === words[split + 1] ? 2 : 1));
|
|
23917
|
+
return runsEntry([...(line ?? "").split(/\s+/u).filter(Boolean), ...rest], inputs, scan);
|
|
23918
|
+
}
|
|
23919
|
+
if (MORE_WRAPPERS.has(name)) {
|
|
23920
|
+
at = pastOptions(words, at + 1, "");
|
|
23921
|
+
continue;
|
|
23922
|
+
}
|
|
23923
|
+
const takes = WRAPPERS3[name];
|
|
23924
|
+
if (takes !== undefined && !PACKAGE_RUNNERS2.has(name)) {
|
|
23925
|
+
at = pastOptions(words, at + 1, takes, name === "env" || name === "sudo");
|
|
23926
|
+
continue;
|
|
23927
|
+
}
|
|
23928
|
+
if (name === "busybox" || name === "toybox") {
|
|
23929
|
+
at += 1;
|
|
23930
|
+
continue;
|
|
23931
|
+
}
|
|
23932
|
+
const runner = PACKAGE_RUNNERS2.has(name) || name === "bun" && words[at + 1] === "x" || /^(?:pnpm|yarn|npm)$/u.test(name) && /^(?:dlx|exec|x)$/u.test(words[at + 1] ?? "");
|
|
23933
|
+
if (runner) {
|
|
23934
|
+
at += PACKAGE_RUNNERS2.has(name) ? 1 : 2;
|
|
23935
|
+
while (words[at]?.startsWith("-"))
|
|
23936
|
+
at += /^(?:-p|--package|-c|--call)$/u.test(words[at] ?? "") ? 2 : 1;
|
|
23937
|
+
if (/^@workit-dev\/(?:claude-code|codex|cursor)(?:@|$)/u.test(words[at] ?? ""))
|
|
23938
|
+
return words[at] ?? null;
|
|
23939
|
+
continue;
|
|
23940
|
+
}
|
|
23941
|
+
if (!RUNNERS.has(name))
|
|
23942
|
+
return null;
|
|
23943
|
+
if ((name === "bun" || name === "deno") && NO_RUN.has(words[at + 1] ?? ""))
|
|
23944
|
+
return null;
|
|
23945
|
+
for (const arg of [...words.slice(at + 1), ...inputs]) {
|
|
23946
|
+
const hit = named(arg);
|
|
23947
|
+
if (hit)
|
|
23948
|
+
return hit;
|
|
23949
|
+
}
|
|
23950
|
+
return null;
|
|
23951
|
+
}
|
|
23952
|
+
return null;
|
|
23953
|
+
};
|
|
23954
|
+
var KEYWORDS3 = new Set([
|
|
23955
|
+
"{",
|
|
23956
|
+
"}",
|
|
23957
|
+
"if",
|
|
23958
|
+
"then",
|
|
23959
|
+
"elif",
|
|
23960
|
+
"else",
|
|
23961
|
+
"fi",
|
|
23962
|
+
"while",
|
|
23963
|
+
"until",
|
|
23964
|
+
"do",
|
|
23965
|
+
"done",
|
|
23966
|
+
"esac",
|
|
23967
|
+
"!"
|
|
23968
|
+
]);
|
|
23969
|
+
var pastKeywords = (words) => {
|
|
23970
|
+
let at = 0;
|
|
23971
|
+
for (;; ) {
|
|
23972
|
+
if (words[at] === "function")
|
|
23973
|
+
at += 2;
|
|
23974
|
+
else if (KEYWORDS3.has(words[at] ?? ""))
|
|
23975
|
+
at += 1;
|
|
23976
|
+
else
|
|
23977
|
+
break;
|
|
23978
|
+
}
|
|
23979
|
+
return /^(?:for|case|select)$/u.test(words[at] ?? "") ? [] : words.slice(at);
|
|
23980
|
+
};
|
|
23981
|
+
var READERS2 = new Set(("cat less more head tail ls dir stat file wc grep egrep fgrep rg ag diff cmp sha256sum md5sum " + "shasum du bat echo printf cp mv rm chmod touch mkdir realpath readlink dirname basename tee " + "oxfmt oxlint prettier eslint tsc gh jq sort uniq cut tr nl od xxd hexdump strings code vim " + "nano sed get-content gc type select-string get-childitem test-path").split(" "));
|
|
23982
|
+
var TOKENS2 = /[\s'"`(),[\]{};|&<>=!]+/u;
|
|
23983
|
+
var ENTRY_SAMPLES = [
|
|
23984
|
+
"workit-hook.mjs",
|
|
23985
|
+
"workit-hook.js",
|
|
23986
|
+
"workit-hook.ts",
|
|
23987
|
+
"cursor-session-start.js"
|
|
23988
|
+
];
|
|
23989
|
+
var tokenEntry = (token, scan) => {
|
|
23990
|
+
if (!/[\\/]/u.test(token) && !existsSync14(path41.resolve(scan.dir ?? "/", token)))
|
|
23991
|
+
return null;
|
|
23992
|
+
return entryNamed(token, scan);
|
|
23993
|
+
};
|
|
23994
|
+
var opaqueEntry = (words, inputs, scan) => {
|
|
23995
|
+
let at = 0;
|
|
23996
|
+
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
23997
|
+
at += 1;
|
|
23998
|
+
const head = baseName3(words[at] ?? "");
|
|
23999
|
+
if (READERS2.has(head))
|
|
24000
|
+
return null;
|
|
24001
|
+
if ((head === "bun" || head === "deno") && NO_RUN.has(words[at + 1] ?? ""))
|
|
24002
|
+
return null;
|
|
24003
|
+
if (head === "git" && !words.some((word) => word.includes("alias.")))
|
|
24004
|
+
return null;
|
|
24005
|
+
if (head === "workit" || head === "workit-cli")
|
|
24006
|
+
return null;
|
|
24007
|
+
const tokens = words.flatMap((word) => word.split(TOKENS2)).filter(Boolean);
|
|
24008
|
+
const runner = (token) => RUNNERS.has(baseName3(token)) && !/^(?:\.|source)$/u.test(token) || PACKAGE_RUNNERS2.has(baseName3(token));
|
|
24009
|
+
if (!tokens.some(runner))
|
|
24010
|
+
return null;
|
|
24011
|
+
if (scan.fed)
|
|
24012
|
+
return scan.fed;
|
|
24013
|
+
for (const token of tokens) {
|
|
24014
|
+
const hit = tokenEntry(token, scan);
|
|
24015
|
+
if (hit)
|
|
24016
|
+
return hit;
|
|
24017
|
+
}
|
|
24018
|
+
if (head === "find")
|
|
24019
|
+
for (const [index, word] of words.entries()) {
|
|
24020
|
+
const named = /^-i?name$/u.test(words[index - 1] ?? "") && /^[^*?[]/u.test(word);
|
|
24021
|
+
const pattern = named ? globPattern(word) : null;
|
|
24022
|
+
if (pattern && ENTRY_SAMPLES.some((sample) => pattern.test(sample)))
|
|
24023
|
+
return word;
|
|
24024
|
+
}
|
|
24025
|
+
if (/^(?:xargs|parallel)$/u.test(head) || tokens.includes("xargs"))
|
|
24026
|
+
for (const input of inputs) {
|
|
24027
|
+
try {
|
|
24028
|
+
const file = path41.resolve(scan.dir ?? "/", expand(input, scan.vars));
|
|
24029
|
+
const text = readFileSync11(file, "utf8").slice(0, 65536);
|
|
24030
|
+
for (const token of text.split(/\s+/u).filter(Boolean)) {
|
|
24031
|
+
const hit = tokenEntry(token, scan);
|
|
24032
|
+
if (hit)
|
|
24033
|
+
return hit;
|
|
24034
|
+
}
|
|
24035
|
+
} catch {}
|
|
24036
|
+
}
|
|
24037
|
+
return null;
|
|
24038
|
+
};
|
|
24039
|
+
var expandedCommand = (words, scan) => {
|
|
24040
|
+
let at = 0;
|
|
24041
|
+
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
24042
|
+
at += 1;
|
|
24043
|
+
if (!/[$`]/u.test(words[at] ?? ""))
|
|
24044
|
+
return null;
|
|
24045
|
+
for (const word of words.slice(at + 1)) {
|
|
24046
|
+
const hit = entryNamed(word, scan);
|
|
24047
|
+
if (hit)
|
|
24048
|
+
return hit;
|
|
24049
|
+
}
|
|
24050
|
+
return null;
|
|
24051
|
+
};
|
|
24052
|
+
var optionsEntry = (words, scan) => {
|
|
24053
|
+
for (const word of words) {
|
|
24054
|
+
const value = /^(?:NODE_OPTIONS|BUN_OPTIONS)=(.*)$/su.exec(word)?.[1];
|
|
24055
|
+
if (value === undefined)
|
|
24056
|
+
continue;
|
|
24057
|
+
for (const token of value.split(TOKENS2).filter(Boolean)) {
|
|
24058
|
+
const hit = tokenEntry(token, scan);
|
|
24059
|
+
if (hit)
|
|
24060
|
+
return hit;
|
|
24061
|
+
}
|
|
24062
|
+
}
|
|
24063
|
+
return null;
|
|
24064
|
+
};
|
|
24065
|
+
var scanCommand = (command, dialect, scan) => {
|
|
24066
|
+
let segments;
|
|
24067
|
+
try {
|
|
24068
|
+
segments = segmentsOf(command, dialect);
|
|
24069
|
+
} catch {
|
|
24070
|
+
return null;
|
|
24071
|
+
}
|
|
24072
|
+
for (const [index, segment] of segments.entries()) {
|
|
24073
|
+
if (segment.unanalyzable)
|
|
24074
|
+
continue;
|
|
24075
|
+
bindLoop(segment.words, segments.slice(index + 1), scan);
|
|
24076
|
+
const words = pastKeywords(segment.words);
|
|
24077
|
+
const fed = scan.fed;
|
|
24078
|
+
scan.fed = null;
|
|
24079
|
+
const hit = segmentEntry(segment, words, dialect, scan, fed);
|
|
24080
|
+
if (hit)
|
|
24081
|
+
return hit;
|
|
24082
|
+
}
|
|
24083
|
+
return null;
|
|
24084
|
+
};
|
|
24085
|
+
var bindLoop = (raw, after, scan) => {
|
|
24086
|
+
const at = raw.findIndex((word) => !KEYWORDS3.has(word));
|
|
24087
|
+
const verb = raw[at];
|
|
24088
|
+
if ((verb === "for" || verb === "select") && raw[at + 2] === "in") {
|
|
24089
|
+
const name = raw[at + 1] ?? "";
|
|
24090
|
+
const items = raw.slice(at + 3);
|
|
24091
|
+
const item = items.find((word) => entryNamed(word, scan)) ?? items[0];
|
|
24092
|
+
if (/^[A-Za-z_]\w*$/u.test(name) && item !== undefined)
|
|
24093
|
+
scan.vars.set(name, expand(item, scan.vars));
|
|
24094
|
+
return;
|
|
24095
|
+
}
|
|
24096
|
+
const read = raw.indexOf("read");
|
|
24097
|
+
if (read < 0 || !raw.slice(0, read).some((word) => word === "while" || word === "until"))
|
|
24098
|
+
return;
|
|
24099
|
+
const fed = after.find((segment) => segment.words[0] === "done")?.stdin?.[0];
|
|
24100
|
+
const line = fed?.split(`
|
|
24101
|
+
`)[0]?.trim();
|
|
24102
|
+
const name = raw.slice(read + 1).find((word) => /^[A-Za-z_]\w*$/u.test(word));
|
|
24103
|
+
if (name && line)
|
|
24104
|
+
scan.vars.set(name, line);
|
|
24105
|
+
};
|
|
24106
|
+
var segmentEntry = (segment, words, dialect, scan, fed) => {
|
|
24107
|
+
const verb = baseName3(words[0] ?? "");
|
|
24108
|
+
if (["cd", "pushd", "chdir", "set-location", "sl"].includes(verb)) {
|
|
24109
|
+
const target = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
|
|
24110
|
+
const moved = target === undefined ? userHome2(process.env) : expand(target, scan.vars);
|
|
24111
|
+
scan.dir = moved === "-" || /[$`]/u.test(moved) ? null : path41.isAbsolute(moved) ? moved : scan.dir && path41.resolve(scan.dir, moved);
|
|
24112
|
+
if (scan.dir === null)
|
|
24113
|
+
scan.vars.delete("PWD");
|
|
24114
|
+
else
|
|
24115
|
+
scan.vars.set("PWD", scan.dir);
|
|
24116
|
+
return null;
|
|
24117
|
+
}
|
|
24118
|
+
if (verb === "popd") {
|
|
24119
|
+
scan.dir = null;
|
|
24120
|
+
return null;
|
|
24121
|
+
}
|
|
24122
|
+
const declares = ["export", "declare", "typeset", "local", "readonly"].includes(verb);
|
|
24123
|
+
const assigns = declares ? words.slice(1) : words.every((word) => /^[A-Za-z_]\w*=/u.test(word)) ? words : [];
|
|
24124
|
+
for (const word of assigns) {
|
|
24125
|
+
const [name = "", value] = word.split(/=(.*)/su);
|
|
24126
|
+
if (value !== undefined && /^[A-Za-z_]\w*$/u.test(name))
|
|
24127
|
+
scan.vars.set(name, expand(value.replace(/^(['"])(.*)\1$/su, "$2"), scan.vars));
|
|
24128
|
+
}
|
|
24129
|
+
const options = optionsEntry(declares ? words.slice(1) : words, scan);
|
|
24130
|
+
if (options)
|
|
24131
|
+
return options;
|
|
24132
|
+
if (verb === "exec" && words.slice(1).every((word) => /^\d+$/u.test(word))) {
|
|
24133
|
+
for (const input of segment.inputs ?? [])
|
|
24134
|
+
if (entryNamed(input, scan))
|
|
24135
|
+
for (const fd of words.slice(1))
|
|
24136
|
+
scan.fds.add(fd);
|
|
24137
|
+
}
|
|
24138
|
+
const inputs = segment.inputs ?? [];
|
|
24139
|
+
const entry = runsEntry(words, inputs, scan) ?? expandedCommand(words, scan) ?? opaqueEntry(words, inputs, { ...scan, fed });
|
|
24140
|
+
if (entry)
|
|
24141
|
+
return entry;
|
|
24142
|
+
if (segment.pipe)
|
|
24143
|
+
scan.fed = words.slice(1).flatMap((word) => word.split(TOKENS2)).map((token) => token ? tokenEntry(token, scan) : null).find(Boolean) ?? null;
|
|
24144
|
+
noteLink(words, scan);
|
|
24145
|
+
if (scan.depth >= 4)
|
|
24146
|
+
return null;
|
|
24147
|
+
const nested = (script) => scanCommand(script, dialect, {
|
|
24148
|
+
...scan,
|
|
24149
|
+
vars: new Map(scan.vars),
|
|
24150
|
+
fed: null,
|
|
24151
|
+
depth: scan.depth + 1
|
|
24152
|
+
});
|
|
24153
|
+
const scripts = [...segment.subs ?? []];
|
|
24154
|
+
const script = shellScript2(words) ?? cmdScript2(words) ?? workitScript(words);
|
|
24155
|
+
if (script)
|
|
24156
|
+
scripts.push(script);
|
|
24157
|
+
if (!script && /^(?:ba|z|da|k)?sh$/u.test(verb) && words.slice(1).every((word) => word.startsWith("-")) || verb === "at" || verb === "batch")
|
|
24158
|
+
scripts.push(...segment.stdin ?? []);
|
|
24159
|
+
for (const text of scripts) {
|
|
24160
|
+
const hit = nested(text);
|
|
24161
|
+
if (hit)
|
|
24162
|
+
return hit;
|
|
24163
|
+
}
|
|
24164
|
+
return null;
|
|
24165
|
+
};
|
|
24166
|
+
var cmdScript2 = (words) => {
|
|
24167
|
+
const name = baseName3(words[0] ?? "");
|
|
24168
|
+
if (!/^(?:cmd|pwsh|powershell)$/u.test(name))
|
|
24169
|
+
return null;
|
|
24170
|
+
const flag = words.findIndex((word, at) => at > 0 && /^[/-](?:c|k|command)$/iu.test(word));
|
|
24171
|
+
return flag < 0 ? null : words.slice(flag + 1).join(" ").replaceAll("\\", "/") || null;
|
|
24172
|
+
};
|
|
24173
|
+
var workitScript = (words) => {
|
|
24174
|
+
if (!/^workit(?:-cli)?$/u.test(baseName3(words[0] ?? "")))
|
|
24175
|
+
return null;
|
|
24176
|
+
const dash = words.indexOf("--");
|
|
24177
|
+
return dash < 0 ? null : words.slice(dash + 1).join(" ") || null;
|
|
24178
|
+
};
|
|
24179
|
+
var substitutions2 = (command) => {
|
|
24180
|
+
const found = [];
|
|
24181
|
+
for (let at = command.indexOf("$(");at >= 0 && found.length < 32; at = command.indexOf("$(", at + 1)) {
|
|
24182
|
+
if (command[at + 2] === "(")
|
|
24183
|
+
continue;
|
|
24184
|
+
let depth = 1;
|
|
24185
|
+
let end = at + 2;
|
|
24186
|
+
for (;end < command.length && depth > 0; end += 1)
|
|
24187
|
+
if (command[end] === "(")
|
|
24188
|
+
depth += 1;
|
|
24189
|
+
else if (command[end] === ")")
|
|
24190
|
+
depth -= 1;
|
|
24191
|
+
found.push(command.slice(at + 2, end - 1));
|
|
24192
|
+
}
|
|
24193
|
+
return found;
|
|
24194
|
+
};
|
|
24195
|
+
var hookEntryRun = (cwd, command, dialect = "posix") => {
|
|
24196
|
+
const scan = (text) => scanCommand(text, dialect, {
|
|
24197
|
+
dir: cwd,
|
|
24198
|
+
vars: new Map([["PWD", cwd]]),
|
|
24199
|
+
links: new Set,
|
|
24200
|
+
fds: new Set,
|
|
24201
|
+
fed: null,
|
|
24202
|
+
depth: 0
|
|
24203
|
+
});
|
|
24204
|
+
const texts = dialect === "posix" && /[A-Za-z]:\\/u.test(command) ? [command, command.replaceAll("\\", "/")] : [command];
|
|
24205
|
+
for (const text of texts) {
|
|
24206
|
+
const hit = scan(text) ?? substitutions2(text).map(scan).find(Boolean);
|
|
24207
|
+
if (hit)
|
|
24208
|
+
return hit;
|
|
24209
|
+
}
|
|
24210
|
+
return null;
|
|
24211
|
+
};
|
|
24212
|
+
var hookEntryDeny = (entry) => `workit hook guard: this command runs Workit's hook entry ${entry}. Only the host runs Workit's hooks, with the payload it builds; a payload written in a shell would act as a session, subagent or agent that never existed. Use the workit CLI for what you need (\`workit doctor\` probes the installed hooks).`;
|
|
24213
|
+
|
|
23560
24214
|
// packages/workit-core/src/hooks/identity-env.ts
|
|
24215
|
+
import fs27 from "node:fs";
|
|
24216
|
+
import path42 from "node:path";
|
|
23561
24217
|
var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
|
|
23562
|
-
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
23563
24218
|
var IDENTITY = new RegExp(`^${NAMES}$`, "u");
|
|
24219
|
+
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
23564
24220
|
var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
|
|
23565
|
-
var
|
|
24221
|
+
var IDENTITY_ANY = new RegExp(NAMES, "iu");
|
|
24222
|
+
var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
|
|
24223
|
+
var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
|
|
24224
|
+
var STATE_ANY = new RegExp(STATE_NAMES, "iu");
|
|
24225
|
+
var powershell = (names) => new RegExp([
|
|
24226
|
+
`\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
|
|
24227
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
|
|
24228
|
+
`SetEnvironmentVariable\\(\\s*['"]${names}\\b`
|
|
24229
|
+
].join("|"), "iu");
|
|
24230
|
+
var PS_ITEM = "\\b(?:(?:Set|New|Remove|Clear|Rename|Move|Copy)-Item(?:Property)?|(?:Set|Add|Clear)-Content|si|ni|ri|rm|del|erase|rd|rmdir|cli|sc|ac|clc|rni|mi|move|mv|cpi|copy|cp|ren)\\b";
|
|
23566
24231
|
var POWERSHELL = powershell(NAMES);
|
|
24232
|
+
var POWERSHELL_STATE = powershell(STATE_NAMES);
|
|
23567
24233
|
var POWERSHELL_HOST = powershell(HOST_NAMES);
|
|
24234
|
+
var POWERSHELL_OPAQUE = new RegExp([
|
|
24235
|
+
`SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
|
|
24236
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
|
|
24237
|
+
`(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
|
|
24238
|
+
`\\b(?:iex|Invoke-Expression)\\b`
|
|
24239
|
+
].join("|"), "iu");
|
|
24240
|
+
var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
|
|
24241
|
+
var CMD_IDENTITY = cmdSet(NAMES);
|
|
24242
|
+
var CMD_STATE = cmdSet(STATE_NAMES);
|
|
24243
|
+
var CMD_HOST = cmdSet(HOST_NAMES);
|
|
24244
|
+
var RUNS_TEXT = /\bworkit(?:-cli)?\b|@workit-dev[\\/]cli/iu;
|
|
23568
24245
|
var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
|
|
23569
24246
|
var OPAQUE = new Set([
|
|
23570
24247
|
"watch",
|
|
@@ -23582,22 +24259,41 @@ var ENV_FLAGS = new Set(["i", "0", "v"]);
|
|
|
23582
24259
|
var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
|
|
23583
24260
|
var ENV_LONG_FLAGS = /^--(?:ignore-environment|null|debug|(?:block|default|ignore)-signal(?:=.*)?)$/u;
|
|
23584
24261
|
var base2 = (word) => (word?.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "");
|
|
23585
|
-
var
|
|
23586
|
-
var
|
|
23587
|
-
var
|
|
24262
|
+
var ASSIGN = /^[A-Za-z_]\w*\+?=/u;
|
|
24263
|
+
var nameOf = (word) => (word?.split("=")[0] ?? "").replace(/\+$/u, "");
|
|
24264
|
+
var named = (word) => IDENTITY.test(nameOf(word));
|
|
24265
|
+
var stateNamed = (word) => STATE2.test(nameOf(word));
|
|
24266
|
+
var isWorkit = (word) => /^workit(?:-cli)?(?:\.[cm]?js)?$/u.test(base2(word)) || /@workit-dev[\\/]cli\b|workit-cli[\\/](?:dist|src)[\\/]/u.test(word ?? "");
|
|
24267
|
+
var linksToWorkit = (word, cwd) => {
|
|
24268
|
+
const places = /[\\/]/u.test(word) ? [path42.resolve(cwd ?? process.cwd(), word)] : (process.env.PATH ?? "").split(path42.delimiter).map((dir) => path42.join(dir, word));
|
|
24269
|
+
for (const place of places) {
|
|
24270
|
+
try {
|
|
24271
|
+
const real = fs27.realpathSync(place);
|
|
24272
|
+
return isWorkit(real);
|
|
24273
|
+
} catch {}
|
|
24274
|
+
}
|
|
24275
|
+
return false;
|
|
24276
|
+
};
|
|
24277
|
+
var newSeg = () => ({ identity: null, scoped: null, runs: false, words: [] });
|
|
23588
24278
|
var UNREADABLE = "env/unset arguments Workit cannot read";
|
|
23589
|
-
var
|
|
23590
|
-
|
|
23591
|
-
|
|
23592
|
-
|
|
23593
|
-
|
|
23594
|
-
|
|
23595
|
-
}
|
|
23596
|
-
|
|
24279
|
+
var note = (scan, seg, word) => {
|
|
24280
|
+
if (scan.identity && named(word)) {
|
|
24281
|
+
if (seg)
|
|
24282
|
+
seg.identity ??= nameOf(word);
|
|
24283
|
+
else
|
|
24284
|
+
scan.hit ??= nameOf(word);
|
|
24285
|
+
}
|
|
24286
|
+
if (!stateNamed(word) && !(scan.identity && HOST_VARIABLE.test(nameOf(word))))
|
|
24287
|
+
return;
|
|
24288
|
+
if (seg)
|
|
24289
|
+
seg.scoped ??= nameOf(word);
|
|
24290
|
+
else
|
|
24291
|
+
scan.shell ??= nameOf(word);
|
|
24292
|
+
};
|
|
24293
|
+
var mayBeWorkit = (words, cwd) => words.some(({ word, built }) => built || linksToWorkit(word, cwd));
|
|
24294
|
+
var scanEnv = (words, at, expands, scan, seg, depth) => {
|
|
23597
24295
|
const risky = (what) => void (scan.risky ??= what);
|
|
23598
|
-
const unset = (name) =>
|
|
23599
|
-
mark(scan, name);
|
|
23600
|
-
};
|
|
24296
|
+
const unset = (name) => note(scan, seg, name);
|
|
23601
24297
|
const split = (line, rest, built) => {
|
|
23602
24298
|
if (line === undefined || depth >= 4)
|
|
23603
24299
|
return risky(UNREADABLE);
|
|
@@ -23614,7 +24310,7 @@ var scanEnv = (words, at, expands, scan, depth) => {
|
|
|
23614
24310
|
} catch {
|
|
23615
24311
|
return risky(UNREADABLE);
|
|
23616
24312
|
}
|
|
23617
|
-
scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, depth + 1);
|
|
24313
|
+
scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, seg, depth + 1);
|
|
23618
24314
|
};
|
|
23619
24315
|
let options = true;
|
|
23620
24316
|
for (let index = at;index < words.length; index += 1) {
|
|
@@ -23672,25 +24368,25 @@ var scanEnv = (words, at, expands, scan, depth) => {
|
|
|
23672
24368
|
}
|
|
23673
24369
|
continue;
|
|
23674
24370
|
}
|
|
23675
|
-
if (
|
|
24371
|
+
if (ASSIGN.test(word)) {
|
|
23676
24372
|
unset(word);
|
|
23677
24373
|
continue;
|
|
23678
24374
|
}
|
|
23679
|
-
return commandAt(words.slice(index), scan);
|
|
24375
|
+
return commandAt(words.slice(index), scan, seg, new Set([...expands].filter((at2) => at2 >= index).map((at2) => at2 - index)));
|
|
23680
24376
|
}
|
|
23681
24377
|
};
|
|
23682
|
-
var commandAt = (words, scan, expands = new Set, from = 0) => {
|
|
24378
|
+
var commandAt = (words, scan, seg, expands = new Set, from = 0) => {
|
|
23683
24379
|
let index = from;
|
|
23684
24380
|
while (index < words.length) {
|
|
23685
|
-
while (
|
|
23686
|
-
|
|
24381
|
+
while (ASSIGN.test(words[index] ?? "")) {
|
|
24382
|
+
note(scan, seg, words[index]);
|
|
23687
24383
|
index += 1;
|
|
23688
24384
|
}
|
|
23689
24385
|
const name = base2(words[index]).toLowerCase();
|
|
23690
24386
|
if (name === "env")
|
|
23691
|
-
return scanEnv(words, index + 1, expands, scan, 0);
|
|
24387
|
+
return scanEnv(words, index + 1, expands, scan, seg, 0);
|
|
23692
24388
|
if (OPAQUE.has(name))
|
|
23693
|
-
return opaque(words.slice(index + 1), scan, true);
|
|
24389
|
+
return opaque(words.slice(index + 1), scan, seg, true);
|
|
23694
24390
|
if (name === "busybox" || name === "toybox") {
|
|
23695
24391
|
index += 1;
|
|
23696
24392
|
continue;
|
|
@@ -23700,21 +24396,37 @@ var commandAt = (words, scan, expands = new Set, from = 0) => {
|
|
|
23700
24396
|
break;
|
|
23701
24397
|
index = pastOptions(words, index + 1, takes);
|
|
23702
24398
|
}
|
|
23703
|
-
|
|
23704
|
-
|
|
23705
|
-
|
|
23706
|
-
|
|
23707
|
-
|
|
23708
|
-
|
|
24399
|
+
const word = words[index];
|
|
24400
|
+
if (word === undefined)
|
|
24401
|
+
return;
|
|
24402
|
+
seg.words.push({ word, built: expands.has(index) });
|
|
24403
|
+
const rest = words.slice(index + 1);
|
|
24404
|
+
if (isWorkit(word) || rest.some(isWorkit))
|
|
24405
|
+
seg.runs = true;
|
|
24406
|
+
if (!isWorkit(word) && rest.some((next) => base2(next).toLowerCase() === "env"))
|
|
24407
|
+
opaque(rest, scan, seg, false);
|
|
24408
|
+
const program = base2(word).toLowerCase();
|
|
24409
|
+
const shell = program === "pwsh" || program === "powershell";
|
|
24410
|
+
if (program === "cmd" || shell) {
|
|
24411
|
+
const at = rest.findIndex((next) => shell ? /^-(?:c|command)$/iu.test(next) : /^\/[ck]$/iu.test(next));
|
|
24412
|
+
if (at >= 0) {
|
|
24413
|
+
const script = rest.slice(at + 1).join(" ");
|
|
24414
|
+
const change = shell ? powershellChange(script, scan.identity) : cmdChange(script, scan);
|
|
24415
|
+
if (change)
|
|
24416
|
+
scan.hit ??= change;
|
|
24417
|
+
}
|
|
24418
|
+
}
|
|
24419
|
+
};
|
|
24420
|
+
var opaque = (rest, scan, seg, assigns) => {
|
|
23709
24421
|
if (!rest.some(isWorkit))
|
|
23710
24422
|
return;
|
|
23711
|
-
|
|
23712
|
-
const changes = (word) => base2(word).toLowerCase() === "env" || DECLARES.has(word) || assigns &&
|
|
24423
|
+
seg.runs = true;
|
|
24424
|
+
const changes = (word) => base2(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && ASSIGN.test(word);
|
|
23713
24425
|
if (rest.some(changes))
|
|
23714
24426
|
scan.risky ??= UNREADABLE;
|
|
23715
|
-
|
|
23716
|
-
|
|
23717
|
-
|
|
24427
|
+
if (rest.some((word) => base2(word).toLowerCase() === "env"))
|
|
24428
|
+
for (const word of rest)
|
|
24429
|
+
note(scan, seg, word);
|
|
23718
24430
|
};
|
|
23719
24431
|
var LOGIN_VALUED = {
|
|
23720
24432
|
su: /[sgGwc]/u,
|
|
@@ -23740,7 +24452,7 @@ var loginScript = (words) => {
|
|
|
23740
24452
|
}
|
|
23741
24453
|
return null;
|
|
23742
24454
|
};
|
|
23743
|
-
var
|
|
24455
|
+
var scanCommand2 = (command, dialect, depth, scan) => {
|
|
23744
24456
|
let segments;
|
|
23745
24457
|
try {
|
|
23746
24458
|
segments = segmentsOf(command, dialect);
|
|
@@ -23749,38 +24461,83 @@ var scanCommand = (command, dialect, depth, scan) => {
|
|
|
23749
24461
|
}
|
|
23750
24462
|
for (const { words, expands = [] } of segments) {
|
|
23751
24463
|
const expanded = new Set(expands);
|
|
24464
|
+
const seg = newSeg();
|
|
23752
24465
|
let at = 0;
|
|
23753
|
-
while (
|
|
23754
|
-
mark(scan, words[at]);
|
|
24466
|
+
while (ASSIGN.test(words[at] ?? ""))
|
|
23755
24467
|
at += 1;
|
|
23756
|
-
|
|
24468
|
+
for (const word of words.slice(0, at))
|
|
24469
|
+
note(scan, at === words.length ? null : seg, word);
|
|
23757
24470
|
let declare = at;
|
|
23758
24471
|
if (["builtin", "command"].includes(words[declare] ?? ""))
|
|
23759
24472
|
declare += 1;
|
|
23760
24473
|
if (DECLARES.has(words[declare] ?? "")) {
|
|
23761
24474
|
for (let index = declare + 1;index < words.length; index += 1) {
|
|
23762
|
-
|
|
24475
|
+
note(scan, null, words[index]);
|
|
23763
24476
|
if (expanded.has(index))
|
|
23764
24477
|
scan.risky ??= UNREADABLE;
|
|
23765
24478
|
}
|
|
23766
24479
|
continue;
|
|
23767
24480
|
}
|
|
23768
|
-
commandAt(words, scan, expanded, at);
|
|
24481
|
+
commandAt(words, scan, seg, expanded, at);
|
|
23769
24482
|
const script = depth < 4 ? shellScript2(words) ?? loginScript(words) : null;
|
|
23770
|
-
if (script)
|
|
23771
|
-
|
|
23772
|
-
|
|
23773
|
-
|
|
23774
|
-
|
|
23775
|
-
|
|
24483
|
+
if (script) {
|
|
24484
|
+
const before = scan.runs;
|
|
24485
|
+
scan.runs = false;
|
|
24486
|
+
scanCommand2(script, dialect, depth + 1, scan);
|
|
24487
|
+
seg.runs ||= scan.runs;
|
|
24488
|
+
scan.runs ||= before;
|
|
24489
|
+
}
|
|
24490
|
+
scan.words.push(...seg.words);
|
|
24491
|
+
const reaches = () => seg.runs || mayBeWorkit(seg.words, scan.cwd);
|
|
24492
|
+
if (seg.identity && reaches())
|
|
24493
|
+
scan.hit ??= seg.identity;
|
|
24494
|
+
if (seg.scoped && reaches())
|
|
24495
|
+
scan.state ??= seg.scoped;
|
|
24496
|
+
scan.runs ||= seg.runs;
|
|
24497
|
+
}
|
|
24498
|
+
};
|
|
24499
|
+
var cmdChange = (script, scan) => (scan.identity ? CMD_IDENTITY.exec(script)?.[1] : null) ?? (RUNS_TEXT.test(script) ? CMD_STATE.exec(script)?.[1] ?? (scan.identity ? CMD_HOST.exec(script)?.[1] : null) ?? null : null);
|
|
24500
|
+
var powershellChange = (command, identity) => {
|
|
24501
|
+
const hit = identity ? POWERSHELL.exec(command)?.[0] : null;
|
|
24502
|
+
if (hit)
|
|
24503
|
+
return hit;
|
|
24504
|
+
if (!RUNS_TEXT.test(command) && !/&\s*[$(]/u.test(command))
|
|
23776
24505
|
return null;
|
|
24506
|
+
const state = POWERSHELL_STATE.exec(command)?.[0] ?? (identity ? POWERSHELL_HOST.exec(command)?.[0] : null) ?? cmdChange(command, { identity });
|
|
24507
|
+
if (state)
|
|
24508
|
+
return state;
|
|
24509
|
+
return POWERSHELL_OPAQUE.test(command) ? UNREADABLE : null;
|
|
24510
|
+
};
|
|
24511
|
+
var identityEnvChange = (command, dialect = "posix", options = {}) => {
|
|
24512
|
+
const identity = options.identity ?? true;
|
|
23777
24513
|
if (dialect === "powershell")
|
|
23778
|
-
return
|
|
23779
|
-
|
|
23780
|
-
|
|
23781
|
-
|
|
24514
|
+
return powershellChange(command, identity);
|
|
24515
|
+
if (!/WORKIT_|XDG_|HOME|USERPROFILE|APPDATA|OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDE|EnvironmentVariable|\b(?:env|unset|export|declare|typeset|local|readonly)\b/iu.test(command))
|
|
24516
|
+
return null;
|
|
24517
|
+
const scan = {
|
|
24518
|
+
identity,
|
|
24519
|
+
cwd: options.cwd,
|
|
24520
|
+
hit: null,
|
|
24521
|
+
state: null,
|
|
24522
|
+
shell: null,
|
|
24523
|
+
risky: null,
|
|
24524
|
+
runs: false,
|
|
24525
|
+
words: []
|
|
24526
|
+
};
|
|
24527
|
+
scanCommand2(command, dialect, 0, scan);
|
|
24528
|
+
if (scan.hit)
|
|
24529
|
+
return scan.hit;
|
|
24530
|
+
if (scan.state)
|
|
24531
|
+
return scan.state;
|
|
24532
|
+
if (scan.shell && (scan.runs || mayBeWorkit(scan.words, scan.cwd)))
|
|
24533
|
+
return scan.shell;
|
|
24534
|
+
return scan.runs ? scan.risky : null;
|
|
24535
|
+
};
|
|
24536
|
+
var identityEnvDeny = (change) => {
|
|
24537
|
+
if (change === UNREADABLE || IDENTITY_ANY.test(change) || !STATE_ANY.test(change))
|
|
24538
|
+
return `workit identity: ${change === UNREADABLE ? `this command runs workit with ${UNREADABLE}` : `this command changes ${change}`}. The host sets WORKIT_HOST, WORKIT_SESSION_ID, WORKIT_AGENT_ID and its own session variables, and Workit acts as who they name; run it without changing them (a verifier or reviewer passes the --session and --token its start text names).`;
|
|
24539
|
+
return `workit identity: this command runs workit with ${change} changed. Workit reads issued sessions, grants and its ledger trust from the state and config dirs the host's environment names, so a workit call may not move them (#980); run it without setting, unsetting or emptying ${change}.`;
|
|
23782
24540
|
};
|
|
23783
|
-
var identityEnvDeny = (change) => `workit identity: ${change === UNREADABLE ? `this command runs workit with ${UNREADABLE}` : `this command changes ${change}`}. The host sets WORKIT_HOST, WORKIT_SESSION_ID, WORKIT_AGENT_ID and its own session variables, and Workit acts as who they name; run it without changing them (a verifier or reviewer passes the --session and --token its start text names).`;
|
|
23784
24541
|
|
|
23785
24542
|
// packages/workit-core/src/hooks/handle.ts
|
|
23786
24543
|
var usable2 = (value) => value === "native" || value === "partial";
|
|
@@ -23857,6 +24614,7 @@ function decide(input, deps) {
|
|
|
23857
24614
|
switch (event.kind) {
|
|
23858
24615
|
case "session.start": {
|
|
23859
24616
|
reapAtStart(input.cwd);
|
|
24617
|
+
pinIssuedRegistry(input.cwd);
|
|
23860
24618
|
if (!usable2(descriptor.context.sessionStart))
|
|
23861
24619
|
return NONE6;
|
|
23862
24620
|
const key = input.session.id ? `${input.host}\x00${input.session.id}` : null;
|
|
@@ -23973,11 +24731,17 @@ function decide(input, deps) {
|
|
|
23973
24731
|
const raw = canDeny ? rawGitPre(input, event.command, { nudge: false }) : NONE6;
|
|
23974
24732
|
if (raw.kind === "deny")
|
|
23975
24733
|
return raw;
|
|
24734
|
+
const entry = canDeny ? hookEntryRun(input.cwd, event.command, event.dialect) : null;
|
|
24735
|
+
if (entry)
|
|
24736
|
+
return { kind: "deny", reason: hookEntryDeny(entry), unblock: null };
|
|
23976
24737
|
const owner = role === "judge" ? null : liveOwner(input, descriptor.transport);
|
|
23977
24738
|
const gate = usable2(descriptor.events["write.pre"].support) ? shellGate(input.cwd, event.command, owner, event.dialect) : NONE6;
|
|
23978
24739
|
if (gate.kind === "deny")
|
|
23979
24740
|
return gate;
|
|
23980
|
-
const identity = canDeny
|
|
24741
|
+
const identity = canDeny ? identityEnvChange(event.command, event.dialect, {
|
|
24742
|
+
identity: stampsAgents(descriptor),
|
|
24743
|
+
cwd: input.cwd
|
|
24744
|
+
}) : null;
|
|
23981
24745
|
if (identity)
|
|
23982
24746
|
return { kind: "deny", reason: identityEnvDeny(identity), unblock: null };
|
|
23983
24747
|
const plan = heavyGate(input.cwd, event.command, {
|
|
@@ -24120,7 +24884,7 @@ var dispatchHook = (adapter, raw, env = process.env) => {
|
|
|
24120
24884
|
};
|
|
24121
24885
|
// packages/workit-core/src/hooks/deadline.ts
|
|
24122
24886
|
import { appendFileSync, mkdirSync as mkdirSync4 } from "node:fs";
|
|
24123
|
-
import
|
|
24887
|
+
import path43 from "node:path";
|
|
24124
24888
|
var HOOK_SKIP_TEXT = "workit context skipped: host under load";
|
|
24125
24889
|
var HOOK_DEADLINE_MS = 8000;
|
|
24126
24890
|
var HOST_DEADLINES = {
|
|
@@ -24138,7 +24902,7 @@ var hookDeadlineMs = (env, host = "", native) => {
|
|
|
24138
24902
|
const row = HOST_DEADLINES[host];
|
|
24139
24903
|
return override(env) ?? (row ? native === undefined ? Math.min(...Object.values(row)) : row[native] ?? row[""] : HOOK_DEADLINE_MS);
|
|
24140
24904
|
};
|
|
24141
|
-
var skipsFile = (stateDir) =>
|
|
24905
|
+
var skipsFile = (stateDir) => path43.join(stateDir, HOOK_SKIPS_FILE);
|
|
24142
24906
|
var recordHookSkip = (skip, stateDir = resolveStateDir()) => {
|
|
24143
24907
|
try {
|
|
24144
24908
|
mkdirSync4(stateDir, { recursive: true });
|
|
@@ -24190,7 +24954,7 @@ var readWithin = async (stdin, budget) => {
|
|
|
24190
24954
|
const text = await within2(read, budget.startedAt + budget.deadlineMs - budget.now());
|
|
24191
24955
|
return isTimedOut(text) ? null : text;
|
|
24192
24956
|
};
|
|
24193
|
-
var
|
|
24957
|
+
var note2 = (adapter, raw, env, budget, outcome, stage) => {
|
|
24194
24958
|
const parsed = raw === undefined ? null : adapter.parse(raw, env);
|
|
24195
24959
|
const event = parsed ? parsed.ok ? parsed.input.event.kind : parsed.event : null;
|
|
24196
24960
|
budget.record({
|
|
@@ -24204,7 +24968,7 @@ var note = (adapter, raw, env, budget, outcome, stage) => {
|
|
|
24204
24968
|
return { native: parsed?.native ?? null, event };
|
|
24205
24969
|
};
|
|
24206
24970
|
var skippedHook = (adapter, raw, env, budget, stage) => {
|
|
24207
|
-
const { native, event } =
|
|
24971
|
+
const { native, event } = note2(adapter, raw, env, budget, "skip", stage);
|
|
24208
24972
|
return {
|
|
24209
24973
|
...adapter.render(skipDecision(event), native),
|
|
24210
24974
|
error: `${HOOK_SKIP_TEXT} (past the ${budget.deadlineMs} ms hook deadline)`,
|
|
@@ -24220,7 +24984,7 @@ var dispatchWithin = async (adapter, raw, env, budget, dispatch = dispatchHook)
|
|
|
24220
24984
|
if (isTimedOut(result))
|
|
24221
24985
|
return skippedHook(adapter, raw, env, budget, "dispatch");
|
|
24222
24986
|
if (remaining() < 0)
|
|
24223
|
-
|
|
24987
|
+
note2(adapter, raw, env, budget, "late", "done");
|
|
24224
24988
|
return { ...result, skipped: false };
|
|
24225
24989
|
};
|
|
24226
24990
|
|