@pushary/agent-hooks 0.8.2 → 0.9.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.js +17 -10
- package/dist/bin/pushary-doctor.js +35 -2
- package/dist/bin/pushary-hook.js +3 -2
- package/dist/bin/pushary-post-hook.js +2 -2
- package/dist/bin/pushary-setup.js +37 -31
- package/dist/bin/pushary-stop-hook.js +2 -2
- package/dist/chunk-5GFUI5N6.js +132 -0
- package/dist/chunk-6SRXMZAN.js +99 -0
- package/dist/chunk-7PTU7TGE.js +96 -0
- package/dist/chunk-AB4KX4XT.js +109 -0
- package/dist/chunk-IBWCHA5M.js +10 -0
- package/dist/chunk-M2N5DYWN.js +247 -0
- package/dist/chunk-M6S3M6E3.js +244 -0
- package/dist/chunk-OF5WIOYS.js +129 -0
- package/dist/chunk-W5KRWUNE.js +262 -0
- package/dist/src/index.d.ts +13 -17
- package/dist/src/index.js +6 -3
- package/package.json +5 -4
|
@@ -0,0 +1,129 @@
|
|
|
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 }, { maxRetries: 3 });
|
|
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 }, { maxRetries: 3 });
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/identity.ts
|
|
44
|
+
import { createHash } from "crypto";
|
|
45
|
+
import { hostname } from "os";
|
|
46
|
+
var deriveMachineId = (host) => createHash("sha256").update(host).digest("hex").slice(0, 8);
|
|
47
|
+
var getMachineId = () => deriveMachineId(hostname());
|
|
48
|
+
|
|
49
|
+
// src/describe.ts
|
|
50
|
+
var hookPrefixes = {
|
|
51
|
+
Bash: (input) => `bash: ${input.command ?? "(no command)"}`,
|
|
52
|
+
Write: (input) => `write file: ${input.file_path ?? "(unknown path)"}`,
|
|
53
|
+
Edit: (input) => `edit file: ${input.file_path ?? "(unknown path)"}`,
|
|
54
|
+
Read: (input) => `read file: ${input.file_path ?? "(unknown path)"}`
|
|
55
|
+
};
|
|
56
|
+
var eventPrefixes = {
|
|
57
|
+
Bash: (input) => `ran: ${String(input.command ?? "").slice(0, 120)}`,
|
|
58
|
+
Write: (input) => `wrote: ${input.file_path ?? "unknown"}`,
|
|
59
|
+
Edit: (input) => `edited: ${input.file_path ?? "unknown"}`,
|
|
60
|
+
Read: (input) => `read: ${input.file_path ?? "unknown"}`
|
|
61
|
+
};
|
|
62
|
+
var describeToolCall = (toolName, toolInput, format = "hook") => {
|
|
63
|
+
const prefixes = format === "hook" ? hookPrefixes : eventPrefixes;
|
|
64
|
+
const builder = prefixes[toolName];
|
|
65
|
+
if (builder) return builder(toolInput);
|
|
66
|
+
return format === "hook" ? `${toolName}: ${JSON.stringify(toolInput).slice(0, 200)}` : `${toolName}: done`;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/pending.ts
|
|
70
|
+
import { join } from "path";
|
|
71
|
+
import { tmpdir } from "os";
|
|
72
|
+
import { existsSync, mkdirSync, writeFileSync, readdirSync, unlinkSync, rmSync, statSync } from "fs";
|
|
73
|
+
var PENDING_DIR = join(tmpdir(), "pushary-pending");
|
|
74
|
+
var DEFAULT_SESSION = "_no_session";
|
|
75
|
+
var GRACE_MS = 10 * 60 * 1e3;
|
|
76
|
+
var sanitize = (sessionId) => sessionId.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 128) || DEFAULT_SESSION;
|
|
77
|
+
var dirFor = (sessionId) => join(PENDING_DIR, sanitize(sessionId));
|
|
78
|
+
var isDefaultSession = (sessionId) => sanitize(sessionId) === DEFAULT_SESSION;
|
|
79
|
+
var savePendingQuestion = (sessionId, correlationId) => {
|
|
80
|
+
const dir = dirFor(sessionId);
|
|
81
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
82
|
+
writeFileSync(join(dir, correlationId), "", "utf-8");
|
|
83
|
+
};
|
|
84
|
+
var listPendingQuestions = (sessionId) => {
|
|
85
|
+
const dir = dirFor(sessionId);
|
|
86
|
+
let files;
|
|
87
|
+
try {
|
|
88
|
+
files = readdirSync(dir);
|
|
89
|
+
} catch {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
if (!isDefaultSession(sessionId)) return files;
|
|
93
|
+
const cutoff = Date.now() - GRACE_MS;
|
|
94
|
+
return files.filter((name) => {
|
|
95
|
+
try {
|
|
96
|
+
return statSync(join(dir, name)).mtimeMs < cutoff;
|
|
97
|
+
} catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
var removePendingQuestion = (sessionId, correlationId) => {
|
|
103
|
+
try {
|
|
104
|
+
unlinkSync(join(dirFor(sessionId), correlationId));
|
|
105
|
+
} catch {
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var removePendingSession = (sessionId) => {
|
|
109
|
+
try {
|
|
110
|
+
rmSync(dirFor(sessionId), { recursive: true, force: true });
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export {
|
|
116
|
+
isPolicyConfig,
|
|
117
|
+
askUser,
|
|
118
|
+
waitForAnswer,
|
|
119
|
+
cancelQuestion,
|
|
120
|
+
sendNotification,
|
|
121
|
+
describeToolCall,
|
|
122
|
+
DEFAULT_SESSION,
|
|
123
|
+
isDefaultSession,
|
|
124
|
+
savePendingQuestion,
|
|
125
|
+
listPendingQuestions,
|
|
126
|
+
removePendingQuestion,
|
|
127
|
+
removePendingSession,
|
|
128
|
+
getMachineId
|
|
129
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isApprovalMode
|
|
3
|
+
} from "./chunk-IBWCHA5M.js";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_SESSION,
|
|
6
|
+
askUser,
|
|
7
|
+
describeToolCall,
|
|
8
|
+
getMachineId,
|
|
9
|
+
isPolicyConfig,
|
|
10
|
+
savePendingQuestion,
|
|
11
|
+
sendNotification,
|
|
12
|
+
waitForAnswer
|
|
13
|
+
} from "./chunk-OF5WIOYS.js";
|
|
14
|
+
import {
|
|
15
|
+
withRetry
|
|
16
|
+
} from "./chunk-3MIR7ODJ.js";
|
|
17
|
+
import {
|
|
18
|
+
getApiKey,
|
|
19
|
+
getBaseUrl
|
|
20
|
+
} from "./chunk-VUNL35KE.js";
|
|
21
|
+
|
|
22
|
+
// src/policy.ts
|
|
23
|
+
import { createHash } from "crypto";
|
|
24
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
25
|
+
import { join } from "path";
|
|
26
|
+
import { tmpdir } from "os";
|
|
27
|
+
var CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
28
|
+
var cacheFile = (apiKey) => {
|
|
29
|
+
const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
|
|
30
|
+
return join(tmpdir(), `pushary-policy-${hash}.json`);
|
|
31
|
+
};
|
|
32
|
+
var fetchPolicy = async (apiKey) => {
|
|
33
|
+
return withRetry(async () => {
|
|
34
|
+
const baseUrl = getBaseUrl();
|
|
35
|
+
const response = await fetch(`${baseUrl}/api/mcp/policy`, {
|
|
36
|
+
headers: { "Authorization": `Bearer ${apiKey}` },
|
|
37
|
+
signal: AbortSignal.timeout(1e4)
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new Error(`Failed to fetch policy: ${response.status}`);
|
|
41
|
+
}
|
|
42
|
+
const raw = await response.json();
|
|
43
|
+
if (!isPolicyConfig(raw)) throw new Error("Invalid policy response");
|
|
44
|
+
return raw;
|
|
45
|
+
}, { maxAttempts: 2 });
|
|
46
|
+
};
|
|
47
|
+
var getPolicy = async (apiKey) => {
|
|
48
|
+
const path = cacheFile(apiKey);
|
|
49
|
+
let staleCache = null;
|
|
50
|
+
if (existsSync(path)) {
|
|
51
|
+
try {
|
|
52
|
+
const stat = readFileSync(path, "utf-8");
|
|
53
|
+
const cached = JSON.parse(stat);
|
|
54
|
+
if (!isPolicyConfig(cached)) throw new Error("Corrupted cache");
|
|
55
|
+
if (!cached._cachedAt || Date.now() - cached._cachedAt < CACHE_TTL_MS) {
|
|
56
|
+
return cached;
|
|
57
|
+
}
|
|
58
|
+
staleCache = cached;
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const policy = await fetchPolicy(apiKey);
|
|
64
|
+
try {
|
|
65
|
+
writeFileSync(path, JSON.stringify({ ...policy, _cachedAt: Date.now() }), "utf-8");
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
return policy;
|
|
69
|
+
} catch {
|
|
70
|
+
if (staleCache) return staleCache;
|
|
71
|
+
throw new Error("Failed to fetch policy and no cached policy available");
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var resolvePolicy = (config, toolName, modeOverride) => {
|
|
75
|
+
const base = config.policies.find((p) => p.tool === toolName) ?? config.policies.find((p) => p.tool === "*") ?? {
|
|
76
|
+
tool: toolName,
|
|
77
|
+
timeoutSeconds: config.defaultTimeoutSeconds,
|
|
78
|
+
timeoutAction: config.defaultTimeoutAction,
|
|
79
|
+
mode: config.defaultMode ?? "push_first",
|
|
80
|
+
pushFirstSeconds: config.defaultPushFirstSeconds ?? 20
|
|
81
|
+
};
|
|
82
|
+
const effectiveOverride = modeOverride ?? config.modeOverride;
|
|
83
|
+
if (effectiveOverride) {
|
|
84
|
+
return { ...base, mode: effectiveOverride };
|
|
85
|
+
}
|
|
86
|
+
return base;
|
|
87
|
+
};
|
|
88
|
+
var fetchModeState = async (apiKey, sessionId) => {
|
|
89
|
+
try {
|
|
90
|
+
const baseUrl = getBaseUrl();
|
|
91
|
+
const url = sessionId ? `${baseUrl}/api/mcp/mode?session=${encodeURIComponent(sessionId)}` : `${baseUrl}/api/mcp/mode`;
|
|
92
|
+
const response = await fetch(url, {
|
|
93
|
+
headers: { "Authorization": `Bearer ${apiKey}` },
|
|
94
|
+
signal: AbortSignal.timeout(3e3)
|
|
95
|
+
});
|
|
96
|
+
if (!response.ok) return { mode: null, kill: false };
|
|
97
|
+
const data = await response.json();
|
|
98
|
+
const mode = data.override?.mode;
|
|
99
|
+
return { mode: isApprovalMode(mode) ? mode : null, kill: data.kill === true };
|
|
100
|
+
} catch {
|
|
101
|
+
return { mode: null, kill: false };
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var fetchModeOverride = async (apiKey) => (await fetchModeState(apiKey)).mode;
|
|
105
|
+
|
|
106
|
+
// src/hook.ts
|
|
107
|
+
import { basename } from "path";
|
|
108
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
109
|
+
var allow = () => ({
|
|
110
|
+
hookSpecificOutput: {
|
|
111
|
+
hookEventName: "PreToolUse",
|
|
112
|
+
permissionDecision: "allow"
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
var deny = (reason) => ({
|
|
116
|
+
hookSpecificOutput: {
|
|
117
|
+
hookEventName: "PreToolUse",
|
|
118
|
+
permissionDecision: "deny",
|
|
119
|
+
permissionDecisionReason: reason
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
var ask = (reason) => ({
|
|
123
|
+
hookSpecificOutput: {
|
|
124
|
+
hookEventName: "PreToolUse",
|
|
125
|
+
permissionDecision: "ask",
|
|
126
|
+
...reason ? { permissionDecisionReason: reason } : {}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
var pollForAnswer = async (apiKey, correlationId, deadlineMs, pollInterval = 2e3) => {
|
|
130
|
+
while (Date.now() < deadlineMs) {
|
|
131
|
+
const remaining = Math.min(Math.max(deadlineMs - Date.now(), 1e3), 3e4);
|
|
132
|
+
let answer;
|
|
133
|
+
try {
|
|
134
|
+
answer = await waitForAnswer(apiKey, correlationId, remaining);
|
|
135
|
+
} catch {
|
|
136
|
+
if (Date.now() + pollInterval >= deadlineMs) break;
|
|
137
|
+
await sleep(pollInterval);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (answer.answered) return answer;
|
|
141
|
+
if (Date.now() + pollInterval >= deadlineMs) break;
|
|
142
|
+
await sleep(pollInterval);
|
|
143
|
+
}
|
|
144
|
+
return { answered: false };
|
|
145
|
+
};
|
|
146
|
+
var handlePushOnly = async (apiKey, description, projectName, timeoutSeconds, timeoutAction, sessionId, machineId, toolName) => {
|
|
147
|
+
let result;
|
|
148
|
+
try {
|
|
149
|
+
result = await askUser(apiKey, {
|
|
150
|
+
question: `Allow ${description}?`,
|
|
151
|
+
type: "confirm",
|
|
152
|
+
context: `Agent wants to run this in ${projectName}`,
|
|
153
|
+
agentName: `Claude Code - ${projectName}`,
|
|
154
|
+
sessionId,
|
|
155
|
+
machineId,
|
|
156
|
+
toolName
|
|
157
|
+
});
|
|
158
|
+
} catch {
|
|
159
|
+
switch (timeoutAction) {
|
|
160
|
+
case "approve":
|
|
161
|
+
return allow();
|
|
162
|
+
case "deny":
|
|
163
|
+
return deny("Push notification failed, denying per policy");
|
|
164
|
+
default:
|
|
165
|
+
return ask("Push notification failed, asking in terminal");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const deadline = Date.now() + timeoutSeconds * 1e3;
|
|
169
|
+
const answer = await pollForAnswer(apiKey, result.correlationId, deadline);
|
|
170
|
+
if (answer.answered) {
|
|
171
|
+
return answer.value === "yes" ? allow() : deny("Denied via push notification");
|
|
172
|
+
}
|
|
173
|
+
switch (timeoutAction) {
|
|
174
|
+
case "approve":
|
|
175
|
+
return allow();
|
|
176
|
+
case "deny":
|
|
177
|
+
return deny("No response within timeout");
|
|
178
|
+
default:
|
|
179
|
+
return ask("No push response, asking in terminal");
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
var handleTerminalOnly = () => {
|
|
183
|
+
return ask();
|
|
184
|
+
};
|
|
185
|
+
var handlePushFirst = async (apiKey, description, projectName, pushFirstSeconds, sessionId, machineId, toolName) => {
|
|
186
|
+
let result;
|
|
187
|
+
try {
|
|
188
|
+
result = await askUser(apiKey, {
|
|
189
|
+
question: `Allow ${description}?`,
|
|
190
|
+
type: "confirm",
|
|
191
|
+
context: `Agent wants to run this in ${projectName}`,
|
|
192
|
+
agentName: `Claude Code - ${projectName}`,
|
|
193
|
+
sessionId,
|
|
194
|
+
machineId,
|
|
195
|
+
toolName
|
|
196
|
+
});
|
|
197
|
+
} catch {
|
|
198
|
+
return ask("Push notification failed, asking in terminal");
|
|
199
|
+
}
|
|
200
|
+
const deadline = Date.now() + pushFirstSeconds * 1e3;
|
|
201
|
+
const answer = await pollForAnswer(apiKey, result.correlationId, deadline, 1500);
|
|
202
|
+
if (answer.answered) {
|
|
203
|
+
return answer.value === "yes" ? allow() : deny("Denied via push notification");
|
|
204
|
+
}
|
|
205
|
+
savePendingQuestion(sessionId || DEFAULT_SESSION, result.correlationId);
|
|
206
|
+
return ask("Sent as push notification. You can also approve here.");
|
|
207
|
+
};
|
|
208
|
+
var handleNotifyOnly = async (apiKey, description, projectName, sessionId, machineId) => {
|
|
209
|
+
try {
|
|
210
|
+
await sendNotification(apiKey, {
|
|
211
|
+
title: "Agent needs approval",
|
|
212
|
+
body: description,
|
|
213
|
+
agentName: `Claude Code - ${projectName}`,
|
|
214
|
+
sessionId,
|
|
215
|
+
machineId
|
|
216
|
+
});
|
|
217
|
+
} catch {
|
|
218
|
+
}
|
|
219
|
+
return ask();
|
|
220
|
+
};
|
|
221
|
+
var handlePreToolUse = async (input) => {
|
|
222
|
+
try {
|
|
223
|
+
const apiKey = getApiKey();
|
|
224
|
+
const [policy, modeState] = await Promise.all([
|
|
225
|
+
getPolicy(apiKey),
|
|
226
|
+
fetchModeState(apiKey, input.session_id)
|
|
227
|
+
]);
|
|
228
|
+
if (modeState.kill) {
|
|
229
|
+
return deny("Stopped by user \u2014 this agent was halted from Pushary");
|
|
230
|
+
}
|
|
231
|
+
const toolPolicy = resolvePolicy(policy, input.tool_name, modeState.mode);
|
|
232
|
+
if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") {
|
|
233
|
+
return allow();
|
|
234
|
+
}
|
|
235
|
+
const description = describeToolCall(input.tool_name, input.tool_input, "hook");
|
|
236
|
+
const projectName = basename(input.cwd ?? process.cwd());
|
|
237
|
+
const sessionId = input.session_id;
|
|
238
|
+
const machineId = getMachineId();
|
|
239
|
+
switch (toolPolicy.mode) {
|
|
240
|
+
case "push_only":
|
|
241
|
+
return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction, sessionId, machineId, input.tool_name);
|
|
242
|
+
case "terminal_only":
|
|
243
|
+
return handleTerminalOnly();
|
|
244
|
+
case "push_first":
|
|
245
|
+
return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name);
|
|
246
|
+
case "notify_only":
|
|
247
|
+
return handleNotifyOnly(apiKey, description, projectName, sessionId, machineId);
|
|
248
|
+
default:
|
|
249
|
+
return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds, sessionId, machineId, input.tool_name);
|
|
250
|
+
}
|
|
251
|
+
} catch {
|
|
252
|
+
return ask("Pushary unavailable, falling back to terminal approval");
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export {
|
|
257
|
+
getPolicy,
|
|
258
|
+
resolvePolicy,
|
|
259
|
+
fetchModeState,
|
|
260
|
+
fetchModeOverride,
|
|
261
|
+
handlePreToolUse
|
|
262
|
+
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { PolicyConfig, ApprovalMode, ToolPolicy } from '@pushary/contracts';
|
|
2
|
+
export { ApprovalMode, PolicyConfig, ToolPolicy } from '@pushary/contracts';
|
|
3
|
+
|
|
1
4
|
interface ToolInput {
|
|
2
5
|
tool_name: string;
|
|
3
6
|
tool_input: Record<string, unknown>;
|
|
@@ -19,6 +22,7 @@ interface AgentEvent {
|
|
|
19
22
|
agentName?: string;
|
|
20
23
|
action?: string;
|
|
21
24
|
machineId?: string;
|
|
25
|
+
sessionId?: string;
|
|
22
26
|
error?: string;
|
|
23
27
|
}
|
|
24
28
|
declare const reportEvent: (event: AgentEvent) => Promise<void>;
|
|
@@ -48,6 +52,9 @@ interface AskUserParams {
|
|
|
48
52
|
options?: string[];
|
|
49
53
|
context?: string;
|
|
50
54
|
agentName?: string;
|
|
55
|
+
sessionId?: string;
|
|
56
|
+
machineId?: string;
|
|
57
|
+
toolName?: string;
|
|
51
58
|
}
|
|
52
59
|
interface AskUserResponse {
|
|
53
60
|
correlationId: string;
|
|
@@ -61,27 +68,16 @@ declare const askUser: (apiKey: string, params: AskUserParams) => Promise<AskUse
|
|
|
61
68
|
declare const waitForAnswer: (apiKey: string, correlationId: string, timeoutMs?: number) => Promise<WaitForAnswerResponse>;
|
|
62
69
|
declare const cancelQuestion: (apiKey: string, correlationId: string) => Promise<void>;
|
|
63
70
|
|
|
64
|
-
type ApprovalMode = 'push_only' | 'terminal_only' | 'push_first' | 'notify_only';
|
|
65
|
-
interface ToolPolicy {
|
|
66
|
-
tool: string;
|
|
67
|
-
timeoutSeconds: number;
|
|
68
|
-
timeoutAction: 'approve' | 'deny' | 'escalate';
|
|
69
|
-
mode: ApprovalMode;
|
|
70
|
-
pushFirstSeconds: number;
|
|
71
|
-
}
|
|
72
|
-
interface PolicyConfig {
|
|
73
|
-
policies: ToolPolicy[];
|
|
74
|
-
defaultTimeoutSeconds: number;
|
|
75
|
-
defaultTimeoutAction: 'approve' | 'deny' | 'escalate';
|
|
76
|
-
defaultMode: ApprovalMode;
|
|
77
|
-
defaultPushFirstSeconds: number;
|
|
78
|
-
modeOverride?: ApprovalMode | null;
|
|
79
|
-
}
|
|
80
71
|
declare const getPolicy: (apiKey: string) => Promise<PolicyConfig>;
|
|
81
72
|
declare const resolvePolicy: (config: PolicyConfig, toolName: string, modeOverride?: ApprovalMode | null) => ToolPolicy;
|
|
73
|
+
interface ModeState {
|
|
74
|
+
readonly mode: ApprovalMode | null;
|
|
75
|
+
readonly kill: boolean;
|
|
76
|
+
}
|
|
77
|
+
declare const fetchModeState: (apiKey: string, sessionId?: string) => Promise<ModeState>;
|
|
82
78
|
declare const fetchModeOverride: (apiKey: string) => Promise<ApprovalMode | null>;
|
|
83
79
|
|
|
84
80
|
declare const getApiKey: () => string;
|
|
85
81
|
declare const getBaseUrl: () => string;
|
|
86
82
|
|
|
87
|
-
export { type
|
|
83
|
+
export { type ModeState, askUser, cancelQuestion, fetchModeOverride, fetchModeState, getApiKey, getBaseUrl, getPolicy, handleNotification, handlePostToolUse, handlePreToolUse, handleStop, reportEvent, resolvePolicy, waitForAnswer };
|
package/dist/src/index.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fetchModeOverride,
|
|
3
|
+
fetchModeState,
|
|
3
4
|
getPolicy,
|
|
4
5
|
handlePreToolUse,
|
|
5
6
|
resolvePolicy
|
|
6
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-W5KRWUNE.js";
|
|
8
|
+
import "../chunk-IBWCHA5M.js";
|
|
7
9
|
import {
|
|
8
10
|
handleNotification,
|
|
9
11
|
handlePostToolUse,
|
|
10
12
|
handleStop,
|
|
11
13
|
reportEvent
|
|
12
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-AB4KX4XT.js";
|
|
13
15
|
import {
|
|
14
16
|
askUser,
|
|
15
17
|
cancelQuestion,
|
|
16
18
|
waitForAnswer
|
|
17
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-OF5WIOYS.js";
|
|
18
20
|
import "../chunk-3MIR7ODJ.js";
|
|
19
21
|
import {
|
|
20
22
|
getApiKey,
|
|
@@ -24,6 +26,7 @@ export {
|
|
|
24
26
|
askUser,
|
|
25
27
|
cancelQuestion,
|
|
26
28
|
fetchModeOverride,
|
|
29
|
+
fetchModeState,
|
|
27
30
|
getApiKey,
|
|
28
31
|
getBaseUrl,
|
|
29
32
|
getPolicy,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushary/agent-hooks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Permission hooks for AI coding agents: route tool approvals through Pushary push notifications",
|
|
5
5
|
"author": "Pushary <business@pushary.com>",
|
|
6
6
|
"homepage": "https://pushary.com",
|
|
@@ -30,15 +30,16 @@
|
|
|
30
30
|
"data"
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "tsup
|
|
34
|
-
"dev": "tsup
|
|
35
|
-
"test": "bun test src/api.test.ts && bun test src/claude-config.test.ts && bun test src/mcp-http.test.ts && bun test src/retry.test.ts && bun test src/validate.test.ts && bun test src/policy.test.ts && bun test src/events.test.ts && bun test src/hook.test.ts"
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"dev": "tsup --watch",
|
|
35
|
+
"test": "bun test src/api.test.ts && bun test src/claude-config.test.ts && bun test src/mcp-http.test.ts && bun test src/retry.test.ts && bun test src/validate.test.ts && bun test src/policy.test.ts && bun test src/identity.test.ts && bun test src/pending.test.ts && bun test src/events.test.ts && bun test src/hook.test.ts"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@inquirer/prompts": "^8.4.2",
|
|
39
39
|
"smol-toml": "^1.6.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
+
"@pushary/contracts": "workspace:*",
|
|
42
43
|
"tsup": "^8.0.0",
|
|
43
44
|
"typescript": "^5.0.0"
|
|
44
45
|
}
|