@pushary/agent-hooks 0.14.2 → 0.14.4
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.
- package/dist/bin/pushary-clean.js +1 -1
- package/dist/bin/pushary-codex-hook.js +4 -4
- package/dist/bin/pushary-codex.js +4 -4
- package/dist/bin/pushary-doctor.js +23 -9
- package/dist/bin/pushary-hook.js +4 -4
- package/dist/bin/pushary-mode.js +1 -1
- package/dist/bin/pushary-post-hook.js +4 -4
- package/dist/bin/pushary-prompt-hook.js +4 -4
- package/dist/bin/pushary-setup.js +84 -35
- package/dist/bin/pushary-stop-hook.js +4 -4
- package/dist/chunk-3QZESA66.js +222 -0
- package/dist/chunk-DWED7BS3.js +112 -0
- package/dist/chunk-HRQEECB6.js +315 -0
- package/dist/chunk-NKXSILEW.js +29 -0
- package/dist/chunk-VC6U3QGF.js +142 -0
- package/dist/chunk-VWBNI4SC.js +174 -0
- package/dist/src/index.js +5 -5
- package/package.json +2 -2
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_SESSION,
|
|
3
|
+
askUser,
|
|
4
|
+
deriveToolTarget,
|
|
5
|
+
describeToolCall,
|
|
6
|
+
fetchModeState,
|
|
7
|
+
getMachineId,
|
|
8
|
+
getPolicy,
|
|
9
|
+
resolvePolicy,
|
|
10
|
+
savePendingQuestion,
|
|
11
|
+
sendNotification,
|
|
12
|
+
waitForAnswer
|
|
13
|
+
} from "./chunk-HRQEECB6.js";
|
|
14
|
+
import {
|
|
15
|
+
getApiKey
|
|
16
|
+
} from "./chunk-NKXSILEW.js";
|
|
17
|
+
|
|
18
|
+
// src/hook.ts
|
|
19
|
+
import { basename } from "path";
|
|
20
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
21
|
+
var 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 modeState = await fetchModeState(apiKey, input.session_id);
|
|
139
|
+
const policy = await getPolicy(apiKey, modeState.policyVersion);
|
|
140
|
+
if (modeState.kill) {
|
|
141
|
+
return deny("Stopped by user \u2014 this agent was halted from Pushary");
|
|
142
|
+
}
|
|
143
|
+
const toolPolicy = resolvePolicy(policy, input.tool_name, modeState.mode, input.tool_input);
|
|
144
|
+
if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") {
|
|
145
|
+
return allow();
|
|
146
|
+
}
|
|
147
|
+
if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "deny") {
|
|
148
|
+
return deny(`Denied by policy for ${toolPolicy.tool}`);
|
|
149
|
+
}
|
|
150
|
+
const description = describeToolCall(input.tool_name, input.tool_input, "hook");
|
|
151
|
+
const projectName = basename(input.cwd ?? process.cwd());
|
|
152
|
+
const sessionId = input.session_id;
|
|
153
|
+
const machineId = getMachineId();
|
|
154
|
+
const toolTarget = deriveToolTarget(input.tool_name, input.tool_input);
|
|
155
|
+
switch (toolPolicy.mode) {
|
|
156
|
+
case "push_only":
|
|
157
|
+
return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction, sessionId, machineId, input.tool_name, toolTarget);
|
|
158
|
+
case "terminal_only":
|
|
159
|
+
return handleTerminalOnly();
|
|
160
|
+
case "push_first":
|
|
161
|
+
return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget);
|
|
162
|
+
case "notify_only":
|
|
163
|
+
return handleNotifyOnly(apiKey, description, projectName, sessionId, machineId);
|
|
164
|
+
default:
|
|
165
|
+
return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget);
|
|
166
|
+
}
|
|
167
|
+
} catch {
|
|
168
|
+
return ask("Pushary unavailable, falling back to terminal approval");
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export {
|
|
173
|
+
handlePreToolUse
|
|
174
|
+
};
|
package/dist/src/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
handlePreToolUse
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-VWBNI4SC.js";
|
|
4
4
|
import {
|
|
5
5
|
handleNotification,
|
|
6
6
|
handlePostToolUse,
|
|
7
7
|
handleStop,
|
|
8
8
|
reportEvent
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-3QZESA66.js";
|
|
10
10
|
import {
|
|
11
11
|
askUser,
|
|
12
12
|
cancelQuestion,
|
|
@@ -15,13 +15,13 @@ import {
|
|
|
15
15
|
getPolicy,
|
|
16
16
|
resolvePolicy,
|
|
17
17
|
waitForAnswer
|
|
18
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-HRQEECB6.js";
|
|
19
19
|
import "../chunk-22CV7V7A.js";
|
|
20
|
-
import "../chunk-
|
|
20
|
+
import "../chunk-DWED7BS3.js";
|
|
21
21
|
import {
|
|
22
22
|
getApiKey,
|
|
23
23
|
getBaseUrl
|
|
24
|
-
} from "../chunk-
|
|
24
|
+
} from "../chunk-NKXSILEW.js";
|
|
25
25
|
export {
|
|
26
26
|
askUser,
|
|
27
27
|
cancelQuestion,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushary/agent-hooks",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.4",
|
|
4
4
|
"description": "Permission hooks for AI coding agents: route tool approvals through Pushary push notifications",
|
|
5
5
|
"author": "Pushary <business@pushary.com>",
|
|
6
6
|
"homepage": "https://pushary.com",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "node scripts/bundle-plugin.mjs && tsup",
|
|
36
36
|
"dev": "tsup --watch",
|
|
37
|
-
"test": "bun test src/api.test.ts && bun test src/claude-config.test.ts && bun test src/mcp-http.test.ts && bun test src/retry.test.ts && bun test src/validate.test.ts && bun test src/policy.test.ts && bun test src/npm.test.ts && bun test src/identity.test.ts && bun test src/pending.test.ts && bun test src/events.test.ts && bun test src/describe.test.ts && bun test src/suggestions.test.ts && bun test src/hook.test.ts && bun test src/codex-adapter.test.ts && bun test src/codex-config.test.ts"
|
|
37
|
+
"test": "bun test src/api.test.ts && bun test src/claude-config.test.ts && bun test src/config.test.ts && bun test src/mcp-http.test.ts && bun test src/retry.test.ts && bun test src/validate.test.ts && bun test src/policy.test.ts && bun test src/npm.test.ts && bun test src/identity.test.ts && bun test src/pending.test.ts && bun test src/events.test.ts && bun test src/describe.test.ts && bun test src/suggestions.test.ts && bun test src/hook.test.ts && bun test src/codex-adapter.test.ts && bun test src/codex-config.test.ts"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@inquirer/prompts": "^8.4.2",
|