@pushary/agent-hooks 0.12.0 → 0.14.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.
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  handleStop
4
- } from "../chunk-AB4KX4XT.js";
5
- import "../chunk-OF5WIOYS.js";
4
+ } from "../chunk-SH26ZOHU.js";
5
+ import "../chunk-QRXWPZKN.js";
6
+ import "../chunk-22CV7V7A.js";
6
7
  import "../chunk-3MIR7ODJ.js";
7
8
  import "../chunk-VUNL35KE.js";
8
9
 
@@ -0,0 +1,38 @@
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 API_KEY_PATTERN = /^pk_[a-f0-9]+\.[a-f0-9]+$/;
30
+ var isValidApiKey = (value) => API_KEY_PATTERN.test(value);
31
+
32
+ export {
33
+ isApprovalMode,
34
+ matchRankWeight,
35
+ matchToolPattern,
36
+ extractPolicyArg,
37
+ isValidApiKey
38
+ };
@@ -0,0 +1,109 @@
1
+ // src/codex-config.ts
2
+ var CODEX_HOOK_BINARY = "pushary-codex-hook";
3
+ var CODEX_HOOK_EVENTS = [
4
+ { event: "PermissionRequest", matcher: "Bash|apply_patch", timeout: 180, statusMessage: "Waiting for your phone" },
5
+ { event: "PreToolUse", matcher: "Bash|apply_patch", timeout: 180, statusMessage: "Checking Pushary policy" },
6
+ { event: "PostToolUse", matcher: "Bash|apply_patch", timeout: 10 },
7
+ { event: "UserPromptSubmit", timeout: 10 },
8
+ { event: "Stop", timeout: 10 },
9
+ { event: "SessionStart", matcher: "startup|resume", timeout: 10 }
10
+ ];
11
+ var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
12
+ var ensureRecord = (target, key) => {
13
+ const existing = asRecord(target[key]);
14
+ if (existing) return existing;
15
+ const created = {};
16
+ target[key] = created;
17
+ return created;
18
+ };
19
+ var isPusharyCodexHook = (entry) => {
20
+ const hooks = asRecord(entry)?.hooks;
21
+ if (!Array.isArray(hooks)) return false;
22
+ return hooks.some((hook) => String(asRecord(hook)?.command ?? "").includes(CODEX_HOOK_BINARY));
23
+ };
24
+ var addCodexHooks = (config, command) => {
25
+ const hooks = ensureRecord(config, "hooks");
26
+ for (const definition of CODEX_HOOK_EVENTS) {
27
+ const existing = Array.isArray(hooks[definition.event]) ? hooks[definition.event] : [];
28
+ const entries = existing.filter((entry) => !isPusharyCodexHook(entry));
29
+ entries.push({
30
+ ...definition.matcher ? { matcher: definition.matcher } : {},
31
+ hooks: [{
32
+ type: "command",
33
+ command,
34
+ timeout: definition.timeout,
35
+ ...definition.statusMessage ? { statusMessage: definition.statusMessage } : {}
36
+ }]
37
+ });
38
+ hooks[definition.event] = entries;
39
+ }
40
+ };
41
+ var removeCodexHooks = (config) => {
42
+ const hooks = asRecord(config.hooks);
43
+ if (!hooks) return false;
44
+ let changed = false;
45
+ for (const definition of CODEX_HOOK_EVENTS) {
46
+ const entries = hooks[definition.event];
47
+ if (!Array.isArray(entries)) continue;
48
+ const filtered = entries.filter((entry) => !isPusharyCodexHook(entry));
49
+ if (filtered.length !== entries.length) {
50
+ if (filtered.length === 0) {
51
+ delete hooks[definition.event];
52
+ } else {
53
+ hooks[definition.event] = filtered;
54
+ }
55
+ changed = true;
56
+ }
57
+ }
58
+ if (Object.keys(hooks).length === 0) delete config.hooks;
59
+ return changed;
60
+ };
61
+ var hasCodexHooks = (config) => {
62
+ const hooks = asRecord(config.hooks);
63
+ if (!hooks) return false;
64
+ return CODEX_HOOK_EVENTS.some((definition) => {
65
+ const entries = hooks[definition.event];
66
+ return Array.isArray(entries) && entries.some(isPusharyCodexHook);
67
+ });
68
+ };
69
+ var missingCodexHookEvents = (config) => {
70
+ const hooks = asRecord(config.hooks);
71
+ return CODEX_HOOK_EVENTS.filter((definition) => {
72
+ const entries = hooks?.[definition.event];
73
+ return !Array.isArray(entries) || !entries.some(isPusharyCodexHook);
74
+ }).map((definition) => definition.event);
75
+ };
76
+
77
+ // src/npm.ts
78
+ import { execSync } from "child_process";
79
+ var cleanNpmEnv = () => {
80
+ const env = {};
81
+ for (const [key, value] of Object.entries(process.env)) {
82
+ if (key.toLowerCase().startsWith("npm_config_workspace")) continue;
83
+ env[key] = value;
84
+ }
85
+ return env;
86
+ };
87
+ var npmErrorMessage = (err) => {
88
+ const e = err;
89
+ const text = [e?.stderr, e?.stdout].map((part) => part ? part.toString() : "").join("\n");
90
+ const line = text.split("\n").map((l) => l.replace(/^npm error\s*/i, "").trim()).find((l) => l && !l.startsWith("A complete log") && !/^code\s/i.test(l));
91
+ return line || e?.message || String(err);
92
+ };
93
+ var execNpm = (args, options = {}) => {
94
+ return execSync(`npm ${args}`, {
95
+ timeout: 12e4,
96
+ stdio: "pipe",
97
+ ...options,
98
+ env: { ...cleanNpmEnv(), ...options.env ?? {} }
99
+ });
100
+ };
101
+
102
+ export {
103
+ addCodexHooks,
104
+ removeCodexHooks,
105
+ hasCodexHooks,
106
+ missingCodexHookEvents,
107
+ npmErrorMessage,
108
+ execNpm
109
+ };
@@ -0,0 +1,141 @@
1
+ // src/claude-config.ts
2
+ import { join } from "path";
3
+ var PUSHARY_MCP_URL = "https://pushary.com/api/mcp/mcp";
4
+ var PUSHARY_PERMISSION_RULE = "mcp__pushary__*";
5
+ var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
6
+ var ensureRecord = (target, key) => {
7
+ const existing = asRecord(target[key]);
8
+ if (existing) return existing;
9
+ const created = {};
10
+ target[key] = created;
11
+ return created;
12
+ };
13
+ var isPusharyPermission = (rule) => typeof rule === "string" && (rule.includes("pushary") || rule.includes("MCP(pushary"));
14
+ var isPusharyHook = (entry) => {
15
+ const hooks = asRecord(entry)?.hooks;
16
+ if (!Array.isArray(hooks)) return false;
17
+ return hooks.some((hook) => {
18
+ const command = String(asRecord(hook)?.command ?? "");
19
+ return command.includes("pushary-hook") || command.includes("pushary-post-hook") || command.includes("pushary-stop-hook") || command.includes("pushary-prompt-hook");
20
+ });
21
+ };
22
+ var addClaudeMcpServer = (config, apiKey) => {
23
+ const mcpServers = ensureRecord(config, "mcpServers");
24
+ mcpServers.pushary = {
25
+ type: "http",
26
+ url: PUSHARY_MCP_URL,
27
+ headers: { Authorization: `Bearer ${apiKey}` }
28
+ };
29
+ };
30
+ var removeClaudeMcpServers = (config) => {
31
+ let changed = false;
32
+ const removeFrom = (target) => {
33
+ const mcpServers = asRecord(target.mcpServers);
34
+ if (!mcpServers?.pushary) return;
35
+ delete mcpServers.pushary;
36
+ if (Object.keys(mcpServers).length === 0) delete target.mcpServers;
37
+ changed = true;
38
+ };
39
+ removeFrom(config);
40
+ const projects = asRecord(config.projects);
41
+ if (projects) {
42
+ for (const project of Object.values(projects)) {
43
+ const projectConfig = asRecord(project);
44
+ if (projectConfig) removeFrom(projectConfig);
45
+ }
46
+ }
47
+ return changed;
48
+ };
49
+ var addPusharyToolPermissions = (settings) => {
50
+ const permissions = ensureRecord(settings, "permissions");
51
+ const allow = Array.isArray(permissions.allow) ? permissions.allow : [];
52
+ const filtered = allow.filter((rule) => !isPusharyPermission(rule));
53
+ if (!filtered.includes(PUSHARY_PERMISSION_RULE)) {
54
+ filtered.push(PUSHARY_PERMISSION_RULE);
55
+ }
56
+ permissions.allow = filtered;
57
+ };
58
+ var addPusharyHooks = (settings, binDir) => {
59
+ const resolve = (name) => binDir ? join(binDir, name) : name;
60
+ const hooks = ensureRecord(settings, "hooks");
61
+ const preToolUse = (Array.isArray(hooks.PreToolUse) ? hooks.PreToolUse : []).filter((entry) => !isPusharyHook(entry));
62
+ preToolUse.push({
63
+ matcher: "Bash|Write|Edit",
64
+ hooks: [{
65
+ type: "command",
66
+ command: resolve("pushary-hook"),
67
+ timeout: 120
68
+ }]
69
+ });
70
+ hooks.PreToolUse = preToolUse;
71
+ const postToolUse = (Array.isArray(hooks.PostToolUse) ? hooks.PostToolUse : []).filter((entry) => !isPusharyHook(entry));
72
+ postToolUse.push({
73
+ matcher: "Bash|Write|Edit",
74
+ hooks: [{
75
+ type: "command",
76
+ command: resolve("pushary-post-hook"),
77
+ timeout: 10
78
+ }]
79
+ });
80
+ hooks.PostToolUse = postToolUse;
81
+ const stop = (Array.isArray(hooks.Stop) ? hooks.Stop : []).filter((entry) => !isPusharyHook(entry));
82
+ stop.push({
83
+ hooks: [{
84
+ type: "command",
85
+ command: resolve("pushary-stop-hook"),
86
+ timeout: 10
87
+ }]
88
+ });
89
+ hooks.Stop = stop;
90
+ const userPromptSubmit = (Array.isArray(hooks.UserPromptSubmit) ? hooks.UserPromptSubmit : []).filter((entry) => !isPusharyHook(entry));
91
+ userPromptSubmit.push({
92
+ hooks: [{
93
+ type: "command",
94
+ command: resolve("pushary-prompt-hook"),
95
+ timeout: 10
96
+ }]
97
+ });
98
+ hooks.UserPromptSubmit = userPromptSubmit;
99
+ };
100
+ var removePusharySettings = (settings) => {
101
+ let changed = removeClaudeMcpServers(settings);
102
+ const permissions = asRecord(settings.permissions);
103
+ if (permissions && Array.isArray(permissions.allow)) {
104
+ const filtered = permissions.allow.filter((rule) => !isPusharyPermission(rule));
105
+ if (filtered.length !== permissions.allow.length) {
106
+ if (filtered.length === 0) {
107
+ delete permissions.allow;
108
+ } else {
109
+ permissions.allow = filtered;
110
+ }
111
+ if (Object.keys(permissions).length === 0) delete settings.permissions;
112
+ changed = true;
113
+ }
114
+ }
115
+ const hooks = asRecord(settings.hooks);
116
+ if (hooks) {
117
+ for (const key of ["PreToolUse", "PostToolUse", "Stop", "UserPromptSubmit"]) {
118
+ const entries = hooks[key];
119
+ if (!Array.isArray(entries)) continue;
120
+ const filtered = entries.filter((entry) => !isPusharyHook(entry));
121
+ if (filtered.length !== entries.length) {
122
+ if (filtered.length === 0) {
123
+ delete hooks[key];
124
+ } else {
125
+ hooks[key] = filtered;
126
+ }
127
+ changed = true;
128
+ }
129
+ }
130
+ if (Object.keys(hooks).length === 0) delete settings.hooks;
131
+ }
132
+ return changed;
133
+ };
134
+
135
+ export {
136
+ addClaudeMcpServer,
137
+ removeClaudeMcpServers,
138
+ addPusharyToolPermissions,
139
+ addPusharyHooks,
140
+ removePusharySettings
141
+ };
@@ -0,0 +1,265 @@
1
+ import {
2
+ callMcpTool,
3
+ withRetry
4
+ } from "./chunk-3MIR7ODJ.js";
5
+ import {
6
+ getBaseUrl
7
+ } from "./chunk-VUNL35KE.js";
8
+ import {
9
+ extractPolicyArg,
10
+ isApprovalMode,
11
+ matchRankWeight,
12
+ matchToolPattern
13
+ } from "./chunk-22CV7V7A.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/identity.ts
54
+ import { createHash } from "crypto";
55
+ import { hostname } from "os";
56
+ var deriveMachineId = (host) => createHash("sha256").update(host).digest("hex").slice(0, 8);
57
+ var getMachineId = () => deriveMachineId(hostname());
58
+
59
+ // src/policy.ts
60
+ import { createHash as createHash2 } from "crypto";
61
+ import { existsSync, readFileSync, writeFileSync } from "fs";
62
+ import { join } from "path";
63
+ import { tmpdir } from "os";
64
+ var CACHE_TTL_MS = 5 * 60 * 1e3;
65
+ var cacheFile = (apiKey) => {
66
+ const hash = createHash2("sha256").update(apiKey).digest("hex").slice(0, 12);
67
+ return join(tmpdir(), `pushary-policy-${hash}.json`);
68
+ };
69
+ var fetchPolicy = async (apiKey) => {
70
+ return withRetry(async () => {
71
+ const baseUrl = getBaseUrl();
72
+ const response = await fetch(`${baseUrl}/api/mcp/policy`, {
73
+ headers: { "Authorization": `Bearer ${apiKey}` },
74
+ signal: AbortSignal.timeout(1e4)
75
+ });
76
+ if (!response.ok) {
77
+ throw new Error(`Failed to fetch policy: ${response.status}`);
78
+ }
79
+ const raw = await response.json();
80
+ if (!isPolicyConfig(raw)) throw new Error("Invalid policy response");
81
+ return raw;
82
+ }, { maxAttempts: 2 });
83
+ };
84
+ var getPolicy = async (apiKey) => {
85
+ const path = cacheFile(apiKey);
86
+ let staleCache = null;
87
+ if (existsSync(path)) {
88
+ try {
89
+ const stat = readFileSync(path, "utf-8");
90
+ const cached = JSON.parse(stat);
91
+ if (!isPolicyConfig(cached)) throw new Error("Corrupted cache");
92
+ if (!cached._cachedAt || Date.now() - cached._cachedAt < CACHE_TTL_MS) {
93
+ return cached;
94
+ }
95
+ staleCache = cached;
96
+ } catch {
97
+ }
98
+ }
99
+ try {
100
+ const policy = await fetchPolicy(apiKey);
101
+ try {
102
+ writeFileSync(path, JSON.stringify({ ...policy, _cachedAt: Date.now() }), "utf-8");
103
+ } catch {
104
+ }
105
+ return policy;
106
+ } catch {
107
+ if (staleCache) return staleCache;
108
+ throw new Error("Failed to fetch policy and no cached policy available");
109
+ }
110
+ };
111
+ var findBestMatch = (policies, toolName, arg) => {
112
+ let best;
113
+ let bestWeight = 0;
114
+ let bestLength = -1;
115
+ for (const candidate of policies) {
116
+ const rank = matchToolPattern(candidate.tool, toolName, arg);
117
+ if (rank === "none") continue;
118
+ const weight = matchRankWeight(rank);
119
+ const length = rank === "prefix" ? candidate.tool.length : -1;
120
+ if (weight > bestWeight || weight === bestWeight && length > bestLength) {
121
+ best = candidate;
122
+ bestWeight = weight;
123
+ bestLength = length;
124
+ }
125
+ }
126
+ return best;
127
+ };
128
+ var resolvePolicy = (config, toolName, modeOverride, toolInput) => {
129
+ const arg = toolInput ? extractPolicyArg(toolName, toolInput) : void 0;
130
+ const base = findBestMatch(config.policies, toolName, arg) ?? config.policies.find((p) => p.tool === "*") ?? {
131
+ tool: toolName,
132
+ timeoutSeconds: config.defaultTimeoutSeconds,
133
+ timeoutAction: config.defaultTimeoutAction,
134
+ mode: config.defaultMode ?? "push_first",
135
+ pushFirstSeconds: config.defaultPushFirstSeconds ?? 20
136
+ };
137
+ const effectiveOverride = modeOverride ?? config.modeOverride;
138
+ if (effectiveOverride) {
139
+ return { ...base, mode: effectiveOverride };
140
+ }
141
+ return base;
142
+ };
143
+ var fetchModeState = async (apiKey, sessionId) => {
144
+ try {
145
+ const baseUrl = getBaseUrl();
146
+ const url = sessionId ? `${baseUrl}/api/mcp/mode?session=${encodeURIComponent(sessionId)}` : `${baseUrl}/api/mcp/mode`;
147
+ const response = await fetch(url, {
148
+ headers: { "Authorization": `Bearer ${apiKey}` },
149
+ signal: AbortSignal.timeout(3e3)
150
+ });
151
+ if (!response.ok) return { mode: null, kill: false };
152
+ const data = await response.json();
153
+ const mode = data.override?.mode;
154
+ return { mode: isApprovalMode(mode) ? mode : null, kill: data.kill === true };
155
+ } catch {
156
+ return { mode: null, kill: false };
157
+ }
158
+ };
159
+ var fetchModeOverride = async (apiKey) => (await fetchModeState(apiKey)).mode;
160
+
161
+ // src/describe.ts
162
+ var hookPrefixes = {
163
+ Bash: (input) => `bash: ${input.command ?? "(no command)"}`,
164
+ Write: (input) => `write file: ${input.file_path ?? "(unknown path)"}`,
165
+ Edit: (input) => `edit file: ${input.file_path ?? "(unknown path)"}`,
166
+ Read: (input) => `read file: ${input.file_path ?? "(unknown path)"}`
167
+ };
168
+ var eventPrefixes = {
169
+ Bash: (input) => `ran: ${String(input.command ?? "").slice(0, 120)}`,
170
+ Write: (input) => `wrote: ${input.file_path ?? "unknown"}`,
171
+ Edit: (input) => `edited: ${input.file_path ?? "unknown"}`,
172
+ Read: (input) => `read: ${input.file_path ?? "unknown"}`
173
+ };
174
+ var describeToolCall = (toolName, toolInput, format = "hook") => {
175
+ const prefixes = format === "hook" ? hookPrefixes : eventPrefixes;
176
+ const builder = prefixes[toolName];
177
+ if (builder) return builder(toolInput);
178
+ return format === "hook" ? `${toolName}: ${JSON.stringify(toolInput).slice(0, 200)}` : `${toolName}: done`;
179
+ };
180
+ var TOOL_TARGET_MAX_LENGTH = 80;
181
+ var deriveToolTarget = (toolName, toolInput) => {
182
+ if (toolName === "Bash") {
183
+ const command = toolInput.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
+ if (toolName === "Edit" || toolName === "Write") {
189
+ const filePath = toolInput.file_path;
190
+ if (typeof filePath !== "string") return void 0;
191
+ const separator = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));
192
+ const base = filePath.slice(separator + 1);
193
+ const dot = base.lastIndexOf(".");
194
+ if (dot <= 0) return void 0;
195
+ return base.slice(dot).slice(0, TOOL_TARGET_MAX_LENGTH);
196
+ }
197
+ return void 0;
198
+ };
199
+
200
+ // src/pending.ts
201
+ import { join as join2 } from "path";
202
+ import { tmpdir as tmpdir2 } from "os";
203
+ import { existsSync as existsSync2, mkdirSync, writeFileSync as writeFileSync2, readdirSync, unlinkSync, rmSync, statSync } from "fs";
204
+ var PENDING_DIR = join2(tmpdir2(), "pushary-pending");
205
+ var DEFAULT_SESSION = "_no_session";
206
+ var GRACE_MS = 10 * 60 * 1e3;
207
+ var sanitize = (sessionId) => sessionId.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 128) || DEFAULT_SESSION;
208
+ var dirFor = (sessionId) => join2(PENDING_DIR, sanitize(sessionId));
209
+ var isDefaultSession = (sessionId) => sanitize(sessionId) === DEFAULT_SESSION;
210
+ var savePendingQuestion = (sessionId, correlationId) => {
211
+ const dir = dirFor(sessionId);
212
+ if (!existsSync2(dir)) mkdirSync(dir, { recursive: true });
213
+ writeFileSync2(join2(dir, correlationId), "", "utf-8");
214
+ };
215
+ var listPendingQuestions = (sessionId) => {
216
+ const dir = dirFor(sessionId);
217
+ let files;
218
+ try {
219
+ files = readdirSync(dir);
220
+ } catch {
221
+ return [];
222
+ }
223
+ if (!isDefaultSession(sessionId)) return files;
224
+ const cutoff = Date.now() - GRACE_MS;
225
+ return files.filter((name) => {
226
+ try {
227
+ return statSync(join2(dir, name)).mtimeMs < cutoff;
228
+ } catch {
229
+ return false;
230
+ }
231
+ });
232
+ };
233
+ var removePendingQuestion = (sessionId, correlationId) => {
234
+ try {
235
+ unlinkSync(join2(dirFor(sessionId), correlationId));
236
+ } catch {
237
+ }
238
+ };
239
+ var removePendingSession = (sessionId) => {
240
+ try {
241
+ rmSync(dirFor(sessionId), { recursive: true, force: true });
242
+ } catch {
243
+ }
244
+ };
245
+
246
+ export {
247
+ isPolicyConfig,
248
+ askUser,
249
+ waitForAnswer,
250
+ cancelQuestion,
251
+ sendNotification,
252
+ describeToolCall,
253
+ deriveToolTarget,
254
+ DEFAULT_SESSION,
255
+ isDefaultSession,
256
+ savePendingQuestion,
257
+ listPendingQuestions,
258
+ removePendingQuestion,
259
+ removePendingSession,
260
+ getMachineId,
261
+ getPolicy,
262
+ resolvePolicy,
263
+ fetchModeState,
264
+ fetchModeOverride
265
+ };