@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-3QZESA66.js
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_SESSION,
|
|
3
|
-
cancelQuestion,
|
|
4
|
-
deriveReceiptMeta,
|
|
5
|
-
describeToolCall,
|
|
6
|
-
fetchModeState,
|
|
7
|
-
getMachineId,
|
|
8
|
-
isDefaultSession,
|
|
9
|
-
isPolicyConfig,
|
|
10
|
-
isToolResultError,
|
|
11
|
-
listPendingQuestions,
|
|
12
|
-
removePendingQuestion,
|
|
13
|
-
removePendingSession,
|
|
14
|
-
resolvePolicy
|
|
15
|
-
} from "./chunk-HRQEECB6.js";
|
|
16
|
-
import {
|
|
17
|
-
withRetry
|
|
18
|
-
} from "./chunk-DWED7BS3.js";
|
|
19
|
-
import {
|
|
20
|
-
getApiKey,
|
|
21
|
-
getBaseUrl
|
|
22
|
-
} from "./chunk-NKXSILEW.js";
|
|
23
|
-
|
|
24
|
-
// src/codex-adapter.ts
|
|
25
|
-
var CODEX_AGENT = { type: "codex", label: "Codex" };
|
|
26
|
-
var codexAllow = () => ({ kind: "allow" });
|
|
27
|
-
var codexDeny = (reason) => ({ kind: "deny", reason });
|
|
28
|
-
var codexPass = () => ({ kind: "pass" });
|
|
29
|
-
var toCodexWire = (event, decision) => {
|
|
30
|
-
if (event === "PermissionRequest") {
|
|
31
|
-
if (decision.kind === "allow") {
|
|
32
|
-
return {
|
|
33
|
-
hookSpecificOutput: {
|
|
34
|
-
hookEventName: "PermissionRequest",
|
|
35
|
-
decision: { behavior: "allow" }
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
if (decision.kind === "deny") {
|
|
40
|
-
return {
|
|
41
|
-
hookSpecificOutput: {
|
|
42
|
-
hookEventName: "PermissionRequest",
|
|
43
|
-
decision: { behavior: "deny", message: decision.reason }
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
if (event === "PreToolUse" && decision.kind === "deny") {
|
|
50
|
-
return {
|
|
51
|
-
hookSpecificOutput: {
|
|
52
|
-
hookEventName: "PreToolUse",
|
|
53
|
-
permissionDecision: "deny",
|
|
54
|
-
permissionDecisionReason: decision.reason
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
};
|
|
60
|
-
var toPolicyLookup = (toolName, toolInput) => {
|
|
61
|
-
if (toolName !== "apply_patch") return { tool: toolName, input: toolInput };
|
|
62
|
-
const command = toolInput.command;
|
|
63
|
-
return {
|
|
64
|
-
tool: "Edit",
|
|
65
|
-
input: typeof command === "string" ? { file_path: command } : {}
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
var permissionTimeoutDecision = (timeoutAction) => {
|
|
69
|
-
if (timeoutAction === "approve") return codexAllow();
|
|
70
|
-
if (timeoutAction === "deny") return codexDeny("No response within timeout");
|
|
71
|
-
return codexPass();
|
|
72
|
-
};
|
|
73
|
-
var preToolUseTimeoutDecision = (timeoutAction, denyReason = "No response within timeout") => timeoutAction === "deny" ? codexDeny(denyReason) : codexPass();
|
|
74
|
-
|
|
75
|
-
// src/events.ts
|
|
76
|
-
import { basename, join } from "path";
|
|
77
|
-
import { createHash } from "crypto";
|
|
78
|
-
import { existsSync, readFileSync } from "fs";
|
|
79
|
-
import { tmpdir } from "os";
|
|
80
|
-
var cleanupPendingQuestions = async (sessionId) => {
|
|
81
|
-
try {
|
|
82
|
-
const files = listPendingQuestions(sessionId);
|
|
83
|
-
const apiKey = getApiKey();
|
|
84
|
-
for (const correlationId of files) {
|
|
85
|
-
try {
|
|
86
|
-
await cancelQuestion(apiKey, correlationId);
|
|
87
|
-
} catch {
|
|
88
|
-
}
|
|
89
|
-
removePendingQuestion(sessionId, correlationId);
|
|
90
|
-
}
|
|
91
|
-
if (!isDefaultSession(sessionId)) removePendingSession(sessionId);
|
|
92
|
-
} catch {
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
var CLAUDE_CODE_AGENT = { type: "claude_code", label: "Claude Code" };
|
|
96
|
-
var POLICY_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
97
|
-
var readFreshCachedPolicy = (apiKey) => {
|
|
98
|
-
const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
|
|
99
|
-
const path = join(tmpdir(), `pushary-policy-${hash}.json`);
|
|
100
|
-
if (!existsSync(path)) return null;
|
|
101
|
-
const cached = JSON.parse(readFileSync(path, "utf-8"));
|
|
102
|
-
if (!isPolicyConfig(cached)) return null;
|
|
103
|
-
if (!cached._cachedAt || Date.now() - cached._cachedAt >= POLICY_CACHE_TTL_MS) return null;
|
|
104
|
-
return cached;
|
|
105
|
-
};
|
|
106
|
-
var deriveDecisionSource = (toolName, toolInput, liveMode) => {
|
|
107
|
-
try {
|
|
108
|
-
if (liveMode.kill) return "terminal";
|
|
109
|
-
const policy = readFreshCachedPolicy(getApiKey());
|
|
110
|
-
if (!policy) return void 0;
|
|
111
|
-
const resolved = resolvePolicy(policy, toolName, liveMode.mode, toolInput);
|
|
112
|
-
if (resolved.timeoutSeconds === 0 && resolved.timeoutAction === "approve") return "policy_auto";
|
|
113
|
-
if (resolved.mode === "push_only" || resolved.mode === "push_first") return "human";
|
|
114
|
-
return "terminal";
|
|
115
|
-
} catch {
|
|
116
|
-
return void 0;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
var reportEvent = async (event, options = {}) => {
|
|
120
|
-
const apiKey = getApiKey();
|
|
121
|
-
const baseUrl = getBaseUrl();
|
|
122
|
-
await withRetry(async () => {
|
|
123
|
-
await fetch(`${baseUrl}/api/agent/event`, {
|
|
124
|
-
method: "POST",
|
|
125
|
-
headers: {
|
|
126
|
-
"Content-Type": "application/json",
|
|
127
|
-
"Authorization": `Bearer ${apiKey}`
|
|
128
|
-
},
|
|
129
|
-
body: JSON.stringify({
|
|
130
|
-
...event,
|
|
131
|
-
machineId: event.machineId ?? getMachineId()
|
|
132
|
-
}),
|
|
133
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? 1e4)
|
|
134
|
-
});
|
|
135
|
-
}, { maxAttempts: options.maxAttempts ?? 2, baseDelayMs: 300 });
|
|
136
|
-
};
|
|
137
|
-
var handlePostToolUse = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
138
|
-
try {
|
|
139
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
140
|
-
const action = describeToolCall(input.tool_name, input.tool_input, "event");
|
|
141
|
-
const lookup = toPolicyLookup(input.tool_name, input.tool_input);
|
|
142
|
-
const isError = isToolResultError(input.tool_result);
|
|
143
|
-
const receiptsEnabled = process.env.PUSHARY_RECEIPTS !== "off";
|
|
144
|
-
const liveMode = await fetchModeState(getApiKey(), input.session_id);
|
|
145
|
-
await Promise.allSettled([
|
|
146
|
-
cleanupPendingQuestions(input.session_id || DEFAULT_SESSION),
|
|
147
|
-
reportEvent({
|
|
148
|
-
event: isError ? "tool_error" : "tool_complete",
|
|
149
|
-
agentType: agent.type,
|
|
150
|
-
agentName: `${agent.label} - ${projectName}`,
|
|
151
|
-
action,
|
|
152
|
-
sessionId: input.session_id,
|
|
153
|
-
error: isError ? String(input.tool_result?.error ?? input.tool_result?.stderr ?? "").slice(0, 500) : void 0,
|
|
154
|
-
decisionSource: deriveDecisionSource(lookup.tool, lookup.input, liveMode),
|
|
155
|
-
meta: receiptsEnabled ? deriveReceiptMeta(lookup.tool, lookup.input, input.tool_result, input.cwd ?? process.cwd()) : void 0
|
|
156
|
-
})
|
|
157
|
-
]);
|
|
158
|
-
} catch {
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
var TASK_TITLE_MAX_LENGTH = 120;
|
|
162
|
-
var handleUserPrompt = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
163
|
-
try {
|
|
164
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
165
|
-
const titlesEnabled = process.env.PUSHARY_TASK_TITLES !== "off";
|
|
166
|
-
const taskTitle = titlesEnabled ? input.prompt?.replace(/\s+/g, " ").trim().slice(0, TASK_TITLE_MAX_LENGTH) || void 0 : void 0;
|
|
167
|
-
await reportEvent({
|
|
168
|
-
event: "user_prompt",
|
|
169
|
-
agentType: agent.type,
|
|
170
|
-
agentName: `${agent.label} - ${projectName}`,
|
|
171
|
-
sessionId: input.session_id,
|
|
172
|
-
taskTitle
|
|
173
|
-
}, { maxAttempts: 1, timeoutMs: 800 });
|
|
174
|
-
} catch {
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
var handleStop = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
178
|
-
try {
|
|
179
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
180
|
-
await Promise.allSettled([
|
|
181
|
-
cleanupPendingQuestions(input.session_id || DEFAULT_SESSION),
|
|
182
|
-
reportEvent({
|
|
183
|
-
event: "session_end",
|
|
184
|
-
agentType: agent.type,
|
|
185
|
-
agentName: `${agent.label} - ${projectName}`,
|
|
186
|
-
action: "Session ended",
|
|
187
|
-
sessionId: input.session_id
|
|
188
|
-
})
|
|
189
|
-
]);
|
|
190
|
-
} catch {
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
var handleNotification = async (input) => {
|
|
194
|
-
try {
|
|
195
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
196
|
-
await reportEvent({
|
|
197
|
-
event: input.type === "error" ? "error" : "notification",
|
|
198
|
-
agentType: "claude_code",
|
|
199
|
-
agentName: `Claude Code - ${projectName}`,
|
|
200
|
-
action: input.title ?? input.message ?? "Notification",
|
|
201
|
-
sessionId: input.session_id,
|
|
202
|
-
error: input.type === "error" ? input.message : void 0
|
|
203
|
-
});
|
|
204
|
-
} catch {
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
export {
|
|
209
|
-
CODEX_AGENT,
|
|
210
|
-
codexAllow,
|
|
211
|
-
codexDeny,
|
|
212
|
-
codexPass,
|
|
213
|
-
toCodexWire,
|
|
214
|
-
toPolicyLookup,
|
|
215
|
-
permissionTimeoutDecision,
|
|
216
|
-
preToolUseTimeoutDecision,
|
|
217
|
-
reportEvent,
|
|
218
|
-
handlePostToolUse,
|
|
219
|
-
handleUserPrompt,
|
|
220
|
-
handleStop,
|
|
221
|
-
handleNotification
|
|
222
|
-
};
|
package/dist/chunk-4Z4MB37G.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
callMcpTool
|
|
3
|
-
} from "./chunk-O6A5RHWY.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 });
|
|
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-5GFUI5N6.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// src/claude-config.ts
|
|
2
|
-
import { join } from "path";
|
|
3
|
-
var PUSHARY_MCP_URL = "https://pushary.com/api/mcp/mcp";
|
|
4
|
-
var PUSHARY_PERMISSION_RULE = "mcp__pushary__*";
|
|
5
|
-
var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
6
|
-
var ensureRecord = (target, key) => {
|
|
7
|
-
const existing = asRecord(target[key]);
|
|
8
|
-
if (existing) return existing;
|
|
9
|
-
const created = {};
|
|
10
|
-
target[key] = created;
|
|
11
|
-
return created;
|
|
12
|
-
};
|
|
13
|
-
var isPusharyPermission = (rule) => typeof rule === "string" && (rule.includes("pushary") || rule.includes("MCP(pushary"));
|
|
14
|
-
var isPusharyHook = (entry) => {
|
|
15
|
-
const hooks = asRecord(entry)?.hooks;
|
|
16
|
-
if (!Array.isArray(hooks)) return false;
|
|
17
|
-
return hooks.some((hook) => {
|
|
18
|
-
const command = String(asRecord(hook)?.command ?? "");
|
|
19
|
-
return command.includes("pushary-hook") || command.includes("pushary-post-hook") || command.includes("pushary-stop-hook");
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var addClaudeMcpServer = (config, apiKey) => {
|
|
23
|
-
const mcpServers = ensureRecord(config, "mcpServers");
|
|
24
|
-
mcpServers.pushary = {
|
|
25
|
-
type: "http",
|
|
26
|
-
url: PUSHARY_MCP_URL,
|
|
27
|
-
headers: { Authorization: `Bearer ${apiKey}` }
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
var removeClaudeMcpServers = (config) => {
|
|
31
|
-
let changed = false;
|
|
32
|
-
const removeFrom = (target) => {
|
|
33
|
-
const mcpServers = asRecord(target.mcpServers);
|
|
34
|
-
if (!mcpServers?.pushary) return;
|
|
35
|
-
delete mcpServers.pushary;
|
|
36
|
-
if (Object.keys(mcpServers).length === 0) delete target.mcpServers;
|
|
37
|
-
changed = true;
|
|
38
|
-
};
|
|
39
|
-
removeFrom(config);
|
|
40
|
-
const projects = asRecord(config.projects);
|
|
41
|
-
if (projects) {
|
|
42
|
-
for (const project of Object.values(projects)) {
|
|
43
|
-
const projectConfig = asRecord(project);
|
|
44
|
-
if (projectConfig) removeFrom(projectConfig);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return changed;
|
|
48
|
-
};
|
|
49
|
-
var addPusharyToolPermissions = (settings) => {
|
|
50
|
-
const permissions = ensureRecord(settings, "permissions");
|
|
51
|
-
const allow = Array.isArray(permissions.allow) ? permissions.allow : [];
|
|
52
|
-
const filtered = allow.filter((rule) => !isPusharyPermission(rule));
|
|
53
|
-
if (!filtered.includes(PUSHARY_PERMISSION_RULE)) {
|
|
54
|
-
filtered.push(PUSHARY_PERMISSION_RULE);
|
|
55
|
-
}
|
|
56
|
-
permissions.allow = filtered;
|
|
57
|
-
};
|
|
58
|
-
var addPusharyHooks = (settings, binDir) => {
|
|
59
|
-
const resolve = (name) => binDir ? join(binDir, name) : name;
|
|
60
|
-
const hooks = ensureRecord(settings, "hooks");
|
|
61
|
-
const preToolUse = (Array.isArray(hooks.PreToolUse) ? hooks.PreToolUse : []).filter((entry) => !isPusharyHook(entry));
|
|
62
|
-
preToolUse.push({
|
|
63
|
-
matcher: "Bash|Write|Edit",
|
|
64
|
-
hooks: [{
|
|
65
|
-
type: "command",
|
|
66
|
-
command: resolve("pushary-hook"),
|
|
67
|
-
timeout: 120
|
|
68
|
-
}]
|
|
69
|
-
});
|
|
70
|
-
hooks.PreToolUse = preToolUse;
|
|
71
|
-
const postToolUse = (Array.isArray(hooks.PostToolUse) ? hooks.PostToolUse : []).filter((entry) => !isPusharyHook(entry));
|
|
72
|
-
postToolUse.push({
|
|
73
|
-
matcher: "Bash|Write|Edit",
|
|
74
|
-
hooks: [{
|
|
75
|
-
type: "command",
|
|
76
|
-
command: resolve("pushary-post-hook"),
|
|
77
|
-
timeout: 10
|
|
78
|
-
}]
|
|
79
|
-
});
|
|
80
|
-
hooks.PostToolUse = postToolUse;
|
|
81
|
-
const stop = (Array.isArray(hooks.Stop) ? hooks.Stop : []).filter((entry) => !isPusharyHook(entry));
|
|
82
|
-
stop.push({
|
|
83
|
-
hooks: [{
|
|
84
|
-
type: "command",
|
|
85
|
-
command: resolve("pushary-stop-hook"),
|
|
86
|
-
timeout: 10
|
|
87
|
-
}]
|
|
88
|
-
});
|
|
89
|
-
hooks.Stop = stop;
|
|
90
|
-
};
|
|
91
|
-
var removePusharySettings = (settings) => {
|
|
92
|
-
let changed = removeClaudeMcpServers(settings);
|
|
93
|
-
const permissions = asRecord(settings.permissions);
|
|
94
|
-
if (permissions && Array.isArray(permissions.allow)) {
|
|
95
|
-
const filtered = permissions.allow.filter((rule) => !isPusharyPermission(rule));
|
|
96
|
-
if (filtered.length !== permissions.allow.length) {
|
|
97
|
-
if (filtered.length === 0) {
|
|
98
|
-
delete permissions.allow;
|
|
99
|
-
} else {
|
|
100
|
-
permissions.allow = filtered;
|
|
101
|
-
}
|
|
102
|
-
if (Object.keys(permissions).length === 0) delete settings.permissions;
|
|
103
|
-
changed = true;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const hooks = asRecord(settings.hooks);
|
|
107
|
-
if (hooks) {
|
|
108
|
-
for (const key of ["PreToolUse", "PostToolUse", "Stop"]) {
|
|
109
|
-
const entries = hooks[key];
|
|
110
|
-
if (!Array.isArray(entries)) continue;
|
|
111
|
-
const filtered = entries.filter((entry) => !isPusharyHook(entry));
|
|
112
|
-
if (filtered.length !== entries.length) {
|
|
113
|
-
if (filtered.length === 0) {
|
|
114
|
-
delete hooks[key];
|
|
115
|
-
} else {
|
|
116
|
-
hooks[key] = filtered;
|
|
117
|
-
}
|
|
118
|
-
changed = true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (Object.keys(hooks).length === 0) delete settings.hooks;
|
|
122
|
-
}
|
|
123
|
-
return changed;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export {
|
|
127
|
-
addClaudeMcpServer,
|
|
128
|
-
removeClaudeMcpServers,
|
|
129
|
-
addPusharyToolPermissions,
|
|
130
|
-
addPusharyHooks,
|
|
131
|
-
removePusharySettings
|
|
132
|
-
};
|
package/dist/chunk-5JEDLXEC.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cancelQuestion,
|
|
3
|
-
describeToolCall,
|
|
4
|
-
listPendingQuestions,
|
|
5
|
-
removePendingQuestion
|
|
6
|
-
} from "./chunk-EMPL27ZV.js";
|
|
7
|
-
import {
|
|
8
|
-
withRetry
|
|
9
|
-
} from "./chunk-3MIR7ODJ.js";
|
|
10
|
-
import {
|
|
11
|
-
getApiKey,
|
|
12
|
-
getBaseUrl
|
|
13
|
-
} from "./chunk-VUNL35KE.js";
|
|
14
|
-
|
|
15
|
-
// src/events.ts
|
|
16
|
-
import { hostname } from "os";
|
|
17
|
-
import { basename } from "path";
|
|
18
|
-
var cleanupPendingQuestions = async () => {
|
|
19
|
-
try {
|
|
20
|
-
const files = listPendingQuestions();
|
|
21
|
-
const apiKey = getApiKey();
|
|
22
|
-
for (const correlationId of files) {
|
|
23
|
-
try {
|
|
24
|
-
await cancelQuestion(apiKey, correlationId);
|
|
25
|
-
} catch {
|
|
26
|
-
}
|
|
27
|
-
removePendingQuestion(correlationId);
|
|
28
|
-
}
|
|
29
|
-
} catch {
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
var reportEvent = async (event) => {
|
|
33
|
-
const apiKey = getApiKey();
|
|
34
|
-
const baseUrl = getBaseUrl();
|
|
35
|
-
await withRetry(async () => {
|
|
36
|
-
await fetch(`${baseUrl}/api/agent/event`, {
|
|
37
|
-
method: "POST",
|
|
38
|
-
headers: {
|
|
39
|
-
"Content-Type": "application/json",
|
|
40
|
-
"Authorization": `Bearer ${apiKey}`
|
|
41
|
-
},
|
|
42
|
-
body: JSON.stringify({
|
|
43
|
-
...event,
|
|
44
|
-
machineId: event.machineId ?? hostname()
|
|
45
|
-
}),
|
|
46
|
-
signal: AbortSignal.timeout(1e4)
|
|
47
|
-
});
|
|
48
|
-
}, { maxAttempts: 2, baseDelayMs: 300 });
|
|
49
|
-
};
|
|
50
|
-
var handlePostToolUse = async (input) => {
|
|
51
|
-
try {
|
|
52
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
53
|
-
const action = describeToolCall(input.tool_name, input.tool_input, "event");
|
|
54
|
-
const isError = input.tool_result && ("error" in input.tool_result || "is_error" in input.tool_result);
|
|
55
|
-
await Promise.allSettled([
|
|
56
|
-
cleanupPendingQuestions(),
|
|
57
|
-
reportEvent({
|
|
58
|
-
event: isError ? "tool_error" : "tool_complete",
|
|
59
|
-
agentType: "claude_code",
|
|
60
|
-
agentName: `Claude Code - ${projectName}`,
|
|
61
|
-
action,
|
|
62
|
-
error: isError ? String(input.tool_result?.error ?? input.tool_result?.stderr ?? "").slice(0, 500) : void 0
|
|
63
|
-
})
|
|
64
|
-
]);
|
|
65
|
-
} catch {
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
var handleStop = async (input) => {
|
|
69
|
-
try {
|
|
70
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
71
|
-
await reportEvent({
|
|
72
|
-
event: "session_end",
|
|
73
|
-
agentType: "claude_code",
|
|
74
|
-
agentName: `Claude Code - ${projectName}`,
|
|
75
|
-
action: "Session ended"
|
|
76
|
-
});
|
|
77
|
-
} catch {
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
var handleNotification = async (input) => {
|
|
81
|
-
try {
|
|
82
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
83
|
-
await reportEvent({
|
|
84
|
-
event: input.type === "error" ? "error" : "notification",
|
|
85
|
-
agentType: "claude_code",
|
|
86
|
-
agentName: `Claude Code - ${projectName}`,
|
|
87
|
-
action: input.title ?? input.message ?? "Notification",
|
|
88
|
-
error: input.type === "error" ? input.message : void 0
|
|
89
|
-
});
|
|
90
|
-
} catch {
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export {
|
|
95
|
-
reportEvent,
|
|
96
|
-
handlePostToolUse,
|
|
97
|
-
handleStop,
|
|
98
|
-
handleNotification
|
|
99
|
-
};
|