@workit-dev/pi 2.28.0 → 2.29.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/worker.js +185 -28
- package/dist/workit.js +1462 -1106
- package/package.json +1 -1
package/dist/workit.js
CHANGED
|
@@ -8474,7 +8474,7 @@ var workspaceConfigSchema = looseObject({
|
|
|
8474
8474
|
})),
|
|
8475
8475
|
models: optional(looseObject({ roles: modelRoles })),
|
|
8476
8476
|
resources: optional(unknown()),
|
|
8477
|
-
remotes: optional(array(nonBlank.check(refine((pattern) =>
|
|
8477
|
+
remotes: optional(array(nonBlank.check(refine((pattern) => isRemotePattern(pattern), "is not a remote URL (https://host/owner/repo, git@host:owner/repo, a path, or owner/*)")))),
|
|
8478
8478
|
externalRepos: optional(array(nonBlank.check(_regex(/^[\w-]+(?:\/\w[\w.-]*)*\/(?:\w[\w.-]*|\*)$/u, "is owner/name, group/project or owner/* on the checkout's forge host, without the host")))),
|
|
8479
8479
|
additiveRiskPaths: optional(array(nonBlank)),
|
|
8480
8480
|
autonomy: optional(looseObject(Object.fromEntries(["push", "pr", "merge", "release", "rerun"].map((kind) => [
|
|
@@ -8843,6 +8843,7 @@ var canonicalGlob = (glob) => {
|
|
|
8843
8843
|
return real + (prefix.endsWith("/") ? "/" : "") + rest;
|
|
8844
8844
|
};
|
|
8845
8845
|
var globSpecificity = (glob) => glob.replaceAll("\\", "/").split("/").filter((segment) => segment.length > 0 && !/[*?[\]{]/.test(segment)).length;
|
|
8846
|
+
var workspaceMatches = (cwd, entries) => matchingEntries(cwd, entries);
|
|
8846
8847
|
var selectWorkspaceMatch = (matches, cwd, workspaceName) => {
|
|
8847
8848
|
if (workspaceName !== undefined) {
|
|
8848
8849
|
const named = matches.filter((entry) => entry.name === workspaceName);
|
|
@@ -8864,15 +8865,32 @@ var selectWorkspaceMatch = (matches, cwd, workspaceName) => {
|
|
|
8864
8865
|
}
|
|
8865
8866
|
return mostSpecific[0];
|
|
8866
8867
|
};
|
|
8867
|
-
var
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
|
|
8868
|
+
var HOSTLESS_REMOTE = /^[\w-]+\/\*$/u;
|
|
8869
|
+
var expandRemotePattern = (entry, pattern) => {
|
|
8870
|
+
if (!HOSTLESS_REMOTE.test(pattern.trim()))
|
|
8871
|
+
return pattern;
|
|
8872
|
+
const vcs = entry.vcs ?? {};
|
|
8873
|
+
const host = typeof vcs.host === "string" && vcs.host.trim().replace(/^https?:\/\/|\/.*$/giu, "") || `${vcs.provider === "gitlab" ? "gitlab" : "github"}.com`;
|
|
8874
|
+
return `https://${host}/${pattern.trim()}`;
|
|
8875
|
+
};
|
|
8876
|
+
var isRemotePattern = (pattern) => !!remotePattern(expandRemotePattern({}, pattern));
|
|
8877
|
+
var remoteClaimOf = (entry, key, exact = false) => (Array.isArray(entry.remotes) ? entry.remotes : []).find((pattern) => typeof pattern === "string" && !(exact && pattern.trim().endsWith("/*")) && remoteMatches(expandRemotePattern(entry, pattern), key));
|
|
8878
|
+
var resolveWorkspaceFromEntries = (cwd, entries, workspaceName, remotes) => {
|
|
8879
|
+
const globbed = matchingEntries(cwd, entries);
|
|
8880
|
+
const listed = !remotes || globbed.length || !entries.some((entry) => entry.remotes) ? [] : checkoutRemotes(cwd);
|
|
8881
|
+
const origin = listed instanceof Error ? [] : listed.filter((item) => item.name === "origin");
|
|
8882
|
+
const hits = entries.filter((entry) => origin.length && origin.every((item) => remoteClaimOf(entry, item.key)));
|
|
8883
|
+
const exact = hits.filter((entry) => origin.every((item) => remoteClaimOf(entry, item.key, true)));
|
|
8884
|
+
const ranked = exact.length ? exact : hits;
|
|
8885
|
+
if (workspaceName === undefined && ranked.length > 1)
|
|
8886
|
+
return null;
|
|
8887
|
+
return selectWorkspaceMatch(hits.length ? workspaceName ? hits : ranked : globbed, cwd, workspaceName) ?? null;
|
|
8888
|
+
};
|
|
8889
|
+
var resolveWorkspaceFrom = (cwd, dir, workspaceName, remotes) => {
|
|
8872
8890
|
const result = readWorkspacesResult(dir);
|
|
8873
8891
|
if (result.status === "malformed" || result.status === "invalid")
|
|
8874
8892
|
throw new WorkspaceConfigError(result.error);
|
|
8875
|
-
return resolveWorkspaceFromEntries(cwd, result.entries, workspaceName);
|
|
8893
|
+
return resolveWorkspaceFromEntries(cwd, result.entries, workspaceName, remotes);
|
|
8876
8894
|
};
|
|
8877
8895
|
var runtimeWorkspacePolicySchema = (kind) => {
|
|
8878
8896
|
const key = kind === "branch" ? "branchPolicy" : kind === "commit" ? "commitPolicy" : "vcs";
|
|
@@ -8922,10 +8940,12 @@ var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
|
|
|
8922
8940
|
if (!glob.ok)
|
|
8923
8941
|
throw new WorkspaceConfigError(`${file} workspace ${entry.name}: ${glob.error}`);
|
|
8924
8942
|
}
|
|
8925
|
-
const matches = matchingEntries(cwd, entries ?? []);
|
|
8926
8943
|
const workspaceName = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
|
|
8927
|
-
const selected =
|
|
8928
|
-
|
|
8944
|
+
const selected = resolveWorkspaceFromEntries(cwd, entries ?? [], workspaceName, true);
|
|
8945
|
+
if (!selected)
|
|
8946
|
+
return null;
|
|
8947
|
+
const matches = matchingEntries(cwd, entries ?? []);
|
|
8948
|
+
return { file, selected, matches: matches.length ? matches : [selected] };
|
|
8929
8949
|
};
|
|
8930
8950
|
var resolveRuntimeReleaseTracks = (cwd) => {
|
|
8931
8951
|
const matched = matchRuntimeWorkspace(cwd);
|
|
@@ -19072,6 +19092,7 @@ var youTrackHostAllowed = (allowed, host) => {
|
|
|
19072
19092
|
var YTRACK_MISSING = "ytrack is not on PATH: Workit reaches YouTrack only through ytrack";
|
|
19073
19093
|
|
|
19074
19094
|
// packages/workit-core/src/autonomy.ts
|
|
19095
|
+
var resolveWorkspaceFrom2 = (cwd, dir, name) => resolveWorkspaceFrom(cwd, dir, name, true);
|
|
19075
19096
|
var accountHomeDir = () => {
|
|
19076
19097
|
const home = grantsHome.resolve();
|
|
19077
19098
|
return home === null ? null : configDir({ HOME: home });
|
|
@@ -19104,11 +19125,11 @@ var accountUnread = () => {
|
|
|
19104
19125
|
};
|
|
19105
19126
|
var entriesIn = (dir) => dir === null ? [] : loadWorkspacesFrom(dir);
|
|
19106
19127
|
var fileSource = (dir = accountDir()) => ({
|
|
19107
|
-
resolve: (cwd, name) => dir === null ? null :
|
|
19128
|
+
resolve: (cwd, name) => dir === null ? null : resolveWorkspaceFrom2(cwd, dir, name),
|
|
19108
19129
|
entries: () => entriesIn(dir)
|
|
19109
19130
|
});
|
|
19110
19131
|
var sealedSource = (entries) => ({
|
|
19111
|
-
resolve: (cwd, name) => resolveWorkspaceFromEntries(cwd, entries, name),
|
|
19132
|
+
resolve: (cwd, name) => resolveWorkspaceFromEntries(cwd, entries, name, true),
|
|
19112
19133
|
entries: () => entries
|
|
19113
19134
|
});
|
|
19114
19135
|
var sealOf = () => {
|
|
@@ -19134,8 +19155,8 @@ var youTrackWritesPolicy = (cwd) => {
|
|
|
19134
19155
|
return ASK;
|
|
19135
19156
|
const auto = (entry) => youtrackOf(entry)?.writes === "auto";
|
|
19136
19157
|
const name = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
|
|
19137
|
-
const named =
|
|
19138
|
-
const folder = name ?
|
|
19158
|
+
const named = resolveWorkspaceFrom2(cwd, dir, name);
|
|
19159
|
+
const folder = name ? resolveWorkspaceFrom2(cwd, dir) : named;
|
|
19139
19160
|
if (!auto(named) || !auto(folder))
|
|
19140
19161
|
return ASK;
|
|
19141
19162
|
const [a, b] = [autoHostsOf(named), autoHostsOf(folder)];
|
|
@@ -19396,7 +19417,8 @@ function resolveWith(source, cwd, world, target) {
|
|
|
19396
19417
|
const above = checkoutsAbove(cwd);
|
|
19397
19418
|
for (const where of above instanceof Error ? [above] : above)
|
|
19398
19419
|
autonomy = capAt(source, autonomy, where, where instanceof Error ? "git" : `checkout ${where}`, "a worktree or submodule never exceeds it", true);
|
|
19399
|
-
|
|
19420
|
+
const own = real && workspaceMatches(cwd, source.entries()).length === 0 ? real : undefined;
|
|
19421
|
+
return capAtRemotes(source, autonomy, cwd, target, own);
|
|
19400
19422
|
}
|
|
19401
19423
|
var needsAccount = (autonomy) => autonomy.configured.length > 0 && !autonomy.accountConfigured;
|
|
19402
19424
|
function stricter(current, sealed, note, unblock) {
|
|
@@ -19435,17 +19457,31 @@ function stricter(current, sealed, note, unblock) {
|
|
|
19435
19457
|
note: current.note ? `${current.note}; ${note}` : note
|
|
19436
19458
|
};
|
|
19437
19459
|
}
|
|
19438
|
-
function capAtRemotes(source, autonomy, cwd, target) {
|
|
19460
|
+
function capAtRemotes(source, autonomy, cwd, target, own) {
|
|
19439
19461
|
const claiming = source.entries().filter((entry) => entry.remotes?.length);
|
|
19440
19462
|
if (claiming.length === 0)
|
|
19441
19463
|
return autonomy;
|
|
19442
19464
|
const remotes = target === undefined ? checkoutRemotes(cwd) : typeof target === "function" ? target() : target;
|
|
19443
19465
|
if (remotes instanceof Error)
|
|
19444
19466
|
return capAt(source, autonomy, remotes, target === undefined ? "git" : "target", "a target that cannot be resolved never raises grants");
|
|
19467
|
+
const listed = Array.isArray(remotes) ? remotes : remotes.remotes;
|
|
19468
|
+
const capped = own ? capAtOwnClaim(source, autonomy, cwd, own, target && listed) : autonomy;
|
|
19469
|
+
return capAtClaims(source, capped, listed, claiming);
|
|
19470
|
+
}
|
|
19471
|
+
function capAtOwnClaim(source, autonomy, cwd, own, judged) {
|
|
19472
|
+
const push = judged ? { remotes: judged } : pushTarget(cwd, pushRemoteName(cwd) ?? "");
|
|
19473
|
+
if (push instanceof Error)
|
|
19474
|
+
return capAt(source, autonomy, push, "push target", "a target that cannot be resolved never raises grants");
|
|
19475
|
+
const unclaimed = push.remotes.filter((remote) => !remoteClaimOf(own, remote.key));
|
|
19476
|
+
if (unclaimed.length === 0 && push.remotes.length > 0)
|
|
19477
|
+
return autonomy;
|
|
19478
|
+
return stricter(autonomy, autonomyOf(null), `${unclaimed.map((remote) => `remote ${remote.name} ${remote.url}`).join(", ") || "no target"}: not in workspace ${own.name}'s remotes, which matched this checkout by its origin; grants capped at the defaults`, `ask the user to add that repository to workspace ${own.name}'s remotes, in their own terminal: workit workspace set ${own.name} remotes=<patterns>`);
|
|
19479
|
+
}
|
|
19480
|
+
function capAtClaims(source, autonomy, listed, claiming) {
|
|
19445
19481
|
let capped = autonomy;
|
|
19446
|
-
for (const remote of
|
|
19482
|
+
for (const remote of listed)
|
|
19447
19483
|
for (const entry of claiming) {
|
|
19448
|
-
const pattern = entry
|
|
19484
|
+
const pattern = remoteClaimOf(entry, remote.key);
|
|
19449
19485
|
if (pattern)
|
|
19450
19486
|
capped = capAt(source, capped, { entry }, `remote ${remote.name} ${remote.url} (workspace ${entry.name} claims ${pattern})`, "a checkout never exceeds the workspace that owns its remote");
|
|
19451
19487
|
}
|
|
@@ -19473,7 +19509,7 @@ function claimsIn(target, entries) {
|
|
|
19473
19509
|
return target;
|
|
19474
19510
|
const claiming = entries.filter((entry) => entry.remotes?.length);
|
|
19475
19511
|
return target.remotes.flatMap((remote) => claiming.flatMap((entry) => {
|
|
19476
|
-
const pattern = entry
|
|
19512
|
+
const pattern = remoteClaimOf(entry, remote.key);
|
|
19477
19513
|
return pattern ? [{ url: remote.url, workspace: entry.name, pattern }] : [];
|
|
19478
19514
|
}));
|
|
19479
19515
|
}
|
|
@@ -19954,9 +19990,9 @@ var arithmeticEnd = (command, start) => {
|
|
|
19954
19990
|
const end = substitutionEnd(command, start);
|
|
19955
19991
|
return command[end - 1] === ")" && end > start + 2 ? end : 0;
|
|
19956
19992
|
};
|
|
19957
|
-
var segmentsOf = (command, dialect = "posix") => {
|
|
19993
|
+
var segmentsOf = (command, dialect = "posix", options = {}) => {
|
|
19958
19994
|
try {
|
|
19959
|
-
return tokenize(command, dialect);
|
|
19995
|
+
return tokenize(command, dialect, options.spans === true);
|
|
19960
19996
|
} catch (error) {
|
|
19961
19997
|
const why = error instanceof ShellAnalysisError ? error.message : String(error);
|
|
19962
19998
|
return [{ words: [], redirects: [], unanalyzable: why }];
|
|
@@ -19966,12 +20002,14 @@ var afterEnv = (words) => {
|
|
|
19966
20002
|
const at = words.map((word) => word.split(/[\\/]/).at(-1)).lastIndexOf("env");
|
|
19967
20003
|
return at >= 0 && words.slice(at + 1).every((word, index, rest) => /^-|=/.test(word) || /^-[^-]*[uCS]$|^--(?:unset|chdir|split-string)$/.test(rest[index - 1] ?? ""));
|
|
19968
20004
|
};
|
|
19969
|
-
var tokenize = (command, dialect) => {
|
|
20005
|
+
var tokenize = (command, dialect, spans) => {
|
|
19970
20006
|
const posix = dialect === "posix";
|
|
19971
20007
|
const segments = [];
|
|
19972
20008
|
let current = { words: [], redirects: [] };
|
|
19973
20009
|
let word = "";
|
|
19974
20010
|
let inWord = false;
|
|
20011
|
+
let wordStart = -1;
|
|
20012
|
+
let cursor = 0;
|
|
19975
20013
|
let expanding = false;
|
|
19976
20014
|
let afterOperator = false;
|
|
19977
20015
|
let pending = null;
|
|
@@ -19982,9 +20020,13 @@ var tokenize = (command, dialect) => {
|
|
|
19982
20020
|
if (!inWord)
|
|
19983
20021
|
return;
|
|
19984
20022
|
const text = MARKERS.test(word) ? literal2(word) : word;
|
|
20023
|
+
const span = [wordStart, cursor];
|
|
19985
20024
|
if (pending === "redirect") {
|
|
19986
|
-
if (!duplicate || !/^(?:\d+-?|-)$/.test(text))
|
|
20025
|
+
if (!duplicate || !/^(?:\d+-?|-)$/.test(text)) {
|
|
19987
20026
|
current.redirects.push(text);
|
|
20027
|
+
if (spans)
|
|
20028
|
+
(current.redirectSpans ??= []).push(span);
|
|
20029
|
+
}
|
|
19988
20030
|
} else if (pending === "heredoc")
|
|
19989
20031
|
heredocs.push({ delimiter: text.replace(/^-/, ""), owner: current });
|
|
19990
20032
|
else if (pending === "herestring")
|
|
@@ -19992,17 +20034,20 @@ var tokenize = (command, dialect) => {
|
|
|
19992
20034
|
else if (pending === "input")
|
|
19993
20035
|
(current.inputs ??= []).push(text);
|
|
19994
20036
|
else {
|
|
19995
|
-
const
|
|
20037
|
+
const at0 = current.words.length;
|
|
19996
20038
|
if (/^[^=-][^=]*=/.test(word) && afterEnv(current.words))
|
|
19997
20039
|
word = word.replace(/^[^=]*/, (name) => name.replace(/\W/g, "_"));
|
|
19998
20040
|
current.words.push(...MARKERS.test(word) ? expandBraces(word) : [word]);
|
|
20041
|
+
if (spans)
|
|
20042
|
+
(current.spans ??= []).push(...current.words.slice(at0).map(() => span));
|
|
19999
20043
|
if (expanding || !posix && word.startsWith("@"))
|
|
20000
|
-
(current.expands ??= []).push(...current.words.slice(
|
|
20044
|
+
(current.expands ??= []).push(...current.words.slice(at0).map((_, i) => at0 + i));
|
|
20001
20045
|
}
|
|
20002
20046
|
pending = null;
|
|
20003
20047
|
duplicate = false;
|
|
20004
20048
|
word = "";
|
|
20005
20049
|
inWord = false;
|
|
20050
|
+
wordStart = -1;
|
|
20006
20051
|
expanding = false;
|
|
20007
20052
|
};
|
|
20008
20053
|
const flushSegment = () => {
|
|
@@ -20027,9 +20072,12 @@ var tokenize = (command, dialect) => {
|
|
|
20027
20072
|
};
|
|
20028
20073
|
const plain = posix ? PLAIN_POSIX : PLAIN_POWERSHELL;
|
|
20029
20074
|
for (let index = 0;index < command.length; index++) {
|
|
20075
|
+
cursor = index;
|
|
20030
20076
|
plain.lastIndex = index;
|
|
20031
20077
|
const run = plain.exec(command);
|
|
20032
20078
|
if (run) {
|
|
20079
|
+
if (wordStart < 0)
|
|
20080
|
+
wordStart = index;
|
|
20033
20081
|
word += run[0];
|
|
20034
20082
|
inWord = true;
|
|
20035
20083
|
if (EXPANDING_RUN.test(run[0]))
|
|
@@ -20055,9 +20103,11 @@ var tokenize = (command, dialect) => {
|
|
|
20055
20103
|
word += text;
|
|
20056
20104
|
inWord = true;
|
|
20057
20105
|
index = end;
|
|
20058
|
-
} else if (posix && char === "$" && next === '"')
|
|
20106
|
+
} else if (posix && char === "$" && next === '"') {
|
|
20107
|
+
if (wordStart < 0)
|
|
20108
|
+
wordStart = index;
|
|
20059
20109
|
continue;
|
|
20060
|
-
else if (char === "'" || char === '"') {
|
|
20110
|
+
} else if (char === "'" || char === '"') {
|
|
20061
20111
|
const end = closingQuote(command, index, dialect);
|
|
20062
20112
|
const body = command.slice(index + 1, end < 0 ? undefined : end);
|
|
20063
20113
|
if (posix && char === '"' && /\$\(|`/.test(body))
|
|
@@ -20098,6 +20148,7 @@ var tokenize = (command, dialect) => {
|
|
|
20098
20148
|
index = end;
|
|
20099
20149
|
} else if (posix && char === "(" && (pending === "input" || pending === "redirect")) {
|
|
20100
20150
|
const sign = pending === "input" ? "<" : ">";
|
|
20151
|
+
wordStart = index - 1;
|
|
20101
20152
|
pending = null;
|
|
20102
20153
|
const end = substitutionEnd(command, index);
|
|
20103
20154
|
const inner = command.slice(index + 1, end);
|
|
@@ -20110,8 +20161,10 @@ var tokenize = (command, dialect) => {
|
|
|
20110
20161
|
if (char === "(" && inWord && word.endsWith("$")) {
|
|
20111
20162
|
word = word.slice(0, -1);
|
|
20112
20163
|
inWord = word !== "";
|
|
20113
|
-
if (!inWord)
|
|
20164
|
+
if (!inWord) {
|
|
20114
20165
|
expanding = false;
|
|
20166
|
+
wordStart = -1;
|
|
20167
|
+
}
|
|
20115
20168
|
}
|
|
20116
20169
|
group(char === "(" ? "open" : "close");
|
|
20117
20170
|
} else if (!posix && (char === "{" || char === "}")) {
|
|
@@ -20146,6 +20199,7 @@ var tokenize = (command, dialect) => {
|
|
|
20146
20199
|
if (inWord && /^\d$/.test(word)) {
|
|
20147
20200
|
word = "";
|
|
20148
20201
|
inWord = false;
|
|
20202
|
+
wordStart = -1;
|
|
20149
20203
|
} else
|
|
20150
20204
|
flushWord();
|
|
20151
20205
|
if (command[index + 1] === ">")
|
|
@@ -20177,7 +20231,10 @@ var tokenize = (command, dialect) => {
|
|
|
20177
20231
|
word += char;
|
|
20178
20232
|
inWord = true;
|
|
20179
20233
|
}
|
|
20234
|
+
if (inWord && wordStart < 0)
|
|
20235
|
+
wordStart = cursor;
|
|
20180
20236
|
}
|
|
20237
|
+
cursor = command.length;
|
|
20181
20238
|
flushSegment();
|
|
20182
20239
|
return segments;
|
|
20183
20240
|
};
|
|
@@ -30539,8 +30596,8 @@ var writePaths = (input) => {
|
|
|
30539
30596
|
return [...new Set(paths)];
|
|
30540
30597
|
};
|
|
30541
30598
|
// packages/workit-core/src/hooks/standing.ts
|
|
30542
|
-
import
|
|
30543
|
-
import
|
|
30599
|
+
import fs32 from "node:fs";
|
|
30600
|
+
import path52 from "node:path";
|
|
30544
30601
|
|
|
30545
30602
|
// packages/workit-core/src/approvals/store.ts
|
|
30546
30603
|
import { createHash as createHash20, randomBytes as randomBytes4 } from "node:crypto";
|
|
@@ -30759,6 +30816,185 @@ var approveCallDeny = (fix) => `Run \`${fix}\` as its own call: no chain, pipe,
|
|
|
30759
30816
|
// packages/workit-core/src/approvals/inline.ts
|
|
30760
30817
|
import path49 from "node:path";
|
|
30761
30818
|
|
|
30819
|
+
// packages/workit-core/src/hooks/cwd-normalize.ts
|
|
30820
|
+
var DIR = String.raw`(?:[A-Za-z0-9_./@%+:,=-]|(?<=[A-Za-z0-9])~)+|'[^'$${"`"}\n]*'|"(?:[^"$${"`"}\\!\n]|\\(?=[^"$${"`"}\\!\n]))*"`;
|
|
30821
|
+
var COMPOUND2 = new RegExp(String.raw`^\s*cd\s+(${DIR})\s*&&\s*(workit(?:\s[\s\S]*)?)$`, "u");
|
|
30822
|
+
var UNSAFE = /[\p{Cf}\p{Zl}\p{Zp}]|[^\P{Cc}\n]/u;
|
|
30823
|
+
var newlines = (text) => text.split(`
|
|
30824
|
+
`).length - 1;
|
|
30825
|
+
var writtenWord = (command, segment, index) => {
|
|
30826
|
+
const span = segment.spans?.[index];
|
|
30827
|
+
if (!span)
|
|
30828
|
+
return null;
|
|
30829
|
+
const glued = (other) => other !== undefined && other !== span && (other[1] === span[0] || other[0] === span[1]);
|
|
30830
|
+
if (glued(segment.spans?.[index - 1]) || glued(segment.spans?.[index + 1]))
|
|
30831
|
+
return null;
|
|
30832
|
+
const text = command.slice(span[0], span[1]);
|
|
30833
|
+
const value = segment.words[index] ?? "";
|
|
30834
|
+
return UNSAFE.test(text) || newlines(text) !== newlines(value) ? null : text;
|
|
30835
|
+
};
|
|
30836
|
+
var writtenWords = (command, segment, indexes) => {
|
|
30837
|
+
const texts = [];
|
|
30838
|
+
let last;
|
|
30839
|
+
for (const index of indexes) {
|
|
30840
|
+
const span = segment.spans?.[index];
|
|
30841
|
+
if (span && span === last)
|
|
30842
|
+
continue;
|
|
30843
|
+
last = span;
|
|
30844
|
+
const text = writtenWord(command, segment, index);
|
|
30845
|
+
if (text === null)
|
|
30846
|
+
return null;
|
|
30847
|
+
texts.push(text);
|
|
30848
|
+
}
|
|
30849
|
+
return texts;
|
|
30850
|
+
};
|
|
30851
|
+
var cwdIndependent = (text, colons = false) => {
|
|
30852
|
+
let quoted = false;
|
|
30853
|
+
for (let index = 0;index < text.length; index += 1) {
|
|
30854
|
+
const char = text[index] ?? "";
|
|
30855
|
+
if (char === "\\")
|
|
30856
|
+
index += 1;
|
|
30857
|
+
else if (char === "'" && !quoted) {
|
|
30858
|
+
const end = text.indexOf("'", index + 1);
|
|
30859
|
+
if (end < 0)
|
|
30860
|
+
return false;
|
|
30861
|
+
index = end;
|
|
30862
|
+
} else if (char === '"')
|
|
30863
|
+
quoted = !quoted;
|
|
30864
|
+
else if (char === "$" || char === "`")
|
|
30865
|
+
return false;
|
|
30866
|
+
else if (quoted)
|
|
30867
|
+
continue;
|
|
30868
|
+
else if (/[*?[]/u.test(char) || /[<>]/u.test(char) && text[index + 1] === "(")
|
|
30869
|
+
return false;
|
|
30870
|
+
else if (char === "~") {
|
|
30871
|
+
const start = index === 0 || colons && text[index - 1] === ":";
|
|
30872
|
+
if (!start || !/^(?:\/|:|$)/u.test(text.slice(index + 1, index + 2)))
|
|
30873
|
+
return false;
|
|
30874
|
+
}
|
|
30875
|
+
}
|
|
30876
|
+
return !quoted;
|
|
30877
|
+
};
|
|
30878
|
+
var NOT_A_PATH = /^(?:\d*|true|false|yes|no|on|off|-[\w-]*(?:=\d+)?)$/iu;
|
|
30879
|
+
var cwdFreeAssignment = (text, value) => {
|
|
30880
|
+
const written = text.replace(/^[A-Za-z_]\w*=/u, "");
|
|
30881
|
+
if (!cwdIndependent(written, true))
|
|
30882
|
+
return false;
|
|
30883
|
+
const quotes = /['"\\]/u.test(written);
|
|
30884
|
+
const parts = value.replace(/^[A-Za-z_]\w*=/u, "").split(":");
|
|
30885
|
+
return parts.every((part) => part.startsWith("/") || !quotes && /^~(?:\/|$)/u.test(part) || (part !== "" || parts.length === 1) && NOT_A_PATH.test(part));
|
|
30886
|
+
};
|
|
30887
|
+
var plainQuotedExpansions = (text) => {
|
|
30888
|
+
const bare = text.replaceAll(/\\./gu, "").replaceAll(/\$(?:[A-Za-z_]\w*|\{[A-Za-z_]\w*\})/gu, "");
|
|
30889
|
+
return !bare.includes("$") && !bare.includes("`");
|
|
30890
|
+
};
|
|
30891
|
+
var certainDir = (text, value) => value !== "" && !value.startsWith("-") && (/^(?:"(?:[^"\\]|\\.)*"|'[^']*')$/u.test(text) && (text.startsWith("'") || plainQuotedExpansions(text)) || cwdIndependent(text) && !/[{}]/u.test(text.replaceAll(/'[^']*'|"(?:[^"\\]|\\.)*"|\\./gu, "")));
|
|
30892
|
+
var namesSet = (segments) => {
|
|
30893
|
+
const names = new Set;
|
|
30894
|
+
for (const { words } of segments) {
|
|
30895
|
+
const at = /^(?:export|declare|typeset|local|readonly)$/u.test(words[0] ?? "") ? 1 : 0;
|
|
30896
|
+
const assigns = words.slice(at).filter((word) => /^[A-Za-z_]\w*=/u.test(word));
|
|
30897
|
+
if (at === 1 || assigns.length === words.length)
|
|
30898
|
+
for (const word of assigns)
|
|
30899
|
+
names.add(word.slice(0, word.indexOf("=")));
|
|
30900
|
+
if (words[0] === "read" || words[0] === "mapfile") {
|
|
30901
|
+
for (const word of words.slice(1))
|
|
30902
|
+
if (/^[A-Za-z_]\w*$/u.test(word))
|
|
30903
|
+
names.add(word);
|
|
30904
|
+
}
|
|
30905
|
+
}
|
|
30906
|
+
return names;
|
|
30907
|
+
};
|
|
30908
|
+
var NO_PATH = /^(?:\d+|-[A-Za-z0-9-]*)$/u;
|
|
30909
|
+
var cwdFreeTail = (texts, check = false) => {
|
|
30910
|
+
const [command = "", ...args] = texts;
|
|
30911
|
+
if (command.includes("/") && !command.startsWith("/"))
|
|
30912
|
+
return false;
|
|
30913
|
+
return check || args.every((text) => NO_PATH.test(text) || /^(?:\/|~(?:\/|$))/u.test(text));
|
|
30914
|
+
};
|
|
30915
|
+
var GLOBALS_FIRST = new RegExp(String.raw`^(\s*workit)((?:\s+(?:--json|--cwd(?:=|\s+)(?:${DIR})))+)\s+([a-z][a-z-]*)(?=\s|$)`, "u");
|
|
30916
|
+
var VERB_FIRST = /^((?:--json\s+)*)([a-z][a-z-]*)(?=\s|$)/u;
|
|
30917
|
+
var VERBS = new Set(WORKIT_ALLOWED_VERBS);
|
|
30918
|
+
var FILTERS = new Set(["tail", "head", "grep"]);
|
|
30919
|
+
var clean = (s) => !s.unanalyzable && !s.group && !s.subs?.length && !s.stdin?.length && !s.redirects.length;
|
|
30920
|
+
var stdinOnly = (words) => {
|
|
30921
|
+
const [name, ...args] = words;
|
|
30922
|
+
const operands = args.filter((w) => !w.startsWith("-"));
|
|
30923
|
+
if (name === "grep")
|
|
30924
|
+
return operands.length <= 1 && !args.some((w) => /^-[^-]*[rRf]|^--(recursive|file)/u.test(w));
|
|
30925
|
+
return operands.every((w) => /^\d+$/u.test(w)) && !args.some((w) => w.startsWith("--output"));
|
|
30926
|
+
};
|
|
30927
|
+
var cwdRewrite = (command) => {
|
|
30928
|
+
const match = COMPOUND2.exec(command);
|
|
30929
|
+
const dir = match?.[1];
|
|
30930
|
+
const rest = match?.[2];
|
|
30931
|
+
if (!dir || !rest || dir.startsWith("-"))
|
|
30932
|
+
return null;
|
|
30933
|
+
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "").replaceAll(/'[^']*'|"([^"\\]|\\.)*"/gu, "")))
|
|
30934
|
+
return null;
|
|
30935
|
+
const segments = segmentsOf(rest);
|
|
30936
|
+
const [head, ...filters] = segments;
|
|
30937
|
+
if (!head || head.words[0] !== "workit")
|
|
30938
|
+
return null;
|
|
30939
|
+
if (!segments.every(clean))
|
|
30940
|
+
return null;
|
|
30941
|
+
if (!segments.slice(0, -1).every((s) => s.pipe))
|
|
30942
|
+
return null;
|
|
30943
|
+
if (!filters.every((s) => FILTERS.has(s.words[0] ?? "") && stdinOnly(s.words)))
|
|
30944
|
+
return null;
|
|
30945
|
+
const at = head.words.indexOf("--cwd");
|
|
30946
|
+
if (at >= 0) {
|
|
30947
|
+
const bare = dir.replace(/^(['"])(.*)\1$/u, "$2");
|
|
30948
|
+
return bare[0] === "/" && head.words[at + 1] === bare ? rest : null;
|
|
30949
|
+
}
|
|
30950
|
+
if (head.words.some((w) => w.startsWith("--cwd=")))
|
|
30951
|
+
return null;
|
|
30952
|
+
const args = rest.slice("workit".length).trimStart();
|
|
30953
|
+
const verb = VERB_FIRST.exec(args);
|
|
30954
|
+
if (!verb?.[2] || !VERBS.has(verb[2]))
|
|
30955
|
+
return `workit --cwd ${dir} ${args}`.trimEnd();
|
|
30956
|
+
const json = verb[1] ? " --json" : "";
|
|
30957
|
+
return `workit ${verb[2]} --cwd ${dir}${json}${args.slice(verb[0].length)}`.trimEnd();
|
|
30958
|
+
};
|
|
30959
|
+
var verbFirst = (command) => {
|
|
30960
|
+
const match = GLOBALS_FIRST.exec(command);
|
|
30961
|
+
const [whole, lead, globals, verb] = match ?? [];
|
|
30962
|
+
if (!whole || !verb || !VERBS.has(verb) || !globals?.includes("--cwd"))
|
|
30963
|
+
return null;
|
|
30964
|
+
const segments = segmentsOf(command);
|
|
30965
|
+
if (segments.length !== 1 || !segments.every(clean))
|
|
30966
|
+
return null;
|
|
30967
|
+
return `${lead} ${verb}${globals}${command.slice(whole.length)}`;
|
|
30968
|
+
};
|
|
30969
|
+
var NPX = new RegExp(String.raw`^(\s*(?:cd\s+(?:${DIR})\s*&&\s*)?)npx(?:\s+(?:-y|--yes))*\s+@workit-dev\/cli(?:@[\w.-]+)?(?=\s|$)`, "u");
|
|
30970
|
+
var npxWorkit = (command) => {
|
|
30971
|
+
const match = NPX.exec(command);
|
|
30972
|
+
if (!match)
|
|
30973
|
+
return null;
|
|
30974
|
+
const call = `${match[1]}workit${command.slice(match[0].length)}`;
|
|
30975
|
+
const left = segmentsOf(call).some((s) => s.unanalyzable || s.words.some((w) => /^(npx|@workit-dev\/cli(@\S*)?)$/u.test(w)));
|
|
30976
|
+
return left ? null : cwdRewrite(call) ?? verbFirst(call) ?? call;
|
|
30977
|
+
};
|
|
30978
|
+
var MUTATING_GIT2 = /^git( -\S+| -[Cc] \S+)* (commit|push|add|switch|checkout|merge|rebase|reset|cherry-pick|revert|branch .*(-[dDmM]|--delete|--move)\b|tag (?!-l\b|--list)|stash(?! (list|show)\b))/u;
|
|
30979
|
+
var cdWorkitSplit = (command) => {
|
|
30980
|
+
const match = COMPOUND2.exec(command);
|
|
30981
|
+
const dir = match?.[1];
|
|
30982
|
+
const rest = match?.[2];
|
|
30983
|
+
if (!dir || !rest || cwdRewrite(command) !== null)
|
|
30984
|
+
return null;
|
|
30985
|
+
const whole = segmentsOf(rest);
|
|
30986
|
+
const boundary = (head) => segmentsOf(head).every((s, at) => s.words.join("\x00") === whole[at]?.words.join("\x00"));
|
|
30987
|
+
for (const op of rest.matchAll(/\|\||;/gu)) {
|
|
30988
|
+
const head = rest.slice(0, op.index).trimEnd();
|
|
30989
|
+
const call = cwdRewrite(`cd ${dir} && ${head}`);
|
|
30990
|
+
if (!call || !boundary(head))
|
|
30991
|
+
continue;
|
|
30992
|
+
const next = segmentsOf(rest.slice(op.index + op[0].length))[0];
|
|
30993
|
+
return next && MUTATING_GIT2.test(next.words.join(" ")) ? call : null;
|
|
30994
|
+
}
|
|
30995
|
+
return null;
|
|
30996
|
+
};
|
|
30997
|
+
|
|
30762
30998
|
// packages/workit-core/src/approvals/release-notes-ask.ts
|
|
30763
30999
|
import { createHash as createHash21 } from "node:crypto";
|
|
30764
31000
|
import { existsSync as existsSync17, readFileSync as readFileSync14, realpathSync as realpathSync12 } from "node:fs";
|
|
@@ -30931,12 +31167,41 @@ var quote2 = (word, dialect) => {
|
|
|
30931
31167
|
return word;
|
|
30932
31168
|
return `'${word.replaceAll("'", dialect === "powershell" ? "''" : `'\\''`)}'`;
|
|
30933
31169
|
};
|
|
31170
|
+
var producedFile = (command, before, words) => {
|
|
31171
|
+
const named = (target) => words.some((word) => word === target || word.endsWith(`=${target}`));
|
|
31172
|
+
for (const segment of before) {
|
|
31173
|
+
const tee = (segment.words[0] ?? "").split(/[\\/]/u).at(-1) === "tee";
|
|
31174
|
+
const found = segment.redirects.findIndex(named);
|
|
31175
|
+
const span = found >= 0 ? segment.redirectSpans?.[found] : undefined;
|
|
31176
|
+
if (span)
|
|
31177
|
+
return command.slice(span[0], span[1]);
|
|
31178
|
+
const operand = tee ? segment.words.findIndex((word, index) => index > 0 && !word.startsWith("-") && named(word)) : -1;
|
|
31179
|
+
if (operand > 0)
|
|
31180
|
+
return writtenWord(command, segment, operand) ?? "a file the call reads";
|
|
31181
|
+
}
|
|
31182
|
+
return null;
|
|
31183
|
+
};
|
|
30934
31184
|
var routed = (call, globals) => {
|
|
30935
31185
|
if (!globals.includes("--json") || call.slice(1).includes("--json"))
|
|
30936
31186
|
return call;
|
|
30937
31187
|
const end = call.indexOf("--");
|
|
30938
31188
|
return end < 0 ? [...call, "--json"] : [...call.slice(0, end), "--json", ...call.slice(end)];
|
|
30939
31189
|
};
|
|
31190
|
+
var keptIndexes = (words, at) => {
|
|
31191
|
+
const kept = [];
|
|
31192
|
+
for (let index = at;index < words.length; index += 1) {
|
|
31193
|
+
if (words[index] === "--") {
|
|
31194
|
+
for (;index < words.length; index += 1)
|
|
31195
|
+
kept.push(index);
|
|
31196
|
+
break;
|
|
31197
|
+
}
|
|
31198
|
+
if (words[index] === "--cwd")
|
|
31199
|
+
index += 1;
|
|
31200
|
+
else if (!words[index]?.startsWith("--cwd="))
|
|
31201
|
+
kept.push(index);
|
|
31202
|
+
}
|
|
31203
|
+
return kept;
|
|
31204
|
+
};
|
|
30940
31205
|
var cwdValue = (value) => value && !value.startsWith("--") ? value : null;
|
|
30941
31206
|
var cwdOf = (globals) => {
|
|
30942
31207
|
let cwd = null;
|
|
@@ -30977,7 +31242,7 @@ var isReadFilter = (segment) => (segment.words[0] === "tail" || segment.words[0]
|
|
|
30977
31242
|
var onlyFiltersAfter = (segments) => segments[0]?.pipe === true && segments.slice(1).every((segment, index, rest) => isReadFilter(segment) && (index === rest.length - 1 ? !segment.pipe : segment.pipe));
|
|
30978
31243
|
var UNSAFE_TEXT = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
|
|
30979
31244
|
var ODD_SPACE = /[^\S \t\n]/u;
|
|
30980
|
-
var
|
|
31245
|
+
var DIR2 = "<dir>";
|
|
30981
31246
|
var literalDir = (word, expanded) => !expanded && !/^[~=]/u.test(word) && !UNSAFE_TEXT.test(word);
|
|
30982
31247
|
var cwdIndexes = (words, from, verb) => {
|
|
30983
31248
|
const found = [];
|
|
@@ -31001,22 +31266,25 @@ var leadingCd = (before, command) => {
|
|
|
31001
31266
|
return;
|
|
31002
31267
|
const dir = cd.words[1] ?? "";
|
|
31003
31268
|
const clean = !cd.redirects.length && !cd.subs?.length && !dir.startsWith("-");
|
|
31004
|
-
|
|
31269
|
+
const written = writtenWord(command, cd, 1);
|
|
31270
|
+
const certain = written !== null && certainDir(written, dir);
|
|
31271
|
+
return clean && certain && literalDir(dir, Boolean(cd.expands?.length)) ? dir : DIR2;
|
|
31005
31272
|
};
|
|
31006
|
-
var
|
|
31273
|
+
var fixDir = (cwd, literal, cd, dialect) => {
|
|
31007
31274
|
if (cwd === null)
|
|
31008
31275
|
return cd ?? null;
|
|
31009
31276
|
if (!literal)
|
|
31010
|
-
return
|
|
31011
|
-
|
|
31277
|
+
return DIR2;
|
|
31278
|
+
const paths = dialect === "powershell" ? path49.win32 : path49.posix;
|
|
31279
|
+
if (paths.isAbsolute(cwd) || path49.isAbsolute(cwd) || cd === null)
|
|
31012
31280
|
return cwd;
|
|
31013
|
-
return cd === undefined || cd ===
|
|
31281
|
+
return cd === undefined || cd === DIR2 ? DIR2 : paths.join(cd, cwd);
|
|
31014
31282
|
};
|
|
31015
|
-
var OPAQUE_RELEASE_FIX = `workit release --cwd ${
|
|
31283
|
+
var OPAQUE_RELEASE_FIX = `workit release --cwd ${DIR2} notes approve <version>`;
|
|
31016
31284
|
var inlineCallIn = (command, dialect = "posix") => {
|
|
31017
31285
|
if (!/\bworkit\b/u.test(command))
|
|
31018
31286
|
return null;
|
|
31019
|
-
const segments = segmentsOf(command, dialect);
|
|
31287
|
+
const segments = segmentsOf(command, dialect, { spans: true });
|
|
31020
31288
|
for (const [position, segment] of segments.entries()) {
|
|
31021
31289
|
if (segment.unanalyzable)
|
|
31022
31290
|
continue;
|
|
@@ -31024,8 +31292,10 @@ var inlineCallIn = (command, dialect = "posix") => {
|
|
|
31024
31292
|
if ((words[0] ?? "").endsWith("sh"))
|
|
31025
31293
|
for (const word of words.slice(1)) {
|
|
31026
31294
|
const inner = /\s/u.test(word) ? inlineCallIn(word, dialect) : null;
|
|
31295
|
+
if (inner?.plain)
|
|
31296
|
+
return { plain: false, fix: word.trim(), words: inner.words };
|
|
31027
31297
|
if (inner)
|
|
31028
|
-
return
|
|
31298
|
+
return inner;
|
|
31029
31299
|
}
|
|
31030
31300
|
const start = words.findIndex(isWorkitWord2);
|
|
31031
31301
|
if (start < 0)
|
|
@@ -31046,12 +31316,44 @@ var inlineCallIn = (command, dialect = "posix") => {
|
|
|
31046
31316
|
return { plain: true, words: routed(call, words.slice(1, at)), cwd: verb.cwd };
|
|
31047
31317
|
const last = cwds.at(-1);
|
|
31048
31318
|
const lastLiteral = last === undefined || literal(last);
|
|
31049
|
-
const
|
|
31050
|
-
const
|
|
31051
|
-
const
|
|
31052
|
-
const
|
|
31053
|
-
const
|
|
31054
|
-
|
|
31319
|
+
const before = segments.slice(0, position);
|
|
31320
|
+
const cd = leadingCd(before, command);
|
|
31321
|
+
const set = namesSet(before);
|
|
31322
|
+
const expanding = new Set(segment.expands ?? []);
|
|
31323
|
+
const texts = [];
|
|
31324
|
+
let prev;
|
|
31325
|
+
for (const index of keptIndexes(words, at)) {
|
|
31326
|
+
const span = segment.spans?.[index];
|
|
31327
|
+
if (span && span === prev)
|
|
31328
|
+
continue;
|
|
31329
|
+
prev = span;
|
|
31330
|
+
const local = expanding.has(index) ? [...(words[index] ?? "").matchAll(/\$\{?(\w+)/gu)].find((match) => set.has(match[1] ?? "")) : undefined;
|
|
31331
|
+
texts.push(local ? `<path of $${local[1]}>` : writtenWord(command, segment, index));
|
|
31332
|
+
}
|
|
31333
|
+
const file = producedFile(command, before, words) ?? undefined;
|
|
31334
|
+
const done = (fix) => ({
|
|
31335
|
+
plain: false,
|
|
31336
|
+
fix,
|
|
31337
|
+
words: call,
|
|
31338
|
+
...file && { file }
|
|
31339
|
+
});
|
|
31340
|
+
if (texts.includes(null)) {
|
|
31341
|
+
const verbs = call.slice(0, 2).join(" ");
|
|
31342
|
+
return done(release ? OPAQUE_RELEASE_FIX : `workit ${verbs} <its other words as you wrote them>`);
|
|
31343
|
+
}
|
|
31344
|
+
const [head = "", ...rest] = texts;
|
|
31345
|
+
const cwdTexts = cwds.map((index) => writtenWord(command, segment, index));
|
|
31346
|
+
const uncertain = !rest.every((text) => cwdIndependent(text)) || cwdTexts.some((text) => text === null || !cwdIndependent(text.replace(/^--cwd=/u, "")));
|
|
31347
|
+
if (cd && cd !== DIR2 && uncertain) {
|
|
31348
|
+
const dir = before[0] ? writtenWord(command, before[0], 1) : null;
|
|
31349
|
+
const all = writtenWords(command, segment, Array.from({ length: words.length - start - 1 }, (_, n) => start + 1 + n));
|
|
31350
|
+
if (dir !== null && all)
|
|
31351
|
+
return done(`cd ${dir} && workit ${all.join(" ")}`);
|
|
31352
|
+
}
|
|
31353
|
+
const cdLost = cd === undefined && !command.includes("||") && before.some((step) => step.words[0] === "cd");
|
|
31354
|
+
const cwd = cdLost && verb.cwd === null ? DIR2 : fixDir(verb.cwd, lastLiteral, cd, dialect);
|
|
31355
|
+
const where = cwd === null ? [] : ["--cwd", cwd === DIR2 ? DIR2 : quote2(cwd, dialect)];
|
|
31356
|
+
return done(["workit", head, ...where, ...rest].join(" "));
|
|
31055
31357
|
}
|
|
31056
31358
|
return null;
|
|
31057
31359
|
};
|
|
@@ -31060,7 +31362,16 @@ var inlineAskFor = (words, cwd) => {
|
|
|
31060
31362
|
return releaseNotesAskAt(words.slice(3), cwd);
|
|
31061
31363
|
return asked(words) && youTrackWritesMode(cwd) !== "auto" ? youTrackAsk(words.slice(1), cwd) : null;
|
|
31062
31364
|
};
|
|
31063
|
-
var
|
|
31365
|
+
var showable = (text) => !/`|[\p{Cf}\p{Zl}\p{Zp}]|[^\P{Cc}\n]/u.test(text);
|
|
31366
|
+
var inlineCallDeny = (fix, file) => {
|
|
31367
|
+
const call = showable(fix) ? `\`${fix}\`` : "the call, its words as you wrote them,";
|
|
31368
|
+
const run = `${call} as its own call so the host can ask the user.`;
|
|
31369
|
+
const first = file ? `An earlier step in this command writes ${showable(file) && !file.includes(`
|
|
31370
|
+
`) ? `\`${file}\`` : "the file the call reads"}; run that step as its own call first, then run ${run}` : `Run ${run}`;
|
|
31371
|
+
const segments = segmentsOf(fix.replace(/<[^>\n]*>/gu, "x"));
|
|
31372
|
+
const expands = segments.length > 1 || segments.some((segment) => segment.expands?.length) || /(?:^|\s)~[^/\s]/u.test(fix);
|
|
31373
|
+
return expands ? `${first} Spell out each word the shell would expand ($…, a glob, a cd): the host asks only on a call its text fixes.` : first;
|
|
31374
|
+
};
|
|
31064
31375
|
|
|
31065
31376
|
// packages/workit-core/src/hooks/hosts/claude-code.ts
|
|
31066
31377
|
var CLAUDE_CODE_DESCRIPTOR = {
|
|
@@ -31541,83 +31852,559 @@ function neededChecks(lane, configured) {
|
|
|
31541
31852
|
|
|
31542
31853
|
// packages/workit-core/src/hooks/worktree-confine.ts
|
|
31543
31854
|
import { createHash as createHash23 } from "node:crypto";
|
|
31544
|
-
import
|
|
31855
|
+
import fs31 from "node:fs";
|
|
31545
31856
|
import os11 from "node:os";
|
|
31857
|
+
import path51 from "node:path";
|
|
31858
|
+
|
|
31859
|
+
// packages/workit-core/src/hooks/identity-env.ts
|
|
31860
|
+
import fs30 from "node:fs";
|
|
31546
31861
|
import path50 from "node:path";
|
|
31547
|
-
var
|
|
31548
|
-
var
|
|
31549
|
-
var
|
|
31550
|
-
var
|
|
31551
|
-
|
|
31552
|
-
|
|
31862
|
+
var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
|
|
31863
|
+
var IDENTITY = new RegExp(`^${NAMES}$`, "u");
|
|
31864
|
+
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
31865
|
+
var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
|
|
31866
|
+
var IDENTITY_ANY = new RegExp(NAMES, "iu");
|
|
31867
|
+
var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
|
|
31868
|
+
var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
|
|
31869
|
+
var STATE_ANY = new RegExp(STATE_NAMES, "iu");
|
|
31870
|
+
var powershell = (names) => new RegExp([
|
|
31871
|
+
`\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
|
|
31872
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
|
|
31873
|
+
`SetEnvironmentVariable\\(\\s*['"]${names}\\b`
|
|
31874
|
+
].join("|"), "iu");
|
|
31875
|
+
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";
|
|
31876
|
+
var POWERSHELL = powershell(NAMES);
|
|
31877
|
+
var POWERSHELL_STATE = powershell(STATE_NAMES);
|
|
31878
|
+
var POWERSHELL_HOST = powershell(HOST_NAMES);
|
|
31879
|
+
var POWERSHELL_OPAQUE = new RegExp([
|
|
31880
|
+
`SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
|
|
31881
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
|
|
31882
|
+
`(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
|
|
31883
|
+
`\\b(?:iex|Invoke-Expression)\\b`
|
|
31884
|
+
].join("|"), "iu");
|
|
31885
|
+
var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
|
|
31886
|
+
var CMD_IDENTITY = cmdSet(NAMES);
|
|
31887
|
+
var CMD_STATE = cmdSet(STATE_NAMES);
|
|
31888
|
+
var CMD_HOST = cmdSet(HOST_NAMES);
|
|
31889
|
+
var RUNS_TEXT = /\bworkit(?:-cli)?\b|@workit-dev[\\/]cli/iu;
|
|
31890
|
+
var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
|
|
31891
|
+
var OPAQUE = new Set([
|
|
31892
|
+
"watch",
|
|
31893
|
+
"strace",
|
|
31894
|
+
"chroot",
|
|
31895
|
+
"flock",
|
|
31896
|
+
"ssh",
|
|
31897
|
+
"su",
|
|
31898
|
+
"runuser",
|
|
31899
|
+
"script",
|
|
31900
|
+
"parallel"
|
|
31901
|
+
]);
|
|
31902
|
+
var ENV_VALUED = new Set(["u", "C", "S", "a", "P"]);
|
|
31903
|
+
var ENV_FLAGS = new Set(["i", "0", "v"]);
|
|
31904
|
+
var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
|
|
31905
|
+
var ENV_LONG_FLAGS = /^--(?:ignore-environment|null|debug|(?:block|default|ignore)-signal(?:=.*)?)$/u;
|
|
31906
|
+
var base2 = (word) => (word?.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "");
|
|
31907
|
+
var ASSIGN = /^[A-Za-z_]\w*\+?=/u;
|
|
31908
|
+
var nameOf = (word) => (word?.split("=")[0] ?? "").replace(/\+$/u, "");
|
|
31909
|
+
var named = (word) => IDENTITY.test(nameOf(word));
|
|
31910
|
+
var stateNamed = (word) => STATE2.test(nameOf(word));
|
|
31911
|
+
var isWorkit = (word) => /^workit(?:-cli)?(?:\.[cm]?js)?$/u.test(base2(word)) || /@workit-dev[\\/]cli\b|workit-cli[\\/](?:dist|src)[\\/]/u.test(word ?? "");
|
|
31912
|
+
var linksToWorkit = (word, cwd) => {
|
|
31913
|
+
const places = /[\\/]/u.test(word) ? [path50.resolve(cwd ?? process.cwd(), word)] : (process.env.PATH ?? "").split(path50.delimiter).map((dir) => path50.join(dir, word));
|
|
31914
|
+
for (const place of places) {
|
|
31553
31915
|
try {
|
|
31554
|
-
|
|
31555
|
-
|
|
31556
|
-
|
|
31557
|
-
return file;
|
|
31558
|
-
rest = rest ? path50.join(path50.basename(dir), rest) : path50.basename(dir);
|
|
31559
|
-
}
|
|
31916
|
+
const real = fs30.realpathSync(place);
|
|
31917
|
+
return isWorkit(real);
|
|
31918
|
+
} catch {}
|
|
31560
31919
|
}
|
|
31920
|
+
return false;
|
|
31561
31921
|
};
|
|
31562
|
-
var
|
|
31563
|
-
|
|
31564
|
-
|
|
31565
|
-
|
|
31566
|
-
|
|
31567
|
-
|
|
31568
|
-
if (part === "" || part === ".")
|
|
31569
|
-
continue;
|
|
31570
|
-
if (part === "..") {
|
|
31571
|
-
at = path50.dirname(at);
|
|
31572
|
-
continue;
|
|
31573
|
-
}
|
|
31574
|
-
const next = path50.join(at, part);
|
|
31575
|
-
let link = null;
|
|
31576
|
-
if (!missing)
|
|
31577
|
-
try {
|
|
31578
|
-
link = fs30.readlinkSync(next);
|
|
31579
|
-
} catch (error) {
|
|
31580
|
-
missing = error.code !== "EINVAL";
|
|
31581
|
-
}
|
|
31582
|
-
if (link === null) {
|
|
31583
|
-
at = next;
|
|
31584
|
-
hops.chain = 40;
|
|
31585
|
-
} else if (hops.chain-- > 0 && hops.total-- > 0)
|
|
31586
|
-
at = canonical6(path50.isAbsolute(link) ? link : `${at}${path50.sep}${link}`, hops);
|
|
31922
|
+
var newSeg = () => ({ identity: null, scoped: null, runs: false, words: [] });
|
|
31923
|
+
var UNREADABLE = "env/unset arguments Workit cannot read";
|
|
31924
|
+
var note = (scan, seg, word) => {
|
|
31925
|
+
if (scan.identity && named(word)) {
|
|
31926
|
+
if (seg)
|
|
31927
|
+
seg.identity ??= nameOf(word);
|
|
31587
31928
|
else
|
|
31588
|
-
|
|
31589
|
-
}
|
|
31590
|
-
return realOf(at);
|
|
31591
|
-
};
|
|
31592
|
-
var within = (child, parent) => {
|
|
31593
|
-
const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
|
|
31594
|
-
const relative = path50.relative(fold(parent), fold(child));
|
|
31595
|
-
return relative === "" || !relative.startsWith("..") && !path50.isAbsolute(relative);
|
|
31596
|
-
};
|
|
31597
|
-
var checkoutOf3 = (file) => {
|
|
31598
|
-
for (let dir = canonical6(file);; dir = path50.dirname(dir)) {
|
|
31599
|
-
const dotGit = path50.join(dir, ".git");
|
|
31600
|
-
if (fs30.existsSync(dotGit)) {
|
|
31601
|
-
const admin = fs30.statSync(dotGit).isFile() ? gitDirsAt(dir, null, false)?.[0] : undefined;
|
|
31602
|
-
return { root: dir, workit: !!admin && fs30.existsSync(path50.join(admin, FANOUT_TOKEN_FILE)) };
|
|
31603
|
-
}
|
|
31604
|
-
if (path50.dirname(dir) === dir)
|
|
31605
|
-
return null;
|
|
31606
|
-
}
|
|
31607
|
-
};
|
|
31608
|
-
var workitWorktreeOf = (file) => {
|
|
31609
|
-
try {
|
|
31610
|
-
const checkout = checkoutOf3(file);
|
|
31611
|
-
return checkout?.workit ? checkout.root : null;
|
|
31612
|
-
} catch {
|
|
31613
|
-
return null;
|
|
31929
|
+
scan.hit ??= nameOf(word);
|
|
31614
31930
|
}
|
|
31931
|
+
if (!stateNamed(word) && !(scan.identity && HOST_VARIABLE.test(nameOf(word))))
|
|
31932
|
+
return;
|
|
31933
|
+
if (seg)
|
|
31934
|
+
seg.scoped ??= nameOf(word);
|
|
31935
|
+
else
|
|
31936
|
+
scan.shell ??= nameOf(word);
|
|
31615
31937
|
};
|
|
31616
|
-
var
|
|
31617
|
-
var
|
|
31618
|
-
|
|
31938
|
+
var mayBeWorkit = (words, cwd) => words.some(({ word, built }) => built || linksToWorkit(word, cwd));
|
|
31939
|
+
var scanEnv = (words, at, expands, scan, seg, depth) => {
|
|
31940
|
+
const risky = (what) => void (scan.risky ??= what);
|
|
31941
|
+
const unset = (name) => note(scan, seg, name);
|
|
31942
|
+
const split = (line, rest, built) => {
|
|
31943
|
+
if (line === undefined || depth >= 4)
|
|
31944
|
+
return risky(UNREADABLE);
|
|
31945
|
+
if (built || /[$`]/u.test(line))
|
|
31946
|
+
risky(UNREADABLE);
|
|
31947
|
+
const tokens = [];
|
|
31948
|
+
const expanded = new Set;
|
|
31949
|
+
try {
|
|
31950
|
+
for (const segment of segmentsOf(line)) {
|
|
31951
|
+
for (const index of segment.expands ?? [])
|
|
31952
|
+
expanded.add(tokens.length + index);
|
|
31953
|
+
tokens.push(...segment.words);
|
|
31954
|
+
}
|
|
31955
|
+
} catch {
|
|
31956
|
+
return risky(UNREADABLE);
|
|
31957
|
+
}
|
|
31958
|
+
scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, seg, depth + 1);
|
|
31959
|
+
};
|
|
31960
|
+
let options = true;
|
|
31961
|
+
for (let index = at;index < words.length; index += 1) {
|
|
31962
|
+
const word = words[index] ?? "";
|
|
31963
|
+
if (expands.has(index)) {
|
|
31964
|
+
risky(UNREADABLE);
|
|
31965
|
+
const built = options ? /^(?:--split-string=|-[\w]*S)(.+)$/su.exec(word) : null;
|
|
31966
|
+
if (built)
|
|
31967
|
+
return split(built[1], index + 1, true);
|
|
31968
|
+
continue;
|
|
31969
|
+
}
|
|
31970
|
+
if (options && word === "--") {
|
|
31971
|
+
options = false;
|
|
31972
|
+
continue;
|
|
31973
|
+
}
|
|
31974
|
+
if (options && word === "-") {
|
|
31975
|
+
risky("env -i");
|
|
31976
|
+
continue;
|
|
31977
|
+
}
|
|
31978
|
+
if (options && word.startsWith("--")) {
|
|
31979
|
+
const [name = "", value] = word.split(/=(.*)/su);
|
|
31980
|
+
if (name === "--ignore-environment")
|
|
31981
|
+
risky("env -i");
|
|
31982
|
+
else if (name === "--unset")
|
|
31983
|
+
unset(value ?? words[index += 1]);
|
|
31984
|
+
else if (name === "--split-string")
|
|
31985
|
+
return split(value ?? words[index + 1], index + (value === undefined ? 2 : 1), expands.has(index + (value === undefined ? 1 : 0)));
|
|
31986
|
+
else if (ENV_LONG_VALUED.has(name))
|
|
31987
|
+
index += value === undefined ? 1 : 0;
|
|
31988
|
+
else if (!ENV_LONG_FLAGS.test(word))
|
|
31989
|
+
risky(UNREADABLE);
|
|
31990
|
+
continue;
|
|
31991
|
+
}
|
|
31992
|
+
if (options && word.startsWith("-") && word.length > 1) {
|
|
31993
|
+
for (let at2 = 1;at2 < word.length; at2 += 1) {
|
|
31994
|
+
const letter = word[at2] ?? "";
|
|
31995
|
+
if (letter === "i")
|
|
31996
|
+
risky("env -i");
|
|
31997
|
+
else if (ENV_FLAGS.has(letter))
|
|
31998
|
+
continue;
|
|
31999
|
+
else if (ENV_VALUED.has(letter)) {
|
|
32000
|
+
const glued = word.slice(at2 + 1);
|
|
32001
|
+
if (!glued)
|
|
32002
|
+
index += 1;
|
|
32003
|
+
const value = glued || words[index];
|
|
32004
|
+
if (letter === "u")
|
|
32005
|
+
unset(value);
|
|
32006
|
+
if (letter === "S")
|
|
32007
|
+
return split(value, index + 1, expands.has(index));
|
|
32008
|
+
break;
|
|
32009
|
+
} else {
|
|
32010
|
+
risky(UNREADABLE);
|
|
32011
|
+
break;
|
|
32012
|
+
}
|
|
32013
|
+
}
|
|
32014
|
+
continue;
|
|
32015
|
+
}
|
|
32016
|
+
if (ASSIGN.test(word)) {
|
|
32017
|
+
unset(word);
|
|
32018
|
+
continue;
|
|
32019
|
+
}
|
|
32020
|
+
return commandAt(words.slice(index), scan, seg, new Set([...expands].filter((at2) => at2 >= index).map((at2) => at2 - index)));
|
|
32021
|
+
}
|
|
32022
|
+
};
|
|
32023
|
+
var commandAt = (words, scan, seg, expands = new Set, from = 0) => {
|
|
32024
|
+
let index = from;
|
|
32025
|
+
while (index < words.length) {
|
|
32026
|
+
while (ASSIGN.test(words[index] ?? "")) {
|
|
32027
|
+
note(scan, seg, words[index]);
|
|
32028
|
+
index += 1;
|
|
32029
|
+
}
|
|
32030
|
+
const name = base2(words[index]).toLowerCase();
|
|
32031
|
+
if (name === "env")
|
|
32032
|
+
return scanEnv(words, index + 1, expands, scan, seg, 0);
|
|
32033
|
+
if (OPAQUE.has(name))
|
|
32034
|
+
return opaque(words.slice(index + 1), scan, seg, true);
|
|
32035
|
+
if (name === "busybox" || name === "toybox") {
|
|
32036
|
+
index += 1;
|
|
32037
|
+
continue;
|
|
32038
|
+
}
|
|
32039
|
+
const takes = WRAPPERS3[name];
|
|
32040
|
+
if (takes === undefined)
|
|
32041
|
+
break;
|
|
32042
|
+
index = pastOptions(words, index + 1, takes);
|
|
32043
|
+
}
|
|
32044
|
+
const word = words[index];
|
|
32045
|
+
if (word === undefined)
|
|
32046
|
+
return;
|
|
32047
|
+
seg.words.push({ word, built: expands.has(index) });
|
|
32048
|
+
const rest = words.slice(index + 1);
|
|
32049
|
+
if (isWorkit(word) || rest.some(isWorkit))
|
|
32050
|
+
seg.runs = true;
|
|
32051
|
+
if (!isWorkit(word) && rest.some((next) => base2(next).toLowerCase() === "env"))
|
|
32052
|
+
opaque(rest, scan, seg, false);
|
|
32053
|
+
const program = base2(word).toLowerCase();
|
|
32054
|
+
const shell = program === "pwsh" || program === "powershell";
|
|
32055
|
+
if (program === "cmd" || shell) {
|
|
32056
|
+
const at = rest.findIndex((next) => shell ? /^-(?:c|command)$/iu.test(next) : /^\/[ck]$/iu.test(next));
|
|
32057
|
+
if (at >= 0) {
|
|
32058
|
+
const script = rest.slice(at + 1).join(" ");
|
|
32059
|
+
const change = shell ? powershellChange(script, scan.identity) : cmdChange(script, scan);
|
|
32060
|
+
if (change)
|
|
32061
|
+
scan.hit ??= change;
|
|
32062
|
+
}
|
|
32063
|
+
}
|
|
32064
|
+
};
|
|
32065
|
+
var opaque = (rest, scan, seg, assigns) => {
|
|
32066
|
+
if (!rest.some(isWorkit))
|
|
32067
|
+
return;
|
|
32068
|
+
seg.runs = true;
|
|
32069
|
+
const changes = (word) => base2(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && ASSIGN.test(word);
|
|
32070
|
+
if (rest.some(changes))
|
|
32071
|
+
scan.risky ??= UNREADABLE;
|
|
32072
|
+
if (rest.some((word) => base2(word).toLowerCase() === "env"))
|
|
32073
|
+
for (const word of rest)
|
|
32074
|
+
note(scan, seg, word);
|
|
32075
|
+
};
|
|
32076
|
+
var LOGIN_VALUED = {
|
|
32077
|
+
su: /[sgGwc]/u,
|
|
32078
|
+
runuser: /[sgGwuc]/u,
|
|
32079
|
+
script: /[cEIOBTmot]/u
|
|
32080
|
+
};
|
|
32081
|
+
var loginScript = (words) => {
|
|
32082
|
+
const at = words.findIndex((word) => /^(?:su|runuser|script)$/u.test(base2(word)));
|
|
32083
|
+
if (at < 0)
|
|
32084
|
+
return null;
|
|
32085
|
+
const valued = LOGIN_VALUED[base2(words[at])] ?? /c/u;
|
|
32086
|
+
for (let index = at + 1;index < words.length; index += 1) {
|
|
32087
|
+
const word = words[index] ?? "";
|
|
32088
|
+
if (word === "--command")
|
|
32089
|
+
return words[index + 1] ?? null;
|
|
32090
|
+
if (word.startsWith("--command="))
|
|
32091
|
+
return word.slice("--command=".length);
|
|
32092
|
+
if (!/^-[^-]/u.test(word))
|
|
32093
|
+
continue;
|
|
32094
|
+
const ends = word.slice(1).search(valued) + 1;
|
|
32095
|
+
if (ends > 0 && word[ends] === "c")
|
|
32096
|
+
return word.slice(ends + 1) || (words[index + 1] ?? null);
|
|
32097
|
+
}
|
|
32098
|
+
return null;
|
|
32099
|
+
};
|
|
32100
|
+
var scanCommand = (command, dialect, depth, scan) => {
|
|
32101
|
+
let segments;
|
|
32102
|
+
try {
|
|
32103
|
+
segments = segmentsOf(command, dialect);
|
|
32104
|
+
} catch {
|
|
32105
|
+
return;
|
|
32106
|
+
}
|
|
32107
|
+
for (const { words, expands = [] } of segments) {
|
|
32108
|
+
const expanded = new Set(expands);
|
|
32109
|
+
const seg = newSeg();
|
|
32110
|
+
let at = 0;
|
|
32111
|
+
while (ASSIGN.test(words[at] ?? ""))
|
|
32112
|
+
at += 1;
|
|
32113
|
+
for (const word of words.slice(0, at))
|
|
32114
|
+
note(scan, at === words.length ? null : seg, word);
|
|
32115
|
+
let declare = at;
|
|
32116
|
+
if (["builtin", "command"].includes(words[declare] ?? ""))
|
|
32117
|
+
declare += 1;
|
|
32118
|
+
if (DECLARES.has(words[declare] ?? "")) {
|
|
32119
|
+
for (let index = declare + 1;index < words.length; index += 1) {
|
|
32120
|
+
note(scan, null, words[index]);
|
|
32121
|
+
if (expanded.has(index))
|
|
32122
|
+
scan.risky ??= UNREADABLE;
|
|
32123
|
+
}
|
|
32124
|
+
continue;
|
|
32125
|
+
}
|
|
32126
|
+
commandAt(words, scan, seg, expanded, at);
|
|
32127
|
+
const script = depth < 4 ? shellScript2(words) ?? loginScript(words) : null;
|
|
32128
|
+
if (script) {
|
|
32129
|
+
const before = scan.runs;
|
|
32130
|
+
scan.runs = false;
|
|
32131
|
+
scanCommand(script, dialect, depth + 1, scan);
|
|
32132
|
+
seg.runs ||= scan.runs;
|
|
32133
|
+
scan.runs ||= before;
|
|
32134
|
+
}
|
|
32135
|
+
scan.words.push(...seg.words);
|
|
32136
|
+
const reaches = () => seg.runs || mayBeWorkit(seg.words, scan.cwd);
|
|
32137
|
+
if (seg.identity && reaches())
|
|
32138
|
+
scan.hit ??= seg.identity;
|
|
32139
|
+
if (seg.scoped && reaches())
|
|
32140
|
+
scan.state ??= seg.scoped;
|
|
32141
|
+
scan.runs ||= seg.runs;
|
|
32142
|
+
}
|
|
32143
|
+
};
|
|
32144
|
+
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);
|
|
32145
|
+
var powershellChange = (command, identity) => {
|
|
32146
|
+
const hit = identity ? POWERSHELL.exec(command)?.[0] : null;
|
|
32147
|
+
if (hit)
|
|
32148
|
+
return hit;
|
|
32149
|
+
if (!RUNS_TEXT.test(command) && !/&\s*[$(]/u.test(command))
|
|
32150
|
+
return null;
|
|
32151
|
+
const state = POWERSHELL_STATE.exec(command)?.[0] ?? (identity ? POWERSHELL_HOST.exec(command)?.[0] : null) ?? cmdChange(command, { identity });
|
|
32152
|
+
if (state)
|
|
32153
|
+
return state;
|
|
32154
|
+
return POWERSHELL_OPAQUE.test(command) ? UNREADABLE : null;
|
|
32155
|
+
};
|
|
32156
|
+
var identityEnvChange = (command, dialect = "posix", options = {}) => {
|
|
32157
|
+
const identity = options.identity ?? true;
|
|
32158
|
+
if (dialect === "powershell")
|
|
32159
|
+
return powershellChange(command, identity);
|
|
32160
|
+
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))
|
|
32161
|
+
return null;
|
|
32162
|
+
const scan = {
|
|
32163
|
+
identity,
|
|
32164
|
+
cwd: options.cwd,
|
|
32165
|
+
hit: null,
|
|
32166
|
+
state: null,
|
|
32167
|
+
shell: null,
|
|
32168
|
+
risky: null,
|
|
32169
|
+
runs: false,
|
|
32170
|
+
words: []
|
|
32171
|
+
};
|
|
32172
|
+
scanCommand(command, dialect, 0, scan);
|
|
32173
|
+
if (scan.hit)
|
|
32174
|
+
return scan.hit;
|
|
32175
|
+
if (scan.state)
|
|
32176
|
+
return scan.state;
|
|
32177
|
+
if (scan.shell && (scan.runs || mayBeWorkit(scan.words, scan.cwd)))
|
|
32178
|
+
return scan.shell;
|
|
32179
|
+
return scan.runs ? scan.risky : null;
|
|
32180
|
+
};
|
|
32181
|
+
var identityEnvDeny = (change) => {
|
|
32182
|
+
if (change === UNREADABLE || IDENTITY_ANY.test(change) || !STATE_ANY.test(change))
|
|
32183
|
+
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).`;
|
|
32184
|
+
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}.`;
|
|
32185
|
+
};
|
|
32186
|
+
|
|
32187
|
+
// packages/workit-core/src/hooks/exit-pipe.ts
|
|
32188
|
+
var EXIT_VERBS = [
|
|
32189
|
+
["ci", "wait"],
|
|
32190
|
+
["check"],
|
|
32191
|
+
["pr", "merge"],
|
|
32192
|
+
["release"],
|
|
32193
|
+
["verify-delivery"]
|
|
32194
|
+
];
|
|
32195
|
+
var base3 = (word = "") => word.split(/[\\/]/u).at(-1) ?? "";
|
|
32196
|
+
var verbPath = (words) => {
|
|
32197
|
+
const path = [];
|
|
32198
|
+
for (let at = 0;at < words.length && path.length < 2; at += 1) {
|
|
32199
|
+
const word = words[at];
|
|
32200
|
+
if (word === "--")
|
|
32201
|
+
break;
|
|
32202
|
+
if (word === "--cwd")
|
|
32203
|
+
at += 1;
|
|
32204
|
+
else if (!word.startsWith("-"))
|
|
32205
|
+
path.push(word);
|
|
32206
|
+
}
|
|
32207
|
+
return path;
|
|
32208
|
+
};
|
|
32209
|
+
var identityAssignment = (name) => identityEnvChange(`${name}=x workit`) !== null;
|
|
32210
|
+
var identityWhy = (names) => names.length ? `
|
|
32211
|
+
Why: the retry leaves out ${names.join(", ")}: the identity guard refuses a workit call that sets ${names.length === 1 ? "it" : "them"}.` : "";
|
|
32212
|
+
var exitCall = (segment, first) => {
|
|
32213
|
+
const { words } = segment;
|
|
32214
|
+
let at = first;
|
|
32215
|
+
while (at < words.length && /^[A-Za-z_]\w*=/u.test(words[at]))
|
|
32216
|
+
at += 1;
|
|
32217
|
+
if (!/^workit(?:-cli)?$/u.test(base3(words[at])))
|
|
32218
|
+
return null;
|
|
32219
|
+
const path = verbPath(words.slice(at + 1));
|
|
32220
|
+
return EXIT_VERBS.some((verb) => verb.every((word, index) => path[index] === word)) ? { segment, first, at } : null;
|
|
32221
|
+
};
|
|
32222
|
+
var backgrounded = (command, segment) => {
|
|
32223
|
+
const ends = [...segment.spans ?? [], ...segment.redirectSpans ?? []].map(([, end]) => end);
|
|
32224
|
+
return /^[ \t]*&(?![&>])/u.test(command.slice(Math.max(0, ...ends)));
|
|
32225
|
+
};
|
|
32226
|
+
var setsPipefail = (words) => words[0] === "set" && words.some((word, at) => word === "pipefail" && /^-[a-z]*o$/u.test(words[at - 1] ?? ""));
|
|
32227
|
+
var range = (from, to) => Array.from({ length: to - from }, (_, i) => from + i);
|
|
32228
|
+
var absoluteCwd = (text, value) => cwdIndependent(text) && (/^(?:\/|[A-Za-z]:[\\/])/u.test(value) || /^~(?:\/|$)/u.test(text));
|
|
32229
|
+
var retryOf = (command, found) => {
|
|
32230
|
+
const { segment, first, at, cd, set } = found;
|
|
32231
|
+
const { words } = segment;
|
|
32232
|
+
const dropped = [];
|
|
32233
|
+
const env = range(first, at).filter((index) => {
|
|
32234
|
+
const name = words[index].slice(0, words[index].indexOf("="));
|
|
32235
|
+
if (!identityAssignment(name))
|
|
32236
|
+
return true;
|
|
32237
|
+
dropped.push(name);
|
|
32238
|
+
return false;
|
|
32239
|
+
});
|
|
32240
|
+
const envText = writtenWords(command, segment, env);
|
|
32241
|
+
const callText = writtenWords(command, segment, range(at + 1, words.length));
|
|
32242
|
+
const dir = cd ? writtenWord(command, cd, 1) : "";
|
|
32243
|
+
if (!envText || !callText || cd === undefined || dir === null)
|
|
32244
|
+
return { retry: null, dropped };
|
|
32245
|
+
const reads = [dir, ...envText, ...callText].flatMap((text) => [...text.matchAll(/\$\{?(\w+)/gu)].map((match) => match[1] ?? "")).find((name) => set.has(name));
|
|
32246
|
+
if (reads)
|
|
32247
|
+
return { retry: null, dropped, reads };
|
|
32248
|
+
const call = words.slice(at + 1);
|
|
32249
|
+
const verbAt = call[0]?.startsWith("-") ? 0 : 1;
|
|
32250
|
+
const plain = (body) => [...envText, "workit", ...body].join(" ");
|
|
32251
|
+
if (!cd)
|
|
32252
|
+
return { retry: plain(callText), dropped };
|
|
32253
|
+
const check = verbPath(call)[0] === "check";
|
|
32254
|
+
const cwds = range(at + 1, words.length).filter((index) => words.slice(at + 1, index).every((word) => word !== "--") && (words[index - 1] === "--cwd" || words[index].startsWith("--cwd=")));
|
|
32255
|
+
const moves = certainDir(dir, cd.words[1] ?? "") && env.every((index, n) => cwdFreeAssignment(envText[n] ?? "", words[index])) && callText.every((text) => cwdIndependent(text)) && (!call.includes("--") || callText.includes("--") && cwdFreeTail(callText.slice(callText.indexOf("--") + 1), check)) && cwds.every((index) => {
|
|
32256
|
+
const text = writtenWord(command, segment, index) ?? "";
|
|
32257
|
+
return absoluteCwd(text.replace(/^--cwd=/u, ""), words[index].replace(/^--cwd=/u, ""));
|
|
32258
|
+
});
|
|
32259
|
+
if (!moves)
|
|
32260
|
+
return { retry: `cd ${dir} && ${plain(callText)}`, dropped };
|
|
32261
|
+
if (cwds.length)
|
|
32262
|
+
return { retry: plain(callText), dropped };
|
|
32263
|
+
return {
|
|
32264
|
+
retry: plain([...callText.slice(0, verbAt), "--cwd", dir, ...callText.slice(verbAt)]),
|
|
32265
|
+
dropped
|
|
32266
|
+
};
|
|
32267
|
+
};
|
|
32268
|
+
function exitPipeGate(command, dialect = "posix") {
|
|
32269
|
+
if (!/\bworkit/u.test(command) || !/\b(?:tail|head)\b/u.test(command))
|
|
32270
|
+
return null;
|
|
32271
|
+
const groups = [];
|
|
32272
|
+
let carry = null;
|
|
32273
|
+
let pipefail = false;
|
|
32274
|
+
let cd = null;
|
|
32275
|
+
const seen = [];
|
|
32276
|
+
const chained = !command.includes("||");
|
|
32277
|
+
for (const segment of segmentsOf(command, dialect, { spans: true })) {
|
|
32278
|
+
if (segment.unanalyzable)
|
|
32279
|
+
return null;
|
|
32280
|
+
let words = segment.words;
|
|
32281
|
+
let closes = segment.group === "close";
|
|
32282
|
+
if (segment.group === "open") {
|
|
32283
|
+
groups.push(null);
|
|
32284
|
+
continue;
|
|
32285
|
+
}
|
|
32286
|
+
if (words[0] === "{") {
|
|
32287
|
+
groups.push(null);
|
|
32288
|
+
words = words.slice(1);
|
|
32289
|
+
} else if (words[0] === "}") {
|
|
32290
|
+
closes = true;
|
|
32291
|
+
words = words.slice(1);
|
|
32292
|
+
}
|
|
32293
|
+
if (closes) {
|
|
32294
|
+
const inner = groups.pop() ?? null;
|
|
32295
|
+
if (segment.group === "close" && cd)
|
|
32296
|
+
cd = undefined;
|
|
32297
|
+
if (inner && groups.length)
|
|
32298
|
+
groups[groups.length - 1] = inner;
|
|
32299
|
+
carry = segment.pipe ? inner ?? carry : null;
|
|
32300
|
+
continue;
|
|
32301
|
+
}
|
|
32302
|
+
if (!words.length && !segment.stdin && !segment.subs)
|
|
32303
|
+
continue;
|
|
32304
|
+
if (setsPipefail(words))
|
|
32305
|
+
pipefail = true;
|
|
32306
|
+
const filter = base3(words[0]);
|
|
32307
|
+
if (carry && !pipefail && (filter === "tail" || filter === "head")) {
|
|
32308
|
+
const { retry, dropped, reads } = retryOf(command, carry);
|
|
32309
|
+
const verb = verbPath(carry.segment.words.slice(carry.at + 1)).join(" ");
|
|
32310
|
+
const why = reads ? `Why: an earlier step sets $${reads}, which the call reads: run the same command without the \`| ${filter}\`, that step kept.` : `Why: run the same call without the \`| ${filter}\`, its words as you wrote them.`;
|
|
32311
|
+
return {
|
|
32312
|
+
kind: "deny",
|
|
32313
|
+
reason: `workit exit-pipe: piping \`workit ${verb}\` into ${filter} hides its exit code.
|
|
32314
|
+
${retry ? `Retry as: ${retry}` : why}${identityWhy(dropped)}`,
|
|
32315
|
+
unblock: retry
|
|
32316
|
+
};
|
|
32317
|
+
}
|
|
32318
|
+
const call = exitCall(segment, segment.words.length - words.length);
|
|
32319
|
+
const found = call ? { ...call, cd, set: namesSet(seen) } : null;
|
|
32320
|
+
seen.push(segment);
|
|
32321
|
+
if (found && groups.length)
|
|
32322
|
+
groups[groups.length - 1] = found;
|
|
32323
|
+
carry = segment.pipe ? found ?? carry : null;
|
|
32324
|
+
const clean = chained && words === segment.words && words.length === 2 && !segment.pipe && !backgrounded(command, segment);
|
|
32325
|
+
if (words[0] === "cd")
|
|
32326
|
+
cd = clean && cd === null ? segment : undefined;
|
|
32327
|
+
else if (cd)
|
|
32328
|
+
cd = undefined;
|
|
32329
|
+
}
|
|
32330
|
+
return null;
|
|
32331
|
+
}
|
|
32332
|
+
|
|
32333
|
+
// packages/workit-core/src/hooks/worktree-confine.ts
|
|
32334
|
+
var FANOUT_TOKEN_FILE = "workit-fanout-token";
|
|
32335
|
+
var NONE5 = { kind: "none" };
|
|
32336
|
+
var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
|
|
32337
|
+
var realOf = (file) => {
|
|
32338
|
+
let rest = "";
|
|
32339
|
+
for (let dir = file;; dir = path51.dirname(dir)) {
|
|
32340
|
+
try {
|
|
32341
|
+
return path51.join(fs31.realpathSync.native(dir), rest);
|
|
32342
|
+
} catch {
|
|
32343
|
+
if (path51.dirname(dir) === dir)
|
|
32344
|
+
return file;
|
|
32345
|
+
rest = rest ? path51.join(path51.basename(dir), rest) : path51.basename(dir);
|
|
32346
|
+
}
|
|
32347
|
+
}
|
|
32348
|
+
};
|
|
32349
|
+
var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
|
|
32350
|
+
const start = path51.isAbsolute(file) ? file : `${process.cwd()}${path51.sep}${file}`;
|
|
32351
|
+
const { root } = path51.parse(start);
|
|
32352
|
+
let at = root;
|
|
32353
|
+
let missing = false;
|
|
32354
|
+
for (const part of start.slice(root.length).split(/[\\/]+/)) {
|
|
32355
|
+
if (part === "" || part === ".")
|
|
32356
|
+
continue;
|
|
32357
|
+
if (part === "..") {
|
|
32358
|
+
at = path51.dirname(at);
|
|
32359
|
+
continue;
|
|
32360
|
+
}
|
|
32361
|
+
const next = path51.join(at, part);
|
|
32362
|
+
let link = null;
|
|
32363
|
+
if (!missing)
|
|
32364
|
+
try {
|
|
32365
|
+
link = fs31.readlinkSync(next);
|
|
32366
|
+
} catch (error) {
|
|
32367
|
+
missing = error.code !== "EINVAL";
|
|
32368
|
+
}
|
|
32369
|
+
if (link === null) {
|
|
32370
|
+
at = next;
|
|
32371
|
+
hops.chain = 40;
|
|
32372
|
+
} else if (hops.chain-- > 0 && hops.total-- > 0)
|
|
32373
|
+
at = canonical6(path51.isAbsolute(link) ? link : `${at}${path51.sep}${link}`, hops);
|
|
32374
|
+
else
|
|
32375
|
+
return path51.resolve(file);
|
|
32376
|
+
}
|
|
32377
|
+
return realOf(at);
|
|
32378
|
+
};
|
|
32379
|
+
var within = (child, parent) => {
|
|
32380
|
+
const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
|
|
32381
|
+
const relative = path51.relative(fold(parent), fold(child));
|
|
32382
|
+
return relative === "" || !relative.startsWith("..") && !path51.isAbsolute(relative);
|
|
32383
|
+
};
|
|
32384
|
+
var checkoutOf3 = (file) => {
|
|
32385
|
+
for (let dir = canonical6(file);; dir = path51.dirname(dir)) {
|
|
32386
|
+
const dotGit = path51.join(dir, ".git");
|
|
32387
|
+
if (fs31.existsSync(dotGit)) {
|
|
32388
|
+
const admin = fs31.statSync(dotGit).isFile() ? gitDirsAt(dir, null, false)?.[0] : undefined;
|
|
32389
|
+
return { root: dir, workit: !!admin && fs31.existsSync(path51.join(admin, FANOUT_TOKEN_FILE)) };
|
|
32390
|
+
}
|
|
32391
|
+
if (path51.dirname(dir) === dir)
|
|
32392
|
+
return null;
|
|
32393
|
+
}
|
|
32394
|
+
};
|
|
32395
|
+
var workitWorktreeOf = (file) => {
|
|
32396
|
+
try {
|
|
32397
|
+
const checkout = checkoutOf3(file);
|
|
32398
|
+
return checkout?.workit ? checkout.root : null;
|
|
32399
|
+
} catch {
|
|
32400
|
+
return null;
|
|
32401
|
+
}
|
|
32402
|
+
};
|
|
32403
|
+
var bindingDir = () => path51.join(resolveStateDir(), "worktree-bind");
|
|
32404
|
+
var bindingFile = (session, agentId) => path51.join(bindingDir(), `${createHash23("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
|
|
32405
|
+
var readBinding = (file) => {
|
|
31619
32406
|
try {
|
|
31620
|
-
const value = JSON.parse(
|
|
32407
|
+
const value = JSON.parse(fs31.readFileSync(file, "utf8"));
|
|
31621
32408
|
return typeof value.worktree === "string" ? value : null;
|
|
31622
32409
|
} catch {
|
|
31623
32410
|
return null;
|
|
@@ -31639,8 +32426,8 @@ var bind = (input, worktree) => {
|
|
|
31639
32426
|
agentId,
|
|
31640
32427
|
at: new Date().toISOString()
|
|
31641
32428
|
};
|
|
31642
|
-
|
|
31643
|
-
|
|
32429
|
+
fs31.mkdirSync(path51.dirname(file), { recursive: true });
|
|
32430
|
+
fs31.writeFileSync(file, JSON.stringify(binding));
|
|
31644
32431
|
try {
|
|
31645
32432
|
if (inWorkitWorkspace(input.cwd))
|
|
31646
32433
|
appendHookObserved(input.cwd, {
|
|
@@ -31658,42 +32445,117 @@ var hostIsolated = (cwd, agentId) => {
|
|
|
31658
32445
|
const checkout = checkoutOf3(cwd);
|
|
31659
32446
|
if (!checkout)
|
|
31660
32447
|
return false;
|
|
31661
|
-
const dotGit =
|
|
31662
|
-
if (!
|
|
32448
|
+
const dotGit = path51.join(checkout.root, ".git");
|
|
32449
|
+
if (!fs31.statSync(dotGit).isFile())
|
|
31663
32450
|
return false;
|
|
31664
32451
|
const [adminDir, gitDir] = gitDirsAt(checkout.root, null, false) ?? [];
|
|
31665
|
-
const back =
|
|
31666
|
-
if (
|
|
32452
|
+
const back = fs31.readFileSync(path51.join(adminDir, "gitdir"), "utf8").trim();
|
|
32453
|
+
if (path51.relative(canonical6(path51.resolve(adminDir, back)), canonical6(dotGit)) !== "")
|
|
31667
32454
|
return false;
|
|
31668
|
-
const expected =
|
|
31669
|
-
return
|
|
32455
|
+
const expected = path51.join(path51.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
|
|
32456
|
+
return path51.relative(canonical6(expected), checkout.root) === "";
|
|
31670
32457
|
} catch {
|
|
31671
32458
|
return false;
|
|
31672
32459
|
}
|
|
31673
32460
|
};
|
|
31674
32461
|
var runnerAt = (target) => {
|
|
31675
|
-
const base =
|
|
32462
|
+
const base = path51.basename(target);
|
|
31676
32463
|
return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
|
|
31677
32464
|
};
|
|
31678
32465
|
var shown = (target) => {
|
|
31679
|
-
const named = /^\.workit-(?:live-target$|runs-)/.test(
|
|
31680
|
-
return
|
|
32466
|
+
const named = /^\.workit-(?:live-target$|runs-)/.test(path51.basename(target)) ? path51.dirname(target) : target;
|
|
32467
|
+
return path51.sep === "\\" ? named.replaceAll("/", "\\") : named;
|
|
32468
|
+
};
|
|
32469
|
+
var plainWorkitCall = (command, dialect) => {
|
|
32470
|
+
if (dialect !== "posix")
|
|
32471
|
+
return null;
|
|
32472
|
+
const segments = segmentsOf(command, dialect, { spans: true });
|
|
32473
|
+
const [only] = segments;
|
|
32474
|
+
if (segments.length !== 1 || !only || only.unanalyzable || only.group || only.pipe)
|
|
32475
|
+
return null;
|
|
32476
|
+
if (only.redirects.length || only.subs?.length || only.stdin?.length || only.inputs?.length)
|
|
32477
|
+
return null;
|
|
32478
|
+
const { words } = only;
|
|
32479
|
+
let at = 0;
|
|
32480
|
+
while (at < words.length && /^[A-Za-z_]\w*=/.test(words[at]))
|
|
32481
|
+
at++;
|
|
32482
|
+
if (words[at] !== "workit" || (only.expands ?? []).some((index) => index >= at))
|
|
32483
|
+
return null;
|
|
32484
|
+
return { segment: only, at, cwd: skipWorkitGlobals(words.slice(at + 1)).cwd };
|
|
32485
|
+
};
|
|
32486
|
+
var workitCallDir = (command, dialect) => {
|
|
32487
|
+
const call = plainWorkitCall(command, dialect);
|
|
32488
|
+
return call?.cwd && path51.isAbsolute(call.cwd) ? call.cwd : null;
|
|
32489
|
+
};
|
|
32490
|
+
var shellWord = (dir) => /^[\w@%+=:,./-]+$/u.test(dir) ? dir : `'${dir.replaceAll("'", `'\\''`)}'`;
|
|
32491
|
+
var cwdAt = (words, index) => words[index] === "--cwd" && words[index + 1] !== undefined ? 2 : words[index]?.startsWith("--cwd=") ? 1 : 0;
|
|
32492
|
+
var plainRetry = (dir, command) => {
|
|
32493
|
+
const call = plainWorkitCall(command, "posix");
|
|
32494
|
+
if (!call)
|
|
32495
|
+
return null;
|
|
32496
|
+
const { segment, at } = call;
|
|
32497
|
+
const { words } = segment;
|
|
32498
|
+
const dropped = [];
|
|
32499
|
+
const env = [];
|
|
32500
|
+
for (let index = 0;index < at; index++) {
|
|
32501
|
+
const name = words[index].slice(0, words[index].indexOf("="));
|
|
32502
|
+
if (identityAssignment(name))
|
|
32503
|
+
dropped.push(name);
|
|
32504
|
+
else
|
|
32505
|
+
env.push(index);
|
|
32506
|
+
}
|
|
32507
|
+
const globals = [];
|
|
32508
|
+
let index = at + 1;
|
|
32509
|
+
for (;index < words.length; index++) {
|
|
32510
|
+
const skip = cwdAt(words, index);
|
|
32511
|
+
if (skip)
|
|
32512
|
+
index += skip - 1;
|
|
32513
|
+
else if (/^--(?:session|token|as)$/u.test(words[index]) && words[index + 1] !== undefined)
|
|
32514
|
+
globals.push(index, ++index);
|
|
32515
|
+
else if (/^--(?:session|token|as)=|^--json$/u.test(words[index]))
|
|
32516
|
+
globals.push(index);
|
|
32517
|
+
else
|
|
32518
|
+
break;
|
|
32519
|
+
}
|
|
32520
|
+
const verb = index;
|
|
32521
|
+
const rest = [];
|
|
32522
|
+
for (index += 1;index < words.length; index++) {
|
|
32523
|
+
if (words[index] === "--") {
|
|
32524
|
+
for (;index < words.length; index++)
|
|
32525
|
+
rest.push(index);
|
|
32526
|
+
break;
|
|
32527
|
+
}
|
|
32528
|
+
const skip = cwdAt(words, index);
|
|
32529
|
+
if (skip)
|
|
32530
|
+
index += skip - 1;
|
|
32531
|
+
else
|
|
32532
|
+
rest.push(index);
|
|
32533
|
+
}
|
|
32534
|
+
const text = (indexes) => writtenWords(command, segment, indexes);
|
|
32535
|
+
const parts = [text(env), text(globals), text(verb < words.length ? [verb] : []), text(rest)];
|
|
32536
|
+
if (parts.includes(null))
|
|
32537
|
+
return null;
|
|
32538
|
+
const [envText, globalText, verbText, restText] = parts;
|
|
32539
|
+
const cwd = ["--cwd", shellWord(dir)];
|
|
32540
|
+
const body = [...globalText, ...verbText, ...cwd, ...restText];
|
|
32541
|
+
return { retry: [...envText, "workit", ...body].join(" "), dropped };
|
|
31681
32542
|
};
|
|
31682
32543
|
var runFrom = (dir, command) => `cd ${dir} && ${command.replace(/^\s*cd\s+\S+\s*(?:&&|;)\s*/, "")}`;
|
|
31683
|
-
var deny2 = (what, unblock) => ({
|
|
32544
|
+
var deny2 = (what, unblock, note = "") => ({
|
|
31684
32545
|
kind: "deny",
|
|
31685
32546
|
reason: `${what}.
|
|
31686
|
-
${unblock}`,
|
|
32547
|
+
${unblock}${note}`,
|
|
31687
32548
|
unblock
|
|
31688
32549
|
});
|
|
31689
32550
|
var unboundDeny = (input, target) => deny2(`workit worktree confinement: implementer ${input.session.agentId} is not working in a Workit worktree yet, and ${shown(target)} is outside every one`, "Why: work only in your brief's worktree (`workit fanout worktree create <slice>`); with none, tell the lead.");
|
|
31690
32551
|
var outsideDeny = (input, worktree, target, command) => {
|
|
31691
32552
|
const runner = runnerAt(target);
|
|
31692
|
-
|
|
32553
|
+
const plain = runner !== null && command ? plainRetry(worktree, command) : null;
|
|
32554
|
+
return deny2(`workit worktree confinement: implementer ${input.session.agentId} is bound to the worktree ${worktree}, and ${runner === null ? `${shown(target)} is` : `\`${runner}\` runs in ${shown(target)},`} outside it`, runner !== null && command ? `Retry as: ${plain?.retry ?? runFrom(worktree, command)}` : `Why: edit only under ${worktree}, git one verb per call (\`workit git --cwd ${worktree} commit -m … -- <paths>\`); the rest is a follow-up.`, identityWhy(plain?.dropped ?? []));
|
|
31693
32555
|
};
|
|
31694
32556
|
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\`.`);
|
|
31695
32557
|
var refsOf = (targets) => [
|
|
31696
|
-
...new Set(targets.flatMap((target) =>
|
|
32558
|
+
...new Set(targets.flatMap((target) => path51.relative(UNKNOWN_VAR, path51.resolve(target)).split(path51.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
|
|
31697
32559
|
];
|
|
31698
32560
|
var literalForm = (command, refs) => {
|
|
31699
32561
|
let text = command;
|
|
@@ -31726,10 +32588,10 @@ function confineImplementer(input, targets, command) {
|
|
|
31726
32588
|
try {
|
|
31727
32589
|
if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
|
|
31728
32590
|
return NONE5;
|
|
31729
|
-
const unresolved = targets.filter((target) => within(
|
|
32591
|
+
const unresolved = targets.filter((target) => within(path51.resolve(target), UNKNOWN_VAR));
|
|
31730
32592
|
if (unresolved.length > 0)
|
|
31731
32593
|
return unknownVarDeny(input, unresolved, command);
|
|
31732
|
-
if (targets.some((target) => within(
|
|
32594
|
+
if (targets.some((target) => within(path51.resolve(target), UNKNOWN_DIR)))
|
|
31733
32595
|
return unknownDirDeny(input, boundWorktree(input));
|
|
31734
32596
|
const bindings = canonical6(bindingDir());
|
|
31735
32597
|
const judged = targets.map((named) => ({ named, real: canonical6(named) })).filter(({ real }) => within(real, bindings) || checkoutOf3(real) !== null);
|
|
@@ -31821,7 +32683,7 @@ function confineImplementerShell(input, command, dialect = "posix") {
|
|
|
31821
32683
|
if (rawInvocations(command, dialect).some((invocation) => invocation.tool === "git" && leadOwnedGit(invocation.args)) || workitInvocations(command, dialect).some(leadOwnedWorkit))
|
|
31822
32684
|
return leadOwnedDeny(input, command);
|
|
31823
32685
|
} catch {}
|
|
31824
|
-
return confineImplementer(input, shellMutationTargets(input.cwd, command, dialect, true), command);
|
|
32686
|
+
return confineImplementer(input, shellMutationTargets(workitCallDir(command, dialect) ?? input.cwd, command, dialect, true), command);
|
|
31825
32687
|
}
|
|
31826
32688
|
var LITERAL_SET = /^\s*([A-Za-z_]\w*)=(['"]?)((?:[\w@%+=:./\\-]|(?<=[^\s:=])~)*)\2[ \t]*(?:;|&&|\n)\s*/;
|
|
31827
32689
|
var SPELLED = /^(?:[A-Za-z]|wt|wd|dir|repo|root|base|sha|ref|branch|file|out|scratch|worktree|WT|WD|DIR|REPO|ROOT|BASE|SHA|REF|BRANCH|FILE|OUT|SCRATCH|WORKTREE)$/;
|
|
@@ -31836,10 +32698,10 @@ var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print)(?:=|$)|^--(?:test|version|he
|
|
|
31836
32698
|
var VALUED2 = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
|
|
31837
32699
|
var commonDir = (root) => gitDirsAt(root, null, false)?.[1] ?? "";
|
|
31838
32700
|
var inScratch = (real, repo) => {
|
|
31839
|
-
for (let dir = real;
|
|
31840
|
-
if (
|
|
32701
|
+
for (let dir = real;path51.dirname(dir) !== dir; dir = path51.dirname(dir)) {
|
|
32702
|
+
if (path51.basename(dir) !== SCRATCH)
|
|
31841
32703
|
continue;
|
|
31842
|
-
const root =
|
|
32704
|
+
const root = path51.dirname(dir);
|
|
31843
32705
|
const checkout = checkoutOf3(root);
|
|
31844
32706
|
if (checkout?.root === root && (repo === null || checkout.workit || commonDir(root) === repo))
|
|
31845
32707
|
return true;
|
|
@@ -31849,7 +32711,7 @@ var inScratch = (real, repo) => {
|
|
|
31849
32711
|
var inGitDir = (real) => real.split(/[\\/]/).includes(".git");
|
|
31850
32712
|
var SAFE_KEY = /^(?:core\.(?:repositoryformatversion|filemode|bare|logallrefupdates|ignorecase|precomposeunicode|symlinks)|user\..*|init\.defaultbranch|commit\.gpgsign|extensions\.(?:objectformat|refstorage)|branch\..*\.(?:remote|merge)|remote\..*\.fetch)$/;
|
|
31851
32713
|
var literalIn = (value, repo, checkout = false) => {
|
|
31852
|
-
if (/[$`]/.test(value) || !
|
|
32714
|
+
if (/[$`]/.test(value) || !path51.isAbsolute(value))
|
|
31853
32715
|
return false;
|
|
31854
32716
|
const real = canonical6(value);
|
|
31855
32717
|
const root = checkout ? checkoutOf3(real)?.root : undefined;
|
|
@@ -31870,45 +32732,45 @@ var configEntries = (text) => {
|
|
|
31870
32732
|
return entries;
|
|
31871
32733
|
};
|
|
31872
32734
|
function gitDirsAt(dir, repo, scan = true) {
|
|
31873
|
-
for (let at = dir;; at =
|
|
31874
|
-
const dotGit =
|
|
32735
|
+
for (let at = dir;; at = path51.dirname(at)) {
|
|
32736
|
+
const dotGit = path51.join(at, ".git");
|
|
31875
32737
|
let gitDir = null;
|
|
31876
32738
|
try {
|
|
31877
|
-
if (
|
|
32739
|
+
if (fs31.statSync(dotGit).isDirectory())
|
|
31878
32740
|
gitDir = canonical6(dotGit);
|
|
31879
32741
|
else {
|
|
31880
|
-
const named = /^gitdir:\s*(.+?)\s*$/mu.exec(
|
|
32742
|
+
const named = /^gitdir:\s*(.+?)\s*$/mu.exec(fs31.readFileSync(dotGit, "utf8"))?.[1];
|
|
31881
32743
|
if (!named)
|
|
31882
32744
|
return null;
|
|
31883
|
-
gitDir = canonical6(
|
|
32745
|
+
gitDir = canonical6(path51.resolve(at, named));
|
|
31884
32746
|
}
|
|
31885
32747
|
} catch (error) {
|
|
31886
32748
|
if (error.code !== "ENOENT")
|
|
31887
32749
|
return null;
|
|
31888
|
-
if (["HEAD", "objects", "refs"].every((name) =>
|
|
32750
|
+
if (["HEAD", "objects", "refs"].every((name) => fs31.existsSync(path51.join(at, name))))
|
|
31889
32751
|
gitDir = canonical6(at);
|
|
31890
32752
|
}
|
|
31891
32753
|
if (gitDir !== null) {
|
|
31892
|
-
const common =
|
|
31893
|
-
const shared =
|
|
32754
|
+
const common = path51.join(gitDir, "commondir");
|
|
32755
|
+
const shared = fs31.existsSync(common) ? canonical6(path51.resolve(gitDir, fs31.readFileSync(common, "utf8").trim())) : gitDir;
|
|
31894
32756
|
const dirs = [gitDir, shared];
|
|
31895
|
-
for (const config of scan ? new Set([
|
|
32757
|
+
for (const config of scan ? new Set([path51.join(gitDir, "config"), path51.join(shared, "config")]) : []) {
|
|
31896
32758
|
let text = "";
|
|
31897
32759
|
try {
|
|
31898
|
-
text =
|
|
32760
|
+
text = fs31.readFileSync(config, "utf8");
|
|
31899
32761
|
} catch {
|
|
31900
32762
|
continue;
|
|
31901
32763
|
}
|
|
31902
32764
|
for (const [key, value] of configEntries(text)) {
|
|
31903
32765
|
if (key === "core.worktree")
|
|
31904
|
-
dirs.push(canonical6(
|
|
32766
|
+
dirs.push(canonical6(path51.resolve(gitDir, value)));
|
|
31905
32767
|
else if (/^remote\..*\.url$/.test(key) ? !literalIn(value, repo, true) : !SAFE_KEY.test(key))
|
|
31906
32768
|
return null;
|
|
31907
32769
|
}
|
|
31908
32770
|
}
|
|
31909
32771
|
return dirs;
|
|
31910
32772
|
}
|
|
31911
|
-
if (
|
|
32773
|
+
if (path51.dirname(at) === at)
|
|
31912
32774
|
return [];
|
|
31913
32775
|
}
|
|
31914
32776
|
}
|
|
@@ -32048,10 +32910,10 @@ var gitKind = (args, local = () => true) => {
|
|
|
32048
32910
|
return GIT_VERBS[verb].startsWith("+") ? "write" : "read";
|
|
32049
32911
|
};
|
|
32050
32912
|
var remoteIn = (dir, name, repo) => {
|
|
32051
|
-
const shared =
|
|
32913
|
+
const shared = path51.isAbsolute(dir) ? gitDirsAt(canonical6(dir), repo, false)?.[1] : undefined;
|
|
32052
32914
|
if (!shared)
|
|
32053
32915
|
return false;
|
|
32054
|
-
const url = configEntries(
|
|
32916
|
+
const url = configEntries(fs31.readFileSync(path51.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
|
|
32055
32917
|
return url !== undefined && literalIn(url, repo, true);
|
|
32056
32918
|
};
|
|
32057
32919
|
var judgeEnvAllowed = (word) => {
|
|
@@ -32080,7 +32942,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
32080
32942
|
at = after;
|
|
32081
32943
|
}
|
|
32082
32944
|
}
|
|
32083
|
-
const name =
|
|
32945
|
+
const name = path51.basename(words[at] ?? "");
|
|
32084
32946
|
let start = words.findIndex((word) => /(?:^|[\\/])git(?:\.exe)?(?:=|$)/.test(word));
|
|
32085
32947
|
if (start > at) {
|
|
32086
32948
|
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] ?? ""))
|
|
@@ -32091,7 +32953,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
32091
32953
|
if (start >= 0 && words[start].includes("="))
|
|
32092
32954
|
why = "git is redefined";
|
|
32093
32955
|
const run = words[start] ?? "";
|
|
32094
|
-
if (run.includes("/") && (!
|
|
32956
|
+
if (run.includes("/") && (!path51.isAbsolute(run) || literalIn(run, repo, true)))
|
|
32095
32957
|
why ??= `\`${run}\` is not the system git`;
|
|
32096
32958
|
if (segment.expands?.includes(at) && name !== "[" || /\{[^}]*,/.test(words[at] ?? ""))
|
|
32097
32959
|
why = "the command's name is expanded by the shell";
|
|
@@ -32116,13 +32978,13 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
32116
32978
|
const args = words[index] === "--version" ? ["version"] : words.slice(index);
|
|
32117
32979
|
if (!why && start >= 0) {
|
|
32118
32980
|
const local = (source, remote) => remote && /^[\w-][\w.-]*$/.test(source) ? remoteIn(dir, source, repo) : literalIn(source, repo, true);
|
|
32119
|
-
const runsIn =
|
|
32981
|
+
const runsIn = path51.isAbsolute(dir) ? dir : cwd && path51.resolve(cwd, dir);
|
|
32120
32982
|
const home = runsIn && checkoutOf3(runsIn);
|
|
32121
32983
|
const fetches = args[0] === "fetch" && plainFetch(args.slice(1)) && home && (home.workit || commonDir(home.root) === repo) && !words.some((word) => /^--[gw]/.test(word));
|
|
32122
32984
|
if (!fetches && !gitKind(args, local))
|
|
32123
32985
|
why = `\`git ${args.slice(0, 2).join(" ")}\` is not allowed`;
|
|
32124
32986
|
}
|
|
32125
|
-
const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(
|
|
32987
|
+
const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path51.basename(word)));
|
|
32126
32988
|
const scripts = [
|
|
32127
32989
|
...words.filter((_, after) => shell >= 0 && after > shell && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(words[after - 1])),
|
|
32128
32990
|
...shell < 0 ? [] : segment.stdin ?? []
|
|
@@ -32167,7 +33029,7 @@ var judgeVerbRefused = (args) => {
|
|
|
32167
33029
|
var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
|
|
32168
33030
|
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?$/;
|
|
32169
33031
|
var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
|
|
32170
|
-
const name =
|
|
33032
|
+
const name = path51.basename(words[0] ?? "").toLowerCase();
|
|
32171
33033
|
if (name === "alias")
|
|
32172
33034
|
return words.flatMap((word) => {
|
|
32173
33035
|
const set = /^([\w-]+)=(.*)$/s.exec(word);
|
|
@@ -32196,11 +33058,11 @@ var judgeRefusal = (command, fed, depth = 0) => {
|
|
|
32196
33058
|
return why;
|
|
32197
33059
|
}
|
|
32198
33060
|
const { words } = segment;
|
|
32199
|
-
const runs = (word = "") => RUNS.test(
|
|
33061
|
+
const runs = (word = "") => RUNS.test(path51.basename(word).toLowerCase());
|
|
32200
33062
|
let at = 0;
|
|
32201
33063
|
while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
|
|
32202
33064
|
at++;
|
|
32203
|
-
const name =
|
|
33065
|
+
const name = path51.basename(words[at] ?? "").toLowerCase();
|
|
32204
33066
|
const args = words.slice(at + 1);
|
|
32205
33067
|
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`;
|
|
32206
33068
|
if (/^(?:cd|chdir|pushd|popd)$/.test(name))
|
|
@@ -32282,10 +33144,10 @@ var judgeDeny = (input, what, target, retry, why = "write only there (mkdir -p i
|
|
|
32282
33144
|
const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
|
|
32283
33145
|
const root = checkoutOf3(input.cwd)?.root;
|
|
32284
33146
|
const candidate = target ? checkoutOf3(target)?.root : undefined;
|
|
32285
|
-
const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ?
|
|
32286
|
-
const scratch = root ? `${
|
|
32287
|
-
const call = root ? retry?.((other ??
|
|
32288
|
-
const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ?
|
|
33147
|
+
const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path51.join(candidate, SCRATCH) : undefined;
|
|
33148
|
+
const scratch = root ? `${path51.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
|
|
33149
|
+
const call = root ? retry?.((other ?? path51.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
|
|
33150
|
+
const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ? path51.join(root, SCRATCH) : SCRATCH))}`;
|
|
32289
33151
|
return {
|
|
32290
33152
|
kind: "deny",
|
|
32291
33153
|
reason: `workit scratch confinement: ${role} ${input.session.agentId} may write only in its scratch dir ${scratch}, and ${what}.
|
|
@@ -32295,9 +33157,9 @@ ${unblock}`,
|
|
|
32295
33157
|
};
|
|
32296
33158
|
var movedInto = (command, cwd, target, dir) => {
|
|
32297
33159
|
for (const { words, redirects } of segmentsOf(command))
|
|
32298
|
-
for (const word of [...redirects, ...
|
|
32299
|
-
if (
|
|
32300
|
-
const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${
|
|
33160
|
+
for (const word of [...redirects, ...path51.basename(words[0] ?? "") === "tee" ? words : []])
|
|
33161
|
+
if (path51.resolve(cwd, word) === path51.resolve(cwd, target)) {
|
|
33162
|
+
const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path51.basename(word)}`);
|
|
32301
33163
|
return moved === command ? null : moved;
|
|
32302
33164
|
}
|
|
32303
33165
|
return null;
|
|
@@ -32309,19 +33171,19 @@ function confineJudge(input, targets, placeholders = placeholdersOf(targets), co
|
|
|
32309
33171
|
const judged = checkoutOf3(input.cwd);
|
|
32310
33172
|
const repo = judged ? commonDir(judged.root) : null;
|
|
32311
33173
|
const scratch = (real) => inScratch(real, repo) || [os11.tmpdir(), "/tmp"].some((dir) => {
|
|
32312
|
-
const [host, , session] =
|
|
33174
|
+
const [host, , session] = path51.relative(canonical6(dir), real).split(path51.sep);
|
|
32313
33175
|
return /^claude-\d+$/.test(host) && session === input.session.id;
|
|
32314
33176
|
});
|
|
32315
33177
|
for (const target of targets) {
|
|
32316
|
-
const resolved =
|
|
33178
|
+
const resolved = path51.resolve(target);
|
|
32317
33179
|
if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
|
|
32318
33180
|
return judgeDeny(input, "it writes to a path Workit cannot resolve", undefined, () => {
|
|
32319
33181
|
const literal = command && literalForm(command, refsOf([target]));
|
|
32320
33182
|
return literal === command ? null : literal;
|
|
32321
33183
|
});
|
|
32322
33184
|
const real = canonical6(target);
|
|
32323
|
-
const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(
|
|
32324
|
-
const gitDirs = runsGit ? gitDirsAt(
|
|
33185
|
+
const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path51.basename(target));
|
|
33186
|
+
const gitDirs = runsGit ? gitDirsAt(path51.dirname(real), repo) : [];
|
|
32325
33187
|
if (gitDirs === null)
|
|
32326
33188
|
return judgeDeny(input, `git in ${shown(target)} uses a git dir or config Workit cannot check`);
|
|
32327
33189
|
if (runsGit ? gitDirs.length > 0 ? gitDirs.every(scratch) : scratch(real) : scratch(real) && !inGitDir(real))
|
|
@@ -32389,7 +33251,7 @@ function confineJudgeShell(input, command, dialect = "posix") {
|
|
|
32389
33251
|
let git = [];
|
|
32390
33252
|
try {
|
|
32391
33253
|
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)))) ? [
|
|
32392
|
-
|
|
33254
|
+
path51.join(dir === undefined ? UNKNOWN_DIR : path51.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
|
|
32393
33255
|
] : []);
|
|
32394
33256
|
} catch {}
|
|
32395
33257
|
const lists = [
|
|
@@ -32434,17 +33296,17 @@ var judgeChecksLine = (cwd) => {
|
|
|
32434
33296
|
|
|
32435
33297
|
// packages/workit-core/src/hooks/standing.ts
|
|
32436
33298
|
var readPlans = (store) => {
|
|
32437
|
-
const dir =
|
|
33299
|
+
const dir = path52.join(store, "fanouts");
|
|
32438
33300
|
let names;
|
|
32439
33301
|
try {
|
|
32440
|
-
names =
|
|
33302
|
+
names = fs32.readdirSync(dir).filter((name) => name.endsWith(".json"));
|
|
32441
33303
|
} catch {
|
|
32442
33304
|
return [];
|
|
32443
33305
|
}
|
|
32444
33306
|
const plans = [];
|
|
32445
33307
|
for (const name of names) {
|
|
32446
33308
|
try {
|
|
32447
|
-
const raw = JSON.parse(
|
|
33309
|
+
const raw = JSON.parse(fs32.readFileSync(path52.join(dir, name), "utf8"));
|
|
32448
33310
|
if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
|
|
32449
33311
|
continue;
|
|
32450
33312
|
const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
|
|
@@ -32566,100 +33428,14 @@ var standingDelta = (input) => {
|
|
|
32566
33428
|
}
|
|
32567
33429
|
};
|
|
32568
33430
|
var sinceStart = new Map;
|
|
32569
|
-
// packages/workit-core/src/hooks/cwd-normalize.ts
|
|
32570
|
-
var DIR2 = String.raw`(?:[A-Za-z0-9_./@%+:,=-]|(?<=[A-Za-z0-9])~)+|'[^'$${"`"}\n]*'|"(?:[^"$${"`"}\\!\n]|\\(?=[^"$${"`"}\\!\n]))*"`;
|
|
32571
|
-
var COMPOUND2 = new RegExp(String.raw`^\s*cd\s+(${DIR2})\s*&&\s*(workit(?:\s[\s\S]*)?)$`, "u");
|
|
32572
|
-
var GLOBALS_FIRST = new RegExp(String.raw`^(\s*workit)((?:\s+(?:--json|--cwd(?:=|\s+)(?:${DIR2})))+)\s+([a-z][a-z-]*)(?=\s|$)`, "u");
|
|
32573
|
-
var VERB_FIRST = /^((?:--json\s+)*)([a-z][a-z-]*)(?=\s|$)/u;
|
|
32574
|
-
var VERBS = new Set(WORKIT_ALLOWED_VERBS);
|
|
32575
|
-
var FILTERS = new Set(["tail", "head", "grep"]);
|
|
32576
|
-
var clean = (s) => !s.unanalyzable && !s.group && !s.subs?.length && !s.stdin?.length && !s.redirects.length;
|
|
32577
|
-
var stdinOnly = (words) => {
|
|
32578
|
-
const [name, ...args] = words;
|
|
32579
|
-
const operands = args.filter((w) => !w.startsWith("-"));
|
|
32580
|
-
if (name === "grep")
|
|
32581
|
-
return operands.length <= 1 && !args.some((w) => /^-[^-]*[rRf]|^--(recursive|file)/u.test(w));
|
|
32582
|
-
return operands.every((w) => /^\d+$/u.test(w)) && !args.some((w) => w.startsWith("--output"));
|
|
32583
|
-
};
|
|
32584
|
-
var cwdRewrite = (command) => {
|
|
32585
|
-
const match = COMPOUND2.exec(command);
|
|
32586
|
-
const dir = match?.[1];
|
|
32587
|
-
const rest = match?.[2];
|
|
32588
|
-
if (!dir || !rest || dir.startsWith("-"))
|
|
32589
|
-
return null;
|
|
32590
|
-
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "").replaceAll(/'[^']*'|"([^"\\]|\\.)*"/gu, "")))
|
|
32591
|
-
return null;
|
|
32592
|
-
const segments = segmentsOf(rest);
|
|
32593
|
-
const [head, ...filters] = segments;
|
|
32594
|
-
if (!head || head.words[0] !== "workit")
|
|
32595
|
-
return null;
|
|
32596
|
-
if (!segments.every(clean))
|
|
32597
|
-
return null;
|
|
32598
|
-
if (!segments.slice(0, -1).every((s) => s.pipe))
|
|
32599
|
-
return null;
|
|
32600
|
-
if (!filters.every((s) => FILTERS.has(s.words[0] ?? "") && stdinOnly(s.words)))
|
|
32601
|
-
return null;
|
|
32602
|
-
const at = head.words.indexOf("--cwd");
|
|
32603
|
-
if (at >= 0) {
|
|
32604
|
-
const bare = dir.replace(/^(['"])(.*)\1$/u, "$2");
|
|
32605
|
-
return bare[0] === "/" && head.words[at + 1] === bare ? rest : null;
|
|
32606
|
-
}
|
|
32607
|
-
if (head.words.some((w) => w.startsWith("--cwd=")))
|
|
32608
|
-
return null;
|
|
32609
|
-
const args = rest.slice("workit".length).trimStart();
|
|
32610
|
-
const verb = VERB_FIRST.exec(args);
|
|
32611
|
-
if (!verb?.[2] || !VERBS.has(verb[2]))
|
|
32612
|
-
return `workit --cwd ${dir} ${args}`.trimEnd();
|
|
32613
|
-
const json = verb[1] ? " --json" : "";
|
|
32614
|
-
return `workit ${verb[2]} --cwd ${dir}${json}${args.slice(verb[0].length)}`.trimEnd();
|
|
32615
|
-
};
|
|
32616
|
-
var verbFirst = (command) => {
|
|
32617
|
-
const match = GLOBALS_FIRST.exec(command);
|
|
32618
|
-
const [whole, lead, globals, verb] = match ?? [];
|
|
32619
|
-
if (!whole || !verb || !VERBS.has(verb) || !globals?.includes("--cwd"))
|
|
32620
|
-
return null;
|
|
32621
|
-
const segments = segmentsOf(command);
|
|
32622
|
-
if (segments.length !== 1 || !segments.every(clean))
|
|
32623
|
-
return null;
|
|
32624
|
-
return `${lead} ${verb}${globals}${command.slice(whole.length)}`;
|
|
32625
|
-
};
|
|
32626
|
-
var NPX = new RegExp(String.raw`^(\s*(?:cd\s+(?:${DIR2})\s*&&\s*)?)npx(?:\s+(?:-y|--yes))*\s+@workit-dev\/cli(?:@[\w.-]+)?(?=\s|$)`, "u");
|
|
32627
|
-
var npxWorkit = (command) => {
|
|
32628
|
-
const match = NPX.exec(command);
|
|
32629
|
-
if (!match)
|
|
32630
|
-
return null;
|
|
32631
|
-
const call = `${match[1]}workit${command.slice(match[0].length)}`;
|
|
32632
|
-
const left = segmentsOf(call).some((s) => s.unanalyzable || s.words.some((w) => /^(npx|@workit-dev\/cli(@\S*)?)$/u.test(w)));
|
|
32633
|
-
return left ? null : cwdRewrite(call) ?? verbFirst(call) ?? call;
|
|
32634
|
-
};
|
|
32635
|
-
var MUTATING_GIT2 = /^git( -\S+| -[Cc] \S+)* (commit|push|add|switch|checkout|merge|rebase|reset|cherry-pick|revert|branch .*(-[dDmM]|--delete|--move)\b|tag (?!-l\b|--list)|stash(?! (list|show)\b))/u;
|
|
32636
|
-
var cdWorkitSplit = (command) => {
|
|
32637
|
-
const match = COMPOUND2.exec(command);
|
|
32638
|
-
const dir = match?.[1];
|
|
32639
|
-
const rest = match?.[2];
|
|
32640
|
-
if (!dir || !rest || cwdRewrite(command) !== null)
|
|
32641
|
-
return null;
|
|
32642
|
-
const whole = segmentsOf(rest);
|
|
32643
|
-
const boundary = (head) => segmentsOf(head).every((s, at) => s.words.join("\x00") === whole[at]?.words.join("\x00"));
|
|
32644
|
-
for (const op of rest.matchAll(/\|\||;/gu)) {
|
|
32645
|
-
const head = rest.slice(0, op.index).trimEnd();
|
|
32646
|
-
const call = cwdRewrite(`cd ${dir} && ${head}`);
|
|
32647
|
-
if (!call || !boundary(head))
|
|
32648
|
-
continue;
|
|
32649
|
-
const next = segmentsOf(rest.slice(op.index + op[0].length))[0];
|
|
32650
|
-
return next && MUTATING_GIT2.test(next.words.join(" ")) ? call : null;
|
|
32651
|
-
}
|
|
32652
|
-
return null;
|
|
32653
|
-
};
|
|
32654
|
-
|
|
32655
33431
|
// packages/workit-core/src/hooks/spawn-gate.ts
|
|
32656
|
-
import
|
|
32657
|
-
import
|
|
33432
|
+
import fs33 from "node:fs";
|
|
33433
|
+
import path54 from "node:path";
|
|
32658
33434
|
|
|
32659
33435
|
// packages/workit-core/src/hooks/model-limit.ts
|
|
32660
33436
|
import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync8, readSync, statSync as statSync5 } from "node:fs";
|
|
32661
33437
|
import os12 from "node:os";
|
|
32662
|
-
import
|
|
33438
|
+
import path53 from "node:path";
|
|
32663
33439
|
var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
32664
33440
|
var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
32665
33441
|
var TIME_WORD = String.raw`(?:\d|(?:in|at|on|later|tomorrow|soon)\b|(?:${[...WEEKDAYS, ...MONTHS].join("|")})[a-z]*\b)`;
|
|
@@ -32857,17 +33633,17 @@ var firstPrompt = (file) => {
|
|
|
32857
33633
|
var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
|
|
32858
33634
|
var listDir = (dir) => {
|
|
32859
33635
|
try {
|
|
32860
|
-
return readdirSync8(dir).map((name) =>
|
|
33636
|
+
return readdirSync8(dir).map((name) => path53.join(dir, name));
|
|
32861
33637
|
} catch {
|
|
32862
33638
|
return [];
|
|
32863
33639
|
}
|
|
32864
33640
|
};
|
|
32865
33641
|
var SCAN_MS = 30 * 60000;
|
|
32866
33642
|
var scanClaudeTranscripts = (cwd, env, now = new Date) => {
|
|
32867
|
-
const projects =
|
|
32868
|
-
const project =
|
|
33643
|
+
const projects = path53.join(env.CLAUDE_CONFIG_DIR || path53.join(env.HOME || os12.homedir(), ".claude"), "projects");
|
|
33644
|
+
const project = path53.join(projects, claudeProjectSlug(cwd));
|
|
32869
33645
|
const notes = [];
|
|
32870
|
-
const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(
|
|
33646
|
+
const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path53.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
|
|
32871
33647
|
for (const { file, worker } of files)
|
|
32872
33648
|
try {
|
|
32873
33649
|
const stat = statSync5(file);
|
|
@@ -32882,7 +33658,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
|
|
|
32882
33658
|
if (!seen)
|
|
32883
33659
|
continue;
|
|
32884
33660
|
notes.push(worker ? redispatchNote(seen, {
|
|
32885
|
-
label: `worker ${
|
|
33661
|
+
label: `worker ${path53.basename(file, ".jsonl")}`,
|
|
32886
33662
|
prompt: firstPrompt(file)
|
|
32887
33663
|
}, 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.`);
|
|
32888
33664
|
} catch {}
|
|
@@ -32981,13 +33757,13 @@ var agentModelDecision = (cwd, tool, options = {}) => {
|
|
|
32981
33757
|
var MADE_WORKTREE = /^WORKTREE:[ \t]*(?!not made yet)\S(?![^\n]*not made yet)/mu;
|
|
32982
33758
|
var namesMade = (word) => {
|
|
32983
33759
|
try {
|
|
32984
|
-
const stat =
|
|
33760
|
+
const stat = fs33.statSync(word);
|
|
32985
33761
|
if (stat.isFile())
|
|
32986
|
-
return stat.size < 1e6 && MADE_WORKTREE.test(
|
|
32987
|
-
const dotGit =
|
|
32988
|
-
const link =
|
|
32989
|
-
const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(
|
|
32990
|
-
return !!admin &&
|
|
33762
|
+
return stat.size < 1e6 && MADE_WORKTREE.test(fs33.readFileSync(word, "utf8"));
|
|
33763
|
+
const dotGit = path54.join(word, ".git");
|
|
33764
|
+
const link = fs33.statSync(dotGit);
|
|
33765
|
+
const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(fs33.readFileSync(dotGit, "utf8"));
|
|
33766
|
+
return !!admin && fs33.existsSync(path54.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
|
|
32991
33767
|
} catch {
|
|
32992
33768
|
return false;
|
|
32993
33769
|
}
|
|
@@ -33032,9 +33808,9 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
|
|
|
33032
33808
|
};
|
|
33033
33809
|
|
|
33034
33810
|
// packages/workit-core/src/hooks/server-gate.ts
|
|
33035
|
-
import
|
|
33036
|
-
import
|
|
33037
|
-
var procNoticeFile = (env, session) =>
|
|
33811
|
+
import fs34 from "node:fs";
|
|
33812
|
+
import path55 from "node:path";
|
|
33813
|
+
var procNoticeFile = (env, session) => path55.join(stateDir(env), "procs", "notices", `${session.replace(/[^A-Za-z0-9_.@+-]/gu, "-").slice(0, 120) || "none"}.json`);
|
|
33038
33814
|
var mb = (bytes) => `${Math.round(Number(bytes) / 1048576)} MB`;
|
|
33039
33815
|
function takeProcNotice(session, env = process.env) {
|
|
33040
33816
|
if (!session)
|
|
@@ -33042,12 +33818,12 @@ function takeProcNotice(session, env = process.env) {
|
|
|
33042
33818
|
const file = procNoticeFile(env, session);
|
|
33043
33819
|
const taken = `${file}.${process.pid}.taken`;
|
|
33044
33820
|
try {
|
|
33045
|
-
|
|
33821
|
+
fs34.renameSync(file, taken);
|
|
33046
33822
|
} catch {
|
|
33047
33823
|
return null;
|
|
33048
33824
|
}
|
|
33049
33825
|
try {
|
|
33050
|
-
const { notices } = JSON.parse(
|
|
33826
|
+
const { notices } = JSON.parse(fs34.readFileSync(taken, "utf8"));
|
|
33051
33827
|
const lines = (Array.isArray(notices) ? notices : []).flatMap((notice) => {
|
|
33052
33828
|
if (!notice || typeof notice !== "object")
|
|
33053
33829
|
return [];
|
|
@@ -33064,29 +33840,29 @@ function takeProcNotice(session, env = process.env) {
|
|
|
33064
33840
|
return null;
|
|
33065
33841
|
} finally {
|
|
33066
33842
|
try {
|
|
33067
|
-
|
|
33843
|
+
fs34.rmSync(taken, { force: true });
|
|
33068
33844
|
} catch {}
|
|
33069
33845
|
}
|
|
33070
33846
|
}
|
|
33071
33847
|
|
|
33072
33848
|
// packages/workit-core/src/hooks/teardown.ts
|
|
33073
33849
|
import { spawn } from "node:child_process";
|
|
33074
|
-
import
|
|
33075
|
-
import
|
|
33850
|
+
import fs35 from "node:fs";
|
|
33851
|
+
import path57 from "node:path";
|
|
33076
33852
|
|
|
33077
33853
|
// packages/workit-core/src/core/cli-locate.ts
|
|
33078
33854
|
import { closeSync as closeSync5, existsSync as existsSync18, openSync as openSync5, readSync as readSync2 } from "node:fs";
|
|
33079
|
-
import
|
|
33855
|
+
import path56 from "node:path";
|
|
33080
33856
|
var LAUNCHER_MARKER = "workit-owned-launcher";
|
|
33081
33857
|
var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
|
|
33082
33858
|
var installRoot = (env, platform = process.platform) => {
|
|
33083
33859
|
if (env.WORKIT_INSTALL_ROOT)
|
|
33084
33860
|
return env.WORKIT_INSTALL_ROOT;
|
|
33085
33861
|
const data = dataDir(env, platform);
|
|
33086
|
-
return platform === "win32" ?
|
|
33862
|
+
return platform === "win32" ? path56.join(data, "install") : data;
|
|
33087
33863
|
};
|
|
33088
|
-
var ownedLauncherPath = (env, platform = process.platform) =>
|
|
33089
|
-
var ownedCurrentEntry = (env, platform = process.platform) =>
|
|
33864
|
+
var ownedLauncherPath = (env, platform = process.platform) => path56.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
|
|
33865
|
+
var ownedCurrentEntry = (env, platform = process.platform) => path56.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
|
|
33090
33866
|
var head = (file) => {
|
|
33091
33867
|
let fd;
|
|
33092
33868
|
try {
|
|
@@ -33113,7 +33889,7 @@ var locateWorkitCli = (options = {}) => {
|
|
|
33113
33889
|
source: "owned-launcher",
|
|
33114
33890
|
command: launcher,
|
|
33115
33891
|
args: [],
|
|
33116
|
-
binDir:
|
|
33892
|
+
binDir: path56.dirname(launcher)
|
|
33117
33893
|
};
|
|
33118
33894
|
const current = ownedCurrentEntry(env, platform);
|
|
33119
33895
|
if (exists(current))
|
|
@@ -33142,7 +33918,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
|
|
|
33142
33918
|
if (located.binDir) {
|
|
33143
33919
|
const key = pathKey(env);
|
|
33144
33920
|
const delimiter = platform === "win32" ? ";" : ":";
|
|
33145
|
-
const same = (dir) => platform === "win32" ?
|
|
33921
|
+
const same = (dir) => platform === "win32" ? path56.win32.normalize(dir).toLowerCase() === path56.win32.normalize(located.binDir).toLowerCase() : path56.posix.normalize(dir) === path56.posix.normalize(located.binDir);
|
|
33146
33922
|
const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
|
|
33147
33923
|
patch[key] = [located.binDir, ...rest].join(delimiter);
|
|
33148
33924
|
}
|
|
@@ -33166,9 +33942,9 @@ var ENDS = {
|
|
|
33166
33942
|
};
|
|
33167
33943
|
var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
|
|
33168
33944
|
var HOST_SESSION_VARS2 = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
|
|
33169
|
-
var teardownDir = (env) =>
|
|
33170
|
-
var teardownLog = (env) =>
|
|
33171
|
-
var reapStamp = (env) =>
|
|
33945
|
+
var teardownDir = (env) => path57.join(stateDir(env), "procs");
|
|
33946
|
+
var teardownLog = (env) => path57.join(teardownDir(env), "teardown.log");
|
|
33947
|
+
var reapStamp = (env) => path57.join(teardownDir(env), "reap-at-start.stamp");
|
|
33172
33948
|
function spawnDetached(request) {
|
|
33173
33949
|
try {
|
|
33174
33950
|
const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
|
|
@@ -33195,13 +33971,13 @@ var teardownDeps = {
|
|
|
33195
33971
|
var openLog = (env, args) => {
|
|
33196
33972
|
try {
|
|
33197
33973
|
const file = teardownLog(env);
|
|
33198
|
-
|
|
33974
|
+
fs35.mkdirSync(path57.dirname(file), { recursive: true });
|
|
33199
33975
|
let size = 0;
|
|
33200
33976
|
try {
|
|
33201
|
-
size =
|
|
33977
|
+
size = fs35.statSync(file).size;
|
|
33202
33978
|
} catch {}
|
|
33203
|
-
const fd =
|
|
33204
|
-
|
|
33979
|
+
const fd = fs35.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
|
|
33980
|
+
fs35.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
|
|
33205
33981
|
`);
|
|
33206
33982
|
return fd;
|
|
33207
33983
|
} catch {
|
|
@@ -33213,7 +33989,7 @@ function runCli(args, env) {
|
|
|
33213
33989
|
try {
|
|
33214
33990
|
const cli = locateWorkitCli({ env });
|
|
33215
33991
|
const cwd = teardownDir(env);
|
|
33216
|
-
|
|
33992
|
+
fs35.mkdirSync(cwd, { recursive: true });
|
|
33217
33993
|
log = openLog(env, args);
|
|
33218
33994
|
const started = teardownDeps.spawn({
|
|
33219
33995
|
command: cli.command,
|
|
@@ -33223,7 +33999,7 @@ function runCli(args, env) {
|
|
|
33223
33999
|
log
|
|
33224
34000
|
});
|
|
33225
34001
|
if (!started && log !== null)
|
|
33226
|
-
|
|
34002
|
+
fs35.writeSync(log, ` not started
|
|
33227
34003
|
`);
|
|
33228
34004
|
return started;
|
|
33229
34005
|
} catch {
|
|
@@ -33231,7 +34007,7 @@ function runCli(args, env) {
|
|
|
33231
34007
|
} finally {
|
|
33232
34008
|
if (log !== null)
|
|
33233
34009
|
try {
|
|
33234
|
-
|
|
34010
|
+
fs35.closeSync(log);
|
|
33235
34011
|
} catch {}
|
|
33236
34012
|
}
|
|
33237
34013
|
}
|
|
@@ -33250,24 +34026,24 @@ function endSession(end, env = process.env) {
|
|
|
33250
34026
|
var claim2 = (file, now) => {
|
|
33251
34027
|
for (let attempt = 0;attempt < 2; attempt += 1)
|
|
33252
34028
|
try {
|
|
33253
|
-
|
|
34029
|
+
fs35.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
|
|
33254
34030
|
return true;
|
|
33255
34031
|
} catch (error) {
|
|
33256
34032
|
if (error.code !== "EEXIST")
|
|
33257
34033
|
return false;
|
|
33258
34034
|
let held = Number.NaN;
|
|
33259
34035
|
try {
|
|
33260
|
-
held = Number(
|
|
34036
|
+
held = Number(fs35.readFileSync(file, "utf8"));
|
|
33261
34037
|
} catch {}
|
|
33262
34038
|
if (now - held < REAP_INTERVAL_MS)
|
|
33263
34039
|
return false;
|
|
33264
|
-
|
|
34040
|
+
fs35.rmSync(file, { force: true });
|
|
33265
34041
|
}
|
|
33266
34042
|
return false;
|
|
33267
34043
|
};
|
|
33268
34044
|
var fresh = (stamp, now) => {
|
|
33269
34045
|
try {
|
|
33270
|
-
const last = Number(
|
|
34046
|
+
const last = Number(fs35.readFileSync(stamp, "utf8"));
|
|
33271
34047
|
return now - last < REAP_INTERVAL_MS && last <= now;
|
|
33272
34048
|
} catch {
|
|
33273
34049
|
return false;
|
|
@@ -33280,7 +34056,7 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
33280
34056
|
try {
|
|
33281
34057
|
if (fresh(stamp, now))
|
|
33282
34058
|
return false;
|
|
33283
|
-
|
|
34059
|
+
fs35.mkdirSync(path57.dirname(stamp), { recursive: true });
|
|
33284
34060
|
if (!claim2(lock, now))
|
|
33285
34061
|
return false;
|
|
33286
34062
|
} catch {
|
|
@@ -33293,12 +34069,12 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
33293
34069
|
started = runCli(["stop", "--orphans", "--reason", "session-start"], env);
|
|
33294
34070
|
if (started) {
|
|
33295
34071
|
const temp = `${stamp}.${process.pid}`;
|
|
33296
|
-
|
|
33297
|
-
|
|
34072
|
+
fs35.writeFileSync(temp, String(now), { mode: 384 });
|
|
34073
|
+
fs35.renameSync(temp, stamp);
|
|
33298
34074
|
}
|
|
33299
34075
|
} catch {} finally {
|
|
33300
34076
|
try {
|
|
33301
|
-
|
|
34077
|
+
fs35.rmSync(lock, { force: true });
|
|
33302
34078
|
} catch {}
|
|
33303
34079
|
}
|
|
33304
34080
|
return started;
|
|
@@ -33868,127 +34644,35 @@ var ytrackGate = (cwd, command, dialect, ask) => {
|
|
|
33868
34644
|
const run = calls.length ? ` Run ${calls.join(", then ")} instead, each as its own plain call: it asks the user first.` : "";
|
|
33869
34645
|
const user = bare.length ? ask ? ` For ${bare.join(", ")}, run it as its own plain call: the host asks the user.` : ` For ${bare.join(", ")}, the user decides: ask the user, and if they agree they run it in their own terminal.` : "";
|
|
33870
34646
|
const rerun = writes.some((write) => write.gap === NOT_PLAIN.gap) ? " To get the named workit youtrack call instead, rerun the ytrack call as one plain command, with no wrapper, loop, substitution or script around it." : "";
|
|
33871
|
-
const retry = writes.find((write) => write.workit)?.workit ?? (rerun ? writes.find((write) => write.gap === NOT_PLAIN.gap)?.command : undefined);
|
|
33872
|
-
return {
|
|
33873
|
-
kind: "deny",
|
|
33874
|
-
reason: `${why}${run}${user}${rerun}${retry ? `
|
|
33875
|
-
Retry as: ${retry}` : ""}`,
|
|
33876
|
-
unblock: writes[0]?.workit ?? null
|
|
33877
|
-
};
|
|
33878
|
-
};
|
|
33879
|
-
|
|
33880
|
-
// packages/workit-core/src/hooks/exit-pipe.ts
|
|
33881
|
-
var EXIT_VERBS = [
|
|
33882
|
-
["ci", "wait"],
|
|
33883
|
-
["check"],
|
|
33884
|
-
["pr", "merge"],
|
|
33885
|
-
["release"],
|
|
33886
|
-
["verify-delivery"]
|
|
33887
|
-
];
|
|
33888
|
-
var base2 = (word = "") => word.split(/[\\/]/u).at(-1) ?? "";
|
|
33889
|
-
var quote4 = (word) => /^[\w@%+=:,./-]+$/u.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
|
|
33890
|
-
var verbPath = (words) => {
|
|
33891
|
-
const path = [];
|
|
33892
|
-
for (let at = 0;at < words.length && path.length < 2; at += 1) {
|
|
33893
|
-
const word = words[at];
|
|
33894
|
-
if (word === "--")
|
|
33895
|
-
break;
|
|
33896
|
-
if (word === "--cwd")
|
|
33897
|
-
at += 1;
|
|
33898
|
-
else if (!word.startsWith("-"))
|
|
33899
|
-
path.push(word);
|
|
33900
|
-
}
|
|
33901
|
-
return path;
|
|
33902
|
-
};
|
|
33903
|
-
var exitCall = (words) => {
|
|
33904
|
-
let at = 0;
|
|
33905
|
-
while (at < words.length && /^[A-Za-z_]\w*=/u.test(words[at]))
|
|
33906
|
-
at += 1;
|
|
33907
|
-
if (!/^workit(?:-cli)?$/u.test(base2(words[at])))
|
|
33908
|
-
return null;
|
|
33909
|
-
const path = verbPath(words.slice(at + 1));
|
|
33910
|
-
return EXIT_VERBS.some((verb) => verb.every((word, index) => path[index] === word)) ? words.slice(at) : null;
|
|
33911
|
-
};
|
|
33912
|
-
var setsPipefail = (words) => words[0] === "set" && words.some((word, at) => word === "pipefail" && /^-[a-z]*o$/u.test(words[at - 1] ?? ""));
|
|
33913
|
-
var retryOf = ({ call, dir }) => {
|
|
33914
|
-
const at = call[1]?.startsWith("-") ? 1 : 2;
|
|
33915
|
-
const words = dir && !call.includes("--cwd") ? [...call.slice(0, at), "--cwd", dir, ...call.slice(at)] : call;
|
|
33916
|
-
return ["workit", ...words.slice(1)].map(quote4).join(" ");
|
|
33917
|
-
};
|
|
33918
|
-
function exitPipeGate(command, dialect = "posix") {
|
|
33919
|
-
if (!/\bworkit/u.test(command) || !/\b(?:tail|head)\b/u.test(command))
|
|
33920
|
-
return null;
|
|
33921
|
-
const groups = [];
|
|
33922
|
-
let carry = null;
|
|
33923
|
-
let pipefail = false;
|
|
33924
|
-
let dir = null;
|
|
33925
|
-
for (const segment of segmentsOf(command, dialect)) {
|
|
33926
|
-
if (segment.unanalyzable)
|
|
33927
|
-
return null;
|
|
33928
|
-
let words = segment.words;
|
|
33929
|
-
let closes = segment.group === "close";
|
|
33930
|
-
if (segment.group === "open") {
|
|
33931
|
-
groups.push(null);
|
|
33932
|
-
continue;
|
|
33933
|
-
}
|
|
33934
|
-
if (words[0] === "{") {
|
|
33935
|
-
groups.push(null);
|
|
33936
|
-
words = words.slice(1);
|
|
33937
|
-
} else if (words[0] === "}") {
|
|
33938
|
-
closes = true;
|
|
33939
|
-
words = words.slice(1);
|
|
33940
|
-
}
|
|
33941
|
-
if (closes) {
|
|
33942
|
-
const inner = groups.pop() ?? null;
|
|
33943
|
-
if (inner && groups.length)
|
|
33944
|
-
groups[groups.length - 1] = inner;
|
|
33945
|
-
carry = segment.pipe ? inner ?? carry : null;
|
|
33946
|
-
continue;
|
|
33947
|
-
}
|
|
33948
|
-
if (!words.length && !segment.stdin && !segment.subs)
|
|
33949
|
-
continue;
|
|
33950
|
-
if (setsPipefail(words))
|
|
33951
|
-
pipefail = true;
|
|
33952
|
-
const filter = base2(words[0]);
|
|
33953
|
-
if (carry && !pipefail && (filter === "tail" || filter === "head")) {
|
|
33954
|
-
const retry = retryOf(carry);
|
|
33955
|
-
return {
|
|
33956
|
-
kind: "deny",
|
|
33957
|
-
reason: `workit exit-pipe: piping \`workit ${verbPath(carry.call.slice(1)).join(" ")}\` into ${filter} hides its exit code.
|
|
33958
|
-
Retry as: ${retry}`,
|
|
33959
|
-
unblock: retry
|
|
33960
|
-
};
|
|
33961
|
-
}
|
|
33962
|
-
const call = exitCall(words);
|
|
33963
|
-
const found = call ? { call, dir } : null;
|
|
33964
|
-
if (found && groups.length)
|
|
33965
|
-
groups[groups.length - 1] = found;
|
|
33966
|
-
carry = segment.pipe ? found ?? carry : null;
|
|
33967
|
-
dir = words.length === 2 && words[0] === "cd" && !segment.expands?.length ? words[1] : null;
|
|
33968
|
-
}
|
|
33969
|
-
return null;
|
|
33970
|
-
}
|
|
34647
|
+
const retry = writes.find((write) => write.workit)?.workit ?? (rerun ? writes.find((write) => write.gap === NOT_PLAIN.gap)?.command : undefined);
|
|
34648
|
+
return {
|
|
34649
|
+
kind: "deny",
|
|
34650
|
+
reason: `${why}${run}${user}${rerun}${retry ? `
|
|
34651
|
+
Retry as: ${retry}` : ""}`,
|
|
34652
|
+
unblock: writes[0]?.workit ?? null
|
|
34653
|
+
};
|
|
34654
|
+
};
|
|
33971
34655
|
|
|
33972
34656
|
// packages/workit-core/src/agent-stamp.ts
|
|
33973
34657
|
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
33974
|
-
import
|
|
33975
|
-
import
|
|
34658
|
+
import fs37 from "node:fs";
|
|
34659
|
+
import path59 from "node:path";
|
|
33976
34660
|
|
|
33977
34661
|
// packages/workit-core/src/hooks/stamp-hint.ts
|
|
33978
34662
|
import { createHash as createHash24 } from "node:crypto";
|
|
33979
|
-
import
|
|
33980
|
-
import
|
|
34663
|
+
import fs36 from "node:fs";
|
|
34664
|
+
import path58 from "node:path";
|
|
33981
34665
|
var stampHash = (text) => createHash24("sha256").update(text).digest("hex").slice(0, 32);
|
|
33982
|
-
var stampDir = (env, session) =>
|
|
34666
|
+
var stampDir = (env, session) => path58.join(stateDir(env), "agent-stamps", stampHash(session));
|
|
33983
34667
|
var callTag = (toolUseId) => stampHash(toolUseId).slice(0, 8);
|
|
33984
34668
|
var backgrounds = (command) => /(?:^|[^&<>])&(?![&>])/u.test(command);
|
|
33985
34669
|
var dropCallStamps = (env, session, toolUseId) => {
|
|
33986
34670
|
try {
|
|
33987
34671
|
const dir = stampDir(env, session);
|
|
33988
34672
|
const tag = `.${callTag(toolUseId)}-`;
|
|
33989
|
-
for (const name of
|
|
34673
|
+
for (const name of fs36.readdirSync(dir))
|
|
33990
34674
|
if (name.includes(tag))
|
|
33991
|
-
|
|
34675
|
+
fs36.rmSync(path58.join(dir, name), { force: true });
|
|
33992
34676
|
} catch {}
|
|
33993
34677
|
};
|
|
33994
34678
|
var STATE_NAME = "(?:WORKIT_(?:STATE_DIR|CONFIG)\\w*|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA|OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
@@ -34018,12 +34702,12 @@ var noteAgentStamps = (env, session, agentId, command, options = {}) => {
|
|
|
34018
34702
|
const call = options.toolUseId ? callTag(options.toolUseId) : randomBytes5(4).toString("hex");
|
|
34019
34703
|
try {
|
|
34020
34704
|
const dir = stampDir(env, session);
|
|
34021
|
-
|
|
34705
|
+
fs37.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
34022
34706
|
const now = Date.now();
|
|
34023
|
-
for (const name of
|
|
34024
|
-
if (now -
|
|
34025
|
-
|
|
34026
|
-
calls.forEach((argv, index) =>
|
|
34707
|
+
for (const name of fs37.readdirSync(dir))
|
|
34708
|
+
if (now - fs37.statSync(path59.join(dir, name)).mtimeMs > STAMP_TTL_MS)
|
|
34709
|
+
fs37.rmSync(path59.join(dir, name), { force: true });
|
|
34710
|
+
calls.forEach((argv, index) => fs37.writeFileSync(path59.join(dir, `${stampHash(argv.join("\x00"))}.${agentId ?? ""}.${call}-${index}`), ""));
|
|
34027
34711
|
} catch {}
|
|
34028
34712
|
};
|
|
34029
34713
|
var dropAgentStamps = (env, session, toolUseId, command) => {
|
|
@@ -34033,7 +34717,7 @@ var dropAgentStamps = (env, session, toolUseId, command) => {
|
|
|
34033
34717
|
|
|
34034
34718
|
// packages/workit-core/src/hooks/hook-entry.ts
|
|
34035
34719
|
import { existsSync as existsSync19, readFileSync as readFileSync16, realpathSync as realpathSync14 } from "node:fs";
|
|
34036
|
-
import
|
|
34720
|
+
import path60 from "node:path";
|
|
34037
34721
|
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;
|
|
34038
34722
|
var PACKAGE_ENTRIES = {
|
|
34039
34723
|
"claude-code": /^(?:bin\/workit-hook\.mjs|src\/(?:run|hook)\.ts|dist\/workit-hook\.js)$/u,
|
|
@@ -34058,744 +34742,416 @@ var RUNNERS2 = new Set([
|
|
|
34058
34742
|
"."
|
|
34059
34743
|
]);
|
|
34060
34744
|
var PACKAGE_RUNNERS2 = new Set(["npx", "bunx", "pnpx"]);
|
|
34061
|
-
var NO_RUN = new Set([
|
|
34062
|
-
"build",
|
|
34063
|
-
"test",
|
|
34064
|
-
"fmt",
|
|
34065
|
-
"lint",
|
|
34066
|
-
"check",
|
|
34067
|
-
"doc",
|
|
34068
|
-
"info",
|
|
34069
|
-
"install",
|
|
34070
|
-
"add",
|
|
34071
|
-
"pm"
|
|
34072
|
-
]);
|
|
34073
|
-
var MORE_WRAPPERS = new Set(["strace", "ltrace", "watch", "unshare", "firejail", "xargs", "&"]);
|
|
34074
|
-
var baseName3 = (word) => (word.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "").toLowerCase();
|
|
34075
|
-
var packageAt = (dir) => {
|
|
34076
|
-
try {
|
|
34077
|
-
const name = JSON.parse(readFileSync16(
|
|
34078
|
-
const short = /^@workit-dev\/(claude-code|codex|cursor|core)$/u.exec(String(name))?.[1];
|
|
34079
|
-
if (short)
|
|
34080
|
-
return short;
|
|
34081
|
-
} catch {}
|
|
34082
|
-
for (const [manifest, short] of [
|
|
34083
|
-
[".claude-plugin", "claude-code"],
|
|
34084
|
-
[".codex-plugin", "codex"],
|
|
34085
|
-
[".cursor-plugin", "cursor"]
|
|
34086
|
-
]) {
|
|
34087
|
-
try {
|
|
34088
|
-
const name = JSON.parse(readFileSync16(
|
|
34089
|
-
if (name === "workit")
|
|
34090
|
-
return short;
|
|
34091
|
-
} catch {}
|
|
34092
|
-
}
|
|
34093
|
-
return null;
|
|
34094
|
-
};
|
|
34095
|
-
var entryByPath = (file) => {
|
|
34096
|
-
let dir = path59.dirname(file);
|
|
34097
|
-
for (let depth = 0;depth < 4; depth += 1, dir = path59.dirname(dir)) {
|
|
34098
|
-
const short = packageAt(dir);
|
|
34099
|
-
if (short)
|
|
34100
|
-
return PACKAGE_ENTRIES[short]?.test(path59.relative(dir, file).split(path59.sep).join("/")) ?? false;
|
|
34101
|
-
if (existsSync19(path59.join(dir, "package.json")))
|
|
34102
|
-
return false;
|
|
34103
|
-
}
|
|
34104
|
-
return false;
|
|
34105
|
-
};
|
|
34106
|
-
var literalSub = (match, inner) => {
|
|
34107
|
-
try {
|
|
34108
|
-
const [only, ...rest] = segmentsOf(inner);
|
|
34109
|
-
const [verb = "", ...args] = only?.words ?? [];
|
|
34110
|
-
const last = args.findLast((arg) => !arg.startsWith("-"));
|
|
34111
|
-
return rest.length === 0 && /^(?:echo|printf|ls|realpath|readlink)$/u.test(baseName3(verb)) && last ? last : match;
|
|
34112
|
-
} catch {
|
|
34113
|
-
return match;
|
|
34114
|
-
}
|
|
34115
|
-
};
|
|
34116
|
-
var expand = (word, vars) => word.replace(/\$\(([^()]*)\)|`([^`]*)`/gu, (match, sub, tick) => literalSub(match, sub ?? tick ?? "")).replace(/\$\{(\w+)\}|\$(\w+)/gu, (match, braced, bare) => {
|
|
34117
|
-
const name = braced ?? bare ?? "";
|
|
34118
|
-
return vars.get(name) ?? process.env[name] ?? match;
|
|
34119
|
-
}).replace(/^~(?=[\\/]|$)/u, userHome(process.env));
|
|
34120
|
-
var entryNamed = (word, scan) => {
|
|
34121
|
-
if (!word)
|
|
34122
|
-
return null;
|
|
34123
|
-
const text = expand(word, scan.vars);
|
|
34124
|
-
if (ENTRY_NAMES.test(baseName3(text)))
|
|
34125
|
-
return text;
|
|
34126
|
-
const fd = /^\/(?:dev|proc\/self)\/fd\/(\d+)$/u.exec(text)?.[1];
|
|
34127
|
-
if (fd !== undefined && scan.fds.has(fd))
|
|
34128
|
-
return text;
|
|
34129
|
-
if (scan.dir === null && !path59.isAbsolute(text))
|
|
34130
|
-
return null;
|
|
34131
|
-
for (const file of expandGlob(path59.resolve(scan.dir ?? "/", text))) {
|
|
34132
|
-
if (scan.links.has(file) || entryByPath(file))
|
|
34133
|
-
return text;
|
|
34134
|
-
let real;
|
|
34135
|
-
try {
|
|
34136
|
-
real = realpathSync14(file);
|
|
34137
|
-
} catch {
|
|
34138
|
-
continue;
|
|
34139
|
-
}
|
|
34140
|
-
if (ENTRY_NAMES.test(baseName3(real)) || entryByPath(real))
|
|
34141
|
-
return text;
|
|
34142
|
-
}
|
|
34143
|
-
return null;
|
|
34144
|
-
};
|
|
34145
|
-
var noteLink = (words, scan) => {
|
|
34146
|
-
if (!/^(?:ln|cp|install)$/u.test(baseName3(words[0] ?? "")) || scan.dir === null)
|
|
34147
|
-
return;
|
|
34148
|
-
const names = words.slice(1).filter((word) => !word.startsWith("-"));
|
|
34149
|
-
const dest = names.at(-1);
|
|
34150
|
-
if (dest === undefined || names.length < 2)
|
|
34151
|
-
return;
|
|
34152
|
-
for (const source of names.slice(0, -1).filter((name) => entryNamed(name, scan))) {
|
|
34153
|
-
const to = path59.resolve(scan.dir, expand(dest, scan.vars));
|
|
34154
|
-
scan.links.add(to);
|
|
34155
|
-
scan.links.add(path59.join(to, path59.basename(source)));
|
|
34156
|
-
}
|
|
34157
|
-
};
|
|
34158
|
-
var runsEntry = (words, inputs, scan) => {
|
|
34159
|
-
const named = (word) => entryNamed(word, scan);
|
|
34160
|
-
let at = 0;
|
|
34161
|
-
while (at < words.length) {
|
|
34162
|
-
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
34163
|
-
at += 1;
|
|
34164
|
-
const word = words[at];
|
|
34165
|
-
if (word === undefined)
|
|
34166
|
-
return null;
|
|
34167
|
-
const entry = named(word);
|
|
34168
|
-
if (entry)
|
|
34169
|
-
return entry;
|
|
34170
|
-
const name = baseName3(word);
|
|
34171
|
-
const split = name === "env" ? words.findIndex((w) => /^(?:-\w*S|--split-string)/u.test(w)) : -1;
|
|
34172
|
-
if (split > at) {
|
|
34173
|
-
const line = /^(?:-\w*S|--split-string=?)(.*)$/su.exec(words[split] ?? "")?.[1] || words[split + 1];
|
|
34174
|
-
const rest = words.slice(split + (line === words[split + 1] ? 2 : 1));
|
|
34175
|
-
return runsEntry([...(line ?? "").split(/\s+/u).filter(Boolean), ...rest], inputs, scan);
|
|
34176
|
-
}
|
|
34177
|
-
if (MORE_WRAPPERS.has(name)) {
|
|
34178
|
-
at = pastOptions(words, at + 1, "");
|
|
34179
|
-
continue;
|
|
34180
|
-
}
|
|
34181
|
-
const takes = WRAPPERS3[name];
|
|
34182
|
-
if (takes !== undefined && !PACKAGE_RUNNERS2.has(name)) {
|
|
34183
|
-
at = pastOptions(words, at + 1, takes, name === "env" || name === "sudo");
|
|
34184
|
-
continue;
|
|
34185
|
-
}
|
|
34186
|
-
if (name === "busybox" || name === "toybox") {
|
|
34187
|
-
at += 1;
|
|
34188
|
-
continue;
|
|
34189
|
-
}
|
|
34190
|
-
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] ?? "");
|
|
34191
|
-
if (runner) {
|
|
34192
|
-
at += PACKAGE_RUNNERS2.has(name) ? 1 : 2;
|
|
34193
|
-
while (words[at]?.startsWith("-"))
|
|
34194
|
-
at += /^(?:-p|--package|-c|--call)$/u.test(words[at] ?? "") ? 2 : 1;
|
|
34195
|
-
if (/^@workit-dev\/(?:claude-code|codex|cursor)(?:@|$)/u.test(words[at] ?? ""))
|
|
34196
|
-
return words[at] ?? null;
|
|
34197
|
-
continue;
|
|
34198
|
-
}
|
|
34199
|
-
if (!RUNNERS2.has(name))
|
|
34200
|
-
return null;
|
|
34201
|
-
if ((name === "bun" || name === "deno") && NO_RUN.has(words[at + 1] ?? ""))
|
|
34202
|
-
return null;
|
|
34203
|
-
for (const arg of [...words.slice(at + 1), ...inputs]) {
|
|
34204
|
-
const hit = named(arg);
|
|
34205
|
-
if (hit)
|
|
34206
|
-
return hit;
|
|
34207
|
-
}
|
|
34208
|
-
return null;
|
|
34209
|
-
}
|
|
34210
|
-
return null;
|
|
34211
|
-
};
|
|
34212
|
-
var KEYWORDS3 = new Set([
|
|
34213
|
-
"{",
|
|
34214
|
-
"}",
|
|
34215
|
-
"if",
|
|
34216
|
-
"then",
|
|
34217
|
-
"elif",
|
|
34218
|
-
"else",
|
|
34219
|
-
"fi",
|
|
34220
|
-
"while",
|
|
34221
|
-
"until",
|
|
34222
|
-
"do",
|
|
34223
|
-
"done",
|
|
34224
|
-
"esac",
|
|
34225
|
-
"!"
|
|
34226
|
-
]);
|
|
34227
|
-
var pastKeywords = (words) => {
|
|
34228
|
-
let at = 0;
|
|
34229
|
-
for (;; ) {
|
|
34230
|
-
if (words[at] === "function")
|
|
34231
|
-
at += 2;
|
|
34232
|
-
else if (KEYWORDS3.has(words[at] ?? ""))
|
|
34233
|
-
at += 1;
|
|
34234
|
-
else
|
|
34235
|
-
break;
|
|
34236
|
-
}
|
|
34237
|
-
return /^(?:for|case|select)$/u.test(words[at] ?? "") ? [] : words.slice(at);
|
|
34238
|
-
};
|
|
34239
|
-
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(" "));
|
|
34240
|
-
var TOKENS2 = /[\s'"`(),[\]{};|&<>=!]+/u;
|
|
34241
|
-
var ENTRY_SAMPLES = [
|
|
34242
|
-
"workit-hook.mjs",
|
|
34243
|
-
"workit-hook.js",
|
|
34244
|
-
"workit-hook.ts",
|
|
34245
|
-
"cursor-session-start.js"
|
|
34246
|
-
];
|
|
34247
|
-
var tokenEntry = (token, scan) => {
|
|
34248
|
-
if (!/[\\/]/u.test(token) && !existsSync19(path59.resolve(scan.dir ?? "/", token)))
|
|
34249
|
-
return null;
|
|
34250
|
-
return entryNamed(token, scan);
|
|
34251
|
-
};
|
|
34252
|
-
var opaqueEntry = (words, inputs, scan) => {
|
|
34253
|
-
let at = 0;
|
|
34254
|
-
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
34255
|
-
at += 1;
|
|
34256
|
-
const head = baseName3(words[at] ?? "");
|
|
34257
|
-
if (READERS2.has(head))
|
|
34258
|
-
return null;
|
|
34259
|
-
if ((head === "bun" || head === "deno") && NO_RUN.has(words[at + 1] ?? ""))
|
|
34260
|
-
return null;
|
|
34261
|
-
if (head === "git" && !words.some((word) => word.includes("alias.")))
|
|
34262
|
-
return null;
|
|
34263
|
-
if (head === "workit" || head === "workit-cli")
|
|
34264
|
-
return null;
|
|
34265
|
-
const tokens = words.flatMap((word) => word.split(TOKENS2)).filter(Boolean);
|
|
34266
|
-
const runner = (token) => RUNNERS2.has(baseName3(token)) && !/^(?:\.|source)$/u.test(token) || PACKAGE_RUNNERS2.has(baseName3(token));
|
|
34267
|
-
if (!tokens.some(runner))
|
|
34268
|
-
return null;
|
|
34269
|
-
if (scan.fed)
|
|
34270
|
-
return scan.fed;
|
|
34271
|
-
for (const token of tokens) {
|
|
34272
|
-
const hit = tokenEntry(token, scan);
|
|
34273
|
-
if (hit)
|
|
34274
|
-
return hit;
|
|
34275
|
-
}
|
|
34276
|
-
if (head === "find")
|
|
34277
|
-
for (const [index, word] of words.entries()) {
|
|
34278
|
-
const named = /^-i?name$/u.test(words[index - 1] ?? "") && /^[^*?[]/u.test(word);
|
|
34279
|
-
const pattern = named ? globPattern(word) : null;
|
|
34280
|
-
if (pattern && ENTRY_SAMPLES.some((sample) => pattern.test(sample)))
|
|
34281
|
-
return word;
|
|
34282
|
-
}
|
|
34283
|
-
if (/^(?:xargs|parallel)$/u.test(head) || tokens.includes("xargs"))
|
|
34284
|
-
for (const input of inputs) {
|
|
34285
|
-
try {
|
|
34286
|
-
const file = path59.resolve(scan.dir ?? "/", expand(input, scan.vars));
|
|
34287
|
-
const text = readFileSync16(file, "utf8").slice(0, 65536);
|
|
34288
|
-
for (const token of text.split(/\s+/u).filter(Boolean)) {
|
|
34289
|
-
const hit = tokenEntry(token, scan);
|
|
34290
|
-
if (hit)
|
|
34291
|
-
return hit;
|
|
34292
|
-
}
|
|
34293
|
-
} catch {}
|
|
34294
|
-
}
|
|
34295
|
-
return null;
|
|
34296
|
-
};
|
|
34297
|
-
var expandedCommand = (words, scan) => {
|
|
34298
|
-
let at = 0;
|
|
34299
|
-
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
34300
|
-
at += 1;
|
|
34301
|
-
if (!/[$`]/u.test(words[at] ?? ""))
|
|
34302
|
-
return null;
|
|
34303
|
-
for (const word of words.slice(at + 1)) {
|
|
34304
|
-
const hit = entryNamed(word, scan);
|
|
34305
|
-
if (hit)
|
|
34306
|
-
return hit;
|
|
34745
|
+
var NO_RUN = new Set([
|
|
34746
|
+
"build",
|
|
34747
|
+
"test",
|
|
34748
|
+
"fmt",
|
|
34749
|
+
"lint",
|
|
34750
|
+
"check",
|
|
34751
|
+
"doc",
|
|
34752
|
+
"info",
|
|
34753
|
+
"install",
|
|
34754
|
+
"add",
|
|
34755
|
+
"pm"
|
|
34756
|
+
]);
|
|
34757
|
+
var MORE_WRAPPERS = new Set(["strace", "ltrace", "watch", "unshare", "firejail", "xargs", "&"]);
|
|
34758
|
+
var baseName3 = (word) => (word.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "").toLowerCase();
|
|
34759
|
+
var packageAt = (dir) => {
|
|
34760
|
+
try {
|
|
34761
|
+
const name = JSON.parse(readFileSync16(path60.join(dir, "package.json"), "utf8")).name;
|
|
34762
|
+
const short = /^@workit-dev\/(claude-code|codex|cursor|core)$/u.exec(String(name))?.[1];
|
|
34763
|
+
if (short)
|
|
34764
|
+
return short;
|
|
34765
|
+
} catch {}
|
|
34766
|
+
for (const [manifest, short] of [
|
|
34767
|
+
[".claude-plugin", "claude-code"],
|
|
34768
|
+
[".codex-plugin", "codex"],
|
|
34769
|
+
[".cursor-plugin", "cursor"]
|
|
34770
|
+
]) {
|
|
34771
|
+
try {
|
|
34772
|
+
const name = JSON.parse(readFileSync16(path60.join(dir, manifest, "plugin.json"), "utf8")).name;
|
|
34773
|
+
if (name === "workit")
|
|
34774
|
+
return short;
|
|
34775
|
+
} catch {}
|
|
34307
34776
|
}
|
|
34308
34777
|
return null;
|
|
34309
34778
|
};
|
|
34310
|
-
var
|
|
34311
|
-
|
|
34312
|
-
|
|
34313
|
-
|
|
34314
|
-
|
|
34315
|
-
|
|
34316
|
-
|
|
34317
|
-
|
|
34318
|
-
return hit;
|
|
34319
|
-
}
|
|
34779
|
+
var entryByPath = (file) => {
|
|
34780
|
+
let dir = path60.dirname(file);
|
|
34781
|
+
for (let depth = 0;depth < 4; depth += 1, dir = path60.dirname(dir)) {
|
|
34782
|
+
const short = packageAt(dir);
|
|
34783
|
+
if (short)
|
|
34784
|
+
return PACKAGE_ENTRIES[short]?.test(path60.relative(dir, file).split(path60.sep).join("/")) ?? false;
|
|
34785
|
+
if (existsSync19(path60.join(dir, "package.json")))
|
|
34786
|
+
return false;
|
|
34320
34787
|
}
|
|
34321
|
-
return
|
|
34788
|
+
return false;
|
|
34322
34789
|
};
|
|
34323
|
-
var
|
|
34324
|
-
let segments;
|
|
34790
|
+
var literalSub = (match, inner) => {
|
|
34325
34791
|
try {
|
|
34326
|
-
|
|
34792
|
+
const [only, ...rest] = segmentsOf(inner);
|
|
34793
|
+
const [verb = "", ...args] = only?.words ?? [];
|
|
34794
|
+
const last = args.findLast((arg) => !arg.startsWith("-"));
|
|
34795
|
+
return rest.length === 0 && /^(?:echo|printf|ls|realpath|readlink)$/u.test(baseName3(verb)) && last ? last : match;
|
|
34327
34796
|
} catch {
|
|
34328
|
-
return
|
|
34329
|
-
}
|
|
34330
|
-
for (const [index, segment] of segments.entries()) {
|
|
34331
|
-
if (segment.unanalyzable)
|
|
34332
|
-
continue;
|
|
34333
|
-
bindLoop(segment.words, segments.slice(index + 1), scan);
|
|
34334
|
-
const words = pastKeywords(segment.words);
|
|
34335
|
-
const fed = scan.fed;
|
|
34336
|
-
scan.fed = null;
|
|
34337
|
-
const hit = segmentEntry(segment, words, dialect, scan, fed);
|
|
34338
|
-
if (hit)
|
|
34339
|
-
return hit;
|
|
34340
|
-
}
|
|
34341
|
-
return null;
|
|
34342
|
-
};
|
|
34343
|
-
var bindLoop = (raw, after, scan) => {
|
|
34344
|
-
const at = raw.findIndex((word) => !KEYWORDS3.has(word));
|
|
34345
|
-
const verb = raw[at];
|
|
34346
|
-
if ((verb === "for" || verb === "select") && raw[at + 2] === "in") {
|
|
34347
|
-
const name = raw[at + 1] ?? "";
|
|
34348
|
-
const items = raw.slice(at + 3);
|
|
34349
|
-
const item = items.find((word) => entryNamed(word, scan)) ?? items[0];
|
|
34350
|
-
if (/^[A-Za-z_]\w*$/u.test(name) && item !== undefined)
|
|
34351
|
-
scan.vars.set(name, expand(item, scan.vars));
|
|
34352
|
-
return;
|
|
34353
|
-
}
|
|
34354
|
-
const read = raw.indexOf("read");
|
|
34355
|
-
if (read < 0 || !raw.slice(0, read).some((word) => word === "while" || word === "until"))
|
|
34356
|
-
return;
|
|
34357
|
-
const fed = after.find((segment) => segment.words[0] === "done")?.stdin?.[0];
|
|
34358
|
-
const line = fed?.split(`
|
|
34359
|
-
`)[0]?.trim();
|
|
34360
|
-
const name = raw.slice(read + 1).find((word) => /^[A-Za-z_]\w*$/u.test(word));
|
|
34361
|
-
if (name && line)
|
|
34362
|
-
scan.vars.set(name, line);
|
|
34363
|
-
};
|
|
34364
|
-
var segmentEntry = (segment, words, dialect, scan, fed) => {
|
|
34365
|
-
const verb = baseName3(words[0] ?? "");
|
|
34366
|
-
if (["cd", "pushd", "chdir", "set-location", "sl"].includes(verb)) {
|
|
34367
|
-
const target = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
|
|
34368
|
-
const moved = target === undefined ? userHome(process.env) : expand(target, scan.vars);
|
|
34369
|
-
scan.dir = moved === "-" || /[$`]/u.test(moved) ? null : path59.isAbsolute(moved) ? moved : scan.dir && path59.resolve(scan.dir, moved);
|
|
34370
|
-
if (scan.dir === null)
|
|
34371
|
-
scan.vars.delete("PWD");
|
|
34372
|
-
else
|
|
34373
|
-
scan.vars.set("PWD", scan.dir);
|
|
34374
|
-
return null;
|
|
34375
|
-
}
|
|
34376
|
-
if (verb === "popd") {
|
|
34377
|
-
scan.dir = null;
|
|
34378
|
-
return null;
|
|
34379
|
-
}
|
|
34380
|
-
const declares = ["export", "declare", "typeset", "local", "readonly"].includes(verb);
|
|
34381
|
-
const assigns = declares ? words.slice(1) : words.every((word) => /^[A-Za-z_]\w*=/u.test(word)) ? words : [];
|
|
34382
|
-
for (const word of assigns) {
|
|
34383
|
-
const [name = "", value] = word.split(/=(.*)/su);
|
|
34384
|
-
if (value !== undefined && /^[A-Za-z_]\w*$/u.test(name))
|
|
34385
|
-
scan.vars.set(name, expand(value.replace(/^(['"])(.*)\1$/su, "$2"), scan.vars));
|
|
34386
|
-
}
|
|
34387
|
-
const options = optionsEntry(declares ? words.slice(1) : words, scan);
|
|
34388
|
-
if (options)
|
|
34389
|
-
return options;
|
|
34390
|
-
if (verb === "exec" && words.slice(1).every((word) => /^\d+$/u.test(word))) {
|
|
34391
|
-
for (const input of segment.inputs ?? [])
|
|
34392
|
-
if (entryNamed(input, scan))
|
|
34393
|
-
for (const fd of words.slice(1))
|
|
34394
|
-
scan.fds.add(fd);
|
|
34395
|
-
}
|
|
34396
|
-
const inputs = segment.inputs ?? [];
|
|
34397
|
-
const entry = runsEntry(words, inputs, scan) ?? expandedCommand(words, scan) ?? opaqueEntry(words, inputs, { ...scan, fed });
|
|
34398
|
-
if (entry)
|
|
34399
|
-
return entry;
|
|
34400
|
-
if (segment.pipe)
|
|
34401
|
-
scan.fed = words.slice(1).flatMap((word) => word.split(TOKENS2)).map((token) => token ? tokenEntry(token, scan) : null).find(Boolean) ?? null;
|
|
34402
|
-
noteLink(words, scan);
|
|
34403
|
-
if (scan.depth >= 4)
|
|
34404
|
-
return null;
|
|
34405
|
-
const nested = (script) => scanCommand(script, dialect, {
|
|
34406
|
-
...scan,
|
|
34407
|
-
vars: new Map(scan.vars),
|
|
34408
|
-
fed: null,
|
|
34409
|
-
depth: scan.depth + 1
|
|
34410
|
-
});
|
|
34411
|
-
const scripts = [...segment.subs ?? []];
|
|
34412
|
-
const script = shellScript2(words) ?? cmdScript2(words) ?? workitScript(words);
|
|
34413
|
-
if (script)
|
|
34414
|
-
scripts.push(script);
|
|
34415
|
-
if (!script && /^(?:ba|z|da|k)?sh$/u.test(verb) && words.slice(1).every((word) => word.startsWith("-")) || verb === "at" || verb === "batch")
|
|
34416
|
-
scripts.push(...segment.stdin ?? []);
|
|
34417
|
-
for (const text of scripts) {
|
|
34418
|
-
const hit = nested(text);
|
|
34419
|
-
if (hit)
|
|
34420
|
-
return hit;
|
|
34797
|
+
return match;
|
|
34421
34798
|
}
|
|
34422
|
-
return null;
|
|
34423
34799
|
};
|
|
34424
|
-
var
|
|
34425
|
-
const name =
|
|
34426
|
-
|
|
34800
|
+
var expand = (word, vars) => word.replace(/\$\(([^()]*)\)|`([^`]*)`/gu, (match, sub, tick) => literalSub(match, sub ?? tick ?? "")).replace(/\$\{(\w+)\}|\$(\w+)/gu, (match, braced, bare) => {
|
|
34801
|
+
const name = braced ?? bare ?? "";
|
|
34802
|
+
return vars.get(name) ?? process.env[name] ?? match;
|
|
34803
|
+
}).replace(/^~(?=[\\/]|$)/u, userHome(process.env));
|
|
34804
|
+
var entryNamed = (word, scan) => {
|
|
34805
|
+
if (!word)
|
|
34427
34806
|
return null;
|
|
34428
|
-
const
|
|
34429
|
-
|
|
34430
|
-
|
|
34431
|
-
|
|
34432
|
-
if (
|
|
34807
|
+
const text = expand(word, scan.vars);
|
|
34808
|
+
if (ENTRY_NAMES.test(baseName3(text)))
|
|
34809
|
+
return text;
|
|
34810
|
+
const fd = /^\/(?:dev|proc\/self)\/fd\/(\d+)$/u.exec(text)?.[1];
|
|
34811
|
+
if (fd !== undefined && scan.fds.has(fd))
|
|
34812
|
+
return text;
|
|
34813
|
+
if (scan.dir === null && !path60.isAbsolute(text))
|
|
34433
34814
|
return null;
|
|
34434
|
-
const
|
|
34435
|
-
|
|
34436
|
-
|
|
34437
|
-
|
|
34438
|
-
const found = [];
|
|
34439
|
-
for (let at = command.indexOf("$(");at >= 0 && found.length < 32; at = command.indexOf("$(", at + 1)) {
|
|
34440
|
-
if (command[at + 2] === "(")
|
|
34441
|
-
continue;
|
|
34442
|
-
let depth = 1;
|
|
34443
|
-
let end = at + 2;
|
|
34444
|
-
for (;end < command.length && depth > 0; end += 1)
|
|
34445
|
-
if (command[end] === "(")
|
|
34446
|
-
depth += 1;
|
|
34447
|
-
else if (command[end] === ")")
|
|
34448
|
-
depth -= 1;
|
|
34449
|
-
found.push(command.slice(at + 2, end - 1));
|
|
34450
|
-
}
|
|
34451
|
-
return found;
|
|
34452
|
-
};
|
|
34453
|
-
var hookEntryRun = (cwd, command, dialect = "posix") => {
|
|
34454
|
-
const scan = (text) => scanCommand(text, dialect, {
|
|
34455
|
-
dir: cwd,
|
|
34456
|
-
vars: new Map([["PWD", cwd]]),
|
|
34457
|
-
links: new Set,
|
|
34458
|
-
fds: new Set,
|
|
34459
|
-
fed: null,
|
|
34460
|
-
depth: 0
|
|
34461
|
-
});
|
|
34462
|
-
const texts = dialect === "posix" && /[A-Za-z]:\\/u.test(command) ? [command, command.replaceAll("\\", "/")] : [command];
|
|
34463
|
-
for (const text of texts) {
|
|
34464
|
-
const hit = scan(text) ?? substitutions2(text).map(scan).find(Boolean);
|
|
34465
|
-
if (hit)
|
|
34466
|
-
return hit;
|
|
34467
|
-
}
|
|
34468
|
-
return null;
|
|
34469
|
-
};
|
|
34470
|
-
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).`;
|
|
34471
|
-
|
|
34472
|
-
// packages/workit-core/src/hooks/identity-env.ts
|
|
34473
|
-
import fs37 from "node:fs";
|
|
34474
|
-
import path60 from "node:path";
|
|
34475
|
-
var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
|
|
34476
|
-
var IDENTITY = new RegExp(`^${NAMES}$`, "u");
|
|
34477
|
-
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
34478
|
-
var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
|
|
34479
|
-
var IDENTITY_ANY = new RegExp(NAMES, "iu");
|
|
34480
|
-
var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
|
|
34481
|
-
var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
|
|
34482
|
-
var STATE_ANY = new RegExp(STATE_NAMES, "iu");
|
|
34483
|
-
var powershell = (names) => new RegExp([
|
|
34484
|
-
`\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
|
|
34485
|
-
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
|
|
34486
|
-
`SetEnvironmentVariable\\(\\s*['"]${names}\\b`
|
|
34487
|
-
].join("|"), "iu");
|
|
34488
|
-
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";
|
|
34489
|
-
var POWERSHELL = powershell(NAMES);
|
|
34490
|
-
var POWERSHELL_STATE = powershell(STATE_NAMES);
|
|
34491
|
-
var POWERSHELL_HOST = powershell(HOST_NAMES);
|
|
34492
|
-
var POWERSHELL_OPAQUE = new RegExp([
|
|
34493
|
-
`SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
|
|
34494
|
-
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
|
|
34495
|
-
`(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
|
|
34496
|
-
`\\b(?:iex|Invoke-Expression)\\b`
|
|
34497
|
-
].join("|"), "iu");
|
|
34498
|
-
var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
|
|
34499
|
-
var CMD_IDENTITY = cmdSet(NAMES);
|
|
34500
|
-
var CMD_STATE = cmdSet(STATE_NAMES);
|
|
34501
|
-
var CMD_HOST = cmdSet(HOST_NAMES);
|
|
34502
|
-
var RUNS_TEXT = /\bworkit(?:-cli)?\b|@workit-dev[\\/]cli/iu;
|
|
34503
|
-
var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
|
|
34504
|
-
var OPAQUE = new Set([
|
|
34505
|
-
"watch",
|
|
34506
|
-
"strace",
|
|
34507
|
-
"chroot",
|
|
34508
|
-
"flock",
|
|
34509
|
-
"ssh",
|
|
34510
|
-
"su",
|
|
34511
|
-
"runuser",
|
|
34512
|
-
"script",
|
|
34513
|
-
"parallel"
|
|
34514
|
-
]);
|
|
34515
|
-
var ENV_VALUED = new Set(["u", "C", "S", "a", "P"]);
|
|
34516
|
-
var ENV_FLAGS = new Set(["i", "0", "v"]);
|
|
34517
|
-
var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
|
|
34518
|
-
var ENV_LONG_FLAGS = /^--(?:ignore-environment|null|debug|(?:block|default|ignore)-signal(?:=.*)?)$/u;
|
|
34519
|
-
var base3 = (word) => (word?.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "");
|
|
34520
|
-
var ASSIGN = /^[A-Za-z_]\w*\+?=/u;
|
|
34521
|
-
var nameOf = (word) => (word?.split("=")[0] ?? "").replace(/\+$/u, "");
|
|
34522
|
-
var named = (word) => IDENTITY.test(nameOf(word));
|
|
34523
|
-
var stateNamed = (word) => STATE2.test(nameOf(word));
|
|
34524
|
-
var isWorkit = (word) => /^workit(?:-cli)?(?:\.[cm]?js)?$/u.test(base3(word)) || /@workit-dev[\\/]cli\b|workit-cli[\\/](?:dist|src)[\\/]/u.test(word ?? "");
|
|
34525
|
-
var linksToWorkit = (word, cwd) => {
|
|
34526
|
-
const places = /[\\/]/u.test(word) ? [path60.resolve(cwd ?? process.cwd(), word)] : (process.env.PATH ?? "").split(path60.delimiter).map((dir) => path60.join(dir, word));
|
|
34527
|
-
for (const place of places) {
|
|
34815
|
+
for (const file of expandGlob(path60.resolve(scan.dir ?? "/", text))) {
|
|
34816
|
+
if (scan.links.has(file) || entryByPath(file))
|
|
34817
|
+
return text;
|
|
34818
|
+
let real;
|
|
34528
34819
|
try {
|
|
34529
|
-
|
|
34530
|
-
|
|
34531
|
-
|
|
34820
|
+
real = realpathSync14(file);
|
|
34821
|
+
} catch {
|
|
34822
|
+
continue;
|
|
34823
|
+
}
|
|
34824
|
+
if (ENTRY_NAMES.test(baseName3(real)) || entryByPath(real))
|
|
34825
|
+
return text;
|
|
34532
34826
|
}
|
|
34533
|
-
return
|
|
34827
|
+
return null;
|
|
34534
34828
|
};
|
|
34535
|
-
var
|
|
34536
|
-
|
|
34537
|
-
var note = (scan, seg, word) => {
|
|
34538
|
-
if (scan.identity && named(word)) {
|
|
34539
|
-
if (seg)
|
|
34540
|
-
seg.identity ??= nameOf(word);
|
|
34541
|
-
else
|
|
34542
|
-
scan.hit ??= nameOf(word);
|
|
34543
|
-
}
|
|
34544
|
-
if (!stateNamed(word) && !(scan.identity && HOST_VARIABLE.test(nameOf(word))))
|
|
34829
|
+
var noteLink = (words, scan) => {
|
|
34830
|
+
if (!/^(?:ln|cp|install)$/u.test(baseName3(words[0] ?? "")) || scan.dir === null)
|
|
34545
34831
|
return;
|
|
34546
|
-
|
|
34547
|
-
|
|
34548
|
-
|
|
34549
|
-
|
|
34832
|
+
const names = words.slice(1).filter((word) => !word.startsWith("-"));
|
|
34833
|
+
const dest = names.at(-1);
|
|
34834
|
+
if (dest === undefined || names.length < 2)
|
|
34835
|
+
return;
|
|
34836
|
+
for (const source of names.slice(0, -1).filter((name) => entryNamed(name, scan))) {
|
|
34837
|
+
const to = path60.resolve(scan.dir, expand(dest, scan.vars));
|
|
34838
|
+
scan.links.add(to);
|
|
34839
|
+
scan.links.add(path60.join(to, path60.basename(source)));
|
|
34840
|
+
}
|
|
34550
34841
|
};
|
|
34551
|
-
var
|
|
34552
|
-
|
|
34553
|
-
|
|
34554
|
-
|
|
34555
|
-
|
|
34556
|
-
|
|
34557
|
-
|
|
34558
|
-
if (
|
|
34559
|
-
|
|
34560
|
-
const
|
|
34561
|
-
|
|
34562
|
-
|
|
34563
|
-
|
|
34564
|
-
|
|
34565
|
-
|
|
34566
|
-
|
|
34567
|
-
|
|
34568
|
-
|
|
34569
|
-
return risky(UNREADABLE);
|
|
34570
|
-
}
|
|
34571
|
-
scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, seg, depth + 1);
|
|
34572
|
-
};
|
|
34573
|
-
let options = true;
|
|
34574
|
-
for (let index = at;index < words.length; index += 1) {
|
|
34575
|
-
const word = words[index] ?? "";
|
|
34576
|
-
if (expands.has(index)) {
|
|
34577
|
-
risky(UNREADABLE);
|
|
34578
|
-
const built = options ? /^(?:--split-string=|-[\w]*S)(.+)$/su.exec(word) : null;
|
|
34579
|
-
if (built)
|
|
34580
|
-
return split(built[1], index + 1, true);
|
|
34581
|
-
continue;
|
|
34842
|
+
var runsEntry = (words, inputs, scan) => {
|
|
34843
|
+
const named = (word) => entryNamed(word, scan);
|
|
34844
|
+
let at = 0;
|
|
34845
|
+
while (at < words.length) {
|
|
34846
|
+
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
34847
|
+
at += 1;
|
|
34848
|
+
const word = words[at];
|
|
34849
|
+
if (word === undefined)
|
|
34850
|
+
return null;
|
|
34851
|
+
const entry = named(word);
|
|
34852
|
+
if (entry)
|
|
34853
|
+
return entry;
|
|
34854
|
+
const name = baseName3(word);
|
|
34855
|
+
const split = name === "env" ? words.findIndex((w) => /^(?:-\w*S|--split-string)/u.test(w)) : -1;
|
|
34856
|
+
if (split > at) {
|
|
34857
|
+
const line = /^(?:-\w*S|--split-string=?)(.*)$/su.exec(words[split] ?? "")?.[1] || words[split + 1];
|
|
34858
|
+
const rest = words.slice(split + (line === words[split + 1] ? 2 : 1));
|
|
34859
|
+
return runsEntry([...(line ?? "").split(/\s+/u).filter(Boolean), ...rest], inputs, scan);
|
|
34582
34860
|
}
|
|
34583
|
-
if (
|
|
34584
|
-
|
|
34861
|
+
if (MORE_WRAPPERS.has(name)) {
|
|
34862
|
+
at = pastOptions(words, at + 1, "");
|
|
34585
34863
|
continue;
|
|
34586
34864
|
}
|
|
34587
|
-
|
|
34588
|
-
|
|
34865
|
+
const takes = WRAPPERS3[name];
|
|
34866
|
+
if (takes !== undefined && !PACKAGE_RUNNERS2.has(name)) {
|
|
34867
|
+
at = pastOptions(words, at + 1, takes, name === "env" || name === "sudo");
|
|
34589
34868
|
continue;
|
|
34590
34869
|
}
|
|
34591
|
-
if (
|
|
34592
|
-
|
|
34593
|
-
if (name === "--ignore-environment")
|
|
34594
|
-
risky("env -i");
|
|
34595
|
-
else if (name === "--unset")
|
|
34596
|
-
unset(value ?? words[index += 1]);
|
|
34597
|
-
else if (name === "--split-string")
|
|
34598
|
-
return split(value ?? words[index + 1], index + (value === undefined ? 2 : 1), expands.has(index + (value === undefined ? 1 : 0)));
|
|
34599
|
-
else if (ENV_LONG_VALUED.has(name))
|
|
34600
|
-
index += value === undefined ? 1 : 0;
|
|
34601
|
-
else if (!ENV_LONG_FLAGS.test(word))
|
|
34602
|
-
risky(UNREADABLE);
|
|
34870
|
+
if (name === "busybox" || name === "toybox") {
|
|
34871
|
+
at += 1;
|
|
34603
34872
|
continue;
|
|
34604
34873
|
}
|
|
34605
|
-
|
|
34606
|
-
|
|
34607
|
-
|
|
34608
|
-
|
|
34609
|
-
|
|
34610
|
-
|
|
34611
|
-
|
|
34612
|
-
else if (ENV_VALUED.has(letter)) {
|
|
34613
|
-
const glued = word.slice(at2 + 1);
|
|
34614
|
-
if (!glued)
|
|
34615
|
-
index += 1;
|
|
34616
|
-
const value = glued || words[index];
|
|
34617
|
-
if (letter === "u")
|
|
34618
|
-
unset(value);
|
|
34619
|
-
if (letter === "S")
|
|
34620
|
-
return split(value, index + 1, expands.has(index));
|
|
34621
|
-
break;
|
|
34622
|
-
} else {
|
|
34623
|
-
risky(UNREADABLE);
|
|
34624
|
-
break;
|
|
34625
|
-
}
|
|
34626
|
-
}
|
|
34874
|
+
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] ?? "");
|
|
34875
|
+
if (runner) {
|
|
34876
|
+
at += PACKAGE_RUNNERS2.has(name) ? 1 : 2;
|
|
34877
|
+
while (words[at]?.startsWith("-"))
|
|
34878
|
+
at += /^(?:-p|--package|-c|--call)$/u.test(words[at] ?? "") ? 2 : 1;
|
|
34879
|
+
if (/^@workit-dev\/(?:claude-code|codex|cursor)(?:@|$)/u.test(words[at] ?? ""))
|
|
34880
|
+
return words[at] ?? null;
|
|
34627
34881
|
continue;
|
|
34628
34882
|
}
|
|
34629
|
-
if (
|
|
34630
|
-
|
|
34631
|
-
|
|
34883
|
+
if (!RUNNERS2.has(name))
|
|
34884
|
+
return null;
|
|
34885
|
+
if ((name === "bun" || name === "deno") && NO_RUN.has(words[at + 1] ?? ""))
|
|
34886
|
+
return null;
|
|
34887
|
+
for (const arg of [...words.slice(at + 1), ...inputs]) {
|
|
34888
|
+
const hit = named(arg);
|
|
34889
|
+
if (hit)
|
|
34890
|
+
return hit;
|
|
34632
34891
|
}
|
|
34633
|
-
return
|
|
34892
|
+
return null;
|
|
34634
34893
|
}
|
|
34894
|
+
return null;
|
|
34635
34895
|
};
|
|
34636
|
-
var
|
|
34637
|
-
|
|
34638
|
-
|
|
34639
|
-
|
|
34640
|
-
|
|
34641
|
-
|
|
34642
|
-
|
|
34643
|
-
|
|
34644
|
-
|
|
34645
|
-
|
|
34646
|
-
|
|
34647
|
-
|
|
34648
|
-
|
|
34649
|
-
|
|
34650
|
-
|
|
34651
|
-
|
|
34652
|
-
|
|
34653
|
-
|
|
34896
|
+
var KEYWORDS3 = new Set([
|
|
34897
|
+
"{",
|
|
34898
|
+
"}",
|
|
34899
|
+
"if",
|
|
34900
|
+
"then",
|
|
34901
|
+
"elif",
|
|
34902
|
+
"else",
|
|
34903
|
+
"fi",
|
|
34904
|
+
"while",
|
|
34905
|
+
"until",
|
|
34906
|
+
"do",
|
|
34907
|
+
"done",
|
|
34908
|
+
"esac",
|
|
34909
|
+
"!"
|
|
34910
|
+
]);
|
|
34911
|
+
var pastKeywords = (words) => {
|
|
34912
|
+
let at = 0;
|
|
34913
|
+
for (;; ) {
|
|
34914
|
+
if (words[at] === "function")
|
|
34915
|
+
at += 2;
|
|
34916
|
+
else if (KEYWORDS3.has(words[at] ?? ""))
|
|
34917
|
+
at += 1;
|
|
34918
|
+
else
|
|
34654
34919
|
break;
|
|
34655
|
-
index = pastOptions(words, index + 1, takes);
|
|
34656
34920
|
}
|
|
34657
|
-
|
|
34658
|
-
|
|
34659
|
-
|
|
34660
|
-
|
|
34661
|
-
|
|
34662
|
-
|
|
34663
|
-
|
|
34664
|
-
|
|
34665
|
-
|
|
34666
|
-
|
|
34667
|
-
|
|
34668
|
-
if (
|
|
34669
|
-
|
|
34670
|
-
|
|
34671
|
-
|
|
34672
|
-
|
|
34673
|
-
|
|
34674
|
-
|
|
34921
|
+
return /^(?:for|case|select)$/u.test(words[at] ?? "") ? [] : words.slice(at);
|
|
34922
|
+
};
|
|
34923
|
+
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(" "));
|
|
34924
|
+
var TOKENS2 = /[\s'"`(),[\]{};|&<>=!]+/u;
|
|
34925
|
+
var ENTRY_SAMPLES = [
|
|
34926
|
+
"workit-hook.mjs",
|
|
34927
|
+
"workit-hook.js",
|
|
34928
|
+
"workit-hook.ts",
|
|
34929
|
+
"cursor-session-start.js"
|
|
34930
|
+
];
|
|
34931
|
+
var tokenEntry = (token, scan) => {
|
|
34932
|
+
if (!/[\\/]/u.test(token) && !existsSync19(path60.resolve(scan.dir ?? "/", token)))
|
|
34933
|
+
return null;
|
|
34934
|
+
return entryNamed(token, scan);
|
|
34935
|
+
};
|
|
34936
|
+
var opaqueEntry = (words, inputs, scan) => {
|
|
34937
|
+
let at = 0;
|
|
34938
|
+
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
34939
|
+
at += 1;
|
|
34940
|
+
const head = baseName3(words[at] ?? "");
|
|
34941
|
+
if (READERS2.has(head))
|
|
34942
|
+
return null;
|
|
34943
|
+
if ((head === "bun" || head === "deno") && NO_RUN.has(words[at + 1] ?? ""))
|
|
34944
|
+
return null;
|
|
34945
|
+
if (head === "git" && !words.some((word) => word.includes("alias.")))
|
|
34946
|
+
return null;
|
|
34947
|
+
if (head === "workit" || head === "workit-cli")
|
|
34948
|
+
return null;
|
|
34949
|
+
const tokens = words.flatMap((word) => word.split(TOKENS2)).filter(Boolean);
|
|
34950
|
+
const runner = (token) => RUNNERS2.has(baseName3(token)) && !/^(?:\.|source)$/u.test(token) || PACKAGE_RUNNERS2.has(baseName3(token));
|
|
34951
|
+
if (!tokens.some(runner))
|
|
34952
|
+
return null;
|
|
34953
|
+
if (scan.fed)
|
|
34954
|
+
return scan.fed;
|
|
34955
|
+
for (const token of tokens) {
|
|
34956
|
+
const hit = tokenEntry(token, scan);
|
|
34957
|
+
if (hit)
|
|
34958
|
+
return hit;
|
|
34959
|
+
}
|
|
34960
|
+
if (head === "find")
|
|
34961
|
+
for (const [index, word] of words.entries()) {
|
|
34962
|
+
const named = /^-i?name$/u.test(words[index - 1] ?? "") && /^[^*?[]/u.test(word);
|
|
34963
|
+
const pattern = named ? globPattern(word) : null;
|
|
34964
|
+
if (pattern && ENTRY_SAMPLES.some((sample) => pattern.test(sample)))
|
|
34965
|
+
return word;
|
|
34966
|
+
}
|
|
34967
|
+
if (/^(?:xargs|parallel)$/u.test(head) || tokens.includes("xargs"))
|
|
34968
|
+
for (const input of inputs) {
|
|
34969
|
+
try {
|
|
34970
|
+
const file = path60.resolve(scan.dir ?? "/", expand(input, scan.vars));
|
|
34971
|
+
const text = readFileSync16(file, "utf8").slice(0, 65536);
|
|
34972
|
+
for (const token of text.split(/\s+/u).filter(Boolean)) {
|
|
34973
|
+
const hit = tokenEntry(token, scan);
|
|
34974
|
+
if (hit)
|
|
34975
|
+
return hit;
|
|
34976
|
+
}
|
|
34977
|
+
} catch {}
|
|
34675
34978
|
}
|
|
34676
|
-
|
|
34677
|
-
};
|
|
34678
|
-
var opaque = (rest, scan, seg, assigns) => {
|
|
34679
|
-
if (!rest.some(isWorkit))
|
|
34680
|
-
return;
|
|
34681
|
-
seg.runs = true;
|
|
34682
|
-
const changes = (word) => base3(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && ASSIGN.test(word);
|
|
34683
|
-
if (rest.some(changes))
|
|
34684
|
-
scan.risky ??= UNREADABLE;
|
|
34685
|
-
if (rest.some((word) => base3(word).toLowerCase() === "env"))
|
|
34686
|
-
for (const word of rest)
|
|
34687
|
-
note(scan, seg, word);
|
|
34688
|
-
};
|
|
34689
|
-
var LOGIN_VALUED = {
|
|
34690
|
-
su: /[sgGwc]/u,
|
|
34691
|
-
runuser: /[sgGwuc]/u,
|
|
34692
|
-
script: /[cEIOBTmot]/u
|
|
34979
|
+
return null;
|
|
34693
34980
|
};
|
|
34694
|
-
var
|
|
34695
|
-
|
|
34696
|
-
|
|
34981
|
+
var expandedCommand = (words, scan) => {
|
|
34982
|
+
let at = 0;
|
|
34983
|
+
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
34984
|
+
at += 1;
|
|
34985
|
+
if (!/[$`]/u.test(words[at] ?? ""))
|
|
34697
34986
|
return null;
|
|
34698
|
-
const
|
|
34699
|
-
|
|
34700
|
-
|
|
34701
|
-
|
|
34702
|
-
|
|
34703
|
-
|
|
34704
|
-
|
|
34705
|
-
|
|
34987
|
+
for (const word of words.slice(at + 1)) {
|
|
34988
|
+
const hit = entryNamed(word, scan);
|
|
34989
|
+
if (hit)
|
|
34990
|
+
return hit;
|
|
34991
|
+
}
|
|
34992
|
+
return null;
|
|
34993
|
+
};
|
|
34994
|
+
var optionsEntry = (words, scan) => {
|
|
34995
|
+
for (const word of words) {
|
|
34996
|
+
const value = /^(?:NODE_OPTIONS|BUN_OPTIONS)=(.*)$/su.exec(word)?.[1];
|
|
34997
|
+
if (value === undefined)
|
|
34706
34998
|
continue;
|
|
34707
|
-
const
|
|
34708
|
-
|
|
34709
|
-
|
|
34999
|
+
for (const token of value.split(TOKENS2).filter(Boolean)) {
|
|
35000
|
+
const hit = tokenEntry(token, scan);
|
|
35001
|
+
if (hit)
|
|
35002
|
+
return hit;
|
|
35003
|
+
}
|
|
34710
35004
|
}
|
|
34711
35005
|
return null;
|
|
34712
35006
|
};
|
|
34713
|
-
var scanCommand2 = (command, dialect,
|
|
35007
|
+
var scanCommand2 = (command, dialect, scan) => {
|
|
34714
35008
|
let segments;
|
|
34715
35009
|
try {
|
|
34716
35010
|
segments = segmentsOf(command, dialect);
|
|
34717
35011
|
} catch {
|
|
34718
|
-
return;
|
|
35012
|
+
return null;
|
|
34719
35013
|
}
|
|
34720
|
-
for (const
|
|
34721
|
-
|
|
34722
|
-
const seg = newSeg();
|
|
34723
|
-
let at = 0;
|
|
34724
|
-
while (ASSIGN.test(words[at] ?? ""))
|
|
34725
|
-
at += 1;
|
|
34726
|
-
for (const word of words.slice(0, at))
|
|
34727
|
-
note(scan, at === words.length ? null : seg, word);
|
|
34728
|
-
let declare = at;
|
|
34729
|
-
if (["builtin", "command"].includes(words[declare] ?? ""))
|
|
34730
|
-
declare += 1;
|
|
34731
|
-
if (DECLARES.has(words[declare] ?? "")) {
|
|
34732
|
-
for (let index = declare + 1;index < words.length; index += 1) {
|
|
34733
|
-
note(scan, null, words[index]);
|
|
34734
|
-
if (expanded.has(index))
|
|
34735
|
-
scan.risky ??= UNREADABLE;
|
|
34736
|
-
}
|
|
35014
|
+
for (const [index, segment] of segments.entries()) {
|
|
35015
|
+
if (segment.unanalyzable)
|
|
34737
35016
|
continue;
|
|
34738
|
-
|
|
34739
|
-
|
|
34740
|
-
const
|
|
34741
|
-
|
|
34742
|
-
|
|
34743
|
-
|
|
34744
|
-
|
|
34745
|
-
seg.runs ||= scan.runs;
|
|
34746
|
-
scan.runs ||= before;
|
|
34747
|
-
}
|
|
34748
|
-
scan.words.push(...seg.words);
|
|
34749
|
-
const reaches = () => seg.runs || mayBeWorkit(seg.words, scan.cwd);
|
|
34750
|
-
if (seg.identity && reaches())
|
|
34751
|
-
scan.hit ??= seg.identity;
|
|
34752
|
-
if (seg.scoped && reaches())
|
|
34753
|
-
scan.state ??= seg.scoped;
|
|
34754
|
-
scan.runs ||= seg.runs;
|
|
35017
|
+
bindLoop(segment.words, segments.slice(index + 1), scan);
|
|
35018
|
+
const words = pastKeywords(segment.words);
|
|
35019
|
+
const fed = scan.fed;
|
|
35020
|
+
scan.fed = null;
|
|
35021
|
+
const hit = segmentEntry(segment, words, dialect, scan, fed);
|
|
35022
|
+
if (hit)
|
|
35023
|
+
return hit;
|
|
34755
35024
|
}
|
|
35025
|
+
return null;
|
|
34756
35026
|
};
|
|
34757
|
-
var
|
|
34758
|
-
|
|
34759
|
-
const
|
|
34760
|
-
if (
|
|
34761
|
-
|
|
34762
|
-
|
|
35027
|
+
var bindLoop = (raw, after, scan) => {
|
|
35028
|
+
const at = raw.findIndex((word) => !KEYWORDS3.has(word));
|
|
35029
|
+
const verb = raw[at];
|
|
35030
|
+
if ((verb === "for" || verb === "select") && raw[at + 2] === "in") {
|
|
35031
|
+
const name = raw[at + 1] ?? "";
|
|
35032
|
+
const items = raw.slice(at + 3);
|
|
35033
|
+
const item = items.find((word) => entryNamed(word, scan)) ?? items[0];
|
|
35034
|
+
if (/^[A-Za-z_]\w*$/u.test(name) && item !== undefined)
|
|
35035
|
+
scan.vars.set(name, expand(item, scan.vars));
|
|
35036
|
+
return;
|
|
35037
|
+
}
|
|
35038
|
+
const read = raw.indexOf("read");
|
|
35039
|
+
if (read < 0 || !raw.slice(0, read).some((word) => word === "while" || word === "until"))
|
|
35040
|
+
return;
|
|
35041
|
+
const fed = after.find((segment) => segment.words[0] === "done")?.stdin?.[0];
|
|
35042
|
+
const line = fed?.split(`
|
|
35043
|
+
`)[0]?.trim();
|
|
35044
|
+
const name = raw.slice(read + 1).find((word) => /^[A-Za-z_]\w*$/u.test(word));
|
|
35045
|
+
if (name && line)
|
|
35046
|
+
scan.vars.set(name, line);
|
|
35047
|
+
};
|
|
35048
|
+
var segmentEntry = (segment, words, dialect, scan, fed) => {
|
|
35049
|
+
const verb = baseName3(words[0] ?? "");
|
|
35050
|
+
if (["cd", "pushd", "chdir", "set-location", "sl"].includes(verb)) {
|
|
35051
|
+
const target = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
|
|
35052
|
+
const moved = target === undefined ? userHome(process.env) : expand(target, scan.vars);
|
|
35053
|
+
scan.dir = moved === "-" || /[$`]/u.test(moved) ? null : path60.isAbsolute(moved) ? moved : scan.dir && path60.resolve(scan.dir, moved);
|
|
35054
|
+
if (scan.dir === null)
|
|
35055
|
+
scan.vars.delete("PWD");
|
|
35056
|
+
else
|
|
35057
|
+
scan.vars.set("PWD", scan.dir);
|
|
34763
35058
|
return null;
|
|
34764
|
-
|
|
34765
|
-
if (
|
|
34766
|
-
|
|
34767
|
-
|
|
35059
|
+
}
|
|
35060
|
+
if (verb === "popd") {
|
|
35061
|
+
scan.dir = null;
|
|
35062
|
+
return null;
|
|
35063
|
+
}
|
|
35064
|
+
const declares = ["export", "declare", "typeset", "local", "readonly"].includes(verb);
|
|
35065
|
+
const assigns = declares ? words.slice(1) : words.every((word) => /^[A-Za-z_]\w*=/u.test(word)) ? words : [];
|
|
35066
|
+
for (const word of assigns) {
|
|
35067
|
+
const [name = "", value] = word.split(/=(.*)/su);
|
|
35068
|
+
if (value !== undefined && /^[A-Za-z_]\w*$/u.test(name))
|
|
35069
|
+
scan.vars.set(name, expand(value.replace(/^(['"])(.*)\1$/su, "$2"), scan.vars));
|
|
35070
|
+
}
|
|
35071
|
+
const options = optionsEntry(declares ? words.slice(1) : words, scan);
|
|
35072
|
+
if (options)
|
|
35073
|
+
return options;
|
|
35074
|
+
if (verb === "exec" && words.slice(1).every((word) => /^\d+$/u.test(word))) {
|
|
35075
|
+
for (const input of segment.inputs ?? [])
|
|
35076
|
+
if (entryNamed(input, scan))
|
|
35077
|
+
for (const fd of words.slice(1))
|
|
35078
|
+
scan.fds.add(fd);
|
|
35079
|
+
}
|
|
35080
|
+
const inputs = segment.inputs ?? [];
|
|
35081
|
+
const entry = runsEntry(words, inputs, scan) ?? expandedCommand(words, scan) ?? opaqueEntry(words, inputs, { ...scan, fed });
|
|
35082
|
+
if (entry)
|
|
35083
|
+
return entry;
|
|
35084
|
+
if (segment.pipe)
|
|
35085
|
+
scan.fed = words.slice(1).flatMap((word) => word.split(TOKENS2)).map((token) => token ? tokenEntry(token, scan) : null).find(Boolean) ?? null;
|
|
35086
|
+
noteLink(words, scan);
|
|
35087
|
+
if (scan.depth >= 4)
|
|
35088
|
+
return null;
|
|
35089
|
+
const nested = (script) => scanCommand2(script, dialect, {
|
|
35090
|
+
...scan,
|
|
35091
|
+
vars: new Map(scan.vars),
|
|
35092
|
+
fed: null,
|
|
35093
|
+
depth: scan.depth + 1
|
|
35094
|
+
});
|
|
35095
|
+
const scripts = [...segment.subs ?? []];
|
|
35096
|
+
const script = shellScript2(words) ?? cmdScript2(words) ?? workitScript(words);
|
|
35097
|
+
if (script)
|
|
35098
|
+
scripts.push(script);
|
|
35099
|
+
if (!script && /^(?:ba|z|da|k)?sh$/u.test(verb) && words.slice(1).every((word) => word.startsWith("-")) || verb === "at" || verb === "batch")
|
|
35100
|
+
scripts.push(...segment.stdin ?? []);
|
|
35101
|
+
for (const text of scripts) {
|
|
35102
|
+
const hit = nested(text);
|
|
35103
|
+
if (hit)
|
|
35104
|
+
return hit;
|
|
35105
|
+
}
|
|
35106
|
+
return null;
|
|
34768
35107
|
};
|
|
34769
|
-
var
|
|
34770
|
-
const
|
|
34771
|
-
if (
|
|
34772
|
-
return powershellChange(command, identity);
|
|
34773
|
-
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))
|
|
35108
|
+
var cmdScript2 = (words) => {
|
|
35109
|
+
const name = baseName3(words[0] ?? "");
|
|
35110
|
+
if (!/^(?:cmd|pwsh|powershell)$/u.test(name))
|
|
34774
35111
|
return null;
|
|
34775
|
-
const
|
|
34776
|
-
|
|
34777
|
-
cwd: options.cwd,
|
|
34778
|
-
hit: null,
|
|
34779
|
-
state: null,
|
|
34780
|
-
shell: null,
|
|
34781
|
-
risky: null,
|
|
34782
|
-
runs: false,
|
|
34783
|
-
words: []
|
|
34784
|
-
};
|
|
34785
|
-
scanCommand2(command, dialect, 0, scan);
|
|
34786
|
-
if (scan.hit)
|
|
34787
|
-
return scan.hit;
|
|
34788
|
-
if (scan.state)
|
|
34789
|
-
return scan.state;
|
|
34790
|
-
if (scan.shell && (scan.runs || mayBeWorkit(scan.words, scan.cwd)))
|
|
34791
|
-
return scan.shell;
|
|
34792
|
-
return scan.runs ? scan.risky : null;
|
|
35112
|
+
const flag = words.findIndex((word, at) => at > 0 && /^[/-](?:c|k|command)$/iu.test(word));
|
|
35113
|
+
return flag < 0 ? null : words.slice(flag + 1).join(" ").replaceAll("\\", "/") || null;
|
|
34793
35114
|
};
|
|
34794
|
-
var
|
|
34795
|
-
if (
|
|
34796
|
-
return
|
|
34797
|
-
|
|
35115
|
+
var workitScript = (words) => {
|
|
35116
|
+
if (!/^workit(?:-cli)?$/u.test(baseName3(words[0] ?? "")))
|
|
35117
|
+
return null;
|
|
35118
|
+
const dash = words.indexOf("--");
|
|
35119
|
+
return dash < 0 ? null : words.slice(dash + 1).join(" ") || null;
|
|
35120
|
+
};
|
|
35121
|
+
var substitutions2 = (command) => {
|
|
35122
|
+
const found = [];
|
|
35123
|
+
for (let at = command.indexOf("$(");at >= 0 && found.length < 32; at = command.indexOf("$(", at + 1)) {
|
|
35124
|
+
if (command[at + 2] === "(")
|
|
35125
|
+
continue;
|
|
35126
|
+
let depth = 1;
|
|
35127
|
+
let end = at + 2;
|
|
35128
|
+
for (;end < command.length && depth > 0; end += 1)
|
|
35129
|
+
if (command[end] === "(")
|
|
35130
|
+
depth += 1;
|
|
35131
|
+
else if (command[end] === ")")
|
|
35132
|
+
depth -= 1;
|
|
35133
|
+
found.push(command.slice(at + 2, end - 1));
|
|
35134
|
+
}
|
|
35135
|
+
return found;
|
|
35136
|
+
};
|
|
35137
|
+
var hookEntryRun = (cwd, command, dialect = "posix") => {
|
|
35138
|
+
const scan = (text) => scanCommand2(text, dialect, {
|
|
35139
|
+
dir: cwd,
|
|
35140
|
+
vars: new Map([["PWD", cwd]]),
|
|
35141
|
+
links: new Set,
|
|
35142
|
+
fds: new Set,
|
|
35143
|
+
fed: null,
|
|
35144
|
+
depth: 0
|
|
35145
|
+
});
|
|
35146
|
+
const texts = dialect === "posix" && /[A-Za-z]:\\/u.test(command) ? [command, command.replaceAll("\\", "/")] : [command];
|
|
35147
|
+
for (const text of texts) {
|
|
35148
|
+
const hit = scan(text) ?? substitutions2(text).map(scan).find(Boolean);
|
|
35149
|
+
if (hit)
|
|
35150
|
+
return hit;
|
|
35151
|
+
}
|
|
35152
|
+
return null;
|
|
34798
35153
|
};
|
|
35154
|
+
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).`;
|
|
34799
35155
|
|
|
34800
35156
|
// packages/workit-core/src/hooks/handle.ts
|
|
34801
35157
|
var usable2 = (value) => value === "native" || value === "partial";
|
|
@@ -35547,7 +35903,7 @@ var enforceToolPolicy = (event, ctx) => {
|
|
|
35547
35903
|
return approveInDialog(approve.ids, event, ctx);
|
|
35548
35904
|
const inline = typeof command === "string" ? inlineCallIn(command) : null;
|
|
35549
35905
|
if (inline && !inline.plain)
|
|
35550
|
-
return { block: true, reason: inlineCallDeny(inline.fix) };
|
|
35906
|
+
return { block: true, reason: inlineCallDeny(inline.fix, inline.file) };
|
|
35551
35907
|
if (inline?.plain && ctx.mode === "tui" && ctx.hasUI) {
|
|
35552
35908
|
const gated = isReleaseNotesCall(inline.words) && inlineAskFor(inline.words, inlineCallCwd(inline, ctx.cwd)) ? undefined : gate({
|
|
35553
35909
|
kind: "shell.pre",
|