@pushary/agent-hooks 0.37.0 → 0.39.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.
@@ -1,8 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- removeClaudeMcpServers,
4
- removePusharySettings
5
- } from "../chunk-JWASPLL3.js";
6
2
  import {
7
3
  removeCodexHooks,
8
4
  removeGeminiSettings,
@@ -11,6 +7,10 @@ import {
11
7
  import {
12
8
  execNpm
13
9
  } from "../chunk-J7JWI3KU.js";
10
+ import {
11
+ removeClaudeMcpServers,
12
+ removePusharySettings
13
+ } from "../chunk-7EW3USQF.js";
14
14
  import "../chunk-Z5PL3K7C.js";
15
15
 
16
16
  // bin/pushary-clean.ts
@@ -32,7 +32,7 @@ import {
32
32
  toCodexWire,
33
33
  toPolicyLookup,
34
34
  waitForAnswer
35
- } from "../chunk-XVN5SMME.js";
35
+ } from "../chunk-JHN3H6LX.js";
36
36
  import {
37
37
  isGatingMoment,
38
38
  recordKeylessMoment
@@ -4,7 +4,7 @@ import {
4
4
  getMachineId,
5
5
  reportEvent,
6
6
  waitForAnswer
7
- } from "../chunk-XVN5SMME.js";
7
+ } from "../chunk-JHN3H6LX.js";
8
8
  import "../chunk-DWED7BS3.js";
9
9
  import "../chunk-Z5PL3K7C.js";
10
10
  import {
@@ -148,14 +148,22 @@ var main = async () => {
148
148
  const settings = readJson(CLAUDE_SETTINGS);
149
149
  if (settings) {
150
150
  const hooks = settings.hooks;
151
- const hasPreHook = JSON.stringify(hooks?.PreToolUse ?? []).includes("pushary-hook");
152
- const hasPostHook = JSON.stringify(hooks?.PostToolUse ?? []).includes("pushary-post-hook");
153
- const hasStopHook = JSON.stringify(hooks?.Stop ?? []).includes("pushary-stop-hook");
154
- const hasPromptHook = JSON.stringify(hooks?.UserPromptSubmit ?? []).includes("pushary-prompt-hook");
155
- check(hasPreHook, "Claude Code: PreToolUse hook");
156
- check(hasPostHook, "Claude Code: PostToolUse hook");
157
- check(hasStopHook, "Claude Code: Stop hook");
158
- check(hasPromptHook, "Claude Code: UserPromptSubmit hook", hasPromptHook ? void 0 : "missing, re-run setup to register it");
151
+ const CLAUDE_HOOK_CHECKS = [
152
+ { event: "PreToolUse", needle: "pushary-hook", label: "PreToolUse hook" },
153
+ { event: "PostToolUse", needle: "pushary-post-hook", label: "PostToolUse hook" },
154
+ { event: "UserPromptSubmit", needle: "pushary-prompt-hook", label: "UserPromptSubmit hook" },
155
+ { event: "Stop", needle: "pushary-stop-hook", label: "Stop hook" },
156
+ { event: "StopFailure", needle: "pushary-stopfailure-hook", label: "StopFailure hook" },
157
+ { event: "Notification", needle: "pushary-notification-hook", label: "Notification hook" },
158
+ { event: "SessionStart", needle: "pushary-session-start-hook", label: "SessionStart hook" },
159
+ { event: "SessionEnd", needle: "pushary-session-end-hook", label: "SessionEnd hook" },
160
+ { event: "PermissionRequest", needle: "pushary-permission-hook", label: "PermissionRequest hook" },
161
+ { event: "PermissionDenied", needle: "pushary-permission-denied-hook", label: "PermissionDenied hook" }
162
+ ];
163
+ for (const { event, needle, label } of CLAUDE_HOOK_CHECKS) {
164
+ const present = JSON.stringify(hooks?.[event] ?? []).includes(needle);
165
+ check(present, `Claude Code: ${label}`, present ? void 0 : "missing \u2014 run npx @pushary/agent-hooks@latest upgrade");
166
+ }
159
167
  const preHookCommand = extractHookCommand(hooks?.PreToolUse, "pushary-hook");
160
168
  if (preHookCommand) {
161
169
  const resolves = commandResolves(preHookCommand);
@@ -24,7 +24,7 @@ import {
24
24
  savePendingQuestion,
25
25
  sendNotification,
26
26
  waitForAnswer
27
- } from "../chunk-XVN5SMME.js";
27
+ } from "../chunk-JHN3H6LX.js";
28
28
  import {
29
29
  isGatingMoment,
30
30
  recordKeylessMoment
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  handlePreToolUse
4
- } from "../chunk-BK4RU2BF.js";
4
+ } from "../chunk-X6L25EOF.js";
5
+ import "../chunk-7EW3USQF.js";
5
6
  import "../chunk-KQYIHZ5E.js";
6
- import "../chunk-XVN5SMME.js";
7
+ import "../chunk-JHN3H6LX.js";
7
8
  import "../chunk-R5AJNXZS.js";
8
9
  import "../chunk-DWED7BS3.js";
9
10
  import "../chunk-Z5PL3K7C.js";
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  handleNotification
4
- } from "../chunk-XVN5SMME.js";
4
+ } from "../chunk-JHN3H6LX.js";
5
5
  import "../chunk-DWED7BS3.js";
6
6
  import "../chunk-Z5PL3K7C.js";
7
7
  import "../chunk-NKXSILEW.js";
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ handlePermissionDenied
4
+ } from "../chunk-X6L25EOF.js";
5
+ import "../chunk-7EW3USQF.js";
6
+ import "../chunk-KQYIHZ5E.js";
7
+ import "../chunk-JHN3H6LX.js";
8
+ import "../chunk-R5AJNXZS.js";
9
+ import "../chunk-DWED7BS3.js";
10
+ import "../chunk-Z5PL3K7C.js";
11
+ import "../chunk-NKXSILEW.js";
12
+
13
+ // bin/pushary-permission-denied-hook.ts
14
+ var main = async () => {
15
+ let rawInput = "";
16
+ for await (const chunk of process.stdin) {
17
+ rawInput += chunk;
18
+ }
19
+ try {
20
+ const input = rawInput.trim() ? JSON.parse(rawInput) : {};
21
+ const output = await handlePermissionDenied(input);
22
+ if (output) process.stdout.write(JSON.stringify(output));
23
+ } catch {
24
+ }
25
+ };
26
+ main();
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ handlePermissionRequest
4
+ } from "../chunk-X6L25EOF.js";
5
+ import "../chunk-7EW3USQF.js";
6
+ import "../chunk-KQYIHZ5E.js";
7
+ import "../chunk-JHN3H6LX.js";
8
+ import "../chunk-R5AJNXZS.js";
9
+ import "../chunk-DWED7BS3.js";
10
+ import "../chunk-Z5PL3K7C.js";
11
+ import "../chunk-NKXSILEW.js";
12
+
13
+ // bin/pushary-permission-hook.ts
14
+ var main = async () => {
15
+ let rawInput = "";
16
+ for await (const chunk of process.stdin) {
17
+ rawInput += chunk;
18
+ }
19
+ try {
20
+ const input = rawInput.trim() ? JSON.parse(rawInput) : {};
21
+ const output = await handlePermissionRequest(input);
22
+ if (output) process.stdout.write(JSON.stringify(output));
23
+ } catch {
24
+ }
25
+ };
26
+ main();
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  handlePostToolUse
4
- } from "../chunk-XVN5SMME.js";
4
+ } from "../chunk-JHN3H6LX.js";
5
5
  import "../chunk-DWED7BS3.js";
