@workit-dev/opencode 2.28.0 → 2.29.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugin.js +921 -408
- package/package.json +2 -2
package/dist/plugin.js
CHANGED
|
@@ -8803,7 +8803,7 @@ var workspaceConfigSchema = looseObject({
|
|
|
8803
8803
|
})),
|
|
8804
8804
|
models: optional(looseObject({ roles: modelRoles })),
|
|
8805
8805
|
resources: optional(unknown()),
|
|
8806
|
-
remotes: optional(array(nonBlank.check(refine((pattern) =>
|
|
8806
|
+
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/*)")))),
|
|
8807
8807
|
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")))),
|
|
8808
8808
|
additiveRiskPaths: optional(array(nonBlank)),
|
|
8809
8809
|
autonomy: optional(looseObject(Object.fromEntries(["push", "pr", "merge", "release", "rerun"].map((kind) => [
|
|
@@ -9173,6 +9173,7 @@ var canonicalGlob = (glob) => {
|
|
|
9173
9173
|
return real + (prefix.endsWith("/") ? "/" : "") + rest;
|
|
9174
9174
|
};
|
|
9175
9175
|
var globSpecificity = (glob) => glob.replaceAll("\\", "/").split("/").filter((segment) => segment.length > 0 && !/[*?[\]{]/.test(segment)).length;
|
|
9176
|
+
var workspaceMatches = (cwd, entries) => matchingEntries(cwd, entries);
|
|
9176
9177
|
var selectWorkspaceMatch = (matches, cwd, workspaceName) => {
|
|
9177
9178
|
if (workspaceName !== undefined) {
|
|
9178
9179
|
const named = matches.filter((entry) => entry.name === workspaceName);
|
|
@@ -9194,15 +9195,32 @@ var selectWorkspaceMatch = (matches, cwd, workspaceName) => {
|
|
|
9194
9195
|
}
|
|
9195
9196
|
return mostSpecific[0];
|
|
9196
9197
|
};
|
|
9197
|
-
var
|
|
9198
|
-
|
|
9199
|
-
|
|
9200
|
-
|
|
9201
|
-
|
|
9198
|
+
var HOSTLESS_REMOTE = /^[\w-]+\/\*$/u;
|
|
9199
|
+
var expandRemotePattern = (entry, pattern) => {
|
|
9200
|
+
if (!HOSTLESS_REMOTE.test(pattern.trim()))
|
|
9201
|
+
return pattern;
|
|
9202
|
+
const vcs = entry.vcs ?? {};
|
|
9203
|
+
const host = typeof vcs.host === "string" && vcs.host.trim().replace(/^https?:\/\/|\/.*$/giu, "") || `${vcs.provider === "gitlab" ? "gitlab" : "github"}.com`;
|
|
9204
|
+
return `https://${host}/${pattern.trim()}`;
|
|
9205
|
+
};
|
|
9206
|
+
var isRemotePattern = (pattern) => !!remotePattern(expandRemotePattern({}, pattern));
|
|
9207
|
+
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));
|
|
9208
|
+
var resolveWorkspaceFromEntries = (cwd, entries, workspaceName, remotes) => {
|
|
9209
|
+
const globbed = matchingEntries(cwd, entries);
|
|
9210
|
+
const listed = !remotes || globbed.length || !entries.some((entry) => entry.remotes) ? [] : checkoutRemotes(cwd);
|
|
9211
|
+
const origin = listed instanceof Error ? [] : listed.filter((item) => item.name === "origin");
|
|
9212
|
+
const hits = entries.filter((entry) => origin.length && origin.every((item) => remoteClaimOf(entry, item.key)));
|
|
9213
|
+
const exact = hits.filter((entry) => origin.every((item) => remoteClaimOf(entry, item.key, true)));
|
|
9214
|
+
const ranked = exact.length ? exact : hits;
|
|
9215
|
+
if (workspaceName === undefined && ranked.length > 1)
|
|
9216
|
+
return null;
|
|
9217
|
+
return selectWorkspaceMatch(hits.length ? workspaceName ? hits : ranked : globbed, cwd, workspaceName) ?? null;
|
|
9218
|
+
};
|
|
9219
|
+
var resolveWorkspaceFrom = (cwd, dir, workspaceName, remotes) => {
|
|
9202
9220
|
const result = readWorkspacesResult(dir);
|
|
9203
9221
|
if (result.status === "malformed" || result.status === "invalid")
|
|
9204
9222
|
throw new WorkspaceConfigError(result.error);
|
|
9205
|
-
return resolveWorkspaceFromEntries(cwd, result.entries, workspaceName);
|
|
9223
|
+
return resolveWorkspaceFromEntries(cwd, result.entries, workspaceName, remotes);
|
|
9206
9224
|
};
|
|
9207
9225
|
var runtimeWorkspacePolicySchema = (kind) => {
|
|
9208
9226
|
const key = kind === "branch" ? "branchPolicy" : kind === "commit" ? "commitPolicy" : "vcs";
|
|
@@ -9252,10 +9270,12 @@ var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
|
|
|
9252
9270
|
if (!glob.ok)
|
|
9253
9271
|
throw new WorkspaceConfigError(`${file} workspace ${entry.name}: ${glob.error}`);
|
|
9254
9272
|
}
|
|
9255
|
-
const matches = matchingEntries(cwd, entries ?? []);
|
|
9256
9273
|
const workspaceName = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
|
|
9257
|
-
const selected =
|
|
9258
|
-
|
|
9274
|
+
const selected = resolveWorkspaceFromEntries(cwd, entries ?? [], workspaceName, true);
|
|
9275
|
+
if (!selected)
|
|
9276
|
+
return null;
|
|
9277
|
+
const matches = matchingEntries(cwd, entries ?? []);
|
|
9278
|
+
return { file, selected, matches: matches.length ? matches : [selected] };
|
|
9259
9279
|
};
|
|
9260
9280
|
var resolveRuntimeReleaseTracks = (cwd) => {
|
|
9261
9281
|
const matched = matchRuntimeWorkspace(cwd);
|
|
@@ -19281,6 +19301,7 @@ function ytrackReadiness(run, host) {
|
|
|
19281
19301
|
}
|
|
19282
19302
|
|
|
19283
19303
|
// packages/workit-core/src/autonomy.ts
|
|
19304
|
+
var resolveWorkspaceFrom2 = (cwd, dir, name) => resolveWorkspaceFrom(cwd, dir, name, true);
|
|
19284
19305
|
var accountHomeDir = () => {
|
|
19285
19306
|
const home = grantsHome.resolve();
|
|
19286
19307
|
return home === null ? null : configDir({ HOME: home });
|
|
@@ -19313,11 +19334,11 @@ var accountUnread = () => {
|
|
|
19313
19334
|
};
|
|
19314
19335
|
var entriesIn = (dir) => dir === null ? [] : loadWorkspacesFrom(dir);
|
|
19315
19336
|
var fileSource = (dir = accountDir()) => ({
|
|
19316
|
-
resolve: (cwd, name) => dir === null ? null :
|
|
19337
|
+
resolve: (cwd, name) => dir === null ? null : resolveWorkspaceFrom2(cwd, dir, name),
|
|
19317
19338
|
entries: () => entriesIn(dir)
|
|
19318
19339
|
});
|
|
19319
19340
|
var sealedSource = (entries) => ({
|
|
19320
|
-
resolve: (cwd, name) => resolveWorkspaceFromEntries(cwd, entries, name),
|
|
19341
|
+
resolve: (cwd, name) => resolveWorkspaceFromEntries(cwd, entries, name, true),
|
|
19321
19342
|
entries: () => entries
|
|
19322
19343
|
});
|
|
19323
19344
|
var sealOf = () => {
|
|
@@ -19343,8 +19364,8 @@ var youTrackWritesPolicy = (cwd) => {
|
|
|
19343
19364
|
return ASK;
|
|
19344
19365
|
const auto = (entry) => youtrackOf(entry)?.writes === "auto";
|
|
19345
19366
|
const name = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
|
|
19346
|
-
const named =
|
|
19347
|
-
const folder = name ?
|
|
19367
|
+
const named = resolveWorkspaceFrom2(cwd, dir, name);
|
|
19368
|
+
const folder = name ? resolveWorkspaceFrom2(cwd, dir) : named;
|
|
19348
19369
|
if (!auto(named) || !auto(folder))
|
|
19349
19370
|
return ASK;
|
|
19350
19371
|
const [a, b] = [autoHostsOf(named), autoHostsOf(folder)];
|
|
@@ -19599,7 +19620,8 @@ function resolveWith(source, cwd, world, target) {
|
|
|
19599
19620
|
const above = checkoutsAbove(cwd);
|
|
19600
19621
|
for (const where of above instanceof Error ? [above] : above)
|
|
19601
19622
|
autonomy = capAt(source, autonomy, where, where instanceof Error ? "git" : `checkout ${where}`, "a worktree or submodule never exceeds it", true);
|
|
19602
|
-
|
|
19623
|
+
const own = real && workspaceMatches(cwd, source.entries()).length === 0 ? real : undefined;
|
|
19624
|
+
return capAtRemotes(source, autonomy, cwd, target, own);
|
|
19603
19625
|
}
|
|
19604
19626
|
var needsAccount = (autonomy) => autonomy.configured.length > 0 && !autonomy.accountConfigured;
|
|
19605
19627
|
function stricter(current, sealed, note, unblock) {
|
|
@@ -19638,17 +19660,31 @@ function stricter(current, sealed, note, unblock) {
|
|
|
19638
19660
|
note: current.note ? `${current.note}; ${note}` : note
|
|
19639
19661
|
};
|
|
19640
19662
|
}
|
|
19641
|
-
function capAtRemotes(source, autonomy, cwd, target) {
|
|
19663
|
+
function capAtRemotes(source, autonomy, cwd, target, own) {
|
|
19642
19664
|
const claiming = source.entries().filter((entry) => entry.remotes?.length);
|
|
19643
19665
|
if (claiming.length === 0)
|
|
19644
19666
|
return autonomy;
|
|
19645
19667
|
const remotes = target === undefined ? checkoutRemotes(cwd) : typeof target === "function" ? target() : target;
|
|
19646
19668
|
if (remotes instanceof Error)
|
|
19647
19669
|
return capAt(source, autonomy, remotes, target === undefined ? "git" : "target", "a target that cannot be resolved never raises grants");
|
|
19670
|
+
const listed = Array.isArray(remotes) ? remotes : remotes.remotes;
|
|
19671
|
+
const capped = own ? capAtOwnClaim(source, autonomy, cwd, own, target && listed) : autonomy;
|
|
19672
|
+
return capAtClaims(source, capped, listed, claiming);
|
|
19673
|
+
}
|
|
19674
|
+
function capAtOwnClaim(source, autonomy, cwd, own, judged) {
|
|
19675
|
+
const push = judged ? { remotes: judged } : pushTarget(cwd, pushRemoteName(cwd) ?? "");
|
|
19676
|
+
if (push instanceof Error)
|
|
19677
|
+
return capAt(source, autonomy, push, "push target", "a target that cannot be resolved never raises grants");
|
|
19678
|
+
const unclaimed = push.remotes.filter((remote) => !remoteClaimOf(own, remote.key));
|
|
19679
|
+
if (unclaimed.length === 0 && push.remotes.length > 0)
|
|
19680
|
+
return autonomy;
|
|
19681
|
+
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>`);
|
|
19682
|
+
}
|
|
19683
|
+
function capAtClaims(source, autonomy, listed, claiming) {
|
|
19648
19684
|
let capped = autonomy;
|
|
19649
|
-
for (const remote of
|
|
19685
|
+
for (const remote of listed)
|
|
19650
19686
|
for (const entry of claiming) {
|
|
19651
|
-
const pattern = entry
|
|
19687
|
+
const pattern = remoteClaimOf(entry, remote.key);
|
|
19652
19688
|
if (pattern)
|
|
19653
19689
|
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");
|
|
19654
19690
|
}
|
|
@@ -19676,7 +19712,7 @@ function claimsIn(target, entries) {
|
|
|
19676
19712
|
return target;
|
|
19677
19713
|
const claiming = entries.filter((entry) => entry.remotes?.length);
|
|
19678
19714
|
return target.remotes.flatMap((remote) => claiming.flatMap((entry) => {
|
|
19679
|
-
const pattern = entry
|
|
19715
|
+
const pattern = remoteClaimOf(entry, remote.key);
|
|
19680
19716
|
return pattern ? [{ url: remote.url, workspace: entry.name, pattern }] : [];
|
|
19681
19717
|
}));
|
|
19682
19718
|
}
|
|
@@ -20135,9 +20171,9 @@ var arithmeticEnd = (command, start) => {
|
|
|
20135
20171
|
const end = substitutionEnd(command, start);
|
|
20136
20172
|
return command[end - 1] === ")" && end > start + 2 ? end : 0;
|
|
20137
20173
|
};
|
|
20138
|
-
var segmentsOf = (command, dialect = "posix") => {
|
|
20174
|
+
var segmentsOf = (command, dialect = "posix", options = {}) => {
|
|
20139
20175
|
try {
|
|
20140
|
-
return tokenize(command, dialect);
|
|
20176
|
+
return tokenize(command, dialect, options.spans === true);
|
|
20141
20177
|
} catch (error) {
|
|
20142
20178
|
const why = error instanceof ShellAnalysisError ? error.message : String(error);
|
|
20143
20179
|
return [{ words: [], redirects: [], unanalyzable: why }];
|
|
@@ -20147,12 +20183,14 @@ var afterEnv = (words) => {
|
|
|
20147
20183
|
const at = words.map((word) => word.split(/[\\/]/).at(-1)).lastIndexOf("env");
|
|
20148
20184
|
return at >= 0 && words.slice(at + 1).every((word, index, rest) => /^-|=/.test(word) || /^-[^-]*[uCS]$|^--(?:unset|chdir|split-string)$/.test(rest[index - 1] ?? ""));
|
|
20149
20185
|
};
|
|
20150
|
-
var tokenize = (command, dialect) => {
|
|
20186
|
+
var tokenize = (command, dialect, spans) => {
|
|
20151
20187
|
const posix = dialect === "posix";
|
|
20152
20188
|
const segments = [];
|
|
20153
20189
|
let current = { words: [], redirects: [] };
|
|
20154
20190
|
let word = "";
|
|
20155
20191
|
let inWord = false;
|
|
20192
|
+
let wordStart = -1;
|
|
20193
|
+
let cursor = 0;
|
|
20156
20194
|
let expanding = false;
|
|
20157
20195
|
let afterOperator = false;
|
|
20158
20196
|
let pending = null;
|
|
@@ -20163,9 +20201,13 @@ var tokenize = (command, dialect) => {
|
|
|
20163
20201
|
if (!inWord)
|
|
20164
20202
|
return;
|
|
20165
20203
|
const text = MARKERS.test(word) ? literal2(word) : word;
|
|
20204
|
+
const span = [wordStart, cursor];
|
|
20166
20205
|
if (pending === "redirect") {
|
|
20167
|
-
if (!duplicate || !/^(?:\d+-?|-)$/.test(text))
|
|
20206
|
+
if (!duplicate || !/^(?:\d+-?|-)$/.test(text)) {
|
|
20168
20207
|
current.redirects.push(text);
|
|
20208
|
+
if (spans)
|
|
20209
|
+
(current.redirectSpans ??= []).push(span);
|
|
20210
|
+
}
|
|
20169
20211
|
} else if (pending === "heredoc")
|
|
20170
20212
|
heredocs.push({ delimiter: text.replace(/^-/, ""), owner: current });
|
|
20171
20213
|
else if (pending === "herestring")
|
|
@@ -20173,17 +20215,20 @@ var tokenize = (command, dialect) => {
|
|
|
20173
20215
|
else if (pending === "input")
|
|
20174
20216
|
(current.inputs ??= []).push(text);
|
|
20175
20217
|
else {
|
|
20176
|
-
const
|
|
20218
|
+
const at0 = current.words.length;
|
|
20177
20219
|
if (/^[^=-][^=]*=/.test(word) && afterEnv(current.words))
|
|
20178
20220
|
word = word.replace(/^[^=]*/, (name) => name.replace(/\W/g, "_"));
|
|
20179
20221
|
current.words.push(...MARKERS.test(word) ? expandBraces(word) : [word]);
|
|
20222
|
+
if (spans)
|
|
20223
|
+
(current.spans ??= []).push(...current.words.slice(at0).map(() => span));
|
|
20180
20224
|
if (expanding || !posix && word.startsWith("@"))
|
|
20181
|
-
(current.expands ??= []).push(...current.words.slice(
|
|
20225
|
+
(current.expands ??= []).push(...current.words.slice(at0).map((_, i) => at0 + i));
|
|
20182
20226
|
}
|
|
20183
20227
|
pending = null;
|
|
20184
20228
|
duplicate = false;
|
|
20185
20229
|
word = "";
|
|
20186
20230
|
inWord = false;
|
|
20231
|
+
wordStart = -1;
|
|
20187
20232
|
expanding = false;
|
|
20188
20233
|
};
|
|
20189
20234
|
const flushSegment = () => {
|
|
@@ -20208,9 +20253,12 @@ var tokenize = (command, dialect) => {
|
|
|
20208
20253
|
};
|
|
20209
20254
|
const plain = posix ? PLAIN_POSIX : PLAIN_POWERSHELL;
|
|
20210
20255
|
for (let index = 0;index < command.length; index++) {
|
|
20256
|
+
cursor = index;
|
|
20211
20257
|
plain.lastIndex = index;
|
|
20212
20258
|
const run = plain.exec(command);
|
|
20213
20259
|
if (run) {
|
|
20260
|
+
if (wordStart < 0)
|
|
20261
|
+
wordStart = index;
|
|
20214
20262
|
word += run[0];
|
|
20215
20263
|
inWord = true;
|
|
20216
20264
|
if (EXPANDING_RUN.test(run[0]))
|
|
@@ -20236,9 +20284,11 @@ var tokenize = (command, dialect) => {
|
|
|
20236
20284
|
word += text;
|
|
20237
20285
|
inWord = true;
|
|
20238
20286
|
index = end;
|
|
20239
|
-
} else if (posix && char === "$" && next === '"')
|
|
20287
|
+
} else if (posix && char === "$" && next === '"') {
|
|
20288
|
+
if (wordStart < 0)
|
|
20289
|
+
wordStart = index;
|
|
20240
20290
|
continue;
|
|
20241
|
-
else if (char === "'" || char === '"') {
|
|
20291
|
+
} else if (char === "'" || char === '"') {
|
|
20242
20292
|
const end = closingQuote(command, index, dialect);
|
|
20243
20293
|
const body = command.slice(index + 1, end < 0 ? undefined : end);
|
|
20244
20294
|
if (posix && char === '"' && /\$\(|`/.test(body))
|
|
@@ -20279,6 +20329,7 @@ var tokenize = (command, dialect) => {
|
|
|
20279
20329
|
index = end;
|
|
20280
20330
|
} else if (posix && char === "(" && (pending === "input" || pending === "redirect")) {
|
|
20281
20331
|
const sign = pending === "input" ? "<" : ">";
|
|
20332
|
+
wordStart = index - 1;
|
|
20282
20333
|
pending = null;
|
|
20283
20334
|
const end = substitutionEnd(command, index);
|
|
20284
20335
|
const inner = command.slice(index + 1, end);
|
|
@@ -20291,8 +20342,10 @@ var tokenize = (command, dialect) => {
|
|
|
20291
20342
|
if (char === "(" && inWord && word.endsWith("$")) {
|
|
20292
20343
|
word = word.slice(0, -1);
|
|
20293
20344
|
inWord = word !== "";
|
|
20294
|
-
if (!inWord)
|
|
20345
|
+
if (!inWord) {
|
|
20295
20346
|
expanding = false;
|
|
20347
|
+
wordStart = -1;
|
|
20348
|
+
}
|
|
20296
20349
|
}
|
|
20297
20350
|
group(char === "(" ? "open" : "close");
|
|
20298
20351
|
} else if (!posix && (char === "{" || char === "}")) {
|
|
@@ -20327,6 +20380,7 @@ var tokenize = (command, dialect) => {
|
|
|
20327
20380
|
if (inWord && /^\d$/.test(word)) {
|
|
20328
20381
|
word = "";
|
|
20329
20382
|
inWord = false;
|
|
20383
|
+
wordStart = -1;
|
|
20330
20384
|
} else
|
|
20331
20385
|
flushWord();
|
|
20332
20386
|
if (command[index + 1] === ">")
|
|
@@ -20358,7 +20412,10 @@ var tokenize = (command, dialect) => {
|
|
|
20358
20412
|
word += char;
|
|
20359
20413
|
inWord = true;
|
|
20360
20414
|
}
|
|
20415
|
+
if (inWord && wordStart < 0)
|
|
20416
|
+
wordStart = cursor;
|
|
20361
20417
|
}
|
|
20418
|
+
cursor = command.length;
|
|
20362
20419
|
flushSegment();
|
|
20363
20420
|
return segments;
|
|
20364
20421
|
};
|
|
@@ -26480,6 +26537,36 @@ var verbAt = (words) => {
|
|
|
26480
26537
|
}
|
|
26481
26538
|
};
|
|
26482
26539
|
var WRAPPERS2 = new Set(["env", "sudo", "nohup", "command", "timeout", "nice", "exec"]);
|
|
26540
|
+
var VALUED = /^-(?:[ugnskCpD]|-user|-group|-signal|-kill-after|-unset|-chdir)$/u;
|
|
26541
|
+
var unwrapped = (words) => {
|
|
26542
|
+
let at = 0;
|
|
26543
|
+
for (;; ) {
|
|
26544
|
+
const word = words[at] ?? "";
|
|
26545
|
+
const name = word.split("/").at(-1) ?? "";
|
|
26546
|
+
if (/^[A-Za-z_]\w*=/u.test(word))
|
|
26547
|
+
at += 1;
|
|
26548
|
+
else if (WRAPPERS2.has(name)) {
|
|
26549
|
+
at += 1;
|
|
26550
|
+
while (words[at]?.startsWith("-"))
|
|
26551
|
+
at += VALUED.test(words[at] ?? "") ? 2 : 1;
|
|
26552
|
+
if (name === "timeout" && words[at] !== undefined)
|
|
26553
|
+
at += 1;
|
|
26554
|
+
} else
|
|
26555
|
+
return words.slice(at);
|
|
26556
|
+
}
|
|
26557
|
+
};
|
|
26558
|
+
var shellScript2 = (all) => {
|
|
26559
|
+
const words = unwrapped(all);
|
|
26560
|
+
const name = words[0]?.split("/").at(-1) ?? "";
|
|
26561
|
+
if (name === "eval")
|
|
26562
|
+
return words.slice(1).join(" ") || null;
|
|
26563
|
+
if (!/^(?:ba|z|da|k)?sh$/u.test(name))
|
|
26564
|
+
return null;
|
|
26565
|
+
const flag = words.findIndex((word, at) => at > 0 && /^-[a-z]*c[a-z]*$/u.test(word));
|
|
26566
|
+
if (flag < 0)
|
|
26567
|
+
return null;
|
|
26568
|
+
return words[words[flag + 1] === "--" ? flag + 2 : flag + 1] ?? null;
|
|
26569
|
+
};
|
|
26483
26570
|
var isAllowedWorkitCall = (words, expands = []) => {
|
|
26484
26571
|
if (words[0] !== "workit")
|
|
26485
26572
|
return false;
|
|
@@ -28103,7 +28190,7 @@ var wrappedScript = (input) => {
|
|
|
28103
28190
|
return null;
|
|
28104
28191
|
if ("script" in tail)
|
|
28105
28192
|
return tail.script;
|
|
28106
|
-
const script =
|
|
28193
|
+
const script = shellScript3(tail.argv);
|
|
28107
28194
|
if (SCRIPT_SHELLS.has((tail.argv[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()) && script)
|
|
28108
28195
|
return script;
|
|
28109
28196
|
return tail.argv.map(quoteWord2).join(" ");
|
|
@@ -28441,13 +28528,13 @@ var scriptArgs = (verb, args) => {
|
|
|
28441
28528
|
}
|
|
28442
28529
|
return { preloads };
|
|
28443
28530
|
};
|
|
28444
|
-
var
|
|
28531
|
+
var unwrapped2 = (words) => {
|
|
28445
28532
|
let at = 0;
|
|
28446
28533
|
for (let takes;(takes = WRAPPERS3[words[at]?.split(/[\\/]/).at(-1) ?? ""]) !== undefined; )
|
|
28447
28534
|
at = pastOptions(words, at + 1, takes, true);
|
|
28448
28535
|
return at ? words.slice(at) : null;
|
|
28449
28536
|
};
|
|
28450
|
-
var
|
|
28537
|
+
var shellScript3 = (words) => {
|
|
28451
28538
|
if (!SCRIPT_SHELLS.has((words[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()))
|
|
28452
28539
|
return null;
|
|
28453
28540
|
for (let index = 1;index < words.length; index++) {
|
|
@@ -28599,7 +28686,7 @@ var opaqueWrites = (input, scriptOf = (index) => input[index], fed, loads = fals
|
|
|
28599
28686
|
return ["."];
|
|
28600
28687
|
if (/^(?:python[\d.]*|node|bun|deno|ruby|php|tsx|ts-node)$/.test(name))
|
|
28601
28688
|
return inline(INLINE_CODE);
|
|
28602
|
-
return
|
|
28689
|
+
return shellScript3(words) === null ? null : ["."];
|
|
28603
28690
|
};
|
|
28604
28691
|
var CURL_LONG = [
|
|
28605
28692
|
"output",
|
|
@@ -29363,7 +29450,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
29363
29450
|
moved(plain);
|
|
29364
29451
|
continue;
|
|
29365
29452
|
}
|
|
29366
|
-
const literal = depth < 4 ? wrappedScript(words) ?? (strict ?
|
|
29453
|
+
const literal = depth < 4 ? wrappedScript(words) ?? (strict ? shellScript3(pastLead(words)) : null) : null;
|
|
29367
29454
|
const held = literal !== null && strict === "registry" ? expansions(literal, vars, loops) : [];
|
|
29368
29455
|
const inner = held.length === 1 ? held[0] : literal;
|
|
29369
29456
|
const unPwd = () => new Map([...vars].filter(([key]) => key !== "PWD"));
|
|
@@ -29378,7 +29465,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
29378
29465
|
if (windows !== null && dir !== undefined)
|
|
29379
29466
|
for (const file of segmentTargets(dir, windows, "powershell", depth + 1, strict, vars, cmd))
|
|
29380
29467
|
targets.push(cmd && CMD_VAR.test(file) ? placeholderIn(dir, `${OPAQUE_TARGET}cmd`) : file);
|
|
29381
|
-
const bare = strict && depth < 4 ?
|
|
29468
|
+
const bare = strict && depth < 4 ? unwrapped2(words) : null;
|
|
29382
29469
|
if (bare?.length && dir !== undefined)
|
|
29383
29470
|
targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord2).join(" "), "posix", depth + 1, strict, vars));
|
|
29384
29471
|
if (strict === "registry" && dir !== undefined && depth < 4) {
|
|
@@ -29415,9 +29502,9 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
29415
29502
|
const shells = verb === "eval" ? [args.join(" ")] : verb === "trap" ? args.slice(0, 1) : verb === "alias" ? args.map((arg) => arg.replace(/^[^=]*=/, "")) : [];
|
|
29416
29503
|
const others = [];
|
|
29417
29504
|
if (SCRIPT_SHELLS.has(verb) || verb === "." || verb === "source") {
|
|
29418
|
-
if (named === undefined &&
|
|
29505
|
+
if (named === undefined && shellScript3(run) === null)
|
|
29419
29506
|
shells.push(...segment.stdin ?? [], ...inputs.flatMap(read), ...piped);
|
|
29420
|
-
else if (named !== undefined &&
|
|
29507
|
+
else if (named !== undefined && shellScript3(run) === null)
|
|
29421
29508
|
shells.push(...read(named));
|
|
29422
29509
|
shells.push(...preloads.flatMap(read));
|
|
29423
29510
|
} else if (INTERPRETERS.test(verb)) {
|
|
@@ -29487,7 +29574,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
29487
29574
|
targets.push(file === "." ? placeholderIn(resolved, here) : path43.basename(resolved).startsWith(OPAQUE_TARGET) ? placeholderIn(path43.dirname(resolved), path43.basename(resolved)) : resolved);
|
|
29488
29575
|
const [shell = "", ...shellArgs] = pastLead(words);
|
|
29489
29576
|
const verb = (shell.split(/[\\/]/).at(-1) ?? "").toLowerCase();
|
|
29490
|
-
const named = (SCRIPT_SHELLS.has(verb) || verb === "source" || verb === ".") &&
|
|
29577
|
+
const named = (SCRIPT_SHELLS.has(verb) || verb === "source" || verb === ".") && shellScript3([verb, ...shellArgs]) === null ? scriptArgs(verb, shellArgs).named ?? "" : null;
|
|
29491
29578
|
if (depth < 4 && verb === "eval")
|
|
29492
29579
|
targets.push(...segmentTargets(runIn, shellArgs.join(" "), dialect, depth + 1, strict, vars));
|
|
29493
29580
|
else if (named !== null && /^<\(|^\/dev\/fd\/[1-9]/.test(named))
|
|
@@ -30523,8 +30610,8 @@ var WRITE_TOOLS = new Set([
|
|
|
30523
30610
|
"writefile"
|
|
30524
30611
|
]);
|
|
30525
30612
|
// packages/workit-core/src/hooks/standing.ts
|
|
30526
|
-
import
|
|
30527
|
-
import
|
|
30613
|
+
import fs31 from "node:fs";
|
|
30614
|
+
import path47 from "node:path";
|
|
30528
30615
|
|
|
30529
30616
|
// packages/workit-core/src/approvals/store.ts
|
|
30530
30617
|
var REQUEST_TTL_MS = 30 * 60000;
|
|
@@ -30534,6 +30621,166 @@ var INLINE_ASK_TTL_MS = 2 * 60000;
|
|
|
30534
30621
|
var namesTicket = (text) => /WORKIT_APPROVAL_(?:TICKET|UNASKED)/u.test(text.replace(/['"\\]/gu, ""));
|
|
30535
30622
|
var TICKET_DENY = "Only the host's prompt adds an approval ticket.";
|
|
30536
30623
|
|
|
30624
|
+
// packages/workit-core/src/hooks/cwd-normalize.ts
|
|
30625
|
+
var DIR = String.raw`(?:[A-Za-z0-9_./@%+:,=-]|(?<=[A-Za-z0-9])~)+|'[^'$${"`"}\n]*'|"(?:[^"$${"`"}\\!\n]|\\(?=[^"$${"`"}\\!\n]))*"`;
|
|
30626
|
+
var COMPOUND2 = new RegExp(String.raw`^\s*cd\s+(${DIR})\s*&&\s*(workit(?:\s[\s\S]*)?)$`, "u");
|
|
30627
|
+
var UNSAFE = /[\p{Cf}\p{Zl}\p{Zp}]|[^\P{Cc}\n]/u;
|
|
30628
|
+
var newlines = (text) => text.split(`
|
|
30629
|
+
`).length - 1;
|
|
30630
|
+
var writtenWord = (command, segment, index) => {
|
|
30631
|
+
const span = segment.spans?.[index];
|
|
30632
|
+
if (!span)
|
|
30633
|
+
return null;
|
|
30634
|
+
const glued = (other) => other !== undefined && other !== span && (other[1] === span[0] || other[0] === span[1]);
|
|
30635
|
+
if (glued(segment.spans?.[index - 1]) || glued(segment.spans?.[index + 1]))
|
|
30636
|
+
return null;
|
|
30637
|
+
const text = command.slice(span[0], span[1]);
|
|
30638
|
+
const value = segment.words[index] ?? "";
|
|
30639
|
+
return UNSAFE.test(text) || newlines(text) !== newlines(value) ? null : text;
|
|
30640
|
+
};
|
|
30641
|
+
var writtenWords = (command, segment, indexes) => {
|
|
30642
|
+
const texts = [];
|
|
30643
|
+
let last;
|
|
30644
|
+
for (const index of indexes) {
|
|
30645
|
+
const span = segment.spans?.[index];
|
|
30646
|
+
if (span && span === last)
|
|
30647
|
+
continue;
|
|
30648
|
+
last = span;
|
|
30649
|
+
const text = writtenWord(command, segment, index);
|
|
30650
|
+
if (text === null)
|
|
30651
|
+
return null;
|
|
30652
|
+
texts.push(text);
|
|
30653
|
+
}
|
|
30654
|
+
return texts;
|
|
30655
|
+
};
|
|
30656
|
+
var cwdIndependent = (text, colons = false) => {
|
|
30657
|
+
let quoted = false;
|
|
30658
|
+
for (let index = 0;index < text.length; index += 1) {
|
|
30659
|
+
const char = text[index] ?? "";
|
|
30660
|
+
if (char === "\\")
|
|
30661
|
+
index += 1;
|
|
30662
|
+
else if (char === "'" && !quoted) {
|
|
30663
|
+
const end = text.indexOf("'", index + 1);
|
|
30664
|
+
if (end < 0)
|
|
30665
|
+
return false;
|
|
30666
|
+
index = end;
|
|
30667
|
+
} else if (char === '"')
|
|
30668
|
+
quoted = !quoted;
|
|
30669
|
+
else if (char === "$" || char === "`")
|
|
30670
|
+
return false;
|
|
30671
|
+
else if (quoted)
|
|
30672
|
+
continue;
|
|
30673
|
+
else if (/[*?[]/u.test(char) || /[<>]/u.test(char) && text[index + 1] === "(")
|
|
30674
|
+
return false;
|
|
30675
|
+
else if (char === "~") {
|
|
30676
|
+
const start = index === 0 || colons && text[index - 1] === ":";
|
|
30677
|
+
if (!start || !/^(?:\/|:|$)/u.test(text.slice(index + 1, index + 2)))
|
|
30678
|
+
return false;
|
|
30679
|
+
}
|
|
30680
|
+
}
|
|
30681
|
+
return !quoted;
|
|
30682
|
+
};
|
|
30683
|
+
var NOT_A_PATH = /^(?:\d*|true|false|yes|no|on|off|-[\w-]*(?:=\d+)?)$/iu;
|
|
30684
|
+
var cwdFreeAssignment = (text, value) => {
|
|
30685
|
+
const written = text.replace(/^[A-Za-z_]\w*=/u, "");
|
|
30686
|
+
if (!cwdIndependent(written, true))
|
|
30687
|
+
return false;
|
|
30688
|
+
const quotes = /['"\\]/u.test(written);
|
|
30689
|
+
const parts = value.replace(/^[A-Za-z_]\w*=/u, "").split(":");
|
|
30690
|
+
return parts.every((part) => part.startsWith("/") || !quotes && /^~(?:\/|$)/u.test(part) || (part !== "" || parts.length === 1) && NOT_A_PATH.test(part));
|
|
30691
|
+
};
|
|
30692
|
+
var plainQuotedExpansions = (text) => {
|
|
30693
|
+
const bare = text.replaceAll(/\\./gu, "").replaceAll(/\$(?:[A-Za-z_]\w*|\{[A-Za-z_]\w*\})/gu, "");
|
|
30694
|
+
return !bare.includes("$") && !bare.includes("`");
|
|
30695
|
+
};
|
|
30696
|
+
var certainDir = (text, value) => value !== "" && !value.startsWith("-") && (/^(?:"(?:[^"\\]|\\.)*"|'[^']*')$/u.test(text) && (text.startsWith("'") || plainQuotedExpansions(text)) || cwdIndependent(text) && !/[{}]/u.test(text.replaceAll(/'[^']*'|"(?:[^"\\]|\\.)*"|\\./gu, "")));
|
|
30697
|
+
var namesSet = (segments) => {
|
|
30698
|
+
const names = new Set;
|
|
30699
|
+
for (const { words } of segments) {
|
|
30700
|
+
const at = /^(?:export|declare|typeset|local|readonly)$/u.test(words[0] ?? "") ? 1 : 0;
|
|
30701
|
+
const assigns = words.slice(at).filter((word) => /^[A-Za-z_]\w*=/u.test(word));
|
|
30702
|
+
if (at === 1 || assigns.length === words.length)
|
|
30703
|
+
for (const word of assigns)
|
|
30704
|
+
names.add(word.slice(0, word.indexOf("=")));
|
|
30705
|
+
if (words[0] === "read" || words[0] === "mapfile") {
|
|
30706
|
+
for (const word of words.slice(1))
|
|
30707
|
+
if (/^[A-Za-z_]\w*$/u.test(word))
|
|
30708
|
+
names.add(word);
|
|
30709
|
+
}
|
|
30710
|
+
}
|
|
30711
|
+
return names;
|
|
30712
|
+
};
|
|
30713
|
+
var NO_PATH = /^(?:\d+|-[A-Za-z0-9-]*)$/u;
|
|
30714
|
+
var cwdFreeTail = (texts, check = false) => {
|
|
30715
|
+
const [command = "", ...args] = texts;
|
|
30716
|
+
if (command.includes("/") && !command.startsWith("/"))
|
|
30717
|
+
return false;
|
|
30718
|
+
return check || args.every((text) => NO_PATH.test(text) || /^(?:\/|~(?:\/|$))/u.test(text));
|
|
30719
|
+
};
|
|
30720
|
+
var GLOBALS_FIRST = new RegExp(String.raw`^(\s*workit)((?:\s+(?:--json|--cwd(?:=|\s+)(?:${DIR})))+)\s+([a-z][a-z-]*)(?=\s|$)`, "u");
|
|
30721
|
+
var VERB_FIRST = /^((?:--json\s+)*)([a-z][a-z-]*)(?=\s|$)/u;
|
|
30722
|
+
var VERBS = new Set(WORKIT_ALLOWED_VERBS);
|
|
30723
|
+
var FILTERS = new Set(["tail", "head", "grep"]);
|
|
30724
|
+
var clean = (s) => !s.unanalyzable && !s.group && !s.subs?.length && !s.stdin?.length && !s.redirects.length;
|
|
30725
|
+
var stdinOnly = (words) => {
|
|
30726
|
+
const [name, ...args] = words;
|
|
30727
|
+
const operands = args.filter((w) => !w.startsWith("-"));
|
|
30728
|
+
if (name === "grep")
|
|
30729
|
+
return operands.length <= 1 && !args.some((w) => /^-[^-]*[rRf]|^--(recursive|file)/u.test(w));
|
|
30730
|
+
return operands.every((w) => /^\d+$/u.test(w)) && !args.some((w) => w.startsWith("--output"));
|
|
30731
|
+
};
|
|
30732
|
+
var cwdRewrite = (command) => {
|
|
30733
|
+
const match = COMPOUND2.exec(command);
|
|
30734
|
+
const dir = match?.[1];
|
|
30735
|
+
const rest = match?.[2];
|
|
30736
|
+
if (!dir || !rest || dir.startsWith("-"))
|
|
30737
|
+
return null;
|
|
30738
|
+
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "").replaceAll(/'[^']*'|"([^"\\]|\\.)*"/gu, "")))
|
|
30739
|
+
return null;
|
|
30740
|
+
const segments = segmentsOf(rest);
|
|
30741
|
+
const [head, ...filters] = segments;
|
|
30742
|
+
if (!head || head.words[0] !== "workit")
|
|
30743
|
+
return null;
|
|
30744
|
+
if (!segments.every(clean))
|
|
30745
|
+
return null;
|
|
30746
|
+
if (!segments.slice(0, -1).every((s) => s.pipe))
|
|
30747
|
+
return null;
|
|
30748
|
+
if (!filters.every((s) => FILTERS.has(s.words[0] ?? "") && stdinOnly(s.words)))
|
|
30749
|
+
return null;
|
|
30750
|
+
const at = head.words.indexOf("--cwd");
|
|
30751
|
+
if (at >= 0) {
|
|
30752
|
+
const bare = dir.replace(/^(['"])(.*)\1$/u, "$2");
|
|
30753
|
+
return bare[0] === "/" && head.words[at + 1] === bare ? rest : null;
|
|
30754
|
+
}
|
|
30755
|
+
if (head.words.some((w) => w.startsWith("--cwd=")))
|
|
30756
|
+
return null;
|
|
30757
|
+
const args = rest.slice("workit".length).trimStart();
|
|
30758
|
+
const verb = VERB_FIRST.exec(args);
|
|
30759
|
+
if (!verb?.[2] || !VERBS.has(verb[2]))
|
|
30760
|
+
return `workit --cwd ${dir} ${args}`.trimEnd();
|
|
30761
|
+
const json = verb[1] ? " --json" : "";
|
|
30762
|
+
return `workit ${verb[2]} --cwd ${dir}${json}${args.slice(verb[0].length)}`.trimEnd();
|
|
30763
|
+
};
|
|
30764
|
+
var verbFirst = (command) => {
|
|
30765
|
+
const match = GLOBALS_FIRST.exec(command);
|
|
30766
|
+
const [whole, lead, globals, verb] = match ?? [];
|
|
30767
|
+
if (!whole || !verb || !VERBS.has(verb) || !globals?.includes("--cwd"))
|
|
30768
|
+
return null;
|
|
30769
|
+
const segments = segmentsOf(command);
|
|
30770
|
+
if (segments.length !== 1 || !segments.every(clean))
|
|
30771
|
+
return null;
|
|
30772
|
+
return `${lead} ${verb}${globals}${command.slice(whole.length)}`;
|
|
30773
|
+
};
|
|
30774
|
+
var NPX = new RegExp(String.raw`^(\s*(?:cd\s+(?:${DIR})\s*&&\s*)?)npx(?:\s+(?:-y|--yes))*\s+@workit-dev\/cli(?:@[\w.-]+)?(?=\s|$)`, "u");
|
|
30775
|
+
var npxWorkit = (command) => {
|
|
30776
|
+
const match = NPX.exec(command);
|
|
30777
|
+
if (!match)
|
|
30778
|
+
return null;
|
|
30779
|
+
const call = `${match[1]}workit${command.slice(match[0].length)}`;
|
|
30780
|
+
const left = segmentsOf(call).some((s) => s.unanalyzable || s.words.some((w) => /^(npx|@workit-dev\/cli(@\S*)?)$/u.test(w)));
|
|
30781
|
+
return left ? null : cwdRewrite(call) ?? verbFirst(call) ?? call;
|
|
30782
|
+
};
|
|
30783
|
+
|
|
30537
30784
|
// packages/workit-core/src/approvals/youtrack-ask.ts
|
|
30538
30785
|
var TIME = "markdown file minutes text date";
|
|
30539
30786
|
var FLAGS = {
|
|
@@ -30545,8 +30792,8 @@ var FLAGS = {
|
|
|
30545
30792
|
};
|
|
30546
30793
|
|
|
30547
30794
|
// packages/workit-core/src/approvals/inline.ts
|
|
30548
|
-
var
|
|
30549
|
-
var OPAQUE_RELEASE_FIX = `workit release --cwd ${
|
|
30795
|
+
var DIR2 = "<dir>";
|
|
30796
|
+
var OPAQUE_RELEASE_FIX = `workit release --cwd ${DIR2} notes approve <version>`;
|
|
30550
30797
|
|
|
30551
30798
|
// packages/workit-core/src/hooks/hosts/claude-code.ts
|
|
30552
30799
|
var CLAUDE_CODE_DESCRIPTOR = {
|
|
@@ -31016,69 +31263,538 @@ var PI_DESCRIPTOR = {
|
|
|
31016
31263
|
]
|
|
31017
31264
|
};
|
|
31018
31265
|
|
|
31019
|
-
// packages/workit-core/src/hooks/
|
|
31020
|
-
|
|
31021
|
-
|
|
31022
|
-
|
|
31023
|
-
|
|
31024
|
-
|
|
31025
|
-
|
|
31026
|
-
|
|
31027
|
-
|
|
31028
|
-
|
|
31029
|
-
|
|
31266
|
+
// packages/workit-core/src/hooks/identity-env.ts
|
|
31267
|
+
import fs30 from "node:fs";
|
|
31268
|
+
import path46 from "node:path";
|
|
31269
|
+
var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
|
|
31270
|
+
var IDENTITY = new RegExp(`^${NAMES}$`, "u");
|
|
31271
|
+
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
31272
|
+
var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
|
|
31273
|
+
var IDENTITY_ANY = new RegExp(NAMES, "iu");
|
|
31274
|
+
var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
|
|
31275
|
+
var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
|
|
31276
|
+
var STATE_ANY = new RegExp(STATE_NAMES, "iu");
|
|
31277
|
+
var powershell = (names) => new RegExp([
|
|
31278
|
+
`\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
|
|
31279
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
|
|
31280
|
+
`SetEnvironmentVariable\\(\\s*['"]${names}\\b`
|
|
31281
|
+
].join("|"), "iu");
|
|
31282
|
+
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";
|
|
31283
|
+
var POWERSHELL = powershell(NAMES);
|
|
31284
|
+
var POWERSHELL_STATE = powershell(STATE_NAMES);
|
|
31285
|
+
var POWERSHELL_HOST = powershell(HOST_NAMES);
|
|
31286
|
+
var POWERSHELL_OPAQUE = new RegExp([
|
|
31287
|
+
`SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
|
|
31288
|
+
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
|
|
31289
|
+
`(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
|
|
31290
|
+
`\\b(?:iex|Invoke-Expression)\\b`
|
|
31291
|
+
].join("|"), "iu");
|
|
31292
|
+
var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
|
|
31293
|
+
var CMD_IDENTITY = cmdSet(NAMES);
|
|
31294
|
+
var CMD_STATE = cmdSet(STATE_NAMES);
|
|
31295
|
+
var CMD_HOST = cmdSet(HOST_NAMES);
|
|
31296
|
+
var RUNS_TEXT = /\bworkit(?:-cli)?\b|@workit-dev[\\/]cli/iu;
|
|
31297
|
+
var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
|
|
31298
|
+
var OPAQUE = new Set([
|
|
31299
|
+
"watch",
|
|
31300
|
+
"strace",
|
|
31301
|
+
"chroot",
|
|
31302
|
+
"flock",
|
|
31303
|
+
"ssh",
|
|
31304
|
+
"su",
|
|
31305
|
+
"runuser",
|
|
31306
|
+
"script",
|
|
31307
|
+
"parallel"
|
|
31030
31308
|
]);
|
|
31031
|
-
|
|
31032
|
-
|
|
31033
|
-
var
|
|
31034
|
-
|
|
31035
|
-
|
|
31036
|
-
|
|
31037
|
-
|
|
31038
|
-
var
|
|
31039
|
-
|
|
31040
|
-
|
|
31041
|
-
|
|
31309
|
+
var ENV_VALUED = new Set(["u", "C", "S", "a", "P"]);
|
|
31310
|
+
var ENV_FLAGS = new Set(["i", "0", "v"]);
|
|
31311
|
+
var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
|
|
31312
|
+
var ENV_LONG_FLAGS = /^--(?:ignore-environment|null|debug|(?:block|default|ignore)-signal(?:=.*)?)$/u;
|
|
31313
|
+
var base2 = (word) => (word?.split(/[\\/]/u).at(-1) ?? "").replace(/\.exe$/iu, "");
|
|
31314
|
+
var ASSIGN = /^[A-Za-z_]\w*\+?=/u;
|
|
31315
|
+
var nameOf = (word) => (word?.split("=")[0] ?? "").replace(/\+$/u, "");
|
|
31316
|
+
var named = (word) => IDENTITY.test(nameOf(word));
|
|
31317
|
+
var stateNamed = (word) => STATE2.test(nameOf(word));
|
|
31318
|
+
var isWorkit = (word) => /^workit(?:-cli)?(?:\.[cm]?js)?$/u.test(base2(word)) || /@workit-dev[\\/]cli\b|workit-cli[\\/](?:dist|src)[\\/]/u.test(word ?? "");
|
|
31319
|
+
var linksToWorkit = (word, cwd) => {
|
|
31320
|
+
const places = /[\\/]/u.test(word) ? [path46.resolve(cwd ?? process.cwd(), word)] : (process.env.PATH ?? "").split(path46.delimiter).map((dir) => path46.join(dir, word));
|
|
31321
|
+
for (const place of places) {
|
|
31322
|
+
try {
|
|
31323
|
+
const real = fs30.realpathSync(place);
|
|
31324
|
+
return isWorkit(real);
|
|
31325
|
+
} catch {}
|
|
31326
|
+
}
|
|
31327
|
+
return false;
|
|
31042
31328
|
};
|
|
31043
|
-
|
|
31044
|
-
|
|
31045
|
-
var
|
|
31046
|
-
|
|
31047
|
-
|
|
31048
|
-
|
|
31049
|
-
|
|
31050
|
-
|
|
31051
|
-
return [];
|
|
31329
|
+
var newSeg = () => ({ identity: null, scoped: null, runs: false, words: [] });
|
|
31330
|
+
var UNREADABLE = "env/unset arguments Workit cannot read";
|
|
31331
|
+
var note = (scan, seg, word) => {
|
|
31332
|
+
if (scan.identity && named(word)) {
|
|
31333
|
+
if (seg)
|
|
31334
|
+
seg.identity ??= nameOf(word);
|
|
31335
|
+
else
|
|
31336
|
+
scan.hit ??= nameOf(word);
|
|
31052
31337
|
}
|
|
31053
|
-
|
|
31054
|
-
|
|
31338
|
+
if (!stateNamed(word) && !(scan.identity && HOST_VARIABLE.test(nameOf(word))))
|
|
31339
|
+
return;
|
|
31340
|
+
if (seg)
|
|
31341
|
+
seg.scoped ??= nameOf(word);
|
|
31342
|
+
else
|
|
31343
|
+
scan.shell ??= nameOf(word);
|
|
31344
|
+
};
|
|
31345
|
+
var mayBeWorkit = (words, cwd) => words.some(({ word, built }) => built || linksToWorkit(word, cwd));
|
|
31346
|
+
var scanEnv = (words, at, expands, scan, seg, depth) => {
|
|
31347
|
+
const risky = (what) => void (scan.risky ??= what);
|
|
31348
|
+
const unset = (name) => note(scan, seg, name);
|
|
31349
|
+
const split = (line, rest, built) => {
|
|
31350
|
+
if (line === undefined || depth >= 4)
|
|
31351
|
+
return risky(UNREADABLE);
|
|
31352
|
+
if (built || /[$`]/u.test(line))
|
|
31353
|
+
risky(UNREADABLE);
|
|
31354
|
+
const tokens = [];
|
|
31355
|
+
const expanded = new Set;
|
|
31055
31356
|
try {
|
|
31056
|
-
const
|
|
31057
|
-
|
|
31058
|
-
|
|
31059
|
-
|
|
31060
|
-
|
|
31061
|
-
|
|
31062
|
-
|
|
31063
|
-
|
|
31064
|
-
|
|
31065
|
-
|
|
31357
|
+
for (const segment of segmentsOf(line)) {
|
|
31358
|
+
for (const index of segment.expands ?? [])
|
|
31359
|
+
expanded.add(tokens.length + index);
|
|
31360
|
+
tokens.push(...segment.words);
|
|
31361
|
+
}
|
|
31362
|
+
} catch {
|
|
31363
|
+
return risky(UNREADABLE);
|
|
31364
|
+
}
|
|
31365
|
+
scanEnv([...tokens, ...words.slice(rest)], 0, expanded, scan, seg, depth + 1);
|
|
31366
|
+
};
|
|
31367
|
+
let options = true;
|
|
31368
|
+
for (let index = at;index < words.length; index += 1) {
|
|
31369
|
+
const word = words[index] ?? "";
|
|
31370
|
+
if (expands.has(index)) {
|
|
31371
|
+
risky(UNREADABLE);
|
|
31372
|
+
const built = options ? /^(?:--split-string=|-[\w]*S)(.+)$/su.exec(word) : null;
|
|
31373
|
+
if (built)
|
|
31374
|
+
return split(built[1], index + 1, true);
|
|
31375
|
+
continue;
|
|
31376
|
+
}
|
|
31377
|
+
if (options && word === "--") {
|
|
31378
|
+
options = false;
|
|
31379
|
+
continue;
|
|
31380
|
+
}
|
|
31381
|
+
if (options && word === "-") {
|
|
31382
|
+
risky("env -i");
|
|
31383
|
+
continue;
|
|
31384
|
+
}
|
|
31385
|
+
if (options && word.startsWith("--")) {
|
|
31386
|
+
const [name = "", value] = word.split(/=(.*)/su);
|
|
31387
|
+
if (name === "--ignore-environment")
|
|
31388
|
+
risky("env -i");
|
|
31389
|
+
else if (name === "--unset")
|
|
31390
|
+
unset(value ?? words[index += 1]);
|
|
31391
|
+
else if (name === "--split-string")
|
|
31392
|
+
return split(value ?? words[index + 1], index + (value === undefined ? 2 : 1), expands.has(index + (value === undefined ? 1 : 0)));
|
|
31393
|
+
else if (ENV_LONG_VALUED.has(name))
|
|
31394
|
+
index += value === undefined ? 1 : 0;
|
|
31395
|
+
else if (!ENV_LONG_FLAGS.test(word))
|
|
31396
|
+
risky(UNREADABLE);
|
|
31397
|
+
continue;
|
|
31398
|
+
}
|
|
31399
|
+
if (options && word.startsWith("-") && word.length > 1) {
|
|
31400
|
+
for (let at2 = 1;at2 < word.length; at2 += 1) {
|
|
31401
|
+
const letter = word[at2] ?? "";
|
|
31402
|
+
if (letter === "i")
|
|
31403
|
+
risky("env -i");
|
|
31404
|
+
else if (ENV_FLAGS.has(letter))
|
|
31405
|
+
continue;
|
|
31406
|
+
else if (ENV_VALUED.has(letter)) {
|
|
31407
|
+
const glued = word.slice(at2 + 1);
|
|
31408
|
+
if (!glued)
|
|
31409
|
+
index += 1;
|
|
31410
|
+
const value = glued || words[index];
|
|
31411
|
+
if (letter === "u")
|
|
31412
|
+
unset(value);
|
|
31413
|
+
if (letter === "S")
|
|
31414
|
+
return split(value, index + 1, expands.has(index));
|
|
31415
|
+
break;
|
|
31416
|
+
} else {
|
|
31417
|
+
risky(UNREADABLE);
|
|
31418
|
+
break;
|
|
31419
|
+
}
|
|
31420
|
+
}
|
|
31421
|
+
continue;
|
|
31422
|
+
}
|
|
31423
|
+
if (ASSIGN.test(word)) {
|
|
31424
|
+
unset(word);
|
|
31425
|
+
continue;
|
|
31426
|
+
}
|
|
31427
|
+
return commandAt(words.slice(index), scan, seg, new Set([...expands].filter((at2) => at2 >= index).map((at2) => at2 - index)));
|
|
31066
31428
|
}
|
|
31067
|
-
return plans;
|
|
31068
31429
|
};
|
|
31069
|
-
var
|
|
31070
|
-
|
|
31071
|
-
|
|
31072
|
-
|
|
31073
|
-
|
|
31074
|
-
|
|
31075
|
-
|
|
31076
|
-
|
|
31430
|
+
var commandAt = (words, scan, seg, expands = new Set, from = 0) => {
|
|
31431
|
+
let index = from;
|
|
31432
|
+
while (index < words.length) {
|
|
31433
|
+
while (ASSIGN.test(words[index] ?? "")) {
|
|
31434
|
+
note(scan, seg, words[index]);
|
|
31435
|
+
index += 1;
|
|
31436
|
+
}
|
|
31437
|
+
const name = base2(words[index]).toLowerCase();
|
|
31438
|
+
if (name === "env")
|
|
31439
|
+
return scanEnv(words, index + 1, expands, scan, seg, 0);
|
|
31440
|
+
if (OPAQUE.has(name))
|
|
31441
|
+
return opaque(words.slice(index + 1), scan, seg, true);
|
|
31442
|
+
if (name === "busybox" || name === "toybox") {
|
|
31443
|
+
index += 1;
|
|
31444
|
+
continue;
|
|
31445
|
+
}
|
|
31446
|
+
const takes = WRAPPERS3[name];
|
|
31447
|
+
if (takes === undefined)
|
|
31448
|
+
break;
|
|
31449
|
+
index = pastOptions(words, index + 1, takes);
|
|
31450
|
+
}
|
|
31451
|
+
const word = words[index];
|
|
31452
|
+
if (word === undefined)
|
|
31453
|
+
return;
|
|
31454
|
+
seg.words.push({ word, built: expands.has(index) });
|
|
31455
|
+
const rest = words.slice(index + 1);
|
|
31456
|
+
if (isWorkit(word) || rest.some(isWorkit))
|
|
31457
|
+
seg.runs = true;
|
|
31458
|
+
if (!isWorkit(word) && rest.some((next) => base2(next).toLowerCase() === "env"))
|
|
31459
|
+
opaque(rest, scan, seg, false);
|
|
31460
|
+
const program = base2(word).toLowerCase();
|
|
31461
|
+
const shell = program === "pwsh" || program === "powershell";
|
|
31462
|
+
if (program === "cmd" || shell) {
|
|
31463
|
+
const at = rest.findIndex((next) => shell ? /^-(?:c|command)$/iu.test(next) : /^\/[ck]$/iu.test(next));
|
|
31464
|
+
if (at >= 0) {
|
|
31465
|
+
const script = rest.slice(at + 1).join(" ");
|
|
31466
|
+
const change = shell ? powershellChange(script, scan.identity) : cmdChange(script, scan);
|
|
31467
|
+
if (change)
|
|
31468
|
+
scan.hit ??= change;
|
|
31469
|
+
}
|
|
31470
|
+
}
|
|
31471
|
+
};
|
|
31472
|
+
var opaque = (rest, scan, seg, assigns) => {
|
|
31473
|
+
if (!rest.some(isWorkit))
|
|
31474
|
+
return;
|
|
31475
|
+
seg.runs = true;
|
|
31476
|
+
const changes = (word) => base2(word).toLowerCase() === "env" || DECLARES.has(word) || assigns && ASSIGN.test(word);
|
|
31477
|
+
if (rest.some(changes))
|
|
31478
|
+
scan.risky ??= UNREADABLE;
|
|
31479
|
+
if (rest.some((word) => base2(word).toLowerCase() === "env"))
|
|
31480
|
+
for (const word of rest)
|
|
31481
|
+
note(scan, seg, word);
|
|
31482
|
+
};
|
|
31483
|
+
var LOGIN_VALUED = {
|
|
31484
|
+
su: /[sgGwc]/u,
|
|
31485
|
+
runuser: /[sgGwuc]/u,
|
|
31486
|
+
script: /[cEIOBTmot]/u
|
|
31487
|
+
};
|
|
31488
|
+
var loginScript = (words) => {
|
|
31489
|
+
const at = words.findIndex((word) => /^(?:su|runuser|script)$/u.test(base2(word)));
|
|
31490
|
+
if (at < 0)
|
|
31491
|
+
return null;
|
|
31492
|
+
const valued = LOGIN_VALUED[base2(words[at])] ?? /c/u;
|
|
31493
|
+
for (let index = at + 1;index < words.length; index += 1) {
|
|
31494
|
+
const word = words[index] ?? "";
|
|
31495
|
+
if (word === "--command")
|
|
31496
|
+
return words[index + 1] ?? null;
|
|
31497
|
+
if (word.startsWith("--command="))
|
|
31498
|
+
return word.slice("--command=".length);
|
|
31499
|
+
if (!/^-[^-]/u.test(word))
|
|
31500
|
+
continue;
|
|
31501
|
+
const ends = word.slice(1).search(valued) + 1;
|
|
31502
|
+
if (ends > 0 && word[ends] === "c")
|
|
31503
|
+
return word.slice(ends + 1) || (words[index + 1] ?? null);
|
|
31504
|
+
}
|
|
31505
|
+
return null;
|
|
31077
31506
|
};
|
|
31078
|
-
var
|
|
31079
|
-
|
|
31080
|
-
|
|
31081
|
-
|
|
31507
|
+
var scanCommand = (command, dialect, depth, scan) => {
|
|
31508
|
+
let segments;
|
|
31509
|
+
try {
|
|
31510
|
+
segments = segmentsOf(command, dialect);
|
|
31511
|
+
} catch {
|
|
31512
|
+
return;
|
|
31513
|
+
}
|
|
31514
|
+
for (const { words, expands = [] } of segments) {
|
|
31515
|
+
const expanded = new Set(expands);
|
|
31516
|
+
const seg = newSeg();
|
|
31517
|
+
let at = 0;
|
|
31518
|
+
while (ASSIGN.test(words[at] ?? ""))
|
|
31519
|
+
at += 1;
|
|
31520
|
+
for (const word of words.slice(0, at))
|
|
31521
|
+
note(scan, at === words.length ? null : seg, word);
|
|
31522
|
+
let declare = at;
|
|
31523
|
+
if (["builtin", "command"].includes(words[declare] ?? ""))
|
|
31524
|
+
declare += 1;
|
|
31525
|
+
if (DECLARES.has(words[declare] ?? "")) {
|
|
31526
|
+
for (let index = declare + 1;index < words.length; index += 1) {
|
|
31527
|
+
note(scan, null, words[index]);
|
|
31528
|
+
if (expanded.has(index))
|
|
31529
|
+
scan.risky ??= UNREADABLE;
|
|
31530
|
+
}
|
|
31531
|
+
continue;
|
|
31532
|
+
}
|
|
31533
|
+
commandAt(words, scan, seg, expanded, at);
|
|
31534
|
+
const script = depth < 4 ? shellScript2(words) ?? loginScript(words) : null;
|
|
31535
|
+
if (script) {
|
|
31536
|
+
const before = scan.runs;
|
|
31537
|
+
scan.runs = false;
|
|
31538
|
+
scanCommand(script, dialect, depth + 1, scan);
|
|
31539
|
+
seg.runs ||= scan.runs;
|
|
31540
|
+
scan.runs ||= before;
|
|
31541
|
+
}
|
|
31542
|
+
scan.words.push(...seg.words);
|
|
31543
|
+
const reaches = () => seg.runs || mayBeWorkit(seg.words, scan.cwd);
|
|
31544
|
+
if (seg.identity && reaches())
|
|
31545
|
+
scan.hit ??= seg.identity;
|
|
31546
|
+
if (seg.scoped && reaches())
|
|
31547
|
+
scan.state ??= seg.scoped;
|
|
31548
|
+
scan.runs ||= seg.runs;
|
|
31549
|
+
}
|
|
31550
|
+
};
|
|
31551
|
+
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);
|
|
31552
|
+
var powershellChange = (command, identity) => {
|
|
31553
|
+
const hit = identity ? POWERSHELL.exec(command)?.[0] : null;
|
|
31554
|
+
if (hit)
|
|
31555
|
+
return hit;
|
|
31556
|
+
if (!RUNS_TEXT.test(command) && !/&\s*[$(]/u.test(command))
|
|
31557
|
+
return null;
|
|
31558
|
+
const state = POWERSHELL_STATE.exec(command)?.[0] ?? (identity ? POWERSHELL_HOST.exec(command)?.[0] : null) ?? cmdChange(command, { identity });
|
|
31559
|
+
if (state)
|
|
31560
|
+
return state;
|
|
31561
|
+
return POWERSHELL_OPAQUE.test(command) ? UNREADABLE : null;
|
|
31562
|
+
};
|
|
31563
|
+
var identityEnvChange = (command, dialect = "posix", options = {}) => {
|
|
31564
|
+
const identity = options.identity ?? true;
|
|
31565
|
+
if (dialect === "powershell")
|
|
31566
|
+
return powershellChange(command, identity);
|
|
31567
|
+
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))
|
|
31568
|
+
return null;
|
|
31569
|
+
const scan = {
|
|
31570
|
+
identity,
|
|
31571
|
+
cwd: options.cwd,
|
|
31572
|
+
hit: null,
|
|
31573
|
+
state: null,
|
|
31574
|
+
shell: null,
|
|
31575
|
+
risky: null,
|
|
31576
|
+
runs: false,
|
|
31577
|
+
words: []
|
|
31578
|
+
};
|
|
31579
|
+
scanCommand(command, dialect, 0, scan);
|
|
31580
|
+
if (scan.hit)
|
|
31581
|
+
return scan.hit;
|
|
31582
|
+
if (scan.state)
|
|
31583
|
+
return scan.state;
|
|
31584
|
+
if (scan.shell && (scan.runs || mayBeWorkit(scan.words, scan.cwd)))
|
|
31585
|
+
return scan.shell;
|
|
31586
|
+
return scan.runs ? scan.risky : null;
|
|
31587
|
+
};
|
|
31588
|
+
|
|
31589
|
+
// packages/workit-core/src/hooks/exit-pipe.ts
|
|
31590
|
+
var EXIT_VERBS = [
|
|
31591
|
+
["ci", "wait"],
|
|
31592
|
+
["check"],
|
|
31593
|
+
["pr", "merge"],
|
|
31594
|
+
["release"],
|
|
31595
|
+
["verify-delivery"]
|
|
31596
|
+
];
|
|
31597
|
+
var base3 = (word = "") => word.split(/[\\/]/u).at(-1) ?? "";
|
|
31598
|
+
var verbPath = (words) => {
|
|
31599
|
+
const path = [];
|
|
31600
|
+
for (let at = 0;at < words.length && path.length < 2; at += 1) {
|
|
31601
|
+
const word = words[at];
|
|
31602
|
+
if (word === "--")
|
|
31603
|
+
break;
|
|
31604
|
+
if (word === "--cwd")
|
|
31605
|
+
at += 1;
|
|
31606
|
+
else if (!word.startsWith("-"))
|
|
31607
|
+
path.push(word);
|
|
31608
|
+
}
|
|
31609
|
+
return path;
|
|
31610
|
+
};
|
|
31611
|
+
var identityAssignment = (name) => identityEnvChange(`${name}=x workit`) !== null;
|
|
31612
|
+
var identityWhy = (names) => names.length ? `
|
|
31613
|
+
Why: the retry leaves out ${names.join(", ")}: the identity guard refuses a workit call that sets ${names.length === 1 ? "it" : "them"}.` : "";
|
|
31614
|
+
var exitCall = (segment, first) => {
|
|
31615
|
+
const { words } = segment;
|
|
31616
|
+
let at = first;
|
|
31617
|
+
while (at < words.length && /^[A-Za-z_]\w*=/u.test(words[at]))
|
|
31618
|
+
at += 1;
|
|
31619
|
+
if (!/^workit(?:-cli)?$/u.test(base3(words[at])))
|
|
31620
|
+
return null;
|
|
31621
|
+
const path = verbPath(words.slice(at + 1));
|
|
31622
|
+
return EXIT_VERBS.some((verb) => verb.every((word, index) => path[index] === word)) ? { segment, first, at } : null;
|
|
31623
|
+
};
|
|
31624
|
+
var backgrounded = (command, segment) => {
|
|
31625
|
+
const ends = [...segment.spans ?? [], ...segment.redirectSpans ?? []].map(([, end]) => end);
|
|
31626
|
+
return /^[ \t]*&(?![&>])/u.test(command.slice(Math.max(0, ...ends)));
|
|
31627
|
+
};
|
|
31628
|
+
var setsPipefail = (words) => words[0] === "set" && words.some((word, at) => word === "pipefail" && /^-[a-z]*o$/u.test(words[at - 1] ?? ""));
|
|
31629
|
+
var range = (from, to) => Array.from({ length: to - from }, (_, i) => from + i);
|
|
31630
|
+
var absoluteCwd = (text, value) => cwdIndependent(text) && (/^(?:\/|[A-Za-z]:[\\/])/u.test(value) || /^~(?:\/|$)/u.test(text));
|
|
31631
|
+
var retryOf = (command, found) => {
|
|
31632
|
+
const { segment, first, at, cd, set } = found;
|
|
31633
|
+
const { words } = segment;
|
|
31634
|
+
const dropped = [];
|
|
31635
|
+
const env = range(first, at).filter((index) => {
|
|
31636
|
+
const name = words[index].slice(0, words[index].indexOf("="));
|
|
31637
|
+
if (!identityAssignment(name))
|
|
31638
|
+
return true;
|
|
31639
|
+
dropped.push(name);
|
|
31640
|
+
return false;
|
|
31641
|
+
});
|
|
31642
|
+
const envText = writtenWords(command, segment, env);
|
|
31643
|
+
const callText = writtenWords(command, segment, range(at + 1, words.length));
|
|
31644
|
+
const dir = cd ? writtenWord(command, cd, 1) : "";
|
|
31645
|
+
if (!envText || !callText || cd === undefined || dir === null)
|
|
31646
|
+
return { retry: null, dropped };
|
|
31647
|
+
const reads = [dir, ...envText, ...callText].flatMap((text) => [...text.matchAll(/\$\{?(\w+)/gu)].map((match) => match[1] ?? "")).find((name) => set.has(name));
|
|
31648
|
+
if (reads)
|
|
31649
|
+
return { retry: null, dropped, reads };
|
|
31650
|
+
const call = words.slice(at + 1);
|
|
31651
|
+
const verbAt = call[0]?.startsWith("-") ? 0 : 1;
|
|
31652
|
+
const plain = (body) => [...envText, "workit", ...body].join(" ");
|
|
31653
|
+
if (!cd)
|
|
31654
|
+
return { retry: plain(callText), dropped };
|
|
31655
|
+
const check = verbPath(call)[0] === "check";
|
|
31656
|
+
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=")));
|
|
31657
|
+
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) => {
|
|
31658
|
+
const text = writtenWord(command, segment, index) ?? "";
|
|
31659
|
+
return absoluteCwd(text.replace(/^--cwd=/u, ""), words[index].replace(/^--cwd=/u, ""));
|
|
31660
|
+
});
|
|
31661
|
+
if (!moves)
|
|
31662
|
+
return { retry: `cd ${dir} && ${plain(callText)}`, dropped };
|
|
31663
|
+
if (cwds.length)
|
|
31664
|
+
return { retry: plain(callText), dropped };
|
|
31665
|
+
return {
|
|
31666
|
+
retry: plain([...callText.slice(0, verbAt), "--cwd", dir, ...callText.slice(verbAt)]),
|
|
31667
|
+
dropped
|
|
31668
|
+
};
|
|
31669
|
+
};
|
|
31670
|
+
function exitPipeGate(command, dialect = "posix") {
|
|
31671
|
+
if (!/\bworkit/u.test(command) || !/\b(?:tail|head)\b/u.test(command))
|
|
31672
|
+
return null;
|
|
31673
|
+
const groups = [];
|
|
31674
|
+
let carry = null;
|
|
31675
|
+
let pipefail = false;
|
|
31676
|
+
let cd = null;
|
|
31677
|
+
const seen = [];
|
|
31678
|
+
const chained = !command.includes("||");
|
|
31679
|
+
for (const segment of segmentsOf(command, dialect, { spans: true })) {
|
|
31680
|
+
if (segment.unanalyzable)
|
|
31681
|
+
return null;
|
|
31682
|
+
let words = segment.words;
|
|
31683
|
+
let closes = segment.group === "close";
|
|
31684
|
+
if (segment.group === "open") {
|
|
31685
|
+
groups.push(null);
|
|
31686
|
+
continue;
|
|
31687
|
+
}
|
|
31688
|
+
if (words[0] === "{") {
|
|
31689
|
+
groups.push(null);
|
|
31690
|
+
words = words.slice(1);
|
|
31691
|
+
} else if (words[0] === "}") {
|
|
31692
|
+
closes = true;
|
|
31693
|
+
words = words.slice(1);
|
|
31694
|
+
}
|
|
31695
|
+
if (closes) {
|
|
31696
|
+
const inner = groups.pop() ?? null;
|
|
31697
|
+
if (segment.group === "close" && cd)
|
|
31698
|
+
cd = undefined;
|
|
31699
|
+
if (inner && groups.length)
|
|
31700
|
+
groups[groups.length - 1] = inner;
|
|
31701
|
+
carry = segment.pipe ? inner ?? carry : null;
|
|
31702
|
+
continue;
|
|
31703
|
+
}
|
|
31704
|
+
if (!words.length && !segment.stdin && !segment.subs)
|
|
31705
|
+
continue;
|
|
31706
|
+
if (setsPipefail(words))
|
|
31707
|
+
pipefail = true;
|
|
31708
|
+
const filter = base3(words[0]);
|
|
31709
|
+
if (carry && !pipefail && (filter === "tail" || filter === "head")) {
|
|
31710
|
+
const { retry, dropped, reads } = retryOf(command, carry);
|
|
31711
|
+
const verb = verbPath(carry.segment.words.slice(carry.at + 1)).join(" ");
|
|
31712
|
+
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.`;
|
|
31713
|
+
return {
|
|
31714
|
+
kind: "deny",
|
|
31715
|
+
reason: `workit exit-pipe: piping \`workit ${verb}\` into ${filter} hides its exit code.
|
|
31716
|
+
${retry ? `Retry as: ${retry}` : why}${identityWhy(dropped)}`,
|
|
31717
|
+
unblock: retry
|
|
31718
|
+
};
|
|
31719
|
+
}
|
|
31720
|
+
const call = exitCall(segment, segment.words.length - words.length);
|
|
31721
|
+
const found = call ? { ...call, cd, set: namesSet(seen) } : null;
|
|
31722
|
+
seen.push(segment);
|
|
31723
|
+
if (found && groups.length)
|
|
31724
|
+
groups[groups.length - 1] = found;
|
|
31725
|
+
carry = segment.pipe ? found ?? carry : null;
|
|
31726
|
+
const clean = chained && words === segment.words && words.length === 2 && !segment.pipe && !backgrounded(command, segment);
|
|
31727
|
+
if (words[0] === "cd")
|
|
31728
|
+
cd = clean && cd === null ? segment : undefined;
|
|
31729
|
+
else if (cd)
|
|
31730
|
+
cd = undefined;
|
|
31731
|
+
}
|
|
31732
|
+
return null;
|
|
31733
|
+
}
|
|
31734
|
+
|
|
31735
|
+
// packages/workit-core/src/hooks/worktree-confine.ts
|
|
31736
|
+
var CASE_INSENSITIVE2 = process.platform === "darwin" || process.platform === "win32";
|
|
31737
|
+
var MUTATING_REMOTE = new Set([
|
|
31738
|
+
"add",
|
|
31739
|
+
"remove",
|
|
31740
|
+
"rm",
|
|
31741
|
+
"rename",
|
|
31742
|
+
"set-url",
|
|
31743
|
+
"set-head",
|
|
31744
|
+
"set-branches",
|
|
31745
|
+
"prune"
|
|
31746
|
+
]);
|
|
31747
|
+
|
|
31748
|
+
// packages/workit-core/src/hooks/steering.ts
|
|
31749
|
+
var ROLES = {
|
|
31750
|
+
implementer: "implementer",
|
|
31751
|
+
verifier: "judge",
|
|
31752
|
+
reviewer: "judge"
|
|
31753
|
+
};
|
|
31754
|
+
var workitRole = (descriptor, agentType) => {
|
|
31755
|
+
const prefix = descriptor.subagents.agentPrefix;
|
|
31756
|
+
const name = agentType.startsWith(prefix) ? agentType.slice(prefix.length) : "";
|
|
31757
|
+
return Object.hasOwn(ROLES, name) ? ROLES[name] : null;
|
|
31758
|
+
};
|
|
31759
|
+
|
|
31760
|
+
// packages/workit-core/src/hooks/standing.ts
|
|
31761
|
+
var readPlans = (store) => {
|
|
31762
|
+
const dir = path47.join(store, "fanouts");
|
|
31763
|
+
let names;
|
|
31764
|
+
try {
|
|
31765
|
+
names = fs31.readdirSync(dir).filter((name) => name.endsWith(".json"));
|
|
31766
|
+
} catch {
|
|
31767
|
+
return [];
|
|
31768
|
+
}
|
|
31769
|
+
const plans = [];
|
|
31770
|
+
for (const name of names) {
|
|
31771
|
+
try {
|
|
31772
|
+
const raw = JSON.parse(fs31.readFileSync(path47.join(dir, name), "utf8"));
|
|
31773
|
+
if (typeof raw.name !== "string" || !Array.isArray(raw.slices))
|
|
31774
|
+
continue;
|
|
31775
|
+
const texts = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string" && item !== "") : [];
|
|
31776
|
+
plans.push({
|
|
31777
|
+
name: raw.name,
|
|
31778
|
+
leads: texts([raw.leadSession, ...texts(raw.formerLeads)]),
|
|
31779
|
+
branches: texts(raw.slices.map((slice) => slice && typeof slice === "object" ? slice.branch : null))
|
|
31780
|
+
});
|
|
31781
|
+
} catch {}
|
|
31782
|
+
}
|
|
31783
|
+
return plans;
|
|
31784
|
+
};
|
|
31785
|
+
var leadOf2 = (input) => input.session.parentId ?? (input.session.agentId ? input.session.id : null) ?? (input.session.id.includes(":") ? input.session.id.split(":")[0] : null);
|
|
31786
|
+
var DESCRIPTORS = {
|
|
31787
|
+
claude_code: CLAUDE_CODE_DESCRIPTOR,
|
|
31788
|
+
opencode: OPENCODE_DESCRIPTOR,
|
|
31789
|
+
codex_cli: codexDescriptor("codex_cli"),
|
|
31790
|
+
codex_desktop: codexDescriptor("codex_desktop"),
|
|
31791
|
+
cursor: CURSOR_DESCRIPTOR,
|
|
31792
|
+
pi: PI_DESCRIPTOR
|
|
31793
|
+
};
|
|
31794
|
+
var workerOfLead = (input) => input.session.agentType === null || workitRole(DESCRIPTORS[input.host], input.session.agentType) !== null;
|
|
31795
|
+
var worksFor = (plan, input, branches) => {
|
|
31796
|
+
const session = input.session.id;
|
|
31797
|
+
if (plan.leads.includes(session) && !input.session.agentId)
|
|
31082
31798
|
return null;
|
|
31083
31799
|
if (branches.some((branch) => plan.branches.includes(branch)))
|
|
31084
31800
|
return "slice";
|
|
@@ -31163,73 +31879,6 @@ var standingSinceStart = (input) => {
|
|
|
31163
31879
|
return null;
|
|
31164
31880
|
}
|
|
31165
31881
|
};
|
|
31166
|
-
// packages/workit-core/src/hooks/cwd-normalize.ts
|
|
31167
|
-
var DIR2 = String.raw`(?:[A-Za-z0-9_./@%+:,=-]|(?<=[A-Za-z0-9])~)+|'[^'$${"`"}\n]*'|"(?:[^"$${"`"}\\!\n]|\\(?=[^"$${"`"}\\!\n]))*"`;
|
|
31168
|
-
var COMPOUND2 = new RegExp(String.raw`^\s*cd\s+(${DIR2})\s*&&\s*(workit(?:\s[\s\S]*)?)$`, "u");
|
|
31169
|
-
var GLOBALS_FIRST = new RegExp(String.raw`^(\s*workit)((?:\s+(?:--json|--cwd(?:=|\s+)(?:${DIR2})))+)\s+([a-z][a-z-]*)(?=\s|$)`, "u");
|
|
31170
|
-
var VERB_FIRST = /^((?:--json\s+)*)([a-z][a-z-]*)(?=\s|$)/u;
|
|
31171
|
-
var VERBS = new Set(WORKIT_ALLOWED_VERBS);
|
|
31172
|
-
var FILTERS = new Set(["tail", "head", "grep"]);
|
|
31173
|
-
var clean = (s) => !s.unanalyzable && !s.group && !s.subs?.length && !s.stdin?.length && !s.redirects.length;
|
|
31174
|
-
var stdinOnly = (words) => {
|
|
31175
|
-
const [name, ...args] = words;
|
|
31176
|
-
const operands = args.filter((w) => !w.startsWith("-"));
|
|
31177
|
-
if (name === "grep")
|
|
31178
|
-
return operands.length <= 1 && !args.some((w) => /^-[^-]*[rRf]|^--(recursive|file)/u.test(w));
|
|
31179
|
-
return operands.every((w) => /^\d+$/u.test(w)) && !args.some((w) => w.startsWith("--output"));
|
|
31180
|
-
};
|
|
31181
|
-
var cwdRewrite = (command) => {
|
|
31182
|
-
const match = COMPOUND2.exec(command);
|
|
31183
|
-
const dir = match?.[1];
|
|
31184
|
-
const rest = match?.[2];
|
|
31185
|
-
if (!dir || !rest || dir.startsWith("-"))
|
|
31186
|
-
return null;
|
|
31187
|
-
if (/[&;<>`\n]/u.test(rest.replaceAll("2>&1", "").replaceAll(/'[^']*'|"([^"\\]|\\.)*"/gu, "")))
|
|
31188
|
-
return null;
|
|
31189
|
-
const segments = segmentsOf(rest);
|
|
31190
|
-
const [head, ...filters] = segments;
|
|
31191
|
-
if (!head || head.words[0] !== "workit")
|
|
31192
|
-
return null;
|
|
31193
|
-
if (!segments.every(clean))
|
|
31194
|
-
return null;
|
|
31195
|
-
if (!segments.slice(0, -1).every((s) => s.pipe))
|
|
31196
|
-
return null;
|
|
31197
|
-
if (!filters.every((s) => FILTERS.has(s.words[0] ?? "") && stdinOnly(s.words)))
|
|
31198
|
-
return null;
|
|
31199
|
-
const at = head.words.indexOf("--cwd");
|
|
31200
|
-
if (at >= 0) {
|
|
31201
|
-
const bare = dir.replace(/^(['"])(.*)\1$/u, "$2");
|
|
31202
|
-
return bare[0] === "/" && head.words[at + 1] === bare ? rest : null;
|
|
31203
|
-
}
|
|
31204
|
-
if (head.words.some((w) => w.startsWith("--cwd=")))
|
|
31205
|
-
return null;
|
|
31206
|
-
const args = rest.slice("workit".length).trimStart();
|
|
31207
|
-
const verb = VERB_FIRST.exec(args);
|
|
31208
|
-
if (!verb?.[2] || !VERBS.has(verb[2]))
|
|
31209
|
-
return `workit --cwd ${dir} ${args}`.trimEnd();
|
|
31210
|
-
const json = verb[1] ? " --json" : "";
|
|
31211
|
-
return `workit ${verb[2]} --cwd ${dir}${json}${args.slice(verb[0].length)}`.trimEnd();
|
|
31212
|
-
};
|
|
31213
|
-
var verbFirst = (command) => {
|
|
31214
|
-
const match = GLOBALS_FIRST.exec(command);
|
|
31215
|
-
const [whole, lead, globals, verb] = match ?? [];
|
|
31216
|
-
if (!whole || !verb || !VERBS.has(verb) || !globals?.includes("--cwd"))
|
|
31217
|
-
return null;
|
|
31218
|
-
const segments = segmentsOf(command);
|
|
31219
|
-
if (segments.length !== 1 || !segments.every(clean))
|
|
31220
|
-
return null;
|
|
31221
|
-
return `${lead} ${verb}${globals}${command.slice(whole.length)}`;
|
|
31222
|
-
};
|
|
31223
|
-
var NPX = new RegExp(String.raw`^(\s*(?:cd\s+(?:${DIR2})\s*&&\s*)?)npx(?:\s+(?:-y|--yes))*\s+@workit-dev\/cli(?:@[\w.-]+)?(?=\s|$)`, "u");
|
|
31224
|
-
var npxWorkit = (command) => {
|
|
31225
|
-
const match = NPX.exec(command);
|
|
31226
|
-
if (!match)
|
|
31227
|
-
return null;
|
|
31228
|
-
const call = `${match[1]}workit${command.slice(match[0].length)}`;
|
|
31229
|
-
const left = segmentsOf(call).some((s) => s.unanalyzable || s.words.some((w) => /^(npx|@workit-dev\/cli(@\S*)?)$/u.test(w)));
|
|
31230
|
-
return left ? null : cwdRewrite(call) ?? verbFirst(call) ?? call;
|
|
31231
|
-
};
|
|
31232
|
-
|
|
31233
31882
|
// packages/workit-core/src/hooks/model-limit.ts
|
|
31234
31883
|
var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
31235
31884
|
var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
@@ -31371,9 +32020,9 @@ var SCAN_MS = 30 * 60000;
|
|
|
31371
32020
|
var UNLISTED = new Set(["description", "prompt"]);
|
|
31372
32021
|
|
|
31373
32022
|
// packages/workit-core/src/hooks/server-gate.ts
|
|
31374
|
-
import
|
|
31375
|
-
import
|
|
31376
|
-
var procNoticeFile = (env, session) =>
|
|
32023
|
+
import fs32 from "node:fs";
|
|
32024
|
+
import path48 from "node:path";
|
|
32025
|
+
var procNoticeFile = (env, session) => path48.join(stateDir(env), "procs", "notices", `${session.replace(/[^A-Za-z0-9_.@+-]/gu, "-").slice(0, 120) || "none"}.json`);
|
|
31377
32026
|
var mb = (bytes) => `${Math.round(Number(bytes) / 1048576)} MB`;
|
|
31378
32027
|
function takeProcNotice(session, env = process.env) {
|
|
31379
32028
|
if (!session)
|
|
@@ -31381,12 +32030,12 @@ function takeProcNotice(session, env = process.env) {
|
|
|
31381
32030
|
const file = procNoticeFile(env, session);
|
|
31382
32031
|
const taken = `${file}.${process.pid}.taken`;
|
|
31383
32032
|
try {
|
|
31384
|
-
|
|
32033
|
+
fs32.renameSync(file, taken);
|
|
31385
32034
|
} catch {
|
|
31386
32035
|
return null;
|
|
31387
32036
|
}
|
|
31388
32037
|
try {
|
|
31389
|
-
const { notices } = JSON.parse(
|
|
32038
|
+
const { notices } = JSON.parse(fs32.readFileSync(taken, "utf8"));
|
|
31390
32039
|
const lines = (Array.isArray(notices) ? notices : []).flatMap((notice) => {
|
|
31391
32040
|
if (!notice || typeof notice !== "object")
|
|
31392
32041
|
return [];
|
|
@@ -31403,29 +32052,29 @@ function takeProcNotice(session, env = process.env) {
|
|
|
31403
32052
|
return null;
|
|
31404
32053
|
} finally {
|
|
31405
32054
|
try {
|
|
31406
|
-
|
|
32055
|
+
fs32.rmSync(taken, { force: true });
|
|
31407
32056
|
} catch {}
|
|
31408
32057
|
}
|
|
31409
32058
|
}
|
|
31410
32059
|
|
|
31411
32060
|
// packages/workit-core/src/hooks/teardown.ts
|
|
31412
32061
|
import { spawn } from "node:child_process";
|
|
31413
|
-
import
|
|
31414
|
-
import
|
|
32062
|
+
import fs33 from "node:fs";
|
|
32063
|
+
import path50 from "node:path";
|
|
31415
32064
|
|
|
31416
32065
|
// packages/workit-core/src/core/cli-locate.ts
|
|
31417
32066
|
import { closeSync as closeSync3, existsSync as existsSync17, openSync as openSync3, readSync } from "node:fs";
|
|
31418
|
-
import
|
|
32067
|
+
import path49 from "node:path";
|
|
31419
32068
|
var LAUNCHER_MARKER = "workit-owned-launcher";
|
|
31420
32069
|
var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
|
|
31421
32070
|
var installRoot = (env, platform = process.platform) => {
|
|
31422
32071
|
if (env.WORKIT_INSTALL_ROOT)
|
|
31423
32072
|
return env.WORKIT_INSTALL_ROOT;
|
|
31424
32073
|
const data = dataDir(env, platform);
|
|
31425
|
-
return platform === "win32" ?
|
|
32074
|
+
return platform === "win32" ? path49.join(data, "install") : data;
|
|
31426
32075
|
};
|
|
31427
|
-
var ownedLauncherPath = (env, platform = process.platform) =>
|
|
31428
|
-
var ownedCurrentEntry = (env, platform = process.platform) =>
|
|
32076
|
+
var ownedLauncherPath = (env, platform = process.platform) => path49.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
|
|
32077
|
+
var ownedCurrentEntry = (env, platform = process.platform) => path49.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
|
|
31429
32078
|
var head = (file) => {
|
|
31430
32079
|
let fd;
|
|
31431
32080
|
try {
|
|
@@ -31452,7 +32101,7 @@ var locateWorkitCli = (options = {}) => {
|
|
|
31452
32101
|
source: "owned-launcher",
|
|
31453
32102
|
command: launcher,
|
|
31454
32103
|
args: [],
|
|
31455
|
-
binDir:
|
|
32104
|
+
binDir: path49.dirname(launcher)
|
|
31456
32105
|
};
|
|
31457
32106
|
const current = ownedCurrentEntry(env, platform);
|
|
31458
32107
|
if (exists(current))
|
|
@@ -31481,7 +32130,7 @@ var workitCliEnv = (located, env = process.env, platform = process.platform) =>
|
|
|
31481
32130
|
if (located.binDir) {
|
|
31482
32131
|
const key = pathKey(env);
|
|
31483
32132
|
const delimiter = platform === "win32" ? ";" : ":";
|
|
31484
|
-
const same = (dir) => platform === "win32" ?
|
|
32133
|
+
const same = (dir) => platform === "win32" ? path49.win32.normalize(dir).toLowerCase() === path49.win32.normalize(located.binDir).toLowerCase() : path49.posix.normalize(dir) === path49.posix.normalize(located.binDir);
|
|
31485
32134
|
const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
|
|
31486
32135
|
patch[key] = [located.binDir, ...rest].join(delimiter);
|
|
31487
32136
|
}
|
|
@@ -31505,9 +32154,9 @@ var ENDS = {
|
|
|
31505
32154
|
};
|
|
31506
32155
|
var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
|
|
31507
32156
|
var HOST_SESSION_VARS2 = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
|
|
31508
|
-
var teardownDir = (env) =>
|
|
31509
|
-
var teardownLog = (env) =>
|
|
31510
|
-
var reapStamp = (env) =>
|
|
32157
|
+
var teardownDir = (env) => path50.join(stateDir(env), "procs");
|
|
32158
|
+
var teardownLog = (env) => path50.join(teardownDir(env), "teardown.log");
|
|
32159
|
+
var reapStamp = (env) => path50.join(teardownDir(env), "reap-at-start.stamp");
|
|
31511
32160
|
function spawnDetached(request) {
|
|
31512
32161
|
try {
|
|
31513
32162
|
const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
|
|
@@ -31534,13 +32183,13 @@ var teardownDeps = {
|
|
|
31534
32183
|
var openLog = (env, args) => {
|
|
31535
32184
|
try {
|
|
31536
32185
|
const file = teardownLog(env);
|
|
31537
|
-
|
|
32186
|
+
fs33.mkdirSync(path50.dirname(file), { recursive: true });
|
|
31538
32187
|
let size = 0;
|
|
31539
32188
|
try {
|
|
31540
|
-
size =
|
|
32189
|
+
size = fs33.statSync(file).size;
|
|
31541
32190
|
} catch {}
|
|
31542
|
-
const fd =
|
|
31543
|
-
|
|
32191
|
+
const fd = fs33.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
|
|
32192
|
+
fs33.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
|
|
31544
32193
|
`);
|
|
31545
32194
|
return fd;
|
|
31546
32195
|
} catch {
|
|
@@ -31552,7 +32201,7 @@ function runCli(args, env) {
|
|
|
31552
32201
|
try {
|
|
31553
32202
|
const cli = locateWorkitCli({ env });
|
|
31554
32203
|
const cwd = teardownDir(env);
|
|
31555
|
-
|
|
32204
|
+
fs33.mkdirSync(cwd, { recursive: true });
|
|
31556
32205
|
log = openLog(env, args);
|
|
31557
32206
|
const started = teardownDeps.spawn({
|
|
31558
32207
|
command: cli.command,
|
|
@@ -31562,7 +32211,7 @@ function runCli(args, env) {
|
|
|
31562
32211
|
log
|
|
31563
32212
|
});
|
|
31564
32213
|
if (!started && log !== null)
|
|
31565
|
-
|
|
32214
|
+
fs33.writeSync(log, ` not started
|
|
31566
32215
|
`);
|
|
31567
32216
|
return started;
|
|
31568
32217
|
} catch {
|
|
@@ -31570,7 +32219,7 @@ function runCli(args, env) {
|
|
|
31570
32219
|
} finally {
|
|
31571
32220
|
if (log !== null)
|
|
31572
32221
|
try {
|
|
31573
|
-
|
|
32222
|
+
fs33.closeSync(log);
|
|
31574
32223
|
} catch {}
|
|
31575
32224
|
}
|
|
31576
32225
|
}
|
|
@@ -31589,24 +32238,24 @@ function endSession(end, env = process.env) {
|
|
|
31589
32238
|
var claim2 = (file, now) => {
|
|
31590
32239
|
for (let attempt = 0;attempt < 2; attempt += 1)
|
|
31591
32240
|
try {
|
|
31592
|
-
|
|
32241
|
+
fs33.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
|
|
31593
32242
|
return true;
|
|
31594
32243
|
} catch (error) {
|
|
31595
32244
|
if (error.code !== "EEXIST")
|
|
31596
32245
|
return false;
|
|
31597
32246
|
let held = Number.NaN;
|
|
31598
32247
|
try {
|
|
31599
|
-
held = Number(
|
|
32248
|
+
held = Number(fs33.readFileSync(file, "utf8"));
|
|
31600
32249
|
} catch {}
|
|
31601
32250
|
if (now - held < REAP_INTERVAL_MS)
|
|
31602
32251
|
return false;
|
|
31603
|
-
|
|
32252
|
+
fs33.rmSync(file, { force: true });
|
|
31604
32253
|
}
|
|
31605
32254
|
return false;
|
|
31606
32255
|
};
|
|
31607
32256
|
var fresh = (stamp, now) => {
|
|
31608
32257
|
try {
|
|
31609
|
-
const last = Number(
|
|
32258
|
+
const last = Number(fs33.readFileSync(stamp, "utf8"));
|
|
31610
32259
|
return now - last < REAP_INTERVAL_MS && last <= now;
|
|
31611
32260
|
} catch {
|
|
31612
32261
|
return false;
|
|
@@ -31619,7 +32268,7 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
31619
32268
|
try {
|
|
31620
32269
|
if (fresh(stamp, now))
|
|
31621
32270
|
return false;
|
|
31622
|
-
|
|
32271
|
+
fs33.mkdirSync(path50.dirname(stamp), { recursive: true });
|
|
31623
32272
|
if (!claim2(lock, now))
|
|
31624
32273
|
return false;
|
|
31625
32274
|
} catch {
|
|
@@ -31632,12 +32281,12 @@ function reapAtStart(_cwd, env = process.env) {
|
|
|
31632
32281
|
started = runCli(["stop", "--orphans", "--reason", "session-start"], env);
|
|
31633
32282
|
if (started) {
|
|
31634
32283
|
const temp = `${stamp}.${process.pid}`;
|
|
31635
|
-
|
|
31636
|
-
|
|
32284
|
+
fs33.writeFileSync(temp, String(now), { mode: 384 });
|
|
32285
|
+
fs33.renameSync(temp, stamp);
|
|
31637
32286
|
}
|
|
31638
32287
|
} catch {} finally {
|
|
31639
32288
|
try {
|
|
31640
|
-
|
|
32289
|
+
fs33.rmSync(lock, { force: true });
|
|
31641
32290
|
} catch {}
|
|
31642
32291
|
}
|
|
31643
32292
|
return started;
|
|
@@ -32216,98 +32865,6 @@ Retry as: ${retry}` : ""}`,
|
|
|
32216
32865
|
};
|
|
32217
32866
|
};
|
|
32218
32867
|
|
|
32219
|
-
// packages/workit-core/src/hooks/exit-pipe.ts
|
|
32220
|
-
var EXIT_VERBS = [
|
|
32221
|
-
["ci", "wait"],
|
|
32222
|
-
["check"],
|
|
32223
|
-
["pr", "merge"],
|
|
32224
|
-
["release"],
|
|
32225
|
-
["verify-delivery"]
|
|
32226
|
-
];
|
|
32227
|
-
var base2 = (word = "") => word.split(/[\\/]/u).at(-1) ?? "";
|
|
32228
|
-
var quote3 = (word) => /^[\w@%+=:,./-]+$/u.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
|
|
32229
|
-
var verbPath = (words) => {
|
|
32230
|
-
const path = [];
|
|
32231
|
-
for (let at = 0;at < words.length && path.length < 2; at += 1) {
|
|
32232
|
-
const word = words[at];
|
|
32233
|
-
if (word === "--")
|
|
32234
|
-
break;
|
|
32235
|
-
if (word === "--cwd")
|
|
32236
|
-
at += 1;
|
|
32237
|
-
else if (!word.startsWith("-"))
|
|
32238
|
-
path.push(word);
|
|
32239
|
-
}
|
|
32240
|
-
return path;
|
|
32241
|
-
};
|
|
32242
|
-
var exitCall = (words) => {
|
|
32243
|
-
let at = 0;
|
|
32244
|
-
while (at < words.length && /^[A-Za-z_]\w*=/u.test(words[at]))
|
|
32245
|
-
at += 1;
|
|
32246
|
-
if (!/^workit(?:-cli)?$/u.test(base2(words[at])))
|
|
32247
|
-
return null;
|
|
32248
|
-
const path = verbPath(words.slice(at + 1));
|
|
32249
|
-
return EXIT_VERBS.some((verb) => verb.every((word, index) => path[index] === word)) ? words.slice(at) : null;
|
|
32250
|
-
};
|
|
32251
|
-
var setsPipefail = (words) => words[0] === "set" && words.some((word, at) => word === "pipefail" && /^-[a-z]*o$/u.test(words[at - 1] ?? ""));
|
|
32252
|
-
var retryOf = ({ call, dir }) => {
|
|
32253
|
-
const at = call[1]?.startsWith("-") ? 1 : 2;
|
|
32254
|
-
const words = dir && !call.includes("--cwd") ? [...call.slice(0, at), "--cwd", dir, ...call.slice(at)] : call;
|
|
32255
|
-
return ["workit", ...words.slice(1)].map(quote3).join(" ");
|
|
32256
|
-
};
|
|
32257
|
-
function exitPipeGate(command, dialect = "posix") {
|
|
32258
|
-
if (!/\bworkit/u.test(command) || !/\b(?:tail|head)\b/u.test(command))
|
|
32259
|
-
return null;
|
|
32260
|
-
const groups = [];
|
|
32261
|
-
let carry = null;
|
|
32262
|
-
let pipefail = false;
|
|
32263
|
-
let dir = null;
|
|
32264
|
-
for (const segment of segmentsOf(command, dialect)) {
|
|
32265
|
-
if (segment.unanalyzable)
|
|
32266
|
-
return null;
|
|
32267
|
-
let words = segment.words;
|
|
32268
|
-
let closes = segment.group === "close";
|
|
32269
|
-
if (segment.group === "open") {
|
|
32270
|
-
groups.push(null);
|
|
32271
|
-
continue;
|
|
32272
|
-
}
|
|
32273
|
-
if (words[0] === "{") {
|
|
32274
|
-
groups.push(null);
|
|
32275
|
-
words = words.slice(1);
|
|
32276
|
-
} else if (words[0] === "}") {
|
|
32277
|
-
closes = true;
|
|
32278
|
-
words = words.slice(1);
|
|
32279
|
-
}
|
|
32280
|
-
if (closes) {
|
|
32281
|
-
const inner = groups.pop() ?? null;
|
|
32282
|
-
if (inner && groups.length)
|
|
32283
|
-
groups[groups.length - 1] = inner;
|
|
32284
|
-
carry = segment.pipe ? inner ?? carry : null;
|
|
32285
|
-
continue;
|
|
32286
|
-
}
|
|
32287
|
-
if (!words.length && !segment.stdin && !segment.subs)
|
|
32288
|
-
continue;
|
|
32289
|
-
if (setsPipefail(words))
|
|
32290
|
-
pipefail = true;
|
|
32291
|
-
const filter = base2(words[0]);
|
|
32292
|
-
if (carry && !pipefail && (filter === "tail" || filter === "head")) {
|
|
32293
|
-
const retry = retryOf(carry);
|
|
32294
|
-
return {
|
|
32295
|
-
kind: "deny",
|
|
32296
|
-
reason: `workit exit-pipe: piping \`workit ${verbPath(carry.call.slice(1)).join(" ")}\` into ${filter} hides its exit code.
|
|
32297
|
-
Retry as: ${retry}`,
|
|
32298
|
-
unblock: retry
|
|
32299
|
-
};
|
|
32300
|
-
}
|
|
32301
|
-
const call = exitCall(words);
|
|
32302
|
-
const found = call ? { call, dir } : null;
|
|
32303
|
-
if (found && groups.length)
|
|
32304
|
-
groups[groups.length - 1] = found;
|
|
32305
|
-
carry = segment.pipe ? found ?? carry : null;
|
|
32306
|
-
dir = words.length === 2 && words[0] === "cd" && !segment.expands?.length ? words[1] : null;
|
|
32307
|
-
}
|
|
32308
|
-
return null;
|
|
32309
|
-
}
|
|
32310
|
-
|
|
32311
32868
|
// packages/workit-core/src/hooks/stamp-hint.ts
|
|
32312
32869
|
var STATE_NAME = "(?:WORKIT_(?:STATE_DIR|CONFIG)\\w*|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA|OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
32313
32870
|
var STATE_ENV = new RegExp(`${STATE_NAME}\\s*\\+?=|(?:unset|-u|--unset)[\\s=]+${STATE_NAME}|env:|EnvironmentVariable`, "iu");
|
|
@@ -32360,50 +32917,6 @@ var KEYWORDS3 = new Set([
|
|
|
32360
32917
|
]);
|
|
32361
32918
|
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(" "));
|
|
32362
32919
|
|
|
32363
|
-
// packages/workit-core/src/hooks/identity-env.ts
|
|
32364
|
-
var NAMES = "WORKIT_(?:AGENT_ID|HOST|SESSION_ID|SESSION_TOKEN)";
|
|
32365
|
-
var IDENTITY = new RegExp(`^${NAMES}$`, "u");
|
|
32366
|
-
var HOST_NAMES = "(?:OPENCODE_SESSION_ID|PI_SESSION_ID|CODEX_THREAD_ID|CLAUDECODE|CLAUDE_CODE_ENTRYPOINT)";
|
|
32367
|
-
var HOST_VARIABLE = new RegExp(`^${HOST_NAMES}$`, "u");
|
|
32368
|
-
var IDENTITY_ANY = new RegExp(NAMES, "iu");
|
|
32369
|
-
var STATE_NAMES = "(?:WORKIT_(?:STATE_DIR|CONFIG(?:_DIR)?)|XDG_(?:STATE|CONFIG|DATA)_HOME|HOME|USERPROFILE|(?:LOCAL)?APPDATA)";
|
|
32370
|
-
var STATE2 = new RegExp(`^${STATE_NAMES}$`, "u");
|
|
32371
|
-
var STATE_ANY = new RegExp(STATE_NAMES, "iu");
|
|
32372
|
-
var powershell = (names) => new RegExp([
|
|
32373
|
-
`\\$\\{?env:${names}\\}?\\s*(?:[-+*/]|\\?\\?)?=(?!=)`,
|
|
32374
|
-
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?${names}\\b`,
|
|
32375
|
-
`SetEnvironmentVariable\\(\\s*['"]${names}\\b`
|
|
32376
|
-
].join("|"), "iu");
|
|
32377
|
-
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";
|
|
32378
|
-
var POWERSHELL = powershell(NAMES);
|
|
32379
|
-
var POWERSHELL_STATE = powershell(STATE_NAMES);
|
|
32380
|
-
var POWERSHELL_HOST = powershell(HOST_NAMES);
|
|
32381
|
-
var POWERSHELL_OPAQUE = new RegExp([
|
|
32382
|
-
`SetEnvironmentVariable\\(\\s*(?:[^'"\\s]|"[^"]*\\$)`,
|
|
32383
|
-
`${PS_ITEM}[^;|\\n]*?(?<![$\\w{])env:[\\\\/]?["']?[$(]`,
|
|
32384
|
-
`(?:^|[;&|{(\\n])\\s*\\.\\s+[^\\s.]`,
|
|
32385
|
-
`\\b(?:iex|Invoke-Expression)\\b`
|
|
32386
|
-
].join("|"), "iu");
|
|
32387
|
-
var cmdSet = (names) => new RegExp(`(?:^|[&|(\\s"])set\\s+(?:/[ap]\\s+)?"?(${names})\\s*\\+?=`, "iu");
|
|
32388
|
-
var CMD_IDENTITY = cmdSet(NAMES);
|
|
32389
|
-
var CMD_STATE = cmdSet(STATE_NAMES);
|
|
32390
|
-
var CMD_HOST = cmdSet(HOST_NAMES);
|
|
32391
|
-
var DECLARES = new Set(["export", "unset", "declare", "typeset", "local", "readonly"]);
|
|
32392
|
-
var OPAQUE = new Set([
|
|
32393
|
-
"watch",
|
|
32394
|
-
"strace",
|
|
32395
|
-
"chroot",
|
|
32396
|
-
"flock",
|
|
32397
|
-
"ssh",
|
|
32398
|
-
"su",
|
|
32399
|
-
"runuser",
|
|
32400
|
-
"script",
|
|
32401
|
-
"parallel"
|
|
32402
|
-
]);
|
|
32403
|
-
var ENV_VALUED = new Set(["u", "C", "S", "a", "P"]);
|
|
32404
|
-
var ENV_FLAGS = new Set(["i", "0", "v"]);
|
|
32405
|
-
var ENV_LONG_VALUED = new Set(["--unset", "--chdir", "--split-string", "--argv0"]);
|
|
32406
|
-
|
|
32407
32920
|
// packages/workit-core/src/hooks/handle.ts
|
|
32408
32921
|
var offered = new Set;
|
|
32409
32922
|
var PRE_TOOL = new Set(["shell.pre", "write.pre", "tool.pre"]);
|
|
@@ -32421,11 +32934,11 @@ var PROCESS_START = performance.timeOrigin;
|
|
|
32421
32934
|
// packages/workit-core/src/hooks/run.ts
|
|
32422
32935
|
if (false) {}
|
|
32423
32936
|
// packages/workit-opencode/src/shared/init-apply.ts
|
|
32424
|
-
import
|
|
32937
|
+
import path56 from "node:path";
|
|
32425
32938
|
|
|
32426
32939
|
// packages/workit-core/src/core/gitignore.ts
|
|
32427
32940
|
import { existsSync as existsSync18, readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "node:fs";
|
|
32428
|
-
import
|
|
32941
|
+
import path51 from "node:path";
|
|
32429
32942
|
var GITIGNORE_ENTRIES = [
|
|
32430
32943
|
"# workit: SDD working state (never commit)",
|
|
32431
32944
|
"docs/*/sdd/",
|
|
@@ -32445,7 +32958,7 @@ var GITIGNORE_ENTRIES = [
|
|
|
32445
32958
|
var ensureProjectGitignore = (workspaceRoot, confirmed) => {
|
|
32446
32959
|
if (!confirmed)
|
|
32447
32960
|
return { ok: false, error: "confirmed: true required" };
|
|
32448
|
-
const file =
|
|
32961
|
+
const file = path51.join(workspaceRoot, ".gitignore");
|
|
32449
32962
|
const existing = existsSync18(file) ? readFileSync13(file, "utf8") : "";
|
|
32450
32963
|
const existingLines = new Set(existing.split(`
|
|
32451
32964
|
`).map((l) => l.trim()).filter(Boolean));
|
|
@@ -32473,7 +32986,7 @@ var ensureProjectGitignore = (workspaceRoot, confirmed) => {
|
|
|
32473
32986
|
|
|
32474
32987
|
// packages/workit-core/src/core/hygiene.ts
|
|
32475
32988
|
import { existsSync as existsSync20, readFileSync as readFileSync15, readdirSync as readdirSync8, writeFileSync as writeFileSync8 } from "node:fs";
|
|
32476
|
-
import
|
|
32989
|
+
import path53 from "node:path";
|
|
32477
32990
|
|
|
32478
32991
|
// packages/workit-core/src/git/ops.ts
|
|
32479
32992
|
import { spawnSync as spawnSync25 } from "node:child_process";
|
|
@@ -32486,7 +32999,7 @@ import {
|
|
|
32486
32999
|
rmSync as rmSync3,
|
|
32487
33000
|
writeFileSync as writeFileSync7
|
|
32488
33001
|
} from "node:fs";
|
|
32489
|
-
import
|
|
33002
|
+
import path52 from "node:path";
|
|
32490
33003
|
var COMMIT_TIMEOUT_MS = 10 * 60000;
|
|
32491
33004
|
var git5 = (cwd, args, options = {}) => {
|
|
32492
33005
|
const result = spawnSync25("git", args, {
|
|
@@ -32519,18 +33032,18 @@ function operationInProgress(cwd) {
|
|
|
32519
33032
|
if (!run.ok)
|
|
32520
33033
|
return null;
|
|
32521
33034
|
const found = run.stdout.split(`
|
|
32522
|
-
`).map((line) =>
|
|
33035
|
+
`).map((line) => path52.resolve(cwd, line.trim()));
|
|
32523
33036
|
const conflicted = () => git5(cwd, ["ls-files", "-u"]).stdout.trim() !== "";
|
|
32524
33037
|
for (const [index, [, operation]] of markers.entries()) {
|
|
32525
33038
|
const marker = found[index];
|
|
32526
33039
|
if (!marker || !existsSync19(marker))
|
|
32527
33040
|
continue;
|
|
32528
|
-
if (index === 1 && existsSync19(
|
|
33041
|
+
if (index === 1 && existsSync19(path52.join(marker, "applying")))
|
|
32529
33042
|
return { operation: "am", commitAllowed: false, branch: null };
|
|
32530
|
-
if (index === 0 && existsSync19(
|
|
33043
|
+
if (index === 0 && existsSync19(path52.join(marker, "amend")) && !conflicted()) {
|
|
32531
33044
|
let headName = "";
|
|
32532
33045
|
try {
|
|
32533
|
-
headName = readFileSync14(
|
|
33046
|
+
headName = readFileSync14(path52.join(marker, "head-name"), "utf8").trim();
|
|
32534
33047
|
} catch {}
|
|
32535
33048
|
const branch = headName.startsWith("refs/heads/") ? headName.slice("refs/heads/".length) : null;
|
|
32536
33049
|
return { operation, commitAllowed: branch !== null, branch };
|
|
@@ -32585,23 +33098,23 @@ var BATCH_BYTES = 16 * 1024 * 1024;
|
|
|
32585
33098
|
|
|
32586
33099
|
// packages/workit-core/src/core/hygiene.ts
|
|
32587
33100
|
var repoRoot3 = assetRoot();
|
|
32588
|
-
var templatesDir = () =>
|
|
33101
|
+
var templatesDir = () => path53.join(repoRoot3, "templates", "hygiene");
|
|
32589
33102
|
var packageJson2 = (root) => {
|
|
32590
|
-
if (!existsSync20(
|
|
33103
|
+
if (!existsSync20(path53.join(root, "package.json")))
|
|
32591
33104
|
return null;
|
|
32592
33105
|
try {
|
|
32593
|
-
return JSON.parse(readFileSync15(
|
|
33106
|
+
return JSON.parse(readFileSync15(path53.join(root, "package.json"), "utf8"));
|
|
32594
33107
|
} catch {
|
|
32595
33108
|
return null;
|
|
32596
33109
|
}
|
|
32597
33110
|
};
|
|
32598
33111
|
var isOpenSource = (root) => {
|
|
32599
|
-
if (existsSync20(
|
|
33112
|
+
if (existsSync20(path53.join(root, "LICENSE")))
|
|
32600
33113
|
return true;
|
|
32601
33114
|
const pkg = packageJson2(root);
|
|
32602
33115
|
if (pkg && !pkg.private)
|
|
32603
33116
|
return true;
|
|
32604
|
-
return
|
|
33117
|
+
return path53.basename(root) === "workit";
|
|
32605
33118
|
};
|
|
32606
33119
|
var licenseHolder = (root) => {
|
|
32607
33120
|
const pkg = packageJson2(root);
|
|
@@ -32624,13 +33137,13 @@ var planHygieneFiles = (root, opts = {}) => {
|
|
|
32624
33137
|
files.push("LICENSE", "CONTRIBUTING.md");
|
|
32625
33138
|
const planned = [];
|
|
32626
33139
|
for (const file of files) {
|
|
32627
|
-
if (existsSync20(
|
|
33140
|
+
if (existsSync20(path53.join(root, file)))
|
|
32628
33141
|
continue;
|
|
32629
|
-
const tpl =
|
|
33142
|
+
const tpl = path53.join(templatesDir(), file);
|
|
32630
33143
|
if (!existsSync20(tpl))
|
|
32631
33144
|
continue;
|
|
32632
|
-
const content = readFileSync15(tpl, "utf8").replace(/<PROJECT>/g,
|
|
32633
|
-
planned.push({ path:
|
|
33145
|
+
const content = readFileSync15(tpl, "utf8").replace(/<PROJECT>/g, path53.basename(root)).replace(/<YEAR>/g, String(new Date().getFullYear())).replace(/<HOLDER>\s*/g, licenseHolder(root));
|
|
33146
|
+
planned.push({ path: path53.join(root, file), content });
|
|
32634
33147
|
}
|
|
32635
33148
|
return planned;
|
|
32636
33149
|
};
|
|
@@ -32640,19 +33153,19 @@ var ensureHygieneFiles = (root, opts) => {
|
|
|
32640
33153
|
const created = [];
|
|
32641
33154
|
for (const planned of planHygieneFiles(root, opts)) {
|
|
32642
33155
|
writeFileSync8(planned.path, planned.content, "utf8");
|
|
32643
|
-
created.push(
|
|
33156
|
+
created.push(path53.basename(planned.path));
|
|
32644
33157
|
}
|
|
32645
33158
|
return { ok: true, created };
|
|
32646
33159
|
};
|
|
32647
33160
|
|
|
32648
33161
|
// packages/workit-core/src/core/init.ts
|
|
32649
|
-
import
|
|
32650
|
-
import
|
|
33162
|
+
import fs34 from "node:fs";
|
|
33163
|
+
import path55 from "node:path";
|
|
32651
33164
|
import { spawnSync as spawnSync26 } from "node:child_process";
|
|
32652
33165
|
|
|
32653
33166
|
// packages/workit-core/src/core/workspace-branch-policy.ts
|
|
32654
33167
|
import { mkdirSync as mkdirSync7, readFileSync as readFileSync16, renameSync as renameSync5, rmSync as rmSync4, writeFileSync as writeFileSync9 } from "node:fs";
|
|
32655
|
-
import
|
|
33168
|
+
import path54 from "node:path";
|
|
32656
33169
|
import { isDeepStrictEqual } from "node:util";
|
|
32657
33170
|
var readFileSafe = (p) => {
|
|
32658
33171
|
try {
|
|
@@ -32663,7 +33176,7 @@ var readFileSafe = (p) => {
|
|
|
32663
33176
|
};
|
|
32664
33177
|
function applyWorkspaceBranchPolicy(opts) {
|
|
32665
33178
|
const { workspace_root, env = process.env } = opts;
|
|
32666
|
-
const dir =
|
|
33179
|
+
const dir = path54.join(env.WORKIT_CONFIG ?? configDir2());
|
|
32667
33180
|
const {
|
|
32668
33181
|
status,
|
|
32669
33182
|
path: wsPath,
|
|
@@ -32675,7 +33188,7 @@ function applyWorkspaceBranchPolicy(opts) {
|
|
|
32675
33188
|
if (status === "malformed" || status === "invalid")
|
|
32676
33189
|
return { ok: false, error: workspacesError ?? `invalid workspaces.json: ${wsPath}` };
|
|
32677
33190
|
const detection = detectBranchPolicy(workspace_root);
|
|
32678
|
-
const name = String(env.WORKIT_BP_NAME ??
|
|
33191
|
+
const name = String(env.WORKIT_BP_NAME ?? path54.basename(workspace_root));
|
|
32679
33192
|
const integration = env.WORKIT_BP_INTEGRATION ?? detection.integration;
|
|
32680
33193
|
const policy = {
|
|
32681
33194
|
preset: detection.preset,
|
|
@@ -32724,7 +33237,7 @@ function applyWorkspaceBranchPolicy(opts) {
|
|
|
32724
33237
|
ok: false,
|
|
32725
33238
|
error: `workspaces.json changed while applying the branch policy: ${wsPath}`
|
|
32726
33239
|
};
|
|
32727
|
-
mkdirSync7(
|
|
33240
|
+
mkdirSync7(path54.dirname(wsPath), { recursive: true });
|
|
32728
33241
|
const tmp = `${wsPath}.${process.pid}.tmp`;
|
|
32729
33242
|
try {
|
|
32730
33243
|
writeFileSync9(tmp, JSON.stringify({ ...document, workspaces: next }, null, 2) + `
|
|
@@ -32758,7 +33271,7 @@ function applyWorkspaceBranchPolicy(opts) {
|
|
|
32758
33271
|
// packages/workit-core/src/core/init.ts
|
|
32759
33272
|
var readJson3 = (p) => {
|
|
32760
33273
|
try {
|
|
32761
|
-
const parsed = JSON.parse(
|
|
33274
|
+
const parsed = JSON.parse(fs34.readFileSync(p, "utf8"));
|
|
32762
33275
|
return isConfigObject(parsed) ? parsed : null;
|
|
32763
33276
|
} catch {
|
|
32764
33277
|
return null;
|
|
@@ -32821,11 +33334,11 @@ var vcsJsonContent = () => {
|
|
|
32821
33334
|
};
|
|
32822
33335
|
function initApplyData(action, env = process.env) {
|
|
32823
33336
|
const dir = String(env.WORKIT_CONFIG ?? configDir2());
|
|
32824
|
-
|
|
33337
|
+
fs34.mkdirSync(dir, { recursive: true });
|
|
32825
33338
|
switch (action) {
|
|
32826
33339
|
case "youtrack_json": {
|
|
32827
|
-
const out =
|
|
32828
|
-
|
|
33340
|
+
const out = path55.join(dir, "youtrack.json");
|
|
33341
|
+
fs34.writeFileSync(out, JSON.stringify(youtrackJsonContent(), null, 2) + `
|
|
32829
33342
|
`, "utf8");
|
|
32830
33343
|
return { action, ok: true, path: out };
|
|
32831
33344
|
}
|
|
@@ -32838,10 +33351,10 @@ function initApplyData(action, env = process.env) {
|
|
|
32838
33351
|
};
|
|
32839
33352
|
}
|
|
32840
33353
|
case "youtrack_scaffold": {
|
|
32841
|
-
const jsonOut =
|
|
32842
|
-
|
|
33354
|
+
const jsonOut = path55.join(dir, "youtrack.json");
|
|
33355
|
+
fs34.writeFileSync(jsonOut, JSON.stringify(youtrackJsonContent(), null, 2) + `
|
|
32843
33356
|
`, "utf8");
|
|
32844
|
-
const configPath =
|
|
33357
|
+
const configPath = path55.resolve(jsonOut);
|
|
32845
33358
|
const cfg = readJson3(configPath) ?? {};
|
|
32846
33359
|
const base = String(cfg.baseUrl ?? "").replace(/\/+$/, "");
|
|
32847
33360
|
const meeting = String(cfg.meetingIssue ?? "");
|
|
@@ -32877,10 +33390,10 @@ function initApplyData(action, env = process.env) {
|
|
|
32877
33390
|
};
|
|
32878
33391
|
}
|
|
32879
33392
|
case "vcs_scaffold": {
|
|
32880
|
-
const jsonOut =
|
|
32881
|
-
|
|
33393
|
+
const jsonOut = path55.join(dir, "vcs.json");
|
|
33394
|
+
fs34.writeFileSync(jsonOut, JSON.stringify(vcsJsonContent(), null, 2) + `
|
|
32882
33395
|
`, "utf8");
|
|
32883
|
-
const configPath =
|
|
33396
|
+
const configPath = path55.resolve(jsonOut);
|
|
32884
33397
|
const prev = process.env.WORKIT_VCS_CONFIG;
|
|
32885
33398
|
process.env.WORKIT_VCS_CONFIG = configPath;
|
|
32886
33399
|
try {
|
|
@@ -32999,7 +33512,7 @@ var executeInitApply = (args, directory, runtime) => {
|
|
|
32999
33512
|
protectedNames: args.branch_policy_protected
|
|
33000
33513
|
}, current);
|
|
33001
33514
|
writeConfig(next);
|
|
33002
|
-
return output(ok({ action: "config", path:
|
|
33515
|
+
return output(ok({ action: "config", path: path56.join(configDir2(), "config.json"), ...next }));
|
|
33003
33516
|
}
|
|
33004
33517
|
const env = Object.fromEntries(Object.entries({
|
|
33005
33518
|
WORKIT_YT_BASE_URL: args.base_url,
|
|
@@ -33016,14 +33529,14 @@ var executeInitApply = (args, directory, runtime) => {
|
|
|
33016
33529
|
|
|
33017
33530
|
// packages/workit-opencode/src/shared/session.ts
|
|
33018
33531
|
import { realpathSync as realpathSync12 } from "node:fs";
|
|
33019
|
-
import
|
|
33532
|
+
import path57 from "node:path";
|
|
33020
33533
|
var sameWorkspace = (expected, observed) => {
|
|
33021
33534
|
if (typeof observed !== "string" || !observed)
|
|
33022
33535
|
return false;
|
|
33023
33536
|
try {
|
|
33024
33537
|
return realpathSync12(expected) === realpathSync12(observed);
|
|
33025
33538
|
} catch {
|
|
33026
|
-
return
|
|
33539
|
+
return path57.resolve(expected) === path57.resolve(observed);
|
|
33027
33540
|
}
|
|
33028
33541
|
};
|
|
33029
33542
|
|
|
@@ -33095,7 +33608,7 @@ var workitFamilyOf = (toolName) => {
|
|
|
33095
33608
|
|
|
33096
33609
|
// packages/workit-opencode/src/tools/context.ts
|
|
33097
33610
|
import { realpathSync as realpathSync13 } from "node:fs";
|
|
33098
|
-
import
|
|
33611
|
+
import path58 from "node:path";
|
|
33099
33612
|
var createContextTool = () => ({
|
|
33100
33613
|
description: "Read Git, pull request, YouTrack, issue, changelog, release, or affected-file context.",
|
|
33101
33614
|
execute: async (args, context) => {
|
|
@@ -33105,7 +33618,7 @@ var createContextTool = () => ({
|
|
|
33105
33618
|
let root;
|
|
33106
33619
|
try {
|
|
33107
33620
|
const cwd = parsed.data.cwd;
|
|
33108
|
-
root = realpathSync13(cwd ?
|
|
33621
|
+
root = realpathSync13(cwd ? path58.resolve(context.directory, cwd) : context.directory);
|
|
33109
33622
|
} catch {
|
|
33110
33623
|
return JSON.stringify(failure2("invalid_input", "context target directory cannot be resolved"), null, 2);
|
|
33111
33624
|
}
|
|
@@ -33137,8 +33650,8 @@ var workerCoordinatorFor = (task, worker) => {
|
|
|
33137
33650
|
// packages/workit-core/src/fanout.ts
|
|
33138
33651
|
import { spawnSync as spawnSync29 } from "node:child_process";
|
|
33139
33652
|
import { createHash as createHash21 } from "node:crypto";
|
|
33140
|
-
import
|
|
33141
|
-
import
|
|
33653
|
+
import fs36 from "node:fs";
|
|
33654
|
+
import path60 from "node:path";
|
|
33142
33655
|
|
|
33143
33656
|
// packages/workit-core/src/fanout-landed.ts
|
|
33144
33657
|
import { spawnSync as spawnSync27 } from "node:child_process";
|
|
@@ -33371,8 +33884,8 @@ var NOTICE_TTL_MS = 7 * 86400000;
|
|
|
33371
33884
|
// packages/workit-core/src/stack.ts
|
|
33372
33885
|
import { spawnSync as spawnSync28 } from "node:child_process";
|
|
33373
33886
|
import { createHash as createHash20, randomBytes as randomBytes4 } from "node:crypto";
|
|
33374
|
-
import
|
|
33375
|
-
import
|
|
33887
|
+
import fs35 from "node:fs";
|
|
33888
|
+
import path59 from "node:path";
|
|
33376
33889
|
|
|
33377
33890
|
// packages/workit-core/src/forge/report.ts
|
|
33378
33891
|
var GITLAB_MERGEABLE = new Set(["mergeable"]);
|
|
@@ -33439,7 +33952,7 @@ function rebasingBranch2(dir) {
|
|
|
33439
33952
|
if (!found.ok)
|
|
33440
33953
|
continue;
|
|
33441
33954
|
try {
|
|
33442
|
-
return
|
|
33955
|
+
return fs35.readFileSync(found.stdout.trim(), "utf8").trim();
|
|
33443
33956
|
} catch {}
|
|
33444
33957
|
}
|
|
33445
33958
|
return null;
|
|
@@ -33447,14 +33960,14 @@ function rebasingBranch2(dir) {
|
|
|
33447
33960
|
function rebaseInProgress(dir) {
|
|
33448
33961
|
for (const name of ["rebase-merge", "rebase-apply"]) {
|
|
33449
33962
|
const found = gitRun4(dir, ["rev-parse", "--path-format=absolute", "--git-path", name]);
|
|
33450
|
-
if (found.ok &&
|
|
33963
|
+
if (found.ok && fs35.existsSync(found.stdout.trim()))
|
|
33451
33964
|
return true;
|
|
33452
33965
|
}
|
|
33453
33966
|
return false;
|
|
33454
33967
|
}
|
|
33455
33968
|
var scratchDir = (cwd) => {
|
|
33456
33969
|
const dir = stacksDir(cwd);
|
|
33457
|
-
return dir.ok ?
|
|
33970
|
+
return dir.ok ? path59.join(dir.data, "worktrees") : null;
|
|
33458
33971
|
};
|
|
33459
33972
|
function gitRestack(cwd, input) {
|
|
33460
33973
|
const owner = worktreeOf(cwd, input.branch);
|
|
@@ -33468,8 +33981,8 @@ function gitRestack(cwd, input) {
|
|
|
33468
33981
|
worktree: cwd,
|
|
33469
33982
|
error: "no store root"
|
|
33470
33983
|
};
|
|
33471
|
-
|
|
33472
|
-
dir =
|
|
33984
|
+
fs35.mkdirSync(scratch, { recursive: true });
|
|
33985
|
+
dir = path59.join(scratch, `${input.branch.replace(/[^A-Za-z0-9._-]+/gu, "_").slice(0, 40)}-${randomBytes4(4).toString("hex")}`);
|
|
33473
33986
|
const added = gitRun4(cwd, ["worktree", "add", "-q", dir, input.branch], GIT_TIMEOUTS.worktree);
|
|
33474
33987
|
if (!added.ok)
|
|
33475
33988
|
return {
|
|
@@ -33528,7 +34041,7 @@ function stacksDir(cwd) {
|
|
|
33528
34041
|
const root = storeRoot(cwd);
|
|
33529
34042
|
if (!root.ok)
|
|
33530
34043
|
return stackFail(root.code, root.error, root.unblock);
|
|
33531
|
-
return { ok: true, data:
|
|
34044
|
+
return { ok: true, data: path59.join(root.value.root, "stacks") };
|
|
33532
34045
|
}
|
|
33533
34046
|
var HEARTBEAT_STALE_MS = 2 * 60000;
|
|
33534
34047
|
var SETTLED_BY_RESTACK = new Set(["checks_pending", "behind_base_required"]);
|
|
@@ -33675,7 +34188,7 @@ function fanoutsDir(cwd) {
|
|
|
33675
34188
|
const root = storeRoot(cwd);
|
|
33676
34189
|
if (!root.ok)
|
|
33677
34190
|
return fanoutFail(root.code, root.error, root.unblock);
|
|
33678
|
-
return { ok: true, data:
|
|
34191
|
+
return { ok: true, data: path60.join(root.value.root, "fanouts") };
|
|
33679
34192
|
}
|
|
33680
34193
|
function parseStored(raw) {
|
|
33681
34194
|
if (!isRecord9(raw) || typeof raw.name !== "string" || typeof raw.trunk !== "string")
|
|
@@ -33743,10 +34256,10 @@ function readFanout(cwd, name) {
|
|
|
33743
34256
|
const dir = fanoutsDir(cwd);
|
|
33744
34257
|
if (!dir.ok)
|
|
33745
34258
|
return dir;
|
|
33746
|
-
const file =
|
|
34259
|
+
const file = path60.join(dir.data, stackFileName(name));
|
|
33747
34260
|
let parsed = null;
|
|
33748
34261
|
try {
|
|
33749
|
-
parsed = parseStored(JSON.parse(
|
|
34262
|
+
parsed = parseStored(JSON.parse(fs36.readFileSync(file, "utf8")));
|
|
33750
34263
|
} catch (error) {
|
|
33751
34264
|
if (error.code === "ENOENT")
|
|
33752
34265
|
return { ok: true, data: null };
|
|
@@ -33760,7 +34273,7 @@ function listFanouts(cwd) {
|
|
|
33760
34273
|
return dir;
|
|
33761
34274
|
let names = [];
|
|
33762
34275
|
try {
|
|
33763
|
-
names =
|
|
34276
|
+
names = fs36.readdirSync(dir.data).filter((entry) => entry.endsWith(".json"));
|
|
33764
34277
|
} catch {
|
|
33765
34278
|
return { ok: true, data: [] };
|
|
33766
34279
|
}
|
|
@@ -33768,7 +34281,7 @@ function listFanouts(cwd) {
|
|
|
33768
34281
|
for (const entry of names) {
|
|
33769
34282
|
let parsed = null;
|
|
33770
34283
|
try {
|
|
33771
|
-
parsed = parseStored(JSON.parse(
|
|
34284
|
+
parsed = parseStored(JSON.parse(fs36.readFileSync(path60.join(dir.data, entry), "utf8")));
|
|
33772
34285
|
} catch {
|
|
33773
34286
|
parsed = null;
|
|
33774
34287
|
}
|
|
@@ -34661,7 +35174,7 @@ var childTaskMissing = (store, input) => {
|
|
|
34661
35174
|
var childDenial = (identity) => `OpenCode child session has no validated Workit worker: as ${identity} it may only inspect the task summary (workit_task action "inspect") or record evidence or findings (workit_evidence/workit_finding action "record") on an existing task; for anything else the lead assigns it a worker with workit_worker before launching it`;
|
|
34662
35175
|
|
|
34663
35176
|
// packages/workit-opencode/src/v2/shell.ts
|
|
34664
|
-
import
|
|
35177
|
+
import path61 from "node:path";
|
|
34665
35178
|
|
|
34666
35179
|
// packages/workit-core/src/hooks/repeat-failure.ts
|
|
34667
35180
|
import { createHash as createHash22 } from "node:crypto";
|
|
@@ -34724,7 +35237,7 @@ var commandOf = (input) => {
|
|
|
34724
35237
|
};
|
|
34725
35238
|
var hookInput = (root, sessionID, id, shell) => ({
|
|
34726
35239
|
host: "opencode",
|
|
34727
|
-
cwd: shell.workdir ?
|
|
35240
|
+
cwd: shell.workdir ? path61.resolve(root, shell.workdir) : root,
|
|
34728
35241
|
session: { id: sessionID, agentId: null, agentType: null, parentId: null },
|
|
34729
35242
|
permissionMode: null,
|
|
34730
35243
|
transcriptPath: null,
|
|
@@ -35248,37 +35761,37 @@ var createStopControl = (root, port) => {
|
|
|
35248
35761
|
|
|
35249
35762
|
// packages/workit-opencode/src/v2/registry.ts
|
|
35250
35763
|
import { existsSync as existsSync22, readFileSync as readFileSync17 } from "node:fs";
|
|
35251
|
-
import
|
|
35764
|
+
import path63 from "node:path";
|
|
35252
35765
|
|
|
35253
35766
|
// packages/workit-opencode/src/shared/assets.ts
|
|
35254
35767
|
import { existsSync as existsSync21, realpathSync as realpathSync14 } from "node:fs";
|
|
35255
|
-
import
|
|
35768
|
+
import path62 from "node:path";
|
|
35256
35769
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
35257
35770
|
var moduleDir = () => {
|
|
35258
35771
|
try {
|
|
35259
|
-
return realpathSync14(
|
|
35772
|
+
return realpathSync14(path62.dirname(fileURLToPath2(import.meta.url)));
|
|
35260
35773
|
} catch {
|
|
35261
|
-
return
|
|
35774
|
+
return path62.dirname(fileURLToPath2(import.meta.url));
|
|
35262
35775
|
}
|
|
35263
35776
|
};
|
|
35264
35777
|
var packageRoot2 = () => {
|
|
35265
35778
|
const dir = moduleDir();
|
|
35266
35779
|
for (const candidate of [
|
|
35267
|
-
|
|
35268
|
-
|
|
35269
|
-
|
|
35780
|
+
path62.resolve(dir, ".."),
|
|
35781
|
+
path62.resolve(dir, "..", ".."),
|
|
35782
|
+
path62.resolve(dir, "..", "..", "..")
|
|
35270
35783
|
]) {
|
|
35271
|
-
if (existsSync21(
|
|
35784
|
+
if (existsSync21(path62.join(candidate, "package.json")))
|
|
35272
35785
|
return candidate;
|
|
35273
35786
|
}
|
|
35274
|
-
return
|
|
35787
|
+
return path62.resolve(dir, "..");
|
|
35275
35788
|
};
|
|
35276
35789
|
var skillsRoot = () => {
|
|
35277
35790
|
const root = packageRoot2();
|
|
35278
|
-
const canonical =
|
|
35279
|
-
if (existsSync21(
|
|
35791
|
+
const canonical = path62.resolve(root, "..", "workit-core", "skills");
|
|
35792
|
+
if (existsSync21(path62.join(root, "src")) && existsSync21(canonical))
|
|
35280
35793
|
return canonical;
|
|
35281
|
-
return
|
|
35794
|
+
return path62.join(root, "assets", "skills");
|
|
35282
35795
|
};
|
|
35283
35796
|
|
|
35284
35797
|
// packages/workit-opencode/src/v2/registry.ts
|
|
@@ -35305,11 +35818,11 @@ var registerSkills = async (ctx) => {
|
|
|
35305
35818
|
if (!existsSync22(skillsDir))
|
|
35306
35819
|
return new Set;
|
|
35307
35820
|
const listed = await ctx.skill.list().catch(() => ({ data: [] }));
|
|
35308
|
-
const own = (skill) => typeof skill.path === "string" &&
|
|
35821
|
+
const own = (skill) => typeof skill.path === "string" && path63.resolve(skill.path).startsWith(skillsDir + path63.sep);
|
|
35309
35822
|
const userSkills = new Set((listed?.data ?? []).filter((skill) => !own(skill)).map((skill) => skill.id));
|
|
35310
35823
|
const packaged = new Map;
|
|
35311
35824
|
for (const id of WORKIT_METHOD_SKILLS) {
|
|
35312
|
-
const file =
|
|
35825
|
+
const file = path63.join(skillsDir, id, "SKILL.md");
|
|
35313
35826
|
if (!userSkills.has(id) && existsSync22(file))
|
|
35314
35827
|
packaged.set(id, file);
|
|
35315
35828
|
}
|
|
@@ -35357,22 +35870,22 @@ var registerCommands = async (ctx, registeredSkills) => {
|
|
|
35357
35870
|
|
|
35358
35871
|
// packages/workit-opencode/src/stale-sources.ts
|
|
35359
35872
|
import { existsSync as existsSync23, readdirSync as readdirSync9 } from "node:fs";
|
|
35360
|
-
import
|
|
35873
|
+
import path64 from "node:path";
|
|
35361
35874
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
35362
35875
|
var typescriptFiles = (directory) => {
|
|
35363
35876
|
if (!existsSync23(directory))
|
|
35364
35877
|
return [];
|
|
35365
35878
|
return readdirSync9(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
35366
|
-
const file =
|
|
35879
|
+
const file = path64.join(directory, entry.name);
|
|
35367
35880
|
return entry.isDirectory() ? typescriptFiles(file) : entry.isFile() && file.endsWith(".ts") ? [file] : [];
|
|
35368
35881
|
});
|
|
35369
35882
|
};
|
|
35370
35883
|
var pluginSourceFiles = [
|
|
35371
35884
|
...new Set([
|
|
35372
35885
|
fileURLToPath3(import.meta.url),
|
|
35373
|
-
...typescriptFiles(
|
|
35374
|
-
|
|
35375
|
-
...typescriptFiles(
|
|
35886
|
+
...typescriptFiles(path64.join(packageRoot2(), "src")),
|
|
35887
|
+
path64.join(packageRoot2(), "..", "workit-core", "src", "core.ts"),
|
|
35888
|
+
...typescriptFiles(path64.join(packageRoot2(), "..", "workit-core", "src", "core"))
|
|
35376
35889
|
])
|
|
35377
35890
|
].filter((file) => existsSync23(file)).toSorted();
|
|
35378
35891
|
|