MCPcopy
hub / github.com/coder/mux / handlePrompt

Function handlePrompt

src/node/runtime/sshAskpass.ts:93–119  ·  view source on GitHub ↗
(requestId: string)

Source from the content-addressed store, hash-verified

91 let closed = false;
92
93 async function handlePrompt(requestId: string): Promise<void> {
94 const promptFile = path.join(dir, `prompt.${requestId}.txt`);
95 const responseFile = path.join(dir, `response.${requestId}.txt`);
96
97 try {
98 await fs.promises.access(promptFile);
99 } catch {
100 processed.delete(requestId);
101 return;
102 }
103
104 if (closed) return;
105
106 try {
107 const promptText = await fs.promises.readFile(promptFile, "utf-8");
108 const response = await onPrompt(promptText);
109 await fs.promises.writeFile(responseFile, response + "\n");
110 } catch (err) {
111 log.debug("Askpass prompt handling failed:", err);
112 // Write rejection to unblock askpass (best-effort)
113 try {
114 await fs.promises.writeFile(responseFile, "no\n");
115 } catch {
116 /* askpass may already be gone */
117 }
118 }
119 }
120
121 // Watch for askpass to write prompt files.
122 // fs.watch is set up BEFORE SSH is spawned, so we cannot miss events.

Callers 1

createAskpassSessionFunction · 0.85

Calls 4

debugMethod · 0.80
readFileMethod · 0.65
writeFileMethod · 0.65
deleteMethod · 0.45

Tested by

no test coverage detected