@pushary/agent-hooks 1.9.29 → 1.9.30

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.
Files changed (100) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/bin/pushary-bell-hook.js +25 -25
  3. package/dist/bin/pushary-bell.js +9 -9
  4. package/dist/bin/pushary-claude.js +29 -26
  5. package/dist/bin/pushary-clean.js +29 -29
  6. package/dist/bin/pushary-codex-bridge.js +17 -17
  7. package/dist/bin/pushary-codex-hook.js +40 -39
  8. package/dist/bin/pushary-codex.js +12 -12
  9. package/dist/bin/pushary-connect.js +24 -24
  10. package/dist/bin/pushary-cowork.js +5 -5
  11. package/dist/bin/pushary-daemon.js +32 -32
  12. package/dist/bin/pushary-disconnect.js +24 -24
  13. package/dist/bin/pushary-doctor.js +33 -33
  14. package/dist/bin/pushary-elicitation-hook.js +25 -25
  15. package/dist/bin/pushary-gemini-bridge.js +13 -13
  16. package/dist/bin/pushary-gemini-hook.js +27 -27
  17. package/dist/bin/pushary-hook.js +29 -29
  18. package/dist/bin/pushary-login.js +12 -12
  19. package/dist/bin/pushary-logout.js +24 -24
  20. package/dist/bin/pushary-mcp.js +9 -9
  21. package/dist/bin/pushary-mode.js +12 -12
  22. package/dist/bin/pushary-notification-hook.js +24 -24
  23. package/dist/bin/pushary-opencode-hook.js +26 -26
  24. package/dist/bin/pushary-permission-denied-hook.js +29 -29
  25. package/dist/bin/pushary-permission-hook.js +28 -28
  26. package/dist/bin/pushary-post-hook.js +24 -24
  27. package/dist/bin/pushary-prompt-hook.js +24 -24
  28. package/dist/bin/pushary-session-end-hook.js +24 -24
  29. package/dist/bin/pushary-session-start-hook.js +28 -28
  30. package/dist/bin/pushary-setup.js +35 -35
  31. package/dist/bin/pushary-stats.js +5 -5
  32. package/dist/bin/pushary-status.js +26 -26
  33. package/dist/bin/pushary-stop-hook.js +24 -24
  34. package/dist/bin/pushary-stopfailure-hook.js +24 -24
  35. package/dist/bin/pushary-suggestions.js +12 -12
  36. package/dist/bin/pushary-transcript-register.js +17 -17
  37. package/dist/bin/pushary-transcripts.js +7 -7
  38. package/dist/bin/pushary-upgrade.js +30 -30
  39. package/dist/bin/pushary-wait.js +12 -12
  40. package/dist/bin/pushary.js +6 -6
  41. package/dist/{chunk-UM2HNUJA.js → chunk-2OIGS4P2.js} +3 -3
  42. package/dist/{chunk-CBOHZ6NY.js → chunk-2QEW5FJK.js} +4 -4
  43. package/dist/{chunk-UW37WHVP.js → chunk-2VQULZ4L.js} +2 -2
  44. package/dist/{chunk-Z2WS466S.js → chunk-3FIKV3PW.js} +15 -13
  45. package/dist/{chunk-CPZZTS4I.js → chunk-3HTCA4SQ.js} +1 -1
  46. package/dist/{chunk-35CMXPES.js → chunk-3QKX22ZA.js} +3 -3
  47. package/dist/{chunk-AVQ6ETA7.js → chunk-434NFCK2.js} +1 -1
  48. package/dist/{chunk-62LJB5U3.js → chunk-4GIGQIRN.js} +2 -2
  49. package/dist/{chunk-YFEHKEGQ.js → chunk-6DJBVMTR.js} +1 -1
  50. package/dist/{chunk-XH7NMH3Q.js → chunk-6R22H57A.js} +2 -2
  51. package/dist/{chunk-GVIPEBEL.js → chunk-7JO33ODX.js} +3 -3
  52. package/dist/{chunk-CCI2UBYR.js → chunk-AO75FKBR.js} +3 -3
  53. package/dist/{chunk-M2L4EHYW.js → chunk-CI2H3U7O.js} +2 -2
  54. package/dist/{chunk-PRVG3COH.js → chunk-CS5JKDWW.js} +2 -2
  55. package/dist/{chunk-WJUYWTNT.js → chunk-DP6FJABB.js} +1 -1
  56. package/dist/{chunk-NRV5PIPA.js → chunk-DU6UZXGV.js} +2 -2
  57. package/dist/{chunk-OUWDJIJF.js → chunk-E2WJLU5U.js} +1 -1
  58. package/dist/{chunk-BP3WMLXJ.js → chunk-EDEEITT3.js} +5 -5
  59. package/dist/{chunk-TJXCBTL4.js → chunk-GFY6XONT.js} +5 -5
  60. package/dist/{chunk-BAVNBGH4.js → chunk-GSMB7FWI.js} +7 -7
  61. package/dist/{chunk-BKOWTW5P.js → chunk-H7HRHS3M.js} +4 -4
  62. package/dist/{chunk-LSB66XQC.js → chunk-HMA7QQ3P.js} +4 -4
  63. package/dist/{chunk-LRLF6PZ2.js → chunk-IMUCTAM2.js} +1 -1
  64. package/dist/{chunk-AZMHKUUU.js → chunk-J3HI2SRD.js} +1 -1
  65. package/dist/{chunk-H7QTZTIE.js → chunk-JBVKA3UR.js} +934 -77
  66. package/dist/{chunk-2FOAQ64R.js → chunk-JHVSVVHB.js} +8 -8
  67. package/dist/{chunk-JGDBHB6L.js → chunk-KHYUAZPL.js} +2 -2
  68. package/dist/{chunk-S3DP6DCZ.js → chunk-KRZECDHA.js} +2 -2
  69. package/dist/{chunk-BJMVQ6D5.js → chunk-KT4SP73I.js} +4 -4
  70. package/dist/{chunk-GMVZYB3W.js → chunk-LD3A63IE.js} +3 -3
  71. package/dist/{chunk-DQGM57ZW.js → chunk-MTPE6BW7.js} +1 -1
  72. package/dist/{chunk-EO2GYHWH.js → chunk-MYTWZ33A.js} +3 -3
  73. package/dist/{chunk-7MYGOFVX.js → chunk-NKDK3H3I.js} +4 -4
  74. package/dist/{chunk-C2ZIVQ6W.js → chunk-OARF7TWF.js} +6 -6
  75. package/dist/{chunk-Y3OZ3CT6.js → chunk-OQ5K6QHU.js} +6 -5
  76. package/dist/{chunk-4DTKE3AS.js → chunk-PGFLQXW5.js} +2 -2
  77. package/dist/{chunk-SLKVEJLM.js → chunk-PWQN4D6R.js} +5 -5
  78. package/dist/{chunk-KMTSU366.js → chunk-Q6HJD6SH.js} +1 -1
  79. package/dist/{chunk-CJQEJWLU.js → chunk-QYD5TN2J.js} +5 -5
  80. package/dist/{chunk-L7PGUSAU.js → chunk-RZTWWE26.js} +1 -1
  81. package/dist/{chunk-BUOLA2AM.js → chunk-S6J3A4DF.js} +1 -1
  82. package/dist/{chunk-5L7H32JK.js → chunk-SAGO6JNL.js} +1 -1
  83. package/dist/{chunk-IWPEAA2J.js → chunk-SM4P6VIY.js} +1 -1
  84. package/dist/{chunk-QOMUEL44.js → chunk-SMA7LUCS.js} +1 -1
  85. package/dist/{chunk-DUVHHQEL.js → chunk-SMAY3CGD.js} +2 -2
  86. package/dist/{chunk-IM73P6JT.js → chunk-T4KXYKDL.js} +5 -5
  87. package/dist/{chunk-ETLVZHRG.js → chunk-V2FRBKMP.js} +2 -2
  88. package/dist/{chunk-WLDFMVRY.js → chunk-VTTHXOCR.js} +2 -2
  89. package/dist/{chunk-TILXDMUR.js → chunk-XKSAXKRY.js} +3 -3
  90. package/dist/{chunk-OSVDGVLL.js → chunk-XLNSQLTV.js} +12 -12
  91. package/dist/{chunk-TXKAPRIA.js → chunk-XNKFK27C.js} +1 -1
  92. package/dist/{chunk-G4X3Z3YS.js → chunk-XZRRYMY2.js} +4 -4
  93. package/dist/{chunk-2XM4TGIM.js → chunk-YZPCDR32.js} +4 -4
  94. package/dist/{chunk-PX4RRHEB.js → chunk-ZLKJHXSC.js} +4 -4
  95. package/dist/{global-upgrade-ZPULZXOY.js → global-upgrade-JDZPAQ6B.js} +6 -6
  96. package/dist/{paths-Y7ZWWCFK.js → paths-4QBYMQHK.js} +2 -2
  97. package/dist/{reapply-I4YMQP7F.js → reapply-26GMHUWI.js} +20 -20
  98. package/dist/src/index.js +19 -19
  99. package/dist/{upgrade-lock-IDAAFSH2.js → upgrade-lock-DIRCINDI.js} +3 -3
  100. package/package.json +1 -1
@@ -296,12 +296,27 @@ var normalizeAgentId = (value, accepted) => {
296
296
  return accepted.find((candidate) => names.includes(candidate)) ?? null;
297
297
  };
298
298
 
299
+ // ../contracts/src/shell-tools.ts
300
+ var SHELL_TOOL = "Bash";
301
+ var POWERSHELL_TOOL = "PowerShell";
302
+ var MONITOR_TOOL = "Monitor";
303
+ var SHELL_DIALECT_BY_TOOL = /* @__PURE__ */ new Map([
304
+ [SHELL_TOOL, "posix"],
305
+ [MONITOR_TOOL, "posix"],
306
+ [POWERSHELL_TOOL, "powershell"]
307
+ ]);
308
+ var shellDialectOf = (toolName) => SHELL_DIALECT_BY_TOOL.get(toolName);
309
+ var POSIX_SHELL_TOOLS = new Set(
310
+ [...SHELL_DIALECT_BY_TOOL].filter(([, dialect]) => dialect === "posix").map(([toolName]) => toolName)
311
+ );
312
+ var toolNameForAPosixReading = (toolName) => shellDialectOf(toolName) === "posix" ? SHELL_TOOL : toolName;
313
+
299
314
  // ../contracts/src/agent-wiring.ts
300
315
  var COMPATIBLE_AGENT_TYPES = ["qwen_code", "codebuddy", "qoder", "droid", "devin", "antigravity_cli"];
301
316
  var isCompatibleAgentType = (value) => typeof value === "string" && COMPATIBLE_AGENT_TYPES.includes(value);
302
317
  var CANONICAL_PATH_KEYS = ["file_path", "path", "notebook_path"];
303
318
  var CANONICAL_COMMAND_KEYS = ["command"];
304
- var SHELL_TOOLS = /* @__PURE__ */ new Set(["Bash", "PowerShell"]);
319
+ var SHELL_TOOLS = /* @__PURE__ */ new Set([SHELL_TOOL, POWERSHELL_TOOL]);
305
320
  var PATH_TOOLS = /* @__PURE__ */ new Set(["Write", "Edit", "MultiEdit", "NotebookEdit", "Read"]);
306
321
  var PHONE_ANSWERED_TOOLS = /* @__PURE__ */ new Set(["AskUserQuestion", "ExitPlanMode"]);
