@workit-dev/pi 2.29.2 → 2.29.4

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 CHANGED
@@ -8374,7 +8374,9 @@ Autonomy contract:
8374
8374
  - Continue to the requested endpoint without asking "continue?", running
8375
8375
  checks and repairs.
8376
8376
  Stop only for a new consequential choice, a host denial, a conflicting edit
8377
- or an unresolved blocker; report open gaps and uncertain workers.
8377
+ or an unresolved blocker; report open gaps and uncertain workers. A
8378
+ classifier denying a chained granted verb: rerun it once alone, verb first;
8379
+ a plain call denied: ask in chat, never a terminal hand-off.
8378
8380
  - No endpoint named: stop at a local commit on a policy-compliant branch and
8379
8381
  state the next command. If the request implies delivery (fix, implement,
8380
8382
  ship), go to the effective endpoint in \`workit grant show\`: \`pr\` stops
@@ -8578,6 +8580,46 @@ var API_VALUES = new Set(["--method", "--header", "--raw-field", "--field", "--j
8578
8580
  "--output"
8579
8581
  ]));
8580
8582
  var API_FIELDS = new Set(["-f", "-F", "--raw-field", "--field"]);
8583
+ var GH_REPO_PATH = String.raw`(?:^|\/)(?:repos\/[^/]+\/[^/]+|repositories\/[^/]+)`;
8584
+ var ghPath = (rest) => new RegExp(`${GH_REPO_PATH}\\/${rest}(?:\\/|$)`, "i");
8585
+ var called = (names) => new RegExp(String.raw`\b(?:${names})(?:[\s,\uFEFF]|#[^\n\r]*[\n\r])*\(`);
8586
+ var GRAPHQL_REF = [
8587
+ [called("createRef|updateRefs?|deleteRef"), "ref"],
8588
+ [
8589
+ called("createCommitOnBranch|createLinkedBranch|createBranch|branchDelete|commitCreate"),
8590
+ "branch"
8591
+ ],
8592
+ [called("tagCreate|tagDelete"), "tag"]
8593
+ ];
8594
+ var GRAPHQL_SETTING = called("(?:create|update|delete)(?:BranchProtectionRule|RepositoryRuleset)|branchRule(?:Create|Update|Delete)");
8595
+ var API_REF = {
8596
+ gh: [
8597
+ [ghPath(String.raw`git\/refs?`), "ref"],
8598
+ [ghPath(String.raw`(?:branches\/.+\/rename|merge-upstream|contents)`), "branch"]
8599
+ ],
8600
+ glab: [
8601
+ [/(?:^|\/)repository\/tags(?:\/|$)/i, "tag"],
8602
+ [/(?:^|\/)repository\/(?:branches|merged_branches|files|submodules)(?:\/|$)/i, "branch"],
8603
+ [/(?:^|\/)repository\/commits(?:\/[^/]+\/(?:cherry_pick|revert))?\/?$/i, "branch"]
8604
+ ]
8605
+ };
8606
+ var API_SETTING = {
8607
+ gh: [
8608
+ ghPath(String.raw`(?:branches\/.+|tags)\/protection`),
8609
+ ghPath("rulesets"),
8610
+ ghPath(String.raw`environments\/[^/]+\/deployment-branch-policies`),
8611
+ /(?:^|\/)orgs\/[^/]+\/rulesets(?:\/|$)/i
8612
+ ],
8613
+ glab: [
8614
+ /(?:^|\/)(?:projects|groups)\/[^/]+\/protected_(?:branches|tags)(?:\/|$)/i,
8615
+ /(?:^|\/)projects\/[^/]+\/push_rule(?:\/|$)/i
8616
+ ]
8617
+ };
8618
+ var API_REPOSITORY = {
8619
+ gh: new RegExp(`${GH_REPO_PATH}\\/?$`, "i"),
8620
+ glab: /(?:^|\/)projects\/[^/]+\/?$/i
8621
+ };
8622
+ var BY_ID = called("updateRefs?|deleteRef");
8581
8623
  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
8624
 
8583
8625
  // packages/workit-core/src/core/route-intent.ts
@@ -9590,6 +9632,7 @@ var FLAGS = {
9590
9632
  // packages/workit-core/src/approvals/inline.ts
9591
9633
  var DIR2 = "<dir>";
9592
9634
  var OPAQUE_RELEASE_FIX = `workit release --cwd ${DIR2} notes approve <version>`;
9635
+ var OPAQUE_RELEASE_FIRST = `workit release notes approve --cwd ${DIR2} <version>`;
9593
9636
 
9594
9637
  // packages/workit-core/src/hooks/hosts/fields.ts
9595
9638
  var SHELLS2 = new Set(["sh", "bash", "zsh", "dash", "pwsh", "powershell", "cmd"]);
package/dist/workit.js CHANGED
@@ -18843,7 +18843,9 @@ Autonomy contract:
18843
18843
  - Continue to the requested endpoint without asking "continue?", running
18844
18844
  checks and repairs.
18845
18845
  Stop only for a new consequential choice, a host denial, a conflicting edit
18846
- or an unresolved blocker; report open gaps and uncertain workers.
18846
+ or an unresolved blocker; report open gaps and uncertain workers. A
18847
+ classifier denying a chained granted verb: rerun it once alone, verb first;
18848
+ a plain call denied: ask in chat, never a terminal hand-off.
18847
18849
  - No endpoint named: stop at a local commit on a policy-compliant branch and
18848
18850
  state the next command. If the request implies delivery (fix, implement,
18849
18851
  ship), go to the effective endpoint in \`workit grant show\`: \`pr\` stops
@@ -20826,7 +20828,7 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
20826
20828
  for (const invocation of inside)
20827
20829
  found.push({ ...invocation, dir: rebase(dir, invocation.dir) });
20828
20830
  };
20829
- const visit = (input, stdin, hops) => {
20831
+ const visit = (input, stdin, hops, expands = "all") => {
20830
20832
  const line = /^\$[\w:]+$/.test(input[0] ?? "") && input[1] === "=" ? input.slice(2) : input;
20831
20833
  const split = splitString(line);
20832
20834
  if (split !== null)
@@ -20888,15 +20890,18 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
20888
20890
  nested(cmdScript(words), "powershell");
20889
20891
  else if (name === "xargs" || name === "find")
20890
20892
  runs(name === "xargs" ? xargsCommands(words, stdin) : findCommands(words));
20891
- else if (name === "gh" || name === "glab")
20893
+ else if (name === "gh" || name === "glab") {
20894
+ const shift = input.length - words.length + 1;
20895
+ const expanded = expands === "all" ? expands : expands.filter((at) => at >= shift).map((at) => at - shift);
20892
20896
  found.push({
20893
20897
  tool: name,
20894
20898
  dir,
20895
20899
  args: words.slice(1),
20896
20900
  ...Object.keys({ ...exported, ...env }).length ? { env: { ...exported, ...env } } : {},
20897
- ...stdin === undefined ? {} : { stdin }
20901
+ ...stdin === undefined ? {} : { stdin },
20902
+ ...expanded.length ? { expanded } : {}
20898
20903
  });
20899
- else if (name === "git") {
20904
+ } else if (name === "git") {
20900
20905
  const invocation = gitInvocation(words.slice(1), dir, { ...exported, ...env }, stdin, sessionConfig);
20901
20906
  found.push(invocation);
20902
20907
  sessionConfig.push(...configSetBy(invocation.args));
@@ -20929,7 +20934,7 @@ function walk2(command, dialect, depth, seen, inherited = {}) {
20929
20934
  }
20930
20935
  const stdin = stdinOf(segment, segments[index - 1]);
20931
20936
  for (const line of substitute(segment.words, vars))
20932
- visit(line, stdin, 0);
20937
+ visit(line, stdin, 0, segment.expands ?? []);
20933
20938
  }
20934
20939
  return found;
20935
20940
  }
@@ -21224,55 +21229,232 @@ var API_VALUES = new Set(["--method", "--header", "--raw-field", "--field", "--j
21224
21229
  var API_SHORT_VALUES = "XHfFqtp";
21225
21230
  var API_FIELDS = new Set(["-f", "-F", "--raw-field", "--field"]);
21226
21231
  var API_MERGE = {
21227
- gh: /(?:^|\/)(?:pulls\/[^/?#]+\/merge|merges)\/?(?:[?#]|$)/i,
21228
- glab: /(?:^|\/)merge_requests\/[^/?#]+\/merge\/?(?:[?#]|$)/i
21232
+ gh: /(?:^|\/)(?:pulls\/[^/?#]+\/merge|merges)\/?$/i,
21233
+ glab: /(?:^|\/)merge_requests\/[^/?#]+\/merge\/?$/i
21229
21234
  };
21230
21235
  var GRAPHQL_MERGE = /\b(?:mergePullRequest|enablePullRequestAutoMerge|mergeBranch|mergeRequestAccept)\b/;
21231
- var apiAction = (tool, args, stdin) => {
21232
- const request = { method: null, body: false };
21236
+ var GH_REPO_PATH = String.raw`(?:^|\/)(?:repos\/[^/]+\/[^/]+|repositories\/[^/]+)`;
21237
+ var ghPath = (rest) => new RegExp(`${GH_REPO_PATH}\\/${rest}(?:\\/|$)`, "i");
21238
+ var called = (names) => new RegExp(String.raw`\b(?:${names})(?:[\s,\uFEFF]|#[^\n\r]*[\n\r])*\(`);
21239
+ var GRAPHQL_REF = [
21240
+ [called("createRef|updateRefs?|deleteRef"), "ref"],
21241
+ [
21242
+ called("createCommitOnBranch|createLinkedBranch|createBranch|branchDelete|commitCreate"),
21243
+ "branch"
21244
+ ],
21245
+ [called("tagCreate|tagDelete"), "tag"]
21246
+ ];
21247
+ var GRAPHQL_SETTING = called("(?:create|update|delete)(?:BranchProtectionRule|RepositoryRuleset)|branchRule(?:Create|Update|Delete)");
21248
+ var API_REF = {
21249
+ gh: [
21250
+ [ghPath(String.raw`git\/refs?`), "ref"],
21251
+ [ghPath(String.raw`(?:branches\/.+\/rename|merge-upstream|contents)`), "branch"]
21252
+ ],
21253
+ glab: [
21254
+ [/(?:^|\/)repository\/tags(?:\/|$)/i, "tag"],
21255
+ [/(?:^|\/)repository\/(?:branches|merged_branches|files|submodules)(?:\/|$)/i, "branch"],
21256
+ [/(?:^|\/)repository\/commits(?:\/[^/]+\/(?:cherry_pick|revert))?\/?$/i, "branch"]
21257
+ ]
21258
+ };
21259
+ var API_SETTING = {
21260
+ gh: [
21261
+ ghPath(String.raw`(?:branches\/.+|tags)\/protection`),
21262
+ ghPath("rulesets"),
21263
+ ghPath(String.raw`environments\/[^/]+\/deployment-branch-policies`),
21264
+ /(?:^|\/)orgs\/[^/]+\/rulesets(?:\/|$)/i
21265
+ ],
21266
+ glab: [
21267
+ /(?:^|\/)(?:projects|groups)\/[^/]+\/protected_(?:branches|tags)(?:\/|$)/i,
21268
+ /(?:^|\/)projects\/[^/]+\/push_rule(?:\/|$)/i
21269
+ ]
21270
+ };
21271
+ var API_REPOSITORY = {
21272
+ gh: new RegExp(`${GH_REPO_PATH}\\/?$`, "i"),
21273
+ glab: /(?:^|\/)projects\/[^/]+\/?$/i
21274
+ };
21275
+ var PLAIN_REF = /^refs\/(?:heads|tags)\/(?!.*\.\.)[^\s$`\\%]+$/;
21276
+ var BY_ID = called("updateRefs?|deleteRef");
21277
+ var createdRefs = (query) => {
21278
+ if (/[\\$]|"""/.test(query))
21279
+ return null;
21280
+ const tokens = query.match(/#[^\n\r]*|"[^"\n\r]*"|[_A-Za-z]\w*|[^\s,\uFEFF]/g) ?? [];
21281
+ const named = [];
21282
+ for (let at = 0;at < tokens.length; at++) {
21283
+ if (tokens[at] !== "createRef")
21284
+ continue;
21285
+ const args = tokens.slice(at + 1).filter((token) => !token.startsWith("#"));
21286
+ if (args[0] !== "(")
21287
+ continue;
21288
+ let depth = 0;
21289
+ const names = [];
21290
+ for (let index = 0;index < args.length; index++) {
21291
+ const token = args[index];
21292
+ if (token === "(" || token === "{" || token === "[")
21293
+ depth++;
21294
+ else if (token === ")" || token === "}" || token === "]") {
21295
+ if (--depth === 0)
21296
+ break;
21297
+ } else if (token === "name" && args[index + 1] === ":")
21298
+ names.push(args[index + 2] ?? "");
21299
+ }
21300
+ if (depth !== 0 || names.length !== 1 || !names[0].startsWith('"'))
21301
+ return null;
21302
+ named.push(names[0].slice(1, -1));
21303
+ }
21304
+ return named;
21305
+ };
21306
+ var provablyRead = (query) => /^[\s,\uFEFF]*(?:\{|query[\s,\uFEFF]*[({])/.test(query) && !/\b(?:mutation|subscription)\b/.test(query);
21307
+ var refWrite = (forge, shapes, named, certain) => {
21308
+ const sure = certain && named.length > 0 && named.every((ref) => PLAIN_REF.test(ref));
21309
+ const tags = !sure || named.some((ref) => ref.startsWith("refs/tags/"));
21310
+ const heads = !sure || named.some((ref) => ref.startsWith("refs/heads/"));
21311
+ const ref = shapes.has("ref");
21312
+ return {
21313
+ kind: "ref-write",
21314
+ forge,
21315
+ tag: shapes.has("tag") || ref && tags,
21316
+ branch: shapes.has("branch") || ref && heads,
21317
+ ...ref && sure ? { ref: named[0] } : {}
21318
+ };
21319
+ };
21320
+ var restRef = (route, fields, readable) => {
21321
+ const inPath = /\/git\/refs?\/(.+)$/i.exec(route)?.[1];
21322
+ if (inPath)
21323
+ return { named: [`refs/${inPath}`], certain: true };
21324
+ const refs = fields.filter((field) => field.startsWith("ref=")).map((field) => field.slice(4));
21325
+ const mentions = fields.filter((field) => /refs\//.test(field)).length;
21326
+ return { named: refs, certain: readable && refs.length === 1 && mentions === 1 };
21327
+ };
21328
+ var routeOf = (endpoint) => endpoint.replace(/(?<!:)\/{2,}/g, "/").replace(/[?#][\s\S]*$/, "").replace(/%([\da-f]{2})/gi, (escape, hex) => {
21329
+ const char = String.fromCodePoint(Number.parseInt(hex, 16));
21330
+ return /[\w.~-]/.test(char) ? char : escape;
21331
+ });
21332
+ var apiAction = (tool, args, stdin, expanded = []) => {
21333
+ const request = { method: null, body: false, input: false, unread: false };
21233
21334
  let endpoint = null;
21335
+ let endpointAt = -1;
21234
21336
  const values = [];
21235
- const take = (name, value) => {
21337
+ const fields = [];
21338
+ const queries = [];
21339
+ const field = (value, expands) => {
21340
+ fields.push(value);
21341
+ values.push(value);
21342
+ if (!value.startsWith("query="))
21343
+ return;
21344
+ const text = value.slice(6);
21345
+ const read = expanded !== "all" && (!(expands && /[$`]/.test(text)) || provablyRead(text));
21346
+ queries.push({ text, read });
21347
+ };
21348
+ const fromStdin = (name, value, text) => {
21349
+ if (name !== "--input") {
21350
+ if (text.includes("\\"))
21351
+ request.unread = true;
21352
+ return field(`${value.slice(0, value.indexOf("=") + 1)}${text}`, true);
21353
+ }
21354
+ values.push(text);
21355
+ let body;
21356
+ try {
21357
+ body = JSON.parse(text);
21358
+ } catch {
21359
+ request.unread = true;
21360
+ return;
21361
+ }
21362
+ const strings = (each) => typeof each === "string" ? [each] : each && typeof each === "object" ? Object.entries(each).flatMap(([key, inner]) => [key, ...strings(inner)]) : [];
21363
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
21364
+ values.push(...strings(body));
21365
+ return;
21366
+ }
21367
+ for (const [key, inner] of Object.entries(body)) {
21368
+ if (typeof inner === "string")
21369
+ field(`${key}=${inner}`, true);
21370
+ else
21371
+ values.push(key, ...strings(inner));
21372
+ }
21373
+ };
21374
+ const take = (name, value, at) => {
21375
+ const expands = expanded === "all" || expanded.includes(at);
21236
21376
  if (name === "-X" || name === "--method")
21237
21377
  request.method = value.toUpperCase();
21238
21378
  if (API_FIELDS.has(name) || name === "--input")
21239
21379
  request.body = true;
21240
- values.push(value);
21241
- const fromStdin = name === "--input" ? value === "-" : /^(?:[^=]*=)?@-$/.test(value);
21242
- if (fromStdin && stdin !== undefined)
21243
- values.push(stdin);
21380
+ if (name === "--input")
21381
+ request.input = true;
21382
+ const piped = name === "--input" ? value === "-" : /^(?:-F|--field)$/.test(name) && /^[^=]*=@-$/.test(value);
21383
+ if (piped && stdin !== undefined) {
21384
+ values.push(value);
21385
+ return fromStdin(name, value, stdin);
21386
+ }
21387
+ if (API_FIELDS.has(name))
21388
+ field(value, expands);
21389
+ else
21390
+ values.push(value);
21391
+ const file = name === "--input" || /^(?:-F|--field)$/.test(name) && /^[^=]*=@/.test(value);
21392
+ if (file)
21393
+ request.unread = true;
21244
21394
  };
