@pushary/agent-hooks 0.94.0 → 0.95.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 (60) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/data/cursor-plugin/CONTRIBUTING.md +31 -19
  3. package/data/vscode-plugin/CONTRIBUTING.md +31 -19
  4. package/dist/bin/pushary-bell-hook.js +22 -1
  5. package/dist/bin/pushary-bell.js +3 -3
  6. package/dist/bin/pushary-claude.js +335 -357
  7. package/dist/bin/pushary-clean.js +21 -16
  8. package/dist/bin/pushary-codex-bridge.js +6 -6
  9. package/dist/bin/pushary-codex-hook.js +20 -2
  10. package/dist/bin/pushary-codex.js +1 -1
  11. package/dist/bin/pushary-connect.js +3 -3
  12. package/dist/bin/pushary-daemon.js +33 -18
  13. package/dist/bin/pushary-disconnect.js +4 -2
  14. package/dist/bin/pushary-doctor.js +31 -28
  15. package/dist/bin/pushary-elicitation-hook.js +21 -1
  16. package/dist/bin/pushary-gemini-bridge.js +6 -6
  17. package/dist/bin/pushary-gemini-hook.js +20 -2
  18. package/dist/bin/pushary-hook.js +20 -3
  19. package/dist/bin/pushary-login.js +3 -3
  20. package/dist/bin/pushary-logout.js +3 -3
  21. package/dist/bin/pushary-mode.js +3 -3
  22. package/dist/bin/pushary-notification-hook.js +20 -2
  23. package/dist/bin/pushary-opencode-hook.js +20 -2
  24. package/dist/bin/pushary-permission-denied-hook.js +21 -3
  25. package/dist/bin/pushary-permission-hook.js +21 -3
  26. package/dist/bin/pushary-post-hook.js +20 -2
  27. package/dist/bin/pushary-prompt-hook.js +20 -2
  28. package/dist/bin/pushary-session-end-hook.js +24 -3
  29. package/dist/bin/pushary-session-start-hook.js +23 -8
  30. package/dist/bin/pushary-setup.js +47 -41
  31. package/dist/bin/pushary-status.js +3 -3
  32. package/dist/bin/pushary-stop-hook.js +20 -2
  33. package/dist/bin/pushary-stopfailure-hook.js +20 -2
  34. package/dist/bin/pushary-suggestions.js +3 -3
  35. package/dist/bin/pushary-transcript-register.d.ts +1 -0
  36. package/dist/bin/pushary-transcript-register.js +42 -0
  37. package/dist/bin/pushary-transcripts.js +1 -1
  38. package/dist/bin/pushary-upgrade.js +11 -10
  39. package/dist/bin/pushary-wait.js +3 -3
  40. package/dist/{chunk-6WYL3XIP.js → chunk-2WVDQVI5.js} +3 -2
  41. package/dist/{chunk-HSAVPZ46.js → chunk-5SJ54JJO.js} +1 -1
  42. package/dist/{chunk-QKNLW7H6.js → chunk-6LQAGVG2.js} +1 -1
  43. package/dist/{chunk-OB4RF2TF.js → chunk-AYJ7NH5S.js} +1 -1
  44. package/dist/chunk-BMOFXRGS.js +185 -0
  45. package/dist/chunk-FH3YLP5Z.js +194 -0
  46. package/dist/chunk-GHCGSEPE.js +86 -0
  47. package/dist/chunk-GI5UQSG7.js +266 -0
  48. package/dist/{chunk-ZO2XG3CX.js → chunk-LSXJH2HB.js} +1 -1
  49. package/dist/{chunk-YANV5TGK.js → chunk-MDQOBG5J.js} +1 -84
  50. package/dist/chunk-N6FAXQDD.js +276 -0
  51. package/dist/{chunk-5HGLZGI4.js → chunk-OXTRFRMD.js} +1 -0
  52. package/dist/chunk-PQ4K74WL.js +30 -0
  53. package/dist/{chunk-46P3VES5.js → chunk-Q5UFC2QK.js} +1 -0
  54. package/dist/{chunk-36LR2LOT.js → chunk-SFCGKE6U.js} +8 -6
  55. package/dist/{chunk-6CUUA7HO.js → chunk-XY4GSZ3K.js} +7 -1
  56. package/dist/chunk-YGZXYEVY.js +503 -0
  57. package/dist/src/index.js +5 -5
  58. package/package.json +3 -2
  59. package/dist/chunk-FYOIW5RV.js +0 -539
  60. package/dist/chunk-RX75MRGC.js +0 -368