307
322
  var firstString = (record, keys) => {
@@ -319,15 +334,15 @@ var canonicalToolName = (profile, toolName) => profile.toolAliases[toolName] ??
319
334
  var TASK_OUTPUT_TOOL = "BashOutput";
320
335
  var TASK_STOP_TOOL = "KillShell";
321
336
  var BLANK_TASK_INPUT_TOOL = "TaskInput";
322
- var SHELL_TOOL = "Bash";
323
337
  var typesText = (value) => typeof value === "string" && value.trim().length > 0;
324
338
  var taskIdOf = (control, toolInput) => typeof toolInput[control.taskKey] === "string" ? { task_id: toolInput[control.taskKey] } : {};
325
339
  var typedIntoTask = (control, toolInput) => {
326
340
  const text = toolInput[control.inputKey];
327
341
  if (typesText(text)) return { tool: SHELL_TOOL, input: { command: text }, unreadable: false };
342
+ if (text !== void 0 && typeof text !== "string") return { tool: control.name, input: toolInput, unreadable: true };
328
343
  return {
329
344
  tool: BLANK_TASK_INPUT_TOOL,
330
- input: { ...taskIdOf(control, toolInput), input: typeof text === "string" ? text : "" },
345
+ input: { ...taskIdOf(control, toolInput), input: text ?? "" },
331
346
  unreadable: false
332
347
  };
333
348
  };
@@ -925,6 +940,816 @@ var shellWordsOf = (command) => {
925
940
  return words;
926
941
  };
927
942
 
943
+ // ../contracts/src/powershell-analysis.ts
944
+ var SINGLE_QUOTES = /* @__PURE__ */ new Set(["'", "\u2018", "\u2019", "\u201A", "\u201B"]);
945
+ var DOUBLE_QUOTES = /* @__PURE__ */ new Set(['"', "\u201C", "\u201D", "\u201E"]);
946
+ var ESCAPE = "`";
947
+ var NEWLINE = "\n";
948
+ var CARRIAGE_RETURN = "\r";
949
+ var WORD_SPACE = /[ \t\r\f\v ]/;
950
+ var GROUP_CLOSERS = /* @__PURE__ */ new Map([["(", ")"], ["{", "}"]]);
951
+ var STRAY_CLOSERS = /* @__PURE__ */ new Set([")", "}"]);
952
+ var SIGILS_THAT_OPEN_A_GROUP = /* @__PURE__ */ new Set(["$", "@"]);
953
+ var LINE_COMMENT = "#";
954
+ var BLOCK_COMMENT_OPEN = "<#";
955
+ var BLOCK_COMMENT_CLOSE = "#>";
956
+ var COMMENT_MAY_FOLLOW = /[\s;|&({]/;
957
+ var HERE_STRING_SIGIL = "@";
958
+ var HERE_STRING_HEADER_REST = /^[ \t\r]*\n/;
959
+ var TRAILING_CARRIAGE_RETURN = /\r$/;
960
+ var BRACED_VARIABLE_OPEN = "${";
961
+ var BRACED_VARIABLE_CLOSE = "}";
962
+ var VARIABLE_SIGIL = "$";
963
+ var SUBEXPRESSION_OPEN = "$(";
964
+ var SUBEXPRESSION_PLACEHOLDER = "$()";
965
+ var VARIABLE_NAME_START = /[A-Za-z0-9_?^$:{(]/;
966
+ var REDIRECTION_OPERATOR = /^[1-6*]?>>?(?:&[1-6])?/;
967
+ var STREAM_NUMBER = /[1-6*]/;
968
+ var OUTPUT_REDIRECT = ">";
969
+ var MERGES_INTO_A_STREAM = "&";
970
+ var PIPE2 = "|";
971
+ var AMPERSAND = "&";
972
+ var STATEMENT_SEPARATOR = ";";
973
+ var ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set(["=", "+=", "-=", "*=", "/=", "%=", "??="]);
974
+ var CALL_OPERATOR_WORD = { text: AMPERSAND, quoted: false, expands: false, nested: [] };
975
+ var NOT_FOUND = -1;
976
+ var TOP_LEVEL = 0;
977
+ var MAX_GROUP_NESTING = 128;
978
+ var opensAVariable = (source, index) => source.charAt(index) === VARIABLE_SIGIL && VARIABLE_NAME_START.test(source.charAt(index + 1));
979
+ var endOfLine = (source, index) => {
980
+ const newline = source.indexOf(NEWLINE, index);
981
+ return newline === NOT_FOUND ? source.length : newline;
982
+ };
983
+ var endOfBlockComment = (source, index) => {
984
+ const close = source.indexOf(BLOCK_COMMENT_CLOSE, index + BLOCK_COMMENT_OPEN.length);
985
+ return close === NOT_FOUND ? null : close + BLOCK_COMMENT_CLOSE.length;
986
+ };
987
+ var commentMayStartAt = (source, index) => index === 0 || COMMENT_MAY_FOLLOW.test(source.charAt(index - 1));
988
+ var opensAHereString = (source, index) => {
989
+ const quote = source.charAt(index + 1);
990
+ return source.charAt(index) === HERE_STRING_SIGIL && (SINGLE_QUOTES.has(quote) || DOUBLE_QUOTES.has(quote)) && HERE_STRING_HEADER_REST.test(source.slice(index + 2));
991
+ };
992
+ var singleQuotedTextAt = (source, open) => {
993
+ let text = "";
994
+ for (let index = open + 1; index < source.length; index += 1) {
995
+ const char = source.charAt(index);
996
+ if (!SINGLE_QUOTES.has(char)) {
997
+ text += char;
998
+ } else if (SINGLE_QUOTES.has(source.charAt(index + 1))) {
999
+ text += char;
1000
+ index += 1;
1001
+ } else {
1002
+ return { end: index + 1, text, expands: false, nested: [] };
1003
+ }
1004
+ }
1005
+ return null;
1006
+ };
1007
+ var expandableTextUntil = (source, start, closesAt, nesting) => {
1008
+ let text = "";
1009
+ let expands = false;
1010
+ const nested = [];
1011
+ for (let index = start; index < source.length; index += 1) {
1012
+ const char = source.charAt(index);
1013
+ if (closesAt(index)) return { end: index + 1, text, expands, nested };
1014
+ if (char === ESCAPE || DOUBLE_QUOTES.has(char) && DOUBLE_QUOTES.has(source.charAt(index + 1))) {
1015
+ text += source.charAt(index + 1);
1016
+ index += 1;
1017
+ } else if (source.startsWith(SUBEXPRESSION_OPEN, index)) {
1018
+ const group = groupAt(source, index + SUBEXPRESSION_OPEN.length, ")", nesting + 1);
1019
+ if (group === null) return null;
1020
+ nested.push(group.inner);
1021
+ text += SUBEXPRESSION_PLACEHOLDER;
1022
+ expands = true;
1023
+ index = group.end - 1;
1024
+ } else {
1025
+ expands ||= opensAVariable(source, index);
1026
+ text += char;
1027
+ }
1028
+ }
1029
+ return null;
1030
+ };
1031
+ var closesADoubleQuote = (source) => (index) => DOUBLE_QUOTES.has(source.charAt(index)) && !DOUBLE_QUOTES.has(source.charAt(index + 1));
1032
+ var doubleQuotedTextAt = (source, open, nesting) => expandableTextUntil(source, open + 1, closesADoubleQuote(source), nesting);
1033
+ var hereStringBody = (body, end, expandable, nesting) => {
1034
+ if (!expandable) return { end, text: body, expands: false, nested: [] };
1035
+ const scanned = expandableTextUntil(`${body}${NEWLINE}`, 0, (index) => index === body.length, nesting);
1036
+ return scanned === null ? null : { ...scanned, end };
1037
+ };
1038
+ var hereStringAt = (source, open, nesting) => {
1039
+ const quote = source.charAt(open + 1);
1040
+ const quotes = SINGLE_QUOTES.has(quote) ? SINGLE_QUOTES : DOUBLE_QUOTES;
1041
+ const header = HERE_STRING_HEADER_REST.exec(source.slice(open + 2));
1042
+ if (header === null) return null;
1043
+ const bodyStart = open + 2 + header[0].length;
1044
+ for (let lineStart = bodyStart; lineStart < source.length; ) {
1045
+ if (quotes.has(source.charAt(lineStart)) && source.charAt(lineStart + 1) === HERE_STRING_SIGIL) {
1046
+ const body = source.slice(bodyStart, Math.max(bodyStart, lineStart - 1)).replace(TRAILING_CARRIAGE_RETURN, "");
1047
+ return hereStringBody(body, lineStart + 2, quotes === DOUBLE_QUOTES, nesting);
1048
+ }
1049
+ const newline = source.indexOf(NEWLINE, lineStart);
1050
+ if (newline === NOT_FOUND) return null;
1051
+ lineStart = newline + 1;
1052
+ }
1053
+ return null;
1054
+ };
1055
+ var quotedTextAt = (source, index, nesting) => {
1056
+ if (opensAHereString(source, index)) return hereStringAt(source, index, nesting);
1057
+ return SINGLE_QUOTES.has(source.charAt(index)) ? singleQuotedTextAt(source, index) : doubleQuotedTextAt(source, index, nesting);
1058
+ };
1059
+ var opensQuotedText = (source, index) => SINGLE_QUOTES.has(source.charAt(index)) || DOUBLE_QUOTES.has(source.charAt(index)) || opensAHereString(source, index);
1060
+ var indexAfterGroupContent = (source, index, nesting) => {
1061
+ const char = source.charAt(index);
1062
+ if (char === ESCAPE) return index + 2;
1063
+ if (opensQuotedText(source, index)) return quotedTextAt(source, index, nesting)?.end ?? null;
1064
+ if (source.startsWith(BLOCK_COMMENT_OPEN, index)) return endOfBlockComment(source, index);
1065
+ if (char === LINE_COMMENT && commentMayStartAt(source, index)) return endOfLine(source, index);
1066
+ const closer = GROUP_CLOSERS.get(char);
1067
+ if (closer !== void 0) return groupAt(source, index + 1, closer, nesting + 1)?.end ?? null;
1068
+ return STRAY_CLOSERS.has(char) ? null : index + 1;
1069
+ };
1070
+ var groupAt = (source, start, closer, nesting) => {
1071
+ if (nesting > MAX_GROUP_NESTING) return null;
1072
+ for (let index = start; index < source.length; ) {
1073
+ if (source.charAt(index) === closer) return { end: index + 1, inner: source.slice(start, index) };
1074
+ const after = indexAfterGroupContent(source, index, nesting);
1075
+ if (after === null) return null;
1076
+ index = after;
1077
+ }
1078
+ return null;
1079
+ };
1080
+ var lineContinuationLength = (source, index) => {
1081
+ if (source.charAt(index) === NEWLINE) return 1;
1082
+ return source.charAt(index) === CARRIAGE_RETURN && source.charAt(index + 1) === NEWLINE ? 2 : 0;
1083
+ };
1084
+ var continuesWithAPipe = (source, from) => {
1085
+ const rest = source.slice(from).trimStart();
1086
+ return rest.startsWith(PIPE2) && !rest.startsWith(`${PIPE2}${PIPE2}`);
1087
+ };
1088
+ var isPowerShellAssignmentOperator = (word) => word !== void 0 && !word.quoted && ASSIGNMENT_OPERATORS.has(word.text);
1089
+ var opensARedirection = (source, index, wordStarted) => source.charAt(index) === OUTPUT_REDIRECT || !wordStarted && STREAM_NUMBER.test(source.charAt(index)) && source.charAt(index + 1) === OUTPUT_REDIRECT;
1090
+ var powerShellStatementsOf = (source) => {
1091
+ const statements = [];
1092
+ let stages = [];
1093
+ let words = [];
1094
+ let redirectTargets = [];
1095
+ let draft = null;
1096
+ let readsAPipe = false;
1097
+ let stageStart = 0;
1098
+ let targetsARedirect = false;
1099
+ const startWord = () => {
1100
+ draft ??= { text: "", quoted: false, expands: false, nested: [] };
1101
+ return draft;
1102
+ };
1103
+ const finishWord = () => {
1104
+ if (draft === null) return;
1105
+ if (targetsARedirect) redirectTargets.push(draft);
1106
+ else words.push(draft);
1107
+ draft = null;
1108
+ targetsARedirect = false;
1109
+ };
1110
+ const finishStage = (end, next) => {
1111
+ finishWord();
1112
+ if (words.length > 0 || redirectTargets.length > 0) {
1113
+ stages.push({ words, redirectTargets, readsAPipe, source: source.slice(stageStart, end).trim() });
1114
+ }
1115
+ words = [];
1116
+ redirectTargets = [];
1117
+ readsAPipe = false;
1118
+ stageStart = next;
1119
+ };
1120
+ const finishStatement = () => {
1121
+ if (stages.length > 0) statements.push({ stages });
1122
+ stages = [];
1123
+ };
1124
+ const awaitsAPipedStage = () => readsAPipe && words.length === 0 && draft === null;
1125
+ const startsACommand = () => draft === null && (words.length === 0 || isPowerShellAssignmentOperator(words.at(-1)));
1126
+ const groupAttachesToTheWord = () => draft !== null && SIGILS_THAT_OPEN_A_GROUP.has(draft.text.slice(-1));
1127
+ let index = 0;
1128
+ while (index < source.length) {
1129
+ const char = source.charAt(index);
1130
+ const next = source.charAt(index + 1);
1131
+ if (char === ESCAPE) {
1132
+ const continuation = lineContinuationLength(source, index + 1);
1133
+ if (continuation === 0) {
1134
+ const word = startWord();
1135
+ word.text += next;
1136
+ word.quoted = true;
1137
+ }
1138
+ index += 1 + Math.max(continuation, 1);
1139
+ } else if (char === NEWLINE) {
1140
+ if (!awaitsAPipedStage()) {
1141
+ finishStage(index, index + 1);
1142
+ if (!continuesWithAPipe(source, index + 1)) finishStatement();
1143
+ }
1144
+ index += 1;
1145
+ } else if (WORD_SPACE.test(char)) {
1146
+ finishWord();
1147
+ index += 1;
1148
+ } else if (char === STATEMENT_SEPARATOR) {
1149
+ finishStage(index, index + 1);
1150
+ finishStatement();
1151
+ index += 1;
1152
+ } else if (char === PIPE2) {
1153
+ const chained = next === PIPE2;
1154
+ finishStage(index, index + (chained ? 2 : 1));
1155
+ if (chained) finishStatement();
1156
+ else readsAPipe = true;
1157
+ index += chained ? 2 : 1;
1158
+ } else if (char === AMPERSAND && next !== AMPERSAND && startsACommand()) {
1159
+ words.push(CALL_OPERATOR_WORD);
1160
+ index += 1;
1161
+ } else if (char === AMPERSAND) {
1162
+ const chained = next === AMPERSAND;
1163
+ finishStage(index, index + (chained ? 2 : 1));
1164
+ finishStatement();
1165
+ index += chained ? 2 : 1;
1166
+ } else if (opensARedirection(source, index, draft !== null)) {
1167
+ finishWord();
1168
+ const operator = REDIRECTION_OPERATOR.exec(source.slice(index))?.[0] ?? char;
1169
+ targetsARedirect = !operator.includes(MERGES_INTO_A_STREAM);
1170
+ index += operator.length;
1171
+ } else if (draft === null && char === LINE_COMMENT) {
1172
+ index = endOfLine(source, index);
1173
+ } else if (draft === null && source.startsWith(BLOCK_COMMENT_OPEN, index)) {
1174
+ const end = endOfBlockComment(source, index);
1175
+ if (end === null) return null;
1176
+ index = end;
1177
+ } else if (SINGLE_QUOTES.has(char) || DOUBLE_QUOTES.has(char) || draft === null && opensAHereString(source, index)) {
1178
+ const quoted = quotedTextAt(source, index, TOP_LEVEL);
1179
+ if (quoted === null) return null;
1180
+ const word = startWord();
1181
+ word.text += quoted.text;
1182
+ word.quoted = true;
1183
+ word.expands ||= quoted.expands;
1184
+ word.nested.push(...quoted.nested);
1185
+ index = quoted.end;
1186
+ } else if (source.startsWith(BRACED_VARIABLE_OPEN, index)) {
1187
+ const close = source.indexOf(BRACED_VARIABLE_CLOSE, index + BRACED_VARIABLE_OPEN.length);
1188
+ if (close === NOT_FOUND) return null;
1189
+ const word = startWord();
1190
+ word.text += source.slice(index, close + 1);
1191
+ word.expands = true;
1192
+ index = close + 1;
1193
+ } else if (GROUP_CLOSERS.has(char)) {
1194
+ const closer = GROUP_CLOSERS.get(char) ?? "";
1195
+ const group = groupAt(source, index + 1, closer, TOP_LEVEL);
1196
+ if (group === null) return null;
1197
+ if (!groupAttachesToTheWord()) finishWord();
1198
+ const word = startWord();
1199
+ word.text += `${char}${closer}`;
1200
+ word.expands = true;
1201
+ word.nested.push(group.inner);
1202
+ index = group.end;
1203
+ } else if (STRAY_CLOSERS.has(char)) {
1204
+ return null;
1205
+ } else {
1206
+ const word = startWord();
1207
+ word.expands ||= opensAVariable(source, index);
1208
+ word.text += char;
1209
+ index += 1;
1210
+ }
1211
+ }
1212
+ finishStage(source.length, source.length);
1213
+ finishStatement();
1214
+ return statements;
1215
+ };
1216
+
1217
+ // ../contracts/src/powershell-consequences.ts
1218
+ var POWERSHELL_ALIASES = /* @__PURE__ */ new Map([
1219
+ ["rm", "remove-item"],
1220
+ ["del", "remove-item"],
1221
+ ["erase", "remove-item"],
1222
+ ["rd", "remove-item"],
1223
+ ["rmdir", "remove-item"],
1224
+ ["ri", "remove-item"],
1225
+ ["cp", "copy-item"],
1226
+ ["copy", "copy-item"],
1227
+ ["cpi", "copy-item"],
1228
+ ["mv", "move-item"],
1229
+ ["move", "move-item"],
1230
+ ["mi", "move-item"],
1231
+ ["ren", "rename-item"],
1232
+ ["rni", "rename-item"],
1233
+ ["sc", "set-content"],
1234
+ ["ac", "add-content"],
1235
+ ["clc", "clear-content"],
1236
+ ["ni", "new-item"],
1237
+ ["tee", "tee-object"],
1238
+ ["iwr", "invoke-webrequest"],
1239
+ ["curl", "invoke-webrequest"],
1240
+ ["wget", "invoke-webrequest"],
1241
+ ["irm", "invoke-restmethod"],
1242
+ ["iex", "invoke-expression"],
1243
+ ["icm", "invoke-command"],
1244
+ ["saps", "start-process"],
1245
+ ["start", "start-process"],
1246
+ ["spsv", "stop-service"],
1247
+ ["sasv", "start-service"],
1248
+ ["%", "foreach-object"],
1249
+ ["foreach", "foreach-object"],
1250
+ ["?", "where-object"],
1251
+ ["where", "where-object"],
1252
+ ["ls", "get-childitem"],
1253
+ ["dir", "get-childitem"],
1254
+ ["gci", "get-childitem"],
1255
+ ["cat", "get-content"],
1256
+ ["type", "get-content"],
1257
+ ["gc", "get-content"],
1258
+ ["echo", "write-output"],
1259
+ ["write", "write-output"],
1260
+ ["select", "select-object"],
1261
+ ["sort", "sort-object"],
1262
+ ["group", "group-object"],
1263
+ ["measure", "measure-object"],
1264
+ ["diff", "compare-object"],
1265
+ ["compare", "compare-object"],
1266
+ ["ft", "format-table"],
1267
+ ["fl", "format-list"],
1268
+ ["fw", "format-wide"],
1269
+ ["gi", "get-item"],
1270
+ ["gp", "get-itemproperty"],
1271
+ ["gl", "get-location"],
1272
+ ["pwd", "get-location"],
1273
+ ["cd", "set-location"],
1274
+ ["chdir", "set-location"],
1275
+ ["sl", "set-location"],
1276
+ ["pushd", "push-location"],
1277
+ ["popd", "pop-location"],
1278
+ ["gcm", "get-command"],
1279
+ ["gps", "get-process"],
1280
+ ["ps", "get-process"],
1281
+ ["gsv", "get-service"],
1282
+ ["sls", "select-string"],
1283
+ ["gm", "get-member"],
1284
+ ["gal", "get-alias"],
1285
+ ["gv", "get-variable"],
1286
+ ["h", "get-history"],
1287
+ ["history", "get-history"],
1288
+ ["cls", "clear-host"],
1289
+ ["clear", "clear-host"],
1290
+ ["sleep", "start-sleep"],
1291
+ ["kill", "stop-process"],
1292
+ ["spps", "stop-process"]
1293
+ ]);
1294
+ var POWERSHELL_READ_VERBS = /* @__PURE__ */ new Set([
1295
+ "get",
1296
+ "test",
1297
+ "select",
1298
+ "measure",
1299
+ "compare",
1300
+ "resolve",
1301
+ "convertto",
1302
+ "convertfrom",
1303
+ "find",
1304
+ "search",
1305
+ "wait",
1306
+ "read",
1307
+ "format"
1308
+ ]);
1309
+ var POWERSHELL_READ_CMDLETS = /* @__PURE__ */ new Set([
1310
+ "sort-object",
1311
+ "group-object",
1312
+ "where-object",
1313
+ "write-output",
1314
+ "write-host",
1315
+ "write-verbose",
1316
+ "write-debug",
1317
+ "write-information",
1318
+ "write-warning",
1319
+ "write-error",
1320
+ "write-progress",
1321
+ "out-string",
1322
+ "out-host",
1323
+ "out-null",
1324
+ "out-default",
1325
+ "split-path",
1326
+ "join-path",
1327
+ "set-location",
1328
+ "push-location",
1329
+ "pop-location",
1330
+ "clear-host",
1331
+ "start-sleep"
1332
+ ]);
1333
+ var POWERSHELL_WRITERS_WITH_A_READ_VERB = /* @__PURE__ */ new Set(["format-volume"]);
1334
+ var POWERSHELL_VERB_SEPARATOR = "-";
1335
+ var POWERSHELL_LANGUAGE_KEYWORDS = /* @__PURE__ */ new Set([
1336
+ "if",
1337
+ "elseif",
1338
+ "else",
1339
+ "foreach",
1340
+ "for",
1341
+ "while",
1342
+ "do",
1343
+ "until",
1344
+ "switch",
1345
+ "try",
1346
+ "catch",
1347
+ "finally",
1348
+ "trap",
1349
+ "function",
1350
+ "filter",
1351
+ "workflow",
1352
+ "param",
1353
+ "begin",
1354
+ "process",
1355
+ "end",
1356
+ "dynamicparam",
1357
+ "break",
1358
+ "continue",
1359
+ "exit",
1360
+ "throw",
1361
+ "data",
1362
+ "class",
1363
+ "enum",
1364
+ "using",
1365
+ "configuration",
1366
+ "in"
1367
+ ]);
1368
+ var POWERSHELL_CALL_OPERATORS = /* @__PURE__ */ new Set(["&", "."]);
1369
+ var POWERSHELL_RETURN_KEYWORD = "return";
1370
+ var POWERSHELL_ASSIGNMENT_TARGET = /^[$[]/;
1371
+ var POWERSHELL_ARRAY_SEPARATOR = ",";
1372
+ var POWERSHELL_ATTACHED_ASSIGNMENT = /^\$[^=\s]*?(?:[+\-*/%]|\?\?)?=(?!=)([\s\S]+)$/;
1373
+ var POWERSHELL_EXPRESSION_START = /^[$({@[\-–—―]/;
1374
+ var POWERSHELL_NUMBER_OR_RANGE = /^\d[\d.]*$/;
1375
+ var POWERSHELL_PARAMETER = /^[-–—―]([A-Za-z][\w-]*)(?::([\s\S]*))?$/;
1376
+ var POWERSHELL_SWITCH_OFF = "$false";
1377
+ var EXECUTABLE_EXTENSION = /\.(?:exe|cmd|bat|com)$/;
1378
+ var REMOVE_ITEM = "remove-item";
1379
+ var COPY_ITEM = "copy-item";
1380
+ var GET_CHILD_ITEM = "get-childitem";
1381
+ var FOREACH_OBJECT = "foreach-object";
1382
+ var INVOKE_EXPRESSION = "invoke-expression";
1383
+ var DELETE_METHOD = "delete";
1384
+ var RECURSE_PARAMETER = "recurse";
1385
+ var DEPTH_PARAMETER = "depth";
1386
+ var WHAT_IF_PARAMETER = "whatif";
1387
+ var DESTINATION_PARAMETER = "destination";
1388
+ var MEMBER_NAME_PARAMETER = "membername";
1389
+ var FILE_PARAMETER = "file";
1390
+ var FILE_PATH_PARAMETER = "filepath";
1391
+ var SHORTEST_PARAMETER_PREFIX = 1;
1392
+ var SHORTEST_DEPTH_PREFIX = 3;
1393
+ var SHORTEST_DESTINATION_PREFIX = 3;
1394
+ var SHORTEST_FILE_PATH_PREFIX = 2;
1395
+ var POWERSHELL_FILE_WRITERS = /* @__PURE__ */ new Set([
1396
+ "set-content",
1397
+ "add-content",
1398
+ "clear-content",
1399
+ "out-file",
1400
+ "new-item",
1401
+ REMOVE_ITEM,
1402
+ "move-item",
1403
+ "rename-item",
1404
+ "tee-object",
1405
+ "invoke-webrequest",
1406
+ "invoke-restmethod",
1407
+ "start-bitstransfer"
1408
+ ]);
1409
+ var POWERSHELL_FETCHERS = /* @__PURE__ */ new Set(["invoke-webrequest", "invoke-restmethod", "start-bitstransfer"]);
1410
+ var DISK_ERASERS = /* @__PURE__ */ new Set(["format-volume", "clear-disk", "initialize-disk", "remove-partition", "format"]);
1411
+ var WINDOWS_SERVICE_CHANGERS = /* @__PURE__ */ new Set([
1412
+ "start-service",
1413
+ "stop-service",
1414
+ "restart-service",
1415
+ "suspend-service",
1416
+ "resume-service",
1417
+ "set-service",
1418
+ "new-service",
1419
+ "remove-service"
1420
+ ]);
1421
+ var SERVICE_CONTROL_PROGRAM = "sc";
1422
+ var SERVICE_CONTROL_VERBS_THAT_CHANGE = /* @__PURE__ */ new Set([
1423
+ "start",
1424
+ "stop",
1425
+ "pause",
1426
+ "continue",
1427
+ "config",
1428
+ "create",
1429
+ "delete",
1430
+ "failure",
1431
+ "failureflag",
1432
+ "sidtype",
1433
+ "privs",
1434
+ "managedaccount",
1435
+ "description",
1436
+ "sdset",
1437
+ "control",
1438
+ "triggerinfo",
1439
+ "preferrednode"
1440
+ ]);
1441
+ var REMOTE_MACHINE_PREFIX = "\\\\";
1442
+ var NET_PROGRAMS = /* @__PURE__ */ new Set(["net", "net1"]);
1443
+ var NET_VERBS_THAT_CHANGE_A_SERVICE = /* @__PURE__ */ new Set(["stop", "pause", "continue"]);
1444
+ var NET_START = "start";
1445
+ var SCHEDULED_TASK_CHANGERS = /* @__PURE__ */ new Set([
1446
+ "register-scheduledtask",
1447
+ "unregister-scheduledtask",
1448
+ "set-scheduledtask",
1449
+ "enable-scheduledtask",
1450
+ "disable-scheduledtask",
1451
+ "start-scheduledtask",
1452
+ "stop-scheduledtask"
1453
+ ]);
1454
+ var SCHTASKS_PROGRAM = "schtasks";
1455
+ var SCHTASKS_SWITCHES_THAT_CHANGE = /^[/-](?:create|delete|change|run|end)$/i;
1456
+ var DOTNET_RECURSIVE_DELETE = /::Delete\s*\([^()]*,\s*(?:\$true|1)\s*\)|\.Delete\s*\(\s*\$true\s*\)/i;
1457
+ var DOTNET_DOWNLOAD = /\.Download(?:String|Data|File)(?:Async|TaskAsync)?\s*\(/i;
1458
+ var SCRIPTBLOCK_FROM_TEXT = /\[(?:System\.Management\.Automation\.)?ScriptBlock\]::Create\s*\(/i;
1459
+ var POWERSHELL_HOSTS = /* @__PURE__ */ new Set(["powershell", "pwsh", "powershell_ise"]);
1460
+ var WINDOWS_POWERSHELL_HOST = "powershell";
1461
+ var POWERSHELL_HOST_COMMAND_SWITCHES = /* @__PURE__ */ new Set(["-c", "-command", "--command", "/c", "/command"]);
1462
+ var POWERSHELL_HOST_SWITCHES_THAT_HIDE_THE_COMMAND = /* @__PURE__ */ new Set([
1463
+ "-f",
1464
+ "-file",
1465
+ "/f",
1466
+ "/file",
1467
+ "-e",
1468
+ "-ec",
1469
+ "-enc",
1470
+ "-encodedcommand",
1471
+ "/encodedcommand"
1472
+ ]);
1473
+ var POWERSHELL_HOST_OPTIONS_WITH_A_VALUE = /* @__PURE__ */ new Set([
1474
+ "-executionpolicy",
1475
+ "-ep",
1476
+ "-ex",
1477
+ "-windowstyle",
1478
+ "-w",
1479
+ "-workingdirectory",
1480
+ "-wd",
1481
+ "-configurationname",
1482
+ "-config",
1483
+ "-inputformat",
1484
+ "-inf",
1485
+ "-if",
1486
+ "-outputformat",
1487
+ "-of",
1488
+ "-o",
1489
+ "-version",
1490
+ "-v",
1491
+ "-settingsfile",
1492
+ "-custompipename",
1493
+ "-psconsolefile"
1494
+ ]);
1495
+ var POWERSHELL_HOST_SWITCH = /^[-/]/;
1496
+ var POWERSHELL_FILE_RUNNERS = /* @__PURE__ */ new Set(["start-process", "invoke-item", "msiexec"]);
1497
+ var WINDOWS_SWITCH = /^[-/–—―]/;
1498
+ var CMD_PROGRAM = "cmd";
1499
+ var CMD_RUNS_THE_REST = /^\/[ck]$/i;
1500
+ var CMD_SEPARATORS = ["&&", "||", "&", "|"];
1501
+ var CMD_ESCAPE = "^";
1502
+ var CMD_QUOTE = '"';
1503
+ var CMD_WORD_SEPARATOR = /\s+/;
1504
+ var CMD_RECURSIVE_REMOVERS = /* @__PURE__ */ new Set(["rd", "rmdir", "del", "erase"]);
1505
+ var CMD_SWITCH_PREFIX = "/";
1506
+ var CMD_RECURSE_SWITCH = "s";
1507
+ var WSL_PROGRAM = "wsl";
1508
+ var WSL_OPTIONS_WITH_A_VALUE = /* @__PURE__ */ new Set(["-d", "--distribution", "-u", "--user", "--cd", "--shell-type"]);
1509
+ var WSL_COMMAND_MARKERS = /* @__PURE__ */ new Set(["-e", "--exec", "--"]);
1510
+ var NO_SCRIPTS_INSIDE = { powerShell: [], cmd: [], posix: [] };
1511
+ var MAX_NESTED_SCRIPT_DEPTH = 4;
1512
+ var TOP_LEVEL_SCRIPT = 0;
1513
+ var POSIX_FLAG = /^-/;
1514
+ var PATH_SEPARATORS = /[/\\]/;
1515
+ var URL_QUERY_OR_FRAGMENT = /[?#].*$/;
1516
+ var fileNameOf = (path) => path.split(PATH_SEPARATORS).at(-1) ?? path;
1517
+ var parameterOf = (word) => {
1518
+ if (word === void 0 || word.quoted) return null;
1519
+ const match = POWERSHELL_PARAMETER.exec(word.text);
1520
+ return match === null ? null : { name: (match[1] ?? "").toLowerCase(), value: match[2] };
1521
+ };
1522
+ var namesTheParameter = (parameter, fullName, shortestPrefix) => parameter !== null && parameter.name.length >= shortestPrefix && fullName.startsWith(parameter.name);
1523
+ var turnsOn = (command, fullName, shortestPrefix) => command.args.some((arg) => {
1524
+ const parameter = parameterOf(arg);
1525
+ return namesTheParameter(parameter, fullName, shortestPrefix) && parameter?.value?.toLowerCase() !== POWERSHELL_SWITCH_OFF;
1526
+ });
1527
+ var parameterValueOf = (command, fullName, shortestPrefix) => {
1528
+ const index = command.args.findIndex((arg) => namesTheParameter(parameterOf(arg), fullName, shortestPrefix));
1529
+ return index === -1 ? void 0 : parameterOf(command.args[index])?.value ?? command.args[index + 1]?.text;
1530
+ };
1531
+ var operandTextsOf = (command) => command.args.flatMap((arg) => {
1532
+ const parameter = parameterOf(arg);
1533
+ const text = parameter === null ? arg.text : parameter.value;
1534
+ return text === void 0 ? [] : text.split(POWERSHELL_ARRAY_SEPARATOR);
1535
+ });
1536
+ var positionalTextsOf = (command) => command.args.filter((arg) => parameterOf(arg) === null).map((arg) => arg.text);
1537
+ var firstOperandOf = (command, isSwitch) => command.args.find((arg) => !isSwitch.test(arg.text))?.text;
1538
+ var namesASecretPath = (text, judge) => judge.namesASecretFile(fileNameOf(text.trim()));
1539
+ var isAssignmentTarget = (word) => POWERSHELL_ASSIGNMENT_TARGET.test(word.text) || word.text === POWERSHELL_ARRAY_SEPARATOR;
1540
+ var wordsAfterAnAssignment = (words) => {
1541
+ const operator = words.findIndex((word) => isPowerShellAssignmentOperator(word));
1542
+ if (operator > 0 && words.slice(0, operator).every(isAssignmentTarget)) return words.slice(operator + 1);
1543
+ const [first, ...rest] = words;
1544
+ const assigned = first === void 0 ? void 0 : POWERSHELL_ATTACHED_ASSIGNMENT.exec(first.text)?.[1];
1545
+ return first === void 0 || assigned === void 0 ? words : [{ ...first, text: assigned }, ...rest];
1546
+ };
1547
+ var commandWordsOf = (words) => {
1548
+ const assigned = wordsAfterAnAssignment(words);
1549
+ const returned = assigned[0] !== void 0 && !assigned[0].quoted && assigned[0].text.toLowerCase() === POWERSHELL_RETURN_KEYWORD ? assigned.slice(1) : assigned;
1550
+ const first = returned[0];
1551
+ const viaCallOperator = first !== void 0 && !first.quoted && POWERSHELL_CALL_OPERATORS.has(first.text);
1552
+ return { words: viaCallOperator ? returned.slice(1) : returned, viaCallOperator };
1553
+ };
1554
+ var namesAPowerShellCommand = (program, viaCallOperator, readsAPipe) => {
1555
+ if (program.text.length === 0 || POWERSHELL_EXPRESSION_START.test(program.text) || POWERSHELL_NUMBER_OR_RANGE.test(program.text)) {
1556
+ return false;
1557
+ }
1558
+ if (viaCallOperator) return true;
1559
+ return !program.quoted && (readsAPipe || !POWERSHELL_LANGUAGE_KEYWORDS.has(program.text.toLowerCase()));
1560
+ };
1561
+ var powerShellCommandOf = (stage) => {
1562
+ const { words, viaCallOperator } = commandWordsOf(stage.words);
1563
+ const [program, ...args] = words;
1564
+ if (program === void 0 || !namesAPowerShellCommand(program, viaCallOperator, stage.readsAPipe)) return null;
1565
+ const fileName = fileNameOf(program.text).toLowerCase();
1566
+ const name = fileName.replace(EXECUTABLE_EXTENSION, "");
1567
+ return { stage, program, args, fileName, name, cmdlet: POWERSHELL_ALIASES.get(fileName) ?? name };
1568
+ };
1569
+ var posixWordOf = (word) => ({ text: word.text, plain: !word.quoted, expands: word.expands, comment: false });
1570
+ var posixProgramWordOf = (command) => ({ ...posixWordOf(command.program), text: command.name });
1571
+ var posixInvocationOf = (command) => ({ program: posixProgramWordOf(command), args: command.args.map(posixWordOf) });
1572
+ var verbOfCmdlet = (cmdlet) => {
1573
+ const separator = cmdlet.indexOf(POWERSHELL_VERB_SEPARATOR);
1574
+ return separator === -1 ? "" : cmdlet.slice(0, separator);
1575
+ };
1576
+ var cmdletOnlyReads = (cmdlet) => POWERSHELL_READ_CMDLETS.has(cmdlet) || POWERSHELL_READ_VERBS.has(verbOfCmdlet(cmdlet)) && !POWERSHELL_WRITERS_WITH_A_READ_VERB.has(cmdlet);
1577
+ var readsLikeAPosixRead = (command, judge) => !command.program.expands && !command.args.some((arg) => arg.expands) && command.stage.redirectTargets.length === 0 && judge.onlyReads([command.name, ...command.args.map((arg) => arg.text)]);
1578
+ var onlyReads = (command, judge) => cmdletOnlyReads(command.cmdlet) || readsLikeAPosixRead(command, judge);
1579
+ var onlyPreviewsInPowerShell = (command) => turnsOn(command, WHAT_IF_PARAMETER, WHAT_IF_PARAMETER.length);
1580
+ var removesRecursively = (command) => command.cmdlet === REMOVE_ITEM && turnsOn(command, RECURSE_PARAMETER, SHORTEST_PARAMETER_PREFIX) && !onlyPreviewsInPowerShell(command);
1581
+ var listsRecursively = (command) => command.cmdlet === GET_CHILD_ITEM && (turnsOn(command, RECURSE_PARAMETER, SHORTEST_PARAMETER_PREFIX) || parameterValueOf(command, DEPTH_PARAMETER, SHORTEST_DEPTH_PREFIX) !== void 0);
1582
+ var calledMemberOf = (command) => (parameterValueOf(command, MEMBER_NAME_PARAMETER, SHORTEST_PARAMETER_PREFIX) ?? firstOperandOf(command, WINDOWS_SWITCH))?.toLowerCase();
1583
+ var removesWhatItIsGiven = (command) => !onlyPreviewsInPowerShell(command) && (command.cmdlet === REMOVE_ITEM || command.cmdlet === FOREACH_OBJECT && calledMemberOf(command) === DELETE_METHOD);
1584
+ var commandsOfStatement = (statement) => statement.stages.map(powerShellCommandOf);
1585
+ var listsRecursivelyIntoARemoval = (statement) => {
1586
+ const commands = commandsOfStatement(statement);
1587
+ const listing = commands.findIndex((command) => command !== null && listsRecursively(command));
1588
+ return listing !== -1 && commands.slice(listing + 1).some((command) => command !== null && removesWhatItIsGiven(command));
1589
+ };
1590
+ var copyDestinationOf = (command) => {
1591
+ const named = parameterValueOf(command, DESTINATION_PARAMETER, SHORTEST_DESTINATION_PREFIX);
1592
+ const positional = positionalTextsOf(command);
1593
+ return named ?? (positional.length > 1 ? positional.at(-1) : void 0);
1594
+ };
1595
+ var writesASecretFileFromPowerShell = (command, judge) => {
1596
+ if (command.cmdlet !== COPY_ITEM) {
1597
+ return POWERSHELL_FILE_WRITERS.has(command.cmdlet) && operandTextsOf(command).some((text) => namesASecretPath(text, judge));
1598
+ }
1599
+ const destination = copyDestinationOf(command);
1600
+ return destination !== void 0 && namesASecretPath(destination, judge);
1601
+ };
1602
+ var formatsADisk = (command) => DISK_ERASERS.has(command.cmdlet);
1603
+ var changesAWindowsService = (command) => {
1604
+ if (WINDOWS_SERVICE_CHANGERS.has(command.cmdlet)) return true;
1605
+ const [verb, ...operands] = command.args.map((arg) => arg.text.toLowerCase()).filter((text) => !text.startsWith(REMOTE_MACHINE_PREFIX));
1606
+ if (command.name === SERVICE_CONTROL_PROGRAM) return SERVICE_CONTROL_VERBS_THAT_CHANGE.has(verb ?? "");
1607
+ return NET_PROGRAMS.has(command.name) && (NET_VERBS_THAT_CHANGE_A_SERVICE.has(verb ?? "") || verb === NET_START && operands.length > 0);
1608
+ };
1609
+ var changesAScheduledTask = (command) => SCHEDULED_TASK_CHANGERS.has(command.cmdlet) || command.name === SCHTASKS_PROGRAM && command.args.some((arg) => SCHTASKS_SWITCHES_THAT_CHANGE.test(arg.text));
1610
+ var powerShellCommandChangesSomething = (command, judge) => judge.invocationShowsAConsequence(posixInvocationOf(command)) || !onlyPreviewsInPowerShell(command) && (writesASecretFileFromPowerShell(command, judge) || formatsADisk(command) || changesAWindowsService(command) || changesAScheduledTask(command));
1611
+ var keywordTextOf = (command) => [command.name, ...[...command.args, ...command.stage.redirectTargets].map((word) => word.text)].join(" ");
1612
+ var stageIsDestructive = (stage, judge) => {
1613
+ const command = powerShellCommandOf(stage);
1614
+ return DOTNET_RECURSIVE_DELETE.test(stage.source) || command !== null && (removesRecursively(command) || !onlyReads(command, judge) && judge.namesADestructiveAction(keywordTextOf(command)));
1615
+ };
1616
+ var stageHasAVisibleConsequence = (stage, judge) => {
1617
+ const command = powerShellCommandOf(stage);
1618
+ return stage.redirectTargets.some((target) => namesASecretPath(target.text, judge)) || command !== null && !onlyReads(command, judge) && powerShellCommandChangesSomething(command, judge);
1619
+ };
1620
+ var fetchesWithPowerShell = (stage, judge) => {
1621
+ const command = powerShellCommandOf(stage);
1622
+ return DOTNET_DOWNLOAD.test(stage.source) || command !== null && (POWERSHELL_FETCHERS.has(command.cmdlet) || judge.fetches(posixInvocationOf(command)));
1623
+ };
1624
+ var runsTextAsCode = (stage, judge) => {
1625
+ const command = powerShellCommandOf(stage);
1626
+ return SCRIPTBLOCK_FROM_TEXT.test(stage.source) || command !== null && (command.cmdlet === INVOKE_EXPRESSION || stage.readsAPipe && judge.runsWhatItReads(posixInvocationOf(command)));
1627
+ };
1628
+ var runsFetchedPowerShellCode = (stages, judge) => stages.some((stage) => fetchesWithPowerShell(stage, judge)) && stages.some((stage) => runsTextAsCode(stage, judge));
1629
+ var downloadedFileNameOf = (text) => fileNameOf(text.replace(URL_QUERY_OR_FRAGMENT, "")).toLowerCase();
1630
+ var downloadedFileNamesOf = (stages, judge) => new Set(stages.filter((stage) => fetchesWithPowerShell(stage, judge)).flatMap((stage) => {
1631
+ const command = powerShellCommandOf(stage);
1632
+ return command === null ? [] : operandTextsOf(command).map(downloadedFileNameOf);
1633
+ }).filter((fileName) => fileName.length > 0));
1634
+ var fileRunBy = (command, judge) => {
1635
+ if (POWERSHELL_HOSTS.has(command.name)) return parameterValueOf(command, FILE_PARAMETER, SHORTEST_PARAMETER_PREFIX);
1636
+ if (POWERSHELL_FILE_RUNNERS.has(command.cmdlet)) {
1637
+ return parameterValueOf(command, FILE_PATH_PARAMETER, SHORTEST_FILE_PATH_PREFIX) ?? firstOperandOf(command, WINDOWS_SWITCH);
1638
+ }
1639
+ return judge.runsScripts(posixProgramWordOf(command)) ? firstOperandOf(command, POSIX_FLAG) : void 0;
1640
+ };
1641
+ var runsADownloadedFile = (stages, judge) => {
1642
+ const downloaded = downloadedFileNamesOf(stages, judge);
1643
+ return downloaded.size > 0 && stages.some((stage) => {
1644
+ const command = powerShellCommandOf(stage);
1645
+ if (command === null || fetchesWithPowerShell(stage, judge)) return false;
1646
+ const file = fileRunBy(command, judge);
1647
+ return downloaded.has(command.fileName) || file !== void 0 && downloaded.has(downloadedFileNameOf(file));
1648
+ });
1649
+ };
1650
+ var invokedExpressionsOf = (command) => command.cmdlet === INVOKE_EXPRESSION ? positionalTextsOf(command) : [];
1651
+ var positionalHostCommandOf = (texts) => {
1652
+ let index = 0;
1653
+ while (index < texts.length && POWERSHELL_HOST_SWITCH.test(texts[index] ?? "")) {
1654
+ index += POWERSHELL_HOST_OPTIONS_WITH_A_VALUE.has((texts[index] ?? "").toLowerCase()) ? 2 : 1;
1655
+ }
1656
+ return index < texts.length ? texts.slice(index).join(" ") : void 0;
1657
+ };
1658
+ var hostedPowerShellScriptOf = (command) => {
1659
+ if (!POWERSHELL_HOSTS.has(command.name)) return void 0;
1660
+ const texts = command.args.map((arg) => arg.text);
1661
+ const lowered = texts.map((text) => text.toLowerCase());
1662
+ const commandSwitch = lowered.findIndex((text) => POWERSHELL_HOST_COMMAND_SWITCHES.has(text));
1663
+ if (commandSwitch !== -1) return texts.slice(commandSwitch + 1).join(" ");
1664
+ if (command.name !== WINDOWS_POWERSHELL_HOST || lowered.some((text) => POWERSHELL_HOST_SWITCHES_THAT_HIDE_THE_COMMAND.has(text))) {
1665
+ return void 0;
1666
+ }
1667
+ return positionalHostCommandOf(texts);
1668
+ };
1669
+ var cmdScriptOf = (command) => {
1670
+ if (command.name !== CMD_PROGRAM) return void 0;
1671
+ const start = command.args.findIndex((arg) => CMD_RUNS_THE_REST.test(arg.text));
1672
+ return start === -1 ? void 0 : command.args.slice(start + 1).map((arg) => arg.text).join(" ");
1673
+ };
1674
+ var cmdPiecesOf = (script) => {
1675
+ const pieces = [];
1676
+ let current = "";
1677
+ let quoted = false;
1678
+ for (let index = 0; index < script.length; index += 1) {
1679
+ const char = script.charAt(index);
1680
+ const separator = quoted ? void 0 : CMD_SEPARATORS.find((candidate) => script.startsWith(candidate, index));
1681
+ if (char === CMD_ESCAPE && !quoted) {
1682
+ current += script.slice(index, index + 2);
1683
+ index += 1;
1684
+ } else if (separator !== void 0) {
1685
+ pieces.push(current);
1686
+ current = "";
1687
+ index += separator.length - 1;
1688
+ } else {
1689
+ quoted = char === CMD_QUOTE ? !quoted : quoted;
1690
+ current += char;
1691
+ }
1692
+ }
1693
+ return [...pieces, current].map((piece) => piece.trim()).filter((piece) => piece.length > 0);
1694
+ };
1695
+ var namesTheCmdRecurseSwitch = (word) => word.startsWith(CMD_SWITCH_PREFIX) && word.toLowerCase().split(CMD_SWITCH_PREFIX).includes(CMD_RECURSE_SWITCH);
1696
+ var cmdPieceRemovesRecursively = (piece) => {
1697
+ const [program = "", ...args] = piece.replaceAll(CMD_QUOTE, "").split(CMD_WORD_SEPARATOR);
1698
+ return CMD_RECURSIVE_REMOVERS.has(program.toLowerCase()) && args.some(namesTheCmdRecurseSwitch);
1699
+ };
1700
+ var cmdScriptRemovesRecursively = (script) => cmdPiecesOf(script).some(cmdPieceRemovesRecursively);
1701
+ var wslCommandWordsOf = (command) => {
1702
+ if (command.name !== WSL_PROGRAM) return void 0;
1703
+ const texts = command.args.map((arg) => arg.text);
1704
+ let index = 0;
1705
+ while (index < texts.length && POSIX_FLAG.test(texts[index] ?? "")) {
1706
+ const text = texts[index] ?? "";
1707
+ index += WSL_OPTIONS_WITH_A_VALUE.has(text) ? 2 : 1;
1708
+ if (WSL_COMMAND_MARKERS.has(text)) break;
1709
+ }
1710
+ return index < texts.length ? texts.slice(index) : void 0;
1711
+ };
1712
+ var presentOnly = (value) => value === void 0 ? [] : [value];
1713
+ var scriptsInsideTheStage = (stage) => {
1714
+ const groups = [...stage.words, ...stage.redirectTargets].flatMap((word) => word.nested);
1715
+ const command = powerShellCommandOf(stage);
1716
+ if (command === null) return { ...NO_SCRIPTS_INSIDE, powerShell: groups };
1717
+ const cmd = presentOnly(cmdScriptOf(command));
1718
+ return {
1719
+ powerShell: [...groups, ...invokedExpressionsOf(command), ...presentOnly(hostedPowerShellScriptOf(command)), ...cmd.flatMap(cmdPiecesOf)],
1720
+ cmd,
1721
+ posix: presentOnly(wslCommandWordsOf(command))
1722
+ };
1723
+ };
1724
+ var powerShellReadingAt = (command, depth) => {
1725
+ const statements = powerShellStatementsOf(command);
1726
+ if (statements === null) return null;
1727
+ const inside = depth >= MAX_NESTED_SCRIPT_DEPTH ? [] : statements.flatMap((statement) => statement.stages).map(scriptsInsideTheStage);
1728
+ const nested = inside.flatMap((scripts) => scripts.powerShell).map((script) => ({ script, reading: powerShellReadingAt(script, depth + 1) }));
1729
+ const readings = nested.flatMap(({ reading }) => reading === null ? [] : [reading]);
1730
+ return {
1731
+ statements: [...statements, ...readings.flatMap((reading) => reading.statements)],
1732
+ cmdScripts: [...inside.flatMap((scripts) => scripts.cmd), ...readings.flatMap((reading) => reading.cmdScripts)],
1733
+ posixCommands: [...inside.flatMap((scripts) => scripts.posix), ...readings.flatMap((reading) => reading.posixCommands)],
1734
+ unreadScripts: [
1735
+ ...nested.flatMap(({ script, reading }) => reading === null ? [script] : []),
1736
+ ...readings.flatMap((reading) => reading.unreadScripts)
1737
+ ]
1738
+ };
1739
+ };
1740
+ var stagesOfTheReading = (reading) => reading.statements.flatMap((statement) => statement.stages);
1741
+ var powerShellReadingIsDestructive = (reading, judge) => stagesOfTheReading(reading).some((stage) => stageIsDestructive(stage, judge)) || reading.cmdScripts.some(cmdScriptRemovesRecursively) || reading.unreadScripts.some((script) => judge.namesADestructiveAction(script));
1742
+ var powerShellCommandIsDestructive = (command, judge) => {
1743
+ const reading = powerShellReadingAt(command, TOP_LEVEL_SCRIPT);
1744
+ return reading === null ? judge.namesADestructiveAction(command) : powerShellReadingIsDestructive(reading, judge);
1745
+ };
1746
+ var powerShellCommandHasAVisibleConsequence = (command, judge) => {
1747
+ const reading = powerShellReadingAt(command, TOP_LEVEL_SCRIPT);
1748
+ if (reading === null) return judge.namesADestructiveAction(command);
1749
+ const stages = stagesOfTheReading(reading);
1750
+ return powerShellReadingIsDestructive(reading, judge) || stages.some((stage) => stageHasAVisibleConsequence(stage, judge)) || reading.statements.some(listsRecursivelyIntoARemoval) || runsFetchedPowerShellCode(stages, judge) || runsADownloadedFile(stages, judge) || reading.posixCommands.some((words) => judge.commandShowsAConsequence(words));
1751
+ };
1752
+
928
1753
  // ../contracts/src/degraded.ts
929
1754
  var DEGRADED_PREFIX = "[degraded]";
930
1755
  var degradedPayload = (subsystem, report) => ({
@@ -1367,11 +2192,9 @@ var POLICY_PATH_KEYS = {
1367
2192
  NotebookEdit: "notebook_path",
1368
2193
  LS: "path"
1369
2194
  };
1370
- var POLICY_COMMAND_KEYS = {
1371
- Bash: "command",
1372
- PowerShell: "command",
1373
- Monitor: "command"
1374
- };
2195
+ var POLICY_COMMAND_KEYS = Object.fromEntries(
2196
+ [...SHELL_DIALECT_BY_TOOL.keys()].map((toolName) => [toolName, "command"])
2197
+ );
1375
2198
  var POLICY_ARG_KEYS = { ...POLICY_COMMAND_KEYS, ...POLICY_PATH_KEYS };
1376
2199
  var extractPolicyArg = (toolName, toolInput) => {
1377
2200
  const key = POLICY_ARG_KEYS[toolName];
@@ -2234,40 +3057,47 @@ var writesASecretFile = ({ program, args }) => {
2234
3057
  if (WRITES_EVERY_OPERAND.has(name)) return operands.some(namesASecretFile);
2235
3058
  return EDITS_IN_PLACE.has(name) && args.some((arg) => IN_PLACE_FLAG.test(arg.text)) && operands.some(namesASecretFile);
2236
3059
  };
2237
- var GITHUB_RESOURCE_NOUNS = /* @__PURE__ */ new Set([
2238
- "pr",
2239
- "issue",
2240
- "release",
2241
- "repo",
2242
- "gist",
2243
- "label",
2244
- "secret",
2245
- "variable",
2246
- "workflow",
2247
- "run",
2248
- "cache",
2249
- "project",
2250
- "ruleset",
2251
- "codespace",
2252
- "org",
2253
- "discussion"
2254
- ]);
2255
- var GITHUB_READ_VERBS = /* @__PURE__ */ new Set([
2256
- "view",
2257
- "list",
2258
- "ls",
2259
- "status",
2260
- "diff",
2261
- "checks",
2262
- "check",
2263
- "watch",
3060
+ var GITHUB_COMMANDS_THAT_ONLY_READ = /* @__PURE__ */ new Set([
3061
+ "search",
2264
3062
  "browse",
2265
- "download",
2266
- "clone",
2267
- "checkout",
2268
- "get",
2269
- "field-list",
2270
- "item-list"
3063
+ "status",
3064
+ "help",
3065
+ "version",
3066
+ "completion"
3067
+ ]);
3068
+ var githubReadVerbs = (...verbs) => /* @__PURE__ */ new Set(["list", "ls", ...verbs]);
3069
+ var GITHUB_RULESET_READS = githubReadVerbs("view", "check");
3070
+ var GITHUB_CODESPACE_READS = githubReadVerbs("view");
3071
+ var GITHUB_EXTENSION_READS = githubReadVerbs("search");
3072
+ var GITHUB_ATTESTATION_READS = /* @__PURE__ */ new Set(["verify", "download", "trusted-root"]);
3073
+ var GITHUB_READ_COMMANDS = /* @__PURE__ */ new Map([
3074
+ ["pr", githubReadVerbs("view", "status", "diff", "checks", "checkout", "co")],
3075
+ ["issue", githubReadVerbs("view", "status")],
3076
+ ["release", githubReadVerbs("view", "download")],
3077
+ ["repo", githubReadVerbs("view", "clone")],
3078
+ ["gist", githubReadVerbs("view", "clone")],
3079
+ ["label", githubReadVerbs()],
3080
+ ["secret", githubReadVerbs()],
3081
+ ["variable", githubReadVerbs("get")],
3082
+ ["workflow", githubReadVerbs("view")],
3083
+ ["run", githubReadVerbs("view", "watch", "download")],
3084
+ ["cache", githubReadVerbs()],
3085
+ ["project", githubReadVerbs("view", "field-list", "item-list")],
3086
+ ["ruleset", GITHUB_RULESET_READS],
3087
+ ["rs", GITHUB_RULESET_READS],
3088
+ ["codespace", GITHUB_CODESPACE_READS],
3089
+ ["cs", GITHUB_CODESPACE_READS],
3090
+ ["org", githubReadVerbs()],
3091
+ ["auth", /* @__PURE__ */ new Set(["status"])],
3092
+ ["extension", GITHUB_EXTENSION_READS],
3093
+ ["extensions", GITHUB_EXTENSION_READS],
3094
+ ["ext", GITHUB_EXTENSION_READS],
3095
+ ["alias", githubReadVerbs()],
3096
+ ["config", githubReadVerbs("get")],
3097
+ ["ssh-key", githubReadVerbs()],
3098
+ ["gpg-key", githubReadVerbs()],
3099
+ ["attestation", GITHUB_ATTESTATION_READS],
3100
+ ["at", GITHUB_ATTESTATION_READS]
2271
3101
  ]);
2272
3102
  var GITHUB_OPTIONS_WITH_VALUES = /* @__PURE__ */ new Set(["-R", "--repo", "--hostname"]);
2273
3103
  var GITHUB_API_SUBCOMMAND = "api";
@@ -2348,11 +3178,16 @@ var githubApiRequestWrites = (args) => {
2348
3178
  if (args.some((arg) => arg.text === GITHUB_GRAPHQL_ENDPOINT)) return graphqlRequestCanWrite(args);
2349
3179
  return args.some((arg) => GITHUB_API_BODY_FLAG.test(arg.text));
2350
3180
  };
3181
+ var githubCommandOnlyReads = (noun, verb) => {
3182
+ if (noun === void 0 || GITHUB_COMMANDS_THAT_ONLY_READ.has(noun.text)) return true;
3183
+ const readVerbs = GITHUB_READ_COMMANDS.get(noun.text);
3184
+ return readVerbs !== void 0 && (verb === void 0 || readVerbs.has(verb.text));
3185
+ };
2351
3186
  var githubCliWrites = (args) => {
2352
3187
  const meaningful = argsAfterHarmlessGlobalFlags(args);
2353
3188
  const [noun, verb] = positionalWordsOf(meaningful, GITHUB_OPTIONS_WITH_VALUES);
2354
3189
  if (noun?.text === GITHUB_API_SUBCOMMAND) return githubApiRequestWrites(meaningful.slice(meaningful.indexOf(noun) + 1));
2355
- return noun !== void 0 && GITHUB_RESOURCE_NOUNS.has(noun.text) && verb !== void 0 && !GITHUB_READ_VERBS.has(verb.text);
3190
+ return !githubCommandOnlyReads(noun, verb);
2356
3191
  };
2357
3192
  var stripeCliWrites = (args) => {
2358
3193
  const [command, operation] = positionalWordsOf(args, STRIPE_OPTIONS_WITH_VALUES);
@@ -2381,19 +3216,22 @@ var invocationWritesThroughARemoteApi = ({ program, args }) => {
2381
3216
  const writes = program === void 0 ? void 0 : REMOTE_API_CLI_WRITES.get(basenameOf(program.text));
2382
3217
  return writes !== void 0 && writes(args);
2383
3218
  };
2384
- var commandWritesThroughARemoteApi = (command) => {
2385
- const segments = readableCommandSegments(command);
2386
- return segments !== null && segments.some((segment) => invocationWritesThroughARemoteApi(invocationOf(segment)));
3219
+ var segmentWritesThroughARemoteApi = (segment, depth) => {
3220
+ const innermost = innermostInvocation(segment.invocation);
3221
+ return invocationWritesThroughARemoteApi(innermost) || commandsNestedIn(innermost, inlineScriptsOf(innermost, segment.heredocs)).some((nested) => commandWritesThroughARemoteApiAt(nested, depth + 1));
2387
3222
  };
3223
+ var commandWritesThroughARemoteApiAt = (command, depth) => depth <= MAX_SPELLING_DEPTH && spelledSegmentsOf(command).some((segment) => segmentWritesThroughARemoteApi(segment, depth));
3224
+ var commandWritesThroughARemoteApi = (command) => commandWritesThroughARemoteApiAt(command, 0);
2388
3225
  var segmentNeedsAPerson = (toolName, segment) => {
2389
3226
  const invocation = invocationOf(segment);
2390
3227
  const normalized = normalizedInvocation(invocation);
2391
3228
  return invocationHidesItsEffect(invocation) || subcommandDestroys(invocation) || changesWhatIsDeployed(toolName, invocation, normalized) || sqlClientChangesData(invocation) || classifyDecisionRisk(toolName, normalized) !== "standard" || isCoveredByPolicy(CAPABILITY_PATTERNS.destructive, toolName, normalized) || isCoveredByPolicy(CAPABILITY_PATTERNS.network, toolName, normalized) || isCoveredByPolicy(DATA_LOSS_COMMAND_PATTERNS, toolName, normalized);
2392
3229
  };
2393
3230
  var commandNeedsAPerson = (toolName, command) => {
2394
- if (toolName === "Bash" && isSafeReadOnlyCommand(command)) return false;
3231
+ const readingTool = toolNameForAPosixReading(toolName);
3232
+ if (readingTool === SHELL_TOOL && isSafeReadOnlyCommand(command)) return false;
2395
3233
  const segments = readableCommandSegments(command);
2396
- return segments === null || classifyDecisionRisk(toolName, command) !== "standard" || segments.some((segment) => segmentNeedsAPerson(toolName, segment)) || pipesIntoASqlClient(command);
3234
+ return segments === null || classifyDecisionRisk(readingTool, command) !== "standard" || segments.some((segment) => segmentNeedsAPerson(readingTool, segment)) || pipesIntoASqlClient(command) || shellDialectOf(toolName) === "powershell" && powerShellCommandHasAVisibleConsequence(command, posixShellJudgeFor(toolName));
2397
3235
  };
2398
3236
  var VISIBLE_DATA_LOSS_PATTERNS = [
2399
3237
  "Bash(git branch -D:*)",
@@ -2660,9 +3498,9 @@ var interpreterNameOf = (program) => basenameOf(program.text).replace(/\d+(?:\.\
2660
3498
  var runsScripts = (program) => SHELLS.has(basenameOf(program.text)) || INLINE_CODE_INTERPRETERS.has(interpreterNameOf(program));
2661
3499
  var runsWhatItReads = ({ program, args }) => program !== void 0 && runsScripts(program) && (args.length === 0 || args.every((arg) => arg.text.startsWith("-")) || args.some((arg) => arg.text === STANDARD_INPUT_ARGUMENT) || SHELLS.has(basenameOf(program.text)) && args.some((arg) => READS_ITS_SCRIPT_FROM_STANDARD_INPUT.test(arg.text)));
2662
3500
  var fetches = (invocation) => FETCHING_PROGRAMS.has(basenameOf(innermostInvocation(invocation).program?.text ?? ""));
2663
- var URL_QUERY_OR_FRAGMENT = /[?#].*$/;
3501
+ var URL_QUERY_OR_FRAGMENT2 = /[?#].*$/;
2664
3502
  var SOURCES_A_SCRIPT = /* @__PURE__ */ new Set(["source", "."]);
2665
- var downloadedNamesOf = (invocations) => new Set(invocations.filter(fetches).flatMap((invocation) => innermostInvocation(invocation).args.filter((arg) => !FLAG.test(arg.text)).map((arg) => basenameOf(arg.text.replace(URL_QUERY_OR_FRAGMENT, "")))));
3503
+ var downloadedNamesOf = (invocations) => new Set(invocations.filter(fetches).flatMap((invocation) => innermostInvocation(invocation).args.filter((arg) => !FLAG.test(arg.text)).map((arg) => basenameOf(arg.text.replace(URL_QUERY_OR_FRAGMENT2, "")))));
2666
3504
  var runsADownloadedScript = (invocations) => {
2667
3505
  const downloaded = downloadedNamesOf(invocations);
2668
3506
  return downloaded.size > 0 && invocations.map((invocation) => innermostInvocation(invocation)).some(({ program, args }) => {
@@ -2716,7 +3554,7 @@ var OUTPUT_REDIRECTION = new RegExp(String.raw`(?:\d*|&)(?:>>?|>\||<>|>&|<&)\s*$
2716
3554
  var REDIRECTED_INPUT_MARK = "\uE000";
2717
3555
  var ROUGH_SEPARATORS = ["&&", "||", "$(", "\n", ";", "|", "&", "`", "(", ")", "{", "}"];
2718
3556
  var SEPARATORS_INSIDE_DOUBLE_QUOTES = /* @__PURE__ */ new Set(["$(", "`", ")"]);
2719
- var PIPE2 = "|";
3557
+ var PIPE3 = "|";
2720
3558
  var SUBSTITUTION_OPENERS = /* @__PURE__ */ new Set(["$(", "`"]);
2721
3559
  var QUOTE_CHARACTERS = /['"]/g;
2722
3560
  var roughPiecesOf = (text) => {
@@ -2764,8 +3602,8 @@ var roughSegmentsOf = (command) => {
2764
3602
  heredocsSeen += heredocCount;
2765
3603
  return {
2766
3604
  invocation: invocationOfRoughPiece(piece.text),
2767
- readsInput: piece.text.includes(REDIRECTED_INPUT_MARK) || heredocCount > 0 || piece.before === PIPE2,
2768
- readsAPipe: piece.before === PIPE2,
3605
+ readsInput: piece.text.includes(REDIRECTED_INPUT_MARK) || heredocCount > 0 || piece.before === PIPE3,
3606
+ readsAPipe: piece.before === PIPE3,
2769
3607
  feedsASubstitution: SUBSTITUTION_OPENERS.has(pieces[index + 1]?.before ?? ""),
2770
3608
  heredocs
2771
3609
  };
@@ -2791,7 +3629,19 @@ var commandHasAVisibleConsequenceAt = (toolName, command, depth) => {
2791
3629
  const invocations = segments.map((segment) => invocationOf(withoutShellGrouping(segment)));
2792
3630
  return invocations.some((invocation) => invocationHasAVisibleConsequence(toolName, invocation, depth)) || pipesIntoASqlClient(command) || pipesFetchedCodeIntoAnInterpreter(command, invocations) || runsADownloadedScript(invocations);
2793
3631
  };
2794
- var commandHasAVisibleConsequence = (toolName, command) => commandHasAVisibleConsequenceAt(toolName, command, 0);
3632
+ var posixCommandOf = (words) => words.map(asOneShellWord).join(" ");
3633
+ var posixShellJudgeFor = (toolName) => ({
3634
+ namesADestructiveAction: (text) => classifyDecisionRisk(toolName, text) === "destructive",
3635
+ invocationShowsAConsequence: (invocation) => invocationHasAVisibleConsequence(SHELL_TOOL, invocation, 0),
3636
+ commandShowsAConsequence: (words) => commandHasAVisibleConsequenceAt(SHELL_TOOL, posixCommandOf(words), 1),
3637
+ onlyReads: (words) => isSafeReadOnlyCommand(posixCommandOf(words)),
3638
+ fetches,
3639
+ runsWhatItReads,
3640
+ runsScripts,
3641
+ namesASecretFile: (fileName) => SECRET_FILE_NAME.test(fileName)
3642
+ });
3643
+ var commandIsDestructive = (toolName, command) => shellDialectOf(toolName) === "powershell" ? powerShellCommandIsDestructive(command, posixShellJudgeFor(toolName)) : classifyDecisionRisk(toolNameForAPosixReading(toolName), command) === "destructive";
3644
+ var commandHasAVisibleConsequence = (toolName, command) => shellDialectOf(toolName) === "powershell" ? powerShellCommandHasAVisibleConsequence(command, posixShellJudgeFor(toolName)) : commandHasAVisibleConsequenceAt(toolNameForAPosixReading(toolName), command, 0);
2795
3645
  var MAX_SPELLING_DEPTH = 3;
2796
3646
  var GIT_GLOBAL_OPTIONS_WITH_A_VALUE = /* @__PURE__ */ new Set([
2797
3647
  "-C",
@@ -2907,7 +3757,7 @@ var withoutSessionToolGrants = (config) => ({
2907
3757
  policies: config.policies.filter((policy) => !isSessionToolGrant(policy))
2908
3758
  });
2909
3759
  var SESSION_TOOL_GRANT_TOOLS = /* @__PURE__ */ new Set(["Bash"]);
2910
- var isStandingShellAllow = (policy) => !policy.origin && !isSessionToolGrant(policy) && SESSION_TOOL_GRANT_TOOLS.has(policy.tool) && isAutoApprove(policy);
3760
+ var isStandingShellAllow = (policy) => !policy.origin && !isSessionToolGrant(policy) && SHELL_DIALECT_BY_TOOL.has(policy.tool) && isAutoApprove(policy);
2911
3761
  var MCP_TOOL_PREFIX = "mcp__";
2912
3762
  var parseMcpToolName = (toolName) => {
2913
3763
  if (!toolName.startsWith(MCP_TOOL_PREFIX)) return void 0;
@@ -3500,7 +4350,6 @@ var AGENT_TASK_CONTROL_TOOLS = [TASK_OUTPUT_TOOL, TASK_STOP_TOOL];
3500
4350
  var AGENT_TASK_CONTROL_TOOL_NAMES = new Set(AGENT_TASK_CONTROL_TOOLS);
3501
4351
  var readsOrStopsItsOwnWork = (toolName) => isCodexCoordinationTool(toolName) || AGENT_TASK_CONTROL_TOOL_NAMES.has(toolName);
3502
4352
  var coordinationFloorApplies = (toolName, rank) => readsOrStopsItsOwnWork(toolName) && !isNamedByARule(rank);
3503
- var POSIX_SHELL_TOOLS = /* @__PURE__ */ new Set(["Bash", "Monitor"]);
3504
4353
  var argumentsAsWritten = (args) => ({ forms: args, hidesWhatItRuns: false });
3505
4354
  var namesAnArgumentOf = (pattern, toolName) => pattern.startsWith(`${toolName}(`);
3506
4355
  var isSpelledOut = (form) => form.length > 0;
@@ -3517,7 +4366,7 @@ var restrictionReadingOf = (restrictingPatterns, toolName, args) => {
3517
4366
  };
3518
4367
  var restrictingPatternsOf = (policies) => policies.filter(restricts).map((policy) => policy.tool);
3519
4368
  var policyReadingOf = (policies, toolName, args) => restrictionReadingOf(restrictingPatternsOf(policies), toolName, args);
3520
- var stricterRule = (current, challenger) => current !== void 0 && (challenger === void 0 || restraintRank(current.policy) > restraintRank(challenger.policy)) ? current : challenger;
4369
+ var stricterRule = (current, challenger) => current !== void 0 && (challenger === void 0 || comparePolicyStrictness(current.policy, challenger.policy) > 0) ? current : challenger;
3521
4370
  var restrictsAnArgumentOf = (policy, toolName) => restricts(policy) && namesAnArgumentOf(policy.tool, toolName);
3522
4371
  var strictestRuleNamingAnArgument = (pool, toolName, repoKey, sessionId) => pool.filter((policy) => restrictsAnArgumentOf(policy, toolName) && appliesToThisCall(policy, repoKey, sessionId)).reduce((strictest, policy) => stricterRule(strictest, { policy, rank: "prefix" }), void 0);
3523
4372
  var governingRuleForReading = (pool, toolName, args, reading, repoKey, sessionId) => {
@@ -3555,7 +4404,7 @@ var unmatchedPolicyOf = (config, toolName) => ({
3555
4404
  mode: config.defaultMode ?? "push_first",
3556
4405
  pushFirstSeconds: config.defaultPushFirstSeconds ?? 20
3557
4406
  });
3558
- var stricterOfTheReadings = (asWritten, asSpelled, unmatched) => restraintRank(asWritten?.policy ?? unmatched) > restraintRank(asSpelled?.policy ?? unmatched) ? asWritten : asSpelled;
4407
+ var stricterOfTheReadings = (asWritten, asSpelled, unmatched) => comparePolicyStrictness(asWritten?.policy ?? unmatched, asSpelled?.policy ?? unmatched) > 0 ? asWritten : asSpelled;
3559
4408
  var resolvePolicy = (config, toolName, modeOverride, toolInput, cwd, repoKey, sessionId) => {
3560
4409
  const args = toolInput ? policyArgForms(toolName, toolInput, cwd) : [];
3561
4410
  const arg = args[0];
@@ -3577,7 +4426,7 @@ var resolvePolicy = (config, toolName, modeOverride, toolInput, cwd, repoKey, se
3577
4426
  base = autoApprove(base.tool);
3578
4427
  }
3579
4428
  const wouldAutoApprove = isAutoApprove(base);
3580
- if (!governedBySpecificRule && wouldAutoApprove && toolName === "Bash" && typeof arg === "string" && (classifyDecisionRisk(toolName, arg) === "destructive" || governedByStandingShellAllow && commandHasAVisibleConsequence(toolName, arg))) {
4429
+ if (!governedBySpecificRule && wouldAutoApprove && SHELL_DIALECT_BY_TOOL.has(toolName) && typeof arg === "string" && (commandIsDestructive(toolName, arg) || governedByStandingShellAllow && commandHasAVisibleConsequence(toolName, arg))) {
3581
4430
  base = {
3582
4431
  tool: base.tool,
3583
4432
  timeoutSeconds: config.defaultTimeoutSeconds,
@@ -3598,7 +4447,14 @@ var restraintRank = (policy) => {
3598
4447
  if (policy.mode === "push_only") return 3;
3599
4448
  return policy.mode === "terminal_only" || policy.mode === "notify_only" ? 1 : 2;
3600
4449
  };
3601
- var strictestPolicy = (a, b) => restraintRank(b) > restraintRank(a) ? b : a;
4450
+ var TIMEOUT_ACTION_STRICTNESS = {
4451
+ approve: 0,
4452
+ escalate: 1,
4453
+ wait: 1,
4454
+ deny: 2
4455
+ };
4456
+ var comparePolicyStrictness = (a, b) => restraintRank(a) - restraintRank(b) || TIMEOUT_ACTION_STRICTNESS[a.timeoutAction] - TIMEOUT_ACTION_STRICTNESS[b.timeoutAction];
4457
+ var strictestPolicy = (current, challenger) => comparePolicyStrictness(current, challenger) > 0 ? current : challenger;
3602
4458
  var resolvePolicyAcross = (config, toolName, modeOverride, toolInputs, cwd, repoKey, sessionId) => {
3603
4459
  if (toolInputs.length === 0) return resolvePolicy(config, toolName, modeOverride, void 0, cwd, repoKey, sessionId);
3604
4460
  return toolInputs.map((input) => resolvePolicy(config, toolName, modeOverride, input, cwd, repoKey, sessionId)).reduce(strictestPolicy);
@@ -3623,7 +4479,7 @@ var strictestScopeVerdict = (scope, paths) => {
3623
4479
  };
3624
4480
  var survivesDegraded = (config, toolName, toolInputs, cwd, repoKey, sessionId) => toolInputs.length === 1 && resolveAutoResolveOrigin(config, toolName, toolInputs[0], cwd, repoKey, sessionId) === "safe_readonly";
3625
4481
  var FULL_DEFER_MODES = /* @__PURE__ */ new Set(["plan", "auto", "dontAsk"]);
3626
- var ACCEPT_EDITS_DEFER_TOOLS = /* @__PURE__ */ new Set([
4482
+ var FILE_EDIT_TOOLS = /* @__PURE__ */ new Set([
3627
4483
  "Write",
3628
4484
  "Edit",
3629
4485
  "MultiEdit",
@@ -3633,7 +4489,7 @@ var shouldDeferToNativeMode = (permissionMode, toolName, options = {}) => {
3633
4489
  if (options.respectPermissionMode === false) return false;
3634
4490
  if (typeof permissionMode !== "string") return false;
3635
4491
  if (FULL_DEFER_MODES.has(permissionMode)) return true;
3636
- if (permissionMode === "acceptEdits" && ACCEPT_EDITS_DEFER_TOOLS.has(toolName)) return true;
4492
+ if (permissionMode === "acceptEdits" && FILE_EDIT_TOOLS.has(toolName)) return true;
3637
4493
  if (permissionMode === "bypassPermissions") return options.deferBypass === true;
3638
4494
  return false;
3639
4495
  };
@@ -3726,7 +4582,7 @@ var resolveGate = (input) => {
3726
4582
  scopePath: scopeReason && "path" in scopeVerdict ? widenablePath(scopeVerdict.path) : void 0
3727
4583
  };
3728
4584
  };
3729
- var editAsksAtTheAgentsPrompt = (input, verdict) => verdict.kind === "gate" && !verdict.scopeReason && (input.modeState.mode ?? input.config.modeOverride ?? null) === null && !aChosenRuleGoverns(input) && verdict.policy.mode === "push_first" && ACCEPT_EDITS_DEFER_TOOLS.has(input.toolName);
4585
+ var editAsksAtTheAgentsPrompt = (input, verdict) => verdict.kind === "gate" && !verdict.scopeReason && (input.modeState.mode ?? input.config.modeOverride ?? null) === null && !aChosenRuleGoverns(input) && verdict.policy.mode === "push_first" && FILE_EDIT_TOOLS.has(input.toolName);
3730
4586
  var claudePromptsBeforeAnEdit = (permissionMode) => permissionMode === "default";
3731
4587
  var runsTheClaudeHook = (source) => source === null || source === "claude" || hookCompatibleProfileBySource(source) !== void 0;
3732
4588
  var agentPromptsBeforeAnEdit = ({ source, event, permissionMode }) => {
@@ -3741,13 +4597,9 @@ var NO_RESPONSE_REASON = "No response within timeout";
3741
4597
  var codexRaisesItsOwnPrompts = (permissionMode) => permissionMode !== "bypassPermissions";
3742
4598
  var codexHasNoPromptOfItsOwn = (scopeReason, permissionMode) => scopeReason !== void 0 || !codexRaisesItsOwnPrompts(permissionMode);
3743
4599
  var CODEX_ASK_PASSES = { kind: "pass" };
3744
- var CODEX_ASK_UNANSWERED = { kind: "deny", reason: NO_RESPONSE_REASON };
3745
- var timeoutActionApplies = (ask) => ask.mode === "push_only" && ask.fullWindowServed;
3746
- var codexUnansweredPreToolUse = (ask) => {
3747
- if (timeoutActionApplies(ask) && ask.timeoutAction === "approve") return CODEX_ASK_PASSES;
3748
- if (timeoutActionApplies(ask) && ask.timeoutAction === "deny") return CODEX_ASK_UNANSWERED;
3749
- return codexRaisesItsOwnPrompts(ask.permissionMode) ? CODEX_ASK_PASSES : CODEX_ASK_UNANSWERED;
3750
- };
4600
+ var codexAskUnanswered = (ask) => ({ kind: "deny", reason: unansweredRefusalReason(ask.paused) });
4601
+ var ruleApprovesAfterItsFullWindow = (ask) => ask.mode === "push_only" && ask.fullWindowServed && ask.timeoutAction === "approve";
4602
+ var codexUnansweredPreToolUse = (ask) => ruleApprovesAfterItsFullWindow(ask) ? CODEX_ASK_PASSES : codexAskUnanswered(ask);
3751
4603
  var HANDED_BACK_REASON = "Handling on your machine";
3752
4604
  var HAND_BACK_WITHOUT_A_PROMPT = { kind: "refuse", reason: NO_AGENT_PROMPT_REASON };
3753
4605
  var CODEX_HAND_BACK_REASON = "You chose to handle this on your machine, so it did not run. Ask Codex to run it again while you are at your computer, or run it yourself.";
@@ -3756,18 +4608,18 @@ var codexDeferredPreToolUse = () => ({ kind: "deny", reason: CODEX_PRE_TOOL_USE_
3756
4608
  var isScopeReason = (scopeReason) => typeof scopeReason === "string" && scopeReason.length > 0;
3757
4609
  var scopeBreachReasonOf = (verdict) => verdict.kind === "gate" && isScopeReason(verdict.scopeReason) ? verdict.scopeReason : void 0;
3758
4610
  var onlyCodexPreToolUseCanAsk = (verdict, permissionMode) => verdict.kind === "gate" && (scopeBreachReasonOf(verdict) !== void 0 || !codexRaisesItsOwnPrompts(permissionMode));
3759
- var runsACommandThatNeedsAPerson = ({ toolName, toolInputs }) => toolName === "Bash" && toolInputs.some((toolInput) => {
4611
+ var runsACommandThatNeedsAPerson = ({ toolName, toolInputs }) => SHELL_DIALECT_BY_TOOL.has(toolName) && toolInputs.some((toolInput) => {
3760
4612
  const command = extractPolicyArg(toolName, toolInput);
3761
4613
  return command !== void 0 && (commandNeedsAPerson(toolName, command) || commandWritesThroughARemoteApi(command));
3762
4614
  });
3763
- var CI_WORKFLOW_FILE = /(?:^|\/)\.github\/workflows\/[^/]+$/;
3764
- var FILE_WRITING_TOOLS = /* @__PURE__ */ new Set(["Edit", "Write", "MultiEdit", "NotebookEdit"]);
4615
+ var CI_WORKFLOW_FILE = /(?:^|\/)\.github\/workflows\/[^/]+$/i;
3765
4616
  var namesASecretOrWorkflowFile = (path) => SECRET_FILE_NAME.test(basenameOf(path)) || CI_WORKFLOW_FILE.test(normalizeSeparators(path));
3766
- var writesASecretOrWorkflowFile = ({ toolName, toolInputs }) => FILE_WRITING_TOOLS.has(toolName) && toolInputs.some((toolInput) => {
4617
+ var fileEditNeedsAPerson = (toolName, path) => FILE_EDIT_TOOLS.has(toolName) && namesASecretOrWorkflowFile(path);
4618
+ var editsAFileThatNeedsAPerson = ({ toolName, toolInputs }) => toolInputs.some((toolInput) => {
3767
4619
  const path = extractPolicyArg(toolName, toolInput);
3768
- return path !== void 0 && namesASecretOrWorkflowFile(path);
4620
+ return path !== void 0 && fileEditNeedsAPerson(toolName, path);
3769
4621
  });
3770
- var codexCallNeedsAPerson = (input, verdict, call) => onlyCodexPreToolUseCanAsk(verdict, call.permissionMode) || verdict.kind === "gate" && (aChosenRuleGoverns(input) || call.deletesFiles || runsACommandThatNeedsAPerson(input) || writesASecretOrWorkflowFile(input));
4622
+ var codexCallNeedsAPerson = (input, verdict, call) => onlyCodexPreToolUseCanAsk(verdict, call.permissionMode) || verdict.kind === "gate" && (aChosenRuleGoverns(input) || call.deletesFiles || runsACommandThatNeedsAPerson(input) || editsAFileThatNeedsAPerson(input));
3771
4623
  var MAX_AGENT_PERMISSION_RULES_PER_KIND = 256;
3772
4624
  var MAX_AGENT_PERMISSION_RULE_LENGTH = 512;
3773
4625
  var isAgentPermissionRule = (value) => typeof value === "string" && value.length > 0 && value.length <= MAX_AGENT_PERMISSION_RULE_LENGTH;
@@ -3802,7 +4654,8 @@ var allowRulesGrant = (rules, toolName, args) => {
3802
4654
  var inputNeedsAPerson = (toolName, toolInput) => {
3803
4655
  const arg = extractPolicyArg(toolName, toolInput);
3804
4656
  if (arg === void 0) return false;
3805
- return toolName in POLICY_COMMAND_KEYS ? commandNeedsAPerson(toolName, arg) : classifyDecisionRisk(toolName, arg) !== "standard";
4657
+ if (toolName in POLICY_COMMAND_KEYS) return commandNeedsAPerson(toolName, arg);
4658
+ return fileEditNeedsAPerson(toolName, arg) || classifyDecisionRisk(toolName, arg) !== "standard";
3806
4659
  };
3807
4660
  var agentRulesAllowEveryInput = (rules, toolName, toolInputs, cwd) => rules.allow.length > 0 && toolInputs.length > 0 && toolInputs.every((toolInput) => {
3808
4661
  const args = policyArgForms(toolName, toolInput, cwd);
@@ -4010,6 +4863,9 @@ var WITHDRAWN_APPROVAL_REASON = "The phone question was withdrawn. Approve in th
4010
4863
  var PLAN_DECLINED_REASON = "Plan declined from the phone. Ask what to change before coding.";
4011
4864
  var claudeStoppedPreToolUseOutput = (reason) => stoppedOutput(claudePreToolUseOutput("deny", reason), reason);
4012
4865
  var claudeStoppedPermissionRequestOutput = (reason) => stoppedOutput(claudePermissionRequestOutput("deny", reason), reason);
4866
+ var UNANSWERED_ASKS_BEFORE_PAUSE = 3;
4867
+ var SESSION_PAUSED_REASON = `Phone approvals for this session are paused because ${UNANSWERED_ASKS_BEFORE_PAUSE} of them went unanswered, so this was refused without asking anyone. A notification was sent to your phone: tap Approve on it to resume, then run this again.`;
4868
+ var unansweredRefusalReason = (paused) => paused ? SESSION_PAUSED_REASON : NO_RESPONSE_REASON;
4013
4869
  var UNHEARD_PUSH_WINDOW_DAYS = 14;
4014
4870
  var DAY_MS = 24 * 60 * 60 * 1e3;
4015
4871
  var UNHEARD_PUSH_WINDOW_MS = UNHEARD_PUSH_WINDOW_DAYS * DAY_MS;
@@ -4411,7 +5267,6 @@ export {
4411
5267
  SCOPE_BATCH_REASON,
4412
5268
  UNREADABLE_CALL_REASON,
4413
5269
  unapprovedScopeReason,
4414
- NO_RESPONSE_REASON,
4415
5270
  codexHasNoPromptOfItsOwn,
4416
5271
  codexUnansweredPreToolUse,
4417
5272
  HANDED_BACK_REASON,
@@ -4444,6 +5299,8 @@ export {
4444
5299
  PLAN_DECLINED_REASON,
4445
5300
  claudeStoppedPreToolUseOutput,
4446
5301
  claudeStoppedPermissionRequestOutput,
5302
+ SESSION_PAUSED_REASON,
5303
+ unansweredRefusalReason,
4447
5304
  ELICITATION_ANSWERABLE_MODE,
4448
5305
  readElicitationFields,
4449
5306
  planElicitationAsk,