@pushary/agent-hooks 0.28.1 → 0.28.2
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/package.json +1 -1
- package/dist/chunk-22CV7V7A.js +0 -38
- package/dist/chunk-2BE2IPMO.js +0 -315
- package/dist/chunk-2CRLBMOX.js +0 -244
- package/dist/chunk-2HMNOZPY.js +0 -109
- package/dist/chunk-2I6DLXJN.js +0 -219
- package/dist/chunk-2Q6XPZ4Q.js +0 -395
- package/dist/chunk-3LC4YUMA.js +0 -194
- package/dist/chunk-3MIR7ODJ.js +0 -112
- package/dist/chunk-3QZESA66.js +0 -222
- package/dist/chunk-4Z4MB37G.js +0 -96
- package/dist/chunk-5GFUI5N6.js +0 -132
- package/dist/chunk-5JEDLXEC.js +0 -99
- package/dist/chunk-5LTQNC7R.js +0 -824
- package/dist/chunk-5MA3CPZB.js +0 -141
- package/dist/chunk-5QHQVXWN.js +0 -174
- package/dist/chunk-5V3XJ2ES.js +0 -357
- package/dist/chunk-6A3WCJO2.js +0 -416
- package/dist/chunk-6QWFMVCD.js +0 -328
- package/dist/chunk-6SRXMZAN.js +0 -99
- package/dist/chunk-7OXL2QQ4.js +0 -357
- package/dist/chunk-7PTU7TGE.js +0 -96
- package/dist/chunk-AB4KX4XT.js +0 -109
- package/dist/chunk-AC4UYAGX.js +0 -136
- package/dist/chunk-ACE77TKQ.js +0 -328
- package/dist/chunk-BHAMEPOP.js +0 -323
- package/dist/chunk-BYNYYZWW.js +0 -412
- package/dist/chunk-C4BMEVK7.js +0 -208
- package/dist/chunk-C5TFTNHG.js +0 -244
- package/dist/chunk-CH53PBQN.js +0 -265
- package/dist/chunk-DF3BM6BF.js +0 -195
- package/dist/chunk-DKZVKEOW.js +0 -175
- package/dist/chunk-EMPL27ZV.js +0 -96
- package/dist/chunk-EQJXMEIR.js +0 -175
- package/dist/chunk-FB3N633T.js +0 -145
- package/dist/chunk-FGZZRCOG.js +0 -194
- package/dist/chunk-FXYTRZHC.js +0 -177
- package/dist/chunk-GTJGZBTQ.js +0 -328
- package/dist/chunk-GYPPVD3P.js +0 -1047
- package/dist/chunk-HJMFYDWY.js +0 -222
- package/dist/chunk-HRQEECB6.js +0 -315
- package/dist/chunk-HWEMAAOY.js +0 -370
- package/dist/chunk-I4GMPUYN.js +0 -231
- package/dist/chunk-IBWCHA5M.js +0 -10
- package/dist/chunk-JPRRYC5X.js +0 -328
- package/dist/chunk-KTM4ZQ3W.js +0 -96
- package/dist/chunk-KTP2EPVB.js +0 -27
- package/dist/chunk-KYARP7KP.js +0 -97
- package/dist/chunk-LXUHXG2X.js +0 -937
- package/dist/chunk-M2N5DYWN.js +0 -247
- package/dist/chunk-M4GDBGXF.js +0 -824
- package/dist/chunk-M5F2L4KF.js +0 -177
- package/dist/chunk-M6S3M6E3.js +0 -244
- package/dist/chunk-N7VXDBQU.js +0 -6
- package/dist/chunk-O2QL6U6G.js +0 -194
- package/dist/chunk-O6A5RHWY.js +0 -122
- package/dist/chunk-ODUXELPM.js +0 -219
- package/dist/chunk-OF5WIOYS.js +0 -129
- package/dist/chunk-OP4QAN23.js +0 -99
- package/dist/chunk-P4JH2Q7Z.js +0 -102
- package/dist/chunk-PMD5JSV3.js +0 -242
- package/dist/chunk-PSSHNBEL.js +0 -177
- package/dist/chunk-PZO7RZ5W.js +0 -145
- package/dist/chunk-QEPRH7JB.js +0 -315
- package/dist/chunk-QRXWPZKN.js +0 -308
- package/dist/chunk-QY4L6XHN.js +0 -384
- package/dist/chunk-RNWPCELY.js +0 -176
- package/dist/chunk-RSHN2AQ7.js +0 -29
- package/dist/chunk-RZLVE57X.js +0 -38
- package/dist/chunk-SDCIKREA.js +0 -241
- package/dist/chunk-SDREQWNI.js +0 -175
- package/dist/chunk-SH26ZOHU.js +0 -159
- package/dist/chunk-SJ5MC36D.js +0 -882
- package/dist/chunk-TRLBBLSS.js +0 -176
- package/dist/chunk-U6OXZPYC.js +0 -384
- package/dist/chunk-UDQZNO5H.js +0 -231
- package/dist/chunk-UIBTFZUD.js +0 -314
- package/dist/chunk-USUCPCUC.js +0 -156
- package/dist/chunk-UTK3TJC4.js +0 -882
- package/dist/chunk-V4GLWPD7.js +0 -174
- package/dist/chunk-VC6U3QGF.js +0 -142
- package/dist/chunk-VIST7ACL.js +0 -88
- package/dist/chunk-VUNL35KE.js +0 -16
- package/dist/chunk-VWBNI4SC.js +0 -174
- package/dist/chunk-W5KRWUNE.js +0 -262
- package/dist/chunk-WCGKLHCL.js +0 -154
- package/dist/chunk-WNXGIEX7.js +0 -219
- package/dist/chunk-WPVL6VIT.js +0 -160
- package/dist/chunk-X6LV22NZ.js +0 -229
- package/dist/chunk-XHTZ2DWC.js +0 -206
- package/dist/chunk-XPVSZIA3.js +0 -315
- package/dist/chunk-Y633ZIJF.js +0 -384
- package/dist/chunk-YCL4GUFR.js +0 -222
- package/dist/chunk-YTMKB44I.js +0 -220
- package/dist/chunk-ZWBS3T7Q.js +0 -244
- package/dist/pushary-mode-T7XOPI6Z.js +0 -83
- package/dist/pushary-wait-4BUC6ZM6.js +0 -93
package/dist/chunk-JPRRYC5X.js
DELETED
|
@@ -1,328 +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 KEYLESS_FALLBACK_LINE = "This repo is set up with Pushary phone approvals. No PUSHARY_API_KEY found for you, so remote notifications are off; questions will fall back to the terminal. Setup: https://pushary.com/docs?utm_source=agents-md&utm_medium=keyless-fallback";
|
|
231
|
-
var renderProjectAgentInstructions = (label) => `${instructionBody(label)}
|
|
232
|
-
|
|
233
|
-
If this environment has no Pushary API key (no PUSHARY_API_KEY and no key in ~/.pushary/config.json), the tools above are unavailable in this session. In that case, treat the following as a statement of fact about this session and continue in the terminal: ${KEYLESS_FALLBACK_LINE}`;
|
|
234
|
-
var wrap = (body) => `${PUSHARY_BEGIN}
|
|
235
|
-
${body}
|
|
236
|
-
${PUSHARY_END}`;
|
|
237
|
-
var writeInstructionBlock = (filePath, body) => {
|
|
238
|
-
const dir = dirname(filePath);
|
|
239
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
240
|
-
let existing = "";
|
|
241
|
-
try {
|
|
242
|
-
existing = readFileSync(filePath, "utf-8");
|
|
243
|
-
} catch {
|
|
244
|
-
}
|
|
245
|
-
const block = wrap(body);
|
|
246
|
-
const start = existing.indexOf(PUSHARY_BEGIN);
|
|
247
|
-
const end = existing.indexOf(PUSHARY_END);
|
|
248
|
-
let next;
|
|
249
|
-
if (start !== -1 && end !== -1 && end > start) {
|
|
250
|
-
next = existing.slice(0, start) + block + existing.slice(end + PUSHARY_END.length);
|
|
251
|
-
} else {
|
|
252
|
-
const prefix = existing.trim() ? existing.replace(/\s*$/, "") + "\n\n" : "";
|
|
253
|
-
next = prefix + block + "\n";
|
|
254
|
-
}
|
|
255
|
-
writeFileSync(filePath, next, "utf-8");
|
|
256
|
-
};
|
|
257
|
-
var removeInstructionBlock = (filePath) => {
|
|
258
|
-
let existing = "";
|
|
259
|
-
try {
|
|
260
|
-
existing = readFileSync(filePath, "utf-8");
|
|
261
|
-
} catch {
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
const start = existing.indexOf(PUSHARY_BEGIN);
|
|
265
|
-
const end = existing.indexOf(PUSHARY_END);
|
|
266
|
-
if (start === -1 || end === -1 || end < start) return false;
|
|
267
|
-
const remaining = (existing.slice(0, start) + existing.slice(end + PUSHARY_END.length)).trim();
|
|
268
|
-
if (remaining === "") {
|
|
269
|
-
rmSync(filePath, { force: true });
|
|
270
|
-
} else {
|
|
271
|
-
writeFileSync(filePath, remaining + "\n", "utf-8");
|
|
272
|
-
}
|
|
273
|
-
return true;
|
|
274
|
-
};
|
|
275
|
-
var hasInstructionBlock = (filePath) => {
|
|
276
|
-
try {
|
|
277
|
-
return readFileSync(filePath, "utf-8").includes(PUSHARY_BEGIN);
|
|
278
|
-
} catch {
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
// src/npm.ts
|
|
284
|
-
import { execSync } from "child_process";
|
|
285
|
-
var cleanNpmEnv = () => {
|
|
286
|
-
const env = {};
|
|
287
|
-
for (const [key, value] of Object.entries(process.env)) {
|
|
288
|
-
if (key.toLowerCase().startsWith("npm_config_workspace")) continue;
|
|
289
|
-
env[key] = value;
|
|
290
|
-
}
|
|
291
|
-
return env;
|
|
292
|
-
};
|
|
293
|
-
var npmErrorMessage = (err) => {
|
|
294
|
-
const e = err;
|
|
295
|
-
const text = [e?.stderr, e?.stdout].map((part) => part ? part.toString() : "").join("\n");
|
|
296
|
-
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));
|
|
297
|
-
return line || e?.message || String(err);
|
|
298
|
-
};
|
|
299
|
-
var execNpm = (args, options = {}) => {
|
|
300
|
-
return execSync(`npm ${args}`, {
|
|
301
|
-
timeout: 12e4,
|
|
302
|
-
stdio: "pipe",
|
|
303
|
-
...options,
|
|
304
|
-
env: { ...cleanNpmEnv(), ...options.env ?? {} }
|
|
305
|
-
});
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
export {
|
|
309
|
-
addCodexHooks,
|
|
310
|
-
removeCodexHooks,
|
|
311
|
-
hasCodexHooks,
|
|
312
|
-
missingCodexHookEvents,
|
|
313
|
-
untrustedCodexHookEvents,
|
|
314
|
-
addCodexHookTrust,
|
|
315
|
-
GEMINI_HOOK_BINARY,
|
|
316
|
-
addGeminiMcpServer,
|
|
317
|
-
addGeminiHooks,
|
|
318
|
-
removeGeminiSettings,
|
|
319
|
-
hasGeminiHooks,
|
|
320
|
-
missingGeminiHookEvents,
|
|
321
|
-
renderAgentInstructions,
|
|
322
|
-
renderProjectAgentInstructions,
|
|
323
|
-
writeInstructionBlock,
|
|
324
|
-
removeInstructionBlock,
|
|
325
|
-
hasInstructionBlock,
|
|
326
|
-
npmErrorMessage,
|
|
327
|
-
execNpm
|
|
328
|
-
};
|
package/dist/chunk-KTM4ZQ3W.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
callMcpTool
|
|
3
|
-
} from "./chunk-3MIR7ODJ.js";
|
|
4
|
-
|
|
5
|
-
// src/validate.ts
|
|
6
|
-
var isPolicyConfig = (data) => {
|
|
7
|
-
if (!data || typeof data !== "object") return false;
|
|
8
|
-
const d = data;
|
|
9
|
-
return Array.isArray(d.policies) && typeof d.defaultTimeoutSeconds === "number" && typeof d.defaultTimeoutAction === "string";
|
|
10
|
-
};
|
|
11
|
-
var isAskUserResponse = (data) => {
|
|
12
|
-
if (!data || typeof data !== "object") return false;
|
|
13
|
-
const d = data;
|
|
14
|
-
return typeof d.correlationId === "string" && typeof d.status === "string";
|
|
15
|
-
};
|
|
16
|
-
var isWaitForAnswerResponse = (data) => {
|
|
17
|
-
if (!data || typeof data !== "object") return false;
|
|
18
|
-
const d = data;
|
|
19
|
-
return typeof d.answered === "boolean";
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/api.ts
|
|
23
|
-
var askUser = async (apiKey, params) => {
|
|
24
|
-
const result = await callMcpTool(apiKey, "ask_user", { ...params, wait: false });
|
|
25
|
-
if (!isAskUserResponse(result)) throw new Error("Invalid ask_user response");
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
var waitForAnswer = async (apiKey, correlationId, timeoutMs = 3e4) => {
|
|
29
|
-
const result = await callMcpTool(apiKey, "wait_for_answer", {
|
|
30
|
-
correlationId,
|
|
31
|
-
timeoutMs
|
|
32
|
-
});
|
|
33
|
-
if (!isWaitForAnswerResponse(result)) throw new Error("Invalid wait_for_answer response");
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
var cancelQuestion = async (apiKey, correlationId) => {
|
|
37
|
-
await callMcpTool(apiKey, "cancel_question", { correlationId });
|
|
38
|
-
};
|
|
39
|
-
var sendNotification = async (apiKey, params) => {
|
|
40
|
-
await callMcpTool(apiKey, "send_notification", { ...params });
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/describe.ts
|
|
44
|
-
var hookPrefixes = {
|
|
45
|
-
Bash: (input) => `bash: ${input.command ?? "(no command)"}`,
|
|
46
|
-
Write: (input) => `write file: ${input.file_path ?? "(unknown path)"}`,
|
|
47
|
-
Edit: (input) => `edit file: ${input.file_path ?? "(unknown path)"}`,
|
|
48
|
-
Read: (input) => `read file: ${input.file_path ?? "(unknown path)"}`
|
|
49
|
-
};
|
|
50
|
-
var eventPrefixes = {
|
|
51
|
-
Bash: (input) => `ran: ${String(input.command ?? "").slice(0, 120)}`,
|
|
52
|
-
Write: (input) => `wrote: ${input.file_path ?? "unknown"}`,
|
|
53
|
-
Edit: (input) => `edited: ${input.file_path ?? "unknown"}`,
|
|
54
|
-
Read: (input) => `read: ${input.file_path ?? "unknown"}`
|
|
55
|
-
};
|
|
56
|
-
var describeToolCall = (toolName, toolInput, format = "hook") => {
|
|
57
|
-
const prefixes = format === "hook" ? hookPrefixes : eventPrefixes;
|
|
58
|
-
const builder = prefixes[toolName];
|
|
59
|
-
if (builder) return builder(toolInput);
|
|
60
|
-
return format === "hook" ? `${toolName}: ${JSON.stringify(toolInput).slice(0, 200)}` : `${toolName}: done`;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// src/pending.ts
|
|
64
|
-
import { join } from "path";
|
|
65
|
-
import { tmpdir } from "os";
|
|
66
|
-
import { existsSync, mkdirSync, writeFileSync, readdirSync, unlinkSync } from "fs";
|
|
67
|
-
var PENDING_DIR = join(tmpdir(), "pushary-pending");
|
|
68
|
-
var savePendingQuestion = (correlationId) => {
|
|
69
|
-
if (!existsSync(PENDING_DIR)) mkdirSync(PENDING_DIR, { recursive: true });
|
|
70
|
-
writeFileSync(join(PENDING_DIR, correlationId), "", "utf-8");
|
|
71
|
-
};
|
|
72
|
-
var listPendingQuestions = () => {
|
|
73
|
-
try {
|
|
74
|
-
return readdirSync(PENDING_DIR);
|
|
75
|
-
} catch {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
var removePendingQuestion = (correlationId) => {
|
|
80
|
-
try {
|
|
81
|
-
unlinkSync(join(PENDING_DIR, correlationId));
|
|
82
|
-
} catch {
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export {
|
|
87
|
-
isPolicyConfig,
|
|
88
|
-
askUser,
|
|
89
|
-
waitForAnswer,
|
|
90
|
-
cancelQuestion,
|
|
91
|
-
sendNotification,
|
|
92
|
-
describeToolCall,
|
|
93
|
-
savePendingQuestion,
|
|
94
|
-
listPendingQuestions,
|
|
95
|
-
removePendingQuestion
|
|
96
|
-
};
|
package/dist/chunk-KTP2EPVB.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
callMcpTool
|
|
3
|
-
} from "./chunk-VIST7ACL.js";
|
|
4
|
-
|
|
5
|
-
// src/api.ts
|
|
6
|
-
var askUser = async (apiKey, params) => {
|
|
7
|
-
return callMcpTool(apiKey, "ask_user", { ...params });
|
|
8
|
-
};
|
|
9
|
-
var waitForAnswer = async (apiKey, correlationId, timeoutMs = 3e4) => {
|
|
10
|
-
return callMcpTool(apiKey, "wait_for_answer", {
|
|
11
|
-
correlationId,
|
|
12
|
-
timeoutMs
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var cancelQuestion = async (apiKey, correlationId) => {
|
|
16
|
-
await callMcpTool(apiKey, "cancel_question", { correlationId });
|
|
17
|
-
};
|
|
18
|
-
var sendNotification = async (apiKey, params) => {
|
|
19
|
-
await callMcpTool(apiKey, "send_notification", { ...params });
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
askUser,
|
|
24
|
-
waitForAnswer,
|
|
25
|
-
cancelQuestion,
|
|
26
|
-
sendNotification
|
|
27
|
-
};
|
package/dist/chunk-KYARP7KP.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cancelQuestion,
|
|
3
|
-
describeToolCall,
|
|
4
|
-
listPendingQuestions,
|
|
5
|
-
removePendingQuestion
|
|
6
|
-
} from "./chunk-4Z4MB37G.js";
|
|
7
|
-
import {
|
|
8
|
-
getApiKey,
|
|
9
|
-
getBaseUrl,
|
|
10
|
-
withRetry
|
|
11
|
-
} from "./chunk-O6A5RHWY.js";
|
|
12
|
-
|
|
13
|
-
// src/events.ts
|
|
14
|
-
import { hostname } from "os";
|
|
15
|
-
import { basename } from "path";
|
|
16
|
-
var cleanupPendingQuestions = async () => {
|
|
17
|
-
try {
|
|
18
|
-
const files = listPendingQuestions();
|
|
19
|
-
const apiKey = getApiKey();
|
|
20
|
-
for (const correlationId of files) {
|
|
21
|
-
try {
|
|
22
|
-
await cancelQuestion(apiKey, correlationId);
|
|
23
|
-
} catch {
|
|
24
|
-
}
|
|
25
|
-
removePendingQuestion(correlationId);
|
|
26
|
-
}
|
|
27
|
-
} catch {
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
var reportEvent = async (event) => {
|
|
31
|
-
const apiKey = getApiKey();
|
|
32
|
-
const baseUrl = getBaseUrl();
|
|
33
|
-
await withRetry(async () => {
|
|
34
|
-
await fetch(`${baseUrl}/api/agent/event`, {
|
|
35
|
-
method: "POST",
|
|
36
|
-
headers: {
|
|
37
|
-
"Content-Type": "application/json",
|
|
38
|
-
"Authorization": `Bearer ${apiKey}`
|
|
39
|
-
},
|
|
40
|
-
body: JSON.stringify({
|
|
41
|
-
...event,
|
|
42
|
-
machineId: event.machineId ?? hostname()
|
|
43
|
-
}),
|
|
44
|
-
signal: AbortSignal.timeout(1e4)
|
|
45
|
-
});
|
|
46
|
-
}, { maxAttempts: 2, baseDelayMs: 300 });
|
|
47
|
-
};
|
|
48
|
-
var handlePostToolUse = async (input) => {
|
|
49
|
-
try {
|
|
50
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
51
|
-
const action = describeToolCall(input.tool_name, input.tool_input, "event");
|
|
52
|
-
const isError = input.tool_result && ("error" in input.tool_result || "is_error" in input.tool_result);
|
|
53
|
-
await Promise.allSettled([
|
|
54
|
-
cleanupPendingQuestions(),
|
|
55
|
-
reportEvent({
|
|
56
|
-
event: isError ? "tool_error" : "tool_complete",
|
|
57
|
-
agentType: "claude_code",
|
|
58
|
-
agentName: `Claude Code - ${projectName}`,
|
|
59
|
-
action,
|
|
60
|
-
error: isError ? String(input.tool_result?.error ?? input.tool_result?.stderr ?? "").slice(0, 500) : void 0
|
|
61
|
-
})
|
|
62
|
-
]);
|
|
63
|
-
} catch {
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
var handleStop = async (input) => {
|
|
67
|
-
try {
|
|
68
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
69
|
-
await reportEvent({
|
|
70
|
-
event: "session_end",
|
|
71
|
-
agentType: "claude_code",
|
|
72
|
-
agentName: `Claude Code - ${projectName}`,
|
|
73
|
-
action: "Session ended"
|
|
74
|
-
});
|
|
75
|
-
} catch {
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
var handleNotification = async (input) => {
|
|
79
|
-
try {
|
|
80
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
81
|
-
await reportEvent({
|
|
82
|
-
event: input.type === "error" ? "error" : "notification",
|
|
83
|
-
agentType: "claude_code",
|
|
84
|
-
agentName: `Claude Code - ${projectName}`,
|
|
85
|
-
action: input.title ?? input.message ?? "Notification",
|
|
86
|
-
error: input.type === "error" ? input.message : void 0
|
|
87
|
-
});
|
|
88
|
-
} catch {
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export {
|
|
93
|
-
reportEvent,
|
|
94
|
-
handlePostToolUse,
|
|
95
|
-
handleStop,
|
|
96
|
-
handleNotification
|
|
97
|
-
};
|