@@ -3,7 +3,7 @@ import {
3
3
  decodePublicKey,
4
4
  generateSessionKey,
5
5
  wrapSessionKey
6
- } from "./chunk-46P3VES5.js";
6
+ } from "./chunk-Q5UFC2QK.js";
7
7
  import {
8
8
  fetchTranscriptRecipients,
9
9
  uploadTranscriptRecords
@@ -0,0 +1,185 @@
1
+ import {
2
+ NOTIFICATION_MATCHED_TYPES,
3
+ POSTTOOLUSE_MIRRORED_TOOLS,
4
+ PRETOOLUSE_GATED_TOOLS,
5
+ PRETOOLUSE_PHONE_ANSWERED_TOOLS
6
+ } from "./chunk-Y3UGCQQC.js";
7
+ import {
8
+ isProtectedByScope
9
+ } from "./chunk-Y6XXFXVB.js";
10
+ import {
11
+ HOOK_BUDGETS,
12
+ HOOK_LOCATOR_BINARY
13
+ } from "./chunk-Z6CP5ZZD.js";
14
+
15
+ // src/gemini-config.ts
16
+ var GEMINI_HOOK_BINARY = "pushary-gemini-hook";
17
+ var GEMINI_MCP_URL = "https://pushary.com/api/mcp/mcp";
18
+ var GEMINI_HOOK_EVENTS = [
19
+ { event: "BeforeTool", matcher: "run_shell_command|write_file|replace", delivery: "approval", timeoutMs: HOOK_BUDGETS.gemini.budgetSeconds * 1e3 },
20
+ { event: "AfterTool", matcher: "run_shell_command|write_file|replace", delivery: "telemetry", timeoutMs: 1e4 },
21
+ { event: "BeforeAgent", delivery: "telemetry", timeoutMs: 1e4 },
22
+ { event: "AfterAgent", delivery: "telemetry", timeoutMs: 1e4 },
23
+ { event: "SessionStart", delivery: "telemetry", timeoutMs: 1e4 },
24
+ { event: "SessionEnd", delivery: "telemetry", timeoutMs: 1e4 }
25
+ ];
26
+ var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
27
+ var ensureRecord = (target, key) => {
28
+ const existing = asRecord(target[key]);
29
+ if (existing) return existing;
30
+ const created = {};
31
+ target[key] = created;
32
+ return created;
33
+ };
34
+ var isPusharyGeminiHook = (entry, scope) => {
35
+ const hooks = asRecord(entry)?.hooks;
36
+ if (!Array.isArray(hooks)) return false;
37
+ return hooks.some((hook) => {
38
+ const command = String(asRecord(hook)?.command ?? "");
39
+ if (isProtectedByScope(command, scope)) return false;
40
+ return command.includes(GEMINI_HOOK_BINARY) || command.includes(HOOK_LOCATOR_BINARY);
41
+ });
42
+ };
43
+ var addGeminiMcpServer = (settings, apiKey) => {
44
+ const mcpServers = ensureRecord(settings, "mcpServers");
45
+ mcpServers.pushary = {
46
+ httpUrl: GEMINI_MCP_URL,
47
+ headers: { Authorization: `Bearer ${apiKey}` },
48
+ trust: true
49
+ };
50
+ };
51
+ var addGeminiHooks = (settings, command) => {
52
+ const hooks = ensureRecord(settings, "hooks");
53
+ for (const definition of GEMINI_HOOK_EVENTS) {
54
+ const existing = Array.isArray(hooks[definition.event]) ? hooks[definition.event] : [];
55
+ const entries = existing.filter((entry) => !isPusharyGeminiHook(entry));
56
+ entries.push({
57
+ ...definition.matcher ? { matcher: definition.matcher } : {},
58
+ hooks: [{
59
+ name: "pushary",
60
+ type: "command",
61
+ command,
62
+ timeout: definition.timeoutMs
63
+ }]
64
+ });
65
+ hooks[definition.event] = entries;
66
+ }
67
+ };
68
+ var removeGeminiHooks = (settings, scope) => {
69
+ const hooks = asRecord(settings.hooks);
70
+ if (!hooks) return false;
71
+ let changed = false;
72
+ for (const definition of GEMINI_HOOK_EVENTS) {
73
+ const entries = hooks[definition.event];
74
+ if (!Array.isArray(entries)) continue;
75
+ const filtered = entries.filter((entry) => !isPusharyGeminiHook(entry, scope));
76
+ if (filtered.length !== entries.length) {
77
+ if (filtered.length === 0) {
78
+ delete hooks[definition.event];
79
+ } else {
80
+ hooks[definition.event] = filtered;
81
+ }
82
+ changed = true;
83
+ }
84
+ }
85
+ if (Object.keys(hooks).length === 0) delete settings.hooks;
86
+ return changed;
87
+ };
88
+ var removeGeminiMcpServer = (settings) => {
89
+ const mcpServers = asRecord(settings.mcpServers);
90
+ if (!mcpServers?.pushary) return false;
91
+ delete mcpServers.pushary;
92
+ if (Object.keys(mcpServers).length === 0) delete settings.mcpServers;
93
+ return true;
94
+ };
95
+ var removeGeminiSettings = (settings, scope) => {
96
+ const mcpRemoved = scope?.keepMcpServer === true ? false : removeGeminiMcpServer(settings);
97
+ const hooksRemoved = removeGeminiHooks(settings, scope);
98
+ return mcpRemoved || hooksRemoved;
99
+ };
100
+ var hasGeminiHooks = (settings) => {
101
+ const hooks = asRecord(settings.hooks);
102
+ if (!hooks) return false;
103
+ return GEMINI_HOOK_EVENTS.some((definition) => {
104
+ const entries = hooks[definition.event];
105
+ return Array.isArray(entries) && entries.some((entry) => isPusharyGeminiHook(entry));
106
+ });
107
+ };
108
+ var missingGeminiHookEvents = (settings) => {
109
+ const hooks = asRecord(settings.hooks);
110
+ return GEMINI_HOOK_EVENTS.filter((definition) => {
111
+ const entries = hooks?.[definition.event];
112
+ return !Array.isArray(entries) || !entries.some((entry) => isPusharyGeminiHook(entry));
113
+ }).map((definition) => definition.event);
114
+ };
115
+
116
+ // src/agent-version.ts
117
+ var parseVersion = (raw) => {
118
+ const match = raw.match(/(\d+)\.(\d+)\.(\d+)/);
119
+ return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
120
+ };
121
+ var compareVersion = (a, b) => {
122
+ for (let index = 0; index < 3; index++) {
123
+ if (a[index] !== b[index]) return a[index] < b[index] ? -1 : 1;
124
+ }
125
+ return 0;
126
+ };
127
+ var atLeast = (version, floor) => compareVersion(version, floor) >= 0;
128
+ var formatVersion = (version) => version.join(".");
129
+
130
+ // src/claude-events.ts
131
+ var GATED_TOOLS = [...PRETOOLUSE_GATED_TOOLS, ...PRETOOLUSE_PHONE_ANSWERED_TOOLS].join("|");
132
+ var MIRRORED_TOOLS = POSTTOOLUSE_MIRRORED_TOOLS.join("|");
133
+ var ESTABLISHED = [1, 0, 0];
134
+ var OBSERVED = [2, 0, 0];
135
+ var CLAUDE_HOOK_EVENTS = [
136
+ { event: "PreToolUse", binary: "pushary-hook", matcher: GATED_TOOLS, timeout: HOOK_BUDGETS.claude.budgetSeconds, delivery: "approval", since: ESTABLISHED },
137
+ { event: "PostToolUse", binary: "pushary-post-hook", matcher: MIRRORED_TOOLS, timeout: 10, delivery: "telemetry", since: ESTABLISHED },
138
+ { event: "Stop", binary: "pushary-stop-hook", timeout: 10, delivery: "telemetry", since: ESTABLISHED },
139
+ { event: "UserPromptSubmit", binary: "pushary-prompt-hook", timeout: 10, delivery: "telemetry", since: ESTABLISHED },
140
+ { event: "Notification", binary: "pushary-notification-hook", matcher: NOTIFICATION_MATCHED_TYPES.join("|"), timeout: 10, delivery: "telemetry", since: ESTABLISHED },
141
+ { event: "SessionStart", binary: "pushary-session-start-hook", matcher: "startup|resume|clear", timeout: 10, delivery: "telemetry", since: ESTABLISHED },
142
+ { event: "SessionEnd", binary: "pushary-session-end-hook", timeout: 10, delivery: "telemetry", since: ESTABLISHED },
143
+ { event: "StopFailure", binary: "pushary-stopfailure-hook", timeout: 10, delivery: "telemetry", since: ESTABLISHED },
144
+ { event: "PermissionRequest", binary: "pushary-permission-hook", timeout: HOOK_BUDGETS.claude.budgetSeconds, delivery: "approval", since: ESTABLISHED },
145
+ { event: "PermissionDenied", binary: "pushary-permission-denied-hook", timeout: 60, delivery: "telemetry", since: ESTABLISHED },
146
+ // Observability only. Each carries session shape the island cannot get any other
147
+ // way, and none of them decides anything.
148
+ { event: "SubagentStart", binary: "pushary-session-start-hook", timeout: 10, delivery: "telemetry", since: OBSERVED },
149
+ { event: "SubagentStop", binary: "pushary-stop-hook", timeout: 10, delivery: "telemetry", since: OBSERVED },
150
+ { event: "PreCompact", binary: "pushary-post-hook", matcher: "manual|auto", timeout: 10, delivery: "telemetry", since: OBSERVED },
151
+ { event: "PostCompact", binary: "pushary-post-hook", matcher: "manual|auto", timeout: 10, delivery: "telemetry", since: OBSERVED },
152
+ { event: "TeammateIdle", binary: "pushary-notification-hook", timeout: 10, delivery: "telemetry", since: OBSERVED },
153
+ // An MCP server asking the person for a value, answered from the phone rather
154
+ // than the terminal. No matcher: Claude Code matches this event on the MCP
155
+ // server's name, and we have no business preferring one server over another.
156
+ { event: "Elicitation", binary: "pushary-elicitation-hook", timeout: HOOK_BUDGETS.claude.budgetSeconds, delivery: "approval", since: OBSERVED }
157
+ ];
158
+ var supportedClaudeEvents = (version) => CLAUDE_HOOK_EVENTS.filter((hook) => version ? atLeast(version, hook.since) : hook.since === ESTABLISHED);
159
+ var registrationSignatures = (events, version) => Object.fromEntries(
160
+ events.map((hook) => [hook.event, `registered|${version ? formatVersion(version) : "unknown"}`])
161
+ );
162
+ var needsReregistration = (stored, version) => {
163
+ const expected = registrationSignatures(supportedClaudeEvents(version), version);
164
+ const keys = Object.keys(expected);
165
+ if (!stored) return true;
166
+ if (keys.length !== Object.keys(stored).length) return true;
167
+ return keys.some((event) => stored[event] !== expected[event]);
168
+ };
169
+
170
+ export {
171
+ GEMINI_HOOK_BINARY,
172
+ GEMINI_HOOK_EVENTS,
173
+ addGeminiMcpServer,
174
+ addGeminiHooks,
175
+ removeGeminiSettings,
176
+ hasGeminiHooks,
177
+ missingGeminiHookEvents,
178
+ parseVersion,
179
+ compareVersion,
180
+ formatVersion,
181
+ CLAUDE_HOOK_EVENTS,
182
+ supportedClaudeEvents,
183
+ registrationSignatures,
184
+ needsReregistration
185
+ };
@@ -0,0 +1,194 @@
1
+ import {
2
+ CLAUDE_HOOK_EVENTS,
3
+ supportedClaudeEvents
4
+ } from "./chunk-BMOFXRGS.js";
5
+ import {
6
+ guardBinary
7
+ } from "./chunk-EZIEXHYM.js";
8
+ import {
9
+ isProtectedByScope
10
+ } from "./chunk-Y6XXFXVB.js";
11
+ import {
12
+ HOOK_LOCATOR_BINARY
13
+ } from "./chunk-Z6CP5ZZD.js";
14
+
15
+ // src/claude-config.ts
16
+ import { join } from "path";
17
+ import { isDeepStrictEqual } from "util";
18
+ var PUSHARY_MCP_URL = "https://pushary.com/api/mcp/mcp";
19
+ var PUSHARY_PERMISSION_RULE = "mcp__pushary__*";
20
+ var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
21
+ var ensureRecord = (target, key) => {
22
+ const existing = asRecord(target[key]);
23
+ if (existing) return existing;
24
+ const created = {};
25
+ target[key] = created;
26
+ return created;
27
+ };
28
+ var isPusharyPermission = (rule) => typeof rule === "string" && (rule.includes("pushary") || rule.includes("MCP(pushary"));
29
+ var HOOK_BINARIES = /* @__PURE__ */ new Set([
30
+ ...CLAUDE_HOOK_EVENTS.map((hook) => hook.binary),
31
+ HOOK_LOCATOR_BINARY
32
+ ]);
33
+ var namesPusharyBinary = (command) => command.split(/[\s/\\"']+/).some((segment) => HOOK_BINARIES.has(segment.replace(/\.(cmd|exe)$/i, "")));
34
+ var isPusharyHook = (entry2, scope) => {
35
+ const hooks = asRecord(entry2)?.hooks;
36
+ if (!Array.isArray(hooks)) return false;
37
+ return hooks.some((hook) => {
38
+ const command = String(asRecord(hook)?.command ?? "");
39
+ if (isProtectedByScope(command, scope)) return false;
40
+ return namesPusharyBinary(command);
41
+ });
42
+ };
43
+ var pusharyMcpServer = (apiKey) => ({
44
+ type: "http",
45
+ url: PUSHARY_MCP_URL,
46
+ headers: { Authorization: `Bearer ${apiKey}` }
47
+ });
48
+ var addClaudeMcpServer = (config, apiKey) => {
49
+ const mcpServers = ensureRecord(config, "mcpServers");
50
+ mcpServers.pushary = pusharyMcpServer(apiKey);
51
+ };
52
+ var isClaudeMcpSnapshot = (value) => {
53
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
54
+ const snapshot = value;
55
+ return typeof snapshot.hadMcpServers === "boolean" && typeof snapshot.mcpServersWasRecord === "boolean" && (!snapshot.hadMcpServers || snapshot.mcpServersWasRecord || Object.hasOwn(snapshot, "mcpServers")) && typeof snapshot.hadPushary === "boolean" && (!snapshot.hadPushary || Object.hasOwn(snapshot, "pushary")) && (!Object.hasOwn(snapshot, "installedPushary") || asRecord(snapshot.installedPushary)?.type === "http" && asRecord(snapshot.installedPushary)?.url === PUSHARY_MCP_URL);
56
+ };
57
+ var captureClaudeMcpServer = (config, apiKey) => {
58
+ const mcpServers = asRecord(config.mcpServers);
59
+ const hadMcpServers = Object.hasOwn(config, "mcpServers");
60
+ return {
61
+ hadMcpServers,
62
+ mcpServersWasRecord: Boolean(mcpServers),
63
+ ...hadMcpServers && !mcpServers ? { mcpServers: structuredClone(config.mcpServers) } : {},
64
+ hadPushary: Boolean(mcpServers && Object.hasOwn(mcpServers, "pushary")),
65
+ ...mcpServers && Object.hasOwn(mcpServers, "pushary") ? { pushary: structuredClone(mcpServers.pushary) } : {},
66
+ ...apiKey ? { installedPushary: pusharyMcpServer(apiKey) } : {}
67
+ };
68
+ };
69
+ var updateClaudeMcpSnapshot = (snapshot, apiKey) => ({
70
+ ...snapshot,
71
+ installedPushary: pusharyMcpServer(apiKey)
72
+ });
73
+ var restoreClaudeMcpServer = (config, snapshot) => {
74
+ const mcpServers = asRecord(config.mcpServers);
75
+ const current = asRecord(mcpServers?.pushary);
76
+ if (Object.hasOwn(snapshot, "installedPushary")) {
77
+ if (!isDeepStrictEqual(mcpServers?.pushary, snapshot.installedPushary)) return false;
78
+ } else if (current?.type !== "http" || current.url !== PUSHARY_MCP_URL) {
79
+ return false;
80
+ }
81
+ if (!snapshot.mcpServersWasRecord) {
82
+ if (Object.keys(mcpServers).length === 1) {
83
+ if (snapshot.hadMcpServers) config.mcpServers = structuredClone(snapshot.mcpServers);
84
+ else delete config.mcpServers;
85
+ } else {
86
+ delete mcpServers.pushary;
87
+ }
88
+ } else if (snapshot.hadPushary) {
89
+ mcpServers.pushary = structuredClone(snapshot.pushary);
90
+ } else {
91
+ delete mcpServers.pushary;
92
+ if (!snapshot.hadMcpServers && Object.keys(mcpServers).length === 0) delete config.mcpServers;
93
+ }
94
+ return true;
95
+ };
96
+ var removeClaudeMcpServers = (config) => {
97
+ let changed = false;
98
+ const removeFrom = (target) => {
99
+ const mcpServers = asRecord(target.mcpServers);
100
+ if (!mcpServers?.pushary) return;
101
+ delete mcpServers.pushary;
102
+ if (Object.keys(mcpServers).length === 0) delete target.mcpServers;
103
+ changed = true;
104
+ };
105
+ removeFrom(config);
106
+ const projects = asRecord(config.projects);
107
+ if (projects) {
108
+ for (const project of Object.values(projects)) {
109
+ const projectConfig = asRecord(project);
110
+ if (projectConfig) removeFrom(projectConfig);
111
+ }
112
+ }
113
+ return changed;
114
+ };
115
+ var addPusharyToolPermissions = (settings) => {
116
+ const permissions = ensureRecord(settings, "permissions");
117
+ const allow = Array.isArray(permissions.allow) ? permissions.allow : [];
118
+ const filtered = allow.filter((rule) => !isPusharyPermission(rule));
119
+ if (!filtered.includes(PUSHARY_PERMISSION_RULE)) {
120
+ filtered.push(PUSHARY_PERMISSION_RULE);
121
+ }
122
+ permissions.allow = filtered;
123
+ };
124
+ var addPusharyHooks = (settings, binDir, version = null) => {
125
+ const resolve = (name) => guardBinary(binDir ? join(binDir, name) : name);
126
+ const hooks = ensureRecord(settings, "hooks");
127
+ const supported = new Map(supportedClaudeEvents(version).map((hook) => [hook.event, hook]));
128
+ for (const known of CLAUDE_HOOK_EVENTS) {
129
+ const current = hooks[known.event];
130
+ const others = (Array.isArray(current) ? current : []).filter((item) => !isPusharyHook(item));
131
+ const definition = supported.get(known.event);
132
+ if (definition) {
133
+ hooks[known.event] = [...others, entry(definition, resolve)];
134
+ } else if (others.length > 0) {
135
+ hooks[known.event] = others;
136
+ } else {
137
+ delete hooks[known.event];
138
+ }
139
+ }
140
+ };
141
+ var entry = (definition, resolve) => ({
142
+ ...definition.matcher ? { matcher: definition.matcher } : {},
143
+ hooks: [{
144
+ type: "command",
145
+ command: resolve(definition.binary),
146
+ timeout: definition.timeout
147
+ }]
148
+ });
149
+ var removePusharySettings = (settings, scope) => {
150
+ let changed = scope?.keepMcpServer === true ? false : removeClaudeMcpServers(settings);
151
+ const permissions = scope?.keepMcpServer === true ? void 0 : asRecord(settings.permissions);
152
+ if (permissions && Array.isArray(permissions.allow)) {
153
+ const filtered = permissions.allow.filter((rule) => !isPusharyPermission(rule));
154
+ if (filtered.length !== permissions.allow.length) {
155
+ if (filtered.length === 0) {
156
+ delete permissions.allow;
157
+ } else {
158
+ permissions.allow = filtered;
159
+ }
160
+ if (Object.keys(permissions).length === 0) delete settings.permissions;
161
+ changed = true;
162
+ }
163
+ }
164
+ const hooks = asRecord(settings.hooks);
165
+ if (hooks) {
166
+ for (const { event: key } of CLAUDE_HOOK_EVENTS) {
167
+ const entries = hooks[key];
168
+ if (!Array.isArray(entries)) continue;
169
+ const filtered = entries.filter((entry2) => !isPusharyHook(entry2, scope));
170
+ if (filtered.length !== entries.length) {
171
+ if (filtered.length === 0) {
172
+ delete hooks[key];
173
+ } else {
174
+ hooks[key] = filtered;
175
+ }
176
+ changed = true;
177
+ }
178
+ }
179
+ if (Object.keys(hooks).length === 0) delete settings.hooks;
180
+ }
181
+ return changed;
182
+ };
183
+
184
+ export {
185
+ addClaudeMcpServer,
186
+ isClaudeMcpSnapshot,
187
+ captureClaudeMcpServer,
188
+ updateClaudeMcpSnapshot,
189
+ restoreClaudeMcpServer,
190
+ removeClaudeMcpServers,
191
+ addPusharyToolPermissions,
192
+ addPusharyHooks,
193
+ removePusharySettings
194
+ };
@@ -0,0 +1,86 @@
1
+ import {
2
+ HOOK_LOCATOR_BINARY
3
+ } from "./chunk-Z6CP5ZZD.js";
4
+
5
+ // src/diagnostics/bridge.ts
6
+ import { execFileSync } from "child_process";
7
+ import { existsSync, readFileSync } from "fs";
8
+ import { homedir } from "os";
9
+ import { dirname, join } from "path";
10
+ var BRIDGE_BUNDLE_IDENTIFIER = "com.pushary.app";
11
+ var BRIDGE_HELPER_SUFFIX = "/Contents/Helpers/pushary-bridge";
12
+ var BRIDGE_BUNDLE_ROOTS = ["/Applications/Pushary.app", "$HOME/Applications/Pushary.app"];
13
+ var expandHome = (path, home) => path.replaceAll("$HOME", home);
14
+ var parseBridgeStub = (contents, stubPath) => {
15
+ const helperSuffix = contents.match(/^H=(\S+)$/m)?.[1] ?? BRIDGE_HELPER_SUFFIX;
16
+ const cachePath = contents.match(/^C="([^"\n]+)"$/m)?.[1] ?? join(dirname(stubPath), ".bridge-cache");
17
+ const rootsLine = contents.match(/^for P in ((?:"[^"\n]*"\s*)+); do$/m)?.[1];
18
+ const bundleRoots = rootsLine ? [...rootsLine.matchAll(/"([^"]*)"/g)].map((match) => match[1]) : BRIDGE_BUNDLE_ROOTS;
19
+ const bundleIdentifier = contents.match(/kMDItemCFBundleIdentifier == "([^"]+)"/)?.[1] ?? BRIDGE_BUNDLE_IDENTIFIER;
20
+ return { helperSuffix, cachePath, bundleRoots, bundleIdentifier };
21
+ };
22
+ var resolveBridgeStub = (stubPath, probe) => {
23
+ const contents = probe.readFile(stubPath);
24
+ if (contents === null) return { kind: "no-stub", stub: stubPath };
25
+ const shape = parseBridgeStub(contents, stubPath);
26
+ const helperIn = (bundle) => `${bundle}${shape.helperSuffix}`;
27
+ const looked = [];
28
+ for (const root of shape.bundleRoots.map((root2) => expandHome(root2, probe.home))) {
29
+ looked.push(root);
30
+ if (probe.exists(helperIn(root))) return { kind: "bundle", helper: helperIn(root), via: "root" };
31
+ }
32
+ const cached = shape.cachePath ? probe.readFile(shape.cachePath)?.split("\n")[0]?.trim() : void 0;
33
+ if (cached) {
34
+ looked.push(cached);
35
+ if (probe.exists(helperIn(cached))) return { kind: "bundle", helper: helperIn(cached), via: "cache" };
36
+ }
37
+ for (const found of probe.mdfind(shape.bundleIdentifier)) {
38
+ looked.push(found);
39
+ if (probe.exists(helperIn(found))) return { kind: "bundle", helper: helperIn(found), via: "spotlight" };
40
+ }
41
+ return { kind: "missing", stub: stubPath, looked };
42
+ };
43
+ var BRIDGE_GONE_MESSAGE = "the Mac app is gone but its hooks remain; run pushary setup or reinstall the app";
44
+ var describeBridgeResolution = (resolution) => {
45
+ switch (resolution.kind) {
46
+ case "bundle":
47
+ return `${resolution.helper} (${resolution.via === "root" ? "installed" : resolution.via === "cache" ? "cached path" : "found by Spotlight"})`;
48
+ case "missing":
49
+ return BRIDGE_GONE_MESSAGE;
50
+ case "no-stub":
51
+ return `${resolution.stub} is not there; ${BRIDGE_GONE_MESSAGE}`;
52
+ }
53
+ };
54
+ var isBridgeLocator = (executable) => executable !== null && executable.split(/[/\\]/).pop() === HOOK_LOCATOR_BINARY;
55
+ var spotlight = (bundleIdentifier) => {
56
+ if (process.platform !== "darwin") return [];
57
+ try {
58
+ return execFileSync("/usr/bin/mdfind", [`kMDItemCFBundleIdentifier == "${bundleIdentifier}"`], {
59
+ encoding: "utf-8",
60
+ timeout: 5e3,
61
+ stdio: ["ignore", "pipe", "ignore"]
62
+ }).split("\n").map((line) => line.trim()).filter((line) => line !== "");
63
+ } catch {
64
+ return [];
65
+ }
66
+ };
67
+ var readOrNull = (path) => {
68
+ try {
69
+ return readFileSync(path, "utf-8");
70
+ } catch {
71
+ return null;
72
+ }
73
+ };
74
+ var liveBridgeProbe = () => ({
75
+ exists: existsSync,
76
+ readFile: readOrNull,
77
+ mdfind: spotlight,
78
+ home: homedir()
79
+ });
80
+
81
+ export {
82
+ resolveBridgeStub,
83
+ describeBridgeResolution,
84
+ isBridgeLocator,
85
+ liveBridgeProbe
86
+ };