Repository navigation
Expand file tree
/
Copy pathconsent.ts
More file actions
65 lines (55 loc) · 1.46 KB
/
Copy pathconsent.ts
File metadata and controls
65 lines (55 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { createInterface } from "node:readline/promises";
export type WriteLike = {
write(chunk: string): void;
};
export type QuestionSession = {
ask(prompt: string): Promise<string>;
close(): void;
};
export type QuestionSessionFactory = (
input: NodeJS.ReadableStream,
output: WriteLike
) => QuestionSession;
export function createReadlineQuestionSession(
input: NodeJS.ReadableStream,
output: WriteLike
): QuestionSession {
const questionInterface = createInterface({
input,
output
});
return {
ask(prompt: string) {
return questionInterface.question(prompt);
},
close() {
questionInterface.close();
}
};
}
export function renderConsentMessage(): string {
return [
"WARNING: YOLO mode will run Claude with:",
"claude remote-control --permission-mode bypassPermissions",
"",
"This can bypass interactive permission checks.",
"Use it only if you understand the security implications.",
""
].join("\n");
}
export function isConsentAccepted(answer: string): boolean {
const normalizedAnswer = answer.trim().toLowerCase();
return normalizedAnswer === "y" || normalizedAnswer === "yes";
}
export async function promptForConsent(
session: QuestionSession,
output: WriteLike
): Promise<boolean> {
output.write(renderConsentMessage());
try {
const answer = await session.ask("Type 'yes' to continue: ");
return isConsentAccepted(answer);
} finally {
session.close();
}
}