@pushary/agent-hooks 0.22.0 → 0.23.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 (82) hide show
  1. package/data/cursor-plugin/README.md +5 -1
  2. package/data/cursor-plugin/mcp.json +1 -1
  3. package/dist/bin/pushary-clean.js +1 -1
  4. package/dist/bin/pushary-doctor.js +2 -2
  5. package/dist/bin/pushary-setup.js +23 -1
  6. package/dist/{chunk-BHAMEPOP.js → chunk-JPRRYC5X.js} +5 -0
  7. package/package.json +1 -1
  8. package/dist/chunk-22CV7V7A.js +0 -38
  9. package/dist/chunk-2BE2IPMO.js +0 -315
  10. package/dist/chunk-2CRLBMOX.js +0 -244
  11. package/dist/chunk-2HMNOZPY.js +0 -109
  12. package/dist/chunk-2I6DLXJN.js +0 -219
  13. package/dist/chunk-2Q6XPZ4Q.js +0 -395
  14. package/dist/chunk-3LC4YUMA.js +0 -194
  15. package/dist/chunk-3MIR7ODJ.js +0 -112
  16. package/dist/chunk-3QZESA66.js +0 -222
  17. package/dist/chunk-4Z4MB37G.js +0 -96
  18. package/dist/chunk-5GFUI5N6.js +0 -132
  19. package/dist/chunk-5JEDLXEC.js +0 -99
  20. package/dist/chunk-5LTQNC7R.js +0 -824
  21. package/dist/chunk-5QHQVXWN.js +0 -174
  22. package/dist/chunk-6A3WCJO2.js +0 -416
  23. package/dist/chunk-6QWFMVCD.js +0 -328
  24. package/dist/chunk-6SRXMZAN.js +0 -99
  25. package/dist/chunk-7PTU7TGE.js +0 -96
  26. package/dist/chunk-AB4KX4XT.js +0 -109
  27. package/dist/chunk-AC4UYAGX.js +0 -136
  28. package/dist/chunk-ACE77TKQ.js +0 -328
  29. package/dist/chunk-BYNYYZWW.js +0 -412
  30. package/dist/chunk-C5TFTNHG.js +0 -244
  31. package/dist/chunk-CH53PBQN.js +0 -265
  32. package/dist/chunk-DF3BM6BF.js +0 -195
  33. package/dist/chunk-DKZVKEOW.js +0 -175
  34. package/dist/chunk-EMPL27ZV.js +0 -96
  35. package/dist/chunk-EQJXMEIR.js +0 -175
  36. package/dist/chunk-FXYTRZHC.js +0 -177
  37. package/dist/chunk-GTJGZBTQ.js +0 -328
  38. package/dist/chunk-HJMFYDWY.js +0 -222
  39. package/dist/chunk-HRQEECB6.js +0 -315
  40. package/dist/chunk-HWEMAAOY.js +0 -370
  41. package/dist/chunk-IBWCHA5M.js +0 -10
  42. package/dist/chunk-KTM4ZQ3W.js +0 -96
  43. package/dist/chunk-KTP2EPVB.js +0 -27
  44. package/dist/chunk-KYARP7KP.js +0 -97
  45. package/dist/chunk-M2N5DYWN.js +0 -247
  46. package/dist/chunk-M5F2L4KF.js +0 -177
  47. package/dist/chunk-M6S3M6E3.js +0 -244
  48. package/dist/chunk-N7VXDBQU.js +0 -6
  49. package/dist/chunk-O6A5RHWY.js +0 -122
  50. package/dist/chunk-ODUXELPM.js +0 -219
  51. package/dist/chunk-OF5WIOYS.js +0 -129
  52. package/dist/chunk-OP4QAN23.js +0 -99
  53. package/dist/chunk-P4JH2Q7Z.js +0 -102
  54. package/dist/chunk-PMD5JSV3.js +0 -242
  55. package/dist/chunk-PSSHNBEL.js +0 -177
  56. package/dist/chunk-QEPRH7JB.js +0 -315
  57. package/dist/chunk-QRXWPZKN.js +0 -308
  58. package/dist/chunk-QY4L6XHN.js +0 -384
  59. package/dist/chunk-RNWPCELY.js +0 -176
  60. package/dist/chunk-RSHN2AQ7.js +0 -29
  61. package/dist/chunk-RZLVE57X.js +0 -38
  62. package/dist/chunk-SDCIKREA.js +0 -241
  63. package/dist/chunk-SDREQWNI.js +0 -175
  64. package/dist/chunk-SH26ZOHU.js +0 -159
  65. package/dist/chunk-TRLBBLSS.js +0 -176
  66. package/dist/chunk-U6OXZPYC.js +0 -384
  67. package/dist/chunk-UIBTFZUD.js +0 -314
  68. package/dist/chunk-USUCPCUC.js +0 -156
  69. package/dist/chunk-V4GLWPD7.js +0 -174
  70. package/dist/chunk-VC6U3QGF.js +0 -142
  71. package/dist/chunk-VIST7ACL.js +0 -88
  72. package/dist/chunk-VUNL35KE.js +0 -16
  73. package/dist/chunk-VWBNI4SC.js +0 -174
  74. package/dist/chunk-W5KRWUNE.js +0 -262
  75. package/dist/chunk-WCGKLHCL.js +0 -154
  76. package/dist/chunk-WNXGIEX7.js +0 -219
  77. package/dist/chunk-XPVSZIA3.js +0 -315
  78. package/dist/chunk-Y633ZIJF.js +0 -384
  79. package/dist/chunk-YCL4GUFR.js +0 -222
  80. package/dist/chunk-YTMKB44I.js +0 -220
  81. package/dist/chunk-ZWBS3T7Q.js +0 -244
  82. package/dist/pushary-mode-T7XOPI6Z.js +0 -83
