@workit-dev/pi 2.29.2 → 2.29.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/worker.js +40 -0
- package/dist/workit.js +500 -53
- package/package.json +1 -1
package/dist/worker.js
CHANGED
|
@@ -8578,6 +8578,46 @@ var API_VALUES = new Set(["--method", "--header", "--raw-field", "--field", "--j
|
|
|
8578
8578
|
"--output"
|
|
8579
8579
|
]));
|
|
8580
8580
|
var API_FIELDS = new Set(["-f", "-F", "--raw-field", "--field"]);
|
|
8581
|
+
var GH_REPO_PATH = String.raw`(?:^|\/)(?:repos\/[^/]+\/[^/]+|repositories\/[^/]+)`;
|
|
8582
|
+
var ghPath = (rest) => new RegExp(`${GH_REPO_PATH}\\/${rest}(?:\\/|$)`, "i");
|
|
8583
|
+
var called = (names) => new RegExp(String.raw`\b(?:${names})(?:[\s,\uFEFF]|#[^\n\r]*[\n\r])*\(`);
|
|
8584
|
+
var GRAPHQL_REF = [
|
|
8585
|
+
[called("createRef|updateRefs?|deleteRef"), "ref"],
|
|
8586
|
+
[
|
|
8587
|
+
called("createCommitOnBranch|createLinkedBranch|createBranch|branchDelete|commitCreate"),
|
|
8588
|
+
"branch"
|
|
8589
|
+
],
|
|
8590
|
+
[called("tagCreate|tagDelete"), "tag"]
|
|
8591
|
+
];
|
|
8592
|
+
var GRAPHQL_SETTING = called("(?:create|update|delete)(?:BranchProtectionRule|RepositoryRuleset)|branchRule(?:Create|Update|Delete)");
|
|
8593
|
+
var API_REF = {
|
|
8594
|
+
gh: [
|
|
8595
|
+
[ghPath(String.raw`git\/refs?`), "ref"],
|
|
8596
|
+
[ghPath(String.raw`(?:branches\/.+\/rename|merge-upstream|contents)`), "branch"]
|
|
8597
|
+
],
|
|
8598
|
+
glab: [
|
|
8599
|
+
[/(?:^|\/)repository\/tags(?:\/|$)/i, "tag"],
|
|
8600
|
+
[/(?:^|\/)repository\/(?:branches|merged_branches|files|submodules)(?:\/|$)/i, "branch"],
|
|
8601
|
+
[/(?:^|\/)repository\/commits(?:\/[^/]+\/(?:cherry_pick|revert))?\/?$/i, "branch"]
|
|
8602
|
+
]
|
|
8603
|
+
};
|
|
8604
|
+
var API_SETTING = {
|
|
8605
|
+
gh: [
|
|
8606
|
+
ghPath(String.raw`(?:branches\/.+|tags)\/protection`),
|
|
8607
|
+
ghPath("rulesets"),
|
|
8608
|
+
ghPath(String.raw`environments\/[^/]+\/deployment-branch-policies`),
|
|
8609
|
+
/(?:^|\/)orgs\/[^/]+\/rulesets(?:\/|$)/i
|
|
8610
|
+
],
|
|
8611
|
+
glab: [
|
|
8612
|
+
/(?:^|\/)(?:projects|groups)\/[^/]+\/protected_(?:branches|tags)(?:\/|$)/i,
|
|
8613
|
+
/(?:^|\/)projects\/[^/]+\/push_rule(?:\/|$)/i
|
|
8614
|
+
]
|
|
8615
|
+
};
|
|
8616
|
+
var API_REPOSITORY = {
|
|
8617
|
+
gh: new RegExp(`${GH_REPO_PATH}\\/?$`, "i"),
|
|
8618
|
+
glab: /(?:^|\/)projects\/[^/]+\/?$/i
|
|
8619
|
+
};
|
|
8620
|
+
var BY_ID = called("updateRefs?|deleteRef");
|
|
8581
8621
|
var GIT_COMMANDS = new Set(("add am annotate apply archive bisect blame branch bugreport bundle cat-file check-attr " + "check-ignore check-mailmap check-ref-format checkout checkout-index cherry cherry-pick " + "citool clean clone column commit commit-graph commit-tree config count-objects credential " + "daemon describe diagnose diff diff-files diff-index diff-tree difftool fast-export " + "fast-import fetch fetch-pack filter-branch fmt-merge-msg for-each-ref for-each-repo " + "format-patch fsck gc get-tar-commit-id grep gui hash-object help hook index-pack init " + "instaweb interpret-trailers lfs log ls-files ls-remote ls-tree mailinfo mailsplit " + "maintenance merge merge-base merge-file merge-index merge-tree mergetool mktag mktree " + "multi-pack-index mv name-rev notes pack-objects pack-refs patch-id prune pull push " + "range-diff read-tree rebase reflog remote repack replace request-pull rerere reset " + "restore rev-list rev-parse revert rm send-email shortlog show show-branch show-ref " + "sparse-checkout stage stash status stripspace submodule subtree switch symbolic-ref tag " + "update-index update-ref var verify-commit verify-pack verify-tag version whatchanged " + "worktree write-tree").split(" "));
|
|
8582
8622
|
|
|
8583
8623
|
// packages/workit-core/src/core/route-intent.ts
|
package/dist/workit.js
CHANGED
|
@@ -20826,7 +20826,7 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
|
|
|
20826
20826
|
for (const invocation of inside)
|
|
20827
20827
|
found.push({ ...invocation, dir: rebase(dir, invocation.dir) });
|
|
20828
20828
|
};
|
|
20829
|
-
const visit = (input, stdin, hops) => {
|
|
20829
|
+
const visit = (input, stdin, hops, expands = "all") => {
|
|
20830
20830
|
const line = /^\$[\w:]+$/.test(input[0] ?? "") && input[1] === "=" ? input.slice(2) : input;
|
|
20831
20831
|
const split = splitString(line);
|
|
20832
20832
|
if (split !== null)
|
|
@@ -20888,15 +20888,18 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
|
|
|
20888
20888
|
nested(cmdScript(words), "powershell");
|
|
20889
20889
|
else if (name === "xargs" || name === "find")
|
|
20890
20890
|
runs(name === "xargs" ? xargsCommands(words, stdin) : findCommands(words));
|
|
20891
|
-
else if (name === "gh" || name === "glab")
|
|
20891
|
+
else if (name === "gh" || name === "glab") {
|
|
20892
|
+
const shift = input.length - words.length + 1;
|
|
20893
|
+
const expanded = expands === "all" ? expands : expands.filter((at) => at >= shift).map((at) => at - shift);
|
|
20892
20894
|
found.push({
|
|
20893
20895
|
tool: name,
|
|
20894
20896
|
dir,
|
|
20895
20897
|
args: words.slice(1),
|
|
20896
20898
|
...Object.keys({ ...exported, ...env }).length ? { env: { ...exported, ...env } } : {},
|
|
20897
|
-
...stdin === undefined ? {} : { stdin }
|
|
20899
|
+
...stdin === undefined ? {} : { stdin },
|
|
20900
|
+
...expanded.length ? { expanded } : {}
|
|
20898
20901
|
});
|
|
20899
|
-
else if (name === "git") {
|
|
20902
|
+
} else if (name === "git") {
|
|
20900
20903
|
const invocation = gitInvocation(words.slice(1), dir, { ...exported, ...env }, stdin, sessionConfig);
|
|
20901
20904
|
found.push(invocation);
|
|
20902
20905
|
sessionConfig.push(...configSetBy(invocation.args));
|
|
@@ -20929,7 +20932,7 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
|
|
|
20929
20932
|
}
|
|
20930
20933
|
const stdin = stdinOf(segment, segments[index - 1]);
|
|
20931
20934
|
for (const line of substitute(segment.words, vars))
|
|
20932
|
-
visit(line, stdin, 0);
|
|
20935
|
+
visit(line, stdin, 0, segment.expands ?? []);
|
|
20933
20936
|
}
|
|
20934
20937
|
return found;
|
|
20935
20938
|
}
|
|
@@ -21224,55 +21227,232 @@ var API_VALUES = new Set(["--method", "--header", "--raw-field", "--field", "--j
|
|
|
21224
21227
|
var API_SHORT_VALUES = "XHfFqtp";
|
|
21225
21228
|
var API_FIELDS = new Set(["-f", "-F", "--raw-field", "--field"]);
|
|
21226
21229
|
var API_MERGE = {
|
|
21227
|
-
gh: /(?:^|\/)(?:pulls\/[^/?#]+\/merge|merges)
|
|
21228
|
-
glab: /(?:^|\/)merge_requests\/[^/?#]+\/merge
|
|
21230
|
+
gh: /(?:^|\/)(?:pulls\/[^/?#]+\/merge|merges)\/?$/i,
|
|
21231
|
+
glab: /(?:^|\/)merge_requests\/[^/?#]+\/merge\/?$/i
|
|
21229
21232
|
};
|
|
21230
21233
|
var GRAPHQL_MERGE = /\b(?:mergePullRequest|enablePullRequestAutoMerge|mergeBranch|mergeRequestAccept)\b/;
|
|
21231
|
-
var
|
|
21232
|
-
|
|
21234
|
+
var GH_REPO_PATH = String.raw`(?:^|\/)(?:repos\/[^/]+\/[^/]+|repositories\/[^/]+)`;
|
|
21235
|
+
var ghPath = (rest) => new RegExp(`${GH_REPO_PATH}\\/${rest}(?:\\/|$)`, "i");
|
|
21236
|
+
var called = (names) => new RegExp(String.raw`\b(?:${names})(?:[\s,\uFEFF]|#[^\n\r]*[\n\r])*\(`);
|
|
21237
|
+
var GRAPHQL_REF = [
|
|
21238
|
+
[called("createRef|updateRefs?|deleteRef"), "ref"],
|
|
21239
|
+
[
|
|
21240
|
+
called("createCommitOnBranch|createLinkedBranch|createBranch|branchDelete|commitCreate"),
|
|
21241
|
+
"branch"
|
|
21242
|
+
],
|
|
21243
|
+
[called("tagCreate|tagDelete"), "tag"]
|
|
21244
|
+
];
|
|
21245
|
+
var GRAPHQL_SETTING = called("(?:create|update|delete)(?:BranchProtectionRule|RepositoryRuleset)|branchRule(?:Create|Update|Delete)");
|
|
21246
|
+
var API_REF = {
|
|
21247
|
+
gh: [
|
|
21248
|
+
[ghPath(String.raw`git\/refs?`), "ref"],
|
|
21249
|
+
[ghPath(String.raw`(?:branches\/.+\/rename|merge-upstream|contents)`), "branch"]
|
|
21250
|
+
],
|
|
21251
|
+
glab: [
|
|
21252
|
+
[/(?:^|\/)repository\/tags(?:\/|$)/i, "tag"],
|
|
21253
|
+
[/(?:^|\/)repository\/(?:branches|merged_branches|files|submodules)(?:\/|$)/i, "branch"],
|
|
21254
|
+
[/(?:^|\/)repository\/commits(?:\/[^/]+\/(?:cherry_pick|revert))?\/?$/i, "branch"]
|
|
21255
|
+
]
|
|
21256
|
+
};
|
|
21257
|
+
var API_SETTING = {
|
|
21258
|
+
gh: [
|
|
21259
|
+
ghPath(String.raw`(?:branches\/.+|tags)\/protection`),
|
|
21260
|
+
ghPath("rulesets"),
|
|
21261
|
+
ghPath(String.raw`environments\/[^/]+\/deployment-branch-policies`),
|
|
21262
|
+
/(?:^|\/)orgs\/[^/]+\/rulesets(?:\/|$)/i
|
|
21263
|
+
],
|
|
21264
|
+
glab: [
|
|
21265
|
+
/(?:^|\/)(?:projects|groups)\/[^/]+\/protected_(?:branches|tags)(?:\/|$)/i,
|
|
21266
|
+
/(?:^|\/)projects\/[^/]+\/push_rule(?:\/|$)/i
|
|
21267
|
+
]
|
|
21268
|
+
};
|
|
21269
|
+
var API_REPOSITORY = {
|
|
21270
|
+
gh: new RegExp(`${GH_REPO_PATH}\\/?$`, "i"),
|
|
21271
|
+
glab: /(?:^|\/)projects\/[^/]+\/?$/i
|
|
21272
|
+
};
|
|
21273
|
+
var PLAIN_REF = /^refs\/(?:heads|tags)\/(?!.*\.\.)[^\s$`\\%]+$/;
|
|
21274
|
+
var BY_ID = called("updateRefs?|deleteRef");
|
|
21275
|
+
var createdRefs = (query) => {
|
|
21276
|
+
if (/[\\$]|"""/.test(query))
|
|
21277
|
+
return null;
|
|
21278
|
+
const tokens = query.match(/#[^\n\r]*|"[^"\n\r]*"|[_A-Za-z]\w*|[^\s,\uFEFF]/g) ?? [];
|
|
21279
|
+
const named = [];
|
|
21280
|
+
for (let at = 0;at < tokens.length; at++) {
|
|
21281
|
+
if (tokens[at] !== "createRef")
|
|
21282
|
+
continue;
|
|
21283
|
+
const args = tokens.slice(at + 1).filter((token) => !token.startsWith("#"));
|
|
21284
|
+
if (args[0] !== "(")
|
|
21285
|
+
continue;
|
|
21286
|
+
let depth = 0;
|
|
21287
|
+
const names = [];
|
|
21288
|
+
for (let index = 0;index < args.length; index++) {
|
|
21289
|
+
const token = args[index];
|
|
21290
|
+
if (token === "(" || token === "{" || token === "[")
|
|
21291
|
+
depth++;
|
|
21292
|
+
else if (token === ")" || token === "}" || token === "]") {
|
|
21293
|
+
if (--depth === 0)
|
|
21294
|
+
break;
|
|
21295
|
+
} else if (token === "name" && args[index + 1] === ":")
|
|
21296
|
+
names.push(args[index + 2] ?? "");
|
|
21297
|
+
}
|
|
21298
|
+
if (depth !== 0 || names.length !== 1 || !names[0].startsWith('"'))
|
|
21299
|
+
return null;
|
|
21300
|
+
named.push(names[0].slice(1, -1));
|
|
21301
|
+
}
|
|
21302
|
+
return named;
|
|
21303
|
+
};
|
|
21304
|
+
var provablyRead = (query) => /^[\s,\uFEFF]*(?:\{|query[\s,\uFEFF]*[({])/.test(query) && !/\b(?:mutation|subscription)\b/.test(query);
|
|
21305
|
+
var refWrite = (forge, shapes, named, certain) => {
|
|
21306
|
+
const sure = certain && named.length > 0 && named.every((ref) => PLAIN_REF.test(ref));
|
|
21307
|
+
const tags = !sure || named.some((ref) => ref.startsWith("refs/tags/"));
|
|
21308
|
+
const heads = !sure || named.some((ref) => ref.startsWith("refs/heads/"));
|
|
21309
|
+
const ref = shapes.has("ref");
|
|
21310
|
+
return {
|
|
21311
|
+
kind: "ref-write",
|
|
21312
|
+
forge,
|
|
21313
|
+
tag: shapes.has("tag") || ref && tags,
|
|
21314
|
+
branch: shapes.has("branch") || ref && heads,
|
|
21315
|
+
...ref && sure ? { ref: named[0] } : {}
|
|
21316
|
+
};
|
|
21317
|
+
};
|
|
21318
|
+
var restRef = (route, fields, readable) => {
|
|
21319
|
+
const inPath = /\/git\/refs?\/(.+)$/i.exec(route)?.[1];
|
|
21320
|
+
if (inPath)
|
|
21321
|
+
return { named: [`refs/${inPath}`], certain: true };
|
|
21322
|
+
const refs = fields.filter((field) => field.startsWith("ref=")).map((field) => field.slice(4));
|
|
21323
|
+
const mentions = fields.filter((field) => /refs\//.test(field)).length;
|
|
21324
|
+
return { named: refs, certain: readable && refs.length === 1 && mentions === 1 };
|
|
21325
|
+
};
|
|
21326
|
+
var routeOf = (endpoint) => endpoint.replace(/(?<!:)\/{2,}/g, "/").replace(/[?#][\s\S]*$/, "").replace(/%([\da-f]{2})/gi, (escape, hex) => {
|
|
21327
|
+
const char = String.fromCodePoint(Number.parseInt(hex, 16));
|
|
21328
|
+
return /[\w.~-]/.test(char) ? char : escape;
|
|
21329
|
+
});
|
|
21330
|
+
var apiAction = (tool, args, stdin, expanded = []) => {
|
|
21331
|
+
const request = { method: null, body: false, input: false, unread: false };
|
|
21233
21332
|
let endpoint = null;
|
|
21333
|
+
let endpointAt = -1;
|
|
21234
21334
|
const values = [];
|
|
21235
|
-
const
|
|
21335
|
+
const fields = [];
|
|
21336
|
+
const queries = [];
|
|
21337
|
+
const field = (value, expands) => {
|
|
21338
|
+
fields.push(value);
|
|
21339
|
+
values.push(value);
|
|
21340
|
+
if (!value.startsWith("query="))
|
|
21341
|
+
return;
|
|
21342
|
+
const text = value.slice(6);
|
|
21343
|
+
const read = expanded !== "all" && (!(expands && /[$`]/.test(text)) || provablyRead(text));
|
|
21344
|
+
queries.push({ text, read });
|
|
21345
|
+
};
|
|
21346
|
+
const fromStdin = (name, value, text) => {
|
|
21347
|
+
if (name !== "--input") {
|
|
21348
|
+
if (text.includes("\\"))
|
|
21349
|
+
request.unread = true;
|
|
21350
|
+
return field(`${value.slice(0, value.indexOf("=") + 1)}${text}`, true);
|
|
21351
|
+
}
|
|
21352
|
+
values.push(text);
|
|
21353
|
+
let body;
|
|
21354
|
+
try {
|
|
21355
|
+
body = JSON.parse(text);
|
|
21356
|
+
} catch {
|
|
21357
|
+
request.unread = true;
|
|
21358
|
+
return;
|
|
21359
|
+
}
|
|
21360
|
+
const strings = (each) => typeof each === "string" ? [each] : each && typeof each === "object" ? Object.entries(each).flatMap(([key, inner]) => [key, ...strings(inner)]) : [];
|
|
21361
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
21362
|
+
values.push(...strings(body));
|
|
21363
|
+
return;
|
|
21364
|
+
}
|
|
21365
|
+
for (const [key, inner] of Object.entries(body)) {
|
|
21366
|
+
if (typeof inner === "string")
|
|
21367
|
+
field(`${key}=${inner}`, true);
|
|
21368
|
+
else
|
|
21369
|
+
values.push(key, ...strings(inner));
|
|
21370
|
+
}
|
|
21371
|
+
};
|
|
21372
|
+
const take = (name, value, at) => {
|
|
21373
|
+
const expands = expanded === "all" || expanded.includes(at);
|
|
21236
21374
|
if (name === "-X" || name === "--method")
|
|
21237
21375
|
request.method = value.toUpperCase();
|
|
21238
21376
|
if (API_FIELDS.has(name) || name === "--input")
|
|
21239
21377
|
request.body = true;
|
|
21240
|
-
|
|
21241
|
-
|
|
21242
|
-
|
|
21243
|
-
|
|
21378
|
+
if (name === "--input")
|
|
21379
|
+
request.input = true;
|
|
21380
|
+
const piped = name === "--input" ? value === "-" : /^(?:-F|--field)$/.test(name) && /^[^=]*=@-$/.test(value);
|
|
21381
|
+
if (piped && stdin !== undefined) {
|
|
21382
|
+
values.push(value);
|
|
21383
|
+
return fromStdin(name, value, stdin);
|
|
21384
|
+
}
|
|
21385
|
+
if (API_FIELDS.has(name))
|
|
21386
|
+
field(value, expands);
|
|
21387
|
+
else
|
|
21388
|
+
values.push(value);
|
|
21389
|
+
const file = name === "--input" || /^(?:-F|--field)$/.test(name) && /^[^=]*=@/.test(value);
|
|
21390
|
+
if (file)
|
|
21391
|
+
request.unread = true;
|
|
21244
21392
|
};
|
|
21245
21393
|
for (let index = 1;index < args.length; index++) {
|
|
21246
21394
|
const arg = args[index];
|
|
21247
21395
|
if (arg === "--") {
|
|
21248
|
-
endpoint
|
|
21396
|
+
if (endpoint === null)
|
|
21397
|
+
[endpoint, endpointAt] = [args[index + 1] ?? null, index + 1];
|
|
21249
21398
|
break;
|
|
21250
21399
|
}
|
|
21251
21400
|
if (arg.startsWith("--")) {
|
|
21252
21401
|
const eq = arg.indexOf("=");
|
|
21253
21402
|
const name = eq > 0 ? arg.slice(0, eq) : arg;
|
|
21254
21403
|
if (API_VALUES.has(name))
|
|
21255
|
-
take(name, eq > 0 ? arg.slice(eq + 1) : args[++index] ?? "");
|
|
21404
|
+
take(name, eq > 0 ? arg.slice(eq + 1) : args[++index] ?? "", index);
|
|
21256
21405
|
} else if (arg.startsWith("-") && arg.length > 1) {
|
|
21257
21406
|
for (let at = 1;at < arg.length; at++) {
|
|
21258
21407
|
if (!API_SHORT_VALUES.includes(arg[at]))
|
|
21259
21408
|
continue;
|
|
21260
|
-
take(`-${arg[at]}`, at + 1 < arg.length ? arg.slice(at + 1) : args[++index] ?? "");
|
|
21409
|
+
take(`-${arg[at]}`, at + 1 < arg.length ? arg.slice(at + 1) : args[++index] ?? "", index);
|
|
21261
21410
|
break;
|
|
21262
21411
|
}
|
|
21263
|
-
} else
|
|
21264
|
-
endpoint
|
|
21412
|
+
} else if (endpoint === null)
|
|
21413
|
+
[endpoint, endpointAt] = [arg, index];
|
|
21265
21414
|
}
|
|
21266
21415
|
if (!endpoint)
|
|
21267
21416
|
return null;
|
|
21268
|
-
|
|
21417
|
+
const atEndpoint = expanded === "all" || expanded.includes(endpointAt);
|
|
21418
|
+
for (const pair of /[?]([^#]*)/.exec(endpoint)?.[1].split("&") ?? []) {
|
|
21419
|
+
let decoded = pair;
|
|
21420
|
+
try {
|
|
21421
|
+
decoded = decodeURIComponent(pair.replaceAll("+", " "));
|
|
21422
|
+
} catch {
|
|
21423
|
+
request.unread = true;
|
|
21424
|
+
}
|
|
21425
|
+
field(decoded, atEndpoint);
|
|
21426
|
+
if (/refs\//i.test(decoded))
|
|
21427
|
+
request.input = true;
|
|
21428
|
+
}
|
|
21429
|
+
const route = routeOf(endpoint);
|
|
21269
21430
|
const merge = { kind: "merge", forge: tool, via: "api" };
|
|
21270
|
-
|
|
21271
|
-
|
|
21431
|
+
const setting = {
|
|
21432
|
+
kind: "ref-write",
|
|
21433
|
+
forge: tool,
|
|
21434
|
+
tag: false,
|
|
21435
|
+
branch: true,
|
|
21436
|
+
setting: true
|
|
21437
|
+
};
|
|
21438
|
+
if (/(?:^|\/)graphql\/?$/i.test(route)) {
|
|
21439
|
+
if (request.unread || queries.some((query) => !query.read))
|
|
21440
|
+
return { kind: "ref-write", forge: tool, tag: true, branch: true, unread: true };
|
|
21441
|
+
if (values.some((value) => GRAPHQL_MERGE.test(value)))
|
|
21442
|
+
return merge;
|
|
21443
|
+
if (values.some((value) => GRAPHQL_SETTING.test(value)))
|
|
21444
|
+
return setting;
|
|
21445
|
+
const shapes = new Set(GRAPHQL_REF.filter(([pattern]) => values.some((value) => pattern.test(value))).map(([, shape]) => shape));
|
|
21446
|
+
if (!shapes.size)
|
|
21447
|
+
return null;
|
|
21448
|
+
const created = queries.map((query) => createdRefs(query.text));
|
|
21449
|
+
const certain = !values.some((value) => BY_ID.test(value)) && created.every((named) => named !== null);
|
|
21450
|
+
return refWrite(tool, shapes, created.flatMap((named) => named ?? []), certain);
|
|
21451
|
+
}
|
|
21272
21452
|
const verb = request.method ?? (request.body ? "POST" : "GET");
|
|
21273
21453
|
if (verb === "GET" || verb === "HEAD")
|
|
21274
21454
|
return null;
|
|
21275
|
-
const named = tool === "gh" ? /(?:^|\/)repos\/([^/{]+\/[^/{]+)
|
|
21455
|
+
const named = tool === "gh" ? /(?:^|\/)repos\/([^/{]+\/[^/{]+)(?:\/|$)/i.exec(route)?.[1] ?? (/(?:^|\/)repositories\/[^/]+(?:\/|$)/i.test(route) ? "?" : undefined) : /(?:^|\/)projects\/([^/]+)(?:\/|$)/i.exec(route)?.[1];
|
|
21276
21456
|
let repo;
|
|
21277
21457
|
try {
|
|
21278
21458
|
repo = named === undefined ? undefined : decodeURIComponent(named) || "?";
|
|
@@ -21280,9 +21460,17 @@ var apiAction = (tool, args, stdin) => {
|
|
|
21280
21460
|
repo = "?";
|
|
21281
21461
|
}
|
|
21282
21462
|
const at = repo === undefined ? {} : { repo };
|
|
21283
|
-
if (API_MERGE[tool].test(
|
|
21463
|
+
if (API_MERGE[tool].test(route))
|
|
21284
21464
|
return { ...merge, ...at };
|
|
21285
|
-
const
|
|
21465
|
+
const defaultBranch = API_REPOSITORY[tool].test(route) && (request.unread || values.some((value) => /default_branch/.test(value)));
|
|
21466
|
+
if (defaultBranch || API_SETTING[tool].some((pattern) => pattern.test(route)))
|
|
21467
|
+
return { ...setting, ...at };
|
|
21468
|
+
const shape = API_REF[tool].find(([pattern]) => pattern.test(route))?.[1];
|
|
21469
|
+
if (shape) {
|
|
21470
|
+
const { named: refs, certain } = restRef(route, fields, !request.unread && !request.input);
|
|
21471
|
+
return { ...refWrite(tool, new Set([shape]), refs, certain), ...at };
|
|
21472
|
+
}
|
|
21473
|
+
const grant = /\/releases(?:\/|$)/i.test(route) ? "release" : (tool === "gh" ? /\/pulls(?:\/\d+)?\/?$/i : /\/merge_requests(?:\/\d+)?\/?$/i).test(route) ? "pr" : null;
|
|
21286
21474
|
return grant ? { kind: "forge", forge: tool, grant, ...at } : null;
|
|
21287
21475
|
};
|
|
21288
21476
|
var subtreePush = (args) => {
|
|
@@ -21300,7 +21488,7 @@ var subtreePush = (args) => {
|
|
|
21300
21488
|
function rawAction(invocation) {
|
|
21301
21489
|
const args = invocation.args;
|
|
21302
21490
|
if (invocation.tool !== "git" && args[0] === "api")
|
|
21303
|
-
return apiAction(invocation.tool, args, invocation.stdin);
|
|
21491
|
+
return apiAction(invocation.tool, args, invocation.stdin, invocation.expanded);
|
|
21304
21492
|
if (asksHelp(invocation))
|
|
21305
21493
|
return null;
|
|
21306
21494
|
const [first] = args;
|
|
@@ -21576,6 +21764,223 @@ var refusal = (action, branch, dir) => {
|
|
|
21576
21764
|
return `workit: raw ${quote("git push")} onto ${branch}, a protected release branch, bypasses workit's protected-branch check. To finish a release or hotfix, push it with ${quote(`workit git push --release ${branch} [--release ${releaseTagPrefixOf(dir)}<version>]`)}: it pushes ${branch} (fast-forward only) and the release tag, verifies the remote and records it, under the ${quote("release")} grant (if refused, ask the user to run ${quote("workit grant set <workspace> release=true")}). Feature work goes through ${quote("workit git push")} and ${quote("workit pr merge")}.`;
|
|
21577
21765
|
return `workit: raw ${quote("git push")}${action.kind === "push" && action.blindForce ? " --force" : ""} onto ${branch}, a protected branch or the default target, bypasses workit's protected-branch check. Push your feature branch with ${quote("workit git push")} (${quote("workit git push --force-with-lease")} to rewrite it) and land it with ${quote("workit pr merge")}.`;
|
|
21578
21766
|
};
|
|
21767
|
+
var PLAIN_EXPANSION = /^(?:[^$`]|\$[A-Za-z_]\w*|\$\{[A-Za-z_]\w*\})*$/u;
|
|
21768
|
+
var shellWord = (text, expands = false) => {
|
|
21769
|
+
if (/^[\w@%+=:,./-]+$/u.test(text))
|
|
21770
|
+
return text;
|
|
21771
|
+
if (expands && text.includes("$") && PLAIN_EXPANSION.test(text))
|
|
21772
|
+
return `"${text.replaceAll(/["\\]/gu, "\\$&")}"`;
|
|
21773
|
+
return `'${text.replaceAll("'", "'\\''")}'`;
|
|
21774
|
+
};
|
|
21775
|
+
var expandingWords = (command, dialect, found = new Set, depth = 0) => {
|
|
21776
|
+
for (const segment of segmentsOf(command, dialect))
|
|
21777
|
+
segment.words.forEach((text, index) => {
|
|
21778
|
+
if (segment.expands?.includes(index))
|
|
21779
|
+
found.add(text);
|
|
21780
|
+
else if (depth < MAX_DEPTH && /\s/u.test(text))
|
|
21781
|
+
expandingWords(text, "posix", found, depth + 1);
|
|
21782
|
+
});
|
|
21783
|
+
return found;
|
|
21784
|
+
};
|
|
21785
|
+
var wordsOf = (command, dialect = "posix") => {
|
|
21786
|
+
const expands = expandsIn(command, dialect);
|
|
21787
|
+
return (text) => shellWord(text, expands(text));
|
|
21788
|
+
};
|
|
21789
|
+
var expandsIn = (command, dialect = "posix") => {
|
|
21790
|
+
let expanding;
|
|
21791
|
+
return (text) => (expanding ??= expandingWords(command, dialect)).has(text);
|
|
21792
|
+
};
|
|
21793
|
+
var oneCall = (command, dialect) => {
|
|
21794
|
+
const steps = /^(?:\s*cd\s+[^\s;&|<>()$`'"\\]+\s*&&)*([\s\S]*)$/u.exec(command);
|
|
21795
|
+
return !!steps && !!simpleCommand(steps[1], dialect);
|
|
21796
|
+
};
|
|
21797
|
+
var flagWord = (flag, value, asWritten) => value.startsWith("-") ? [`${flag}=${asWritten(value)}`] : [flag, asWritten(value)];
|
|
21798
|
+
var PR_FLAGS = {
|
|
21799
|
+
"gh ready": { verb: "ready", booleans: { "--undo": ["--undo"] }, values: {} },
|
|
21800
|
+
"gh merge": {
|
|
21801
|
+
verb: "merge",
|
|
21802
|
+
booleans: {
|
|
21803
|
+
"--squash": ["--squash"],
|
|
21804
|
+
"-s": ["--squash"],
|
|
21805
|
+
"--merge": ["--merge"],
|
|
21806
|
+
"-m": ["--merge"],
|
|
21807
|
+
"--rebase": ["--rebase"],
|
|
21808
|
+
"-r": ["--rebase"],
|
|
21809
|
+
"--delete-branch": ["--delete-branch"],
|
|
21810
|
+
"-d": ["--delete-branch"]
|
|
21811
|
+
},
|
|
21812
|
+
values: {
|
|
21813
|
+
"--subject": { flag: "--subject" },
|
|
21814
|
+
"-t": { flag: "--subject" },
|
|
21815
|
+
"--body": { flag: "--body" },
|
|
21816
|
+
"-b": { flag: "--body" },
|
|
21817
|
+
"--body-file": { flag: "--body-file" },
|
|
21818
|
+
"-F": { flag: "--body-file" }
|
|
21819
|
+
}
|
|
21820
|
+
},
|
|
21821
|
+
"gh edit": {
|
|
21822
|
+
verb: "edit",
|
|
21823
|
+
booleans: {},
|
|
21824
|
+
values: {
|
|
21825
|
+
"--title": { flag: "--title" },
|
|
21826
|
+
"-t": { flag: "--title" },
|
|
21827
|
+
"--body-file": { flag: "--body-file" },
|
|
21828
|
+
"-F": { flag: "--body-file" },
|
|
21829
|
+
"--add-label": { flag: "--add-label", split: true },
|
|
21830
|
+
"--remove-label": { flag: "--remove-label", split: true },
|
|
21831
|
+
"--add-reviewer": { flag: "--add-reviewer", split: true },
|
|
21832
|
+
"--base": { flag: "--base" },
|
|
21833
|
+
"-B": { flag: "--base" }
|
|
21834
|
+
}
|
|
21835
|
+
},
|
|
21836
|
+
"glab merge": {
|
|
21837
|
+
verb: "merge",
|
|
21838
|
+
booleans: {
|
|
21839
|
+
"--squash": ["--squash"],
|
|
21840
|
+
"-s": ["--squash"],
|
|
21841
|
+
"--rebase": ["--rebase"],
|
|
21842
|
+
"-r": ["--rebase"],
|
|
21843
|
+
"--remove-source-branch": ["--delete-branch"],
|
|
21844
|
+
"-d": ["--delete-branch"],
|
|
21845
|
+
"--yes": [],
|
|
21846
|
+
"-y": []
|
|
21847
|
+
},
|
|
21848
|
+
values: {}
|
|
21849
|
+
},
|
|
21850
|
+
"glab update": {
|
|
21851
|
+
verb: "edit",
|
|
21852
|
+
booleans: { "--ready": [], "-r": [], "--draft": ["--undo"], "--yes": [], "-y": [] },
|
|
21853
|
+
values: {
|
|
21854
|
+
"--title": { flag: "--title" },
|
|
21855
|
+
"-t": { flag: "--title" },
|
|
21856
|
+
"--label": { flag: "--add-label", split: true },
|
|
21857
|
+
"-l": { flag: "--add-label", split: true },
|
|
21858
|
+
"--unlabel": { flag: "--remove-label", split: true },
|
|
21859
|
+
"-u": { flag: "--remove-label", split: true },
|
|
21860
|
+
"--target-branch": { flag: "--base" }
|
|
21861
|
+
}
|
|
21862
|
+
}
|
|
21863
|
+
};
|
|
21864
|
+
var prRetry = (cwd, repo, invocation, cache, asWritten) => {
|
|
21865
|
+
const forge = invocation.tool;
|
|
21866
|
+
if (forge === "git")
|
|
21867
|
+
return null;
|
|
21868
|
+
const values = VALUE_OPTIONS[forge];
|
|
21869
|
+
const args = invocation.args;
|
|
21870
|
+
let verb;
|
|
21871
|
+
let at = 1;
|
|
21872
|
+
for (;at < args.length; at++) {
|
|
21873
|
+
if (!args[at].startsWith("-")) {
|
|
21874
|
+
verb = args[at];
|
|
21875
|
+
break;
|
|
21876
|
+
}
|
|
21877
|
+
if (values.has(args[at]))
|
|
21878
|
+
at++;
|
|
21879
|
+
}
|
|
21880
|
+
const table = PR_FLAGS[`${forge} ${verb}`];
|
|
21881
|
+
if (!table)
|
|
21882
|
+
return null;
|
|
21883
|
+
const words = [];
|
|
21884
|
+
const repos = [];
|
|
21885
|
+
let selector;
|
|
21886
|
+
let ready = false;
|
|
21887
|
+
const rest = [...args.slice(1, at), ...args.slice(at + 1)];
|
|
21888
|
+
for (let index = 0;index < rest.length; index++) {
|
|
21889
|
+
const arg = rest[index];
|
|
21890
|
+
const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
|
|
21891
|
+
const name = eq > 0 ? arg.slice(0, eq) : arg;
|
|
21892
|
+
const value = () => eq > 0 ? arg.slice(eq + 1) : rest[++index];
|
|
21893
|
+
if (name === "-R" || name === "--repo") {
|
|
21894
|
+
const named = value();
|
|
21895
|
+
if (named === undefined)
|
|
21896
|
+
return null;
|
|
21897
|
+
repos.push(named);
|
|
21898
|
+
} else if (/^-R./.test(arg))
|
|
21899
|
+
repos.push(arg.slice(2).replace(/^=/, ""));
|
|
21900
|
+
else if (eq < 0 && Object.hasOwn(table.booleans, arg)) {
|
|
21901
|
+
if (forge === "glab" && (arg === "--ready" || arg === "-r" || arg === "--draft")) {
|
|
21902
|
+
if (ready && words.includes("--undo") !== (arg === "--draft"))
|
|
21903
|
+
return null;
|
|
21904
|
+
ready = true;
|
|
21905
|
+
}
|
|
21906
|
+
words.push(...table.booleans[arg]);
|
|
21907
|
+
} else if (Object.hasOwn(table.values, name)) {
|
|
21908
|
+
const given = value();
|
|
21909
|
+
if (given === undefined)
|
|
21910
|
+
return null;
|
|
21911
|
+
const { flag, split } = table.values[name];
|
|
21912
|
+
if (split && given.includes(",") && /[$`]/.test(given))
|
|
21913
|
+
return null;
|
|
21914
|
+
for (const item of split ? given.split(",").filter(Boolean) : [given])
|
|
21915
|
+
words.push(...flagWord(flag, item, asWritten));
|
|
21916
|
+
} else if (arg.startsWith("-") || selector !== undefined)
|
|
21917
|
+
return null;
|
|
21918
|
+
else
|
|
21919
|
+
selector = arg;
|
|
21920
|
+
}
|
|
21921
|
+
const workitVerb = ready ? "ready" : table.verb;
|
|
21922
|
+
if (ready && words.some((word) => word !== "--undo"))
|
|
21923
|
+
return null;
|
|
21924
|
+
const pr = [];
|
|
21925
|
+
if (selector !== undefined) {
|
|
21926
|
+
const url = /^(https?:\/\/[^/]+\/.+?)\/(?:-\/)?(?:pull|merge_requests)\/(\d+)(?:[/?#].*)?$/.exec(selector);
|
|
21927
|
+
const number = url?.[2] ?? /^[#!]?(\d+)$/.exec(selector)?.[1];
|
|
21928
|
+
if (url)
|
|
21929
|
+
repos.push(url[1]);
|
|
21930
|
+
if (number)
|
|
21931
|
+
pr.push("--pr", number);
|
|
21932
|
+
else if (/\$[A-Za-z_{]/.test(selector))
|
|
21933
|
+
pr.push("--pr", asWritten(selector));
|
|
21934
|
+
else if (selector !== repo.branch)
|
|
21935
|
+
return null;
|
|
21936
|
+
}
|
|
21937
|
+
const env = invocation.env ?? {};
|
|
21938
|
+
if (forge === "gh" && (env.GH_REPO ?? process.env.GH_REPO))
|
|
21939
|
+
repos.push(env.GH_REPO ?? process.env.GH_REPO ?? "");
|
|
21940
|
+
if (repos.length) {
|
|
21941
|
+
const config = gitConfig(repo.dir, invocation, cache);
|
|
21942
|
+
const { GH_REPO: _named, ...own } = env;
|
|
21943
|
+
const key = (named, from) => {
|
|
21944
|
+
const found = forgeRepo(forge === "gh", named, from, config, repo.branch, repo.dir);
|
|
21945
|
+
return found instanceof Error ? null : found.remotes[0]?.key.toLowerCase() ?? null;
|
|
21946
|
+
};
|
|
21947
|
+
const checkout = key("", own);
|
|
21948
|
+
if (!checkout || repos.some((named) => /[$`]/.test(named) || key(named, own) !== checkout))
|
|
21949
|
+
return null;
|
|
21950
|
+
}
|
|
21951
|
+
const dir = path31.resolve(cwd, invocation.dir ?? ".");
|
|
21952
|
+
const call = [
|
|
21953
|
+
`workit pr ${workitVerb}`,
|
|
21954
|
+
...dir === path31.resolve(cwd) ? [] : ["--cwd", shellWord(dir)],
|
|
21955
|
+
...pr,
|
|
21956
|
+
...words
|
|
21957
|
+
].join(" ");
|
|
21958
|
+
return { raw: `${forge} ${forge === "gh" ? "pr" : "mr"} ${verb}`, call };
|
|
21959
|
+
};
|
|
21960
|
+
var prWriteRefusal = (writes, retry) => {
|
|
21961
|
+
const raws = [...new Set(writes.map((write) => quote(write.raw)))].join(", ");
|
|
21962
|
+
const calls = writes.map((write) => quote(write.call)).join(", ");
|
|
21963
|
+
const why = `workit: raw ${raws} changes the PR past workit's checks (the pr grant, and that the PR is this session's own).`;
|
|
21964
|
+
if (retry && writes.length === 1)
|
|
21965
|
+
return `${why} Run ${calls} instead.
|
|
21966
|
+
Retry as: ${writes[0].call}`;
|
|
21967
|
+
return `${why} Run ${writes.length > 1 ? `each as its own call: ${calls}` : `${calls} as its own call`}, in place of the raw ${writes.length > 1 ? "ones" : "one"}; the rest of this command is yours to run apart.`;
|
|
21968
|
+
};
|
|
21969
|
+
var refWriteRefusal = (action) => {
|
|
21970
|
+
if (action.unread)
|
|
21971
|
+
return `workit: raw ${quote(`${action.forge} api graphql`)} sends a document the hook cannot read (a file, stdin it does not see, or a shell expansion), so it may merge, write a ref or change branch protection past workit's checks. Write the document inline in single quotes, run the change through ${quote("workit git push")}, ${quote("workit release tag <vX.Y.Z>")} or ${quote("workit pr merge")}, or ask the user to run it.`;
|
|
21972
|
+
if (action.setting)
|
|
21973
|
+
return `workit: raw ${quote(`${action.forge} api`)} changes branch protection, a ruleset or the default branch on the forge directly: that guards what ${quote("workit git push")} and ${quote("workit pr merge")} may do, and no agent call changes it. Ask the user to change it in the forge's settings.`;
|
|
21974
|
+
const steers = [
|
|
21975
|
+
...action.branch ? [
|
|
21976
|
+
`push a branch with ${quote("workit git push")} (it refuses protected branches and verifies the remote tip)`
|
|
21977
|
+
] : [],
|
|
21978
|
+
...action.tag ? [
|
|
21979
|
+
`tag a release with ${quote("workit release tag <vX.Y.Z>")} or ${quote("workit git push --release <tag>")}, under the ${quote("release")} grant`
|
|
21980
|
+
] : []
|
|
21981
|
+
];
|
|
21982
|
+
return `workit: raw ${quote(`${action.forge} api`)} writes ${action.ref ?? (action.tag && !action.branch ? "a tag" : action.branch && !action.tag ? "a branch" : "a ref")} on the forge directly, past workit's protected-branch check${action.tag ? " and the release grant" : ""}. Instead, ${steers.join("; ")}.`;
|
|
21983
|
+
};
|
|
21579
21984
|
var refFacts = (repo, remote) => {
|
|
21580
21985
|
const facts = {
|
|
21581
21986
|
heads: new Set,
|
|
@@ -21724,6 +22129,7 @@ var nudgeFor = (action, host, session) => {
|
|
|
21724
22129
|
case "pr-read":
|
|
21725
22130
|
case "forge":
|
|
21726
22131
|
case "merge":
|
|
22132
|
+
case "ref-write":
|
|
21727
22133
|
return null;
|
|
21728
22134
|
}
|
|
21729
22135
|
};
|
|
@@ -21741,8 +22147,10 @@ var pushRefusal = (action, repo, config) => {
|
|
|
21741
22147
|
return offPolicy;
|
|
21742
22148
|
for (const target of targets) {
|
|
21743
22149
|
const guarded = guardedTarget(repo.dir, target ?? repo.branch ?? "");
|
|
21744
|
-
if (guarded)
|
|
21745
|
-
|
|
22150
|
+
if (!guarded)
|
|
22151
|
+
continue;
|
|
22152
|
+
const first = !action.blindForce && !action.deletes && !facts.remoteHeads.has(guarded) ? ` ${remote} has no ${guarded} as last fetched: if it is a new, empty remote, ${quote("workit git push")} from ${guarded} makes that first push (it checks the remote first).` : "";
|
|
22153
|
+
return refusal(action, guarded, repo.dir) + first;
|
|
21746
22154
|
}
|
|
21747
22155
|
return tagRefusal(pushed, facts, repo.dir) ?? (action.deletes ? null : offPolicyPush(pushed, repo, facts, remote));
|
|
21748
22156
|
};
|
|
@@ -21924,6 +22332,8 @@ var commitRefusal = (input, command, dialect, { action, repo, invocation, workit
|
|
|
21924
22332
|
try {
|
|
21925
22333
|
guarded = !!repo.branch && resolveBranchPolicyFor(repo.dir).protected.has(repo.branch.toLowerCase());
|
|
21926
22334
|
} catch {}
|
|
22335
|
+
if (guarded && !switches && noRefs(repo))
|
|
22336
|
+
return `workit: raw ${quote("git commit")} on ${repo.branch}, a protected branch. This repository has no commit yet, so its root commit may go there: run ${quote("workit git commit -m '<msg>' [--all | -- <paths>]")} (it adds the Workit-Session trailer; later work goes on a branch).`;
|
|
21927
22337
|
if (guarded && !switches)
|
|
21928
22338
|
return `workit: raw ${quote("git commit")} on ${repo.branch}, a protected branch. Branch first: ${quote("workit git branch --kind feature --slug <slug>")} (uncommitted changes come along), then ${quote("workit git commit -m '<msg>' -- <paths>")}.`;
|
|
21929
22339
|
const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path31.resolve(input.cwd, invocation.dir), repo);
|
|
@@ -21933,6 +22343,8 @@ function rawGitPre(input, command, options = {}) {
|
|
|
21933
22343
|
try {
|
|
21934
22344
|
const dialect = dialectOf(input);
|
|
21935
22345
|
const nudges = new Map;
|
|
22346
|
+
const prWrites = [];
|
|
22347
|
+
const asWritten = wordsOf(command, dialect);
|
|
21936
22348
|
let store = null;
|
|
21937
22349
|
const cache = new Map;
|
|
21938
22350
|
const blind = rawInvocations(command, dialect).find((raw) => raw.redirect && rawAction(raw)?.kind === "push");
|
|
@@ -21953,8 +22365,19 @@ function rawGitPre(input, command, options = {}) {
|
|
|
21953
22365
|
if (!workit)
|
|
21954
22366
|
continue;
|
|
21955
22367
|
store ??= repo.location.dir;
|
|
21956
|
-
if (action.kind === "merge")
|
|
21957
|
-
|
|
22368
|
+
if (action.kind === "merge") {
|
|
22369
|
+
const retry = prRetry(input.cwd, repo, invocation, cache, asWritten);
|
|
22370
|
+
const named = !retry ? "" : oneCall(command, dialect) ? `
|
|
22371
|
+
Retry as: ${retry.call}` : ` Run ${quote(retry.call)} as its own call, in place of the raw one; the rest of this command is yours to run apart.`;
|
|
22372
|
+
return deny(`${refusal(action, null)}${named}`);
|
|
22373
|
+
}
|
|
22374
|
+
if (action.kind === "ref-write")
|
|
22375
|
+
return deny(refWriteRefusal(action));
|
|
22376
|
+
if (action.kind === "forge" && action.grant === "pr") {
|
|
22377
|
+
const retry = prRetry(input.cwd, repo, invocation, cache, asWritten);
|
|
22378
|
+
if (retry)
|
|
22379
|
+
prWrites.push(retry);
|
|
22380
|
+
}
|
|
21958
22381
|
if (action.kind === "push") {
|
|
21959
22382
|
const refused = pushRefusal(action, repo, gitConfig(repo.dir, invocation, cache));
|
|
21960
22383
|
if (refused)
|
|
@@ -21964,6 +22387,8 @@ function rawGitPre(input, command, options = {}) {
|
|
|
21964
22387
|
if (nudge && !nudges.has(nudgeKind(action)))
|
|
21965
22388
|
nudges.set(nudgeKind(action), nudge);
|
|
21966
22389
|
}
|
|
22390
|
+
if (prWrites.length)
|
|
22391
|
+
return deny(prWriteRefusal(prWrites, oneCall(command, dialect)));
|
|
21967
22392
|
const pkill = options.nudge === false ? null : pkillSelfMatch(command, dialect);
|
|
21968
22393
|
const pkillNote = pkill ? { kind: "context", text: pkill } : NONE2;
|
|
21969
22394
|
if (options.nudge === false || !store || nudges.size === 0)
|
|
@@ -22047,6 +22472,8 @@ var grantRefusal = (action, repo, invocation, cache) => {
|
|
|
22047
22472
|
kinds.push("pr");
|
|
22048
22473
|
else if (action.kind === "forge")
|
|
22049
22474
|
kinds.push(action.grant);
|
|
22475
|
+
else if (action.kind === "ref-write")
|
|
22476
|
+
kinds.push(...action.branch ? ["push"] : [], ...action.tag ? ["release"] : [], ...action.unread ? ["merge"] : []);
|
|
22050
22477
|
for (const kind of kinds) {
|
|
22051
22478
|
const denied = rawGrantDenial(repo.dir, kind, target);
|
|
22052
22479
|
if (denied)
|
|
@@ -22054,6 +22481,21 @@ var grantRefusal = (action, repo, invocation, cache) => {
|
|
|
22054
22481
|
}
|
|
22055
22482
|
return null;
|
|
22056
22483
|
};
|
|
22484
|
+
var noRefs = (repo) => {
|
|
22485
|
+
const common = path31.dirname(repo.location.dir);
|
|
22486
|
+
const holds = (dir) => {
|
|
22487
|
+
try {
|
|
22488
|
+
return fs21.readdirSync(dir, { withFileTypes: true }).some((entry) => entry.isFile() || entry.isDirectory() && holds(path31.join(dir, entry.name)));
|
|
22489
|
+
} catch {
|
|
22490
|
+
return false;
|
|
22491
|
+
}
|
|
22492
|
+
};
|
|
22493
|
+
try {
|
|
22494
|
+
if (/ refs\//.test(fs21.readFileSync(path31.join(common, "packed-refs"), "utf8")))
|
|
22495
|
+
return false;
|
|
22496
|
+
} catch {}
|
|
22497
|
+
return fs21.existsSync(path31.join(common, "refs")) && !holds(path31.join(common, "refs"));
|
|
22498
|
+
};
|
|
22057
22499
|
var localTag = (repo, name) => {
|
|
22058
22500
|
const common = path31.dirname(repo.location.dir);
|
|
22059
22501
|
try {
|
|
@@ -27382,8 +27824,7 @@ var linesOf = (command, dialect) => {
|
|
|
27382
27824
|
return null;
|
|
27383
27825
|
}
|
|
27384
27826
|
};
|
|
27385
|
-
var
|
|
27386
|
-
var leaseCommand = (words) => `workit check --heavy -- ${words.map(quoteWord).join(" ")}`;
|
|
27827
|
+
var leaseCommand = (words, word) => `workit check --heavy -- ${words.map(word).join(" ")}`;
|
|
27387
27828
|
function heavyPlan(command, options) {
|
|
27388
27829
|
const dialect = options.dialect ?? "posix";
|
|
27389
27830
|
if (dialect !== "posix" || !gitTop(options.cwd))
|
|
@@ -27416,7 +27857,8 @@ function heavyPlan(command, options) {
|
|
|
27416
27857
|
}));
|
|
27417
27858
|
return rewrite ? { kind: "rewrite", command: rewrite, reason: single.reason } : { kind: "none" };
|
|
27418
27859
|
}
|
|
27419
|
-
const
|
|
27860
|
+
const word = wordsOf(command, dialect);
|
|
27861
|
+
const parts = heavy.map((match) => leaseCommand(match.line, word));
|
|
27420
27862
|
return {
|
|
27421
27863
|
kind: "split",
|
|
27422
27864
|
reason: `heavy_command: \`${command.trim()}\` chains heavy work (${heavy.map((match) => match.reason).join("; ")}) with other commands, and a chain cannot run under the machine-wide heavy-check lease. Run the heavy part alone, now: \`${parts[0]}\`; then run the other parts as their own commands${parts.length > 1 ? ", each heavy one the same way" : ""}.`,
|
|
@@ -27438,7 +27880,7 @@ function serverPlan(command, options) {
|
|
|
27438
27880
|
const rewrite = leaseRewrite(command)?.replace("workit check --heavy --", "workit run --bg --");
|
|
27439
27881
|
return rewrite ? { kind: "rewrite", command: rewrite, reason: single, server: true } : { kind: "none" };
|
|
27440
27882
|
}
|
|
27441
|
-
const start = `workit run --bg -- ${found.line.map(
|
|
27883
|
+
const start = `workit run --bg -- ${found.line.map(wordsOf(command, dialect)).join(" ")}`;
|
|
27442
27884
|
return {
|
|
27443
27885
|
kind: "split",
|
|
27444
27886
|
reason: `dev_server: \`${command.trim()}\` chains a dev server (${found.reason}) with other commands. Start it alone, now: \`${start}\`; then run the other parts as their own commands.`,
|
|
@@ -27473,7 +27915,7 @@ function leaseRewrite(command) {
|
|
|
27473
27915
|
import fs27 from "node:fs";
|
|
27474
27916
|
import path40 from "node:path";
|
|
27475
27917
|
var HEAVY_WORDS = new Set(("npm npx pnpm pnpx yarn bun bunx deno corepack make gmake docker podman nerdctl " + "python python3 py uv poetry pdm pipenv hatch rye bundle rake nx " + "jest vitest mocha ava tap karma jasmine nyc c8 tsc vue-tsc svelte-check eslint stylelint " + "tslint webpack webpack-cli rollup parcel tsup vite next nuxt nuxi astro ng react-scripts " + "playwright cypress wdio testcafe turbo lerna sonar-scanner sonarless sonarless-mcp go " + "golangci-lint gotestsum staticcheck cargo mvn mvnw gradle gradlew ant sbt bazel bazelisk " + "buck2 dotnet msbuild pytest py.test tox nox mypy pyright pylint coverage maturin pip pip3 " + "rspec rails phpunit pest phpstan psalm composer mix swift xcodebuild flutter dart pod cmake " + "ninja meson ctest scons docker-compose buildah earthly").split(" "));
|
|
27476
|
-
var
|
|
27918
|
+
var wordsOf2 = (command) => command.split(/[\s;&|()<>`'"]+/u).map((word) => (word.split(/[\\/]/u).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd|bat)$/u, "")).filter(Boolean);
|
|
27477
27919
|
var stateDir3 = (env) => stateDir(env);
|
|
27478
27920
|
var readJson2 = (file) => {
|
|
27479
27921
|
try {
|
|
@@ -27499,7 +27941,7 @@ var patternWords = (cwd, env) => {
|
|
|
27499
27941
|
for (const pattern of patterns) {
|
|
27500
27942
|
if (typeof pattern !== "string")
|
|
27501
27943
|
continue;
|
|
27502
|
-
const first =
|
|
27944
|
+
const first = wordsOf2(pattern)[0];
|
|
27503
27945
|
if (!first || first.includes("*"))
|
|
27504
27946
|
return null;
|
|
27505
27947
|
words.add(first);
|
|
@@ -27508,7 +27950,7 @@ var patternWords = (cwd, env) => {
|
|
|
27508
27950
|
};
|
|
27509
27951
|
function maybeHeavy(command, cwd, env = process.env) {
|
|
27510
27952
|
try {
|
|
27511
|
-
const words =
|
|
27953
|
+
const words = wordsOf2(command);
|
|
27512
27954
|
if (words.some((word) => HEAVY_WORDS.has(word) || /^python[\d.]*$/u.test(word)))
|
|
27513
27955
|
return true;
|
|
27514
27956
|
const extra = patternWords(cwd, env);
|
|
@@ -28235,7 +28677,7 @@ var wrappedScript = (input) => {
|
|
|
28235
28677
|
const script = shellScript3(tail.argv);
|
|
28236
28678
|
if (SCRIPT_SHELLS.has((tail.argv[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()) && script)
|
|
28237
28679
|
return script;
|
|
28238
|
-
return tail.argv.map(
|
|
28680
|
+
return tail.argv.map(quoteWord).join(" ");
|
|
28239
28681
|
};
|
|
28240
28682
|
var editsOf = (input) => {
|
|
28241
28683
|
const words = pastLead(input);
|
|
@@ -29113,7 +29555,7 @@ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
|
|
|
29113
29555
|
return lost;
|
|
29114
29556
|
return target === undefined ? os10.homedir() : path43.resolve(dir, target);
|
|
29115
29557
|
};
|
|
29116
|
-
var
|
|
29558
|
+
var quoteWord = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
29117
29559
|
var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
|
|
29118
29560
|
const value = vars.get(bare ?? braced ?? "");
|
|
29119
29561
|
return value === undefined ? whole : value;
|
|
@@ -29511,7 +29953,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
29511
29953
|
targets.push(cmd && CMD_VAR.test(file) ? placeholderIn(dir, `${OPAQUE_TARGET}cmd`) : file);
|
|
29512
29954
|
const bare = strict && depth < 4 ? unwrapped2(words) : null;
|
|
29513
29955
|
if (bare?.length && dir !== undefined)
|
|
29514
|
-
targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(
|
|
29956
|
+
targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord).join(" "), "posix", depth + 1, strict, vars));
|
|
29515
29957
|
if (strict === "registry" && dir !== undefined && depth < 4) {
|
|
29516
29958
|
const run = words.slice(Math.max(0, words.findIndex((word) => !PREFIXES2.has(word))));
|
|
29517
29959
|
const [verb = "", ...args] = run.map((word, index) => index ? word : (word.split(/[\\/]/).at(-1) ?? "").toLowerCase());
|
|
@@ -29646,7 +30088,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
29646
30088
|
if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file) && !(dialect === "powershell" && /^(?:\$null|nul)$/i.test(file)))
|
|
29647
30089
|
targets.push(...atAll(file));
|
|
29648
30090
|
if (dir !== undefined)
|
|
29649
|
-
for (const invocation of workitInvocations(body.map(
|
|
30091
|
+
for (const invocation of workitInvocations(body.map(quoteWord).join(" "), "posix")) {
|
|
29650
30092
|
const { at: runsIn, args } = workitCwd(dir, invocation, atAll);
|
|
29651
30093
|
if (args[0] === "git" && MUTATING_WORKIT_GIT.has(args[1] ?? "") && !inert(args.slice(2), ""))
|
|
29652
30094
|
targets.push(...runsIn.map((runs) => placeholderIn(runs, DIR_TARGET)));
|
|
@@ -29655,7 +30097,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
|
|
|
29655
30097
|
return targets;
|
|
29656
30098
|
};
|
|
29657
30099
|
var workitRunDir = (dir, words, resolve) => {
|
|
29658
|
-
for (const invocation of workitInvocations(words.map(
|
|
30100
|
+
for (const invocation of workitInvocations(words.map(quoteWord).join(" "), "posix")) {
|
|
29659
30101
|
const { at, args } = workitCwd(dir, invocation, resolve);
|
|
29660
30102
|
if (args[0] === "check" || args[0] === "lock" && args[1] === "run")
|
|
29661
30103
|
return at;
|
|
@@ -32573,7 +33015,7 @@ var workitCallDir = (command, dialect) => {
|
|
|
32573
33015
|
const call = plainWorkitCall(command, dialect);
|
|
32574
33016
|
return call?.cwd && path51.isAbsolute(call.cwd) ? call.cwd : null;
|
|
32575
33017
|
};
|
|
32576
|
-
var
|
|
33018
|
+
var shellWord2 = (dir) => /^[\w@%+=:,./-]+$/u.test(dir) ? dir : `'${dir.replaceAll("'", `'\\''`)}'`;
|
|
32577
33019
|
var cwdAt = (words, index) => words[index] === "--cwd" && words[index + 1] !== undefined ? 2 : words[index]?.startsWith("--cwd=") ? 1 : 0;
|
|
32578
33020
|
var plainRetry = (dir, command) => {
|
|
32579
33021
|
const call = plainWorkitCall(command, "posix");
|
|
@@ -32622,7 +33064,7 @@ var plainRetry = (dir, command) => {
|
|
|
32622
33064
|
if (parts.includes(null))
|
|
32623
33065
|
return null;
|
|
32624
33066
|
const [envText, globalText, verbText, restText] = parts;
|
|
32625
|
-
const cwd = ["--cwd",
|
|
33067
|
+
const cwd = ["--cwd", shellWord2(dir)];
|
|
32626
33068
|
const body = [...globalText, ...verbText, ...cwd, ...restText];
|
|
32627
33069
|
return { retry: [...envText, "workit", ...body].join(" "), dropped };
|
|
32628
33070
|
};
|
|
@@ -34505,11 +34947,12 @@ var hinted = (write) => write.hint ? {
|
|
|
34505
34947
|
plain: false,
|
|
34506
34948
|
workit: write.hint
|
|
34507
34949
|
} : write;
|
|
34508
|
-
var ytrackArgs = (line, found, depth, names, plain) => {
|
|
34950
|
+
var ytrackArgs = (line, found, depth, names, plain, expands = () => false) => {
|
|
34509
34951
|
const inner = (script) => void found.push(...ytrackWrites(script, "posix", depth + 1, plain));
|
|
34510
34952
|
const tail = workitCheckTail(line);
|
|
34511
34953
|
if (tail) {
|
|
34512
|
-
|
|
34954
|
+
const live = (text) => expands(text) && /[$`]/.test(text) ? `"${text.replaceAll(/["\\]/g, "\\$&")}"` : quote3(text);
|
|
34955
|
+
inner("script" in tail ? tail.script : tail.argv.map(live).join(" "));
|
|
34513
34956
|
return true;
|
|
34514
34957
|
}
|
|
34515
34958
|
const flag = SHELLS3.test(name2(line[0])) ? line.findIndex((word, index) => index > 0 && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(word)) : -1;
|
|
@@ -34539,8 +34982,9 @@ var ytrackArgs = (line, found, depth, names, plain) => {
|
|
|
34539
34982
|
const argv = [...alias ?? [], ...line.slice(at + 1)];
|
|
34540
34983
|
const write = classify2(argv);
|
|
34541
34984
|
if (write) {
|
|
34985
|
+
const word = (text) => plain ? quote3(text) : shellWord(text, expands(text));
|
|
34542
34986
|
const one = {
|
|
34543
|
-
command: ["ytrack", ...argv].map(
|
|
34987
|
+
command: ["ytrack", ...argv].map(word).join(" "),
|
|
34544
34988
|
...write,
|
|
34545
34989
|
...hostsOf(argv),
|
|
34546
34990
|
plain
|
|
@@ -34643,14 +35087,15 @@ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
|
|
|
34643
35087
|
let found = [];
|
|
34644
35088
|
const lines = plain ? plainLines(command, dialect) : null;
|
|
34645
35089
|
const none = new Map;
|
|
35090
|
+
const expands = expandsIn(command, dialect);
|
|
34646
35091
|
const plainFirst = lines ? ytrackArgs(lines.first, found, depth, none, true) : false;
|
|
34647
35092
|
const joined = lines && plainFirst ? chained(found, lines.chain, depth) : null;
|
|
34648
35093
|
if (joined)
|
|
34649
35094
|
found = joined;
|
|
34650
|
-
if (!lines || !plainFirst || !(joined ? [] : lines.chain).every((line) => ytrackArgs(line, found, depth, none, false)) || !lines.later.every((line) => ytrackArgs(line, found, depth, none, false))) {
|
|
35095
|
+
if (!lines || !plainFirst || !(joined ? [] : lines.chain).every((line) => ytrackArgs(line, found, depth, none, false, expands)) || !lines.later.every((line) => ytrackArgs(line, found, depth, none, false, expands))) {
|
|
34651
35096
|
found = [];
|
|
34652
35097
|
for (const line of commandLines(command, dialect))
|
|
34653
|
-
ytrackArgs(line, found, depth, aliases(command), false);
|
|
35098
|
+
ytrackArgs(line, found, depth, aliases(command), false, expands);
|
|
34654
35099
|
found = found.map(hinted);
|
|
34655
35100
|
}
|
|
34656
35101
|
READ.set(key, found);
|
|
@@ -34660,7 +35105,7 @@ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
|
|
|
34660
35105
|
};
|
|
34661
35106
|
var RELOCATES = /(?<![$\w])YTRACK_CONFIG_DIR\b/;
|
|
34662
35107
|
var reachesOnly = (allowed, write) => write.plain && !!write.hosts?.length && write.hosts.every((host) => youTrackHostAllowed(allowed, host));
|
|
34663
|
-
var scopedGate = (allowed, command, writes) => {
|
|
35108
|
+
var scopedGate = (allowed, command, dialect, writes) => {
|
|
34664
35109
|
const scope = `youtrack.autoHosts (${allowed.join(", ")})`;
|
|
34665
35110
|
if (RELOCATES.test(command))
|
|
34666
35111
|
return {
|
|
@@ -34675,8 +35120,10 @@ var scopedGate = (allowed, command, writes) => {
|
|
|
34675
35120
|
if (!unnamed.length)
|
|
34676
35121
|
return null;
|
|
34677
35122
|
const why = (write) => write.hosts === null ? "its --host is no literal host" : !write.hosts.length ? "it names no --host" : "it is not a plain command of its own";
|
|
34678
|
-
const
|
|
34679
|
-
const
|
|
35123
|
+
const hostless = unnamed.find((each) => each.bare);
|
|
35124
|
+
const expands = expandsIn(command, dialect);
|
|
35125
|
+
const word = (text) => hostless?.plain ? quote3(text) : shellWord(text, expands(text));
|
|
35126
|
+
const retry = hostless?.bare ? ["ytrack", "--host", first, ...hostless.bare].map(word).join(" ") : null;
|
|
34680
35127
|
return {
|
|
34681
35128
|
kind: "deny",
|
|
34682
35129
|
reason: `${scope} posts to YouTrack unasked only from a plain ytrack call that names an allowed host with --host: ${unnamed.map((write) => `\`${write.command}\` (${why(write)})`).join(", ")}. Name the host, as its own plain call.${retry ? `
|
|
@@ -34712,7 +35159,7 @@ var ytrackGate = (cwd, command, dialect, ask) => {
|
|
|
34712
35159
|
const hosts = policy.hosts;
|
|
34713
35160
|
if (hosts === null)
|
|
34714
35161
|
return null;
|
|
34715
|
-
const scoped = scopedGate(hosts, command, writes);
|
|
35162
|
+
const scoped = scopedGate(hosts, command, dialect, writes);
|
|
34716
35163
|
if (scoped)
|
|
34717
35164
|
return scoped;
|
|
34718
35165
|
writes = writes.filter((write) => !reachesOnly(hosts, write));
|