6
6
  import "../chunk-Z5PL3K7C.js";
7
7
  import "../chunk-NKXSILEW.js";
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  handleUserPrompt
4
- } from "../chunk-XVN5SMME.js";
4
+ } from "../chunk-JHN3H6LX.js";
5
5
  import "../chunk-DWED7BS3.js";
6
6
  import "../chunk-Z5PL3K7C.js";
7
7
  import "../chunk-NKXSILEW.js";
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  handleSessionEnd
4
- } from "../chunk-XVN5SMME.js";
4
+ } from "../chunk-JHN3H6LX.js";
5
5
  import "../chunk-DWED7BS3.js";
6
6
  import "../chunk-Z5PL3K7C.js";
7
7
  import "../chunk-NKXSILEW.js";
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  handleSessionStart
4
- } from "../chunk-XVN5SMME.js";
4
+ } from "../chunk-JHN3H6LX.js";
5
5
  import "../chunk-DWED7BS3.js";
6
6
  import "../chunk-Z5PL3K7C.js";
7
7
  import "../chunk-NKXSILEW.js";
@@ -1,9 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- addClaudeMcpServer,
4
- addPusharyHooks,
5
- addPusharyToolPermissions
6
- } from "../chunk-JWASPLL3.js";
7
2
  import {
8
3
  GEMINI_HOOK_BINARY,
9
4
  addCodexHookTrust,
@@ -22,9 +17,14 @@ import {
22
17
  resolveGlobalBinDir,
23
18
  resolveGlobalBinary
24
19
  } from "../chunk-J7JWI3KU.js";
20
+ import {
21
+ addClaudeMcpServer,
22
+ addPusharyHooks,
23
+ addPusharyToolPermissions
24
+ } from "../chunk-7EW3USQF.js";
25
25
  import {
26
26
  reportEvent
27
- } from "../chunk-XVN5SMME.js";
27
+ } from "../chunk-JHN3H6LX.js";
28
28
  import "../chunk-DWED7BS3.js";
