@pushary/agent-hooks 0.25.0 → 0.26.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-doctor.js +21 -9
- package/dist/bin/pushary-gemini-hook.js +1 -1
- package/dist/bin/pushary-hook.js +2 -2
- package/dist/bin/pushary-post-hook.js +1 -1
- package/dist/bin/pushary-prompt-hook.js +1 -1
- package/dist/bin/pushary-setup.js +7 -19
- package/dist/bin/pushary-stop-hook.js +1 -1
- package/dist/{chunk-GYPPVD3P.js → chunk-A7DQCA2N.js} +1 -1
- package/dist/{chunk-O2QL6U6G.js → chunk-SA4BDS7T.js} +1 -1
- package/dist/{chunk-JPRRYC5X.js → chunk-SLX4AONG.js} +25 -0
- package/dist/src/index.js +2 -2
- 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-5QHQVXWN.js +0 -174
- package/dist/chunk-6A3WCJO2.js +0 -416
- package/dist/chunk-6QWFMVCD.js +0 -328
- package/dist/chunk-6SRXMZAN.js +0 -99
- 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-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-FGZZRCOG.js +0 -194
- package/dist/chunk-FXYTRZHC.js +0 -177
- package/dist/chunk-GTJGZBTQ.js +0 -328
- package/dist/chunk-HJMFYDWY.js +0 -222
- package/dist/chunk-HRQEECB6.js +0 -315
- package/dist/chunk-HWEMAAOY.js +0 -370
- package/dist/chunk-IBWCHA5M.js +0 -10
- package/dist/chunk-KTM4ZQ3W.js +0 -96
- package/dist/chunk-KTP2EPVB.js +0 -27
- package/dist/chunk-KYARP7KP.js +0 -97
- 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-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-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-TRLBBLSS.js +0 -176
- package/dist/chunk-U6OXZPYC.js +0 -384
- package/dist/chunk-UIBTFZUD.js +0 -314
- package/dist/chunk-USUCPCUC.js +0 -156
- 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-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/chunk-WCGKLHCL.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_SESSION,
|
|
3
|
-
cancelQuestion,
|
|
4
|
-
describeToolCall,
|
|
5
|
-
getMachineId,
|
|
6
|
-
isDefaultSession,
|
|
7
|
-
isPolicyConfig,
|
|
8
|
-
listPendingQuestions,
|
|
9
|
-
removePendingQuestion,
|
|
10
|
-
removePendingSession,
|
|
11
|
-
resolvePolicy
|
|
12
|
-
} from "./chunk-CH53PBQN.js";
|
|
13
|
-
import {
|
|
14
|
-
withRetry
|
|
15
|
-
} from "./chunk-3MIR7ODJ.js";
|
|
16
|
-
import {
|
|
17
|
-
getApiKey,
|
|
18
|
-
getBaseUrl
|
|
19
|
-
} from "./chunk-VUNL35KE.js";
|
|
20
|
-
|
|
21
|
-
// src/events.ts
|
|
22
|
-
import { basename, join } from "path";
|
|
23
|
-
import { createHash } from "crypto";
|
|
24
|
-
import { existsSync, readFileSync } from "fs";
|
|
25
|
-
import { tmpdir } from "os";
|
|
26
|
-
var cleanupPendingQuestions = async (sessionId) => {
|
|
27
|
-
try {
|
|
28
|
-
const files = listPendingQuestions(sessionId);
|
|
29
|
-
const apiKey = getApiKey();
|
|
30
|
-
for (const correlationId of files) {
|
|
31
|
-
try {
|
|
32
|
-
await cancelQuestion(apiKey, correlationId);
|
|
33
|
-
} catch {
|
|
34
|
-
}
|
|
35
|
-
removePendingQuestion(sessionId, correlationId);
|
|
36
|
-
}
|
|
37
|
-
if (!isDefaultSession(sessionId)) removePendingSession(sessionId);
|
|
38
|
-
} catch {
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var POLICY_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
42
|
-
var readFreshCachedPolicy = (apiKey) => {
|
|
43
|
-
const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
|
|
44
|
-
const path = join(tmpdir(), `pushary-policy-${hash}.json`);
|
|
45
|
-
if (!existsSync(path)) return null;
|
|
46
|
-
const cached = JSON.parse(readFileSync(path, "utf-8"));
|
|
47
|
-
if (!isPolicyConfig(cached)) return null;
|
|
48
|
-
if (!cached._cachedAt || Date.now() - cached._cachedAt >= POLICY_CACHE_TTL_MS) return null;
|
|
49
|
-
return cached;
|
|
50
|
-
};
|
|
51
|
-
var deriveDecisionSource = (toolName, toolInput) => {
|
|
52
|
-
try {
|
|
53
|
-
const policy = readFreshCachedPolicy(getApiKey());
|
|
54
|
-
if (!policy) return void 0;
|
|
55
|
-
const resolved = resolvePolicy(policy, toolName, null, toolInput);
|
|
56
|
-
if (resolved.timeoutSeconds === 0 && resolved.timeoutAction === "approve") return "policy_auto";
|
|
57
|
-
if (resolved.mode === "push_only" || resolved.mode === "push_first") return "human";
|
|
58
|
-
return "terminal";
|
|
59
|
-
} catch {
|
|
60
|
-
return void 0;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
var reportEvent = async (event, options = {}) => {
|
|
64
|
-
const apiKey = getApiKey();
|
|
65
|
-
const baseUrl = getBaseUrl();
|
|
66
|
-
await withRetry(async () => {
|
|
67
|
-
await fetch(`${baseUrl}/api/agent/event`, {
|
|
68
|
-
method: "POST",
|
|
69
|
-
headers: {
|
|
70
|
-
"Content-Type": "application/json",
|
|
71
|
-
"Authorization": `Bearer ${apiKey}`
|
|
72
|
-
},
|
|
73
|
-
body: JSON.stringify({
|
|
74
|
-
...event,
|
|
75
|
-
machineId: event.machineId ?? getMachineId()
|
|
76
|
-
}),
|
|
77
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? 1e4)
|
|
78
|
-
});
|
|
79
|
-
}, { maxAttempts: options.maxAttempts ?? 2, baseDelayMs: 300 });
|
|
80
|
-
};
|
|
81
|
-
var handlePostToolUse = async (input) => {
|
|
82
|
-
try {
|
|
83
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
84
|
-
const action = describeToolCall(input.tool_name, input.tool_input, "event");
|
|
85
|
-
const isError = input.tool_result && ("error" in input.tool_result || "is_error" in input.tool_result);
|
|
86
|
-
await Promise.allSettled([
|
|
87
|
-
cleanupPendingQuestions(input.session_id || DEFAULT_SESSION),
|
|
88
|
-
reportEvent({
|
|
89
|
-
event: isError ? "tool_error" : "tool_complete",
|
|
90
|
-
agentType: "claude_code",
|
|
91
|
-
agentName: `Claude Code - ${projectName}`,
|
|
92
|
-
action,
|
|
93
|
-
sessionId: input.session_id,
|
|
94
|
-
error: isError ? String(input.tool_result?.error ?? input.tool_result?.stderr ?? "").slice(0, 500) : void 0,
|
|
95
|
-
decisionSource: deriveDecisionSource(input.tool_name, input.tool_input)
|
|
96
|
-
})
|
|
97
|
-
]);
|
|
98
|
-
} catch {
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
var TASK_TITLE_MAX_LENGTH = 120;
|
|
102
|
-
var handleUserPrompt = async (input) => {
|
|
103
|
-
try {
|
|
104
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
105
|
-
const titlesEnabled = process.env.PUSHARY_TASK_TITLES !== "off";
|
|
106
|
-
const taskTitle = titlesEnabled ? input.prompt?.replace(/\s+/g, " ").trim().slice(0, TASK_TITLE_MAX_LENGTH) || void 0 : void 0;
|
|
107
|
-
await reportEvent({
|
|
108
|
-
event: "user_prompt",
|
|
109
|
-
agentType: "claude_code",
|
|
110
|
-
agentName: `Claude Code - ${projectName}`,
|
|
111
|
-
sessionId: input.session_id,
|
|
112
|
-
taskTitle
|
|
113
|
-
}, { maxAttempts: 1, timeoutMs: 800 });
|
|
114
|
-
} catch {
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
var handleStop = async (input) => {
|
|
118
|
-
try {
|
|
119
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
120
|
-
await Promise.allSettled([
|
|
121
|
-
cleanupPendingQuestions(input.session_id || DEFAULT_SESSION),
|
|
122
|
-
reportEvent({
|
|
123
|
-
event: "session_end",
|
|
124
|
-
agentType: "claude_code",
|
|
125
|
-
agentName: `Claude Code - ${projectName}`,
|
|
126
|
-
action: "Session ended",
|
|
127
|
-
sessionId: input.session_id
|
|
128
|
-
})
|
|
129
|
-
]);
|
|
130
|
-
} catch {
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
var handleNotification = async (input) => {
|
|
134
|
-
try {
|
|
135
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
136
|
-
await reportEvent({
|
|
137
|
-
event: input.type === "error" ? "error" : "notification",
|
|
138
|
-
agentType: "claude_code",
|
|
139
|
-
agentName: `Claude Code - ${projectName}`,
|
|
140
|
-
action: input.title ?? input.message ?? "Notification",
|
|
141
|
-
sessionId: input.session_id,
|
|
142
|
-
error: input.type === "error" ? input.message : void 0
|
|
143
|
-
});
|
|
144
|
-
} catch {
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export {
|
|
149
|
-
reportEvent,
|
|
150
|
-
handlePostToolUse,
|
|
151
|
-
handleUserPrompt,
|
|
152
|
-
handleStop,
|
|
153
|
-
handleNotification
|
|
154
|
-
};
|
package/dist/chunk-WNXGIEX7.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
askUser,
|
|
3
|
-
describeToolCall,
|
|
4
|
-
isPolicyConfig,
|
|
5
|
-
savePendingQuestion,
|
|
6
|
-
sendNotification,
|
|
7
|
-
waitForAnswer
|
|
8
|
-
} from "./chunk-4Z4MB37G.js";
|
|
9
|
-
import {
|
|
10
|
-
getApiKey,
|
|
11
|
-
getBaseUrl,
|
|
12
|
-
withRetry
|
|
13
|
-
} from "./chunk-O6A5RHWY.js";
|
|
14
|
-
|
|
15
|
-
// src/policy.ts
|
|
16
|
-
import { createHash } from "crypto";
|
|
17
|
-
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
18
|
-
import { join } from "path";
|
|
19
|
-
import { tmpdir } from "os";
|
|
20
|
-
var CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
21
|
-
var cacheFile = (apiKey) => {
|
|
22
|
-
const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
|
|
23
|
-
return join(tmpdir(), `pushary-policy-${hash}.json`);
|
|
24
|
-
};
|
|
25
|
-
var fetchPolicy = async (apiKey) => {
|
|
26
|
-
return withRetry(async () => {
|
|
27
|
-
const baseUrl = getBaseUrl();
|
|
28
|
-
const response = await fetch(`${baseUrl}/api/mcp/policy`, {
|
|
29
|
-
headers: { "Authorization": `Bearer ${apiKey}` },
|
|
30
|
-
signal: AbortSignal.timeout(1e4)
|
|
31
|
-
});
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
throw new Error(`Failed to fetch policy: ${response.status}`);
|
|
34
|
-
}
|
|
35
|
-
const raw = await response.json();
|
|
36
|
-
if (!isPolicyConfig(raw)) throw new Error("Invalid policy response");
|
|
37
|
-
return raw;
|
|
38
|
-
}, { maxAttempts: 2 });
|
|
39
|
-
};
|
|
40
|
-
var getPolicy = async (apiKey) => {
|
|
41
|
-
const path = cacheFile(apiKey);
|
|
42
|
-
let staleCache = null;
|
|
43
|
-
if (existsSync(path)) {
|
|
44
|
-
try {
|
|
45
|
-
const stat = readFileSync(path, "utf-8");
|
|
46
|
-
const cached = JSON.parse(stat);
|
|
47
|
-
if (!isPolicyConfig(cached)) throw new Error("Corrupted cache");
|
|
48
|
-
if (!cached._cachedAt || Date.now() - cached._cachedAt < CACHE_TTL_MS) {
|
|
49
|
-
return cached;
|
|
50
|
-
}
|
|
51
|
-
staleCache = cached;
|
|
52
|
-
} catch {
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
const policy = await fetchPolicy(apiKey);
|
|
57
|
-
try {
|
|
58
|
-
writeFileSync(path, JSON.stringify({ ...policy, _cachedAt: Date.now() }), "utf-8");
|
|
59
|
-
} catch {
|
|
60
|
-
}
|
|
61
|
-
return policy;
|
|
62
|
-
} catch {
|
|
63
|
-
if (staleCache) return staleCache;
|
|
64
|
-
throw new Error("Failed to fetch policy and no cached policy available");
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var resolvePolicy = (config, toolName) => {
|
|
68
|
-
const exact = config.policies.find((p) => p.tool === toolName);
|
|
69
|
-
if (exact) return exact;
|
|
70
|
-
const wildcard = config.policies.find((p) => p.tool === "*");
|
|
71
|
-
if (wildcard) return wildcard;
|
|
72
|
-
return {
|
|
73
|
-
tool: toolName,
|
|
74
|
-
timeoutSeconds: config.defaultTimeoutSeconds,
|
|
75
|
-
timeoutAction: config.defaultTimeoutAction,
|
|
76
|
-
mode: config.defaultMode ?? "push_first",
|
|
77
|
-
pushFirstSeconds: config.defaultPushFirstSeconds ?? 10
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// src/hook.ts
|
|
82
|
-
import { basename } from "path";
|
|
83
|
-
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
84
|
-
var allow = () => ({
|
|
85
|
-
hookSpecificOutput: {
|
|
86
|
-
hookEventName: "PreToolUse",
|
|
87
|
-
permissionDecision: "allow"
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
var deny = (reason) => ({
|
|
91
|
-
hookSpecificOutput: {
|
|
92
|
-
hookEventName: "PreToolUse",
|
|
93
|
-
permissionDecision: "deny",
|
|
94
|
-
permissionDecisionReason: reason
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
var ask = (reason) => ({
|
|
98
|
-
hookSpecificOutput: {
|
|
99
|
-
hookEventName: "PreToolUse",
|
|
100
|
-
permissionDecision: "ask",
|
|
101
|
-
...reason ? { permissionDecisionReason: reason } : {}
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
var pollForAnswer = async (apiKey, correlationId, deadlineMs, pollInterval = 2e3) => {
|
|
105
|
-
while (Date.now() < deadlineMs) {
|
|
106
|
-
const remaining = Math.min(Math.max(deadlineMs - Date.now(), 1e3), 3e4);
|
|
107
|
-
let answer;
|
|
108
|
-
try {
|
|
109
|
-
answer = await waitForAnswer(apiKey, correlationId, remaining);
|
|
110
|
-
} catch {
|
|
111
|
-
if (Date.now() + pollInterval >= deadlineMs) break;
|
|
112
|
-
await sleep(pollInterval);
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (answer.answered) return answer;
|
|
116
|
-
if (Date.now() + pollInterval >= deadlineMs) break;
|
|
117
|
-
await sleep(pollInterval);
|
|
118
|
-
}
|
|
119
|
-
return { answered: false };
|
|
120
|
-
};
|
|
121
|
-
var handlePushOnly = async (apiKey, description, projectName, timeoutSeconds, timeoutAction) => {
|
|
122
|
-
let result;
|
|
123
|
-
try {
|
|
124
|
-
result = await askUser(apiKey, {
|
|
125
|
-
question: `Allow ${description}?`,
|
|
126
|
-
type: "confirm",
|
|
127
|
-
context: `Agent wants to run this in ${projectName}`,
|
|
128
|
-
agentName: `Claude Code - ${projectName}`
|
|
129
|
-
});
|
|
130
|
-
} catch {
|
|
131
|
-
switch (timeoutAction) {
|
|
132
|
-
case "approve":
|
|
133
|
-
return allow();
|
|
134
|
-
case "deny":
|
|
135
|
-
return deny("Push notification failed, denying per policy");
|
|
136
|
-
default:
|
|
137
|
-
return ask("Push notification failed, asking in terminal");
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
const deadline = Date.now() + timeoutSeconds * 1e3;
|
|
141
|
-
const answer = await pollForAnswer(apiKey, result.correlationId, deadline);
|
|
142
|
-
if (answer.answered) {
|
|
143
|
-
return answer.value === "yes" ? allow() : deny("Denied via push notification");
|
|
144
|
-
}
|
|
145
|
-
switch (timeoutAction) {
|
|
146
|
-
case "approve":
|
|
147
|
-
return allow();
|
|
148
|
-
case "deny":
|
|
149
|
-
return deny("No response within timeout");
|
|
150
|
-
default:
|
|
151
|
-
return ask("No push response, asking in terminal");
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
var handleTerminalOnly = () => {
|
|
155
|
-
return ask();
|
|
156
|
-
};
|
|
157
|
-
var handlePushFirst = async (apiKey, description, projectName, pushFirstSeconds) => {
|
|
158
|
-
let result;
|
|
159
|
-
try {
|
|
160
|
-
result = await askUser(apiKey, {
|
|
161
|
-
question: `Allow ${description}?`,
|
|
162
|
-
type: "confirm",
|
|
163
|
-
context: `Agent wants to run this in ${projectName}`,
|
|
164
|
-
agentName: `Claude Code - ${projectName}`
|
|
165
|
-
});
|
|
166
|
-
} catch {
|
|
167
|
-
return ask("Push notification failed, asking in terminal");
|
|
168
|
-
}
|
|
169
|
-
const deadline = Date.now() + pushFirstSeconds * 1e3;
|
|
170
|
-
const answer = await pollForAnswer(apiKey, result.correlationId, deadline, 1500);
|
|
171
|
-
if (answer.answered) {
|
|
172
|
-
return answer.value === "yes" ? allow() : deny("Denied via push notification");
|
|
173
|
-
}
|
|
174
|
-
savePendingQuestion(result.correlationId);
|
|
175
|
-
return ask("Sent as push notification. You can also approve here.");
|
|
176
|
-
};
|
|
177
|
-
var handleNotifyOnly = async (apiKey, description, projectName) => {
|
|
178
|
-
try {
|
|
179
|
-
await sendNotification(apiKey, {
|
|
180
|
-
title: "Agent needs approval",
|
|
181
|
-
body: description,
|
|
182
|
-
agentName: `Claude Code - ${projectName}`
|
|
183
|
-
});
|
|
184
|
-
} catch {
|
|
185
|
-
}
|
|
186
|
-
return ask();
|
|
187
|
-
};
|
|
188
|
-
var handlePreToolUse = async (input) => {
|
|
189
|
-
try {
|
|
190
|
-
const apiKey = getApiKey();
|
|
191
|
-
const policy = await getPolicy(apiKey);
|
|
192
|
-
const toolPolicy = resolvePolicy(policy, input.tool_name);
|
|
193
|
-
if (toolPolicy.timeoutSeconds === 0 && toolPolicy.timeoutAction === "approve") {
|
|
194
|
-
return allow();
|
|
195
|
-
}
|
|
196
|
-
const description = describeToolCall(input.tool_name, input.tool_input, "hook");
|
|
197
|
-
const projectName = basename(input.cwd ?? process.cwd());
|
|
198
|
-
switch (toolPolicy.mode) {
|
|
199
|
-
case "push_only":
|
|
200
|
-
return handlePushOnly(apiKey, description, projectName, toolPolicy.timeoutSeconds, toolPolicy.timeoutAction);
|
|
201
|
-
case "terminal_only":
|
|
202
|
-
return handleTerminalOnly();
|
|
203
|
-
case "push_first":
|
|
204
|
-
return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds);
|
|
205
|
-
case "notify_only":
|
|
206
|
-
return handleNotifyOnly(apiKey, description, projectName);
|
|
207
|
-
default:
|
|
208
|
-
return handlePushFirst(apiKey, description, projectName, toolPolicy.pushFirstSeconds);
|
|
209
|
-
}
|
|
210
|
-
} catch {
|
|
211
|
-
return ask("Pushary unavailable, falling back to terminal approval");
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
export {
|
|
216
|
-
getPolicy,
|
|
217
|
-
resolvePolicy,
|
|
218
|
-
handlePreToolUse
|
|
219
|
-
};
|
package/dist/chunk-WPVL6VIT.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
// ../contracts/src/index.ts
|
|
2
|
-
var APPROVAL_MODES = ["push_only", "terminal_only", "push_first", "notify_only"];
|
|
3
|
-
var isApprovalMode = (value) => typeof value === "string" && APPROVAL_MODES.includes(value);
|
|
4
|
-
var MATCH_RANKS = ["none", "tool", "prefix", "exact"];
|
|
5
|
-
var matchRankWeight = (rank) => MATCH_RANKS.indexOf(rank);
|
|
6
|
-
var matchToolPattern = (pattern, toolName, arg) => {
|
|
7
|
-
const open = pattern.indexOf("(");
|
|
8
|
-
if (open === -1 || !pattern.endsWith(")")) {
|
|
9
|
-
return pattern === toolName ? "tool" : "none";
|
|
10
|
-
}
|
|
11
|
-
if (pattern.slice(0, open) !== toolName || arg === void 0) return "none";
|
|
12
|
-
const inner = pattern.slice(open + 1, -1);
|
|
13
|
-
if (inner.endsWith(":*")) {
|
|
14
|
-
return arg.startsWith(inner.slice(0, -2)) ? "prefix" : "none";
|
|
15
|
-
}
|
|
16
|
-
return arg === inner ? "exact" : "none";
|
|
17
|
-
};
|
|
18
|
-
var POLICY_ARG_KEYS = {
|
|
19
|
-
Bash: "command",
|
|
20
|
-
Edit: "file_path",
|
|
21
|
-
Write: "file_path"
|
|
22
|
-
};
|
|
23
|
-
var extractPolicyArg = (toolName, toolInput) => {
|
|
24
|
-
const key = POLICY_ARG_KEYS[toolName];
|
|
25
|
-
if (!key) return void 0;
|
|
26
|
-
const value = toolInput[key];
|
|
27
|
-
return typeof value === "string" ? value : void 0;
|
|
28
|
-
};
|
|
29
|
-
var SAFE_SHELL_COMMANDS = /* @__PURE__ */ new Set([
|
|
30
|
-
"ls",
|
|
31
|
-
"pwd",
|
|
32
|
-
"cd",
|
|
33
|
-
"cat",
|
|
34
|
-
"head",
|
|
35
|
-
"tail",
|
|
36
|
-
"wc",
|
|
37
|
-
"echo",
|
|
38
|
-
"printf",
|
|
39
|
-
"which",
|
|
40
|
-
"type",
|
|
41
|
-
"whoami",
|
|
42
|
-
"id",
|
|
43
|
-
"uname",
|
|
44
|
-
"arch",
|
|
45
|
-
"printenv",
|
|
46
|
-
"locale",
|
|
47
|
-
"tty",
|
|
48
|
-
"dirname",
|
|
49
|
-
"basename",
|
|
50
|
-
"realpath",
|
|
51
|
-
"readlink",
|
|
52
|
-
"stat",
|
|
53
|
-
"cut",
|
|
54
|
-
"nl",
|
|
55
|
-
"tr",
|
|
56
|
-
"comm",
|
|
57
|
-
"diff",
|
|
58
|
-
"cmp",
|
|
59
|
-
"grep",
|
|
60
|
-
"egrep",
|
|
61
|
-
"fgrep",
|
|
62
|
-
"jq",
|
|
63
|
-
"cksum",
|
|
64
|
-
"md5sum",
|
|
65
|
-
"sha1sum",
|
|
66
|
-
"sha256sum",
|
|
67
|
-
"du",
|
|
68
|
-
"df",
|
|
69
|
-
"ps",
|
|
70
|
-
"true"
|
|
71
|
-
]);
|
|
72
|
-
var SAFE_GIT_SUBCOMMANDS = /* @__PURE__ */ new Set([
|
|
73
|
-
"status",
|
|
74
|
-
"log",
|
|
75
|
-
"diff",
|
|
76
|
-
"show",
|
|
77
|
-
"rev-parse",
|
|
78
|
-
"describe",
|
|
79
|
-
"blame",
|
|
80
|
-
"shortlog",
|
|
81
|
-
"ls-files",
|
|
82
|
-
"ls-tree",
|
|
83
|
-
"cat-file",
|
|
84
|
-
"whatchanged",
|
|
85
|
-
"rev-list",
|
|
86
|
-
"name-rev",
|
|
87
|
-
"for-each-ref",
|
|
88
|
-
"var",
|
|
89
|
-
"count-objects"
|
|
90
|
-
]);
|
|
91
|
-
var GIT_WRITE_FLAGS = (token) => token === "--output" || token.startsWith("--output=");
|
|
92
|
-
var UNSAFE_SHELL_CHARS = /[;&|<>(){}`\\\n\r]/;
|
|
93
|
-
var basenameOf = (token) => {
|
|
94
|
-
const slash = Math.max(token.lastIndexOf("/"), token.lastIndexOf("\\"));
|
|
95
|
-
return slash === -1 ? token : token.slice(slash + 1);
|
|
96
|
-
};
|
|
97
|
-
var tokenizeShellCommand = (command) => {
|
|
98
|
-
const tokens = [];
|
|
99
|
-
let current = "";
|
|
100
|
-
let quote = null;
|
|
101
|
-
let started = false;
|
|
102
|
-
for (const ch of command) {
|
|
103
|
-
if (quote) {
|
|
104
|
-
if (ch === quote) quote = null;
|
|
105
|
-
else current += ch;
|
|
106
|
-
started = true;
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
if (ch === '"' || ch === "'") {
|
|
110
|
-
quote = ch;
|
|
111
|
-
started = true;
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
if (ch === " " || ch === " ") {
|
|
115
|
-
if (started) {
|
|
116
|
-
tokens.push(current);
|
|
117
|
-
current = "";
|
|
118
|
-
started = false;
|
|
119
|
-
}
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
current += ch;
|
|
123
|
-
started = true;
|
|
124
|
-
}
|
|
125
|
-
if (quote) return null;
|
|
126
|
-
if (started) tokens.push(current);
|
|
127
|
-
return tokens;
|
|
128
|
-
};
|
|
129
|
-
var isSafeReadOnlyCommand = (command) => {
|
|
130
|
-
const trimmed = command.trim();
|
|
131
|
-
if (!trimmed || trimmed.length > 2e3) return false;
|
|
132
|
-
if (UNSAFE_SHELL_CHARS.test(trimmed)) return false;
|
|
133
|
-
const tokens = tokenizeShellCommand(trimmed);
|
|
134
|
-
if (!tokens || tokens.length === 0) return false;
|
|
135
|
-
const first = tokens[0];
|
|
136
|
-
if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(first) || first.includes("$")) return false;
|
|
137
|
-
const exe = basenameOf(first);
|
|
138
|
-
if (exe === "git") {
|
|
139
|
-
const sub = tokens[1];
|
|
140
|
-
if (!sub || sub.startsWith("-")) return false;
|
|
141
|
-
if (!SAFE_GIT_SUBCOMMANDS.has(sub)) return false;
|
|
142
|
-
return !tokens.some(GIT_WRITE_FLAGS);
|
|
143
|
-
}
|
|
144
|
-
return SAFE_SHELL_COMMANDS.has(exe);
|
|
145
|
-
};
|
|
146
|
-
var API_KEY_PATTERN = /^pk_[a-f0-9]+\.[a-f0-9]+$/;
|
|
147
|
-
var isValidApiKey = (value) => API_KEY_PATTERN.test(value);
|
|
148
|
-
var ACTION_BODY_MAX = 4e3;
|
|
149
|
-
var DECISION_LINE_MAX = 500;
|
|
150
|
-
|
|
151
|
-
export {
|
|
152
|
-
isApprovalMode,
|
|
153
|
-
matchRankWeight,
|
|
154
|
-
matchToolPattern,
|
|
155
|
-
extractPolicyArg,
|
|
156
|
-
isSafeReadOnlyCommand,
|
|
157
|
-
isValidApiKey,
|
|
158
|
-
ACTION_BODY_MAX,
|
|
159
|
-
DECISION_LINE_MAX
|
|
160
|
-
};
|