21245
21395
  for (let index = 1;index < args.length; index++) {
21246
21396
  const arg = args[index];
21247
21397
  if (arg === "--") {
21248
- endpoint ??= args[index + 1] ?? null;
21398
+ if (endpoint === null)
21399
+ [endpoint, endpointAt] = [args[index + 1] ?? null, index + 1];
21249
21400
  break;
21250
21401
  }
21251
21402
  if (arg.startsWith("--")) {
21252
21403
  const eq = arg.indexOf("=");
21253
21404
  const name = eq > 0 ? arg.slice(0, eq) : arg;
21254
21405
  if (API_VALUES.has(name))
21255
- take(name, eq > 0 ? arg.slice(eq + 1) : args[++index] ?? "");
21406
+ take(name, eq > 0 ? arg.slice(eq + 1) : args[++index] ?? "", index);
21256
21407
  } else if (arg.startsWith("-") && arg.length > 1) {
21257
21408
  for (let at = 1;at < arg.length; at++) {
21258
21409
  if (!API_SHORT_VALUES.includes(arg[at]))
21259
21410
  continue;
21260
- take(`-${arg[at]}`, at + 1 < arg.length ? arg.slice(at + 1) : args[++index] ?? "");
21411
+ take(`-${arg[at]}`, at + 1 < arg.length ? arg.slice(at + 1) : args[++index] ?? "", index);
21261
21412
  break;
21262
21413
  }
21263
- } else
21264
- endpoint ??= arg;
21414
+ } else if (endpoint === null)
21415
+ [endpoint, endpointAt] = [arg, index];
21265
21416
  }