29
29
  import {
30
30
  isValidApiKey
@@ -481,7 +481,7 @@ var setupClaudeCode = async (apiKey) => {
481
481
  addPusharyToolPermissions(settings);
482
482
  });
483
483
  await installGlobally();
484
- await spinner("Adding hooks (PreToolUse, PostToolUse, UserPromptSubmit, Stop)", async () => {
484
+ await spinner("Adding hooks (approvals, activity, presence, and lifecycle events)", async () => {
485
485
  addPusharyHooks(settings, resolveGlobalBinDir("pushary-hook"));
486
486
  });
487
487
  await spinner(`Writing ${CLAUDE_SETTINGS}`, async () => {
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  handleStop
4
- } from "../chunk-XVN5SMME.js";
4
+ } from "../chunk-JHN3H6LX.js";
5
5
  import "../chunk-DWED7BS3.js";
6
6
  import "../chunk-Z5PL3K7C.js";
7
7
  import "../chunk-NKXSILEW.js";
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  handleStopFailure
4
- } from "../chunk-XVN5SMME.js";
4
+ } from "../chunk-JHN3H6LX.js";
5
5
  import "../chunk-DWED7BS3.js";
6
6
  import "../chunk-Z5PL3K7C.js";
7
7
  import "../chunk-NKXSILEW.js";
@@ -1,8 +1,67 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  execNpm,
4
- npmErrorMessage
4
+ npmErrorMessage,
5
+ resolveGlobalBinDir
5
6
  } from "../chunk-J7JWI3KU.js";