@@ -1,328 +0,0 @@
1
- import {
2
- extractPolicyArg,
3
- isApprovalMode,
4
- isSafeReadOnlyCommand,
5
- matchRankWeight,
6
- matchToolPattern
7
- } from "./chunk-USUCPCUC.js";
8
- import {
9
- callMcpTool,
10
- withRetry
11
- } from "./chunk-DWED7BS3.js";
12
- import {
13
- getBaseUrl
14
- } from "./chunk-NKXSILEW.js";
15
-
16
- // src/validate.ts
17
- var isPolicyConfig = (data) => {
18
- if (!data || typeof data !== "object") return false;
19
- const d = data;
20
- return Array.isArray(d.policies) && typeof d.defaultTimeoutSeconds === "number" && typeof d.defaultTimeoutAction === "string";
21
- };
22
- var isAskUserResponse = (data) => {
23
- if (!data || typeof data !== "object") return false;
24
- const d = data;
25
- return typeof d.correlationId === "string" && typeof d.status === "string";
26
- };
27
- var isWaitForAnswerResponse = (data) => {
28
- if (!data || typeof data !== "object") return false;
29
- const d = data;
30
- return typeof d.answered === "boolean";
31
- };
32
-
33
- // src/api.ts
34
- var askUser = async (apiKey, params, timeoutMs = 15e3) => {
35
- const result = await callMcpTool(apiKey, "ask_user", { ...params, wait: false }, { maxRetries: 3, timeoutMs });
36
- if (!isAskUserResponse(result)) throw new Error("Invalid ask_user response");
37
- return result;
38
- };
39
- var waitForAnswer = async (apiKey, correlationId, timeoutMs = 3e4) => {
40
- const result = await callMcpTool(apiKey, "wait_for_answer", {
41
- correlationId,
42
- timeoutMs
43
- }, { timeoutMs: timeoutMs + 1e4 });
44
- if (!isWaitForAnswerResponse(result)) throw new Error("Invalid wait_for_answer response");
45
- return result;
46
- };
47
- var cancelQuestion = async (apiKey, correlationId) => {
48
- await callMcpTool(apiKey, "cancel_question", { correlationId });
49
- };
50
- var sendNotification = async (apiKey, params, timeoutMs = 15e3) => {
51
- await callMcpTool(apiKey, "send_notification", { ...params }, { maxRetries: 3, timeoutMs });
52
- };
53
-
54
- // src/policy.ts
55
- import { createHash } from "crypto";
56
- import { existsSync, readFileSync, writeFileSync } from "fs";
57
- import { join } from "path";
58
- import { tmpdir } from "os";
59
- var CACHE_TTL_MS = 60 * 1e3;
60
- var cacheFile = (apiKey) => {
61
- const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
62
- return join(tmpdir(), `pushary-policy-${hash}.json`);
63
- };
64
- var fetchPolicy = async (apiKey) => {
65
- return withRetry(async () => {
66
- const baseUrl = getBaseUrl();
67
- const response = await fetch(`${baseUrl}/api/mcp/policy`, {
68
- headers: { "Authorization": `Bearer ${apiKey}` },
69
- signal: AbortSignal.timeout(1e4)
70
- });
71
- if (!response.ok) {
72
- throw new Error(`Failed to fetch policy: ${response.status}`);
73
- }
74
- const raw = await response.json();
75
- if (!isPolicyConfig(raw)) throw new Error("Invalid policy response");
76
- return raw;
77
- }, { maxAttempts: 2 });
78
- };
79
- var getPolicy = async (apiKey, expectedVersion) => {
80
- const path = cacheFile(apiKey);
81
- let staleCache = null;
82
- if (existsSync(path)) {
83
- try {
84
- const stat = readFileSync(path, "utf-8");
85
- const cached = JSON.parse(stat);
86
- if (!isPolicyConfig(cached)) throw new Error("Corrupted cache");
87
- const versionStale = expectedVersion != null && (cached._policyVersion ?? null) !== expectedVersion;
88
- const ttlFresh = !cached._cachedAt || Date.now() - cached._cachedAt < CACHE_TTL_MS;
89
- if (ttlFresh && !versionStale) {
90
- return cached;
91
- }
92
- staleCache = cached;
93
- } catch {
94
- }
95
- }
96
- try {
97
- const policy = await fetchPolicy(apiKey);
98
- try {
99
- writeFileSync(path, JSON.stringify({ ...policy, _cachedAt: Date.now(), _policyVersion: expectedVersion ?? null }), "utf-8");
100
- } catch {
101
- }
102
- return policy;
103
- } catch {
104
- if (staleCache) return staleCache;
105
- throw new Error("Failed to fetch policy and no cached policy available");
106
- }
107
- };
108
- var findBestMatch = (policies, toolName, arg) => {
109
- let best;
110
- let bestWeight = 0;
111
- let bestLength = -1;
112
- for (const candidate of policies) {
113
- const rank = matchToolPattern(candidate.tool, toolName, arg);
114
- if (rank === "none") continue;
115
- const weight = matchRankWeight(rank);
116
- const length = rank === "prefix" ? candidate.tool.length : -1;
117
- if (weight > bestWeight || weight === bestWeight && length > bestLength) {
118
- best = { policy: candidate, rank };
119
- bestWeight = weight;
120
- bestLength = length;
121
- }
122
- }
123
- return best;
124
- };
125
- var autoApprove = (tool) => ({
126
- tool,
127
- timeoutSeconds: 0,
128
- timeoutAction: "approve",
129
- mode: "terminal_only",
130
- pushFirstSeconds: 0
131
- });
132
- var resolvePolicy = (config, toolName, modeOverride, toolInput) => {
133
- const arg = toolInput ? extractPolicyArg(toolName, toolInput) : void 0;
134
- const match = findBestMatch(config.policies, toolName, arg);
135
- let base = match?.policy ?? config.policies.find((p) => p.tool === "*") ?? {
136
- tool: toolName,
137
- timeoutSeconds: config.defaultTimeoutSeconds,
138
- timeoutAction: config.defaultTimeoutAction,
139
- mode: config.defaultMode ?? "push_first",
140
- pushFirstSeconds: config.defaultPushFirstSeconds ?? 20
141
- };
142
- const governedBySpecificRule = match?.rank === "exact" || match?.rank === "prefix";
143
- if (!governedBySpecificRule && toolName === "Bash" && typeof arg === "string" && isSafeReadOnlyCommand(arg)) {
144
- base = autoApprove(base.tool);
145
- }
146
- const effectiveOverride = modeOverride ?? config.modeOverride;
147
- if (effectiveOverride) {
148
- return { ...base, mode: effectiveOverride };
149
- }
150
- return base;
151
- };
152
- var toPolicyVersion = (value) => typeof value === "string" || typeof value === "number" ? String(value) : null;
153
- var fetchModeState = async (apiKey, sessionId) => {
154
- try {
155
- const baseUrl = getBaseUrl();
156
- const url = sessionId ? `${baseUrl}/api/mcp/mode?session=${encodeURIComponent(sessionId)}` : `${baseUrl}/api/mcp/mode`;
157
- const response = await fetch(url, {
158
- headers: { "Authorization": `Bearer ${apiKey}` },
159
- signal: AbortSignal.timeout(3e3)
160
- });
161
- if (!response.ok) return { mode: null, kill: false, policyVersion: null };
162
- const data = await response.json();
163
- const mode = data.override?.mode;
164
- return {
165
- mode: isApprovalMode(mode) ? mode : null,
166
- kill: data.kill === true,
167
- policyVersion: toPolicyVersion(data.policyVersion)
168
- };
169
- } catch {
170
- return { mode: null, kill: false, policyVersion: null };
171
- }
172
- };
173
- var fetchModeOverride = async (apiKey) => (await fetchModeState(apiKey)).mode;
174
-
175
- // src/describe.ts
176
- import { isAbsolute, relative } from "path";
177
- var hookPrefixes = {
178
- Bash: (input) => `bash: ${input.command ?? "(no command)"}`,
179
- Write: (input) => `write file: ${input.file_path ?? "(unknown path)"}`,
180
- Edit: (input) => `edit file: ${input.file_path ?? "(unknown path)"}`,
181
- Read: (input) => `read file: ${input.file_path ?? "(unknown path)"}`
182
- };
183
- var eventPrefixes = {
184
- Bash: (input) => `ran: ${String(input.command ?? "").slice(0, 120)}`,
185
- Write: (input) => `wrote: ${input.file_path ?? "unknown"}`,
186
- Edit: (input) => `edited: ${input.file_path ?? "unknown"}`,
187
- Read: (input) => `read: ${input.file_path ?? "unknown"}`
188
- };
189
- var describeToolCall = (toolName, toolInput, format = "hook") => {
190
- const prefixes = format === "hook" ? hookPrefixes : eventPrefixes;
191
- const builder = prefixes[toolName];
192
- if (builder) return builder(toolInput);
193
- return format === "hook" ? `${toolName}: ${JSON.stringify(toolInput).slice(0, 200)}` : `${toolName}: done`;
194
- };
195
- var TOOL_TARGET_MAX_LENGTH = 80;
196
- var deriveCommandHead = (command) => {
197
- if (typeof command !== "string") return void 0;
198
- const head = command.trim().split(/\s+/).slice(0, 2).join(" ");
199
- return head ? head.slice(0, TOOL_TARGET_MAX_LENGTH) : void 0;
200
- };
201
- var deriveToolTarget = (toolName, toolInput) => {
202
- if (toolName === "Bash") {
203
- return deriveCommandHead(toolInput.command);
204
- }
205
- if (toolName === "Edit" || toolName === "Write") {
206
- const filePath = toolInput.file_path;
207
- if (typeof filePath !== "string") return void 0;
208
- const separator = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));
209
- const base = filePath.slice(separator + 1);
210
- const dot = base.lastIndexOf(".");
211
- if (dot <= 0) return void 0;
212
- return base.slice(dot).slice(0, TOOL_TARGET_MAX_LENGTH);
213
- }
214
- return void 0;
215
- };
216
- var RECEIPT_TARGET_MAX_LENGTH = 256;
217
- var isToolResultError = (toolResult) => {
218
- try {
219
- return Boolean(toolResult && ("error" in toolResult || "is_error" in toolResult));
220
- } catch {
221
- return false;
222
- }
223
- };
224
- var relativizeReceiptPath = (filePath, cwd) => {
225
- if (!cwd || !isAbsolute(filePath)) return filePath;
226
- return relative(cwd, filePath);
227
- };
228
- var deriveReceiptMeta = (toolName, toolInput, toolResult, cwd) => {
229
- try {
230
- const ok = !isToolResultError(toolResult);
231
- if (toolName === "Edit" || toolName === "Write") {
232
- const filePath = toolInput.file_path;
233
- if (typeof filePath !== "string" || !filePath) return void 0;
234
- return {
235
- kind: toolName === "Edit" ? "edit" : "write",
236
- target: relativizeReceiptPath(filePath, cwd).slice(0, RECEIPT_TARGET_MAX_LENGTH),
237
- ok
238
- };
239
- }
240
- if (toolName === "Bash") {
241
- const head = deriveCommandHead(toolInput.command);
242
- if (!head) return void 0;
243
- return {
244
- kind: head === "git commit" ? "commit" : "bash",
245
- target: head,
246
- ok
247
- };
248
- }
249
- return void 0;
250
- } catch {
251
- return void 0;
252
- }
253
- };
254
-
255
- // src/identity.ts
256
- import { createHash as createHash2 } from "crypto";
257
- import { hostname } from "os";
258
- var deriveMachineId = (host) => createHash2("sha256").update(host).digest("hex").slice(0, 8);
259
- var getMachineId = () => deriveMachineId(hostname());
260
-
261
- // src/pending.ts
262
- import { join as join2 } from "path";
263
- import { tmpdir as tmpdir2 } from "os";
264
- import { existsSync as existsSync2, mkdirSync, writeFileSync as writeFileSync2, readdirSync, unlinkSync, rmSync, statSync } from "fs";
265
- var PENDING_DIR = join2(tmpdir2(), "pushary-pending");
266
- var DEFAULT_SESSION = "_no_session";
267
- var GRACE_MS = 10 * 60 * 1e3;
268
- var sanitize = (sessionId) => sessionId.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 128) || DEFAULT_SESSION;
269
- var dirFor = (sessionId) => join2(PENDING_DIR, sanitize(sessionId));
270
- var isDefaultSession = (sessionId) => sanitize(sessionId) === DEFAULT_SESSION;
271
- var savePendingQuestion = (sessionId, correlationId) => {
272
- const dir = dirFor(sessionId);
273
- if (!existsSync2(dir)) mkdirSync(dir, { recursive: true });
274
- writeFileSync2(join2(dir, correlationId), "", "utf-8");
275
- };
276
- var listPendingQuestions = (sessionId) => {
277
- const dir = dirFor(sessionId);
278
- let files;
279
- try {
280
- files = readdirSync(dir);
281
- } catch {
282
- return [];
283
- }
284
- if (!isDefaultSession(sessionId)) return files;
285
- const cutoff = Date.now() - GRACE_MS;
286
- return files.filter((name) => {
287
- try {
288
- return statSync(join2(dir, name)).mtimeMs < cutoff;
289
- } catch {
290
- return false;
291
- }
292
- });
293
- };
294
- var removePendingQuestion = (sessionId, correlationId) => {
295
- try {
296
- unlinkSync(join2(dirFor(sessionId), correlationId));
297
- } catch {
298
- }
299
- };
300
- var removePendingSession = (sessionId) => {
301
- try {
302
- rmSync(dirFor(sessionId), { recursive: true, force: true });
303
- } catch {
304
- }
305
- };
306
-
307
- export {
308
- isPolicyConfig,
309
- askUser,
310
- waitForAnswer,
311
- cancelQuestion,
312
- sendNotification,
313
- getPolicy,
314
- resolvePolicy,
315
- fetchModeState,
316
- fetchModeOverride,
317
- describeToolCall,
318
- deriveToolTarget,
319
- isToolResultError,
320
- deriveReceiptMeta,
321
- getMachineId,
322
- DEFAULT_SESSION,
323
- isDefaultSession,
324
- savePendingQuestion,
325
- listPendingQuestions,
326
- removePendingQuestion,
327
- removePendingSession
328
- };
@@ -1,99 +0,0 @@
1
- import {
2
- cancelQuestion,
3
- describeToolCall,
4
- listPendingQuestions,
5
- removePendingQuestion
6
- } from "./chunk-7PTU7TGE.js";
7
- import {
8
- withRetry
9
- } from "./chunk-3MIR7ODJ.js";
10
- import {
11
- getApiKey,
12
- getBaseUrl
13
- } from "./chunk-VUNL35KE.js";
14
-
15
- // src/events.ts
16
- import { hostname } from "os";
17
- import { basename } from "path";
18
- var cleanupPendingQuestions = async () => {
19
- try {
20
- const files = listPendingQuestions();
21
- const apiKey = getApiKey();
22
- for (const correlationId of files) {
23
- try {
24
- await cancelQuestion(apiKey, correlationId);
25
- } catch {
26
- }
27
- removePendingQuestion(correlationId);
28
- }
29
- } catch {
30
- }
31
- };
32
- var reportEvent = async (event) => {
33
- const apiKey = getApiKey();
34
- const baseUrl = getBaseUrl();
35
- await withRetry(async () => {
36
- await fetch(`${baseUrl}/api/agent/event`, {
37
- method: "POST",
38
- headers: {
39
- "Content-Type": "application/json",
40
- "Authorization": `Bearer ${apiKey}`
41
- },
42
- body: JSON.stringify({
43
- ...event,
44
- machineId: event.machineId ?? hostname()
45
- }),
46
- signal: AbortSignal.timeout(1e4)
47
- });
48
- }, { maxAttempts: 2, baseDelayMs: 300 });
49
- };
50
- var handlePostToolUse = async (input) => {
51
- try {
52
- const projectName = basename(input.cwd ?? process.cwd());
53
- const action = describeToolCall(input.tool_name, input.tool_input, "event");
54
- const isError = input.tool_result && ("error" in input.tool_result || "is_error" in input.tool_result);
55
- await Promise.allSettled([
56
- cleanupPendingQuestions(),
57
- reportEvent({
58
- event: isError ? "tool_error" : "tool_complete",
59
- agentType: "claude_code",
60
- agentName: `Claude Code - ${projectName}`,
61
- action,
62
- error: isError ? String(input.tool_result?.error ?? input.tool_result?.stderr ?? "").slice(0, 500) : void 0
63
- })
64
- ]);
65
- } catch {
66
- }
67
- };
68
- var handleStop = async (input) => {
69
- try {
70
- const projectName = basename(input.cwd ?? process.cwd());
71
- await reportEvent({
72
- event: "session_end",
73
- agentType: "claude_code",
74
- agentName: `Claude Code - ${projectName}`,
75
- action: "Session ended"
76
- });
77
- } catch {
78
- }
79
- };
80
- var handleNotification = async (input) => {
81
- try {
82
- const projectName = basename(input.cwd ?? process.cwd());
83
- await reportEvent({
84
- event: input.type === "error" ? "error" : "notification",
85
- agentType: "claude_code",
86
- agentName: `Claude Code - ${projectName}`,
87
- action: input.title ?? input.message ?? "Notification",
88
- error: input.type === "error" ? input.message : void 0
89
- });
90
- } catch {
91
- }
92
- };
93
-
94
- export {
95
- reportEvent,
96
- handlePostToolUse,
97
- handleStop,
98
- handleNotification
99
- };
@@ -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
- };