@pushary/agent-hooks 0.21.1 → 0.23.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.
Files changed (91) hide show
  1. package/data/cursor-plugin/README.md +5 -1
  2. package/data/cursor-plugin/mcp.json +1 -1
  3. package/data/cursor-plugin/scripts/pushary-gate.mjs +28 -2
  4. package/dist/bin/pushary-clean.js +1 -1
  5. package/dist/bin/pushary-codex-hook.js +29 -19
  6. package/dist/bin/pushary-codex.js +3 -5
  7. package/dist/bin/pushary-doctor.js +2 -2
  8. package/dist/bin/pushary-gemini-hook.js +25 -14
  9. package/dist/bin/pushary-hook.js +4 -4
  10. package/dist/bin/pushary-post-hook.js +2 -3
  11. package/dist/bin/pushary-prompt-hook.js +2 -3
  12. package/dist/bin/pushary-setup.js +24 -2
  13. package/dist/bin/pushary-stop-hook.js +2 -3
  14. package/dist/{chunk-FXYTRZHC.js → chunk-FGZZRCOG.js} +27 -10
  15. package/dist/{chunk-BHAMEPOP.js → chunk-JPRRYC5X.js} +5 -0
  16. package/dist/{chunk-N7VXDBQU.js → chunk-KQYIHZ5E.js} +3 -1
  17. package/dist/chunk-M4GDBGXF.js +824 -0
  18. package/dist/{chunk-USUCPCUC.js → chunk-WPVL6VIT.js} +5 -1
  19. package/dist/src/index.d.ts +4 -0
  20. package/dist/src/index.js +8 -10
  21. package/package.json +1 -1
  22. package/dist/chunk-22CV7V7A.js +0 -38
  23. package/dist/chunk-2BE2IPMO.js +0 -315
  24. package/dist/chunk-2CRLBMOX.js +0 -244
  25. package/dist/chunk-2HMNOZPY.js +0 -109
  26. package/dist/chunk-2I6DLXJN.js +0 -219
  27. package/dist/chunk-2Q6XPZ4Q.js +0 -395
  28. package/dist/chunk-3MIR7ODJ.js +0 -112
  29. package/dist/chunk-3QZESA66.js +0 -222
  30. package/dist/chunk-4Z4MB37G.js +0 -96
  31. package/dist/chunk-5GFUI5N6.js +0 -132
  32. package/dist/chunk-5JEDLXEC.js +0 -99
  33. package/dist/chunk-5QHQVXWN.js +0 -174
  34. package/dist/chunk-6A3WCJO2.js +0 -416
  35. package/dist/chunk-6QWFMVCD.js +0 -328
  36. package/dist/chunk-6SRXMZAN.js +0 -99
  37. package/dist/chunk-7PTU7TGE.js +0 -96
  38. package/dist/chunk-AB4KX4XT.js +0 -109
  39. package/dist/chunk-AC4UYAGX.js +0 -136
  40. package/dist/chunk-ACE77TKQ.js +0 -328
  41. package/dist/chunk-BYNYYZWW.js +0 -412
  42. package/dist/chunk-C5TFTNHG.js +0 -244
  43. package/dist/chunk-CH53PBQN.js +0 -265
  44. package/dist/chunk-DF3BM6BF.js +0 -195
  45. package/dist/chunk-DKZVKEOW.js +0 -175
  46. package/dist/chunk-EMPL27ZV.js +0 -96
  47. package/dist/chunk-EQJXMEIR.js +0 -175
  48. package/dist/chunk-GTJGZBTQ.js +0 -328
  49. package/dist/chunk-HJMFYDWY.js +0 -222
  50. package/dist/chunk-HRQEECB6.js +0 -315
  51. package/dist/chunk-HWEMAAOY.js +0 -370
  52. package/dist/chunk-IBWCHA5M.js +0 -10
  53. package/dist/chunk-KTM4ZQ3W.js +0 -96
  54. package/dist/chunk-KTP2EPVB.js +0 -27
  55. package/dist/chunk-KYARP7KP.js +0 -97
  56. package/dist/chunk-M2N5DYWN.js +0 -247
  57. package/dist/chunk-M5F2L4KF.js +0 -177
  58. package/dist/chunk-M6S3M6E3.js +0 -244
  59. package/dist/chunk-O6A5RHWY.js +0 -122
  60. package/dist/chunk-ODUXELPM.js +0 -219
  61. package/dist/chunk-OF5WIOYS.js +0 -129
  62. package/dist/chunk-OP4QAN23.js +0 -99
  63. package/dist/chunk-P4JH2Q7Z.js +0 -102
  64. package/dist/chunk-PMD5JSV3.js +0 -242
  65. package/dist/chunk-PSSHNBEL.js +0 -177
  66. package/dist/chunk-QEPRH7JB.js +0 -315
  67. package/dist/chunk-QRXWPZKN.js +0 -308
  68. package/dist/chunk-QY4L6XHN.js +0 -384
  69. package/dist/chunk-RNWPCELY.js +0 -176
  70. package/dist/chunk-RSHN2AQ7.js +0 -29
  71. package/dist/chunk-RZLVE57X.js +0 -38
  72. package/dist/chunk-SDCIKREA.js +0 -241
  73. package/dist/chunk-SDREQWNI.js +0 -175
  74. package/dist/chunk-SH26ZOHU.js +0 -159
  75. package/dist/chunk-TRLBBLSS.js +0 -176
  76. package/dist/chunk-U6OXZPYC.js +0 -384
  77. package/dist/chunk-UIBTFZUD.js +0 -314
  78. package/dist/chunk-V4GLWPD7.js +0 -174
  79. package/dist/chunk-VC6U3QGF.js +0 -142
  80. package/dist/chunk-VIST7ACL.js +0 -88
  81. package/dist/chunk-VUNL35KE.js +0 -16
  82. package/dist/chunk-VWBNI4SC.js +0 -174
  83. package/dist/chunk-W5KRWUNE.js +0 -262
  84. package/dist/chunk-WCGKLHCL.js +0 -154
  85. package/dist/chunk-WNXGIEX7.js +0 -219
  86. package/dist/chunk-XPVSZIA3.js +0 -315
  87. package/dist/chunk-Y633ZIJF.js +0 -384
  88. package/dist/chunk-YCL4GUFR.js +0 -222
  89. package/dist/chunk-YTMKB44I.js +0 -220
  90. package/dist/chunk-ZWBS3T7Q.js +0 -244
  91. package/dist/pushary-mode-T7XOPI6Z.js +0 -83