7
+ import {
8
+ addClaudeMcpServer,
9
+ addPusharyHooks,
10
+ addPusharyToolPermissions
11
+ } from "../chunk-7EW3USQF.js";
12
+ import "../chunk-Z5PL3K7C.js";
13
+ import {
14
+ getApiKey
15
+ } from "../chunk-NKXSILEW.js";
16
+
17
+ // src/reapply.ts
18
+ import { join, dirname } from "path";
19
+ import { homedir } from "os";
20
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
21
+ var CLAUDE_SETTINGS = join(homedir(), ".claude", "settings.json");
22
+ var CLAUDE_JSON = join(homedir(), ".claude.json");
23
+ var readJson = (filePath) => {
24
+ try {
25
+ return JSON.parse(readFileSync(filePath, "utf-8"));
26
+ } catch {
27
+ return null;
28
+ }
29
+ };
30
+ var writeJson = (filePath, data) => {
31
+ const dir = dirname(filePath);
32
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
33
+ writeFileSync(filePath, JSON.stringify(data, null, 2) + "\n", "utf-8");
34
+ };
35
+ var hasPusharyClaudeHooks = (settings) => JSON.stringify(settings.hooks ?? {}).includes("pushary-hook");
36
+ var hasPusharyMcp = (claudeJson) => !!claudeJson.mcpServers?.pushary;
37
+ var reapplyClaudeSettings = (apiKey, paths = {}) => {
38
+ const settingsPath = paths.settingsPath ?? CLAUDE_SETTINGS;
39
+ const claudeJsonPath = paths.claudeJsonPath ?? CLAUDE_JSON;
40
+ const settings = readJson(settingsPath);
41
+ const claudeJson = readJson(claudeJsonPath);
42
+ const configured = settings != null && hasPusharyClaudeHooks(settings) || claudeJson != null && hasPusharyMcp(claudeJson);
43
+ if (!configured) return { reapplied: false, hooks: false, mcp: false };
44
+ let hooks = false;
45
+ let mcp = false;
46
+ try {
47
+ const s = settings ?? {};
48
+ addPusharyToolPermissions(s);
49
+ addPusharyHooks(s, resolveGlobalBinDir("pushary-hook"));
50
+ writeJson(settingsPath, s);
51
+ hooks = true;
52
+ } catch {
53
+ }
54
+ if (apiKey) {
55
+ try {
56
+ const cj = claudeJson ?? {};
57
+ addClaudeMcpServer(cj, apiKey);
58
+ writeJson(claudeJsonPath, cj);
59
+ mcp = true;
60
+ } catch {
61
+ }
62
+ }
63
+ return { reapplied: hooks || mcp, hooks, mcp };
64
+ };
6
65
 
7
66
  // bin/pushary-upgrade.ts
8
67
  var getInstalledVersion = () => {
@@ -52,7 +111,20 @@ var main = async () => {
52
111
  console.error(`Upgrade failed: ${npmErrorMessage(err)}`);
53
112
  process.exit(1);
54
113
  }
55
- console.log("Done. Your hooks point at the global install, so agents pick this up on their next tool call.");
114
+ let apiKey;
115
+ try {
116
+ apiKey = getApiKey();
117
+ } catch {
118
+ apiKey = void 0;
119
+ }
120
+ try {
121
+ const result = reapplyClaudeSettings(apiKey);
122
+ if (result.reapplied) {
123
+ console.log("Refreshed Claude Code hooks and settings so the new hook set is active now.");
124
+ }
125
+ } catch {
126
+ }
127
+ console.log("Done. Your hooks point at the global install and settings were refreshed.");
56
128
  console.log("Verify with: pushary doctor");
57
129
  };
58
130
  main();