21266
21417
  if (!endpoint)
21267
21418
  return null;
21268
- endpoint = endpoint.replace(/(?<!:)\/{2,}/g, "/");
21419
+ const atEndpoint = expanded === "all" || expanded.includes(endpointAt);
21420
+ for (const pair of /[?]([^#]*)/.exec(endpoint)?.[1].split("&") ?? []) {
21421
+ let decoded = pair;
21422
+ try {
21423
+ decoded = decodeURIComponent(pair.replaceAll("+", " "));
21424
+ } catch {
21425
+ request.unread = true;
21426
+ }
21427
+ field(decoded, atEndpoint);
21428
+ if (/refs\//i.test(decoded))
21429
+ request.input = true;
21430
+ }
21431
+ const route = routeOf(endpoint);
21269
21432
  const merge = { kind: "merge", forge: tool, via: "api" };
21270
- if (/(?:^|\/)graphql\/?$/i.test(endpoint))
21271
- return values.some((value) => GRAPHQL_MERGE.test(value)) ? merge : null;
21433
+ const setting = {
21434
+ kind: "ref-write",
21435
+ forge: tool,
21436
+ tag: false,
21437
+ branch: true,
21438
+ setting: true
21439
+ };
21440
+ if (/(?:^|\/)graphql\/?$/i.test(route)) {
21441
+ if (request.unread || queries.some((query) => !query.read))
21442
+ return { kind: "ref-write", forge: tool, tag: true, branch: true, unread: true };
21443
+ if (values.some((value) => GRAPHQL_MERGE.test(value)))
21444
+ return merge;
21445
+ if (values.some((value) => GRAPHQL_SETTING.test(value)))
21446
+ return setting;
21447
+ const shapes = new Set(GRAPHQL_REF.filter(([pattern]) => values.some((value) => pattern.test(value))).map(([, shape]) => shape));
21448
+ if (!shapes.size)
21449
+ return null;
21450
+ const created = queries.map((query) => createdRefs(query.text));
21451
+ const certain = !values.some((value) => BY_ID.test(value)) && created.every((named) => named !== null);
21452
+ return refWrite(tool, shapes, created.flatMap((named) => named ?? []), certain);
21453
+ }
21272
21454
  const verb = request.method ?? (request.body ? "POST" : "GET");
21273
21455
  if (verb === "GET" || verb === "HEAD")
21274
21456
  return null;
21275
- const named = tool === "gh" ? /(?:^|\/)repos\/([^/{]+\/[^/{]+)\//i.exec(endpoint)?.[1] : /(?:^|\/)projects\/([^/]+)\//i.exec(endpoint)?.[1];
21457
+ const named = tool === "gh" ? /(?:^|\/)repos\/([^/{]+\/[^/{]+)(?:\/|$)/i.exec(route)?.[1] ?? (/(?:^|\/)repositories\/[^/]+(?:\/|$)/i.test(route) ? "?" : undefined) : /(?:^|\/)projects\/([^/]+)(?:\/|$)/i.exec(route)?.[1];
21276
21458
  let repo;
21277
21459
  try {
21278
21460
  repo = named === undefined ? undefined : decodeURIComponent(named) || "?";
@@ -21280,9 +21462,17 @@ var apiAction = (tool, args, stdin) => {
21280
21462
  repo = "?";
21281
21463
  }
21282
21464
  const at = repo === undefined ? {} : { repo };
21283
- if (API_MERGE[tool].test(endpoint))
21465
+ if (API_MERGE[tool].test(route))
21284
21466
  return { ...merge, ...at };
21285
- const grant = /\/releases(?:\/|$|\?)/i.test(endpoint) ? "release" : (tool === "gh" ? /\/pulls(?:\/\d+)?\/?(?:\?|$)/i : /\/merge_requests(?:\/\d+)?\/?(?:\?|$)/i).test(endpoint) ? "pr" : null;
21467
+ const defaultBranch = API_REPOSITORY[tool].test(route) && (request.unread || values.some((value) => /default_branch/.test(value)));
21468
+ if (defaultBranch || API_SETTING[tool].some((pattern) => pattern.test(route)))
21469
+ return { ...setting, ...at };
21470
+ const shape = API_REF[tool].find(([pattern]) => pattern.test(route))?.[1];
21471
+ if (shape) {
21472
+ const { named: refs, certain } = restRef(route, fields, !request.unread && !request.input);
21473
+ return { ...refWrite(tool, new Set([shape]), refs, certain), ...at };
21474
+ }
21475
+ const grant = /\/releases(?:\/|$)/i.test(route) ? "release" : (tool === "gh" ? /\/pulls(?:\/\d+)?\/?$/i : /\/merge_requests(?:\/\d+)?\/?$/i).test(route) ? "pr" : null;
21286
21476
  return grant ? { kind: "forge", forge: tool, grant, ...at } : null;
21287
21477
  };
21288
21478
  var subtreePush = (args) => {
@@ -21300,7 +21490,7 @@ var subtreePush = (args) => {
21300
21490
  function rawAction(invocation) {
21301
21491
  const args = invocation.args;
21302
21492
  if (invocation.tool !== "git" && args[0] === "api")
21303
- return apiAction(invocation.tool, args, invocation.stdin);
21493
+ return apiAction(invocation.tool, args, invocation.stdin, invocation.expanded);
21304
21494
  if (asksHelp(invocation))
21305
21495
  return null;
21306
21496
  const [first] = args;
@@ -21576,6 +21766,223 @@ var refusal = (action, branch, dir) => {
21576
21766
  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
21767
  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
21768
  };
21769
+ var PLAIN_EXPANSION = /^(?:[^$`]|\$[A-Za-z_]\w*|\$\{[A-Za-z_]\w*\})*$/u;
21770
+ var shellWord = (text, expands = false) => {
21771
+ if (/^[\w@%+=:,./-]+$/u.test(text))
21772
+ return text;
21773
+ if (expands && text.includes("$") && PLAIN_EXPANSION.test(text))
21774
+ return `"${text.replaceAll(/["\\]/gu, "\\$&")}"`;
21775
+ return `'${text.replaceAll("'", "'\\''")}'`;
21776
+ };
21777
+ var expandingWords = (command, dialect, found = new Set, depth = 0) => {
21778
+ for (const segment of segmentsOf(command, dialect))
21779
+ segment.words.forEach((text, index) => {
21780
+ if (segment.expands?.includes(index))
21781
+ found.add(text);
21782
+ else if (depth < MAX_DEPTH && /\s/u.test(text))
21783
+ expandingWords(text, "posix", found, depth + 1);
21784
+ });
21785
+ return found;
21786
+ };
21787
+ var wordsOf = (command, dialect = "posix") => {
21788
+ const expands = expandsIn(command, dialect);
21789
+ return (text) => shellWord(text, expands(text));
21790
+ };
21791
+ var expandsIn = (command, dialect = "posix") => {
21792
+ let expanding;
21793
+ return (text) => (expanding ??= expandingWords(command, dialect)).has(text);
21794
+ };
21795
+ var oneCall = (command, dialect) => {
21796
+ const steps = /^(?:\s*cd\s+[^\s;&|<>()$`'"\\]+\s*&&)*([\s\S]*)$/u.exec(command);
21797
+ return !!steps && !!simpleCommand(steps[1], dialect);
21798
+ };
21799
+ var flagWord = (flag, value, asWritten) => value.startsWith("-") ? [`${flag}=${asWritten(value)}`] : [flag, asWritten(value)];
21800
+ var PR_FLAGS = {
21801
+ "gh ready": { verb: "ready", booleans: { "--undo": ["--undo"] }, values: {} },
21802
+ "gh merge": {
21803
+ verb: "merge",
21804
+ booleans: {
21805
+ "--squash": ["--squash"],
21806
+ "-s": ["--squash"],
21807
+ "--merge": ["--merge"],
21808
+ "-m": ["--merge"],
21809
+ "--rebase": ["--rebase"],
21810
+ "-r": ["--rebase"],
21811
+ "--delete-branch": ["--delete-branch"],
21812
+ "-d": ["--delete-branch"]
21813
+ },
21814
+ values: {
21815
+ "--subject": { flag: "--subject" },
21816
+ "-t": { flag: "--subject" },
21817
+ "--body": { flag: "--body" },
21818
+ "-b": { flag: "--body" },
21819
+ "--body-file": { flag: "--body-file" },
21820
+ "-F": { flag: "--body-file" }
21821
+ }
21822
+ },
21823
+ "gh edit": {
21824
+ verb: "edit",
21825
+ booleans: {},
21826
+ values: {
21827
+ "--title": { flag: "--title" },
21828
+ "-t": { flag: "--title" },
21829
+ "--body-file": { flag: "--body-file" },
21830
+ "-F": { flag: "--body-file" },
21831
+ "--add-label": { flag: "--add-label", split: true },
21832
+ "--remove-label": { flag: "--remove-label", split: true },
21833
+ "--add-reviewer": { flag: "--add-reviewer", split: true },
21834
+ "--base": { flag: "--base" },
21835
+ "-B": { flag: "--base" }
21836
+ }
21837
+ },
21838
+ "glab merge": {
21839
+ verb: "merge",
21840
+ booleans: {
21841
+ "--squash": ["--squash"],
21842
+ "-s": ["--squash"],
21843
+ "--rebase": ["--rebase"],
21844
+ "-r": ["--rebase"],
21845
+ "--remove-source-branch": ["--delete-branch"],
21846
+ "-d": ["--delete-branch"],
21847
+ "--yes": [],
21848
+ "-y": []
21849
+ },
21850
+ values: {}
21851
+ },
21852
+ "glab update": {
21853
+ verb: "edit",
21854
+ booleans: { "--ready": [], "-r": [], "--draft": ["--undo"], "--yes": [], "-y": [] },
21855
+ values: {
21856
+ "--title": { flag: "--title" },
21857
+ "-t": { flag: "--title" },
21858
+ "--label": { flag: "--add-label", split: true },
21859
+ "-l": { flag: "--add-label", split: true },
21860
+ "--unlabel": { flag: "--remove-label", split: true },
21861
+ "-u": { flag: "--remove-label", split: true },
21862
+ "--target-branch": { flag: "--base" }
21863
+ }
21864
+ }
21865
+ };
21866
+ var prRetry = (cwd, repo, invocation, cache, asWritten) => {
21867
+ const forge = invocation.tool;
21868
+ if (forge === "git")
21869
+ return null;
21870
+ const values = VALUE_OPTIONS[forge];
21871
+ const args = invocation.args;
21872
+ let verb;
21873
+ let at = 1;
21874
+ for (;at < args.length; at++) {
21875
+ if (!args[at].startsWith("-")) {
21876
+ verb = args[at];
21877
+ break;
21878
+ }
21879
+ if (values.has(args[at]))
21880
+ at++;
21881
+ }
21882
+ const table = PR_FLAGS[`${forge} ${verb}`];
21883
+ if (!table)
21884
+ return null;
21885
+ const words = [];
21886
+ const repos = [];
21887
+ let selector;
21888
+ let ready = false;
21889
+ const rest = [...args.slice(1, at), ...args.slice(at + 1)];
21890
+ for (let index = 0;index < rest.length; index++) {
21891
+ const arg = rest[index];
21892
+ const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
21893
+ const name = eq > 0 ? arg.slice(0, eq) : arg;
21894
+ const value = () => eq > 0 ? arg.slice(eq + 1) : rest[++index];
21895
+ if (name === "-R" || name === "--repo") {
21896
+ const named = value();
21897
+ if (named === undefined)
21898
+ return null;
21899
+ repos.push(named);
21900
+ } else if (/^-R./.test(arg))
21901
+ repos.push(arg.slice(2).replace(/^=/, ""));
21902
+ else if (eq < 0 && Object.hasOwn(table.booleans, arg)) {
21903
+ if (forge === "glab" && (arg === "--ready" || arg === "-r" || arg === "--draft")) {
21904
+ if (ready && words.includes("--undo") !== (arg === "--draft"))
21905
+ return null;
21906
+ ready = true;
21907
+ }
21908
+ words.push(...table.booleans[arg]);
21909
+ } else if (Object.hasOwn(table.values, name)) {
21910
+ const given = value();
21911
+ if (given === undefined)
21912
+ return null;
21913
+ const { flag, split } = table.values[name];
21914
+ if (split && given.includes(",") && /[$`]/.test(given))
21915
+ return null;
21916
+ for (const item of split ? given.split(",").filter(Boolean) : [given])
21917
+ words.push(...flagWord(flag, item, asWritten));
21918
+ } else if (arg.startsWith("-") || selector !== undefined)
21919
+ return null;
21920
+ else
21921
+ selector = arg;
21922
+ }
21923
+ const workitVerb = ready ? "ready" : table.verb;
21924
+ if (ready && words.some((word) => word !== "--undo"))
21925
+ return null;
21926
+ const pr = [];
21927
+ if (selector !== undefined) {
21928
+ const url = /^(https?:\/\/[^/]+\/.+?)\/(?:-\/)?(?:pull|merge_requests)\/(\d+)(?:[/?#].*)?$/.exec(selector);
21929
+ const number = url?.[2] ?? /^[#!]?(\d+)$/.exec(selector)?.[1];
21930
+ if (url)
21931
+ repos.push(url[1]);
21932
+ if (number)
21933
+ pr.push("--pr", number);
21934
+ else if (/\$[A-Za-z_{]/.test(selector))
21935
+ pr.push("--pr", asWritten(selector));
21936
+ else if (selector !== repo.branch)
21937
+ return null;
21938
+ }
21939
+ const env = invocation.env ?? {};
21940
+ if (forge === "gh" && (env.GH_REPO ?? process.env.GH_REPO))
21941
+ repos.push(env.GH_REPO ?? process.env.GH_REPO ?? "");
21942
+ if (repos.length) {
21943
+ const config = gitConfig(repo.dir, invocation, cache);
21944
+ const { GH_REPO: _named, ...own } = env;
21945
+ const key = (named, from) => {
21946
+ const found = forgeRepo(forge === "gh", named, from, config, repo.branch, repo.dir);
21947
+ return found instanceof Error ? null : found.remotes[0]?.key.toLowerCase() ?? null;
21948
+ };
21949
+ const checkout = key("", own);
21950
+ if (!checkout || repos.some((named) => /[$`]/.test(named) || key(named, own) !== checkout))
21951
+ return null;
21952
+ }
21953
+ const dir = path31.resolve(cwd, invocation.dir ?? ".");
21954
+ const call = [
21955
+ `workit pr ${workitVerb}`,
21956
+ ...dir === path31.resolve(cwd) ? [] : ["--cwd", shellWord(dir)],
21957
+ ...pr,
21958
+ ...words
21959
+ ].join(" ");
21960
+ return { raw: `${forge} ${forge === "gh" ? "pr" : "mr"} ${verb}`, call };
21961
+ };
21962
+ var prWriteRefusal = (writes, retry) => {
21963
+ const raws = [...new Set(writes.map((write) => quote(write.raw)))].join(", ");
21964
+ const calls = writes.map((write) => quote(write.call)).join(", ");
21965
+ const why = `workit: raw ${raws} changes the PR past workit's checks (the pr grant, and that the PR is this session's own).`;
21966
+ if (retry && writes.length === 1)
21967
+ return `${why} Run ${calls} instead.
21968
+ Retry as: ${writes[0].call}`;
21969
+ 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.`;
21970
+ };
21971
+ var refWriteRefusal = (action) => {
21972
+ if (action.unread)
21973
+ 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.`;
21974
+ if (action.setting)
21975
+ 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.`;
21976
+ const steers = [
21977
+ ...action.branch ? [
21978
+ `push a branch with ${quote("workit git push")} (it refuses protected branches and verifies the remote tip)`
21979
+ ] : [],
21980
+ ...action.tag ? [
21981
+ `tag a release with ${quote("workit release tag <vX.Y.Z>")} or ${quote("workit git push --release <tag>")}, under the ${quote("release")} grant`
21982
+ ] : []
21983
+ ];
21984
+ 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("; ")}.`;
21985
+ };
21579
21986
  var refFacts = (repo, remote) => {
21580
21987
  const facts = {
21581
21988
  heads: new Set,
@@ -21724,6 +22131,7 @@ var nudgeFor = (action, host, session) => {
21724
22131
  case "pr-read":
21725
22132
  case "forge":
21726
22133
  case "merge":
22134
+ case "ref-write":
21727
22135
  return null;
21728
22136
  }
21729
22137
  };
@@ -21741,8 +22149,10 @@ var pushRefusal = (action, repo, config) => {
21741
22149
  return offPolicy;
21742
22150
  for (const target of targets) {
21743
22151
  const guarded = guardedTarget(repo.dir, target ?? repo.branch ?? "");
21744
- if (guarded)
21745
- return refusal(action, guarded, repo.dir);
22152
+ if (!guarded)
22153
+ continue;
22154
+ 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).` : "";
22155
+ return refusal(action, guarded, repo.dir) + first;
21746
22156
  }
21747
22157
  return tagRefusal(pushed, facts, repo.dir) ?? (action.deletes ? null : offPolicyPush(pushed, repo, facts, remote));
21748
22158
  };
@@ -21924,6 +22334,8 @@ var commitRefusal = (input, command, dialect, { action, repo, invocation, workit
21924
22334
  try {
21925
22335
  guarded = !!repo.branch && resolveBranchPolicyFor(repo.dir).protected.has(repo.branch.toLowerCase());
21926
22336
  } catch {}
22337
+ if (guarded && !switches && noRefs(repo))
22338
+ 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
22339
  if (guarded && !switches)
21928
22340
  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
22341
  const call = action.amend || dialect !== "posix" || typeof invocation.dir !== "string" ? null : cdCommitCall(input, command, path31.resolve(input.cwd, invocation.dir), repo);
@@ -21933,6 +22345,8 @@ function rawGitPre(input, command, options = {}) {
21933
22345
  try {
21934
22346
  const dialect = dialectOf(input);
21935
22347
  const nudges = new Map;
22348
+ const prWrites = [];
22349
+ const asWritten = wordsOf(command, dialect);
21936
22350
  let store = null;
21937
22351
  const cache = new Map;
21938
22352
  const blind = rawInvocations(command, dialect).find((raw) => raw.redirect && rawAction(raw)?.kind === "push");
@@ -21953,8 +22367,19 @@ function rawGitPre(input, command, options = {}) {
21953
22367
  if (!workit)
21954
22368
  continue;
21955
22369
  store ??= repo.location.dir;
21956
- if (action.kind === "merge")
21957
- return deny(refusal(action, null));
22370
+ if (action.kind === "merge") {
22371
+ const retry = prRetry(input.cwd, repo, invocation, cache, asWritten);
22372
+ const named = !retry ? "" : oneCall(command, dialect) ? `
22373
+ 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.`;
22374
+ return deny(`${refusal(action, null)}${named}`);
22375
+ }
22376
+ if (action.kind === "ref-write")
22377
+ return deny(refWriteRefusal(action));
22378
+ if (action.kind === "forge" && action.grant === "pr") {
22379
+ const retry = prRetry(input.cwd, repo, invocation, cache, asWritten);
22380
+ if (retry)
22381
+ prWrites.push(retry);
22382
+ }
21958
22383
  if (action.kind === "push") {
21959
22384
  const refused = pushRefusal(action, repo, gitConfig(repo.dir, invocation, cache));
21960
22385
  if (refused)
@@ -21964,6 +22389,8 @@ function rawGitPre(input, command, options = {}) {
21964
22389
  if (nudge && !nudges.has(nudgeKind(action)))
21965
22390
  nudges.set(nudgeKind(action), nudge);
21966
22391
  }
22392
+ if (prWrites.length)
22393
+ return deny(prWriteRefusal(prWrites, oneCall(command, dialect)));
21967
22394
  const pkill = options.nudge === false ? null : pkillSelfMatch(command, dialect);
21968
22395
  const pkillNote = pkill ? { kind: "context", text: pkill } : NONE2;
21969
22396
  if (options.nudge === false || !store || nudges.size === 0)
@@ -22047,6 +22474,8 @@ var grantRefusal = (action, repo, invocation, cache) => {
22047
22474
  kinds.push("pr");
22048
22475
  else if (action.kind === "forge")
22049
22476
  kinds.push(action.grant);
22477
+ else if (action.kind === "ref-write")
22478
+ kinds.push(...action.branch ? ["push"] : [], ...action.tag ? ["release"] : [], ...action.unread ? ["merge"] : []);
22050
22479
  for (const kind of kinds) {
22051
22480
  const denied = rawGrantDenial(repo.dir, kind, target);
22052
22481
  if (denied)
@@ -22054,6 +22483,21 @@ var grantRefusal = (action, repo, invocation, cache) => {
22054
22483
  }
22055
22484
  return null;
22056
22485
  };
22486
+ var noRefs = (repo) => {
22487
+ const common = path31.dirname(repo.location.dir);
22488
+ const holds = (dir) => {
22489
+ try {
22490
+ return fs21.readdirSync(dir, { withFileTypes: true }).some((entry) => entry.isFile() || entry.isDirectory() && holds(path31.join(dir, entry.name)));
22491
+ } catch {
22492
+ return false;
22493
+ }
22494
+ };
22495
+ try {
22496
+ if (/ refs\//.test(fs21.readFileSync(path31.join(common, "packed-refs"), "utf8")))
22497
+ return false;
22498
+ } catch {}
22499
+ return fs21.existsSync(path31.join(common, "refs")) && !holds(path31.join(common, "refs"));
22500
+ };
22057
22501
  var localTag = (repo, name) => {
22058
22502
  const common = path31.dirname(repo.location.dir);
22059
22503
  try {
@@ -27382,8 +27826,7 @@ var linesOf = (command, dialect) => {
27382
27826
  return null;
27383
27827
  }
27384
27828
  };
27385
- var quoteWord = (word) => /^[\w@%+=:,./-]+$/u.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
27386
- var leaseCommand = (words) => `workit check --heavy -- ${words.map(quoteWord).join(" ")}`;
27829
+ var leaseCommand = (words, word) => `workit check --heavy -- ${words.map(word).join(" ")}`;
27387
27830
  function heavyPlan(command, options) {
27388
27831
  const dialect = options.dialect ?? "posix";
27389
27832
  if (dialect !== "posix" || !gitTop(options.cwd))
@@ -27416,7 +27859,8 @@ function heavyPlan(command, options) {
27416
27859
  }));
27417
27860
  return rewrite ? { kind: "rewrite", command: rewrite, reason: single.reason } : { kind: "none" };
27418
27861
  }
27419
- const parts = heavy.map((match) => leaseCommand(match.line));
27862
+ const word = wordsOf(command, dialect);
27863
+ const parts = heavy.map((match) => leaseCommand(match.line, word));
27420
27864
  return {
27421
27865
  kind: "split",
27422
27866
  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 +27882,7 @@ function serverPlan(command, options) {
27438
27882
  const rewrite = leaseRewrite(command)?.replace("workit check --heavy --", "workit run --bg --");
27439
27883
  return rewrite ? { kind: "rewrite", command: rewrite, reason: single, server: true } : { kind: "none" };
27440
27884
  }
27441
- const start = `workit run --bg -- ${found.line.map(quoteWord).join(" ")}`;
27885
+ const start = `workit run --bg -- ${found.line.map(wordsOf(command, dialect)).join(" ")}`;
27442
27886
  return {
27443
27887
  kind: "split",
27444
27888
  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 +27917,7 @@ function leaseRewrite(command) {
27473
27917
  import fs27 from "node:fs";
27474
27918
  import path40 from "node:path";
27475
27919
  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 wordsOf = (command) => command.split(/[\s;&|()<>`'"]+/u).map((word) => (word.split(/[\\/]/u).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd|bat)$/u, "")).filter(Boolean);
27920
+ var wordsOf2 = (command) => command.split(/[\s;&|()<>`'"]+/u).map((word) => (word.split(/[\\/]/u).at(-1) ?? "").toLowerCase().replace(/\.(?:exe|cmd|bat)$/u, "")).filter(Boolean);
27477
27921
  var stateDir3 = (env) => stateDir(env);
27478
27922
  var readJson2 = (file) => {
27479
27923
  try {
@@ -27499,7 +27943,7 @@ var patternWords = (cwd, env) => {
27499
27943
  for (const pattern of patterns) {
27500
27944
  if (typeof pattern !== "string")
27501
27945
  continue;
27502
- const first = wordsOf(pattern)[0];
27946
+ const first = wordsOf2(pattern)[0];
27503
27947
  if (!first || first.includes("*"))
27504
27948
  return null;
27505
27949
  words.add(first);
@@ -27508,7 +27952,7 @@ var patternWords = (cwd, env) => {
27508
27952
  };
27509
27953
  function maybeHeavy(command, cwd, env = process.env) {
27510
27954
  try {
27511
- const words = wordsOf(command);
27955
+ const words = wordsOf2(command);
27512
27956
  if (words.some((word) => HEAVY_WORDS.has(word) || /^python[\d.]*$/u.test(word)))
27513
27957
  return true;
27514
27958
  const extra = patternWords(cwd, env);
@@ -28235,7 +28679,7 @@ var wrappedScript = (input) => {
28235
28679
  const script = shellScript3(tail.argv);
28236
28680
  if (SCRIPT_SHELLS.has((tail.argv[0]?.split(/[\\/]/).at(-1) ?? "").toLowerCase()) && script)
28237
28681
  return script;
28238
- return tail.argv.map(quoteWord2).join(" ");
28682
+ return tail.argv.map(quoteWord).join(" ");
28239
28683
  };
28240
28684
  var editsOf = (input) => {
28241
28685
  const words = pastLead(input);
@@ -29113,7 +29557,7 @@ var cdInto = (dir, words, strict = false, vars = new Map, globs = false) => {
29113
29557
  return lost;
29114
29558
  return target === undefined ? os10.homedir() : path43.resolve(dir, target);
29115
29559
  };
29116
- var quoteWord2 = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
29560
+ var quoteWord = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
29117
29561
  var expandVars = (text, vars) => vars.size === 0 || !text.includes("$") ? text : text.replace(/\$(?:(\w+)|\{(\w+)\})/g, (whole, bare, braced) => {
29118
29562
  const value = vars.get(bare ?? braced ?? "");
29119
29563
  return value === undefined ? whole : value;
@@ -29511,7 +29955,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29511
29955
  targets.push(cmd && CMD_VAR.test(file) ? placeholderIn(dir, `${OPAQUE_TARGET}cmd`) : file);
29512
29956
  const bare = strict && depth < 4 ? unwrapped2(words) : null;
29513
29957
  if (bare?.length && dir !== undefined)
29514
- targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord2).join(" "), "posix", depth + 1, strict, vars));
29958
+ targets.push(...segmentTargets(dir, bare.flatMap((word) => expansions(word, vars, loops)).map(quoteWord).join(" "), "posix", depth + 1, strict, vars));
29515
29959
  if (strict === "registry" && dir !== undefined && depth < 4) {
29516
29960
  const run = words.slice(Math.max(0, words.findIndex((word) => !PREFIXES2.has(word))));
29517
29961
  const [verb = "", ...args] = run.map((word, index) => index ? word : (word.split(/[\\/]/).at(-1) ?? "").toLowerCase());
@@ -29646,7 +30090,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29646
30090
  if (!/^\/dev\/(?:null|stdout|stderr|tty)$/.test(file) && !(dialect === "powershell" && /^(?:\$null|nul)$/i.test(file)))
29647
30091
  targets.push(...atAll(file));
29648
30092
  if (dir !== undefined)
29649
- for (const invocation of workitInvocations(body.map(quoteWord2).join(" "), "posix")) {
30093
+ for (const invocation of workitInvocations(body.map(quoteWord).join(" "), "posix")) {
29650
30094
  const { at: runsIn, args } = workitCwd(dir, invocation, atAll);
29651
30095
  if (args[0] === "git" && MUTATING_WORKIT_GIT.has(args[1] ?? "") && !inert(args.slice(2), ""))
29652
30096
  targets.push(...runsIn.map((runs) => placeholderIn(runs, DIR_TARGET)));
@@ -29655,7 +30099,7 @@ var segmentTargets = (cwd, command, dialect, depth = 0, strict = false, inherite
29655
30099
  return targets;
29656
30100
  };
29657
30101
  var workitRunDir = (dir, words, resolve) => {
29658
- for (const invocation of workitInvocations(words.map(quoteWord2).join(" "), "posix")) {
30102
+ for (const invocation of workitInvocations(words.map(quoteWord).join(" "), "posix")) {
29659
30103
  const { at, args } = workitCwd(dir, invocation, resolve);
29660
30104
  if (args[0] === "check" || args[0] === "lock" && args[1] === "run")
29661
30105
  return at;
@@ -31367,7 +31811,9 @@ var fixDir = (cwd, literal, cd, dialect) => {
31367
31811
  return cd === undefined || cd === DIR2 ? DIR2 : paths.join(cd, cwd);
31368
31812
  };
31369
31813
  var OPAQUE_RELEASE_FIX = `workit release --cwd ${DIR2} notes approve <version>`;
31370
- var inlineCallIn = (command, dialect = "posix") => {
31814
+ var SUB_VERB = /^[a-z][a-z-]*$/u;
31815
+ var OPAQUE_RELEASE_FIRST = `workit release notes approve --cwd ${DIR2} <version>`;
31816
+ var inlineCallIn = (command, dialect = "posix", wrapped = false) => {
31371
31817
  if (!/\bworkit\b/u.test(command))
31372
31818
  return null;
31373
31819
  const segments = segmentsOf(command, dialect, { spans: true });
@@ -31378,8 +31824,11 @@ var inlineCallIn = (command, dialect = "posix") => {
31378
31824
  if ((words[0] ?? "").endsWith("sh"))
31379
31825
  for (const word of words.slice(1)) {
31380
31826
  const inner = /\s/u.test(word) ? inlineCallIn(word, dialect) : null;
31381
- if (inner?.plain)
31382
- return { plain: false, fix: word.trim(), words: inner.words };
31827
+ const own = inner?.plain ? inlineCallIn(word, dialect, true) : null;
31828
+ if (inner?.plain) {
31829
+ const first = own?.plain === false ? own.first : word.trim();
31830
+ return { plain: false, fix: word.trim(), first, words: inner.words };
31831
+ }
31383
31832
  if (inner)
31384
31833
  return inner;
31385
31834
  }
@@ -31394,10 +31843,10 @@ var inlineCallIn = (command, dialect = "posix") => {
31394
31843
  const call = verb.words;
31395
31844
  const release = isReleaseNotesCall(call);
31396
31845
  if (release && (ODD_SPACE.test(command) || words.some((word) => UNSAFE_TEXT.test(word))))
31397
- return { plain: false, fix: OPAQUE_RELEASE_FIX, words: call };
31846
+ return { plain: false, fix: OPAQUE_RELEASE_FIX, first: OPAQUE_RELEASE_FIRST, words: call };
31398
31847
  const cwds = cwdIndexes(words, start + 1, at);
31399
31848
  const literal = (index) => literalDir((words[index] ?? "").replace(/^--cwd=/u, ""), segment.expands?.includes(index) ?? false);
31400
- const plain = (segments.length === 1 || position === 0 && onlyFiltersAfter(segments)) && start === 0 && words[0] === "workit" && cwds.every(literal) && !segment.redirects.length && !segment.subs?.length && !segment.stdin?.length && !segment.expands?.length && !segment.group;
31849
+ const plain = !wrapped && (segments.length === 1 || position === 0 && onlyFiltersAfter(segments)) && start === 0 && words[0] === "workit" && cwds.every(literal) && !segment.redirects.length && !segment.subs?.length && !segment.stdin?.length && !segment.expands?.length && !segment.group;
31401
31850
  if (plain)
31402
31851
  return { plain: true, words: routed(call, words.slice(1, at)), cwd: verb.cwd };
31403
31852
  const last = cwds.at(-1);
@@ -31417,29 +31866,35 @@ var inlineCallIn = (command, dialect = "posix") => {
31417
31866
  texts.push(local ? `<path of $${local[1]}>` : writtenWord(command, segment, index));
31418
31867
  }
31419
31868
  const file = producedFile(command, before, words) ?? undefined;
31420
- const done = (fix) => ({
31869
+ const done = (fix, first = fix) => ({
31421
31870
  plain: false,
31422
31871
  fix,
31872
+ first,
31423
31873
  words: call,
31424
31874
  ...file && { file }
31425
31875
  });
31426
31876
  if (texts.includes(null)) {
31427
31877
  const verbs = call.slice(0, 2).join(" ");
31428
- return done(release ? OPAQUE_RELEASE_FIX : `workit ${verbs} <its other words as you wrote them>`);
31878
+ const opaque = `workit ${verbs} <its other words as you wrote them>`;
31879
+ return release ? done(OPAQUE_RELEASE_FIX, OPAQUE_RELEASE_FIRST) : done(opaque);
31429
31880
  }
31430
31881
  const [head = "", ...rest] = texts;
31431
31882
  const cwdTexts = cwds.map((index) => writtenWord(command, segment, index));
31432
31883
  const uncertain = !rest.every((text) => cwdIndependent(text)) || cwdTexts.some((text) => text === null || !cwdIndependent(text.replace(/^--cwd=/u, "")));
31884
+ const cdLost = cd === undefined && !command.includes("||") && before.some((step) => step.words[0] === "cd");
31885
+ const cwd = cdLost && verb.cwd === null ? DIR2 : fixDir(verb.cwd, lastLiteral, cd, dialect);
31886
+ const where = cwd === null ? [] : ["--cwd", cwd === DIR2 ? DIR2 : quote2(cwd, dialect)];
31887
+ const subs = release ? 3 : 2;
31888
+ const subWords = texts.slice(1, subs);
31889
+ const literalSubs = subWords.length === subs - 1 && subWords.every((w) => SUB_VERB.test(w));
31890
+ const first = literalSubs ? ["workit", ...texts.slice(0, subs), ...where, ...texts.slice(subs)].join(" ") : ["workit", head, ...where, ...rest].join(" ");
31433
31891
  if (cd && cd !== DIR2 && uncertain) {
31434
31892
  const dir = before[0] ? writtenWord(command, before[0], 1) : null;
31435
31893
  const all = writtenWords(command, segment, Array.from({ length: words.length - start - 1 }, (_, n) => start + 1 + n));
31436
31894
  if (dir !== null && all)
31437
31895
  return done(`cd ${dir} && workit ${all.join(" ")}`);
31438
31896
  }
31439
- const cdLost = cd === undefined && !command.includes("||") && before.some((step) => step.words[0] === "cd");
31440
- const cwd = cdLost && verb.cwd === null ? DIR2 : fixDir(verb.cwd, lastLiteral, cd, dialect);
31441
- const where = cwd === null ? [] : ["--cwd", cwd === DIR2 ? DIR2 : quote2(cwd, dialect)];
31442
- return done(["workit", head, ...where, ...rest].join(" "));
31897
+ return done(["workit", head, ...where, ...rest].join(" "), first);
31443
31898
  }
31444
31899
  return null;
31445
31900
  };
@@ -31455,7 +31910,7 @@ var inlineCallDeny = (fix, file) => {
31455
31910
  const first = file ? `An earlier step in this command writes ${showable(file) && !file.includes(`
31456
31911
  `) ? `\`${file}\`` : "the file the call reads"}; run that step as its own call first, then run ${run}` : `Run ${run}`;
31457
31912
  const segments = segmentsOf(fix.replace(/<[^>\n]*>/gu, "x"));
31458
- const expands = segments.length > 1 || segments.some((segment) => segment.expands?.length) || /(?:^|\s)~[^/\s]/u.test(fix);
31913
+ const expands = segments.length > 1 || segments.some((segment) => segment.expands?.length || segment.subs?.length) || /(?:^|\s)~[^/\s]/u.test(fix);
31459
31914
  return expands ? `${first} Spell out each word the shell would expand ($…, a glob, a cd): the host asks only on a call its text fixes.` : first;
31460
31915
  };
31461
31916
 
@@ -32573,7 +33028,7 @@ var workitCallDir = (command, dialect) => {
32573
33028
  const call = plainWorkitCall(command, dialect);
32574
33029
  return call?.cwd && path51.isAbsolute(call.cwd) ? call.cwd : null;
32575
33030
  };
32576
- var shellWord = (dir) => /^[\w@%+=:,./-]+$/u.test(dir) ? dir : `'${dir.replaceAll("'", `'\\''`)}'`;
33031
+ var shellWord2 = (dir) => /^[\w@%+=:,./-]+$/u.test(dir) ? dir : `'${dir.replaceAll("'", `'\\''`)}'`;
32577
33032
  var cwdAt = (words, index) => words[index] === "--cwd" && words[index + 1] !== undefined ? 2 : words[index]?.startsWith("--cwd=") ? 1 : 0;
32578
33033
  var plainRetry = (dir, command) => {
32579
33034
  const call = plainWorkitCall(command, "posix");
@@ -32622,7 +33077,7 @@ var plainRetry = (dir, command) => {
32622
33077
  if (parts.includes(null))
32623
33078
  return null;
32624
33079
  const [envText, globalText, verbText, restText] = parts;
32625
- const cwd = ["--cwd", shellWord(dir)];
33080
+ const cwd = ["--cwd", shellWord2(dir)];
32626
33081
  const body = [...globalText, ...verbText, ...cwd, ...restText];
32627
33082
  return { retry: [...envText, "workit", ...body].join(" "), dropped };
32628
33083
  };
@@ -34505,11 +34960,12 @@ var hinted = (write) => write.hint ? {
34505
34960
  plain: false,
34506
34961
  workit: write.hint
34507
34962
  } : write;
34508
- var ytrackArgs = (line, found, depth, names, plain) => {
34963
+ var ytrackArgs = (line, found, depth, names, plain, expands = () => false) => {
34509
34964
  const inner = (script) => void found.push(...ytrackWrites(script, "posix", depth + 1, plain));
34510
34965
  const tail = workitCheckTail(line);
34511
34966
  if (tail) {
34512
- inner("script" in tail ? tail.script : tail.argv.map(quote3).join(" "));
34967
+ const live = (text) => expands(text) && /[$`]/.test(text) ? `"${text.replaceAll(/["\\]/g, "\\$&")}"` : quote3(text);
34968
+ inner("script" in tail ? tail.script : tail.argv.map(live).join(" "));
34513
34969
  return true;
34514
34970
  }
34515
34971
  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 +34995,9 @@ var ytrackArgs = (line, found, depth, names, plain) => {
34539
34995
  const argv = [...alias ?? [], ...line.slice(at + 1)];
34540
34996
  const write = classify2(argv);
34541
34997
  if (write) {
34998
+ const word = (text) => plain ? quote3(text) : shellWord(text, expands(text));
34542
34999
  const one = {
34543
- command: ["ytrack", ...argv].map(quote3).join(" "),
35000
+ command: ["ytrack", ...argv].map(word).join(" "),
34544
35001
  ...write,
34545
35002
  ...hostsOf(argv),
34546
35003
  plain
@@ -34643,14 +35100,15 @@ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
34643
35100
  let found = [];
34644
35101
  const lines = plain ? plainLines(command, dialect) : null;
34645
35102
  const none = new Map;
35103
+ const expands = expandsIn(command, dialect);
34646
35104
  const plainFirst = lines ? ytrackArgs(lines.first, found, depth, none, true) : false;
34647
35105
  const joined = lines && plainFirst ? chained(found, lines.chain, depth) : null;
34648
35106
  if (joined)
34649
35107
  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))) {
35108
+ 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
35109
  found = [];
34652
35110
  for (const line of commandLines(command, dialect))
34653
- ytrackArgs(line, found, depth, aliases(command), false);
35111
+ ytrackArgs(line, found, depth, aliases(command), false, expands);
34654
35112
  found = found.map(hinted);
34655
35113
  }
34656
35114
  READ.set(key, found);
@@ -34660,7 +35118,7 @@ var ytrackWrites = (command, dialect = "posix", depth = 0, plain = true) => {
34660
35118
  };
34661
35119
  var RELOCATES = /(?<![$\w])YTRACK_CONFIG_DIR\b/;
34662
35120
  var reachesOnly = (allowed, write) => write.plain && !!write.hosts?.length && write.hosts.every((host) => youTrackHostAllowed(allowed, host));
34663
- var scopedGate = (allowed, command, writes) => {
35121
+ var scopedGate = (allowed, command, dialect, writes) => {
34664
35122
  const scope = `youtrack.autoHosts (${allowed.join(", ")})`;
34665
35123
  if (RELOCATES.test(command))
34666
35124
  return {
@@ -34675,8 +35133,10 @@ var scopedGate = (allowed, command, writes) => {
34675
35133
  if (!unnamed.length)
34676
35134
  return null;
34677
35135
  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 bare = unnamed.find((write) => write.bare)?.bare;
34679
- const retry = bare ? ["ytrack", "--host", first, ...bare].map(quote3).join(" ") : null;
35136
+ const hostless = unnamed.find((each) => each.bare);
35137
+ const expands = expandsIn(command, dialect);
35138
+ const word = (text) => hostless?.plain ? quote3(text) : shellWord(text, expands(text));
35139
+ const retry = hostless?.bare ? ["ytrack", "--host", first, ...hostless.bare].map(word).join(" ") : null;
34680
35140
  return {
34681
35141
  kind: "deny",
34682
35142
  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 +35172,7 @@ var ytrackGate = (cwd, command, dialect, ask) => {
34712
35172
  const hosts = policy.hosts;
34713
35173
  if (hosts === null)
34714
35174
  return null;
34715
- const scoped = scopedGate(hosts, command, writes);
35175
+ const scoped = scopedGate(hosts, command, dialect, writes);
34716
35176
  if (scoped)
34717
35177
  return scoped;
34718
35178
  writes = writes.filter((write) => !reachesOnly(hosts, write));
@@ -35989,7 +36449,7 @@ var enforceToolPolicy = (event, ctx) => {
35989
36449
  return approveInDialog(approve.ids, event, ctx);
35990
36450
  const inline = typeof command === "string" ? inlineCallIn(command) : null;
35991
36451
  if (inline && !inline.plain)
35992
- return { block: true, reason: inlineCallDeny(inline.fix, inline.file) };
36452
+ return { block: true, reason: inlineCallDeny(inline.first, inline.file) };
35993
36453
  if (inline?.plain && ctx.mode === "tui" && ctx.hasUI) {
35994
36454
  const gated = isReleaseNotesCall(inline.words) && inlineAskFor(inline.words, inlineCallCwd(inline, ctx.cwd)) ? undefined : gate({
35995
36455
  kind: "shell.pre",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/pi",
3
- "version": "2.29.2",
3
+ "version": "2.29.4",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",
@@ -53,7 +53,7 @@ the same check. Fix round and recheck both failed: the decider agent (read the `
53
53
  with `workit check`, fix the root cause, batch every fix in one push, one focused commit per fix (unrelated hunks in one file: `workit git stage --patch <file>`, then `workit git commit -m "<msg>" --staged`). A tool warning is a finding: fix it in this PR in the right layer, or record the false positive with evidence; pre-existing ones get their own PR.
54
54
  6. **Verified.** The lane in `workit pr status` decides: none, no verdict; self, your `--self` verdict; focused or full (or `verification: self|independent`), one non-author verifier per PR after the last push, never per push (read the `workit-review` skill's SKILL.md and follow it), on Claude Code with the `model` and `effort` of `workit models show --role verifier`. A docs-only push (or test-only under a unit verdict) keeps the verdict (`carried`); `reverify: focused` re-checks only the new diff, reusing green CI; one verdict at a stack's top covers its unchanged lower PRs. Land only when
55
55
  granted: `workit stack land` or `workit pr merge`; `--unverified --reason` if user-asked.
56
- Never pipe a delivery verb through `grep`, `tail` or `head`: read its exit code, or use `--json`. Trunk CI after a merge: `workit ci wait --branch <trunk>`.
56
+ Never pipe a delivery verb through `grep`, `tail` or `head`: read its exit code, or use `--json`. Trunk CI after a merge: `workit ci wait --branch <trunk>`. Run each delivery verb alone, verb first (`workit pr merge --cwd <dir> …`), never chained. A classifier denial of a chained granted verb: rerun it once alone; a plain call denied: ask the user in chat, never hand it to their terminal.
57
57
  7. **Observe it landed:** `workit verify-delivery pr` or `merge`. After a failed
58
58
  verdict or a check red 3+ times, at any endpoint: offer `/wk-retro` in one
59
59
  line of the final or stop report; never pause the babysit loop for it.