@workit-dev/codex 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/.codex-plugin/plugin.json +1 -1
- package/dist/launch-mcp.js +200 -69
- package/dist/{workit-hook-kdr9kpqg.js → workit-hook-msgjv4q2.js} +1360 -1079
- package/dist/workit-hook.js +1 -1
- package/package.json +3 -3
|
@@ -4147,7 +4147,7 @@ var workspaceConfigSchema = looseObject({
|
|
|
4147
4147
|
})),
|
|
4148
4148
|
models: optional(looseObject({ roles: modelRoles })),
|
|
4149
4149
|
resources: optional(unknown()),
|
|
4150
|
-
remotes: optional(array(nonBlank.check(refine((pattern) =>
|
|
4150
|
+
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/*)")))),
|
|
4151
4151
|
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")))),
|
|
4152
4152
|
additiveRiskPaths: optional(array(nonBlank)),
|
|
4153
4153
|
autonomy: optional(looseObject(Object.fromEntries(["push", "pr", "merge", "release", "rerun"].map((kind) => [
|
|
@@ -4516,6 +4516,7 @@ var canonicalGlob = (glob) => {
|
|
|
4516
4516
|
return real + (prefix.endsWith("/") ? "/" : "") + rest;
|
|
4517
4517
|
};
|
|
4518
4518
|
var globSpecificity = (glob) => glob.replaceAll("\\", "/").split("/").filter((segment) => segment.length > 0 && !/[*?[\]{]/.test(segment)).length;
|
|
4519
|
+
var workspaceMatches = (cwd, entries) => matchingEntries(cwd, entries);
|
|
4519
4520
|
var selectWorkspaceMatch = (matches, cwd, workspaceName) => {
|
|
4520
4521
|
if (workspaceName !== undefined) {
|
|
4521
4522
|
const named = matches.filter((entry) => entry.name === workspaceName);
|
|
@@ -4537,15 +4538,32 @@ var selectWorkspaceMatch = (matches, cwd, workspaceName) => {
|
|
|
4537
4538
|
}
|
|
4538
4539
|
return mostSpecific[0];
|
|
4539
4540
|
};
|
|
4540
|
-
var
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4541
|
+
var HOSTLESS_REMOTE = /^[\w-]+\/\*$/u;
|
|
4542
|
+
var expandRemotePattern = (entry, pattern) => {
|
|
4543
|
+
if (!HOSTLESS_REMOTE.test(pattern.trim()))
|
|
4544
|
+
return pattern;
|
|
4545
|
+
const vcs = entry.vcs ?? {};
|
|
4546
|
+
const host = typeof vcs.host === "string" && vcs.host.trim().replace(/^https?:\/\/|\/.*$/giu, "") || `${vcs.provider === "gitlab" ? "gitlab" : "github"}.com`;
|
|
4547
|
+
return `https://${host}/${pattern.trim()}`;
|
|
4548
|
+
};
|
|
4549
|
+
var isRemotePattern = (pattern) => !!remotePattern(expandRemotePattern({}, pattern));
|
|
4550
|
+
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));
|
|
4551
|
+
var resolveWorkspaceFromEntries = (cwd, entries, workspaceName, remotes) => {
|
|
4552
|
+
const globbed = matchingEntries(cwd, entries);
|
|
4553
|
+
const listed = !remotes || globbed.length || !entries.some((entry) => entry.remotes) ? [] : checkoutRemotes(cwd);
|
|
4554
|
+
const origin = listed instanceof Error ? [] : listed.filter((item) => item.name === "origin");
|
|
4555
|
+
const hits = entries.filter((entry) => origin.length && origin.every((item) => remoteClaimOf(entry, item.key)));
|
|
4556
|
+
const exact = hits.filter((entry) => origin.every((item) => remoteClaimOf(entry, item.key, true)));
|
|
4557
|
+
const ranked = exact.length ? exact : hits;
|
|
4558
|
+
if (workspaceName === undefined && ranked.length > 1)
|
|
4559
|
+
return null;
|
|
4560
|
+
return selectWorkspaceMatch(hits.length ? workspaceName ? hits : ranked : globbed, cwd, workspaceName) ?? null;
|
|
4561
|
+
};
|
|
4562
|
+
var resolveWorkspaceFrom = (cwd, dir, workspaceName, remotes) => {
|
|
4545
4563
|
const result = readWorkspacesResult(dir);
|
|
4546
4564
|
if (result.status === "malformed" || result.status === "invalid")
|
|
4547
4565
|
throw new WorkspaceConfigError(result.error);
|
|
4548
|
-
return resolveWorkspaceFromEntries(cwd, result.entries, workspaceName);
|
|
4566
|
+
return resolveWorkspaceFromEntries(cwd, result.entries, workspaceName, remotes);
|
|
4549
4567
|
};
|
|
4550
4568
|
var runtimeWorkspacePolicySchema = (kind) => {
|
|
4551
4569
|
const key = kind === "branch" ? "branchPolicy" : kind === "commit" ? "commitPolicy" : "vcs";
|
|
@@ -4595,10 +4613,12 @@ var matchRuntimeWorkspace = (cwd, dir = configDir()) => {
|
|
|
4595
4613
|
if (!glob.ok)
|
|
4596
4614
|
throw new WorkspaceConfigError(`${file} workspace ${entry.name}: ${glob.error}`);
|
|
4597
4615
|
}
|
|
4598
|
-
const matches = matchingEntries(cwd, entries ?? []);
|
|
4599
4616
|
const workspaceName = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
|
|
4600
|
-
const selected =
|
|
4601
|
-
|
|
4617
|
+
const selected = resolveWorkspaceFromEntries(cwd, entries ?? [], workspaceName, true);
|
|
4618
|
+
if (!selected)
|
|
4619
|
+
return null;
|
|
4620
|
+
const matches = matchingEntries(cwd, entries ?? []);
|
|
4621
|
+
return { file, selected, matches: matches.length ? matches : [selected] };
|
|
4602
4622
|
};
|
|
4603
4623
|
var resolveRuntimeReleaseTracks = (cwd) => {
|
|
4604
4624
|
const matched = matchRuntimeWorkspace(cwd);
|
|
@@ -13388,6 +13408,7 @@ var youTrackHostAllowed = (allowed, host) => {
|
|
|
13388
13408
|
};
|
|
13389
13409
|
|
|
13390
13410
|
// packages/workit-core/src/autonomy.ts
|
|
13411
|
+
var resolveWorkspaceFrom2 = (cwd, dir, name) => resolveWorkspaceFrom(cwd, dir, name, true);
|
|
13391
13412
|
var accountHomeDir = () => {
|
|
13392
13413
|
const home = grantsHome.resolve();
|
|
13393
13414
|
return home === null ? null : configDir2({ HOME: home });
|
|
@@ -13420,11 +13441,11 @@ var accountUnread = () => {
|
|
|
13420
13441
|
};
|
|
13421
13442
|
var entriesIn = (dir) => dir === null ? [] : loadWorkspacesFrom(dir);
|
|
13422
13443
|
var fileSource = (dir = accountDir()) => ({
|
|
13423
|
-
resolve: (cwd, name) => dir === null ? null :
|
|
13444
|
+
resolve: (cwd, name) => dir === null ? null : resolveWorkspaceFrom2(cwd, dir, name),
|
|
13424
13445
|
entries: () => entriesIn(dir)
|
|
13425
13446
|
});
|
|
13426
13447
|
var sealedSource = (entries) => ({
|
|
13427
|
-
resolve: (cwd, name) => resolveWorkspaceFromEntries(cwd, entries, name),
|
|
13448
|
+
resolve: (cwd, name) => resolveWorkspaceFromEntries(cwd, entries, name, true),
|
|
13428
13449
|
entries: () => entries
|
|
13429
13450
|
});
|
|
13430
13451
|
var sealOf = () => {
|
|
@@ -13450,8 +13471,8 @@ var youTrackWritesPolicy = (cwd) => {
|
|
|
13450
13471
|
return ASK;
|
|
13451
13472
|
const auto = (entry) => youtrackOf(entry)?.writes === "auto";
|
|
13452
13473
|
const name = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
|
|
13453
|
-
const named =
|
|
13454
|
-
const folder = name ?
|
|
13474
|
+
const named = resolveWorkspaceFrom2(cwd, dir, name);
|
|
13475
|
+
const folder = name ? resolveWorkspaceFrom2(cwd, dir) : named;
|
|
13455
13476
|
if (!auto(named) || !auto(folder))
|
|
13456
13477
|
return ASK;
|
|
13457
13478
|
const [a, b] = [autoHostsOf(named), autoHostsOf(folder)];
|
|
@@ -13706,7 +13727,8 @@ function resolveWith(source, cwd, world, target) {
|
|
|
13706
13727
|
const above = checkoutsAbove(cwd);
|
|
13707
13728
|
for (const where of above instanceof Error ? [above] : above)
|
|
13708
13729
|
autonomy = capAt(source, autonomy, where, where instanceof Error ? "git" : `checkout ${where}`, "a worktree or submodule never exceeds it", true);
|
|
13709
|
-
|
|
13730
|
+
const own = real && workspaceMatches(cwd, source.entries()).length === 0 ? real : undefined;
|
|
13731
|
+
return capAtRemotes(source, autonomy, cwd, target, own);
|
|
13710
13732
|
}
|
|
13711
13733
|
var needsAccount = (autonomy) => autonomy.configured.length > 0 && !autonomy.accountConfigured;
|
|
13712
13734
|
function stricter(current, sealed, note, unblock) {
|
|
@@ -13745,17 +13767,31 @@ function stricter(current, sealed, note, unblock) {
|
|
|
13745
13767
|
note: current.note ? `${current.note}; ${note}` : note
|
|
13746
13768
|
};
|
|
13747
13769
|
}
|
|
13748
|
-
function capAtRemotes(source, autonomy, cwd, target) {
|
|
13770
|
+
function capAtRemotes(source, autonomy, cwd, target, own) {
|
|
13749
13771
|
const claiming = source.entries().filter((entry) => entry.remotes?.length);
|
|
13750
13772
|
if (claiming.length === 0)
|
|
13751
13773
|
return autonomy;
|
|
13752
13774
|
const remotes = target === undefined ? checkoutRemotes(cwd) : typeof target === "function" ? target() : target;
|
|
13753
13775
|
if (remotes instanceof Error)
|
|
13754
13776
|
return capAt(source, autonomy, remotes, target === undefined ? "git" : "target", "a target that cannot be resolved never raises grants");
|
|
13777
|
+
const listed = Array.isArray(remotes) ? remotes : remotes.remotes;
|
|
13778
|
+
const capped = own ? capAtOwnClaim(source, autonomy, cwd, own, target && listed) : autonomy;
|
|
13779
|
+
return capAtClaims(source, capped, listed, claiming);
|
|
13780
|
+
}
|
|
13781
|
+
function capAtOwnClaim(source, autonomy, cwd, own, judged) {
|
|
13782
|
+
const push = judged ? { remotes: judged } : pushTarget(cwd, pushRemoteName(cwd) ?? "");
|
|
13783
|
+
if (push instanceof Error)
|
|
13784
|
+
return capAt(source, autonomy, push, "push target", "a target that cannot be resolved never raises grants");
|
|
13785
|
+
const unclaimed = push.remotes.filter((remote) => !remoteClaimOf(own, remote.key));
|
|
13786
|
+
if (unclaimed.length === 0 && push.remotes.length > 0)
|
|
13787
|
+
return autonomy;
|
|
13788
|
+
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>`);
|
|
13789
|
+
}
|
|
13790
|
+
function capAtClaims(source, autonomy, listed, claiming) {
|
|
13755
13791
|
let capped = autonomy;
|
|
13756
|
-
for (const remote of
|
|
13792
|
+
for (const remote of listed)
|
|
13757
13793
|
for (const entry of claiming) {
|
|
13758
|
-
const pattern = entry
|
|
13794
|
+
const pattern = remoteClaimOf(entry, remote.key);
|
|
13759
13795
|
if (pattern)
|
|
13760
13796
|
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");
|
|
13761
13797
|
}
|
|
@@ -13783,7 +13819,7 @@ function claimsIn(target, entries) {
|
|
|
13783
13819
|
return target;
|
|
13784
13820
|
const claiming = entries.filter((entry) => entry.remotes?.length);
|
|
13785
13821
|
return target.remotes.flatMap((remote) => claiming.flatMap((entry) => {
|
|
13786
|
-
const pattern = entry
|
|
13822
|
+
const pattern = remoteClaimOf(entry, remote.key);
|
|
13787
13823
|
return pattern ? [{ url: remote.url, workspace: entry.name, pattern }] : [];
|
|
13788
13824
|
}));
|
|
13789
13825
|
}
|
|
@@ -14264,9 +14300,9 @@ var arithmeticEnd = (command, start) => {
|
|
|
14264
14300
|
const end = substitutionEnd(command, start);
|
|
14265
14301
|
return command[end - 1] === ")" && end > start + 2 ? end : 0;
|
|
14266
14302
|
};
|
|
14267
|
-
var segmentsOf = (command, dialect = "posix") => {
|
|
14303
|
+
var segmentsOf = (command, dialect = "posix", options = {}) => {
|
|
14268
14304
|
try {
|
|
14269
|
-
return tokenize(command, dialect);
|
|
14305
|
+
return tokenize(command, dialect, options.spans === true);
|
|
14270
14306
|
} catch (error) {
|
|
14271
14307
|
const why = error instanceof ShellAnalysisError ? error.message : String(error);
|
|
14272
14308
|
return [{ words: [], redirects: [], unanalyzable: why }];
|
|
@@ -14276,12 +14312,14 @@ var afterEnv = (words) => {
|
|
|
14276
14312
|
const at = words.map((word) => word.split(/[\\/]/).at(-1)).lastIndexOf("env");
|
|
14277
14313
|
return at >= 0 && words.slice(at + 1).every((word, index, rest) => /^-|=/.test(word) || /^-[^-]*[uCS]$|^--(?:unset|chdir|split-string)$/.test(rest[index - 1] ?? ""));
|
|
14278
14314
|
};
|
|
14279
|
-
var tokenize = (command, dialect) => {
|
|
14315
|
+
var tokenize = (command, dialect, spans) => {
|
|
14280
14316
|
const posix = dialect === "posix";
|
|
14281
14317
|
const segments = [];
|
|
14282
14318
|
let current = { words: [], redirects: [] };
|
|
14283
14319
|
let word = "";
|
|
14284
14320
|
let inWord = false;
|
|
14321
|
+
let wordStart = -1;
|
|
14322
|
+
let cursor = 0;
|
|
14285
14323
|
let expanding = false;
|
|
14286
14324
|
let afterOperator = false;
|
|
14287
14325
|
let pending = null;
|
|
@@ -14292,9 +14330,13 @@ var tokenize = (command, dialect) => {
|
|
|
14292
14330
|
if (!inWord)
|
|
14293
14331
|
return;
|
|
14294
14332
|
const text = MARKERS.test(word) ? literal2(word) : word;
|
|
14333
|
+
const span = [wordStart, cursor];
|
|
14295
14334
|
if (pending === "redirect") {
|
|
14296
|
-
if (!duplicate || !/^(?:\d+-?|-)$/.test(text))
|
|
14335
|
+
if (!duplicate || !/^(?:\d+-?|-)$/.test(text)) {
|
|
14297
14336
|
current.redirects.push(text);
|
|
14337
|
+
if (spans)
|
|
14338
|
+
(current.redirectSpans ??= []).push(span);
|
|
14339
|
+
}
|
|
14298
14340
|
} else if (pending === "heredoc")
|
|
14299
14341
|
heredocs.push({ delimiter: text.replace(/^-/, ""), owner: current });
|
|
14300
14342
|
else if (pending === "herestring")
|
|
@@ -14302,17 +14344,20 @@ var tokenize = (command, dialect) => {
|
|
|
14302
14344
|
else if (pending === "input")
|
|
14303
14345
|
(current.inputs ??= []).push(text);
|
|
14304
14346
|
else {
|
|
14305
|
-
const
|
|
14347
|
+
const at0 = current.words.length;
|
|
14306
14348
|
if (/^[^=-][^=]*=/.test(word) && afterEnv(current.words))
|
|
14307
14349
|
word = word.replace(/^[^=]*/, (name) => name.replace(/\W/g, "_"));
|
|
14308
14350
|
current.words.push(...MARKERS.test(word) ? expandBraces(word) : [word]);
|
|
14351
|
+
if (spans)
|
|
14352
|
+
(current.spans ??= []).push(...current.words.slice(at0).map(() => span));
|
|
14309
14353
|
if (expanding || !posix && word.startsWith("@"))
|
|
14310
|
-
(current.expands ??= []).push(...current.words.slice(
|
|
14354
|
+
(current.expands ??= []).push(...current.words.slice(at0).map((_, i) => at0 + i));
|
|
14311
14355
|
}
|
|
14312
14356
|
pending = null;
|
|
14313
14357
|
duplicate = false;
|
|
14314
14358
|
word = "";
|
|
14315
14359
|
inWord = false;
|
|
14360
|
+
wordStart = -1;
|
|
14316
14361
|
expanding = false;
|
|
14317
14362
|
};
|
|
14318
14363
|
const flushSegment = () => {
|
|
@@ -14337,9 +14382,12 @@ var tokenize = (command, dialect) => {
|
|
|
14337
14382
|
};
|
|
14338
14383
|
const plain = posix ? PLAIN_POSIX : PLAIN_POWERSHELL;
|
|
14339
14384
|
for (let index = 0;index < command.length; index++) {
|
|
14385
|
+
cursor = index;
|
|
14340
14386
|
plain.lastIndex = index;
|
|
14341
14387
|
const run = plain.exec(command);
|
|
14342
14388
|
if (run) {
|
|
14389
|
+
if (wordStart < 0)
|
|
14390
|
+
wordStart = index;
|
|
14343
14391
|
word += run[0];
|
|
14344
14392
|
inWord = true;
|
|
14345
14393
|
if (EXPANDING_RUN.test(run[0]))
|
|
@@ -14365,9 +14413,11 @@ var tokenize = (command, dialect) => {
|
|
|
14365
14413
|
word += text;
|
|
14366
14414
|
inWord = true;
|
|
14367
14415
|
index = end;
|
|
14368
|
-
} else if (posix && char === "$" && next === '"')
|
|
14416
|
+
} else if (posix && char === "$" && next === '"') {
|
|
14417
|
+
if (wordStart < 0)
|
|
14418
|
+
wordStart = index;
|
|
14369
14419
|
continue;
|
|
14370
|
-
else if (char === "'" || char === '"') {
|
|
14420
|
+
} else if (char === "'" || char === '"') {
|
|
14371
14421
|
const end = closingQuote(command, index, dialect);
|
|
14372
14422
|
const body = command.slice(index + 1, end < 0 ? undefined : end);
|
|
14373
14423
|
if (posix && char === '"' && /\$\(|`/.test(body))
|
|
@@ -14408,6 +14458,7 @@ var tokenize = (command, dialect) => {
|
|
|
14408
14458
|
index = end;
|
|
14409
14459
|
} else if (posix && char === "(" && (pending === "input" || pending === "redirect")) {
|
|
14410
14460
|
const sign = pending === "input" ? "<" : ">";
|
|
14461
|
+
wordStart = index - 1;
|
|
14411
14462
|
pending = null;
|
|
14412
14463
|
const end = substitutionEnd(command, index);
|
|
14413
14464
|
const inner = command.slice(index + 1, end);
|
|
@@ -14420,8 +14471,10 @@ var tokenize = (command, dialect) => {
|
|
|
14420
14471
|
if (char === "(" && inWord && word.endsWith("$")) {
|
|
14421
14472
|
word = word.slice(0, -1);
|
|
14422
14473
|
inWord = word !== "";
|
|
14423
|
-
if (!inWord)
|
|
14474
|
+
if (!inWord) {
|
|
14424
14475
|
expanding = false;
|
|
14476
|
+
wordStart = -1;
|
|
14477
|
+
}
|
|
14425
14478
|
}
|
|
14426
14479
|
group(char === "(" ? "open" : "close");
|
|
14427
14480
|
} else if (!posix && (char === "{" || char === "}")) {
|
|
@@ -14456,6 +14509,7 @@ var tokenize = (command, dialect) => {
|
|
|
14456
14509
|
if (inWord && /^\d$/.test(word)) {
|
|
14457
14510
|
word = "";
|
|
14458
14511
|
inWord = false;
|
|
14512
|
+
wordStart = -1;
|
|
14459
14513
|
} else
|
|
14460
14514
|
flushWord();
|
|
14461
14515
|
if (command[index + 1] === ">")
|
|
@@ -14487,7 +14541,10 @@ var tokenize = (command, dialect) => {
|
|
|
14487
14541
|
word += char;
|
|
14488
14542
|
inWord = true;
|
|
14489
14543
|
}
|
|
14544
|
+
if (inWord && wordStart < 0)
|
|
14545
|
+
wordStart = cursor;
|
|
14490
14546
|
}
|
|
14547
|
+
cursor = command.length;
|
|
14491
14548
|
flushSegment();
|
|
14492
14549
|
return segments;
|
|
14493
14550
|
};
|
|
@@ -20719,8 +20776,8 @@ var writeTargets = (input) => {
|
|
|
20719
20776
|
return paths.length > 0 ? paths : null;
|
|
20720
20777
|
};
|
|
20721
20778
|
// packages/workit-core/src/hooks/standing.ts
|
|
20722
|
-
import
|
|
20723
|
-
import
|
|
20779
|
+
import fs24 from "node:fs";
|
|
20780
|
+
import path37 from "node:path";
|
|
20724
20781
|
|
|
20725
20782
|
// packages/workit-core/src/approvals/store.ts
|
|
20726
20783
|
var REQUEST_TTL_MS = 30 * 60000;
|
|
@@ -20773,6 +20830,185 @@ var approveCallIn = (command, dialect = "posix") => {
|
|
|
20773
20830
|
};
|
|
20774
20831
|
var approveCallDeny = (fix) => `Run \`${fix}\` as its own call: no chain, pipe, substitution, leading cd, env prefix or redirect around it, so the host can show the request and record the user's answer.`;
|
|
20775
20832
|
|
|
20833
|
+
// packages/workit-core/src/hooks/cwd-normalize.ts
|
|
20834
|
+
var DIR = String.raw`(?:[A-Za-z0-9_./@%+:,=-]|(?<=[A-Za-z0-9])~)+|'[^'$${"`"}\n]*'|"(?:[^"$${"`"}\\!\n]|\\(?=[^"$${"`"}\\!\n]))*"`;
|
|
20835
|
+
var COMPOUND2 = new RegExp(String.raw`^\s*cd\s+(${DIR})\s*&&\s*(workit(?:\s[\s\S]*)?)$`, "u");
|
|
20836
|
+
var UNSAFE = /[\p{Cf}\p{Zl}\p{Zp}]|[^\P{Cc}\n]/u;
|
|
20837
|
+
var newlines = (text) => text.split(`
|
|
20838
|
+
`).length - 1;
|
|
20839
|
+
var writtenWord = (command, segment, index) => {
|
|
20840
|
+
const span = segment.spans?.[index];
|
|
20841
|
+
if (!span)
|
|
20842
|
+
return null;
|
|
20843
|
+
const glued = (other) => other !== undefined && other !== span && (other[1] === span[0] || other[0] === span[1]);
|
|
20844
|
+
if (glued(segment.spans?.[index - 1]) || glued(segment.spans?.[index + 1]))
|
|
20845
|
+
return null;
|
|
20846
|
+
const text = command.slice(span[0], span[1]);
|
|
20847
|
+
const value = segment.words[index] ?? "";
|
|
20848
|
+
return UNSAFE.test(text) || newlines(text) !== newlines(value) ? null : text;
|
|
20849
|
+
};
|
|
20850
|
+
var writtenWords = (command, segment, indexes) => {
|
|
20851
|
+
const texts = [];
|
|
20852
|
+
let last;
|
|
20853
|
+
for (const index of indexes) {
|
|
20854
|
+
const span = segment.spans?.[index];
|
|
20855
|
+
if (span && span === last)
|
|
20856
|
+
continue;
|
|
20857
|
+
last = span;
|
|
20858
|
+
const text = writtenWord(command, segment, index);
|
|
20859
|
+
if (text === null)
|
|
20860
|
+
return null;
|
|
20861
|
+
texts.push(text);
|
|
20862
|
+
}
|
|
20863
|
+
return texts;
|
|
20864
|
+
};
|
|
20865
|
+
var cwdIndependent = (text, colons = false) => {
|
|
20866
|
+
let quoted = false;
|
|
20867
|
+
for (let index = 0;index < text.length; index += 1) {
|
|
20868
|
+
const char = text[index] ?? "";
|
|
20869
|
+
if (char === "\\")
|
|
20870
|
+
index += 1;
|
|
20871
|
+
else if (char === "'" && !quoted) {
|
|
20872
|
+
const end = text.indexOf("'", index + 1);
|
|
20873
|
+
if (end < 0)
|
|
20874
|
+
return false;
|
|
20875
|
+
index = end;
|
|
20876
|
+
} else if (char === '"')
|
|
20877
|
+
quoted = !quoted;
|
|
20878
|
+
else if (char === "$" || char === "`")
|
|
20879
|
+
return false;
|
|
20880
|
+
else if (quoted)
|
|
20881
|
+
continue;
|
|
20882
|
+
else if (/[*?[]/u.test(char) || /[<>]/u.test(char) && text[index + 1] === "(")
|
|
20883
|
+
return false;
|
|
20884
|
+
else if (char === "~") {
|
|
20885
|
+
const start = index === 0 || colons && text[index - 1] === ":";
|
|
20886
|
+
if (!start || !/^(?:\/|:|$)/u.test(text.slice(index + 1, index + 2)))
|
|
20887
|
+
return false;
|
|
20888
|
+
}
|
|
20889
|
+
}
|
|
20890
|
+
return !quoted;
|
|
20891
|
+
};
|
|
20892
|
+
var NOT_A_PATH = /^(?:\d*|true|false|yes|no|on|off|-[\w-]*(?:=\d+)?)$/iu;
|
|
20893
|
+
var cwdFreeAssignment = (text, value) => {
|
|
20894
|
+
const written = text.replace(/^[A-Za-z_]\w*=/u, "");
|
|
20895
|
+
if (!cwdIndependent(written, true))
|
|
20896
|
+
return false;
|
|
20897
|
+
const quotes = /['"\\]/u.test(written);
|
|
20898
|
+
const parts = value.replace(/^[A-Za-z_]\w*=/u, "").split(":");
|
|
20899
|
+
return parts.every((part) => part.startsWith("/") || !quotes && /^~(?:\/|$)/u.test(part) || (part !== "" || parts.length === 1) && NOT_A_PATH.test(part));
|
|
20900
|
+
};
|
|
20901
|
+
var plainQuotedExpansions = (text) => {
|
|
20902
|
+
const bare = text.replaceAll(/\\./gu, "").replaceAll(/\$(?:[A-Za-z_]\w*|\{[A-Za-z_]\w*\})/gu, "");
|
|
20903
|
+
return !bare.includes("$") && !bare.includes("`");
|
|
20904
|
+
};
|
|
20905
|
+
var certainDir = (text, value) => value !== "" && !value.startsWith("-") && (/^(?:"(?:[^"\\]|\\.)*"|'[^']*')$/u.test(text) && (text.startsWith("'") || plainQuotedExpansions(text)) || cwdIndependent(text) && !/[{}]/u.test(text.replaceAll(/'[^']*'|"(?:[^"\\]|\\.)*"|\\./gu, "")));
|
|
20906
|
+
var namesSet = (segments) => {
|
|
20907
|
+
const names = new Set;
|
|
20908
|
+
for (const { words } of segments) {
|
|
20909
|
+
const at = /^(?:export|declare|typeset|local|readonly)$/u.test(words[0] ?? "") ? 1 : 0;
|
|
20910
|
+
const assigns = words.slice(at).filter((word) => /^[A-Za-z_]\w*=/u.test(word));
|
|
20911
|
+
if (at === 1 || assigns.length === words.length)
|
|
20912
|
+
for (const word of assigns)
|
|
20913
|
+
names.add(word.slice(0, word.indexOf("=")));
|
|
20914
|
+
if (words[0] === "read" || words[0] === "mapfile") {
|
|
20915
|
+
for (const word of words.slice(1))
|
|
20916
|
+
if (/^[A-Za-z_]\w*$/u.test(word))
|
|
20917
|
+
names.add(word);
|
|
20918
|
+
}
|
|
20919
|
+
}
|
|
20920
|
+
return names;
|
|
20921
|
+
};
|
|
20922
|
+
var NO_PATH = /^(?:\d+|-[A-Za-z0-9-]*)$/u;
|
|
20923
|
+
var cwdFreeTail = (texts, check = false) => {
|
|
20924
|
+
const [command = "", ...args] = texts;
|
|
20925
|
+
if (command.includes("/") && !command.startsWith("/"))
|
|
20926
|
+
return false;
|
|
20927
|
+
return check || args.every((text) => NO_PATH.test(text) || /^(?:\/|~(?:\/|$))/u.test(text));
|
|
20928
|
+
};
|
|
20929
|
+
var GLOBALS_FIRST = new RegExp(String.raw`^(\s*workit)((?:\s+(?:--json|--cwd(?:=|\s+)(?:${DIR})))+)\s+([a-z][a-z-]*)(?=\s|$)`, "u");
|
|
20930
|
+
var VERB_FIRST = /^((?:--json\s+)*)([a-z][a-z-]*)(?=\s|$)/u;
|
|
20931
|
+
var VERBS = new Set(WORKIT_ALLOWED_VERBS);
|
|
20932
|
+
var FILTERS = new Set(["tail", "head", "grep"]);
|
|
20933
|
+
var clean = (s) => !s.unanalyzable && !s.group && !s.subs?.length && !s.stdin?.length && !s.redirects.length;
|
|
20934
|
+
var stdinOnly = (words) => {
|
|
20935
|
+
const [name, ...args] = words;
|
|
20936
|
+
const operands = args.filter((w) => !w.startsWith("-"));
|
|
20937
|
+
if (name === "grep")
|
|
20938
|
+
return operands.length <= 1 && !args.some((w) => /^-[^-]*[rRf]|^--(recursive|file)/u.test(w));
|
|
20939
|
+
return operands.every((w) => /^\d+$/u.test(w)) && !args.some((w) => w.startsWith("--output"));
|
|
20940
|
+
};
|
|
20941
|
+
var cwdRewrite = (command) => {
|
|
20942
|
+
const match = COMPOUND2.exec(command);
|
|
20943
|
+
const dir = match?.[1];
|
|
20944
|
+
const rest = match?.[2];
|
|
20945
|
+
if (!dir || !rest || dir.startsWith("-"))
|
|
20946
|
+
return null;
|
|
20947
|
+
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "").replaceAll(/'[^']*'|"([^"\\]|\\.)*"/gu, "")))
|
|
20948
|
+
return null;
|
|
20949
|
+
const segments = segmentsOf(rest);
|
|
20950
|
+
const [head, ...filters] = segments;
|
|
20951
|
+
if (!head || head.words[0] !== "workit")
|
|
20952
|
+
return null;
|
|
20953
|
+
if (!segments.every(clean))
|
|
20954
|
+
return null;
|
|
20955
|
+
if (!segments.slice(0, -1).every((s) => s.pipe))
|
|
20956
|
+
return null;
|
|
20957
|
+
if (!filters.every((s) => FILTERS.has(s.words[0] ?? "") && stdinOnly(s.words)))
|
|
20958
|
+
return null;
|
|
20959
|
+
const at = head.words.indexOf("--cwd");
|
|
20960
|
+
if (at >= 0) {
|
|
20961
|
+
const bare = dir.replace(/^(['"])(.*)\1$/u, "$2");
|
|
20962
|
+
return bare[0] === "/" && head.words[at + 1] === bare ? rest : null;
|
|
20963
|
+
}
|
|
20964
|
+
if (head.words.some((w) => w.startsWith("--cwd=")))
|
|
20965
|
+
return null;
|
|
20966
|
+
const args = rest.slice("workit".length).trimStart();
|
|
20967
|
+
const verb = VERB_FIRST.exec(args);
|
|
20968
|
+
if (!verb?.[2] || !VERBS.has(verb[2]))
|
|
20969
|
+
return `workit --cwd ${dir} ${args}`.trimEnd();
|
|
20970
|
+
const json = verb[1] ? " --json" : "";
|
|
20971
|
+
return `workit ${verb[2]} --cwd ${dir}${json}${args.slice(verb[0].length)}`.trimEnd();
|
|
20972
|
+
};
|
|
20973
|
+
var verbFirst = (command) => {
|
|
20974
|
+
const match = GLOBALS_FIRST.exec(command);
|
|
20975
|
+
const [whole, lead, globals, verb] = match ?? [];
|
|
20976
|
+
if (!whole || !verb || !VERBS.has(verb) || !globals?.includes("--cwd"))
|
|
20977
|
+
return null;
|
|
20978
|
+
const segments = segmentsOf(command);
|
|
20979
|
+
if (segments.length !== 1 || !segments.every(clean))
|
|
20980
|
+
return null;
|
|
20981
|
+
return `${lead} ${verb}${globals}${command.slice(whole.length)}`;
|
|
20982
|
+
};
|
|
20983
|
+
var NPX = new RegExp(String.raw`^(\s*(?:cd\s+(?:${DIR})\s*&&\s*)?)npx(?:\s+(?:-y|--yes))*\s+@workit-dev\/cli(?:@[\w.-]+)?(?=\s|$)`, "u");
|
|
20984
|
+
var npxWorkit = (command) => {
|
|
20985
|
+
const match = NPX.exec(command);
|
|
20986
|
+
if (!match)
|
|
20987
|
+
return null;
|
|
20988
|
+
const call = `${match[1]}workit${command.slice(match[0].length)}`;
|
|
20989
|
+
const left = segmentsOf(call).some((s) => s.unanalyzable || s.words.some((w) => /^(npx|@workit-dev\/cli(@\S*)?)$/u.test(w)));
|
|
20990
|
+
return left ? null : cwdRewrite(call) ?? verbFirst(call) ?? call;
|
|
20991
|
+
};
|
|
20992
|
+
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;
|
|
20993
|
+
var cdWorkitSplit = (command) => {
|
|
20994
|
+
const match = COMPOUND2.exec(command);
|
|
20995
|
+
const dir = match?.[1];
|
|
20996
|
+
const rest = match?.[2];
|
|
20997
|
+
if (!dir || !rest || cwdRewrite(command) !== null)
|
|
20998
|
+
return null;
|
|
20999
|
+
const whole = segmentsOf(rest);
|
|
21000
|
+
const boundary = (head) => segmentsOf(head).every((s, at) => s.words.join("\x00") === whole[at]?.words.join("\x00"));
|
|
21001
|
+
for (const op of rest.matchAll(/\|\||;/gu)) {
|
|
21002
|
+
const head = rest.slice(0, op.index).trimEnd();
|
|
21003
|
+
const call = cwdRewrite(`cd ${dir} && ${head}`);
|
|
21004
|
+
if (!call || !boundary(head))
|
|
21005
|
+
continue;
|
|
21006
|
+
const next = segmentsOf(rest.slice(op.index + op[0].length))[0];
|
|
21007
|
+
return next && MUTATING_GIT2.test(next.words.join(" ")) ? call : null;
|
|
21008
|
+
}
|
|
21009
|
+
return null;
|
|
21010
|
+
};
|
|
21011
|
+
|
|
20776
21012
|
// packages/workit-core/src/approvals/youtrack-ask.ts
|
|
20777
21013
|
var TIME = "markdown file minutes text date";
|
|
20778
21014
|
var FLAGS = {
|
|
@@ -20784,8 +21020,8 @@ var FLAGS = {
|
|
|
20784
21020
|
};
|
|
20785
21021
|
|
|
20786
21022
|
// packages/workit-core/src/approvals/inline.ts
|
|
20787
|
-
var
|
|
20788
|
-
var OPAQUE_RELEASE_FIX = `workit release --cwd ${
|
|
21023
|
+
var DIR2 = "<dir>";
|
|
21024
|
+
var OPAQUE_RELEASE_FIX = `workit release --cwd ${DIR2} notes approve <version>`;
|
|
20789
21025
|
|
|
20790
21026
|
// packages/workit-core/src/hooks/hosts/claude-code.ts
|
|
20791
21027
|
var CLAUDE_CODE_DESCRIPTOR = {
|
|
@@ -21430,83 +21666,559 @@ function neededChecks(lane, configured) {
|
|
|
21430
21666
|
|
|
21431
21667
|
// packages/workit-core/src/hooks/worktree-confine.ts
|
|
21432
21668
|
import { createHash as createHash16 } from "node:crypto";
|
|
21433
|
-
import
|
|
21669
|
+
import fs23 from "node:fs";
|
|
21434
21670
|
import os10 from "node:os";
|
|
21671
|
+
import path36 from "node:path";
|
|
21672
|
+
|
|
21673
|
+
// packages/workit-core/src/hooks/identity-env.ts
|
|
21674
|
+
import fs22 from "node:fs";
|
|
21435
21675
|
import path35 from "node:path";
|
|
21436
|
-
var
|
|
21437
|
-
var
|
|
21438
|
-
var
|
|
21439
|
-
var
|
|
21440
|
-
|
|
21441
|
-
|
|
21676
|
+
var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
|
|
21677
|
+
var IDENTITY = new RegExp(`^${NAMES}$`, "u");
|
|
21678
|
+
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
21679
|
+
var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
|
|
21680
|
+
var IDENTITY_ANY = new RegExp(NAMES, "iu");
|
|
21681
|
+
var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
|
|
21682
|
+
var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
|
|
21683
|
+
var STATE_ANY = new RegExp(STATE_NAMES, "iu");
|
|
21684
|
+
var powershell = (names) => new RegExp([
|
|
21685
|
+
`\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
|
|
21686
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
|
|
21687
|
+
`SetEnvironmentVariable\\(\\s*['"]${names}\\b`
|
|
21688
|
+
].join("|"), "iu");
|
|
21689
|
+
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";
|
|
21690
|
+
var POWERSHELL = powershell(NAMES);
|
|
21691
|
+
var POWERSHELL_STATE = powershell(STATE_NAMES);
|
|
21692
|
+
var POWERSHELL_HOST = powershell(HOST_NAMES);
|
|
21693
|
+
var POWERSHELL_OPAQUE = new RegExp([
|
|
21694
|
+
`SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
|
|
21695
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
|
|
21696
|
+
`(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
|
|
21697
|
+
`\\b(?:iex|Invoke-Expression)\\b`
|
|
21698
|
+
].join("|"), "iu");
|
|
21699
|
+
var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
|
|
21700
|
+
var CMD_IDENTITY = cmdSet(NAMES);
|
|
21701
|
+
var CMD_STATE = cmdSet(STATE_NAMES);
|
|
21702
|
+
var CMD_HOST = cmdSet(HOST_NAMES);
|
|
21703
|
+
var RUNS_TEXT = /\bworkit(?:-cli)?\b|@workit-dev[\\/]cli/iu;
|
|
21704
|
+
var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
|
|
21705
|
+
var OPAQUE = new Set([
|
|
21706
|
+
"watch",
|
|
21707
|
+
"strace",
|
|
21708
|
+
"chroot",
|
|
21709
|
+
"flock",
|
|
21710
|
+
"ssh",
|
|
21711
|
+
"su",
|
|
21712
|
+
"runuser",
|
|
21713
|
+
"script",
|
|
21714
|
+
"parallel"
|
|
21715
|
+
]);
|
|
21716
|
+
var ENV_VALUED = new Set(["u", "C", "S", "a", "P"]);
|
|
21717
|
+
var ENV_FLAGS = new Set(["i", "0", "v"]);
|
|
21718
|
+
var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
|
|
21719
|
+
var ENV_LONG_FLAGS = /^--(?:ignore-environment|null|debug|(?:block|default|ignore)-signal(?:=.*)?)$/u;
|
|
21720
|
+
var base = (word) => (word?.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "");
|
|
21721
|
+
var ASSIGN = /^[A-Za-z_]\w*\+?=/u;
|
|
21722
|
+
var nameOf = (word) => (word?.split("=")[0] ?? "").replace(/\+$/u, "");
|
|
21723
|
+
var named = (word) => IDENTITY.test(nameOf(word));
|
|
21724
|
+
var stateNamed = (word) => STATE2.test(nameOf(word));
|
|
21725
|
+
var isWorkit = (word) => /^workit(?:-cli)?(?:\.[cm]?js)?$/u.test(base(word)) || /@workit-dev[\\/]cli\b|workit-cli[\\/](?:dist|src)[\\/]/u.test(word ?? "");
|
|
21726
|
+
var linksToWorkit = (word, cwd) => {
|
|
21727
|
+
const places = /[\\/]/u.test(word) ? [path35.resolve(cwd ?? process.cwd(), word)] : (process.env.PATH ?? "").split(path35.delimiter).map((dir) => path35.join(dir, word));
|
|
21728
|
+
for (const place of places) {
|
|
21442
21729
|
try {
|
|
21443
|
-
|
|
21444
|
-
|
|
21445
|
-
|
|
21446
|
-
return file;
|
|
21447
|
-
rest = rest ? path35.join(path35.basename(dir), rest) : path35.basename(dir);
|
|
21448
|
-
}
|
|
21730
|
+
const real = fs22.realpathSync(place);
|
|
21731
|
+
return isWorkit(real);
|
|
21732
|
+
} catch {}
|
|
21449
21733
|
}
|
|
21734
|
+
return false;
|
|
21450
21735
|
};
|
|
21451
|
-
var
|
|
21452
|
-
|
|
21453
|
-
|
|
21454
|
-
|
|
21455
|
-
|
|
21456
|
-
|
|
21457
|
-
if (part === "" || part === ".")
|
|
21458
|
-
continue;
|
|
21459
|
-
if (part === "..") {
|
|
21460
|
-
at = path35.dirname(at);
|
|
21461
|
-
continue;
|
|
21462
|
-
}
|
|
21463
|
-
const next = path35.join(at, part);
|
|
21464
|
-
let link = null;
|
|
21465
|
-
if (!missing)
|
|
21466
|
-
try {
|
|
21467
|
-
link = fs22.readlinkSync(next);
|
|
21468
|
-
} catch (error) {
|
|
21469
|
-
missing = error.code !== "EINVAL";
|
|
21470
|
-
}
|
|
21471
|
-
if (link === null) {
|
|
21472
|
-
at = next;
|
|
21473
|
-
hops.chain = 40;
|
|
21474
|
-
} else if (hops.chain-- > 0 && hops.total-- > 0)
|
|
21475
|
-
at = canonical6(path35.isAbsolute(link) ? link : `${at}${path35.sep}${link}`, hops);
|
|
21736
|
+
var newSeg = () => ({ identity: null, scoped: null, runs: false, words: [] });
|
|
21737
|
+
var UNREADABLE = "env/unset arguments Workit cannot read";
|
|
21738
|
+
var note = (scan, seg, word) => {
|
|
21739
|
+
if (scan.identity && named(word)) {
|
|
21740
|
+
if (seg)
|
|
21741
|
+
seg.identity ??= nameOf(word);
|
|
21476
21742
|
else
|
|
21477
|
-
|
|
21743
|
+
scan.hit ??= nameOf(word);
|
|
21478
21744
|
}
|
|
21479
|
-
|
|
21480
|
-
|
|
21481
|
-
|
|
21482
|
-
|
|
21483
|
-
|
|
21484
|
-
|
|
21745
|
+
if (!stateNamed(word) && !(scan.identity && HOST_VARIABLE.test(nameOf(word))))
|
|
21746
|
+
return;
|
|
21747
|
+
if (seg)
|
|
21748
|
+
seg.scoped ??= nameOf(word);
|
|
21749
|
+
else
|
|
21750
|
+
scan.shell ??= nameOf(word);
|
|
21485
21751
|
};
|
|
21486
|
-
var
|
|
21487
|
-
|
|
21488
|
-
|
|
21489
|
-
|
|
21490
|
-
|
|
21491
|
-
|
|
21752
|
+
var mayBeWorkit = (words, cwd) => words.some(({ word, built }) => built || linksToWorkit(word, cwd));
|
|
21753
|
+
var scanEnv = (words, at, expands, scan, seg, depth) => {
|
|
21754
|
+
const risky = (what) => void (scan.risky ??= what);
|
|
21755
|
+
const unset = (name) => note(scan, seg, name);
|
|
21756
|
+
const split = (line, rest, built) => {
|
|
21757
|
+
if (line === undefined || depth >= 4)
|
|
21758
|
+
return risky(UNREADABLE);
|
|
21759
|
+
if (built || /[$`]/u.test(line))
|
|
21760
|
+
risky(UNREADABLE);
|
|
21761
|
+
const tokens = [];
|
|
21762
|
+
const expanded = new Set;
|
|
21763
|
+
try {
|
|
21764
|
+
for (const segment of segmentsOf(line)) {
|
|
21765
|
+
for (const index of segment.expands ?? [])
|
|
21766
|
+
expanded.add(tokens.length + index);
|
|
21767
|
+
tokens.push(...segment.words);
|
|
21768
|
+
}
|
|
21769
|
+
} catch {
|
|
21770
|
+
return risky(UNREADABLE);
|
|
21492
21771
|
}
|
|
21493
|
-
|
|
21494
|
-
|
|
21495
|
-
|
|
21496
|
-
|
|
21497
|
-
|
|
21498
|
-
|
|
21499
|
-
|
|
21500
|
-
|
|
21501
|
-
|
|
21502
|
-
|
|
21503
|
-
|
|
21772
|
+
scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, seg, depth + 1);
|
|
21773
|
+
};
|
|
21774
|
+
let options = true;
|
|
21775
|
+
for (let index = at;index < words.length; index += 1) {
|
|
21776
|
+
const word = words[index] ?? "";
|
|
21777
|
+
if (expands.has(index)) {
|
|
21778
|
+
risky(UNREADABLE);
|
|
21779
|
+
const built = options ? /^(?:--split-string=|-[\w]*S)(.+)$/su.exec(word) : null;
|
|
21780
|
+
if (built)
|
|
21781
|
+
return split(built[1], index + 1, true);
|
|
21782
|
+
continue;
|
|
21783
|
+
}
|
|
21784
|
+
if (options && word === "--") {
|
|
21785
|
+
options = false;
|
|
21786
|
+
continue;
|
|
21787
|
+
}
|
|
21788
|
+
if (options && word === "-") {
|
|
21789
|
+
risky("env -i");
|
|
21790
|
+
continue;
|
|
21791
|
+
}
|
|
21792
|
+
if (options && word.startsWith("--")) {
|
|
21793
|
+
const [name = "", value] = word.split(/=(.*)/su);
|
|
21794
|
+
if (name === "--ignore-environment")
|
|
21795
|
+
risky("env -i");
|
|
21796
|
+
else if (name === "--unset")
|
|
21797
|
+
unset(value ?? words[index += 1]);
|
|
21798
|
+
else if (name === "--split-string")
|
|
21799
|
+
return split(value ?? words[index + 1], index + (value === undefined ? 2 : 1), expands.has(index + (value === undefined ? 1 : 0)));
|
|
21800
|
+
else if (ENV_LONG_VALUED.has(name))
|
|
21801
|
+
index += value === undefined ? 1 : 0;
|
|
21802
|
+
else if (!ENV_LONG_FLAGS.test(word))
|
|
21803
|
+
risky(UNREADABLE);
|
|
21804
|
+
continue;
|
|
21805
|
+
}
|
|
21806
|
+
if (options && word.startsWith("-") && word.length > 1) {
|
|
21807
|
+
for (let at2 = 1;at2 < word.length; at2 += 1) {
|
|
21808
|
+
const letter = word[at2] ?? "";
|
|
21809
|
+
if (letter === "i")
|
|
21810
|
+
risky("env -i");
|
|
21811
|
+
else if (ENV_FLAGS.has(letter))
|
|
21812
|
+
continue;
|
|
21813
|
+
else if (ENV_VALUED.has(letter)) {
|
|
21814
|
+
const glued = word.slice(at2 + 1);
|
|
21815
|
+
if (!glued)
|
|
21816
|
+
index += 1;
|
|
21817
|
+
const value = glued || words[index];
|
|
21818
|
+
if (letter === "u")
|
|
21819
|
+
unset(value);
|
|
21820
|
+
if (letter === "S")
|
|
21821
|
+
return split(value, index + 1, expands.has(index));
|
|
21822
|
+
break;
|
|
21823
|
+
} else {
|
|
21824
|
+
risky(UNREADABLE);
|
|
21825
|
+
break;
|
|
21826
|
+
}
|
|
21827
|
+
}
|
|
21828
|
+
continue;
|
|
21829
|
+
}
|
|
21830
|
+
if (ASSIGN.test(word)) {
|
|
21831
|
+
unset(word);
|
|
21832
|
+
continue;
|
|
21833
|
+
}
|
|
21834
|
+
return commandAt(words.slice(index), scan, seg, new Set([...expands].filter((at2) => at2 >= index).map((at2) => at2 - index)));
|
|
21835
|
+
}
|
|
21836
|
+
};
|
|
21837
|
+
var commandAt = (words, scan, seg, expands = new Set, from = 0) => {
|
|
21838
|
+
let index = from;
|
|
21839
|
+
while (index < words.length) {
|
|
21840
|
+
while (ASSIGN.test(words[index] ?? "")) {
|
|
21841
|
+
note(scan, seg, words[index]);
|
|
21842
|
+
index += 1;
|
|
21843
|
+
}
|
|
21844
|
+
const name = base(words[index]).toLowerCase();
|
|
21845
|
+
if (name === "env")
|
|
21846
|
+
return scanEnv(words, index + 1, expands, scan, seg, 0);
|
|
21847
|
+
if (OPAQUE.has(name))
|
|
21848
|
+
return opaque(words.slice(index + 1), scan, seg, true);
|
|
21849
|
+
if (name === "busybox" || name === "toybox") {
|
|
21850
|
+
index += 1;
|
|
21851
|
+
continue;
|
|
21852
|
+
}
|
|
21853
|
+
const takes = WRAPPERS3[name];
|
|
21854
|
+
if (takes === undefined)
|
|
21855
|
+
break;
|
|
21856
|
+
index = pastOptions(words, index + 1, takes);
|
|
21857
|
+
}
|
|
21858
|
+
const word = words[index];
|
|
21859
|
+
if (word === undefined)
|
|
21860
|
+
return;
|
|
21861
|
+
seg.words.push({ word, built: expands.has(index) });
|
|
21862
|
+
const rest = words.slice(index + 1);
|
|
21863
|
+
if (isWorkit(word) || rest.some(isWorkit))
|
|
21864
|
+
seg.runs = true;
|
|
21865
|
+
if (!isWorkit(word) && rest.some((next) => base(next).toLowerCase() === "env"))
|
|
21866
|
+
opaque(rest, scan, seg, false);
|
|
21867
|
+
const program = base(word).toLowerCase();
|
|
21868
|
+
const shell = program === "pwsh" || program === "powershell";
|
|
21869
|
+
if (program === "cmd" || shell) {
|
|
21870
|
+
const at = rest.findIndex((next) => shell ? /^-(?:c|command)$/iu.test(next) : /^\/[ck]$/iu.test(next));
|
|
21871
|
+
if (at >= 0) {
|
|
21872
|
+
const script = rest.slice(at + 1).join(" ");
|
|
21873
|
+
const change = shell ? powershellChange(script, scan.identity) : cmdChange(script, scan);
|
|
21874
|
+
if (change)
|
|
21875
|
+
scan.hit ??= change;
|
|
21876
|
+
}
|
|
21877
|
+
}
|
|
21878
|
+
};
|
|
21879
|
+
var opaque = (rest, scan, seg, assigns) => {
|
|
21880
|
+
if (!rest.some(isWorkit))
|
|
21881
|
+
return;
|
|
21882
|
+
seg.runs = true;
|
|
21883
|
+
const changes = (word) => base(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && ASSIGN.test(word);
|
|
21884
|
+
if (rest.some(changes))
|
|
21885
|
+
scan.risky ??= UNREADABLE;
|
|
21886
|
+
if (rest.some((word) => base(word).toLowerCase() === "env"))
|
|
21887
|
+
for (const word of rest)
|
|
21888
|
+
note(scan, seg, word);
|
|
21889
|
+
};
|
|
21890
|
+
var LOGIN_VALUED = {
|
|
21891
|
+
su: /[sgGwc]/u,
|
|
21892
|
+
runuser: /[sgGwuc]/u,
|
|
21893
|
+
script: /[cEIOBTmot]/u
|
|
21894
|
+
};
|
|
21895
|
+
var loginScript = (words) => {
|
|
21896
|
+
const at = words.findIndex((word) => /^(?:su|runuser|script)$/u.test(base(word)));
|
|
21897
|
+
if (at < 0)
|
|
21898
|
+
return null;
|
|
21899
|
+
const valued = LOGIN_VALUED[base(words[at])] ?? /c/u;
|
|
21900
|
+
for (let index = at + 1;index < words.length; index += 1) {
|
|
21901
|
+
const word = words[index] ?? "";
|
|
21902
|
+
if (word === "--command")
|
|
21903
|
+
return words[index + 1] ?? null;
|
|
21904
|
+
if (word.startsWith("--command="))
|
|
21905
|
+
return word.slice("--command=".length);
|
|
21906
|
+
if (!/^-[^-]/u.test(word))
|
|
21907
|
+
continue;
|
|
21908
|
+
const ends = word.slice(1).search(valued) + 1;
|
|
21909
|
+
if (ends > 0 && word[ends] === "c")
|
|
21910
|
+
return word.slice(ends + 1) || (words[index + 1] ?? null);
|
|
21911
|
+
}
|
|
21912
|
+
return null;
|
|
21913
|
+
};
|
|
21914
|
+
var scanCommand = (command, dialect, depth, scan) => {
|
|
21915
|
+
let segments;
|
|
21916
|
+
try {
|
|
21917
|
+
segments = segmentsOf(command, dialect);
|
|
21918
|
+
} catch {
|
|
21919
|
+
return;
|
|
21920
|
+
}
|
|
21921
|
+
for (const { words, expands = [] } of segments) {
|
|
21922
|
+
const expanded = new Set(expands);
|
|
21923
|
+
const seg = newSeg();
|
|
21924
|
+
let at = 0;
|
|
21925
|
+
while (ASSIGN.test(words[at] ?? ""))
|
|
21926
|
+
at += 1;
|
|
21927
|
+
for (const word of words.slice(0, at))
|
|
21928
|
+
note(scan, at === words.length ? null : seg, word);
|
|
21929
|
+
let declare = at;
|
|
21930
|
+
if (["builtin", "command"].includes(words[declare] ?? ""))
|
|
21931
|
+
declare += 1;
|
|
21932
|
+
if (DECLARES.has(words[declare] ?? "")) {
|
|
21933
|
+
for (let index = declare + 1;index < words.length; index += 1) {
|
|
21934
|
+
note(scan, null, words[index]);
|
|
21935
|
+
if (expanded.has(index))
|
|
21936
|
+
scan.risky ??= UNREADABLE;
|
|
21937
|
+
}
|
|
21938
|
+
continue;
|
|
21939
|
+
}
|
|
21940
|
+
commandAt(words, scan, seg, expanded, at);
|
|
21941
|
+
const script = depth < 4 ? shellScript2(words) ?? loginScript(words) : null;
|
|
21942
|
+
if (script) {
|
|
21943
|
+
const before = scan.runs;
|
|
21944
|
+
scan.runs = false;
|
|
21945
|
+
scanCommand(script, dialect, depth + 1, scan);
|
|
21946
|
+
seg.runs ||= scan.runs;
|
|
21947
|
+
scan.runs ||= before;
|
|
21948
|
+
}
|
|
21949
|
+
scan.words.push(...seg.words);
|
|
21950
|
+
const reaches = () => seg.runs || mayBeWorkit(seg.words, scan.cwd);
|
|
21951
|
+
if (seg.identity && reaches())
|
|
21952
|
+
scan.hit ??= seg.identity;
|
|
21953
|
+
if (seg.scoped && reaches())
|
|
21954
|
+
scan.state ??= seg.scoped;
|
|
21955
|
+
scan.runs ||= seg.runs;
|
|
21956
|
+
}
|
|
21957
|
+
};
|
|
21958
|
+
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);
|
|
21959
|
+
var powershellChange = (command, identity) => {
|
|
21960
|
+
const hit = identity ? POWERSHELL.exec(command)?.[0] : null;
|
|
21961
|
+
if (hit)
|
|
21962
|
+
return hit;
|
|
21963
|
+
if (!RUNS_TEXT.test(command) && !/&\s*[$(]/u.test(command))
|
|
21964
|
+
return null;
|
|
21965
|
+
const state = POWERSHELL_STATE.exec(command)?.[0] ?? (identity ? POWERSHELL_HOST.exec(command)?.[0] : null) ?? cmdChange(command, { identity });
|
|
21966
|
+
if (state)
|
|
21967
|
+
return state;
|
|
21968
|
+
return POWERSHELL_OPAQUE.test(command) ? UNREADABLE : null;
|
|
21969
|
+
};
|
|
21970
|
+
var identityEnvChange = (command, dialect = "posix", options = {}) => {
|
|
21971
|
+
const identity = options.identity ?? true;
|
|
21972
|
+
if (dialect === "powershell")
|
|
21973
|
+
return powershellChange(command, identity);
|
|
21974
|
+
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))
|
|
21975
|
+
return null;
|
|
21976
|
+
const scan = {
|
|
21977
|
+
identity,
|
|
21978
|
+
cwd: options.cwd,
|
|
21979
|
+
hit: null,
|
|
21980
|
+
state: null,
|
|
21981
|
+
shell: null,
|
|
21982
|
+
risky: null,
|
|
21983
|
+
runs: false,
|
|
21984
|
+
words: []
|
|
21985
|
+
};
|
|
21986
|
+
scanCommand(command, dialect, 0, scan);
|
|
21987
|
+
if (scan.hit)
|
|
21988
|
+
return scan.hit;
|
|
21989
|
+
if (scan.state)
|
|
21990
|
+
return scan.state;
|
|
21991
|
+
if (scan.shell && (scan.runs || mayBeWorkit(scan.words, scan.cwd)))
|
|
21992
|
+
return scan.shell;
|
|
21993
|
+
return scan.runs ? scan.risky : null;
|
|
21994
|
+
};
|
|
21995
|
+
var identityEnvDeny = (change) => {
|
|
21996
|
+
if (change === UNREADABLE || IDENTITY_ANY.test(change) || !STATE_ANY.test(change))
|
|
21997
|
+
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).`;
|
|
21998
|
+
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}.`;
|
|
21999
|
+
};
|
|
22000
|
+
|
|
22001
|
+
// packages/workit-core/src/hooks/exit-pipe.ts
|
|
22002
|
+
var EXIT_VERBS = [
|
|
22003
|
+
["ci", "wait"],
|
|
22004
|
+
["check"],
|
|
22005
|
+
["pr", "merge"],
|
|
22006
|
+
["release"],
|
|
22007
|
+
["verify-delivery"]
|
|
22008
|
+
];
|
|
22009
|
+
var base2 = (word = "") => word.split(/[\\/]/u).at(-1) ?? "";
|
|
22010
|
+
var verbPath = (words) => {
|
|
22011
|
+
const path = [];
|
|
22012
|
+
for (let at = 0;at < words.length && path.length < 2; at += 1) {
|
|
22013
|
+
const word = words[at];
|
|
22014
|
+
if (word === "--")
|
|
22015
|
+
break;
|
|
22016
|
+
if (word === "--cwd")
|
|
22017
|
+
at += 1;
|
|
22018
|
+
else if (!word.startsWith("-"))
|
|
22019
|
+
path.push(word);
|
|
22020
|
+
}
|
|
22021
|
+
return path;
|
|
22022
|
+
};
|
|
22023
|
+
var identityAssignment = (name) => identityEnvChange(`${name}=x workit`) !== null;
|
|
22024
|
+
var identityWhy = (names) => names.length ? `
|
|
22025
|
+
Why: the retry leaves out ${names.join(", ")}: the identity guard refuses a workit call that sets ${names.length === 1 ? "it" : "them"}.` : "";
|
|
22026
|
+
var exitCall = (segment, first) => {
|
|
22027
|
+
const { words } = segment;
|
|
22028
|
+
let at = first;
|
|
22029
|
+
while (at < words.length && /^[A-Za-z_]\w*=/u.test(words[at]))
|
|
22030
|
+
at += 1;
|
|
22031
|
+
if (!/^workit(?:-cli)?$/u.test(base2(words[at])))
|
|
22032
|
+
return null;
|
|
22033
|
+
const path = verbPath(words.slice(at + 1));
|
|
22034
|
+
return EXIT_VERBS.some((verb) => verb.every((word, index) => path[index] === word)) ? { segment, first, at } : null;
|
|
22035
|
+
};
|
|
22036
|
+
var backgrounded = (command, segment) => {
|
|
22037
|
+
const ends = [...segment.spans ?? [], ...segment.redirectSpans ?? []].map(([, end]) => end);
|
|
22038
|
+
return /^[ \t]*&(?![&>])/u.test(command.slice(Math.max(0, ...ends)));
|
|
22039
|
+
};
|
|
22040
|
+
var setsPipefail = (words) => words[0] === "set" && words.some((word, at) => word === "pipefail" && /^-[a-z]*o$/u.test(words[at - 1] ?? ""));
|
|
22041
|
+
var range = (from, to) => Array.from({ length: to - from }, (_, i) => from + i);
|
|
22042
|
+
var absoluteCwd = (text, value) => cwdIndependent(text) && (/^(?:\/|[A-Za-z]:[\\/])/u.test(value) || /^~(?:\/|$)/u.test(text));
|
|
22043
|
+
var retryOf = (command, found) => {
|
|
22044
|
+
const { segment, first, at, cd, set } = found;
|
|
22045
|
+
const { words } = segment;
|
|
22046
|
+
const dropped = [];
|
|
22047
|
+
const env = range(first, at).filter((index) => {
|
|
22048
|
+
const name = words[index].slice(0, words[index].indexOf("="));
|
|
22049
|
+
if (!identityAssignment(name))
|
|
22050
|
+
return true;
|
|
22051
|
+
dropped.push(name);
|
|
22052
|
+
return false;
|
|
22053
|
+
});
|
|
22054
|
+
const envText = writtenWords(command, segment, env);
|
|
22055
|
+
const callText = writtenWords(command, segment, range(at + 1, words.length));
|
|
22056
|
+
const dir = cd ? writtenWord(command, cd, 1) : "";
|
|
22057
|
+
if (!envText || !callText || cd === undefined || dir === null)
|
|
22058
|
+
return { retry: null, dropped };
|
|
22059
|
+
const reads = [dir, ...envText, ...callText].flatMap((text) => [...text.matchAll(/\$\{?(\w+)/gu)].map((match) => match[1] ?? "")).find((name) => set.has(name));
|
|
22060
|
+
if (reads)
|
|
22061
|
+
return { retry: null, dropped, reads };
|
|
22062
|
+
const call = words.slice(at + 1);
|
|
22063
|
+
const verbAt = call[0]?.startsWith("-") ? 0 : 1;
|
|
22064
|
+
const plain = (body) => [...envText, "workit", ...body].join(" ");
|
|
22065
|
+
if (!cd)
|
|
22066
|
+
return { retry: plain(callText), dropped };
|
|
22067
|
+
const check = verbPath(call)[0] === "check";
|
|
22068
|
+
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=")));
|
|
22069
|
+
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) => {
|
|
22070
|
+
const text = writtenWord(command, segment, index) ?? "";
|
|
22071
|
+
return absoluteCwd(text.replace(/^--cwd=/u, ""), words[index].replace(/^--cwd=/u, ""));
|
|
22072
|
+
});
|
|
22073
|
+
if (!moves)
|
|
22074
|
+
return { retry: `cd ${dir} && ${plain(callText)}`, dropped };
|
|
22075
|
+
if (cwds.length)
|
|
22076
|
+
return { retry: plain(callText), dropped };
|
|
22077
|
+
return {
|
|
22078
|
+
retry: plain([...callText.slice(0, verbAt), "--cwd", dir, ...callText.slice(verbAt)]),
|
|
22079
|
+
dropped
|
|
22080
|
+
};
|
|
22081
|
+
};
|
|
22082
|
+
function exitPipeGate(command, dialect = "posix") {
|
|
22083
|
+
if (!/\bworkit/u.test(command) || !/\b(?:tail|head)\b/u.test(command))
|
|
22084
|
+
return null;
|
|
22085
|
+
const groups = [];
|
|
22086
|
+
let carry = null;
|
|
22087
|
+
let pipefail = false;
|
|
22088
|
+
let cd = null;
|
|
22089
|
+
const seen = [];
|
|
22090
|
+
const chained = !command.includes("||");
|
|
22091
|
+
for (const segment of segmentsOf(command, dialect, { spans: true })) {
|
|
22092
|
+
if (segment.unanalyzable)
|
|
22093
|
+
return null;
|
|
22094
|
+
let words = segment.words;
|
|
22095
|
+
let closes = segment.group === "close";
|
|
22096
|
+
if (segment.group === "open") {
|
|
22097
|
+
groups.push(null);
|
|
22098
|
+
continue;
|
|
22099
|
+
}
|
|
22100
|
+
if (words[0] === "{") {
|
|
22101
|
+
groups.push(null);
|
|
22102
|
+
words = words.slice(1);
|
|
22103
|
+
} else if (words[0] === "}") {
|
|
22104
|
+
closes = true;
|
|
22105
|
+
words = words.slice(1);
|
|
22106
|
+
}
|
|
22107
|
+
if (closes) {
|
|
22108
|
+
const inner = groups.pop() ?? null;
|
|
22109
|
+
if (segment.group === "close" && cd)
|
|
22110
|
+
cd = undefined;
|
|
22111
|
+
if (inner && groups.length)
|
|
22112
|
+
groups[groups.length - 1] = inner;
|
|
22113
|
+
carry = segment.pipe ? inner ?? carry : null;
|
|
22114
|
+
continue;
|
|
22115
|
+
}
|
|
22116
|
+
if (!words.length && !segment.stdin && !segment.subs)
|
|
22117
|
+
continue;
|
|
22118
|
+
if (setsPipefail(words))
|
|
22119
|
+
pipefail = true;
|
|
22120
|
+
const filter = base2(words[0]);
|
|
22121
|
+
if (carry && !pipefail && (filter === "tail" || filter === "head")) {
|
|
22122
|
+
const { retry, dropped, reads } = retryOf(command, carry);
|
|
22123
|
+
const verb = verbPath(carry.segment.words.slice(carry.at + 1)).join(" ");
|
|
22124
|
+
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.`;
|
|
22125
|
+
return {
|
|
22126
|
+
kind: "deny",
|
|
22127
|
+
reason: `workit exit-pipe: piping \`workit ${verb}\` into ${filter} hides its exit code.
|
|
22128
|
+
${retry ? `Retry as: ${retry}` : why}${identityWhy(dropped)}`,
|
|
22129
|
+
unblock: retry
|
|
22130
|
+
};
|
|
22131
|
+
}
|
|
22132
|
+
const call = exitCall(segment, segment.words.length - words.length);
|
|
22133
|
+
const found = call ? { ...call, cd, set: namesSet(seen) } : null;
|
|
22134
|
+
seen.push(segment);
|
|
22135
|
+
if (found && groups.length)
|
|
22136
|
+
groups[groups.length - 1] = found;
|
|
22137
|
+
carry = segment.pipe ? found ?? carry : null;
|
|
22138
|
+
const clean = chained && words === segment.words && words.length === 2 && !segment.pipe && !backgrounded(command, segment);
|
|
22139
|
+
if (words[0] === "cd")
|
|
22140
|
+
cd = clean && cd === null ? segment : undefined;
|
|
22141
|
+
else if (cd)
|
|
22142
|
+
cd = undefined;
|
|
22143
|
+
}
|
|
22144
|
+
return null;
|
|
22145
|
+
}
|
|
22146
|
+
|
|
22147
|
+
// packages/workit-core/src/hooks/worktree-confine.ts
|
|
22148
|
+
var FANOUT_TOKEN_FILE = "workit-fanout-token";
|
|
22149
|
+
var NONE5 = { kind: "none" };
|
|
22150
|
+
var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
|
|
22151
|
+
var realOf = (file) => {
|
|
22152
|
+
let rest = "";
|
|
22153
|
+
for (let dir = file;; dir = path36.dirname(dir)) {
|
|
22154
|
+
try {
|
|
22155
|
+
return path36.join(fs23.realpathSync.native(dir), rest);
|
|
22156
|
+
} catch {
|
|
22157
|
+
if (path36.dirname(dir) === dir)
|
|
22158
|
+
return file;
|
|
22159
|
+
rest = rest ? path36.join(path36.basename(dir), rest) : path36.basename(dir);
|
|
22160
|
+
}
|
|
22161
|
+
}
|
|
22162
|
+
};
|
|
22163
|
+
var canonical6 = (file, hops = { chain: 40, total: 1000 }) => {
|
|
22164
|
+
const start = path36.isAbsolute(file) ? file : `${process.cwd()}${path36.sep}${file}`;
|
|
22165
|
+
const { root } = path36.parse(start);
|
|
22166
|
+
let at = root;
|
|
22167
|
+
let missing = false;
|
|
22168
|
+
for (const part of start.slice(root.length).split(/[\\/]+/)) {
|
|
22169
|
+
if (part === "" || part === ".")
|
|
22170
|
+
continue;
|
|
22171
|
+
if (part === "..") {
|
|
22172
|
+
at = path36.dirname(at);
|
|
22173
|
+
continue;
|
|
22174
|
+
}
|
|
22175
|
+
const next = path36.join(at, part);
|
|
22176
|
+
let link = null;
|
|
22177
|
+
if (!missing)
|
|
22178
|
+
try {
|
|
22179
|
+
link = fs23.readlinkSync(next);
|
|
22180
|
+
} catch (error) {
|
|
22181
|
+
missing = error.code !== "EINVAL";
|
|
22182
|
+
}
|
|
22183
|
+
if (link === null) {
|
|
22184
|
+
at = next;
|
|
22185
|
+
hops.chain = 40;
|
|
22186
|
+
} else if (hops.chain-- > 0 && hops.total-- > 0)
|
|
22187
|
+
at = canonical6(path36.isAbsolute(link) ? link : `${at}${path36.sep}${link}`, hops);
|
|
22188
|
+
else
|
|
22189
|
+
return path36.resolve(file);
|
|
22190
|
+
}
|
|
22191
|
+
return realOf(at);
|
|
22192
|
+
};
|
|
22193
|
+
var within = (child, parent) => {
|
|
22194
|
+
const fold = (value) => CASE_INSENSITIVE2 ? value.toLowerCase() : value;
|
|
22195
|
+
const relative = path36.relative(fold(parent), fold(child));
|
|
22196
|
+
return relative === "" || !relative.startsWith("..") && !path36.isAbsolute(relative);
|
|
22197
|
+
};
|
|
22198
|
+
var checkoutOf2 = (file) => {
|
|
22199
|
+
for (let dir = canonical6(file);; dir = path36.dirname(dir)) {
|
|
22200
|
+
const dotGit = path36.join(dir, ".git");
|
|
22201
|
+
if (fs23.existsSync(dotGit)) {
|
|
22202
|
+
const admin = fs23.statSync(dotGit).isFile() ? gitDirsAt(dir, null, false)?.[0] : undefined;
|
|
22203
|
+
return { root: dir, workit: !!admin && fs23.existsSync(path36.join(admin, FANOUT_TOKEN_FILE)) };
|
|
22204
|
+
}
|
|
22205
|
+
if (path36.dirname(dir) === dir)
|
|
22206
|
+
return null;
|
|
22207
|
+
}
|
|
22208
|
+
};
|
|
22209
|
+
var workitWorktreeOf = (file) => {
|
|
22210
|
+
try {
|
|
22211
|
+
const checkout = checkoutOf2(file);
|
|
22212
|
+
return checkout?.workit ? checkout.root : null;
|
|
22213
|
+
} catch {
|
|
22214
|
+
return null;
|
|
22215
|
+
}
|
|
21504
22216
|
};
|
|
21505
|
-
var bindingDir = () =>
|
|
21506
|
-
var bindingFile = (session, agentId) =>
|
|
22217
|
+
var bindingDir = () => path36.join(resolveStateDir(), "worktree-bind");
|
|
22218
|
+
var bindingFile = (session, agentId) => path36.join(bindingDir(), `${createHash16("sha256").update(`${session}\x00${agentId}`).digest("hex").slice(0, 32)}.json`);
|
|
21507
22219
|
var readBinding = (file) => {
|
|
21508
22220
|
try {
|
|
21509
|
-
const value = JSON.parse(
|
|
22221
|
+
const value = JSON.parse(fs23.readFileSync(file, "utf8"));
|
|
21510
22222
|
return typeof value.worktree === "string" ? value : null;
|
|
21511
22223
|
} catch {
|
|
21512
22224
|
return null;
|
|
@@ -21528,8 +22240,8 @@ var bind = (input, worktree) => {
|
|
|
21528
22240
|
agentId,
|
|
21529
22241
|
at: new Date().toISOString()
|
|
21530
22242
|
};
|
|
21531
|
-
|
|
21532
|
-
|
|
22243
|
+
fs23.mkdirSync(path36.dirname(file), { recursive: true });
|
|
22244
|
+
fs23.writeFileSync(file, JSON.stringify(binding));
|
|
21533
22245
|
try {
|
|
21534
22246
|
if (inWorkitWorkspace(input.cwd))
|
|
21535
22247
|
appendHookObserved(input.cwd, {
|
|
@@ -21547,42 +22259,117 @@ var hostIsolated = (cwd, agentId) => {
|
|
|
21547
22259
|
const checkout = checkoutOf2(cwd);
|
|
21548
22260
|
if (!checkout)
|
|
21549
22261
|
return false;
|
|
21550
|
-
const dotGit =
|
|
21551
|
-
if (!
|
|
22262
|
+
const dotGit = path36.join(checkout.root, ".git");
|
|
22263
|
+
if (!fs23.statSync(dotGit).isFile())
|
|
21552
22264
|
return false;
|
|
21553
22265
|
const [adminDir, gitDir] = gitDirsAt(checkout.root, null, false) ?? [];
|
|
21554
|
-
const back =
|
|
21555
|
-
if (
|
|
22266
|
+
const back = fs23.readFileSync(path36.join(adminDir, "gitdir"), "utf8").trim();
|
|
22267
|
+
if (path36.relative(canonical6(path36.resolve(adminDir, back)), canonical6(dotGit)) !== "")
|
|
21556
22268
|
return false;
|
|
21557
|
-
const expected =
|
|
21558
|
-
return
|
|
22269
|
+
const expected = path36.join(path36.dirname(gitDir), ".claude", "worktrees", `agent-${agentId}`);
|
|
22270
|
+
return path36.relative(canonical6(expected), checkout.root) === "";
|
|
21559
22271
|
} catch {
|
|
21560
22272
|
return false;
|
|
21561
22273
|
}
|
|
21562
22274
|
};
|
|
21563
22275
|
var runnerAt = (target) => {
|
|
21564
|
-
const base =
|
|
22276
|
+
const base = path36.basename(target);
|
|
21565
22277
|
return base.startsWith(OPAQUE_TARGET) ? decodeURIComponent(base.slice(OPAQUE_TARGET.length)) : null;
|
|
21566
22278
|
};
|
|
21567
22279
|
var shown = (target) => {
|
|
21568
|
-
const named = /^\.workit-(?:live-target$|runs-)/.test(
|
|
21569
|
-
return
|
|
22280
|
+
const named = /^\.workit-(?:live-target$|runs-)/.test(path36.basename(target)) ? path36.dirname(target) : target;
|
|
22281
|
+
return path36.sep === "\\" ? named.replaceAll("/", "\\") : named;
|
|
22282
|
+
};
|
|
22283
|
+
var plainWorkitCall = (command, dialect) => {
|
|
22284
|
+
if (dialect !== "posix")
|
|
22285
|
+
return null;
|
|
22286
|
+
const segments = segmentsOf(command, dialect, { spans: true });
|
|
22287
|
+
const [only] = segments;
|
|
22288
|
+
if (segments.length !== 1 || !only || only.unanalyzable || only.group || only.pipe)
|
|
22289
|
+
return null;
|
|
22290
|
+
if (only.redirects.length || only.subs?.length || only.stdin?.length || only.inputs?.length)
|
|
22291
|
+
return null;
|
|
22292
|
+
const { words } = only;
|
|
22293
|
+
let at = 0;
|
|
22294
|
+
while (at < words.length && /^[A-Za-z_]\w*=/.test(words[at]))
|
|
22295
|
+
at++;
|
|
22296
|
+
if (words[at] !== "workit" || (only.expands ?? []).some((index) => index >= at))
|
|
22297
|
+
return null;
|
|
22298
|
+
return { segment: only, at, cwd: skipWorkitGlobals(words.slice(at + 1)).cwd };
|
|
22299
|
+
};
|
|
22300
|
+
var workitCallDir = (command, dialect) => {
|
|
22301
|
+
const call = plainWorkitCall(command, dialect);
|
|
22302
|
+
return call?.cwd && path36.isAbsolute(call.cwd) ? call.cwd : null;
|
|
22303
|
+
};
|
|
22304
|
+
var shellWord = (dir) => /^[\w@%+=:,./-]+$/u.test(dir) ? dir : `'${dir.replaceAll("'", `'\\''`)}'`;
|
|
22305
|
+
var cwdAt = (words, index) => words[index] === "--cwd" && words[index + 1] !== undefined ? 2 : words[index]?.startsWith("--cwd=") ? 1 : 0;
|
|
22306
|
+
var plainRetry = (dir, command) => {
|
|
22307
|
+
const call = plainWorkitCall(command, "posix");
|
|
22308
|
+
if (!call)
|
|
22309
|
+
return null;
|
|
22310
|
+
const { segment, at } = call;
|
|
22311
|
+
const { words } = segment;
|
|
22312
|
+
const dropped = [];
|
|
22313
|
+
const env = [];
|
|
22314
|
+
for (let index = 0;index < at; index++) {
|
|
22315
|
+
const name = words[index].slice(0, words[index].indexOf("="));
|
|
22316
|
+
if (identityAssignment(name))
|
|
22317
|
+
dropped.push(name);
|
|
22318
|
+
else
|
|
22319
|
+
env.push(index);
|
|
22320
|
+
}
|
|
22321
|
+
const globals = [];
|
|
22322
|
+
let index = at + 1;
|
|
22323
|
+
for (;index < words.length; index++) {
|
|
22324
|
+
const skip = cwdAt(words, index);
|
|
22325
|
+
if (skip)
|
|
22326
|
+
index += skip - 1;
|
|
22327
|
+
else if (/^--(?:session|token|as)$/u.test(words[index]) && words[index + 1] !== undefined)
|
|
22328
|
+
globals.push(index, ++index);
|
|
22329
|
+
else if (/^--(?:session|token|as)=|^--json$/u.test(words[index]))
|
|
22330
|
+
globals.push(index);
|
|
22331
|
+
else
|
|
22332
|
+
break;
|
|
22333
|
+
}
|
|
22334
|
+
const verb = index;
|
|
22335
|
+
const rest = [];
|
|
22336
|
+
for (index += 1;index < words.length; index++) {
|
|
22337
|
+
if (words[index] === "--") {
|
|
22338
|
+
for (;index < words.length; index++)
|
|
22339
|
+
rest.push(index);
|
|
22340
|
+
break;
|
|
22341
|
+
}
|
|
22342
|
+
const skip = cwdAt(words, index);
|
|
22343
|
+
if (skip)
|
|
22344
|
+
index += skip - 1;
|
|
22345
|
+
else
|
|
22346
|
+
rest.push(index);
|
|
22347
|
+
}
|
|
22348
|
+
const text = (indexes) => writtenWords(command, segment, indexes);
|
|
22349
|
+
const parts = [text(env), text(globals), text(verb < words.length ? [verb] : []), text(rest)];
|
|
22350
|
+
if (parts.includes(null))
|
|
22351
|
+
return null;
|
|
22352
|
+
const [envText, globalText, verbText, restText] = parts;
|
|
22353
|
+
const cwd = ["--cwd", shellWord(dir)];
|
|
22354
|
+
const body = [...globalText, ...verbText, ...cwd, ...restText];
|
|
22355
|
+
return { retry: [...envText, "workit", ...body].join(" "), dropped };
|
|
21570
22356
|
};
|
|
21571
22357
|
var runFrom = (dir, command) => `cd ${dir} && ${command.replace(/^\s*cd\s+\S+\s*(?:&&|;)\s*/, "")}`;
|
|
21572
|
-
var deny2 = (what, unblock) => ({
|
|
22358
|
+
var deny2 = (what, unblock, note = "") => ({
|
|
21573
22359
|
kind: "deny",
|
|
21574
22360
|
reason: `${what}.
|
|
21575
|
-
${unblock}`,
|
|
22361
|
+
${unblock}${note}`,
|
|
21576
22362
|
unblock
|
|
21577
22363
|
});
|
|
21578
22364
|
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.");
|
|
21579
22365
|
var outsideDeny = (input, worktree, target, command) => {
|
|
21580
22366
|
const runner = runnerAt(target);
|
|
21581
|
-
|
|
22367
|
+
const plain = runner !== null && command ? plainRetry(worktree, command) : null;
|
|
22368
|
+
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 ?? []));
|
|
21582
22369
|
};
|
|
21583
22370
|
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\`.`);
|
|
21584
22371
|
var refsOf = (targets) => [
|
|
21585
|
-
...new Set(targets.flatMap((target) =>
|
|
22372
|
+
...new Set(targets.flatMap((target) => path36.relative(UNKNOWN_VAR, path36.resolve(target)).split(path36.sep)[0].split("+").filter(Boolean).map(decodeURIComponent)))
|
|
21586
22373
|
];
|
|
21587
22374
|
var literalForm = (command, refs) => {
|
|
21588
22375
|
let text = command;
|
|
@@ -21615,10 +22402,10 @@ function confineImplementer(input, targets, command) {
|
|
|
21615
22402
|
try {
|
|
21616
22403
|
if (!input.session.agentId || hostIsolated(input.cwd, input.session.agentId))
|
|
21617
22404
|
return NONE5;
|
|
21618
|
-
const unresolved = targets.filter((target) => within(
|
|
22405
|
+
const unresolved = targets.filter((target) => within(path36.resolve(target), UNKNOWN_VAR));
|
|
21619
22406
|
if (unresolved.length > 0)
|
|
21620
22407
|
return unknownVarDeny(input, unresolved, command);
|
|
21621
|
-
if (targets.some((target) => within(
|
|
22408
|
+
if (targets.some((target) => within(path36.resolve(target), UNKNOWN_DIR)))
|
|
21622
22409
|
return unknownDirDeny(input, boundWorktree(input));
|
|
21623
22410
|
const bindings = canonical6(bindingDir());
|
|
21624
22411
|
const judged = targets.map((named) => ({ named, real: canonical6(named) })).filter(({ real }) => within(real, bindings) || checkoutOf2(real) !== null);
|
|
@@ -21710,7 +22497,7 @@ function confineImplementerShell(input, command, dialect = "posix") {
|
|
|
21710
22497
|
if (rawInvocations(command, dialect).some((invocation) => invocation.tool === "git" && leadOwnedGit(invocation.args)) || workitInvocations(command, dialect).some(leadOwnedWorkit))
|
|
21711
22498
|
return leadOwnedDeny(input, command);
|
|
21712
22499
|
} catch {}
|
|
21713
|
-
return confineImplementer(input, shellMutationTargets(input.cwd, command, dialect, true), command);
|
|
22500
|
+
return confineImplementer(input, shellMutationTargets(workitCallDir(command, dialect) ?? input.cwd, command, dialect, true), command);
|
|
21714
22501
|
}
|
|
21715
22502
|
var LITERAL_SET = /^\s*([A-Za-z_]\w*)=(['"]?)((?:[\w@%+=:./\\-]|(?<=[^\s:=])~)*)\2[ \t]*(?:;|&&|\n)\s*/;
|
|
21716
22503
|
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)$/;
|
|
@@ -21725,10 +22512,10 @@ var INLINE = /^-[a-zA-Z]*[ceEpm]$|^--(?:eval|print)(?:=|$)|^--(?:test|version|he
|
|
|
21725
22512
|
var VALUED2 = /^-[WXIrC]$|^--(?:require|import|loader|conditions|input-type)$/;
|
|
21726
22513
|
var commonDir = (root) => gitDirsAt(root, null, false)?.[1] ?? "";
|
|
21727
22514
|
var inScratch = (real, repo) => {
|
|
21728
|
-
for (let dir = real;
|
|
21729
|
-
if (
|
|
22515
|
+
for (let dir = real;path36.dirname(dir) !== dir; dir = path36.dirname(dir)) {
|
|
22516
|
+
if (path36.basename(dir) !== SCRATCH)
|
|
21730
22517
|
continue;
|
|
21731
|
-
const root =
|
|
22518
|
+
const root = path36.dirname(dir);
|
|
21732
22519
|
const checkout = checkoutOf2(root);
|
|
21733
22520
|
if (checkout?.root === root && (repo === null || checkout.workit || commonDir(root) === repo))
|
|
21734
22521
|
return true;
|
|
@@ -21738,7 +22525,7 @@ var inScratch = (real, repo) => {
|
|
|
21738
22525
|
var inGitDir = (real) => real.split(/[\\/]/).includes(".git");
|
|
21739
22526
|
var SAFE_KEY = /^(?:core\.(?:repositoryformatversion|filemode|bare|logallrefupdates|ignorecase|precomposeunicode|symlinks)|user\..*|init\.defaultbranch|commit\.gpgsign|extensions\.(?:objectformat|refstorage)|branch\..*\.(?:remote|merge)|remote\..*\.fetch)$/;
|
|
21740
22527
|
var literalIn = (value, repo, checkout = false) => {
|
|
21741
|
-
if (/[$`]/.test(value) || !
|
|
22528
|
+
if (/[$`]/.test(value) || !path36.isAbsolute(value))
|
|
21742
22529
|
return false;
|
|
21743
22530
|
const real = canonical6(value);
|
|
21744
22531
|
const root = checkout ? checkoutOf2(real)?.root : undefined;
|
|
@@ -21759,45 +22546,45 @@ var configEntries = (text) => {
|
|
|
21759
22546
|
return entries;
|
|
21760
22547
|
};
|
|
21761
22548
|
function gitDirsAt(dir, repo, scan = true) {
|
|
21762
|
-
for (let at = dir;; at =
|
|
21763
|
-
const dotGit =
|
|
22549
|
+
for (let at = dir;; at = path36.dirname(at)) {
|
|
22550
|
+
const dotGit = path36.join(at, ".git");
|
|
21764
22551
|
let gitDir = null;
|
|
21765
22552
|
try {
|
|
21766
|
-
if (
|
|
22553
|
+
if (fs23.statSync(dotGit).isDirectory())
|
|
21767
22554
|
gitDir = canonical6(dotGit);
|
|
21768
22555
|
else {
|
|
21769
|
-
const named = /^gitdir:\s*(.+?)\s*$/mu.exec(
|
|
22556
|
+
const named = /^gitdir:\s*(.+?)\s*$/mu.exec(fs23.readFileSync(dotGit, "utf8"))?.[1];
|
|
21770
22557
|
if (!named)
|
|
21771
22558
|
return null;
|
|
21772
|
-
gitDir = canonical6(
|
|
22559
|
+
gitDir = canonical6(path36.resolve(at, named));
|
|
21773
22560
|
}
|
|
21774
22561
|
} catch (error) {
|
|
21775
22562
|
if (error.code !== "ENOENT")
|
|
21776
22563
|
return null;
|
|
21777
|
-
if (["HEAD", "objects", "refs"].every((name) =>
|
|
22564
|
+
if (["HEAD", "objects", "refs"].every((name) => fs23.existsSync(path36.join(at, name))))
|
|
21778
22565
|
gitDir = canonical6(at);
|
|
21779
22566
|
}
|
|
21780
22567
|
if (gitDir !== null) {
|
|
21781
|
-
const common =
|
|
21782
|
-
const shared =
|
|
22568
|
+
const common = path36.join(gitDir, "commondir");
|
|
22569
|
+
const shared = fs23.existsSync(common) ? canonical6(path36.resolve(gitDir, fs23.readFileSync(common, "utf8").trim())) : gitDir;
|
|
21783
22570
|
const dirs = [gitDir, shared];
|
|
21784
|
-
for (const config of scan ? new Set([
|
|
22571
|
+
for (const config of scan ? new Set([path36.join(gitDir, "config"), path36.join(shared, "config")]) : []) {
|
|
21785
22572
|
let text = "";
|
|
21786
22573
|
try {
|
|
21787
|
-
text =
|
|
22574
|
+
text = fs23.readFileSync(config, "utf8");
|
|
21788
22575
|
} catch {
|
|
21789
22576
|
continue;
|
|
21790
22577
|
}
|
|
21791
22578
|
for (const [key, value] of configEntries(text)) {
|
|
21792
22579
|
if (key === "core.worktree")
|
|
21793
|
-
dirs.push(canonical6(
|
|
22580
|
+
dirs.push(canonical6(path36.resolve(gitDir, value)));
|
|
21794
22581
|
else if (/^remote\..*\.url$/.test(key) ? !literalIn(value, repo, true) : !SAFE_KEY.test(key))
|
|
21795
22582
|
return null;
|
|
21796
22583
|
}
|
|
21797
22584
|
}
|
|
21798
22585
|
return dirs;
|
|
21799
22586
|
}
|
|
21800
|
-
if (
|
|
22587
|
+
if (path36.dirname(at) === at)
|
|
21801
22588
|
return [];
|
|
21802
22589
|
}
|
|
21803
22590
|
}
|
|
@@ -21937,10 +22724,10 @@ var gitKind = (args, local = () => true) => {
|
|
|
21937
22724
|
return GIT_VERBS[verb].startsWith("+") ? "write" : "read";
|
|
21938
22725
|
};
|
|
21939
22726
|
var remoteIn = (dir, name, repo) => {
|
|
21940
|
-
const shared =
|
|
22727
|
+
const shared = path36.isAbsolute(dir) ? gitDirsAt(canonical6(dir), repo, false)?.[1] : undefined;
|
|
21941
22728
|
if (!shared)
|
|
21942
22729
|
return false;
|
|
21943
|
-
const url = configEntries(
|
|
22730
|
+
const url = configEntries(fs23.readFileSync(path36.join(shared, "config"), "utf8")).find(([key]) => key === `remote.${name}.url`.toLowerCase())?.[1];
|
|
21944
22731
|
return url !== undefined && literalIn(url, repo, true);
|
|
21945
22732
|
};
|
|
21946
22733
|
var judgeEnvAllowed = (word) => {
|
|
@@ -21969,7 +22756,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
21969
22756
|
at = after;
|
|
21970
22757
|
}
|
|
21971
22758
|
}
|
|
21972
|
-
const name =
|
|
22759
|
+
const name = path36.basename(words[at] ?? "");
|
|
21973
22760
|
let start = words.findIndex((word) => /(?:^|[\\/])git(?:\.exe)?(?:=|$)/.test(word));
|
|
21974
22761
|
if (start > at) {
|
|
21975
22762
|
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] ?? ""))
|
|
@@ -21980,7 +22767,7 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
21980
22767
|
if (start >= 0 && words[start].includes("="))
|
|
21981
22768
|
why = "git is redefined";
|
|
21982
22769
|
const run = words[start] ?? "";
|
|
21983
|
-
if (run.includes("/") && (!
|
|
22770
|
+
if (run.includes("/") && (!path36.isAbsolute(run) || literalIn(run, repo, true)))
|
|
21984
22771
|
why ??= `\`${run}\` is not the system git`;
|
|
21985
22772
|
if (segment.expands?.includes(at) && name !== "[" || /\{[^}]*,/.test(words[at] ?? ""))
|
|
21986
22773
|
why = "the command's name is expanded by the shell";
|
|
@@ -22005,13 +22792,13 @@ var judgeGit = (command, repo, cwd, depth = 0) => {
|
|
|
22005
22792
|
const args = words[index] === "--version" ? ["version"] : words.slice(index);
|
|
22006
22793
|
if (!why && start >= 0) {
|
|
22007
22794
|
const local = (source, remote) => remote && /^[\w-][\w.-]*$/.test(source) ? remoteIn(dir, source, repo) : literalIn(source, repo, true);
|
|
22008
|
-
const runsIn =
|
|
22795
|
+
const runsIn = path36.isAbsolute(dir) ? dir : cwd && path36.resolve(cwd, dir);
|
|
22009
22796
|
const home = runsIn && checkoutOf2(runsIn);
|
|
22010
22797
|
const fetches = args[0] === "fetch" && plainFetch(args.slice(1)) && home && (home.workit || commonDir(home.root) === repo) && !words.some((word) => /^--[gw]/.test(word));
|
|
22011
22798
|
if (!fetches && !gitKind(args, local))
|
|
22012
22799
|
why = `\`git ${args.slice(0, 2).join(" ")}\` is not allowed`;
|
|
22013
22800
|
}
|
|
22014
|
-
const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(
|
|
22801
|
+
const shell = /^(?:grep|egrep|rg|echo|printf|cat)$/.test(name) ? -1 : words.findIndex((word) => /^(?:sh|bash|zsh|dash|ksh|mksh|ash)$/.test(path36.basename(word)));
|
|
22015
22802
|
const scripts = [
|
|
22016
22803
|
...words.filter((_, after) => shell >= 0 && after > shell && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(words[after - 1])),
|
|
22017
22804
|
...shell < 0 ? [] : segment.stdin ?? []
|
|
@@ -22056,7 +22843,7 @@ var judgeVerbRefused = (args) => {
|
|
|
22056
22843
|
var CLI_RUNNERS = /^(?:npx|bunx|pnpx|npm|pnpm|yarn|bun|node|nodejs|deno|tsx|ts-node)$/;
|
|
22057
22844
|
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?$/;
|
|
22058
22845
|
var workitCalls = (command, depth = 0, aliases = new Map) => depth > 4 ? [] : commandLines(command).flatMap((words) => {
|
|
22059
|
-
const name =
|
|
22846
|
+
const name = path36.basename(words[0] ?? "").toLowerCase();
|
|
22060
22847
|
if (name === "alias")
|
|
22061
22848
|
return words.flatMap((word) => {
|
|
22062
22849
|
const set = /^([\w-]+)=(.*)$/s.exec(word);
|
|
@@ -22085,11 +22872,11 @@ var judgeRefusal = (command, fed, depth = 0) => {
|
|
|
22085
22872
|
return why;
|
|
22086
22873
|
}
|
|
22087
22874
|
const { words } = segment;
|
|
22088
|
-
const runs = (word = "") => RUNS.test(
|
|
22875
|
+
const runs = (word = "") => RUNS.test(path36.basename(word).toLowerCase());
|
|
22089
22876
|
let at = 0;
|
|
22090
22877
|
while (at < words.length && (LEADS.test(words[at]) || /^-\w$/.test(words[at - 1] ?? "") && !runs(words[at])))
|
|
22091
22878
|
at++;
|
|
22092
|
-
const name =
|
|
22879
|
+
const name = path36.basename(words[at] ?? "").toLowerCase();
|
|
22093
22880
|
const args = words.slice(at + 1);
|
|
22094
22881
|
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`;
|
|
22095
22882
|
if (/^(?:cd|chdir|pushd|popd)$/.test(name))
|
|
@@ -22171,10 +22958,10 @@ var judgeDeny = (input, what, target, retry, why = "write only there (mkdir -p i
|
|
|
22171
22958
|
const role = input.session.agentType?.endsWith("reviewer") ? "reviewer" : "verifier";
|
|
22172
22959
|
const root = checkoutOf2(input.cwd)?.root;
|
|
22173
22960
|
const candidate = target ? checkoutOf2(target)?.root : undefined;
|
|
22174
|
-
const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ?
|
|
22175
|
-
const scratch = root ? `${
|
|
22176
|
-
const call = root ? retry?.((other ??
|
|
22177
|
-
const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ?
|
|
22961
|
+
const other = root && candidate && candidate !== root && commonDir(candidate) === commonDir(root) ? path36.join(candidate, SCRATCH) : undefined;
|
|
22962
|
+
const scratch = root ? `${path36.join(root, SCRATCH)}${other ? ` or ${other}` : ""}` : `${SCRATCH}/ at the root of the checkout you judge`;
|
|
22963
|
+
const call = root ? retry?.((other ?? path36.join(root, SCRATCH)).replaceAll("\\", "/")) : null;
|
|
22964
|
+
const unblock = call ? `Retry as: ${call}` : `Why: ${why.replaceAll("<scratch>", other ?? (root ? path36.join(root, SCRATCH) : SCRATCH))}`;
|
|
22178
22965
|
return {
|
|
22179
22966
|
kind: "deny",
|
|
22180
22967
|
reason: `workit scratch confinement: ${role} ${input.session.agentId} may write only in its scratch dir ${scratch}, and ${what}.
|
|
@@ -22184,9 +22971,9 @@ ${unblock}`,
|
|
|
22184
22971
|
};
|
|
22185
22972
|
var movedInto = (command, cwd, target, dir) => {
|
|
22186
22973
|
for (const { words, redirects } of segmentsOf(command))
|
|
22187
|
-
for (const word of [...redirects, ...
|
|
22188
|
-
if (
|
|
22189
|
-
const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${
|
|
22974
|
+
for (const word of [...redirects, ...path36.basename(words[0] ?? "") === "tee" ? words : []])
|
|
22975
|
+
if (path36.resolve(cwd, word) === path36.resolve(cwd, target)) {
|
|
22976
|
+
const moved = command.replace(new RegExp(`((?:>>?\\|?|\\btee(?:\\s+-a)?)\\s*)(['"]?)${word.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")}\\2(?![^\\s;&|)])`), (_, lead) => `${lead}${dir}/${path36.basename(word)}`);
|
|
22190
22977
|
return moved === command ? null : moved;
|
|
22191
22978
|
}
|
|
22192
22979
|
return null;
|
|
@@ -22198,19 +22985,19 @@ function confineJudge(input, targets, placeholders = placeholdersOf(targets), co
|
|
|
22198
22985
|
const judged = checkoutOf2(input.cwd);
|
|
22199
22986
|
const repo = judged ? commonDir(judged.root) : null;
|
|
22200
22987
|
const scratch = (real) => inScratch(real, repo) || [os10.tmpdir(), "/tmp"].some((dir) => {
|
|
22201
|
-
const [host, , session] =
|
|
22988
|
+
const [host, , session] = path36.relative(canonical6(dir), real).split(path36.sep);
|
|
22202
22989
|
return /^claude-\d+$/.test(host) && session === input.session.id;
|
|
22203
22990
|
});
|
|
22204
22991
|
for (const target of targets) {
|
|
22205
|
-
const resolved =
|
|
22992
|
+
const resolved = path36.resolve(target);
|
|
22206
22993
|
if (within(resolved, UNKNOWN_VAR) || within(resolved, UNKNOWN_DIR))
|
|
22207
22994
|
return judgeDeny(input, "it writes to a path Workit cannot resolve", undefined, () => {
|
|
22208
22995
|
const literal = command && literalForm(command, refsOf([target]));
|
|
22209
22996
|
return literal === command ? null : literal;
|
|
22210
22997
|
});
|
|
22211
22998
|
const real = canonical6(target);
|
|
22212
|
-
const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(
|
|
22213
|
-
const gitDirs = runsGit ? gitDirsAt(
|
|
22999
|
+
const runsGit = placeholders.has(target) && /^\.workit-(?:runs-git|live-target)$/.test(path36.basename(target));
|
|
23000
|
+
const gitDirs = runsGit ? gitDirsAt(path36.dirname(real), repo) : [];
|
|
22214
23001
|
if (gitDirs === null)
|
|
22215
23002
|
return judgeDeny(input, `git in ${shown(target)} uses a git dir or config Workit cannot check`);
|
|
22216
23003
|
if (runsGit ? gitDirs.length > 0 ? gitDirs.every(scratch) : scratch(real) : scratch(real) && !inGitDir(real))
|
|
@@ -22278,7 +23065,7 @@ function confineJudgeShell(input, command, dialect = "posix") {
|
|
|
22278
23065
|
let git = [];
|
|
22279
23066
|
try {
|
|
22280
23067
|
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)))) ? [
|
|
22281
|
-
|
|
23068
|
+
path36.join(dir === undefined ? UNKNOWN_DIR : path36.resolve(input.cwd, dir ?? "."), `${OPAQUE_TARGET}git`)
|
|
22282
23069
|
] : []);
|
|
22283
23070
|
} catch {}
|
|
22284
23071
|
const lists = [
|
|
@@ -22323,17 +23110,17 @@ var judgeChecksLine = (cwd) => {
|
|
|
22323
23110
|
|
|
22324
23111
|
// packages/workit-core/src/hooks/standing.ts
|
|
22325
23112
|
var readPlans = (store) => {
|
|
22326
|
-
const dir =
|
|
23113
|
+
const dir = path37.join(store, "fanouts");
|
|
22327
23114
|
let names;
|
|
22328
23115
|
try {
|
|
22329
|
-
names =
|
|
23116
|
+
names = fs24.readdirSync(dir).filter((name) => name.endsWith(".json"));
|
|
22330
23117
|
} catch {
|
|
22331
23118
|
return [];
|
|
22332
23119
|
}
|
|
22333
23120
|
const plans = [];
|
|
22334
23121
|
for (const name of names) {
|
|
22335
23122
|
try {
|
|
22336
|
-
const raw = JSON.parse(
|
|
23123
|
+
const raw = JSON.parse(fs24.readFileSync(path37.join(dir, name), "utf8"));
|
|
22337
23124
|
if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
|
|
22338
23125
|
continue;
|
|
22339
23126
|
const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
|
|
@@ -22455,100 +23242,14 @@ var standingDelta = (input) => {
|
|
|
22455
23242
|
}
|
|
22456
23243
|
};
|
|
22457
23244
|
var sinceStart = new Map;
|
|
22458
|
-
// packages/workit-core/src/hooks/cwd-normalize.ts
|
|
22459
|
-
var DIR2 = String.raw`(?:[A-Za-z0-9_./@%+:,=-]|(?<=[A-Za-z0-9])~)+|'[^'$${"`"}\n]*'|"(?:[^"$${"`"}\\!\n]|\\(?=[^"$${"`"}\\!\n]))*"`;
|
|
22460
|
-
var COMPOUND2 = new RegExp(String.raw`^\s*cd\s+(${DIR2})\s*&&\s*(workit(?:\s[\s\S]*)?)$`, "u");
|
|
22461
|
-
var GLOBALS_FIRST = new RegExp(String.raw`^(\s*workit)((?:\s+(?:--json|--cwd(?:=|\s+)(?:${DIR2})))+)\s+([a-z][a-z-]*)(?=\s|$)`, "u");
|
|
22462
|
-
var VERB_FIRST = /^((?:--json\s+)*)([a-z][a-z-]*)(?=\s|$)/u;
|
|
22463
|
-
var VERBS = new Set(WORKIT_ALLOWED_VERBS);
|
|
22464
|
-
var FILTERS = new Set(["tail", "head", "grep"]);
|
|
22465
|
-
var clean = (s) => !s.unanalyzable && !s.group && !s.subs?.length && !s.stdin?.length && !s.redirects.length;
|
|
22466
|
-
var stdinOnly = (words) => {
|
|
22467
|
-
const [name, ...args] = words;
|
|
22468
|
-
const operands = args.filter((w) => !w.startsWith("-"));
|
|
22469
|
-
if (name === "grep")
|
|
22470
|
-
return operands.length <= 1 && !args.some((w) => /^-[^-]*[rRf]|^--(recursive|file)/u.test(w));
|
|
22471
|
-
return operands.every((w) => /^\d+$/u.test(w)) && !args.some((w) => w.startsWith("--output"));
|
|
22472
|
-
};
|
|
22473
|
-
var cwdRewrite = (command) => {
|
|
22474
|
-
const match = COMPOUND2.exec(command);
|
|
22475
|
-
const dir = match?.[1];
|
|
22476
|
-
const rest = match?.[2];
|
|
22477
|
-
if (!dir || !rest || dir.startsWith("-"))
|
|
22478
|
-
return null;
|
|
22479
|
-
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "").replaceAll(/'[^']*'|"([^"\\]|\\.)*"/gu, "")))
|
|
22480
|
-
return null;
|
|
22481
|
-
const segments = segmentsOf(rest);
|
|
22482
|
-
const [head, ...filters] = segments;
|
|
22483
|
-
if (!head || head.words[0] !== "workit")
|
|
22484
|
-
return null;
|
|
22485
|
-
if (!segments.every(clean))
|
|
22486
|
-
return null;
|
|
22487
|
-
if (!segments.slice(0, -1).every((s) => s.pipe))
|
|
22488
|
-
return null;
|
|
22489
|
-
if (!filters.every((s) => FILTERS.has(s.words[0] ?? "") && stdinOnly(s.words)))
|
|
22490
|
-
return null;
|
|
22491
|
-
const at = head.words.indexOf("--cwd");
|
|
22492
|
-
if (at >= 0) {
|
|
22493
|
-
const bare = dir.replace(/^(['"])(.*)\1$/u, "$2");
|
|
22494
|
-
return bare[0] === "/" && head.words[at + 1] === bare ? rest : null;
|
|
22495
|
-
}
|
|
22496
|
-
if (head.words.some((w) => w.startsWith("--cwd=")))
|
|
22497
|
-
return null;
|
|
22498
|
-
const args = rest.slice("workit".length).trimStart();
|
|
22499
|
-
const verb = VERB_FIRST.exec(args);
|
|
22500
|
-
if (!verb?.[2] || !VERBS.has(verb[2]))
|
|
22501
|
-
return `workit --cwd ${dir} ${args}`.trimEnd();
|
|
22502
|
-
const json = verb[1] ? " --json" : "";
|
|
22503
|
-
return `workit ${verb[2]} --cwd ${dir}${json}${args.slice(verb[0].length)}`.trimEnd();
|
|
22504
|
-
};
|
|
22505
|
-
var verbFirst = (command) => {
|
|
22506
|
-
const match = GLOBALS_FIRST.exec(command);
|
|
22507
|
-
const [whole, lead, globals, verb] = match ?? [];
|
|
22508
|
-
if (!whole || !verb || !VERBS.has(verb) || !globals?.includes("--cwd"))
|
|
22509
|
-
return null;
|
|
22510
|
-
const segments = segmentsOf(command);
|
|
22511
|
-
if (segments.length !== 1 || !segments.every(clean))
|
|
22512
|
-
return null;
|
|
22513
|
-
return `${lead} ${verb}${globals}${command.slice(whole.length)}`;
|
|
22514
|
-
};
|
|
22515
|
-
var NPX = new RegExp(String.raw`^(\s*(?:cd\s+(?:${DIR2})\s*&&\s*)?)npx(?:\s+(?:-y|--yes))*\s+@workit-dev\/cli(?:@[\w.-]+)?(?=\s|$)`, "u");
|
|
22516
|
-
var npxWorkit = (command) => {
|
|
22517
|
-
const match = NPX.exec(command);
|
|
22518
|
-
if (!match)
|
|
22519
|
-
return null;
|
|
22520
|
-
const call = `${match[1]}workit${command.slice(match[0].length)}`;
|
|
22521
|
-
const left = segmentsOf(call).some((s) => s.unanalyzable || s.words.some((w) => /^(npx|@workit-dev\/cli(@\S*)?)$/u.test(w)));
|
|
22522
|
-
return left ? null : cwdRewrite(call) ?? verbFirst(call) ?? call;
|
|
22523
|
-
};
|
|
22524
|
-
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;
|
|
22525
|
-
var cdWorkitSplit = (command) => {
|
|
22526
|
-
const match = COMPOUND2.exec(command);
|
|
22527
|
-
const dir = match?.[1];
|
|
22528
|
-
const rest = match?.[2];
|
|
22529
|
-
if (!dir || !rest || cwdRewrite(command) !== null)
|
|
22530
|
-
return null;
|
|
22531
|
-
const whole = segmentsOf(rest);
|
|
22532
|
-
const boundary = (head) => segmentsOf(head).every((s, at) => s.words.join("\x00") === whole[at]?.words.join("\x00"));
|
|
22533
|
-
for (const op of rest.matchAll(/\|\||;/gu)) {
|
|
22534
|
-
const head = rest.slice(0, op.index).trimEnd();
|
|
22535
|
-
const call = cwdRewrite(`cd ${dir} && ${head}`);
|
|
22536
|
-
if (!call || !boundary(head))
|
|
22537
|
-
continue;
|
|
22538
|
-
const next = segmentsOf(rest.slice(op.index + op[0].length))[0];
|
|
22539
|
-
return next && MUTATING_GIT2.test(next.words.join(" ")) ? call : null;
|
|
22540
|
-
}
|
|
22541
|
-
return null;
|
|
22542
|
-
};
|
|
22543
|
-
|
|
22544
23245
|
// packages/workit-core/src/hooks/spawn-gate.ts
|
|
22545
|
-
import
|
|
22546
|
-
import
|
|
23246
|
+
import fs25 from "node:fs";
|
|
23247
|
+
import path39 from "node:path";
|
|
22547
23248
|
|
|
22548
23249
|
// packages/workit-core/src/hooks/model-limit.ts
|
|
22549
23250
|
import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync5, readSync, statSync as statSync5 } from "node:fs";
|
|
22550
23251
|
import os11 from "node:os";
|
|
22551
|
-
import
|
|
23252
|
+
import path38 from "node:path";
|
|
22552
23253
|
var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
22553
23254
|
var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
22554
23255
|
var TIME_WORD = String.raw`(?:\d|(?:in|at|on|later|tomorrow|soon)\b|(?:${[...WEEKDAYS, ...MONTHS].join("|")})[a-z]*\b)`;
|
|
@@ -22746,17 +23447,17 @@ var firstPrompt = (file) => {
|
|
|
22746
23447
|
var claudeProjectSlug = (cwd) => cwd.replace(/[^A-Za-z0-9]/gu, "-");
|
|
22747
23448
|
var listDir = (dir) => {
|
|
22748
23449
|
try {
|
|
22749
|
-
return readdirSync5(dir).map((name) =>
|
|
23450
|
+
return readdirSync5(dir).map((name) => path38.join(dir, name));
|
|
22750
23451
|
} catch {
|
|
22751
23452
|
return [];
|
|
22752
23453
|
}
|
|
22753
23454
|
};
|
|
22754
23455
|
var SCAN_MS = 30 * 60000;
|
|
22755
23456
|
var scanClaudeTranscripts = (cwd, env, now = new Date) => {
|
|
22756
|
-
const projects =
|
|
22757
|
-
const project =
|
|
23457
|
+
const projects = path38.join(env.CLAUDE_CONFIG_DIR || path38.join(env.HOME || os11.homedir(), ".claude"), "projects");
|
|
23458
|
+
const project = path38.join(projects, claudeProjectSlug(cwd));
|
|
22758
23459
|
const notes = [];
|
|
22759
|
-
const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(
|
|
23460
|
+
const files = listDir(project).flatMap((entry) => entry.endsWith(".jsonl") ? [{ file: entry, worker: false }] : listDir(path38.join(entry, "subagents")).filter((file) => file.endsWith(".jsonl")).map((file) => ({ file, worker: true })));
|
|
22760
23461
|
for (const { file, worker } of files)
|
|
22761
23462
|
try {
|
|
22762
23463
|
const stat = statSync5(file);
|
|
@@ -22771,7 +23472,7 @@ var scanClaudeTranscripts = (cwd, env, now = new Date) => {
|
|
|
22771
23472
|
if (!seen)
|
|
22772
23473
|
continue;
|
|
22773
23474
|
notes.push(worker ? redispatchNote(seen, {
|
|
22774
|
-
label: `worker ${
|
|
23475
|
+
label: `worker ${path38.basename(file, ".jsonl")}`,
|
|
22775
23476
|
prompt: firstPrompt(file)
|
|
22776
23477
|
}, 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.`);
|
|
22777
23478
|
} catch {}
|
|
@@ -22870,13 +23571,13 @@ var agentModelDecision = (cwd, tool, options = {}) => {
|
|
|
22870
23571
|
var MADE_WORKTREE = /^WORKTREE:[ \t]*(?!not made yet)\S(?![^\n]*not made yet)/mu;
|
|
22871
23572
|
var namesMade = (word) => {
|
|
22872
23573
|
try {
|
|
22873
|
-
const stat =
|
|
23574
|
+
const stat = fs25.statSync(word);
|
|
22874
23575
|
if (stat.isFile())
|
|
22875
|
-
return stat.size < 1e6 && MADE_WORKTREE.test(
|
|
22876
|
-
const dotGit =
|
|
22877
|
-
const link =
|
|
22878
|
-
const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(
|
|
22879
|
-
return !!admin &&
|
|
23576
|
+
return stat.size < 1e6 && MADE_WORKTREE.test(fs25.readFileSync(word, "utf8"));
|
|
23577
|
+
const dotGit = path39.join(word, ".git");
|
|
23578
|
+
const link = fs25.statSync(dotGit);
|
|
23579
|
+
const admin = link.isFile() && link.size <= 4096 && /^gitdir: *(.+)/u.exec(fs25.readFileSync(dotGit, "utf8"));
|
|
23580
|
+
return !!admin && fs25.existsSync(path39.resolve(word, admin[1].trim(), FANOUT_TOKEN_FILE));
|
|
22880
23581
|
} catch {
|
|
22881
23582
|
return false;
|
|
22882
23583
|
}
|
|
@@ -22922,8 +23623,8 @@ var spawnDecision = (descriptor, cwd, tool, permissionMode = null) => {
|
|
|
22922
23623
|
|
|
22923
23624
|
// packages/workit-core/src/hooks/teardown.ts
|
|
22924
23625
|
import { spawn } from "node:child_process";
|
|
22925
|
-
import
|
|
22926
|
-
import
|
|
23626
|
+
import fs26 from "node:fs";
|
|
23627
|
+
import path40 from "node:path";
|
|
22927
23628
|
var REAP_INTERVAL_MS = 10 * 60000;
|
|
22928
23629
|
var LOG_MAX_BYTES = 1 << 20;
|
|
22929
23630
|
var ENDS = {
|
|
@@ -22934,9 +23635,9 @@ var ENDS = {
|
|
|
22934
23635
|
};
|
|
22935
23636
|
var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
|
|
22936
23637
|
var HOST_SESSION_VARS = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
|
|
22937
|
-
var teardownDir = (env) =>
|
|
22938
|
-
var teardownLog = (env) =>
|
|
22939
|
-
var reapStamp = (env) =>
|
|
23638
|
+
var teardownDir = (env) => path40.join(stateDir3(env), "procs");
|
|
23639
|
+
var teardownLog = (env) => path40.join(teardownDir(env), "teardown.log");
|
|
23640
|
+
var reapStamp = (env) => path40.join(teardownDir(env), "reap-at-start.stamp");
|
|
22940
23641
|
function spawnDetached(request) {
|
|
22941
23642
|
try {
|
|
22942
23643
|
const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
|
|
@@ -22963,13 +23664,13 @@ var teardownDeps = {
|
|
|
22963
23664
|
var openLog = (env, args) => {
|
|
22964
23665
|
try {
|
|
22965
23666
|
const file = teardownLog(env);
|
|
22966
|
-
|
|
23667
|
+
fs26.mkdirSync(path40.dirname(file), { recursive: true });
|
|
22967
23668
|
let size = 0;
|
|
22968
23669
|
try {
|
|
22969
|
-
size =
|
|
23670
|
+
size = fs26.statSync(file).size;
|
|
22970
23671
|
} catch {}
|
|
22971
|
-
const fd =
|
|
22972
|
-
|
|
23672
|
+
const fd = fs26.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
|
|
23673
|
+
fs26.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
|
|
22973
23674
|
`);
|
|
22974
23675
|
return fd;
|
|
22975
23676
|
} catch {
|
|
@@ -22981,7 +23682,7 @@ function runCli(args, env) {
|
|
|
22981
23682
|
try {
|
|
22982
23683
|
const cli = locateWorkitCli2({ env });
|
|
22983
23684
|
const cwd = teardownDir(env);
|
|
22984
|
-
|
|
23685
|
+
fs26.mkdirSync(cwd, { recursive: true });
|
|
22985
23686
|
log = openLog(env, args);
|
|
22986
23687
|
const started = teardownDeps.spawn({
|
|
22987
23688
|
command: cli.command,
|
|
@@ -22991,7 +23692,7 @@ function runCli(args, env) {
|
|
|
22991
23692
|
log
|
|
22992
23693
|
});
|
|
22993
23694
|
if (!started && log !== null)
|
|
22994
|
-
|
|
23695
|
+
fs26.writeSync(log, ` not started
|
|
22995
23696
|
`);
|
|
22996
23697
|
return started;
|
|
22997
23698
|
} catch {
|
|
@@ -22999,7 +23700,7 @@ function runCli(args, env) {
|
|
|
22999
23700
|
} finally {
|
|
23000
23701
|
if (log !== null)
|
|
23001
23702
|
try {
|
|
23002
|
-
|
|
23703
|
+
fs26.closeSync(log);
|
|
23003
23704
|
} catch {}
|
|
23004
23705
|
}
|
|
23005
23706
|
}
|
|
@@ -23018,24 +23719,24 @@ function endSession(end, env = process.env) {
|
|
|
23018
23719
|
var claim2 = (file, now) => {
|
|
23019
23720
|
for (let attempt = 0;attempt < 2; attempt += 1)
|
|
23020
23721
|
try {
|
|
23021
|
-
|
|
23722
|
+
fs26.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
|
|
23022
23723
|
return true;
|
|
23023
23724
|
} catch (error) {
|
|
23024
23725
|
if (error.code !== "EEXIST")
|
|
23025
23726
|
return false;
|
|
23026
23727
|
let held = Number.NaN;
|
|
23027
23728
|
try {
|
|
23028
|
-
held = Number(
|
|
23729
|
+
held = Number(fs26.readFileSync(file, "utf8"));
|
|
23029
23730
|
} catch {}
|
|
23030
23731
|
if (now - held < REAP_INTERVAL_MS)
|
|
23031
23732
|
return false;
|
|
23032
|
-
|
|
23733
|
+
fs26.rmSync(file, { force: true });
|
|
23033
23734
|
}
|
|
23034
23735
|
return false;
|
|
23035
23736
|
};
|
|
23036
23737
|
var fresh = (stamp, now) => {
|
|
23037
23738
|
try {
|
|
23038
|
-
const last = Number(
|
|
23739
|
+
const last = Number(fs26.readFileSync(stamp, "utf8"));
|
|
23039
23740
|
return now - last < REAP_INTERVAL_MS && last <= now;
|
|
23040
23741
|
} catch {
|
|
23041
23742
|
return false;
|
|
@@ -23048,7 +23749,7 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
23048
23749
|
try {
|
|
23049
23750
|
if (fresh(stamp, now))
|
|
23050
23751
|
return false;
|
|
23051
|
-
|
|
23752
|
+
fs26.mkdirSync(path40.dirname(stamp), { recursive: true });
|
|
23052
23753
|
if (!claim2(lock, now))
|
|
23053
23754
|
return false;
|
|
23054
23755
|
} catch {
|
|
@@ -23061,12 +23762,12 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
23061
23762
|
started = runCli(["stop", "--orphans", "--reason", "session-start"], env);
|
|
23062
23763
|
if (started) {
|
|
23063
23764
|
const temp = `${stamp}.${process.pid}`;
|
|
23064
|
-
|
|
23065
|
-
|
|
23765
|
+
fs26.writeFileSync(temp, String(now), { mode: 384 });
|
|
23766
|
+
fs26.renameSync(temp, stamp);
|
|
23066
23767
|
}
|
|
23067
23768
|
} catch {} finally {
|
|
23068
23769
|
try {
|
|
23069
|
-
|
|
23770
|
+
fs26.rmSync(lock, { force: true });
|
|
23070
23771
|
} catch {}
|
|
23071
23772
|
}
|
|
23072
23773
|
return started;
|
|
@@ -23628,119 +24329,27 @@ var ytrackGate = (cwd, command, dialect, ask) => {
|
|
|
23628
24329
|
const calls = writes.flatMap((write) => write.workit ? [`\`${write.workit}\``] : []);
|
|
23629
24330
|
const bare = writes.filter((write) => !write.workit).map((write) => `\`${write.command}\` (${write.gap ? `Workit cannot carry ${write.gap} into a workit youtrack call` : "no workit youtrack verb covers it"})`);
|
|
23630
24331
|
if (!calls.length && ask)
|
|
23631
|
-
return {
|
|
23632
|
-
kind: "ask",
|
|
23633
|
-
reason: `${bare.join(", ")} writes to YouTrack: the user decides this call (#780).`
|
|
23634
|
-
};
|
|
23635
|
-
const why = `A raw ytrack write posts to YouTrack without the user's yes (#780).`;
|
|
23636
|
-
const run = calls.length ? ` Run ${calls.join(", then ")} instead, each as its own plain call: it asks the user first.` : "";
|
|
23637
|
-
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.` : "";
|
|
23638
|
-
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." : "";
|
|
23639
|
-
const retry = writes.find((write) => write.workit)?.workit ?? (rerun ? writes.find((write) => write.gap === NOT_PLAIN.gap)?.command : undefined);
|
|
23640
|
-
return {
|
|
23641
|
-
kind: "deny",
|
|
23642
|
-
reason: `${why}${run}${user}${rerun}${retry ? `
|
|
23643
|
-
Retry as: ${retry}` : ""}`,
|
|
23644
|
-
unblock: writes[0]?.workit ?? null
|
|
23645
|
-
};
|
|
23646
|
-
};
|
|
23647
|
-
|
|
23648
|
-
// packages/workit-core/src/hooks/exit-pipe.ts
|
|
23649
|
-
var EXIT_VERBS = [
|
|
23650
|
-
["ci", "wait"],
|
|
23651
|
-
["check"],
|
|
23652
|
-
["pr", "merge"],
|
|
23653
|
-
["release"],
|
|
23654
|
-
["verify-delivery"]
|
|
23655
|
-
];
|
|
23656
|
-
var base = (word = "") => word.split(/[\\/]/u).at(-1) ?? "";
|
|
23657
|
-
var quote3 = (word) => /^[\w@%+=:,./-]+$/u.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
|
|
23658
|
-
var verbPath = (words) => {
|
|
23659
|
-
const path = [];
|
|
23660
|
-
for (let at = 0;at < words.length && path.length < 2; at += 1) {
|
|
23661
|
-
const word = words[at];
|
|
23662
|
-
if (word === "--")
|
|
23663
|
-
break;
|
|
23664
|
-
if (word === "--cwd")
|
|
23665
|
-
at += 1;
|
|
23666
|
-
else if (!word.startsWith("-"))
|
|
23667
|
-
path.push(word);
|
|
23668
|
-
}
|
|
23669
|
-
return path;
|
|
23670
|
-
};
|
|
23671
|
-
var exitCall = (words) => {
|
|
23672
|
-
let at = 0;
|
|
23673
|
-
while (at < words.length && /^[A-Za-z_]\w*=/u.test(words[at]))
|
|
23674
|
-
at += 1;
|
|
23675
|
-
if (!/^workit(?:-cli)?$/u.test(base(words[at])))
|
|
23676
|
-
return null;
|
|
23677
|
-
const path = verbPath(words.slice(at + 1));
|
|
23678
|
-
return EXIT_VERBS.some((verb) => verb.every((word, index) => path[index] === word)) ? words.slice(at) : null;
|
|
23679
|
-
};
|
|
23680
|
-
var setsPipefail = (words) => words[0] === "set" && words.some((word, at) => word === "pipefail" && /^-[a-z]*o$/u.test(words[at - 1] ?? ""));
|
|
23681
|
-
var retryOf = ({ call, dir }) => {
|
|
23682
|
-
const at = call[1]?.startsWith("-") ? 1 : 2;
|
|
23683
|
-
const words = dir && !call.includes("--cwd") ? [...call.slice(0, at), "--cwd", dir, ...call.slice(at)] : call;
|
|
23684
|
-
return ["workit", ...words.slice(1)].map(quote3).join(" ");
|
|
23685
|
-
};
|
|
23686
|
-
function exitPipeGate(command, dialect = "posix") {
|
|
23687
|
-
if (!/\bworkit/u.test(command) || !/\b(?:tail|head)\b/u.test(command))
|
|
23688
|
-
return null;
|
|
23689
|
-
const groups = [];
|
|
23690
|
-
let carry = null;
|
|
23691
|
-
let pipefail = false;
|
|
23692
|
-
let dir = null;
|
|
23693
|
-
for (const segment of segmentsOf(command, dialect)) {
|
|
23694
|
-
if (segment.unanalyzable)
|
|
23695
|
-
return null;
|
|
23696
|
-
let words = segment.words;
|
|
23697
|
-
let closes = segment.group === "close";
|
|
23698
|
-
if (segment.group === "open") {
|
|
23699
|
-
groups.push(null);
|
|
23700
|
-
continue;
|
|
23701
|
-
}
|
|
23702
|
-
if (words[0] === "{") {
|
|
23703
|
-
groups.push(null);
|
|
23704
|
-
words = words.slice(1);
|
|
23705
|
-
} else if (words[0] === "}") {
|
|
23706
|
-
closes = true;
|
|
23707
|
-
words = words.slice(1);
|
|
23708
|
-
}
|
|
23709
|
-
if (closes) {
|
|
23710
|
-
const inner = groups.pop() ?? null;
|
|
23711
|
-
if (inner && groups.length)
|
|
23712
|
-
groups[groups.length - 1] = inner;
|
|
23713
|
-
carry = segment.pipe ? inner ?? carry : null;
|
|
23714
|
-
continue;
|
|
23715
|
-
}
|
|
23716
|
-
if (!words.length && !segment.stdin && !segment.subs)
|
|
23717
|
-
continue;
|
|
23718
|
-
if (setsPipefail(words))
|
|
23719
|
-
pipefail = true;
|
|
23720
|
-
const filter = base(words[0]);
|
|
23721
|
-
if (carry && !pipefail && (filter === "tail" || filter === "head")) {
|
|
23722
|
-
const retry = retryOf(carry);
|
|
23723
|
-
return {
|
|
23724
|
-
kind: "deny",
|
|
23725
|
-
reason: `workit exit-pipe: piping \`workit ${verbPath(carry.call.slice(1)).join(" ")}\` into ${filter} hides its exit code.
|
|
23726
|
-
Retry as: ${retry}`,
|
|
23727
|
-
unblock: retry
|
|
23728
|
-
};
|
|
23729
|
-
}
|
|
23730
|
-
const call = exitCall(words);
|
|
23731
|
-
const found = call ? { call, dir } : null;
|
|
23732
|
-
if (found && groups.length)
|
|
23733
|
-
groups[groups.length - 1] = found;
|
|
23734
|
-
carry = segment.pipe ? found ?? carry : null;
|
|
23735
|
-
dir = words.length === 2 && words[0] === "cd" && !segment.expands?.length ? words[1] : null;
|
|
23736
|
-
}
|
|
23737
|
-
return null;
|
|
23738
|
-
}
|
|
24332
|
+
return {
|
|
24333
|
+
kind: "ask",
|
|
24334
|
+
reason: `${bare.join(", ")} writes to YouTrack: the user decides this call (#780).`
|
|
24335
|
+
};
|
|
24336
|
+
const why = `A raw ytrack write posts to YouTrack without the user's yes (#780).`;
|
|
24337
|
+
const run = calls.length ? ` Run ${calls.join(", then ")} instead, each as its own plain call: it asks the user first.` : "";
|
|
24338
|
+
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.` : "";
|
|
24339
|
+
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." : "";
|
|
24340
|
+
const retry = writes.find((write) => write.workit)?.workit ?? (rerun ? writes.find((write) => write.gap === NOT_PLAIN.gap)?.command : undefined);
|
|
24341
|
+
return {
|
|
24342
|
+
kind: "deny",
|
|
24343
|
+
reason: `${why}${run}${user}${rerun}${retry ? `
|
|
24344
|
+
Retry as: ${retry}` : ""}`,
|
|
24345
|
+
unblock: writes[0]?.workit ?? null
|
|
24346
|
+
};
|
|
24347
|
+
};
|
|
23739
24348
|
|
|
23740
24349
|
// packages/workit-core/src/agent-stamp.ts
|
|
23741
24350
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
23742
|
-
import
|
|
23743
|
-
import
|
|
24351
|
+
import fs27 from "node:fs";
|
|
24352
|
+
import path41 from "node:path";
|
|
23744
24353
|
var STAMP_TTL_MS = 120000;
|
|
23745
24354
|
var AGENT_ID = /^[\w-]{1,64}$/u;
|
|
23746
24355
|
var workitCalls2 = (command, dialect = "posix") => {
|
|
@@ -23764,12 +24373,12 @@ var noteAgentStamps = (env, session, agentId, command, options = {}) => {
|
|
|
23764
24373
|
const call = options.toolUseId ? callTag2(options.toolUseId) : randomBytes4(4).toString("hex");
|
|
23765
24374
|
try {
|
|
23766
24375
|
const dir = stampDir2(env, session);
|
|
23767
|
-
|
|
24376
|
+
fs27.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
23768
24377
|
const now = Date.now();
|
|
23769
|
-
for (const name of
|
|
23770
|
-
if (now -
|
|
23771
|
-
|
|
23772
|
-
calls.forEach((argv, index) =>
|
|
24378
|
+
for (const name of fs27.readdirSync(dir))
|
|
24379
|
+
if (now - fs27.statSync(path41.join(dir, name)).mtimeMs > STAMP_TTL_MS)
|
|
24380
|
+
fs27.rmSync(path41.join(dir, name), { force: true });
|
|
24381
|
+
calls.forEach((argv, index) => fs27.writeFileSync(path41.join(dir, `${stampHash2(argv.join("\x00"))}.${agentId ?? ""}.${call}-${index}`), ""));
|
|
23773
24382
|
} catch {}
|
|
23774
24383
|
};
|
|
23775
24384
|
var dropAgentStamps = (env, session, toolUseId, command) => {
|
|
@@ -23779,7 +24388,7 @@ var dropAgentStamps = (env, session, toolUseId, command) => {
|
|
|
23779
24388
|
|
|
23780
24389
|
// packages/workit-core/src/hooks/hook-entry.ts
|
|
23781
24390
|
import { existsSync as existsSync14, readFileSync as readFileSync11, realpathSync as realpathSync10 } from "node:fs";
|
|
23782
|
-
import
|
|
24391
|
+
import path42 from "node:path";
|
|
23783
24392
|
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;
|
|
23784
24393
|
var PACKAGE_ENTRIES = {
|
|
23785
24394
|
"claude-code": /^(?:bin\/workit-hook\.mjs|src\/(?:run|hook)\.ts|dist\/workit-hook\.js)$/u,
|
|
@@ -23804,744 +24413,416 @@ var RUNNERS = new Set([
|
|
|
23804
24413
|
"."
|
|
23805
24414
|
]);
|
|
23806
24415
|
var PACKAGE_RUNNERS2 = new Set(["npx", "bunx", "pnpx"]);
|
|
23807
|
-
var NO_RUN = new Set([
|
|
23808
|
-
"build",
|
|
23809
|
-
"test",
|
|
23810
|
-
"fmt",
|
|
23811
|
-
"lint",
|
|
23812
|
-
"check",
|
|
23813
|
-
"doc",
|
|
23814
|
-
"info",
|
|
23815
|
-
"install",
|
|
23816
|
-
"add",
|
|
23817
|
-
"pm"
|
|
23818
|
-
]);
|
|
23819
|
-
var MORE_WRAPPERS = new Set(["strace", "ltrace", "watch", "unshare", "firejail", "xargs", "&"]);
|
|
23820
|
-
var baseName3 = (word) => (word.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "").toLowerCase();
|
|
23821
|
-
var packageAt = (dir) => {
|
|
23822
|
-
try {
|
|
23823
|
-
const name = JSON.parse(readFileSync11(
|
|
23824
|
-
const short = /^@workit-dev\/(claude-code|codex|cursor|core)$/u.exec(String(name))?.[1];
|
|
23825
|
-
if (short)
|
|
23826
|
-
return short;
|
|
23827
|
-
} catch {}
|
|
23828
|
-
for (const [manifest, short] of [
|
|
23829
|
-
[".claude-plugin", "claude-code"],
|
|
23830
|
-
[".codex-plugin", "codex"],
|
|
23831
|
-
[".cursor-plugin", "cursor"]
|
|
23832
|
-
]) {
|
|
23833
|
-
try {
|
|
23834
|
-
const name = JSON.parse(readFileSync11(
|
|
23835
|
-
if (name === "workit")
|
|
23836
|
-
return short;
|
|
23837
|
-
} catch {}
|
|
23838
|
-
}
|
|
23839
|
-
return null;
|
|
23840
|
-
};
|
|
23841
|
-
var entryByPath = (file) => {
|
|
23842
|
-
let dir = path41.dirname(file);
|
|
23843
|
-
for (let depth = 0;depth < 4; depth += 1, dir = path41.dirname(dir)) {
|
|
23844
|
-
const short = packageAt(dir);
|
|
23845
|
-
if (short)
|
|
23846
|
-
return PACKAGE_ENTRIES[short]?.test(path41.relative(dir, file).split(path41.sep).join("/")) ?? false;
|
|
23847
|
-
if (existsSync14(path41.join(dir, "package.json")))
|
|
23848
|
-
return false;
|
|
23849
|
-
}
|
|
23850
|
-
return false;
|
|
23851
|
-
};
|
|
23852
|
-
var literalSub = (match, inner) => {
|
|
23853
|
-
try {
|
|
23854
|
-
const [only, ...rest] = segmentsOf(inner);
|
|
23855
|
-
const [verb = "", ...args] = only?.words ?? [];
|
|
23856
|
-
const last = args.findLast((arg) => !arg.startsWith("-"));
|
|
23857
|
-
return rest.length === 0 && /^(?:echo|printf|ls|realpath|readlink)$/u.test(baseName3(verb)) && last ? last : match;
|
|
23858
|
-
} catch {
|
|
23859
|
-
return match;
|
|
23860
|
-
}
|
|
23861
|
-
};
|
|
23862
|
-
var expand = (word, vars) => word.replace(/\$\(([^()]*)\)|`([^`]*)`/gu, (match, sub, tick) => literalSub(match, sub ?? tick ?? "")).replace(/\$\{(\w+)\}|\$(\w+)/gu, (match, braced, bare) => {
|
|
23863
|
-
const name = braced ?? bare ?? "";
|
|
23864
|
-
return vars.get(name) ?? process.env[name] ?? match;
|
|
23865
|
-
}).replace(/^~(?=[\\/]|$)/u, userHome2(process.env));
|
|
23866
|
-
var entryNamed = (word, scan) => {
|
|
23867
|
-
if (!word)
|
|
23868
|
-
return null;
|
|
23869
|
-
const text = expand(word, scan.vars);
|
|
23870
|
-
if (ENTRY_NAMES.test(baseName3(text)))
|
|
23871
|
-
return text;
|
|
23872
|
-
const fd = /^\/(?:dev|proc\/self)\/fd\/(\d+)$/u.exec(text)?.[1];
|
|
23873
|
-
if (fd !== undefined && scan.fds.has(fd))
|
|
23874
|
-
return text;
|
|
23875
|
-
if (scan.dir === null && !path41.isAbsolute(text))
|
|
23876
|
-
return null;
|
|
23877
|
-
for (const file of expandGlob(path41.resolve(scan.dir ?? "/", text))) {
|
|
23878
|
-
if (scan.links.has(file) || entryByPath(file))
|
|
23879
|
-
return text;
|
|
23880
|
-
let real;
|
|
23881
|
-
try {
|
|
23882
|
-
real = realpathSync10(file);
|
|
23883
|
-
} catch {
|
|
23884
|
-
continue;
|
|
23885
|
-
}
|
|
23886
|
-
if (ENTRY_NAMES.test(baseName3(real)) || entryByPath(real))
|
|
23887
|
-
return text;
|
|
23888
|
-
}
|
|
23889
|
-
return null;
|
|
23890
|
-
};
|
|
23891
|
-
var noteLink = (words, scan) => {
|
|
23892
|
-
if (!/^(?:ln|cp|install)$/u.test(baseName3(words[0] ?? "")) || scan.dir === null)
|
|
23893
|
-
return;
|
|
23894
|
-
const names = words.slice(1).filter((word) => !word.startsWith("-"));
|
|
23895
|
-
const dest = names.at(-1);
|
|
23896
|
-
if (dest === undefined || names.length < 2)
|
|
23897
|
-
return;
|
|
23898
|
-
for (const source of names.slice(0, -1).filter((name) => entryNamed(name, scan))) {
|
|
23899
|
-
const to = path41.resolve(scan.dir, expand(dest, scan.vars));
|
|
23900
|
-
scan.links.add(to);
|
|
23901
|
-
scan.links.add(path41.join(to, path41.basename(source)));
|
|
23902
|
-
}
|
|
23903
|
-
};
|
|
23904
|
-
var runsEntry = (words, inputs, scan) => {
|
|
23905
|
-
const named = (word) => entryNamed(word, scan);
|
|
23906
|
-
let at = 0;
|
|
23907
|
-
while (at < words.length) {
|
|
23908
|
-
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
23909
|
-
at += 1;
|
|
23910
|
-
const word = words[at];
|
|
23911
|
-
if (word === undefined)
|
|
23912
|
-
return null;
|
|
23913
|
-
const entry = named(word);
|
|
23914
|
-
if (entry)
|
|
23915
|
-
return entry;
|
|
23916
|
-
const name = baseName3(word);
|
|
23917
|
-
const split = name === "env" ? words.findIndex((w) => /^(?:-\w*S|--split-string)/u.test(w)) : -1;
|
|
23918
|
-
if (split > at) {
|
|
23919
|
-
const line = /^(?:-\w*S|--split-string=?)(.*)$/su.exec(words[split] ?? "")?.[1] || words[split + 1];
|
|
23920
|
-
const rest = words.slice(split + (line === words[split + 1] ? 2 : 1));
|
|
23921
|
-
return runsEntry([...(line ?? "").split(/\s+/u).filter(Boolean), ...rest], inputs, scan);
|
|
23922
|
-
}
|
|
23923
|
-
if (MORE_WRAPPERS.has(name)) {
|
|
23924
|
-
at = pastOptions(words, at + 1, "");
|
|
23925
|
-
continue;
|
|
23926
|
-
}
|
|
23927
|
-
const takes = WRAPPERS3[name];
|
|
23928
|
-
if (takes !== undefined && !PACKAGE_RUNNERS2.has(name)) {
|
|
23929
|
-
at = pastOptions(words, at + 1, takes, name === "env" || name === "sudo");
|
|
23930
|
-
continue;
|
|
23931
|
-
}
|
|
23932
|
-
if (name === "busybox" || name === "toybox") {
|
|
23933
|
-
at += 1;
|
|
23934
|
-
continue;
|
|
23935
|
-
}
|
|
23936
|
-
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] ?? "");
|
|
23937
|
-
if (runner) {
|
|
23938
|
-
at += PACKAGE_RUNNERS2.has(name) ? 1 : 2;
|
|
23939
|
-
while (words[at]?.startsWith("-"))
|
|
23940
|
-
at += /^(?:-p|--package|-c|--call)$/u.test(words[at] ?? "") ? 2 : 1;
|
|
23941
|
-
if (/^@workit-dev\/(?:claude-code|codex|cursor)(?:@|$)/u.test(words[at] ?? ""))
|
|
23942
|
-
return words[at] ?? null;
|
|
23943
|
-
continue;
|
|
23944
|
-
}
|
|
23945
|
-
if (!RUNNERS.has(name))
|
|
23946
|
-
return null;
|
|
23947
|
-
if ((name === "bun" || name === "deno") && NO_RUN.has(words[at + 1] ?? ""))
|
|
23948
|
-
return null;
|
|
23949
|
-
for (const arg of [...words.slice(at + 1), ...inputs]) {
|
|
23950
|
-
const hit = named(arg);
|
|
23951
|
-
if (hit)
|
|
23952
|
-
return hit;
|
|
23953
|
-
}
|
|
23954
|
-
return null;
|
|
23955
|
-
}
|
|
23956
|
-
return null;
|
|
23957
|
-
};
|
|
23958
|
-
var KEYWORDS3 = new Set([
|
|
23959
|
-
"{",
|
|
23960
|
-
"}",
|
|
23961
|
-
"if",
|
|
23962
|
-
"then",
|
|
23963
|
-
"elif",
|
|
23964
|
-
"else",
|
|
23965
|
-
"fi",
|
|
23966
|
-
"while",
|
|
23967
|
-
"until",
|
|
23968
|
-
"do",
|
|
23969
|
-
"done",
|
|
23970
|
-
"esac",
|
|
23971
|
-
"!"
|
|
23972
|
-
]);
|
|
23973
|
-
var pastKeywords = (words) => {
|
|
23974
|
-
let at = 0;
|
|
23975
|
-
for (;; ) {
|
|
23976
|
-
if (words[at] === "function")
|
|
23977
|
-
at += 2;
|
|
23978
|
-
else if (KEYWORDS3.has(words[at] ?? ""))
|
|
23979
|
-
at += 1;
|
|
23980
|
-
else
|
|
23981
|
-
break;
|
|
23982
|
-
}
|
|
23983
|
-
return /^(?:for|case|select)$/u.test(words[at] ?? "") ? [] : words.slice(at);
|
|
23984
|
-
};
|
|
23985
|
-
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(" "));
|
|
23986
|
-
var TOKENS2 = /[\s'"`(),[\]{};|&<>=!]+/u;
|
|
23987
|
-
var ENTRY_SAMPLES = [
|
|
23988
|
-
"workit-hook.mjs",
|
|
23989
|
-
"workit-hook.js",
|
|
23990
|
-
"workit-hook.ts",
|
|
23991
|
-
"cursor-session-start.js"
|
|
23992
|
-
];
|
|
23993
|
-
var tokenEntry = (token, scan) => {
|
|
23994
|
-
if (!/[\\/]/u.test(token) && !existsSync14(path41.resolve(scan.dir ?? "/", token)))
|
|
23995
|
-
return null;
|
|
23996
|
-
return entryNamed(token, scan);
|
|
23997
|
-
};
|
|
23998
|
-
var opaqueEntry = (words, inputs, scan) => {
|
|
23999
|
-
let at = 0;
|
|
24000
|
-
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
24001
|
-
at += 1;
|
|
24002
|
-
const head = baseName3(words[at] ?? "");
|
|
24003
|
-
if (READERS2.has(head))
|
|
24004
|
-
return null;
|
|
24005
|
-
if ((head === "bun" || head === "deno") && NO_RUN.has(words[at + 1] ?? ""))
|
|
24006
|
-
return null;
|
|
24007
|
-
if (head === "git" && !words.some((word) => word.includes("alias.")))
|
|
24008
|
-
return null;
|
|
24009
|
-
if (head === "workit" || head === "workit-cli")
|
|
24010
|
-
return null;
|
|
24011
|
-
const tokens = words.flatMap((word) => word.split(TOKENS2)).filter(Boolean);
|
|
24012
|
-
const runner = (token) => RUNNERS.has(baseName3(token)) && !/^(?:\.|source)$/u.test(token) || PACKAGE_RUNNERS2.has(baseName3(token));
|
|
24013
|
-
if (!tokens.some(runner))
|
|
24014
|
-
return null;
|
|
24015
|
-
if (scan.fed)
|
|
24016
|
-
return scan.fed;
|
|
24017
|
-
for (const token of tokens) {
|
|
24018
|
-
const hit = tokenEntry(token, scan);
|
|
24019
|
-
if (hit)
|
|
24020
|
-
return hit;
|
|
24021
|
-
}
|
|
24022
|
-
if (head === "find")
|
|
24023
|
-
for (const [index, word] of words.entries()) {
|
|
24024
|
-
const named = /^-i?name$/u.test(words[index - 1] ?? "") && /^[^*?[]/u.test(word);
|
|
24025
|
-
const pattern = named ? globPattern(word) : null;
|
|
24026
|
-
if (pattern && ENTRY_SAMPLES.some((sample) => pattern.test(sample)))
|
|
24027
|
-
return word;
|
|
24028
|
-
}
|
|
24029
|
-
if (/^(?:xargs|parallel)$/u.test(head) || tokens.includes("xargs"))
|
|
24030
|
-
for (const input of inputs) {
|
|
24031
|
-
try {
|
|
24032
|
-
const file = path41.resolve(scan.dir ?? "/", expand(input, scan.vars));
|
|
24033
|
-
const text = readFileSync11(file, "utf8").slice(0, 65536);
|
|
24034
|
-
for (const token of text.split(/\s+/u).filter(Boolean)) {
|
|
24035
|
-
const hit = tokenEntry(token, scan);
|
|
24036
|
-
if (hit)
|
|
24037
|
-
return hit;
|
|
24038
|
-
}
|
|
24039
|
-
} catch {}
|
|
24040
|
-
}
|
|
24041
|
-
return null;
|
|
24042
|
-
};
|
|
24043
|
-
var expandedCommand = (words, scan) => {
|
|
24044
|
-
let at = 0;
|
|
24045
|
-
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
24046
|
-
at += 1;
|
|
24047
|
-
if (!/[$`]/u.test(words[at] ?? ""))
|
|
24048
|
-
return null;
|
|
24049
|
-
for (const word of words.slice(at + 1)) {
|
|
24050
|
-
const hit = entryNamed(word, scan);
|
|
24051
|
-
if (hit)
|
|
24052
|
-
return hit;
|
|
24416
|
+
var NO_RUN = new Set([
|
|
24417
|
+
"build",
|
|
24418
|
+
"test",
|
|
24419
|
+
"fmt",
|
|
24420
|
+
"lint",
|
|
24421
|
+
"check",
|
|
24422
|
+
"doc",
|
|
24423
|
+
"info",
|
|
24424
|
+
"install",
|
|
24425
|
+
"add",
|
|
24426
|
+
"pm"
|
|
24427
|
+
]);
|
|
24428
|
+
var MORE_WRAPPERS = new Set(["strace", "ltrace", "watch", "unshare", "firejail", "xargs", "&"]);
|
|
24429
|
+
var baseName3 = (word) => (word.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "").toLowerCase();
|
|
24430
|
+
var packageAt = (dir) => {
|
|
24431
|
+
try {
|
|
24432
|
+
const name = JSON.parse(readFileSync11(path42.join(dir, "package.json"), "utf8")).name;
|
|
24433
|
+
const short = /^@workit-dev\/(claude-code|codex|cursor|core)$/u.exec(String(name))?.[1];
|
|
24434
|
+
if (short)
|
|
24435
|
+
return short;
|
|
24436
|
+
} catch {}
|
|
24437
|
+
for (const [manifest, short] of [
|
|
24438
|
+
[".claude-plugin", "claude-code"],
|
|
24439
|
+
[".codex-plugin", "codex"],
|
|
24440
|
+
[".cursor-plugin", "cursor"]
|
|
24441
|
+
]) {
|
|
24442
|
+
try {
|
|
24443
|
+
const name = JSON.parse(readFileSync11(path42.join(dir, manifest, "plugin.json"), "utf8")).name;
|
|
24444
|
+
if (name === "workit")
|
|
24445
|
+
return short;
|
|
24446
|
+
} catch {}
|
|
24053
24447
|
}
|
|
24054
24448
|
return null;
|
|
24055
24449
|
};
|
|
24056
|
-
var
|
|
24057
|
-
|
|
24058
|
-
|
|
24059
|
-
|
|
24060
|
-
|
|
24061
|
-
|
|
24062
|
-
|
|
24063
|
-
|
|
24064
|
-
return hit;
|
|
24065
|
-
}
|
|
24450
|
+
var entryByPath = (file) => {
|
|
24451
|
+
let dir = path42.dirname(file);
|
|
24452
|
+
for (let depth = 0;depth < 4; depth += 1, dir = path42.dirname(dir)) {
|
|
24453
|
+
const short = packageAt(dir);
|
|
24454
|
+
if (short)
|
|
24455
|
+
return PACKAGE_ENTRIES[short]?.test(path42.relative(dir, file).split(path42.sep).join("/")) ?? false;
|
|
24456
|
+
if (existsSync14(path42.join(dir, "package.json")))
|
|
24457
|
+
return false;
|
|
24066
24458
|
}
|
|
24067
|
-
return
|
|
24459
|
+
return false;
|
|
24068
24460
|
};
|
|
24069
|
-
var
|
|
24070
|
-
let segments;
|
|
24461
|
+
var literalSub = (match, inner) => {
|
|
24071
24462
|
try {
|
|
24072
|
-
|
|
24463
|
+
const [only, ...rest] = segmentsOf(inner);
|
|
24464
|
+
const [verb = "", ...args] = only?.words ?? [];
|
|
24465
|
+
const last = args.findLast((arg) => !arg.startsWith("-"));
|
|
24466
|
+
return rest.length === 0 && /^(?:echo|printf|ls|realpath|readlink)$/u.test(baseName3(verb)) && last ? last : match;
|
|
24073
24467
|
} catch {
|
|
24074
|
-
return
|
|
24075
|
-
}
|
|
24076
|
-
for (const [index, segment] of segments.entries()) {
|
|
24077
|
-
if (segment.unanalyzable)
|
|
24078
|
-
continue;
|
|
24079
|
-
bindLoop(segment.words, segments.slice(index + 1), scan);
|
|
24080
|
-
const words = pastKeywords(segment.words);
|
|
24081
|
-
const fed = scan.fed;
|
|
24082
|
-
scan.fed = null;
|
|
24083
|
-
const hit = segmentEntry(segment, words, dialect, scan, fed);
|
|
24084
|
-
if (hit)
|
|
24085
|
-
return hit;
|
|
24086
|
-
}
|
|
24087
|
-
return null;
|
|
24088
|
-
};
|
|
24089
|
-
var bindLoop = (raw, after, scan) => {
|
|
24090
|
-
const at = raw.findIndex((word) => !KEYWORDS3.has(word));
|
|
24091
|
-
const verb = raw[at];
|
|
24092
|
-
if ((verb === "for" || verb === "select") && raw[at + 2] === "in") {
|
|
24093
|
-
const name = raw[at + 1] ?? "";
|
|
24094
|
-
const items = raw.slice(at + 3);
|
|
24095
|
-
const item = items.find((word) => entryNamed(word, scan)) ?? items[0];
|
|
24096
|
-
if (/^[A-Za-z_]\w*$/u.test(name) && item !== undefined)
|
|
24097
|
-
scan.vars.set(name, expand(item, scan.vars));
|
|
24098
|
-
return;
|
|
24099
|
-
}
|
|
24100
|
-
const read = raw.indexOf("read");
|
|
24101
|
-
if (read < 0 || !raw.slice(0, read).some((word) => word === "while" || word === "until"))
|
|
24102
|
-
return;
|
|
24103
|
-
const fed = after.find((segment) => segment.words[0] === "done")?.stdin?.[0];
|
|
24104
|
-
const line = fed?.split(`
|
|
24105
|
-
`)[0]?.trim();
|
|
24106
|
-
const name = raw.slice(read + 1).find((word) => /^[A-Za-z_]\w*$/u.test(word));
|
|
24107
|
-
if (name && line)
|
|
24108
|
-
scan.vars.set(name, line);
|
|
24109
|
-
};
|
|
24110
|
-
var segmentEntry = (segment, words, dialect, scan, fed) => {
|
|
24111
|
-
const verb = baseName3(words[0] ?? "");
|
|
24112
|
-
if (["cd", "pushd", "chdir", "set-location", "sl"].includes(verb)) {
|
|
24113
|
-
const target = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
|
|
24114
|
-
const moved = target === undefined ? userHome2(process.env) : expand(target, scan.vars);
|
|
24115
|
-
scan.dir = moved === "-" || /[$`]/u.test(moved) ? null : path41.isAbsolute(moved) ? moved : scan.dir && path41.resolve(scan.dir, moved);
|
|
24116
|
-
if (scan.dir === null)
|
|
24117
|
-
scan.vars.delete("PWD");
|
|
24118
|
-
else
|
|
24119
|
-
scan.vars.set("PWD", scan.dir);
|
|
24120
|
-
return null;
|
|
24121
|
-
}
|
|
24122
|
-
if (verb === "popd") {
|
|
24123
|
-
scan.dir = null;
|
|
24124
|
-
return null;
|
|
24125
|
-
}
|
|
24126
|
-
const declares = ["export", "declare", "typeset", "local", "readonly"].includes(verb);
|
|
24127
|
-
const assigns = declares ? words.slice(1) : words.every((word) => /^[A-Za-z_]\w*=/u.test(word)) ? words : [];
|
|
24128
|
-
for (const word of assigns) {
|
|
24129
|
-
const [name = "", value] = word.split(/=(.*)/su);
|
|
24130
|
-
if (value !== undefined && /^[A-Za-z_]\w*$/u.test(name))
|
|
24131
|
-
scan.vars.set(name, expand(value.replace(/^(['"])(.*)\1$/su, "$2"), scan.vars));
|
|
24132
|
-
}
|
|
24133
|
-
const options = optionsEntry(declares ? words.slice(1) : words, scan);
|
|
24134
|
-
if (options)
|
|
24135
|
-
return options;
|
|
24136
|
-
if (verb === "exec" && words.slice(1).every((word) => /^\d+$/u.test(word))) {
|
|
24137
|
-
for (const input of segment.inputs ?? [])
|
|
24138
|
-
if (entryNamed(input, scan))
|
|
24139
|
-
for (const fd of words.slice(1))
|
|
24140
|
-
scan.fds.add(fd);
|
|
24141
|
-
}
|
|
24142
|
-
const inputs = segment.inputs ?? [];
|
|
24143
|
-
const entry = runsEntry(words, inputs, scan) ?? expandedCommand(words, scan) ?? opaqueEntry(words, inputs, { ...scan, fed });
|
|
24144
|
-
if (entry)
|
|
24145
|
-
return entry;
|
|
24146
|
-
if (segment.pipe)
|
|
24147
|
-
scan.fed = words.slice(1).flatMap((word) => word.split(TOKENS2)).map((token) => token ? tokenEntry(token, scan) : null).find(Boolean) ?? null;
|
|
24148
|
-
noteLink(words, scan);
|
|
24149
|
-
if (scan.depth >= 4)
|
|
24150
|
-
return null;
|
|
24151
|
-
const nested = (script) => scanCommand(script, dialect, {
|
|
24152
|
-
...scan,
|
|
24153
|
-
vars: new Map(scan.vars),
|
|
24154
|
-
fed: null,
|
|
24155
|
-
depth: scan.depth + 1
|
|
24156
|
-
});
|
|
24157
|
-
const scripts = [...segment.subs ?? []];
|
|
24158
|
-
const script = shellScript2(words) ?? cmdScript2(words) ?? workitScript(words);
|
|
24159
|
-
if (script)
|
|
24160
|
-
scripts.push(script);
|
|
24161
|
-
if (!script && /^(?:ba|z|da|k)?sh$/u.test(verb) && words.slice(1).every((word) => word.startsWith("-")) || verb === "at" || verb === "batch")
|
|
24162
|
-
scripts.push(...segment.stdin ?? []);
|
|
24163
|
-
for (const text of scripts) {
|
|
24164
|
-
const hit = nested(text);
|
|
24165
|
-
if (hit)
|
|
24166
|
-
return hit;
|
|
24468
|
+
return match;
|
|
24167
24469
|
}
|
|
24168
|
-
return null;
|
|
24169
24470
|
};
|
|
24170
|
-
var
|
|
24171
|
-
const name =
|
|
24172
|
-
|
|
24471
|
+
var expand = (word, vars) => word.replace(/\$\(([^()]*)\)|`([^`]*)`/gu, (match, sub, tick) => literalSub(match, sub ?? tick ?? "")).replace(/\$\{(\w+)\}|\$(\w+)/gu, (match, braced, bare) => {
|
|
24472
|
+
const name = braced ?? bare ?? "";
|
|
24473
|
+
return vars.get(name) ?? process.env[name] ?? match;
|
|
24474
|
+
}).replace(/^~(?=[\\/]|$)/u, userHome2(process.env));
|
|
24475
|
+
var entryNamed = (word, scan) => {
|
|
24476
|
+
if (!word)
|
|
24173
24477
|
return null;
|
|
24174
|
-
const
|
|
24175
|
-
|
|
24176
|
-
|
|
24177
|
-
|
|
24178
|
-
if (
|
|
24478
|
+
const text = expand(word, scan.vars);
|
|
24479
|
+
if (ENTRY_NAMES.test(baseName3(text)))
|
|
24480
|
+
return text;
|
|
24481
|
+
const fd = /^\/(?:dev|proc\/self)\/fd\/(\d+)$/u.exec(text)?.[1];
|
|
24482
|
+
if (fd !== undefined && scan.fds.has(fd))
|
|
24483
|
+
return text;
|
|
24484
|
+
if (scan.dir === null && !path42.isAbsolute(text))
|
|
24179
24485
|
return null;
|
|
24180
|
-
const
|
|
24181
|
-
|
|
24182
|
-
|
|
24183
|
-
|
|
24184
|
-
const found = [];
|
|
24185
|
-
for (let at = command.indexOf("$(");at >= 0 && found.length < 32; at = command.indexOf("$(", at + 1)) {
|
|
24186
|
-
if (command[at + 2] === "(")
|
|
24187
|
-
continue;
|
|
24188
|
-
let depth = 1;
|
|
24189
|
-
let end = at + 2;
|
|
24190
|
-
for (;end < command.length && depth > 0; end += 1)
|
|
24191
|
-
if (command[end] === "(")
|
|
24192
|
-
depth += 1;
|
|
24193
|
-
else if (command[end] === ")")
|
|
24194
|
-
depth -= 1;
|
|
24195
|
-
found.push(command.slice(at + 2, end - 1));
|
|
24196
|
-
}
|
|
24197
|
-
return found;
|
|
24198
|
-
};
|
|
24199
|
-
var hookEntryRun = (cwd, command, dialect = "posix") => {
|
|
24200
|
-
const scan = (text) => scanCommand(text, dialect, {
|
|
24201
|
-
dir: cwd,
|
|
24202
|
-
vars: new Map([["PWD", cwd]]),
|
|
24203
|
-
links: new Set,
|
|
24204
|
-
fds: new Set,
|
|
24205
|
-
fed: null,
|
|
24206
|
-
depth: 0
|
|
24207
|
-
});
|
|
24208
|
-
const texts = dialect === "posix" && /[A-Za-z]:\\/u.test(command) ? [command, command.replaceAll("\\", "/")] : [command];
|
|
24209
|
-
for (const text of texts) {
|
|
24210
|
-
const hit = scan(text) ?? substitutions2(text).map(scan).find(Boolean);
|
|
24211
|
-
if (hit)
|
|
24212
|
-
return hit;
|
|
24213
|
-
}
|
|
24214
|
-
return null;
|
|
24215
|
-
};
|
|
24216
|
-
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).`;
|
|
24217
|
-
|
|
24218
|
-
// packages/workit-core/src/hooks/identity-env.ts
|
|
24219
|
-
import fs27 from "node:fs";
|
|
24220
|
-
import path42 from "node:path";
|
|
24221
|
-
var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
|
|
24222
|
-
var IDENTITY = new RegExp(`^${NAMES}$`, "u");
|
|
24223
|
-
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
24224
|
-
var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
|
|
24225
|
-
var IDENTITY_ANY = new RegExp(NAMES, "iu");
|
|
24226
|
-
var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
|
|
24227
|
-
var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
|
|
24228
|
-
var STATE_ANY = new RegExp(STATE_NAMES, "iu");
|
|
24229
|
-
var powershell = (names) => new RegExp([
|
|
24230
|
-
`\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
|
|
24231
|
-
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
|
|
24232
|
-
`SetEnvironmentVariable\\(\\s*['"]${names}\\b`
|
|
24233
|
-
].join("|"), "iu");
|
|
24234
|
-
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";
|
|
24235
|
-
var POWERSHELL = powershell(NAMES);
|
|
24236
|
-
var POWERSHELL_STATE = powershell(STATE_NAMES);
|
|
24237
|
-
var POWERSHELL_HOST = powershell(HOST_NAMES);
|
|
24238
|
-
var POWERSHELL_OPAQUE = new RegExp([
|
|
24239
|
-
`SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
|
|
24240
|
-
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
|
|
24241
|
-
`(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
|
|
24242
|
-
`\\b(?:iex|Invoke-Expression)\\b`
|
|
24243
|
-
].join("|"), "iu");
|
|
24244
|
-
var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
|
|
24245
|
-
var CMD_IDENTITY = cmdSet(NAMES);
|
|
24246
|
-
var CMD_STATE = cmdSet(STATE_NAMES);
|
|
24247
|
-
var CMD_HOST = cmdSet(HOST_NAMES);
|
|
24248
|
-
var RUNS_TEXT = /\bworkit(?:-cli)?\b|@workit-dev[\\/]cli/iu;
|
|
24249
|
-
var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
|
|
24250
|
-
var OPAQUE = new Set([
|
|
24251
|
-
"watch",
|
|
24252
|
-
"strace",
|
|
24253
|
-
"chroot",
|
|
24254
|
-
"flock",
|
|
24255
|
-
"ssh",
|
|
24256
|
-
"su",
|
|
24257
|
-
"runuser",
|
|
24258
|
-
"script",
|
|
24259
|
-
"parallel"
|
|
24260
|
-
]);
|
|
24261
|
-
var ENV_VALUED = new Set(["u", "C", "S", "a", "P"]);
|
|
24262
|
-
var ENV_FLAGS = new Set(["i", "0", "v"]);
|
|
24263
|
-
var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
|
|
24264
|
-
var ENV_LONG_FLAGS = /^--(?:ignore-environment|null|debug|(?:block|default|ignore)-signal(?:=.*)?)$/u;
|
|
24265
|
-
var base2 = (word) => (word?.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "");
|
|
24266
|
-
var ASSIGN = /^[A-Za-z_]\w*\+?=/u;
|
|
24267
|
-
var nameOf = (word) => (word?.split("=")[0] ?? "").replace(/\+$/u, "");
|
|
24268
|
-
var named = (word) => IDENTITY.test(nameOf(word));
|
|
24269
|
-
var stateNamed = (word) => STATE2.test(nameOf(word));
|
|
24270
|
-
var isWorkit = (word) => /^workit(?:-cli)?(?:\.[cm]?js)?$/u.test(base2(word)) || /@workit-dev[\\/]cli\b|workit-cli[\\/](?:dist|src)[\\/]/u.test(word ?? "");
|
|
24271
|
-
var linksToWorkit = (word, cwd) => {
|
|
24272
|
-
const places = /[\\/]/u.test(word) ? [path42.resolve(cwd ?? process.cwd(), word)] : (process.env.PATH ?? "").split(path42.delimiter).map((dir) => path42.join(dir, word));
|
|
24273
|
-
for (const place of places) {
|
|
24486
|
+
for (const file of expandGlob(path42.resolve(scan.dir ?? "/", text))) {
|
|
24487
|
+
if (scan.links.has(file) || entryByPath(file))
|
|
24488
|
+
return text;
|
|
24489
|
+
let real;
|
|
24274
24490
|
try {
|
|
24275
|
-
|
|
24276
|
-
|
|
24277
|
-
|
|
24491
|
+
real = realpathSync10(file);
|
|
24492
|
+
} catch {
|
|
24493
|
+
continue;
|
|
24494
|
+
}
|
|
24495
|
+
if (ENTRY_NAMES.test(baseName3(real)) || entryByPath(real))
|
|
24496
|
+
return text;
|
|
24278
24497
|
}
|
|
24279
|
-
return
|
|
24498
|
+
return null;
|
|
24280
24499
|
};
|
|
24281
|
-
var
|
|
24282
|
-
|
|
24283
|
-
var note = (scan, seg, word) => {
|
|
24284
|
-
if (scan.identity && named(word)) {
|
|
24285
|
-
if (seg)
|
|
24286
|
-
seg.identity ??= nameOf(word);
|
|
24287
|
-
else
|
|
24288
|
-
scan.hit ??= nameOf(word);
|
|
24289
|
-
}
|
|
24290
|
-
if (!stateNamed(word) && !(scan.identity && HOST_VARIABLE.test(nameOf(word))))
|
|
24500
|
+
var noteLink = (words, scan) => {
|
|
24501
|
+
if (!/^(?:ln|cp|install)$/u.test(baseName3(words[0] ?? "")) || scan.dir === null)
|
|
24291
24502
|
return;
|
|
24292
|
-
|
|
24293
|
-
|
|
24294
|
-
|
|
24295
|
-
|
|
24503
|
+
const names = words.slice(1).filter((word) => !word.startsWith("-"));
|
|
24504
|
+
const dest = names.at(-1);
|
|
24505
|
+
if (dest === undefined || names.length < 2)
|
|
24506
|
+
return;
|
|
24507
|
+
for (const source of names.slice(0, -1).filter((name) => entryNamed(name, scan))) {
|
|
24508
|
+
const to = path42.resolve(scan.dir, expand(dest, scan.vars));
|
|
24509
|
+
scan.links.add(to);
|
|
24510
|
+
scan.links.add(path42.join(to, path42.basename(source)));
|
|
24511
|
+
}
|
|
24296
24512
|
};
|
|
24297
|
-
var
|
|
24298
|
-
|
|
24299
|
-
|
|
24300
|
-
|
|
24301
|
-
|
|
24302
|
-
|
|
24303
|
-
|
|
24304
|
-
if (
|
|
24305
|
-
|
|
24306
|
-
const
|
|
24307
|
-
|
|
24308
|
-
|
|
24309
|
-
|
|
24310
|
-
|
|
24311
|
-
|
|
24312
|
-
|
|
24313
|
-
|
|
24314
|
-
|
|
24315
|
-
return risky(UNREADABLE);
|
|
24316
|
-
}
|
|
24317
|
-
scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, seg, depth + 1);
|
|
24318
|
-
};
|
|
24319
|
-
let options = true;
|
|
24320
|
-
for (let index = at;index < words.length; index += 1) {
|
|
24321
|
-
const word = words[index] ?? "";
|
|
24322
|
-
if (expands.has(index)) {
|
|
24323
|
-
risky(UNREADABLE);
|
|
24324
|
-
const built = options ? /^(?:--split-string=|-[\w]*S)(.+)$/su.exec(word) : null;
|
|
24325
|
-
if (built)
|
|
24326
|
-
return split(built[1], index + 1, true);
|
|
24327
|
-
continue;
|
|
24513
|
+
var runsEntry = (words, inputs, scan) => {
|
|
24514
|
+
const named = (word) => entryNamed(word, scan);
|
|
24515
|
+
let at = 0;
|
|
24516
|
+
while (at < words.length) {
|
|
24517
|
+
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
24518
|
+
at += 1;
|
|
24519
|
+
const word = words[at];
|
|
24520
|
+
if (word === undefined)
|
|
24521
|
+
return null;
|
|
24522
|
+
const entry = named(word);
|
|
24523
|
+
if (entry)
|
|
24524
|
+
return entry;
|
|
24525
|
+
const name = baseName3(word);
|
|
24526
|
+
const split = name === "env" ? words.findIndex((w) => /^(?:-\w*S|--split-string)/u.test(w)) : -1;
|
|
24527
|
+
if (split > at) {
|
|
24528
|
+
const line = /^(?:-\w*S|--split-string=?)(.*)$/su.exec(words[split] ?? "")?.[1] || words[split + 1];
|
|
24529
|
+
const rest = words.slice(split + (line === words[split + 1] ? 2 : 1));
|
|
24530
|
+
return runsEntry([...(line ?? "").split(/\s+/u).filter(Boolean), ...rest], inputs, scan);
|
|
24328
24531
|
}
|
|
24329
|
-
if (
|
|
24330
|
-
|
|
24532
|
+
if (MORE_WRAPPERS.has(name)) {
|
|
24533
|
+
at = pastOptions(words, at + 1, "");
|
|
24331
24534
|
continue;
|
|
24332
24535
|
}
|
|
24333
|
-
|
|
24334
|
-
|
|
24536
|
+
const takes = WRAPPERS3[name];
|
|
24537
|
+
if (takes !== undefined && !PACKAGE_RUNNERS2.has(name)) {
|
|
24538
|
+
at = pastOptions(words, at + 1, takes, name === "env" || name === "sudo");
|
|
24335
24539
|
continue;
|
|
24336
24540
|
}
|
|
24337
|
-
if (
|
|
24338
|
-
|
|
24339
|
-
if (name === "--ignore-environment")
|
|
24340
|
-
risky("env -i");
|
|
24341
|
-
else if (name === "--unset")
|
|
24342
|
-
unset(value ?? words[index += 1]);
|
|
24343
|
-
else if (name === "--split-string")
|
|
24344
|
-
return split(value ?? words[index + 1], index + (value === undefined ? 2 : 1), expands.has(index + (value === undefined ? 1 : 0)));
|
|
24345
|
-
else if (ENV_LONG_VALUED.has(name))
|
|
24346
|
-
index += value === undefined ? 1 : 0;
|
|
24347
|
-
else if (!ENV_LONG_FLAGS.test(word))
|
|
24348
|
-
risky(UNREADABLE);
|
|
24541
|
+
if (name === "busybox" || name === "toybox") {
|
|
24542
|
+
at += 1;
|
|
24349
24543
|
continue;
|
|
24350
24544
|
}
|
|
24351
|
-
|
|
24352
|
-
|
|
24353
|
-
|
|
24354
|
-
|
|
24355
|
-
|
|
24356
|
-
|
|
24357
|
-
|
|
24358
|
-
else if (ENV_VALUED.has(letter)) {
|
|
24359
|
-
const glued = word.slice(at2 + 1);
|
|
24360
|
-
if (!glued)
|
|
24361
|
-
index += 1;
|
|
24362
|
-
const value = glued || words[index];
|
|
24363
|
-
if (letter === "u")
|
|
24364
|
-
unset(value);
|
|
24365
|
-
if (letter === "S")
|
|
24366
|
-
return split(value, index + 1, expands.has(index));
|
|
24367
|
-
break;
|
|
24368
|
-
} else {
|
|
24369
|
-
risky(UNREADABLE);
|
|
24370
|
-
break;
|
|
24371
|
-
}
|
|
24372
|
-
}
|
|
24545
|
+
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] ?? "");
|
|
24546
|
+
if (runner) {
|
|
24547
|
+
at += PACKAGE_RUNNERS2.has(name) ? 1 : 2;
|
|
24548
|
+
while (words[at]?.startsWith("-"))
|
|
24549
|
+
at += /^(?:-p|--package|-c|--call)$/u.test(words[at] ?? "") ? 2 : 1;
|
|
24550
|
+
if (/^@workit-dev\/(?:claude-code|codex|cursor)(?:@|$)/u.test(words[at] ?? ""))
|
|
24551
|
+
return words[at] ?? null;
|
|
24373
24552
|
continue;
|
|
24374
24553
|
}
|
|
24375
|
-
if (
|
|
24376
|
-
|
|
24377
|
-
|
|
24554
|
+
if (!RUNNERS.has(name))
|
|
24555
|
+
return null;
|
|
24556
|
+
if ((name === "bun" || name === "deno") && NO_RUN.has(words[at + 1] ?? ""))
|
|
24557
|
+
return null;
|
|
24558
|
+
for (const arg of [...words.slice(at + 1), ...inputs]) {
|
|
24559
|
+
const hit = named(arg);
|
|
24560
|
+
if (hit)
|
|
24561
|
+
return hit;
|
|
24378
24562
|
}
|
|
24379
|
-
return
|
|
24563
|
+
return null;
|
|
24380
24564
|
}
|
|
24565
|
+
return null;
|
|
24381
24566
|
};
|
|
24382
|
-
var
|
|
24383
|
-
|
|
24384
|
-
|
|
24385
|
-
|
|
24386
|
-
|
|
24387
|
-
|
|
24388
|
-
|
|
24389
|
-
|
|
24390
|
-
|
|
24391
|
-
|
|
24392
|
-
|
|
24393
|
-
|
|
24394
|
-
|
|
24395
|
-
|
|
24396
|
-
|
|
24397
|
-
|
|
24398
|
-
|
|
24399
|
-
|
|
24567
|
+
var KEYWORDS3 = new Set([
|
|
24568
|
+
"{",
|
|
24569
|
+
"}",
|
|
24570
|
+
"if",
|
|
24571
|
+
"then",
|
|
24572
|
+
"elif",
|
|
24573
|
+
"else",
|
|
24574
|
+
"fi",
|
|
24575
|
+
"while",
|
|
24576
|
+
"until",
|
|
24577
|
+
"do",
|
|
24578
|
+
"done",
|
|
24579
|
+
"esac",
|
|
24580
|
+
"!"
|
|
24581
|
+
]);
|
|
24582
|
+
var pastKeywords = (words) => {
|
|
24583
|
+
let at = 0;
|
|
24584
|
+
for (;; ) {
|
|
24585
|
+
if (words[at] === "function")
|
|
24586
|
+
at += 2;
|
|
24587
|
+
else if (KEYWORDS3.has(words[at] ?? ""))
|
|
24588
|
+
at += 1;
|
|
24589
|
+
else
|
|
24400
24590
|
break;
|
|
24401
|
-
index = pastOptions(words, index + 1, takes);
|
|
24402
24591
|
}
|
|
24403
|
-
|
|
24404
|
-
|
|
24405
|
-
|
|
24406
|
-
|
|
24407
|
-
|
|
24408
|
-
|
|
24409
|
-
|
|
24410
|
-
|
|
24411
|
-
|
|
24412
|
-
|
|
24413
|
-
|
|
24414
|
-
if (
|
|
24415
|
-
|
|
24416
|
-
|
|
24417
|
-
|
|
24418
|
-
|
|
24419
|
-
|
|
24420
|
-
|
|
24592
|
+
return /^(?:for|case|select)$/u.test(words[at] ?? "") ? [] : words.slice(at);
|
|
24593
|
+
};
|
|
24594
|
+
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(" "));
|
|
24595
|
+
var TOKENS2 = /[\s'"`(),[\]{};|&<>=!]+/u;
|
|
24596
|
+
var ENTRY_SAMPLES = [
|
|
24597
|
+
"workit-hook.mjs",
|
|
24598
|
+
"workit-hook.js",
|
|
24599
|
+
"workit-hook.ts",
|
|
24600
|
+
"cursor-session-start.js"
|
|
24601
|
+
];
|
|
24602
|
+
var tokenEntry = (token, scan) => {
|
|
24603
|
+
if (!/[\\/]/u.test(token) && !existsSync14(path42.resolve(scan.dir ?? "/", token)))
|
|
24604
|
+
return null;
|
|
24605
|
+
return entryNamed(token, scan);
|
|
24606
|
+
};
|
|
24607
|
+
var opaqueEntry = (words, inputs, scan) => {
|
|
24608
|
+
let at = 0;
|
|
24609
|
+
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
24610
|
+
at += 1;
|
|
24611
|
+
const head = baseName3(words[at] ?? "");
|
|
24612
|
+
if (READERS2.has(head))
|
|
24613
|
+
return null;
|
|
24614
|
+
if ((head === "bun" || head === "deno") && NO_RUN.has(words[at + 1] ?? ""))
|
|
24615
|
+
return null;
|
|
24616
|
+
if (head === "git" && !words.some((word) => word.includes("alias.")))
|
|
24617
|
+
return null;
|
|
24618
|
+
if (head === "workit" || head === "workit-cli")
|
|
24619
|
+
return null;
|
|
24620
|
+
const tokens = words.flatMap((word) => word.split(TOKENS2)).filter(Boolean);
|
|
24621
|
+
const runner = (token) => RUNNERS.has(baseName3(token)) && !/^(?:\.|source)$/u.test(token) || PACKAGE_RUNNERS2.has(baseName3(token));
|
|
24622
|
+
if (!tokens.some(runner))
|
|
24623
|
+
return null;
|
|
24624
|
+
if (scan.fed)
|
|
24625
|
+
return scan.fed;
|
|
24626
|
+
for (const token of tokens) {
|
|
24627
|
+
const hit = tokenEntry(token, scan);
|
|
24628
|
+
if (hit)
|
|
24629
|
+
return hit;
|
|
24630
|
+
}
|
|
24631
|
+
if (head === "find")
|
|
24632
|
+
for (const [index, word] of words.entries()) {
|
|
24633
|
+
const named = /^-i?name$/u.test(words[index - 1] ?? "") && /^[^*?[]/u.test(word);
|
|
24634
|
+
const pattern = named ? globPattern(word) : null;
|
|
24635
|
+
if (pattern && ENTRY_SAMPLES.some((sample) => pattern.test(sample)))
|
|
24636
|
+
return word;
|
|
24637
|
+
}
|
|
24638
|
+
if (/^(?:xargs|parallel)$/u.test(head) || tokens.includes("xargs"))
|
|
24639
|
+
for (const input of inputs) {
|
|
24640
|
+
try {
|
|
24641
|
+
const file = path42.resolve(scan.dir ?? "/", expand(input, scan.vars));
|
|
24642
|
+
const text = readFileSync11(file, "utf8").slice(0, 65536);
|
|
24643
|
+
for (const token of text.split(/\s+/u).filter(Boolean)) {
|
|
24644
|
+
const hit = tokenEntry(token, scan);
|
|
24645
|
+
if (hit)
|
|
24646
|
+
return hit;
|
|
24647
|
+
}
|
|
24648
|
+
} catch {}
|
|
24421
24649
|
}
|
|
24422
|
-
|
|
24423
|
-
};
|
|
24424
|
-
var opaque = (rest, scan, seg, assigns) => {
|
|
24425
|
-
if (!rest.some(isWorkit))
|
|
24426
|
-
return;
|
|
24427
|
-
seg.runs = true;
|
|
24428
|
-
const changes = (word) => base2(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && ASSIGN.test(word);
|
|
24429
|
-
if (rest.some(changes))
|
|
24430
|
-
scan.risky ??= UNREADABLE;
|
|
24431
|
-
if (rest.some((word) => base2(word).toLowerCase() === "env"))
|
|
24432
|
-
for (const word of rest)
|
|
24433
|
-
note(scan, seg, word);
|
|
24434
|
-
};
|
|
24435
|
-
var LOGIN_VALUED = {
|
|
24436
|
-
su: /[sgGwc]/u,
|
|
24437
|
-
runuser: /[sgGwuc]/u,
|
|
24438
|
-
script: /[cEIOBTmot]/u
|
|
24650
|
+
return null;
|
|
24439
24651
|
};
|
|
24440
|
-
var
|
|
24441
|
-
|
|
24442
|
-
|
|
24652
|
+
var expandedCommand = (words, scan) => {
|
|
24653
|
+
let at = 0;
|
|
24654
|
+
while (/^[A-Za-z_]\w*=/u.test(words[at] ?? ""))
|
|
24655
|
+
at += 1;
|
|
24656
|
+
if (!/[$`]/u.test(words[at] ?? ""))
|
|
24443
24657
|
return null;
|
|
24444
|
-
const
|
|
24445
|
-
|
|
24446
|
-
|
|
24447
|
-
|
|
24448
|
-
|
|
24449
|
-
|
|
24450
|
-
|
|
24451
|
-
|
|
24658
|
+
for (const word of words.slice(at + 1)) {
|
|
24659
|
+
const hit = entryNamed(word, scan);
|
|
24660
|
+
if (hit)
|
|
24661
|
+
return hit;
|
|
24662
|
+
}
|
|
24663
|
+
return null;
|
|
24664
|
+
};
|
|
24665
|
+
var optionsEntry = (words, scan) => {
|
|
24666
|
+
for (const word of words) {
|
|
24667
|
+
const value = /^(?:NODE_OPTIONS|BUN_OPTIONS)=(.*)$/su.exec(word)?.[1];
|
|
24668
|
+
if (value === undefined)
|
|
24452
24669
|
continue;
|
|
24453
|
-
const
|
|
24454
|
-
|
|
24455
|
-
|
|
24670
|
+
for (const token of value.split(TOKENS2).filter(Boolean)) {
|
|
24671
|
+
const hit = tokenEntry(token, scan);
|
|
24672
|
+
if (hit)
|
|
24673
|
+
return hit;
|
|
24674
|
+
}
|
|
24456
24675
|
}
|
|
24457
24676
|
return null;
|
|
24458
24677
|
};
|
|
24459
|
-
var scanCommand2 = (command, dialect,
|
|
24678
|
+
var scanCommand2 = (command, dialect, scan) => {
|
|
24460
24679
|
let segments;
|
|
24461
24680
|
try {
|
|
24462
24681
|
segments = segmentsOf(command, dialect);
|
|
24463
24682
|
} catch {
|
|
24464
|
-
return;
|
|
24683
|
+
return null;
|
|
24465
24684
|
}
|
|
24466
|
-
for (const
|
|
24467
|
-
|
|
24468
|
-
const seg = newSeg();
|
|
24469
|
-
let at = 0;
|
|
24470
|
-
while (ASSIGN.test(words[at] ?? ""))
|
|
24471
|
-
at += 1;
|
|
24472
|
-
for (const word of words.slice(0, at))
|
|
24473
|
-
note(scan, at === words.length ? null : seg, word);
|
|
24474
|
-
let declare = at;
|
|
24475
|
-
if (["builtin", "command"].includes(words[declare] ?? ""))
|
|
24476
|
-
declare += 1;
|
|
24477
|
-
if (DECLARES.has(words[declare] ?? "")) {
|
|
24478
|
-
for (let index = declare + 1;index < words.length; index += 1) {
|
|
24479
|
-
note(scan, null, words[index]);
|
|
24480
|
-
if (expanded.has(index))
|
|
24481
|
-
scan.risky ??= UNREADABLE;
|
|
24482
|
-
}
|
|
24685
|
+
for (const [index, segment] of segments.entries()) {
|
|
24686
|
+
if (segment.unanalyzable)
|
|
24483
24687
|
continue;
|
|
24484
|
-
|
|
24485
|
-
|
|
24486
|
-
const
|
|
24487
|
-
|
|
24488
|
-
|
|
24489
|
-
|
|
24490
|
-
|
|
24491
|
-
seg.runs ||= scan.runs;
|
|
24492
|
-
scan.runs ||= before;
|
|
24493
|
-
}
|
|
24494
|
-
scan.words.push(...seg.words);
|
|
24495
|
-
const reaches = () => seg.runs || mayBeWorkit(seg.words, scan.cwd);
|
|
24496
|
-
if (seg.identity && reaches())
|
|
24497
|
-
scan.hit ??= seg.identity;
|
|
24498
|
-
if (seg.scoped && reaches())
|
|
24499
|
-
scan.state ??= seg.scoped;
|
|
24500
|
-
scan.runs ||= seg.runs;
|
|
24688
|
+
bindLoop(segment.words, segments.slice(index + 1), scan);
|
|
24689
|
+
const words = pastKeywords(segment.words);
|
|
24690
|
+
const fed = scan.fed;
|
|
24691
|
+
scan.fed = null;
|
|
24692
|
+
const hit = segmentEntry(segment, words, dialect, scan, fed);
|
|
24693
|
+
if (hit)
|
|
24694
|
+
return hit;
|
|
24501
24695
|
}
|
|
24696
|
+
return null;
|
|
24502
24697
|
};
|
|
24503
|
-
var
|
|
24504
|
-
|
|
24505
|
-
const
|
|
24506
|
-
if (
|
|
24507
|
-
|
|
24508
|
-
|
|
24698
|
+
var bindLoop = (raw, after, scan) => {
|
|
24699
|
+
const at = raw.findIndex((word) => !KEYWORDS3.has(word));
|
|
24700
|
+
const verb = raw[at];
|
|
24701
|
+
if ((verb === "for" || verb === "select") && raw[at + 2] === "in") {
|
|
24702
|
+
const name = raw[at + 1] ?? "";
|
|
24703
|
+
const items = raw.slice(at + 3);
|
|
24704
|
+
const item = items.find((word) => entryNamed(word, scan)) ?? items[0];
|
|
24705
|
+
if (/^[A-Za-z_]\w*$/u.test(name) && item !== undefined)
|
|
24706
|
+
scan.vars.set(name, expand(item, scan.vars));
|
|
24707
|
+
return;
|
|
24708
|
+
}
|
|
24709
|
+
const read = raw.indexOf("read");
|
|
24710
|
+
if (read < 0 || !raw.slice(0, read).some((word) => word === "while" || word === "until"))
|
|
24711
|
+
return;
|
|
24712
|
+
const fed = after.find((segment) => segment.words[0] === "done")?.stdin?.[0];
|
|
24713
|
+
const line = fed?.split(`
|
|
24714
|
+
`)[0]?.trim();
|
|
24715
|
+
const name = raw.slice(read + 1).find((word) => /^[A-Za-z_]\w*$/u.test(word));
|
|
24716
|
+
if (name && line)
|
|
24717
|
+
scan.vars.set(name, line);
|
|
24718
|
+
};
|
|
24719
|
+
var segmentEntry = (segment, words, dialect, scan, fed) => {
|
|
24720
|
+
const verb = baseName3(words[0] ?? "");
|
|
24721
|
+
if (["cd", "pushd", "chdir", "set-location", "sl"].includes(verb)) {
|
|
24722
|
+
const target = words.slice(1).find((word) => !word.startsWith("-") || word === "-");
|
|
24723
|
+
const moved = target === undefined ? userHome2(process.env) : expand(target, scan.vars);
|
|
24724
|
+
scan.dir = moved === "-" || /[$`]/u.test(moved) ? null : path42.isAbsolute(moved) ? moved : scan.dir && path42.resolve(scan.dir, moved);
|
|
24725
|
+
if (scan.dir === null)
|
|
24726
|
+
scan.vars.delete("PWD");
|
|
24727
|
+
else
|
|
24728
|
+
scan.vars.set("PWD", scan.dir);
|
|
24509
24729
|
return null;
|
|
24510
|
-
|
|
24511
|
-
if (
|
|
24512
|
-
|
|
24513
|
-
|
|
24730
|
+
}
|
|
24731
|
+
if (verb === "popd") {
|
|
24732
|
+
scan.dir = null;
|
|
24733
|
+
return null;
|
|
24734
|
+
}
|
|
24735
|
+
const declares = ["export", "declare", "typeset", "local", "readonly"].includes(verb);
|
|
24736
|
+
const assigns = declares ? words.slice(1) : words.every((word) => /^[A-Za-z_]\w*=/u.test(word)) ? words : [];
|
|
24737
|
+
for (const word of assigns) {
|
|
24738
|
+
const [name = "", value] = word.split(/=(.*)/su);
|
|
24739
|
+
if (value !== undefined && /^[A-Za-z_]\w*$/u.test(name))
|
|
24740
|
+
scan.vars.set(name, expand(value.replace(/^(['"])(.*)\1$/su, "$2"), scan.vars));
|
|
24741
|
+
}
|
|
24742
|
+
const options = optionsEntry(declares ? words.slice(1) : words, scan);
|
|
24743
|
+
if (options)
|
|
24744
|
+
return options;
|
|
24745
|
+
if (verb === "exec" && words.slice(1).every((word) => /^\d+$/u.test(word))) {
|
|
24746
|
+
for (const input of segment.inputs ?? [])
|
|
24747
|
+
if (entryNamed(input, scan))
|
|
24748
|
+
for (const fd of words.slice(1))
|
|
24749
|
+
scan.fds.add(fd);
|
|
24750
|
+
}
|
|
24751
|
+
const inputs = segment.inputs ?? [];
|
|
24752
|
+
const entry = runsEntry(words, inputs, scan) ?? expandedCommand(words, scan) ?? opaqueEntry(words, inputs, { ...scan, fed });
|
|
24753
|
+
if (entry)
|
|
24754
|
+
return entry;
|
|
24755
|
+
if (segment.pipe)
|
|
24756
|
+
scan.fed = words.slice(1).flatMap((word) => word.split(TOKENS2)).map((token) => token ? tokenEntry(token, scan) : null).find(Boolean) ?? null;
|
|
24757
|
+
noteLink(words, scan);
|
|
24758
|
+
if (scan.depth >= 4)
|
|
24759
|
+
return null;
|
|
24760
|
+
const nested = (script) => scanCommand2(script, dialect, {
|
|
24761
|
+
...scan,
|
|
24762
|
+
vars: new Map(scan.vars),
|
|
24763
|
+
fed: null,
|
|
24764
|
+
depth: scan.depth + 1
|
|
24765
|
+
});
|
|
24766
|
+
const scripts = [...segment.subs ?? []];
|
|
24767
|
+
const script = shellScript2(words) ?? cmdScript2(words) ?? workitScript(words);
|
|
24768
|
+
if (script)
|
|
24769
|
+
scripts.push(script);
|
|
24770
|
+
if (!script && /^(?:ba|z|da|k)?sh$/u.test(verb) && words.slice(1).every((word) => word.startsWith("-")) || verb === "at" || verb === "batch")
|
|
24771
|
+
scripts.push(...segment.stdin ?? []);
|
|
24772
|
+
for (const text of scripts) {
|
|
24773
|
+
const hit = nested(text);
|
|
24774
|
+
if (hit)
|
|
24775
|
+
return hit;
|
|
24776
|
+
}
|
|
24777
|
+
return null;
|
|
24514
24778
|
};
|
|
24515
|
-
var
|
|
24516
|
-
const
|
|
24517
|
-
if (
|
|
24518
|
-
return powershellChange(command, identity);
|
|
24519
|
-
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))
|
|
24779
|
+
var cmdScript2 = (words) => {
|
|
24780
|
+
const name = baseName3(words[0] ?? "");
|
|
24781
|
+
if (!/^(?:cmd|pwsh|powershell)$/u.test(name))
|
|
24520
24782
|
return null;
|
|
24521
|
-
const
|
|
24522
|
-
|
|
24523
|
-
cwd: options.cwd,
|
|
24524
|
-
hit: null,
|
|
24525
|
-
state: null,
|
|
24526
|
-
shell: null,
|
|
24527
|
-
risky: null,
|
|
24528
|
-
runs: false,
|
|
24529
|
-
words: []
|
|
24530
|
-
};
|
|
24531
|
-
scanCommand2(command, dialect, 0, scan);
|
|
24532
|
-
if (scan.hit)
|
|
24533
|
-
return scan.hit;
|
|
24534
|
-
if (scan.state)
|
|
24535
|
-
return scan.state;
|
|
24536
|
-
if (scan.shell && (scan.runs || mayBeWorkit(scan.words, scan.cwd)))
|
|
24537
|
-
return scan.shell;
|
|
24538
|
-
return scan.runs ? scan.risky : null;
|
|
24783
|
+
const flag = words.findIndex((word, at) => at > 0 && /^[/-](?:c|k|command)$/iu.test(word));
|
|
24784
|
+
return flag < 0 ? null : words.slice(flag + 1).join(" ").replaceAll("\\", "/") || null;
|
|
24539
24785
|
};
|
|
24540
|
-
var
|
|
24541
|
-
if (
|
|
24542
|
-
return
|
|
24543
|
-
|
|
24786
|
+
var workitScript = (words) => {
|
|
24787
|
+
if (!/^workit(?:-cli)?$/u.test(baseName3(words[0] ?? "")))
|
|
24788
|
+
return null;
|
|
24789
|
+
const dash = words.indexOf("--");
|
|
24790
|
+
return dash < 0 ? null : words.slice(dash + 1).join(" ") || null;
|
|
24791
|
+
};
|
|
24792
|
+
var substitutions2 = (command) => {
|
|
24793
|
+
const found = [];
|
|
24794
|
+
for (let at = command.indexOf("$(");at >= 0 && found.length < 32; at = command.indexOf("$(", at + 1)) {
|
|
24795
|
+
if (command[at + 2] === "(")
|
|
24796
|
+
continue;
|
|
24797
|
+
let depth = 1;
|
|
24798
|
+
let end = at + 2;
|
|
24799
|
+
for (;end < command.length && depth > 0; end += 1)
|
|
24800
|
+
if (command[end] === "(")
|
|
24801
|
+
depth += 1;
|
|
24802
|
+
else if (command[end] === ")")
|
|
24803
|
+
depth -= 1;
|
|
24804
|
+
found.push(command.slice(at + 2, end - 1));
|
|
24805
|
+
}
|
|
24806
|
+
return found;
|
|
24807
|
+
};
|
|
24808
|
+
var hookEntryRun = (cwd, command, dialect = "posix") => {
|
|
24809
|
+
const scan = (text) => scanCommand2(text, dialect, {
|
|
24810
|
+
dir: cwd,
|
|
24811
|
+
vars: new Map([["PWD", cwd]]),
|
|
24812
|
+
links: new Set,
|
|
24813
|
+
fds: new Set,
|
|
24814
|
+
fed: null,
|
|
24815
|
+
depth: 0
|
|
24816
|
+
});
|
|
24817
|
+
const texts = dialect === "posix" && /[A-Za-z]:\\/u.test(command) ? [command, command.replaceAll("\\", "/")] : [command];
|
|
24818
|
+
for (const text of texts) {
|
|
24819
|
+
const hit = scan(text) ?? substitutions2(text).map(scan).find(Boolean);
|
|
24820
|
+
if (hit)
|
|
24821
|
+
return hit;
|
|
24822
|
+
}
|
|
24823
|
+
return null;
|
|
24544
24824
|
};
|
|
24825
|
+
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).`;
|
|
24545
24826
|
|
|
24546
24827
|
// packages/workit-core/src/hooks/handle.ts
|
|
24547
24828
|
var usable2 = (value) => value === "native" || value === "partial";
|