@pushary/agent-hooks 0.1.1 → 0.2.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.
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env node
2
+
3
+ // bin/pushary-setup.ts
4
+ import { existsSync, readFileSync, writeFileSync, appendFileSync, mkdirSync } from "fs";
5
+ import { join } from "path";
6
+ import { homedir } from "os";
7
+ import { createInterface } from "readline";
8
+ var rl = createInterface({ input: process.stdin, output: process.stdout });
9
+ var ask = (q) => new Promise((r) => rl.question(q, r));
10
+ var CLAUDE_SETTINGS = join(homedir(), ".claude", "settings.json");
11
+ var CURSOR_MCP = join(".cursor", "mcp.json");
12
+ var SHELL_FILES = [".zshrc", ".bashrc"].map((f) => join(homedir(), f));
13
+ var dim = (s) => `\x1B[2m${s}\x1B[0m`;
14
+ var bold = (s) => `\x1B[1m${s}\x1B[0m`;
15
+ var green = (s) => `\x1B[32m${s}\x1B[0m`;
16
+ var cyan = (s) => `\x1B[36m${s}\x1B[0m`;
17
+ var readJson = (path) => {
18
+ try {
19
+ return JSON.parse(readFileSync(path, "utf-8"));
20
+ } catch {
21
+ return {};
22
+ }
23
+ };
24
+ var writeJson = (path, data) => {
25
+ const dir = path.substring(0, path.lastIndexOf("/"));
26
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
27
+ writeFileSync(path, JSON.stringify(data, null, 2) + "\n", "utf-8");
28
+ };
29
+ var setupClaudeCode = async (apiKey) => {
30
+ console.log(`
31
+ ${bold("Claude Code Setup")}
32
+ `);
33
+ const settings = readJson(CLAUDE_SETTINGS);
34
+ const mcpServers = settings.mcpServers ?? {};
35
+ mcpServers.pushary = {
36
+ url: "https://pushary.com/api/mcp/mcp",
37
+ headers: { Authorization: `Bearer ${apiKey}` }
38
+ };
39
+ settings.mcpServers = mcpServers;
40
+ const addHooks = await ask(`Add permission hooks? (approve/deny tools from your phone) ${dim("[Y/n]")} `);
41
+ if (addHooks.toLowerCase() !== "n") {
42
+ const hooks = settings.hooks ?? {};
43
+ const preToolUse = hooks.PreToolUse ?? [];
44
+ const alreadyHasPushary = JSON.stringify(preToolUse).includes("pushary-hook");
45
+ if (!alreadyHasPushary) {
46
+ preToolUse.push({
47
+ matcher: "Bash|Write|Edit",
48
+ hooks: [{
49
+ type: "command",
50
+ command: "pushary-hook",
51
+ timeout: 120
52
+ }]
53
+ });
54
+ hooks.PreToolUse = preToolUse;
55
+ settings.hooks = hooks;
56
+ }
57
+ }
58
+ writeJson(CLAUDE_SETTINGS, settings);
59
+ console.log(` ${green("done")} MCP server added to ${dim(CLAUDE_SETTINGS)}`);
60
+ if (settings.hooks) {
61
+ console.log(` ${green("done")} Permission hooks configured`);
62
+ }
63
+ };
64
+ var setupCursor = async (apiKey) => {
65
+ console.log(`
66
+ ${bold("Cursor Setup")}
67
+ `);
68
+ const config = readJson(CURSOR_MCP);
69
+ const mcpServers = config.mcpServers ?? {};
70
+ mcpServers.pushary = {
71
+ url: "https://pushary.com/api/mcp/mcp",
72
+ headers: { Authorization: `Bearer ${apiKey}` }
73
+ };
74
+ config.mcpServers = mcpServers;
75
+ writeJson(CURSOR_MCP, config);
76
+ console.log(` ${green("done")} MCP server added to ${dim(CURSOR_MCP)}`);
77
+ };
78
+ var saveApiKey = (apiKey) => {
79
+ const exportLine = `
80
+ export PUSHARY_API_KEY="${apiKey}"
81
+ `;
82
+ const shellFile = SHELL_FILES.find((f) => existsSync(f));
83
+ if (shellFile) {
84
+ const content = readFileSync(shellFile, "utf-8");
85
+ if (content.includes("PUSHARY_API_KEY")) {
86
+ console.log(` ${dim("PUSHARY_API_KEY already in")} ${shellFile}`);
87
+ } else {
88
+ appendFileSync(shellFile, exportLine, "utf-8");
89
+ console.log(` ${green("done")} Added PUSHARY_API_KEY to ${dim(shellFile)}`);
90
+ }
91
+ }
92
+ process.env.PUSHARY_API_KEY = apiKey;
93
+ };
94
+ var sendTestNotification = async (apiKey) => {
95
+ console.log(`
96
+ ${bold("Sending test notification...")}`);
97
+ try {
98
+ const response = await fetch("https://pushary.com/api/mcp/mcp", {
99
+ method: "POST",
100
+ headers: {
101
+ "Content-Type": "application/json",
102
+ Authorization: `Bearer ${apiKey}`
103
+ },
104
+ body: JSON.stringify({
105
+ jsonrpc: "2.0",
106
+ id: 1,
107
+ method: "tools/call",
108
+ params: {
109
+ name: "send_notification",
110
+ arguments: {
111
+ title: "Pushary is working",
112
+ body: "Your AI agent can now send you push notifications.",
113
+ agentName: "Pushary Setup"
114
+ }
115
+ }
116
+ })
117
+ });
118
+ if (response.ok) {
119
+ console.log(` ${green("done")} Check your phone!`);
120
+ } else {
121
+ console.log(` ${dim("Could not send test notification. Make sure you enabled notifications at pushary.com")}`);
122
+ }
123
+ } catch {
124
+ console.log(` ${dim("Could not reach Pushary API. Check your internet connection.")}`);
125
+ }
126
+ };
127
+ var main = async () => {
128
+ console.log(`
129
+ ${bold("Pushary Setup")}
130
+ `);
131
+ console.log(`Push notifications for your AI coding agents.
132
+ `);
133
+ const apiKey = await ask(`Paste your API key ${dim("(from pushary.com/dashboard/agent/settings)")}: `);
134
+ if (!apiKey.trim() || !apiKey.includes(".")) {
135
+ console.log("\nInvalid API key. Get yours at https://pushary.com/sign-up?from=ai-coding\n");
136
+ rl.close();
137
+ process.exit(1);
138
+ }
139
+ const trimmedKey = apiKey.trim();
140
+ console.log(`
141
+ Which agents do you use?
142
+ `);
143
+ console.log(` 1. ${cyan("Claude Code")}`);
144
+ console.log(` 2. ${cyan("Cursor")}`);
145
+ console.log(` 3. ${cyan("Both")}`);
146
+ console.log(` 4. ${cyan("Other")} ${dim("(just save the API key)")}`);
147
+ console.log();
148
+ const choice = await ask(`Choice ${dim("[1-4]")}: `);
149
+ saveApiKey(trimmedKey);
150
+ switch (choice.trim()) {
151
+ case "1":
152
+ await setupClaudeCode(trimmedKey);
153
+ break;
154
+ case "2":
155
+ await setupCursor(trimmedKey);
156
+ break;
157
+ case "3":
158
+ await setupClaudeCode(trimmedKey);
159
+ await setupCursor(trimmedKey);
160
+ break;
161
+ case "4":
162
+ default:
163
+ break;
164
+ }
165
+ const test = await ask(`
166
+ Send a test notification? ${dim("[Y/n]")} `);
167
+ if (test.toLowerCase() !== "n") {
168
+ await sendTestNotification(trimmedKey);
169
+ }
170
+ console.log(`
171
+ ${green("Setup complete.")} Your agents will now send you push notifications.
172
+ `);
173
+ console.log(`${dim("Next steps:")}`);
174
+ console.log(` ${dim("1.")} Enable notifications on your phone at ${cyan("pushary.com")}`);
175
+ console.log(` ${dim("2.")} Configure timeout policies at ${cyan("pushary.com/dashboard/agent/policies")}`);
176
+ console.log(` ${dim("3.")} Start coding with your agent
177
+ `);
178
+ rl.close();
179
+ };
180
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushary/agent-hooks",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
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",
@@ -14,14 +14,15 @@
14
14
  "main": "./dist/src/index.js",
15
15
  "types": "./dist/src/index.d.ts",
16
16
  "bin": {
17
- "pushary-hook": "./dist/bin/pushary-hook.js"
17
+ "pushary-hook": "./dist/bin/pushary-hook.js",
18
+ "pushary-setup": "./dist/bin/pushary-setup.js"
18
19
  },
19
20
  "files": [
20
21
  "dist"
21
22
  ],
22
23
  "scripts": {
23
- "build": "tsup src/index.ts bin/pushary-hook.ts --format esm --dts --outDir dist",
24
- "dev": "tsup src/index.ts bin/pushary-hook.ts --format esm --watch"
24
+ "build": "tsup src/index.ts bin/pushary-hook.ts bin/pushary-setup.ts --format esm --dts --outDir dist",
25
+ "dev": "tsup src/index.ts bin/pushary-hook.ts bin/pushary-setup.ts --format esm --watch"
25
26
  },
26
27
  "devDependencies": {
27
28
  "tsup": "^8.0.0",