@@ -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
- };
@@ -1,315 +0,0 @@
1
- import {
2
- extractPolicyArg,
3
- isApprovalMode,
4
- matchRankWeight,
5
- matchToolPattern
6
- } from "./chunk-22CV7V7A.js";
7
- import {
8
- callMcpTool,
9
- withRetry
10
- } from "./chunk-3MIR7ODJ.js";
11
- import {
12
- getBaseUrl
13
- } from "./chunk-VUNL35KE.js";
14
-
15
- // src/validate.ts
16
- var isPolicyConfig = (data) => {
17
- if (!data || typeof data !== "object") return false;
18
- const d = data;
19
- return Array.isArray(d.policies) && typeof d.defaultTimeoutSeconds === "number" && typeof d.defaultTimeoutAction === "string";
20
- };
21
- var isAskUserResponse = (data) => {
22
- if (!data || typeof data !== "object") return false;
23
- const d = data;
24
- return typeof d.correlationId === "string" && typeof d.status === "string";
25
- };
26
- var isWaitForAnswerResponse = (data) => {
27
- if (!data || typeof data !== "object") return false;
28
- const d = data;
29
- return typeof d.answered === "boolean";
30
- };
31
-
32
- // src/api.ts
33
- var askUser = async (apiKey, params) => {
34
- const result = await callMcpTool(apiKey, "ask_user", { ...params, wait: false }, { maxRetries: 3 });
35
- if (!isAskUserResponse(result)) throw new Error("Invalid ask_user response");
36
- return result;
37
- };
38
- var waitForAnswer = async (apiKey, correlationId, timeoutMs = 3e4) => {
39
- const result = await callMcpTool(apiKey, "wait_for_answer", {
40
- correlationId,
41
- timeoutMs
42
- });
43
- if (!isWaitForAnswerResponse(result)) throw new Error("Invalid wait_for_answer response");
44
- return result;
45
- };
46
- var cancelQuestion = async (apiKey, correlationId) => {
47
- await callMcpTool(apiKey, "cancel_question", { correlationId });
48
- };
49
- var sendNotification = async (apiKey, params) => {
50
- await callMcpTool(apiKey, "send_notification", { ...params }, { maxRetries: 3 });
51
- };
52
-
53
- // src/policy.ts
54
- import { createHash } from "crypto";
55
- import { existsSync, readFileSync, writeFileSync } from "fs";
56
- import { join } from "path";
57
- import { tmpdir } from "os";
58
- var CACHE_TTL_MS = 5 * 60 * 1e3;
59
- var cacheFile = (apiKey) => {
60
- const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
61
- return join(tmpdir(), `pushary-policy-${hash}.json`);
62
- };
63
- var fetchPolicy = async (apiKey) => {
64
- return withRetry(async () => {
65
- const baseUrl = getBaseUrl();
66
- const response = await fetch(`${baseUrl}/api/mcp/policy`, {
67
- headers: { "Authorization": `Bearer ${apiKey}` },
68
- signal: AbortSignal.timeout(1e4)
69
- });
70
- if (!response.ok) {
71
- throw new Error(`Failed to fetch policy: ${response.status}`);
72
- }
73
- const raw = await response.json();
74
- if (!isPolicyConfig(raw)) throw new Error("Invalid policy response");
75
- return raw;
76
- }, { maxAttempts: 2 });
77
- };
78
- var getPolicy = async (apiKey, expectedVersion) => {
79
- const path = cacheFile(apiKey);
80
- let staleCache = null;
81
- if (existsSync(path)) {
82
- try {
83
- const stat = readFileSync(path, "utf-8");
84
- const cached = JSON.parse(stat);
85
- if (!isPolicyConfig(cached)) throw new Error("Corrupted cache");
86
- const versionStale = expectedVersion != null && (cached._policyVersion ?? null) !== expectedVersion;
87
- const ttlFresh = !cached._cachedAt || Date.now() - cached._cachedAt < CACHE_TTL_MS;
88
- if (ttlFresh && !versionStale) {
89
- return cached;
90
- }
91
- staleCache = cached;
92
- } catch {
93
- }
94
- }
95
- try {
96
- const policy = await fetchPolicy(apiKey);
97
- try {
98
- writeFileSync(path, JSON.stringify({ ...policy, _cachedAt: Date.now(), _policyVersion: expectedVersion ?? null }), "utf-8");
99
- } catch {
100
- }
101
- return policy;
102
- } catch {
103
- if (staleCache) return staleCache;
104
- throw new Error("Failed to fetch policy and no cached policy available");
105
- }
106
- };
107
- var findBestMatch = (policies, toolName, arg) => {
108
- let best;
109
- let bestWeight = 0;
110
- let bestLength = -1;
111
- for (const candidate of policies) {
112
- const rank = matchToolPattern(candidate.tool, toolName, arg);
113
- if (rank === "none") continue;
114
- const weight = matchRankWeight(rank);
115
- const length = rank === "prefix" ? candidate.tool.length : -1;
116
- if (weight > bestWeight || weight === bestWeight && length > bestLength) {
117
- best = candidate;
118
- bestWeight = weight;
119
- bestLength = length;
120
- }
121
- }
122
- return best;
123
- };
124
- var resolvePolicy = (config, toolName, modeOverride, toolInput) => {
125
- const arg = toolInput ? extractPolicyArg(toolName, toolInput) : void 0;
126
- const base = findBestMatch(config.policies, toolName, arg) ?? config.policies.find((p) => p.tool === "*") ?? {
127
- tool: toolName,
128
- timeoutSeconds: config.defaultTimeoutSeconds,
129
- timeoutAction: config.defaultTimeoutAction,
130
- mode: config.defaultMode ?? "push_first",
131
- pushFirstSeconds: config.defaultPushFirstSeconds ?? 20
132
- };
133
- const effectiveOverride = modeOverride ?? config.modeOverride;
134
- if (effectiveOverride) {
135
- return { ...base, mode: effectiveOverride };
136
- }
137
- return base;
138
- };
139
- var toPolicyVersion = (value) => typeof value === "string" || typeof value === "number" ? String(value) : null;
140
- var fetchModeState = async (apiKey, sessionId) => {
141
- try {
142
- const baseUrl = getBaseUrl();
143
- const url = sessionId ? `${baseUrl}/api/mcp/mode?session=${encodeURIComponent(sessionId)}` : `${baseUrl}/api/mcp/mode`;
144
- const response = await fetch(url, {
145
- headers: { "Authorization": `Bearer ${apiKey}` },
146
- signal: AbortSignal.timeout(3e3)
147
- });
148
- if (!response.ok) return { mode: null, kill: false, policyVersion: null };
149
- const data = await response.json();
150
- const mode = data.override?.mode;
151
- return {
152
- mode: isApprovalMode(mode) ? mode : null,
153
- kill: data.kill === true,
154
- policyVersion: toPolicyVersion(data.policyVersion)
155
- };
156
- } catch {
157
- return { mode: null, kill: false, policyVersion: null };
158
- }
159
- };
160
- var fetchModeOverride = async (apiKey) => (await fetchModeState(apiKey)).mode;
161
-
162
- // src/describe.ts
163
- import { isAbsolute, relative } from "path";
164
- var hookPrefixes = {
165
- Bash: (input) => `bash: ${input.command ?? "(no command)"}`,
166
- Write: (input) => `write file: ${input.file_path ?? "(unknown path)"}`,
167
- Edit: (input) => `edit file: ${input.file_path ?? "(unknown path)"}`,
168
- Read: (input) => `read file: ${input.file_path ?? "(unknown path)"}`
169
- };
170
- var eventPrefixes = {
171
- Bash: (input) => `ran: ${String(input.command ?? "").slice(0, 120)}`,
172
- Write: (input) => `wrote: ${input.file_path ?? "unknown"}`,
173
- Edit: (input) => `edited: ${input.file_path ?? "unknown"}`,
174
- Read: (input) => `read: ${input.file_path ?? "unknown"}`
175
- };
176
- var describeToolCall = (toolName, toolInput, format = "hook") => {
177
- const prefixes = format === "hook" ? hookPrefixes : eventPrefixes;
178
- const builder = prefixes[toolName];
179
- if (builder) return builder(toolInput);
180
- return format === "hook" ? `${toolName}: ${JSON.stringify(toolInput).slice(0, 200)}` : `${toolName}: done`;
181
- };
182
- var TOOL_TARGET_MAX_LENGTH = 80;
183
- var deriveCommandHead = (command) => {
184
- if (typeof command !== "string") return void 0;
185
- const head = command.trim().split(/\s+/).slice(0, 2).join(" ");
186
- return head ? head.slice(0, TOOL_TARGET_MAX_LENGTH) : void 0;
187
- };
188
- var deriveToolTarget = (toolName, toolInput) => {
189
- if (toolName === "Bash") {
190
- return deriveCommandHead(toolInput.command);
191
- }
192
- if (toolName === "Edit" || toolName === "Write") {
193
- const filePath = toolInput.file_path;
194
- if (typeof filePath !== "string") return void 0;
195
- const separator = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));
196
- const base = filePath.slice(separator + 1);
197
- const dot = base.lastIndexOf(".");
198
- if (dot <= 0) return void 0;
199
- return base.slice(dot).slice(0, TOOL_TARGET_MAX_LENGTH);
200
- }
201
- return void 0;
202
- };
203
- var RECEIPT_TARGET_MAX_LENGTH = 256;
204
- var isToolResultError = (toolResult) => {
205
- try {
206
- return Boolean(toolResult && ("error" in toolResult || "is_error" in toolResult));
207
- } catch {
208
- return false;
209
- }
210
- };
211
- var relativizeReceiptPath = (filePath, cwd) => {
212
- if (!cwd || !isAbsolute(filePath)) return filePath;
213
- return relative(cwd, filePath);
214
- };
215
- var deriveReceiptMeta = (toolName, toolInput, toolResult, cwd) => {
216
- try {
217
- const ok = !isToolResultError(toolResult);
218
- if (toolName === "Edit" || toolName === "Write") {
219
- const filePath = toolInput.file_path;
220
- if (typeof filePath !== "string" || !filePath) return void 0;
221
- return {
222
- kind: toolName === "Edit" ? "edit" : "write",
223
- target: relativizeReceiptPath(filePath, cwd).slice(0, RECEIPT_TARGET_MAX_LENGTH),
224
- ok
225
- };
226
- }
227
- if (toolName === "Bash") {
228
- const head = deriveCommandHead(toolInput.command);
229
- if (!head) return void 0;
230
- return {
231
- kind: head === "git commit" ? "commit" : "bash",
232
- target: head,
233
- ok
234
- };
235
- }
236
- return void 0;
237
- } catch {
238
- return void 0;
239
- }
240
- };
241
-
242
- // src/identity.ts
243
- import { createHash as createHash2 } from "crypto";
244
- import { hostname } from "os";
245
- var deriveMachineId = (host) => createHash2("sha256").update(host).digest("hex").slice(0, 8);
246
- var getMachineId = () => deriveMachineId(hostname());
247
-
248
- // src/pending.ts
249
- import { join as join2 } from "path";
250
- import { tmpdir as tmpdir2 } from "os";
251
- import { existsSync as existsSync2, mkdirSync, writeFileSync as writeFileSync2, readdirSync, unlinkSync, rmSync, statSync } from "fs";
252
- var PENDING_DIR = join2(tmpdir2(), "pushary-pending");
253
- var DEFAULT_SESSION = "_no_session";
254
- var GRACE_MS = 10 * 60 * 1e3;
255
- var sanitize = (sessionId) => sessionId.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 128) || DEFAULT_SESSION;
256
- var dirFor = (sessionId) => join2(PENDING_DIR, sanitize(sessionId));
257
- var isDefaultSession = (sessionId) => sanitize(sessionId) === DEFAULT_SESSION;
258
- var savePendingQuestion = (sessionId, correlationId) => {
259
- const dir = dirFor(sessionId);
260
- if (!existsSync2(dir)) mkdirSync(dir, { recursive: true });
261
- writeFileSync2(join2(dir, correlationId), "", "utf-8");
262
- };
263
- var listPendingQuestions = (sessionId) => {
264
- const dir = dirFor(sessionId);
265
- let files;
266
- try {
267
- files = readdirSync(dir);
268
- } catch {
269
- return [];
270
- }
271
- if (!isDefaultSession(sessionId)) return files;
272
- const cutoff = Date.now() - GRACE_MS;
273
- return files.filter((name) => {
274
- try {
275
- return statSync(join2(dir, name)).mtimeMs < cutoff;
276
- } catch {
277
- return false;
278
- }
279
- });
280
- };
281
- var removePendingQuestion = (sessionId, correlationId) => {
282
- try {
283
- unlinkSync(join2(dirFor(sessionId), correlationId));
284
- } catch {
285
- }
286
- };
287
- var removePendingSession = (sessionId) => {
288
- try {
289
- rmSync(dirFor(sessionId), { recursive: true, force: true });
290
- } catch {
291
- }
292
- };
293
-
294
- export {
295
- isPolicyConfig,
296
- askUser,
297
- waitForAnswer,
298
- cancelQuestion,
299
- sendNotification,
300
- getPolicy,
301
- resolvePolicy,
302
- fetchModeState,
303
- fetchModeOverride,
304
- describeToolCall,
305
- deriveToolTarget,
306
- isToolResultError,
307
- deriveReceiptMeta,
308
- getMachineId,
309
- DEFAULT_SESSION,
310
- isDefaultSession,
311
- savePendingQuestion,
312
- listPendingQuestions,
313
- removePendingQuestion,
314
- removePendingSession
315
- };