@pushary/agent-hooks 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/data/cursor-plugin/scripts/pushary-gate.mjs +21 -1
  2. package/dist/bin/pushary-clean.js +3 -2
  3. package/dist/bin/pushary-codex-hook.js +37 -12
  4. package/dist/bin/pushary-codex.js +2 -1
  5. package/dist/bin/pushary-doctor.js +52 -10
  6. package/dist/bin/pushary-gemini-hook.js +36 -11
  7. package/dist/bin/pushary-hook.js +3 -2
  8. package/dist/bin/pushary-mode.js +5 -3
  9. package/dist/bin/pushary-post-hook.js +8 -2
  10. package/dist/bin/pushary-prompt-hook.js +8 -2
  11. package/dist/bin/pushary-setup.js +11 -21
  12. package/dist/bin/pushary-stop-hook.js +2 -1
  13. package/dist/bin/pushary-wait.d.ts +1 -0
  14. package/dist/bin/pushary-wait.js +86 -0
  15. package/dist/bin/pushary.js +4 -0
  16. package/dist/{chunk-WPVL6VIT.js → chunk-FDR5WYT7.js} +50 -2
  17. package/dist/chunk-IIENZE2J.js +15 -0
  18. package/dist/{chunk-5MA3CPZB.js → chunk-MVNOP5IZ.js} +5 -1
  19. package/dist/{chunk-GYPPVD3P.js → chunk-TUILTFLS.js} +74 -184
  20. package/dist/{chunk-O2QL6U6G.js → chunk-VHD3GMZ3.js} +40 -3
  21. package/dist/{chunk-JPRRYC5X.js → chunk-WXWHRXDK.js} +32 -3
  22. package/dist/src/index.d.ts +7 -1
  23. package/dist/src/index.js +3 -2
  24. package/package.json +4 -3
  25. package/dist/chunk-22CV7V7A.js +0 -38
  26. package/dist/chunk-2BE2IPMO.js +0 -315
  27. package/dist/chunk-2CRLBMOX.js +0 -244
  28. package/dist/chunk-2HMNOZPY.js +0 -109
  29. package/dist/chunk-2I6DLXJN.js +0 -219
  30. package/dist/chunk-2Q6XPZ4Q.js +0 -395
  31. package/dist/chunk-3LC4YUMA.js +0 -194
  32. package/dist/chunk-3MIR7ODJ.js +0 -112
  33. package/dist/chunk-3QZESA66.js +0 -222
  34. package/dist/chunk-4Z4MB37G.js +0 -96
  35. package/dist/chunk-5GFUI5N6.js +0 -132
  36. package/dist/chunk-5JEDLXEC.js +0 -99
  37. package/dist/chunk-5LTQNC7R.js +0 -824
  38. package/dist/chunk-5QHQVXWN.js +0 -174
  39. package/dist/chunk-6A3WCJO2.js +0 -416
  40. package/dist/chunk-6QWFMVCD.js +0 -328
  41. package/dist/chunk-6SRXMZAN.js +0 -99
  42. package/dist/chunk-7PTU7TGE.js +0 -96
  43. package/dist/chunk-AB4KX4XT.js +0 -109
  44. package/dist/chunk-AC4UYAGX.js +0 -136
  45. package/dist/chunk-ACE77TKQ.js +0 -328
  46. package/dist/chunk-BHAMEPOP.js +0 -323
  47. package/dist/chunk-BYNYYZWW.js +0 -412
  48. package/dist/chunk-C5TFTNHG.js +0 -244
  49. package/dist/chunk-CH53PBQN.js +0 -265
  50. package/dist/chunk-DF3BM6BF.js +0 -195
  51. package/dist/chunk-DKZVKEOW.js +0 -175
  52. package/dist/chunk-EMPL27ZV.js +0 -96
  53. package/dist/chunk-EQJXMEIR.js +0 -175
  54. package/dist/chunk-FGZZRCOG.js +0 -194
  55. package/dist/chunk-FXYTRZHC.js +0 -177
  56. package/dist/chunk-GTJGZBTQ.js +0 -328
  57. package/dist/chunk-HJMFYDWY.js +0 -222
  58. package/dist/chunk-HRQEECB6.js +0 -315
  59. package/dist/chunk-HWEMAAOY.js +0 -370
  60. package/dist/chunk-IBWCHA5M.js +0 -10
  61. package/dist/chunk-KTM4ZQ3W.js +0 -96
  62. package/dist/chunk-KTP2EPVB.js +0 -27
  63. package/dist/chunk-KYARP7KP.js +0 -97
  64. package/dist/chunk-M2N5DYWN.js +0 -247
  65. package/dist/chunk-M4GDBGXF.js +0 -824
  66. package/dist/chunk-M5F2L4KF.js +0 -177
  67. package/dist/chunk-M6S3M6E3.js +0 -244
  68. package/dist/chunk-N7VXDBQU.js +0 -6
  69. package/dist/chunk-O6A5RHWY.js +0 -122
  70. package/dist/chunk-ODUXELPM.js +0 -219
  71. package/dist/chunk-OF5WIOYS.js +0 -129
  72. package/dist/chunk-OP4QAN23.js +0 -99
  73. package/dist/chunk-P4JH2Q7Z.js +0 -102
  74. package/dist/chunk-PMD5JSV3.js +0 -242
  75. package/dist/chunk-PSSHNBEL.js +0 -177
  76. package/dist/chunk-QEPRH7JB.js +0 -315
  77. package/dist/chunk-QRXWPZKN.js +0 -308
  78. package/dist/chunk-QY4L6XHN.js +0 -384
  79. package/dist/chunk-RNWPCELY.js +0 -176
  80. package/dist/chunk-RSHN2AQ7.js +0 -29
  81. package/dist/chunk-RZLVE57X.js +0 -38
  82. package/dist/chunk-SDCIKREA.js +0 -241
  83. package/dist/chunk-SDREQWNI.js +0 -175
  84. package/dist/chunk-SH26ZOHU.js +0 -159
  85. package/dist/chunk-TRLBBLSS.js +0 -176
  86. package/dist/chunk-U6OXZPYC.js +0 -384
  87. package/dist/chunk-UIBTFZUD.js +0 -314
  88. package/dist/chunk-USUCPCUC.js +0 -156
  89. package/dist/chunk-V4GLWPD7.js +0 -174
  90. package/dist/chunk-VC6U3QGF.js +0 -142
  91. package/dist/chunk-VIST7ACL.js +0 -88
  92. package/dist/chunk-VUNL35KE.js +0 -16
  93. package/dist/chunk-VWBNI4SC.js +0 -174
  94. package/dist/chunk-W5KRWUNE.js +0 -262
  95. package/dist/chunk-WCGKLHCL.js +0 -154
  96. package/dist/chunk-WNXGIEX7.js +0 -219
  97. package/dist/chunk-XPVSZIA3.js +0 -315
  98. package/dist/chunk-Y633ZIJF.js +0 -384
  99. package/dist/chunk-YCL4GUFR.js +0 -222
  100. package/dist/chunk-YTMKB44I.js +0 -220
  101. package/dist/chunk-ZWBS3T7Q.js +0 -244
  102. package/dist/pushary-mode-T7XOPI6Z.js +0 -83
