@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,357 +0,0 @@
1
- import {
2
- HOOK_BUDGETS
3
- } from "./chunk-C4BMEVK7.js";
4
-
5
- // src/codex-config.ts
6
- import { createHash } from "crypto";
7
- var CODEX_HOOK_BINARY = "pushary-codex-hook";
8
- var CODEX_HOOK_EVENTS = [
9
- { event: "PermissionRequest", matcher: "Bash|apply_patch", timeout: HOOK_BUDGETS.codex.budgetSeconds, statusMessage: "Waiting for your phone" },
10
- { event: "PreToolUse", matcher: "Bash|apply_patch", timeout: HOOK_BUDGETS.codex.budgetSeconds, statusMessage: "Checking Pushary policy" },
11
- { event: "PostToolUse", matcher: "Bash|apply_patch", timeout: 10 },
12
- { event: "UserPromptSubmit", timeout: 10 },
13
- { event: "Stop", timeout: 10 },
14
- { event: "SessionStart", matcher: "startup|resume", timeout: 10 }
15
- ];
16
- var CODEX_EVENT_KEY = {
17
- PermissionRequest: "permission_request",
18
- PreToolUse: "pre_tool_use",
19
- PostToolUse: "post_tool_use",
20
- UserPromptSubmit: "user_prompt_submit",
21
- Stop: "stop",
22
- SessionStart: "session_start"
23
- };
24
- var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
25
- var ensureRecord = (target, key) => {
26
- const existing = asRecord(target[key]);
27
- if (existing) return existing;
28
- const created = {};
29
- target[key] = created;
30
- return created;
31
- };
32
- var CODEX_MCP_URL = "https://pushary.com/api/mcp/mcp";
33
- var addCodexMcpServer = (config, apiKey) => {
34
- const servers = ensureRecord(config, "mcp_servers");
35
- const pushary = ensureRecord(servers, "pushary");
36
- pushary.url = CODEX_MCP_URL;
37
- ensureRecord(pushary, "http_headers").Authorization = `Bearer ${apiKey}`;
38
- pushary.default_tools_approval_mode = "approve";
39
- delete pushary.bearer_token_env_var;
40
- delete pushary.tools;
41
- };
42
- var readCodexMcpAuth = (config) => {
43
- const pushary = asRecord(asRecord(config.mcp_servers)?.pushary);
44
- if (!pushary) return void 0;
45
- const authorization = asRecord(pushary.http_headers)?.Authorization;
46
- if (typeof authorization === "string" && authorization.startsWith("Bearer ")) {
47
- return { method: "embedded", key: authorization.slice("Bearer ".length).trim() };
48
- }
49
- if (typeof pushary.bearer_token_env_var === "string") {
50
- return { method: "env", envVar: pushary.bearer_token_env_var };
51
- }
52
- if (typeof pushary.bearer_token === "string") return { method: "legacy-bearer" };
53
- return void 0;
54
- };
55
- var isPusharyCodexHook = (entry) => {
56
- const hooks = asRecord(entry)?.hooks;
57
- if (!Array.isArray(hooks)) return false;
58
- return hooks.some((hook) => String(asRecord(hook)?.command ?? "").includes(CODEX_HOOK_BINARY));
59
- };
60
- var addCodexHooks = (config, command) => {
61
- const hooks = ensureRecord(config, "hooks");
62
- for (const definition of CODEX_HOOK_EVENTS) {
63
- const existing = Array.isArray(hooks[definition.event]) ? hooks[definition.event] : [];
64
- const entries = existing.filter((entry) => !isPusharyCodexHook(entry));
65
- entries.push({
66
- ...definition.matcher ? { matcher: definition.matcher } : {},
67
- hooks: [{
68
- type: "command",
69
- command,
70
- timeout: definition.timeout,
71
- ...definition.statusMessage ? { statusMessage: definition.statusMessage } : {}
72
- }]
73
- });
74
- hooks[definition.event] = entries;
75
- }
76
- };
77
- var removeCodexHooks = (config) => {
78
- const hooks = asRecord(config.hooks);
79
- if (!hooks) return false;
80
- let changed = false;
81
- for (const definition of CODEX_HOOK_EVENTS) {
82
- const entries = hooks[definition.event];
83
- if (!Array.isArray(entries)) continue;
84
- const filtered = entries.filter((entry) => !isPusharyCodexHook(entry));
85
- if (filtered.length !== entries.length) {
86
- if (filtered.length === 0) {
87
- delete hooks[definition.event];
88
- } else {
89
- hooks[definition.event] = filtered;
90
- }
91
- changed = true;
92
- }
93
- }
94
- if (Object.keys(hooks).length === 0) delete config.hooks;
95
- return changed;
96
- };
97
- var hasCodexHooks = (config) => {
98
- const hooks = asRecord(config.hooks);
99
- if (!hooks) return false;
100
- return CODEX_HOOK_EVENTS.some((definition) => {
101
- const entries = hooks[definition.event];
102
- return Array.isArray(entries) && entries.some(isPusharyCodexHook);
103
- });
104
- };
105
- var missingCodexHookEvents = (config) => {
106
- const hooks = asRecord(config.hooks);
107
- return CODEX_HOOK_EVENTS.filter((definition) => {
108
- const entries = hooks?.[definition.event];
109
- return !Array.isArray(entries) || !entries.some(isPusharyCodexHook);
110
- }).map((definition) => definition.event);
111
- };
112
- var canonicalJson = (value) => {
113
- if (value === null || typeof value !== "object") return JSON.stringify(value);
114
- if (Array.isArray(value)) return "[" + value.map(canonicalJson).join(",") + "]";
115
- const obj = value;
116
- return "{" + Object.keys(obj).sort().map((key) => JSON.stringify(key) + ":" + canonicalJson(obj[key])).join(",") + "}";
117
- };
118
- var codexHookTrustHash = (definition, command) => {
119
- const hook = { async: false, command, timeout: definition.timeout, type: "command" };
120
- if (definition.statusMessage) hook.statusMessage = definition.statusMessage;
121
- const identity = { event_name: CODEX_EVENT_KEY[definition.event], hooks: [hook] };
122
- if (definition.matcher) identity.matcher = definition.matcher;
123
- return "sha256:" + createHash("sha256").update(canonicalJson(identity), "utf8").digest("hex");
124
- };
125
- var codexHookStateKey = (hooksJsonPath, event) => `${hooksJsonPath}:${CODEX_EVENT_KEY[event]}:0:0`;
126
- var untrustedCodexHookEvents = (config, hooksJsonPath, command) => {
127
- const state = asRecord(asRecord(config.hooks)?.state);
128
- return CODEX_HOOK_EVENTS.filter((definition) => {
129
- const entry = asRecord(state?.[codexHookStateKey(hooksJsonPath, definition.event)]);
130
- const stored = entry?.trusted_hash;
131
- return stored !== codexHookTrustHash(definition, command);
132
- }).map((definition) => definition.event);
133
- };
134
- var addCodexHookTrust = (config, hooksJsonPath, command) => {
135
- const hooks = ensureRecord(config, "hooks");
136
- const state = ensureRecord(hooks, "state");
137
- for (const definition of CODEX_HOOK_EVENTS) {
138
- const key = codexHookStateKey(hooksJsonPath, definition.event);
139
- const existing = asRecord(state[key]) ?? {};
140
- state[key] = { ...existing, trusted_hash: codexHookTrustHash(definition, command) };
141
- }
142
- };
143
-
144
- // src/gemini-config.ts
145
- var GEMINI_HOOK_BINARY = "pushary-gemini-hook";
146
- var GEMINI_MCP_URL = "https://pushary.com/api/mcp/mcp";
147
- var GEMINI_HOOK_EVENTS = [
148
- { event: "BeforeTool", matcher: "run_shell_command|write_file|replace", timeoutMs: HOOK_BUDGETS.gemini.budgetSeconds * 1e3 },
149
- { event: "AfterTool", matcher: "run_shell_command|write_file|replace", timeoutMs: 1e4 },
150
- { event: "BeforeAgent", timeoutMs: 1e4 },
151
- { event: "SessionStart", timeoutMs: 1e4 },
152
- { event: "SessionEnd", timeoutMs: 1e4 }
153
- ];
154
- var asRecord2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
155
- var ensureRecord2 = (target, key) => {
156
- const existing = asRecord2(target[key]);
157
- if (existing) return existing;
158
- const created = {};
159
- target[key] = created;
160
- return created;
161
- };
162
- var isPusharyGeminiHook = (entry) => {
163
- const hooks = asRecord2(entry)?.hooks;
164
- if (!Array.isArray(hooks)) return false;
165
- return hooks.some((hook) => String(asRecord2(hook)?.command ?? "").includes(GEMINI_HOOK_BINARY));
166
- };
167
- var addGeminiMcpServer = (settings, apiKey) => {
168
- const mcpServers = ensureRecord2(settings, "mcpServers");
169
- mcpServers.pushary = {
170
- httpUrl: GEMINI_MCP_URL,
171
- headers: { Authorization: `Bearer ${apiKey}` },
172
- trust: true
173
- };
174
- };
175
- var addGeminiHooks = (settings, command) => {
176
- const hooks = ensureRecord2(settings, "hooks");
177
- for (const definition of GEMINI_HOOK_EVENTS) {
178
- const existing = Array.isArray(hooks[definition.event]) ? hooks[definition.event] : [];
179
- const entries = existing.filter((entry) => !isPusharyGeminiHook(entry));
180
- entries.push({
181
- ...definition.matcher ? { matcher: definition.matcher } : {},
182
- hooks: [{
183
- name: "pushary",
184
- type: "command",
185
- command,
186
- timeout: definition.timeoutMs
187
- }]
188
- });
189
- hooks[definition.event] = entries;
190
- }
191
- };
192
- var removeGeminiHooks = (settings) => {
193
- const hooks = asRecord2(settings.hooks);
194
- if (!hooks) return false;
195
- let changed = false;
196
- for (const definition of GEMINI_HOOK_EVENTS) {
197
- const entries = hooks[definition.event];
198
- if (!Array.isArray(entries)) continue;
199
- const filtered = entries.filter((entry) => !isPusharyGeminiHook(entry));
200
- if (filtered.length !== entries.length) {
201
- if (filtered.length === 0) {
202
- delete hooks[definition.event];
203
- } else {
204
- hooks[definition.event] = filtered;
205
- }
206
- changed = true;
207
- }
208
- }
209
- if (Object.keys(hooks).length === 0) delete settings.hooks;
210
- return changed;
211
- };
212
- var removeGeminiMcpServer = (settings) => {
213
- const mcpServers = asRecord2(settings.mcpServers);
214
- if (!mcpServers?.pushary) return false;
215
- delete mcpServers.pushary;
216
- if (Object.keys(mcpServers).length === 0) delete settings.mcpServers;
217
- return true;
218
- };
219
- var removeGeminiSettings = (settings) => {
220
- const mcpRemoved = removeGeminiMcpServer(settings);
221
- const hooksRemoved = removeGeminiHooks(settings);
222
- return mcpRemoved || hooksRemoved;
223
- };
224
- var hasGeminiHooks = (settings) => {
225
- const hooks = asRecord2(settings.hooks);
226
- if (!hooks) return false;
227
- return GEMINI_HOOK_EVENTS.some((definition) => {
228
- const entries = hooks[definition.event];
229
- return Array.isArray(entries) && entries.some(isPusharyGeminiHook);
230
- });
231
- };
232
- var missingGeminiHookEvents = (settings) => {
233
- const hooks = asRecord2(settings.hooks);
234
- return GEMINI_HOOK_EVENTS.filter((definition) => {
235
- const entries = hooks?.[definition.event];
236
- return !Array.isArray(entries) || !entries.some(isPusharyGeminiHook);
237
- }).map((definition) => definition.event);
238
- };
239
-
240
- // src/instruction-file.ts
241
- import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync } from "fs";
242
- import { dirname } from "path";
243
- var PUSHARY_BEGIN = "<!-- BEGIN PUSHARY (managed by @pushary/agent-hooks; do not edit this block) -->";
244
- var PUSHARY_END = "<!-- END PUSHARY -->";
245
- var instructionBody = (label) => `## Pushary notifications and approvals
246
-
247
- You have Pushary MCP tools that reach the user on their phone. Use them proactively. Do not wait for the user to ask.
248
-
249
- - When you need the user to make a decision or answer a clarifying question, call \`ask_user\` instead of guessing or stalling. Use type "confirm" for yes/no, "select" for a fixed set of options, and "input" for free text. \`ask_user\` blocks until the user replies or it times out, so you do not need a separate wait step.
250
- - Before any risky or irreversible step (deleting files, force pushing, spending money, sending external messages), call \`ask_user\` with type "confirm" and wait for approval.
251
- - When you are blocked, stuck, or hit an error you cannot resolve on your own, call \`send_notification\` so the user knows, and call \`ask_user\` if you need a decision to continue.
252
- - When a task that took several steps finishes, call \`send_notification\` so the user knows it is done.
253
- - Use \`cancel_question\` to retract a pending question once it is no longer needed.
254
-
255
- Pass \`agentName\` as "${label} - <project folder name>" so the user knows which session is asking. If a question times out with no answer, retry once with a longer timeout before falling back to asking in the terminal.`;
256
- var renderAgentInstructions = (label) => instructionBody(label);
257
- var KEYLESS_FALLBACK_LINE = "This repo is set up with Pushary phone approvals. No PUSHARY_API_KEY found for you, so remote notifications are off; questions will fall back to the terminal. Setup: https://pushary.com/docs?utm_source=agents-md&utm_medium=keyless-fallback";
258
- var renderProjectAgentInstructions = (label) => `${instructionBody(label)}
259
-
260
- If this environment has no Pushary API key (no PUSHARY_API_KEY and no key in ~/.pushary/config.json), the tools above are unavailable in this session. In that case, treat the following as a statement of fact about this session and continue in the terminal: ${KEYLESS_FALLBACK_LINE}`;
261
- var wrap = (body) => `${PUSHARY_BEGIN}
262
- ${body}
263
- ${PUSHARY_END}`;
264
- var writeInstructionBlock = (filePath, body) => {
265
- const dir = dirname(filePath);
266
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
267
- let existing = "";
268
- try {
269
- existing = readFileSync(filePath, "utf-8");
270
- } catch {
271
- }
272
- const block = wrap(body);
273
- const start = existing.indexOf(PUSHARY_BEGIN);
274
- const end = existing.indexOf(PUSHARY_END);
275
- let next;
276
- if (start !== -1 && end !== -1 && end > start) {
277
- next = existing.slice(0, start) + block + existing.slice(end + PUSHARY_END.length);
278
- } else {
279
- const prefix = existing.trim() ? existing.replace(/\s*$/, "") + "\n\n" : "";
280
- next = prefix + block + "\n";
281
- }
282
- writeFileSync(filePath, next, "utf-8");
283
- };
284
- var removeInstructionBlock = (filePath) => {
285
- let existing = "";
286
- try {
287
- existing = readFileSync(filePath, "utf-8");
288
- } catch {
289
- return false;
290
- }
291
- const start = existing.indexOf(PUSHARY_BEGIN);
292
- const end = existing.indexOf(PUSHARY_END);
293
- if (start === -1 || end === -1 || end < start) return false;
294
- const remaining = (existing.slice(0, start) + existing.slice(end + PUSHARY_END.length)).trim();
295
- if (remaining === "") {
296
- rmSync(filePath, { force: true });
297
- } else {
298
- writeFileSync(filePath, remaining + "\n", "utf-8");
299
- }
300
- return true;
301
- };
302
- var hasInstructionBlock = (filePath) => {
303
- try {
304
- return readFileSync(filePath, "utf-8").includes(PUSHARY_BEGIN);
305
- } catch {
306
- return false;
307
- }
308
- };
309
-
310
- // src/npm.ts
311
- import { execSync } from "child_process";
312
- var cleanNpmEnv = () => {
313
- const env = {};
314
- for (const [key, value] of Object.entries(process.env)) {
315
- if (key.toLowerCase().startsWith("npm_config_workspace")) continue;
316
- env[key] = value;
317
- }
318
- return env;
319
- };
320
- var npmErrorMessage = (err) => {
321
- const e = err;
322
- const text = [e?.stderr, e?.stdout].map((part) => part ? part.toString() : "").join("\n");
323
- const line = text.split("\n").map((l) => l.replace(/^npm error\s*/i, "").trim()).find((l) => l && !l.startsWith("A complete log") && !/^code\s/i.test(l));
324
- return line || e?.message || String(err);
325
- };
326
- var execNpm = (args, options = {}) => {
327
- return execSync(`npm ${args}`, {
328
- timeout: 12e4,
329
- stdio: "pipe",
330
- ...options,
331
- env: { ...cleanNpmEnv(), ...options.env ?? {} }
332
- });
333
- };
334
-
335
- export {
336
- addCodexMcpServer,
337
- readCodexMcpAuth,
338
- addCodexHooks,
339
- removeCodexHooks,
340
- hasCodexHooks,
341
- missingCodexHookEvents,
342
- untrustedCodexHookEvents,
343
- addCodexHookTrust,
344
- GEMINI_HOOK_BINARY,
345
- addGeminiMcpServer,
346
- addGeminiHooks,
347
- removeGeminiSettings,
348
- hasGeminiHooks,
349
- missingGeminiHookEvents,
350
- renderAgentInstructions,
351
- renderProjectAgentInstructions,
352
- writeInstructionBlock,
353
- removeInstructionBlock,
354
- hasInstructionBlock,
355
- npmErrorMessage,
356
- execNpm
357
- };
@@ -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, wait: false }, { maxRetries: 3 });
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 }, { maxRetries: 3 });
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,109 +0,0 @@
1
- import {
2
- DEFAULT_SESSION,
3
- cancelQuestion,
4
- describeToolCall,
5
- getMachineId,
6
- isDefaultSession,
7
- listPendingQuestions,
8
- removePendingQuestion,
9
- removePendingSession
10
- } from "./chunk-OF5WIOYS.js";
11
- import {
12
- withRetry
13
- } from "./chunk-3MIR7ODJ.js";
14
- import {
15
- getApiKey,
16
- getBaseUrl
17
- } from "./chunk-VUNL35KE.js";
18
-
19
- // src/events.ts
20
- import { basename } from "path";
21
- var cleanupPendingQuestions = async (sessionId) => {
22
- try {
23
- const files = listPendingQuestions(sessionId);
24
- const apiKey = getApiKey();
25
- for (const correlationId of files) {
26
- try {
27
- await cancelQuestion(apiKey, correlationId);
28
- } catch {
29
- }
30
- removePendingQuestion(sessionId, correlationId);
31
- }
32
- if (!isDefaultSession(sessionId)) removePendingSession(sessionId);
33
- } catch {
34
- }
35
- };
36
- var reportEvent = async (event) => {
37
- const apiKey = getApiKey();
38
- const baseUrl = getBaseUrl();
39
- await withRetry(async () => {
40
- await fetch(`${baseUrl}/api/agent/event`, {
41
- method: "POST",
42
- headers: {
43
- "Content-Type": "application/json",
44
- "Authorization": `Bearer ${apiKey}`
45
- },
46
- body: JSON.stringify({
47
- ...event,
48
- machineId: event.machineId ?? getMachineId()
49
- }),
50
- signal: AbortSignal.timeout(1e4)
51
- });
52
- }, { maxAttempts: 2, baseDelayMs: 300 });
53
- };
54
- var handlePostToolUse = async (input) => {
55
- try {
56
- const projectName = basename(input.cwd ?? process.cwd());
57
- const action = describeToolCall(input.tool_name, input.tool_input, "event");
58
- const isError = input.tool_result && ("error" in input.tool_result || "is_error" in input.tool_result);
59
- await Promise.allSettled([
60
- cleanupPendingQuestions(input.session_id || DEFAULT_SESSION),
61
- reportEvent({
62
- event: isError ? "tool_error" : "tool_complete",
63
- agentType: "claude_code",
64
- agentName: `Claude Code - ${projectName}`,
65
- action,
66
- sessionId: input.session_id,
67
- error: isError ? String(input.tool_result?.error ?? input.tool_result?.stderr ?? "").slice(0, 500) : void 0
68
- })
69
- ]);
70
- } catch {
71
- }
72
- };
73
- var handleStop = async (input) => {
74
- try {
75
- const projectName = basename(input.cwd ?? process.cwd());
76
- await Promise.allSettled([
77
- cleanupPendingQuestions(input.session_id || DEFAULT_SESSION),
78
- reportEvent({
79
- event: "session_end",
80
- agentType: "claude_code",
81
- agentName: `Claude Code - ${projectName}`,
82
- action: "Session ended",
83
- sessionId: input.session_id
84
- })
85
- ]);
86
- } catch {
87
- }
88
- };
89
- var handleNotification = async (input) => {
90
- try {
91
- const projectName = basename(input.cwd ?? process.cwd());
92
- await reportEvent({
93
- event: input.type === "error" ? "error" : "notification",
94
- agentType: "claude_code",
95
- agentName: `Claude Code - ${projectName}`,
96
- action: input.title ?? input.message ?? "Notification",
97
- sessionId: input.session_id,
98
- error: input.type === "error" ? input.message : void 0
99
- });
100
- } catch {
101
- }
102
- };
103
-
104
- export {
105
- reportEvent,
106
- handlePostToolUse,
107
- handleStop,
108
- handleNotification
109
- };
@@ -1,136 +0,0 @@
1
- // src/claude-config.ts
2
- var PUSHARY_MCP_URL = "https://pushary.com/api/mcp/mcp";
3
- var PUSHARY_PERMISSION_RULE = "mcp__pushary__*";
4
- var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
5
- var ensureRecord = (target, key) => {
6
- const existing = asRecord(target[key]);
7
- if (existing) return existing;
8
- const created = {};
9
- target[key] = created;
10
- return created;
11
- };
12
- var isPusharyPermission = (rule) => typeof rule === "string" && (rule.includes("pushary") || rule.includes("MCP(pushary"));
13
- var isPusharyHook = (entry) => {
14
- const hooks = asRecord(entry)?.hooks;
15
- if (!Array.isArray(hooks)) return false;
16
- return hooks.some((hook) => {
17
- const command = String(asRecord(hook)?.command ?? "");
18
- return command.includes("pushary-hook") || command.includes("pushary-post-hook") || command.includes("pushary-stop-hook");
19
- });
20
- };
21
- var addClaudeMcpServer = (config, apiKey) => {
22
- const mcpServers = ensureRecord(config, "mcpServers");
23
- mcpServers.pushary = {
24
- type: "http",
25
- url: PUSHARY_MCP_URL,
26
- headers: { Authorization: `Bearer ${apiKey}` }
27
- };
28
- };
29
- var removeClaudeMcpServers = (config) => {
30
- let changed = false;
31
- const removeFrom = (target) => {
32
- const mcpServers = asRecord(target.mcpServers);
33
- if (!mcpServers?.pushary) return;
34
- delete mcpServers.pushary;
35
- if (Object.keys(mcpServers).length === 0) delete target.mcpServers;
36
- changed = true;
37
- };
38
- removeFrom(config);
39
- const projects = asRecord(config.projects);
40
- if (projects) {
41
- for (const project of Object.values(projects)) {
42
- const projectConfig = asRecord(project);
43
- if (projectConfig) removeFrom(projectConfig);
44
- }
45
- }
46
- return changed;
47
- };
48
- var addPusharyToolPermissions = (settings) => {
49
- const permissions = ensureRecord(settings, "permissions");
50
- const allow = Array.isArray(permissions.allow) ? permissions.allow : [];
51
- const filtered = allow.filter((rule) => !isPusharyPermission(rule));
52
- if (!filtered.includes(PUSHARY_PERMISSION_RULE)) {
53
- filtered.push(PUSHARY_PERMISSION_RULE);
54
- }
55
- permissions.allow = filtered;
56
- };
57
- var addPusharyHooks = (settings) => {
58
- const hooks = ensureRecord(settings, "hooks");
59
- const preToolUse = Array.isArray(hooks.PreToolUse) ? hooks.PreToolUse : [];
60
- if (!preToolUse.some(isPusharyHook)) {
61
- preToolUse.push({
62
- matcher: "Bash|Write|Edit",
63
- hooks: [{
64
- type: "command",
65
- command: "pushary-hook",
66
- timeout: 120
67
- }]
68
- });
69
- hooks.PreToolUse = preToolUse;
70
- }
71
- const postToolUse = Array.isArray(hooks.PostToolUse) ? hooks.PostToolUse : [];
72
- if (!postToolUse.some(isPusharyHook)) {
73
- postToolUse.push({
74
- matcher: "Bash|Write|Edit",
75
- hooks: [{
76
- type: "command",
77
- command: "pushary-post-hook",
78
- timeout: 10
79
- }]
80
- });
81
- hooks.PostToolUse = postToolUse;
82
- }
83
- const stop = Array.isArray(hooks.Stop) ? hooks.Stop : [];
84
- if (!stop.some(isPusharyHook)) {
85
- stop.push({
86
- hooks: [{
87
- type: "command",
88
- command: "pushary-stop-hook",
89
- timeout: 10
90
- }]
91
- });
92
- hooks.Stop = stop;
93
- }
94
- };
95
- var removePusharySettings = (settings) => {
96
- let changed = removeClaudeMcpServers(settings);
97
- const permissions = asRecord(settings.permissions);
98
- if (permissions && Array.isArray(permissions.allow)) {
99
- const filtered = permissions.allow.filter((rule) => !isPusharyPermission(rule));
100
- if (filtered.length !== permissions.allow.length) {
101
- if (filtered.length === 0) {
102
- delete permissions.allow;
103
- } else {
104
- permissions.allow = filtered;
105
- }
106
- if (Object.keys(permissions).length === 0) delete settings.permissions;
107
- changed = true;
108
- }
109
- }
110
- const hooks = asRecord(settings.hooks);
111
- if (hooks) {
112
- for (const key of ["PreToolUse", "PostToolUse", "Stop"]) {
113
- const entries = hooks[key];
114
- if (!Array.isArray(entries)) continue;
115
- const filtered = entries.filter((entry) => !isPusharyHook(entry));
116
- if (filtered.length !== entries.length) {
117
- if (filtered.length === 0) {
118
- delete hooks[key];
119
- } else {
120
- hooks[key] = filtered;
121
- }
122
- changed = true;
123
- }
124
- }
125
- if (Object.keys(hooks).length === 0) delete settings.hooks;
126
- }
127
- return changed;
128
- };
129
-
130
- export {
131
- addClaudeMcpServer,
132
- removeClaudeMcpServers,
133
- addPusharyToolPermissions,
134
- addPusharyHooks,
135
- removePusharySettings
136
- };