@pushary/agent-hooks 0.28.1 → 0.28.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/package.json +1 -1
  2. package/dist/chunk-22CV7V7A.js +0 -38
  3. package/dist/chunk-2BE2IPMO.js +0 -315
  4. package/dist/chunk-2CRLBMOX.js +0 -244
  5. package/dist/chunk-2HMNOZPY.js +0 -109
  6. package/dist/chunk-2I6DLXJN.js +0 -219
  7. package/dist/chunk-2Q6XPZ4Q.js +0 -395
  8. package/dist/chunk-3LC4YUMA.js +0 -194
  9. package/dist/chunk-3MIR7ODJ.js +0 -112
  10. package/dist/chunk-3QZESA66.js +0 -222
  11. package/dist/chunk-4Z4MB37G.js +0 -96
  12. package/dist/chunk-5GFUI5N6.js +0 -132
  13. package/dist/chunk-5JEDLXEC.js +0 -99
  14. package/dist/chunk-5LTQNC7R.js +0 -824
  15. package/dist/chunk-5MA3CPZB.js +0 -141
  16. package/dist/chunk-5QHQVXWN.js +0 -174
  17. package/dist/chunk-5V3XJ2ES.js +0 -357
  18. package/dist/chunk-6A3WCJO2.js +0 -416
  19. package/dist/chunk-6QWFMVCD.js +0 -328
  20. package/dist/chunk-6SRXMZAN.js +0 -99
  21. package/dist/chunk-7OXL2QQ4.js +0 -357
  22. package/dist/chunk-7PTU7TGE.js +0 -96
  23. package/dist/chunk-AB4KX4XT.js +0 -109
  24. package/dist/chunk-AC4UYAGX.js +0 -136
  25. package/dist/chunk-ACE77TKQ.js +0 -328
  26. package/dist/chunk-BHAMEPOP.js +0 -323
  27. package/dist/chunk-BYNYYZWW.js +0 -412
  28. package/dist/chunk-C4BMEVK7.js +0 -208
  29. package/dist/chunk-C5TFTNHG.js +0 -244
  30. package/dist/chunk-CH53PBQN.js +0 -265
  31. package/dist/chunk-DF3BM6BF.js +0 -195
  32. package/dist/chunk-DKZVKEOW.js +0 -175
  33. package/dist/chunk-EMPL27ZV.js +0 -96
  34. package/dist/chunk-EQJXMEIR.js +0 -175
  35. package/dist/chunk-FB3N633T.js +0 -145
  36. package/dist/chunk-FGZZRCOG.js +0 -194
  37. package/dist/chunk-FXYTRZHC.js +0 -177
  38. package/dist/chunk-GTJGZBTQ.js +0 -328
  39. package/dist/chunk-GYPPVD3P.js +0 -1047
  40. package/dist/chunk-HJMFYDWY.js +0 -222
  41. package/dist/chunk-HRQEECB6.js +0 -315
  42. package/dist/chunk-HWEMAAOY.js +0 -370
  43. package/dist/chunk-I4GMPUYN.js +0 -231
  44. package/dist/chunk-IBWCHA5M.js +0 -10
  45. package/dist/chunk-JPRRYC5X.js +0 -328
  46. package/dist/chunk-KTM4ZQ3W.js +0 -96
  47. package/dist/chunk-KTP2EPVB.js +0 -27
  48. package/dist/chunk-KYARP7KP.js +0 -97
  49. package/dist/chunk-LXUHXG2X.js +0 -937
  50. package/dist/chunk-M2N5DYWN.js +0 -247
  51. package/dist/chunk-M4GDBGXF.js +0 -824
  52. package/dist/chunk-M5F2L4KF.js +0 -177
  53. package/dist/chunk-M6S3M6E3.js +0 -244
  54. package/dist/chunk-N7VXDBQU.js +0 -6
  55. package/dist/chunk-O2QL6U6G.js +0 -194
  56. package/dist/chunk-O6A5RHWY.js +0 -122
  57. package/dist/chunk-ODUXELPM.js +0 -219
  58. package/dist/chunk-OF5WIOYS.js +0 -129
  59. package/dist/chunk-OP4QAN23.js +0 -99
  60. package/dist/chunk-P4JH2Q7Z.js +0 -102
  61. package/dist/chunk-PMD5JSV3.js +0 -242
  62. package/dist/chunk-PSSHNBEL.js +0 -177
  63. package/dist/chunk-PZO7RZ5W.js +0 -145
  64. package/dist/chunk-QEPRH7JB.js +0 -315
  65. package/dist/chunk-QRXWPZKN.js +0 -308
  66. package/dist/chunk-QY4L6XHN.js +0 -384
  67. package/dist/chunk-RNWPCELY.js +0 -176
  68. package/dist/chunk-RSHN2AQ7.js +0 -29
  69. package/dist/chunk-RZLVE57X.js +0 -38
  70. package/dist/chunk-SDCIKREA.js +0 -241
  71. package/dist/chunk-SDREQWNI.js +0 -175
  72. package/dist/chunk-SH26ZOHU.js +0 -159
  73. package/dist/chunk-SJ5MC36D.js +0 -882
  74. package/dist/chunk-TRLBBLSS.js +0 -176
  75. package/dist/chunk-U6OXZPYC.js +0 -384
  76. package/dist/chunk-UDQZNO5H.js +0 -231
  77. package/dist/chunk-UIBTFZUD.js +0 -314
  78. package/dist/chunk-USUCPCUC.js +0 -156
  79. package/dist/chunk-UTK3TJC4.js +0 -882
  80. package/dist/chunk-V4GLWPD7.js +0 -174
  81. package/dist/chunk-VC6U3QGF.js +0 -142
  82. package/dist/chunk-VIST7ACL.js +0 -88
  83. package/dist/chunk-VUNL35KE.js +0 -16
  84. package/dist/chunk-VWBNI4SC.js +0 -174
  85. package/dist/chunk-W5KRWUNE.js +0 -262
  86. package/dist/chunk-WCGKLHCL.js +0 -154
  87. package/dist/chunk-WNXGIEX7.js +0 -219
  88. package/dist/chunk-WPVL6VIT.js +0 -160
  89. package/dist/chunk-X6LV22NZ.js +0 -229
  90. package/dist/chunk-XHTZ2DWC.js +0 -206
  91. package/dist/chunk-XPVSZIA3.js +0 -315
  92. package/dist/chunk-Y633ZIJF.js +0 -384
  93. package/dist/chunk-YCL4GUFR.js +0 -222
  94. package/dist/chunk-YTMKB44I.js +0 -220
  95. package/dist/chunk-ZWBS3T7Q.js +0 -244
  96. package/dist/pushary-mode-T7XOPI6Z.js +0 -83
  97. package/dist/pushary-wait-4BUC6ZM6.js +0 -93
