@pushary/agent-hooks 0.25.0 → 0.26.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 (94) hide show
  1. package/dist/bin/pushary-clean.js +1 -1
  2. package/dist/bin/pushary-codex-hook.js +1 -1
  3. package/dist/bin/pushary-codex.js +1 -1
  4. package/dist/bin/pushary-doctor.js +21 -9
  5. package/dist/bin/pushary-gemini-hook.js +1 -1
  6. package/dist/bin/pushary-hook.js +2 -2
  7. package/dist/bin/pushary-post-hook.js +1 -1
  8. package/dist/bin/pushary-prompt-hook.js +1 -1
  9. package/dist/bin/pushary-setup.js +7 -19
  10. package/dist/bin/pushary-stop-hook.js +1 -1
  11. package/dist/{chunk-GYPPVD3P.js → chunk-A7DQCA2N.js} +1 -1
  12. package/dist/{chunk-O2QL6U6G.js → chunk-SA4BDS7T.js} +1 -1
  13. package/dist/{chunk-JPRRYC5X.js → chunk-SLX4AONG.js} +25 -0
  14. package/dist/src/index.js +2 -2
  15. package/package.json +1 -1
  16. package/dist/chunk-22CV7V7A.js +0 -38
  17. package/dist/chunk-2BE2IPMO.js +0 -315
  18. package/dist/chunk-2CRLBMOX.js +0 -244
  19. package/dist/chunk-2HMNOZPY.js +0 -109
  20. package/dist/chunk-2I6DLXJN.js +0 -219
  21. package/dist/chunk-2Q6XPZ4Q.js +0 -395
  22. package/dist/chunk-3LC4YUMA.js +0 -194
  23. package/dist/chunk-3MIR7ODJ.js +0 -112
  24. package/dist/chunk-3QZESA66.js +0 -222
  25. package/dist/chunk-4Z4MB37G.js +0 -96
  26. package/dist/chunk-5GFUI5N6.js +0 -132
  27. package/dist/chunk-5JEDLXEC.js +0 -99
  28. package/dist/chunk-5LTQNC7R.js +0 -824
  29. package/dist/chunk-5QHQVXWN.js +0 -174
  30. package/dist/chunk-6A3WCJO2.js +0 -416
  31. package/dist/chunk-6QWFMVCD.js +0 -328
  32. package/dist/chunk-6SRXMZAN.js +0 -99
  33. package/dist/chunk-7PTU7TGE.js +0 -96
  34. package/dist/chunk-AB4KX4XT.js +0 -109
  35. package/dist/chunk-AC4UYAGX.js +0 -136
  36. package/dist/chunk-ACE77TKQ.js +0 -328
  37. package/dist/chunk-BHAMEPOP.js +0 -323
  38. package/dist/chunk-BYNYYZWW.js +0 -412
  39. package/dist/chunk-C5TFTNHG.js +0 -244
  40. package/dist/chunk-CH53PBQN.js +0 -265
  41. package/dist/chunk-DF3BM6BF.js +0 -195
  42. package/dist/chunk-DKZVKEOW.js +0 -175
  43. package/dist/chunk-EMPL27ZV.js +0 -96
  44. package/dist/chunk-EQJXMEIR.js +0 -175
  45. package/dist/chunk-FGZZRCOG.js +0 -194
  46. package/dist/chunk-FXYTRZHC.js +0 -177
  47. package/dist/chunk-GTJGZBTQ.js +0 -328
  48. package/dist/chunk-HJMFYDWY.js +0 -222
  49. package/dist/chunk-HRQEECB6.js +0 -315
  50. package/dist/chunk-HWEMAAOY.js +0 -370
  51. package/dist/chunk-IBWCHA5M.js +0 -10
  52. package/dist/chunk-KTM4ZQ3W.js +0 -96
  53. package/dist/chunk-KTP2EPVB.js +0 -27
  54. package/dist/chunk-KYARP7KP.js +0 -97
  55. package/dist/chunk-M2N5DYWN.js +0 -247
  56. package/dist/chunk-M4GDBGXF.js +0 -824
  57. package/dist/chunk-M5F2L4KF.js +0 -177
  58. package/dist/chunk-M6S3M6E3.js +0 -244
  59. package/dist/chunk-N7VXDBQU.js +0 -6
  60. package/dist/chunk-O6A5RHWY.js +0 -122
  61. package/dist/chunk-ODUXELPM.js +0 -219
  62. package/dist/chunk-OF5WIOYS.js +0 -129
  63. package/dist/chunk-OP4QAN23.js +0 -99
  64. package/dist/chunk-P4JH2Q7Z.js +0 -102
  65. package/dist/chunk-PMD5JSV3.js +0 -242
  66. package/dist/chunk-PSSHNBEL.js +0 -177
  67. package/dist/chunk-QEPRH7JB.js +0 -315
  68. package/dist/chunk-QRXWPZKN.js +0 -308
  69. package/dist/chunk-QY4L6XHN.js +0 -384
  70. package/dist/chunk-RNWPCELY.js +0 -176
  71. package/dist/chunk-RSHN2AQ7.js +0 -29
  72. package/dist/chunk-RZLVE57X.js +0 -38
  73. package/dist/chunk-SDCIKREA.js +0 -241
  74. package/dist/chunk-SDREQWNI.js +0 -175
  75. package/dist/chunk-SH26ZOHU.js +0 -159
  76. package/dist/chunk-TRLBBLSS.js +0 -176
  77. package/dist/chunk-U6OXZPYC.js +0 -384
  78. package/dist/chunk-UIBTFZUD.js +0 -314
  79. package/dist/chunk-USUCPCUC.js +0 -156
  80. package/dist/chunk-V4GLWPD7.js +0 -174
  81. package/dist/chunk-VC6U3QGF.js +0 -142
  82. package/dist/chunk-VIST7ACL.js +0 -88
  83. package/dist/chunk-VUNL35KE.js +0 -16
  84. package/dist/chunk-VWBNI4SC.js +0 -174
  85. package/dist/chunk-W5KRWUNE.js +0 -262
  86. package/dist/chunk-WCGKLHCL.js +0 -154
  87. package/dist/chunk-WNXGIEX7.js +0 -219
  88. package/dist/chunk-WPVL6VIT.js +0 -160
  89. package/dist/chunk-XPVSZIA3.js +0 -315
  90. package/dist/chunk-Y633ZIJF.js +0 -384
  91. package/dist/chunk-YCL4GUFR.js +0 -222
  92. package/dist/chunk-YTMKB44I.js +0 -220
  93. package/dist/chunk-ZWBS3T7Q.js +0 -244
  94. package/dist/pushary-mode-T7XOPI6Z.js +0 -83
