@pushary/agent-hooks 0.22.0 → 0.24.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 (91) 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-codex-hook.js +2 -4
  5. package/dist/bin/pushary-codex.js +1 -2
  6. package/dist/bin/pushary-doctor.js +2 -2
  7. package/dist/bin/pushary-gemini-hook.js +2 -4
  8. package/dist/bin/pushary-hook.js +2 -3
  9. package/dist/bin/pushary-post-hook.js +1 -2
  10. package/dist/bin/pushary-prompt-hook.js +1 -2
  11. package/dist/bin/pushary-setup.js +39 -3
  12. package/dist/bin/pushary-stop-hook.js +1 -2
  13. package/dist/{chunk-BHAMEPOP.js → chunk-JPRRYC5X.js} +5 -0
  14. package/dist/{chunk-5LTQNC7R.js → chunk-OQZH5PVA.js} +242 -33
  15. package/dist/{chunk-3LC4YUMA.js → chunk-U4SSWRVM.js} +1 -1
  16. package/dist/src/index.d.ts +15 -10
  17. package/dist/src/index.js +2 -3
  18. package/package.json +1 -1
  19. package/dist/chunk-22CV7V7A.js +0 -38
  20. package/dist/chunk-2BE2IPMO.js +0 -315
  21. package/dist/chunk-2CRLBMOX.js +0 -244
  22. package/dist/chunk-2HMNOZPY.js +0 -109
  23. package/dist/chunk-2I6DLXJN.js +0 -219
  24. package/dist/chunk-2Q6XPZ4Q.js +0 -395
  25. package/dist/chunk-3MIR7ODJ.js +0 -112
  26. package/dist/chunk-3QZESA66.js +0 -222
  27. package/dist/chunk-4Z4MB37G.js +0 -96
  28. package/dist/chunk-5GFUI5N6.js +0 -132
  29. package/dist/chunk-5JEDLXEC.js +0 -99
  30. package/dist/chunk-5QHQVXWN.js +0 -174
  31. package/dist/chunk-6A3WCJO2.js +0 -416
  32. package/dist/chunk-6QWFMVCD.js +0 -328
  33. package/dist/chunk-6SRXMZAN.js +0 -99
  34. package/dist/chunk-7PTU7TGE.js +0 -96
  35. package/dist/chunk-AB4KX4XT.js +0 -109
  36. package/dist/chunk-AC4UYAGX.js +0 -136
  37. package/dist/chunk-ACE77TKQ.js +0 -328
  38. package/dist/chunk-BYNYYZWW.js +0 -412
  39. package/dist/chunk-C5TFTNHG.js +0 -244
  40. package/dist/chunk-CH53PBQN.js +0 -265
  41. package/dist/chunk-DF3BM6BF.js +0 -195
  42. package/dist/chunk-DKZVKEOW.js +0 -175
  43. package/dist/chunk-EMPL27ZV.js +0 -96
  44. package/dist/chunk-EQJXMEIR.js +0 -175
  45. package/dist/chunk-FXYTRZHC.js +0 -177
  46. package/dist/chunk-GTJGZBTQ.js +0 -328
  47. package/dist/chunk-HJMFYDWY.js +0 -222
  48. package/dist/chunk-HRQEECB6.js +0 -315
  49. package/dist/chunk-HWEMAAOY.js +0 -370
  50. package/dist/chunk-IBWCHA5M.js +0 -10
  51. package/dist/chunk-KTM4ZQ3W.js +0 -96
  52. package/dist/chunk-KTP2EPVB.js +0 -27
  53. package/dist/chunk-KYARP7KP.js +0 -97
  54. package/dist/chunk-M2N5DYWN.js +0 -247
  55. package/dist/chunk-M5F2L4KF.js +0 -177
  56. package/dist/chunk-M6S3M6E3.js +0 -244
  57. package/dist/chunk-N7VXDBQU.js +0 -6
  58. package/dist/chunk-O6A5RHWY.js +0 -122
  59. package/dist/chunk-ODUXELPM.js +0 -219
  60. package/dist/chunk-OF5WIOYS.js +0 -129
  61. package/dist/chunk-OP4QAN23.js +0 -99
  62. package/dist/chunk-P4JH2Q7Z.js +0 -102
  63. package/dist/chunk-PMD5JSV3.js +0 -242
  64. package/dist/chunk-PSSHNBEL.js +0 -177
  65. package/dist/chunk-QEPRH7JB.js +0 -315
  66. package/dist/chunk-QRXWPZKN.js +0 -308
  67. package/dist/chunk-QY4L6XHN.js +0 -384
  68. package/dist/chunk-RNWPCELY.js +0 -176
  69. package/dist/chunk-RSHN2AQ7.js +0 -29
  70. package/dist/chunk-RZLVE57X.js +0 -38
  71. package/dist/chunk-SDCIKREA.js +0 -241
  72. package/dist/chunk-SDREQWNI.js +0 -175
  73. package/dist/chunk-SH26ZOHU.js +0 -159
  74. package/dist/chunk-TRLBBLSS.js +0 -176
  75. package/dist/chunk-U6OXZPYC.js +0 -384
  76. package/dist/chunk-UIBTFZUD.js +0 -314
  77. package/dist/chunk-USUCPCUC.js +0 -156
  78. package/dist/chunk-V4GLWPD7.js +0 -174
  79. package/dist/chunk-VC6U3QGF.js +0 -142
  80. package/dist/chunk-VIST7ACL.js +0 -88
  81. package/dist/chunk-VUNL35KE.js +0 -16
  82. package/dist/chunk-VWBNI4SC.js +0 -174
  83. package/dist/chunk-W5KRWUNE.js +0 -262
  84. package/dist/chunk-WCGKLHCL.js +0 -154
  85. package/dist/chunk-WNXGIEX7.js +0 -219
  86. package/dist/chunk-XPVSZIA3.js +0 -315
  87. package/dist/chunk-Y633ZIJF.js +0 -384
  88. package/dist/chunk-YCL4GUFR.js +0 -222
  89. package/dist/chunk-YTMKB44I.js +0 -220
  90. package/dist/chunk-ZWBS3T7Q.js +0 -244
  91. package/dist/pushary-mode-T7XOPI6Z.js +0 -83