@@ -1,96 +0,0 @@
1
- import {
2
- callMcpTool
3
- } from "./chunk-3MIR7ODJ.js";
4
-
5
- // src/validate.ts
6
- var isPolicyConfig = (data) => {
7
- if (!data || typeof data !== "object") return false;
8
- const d = data;
9
- return Array.isArray(d.policies) && typeof d.defaultTimeoutSeconds === "number" && typeof d.defaultTimeoutAction === "string";
10
- };
11
- var isAskUserResponse = (data) => {
12
- if (!data || typeof data !== "object") return false;
13
- const d = data;
14
- return typeof d.correlationId === "string" && typeof d.status === "string";
15
- };
16
- var isWaitForAnswerResponse = (data) => {
17
- if (!data || typeof data !== "object") return false;
18
- const d = data;
19
- return typeof d.answered === "boolean";
20
- };
21
-
22
- // src/api.ts
23
- var askUser = async (apiKey, params) => {
24
- const result = await callMcpTool(apiKey, "ask_user", { ...params });
25
- if (!isAskUserResponse(result)) throw new Error("Invalid ask_user response");
26
- return result;
27
- };
28
- var waitForAnswer = async (apiKey, correlationId, timeoutMs = 3e4) => {
29
- const result = await callMcpTool(apiKey, "wait_for_answer", {
30
- correlationId,
31
- timeoutMs
32
- });
33
- if (!isWaitForAnswerResponse(result)) throw new Error("Invalid wait_for_answer response");
34
- return result;
35
- };
36
- var cancelQuestion = async (apiKey, correlationId) => {
37
- await callMcpTool(apiKey, "cancel_question", { correlationId });
38
- };
39
- var sendNotification = async (apiKey, params) => {
40
- await callMcpTool(apiKey, "send_notification", { ...params });
41
- };
42
-
43
- // src/describe.ts
44
- var hookPrefixes = {
45
- Bash: (input) => `bash: ${input.command ?? "(no command)"}`,
46
- Write: (input) => `write file: ${input.file_path ?? "(unknown path)"}`,
47
- Edit: (input) => `edit file: ${input.file_path ?? "(unknown path)"}`,
48
- Read: (input) => `read file: ${input.file_path ?? "(unknown path)"}`
49
- };
50
- var eventPrefixes = {
51
- Bash: (input) => `ran: ${String(input.command ?? "").slice(0, 120)}`,
52
- Write: (input) => `wrote: ${input.file_path ?? "unknown"}`,
53
- Edit: (input) => `edited: ${input.file_path ?? "unknown"}`,
54
- Read: (input) => `read: ${input.file_path ?? "unknown"}`
55
- };
56
- var describeToolCall = (toolName, toolInput, format = "hook") => {
57
- const prefixes = format === "hook" ? hookPrefixes : eventPrefixes;
58
- const builder = prefixes[toolName];
59
- if (builder) return builder(toolInput);
60
- return format === "hook" ? `${toolName}: ${JSON.stringify(toolInput).slice(0, 200)}` : `${toolName}: done`;
61
- };
62
-
63
- // src/pending.ts
64
- import { join } from "path";
65
- import { tmpdir } from "os";
66
- import { existsSync, mkdirSync, writeFileSync, readdirSync, unlinkSync } from "fs";
67
- var PENDING_DIR = join(tmpdir(), "pushary-pending");
68
- var savePendingQuestion = (correlationId) => {
69
- if (!existsSync(PENDING_DIR)) mkdirSync(PENDING_DIR, { recursive: true });
70
- writeFileSync(join(PENDING_DIR, correlationId), "", "utf-8");
71
- };
72
- var listPendingQuestions = () => {
73
- try {
74
- return readdirSync(PENDING_DIR);
75
- } catch {
76
- return [];
77
- }
78
- };
79
- var removePendingQuestion = (correlationId) => {
80
- try {
81
- unlinkSync(join(PENDING_DIR, correlationId));
82
- } catch {
83
- }
84
- };
85
-
86
- export {
87
- isPolicyConfig,
88
- askUser,
89
- waitForAnswer,
90
- cancelQuestion,
91
- sendNotification,
92
- describeToolCall,
93
- savePendingQuestion,
94
- listPendingQuestions,
95
- removePendingQuestion
96
- };
@@ -1,175 +0,0 @@
1
- import {
2
- DEFAULT_SESSION,
3
- askUser,
4
- deriveToolTarget,
5
- describeToolCall,
6
- fetchModeState,
7
- getMachineId,
8
- getPolicy,
9
- resolvePolicy,
10
- savePendingQuestion,
11
- sendNotification,
12
- waitForAnswer
13
- } from "./chunk-HRQEECB6.js";
14
- import {
15
- getApiKey
16
- } from "./chunk-NKXSILEW.js";
17
-
18
- // src/hook.ts
19
- import { basename } from "path";
20
- var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
21
- var denyReasonFrom = (value) => value && value !== "no" && value !== "yes" ? `Denied from your phone: ${value}` : "Denied via push notification";
22
- var allow = () => ({
23
- hookSpecificOutput: {
24
- hookEventName: "PreToolUse",
25
- permissionDecision: "allow"
26
- }
27
- });
28
- var deny = (reason) => ({
29
- hookSpecificOutput: {
30
- hookEventName: "PreToolUse",
31
- permissionDecision: "deny",
32
- permissionDecisionReason: reason
33
- }
34
- });
35
- var ask = (reason) => ({
36
- hookSpecificOutput: {
37
- hookEventName: "PreToolUse",
38
- permissionDecision: "ask",
39
- ...reason ? { permissionDecisionReason: reason } : {}
40
- }
41
- });
42
- var pollForAnswer = async (apiKey, correlationId, deadlineMs, pollInterval = 2e3) => {
43
- while (Date.now() < deadlineMs) {
44
- const remaining = Math.min(Math.max(deadlineMs - Date.now(), 1e3), 3e4);
45
- let answer;
46
- try {
47
- answer = await waitForAnswer(apiKey, correlationId, remaining);
48
- } catch {
49
- if (Date.now() + pollInterval >= deadlineMs) break;
50
- await sleep(pollInterval);
51
- continue;
52
- }
53
- if (answer.answered) return answer;
54
- if (Date.now() + pollInterval >= deadlineMs) break;
55
- await sleep(pollInterval);
56
- }
57
- return { answered: false };
58
- };
59
- var handlePushOnly = async (apiKey, description, projectName, timeoutSeconds, timeoutAction, sessionId, machineId, toolName, toolTarget) => {
60
- let result;
61
- try {
62
- result = await askUser(apiKey, {
63
- question: `Allow ${description}?`,
64
- type: "confirm",
65
- context: `Agent wants to run this in ${projectName}`,
66
- agentName: `Claude Code - ${projectName}`,
67
- sessionId,
68
- machineId,
69
- toolName,
70
- toolTarget
71
- });
72
- } catch {
73
- switch (timeoutAction) {
74
- case "approve":
75
- return allow();
76
- case "deny":
77
- return deny("Push notification failed, denying per policy");
78
- default:
79
- return ask("Push notification failed, asking in terminal");
80
- }
81
- }
82
- const deadline = Date.now() + timeoutSeconds * 1e3;
83
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline);
84
- if (answer.answered) {
85
- return answer.value === "yes" ? allow() : deny(denyReasonFrom(answer.value));
86
- }
87
- switch (timeoutAction) {
88
- case "approve":
89
- return allow();
90
- case "deny":
91
- return deny("No response within timeout");
92
- default:
93
- return ask("No push response, asking in terminal");
94
- }
95
- };
96
- var handleTerminalOnly = () => {
97
- return ask();
98
- };
99
- var handlePushFirst = async (apiKey, description, projectName, pushFirstSeconds, sessionId, machineId, toolName, toolTarget) => {
100
- let result;
101
- try {
102
- result = await askUser(apiKey, {
103
- question: `Allow ${description}?`,
104
- type: "confirm",
105
- context: `Agent wants to run this in ${projectName}`,
106
- agentName: `Claude Code - ${projectName}`,
107
- sessionId,
108
- machineId,
109
- toolName,
110
- toolTarget
111
- });
112
- } catch {
113
- return ask("Push notification failed, asking in terminal");
114
- }
115
- const deadline = Date.now() + pushFirstSeconds * 1e3;
116
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline, 1500);
117
- if (answer.answered) {
118
- return answer.value === "yes" ? allow() : deny(denyReasonFrom(answer.value));
119
- }
120
- savePendingQuestion(sessionId || DEFAULT_SESSION, result.correlationId);
121
- return ask("Sent as push notification. You can also approve here.");
122
- };
123
- var handleNotifyOnly = async (apiKey, description, projectName, sessionId, machineId) => {
124
- try {
125
- await sendNotification(apiKey, {
126
- title: "Agent needs approval",
127
- body: description,
128
- agentName: `Claude Code - ${projectName}`,
129
- sessionId,
130
- machineId
131
- });
132
- } catch {
133
- }
134
- return ask();
135
- };
136
- var handlePreToolUse = async (input) => {
137
- try {
138
- const apiKey = getApiKey();
139
- const modeState = await fetchModeState(apiKey, input.session_id);
140
- const policy = await getPolicy(apiKey, modeState.policyVersion);
141
- if (modeState.kill) {
142
- return deny("Stopped by user \u2014 this agent was halted from Pushary");
143
- }
144
- const toolPolicy = resolvePolicy(policy, input.tool_name, modeState.mode, input.tool_input);
145
- if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") {
146
- return allow();
147
- }
148
- if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "deny") {
149
- return deny(`Denied by policy for ${toolPolicy.tool}`);
150
- }
151
- const description = describeToolCall(input.tool_name, input.tool_input, "hook");
152
- const projectName = basename(input.cwd ?? process.cwd());
153
- const sessionId = input.session_id;
154
- const machineId = getMachineId();
155
- const toolTarget = deriveToolTarget(input.tool_name, input.tool_input);
156
- switch (toolPolicy.mode) {
157
- case "push_only":
158
- return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction, sessionId, machineId, input.tool_name, toolTarget);
159
- case "terminal_only":
160
- return handleTerminalOnly();
161
- case "push_first":
162
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget);
163
- case "notify_only":
164
- return handleNotifyOnly(apiKey, description, projectName, sessionId, machineId);
165
- default:
166
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget);
167
- }
168
- } catch {
169
- return ask("Pushary unavailable, falling back to terminal approval");
170
- }
171
- };
172
-
173
- export {
174
- handlePreToolUse
175
- };
@@ -1,194 +0,0 @@
1
- import {
2
- denyReasonFrom,
3
- isDeferAnswer
4
- } from "./chunk-KQYIHZ5E.js";
5
- import {
6
- DEFAULT_SESSION,
7
- askUser,
8
- deriveAction,
9
- deriveActionBody,
10
- deriveBlocker,
11
- deriveToolTarget,
12
- describeToolCall,
13
- fetchModeState,
14
- getMachineId,
15
- getPolicy,
16
- readLastPrompt,
17
- readLastUserPrompt,
18
- resolvePolicy,
19
- savePendingQuestion,
20
- sendNotification,
21
- waitForAnswer
22
- } from "./chunk-M4GDBGXF.js";
23
- import {
24
- getApiKey
25
- } from "./chunk-NKXSILEW.js";
26
-
27
- // src/hook.ts
28
- import { basename } from "path";
29
- var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
30
- var allow = () => ({
31
- hookSpecificOutput: {
32
- hookEventName: "PreToolUse",
33
- permissionDecision: "allow"
34
- }
35
- });
36
- var deny = (reason) => ({
37
- hookSpecificOutput: {
38
- hookEventName: "PreToolUse",
39
- permissionDecision: "deny",
40
- permissionDecisionReason: reason
41
- }
42
- });
43
- var ask = (reason) => ({
44
- hookSpecificOutput: {
45
- hookEventName: "PreToolUse",
46
- permissionDecision: "ask",
47
- ...reason ? { permissionDecisionReason: reason } : {}
48
- }
49
- });
50
- var pollForAnswer = async (apiKey, correlationId, deadlineMs, pollInterval = 2e3) => {
51
- while (Date.now() < deadlineMs) {
52
- const remaining = Math.min(Math.max(deadlineMs - Date.now(), 1e3), 3e4);
53
- let answer;
54
- try {
55
- answer = await waitForAnswer(apiKey, correlationId, remaining);
56
- } catch {
57
- if (Date.now() + pollInterval >= deadlineMs) break;
58
- await sleep(pollInterval);
59
- continue;
60
- }
61
- if (answer.answered) return answer;
62
- if (Date.now() + pollInterval >= deadlineMs) break;
63
- await sleep(pollInterval);
64
- }
65
- return { answered: false };
66
- };
67
- var handlePushOnly = async (apiKey, description, projectName, timeoutSeconds, timeoutAction, sessionId, machineId, toolName, toolTarget, decision) => {
68
- let result;
69
- try {
70
- result = await askUser(apiKey, {
71
- question: `Allow ${description}?`,
72
- type: "confirm",
73
- context: `Agent wants to run this in ${projectName}`,
74
- agentName: `Claude Code - ${projectName}`,
75
- sessionId,
76
- machineId,
77
- toolName,
78
- toolTarget,
79
- ...decision
80
- });
81
- } catch {
82
- switch (timeoutAction) {
83
- case "approve":
84
- return allow();
85
- case "deny":
86
- return deny("Push notification failed, denying per policy");
87
- default:
88
- return ask("Push notification failed, asking in terminal");
89
- }
90
- }
91
- const deadline = Date.now() + timeoutSeconds * 1e3;
92
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline);
93
- if (answer.answered) {
94
- if (isDeferAnswer(answer.value)) return ask("Handling on your machine");
95
- return answer.value === "yes" ? allow() : deny(denyReasonFrom(answer.value));
96
- }
97
- switch (timeoutAction) {
98
- case "approve":
99
- return allow();
100
- case "deny":
101
- return deny("No response within timeout");
102
- default:
103
- return ask("No push response, asking in terminal");
104
- }
105
- };
106
- var handleTerminalOnly = () => {
107
- return ask();
108
- };
109
- var handlePushFirst = async (apiKey, description, projectName, pushFirstSeconds, sessionId, machineId, toolName, toolTarget, decision) => {
110
- let result;
111
- try {
112
- result = await askUser(apiKey, {
113
- question: `Allow ${description}?`,
114
- type: "confirm",
115
- context: `Agent wants to run this in ${projectName}`,
116
- agentName: `Claude Code - ${projectName}`,
117
- sessionId,
118
- machineId,
119
- toolName,
120
- toolTarget,
121
- ...decision
122
- });
123
- } catch {
124
- return ask("Push notification failed, asking in terminal");
125
- }
126
- const deadline = Date.now() + pushFirstSeconds * 1e3;
127
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline, 1500);
128
- if (answer.answered) {
129
- if (isDeferAnswer(answer.value)) return ask("Handling on your machine");
130
- return answer.value === "yes" ? allow() : deny(denyReasonFrom(answer.value));
131
- }
132
- savePendingQuestion(sessionId || DEFAULT_SESSION, result.correlationId);
133
- return ask("Sent as push notification. You can also approve here.");
134
- };
135
- var handleNotifyOnly = async (apiKey, description, projectName, sessionId, machineId) => {
136
- try {
137
- await sendNotification(apiKey, {
138
- title: "Agent needs approval",
139
- body: description,
140
- agentName: `Claude Code - ${projectName}`,
141
- sessionId,
142
- machineId
143
- });
144
- } catch {
145
- }
146
- return ask();
147
- };
148
- var handlePreToolUse = async (input) => {
149
- try {
150
- const apiKey = getApiKey();
151
- const modeState = await fetchModeState(apiKey, input.session_id);
152
- const policy = await getPolicy(apiKey, modeState.policyVersion);
153
- if (modeState.kill) {
154
- return deny("Stopped by user \u2014 this agent was halted from Pushary");
155
- }
156
- const toolPolicy = resolvePolicy(policy, input.tool_name, modeState.mode, input.tool_input);
157
- if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") {
158
- return allow();
159
- }
160
- if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "deny") {
161
- return deny(`Denied by policy for ${toolPolicy.tool}`);
162
- }
163
- const description = describeToolCall(input.tool_name, input.tool_input, "hook");
164
- const projectName = basename(input.cwd ?? process.cwd());
165
- const sessionId = input.session_id;
166
- const machineId = getMachineId();
167
- const toolTarget = deriveToolTarget(input.tool_name, input.tool_input);
168
- const intent = readLastPrompt(sessionId ?? DEFAULT_SESSION) ?? (input.transcript_path ? readLastUserPrompt(input.transcript_path) : void 0);
169
- const decision = {
170
- intent,
171
- action: deriveAction(input.tool_name, input.tool_input),
172
- blocker: deriveBlocker(toolPolicy.mode),
173
- actionBody: deriveActionBody(input.tool_name, input.tool_input)
174
- };
175
- switch (toolPolicy.mode) {
176
- case "push_only":
177
- return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction, sessionId, machineId, input.tool_name, toolTarget, decision);
178
- case "terminal_only":
179
- return handleTerminalOnly();
180
- case "push_first":
181
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget, decision);
182
- case "notify_only":
183
- return handleNotifyOnly(apiKey, description, projectName, sessionId, machineId);
184
- default:
185
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget, decision);
186
- }
187
- } catch {
188
- return ask("Pushary unavailable, falling back to terminal approval");
189
- }
190
- };
191
-
192
- export {
193
- handlePreToolUse
194
- };
@@ -1,177 +0,0 @@
1
- import {
2
- denyReasonFrom
3
- } from "./chunk-N7VXDBQU.js";
4
- import {
5
- DEFAULT_SESSION,
6
- askUser,
7
- deriveToolTarget,
8
- describeToolCall,
9
- fetchModeState,
10
- getMachineId,
11
- getPolicy,
12
- resolvePolicy,
13
- savePendingQuestion,
14
- sendNotification,
15
- waitForAnswer
16
- } from "./chunk-ACE77TKQ.js";
17
- import {
18
- getApiKey
19
- } from "./chunk-NKXSILEW.js";
20
-
21
- // src/hook.ts
22
- import { basename } from "path";
23
- var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
24
- var allow = () => ({
25
- hookSpecificOutput: {
26
- hookEventName: "PreToolUse",
27
- permissionDecision: "allow"
28
- }
29
- });
30
- var deny = (reason) => ({
31
- hookSpecificOutput: {
32
- hookEventName: "PreToolUse",
33
- permissionDecision: "deny",
34
- permissionDecisionReason: reason
35
- }
36
- });
37
- var ask = (reason) => ({
38
- hookSpecificOutput: {
39
- hookEventName: "PreToolUse",
40
- permissionDecision: "ask",
41
- ...reason ? { permissionDecisionReason: reason } : {}
42
- }
43
- });
44
- var pollForAnswer = async (apiKey, correlationId, deadlineMs, pollInterval = 2e3) => {
45
- while (Date.now() < deadlineMs) {
46
- const remaining = Math.min(Math.max(deadlineMs - Date.now(), 1e3), 3e4);
47
- let answer;
48
- try {
49
- answer = await waitForAnswer(apiKey, correlationId, remaining);
50
- } catch {
51
- if (Date.now() + pollInterval >= deadlineMs) break;
52
- await sleep(pollInterval);
53
- continue;
54
- }
55
- if (answer.answered) return answer;
56
- if (Date.now() + pollInterval >= deadlineMs) break;
57
- await sleep(pollInterval);
58
- }
59
- return { answered: false };
60
- };
61
- var handlePushOnly = async (apiKey, description, projectName, timeoutSeconds, timeoutAction, sessionId, machineId, toolName, toolTarget) => {
62
- let result;
63
- try {
64
- result = await askUser(apiKey, {
65
- question: `Allow ${description}?`,
66
- type: "confirm",
67
- context: `Agent wants to run this in ${projectName}`,
68
- agentName: `Claude Code - ${projectName}`,
69
- sessionId,
70
- machineId,
71
- toolName,
72
- toolTarget
73
- });
74
- } catch {
75
- switch (timeoutAction) {
76
- case "approve":
77
- return allow();
78
- case "deny":
79
- return deny("Push notification failed, denying per policy");
80
- default:
81
- return ask("Push notification failed, asking in terminal");
82
- }
83
- }
84
- const deadline = Date.now() + timeoutSeconds * 1e3;
85
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline);
86
- if (answer.answered) {
87
- return answer.value === "yes" ? allow() : deny(denyReasonFrom(answer.value));
88
- }
89
- switch (timeoutAction) {
90
- case "approve":
91
- return allow();
92
- case "deny":
93
- return deny("No response within timeout");
94
- default:
95
- return ask("No push response, asking in terminal");
96
- }
97
- };
98
- var handleTerminalOnly = () => {
99
- return ask();
100
- };
101
- var handlePushFirst = async (apiKey, description, projectName, pushFirstSeconds, sessionId, machineId, toolName, toolTarget) => {
102
- let result;
103
- try {
104
- result = await askUser(apiKey, {
105
- question: `Allow ${description}?`,
106
- type: "confirm",
107
- context: `Agent wants to run this in ${projectName}`,
108
- agentName: `Claude Code - ${projectName}`,
109
- sessionId,
110
- machineId,
111
- toolName,
112
- toolTarget
113
- });
114
- } catch {
115
- return ask("Push notification failed, asking in terminal");
116
- }
117
- const deadline = Date.now() + pushFirstSeconds * 1e3;
118
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline, 1500);
119
- if (answer.answered) {
120
- return answer.value === "yes" ? allow() : deny(denyReasonFrom(answer.value));
121
- }
122
- savePendingQuestion(sessionId || DEFAULT_SESSION, result.correlationId);
123
- return ask("Sent as push notification. You can also approve here.");
124
- };
125
- var handleNotifyOnly = async (apiKey, description, projectName, sessionId, machineId) => {
126
- try {
127
- await sendNotification(apiKey, {
128
- title: "Agent needs approval",
129
- body: description,
130
- agentName: `Claude Code - ${projectName}`,
131
- sessionId,
132
- machineId
133
- });
134
- } catch {
135
- }
136
- return ask();
137
- };
138
- var handlePreToolUse = async (input) => {
139
- try {
140
- const apiKey = getApiKey();
141
- const modeState = await fetchModeState(apiKey, input.session_id);
142
- const policy = await getPolicy(apiKey, modeState.policyVersion);
143
- if (modeState.kill) {
144
- return deny("Stopped by user \u2014 this agent was halted from Pushary");
145
- }
146
- const toolPolicy = resolvePolicy(policy, input.tool_name, modeState.mode, input.tool_input);
147
- if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") {
148
- return allow();
149
- }
150
- if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "deny") {
151
- return deny(`Denied by policy for ${toolPolicy.tool}`);
152
- }
153
- const description = describeToolCall(input.tool_name, input.tool_input, "hook");
154
- const projectName = basename(input.cwd ?? process.cwd());
155
- const sessionId = input.session_id;
156
- const machineId = getMachineId();
157
- const toolTarget = deriveToolTarget(input.tool_name, input.tool_input);
158
- switch (toolPolicy.mode) {
159
- case "push_only":
160
- return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction, sessionId, machineId, input.tool_name, toolTarget);
161
- case "terminal_only":
162
- return handleTerminalOnly();
163
- case "push_first":
164
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget);
165
- case "notify_only":
166
- return handleNotifyOnly(apiKey, description, projectName, sessionId, machineId);
167
- default:
168
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget);
169
- }
170
- } catch {
171
- return ask("Pushary unavailable, falling back to terminal approval");
172
- }
173
- };
174
-
175
- export {
176
- handlePreToolUse
177
- };