@@ -6,6 +6,8 @@ import {
6
6
  import { join } from "path";
7
7
  var PUSHARY_MCP_URL = "https://pushary.com/api/mcp/mcp";
8
8
  var PUSHARY_PERMISSION_RULE = "mcp__pushary__*";
9
+ var PRETOOLUSE_GATED_TOOLS = ["Bash", "Write", "Edit", "MultiEdit", "NotebookEdit", "PowerShell", "Monitor"];
10
+ var PRETOOLUSE_HANDLED_TOOLS = /* @__PURE__ */ new Set([...PRETOOLUSE_GATED_TOOLS, "AskUserQuestion"]);
9
11
  var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
10
12
  var ensureRecord = (target, key) => {
11
13
  const existing = asRecord(target[key]);
@@ -20,7 +22,7 @@ var isPusharyHook = (entry) => {
20
22
  if (!Array.isArray(hooks)) return false;
21
23
  return hooks.some((hook) => {
22
24
  const command = String(asRecord(hook)?.command ?? "");
23
- return command.includes("pushary-hook") || command.includes("pushary-post-hook") || command.includes("pushary-stop-hook") || command.includes("pushary-prompt-hook") || command.includes("pushary-notification-hook") || command.includes("pushary-session-start-hook") || command.includes("pushary-session-end-hook") || command.includes("pushary-stopfailure-hook");
25
+ return command.includes("pushary-hook") || command.includes("pushary-post-hook") || command.includes("pushary-stop-hook") || command.includes("pushary-prompt-hook") || command.includes("pushary-notification-hook") || command.includes("pushary-session-start-hook") || command.includes("pushary-session-end-hook") || command.includes("pushary-stopfailure-hook") || command.includes("pushary-permission-hook") || command.includes("pushary-permission-denied-hook");
24
26
  });
25
27
  };
26
28
  var addClaudeMcpServer = (config, apiKey) => {
@@ -65,7 +67,7 @@ var addPusharyHooks = (settings, binDir) => {
65
67
  return /\s/.test(path) ? `"${path}"` : path;
66
68
  };
67
69
  const hooks = ensureRecord(settings, "hooks");
68
- const SHELL_AND_FILE_TOOLS = "Bash|Write|Edit|MultiEdit|NotebookEdit|PowerShell|Monitor";
70
+ const SHELL_AND_FILE_TOOLS = PRETOOLUSE_GATED_TOOLS.join("|");
69
71
  const preToolUse = (Array.isArray(hooks.PreToolUse) ? hooks.PreToolUse : []).filter((entry) => !isPusharyHook(entry));
70
72
  preToolUse.push({
71
73
  matcher: `${SHELL_AND_FILE_TOOLS}|AskUserQuestion`,
@@ -142,6 +144,24 @@ var addPusharyHooks = (settings, binDir) => {
142
144
  }]
143
145
  });
144
146
  hooks.StopFailure = stopFailure;
147
+ const permissionRequest = (Array.isArray(hooks.PermissionRequest) ? hooks.PermissionRequest : []).filter((entry) => !isPusharyHook(entry));
148
+ permissionRequest.push({
149
+ hooks: [{
150
+ type: "command",
151
+ command: resolve("pushary-permission-hook"),
152
+ timeout: HOOK_BUDGETS.claude.budgetSeconds
153
+ }]
154
+ });
155
+ hooks.PermissionRequest = permissionRequest;
156
+ const permissionDenied = (Array.isArray(hooks.PermissionDenied) ? hooks.PermissionDenied : []).filter((entry) => !isPusharyHook(entry));
157
+ permissionDenied.push({
158
+ hooks: [{
159
+ type: "command",
160
+ command: resolve("pushary-permission-denied-hook"),
161
+ timeout: 60
162
+ }]
163
+ });
164
+ hooks.PermissionDenied = permissionDenied;
145
165
  };
146
166
  var removePusharySettings = (settings) => {
147
167
  let changed = removeClaudeMcpServers(settings);
@@ -160,7 +180,7 @@ var removePusharySettings = (settings) => {
160
180
  }
161
181
  const hooks = asRecord(settings.hooks);
162
182
  if (hooks) {
163
- for (const key of ["PreToolUse", "PostToolUse", "Stop", "StopFailure", "UserPromptSubmit", "Notification", "SessionStart", "SessionEnd"]) {
183
+ for (const key of ["PreToolUse", "PostToolUse", "Stop", "StopFailure", "UserPromptSubmit", "Notification", "SessionStart", "SessionEnd", "PermissionRequest", "PermissionDenied"]) {
164
184
  const entries = hooks[key];
165
185
  if (!Array.isArray(entries)) continue;
166
186
  const filtered = entries.filter((entry) => !isPusharyHook(entry));
@@ -179,6 +199,7 @@ var removePusharySettings = (settings) => {
179
199
  };
180
200
 
181
201
  export {
202
+ PRETOOLUSE_HANDLED_TOOLS,
182
203
  addClaudeMcpServer,
183
204
  removeClaudeMcpServers,
184
205
  addPusharyToolPermissions,
@@ -1100,6 +1100,7 @@ export {
1100
1100
  getMachineId,
1101
1101
  DEFAULT_SESSION,
1102
1102
  savePendingQuestion,
1103
+ throttlePass,
1103
1104
  readLastUserPrompt,
1104
1105
  CODEX_AGENT,
1105
1106
  codexAllow,
@@ -1,3 +1,6 @@
1
+ import {
2
+ PRETOOLUSE_HANDLED_TOOLS
3
+ } from "./chunk-7EW3USQF.js";
1
4
  import {
2
5
  denyReasonFrom,
3
6
  isDeferAnswer
@@ -19,8 +22,9 @@ import {
19
22
  resolvePolicy,
20
23
  savePendingQuestion,
21
24
  sendNotification,
25
+ throttlePass,
22
26
  waitForAnswer
23
- } from "./chunk-XVN5SMME.js";
27
+ } from "./chunk-JHN3H6LX.js";
24
28
  import {
25
29
  isGatingMoment,
26
30
  recordKeylessMoment
@@ -195,6 +199,31 @@ var handleNotifyOnly = async (apiKey, description, projectName, sessionId, machi
195
199
  }
196
200
  return ask();
197
201
  };
202
+ var dispatchModeHandler = async (apiKey, input, toolPolicy, machineId) => {
203
+ const description = describeToolCall(input.tool_name, input.tool_input, "hook");
204
+ const projectName = basename(input.cwd ?? process.cwd());
205
+ const sessionId = input.session_id;
206
+ const toolTarget = deriveToolTarget(input.tool_name, input.tool_input);
207
+ const intent = readLastPrompt(sessionId ?? DEFAULT_SESSION) ?? (input.transcript_path ? readLastUserPrompt(input.transcript_path) : void 0);
208
+ const decision = {
209
+ intent,
210
+ action: deriveAction(input.tool_name, input.tool_input),
211
+ blocker: deriveBlocker(toolPolicy.mode),
212
+ actionBody: deriveActionBody(input.tool_name, input.tool_input)
213
+ };
214
+ switch (toolPolicy.mode) {
215
+ case "push_only":
216
+ return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction, sessionId, machineId, input.tool_name, toolTarget, decision);
217
+ case "terminal_only":
218
+ return handleTerminalOnly();
219
+ case "push_first":
220
+ return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget, decision);
221
+ case "notify_only":
222
+ return handleNotifyOnly(apiKey, description, projectName, sessionId, machineId);
223
+ default:
224
+ return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget, decision);
225
+ }
226
+ };
198
227
  var KEYLESS_NOTICE = "[pushary] Not connected (no API key), so your agent runs untouched. Approval moments are counted locally; see them with: npx @pushary/agent-hooks@latest stats. Connect: https://pushary.com/sign-up?utm_source=cli&utm_medium=keyless-hook";
199
228
  var keylessNoticeOnce = (sessionId) => {
200
229
  try {
@@ -308,35 +337,115 @@ var handlePreToolUse = async (input) => {
308
337
  if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "deny") {
309
338
  return deny(`Denied by policy for ${toolPolicy.tool}`);
310
339
  }
311
- const description = describeToolCall(input.tool_name, input.tool_input, "hook");
340
+ return dispatchModeHandler(apiKey, input, toolPolicy, getMachineId());
341
+ } catch {
342
+ return void 0;
343
+ }
344
+ };
345
+ var permReqAllow = (updatedInput) => ({
346
+ hookSpecificOutput: {
347
+ hookEventName: "PermissionRequest",
348
+ decision: { behavior: "allow", ...updatedInput ? { updatedInput } : {} }
349
+ }
350
+ });
351
+ var permReqDeny = (message) => ({
352
+ hookSpecificOutput: {
353
+ hookEventName: "PermissionRequest",
354
+ decision: { behavior: "deny", ...message ? { message } : {} }
355
+ }
356
+ });
357
+ var toPermissionRequestOutput = (hookOutput) => {
358
+ if (!hookOutput) return void 0;
359
+ const d = hookOutput.hookSpecificOutput;
360
+ if (d.permissionDecision === "allow") return permReqAllow(d.updatedInput);
361
+ if (d.permissionDecision === "deny") return permReqDeny(d.permissionDecisionReason);
362
+ return void 0;
363
+ };
364
+ var handlePermissionRequest = async (input) => {
365
+ if (PRETOOLUSE_HANDLED_TOOLS.has(input.tool_name)) return void 0;
366
+ if (input.tool_name.startsWith("mcp__pushary__")) return void 0;
367
+ let apiKey;
368
+ try {
369
+ apiKey = getApiKey();
370
+ } catch {
371
+ return void 0;
372
+ }
373
+ try {
374
+ const modeState = await fetchModeState(apiKey, input.session_id);
375
+ const policy = await getPolicy(apiKey, modeState.policyVersion);
376
+ if (modeState.kill) return permReqDeny("Stopped by user \u2014 this agent was halted from Pushary");
377
+ const toolPolicy = resolvePolicy(policy, input.tool_name, modeState.mode, input.tool_input);
378
+ if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") return permReqAllow();
379
+ if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "deny") {
380
+ return permReqDeny(`Denied by policy for ${toolPolicy.tool}`);
381
+ }
382
+ return toPermissionRequestOutput(await dispatchModeHandler(apiKey, input, toolPolicy, getMachineId()));
383
+ } catch {
384
+ return void 0;
385
+ }
386
+ };
387
+ var PERMISSION_DENIED_WINDOW_MS = 5 * 60 * 1e3;
388
+ var PERMISSION_DENIED_WAIT_SECONDS = 25;
389
+ var automodeRetryEnabled = () => {
390
+ const flag = process.env.PUSHARY_AUTOMODE_RETRY;
391
+ return flag === "1" || flag === "true";
392
+ };
393
+ var handlePermissionDenied = async (input) => {
394
+ if (input.tool_name.startsWith("mcp__pushary__")) return void 0;
395
+ let apiKey;
396
+ try {
397
+ apiKey = getApiKey();
398
+ } catch {
399
+ return void 0;
400
+ }
401
+ try {
312
402
  const projectName = basename(input.cwd ?? process.cwd());
313
- const sessionId = input.session_id;
314
- const machineId = getMachineId();
315
- const toolTarget = deriveToolTarget(input.tool_name, input.tool_input);
316
- const intent = readLastPrompt(sessionId ?? DEFAULT_SESSION) ?? (input.transcript_path ? readLastUserPrompt(input.transcript_path) : void 0);
317
- const decision = {
318
- intent,
319
- action: deriveAction(input.tool_name, input.tool_input),
320
- blocker: deriveBlocker(toolPolicy.mode),
321
- actionBody: deriveActionBody(input.tool_name, input.tool_input)
322
- };
323
- switch (toolPolicy.mode) {
324
- case "push_only":
325
- return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction, sessionId, machineId, input.tool_name, toolTarget, decision);
326
- case "terminal_only":
327
- return handleTerminalOnly();
328
- case "push_first":
329
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget, decision);
330
- case "notify_only":
331
- return handleNotifyOnly(apiKey, description, projectName, sessionId, machineId);
332
- default:
333
- return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name, toolTarget, decision);
403
+ const sessionKey = input.session_id || DEFAULT_SESSION;
404
+ if (!throttlePass(`permdenied:${sessionKey}:${input.tool_name}`, PERMISSION_DENIED_WINDOW_MS)) return void 0;
405
+ const mode = await fetchModeState(apiKey, input.session_id).catch(() => null);
406
+ if (mode?.kill || mode?.mode === "terminal_only") return void 0;
407
+ if (!automodeRetryEnabled()) {
408
+ await sendNotification(apiKey, {
409
+ title: `Auto-mode blocked ${input.tool_name}`,
410
+ body: `Your agent was denied ${input.tool_name} in ${projectName}.`,
411
+ agentName: `Claude Code - ${projectName}`,
412
+ sessionId: input.session_id
413
+ }, 4e3).catch(() => {
414
+ });
415
+ return void 0;
416
+ }
417
+ let result;
418
+ try {
419
+ result = await askUser(apiKey, {
420
+ question: `Auto-mode blocked ${input.tool_name} in ${projectName}. Let the agent retry it?`,
421
+ type: "confirm",
422
+ context: "Your agent hit a permission wall in auto mode",
423
+ agentName: `Claude Code - ${projectName}`,
424
+ sessionId: input.session_id,
425
+ machineId: getMachineId(),
426
+ toolName: input.tool_name
427
+ });
428
+ } catch {
429
+ return void 0;
334
430
  }
431
+ if (result.suppressed || result.noDevices) {
432
+ await cancelQuestion(apiKey, result.correlationId).catch(() => {
433
+ });
434
+ return void 0;
435
+ }
436
+ const deadline = hookWaitDeadline(START_MS, PERMISSION_DENIED_WAIT_SECONDS, "claude", Date.now());
437
+ const answer = await pollForAnswer(apiKey, result.correlationId, deadline);
438
+ if (answer.answered && answer.value === "yes") {
439
+ return { hookSpecificOutput: { hookEventName: "PermissionDenied", retry: true } };
440
+ }
441
+ return void 0;
335
442
  } catch {
336
443
  return void 0;
337
444
  }
338
445
  };
339
446
 
340
447
  export {
341
- handlePreToolUse
448
+ handlePreToolUse,
449
+ handlePermissionRequest,
450
+ handlePermissionDenied
342
451
  };
package/dist/src/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  handlePreToolUse
3
- } from "../chunk-BK4RU2BF.js";
3
+ } from "../chunk-X6L25EOF.js";
4
+ import "../chunk-7EW3USQF.js";
4
5
  import "../chunk-KQYIHZ5E.js";
