claude-remote-approver 0.5.0 → 0.5.1
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/bin/cli.mjs +5 -4
- package/package.json +1 -1
- package/src/hook.mjs +13 -5
- package/src/ntfy.mjs +1 -1
package/bin/cli.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import fs from "node:fs";
|
|
|
12
12
|
import path from "node:path";
|
|
13
13
|
import os from "node:os";
|
|
14
14
|
import qrcode from "qrcode-terminal";
|
|
15
|
+
import { ASK } from "../src/hook.mjs";
|
|
15
16
|
|
|
16
17
|
// ---------------------------------------------------------------------------
|
|
17
18
|
// main
|
|
@@ -87,8 +88,8 @@ export async function main(args, deps) {
|
|
|
87
88
|
try {
|
|
88
89
|
input = JSON.parse(deps.stdin);
|
|
89
90
|
} catch {
|
|
90
|
-
|
|
91
|
-
deps.stdout.write(JSON.stringify(
|
|
91
|
+
deps.stderr.write("[claude-remote-approver] Invalid hook input. Falling back to CLI.\n");
|
|
92
|
+
deps.stdout.write(JSON.stringify(ASK) + "\n");
|
|
92
93
|
break;
|
|
93
94
|
}
|
|
94
95
|
|
|
@@ -96,8 +97,8 @@ export async function main(args, deps) {
|
|
|
96
97
|
try {
|
|
97
98
|
result = await deps.processHook(input, deps);
|
|
98
99
|
} catch {
|
|
99
|
-
|
|
100
|
-
deps.stdout.write(JSON.stringify(
|
|
100
|
+
deps.stderr.write("[claude-remote-approver] Hook processing failed. Falling back to CLI.\n");
|
|
101
|
+
deps.stdout.write(JSON.stringify(ASK) + "\n");
|
|
101
102
|
break;
|
|
102
103
|
}
|
|
103
104
|
|
package/package.json
CHANGED
package/src/hook.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import crypto from "node:crypto";
|
|
4
4
|
import { DEFAULT_CONFIG } from "./config.mjs";
|
|
5
5
|
|
|
6
|
-
const ASK = Object.freeze({ hookSpecificOutput: Object.freeze({ hookEventName: "PermissionRequest", decision: Object.freeze({ behavior: "ask" }) }) });
|
|
6
|
+
export const ASK = Object.freeze({ hookSpecificOutput: Object.freeze({ hookEventName: "PermissionRequest", decision: Object.freeze({ behavior: "ask" }) }) });
|
|
7
7
|
const DENY = Object.freeze({ hookSpecificOutput: Object.freeze({ hookEventName: "PermissionRequest", decision: Object.freeze({ behavior: "deny" }) }) });
|
|
8
8
|
const MAX_RETRIES = 3;
|
|
9
9
|
|
|
@@ -44,7 +44,7 @@ export async function sendWithRetry(sendFn, params) {
|
|
|
44
44
|
return await sendFn(params);
|
|
45
45
|
} catch (err) {
|
|
46
46
|
if (i === MAX_RETRIES - 1) {
|
|
47
|
-
console.error(
|
|
47
|
+
console.error(`[claude-remote-approver] Notification failed after ${MAX_RETRIES} attempts:`, err.message, "— Falling back to CLI.");
|
|
48
48
|
return null;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -139,13 +139,14 @@ export async function processAskUserQuestion(input, deps) {
|
|
|
139
139
|
timeout: config.timeout * 1000,
|
|
140
140
|
});
|
|
141
141
|
} catch (err) {
|
|
142
|
-
console.error("
|
|
142
|
+
console.error("[claude-remote-approver] Response listener failed:", err.message, "— Falling back to CLI.");
|
|
143
143
|
return ASK;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
if (response.answer) {
|
|
147
147
|
answers[q.question] = response.answer;
|
|
148
148
|
} else {
|
|
149
|
+
console.error("[claude-remote-approver] No answer received. Falling back to CLI.");
|
|
149
150
|
return ASK;
|
|
150
151
|
}
|
|
151
152
|
}
|
|
@@ -211,11 +212,18 @@ export async function processHook(input, { loadConfig, sendNotification, waitFor
|
|
|
211
212
|
timeout,
|
|
212
213
|
});
|
|
213
214
|
} catch (err) {
|
|
214
|
-
console.error("
|
|
215
|
+
console.error("[claude-remote-approver] Response listener failed:", err.message, "— Falling back to CLI.");
|
|
215
216
|
return ASK;
|
|
216
217
|
}
|
|
217
218
|
|
|
218
|
-
if (response.timeout
|
|
219
|
+
if (response.timeout) {
|
|
220
|
+
console.error("[claude-remote-approver] Timed out waiting for response. Falling back to CLI.");
|
|
221
|
+
return ASK;
|
|
222
|
+
}
|
|
223
|
+
if (response.error) {
|
|
224
|
+
console.error("[claude-remote-approver] Response error:", response.error.message, "— Falling back to CLI.");
|
|
225
|
+
return ASK;
|
|
226
|
+
}
|
|
219
227
|
if (response.approved === false) return DENY;
|
|
220
228
|
return { hookSpecificOutput: { hookEventName: "PermissionRequest", decision: { behavior: "allow" } } };
|
|
221
229
|
}
|
package/src/ntfy.mjs
CHANGED
|
@@ -91,7 +91,7 @@ export async function waitForResponse({ server, topic, requestId, timeout }) {
|
|
|
91
91
|
if (err?.name === "AbortError") {
|
|
92
92
|
return { timeout: true };
|
|
93
93
|
}
|
|
94
|
-
console.error("[claude-remote-approver] waitForResponse error:", err);
|
|
94
|
+
console.error("[claude-remote-approver] waitForResponse error:", err.message ?? err);
|
|
95
95
|
return { error: err };
|
|
96
96
|
}
|
|
97
97
|
}
|