@@ -1,323 +0,0 @@
1
- // src/codex-config.ts
2
- import { createHash } from "crypto";
3
- var CODEX_HOOK_BINARY = "pushary-codex-hook";
4
- var CODEX_HOOK_EVENTS = [
5
- { event: "PermissionRequest", matcher: "Bash|apply_patch", timeout: 180, statusMessage: "Waiting for your phone" },
6
- { event: "PreToolUse", matcher: "Bash|apply_patch", timeout: 180, statusMessage: "Checking Pushary policy" },
7
- { event: "PostToolUse", matcher: "Bash|apply_patch", timeout: 10 },
8
- { event: "UserPromptSubmit", timeout: 10 },
9
- { event: "Stop", timeout: 10 },
10
- { event: "SessionStart", matcher: "startup|resume", timeout: 10 }
11
- ];
12
- var CODEX_EVENT_KEY = {
13
- PermissionRequest: "permission_request",
14
- PreToolUse: "pre_tool_use",
15
- PostToolUse: "post_tool_use",
16
- UserPromptSubmit: "user_prompt_submit",
17
- Stop: "stop",
18
- SessionStart: "session_start"
19
- };
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 isPusharyCodexHook = (entry) => {
29
- const hooks = asRecord(entry)?.hooks;
30
- if (!Array.isArray(hooks)) return false;
31
- return hooks.some((hook) => String(asRecord(hook)?.command ?? "").includes(CODEX_HOOK_BINARY));
32
- };
33
- var addCodexHooks = (config, command) => {
34
- const hooks = ensureRecord(config, "hooks");
35
- for (const definition of CODEX_HOOK_EVENTS) {
36
- const existing = Array.isArray(hooks[definition.event]) ? hooks[definition.event] : [];
37
- const entries = existing.filter((entry) => !isPusharyCodexHook(entry));
38
- entries.push({
39
- ...definition.matcher ? { matcher: definition.matcher } : {},
40
- hooks: [{
41
- type: "command",
42
- command,
43
- timeout: definition.timeout,
44
- ...definition.statusMessage ? { statusMessage: definition.statusMessage } : {}
45
- }]
46
- });
47
- hooks[definition.event] = entries;
48
- }
49
- };
50
- var removeCodexHooks = (config) => {
51
- const hooks = asRecord(config.hooks);
52
- if (!hooks) return false;
53
- let changed = false;
54
- for (const definition of CODEX_HOOK_EVENTS) {
55
- const entries = hooks[definition.event];
56
- if (!Array.isArray(entries)) continue;
57
- const filtered = entries.filter((entry) => !isPusharyCodexHook(entry));
58
- if (filtered.length !== entries.length) {
59
- if (filtered.length === 0) {
60
- delete hooks[definition.event];
61
- } else {
62
- hooks[definition.event] = filtered;
63
- }
64
- changed = true;
65
- }
66
- }
67
- if (Object.keys(hooks).length === 0) delete config.hooks;
68
- return changed;
69
- };
70
- var hasCodexHooks = (config) => {
71
- const hooks = asRecord(config.hooks);
72
- if (!hooks) return false;
73
- return CODEX_HOOK_EVENTS.some((definition) => {
74
- const entries = hooks[definition.event];
75
- return Array.isArray(entries) && entries.some(isPusharyCodexHook);
76
- });
77
- };
78
- var missingCodexHookEvents = (config) => {
79
- const hooks = asRecord(config.hooks);
80
- return CODEX_HOOK_EVENTS.filter((definition) => {
81
- const entries = hooks?.[definition.event];
82
- return !Array.isArray(entries) || !entries.some(isPusharyCodexHook);
83
- }).map((definition) => definition.event);
84
- };
85
- var canonicalJson = (value) => {
86
- if (value === null || typeof value !== "object") return JSON.stringify(value);
87
- if (Array.isArray(value)) return "[" + value.map(canonicalJson).join(",") + "]";
88
- const obj = value;
89
- return "{" + Object.keys(obj).sort().map((key) => JSON.stringify(key) + ":" + canonicalJson(obj[key])).join(",") + "}";
90
- };
91
- var codexHookTrustHash = (definition, command) => {
92
- const hook = { async: false, command, timeout: definition.timeout, type: "command" };
93
- if (definition.statusMessage) hook.statusMessage = definition.statusMessage;
94
- const identity = { event_name: CODEX_EVENT_KEY[definition.event], hooks: [hook] };
95
- if (definition.matcher) identity.matcher = definition.matcher;
96
- return "sha256:" + createHash("sha256").update(canonicalJson(identity), "utf8").digest("hex");
97
- };
98
- var codexHookStateKey = (hooksJsonPath, event) => `${hooksJsonPath}:${CODEX_EVENT_KEY[event]}:0:0`;
99
- var untrustedCodexHookEvents = (config, hooksJsonPath, command) => {
100
- const state = asRecord(asRecord(config.hooks)?.state);
101
- return CODEX_HOOK_EVENTS.filter((definition) => {
102
- const entry = asRecord(state?.[codexHookStateKey(hooksJsonPath, definition.event)]);
103
- const stored = entry?.trusted_hash;
104
- return stored !== codexHookTrustHash(definition, command);
105
- }).map((definition) => definition.event);
106
- };
107
- var addCodexHookTrust = (config, hooksJsonPath, command) => {
108
- const hooks = ensureRecord(config, "hooks");
109
- const state = ensureRecord(hooks, "state");
110
- for (const definition of CODEX_HOOK_EVENTS) {
111
- const key = codexHookStateKey(hooksJsonPath, definition.event);
112
- const existing = asRecord(state[key]) ?? {};
113
- state[key] = { ...existing, trusted_hash: codexHookTrustHash(definition, command) };
114
- }
115
- };
116
-
117
- // src/gemini-config.ts
118
- var GEMINI_HOOK_BINARY = "pushary-gemini-hook";
119
- var GEMINI_MCP_URL = "https://pushary.com/api/mcp/mcp";
120
- var GEMINI_HOOK_EVENTS = [
121
- { event: "BeforeTool", matcher: "run_shell_command|write_file|replace", timeoutMs: 18e4 },
122
- { event: "AfterTool", matcher: "run_shell_command|write_file|replace", timeoutMs: 1e4 },
123
- { event: "BeforeAgent", timeoutMs: 1e4 },
124
- { event: "SessionStart", timeoutMs: 1e4 },
125
- { event: "SessionEnd", timeoutMs: 1e4 }
126
- ];
127
- var asRecord2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
128
- var ensureRecord2 = (target, key) => {
129
- const existing = asRecord2(target[key]);
130
- if (existing) return existing;
131
- const created = {};
132
- target[key] = created;
133
- return created;
134
- };
135
- var isPusharyGeminiHook = (entry) => {
136
- const hooks = asRecord2(entry)?.hooks;
137
- if (!Array.isArray(hooks)) return false;
138
- return hooks.some((hook) => String(asRecord2(hook)?.command ?? "").includes(GEMINI_HOOK_BINARY));
139
- };
140
- var addGeminiMcpServer = (settings, apiKey) => {
141
- const mcpServers = ensureRecord2(settings, "mcpServers");
142
- mcpServers.pushary = {
143
- httpUrl: GEMINI_MCP_URL,
144
- headers: { Authorization: `Bearer ${apiKey}` },
145
- trust: true
146
- };
147
- };
148
- var addGeminiHooks = (settings, command) => {
149
- const hooks = ensureRecord2(settings, "hooks");
150
- for (const definition of GEMINI_HOOK_EVENTS) {
151
- const existing = Array.isArray(hooks[definition.event]) ? hooks[definition.event] : [];
152
- const entries = existing.filter((entry) => !isPusharyGeminiHook(entry));
153
- entries.push({
154
- ...definition.matcher ? { matcher: definition.matcher } : {},
155
- hooks: [{
156
- name: "pushary",
157
- type: "command",
158
- command,
159
- timeout: definition.timeoutMs
160
- }]
161
- });
162
- hooks[definition.event] = entries;
163
- }
164
- };
165
- var removeGeminiHooks = (settings) => {
166
- const hooks = asRecord2(settings.hooks);
167
- if (!hooks) return false;
168
- let changed = false;
169
- for (const definition of GEMINI_HOOK_EVENTS) {
170
- const entries = hooks[definition.event];
171
- if (!Array.isArray(entries)) continue;
172
- const filtered = entries.filter((entry) => !isPusharyGeminiHook(entry));
173
- if (filtered.length !== entries.length) {
174
- if (filtered.length === 0) {
175
- delete hooks[definition.event];
176
- } else {
177
- hooks[definition.event] = filtered;
178
- }
179
- changed = true;
180
- }
181
- }
182
- if (Object.keys(hooks).length === 0) delete settings.hooks;
183
- return changed;
184
- };
185
- var removeGeminiMcpServer = (settings) => {
186
- const mcpServers = asRecord2(settings.mcpServers);
187
- if (!mcpServers?.pushary) return false;
188
- delete mcpServers.pushary;
189
- if (Object.keys(mcpServers).length === 0) delete settings.mcpServers;
190
- return true;
191
- };
192
- var removeGeminiSettings = (settings) => {
193
- const mcpRemoved = removeGeminiMcpServer(settings);
194
- const hooksRemoved = removeGeminiHooks(settings);
195
- return mcpRemoved || hooksRemoved;
196
- };
197
- var hasGeminiHooks = (settings) => {
198
- const hooks = asRecord2(settings.hooks);
199
- if (!hooks) return false;
200
- return GEMINI_HOOK_EVENTS.some((definition) => {
201
- const entries = hooks[definition.event];
202
- return Array.isArray(entries) && entries.some(isPusharyGeminiHook);
203
- });
204
- };
205
- var missingGeminiHookEvents = (settings) => {
206
- const hooks = asRecord2(settings.hooks);
207
- return GEMINI_HOOK_EVENTS.filter((definition) => {
208
- const entries = hooks?.[definition.event];
209
- return !Array.isArray(entries) || !entries.some(isPusharyGeminiHook);
210
- }).map((definition) => definition.event);
211
- };
212
-
213
- // src/instruction-file.ts
214
- import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync } from "fs";
215
- import { dirname } from "path";
216
- var PUSHARY_BEGIN = "<!-- BEGIN PUSHARY (managed by @pushary/agent-hooks; do not edit this block) -->";
217
- var PUSHARY_END = "<!-- END PUSHARY -->";
218
- var instructionBody = (label) => `## Pushary notifications and approvals
219
-
220
- You have Pushary MCP tools that reach the user on their phone. Use them proactively. Do not wait for the user to ask.
221
-
222
- - When you need the user to make a decision or answer a clarifying question, call \`ask_user\` instead of guessing or stalling. Use type "confirm" for yes/no, "select" for a fixed set of options, and "input" for free text. \`ask_user\` blocks until the user replies or it times out, so you do not need a separate wait step.
223
- - Before any risky or irreversible step (deleting files, force pushing, spending money, sending external messages), call \`ask_user\` with type "confirm" and wait for approval.
224
- - When you are blocked, stuck, or hit an error you cannot resolve on your own, call \`send_notification\` so the user knows, and call \`ask_user\` if you need a decision to continue.
225
- - When a task that took several steps finishes, call \`send_notification\` so the user knows it is done.
226
- - Use \`cancel_question\` to retract a pending question once it is no longer needed.
227
-
228
- Pass \`agentName\` as "${label} - <project folder name>" so the user knows which session is asking. If a question times out with no answer, retry once with a longer timeout before falling back to asking in the terminal.`;
229
- var renderAgentInstructions = (label) => instructionBody(label);
230
- var wrap = (body) => `${PUSHARY_BEGIN}
231
- ${body}
232
- ${PUSHARY_END}`;
233
- var writeInstructionBlock = (filePath, body) => {
234
- const dir = dirname(filePath);
235
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
236
- let existing = "";
237
- try {
238
- existing = readFileSync(filePath, "utf-8");
239
- } catch {
240
- }
241
- const block = wrap(body);
242
- const start = existing.indexOf(PUSHARY_BEGIN);
243
- const end = existing.indexOf(PUSHARY_END);
244
- let next;
245
- if (start !== -1 && end !== -1 && end > start) {
246
- next = existing.slice(0, start) + block + existing.slice(end + PUSHARY_END.length);
247
- } else {
248
- const prefix = existing.trim() ? existing.replace(/\s*$/, "") + "\n\n" : "";
249
- next = prefix + block + "\n";
250
- }
251
- writeFileSync(filePath, next, "utf-8");
252
- };
253
- var removeInstructionBlock = (filePath) => {
254
- let existing = "";
255
- try {
256
- existing = readFileSync(filePath, "utf-8");
257
- } catch {
258
- return false;
259
- }
260
- const start = existing.indexOf(PUSHARY_BEGIN);
261
- const end = existing.indexOf(PUSHARY_END);
262
- if (start === -1 || end === -1 || end < start) return false;
263
- const remaining = (existing.slice(0, start) + existing.slice(end + PUSHARY_END.length)).trim();
264
- if (remaining === "") {
265
- rmSync(filePath, { force: true });
266
- } else {
267
- writeFileSync(filePath, remaining + "\n", "utf-8");
268
- }
269
- return true;
270
- };
271
- var hasInstructionBlock = (filePath) => {
272
- try {
273
- return readFileSync(filePath, "utf-8").includes(PUSHARY_BEGIN);
274
- } catch {
275
- return false;
276
- }
277
- };
278
-
279
- // src/npm.ts
280
- import { execSync } from "child_process";
281
- var cleanNpmEnv = () => {
282
- const env = {};
283
- for (const [key, value] of Object.entries(process.env)) {
284
- if (key.toLowerCase().startsWith("npm_config_workspace")) continue;
285
- env[key] = value;
286
- }
287
- return env;
288
- };
289
- var npmErrorMessage = (err) => {
290
- const e = err;
291
- const text = [e?.stderr, e?.stdout].map((part) => part ? part.toString() : "").join("\n");
292
- const line = text.split("\n").map((l) => l.replace(/^npm error\s*/i, "").trim()).find((l) => l && !l.startsWith("A complete log") && !/^code\s/i.test(l));
293
- return line || e?.message || String(err);
294
- };
295
- var execNpm = (args, options = {}) => {
296
- return execSync(`npm ${args}`, {
297
- timeout: 12e4,
298
- stdio: "pipe",
299
- ...options,
300
- env: { ...cleanNpmEnv(), ...options.env ?? {} }
301
- });
302
- };
303
-
304
- export {
305
- addCodexHooks,
306
- removeCodexHooks,
307
- hasCodexHooks,
308
- missingCodexHookEvents,
309
- untrustedCodexHookEvents,
310
- addCodexHookTrust,
311
- GEMINI_HOOK_BINARY,
312
- addGeminiMcpServer,
313
- addGeminiHooks,
314
- removeGeminiSettings,
315
- hasGeminiHooks,
316
- missingGeminiHookEvents,
317
- renderAgentInstructions,
318
- writeInstructionBlock,
319
- removeInstructionBlock,
320
- hasInstructionBlock,
321
- npmErrorMessage,
322
- execNpm
323
- };