@@ -1,160 +0,0 @@
1
- // ../contracts/src/index.ts
2
- var APPROVAL_MODES = ["push_only", "terminal_only", "push_first", "notify_only"];
3
- var isApprovalMode = (value) => typeof value === "string" && APPROVAL_MODES.includes(value);
4
- var MATCH_RANKS = ["none", "tool", "prefix", "exact"];
5
- var matchRankWeight = (rank) => MATCH_RANKS.indexOf(rank);
6
- var matchToolPattern = (pattern, toolName, arg) => {
7
- const open = pattern.indexOf("(");
8
- if (open === -1 || !pattern.endsWith(")")) {
9
- return pattern === toolName ? "tool" : "none";
10
- }
11
- if (pattern.slice(0, open) !== toolName || arg === void 0) return "none";
12
- const inner = pattern.slice(open + 1, -1);
13
- if (inner.endsWith(":*")) {
14
- return arg.startsWith(inner.slice(0, -2)) ? "prefix" : "none";
15
- }
16
- return arg === inner ? "exact" : "none";
17
- };
18
- var POLICY_ARG_KEYS = {
19
- Bash: "command",
20
- Edit: "file_path",
21
- Write: "file_path"
22
- };
23
- var extractPolicyArg = (toolName, toolInput) => {
24
- const key = POLICY_ARG_KEYS[toolName];
25
- if (!key) return void 0;
26
- const value = toolInput[key];
27
- return typeof value === "string" ? value : void 0;
28
- };
29
- var SAFE_SHELL_COMMANDS = /* @__PURE__ */ new Set([
30
- "ls",
31
- "pwd",
32
- "cd",
33
- "cat",
34
- "head",
35
- "tail",
36
- "wc",
37
- "echo",
38
- "printf",
39
- "which",
40
- "type",
41
- "whoami",
42
- "id",
43
- "uname",
44
- "arch",
45
- "printenv",
46
- "locale",
47
- "tty",
48
- "dirname",
49
- "basename",
50
- "realpath",
51
- "readlink",
52
- "stat",
53
- "cut",
54
- "nl",
55
- "tr",
56
- "comm",
57
- "diff",
58
- "cmp",
59
- "grep",
60
- "egrep",
61
- "fgrep",
62
- "jq",
63
- "cksum",
64
- "md5sum",
65
- "sha1sum",
66
- "sha256sum",
67
- "du",
68
- "df",
69
- "ps",
70
- "true"
71
- ]);
72
- var SAFE_GIT_SUBCOMMANDS = /* @__PURE__ */ new Set([
73
- "status",
74
- "log",
75
- "diff",
76
- "show",
77
- "rev-parse",
78
- "describe",
79
- "blame",
80
- "shortlog",
81
- "ls-files",
82
- "ls-tree",
83
- "cat-file",
84
- "whatchanged",
85
- "rev-list",
86
- "name-rev",
87
- "for-each-ref",
88
- "var",
89
- "count-objects"
90
- ]);
91
- var GIT_WRITE_FLAGS = (token) => token === "--output" || token.startsWith("--output=");
92
- var UNSAFE_SHELL_CHARS = /[;&|<>(){}`\\\n\r]/;
93
- var basenameOf = (token) => {
94
- const slash = Math.max(token.lastIndexOf("/"), token.lastIndexOf("\\"));
95
- return slash === -1 ? token : token.slice(slash + 1);
96
- };
97
- var tokenizeShellCommand = (command) => {
98
- const tokens = [];
99
- let current = "";
100
- let quote = null;
101
- let started = false;
102
- for (const ch of command) {
103
- if (quote) {
104
- if (ch === quote) quote = null;
105
- else current += ch;
106
- started = true;
107
- continue;
108
- }
109
- if (ch === '"' || ch === "'") {
110
- quote = ch;
111
- started = true;
112
- continue;
113
- }
114
- if (ch === " " || ch === " ") {
115
- if (started) {
116
- tokens.push(current);
117
- current = "";
118
- started = false;
119
- }
120
- continue;
121
- }
122
- current += ch;
123
- started = true;
124
- }
125
- if (quote) return null;
126
- if (started) tokens.push(current);
127
- return tokens;
128
- };
129
- var isSafeReadOnlyCommand = (command) => {
130
- const trimmed = command.trim();
131
- if (!trimmed || trimmed.length > 2e3) return false;
132
- if (UNSAFE_SHELL_CHARS.test(trimmed)) return false;
133
- const tokens = tokenizeShellCommand(trimmed);
134
- if (!tokens || tokens.length === 0) return false;
135
- const first = tokens[0];
136
- if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(first) || first.includes("$")) return false;
137
- const exe = basenameOf(first);
138
- if (exe === "git") {
139
- const sub = tokens[1];
140
- if (!sub || sub.startsWith("-")) return false;
141
- if (!SAFE_GIT_SUBCOMMANDS.has(sub)) return false;
142
- return !tokens.some(GIT_WRITE_FLAGS);
143
- }
144
- return SAFE_SHELL_COMMANDS.has(exe);
145
- };
146
- var API_KEY_PATTERN = /^pk_[a-f0-9]+\.[a-f0-9]+$/;
147
- var isValidApiKey = (value) => API_KEY_PATTERN.test(value);
148
- var ACTION_BODY_MAX = 4e3;
149
- var DECISION_LINE_MAX = 500;
150
-
151
- export {
152
- isApprovalMode,
153
- matchRankWeight,
154
- matchToolPattern,
155
- extractPolicyArg,
156
- isSafeReadOnlyCommand,
157
- isValidApiKey,
158
- ACTION_BODY_MAX,
159
- DECISION_LINE_MAX
160
- };
@@ -1,229 +0,0 @@
1
- import {
2
- denyReasonFrom,
3
- isDeferAnswer
4
- } from "./chunk-KQYIHZ5E.js";
5
- import {
6
- DEFAULT_SESSION,
7
- askUser,
8
- cancelQuestion,
9
- deriveAction,
10
- deriveActionBody,
11
- deriveBlocker,
12
- deriveToolTarget,
13
- describeToolCall,
14
- fetchModeState,
15
- getMachineId,
16
- getPolicy,
17
- readLastPrompt,
18
- readLastUserPrompt,
19
- resolvePolicy,
20
- savePendingQuestion,
21
- sendNotification,
22
- waitForAnswer
23
- } from "./chunk-UTK3TJC4.js";
24
- import {
25
- hookWaitClamped,
26
- hookWaitDeadline
27
- } from "./chunk-XHTZ2DWC.js";
28
- import {
29
- getApiKey
30
- } from "./chunk-NKXSILEW.js";
31
-
32
- // src/hook.ts
33
- import { basename } from "path";
34
- var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
35
- var START_MS = Date.now();
36
- var allow = () => ({
37
- hookSpecificOutput: {
38
- hookEventName: "PreToolUse",
39
- permissionDecision: "allow"
40
- }
41
- });
42
- var deny = (reason) => ({
43
- hookSpecificOutput: {
44
- hookEventName: "PreToolUse",
45
- permissionDecision: "deny",
46
- permissionDecisionReason: reason
47
- }
48
- });
49
- var ask = (reason) => ({
50
- hookSpecificOutput: {
51
- hookEventName: "PreToolUse",
52
- permissionDecision: "ask",
53
- ...reason ? { permissionDecisionReason: reason } : {}
54
- }
55
- });
56
- var pollForAnswer = async (apiKey, correlationId, deadlineMs, pollInterval = 2e3) => {
57
- while (Date.now() < deadlineMs) {
58
- const remaining = Math.min(Math.max(deadlineMs - Date.now(), 1e3), 3e4);
59
- let answer;
60
- try {
61
- answer = await waitForAnswer(apiKey, correlationId, remaining);
62
- } catch {
63
- if (Date.now() + pollInterval >= deadlineMs) break;
64
- await sleep(pollInterval);
65
- continue;
66
- }
67
- if (answer.answered) return answer;
68
- if (Date.now() + pollInterval >= deadlineMs) break;
69
- await sleep(pollInterval);
70
- }
71
- return { answered: false };
72
- };
73
- var handlePushOnly = async (apiKey, description, projectName, timeoutSeconds, timeoutAction, sessionId, machineId, toolName, toolTarget, decision) => {
74
- let result;
75
- try {
76
- result = await askUser(apiKey, {
77
- question: `Allow ${description}?`,
78
- type: "confirm",
79
- context: `Agent wants to run this in ${projectName}`,
80
- agentName: `Claude Code - ${projectName}`,
81
- sessionId,
82
- machineId,
83
- toolName,
84
- toolTarget,
85
- ...decision
86
- });
87
- } catch {
88
- switch (timeoutAction) {
89
- case "approve":
90
- return allow();
91
- case "deny":
92
- return deny("Push notification failed, denying per policy");
93
- default:
94
- return ask("Push notification failed, asking in terminal");
95
- }
96
- }
97
- if (result.suppressed) {
98
- await cancelQuestion(apiKey, result.correlationId).catch(() => {
99
- });
100
- return ask("You are at the keyboard \u2014 approve here.");
101
- }
102
- if (result.noDevices) {
103
- switch (timeoutAction) {
104
- case "approve":
105
- return allow();
106
- case "deny":
107
- return deny("No device connected to approve on");
108
- default:
109
- return ask("No device connected \u2014 asking in terminal");
110
- }
111
- }
112
- const now = Date.now();
113
- const deadline = hookWaitDeadline(START_MS, timeoutSeconds, "claude", now);
114
- const clampCut = hookWaitClamped(START_MS, timeoutSeconds, "claude", now);
115
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline);
116
- if (answer.answered) {
117
- if (isDeferAnswer(answer.value)) return ask("Handling on your machine");
118
- return answer.value === "yes" ? allow() : deny(denyReasonFrom(answer.value));
119
- }
120
- if (clampCut) {
121
- savePendingQuestion(sessionId || DEFAULT_SESSION, result.correlationId);
122
- return ask("Approval window exceeds this hook budget \u2014 asking here.");
123
- }
124
- switch (timeoutAction) {
125
- case "approve":
126
- return allow();
127
- case "deny":
128
- return deny("No response within timeout");
129
- default:
130
- return ask("No push response, asking in terminal");
131
- }
132
- };
133
- var handleTerminalOnly = () => {
134
- return ask();
135
- };
136
- var handlePushFirst = async (apiKey, description, projectName, pushFirstSeconds, sessionId, machineId, toolName, toolTarget, decision) => {
137
- let result;
138
- try {
139
- result = await askUser(apiKey, {
140
- question: `Allow ${description}?`,
141
- type: "confirm",
142
- context: `Agent wants to run this in ${projectName}`,
143
- agentName: `Claude Code - ${projectName}`,
144
- sessionId,
145
- machineId,
146
- toolName,
147
- toolTarget,
148
- ...decision
149
- });
150
- } catch {
151
- return ask("Push notification failed, asking in terminal");
152
- }
153
- if (result.suppressed) {
154
- await cancelQuestion(apiKey, result.correlationId).catch(() => {
155
- });
156
- return ask("You are at the keyboard \u2014 approve here.");
157
- }
158
- if (result.noDevices) {
159
- return ask("No device connected \u2014 asking in terminal.");
160
- }
161
- const deadline = hookWaitDeadline(START_MS, pushFirstSeconds, "claude", Date.now());
162
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline, 1500);
163
- if (answer.answered) {
164
- if (isDeferAnswer(answer.value)) return ask("Handling on your machine");
165
- return answer.value === "yes" ? allow() : deny(denyReasonFrom(answer.value));
166
- }
167
- savePendingQuestion(sessionId || DEFAULT_SESSION, result.correlationId);
168
- return ask("Sent as push notification. You can also approve here.");
169
- };
170
- var handleNotifyOnly = async (apiKey, description, projectName, sessionId, machineId) => {
171
- try {
172
- await sendNotification(apiKey, {
173
- title: "Agent needs approval",
174
- body: description,
175
- agentName: `Claude Code - ${projectName}`,
176
- sessionId,
177
- machineId
178
- });
179
- } catch {
180
- }
181
- return ask();
182
- };
183
- var handlePreToolUse = async (input) => {
184
- try {
185
- const apiKey = getApiKey();
186
- const modeState = await fetchModeState(apiKey, input.session_id);
187
- const policy = await getPolicy(apiKey, modeState.policyVersion);
188
- if (modeState.kill) {
189
- return deny("Stopped by user \u2014 this agent was halted from Pushary");
190
- }
191
- const toolPolicy = resolvePolicy(policy, input.tool_name, modeState.mode, input.tool_input);
192
- if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") {
193
- return allow();
194
- }
195
- if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "deny") {
196
- return deny(`Denied by policy for ${toolPolicy.tool}`);
197
- }
198
- const description = describeToolCall(input.tool_name, input.tool_input, "hook");
199
- const projectName = basename(input.cwd ?? process.cwd());
200
- const sessionId = input.session_id;
201
- const machineId = getMachineId();
202
- const toolTarget = deriveToolTarget(input.tool_name, input.tool_input);
203
- const intent = readLastPrompt(sessionId ?? DEFAULT_SESSION) ?? (input.transcript_path ? readLastUserPrompt(input.transcript_path) : void 0);
204
- const decision = {
205
- intent,
206
- action: deriveAction(input.tool_name, input.tool_input),
207
- blocker: deriveBlocker(toolPolicy.mode),
208
- actionBody: deriveActionBody(input.tool_name, input.tool_input)
209
- };
210
- switch (toolPolicy.mode) {
211
- case "push_only":
212
- return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction, sessionId, machineId, input.tool_name, toolTarget, decision);
213
- case "terminal_only":
214
- return handleTerminalOnly();
215
- case "push_first":
216
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget, decision);
217
- case "notify_only":
218
- return handleNotifyOnly(apiKey, description, projectName, sessionId, machineId);
219
- default:
220
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget, decision);
221
- }
222
- } catch {
223
- return ask("Pushary unavailable, falling back to terminal approval");
224
- }
225
- };
226
-
227
- export {
228
- handlePreToolUse
229
- };
@@ -1,206 +0,0 @@
1
- // ../contracts/src/index.ts
2
- var APPROVAL_MODES = ["push_only", "terminal_only", "push_first", "notify_only"];
3
- var isApprovalMode = (value) => typeof value === "string" && APPROVAL_MODES.includes(value);
4
- var HOOK_BUDGETS = {
5
- claude: { budgetSeconds: 120, guardSeconds: 10 },
6
- codex: { budgetSeconds: 180, guardSeconds: 10 },
7
- gemini: { budgetSeconds: 180, guardSeconds: 10 },
8
- // The Cursor gate is a dependency-free .mjs that cannot import this module; it
9
- // mirrors these as MAX_BLOCK_MS (45s) inside its 60s failClosed budget.
10
- cursor: { budgetSeconds: 60, guardSeconds: 15 }
11
- };
12
- var hookMaxWaitSeconds = (agent) => Math.max(HOOK_BUDGETS[agent].budgetSeconds - HOOK_BUDGETS[agent].guardSeconds, 1);
13
- var hookWaitDeadline = (startMs, policyWaitSeconds, agent, nowMs) => {
14
- const maxWait = hookMaxWaitSeconds(agent);
15
- return Math.min(
16
- nowMs + Math.min(Math.max(policyWaitSeconds, 0), maxWait) * 1e3,
17
- startMs + maxWait * 1e3
18
- );
19
- };
20
- var hookWaitClamped = (startMs, policyWaitSeconds, agent, nowMs) => startMs + hookMaxWaitSeconds(agent) * 1e3 < nowMs + Math.max(policyWaitSeconds, 0) * 1e3;
21
- var MATCH_RANKS = ["none", "tool", "prefix", "exact"];
22
- var matchRankWeight = (rank) => MATCH_RANKS.indexOf(rank);
23
- var matchToolPattern = (pattern, toolName, arg) => {
24
- const open = pattern.indexOf("(");
25
- if (open === -1 || !pattern.endsWith(")")) {
26
- return pattern === toolName ? "tool" : "none";
27
- }
28
- if (pattern.slice(0, open) !== toolName || arg === void 0) return "none";
29
- const inner = pattern.slice(open + 1, -1);
30
- if (inner.endsWith(":*")) {
31
- return arg.startsWith(inner.slice(0, -2)) ? "prefix" : "none";
32
- }
33
- return arg === inner ? "exact" : "none";
34
- };
35
- var POLICY_ARG_KEYS = {
36
- Bash: "command",
37
- Edit: "file_path",
38
- Write: "file_path"
39
- };
40
- var extractPolicyArg = (toolName, toolInput) => {
41
- const key = POLICY_ARG_KEYS[toolName];
42
- if (!key) return void 0;
43
- const value = toolInput[key];
44
- return typeof value === "string" ? value : void 0;
45
- };
46
- var SAFE_SHELL_COMMANDS = /* @__PURE__ */ new Set([
47
- "ls",
48
- "pwd",
49
- "cd",
50
- "cat",
51
- "head",
52
- "tail",
53
- "wc",
54
- "echo",
55
- "printf",
56
- "which",
57
- "type",
58
- "whoami",
59
- "id",
60
- "uname",
61
- "arch",
62
- "printenv",
63
- "locale",
64
- "tty",
65
- "dirname",
66
- "basename",
67
- "realpath",
68
- "readlink",
69
- "stat",
70
- "cut",
71
- "nl",
72
- "tr",
73
- "comm",
74
- "diff",
75
- "cmp",
76
- "grep",
77
- "egrep",
78
- "fgrep",
79
- "jq",
80
- "cksum",
81
- "md5sum",
82
- "sha1sum",
83
- "sha256sum",
84
- "du",
85
- "df",
86
- "ps",
87
- "true"
88
- ]);
89
- var SAFE_GIT_SUBCOMMANDS = /* @__PURE__ */ new Set([
90
- "status",
91
- "log",
92
- "diff",
93
- "show",
94
- "rev-parse",
95
- "describe",
96
- "blame",
97
- "shortlog",
98
- "ls-files",
99
- "ls-tree",
100
- "cat-file",
101
- "whatchanged",
102
- "rev-list",
103
- "name-rev",
104
- "for-each-ref",
105
- "var",
106
- "count-objects"
107
- ]);
108
- var GIT_WRITE_FLAGS = (token) => token === "--output" || token.startsWith("--output=");
109
- var UNSAFE_SHELL_CHARS = /[;&|<>(){}`\\\n\r]/;
110
- var basenameOf = (token) => {
111
- const slash = Math.max(token.lastIndexOf("/"), token.lastIndexOf("\\"));
112
- return slash === -1 ? token : token.slice(slash + 1);
113
- };
114
- var tokenizeShellCommand = (command) => {
115
- const tokens = [];
116
- let current = "";
117
- let quote = null;
118
- let started = false;
119
- for (const ch of command) {
120
- if (quote) {
121
- if (ch === quote) quote = null;
122
- else current += ch;
123
- started = true;
124
- continue;
125
- }
126
- if (ch === '"' || ch === "'") {
127
- quote = ch;
128
- started = true;
129
- continue;
130
- }
131
- if (ch === " " || ch === " ") {
132
- if (started) {
133
- tokens.push(current);
134
- current = "";
135
- started = false;
136
- }
137
- continue;
138
- }
139
- current += ch;
140
- started = true;
141
- }
142
- if (quote) return null;
143
- if (started) tokens.push(current);
144
- return tokens;
145
- };
146
- var isSafeReadOnlyCommand = (command) => {
147
- const trimmed = command.trim();
148
- if (!trimmed || trimmed.length > 2e3) return false;
149
- if (UNSAFE_SHELL_CHARS.test(trimmed)) return false;
150
- const tokens = tokenizeShellCommand(trimmed);
151
- if (!tokens || tokens.length === 0) return false;
152
- const first = tokens[0];
153
- if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(first) || first.includes("$")) return false;
154
- const exe = basenameOf(first);
155
- if (exe === "git") {
156
- const sub = tokens[1];
157
- if (!sub || sub.startsWith("-")) return false;
158
- if (!SAFE_GIT_SUBCOMMANDS.has(sub)) return false;
159
- return !tokens.some(GIT_WRITE_FLAGS);
160
- }
161
- return SAFE_SHELL_COMMANDS.has(exe);
162
- };
163
- var API_KEY_PATTERN = /^pk_[a-f0-9]+\.[a-f0-9]+$/;
164
- var isValidApiKey = (value) => API_KEY_PATTERN.test(value);
165
- var ACTION_BODY_MAX = 4e3;
166
- var DECISION_LINE_MAX = 500;
167
- var SECRET_REDACTION_RULES = [
168
- { pattern: /-----BEGIN[A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END[A-Z0-9 ]*PRIVATE KEY-----/g, replacement: "[redacted key]" },
169
- { pattern: /\bsk-[A-Za-z0-9_-]{16,}\b/g, replacement: "[redacted]" },
170
- { pattern: /\b[spr]k_(?:live|test)_[A-Za-z0-9]{8,}\b/g, replacement: "[redacted]" },
171
- { pattern: /\bwhsec_[A-Za-z0-9]{16,}\b/g, replacement: "[redacted]" },
172
- { pattern: /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36,}\b/g, replacement: "[redacted]" },
173
- { pattern: /\bgithub_pat_[A-Za-z0-9_]{22,}\b/g, replacement: "[redacted]" },
174
- { pattern: /\bglpat-[A-Za-z0-9_-]{20,}\b/g, replacement: "[redacted]" },
175
- { pattern: /\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g, replacement: "[redacted]" },
176
- { pattern: /\bAIza[A-Za-z0-9_-]{35}\b/g, replacement: "[redacted]" },
177
- { pattern: /\bAKIA[0-9A-Z]{16}\b/g, replacement: "[redacted]" },
178
- { pattern: /\bnpm_[A-Za-z0-9]{36}\b/g, replacement: "[redacted]" },
179
- { pattern: /\bxai-[A-Za-z0-9]{16,}\b/g, replacement: "[redacted]" },
180
- { pattern: /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, replacement: "[redacted]" },
181
- { pattern: /\bbearer\s+[A-Za-z0-9._~+/=-]+/gi, replacement: "bearer [redacted]" },
182
- { pattern: /\bauthorization:\s*\S+/gi, replacement: "authorization: [redacted]" },
183
- {
184
- pattern: /((?:secret|token|password|passwd|api[_-]?key|access[_-]?key|client[_-]?secret|private[_-]?key)\s*[=:]\s*)("[^"]*"|'[^']*'|\S+)/gi,
185
- replacement: "$1[redacted]"
186
- }
187
- ];
188
- var HIGH_ENTROPY_RULE = { pattern: /[A-Za-z0-9+/]{40,}={0,2}/g, replacement: "[redacted]" };
189
- var redactSecrets = (text) => SECRET_REDACTION_RULES.reduce((acc, rule) => acc.replace(rule.pattern, rule.replacement), text);
190
- var redactSecretsDeep = (text) => redactSecrets(text).replace(HIGH_ENTROPY_RULE.pattern, HIGH_ENTROPY_RULE.replacement);
191
-
192
- export {
193
- isApprovalMode,
194
- HOOK_BUDGETS,
195
- hookWaitDeadline,
196
- hookWaitClamped,
197
- matchRankWeight,
198
- matchToolPattern,
199
- extractPolicyArg,
200
- isSafeReadOnlyCommand,
201
- isValidApiKey,
202
- ACTION_BODY_MAX,
203
- DECISION_LINE_MAX,
204
- redactSecrets,
205
- redactSecretsDeep
206
- };