@pushary/agent-hooks 0.28.1 → 0.28.2

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,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-2BE2IPMO.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,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,145 +0,0 @@
1
- import {
2
- HOOK_BUDGETS
3
- } from "./chunk-C4BMEVK7.js";
4
-
5
- // src/claude-config.ts
6
- import { join } from "path";
7
- var PUSHARY_MCP_URL = "https://pushary.com/api/mcp/mcp";
8
- var PUSHARY_PERMISSION_RULE = "mcp__pushary__*";
9
- var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
10
- var ensureRecord = (target, key) => {
11
- const existing = asRecord(target[key]);
12
- if (existing) return existing;
13
- const created = {};
14
- target[key] = created;
15
- return created;
16
- };
17
- var isPusharyPermission = (rule) => typeof rule === "string" && (rule.includes("pushary") || rule.includes("MCP(pushary"));
18
- var isPusharyHook = (entry) => {
19
- const hooks = asRecord(entry)?.hooks;
20
- if (!Array.isArray(hooks)) return false;
21
- return hooks.some((hook) => {
22
- const command = String(asRecord(hook)?.command ?? "");
23
- return command.includes("pushary-hook") || command.includes("pushary-post-hook") || command.includes("pushary-stop-hook") || command.includes("pushary-prompt-hook");
24
- });
25
- };
26
- var addClaudeMcpServer = (config, apiKey) => {
27
- const mcpServers = ensureRecord(config, "mcpServers");
28
- mcpServers.pushary = {
29
- type: "http",
30
- url: PUSHARY_MCP_URL,
31
- headers: { Authorization: `Bearer ${apiKey}` }
32
- };
33
- };
34
- var removeClaudeMcpServers = (config) => {
35
- let changed = false;
36
- const removeFrom = (target) => {
37
- const mcpServers = asRecord(target.mcpServers);
38
- if (!mcpServers?.pushary) return;
39
- delete mcpServers.pushary;
40
- if (Object.keys(mcpServers).length === 0) delete target.mcpServers;
41
- changed = true;
42
- };
43
- removeFrom(config);
44
- const projects = asRecord(config.projects);
45
- if (projects) {
46
- for (const project of Object.values(projects)) {
47
- const projectConfig = asRecord(project);
48
- if (projectConfig) removeFrom(projectConfig);
49
- }
50
- }
51
- return changed;
52
- };
53
- var addPusharyToolPermissions = (settings) => {
54
- const permissions = ensureRecord(settings, "permissions");
55
- const allow = Array.isArray(permissions.allow) ? permissions.allow : [];
56
- const filtered = allow.filter((rule) => !isPusharyPermission(rule));
57
- if (!filtered.includes(PUSHARY_PERMISSION_RULE)) {
58
- filtered.push(PUSHARY_PERMISSION_RULE);
59
- }
60
- permissions.allow = filtered;
61
- };
62
- var addPusharyHooks = (settings, binDir) => {
63
- const resolve = (name) => binDir ? join(binDir, name) : name;
64
- const hooks = ensureRecord(settings, "hooks");
65
- const preToolUse = (Array.isArray(hooks.PreToolUse) ? hooks.PreToolUse : []).filter((entry) => !isPusharyHook(entry));
66
- preToolUse.push({
67
- matcher: "Bash|Write|Edit",
68
- hooks: [{
69
- type: "command",
70
- command: resolve("pushary-hook"),
71
- timeout: HOOK_BUDGETS.claude.budgetSeconds
72
- }]
73
- });
74
- hooks.PreToolUse = preToolUse;
75
- const postToolUse = (Array.isArray(hooks.PostToolUse) ? hooks.PostToolUse : []).filter((entry) => !isPusharyHook(entry));
76
- postToolUse.push({
77
- matcher: "Bash|Write|Edit",
78
- hooks: [{
79
- type: "command",
80
- command: resolve("pushary-post-hook"),
81
- timeout: 10
82
- }]
83
- });
84
- hooks.PostToolUse = postToolUse;
85
- const stop = (Array.isArray(hooks.Stop) ? hooks.Stop : []).filter((entry) => !isPusharyHook(entry));
86
- stop.push({
87
- hooks: [{
88
- type: "command",
89
- command: resolve("pushary-stop-hook"),
90
- timeout: 10
91
- }]
92
- });
93
- hooks.Stop = stop;
94
- const userPromptSubmit = (Array.isArray(hooks.UserPromptSubmit) ? hooks.UserPromptSubmit : []).filter((entry) => !isPusharyHook(entry));
95
- userPromptSubmit.push({
96
- hooks: [{
97
- type: "command",
98
- command: resolve("pushary-prompt-hook"),
99
- timeout: 10
100
- }]
101
- });
102
- hooks.UserPromptSubmit = userPromptSubmit;
103
- };
104
- var removePusharySettings = (settings) => {
105
- let changed = removeClaudeMcpServers(settings);
106
- const permissions = asRecord(settings.permissions);
107
- if (permissions && Array.isArray(permissions.allow)) {
108
- const filtered = permissions.allow.filter((rule) => !isPusharyPermission(rule));
109
- if (filtered.length !== permissions.allow.length) {
110
- if (filtered.length === 0) {
111
- delete permissions.allow;
112
- } else {
113
- permissions.allow = filtered;
114
- }
115
- if (Object.keys(permissions).length === 0) delete settings.permissions;
116
- changed = true;
117
- }
118
- }
119
- const hooks = asRecord(settings.hooks);
120
- if (hooks) {
121
- for (const key of ["PreToolUse", "PostToolUse", "Stop", "UserPromptSubmit"]) {
122
- const entries = hooks[key];
123
- if (!Array.isArray(entries)) continue;
124
- const filtered = entries.filter((entry) => !isPusharyHook(entry));
125
- if (filtered.length !== entries.length) {
126
- if (filtered.length === 0) {
127
- delete hooks[key];
128
- } else {
129
- hooks[key] = filtered;
130
- }
131
- changed = true;
132
- }
133
- }
134
- if (Object.keys(hooks).length === 0) delete settings.hooks;
135
- }
136
- return changed;
137
- };
138
-
139
- export {
140
- addClaudeMcpServer,
141
- removeClaudeMcpServers,
142
- addPusharyToolPermissions,
143
- addPusharyHooks,
144
- removePusharySettings
145
- };