@staff0rd/assist 0.801.5 → 0.802.0

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/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.801.5",
9
+ version: "0.802.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -18867,55 +18867,9 @@ function tokenize(command) {
18867
18867
  return tokens;
18868
18868
  }
18869
18869
 
18870
- // src/commands/cliHook/extractQuotedSubstitutions.ts
18871
- function extractQuotedSubstitutions(command) {
18872
- const bodies = [];
18873
- scanUnquoted(command, 0, (i, inDouble) => {
18874
- if (!inDouble) return void 0;
18875
- if (command[i] === "$" && command[i + 1] === "(") {
18876
- const end = findClosingParen(command, i + 2);
18877
- bodies.push(command.slice(i + 2, end));
18878
- return end;
18879
- }
18880
- if (command[i] === "`") {
18881
- const end = command.indexOf("`", i + 1);
18882
- const stop2 = end === -1 ? command.length : end;
18883
- bodies.push(command.slice(i + 1, stop2));
18884
- return stop2;
18885
- }
18886
- return void 0;
18887
- });
18888
- return bodies;
18889
- }
18890
- function findClosingParen(command, start2) {
18891
- let depth = 1;
18892
- let close = command.length;
18893
- scanUnquoted(command, start2, (i, inDouble) => {
18894
- if (inDouble) return void 0;
18895
- if (command[i] === "(") depth++;
18896
- else if (command[i] === ")" && --depth === 0) {
18897
- close = i;
18898
- return command.length;
18899
- }
18900
- return void 0;
18901
- });
18902
- return close;
18903
- }
18904
- function scanUnquoted(command, start2, visit2) {
18905
- let inSingle = false;
18906
- let inDouble = false;
18907
- for (let i = start2; i < command.length; i++) {
18908
- const ch = command[i];
18909
- if (ch === "\\" && !inSingle) i++;
18910
- else if (ch === "'" && !inDouble) inSingle = !inSingle;
18911
- else if (ch === '"' && !inSingle) inDouble = !inDouble;
18912
- else if (!inSingle) i = visit2(i, inDouble) ?? i;
18913
- }
18914
- }
18915
-
18916
18870
  // src/commands/cliHook/isGhGraphqlIssueMutation.ts
18917
18871
  import { readFileSync as readFileSync26 } from "fs";
