@pushary/agent-hooks 0.27.0 → 0.28.1
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/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/bin/pushary-clean.js +3 -3
- package/dist/bin/pushary-codex-hook.js +2 -2
- package/dist/bin/pushary-codex.js +2 -2
- package/dist/bin/pushary-doctor.js +2 -2
- package/dist/bin/pushary-gemini-hook.js +2 -2
- package/dist/bin/pushary-hook.js +3 -3
- package/dist/bin/pushary-post-hook.js +2 -2
- package/dist/bin/pushary-prompt-hook.js +2 -2
- package/dist/bin/pushary-setup.js +4 -4
- package/dist/bin/pushary-stop-hook.js +2 -2
- package/dist/chunk-22CV7V7A.js +38 -0
- package/dist/chunk-2BE2IPMO.js +315 -0
- package/dist/chunk-2CRLBMOX.js +244 -0
- package/dist/chunk-2HMNOZPY.js +109 -0
- package/dist/chunk-2I6DLXJN.js +219 -0
- package/dist/chunk-2Q6XPZ4Q.js +395 -0
- package/dist/chunk-3LC4YUMA.js +194 -0
- package/dist/chunk-3MIR7ODJ.js +112 -0
- package/dist/chunk-3QZESA66.js +222 -0
- package/dist/chunk-4Z4MB37G.js +96 -0
- package/dist/chunk-5GFUI5N6.js +132 -0
- package/dist/chunk-5JEDLXEC.js +99 -0
- package/dist/chunk-5LTQNC7R.js +824 -0
- package/dist/chunk-5MA3CPZB.js +141 -0
- package/dist/chunk-5QHQVXWN.js +174 -0
- package/dist/{chunk-WXWHRXDK.js → chunk-5V3XJ2ES.js} +1 -1
- package/dist/chunk-6A3WCJO2.js +416 -0
- package/dist/chunk-6QWFMVCD.js +328 -0
- package/dist/chunk-6SRXMZAN.js +99 -0
- package/dist/chunk-7OXL2QQ4.js +357 -0
- package/dist/chunk-7PTU7TGE.js +96 -0
- package/dist/chunk-AB4KX4XT.js +109 -0
- package/dist/chunk-AC4UYAGX.js +136 -0
- package/dist/chunk-ACE77TKQ.js +328 -0
- package/dist/chunk-BHAMEPOP.js +323 -0
- package/dist/chunk-BYNYYZWW.js +412 -0
- package/dist/{chunk-FDR5WYT7.js → chunk-C4BMEVK7.js} +1 -1
- package/dist/chunk-C5TFTNHG.js +244 -0
- package/dist/chunk-CH53PBQN.js +265 -0
- package/dist/chunk-DF3BM6BF.js +195 -0
- package/dist/chunk-DKZVKEOW.js +175 -0
- package/dist/chunk-EMPL27ZV.js +96 -0
- package/dist/chunk-EQJXMEIR.js +175 -0
- package/dist/{chunk-MVNOP5IZ.js → chunk-FB3N633T.js} +1 -1
- package/dist/chunk-FGZZRCOG.js +194 -0
- package/dist/chunk-FXYTRZHC.js +177 -0
- package/dist/chunk-GTJGZBTQ.js +328 -0
- package/dist/chunk-GYPPVD3P.js +1047 -0
- package/dist/chunk-HJMFYDWY.js +222 -0
- package/dist/chunk-HRQEECB6.js +315 -0
- package/dist/chunk-HWEMAAOY.js +370 -0
- package/dist/{chunk-VHD3GMZ3.js → chunk-I4GMPUYN.js} +2 -2
- package/dist/{chunk-TUILTFLS.js → chunk-IAOXM7X5.js} +1 -1
- package/dist/chunk-IBWCHA5M.js +10 -0
- package/dist/chunk-JPRRYC5X.js +328 -0
- package/dist/chunk-KTM4ZQ3W.js +96 -0
- package/dist/chunk-KTP2EPVB.js +27 -0
- package/dist/chunk-KYARP7KP.js +97 -0
- package/dist/chunk-LXUHXG2X.js +937 -0
- package/dist/chunk-M2N5DYWN.js +247 -0
- package/dist/chunk-M4GDBGXF.js +824 -0
- package/dist/chunk-M5F2L4KF.js +177 -0
- package/dist/chunk-M6S3M6E3.js +244 -0
- package/dist/chunk-N7VXDBQU.js +6 -0
- package/dist/chunk-O2QL6U6G.js +194 -0
- package/dist/chunk-O6A5RHWY.js +122 -0
- package/dist/chunk-ODUXELPM.js +219 -0
- package/dist/chunk-OF5WIOYS.js +129 -0
- package/dist/chunk-OP4QAN23.js +99 -0
- package/dist/chunk-P4JH2Q7Z.js +102 -0
- package/dist/chunk-P6QBZS27.js +231 -0
- package/dist/chunk-PMD5JSV3.js +242 -0
- package/dist/chunk-PSSHNBEL.js +177 -0
- package/dist/chunk-PZO7RZ5W.js +145 -0
- package/dist/chunk-QEPRH7JB.js +315 -0
- package/dist/chunk-QNEYHDKR.js +145 -0
- package/dist/chunk-QRXWPZKN.js +308 -0
- package/dist/chunk-QY4L6XHN.js +384 -0
- package/dist/chunk-RNWPCELY.js +176 -0
- package/dist/chunk-RSHN2AQ7.js +29 -0
- package/dist/chunk-RZLVE57X.js +38 -0
- package/dist/chunk-SDCIKREA.js +241 -0
- package/dist/chunk-SDREQWNI.js +175 -0
- package/dist/chunk-SH26ZOHU.js +159 -0
- package/dist/chunk-SJ5MC36D.js +882 -0
- package/dist/chunk-TRLBBLSS.js +176 -0
- package/dist/chunk-U6OXZPYC.js +384 -0
- package/dist/chunk-UDQZNO5H.js +231 -0
- package/dist/chunk-UIBTFZUD.js +314 -0
- package/dist/chunk-USUCPCUC.js +156 -0
- package/dist/chunk-UTK3TJC4.js +882 -0
- package/dist/chunk-V4GLWPD7.js +174 -0
- package/dist/chunk-VC6U3QGF.js +142 -0
- package/dist/chunk-VIST7ACL.js +88 -0
- package/dist/chunk-VUNL35KE.js +16 -0
- package/dist/chunk-VWBNI4SC.js +174 -0
- package/dist/chunk-W5KRWUNE.js +262 -0
- package/dist/chunk-WCGKLHCL.js +154 -0
- package/dist/chunk-WNXGIEX7.js +219 -0
- package/dist/chunk-WPVL6VIT.js +160 -0
- package/dist/chunk-X3YCHQQK.js +357 -0
- package/dist/chunk-X6LV22NZ.js +229 -0
- package/dist/chunk-XHTZ2DWC.js +206 -0
- package/dist/chunk-XPVSZIA3.js +315 -0
- package/dist/chunk-Y633ZIJF.js +384 -0
- package/dist/chunk-YCL4GUFR.js +222 -0
- package/dist/chunk-YTMKB44I.js +220 -0
- package/dist/chunk-Z5PL3K7C.js +322 -0
- package/dist/chunk-ZWBS3T7Q.js +244 -0
- package/dist/pushary-mode-T7XOPI6Z.js +83 -0
- package/dist/pushary-wait-4BUC6ZM6.js +93 -0
- package/dist/src/index.js +3 -3
- package/package.json +25 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_SESSION,
|
|
3
|
+
cancelQuestion,
|
|
4
|
+
deriveReceiptMeta,
|
|
5
|
+
describeToolCall,
|
|
6
|
+
getMachineId,
|
|
7
|
+
isDefaultSession,
|
|
8
|
+
isPolicyConfig,
|
|
9
|
+
isToolResultError,
|
|
10
|
+
listPendingQuestions,
|
|
11
|
+
removePendingQuestion,
|
|
12
|
+
removePendingSession,
|
|
13
|
+
resolvePolicy
|
|
14
|
+
} from "./chunk-QRXWPZKN.js";
|
|
15
|
+
import {
|
|
16
|
+
withRetry
|
|
17
|
+
} from "./chunk-3MIR7ODJ.js";
|
|
18
|
+
import {
|
|
19
|
+
getApiKey,
|
|
20
|
+
getBaseUrl
|
|
21
|
+
} from "./chunk-VUNL35KE.js";
|
|
22
|
+
|
|
23
|
+
// src/events.ts
|
|
24
|
+
import { basename, join } from "path";
|
|
25
|
+
import { createHash } from "crypto";
|
|
26
|
+
import { existsSync, readFileSync } from "fs";
|
|
27
|
+
import { tmpdir } from "os";
|
|
28
|
+
var cleanupPendingQuestions = async (sessionId) => {
|
|
29
|
+
try {
|
|
30
|
+
const files = listPendingQuestions(sessionId);
|
|
31
|
+
const apiKey = getApiKey();
|
|
32
|
+
for (const correlationId of files) {
|
|
33
|
+
try {
|
|
34
|
+
await cancelQuestion(apiKey, correlationId);
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
removePendingQuestion(sessionId, correlationId);
|
|
38
|
+
}
|
|
39
|
+
if (!isDefaultSession(sessionId)) removePendingSession(sessionId);
|
|
40
|
+
} catch {
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var CLAUDE_CODE_AGENT = { type: "claude_code", label: "Claude Code" };
|
|
44
|
+
var POLICY_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
45
|
+
var readFreshCachedPolicy = (apiKey) => {
|
|
46
|
+
const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
|
|
47
|
+
const path = join(tmpdir(), `pushary-policy-${hash}.json`);
|
|
48
|
+
if (!existsSync(path)) return null;
|
|
49
|
+
const cached = JSON.parse(readFileSync(path, "utf-8"));
|
|
50
|
+
if (!isPolicyConfig(cached)) return null;
|
|
51
|
+
if (!cached._cachedAt || Date.now() - cached._cachedAt >= POLICY_CACHE_TTL_MS) return null;
|
|
52
|
+
return cached;
|
|
53
|
+
};
|
|
54
|
+
var deriveDecisionSource = (toolName, toolInput) => {
|
|
55
|
+
try {
|
|
56
|
+
const policy = readFreshCachedPolicy(getApiKey());
|
|
57
|
+
if (!policy) return void 0;
|
|
58
|
+
const resolved = resolvePolicy(policy, toolName, null, toolInput);
|
|
59
|
+
if (resolved.timeoutSeconds === 0 && resolved.timeoutAction === "approve") return "policy_auto";
|
|
60
|
+
if (resolved.mode === "push_only" || resolved.mode === "push_first") return "human";
|
|
61
|
+
return "terminal";
|
|
62
|
+
} catch {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var reportEvent = async (event, options = {}) => {
|
|
67
|
+
const apiKey = getApiKey();
|
|
68
|
+
const baseUrl = getBaseUrl();
|
|
69
|
+
await withRetry(async () => {
|
|
70
|
+
await fetch(`${baseUrl}/api/agent/event`, {
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: {
|
|
73
|
+
"Content-Type": "application/json",
|
|
74
|
+
"Authorization": `Bearer ${apiKey}`
|
|
75
|
+
},
|
|
76
|
+
body: JSON.stringify({
|
|
77
|
+
...event,
|
|
78
|
+
machineId: event.machineId ?? getMachineId()
|
|
79
|
+
}),
|
|
80
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? 1e4)
|
|
81
|
+
});
|
|
82
|
+
}, { maxAttempts: options.maxAttempts ?? 2, baseDelayMs: 300 });
|
|
83
|
+
};
|
|
84
|
+
var handlePostToolUse = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
85
|
+
try {
|
|
86
|
+
const projectName = basename(input.cwd ?? process.cwd());
|
|
87
|
+
const action = describeToolCall(input.tool_name, input.tool_input, "event");
|
|
88
|
+
const isError = isToolResultError(input.tool_result);
|
|
89
|
+
const receiptsEnabled = process.env.PUSHARY_RECEIPTS !== "off";
|
|
90
|
+
await Promise.allSettled([
|
|
91
|
+
cleanupPendingQuestions(input.session_id || DEFAULT_SESSION),
|
|
92
|
+
reportEvent({
|
|
93
|
+
event: isError ? "tool_error" : "tool_complete",
|
|
94
|
+
agentType: agent.type,
|
|
95
|
+
agentName: `${agent.label} - ${projectName}`,
|
|
96
|
+
action,
|
|
97
|
+
sessionId: input.session_id,
|
|
98
|
+
error: isError ? String(input.tool_result?.error ?? input.tool_result?.stderr ?? "").slice(0, 500) : void 0,
|
|
99
|
+
decisionSource: deriveDecisionSource(input.tool_name, input.tool_input),
|
|
100
|
+
meta: receiptsEnabled ? deriveReceiptMeta(input.tool_name, input.tool_input, input.tool_result, input.cwd ?? process.cwd()) : void 0
|
|
101
|
+
})
|
|
102
|
+
]);
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var TASK_TITLE_MAX_LENGTH = 120;
|
|
107
|
+
var handleUserPrompt = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
108
|
+
try {
|
|
109
|
+
const projectName = basename(input.cwd ?? process.cwd());
|
|
110
|
+
const titlesEnabled = process.env.PUSHARY_TASK_TITLES !== "off";
|
|
111
|
+
const taskTitle = titlesEnabled ? input.prompt?.replace(/\s+/g, " ").trim().slice(0, TASK_TITLE_MAX_LENGTH) || void 0 : void 0;
|
|
112
|
+
await reportEvent({
|
|
113
|
+
event: "user_prompt",
|
|
114
|
+
agentType: agent.type,
|
|
115
|
+
agentName: `${agent.label} - ${projectName}`,
|
|
116
|
+
sessionId: input.session_id,
|
|
117
|
+
taskTitle
|
|
118
|
+
}, { maxAttempts: 1, timeoutMs: 800 });
|
|
119
|
+
} catch {
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var handleStop = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
123
|
+
try {
|
|
124
|
+
const projectName = basename(input.cwd ?? process.cwd());
|
|
125
|
+
await Promise.allSettled([
|
|
126
|
+
cleanupPendingQuestions(input.session_id || DEFAULT_SESSION),
|
|
127
|
+
reportEvent({
|
|
128
|
+
event: "session_end",
|
|
129
|
+
agentType: agent.type,
|
|
130
|
+
agentName: `${agent.label} - ${projectName}`,
|
|
131
|
+
action: "Session ended",
|
|
132
|
+
sessionId: input.session_id
|
|
133
|
+
})
|
|
134
|
+
]);
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
var handleNotification = async (input) => {
|
|
139
|
+
try {
|
|
140
|
+
const projectName = basename(input.cwd ?? process.cwd());
|
|
141
|
+
await reportEvent({
|
|
142
|
+
event: input.type === "error" ? "error" : "notification",
|
|
143
|
+
agentType: "claude_code",
|
|
144
|
+
agentName: `Claude Code - ${projectName}`,
|
|
145
|
+
action: input.title ?? input.message ?? "Notification",
|
|
146
|
+
sessionId: input.session_id,
|
|
147
|
+
error: input.type === "error" ? input.message : void 0
|
|
148
|
+
});
|
|
149
|
+
} catch {
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export {
|
|
154
|
+
reportEvent,
|
|
155
|
+
handlePostToolUse,
|
|
156
|
+
handleUserPrompt,
|
|
157
|
+
handleStop,
|
|
158
|
+
handleNotification
|
|
159
|
+
};
|