@pushary/agent-hooks 0.35.0 → 0.37.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.
- package/dist/bin/pushary-clean.js +1 -1
- package/dist/bin/pushary-codex-hook.js +1 -1
- package/dist/bin/pushary-codex.js +1 -1
- package/dist/bin/pushary-gemini-hook.js +1 -1
- package/dist/bin/pushary-hook.js +2 -2
- package/dist/bin/pushary-notification-hook.js +1 -1
- package/dist/bin/pushary-post-hook.js +1 -1
- package/dist/bin/pushary-prompt-hook.js +1 -1
- package/dist/bin/pushary-session-end-hook.d.ts +1 -0
- package/dist/bin/pushary-session-end-hook.js +21 -0
- package/dist/bin/pushary-session-start-hook.js +1 -1
- package/dist/bin/pushary-setup.js +2 -2
- package/dist/bin/pushary-stop-hook.js +1 -1
- package/dist/bin/pushary-stopfailure-hook.d.ts +1 -0
- package/dist/bin/pushary-stopfailure-hook.js +21 -0
- package/dist/{chunk-JE3WQW63.js → chunk-BK4RU2BF.js} +1 -1
- package/dist/{chunk-ZJICOAAN.js → chunk-JWASPLL3.js} +20 -2
- package/dist/{chunk-FIBI2QZC.js → chunk-XVN5SMME.js} +102 -8
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +2 -2
- package/package.json +3 -1
package/dist/bin/pushary-hook.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
handlePreToolUse
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-BK4RU2BF.js";
|
|
5
5
|
import "../chunk-KQYIHZ5E.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-XVN5SMME.js";
|
|
7
7
|
import "../chunk-R5AJNXZS.js";
|
|
8
8
|
import "../chunk-DWED7BS3.js";
|
|
9
9
|
import "../chunk-Z5PL3K7C.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
handleSessionEnd
|
|
4
|
+
} from "../chunk-XVN5SMME.js";
|
|
5
|
+
import "../chunk-DWED7BS3.js";
|
|
6
|
+
import "../chunk-Z5PL3K7C.js";
|
|
7
|
+
import "../chunk-NKXSILEW.js";
|
|
8
|
+
|
|
9
|
+
// bin/pushary-session-end-hook.ts
|
|
10
|
+
var main = async () => {
|
|
11
|
+
let rawInput = "";
|
|
12
|
+
for await (const chunk of process.stdin) {
|
|
13
|
+
rawInput += chunk;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const input = rawInput.trim() ? JSON.parse(rawInput) : {};
|
|
17
|
+
await handleSessionEnd(input);
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
main();
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
addClaudeMcpServer,
|
|
4
4
|
addPusharyHooks,
|
|
5
5
|
addPusharyToolPermissions
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-JWASPLL3.js";
|
|
7
7
|
import {
|
|
8
8
|
GEMINI_HOOK_BINARY,
|
|
9
9
|
addCodexHookTrust,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
} from "../chunk-J7JWI3KU.js";
|
|
25
25
|
import {
|
|
26
26
|
reportEvent
|
|
27
|
-
} from "../chunk-
|
|
27
|
+
} from "../chunk-XVN5SMME.js";
|
|
28
28
|
import "../chunk-DWED7BS3.js";
|
|
29
29
|
import {
|
|
30
30
|
isValidApiKey
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
handleStopFailure
|
|
4
|
+
} from "../chunk-XVN5SMME.js";
|
|
5
|
+
import "../chunk-DWED7BS3.js";
|
|
6
|
+
import "../chunk-Z5PL3K7C.js";
|
|
7
|
+
import "../chunk-NKXSILEW.js";
|
|
8
|
+
|
|
9
|
+
// bin/pushary-stopfailure-hook.ts
|
|
10
|
+
var main = async () => {
|
|
11
|
+
let rawInput = "";
|
|
12
|
+
for await (const chunk of process.stdin) {
|
|
13
|
+
rawInput += chunk;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const input = rawInput.trim() ? JSON.parse(rawInput) : {};
|
|
17
|
+
await handleStopFailure(input);
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
main();
|
|
@@ -20,7 +20,7 @@ var isPusharyHook = (entry) => {
|
|
|
20
20
|
if (!Array.isArray(hooks)) return false;
|
|
21
21
|
return hooks.some((hook) => {
|
|
22
22
|
const command = String(asRecord(hook)?.command ?? "");
|
|
23
|
-
return command.includes("pushary-hook") || command.includes("pushary-post-hook") || command.includes("pushary-stop-hook") || command.includes("pushary-prompt-hook") || command.includes("pushary-notification-hook") || command.includes("pushary-session-start-hook");
|
|
23
|
+
return command.includes("pushary-hook") || command.includes("pushary-post-hook") || command.includes("pushary-stop-hook") || command.includes("pushary-prompt-hook") || command.includes("pushary-notification-hook") || command.includes("pushary-session-start-hook") || command.includes("pushary-session-end-hook") || command.includes("pushary-stopfailure-hook");
|
|
24
24
|
});
|
|
25
25
|
};
|
|
26
26
|
var addClaudeMcpServer = (config, apiKey) => {
|
|
@@ -124,6 +124,24 @@ var addPusharyHooks = (settings, binDir) => {
|
|
|
124
124
|
}]
|
|
125
125
|
});
|
|
126
126
|
hooks.SessionStart = sessionStart;
|
|
127
|
+
const sessionEnd = (Array.isArray(hooks.SessionEnd) ? hooks.SessionEnd : []).filter((entry) => !isPusharyHook(entry));
|
|
128
|
+
sessionEnd.push({
|
|
129
|
+
hooks: [{
|
|
130
|
+
type: "command",
|
|
131
|
+
command: resolve("pushary-session-end-hook"),
|
|
132
|
+
timeout: 10
|
|
133
|
+
}]
|
|
134
|
+
});
|
|
135
|
+
hooks.SessionEnd = sessionEnd;
|
|
136
|
+
const stopFailure = (Array.isArray(hooks.StopFailure) ? hooks.StopFailure : []).filter((entry) => !isPusharyHook(entry));
|
|
137
|
+
stopFailure.push({
|
|
138
|
+
hooks: [{
|
|
139
|
+
type: "command",
|
|
140
|
+
command: resolve("pushary-stopfailure-hook"),
|
|
141
|
+
timeout: 10
|
|
142
|
+
}]
|
|
143
|
+
});
|
|
144
|
+
hooks.StopFailure = stopFailure;
|
|
127
145
|
};
|
|
128
146
|
var removePusharySettings = (settings) => {
|
|
129
147
|
let changed = removeClaudeMcpServers(settings);
|
|
@@ -142,7 +160,7 @@ var removePusharySettings = (settings) => {
|
|
|
142
160
|
}
|
|
143
161
|
const hooks = asRecord(settings.hooks);
|
|
144
162
|
if (hooks) {
|
|
145
|
-
for (const key of ["PreToolUse", "PostToolUse", "Stop", "UserPromptSubmit", "Notification", "SessionStart"]) {
|
|
163
|
+
for (const key of ["PreToolUse", "PostToolUse", "Stop", "StopFailure", "UserPromptSubmit", "Notification", "SessionStart", "SessionEnd"]) {
|
|
146
164
|
const entries = hooks[key];
|
|
147
165
|
if (!Array.isArray(entries)) continue;
|
|
148
166
|
const filtered = entries.filter((entry) => !isPusharyHook(entry));
|
|
@@ -812,12 +812,14 @@ var reportEvent = async (event, options = {}) => {
|
|
|
812
812
|
}
|
|
813
813
|
}, { maxAttempts: options.maxAttempts ?? 2, baseDelayMs: 300 });
|
|
814
814
|
};
|
|
815
|
+
var NON_GATED_MIRROR_TOOLS = /* @__PURE__ */ new Set(["TodoWrite"]);
|
|
815
816
|
var handlePostToolUse = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
816
817
|
try {
|
|
817
818
|
const projectName = basename(input.cwd ?? process.cwd());
|
|
818
819
|
const action = describeToolCall(input.tool_name, input.tool_input, "event");
|
|
819
820
|
const lookup = toPolicyLookup(input.tool_name, input.tool_input);
|
|
820
|
-
const
|
|
821
|
+
const toolResult = input.tool_response ?? input.tool_result;
|
|
822
|
+
const isError = isToolResultError(toolResult);
|
|
821
823
|
const receiptsEnabled = process.env.PUSHARY_RECEIPTS !== "off";
|
|
822
824
|
const sessionKey = input.session_id || DEFAULT_SESSION;
|
|
823
825
|
const liveMode = await fetchModeState(getApiKey(), input.session_id);
|
|
@@ -827,18 +829,19 @@ var handlePostToolUse = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
|
827
829
|
additionalContext = buildLateAnswerContext(late);
|
|
828
830
|
for (const l of late) removePendingQuestion(sessionKey, l.correlationId);
|
|
829
831
|
}
|
|
830
|
-
const
|
|
831
|
-
const
|
|
832
|
+
const isMirrorOnly = NON_GATED_MIRROR_TOOLS.has(input.tool_name);
|
|
833
|
+
const decisionSource = isMirrorOnly ? void 0 : deriveDecisionSource(lookup.tool, lookup.input, liveMode);
|
|
834
|
+
const beacon = !isMirrorOnly && decisionSource === "policy_auto" && throttlePass(`autodecision:${sessionKey}:${lookup.tool}`, AUTO_DECISION_WINDOW_MS) ? deriveAutoDecisionBeacon(lookup.tool, lookup.input, liveMode) : void 0;
|
|
832
835
|
const toolReport = reportEvent({
|
|
833
836
|
event: isError ? "tool_error" : "tool_complete",
|
|
834
837
|
agentType: agent.type,
|
|
835
838
|
agentName: `${agent.label} - ${projectName}`,
|
|
836
839
|
action,
|
|
837
840
|
sessionId: input.session_id,
|
|
838
|
-
error: isError ? String(
|
|
841
|
+
error: isError ? String(toolResult?.error ?? toolResult?.stderr ?? "").slice(0, 500) : void 0,
|
|
839
842
|
decisionSource,
|
|
840
843
|
...beacon ? { decisionOrigin: beacon.decisionOrigin, toolName: beacon.toolName, toolTarget: beacon.toolTarget } : {},
|
|
841
|
-
meta: receiptsEnabled ? deriveReceiptMeta(lookup.tool, lookup.input,
|
|
844
|
+
meta: receiptsEnabled ? deriveReceiptMeta(lookup.tool, lookup.input, toolResult, input.cwd ?? process.cwd()) : void 0,
|
|
842
845
|
usage: deriveUsage(input.transcript_path, input.session_id)
|
|
843
846
|
}, { maxAttempts: 1 });
|
|
844
847
|
const extraReports = [];
|
|
@@ -902,6 +905,14 @@ var summarizeFinalMessage = (message) => {
|
|
|
902
905
|
if (!collapsed) return "Session ended";
|
|
903
906
|
return collapsed.slice(0, STOP_SUMMARY_MAX_LENGTH);
|
|
904
907
|
};
|
|
908
|
+
var countArray = (value) => Array.isArray(value) ? value.length : 0;
|
|
909
|
+
var summarizeStop = (input) => {
|
|
910
|
+
const running = countArray(input.background_tasks);
|
|
911
|
+
if (running > 0) return `Paused with ${running} background task${running === 1 ? "" : "s"} still running`;
|
|
912
|
+
const crons = countArray(input.session_crons);
|
|
913
|
+
if (crons > 0) return `Idle until a scheduled task wakes it (${crons} pending)`;
|
|
914
|
+
return summarizeFinalMessage(input.last_assistant_message);
|
|
915
|
+
};
|
|
905
916
|
var handleStop = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
906
917
|
try {
|
|
907
918
|
const projectName = basename(input.cwd ?? process.cwd());
|
|
@@ -915,7 +926,7 @@ var handleStop = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
|
915
926
|
event: "session_end",
|
|
916
927
|
agentType: agent.type,
|
|
917
928
|
agentName: `${agent.label} - ${projectName}`,
|
|
918
|
-
action:
|
|
929
|
+
action: summarizeStop(input),
|
|
919
930
|
sessionId: input.session_id,
|
|
920
931
|
usage: deriveUsage(input.transcript_path, input.session_id)
|
|
921
932
|
}, { maxAttempts: 1 })
|
|
@@ -948,7 +959,37 @@ var handleSessionStart = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
|
948
959
|
agentName: `${agent.label} - ${projectName}`,
|
|
949
960
|
action,
|
|
950
961
|
sessionId: input.session_id
|
|
951
|
-
}, { maxAttempts:
|
|
962
|
+
}, { maxAttempts: 2, timeoutMs: 4e3 });
|
|
963
|
+
} catch {
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
var SESSION_END_ACTIONS = {
|
|
967
|
+
clear: "Session cleared",
|
|
968
|
+
logout: "Logged out",
|
|
969
|
+
resume: "Session suspended",
|
|
970
|
+
prompt_input_exit: "Session ended",
|
|
971
|
+
bypass_permissions_disabled: "Session ended",
|
|
972
|
+
other: "Session ended"
|
|
973
|
+
};
|
|
974
|
+
var handleSessionEnd = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
975
|
+
try {
|
|
976
|
+
const projectName = basename(input.cwd ?? process.cwd());
|
|
977
|
+
const action = typeof input.reason === "string" && SESSION_END_ACTIONS[input.reason] || "Session ended";
|
|
978
|
+
const sessionKey = input.session_id || DEFAULT_SESSION;
|
|
979
|
+
const late = await reconcilePendingQuestions(sessionKey);
|
|
980
|
+
if (late.length > 0) {
|
|
981
|
+
await notifyLateAnswers(getApiKey(), late, `${agent.label} - ${projectName}`, input.session_id).catch(() => {
|
|
982
|
+
});
|
|
983
|
+
for (const l of late) removePendingQuestion(sessionKey, l.correlationId);
|
|
984
|
+
}
|
|
985
|
+
if (!isDefaultSession(sessionKey)) removePendingSession(sessionKey);
|
|
986
|
+
await reportEvent({
|
|
987
|
+
event: "session_closed",
|
|
988
|
+
agentType: agent.type,
|
|
989
|
+
agentName: `${agent.label} - ${projectName}`,
|
|
990
|
+
action,
|
|
991
|
+
sessionId: input.session_id
|
|
992
|
+
}, { maxAttempts: 2, timeoutMs: 3e3 });
|
|
952
993
|
} catch {
|
|
953
994
|
}
|
|
954
995
|
};
|
|
@@ -990,6 +1031,57 @@ var handleNotification = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
|
990
1031
|
} catch {
|
|
991
1032
|
}
|
|
992
1033
|
};
|
|
1034
|
+
var STOPFAILURE_MAX_ERROR_LENGTH = 300;
|
|
1035
|
+
var STOPFAILURE_REASONS = {
|
|
1036
|
+
rate_limit: "Rate limited by the API",
|
|
1037
|
+
overloaded: "The API is overloaded right now",
|
|
1038
|
+
authentication_failed: "Authentication failed",
|
|
1039
|
+
billing_error: "A billing error stopped the turn"
|
|
1040
|
+
};
|
|
1041
|
+
var describeStopFailure = (error) => {
|
|
1042
|
+
const fromString = (s) => {
|
|
1043
|
+
const v = s.trim();
|
|
1044
|
+
if (!v) return void 0;
|
|
1045
|
+
return STOPFAILURE_REASONS[v] ?? v.slice(0, STOPFAILURE_MAX_ERROR_LENGTH);
|
|
1046
|
+
};
|
|
1047
|
+
if (typeof error === "string") {
|
|
1048
|
+
const described = fromString(error);
|
|
1049
|
+
if (described) return described;
|
|
1050
|
+
} else if (error && typeof error === "object") {
|
|
1051
|
+
const e = error;
|
|
1052
|
+
for (const key of ["type", "message", "error", "code"]) {
|
|
1053
|
+
const val = e[key];
|
|
1054
|
+
if (typeof val === "string") {
|
|
1055
|
+
const described = fromString(val);
|
|
1056
|
+
if (described) return described;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
return "The turn ended on an API error (rate limit, billing, or auth).";
|
|
1061
|
+
};
|
|
1062
|
+
var handleStopFailure = async (input, agent = CLAUDE_CODE_AGENT) => {
|
|
1063
|
+
try {
|
|
1064
|
+
let apiKey;
|
|
1065
|
+
try {
|
|
1066
|
+
apiKey = getApiKey();
|
|
1067
|
+
} catch {
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
const projectName = basename(input.cwd ?? process.cwd());
|
|
1071
|
+
const mode = await fetchModeState(apiKey, input.session_id).catch(() => null);
|
|
1072
|
+
if (mode?.kill || mode?.mode === "terminal_only") return;
|
|
1073
|
+
const reason = describeStopFailure(input.error);
|
|
1074
|
+
await sendNotification(apiKey, {
|
|
1075
|
+
title: `${agent.label} stopped on an error`,
|
|
1076
|
+
body: reason,
|
|
1077
|
+
agentName: `${agent.label} - ${projectName}`,
|
|
1078
|
+
sessionId: input.session_id,
|
|
1079
|
+
context: { type: "error", errorMessage: reason }
|
|
1080
|
+
}, 4e3).catch(() => {
|
|
1081
|
+
});
|
|
1082
|
+
} catch {
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
993
1085
|
|
|
994
1086
|
export {
|
|
995
1087
|
askUser,
|
|
@@ -1024,5 +1116,7 @@ export {
|
|
|
1024
1116
|
handleUserPrompt,
|
|
1025
1117
|
handleStop,
|
|
1026
1118
|
handleSessionStart,
|
|
1027
|
-
|
|
1119
|
+
handleSessionEnd,
|
|
1120
|
+
handleNotification,
|
|
1121
|
+
handleStopFailure
|
|
1028
1122
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -78,6 +78,7 @@ declare const reportEvent: (event: AgentEvent, options?: ReportEventOptions) =>
|
|
|
78
78
|
declare const handlePostToolUse: (input: {
|
|
79
79
|
tool_name: string;
|
|
80
80
|
tool_input: Record<string, unknown>;
|
|
81
|
+
tool_response?: Record<string, unknown>;
|
|
81
82
|
tool_result?: Record<string, unknown>;
|
|
82
83
|
cwd?: string;
|
|
83
84
|
session_id?: string;
|
|
@@ -93,6 +94,8 @@ declare const handleStop: (input: {
|
|
|
93
94
|
stop_hook_active?: boolean;
|
|
94
95
|
transcript_path?: string;
|
|
95
96
|
last_assistant_message?: string;
|
|
97
|
+
background_tasks?: unknown;
|
|
98
|
+
session_crons?: unknown;
|
|
96
99
|
}, agent?: AgentIdentity) => Promise<StopHookOutput | undefined>;
|
|
97
100
|
declare const handleNotification: (input: {
|
|
98
101
|
message?: string;
|
package/dist/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
handlePreToolUse
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-BK4RU2BF.js";
|
|
4
4
|
import "../chunk-KQYIHZ5E.js";
|
|
5
5
|
import {
|
|
6
6
|
askUser,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
reportEvent,
|
|
15
15
|
resolvePolicy,
|
|
16
16
|
waitForAnswer
|
|
17
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-XVN5SMME.js";
|
|
18
18
|
import "../chunk-R5AJNXZS.js";
|
|
19
19
|
import "../chunk-DWED7BS3.js";
|
|
20
20
|
import "../chunk-Z5PL3K7C.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushary/agent-hooks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Permission hooks for AI coding agents: route tool approvals through Pushary push notifications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pushary",
|
|
@@ -49,6 +49,8 @@
|
|
|
49
49
|
"pushary-prompt-hook": "./dist/bin/pushary-prompt-hook.js",
|
|
50
50
|
"pushary-notification-hook": "./dist/bin/pushary-notification-hook.js",
|
|
51
51
|
"pushary-session-start-hook": "./dist/bin/pushary-session-start-hook.js",
|
|
52
|
+
"pushary-session-end-hook": "./dist/bin/pushary-session-end-hook.js",
|
|
53
|
+
"pushary-stopfailure-hook": "./dist/bin/pushary-stopfailure-hook.js",
|
|
52
54
|
"pushary-claude": "./dist/bin/pushary-claude.js",
|
|
53
55
|
"pushary-codex": "./dist/bin/pushary-codex.js",
|
|
54
56
|
"pushary-codex-hook": "./dist/bin/pushary-codex-hook.js",
|