18918
- var ISSUE_MUTATION = /\bmutation\b[\s\S]*\b(?:createIssue|updateIssue|deleteIssue|closeIssue|reopenIssue|transferIssue|pinIssue|unpinIssue|addComment|updateIssueComment|deleteIssueComment|addSubIssue|removeSubIssue|reprioritizeSubIssue)\s*\(/;
18872
+ var ISSUE_MUTATION = /\bmutation\b[\s\S]*(?:issue|comment|label|assign|reaction|milestone)/i;
18919
18873
  var FIELD_FLAGS = ["-f", "-F", "--field", "--raw-field"];
18920
18874
  function isGhGraphqlIssueMutation(args, command) {
18921
18875
  if (!args.some((arg) => unquote(arg) === "graphql")) return false;
@@ -18959,40 +18913,20 @@ function unquote(value) {
18959
18913
  return value.replace(/['"]/g, "");
18960
18914
  }
18961
18915
 
18962
- // src/commands/cliHook/splitSubstitutionTokens.ts
18963
- var OPENER = /^(?:\w+=)?(?:\$\(|`|\()+/;
18964
- var CLOSER = /[)`]+$/;
18965
- var SUBSTITUTION_CLOSE = ")";
18966
- function splitSubstitutionTokens(tokens) {
18967
- return tokens.flatMap((token) => {
18968
- const body = token.replace(OPENER, "");
18969
- if (/['"]$/.test(body) || !CLOSER.test(body)) return body ? [body] : [];
18970
- const inner = body.replace(CLOSER, "");
18971
- return inner ? [inner, SUBSTITUTION_CLOSE] : [SUBSTITUTION_CLOSE];
18972
- });
18973
- }
18974
-
18975
18916
  // src/commands/cliHook/isGhIssueApiWrite.ts
18976
18917
  var WRITE_METHODS = /* @__PURE__ */ new Set(["POST", "PATCH", "PUT", "DELETE"]);
18977
18918
  var BODY_FLAGS = ["-f", "-F", "--field", "--raw-field", "--input"];
18978
- var COMMAND_OPERATORS = /* @__PURE__ */ new Set([
18979
- "&&",
18980
- "||",
18981
- ";",
18982
- "|",
18983
- "&",
18984
- SUBSTITUTION_CLOSE
18985
- ]);
18919
+ var COMMAND_OPERATORS = /* @__PURE__ */ new Set(["&&", "||", ";", "|", "&"]);
18986
18920
  var ISSUE_ENDPOINT = /(?:^|[/"'`])repos\/[^/\s"'`]+\/[^/\s"'`]+\/issues(?:$|[/?"'`])/;
18987
18921
  function isGhIssueApiWrite(command) {
18988
- const tokens = splitSubstitutionTokens(tokenize(command));
18922
+ const tokens = tokenize(command);
18989
18923
  for (let i = 0; i + 1 < tokens.length; i++) {
18990
18924
  if (tokens[i] !== "gh" || tokens[i + 1] !== "api") continue;
18991
18925
  const args = argsUntilNextCommand(tokens.slice(i + 2));
18992
18926
  if (targetsIssueEndpoint(args) && isWrite(args)) return true;
18993
18927
  if (isGhGraphqlIssueMutation(args, command)) return true;
18994
18928
  }
18995
- return extractQuotedSubstitutions(command).some(isGhIssueApiWrite);
18929
+ return false;
18996
18930
  }
18997
18931
  function argsUntilNextCommand(tokens) {
18998
18932
  const end = tokens.findIndex((token) => COMMAND_OPERATORS.has(token));
@@ -19088,10 +19022,61 @@ var builtinDenyRules = [
19088
19022
  }
19089
19023
  ];
19090
19024
 
19025
+ // src/commands/cliHook/extractNestedCommands.ts
19026
+ function extractNestedCommands(command) {
19027
+ const bodies = [];
19028
+ scanUnquoted(command, 0, (i, inDouble) => {
19029
+ const opener = openerLength(command, i, inDouble);
19030
+ if (opener === void 0) return void 0;
19031
+ const start2 = i + opener;
19032
+ const end = command[i] === "`" ? findClosingBacktick(command, start2) : findClosingParen(command, start2);
19033
+ const body = command.slice(start2, end);
19034
+ bodies.push(body, ...extractNestedCommands(body));
19035
+ return end;
19036
+ });
19037
+ return bodies;
19038
+ }
19039
+ function openerLength(command, i, inDouble) {
19040
+ if (command[i] === "$" && command[i + 1] === "(") return 2;
19041
+ if (command[i] === "`") return 1;
19042
+ if (command[i] === "(" && !inDouble) return 1;
19043
+ return void 0;
19044
+ }
19045
+ function findClosingBacktick(command, start2) {
19046
+ const end = command.indexOf("`", start2);
19047
+ return end === -1 ? command.length : end;
19048
+ }
19049
+ function findClosingParen(command, start2) {
19050
+ let depth = 1;
19051
+ let close = command.length;
19052
+ scanUnquoted(command, start2, (i, inDouble) => {
19053
+ if (inDouble) return void 0;
19054
+ if (command[i] === "(") depth++;
19055
+ else if (command[i] === ")" && --depth === 0) {
19056
+ close = i;
19057
+ return command.length;
19058
+ }
19059
+ return void 0;
19060
+ });
19061
+ return close;
19062
+ }
19063
+ function scanUnquoted(command, start2, visit2) {
19064
+ let inSingle = false;
19065
+ let inDouble = false;
19066
+ for (let i = start2; i < command.length; i++) {
19067
+ const ch = command[i];
19068
+ if (ch === "\\" && !inSingle) i++;
19069
+ else if (ch === "'" && !inDouble) inSingle = !inSingle;
19070
+ else if (ch === '"' && !inSingle) inDouble = !inDouble;
19071
+ else if (!inSingle) i = visit2(i, inDouble) ?? i;
19072
+ }
19073
+ }
19074
+
19091
19075
  // src/commands/cliHook/findBuiltinDeny.ts
19092
19076
  function matchBuiltinDeny(text18) {
19077
+ const commands = [text18, ...extractNestedCommands(text18)];
19093
19078
  return builtinDenyRules.find(
19094
- (rule) => rule.matches(text18) && (rule.enabled?.() ?? true)
19079
+ (rule) => commands.some((command) => rule.matches(command)) && (rule.enabled?.() ?? true)
19095
19080
  );
19096
19081
  }
19097
19082
  function toDecision(rule) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.801.5",
3
+ "version": "0.802.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {