@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,242 +0,0 @@
1
- import {
2
- askUser,
3
- describeToolCall,
4
- isPolicyConfig,
5
- savePendingQuestion,
6
- sendNotification,
7
- waitForAnswer
8
- } from "./chunk-4Z4MB37G.js";
9
- import {
10
- getApiKey,
11
- getBaseUrl,
12
- withRetry
13
- } from "./chunk-O6A5RHWY.js";
14
-
15
- // src/policy.ts
16
- import { createHash } from "crypto";
17
- import { existsSync, readFileSync, writeFileSync } from "fs";
18
- import { join } from "path";
19
- import { tmpdir } from "os";
20
- var CACHE_TTL_MS = 5 * 60 * 1e3;
21
- var cacheFile = (apiKey) => {
22
- const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
23
- return join(tmpdir(), `pushary-policy-${hash}.json`);
24
- };
25
- var fetchPolicy = async (apiKey) => {
26
- return withRetry(async () => {
27
- const baseUrl = getBaseUrl();
28
- const response = await fetch(`${baseUrl}/api/mcp/policy`, {
29
- headers: { "Authorization": `Bearer ${apiKey}` },
30
- signal: AbortSignal.timeout(1e4)
31
- });
32
- if (!response.ok) {
33
- throw new Error(`Failed to fetch policy: ${response.status}`);
34
- }
35
- const raw = await response.json();
36
- if (!isPolicyConfig(raw)) throw new Error("Invalid policy response");
37
- return raw;
38
- }, { maxAttempts: 2 });
39
- };
40
- var getPolicy = async (apiKey) => {
41
- const path = cacheFile(apiKey);
42
- let staleCache = null;
43
- if (existsSync(path)) {
44
- try {
45
- const stat = readFileSync(path, "utf-8");
46
- const cached = JSON.parse(stat);
47
- if (!isPolicyConfig(cached)) throw new Error("Corrupted cache");
48
- if (!cached._cachedAt || Date.now() - cached._cachedAt < CACHE_TTL_MS) {
49
- return cached;
50
- }
51
- staleCache = cached;
52
- } catch {
53
- }
54
- }
55
- try {
56
- const policy = await fetchPolicy(apiKey);
57
- try {
58
- writeFileSync(path, JSON.stringify({ ...policy, _cachedAt: Date.now() }), "utf-8");
59
- } catch {
60
- }
61
- return policy;
62
- } catch {
63
- if (staleCache) return staleCache;
64
- throw new Error("Failed to fetch policy and no cached policy available");
65
- }
66
- };
67
- var resolvePolicy = (config, toolName, modeOverride) => {
68
- const base = config.policies.find((p) => p.tool === toolName) ?? config.policies.find((p) => p.tool === "*") ?? {
69
- tool: toolName,
70
- timeoutSeconds: config.defaultTimeoutSeconds,
71
- timeoutAction: config.defaultTimeoutAction,
72
- mode: config.defaultMode ?? "push_first",
73
- pushFirstSeconds: config.defaultPushFirstSeconds ?? 20
74
- };
75
- const effectiveOverride = modeOverride ?? config.modeOverride;
76
- if (effectiveOverride) {
77
- return { ...base, mode: effectiveOverride };
78
- }
79
- return base;
80
- };
81
- var fetchModeOverride = async (apiKey) => {
82
- try {
83
- const baseUrl = getBaseUrl();
84
- const response = await fetch(`${baseUrl}/api/mcp/mode`, {
85
- headers: { "Authorization": `Bearer ${apiKey}` },
86
- signal: AbortSignal.timeout(3e3)
87
- });
88
- if (!response.ok) return null;
89
- const data = await response.json();
90
- const mode = data.override?.mode;
91
- if (mode && ["push_only", "terminal_only", "push_first", "notify_only"].includes(mode)) {
92
- return mode;
93
- }
94
- return null;
95
- } catch {
96
- return null;
97
- }
98
- };
99
-
100
- // src/hook.ts
101
- import { basename } from "path";
102
- var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
103
- var allow = () => ({
104
- hookSpecificOutput: {
105
- hookEventName: "PreToolUse",
106
- permissionDecision: "allow"
107
- }
108
- });
109
- var deny = (reason) => ({
110
- hookSpecificOutput: {
111
- hookEventName: "PreToolUse",
112
- permissionDecision: "deny",
113
- permissionDecisionReason: reason
114
- }
115
- });
116
- var ask = (reason) => ({
117
- hookSpecificOutput: {
118
- hookEventName: "PreToolUse",
119
- permissionDecision: "ask",
120
- ...reason ? { permissionDecisionReason: reason } : {}
121
- }
122
- });
123
- var pollForAnswer = async (apiKey, correlationId, deadlineMs, pollInterval = 2e3) => {
124
- while (Date.now() < deadlineMs) {
125
- const remaining = Math.min(Math.max(deadlineMs - Date.now(), 1e3), 3e4);
126
- let answer;
127
- try {
128
- answer = await waitForAnswer(apiKey, correlationId, remaining);
129
- } catch {
130
- if (Date.now() + pollInterval >= deadlineMs) break;
131
- await sleep(pollInterval);
132
- continue;
133
- }
134
- if (answer.answered) return answer;
135
- if (Date.now() + pollInterval >= deadlineMs) break;
136
- await sleep(pollInterval);
137
- }
138
- return { answered: false };
139
- };
140
- var handlePushOnly = async (apiKey, description, projectName, timeoutSeconds, timeoutAction) => {
141
- let result;
142
- try {
143
- result = await askUser(apiKey, {
144
- question: `Allow ${description}?`,
145
- type: "confirm",
146
- context: `Agent wants to run this in ${projectName}`,
147
- agentName: `Claude Code - ${projectName}`
148
- });
149
- } catch {
150
- switch (timeoutAction) {
151
- case "approve":
152
- return allow();
153
- case "deny":
154
- return deny("Push notification failed, denying per policy");
155
- default:
156
- return ask("Push notification failed, asking in terminal");
157
- }
158
- }
159
- const deadline = Date.now() + timeoutSeconds * 1e3;
160
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline);
161
- if (answer.answered) {
162
- return answer.value === "yes" ? allow() : deny("Denied via push notification");
163
- }
164
- switch (timeoutAction) {
165
- case "approve":
166
- return allow();
167
- case "deny":
168
- return deny("No response within timeout");
169
- default:
170
- return ask("No push response, asking in terminal");
171
- }
172
- };
173
- var handleTerminalOnly = () => {
174
- return ask();
175
- };
176
- var handlePushFirst = async (apiKey, description, projectName, pushFirstSeconds) => {
177
- let result;
178
- try {
179
- result = await askUser(apiKey, {
180
- question: `Allow ${description}?`,
181
- type: "confirm",
182
- context: `Agent wants to run this in ${projectName}`,
183
- agentName: `Claude Code - ${projectName}`
184
- });
185
- } catch {
186
- return ask("Push notification failed, asking in terminal");
187
- }
188
- const deadline = Date.now() + pushFirstSeconds * 1e3;
189
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline, 1500);
190
- if (answer.answered) {
191
- return answer.value === "yes" ? allow() : deny("Denied via push notification");
192
- }
193
- savePendingQuestion(result.correlationId);
194
- return ask("Sent as push notification. You can also approve here.");
195
- };
196
- var handleNotifyOnly = async (apiKey, description, projectName) => {
197
- try {
198
- await sendNotification(apiKey, {
199
- title: "Agent needs approval",
200
- body: description,
201
- agentName: `Claude Code - ${projectName}`
202
- });
203
- } catch {
204
- }
205
- return ask();
206
- };
207
- var handlePreToolUse = async (input) => {
208
- try {
209
- const apiKey = getApiKey();
210
- const [policy, modeOverride] = await Promise.all([
211
- getPolicy(apiKey),
212
- fetchModeOverride(apiKey)
213
- ]);
214
- const toolPolicy = resolvePolicy(policy, input.tool_name, modeOverride);
215
- if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") {
216
- return allow();
217
- }
218
- const description = describeToolCall(input.tool_name, input.tool_input, "hook");
219
- const projectName = basename(input.cwd ?? process.cwd());
220
- switch (toolPolicy.mode) {
221
- case "push_only":
222
- return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction);
223
- case "terminal_only":
224
- return handleTerminalOnly();
225
- case "push_first":
226
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds);
227
- case "notify_only":
228
- return handleNotifyOnly(apiKey, description, projectName);
229
- default:
230
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds);
231
- }
232
- } catch {
233
- return ask("Pushary unavailable, falling back to terminal approval");
234
- }
235
- };
236
-
237
- export {
238
- getPolicy,
239
- resolvePolicy,
240
- fetchModeOverride,
241
- handlePreToolUse
242
- };
@@ -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-GTJGZBTQ.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
- };
@@ -1,145 +0,0 @@
1
- import {
2
- HOOK_BUDGETS
3
- } from "./chunk-XHTZ2DWC.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
- };