5
6
  import {
6
7
  askUser,
@@ -14,7 +15,7 @@ import {
14
15
  reportEvent,
15
16
  resolvePolicy,
16
17
  waitForAnswer
17
- } from "../chunk-XVN5SMME.js";
18
+ } from "../chunk-JHN3H6LX.js";
18
19
  import "../chunk-R5AJNXZS.js";
19
20
  import "../chunk-DWED7BS3.js";
20
21
  import "../chunk-Z5PL3K7C.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushary/agent-hooks",
3
- "version": "0.37.0",
3
+ "version": "0.39.0",
4
4
  "description": "Permission hooks for AI coding agents: route tool approvals through Pushary push notifications",
5
5
  "keywords": [
6
6
  "pushary",
@@ -51,6 +51,8 @@
51
51
  "pushary-session-start-hook": "./dist/bin/pushary-session-start-hook.js",
52
52
  "pushary-session-end-hook": "./dist/bin/pushary-session-end-hook.js",
53
53
  "pushary-stopfailure-hook": "./dist/bin/pushary-stopfailure-hook.js",
54
+ "pushary-permission-hook": "./dist/bin/pushary-permission-hook.js",
55
+ "pushary-permission-denied-hook": "./dist/bin/pushary-permission-denied-hook.js",
54
56
  "pushary-claude": "./dist/bin/pushary-claude.js",
55
57
  "pushary-codex": "./dist/bin/pushary-codex.js",
56
58
  "pushary-codex-hook": "./dist/bin/pushary-codex-hook.js",
@@ -70,7 +72,7 @@
70
72
  "scripts": {
71
73
  "build": "node scripts/bundle-plugin.mjs && tsup",
72
74
  "dev": "tsup --watch",
73
- "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/usage.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/safe-commands.test.ts && bun test src/hook.test.ts && bun test src/codex-adapter.test.ts && bun test src/codex-config.test.ts && bun test src/gemini-adapter.test.ts && bun test src/gemini-config.test.ts && bun test src/instruction-file.test.ts && bun test src/pairing.test.ts && bun test src/wait-ladder.test.ts && bun test src/ledger.test.ts && bun test src/wrapper/wrapper.test.ts"
75
+ "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/usage.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/reapply.test.ts && bun test src/suggestions.test.ts && bun test src/safe-commands.test.ts && bun test src/hook.test.ts && bun test src/codex-adapter.test.ts && bun test src/codex-config.test.ts && bun test src/gemini-adapter.test.ts && bun test src/gemini-config.test.ts && bun test src/instruction-file.test.ts && bun test src/pairing.test.ts && bun test src/wait-ladder.test.ts && bun test src/ledger.test.ts && bun test src/wrapper/wrapper.test.ts"
74
76
  },
75
77
  "dependencies": {
76
78
  "@inquirer/prompts": "^8.4.2",