@pushary/agent-hooks 0.4.6 → 0.5.1
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 +2 -2
- package/dist/bin/pushary-codex.js +5 -6
- package/dist/bin/pushary-doctor.js +18 -2
- package/dist/bin/pushary-hook.js +3 -4
- package/dist/bin/pushary-post-hook.js +3 -2
- package/dist/bin/pushary-setup.js +121 -15
- package/dist/bin/pushary-stop-hook.js +3 -2
- package/dist/chunk-DF3BM6BF.js +195 -0
- package/dist/{chunk-M5SRSBLS.js → chunk-KTP2EPVB.js} +6 -2
- package/dist/{chunk-EQE6Z4YQ.js → chunk-P4JH2Q7Z.js} +26 -1
- package/dist/{chunk-RJKW6LLC.js → chunk-VIST7ACL.js} +13 -3
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +8 -9
- package/package.json +1 -1
- package/dist/chunk-4TQW4K6T.js +0 -136
- package/dist/chunk-VUNL35KE.js +0 -16
|
@@ -98,11 +98,11 @@ var main = async () => {
|
|
|
98
98
|
const cleaned = [];
|
|
99
99
|
let skipping = false;
|
|
100
100
|
for (const line of lines) {
|
|
101
|
-
if (line.trim()
|
|
101
|
+
if (/^\[mcp_servers\.pushary(?:\.|]$)/.test(line.trim())) {
|
|
102
102
|
skipping = true;
|
|
103
103
|
continue;
|
|
104
104
|
}
|
|
105
|
-
if (skipping &&
|
|
105
|
+
if (skipping && line.startsWith("[") && !/^\[mcp_servers\.pushary/.test(line.trim())) {
|
|
106
106
|
skipping = false;
|
|
107
107
|
}
|
|
108
108
|
if (skipping) continue;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
reportEvent
|
|
4
|
+
} from "../chunk-P4JH2Q7Z.js";
|
|
2
5
|
import {
|
|
3
6
|
askUser,
|
|
4
7
|
waitForAnswer
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-RJKW6LLC.js";
|
|
7
|
-
import {
|
|
8
|
-
reportEvent
|
|
9
|
-
} from "../chunk-EQE6Z4YQ.js";
|
|
8
|
+
} from "../chunk-KTP2EPVB.js";
|
|
10
9
|
import {
|
|
11
10
|
getApiKey
|
|
12
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-VIST7ACL.js";
|
|
13
12
|
|
|
14
13
|
// bin/pushary-codex.ts
|
|
15
14
|
import { hostname } from "os";
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
callMcpTool,
|
|
4
4
|
sendMcpRequest
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-VUNL35KE.js";
|
|
5
|
+
} from "../chunk-VIST7ACL.js";
|
|
7
6
|
|
|
8
7
|
// bin/pushary-doctor.ts
|
|
9
8
|
import { existsSync, readFileSync } from "fs";
|
|
@@ -69,6 +68,23 @@ var main = async () => {
|
|
|
69
68
|
} else {
|
|
70
69
|
check(false, "Claude Code: settings.json", "not found");
|
|
71
70
|
}
|
|
71
|
+
const codexConfigPath = join(homedir(), ".codex", "config.toml");
|
|
72
|
+
if (existsSync(codexConfigPath)) {
|
|
73
|
+
const codexConfig = readFileSync(codexConfigPath, "utf-8");
|
|
74
|
+
const hasPusharyMcp = codexConfig.includes("[mcp_servers.pushary]");
|
|
75
|
+
check(hasPusharyMcp, "Codex: MCP server configured");
|
|
76
|
+
if (hasPusharyMcp) {
|
|
77
|
+
const hasAutoApprove = codexConfig.includes('default_tools_approval_mode = "approve"');
|
|
78
|
+
check(hasAutoApprove, "Codex: tools auto-allowed", hasAutoApprove ? 'default_tools_approval_mode = "approve"' : "missing \u2014 MCP calls will prompt for approval");
|
|
79
|
+
const hasPerToolOverrides = /\[mcp_servers\.pushary\.tools\./.test(codexConfig);
|
|
80
|
+
if (hasPerToolOverrides) {
|
|
81
|
+
console.log(` ${warn} Codex: per-tool approval overrides detected ${dim("(redundant with default_tools_approval_mode)")}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
check(codexConfig.includes("pushary-codex"), "Codex: notify handler configured");
|
|
85
|
+
const codexSkillPath = join(homedir(), ".codex", "skills", "pushary", "SKILL.md");
|
|
86
|
+
check(existsSync(codexSkillPath), "Codex: skill installed");
|
|
87
|
+
}
|
|
72
88
|
check(existsSync(SKILL_PATH), "Skill installed", existsSync(SKILL_PATH) ? SKILL_PATH : "not found");
|
|
73
89
|
let globalVersion = "";
|
|
74
90
|
try {
|
package/dist/bin/pushary-hook.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
handlePreToolUse
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-VUNL35KE.js";
|
|
4
|
+
} from "../chunk-DF3BM6BF.js";
|
|
5
|
+
import "../chunk-KTP2EPVB.js";
|
|
6
|
+
import "../chunk-VIST7ACL.js";
|
|
8
7
|
|
|
9
8
|
// bin/pushary-hook.ts
|
|
10
9
|
var main = async () => {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
handlePostToolUse
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-P4JH2Q7Z.js";
|
|
5
|
+
import "../chunk-KTP2EPVB.js";
|
|
6
|
+
import "../chunk-VIST7ACL.js";
|
|
6
7
|
|
|
7
8
|
// bin/pushary-post-hook.ts
|
|
8
9
|
var main = async () => {
|
|
@@ -146,29 +146,86 @@ var setupClaudeCode = async (apiKey) => {
|
|
|
146
146
|
console.log(` ${dim("\u2022")} Hooks: route permission approvals through push notifications`);
|
|
147
147
|
console.log(` ${dim("\u2022")} Auto-allowed tools: no permission prompts for Pushary MCP calls`);
|
|
148
148
|
};
|
|
149
|
+
var findPython310Plus = () => {
|
|
150
|
+
const candidates = ["python3.13", "python3.12", "python3.11", "python3.10", "python3", "python"];
|
|
151
|
+
for (const py of candidates) {
|
|
152
|
+
try {
|
|
153
|
+
const version = execSync(`${py} --version 2>&1`, { encoding: "utf-8", stdio: "pipe" }).trim();
|
|
154
|
+
const match = version.match(/Python (\d+)\.(\d+)/);
|
|
155
|
+
if (match && (Number(match[1]) > 3 || Number(match[1]) === 3 && Number(match[2]) >= 10)) {
|
|
156
|
+
return py;
|
|
157
|
+
}
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
};
|
|
163
|
+
var installPythonPlugin = (pythonBin) => {
|
|
164
|
+
execSync(`${pythonBin} -m pip install --upgrade hermes-plugin-pushary`, { stdio: "pipe" });
|
|
165
|
+
};
|
|
149
166
|
var setupHermes = async (_apiKey) => {
|
|
150
167
|
console.log(`
|
|
151
168
|
${bold("Setting up Hermes Agent")}
|
|
152
169
|
`);
|
|
153
|
-
|
|
170
|
+
const whichCmd = process.platform === "win32" ? "where" : "which";
|
|
171
|
+
const hasHermes = (() => {
|
|
172
|
+
try {
|
|
173
|
+
execSync(`${whichCmd} hermes`, { stdio: "ignore" });
|
|
174
|
+
return true;
|
|
175
|
+
} catch {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
})();
|
|
179
|
+
if (!hasHermes) {
|
|
180
|
+
console.log(` ${yellow("!")} Hermes CLI not found. Skipping.`);
|
|
181
|
+
console.log(` ${dim("Install Hermes and re-run setup to configure.")}`);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
154
184
|
await spinner("Installing hermes-plugin-pushary", async () => {
|
|
185
|
+
try {
|
|
186
|
+
execSync("uv pip install hermes-plugin-pushary", { stdio: "pipe" });
|
|
187
|
+
return;
|
|
188
|
+
} catch {
|
|
189
|
+
}
|
|
190
|
+
let python = findPython310Plus();
|
|
191
|
+
if (!python) {
|
|
192
|
+
if (process.platform === "darwin") {
|
|
193
|
+
try {
|
|
194
|
+
execSync("which brew", { stdio: "ignore" });
|
|
195
|
+
execSync("brew install python@3.12", { stdio: "pipe" });
|
|
196
|
+
python = findPython310Plus();
|
|
197
|
+
} catch {
|
|
198
|
+
}
|
|
199
|
+
} else if (process.platform === "linux") {
|
|
200
|
+
for (const [check2, install] of [
|
|
201
|
+
["which apt-get", "sudo apt-get update -qq && sudo apt-get install -y -qq python3 python3-pip"],
|
|
202
|
+
["which dnf", "sudo dnf install -y -q python3 python3-pip"],
|
|
203
|
+
["which yum", "sudo yum install -y -q python3 python3-pip"],
|
|
204
|
+
["which pacman", "sudo pacman -S --noconfirm python python-pip"]
|
|
205
|
+
]) {
|
|
206
|
+
try {
|
|
207
|
+
execSync(check2, { stdio: "ignore" });
|
|
208
|
+
execSync(install, { stdio: "pipe" });
|
|
209
|
+
python = findPython310Plus();
|
|
210
|
+
if (python) break;
|
|
211
|
+
} catch {
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (python) {
|
|
217
|
+
installPythonPlugin(python);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
155
220
|
for (const pip of ["pip3", "pip"]) {
|
|
156
221
|
try {
|
|
157
222
|
execSync(`${pip} install hermes-plugin-pushary`, { stdio: "pipe" });
|
|
158
|
-
pipInstalled = true;
|
|
159
223
|
return;
|
|
160
|
-
} catch
|
|
161
|
-
const msg = err instanceof Error ? err.stderr?.toString() ?? "" : "";
|
|
162
|
-
if (msg.includes("No matching distribution")) {
|
|
163
|
-
throw new Error("requires Python 3.10+ (your pip uses an older version)");
|
|
164
|
-
}
|
|
224
|
+
} catch {
|
|
165
225
|
}
|
|
166
226
|
}
|
|
167
|
-
throw new Error("
|
|
227
|
+
throw new Error("Python 3.10+ not found and could not be installed");
|
|
168
228
|
});
|
|
169
|
-
if (!pipInstalled) {
|
|
170
|
-
console.log(` ${dim(" Install Python 3.10+ and re-run setup to fix.")}`);
|
|
171
|
-
}
|
|
172
229
|
await spinner("Enabling plugin", async () => {
|
|
173
230
|
execSync("hermes plugins enable pushary", { stdio: "ignore" });
|
|
174
231
|
});
|
|
@@ -181,9 +238,10 @@ var setupCodex = async (_apiKey) => {
|
|
|
181
238
|
console.log(`
|
|
182
239
|
${bold("Setting up Codex")}
|
|
183
240
|
`);
|
|
241
|
+
const whichCmd = process.platform === "win32" ? "where" : "which";
|
|
184
242
|
const hasCodex = (() => {
|
|
185
243
|
try {
|
|
186
|
-
execSync(
|
|
244
|
+
execSync(`${whichCmd} codex`, { stdio: "ignore" });
|
|
187
245
|
return true;
|
|
188
246
|
} catch {
|
|
189
247
|
return false;
|
|
@@ -195,6 +253,7 @@ var setupCodex = async (_apiKey) => {
|
|
|
195
253
|
return;
|
|
196
254
|
}
|
|
197
255
|
await installGlobally();
|
|
256
|
+
const codexConfig = join(homedir(), ".codex", "config.toml");
|
|
198
257
|
await spinner("Adding Pushary MCP server to Codex", async () => {
|
|
199
258
|
try {
|
|
200
259
|
execSync(
|
|
@@ -204,7 +263,42 @@ var setupCodex = async (_apiKey) => {
|
|
|
204
263
|
} catch {
|
|
205
264
|
}
|
|
206
265
|
});
|
|
207
|
-
|
|
266
|
+
await spinner("Auto-allowing all Pushary tools", async () => {
|
|
267
|
+
let config = "";
|
|
268
|
+
try {
|
|
269
|
+
config = readFileSync(codexConfig, "utf-8");
|
|
270
|
+
} catch {
|
|
271
|
+
}
|
|
272
|
+
const lines = config.split("\n");
|
|
273
|
+
const cleaned = [];
|
|
274
|
+
let skippingToolSection = false;
|
|
275
|
+
for (const line of lines) {
|
|
276
|
+
if (/^\[mcp_servers\.pushary\.tools\./.test(line.trim())) {
|
|
277
|
+
skippingToolSection = true;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (skippingToolSection) {
|
|
281
|
+
if (line.startsWith("[") || line.trim() === "") {
|
|
282
|
+
skippingToolSection = false;
|
|
283
|
+
if (line.startsWith("[")) {
|
|
284
|
+
cleaned.push(line);
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
cleaned.push(line);
|
|
292
|
+
}
|
|
293
|
+
config = cleaned.join("\n");
|
|
294
|
+
if (!config.includes("default_tools_approval_mode")) {
|
|
295
|
+
config = config.replace(
|
|
296
|
+
/(\[mcp_servers\.pushary\]\n)/,
|
|
297
|
+
'$1default_tools_approval_mode = "approve"\n'
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
writeFileSync(codexConfig, config, "utf-8");
|
|
301
|
+
});
|
|
208
302
|
await spinner("Adding notify handler for Codex events", async () => {
|
|
209
303
|
const globalPrefix = execSync("npm prefix -g", { encoding: "utf-8" }).trim();
|
|
210
304
|
const pusharyCodexPath = join(globalPrefix, "bin", "pushary-codex");
|
|
@@ -225,6 +319,7 @@ notify = ["${pusharyCodexPath}"]
|
|
|
225
319
|
console.log();
|
|
226
320
|
console.log(` ${dim("What this configured:")}`);
|
|
227
321
|
console.log(` ${dim("\u2022")} MCP server: Codex can send notifications and ask questions`);
|
|
322
|
+
console.log(` ${dim("\u2022")} Auto-allowed tools: no permission prompts for Pushary MCP calls`);
|
|
228
323
|
console.log(` ${dim("\u2022")} Notify handler: captures turn completions and approval requests`);
|
|
229
324
|
};
|
|
230
325
|
var setupCursor = async (apiKey) => {
|
|
@@ -324,7 +419,7 @@ var main = async () => {
|
|
|
324
419
|
message: "Which agents do you use? " + dim("(space = toggle, enter = confirm)"),
|
|
325
420
|
choices: [
|
|
326
421
|
{ name: `Claude Code ${dim("MCP + hooks + auto-allowed tools")}`, value: "claude_code" },
|
|
327
|
-
{ name: `Codex ${dim("MCP
|
|
422
|
+
{ name: `Codex ${dim("MCP + notify handler + auto-allowed tools")}`, value: "codex" },
|
|
328
423
|
{ name: `Hermes ${dim("native plugin + auto-error notifications")}`, value: "hermes" },
|
|
329
424
|
{ name: `Cursor ${dim("MCP server")}`, value: "cursor" }
|
|
330
425
|
]
|
|
@@ -334,8 +429,19 @@ var main = async () => {
|
|
|
334
429
|
console.log(`
|
|
335
430
|
${dim("No agents selected. API key saved.")}`);
|
|
336
431
|
} else {
|
|
432
|
+
const failed = [];
|
|
337
433
|
for (const agent of agents) {
|
|
338
|
-
|
|
434
|
+
try {
|
|
435
|
+
await AGENT_SETUP[agent](trimmedKey);
|
|
436
|
+
} catch (err) {
|
|
437
|
+
failed.push(agent.replace("_", " "));
|
|
438
|
+
console.log(` ${yellow("!")} ${agent.replace("_", " ")} setup failed: ${formatError(err)}`);
|
|
439
|
+
console.log(` ${dim("Other agents will continue. Re-run setup to retry.")}`);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if (failed.length > 0) {
|
|
443
|
+
console.log();
|
|
444
|
+
console.log(` ${yellow("!")} Failed: ${failed.join(", ")} ${dim("(others completed successfully)")}`);
|
|
339
445
|
}
|
|
340
446
|
}
|
|
341
447
|
const sendTest = await confirm({ message: "Send a test notification?", default: true });
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
handleStop
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-P4JH2Q7Z.js";
|
|
5
|
+
import "../chunk-KTP2EPVB.js";
|
|
6
|
+
import "../chunk-VIST7ACL.js";
|
|
6
7
|
|
|
7
8
|
// bin/pushary-stop-hook.ts
|
|
8
9
|
var main = async () => {
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {
|
|
2
|
+
askUser,
|
|
3
|
+
sendNotification,
|
|
4
|
+
waitForAnswer
|
|
5
|
+
} from "./chunk-KTP2EPVB.js";
|
|
6
|
+
import {
|
|
7
|
+
getApiKey,
|
|
8
|
+
getBaseUrl
|
|
9
|
+
} from "./chunk-VIST7ACL.js";
|
|
10
|
+
|
|
11
|
+
// src/policy.ts
|
|
12
|
+
import { createHash } from "crypto";
|
|
13
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
14
|
+
import { join } from "path";
|
|
15
|
+
import { tmpdir } from "os";
|
|
16
|
+
var CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
17
|
+
var cacheFile = (apiKey) => {
|
|
18
|
+
const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
|
|
19
|
+
return join(tmpdir(), `pushary-policy-${hash}.json`);
|
|
20
|
+
};
|
|
21
|
+
var fetchPolicy = async (apiKey) => {
|
|
22
|
+
const baseUrl = getBaseUrl();
|
|
23
|
+
const response = await fetch(`${baseUrl}/api/mcp/policy`, {
|
|
24
|
+
headers: { "Authorization": `Bearer ${apiKey}` },
|
|
25
|
+
signal: AbortSignal.timeout(1e4)
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
throw new Error(`Failed to fetch policy: ${response.status}`);
|
|
29
|
+
}
|
|
30
|
+
return response.json();
|
|
31
|
+
};
|
|
32
|
+
var getPolicy = async (apiKey) => {
|
|
33
|
+
const path = cacheFile(apiKey);
|
|
34
|
+
if (existsSync(path)) {
|
|
35
|
+
try {
|
|
36
|
+
const stat = readFileSync(path, "utf-8");
|
|
37
|
+
const cached = JSON.parse(stat);
|
|
38
|
+
if (!cached._cachedAt || Date.now() - cached._cachedAt < CACHE_TTL_MS) {
|
|
39
|
+
return cached;
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const policy = await fetchPolicy(apiKey);
|
|
45
|
+
writeFileSync(path, JSON.stringify({ ...policy, _cachedAt: Date.now() }), "utf-8");
|
|
46
|
+
return policy;
|
|
47
|
+
};
|
|
48
|
+
var resolvePolicy = (config, toolName) => {
|
|
49
|
+
const exact = config.policies.find((p) => p.tool === toolName);
|
|
50
|
+
if (exact) return exact;
|
|
51
|
+
const wildcard = config.policies.find((p) => p.tool === "*");
|
|
52
|
+
if (wildcard) return wildcard;
|
|
53
|
+
return {
|
|
54
|
+
tool: toolName,
|
|
55
|
+
timeoutSeconds: config.defaultTimeoutSeconds,
|
|
56
|
+
timeoutAction: config.defaultTimeoutAction,
|
|
57
|
+
mode: config.defaultMode ?? "push_first",
|
|
58
|
+
pushFirstSeconds: config.defaultPushFirstSeconds ?? 10
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/hook.ts
|
|
63
|
+
import { basename } from "path";
|
|
64
|
+
import { writeFileSync as writeFileSync2, mkdirSync, existsSync as existsSync2 } from "fs";
|
|
65
|
+
import { join as join2 } from "path";
|
|
66
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
67
|
+
var describeToolCall = (input) => {
|
|
68
|
+
const { tool_name, tool_input } = input;
|
|
69
|
+
switch (tool_name) {
|
|
70
|
+
case "Bash":
|
|
71
|
+
return `bash: ${tool_input.command ?? "(no command)"}`;
|
|
72
|
+
case "Write":
|
|
73
|
+
return `write file: ${tool_input.file_path ?? "(unknown path)"}`;
|
|
74
|
+
case "Edit":
|
|
75
|
+
return `edit file: ${tool_input.file_path ?? "(unknown path)"}`;
|
|
76
|
+
case "Read":
|
|
77
|
+
return `read file: ${tool_input.file_path ?? "(unknown path)"}`;
|
|
78
|
+
default:
|
|
79
|
+
return `${tool_name}: ${JSON.stringify(tool_input).slice(0, 200)}`;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
83
|
+
var allow = () => ({
|
|
84
|
+
hookSpecificOutput: {
|
|
85
|
+
hookEventName: "PreToolUse",
|
|
86
|
+
permissionDecision: "allow"
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
var deny = (reason) => ({
|
|
90
|
+
hookSpecificOutput: {
|
|
91
|
+
hookEventName: "PreToolUse",
|
|
92
|
+
permissionDecision: "deny",
|
|
93
|
+
permissionDecisionReason: reason
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
var ask = (reason) => ({
|
|
97
|
+
hookSpecificOutput: {
|
|
98
|
+
hookEventName: "PreToolUse",
|
|
99
|
+
permissionDecision: "ask",
|
|
100
|
+
...reason ? { permissionDecisionReason: reason } : {}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
var PENDING_DIR = join2(tmpdir2(), "pushary-pending");
|
|
104
|
+
var savePendingQuestion = (correlationId) => {
|
|
105
|
+
if (!existsSync2(PENDING_DIR)) mkdirSync(PENDING_DIR, { recursive: true });
|
|
106
|
+
writeFileSync2(join2(PENDING_DIR, correlationId), "", "utf-8");
|
|
107
|
+
};
|
|
108
|
+
var pollForAnswer = async (apiKey, correlationId, deadlineMs, pollInterval = 2e3) => {
|
|
109
|
+
while (Date.now() < deadlineMs) {
|
|
110
|
+
const remaining = Math.min(Math.max(deadlineMs - Date.now(), 1e3), 3e4);
|
|
111
|
+
const answer = await waitForAnswer(apiKey, correlationId, remaining);
|
|
112
|
+
if (answer.answered) return answer;
|
|
113
|
+
if (Date.now() + pollInterval >= deadlineMs) break;
|
|
114
|
+
await sleep(pollInterval);
|
|
115
|
+
}
|
|
116
|
+
return { answered: false };
|
|
117
|
+
};
|
|
118
|
+
var handlePushOnly = async (apiKey, description, projectName, timeoutSeconds, timeoutAction) => {
|
|
119
|
+
const result = await askUser(apiKey, {
|
|
120
|
+
question: `Allow ${description}?`,
|
|
121
|
+
type: "confirm",
|
|
122
|
+
context: `Agent wants to run this in ${projectName}`,
|
|
123
|
+
agentName: `Claude Code - ${projectName}`
|
|
124
|
+
});
|
|
125
|
+
const deadline = Date.now() + timeoutSeconds * 1e3;
|
|
126
|
+
const answer = await pollForAnswer(apiKey, result.correlationId, deadline);
|
|
127
|
+
if (answer.answered) {
|
|
128
|
+
return answer.value === "yes" ? allow() : deny("Denied via push notification");
|
|
129
|
+
}
|
|
130
|
+
switch (timeoutAction) {
|
|
131
|
+
case "approve":
|
|
132
|
+
return allow();
|
|
133
|
+
case "deny":
|
|
134
|
+
return deny("No response within timeout");
|
|
135
|
+
default:
|
|
136
|
+
return ask("No push response, asking in terminal");
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var handleTerminalOnly = () => {
|
|
140
|
+
return ask();
|
|
141
|
+
};
|
|
142
|
+
var handlePushFirst = async (apiKey, description, projectName, pushFirstSeconds) => {
|
|
143
|
+
const 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
|
+
const deadline = Date.now() + pushFirstSeconds * 1e3;
|
|
150
|
+
const answer = await pollForAnswer(apiKey, result.correlationId, deadline, 1500);
|
|
151
|
+
if (answer.answered) {
|
|
152
|
+
return answer.value === "yes" ? allow() : deny("Denied via push notification");
|
|
153
|
+
}
|
|
154
|
+
savePendingQuestion(result.correlationId);
|
|
155
|
+
return ask("Sent as push notification. You can also approve here.");
|
|
156
|
+
};
|
|
157
|
+
var handleNotifyOnly = async (apiKey, description, projectName) => {
|
|
158
|
+
try {
|
|
159
|
+
await sendNotification(apiKey, {
|
|
160
|
+
title: "Agent needs approval",
|
|
161
|
+
body: description,
|
|
162
|
+
agentName: `Claude Code - ${projectName}`
|
|
163
|
+
});
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
return ask();
|
|
167
|
+
};
|
|
168
|
+
var handlePreToolUse = async (input) => {
|
|
169
|
+
const apiKey = getApiKey();
|
|
170
|
+
const policy = await getPolicy(apiKey);
|
|
171
|
+
const toolPolicy = resolvePolicy(policy, input.tool_name);
|
|
172
|
+
if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") {
|
|
173
|
+
return allow();
|
|
174
|
+
}
|
|
175
|
+
const description = describeToolCall(input);
|
|
176
|
+
const projectName = basename(input.cwd ?? process.cwd());
|
|
177
|
+
switch (toolPolicy.mode) {
|
|
178
|
+
case "push_only":
|
|
179
|
+
return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction);
|
|
180
|
+
case "terminal_only":
|
|
181
|
+
return handleTerminalOnly();
|
|
182
|
+
case "push_first":
|
|
183
|
+
return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds);
|
|
184
|
+
case "notify_only":
|
|
185
|
+
return handleNotifyOnly(apiKey, description, projectName);
|
|
186
|
+
default:
|
|
187
|
+
return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export {
|
|
192
|
+
getPolicy,
|
|
193
|
+
resolvePolicy,
|
|
194
|
+
handlePreToolUse
|
|
195
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
callMcpTool
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VIST7ACL.js";
|
|
4
4
|
|
|
5
5
|
// src/api.ts
|
|
6
6
|
var askUser = async (apiKey, params) => {
|
|
@@ -15,9 +15,13 @@ var waitForAnswer = async (apiKey, correlationId, timeoutMs = 3e4) => {
|
|
|
15
15
|
var cancelQuestion = async (apiKey, correlationId) => {
|
|
16
16
|
await callMcpTool(apiKey, "cancel_question", { correlationId });
|
|
17
17
|
};
|
|
18
|
+
var sendNotification = async (apiKey, params) => {
|
|
19
|
+
await callMcpTool(apiKey, "send_notification", { ...params });
|
|
20
|
+
};
|
|
18
21
|
|
|
19
22
|
export {
|
|
20
23
|
askUser,
|
|
21
24
|
waitForAnswer,
|
|
22
|
-
cancelQuestion
|
|
25
|
+
cancelQuestion,
|
|
26
|
+
sendNotification
|
|
23
27
|
};
|
|
@@ -1,11 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cancelQuestion
|
|
3
|
+
} from "./chunk-KTP2EPVB.js";
|
|
1
4
|
import {
|
|
2
5
|
getApiKey,
|
|
3
6
|
getBaseUrl
|
|
4
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-VIST7ACL.js";
|
|
5
8
|
|
|
6
9
|
// src/events.ts
|
|
7
10
|
import { hostname } from "os";
|
|
8
11
|
import { basename } from "path";
|
|
12
|
+
import { readdirSync, unlinkSync } from "fs";
|
|
13
|
+
import { join } from "path";
|
|
14
|
+
import { tmpdir } from "os";
|
|
15
|
+
var PENDING_DIR = join(tmpdir(), "pushary-pending");
|
|
16
|
+
var cleanupPendingQuestions = async () => {
|
|
17
|
+
try {
|
|
18
|
+
const files = readdirSync(PENDING_DIR);
|
|
19
|
+
const apiKey = getApiKey();
|
|
20
|
+
for (const correlationId of files) {
|
|
21
|
+
try {
|
|
22
|
+
await cancelQuestion(apiKey, correlationId);
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
unlinkSync(join(PENDING_DIR, correlationId));
|
|
27
|
+
} catch {
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
};
|
|
9
33
|
var reportEvent = async (event) => {
|
|
10
34
|
const apiKey = getApiKey();
|
|
11
35
|
const baseUrl = getBaseUrl();
|
|
@@ -40,6 +64,7 @@ var handlePostToolUse = async (input) => {
|
|
|
40
64
|
default:
|
|
41
65
|
action = `${input.tool_name}: done`;
|
|
42
66
|
}
|
|
67
|
+
await cleanupPendingQuestions();
|
|
43
68
|
const isError = input.tool_result && ("error" in input.tool_result || "is_error" in input.tool_result);
|
|
44
69
|
await reportEvent({
|
|
45
70
|
event: isError ? "tool_error" : "tool_complete",
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// src/config.ts
|
|
2
|
+
var getApiKey = () => {
|
|
3
|
+
const key = process.env.PUSHARY_API_KEY;
|
|
4
|
+
if (!key) {
|
|
5
|
+
throw new Error(
|
|
6
|
+
"PUSHARY_API_KEY environment variable is not set. Get your API key at https://pushary.com/sign-up?from=ai-coding"
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
return key;
|
|
10
|
+
};
|
|
11
|
+
var getBaseUrl = () => process.env.PUSHARY_BASE_URL ?? "https://pushary.com";
|
|
4
12
|
|
|
5
13
|
// src/mcp-http.ts
|
|
6
14
|
var parseSseJson = (body) => {
|
|
@@ -73,6 +81,8 @@ var callMcpTool = async (apiKey, toolName, params, options = {}) => {
|
|
|
73
81
|
};
|
|
74
82
|
|
|
75
83
|
export {
|
|
84
|
+
getApiKey,
|
|
85
|
+
getBaseUrl,
|
|
76
86
|
sendMcpRequest,
|
|
77
87
|
callMcpTool
|
|
78
88
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -61,15 +61,20 @@ declare const askUser: (apiKey: string, params: AskUserParams) => Promise<AskUse
|
|
|
61
61
|
declare const waitForAnswer: (apiKey: string, correlationId: string, timeoutMs?: number) => Promise<WaitForAnswerResponse>;
|
|
62
62
|
declare const cancelQuestion: (apiKey: string, correlationId: string) => Promise<void>;
|
|
63
63
|
|
|
64
|
+
type ApprovalMode = 'push_only' | 'terminal_only' | 'push_first' | 'notify_only';
|
|
64
65
|
interface ToolPolicy {
|
|
65
66
|
tool: string;
|
|
66
67
|
timeoutSeconds: number;
|
|
67
68
|
timeoutAction: 'approve' | 'deny' | 'escalate';
|
|
69
|
+
mode: ApprovalMode;
|
|
70
|
+
pushFirstSeconds: number;
|
|
68
71
|
}
|
|
69
72
|
interface PolicyConfig {
|
|
70
73
|
policies: ToolPolicy[];
|
|
71
74
|
defaultTimeoutSeconds: number;
|
|
72
75
|
defaultTimeoutAction: 'approve' | 'deny' | 'escalate';
|
|
76
|
+
defaultMode: ApprovalMode;
|
|
77
|
+
defaultPushFirstSeconds: number;
|
|
73
78
|
}
|
|
74
79
|
declare const getPolicy: (apiKey: string) => Promise<PolicyConfig>;
|
|
75
80
|
declare const resolvePolicy: (config: PolicyConfig, toolName: string) => ToolPolicy;
|
package/dist/src/index.js
CHANGED
|
@@ -2,23 +2,22 @@ import {
|
|
|
2
2
|
getPolicy,
|
|
3
3
|
handlePreToolUse,
|
|
4
4
|
resolvePolicy
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import {
|
|
7
|
-
askUser,
|
|
8
|
-
cancelQuestion,
|
|
9
|
-
waitForAnswer
|
|
10
|
-
} from "../chunk-M5SRSBLS.js";
|
|
11
|
-
import "../chunk-RJKW6LLC.js";
|
|
5
|
+
} from "../chunk-DF3BM6BF.js";
|
|
12
6
|
import {
|
|
13
7
|
handleNotification,
|
|
14
8
|
handlePostToolUse,
|
|
15
9
|
handleStop,
|
|
16
10
|
reportEvent
|
|
17
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-P4JH2Q7Z.js";
|
|
12
|
+
import {
|
|
13
|
+
askUser,
|
|
14
|
+
cancelQuestion,
|
|
15
|
+
waitForAnswer
|
|
16
|
+
} from "../chunk-KTP2EPVB.js";
|
|
18
17
|
import {
|
|
19
18
|
getApiKey,
|
|
20
19
|
getBaseUrl
|
|
21
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-VIST7ACL.js";
|
|
22
21
|
export {
|
|
23
22
|
askUser,
|
|
24
23
|
cancelQuestion,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushary/agent-hooks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
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",
|
package/dist/chunk-4TQW4K6T.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
askUser,
|
|
3
|
-
waitForAnswer
|
|
4
|
-
} from "./chunk-M5SRSBLS.js";
|
|
5
|
-
import {
|
|
6
|
-
getApiKey,
|
|
7
|
-
getBaseUrl
|
|
8
|
-
} from "./chunk-VUNL35KE.js";
|
|
9
|
-
|
|
10
|
-
// src/policy.ts
|
|
11
|
-
import { createHash } from "crypto";
|
|
12
|
-
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
13
|
-
import { join } from "path";
|
|
14
|
-
import { tmpdir } from "os";
|
|
15
|
-
var cacheFile = (apiKey) => {
|
|
16
|
-
const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
|
|
17
|
-
return join(tmpdir(), `pushary-policy-${hash}.json`);
|
|
18
|
-
};
|
|
19
|
-
var fetchPolicy = async (apiKey) => {
|
|
20
|
-
const baseUrl = getBaseUrl();
|
|
21
|
-
const response = await fetch(`${baseUrl}/api/mcp/policy`, {
|
|
22
|
-
headers: { "Authorization": `Bearer ${apiKey}` },
|
|
23
|
-
signal: AbortSignal.timeout(1e4)
|
|
24
|
-
});
|
|
25
|
-
if (!response.ok) {
|
|
26
|
-
throw new Error(`Failed to fetch policy: ${response.status}`);
|
|
27
|
-
}
|
|
28
|
-
return response.json();
|
|
29
|
-
};
|
|
30
|
-
var getPolicy = async (apiKey) => {
|
|
31
|
-
const path = cacheFile(apiKey);
|
|
32
|
-
if (existsSync(path)) {
|
|
33
|
-
try {
|
|
34
|
-
return JSON.parse(readFileSync(path, "utf-8"));
|
|
35
|
-
} catch {
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const policy = await fetchPolicy(apiKey);
|
|
39
|
-
writeFileSync(path, JSON.stringify(policy), "utf-8");
|
|
40
|
-
return policy;
|
|
41
|
-
};
|
|
42
|
-
var resolvePolicy = (config, toolName) => {
|
|
43
|
-
const exact = config.policies.find((p) => p.tool === toolName);
|
|
44
|
-
if (exact) return exact;
|
|
45
|
-
const wildcard = config.policies.find((p) => p.tool === "*");
|
|
46
|
-
if (wildcard) return wildcard;
|
|
47
|
-
return {
|
|
48
|
-
tool: toolName,
|
|
49
|
-
timeoutSeconds: config.defaultTimeoutSeconds,
|
|
50
|
-
timeoutAction: config.defaultTimeoutAction
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// src/hook.ts
|
|
55
|
-
import { basename } from "path";
|
|
56
|
-
var describeToolCall = (input) => {
|
|
57
|
-
const { tool_name, tool_input } = input;
|
|
58
|
-
switch (tool_name) {
|
|
59
|
-
case "Bash":
|
|
60
|
-
return `bash: ${tool_input.command ?? "(no command)"}`;
|
|
61
|
-
case "Write":
|
|
62
|
-
return `write file: ${tool_input.file_path ?? "(unknown path)"}`;
|
|
63
|
-
case "Edit":
|
|
64
|
-
return `edit file: ${tool_input.file_path ?? "(unknown path)"}`;
|
|
65
|
-
case "Read":
|
|
66
|
-
return `read file: ${tool_input.file_path ?? "(unknown path)"}`;
|
|
67
|
-
default:
|
|
68
|
-
return `${tool_name}: ${JSON.stringify(tool_input).slice(0, 200)}`;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
72
|
-
var allow = () => ({
|
|
73
|
-
hookSpecificOutput: {
|
|
74
|
-
hookEventName: "PreToolUse",
|
|
75
|
-
permissionDecision: "allow"
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
var deny = (reason) => ({
|
|
79
|
-
hookSpecificOutput: {
|
|
80
|
-
hookEventName: "PreToolUse",
|
|
81
|
-
permissionDecision: "deny",
|
|
82
|
-
permissionDecisionReason: reason
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
var ask = (reason) => ({
|
|
86
|
-
hookSpecificOutput: {
|
|
87
|
-
hookEventName: "PreToolUse",
|
|
88
|
-
permissionDecision: "ask",
|
|
89
|
-
permissionDecisionReason: reason
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
var handlePreToolUse = async (input) => {
|
|
93
|
-
const apiKey = getApiKey();
|
|
94
|
-
const policy = await getPolicy(apiKey);
|
|
95
|
-
const toolPolicy = resolvePolicy(policy, input.tool_name);
|
|
96
|
-
if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") {
|
|
97
|
-
return allow();
|
|
98
|
-
}
|
|
99
|
-
const description = describeToolCall(input);
|
|
100
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
101
|
-
const 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
|
-
});
|
|
107
|
-
const deadline = Date.now() + toolPolicy.timeoutSeconds * 1e3;
|
|
108
|
-
const pollInterval = 2e3;
|
|
109
|
-
while (Date.now() < deadline) {
|
|
110
|
-
const remaining = Math.min(
|
|
111
|
-
Math.max(deadline - Date.now(), 1e3),
|
|
112
|
-
3e4
|
|
113
|
-
);
|
|
114
|
-
const answer = await waitForAnswer(apiKey, result.correlationId, remaining);
|
|
115
|
-
if (answer.answered) {
|
|
116
|
-
return answer.value === "yes" ? allow() : deny("Denied via Pushary push notification");
|
|
117
|
-
}
|
|
118
|
-
if (Date.now() + pollInterval >= deadline) break;
|
|
119
|
-
await sleep(pollInterval);
|
|
120
|
-
}
|
|
121
|
-
switch (toolPolicy.timeoutAction) {
|
|
122
|
-
case "approve":
|
|
123
|
-
return allow();
|
|
124
|
-
case "deny":
|
|
125
|
-
return deny("No response within timeout");
|
|
126
|
-
case "escalate":
|
|
127
|
-
default:
|
|
128
|
-
return ask("Pushary: no response, asking in terminal");
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export {
|
|
133
|
-
getPolicy,
|
|
134
|
-
resolvePolicy,
|
|
135
|
-
handlePreToolUse
|
|
136
|
-
};
|
package/dist/chunk-VUNL35KE.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// src/config.ts
|
|
2
|
-
var getApiKey = () => {
|
|
3
|
-
const key = process.env.PUSHARY_API_KEY;
|
|
4
|
-
if (!key) {
|
|
5
|
-
throw new Error(
|
|
6
|
-
"PUSHARY_API_KEY environment variable is not set. Get your API key at https://pushary.com/sign-up?from=ai-coding"
|
|
7
|
-
);
|
|
8
|
-
}
|
|
9
|
-
return key;
|
|
10
|
-
};
|
|
11
|
-
var getBaseUrl = () => process.env.PUSHARY_BASE_URL ?? "https://pushary.com";
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
getApiKey,
|
|
15
|
-
getBaseUrl
|
|
16
|
-
};
|