@@ -1,159 +0,0 @@
1
- import {
2
- DEFAULT_SESSION,
3
- cancelQuestion,
4
- deriveReceiptMeta,
5
- describeToolCall,
6
- getMachineId,
7
- isDefaultSession,
8
- isPolicyConfig,
9
- isToolResultError,
10
- listPendingQuestions,
11
- removePendingQuestion,
12
- removePendingSession,
13
- resolvePolicy
14
- } from "./chunk-QRXWPZKN.js";
15
- import {
16
- withRetry
17
- } from "./chunk-3MIR7ODJ.js";
18
- import {
19
- getApiKey,
20
- getBaseUrl
21
- } from "./chunk-VUNL35KE.js";
22
-
23
- // src/events.ts
24
- import { basename, join } from "path";
25
- import { createHash } from "crypto";
26
- import { existsSync, readFileSync } from "fs";
27
- import { tmpdir } from "os";
28
- var cleanupPendingQuestions = async (sessionId) => {
29
- try {
30
- const files = listPendingQuestions(sessionId);
31
- const apiKey = getApiKey();
32
- for (const correlationId of files) {
33
- try {
34
- await cancelQuestion(apiKey, correlationId);
35
- } catch {
36
- }
37
- removePendingQuestion(sessionId, correlationId);
38
- }
39
- if (!isDefaultSession(sessionId)) removePendingSession(sessionId);
40
- } catch {
41
- }
42
- };
43
- var CLAUDE_CODE_AGENT = { type: "claude_code", label: "Claude Code" };
44
- var POLICY_CACHE_TTL_MS = 5 * 60 * 1e3;
45
- var readFreshCachedPolicy = (apiKey) => {
46
- const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
47
- const path = join(tmpdir(), `pushary-policy-${hash}.json`);
48
- if (!existsSync(path)) return null;
49
- const cached = JSON.parse(readFileSync(path, "utf-8"));
50
- if (!isPolicyConfig(cached)) return null;
51
- if (!cached._cachedAt || Date.now() - cached._cachedAt >= POLICY_CACHE_TTL_MS) return null;
52
- return cached;
53
- };
54
- var deriveDecisionSource = (toolName, toolInput) => {
55
- try {
56
- const policy = readFreshCachedPolicy(getApiKey());
57
- if (!policy) return void 0;
58
- const resolved = resolvePolicy(policy, toolName, null, toolInput);
59
- if (resolved.timeoutSeconds === 0 && resolved.timeoutAction === "approve") return "policy_auto";
60
- if (resolved.mode === "push_only" || resolved.mode === "push_first") return "human";
61
- return "terminal";
62
- } catch {
63
- return void 0;
64
- }
65
- };
66
- var reportEvent = async (event, options = {}) => {
67
- const apiKey = getApiKey();
68
- const baseUrl = getBaseUrl();
69
- await withRetry(async () => {
70
- await fetch(`${baseUrl}/api/agent/event`, {
71
- method: "POST",
72
- headers: {
73
- "Content-Type": "application/json",
74
- "Authorization": `Bearer ${apiKey}`
75
- },
76
- body: JSON.stringify({
77
- ...event,
78
- machineId: event.machineId ?? getMachineId()
79
- }),
80
- signal: AbortSignal.timeout(options.timeoutMs ?? 1e4)
81
- });
82
- }, { maxAttempts: options.maxAttempts ?? 2, baseDelayMs: 300 });
83
- };
84
- var handlePostToolUse = async (input, agent = CLAUDE_CODE_AGENT) => {
85
- try {
86
- const projectName = basename(input.cwd ?? process.cwd());
87
- const action = describeToolCall(input.tool_name, input.tool_input, "event");
88
- const isError = isToolResultError(input.tool_result);
89
- const receiptsEnabled = process.env.PUSHARY_RECEIPTS !== "off";
90
- await Promise.allSettled([
91
- cleanupPendingQuestions(input.session_id || DEFAULT_SESSION),
92
- reportEvent({
93
- event: isError ? "tool_error" : "tool_complete",
94
- agentType: agent.type,
95
- agentName: `${agent.label} - ${projectName}`,
96
- action,
97
- sessionId: input.session_id,
98
- error: isError ? String(input.tool_result?.error ?? input.tool_result?.stderr ?? "").slice(0, 500) : void 0,
99
- decisionSource: deriveDecisionSource(input.tool_name, input.tool_input),
100
- meta: receiptsEnabled ? deriveReceiptMeta(input.tool_name, input.tool_input, input.tool_result, input.cwd ?? process.cwd()) : void 0
101
- })
102
- ]);
103
- } catch {
104
- }
105
- };
106
- var TASK_TITLE_MAX_LENGTH = 120;
107
- var handleUserPrompt = async (input, agent = CLAUDE_CODE_AGENT) => {
108
- try {
109
- const projectName = basename(input.cwd ?? process.cwd());
110
- const titlesEnabled = process.env.PUSHARY_TASK_TITLES !== "off";
111
- const taskTitle = titlesEnabled ? input.prompt?.replace(/\s+/g, " ").trim().slice(0, TASK_TITLE_MAX_LENGTH) || void 0 : void 0;
112
- await reportEvent({
113
- event: "user_prompt",
114
- agentType: agent.type,
115
- agentName: `${agent.label} - ${projectName}`,
116
- sessionId: input.session_id,
117
- taskTitle
118
- }, { maxAttempts: 1, timeoutMs: 800 });
119
- } catch {
120
- }
121
- };
122
- var handleStop = async (input, agent = CLAUDE_CODE_AGENT) => {
123
- try {
124
- const projectName = basename(input.cwd ?? process.cwd());
125
- await Promise.allSettled([
126
- cleanupPendingQuestions(input.session_id || DEFAULT_SESSION),
127
- reportEvent({
128
- event: "session_end",
129
- agentType: agent.type,
130
- agentName: `${agent.label} - ${projectName}`,
131
- action: "Session ended",
132
- sessionId: input.session_id
133
- })
134
- ]);
135
- } catch {
136
- }
137
- };
138
- var handleNotification = async (input) => {
139
- try {
140
- const projectName = basename(input.cwd ?? process.cwd());
141
- await reportEvent({
142
- event: input.type === "error" ? "error" : "notification",
143
- agentType: "claude_code",
144
- agentName: `Claude Code - ${projectName}`,
145
- action: input.title ?? input.message ?? "Notification",
146
- sessionId: input.session_id,
147
- error: input.type === "error" ? input.message : void 0
148
- });
149
- } catch {
150
- }
151
- };
152
-
153
- export {
154
- reportEvent,
155
- handlePostToolUse,
156
- handleUserPrompt,
157
- handleStop,
158
- handleNotification
159
- };
@@ -1,176 +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-QRXWPZKN.js";
14
- import {
15
- getApiKey
16
- } from "./chunk-VUNL35KE.js";
17
-
18
- // src/hook.ts
19
- import { basename } from "path";
20
- var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
21
- var allow = () => ({
22
- hookSpecificOutput: {
23
- hookEventName: "PreToolUse",
24
- permissionDecision: "allow"
25
- }
26
- });
27
- var deny = (reason) => ({
28
- hookSpecificOutput: {
29
- hookEventName: "PreToolUse",
30
- permissionDecision: "deny",
31
- permissionDecisionReason: reason
32
- }
33
- });
34
- var ask = (reason) => ({
35
- hookSpecificOutput: {
36
- hookEventName: "PreToolUse",
37
- permissionDecision: "ask",
38
- ...reason ? { permissionDecisionReason: reason } : {}
39
- }
40
- });
41
- var pollForAnswer = async (apiKey, correlationId, deadlineMs, pollInterval = 2e3) => {
42
- while (Date.now() < deadlineMs) {
43
- const remaining = Math.min(Math.max(deadlineMs - Date.now(), 1e3), 3e4);
44
- let answer;
45
- try {
46
- answer = await waitForAnswer(apiKey, correlationId, remaining);
47
- } catch {
48
- if (Date.now() + pollInterval >= deadlineMs) break;
49
- await sleep(pollInterval);
50
- continue;
51
- }
52
- if (answer.answered) return answer;
53
- if (Date.now() + pollInterval >= deadlineMs) break;
54
- await sleep(pollInterval);
55
- }
56
- return { answered: false };
57
- };
58
- var handlePushOnly = async (apiKey, description, projectName, timeoutSeconds, timeoutAction, sessionId, machineId, toolName, toolTarget) => {
59
- let result;
60
- try {
61
- result = await askUser(apiKey, {
62
- question: `Allow ${description}?`,
63
- type: "confirm",
64
- context: `Agent wants to run this in ${projectName}`,
65
- agentName: `Claude Code - ${projectName}`,
66
- sessionId,
67
- machineId,
68
- toolName,
69
- toolTarget
70
- });
71
- } catch {
72
- switch (timeoutAction) {
73
- case "approve":
74
- return allow();
75
- case "deny":
76
- return deny("Push notification failed, denying per policy");
77
- default:
78
- return ask("Push notification failed, asking in terminal");
79
- }
80
- }
81
- const deadline = Date.now() + timeoutSeconds * 1e3;
82
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline);
83
- if (answer.answered) {
84
- return answer.value === "yes" ? allow() : deny("Denied via push notification");
85
- }
86
- switch (timeoutAction) {
87
- case "approve":
88
- return allow();
89
- case "deny":
90
- return deny("No response within timeout");
91
- default:
92
- return ask("No push response, asking in terminal");
93
- }
94
- };
95
- var handleTerminalOnly = () => {
96
- return ask();
97
- };
98
- var handlePushFirst = async (apiKey, description, projectName, pushFirstSeconds, sessionId, machineId, toolName, toolTarget) => {
99
- let result;
100
- try {
101
- result = await askUser(apiKey, {
102
- question: `Allow ${description}?`,
103
- type: "confirm",
104
- context: `Agent wants to run this in ${projectName}`,
105
- agentName: `Claude Code - ${projectName}`,
106
- sessionId,
107
- machineId,
108
- toolName,
109
- toolTarget
110
- });
111
- } catch {
112
- return ask("Push notification failed, asking in terminal");
113
- }
114
- const deadline = Date.now() + pushFirstSeconds * 1e3;
115
- const answer = await pollForAnswer(apiKey, result.correlationId, deadline, 1500);
116
- if (answer.answered) {
117
- return answer.value === "yes" ? allow() : deny("Denied via push notification");
118
- }
119
- savePendingQuestion(sessionId || DEFAULT_SESSION, result.correlationId);
120
- return ask("Sent as push notification. You can also approve here.");
121
- };
122
- var handleNotifyOnly = async (apiKey, description, projectName, sessionId, machineId) => {
123
- try {
124
- await sendNotification(apiKey, {
125
- title: "Agent needs approval",
126
- body: description,
127
- agentName: `Claude Code - ${projectName}`,
128
- sessionId,
129
- machineId
130
- });
131
- } catch {
132
- }
133
- return ask();
134
- };
135
- var handlePreToolUse = async (input) => {
136
- try {
137
- const apiKey = getApiKey();
138
- const [policy, modeState] = await Promise.all([
139
- getPolicy(apiKey),
140
- fetchModeState(apiKey, input.session_id)
141
- ]);
142
- if (modeState.kill) {
143
- return deny("Stopped by user \u2014 this agent was halted from Pushary");
144
- }
145
- const toolPolicy = resolvePolicy(policy, input.tool_name, modeState.mode, input.tool_input);
146
- if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") {
147
- return allow();
148
- }
149
- if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "deny") {
150
- return deny(`Denied by policy for ${toolPolicy.tool}`);
151
- }
152
- const description = describeToolCall(input.tool_name, input.tool_input, "hook");
153
- const projectName = basename(input.cwd ?? process.cwd());
154
- const sessionId = input.session_id;
155
- const machineId = getMachineId();
156
- const toolTarget = deriveToolTarget(input.tool_name, input.tool_input);
157
- switch (toolPolicy.mode) {
158
- case "push_only":
159
- return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction, sessionId, machineId, input.tool_name, toolTarget);
160
- case "terminal_only":
161
- return handleTerminalOnly();
162
- case "push_first":
163
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget);
164
- case "notify_only":
165
- return handleNotifyOnly(apiKey, description, projectName, sessionId, machineId);
166
- default:
167
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget);
168
- }
169
- } catch {
170
- return ask("Pushary unavailable, falling back to terminal approval");
171
- }
172
- };
173
-
174
- export {
175
- handlePreToolUse
176
- };